NX二次开发:Checkmate例子根据dfa文件检查模型数据

  • Post category:C++

NX中的checkmate功能是用于检查模型、图纸数据的工具,在UGOPEN中有例子。手动操作可以检查已加载的装配下所有零部件,可以设置通过后保存模型,检查结果保存到Teamcenter中,默认保存在零组件版本下。

代码中可以设置多个检查规则。相关设置可以在用户默认设置中进行设置。

  1 //=============================
  2 // Checkmate例子
  3 //=============================
  4 // Mandatory UF Includes
  5 #include <uf.h>
  6 #include <uf_object_types.h>
  7 #include <uf_draw.h>
  8 #include <uf_part.h>
  9 #include <uf_ugmgr.h>
 10 #include <uf_ui.h>
 11 #include <uf_obj.h>
 12 #include <uf_drf.h>
 13 
 14 // Std C++ Includes
 15 #include <iostream>
 16 #include <sstream>
 17 #include <vector>
 18 #include <string>
 19 #include <algorithm>
 20 #include <tchar.h>
 21 #include <atlconv.h>
 22 #include <shellapi.h>
 23 
 24 // check mate
 25 #include <NXOpen/Validate_ValidationManager.hxx>
 26 #include <NXOpen/Validate_Validator.hxx>
 27 #include <NXOpen/Validate_ValidatorOptions.hxx>
 28 #include <NXOpen/Validate_Parser.hxx>
 29 
 30 #include <windows.h>
 31 #undef CreateDialog
 32 #pragma comment(lib,"shell32.lib")
 33 
 34 using namespace NXOpen;
 35 using std::string;
 36 using std::exception;
 37 using std::stringstream;
 38 using std::endl;
 39 using std::cout;
 40 using std::cerr;
 41 
 42 int ExecuteCheckerAndGetResults();
 43 
 44 extern "C" DllExport void ufusr( char *parm, int *returnCode, int rlen )
 45 {
 46     try
 47     {
 48         UF_CALL(UF_initialize());
 49 
 50         ExecuteCheckerAndGetResults();
 51 
 52         UF_CALL(UF_terminate());
 53     }
 54     catch (const NXException& e1)
 55     {
 56         UI::GetUI()->NXMessageBox()->Show("NXException", NXOpen::NXMessageBox::DialogTypeError, e1.Message());
 57     }
 58     catch (const exception& e2)
 59     {
 60         UI::GetUI()->NXMessageBox()->Show("Exception", NXOpen::NXMessageBox::DialogTypeError, e2.what());
 61     }
 62     catch (...)
 63     {
 64         UI::GetUI()->NXMessageBox()->Show("Exception", NXOpen::NXMessageBox::DialogTypeError, "Unknown Exception.");
 65     }
 66 }
 67 
 68 extern "C" DllExport int ufusr_ask_unload()
 69 {
 70     return (int)NXOpen::Session::LibraryUnloadOptionImmediately;// 调试用
 71     //return (int)NXOpen::Session::LibraryUnloadOptionAtTermination;// 程序发布用
 72     //return (int)NXOpen::Session::LibraryUnloadOptionExplicitly;
 73 }
 74 
 75 int ExecuteCheckerAndGetResults()
 76 { 
 77     // Get the NX session, work part, display part.
 78     Session *theSession = Session::GetSession();
 79     Part *workPart(theSession->Parts()->Work());
 80     Part *displayPart(theSession->Parts()->Display());
 81 
 82     // Get the NX Check-Mate Validator object.
 83     std::vector<Validate::Validator *> validators1;
 84     theSession->ValidationManager()->FindValidator("Check-Mate", validators1);
 85 
 86     // Get the NX Check-Mate ValidatorOptions, and set options.
 87     Validate::ValidatorOptions *validatorOptions1;
 88     validatorOptions1 = validators1[0]->ValidatorOptions();
 89 
 90     validatorOptions1->SetSkipChecking(false);
 91     validatorOptions1->SetSkipCheckingDontLoadPart(false);
 92     validatorOptions1->SetSaveResultInTeamcenter(Validate::ValidatorOptions::SaveModeTypesSaveIfPassed);
 93     validatorOptions1->SetSavePartFile(Validate::ValidatorOptions::SaveModeTypesSaveIfPassed);
 94     validatorOptions1->SetSaveResultInPart(false);
 95 
 96     // 2023_0328
 97     validatorOptions1->SetAutoDisplayResults(Validate::ValidatorOptions::ResultsDisplayModeTypesAlwaysDisplay);
 98     validatorOptions1->SetExcludeNonOwnerParts(true);
 99     validatorOptions1->SetExcludeReadonlyParts(true);
100     validatorOptions1->SetGenerateCheckFlag(false);
101     validatorOptions1->SetGenerateLogFile(false);
102     validatorOptions1->SetStopOnError(false);
103     validatorOptions1->SetStopOnWarning(false);
104     // 2023_0328
105 
106     // Clear part nodes if any.
107     validators1[0]->ClearPartNodes();
108 
109     // Appends the full path of a part file or the current work part.
110     validators1[0]->AppendPartNode(workPart);
111 
112     // Manually add this line to clean all existing tests
113     validators1[0]->ClearCheckerNodes();
114 
115     // Select a checker and append it into the Validator object.
116     std::vector<NXString> classnames1(2);
117     classnames1[0] = "%mqc_report_browseable_features";//mqc_profile_modeling_cn.dfa
118     classnames1[1] = "%mqc_profile_modeling_cn";//mqc_profile_modeling_cn.dfa
119     validators1[0]->AppendCheckerNodes(classnames1);
120 
121     // Execute the Check-Mate checker.
122     Validation::Result status1;
123     status1 = validators1[0]->Commit();
124 
125     // Get a Parser object, and show the checker result.
126     std::vector<Validate::Parser *> parsers1;
127     theSession->ValidationManager()->FindParser("Validation Gadget", parsers1);
128     parsers1[0]->ClearResultObjects();
129     parsers1[0]->SetDataSource(Validate::Parser::DataSourceTypesMostRecentRun);
130     parsers1[0]->SetMaxDisplayObjects(10);
131     parsers1[0]->Commit();
132 
133     return 0;
134 }

 

设置、保存后、用户默认设置截图:

 

 

 

 调试GIF动态图:

 

黄河远上白云间,一片孤城万仞山。
羌笛何须怨杨柳,春风不度玉门关。

 

诗人初到凉州,面对黄河、边城的辽阔景象,又耳听着《折杨柳》曲,有感而发,写成了这首表现戍守边疆的士兵思念家乡情怀的诗作。

  诗的前两句描绘了西北边地广漠壮阔的风光。首句抓住自下(游)向上(游)、由近及远眺望黄河的特殊感受,描绘出“黄河远上白云间”的动人画面:汹涌澎湃波浪滔滔的黄河竟像一条丝带迤逦飞上云端。写得真是神思飞跃,气象开阔。诗人的另一名句“黄河入海流”,其观察角度与此正好相反,是自上而下的目送;而李白的“黄河之水天上来”,虽也写观望上游,但视线运动却又由远及近,与此句不同。“黄河入海流”和“黄河之水天上来”,同是着意渲染黄河一泻千里的气派,表现的是动态美。而“黄河远上白云间”,方向与河的流向相反,意在突出其源远流长的闲远仪态,表现的是一种静态美。同时展示了边地广漠壮阔的风光,不愧为千古奇句。