zoukankan      html  css  js  c++  java
  • NX二次开发-BlockUI不用选择控件,用鼠标点选去实时选择

    用计时器去实现

    //==============================================================================
    //  WARNING!!  This file is overwritten by the Block Styler while generating
    //  the automation code. Any modifications to this file will be lost after
    //  generating the code again.
    //
    //       Filename:  C:Program FilesSiemensNX 11.0CaesarToolkitsApplication	estCAM.hpp
    //
    //        This file was generated by the NX Block Styler
    //        Created by: Administrator
    //              Version: NX 11
    //              Date: 05-29-2020  (Format: mm-dd-yyyy)
    //              Time: 11:08
    //
    //==============================================================================
    
    #ifndef TESTCAM_H_INCLUDED
    #define TESTCAM_H_INCLUDED
    
    //------------------------------------------------------------------------------
    //These includes are needed for the following template code
    //------------------------------------------------------------------------------
    #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_StringBlock.hxx>
    
    /*头文件,命名空间,宏定义*/
    #include <stdarg.h>
    #include <strstream>
    #include <iostream>
    using std::ostrstream;
    using std::endl;
    using std::ends;
    using std::cerr;
    #include <uf.h>
    #include <uf_ui.h>
    #include <uf_ui_ont.h>
    #include <uf_obj.h>
    #include <uf_assem.h>
    #include <uf_part.h>
    #include <uf_exit.h>
    #include <afxwin.h>
    #include <windows.h>
    #include <shellapi.h>
    #include <winuser.h>
    #include <atlstr.h>  
    #pragma comment(lib, "User32.lib")
    #pragma warning(disable:4267)
    
    //------------------------------------------------------------------------------
    // Namespaces needed for following template
    //------------------------------------------------------------------------------
    using namespace std;
    using namespace NXOpen;
    using namespace NXOpen::BlockStyler;
    
    #undef CreateDialog
    
    class DllExport testCAM
    {
        // class members
    public:
        static Session *theSession;
        static UI *theUI;
        testCAM();
        ~testCAM();
        int Show();
        
        //void CALLBACK MyTimer(HWND hWnd, UINT nMsg, UINT nIDEvent, DWORD dwTime);
        //----------------------- 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 testCAM.cpp file. 
        // You are REQUIRED to write the implementation for these functions.
        //------------------------------------------------------------------------------
        void initialize_cb();
        void dialogShown_cb();
        int update_cb(NXOpen::BlockStyler::UIBlock* block);
        PropertyList* GetBlockProperties(const char *blockID);
        
    private:
        const char* theDlxFileName;
        NXOpen::BlockStyler::BlockDialog* theDialog; 
    };
    
    //将字符串控件定义到类的外面
    NXOpen::BlockStyler::StringBlock* string0;// Block type: String
    
    #endif //TESTCAM_H_INCLUDED
    //==============================================================================
    //  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:  C:Program FilesSiemensNX 11.0CaesarToolkitsApplication	estCAM.cpp
    //
    //        This file was generated by the NX Block UI Styler
    //        Created by: Administrator
    //              Version: NX 11
    //              Date: 05-29-2020  (Format: mm-dd-yyyy)
    //              Time: 11:08 (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 "testCAM.hpp"
    using namespace NXOpen;
    using namespace NXOpen::BlockStyler;
    
    //------------------------------------------------------------------------------
    // Initialize static variables
    //------------------------------------------------------------------------------
    Session *(testCAM::theSession) = NULL;
    UI *(testCAM::theUI) = NULL;
    
    //定义句柄变量
    HWND UGHwnd;
    //------------------------------------------------------------------------------
    // Constructor for NX Styler class
    //------------------------------------------------------------------------------
    testCAM::testCAM()
    {
        try
        {
            // Initialize the NX Open C++ API environment
            testCAM::theSession = NXOpen::Session::GetSession();
            testCAM::theUI = UI::GetUI();
            theDlxFileName = "testCAM.dlx";
            theDialog = testCAM::theUI->CreateDialog(theDlxFileName);
            // Registration of callback functions
            theDialog->AddUpdateHandler(make_callback(this, &testCAM::update_cb));
            theDialog->AddInitializeHandler(make_callback(this, &testCAM::initialize_cb));
            theDialog->AddDialogShownHandler(make_callback(this, &testCAM::dialogShown_cb));
        }
        catch(exception& ex)
        {
            //---- Enter your exception handling code here -----
            throw;
        }
    }
    
    //------------------------------------------------------------------------------
    // Destructor for NX Styler class
    //------------------------------------------------------------------------------
    testCAM::~testCAM()
    {
        if (theDialog != NULL)
        {
            delete theDialog;
            theDialog = NULL;
        }
        //取消定时器
        KillTimer(UGHwnd, 1);
    }
    //------------------------------- 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_BASE_DIRugiimenuscustom_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.
    //
    //------------------------------------------------------------------------------
    
    
    //定义变量
    string data1 = "";
    //创建回调函数
    void CALLBACK MyTimer(HWND hWnd, UINT nMsg, UINT nIDEvent, DWORD dwTime)
    {
        //获取当前加工导航器选中的对象数量和TAG
        int count = 0;
        tag_t* objects = NULL_TAG;
        UF_UI_ONT_ask_selected_nodes(&count, &objects);
    
        //UF_UI_open_listing_window();
        if (objects[0] != NULL_TAG)
        {
            //由tag获得名字
            char name[256];
            UF_OBJ_ask_name(objects[0], name);
            //转换
            string data2 = name;
    
            if (data1 != data2)//判断名字是否重复
            {
                //UF_UI_write_listing_window(name);
                //UF_UI_write_listing_window("
    ");
                string0->SetValue(name);//把名字设置到字符串控件上
                data1 = name;//赋值
            }
        }
    }
    
    
    extern "C" DllExport void  ufusr(char *param, int *retcod, int param_len)
    {
        testCAM *thetestCAM = NULL;
        try
        {
            UF_initialize();
    
            thetestCAM = new testCAM();
            // The following method shows the dialog immediately
            thetestCAM->Show();
            
            UF_terminate();
        }
        catch(exception& ex)
        {
            //---- Enter your exception handling code here -----
            testCAM::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
        }
        if(thetestCAM != NULL)
        {
            delete thetestCAM;
            thetestCAM = 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 -----
            testCAM::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
        }
    }
    
    int testCAM::Show()
    {
        try
        {
            theDialog->Show();
        }
        catch(exception& ex)
        {
            //---- Enter your exception handling code here -----
            testCAM::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
        }
        return 0;
    }
    
    //------------------------------------------------------------------------------
    //---------------------Block UI Styler Callback Functions--------------------------
    //------------------------------------------------------------------------------
    
    //------------------------------------------------------------------------------
    //Callback Name: initialize_cb
    //------------------------------------------------------------------------------
    void testCAM::initialize_cb()
    {
        try
        {
            string0 = dynamic_cast<NXOpen::BlockStyler::StringBlock*>(theDialog->TopBlock()->FindBlock("string0"));
    
            //获得NX窗口句柄
            UGHwnd = (HWND)UF_UI_get_default_parent();
    
            //每隔500ms运行一次回调函数
            SetTimer(UGHwnd, 1, 500, (TIMERPROC)MyTimer);
        }
        catch(exception& ex)
        {
            //---- Enter your exception handling code here -----
            testCAM::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 testCAM::dialogShown_cb()
    {
        try
        {
            //---- Enter your callback code here -----    
        }
        catch(exception& ex)
        {
            //---- Enter your exception handling code here -----
            testCAM::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
        }
    }
    
    //------------------------------------------------------------------------------
    //Callback Name: update_cb
    //------------------------------------------------------------------------------
    int testCAM::update_cb(NXOpen::BlockStyler::UIBlock* block)
    {
        try
        {
            if(block == string0)
            {
            //---------Enter your code here-----------
            }
        }
        catch(exception& ex)
        {
            //---- Enter your exception handling code here -----
            testCAM::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
        }
        return 0;
    }
    
    //------------------------------------------------------------------------------
    //Function Name: GetBlockProperties
    //Description: Returns the propertylist of the specified BlockID
    //------------------------------------------------------------------------------
    PropertyList* testCAM::GetBlockProperties(const char *blockID)
    {
        return theDialog->GetBlockProperties(blockID);
    }

    Caesar卢尚宇

    2020年5月30日

  • 相关阅读:
    GlusterFS 配置及使用
    zabbix-监控Linux服务器
    ansible安装及使用
    使用ansible 完成yum安装lamp环境
    mysql基础
    shell基础
    shell
    Javascript动画效果(四)
    Javascript动画效果(三)
    Javascript动画效果(二)
  • 原文地址:https://www.cnblogs.com/nxopen2018/p/12994700.html
Copyright © 2011-2022 走看看