NX二次开发-BlockUI的Tree树控件

关于BlockUI的Tree树控件只要研究UGOPEN里西门子官方的那个例子在结合去查NXOPEN的帮助基本就可以了。[不过我是看唐工的视频学会的,没办法自己领悟性不太强]

  1 //=============================================================================
  2 //
  3 //                   Copyright (c) 2009 Siemens PLM Solutions
  4 //                     Unpublished - All rights reserved
  5 //===============================================================================
  6 //File description: Sample NX/Open Application for Block Styler
  7 //===============================================================================
  8 //
  9 
 10 //  WARNING!!  This file is overwritten by the Block Styler while generating
 11 //  the automation code. Any modifications to this file will be lost after
 12 //  generating the code again.
 13 
 14 //==============================================================================
 15 
 16 #ifndef TREELISTDEMO_H_INCLUDED
 17 #define TREELISTDEMO_H_INCLUDED
 18 
 19 //------------------------------------------------------------------------------
 20 //These includes are needed for the following template code
 21 //------------------------------------------------------------------------------
 22 #include <uf_defs.h>
 23 #include <string.h>
 24 #include <uf_ui_types.h>
 25 #include <iostream>
 26 #include <NXOpen/Session.hxx>
 27 #include <NXOpen/UI.hxx>
 28 #include <NXOpen/NXMessageBox.hxx>
 29 #include <NXOpen/Callback.hxx>
 30 #include <NXOpen/NXException.hxx>
 31 #include <NXOpen/ListingWindow.hxx>
 32 #include <NXOpen/BlockStyler_UIBlock.hxx>
 33 #include <NXOpen/BlockStyler_BlockDialog.hxx>
 34 #include <NXOpen/BlockStyler_PropertyList.hxx>
 35 #include <NXOpen/BlockStyler_Tree.hxx>
 36 #include <NXOpen/BlockStyler_Node.hxx>
 37 
 38 //------------------------------------------------------------------------------
 39 //Bit Option for Property: SnapPointTypesEnabled
 40 //------------------------------------------------------------------------------
 41 #define              SnapPointTypesEnabled_UserDefined (1 << 0);
 42 #define                 SnapPointTypesEnabled_Inferred (1 << 1);
 43 #define           SnapPointTypesEnabled_ScreenPosition (1 << 2);
 44 #define                 SnapPointTypesEnabled_EndPoint (1 << 3);
 45 #define                 SnapPointTypesEnabled_MidPoint (1 << 4);
 46 #define             SnapPointTypesEnabled_ControlPoint (1 << 5);
 47 #define             SnapPointTypesEnabled_Intersection (1 << 6);
 48 #define                SnapPointTypesEnabled_ArcCenter (1 << 7);
 49 #define            SnapPointTypesEnabled_QuadrantPoint (1 << 8);
 50 #define            SnapPointTypesEnabled_ExistingPoint (1 << 9);
 51 #define             SnapPointTypesEnabled_PointonCurve (1 <<10);
 52 #define           SnapPointTypesEnabled_PointonSurface (1 <<11);
 53 #define         SnapPointTypesEnabled_PointConstructor (1 <<12);
 54 #define     SnapPointTypesEnabled_TwocurveIntersection (1 <<13);
 55 #define             SnapPointTypesEnabled_TangentPoint (1 <<14);
 56 #define                    SnapPointTypesEnabled_Poles (1 <<15);
 57 #define         SnapPointTypesEnabled_BoundedGridPoint (1 <<16);
 58 //------------------------------------------------------------------------------
 59 //Bit Option for Property: SnapPointTypesOnByDefault
 60 //------------------------------------------------------------------------------
 61 #define             SnapPointTypesOnByDefault_EndPoint (1 << 3);
 62 #define             SnapPointTypesOnByDefault_MidPoint (1 << 4);
 63 #define         SnapPointTypesOnByDefault_ControlPoint (1 << 5);
 64 #define         SnapPointTypesOnByDefault_Intersection (1 << 6);
 65 #define            SnapPointTypesOnByDefault_ArcCenter (1 << 7);
 66 #define        SnapPointTypesOnByDefault_QuadrantPoint (1 << 8);
 67 #define        SnapPointTypesOnByDefault_ExistingPoint (1 << 9);
 68 #define         SnapPointTypesOnByDefault_PointonCurve (1 <<10);
 69 #define       SnapPointTypesOnByDefault_PointonSurface (1 <<11);
 70 #define     SnapPointTypesOnByDefault_PointConstructor (1 <<12);
 71 #define     SnapPointTypesOnByDefault_BoundedGridPoint (1 <<16);
 72 //------------------------------------------------------------------------------
 73 // Namespaces needed for following template
 74 //------------------------------------------------------------------------------
 75 using namespace std;
 76 using namespace NXOpen;
 77 using namespace NXOpen::BlockStyler;
 78 
 79 //------------------------------------------------------------------------------
 80 // Forward declaration for Class
 81 //------------------------------------------------------------------------------
 82 class TreeListDemo;
 83 //
 84 //------------------------------------------------------------------------------
 85 // Declaration of global variables
 86 //------------------------------------------------------------------------------
 87 extern TreeListDemo *theTreeListDemo;
 88 
 89 class TreeListDemo
 90 {
 91     // class members
 92 public:
 93     static Session *theSession;
 94     static UI *theUI;
 95     TreeListDemo();
 96     ~TreeListDemo();
 97     int Show();
 98     
 99     //----------------------- BlockStyler Callback Prototypes ---------------------
100     // The following member function prototypes define the callbacks 
101     // specified in your BlockStyler dialog.  The empty implementaiton
102     // of these prototypes is provided in the TreeListDemo.cpp file. 
103     // You are REQUIRED to write the implementation for these funtions.
104     //------------------------------------------------------------------------------
105     void initialize_cb();
106     void dialogShown_cb();
107     int apply_cb();
108     int ok_cb();
109     int update_cb(NXOpen::BlockStyler::UIBlock* block);
110     void focusNotify_cb(NXOpen::BlockStyler::UIBlock* block, bool focus);
111 
112     
113     //void OnExpandCallback (NXOpen::BlockStyler::Tree *tree, NXOpen::BlockStyler::Node *node);
114     //void OnInsertColumnCallback(NXOpen::BlockStyler::Tree *tree, NXOpen::BlockStyler::Node *node, int columnID);
115     void OnInsertNodeCallback(NXOpen::BlockStyler::Tree *tree, NXOpen::BlockStyler::Node *node);
116     void OnDeleteNodeCallback(NXOpen::BlockStyler::Tree *tree, NXOpen::BlockStyler::Node *node);
117     //void OnPreSelectCallback(NXOpen::BlockStyler::Tree *tree, NXOpen::BlockStyler::Node *node, int ID, bool selected);
118     void OnSelectCallback(NXOpen::BlockStyler::Tree *, NXOpen::BlockStyler::Node *, int columnID, bool selected);
119     void OnStateChangeCallback(NXOpen::BlockStyler::Tree *tree, NXOpen::BlockStyler::Node *node, int state);
120     NXString ToolTipTextCallback(NXOpen::BlockStyler::Tree *tree, NXOpen::BlockStyler::Node *node, int columnID);
121     //int ColumnSortCallback(NXOpen::BlockStyler::Tree *tree, int columnID, NXOpen::BlockStyler::Node *node1, NXOpen::BlockStyler::Node *node2);
122     NXString StateIconNameCallback(NXOpen::BlockStyler::Tree *tree, NXOpen::BlockStyler::Node *node, int state);
123     NXOpen::BlockStyler::Tree::BeginLabelEditState OnBeginLabelEditCallback(NXOpen::BlockStyler::Tree *tree, NXOpen::BlockStyler::Node *node, int columnID);
124     NXOpen::BlockStyler::Tree::EndLabelEditState OnEndLabelEditCallback(NXOpen::BlockStyler::Tree *tree, NXOpen::BlockStyler::Node *node, int, NXString editedText);
125     NXOpen::BlockStyler::Tree::EditControlOption OnEditOptionSelectedCallback(NXOpen::BlockStyler::Tree *tree, NXOpen::BlockStyler::Node *node, int columnID, int selectedOptionID, NXString selectedOptionText, NXOpen::BlockStyler::Tree::ControlType type);
126     NXOpen::BlockStyler::Tree::ControlType AskEditControlCallback(NXOpen::BlockStyler::Tree *tree, NXOpen::BlockStyler::Node *node, int columnID);
127     void OnMenuCallback(NXOpen::BlockStyler::Tree *, NXOpen::BlockStyler::Node *node, int columnID);
128     void OnMenuSelectionCallback(NXOpen::BlockStyler::Tree *tree, NXOpen::BlockStyler::Node *node, int menuItemID);
129     NXOpen::BlockStyler::Node::DropType IsDropAllowedCallback(NXOpen::BlockStyler::Tree *tree, NXOpen::BlockStyler::Node *node, int columnID, NXOpen::BlockStyler::Node *targetNode, int targetColumnID);
130     NXOpen::BlockStyler::Node::DragType IsDragAllowedCallback(NXOpen::BlockStyler::Tree *tree, NXOpen::BlockStyler::Node *node, int columnID);
131     bool OnDropCallback(NXOpen::BlockStyler::Tree *tree, std::vector<NXOpen::BlockStyler::Node *> node, int columnID, NXOpen::BlockStyler::Node *targetNode, int targetColumnID, NXOpen::BlockStyler::Node::DropType dropType, int dropMenuItemId);
132     //void OnDropMenuCallback(NXOpen::BlockStyler::Tree *tree, NXOpen::BlockStyler::Node *node, int columnID, NXOpen::BlockStyler::Node *targetNode, int targetColumnID);
133     void OnDefaultAction(NXOpen::BlockStyler::Tree *tree, NXOpen::BlockStyler::Node *node, int columnID);
134 private:
135     std::string theDialogName;
136     NXOpen::BlockStyler::BlockDialog* theDialog;
137     NXOpen::BlockStyler::UIBlock* group0;// Block type: Group
138     NXOpen::BlockStyler::Tree* tree_control0;// Block type: Tree Control
139     NXOpen::BlockStyler::UIBlock* addDeleteNodeGroup;// Block type: Group
140     NXOpen::BlockStyler::UIBlock* nodeString;// Block type: String
141     NXOpen::BlockStyler::UIBlock* addNodeButton;// Block type: Button
142     NXOpen::BlockStyler::UIBlock* deleteNodeButton;// Block type: Button
143     NXOpen::BlockStyler::UIBlock* stateIconGroup;// Block type: Group
144     NXOpen::BlockStyler::UIBlock* stateIconOptions;// Block type: Enumeration
145     NXOpen::BlockStyler::UIBlock* nodeToolTip;// Block type: String
146     NXOpen::BlockStyler::UIBlock* NodeEditGroup;// Block type: Group
147     NXOpen::BlockStyler::UIBlock* nodeEditOptions;// Block type: Enumeration
148     NXOpen::BlockStyler::UIBlock* menuGroup;// Block type: Group
149     NXOpen::BlockStyler::UIBlock* showMenuToggle;// Block type: Toggle
150     NXOpen::BlockStyler::UIBlock* dragDropGroup;// Block type: Group
151     NXOpen::BlockStyler::UIBlock* disallowDragToggle;// Block type: Toggle
152     NXOpen::BlockStyler::UIBlock* dropOptions;// Block type: Enumeration
153     NXOpen::BlockStyler::UIBlock* defaultActionGroup;// Block type: Group
154     NXOpen::BlockStyler::UIBlock* defaultActionToggle;// Block type: Toggle
155     NXOpen::BlockStyler::UIBlock* nodeDataGroup;// Block type: Group
156     NXOpen::BlockStyler::UIBlock* instructions;// Block type: Multiline String
157     NXOpen::BlockStyler::UIBlock* selection0;// Block type: Selection
158     NXOpen::BlockStyler::UIBlock* addCrossSelectionNodeButton;// Block type: Button
159     NXOpen::BlockStyler::UIBlock* redrawGroup;// Block type: Group
160     NXOpen::BlockStyler::UIBlock* redrawInstruction;// Block type: Multiline String
161     NXOpen::BlockStyler::UIBlock* redrawToggle;// Block type: Toggle
162     NXOpen::BlockStyler::UIBlock* listingWindowGroup;// Block type: Group
163     NXOpen::BlockStyler::UIBlock* listingWindowToggle;// Block type: Toggle
164     void DeleteSelectedNodes();
165     BlockStyler::Node* CreateAndAddNode(BlockStyler::Node* afterNode);
166     void WriteCallbackToListingWindow(NXString);
167     
168 };
169 #endif //TREELISTDEMO_H_INCLUDED
170 
171 Caesar卢尚宇
172 2019年11月23日
   1 //===============================================================================
   2 //
   3 //                   Copyright (c) 2009 Siemens PLM Solutions
   4 //                     Unpublished - All rights reserved
   5 //===============================================================================
   6 //File description: Sample NX/Open Application for Block Styler
   7 //===============================================================================
   8 //
   9 
  10 //  WARNING!!  This file is overwritten by the Block UI Styler while generating
  11 //  the automation code. Any modifications to this file will be lost after
  12 //  generating the code again.
  13 
  14 //================================================================================
  15 
  16 //================================================================================
  17 //  Purpose:  This TEMPLATE file contains C++ source to guide you in the
  18 //  construction of your Block application dialog. The generation of your
  19 //  dialog file (.dlx extension) is the first step towards dialog construction
  20 //  within NX.  You must now create a NX Open application that
  21 //  utilizes this file (.dlx).
  22 //
  23 //  The information in this file provides you with the following:
  24 //
  25 //  1.  Help on how to load and display your Block UI Styler dialog in NX
  26 //      using APIs provided in NXOpen.BlockStyler namespace
  27 //  2.  The empty callback methods (stubs) associated with your dialog items
  28 //      have also been placed in this file. These empty methods have been
  29 //      created simply to start you along with your coding requirements.
  30 //      The method name, argument list and possible return values have already
  31 //      been provided for you.
  32 //================================================================================
  33 
  34 //--------------------------------------------------------------------------------
  35 //These includes are needed for the following template code
  36 //--------------------------------------------------------------------------------
  37 #include "TreeListDemo.hpp"
  38 #include <sstream>
  39 using namespace NXOpen;
  40 using namespace NXOpen::BlockStyler;
  41 
  42 //------------------------------------------------------------------------------
  43 // Initialize static variables
  44 //------------------------------------------------------------------------------
  45 Session *(TreeListDemo::theSession) = NULL;
  46 UI *(TreeListDemo::theUI) = NULL;
  47 
  48 //------------------------------------------------------------------------------
  49 // Declaration of global variables
  50 //------------------------------------------------------------------------------
  51 TreeListDemo *theTreeListDemo;
  52 //------------------------------------------------------------------------------
  53 // Constructor for NX Styler class
  54 //------------------------------------------------------------------------------
  55 TreeListDemo::TreeListDemo()
  56 {
  57     try
  58     {
  59         // Initialize the NX Open C++ API environment
  60         TreeListDemo::theSession = NXOpen::Session::GetSession();
  61         TreeListDemo::theUI = UI::GetUI();
  62         theDialogName = "TreeListDemo.dlx";
  63         theDialog = TreeListDemo::theUI->CreateDialog(theDialogName.c_str());
  64         // Registration of callback functions
  65         theDialog->AddApplyHandler(make_callback(this, &TreeListDemo::apply_cb));
  66         theDialog->AddOkHandler(make_callback(this, &TreeListDemo::ok_cb));
  67         theDialog->AddUpdateHandler(make_callback(this, &TreeListDemo::update_cb));
  68         theDialog->AddInitializeHandler(make_callback(this, &TreeListDemo::initialize_cb));
  69         theDialog->AddFocusNotifyHandler(make_callback(this, &TreeListDemo::focusNotify_cb));
  70         theDialog->AddDialogShownHandler(make_callback(this, &TreeListDemo::dialogShown_cb));
  71     }
  72     catch(exception& ex)
  73     {
  74         //---- Enter your exception handling code here -----
  75         throw;
  76     }
  77 }
  78 
  79 //------------------------------------------------------------------------------
  80 // Destructor for NX Styler class
  81 //------------------------------------------------------------------------------
  82 TreeListDemo::~TreeListDemo()
  83 {
  84     if (theDialog != NULL)
  85     {
  86         delete theDialog;
  87         theDialog = NULL;
  88     }
  89 }
  90 //------------------------------- DIALOG LAUNCHING ---------------------------------
  91 //
  92 //    Before invoking this application one needs to open any part/empty part in NX
  93 //    because of the behavior of the blocks.
  94 //
  95 //    Make sure the dlx file is in one of the following locations:
  96 //        1.) From where NX session is launched
  97 //        2.) $UGII_USER_DIR/application
  98 //        3.) For released applications, using UGII_CUSTOM_DIRECTORY_FILE is highly
  99 //            recommended. This variable is set to a full directory path to a file 
 100 //            containing a list of root directories for all custom applications.
 101 //            e.g., UGII_CUSTOM_DIRECTORY_FILE=$UGII_BASE_DIR\ugii\menus\custom_dirs.dat
 102 //
 103 //    You can create the dialog using one of the following way:
 104 //
 105 //    1. USER EXIT
 106 //
 107 //        1) Create the Shared Library -- Refer "Block UI Styler programmer's guide"
 108 //        2) Invoke the Shared Library through File->Execute->NX Open menu.
 109 //
 110 //------------------------------------------------------------------------------
 111 extern "C" DllExport void  ufusr(char *param, int *retcod, int param_len)
 112 {
 113     try
 114     {
 115         theTreeListDemo = new TreeListDemo();
 116         // The following method shows the dialog immediately
 117         theTreeListDemo->Show();
 118     }
 119     catch(exception& ex)
 120     {
 121         //---- Enter your exception handling code here -----
 122         TreeListDemo::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
 123     }
 124     delete theTreeListDemo;
 125 }
 126 
 127 //------------------------------------------------------------------------------
 128 // This method specifies how a shared image is unloaded from memory
 129 // within NX. This method gives you the capability to unload an
 130 // internal NX Open application or user  exit from NX. Specify any
 131 // one of the three constants as a return value to determine the type
 132 // of unload to perform:
 133 //
 134 //
 135 //    Immediately : unload the library as soon as the automation program has completed
 136 //    Explicitly  : unload the library from the "Unload Shared Image" dialog
 137 //    AtTermination : unload the library when the NX session terminates
 138 //
 139 //
 140 // NOTE:  A program which associates NX Open applications with the menubar
 141 // MUST NOT use this option since it will UNLOAD your NX Open application image
 142 // from the menubar.
 143 //------------------------------------------------------------------------------
 144 extern "C" DllExport int ufusr_ask_unload()
 145 {
 146     //return (int)Session::LibraryUnloadOptionExplicitly;
 147     return (int)Session::LibraryUnloadOptionImmediately;
 148     //return (int)Session::LibraryUnloadOptionAtTermination;
 149 }
 150 
 151 //------------------------------------------------------------------------------
 152 // Following method cleanup any housekeeping chores that may be needed.
 153 // This method is automatically called by NX.
 154 //------------------------------------------------------------------------------
 155 extern "C" DllExport void ufusr_cleanup(void)
 156 {
 157     try
 158     {
 159         //---- Enter your callback code here -----
 160     }
 161     catch(exception& ex)
 162     {
 163         //---- Enter your exception handling code here -----
 164         TreeListDemo::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
 165     }
 166 }
 167 
 168 int TreeListDemo::Show()
 169 {
 170     try
 171     {
 172         theDialog->Show();
 173     }
 174     catch(exception& ex)
 175     {
 176         //---- Enter your exception handling code here -----
 177         TreeListDemo::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
 178     }
 179     return 0;
 180 }
 181 
 182 //------------------------------------------------------------------------------
 183 //---------------------Block UI Styler Callback Functions--------------------------
 184 //------------------------------------------------------------------------------
 185 
 186 //------------------------------------------------------------------------------
 187 //Callback Name: initialize_cb
 188 
 189 NXOpen::NXString nodeBaseString;
 190 int nodeSuffixNumber = 0;
 191 //------------------------------------------------------------------------------
 192 void TreeListDemo::initialize_cb()
 193 {
 194     try
 195     {
 196         group0 = dynamic_cast<NXOpen::BlockStyler::UIBlock* >(theDialog->TopBlock()->FindBlock("group0"));
 197         tree_control0 = dynamic_cast<NXOpen::BlockStyler::Tree* >(theDialog->TopBlock()->FindBlock("tree_control0"));
 198         addDeleteNodeGroup = dynamic_cast<NXOpen::BlockStyler::UIBlock* >(theDialog->TopBlock()->FindBlock("addDeleteNodeGroup"));
 199         nodeString = dynamic_cast<NXOpen::BlockStyler::UIBlock* >(theDialog->TopBlock()->FindBlock("nodeString"));
 200         addNodeButton = dynamic_cast<NXOpen::BlockStyler::UIBlock* >(theDialog->TopBlock()->FindBlock("addNodeButton"));
 201         deleteNodeButton = dynamic_cast<NXOpen::BlockStyler::UIBlock* >(theDialog->TopBlock()->FindBlock("deleteNodeButton"));
 202         stateIconGroup = dynamic_cast<NXOpen::BlockStyler::UIBlock* >(theDialog->TopBlock()->FindBlock("stateIconGroup"));
 203         stateIconOptions = dynamic_cast<NXOpen::BlockStyler::UIBlock* >(theDialog->TopBlock()->FindBlock("stateIconOptions"));
 204         nodeToolTip = dynamic_cast<NXOpen::BlockStyler::UIBlock* >(theDialog->TopBlock()->FindBlock("nodeToolTip"));
 205         NodeEditGroup = dynamic_cast<NXOpen::BlockStyler::UIBlock* >(theDialog->TopBlock()->FindBlock("NodeEditGroup"));
 206         nodeEditOptions = dynamic_cast<NXOpen::BlockStyler::UIBlock* >(theDialog->TopBlock()->FindBlock("nodeEditOptions"));
 207         menuGroup = dynamic_cast<NXOpen::BlockStyler::UIBlock* >(theDialog->TopBlock()->FindBlock("menuGroup"));
 208         showMenuToggle = dynamic_cast<NXOpen::BlockStyler::UIBlock* >(theDialog->TopBlock()->FindBlock("showMenuToggle"));
 209         dragDropGroup = dynamic_cast<NXOpen::BlockStyler::UIBlock* >(theDialog->TopBlock()->FindBlock("dragDropGroup"));
 210         disallowDragToggle = dynamic_cast<NXOpen::BlockStyler::UIBlock* >(theDialog->TopBlock()->FindBlock("disallowDragToggle"));
 211         dropOptions = dynamic_cast<NXOpen::BlockStyler::UIBlock* >(theDialog->TopBlock()->FindBlock("dropOptions"));
 212         defaultActionGroup = dynamic_cast<NXOpen::BlockStyler::UIBlock* >(theDialog->TopBlock()->FindBlock("defaultActionGroup"));
 213         defaultActionToggle = dynamic_cast<NXOpen::BlockStyler::UIBlock* >(theDialog->TopBlock()->FindBlock("defaultActionToggle"));
 214         nodeDataGroup = dynamic_cast<NXOpen::BlockStyler::UIBlock* >(theDialog->TopBlock()->FindBlock("nodeDataGroup"));
 215         instructions = dynamic_cast<NXOpen::BlockStyler::UIBlock* >(theDialog->TopBlock()->FindBlock("instructions"));
 216         selection0 = dynamic_cast<NXOpen::BlockStyler::UIBlock* >(theDialog->TopBlock()->FindBlock("selection0"));
 217         addCrossSelectionNodeButton = dynamic_cast<NXOpen::BlockStyler::UIBlock* >(theDialog->TopBlock()->FindBlock("addCrossSelectionNodeButton"));
 218         redrawGroup = dynamic_cast<NXOpen::BlockStyler::UIBlock* >(theDialog->TopBlock()->FindBlock("redrawGroup"));
 219         redrawInstruction = dynamic_cast<NXOpen::BlockStyler::UIBlock* >(theDialog->TopBlock()->FindBlock("redrawInstruction"));
 220         redrawToggle = dynamic_cast<NXOpen::BlockStyler::UIBlock* >(theDialog->TopBlock()->FindBlock("redrawToggle"));
 221         listingWindowGroup = dynamic_cast<NXOpen::BlockStyler::UIBlock* >(theDialog->TopBlock()->FindBlock("listingWindowGroup"));
 222         listingWindowToggle = dynamic_cast<NXOpen::BlockStyler::UIBlock* >(theDialog->TopBlock()->FindBlock("listingWindowToggle"));
 223         //------------------------------------------------------------------------------
 224         //Registration of Treelist specific callbacks
 225         //------------------------------------------------------------------------------
 226         //tree_control0->SetOnExpandHandler(make_callback(this, &TreeListDemo::OnExpandCallback));
 227 
 228         //tree_control0->SetOnInsertColumnHandler(make_callback(this, &TreeListDemo::OnInsertColumnCallback));
 229 
 230         tree_control0->SetOnInsertNodeHandler(make_callback(this, &TreeListDemo::OnInsertNodeCallback));
 231 
 232         tree_control0->SetOnDeleteNodeHandler(make_callback(this, &TreeListDemo::OnDeleteNodeCallback));
 233 
 234         //tree_control0->SetOnPreSelectHandler(make_callback(this, &TreeListDemo::OnPreSelectCallback));
 235 
 236         tree_control0->SetOnSelectHandler(make_callback(this, &TreeListDemo::OnSelectCallback));
 237 
 238         tree_control0->SetOnStateChangeHandler(make_callback(this, &TreeListDemo::OnStateChangeCallback));
 239 
 240         tree_control0->SetToolTipTextHandler(make_callback(this, &TreeListDemo::ToolTipTextCallback));
 241 
 242         //tree_control0->SetColumnSortHandler(make_callback(this, &TreeListDemo::ColumnSortCallback));
 243 
 244         tree_control0->SetStateIconNameHandler(make_callback(this, &TreeListDemo::StateIconNameCallback));
 245 
 246         tree_control0->SetOnBeginLabelEditHandler(make_callback(this, &TreeListDemo::OnBeginLabelEditCallback));
 247 
 248         tree_control0->SetOnEndLabelEditHandler(make_callback(this, &TreeListDemo::OnEndLabelEditCallback));        
 249 
 250         tree_control0->SetOnEditOptionSelectedHandler(make_callback(this, &TreeListDemo::OnEditOptionSelectedCallback));
 251 
 252         tree_control0->SetAskEditControlHandler(make_callback(this, &TreeListDemo::AskEditControlCallback));
 253 
 254         tree_control0->SetOnMenuHandler(make_callback(this, &TreeListDemo::OnMenuCallback));
 255 
 256         tree_control0->SetOnMenuSelectionHandler(make_callback(this, &TreeListDemo::OnMenuSelectionCallback));
 257 
 258         tree_control0->SetIsDropAllowedHandler(make_callback(this, &TreeListDemo::IsDropAllowedCallback));
 259 
 260         tree_control0->SetIsDragAllowedHandler(make_callback(this, &TreeListDemo::IsDragAllowedCallback));
 261 
 262         tree_control0->SetOnDropHandler(make_callback(this, &TreeListDemo::OnDropCallback));
 263 
 264         //tree_control0->SetOnDropMenuHandler(make_callback(this, &TreeListDemo::OnDropMenuCallback));
 265 
 266         tree_control0->SetOnDefaultActionHandler(make_callback(this, &TreeListDemo::OnDefaultAction));
 267 
 268         //------------------------------------------------------------------------------
 269 
 270         BlockStyler::PropertyList *stringPropList = nodeString->GetProperties() ;
 271         nodeBaseString = stringPropList->GetString("Value");    
 272         NXOpen::NXString nodeDisplayString = nodeBaseString;
 273         std::stringstream stringBuffer;
 274         stringBuffer << nodeSuffixNumber;            
 275         nodeDisplayString += stringBuffer.str();                
 276         stringPropList->SetString("Value",nodeDisplayString);            
 277         delete stringPropList;
 278     }
 279     catch(exception& ex)
 280     {
 281         //---- Enter your exception handling code here -----
 282         TreeListDemo::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
 283     }
 284 }
 285 
 286 enum Columns
 287 {
 288     ColumnFirst = 0,
 289     ColumnSecond = 1,
 290     ColumnThird = 2
 291 };
 292 BlockStyler::Node *previousAddedNode = NULL;    
 293 int randomIcon = 0;
 294 NXOpen::NXString randomIconString[] = {"extrude", "cone", "block", "blend"};
 295 
 296     
 297 
 298 
 299 //------------------------------------------------------------------------------
 300 //Callback Name: dialogShown_cb
 301 //This callback is executed just before the dialog launch. Thus any value set 
 302 //here will take precedence and dialog will be launched showing that value. 
 303 //------------------------------------------------------------------------------
 304 void TreeListDemo::dialogShown_cb()
 305 {
 306     try
 307     {
 308         //---- Enter your callback code here -----
 309 
 310         //Insert Columns        
 311         tree_control0->InsertColumn(ColumnFirst, "First Column", 80);
 312         tree_control0->InsertColumn(ColumnSecond, "Second Column", 80);
 313         tree_control0->InsertColumn(ColumnThird, "Third Column", 80);
 314 
 315         //Set resize policy for columns
 316         tree_control0->SetColumnResizePolicy(ColumnFirst, Tree::ColumnResizePolicyConstantWidth);
 317         tree_control0->SetColumnResizePolicy(ColumnSecond, Tree::ColumnResizePolicyConstantWidth);
 318         tree_control0->SetColumnResizePolicy(ColumnThird, Tree::ColumnResizePolicyConstantWidth);
 319 
 320         //Let the second column interpret the text as icon
 321         tree_control0->SetColumnDisplayType(ColumnSecond, Tree::ColumnDisplayIcon);        
 322     }
 323     catch(exception& ex)
 324     {
 325         //---- Enter your exception handling code here -----
 326         TreeListDemo::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
 327     }
 328 }
 329 
 330 //------------------------------------------------------------------------------
 331 //Callback Name: apply_cb
 332 //------------------------------------------------------------------------------
 333 int TreeListDemo::apply_cb()
 334 {
 335     int errorCode = 0;
 336     try
 337     {
 338         //---- Enter your callback code here -----
 339     }
 340     catch(exception& ex)
 341     {
 342         //---- Enter your exception handling code here -----
 343         errorCode = 1;
 344         TreeListDemo::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
 345     }
 346     return errorCode;
 347 }
 348 
 349 
 350 BlockStyler::Node* TreeListDemo::CreateAndAddNode(BlockStyler::Node* afterNode)
 351 {
 352     BlockStyler::Node *parentNode = NULL;
 353 
 354     //Get node display string from the block
 355     BlockStyler::PropertyList *stringPropList = nodeString->GetProperties() ;
 356     NXOpen::NXString nodeDisplayString = stringPropList->GetString("Value");
 357     delete stringPropList;
 358 
 359     BlockStyler::Node *node = tree_control0->CreateNode(nodeDisplayString);
 360 
 361     //Set few properties of node
 362     node->SetForegroundColor(198);
 363     node->SetDisplayIcon(randomIconString[randomIcon]);
 364     node->SetSelectedIcon("draft");
 365 
 366     //Take first selected node as parent node    
 367     std::vector<BlockStyler::Node *>selectedNodes=tree_control0->GetSelectedNodes();
 368     if (selectedNodes.size()>0)
 369     {
 370         parentNode = selectedNodes[0];    
 371     }
 372 
 373     //Insert Node
 374     tree_control0->InsertNode(node,parentNode,afterNode,tree_control0->NodeInsertOptionSort);
 375     node->ScrollTo(ColumnFirst,BlockStyler::Node::ScrollCenter);
 376 
 377     //Change the last node color. Making sure that new node color is distinct
 378     if (previousAddedNode != NULL)
 379     {
 380         previousAddedNode->SetForegroundColor(211);
 381     }
 382     previousAddedNode = node;    
 383     
 384     return node;    
 385 }
 386 
 387 
 388 void TreeListDemo::DeleteSelectedNodes()
 389 {
 390     std::vector<BlockStyler::Node *>selectedNodes=tree_control0->GetSelectedNodes();                
 391     if(selectedNodes.size()>0)
 392     {
 393         while(selectedNodes.size()>0)
 394         {
 395             tree_control0->DeleteNode(selectedNodes[0]);
 396             selectedNodes=tree_control0->GetSelectedNodes();
 397         }
 398     }
 399     else
 400     {
 401         theUI->NXMessageBox()->Show("Delete Node", NXOpen::NXMessageBox::DialogTypeInformation, "No Nodes are selected");
 402     } 
 403 }
 404 
 405 //Writes callback name to ListingWindow
 406 void TreeListDemo::WriteCallbackToListingWindow(NXString callbackName)
 407 {
 408     if (!listingWindowToggle)
 409         return;
 410     try
 411     {
 412         //---- Enter your callback code here -----
 413 
 414         NXOpen::BlockStyler::PropertyList *listingWindowToggleProps = listingWindowToggle->GetProperties();
 415         bool listingWindow = listingWindowToggleProps->GetLogical("Value");
 416         delete listingWindowToggleProps;
 417 
 418         if(listingWindow)
 419         {
 420             theSession->ListingWindow()->Open();
 421             NXString nullString = NULL;
 422             theSession->ListingWindow()->WriteLine(nullString);
 423             theSession->ListingWindow()->WriteLine(callbackName);
 424         }
 425     }
 426     catch(exception& ex)
 427     {
 428         //---- Enter your exception handling code here -----
 429         TreeListDemo::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
 430     }
 431 }
 432 
 433 
 434 //------------------------------------------------------------------------------
 435 //Callback Name: update_cb
 436 //------------------------------------------------------------------------------
 437 int TreeListDemo::update_cb(NXOpen::BlockStyler::UIBlock* block)
 438 {
 439     try
 440     {
 441         if(block == nodeString)
 442         {
 443             //---------Enter your code here-----------
 444         }
 445         else if(block == addNodeButton)
 446         {
 447             //---------Enter your code here-----------
 448             BlockStyler::Node *afterNode = NULL;
 449             BlockStyler::Node *node = CreateAndAddNode(afterNode);
 450 
 451             //State Icon
 452 
 453             BlockStyler::PropertyList *prop = stateIconOptions->GetProperties();
 454             int enumValue = prop->GetEnum("Value");
 455             delete prop;
 456 
 457             if(enumValue==0)
 458             {
 459                 //Ignore
 460             }
 461             else if(enumValue==1)
 462             {
 463                 node->SetState(1);
 464             }
 465             else if(enumValue==2)
 466             {
 467                 node->SetState(3);//set value other than 1 or 2
 468             }
 469         }
 470         else if(block == deleteNodeButton)
 471         {
 472             //---------Enter your code here-----------
 473             DeleteSelectedNodes();            
 474         }
 475         else if(block == stateIconOptions)
 476         {
 477             //---------Enter your code here-----------
 478         }
 479         else if(block == nodeToolTip)
 480         {
 481             //---------Enter your code here-----------
 482         }
 483         else if(block == nodeEditOptions)
 484         {
 485             //---------Enter your code here-----------
 486             if (!defaultActionToggle)
 487             {
 488                 return 0;
 489             }
 490 
 491             NXOpen::BlockStyler::PropertyList *nodeEditOptionsProps = nodeEditOptions->GetProperties();
 492             NXString nodeEditOption = nodeEditOptionsProps->GetEnumAsString("Value");
 493             delete nodeEditOptionsProps;
 494 
 495             NXOpen::BlockStyler::PropertyList *defaultActionToggleProps = defaultActionToggle->GetProperties();
 496 
 497             if(!(strcmp(nodeEditOption.GetText(),"Combo Box Edit"))||!(strcmp(nodeEditOption.GetText(),"Listbox Edit")))
 498             {
 499                 defaultActionToggleProps->SetLogical("Enable",false);
 500                 defaultActionToggleProps->SetLogical("Value",false);
 501             }
 502             else
 503             {
 504                 defaultActionToggleProps->SetLogical("Enable",true);
 505             }
 506             delete defaultActionToggleProps;
 507         }
 508         else if(block == showMenuToggle)
 509         {
 510             //---------Enter your code here-----------
 511         }
 512         else if(block == disallowDragToggle)
 513         {
 514             //---------Enter your code here-----------
 515         }
 516         else if(block == dropOptions)
 517         {
 518             //---------Enter your code here-----------
 519         }
 520         else if(block == defaultActionToggle)
 521         {
 522             //---------Enter your code here-----------
 523         }
 524         else if(block == instructions)
 525         {
 526             //---------Enter your code here-----------
 527         }
 528         else if(block == selection0)
 529         {
 530             //---------Enter your code here-----------
 531         }
 532         else if(block == addCrossSelectionNodeButton)
 533         {
 534             //---------Enter your code here-----------
 535             BlockStyler::PropertyList *prop = selection0->GetProperties();
 536             std::vector<NXOpen::TaggedObject *>objects = prop->GetTaggedObjectVector("SelectedObjects");
 537 
 538             if (objects.size()>0)
 539             {
 540                 //Create node and node data
 541                 BlockStyler::Node *node = tree_control0->CreateNode("CrossSelection-NodeData");
 542                 NXOpen::DataContainer *nodeData = node->GetNodeData();
 543                 nodeData->AddTaggedObject("Data",objects[0]);
 544                 delete nodeData;
 545                 tree_control0->InsertNode(node,NULL,NULL,tree_control0->NodeInsertOptionAlwaysLast);
 546 
 547                 //Reset Selection block
 548                 std::vector<TaggedObject *>blank;            
 549                 prop->SetTaggedObjectVector("SelectedObjects",blank);
 550             }
 551             delete prop;                     
 552         }
 553         else if(block == redrawInstruction)
 554         {
 555             //---------Enter your code here-----------
 556         }
 557         else if(block == redrawToggle)
 558         {
 559             //---------Enter your code here-----------
 560             BlockStyler::PropertyList *prop = redrawToggle->GetProperties();
 561             bool isRedraw = prop->GetLogical("Value");
 562             delete prop;
 563             tree_control0->Redraw(isRedraw);            
 564         }
 565         else if(block == listingWindowToggle)
 566         {
 567             //---------Enter your code here-----------
 568         }
 569     }
 570     catch(exception& ex)
 571     {
 572         //---- Enter your exception handling code here -----
 573         TreeListDemo::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
 574     }
 575     return 0;
 576 }
 577 
 578 //------------------------------------------------------------------------------
 579 //Callback Name: ok_cb
 580 //------------------------------------------------------------------------------
 581 int TreeListDemo::ok_cb()
 582 {
 583     int errorCode = 0;
 584     try
 585     {
 586         errorCode = apply_cb();
 587     }
 588     catch(exception& ex)
 589     {
 590         //---- Enter your exception handling code here -----
 591         errorCode = 1;
 592         TreeListDemo::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
 593     }
 594     return errorCode;
 595 }
 596 
 597 //------------------------------------------------------------------------------
 598 //Callback Name: focusNotify_cb
 599 //This callback is executed when any block (except the ones which receive keyboard entry such as Integer block) receives focus.
 600 //------------------------------------------------------------------------------
 601 void TreeListDemo::focusNotify_cb(NXOpen::BlockStyler::UIBlock* block, bool focus)
 602 {
 603     try
 604     {
 605         //---- Enter your callback code here -----
 606     }
 607     catch(exception& ex)
 608     {
 609         //---- Enter your exception handling code here -----
 610         TreeListDemo::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
 611     }
 612 }
 613 //------------------------------------------------------------------------------
 614 //Treelist specific callbacks
 615 //------------------------------------------------------------------------------
 616 //void TreeListDemo::OnExpandCallback (NXOpen::BlockStyler::Tree *tree, NXOpen::BlockStyler::Node *node)
 617 //{
 618 //}
 619 
 620 //void TreeListDemo::OnInsertColumnCallback(NXOpen::BlockStyler::Tree *tree, NXOpen::BlockStyler::Node *node, int columnID)
 621 //{
 622 //}
 623 
 624 void TreeListDemo::OnInsertNodeCallback(NXOpen::BlockStyler::Tree *tree, NXOpen::BlockStyler::Node *node)
 625 {
 626     try
 627     {
 628         //---- Enter your callback code here -----
 629         WriteCallbackToListingWindow("OnInsertNodeCallback Invoked");
 630 
 631         //Setting random icon
 632         if (randomIcon==0)
 633         {
 634             node->SetColumnDisplayText(ColumnSecond,randomIconString[randomIcon]);
 635         }
 636         else if (randomIcon==1)
 637         {
 638             node->SetColumnDisplayText(ColumnSecond,randomIconString[randomIcon]);
 639         }
 640         else if (randomIcon==2)
 641         {
 642             node->SetColumnDisplayText(ColumnSecond,randomIconString[randomIcon]);
 643         }
 644         else if (randomIcon==3)
 645         {
 646             node->SetColumnDisplayText(ColumnSecond,randomIconString[randomIcon]);
 647         }
 648         randomIcon = randomIcon + 1;
 649         if (randomIcon > 3)
 650         {
 651             randomIcon = 0;
 652         }
 653 
 654         std::stringstream stringBuffer;
 655         stringBuffer << "Column Text - "<<randomIcon;
 656         NXOpen::NXString columnText ;
 657         columnText += stringBuffer.str();
 658         node->SetColumnDisplayText(ColumnThird,columnText);
 659 
 660         if (nodeSuffixNumber == 15000)
 661         {
 662             nodeSuffixNumber = 0;
 663         }
 664         else
 665         {
 666             nodeSuffixNumber = nodeSuffixNumber + 1;
 667         }
 668 
 669         //New Node text for the next node
 670         std::stringstream stringBuffer1;
 671         BlockStyler::PropertyList *prop = nodeString->GetProperties();        
 672 
 673         NXOpen::NXString nodeDisplayString = nodeBaseString;
 674         stringBuffer1 << nodeSuffixNumber;
 675         nodeDisplayString += stringBuffer1.str();
 676         prop->SetString("Value",nodeDisplayString);
 677         delete prop;
 678     }
 679     catch(exception& ex)
 680     {
 681         //---- Enter your exception handling code here -----
 682         TreeListDemo::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
 683     }
 684 }
 685 
 686 void TreeListDemo::OnDeleteNodeCallback(NXOpen::BlockStyler::Tree *tree, NXOpen::BlockStyler::Node *node)
 687 {
 688     try
 689     {
 690         //---- Enter your callback code here -----
 691         WriteCallbackToListingWindow("OnDeleteNodeCallback Invoked");
 692 
 693         if(node==previousAddedNode)
 694         {
 695             //Set the previous node to Nothing. Done for safe execution.
 696             previousAddedNode = NULL;
 697         }          
 698     }
 699     catch(exception& ex)
 700     {
 701         //---- Enter your exception handling code here -----
 702         TreeListDemo::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
 703     }
 704 }
 705 
 706 //void TreeListDemo::OnPreSelectCallback(NXOpen::BlockStyler::Tree *tree, NXOpen::BlockStyler::Node *node, int ID, bool selected)
 707 //{
 708 //}
 709 
 710 void TreeListDemo::OnSelectCallback(NXOpen::BlockStyler::Tree *tree, NXOpen::BlockStyler::Node *node, int columnID, bool selected)
 711 {
 712     std::stringstream column;
 713     column << columnID;
 714 
 715     std::string text = std::string("OnSelectCallback Invoked: Node \"") + std::string(node->DisplayText().GetText()) + std::string("\" ") +  std::string(selected?"Selected":"Deselected") + std::string(selected?" at column ":"") + std::string(selected?column.str():"");
 716     WriteCallbackToListingWindow(text);    
 717 }
 718 
 719 void TreeListDemo::OnStateChangeCallback(NXOpen::BlockStyler::Tree *tree, NXOpen::BlockStyler::Node *node, int state)
 720 {
 721     try
 722     {
 723         //---- Enter your callback code here -----
 724         WriteCallbackToListingWindow("OnStateChangeCallback Invoked");
 725         if (state == 1)
 726         {
 727             node->SetState(2);
 728         }
 729         else if(state == 2)
 730         {
 731             node->SetState(1);
 732         }
 733         else if(state == 3)
 734         {
 735             node->SetState(4);
 736         }
 737         else if(state == 4)
 738         {
 739             node->SetState(3);
 740         }          
 741     }
 742     catch(exception& ex)
 743     {
 744         //---- Enter your exception handling code here -----
 745         TreeListDemo::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
 746     }
 747 }
 748 
 749 NXString TreeListDemo::ToolTipTextCallback(NXOpen::BlockStyler::Tree *tree, NXOpen::BlockStyler::Node *node, int columnID)
 750 {
 751     NXOpen::NXString ToolTipText;
 752     try
 753     {
 754         //---- Enter your callback code here -----
 755 
 756         BlockStyler::PropertyList *prop = nodeToolTip->GetProperties();
 757         ToolTipText = prop->GetString("Value");        
 758         delete prop;
 759     }
 760     catch(exception& ex)
 761     {
 762         //---- Enter your exception handling code here -----
 763         TreeListDemo::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
 764     }
 765     return ToolTipText;    
 766 }
 767 //The possible return values are 0, positive and negative value, suggesting respectively that both nodes are same, first node greater than second, and first node smaller than second.
 768 //int TreeListDemo::ColumnSortCallback(NXOpen::BlockStyler::Tree *tree, int columnID, NXOpen::BlockStyler::Node *node1, NXOpen::BlockStyler::Node *node2)
 769 //{
 770 //}
 771 
 772 NXString TreeListDemo::StateIconNameCallback(NXOpen::BlockStyler::Tree *tree, NXOpen::BlockStyler::Node *node, int state)
 773 {
 774     NXOpen::NXString stateIcon;
 775     try
 776     {
 777         //---- Enter your callback code here -----
 778         WriteCallbackToListingWindow("StateIconNameCallback Invoked");
 779         if(state==3)
 780         {
 781             stateIcon = "hole";
 782         }
 783         else if(state==4)
 784         {
 785             stateIcon = "boss";
 786         }
 787         else if(state==5)
 788         {
 789             stateIcon = "revolve";
 790         }
 791     }
 792     catch(exception& ex)
 793     {
 794         //---- Enter your exception handling code here -----
 795         TreeListDemo::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
 796     }
 797     return stateIcon;
 798 }
 799 
 800 NXOpen::BlockStyler::Tree::BeginLabelEditState TreeListDemo::OnBeginLabelEditCallback(NXOpen::BlockStyler::Tree *tree, NXOpen::BlockStyler::Node *node, int columnID)
 801 {
 802     NXOpen::BlockStyler::Tree::BeginLabelEditState OnBeginLabelEdit = BlockStyler::Tree::BeginLabelEditStateDisallow;
 803     try
 804     {
 805         //---- Enter your callback code here -----
 806         WriteCallbackToListingWindow("OnBeginLabelEditCallback Invoked");
 807         BlockStyler::PropertyList *prop = nodeEditOptions->GetProperties();
 808         int labelEditOption = prop->GetEnum("Value");
 809         delete prop;
 810 
 811         if (labelEditOption==1)
 812         {
 813             OnBeginLabelEdit = BlockStyler::Tree::BeginLabelEditStateAllow;
 814         }
 815         else
 816         {
 817             OnBeginLabelEdit = BlockStyler::Tree::BeginLabelEditStateDisallow;
 818         }
 819     }
 820     catch(exception& ex)
 821     {
 822         //---- Enter your exception handling code here -----
 823         TreeListDemo::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
 824     }
 825 
 826     return OnBeginLabelEdit;
 827 
 828 }
 829 
 830 NXOpen::BlockStyler::Tree::EndLabelEditState TreeListDemo::OnEndLabelEditCallback(NXOpen::BlockStyler::Tree *tree, NXOpen::BlockStyler::Node *node, int, NXString editedText)
 831 {
 832     NXOpen::BlockStyler::Tree::EndLabelEditState OnEndLabelEdit = BlockStyler::Tree::EndLabelEditStateRejectText;
 833     try
 834     {
 835         //---- Enter your callback code here -----
 836         WriteCallbackToListingWindow("OnEndLabelEditCallback Invoked");
 837 
 838         if(0 == strcmp(editedText.GetText(),"Reject") )
 839         {
 840             OnEndLabelEdit = BlockStyler::Tree::EndLabelEditStateRejectText;
 841         }
 842         else
 843         {
 844             OnEndLabelEdit = BlockStyler::Tree::EndLabelEditStateAcceptText;
 845         }
 846     }
 847     catch(exception& ex)
 848     {
 849         //---- Enter your exception handling code here -----
 850         TreeListDemo::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
 851     }
 852 
 853     return OnEndLabelEdit;
 854 
 855 }
 856 
 857 NXOpen::BlockStyler::Tree::EditControlOption TreeListDemo::OnEditOptionSelectedCallback(NXOpen::BlockStyler::Tree *tree, NXOpen::BlockStyler::Node *node, int columnID, int selectedOptionID, NXString selectedOptionText, NXOpen::BlockStyler::Tree::ControlType type)
 858 {
 859     NXOpen::BlockStyler::Tree::EditControlOption OnEditOptionSelected = BlockStyler::Tree::EditControlOptionReject;    
 860     try
 861     {
 862         //---- Enter your callback code here -----
 863 
 864         if (BlockStyler::Tree::ControlTypeComboBox == type)
 865         {
 866             if (0 == strcmp(selectedOptionText.GetText(),"ComboBox-RejectText"))
 867             {
 868                 OnEditOptionSelected = BlockStyler::Tree::EditControlOptionReject;
 869             }
 870             else
 871             {
 872                 OnEditOptionSelected = BlockStyler::Tree::EditControlOptionAccept;
 873             }
 874         }
 875         else if (BlockStyler::Tree::ControlTypeListBox == type)
 876         {
 877             if (0 == strcmp(selectedOptionText.GetText(),"ListBox-RejectText"))
 878             {
 879                 OnEditOptionSelected = BlockStyler::Tree::EditControlOptionReject;
 880             }
 881             else
 882             {
 883                 OnEditOptionSelected = BlockStyler::Tree::EditControlOptionAccept;
 884             }
 885         }                          
 886     }
 887     catch(exception& ex)
 888     {
 889         //---- Enter your exception handling code here -----
 890         TreeListDemo::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
 891     }
 892 
 893     return OnEditOptionSelected;
 894 }
 895 
 896 NXOpen::BlockStyler::Tree::ControlType TreeListDemo::AskEditControlCallback(NXOpen::BlockStyler::Tree *tree, NXOpen::BlockStyler::Node *node, int columnID)
 897 {
 898     NXOpen::BlockStyler::Tree::ControlType AskEditControl = BlockStyler::Tree::ControlTypeNone;;
 899 
 900     try
 901     {
 902         //---- Enter your callback code here -----
 903         BlockStyler::PropertyList *prop = nodeEditOptions->GetProperties();
 904         int labelEditOption = prop->GetEnum("Value");
 905         delete prop;
 906 
 907         if(labelEditOption==2)
 908         {
 909             AskEditControl = BlockStyler::Tree::ControlTypeComboBox;  
 910             std::vector<NXOpen::NXString> options;
 911             options.push_back(NXOpen::NXString("ComboBox-AcceptText"));
 912             options.push_back(NXOpen::NXString("ComboBox-DefaultText"));
 913             options.push_back(NXOpen::NXString("ComboBox-RejectText"));
 914             tree->SetEditOptions(options,1);    
 915         }
 916         else if(labelEditOption==3)
 917         {
 918             AskEditControl = BlockStyler::Tree::ControlTypeListBox;
 919             
 920             std::vector<NXOpen::NXString> options;
 921             options.push_back(NXOpen::NXString("ListBox-AcceptText"));
 922             options.push_back(NXOpen::NXString("ListBox-DefaultText"));
 923             options.push_back(NXOpen::NXString("ListBox-RejectText"));
 924 
 925             tree->SetEditOptions(options,1);        
 926         }                                   
 927     }
 928     catch(exception& ex)
 929     {
 930         //---- Enter your exception handling code here -----
 931         TreeListDemo::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
 932     }
 933     return AskEditControl;
 934 }
 935 
 936 enum MenuID
 937 {
 938     AddNode = 0,
 939     DeleteNode,
 940     CheckedMenuItem,
 941     DefaultMenuItem,
 942     DialogLaunchMenuItem,
 943     DisableMenuItem,
 944     HiddenMenuItem,
 945     IconMenuItem,
 946 
 947     SubMenu1,
 948     SubMenu2,
 949     SubMenuItem1,
 950     SubMenuItem2,
 951     SubMenuItem3,
 952     SubMenuItem4,
 953 
 954     TreeMenuItem,
 955 };
 956 
 957 
 958 void TreeListDemo::OnMenuCallback(NXOpen::BlockStyler::Tree *tree, NXOpen::BlockStyler::Node *node, int columnID)
 959 {
 960     try
 961     {
 962         //---- Enter your callback code here -----
 963         WriteCallbackToListingWindow("OnMenuCallback Invoked");
 964         BlockStyler::PropertyList *prop = showMenuToggle->GetProperties() ;
 965         bool value = prop->GetLogical("Value");
 966         delete prop;
 967 
 968         if(value == false)
 969         {
 970             return;
 971         }
 972 
 973         //Create Menu
 974         BlockStyler::TreeListMenu *menu = tree->CreateMenu();
 975         BlockStyler::TreeListMenu *SubMenu1 = tree->CreateMenu();
 976         BlockStyler::TreeListMenu *SubMenu2 = tree->CreateMenu();
 977 
 978 
 979         if(node==NULL)
 980         {
 981             menu->AddMenuItem(AddNode,"Add Node");
 982             menu->AddSeparator();
 983             menu->AddMenuItem(TreeMenuItem,"Tree menu item");            
 984         }
 985         else //Menu request for Node
 986         {
 987             menu->AddMenuItem(AddNode,"Add Node");
 988             menu->AddMenuItem(MenuID(DeleteNode),"Delete Node");
 989 
 990 
 991             menu->AddSeparator();
 992             menu->AddMenuItem(CheckedMenuItem,"Checked Menu Item");
 993             menu->AddMenuItem(DefaultMenuItem,"Default Menu Item");
 994             menu->AddMenuItem(DialogLaunchMenuItem,"Dialog Launch Menu Item");
 995             menu->AddMenuItem(DisableMenuItem,"Disable Menu Item");
 996             menu->AddMenuItem(HiddenMenuItem,"Hidden Menu Item");
 997             menu->AddMenuItem(IconMenuItem,"Icon Menu Item");
 998 
 999             menu->AddSeparator();
1000             menu->AddMenuItem(::SubMenu1,"Sub Menu 1");
1001             menu->AddMenuItem(::SubMenu2,"Sub Menu 2");
1002 
1003             //Sub Menu
1004             SubMenu1->AddMenuItem(SubMenuItem1,"Sub Menu Item 1");
1005             SubMenu1->AddMenuItem(SubMenuItem2,"Sub Menu Item 2");
1006 
1007             SubMenu2->AddMenuItem(SubMenuItem3,"Sub Menu Item 3");
1008             SubMenu2->AddMenuItem(SubMenuItem4,"Sub Menu Item 4");
1009 
1010             //Set Sub Menu
1011             menu->SetSubMenu(::SubMenu1,SubMenu1);
1012             menu->SetSubMenu(::SubMenu2,SubMenu2);
1013 
1014             //Edit Menu Items
1015             menu->SetItemChecked(CheckedMenuItem,true);
1016             menu->SetItemDefault(DefaultMenuItem,true);
1017             menu->SetItemDialogLaunching(DialogLaunchMenuItem,true);
1018             menu->SetItemDisable(DisableMenuItem,true);
1019             menu->SetItemHidden(HiddenMenuItem,true);
1020             menu->SetItemIcon(IconMenuItem,"sketch");
1021         }
1022 
1023         //Set menu on tree
1024         tree->SetMenu(menu);
1025 
1026         //Dispose the menu only after setting the menu on tree
1027         delete menu;
1028         delete SubMenu1;
1029         delete SubMenu2;            
1030     }
1031     catch(exception& ex)
1032     {
1033         //---- Enter your exception handling code here -----
1034         TreeListDemo::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
1035     }
1036 }
1037 
1038 void TreeListDemo::OnMenuSelectionCallback(NXOpen::BlockStyler::Tree *tree, NXOpen::BlockStyler::Node *node, int menuItemID)
1039 {
1040     try
1041     {
1042         //---- Enter your callback code here -----
1043         WriteCallbackToListingWindow("OnMenuSelectionCallback Invoked");
1044         if(node==NULL)
1045         {
1046             if((MenuID)menuItemID == AddNode)
1047             {
1048                 CreateAndAddNode(NULL);
1049             }
1050         }
1051         else 
1052         {
1053             if((MenuID)menuItemID == AddNode)
1054             {
1055                 CreateAndAddNode(NULL);
1056             }
1057             else if((MenuID)menuItemID == DeleteNode)
1058             {
1059                 std::vector<BlockStyler::Node *>SelectedNodes = tree_control0->GetSelectedNodes();
1060                 if(SelectedNodes.size()>0)
1061                 {
1062                     DeleteSelectedNodes();
1063                 }
1064                 else 
1065                 {                        
1066                     if(node!=NULL)
1067                     {
1068                         tree->DeleteNode(node);
1069                     }                        
1070                 }
1071             }
1072         }
1073     }
1074     catch(exception& ex)
1075     {
1076         //---- Enter your exception handling code here -----
1077         TreeListDemo::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
1078     }
1079 }
1080 
1081 NXOpen::BlockStyler::Node::DropType TreeListDemo::IsDropAllowedCallback(NXOpen::BlockStyler::Tree *tree, NXOpen::BlockStyler::Node *node, int columnID, NXOpen::BlockStyler::Node *targetNode, int targetColumnID)
1082 {
1083     NXOpen::BlockStyler::Node::DropType IsDropAllowed;
1084     try
1085     {
1086         //---- Enter your callback code here -----
1087         BlockStyler::PropertyList *prop = dropOptions->GetProperties() ;
1088         int dropOption = prop->GetEnum("Value");
1089         delete prop;
1090 
1091         // This will just show iconic representation that drop is allowed. No default action is performed after drop.
1092         // OnDropCallback should be implemented for specific drop behaviour
1093 
1094         if (dropOption == 0)
1095         {
1096             IsDropAllowed = BlockStyler::Node::DropTypeNone;
1097         }
1098         else if (dropOption == 1)
1099         {
1100             IsDropAllowed = BlockStyler::Node::DropTypeAfter;
1101         }
1102         else if (dropOption == 2)
1103         {
1104             IsDropAllowed = BlockStyler::Node::DropTypeBefore;
1105         }
1106         else if (dropOption == 3)
1107         {
1108             IsDropAllowed = BlockStyler::Node::DropTypeBeforeAndAfter;
1109         }
1110         else if (dropOption == 4)
1111         {
1112             IsDropAllowed = BlockStyler::Node::DropTypeOn;
1113         }
1114     }
1115     catch(exception& ex)
1116     {
1117         //---- Enter your exception handling code here -----
1118         TreeListDemo::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
1119     }
1120     return IsDropAllowed;
1121 }
1122 
1123 NXOpen::BlockStyler::Node::DragType TreeListDemo::IsDragAllowedCallback(NXOpen::BlockStyler::Tree *tree, NXOpen::BlockStyler::Node *node, int columnID)
1124 {
1125     NXOpen::BlockStyler::Node::DragType IsDragAllowedCallback;
1126     try
1127     {
1128         //---- Enter your callback code here -----
1129         BlockStyler::PropertyList *prop = disallowDragToggle->GetProperties() ;
1130         bool isDragDisallowed = prop->GetLogical("Value");
1131         delete prop;
1132 
1133         if(isDragDisallowed == true)
1134         {
1135             IsDragAllowedCallback = BlockStyler::Node::DragTypeNone;
1136         }
1137         else
1138         {
1139             IsDragAllowedCallback = BlockStyler::Node::DragTypeAll;
1140         }
1141     }
1142     catch(exception& ex)
1143     {
1144         //---- Enter your exception handling code here -----
1145         TreeListDemo::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
1146     }
1147 
1148     return IsDragAllowedCallback;
1149 }
1150 
1151 bool TreeListDemo::OnDropCallback(NXOpen::BlockStyler::Tree *tree, std::vector<NXOpen::BlockStyler::Node *> node, int columnID, NXOpen::BlockStyler::Node *targetNode, int targetColumnID, NXOpen::BlockStyler::Node::DropType dropType, int dropMenuItemId)
1152 {
1153     try
1154     {
1155         //---- Enter your callback code here -----
1156         WriteCallbackToListingWindow("OnDropCallback Invoked");
1157     }
1158     catch(exception& ex)
1159     {
1160         //---- Enter your exception handling code here -----
1161         TreeListDemo::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
1162     }
1163     return true;
1164 }
1165 
1166 //void TreeListDemo::OnDropMenuCallback(NXOpen::BlockStyler::Tree *tree, NXOpen::BlockStyler::Node *node, int columnID, NXOpen::BlockStyler::Node *targetNode, int targetColumnID)
1167 //{
1168 //}
1169 
1170 void TreeListDemo::OnDefaultAction(NXOpen::BlockStyler::Tree *tree, NXOpen::BlockStyler::Node *node, int columnID)
1171 {
1172      try
1173     {
1174         //---- Enter your callback code here -----
1175         WriteCallbackToListingWindow("OnDefaultAction Invoked");
1176 
1177         if (!defaultActionToggle)
1178         {
1179             return;
1180         }
1181 
1182         NXOpen::BlockStyler::PropertyList *defaultActionToggleProps = defaultActionToggle->GetProperties();
1183         bool defaultActionToggle = defaultActionToggleProps->GetLogical("Value");
1184         delete defaultActionToggleProps;
1185 
1186         if(defaultActionToggle)
1187         {
1188             std::vector<BlockStyler::Node *> selectedNode = tree_control0->GetSelectedNodes();
1189             selectedNode[0]->SetColumnDisplayText(2,"Default Action");                
1190             TreeListDemo::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeInformation, "Default Action: Third column text is changed");
1191             selectedNode.clear();
1192         }
1193     }
1194     catch(exception& ex)
1195     {
1196         //---- Enter your exception handling code here -----
1197         TreeListDemo::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
1198     }
1199 }
1200 
1201 
1202 Caesar卢尚宇
1203 2019年11月23日

猜你喜欢

转载自www.cnblogs.com/nxopen2018/p/11920356.html
今日推荐