commit d9a86691358cabd5b8af19ad62e6fb1093f1a320 Author: ChenZichaoczc <2974997276@qq.com> Date: Tue Jun 3 17:02:04 2025 +0800 first commit diff --git a/qf_nx_itk-master (3)/qf_nx_itk/.gitattributes b/qf_nx_itk-master (3)/qf_nx_itk/.gitattributes new file mode 100644 index 0000000..1ff0c42 --- /dev/null +++ b/qf_nx_itk-master (3)/qf_nx_itk/.gitattributes @@ -0,0 +1,63 @@ +############################################################################### +# Set default behavior to automatically normalize line endings. +############################################################################### +* text=auto + +############################################################################### +# Set default behavior for command prompt diff. +# +# This is need for earlier builds of msysgit that does not have it on by +# default for csharp files. +# Note: This is only used by command line +############################################################################### +#*.cs diff=csharp + +############################################################################### +# Set the merge driver for project and solution files +# +# Merging from the command prompt will add diff markers to the files if there +# are conflicts (Merging from VS is not affected by the settings below, in VS +# the diff markers are never inserted). Diff markers may cause the following +# file extensions to fail to load in VS. An alternative would be to treat +# these files as binary and thus will always conflict and require user +# intervention with every merge. To do so, just uncomment the entries below +############################################################################### +#*.sln merge=binary +#*.csproj merge=binary +#*.vbproj merge=binary +#*.vcxproj merge=binary +#*.vcproj merge=binary +#*.dbproj merge=binary +#*.fsproj merge=binary +#*.lsproj merge=binary +#*.wixproj merge=binary +#*.modelproj merge=binary +#*.sqlproj merge=binary +#*.wwaproj merge=binary + +############################################################################### +# behavior for image files +# +# image files are treated as binary by default. +############################################################################### +#*.jpg binary +#*.png binary +#*.gif binary + +############################################################################### +# diff behavior for common document formats +# +# Convert binary document formats to text before diffing them. This feature +# is only available from the command line. Turn it on by uncommenting the +# entries below. +############################################################################### +#*.doc diff=astextplain +#*.DOC diff=astextplain +#*.docx diff=astextplain +#*.DOCX diff=astextplain +#*.dot diff=astextplain +#*.DOT diff=astextplain +#*.pdf diff=astextplain +#*.PDF diff=astextplain +#*.rtf diff=astextplain +#*.RTF diff=astextplain diff --git a/qf_nx_itk-master (3)/qf_nx_itk/.gitignore b/qf_nx_itk-master (3)/qf_nx_itk/.gitignore new file mode 100644 index 0000000..4ce6fdd --- /dev/null +++ b/qf_nx_itk-master (3)/qf_nx_itk/.gitignore @@ -0,0 +1,340 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore + +# User-specific files +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!?*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser +*- Backup*.rdl + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# JetBrains Rider +.idea/ +*.sln.iml + +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + +# BeatPulse healthcheck temp database +healthchecksdb \ No newline at end of file diff --git a/qf_nx_itk-master (3)/qf_nx_itk/Connor_NX/Connor_NX.cpp b/qf_nx_itk-master (3)/qf_nx_itk/Connor_NX/Connor_NX.cpp new file mode 100644 index 0000000..dbc4afc --- /dev/null +++ b/qf_nx_itk-master (3)/qf_nx_itk/Connor_NX/Connor_NX.cpp @@ -0,0 +1,163 @@ +// Connor_NX.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 +// + +#include "Connor_NX.h" + + +#ifdef __cplusplus +extern "C" { +#endif + /** + * @fn extern "C" DLLAPI int liborigin_register_callbacks + * @return usually return ITK_ok + * @brief liborigin customization entry + * 此函数必须有规范的写法,必须以dll的名称加上"_"开头 + */ + DLLAPI int connor_nx_itk_register_callbacks() + { + int ifail = ITK_ok; + ITKCALL(ifail = CUSTOM_register_exit("connor_nx_itk", "USER_invoke_pdm_server", (CUSTOM_EXIT_ftn_t)K_invoke_pdm_server)); + fprintf(stdout, "connor_nx_itk register USER_invoke_pdm_server complete\n"); + ITKCALL( ifail = CUSTOM_register_exit( "connor_nx_itk", "USERSERVICE_register_methods", + (CUSTOM_EXIT_ftn_t)USERSERVICE_custom_register_methods) ); + fprintf( stdout, "connor_nx_itk register USERSERVICE_custom_register_methods complete\n" ); + ITKCALL(ifail = CUSTOM_register_exit("connor_nx_itk", "USER_gs_shell_init_module", + (CUSTOM_EXIT_ftn_t)USERSERVICE_custom_register_handlers)); + fprintf(stdout, "connor_nx_itk register USER_gs_shell_init_module complete\n"); + return ifail; + } + + + DLLAPI int USERSERVICE_custom_register_handlers(int* decision, va_list args) + { + int ifail = ITK_ok; + //CONNOR_Check_IP_Classification + ITKCALL(ifail = EPM_register_action_handler("QF_signoff_rev", "QF_signoff_rev", (EPM_action_handler_t)CONNOR_SIGN_MASTER)); + if (ifail == 0) { + printf("注册操作处理程序成功:QF_signoff_rev\n"); + } + else { + printf("注册操作处理程序失败[%d]:QF_signoff_rev\n", ifail); + } + ITKCALL(ifail = EPM_register_action_handler("QF_signoff_prt", "QF_signoff_prt", (EPM_action_handler_t)CONNOR_SIGN_DATASET)); + if (ifail == 0) { + printf("注册操作处理程序成功:QF_signoff_prt\n"); + } + else { + printf("注册操作处理程序失败[%d]:QF_signoff_prt\n", ifail); + } + return ifail; + } + + int Connor_open_bypass(void* returnValue) + { + POM_AM__set_application_bypass(true); + return 0; + } + + int Connor_close_bypass(void* returnValue) + { + POM_AM__set_application_bypass(false); + return 0; + } + + int Get_New_AutoCode_ID(void* returnValue) + { + int ifail = ITK_ok; + char* old_id, * suffix; + tag_t type_tag; + ITKCALL(ifail = USERARG_get_tag_argument(&type_tag)); + ITKCALL(ifail = USERARG_get_string_argument(&old_id)); + ITKCALL(ifail = USERARG_get_string_argument(&suffix)); + string new_id; + ifail = Get_New_ID(type_tag, old_id, suffix, new_id); + if (ifail == ITK_ok) { + char* returnData; + returnData = (char*)MEM_alloc((ITEM_id_size_c + 1) * sizeof(char)); + tc_strcpy(returnData, new_id.c_str()); + *((char**)returnValue) = returnData; + MEM_free(old_id); + } + return ifail; + } + + + DLLAPI int USERSERVICE_custom_register_methods() + { + int + status = ITK_ok, + numberOfArguments = 0, + returnValueType = USERARG_STRING_TYPE, + * argumentList = NULL; + USER_function_t functionPtr; + { + numberOfArguments = 1; + functionPtr = Connor_open_bypass; + argumentList = (int*)MEM_alloc(numberOfArguments * sizeof(int)); + argumentList[0] = USERARG_STRING_TYPE; + returnValueType = USERARG_VOID_TYPE; + char* mth_name = (char*)malloc(1 + sizeof(char) * strlen("CONNOR_open_bypass")); + tc_strcpy(mth_name, "CONNOR_open_bypass"); + ITKCALL(status = USERSERVICE_register_method(mth_name, functionPtr, numberOfArguments, + argumentList, returnValueType)); + MEM_free(argumentList); + if (status == ITK_ok) + { + printf("Method: %s\n", mth_name); + } + else + { + printf("Method register failed [%d]: %s\n", status, mth_name); + } + } + { + numberOfArguments = 1; + functionPtr = Connor_close_bypass; + argumentList = (int*)MEM_alloc(numberOfArguments * sizeof(int)); + argumentList[0] = USERARG_STRING_TYPE; + returnValueType = USERARG_VOID_TYPE; + char* mth_name = (char*)malloc(1 + sizeof(char) * strlen("CONNOR_close_bypass")); + tc_strcpy(mth_name, "CONNOR_close_bypass"); + ITKCALL(status = USERSERVICE_register_method(mth_name, functionPtr, numberOfArguments, + argumentList, returnValueType)); + MEM_free(argumentList); + if (status == ITK_ok) + { + printf("Method: %s\n", mth_name); + } + else + { + printf("Method register failed [%d]: %s\n", status, mth_name); + } + } + { + numberOfArguments = 3; + functionPtr = Get_New_AutoCode_ID; + argumentList = (int*)MEM_alloc(numberOfArguments * sizeof(int)); + argumentList[0] = USERARG_TAG_TYPE; + argumentList[1] = USERARG_STRING_TYPE; + argumentList[2] = USERARG_STRING_TYPE; + returnValueType = USERARG_STRING_TYPE; + char* mth_name = (char*)malloc(1 + sizeof(char) * strlen("Get_New_AutoCode_ID")); + tc_strcpy(mth_name, "Get_New_AutoCode_ID"); + ITKCALL(status = USERSERVICE_register_method(mth_name, functionPtr, numberOfArguments, + argumentList, returnValueType)); + MEM_free(argumentList); + if (status == ITK_ok) + { + printf("Method: %s\n", mth_name); + } + else + { + printf("Method register failed [%d]: %s\n", status, mth_name); + } + } + + + return ITK_ok; + } + + +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/qf_nx_itk-master (3)/qf_nx_itk/Connor_NX/Connor_NX.h b/qf_nx_itk-master (3)/qf_nx_itk/Connor_NX/Connor_NX.h new file mode 100644 index 0000000..b418bb1 --- /dev/null +++ b/qf_nx_itk-master (3)/qf_nx_itk/Connor_NX/Connor_NX.h @@ -0,0 +1,78 @@ +#include +#include +#include +#include "kutil.h" +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef list RetData; +typedef list::iterator RetDataIterator; +typedef map SearchCriterionInputs; + +DLLAPI int USERSERVICE_custom_register_methods(); +DLLAPI int K_invoke_pdm_server(int *decision, va_list args); +DLLAPI int USERSERVICE_custom_register_handlers(int* decision, va_list args); + +int Get_New_ID(tag_t item_type_tag, string old_id, string suffix, string& new_item_id); +int CONNOR_SIGN_MASTER(EPM_action_message_t msg); +int CONNOR_SIGN_DATASET(EPM_action_message_t msg); +//int check_form_attribute(EPM_action_message_t msg); +//int check_owner(EPM_rule_message_t msg); +//int check_release(EPM_rule_message_t msg); +void map_insert(map < string, string >* strmap, string index, string x); +void init_search_criteria_map(string searchStr, SearchCriterionInputs& searchCriteria); +void init_search_criteria_vector(string searchStr, vector& propNames, vector& propValues); +int Parse_NX_Template_By_ID(const std::string& itemID, std::string& res); +int Read_NX_Image_By_ID(const std::string& itemID, std::string& res); +int Download_Dataset_By_UID(const std::string& itemID, std::string& res); +int Get_All_SubTypes(const std::string& typeName, std::string& res); +int SEARCH_AUTOCODE_NODE(const std::string& typeName, std::string& res); +int Get_Uid(const std::string& name, std::string& res); +int SEARCH_AUTOCODE_SEGMENT(const std::string& searchStr, std::string& res); +int SEARCH_AUTOCODE_USER(const std::string& searchStr, std::string& res); +int GET_TREE_AND_LIST_STRING_VALUE(const std::string& searchStr, std::string& res); +int GET_NEW_REV_ID(const std::string& typeNameStr, std::string& res); +int GET_LOGICAL_PROP_VALUE(const std::string& str, std::string& res); +int SEARCH_TREE_OR_LIST_NODE(const std::string& searchStr, std::string& res); +int GET_TREE_AND_LIST_STRING_VALUES(const std::string& searchStr, std::string& res); +int SEARCH_PARENT_TREE_OR_LIST_NODE(const std::string& searchStr, std::string& res); +int ICS_GET_ATTRIBUTES(const std::string& str, std::string& res); +int ICS_ATTR_IS_REFERENCE_ATTRIBUTE(const std::string& str, std::string& res); +int ICS_ATTR_ASK_PROPERTY(const std::string& str, std::string& res); +int ICS_ATTR_ASK_KEYLOV(const std::string& str, std::string& res); +int GET_DISPLAY_PROP_VALUE(const std::string& str, std::string& res); +int FIND_LOV_BY_NAME(const std::string& str, std::string& res); +int GET_REFERENCE_PROP_VALUE(const std::string& str, std::string& res); +int QUERY_PART_NO(const std::string& str, std::string& res); +int DELETE_RECYCLE_ID(const std::string& str, std::string& res); +int ITEM_EXIST(const std::string& str, std::string& res); +int ITEM_CREATE(const std::string& str, std::string& res); +int ADD_TO_NEWSTUFF(const std::string& uid, std::string& res); +int GET_CLASSIFICATION_ID(const std::string& uid, std::string& res); +int SEND_ITEM_TO_CLASSIFICATION(const std::string& str, std::string& res); +int GET_ITEMTYPE_BY_ID(const std::string& item_id, std::string& res); +int GET_REVUID_BY_ID(const std::string& item_id, std::string& res); +int ITEM_UPDATE(const std::string& str, std::string& res); +int READ_NX_TEMPLATE_BOM(const std::string& itemID, std::string& res); +int GET_CLONE_INFO(const std::string& uid, std::string& res); +int GET_LATEST_ITEM_REVISION(const std::string& str, std::string& res); +int GRANT_PRIVILEGE(const std::string& str, std::string& res); +int GET_UOM_TAGS(const std::string& str, std::string& res); +int UPDATE_UOM(const std::string& str, std::string& res); +int GET_REFERENCE_PROP_VALUE_ARRAY(const std::string& str, std::string& res); +int ICS_ATTR_ASK_METRIC_UNIT(const std::string& str, std::string& res); + +#define debug true +#define OUTPUT_CODE_ERROR -1 +#define SPLITTER "&;&" +#define SPLIT_SECTION "&SECTION&" +#define SPLIT_PROP_STR "&PROP&" +#define SPLIT_PROP_NAME_VALUE "&=&" + +#ifdef __cplusplus +} +#endif + diff --git a/qf_nx_itk-master (3)/qf_nx_itk/Connor_NX/Connor_NX.vcxproj b/qf_nx_itk-master (3)/qf_nx_itk/Connor_NX/Connor_NX.vcxproj new file mode 100644 index 0000000..cc99185 --- /dev/null +++ b/qf_nx_itk-master (3)/qf_nx_itk/Connor_NX/Connor_NX.vcxproj @@ -0,0 +1,183 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 16.0 + {B66C17FA-78C8-443E-8239-6E8744560AD7} + Win32Proj + ConnorNX + 10.0 + connor_nx_itk + + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + Application + true + v142 + Unicode + + + DynamicLibrary + false + v142 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + + + true + + + false + + + false + + + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + NotUsing + Level3 + true + true + true + NDEBUG;_CRT_SECURE_NO_WARNINGS;_CONSOLE;IPLIB=none;%(PreprocessorDefinitions) + false + D:\WorkEnvironment\QunFeng\nx_itk\oci;D:\WorkEnvironment\QunFeng\nx_itk\include_cpp;D:\WorkEnvironment\QunFeng\nx_itk\include;%(AdditionalIncludeDirectories) + + + Console + true + true + true + D:\WorkEnvironment\QunFeng\nx_itk\lib\*.lib;%(AdditionalDependencies) + libuser_exits.ar.lib + + + + + + \ No newline at end of file diff --git a/qf_nx_itk-master (3)/qf_nx_itk/Connor_NX/Connor_NX.vcxproj.filters b/qf_nx_itk-master (3)/qf_nx_itk/Connor_NX/Connor_NX.vcxproj.filters new file mode 100644 index 0000000..7e8f97e --- /dev/null +++ b/qf_nx_itk-master (3)/qf_nx_itk/Connor_NX/Connor_NX.vcxproj.filters @@ -0,0 +1,87 @@ +锘 + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + 婧愭枃浠 + + + 婧愭枃浠 + + + 婧愭枃浠 + + + 婧愭枃浠 + + + 婧愭枃浠 + + + 婧愭枃浠 + + + 婧愭枃浠 + + + 婧愭枃浠 + + + 婧愭枃浠 + + + 婧愭枃浠 + + + 婧愭枃浠 + + + 婧愭枃浠 + + + 婧愭枃浠 + + + 婧愭枃浠 + + + 婧愭枃浠 + + + 婧愭枃浠 + + + + + 澶存枃浠 + + + 澶存枃浠 + + + 澶存枃浠 + + + 澶存枃浠 + + + 澶存枃浠 + + + + + + \ No newline at end of file diff --git a/qf_nx_itk-master (3)/qf_nx_itk/Connor_NX/Download_Dataset_By_UID.cpp b/qf_nx_itk-master (3)/qf_nx_itk/Connor_NX/Download_Dataset_By_UID.cpp new file mode 100644 index 0000000..4abbf40 --- /dev/null +++ b/qf_nx_itk-master (3)/qf_nx_itk/Connor_NX/Download_Dataset_By_UID.cpp @@ -0,0 +1,43 @@ +#include "Connor_NX.h" +using namespace std; + + +int Download_Dataset_By_UID(const std::string& dataset_uid_ref_ext, std::string& res) { + int ifail = ITK_ok; + char* object_string = NULL; + char *dataset_file = NULL, *original_file_name = NULL; + tag_t dataset_tag = NULLTAG; + vector split; + POM_AM__set_application_bypass(true); + WriteLog(debug, "下载数据集:%s", dataset_uid_ref_ext.c_str()); + if (tc_strlen(dataset_uid_ref_ext.c_str()) == 0) { + res.append(("数据集UID不可为空")); + ifail = OUTPUT_CODE_ERROR; + goto gx_nx_image_end; + } + Split(dataset_uid_ref_ext, SPLITTER, split); + if (split.size() != 3) { + res.append(("调用参数错误“UID;引用;后缀”")); + ifail = OUTPUT_CODE_ERROR; + goto gx_nx_image_end; + } + ITKCALL(ifail = AOM_string_to_tag(split[0].c_str(), &dataset_tag)); + if (ifail != ITK_ok || dataset_tag == NULLTAG) { + res.append(("未找到数据集: ")).append(split[0]); + goto gx_nx_image_end; + } + ITKCALL(ifail = AOM_ask_value_string(dataset_tag, "object_string", &object_string)); + WriteLog(debug, "找到数据集:%s", object_string); + export_dataset_file(debug, dataset_tag, split[1].c_str(), split[2].c_str(), &dataset_file, &original_file_name); + if (dataset_file == NULL) { + res.append(("从数据集下载失败: ")).append(object_string); + ifail = OUTPUT_CODE_ERROR; + goto gx_nx_image_end; + } + res.append(dataset_file); +gx_nx_image_end: + POM_AM__set_application_bypass(false); + DOFREE(original_file_name); + DOFREE(object_string); + return ifail; +} \ No newline at end of file diff --git a/qf_nx_itk-master (3)/qf_nx_itk/Connor_NX/GET_ALL_SUB_TYPES.cpp b/qf_nx_itk-master (3)/qf_nx_itk/Connor_NX/GET_ALL_SUB_TYPES.cpp new file mode 100644 index 0000000..83951b0 --- /dev/null +++ b/qf_nx_itk-master (3)/qf_nx_itk/Connor_NX/GET_ALL_SUB_TYPES.cpp @@ -0,0 +1,51 @@ +#include "Connor_NX.h" +using namespace std; + + +int Get_All_SubTypes(const std::string& typeNameStr, std::string& res) { + int ifail = ITK_ok; + tag_t type_tag = NULLTAG; + tag_t *all_type_tags = NULL; + int type_cnt = 0; + vector typeNames; + Split(typeNameStr, SPLITTER, typeNames); + int exclude_type_name_cnt = typeNames.size()-1; + const char** exclude_type_names; + char** names = NULL; + char** uif_names = NULL; + exclude_type_names = (const char**)MEM_alloc(exclude_type_name_cnt * sizeof(const char*)); + for (int i = 0; i < exclude_type_name_cnt; i++) { + string typeName = typeNames[i + 1]; + exclude_type_names[i] = typeName.c_str(); // (char*)MEM_alloc(typeName.length() * sizeof(char)); + // tc_strcpy(exclude_type_names[i], typeName.c_str()); + //printf(">> %s\n", exclude_type_names[i]); + } + /*ITKCALL(ifail = TCTYPE_ask_type(typeName.c_str(), &type_tag)); + if (ifail != ITK_ok||type_tag==NULLTAG) { + res.append(("未找到对象类型: ")).append(typeName); + ifail = OUTPUT_CODE_ERROR; + goto get_subtype_end; + } + ITKCALL(ifail = TCTYPE_ask_subtypes(type_tag, false, &type_cnt, &all_type_tags));*/ + ITKCALL(ifail = TCTYPE_UIF_find_generically_creatable_business_objects(typeNames[0].c_str(), exclude_type_name_cnt, exclude_type_names, &type_cnt, &all_type_tags, &names, &uif_names)); + //ITKCALL(ifail = TCTYPE_find_alltypes_for_class(typeName.c_str(), &type_cnt, &all_type_tags)); + if (ifail != ITK_ok) { + res.append(("获取类型失败: ")).append(typeNameStr); + goto get_subtype_end; + } + for (int i = 0; i < type_cnt; i++) { + tag_t a_tag = all_type_tags[i]; + char* type_name = NULL, * dis_name = NULL; + ITKCALL(ifail = TCTYPE_ask_name2(a_tag, &type_name)); + ITKCALL(ifail = TCTYPE_ask_display_name(a_tag, &dis_name)); + if (type_name != NULL && dis_name != NULL) { + res.append(type_name).append("=").append(dis_name).append(SPLITTER); + } + } + +get_subtype_end: + DOFREE(all_type_tags); + DOFREE(names); + DOFREE(uif_names); + return ifail; +} \ No newline at end of file diff --git a/qf_nx_itk-master (3)/qf_nx_itk/Connor_NX/Get_Uid.cpp b/qf_nx_itk-master (3)/qf_nx_itk/Connor_NX/Get_Uid.cpp new file mode 100644 index 0000000..226b45d --- /dev/null +++ b/qf_nx_itk-master (3)/qf_nx_itk/Connor_NX/Get_Uid.cpp @@ -0,0 +1,71 @@ +#include "Connor_NX.h" +using namespace std; + + +int Get_Uid(const std::string& name, std::string& res) { + int ifail = ITK_ok; + tag_t member_tag = NULLTAG; + tag_t user_tag = NULLTAG, role_tag = NULLTAG, group_tag = NULLTAG; + char* user_uid = NULL, * role_uid = NULL, * group_uid = NULL; + ITKCALL(ifail = POM_ask_member(&member_tag)); + if (ifail != ITK_ok || member_tag == NULLTAG) { + ifail = OUTPUT_CODE_ERROR; + res.append("获取当前成员失败"); + goto get_uid_end; + } + if (strcmp("user", name.c_str()) == 0) { + ITKCALL(ifail = SA_ask_groupmember_user(member_tag, &user_tag)); + if (ifail != ITK_ok || user_tag == NULLTAG) { + ifail = OUTPUT_CODE_ERROR; + res.append("获取当前用户失败"); + goto get_uid_end; + } + ITK__convert_tag_to_uid(user_tag, &user_uid); + res.append(user_uid); + } + else if (strcmp("role", name.c_str()) == 0) { + ITKCALL(ifail = SA_ask_groupmember_role(member_tag, &role_tag)); + if (ifail != ITK_ok || role_tag == NULLTAG) { + ifail = OUTPUT_CODE_ERROR; + res.append("获取当前用户角色失败"); + goto get_uid_end; + } + ITK__convert_tag_to_uid(role_tag, &role_uid); + res.append(role_uid); + } + else if (strcmp("group", name.c_str()) == 0) { + ITKCALL(ifail = SA_ask_groupmember_group(member_tag, &group_tag)); + if (ifail != ITK_ok || group_tag == NULLTAG) { + ifail = OUTPUT_CODE_ERROR; + res.append("获取当前用户组失败"); + goto get_uid_end; + } + ITK__convert_tag_to_uid(group_tag, &group_uid); + res.append(group_uid); + } + else if(strcmp("parentgroup", name.c_str()) == 0) { + tag_t parent_group_tag = NULLTAG; + ITKCALL(ifail = SA_ask_groupmember_group(member_tag, &group_tag)); + if (ifail != ITK_ok || group_tag == NULLTAG) { + ifail = OUTPUT_CODE_ERROR; + res.append("获取当前用户组失败"); + goto get_uid_end; + } + ITKCALL(ifail = AOM_ask_value_tag(group_tag, "parent", &parent_group_tag)); + if (ifail != ITK_ok) { + ifail = OUTPUT_CODE_ERROR; + res.append("获取当前用户组的父级组织失败"); + goto get_uid_end; + } + if (parent_group_tag != NULLTAG) { + ITK__convert_tag_to_uid(parent_group_tag, &group_uid); + res.append(group_uid); + } + } + +get_uid_end: + DOFREE(user_uid); + DOFREE(group_uid); + DOFREE(role_uid); + return ifail; +} \ No newline at end of file diff --git a/qf_nx_itk-master (3)/qf_nx_itk/Connor_NX/K_autocode_util.cpp b/qf_nx_itk-master (3)/qf_nx_itk/Connor_NX/K_autocode_util.cpp new file mode 100644 index 0000000..62f6e9b --- /dev/null +++ b/qf_nx_itk-master (3)/qf_nx_itk/Connor_NX/K_autocode_util.cpp @@ -0,0 +1,632 @@ +#pragma warning (disable: 4996) +#include "K_autocode_util.h" +#include "kutil.h" + +#ifdef __cplusplus +extern "C" { +#endif + + tag_t getCurrentUser() + { + char* userName; + tag_t user; + POM_get_user(&userName, &user); + return user; + } + + char* filterChar(string str, string filterStr) + { + char* returnValue = (char*)MEM_alloc(10000 * sizeof(char)); + size_t postion = str.find(filterStr); + //printf("str::%s\n",str.c_str()); + if (postion != string::npos && str.length() > 0) + { + string temp1 = ""; + string temp2 = ""; + string temp3 = ""; + string temp4 = ""; + //printf("postion::%d\n",postion); + temp1 = str.substr(0, postion); + temp2 = str.substr(postion + (filterStr.length())); + temp3 = temp1; + temp4 = temp2; + size_t postion2 = temp1.find(","); + //printf("postion2=========%d\n",postion2); + if ((postion2 == (temp1.length() - 1)) && (temp1.length() > 0)) + { + temp3 = temp1.substr(0, postion2); + } + else + { + size_t postion3 = temp2.find(","); + //printf("postion3=========%d\n",postion3); + if (postion3 == 0) + { + if (temp2.length() == 1) + { + temp4 = ""; + } + else + { + temp4 = temp2.substr(1); + } + } + } + //cout << "temp1 value " <tm_mday; + modify_date.hour = p->tm_hour; + modify_date.minute = p->tm_min; + modify_date.month = p->tm_mon; + modify_date.second = p->tm_sec; + modify_date.year = p->tm_year + 1900; + return modify_date; + + } + + + void map_insert(map < string, string >* strmap, string index, string x) + { + //printf("map_insert==1 =====\n"); + //strmap->insert(map < string, string >::value_type(index, x)); + strmap->insert(pair< string, string >(index, x)); + // printf("map_insert==2 =====\n"); + } + int select_id_counter_beforeEnquiry(const char* id_counter, int next_id, tag_t* id_counter_tag, logical* is_new) + { + int ifail = ITK_ok; + + tag_t class_id = NULLTAG; + ITKCALL(POM_class_id_of_class("Cd9_CodeNextID", &class_id)); + + int n_instances = 0, n_ret_instances = 0; + tag_t* instances_tags = NULL, * ret_instances = NULL, the_instance = NULLTAG; + ITKCALL(POM_instances_of_class(class_id, FALSE, &n_ret_instances, &ret_instances)); + + if (n_ret_instances > 0) + { + ITKCALL(POM_load_instances_possible(n_ret_instances, ret_instances, &n_instances, &instances_tags)); + } + + tag_t name_attr = NULLTAG, nextid_attr = NULLTAG; + ITKCALL(POM_attr_id_of_attr("cd9_name", "Cd9_CodeNextID", &name_attr)); + ITKCALL(POM_attr_id_of_attr("cd9_nextID", "Cd9_CodeNextID", &nextid_attr)); + + for (int i = 0; i < n_instances; i++) + { + the_instance = NULLTAG; + //std::cout << "instances_tags[" << i << "] = " << instances_tags[i] << std::endl; + + logical is_loaded = FALSE; + ITKCALL(POM_is_loaded(instances_tags[i], &is_loaded)); + if (!is_loaded) + { + ITKCALL(POM_load_instances_any_class(1, &instances_tags[i], POM_no_lock)); + } + //check is need refresh or not + logical need_refresh = FALSE; + ITKCALL(POM_refresh_required(instances_tags[i], &need_refresh)); + if (need_refresh) + { + POM_refresh_instances_any_class(1, &instances_tags[i], POM_read_lock); + } + char* name_value = NULL; + logical is_it_null = FALSE, is_it_empty = FALSE; + ITKCALL(ifail = POM_ask_attr_string(instances_tags[i], name_attr, + &name_value, &is_it_null, &is_it_empty)); + + //printf("name_value=====================%s\n",name_value); + //printf("id_counter=====================%s\n",id_counter); + if (ifail == ITK_ok && + !is_it_null && + !is_it_empty) + { + if (tc_strcmp(name_value, id_counter) == 0) + { + logical is_it_null = FALSE, is_it_empty = FALSE; + int new_next_id = 0; + the_instance = instances_tags[i]; + ITKCALL(ifail = POM_ask_attr_int(instances_tags[i], nextid_attr, + &new_next_id, &is_it_null, &is_it_empty)); + + int lock_token = 0; + ITKCALL(POM_ask_instance_lock(instances_tags[i], &lock_token)); + if (lock_token != POM_modify_lock) + { + ITKCALL(POM_refresh_instances_any_class(1, &instances_tags[i], POM_modify_lock)); + } + if (new_next_id < next_id) + { + ITKCALL(POM_set_attr_int(1, &instances_tags[i], nextid_attr, next_id)); + } + ITKCALL(ifail = POM_save_instances(1, &instances_tags[i], false)); + ITKCALL(ifail = POM_refresh_instances_any_class(1, &instances_tags[i], POM_no_lock)); + the_instance = instances_tags[i]; + MEM_free(name_value); + break; + } + else + { + int isEqual = 0; + std::vector< std::string > searched_tags1; + std::vector< std::string > searched_tags2; + Split(name_value, "$", searched_tags1); + Split(id_counter, "$", searched_tags2); + //printf("name_value=====================%s\n",name_value); + // printf("id_counter=====================%s\n",id_counter); + + int searchLength1 = (int)searched_tags1.size(); + int searchLength2 = (int)searched_tags2.size(); + //printf("searchLength1=============%d\n",searchLength1); + //printf("searchLength2=============%d\n",searchLength2); + if (searchLength2 == searchLength1) { + int k = 0; + for (int k = 0; k < searchLength1; ++k) + { + if (k > 1) + { + break; + } + if (tc_strcmp(searched_tags1[k].c_str(), searched_tags2[k].c_str()) == 0) + { + isEqual = isEqual + 1; + } + } + if (isEqual > 1) + { + logical is_it_null = FALSE, is_it_empty = FALSE; + int new_next_id = 0; + ITKCALL(ifail = POM_ask_attr_int(instances_tags[i], nextid_attr, + &new_next_id, &is_it_null, &is_it_empty)); + ITKCALL(POM_refresh_instances_any_class(1, &instances_tags[i], POM_modify_lock)); + ITKCALL(POM_set_attr_string(1, &instances_tags[i], name_attr, id_counter)); + if (new_next_id < next_id) + { + ITKCALL(POM_set_attr_int(1, &instances_tags[i], nextid_attr, next_id)); + } + ITKCALL(ifail = POM_save_instances(1, &instances_tags[i], false)); + ITKCALL(ifail = POM_refresh_instances_any_class(1, &instances_tags[i], POM_no_lock)); + the_instance = instances_tags[i]; + break; + } + } + } + MEM_free(name_value); + } + } + + + *id_counter_tag = the_instance; + *is_new = FALSE; + if (the_instance == NULLTAG) + { + tag_t new_inst = NULLTAG; + ITKCALL(POM_create_instance(class_id, &new_inst)); + + ITKCALL(POM_set_attr_string(1, &new_inst, name_attr, id_counter)); + ITKCALL(POM_set_attr_int(1, &new_inst, nextid_attr, next_id)); + + ITKCALL(POM_save_instances(1, &new_inst, false)); + *id_counter_tag = new_inst; + *is_new = TRUE; + } + //MEM_free(instances_tags); + return ITK_ok; + } + + int select_id_counter1(const char* id_counter, int next_id, tag_t* id_counter_tag, logical* is_new, string& isSuccess) + { + int ifail = ITK_ok; + tag_t class_id = NULLTAG; + ITKCALL(POM_class_id_of_class("Cd9_CodeNextID", &class_id)); + tag_t the_instance = NULLTAG; + + tag_t name_attr = NULLTAG, nextid_attr = NULLTAG; + ITKCALL(POM_attr_id_of_attr("cd9_name", "Cd9_CodeNextID", &name_attr)); + ITKCALL(POM_attr_id_of_attr("cd9_nextID", "Cd9_CodeNextID", &nextid_attr)); + const char* source_Pom_Class = "Cd9_CodeNextID"; + const char* selectNextID1 = "Select Cd9_CodeNextID1"; + //char *select_nextidAttrs1[1] = {"puid"}; + const char* select_nextidAttrs1[1] = { "puid" }; + int nextidRows1, nextidCols1; + void*** nextidReport1 = NULL; + ITKCALL(POM_enquiry_create(selectNextID1)); + + ITKCALL(POM_enquiry_add_select_attrs(selectNextID1, source_Pom_Class, + 1, (const char**)select_nextidAttrs1)); + POM_enquiry_set_string_value(selectNextID1, "code_name_value", + 1, (const char**)(&id_counter), POM_enquiry_asc_order); + POM_enquiry_set_attr_expr(selectNextID1, "code_name_exp", + source_Pom_Class, "cd9_name", POM_enquiry_like, "code_name_value"); + POM_enquiry_set_where_expr(selectNextID1, "code_name_exp"); + ITKCALL(POM_enquiry_execute(selectNextID1, &nextidRows1, &nextidCols1, &nextidReport1)); + //printf("nextidRows1===============%d\n",nextidRows1); + //printf("nextidCols1===============%d\n",nextidCols1); + int i = 0; + if (nextidRows1 <= 0) + { + *id_counter_tag = NULLTAG; + MEM_free(nextidReport1); + ITKCALL(ifail = POM_enquiry_delete(selectNextID1)); + return ITK_ok; + } + if (nextidRows1 > 0) + { + tag_t searchTag = NULLTAG; + searchTag = *((tag_t*)nextidReport1[0][0]); + //printf("searchTag===============%d\n",searchTag); + POM_load_instances(1, &searchTag, NULLTAG, POM_no_lock); + logical is_it_null = FALSE, is_it_empty = FALSE; + int new_next_id = 0; + the_instance = searchTag; + ITKCALL(ifail = POM_ask_attr_int(searchTag, nextid_attr, + &new_next_id, &is_it_null, &is_it_empty)); + int lock_token = 0; + ITKCALL(POM_ask_instance_lock(searchTag, &lock_token)); + if (lock_token != POM_modify_lock) + { + ITKCALL(POM_refresh_instances_any_class(1, &searchTag, POM_modify_lock)); + } + if (new_next_id < next_id) + { + ITKCALL(POM_set_attr_int(1, &searchTag, nextid_attr, next_id)); + } + ITKCALL(ifail = POM_save_instances(1, &searchTag, false)); + ITKCALL(ifail = POM_refresh_instances_any_class(1, &searchTag, POM_no_lock)); + the_instance = searchTag; + *id_counter_tag = the_instance; + *is_new = FALSE; + isSuccess.assign(""); + isSuccess.append("Y"); + // printf("searchTag=id_counter_tag==============%d\n",id_counter_tag); + } + MEM_free(nextidReport1); + ITKCALL(ifail = POM_enquiry_delete(selectNextID1)); + + return ifail; + } + + int select_id_counter2(const char* id_counter, int next_id, tag_t* id_counter_tag, logical* is_new, string& isSuccess) { + int ifail = ITK_ok; + const char* source_Pom_Class = "Cd9_CodeNextID"; + tag_t class_id = NULLTAG; + ITKCALL(POM_class_id_of_class("Cd9_CodeNextID", &class_id)); + tag_t the_instance = NULLTAG; + + tag_t name_attr = NULLTAG, nextid_attr = NULLTAG; + ITKCALL(POM_attr_id_of_attr("cd9_name", "Cd9_CodeNextID", &name_attr)); + ITKCALL(POM_attr_id_of_attr("cd9_nextID", "Cd9_CodeNextID", &nextid_attr)); + const char* selectNextID2 = "Select Cd9_CodeNextID2"; + const char* select_nextidAttrs2[1] = { "puid" }; + + int m = 0; + int nextidRows2, nextidCols2; + void*** nextidReport2 = NULL; + ITKCALL(POM_enquiry_create(selectNextID2)); + ITKCALL(POM_enquiry_add_select_attrs(selectNextID2, source_Pom_Class, + 1, (const char**)select_nextidAttrs2)); + std::vector< std::string > searched_tags2; + //printf("id_counter===============%s\n",id_counter); + //printf("next_id===============%d\n",next_id); + + Split(id_counter, "$", searched_tags2); + int searchLength2 = (int)searched_tags2.size(); + //printf("searched_tags2[0]===============%s\n", &(searched_tags2[0])); + char* select_nameValue2[1] = { const_cast(searched_tags2[0].c_str()) }; + + POM_enquiry_set_string_value(selectNextID2, "code_name_value", + 1, (const char**)(select_nameValue2), POM_enquiry_asc_order); + POM_enquiry_set_attr_expr(selectNextID2, "code_name_exp", + source_Pom_Class, "cd9_name", POM_enquiry_like, "code_name_value"); + POM_enquiry_set_where_expr(selectNextID2, "code_name_exp"); + ITKCALL(POM_enquiry_execute(selectNextID2, &nextidRows2, &nextidCols2, &nextidReport2)); + if (nextidRows2 <= 0) + { + *id_counter_tag = NULLTAG; + MEM_free(nextidReport2); + ITKCALL(ifail = POM_enquiry_delete(selectNextID2)); + return ITK_ok; + } + if (nextidRows2 > 0) + { + tag_t searchTag2 = NULLTAG; + searchTag2 = *((tag_t*)nextidReport2[0][0]); + + POM_load_instances(1, &searchTag2, NULLTAG, POM_no_lock); + logical is_it_null = FALSE, is_it_empty = FALSE; + int new_next_id = 0; + ITKCALL(ifail = POM_ask_attr_int(searchTag2, nextid_attr, + &new_next_id, &is_it_null, &is_it_empty)); + //printf("id_counter===%s new_next_id==%d=================\n",id_counter,new_next_id); + int lock_token = 0; + ITKCALL(POM_ask_instance_lock(searchTag2, &lock_token)); + if (lock_token != POM_modify_lock) + { + ITKCALL(POM_refresh_instances_any_class(1, &searchTag2, POM_modify_lock)); + } + ITKCALL(POM_set_attr_string(1, &searchTag2, name_attr, id_counter)); + //printf("id_counter===%s next_id==%d=================\n",id_counter,next_id); + if (new_next_id < next_id) + { + ITKCALL(POM_set_attr_int(1, &searchTag2, nextid_attr, next_id)); + } + ITKCALL(ifail = POM_save_instances(1, &searchTag2, false)); + ITKCALL(ifail = POM_refresh_instances_any_class(1, &searchTag2, POM_no_lock)); + ITKCALL(ifail = POM_ask_attr_int(searchTag2, nextid_attr, &new_next_id, &is_it_null, &is_it_empty)); + //printf("id_counter===%s new_next_id 2==%d=================\n",id_counter,new_next_id); + + the_instance = searchTag2; + *id_counter_tag = the_instance; + *is_new = FALSE; + isSuccess.assign(""); + isSuccess.append("Y"); + } + MEM_free(nextidReport2); + ITKCALL(ifail = POM_enquiry_delete(selectNextID2)); + } + + int select_id_counter(const char* id_counter, int next_id, tag_t* id_counter_tag, logical* is_new) + { + int ifail = ITK_ok; + tag_t class_id = NULLTAG; + ITKCALL(POM_class_id_of_class("Cd9_CodeNextID", &class_id)); + + tag_t name_attr = NULLTAG, nextid_attr = NULLTAG; + ITKCALL(POM_attr_id_of_attr("cd9_name", "Cd9_CodeNextID", &name_attr)); + ITKCALL(POM_attr_id_of_attr("cd9_nextID", "Cd9_CodeNextID", &nextid_attr)); + const char* source_Pom_Class = "Cd9_CodeNextID"; + //printf("select_id_counter=======\n"); + string isSuccess; + isSuccess.assign("N"); + select_id_counter1(id_counter, next_id, id_counter_tag, is_new, isSuccess); + //printf("isSuccess1===========%s\n",isSuccess.c_str()); + if (tc_strcmp(isSuccess.c_str(), "Y") != 0) { + select_id_counter2(id_counter, next_id, id_counter_tag, is_new, isSuccess); + // printf("isSuccess2===========%s\n",isSuccess.c_str()); + } + //printf("isSuccess13===========%s\n",isSuccess.c_str()); + if (tc_strcmp(isSuccess.c_str(), "Y") != 0) { + tag_t new_inst = NULLTAG; + ITKCALL(POM_create_instance(class_id, &new_inst)); + + ITKCALL(POM_set_attr_string(1, &new_inst, name_attr, id_counter)); + ITKCALL(POM_set_attr_int(1, &new_inst, nextid_attr, next_id)); + + ITKCALL(POM_save_instances(1, &new_inst, false)); + *id_counter_tag = new_inst; + *is_new = TRUE; + } + //printf("id_counter_tag4===========%d\n",id_counter_tag); + + //MEM_free(instances_tags); + return ITK_ok; + } + int load_current_number(tag_t id_counter_tag, const char* id_counter, int* next_id, logical* is_new) + { + int ifail = ITK_ok, i = 0, + new_next_id = *next_id; + + logical is_valid = FALSE; + ITKCALL(POM_is_tag_valid(id_counter_tag, &is_valid)); + if (id_counter_tag == NULLTAG || !is_valid) + { + int initial_next_id = 1; + ifail = select_id_counter(id_counter, initial_next_id, &id_counter_tag, is_new); + TEST_ERROR(ifail); + } + + //check is loaded or not + logical is_loaded = FALSE; + ITKCALL(POM_is_loaded(id_counter_tag, &is_loaded)); + if (!is_loaded) + { + ITKCALL(POM_load_instances_any_class(1, &id_counter_tag, POM_no_lock)); + //cout << "load again!" << endl; + } + + for (i = 0; i < GET_ID_RETRIES && ifail != ITK_ok; i++) + { + ITKCALL(ifail = POM_refresh_instances_any_class(1, + &id_counter_tag, POM_no_lock)); + } + + TEST_POM_ERROR(ifail); + + tag_t nextid_attr = NULLTAG; + logical is_it_null = FALSE, is_it_empty = FALSE; + ITKCALL(ifail = POM_attr_id_of_attr("cd9_nextID", "Cd9_CodeNextID", &nextid_attr)); + ITKCALL(ifail = POM_ask_attr_int(id_counter_tag, nextid_attr, + &new_next_id, &is_it_null, &is_it_empty)); + //printf("id_counter=============%d\n",id_counter); + //printf("new_next_id=============%d\n",new_next_id); + TEST_POM_ERROR(ifail); + if (!is_it_null && !is_it_empty) + { + *next_id = new_next_id; + } + return ITK_ok; + } + int filterNewSequence(int new_index, int step) + { + int new_id = new_index + step; + char* optionValue; + ITKCALL(PREF_ask_char_value(origin_autocode_sequence_exclude_number, 0, &optionValue)); + //printf(" exclude_number = %s\n",optionValue); + if (optionValue == NULL) + { + return new_id; + } + else + { + string str2; + char new_id_str[64]; + sprintf(new_id_str, "%d", new_id); + str2 = new_id_str; + //printf(" exclude_number !=NULL ::str2== %s\n",str2.c_str()); + size_t postion = str2.find(optionValue); + if (postion != string::npos) + { + //printf(" find exclude_number new_id==%d\n",new_id); + new_id = filterNewSequence(new_id, step); + } + } + //printf(" filterNewSequence ::new_id === %d\n",new_id); + return new_id; + } + + + int get_sequence_no(const char* pattern_code, int length, int start_index, int end_index, int step, int* new_id, const char* code_exclude_character) + { + int ifail = ITK_ok; + tag_t id_counter_tag = NULLTAG; + + char id_counter[BUFSIZ] = ""; + sprintf(id_counter, "%s$%d$%d$%d$%d", pattern_code, length, start_index, end_index, step); + //std::cout << "id_counter : " << id_counter << std::endl; + + logical is_new = FALSE; + TEST_ERROR(ifail = select_id_counter(id_counter, start_index, &id_counter_tag, &is_new)); + //std::cout << "is_new : " << is_new << ", id_counter_tag : " << id_counter_tag << std::endl; + + int new_index = 1; + TEST_ERROR(ifail = load_current_number(id_counter_tag, id_counter, &new_index, &is_new)); + //std::cout << "new_index : " << is_new << ", is_new : " << is_new << std::endl; + + tag_t nextid_attr = NULLTAG; + ITKCALL(ifail = POM_attr_id_of_attr("cd9_nextID", "Cd9_CodeNextID", &nextid_attr)); + + logical can_modify = FALSE; + ITKCALL(POM_modifiable(id_counter_tag, &can_modify)); + //std::cout << "can_modify : " << (can_modify ? "true" : "false") << std::endl; + if (!can_modify) + { + ITKCALL(POM_refresh_instances(1, &id_counter_tag, NULLTAG, POM_modify_lock)); + } + + if (is_new) + { + *new_id = start_index; + ITKCALL(ifail = POM_set_attr_int(1, &id_counter_tag, nextid_attr, start_index)); + TEST_POM_ERROR(ifail); + } + else + { + if (new_index + step > end_index) + { + *new_id = new_index + step; + return -1; + } + + int id = new_index + step; + //当以数字开始,过滤掉以4开始编码 + if (tc_strlen(pattern_code) > 0) { + char startChar[8]; + char startChar2[8]; + memcpy(startChar, pattern_code, 1); + memcpy(startChar2, pattern_code, 3); + //printf("startChar====%s\n",startChar); + boolean isDigit = isdigit(startChar[0]); + //printf("isDigit====%d\n",isDigit); + + if ((isDigit) || (tc_strcasecmp(startChar2, "BJ0") == 0)) { + id = filterNewSequence(new_index, step); + } + //printf("filterNewSequence====%d\n",id); + } + *new_id = id; + ITKCALL(ifail = POM_set_attr_int(1, &id_counter_tag, nextid_attr, id)); + } + + ITKCALL(ifail = POM_save_instances(1, &id_counter_tag, true)); + //ITKCALL(ifail = POM_refresh_instances_any_class(1, &id_counter_tag, POM_no_lock)); + TEST_POM_ERROR(ifail); + //std::cout << "new_id : " << *new_id << endl; + + if (tc_strcmp(code_exclude_character, "") == 0) + { + return ITK_ok; + } + else + { + if (filterItemID(code_exclude_character, new_index + step)) + { + return ITK_ok; + } + else + { + get_sequence_no(pattern_code, length, start_index, end_index, step, new_id, code_exclude_character); + } + } + return ifail; + } + + int filterItemID(const char* filterStr, int new_id) + { + char id_string[64]; + sprintf(id_string, "%d", new_id); + string str2; + str2.c_str(); + str2 = id_string; + //cout << " str2 =====" << str2 < 0) + { + pad_string[left_length] = '\0'; + for (int i = 0; i < left_length; i++) + { + pad_string[i] = '0'; + } + sprintf(final_code, "%s%s%s", pattern_code, pad_string, index_string); + } + else + { + sprintf(final_code, "%s%s", pattern_code, index_string); + } + *generated_num = (char*)MEM_alloc(sizeof(char) * (strlen(final_code) + 1)); + tc_strcpy(*generated_num, final_code); + return ITK_ok; + } + +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/qf_nx_itk-master (3)/qf_nx_itk/Connor_NX/K_autocode_util.h b/qf_nx_itk-master (3)/qf_nx_itk/Connor_NX/K_autocode_util.h new file mode 100644 index 0000000..0eb8c83 --- /dev/null +++ b/qf_nx_itk-master (3)/qf_nx_itk/Connor_NX/K_autocode_util.h @@ -0,0 +1,109 @@ +#include +#include +#include +#include +#include +#include + + +//tc +#include +#include +#include +#include +#include +#include +#include +//#include + +#include +#include +#include +#include +#include +#include +#include +#include "origin_PropNames.h" +#include + +#include + + +using namespace std; + +//#include +#ifdef __cplusplus +extern "C" { +#endif + +#define GET_ID_RETRIES 10 +#define CYCLE_TIMES 10 +#define STARTNUMBER 1 +#define PADNUMBER 4 +#define RETRY_STRING "10" +#define HANDLE_ERROR_S1(E,S) \ + { EMH_store_initial_error_s1(EMH_severity_error,(E),(S)); return(E); } + +#define REPORT_IFAIL(M) \ + ifail?printf("%s : ERROR : ifail = %d\n",M,ifail):printf("%s : Ok\n",M) + +#define HANDLE_ERROR(E) \ + { EMH_store_initial_error(EMH_severity_error,(E)); return(E); } + +#define HANDLE_ERROR_S1(E,S) \ + { EMH_store_initial_error_s1(EMH_severity_error,(E),(S)); return(E); } + +#define HANDLE_ERROR_AND_RELEASE(E,I) \ + { \ + (void)release_number(I); \ + EMH_store_initial_error(EMH_severity_error,(E)); \ + return(E); \ +} + +#define TEST_ERROR(E) \ + if ((E) != ITK_ok) return(E); + +#define TEST_POM_ERROR(E) \ + if ((E) != ITK_ok) HANDLE_ERROR(E) + +#define TEST_ERROR_AND_RELEASE(E,I) \ + if ((E) != ITK_ok) { (void)release_number(I); return(E); } + + /* Define the number of retries when fetching the next ID. */ + /* This must be stored in both numeric and string forms. */ +#define GET_ID_RETRIES 10 +#define RETRY_STRING "10" + + /* Empty string test macro */ +#define IS_EMPTY(S) (!(*(S))) + + /* Define the methods by which a new item name can be obtained */ +#define SEED_METHOD 0 +#define BUILD_METHOD 1 + + /* The following define the maximum index number to be used. * + * Note that the actual maximum is one less than MAXNUM. * + * NUMERIC_LIMIT must be large enough to store decimal string * + * version of MAXNUM plus a NULL terminator. */ +#define NUMERIC_LIMIT 12 +#define MAXNUM 0x7FFFFFFF + /* define the class for which id and rev is generated */ +#define CLASS_IS_ITEM 0 +#define CLASS_IS_DATASET 1 + +#define origin_autocode_sequence_exclude_number "origin_autocode_sequence_exclude_number" + + tag_t getCurrentUser(); + char* filterChar(string str, string filterStr); + date_t getCurrentDate(); + void map_insert(map < string, string >* strmap, string index, string x); + int select_id_counter(const char* id_counter, int next_id, tag_t* id_counter_tag, logical* is_new); + int load_current_number(tag_t id_counter_tag, const char* id_counter, int* next_id, logical* is_new); + //int load_current_number(tag_t id_counter_tag, const char *id_counter, int *next_id, logical *is_new); + int get_sequence_no(const char* pattern_code, int length, int start_index, int end_index, int step, int* new_id, const char* code_exclude_character); + int generate_num(const char* pattern_code, int length, int new_index, char** generated_num); + int filterItemID(const char* filterStr, int new_id); + int isContainsStr(char* sourceStr, char* containsStr); +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/qf_nx_itk-master (3)/qf_nx_itk/Connor_NX/K_getComponentPropertyValue.cpp b/qf_nx_itk-master (3)/qf_nx_itk/Connor_NX/K_getComponentPropertyValue.cpp new file mode 100644 index 0000000..574c997 --- /dev/null +++ b/qf_nx_itk-master (3)/qf_nx_itk/Connor_NX/K_getComponentPropertyValue.cpp @@ -0,0 +1,370 @@ +#pragma warning (disable: 4996) +#include "Connor_NX.h" +#include "origin_PropNames.h" +#include + +const char* getChildrenNodesString(const char** propNames, const char** propValues, int length) +{ + int ifail = ITK_ok; + const char* class_name = "Cd9_CodeRelation"; + const char* selectTreeNode = "Select Cd9_CodeRelation1"; + const char* select_nextidAttrs[1] = { CodeRelation_children_nodes }; + int rows, cols; + void*** report = NULL; + int i = 0; + const char* strValues; + + ITKCALL(POM_enquiry_create(selectTreeNode)); + ITKCALL(POM_enquiry_add_select_attrs(selectTreeNode, class_name, + 1, (const char**)select_nextidAttrs)); + + if (length == 1) + { + if (tc_strlen(propValues[0]) == 0) + { + ifail = POM_enquiry_set_attr_expr(selectTreeNode, "expr1", class_name, propNames[0], POM_enquiry_is_null, NULL); + } + else + { + ifail = POM_enquiry_set_string_value(selectTreeNode, "prop1", 1, (const char**)&propValues[0], POM_enquiry_bind_value); + ifail = POM_enquiry_set_attr_expr(selectTreeNode, "expr1", class_name, propNames[0], POM_enquiry_equal, "prop1"); + } + ifail = POM_enquiry_set_where_expr(selectTreeNode, "expr1"); + } + else { + if (tc_strlen(propValues[0]) == 0) + { + ifail = POM_enquiry_set_attr_expr(selectTreeNode, "expr1", class_name, propNames[0], POM_enquiry_is_null, NULL); + } + else + { + ifail = POM_enquiry_set_string_value(selectTreeNode, "prop1", 1, (const char**)&propValues[0], POM_enquiry_bind_value); + ifail = POM_enquiry_set_attr_expr(selectTreeNode, "expr1", class_name, propNames[0], POM_enquiry_equal, "prop1"); + } + + if (tc_strlen(propValues[1]) == 0) + { + ifail = POM_enquiry_set_attr_expr(selectTreeNode, "expr2", class_name, propNames[1], POM_enquiry_is_null, NULL); + } + else + { + ifail = POM_enquiry_set_string_value(selectTreeNode, "prop2", 1, (const char**)&propValues[1], POM_enquiry_bind_value); + ifail = POM_enquiry_set_attr_expr(selectTreeNode, "expr2", class_name, propNames[1], POM_enquiry_equal, "prop2"); + } + POM_enquiry_set_expr(selectTreeNode, "expr", "expr1", POM_enquiry_and, "expr2"); + ifail = POM_enquiry_set_where_expr(selectTreeNode, "expr"); + } + + ITKCALL(POM_enquiry_execute(selectTreeNode, &rows, &cols, &report)); + //printf("nextidRows===============%d\n",rows); + if (rows > 0) + { + strValues = (char*)report[0][0]; + } + else + { + strValues = ""; + } + POM_enquiry_delete(selectTreeNode); + return strValues; +} + +int isContainChildrenNode(const char** propNames, const char** propValues, int length) +{ + int returnValue = 0;; + const char* value = getChildrenNodesString(propNames, propValues, length); + if (tc_strlen(value) > 0) + { + returnValue = 1; + } + return returnValue; +} + + +char* getCodeNodeInfos(tag_t tag, vector propNames, int propLength, const char* parentString, int isNewComponent) +{ + int ifail = 0; + int allocLength = 0; + const char* class_name = "Cd9_TreeAndListCodeNode"; + const char** values = (const char**)MEM_alloc(propLength * sizeof(const char*)); + for (int m = 0; m < propLength; m++) { + tag_t prop_tag; + // printf("propNames[m].c_str()====%s\n",propNames[m].c_str()); + if (tc_strcmp(propNames[m].c_str(), TreeAndListCodeNode_isContainsChildren) == 0) + { + if (isNewComponent == 1) + { + values[m] = (char*)MEM_alloc(3 * sizeof(char)); + allocLength += 3; + values[m] = "no"; + continue; + } + char* value; + POM_tag_to_uid(tag, &value); + const char* isContainChildrenPropNames[2] = { CodeRelation_parent_nodes,CodeRelation_current_node }; + const char* isContainChildrenValues[2] = { parentString, value }; + int isContains = isContainChildrenNode(isContainChildrenPropNames, isContainChildrenValues, 2); + if (isContains == 1) + { + values[m] = (char*)MEM_alloc(4 * sizeof(char)); + allocLength += 4; + values[m] = "yes"; + } + else { + values[m] = (char*)MEM_alloc(3 * sizeof(char)); + allocLength += 3; + values[m] = "no"; + } + MEM_free(value); + continue; + } + tag_t attr_id = NULLTAG; + // printf("Check Property: %s\n", propNames[m].c_str()); + ITKCALL(POM_attr_id_of_attr(propNames[m].c_str(), + class_name, &attr_id)); + if (attr_id) + { + if (tc_strcmp(propNames[m].c_str(), TreeAndListCodeNode_node_name) == 0 + || tc_strcmp(propNames[m].c_str(), TreeAndListCodeNode_node_type) == 0 + || tc_strcmp(propNames[m].c_str(), TreeAndListCodeNode_node_value) == 0 + || tc_strcmp(propNames[m].c_str(), TreeAndListCodeNode_node_desc) == 0 + || tc_strcmp(propNames[m].c_str(), TreeAndListCodeNode_code_style) == 0 + ) { + char* value; + logical is_it_null = FALSE; + logical is_it_empty = FALSE; + ITKCALL(POM_ask_attr_string(tag, attr_id, + &value, &is_it_null, &is_it_empty)); + if (is_it_null) + { + values[m] = (char*)MEM_alloc(5 * sizeof(char)); + allocLength += 5; + values[m] = "null"; + } + else { + values[m] = (char*)MEM_alloc(tc_strlen(value) * sizeof(char)); + allocLength += tc_strlen(value); + values[m] = value; + } + } + if ( + tc_strcmp(propNames[m].c_str(), TreeAndListCodeNode_is_root) == 0 + || tc_strcmp(propNames[m].c_str(), TreeAndListCodeNode_is_lock) == 0 + || tc_strcmp(propNames[m].c_str(), TreeAndListCodeNode_isDefaultSelected) == 0 + ) { + logical value; + logical is_it_null = FALSE; + logical is_it_empty = FALSE; + ITKCALL(POM_ask_attr_logical(tag, attr_id, + &value, &is_it_null, &is_it_empty)); + if ((is_it_null) || (!value)) + { + values[m] = (char*)MEM_alloc(3 * sizeof(char)); + allocLength += 3; + values[m] = "no"; + + } + else { + values[m] = (char*)MEM_alloc(4 * sizeof(char)); + allocLength += 4; + values[m] = "yes"; + } + } + if (tc_strcmp(propNames[m].c_str(), TreeAndListCodeNode_rule_node) == 0 + || tc_strcmp(propNames[m].c_str(), TreeAndListCodeNode_create_user) == 0 + || tc_strcmp(propNames[m].c_str(), TreeAndListCodeNode_last_revise_user) == 0 + ) { + tag_t value; + logical is_it_null = FALSE; + logical is_it_empty = FALSE; + ITKCALL(POM_ask_attr_tag(tag, attr_id, + &value, &is_it_null, &is_it_empty)); + + if ((!is_it_null) && (!is_it_empty) && (value != NULLTAG)) + { + if (tc_strcmp(propNames[m].c_str(), TreeAndListCodeNode_rule_node) == 0) + { + char* name; + ITKCALL(ifail = AOM_ask_value_string(value, TreeAndListCodeNode_node_name, &name)); + { + values[m] = (char*)MEM_alloc(tc_strlen(name) * sizeof(char)); + allocLength += tc_strlen(name); + values[m] = name; + } + } + else { + //char name[WSO_desc_size_c + 1]=""; + char* name = NULL; + SA_ask_user_person_name2(value, &name); + values[m] = (char*)MEM_alloc(tc_strlen(name) * sizeof(char)); + allocLength += tc_strlen(name); + values[m] = name; + } + } + else { + values[m] = (char*)MEM_alloc(5 * sizeof(char)); + allocLength += 5; + values[m] = "null"; + } + } + if (tc_strcmp(propNames[m].c_str(), TreeAndListCodeNode_create_date) == 0 + || tc_strcmp(propNames[m].c_str(), TreeAndListCodeNode_last_revise_date) == 0 + ) { + date_t value; + logical is_it_null = FALSE; + logical is_it_empty = FALSE; + ITKCALL(POM_ask_attr_date(tag, attr_id, + &value, &is_it_null, &is_it_empty)); + if ((is_it_null) || (is_it_empty)) + { + values[m] = (char*)MEM_alloc(5 * sizeof(char)); + allocLength += 5; + values[m] = "null"; + } + else { + char str_date[30] = ""; + + sprintf(str_date, "%4d/%02d/%02d %02d:%02d:%02d", value.year, value.month + 1, value.day, + value.hour, value.minute, value.second); + values[m] = (char*)MEM_alloc(tc_strlen(str_date) * sizeof(char)); + allocLength += tc_strlen(str_date); + values[m] = str_date; + } + } + //printf("values[m]====%s\n",values[m]); + } + else + { + values[m] = (char*)MEM_alloc(5 * sizeof(char)); + allocLength += 5; + values[m] = "null"; + } + } + + allocLength = allocLength + (propLength * 2); + char* infos = (char*)MEM_alloc(allocLength * sizeof(char)); + tc_strcpy(infos, ""); + for (int i = 0; i < propLength; i++) + { + tc_strcat(infos, values[i]); + tc_strcat(infos, "&&"); + } + return infos; +} + +int GET_TREE_AND_LIST_STRING_VALUES(const std::string& searchStr, std::string& res) +{ + int ifail = ITK_ok; + int i, propLength, tagLength; + vector tags; + const char* class_name = "Cd9_TreeAndListCodeNode"; + vector propNames; + string parentString; + vector searchStrSplit; + Split(searchStr, SPLITTER, searchStrSplit); + int size = searchStrSplit.size(); + char* rtnStr = NULL; + const char** values = NULL; + if (size == 0) { + return ifail; + } + //printf("\nGET_TREE_AND_LIST_STRING_VALUES\n%s\n", searchStr.c_str()); + //printf("PARENTSTRING: [%s]\n", searchStrSplit[0].c_str()); + parentString = searchStrSplit[0]; + for (i = 1; i < size; i++) { + tag_t tag = NULLTAG; + string str = searchStrSplit[i]; + //printf("UID: [%s]\n", str.c_str()); + if (strcmp(SPLIT_SECTION, str.c_str()) == 0) { + i++; + break; + } + ITK__convert_uid_to_tag(str.c_str(), &tag); + if (tag == NULLTAG) { + res.append("未找到对象 UID:").append(str); + ifail = OUTPUT_CODE_ERROR; + goto GET_TREE_AND_LIST_STRING_VALUES_END; + } + tags.push_back(tag); + } + propLength = size - i; + for (; i < size; i++) { + string propName = searchStrSplit[i]; + //printf("PROPNAME: [%s]\n", propName.c_str()); + propNames.push_back(propName); + } + + tagLength = tags.size(); + values = (const char**)MEM_alloc(tagLength * sizeof(char*)); + + + rtnStr = (char*)MEM_alloc(40000 * sizeof(char)); + memset(rtnStr, 0, sizeof(rtnStr)); + for (int i = 0; i < tagLength; i++) + { + tag_t tag = tags[i]; + //printf("Load Tag\n"); + ITKCALL(ifail = AOM_load(tag)); + if (ifail != ITK_ok) { + continue; + } + // printf("\n ---------->i=%d, parentString=%s",i,parentString); + char* info = getCodeNodeInfos(tags[i], propNames, propLength, parentString.c_str(), 0); + values[i] = (char*)MEM_alloc(tc_strlen(info) * sizeof(char)); + values[i] = info; + // printf("\n values[i]==============%s\n",values[i]); + strcat(rtnStr, info); + strcat(rtnStr, "@@"); + ITKCALL(ifail = AOM_unload(tag)); + } + res.append(rtnStr); +GET_TREE_AND_LIST_STRING_VALUES_END: + propNames.clear(); + tags.clear(); + return ifail; +} + +int GET_TREE_AND_LIST_STRING_VALUE(const std::string& searchStr, std::string& res) { + int ifail = ITK_ok; + int i, propLength, tagLength; + tag_t tag; + vector propNames; + const char* class_name = "Cd9_TreeAndListCodeNode"; + char* info = NULL; + vector searchStrSplit; + Split(searchStr, SPLITTER, searchStrSplit); + int size = searchStrSplit.size(); + if (size == 0) { + return ifail; + } + + propLength = size - 1; + + //printf("\nGET_TREE_AND_LIST_STRING_VALUE\n%s\n", searchStr.c_str()); + //printf("UID: [%s]\n", searchStrSplit[0].c_str()); + ITK__convert_uid_to_tag(searchStrSplit[0].c_str(), &tag); + if (tag == NULLTAG) { + res.append("未找到对象 UID:").append(searchStrSplit[0]); + ifail = OUTPUT_CODE_ERROR; + goto GET_TREE_AND_LIST_STRING_VALUE_END; + } + //printf("Find Tag\n"); + + for (i = 0; i < propLength; i++) { + string propName = searchStrSplit[i + 1]; + propNames.push_back(propName); + // printf(">> %s\n", propNames[i].c_str()); + } + //printf("Load Tag\n"); + ITKCALL(ifail = AOM_load(tag)); + if (ifail != ITK_ok) { + res.append("无法加载实例 UID:").append(searchStrSplit[0]); + goto GET_TREE_AND_LIST_STRING_VALUE_END; + } + //printf("Load Tag Complete\n"); + info = getCodeNodeInfos(tag, propNames, propLength, "", 1); + res.append(info); + ITKCALL(ifail = AOM_unload(tag)); +GET_TREE_AND_LIST_STRING_VALUE_END: + return ifail; +} \ No newline at end of file diff --git a/qf_nx_itk-master (3)/qf_nx_itk/Connor_NX/K_invoke_pdm_server.cpp b/qf_nx_itk-master (3)/qf_nx_itk/Connor_NX/K_invoke_pdm_server.cpp new file mode 100644 index 0000000..6562290 --- /dev/null +++ b/qf_nx_itk-master (3)/qf_nx_itk/Connor_NX/K_invoke_pdm_server.cpp @@ -0,0 +1,223 @@ + +#include "Connor_NX.h" + +#define K_GetPrefValue 0 +#define K_Parse_NX_Template_By_ID 1 +#define K_Read_NX_Image_By_ID 2 +#define K_Download_Dataset_By_UID 3 +#define INPUTCODE_GET_ALL_SUB_TYPES 4 +#define INPUTCODE_SEARCH_AUTOCODE_NODE 5 +#define INPUTCODE_GET_UID 6 +#define INPUTCODE_SEARCH_AUTOCODE_SEGMENT 7 +#define INPUTCODE_SEARCH_AUTOCODE_USER 8 +#define INPUTCODE_GET_TREE_AND_LIST_STRING_VALUE 9 +#define INPUTCODE_GET_NEW_REV_ID 10 +#define INPUTCODE_GET_LOGICAL_PROP_VALUE 11 +#define INPUTCODE_SEARCH_TREE_OR_LIST_NODE 12 +#define INPUTCODE_GET_TREE_AND_LIST_STRING_VALUES 13 +#define INPUTCODE_SEARCH_PARENT_TREE_OR_LIST_NODE 14 +#define INPUTCODE_ICS_GET_ATTRIBUTES 15 +#define INPUTCODE_ICS_ATTR_IS_REFERENCE_ATTRIBUTE 16 +#define INPUTCODE_ICS_ATTR_ASK_PROPERTY 17 +#define INPUTCODE_ICS_ATTR_ASK_KEYLOV 18 +#define INPUTCODE_GET_DISPLAY_PROP_VALUE 19 +#define INPUTCODE_FIND_LOV_BY_NAME 20 +#define INPUTCODE_GET_REFERENCE_PROP_VALUE 21 +#define INPUTCODE_QUERY_PART_NO 22 +#define INPUTCODE_DELETE_RECYCLE_ID 23 +#define INPUTCODE_ITEM_EXIST 24 +#define INPUTCODE_ITEM_CREATE 25 +#define INPUTCODE_ADD_TO_NEWSTUFF 26 +#define INPUTCODE_GET_CLASSIFICATION_ID 27 +#define INPUTCODE_SEND_ITEM_TO_CLASSIFICATION 28 +#define INPUTCODE_GET_ITEMTYPE_BY_ID 29 +#define INPUTCODE_GET_REVUID_BY_ID 30 +#define INPUTCODE_ITEM_UPDATE 31 +#define INPUTCODE_READ_NX_TEMPLATE_BOM 32 +#define INPUTCODE_GET_CLONE_INFO 33 +#define INPUTCODE_GET_LATEST_ITEM_REVISION 34 +#define INPUTCODE_GRANT_PRIVILEGE 35 +#define INPUTCODE_GET_UOM_TAGS 36 +#define INPUTCODE_UPDATE_UOM 37 +#define INPUTCODE_GET_REFERENCE_PROP_VALUE_ARRAY 38 +#define INPUTCODE_ICS_ATTR_ASK_METRIC_UNIT 39 +using namespace std; + +int GetPrefValue(const std::string &pref_name, std::string &prefValue) { + int ifail = ITK_ok; + int pref_len = 0; + char** pref_vals = NULL; + printf("查询首选项:%s\n", pref_name.c_str()); + if (tc_strlen(pref_name.c_str()) == 0) { + return ifail; + } + ITKCALL(ifail = PREF_refresh(pref_name.c_str())); + if (ifail != ITK_ok) { + prefValue.append(("未配置首选项:")).append(pref_name); + return ifail; + } + ITKCALL(ifail = PREF_ask_char_values(pref_name.c_str(), &pref_len, &pref_vals)); + for (int i = 0;i < pref_len;i++) { + printf(">> %d. %s\n", i + 1, pref_vals[i]); + prefValue.append(pref_vals[i]); + if (i != pref_len - 1) { + prefValue.append(SPLITTER); + } + } + if (ifail != ITK_ok) { + prefValue.append(("未配置首选项:")).append(pref_name); + } + return ifail; +} + +DLLAPI int K_invoke_pdm_server(int *decision, va_list args) { + int ifail = ITK_ok; + // get the input parameters from the va_list: + int input_code = va_arg(args, int); + char* input_str = va_arg(args, char*); + int* output_code = va_arg(args, int*); + char** output_str = va_arg(args, char**); + // set decision. We'll let other customizations have + // a chance to handle this PDM Server call too. + *decision = ALL_CUSTOMIZATIONS; + + // I do all intermediate string processing with std::string's + // instead of char* strings. Later I'll copy the final + // std::string's contents to the char* output_str + std::string output_string; + + // pass the input_code to a switch(): + switch (input_code) + { + case K_GetPrefValue: + *output_code = GetPrefValue(input_str, output_string); + break; + case K_Read_NX_Image_By_ID: + *output_code = Read_NX_Image_By_ID(input_str, output_string); + break; + case K_Parse_NX_Template_By_ID: + *output_code = Parse_NX_Template_By_ID(input_str, output_string); + break; + case K_Download_Dataset_By_UID: + *output_code = Download_Dataset_By_UID(input_str, output_string); + break; + case INPUTCODE_GET_ALL_SUB_TYPES: + *output_code = Get_All_SubTypes(input_str, output_string); + break; + case INPUTCODE_SEARCH_AUTOCODE_NODE: + *output_code = SEARCH_AUTOCODE_NODE(input_str, output_string); + break; + case INPUTCODE_GET_UID: + *output_code = Get_Uid(input_str, output_string); + break; + case INPUTCODE_SEARCH_AUTOCODE_SEGMENT: + *output_code = SEARCH_AUTOCODE_SEGMENT(input_str, output_string); + break; + case INPUTCODE_SEARCH_AUTOCODE_USER: + *output_code = SEARCH_AUTOCODE_USER(input_str, output_string); + break; + case INPUTCODE_GET_TREE_AND_LIST_STRING_VALUE: + *output_code = GET_TREE_AND_LIST_STRING_VALUE(input_str, output_string); + break; + case INPUTCODE_GET_NEW_REV_ID: + *output_code = GET_NEW_REV_ID(input_str, output_string); + break; + case INPUTCODE_GET_LOGICAL_PROP_VALUE: + *output_code = GET_LOGICAL_PROP_VALUE(input_str, output_string); + break; + case INPUTCODE_SEARCH_TREE_OR_LIST_NODE: + *output_code = SEARCH_TREE_OR_LIST_NODE(input_str, output_string); + break; + case INPUTCODE_GET_TREE_AND_LIST_STRING_VALUES: + *output_code = GET_TREE_AND_LIST_STRING_VALUES(input_str, output_string); + break; + case INPUTCODE_SEARCH_PARENT_TREE_OR_LIST_NODE: + *output_code = SEARCH_PARENT_TREE_OR_LIST_NODE(input_str, output_string); + break; + case INPUTCODE_ICS_GET_ATTRIBUTES: + *output_code = ICS_GET_ATTRIBUTES(input_str, output_string); + break; + case INPUTCODE_ICS_ATTR_IS_REFERENCE_ATTRIBUTE: + *output_code = ICS_ATTR_IS_REFERENCE_ATTRIBUTE(input_str, output_string); + break; + case INPUTCODE_ICS_ATTR_ASK_PROPERTY: + *output_code = ICS_ATTR_ASK_PROPERTY(input_str, output_string); + break; + case INPUTCODE_ICS_ATTR_ASK_KEYLOV: + *output_code = ICS_ATTR_ASK_KEYLOV(input_str, output_string); + break; + case INPUTCODE_GET_DISPLAY_PROP_VALUE: + *output_code = GET_DISPLAY_PROP_VALUE(input_str, output_string); + break; + case INPUTCODE_FIND_LOV_BY_NAME: + *output_code = FIND_LOV_BY_NAME(input_str, output_string); + break; + case INPUTCODE_GET_REFERENCE_PROP_VALUE: + *output_code = GET_REFERENCE_PROP_VALUE(input_str, output_string); + break; + case INPUTCODE_QUERY_PART_NO: + *output_code = QUERY_PART_NO(input_str, output_string); + break; + case INPUTCODE_DELETE_RECYCLE_ID: + *output_code = DELETE_RECYCLE_ID(input_str, output_string); + break; + case INPUTCODE_ITEM_EXIST: + *output_code = ITEM_EXIST(input_str, output_string); + break; + case INPUTCODE_ITEM_CREATE: + *output_code = ITEM_CREATE(input_str, output_string); + break; + case INPUTCODE_ADD_TO_NEWSTUFF: + *output_code = ADD_TO_NEWSTUFF(input_str, output_string); + break; + case INPUTCODE_GET_CLASSIFICATION_ID: + *output_code = GET_CLASSIFICATION_ID(input_str, output_string); + break; + case INPUTCODE_SEND_ITEM_TO_CLASSIFICATION: + *output_code = SEND_ITEM_TO_CLASSIFICATION(input_str, output_string); + break; + case INPUTCODE_GET_ITEMTYPE_BY_ID: + *output_code = GET_ITEMTYPE_BY_ID(input_str, output_string); + break; + case INPUTCODE_GET_REVUID_BY_ID: + *output_code = GET_REVUID_BY_ID(input_str, output_string); + break; + case INPUTCODE_ITEM_UPDATE: + *output_code = ITEM_UPDATE(input_str, output_string); + break; + case INPUTCODE_READ_NX_TEMPLATE_BOM: + *output_code = READ_NX_TEMPLATE_BOM(input_str, output_string); + break; + case INPUTCODE_GET_CLONE_INFO: + *output_code = GET_CLONE_INFO(input_str, output_string); + break; + case INPUTCODE_GET_LATEST_ITEM_REVISION: + *output_code = GET_LATEST_ITEM_REVISION(input_str, output_string); + break; + case INPUTCODE_GRANT_PRIVILEGE: + *output_code = GRANT_PRIVILEGE(input_str, output_string); + break; + case INPUTCODE_GET_UOM_TAGS: + *output_code = GET_UOM_TAGS(input_str, output_string); + break; + case INPUTCODE_UPDATE_UOM: + *output_code = UPDATE_UOM(input_str, output_string); + break; + case INPUTCODE_GET_REFERENCE_PROP_VALUE_ARRAY: + *output_code = GET_REFERENCE_PROP_VALUE_ARRAY(input_str, output_string); + break; + case INPUTCODE_ICS_ATTR_ASK_METRIC_UNIT: + *output_code = ICS_ATTR_ASK_METRIC_UNIT(input_str, output_string); + break; + default: + *decision = NO_CUSTOMIZATION; // do nothing INPUTCODE_ITEM_UPDATE + // code may be meant for another library using PDM Server + } + // allocate memory for output string and copy + // std::string's contents to it: + TC_write_syslog("NX Return [%d]: %s", *output_code, output_string.c_str()); + *output_str =(char*) malloc(sizeof(char) * (output_string.length() + 1)); + tc_strcpy(*output_str, output_string.c_str()); + return ifail; +} + diff --git a/qf_nx_itk-master (3)/qf_nx_itk/Connor_NX/K_nx_common.cpp b/qf_nx_itk-master (3)/qf_nx_itk/Connor_NX/K_nx_common.cpp new file mode 100644 index 0000000..18a8489 --- /dev/null +++ b/qf_nx_itk-master (3)/qf_nx_itk/Connor_NX/K_nx_common.cpp @@ -0,0 +1,1619 @@ +#pragma warning (disable: 4996) +#include "Connor_NX.h" +#include "K_recycle_item_id.h" +#include +#include +#include +#include +//#include +#include +#include + +using namespace std; +#define ITK_err 919012 + +#include +#include +#include +#include +#define _SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING +#include +namespace fs = std::experimental::filesystem; + +void removeLogsFile() { + fs::path filePath("D:\\logs.txt"); + if (fs::exists(filePath)) { + fs::remove(filePath); + std::cout << "文件已删除: " << filePath << std::endl; + } + else { + std::cout << "文件不存在: " << filePath << std::endl; + } +} + +// 获取当前时间的字符串表示 +std::string getCurrentTime() { + std::time_t now = std::time(nullptr); + std::tm* now_tm = std::localtime(&now); + char buffer[20]; + std::strftime(buffer, sizeof(buffer), "%Y-%m-%d %H:%M:%S", now_tm); + return std::string(buffer); +} + +// 写入日志信息到文件 writeLog("当前工时: "+ std::to_string(totalGs)); +void writeLog(const std::string& message) { + std::ofstream logFile("D:\\logs.txt", std::ios_base::app); // 以追加模式打开文件 + if (logFile.is_open()) { + std::string logEntry = "[" + getCurrentTime() + "] " + message + "\n"; + logFile << logEntry; + logFile.close(); + } + else { + std::cerr << "无法打开日志文件" << std::endl; + } +} + +char* getSubstringAfterDelimiter(const char* input, char delimiter) { + const char* delimiterPos = strchr(input, delimiter); + + if (delimiterPos == nullptr) { + size_t length = strlen(input); + char* result = new char[length + 1]; + strcpy(result, input); + return result; + } + + size_t length = strlen(delimiterPos); + + char* result = new char[length + 1]; + + strcpy(result, delimiterPos); + + return result; +} + +char* concatenateStrings(const char* str1, const char* str2) { + // 计算两个字符串的长度 + size_t len1 = strlen(str1); + size_t len2 = strlen(str2); + + // 分配足够的内存来存储拼接后的字符串 + char* result = new char[len1 + len2 + 1]; + + // 复制第一个字符串到结果字符串 + strcpy(result, str1); + + // 拼接第二个字符串到结果字符串 + strncat(result, str2, len2); + + return result; +} + +int init_prop_map(string str, map &prop_map) { + vector prop_strs; + Split(str, SPLIT_PROP_STR, prop_strs); + int prop_cnt = prop_strs.size(); + for (int i = 0; i < prop_cnt; i++) { + string prop_str = prop_strs[i]; + vector prop_name_value; + Split(prop_str, SPLIT_PROP_NAME_VALUE, prop_name_value); + if (prop_name_value.size() == 2 ) { + string prop_name = prop_name_value[0]; + string prop_value = prop_name_value[1]; + if (prop_map.count(prop_name) == 0) { + prop_map.insert(make_pair(prop_name, prop_value)); + } + } + } + return ITK_ok; +} + +int set_createinput_properties(tag_t createinput_tag ,map prop_map) { + int ifail = ITK_ok; + if (createinput_tag == NULLTAG || prop_map.size() == 0) { + return ifail; + } + map::iterator it; + for (it = prop_map.begin(); it != prop_map.end(); it++) { + string propname = it->first; + string propval = it->second; + printf(">> 设置属性: [%s] = [%s]\n", propname.c_str(), (propval.c_str())); + char* name_c = (char*)malloc(sizeof(char) * (propname.length() + 1)); + tc_strcpy(name_c, propname.c_str()); + const char* val_c[1] = { propval.c_str() }; + ITKCALL(TCTYPE_set_create_display_value(createinput_tag, name_c, 1, val_c)); + } + return ifail; +} + +int Set_Properties(tag_t item_tag, map prop_map) { + int ifail = ITK_ok; + char* object_string = NULL; + if (item_tag == NULLTAG || prop_map.size() == 0) { + return ifail; + } + ITKCALL(ifail = AOM_ask_value_string(item_tag, "object_string", &object_string)); + printf("更新对象属性:%s\n", object_string); + map::iterator it; + ITKCALL(ifail = AOM_lock(item_tag)); + if (ifail != ITK_ok) { + printf("无法锁定对象:%s\n", object_string); + ifail = OUTPUT_CODE_ERROR; + goto end; + } + for (it = prop_map.begin(); it != prop_map.end(); it++) { + string propname = it->first; + string propval = it->second; + printf(">> 设置属性: [%s] = [%s]\n", propname.c_str(), (propval.c_str())); + ITKCALL(ifail = AOM_UIF_set_value(item_tag, propname.c_str(), propval.c_str())); + } + ITKCALL(ifail = AOM_save(item_tag)); + AOM_unlock(item_tag); +end: + DOFREE(object_string); + return ifail; +} + +int Set_Uneditable_Property(tag_t item_tag, char* prop_name, const char* prop_value) { + char* object_string = NULL; + int ifail = ITK_ok; + if (item_tag == NULLTAG) { + return ifail; + } + ITKCALL(ifail = AOM_ask_value_string(item_tag, "object_string", &object_string)); + printf("更新对象属性:%s [%s]=[%s]\n", object_string, prop_name, prop_value); + // 修改id + { + tag_t class_tag = NULLTAG, attr_id = NULLTAG; + char* class_id = NULL; + ITKCALL(ifail = POM_class_of_instance(item_tag, &class_tag)); + if (ifail != ITK_ok) { + printf("未找到对象类实例:%s\n", object_string); + ifail = OUTPUT_CODE_ERROR; + goto end; + } + ITKCALL(ifail = POM_name_of_class(class_tag, &class_id)); + if (ifail != ITK_ok) { + printf("未找到对象类实例名称:%s\n", object_string); + ifail = OUTPUT_CODE_ERROR; + goto end; + } + ITKCALL(ifail = POM_attr_id_of_attr(prop_name, class_id, &attr_id)); + if (ifail != ITK_ok) { + printf("未找到对象属性id:%s -> %s\n", object_string, prop_name); + ifail = OUTPUT_CODE_ERROR; + goto end; + } + ITKCALL(ifail = AOM_lock(item_tag)); + if (ifail != ITK_ok) { + printf("无法锁定对象:%s\n", object_string); + ifail = OUTPUT_CODE_ERROR; + goto end; + } + ITKCALL(ifail = POM_set_attr_string(1, &item_tag, attr_id, prop_value)); + if (ifail != ITK_ok) { + printf("设置属性失败:%s\n", object_string); + ifail = OUTPUT_CODE_ERROR; + AOM_unlock(item_tag); + goto end; + } + ITKCALL(ifail = AOM_save(item_tag)); + AOM_unlock(item_tag); + } +end: + DOFREE(object_string); + return ifail; +} + +// 2025/3/5增加判断逻辑 +int judge_item_exist(string revType, string itemTh,string old_item_id, std::string& res) { + int ifail = ITK_ok; + int pref_len = 0; + char** pref_vals = NULL; + char* pref_name = "QF_Check_MaterialProperty"; + //writeLog("查询首选项:"+ pref_name); + writeLog("当前对象类型:"+ revType); + writeLog("当前对象图号:"+itemTh); + ITKCALL(ifail = PREF_ask_char_values(pref_name, &pref_len, &pref_vals)); + + if (ifail != ITK_ok || pref_vals == NULL) { + printf("获取首选项失败\n"); + return ifail; + } + + for (int i = 0; i < pref_len; i++) { + char* pref_val = pref_vals[i]; + // 查找第一个"=" + char* first_eq = strchr(pref_val, '='); + if (first_eq == NULL) { + printf("格式错误: %s\n", pref_val); + continue; + } + + // 提取首选项类型 + string pre_type(pref_val, first_eq - pref_val); + + // 检查对象类型是否匹配 + if (pre_type != revType) { + continue; + } + + // 查找"#_#图号#@#" + char* delimiter = strstr(first_eq + 1, "#_#图号#@#"); + if (delimiter == NULL) { + printf("格式错误: %s\n", pref_val); + continue; + } + + // 提取编码器QF8PartRevision + string query(first_eq + 1, delimiter - (first_eq + 1)); + + // 提取字段 + string th(delimiter + 10); // "#_#图号#@#" 的长度是 10 + + writeLog("类型:" + pre_type); + writeLog("查询名称:" + query); + writeLog("查询字段图号:" + th); + + + tag_t queryTag; + ITKCALL(ifail = QRY_find2(query.c_str(), &queryTag)); + if (ifail != ITK_ok) { + writeLog("查询失败:"+ query); + break; + } + tag_t* tags = NULL; + int n_found = 0; + char* qry_entries[1] = { const_cast(th.c_str()) }, + * qry_values[1] = { const_cast(itemTh.c_str()) }; + + // 查询对象 查询参数查询条目 key value 数组 返回的结果个数 查询的结果集 + ITKCALL(ifail = QRY_execute(queryTag, 1, qry_entries, qry_values, &n_found, &tags)); + if (ifail != ITK_ok) { + writeLog("执行查询失败:"+query); + break; + } + writeLog("执行查询成功,查到个数有:" + n_found); + + writeLog("old_item_id : "+ old_item_id); + if (n_found >=1) { + // 弹出提示存在该图号的弹框 + char* item_id = NULL; + if (old_item_id != "") { + AOM_ask_value_string(tags[0], "item_id", &item_id); + if (old_item_id == item_id) { + writeLog("图号只存在自己的"); + DOFREE(item_id); + return ifail; + } + else { + res.append("@#ItemId为:").append(item_id).append("已经存在该图号,请更换图号!"); + writeLog("@#图号已存在1:"); + DOFREE(item_id); + return OUTPUT_CODE_ERROR; + } + } + else { + AOM_ask_value_string(tags[0], "item_id", &item_id); + res.append("@#ItemId为:").append(item_id).append("已经存在该图号,请更换图号!"); + writeLog("@#图号已存在2:"); + return OUTPUT_CODE_ERROR; + } + } + else { + writeLog("图号不存在"); + return ifail; + } + + } + + return ifail; +} + +// 2025/03/04 执行更新操作 +int ITEM_UPDATE(const std::string& str, std::string& res) { + int ifail = ITK_ok, form_cnt = 0; + logical exist = false; + tag_t *form_tags = NULL; + tag_t item_tag = NULLTAG, rev_tag=NULLTAG; + tag_t item_type_tag = NULLTAG, rev_type_tag = NULLTAG;; + tag_t item_create_input_tag = NULLTAG, rev_create_input_tag = NULLTAG; + vector sections; + map revmaster_prop, item_prop, rev_prop; + Split(str, SPLIT_SECTION, sections); // id 版本 需要修改的版本uid 名称 对象属性 版本属性 版本表单属性 + string rev_uid, id, rev_id, name, item_prop_str, rev_prop_str, revmaster_prop_str,old_item_id, old_name_1, old_name_2, new_name_1, new_name_2; + char* object_string = NULL, * object_type = NULL, *object_name = NULL, *old_id = NULL, * old_rev_id = NULL; + if (sections.size() != 8) { + res.append("参数错误"); + ifail = OUTPUT_CODE_ERROR; + + DOFREE(old_id); + DOFREE(old_rev_id); + DOFREE(object_string); + DOFREE(object_type); + DOFREE(object_name); + DOFREE(form_tags); + return ifail; + } + id = sections[0]; + rev_id = sections[1]; + rev_uid = sections[2]; + name = sections[3]; + item_prop_str = sections[4]; + rev_prop_str = sections[5]; + revmaster_prop_str = sections[6]; + old_item_id = sections[7]; + init_prop_map(item_prop_str, item_prop); + init_prop_map(rev_prop_str, rev_prop); + init_prop_map(revmaster_prop_str, revmaster_prop); + + item_prop.insert(make_pair("object_name", name)); + rev_prop.insert(make_pair("object_name", name)); + ITK__convert_uid_to_tag(rev_uid.c_str(), &rev_tag); + if (rev_tag == NULLTAG) { + res.append("未找到版本UID:").append(rev_uid); + ifail = OUTPUT_CODE_ERROR; + + DOFREE(old_id); + DOFREE(old_rev_id); + DOFREE(object_string); + DOFREE(object_type); + DOFREE(object_name); + DOFREE(form_tags); + return ifail; + } + ITKCALL(ifail = ITEM_ask_item_of_rev(rev_tag, &item_tag)); + + // 2025/03/05 + string revTh = ""; + auto it = revmaster_prop.find("qf8th"); + if (it != revmaster_prop.end()) { + revTh = it->second; + } else { + // 记录日志或抛出异常,表示未找到 "qf8th" 键 + writeLog("未找到 qf8th 属性"); + // 可以选择返回错误码或设置默认值 + // return OUTPUT_CODE_ERROR; // 如果需要提前返回错误 + } + writeLog("=====开始检索====="); + char* targetType = NULL; + AOM_ask_value_string(item_tag, "object_type", &targetType); + ifail = judge_item_exist(targetType, revTh, old_item_id,res); + writeLog("=====结束检索====="); + if (ifail != ITK_ok) { + DOFREE(old_id); + DOFREE(old_rev_id); + DOFREE(object_string); + DOFREE(object_type); + DOFREE(object_name); + DOFREE(form_tags); + return ifail; + } + + ITKCALL(ifail = AOM_ask_value_string(rev_tag, "object_string", &object_string)); + printf("编码器更新版本:%s\n", object_string); + ITKCALL(ifail = AOM_ask_value_string(rev_tag, "item_revision_id", &old_rev_id)); + ITKCALL(ifail = AOM_ask_value_string(rev_tag, "item_id", &old_id)); + if (ifail==ITK_ok && (!id._Equal(old_id) || !rev_id._Equal(old_rev_id))) { + old_name_1.assign(old_id).append("/").append(old_rev_id); + old_name_2.assign(old_id).append("-").append(old_rev_id); + new_name_1.assign(id).append("/").append(rev_id); + new_name_2.assign(id).append("-").append(rev_id); + } + + if (rev_tag == NULLTAG) { + res.append("未找到版本的对象:").append(object_string); + ifail = OUTPUT_CODE_ERROR; + DOFREE(old_id); + DOFREE(old_rev_id); + DOFREE(object_string); + DOFREE(object_type); + DOFREE(object_name); + DOFREE(form_tags); + return ifail; + } + + writeLog("开始更新ID :"+ id); + ifail = Set_Uneditable_Property(item_tag, "item_id", id.c_str()); + if (ifail != ITK_ok) { + res.append("更新ID失败:").append(object_string); + writeLog("更新ID失败"); + ifail = OUTPUT_CODE_ERROR; + DOFREE(old_id); + DOFREE(old_rev_id); + DOFREE(object_string); + DOFREE(object_type); + DOFREE(object_name); + DOFREE(form_tags); + return ifail; + } + DOFREE(object_string); + AOM_refresh(rev_tag, 0); + ITKCALL(ifail = AOM_ask_value_string(rev_tag, "object_string", &object_string)); + printf("更新ID完成:%s\n", object_string); + printf("设置对象属性\n"); + ifail = Set_Properties(item_tag, item_prop); + printf("设置版本属性\n"); + ifail = Set_Properties(rev_tag, rev_prop); + printf("设置版本表单属性\n"); + ITKCALL(ifail = AOM_ask_value_tags(rev_tag, "IMAN_master_form_rev", &form_cnt, &form_tags)); + if (form_cnt == 1) { + ifail = Set_Properties(form_tags[0], revmaster_prop); + } + if (!new_name_2.empty()) { + char* obj_name = NULL; + char* subName = NULL; + char* newId = NULL; + + tag_t* bomViews = NULL; + int viewCount = 0; + ITKCALL(AOM_ask_value_tags(rev_tag, "structure_revisions", &viewCount, &bomViews)); + for (int j = 0; j < viewCount; j++) { + ITKCALL(AOM_ask_value_string(bomViews[j], "object_name", &obj_name)); + + subName = getSubstringAfterDelimiter(obj_name, '/'); + newId = concatenateStrings(id.c_str(), subName); + + AOM_load(bomViews[j]); + AOM_lock(bomViews[j]); + ITKCALL(AOM_set_value_string(bomViews[j], "object_name", newId)); + ITKCALL(AOM_save(bomViews[j])); + ITKCALL(AOM_refresh(bomViews[j], TRUE)); + AOM_unlock(bomViews[j]); + } + DOFREE(bomViews); + + /*tag_t* dataSetTags = NULL; + int dataSetCount = 0; + ITKCALL(AOM_ask_value_tags(rev_tag, "IMAN_specification", &dataSetCount, &dataSetTags)); + for (int j = 0; j < dataSetCount; j++) { + ITKCALL(AOM_ask_value_string(dataSetTags[j], "object_name", &obj_name)); + + subName = getSubstringAfterDelimiter(obj_name, '-'); + newId = concatenateStrings(id.c_str(), subName); + + AOM_load(dataSetTags[j]); + AOM_lock(dataSetTags[j]); + ITKCALL(AOM_set_value_string(dataSetTags[j], "object_name", newId)); + ITKCALL(AOM_save(dataSetTags[j])); + ITKCALL(AOM_refresh(dataSetTags[j], TRUE)); + AOM_unlock(dataSetTags[j]); + } + DOFREE(dataSetTags); + */ + + tag_t* itemBomViewTags = NULL; + int itemViewCount = 0; + ITKCALL(AOM_ask_value_tags(item_tag, "bom_view_tags", &itemViewCount, &itemBomViewTags)); + for (int j = 0; j < itemViewCount; j++) { + ITKCALL(AOM_ask_value_string(itemBomViewTags[j], "object_name", &obj_name)); + + subName = getSubstringAfterDelimiter(obj_name, '-'); + newId = concatenateStrings(id.c_str(), subName); + + AOM_load(itemBomViewTags[j]); + AOM_lock(itemBomViewTags[j]); + ITKCALL(AOM_set_value_string(itemBomViewTags[j], "object_name", newId)); + ITKCALL(AOM_save(itemBomViewTags[j])); + ITKCALL(AOM_refresh(itemBomViewTags[j], TRUE)); + AOM_unlock(itemBomViewTags[j]); + } + DOFREE(itemBomViewTags); + delete[] newId; + delete[] subName; + DOFREE(obj_name); + + int child_cnt = 0; + tag_t* child_tags = NULL; + printf("更新子对象名称 [%s]->[%s] [%s]->[%s]\n", old_name_1.c_str(), new_name_1.c_str(), old_name_2.c_str(), new_name_2.c_str()); + ITKCALL(ifail = GRM_list_secondary_objects_only(rev_tag, NULLTAG, &child_cnt, &child_tags)); + printf("子对象数量: %d\n", child_cnt); + for (int i = 0; i < child_cnt; i++) { + DOFREE(object_type); + DOFREE(object_name); + tag_t child_tag = child_tags[i]; + ITKCALL(ifail = WSOM_ask_object_type2(child_tag, &object_type)); + ITKCALL(ifail = AOM_ask_value_string(child_tag, "object_name", &object_name)); + if (ifail != ITK_ok) { + continue; + } + + printf(">> %d. [%s][%s]\n", i+1, object_name, object_type); + if (old_name_1._Equal(object_name)) { + printf(">> rename to %s\n", new_name_1.c_str()); + ITKCALL(ifail = AOM_lock(child_tag)); + if (ifail != ITK_ok) { + printf(">> 无法锁定对象\n"); + continue; + } + ITKCALL(ifail = AOM_set_value_string(child_tag, "object_name", new_name_1.c_str())); + ITKCALL(ifail = AOM_save(child_tag)); + AOM_unlock(child_tag); + } + else if (old_name_2._Equal(object_name)) { + printf(">> rename to %s\n", new_name_2.c_str()); + ITKCALL(ifail = AOM_lock(child_tag)); + if (ifail != ITK_ok) { + printf(">> 无法锁定对象\n"); + continue; + } + ITKCALL(ifail = AOM_set_value_string(child_tag, "object_name", new_name_2.c_str())); + ITKCALL(ifail = AOM_save(child_tag)); + AOM_unlock(child_tag); + } + } + DOFREE(child_tags); + } + { + char* uid = NULL; + ITK__convert_tag_to_uid(item_tag, &uid); + res.append(uid); + DOFREE(uid); + } +//end: +// DOFREE(old_id); +// DOFREE(old_rev_id); +// DOFREE(object_string); +// DOFREE(object_type); +// DOFREE(object_name); +// DOFREE(form_tags); +// return ifail; +} + + +int ITEM_CREATE(const std::string& str, std::string& res) { + int ifail = ITK_ok; + char* rev_type_name = NULL; + logical exist = false; + tag_t item_tag = NULLTAG; + tag_t item_type_tag = NULLTAG, rev_type_tag = NULLTAG;; + tag_t item_create_input_tag = NULLTAG, rev_create_input_tag = NULLTAG; + vector sections; + map revmaster_prop, item_prop, rev_prop; + Split(str, SPLIT_SECTION, sections); //id 版本 类型 名称 对象属性 版本属性 版本表单属性 + string id, rev_id, item_type, name, item_prop_str, rev_prop_str, revmaster_prop_str; + if (sections.size() != 8) { + res.append("参数错误"); + ifail = OUTPUT_CODE_ERROR; + DOFREE(rev_type_name); + return ifail; + } + id = sections[0]; + rev_id = sections[1]; + item_type = sections[2]; + name = sections[3]; + item_prop_str = sections[4]; + rev_prop_str = sections[5]; + revmaster_prop_str = sections[6]; + init_prop_map(item_prop_str, item_prop); + init_prop_map(rev_prop_str, rev_prop); + init_prop_map(revmaster_prop_str, revmaster_prop); + + // 2025/03/05 + writeLog("=====开始检索====="); + string revTh = ""; + for (auto it = revmaster_prop.begin(); it != revmaster_prop.end(); ++it) { + if (it->first == "qf8th") { + revTh = it->second; + break; + } + } + ifail = judge_item_exist(item_type, revTh,"",res); + writeLog("=====结束检索====="); + if (ifail != ITK_ok) { + DOFREE(rev_type_name); + return ifail; + } + + + ITKCALL(ifail = TCTYPE_find_type(item_type.c_str(), NULL, &item_type_tag)); + if (item_type_tag == NULLTAG) { + res.append("未找到对象类型:").append(item_type); + ifail = OUTPUT_CODE_ERROR; + DOFREE(rev_type_name); + return ifail; + } + rev_type_name = (char*) + MEM_alloc((strlen(item_type.c_str()) + strlen("Revision") + 1) * sizeof(char)); + sprintf(rev_type_name, "%sRevision", item_type.c_str()); + ITKCALL(ifail = TCTYPE_find_type(rev_type_name, NULL, &rev_type_tag)); + if (rev_type_tag == NULLTAG) { + res.append("未找到版本类型:").append(rev_type_name); + ifail = OUTPUT_CODE_ERROR; + DOFREE(rev_type_name); + return ifail; + } + ITKCALL(ifail = TCTYPE_construct_create_input(item_type_tag, &item_create_input_tag)); + ITKCALL(TCTYPE_construct_create_input(rev_type_tag, &rev_create_input_tag)); + ITKCALL(AOM_set_value_string(item_create_input_tag, "item_id", id.c_str())); + ITKCALL(AOM_set_value_string(item_create_input_tag, "object_name", name.c_str())); + ITKCALL(AOM_set_value_tag(item_create_input_tag, "revision", rev_create_input_tag)); + ITKCALL(AOM_set_value_string(rev_create_input_tag, "item_revision_id", rev_id.c_str())); + ITKCALL(AOM_set_value_string(rev_create_input_tag, "object_name", name.c_str())); + printf("设置对象属性\n"); + set_createinput_properties(item_create_input_tag, item_prop); + printf("设置版本属性\n"); + set_createinput_properties(rev_create_input_tag, rev_prop); + //版本表单属性 + if(revmaster_prop.size()>0) { + tag_t revmaster_type_tag = NULLTAG, revmaster_create_input_tag=NULLTAG; + char* revmaster_type_name = (char*) + MEM_alloc((strlen(item_type.c_str()) + strlen("RevisionMaster") + 1) * sizeof(char)); + sprintf(revmaster_type_name, "%sRevisionMaster", item_type.c_str()); + ITKCALL(ifail = TCTYPE_find_type(revmaster_type_name, NULL, &revmaster_type_tag)); + if (revmaster_type_tag == NULLTAG) { + res.append("未找到版本表单类型:").append(revmaster_type_name); + ifail = OUTPUT_CODE_ERROR; + DOFREE(rev_type_name); + return ifail; + } + ITKCALL(TCTYPE_construct_create_input(revmaster_type_tag, &revmaster_create_input_tag)); + tag_t tag_arr[1] = { revmaster_create_input_tag }; + ITKCALL(AOM_set_value_tags(rev_create_input_tag, "IMAN_master_form_rev", 1, tag_arr)); + printf("设置版本表单属性\n"); + set_createinput_properties(revmaster_create_input_tag, revmaster_prop); + } + + ITKCALL(TCTYPE_create_object(item_create_input_tag, &item_tag)); + if (item_tag == NULLTAG) { + res.append("创建对象失败"); + ifail = OUTPUT_CODE_ERROR; + DOFREE(rev_type_name); + return ifail; + } + ITKCALL(ifail = AOM_save_with_extensions(item_tag)); + if (ifail != ITK_ok) { + res.append("创建对象失败"); + DOFREE(rev_type_name); + return ifail; + } + { + char* uid = NULL; + ITK__convert_tag_to_uid(item_tag, &uid); + res.append(uid); + DOFREE(uid); + } + + +//end: +// DOFREE(rev_type_name); +// return ifail; +} + +int ADD_TO_NEWSTUFF(const std::string& uid, std::string& res) { + int ifail = ITK_ok; + tag_t tag = NULLTAG, member_tag=NULLTAG, user_tag=NULLTAG, folder_tag=NULLTAG; + ITK__convert_uid_to_tag(uid.c_str(), &tag); + if (tag == NULLTAG) { + res.append("未找到对象 UID:").append(uid); + ifail = OUTPUT_CODE_ERROR; + goto end; + } + ITKCALL(ifail = POM_ask_member(&member_tag)); + if (ifail != ITK_ok || member_tag == NULLTAG) { + ifail = OUTPUT_CODE_ERROR; + res.append("获取当前成员失败"); + goto end; + } + ITKCALL(ifail = SA_ask_groupmember_user(member_tag, &user_tag)); + if (ifail != ITK_ok || user_tag == NULLTAG) { + ifail = OUTPUT_CODE_ERROR; + res.append("获取当前用户失败"); + goto end; + } + ITKCALL(ifail = SA_ask_user_newstuff_folder(user_tag, &folder_tag)); + if (ifail != ITK_ok || folder_tag == NULLTAG) { + ifail = OUTPUT_CODE_ERROR; + res.append("获取当前用户NewStuff文件夹失败"); + goto end; + } + ITKCALL(ifail = FL_insert(folder_tag, tag, 990)); + if (ifail != ITK_ok) { + res.append("添加对象到用户NewStuff文件夹失败"); + goto end; + } +end: + return ifail; +} + + +int getIcsID(const char* parentIcsID, const char* childName, char returnData[]) +{ + int + ifail = ITK_ok, + nChildren = 0, + ii = 0; + + char* childId = NULL, + * className = NULL; + + tag_t classObject = NULLTAG, + * children = NULL; + + ITKCALL(ICS_find_class(parentIcsID, &classObject)); + if (classObject != NULLTAG) + { + ITKCALL(ICS_ask_children(classObject, &nChildren, &children)); + if (nChildren) + { + for (ii = 0; ii < nChildren; ii++) + { + ITKCALL(ICS_ask_id_name(children[ii], &childId, &className)); + if (className && tc_strcmp(childName, className) == 0) + { + tc_strcpy(returnData, childId); + //printf("returnData = %s\n",returnData); + MEM_free(childId); + MEM_free(className); + break; + } + MEM_free(childId); + MEM_free(className); + } + } + } + MEM_free(children); + return ifail; +} + +int SEND_ITEM_TO_CLASSIFICATION(const std::string& str, std::string& res) { + vector sections; + map prop_map; + Split(str, SPLIT_SECTION, sections); //id 版本 类型 名称 对象属性 版本属性 版本表单属性 + string item_uid, theClassId, prop_str; + + char //itemID[ITEM_id_size_c + 1] = "", + * itemID = NULL, + * rData = NULL; + const char** iAbValues = NULL; + + tag_t item = NULLTAG, + theICOTag = NULLTAG; + + char* theParent = NULL; /**< (OF) The id of the parent class or group */ + int theType = 0; /**< (O) Group, Class, StorageClass */ + char* theName = NULL; /**< (OF) The display name for the class */ + char* theShortName = NULL; /**< (OF) An optional short version of theName */ + char* theDescription = NULL; /**< (OF) A user oriented description of the class */ + char* theUserData1 = NULL; /**< (OF) Customer specific values not used by UGS */ + char* theUserData2 = NULL; /**< (OF) Customer specific values not used by UGS */ + int theClassOptions = 0; /**< (O) Bit encoded values from #ICS_class_flags_e */ + int theInstanceCount = 0; /**< (O) The number of instances stored in this class or any of its children */ + int theChildrenCount = 0; /**< (O) The number of children of this class */ + int theViewCount = 0; /**< (O) The number of views defined for this class */ + + int theCount = 0; /**< (O) The number of attributes of this class */ + int* theIds = NULL; /**< (OF) theCount The attribute id */ + char** theNames = NULL; /**< (OF) theCount The display name */ + char** theShortNames = NULL; /**< (OF) theCount The short version of the display name */ + char** theAnnotations = NULL; /**< (OF) theCount The annotation */ + int* theArraySize = NULL; /**< (OF) theCount 1 for non vla attributes, > 1 for vla attribute */ + int* theFormat = NULL; /**< (OF) theCount The internal format definition. + Use ICS_describe_format() to get details. */ + char** theUnit = NULL; /**< (OF) theCount */ + char** theMinValues = NULL; /**< (OF) theCount Minimum allowed value ( valid for integer and float attributes) */ + char** theMaxValues = NULL; /**< (OF) theCount Maximum allowed value ( valid for integer and float attributes) */ + char** theDefaultValues = NULL; /**< (OF) theCount Default value for new Instances */ + char** theDescriptions = NULL; /**< (OF) theCount The attribute description from the dictionary */ + int* theOptions = NULL; /**< (OF) theCount Bit encoded values from #ICS_class_attr_flags_e */ + + int + ifail = 0, + ii = 0, + jj = 0; + + if (sections.size() != 3) { + res.append("参数错误"); + ifail = OUTPUT_CODE_ERROR; + goto end; + } + item_uid = sections[0]; + theClassId = sections[1]; + prop_str = sections[2]; + init_prop_map(prop_str, prop_map); + ITK__convert_uid_to_tag(item_uid.c_str(), &item); + if (item == NULLTAG) { + res.append("未找到对象 UID:").append(item_uid); + ifail = OUTPUT_CODE_ERROR; + goto end; + } + //printf("theClassId = %s\n",theClassId); + //printf("iAbCnt = %d\n", iAbCnt); + + ITKCALL(ICS_class_describe(theClassId.c_str(), &theParent, &theType, &theName, &theShortName, &theDescription, + &theUserData1, &theUserData2, &theClassOptions, &theInstanceCount, &theChildrenCount, &theViewCount)); + + if (1 << theType != CLASS_flag_isStorrageClass) + { + res.append("isAbstract"); + /* rData = (char*)MEM_alloc(32 * sizeof(char)); + tc_strcpy(rData, "isAbstract"); + *((char**)returnValue) = rData;*/ + goto end; + } + + ITKCALL(ITEM_ask_id2(item, &itemID)); + //printf("itemID = %s\n",itemID); + + ITKCALL(ICS_class_describe_attributes(theClassId.c_str(), &theCount, &theIds, &theNames, &theShortNames, + &theAnnotations, &theArraySize, &theFormat, &theUnit, &theMinValues, &theMaxValues, &theDefaultValues, &theDescriptions, &theOptions)); + // printf("theCount = %d\n",theCount); + + iAbValues = (const char**)MEM_alloc(theCount * sizeof(char*)); + for (ii = 0; ii < theCount; ii++) + iAbValues[ii] = (char*)MEM_alloc(256 * sizeof(char)); + + for (ii = 0; ii < theCount; ii++) + { + bool find_it = false; + map::iterator it; + for (it = prop_map.begin(); it != prop_map.end(); it++) { + string propname = it->first; + if (tc_strcmp(propname.c_str(), theNames[ii]) == 0) + { + find_it = true; + iAbValues[ii] = it->second.c_str(); + break; + } + } + if (!find_it) + { + iAbValues[ii] = ""; + } + } + + ITKCALL(ifail = ICS_ico_create(itemID, item, theClassId.c_str(), theCount, theIds, iAbValues, &theICOTag)); + + MEM_free(theIds); + MEM_free(theNames); + MEM_free(theShortNames); + MEM_free(theAnnotations); + MEM_free(theArraySize); + MEM_free(theFormat); + MEM_free(theUnit); + MEM_free(theMinValues); + MEM_free(theMaxValues); + MEM_free(theDefaultValues); + MEM_free(theDescriptions); + MEM_free(theOptions); + /* + for( ii = 0; ii < theCount; ii++ ) + { + printf("ii===============%d\n",ii); + delete( iAbValues[ii] ); + } + */ + MEM_free(iAbValues); +end: + MEM_free(theParent); + MEM_free(theName); + MEM_free(theShortName); + MEM_free(theDescription); + MEM_free(theUserData1); + MEM_free(theUserData2); + MEM_free(itemID); + //printf("************************Send item to classification end***********************\n"); + return ifail; +} + +int GET_CLASSIFICATION_ID(const std::string& str, std::string& res) { + int ifail = ITK_ok; + char + returnData[ITEM_id_size_c + 1] = ""; + vector split; + string parentIcsID, childName; + Split(str, SPLITTER, split); + if (split.size() != 2) { + res.append("参数错误"); + ifail = OUTPUT_CODE_ERROR; + goto end; + } + parentIcsID = split[0]; + childName = split[1]; + printf("查询分类:[%s] - [%s]\n", parentIcsID.c_str(), childName.c_str()); + getIcsID(parentIcsID.c_str(), childName.c_str(), returnData); + res.append(returnData); + printf(">> [%s]\n", res.c_str()); +end: + return ifail; +} + +int GET_REVUID_BY_ID(const std::string& item_rev_id, std::string& res) { + int ifail = ITK_ok, item_cnt = 0; + tag_t rev_tag = NULLTAG; + char* uid = NULL; + vector split; + string item_id, rev_id; + Split(item_rev_id, "/", split); + if (split.size() != 2) { + res.append("参数错误"); + ifail = OUTPUT_CODE_ERROR; + goto end; + } + item_id = split[0]; + rev_id = split[1]; + ITKCALL(ifail = ITEM_find_rev(item_id.c_str(), rev_id.c_str(), &rev_tag)); + if (rev_tag == NULLTAG) { + res.append("未找到版本:").append(item_rev_id); + ifail = OUTPUT_CODE_ERROR; + goto end; + } + ITK__convert_tag_to_uid(rev_tag, &uid); + res.append(uid); +end: + DOFREE(uid); + return ifail; +} + +int GET_ITEMTYPE_BY_ID(const std::string& item_id, std::string& res) { + int ifail = ITK_ok, item_cnt=0; + tag_t* item_tags = NULL; + ITKCALL(ifail = ITEM_find(item_id.c_str(), &item_cnt, &item_tags)); + for (int i = 0; i < item_cnt; i++) { + char* object_type = NULL; + ITKCALL(ifail = WSOM_ask_object_type2(item_tags[i], &object_type)); + if (ifail == ITK_ok) { + res.append(object_type); + DOFREE(object_type); + goto end; + } + DOFREE(object_type); + } +end: + DOFREE(item_tags); + return ifail; +} + + +int ITEM_EXIST(const std::string& item_id, std::string& res) { + int ifail = ITK_ok; + logical exist = false; + ITKCALL(ifail = ITEM_id_exists(item_id.c_str(), &exist)); + if (exist) { + res.append("true"); + } +end: + return ifail; +} + +int DELETE_RECYCLE_ID(const std::string& str, std::string& res) +{ + int ifail = ITK_ok; + const char* class_name = "Cd9_CodeCounter"; + int length = 0, i = 0; + tag_t class_id = NULLTAG; + ITKCALL(POM_class_id_of_class(class_name, &class_id)); + + //find all instance + int n_instances = 0, n_ret_instances = 0; + tag_t* instance_tags = NULL, * ret_instances = NULL; + ITKCALL(POM_instances_of_class(class_id, FALSE, &n_instances, + &instance_tags)); + if (n_instances > 0) + { + ITKCALL(POM_load_instances_possible(n_instances, instance_tags, &n_ret_instances, &ret_instances)); + } + + for (int i = 0; i < n_ret_instances; ++i) { + tag_t bo_inst = ret_instances[i]; + tag_t recycleID_attr_id = NULLTAG; + tag_t occ_attr_id = NULLTAG; + char* recycleID_value = NULL; + logical is_it_null = FALSE; + logical is_it_empty = FALSE; + + ITKCALL(POM_refresh_instances_any_class(1, &bo_inst, POM_no_lock)); + + ITKCALL(POM_attr_id_of_attr(CodeCounter_isUsed, class_name, &occ_attr_id)); + ITKCALL(POM_attr_id_of_attr(CodeCounter_recycleID, + class_name, &recycleID_attr_id)); + + ITKCALL(POM_ask_attr_string(bo_inst, recycleID_attr_id, + &recycleID_value, &is_it_null, &is_it_empty)); + //printf("recycleID_value=============%s\n",recycleID_value); + //printf("codeID=============%s\n",codeID); + + if (tc_strcmp(recycleID_value, str.c_str()) == 0) + { + int lock_token = 0; + ITKCALL(POM_refresh_instances_any_class(1, &ret_instances[i], POM_no_lock)); + ITKCALL(POM_ask_instance_lock(ret_instances[i], &lock_token)); + if (lock_token == POM_no_lock) + { + ITKCALL(POM_delete_instances(1, &ret_instances[i])); + ret_instances[i] = NULLTAG; + } + MEM_free(recycleID_value); + break; + } + MEM_free(recycleID_value); + } + + MEM_free(instance_tags); + MEM_free(ret_instances); + return ifail; +} + +int QUERY_PART_NO(const std::string& str, std::string& res) +{ + int ifail = ITK_ok; + string patternCode, code_exclude_character; + vector split; + char pattern_code[BUFSIZ] = "", new_id[BUFSIZ] = ""; + int length = 0, + start_index = 0, + end_index = 0, + step = 0, new_index = 0; + char* generate_code = NULL; + char id_counter[BUFSIZ] = ""; + + Split(str, SPLITTER, split); + if (split.size() != 6) { + res.append("参数错误"); + ifail = OUTPUT_CODE_ERROR; + goto end; + } + patternCode = split[0]; + length = atoi(split[1].c_str()); + start_index = atoi(split[2].c_str()); + end_index = atoi(split[3].c_str()); + step = atoi(split[4].c_str()); + code_exclude_character = split[5]; + + if (patternCode.size()>0) + { + tc_strcpy(pattern_code, patternCode.c_str()); + } + //find recycled item id + + sprintf(id_counter, "%s$%d$%d$%d$%d", pattern_code, length, start_index, end_index, step); + + ITKCALL(ifail = QueryReduntantItemId(id_counter, &generate_code)); + + if (!generate_code) + { + ifail = get_sequence_no(pattern_code, length, start_index, end_index, step, &new_index, code_exclude_character.c_str()); + // std::cout << "get_sequence_no, " << "new_index : " << new_index << std::endl; + ITKCALL(generate_num(pattern_code, length, new_index, &generate_code)); + // std::cout << "generate_num, " << "new part id: " << generate_code << std::endl; + + if (!ifail) + { + ITKCALL(SaveReduntantItemId(id_counter, generate_code, "true")); + } + } + if (new_index > end_index) { + sprintf(new_id, "out of max value!"); + ifail = OUTPUT_CODE_ERROR; + } + else { + sprintf(new_id, "%s", generate_code); + } + res.append(new_id); + +end: + MEM_free(generate_code); + return ifail; +} + +int FIND_LOV_BY_NAME(const std::string& str, std::string& res) { + int ifail = ITK_ok, lov_cnt = 0; + tag_t* lov_tags = NULL; + ITKCALL(ifail = LOV_find(str.c_str(),&lov_cnt, &lov_tags)); + for (int i = 0; i < lov_cnt; i++) { + LOV_usage_t usage; + int value_cnt = 0; + char** dis_values = NULL; + char** values = NULL; + ITKCALL(ifail = LOV_ask_values_display_string(lov_tags[i], &usage, &value_cnt, &dis_values, &values)); + for (int j = 0; j < value_cnt; j++) { + res.append(values[j]).append("=").append(dis_values[j]).append(SPLITTER); + } + DOFREE(dis_values); + DOFREE(values); + } +end: + DOFREE(lov_tags); + return ifail; +} + +int ICS_ATTR_ASK_KEYLOV(const std::string& str, std::string& res) { + int ifail = ITK_ok; + char* key_lov_name = NULL; + int options = 0; + int n_lov_entries = 0; + char** lov_keys = NULL; + char** lov_values = NULL; + logical* deprecated_staus = NULL; + char* owning_site = NULL; + int n_shared_sites = 0; + char** shared_sites = NULL; + ITKCALL(ifail = ICS_keylov_get_keylov(str.c_str(), &key_lov_name, &options, &n_lov_entries, &lov_keys, &lov_values, &deprecated_staus, &owning_site, &n_shared_sites, &shared_sites)); + if (ifail != ITK_ok) { + goto end; + } + for (int i = 0; i < n_lov_entries; i++) { + if (deprecated_staus[i]) { + continue; + } + res.append(lov_keys[i]).append("=").append(lov_values[i]).append(SPLITTER); + } +end: + DOFREE(key_lov_name); + DOFREE(lov_values); + DOFREE(lov_keys); + DOFREE(deprecated_staus); + DOFREE(owning_site); + DOFREE(shared_sites); + return ifail; +} + +int ICS_ATTR_ASK_PROPERTY(const std::string& str, std::string& res) { + int ifail = ITK_ok; + int prop_id; + tag_t attr_tag = NULLTAG; + char* prop_value = NULL; + vector split; + Split(str, SPLITTER, split); + if (split.size() != 2) { + res.append("参数错误"); + ifail = OUTPUT_CODE_ERROR; + goto end; + } + prop_id = atoi(split[0].c_str()); + ITKCALL(ifail = ICS_attribute_ask_property(prop_id, split[1].c_str(), &prop_value)); + if (ifail == ITK_ok) { + res.append(prop_value); + } + else { + res.append("获取分类属性的属性失败:").append(str); + } +end: + DOFREE(prop_value); + return ifail; +} + +int ICS_ATTR_IS_REFERENCE_ATTRIBUTE(const std::string& str, std::string& res) { + int ifail = ITK_ok; + int prop_id = atoi(str.c_str()); + int ref_attr_type = 0, flag = 0; + char * class_name = NULL, * rel_name = NULL, * attr_name = NULL; + ITKCALL(ifail = ICS_attribute_ask_reference_props(prop_id, &ref_attr_type, &flag, &class_name, &attr_name, &rel_name)); + if (ifail == ICS_invalid_attribute_id) { + res.append("未找到分类属性: ").append(str); + ifail = OUTPUT_CODE_ERROR; + goto end; + } + // printf("Class Attr [%s]: %d", str.c_str(), ref_attr_type); + if (ref_attr_type == 0) { + res.append("false"); + } + else { + res.append("true"); + } +end: + DOFREE(class_name); + DOFREE(rel_name); + DOFREE(attr_name); + return ifail; +} + +int ICS_ATTR_ASK_METRIC_UNIT(const std::string& str, std::string& res) { + int ifail = ITK_ok, attr_cnt = 0; + int prop_id, * attr_ids = NULL, * metric_formats = NULL, * non_metric_formats = NULL; + char** attr_names = NULL, ** metric_units = NULL, ** non_metric_units = NULL; + vector split; + Split(str, SPLITTER, split); + if (split.size() != 2) { + res.append("参数错误"); + ifail = OUTPUT_CODE_ERROR; + goto end; + } + { + const char* clsId = split[0].c_str(); + prop_id = atoi(split[1].c_str()); + printf("ICS_ATTR_ASK_METRIC_UNIT [%s][%d]\n", clsId, prop_id); + ITKCALL(ifail = ICS_ask_common_attributes_used_as_facets2(1, &clsId, &attr_cnt, &attr_ids, + &metric_formats, &non_metric_formats, &attr_names, &metric_units, &non_metric_units)); + if (ifail == ITK_ok) { + for (int i = 0; i < attr_cnt; i++) { + printf(">> %d. [%d][%s] metric_formats = [%d] metric_units = [%s]\n", i+1, attr_ids[i], attr_names[i], metric_formats[i], metric_units[i]); + if (prop_id == attr_ids[i]) { + if (metric_units[i] != NULL) { + res.assign(metric_units[i]); + } + break; + } + } + } + else { + res.append("获取分类属性的属性失败:").append(clsId); + } + } + +end: + DOFREE(attr_ids); + DOFREE(metric_formats); + DOFREE(non_metric_formats); + DOFREE(attr_names); + DOFREE(metric_units); + DOFREE(non_metric_units); + return ifail; +} + + +int ICS_GET_ATTRIBUTES(const std::string& str, std::string& res) { + int ifail = ITK_ok; + tag_t * attr_tags = NULL; + int attr_cnt = 0, *attr_ids = NULL; + //printf("Get Ics Attributes: %s\n", str.c_str()); + ////ITKCALL(ifail = ICS_class_ask_tag(str.c_str(), &class_tag)); + //ITKCALL(ifail = ICS_find_class(str.c_str(), &class_tag)); + //if (ifail != ITK_ok || class_tag == NULLTAG) { + // res.append("未找到分类: ").append(str); + // ifail = OUTPUT_CODE_ERROR; + // goto end; + //} + //ITKCALL(ifail = ICS_view_refresh(str.c_str(), "defaultView")); + ITKCALL(ifail = ICS_class_ask_attributes(str.c_str(), &attr_cnt, &attr_tags, &attr_ids)); + //ITKCALL(ifail = ICS_ask_attributes(class_tag, &attr_cnt, &attr_tags)); + for (int i = 0; i < attr_cnt; i++) { + // printf(">> %d\n", attr_ids[i]); + if (ifail == ITK_ok) { + res.append(std::to_string(attr_ids[i])).append(SPLITTER); + } + } +end: + DOFREE(attr_ids); + return ifail; +} + +int GET_UOM_TAGS(const std::string& str, std::string& res) { + int ifail = ITK_ok, lov_cnt = 0, value_cnt = 0; + tag_t *lov_tags = NULL, *value_tags = NULL; + ITKCALL(ifail = LOV_find("Unit of Measures", &lov_cnt, &lov_tags)); + if (ifail != ITK_ok || lov_cnt == 0) { + res.append("未找到LOV:Unit of Measures"); + goto GET_LOGICAL_PROP_VALUE_END; + } + ITKCALL(ifail = LOV_ask_values_tag(lov_tags[0], &value_cnt, &value_tags)); + for (int i = 0; i < value_cnt; i++) { + tag_t uom_tag = value_tags[i]; + char* uid = NULL; + ITK__convert_tag_to_uid(uom_tag, &uid); + if (i != 0) { + res.append(SPLITTER); + } + res.append(uid); + DOFREE(uid); + } +GET_LOGICAL_PROP_VALUE_END: + DOFREE(lov_tags); + DOFREE(value_tags); + return ifail; +} + +int GET_LATEST_ITEM_REVISION(const std::string& str, std::string& res) { + int ifail = ITK_ok; + tag_t tag = NULLTAG; + tag_t value = NULLTAG; + ITK__convert_uid_to_tag(str.c_str(), &tag); + if (tag == NULLTAG) { + res.append("未找到对象 UID:").append(str); + ifail = OUTPUT_CODE_ERROR; + goto GET_LOGICAL_PROP_VALUE_END; + } + ITKCALL(ifail = AOM_load(tag)); + if (ifail != ITK_ok) { + res.append("无法加载实例 UID:").append(str); + goto GET_LOGICAL_PROP_VALUE_END; + } + ITKCALL(ifail = ITEM_ask_latest_rev(tag, &value)); + if (ifail != ITK_ok) { + res.append("读取属性失败:").append(str); + } + else { + if (value != NULLTAG) { + char* uid = NULL; + ITK__convert_tag_to_uid(value, &uid); + res.append(uid); + DOFREE(uid); + } + } + ITKCALL(AOM_unload(tag)); +GET_LOGICAL_PROP_VALUE_END: + return ifail; +} + +int UPDATE_UOM(const std::string& str, std::string& res) { + int ifail = ITK_ok; + vector split; + tag_t tag = NULLTAG, uom_tag = NULLTAG; + Split(str, SPLITTER, split); // uid;userid;priv1;priv2 + if (split.size() != 2) { + res.append("参数错误"); + ifail = OUTPUT_CODE_ERROR; + goto GET_LOGICAL_PROP_VALUE_END; + } + set_bypass(true); + ITK__convert_uid_to_tag(split[0].c_str(), &tag); + if (tag == NULLTAG) { + res.append("未找到对象 UID:").append(split[0]); + ifail = OUTPUT_CODE_ERROR; + goto GET_LOGICAL_PROP_VALUE_END; + } + ITKCALL(ifail = AOM_load(tag)); + if (ifail != ITK_ok) { + res.append("无法加载实例 UID:").append(split[0]); + goto GET_LOGICAL_PROP_VALUE_END; + } + ITK__convert_uid_to_tag(split[1].c_str(), &uom_tag); + if (uom_tag == NULLTAG) { + res.append("未找到单位 UID:").append(split[1]); + ifail = OUTPUT_CODE_ERROR; + goto GET_LOGICAL_PROP_VALUE_END; + } + ITKCALL(ifail = AOM_lock(tag)); + ITKCALL(ifail = ITEM_set_unit_of_measure(tag, uom_tag)); + if (ifail != ITK_ok) { + res.append("更新单位失败"); + ifail = OUTPUT_CODE_ERROR; + goto GET_LOGICAL_PROP_VALUE_END; + } + ITKCALL(ifail = AOM_save(tag)); +GET_LOGICAL_PROP_VALUE_END: + if (tag != NULLTAG) { + ITKCALL(ifail = AOM_unlock(tag)); + ITKCALL(AOM_unload(tag)); + } + set_bypass(false); + return ifail; +} + +int GRANT_PRIVILEGE(const std::string& str, std::string& res) { + int ifail = ITK_ok; + vector split; + tag_t tag = NULLTAG, user_tag=NULLTAG; + tag_t value = NULLTAG; + Split(str, SPLITTER, split); // uid;userid;priv1;priv2 + if (split.size() < 3) { + res.append("参数错误"); + ifail = OUTPUT_CODE_ERROR; + goto GET_LOGICAL_PROP_VALUE_END; + } + set_bypass(true); + ITK__convert_uid_to_tag(split[0].c_str(), &tag); + if (tag == NULLTAG) { + res.append("未找到对象 UID:").append(split[0]); + ifail = OUTPUT_CODE_ERROR; + goto GET_LOGICAL_PROP_VALUE_END; + } + ITKCALL(ifail = AOM_load(tag)); + if (ifail != ITK_ok) { + res.append("无法加载实例 UID:").append(split[0]); + goto GET_LOGICAL_PROP_VALUE_END; + } + ITKCALL(ifail = AOM_lock(tag)); + for (int i = 2; i < split.size(); i++) { + string privName = split[i]; + tag_t world_tag = NULLTAG; + tag_t write_prev = NULLTAG; + ITKCALL(ifail = AM_find_accessor("User", split[1].c_str(), &world_tag)); + if (ifail != ITK_ok) { + res.append("未找到用户:").append(split[1]); + goto GET_LOGICAL_PROP_VALUE_END; + } + ITKCALL(ifail = AM_find_privilege(privName.c_str(), &write_prev)); + if (ifail != ITK_ok) + { + res.append("未找到权限:").append(privName); + goto GET_LOGICAL_PROP_VALUE_END; + } + ITKCALL(ifail = AM_grant_privilege(tag, world_tag, write_prev)); + if (ifail != ITK_ok) + { + res.append("赋予权限失败:").append(privName); + goto GET_LOGICAL_PROP_VALUE_END; + } + } + ITKCALL(ifail = AM_save_acl(tag)); + if (ifail != ITK_ok) + { + res.append("保存ACL失败"); + goto GET_LOGICAL_PROP_VALUE_END; + } +GET_LOGICAL_PROP_VALUE_END: + if (tag != NULLTAG) { + ITKCALL(ifail = AOM_unlock(tag)); + ITKCALL(AOM_unload(tag)); + } + set_bypass(false); + return ifail; +} + +int GET_REFERENCE_PROP_VALUE(const std::string& str, std::string& res) { + int ifail = ITK_ok; + vector split; + tag_t tag = NULLTAG; + tag_t value = NULLTAG; + Split(str, SPLITTER, split); + if (split.size() != 2) { + res.append("参数错误"); + ifail = OUTPUT_CODE_ERROR; + goto GET_LOGICAL_PROP_VALUE_END; + } + ITK__convert_uid_to_tag(split[0].c_str(), &tag); + if (tag == NULLTAG) { + res.append("未找到对象 UID:").append(split[0]); + ifail = OUTPUT_CODE_ERROR; + goto GET_LOGICAL_PROP_VALUE_END; + } + ITKCALL(ifail = AOM_load(tag)); + if (ifail != ITK_ok) { + res.append("无法加载实例 UID:").append(split[0]); + goto GET_LOGICAL_PROP_VALUE_END; + } + ITKCALL(ifail = AOM_ask_value_tag(tag, split[1].c_str(), &value)); + if (ifail != ITK_ok) { + res.append("读取属性失败:").append(str); + } + else { + if (value != NULLTAG) { + char* uid = NULL; + ITK__convert_tag_to_uid(value, &uid); + res.append(uid); + DOFREE(uid); + } + } + ITKCALL(AOM_unload(tag)); + +GET_LOGICAL_PROP_VALUE_END: + return ifail; +} + +int GET_REFERENCE_PROP_VALUE_ARRAY(const std::string& str, std::string& res) { + int ifail = ITK_ok, value_cnt = 0; + vector split; + tag_t tag = NULLTAG; + tag_t *values = NULL; + Split(str, SPLITTER, split); + if (split.size() != 2) { + res.append("参数错误"); + ifail = OUTPUT_CODE_ERROR; + goto GET_LOGICAL_PROP_VALUE_END; + } + ITK__convert_uid_to_tag(split[0].c_str(), &tag); + if (tag == NULLTAG) { + res.append("未找到对象 UID:").append(split[0]); + ifail = OUTPUT_CODE_ERROR; + goto GET_LOGICAL_PROP_VALUE_END; + } + ITKCALL(ifail = AOM_load(tag)); + if (ifail != ITK_ok) { + res.append("无法加载实例 UID:").append(split[0]); + goto GET_LOGICAL_PROP_VALUE_END; + } + ITKCALL(ifail = AOM_ask_value_tags(tag, split[1].c_str(), &value_cnt, &values)); + if (ifail != ITK_ok) { + res.append("读取属性失败:").append(str); + } + else { + for (int i = 0; i < value_cnt; i++) { + tag_t value = values[i]; + char* uid = NULL; + ITK__convert_tag_to_uid(value, &uid); + if (i != 0) { + res.append(SPLITTER); + } + res.append(uid); + DOFREE(uid); + } + } + ITKCALL(AOM_unload(tag)); +GET_LOGICAL_PROP_VALUE_END: + DOFREE(values); + return ifail; +} + +int GET_DISPLAY_PROP_VALUE(const std::string& str, std::string& res) { + int ifail = ITK_ok; + vector split; + tag_t tag = NULLTAG; + char* value = NULL; + Split(str, SPLITTER, split); + if (split.size() != 2) { + res.append("参数错误"); + ifail = OUTPUT_CODE_ERROR; + goto GET_LOGICAL_PROP_VALUE_END; + } + ITK__convert_uid_to_tag(split[0].c_str(), &tag); + if (tag == NULLTAG) { + res.append("未找到对象 UID:").append(split[0]); + ifail = OUTPUT_CODE_ERROR; + goto GET_LOGICAL_PROP_VALUE_END; + } + ITKCALL(ifail = AOM_load(tag)); + if (ifail != ITK_ok) { + res.append("无法加载实例 UID:").append(split[0]); + goto GET_LOGICAL_PROP_VALUE_END; + } + ITKCALL(ifail = AOM_UIF_ask_value(tag, split[1].c_str(), &value)); + if (ifail != ITK_ok) { + res.append("读取属性失败:").append(str); + } + else { + res.append(value); + } + ITKCALL(AOM_unload(tag)); + +GET_LOGICAL_PROP_VALUE_END: + DOFREE(value); + return ifail; +} + +int GET_LOGICAL_PROP_VALUE(const std::string& str, std::string& res) { + int ifail = ITK_ok; + vector split; + tag_t tag = NULLTAG; + logical value; + Split(str, SPLITTER, split); + if (split.size() != 2) { + res.append("参数错误"); + ifail = OUTPUT_CODE_ERROR; + goto GET_LOGICAL_PROP_VALUE_END; + } + ITK__convert_uid_to_tag(split[0].c_str(), &tag); + if (tag == NULLTAG) { + res.append("未找到对象 UID:").append(split[0]); + ifail = OUTPUT_CODE_ERROR; + goto GET_LOGICAL_PROP_VALUE_END; + } + ITKCALL(ifail = AOM_load(tag)); + if (ifail != ITK_ok) { + res.append("无法加载实例 UID:").append(split[0]); + goto GET_LOGICAL_PROP_VALUE_END; + } + ITKCALL(ifail = AOM_ask_value_logical(tag, split[1].c_str(), &value)); + if (ifail != ITK_ok) { + res.append("读取属性失败:").append(str); + } + else { + if (value) { + res.append("true"); + } + else { + res.append("false"); + } + } + ITKCALL(AOM_unload(tag)); + +GET_LOGICAL_PROP_VALUE_END: + return ifail; +} + +int GET_NEW_REV_ID(const std::string& typeName, std::string& res) { + int ifail = ITK_ok; + tag_t type_tag = NULLTAG; + logical isModified = FALSE; + char* new_rev_id = NULL; + ITKCALL(ifail = TCTYPE_ask_type(typeName.c_str(), &type_tag)); + if (ifail != ITK_ok) { + res.append("未找到对象类型: ").append(typeName); + goto GET_NEW_REV_ID_END; + } + if (type_tag == NULLTAG) { + res.append("未找到对象类型: ").append(typeName); + ifail = OUTPUT_CODE_ERROR; + goto GET_NEW_REV_ID_END; + } + ITKCALL(ifail = USER_new_revision_id(NULLTAG, type_tag, &isModified, &new_rev_id)); + if (ifail != ITK_ok || new_rev_id == NULL) { + res.append("获取类型版本号失败: ").append(typeName); + ifail = OUTPUT_CODE_ERROR; + goto GET_NEW_REV_ID_END; + } + res.append(new_rev_id); +GET_NEW_REV_ID_END: + DOFREE(new_rev_id); + return ifail; +} \ No newline at end of file diff --git a/qf_nx_itk-master (3)/qf_nx_itk/Connor_NX/K_read_nx_bom.cpp b/qf_nx_itk-master (3)/qf_nx_itk/Connor_NX/K_read_nx_bom.cpp new file mode 100644 index 0000000..9a6a707 --- /dev/null +++ b/qf_nx_itk-master (3)/qf_nx_itk/Connor_NX/K_read_nx_bom.cpp @@ -0,0 +1,121 @@ +#include "Connor_NX.h" +using namespace std; + +int Cycle_BOM(tag_t bomline, std::string& res, vector& checkedIDs) { + int ifail = ITK_ok, child_cnt = 0; + tag_t rev_tag = NULLTAG, * child_lines = NULL; + char* object_string = NULL, * uid = NULL; + ITKCALL(ifail = AOM_ask_value_tag(bomline, "bl_revision", &rev_tag)); + if (ifail != ITK_ok || rev_tag == NULLTAG) { + goto cycle_bom_end; + } + ITK__convert_tag_to_uid(rev_tag, &uid); + if (inArray(checkedIDs, uid)) { + goto cycle_bom_end; + } + ITKCALL(ifail = BOM_line_ask_child_lines(bomline, &child_cnt, &child_lines)); + if (child_cnt == 0) { + goto cycle_bom_end; + } + ITKCALL(ifail = AOM_ask_value_string(bomline, "bl_indented_title", &object_string)); + if (ifail != ITK_ok) { + goto cycle_bom_end; + } + res.append(""); + res.append(uid); + res.append("="); + res.append(object_string); + for (int i = 0; i < child_cnt; i++) { + tag_t cLine = child_lines[i]; + tag_t cRev = NULLTAG; + DOFREE(uid); + DOFREE(object_string); + ITKCALL(ifail = AOM_ask_value_tag(cLine, "bl_revision", &cRev)); + if (ifail != ITK_ok || cRev == NULLTAG) { + continue; + } + ITK__convert_tag_to_uid(cRev, &uid); + ITKCALL(ifail = AOM_ask_value_string(cLine, "bl_indented_title", &object_string)); + if (ifail != ITK_ok) { + continue; + } + res.append(""); + res.append(uid); + res.append("="); + res.append(object_string); + } + for (int i = 0; i < child_cnt; i++) { + Cycle_BOM(child_lines[i], res, checkedIDs); + } +cycle_bom_end: + DOFREE(object_string); + DOFREE(uid); + DOFREE(child_lines); + return ifail; +} + + +//READ_NX_TEMPLATE_BOM +int READ_NX_TEMPLATE_BOM(const std::string& itemID, std::string& res) { + int ifail = ITK_ok, release_flag = 0; + int pref_len = 0, ds_count = 0; + char* object_string = NULL; + char* rev_id = NULL; + tag_t item_tag = NULLTAG; + tag_t rev_tag = NULLTAG; + tag_t bom_view = NULLTAG, bvr_tag = NULLTAG, bom_window = NULLTAG, topBomLine = NULLTAG; + vector checkedIDs; + POM_AM__set_application_bypass(true); + WriteLog(debug, "查询NX模板:%s", itemID.c_str()); + if (tc_strlen(itemID.c_str()) == 0) { + res.append(("NX模板ID不可为空")); + ifail = OUTPUT_CODE_ERROR; + goto gx_nx_template_end; + } + ITKCALL(ifail = ITEM_find_item(itemID.c_str(), &item_tag)); + if (ifail != ITK_ok) { + goto gx_nx_template_end; + } + ITKCALL(ifail = AOM_ask_value_string(item_tag, "object_string", &object_string)); + WriteLog(debug, "找到对象:%s", object_string); + DOFREE(object_string); + ITKCALL(ifail = ITEM_ask_latest_rev(item_tag, &rev_tag)); + if (rev_tag == NULLTAG) { + res.append(("未找到模板对象的最新版本,请检查是否具有查看权限")); + ifail = OUTPUT_CODE_ERROR; + goto gx_nx_template_end; + } + ITKCALL(ifail = AOM_refresh(rev_tag, FALSE)); + ITKCALL(ifail = AOM_ask_value_string(rev_tag, "object_string", &object_string)); + WriteLog(debug, "最新版本:%s", object_string); + DOFREE(object_string); + // 检查是否发布 + ITKCALL(ifail = EPM_ask_if_released(rev_tag, &release_flag)); + if (release_flag == 0) { + res.append(("模板对象最新版本未发布")); + ifail = OUTPUT_CODE_ERROR; + goto gx_nx_template_end; + } + ITKCALL(ifail = AOM_ask_value_string(rev_tag, "item_revision_id", &rev_id)); + res.append("@DB/").append(itemID).append("/").append(rev_id); + // 加载BOM + ITKCALL(ifail = GetBomView(rev_tag, "view", &bom_view, &bvr_tag, debug)); + if (bom_view != NULLTAG) { + BOM_create_window(&bom_window); + BOM_set_window_top_line_bvr(bom_window, bvr_tag, &topBomLine); + ifail = Cycle_BOM(topBomLine, res, checkedIDs); + BOM_close_window(bom_window); + } + else { + WriteLog(debug, "未找到BOM视图"); + } +gx_nx_template_end: + if (ifail != ITK_ok) { + res.assign("读取BOM异常"); + ifail = OUTPUT_CODE_ERROR; + } + POM_AM__set_application_bypass(false); + DOFREE(object_string); + DOFREE(rev_id); + return ifail; +} \ No newline at end of file diff --git a/qf_nx_itk-master (3)/qf_nx_itk/Connor_NX/K_recycle_item_id.cpp b/qf_nx_itk-master (3)/qf_nx_itk/Connor_NX/K_recycle_item_id.cpp new file mode 100644 index 0000000..ba3d211 --- /dev/null +++ b/qf_nx_itk-master (3)/qf_nx_itk/Connor_NX/K_recycle_item_id.cpp @@ -0,0 +1,775 @@ +#pragma warning (disable: 4996) +#include "K_recycle_item_id.h" + +#ifdef __cplusplus +extern "C" { +#endif + /************************************************************************/ + /* 记录空闲item id的schema类(或数据库表) + * Schema类名:TempCounter,父类:POM_object + * 表结构字段: + * name:字符串类型,32位,计数器名字,如特征码abc + * id:字符串类型,32位,当前计数器对应的新的id,如abc0001 + * occ:字符串类型,32位,指示id是否被占用,值为true/false + * create_date:日期类型,记录创建时间,用来处理异常情况 + */ + /************************************************************************/ + + int CheckReference(tag_t one_instance) + { + int n_levels = 1; + int n_instances = 0; + tag_t* ref_instances = NULL; + int* instance_levels = NULL, * instance_where_found = NULL; + int n_classes = 0; + tag_t* ref_classes = NULL; + int* class_levels = NULL, * class_where_found = NULL; + CALL(POM_referencers_of_instance(one_instance, + n_levels, + POM_in_ds_and_db, + &n_instances, /**< (O) Number of referencing instances */ + &ref_instances, /**< (OF) n_instances Tags of referencing instances */ + &instance_levels, /**< (OF) n_instances Levels of referencing instances */ + &instance_where_found, /**< (OF) n_instances Where the instance was found */ + &n_classes, /**< (O) Number of referencing classes */ + &ref_classes, /**< (OF) n_classes Tags of referencing classes */ + &class_levels, /**< (OF) n_classes Levels of referencing classes */ + &class_where_found /**< (OF) n_classes Where the class was found (always DB) */ + )); + + if (n_instances == 0) + return 0; + + MEM_free(ref_instances); + MEM_free(instance_levels); + MEM_free(instance_where_found); + MEM_free(ref_classes); + MEM_free(class_levels); + MEM_free(class_where_found); + + return -1; + } + + int enq_like_num(const char* filter_code, int* index) + { + int ifail; + const char* enquiryLikeItem = "Select_ITEM"; + const char* select_attrs[1] = { "puid" }; + int rows, cols; + void*** report = NULL; + + //===============select puid form Item where ITEM_ID like TeZhengManWithNumber% + CALL(POM_enquiry_create(enquiryLikeItem)); + CALL(POM_enquiry_add_select_attrs(enquiryLikeItem, ITEM_POM_CLASS, + 1, (const char**)select_attrs)); + CALL(POM_enquiry_set_string_value(enquiryLikeItem, "item_id_value", + 1, (const char**)(&filter_code), POM_enquiry_asc_order)); + CALL(POM_enquiry_set_attr_expr(enquiryLikeItem, "item_id_exp", + ITEM_POM_CLASS, "ITEM_ID", POM_enquiry_like, "item_id_value")); + CALL(POM_enquiry_set_where_expr(enquiryLikeItem, "item_id_exp")); + CALL(POM_enquiry_execute(enquiryLikeItem, &rows, &cols, &report)); + *index = rows; + MEM_free(report); + CALL(ifail = POM_enquiry_delete(enquiryLikeItem)); + return ifail; + } + + /************************************************************************/ + /* + * Description: Query redundant item id from the recycle item id's table + * Function : QueryReduntantItemId2 + * Params : TeZhengMa - item id's TeZhengMa, usually, this is the item + * id counter's name + * : the_item_id - searched item id, maybe null. + * Return : 0 - no error, else errors + */ + /************************************************************************/ + + + int QueryReduntantItemId(char* TeZhengMa, char** the_item_id) + { + int ifail = ITK_ok, i = 0; + const char + * Temp_Pom_Class = "Cd9_CodeCounter"; + char + * name_attr_value = NULL, + * id_attr_value = NULL, + * occ_attr_value = NULL; + tag_t + class_id = NULLTAG, + name_attr_id = NULLTAG, + id_attr_id = NULLTAG, + occ_attr_id = NULLTAG, + createdate_attr_id = NULLTAG, + item_exists = NULLTAG; + logical + include_subclasses = FALSE, + is_it_null = FALSE, + is_it_empty = FALSE, + is_old_enough = FALSE; + int + n_instance = 0, + n_ret_instances = 0, + lock_token = 0, lock_token_2 = 0, + day = 0, month = 0, year = 0, + hour = 0, minute = 0, second = 0, zjdnum = 0; //zjd + tag_t + * instance_tags = NULL, + * ret_instances = NULL, + one_instance = NULLTAG, + found_instance = NULLTAG; + struct tm* p; + time_t now; + date_t date_attr_value; + char counter_name1[255]; + date_t modify_date; //liny + + CALL(POM_class_id_of_class(Temp_Pom_Class, &class_id)); + CALL(POM_attr_id_of_attr(CodeCounter_name, Temp_Pom_Class, &name_attr_id)); + CALL(POM_attr_id_of_attr(CodeCounter_recycleID, Temp_Pom_Class, &id_attr_id)); + CALL(POM_attr_id_of_attr(CodeCounter_isUsed, Temp_Pom_Class, &occ_attr_id)); + CALL(POM_attr_id_of_attr(CodeCounter_createDate, Temp_Pom_Class, &createdate_attr_id)); + + //查询废号表中的所有实例,但尚未加载 + CALL(POM_instances_of_class(class_id, include_subclasses, &n_instance, &instance_tags)); + //fprintf( stdout, "%d instances found\n", n_instance ); + if (n_instance == 0) { + return ITK_ok; + } + + //返回所有成功加载的instance + CALL(POM_load_instances_possible(n_instance, instance_tags, &n_ret_instances, &ret_instances)); + CALL(POM_refresh_instances(n_ret_instances, ret_instances, NULLTAG, POM_no_lock)); + + //刷新实例,找到所有的报废号码 + for (i = 0; i < n_ret_instances; i++) + { + one_instance = ret_instances[i]; + + //取得所有occ自动为true的记录,如果这些记录合适,则更新这些记录的occ字段为false,以备取号使用 + CALL(POM_ask_attr_string(one_instance, occ_attr_id, &occ_attr_value, &is_it_null, &is_it_empty)); + + //查询符合条件的实例的时间状态,如果已经过期,则设置occ为false,以备取废号使用 + if (tc_strcmp(occ_attr_value, "true") == 0) + { + CALL(POM_ask_attr_date(one_instance, createdate_attr_id, &date_attr_value, &is_it_null, &is_it_empty)); + year = date_attr_value.year; + month = date_attr_value.month; + day = date_attr_value.day; + hour = date_attr_value.hour; + minute = date_attr_value.minute; + + + time(&now); + p = localtime(&now); /* 取得当前时间 */ + is_old_enough = FALSE; + + //printf("year==%d month==%d day==%d hour==%d minute==%d \n",year,month,day,hour,minute); + //printf("now::year==%d month==%d day==%d hour==%d minute==%d \n",p->tm_year + 1900, p->tm_mon,p->tm_mday,p->tm_hour,p->tm_min); + + if ((p->tm_year + 1900) > year) //如果当前年份大于对象的创建年份,则设置标志位 + is_old_enough = TRUE; + else + { + if (p->tm_mon > month) //如果当前月份大于对象的创建月份,则设置标志位 + is_old_enough = TRUE; + else + { + if (p->tm_mday > day) //如果当前月份大于对象的创建日期,则设置标志位 + is_old_enough = TRUE; + //else + // is_old_enough = FALSE; + else + { + //if( p->tm_hour> (hour+1)%24 ) + if (p->tm_hour > hour) + is_old_enough = TRUE; + //else + // is_old_enough = FALSE; + else //liny + { + if (p->tm_min > (minute + 5)) + is_old_enough = TRUE; + else + is_old_enough = FALSE; + } + } + } + } + + if (is_old_enough == TRUE) + { //查询当前instance是否被加了修改锁,如果未被加修改锁,则设置这些记录刷新内存记录 + CALL(POM_ask_instance_lock(one_instance, &lock_token)); + if (lock_token != POM_modify_lock) + { + CALL(POM_refresh_instances_any_class(1, &one_instance, POM_modify_lock)); + CALL(POM_set_attr_string(1, &one_instance, occ_attr_id, "false")); + CALL(POM_save_instances(1, &one_instance, false)); + CALL(POM_refresh_instances_any_class(1, &one_instance, POM_no_lock));//刷新内存记录,恢复锁的状态 + } + } + } + } + + //所有的记录被刷新,重新取号 + for (i = 0; i < n_ret_instances; i++) + { + one_instance = ret_instances[i]; + + CALL(POM_ask_attr_string(one_instance, name_attr_id, &name_attr_value, &is_it_null, &is_it_empty)); + + if (tc_strcmp(name_attr_value, TeZhengMa) == 0) + { + CALL(POM_ask_attr_string(one_instance, occ_attr_id, &occ_attr_value, &is_it_null, &is_it_empty)); + + //如果当前记录是新创建的且未过时,跳过不处理 + if (tc_strcmp(occ_attr_value, "true") == 0) + { + MEM_free(occ_attr_value); + continue; + } + //如果当前instance被别人加了修改锁,跳过 + CALL(POM_ask_instance_lock(one_instance, &lock_token)); + if (lock_token == POM_modify_lock) + { + MEM_free(occ_attr_value); + continue; + } + + CALL(POM_ask_attr_string(one_instance, id_attr_id, &id_attr_value, &is_it_empty, &is_it_empty)); + + //检查数据库是否有记录,有则尝试取消这个废号,成功则删除记录,否则设置当前的instance为nulltag + item_exists = NULLTAG; + /*CALL( ITEM_find_item( id_attr_value, &item_exists ) ); + if( item_exists != NULLTAG )*/ + tc_strcpy(counter_name1, "%"); + tc_strcat(counter_name1, id_attr_value); + tc_strcat(counter_name1, "%"); + + { + int n_levels = 2; + int where_to_search = POM_in_ds_and_db; + int n_ref_instances; + tag_t* ref_instances; + int* ref_instance_levels; + int* ref_instance_where_found; + int n_ref_classes; + tag_t* ref_classes; + int* class_levels; + int* class_where_found; + + POM_referencers_of_instance(one_instance, n_levels, where_to_search, &n_ref_instances, &ref_instances, &ref_instance_levels, &ref_instance_where_found, &n_ref_classes, &ref_classes, &class_levels, &class_where_found); + //printf("id==%s的被%d个实例引用\n",counter_name1,n_ref_instances); + //printf("id==%s的被%d个类引用\n",counter_name1,n_ref_instances); + } + + + //查找新建的item中是否已存在该ID + ifail = enq_like_num(counter_name1, &zjdnum); + if (zjdnum != 0) + { + int lock_token = 0; + ITKCALL(POM_refresh_instances_any_class(1, &one_instance, POM_no_lock)); + ITKCALL(POM_ask_instance_lock(one_instance, &lock_token)); + if (lock_token == POM_no_lock) + { + int n_levels = 2; + int where_to_search = POM_in_ds_and_db; + int n_ref_instances; + tag_t* ref_instances; + int* ref_instance_levels; + int* ref_instance_where_found; + int n_ref_classes; + tag_t* ref_classes; + int* class_levels; + int* class_where_found; + + + POM_referencers_of_instance(one_instance, n_levels, where_to_search, &n_ref_instances, &ref_instances, &ref_instance_levels, &ref_instance_where_found, &n_ref_classes, &ref_classes, &class_levels, &class_where_found); + // printf("id==%s的被%d个实例引用\n",counter_name1,n_ref_instances); + //printf("id==%s的被%d个类引用\n",counter_name1,n_ref_instances); + + /* + for(int k=0;k 0) + { + tc_strcpy(*the_item_id, id_attr_value); + found_instance = one_instance; + } + } + + MEM_free(id_attr_value); + MEM_free(occ_attr_value); + MEM_free(name_attr_value); + } + else + { + MEM_free(name_attr_value); + continue; + } + } + + if (found_instance != NULLTAG) + { + CALL(POM_ask_instance_lock(found_instance, &lock_token)); + if (lock_token != POM_modify_lock) + { + CALL(POM_refresh_instances_any_class(1, &found_instance, POM_modify_lock)); + CALL(POM_set_attr_string(1, &found_instance, occ_attr_id, "true")); + + //刷新记录的修改时间,确保同一时刻不会再次被要出//liny + time(&now); + p = localtime(&now); /* 取得当前时间 */ + modify_date.day = p->tm_mday; + modify_date.hour = p->tm_hour; + modify_date.minute = p->tm_min; + modify_date.month = p->tm_mon; + modify_date.second = p->tm_sec; + modify_date.year = p->tm_year + 1900; + CALL(POM_set_attr_date(1, &found_instance, createdate_attr_id, modify_date)); + CALL(POM_save_instances(1, &found_instance, true)); + } + } + MEM_free(instance_tags); + + return ifail; + } + + /************************************************************************/ + /* + * Description: Query redundant item id from the recycle item id's table + * Function : SaveReduntantItemId + * Params : TeZhengMa - item id's TeZhengMa, usually, this is the item + * id counter's name + * : the_item_id - new created item id + * : occupied - indicate weather current item id was used, almost + * in every case its value is "true" + * Return : 0 - no error, else errors + */ + /************************************************************************/ + //保存当前生产的新的itemid到系统的临时itemid表中 + + int SaveReduntantItemId(char* TeZhengMa, char* new_item_id, const char* occupied) + { + int ifail = ITK_ok; + + tag_t + class_id = NULLTAG, + instance_tag = NULLTAG, + attr_id = NULLTAG; + date_t create_date; + struct tm* p; + time_t now; + + const char* Temp_Pom_Class = "Cd9_CodeCounter"; + CALL(POM_class_id_of_class(Temp_Pom_Class, &class_id)); + CALL(POM_create_instance(class_id, &instance_tag)); + + + CALL(POM_attr_id_of_attr(CodeCounter_index, Temp_Pom_Class, &attr_id)); + int new_index = 0; + get_sequence_no("OACC", 8, 1, 99999999, 1, &new_index, ""); + ITKCALL(POM_set_attr_int(1, &instance_tag, attr_id, new_index)); + + //now, set the TeZhengMa attribute of the new instance + CALL(POM_attr_id_of_attr(CodeCounter_name, Temp_Pom_Class, &attr_id)); + CALL(POM_set_attr_string(1, &instance_tag, attr_id, TeZhengMa)); + + //set the Id attribute of the new instance + CALL(POM_attr_id_of_attr(CodeCounter_recycleID, Temp_Pom_Class, &attr_id)); + CALL(POM_set_attr_string(1, &instance_tag, attr_id, new_item_id)); + + //set the Occ attribute of the new instance + CALL(POM_attr_id_of_attr(CodeCounter_isUsed, Temp_Pom_Class, &attr_id)); + CALL(POM_set_attr_string(1, &instance_tag, attr_id, occupied)); + + /* + time(&now); + p = localtime(&now); // 取得当前时间 + create_date.day = p->tm_mday; + create_date.hour = p->tm_hour; + create_date.minute = p->tm_min; + create_date.month = p->tm_mon; + create_date.second = p->tm_sec; + create_date.year = p->tm_year + 1900; */ + + CALL(POM_attr_id_of_attr(CodeCounter_createDate, Temp_Pom_Class, &attr_id)); + ITKCALL(POM_set_attr_date(1, &instance_tag, attr_id, getCurrentDate())); + + CALL(POM_attr_id_of_attr(CodeCounter_last_revise_date, Temp_Pom_Class, &attr_id)); + CALL(POM_set_attr_date(1, &instance_tag, attr_id, getCurrentDate())); + + CALL(POM_attr_id_of_attr(CodeCounter_createUser, Temp_Pom_Class, &attr_id)); + ITKCALL(POM_set_attr_tag(1, &instance_tag, attr_id, getCurrentUser())); + CALL(POM_attr_id_of_attr(CodeCounter_last_revise_user, Temp_Pom_Class, &attr_id)); + ITKCALL(POM_set_attr_tag(1, &instance_tag, attr_id, getCurrentUser())); + + CALL(POM_save_instances(1, &instance_tag, TRUE)); + //CALL( POM_refresh_instances_any_class( 1, &instance_tag, POM_no_lock ) ); + //fprintf( stdout, "a new itemid %s created at %d/%d/%d\n", new_item_id, create_date.year, create_date.month, create_date.day ); + return ifail; + } + + /** + Removes the given object from the database. + + @param tag_t object + */ + //#define TC_delete_msg "IMAN_delete" + int recycle_deleted_ItemID(METHOD_message_t* msg, va_list args) + { + int ifail = ITK_ok; + char buf[BUFSIZ] = ""; + + //retrieve the deleted object (will but not yet) from IMAN_delete msg + tag_t deleted_item = va_arg(args, tag_t); + //char deleted_item_id[ITEM_id_size_c + 1] = ""; + //ITKCALL( ifail = ITEM_ask_id(deleted_item, deleted_item_id) ); + if (ifail == ITK_ok) + { + char* pattern_code = NULL; + ITKCALL(ifail = AOM_ask_value_string(deleted_item, Item_codePattern, &pattern_code)); + if (ifail == ITK_ok && pattern_code != NULL && strlen(pattern_code) > 0) + { + char* item_id; + ITKCALL(ifail = AOM_ask_value_string(deleted_item, Item_codeID, &item_id)); + if (tc_strlen(item_id) > 0) + { + SaveReduntantItemId(pattern_code, item_id, "false"); + } + MEM_free(pattern_code); + MEM_free(item_id); + } + } + return ITK_ok; + } + + int recycleNewProjectId(METHOD_message_t* msg, va_list args) + { + int ifail = ITK_ok, i = 0; + tag_t project = NULLTAG; + //char project_id[ITEM_id_size_c + 1] = ""; + char* project_id; + //char* project_idValue ; + + const char + * Temp_Pom_Class = "Cd9_CodeCounter"; + char + * id_attr_value = NULL; + tag_t + class_id = NULLTAG, + id_attr_id = NULLTAG; + //occ_attr_id = NULLTAG, + //createdate_attr_id = NULLTAG; + logical + include_subclasses = FALSE, + is_it_null = FALSE, + is_it_empty = FALSE, + find_deleted_instance = FALSE; + int + n_instance = 0, + lock_token = 0; + tag_t + * instance_tags = NULL, + one_instance = NULLTAG, + deleted_instance = NULLTAG; + //msg_item_tag = msg->object; + //CALL( ITEM_ask_item_of_rev( msg_item_tag, &item ) ); + + char* rule_name = NULL; + + //project = msg->object_tag; + /* 无法获得,按顺序,第一个为id + project = va_arg( args, tag_t ); + if (project == NULLTAG) + { + printf("FUNCTION : recycleNewProjectId.\nERROR : object tag is NULLTAG.\n"); + return ifail; + } + */ + + //ITKCALL(PROJ_ask_id( project, project_id ) ); + //fprintf( stdout, "project_id == %s\n", project_id ); + project_id = va_arg(args, char*); + //fprintf( stdout, "project_id == %s\n", project_id ); + + ITKCALL(POM_class_id_of_class(Temp_Pom_Class, &class_id)); + ITKCALL(POM_attr_id_of_attr(CodeCounter_recycleID, Temp_Pom_Class, &id_attr_id)); + ITKCALL(POM_instances_of_class(class_id, include_subclasses, &n_instance, &instance_tags)); + //fprintf( stdout, "%d instances found\n", n_instance ); + if (n_instance == 0) { + return ITK_ok; + } + //加载所有的实例,但是不要锁定 + ITKCALL(POM_load_instances_any_class(n_instance, instance_tags, POM_no_lock)); + + for (i = 0; i < n_instance; i++) + { + one_instance = instance_tags[i]; + ITKCALL(POM_ask_attr_string(one_instance, id_attr_id, &id_attr_value, &is_it_null, &is_it_empty)); + + if (tc_strcmp(id_attr_value, project_id) == 0 && find_deleted_instance == FALSE) + { + deleted_instance = one_instance; + find_deleted_instance = TRUE; + + ITKCALL(POM_refresh_instances_any_class(1, &deleted_instance, POM_no_lock)); + ITKCALL(POM_ask_instance_lock(deleted_instance, &lock_token)); + if (lock_token == POM_no_lock) + { + ITKCALL(POM_delete_instances(1, &deleted_instance)); + //fprintf( stdout, "\n\nDelete a instance, its id is %s\n\n", id_attr_value ); + instance_tags[i] = NULLTAG; + } + MEM_free(id_attr_value); + break; + } + else + { + MEM_free(id_attr_value); + } + } + MEM_free(instance_tags); + return ifail; + } + + + + int recycleNewItemId(METHOD_message_t* msg, va_list args) + { + int ifail = ITK_ok, i = 0; + tag_t item = NULLTAG; + //char item_id[ITEM_id_size_c + 1] = ""; + char* item_id = NULL; + char* item_idValue; + + const char + * Temp_Pom_Class = "Cd9_CodeCounter"; + char + * id_attr_value = NULL; + tag_t + class_id = NULLTAG, + id_attr_id = NULLTAG; + //occ_attr_id = NULLTAG, + //createdate_attr_id = NULLTAG; + logical + include_subclasses = FALSE, + is_it_null = FALSE, + is_it_empty = FALSE, + find_deleted_instance = FALSE; + int + n_instance = 0, + lock_token = 0; + tag_t + * instance_tags = NULL, + one_instance = NULLTAG, + deleted_instance = NULLTAG; + //msg_item_tag = msg->object; + //CALL( ITEM_ask_item_of_rev( msg_item_tag, &item ) ); + + char* rule_name = NULL; + + item = msg->object; + if (item == NULLTAG) + { + printf("FUNCTION : recycleRedundantItemId.\nERROR : object tag is NULLTAG.\n"); + return ifail; + } + + // tag_t deleted_item = va_arg( args, tag_t ); + + ITKCALL(ITEM_ask_id2(item, &item_id)); + //fprintf( stdout, "item id %s\n", item_id ); + + ITKCALL(POM_class_id_of_class(Temp_Pom_Class, &class_id)); + ITKCALL(POM_attr_id_of_attr(CodeCounter_recycleID, Temp_Pom_Class, &id_attr_id)); + ITKCALL(POM_instances_of_class(class_id, include_subclasses, &n_instance, &instance_tags)); + //fprintf( stdout, "%d instances found\n", n_instance ); + if (n_instance == 0) { + return ITK_ok; + } + //加载所有的实例,但是不要锁定 + ITKCALL(POM_load_instances_any_class(n_instance, instance_tags, POM_no_lock)); + + for (i = 0; i < n_instance; i++) + { + one_instance = instance_tags[i]; + ITKCALL(POM_ask_attr_string(one_instance, id_attr_id, &id_attr_value, &is_it_null, &is_it_empty)); + + if (tc_strcmp(id_attr_value, item_id) == 0 && find_deleted_instance == FALSE) + { + deleted_instance = one_instance; + find_deleted_instance = TRUE; + + ITKCALL(POM_refresh_instances_any_class(1, &deleted_instance, POM_no_lock)); + ITKCALL(POM_ask_instance_lock(deleted_instance, &lock_token)); + if (lock_token == POM_no_lock) + { + ITKCALL(POM_delete_instances(1, &deleted_instance)); + //fprintf( stdout, "\n\nDelete a instance, its id is %s\n\n", id_attr_value ); + instance_tags[i] = NULLTAG; + } + MEM_free(id_attr_value); + break; + } + else + { + MEM_free(id_attr_value); + } + } + MEM_free(instance_tags); + MEM_free(item_id); + return ifail; + } + + /* + int recycle_ItemID( void *returnValue) + { + int ifail = ITK_ok; + char* class_name = "Cd9_CodeCounter"; + char* codeID;; + int length=0,i=0; + + USERARG_get_string_argument(&codeID); + tag_t class_id = NULLTAG; + ITKCALL(POM_class_id_of_class(class_name, &class_id)); + + //find all instance + int n_instances = 0, n_ret_instances = 0; + tag_t *instance_tags = NULL, *ret_instances = NULL; + ITKCALL(POM_instances_of_class(class_id, FALSE, &n_instances, + &instance_tags)); + if (n_instances > 0) + { + ITKCALL(POM_load_instances_possible(n_instances, instance_tags, &n_ret_instances, &ret_instances)); + } + + for (int i = 0; i < n_ret_instances; ++i) { + tag_t bo_inst = ret_instances[i]; + tag_t recycleID_attr_id = NULLTAG; + tag_t occ_attr_id = NULLTAG; + char *recycleID_value = NULL; + logical is_it_null = FALSE; + logical is_it_empty = FALSE; + + ITKCALL( POM_attr_id_of_attr( CodeCounter_isUsed, class_name, &occ_attr_id ) ); + ITKCALL(POM_attr_id_of_attr(CodeCounter_recycleID, + class_name, &recycleID_attr_id)); + + ITKCALL(POM_ask_attr_string(bo_inst,recycleID_attr_id, + &recycleID_value, &is_it_null, &is_it_empty)); + // printf("recycleID_value=============%s\n",recycleID_value); + + if( tc_strcmp( recycleID_value, codeID ) == 0 ) + { + ITKCALL( POM_refresh_instances_any_class( 1, &ret_instances[i], POM_modify_lock ) ); + ITKCALL( POM_set_attr_string( 1, &ret_instances[i], occ_attr_id, "false" ) ); + ITKCALL(ifail = POM_save_instances(1, &ret_instances[i], false)); + ITKCALL(ifail = POM_refresh_instances_any_class(1, &ret_instances[i], POM_no_lock)); + MEM_free( recycleID_value ); + break; + } + MEM_free( recycleID_value ); + } + CALL( POM_unload_instances( n_instances, instance_tags ) ); + MEM_free( codeID ); + MEM_free( instance_tags ); + MEM_free( ret_instances ); + return ifail; + }*/ + + int delete_recycleID(void* returnValue) + { + int ifail = ITK_ok; + const char* class_name = "Cd9_CodeCounter"; + char* codeID;; + int length = 0, i = 0; + + USERARG_get_string_argument(&codeID); + tag_t class_id = NULLTAG; + ITKCALL(POM_class_id_of_class(class_name, &class_id)); + + //find all instance + int n_instances = 0, n_ret_instances = 0; + tag_t* instance_tags = NULL, * ret_instances = NULL; + ITKCALL(POM_instances_of_class(class_id, FALSE, &n_instances, + &instance_tags)); + if (n_instances > 0) + { + ITKCALL(POM_load_instances_possible(n_instances, instance_tags, &n_ret_instances, &ret_instances)); + } + + for (int i = 0; i < n_ret_instances; ++i) { + tag_t bo_inst = ret_instances[i]; + tag_t recycleID_attr_id = NULLTAG; + tag_t occ_attr_id = NULLTAG; + char* recycleID_value = NULL; + logical is_it_null = FALSE; + logical is_it_empty = FALSE; + + ITKCALL(POM_refresh_instances_any_class(1, &bo_inst, POM_no_lock)); + + ITKCALL(POM_attr_id_of_attr(CodeCounter_isUsed, class_name, &occ_attr_id)); + ITKCALL(POM_attr_id_of_attr(CodeCounter_recycleID, + class_name, &recycleID_attr_id)); + + ITKCALL(POM_ask_attr_string(bo_inst, recycleID_attr_id, + &recycleID_value, &is_it_null, &is_it_empty)); + //printf("recycleID_value=============%s\n",recycleID_value); + //printf("codeID=============%s\n",codeID); + + if (tc_strcmp(recycleID_value, codeID) == 0) + { + int lock_token = 0; + ITKCALL(POM_refresh_instances_any_class(1, &ret_instances[i], POM_no_lock)); + ITKCALL(POM_ask_instance_lock(ret_instances[i], &lock_token)); + if (lock_token == POM_no_lock) + { + ITKCALL(POM_delete_instances(1, &ret_instances[i])); + ret_instances[i] = NULLTAG; + } + MEM_free(recycleID_value); + break; + } + MEM_free(recycleID_value); + } + + MEM_free(codeID); + MEM_free(instance_tags); + MEM_free(ret_instances); + return ifail; + } +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/qf_nx_itk-master (3)/qf_nx_itk/Connor_NX/K_recycle_item_id.h b/qf_nx_itk-master (3)/qf_nx_itk/Connor_NX/K_recycle_item_id.h new file mode 100644 index 0000000..3390315 --- /dev/null +++ b/qf_nx_itk-master (3)/qf_nx_itk/Connor_NX/K_recycle_item_id.h @@ -0,0 +1,53 @@ +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include "K_autocode_util.h" +#include "origin_PropNames.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define ECHO(X) printf X; +#define SYS_LOG(X) TC_write_syslog X; +#define LOG_ECHO(X) printf X; TC_write_syslog X; + /*! + * \def CALL(x) + * 打印错误信息 + */ +#define CALL(x) { \ + int stat; \ + char *err_string; \ + if( (stat = (x)) != ITK_ok) \ + { \ + EMH_ask_error_text (stat, &err_string); \ + LOG_ECHO( ("ERROR: %d ERROR MSG: %s.\n",stat, err_string) ) \ + LOG_ECHO( ("Function: %s FILE: %s LINE: %d\n", #x, __FILE__, __LINE__ ) ) \ + MEM_free (err_string); \ + return (stat); \ +} \ +} +#define ITEM_POM_CLASS "ITEM" + + int QueryReduntantItemId(char* TeZhengMa, char** the_item_id); + int recycle_ItemID(void* returnValue); + int recycle_deleted_ItemID(METHOD_message_t* msg, va_list args); + int SaveReduntantItemId(char* TeZhengMa, char* new_item_id, const char* occupied); + int recycleNewItemId(METHOD_message_t* msg, va_list args); + int recycleNewProjectId(METHOD_message_t* msg, va_list args); + int delete_recycleID(void* returnValue); + +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/qf_nx_itk-master (3)/qf_nx_itk/Connor_NX/K_searchClassificationNodes.cpp b/qf_nx_itk-master (3)/qf_nx_itk/Connor_NX/K_searchClassificationNodes.cpp new file mode 100644 index 0000000..0e4cc66 --- /dev/null +++ b/qf_nx_itk-master (3)/qf_nx_itk/Connor_NX/K_searchClassificationNodes.cpp @@ -0,0 +1,589 @@ +#include "Connor_NX.h" +#include "origin_PropNames.h" +#include +#include + +using namespace std; + +#ifdef __cplusplus +extern "C" { +#endif + + //void map_insert(map < string, string >* strmap, string index, string x) + //{ + // //printf("map_insert==1 =====\n"); + // //strmap->insert(map < string, string >::value_type(index, x)); + // strmap->insert(pair< string, string >(index, x)); + // // printf("map_insert==2 =====\n"); + //} + + void init_search_criteria_map(string searchStr, SearchCriterionInputs &searchCriteria) { + vector searchStrSplit; + // printf("Search AutoCode_Node: %s \n", searchStr.c_str()); + Split(searchStr, SPLITTER, searchStrSplit); + int length = searchStrSplit.size(); + for (int i = 0; i < length; i++) { + string str = searchStrSplit[i]; + int ind = str.find_first_of('='); + if (ind <= 0) { + continue; + } + string s1 = str.substr(0, ind); + string s2 = str.substr(ind + 1); + map_insert(&searchCriteria, s1, s2); + } + } + + void init_search_criteria_vector(string searchStr, vector &propNames, vector &propValues) { + vector searchStrSplit; + // printf("Search AutoCode_Node: %s \n", searchStr.c_str()); + Split(searchStr, SPLITTER, searchStrSplit); + int length = searchStrSplit.size(); + for (int i = 0; i < length; i++) { + string str = searchStrSplit[i]; + int ind = str.find_first_of('='); + if (ind <= 0) { + continue; + } + string s1 = str.substr(0, ind); + string s2 = str.substr(ind + 1); + propNames.push_back(s1); + propValues.push_back(s2); + } + } + + int SEARCH_AUTOCODE_USER(const std::string& searchStr, std::string& res) { + int ifail = ITK_ok; + const char* class_name = "Cd9_ClassificationCodeNode"; + RetData retData; + SearchCriterionInputs searchCriteria; + + init_search_criteria_map(searchStr, searchCriteria); + //get class id and attr id + tag_t class_id = NULLTAG; + ITKCALL(POM_class_id_of_class(class_name, &class_id)); + + std::map prop_to_attrid; + std::map prop_value_type; + for (SearchCriterionInputs::const_iterator searchIter = + searchCriteria.begin(); searchIter != searchCriteria.end(); searchIter++) { + tag_t attr_id = NULLTAG; + ITKCALL(POM_attr_id_of_attr(searchIter->first.c_str(), + class_name, &attr_id)); + + if (prop_to_attrid.find(searchIter->first) == prop_to_attrid.end()) { + prop_to_attrid.insert(make_pair(searchIter->first, attr_id)); + if (searchIter->first.compare(ClassificationCodeNode_node_name) == 0 + || searchIter->first.compare(ClassificationCodeNode_segment) == 0 + ) { + prop_value_type.insert(make_pair(searchIter->first, + "String")); + continue; + } + } + } + + //find all instance + int n_instances = 0, n_ret_instances = 0; + tag_t* instance_tags = NULL, * ret_instances = NULL; + ITKCALL(POM_instances_of_class(class_id, FALSE, &n_instances, + &instance_tags)); + if (n_instances > 0) + { + ITKCALL(POM_load_instances_possible(n_instances, instance_tags, &n_ret_instances, &ret_instances)); + } + + for (int i = 0; i < n_ret_instances; ++i) { + tag_t bo_inst = ret_instances[i]; + logical is_same = TRUE; + + for (SearchCriterionInputs::const_iterator searchIter = + searchCriteria.begin(); searchIter != searchCriteria.end(); searchIter++) { + std::map::iterator prop_to_attrid_iter = + prop_to_attrid.find(searchIter->first); + + std::map::iterator prop_value_type_iter = + prop_value_type.find(searchIter->first); + + + if (prop_value_type_iter->second.compare("String") == 0) { + char* str_val = NULL; + logical is_it_null = FALSE; + logical is_it_empty = FALSE; + ITKCALL(POM_ask_attr_string(bo_inst, prop_to_attrid_iter->second, + &str_val, &is_it_null, &is_it_empty)); + + if ((is_it_empty || is_it_null) && ((tc_strlen(searchIter->second.c_str()) == 0) || (searchIter->second.c_str() == NULL))) + { + continue; + } + if (tc_strcmp(searchIter->second.c_str(), str_val) != 0) { + is_same = FALSE; + MEM_free(str_val); + break; + } + MEM_free(str_val); + } + } + + if (is_same) { + tag_t attr_id = NULLTAG; + logical* is_it_null = FALSE, * is_it_empty = FALSE; + tag_t* values; + int targetNum = 0; + + ITKCALL(POM_attr_id_of_attr(ClassificationCodeNode_grant_users, class_name, &attr_id)); + POM_length_of_attr(bo_inst, attr_id, &targetNum); + if (targetNum > 0) { + ITKCALL(POM_ask_attr_tags(bo_inst, attr_id, 0, targetNum, &values, &is_it_null, &is_it_empty)); + for (int i = 0; i < targetNum; i++) + { + if (values[i] != NULLTAG) + { + retData.insert(retData.end(), values[i]); + } + } + } + + ITKCALL(POM_attr_id_of_attr(ClassificationCodeNode_grant_roles, class_name, &attr_id)); + POM_length_of_attr(bo_inst, attr_id, &targetNum); + if (targetNum > 0) { + ITKCALL(POM_ask_attr_tags(bo_inst, attr_id, 0, targetNum, &values, &is_it_null, &is_it_empty)); + for (int i = 0; i < targetNum; i++) + { + if (values[i] != NULLTAG) + { + retData.insert(retData.end(), values[i]); + } + } + } + + ITKCALL(POM_attr_id_of_attr(ClassificationCodeNode_grant_groups, class_name, &attr_id)); + POM_length_of_attr(bo_inst, attr_id, &targetNum); + if (targetNum > 0) { + ITKCALL(POM_ask_attr_tags(bo_inst, attr_id, 0, targetNum, &values, &is_it_null, &is_it_empty)); + for (int i = 0; i < targetNum; i++) + { + if (values[i] != NULLTAG) + { + retData.insert(retData.end(), values[i]); + } + } + } + + MEM_free(is_it_null); + MEM_free(is_it_empty); + + } + continue; + } + int arraySize = 0; + tag_t* tag_array; + USERSERVICE_array_t arrayStruct; + arraySize = retData.size(); + tag_array = (tag_t*)MEM_alloc(arraySize * sizeof(tag_t)); + //printf("arraySize=======%d\n",arraySize); + + RetDataIterator retDataIterator = retData.begin(); + for (int i = 0; i < arraySize; i++) + { + char* uid = NULL; + tag_array[i] = static_cast(*retDataIterator); + //printf("tag_array[i]=======%u\n",tag_array[i]); + ITK__convert_tag_to_uid(tag_array[i], &uid); + if (uid != NULL) { + res.append(uid).append(SPLITTER); + } + ++retDataIterator; + DOFREE(uid); + } + /*ITKCALL(USERSERVICE_return_tag_array(tag_array, arraySize, + &arrayStruct)); + if (arrayStruct.length != 0) { + *((USERSERVICE_array_t*)returnValue) = arrayStruct; + }*/ + + MEM_free(instance_tags); + MEM_free(ret_instances); + MEM_free(tag_array); + return ifail; + } + + int SEARCH_AUTOCODE_SEGMENT(const std::string& searchStr, std::string& res) { + int ifail = ITK_ok; + const char* class_name = "Cd9_ClassificationCodeNode"; + RetData retData; + SearchCriterionInputs searchCriteria; + + init_search_criteria_map(searchStr, searchCriteria); + + tag_t class_id = NULLTAG; + ITKCALL(POM_class_id_of_class(class_name, &class_id)); + + std::map prop_to_attrid; + std::map prop_value_type; + for (SearchCriterionInputs::const_iterator searchIter = + searchCriteria.begin(); searchIter != searchCriteria.end(); searchIter++) { + tag_t attr_id = NULLTAG; + ITKCALL(POM_attr_id_of_attr(searchIter->first.c_str(), + class_name, &attr_id)); + + if (prop_to_attrid.find(searchIter->first) == prop_to_attrid.end()) { + prop_to_attrid.insert(make_pair(searchIter->first, attr_id)); + + if (searchIter->first.compare(ClassificationCodeNode_node_name) == 0) { + prop_value_type.insert(make_pair(searchIter->first, + "String")); + continue; + } + } + else + if (searchIter->first.compare(ClassificationCodeNode_grant_users) == 0 + || searchIter->first.compare(ClassificationCodeNode_grant_roles) == 0 + || searchIter->first.compare(ClassificationCodeNode_grant_groups) == 0 + ) { + prop_value_type.insert(make_pair(searchIter->first, + "TCComponents")); + continue; + } + } + + int n_instances = 0, n_ret_instances = 0; + tag_t* instance_tags = NULL, * ret_instances = NULL; + ITKCALL(POM_instances_of_class(class_id, FALSE, &n_instances, + &instance_tags)); + if (n_instances > 0) + { + ITKCALL(POM_load_instances_possible(n_instances, instance_tags, &n_ret_instances, &ret_instances)); + } + + for (int i = 0; i < n_ret_instances; ++i) { + tag_t bo_inst = ret_instances[i]; + logical is_same = TRUE; + int nullUserCount = 0; + + for (SearchCriterionInputs::const_iterator searchIter = + searchCriteria.begin(); searchIter != searchCriteria.end(); searchIter++) { + std::map::iterator prop_to_attrid_iter = + prop_to_attrid.find(searchIter->first); + + std::map::iterator prop_value_type_iter = + prop_value_type.find(searchIter->first); + + + if (prop_value_type_iter->second.compare("String") == 0) { + char* str_val = NULL; + logical is_it_null = FALSE; + logical is_it_empty = FALSE; + ITKCALL(POM_ask_attr_string(bo_inst, prop_to_attrid_iter->second, + &str_val, &is_it_null, &is_it_empty)); + + if ((is_it_empty || is_it_null) && ((tc_strlen(searchIter->second.c_str()) == 0) || (searchIter->second.c_str() == NULL))) + { + continue; + } + if (tc_strcmp(searchIter->second.c_str(), str_val) != 0) { + is_same = FALSE; + MEM_free(str_val); + break; + } + MEM_free(str_val); + + } + else { + if (prop_value_type_iter->second.compare("TCComponents") == 0) { + } + } + } + + if (is_same) { + tag_t attr_id = NULLTAG; + logical is_it_null = FALSE, is_it_empty = FALSE; + char* strValues = NULL; + ITKCALL(POM_attr_id_of_attr(ClassificationCodeNode_segment, class_name, &attr_id)); + ITKCALL(POM_ask_attr_string(bo_inst, attr_id, &strValues, &is_it_null, &is_it_empty)); + + if (tc_strlen(strValues) == 0) + { + continue; + } + + std::vector< std::string > searched_tags; + Split(strValues, ",", searched_tags); + for (int i = 0; i < (int)searched_tags.size(); i++) + { + if (tc_strlen(searched_tags[i].c_str()) > 0) + { + tag_t ref_obj = NULLTAG; + ITKCALL(POM_string_to_tag(searched_tags[i].c_str(), &ref_obj)); + if (ref_obj != NULLTAG) + { + retData.insert(retData.end(), ref_obj); + } + } + } + + MEM_free(strValues); + } + continue; + } + int arraySize = 0; + tag_t* tag_array; + USERSERVICE_array_t arrayStruct; + arraySize = retData.size(); + tag_array = (tag_t*)MEM_alloc(arraySize * sizeof(tag_t)); + //printf("arraySize=======%d\n",arraySize); + + RetDataIterator retDataIterator = retData.begin(); + for (int i = 0; i < arraySize; i++) + { + char* uid = NULL; + tag_array[i] = static_cast(*retDataIterator); + ITK__convert_tag_to_uid(tag_array[i], &uid); + if (uid != NULL) { + res.append(uid).append(SPLITTER); + } + DOFREE(uid); + //printf("tag_array[i]=======%u\n",tag_array[i]); + ++retDataIterator; + } + + MEM_free(instance_tags); + MEM_free(ret_instances); + MEM_free(tag_array); + return ifail; + } + + int SEARCH_AUTOCODE_NODE(const std::string& searchStr, std::string& res) { + int ifail = ITK_ok; + const char* class_name = "Cd9_ClassificationCodeNode"; + RetData retData; + SearchCriterionInputs searchCriteria; + int length = 0, i = 0; + std::map prop_to_attrid; + std::map prop_value_type; + tag_t class_id = NULLTAG; + int n_instances = 0, n_ret_instances = 0; + tag_t* instance_tags = NULL, * ret_instances = NULL; + tag_t* tag_array = NULL; + + // printf("Search AutoCode_Node: %s \n", searchStr.c_str()); + init_search_criteria_map(searchStr, searchCriteria); + + ITKCALL(POM_class_id_of_class(class_name, &class_id)); + + for (SearchCriterionInputs::const_iterator searchIter = + searchCriteria.begin(); searchIter != searchCriteria.end(); searchIter++) { + tag_t attr_id = NULLTAG; + ITKCALL(POM_attr_id_of_attr(searchIter->first.c_str(), + class_name, &attr_id)); + + if (prop_to_attrid.find(searchIter->first) == prop_to_attrid.end()) { + prop_to_attrid.insert(make_pair(searchIter->first, attr_id)); + + if (searchIter->first.compare(ClassificationCodeNode_node_name) == 0 + || searchIter->first.compare(ClassificationCodeNode_segment) == 0) { + prop_value_type.insert(make_pair(searchIter->first, + "String")); + continue; + } + else + if (searchIter->first.compare(ClassificationCodeNode_grant_users) == 0 + || searchIter->first.compare(ClassificationCodeNode_grant_roles) == 0 + || searchIter->first.compare(ClassificationCodeNode_grant_groups) == 0 + ) { + prop_value_type.insert(make_pair(searchIter->first, + "TCComponents")); + continue; + } + } + } + + //find all instance + + ITKCALL(POM_instances_of_class(class_id, FALSE, &n_instances, + &instance_tags)); + if (n_instances > 0) + { + ITKCALL(POM_load_instances_possible(n_instances, instance_tags, &n_ret_instances, &ret_instances)); + } + + for (int i = 0; i < n_ret_instances; ++i) { + tag_t bo_inst = ret_instances[i]; + logical is_same = TRUE; + int nullUserCount = 0; + + for (SearchCriterionInputs::const_iterator searchIter = + searchCriteria.begin(); searchIter != searchCriteria.end(); searchIter++) { + std::map::iterator prop_to_attrid_iter = + prop_to_attrid.find(searchIter->first); + std::map::iterator prop_value_type_iter = + prop_value_type.find(searchIter->first); + + //printf("searchIter->first===========%s\n",searchIter->first.c_str()); + //printf("searchIter->second.c_str()==========%s\n\n",searchIter->second.c_str()); + if (prop_value_type_iter->second.compare("String") == 0) { + char* str_val = NULL; + logical is_it_null = FALSE; + logical is_it_empty = FALSE; + ITKCALL(POM_ask_attr_string(bo_inst, prop_to_attrid_iter->second, + &str_val, &is_it_null, &is_it_empty)); + + //printf("searchIter->second.c_str()=======%s\n",searchIter->second.c_str()); + if ((is_it_empty || is_it_null) && ((tc_strlen(searchIter->second.c_str()) == 0) || (searchIter->second.c_str() == NULL))) + { + continue; + } + if (tc_strcmp(searchIter->second.c_str(), str_val) != 0) { + is_same = FALSE; + MEM_free(str_val); + break; + } + MEM_free(str_val); + } + else { + if (prop_value_type_iter->second.compare("TCComponents") == 0) { + logical* is_it_null = FALSE, * is_it_empty = FALSE; + tag_t* values; + int targetNum = 0, m = 0; + tag_t currentGroupTag; + + if (tc_strlen(searchIter->second.c_str()) == 0) + { + continue; + } + + ITKCALL(POM_string_to_tag(searchIter->second.c_str(), ¤tGroupTag)); + if (currentGroupTag == NULLTAG) + { + continue; + } + + POM_length_of_attr(bo_inst, prop_to_attrid_iter->second, &targetNum); + if (targetNum == 0) + { + nullUserCount = nullUserCount + 1; + continue; + } + if (targetNum > 0) { + logical isEqual = FALSE; + ITKCALL(POM_ask_attr_tags(bo_inst, prop_to_attrid_iter->second, 0, targetNum, &values, &is_it_null, &is_it_empty)); + for (int m = 0; m < targetNum; m++) + { + char* user; + ITKCALL(POM_tag_to_string(values[m], &user)); + if (tc_strcmp(user, searchIter->second.c_str()) == 0) + { + // printf("searchIter->first.c_str()=======%s\n",searchIter->first.c_str()); + isEqual = TRUE; + continue; + } + + //char objectType[TCTYPE_class_name_size_c+1]=""; + char* objectType = NULL; + tag_t typetag; + ITKCALL(TCTYPE_ask_object_type(values[m], &typetag)); + TCTYPE_ask_class_name2(typetag, &objectType); + if (tc_strcmp("Group", objectType) != 0) + { + MEM_free(user); + MEM_free(objectType); + continue; + } + MEM_free(objectType); + tag_t parent1; + char* parentString1; + SA_ask_group_parent(currentGroupTag, &parent1); + if (parent1 == NULLTAG) + { + MEM_free(user); + continue; + } + + ITKCALL(POM_tag_to_string(parent1, &parentString1)); + if (tc_strcmp(parentString1, user) == 0) + { + isEqual = TRUE; + MEM_free(user); + MEM_free(parentString1); + continue; + } + MEM_free(parentString1); + tag_t parent2; + char* parentString2; + SA_ask_group_parent(parent1, &parent2); + if (parent2 == NULLTAG) + { + MEM_free(user); + continue; + } + ITKCALL(POM_tag_to_string(parent2, &parentString2)); + if (tc_strcmp(parentString2, user) == 0) + { + isEqual = TRUE; + MEM_free(user); + MEM_free(parentString2); + continue; + } + else + { + MEM_free(user); + MEM_free(parentString2); + continue; + } + } + MEM_free(values); + MEM_free(is_it_null); + MEM_free(is_it_empty); + if (isEqual == FALSE) + { + nullUserCount = nullUserCount + 1; + } + } + } + } + } + if (is_same) { + // printf("is_same=======%d\n",is_same); + if (nullUserCount < 3) + { + retData.insert(retData.end(), bo_inst); + } + } + continue; + } + { + int arraySize = 0; + + USERSERVICE_array_t arrayStruct; + arraySize = retData.size(); + tag_array = (tag_t*)MEM_alloc(arraySize * sizeof(tag_t)); + //printf("arraySize=======%d\n",arraySize); + + RetDataIterator retDataIterator = retData.begin(); + for (i = 0; i < arraySize; i++) + { + char* uid = NULL; + tag_array[i] = static_cast(*retDataIterator); + ITK__convert_tag_to_uid(tag_array[i], &uid); + if (uid != NULL) { + res.append(uid).append(SPLITTER); + } + //printf("tag_array[i]=======%u\n",tag_array[i]); + ++retDataIterator; + DOFREE(uid); + } + } + + + search_autocode_node_end: + DOFREE(instance_tags); + DOFREE(ret_instances); + DOFREE(tag_array); + return ifail; + } + + +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/qf_nx_itk-master (3)/qf_nx_itk/Connor_NX/K_searchTreeOrListNodes.cpp b/qf_nx_itk-master (3)/qf_nx_itk/Connor_NX/K_searchTreeOrListNodes.cpp new file mode 100644 index 0000000..3fdae82 --- /dev/null +++ b/qf_nx_itk-master (3)/qf_nx_itk/Connor_NX/K_searchTreeOrListNodes.cpp @@ -0,0 +1,279 @@ +#include "Connor_NX.h" +#include "origin_PropNames.h" +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + + + const char* getChildrenNodesString(vector propNames, vector propValues, int length) + { + int ifail = ITK_ok; + const char* class_name = "Cd9_CodeRelation"; + const char* selectTreeNode = "Select Cd9_CodeRelation1"; + const char* select_nextidAttrs[1] = { CodeRelation_children_nodes }; + int rows, cols; + void*** report = NULL; + int i = 0; + const char* strValues; + + ITKCALL(POM_enquiry_create(selectTreeNode)); + ITKCALL(POM_enquiry_add_select_attrs(selectTreeNode, class_name, + 1, (const char**)select_nextidAttrs)); + + if (length == 1) + { + if (tc_strlen(propValues[0].c_str()) == 0) + { + ifail = POM_enquiry_set_attr_expr(selectTreeNode, "expr1", class_name, propNames[0].c_str(), POM_enquiry_is_null, NULL); + } + else + { + const char* temp = propValues[0].c_str(); + ifail = POM_enquiry_set_string_value(selectTreeNode, "prop1", 1, (const char**)&temp, POM_enquiry_bind_value); + ifail = POM_enquiry_set_attr_expr(selectTreeNode, "expr1", class_name, propNames[0].c_str(), POM_enquiry_equal, "prop1"); + } + ifail = POM_enquiry_set_where_expr(selectTreeNode, "expr1"); + } + else { + if (tc_strlen(propValues[0].c_str()) == 0) + { + ifail = POM_enquiry_set_attr_expr(selectTreeNode, "expr1", class_name, propNames[0].c_str(), POM_enquiry_is_null, NULL); + } + else + { + const char* temp = propValues[0].c_str(); + ifail = POM_enquiry_set_string_value(selectTreeNode, "prop1", 1, (const char**)&temp, POM_enquiry_bind_value); + ifail = POM_enquiry_set_attr_expr(selectTreeNode, "expr1", class_name, propNames[0].c_str(), POM_enquiry_equal, "prop1"); + } + + if (tc_strlen(propValues[1].c_str()) == 0) + { + ifail = POM_enquiry_set_attr_expr(selectTreeNode, "expr2", class_name, propNames[1].c_str(), POM_enquiry_is_null, NULL); + } + else + { + const char* temp = propValues[1].c_str(); + ifail = POM_enquiry_set_string_value(selectTreeNode, "prop2", 1, (const char**)&temp, POM_enquiry_bind_value); + ifail = POM_enquiry_set_attr_expr(selectTreeNode, "expr2", class_name, propNames[1].c_str(), POM_enquiry_equal, "prop2"); + } + POM_enquiry_set_expr(selectTreeNode, "expr", "expr1", POM_enquiry_and, "expr2"); + ifail = POM_enquiry_set_where_expr(selectTreeNode, "expr"); + } + + ITKCALL(POM_enquiry_execute(selectTreeNode, &rows, &cols, &report)); + //printf("nextidRows===============%d\n",rows); + if (rows > 0) + { + strValues = (char*)report[0][0]; + } + else + { + strValues = ""; + } + POM_enquiry_delete(selectTreeNode); + return strValues; + } + + int isContainChildrenNode(vector propNames, vectorpropValues, int length) + { + int returnValue = 0;; + const char* value = getChildrenNodesString(propNames, propValues, length); + if (tc_strlen(value) > 0) + { + returnValue = 1; + } + return returnValue; + } + + int SEARCH_TREE_OR_LIST_NODE(const std::string& searchStr, std::string& res) { + int ifail = ITK_ok; + const char* class_name = "Cd9_CodeRelation"; + int i = 0; + int length = 0; + vector propNames; + vector propValues; + //clock_t start, finish; + //double duration; + //start = clock(); + + init_search_criteria_vector(searchStr, propNames, propValues); + length = propNames.size(); + const char* strValues = getChildrenNodesString(propNames, propValues, length); + if (tc_strlen(strValues) > 0) + { + int arraySize = 0; + std::vector< std::string > searched_tags; + Split(strValues, ",", searched_tags); + arraySize = (int)searched_tags.size(); + for (int i = 0; i < (int)searched_tags.size(); i++) + { + if (tc_strlen(searched_tags[i].c_str()) > 0) + { + + tag_t ref_obj = NULLTAG; + ITKCALL(POM_string_to_tag(searched_tags[i].c_str(), &ref_obj)); + if (ref_obj != NULLTAG) + { + res.append(searched_tags[i].c_str()).append(SPLITTER); + } + } + } + } + //finish = clock(); + //duration = (double)(finish - start) / CLOCKS_PER_SEC; + //printf("%f seconds查询时间\n",duration); + propNames.clear(); + propValues.clear(); + return ifail; + } + + int IS_CONTAIN_CHILD_NODE(const std::string& searchStr, std::string& res) + { + int ifail = ITK_ok; + const char* class_name = "Cd9_CodeRelation"; + RetData retData; + + vector propNames; + vector propValues; + int length = 0, i = 0; + /*ITKCALL(ifail = USERARG_get_string_array_argument(&length, &propNames)); + ITKCALL(ifail = USERARG_get_string_array_argument(&length, &propValues)); + for (i = 0; i < length; i++) + { + string s1 = (propNames[i]); + string s2 = (propValues[i]); + }*/ + init_search_criteria_vector(searchStr, propNames, propValues); + length = propNames.size(); + int isContains = isContainChildrenNode(propNames, propValues, length); + char* returnData; + returnData = (char*)MEM_alloc(5 * sizeof(char)); + if (isContains == 1) + { + tc_strcpy(returnData, "true"); + } + else + { + tc_strcpy(returnData, "false"); + } + res.append(returnData); + propNames.clear(); + propValues.clear(); + return ifail; + } + + int SEARCH_PARENT_TREE_OR_LIST_NODE(const std::string& searchStr, std::string& res) { + int ifail = ITK_ok; + const char* class_name = "Cd9_CodeRelation"; + SearchCriterionInputs searchCriteria; + + init_search_criteria_map(searchStr, searchCriteria); + tag_t class_id = NULLTAG; + ITKCALL(POM_class_id_of_class(class_name, &class_id)); + + std::map prop_to_attrid; + std::map prop_value_type; + + for (SearchCriterionInputs::const_iterator searchIter = + searchCriteria.begin(); searchIter != searchCriteria.end(); searchIter++) { + tag_t attr_id = NULLTAG; + ITKCALL(POM_attr_id_of_attr(searchIter->first.c_str(), + class_name, &attr_id)); + + if (prop_to_attrid.find(searchIter->first) == prop_to_attrid.end()) { + prop_to_attrid.insert(make_pair(searchIter->first, attr_id)); + + if (searchIter->first.compare(CodeRelation_children_nodes) == 0 + || searchIter->first.compare(CodeRelation_current_node) == 0) { + prop_value_type.insert(make_pair(searchIter->first, + "String")); + continue; + } + } + } + + //find all instance + int n_instances = 0, n_ret_instances = 0; + tag_t* instance_tags = NULL, * ret_instances = NULL; + ITKCALL(POM_instances_of_class(class_id, FALSE, &n_instances, + &instance_tags)); + if (n_instances > 0) + { + ITKCALL(POM_load_instances_possible(n_instances, instance_tags, &n_ret_instances, &ret_instances)); + } + + for (int i = 0; i < n_ret_instances; ++i) { + tag_t bo_inst = ret_instances[i]; + logical is_same = TRUE; + + for (SearchCriterionInputs::const_iterator searchIter = + searchCriteria.begin(); searchIter != searchCriteria.end(); searchIter++) { + std::map::iterator prop_to_attrid_iter = + prop_to_attrid.find(searchIter->first); + + std::map::iterator prop_value_type_iter = + prop_value_type.find(searchIter->first); + + //printf("searchIter->first===========%s\n",searchIter->first.c_str()); + //printf("searchIter->second.c_str()==========%s\n\n",searchIter->second.c_str()); + if (prop_value_type_iter->second.compare("String") == 0) { + char* str_val = NULL; + logical is_it_null = FALSE; + logical is_it_empty = FALSE; + ITKCALL(POM_ask_attr_string(bo_inst, prop_to_attrid_iter->second, + &str_val, &is_it_null, &is_it_empty)); + + if ((is_it_empty || is_it_null) && ((tc_strlen(searchIter->second.c_str()) == 0) || (searchIter->second.c_str() == NULL))) + { + continue; + } + if (tc_strcmp(searchIter->second.c_str(), str_val) != 0) { + is_same = FALSE; + MEM_free(str_val); + break; + } + MEM_free(str_val); + } + } + + if (is_same) { + tag_t attr_id = NULLTAG; + logical is_it_null = FALSE, is_it_empty = FALSE; + char* strValues = NULL; + ITKCALL(POM_attr_id_of_attr(CodeRelation_parent_nodes, class_name, &attr_id)); + ITKCALL(POM_ask_attr_string(bo_inst, attr_id, &strValues, &is_it_null, &is_it_empty)); + + if (is_it_empty || is_it_null) + { + continue; + } + std::vector< std::string > searched_tags; + Split(strValues, ",", searched_tags); + for (int i = 0; i < (int)searched_tags.size(); i++) + { + if (tc_strlen(searched_tags[i].c_str()) > 0) + { + tag_t ref_obj = NULLTAG; + ITKCALL(POM_string_to_tag(searched_tags[i].c_str(), &ref_obj)); + if (ref_obj != NULLTAG) + { + res.append(searched_tags[i]).append(SPLITTER); + } + } + } + MEM_free(strValues); + } + continue; + } + + MEM_free(instance_tags); + MEM_free(ret_instances); + // MEM_free(tag_array); + return ifail; + } +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/qf_nx_itk-master (3)/qf_nx_itk/Connor_NX/Top_Down_Design.cpp b/qf_nx_itk-master (3)/qf_nx_itk/Connor_NX/Top_Down_Design.cpp new file mode 100644 index 0000000..47843fa --- /dev/null +++ b/qf_nx_itk-master (3)/qf_nx_itk/Connor_NX/Top_Down_Design.cpp @@ -0,0 +1,378 @@ +#include "Connor_NX.h" +using namespace std; + +//#define PROPNAME_CLONE "object_desc" +//#define PROPVALUE_CLONE "clone" +//#define IMAGE_DSNAME_SANWEI "三维简图.bmp" +//#define IMAGE_DSNAME_ERWEI "二维简图.bmp" +#define PREF_NX_TEMPLATE "Connor_NXBomClone" +string PROPNAME_CLONE, PROPVALUE_CLONE, IMAGE_DSNAME_SANWEI, IMAGE_DSNAME_ERWEI, INPUT_SUFFIX; +string err; + +int Get_New_ID(tag_t item_type_tag, char** new_item_id) { + int ifail = ITK_ok; + logical isModified = FALSE; + ITKCALL(ifail = USER_new_item_id(NULLTAG, item_type_tag, &isModified, new_item_id)); + return ifail; +} + +int Get_New_ID(tag_t item_type_tag, string old_id, string suffix, string &new_item_id) { + int ifail = ITK_ok; + logical isModified = FALSE; + logical exist = true; + printf("Get New ID From: %s\n", old_id.c_str()); + if (old_id.length() <= 4) { + exist = false; + char* newid = NULL; + ITKCALL(ifail = USER_new_item_id(NULLTAG, item_type_tag, &isModified, &newid)); + if (ifail != ITK_ok) { + goto end; + } + new_item_id.append(newid); + DOFREE(newid); + printf("Use Assigned ID: %s\n", new_item_id.c_str()); + } + else { + string featureCode = old_id.substr(0, 4); + featureCode.append(suffix); + int ii = 0; + string temp_id = ""; + ifail = QUERY_PART_NO(featureCode, temp_id); + if (ifail != ITK_ok) { + goto end; + } + printf("Autocode ID: %s\n", temp_id.c_str()); + ITKCALL(ifail = ITEM_id_exists(temp_id.c_str(), &exist)); + if (ifail != ITK_ok) { + goto end; + } + while (exist && ii != 15) { + ii++; + temp_id = ""; + string delete_resp=""; + ifail = QUERY_PART_NO(featureCode, temp_id); + if (ifail != ITK_ok) { + goto end; + } + printf("再次尝试获取 ID: %s\n", temp_id.c_str()); + DELETE_RECYCLE_ID(temp_id, delete_resp); + ITKCALL(ITEM_id_exists(temp_id.c_str(), &exist)); + } + ITKCALL(ITEM_id_exists(temp_id.c_str(), &exist)); + new_item_id.append(temp_id); + if (exist) { + err.append("获取新编码失败:").append(old_id); + printf("获取ID失败!\n"); + ifail = OUTPUT_CODE_ERROR; + } + } +end: + return ifail; +} + +int Check_Rev(tag_t rev_tag, std::string& res, vector& checkedIDs, bool is_top_line) { + int ifail = ITK_ok; + tag_t item_tag = NULLTAG; + char *item_id = NULL, *rev_id = NULL, *prop_value = NULL; + char * new_rev_id = NULL; + tag_t tType = NULLTAG; + logical isModified = FALSE; + string id_str, new_item_id; + if (!is_top_line) { + ITKCALL(ifail = AOM_ask_value_string(rev_tag, PROPNAME_CLONE.c_str(), &prop_value)); + if (ifail != ITK_ok || strcmp(PROPVALUE_CLONE.c_str(), prop_value) != 0) { + goto check_rev_end; + } + } + ITKCALL(ifail = ITEM_ask_item_of_rev(rev_tag, &item_tag)); + if (item_tag == NULLTAG) { + goto check_rev_end; + } + ITKCALL(ifail = AOM_ask_value_string(item_tag, "item_id", &item_id)); + if (ifail != ITK_ok) { + goto check_rev_end; + } + if(inArray(checkedIDs, item_id)){ + goto check_rev_end; + } + id_str.append(item_id); + ITKCALL(ifail = TCTYPE_ask_object_type(item_tag, &tType)); + ITKCALL(ifail = AOM_ask_value_string(rev_tag, "item_revision_id", &rev_id)); + ITKCALL(ifail = Get_New_ID(tType, id_str, INPUT_SUFFIX, new_item_id)); + if (ifail != ITK_ok) { + res.clear(); + res.append(err); + goto check_rev_end; + } + ITKCALL(ifail = USER_new_revision_id(NULLTAG, tType, &isModified, &new_rev_id)); + res.append(SPLITTER); + res.append("@DB/").append(item_id).append("/").append(rev_id); + res.append("="); + res.append("@DB/").append(new_item_id).append("/").append(new_rev_id); + checkedIDs.push_back(item_id); +check_rev_end: + DOFREE(item_id); + DOFREE(rev_id); + DOFREE(new_rev_id); + DOFREE(prop_value); + return ifail; +} + +int Cycle_BOM(tag_t bomline, std::string& res, vector& checkedIDs, bool is_top_line){ + int ifail = ITK_ok, child_cnt = 0; + tag_t rev_tag = NULLTAG, *child_lines = NULL; + ITKCALL(ifail = AOM_ask_value_tag(bomline, "bl_revision", &rev_tag)); + ifail = Check_Rev(rev_tag, res, checkedIDs, is_top_line); + if (ifail != ITK_ok) { + goto cycle_bom_end; + } + ITKCALL(ifail = BOM_line_ask_child_lines(bomline, &child_cnt, &child_lines)); + for (int i = 0;i < child_cnt;i++) { + ifail = Cycle_BOM(child_lines[i], res, checkedIDs, false); + if (ifail != ITK_ok) { + goto cycle_bom_end; + } + } + DOFREE(child_lines); +cycle_bom_end: + return ifail; +} + +int Read_NX_Image_By_ID(const std::string& itemID, std::string& res) { + + int ifail = ITK_ok, release_flag = 0; + int pref_len = 0, ds_count = 0; + char* object_string = NULL; + char* rev_id = NULL; + string erwei_file, sanwei_file; + tag_t item_tag = NULLTAG; + tag_t rev_tag = NULLTAG; + tag_t* ds_tags = NULL; + vector checkedIDs; + vector prefVals; + POM_AM__set_application_bypass(true); + getPrefStrings(PREF_NX_TEMPLATE, TC_preference_site, prefVals); + if (prefVals.size() != 5) { + res.append(("首选项配置错误:")).append(PREF_NX_TEMPLATE); + ifail = OUTPUT_CODE_ERROR; + goto gx_nx_image_end; + } + PROPNAME_CLONE = prefVals[0]; + PROPVALUE_CLONE = prefVals[1]; + IMAGE_DSNAME_SANWEI = prefVals[2]; + IMAGE_DSNAME_ERWEI = prefVals[3]; + INPUT_SUFFIX = prefVals[4]; + err = ""; + WriteLog(debug, "查询NX模板:%s", itemID.c_str()); + if (tc_strlen(itemID.c_str()) == 0) { + res.append(("NX模板ID不可为空")); + ifail = OUTPUT_CODE_ERROR; + goto gx_nx_image_end; + } + ITKCALL(ifail = ITEM_find_item(itemID.c_str(), &item_tag)); + if (ifail != ITK_ok) { + goto gx_nx_image_end; + } + ITKCALL(ifail = AOM_ask_value_string(item_tag, "object_string", &object_string)); + WriteLog(debug, "找到对象:%s", object_string); + DOFREE(object_string); + ITKCALL(ifail = ITEM_ask_latest_rev(item_tag, &rev_tag)); + if (rev_tag == NULLTAG) { + res.append(("未找到模板对象的最新版本,请检查是否具有查看权限")); + ifail = OUTPUT_CODE_ERROR; + goto gx_nx_image_end; + } + ITKCALL(ifail = AOM_refresh(rev_tag, FALSE)); + ITKCALL(ifail = AOM_ask_value_string(rev_tag, "object_string", &object_string)); + WriteLog(debug, "最新版本:%s", object_string); + DOFREE(object_string); + // 检查是否发布 + ITKCALL(ifail = EPM_ask_if_released(rev_tag, &release_flag)); + if (release_flag == 0) { + res.append(("模板对象最新版本未发布")); + ifail = OUTPUT_CODE_ERROR; + goto gx_nx_image_end; + } + // 读取简图 + ITKCALL(ifail = AOM_ask_value_tags(rev_tag, "IMAN_specification", &ds_count, &ds_tags)); + for (int i = 0;i < ds_count;i++) { + tag_t ds_tag = ds_tags[i]; + char* ds_type = NULL, * ds_name = NULL, * original_file_name = NULL; + ITKCALL(ifail = AOM_refresh(ds_tag, false)); + ITKCALL(ifail = AOM_ask_value_string(ds_tag, "object_name", &ds_name)); + ITKCALL(ifail = WSOM_ask_object_type2(ds_tag, &ds_type)); + WriteLog(debug, "Find Child: %s[%s]", ds_name, ds_type); + //res.append(ds_name).append("->").append(ds_type).append(";"); + if (strcmp("Bitmap", ds_type) == 0) { + if (strcmp((IMAGE_DSNAME_ERWEI.c_str()), ds_name) == 0) { + char* uid = NULL; + ITK__convert_tag_to_uid(ds_tag, &uid); + if (uid != NULL) { + erwei_file.assign(uid); + } + //res.append(erwei_file).append(";"); + } + else if (strcmp((IMAGE_DSNAME_SANWEI.c_str()), ds_name) == 0) { + char* uid = NULL; + ITK__convert_tag_to_uid(ds_tag, &uid); + if (uid != NULL) { + sanwei_file.assign(uid); + } + //DOFREE(sanwei_file); + //export_dataset_file(debug, ds_tag, "Image", "bmp", &sanwei_file, &original_file_name); + //res.append(sanwei_file).append(";"); + } + } + DOFREE(ds_type); + DOFREE(ds_name); + DOFREE(original_file_name); + } + if (erwei_file.length()==0 || sanwei_file.length()==0) { + res.append(("获取图纸简图失败")); + ifail = OUTPUT_CODE_ERROR; + goto gx_nx_image_end; + } + ITKCALL(ifail = AOM_ask_value_string(rev_tag, "item_revision_id", &rev_id)); + res.append("@DB/").append(itemID).append("/").append(rev_id); + res.append(SPLITTER).append((IMAGE_DSNAME_ERWEI)).append("=").append((erwei_file)); + res.append(SPLITTER).append((IMAGE_DSNAME_SANWEI)).append("=").append((sanwei_file)); + +gx_nx_image_end: + POM_AM__set_application_bypass(false); + DOFREE(ds_tags); + DOFREE(object_string); + DOFREE(rev_id); + return ifail; +} + +int Parse_NX_Template_By_ID(const std::string& itemID, std::string& res) { + int ifail = ITK_ok, release_flag = 0; + int pref_len = 0, ds_count = 0; + char* object_string = NULL; + char* rev_id = NULL; + tag_t item_tag = NULLTAG; + tag_t rev_tag = NULLTAG; + tag_t bom_view = NULLTAG, bvr_tag = NULLTAG, bom_window = NULLTAG, topBomLine = NULLTAG; + vector checkedIDs; + vector prefVals; + POM_AM__set_application_bypass(true); + getPrefStrings(PREF_NX_TEMPLATE, TC_preference_site, prefVals); + if (prefVals.size() != 5) { + res.append(("首选项配置错误:")).append(PREF_NX_TEMPLATE); + ifail = OUTPUT_CODE_ERROR; + goto gx_nx_template_end; + } + PROPNAME_CLONE = prefVals[0]; + PROPVALUE_CLONE = prefVals[1]; + IMAGE_DSNAME_SANWEI = prefVals[2]; + IMAGE_DSNAME_ERWEI = prefVals[3]; + INPUT_SUFFIX = prefVals[4]; + err = ""; + WriteLog(debug, "查询NX模板:%s", itemID.c_str()); + if (tc_strlen(itemID.c_str()) == 0) { + res.append(("NX模板ID不可为空")); + ifail = OUTPUT_CODE_ERROR; + goto gx_nx_template_end; + } + ITKCALL(ifail = ITEM_find_item(itemID.c_str(), &item_tag)); + if (ifail != ITK_ok) { + goto gx_nx_template_end; + } + ITKCALL(ifail = AOM_ask_value_string(item_tag, "object_string", &object_string)); + WriteLog(debug, "找到对象:%s", object_string); + DOFREE(object_string); + ITKCALL(ifail = ITEM_ask_latest_rev(item_tag, &rev_tag)); + if (rev_tag == NULLTAG) { + res.append(("未找到模板对象的最新版本,请检查是否具有查看权限")); + ifail = OUTPUT_CODE_ERROR; + goto gx_nx_template_end; + } + ITKCALL(ifail = AOM_refresh(rev_tag, FALSE)); + ITKCALL(ifail = AOM_ask_value_string(rev_tag, "object_string", &object_string)); + WriteLog(debug, "最新版本:%s", object_string); + DOFREE(object_string); + // 检查是否发布 + ITKCALL(ifail = EPM_ask_if_released(rev_tag, &release_flag)); + if (release_flag == 0) { + res.append(("模板对象最新版本未发布")); + ifail = OUTPUT_CODE_ERROR; + goto gx_nx_template_end; + } + ITKCALL(ifail = AOM_ask_value_string(rev_tag, "item_revision_id", &rev_id)); + res.append("@DB/").append(itemID).append("/").append(rev_id); + // 加载BOM + ITKCALL(ifail = GetBomView(rev_tag, "view", &bom_view, &bvr_tag, debug)); + if (bom_view != NULLTAG) { + BOM_create_window(&bom_window); + BOM_set_window_top_line_bvr(bom_window, bvr_tag, &topBomLine); + ifail = Cycle_BOM(topBomLine, res, checkedIDs, true); + BOM_close_window(bom_window); + } + else { + WriteLog(debug, "未找到BOM视图"); + } + +gx_nx_template_end: + POM_AM__set_application_bypass(false); + DOFREE(object_string); + DOFREE(rev_id); + return ifail; +} + + +int GET_CLONE_INFO(const std::string& uid, std::string& res) { + int ifail = ITK_ok; + tag_t item_tag = NULLTAG, rev_tag = NULLTAG; + char* item_id = NULL, * rev_id = NULL, * prop_value = NULL; + char* new_rev_id = NULL; + tag_t tType = NULLTAG; + logical isModified = FALSE; + string id_str, new_item_id; + vector prefVals; + if (uid.size() < 1) { + goto end; + } + getPrefStrings(PREF_NX_TEMPLATE, TC_preference_site, prefVals); + if (prefVals.size() != 5) { + res.append(("首选项配置错误:")).append(PREF_NX_TEMPLATE); + ifail = OUTPUT_CODE_ERROR; + goto end; + } + PROPNAME_CLONE = prefVals[0]; + PROPVALUE_CLONE = prefVals[1]; + IMAGE_DSNAME_SANWEI = prefVals[2]; + IMAGE_DSNAME_ERWEI = prefVals[3]; + INPUT_SUFFIX = prefVals[4]; + err = ""; + ITK__convert_uid_to_tag(uid.c_str(), &rev_tag); + if (rev_tag == NULLTAG) { + res.assign("无法加载版本,UID=").append(uid); + ifail = OUTPUT_CODE_ERROR; + goto end; + } + ITKCALL(ifail = ITEM_ask_item_of_rev(rev_tag, &item_tag)); + if (item_tag == NULLTAG) { + goto end; + } + ITKCALL(ifail = AOM_ask_value_string(item_tag, "item_id", &item_id)); + if (ifail != ITK_ok) { + goto end; + } + id_str.append(item_id); + ITKCALL(ifail = TCTYPE_ask_object_type(item_tag, &tType)); + ITKCALL(ifail = AOM_ask_value_string(rev_tag, "item_revision_id", &rev_id)); + ITKCALL(ifail = Get_New_ID(tType, id_str, INPUT_SUFFIX, new_item_id)); + if (ifail != ITK_ok) { + res.clear(); + res.append(err); + goto end; + } + ITKCALL(ifail = USER_new_revision_id(NULLTAG, tType, &isModified, &new_rev_id)); + res.append("@DB/").append(item_id).append("/").append(rev_id); + res.append("="); + res.append("@DB/").append(new_item_id).append("/").append(new_rev_id); +end: + prefVals.clear(); + DOFREE(rev_id); + return ifail; +} \ No newline at end of file diff --git a/qf_nx_itk-master (3)/qf_nx_itk/Connor_NX/connor_sign_dataset.cpp b/qf_nx_itk-master (3)/qf_nx_itk/Connor_NX/connor_sign_dataset.cpp new file mode 100644 index 0000000..df8543c --- /dev/null +++ b/qf_nx_itk-master (3)/qf_nx_itk/Connor_NX/connor_sign_dataset.cpp @@ -0,0 +1,292 @@ +#pragma warning (disable: 4996) +#include "Connor_NX.h" + +#define ITK_err 919013 +#define TYPE_REV "ItemRevision" +#define PREF_EXE "Connor_Sign_NX_EXE_Path" + +string exe_path; + +int signoff_NX(tag_t dataset, char *dat_file, char *ext) +{ + int ifail = ITK_ok; + WriteLog(debug, "开始签名到NX数据集"); + tag_t spec_dataset_rev = NULLTAG, ref_object = NULLTAG; + + AE_reference_type_t reference_type; + ITKCALL(ifail = AE_ask_dataset_latest_rev(dataset, &spec_dataset_rev)); + + char ref_name[WSO_name_size_c + 1] = "UGPART"; + ITKCALL(ifail = AE_ask_dataset_named_ref2(spec_dataset_rev, ref_name, &reference_type, &ref_object)); + if (reference_type == AE_PART_OF) + { + char *pathname = NULL; + ITKCALL(ifail = IMF_ask_file_pathname2(ref_object, SS_WNT_MACHINE, &pathname)); + char *origin_file_name = NULL; + IMF_ask_original_file_name2(ref_object, &origin_file_name); + char new_ds_name[WSO_name_size_c + 1] = ""; + char *new_file_name = USER_new_file_name(new_ds_name, ref_name, ext, 0); + char *temp_dir = getenv("temp"); + char temp_file[SS_MAXPATHLEN] = ""; + strcpy_s(temp_file, temp_dir); + strcat_s(temp_file, "\\"); + strcat_s(temp_file, new_file_name); + + ITKCALL(ifail = IMF_export_file(ref_object, temp_file)); + + int iCnt; + char *user_lib_env, pTempStr[500]; + char local_path[MAX_PATH] = ""; + char cmd[256] = ""; + strcpy_s(cmd, exe_path.c_str()); + strcat_s(cmd, " \""); + strcat_s(cmd, temp_file); + strcat_s(cmd, "\" \""); + strcat_s(cmd, dat_file); + strcat_s(cmd, "\""); + WriteLog(debug, "CMD:%s", cmd); + // runCMD(cmd, debug); + system(cmd); + WriteLog(debug, "执行完成,开始上传文件"); + tag_t new_file_tag = NULLTAG; + IMF_file_t file_descriptor; + WriteLog(debug, "上传文件..."); + ITKCALL(ifail = IMF_import_file(temp_file, new_file_name, SS_BINARY, &new_file_tag, &file_descriptor)); + ITKCALL(ifail = AOM_lock(new_file_tag)); + ITKCALL(ifail = IMF_set_original_file_name2(new_file_tag, origin_file_name)); + ITKCALL(ifail = IMF_close_file(file_descriptor)); + ITKCALL(ifail = AOM_save(new_file_tag)); + ITKCALL(ifail = AOM_unlock(new_file_tag)); + WriteLog(debug, "移除旧文件引用..."); + ITKCALL(ifail =AOM_lock(spec_dataset_rev)); + ITKCALL(ifail = AE_remove_dataset_named_ref_by_tag2(spec_dataset_rev, ref_name, ref_object)); + WriteLog(debug, "添加新文件引用..."); + ITKCALL(ifail = AE_add_dataset_named_ref2(spec_dataset_rev, ref_name, AE_PART_OF, new_file_tag)); + ITKCALL(ifail = AE_save_myself(spec_dataset_rev)); + ITKCALL(ifail = AOM_unlock(spec_dataset_rev)); + WriteLog(debug, "上传完成"); + + DOFREE(pathname); + DOFREE(origin_file_name); + } + + return ITK_ok; +} + +int sign(tag_t rev_tag, map sign_config_NX, char* user_id){ + int ifail = ITK_ok, rf_cnt = 0; + FILE* NXfile = NULL; + tag_t *rf_tags = NULL; + char NXinfo[2048]; + memset(NXinfo, 0, sizeof(NXinfo)); + char *NXfilepath = NULL; + //创建映射文件 + WriteLog(debug, "创建数据文件..."); + ifail = CreateUserFile(debug, "CONNOR_Sign_NX", user_id, &NXfilepath, &NXfile); + if (ifail == ITK_ok) { + WriteLog(debug, "数据文件:%s", NXfile); + } + else { + WriteLog(debug, "创建数据文件失败"); + EMH_store_error_s1(EMH_severity_error, ITK_err, ("创建数据文件失败")); + ifail = ITK_err; + goto sign_end; + } + + { + map::iterator it; + for(it = sign_config_NX.begin();it!=sign_config_NX.end();it++){ + string flag = it->first; + string propname = it->second; + string propvalstr; + vector split; + int index = 0; + Split(propname,";",split); + if(split.size()==2){ + propname.assign(split[0]); + index = atoi(split[1].c_str()); + } + char* propval = NULL; + ITKCALL(ifail = AOM_UIF_ask_value(rev_tag, propname.c_str(), &propval)); + if(ifail!=ITK_ok){ + WriteLog(debug,">> Error Reading Property [%s][%d]", propname.c_str(), ifail); + ITKCALL(EMH_clear_last_error(ifail)); + continue; + } + propvalstr.assign((propval)); + WriteLog(debug, ">> Reflect [%s]: [%s] = [%s]",flag.c_str(), propname.c_str(), propvalstr.c_str()); + if(index>=0){ + vector tempvec; + Split(propvalstr,";",tempvec); + if(tempvec.size()>index){ + propvalstr.assign(tempvec[index]); + }else{ + propvalstr.assign(""); + } + WriteLog(debug, ">> Split [%d]: %s", index, propvalstr.c_str()); + tempvec.clear(); + } + strcat_s(NXinfo, flag.c_str()); + strcat_s(NXinfo, "="); + strcat_s(NXinfo, propvalstr.c_str()); + strcat_s(NXinfo, "|"); + DOFREE(propval); + split.clear(); + } + } + WriteLog(debug, "NX 映射数据:\n%s", NXinfo); + ifail = WriteToFile(debug, NXfile, NXinfo); + if (ifail != ITK_ok) { + WriteLog(debug, "写入数据文件失败"); + EMH_store_error_s1(EMH_severity_error, ITK_err, ("写入数据文件失败")); + ifail = ITK_err; + goto sign_end; + } + //关闭数据文件 + if (NXfile) { + fclose(NXfile); + NXfile = NULL; + } + + ITKCALL(ifail = AOM_ask_value_tags(rev_tag, "IMAN_specification", &rf_cnt, &rf_tags)); + + for (int i = 0; i < rf_cnt; i++) + { + char *objectstring = NULL, *object_type = NULL; + tag_t ds = rf_tags[i]; + ITKCALL(ifail = AOM_ask_value_string(ds, "object_string", &objectstring)); + ITKCALL(ifail = AOM_ask_value_string(ds, "object_type", &object_type)); + WriteLog(debug, ">> %d. 子对象 [%s] 类型 [%s]", i+1, objectstring, object_type); + if (strcmp(object_type, "UGMASTER") == 0) + { + signoff_NX(ds, NXfilepath, "prt"); + } + DOFREE(objectstring); + DOFREE(object_type); + } + +sign_end: + DOFREE(rf_tags); + //关闭数据文件 + if (NXfile) { + fclose(NXfile); + NXfile = NULL; + } + //deleteFile(debug, NXfilepath); + return ifail; +} + +int CONNOR_SIGN_DATASET(EPM_action_message_t msg) +{ + int ifail = ITK_ok, att_cnt = 0, arg_cnt=0; + char* arg = NULL, * argflag = NULL, * argvalue = NULL; + map sign_config_NX; + vector sign_config; + vector pref_values; + tag_t current_task = NULLTAG, root_task = NULLTAG, *attachments = NULL, rev_type = NULLTAG; + char *user_name = NULL; + tag_t user_tag = NULLTAG; + char *user_id = NULL; + string sign_name_str; + arg_cnt = TC_number_of_arguments(msg.arguments); + if (arg_cnt > 0) { + for (int i = 0; i < arg_cnt; i++) { + arg = TC_next_argument(msg.arguments); + ITKCALL(ifail = ITK_ask_argument_named_value(arg, &argflag, &argvalue)); + if (strcmp(argflag, "SignName") == 0) { + sign_name_str.assign(argvalue); + } + MEM_free(argflag); + MEM_free(argvalue); + } + } + + current_task = msg.task; + EPM_ask_root_task(msg.task, &root_task); + //生成日志 + ITKCALL(POM_get_user(&user_name, &user_tag)); + ITKCALL(SA_ask_user_identifier2(user_tag, &user_id)); + WriteLog(debug, "========================================================="); + WriteLog(debug, "签名 开始执行"); + WriteLog(debug, "========================================================="); + initUserDir(user_id); + ITKCALL(ifail = TCTYPE_ask_type(TYPE_REV,&rev_type)); + if(rev_type==NULLTAG){ + EMH_store_error_s2(EMH_severity_error, ITK_err, ("未找到版本类型"),TYPE_REV); + goto end; + } + getPrefStrings(PREF_EXE, TC_preference_site, pref_values); + if (pref_values.size() == 0) { + EMH_store_error_s2(EMH_severity_error, ITK_err, ("未配置首选项"), PREF_EXE); + goto end; + } + exe_path = pref_values[0]; + ITKCALL(ifail = EPM_ask_attachments(root_task, EPM_target_attachment, &att_cnt, &attachments)); + if(att_cnt==0){ + goto end; + } + POM_AM__set_application_bypass(true); + //获取首选项配置 + Split(sign_name_str, ";", sign_config); + WriteLog(debug,"解析 NX 签名配置..."); + for each (string conf in sign_config) + { + conf.assign((conf.c_str())); + WriteLog(debug,">> %s",conf.c_str()); + vector strs; + Split(conf,"=",strs); + if(strs.size()==2){ + if(sign_config_NX.count(strs[1])==0){ + sign_config_NX.insert(make_pair(strs[1], strs[0])); + WriteLog(debug, ">> [%s] = [%s]", strs[0].c_str(), strs[1].c_str()); + }else{ + WriteLog(debug, ">> 重复配置 [%s] = [%s]", strs[0].c_str(), strs[1].c_str()); + } + }else{ + EMH_store_error_s2(EMH_severity_error, ITK_err, ("无效签名配置"),conf.c_str()); + } + strs.clear(); + } + if(sign_config_NX.size()==0){ + WriteLog(debug,"获取 NX 签名配置失败"); + EMH_store_error_s1(EMH_severity_error, ITK_err, ("获取 NX 签名配置失败")); + goto end; + } + sign_config.clear(); + + for(int i=0;i> 非版本类型"); + DOFREE(objectstring); + continue; + } + sign(attachment, sign_config_NX, user_id); + } + + + +end: + POM_AM__set_application_bypass(false); + DOFREE(attachments); + DOFREE(user_id); + sign_config.clear(); + pref_values.clear(); + sign_config_NX.clear(); + WriteLog(debug, "========================================================="); + WriteLog(debug, "签名 执行结束"); + WriteLog(debug, "========================================================="); + return ifail; +} + diff --git a/qf_nx_itk-master (3)/qf_nx_itk/Connor_NX/connor_sign_master.cpp b/qf_nx_itk-master (3)/qf_nx_itk/Connor_NX/connor_sign_master.cpp new file mode 100644 index 0000000..4c074ef --- /dev/null +++ b/qf_nx_itk-master (3)/qf_nx_itk/Connor_NX/connor_sign_master.cpp @@ -0,0 +1,293 @@ +#include "Connor_NX.h" + +#define ITK_err 919012 + +#define SIGN_DATE_FORMAT "%Y-%m-%d" +#define TYPE_REV "ItemRevision" + +struct Sign_Info{ + string node_name; + string propname_user; + string propname_date; +}; + + +int CONNOR_SIGN_MASTER(EPM_action_message_t msg){ + int ifail = ITK_ok, arg_cnt = 0,att_cnt=0, task_count=0; + char *arg = NULL,*argflag =NULL,*argvalue=NULL,*propvalue=NULL,*objectstring=NULL,*task_name=NULL,*task_type=NULL; + char *user_id = NULL, *user_name = NULL, *logPath = NULL; + tag_t task_tag = NULLTAG,rootTask_tag=NULLTAG, user_tag=NULLTAG; + tag_t *attachments = NULL, *task_tags=NULL; + string attr_sign_name, attr_sign_date; + vector attr_sign_name_split, attr_sign_date_split; + map sign_config_map; + map property_map; + string dateFormat, prop_name_bianzhi; + tag_t rev_type = NULLTAG; + dateFormat.assign(SIGN_DATE_FORMAT); + arg_cnt = TC_number_of_arguments(msg.arguments); + if (arg_cnt > 0) { + for (int i = 0;i < arg_cnt;i++) { + arg = TC_next_argument(msg.arguments); + ITKCALL(ifail = ITK_ask_argument_named_value(arg, &argflag, &argvalue)); + if(strcmp(argflag, "SignUserName") == 0){ + attr_sign_name.assign(argvalue); + }else if(strcmp(argflag, "SignDate") == 0){ + attr_sign_date.assign(argvalue); + }else if(strcmp(argflag, "SignDateFormat") == 0){ + dateFormat.assign(argvalue); + } + MEM_free(argflag); + MEM_free(argvalue); + } + } + ITKCALL(POM_get_user(&user_name, &user_tag)); + ITKCALL(SA_ask_user_identifier2(user_tag, &user_id)); + DOFREE(user_id); + WriteLog(debug, "============================================================="); + WriteLog(debug, "开始执行:CONNOR_SIGN_MASTER"); + WriteLog(debug, "============================================================="); + task_tag=msg.task; + if(task_tag==NULLTAG){ + goto end; + } + ITKCALL(ifail = TCTYPE_ask_type(TYPE_REV, &rev_type)); + if (rev_type == NULLTAG) { + EMH_store_error_s2(EMH_severity_error, ITK_err, ("未找到版本类型"), TYPE_REV); + goto end; + } + WriteLog(debug, "sign_user_name: %s", attr_sign_name.c_str()); + WriteLog(debug, "sign_date: %s", attr_sign_date.c_str()); + WriteLog(debug, "date_format: %s", dateFormat.c_str()); + ITKCALL(ifail = EPM_ask_root_task(task_tag, &rootTask_tag)); + ITKCALL(ifail = EPM_ask_attachments(rootTask_tag, EPM_target_attachment, &att_cnt, &attachments)); + if(att_cnt==0){ + goto end; + } + POM_AM__set_application_bypass(true); + //获取首选项配置 + WriteLog(debug,"解析签名配置..."); + Split(attr_sign_name, ";", attr_sign_name_split); + Split(attr_sign_date, ";", attr_sign_date_split); + for each (string conf in attr_sign_name_split) + { + WriteLog(debug,">> %s",conf.c_str()); + vector strs; + Split(conf,"=",strs); + if(strs.size()==2){ + if (sign_config_map.count(strs[0]) == 0) { + Sign_Info* info = new Sign_Info(); + info->node_name = strs[0]; + info->propname_user = strs[1]; + sign_config_map.insert(make_pair(info->node_name, info)); + if (info->node_name._Equal("编制")) { + prop_name_bianzhi.assign(info->propname_user); + } + } + }else{ + EMH_store_error_s2(EMH_severity_error, ITK_err, ("无效签名配置"),conf.c_str()); + } + strs.clear(); + } + for each (string conf in attr_sign_date_split) + { + WriteLog(debug, ">> %s", conf.c_str()); + vector strs; + Split(conf, "=", strs); + if (strs.size() == 2) { + if (sign_config_map.count(strs[0]) == 0) { + Sign_Info* info = new Sign_Info(); + info->node_name = strs[0]; + info->propname_date = strs[1]; + sign_config_map.insert(make_pair(info->node_name, info)); + } + else { + sign_config_map[strs[0]]->propname_date = strs[1]; + } + } + else { + EMH_store_error_s2(EMH_severity_error, ITK_err, ("无效签名配置"), conf.c_str()); + } + strs.clear(); + } + if(sign_config_map.size()==0){ + WriteLog(debug,"获取签名配置失败"); + EMH_store_error_s1(EMH_severity_error, ITK_err, ("获取签名配置失败")); + goto end; + } + WriteLog(debug, "编制属性 [%s]", prop_name_bianzhi.c_str()); + WriteLog(debug,"读取签名信息..."); + ITKCALL(ifail=EPM_ask_sub_tasks(rootTask_tag,&task_count,&task_tags)); + for(int i=0;i %s",i+1, task_name,task_type); + if (sign_config_map.count(task_name) == 0) { + WriteLog(debug, ">> SKIP"); + DOFREE(task_name); + DOFREE(task_type); + continue; + } + if(strcmp("EPMDoTask", task_type)==0){ + tag_t user_tag = NULLTAG; + ITKCALL(ifail = AOM_ask_value_tag(sub_task,"fnd0Performer",&user_tag)); + if(user_tag==NULLTAG){ + WriteLog(debug, "未找到执行者"); + continue; + } + char *date_str = NULL, *user_name = NULL, *task_state=NULL; + date_t date; + ITKCALL(ifail = AOM_ask_value_string(user_tag,"user_name",&user_name)); + ITKCALL(ifail = AOM_ask_value_date(sub_task, "fnd0EndDate", &date)); + ITKCALL(ifail = AOM_ask_value_string(sub_task,"task_state", &task_state)); + ITKCALL(ifail = DATE_date_to_string(date,dateFormat.c_str(),&date_str)); + WriteLog(debug, ">> DO任务信息:%s|%s|%s",user_name, date_str, task_state); + if(date.year<=0){ + WriteLog(debug, "任务未完成"); + continue; + } + Sign_Info* info = sign_config_map[task_name]; + + if(info->propname_user.length()>0){ + WriteLog(debug, ">>>> 记录用户信息 %s = %s", info->propname_user.c_str(), user_name); + if (property_map.count(info->propname_user) == 0) { + property_map.insert(make_pair(info->propname_user, user_name)); + } + else { + WriteLog(debug, "重复属性"); + } + } + if(info->propname_date.length() > 0){ + WriteLog(debug, ">>>> 记录时间信息 %s = %s", info->propname_date.c_str(), date_str); + if (property_map.count(info->propname_date) == 0) { + property_map.insert(make_pair(info->propname_date, date_str)); + } + else { + WriteLog(debug, "重复属性"); + } + } + + DOFREE(user_name); + DOFREE(date_str); + DOFREE(task_state); + }else if(strcmp("EPMReviewTask",task_type)==0||strcmp("EPMAcknowledgeTask",task_type)==0){ + int reviewer_cnt=0; + tag_t *reviewers=NULL; + ITKCALL(ifail = EPM_ask_reviewers(sub_task,&reviewer_cnt,&reviewers)); + for(int j=0;j> %d. 审核信息:%s|%s|%s",j+1,user_name,group_full_name, date_str); + if(decision != EPM_approve_decision){ + WriteLog(debug, "审核未同意"); + DOFREE(comment); + DOFREE(user_name); + DOFREE(group_full_name); + DOFREE(date_str); + continue; + } + Sign_Info* info = sign_config_map[task_name]; + if (info->propname_user.length() > 0) { + WriteLog(debug, ">>>> 记录用户信息 %s = %s", info->propname_user.c_str(), user_name); + if (property_map.count(info->propname_user) == 0) { + property_map.insert(make_pair(info->propname_user, user_name)); + } + else { + WriteLog(debug, "重复属性"); + } + } + if (info->propname_date.length() > 0) { + WriteLog(debug, ">>>> 记录时间信息 %s = %s", info->propname_date.c_str(), date_str); + if (property_map.count(info->propname_date) == 0) { + property_map.insert(make_pair(info->propname_date, date_str)); + } + else { + WriteLog(debug, "重复属性"); + } + } + + DOFREE(comment); + DOFREE(user_name); + DOFREE(group_full_name); + DOFREE(date_str); + } + DOFREE(reviewers); + }else{ + WriteLog(debug, ">> 未知任务类型"); + } + DOFREE(task_name); + DOFREE(task_type); + } + + //获取最高文件密级 + for(int i=0;i> 非版本类型"); + DOFREE(objectstring); + continue; + } + ITKCALL(ifail = AOM_lock(attachment)); + if(ifail!=ITK_ok){ + continue; + } + ITKCALL(ifail = AOM_ask_value_tag(attachment, "owning_user", &rev_owner)); + ITKCALL(ifail = AOM_ask_value_string(rev_owner, "user_name", &rev_owner_name)); + WriteLog(debug, ">> 所有者 %s", rev_owner_name); + map::iterator it; + for(it = property_map.begin();it!=property_map.end();it++){ + string propname = it->first; + string propval = it->second; + if (prop_name_bianzhi._Equal(propname)) { + propval.assign(rev_owner_name); + } + WriteLog(debug, ">> 设置属性: [%s] = [%s]", propname.c_str(), propval.c_str()); + ITKCALL(ifail = AOM_set_value_string(attachment, propname.c_str(), propval.c_str())); + if(ifail!=ITK_ok){ + WriteLog(debug, ">> 设置属性失败:%d", ifail); + EMH_clear_last_error(ifail); + } + } + ITKCALL(AOM_save(attachment)); + AOM_unlock(attachment); + } +end: + POM_AM__set_application_bypass(false); + DOFREE(attachments); + sign_config_map.clear(); + property_map.clear(); + attr_sign_name_split.clear(); + attr_sign_date_split.clear(); + WriteLog(debug, "============================================================="); + WriteLog(debug, "执行结束:CONNOR_SIGN_MASTER"); + WriteLog(debug, "============================================================="); + return ITK_ok; +} + diff --git a/qf_nx_itk-master (3)/qf_nx_itk/Connor_NX/kutil - 鍓湰 (2).cpp b/qf_nx_itk-master (3)/qf_nx_itk/Connor_NX/kutil - 鍓湰 (2).cpp new file mode 100644 index 0000000..ad42e31 --- /dev/null +++ b/qf_nx_itk-master (3)/qf_nx_itk/Connor_NX/kutil - 鍓湰 (2).cpp @@ -0,0 +1,693 @@ +锘#pragma warning (disable: 4996) +#pragma warning (disable: 4819) + +#include "kutil.h" + +FILE* logFile = NULL; + +#define MAX_PATH_LENGTH 200 +#define MAX_PRINTLINE_LENGTH 2000 + +void initUserDir(char* userId) { + char logFileDir[MAX_PATH_LENGTH]; + memset(logFileDir, 0, sizeof(logFileDir)); + sprintf(logFileDir, "%s", getenv("TEMP")); + strcat(logFileDir, "\\tc_"); + strcat(logFileDir, userId); + if (chdir(logFileDir) != ITK_ok) { + printf(">> Create Path: %s\n", logFileDir); + mkdir(logFileDir); + } +} + +void WriteLog(logical debug, const char* format, ...) +{ + va_list arg; + char tmp[MAX_PRINTLINE_LENGTH]; + char date_string[MAX_PATH_LENGTH]; + time_t now; + struct tm* p; + + //get the message + memset(tmp, 0, sizeof(tmp)); + va_start(arg, format); + vsprintf(tmp, format, arg); + va_end(arg); + //----------print to command window for trace--------// + //printf("%s\n", tmp); + printf("%s\n", tmp); + //print message to log file + TC_write_syslog("%s\n", tmp); +} + +void WriteLog2(logical debug, const char* format, ...) +{ + va_list arg; + char tmp[MAX_PRINTLINE_LENGTH]; + char date_string[MAX_PATH_LENGTH]; + time_t now; + struct tm* p; + + //get the message + memset(tmp, 0, sizeof(tmp)); + va_start(arg, format); + vsprintf(tmp, format, arg); + va_end(arg); + //----------print to command window for trace--------// + //printf("%s\n", tmp); + printf("%s\n", tmp); + //print message to log file + if (!debug) { + return; + } + if (logFile) + { + time(&now); + //current_time(&status_now); + p = localtime(&now); + memset(date_string, 0, sizeof(date_string)); + sprintf(date_string, "%02d:%02d:%02d", p->tm_hour, p->tm_min, p->tm_sec); + fprintf(logFile, "[%s] %s\n", date_string, tmp); + fflush(logFile); + } + else + { + printf("*!Error!*: Log File Not Exist\n"); + } +} + +void CloseLog(void) +{ + if (logFile) + { + fclose(logFile); + logFile = NULL; + } +} + +void CreateLogFile(char* FunctionName, char* userId, char** fullname) +{ + int ifail = ITK_ok; + //date_t status_now; + //char* date_string = NULL; + char date_string[MAX_PATH_LENGTH]; + char logFileDir[MAX_PATH_LENGTH]; + char logFileName[MAX_PATH_LENGTH]; + //char* session_uid = NULL; + //tag_t session_tag = NULLTAG; + + time_t now; + struct tm* p; + + time(&now); + + logFile = NULL; + //current_time(&status_now); + p = localtime(&now); + + memset(date_string, 0, sizeof(date_string)); + //sprintf(date_string,"%4d%02d%02d%02d%02d%02d",1900+p->tm_year,p->tm_mon+1 ,p->tm_mday ,p->tm_hour,p->tm_min ,p->tm_sec ); + sprintf(date_string, "%4d%02d%02d", 1900 + p->tm_year, p->tm_mon + 1, p->tm_mday); + //if( DATE_date_to_string( status_now, "%Y%m%d%H%M%S", &date_string) != ITK_ok ) + //ifail = ITK_date_to_string (status_now, &date_string ); + //if (ifail) + //{ + // printf("!*ERROR*!: Failed to get current date time\n"); + // goto CLEANUP; + //} + + memset(logFileDir, 0, sizeof(logFileDir)); + memset(logFileName, 0, sizeof(logFileName)); + //get log dir + sprintf(logFileDir, "%s", getenv("TEMP")); + strcat(logFileDir, "\\tc_"); + strcat(logFileDir, userId); + //printf("\n log file dir: %s\n", logFileDir); + //try to change dir to TC_USER_LOG_DIR + if (chdir(logFileDir) != ITK_ok) + { + //not set TC_USER_LOG_DIR + //log in to default TC_LOG + memset(logFileDir, 0, sizeof(logFileDir)); + sprintf(logFileDir, "%s", getenv("TC_LOG")); + printf("\n TC_USER_LOG_DIR invalide, log file dir: %s\n", logFileDir); + if (chdir(logFileDir) != ITK_ok) + { + //still can not change to log dir + printf("!*ERROR*!: Failed to change dir to TC_USER_LOG_DIR\n"); + goto CLEANUP; + } + } + + //get session_uid to make sure the log file name unique + //POM_ask_session(&session_tag); + //ITK__convert_tag_to_uid(session_tag, &session_uid); + //get logFileName + sprintf(logFileName, "%s_%s_%s.log", FunctionName, userId, date_string); + //printf("log file name: %s\n", logFileName); + + *fullname = (char*)MEM_alloc(sizeof(char) * 512); + sprintf(*fullname, "%s\\%s", logFileDir, logFileName); + + //for(i = 0; _access((char *)logFileName, 4) == 0; i++) + /*{ + memset(logFileName, 0, sizeof(logFileName)); + sprintf(logFileName, "%s_%s_%s_%d.log", FunctionName, session_uid, date_string, i); + } + printf("final log file name: %s\n", logFileName);*/ + + //create log file + logFile = fopen(logFileName, "a"); + +CLEANUP:; + //DOFREE(date_string); + /*if(session_uid!=NULL){ + MEM_free(session_uid); + session_uid=NULL; + }*/ +} + + + +void set_bypass(logical bypass) +{ + //AM__set_application_bypass(bypass); + POM_AM__set_application_bypass(bypass); +} + +bool isClass(tag_t class_id, char* className) { + tag_t* pclass_ids = NULL; + char* class_name = NULL; + int pclass_count = 0, ifail = ITK_ok; + ITKCALL(POM_name_of_class(class_id, &class_name)); + printf("class name = %s\n", class_name); + bool isType = false; + if (strcmp(class_name, className) == 0) { + isType = true; + } + DOFREE(class_name); + if (isType) { + return true; + } + ITKCALL(ifail = POM_superclasses_of_class(class_id, &pclass_count, &pclass_ids)); + for (int i = 0;i < pclass_count;i++) { + isType = isClass(pclass_ids[i], className); + if (isType) { + return true; + } + } + return false; +} + +bool isType(tag_t item, char* type) { + tag_t class_id = NULLTAG, * pclass_ids = NULL; + char* class_name = NULL; + int pclass_count = 0, ifail = ITK_ok; + + ITKCALL(POM_class_of_instance(item, &class_id)); + return isClass(class_id, type); +} + +void deleteFile(bool debug, char* path) { + //脡戮鲁媒脦脛录镁 + if (remove(path) == 0) { + WriteLog(debug, "Delete File: %s", path); + } + else { + WriteLog(debug, "Delete File failed: %s", path); + } +} + + +int readError(bool debug, char* errFilePath, int errCode) { + fstream _file; + _file.open(errFilePath, ios::in); + if (_file) { + WriteLog(debug, "Find Error File: %s", errFilePath); + ifstream fin(errFilePath); + string s; + while (getline(fin, s)) + { + WriteLog(debug, s.c_str()); + EMH_store_error_s1(EMH_severity_error, errCode, s.c_str()); + } + _file.close(); + return errCode; + } + return ITK_ok; +} + +//碌录脠毛脢媒戮脻录炉 +int import_dataset_file(tag_t dataset, const char* ref_name, char* ext, char* fullfilename, char* original_name) +{ + int ifail = ITK_ok; + tag_t new_file_tag = NULLTAG; + IMF_file_t file_descriptor = NULL; + AOM_refresh(dataset, FALSE); + char* new_file_name = NULL; + char new_ds_name[WSO_name_size_c + 1] = ""; + char* filename = NULL; + new_file_name = USER_new_file_name(new_ds_name, ref_name, ext, 0); + filename = strrchr(fullfilename, '\\') + 1; + if (filename == NULL) + return ITK_ok; + set_bypass(true); + ITKCALL(ifail = IMF_import_file(fullfilename, new_file_name, SS_TEXT, &new_file_tag, &file_descriptor)); + if (ifail != ITK_ok) { + ITKCALL(ifail = IMF_import_file(fullfilename, new_file_name, SS_BINARY, &new_file_tag, &file_descriptor)); + } + ITKCALL(ifail = IMF_set_original_file_name2(new_file_tag, original_name)); + + ITKCALL(ifail = IMF_close_file(file_descriptor)); + ITKCALL(ifail = AOM_save(new_file_tag)); + AOM_unlock(new_file_tag); + ITKCALL(ifail = AOM_refresh(new_file_tag, FALSE)); + //脤铆录脫脰脕脙眉脙没脪媒脫脙 + set_bypass(true); + ITKCALL(AOM_lock(dataset)); + ITKCALL(ifail = AE_remove_dataset_named_ref2(dataset, ref_name)); + ITKCALL(ifail = AOM_save(dataset)); + set_bypass(true); + ITKCALL(ifail = AE_add_dataset_named_ref2(dataset, ref_name, AE_PART_OF, new_file_tag)); + AOM_save(dataset); + AOM_unlock(dataset); + set_bypass(false); + //ITKCALL( AOM_refresh( dataset, FALSE ) ); + return ifail; +} + +//碌录脠毛脢媒戮脻录炉 +int import_dataset_file_binary(tag_t dataset, const char* ref_name, char* ext, char* fullfilename, char* original_name) +{ + int ifail = ITK_ok; + tag_t new_file_tag = NULLTAG; + IMF_file_t file_descriptor = NULL; + AOM_refresh(dataset, FALSE); + char* new_file_name = NULL; + char new_ds_name[WSO_name_size_c + 1] = ""; + char* filename = NULL; + new_file_name = USER_new_file_name(new_ds_name, ref_name, ext, 0); + filename = strrchr(fullfilename, '\\') + 1; + if (filename == NULL) + return ITK_ok; + set_bypass(true); + ITKCALL(ifail = IMF_import_file(fullfilename, new_file_name, SS_BINARY, &new_file_tag, &file_descriptor)); + ITKCALL(ifail = IMF_set_original_file_name2(new_file_tag, original_name)); + + ITKCALL(ifail = IMF_close_file(file_descriptor)); + ITKCALL(ifail = AOM_save(new_file_tag)); + AOM_unlock(new_file_tag); + ITKCALL(ifail = AOM_refresh(new_file_tag, FALSE)); + //脤铆录脫脰脕脙眉脙没脪媒脫脙 + set_bypass(true); + ITKCALL(AOM_lock(dataset)); + ITKCALL(ifail = AE_remove_dataset_named_ref2(dataset, ref_name)); + ITKCALL(ifail = AOM_save(dataset)); + set_bypass(true); + ITKCALL(ifail = AE_add_dataset_named_ref2(dataset, ref_name, AE_PART_OF, new_file_tag)); + AOM_save(dataset); + AOM_unlock(dataset); + set_bypass(false); + //ITKCALL( AOM_refresh( dataset, FALSE ) ); + return ifail; +} + + +void Split(string strArg, char spliter, vector& ans) +{ + ans.clear(); + size_t index0 = 0; + string one_arg; + if (strArg.find_first_not_of(' ') == string::npos) + strArg = ""; + while (strArg.size() > 0) + { + index0 = strArg.find_first_of(spliter); + if (index0 != string::npos) + { + one_arg = strArg.substr(0, index0); + strArg = strArg.substr(index0 + 1); + ans.push_back(one_arg); + } + else + { + ans.push_back(strArg); + break; + } + } +} + +void Split(string strArg, string spliter, vector& ans) +{ + ans.clear(); + size_t index0 = 0; + string one_arg; + if (strArg.find_first_not_of(' ') == string::npos) + strArg = ""; + while (strArg.size() > 0) + { + index0 = strArg.find_first_of(spliter); + if (index0 != string::npos) + { + one_arg = strArg.substr(0, index0); + strArg = strArg.substr(index0 + 1); + ans.push_back(one_arg); + } + else + { + ans.push_back(strArg); + break; + } + } +} + +bool inArray(vector types, string type) { + int len = types.size(); + for (int i = 0;i < len;i++) { + if (strcmp(types[i].c_str(), type.c_str()) == 0) { + return true; + } + } + return false; +} + +int getIndexInArray(vector types, string type) { + int len = types.size(); + for (int i = 0;i < len;i++) { + if (strcmp(types[i].c_str(), type.c_str()) == 0) { + return i; + } + } + return -1; +} + +bool CheckType(string config, char* type, char spliter) { + vector types; + Split(config, spliter, types); + int len = types.size(); + for (int i = 0;i < len;i++) { + if (strcmp(types[i].c_str(), type) == 0) { + return true; + } + } + return false; +} + +int GetProcessTargets(bool debug, int att_cnt, tag_t* attachments, vector& targets, char* formType, char splitter) { + char* object_name = NULL, * object_type = NULL; + int ifail = ITK_ok; + WriteLog(debug, "Get Targets of Process: %d", att_cnt); + for (int i = 0;i < att_cnt;i++) { + ITKCALL(ifail = WSOM_ask_name2(attachments[i], &object_name)); + ITKCALL(ifail = WSOM_ask_object_type2(attachments[i], &object_type)); + WriteLog(debug, "%d. Target [%s], type: %s", i + 1, object_name, object_type); + //if (strcmp(object_type, TYPE_ITEM_PZJ.c_str()) == 0) { + if (CheckType(formType, object_type, splitter)) { + targets.push_back(attachments[i]); + } + DOFREE(object_name); + DOFREE(object_type); + } + return ITK_ok; +} + +int findUser(bool debug, string userStr, tag_t* user_tag) { + int ind1 = userStr.find_first_of('('); + int ind2 = userStr.find_first_of(')'); + WriteLog(debug, "Search User: %s", userStr.c_str()); + if (ind1 != string::npos && ind2 != string::npos && ind1 < ind2) { + userStr = userStr.substr(ind1 + 1, ind2 - ind1 - 1); + WriteLog(debug, ">> User id: %s", userStr.c_str()); + } + int ifail = ITK_ok; + ITKCALL(ifail = SA_find_user2(userStr.c_str(), user_tag)); + return ifail; +} + +int GetBomLinePropString(bool debug, tag_t line, char* propName, int errCode, char** attr_val) { + int attribute_id = 0, ifail = ITK_ok; + ITKCALL(ifail = BOM_line_look_up_attribute(propName, &attribute_id)); + if (attribute_id == 0) { + WriteLog(debug, "BOMLine property not exist: %s", propName); + EMH_store_error_s2(EMH_severity_error, errCode, "BOMLine property not exist", propName); + return errCode; + } + else { + ITKCALL(ifail = BOM_line_ask_attribute_string(line, attribute_id, &*attr_val)); + return ifail; + } + return ITK_ok; +} + +int GetStringProp(tag_t obj, char* propName, char** attr_val) { + return AOM_ask_value_string(obj, propName, &*attr_val); +} + +bool isRev(char* object_type) { + if (((strstr(object_type, "Revision") != NULL) || (strstr(object_type, "revision") != NULL)) + && (strstr(object_type, "Master") == NULL) && (strstr(object_type, "master") == NULL) + && (strstr(object_type, "BOM") == NULL) && (strstr(object_type, "bom") == NULL) && (strstr(object_type, "Bom") == NULL)) { + return true; + } + return false; +} + +int GetBomView(tag_t rev_tag, char* viewtype, tag_t* bomView, tag_t* bomBVR, bool debug) +{ + WriteLog(debug, "Get BOM View: %s", viewtype); + int ifail = ITK_ok, bvr_count = 0; + tag_t* bvr_list = NULL, bom_view = NULLTAG, view_type = NULLTAG; + *bomBVR = NULLTAG; + *bomView = NULLTAG; + ITKCALL(ITEM_rev_list_bom_view_revs(rev_tag, &bvr_count, &bvr_list)); + if (bvr_count > 0) + { + for (int i = 0; i < bvr_count; i++) + { + ITKCALL(PS_ask_bom_view_of_bvr(bvr_list[i], &bom_view)); + + ITKCALL(PS_ask_bom_view_type(bom_view, &view_type)); + //ITKCALL( PS_find_view_type(bom_view, &view_type)); + char* view_type_name = NULL; + ITKCALL(PS_ask_view_type_name(view_type, &view_type_name)); + WriteLog(debug, "Find View: %s", view_type_name); + if (tc_strcmp(view_type_name, viewtype) == 0) + { + *bomBVR = bvr_list[i]; + *bomView = bom_view; + } + DOFREE(view_type_name); + } + } + //else { + // WriteLog(debug, "脙禄脫脨脮脪碌陆bvr驴陋脢录陆酶脨脨麓麓陆篓"); + // tag_t bv = NULLTAG, bvr = NULLTAG, item_tag = NULLTAG; + // int bvCnt = 0; + // tag_t* bvTags = NULL; + + + // ITKCALL(ifail = ITEM_ask_item_of_rev(rev_tag, &item_tag)); + + + // tag_t tWindow = NULLTAG; + // ITKCALL(BOM_create_window(&tWindow)); + + // tag_t tTopLine = NULLTAG; + // ITKCALL(BOM_set_window_top_line(tWindow, item_tag, NULLTAG, NULLTAG, &tTopLine)); + + // //虏茅脮脪脭颅BOM脢脫脥录 + // ITKCALL(ifail=ITEM_list_bom_views(item_tag, &bvCnt, &bvTags)); + // if (bvCnt > 0) { + // WriteLog(debug, "露脭脧贸脪脩麓忙脭脷BOM脢脫脥录拢潞%d", bvCnt); + // bv = bvTags[0]; + // } + // ITKCALL(AOM_lock(item_tag)); + // if (bv == NULLTAG) { + // ITKCALL(ifail=PS_create_bom_view(NULLTAG, "", "", item_tag, &bv)); + // if (ifail != ITK_ok) { + // ITKCALL(AOM_unlock(item_tag)); + // return ifail; + // } + // ITKCALL(AOM_save(bv)); + // } + // ITKCALL(ifail=PS_create_bvr(bv, "", "", false, rev_tag, &bvr)); + // if (ifail != ITK_ok) { + // ITKCALL(AOM_unlock(item_tag)); + // return ifail; + // } + // ITKCALL(AOM_save(bvr)); + // ITKCALL(AOM_save(bv)); + // ITKCALL(AOM_save(item_tag)); + + // tag_t tChildLine = NULLTAG; + + // ITKCALL(BOM_save_window(tWindow)); + // ITKCALL(BOM_close_window(tWindow)); + + // ITKCALL(AOM_unlock(item_tag)); + // *bomBVR = bvr; + // *bomView = bv; + // WriteLog(debug, "bvr脨脗陆篓脥锚鲁脡"); + // DOFREE(bvTags); + + //} + DOFREE(bvr_list); + return ifail; +} + +bool propExist(bool debug, tag_t obj, const char* propName) { + tag_t clTag = NULLTAG, * superClass = NULL; + char* clName = NULL; + int ifail = ITK_ok, cnt = 0; + logical exists = false; + ITKCALL(ifail = POM_class_of_instance(obj, &clTag)); + if (ifail != ITK_ok) { return false; } + ITKCALL(ifail = POM_name_of_class(clTag, &clName)); + if (ifail != ITK_ok) { return false; } + WriteLog(debug, ">> [%s] Check Property: %s", clName, propName); + ITKCALL(ifail = POM_attr_exists(propName, clName, &exists)); + if (ifail != ITK_ok) { return false; } + DOFREE(clName); + if (exists) { + //WriteLog(debug,"脢么脨脭麓忙脭脷"); + return exists; + } + ITKCALL(ifail = POM_superclasses_of_class(clTag, &cnt, &superClass)); + for (int i = 0;i < cnt;i++) { + ITKCALL(ifail = POM_name_of_class(superClass[i], &clName)); + if (ifail != ITK_ok) { return false; } + WriteLog(debug, ">> [%s] Check Property: %s", clName, propName); + ITKCALL(ifail = POM_attr_exists(propName, clName, &exists)); + DOFREE(clName); + if (exists) { + //WriteLog(debug, "脢么脨脭麓忙脭脷"); + return exists; + } + } + WriteLog(debug, "Property not exist"); + return exists; +} + + +char* G2U(const char* gb2312) +{ + int len = MultiByteToWideChar(CP_ACP, 0, gb2312, -1, NULL, 0); + wchar_t* wstr = new wchar_t[len + 1]; + memset(wstr, 0, len + 1); + MultiByteToWideChar(CP_ACP, 0, gb2312, -1, wstr, len); + len = WideCharToMultiByte(CP_UTF8, 0, wstr, -1, NULL, 0, NULL, NULL); + char* str = new char[len + 1]; + memset(str, 0, len + 1); + WideCharToMultiByte(CP_UTF8, 0, wstr, -1, str, len, NULL, NULL); + if (wstr) delete[] wstr; + return str; +} + +int getPrefStrings(const char* preference, TC_preference_search_scope_t scope, vector& pref_vec) +{ + int ifail = ITK_ok, i = 0, j = 0, k = 0, num = 0; + char** values; + TC_preference_search_scope_t old_scope; + //ITKCALL(ifail = PREF_ask_search_scope(&old_scope)); + //ITKCALL(ifail = PREF_set_search_scope(scope)); + //ITKCALL(ifail = PREF_ask_char_values(preference, &num, &values)); + ITKCALL(ifail = PREF_ask_char_values_at_location(preference, scope, &num, &values)); + if (ifail != ITK_ok) { + return ifail; + } + for (i = 0; i < num; i++) + { + pref_vec.push_back(values[i]); + } + DOFREE(values); + //ITKCALL(ifail = PREF_set_search_scope(old_scope)); + return ifail; +} + +int getPrefStrings2(const char* preference, TC_preference_search_scope_t scope, char splitter, vector& pref_vec) +{ + int ifail = ITK_ok, i = 0, j = 0, k = 0, num = 0; + char** values; + TC_preference_search_scope_t old_scope; + //ITKCALL(ifail = PREF_ask_search_scope(&old_scope)); + //ITKCALL(ifail = PREF_set_search_scope(scope)); + //ITKCALL(ifail = PREF_ask_char_values(preference, &num, &values)); + ITKCALL(ifail = PREF_ask_char_values_at_location(preference, scope, &num, &values)); + if (ifail != ITK_ok) { + return ifail; + } + for (i = 0; i < num; i++) + { + vector split; + Split(values[i], splitter, split); + int size = split.size(); + for (j = 0;j < size;j++) { + pref_vec.push_back(split[j]); + } + /*for each (string val in split) { + pref_vec.push_back(val); + }*/ + } + DOFREE(values); + //ITKCALL(ifail = PREF_set_search_scope(old_scope)); + return ifail; +} + +//碌录鲁枚脢媒戮脻录炉脦脛录镁 +int export_dataset_file(bool debug, tag_t dataset, const char* ref_name, char* userId, char* ext, char** filename, char** original_name) +{ + int ifail = ITK_ok; + tag_t ref_object = NULLTAG, + datasettype = NULLTAG, + new_ds = NULLTAG, + tool = NULLTAG, + folder_tag = NULLTAG, + spec_dataset_rev = NULLTAG; + AE_reference_type_t reference_type; + tag_t new_file_tag = NULLTAG; + IMF_file_t file_descriptor; + char* target_ds_name = NULL; + char* new_file_name; + WSOM_ask_name2(dataset, &target_ds_name); + WriteLog(debug, "Download file from dataset %s", target_ds_name); + DOFREE(target_ds_name); + *filename = (char*)MEM_alloc(sizeof(char) * 512); + *original_name = (char*)MEM_alloc(sizeof(char) * 512); + strcpy(*filename, ""); + AE_ask_dataset_latest_rev(dataset, &spec_dataset_rev); + AE_ask_dataset_named_ref2(dataset, ref_name, &reference_type, &ref_object); + if (ref_object == NULLTAG) + { + WriteLog(debug, "File ref not exist"); + return 1; + } + if (reference_type == AE_PART_OF) + { + char* pathname2 = NULL; + IMF_ask_file_pathname2(ref_object, SS_WNT_MACHINE, &pathname2); + DOFREE(pathname2); + char* origin_file_name2 = NULL; + IMF_ask_original_file_name2(ref_object, &origin_file_name2); + strcpy(*original_name, origin_file_name2); + DOFREE(origin_file_name2); + char new_ds_name[WSO_name_size_c + 1] = ""; + char* new_file_name = USER_new_file_name(new_ds_name, ref_name, ext, 0); + char* temp_dir = getenv("TEMP"); + char temp_file[SS_MAXPATHLEN] = ""; + strcpy(temp_file, temp_dir); + strcat(temp_file, "\\tc_"); + strcat(temp_file, userId); + strcat(temp_file, "\\"); + strcat(temp_file, new_file_name); + WriteLog(debug, "Temp path: %s", temp_file); + if ((_access(temp_file, 0)) != -1) { + if (!remove(temp_file)) { + remove(temp_file); + } + } + IMF_export_file(ref_object, temp_file); + strcpy(*filename, temp_file); + return ITK_ok; + } + return -1; +} \ No newline at end of file diff --git a/qf_nx_itk-master (3)/qf_nx_itk/Connor_NX/kutil - 鍓湰.cpp b/qf_nx_itk-master (3)/qf_nx_itk/Connor_NX/kutil - 鍓湰.cpp new file mode 100644 index 0000000..cdd05c4 --- /dev/null +++ b/qf_nx_itk-master (3)/qf_nx_itk/Connor_NX/kutil - 鍓湰.cpp @@ -0,0 +1,693 @@ +锘#pragma warning (disable: 4996) +#pragma warning (disable: 4819) + +#include "kutil.h" + +FILE* logFile = NULL; + +#define MAX_PATH_LENGTH 200 +#define MAX_PRINTLINE_LENGTH 2000 + +void initUserDir(char* userId) { + char logFileDir[MAX_PATH_LENGTH]; + memset(logFileDir, 0, sizeof(logFileDir)); + sprintf(logFileDir, "%s", getenv("TEMP")); + strcat(logFileDir, "\\tc_"); + strcat(logFileDir, userId); + if (chdir(logFileDir) != ITK_ok) { + printf(">> 脨脗陆篓脗路戮露拢潞%s\n", logFileDir); + mkdir(logFileDir); + } +} + +void WriteLog(logical debug, const char* format, ...) +{ + va_list arg; + char tmp[MAX_PRINTLINE_LENGTH]; + char date_string[MAX_PATH_LENGTH]; + time_t now; + struct tm* p; + + //get the message + memset(tmp, 0, sizeof(tmp)); + va_start(arg, format); + vsprintf(tmp, format, arg); + va_end(arg); + //----------print to command window for trace--------// + //printf("%s\n", tmp); + printf("%s\n", tmp); + //print message to log file + TC_write_syslog("%s\n", tmp); +} + +void WriteLog2(logical debug, const char* format, ...) +{ + va_list arg; + char tmp[MAX_PRINTLINE_LENGTH]; + char date_string[MAX_PATH_LENGTH]; + time_t now; + struct tm* p; + + //get the message + memset(tmp, 0, sizeof(tmp)); + va_start(arg, format); + vsprintf(tmp, format, arg); + va_end(arg); + //----------print to command window for trace--------// + //printf("%s\n", tmp); + printf("%s\n", tmp); + //print message to log file + if (!debug) { + return; + } + if (logFile) + { + time(&now); + //current_time(&status_now); + p = localtime(&now); + memset(date_string, 0, sizeof(date_string)); + sprintf(date_string, "%02d:%02d:%02d", p->tm_hour, p->tm_min, p->tm_sec); + fprintf(logFile, "[%s] %s\n", date_string, tmp); + fflush(logFile); + } + else + { + printf("*!Error!*: Log File Not Exist\n"); + } +} + +void CloseLog(void) +{ + if (logFile) + { + fclose(logFile); + logFile = NULL; + } +} + +void CreateLogFile(char* FunctionName, char* userId, char** fullname) +{ + int ifail = ITK_ok; + //date_t status_now; + //char* date_string = NULL; + char date_string[MAX_PATH_LENGTH]; + char logFileDir[MAX_PATH_LENGTH]; + char logFileName[MAX_PATH_LENGTH]; + //char* session_uid = NULL; + //tag_t session_tag = NULLTAG; + + time_t now; + struct tm* p; + + time(&now); + + logFile = NULL; + //current_time(&status_now); + p = localtime(&now); + + memset(date_string, 0, sizeof(date_string)); + //sprintf(date_string,"%4d%02d%02d%02d%02d%02d",1900+p->tm_year,p->tm_mon+1 ,p->tm_mday ,p->tm_hour,p->tm_min ,p->tm_sec ); + sprintf(date_string, "%4d%02d%02d", 1900 + p->tm_year, p->tm_mon + 1, p->tm_mday); + //if( DATE_date_to_string( status_now, "%Y%m%d%H%M%S", &date_string) != ITK_ok ) + //ifail = ITK_date_to_string (status_now, &date_string ); + //if (ifail) + //{ + // printf("!*ERROR*!: Failed to get current date time\n"); + // goto CLEANUP; + //} + + memset(logFileDir, 0, sizeof(logFileDir)); + memset(logFileName, 0, sizeof(logFileName)); + //get log dir + sprintf(logFileDir, "%s", getenv("TEMP")); + strcat(logFileDir, "\\tc_"); + strcat(logFileDir, userId); + //printf("\n log file dir: %s\n", logFileDir); + //try to change dir to TC_USER_LOG_DIR + if (chdir(logFileDir) != ITK_ok) + { + //not set TC_USER_LOG_DIR + //log in to default TC_LOG + memset(logFileDir, 0, sizeof(logFileDir)); + sprintf(logFileDir, "%s", getenv("TC_LOG")); + printf("\n TC_USER_LOG_DIR invalide, log file dir: %s\n", logFileDir); + if (chdir(logFileDir) != ITK_ok) + { + //still can not change to log dir + printf("!*ERROR*!: Failed to change dir to TC_USER_LOG_DIR\n"); + goto CLEANUP; + } + } + + //get session_uid to make sure the log file name unique + //POM_ask_session(&session_tag); + //ITK__convert_tag_to_uid(session_tag, &session_uid); + //get logFileName + sprintf(logFileName, "%s_%s_%s.log", FunctionName, userId, date_string); + //printf("log file name: %s\n", logFileName); + + *fullname = (char*)MEM_alloc(sizeof(char) * 512); + sprintf(*fullname, "%s\\%s", logFileDir, logFileName); + + //for(i = 0; _access((char *)logFileName, 4) == 0; i++) + /*{ + memset(logFileName, 0, sizeof(logFileName)); + sprintf(logFileName, "%s_%s_%s_%d.log", FunctionName, session_uid, date_string, i); + } + printf("final log file name: %s\n", logFileName);*/ + + //create log file + logFile = fopen(logFileName, "a"); + +CLEANUP:; + //DOFREE(date_string); + /*if(session_uid!=NULL){ + MEM_free(session_uid); + session_uid=NULL; + }*/ +} + + + +void set_bypass(logical bypass) +{ + //AM__set_application_bypass(bypass); + POM_AM__set_application_bypass(bypass); +} + +bool isClass(tag_t class_id, char* className) { + tag_t* pclass_ids = NULL; + char* class_name = NULL; + int pclass_count = 0, ifail = ITK_ok; + ITKCALL(POM_name_of_class(class_id, &class_name)); + printf("class name = %s\n", class_name); + bool isType = false; + if (strcmp(class_name, className) == 0) { + isType = true; + } + DOFREE(class_name); + if (isType) { + return true; + } + ITKCALL(ifail = POM_superclasses_of_class(class_id, &pclass_count, &pclass_ids)); + for (int i = 0;i < pclass_count;i++) { + isType = isClass(pclass_ids[i], className); + if (isType) { + return true; + } + } + return false; +} + +bool isType(tag_t item, char* type) { + tag_t class_id = NULLTAG, * pclass_ids = NULL; + char* class_name = NULL; + int pclass_count = 0, ifail = ITK_ok; + + ITKCALL(POM_class_of_instance(item, &class_id)); + return isClass(class_id, type); +} + +void deleteFile(bool debug, char* path) { + //脡戮鲁媒脦脛录镁 + if (remove(path) == 0) { + WriteLog(debug, "脡戮鲁媒脦脛录镁鲁脡鹿娄拢潞%s", path); + } + else { + WriteLog(debug, "脡戮鲁媒脦脛录镁脢搂掳脺拢潞%s", path); + } +} + + +int readError(bool debug, char* errFilePath, int errCode) { + fstream _file; + _file.open(errFilePath, ios::in); + if (_file) { + WriteLog(debug, "脮脪碌陆脪矛鲁拢脕脵脢卤脦脛录镁拢潞%s", errFilePath); + ifstream fin(errFilePath); + string s; + while (getline(fin, s)) + { + WriteLog(debug, s.c_str()); + EMH_store_error_s1(EMH_severity_error, errCode, s.c_str()); + } + _file.close(); + return errCode; + } + return ITK_ok; +} + +//碌录脠毛脢媒戮脻录炉 +int import_dataset_file(tag_t dataset, const char* ref_name, char* ext, char* fullfilename, char* original_name) +{ + int ifail = ITK_ok; + tag_t new_file_tag = NULLTAG; + IMF_file_t file_descriptor = NULL; + AOM_refresh(dataset, FALSE); + char* new_file_name = NULL; + char new_ds_name[WSO_name_size_c + 1] = ""; + char* filename = NULL; + new_file_name = USER_new_file_name(new_ds_name, ref_name, ext, 0); + filename = strrchr(fullfilename, '\\') + 1; + if (filename == NULL) + return ITK_ok; + set_bypass(true); + ITKCALL(ifail = IMF_import_file(fullfilename, new_file_name, SS_TEXT, &new_file_tag, &file_descriptor)); + if (ifail != ITK_ok) { + ITKCALL(ifail = IMF_import_file(fullfilename, new_file_name, SS_BINARY, &new_file_tag, &file_descriptor)); + } + ITKCALL(ifail = IMF_set_original_file_name2(new_file_tag, original_name)); + + ITKCALL(ifail = IMF_close_file(file_descriptor)); + ITKCALL(ifail = AOM_save(new_file_tag)); + AOM_unlock(new_file_tag); + ITKCALL(ifail = AOM_refresh(new_file_tag, FALSE)); + //脤铆录脫脰脕脙眉脙没脪媒脫脙 + set_bypass(true); + ITKCALL(AOM_lock(dataset)); + ITKCALL(ifail = AE_remove_dataset_named_ref2(dataset, ref_name)); + ITKCALL(ifail = AOM_save(dataset)); + set_bypass(true); + ITKCALL(ifail = AE_add_dataset_named_ref2(dataset, ref_name, AE_PART_OF, new_file_tag)); + AOM_save(dataset); + AOM_unlock(dataset); + set_bypass(false); + //ITKCALL( AOM_refresh( dataset, FALSE ) ); + return ifail; +} + +//碌录脠毛脢媒戮脻录炉 +int import_dataset_file_binary(tag_t dataset, const char* ref_name, char* ext, char* fullfilename, char* original_name) +{ + int ifail = ITK_ok; + tag_t new_file_tag = NULLTAG; + IMF_file_t file_descriptor = NULL; + AOM_refresh(dataset, FALSE); + char* new_file_name = NULL; + char new_ds_name[WSO_name_size_c + 1] = ""; + char* filename = NULL; + new_file_name = USER_new_file_name(new_ds_name, ref_name, ext, 0); + filename = strrchr(fullfilename, '\\') + 1; + if (filename == NULL) + return ITK_ok; + set_bypass(true); + ITKCALL(ifail = IMF_import_file(fullfilename, new_file_name, SS_BINARY, &new_file_tag, &file_descriptor)); + ITKCALL(ifail = IMF_set_original_file_name2(new_file_tag, original_name)); + + ITKCALL(ifail = IMF_close_file(file_descriptor)); + ITKCALL(ifail = AOM_save(new_file_tag)); + AOM_unlock(new_file_tag); + ITKCALL(ifail = AOM_refresh(new_file_tag, FALSE)); + //脤铆录脫脰脕脙眉脙没脪媒脫脙 + set_bypass(true); + ITKCALL(AOM_lock(dataset)); + ITKCALL(ifail = AE_remove_dataset_named_ref2(dataset, ref_name)); + ITKCALL(ifail = AOM_save(dataset)); + set_bypass(true); + ITKCALL(ifail = AE_add_dataset_named_ref2(dataset, ref_name, AE_PART_OF, new_file_tag)); + AOM_save(dataset); + AOM_unlock(dataset); + set_bypass(false); + //ITKCALL( AOM_refresh( dataset, FALSE ) ); + return ifail; +} + + +void Split(string strArg, char spliter, vector& ans) +{ + ans.clear(); + size_t index0 = 0; + string one_arg; + if (strArg.find_first_not_of(' ') == string::npos) + strArg = ""; + while (strArg.size() > 0) + { + index0 = strArg.find_first_of(spliter); + if (index0 != string::npos) + { + one_arg = strArg.substr(0, index0); + strArg = strArg.substr(index0 + 1); + ans.push_back(one_arg); + } + else + { + ans.push_back(strArg); + break; + } + } +} + +void Split(string strArg, string spliter, vector& ans) +{ + ans.clear(); + size_t index0 = 0; + string one_arg; + if (strArg.find_first_not_of(' ') == string::npos) + strArg = ""; + while (strArg.size() > 0) + { + index0 = strArg.find_first_of(spliter); + if (index0 != string::npos) + { + one_arg = strArg.substr(0, index0); + strArg = strArg.substr(index0 + 1); + ans.push_back(one_arg); + } + else + { + ans.push_back(strArg); + break; + } + } +} + +bool inArray(vector types, string type) { + int len = types.size(); + for (int i = 0;i < len;i++) { + if (strcmp(types[i].c_str(), type.c_str()) == 0) { + return true; + } + } + return false; +} + +int getIndexInArray(vector types, string type) { + int len = types.size(); + for (int i = 0;i < len;i++) { + if (strcmp(types[i].c_str(), type.c_str()) == 0) { + return i; + } + } + return -1; +} + +bool CheckType(string config, char* type, char spliter) { + vector types; + Split(config, spliter, types); + int len = types.size(); + for (int i = 0;i < len;i++) { + if (strcmp(types[i].c_str(), type) == 0) { + return true; + } + } + return false; +} + +int GetProcessTargets(bool debug, int att_cnt, tag_t* attachments, vector& targets, char* formType, char splitter) { + char* object_name = NULL, * object_type = NULL; + int ifail = ITK_ok; + WriteLog(debug, "驴陋脢录录矛脣梅脕梅鲁脤脛驴卤锚露脭脧贸拢潞%d", att_cnt); + for (int i = 0;i < att_cnt;i++) { + ITKCALL(ifail = WSOM_ask_name2(attachments[i], &object_name)); + ITKCALL(ifail = WSOM_ask_object_type2(attachments[i], &object_type)); + WriteLog(debug, "%d. 脕梅鲁脤露脭脧贸<%s>拢卢脌脿脨脥拢潞%s", i + 1, object_name, object_type); + //if (strcmp(object_type, TYPE_ITEM_PZJ.c_str()) == 0) { + if (CheckType(formType, object_type, splitter)) { + targets.push_back(attachments[i]); + } + DOFREE(object_name); + DOFREE(object_type); + } + return ITK_ok; +} + +int findUser(bool debug, string userStr, tag_t* user_tag) { + int ind1 = userStr.find_first_of('('); + int ind2 = userStr.find_first_of(')'); + WriteLog(debug, "虏茅脩炉脫脙禄搂拢潞%s", userStr.c_str()); + if (ind1 != string::npos && ind2 != string::npos && ind1 < ind2) { + userStr = userStr.substr(ind1 + 1, ind2 - ind1 - 1); + WriteLog(debug, ">> 脫脙禄搂id: %s", userStr.c_str()); + } + int ifail = ITK_ok; + ITKCALL(ifail = SA_find_user2(userStr.c_str(), user_tag)); + return ifail; +} + +int GetBomLinePropString(bool debug, tag_t line, char* propName, int errCode, char** attr_val) { + int attribute_id = 0, ifail = ITK_ok; + ITKCALL(ifail = BOM_line_look_up_attribute(propName, &attribute_id)); + if (attribute_id == 0) { + WriteLog(debug, "BOM脨脨脢么脨脭虏禄麓忙脭脷拢潞%s", propName); + EMH_store_error_s2(EMH_severity_error, errCode, "BOM脨脨脢么脨脭虏禄麓忙脭脷", propName); + return errCode; + } + else { + ITKCALL(ifail = BOM_line_ask_attribute_string(line, attribute_id, &*attr_val)); + return ifail; + } + return ITK_ok; +} + +int GetStringProp(tag_t obj, char* propName, char** attr_val) { + return AOM_ask_value_string(obj, propName, &*attr_val); +} + +bool isRev(char* object_type) { + if (((strstr(object_type, "Revision") != NULL) || (strstr(object_type, "revision") != NULL)) + && (strstr(object_type, "Master") == NULL) && (strstr(object_type, "master") == NULL) + && (strstr(object_type, "BOM") == NULL) && (strstr(object_type, "bom") == NULL) && (strstr(object_type, "Bom") == NULL)) { + return true; + } + return false; +} + +int GetBomView(tag_t rev_tag, char* viewtype, tag_t* bomView, tag_t* bomBVR, bool debug) +{ + WriteLog(debug, "驴陋脢录禄帽脠隆BOM脢脫脥录拢潞%s", viewtype); + int ifail = ITK_ok, bvr_count = 0; + tag_t* bvr_list = NULL, bom_view = NULLTAG, view_type = NULLTAG; + *bomBVR = NULLTAG; + *bomView = NULLTAG; + ITKCALL(ITEM_rev_list_bom_view_revs(rev_tag, &bvr_count, &bvr_list)); + if (bvr_count > 0) + { + for (int i = 0; i < bvr_count; i++) + { + ITKCALL(PS_ask_bom_view_of_bvr(bvr_list[i], &bom_view)); + + ITKCALL(PS_ask_bom_view_type(bom_view, &view_type)); + //ITKCALL( PS_find_view_type(bom_view, &view_type)); + char* view_type_name = NULL; + ITKCALL(PS_ask_view_type_name(view_type, &view_type_name)); + WriteLog(debug, "脮脪碌陆脢脫脥录 脌脿脨脥拢潞%s", view_type_name); + if (tc_strcmp(view_type_name, viewtype) == 0) + { + *bomBVR = bvr_list[i]; + *bomView = bom_view; + } + DOFREE(view_type_name); + } + } + //else { + // WriteLog(debug, "脙禄脫脨脮脪碌陆bvr驴陋脢录陆酶脨脨麓麓陆篓"); + // tag_t bv = NULLTAG, bvr = NULLTAG, item_tag = NULLTAG; + // int bvCnt = 0; + // tag_t* bvTags = NULL; + + + // ITKCALL(ifail = ITEM_ask_item_of_rev(rev_tag, &item_tag)); + + + // tag_t tWindow = NULLTAG; + // ITKCALL(BOM_create_window(&tWindow)); + + // tag_t tTopLine = NULLTAG; + // ITKCALL(BOM_set_window_top_line(tWindow, item_tag, NULLTAG, NULLTAG, &tTopLine)); + + // //虏茅脮脪脭颅BOM脢脫脥录 + // ITKCALL(ifail=ITEM_list_bom_views(item_tag, &bvCnt, &bvTags)); + // if (bvCnt > 0) { + // WriteLog(debug, "露脭脧贸脪脩麓忙脭脷BOM脢脫脥录拢潞%d", bvCnt); + // bv = bvTags[0]; + // } + // ITKCALL(AOM_lock(item_tag)); + // if (bv == NULLTAG) { + // ITKCALL(ifail=PS_create_bom_view(NULLTAG, "", "", item_tag, &bv)); + // if (ifail != ITK_ok) { + // ITKCALL(AOM_unlock(item_tag)); + // return ifail; + // } + // ITKCALL(AOM_save(bv)); + // } + // ITKCALL(ifail=PS_create_bvr(bv, "", "", false, rev_tag, &bvr)); + // if (ifail != ITK_ok) { + // ITKCALL(AOM_unlock(item_tag)); + // return ifail; + // } + // ITKCALL(AOM_save(bvr)); + // ITKCALL(AOM_save(bv)); + // ITKCALL(AOM_save(item_tag)); + + // tag_t tChildLine = NULLTAG; + + // ITKCALL(BOM_save_window(tWindow)); + // ITKCALL(BOM_close_window(tWindow)); + + // ITKCALL(AOM_unlock(item_tag)); + // *bomBVR = bvr; + // *bomView = bv; + // WriteLog(debug, "bvr脨脗陆篓脥锚鲁脡"); + // DOFREE(bvTags); + + //} + DOFREE(bvr_list); + return ifail; +} + +bool propExist(bool debug, tag_t obj, const char* propName) { + tag_t clTag = NULLTAG, * superClass = NULL; + char* clName = NULL; + int ifail = ITK_ok, cnt = 0; + logical exists = false; + ITKCALL(ifail = POM_class_of_instance(obj, &clTag)); + if (ifail != ITK_ok) { return false; } + ITKCALL(ifail = POM_name_of_class(clTag, &clName)); + if (ifail != ITK_ok) { return false; } + WriteLog(debug, ">> 录矛虏茅%s脢么脨脭: %s", clName, propName); + ITKCALL(ifail = POM_attr_exists(propName, clName, &exists)); + if (ifail != ITK_ok) { return false; } + DOFREE(clName); + if (exists) { + //WriteLog(debug,"脢么脨脭麓忙脭脷"); + return exists; + } + ITKCALL(ifail = POM_superclasses_of_class(clTag, &cnt, &superClass)); + for (int i = 0;i < cnt;i++) { + ITKCALL(ifail = POM_name_of_class(superClass[i], &clName)); + if (ifail != ITK_ok) { return false; } + WriteLog(debug, ">> 录矛虏茅%s脢么脨脭: %s", clName, propName); + ITKCALL(ifail = POM_attr_exists(propName, clName, &exists)); + DOFREE(clName); + if (exists) { + //WriteLog(debug, "脢么脨脭麓忙脭脷"); + return exists; + } + } + WriteLog(debug, "脢么脨脭虏禄麓忙脭脷"); + return exists; +} + + +char* G2U(const char* gb2312) +{ + int len = MultiByteToWideChar(CP_ACP, 0, gb2312, -1, NULL, 0); + wchar_t* wstr = new wchar_t[len + 1]; + memset(wstr, 0, len + 1); + MultiByteToWideChar(CP_ACP, 0, gb2312, -1, wstr, len); + len = WideCharToMultiByte(CP_UTF8, 0, wstr, -1, NULL, 0, NULL, NULL); + char* str = new char[len + 1]; + memset(str, 0, len + 1); + WideCharToMultiByte(CP_UTF8, 0, wstr, -1, str, len, NULL, NULL); + if (wstr) delete[] wstr; + return str; +} + +int getPrefStrings(const char* preference, TC_preference_search_scope_t scope, vector& pref_vec) +{ + int ifail = ITK_ok, i = 0, j = 0, k = 0, num = 0; + char** values; + TC_preference_search_scope_t old_scope; + //ITKCALL(ifail = PREF_ask_search_scope(&old_scope)); + //ITKCALL(ifail = PREF_set_search_scope(scope)); + //ITKCALL(ifail = PREF_ask_char_values(preference, &num, &values)); + ITKCALL(ifail = PREF_ask_char_values_at_location(preference, scope, &num, &values)); + if (ifail != ITK_ok) { + return ifail; + } + for (i = 0; i < num; i++) + { + pref_vec.push_back(values[i]); + } + DOFREE(values); + //ITKCALL(ifail = PREF_set_search_scope(old_scope)); + return ifail; +} + +int getPrefStrings2(const char* preference, TC_preference_search_scope_t scope, char splitter, vector& pref_vec) +{ + int ifail = ITK_ok, i = 0, j = 0, k = 0, num = 0; + char** values; + TC_preference_search_scope_t old_scope; + //ITKCALL(ifail = PREF_ask_search_scope(&old_scope)); + //ITKCALL(ifail = PREF_set_search_scope(scope)); + //ITKCALL(ifail = PREF_ask_char_values(preference, &num, &values)); + ITKCALL(ifail = PREF_ask_char_values_at_location(preference, scope, &num, &values)); + if (ifail != ITK_ok) { + return ifail; + } + for (i = 0; i < num; i++) + { + vector split; + Split(values[i], splitter, split); + int size = split.size(); + for (j = 0;j < size;j++) { + pref_vec.push_back(split[j]); + } + /*for each (string val in split) { + pref_vec.push_back(val); + }*/ + } + DOFREE(values); + //ITKCALL(ifail = PREF_set_search_scope(old_scope)); + return ifail; +} + +//碌录鲁枚脢媒戮脻录炉脦脛录镁 +int export_dataset_file(bool debug, tag_t dataset, const char* ref_name, char* userId, char* ext, char** filename, char** original_name) +{ + int ifail = ITK_ok; + tag_t ref_object = NULLTAG, + datasettype = NULLTAG, + new_ds = NULLTAG, + tool = NULLTAG, + folder_tag = NULLTAG, + spec_dataset_rev = NULLTAG; + AE_reference_type_t reference_type; + tag_t new_file_tag = NULLTAG; + IMF_file_t file_descriptor; + char* target_ds_name = NULL; + char* new_file_name; + WSOM_ask_name2(dataset, &target_ds_name); + WriteLog(debug, "驴陋脢录麓脫脢媒戮脻录炉<%s>脧脗脭脴脦脛录镁", target_ds_name); + DOFREE(target_ds_name); + *filename = (char*)MEM_alloc(sizeof(char) * 512); + *original_name = (char*)MEM_alloc(sizeof(char) * 512); + strcpy(*filename, ""); + AE_ask_dataset_latest_rev(dataset, &spec_dataset_rev); + AE_ask_dataset_named_ref2(dataset, ref_name, &reference_type, &ref_object); + if (ref_object == NULLTAG) + { + WriteLog(debug, "脦脛录镁脪媒脫脙脦陋驴脮"); + return 1; + } + if (reference_type == AE_PART_OF) + { + char* pathname2 = NULL; + IMF_ask_file_pathname2(ref_object, SS_WNT_MACHINE, &pathname2); + DOFREE(pathname2); + char* origin_file_name2 = NULL; + IMF_ask_original_file_name2(ref_object, &origin_file_name2); + strcpy(*original_name, origin_file_name2); + DOFREE(origin_file_name2); + char new_ds_name[WSO_name_size_c + 1] = ""; + char* new_file_name = USER_new_file_name(new_ds_name, ref_name, ext, 0); + char* temp_dir = getenv("TEMP"); + char temp_file[SS_MAXPATHLEN] = ""; + strcpy(temp_file, temp_dir); + strcat(temp_file, "\\tc_"); + strcat(temp_file, userId); + strcat(temp_file, "\\"); + strcat(temp_file, new_file_name); + WriteLog(debug, "脕脵脢卤脦脛录镁脗路戮露拢潞%s", temp_file); + if ((_access(temp_file, 0)) != -1) { + if (!remove(temp_file)) { + remove(temp_file); + } + } + IMF_export_file(ref_object, temp_file); + strcpy(*filename, temp_file); + return ITK_ok; + } + return -1; +} \ No newline at end of file diff --git a/qf_nx_itk-master (3)/qf_nx_itk/Connor_NX/kutil.cpp b/qf_nx_itk-master (3)/qf_nx_itk/Connor_NX/kutil.cpp new file mode 100644 index 0000000..af3d0f9 --- /dev/null +++ b/qf_nx_itk-master (3)/qf_nx_itk/Connor_NX/kutil.cpp @@ -0,0 +1,800 @@ +#pragma warning (disable: 4996) +#pragma warning (disable: 4819) + +#include "kutil.h" + +FILE* logFile = NULL; + +#define MAX_PATH_LENGTH 200 +#define MAX_PRINTLINE_LENGTH 8000 + +void initUserDir(char* userId) { + char logFileDir[MAX_PATH_LENGTH]; + memset(logFileDir, 0, sizeof(logFileDir)); + sprintf(logFileDir, "%s", getenv("TEMP")); + strcat(logFileDir, "\\tc_"); + strcat(logFileDir, userId); + if (chdir(logFileDir) != ITK_ok) { + printf(">> Create Path: %s\n", logFileDir); + mkdir(logFileDir); + } +} + + +int WriteToFile(logical debug, FILE* file, const char* format, ...) +{ + va_list arg; + char tmp[MAX_PRINTLINE_LENGTH]; + + //get the message + memset(tmp, 0, sizeof(tmp)); + va_start(arg, format); + vsprintf(tmp, format, arg); + va_end(arg); + //print message to log file + WriteLog(debug, "写入内容:%s", tmp); + if (file) + { + fprintf(file, "%s", tmp); + fflush(file); + return ITK_ok; + } + else + { + WriteLog(debug, "写入文件失败,文件不存在"); + return -1; + } +} + +int CreateUserFile(logical debug, const char* FunctionName, char* userId, char** fullname, FILE** file) +{ + int ifail = ITK_ok; + //date_t status_now; + //char* date_string = NULL; + char date_string[MAX_PATH_LENGTH]; + char logFileDir[MAX_PATH_LENGTH]; + char logFileName[MAX_PATH_LENGTH]; + //char* session_uid = NULL; + //tag_t session_tag = NULLTAG; + + time_t now; + struct tm* p; + + time(&now); + + //logFile = NULL; + //current_time(&status_now); + p = localtime(&now); + + memset(date_string, 0, sizeof(date_string)); + sprintf(date_string, "%4d%02d%02d%02d%02d%02d", 1900 + p->tm_year, p->tm_mon + 1, p->tm_mday, p->tm_hour, p->tm_min, p->tm_sec); + //sprintf(date_string, "%4d%02d%02d", 1900 + p->tm_year, p->tm_mon + 1, p->tm_mday); + //if( DATE_date_to_string( status_now, "%Y%m%d%H%M%S", &date_string) != ITK_ok ) + //ifail = ITK_date_to_string (status_now, &date_string ); + //if (ifail) + //{ + // printf("!*ERROR*!: Failed to get current date time\n"); + // goto CLEANUP; + //} + + memset(logFileDir, 0, sizeof(logFileDir)); + memset(logFileName, 0, sizeof(logFileName)); + //get log dir + sprintf(logFileDir, "%s", getenv("TEMP")); + strcat(logFileDir, "\\tc_"); + strcat(logFileDir, userId); + //printf("\n log file dir: %s\n", logFileDir); + //try to change dir to TC_USER_LOG_DIR + if (chdir(logFileDir) != ITK_ok) + { + //not set TC_USER_LOG_DIR + //log in to default TC_LOG + memset(logFileDir, 0, sizeof(logFileDir)); + sprintf(logFileDir, "%s", getenv("TC_LOG")); + WriteLog(debug, "TC_USER_LOG_DIR invalide, log file dir: %s", logFileDir); + //printf("\n TC_USER_LOG_DIR invalide, log file dir: %s\n", logFileDir); + if (chdir(logFileDir) != ITK_ok) + { + //still can not change to log dir + WriteLog(debug, "!*ERROR*!: Failed to change dir to TC_USER_LOG_DIR"); + //printf("!*ERROR*!: Failed to change dir to TC_USER_LOG_DIR\n"); + return -1; + } + } + + //get session_uid to make sure the log file name unique + //POM_ask_session(&session_tag); + //ITK__convert_tag_to_uid(session_tag, &session_uid); + //get logFileName + sprintf(logFileName, "%s_%s_%s.txt", FunctionName, userId, date_string); + //printf("log file name: %s\n", logFileName); + + *fullname = (char*)MEM_alloc(sizeof(char) * 512); + sprintf(*fullname, "%s\\%s", logFileDir, logFileName); + + //for(i = 0; _access((char *)logFileName, 4) == 0; i++) + /*{ + memset(logFileName, 0, sizeof(logFileName)); + sprintf(logFileName, "%s_%s_%s_%d.log", FunctionName, session_uid, date_string, i); + } + printf("final log file name: %s\n", logFileName);*/ + + //create log file + *file = fopen(logFileName, "a"); + return ITK_ok; + //CLEANUP:; + //DOFREE(date_string); + /*if(session_uid!=NULL){ + MEM_free(session_uid); + session_uid=NULL; + }*/ +} + + +void WriteLog(logical debug, const char* format, ...) +{ + va_list arg; + char tmp[MAX_PRINTLINE_LENGTH]; + memset(tmp, 0, sizeof(tmp)); + va_start(arg, format); + vsprintf(tmp, format, arg); + va_end(arg); + printf("%s\n", tmp); + TC_write_syslog("%s\n", tmp); +} + +void WriteLog2(logical debug, const char* format, ...) +{ + va_list arg; + char tmp[MAX_PRINTLINE_LENGTH]; + char date_string[MAX_PATH_LENGTH]; + time_t now; + struct tm* p; + + //get the message + memset(tmp, 0, sizeof(tmp)); + va_start(arg, format); + vsprintf(tmp, format, arg); + va_end(arg); + //----------print to command window for trace--------// + //printf("%s\n", tmp); + printf("%s\n", tmp); + //print message to log file + if (!debug) { + return; + } + if (logFile) + { + time(&now); + //current_time(&status_now); + p = localtime(&now); + memset(date_string, 0, sizeof(date_string)); + sprintf(date_string, "%02d:%02d:%02d", p->tm_hour, p->tm_min, p->tm_sec); + fprintf(logFile, "[%s] %s\n", date_string, tmp); + fflush(logFile); + } + else + { + printf("*!Error!*: Log File Not Exist\n"); + } +} + +void CloseLog(void) +{ + if (logFile) + { + fclose(logFile); + logFile = NULL; + } +} + +void CreateLogFile(char* FunctionName, char* userId, char** fullname) +{ + int ifail = ITK_ok; + //date_t status_now; + //char* date_string = NULL; + char date_string[MAX_PATH_LENGTH]; + char logFileDir[MAX_PATH_LENGTH]; + char logFileName[MAX_PATH_LENGTH]; + //char* session_uid = NULL; + //tag_t session_tag = NULLTAG; + + time_t now; + struct tm* p; + + time(&now); + + logFile = NULL; + //current_time(&status_now); + p = localtime(&now); + + memset(date_string, 0, sizeof(date_string)); + //sprintf(date_string,"%4d%02d%02d%02d%02d%02d",1900+p->tm_year,p->tm_mon+1 ,p->tm_mday ,p->tm_hour,p->tm_min ,p->tm_sec ); + sprintf(date_string, "%4d%02d%02d", 1900 + p->tm_year, p->tm_mon + 1, p->tm_mday); + //if( DATE_date_to_string( status_now, "%Y%m%d%H%M%S", &date_string) != ITK_ok ) + //ifail = ITK_date_to_string (status_now, &date_string ); + //if (ifail) + //{ + // printf("!*ERROR*!: Failed to get current date time\n"); + // goto CLEANUP; + //} + + memset(logFileDir, 0, sizeof(logFileDir)); + memset(logFileName, 0, sizeof(logFileName)); + //get log dir + sprintf(logFileDir, "%s", getenv("TEMP")); + strcat(logFileDir, "\\tc_"); + strcat(logFileDir, userId); + //printf("\n log file dir: %s\n", logFileDir); + //try to change dir to TC_USER_LOG_DIR + if (chdir(logFileDir) != ITK_ok) + { + //not set TC_USER_LOG_DIR + //log in to default TC_LOG + memset(logFileDir, 0, sizeof(logFileDir)); + sprintf(logFileDir, "%s", getenv("TC_LOG")); + printf("\n TC_USER_LOG_DIR invalide, log file dir: %s\n", logFileDir); + if (chdir(logFileDir) != ITK_ok) + { + //still can not change to log dir + printf("!*ERROR*!: Failed to change dir to TC_USER_LOG_DIR\n"); + goto CLEANUP; + } + } + + //get session_uid to make sure the log file name unique + //POM_ask_session(&session_tag); + //ITK__convert_tag_to_uid(session_tag, &session_uid); + //get logFileName + sprintf(logFileName, "%s_%s_%s.log", FunctionName, userId, date_string); + //printf("log file name: %s\n", logFileName); + + *fullname = (char*)MEM_alloc(sizeof(char) * 512); + sprintf(*fullname, "%s\\%s", logFileDir, logFileName); + + //for(i = 0; _access((char *)logFileName, 4) == 0; i++) + /*{ + memset(logFileName, 0, sizeof(logFileName)); + sprintf(logFileName, "%s_%s_%s_%d.log", FunctionName, session_uid, date_string, i); + } + printf("final log file name: %s\n", logFileName);*/ + + //create log file + logFile = fopen(logFileName, "a"); + +CLEANUP:; + //DOFREE(date_string); + /*if(session_uid!=NULL){ + MEM_free(session_uid); + session_uid=NULL; + }*/ +} + + + +void set_bypass(logical bypass) +{ + //AM__set_application_bypass(bypass); + POM_AM__set_application_bypass(bypass); +} + +bool isClass(tag_t class_id, char* className) { + tag_t* pclass_ids = NULL; + char* class_name = NULL; + int pclass_count = 0, ifail = ITK_ok; + ITKCALL(POM_name_of_class(class_id, &class_name)); + printf("class name = %s\n", class_name); + bool isType = false; + if (strcmp(class_name, className) == 0) { + isType = true; + } + DOFREE(class_name); + if (isType) { + return true; + } + ITKCALL(ifail = POM_superclasses_of_class(class_id, &pclass_count, &pclass_ids)); + for (int i = 0;i < pclass_count;i++) { + isType = isClass(pclass_ids[i], className); + if (isType) { + return true; + } + } + return false; +} + +bool isType(tag_t item, char* type) { + tag_t class_id = NULLTAG, * pclass_ids = NULL; + char* class_name = NULL; + int pclass_count = 0, ifail = ITK_ok; + + ITKCALL(POM_class_of_instance(item, &class_id)); + return isClass(class_id, type); +} + +void deleteFile(bool debug, char* path) { + //é?3y???t + if (remove(path) == 0) { + WriteLog(debug, "Delete File: %s", path); + } + else { + WriteLog(debug, "Delete File failed: %s", path); + } +} + + +int readError(bool debug, char* errFilePath, int errCode) { + fstream _file; + _file.open(errFilePath, ios::in); + if (_file) { + WriteLog(debug, "Find Error File: %s", errFilePath); + ifstream fin(errFilePath); + string s; + while (getline(fin, s)) + { + WriteLog(debug, s.c_str()); + EMH_store_error_s1(EMH_severity_error, errCode, s.c_str()); + } + _file.close(); + return errCode; + } + return ITK_ok; +} + +//μ?è?êy?Y?ˉ +int import_dataset_file(tag_t dataset, const char* ref_name, char* ext, char* fullfilename, char* original_name) +{ + int ifail = ITK_ok; + tag_t new_file_tag = NULLTAG; + IMF_file_t file_descriptor = NULL; + AOM_refresh(dataset, FALSE); + char* new_file_name = NULL; + char new_ds_name[WSO_name_size_c + 1] = ""; + char* filename = NULL; + new_file_name = USER_new_file_name(new_ds_name, ref_name, ext, 0); + filename = strrchr(fullfilename, '\\') + 1; + if (filename == NULL) + return ITK_ok; + set_bypass(true); + ITKCALL(ifail = IMF_import_file(fullfilename, new_file_name, SS_TEXT, &new_file_tag, &file_descriptor)); + if (ifail != ITK_ok) { + ITKCALL(ifail = IMF_import_file(fullfilename, new_file_name, SS_BINARY, &new_file_tag, &file_descriptor)); + } + ITKCALL(ifail = IMF_set_original_file_name2(new_file_tag, original_name)); + + ITKCALL(ifail = IMF_close_file(file_descriptor)); + ITKCALL(ifail = AOM_save(new_file_tag)); + AOM_unlock(new_file_tag); + ITKCALL(ifail = AOM_refresh(new_file_tag, FALSE)); + //ìí?ó?á?ü??òyó? + set_bypass(true); + ITKCALL(AOM_lock(dataset)); + ITKCALL(ifail = AE_remove_dataset_named_ref2(dataset, ref_name)); + ITKCALL(ifail = AOM_save(dataset)); + set_bypass(true); + ITKCALL(ifail = AE_add_dataset_named_ref2(dataset, ref_name, AE_PART_OF, new_file_tag)); + AOM_save(dataset); + AOM_unlock(dataset); + set_bypass(false); + //ITKCALL( AOM_refresh( dataset, FALSE ) ); + return ifail; +} + +//μ?è?êy?Y?ˉ +int import_dataset_file_binary(tag_t dataset, const char* ref_name, char* ext, char* fullfilename, char* original_name) +{ + int ifail = ITK_ok; + tag_t new_file_tag = NULLTAG; + IMF_file_t file_descriptor = NULL; + AOM_refresh(dataset, FALSE); + char* new_file_name = NULL; + char new_ds_name[WSO_name_size_c + 1] = ""; + char* filename = NULL; + new_file_name = USER_new_file_name(new_ds_name, ref_name, ext, 0); + filename = strrchr(fullfilename, '\\') + 1; + if (filename == NULL) + return ITK_ok; + set_bypass(true); + ITKCALL(ifail = IMF_import_file(fullfilename, new_file_name, SS_BINARY, &new_file_tag, &file_descriptor)); + ITKCALL(ifail = IMF_set_original_file_name2(new_file_tag, original_name)); + + ITKCALL(ifail = IMF_close_file(file_descriptor)); + ITKCALL(ifail = AOM_save(new_file_tag)); + AOM_unlock(new_file_tag); + ITKCALL(ifail = AOM_refresh(new_file_tag, FALSE)); + //ìí?ó?á?ü??òyó? + set_bypass(true); + ITKCALL(AOM_lock(dataset)); + ITKCALL(ifail = AE_remove_dataset_named_ref2(dataset, ref_name)); + ITKCALL(ifail = AOM_save(dataset)); + set_bypass(true); + ITKCALL(ifail = AE_add_dataset_named_ref2(dataset, ref_name, AE_PART_OF, new_file_tag)); + AOM_save(dataset); + AOM_unlock(dataset); + set_bypass(false); + //ITKCALL( AOM_refresh( dataset, FALSE ) ); + return ifail; +} + + +void Split(string strArg, char spliter, vector& ans) +{ + ans.clear(); + size_t index0 = 0; + string one_arg; + if (strArg.find_first_not_of(' ') == string::npos) + strArg = ""; + while (strArg.size() > 0) + { + index0 = strArg.find_first_of(spliter); + if (index0 != string::npos) + { + one_arg = strArg.substr(0, index0); + strArg = strArg.substr(index0 + 1); + ans.push_back(one_arg); + } + else + { + ans.push_back(strArg); + break; + } + } +} + +void Split(string strArg, string spliter, vector& ans) +{ + ans.clear(); + size_t index0 = 0; + string one_arg; + if (strArg.find_first_not_of(' ') == string::npos) + strArg = ""; + int len = spliter.size(); + while (strArg.size() > 0) + { + index0 = strArg.find(spliter); + if (index0 != string::npos) + { + one_arg = strArg.substr(0, index0); + strArg = strArg.substr(index0 + len); + ans.push_back(one_arg); + if (strArg.size() == 0) { + ans.push_back(strArg); + } + } + else + { + ans.push_back(strArg); + break; + } + } +} + +bool inArray(vector types, string type) { + int len = types.size(); + for (int i = 0;i < len;i++) { + if (strcmp(types[i].c_str(), type.c_str()) == 0) { + return true; + } + } + return false; +} + +int getIndexInArray(vector types, string type) { + int len = types.size(); + for (int i = 0;i < len;i++) { + if (strcmp(types[i].c_str(), type.c_str()) == 0) { + return i; + } + } + return -1; +} + +bool CheckType(string config, char* type, char spliter) { + vector types; + Split(config, spliter, types); + int len = types.size(); + for (int i = 0;i < len;i++) { + if (strcmp(types[i].c_str(), type) == 0) { + return true; + } + } + return false; +} + +int GetProcessTargets(bool debug, int att_cnt, tag_t* attachments, vector& targets, char* formType, char splitter) { + char* object_name = NULL, * object_type = NULL; + int ifail = ITK_ok; + WriteLog(debug, "Get Targets of Process: %d", att_cnt); + for (int i = 0;i < att_cnt;i++) { + ITKCALL(ifail = WSOM_ask_name2(attachments[i], &object_name)); + ITKCALL(ifail = WSOM_ask_object_type2(attachments[i], &object_type)); + WriteLog(debug, "%d. Target [%s], type: %s", i + 1, object_name, object_type); + //if (strcmp(object_type, TYPE_ITEM_PZJ.c_str()) == 0) { + if (CheckType(formType, object_type, splitter)) { + targets.push_back(attachments[i]); + } + DOFREE(object_name); + DOFREE(object_type); + } + return ITK_ok; +} + +int findUser(bool debug, string userStr, tag_t* user_tag) { + int ind1 = userStr.find_first_of('('); + int ind2 = userStr.find_first_of(')'); + WriteLog(debug, "Search User: %s", userStr.c_str()); + if (ind1 != string::npos && ind2 != string::npos && ind1 < ind2) { + userStr = userStr.substr(ind1 + 1, ind2 - ind1 - 1); + WriteLog(debug, ">> User id: %s", userStr.c_str()); + } + int ifail = ITK_ok; + ITKCALL(ifail = SA_find_user2(userStr.c_str(), user_tag)); + return ifail; +} + +int GetBomLinePropString(bool debug, tag_t line, char* propName, int errCode, char** attr_val) { + int attribute_id = 0, ifail = ITK_ok; + ITKCALL(ifail = BOM_line_look_up_attribute(propName, &attribute_id)); + if (attribute_id == 0) { + WriteLog(debug, "BOMLine property not exist: %s", propName); + EMH_store_error_s2(EMH_severity_error, errCode, "BOMLine property not exist", propName); + return errCode; + } + else { + ITKCALL(ifail = BOM_line_ask_attribute_string(line, attribute_id, &*attr_val)); + return ifail; + } + return ITK_ok; +} + +int GetStringProp(tag_t obj, char* propName, char** attr_val) { + return AOM_ask_value_string(obj, propName, &*attr_val); +} + +bool isRev(char* object_type) { + if (((strstr(object_type, "Revision") != NULL) || (strstr(object_type, "revision") != NULL)) + && (strstr(object_type, "Master") == NULL) && (strstr(object_type, "master") == NULL) + && (strstr(object_type, "BOM") == NULL) && (strstr(object_type, "bom") == NULL) && (strstr(object_type, "Bom") == NULL)) { + return true; + } + return false; +} + +int GetBomView(tag_t rev_tag, const char* viewtype, tag_t* bomView, tag_t* bomBVR, bool debug) +{ + WriteLog(debug, "Get BOM View: %s", viewtype); + int ifail = ITK_ok, bvr_count = 0; + tag_t* bvr_list = NULL, bom_view = NULLTAG, view_type = NULLTAG; + *bomBVR = NULLTAG; + *bomView = NULLTAG; + ITKCALL(ITEM_rev_list_bom_view_revs(rev_tag, &bvr_count, &bvr_list)); + if (bvr_count > 0) + { + for (int i = 0; i < bvr_count; i++) + { + ITKCALL(PS_ask_bom_view_of_bvr(bvr_list[i], &bom_view)); + + ITKCALL(PS_ask_bom_view_type(bom_view, &view_type)); + //ITKCALL( PS_find_view_type(bom_view, &view_type)); + char* view_type_name = NULL; + ITKCALL(PS_ask_view_type_name(view_type, &view_type_name)); + WriteLog(debug, "Find View: %s", view_type_name); + if (tc_strcmp(view_type_name, viewtype) == 0) + { + *bomBVR = bvr_list[i]; + *bomView = bom_view; + } + DOFREE(view_type_name); + } + } + //else { + // WriteLog(debug, "??óD?òμ?bvr?aê???DD′′?¨"); + // tag_t bv = NULLTAG, bvr = NULLTAG, item_tag = NULLTAG; + // int bvCnt = 0; + // tag_t* bvTags = NULL; + + + // ITKCALL(ifail = ITEM_ask_item_of_rev(rev_tag, &item_tag)); + + + // tag_t tWindow = NULLTAG; + // ITKCALL(BOM_create_window(&tWindow)); + + // tag_t tTopLine = NULLTAG; + // ITKCALL(BOM_set_window_top_line(tWindow, item_tag, NULLTAG, NULLTAG, &tTopLine)); + + // //2é?ò?-BOMêóí? + // ITKCALL(ifail=ITEM_list_bom_views(item_tag, &bvCnt, &bvTags)); + // if (bvCnt > 0) { + // WriteLog(debug, "???óò?′??úBOMêóí?£o%d", bvCnt); + // bv = bvTags[0]; + // } + // ITKCALL(AOM_lock(item_tag)); + // if (bv == NULLTAG) { + // ITKCALL(ifail=PS_create_bom_view(NULLTAG, "", "", item_tag, &bv)); + // if (ifail != ITK_ok) { + // ITKCALL(AOM_unlock(item_tag)); + // return ifail; + // } + // ITKCALL(AOM_save(bv)); + // } + // ITKCALL(ifail=PS_create_bvr(bv, "", "", false, rev_tag, &bvr)); + // if (ifail != ITK_ok) { + // ITKCALL(AOM_unlock(item_tag)); + // return ifail; + // } + // ITKCALL(AOM_save(bvr)); + // ITKCALL(AOM_save(bv)); + // ITKCALL(AOM_save(item_tag)); + + // tag_t tChildLine = NULLTAG; + + // ITKCALL(BOM_save_window(tWindow)); + // ITKCALL(BOM_close_window(tWindow)); + + // ITKCALL(AOM_unlock(item_tag)); + // *bomBVR = bvr; + // *bomView = bv; + // WriteLog(debug, "bvrD??¨íê3é"); + // DOFREE(bvTags); + + //} + DOFREE(bvr_list); + return ifail; +} + +bool propExist(bool debug, tag_t obj, const char* propName) { + tag_t clTag = NULLTAG, * superClass = NULL; + char* clName = NULL; + int ifail = ITK_ok, cnt = 0; + logical exists = false; + ITKCALL(ifail = POM_class_of_instance(obj, &clTag)); + if (ifail != ITK_ok) { return false; } + ITKCALL(ifail = POM_name_of_class(clTag, &clName)); + if (ifail != ITK_ok) { return false; } + WriteLog(debug, ">> [%s] Check Property: %s", clName, propName); + ITKCALL(ifail = POM_attr_exists(propName, clName, &exists)); + if (ifail != ITK_ok) { return false; } + DOFREE(clName); + if (exists) { + //WriteLog(debug,"ê?D?′??ú"); + return exists; + } + ITKCALL(ifail = POM_superclasses_of_class(clTag, &cnt, &superClass)); + for (int i = 0;i < cnt;i++) { + ITKCALL(ifail = POM_name_of_class(superClass[i], &clName)); + if (ifail != ITK_ok) { return false; } + WriteLog(debug, ">> [%s] Check Property: %s", clName, propName); + ITKCALL(ifail = POM_attr_exists(propName, clName, &exists)); + DOFREE(clName); + if (exists) { + //WriteLog(debug, "ê?D?′??ú"); + return exists; + } + } + WriteLog(debug, "Property not exist"); + return exists; +} + + +char* G2U(const char* gb2312) +{ + int len = MultiByteToWideChar(CP_ACP, 0, gb2312, -1, NULL, 0); + wchar_t* wstr = new wchar_t[len + 1]; + memset(wstr, 0, len + 1); + MultiByteToWideChar(CP_ACP, 0, gb2312, -1, wstr, len); + len = WideCharToMultiByte(CP_UTF8, 0, wstr, -1, NULL, 0, NULL, NULL); + char* str = new char[len + 1]; + memset(str, 0, len + 1); + WideCharToMultiByte(CP_UTF8, 0, wstr, -1, str, len, NULL, NULL); + if (wstr) delete[] wstr; + return str; +} + +int getPrefStrings(const char* preference, TC_preference_search_scope_t scope, vector& pref_vec) +{ + int ifail = ITK_ok, i = 0, j = 0, k = 0, num = 0; + char** values; + //TC_preference_search_scope_t old_scope; + //ITKCALL(ifail = PREF_ask_search_scope(&old_scope)); + //ITKCALL(ifail = PREF_set_search_scope(scope)); + //ITKCALL(ifail = PREF_ask_char_values(preference, &num, &values)); + ITKCALL(ifail = PREF_ask_char_values_at_location(preference, scope, &num, &values)); + if (ifail != ITK_ok) { + return ifail; + } + for (i = 0; i < num; i++) + { + pref_vec.push_back(values[i]); + } + DOFREE(values); + //ITKCALL(ifail = PREF_set_search_scope(old_scope)); + return ifail; +} + +int getPrefStrings2(const char* preference, TC_preference_search_scope_t scope, char splitter, vector& pref_vec) +{ + int ifail = ITK_ok, i = 0, j = 0, k = 0, num = 0; + char** values; + TC_preference_search_scope_t old_scope; + //ITKCALL(ifail = PREF_ask_search_scope(&old_scope)); + //ITKCALL(ifail = PREF_set_search_scope(scope)); + //ITKCALL(ifail = PREF_ask_char_values(preference, &num, &values)); + ITKCALL(ifail = PREF_ask_char_values_at_location(preference, scope, &num, &values)); + if (ifail != ITK_ok) { + return ifail; + } + for (i = 0; i < num; i++) + { + vector split; + Split(values[i], splitter, split); + int size = split.size(); + for (j = 0;j < size;j++) { + pref_vec.push_back(split[j]); + } + /*for each (string val in split) { + pref_vec.push_back(val); + }*/ + } + DOFREE(values); + //ITKCALL(ifail = PREF_set_search_scope(old_scope)); + return ifail; +} + +//μ?3?êy?Y?ˉ???t +int export_dataset_file(bool debug, tag_t dataset, const char* ref_name, const char* ext, char** filename, char** original_name) +{ + int ifail = ITK_ok; + tag_t ref_object = NULLTAG, + datasettype = NULLTAG, + new_ds = NULLTAG, + tool = NULLTAG, + folder_tag = NULLTAG, + spec_dataset_rev = NULLTAG; + AE_reference_type_t reference_type; + tag_t new_file_tag = NULLTAG; + IMF_file_t file_descriptor; + char* target_ds_name = NULL; + char* new_file_name; + WSOM_ask_name2(dataset, &target_ds_name); + WriteLog(debug, "Download file from dataset %s", target_ds_name); + DOFREE(target_ds_name); + *filename = (char*)MEM_alloc(sizeof(char) * 512); + *original_name = (char*)MEM_alloc(sizeof(char) * 512); + strcpy(*filename, ""); + AE_ask_dataset_latest_rev(dataset, &spec_dataset_rev); + AE_ask_dataset_named_ref2(dataset, ref_name, &reference_type, &ref_object); + if (ref_object == NULLTAG) + { + WriteLog(debug, "File ref not exist"); + return 1; + } + if (reference_type == AE_PART_OF) + { + char* pathname2 = NULL; + IMF_ask_file_pathname2(ref_object, SS_WNT_MACHINE, &pathname2); + DOFREE(pathname2); + char* origin_file_name2 = NULL; + IMF_ask_original_file_name2(ref_object, &origin_file_name2); + strcpy(*original_name, origin_file_name2); + DOFREE(origin_file_name2); + char new_ds_name[WSO_name_size_c + 1] = ""; + char* new_file_name = USER_new_file_name(new_ds_name, ref_name, ext, 0); + char* temp_dir = getenv("TEMP"); + char temp_file[SS_MAXPATHLEN] = ""; + strcpy(temp_file, temp_dir); + //strcat(temp_file, "\\tc_"); + //strcat(temp_file, userId); + strcat(temp_file, "\\"); + strcat(temp_file, new_file_name); + WriteLog(debug, "Temp path: %s", temp_file); + if ((_access(temp_file, 0)) != -1) { + if (!remove(temp_file)) { + remove(temp_file); + } + } + IMF_export_file(ref_object, temp_file); + strcpy(*filename, temp_file); + return ITK_ok; + } + return -1; +} \ No newline at end of file diff --git a/qf_nx_itk-master (3)/qf_nx_itk/Connor_NX/kutil.h b/qf_nx_itk-master (3)/qf_nx_itk/Connor_NX/kutil.h new file mode 100644 index 0000000..391127f --- /dev/null +++ b/qf_nx_itk-master (3)/qf_nx_itk/Connor_NX/kutil.h @@ -0,0 +1,88 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +// #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + + +#ifdef WIN32 +#include +#include +#else +#include +#endif + +#define DOFREE(obj) \ +{ \ + if(obj) \ + { \ + MEM_free(obj); \ + obj = NULL; \ + } \ +} + +extern "C" int POM_AM__set_application_bypass(logical bypass); + +using namespace std; + +void WriteLog(logical debug, const char* format, ...); +void set_bypass(logical bypass); +char* G2U(const char* gb2312); +int getPrefStrings(const char* preference, TC_preference_search_scope_t scope, vector& pref_vec); +int export_dataset_file(bool debug, tag_t dataset, const char* ref_name, const char* ext, char** filename, char** original_name); +int GetBomView(tag_t rev_tag, const char* viewtype, tag_t* bomView, tag_t* bomBVR, bool debug); +int GetBomLinePropString(bool debug, tag_t line, char* propName, int errCode, char** attr_val); +void Split(string strArg, char spliter, vector& ans); +void Split(string strArg, string spliter, vector& ans); +int getPrefStrings2(const char* preference, TC_preference_search_scope_t scope, char splitter, vector& pref_vec); +int import_dataset_file(tag_t dataset, const char* ref_name, char* ext, char* fullfilename, char* original_name); +int import_dataset_file_binary(tag_t dataset, const char* ref_name, char* ext, char* fullfilename, char* original_name); +int readError(bool debug, char* errFilePath, int errCode); +void deleteFile(bool debug, char* path); +bool CheckType(string config, char* type, char spliter); +bool propExist(bool debug, tag_t obj, const char* propName); +bool isRev(char* object_type); +int GetProcessTargets(bool debug, int att_cnt, tag_t* attachments, vector& targets, char* formType, char splitter); +bool inArray(vector types, string type); +int getIndexInArray(vector types, string type); +int findUser(bool debug, string userStr, tag_t* user_tag); +bool isType(tag_t item, char* type); +void initUserDir(char* userId); +int CreateUserFile(logical debug, const char* FunctionName, char* userId, char** fullname, FILE** file); +int WriteToFile(logical debug, FILE* file, const char* format, ...); \ No newline at end of file diff --git a/qf_nx_itk-master (3)/qf_nx_itk/Connor_NX/origin_PropNames.h b/qf_nx_itk-master (3)/qf_nx_itk/Connor_NX/origin_PropNames.h new file mode 100644 index 0000000..2919b6b --- /dev/null +++ b/qf_nx_itk-master (3)/qf_nx_itk/Connor_NX/origin_PropNames.h @@ -0,0 +1,169 @@ +// cd9_TreeAndListCodeNode + +#define TreeAndListCodeNode_uid "uid" // Integer 节点序号 + +#define TreeAndListCodeNode_isContainsChildren "isContainsChildren" // Integer 节点序号 +#define TreeAndListCodeNode_node_index "cd9_node_index" // Integer 节点序号 +#define TreeAndListCodeNode_node_type "cd9_node_type"// String 节点名称 +#define TreeAndListCodeNode_node_name "cd9_node_name"// String 节点名称 +#define TreeAndListCodeNode_node_value "cd9_node_value" // String 节点值 +#define TreeAndListCodeNode_node_desc "cd9_node_desc" // String 节点描述 +#define TreeAndListCodeNode_is_root "cd9_is_root"// boolean 是否是根节点 +#define TreeAndListCodeNode_code_style "cd9_code_style" // String 编码格式 +#define TreeAndListCodeNode_code_length "cd9_code_length" // int 编码长度 +#define TreeAndListCodeNode_rule_node "cd9_rule_node" // String 编码格式 +#define TreeAndListCodeNode_reference_nodes "cd9_reference_nodes" // 引用的节点 + +#define TreeAndListCodeNode_is_lock "cd9_is_lock"// boolean 是否锁定 +#define TreeAndListCodeNode_create_date "cd9_create_date"// Date 创建日期 +#define TreeAndListCodeNode_last_revise_date "cd9_last_revise_date"// Date 最后修改日期 +#define TreeAndListCodeNode_create_user "cd9_create_user"// TypeReference 创建者 +#define TreeAndListCodeNode_last_revise_user "cd9_last_revise_user"// TypeReference 最后修改者 + +#define TreeAndListCodeNode_seq_begin_value "cd9_seq_begin_value" // Integer 流水码初始值 +#define TreeAndListCodeNode_seq_max_value "cd9_seq_max_value" // Integer 流水码最大值 +#define TreeAndListCodeNode_seq_length "cd9_seq_length" // Integer 流水码长度 +#define TreeAndListCodeNode_isDefaultSelected "cd9_isDefaultSelected" // boolean是否默认选中 +#define TreeAndListCodeNode_icsID "cd9_icsID" //对应的分类ID + +// Cd9_CodeRelation +#define CodeRelation_parent_nodes "cd9_parent_nodes" // TypeReference 父节点 +#define CodeRelation_current_node "cd9_current_node" // TypeReference 当前节点 +#define CodeRelation_children_nodes "cd9_children_nodes" // TypeReference 子节点 +#define CodeRelation_create_date "cd9_create_date"// Date 创建日期 +#define CodeRelation_create_user "cd9_create_user"// TypeReference 创建者 + +// Cd9_ClassificationCodeNode +#define ClassificationCodeNode_node_index "cd9_node_index" // Integer 节点序号 +#define ClassificationCodeNode_node_name "cd9_node_name"// String 节点名称 +#define ClassificationCodeNode_segment "cd9_segment"// String 所含码段 +#define ClassificationCodeNode_create_date "cd9_create_date"// Date 创建日期 +#define ClassificationCodeNode_last_revise_date "cd9_last_revise_date"// Date 最后修改日期 +#define ClassificationCodeNode_create_user "cd9_create_user"// TypeReference 创建者 +#define ClassificationCodeNode_last_revise_user "cd9_last_revise_user"// TypeReference 最后修改者 +#define ClassificationCodeNode_grant_users "cd9_grant_users"// TypeReference 授权用户 +#define ClassificationCodeNode_grant_roles "cd9_grant_roles"// TypeReference 授权角色 +#define ClassificationCodeNode_grant_groups "cd9_grant_groups"// TypeReference 授权组 + +// Cd9_CodeSequence +#define CodeSequence_seq_node_index "cd9_seq_node_index" // string 流水码码段名称 +#define CodeSequence_seq_node_name "cd9_seq_node_name" // Integer 流水码初始值 +#define CodeSequence_seq_begin_value "cd9_seq_begin_value" // Integer 流水码初始值 +#define CodeSequence_seq_max_value "cd9_seq_max_value" // Integer 流水码最大值 +#define CodeSequence_seq_length "cd9_seq_length" // Integer 流水码长度 +#define CodeSequence_seq_step "cd9_seq_step" // Integer 流水码步长 +#define CodeSequence_seq_exclude_num "cd9_seq_exclude_num" // String 流水码不包含数字 +#define CodeSequence_is_lock "cd9_is_lock"// boolean 是否锁定 +#define CodeSequence_create_date "cd9_create_date"// Date 创建日期 +#define CodeSequence_last_revise_date "cd9_last_revise_date"// Date 最后修改日期 +#define CodeSequence_create_user "cd9_create_user"// TypeReference 创建者 +#define CodeSequence_last_revise_user "cd9_last_revise_user"// TypeReference 最后修改者 + +// Cd9_CodeCounter +#define CodeCounter_index "cd9_index" +#define CodeCounter_name "cd9_name" +#define CodeCounter_recycleID "cd9_recycleID" +#define CodeCounter_isUsed "cd9_isUsed" +#define CodeCounter_createDate "cd9_createDate" +#define CodeCounter_createUser "cd9_createUser" +#define CodeCounter_last_revise_date "cd9_last_revise_date"// Date 最后修改日期 +#define CodeCounter_last_revise_user "cd9_last_revise_user" + +// Item +#define Item_codeDesc "cd9_codeDesc" +#define Item_codePattern "cd9_codePattern" +#define Item_codeID "cd9_codeID" +#define Item_codeRuleName "cd9_codeRuleName" + + + + + + + + +// cd9_TreeAndListCodeNode + +#define TreeAndListCodeNode_uid "uid" // Integer 节点序号 + +#define TreeAndListCodeNode_isContainsChildren "isContainsChildren" // Integer 节点序号 +#define TreeAndListCodeNode_node_index "cd9_node_index" // Integer 节点序号 +#define TreeAndListCodeNode_node_type "cd9_node_type"// String 节点名称 +#define TreeAndListCodeNode_node_name "cd9_node_name"// String 节点名称 +#define TreeAndListCodeNode_node_value "cd9_node_value" // String 节点值 +#define TreeAndListCodeNode_node_desc "cd9_node_desc" // String 节点描述 +#define TreeAndListCodeNode_is_root "cd9_is_root"// boolean 是否是根节点 +#define TreeAndListCodeNode_code_style "cd9_code_style" // String 编码格式 +#define TreeAndListCodeNode_code_length "cd9_code_length" // int 编码长度 +#define TreeAndListCodeNode_rule_node "cd9_rule_node" // String 编码格式 +#define TreeAndListCodeNode_reference_nodes "cd9_reference_nodes" // 引用的节点 + +#define TreeAndListCodeNode_is_lock "cd9_is_lock"// boolean 是否锁定 +#define TreeAndListCodeNode_create_date "cd9_create_date"// Date 创建日期 +#define TreeAndListCodeNode_last_revise_date "cd9_last_revise_date"// Date 最后修改日期 +#define TreeAndListCodeNode_create_user "cd9_create_user"// TypeReference 创建者 +#define TreeAndListCodeNode_last_revise_user "cd9_last_revise_user"// TypeReference 最后修改者 + +#define TreeAndListCodeNode_seq_begin_value "cd9_seq_begin_value" // Integer 流水码初始值 +#define TreeAndListCodeNode_seq_max_value "cd9_seq_max_value" // Integer 流水码最大值 +#define TreeAndListCodeNode_seq_length "cd9_seq_length" // Integer 流水码长度 +#define TreeAndListCodeNode_isDefaultSelected "cd9_isDefaultSelected" // boolean是否默认选中 +#define TreeAndListCodeNode_icsID "cd9_icsID" //对应的分类ID + +// Cd9_CodeRelation +#define CodeRelation_parent_nodes "cd9_parent_nodes" // TypeReference 父节点 +#define CodeRelation_current_node "cd9_current_node" // TypeReference 当前节点 +#define CodeRelation_children_nodes "cd9_children_nodes" // TypeReference 子节点 +#define CodeRelation_create_date "cd9_create_date"// Date 创建日期 +#define CodeRelation_create_user "cd9_create_user"// TypeReference 创建者 + +// Cd9_ClassificationCodeNode +#define ClassificationCodeNode_node_index "cd9_node_index" // Integer 节点序号 +#define ClassificationCodeNode_node_name "cd9_node_name"// String 节点名称 +#define ClassificationCodeNode_segment "cd9_segment"// String 所含码段 +#define ClassificationCodeNode_create_date "cd9_create_date"// Date 创建日期 +#define ClassificationCodeNode_last_revise_date "cd9_last_revise_date"// Date 最后修改日期 +#define ClassificationCodeNode_create_user "cd9_create_user"// TypeReference 创建者 +#define ClassificationCodeNode_last_revise_user "cd9_last_revise_user"// TypeReference 最后修改者 +#define ClassificationCodeNode_grant_users "cd9_grant_users"// TypeReference 授权用户 +#define ClassificationCodeNode_grant_roles "cd9_grant_roles"// TypeReference 授权角色 +#define ClassificationCodeNode_grant_groups "cd9_grant_groups"// TypeReference 授权组 + +// Cd9_CodeSequence +#define CodeSequence_seq_node_index "cd9_seq_node_index" // string 流水码码段名称 +#define CodeSequence_seq_node_name "cd9_seq_node_name" // Integer 流水码初始值 +#define CodeSequence_seq_begin_value "cd9_seq_begin_value" // Integer 流水码初始值 +#define CodeSequence_seq_max_value "cd9_seq_max_value" // Integer 流水码最大值 +#define CodeSequence_seq_length "cd9_seq_length" // Integer 流水码长度 +#define CodeSequence_seq_step "cd9_seq_step" // Integer 流水码步长 +#define CodeSequence_seq_exclude_num "cd9_seq_exclude_num" // String 流水码不包含数字 +#define CodeSequence_is_lock "cd9_is_lock"// boolean 是否锁定 +#define CodeSequence_create_date "cd9_create_date"// Date 创建日期 +#define CodeSequence_last_revise_date "cd9_last_revise_date"// Date 最后修改日期 +#define CodeSequence_create_user "cd9_create_user"// TypeReference 创建者 +#define CodeSequence_last_revise_user "cd9_last_revise_user"// TypeReference 最后修改者 + +// Cd9_CodeCounter +#define CodeCounter_index "cd9_index" +#define CodeCounter_name "cd9_name" +#define CodeCounter_recycleID "cd9_recycleID" +#define CodeCounter_isUsed "cd9_isUsed" +#define CodeCounter_createDate "cd9_createDate" +#define CodeCounter_createUser "cd9_createUser" +#define CodeCounter_last_revise_date "cd9_last_revise_date"// Date 最后修改日期 +#define CodeCounter_last_revise_user "cd9_last_revise_user" + +// Item +#define Item_codeDesc "cd9_codeDesc" +#define Item_codePattern "cd9_codePattern" +#define Item_codeID "cd9_codeID" +#define Item_codeRuleName "cd9_codeRuleName" + + + + + + + + +#pragma once diff --git a/qf_nx_itk-master (3)/qf_nx_itk/README.MD b/qf_nx_itk-master (3)/qf_nx_itk/README.MD new file mode 100644 index 0000000..1f6bce5 --- /dev/null +++ b/qf_nx_itk-master (3)/qf_nx_itk/README.MD @@ -0,0 +1,18 @@ +## 1. 规则处理程序:CONNOR-check-owner + +功能:仅对象所有者可以发起流程 + +```text +参数: +-alert: 提示的内容 +``` + +## 2. 规则处理程序:CONNOR-check-release + +功能:检查目标下的所有版本类型下的关系中,特定类型对象是否发布 + +```text +参数: +-alert: 提示的内容 +-check: 关系和检查类型,格式“关系1=类型1;类型2|关系2=类型3;类型4;类型5|关系3=类型6” +``` diff --git a/qf_nx_itk-master (3)/qf_nx_itk/connor_nx_itk.sln b/qf_nx_itk-master (3)/qf_nx_itk/connor_nx_itk.sln new file mode 100644 index 0000000..c38357e --- /dev/null +++ b/qf_nx_itk-master (3)/qf_nx_itk/connor_nx_itk.sln @@ -0,0 +1,31 @@ +锘 +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30002.166 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "NX12_Connor_ITK_QF", "Connor_NX\Connor_NX.vcxproj", "{B66C17FA-78C8-443E-8239-6E8744560AD7}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {B66C17FA-78C8-443E-8239-6E8744560AD7}.Debug|x64.ActiveCfg = Release|x64 + {B66C17FA-78C8-443E-8239-6E8744560AD7}.Debug|x64.Build.0 = Release|x64 + {B66C17FA-78C8-443E-8239-6E8744560AD7}.Debug|x86.ActiveCfg = Debug|Win32 + {B66C17FA-78C8-443E-8239-6E8744560AD7}.Debug|x86.Build.0 = Debug|Win32 + {B66C17FA-78C8-443E-8239-6E8744560AD7}.Release|x64.ActiveCfg = Release|x64 + {B66C17FA-78C8-443E-8239-6E8744560AD7}.Release|x64.Build.0 = Release|x64 + {B66C17FA-78C8-443E-8239-6E8744560AD7}.Release|x86.ActiveCfg = Release|Win32 + {B66C17FA-78C8-443E-8239-6E8744560AD7}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {860AF573-225E-4004-AED7-10B6AE5AA6DE} + EndGlobalSection +EndGlobal diff --git a/qf_nx_java-master (1)/qf_nx_java/.classpath b/qf_nx_java-master (1)/qf_nx_java/.classpath new file mode 100644 index 0000000..e04d9f8 --- /dev/null +++ b/qf_nx_java-master (1)/qf_nx_java/.classpath @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/qf_nx_java-master (1)/qf_nx_java/.gitignore b/qf_nx_java-master (1)/qf_nx_java/.gitignore new file mode 100644 index 0000000..ae3c172 --- /dev/null +++ b/qf_nx_java-master (1)/qf_nx_java/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/qf_nx_java-master (1)/qf_nx_java/.project b/qf_nx_java-master (1)/qf_nx_java/.project new file mode 100644 index 0000000..6dd7105 --- /dev/null +++ b/qf_nx_java-master (1)/qf_nx_java/.project @@ -0,0 +1,18 @@ + + + NX_Connor_QF + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jem.workbench.JavaEMFNature + org.eclipse.jdt.core.javanature + + diff --git a/qf_nx_java-master (1)/qf_nx_java/.settings/org.eclipse.core.resources.prefs b/qf_nx_java-master (1)/qf_nx_java/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..f22b8c5 --- /dev/null +++ b/qf_nx_java-master (1)/qf_nx_java/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,10 @@ +eclipse.preferences.version=1 +encoding//src/org/tempuri/ErpWebService.java=UTF-8 +encoding//src/org/tempuri/ErpWebServiceLocator.java=UTF-8 +encoding//src/org/tempuri/ErpWebServiceSoap.java=UTF-8 +encoding//src/org/tempuri/ErpWebServiceSoapStub.java=UTF-8 +encoding//src/service/KWebService.java=UTF-8 +encoding//src/service/KWebServicePortBindingStub.java=UTF-8 +encoding//src/service/KWebServiceService.java=UTF-8 +encoding//src/service/KWebServiceServiceLocator.java=UTF-8 +encoding/TopDownDesignUI.dlx=UTF-8 diff --git a/qf_nx_java-master (1)/qf_nx_java/.settings/org.eclipse.jdt.core.prefs b/qf_nx_java-master (1)/qf_nx_java/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0fee6a9 --- /dev/null +++ b/qf_nx_java-master (1)/qf_nx_java/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,15 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning +org.eclipse.jdt.core.compiler.release=disabled +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/qf_nx_java-master (1)/qf_nx_java/README.MD b/qf_nx_java-master (1)/qf_nx_java/README.MD new file mode 100644 index 0000000..3e2afc1 --- /dev/null +++ b/qf_nx_java-master (1)/qf_nx_java/README.MD @@ -0,0 +1,102 @@ +# 一、NX集成配置 + +## 1. 安装 + +1. 解压文件 `ConnorNX.rar` 到NX安装目录%UGII_BASE_DIR%\ConnorNX` +2. 在NX安装目录找到文件%UGII_BASE_DIR%\UGII\menus\custom_dirs.dat` ,新增行%UGII_BASE_DIR%\ConnorNX` +3. 将文件 connor_nx_itk.dll 拷贝到TC目录`$TC_ROOT\bin`,并修改首选项TC_customization_libraries,新增行`connor_nx_itk` + +## 2. 签名 + +需要对`Connor_NXOpen.jar`文件进行签名,使用CMD执行命令: + +```text +%UGII_BASE_DIR%\NXBIN\SignJar.bat %UGII_BASE_DIR%\ConnorNX\Application\Connor_NXOpen.jar +``` + +## 3. NX 目录配置 + +`%UGII_BASE_DIR%\ConnorNX\Startup` 目录中包含两个文件`ConnorNX.men`和`ConnorNX.rtb` + +1. 在`ConnorNX.men`定义按钮 + + ```text + BUTTON 命令ID + LABEL 按钮文本 + ACTIONS Connor_NXOpen.jar + ``` + +2. 将按钮添加到`ConnorNX.rtb` + + ```text + BUTTON 命令ID + RIBBON_STYLE SMALL_IMAGE_AND_TEXT + ``` + +## 4. 命令ID + +**编码器:**`autocode` + +**模块化设计:**`top-down-design#首选项名称` + +> 模块化设计命令ID中首选项配置为多值、站点。 +> +> 1. 第一行填写模板对象ID。模板对象最新版本要求发布,版本下以“规范”关系添加图纸简图数据集,命名分别为“二维简图.bmp”和“三维简图.bmp” +> 2. 第二行开始配置图纸属性,格式“显示名称=属性名称[=下拉值1;下拉值2;下拉值3...]” +> +> 示例: +> +> ```text +> C3F000001138 +> 高度=gaodu=30;50;80;180 +> 导柱间距1=jj1=1700;1800;1900 +> 导柱间距2=jj2 +> 导柱直径=zj=80;90;100 +> 机架高度=gd +> ``` +> +> 配置首选项:**Connor_NXBomClone**,多值,站点 +> +> 格式: +> +> ```text +> 第一行:需要检查的版本属性名称 +> 第二行:需要检查的版本属性值,匹配时进行克隆操作 +> 第三行:模板版本下规范关系的三维数据集名称 +> 第四行:模板版本下规范关系的二维数据集名称 +> 第五行:固定内容,表示申请新编码的输入参数 “&;&6&;&1&;&999999&;&1&;&”。配置释义“&;&编码长度&;&起始流水&;&最大流水&;&步长&;&exclude” +> ``` +> +> 示例: +> +> ```text +> object_desc +> 是 +> 三维简图.bmp +> 二维简图.bmp +> &;&6&;&1&;&999999&;&1&;& +> ``` + +# 二、NX签名配置 + +## 1. 安装 + +1. 解压`NX签名.rar`文件到目录`%UGII_BASE_DIR%\NXBIN` +2. 将文件 connor_nx_itk.dll 拷贝到TC目录`$TC_ROOT\bin`,并修改首选项TC_customization_libraries,新增行`connor_nx_itk` + +## 2. 签名 + +需要对`NX12_Open_CS_Wizard1.exe`文件进行签名,使用CMD执行命令: + +```text +%UGII_BASE_DIR%\NXBIN\SignDotNet.exe %UGII_BASE_DIR%\NXBIN\NX12_Open_CS_Wizard1.exe +``` + +## 3. 首选项 + + 配置首选项:**Connor_Sign_NX_EXE_Path**,单值,站点。 + +值填写`NX12_Open_CS_Wizard1.exe`文件路径 + +示例:`%UGII_BASE_DIR%\NXBIN\NX12_Open_CS_Wizard1.exe` + diff --git a/qf_nx_java-master (1)/qf_nx_java/README澶囦唤.MD b/qf_nx_java-master (1)/qf_nx_java/README澶囦唤.MD new file mode 100644 index 0000000..0ee1110 --- /dev/null +++ b/qf_nx_java-master (1)/qf_nx_java/README澶囦唤.MD @@ -0,0 +1,77 @@ +注:以下配置中,中括号表示选配内容,配置时不要带中括号 + +# 集成配置 + +1. 修改文件“NX安装目录\UGII\menus\custom_dirs.dat” ,新增行“$UGII_BASE_DIR\ConnorNX” + +2. 解压集成文件到NX安装目录 + +# NXOPEN命令参数 + +输入操作参数格式: + +```text +命令ID +参数1 +参数2 +... +``` + +## 编码器 + +命令ID:“autocode” + +## Top-Down Design + +命令ID 1:"top-down-design" 界面使用javafx绘制,任何时间都可以使用 + +命令ID 2:"top-down-design-nx" 界面使用nx block styler绘制,需要“TopDownDesignUI.dlx”,只有在工作部件打开时可以正常打开 + +参数: +1. 首选项名称,写在第二行 + +示例: + +```text +top-down design +01 +``` + +首选项格式: + +1. 第一行填写模板对象ID。模板对象最新版本要求发布,版本下以“规范”关系添加图纸简图数据集,命名分别为“二维简图.bmp”和“三维简图.bmp” + +2. 第二行开始配置图纸属性,格式“显示名称=属性名称[=下拉值1;下拉值2;下拉值3...]”。"top-down design nx"命令最多支持配置21个属性,如需更多可修改TopDownDesignUI.dlx文件 + +示例: + +```text +C3F000001138 +高度=gaodu=30;50;80;180 +导柱间距1=jj1=1700;1800;1900 +导柱间距2=jj2 +导柱直径=zj=80;90;100 +机架高度=gd +``` + +配置首选项:Connor_NXBomClone,多值,站点 + +格式: + +```text +第一行:需要检查的版本属性名称 +第二行:需要检查的版本属性值,匹配时进行克隆操作 +第三行:三维数据集名称 +第四行:二维数据集名称 +第五行:固定内容,表示申请新编码的输入参数 “&;&6&;&1&;&999999&;&1&;&”。配置释义“&;&编码长度&;&起始流水&;&最大流水&;&步长&;&exclude” +``` + +示例: + +```text +object_desc +clone +三维简图.bmp +二维简图.bmp +&;&6&;&1&;&999999&;&1&;& +``` \ No newline at end of file diff --git a/qf_nx_java-master (1)/qf_nx_java/TopDownDesignUI.dlx b/qf_nx_java-master (1)/qf_nx_java/TopDownDesignUI.dlx new file mode 100644 index 0000000..9cc264f --- /dev/null +++ b/qf_nx_java-master (1)/qf_nx_java/TopDownDesignUI.dlx @@ -0,0 +1,4 @@ + + + + diff --git a/qf_nx_java-master (1)/qf_nx_java/jsonlib/commons-beanutils-1.7.0.jar b/qf_nx_java-master (1)/qf_nx_java/jsonlib/commons-beanutils-1.7.0.jar new file mode 100644 index 0000000..b1b89c9 Binary files /dev/null and b/qf_nx_java-master (1)/qf_nx_java/jsonlib/commons-beanutils-1.7.0.jar differ diff --git a/qf_nx_java-master (1)/qf_nx_java/jsonlib/commons-collections-3.2.jar b/qf_nx_java-master (1)/qf_nx_java/jsonlib/commons-collections-3.2.jar new file mode 100644 index 0000000..75580be Binary files /dev/null and b/qf_nx_java-master (1)/qf_nx_java/jsonlib/commons-collections-3.2.jar differ diff --git a/qf_nx_java-master (1)/qf_nx_java/jsonlib/commons-lang-2.4.jar b/qf_nx_java-master (1)/qf_nx_java/jsonlib/commons-lang-2.4.jar new file mode 100644 index 0000000..532939e Binary files /dev/null and b/qf_nx_java-master (1)/qf_nx_java/jsonlib/commons-lang-2.4.jar differ diff --git a/qf_nx_java-master (1)/qf_nx_java/jsonlib/commons-logging-1.1.jar b/qf_nx_java-master (1)/qf_nx_java/jsonlib/commons-logging-1.1.jar new file mode 100644 index 0000000..2ff9bbd Binary files /dev/null and b/qf_nx_java-master (1)/qf_nx_java/jsonlib/commons-logging-1.1.jar differ diff --git a/qf_nx_java-master (1)/qf_nx_java/jsonlib/ezmorph-1.0.4.jar b/qf_nx_java-master (1)/qf_nx_java/jsonlib/ezmorph-1.0.4.jar new file mode 100644 index 0000000..7625af6 Binary files /dev/null and b/qf_nx_java-master (1)/qf_nx_java/jsonlib/ezmorph-1.0.4.jar differ diff --git a/qf_nx_java-master (1)/qf_nx_java/jsonlib/javax.wsdl_1.6.2.v201012040545.jar b/qf_nx_java-master (1)/qf_nx_java/jsonlib/javax.wsdl_1.6.2.v201012040545.jar new file mode 100644 index 0000000..662bd7b Binary files /dev/null and b/qf_nx_java-master (1)/qf_nx_java/jsonlib/javax.wsdl_1.6.2.v201012040545.jar differ diff --git a/qf_nx_java-master (1)/qf_nx_java/jsonlib/jdom.jar b/qf_nx_java-master (1)/qf_nx_java/jsonlib/jdom.jar new file mode 100644 index 0000000..65a1b3f Binary files /dev/null and b/qf_nx_java-master (1)/qf_nx_java/jsonlib/jdom.jar differ diff --git a/qf_nx_java-master (1)/qf_nx_java/jsonlib/json-lib-2.2.2-jdk15.jar b/qf_nx_java-master (1)/qf_nx_java/jsonlib/json-lib-2.2.2-jdk15.jar new file mode 100644 index 0000000..27e7c7c Binary files /dev/null and b/qf_nx_java-master (1)/qf_nx_java/jsonlib/json-lib-2.2.2-jdk15.jar differ diff --git a/qf_nx_java-master (1)/qf_nx_java/jsonlib/json-lib-2.2.3-jdk13.jar b/qf_nx_java-master (1)/qf_nx_java/jsonlib/json-lib-2.2.3-jdk13.jar new file mode 100644 index 0000000..a6513db Binary files /dev/null and b/qf_nx_java-master (1)/qf_nx_java/jsonlib/json-lib-2.2.3-jdk13.jar differ diff --git a/qf_nx_java-master (1)/qf_nx_java/lib/NXOpen.jar b/qf_nx_java-master (1)/qf_nx_java/lib/NXOpen.jar new file mode 100644 index 0000000..eb4f093 Binary files /dev/null and b/qf_nx_java-master (1)/qf_nx_java/lib/NXOpen.jar differ diff --git a/qf_nx_java-master (1)/qf_nx_java/lib/NXOpenUF.jar b/qf_nx_java-master (1)/qf_nx_java/lib/NXOpenUF.jar new file mode 100644 index 0000000..9d950c3 Binary files /dev/null and b/qf_nx_java-master (1)/qf_nx_java/lib/NXOpenUF.jar differ diff --git a/qf_nx_java-master (1)/qf_nx_java/lib/NXOpenUI.jar b/qf_nx_java-master (1)/qf_nx_java/lib/NXOpenUI.jar new file mode 100644 index 0000000..81f8c10 Binary files /dev/null and b/qf_nx_java-master (1)/qf_nx_java/lib/NXOpenUI.jar differ diff --git a/qf_nx_java-master (1)/qf_nx_java/lib/axis.jar b/qf_nx_java-master (1)/qf_nx_java/lib/axis.jar new file mode 100644 index 0000000..20b09a5 Binary files /dev/null and b/qf_nx_java-master (1)/qf_nx_java/lib/axis.jar differ diff --git a/qf_nx_java-master (1)/qf_nx_java/lib/commons-discovery-0.2.jar b/qf_nx_java-master (1)/qf_nx_java/lib/commons-discovery-0.2.jar new file mode 100644 index 0000000..b885548 Binary files /dev/null and b/qf_nx_java-master (1)/qf_nx_java/lib/commons-discovery-0.2.jar differ diff --git a/qf_nx_java-master (1)/qf_nx_java/lib/commons-io-2.6.jar b/qf_nx_java-master (1)/qf_nx_java/lib/commons-io-2.6.jar new file mode 100644 index 0000000..00556b1 Binary files /dev/null and b/qf_nx_java-master (1)/qf_nx_java/lib/commons-io-2.6.jar differ diff --git a/qf_nx_java-master (1)/qf_nx_java/lib/jaxrpc.jar b/qf_nx_java-master (1)/qf_nx_java/lib/jaxrpc.jar new file mode 100644 index 0000000..a2c13d9 Binary files /dev/null and b/qf_nx_java-master (1)/qf_nx_java/lib/jaxrpc.jar differ diff --git a/qf_nx_java-master (1)/qf_nx_java/lib/jfxrt.jar b/qf_nx_java-master (1)/qf_nx_java/lib/jfxrt.jar new file mode 100644 index 0000000..49b7d90 Binary files /dev/null and b/qf_nx_java-master (1)/qf_nx_java/lib/jfxrt.jar differ diff --git a/qf_nx_java-master (1)/qf_nx_java/lib/jfxswt.jar b/qf_nx_java-master (1)/qf_nx_java/lib/jfxswt.jar new file mode 100644 index 0000000..4679ef7 Binary files /dev/null and b/qf_nx_java-master (1)/qf_nx_java/lib/jfxswt.jar differ diff --git a/qf_nx_java-master (1)/qf_nx_java/lib/org.apache.commons.logging_1.2.0.v20180409-1502.jar b/qf_nx_java-master (1)/qf_nx_java/lib/org.apache.commons.logging_1.2.0.v20180409-1502.jar new file mode 100644 index 0000000..620d4cb Binary files /dev/null and b/qf_nx_java-master (1)/qf_nx_java/lib/org.apache.commons.logging_1.2.0.v20180409-1502.jar differ diff --git a/qf_nx_java-master (1)/qf_nx_java/lib/saaj.jar b/qf_nx_java-master (1)/qf_nx_java/lib/saaj.jar new file mode 100644 index 0000000..4ea696e Binary files /dev/null and b/qf_nx_java-master (1)/qf_nx_java/lib/saaj.jar differ diff --git a/qf_nx_java-master (1)/qf_nx_java/nx12lib/NXOpen.jar b/qf_nx_java-master (1)/qf_nx_java/nx12lib/NXOpen.jar new file mode 100644 index 0000000..b6de187 Binary files /dev/null and b/qf_nx_java-master (1)/qf_nx_java/nx12lib/NXOpen.jar differ diff --git a/qf_nx_java-master (1)/qf_nx_java/nx12lib/NXOpenUF.jar b/qf_nx_java-master (1)/qf_nx_java/nx12lib/NXOpenUF.jar new file mode 100644 index 0000000..915bd73 Binary files /dev/null and b/qf_nx_java-master (1)/qf_nx_java/nx12lib/NXOpenUF.jar differ diff --git a/qf_nx_java-master (1)/qf_nx_java/nx12lib/NXOpenUI.jar b/qf_nx_java-master (1)/qf_nx_java/nx12lib/NXOpenUI.jar new file mode 100644 index 0000000..7690d60 Binary files /dev/null and b/qf_nx_java-master (1)/qf_nx_java/nx12lib/NXOpenUI.jar differ diff --git a/qf_nx_java-master (1)/qf_nx_java/src/nx_connor/KFXPanel.java b/qf_nx_java-master (1)/qf_nx_java/src/nx_connor/KFXPanel.java new file mode 100644 index 0000000..97ecff2 --- /dev/null +++ b/qf_nx_java-master (1)/qf_nx_java/src/nx_connor/KFXPanel.java @@ -0,0 +1,91 @@ +package nx_connor; + +import com.sun.javafx.util.Logging; + +import javafx.application.Application; +import javafx.application.Platform; +import javafx.fxml.FXMLLoader; +import javafx.scene.Parent; +import javafx.scene.Scene; +import javafx.scene.image.Image; +import javafx.stage.Stage; +import sun.util.logging.PlatformLogger.Level; + +public abstract class KFXPanel extends Application { + + static { + Platform.setImplicitExit(false); + Logging.getCSSLogger().setLevel(Level.OFF); + } + + public KFXPanel(Stage dialog) throws Exception { + setParentDialog(dialog); + initUI(); + } + + public KFXPanel(Stage dialog, Class c, String css) throws Exception { + setParentDialog(dialog); + this.cssForm = c.getResource(css).toExternalForm(); + initUI(); + } + + protected Scene scene; + protected Parent root; + protected String cssForm; + protected Stage parentDialog; + + public void setParentDialog(Stage dialog) { + this.parentDialog = dialog; + if(dialog!=null) { + dialog.getIcons().add(new Image(KMain.class.getResourceAsStream("teamcenter_app_128.gif"))); + } + } + + public Stage getParentDialog() { + return this.parentDialog; + } + + public Parent getRoot() { + return root; + } + + public Scene getScene() { + if (scene == null) { + scene = new Scene(root); + scene.setFill(null); + } + return scene; + } + + public abstract Object getController(); + + protected void initUI() throws Exception { + FXMLLoader fxmlLoader = new FXMLLoader(); + String resource = this.getClass().getSimpleName() + ".fxml"; + // System.out.println("Load Resource: "+resource); + fxmlLoader.setLocation(this.getClass().getResource(resource)); + fxmlLoader.setController(getController()); + root = fxmlLoader.load(); + // controller = fxmlLoader.getController(); + // primaryStage.initStyle(StageStyle.TRANSPARENT); + if (cssForm != null) { + root.getStylesheets().add(cssForm); + } + } + + @Override + public void start(Stage primaryStage) throws Exception { + initUI(); + primaryStage.setScene(getScene()); + primaryStage.show(); + } + + /** + * Run as javafx application to test ui + * + * @param args + */ +// public static void main(String[] args) { +// launch(args); +// } +} \ No newline at end of file diff --git a/qf_nx_java-master (1)/qf_nx_java/src/nx_connor/KMain.java b/qf_nx_java-master (1)/qf_nx_java/src/nx_connor/KMain.java new file mode 100644 index 0000000..84c86b9 --- /dev/null +++ b/qf_nx_java-master (1)/qf_nx_java/src/nx_connor/KMain.java @@ -0,0 +1,120 @@ +package nx_connor; + +import java.util.Arrays; + +import nx_connor.autcocode.AutoCode; +import nx_connor.bomcopy.BomCopy; +import nx_connor.bomcopy2.BomCopy2; +import nx_connor.util.KUtil; +import nxopen.NXException; +import nxopen.NXMessageBox.DialogType; +import nxopen.Session; +import nxopen.SessionFactory; +import nxopen.UFSession; +import nxopen.UI; + +public class KMain { + + public static Session theSession = null; + public static UI theUI = null; + public static UFSession theUFSession = null; + public static final String APP_PATH; + + public static final String SPLIT_SECTION = "&SECTION&"; + public static final String SPLIT_PROP_STR = "&PROP&"; + public static final String SPLIT_PROP_NAME_VALUE = "&=&"; + public static final String SPLITTER = "&;&"; + + public static final String COMMAND_TOP_DOWN_DESIGN_NX = "TOP-DOWN-DESIGN-NX"; + public static final String COMMAND_TOP_DOWN_DESIGN_FX = "TOP-DOWN-DESIGN"; + public static final String COMMAND_AUTOCODE = "AUTOCODE"; + public static final int INPUTCODE_GetPrefValue = 0; + public static final int INPUTCODE_Parse_NX_Template_By_ID = 1; + public static final int INPUTCODE_Read_NX_Image_By_ID = 2; + public static final int INPUTCODE_Download_Dataset_By_UID = 3; + public static final int INPUTCODE_GET_ALL_SUB_TYPES = 4; + public static final int INPUTCODE_SEARCH_AUTOCODE_NODE = 5; + public static final int INPUTCODE_GET_UID = 6; + public static final int INPUTCODE_SEARCH_AUTOCODE_SEGMENT = 7; + public static final int INPUTCODE_SEARCH_AUTOCODE_USER = 8; + public static final int INPUTCODE_GET_TREE_AND_LIST_STRING_VALUE = 9; + public static final int INPUTCODE_GET_NEW_REV_ID = 10; + public static final int INPUTCODE_GET_LOGICAL_PROP_VALUE = 11; + public static final int INPUTCODE_SEARCH_TREE_OR_LIST_NODE = 12; + public static final int INPUTCODE_GET_TREE_AND_LIST_STRING_VALUES = 13; + public static final int INPUTCODE_SEARCH_PARENT_TREE_OR_LIST_NODE = 14; + public static final int INPUTCODE_ICS_GET_ATTRIBUTES = 15; + // public static final int INPUTCODE_ICS_ATTR_IS_REFERENCE_ATTRIBUTE = 16; + public static final int INPUTCODE_ICS_ATTR_ASK_PROPERTY = 17; + public static final int INPUTCODE_ICS_ATTR_ASK_KEYLOV = 18; + public static final int INPUTCODE_GET_DISPLAY_PROP_VALUE = 19; + public static final int INPUTCODE_FIND_LOV_BY_NAME = 20; + public static final int INPUTCODE_GET_REFERENCE_PROP_VALUE = 21; + public static final int INPUTCODE_QUERY_PART_NO = 22; + public static final int INPUTCODE_DELETE_RECYCLE_ID = 23; + public static final int INPUTCODE_ITEM_EXIST = 24; + public static final int INPUTCODE_ITEM_CREATE = 25; + public static final int INPUTCODE_ADD_TO_NEWSTUFF = 26; + public static final int INPUTCODE_GET_CLASSIFICATION_ID = 27; + public static final int INPUTCODE_SEND_ITEM_TO_CLASSIFICATION = 28; + public static final int INPUTCODE_GET_ITEMTYPE_BY_ID = 29; + public static final int INPUTCODE_GET_REVUID_BY_ID = 30; + public static final int INPUTCODE_ITEM_UPDATE = 31; + public static final int INPUTCODE_READ_NX_TEMPLATE_BOM = 32; + public static final int INPUTCODE_GET_CLONE_INFO = 33; + public static final int INPUTCODE_GET_LATEST_ITEM_REVISION = 34; + public static final int INPUTCODE_GRANT_PRIVILEGE = 35; + public static final int INPUTCODE_GET_UOM_TAGS = 36; + public static final int INPUTCODE_UPDATE_UOM = 37; + public static final int INPUTCODE_GET_REFERENCE_PROP_VALUE_ARRAY = 38; + public static final int INPUTCODE_ICS_ATTR_ASK_METRIC_UNIT = 39; + + static { + //APP_PATH = KMain.class.getProtectionDomain().getCodeSource().getLocation().getPath(); + String path = KMain.class.getProtectionDomain().getCodeSource() + .getLocation().getPath(); + APP_PATH = path.substring(1, path.lastIndexOf('/')+1); + } + + public static void main(String[] args) throws NXException, java.rmi.RemoteException { + theSession = (Session) SessionFactory.get("Session"); + theUI = (UI) SessionFactory.get("UI"); + theUFSession = (UFSession) SessionFactory.get("UFSession"); + + KUtil.LOG("---------------------------------------------------------------------"); + KUtil.LOG("NX12_Connor"); + KUtil.LOG("Args: \n- "+Arrays.toString(args)); + KUtil.LOG("---------------------------------------------------------------------"); + int argCnt = args == null ? 0 : args.length; + if (argCnt == 0) { + return; + }else if(argCnt==1) { + args = args[0].split("#"); + } + String commandName = args[0].toUpperCase(); + try { + switch (commandName) { + case COMMAND_TOP_DOWN_DESIGN_NX: + BomCopy.copyFromTemplate(args, false); + break; + case COMMAND_TOP_DOWN_DESIGN_FX: + BomCopy2.copyFromTemplate(args); + break; + case COMMAND_AUTOCODE: + AutoCode.runAutoCode(args); + break; + default: + KUtil.LOG("Unknown Command: " + commandName); + break; + } + } + catch (Exception ex) { + KUtil.LOGERROR(ex); + theUI.nxmessageBox().show("错误", DialogType.ERROR, ex.getMessage()); + } + KUtil.LOG("---------------------------------------------------------------------"); + KUtil.LOG("NX12_Connor Complete"); + KUtil.LOG("---------------------------------------------------------------------"); + } + +} diff --git a/qf_nx_java-master (1)/qf_nx_java/src/nx_connor/autcocode/AutoCode.java b/qf_nx_java-master (1)/qf_nx_java/src/nx_connor/autcocode/AutoCode.java new file mode 100644 index 0000000..8ec3ee5 --- /dev/null +++ b/qf_nx_java-master (1)/qf_nx_java/src/nx_connor/autcocode/AutoCode.java @@ -0,0 +1,43 @@ +package nx_connor.autcocode; + +import javafx.application.Platform; +import javafx.embed.swing.JFXPanel; +import javafx.stage.Stage; +import nx_connor.util.KUtil; +import nxopen.NXMessageBox.DialogType; + +public class AutoCode { + + public static void runAutoCode(String[] args) throws Exception{ + new JFXPanel(); + Platform.runLater(()->{ + Stage stage = new Stage(); + stage.setTitle("编码器"); + try { + stage.setScene(new AutoCodeDialog(stage).getScene()); + stage.show(); + } catch (Exception e) { + e.printStackTrace(); + KUtil.LOGERROR(e); + KUtil.showNXMessage("错误", DialogType.ERROR, e.getMessage()); + } + }); +// JFrame frame = new JFrame("缂栫爜鍣"); +// JFXPanel panel = new JFXPanel(); +// panel.setScene(new AutoCodeDialog(frame).getScene()); +// frame.setContentPane(panel); +// frame.setSize(new Dimension(1200, 800)); +// frame.setLocationRelativeTo(null); +// frame.setAlwaysOnTop(true); +// frame.setVisible(true); + } + + public static void main(String[] args) { + try { + runAutoCode(args); + } catch (Exception e) { + e.printStackTrace(); + } + } + +} diff --git a/qf_nx_java-master (1)/qf_nx_java/src/nx_connor/autcocode/AutoCodeDialog.fxml b/qf_nx_java-master (1)/qf_nx_java/src/nx_connor/autcocode/AutoCodeDialog.fxml new file mode 100644 index 0000000..a605840 --- /dev/null +++ b/qf_nx_java-master (1)/qf_nx_java/src/nx_connor/autcocode/AutoCodeDialog.fxml @@ -0,0 +1,137 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +