- // Filename: UIStylerSelectionExample.cxx
- //------------------------------------------------------------------------------
- // These includes are needed for the following template code
- //------------------------------------------------------------------------------
- #include <map>
- #include <algorithm>
- #include <NXOpen/UI.hxx>
- #include <NXOpen/UIStyler_Styler.hxx>
- #include <NXOpen/Selection.hxx>
- #include <NXOpen/NXObject.hxx>
- #include <NXOpen/UIStyler_LabelItem.hxx>
- #include <uf_defs.h>
- #include <NXOpen/Builder.hxx>
- #include <NXOpen/Edge.hxx>
- #include <NXOpen/EdgeMultipleSeedTangentRule.hxx>
- #include <NXOpen/Features_Block.hxx>
- #include <NXOpen/Features_EdgeBlendBuilder.hxx>
- #include <NXOpen/Features_Feature.hxx>
- #include <NXOpen/Features_FeatureBuilder.hxx>
- #include <NXOpen/Features_FeatureCollection.hxx>
- #include <NXOpen/GeometricUtilities_BlendLimitsData.hxx>
- #include <NXOpen/ObjectList.hxx>
- #include <NXOpen/Part.hxx>
- #include <NXOpen/PartCollection.hxx>
- #include <NXOpen/ScCollector.hxx>
- #include <NXOpen/ScCollectorCollection.hxx>
- #include <NXOpen/ScRuleFactory.hxx>
- #include <NXOpen/SelectionIntentRule.hxx>
- #include <NXOpen/Session.hxx>
- #include <NXOpen/TaggedObjectList.hxx>
- #include <uf_object_types.h>
- #include <uf_ui_types.h>
- #include "UIStylerSelectionExample.hxx"
- using namespace NXOpen;
- std::map<const char*, NXOpen::NXObject*> htEdges;
- std::map<const char*, NXOpen::NXObject*>::iterator htEdgesIterator;
- //------------------------------------------------------------------------------
- // Initialize static variables
- //------------------------------------------------------------------------------
- Session *(UIStylerSelectionExample::theSession) = NULL;
- UI *(UIStylerSelectionExample::theUI) = NULL;
- bool UIStylerSelectionExample::isDisposeCalled = false;
- //------------------------------------------------------------------------------
- // Declaration of global variables
- //------------------------------------------------------------------------------
- UIStylerSelectionExample *theUIStylerSelectionExample;
- //------------------------------------------------------------------------------
- // Constructor for NX Styler class
- //------------------------------------------------------------------------------
- UIStylerSelectionExample::UIStylerSelectionExample()
- {
- try
- {
- // Initialize the NX Open C++ API environment
- UIStylerSelectionExample::theSession = NXOpen::Session::GetSession();
- UIStylerSelectionExample::theUI = UI::GetUI();
- // Initialize the Open C API environment
- UIStylerSelectionExample::isDisposeCalled = false;
- NXOpen::UIStyler::Styler* theStyler = theUI->Styler();
- theDialog = theStyler->CreateStylerDialog("UIStylerSelectionExample.dlg");
- InitializeUIStylerDialog();
- }
- catch (const NXOpen::NXException& ex)
- {
- // ---- Enter your exception handling code here -----
- UIStylerSelectionExample::theUI->NXMessageBox()->Show("UI Styler", NXOpen::NXMessageBox::DialogTypeError, ex.Message());
- }
- return;
- }
- //------------------------------------------------------------------------------
- // This method is required for UI styler dialog creation
- //------------------------------------------------------------------------------
- void UIStylerSelectionExample::InitializeUIStylerDialog()
- {
- try
- {
- changeDialog = (NXOpen::UIStyler::DialogItem*)theDialog->GetStylerItem("UF_STYLER_DIALOG_INDEX", NXOpen::UIStyler::Dialog::ItemTypeDialogItem);
- changeDialog->AddConstructHandler(make_callback(this, &UIStylerSelectionExample::constructor_cb), false);
- changeDialog->AddOkayHandler(make_callback(this, &UIStylerSelectionExample::ok_cb), false);
- changeDialog->AddApplyHandler(make_callback(this, &UIStylerSelectionExample::apply_cb), false);
- changeGrBeg1 = (NXOpen::UIStyler::GroupBox*)theDialog->GetStylerItem("GR_BEG_1", NXOpen::UIStyler::Dialog::ItemTypeGroupBox);
- changeBitmap1 = (NXOpen::UIStyler::BitMap*)theDialog->GetStylerItem("BITMAP_1", NXOpen::UIStyler::Dialog::ItemTypeBitmap);
- changeLabel1 = (NXOpen::UIStyler::LabelItem*)theDialog->GetStylerItem("LABEL_1", NXOpen::UIStyler::Dialog::ItemTypeLabelItem);
- changeStr0 = (NXOpen::UIStyler::StringItem*)theDialog->GetStylerItem("STR_0", NXOpen::UIStyler::Dialog::ItemTypeStringItem);
- changeStr0->AddActivateHandler(make_callback(this, &UIStylerSelectionExample::bend_radius_cb), false);
- changeCgBeg5 = (NXOpen::UIStyler::CollapsibleGroup*)theDialog->GetStylerItem("CG_BEG_5", NXOpen::UIStyler::Dialog::ItemTypeCollapsibleGroup);
- changeToggle6 = (NXOpen::UIStyler::Toggle*)theDialog->GetStylerItem("TOGGLE_6", NXOpen::UIStyler::Dialog::ItemTypeToggle);
- changeToggle6->AddValueChangedHandler(make_callback(this, &UIStylerSelectionExample::remove_surface_self_intersections_cb), false);
- changeReal6 = (NXOpen::UIStyler::RealItem*)theDialog->GetStylerItem("REAL_6", NXOpen::UIStyler::Dialog::ItemTypeRealItem);
- changeReal6->AddActivateHandler(make_callback(this, &UIStylerSelectionExample::tolerance_cb), false);
- }
- catch (const NXOpen::NXException& ex)
- {
- // ---- Enter your exception handling code here -----
- UIStylerSelectionExample::theUI->NXMessageBox()->Show("UI Styler", NXOpen::NXMessageBox::DialogTypeError, ex.Message());
- }
- return;
- }
- NXOpen::UIStyler::LabelItem* UIStylerSelectionExample::GetChangeLabel1()
- {
- return changeLabel1;
- }
- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
- {
- try
- {
- NXOpen::UIStyler::DialogResponse response;
- theUIStylerSelectionExample = new UIStylerSelectionExample();
- // The following method shows the dialog immediately
- response = theUIStylerSelectionExample->Show();
- theUIStylerSelectionExample->Dispose();
- }
- catch (const NXOpen::NXException& ex)
- {
- // ---- Enter your exception handling code here -----
- UIStylerSelectionExample::theUI->NXMessageBox()->Show("UI Styler", NXOpen::NXMessageBox::DialogTypeError, ex.Message());
- }
- } // User exit ends
- extern "C" DllExport int ufusr_ask_unload()
- {
- // return (int)Session::LibraryUnloadOptionExplicitly;
- return (int)Session::LibraryUnloadOptionImmediately;
- // return (int)Session::LibraryUnloadOptionAtTermination;
- }
- extern "C" DllExport void ufusr_cleanup(void)
- {
- try
- {
- if(UIStylerSelectionExample::isDisposeCalled == false)
- {
- theUIStylerSelectionExample->Dispose();
- }
- UIStylerSelectionExample::isDisposeCalled = true;
- }
- catch (const NXOpen::NXException& ex)
- {
- // ---- Enter your exception handling code here -----
- UIStylerSelectionExample::theUI->NXMessageBox()->Show("UI Styler", NXOpen::NXMessageBox::DialogTypeError, ex.Message());
- }
- return;
- }
- NXOpen::UIStyler::DialogResponse UIStylerSelectionExample::Show()
- {
- NXOpen::UIStyler::DialogResponse retValue = NXOpen::UIStyler::DialogResponseOk;
- try
- {
- retValue = theDialog->Show();
- }
- catch (const NXOpen::NXException& ex)
- {
- UIStylerSelectionExample::theUI->NXMessageBox()->Show("UI Styler", NXOpen::NXMessageBox::DialogTypeError, ex.Message());
- }
- return retValue;
- }
- void UIStylerSelectionExample::Dispose()
- {
- try
- {
- if (UIStylerSelectionExample::isDisposeCalled == false)
- {
- delete changeDialog;
- delete changeGrBeg1;
- delete changeBitmap1;
- delete changeLabel1;
- delete changeStr0;
- delete changeCgBeg5;
- delete changeToggle6;
- delete changeReal6;
- delete theDialog;
- }
- UIStylerSelectionExample::isDisposeCalled = true;
- }
- catch (const NXOpen::NXException& ex)
- {
- UIStylerSelectionExample::theUI->NXMessageBox()->Show("UI Styler", NXOpen::NXMessageBox::DialogTypeError, ex.Message());
- }
- return;
- }
- int sel_cb(std::vector<NXOpen::NXObject *> selectedObject, std::vector<NXOpen::NXObject *> deselectedObjects, NXOpen::SelectionHandle* selectHandle)
- {
- try
- {
- std::vector<NXOpen::NXObject *>::iterator selIter;
- for (selIter = selectedObject.begin(); selIter != selectedObject.end(); selIter++)
- {
- htEdges[(*selIter)->JournalIdentifier().GetLocaleText()] = *selIter;
- }
- for (selIter = deselectedObjects.begin(); selIter != deselectedObjects.end(); selIter++)
- {
- htEdges.erase((*selIter)->JournalIdentifier().GetLocaleText());
- }
- int cnt = htEdges.size();
- char sel_edges[100];
- sprintf(sel_edges, "Select Edges ( %d )", cnt);
- theUIStylerSelectionExample->GetChangeLabel1()->SetLabel(NXOpen::NXString(std::string(sel_edges)));
- }
- catch (const NXOpen::NXException& ex)
- {
- UIStylerSelectionExample::theUI->NXMessageBox()->Show("UI Styler", NXOpen::NXMessageBox::DialogTypeError, ex.Message());
- }
- return NXOpen::UIStyler::DialogStateContinueDialog;
- }
- int filter_cb(NXOpen::NXObject *selectedObject, NXOpen::Selection::MaskTriple* selectionMask_array, NXOpen::SelectionHandle* selectHandle)
- {
- try
- {
- if(std::string(selectedObject->JournalIdentifier().GetText()) == std::string("EDGE * 6 * 1"))
- return UF_UI_SEL_REJECT;
- else
- return UF_UI_SEL_ACCEPT;
- }
- catch (const NXOpen::NXException& ex)
- {
- UIStylerSelectionExample::theUI->NXMessageBox()->Show("UI Styler", NXOpen::NXMessageBox::DialogTypeError, ex.Message());
- }
- return NXOpen::UIStyler::DialogStateContinueDialog;
- }
- NXOpen::UIStyler::DialogState UIStylerSelectionExample::constructor_cb(NXOpen::UIStyler::StylerEvent* eventObject)
- {
- try
- {
- // Get the selection handle
- NXOpen::SelectionHandle *selectH = changeDialog->GetSelectionHandle();
- std::vector<NXOpen::Selection::MaskTriple> selectionMask_array;
- NXOpen::Selection::MaskTriple selectionMask_arrayElem;
- selectionMask_arrayElem.Type = UF_solid_type;
- selectionMask_arrayElem.Subtype = UF_solid_edge_subtype;
- selectionMask_arrayElem.SolidBodySubtype = UF_UI_SEL_FEATURE_ANY_EDGE;
- selectionMask_array.push_back(selectionMask_arrayElem);
- UI::GetUI()->SelectionManager()->SetSelectionMask(selectH, NXOpen::Selection::SelectionActionClearAndEnableSpecific, selectionMask_array);
- UI::GetUI()->SelectionManager()->SetSelectionCallbacks(selectH, make_callback(&filter_cb), make_callback(&sel_cb));
- changeToggle6->SetItemValue(true);
- changeStr0->SetItemValue("5.0");
- changeLabel1->SetLabel("Select Edges (0)");
- }
- catch (const NXOpen::NXException& ex)
- {
- UIStylerSelectionExample::theUI->NXMessageBox()->Show("UI Styler", NXOpen::NXMessageBox::DialogTypeError, ex.Message());
- }
- return NXOpen::UIStyler::DialogStateContinueDialog;
- }
- NXOpen::UIStyler::DialogState UIStylerSelectionExample::ok_cb(NXOpen::UIStyler::StylerEvent* eventObject)
- {
- try
- {
- NXOpen::UIStyler::DialogState LOCAL_state = apply_cb(eventObject);
- return LOCAL_state;
- }
- catch (const NXOpen::NXException& ex)
- {
- UIStylerSelectionExample::theUI->NXMessageBox()->Show("UI Styler", NXOpen::NXMessageBox::DialogTypeError, ex.Message());
- }
- return NXOpen::UIStyler::DialogStateExitDialog;
- }
- NXOpen::UIStyler::DialogState UIStylerSelectionExample::apply_cb(NXOpen::UIStyler::StylerEvent* eventObject)
- {
- try
- {
- Part *workPart(theSession->Parts()->Work());
- Part *displayPart(theSession->Parts()->Display());
- Session::UndoMarkId markId1;
- markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible, "Start");
- Features::Feature *nullFeatures_Feature(NULL);
- Features::EdgeBlendBuilder *edgeBlendBuilder1;
- edgeBlendBuilder1 = workPart->Features()->CreateEdgeBlendBuilder(nullFeatures_Feature);
- theSession->SetUndoMarkName(markId1, "Edge Blend");
- ScCollector *scCollector1;
- scCollector1 = workPart->ScCollectors()->CreateCollector();
- std::vector<Edge *> seedEdges1;
- Features::Block *block1(dynamic_cast<Features::Block *>(workPart->Features()->FindObject("BLOCK(1)")));
- for (htEdgesIterator = htEdges.begin(); htEdgesIterator != htEdges.end(); ++htEdgesIterator)
- {
- Edge *edge1(dynamic_cast<Edge *>(htEdgesIterator->second));
- seedEdges1.push_back(edge1);
- }
- EdgeMultipleSeedTangentRule *edgeMultipleSeedTangentRule1;
- edgeMultipleSeedTangentRule1 = workPart->ScRuleFactory()->CreateRuleEdgeMultipleSeedTangent(seedEdges1, 0.5, true);
- std::vector<SelectionIntentRule *> rules1(1);
- rules1[0] = edgeMultipleSeedTangentRule1;
- scCollector1->ReplaceRules(rules1, false);
- Session::UndoMarkId markId2;
- markId2 = theSession->SetUndoMark(Session::MarkVisibilityInvisible, "Edge Blend");
- edgeBlendBuilder1->LimitsListData()->CapsList()->Clear(ObjectList::DeleteOptionDelete);
- edgeBlendBuilder1->SetTolerance(0.0254);
- edgeBlendBuilder1->SetAllInstancesOption(false);
- edgeBlendBuilder1->SetRemoveSelfIntersection(true);
- edgeBlendBuilder1->SetConvexConcaveY(false);
- edgeBlendBuilder1->SetRollOverSmoothEdge(true);
- edgeBlendBuilder1->SetRollOntoEdge(true);
- edgeBlendBuilder1->SetMoveSharpEdge(true);
- edgeBlendBuilder1->SetOverlapOption(Features::EdgeBlendBuilder::OverlapAnyConvexityRollOver);
- edgeBlendBuilder1->SetBlendOrder(Features::EdgeBlendBuilder::OrderOfBlendingConvexFirst);
- edgeBlendBuilder1->SetSetbackOption(Features::EdgeBlendBuilder::SetbackSeparateFromCorner);
- int csIndex1;
- csIndex1 = edgeBlendBuilder1->AddChainset(scCollector1, "5");
- Features::Feature *feature1;
- feature1 = edgeBlendBuilder1->CommitFeature();
- theSession->DeleteUndoMark(markId2, NULL);
- edgeBlendBuilder1->Destroy();
- htEdges.clear();
- changeLabel1->SetLabel("Select Edges (0)");
- }
- catch (const NXOpen::NXException& ex)
- {
- UIStylerSelectionExample::theUI->NXMessageBox()->Show("UI Styler", NXOpen::NXMessageBox::DialogTypeError, ex.Message());
- }
- return NXOpen::UIStyler::DialogStateContinueDialog;
- }
- NXOpen::UIStyler::DialogState UIStylerSelectionExample::bend_radius_cb(NXOpen::UIStyler::StylerEvent* eventObject)
- {
- try
- {
- }
- catch (const NXOpen::NXException& ex)
- {
- // ---- Enter your exception handling code here -----
- UIStylerSelectionExample::theUI->NXMessageBox()->Show("UI Styler", NXOpen::NXMessageBox::DialogTypeError, ex.Message());
- }
- // Callback acknowledged, do not terminate dialog
- return NXOpen::UIStyler::DialogStateContinueDialog;
- // or Callback acknowledged, terminate dialog.
- // return NXOpen::UIStyler::DialogStateExitDialog;
- }
- NXOpen::UIStyler::DialogState UIStylerSelectionExample::remove_surface_self_intersections_cb(NXOpen::UIStyler::StylerEvent* eventObject)
- {
- try
- {
- }
- catch (const NXOpen::NXException& ex)
- {
- // ---- Enter your exception handling code here -----
- UIStylerSelectionExample::theUI->NXMessageBox()->Show("UI Styler", NXOpen::NXMessageBox::DialogTypeError, ex.Message());
- }
- // Callback acknowledged, do not terminate dialog
- return NXOpen::UIStyler::DialogStateContinueDialog;
- // or Callback acknowledged, terminate dialog.
- // return NXOpen::UIStyler::DialogStateExitDialog;
- }
- NXOpen::UIStyler::DialogState UIStylerSelectionExample::tolerance_cb(NXOpen::UIStyler::StylerEvent* eventObject)
- {
- try
- {
- }
- catch (const NXOpen::NXException& ex)
- {
- UIStylerSelectionExample::theUI->NXMessageBox()->Show("UI Styler", NXOpen::NXMessageBox::DialogTypeError, ex.Message());
- }
- return NXOpen::UIStyler::DialogStateContinueDialog;
- }
复制代码 |