/// <summary>
        /// The helper method for constructors to call to avoid duplicate code.
        /// </summary>
        public void Create(
            string displayName, string internalName, string description, string tooltip,
            string clientId,
            Icon standardIcon, Icon largeIcon,
            CommandTypesEnum commandType, ButtonDisplayEnum buttonDisplayType)
        {
            if (string.IsNullOrEmpty(clientId))
            {
                clientId = AddinGlobal.ClassId;
            }

            stdole.IPictureDisp standardIconIPictureDisp = null;
            stdole.IPictureDisp largeIconIPictureDisp    = null;
            if (standardIcon != null)
            {
                standardIconIPictureDisp = Support.IconToIPicture(standardIcon) as stdole.IPictureDisp;
                largeIconIPictureDisp    = (stdole.IPictureDisp)Support.IconToIPicture(largeIcon);
            }

            mButtonDef = AddinGlobal.InventorApp.CommandManager.ControlDefinitions.AddButtonDefinition(
                displayName, internalName, commandType,
                clientId, description, tooltip,
                standardIconIPictureDisp, largeIconIPictureDisp, buttonDisplayType);

            mButtonDef.Enabled    = true;
            mButtonDef.OnExecute += ButtonDefinition_OnExecute;

            DisplayText = true;

            AddinGlobal.ButtonList.Add(this);
        }
Beispiel #2
0
        /**
         * @fn GetImageByGiveSymbolAfterSelectItem
         * @date 2013.03.16
         * @author Ge Xizhi
         * @brief 调用边框样式前返回选择样式的图片
         * @param width 图片宽度
         * @param height 图片高度
         * @retval TRUE 成功
         * @retval FALSE 失败
         */
        //选择样式后返回图片
        public Image GetImageByGiveSymbolAfterSelectItem(int width, int height)
        {
            ISymbologyStyleClass symbologyStyleClass = axSymbologyCtlFrame.GetStyleClass(axSymbologyCtlFrame.StyleClass);

            stdole.IPictureDisp  picture = symbologyStyleClass.PreviewItem(pStyleGalleryItem, width, height);
            System.Drawing.Image image   = System.Drawing.Image.FromHbitmap(new System.IntPtr(picture.Handle));
            return(image);
        }
        private void PreviewImage()
        {
            //Get and set the style class
            ISymbologyStyleClass symbologyStyleClass = axSymbologyControl1.GetStyleClass(axSymbologyControl1.StyleClass);

            //Preview an image of the symbol
            stdole.IPictureDisp  picture = symbologyStyleClass.PreviewItem(m_StyleGallertItem, pictureBox1.Width, pictureBox1.Height);
            System.Drawing.Image image   = System.Drawing.Image.FromHbitmap(new System.IntPtr(picture.Handle));
            pictureBox1.Image = image;
        }
Beispiel #4
0
        //预览样式
        private void PreviewImage()
        {
            //Get and set the style class
            ISymbologyStyleClass symbologyStyleClass = axSymbologyCtlLegendItem.GetStyleClass(axSymbologyCtlLegendItem.StyleClass);

            //Preview an image of the symbol
            stdole.IPictureDisp  pPicpture = symbologyStyleClass.PreviewItem(pStyleGalleryItem, ImagePreview.Width, ImagePreview.Height);
            System.Drawing.Image pImage    = System.Drawing.Image.FromHbitmap(new System.IntPtr(pPicpture.Handle));

            ImagePreview.Image = pImage;
        }
        public void Activate(Inventor.ApplicationAddInSite addInSiteObject, bool firstTime)
        {
            // This method is called by Inventor when it loads the addin.
            // The AddInSiteObject provides access to the Inventor Application object.
            // The FirstTime flag indicates if the addin is loaded for the first time.

            // Initialize AddIn members.
            m_inventorApplication = addInSiteObject.Application;

            // TODO: Add ApplicationAddInServer.Activate implementation.
            // e.g. event initialization, command creation etc.

            int largeIconSize = 0;

            if (m_inventorApplication.UserInterfaceManager.InterfaceStyle == InterfaceStyleEnum.kRibbonInterface)
            {
                largeIconSize = 32;
            }
            else
            {
                largeIconSize = 24;
            }

            ControlDefinitions controlDefs = m_inventorApplication.CommandManager.ControlDefinitions;

            stdole.IPictureDisp smallPicture1 = AxHostConverter.ImageToPictureDisp(new Icon(@"Resources\Icon1.ico").ToBitmap());
            stdole.IPictureDisp largePicture1 = AxHostConverter.ImageToPictureDisp(new Icon(@"Resources\Icon1.ico").ToBitmap());
            m_TreeViewBrowser            = controlDefs.AddButtonDefinition("HierarchyPane", "BrowserSample:HierarchyPane", CommandTypesEnum.kNonShapeEditCmdType, m_ClientId, null, null, smallPicture1, largePicture1);
            m_TreeViewBrowser.OnExecute += new ButtonDefinitionSink_OnExecuteEventHandler(m_TreeViewBrowser_OnExecute);



            stdole.IPictureDisp smallPicture2 = AxHostConverter.ImageToPictureDisp(new Icon(@"Resources\Icon2.ico").ToBitmap());
            stdole.IPictureDisp largePicture2 = AxHostConverter.ImageToPictureDisp(new Icon(@"Resources\Icon2.ico").ToBitmap());
            m_ActiveXBrowser            = controlDefs.AddButtonDefinition("ActiveXPane", "BrowserSample:ActiveXPane", CommandTypesEnum.kNonShapeEditCmdType, m_ClientId, null, null, smallPicture2, largePicture2);
            m_ActiveXBrowser.OnExecute += new ButtonDefinitionSink_OnExecuteEventHandler(m_ActiveXBrowser_OnExecute);

            stdole.IPictureDisp smallPicture3 = AxHostConverter.ImageToPictureDisp(new Icon(@"Resources\Icon3.ico").ToBitmap());
            stdole.IPictureDisp largePicture3 = AxHostConverter.ImageToPictureDisp(new Icon(@"Resources\Icon3.ico").ToBitmap());
            m_DoBrowserEvents            = controlDefs.AddButtonDefinition("DoBrowserEvents", "BrowserSample:DoBrowserEvents", CommandTypesEnum.kNonShapeEditCmdType, m_ClientId, null, null, smallPicture3, largePicture3);
            m_DoBrowserEvents.OnExecute += new ButtonDefinitionSink_OnExecuteEventHandler(m_DoBrowserEvents_OnExecute);


            // Get the assembly ribbon.
            Inventor.Ribbon partRibbon = m_inventorApplication.UserInterfaceManager.Ribbons["Part"];
            // Get the "Part" tab.
            Inventor.RibbonTab   partTab   = partRibbon.RibbonTabs[1];
            Inventor.RibbonPanel partPanel = partTab.RibbonPanels[1];
            partPanel.CommandControls.AddButton(m_TreeViewBrowser, true);
            partPanel.CommandControls.AddButton(m_DoBrowserEvents);
            partPanel.CommandControls.AddButton(m_ActiveXBrowser);
        }
