zoukankan      html  css  js  c++  java
  • NXOpen 树列表实例(创建列、节点、创建下拉菜单、创建右键菜单和响应、文本输入和响应、自动输入系统日期)

    C++

    //HPP头文件内容

    #include <uf_defs.h>
    #include <uf_ui_types.h>
    #include <iostream>
    #include <NXOpen/Session.hxx>
    #include <NXOpen/UI.hxx>
    #include <NXOpen/NXMessageBox.hxx>
    #include <NXOpen/Callback.hxx>
    #include <NXOpen/NXException.hxx>
    #include <NXOpen/BlockStyler_UIBlock.hxx>
    #include <NXOpen/BlockStyler_BlockDialog.hxx>
    #include <NXOpen/BlockStyler_PropertyList.hxx>
    #include <NXOpen/BlockStyler_Tree.hxx>
    #include <NXOpen/BlockStyler_Node.hxx>
    #include <NXOpen/BlockStyler_Group.hxx>
    #include <NXOpen/BlockStyler_Button.hxx>

    //用户头文件
    #include <NXOpen/Part.hxx>
    #include <NXOpen/PartCollection.hxx>
    #include <uf.h>

    //------------------------------------------------------------------------------
    // Namespaces needed for following template
    //------------------------------------------------------------------------------
    using namespace std;
    using namespace NXOpen;
    using namespace NXOpen::BlockStyler;

    class DllExport TreeSample
    {
    // class members
    public:
    static Session *theSession;
    static UI *theUI;
    TreeSample();
    ~TreeSample();
    int Show();

    //----------------------- BlockStyler Callback Prototypes ---------------------
    // The following member function prototypes define the callbacks
    // specified in your BlockStyler dialog. The empty implementation
    // of these prototypes is provided in the TreeSample.cpp file.
    // You are REQUIRED to write the implementation for these functions.
    //------------------------------------------------------------------------------
    void initialize_cb();
    void dialogShown_cb();
    int apply_cb();
    int ok_cb();
    int update_cb(NXOpen::BlockStyler::UIBlock* block);
    PropertyList* GetBlockProperties(const char *blockID);

    //void OnExpandCallback (NXOpen::BlockStyler::Tree *tree, NXOpen::BlockStyler::Node *node);
    //void OnInsertColumnCallback(NXOpen::BlockStyler::Tree *tree, NXOpen::BlockStyler::Node *node, int columnID);
    //void OnInsertNodeCallback(NXOpen::BlockStyler::Tree *tree, NXOpen::BlockStyler::Node *node);
    //void OnDeleteNodeCallback(NXOpen::BlockStyler::Tree *tree, NXOpen::BlockStyler::Node *node);
    //void OnPreSelectCallback(NXOpen::BlockStyler::Tree *tree, NXOpen::BlockStyler::Node *node, int ID, bool selected);
    //void OnSelectCallback(NXOpen::BlockStyler::Tree *tree, NXOpen::BlockStyler::Node *, int columnID, bool selected);
    //void OnStateChangeCallback(NXOpen::BlockStyler::Tree *tree, NXOpen::BlockStyler::Node *node, int state);
    //NXString ToolTipTextCallback(NXOpen::BlockStyler::Tree *tree, NXOpen::BlockStyler::Node *node, int columnID);
    //int ColumnSortCallback(NXOpen::BlockStyler::Tree *tree, int columnID, NXOpen::BlockStyler::Node *node1, NXOpen::BlockStyler::Node *node2);
    //NXString StateIconNameCallback(NXOpen::BlockStyler::Tree *tree, NXOpen::BlockStyler::Node *node, int state);
    NXOpen::BlockStyler::Tree::BeginLabelEditState OnBeginLabelEditCallback(NXOpen::BlockStyler::Tree *tree, NXOpen::BlockStyler::Node *node, int columnID);//根据函数返回值来确定是否允许编辑选中的单元格文本
    NXOpen::BlockStyler::Tree::EndLabelEditState OnEndLabelEditCallback(NXOpen::BlockStyler::Tree *tree, NXOpen::BlockStyler::Node *node, int, NXString editedText);//根据返回值确定是否接受修改的文本
    NXOpen::BlockStyler::Tree::EditControlOption OnEditOptionSelectedCallback(NXOpen::BlockStyler::Tree *tree, NXOpen::BlockStyler::Node *node, int columnID, int selectedOptionID, NXString selectedOptionText, NXOpen::BlockStyler::Tree::ControlType type);//编辑Tree::ControlTypeComboBox类型、Tree::ControlTypeListBox类型单元格时触发
    NXOpen::BlockStyler::Tree::ControlType AskEditControlCallback(NXOpen::BlockStyler::Tree *tree, NXOpen::BlockStyler::Node *node, int columnID);//可以设置单元格类型ControlTypeNone 、ControlTypeComboBox、ControlTypeListBox,以及下拉列表内容
    void OnMenuCallback(NXOpen::BlockStyler::Tree *tree, NXOpen::BlockStyler::Node *node, int columnID );//菜单内容回调函数
    void OnMenuSelectionCallback(NXOpen::BlockStyler::Tree *tree, NXOpen::BlockStyler::Node *node, int menuItemID);//选择菜单时回调函数
    //NXOpen::BlockStyler::Node::DropType IsDropAllowedCallback(NXOpen::BlockStyler::Tree *tree, NXOpen::BlockStyler::Node *node, int columnID, NXOpen::BlockStyler::Node *targetNode, int targetColumnID);
    //NXOpen::BlockStyler::Node::DragType IsDragAllowedCallback(NXOpen::BlockStyler::Tree *tree, NXOpen::BlockStyler::Node *node, int columnID);
    //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);
    //void OnDropMenuCallback(NXOpen::BlockStyler::Tree *tree, NXOpen::BlockStyler::Node *node, int columnID, NXOpen::BlockStyler::Node *targetNode, int targetColumnID);
    //void OnDefaultAction(NXOpen::BlockStyler::Tree *tree, NXOpen::BlockStyler::Node *node, int columnID);
    private:
    const char* theDlxFileName;
    NXOpen::BlockStyler::BlockDialog* theDialog;
    NXOpen::BlockStyler::Group* group0;// Block type: Group
    NXOpen::BlockStyler::Tree* tree_control0;// Block type: Tree Control
    NXOpen::BlockStyler::Button* button0;// Block type: Button

    //用户代码
    Part *displayPart;//private 下定义displayPart为全局变量
    Part *workPart;//private 下定义workPart为全局变量


    };
    #endif //TREESAMPLE_H_INCLUDED

    //CPP文件内容

    //==============================================================================
    // WARNING!! This file is overwritten by the Block UI Styler while generating
    // the automation code. Any modifications to this file will be lost after
    // generating the code again.
    //
    // Filename: D:YiNing tools1_NXopenAPITreeSampleTreeSample.cpp
    //
    // This file was generated by the NX Block UI Styler
    // Created by: Administrator
    // Version: NX 8.5
    // Date: 01-01-2021 (Format: mm-dd-yyyy)
    // Time: 12:52 (Format: hh-mm)
    //
    //==============================================================================

    //==============================================================================
    // Purpose: This TEMPLATE file contains C++ source to guide you in the
    // construction of your Block application dialog. The generation of your
    // dialog file (.dlx extension) is the first step towards dialog construction
    // within NX. You must now create a NX Open application that
    // utilizes this file (.dlx).
    //
    // The information in this file provides you with the following:
    //
    // 1. Help on how to load and display your Block UI Styler dialog in NX
    // using APIs provided in NXOpen.BlockStyler namespace
    // 2. The empty callback methods (stubs) associated with your dialog items
    // have also been placed in this file. These empty methods have been
    // created simply to start you along with your coding requirements.
    // The method name, argument list and possible return values have already
    // been provided for you.
    //==============================================================================

    //------------------------------------------------------------------------------
    //These includes are needed for the following template code
    //------------------------------------------------------------------------------
    #include "TreeSample.hpp"
    using namespace NXOpen;
    using namespace NXOpen::BlockStyler;

    //------------------------------------------------------------------------------
    // Initialize static variables
    //------------------------------------------------------------------------------
    Session *(TreeSample::theSession) = NULL;
    UI *(TreeSample::theUI) = NULL;
    //------------------------------------------------------------------------------
    // Constructor for NX Styler class
    //------------------------------------------------------------------------------
    TreeSample::TreeSample()
    {
    try
    {
    // Initialize the NX Open C++ API environment
    TreeSample::theSession = NXOpen::Session::GetSession();
    TreeSample::theUI = UI::GetUI();
    theDlxFileName = "TreeSample.dlx";
    theDialog = TreeSample::theUI->CreateDialog(theDlxFileName);
    // Registration of callback functions
    theDialog->AddApplyHandler(make_callback(this, &TreeSample::apply_cb));
    theDialog->AddOkHandler(make_callback(this, &TreeSample::ok_cb));
    theDialog->AddUpdateHandler(make_callback(this, &TreeSample::update_cb));
    theDialog->AddInitializeHandler(make_callback(this, &TreeSample::initialize_cb));
    theDialog->AddDialogShownHandler(make_callback(this, &TreeSample::dialogShown_cb));
    }
    catch(exception& ex)
    {
    //---- Enter your exception handling code here -----
    throw;
    }
    }

    //------------------------------------------------------------------------------
    // Destructor for NX Styler class
    //------------------------------------------------------------------------------
    TreeSample::~TreeSample()
    {
    if (theDialog != NULL)
    {
    delete theDialog;
    theDialog = NULL;
    }
    }
    //------------------------------- DIALOG LAUNCHING ---------------------------------
    //
    // Before invoking this application one needs to open any part/empty part in NX
    // because of the behavior of the blocks.
    //
    // Make sure the dlx file is in one of the following locations:
    // 1.) From where NX session is launched
    // 2.) $UGII_USER_DIR/application
    // 3.) For released applications, using UGII_CUSTOM_DIRECTORY_FILE is highly
    // recommended. This variable is set to a full directory path to a file
    // containing a list of root directories for all custom applications.
    // e.g., UGII_CUSTOM_DIRECTORY_FILE=$UGII_ROOT_DIRmenuscustom_dirs.dat
    //
    // You can create the dialog using one of the following way:
    //
    // 1. USER EXIT
    //
    // 1) Create the Shared Library -- Refer "Block UI Styler programmer's guide"
    // 2) Invoke the Shared Library through File->Execute->NX Open menu.
    //
    //------------------------------------------------------------------------------
    extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
    {
    TreeSample *theTreeSample = NULL;
    try
    {
    theTreeSample = new TreeSample();
    // The following method shows the dialog immediately
    theTreeSample->Show();
    }
    catch(exception& ex)
    {
    //---- Enter your exception handling code here -----
    TreeSample::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
    }
    if(theTreeSample != NULL)
    {
    delete theTreeSample;
    theTreeSample = NULL;
    }
    }

    //------------------------------------------------------------------------------
    // This method specifies how a shared image is unloaded from memory
    // within NX. This method gives you the capability to unload an
    // internal NX Open application or user exit from NX. Specify any
    // one of the three constants as a return value to determine the type
    // of unload to perform:
    //
    //
    // Immediately : unload the library as soon as the automation program has completed
    // Explicitly : unload the library from the "Unload Shared Image" dialog
    // AtTermination : unload the library when the NX session terminates
    //
    //
    // NOTE: A program which associates NX Open applications with the menubar
    // MUST NOT use this option since it will UNLOAD your NX Open application image
    // from the menubar.
    //------------------------------------------------------------------------------
    extern "C" DllExport int ufusr_ask_unload()
    {
    //return (int)Session::LibraryUnloadOptionExplicitly;
    return (int)Session::LibraryUnloadOptionImmediately;
    //return (int)Session::LibraryUnloadOptionAtTermination;
    }

    //------------------------------------------------------------------------------
    // Following method cleanup any housekeeping chores that may be needed.
    // This method is automatically called by NX.
    //------------------------------------------------------------------------------
    extern "C" DllExport void ufusr_cleanup(void)
    {
    try
    {
    //---- Enter your callback code here -----
    }
    catch(exception& ex)
    {
    //---- Enter your exception handling code here -----
    TreeSample::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
    }
    }

    int TreeSample::Show()
    {
    try
    {
    theDialog->Show();
    }
    catch(exception& ex)
    {
    //---- Enter your exception handling code here -----
    TreeSample::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
    }
    return 0;
    }

    //------------------------------------------------------------------------------
    //---------------------Block UI Styler Callback Functions--------------------------
    //------------------------------------------------------------------------------

    //------------------------------------------------------------------------------
    //Callback Name: initialize_cb
    //------------------------------------------------------------------------------
    void TreeSample::initialize_cb()
    {
    try
    {
    group0 = dynamic_cast<NXOpen::BlockStyler::Group*>(theDialog->TopBlock()->FindBlock("group0"));
    tree_control0 = dynamic_cast<NXOpen::BlockStyler::Tree*>(theDialog->TopBlock()->FindBlock("tree_control0"));
    button0 = dynamic_cast<NXOpen::BlockStyler::Button*>(theDialog->TopBlock()->FindBlock("button0"));
    //------------------------------------------------------------------------------
    //Registration of Treelist specific callbacks
    //------------------------------------------------------------------------------
    //tree_control0->SetOnExpandHandler(make_callback(this, &TreeSample::OnExpandCallback));

    //tree_control0->SetOnInsertColumnHandler(make_callback(this, &TreeSample::OnInsertColumnCallback));

    //tree_control0->SetOnInsertNodeHandler(make_callback(this, &TreeSample::OnInsertNodeCallback));

    //tree_control0->SetOnDeleteNodeHandler(make_callback(this, &TreeSample::OnDeleteNodeCallback));

    //tree_control0->SetOnPreSelectHandler(make_callback(this, &TreeSample::OnPreSelectCallback));

    //tree_control0->SetOnSelectHandler(make_callback(this, &TreeSample::OnSelectCallback));

    //tree_control0->SetOnStateChangeHandler(make_callback(this, &TreeSample::OnStateChangeCallback));

    //tree_control0->SetToolTipTextHandler(make_callback(this, &TreeSample::ToolTipTextCallback));

    //tree_control0->SetColumnSortHandler(make_callback(this, &TreeSample::ColumnSortCallback));

    //tree_control0->SetStateIconNameHandler(make_callback(this, &TreeSample::StateIconNameCallback));

    tree_control0->SetOnBeginLabelEditHandler(make_callback(this, &TreeSample::OnBeginLabelEditCallback));//根据函数返回值来确定是否允许编辑选中的单元格文本

    tree_control0->SetOnEndLabelEditHandler(make_callback(this, &TreeSample::OnEndLabelEditCallback));//根据返回值确定是否接受修改的文本

    tree_control0->SetOnEditOptionSelectedHandler(make_callback(this, &TreeSample::OnEditOptionSelectedCallback));//编辑Tree::ControlTypeComboBox类型、Tree::ControlTypeListBox类型单元格时触发

    tree_control0->SetAskEditControlHandler(make_callback(this, &TreeSample::AskEditControlCallback));//可以设置单元格类型ControlTypeNone 、ControlTypeComboBox、ControlTypeListBox,以及下拉列表内容

    tree_control0->SetOnMenuHandler(make_callback(this, &TreeSample::OnMenuCallback));//菜单内容回调函数

    tree_control0->SetOnMenuSelectionHandler(make_callback(this, &TreeSample::OnMenuSelectionCallback));//选择菜单时回调函数

    //tree_control0->SetIsDropAllowedHandler(make_callback(this, &TreeSample::IsDropAllowedCallback));

    //tree_control0->SetIsDragAllowedHandler(make_callback(this, &TreeSample::IsDragAllowedCallback));

    //tree_control0->SetOnDropHandler(make_callback(this, &TreeSample::OnDropCallback));

    //tree_control0->SetOnDropMenuHandler(make_callback(this, &TreeSample::OnDropMenuCallback));

    //tree_control0->SetOnDefaultActionHandler(make_callback(this, &TreeSample::OnDefaultAction));

    //------------------------------------------------------------------------------

    //用户代码
    displayPart = theSession->Parts()->Display();//获取显示部件
    workPart = theSession->Parts()->Work();//获取工作部件
    theDialog->TopBlock()->FindBlock("Dialog")->GetProperties()->SetString("Label","树列表实例 制作:黄庆生");//对话框标题设置
    button0->GetProperties()->SetString("Label","制作:Alan Huange QQ:185266370"); //修改按钮显示的内容
    this->tree_control0->GetProperties()->SetInteger("Height",300);//设置树列表高度

    }
    catch(exception& ex)
    {
    //---- Enter your exception handling code here -----
    TreeSample::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
    }
    }

    //------------------------------------------------------------------------------
    //Callback Name: dialogShown_cb
    //This callback is executed just before the dialog launch. Thus any value set
    //here will take precedence and dialog will be launched showing that value.
    //------------------------------------------------------------------------------

    void TreeSample::dialogShown_cb()
    {
    try
    {
    //---- Enter your callback code here -----
    //用户代码
    //创建列
    this->tree_control0->InsertColumn(0,"工件号",80);
    this->tree_control0->InsertColumn(1,"工件名字",80);
    this->tree_control0->InsertColumn(2,"备注",100);
    this->tree_control0->InsertColumn(3,"设计",80);
    this->tree_control0->InsertColumn(4,"QQ",100);
    this->tree_control0->InsertColumn(5,"日期",100);

    //插入节点
    Node *node = this->tree_control0->CreateNode("1-001");//第一例节点显示内容
    this->tree_control0->InsertNode(node,NULL,NULL,Tree::NodeInsertOptionAlwaysFirst);//括号内容(创建的节点,父节点,子节点,插入节点的顺序控制(有5种))
    node->SetColumnDisplayText(1,"后模仁");//第二例节点显示内容
    node->SetColumnDisplayText(2,"粗料");//第三例节点显示内容
    node->SetColumnDisplayText(3,"黄庆生");//第四例节点显示内容
    node->SetColumnDisplayText(4,"185266370");//第五例节点显示内容

    //获取日期
    UF_system_info_t info; //定义info
    UF_ask_system_info(&info); //获取系统日期时间
    //格式化日期
    string formatdate = info.date_buf; //转换获得的日期和时间为字符串
    char msgdate[256]; //定义数簇
    sprintf(msgdate,"%s-%s-%s",formatdate.substr(0,4),formatdate.substr(5,2),formatdate.substr(8,2)); //格式化日期
    node->SetColumnDisplayText(5,msgdate); //输入读取的系统时间创建6列节点
    UF_free_system_info(&info);//释放内存


    tree_control0-> SetPreSelectionTimeOut(0);//设置触发OnPreSelectCallback回调函数反应时间,参数单位是“秒”,默认为1秒


    }
    catch(exception& ex)
    {
    //---- Enter your exception handling code here -----
    TreeSample::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
    }
    }

    //------------------------------------------------------------------------------
    //Callback Name: apply_cb
    //------------------------------------------------------------------------------
    int TreeSample::apply_cb()
    {
    int errorCode = 0;
    try
    {
    //---- Enter your callback code here -----
    }
    catch(exception& ex)
    {
    //---- Enter your exception handling code here -----
    errorCode = 1;
    TreeSample::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
    }
    return errorCode;
    }

    //------------------------------------------------------------------------------
    //Callback Name: update_cb
    //------------------------------------------------------------------------------
    int TreeSample::update_cb(NXOpen::BlockStyler::UIBlock* block)
    {
    try
    {
    if(block == button0)
    {
    //---------Enter your code here-----------
    }
    }
    catch(exception& ex)
    {
    //---- Enter your exception handling code here -----
    TreeSample::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
    }
    return 0;
    }

    //------------------------------------------------------------------------------
    //Callback Name: ok_cb
    //------------------------------------------------------------------------------
    int TreeSample::ok_cb()
    {
    int errorCode = 0;
    try
    {
    errorCode = apply_cb();
    }
    catch(exception& ex)
    {
    //---- Enter your exception handling code here -----
    errorCode = 1;
    TreeSample::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
    }
    return errorCode;
    }
    //------------------------------------------------------------------------------
    //Treelist specific callbacks
    //------------------------------------------------------------------------------
    //void TreeSample::OnExpandCallback (NXOpen::BlockStyler::Tree *tree, NXOpen::BlockStyler::Node *node)
    //{
    //}

    //void TreeSample::OnInsertColumnCallback(NXOpen::BlockStyler::Tree *tree, NXOpen::BlockStyler::Node *node, int columnID)
    //{
    //}

    //void TreeSample::OnInsertNodeCallback(NXOpen::BlockStyler::Tree *tree, NXOpen::BlockStyler::Node *node)
    //{
    //}

    //void TreeSample::OnDeleteNodeCallback(NXOpen::BlockStyler::Tree *tree, NXOpen::BlockStyler::Node *node)
    //{
    //}

    //void TreeSample::OnPreSelectCallback(NXOpen::BlockStyler::Tree *tree, NXOpen::BlockStyler::Node *node, int ID, bool selected)
    //{
    //}

    //void TreeSample::OnSelectCallback(NXOpen::BlockStyler::Tree *tree, NXOpen::BlockStyler::Node *, int columnID, bool selected)
    //{
    //}

    //void TreeSample::OnStateChangeCallback(NXOpen::BlockStyler::Tree *tree, NXOpen::BlockStyler::Node *node, int state)
    //{
    //}

    //NXString TreeSample::ToolTipTextCallback(NXOpen::BlockStyler::Tree *tree, NXOpen::BlockStyler::Node *node, int columnID)
    //{
    //}

    //int TreeSample::ColumnSortCallback(NXOpen::BlockStyler::Tree *tree, int columnID, NXOpen::BlockStyler::Node *node1, NXOpen::BlockStyler::Node *node2)
    //{
    //}

    //NXString TreeSample::StateIconNameCallback(NXOpen::BlockStyler::Tree *tree, NXOpen::BlockStyler::Node *node, int state)
    //{
    //}

    NXOpen::BlockStyler::Tree::BeginLabelEditState TreeSample::OnBeginLabelEditCallback(NXOpen::BlockStyler::Tree *tree, NXOpen::BlockStyler::Node *node, int columnID)
    {
    if (columnID==2)

    {
    return Tree::BeginLabelEditStateAllow;//返回值是BeginLabelEditStateAllow时,允许编辑单元格文本;返回值是BeginLabelEditStateDisallow时,不允许编辑此单元格文本

    }


    }

    NXOpen::BlockStyler::Tree::EndLabelEditState TreeSample::OnEndLabelEditCallback(NXOpen::BlockStyler::Tree *tree, NXOpen::BlockStyler::Node *node, int, NXString editedText)
    {

    {
    return Tree::EndLabelEditStateAcceptText;//返回值是EndLabelEditStateAcceptText时,接受修改的文本;返回值是EndLabelEditStateRejectText时,不接收修改的文本,界面上显示原来的内容。

    }


    }

    NXOpen::BlockStyler::Tree::EditControlOption TreeSample::OnEditOptionSelectedCallback(NXOpen::BlockStyler::Tree *tree, NXOpen::BlockStyler::Node *node, int columnID, int selectedOptionID, NXString selectedOptionText, NXOpen::BlockStyler::Tree::ControlType type)
    {

    return Tree::EditControlOptionAccept;//返回值为EditControlOptionAccept接受编辑,返回值为EditControlOptionReject不接受编辑(触发条件编辑Tree::ControlTypeComboBox类型、Tree::ControlTypeListBox类型单元格时触发)

    }

    NXOpen::BlockStyler::Tree::ControlType TreeSample::AskEditControlCallback(NXOpen::BlockStyler::Tree *tree, NXOpen::BlockStyler::Node *node, int columnID)
    {

    NXOpen::BlockStyler::Tree::ControlType AskEditControl = BlockStyler::Tree::ControlTypeNone;;
    try
    {
    if(columnID==1)
    {
    //可选择下拉菜单的内容
    AskEditControl = BlockStyler::Tree::ControlTypeListBox; // 无控制:ControlTypeNone ; 控制类型组合框:ControlTypeComboBox ; 控制类型列表框:ControlTypeListBox ;
    std::vector<NXOpen::NXString> options0;
    options0.push_back(NXOpen::NXString("前模仁"));
    options0.push_back(NXOpen::NXString("后模仁"));
    options0.push_back(NXOpen::NXString("行位"));

    tree->SetEditOptions(options0,0);
    }

    }

    catch(exception& ex)
    {
    //---- Enter your exception handling code here -----
    TreeSample::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
    }
    return AskEditControl;

    }

    void TreeSample::OnMenuCallback(NXOpen::BlockStyler::Tree *tree, NXOpen::BlockStyler::Node *node, int columnID )
    {
    try
    {

    //创建菜单
    BlockStyler::TreeListMenu *menu = tree->CreateMenu();
    //一级菜单

    if(node==NULL)
    {
    menu->AddMenuItem(0,"没选中删除对象,请重新选择","exclamationred"); //在树列表空白处显示右键菜单

    }
    else //Menu request for Node
    {
    menu->AddMenuItem(0,"删除节点","delete"); //在树列表选中有内容的节点处显示右键菜单
    }

    //挂一级菜单到列表
    tree->SetMenu(menu);
    //删除菜单(只有在树形菜单设置后才能删除菜单)
    delete menu;

    }
    catch(exception& ex)
    {
    //---- Enter your exception handling code here -----
    TreeSample::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
    }

    }

    void TreeSample::OnMenuSelectionCallback(NXOpen::BlockStyler::Tree *tree, NXOpen::BlockStyler::Node *node, int menuItemID)
    {
    try
    {
    //用户代码
    if(menuItemID == 0)
    {
    //删除节点
    std::vector<BlockStyler::Node *>selectedNodes=tree_control0->GetSelectedNodes();
    if(selectedNodes.size()>0)
    {
    while(selectedNodes.size()>0)
    {
    tree_control0->DeleteNode(selectedNodes[0]);
    selectedNodes=tree_control0->GetSelectedNodes();
    }
    }
    else
    {

    theUI->NXMessageBox()->Show("删除节点", NXOpen::NXMessageBox::DialogTypeInformation, "没选中删除对象,请重新选择");

    }

    }

    }
    catch(exception& ex)
    {
    //---- Enter your exception handling code here -----
    TreeSample::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
    }


    }

    //NXOpen::BlockStyler::Node::DropType TreeSample::IsDropAllowedCallback(NXOpen::BlockStyler::Tree *tree, NXOpen::BlockStyler::Node *node, int columnID, NXOpen::BlockStyler::Node *targetNode, int targetColumnID)
    //{
    //}

    //NXOpen::BlockStyler::Node::DragType TreeSample::IsDragAllowedCallback(NXOpen::BlockStyler::Tree *tree, NXOpen::BlockStyler::Node *node, int columnID)
    //{
    //}

    //bool TreeSample::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)
    //{
    //}

    //void TreeSample::OnDropMenuCallback(NXOpen::BlockStyler::Tree *tree, NXOpen::BlockStyler::Node *node, int columnID, NXOpen::BlockStyler::Node *targetNode, int targetColumnID)
    //{
    //}

    //void TreeSample::OnDefaultAction(NXOpen::BlockStyler::Tree *tree, NXOpen::BlockStyler::Node *node, int columnID)
    //{
    //}


    //------------------------------------------------------------------------------
    //Function Name: GetBlockProperties
    //Description: Returns the propertylist of the specified BlockID
    //------------------------------------------------------------------------------
    PropertyList* TreeSample::GetBlockProperties(const char *blockID)
    {
    return theDialog->GetBlockProperties(blockID);
    }

    怡宁塑胶模具设计
  • 相关阅读:
    Time Zone 【模拟时区转换】(HDU暑假2018多校第一场)
    HDU 1281 棋盘游戏 【二分图最大匹配】
    Codeforces Round #527 (Div. 3) F. Tree with Maximum Cost 【DFS换根 || 树形dp】
    Codeforces Round #527 (Div. 3) D2. Great Vova Wall (Version 2) 【思维】
    Codeforces Round #527 (Div. 3) D1. Great Vova Wall (Version 1) 【思维】
    Codeforces Round #528 (Div. 2, based on Technocup 2019 Elimination Round 4) C. Connect Three 【模拟】
    Avito Cool Challenge 2018 E. Missing Numbers 【枚举】
    Avito Cool Challenge 2018 C. Colorful Bricks 【排列组合】
    005 如何分析问题框架
    004 如何定义和澄清问题
  • 原文地址:https://www.cnblogs.com/hqsalanhuang/p/14219970.html
Copyright © 2011-2022 走看看