日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪(fǎng)問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

UG/NX二次开发Siemens官方NXOPEN实例解析—1.2 BlockStyler/EditExpression

發(fā)布時(shí)間:2023/12/31 编程问答 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 UG/NX二次开发Siemens官方NXOPEN实例解析—1.2 BlockStyler/EditExpression 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

列文章目錄

UG/NX二次開(kāi)發(fā)Siemens官方NXOPEN實(shí)例解析—1.1 BlockStyler/ColoredBlock
UG/NX二次開(kāi)發(fā)Siemens官方NXOPEN實(shí)例解析—1.2 BlockStyler/EditExpression
UG/NX二次開(kāi)發(fā)Siemens官方NXOPEN實(shí)例解析—1.3 BlockStyler/ExtrudewithPreview
UG/NX二次開(kāi)發(fā)Siemens官方NXOPEN實(shí)例解析—1.4 BlockStyler/HoleCoordinates
UG/NX二次開(kāi)發(fā)Siemens官方NXOPEN實(shí)例解析—1.5 BlockStyler/MatrixOperations
UG/NX二次開(kāi)發(fā)Siemens官方NXOPEN實(shí)例解析—1.6 BlockStyler/SelectionExample
UG/NX二次開(kāi)發(fā)Siemens官方NXOPEN實(shí)例解析—1.7 BlockStyler/TreeListDemo
UG/NX二次開(kāi)發(fā)Siemens官方NXOPEN實(shí)例解析—1.8 BlockStyler/UDB_CreateCylinder
UG/NX二次開(kāi)發(fā)Siemens官方NXOPEN實(shí)例解析—1.9 BlockStyler/UpdateExample

文章目錄

目錄

列文章目錄

文章目錄

前言

一、UI樣式文件分析

1. 樣式文件目錄

2. 樣式文件導(dǎo)入預(yù)覽?

?3. 樣式文件解析

二、源碼文件解析

1. 主程序分析

2. 處理模塊分析

3. 運(yùn)行結(jié)果截圖

總結(jié)


前言

????????隨著工業(yè)智能化的不斷發(fā)展,UG二次開(kāi)發(fā)的需求越來(lái)越多,也吸引了大批的二開(kāi)從業(yè)人員,本人作為一名資深I(lǐng)T從業(yè)者(10年+)也毅然加入二次開(kāi)發(fā)大軍。

? ? ? ? 然而,和流行IT行業(yè)(互聯(lián)網(wǎng)、金融、醫(yī)療等)相比,工業(yè)智能化的門(mén)檻顯得更高一點(diǎn),專(zhuān)業(yè)的工業(yè)軟件,相對(duì)封閉的開(kāi)發(fā)理念和更小的開(kāi)發(fā)圈子,讓剛進(jìn)入二開(kāi)的從業(yè)者有點(diǎn)舉步維艱。邊學(xué)邊整理,希望通過(guò)這系列文章的整理能給二開(kāi)的生態(tài)增添一葉綠。


一、UI樣式文件分析

1. 樣式文件目錄

目錄位置:$UGII_BASE_DIR\UGOPEN\SampleNXOpenApplications\C++\BlockStyler\EditExpression

2. 樣式文件導(dǎo)入預(yù)覽?

3. 樣式文件解析

本實(shí)例主要用到的控件有:集列表、列表框、選擇特征、雙精度、字符串、按鈕。

二、源碼文件解析

1. 主程序分析