Beispiel #6
0
        //返回样式图片
        public void GetImageByGiveSymbolBeforeSelectItem(esriSymbologyStyleClass styleClass, ISymbol symbol)
        {
            axSymbologyControl.StyleClass = styleClass;
            ISymbologyStyleClass symbologyStyleClass = axSymbologyControl.GetStyleClass(styleClass);

            IStyleGalleryItem styleGalleryItem = new ServerStyleGalleryItem();

            styleGalleryItem.Item = symbol;

            stdole.IPictureDisp  picture = symbologyStyleClass.PreviewItem(styleGalleryItem, ImagePreview.Width, ImagePreview.Height);
            System.Drawing.Image pImage  = System.Drawing.Image.FromHbitmap(new System.IntPtr(picture.Handle));
            ImagePreview.Image = pImage;
        }
Beispiel #7
0
        /**
         * @fn GetImageByGiveSymbolAfterSelectItem
         * @date 2013.03.16
         * @author Ge Xizhi
         * @brief 调用背景样式前返回选择样式的图片
         * @param width 图片宽度
         * @param height 图片高度
         * @retval TRUE 成功
         * @retval FALSE 失败
         */

        //选择样式后返回图片
        public Image GetImageByGiveSymbolAfterSelectItem(int width, int height)
        {
            if (pStyleGalleryItem == null)
            {
                MessageBox.Show("请选择背景式", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            ISymbologyStyleClass symbologyStyleClass = axSymbologyCtlFrame.GetStyleClass(axSymbologyCtlFrame.StyleClass);

            //Preview an image of the symbol
            stdole.IPictureDisp  picture = symbologyStyleClass.PreviewItem(pStyleGalleryItem, width, height);
            System.Drawing.Image image   = System.Drawing.Image.FromHbitmap(new System.IntPtr(picture.Handle));
            return(image);
        }
Beispiel #8
0
        //选择样式前返回面图片
        public Image GetImageByGiveAreaSymbolBeforeSelectItem(esriSymbologyStyleClass styleClass, IAreaPatch symbol, int width, int height)
        {
            axSymbologyCtlFrame.StyleClass = styleClass;
            ISymbologyStyleClass symbologyStyleClass = axSymbologyCtlFrame.GetStyleClass(styleClass);

            IStyleGalleryItem styleGalleryItem = new ServerStyleGalleryItem();

            styleGalleryItem.Item = symbol;
            symbologyStyleClass.AddItem(styleGalleryItem, 0);
            symbologyStyleClass.SelectItem(0);
            stdole.IPictureDisp  picture = symbologyStyleClass.PreviewItem(pStyleGalleryItem, width, height);
            System.Drawing.Image image   = System.Drawing.Image.FromHbitmap(new System.IntPtr(picture.Handle));
            return(image);
        }
Beispiel #9
0
 public static stdole.IPictureDisp Convert(System.Drawing.Image image)
 {
     stdole.IPictureDisp temp = null;
     try
     {
         temp = (stdole.IPictureDisp)GetIPictureDispFromPicture(image);
     }
     catch (Exception ex)
     {
         if (ex is System.ArgumentException || ex is System.Runtime.InteropServices.ExternalException)
         {
             Debug.Print("doing that thin agian...");
             throw;
         }
     }
     return(temp);
 }
Beispiel #10
0
        public void Activate(Inventor.ApplicationAddInSite addInSiteObject, bool firstTime)
        {
            // This method is called by Inventor when it loads the addin.
            // The AddInSiteObject provides access to the Inventor Application object.
            // The FirstTime flag indicates if the addin is loaded for the first time.

            // Initialize AddIn members.
            m_inventorApplication = addInSiteObject.Application;

            // TODO: Add ApplicationAddInServer.Activate implementation.
            // e.g. event initialization, command creation etc.

            // Get a reference to the UserInterfaceManager object.
            Inventor.UserInterfaceManager UIManager = m_inventorApplication.UserInterfaceManager;

            // Get a reference to the ControlDefinitions object.
            ControlDefinitions controlDefs = m_inventorApplication.CommandManager.ControlDefinitions;

            // Get the images from the resources.  They are stored as .Net images and the
            // PictureConverter class is used to convert them to IPictureDisp objects, which
            // the Inventor API requires.
            stdole.IPictureDisp icon_large = PictureConverter.ImageToPictureDisp(Properties.Resources.ribbon_icon);
            stdole.IPictureDisp icon_small = PictureConverter.ImageToPictureDisp(Properties.Resources.icon16);

            // Create the button definition.
            m_buttonDef = controlDefs.AddButtonDefinition("Tabs", "UIRibbonSampleOne",
                                                          CommandTypesEnum.kNonShapeEditCmdType,
                                                          "{0defbf22-e302-4266-9bc9-fb80d5c8eb7e}", "", "", icon_small, icon_large);

            // Call the function to add information to the user-interface.
            if (firstTime)
            {
                CreateUserInterface();
                //PrintRibbonNames();
            }

            // Connect to UI events to be able to handle a UI reset.
            m_uiEvents = m_inventorApplication.UserInterfaceManager.UserInterfaceEvents;
            m_uiEvents.OnResetRibbonInterface += m_uiEvents_OnResetRibbonInterface;

            m_buttonDef.OnExecute += m_buttonDef_OnExecute;
        }
        /// <summary>
        /// When [HierarchicalBrowser] button is clicked
        /// </summary>
        /// <param name="Context"></param>
        /// <remarks></remarks>

        private void m_TreeViewBrowser_OnExecute(Inventor.NameValueMap Context)
        {
            Document oDoc = default(Document);

            oDoc = m_inventorApplication.ActiveDocument;

            BrowserPanes oPanes = default(BrowserPanes);

            oPanes = oDoc.BrowserPanes;

            //Create a standard Microsoft Windows IPictureDisp referencing an icon (.bmp) bitmap file.
            //Change the file referenced here as appropriate - here the code references test.bmp.
            //This is the icon that will be displayed at this node. Add the IPictureDisp to the client node resource.

            ClientNodeResources oRscs = oPanes.ClientNodeResources;

            stdole.IPictureDisp clientNodeIcon = AxHostConverter.ImageToPictureDisp(new Bitmap(@"Resources\test.bmp"));

            ClientNodeResource oRsc = oRscs.Add(m_ClientId, 1, clientNodeIcon);

            BrowserNodeDefinition oDef = (BrowserNodeDefinition)oPanes.CreateBrowserNodeDefinition("Top Node", 3, oRsc);

            //adding a new pane tab to the panes collection, define the top node the pane will contain.
            Inventor.BrowserPane oPane = oPanes.AddTreeBrowserPane("My Pane", m_ClientId, oDef);

            //Add two child nodes to the tree, labeled Node 2 and Node 3.
            BrowserNodeDefinition oDef1  = (BrowserNodeDefinition)oPanes.CreateBrowserNodeDefinition("Node2", 5, oRsc);
            BrowserNode           oNode1 = oPane.TopNode.AddChild(oDef1);

            BrowserNodeDefinition oDef2  = (BrowserNodeDefinition)oPanes.CreateBrowserNodeDefinition("Node3", 6, oRsc);
            BrowserNode           oNode2 = oPane.TopNode.AddChild(oDef2);

            //Add the native node (from root)  of "Model" pane to the tree
            BrowserNode oNativeRootNode = default(BrowserNode);

            oNativeRootNode = oDoc.BrowserPanes["Model"].TopNode;

            oPane.TopNode.AddChild(oNativeRootNode.BrowserNodeDefinition);
        }
Beispiel #12
0
 public static Image PictureDispToImage(stdole.IPictureDisp pictureDisp)
 {
     return(GetPictureFromIPicture(pictureDisp));
 }
Beispiel #13
0
 static public System.Drawing.Image PictureDispToImage(stdole.IPictureDisp picture)
 {
     return(GetPictureFromIPicture(picture));
 }
Beispiel #14
0
        private void AddTreeBrowersPane()
        {
            IconPictureInitial();
            Document oDoc = default(Document);

            oDoc = m_inventorApplication.ActiveDocument;

            BrowserPanes oPanes = default(BrowserPanes);

            oPanes = oDoc.BrowserPanes;

            System.IO.Stream    oStream_Block = assembly.GetManifestResourceStream("ValveBlockDesign.resources.BlockStandard.ico");
            System.Drawing.Icon oIcon_Block   = new System.Drawing.Icon(oStream_Block);

            System.IO.Stream    oStream_NET1  = assembly.GetManifestResourceStream("ValveBlockDesign.resources.NET1.ico");
            System.Drawing.Icon oIcon_NET1    = new System.Drawing.Icon(oStream_NET1);
            System.IO.Stream    oStream_NET2  = assembly.GetManifestResourceStream("ValveBlockDesign.resources.NET2.ico");
            System.Drawing.Icon oIcon_NET2    = new System.Drawing.Icon(oStream_NET2);
            System.IO.Stream    oStream_NET3  = assembly.GetManifestResourceStream("ValveBlockDesign.resources.NET3.ico");
            System.Drawing.Icon oIcon_NET3    = new System.Drawing.Icon(oStream_NET3);
            System.IO.Stream    oStream_NET4  = assembly.GetManifestResourceStream("ValveBlockDesign.resources.NET4.ico");
            System.Drawing.Icon oIcon_NET4    = new System.Drawing.Icon(oStream_NET4);
            System.IO.Stream    oStream_NET5  = assembly.GetManifestResourceStream("ValveBlockDesign.resources.NET5.ico");
            System.Drawing.Icon oIcon_NET5    = new System.Drawing.Icon(oStream_NET5);
            System.IO.Stream    oStream_NET6  = assembly.GetManifestResourceStream("ValveBlockDesign.resources.NET6.ico");
            System.Drawing.Icon oIcon_NET6    = new System.Drawing.Icon(oStream_NET6);
            System.IO.Stream    oStream_NET7  = assembly.GetManifestResourceStream("ValveBlockDesign.resources.NET7.ico");
            System.Drawing.Icon oIcon_NET7    = new System.Drawing.Icon(oStream_NET7);
            System.IO.Stream    oStream_NET8  = assembly.GetManifestResourceStream("ValveBlockDesign.resources.NET8.ico");
            System.Drawing.Icon oIcon_NET8    = new System.Drawing.Icon(oStream_NET8);
            System.IO.Stream    oStream_NET9  = assembly.GetManifestResourceStream("ValveBlockDesign.resources.NET9.ico");
            System.Drawing.Icon oIcon_NET9    = new System.Drawing.Icon(oStream_NET9);
            System.IO.Stream    oStream_NET10 = assembly.GetManifestResourceStream("ValveBlockDesign.resources.NET10.ico");
            System.Drawing.Icon oIcon_NET10   = new System.Drawing.Icon(oStream_NET10);
            System.IO.Stream    oStream_NET11 = assembly.GetManifestResourceStream("ValveBlockDesign.resources.NET11.ico");
            System.Drawing.Icon oIcon_NET11   = new System.Drawing.Icon(oStream_NET11);
            System.IO.Stream    oStream_NET12 = assembly.GetManifestResourceStream("ValveBlockDesign.resources.NET12.ico");
            System.Drawing.Icon oIcon_NET12   = new System.Drawing.Icon(oStream_NET12);
            System.IO.Stream    oStream_NET13 = assembly.GetManifestResourceStream("ValveBlockDesign.resources.NET13.ico");
            System.Drawing.Icon oIcon_NET13   = new System.Drawing.Icon(oStream_NET13);
            System.IO.Stream    oStream_NET14 = assembly.GetManifestResourceStream("ValveBlockDesign.resources.NET14.ico");
            System.Drawing.Icon oIcon_NET14   = new System.Drawing.Icon(oStream_NET14);
            System.IO.Stream    oStream_NULL  = assembly.GetManifestResourceStream("ValveBlockDesign.resources.NULL.ico");
            System.Drawing.Icon oIcon_NULL    = new System.Drawing.Icon(oStream_NULL);

            System.IO.Stream    oStream_Cavity    = assembly.GetManifestResourceStream("ValveBlockDesign.resources.Cavity.ico");
            System.Drawing.Icon oIcon_Cavity      = new System.Drawing.Icon(oStream_Cavity);
            System.IO.Stream    oStream_Footprint = assembly.GetManifestResourceStream("ValveBlockDesign.resources.Footprint.ico");
            System.Drawing.Icon oIcon_Footprint   = new System.Drawing.Icon(oStream_Footprint);

            //This is the icon that will be displayed at this node. Add the IPictureDisp to the client node resource.

            ClientNodeResources oRscs = oPanes.ClientNodeResources;

            stdole.IPictureDisp clientNodeIcon = ValveBlockDesign.StandardAddInServer.AxHostConverter.ImageToPictureDisp(oIcon_Block.ToBitmap());
            ClientNodeResource  oRsc           = oRscs.Add(m_ClientId, 1, clientNodeIcon);

            stdole.IPictureDisp clientNodeIcon1 = ValveBlockDesign.StandardAddInServer.AxHostConverter.ImageToPictureDisp(oIcon_NET1.ToBitmap());
            ClientNodeResource  oRsc1           = oRscs.Add(m_ClientId, 2, clientNodeIcon1);

            stdole.IPictureDisp clientNodeIcon2 = ValveBlockDesign.StandardAddInServer.AxHostConverter.ImageToPictureDisp(oIcon_NET2.ToBitmap());
            ClientNodeResource  oRsc2           = oRscs.Add(m_ClientId, 3, clientNodeIcon2);

            stdole.IPictureDisp clientNodeIcon3 = ValveBlockDesign.StandardAddInServer.AxHostConverter.ImageToPictureDisp(oIcon_NET3.ToBitmap());
            ClientNodeResource  oRsc3           = oRscs.Add(m_ClientId, 4, clientNodeIcon3);

            stdole.IPictureDisp clientNodeIcon4 = ValveBlockDesign.StandardAddInServer.AxHostConverter.ImageToPictureDisp(oIcon_NET4.ToBitmap());
            ClientNodeResource  oRsc4           = oRscs.Add(m_ClientId, 5, clientNodeIcon4);

            stdole.IPictureDisp clientNodeIcon5 = ValveBlockDesign.StandardAddInServer.AxHostConverter.ImageToPictureDisp(oIcon_NET5.ToBitmap());
            ClientNodeResource  oRsc5           = oRscs.Add(m_ClientId, 6, clientNodeIcon5);

            stdole.IPictureDisp clientNodeIcon6 = ValveBlockDesign.StandardAddInServer.AxHostConverter.ImageToPictureDisp(oIcon_NET6.ToBitmap());
            ClientNodeResource  oRsc6           = oRscs.Add(m_ClientId, 7, clientNodeIcon6);

            stdole.IPictureDisp clientNodeIcon7 = ValveBlockDesign.StandardAddInServer.AxHostConverter.ImageToPictureDisp(oIcon_NET7.ToBitmap());
            ClientNodeResource  oRsc7           = oRscs.Add(m_ClientId, 8, clientNodeIcon7);

            stdole.IPictureDisp clientNodeIcon8 = ValveBlockDesign.StandardAddInServer.AxHostConverter.ImageToPictureDisp(oIcon_NET8.ToBitmap());
            ClientNodeResource  oRsc8           = oRscs.Add(m_ClientId, 9, clientNodeIcon8);

            stdole.IPictureDisp clientNodeIcon9 = ValveBlockDesign.StandardAddInServer.AxHostConverter.ImageToPictureDisp(oIcon_NET9.ToBitmap());
            ClientNodeResource  oRsc9           = oRscs.Add(m_ClientId, 10, clientNodeIcon9);

            stdole.IPictureDisp clientNodeIcon10 = ValveBlockDesign.StandardAddInServer.AxHostConverter.ImageToPictureDisp(oIcon_NET10.ToBitmap());
            ClientNodeResource  oRsc10           = oRscs.Add(m_ClientId, 11, clientNodeIcon10);

            stdole.IPictureDisp clientNodeIcon11 = ValveBlockDesign.StandardAddInServer.AxHostConverter.ImageToPictureDisp(oIcon_NET11.ToBitmap());
            ClientNodeResource  oRsc11           = oRscs.Add(m_ClientId, 12, clientNodeIcon11);

            stdole.IPictureDisp clientNodeIcon12 = ValveBlockDesign.StandardAddInServer.AxHostConverter.ImageToPictureDisp(oIcon_NET12.ToBitmap());
            ClientNodeResource  oRsc12           = oRscs.Add(m_ClientId, 13, clientNodeIcon12);

            stdole.IPictureDisp clientNodeIcon13 = ValveBlockDesign.StandardAddInServer.AxHostConverter.ImageToPictureDisp(oIcon_Cavity.ToBitmap());
            ClientNodeResource  oRsc13           = oRscs.Add(m_ClientId, 14, clientNodeIcon13);

            stdole.IPictureDisp clientNodeIcon14 = ValveBlockDesign.StandardAddInServer.AxHostConverter.ImageToPictureDisp(oIcon_Footprint.ToBitmap());
            ClientNodeResource  oRsc14           = oRscs.Add(m_ClientId, 15, clientNodeIcon14);

            stdole.IPictureDisp clientNodeIcon15 = ValveBlockDesign.StandardAddInServer.AxHostConverter.ImageToPictureDisp(oIcon_NULL.ToBitmap());
            ClientNodeResource  oRsc15           = oRscs.Add(m_ClientId, 16, clientNodeIcon15);

            stdole.IPictureDisp clientNodeIcon16 = ValveBlockDesign.StandardAddInServer.AxHostConverter.ImageToPictureDisp(oIcon_NET13.ToBitmap());
            ClientNodeResource  oRsc16           = oRscs.Add(m_ClientId, 17, clientNodeIcon16);

            stdole.IPictureDisp clientNodeIcon17 = ValveBlockDesign.StandardAddInServer.AxHostConverter.ImageToPictureDisp(oIcon_NET14.ToBitmap());
            ClientNodeResource  oRsc17           = oRscs.Add(m_ClientId, 18, clientNodeIcon17);

            BrowserNodeDefinition oDef = (BrowserNodeDefinition)oPanes.CreateBrowserNodeDefinition("网络清单", 1, oRsc);

            Inventor.BrowserPane  oPane   = oPanes.AddTreeBrowserPane("油路", m_ClientId, oDef);
            Inventor.BrowserNode  topNode = oPanes["油路"].TopNode;
            BrowserNodeDefinition oDef1   = (BrowserNodeDefinition)oPanes.CreateBrowserNodeDefinition("NET1", 2, oRsc1);

            topNode.AddChild(oDef1);
            BrowserNodeDefinition oDef2 = (BrowserNodeDefinition)oPanes.CreateBrowserNodeDefinition("NET2", 3, oRsc2);

            topNode.AddChild(oDef2);
            BrowserNodeDefinition oDef3 = (BrowserNodeDefinition)oPanes.CreateBrowserNodeDefinition("NET3", 4, oRsc3);

            topNode.AddChild(oDef3);
            BrowserNodeDefinition oDef4 = (BrowserNodeDefinition)oPanes.CreateBrowserNodeDefinition("NET4", 5, oRsc4);

            topNode.AddChild(oDef4);
            BrowserNodeDefinition oDef5 = (BrowserNodeDefinition)oPanes.CreateBrowserNodeDefinition("NET5", 6, oRsc5);

            topNode.AddChild(oDef5);
            BrowserNodeDefinition oDef6 = (BrowserNodeDefinition)oPanes.CreateBrowserNodeDefinition("NET6", 7, oRsc6);

            topNode.AddChild(oDef6);
            BrowserNodeDefinition oDef7 = (BrowserNodeDefinition)oPanes.CreateBrowserNodeDefinition("NET7", 8, oRsc7);

            topNode.AddChild(oDef7);
            BrowserNodeDefinition oDef8 = (BrowserNodeDefinition)oPanes.CreateBrowserNodeDefinition("NET8", 9, oRsc8);

            topNode.AddChild(oDef8);
            BrowserNodeDefinition oDef9 = (BrowserNodeDefinition)oPanes.CreateBrowserNodeDefinition("NET9", 10, oRsc9);

            topNode.AddChild(oDef9);
            BrowserNodeDefinition oDef10 = (BrowserNodeDefinition)oPanes.CreateBrowserNodeDefinition("NET10", 11, oRsc10);

            topNode.AddChild(oDef10);
            BrowserNodeDefinition oDef11 = (BrowserNodeDefinition)oPanes.CreateBrowserNodeDefinition("NET11", 12, oRsc11);

            topNode.AddChild(oDef11);
            BrowserNodeDefinition oDef12 = (BrowserNodeDefinition)oPanes.CreateBrowserNodeDefinition("NET12", 13, oRsc12);

            topNode.AddChild(oDef12);
            BrowserNodeDefinition oDef13 = (BrowserNodeDefinition)oPanes.CreateBrowserNodeDefinition("NET13", 14, oRsc16);

            topNode.AddChild(oDef13);
            BrowserNodeDefinition oDef14 = (BrowserNodeDefinition)oPanes.CreateBrowserNodeDefinition("NET14", 15, oRsc17);

            topNode.AddChild(oDef14);
            BrowserNodeDefinition oDef15 = (BrowserNodeDefinition)oPanes.CreateBrowserNodeDefinition("NULLNET", 16, oRsc15);

            topNode.AddChild(oDef15);
            oPanes["油路"].Update();
            oPanes["模型"].Activate();
        }//创建浏览器节点
Beispiel #15
0
        private void Button_ok_Click(object sender, EventArgs e)
        {
            // references to some useful objects
            TransientGeometry geom = m_inventorApplication.TransientGeometry;
            //PartDocument document = m_inventorApplication.ActiveDocument as PartDocument;
            //_Document document = m_inventorApplication.ActiveDocument;


            /*
             * if (document == null)
             * {
             *  AssemblyDocument asm = m_inventorApplication.ActiveDocument as AssemblyDocument;
             *  m_inventorApplication.ActiveDocument;
             * }
             */

            PartComponentDefinition def;   // = document.ComponentDefinition;
            UnitsOfMeasure          units; // = document.UnitsOfMeasure;
            UserParameters          user_params;
            Document document = m_inventorApplication.ActiveDocument;

            if (m_inventorApplication.ActiveDocument is AssemblyDocument)
            {
                AssemblyDocument doc  = m_inventorApplication.ActiveDocument as AssemblyDocument;
                PartDocument     part = doc.ActivatedObject as PartDocument;

                if (part == null)
                {
                    m_inventorApplication.ErrorManager.Show("Please activate a part!", true, false);
                    return;
                }

                def         = part.ComponentDefinition;
                units       = part.UnitsOfMeasure;
                user_params = part.ComponentDefinition.Parameters.UserParameters;
            }
            else if (m_inventorApplication.ActiveDocument is PartDocument)
            {
                PartDocument doc = m_inventorApplication.ActiveDocument as PartDocument;
                def         = doc.ComponentDefinition;
                units       = doc.UnitsOfMeasure;
                user_params = doc.ComponentDefinition.Parameters.UserParameters;
            }
            else
            {
                m_inventorApplication.ErrorManager.Show("Current document is neither an Assembly nor a Part.", true, false);
                return;
            }

            // get and check selected faces
            ObjectsEnumerator JustSelectedEntities = m_selects.SelectedEntities;

            if (JustSelectedEntities.Count == 0)
            {
                m_inventorApplication.ErrorManager.Show("Select at least one planar, rectangular face.", true, false);
                return;
            }

            foreach (Object _f in JustSelectedEntities)
            {
                Face f = _f as Face;
                if (f == null)
                {
                    m_inventorApplication.ErrorManager.Show("Somehow, you managed to select something that isn't a face. This should not happen, please report it.", true, false);
                    return;
                }

                if (f.Edges.Count != 4)
                {
                    m_inventorApplication.ErrorManager.Show("Please only select rectangular faces.", true, false);
                    return;
                }
            }

            // TODO: catch exception when invalid was is entered
            UserParameter tab_user_constr;

            if (m_dialog.mode_count.Checked)
            {
                tab_user_constr = user_params.AddByExpression("tab_count", m_dialog.tab_size_input.Text, UnitsTypeEnum.kUnitlessUnits);
            }
            else
            {
                tab_user_constr = user_params.AddByExpression("tab_size", m_dialog.tab_size_input.Text, UnitsTypeEnum.kDefaultDisplayLengthUnits);
            }



            int total_operations = JustSelectedEntities.Count;

            WorkAxis[]       extrusion_dir = new WorkAxis[total_operations];
            bool[]           long_edge_dir = new bool[total_operations];
            PlanarSketch[]   all_sketches  = new PlanarSketch[total_operations];
            Profile[]        profile       = new Profile[total_operations];
            ExtrudeFeature[] extrusion     = new ExtrudeFeature[total_operations];
            TwoPointDistanceDimConstraint[] tab_length_constr     = new TwoPointDistanceDimConstraint[total_operations];
            TwoPointDistanceDimConstraint[] tab_widthdepth_constr = new TwoPointDistanceDimConstraint[total_operations];
            TwoPointDistanceDimConstraint[] total_length_constr   = new TwoPointDistanceDimConstraint[total_operations];
            RectangularPatternFeature[]     rect_pattern          = new RectangularPatternFeature[total_operations];

            Transaction transaction = m_inventorApplication.TransactionManager.StartTransaction(m_inventorApplication.ActiveDocument, "LaserTab");

            // create extrusion feature for each face
            int i = 0;

            foreach (Object _f in JustSelectedEntities)
            {
                Face f = _f as Face;

                if (_f is FaceProxy)
                {
                    f = ((FaceProxy)_f).NativeObject;
                }

                // TODO: make sure active document is a partDocument and ActiveEditObject is not a sketch (should be also a partDocument?)
                // TODO: wrap it all into a ClientFeature
                // TODO: maybe also wrap it in a Transaction?



                // create sketch

                PlanarSketch sketch = def.Sketches.Add(f, false); // don't project anything
                //PlanarSketch sketch = def.Sketches.Add(f, true); // project existing geometry
                //PlanarSketch sketch = def.Sketches.AddWithOrientation(f, long_edge, true, true, long_edge.StartVertex, true);

                Edge   short_edge, long_edge;
                Vertex vert_origin, vert_short_end, vert_long_end;
                determine_orientation(f, out long_edge, out short_edge, out vert_origin, out vert_long_end, out vert_short_end);

                // remember wheter 'long_edge' starts or stops at 'P_orig' (which is important for the direction of the rectangular pattern)
                long_edge_dir[i] = long_edge.StartVertex == vert_origin;
                extrusion_dir[i] = def.WorkAxes.AddByLine(long_edge, true);

                // project important points
                SketchPoint P_orig  = sketch.AddByProjectingEntity(vert_origin) as SketchPoint;
                SketchPoint P_long  = sketch.AddByProjectingEntity(vert_long_end) as SketchPoint;
                SketchPoint P_short = sketch.AddByProjectingEntity(vert_short_end) as SketchPoint; // fails! :(


                // driven constraint of short dimension (determining thickness and depth of tab)
                tab_widthdepth_constr[i] = sketch.DimensionConstraints.AddTwoPointDistance(
                    P_orig, P_short, DimensionOrientationEnum.kAlignedDim,
                    P_short.Geometry, true);

                // driven constraint of long dimenstion (determining number/size of tabs)
                total_length_constr[i] = sketch.DimensionConstraints.AddTwoPointDistance(
                    P_orig, P_long, DimensionOrientationEnum.kAlignedDim,
                    P_long.Geometry, true);



                // appearantly, Profiles.AddForSolid() doesn't like lines that are made entirely out of projected points... (maybe because the line already exists?)
                SketchPoint P_orig_proj = P_orig, P_short_proj = P_short;

                P_short = sketch.SketchPoints.Add(P_short_proj.Geometry, false);
                P_orig  = sketch.SketchPoints.Add(P_orig_proj.Geometry, false);


                // create dimension constraints

                // TODO: calculate better position for text label



                //Debug.Print("constraint short: {0} = {1}", constr_short.Parameter.Expression, constr_short.Parameter.Value);
                //Debug.Print("constraint long: {0} = {1}", constr_long.Parameter.Expression, constr_long.Parameter.Value);

                // create endpoint for rectangle
                Point2d P_end2 = P_short.Geometry.Copy();
                Point2d P_end1 = P_orig.Geometry.Copy();

                Vector2d long_direction = P_orig.Geometry.VectorTo(P_long.Geometry);
                long_direction.ScaleBy(0.2);

                P_end1.TranslateBy(long_direction);
                P_end2.TranslateBy(long_direction);

                SketchPoint P_end1_sk = sketch.SketchPoints.Add(P_end1, false);
                SketchPoint P_end2_sk = sketch.SketchPoints.Add(P_end2, false);

                // constrain endpoints properly
                //sketch.GeometricConstraints.AddCoincident((SketchEntity)long_line2, (SketchEntity)P_end2_sk);
                //sketch.GeometricConstraints.AddCoincident((SketchEntity)long_line, (SketchEntity)P_end1_sk);

                // constraint for tab length (twice, once for each side of the rectangle)
                TwoPointDistanceDimConstraint tab_len_constraint1 = sketch.DimensionConstraints.AddTwoPointDistance(P_orig, P_end1_sk, DimensionOrientationEnum.kAlignedDim, P_end1);
                TwoPointDistanceDimConstraint tab_len_constraint2 = sketch.DimensionConstraints.AddTwoPointDistance(P_short, P_end2_sk, DimensionOrientationEnum.kAlignedDim, P_end2);
                tab_length_constr[i] = tab_len_constraint1;

                // {0}: total length
                // {1}: user input (count or length of single tab)

                string expr;
                if (m_dialog.mode_count.Checked)
                {
                    if (m_dialog.force_parity.Checked)
                    {
                        if (m_dialog.parity_even.Checked)
                        {
                            expr = "{0} / ( round({1}/2)*2 )";
                        }
                        else
                        {
                            expr = "{0} / ( round( ({1}+1)/2 )*2 - 1 )";
                        }
                    }
                    else
                    {
                        expr = "{0} / {1}";
                    }
                }
                else
                {
                    // TODO: take dropdown of >/</~ into account
                    if (m_dialog.force_parity.Checked)
                    {
                        if (m_dialog.parity_even.Checked)
                        {
                            expr = "{0} / ( round( {0}/{1}/2 )*2 )";
                        }
                        else
                        {
                            expr = "{0} / ( round( ({0}/{1}+1)/2 )*2 - 1)";
                        }
                    }
                    else
                    {
                        expr = "{0} / round({0}/{1})";
                    }
                }

                tab_len_constraint1.Parameter.Expression = string.Format(expr, total_length_constr[i].Parameter.Name, tab_user_constr.Name);
                tab_len_constraint2.Parameter.Expression = tab_len_constraint1.Parameter.Name;

                // create a rectangle based on these points
                // two-point rectangle is always axis-aligned -> doesn't work for rotated stuff
                //SketchEntitiesEnumerator rect = sketch.SketchLines.AddAsTwoPointRectangle(P_orig, P_end_sk);
                // this is cumbersome, as the third point is transient and therefore the rectangle would have to be constrained afterwards
                //SketchEntitiesEnumerator rect = sketch.SketchLines.AddAsThreePointRectangle(P_orig, P_short, P_end);


                ObjectCollection rect = m_inventorApplication.TransientObjects.CreateObjectCollection();
                rect.Add(sketch.SketchLines.AddByTwoPoints(P_orig, P_end1_sk));
                rect.Add(sketch.SketchLines.AddByTwoPoints(P_end1_sk, P_end2_sk));
                rect.Add(sketch.SketchLines.AddByTwoPoints(P_end2_sk, P_short));
                rect.Add(sketch.SketchLines.AddByTwoPoints(P_short, P_orig));

                // constrain rectangle

                if (m_dialog.offset.Checked)
                {
                    sketch.GeometricConstraints.AddCoincident((SketchEntity)rect[1], (SketchEntity)P_orig_proj);
                    sketch.GeometricConstraints.AddCoincident((SketchEntity)rect[3], (SketchEntity)P_short_proj);
                    sketch.GeometricConstraints.AddPerpendicular((SketchEntity)rect[1], (SketchEntity)rect[2]);

                    TwoPointDistanceDimConstraint offset_dist = sketch.DimensionConstraints.AddTwoPointDistance(P_orig, P_orig_proj, DimensionOrientationEnum.kAlignedDim, P_orig_proj.Geometry);
                    offset_dist.Parameter.Expression = tab_len_constraint1.Parameter.Name;
                }
                else
                {
                    sketch.GeometricConstraints.AddCoincident((SketchEntity)P_short, (SketchEntity)P_short_proj);
                    sketch.GeometricConstraints.AddCoincident((SketchEntity)P_orig, (SketchEntity)P_orig_proj);
                }

                sketch.GeometricConstraints.AddCoincident((SketchEntity)rect[1], (SketchEntity)P_long);
                sketch.GeometricConstraints.AddParallel((SketchEntity)rect[1], (SketchEntity)rect[3]);

                profile[i]      = sketch.Profiles.AddForSolid(false, rect);
                all_sketches[i] = sketch;

                i++;
            }

            // do extrusions
            for (i = 0; i < total_operations; i++)
            {
                string dist_expr;
                if (m_dialog.auto_depth.Checked)
                {
                    // use thickness of material
                    dist_expr = tab_widthdepth_constr[i].Parameter.Name;
                }
                else
                {
                    // use user input
                    // TODO: validate!
                    dist_expr = m_dialog.tab_depth_input.Text;
                }

                PartFeatureExtentDirectionEnum dir;
                PartFeatureOperationEnum       op;
                if (m_dialog.extrude_positive.Checked)
                {
                    dir = PartFeatureExtentDirectionEnum.kPositiveExtentDirection;
                    op  = PartFeatureOperationEnum.kJoinOperation;
                }
                else
                {
                    dir = PartFeatureExtentDirectionEnum.kNegativeExtentDirection;
                    op  = PartFeatureOperationEnum.kCutOperation;
                }

                // extrude said rectangle
                ExtrudeDefinition extrusion_def = def.Features.ExtrudeFeatures.CreateExtrudeDefinition(profile[i], op);
                extrusion_def.SetDistanceExtent(dist_expr, dir);
                extrusion[i] = def.Features.ExtrudeFeatures.Add(extrusion_def);
            }

            // do rectangular patterns
            for (i = 0; i < total_operations; i++)
            {
                // now repeat that extrusion
                ObjectCollection col = m_inventorApplication.TransientObjects.CreateObjectCollection();
                col.Add(extrusion[i]);

                // TODO: is ceil() actually correct here?
                string offset     = (m_dialog.offset.Checked ? "1" : "0");
                string count_expr = string.Format("ceil(round({0} / {1} - {2}) / 2)", total_length_constr[i].Parameter.Name, tab_length_constr[i].Parameter.Name, offset);


                RectangularPatternFeatureDefinition pattern_def =
                    def.Features.RectangularPatternFeatures.CreateDefinition(
                        col, extrusion_dir[i], long_edge_dir[i], count_expr, tab_length_constr[i].Parameter.Name + "*2");
                // TODO: we could use PatternSpacingType kFitToPathLength here...

                try
                {
                    rect_pattern[i] =
                        def.Features.RectangularPatternFeatures.AddByDefinition(pattern_def);
                }
                catch (Exception ex)
                {
                    Debug.Print("rect pattern failed: {0}", ex.Message);
                    Debug.Print("long edge: {0}, dir: {1}, count_expr = '{2}', len = '{3}'", extrusion_dir[i], long_edge_dir[i], count_expr, tab_length_constr[i].Parameter.Name + "*2");
                    transaction.End();
                    return;
                }
            }


            stop_selection();

            // create custom feature (called a ClientFeature by Inventor) containing all our sketches, extrusions and patterns in a single node

            object start_element;

            if (total_operations == 1)
            {
                // if there is only a single operation, the tree looks like this:

                /*
                 * - extrusion 1 (consumed sketch 1)
                 * - pattern 1
                 */
                start_element = extrusion[0];
            }
            else
            {
                // if there are multiple operations, the sketch is not consumed by the extrusion
                // and the tree looks like this:

                /*
                 * - sketch 1
                 * - sketch 2
                 * - extrusion 1
                 * - extrusion 2
                 * - pattern 1
                 * - pattern 2
                 */
                start_element = all_sketches[0];
            }

            ClientFeatureDefinition feature_def = def.Features.ClientFeatures.CreateDefinition("LaserTab", start_element, rect_pattern[total_operations - 1]);
            ClientFeature           feature     = def.Features.ClientFeatures.Add(feature_def, "{0defbf22-e302-4266-9bc9-fb80d5c8eb7e}");

            // load the icon for our custom feature if not done so already
            if (m_browser_icon == null)
            {
                stdole.IPictureDisp icon = PictureConverter.ImageToPictureDisp(Properties.Resources.browser_icon_16);
                m_browser_icon = document.BrowserPanes.ClientNodeResources.Add("{0defbf22-e302-4266-9bc9-fb80d5c8eb7e}", -1, icon);
            }

            NativeBrowserNodeDefinition ndef = document.BrowserPanes[1].GetBrowserNodeFromObject(feature).BrowserNodeDefinition as NativeBrowserNodeDefinition;

            ndef.OverrideIcon = m_browser_icon;

            transaction.End();
        }