extern "C" DllExport void ufusr(char *param, int *retcod, int param_len) {try{theEditExpression = new EditExpression();// The following method shows the dialog immediatelytheEditExpression->Show();}catch(exception& ex){//---- Enter your exception handling code here -----EditExpression::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());}delete theEditExpression; } EditExpression::EditExpression() {try{// Initialize the NX Open C++ API environmentEditExpression::theSession = NXOpen::Session::GetSession();EditExpression::theUI = UI::GetUI();theDialogName = "EditExpression.dlx";theDialog = EditExpression::theUI->CreateDialog(theDialogName.c_str());// Registration of callback functionstheDialog->AddApplyHandler(make_callback(this, &EditExpression::apply_cb));theDialog->AddUpdateHandler(make_callback(this, &EditExpression::update_cb));theDialog->AddFilterHandler(make_callback(this, &EditExpression::filter_cb));theDialog->AddInitializeHandler(make_callback(this, &EditExpression::initialize_cb));theDialog->AddDialogShownHandler(make_callback(this, &EditExpression::dialogShown_cb));}catch(exception& ex){throw;} }

構(gòu)造函數(shù)里,我們需要關(guān)注dlx文件加載,回調(diào)方法里面主要關(guān)注:提交方法apply_cb、更新方法update_cb、初始化方法initialize_cb。

2. 處理模塊分析

2.1 初始化方法

void EditExpression::initialize_cb() {try{GroupFeatureSelection = theDialog->TopBlock()->FindBlock("GroupFeatureSelection");FeatureList = dynamic_cast<NXOpen::BlockStyler::SetList* >(theDialog->TopBlock()->FindBlock("FeatureList"));GroupExpressionList = theDialog->TopBlock()->FindBlock("GroupExpressionList");ButtonGetExpressions = theDialog->TopBlock()->FindBlock("ButtonGetExpressions");ExpressionList = dynamic_cast<NXOpen::BlockStyler::ListBox* >(theDialog->TopBlock()->FindBlock("ExpressionList"));GroupExpression = theDialog->TopBlock()->FindBlock("GroupExpression");ExpressionName = theDialog->TopBlock()->FindBlock("ExpressionName");ExpressionValue = theDialog->TopBlock()->FindBlock("ExpressionValue");// User defined codenewFeatCol.clear();newBlock = FeatureList->AddNewSet(true);FeatureList->SetAddHandler(make_callback(this, &EditExpression::add_handler));FeatureList->SetDeleteHandler(make_callback(this, &EditExpression::delete_handler));FeatureList->SetReorderObserver(make_callback(this, &EditExpression::reorder_handler));expToEdit = NULL;}catch(exception& ex){//---- Enter your exception handling code here -----EditExpression::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());} }

初始化方法initialize_cb()

1、獲取控件方法:

????????GroupFeatureSelection = theDialog->TopBlock()->FindBlock("GroupFeatureSelection");
? ? ? ? FeatureList = dynamic_cast<NXOpen::BlockStyler::SetList* >(theDialog->TopBlock()->FindBlock("FeatureList"));
? ? ? ? GroupExpressionList = theDialog->TopBlock()->FindBlock("GroupExpressionList");
? ? ? ? ButtonGetExpressions = theDialog->TopBlock()->FindBlock("ButtonGetExpressions");
? ? ? ? ExpressionList = dynamic_cast<NXOpen::BlockStyler::ListBox* >(theDialog->TopBlock()->FindBlock("ExpressionList"));
? ? ? ? GroupExpression = theDialog->TopBlock()->FindBlock("GroupExpression");
? ? ? ? ExpressionName = theDialog->TopBlock()->FindBlock("ExpressionName");
? ? ? ? ExpressionValue = theDialog->TopBlock()->FindBlock("ExpressionValue");

2、初始化集列表

????????newFeatCol.clear();
? ? ? ? newBlock = FeatureList->AddNewSet(true);
? ? ? ? FeatureList->SetAddHandler(make_callback(this, &EditExpression::add_handler));
? ? ? ? FeatureList->SetDeleteHandler(make_callback(this, &EditExpression::delete_handler));
? ? ? ? FeatureList->SetReorderObserver(make_callback(this, &EditExpression::reorder_handler));
? ? ? ? expToEdit = NULL;

2.2 控件更新/點(diǎn)擊/激活方法?

int EditExpression::update_cb(NXOpen::BlockStyler::UIBlock* block) {try{NXOpen::Part* workPart = EditExpression::theSession->Parts()->Work();if(block == FeatureList){NXOpen::BlockStyler::CompositeBlock* updatedBlock = dynamic_cast<NXOpen::BlockStyler::CompositeBlock* >(FeatureList->FindUpdated());if (updatedBlock != NULL) {NXOpen::BlockStyler::UIBlock* subBlock = updatedBlock->FindBlock("select_feature0");if( subBlock != NULL) {PropertyList* subBlockProperties = subBlock->GetProperties();std::vector<NXOpen::TaggedObject* > featCol = subBlockProperties->GetTaggedObjectVector("SelectedObjects");if (featCol.size() > 1){newFeatCol.clear();newFeatCol.push_back(featCol[featCol.size() - 1]);subBlockProperties->SetTaggedObjectVector("SelectedObjects", newFeatCol);}else if (featCol.size() == 1) {newFeatCol.clear();newFeatCol.push_back(featCol[0]);}NXOpen::Features::Feature* feature1 = dynamic_cast<NXOpen::Features::Feature*>(newFeatCol[0]);std::vector<NXOpen::NXString> str;str.push_back(feature1->JournalIdentifier());FeatureList->SetItemText(updatedBlock, str);delete subBlockProperties;}}}else if(block == ButtonGetExpressions){std::vector<NXOpen::BlockStyler::UIBlock* > selectedBlocks = FeatureList->GetSelected();UIBlock* updatedBlock = NULL;if (selectedBlocks.size() > 0){updatedBlock = selectedBlocks[0];}if (updatedBlock != NULL){FeatureList->GetItemText(updatedBlock);std::vector<NXOpen::NXString> strings = FeatureList->GetItemText(updatedBlock);if ( strings[0].GetText() != "" ){NXOpen::Features::Feature* feat = workPart->Features()->FindObject(strings[0]);std::vector<NXOpen::Expression* > allExp = feat->GetExpressions();std::vector<NXOpen::NXString> allExpStr;for (unsigned int ii = 0; ii < allExp.size(); ++ii){Expression* exp = allExp[ii];stringstream tmpStream;tmpStream << exp->Name().GetUTF8Text() << " = " << exp->Value() << " - " << exp->GetDescriptor().GetUTF8Text();allExpStr.push_back(tmpStream.str());}PropertyList* ExpressionListProperties = ExpressionList->GetProperties();ExpressionListProperties->SetStrings("ListItems", allExpStr);delete ExpressionListProperties;FeatureList->SetItemText(updatedBlock, strings);}}}else if(block == ExpressionList){PropertyList* ExpressionListProperties = ExpressionList->GetProperties();std::vector<NXOpen::NXString> listStrings = ExpressionListProperties->GetStrings("ListItems");std::vector<int> index = ExpressionListProperties->GetIntegerVector("SelectedItems");delete ExpressionListProperties;std::string splitStr (listStrings[index[0]].GetUTF8Text());size_t ind = splitStr.find(" ");if (ind != splitStr.npos){splitStr = splitStr.substr(0, ind);}PropertyList* ExpressionNameProperties = ExpressionName->GetProperties();ExpressionNameProperties->SetString("Value", splitStr);delete ExpressionNameProperties;expToEdit = workPart->Expressions()->FindObject(splitStr);PropertyList* ExpressionValueProperties = ExpressionValue->GetProperties();ExpressionValueProperties->SetDouble("Value", expToEdit->Value());delete ExpressionValueProperties;}else if(block == ExpressionName){//---------Enter your code here-----------}else if(block == ExpressionValue){//---------Enter your code here-----------}}catch(exception& ex){//---- Enter your exception handling code here -----EditExpression::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());}return 0; }

?這里涉及到FeatureList、ButtonGetExpressions、ExpressionList三個(gè)控件的Update方法

1、FeatureList 主要用來(lái)獲取特征,并把特征插入到集列表

? ? ? 獲取選擇的特征方式如下:

? ? ??NXOpen::BlockStyler::UIBlock* subBlock = updatedBlock->FindBlock("select_feature0");

??????featCol = subBlockProperties->GetTaggedObjectVector("SelectedObjects");

? ? ??把特征插入到集列表方法如下:?newFeatCol.push_back(featCol[0]);

2、ButtonGetExpressions用來(lái)獲取指定對(duì)象的表達(dá)式,并在ExpressionsList顯示出來(lái)

? ? ? 獲取表達(dá)式方法:

? ? ??NXOpen::Features::Feature* feat = workPart->Features()->FindObject(strings[0]);
? ? ? std::vector<NXOpen::Expression* > allExp = feat->GetExpressions();

? ? ? 顯示表達(dá)式方法:

??????PropertyList* ExpressionListProperties = ExpressionList->GetProperties();
? ? ? ExpressionListProperties->SetStrings("ListItems", allExpStr);

3、ExpressionList的更新方法,用來(lái)把選擇的表達(dá)式顯示在下面的輸入框,方便后面更新具體的表達(dá)式

? ? ??std::vector<int> index = ExpressionListProperties->GetIntegerVector("SelectedItems");

? ? ??std::string splitStr (listStrings[index[0]].GetUTF8Text());

? ? ??ExpressionNameProperties->SetString("Value", splitStr);

? ? ??ExpressionValueProperties->SetDouble("Value", expToEdit->Value());

2.3 更新表達(dá)式方法?

int EditExpression::apply_cb() {int errorCode = 0;try{if (expToEdit != NULL){NXOpen::Part* workPart = EditExpression::theSession->Parts()->Work();PropertyList* ExpressionValueProperties = ExpressionValue->GetProperties();double editedvalue = ExpressionValueProperties->GetDouble("Value");delete ExpressionValueProperties;ExpressionValueProperties = NULL;Unit* unit1 = dynamic_cast<NXOpen::Unit*>(workPart->UnitCollection()->FindObject("MilliMeter"));NXOpen::Session::UndoMarkId markId2 = EditExpression::theSession->SetUndoMark(NXOpen::Session::MarkVisibilityInvisible, "Update Expression Data");// Convert angle in double to std::stringstd::stringstream expValue;expValue << setprecision(16) << editedvalue;workPart->Expressions()->EditWithUnits(expToEdit, unit1, expValue.str());int nErrs1 = EditExpression::theSession->UpdateManager()->DoUpdate(markId2);if (nErrs1 > 0){errorCode = 1;EditExpression::theUI->NXMessageBox()->Show("Update Errors", NXOpen::NXMessageBox::DialogTypeError, "Update Failed with errors");}EditExpression::theSession->DeleteUndoMark(markId2, "Update Expression Data");}}catch(exception& ex){errorCode = 1;//---- Enter your exception handling code here -----EditExpression::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());}return errorCode; }

根據(jù)編輯后的表達(dá)式,更新對(duì)象

expValue << setprecision(16) << editedvalue;
workPart->Expressions()->EditWithUnits(expToEdit, unit1, expValue.str());

int nErrs1 = EditExpression::theSession->UpdateManager()->DoUpdate(markId2);

3. 運(yùn)行結(jié)果截圖

總結(jié)

官方實(shí)例 EditExpression

1、前端BlockUI,用到了集列表、列表框、選擇特征、雙精度、字符串、按鈕。主要涉及集列表的初始化、賦值和更新,列表框的賦值和取值,特征選擇器的使用。

2、后臺(tái)根據(jù)特征選擇的對(duì)象,在表達(dá)式編輯后,提交更新到對(duì)象。

總結(jié)

以上是生活随笔為你收集整理的UG/NX二次开发Siemens官方NXOPEN实例解析—1.2 BlockStyler/EditExpression的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。