private void refSkeletonCanvas_Paint(object sender, PaintEventArgs e) { e.Graphics.Clear(Color.White); if (refSkeletonAnnotation == null) { return; } var size = BitmapHandler.GetFittingSize(refSkeletonAnnotation.bmp, refSkeletonCanvas.Width, refSkeletonCanvas.Height); refSkeletonCanvasTransform = new Matrix(); refSkeletonCanvasTransform.Scale(size.Width / refSkeletonAnnotation.bmp.Width, size.Height / refSkeletonAnnotation.bmp.Height); e.Graphics.Transform = refSkeletonCanvasTransform; e.Graphics.DrawImage(refSkeletonAnnotation.bmp, Point.Empty); int radius = 10; foreach (JointAnnotation joint in refSkeletonAnnotation.joints) { Brush brush = JointBrush(joint.name, jointNameTextBox.Text, jointBrushDict); e.Graphics.FillEllipse(brush, joint.position.X - radius, joint.position.Y - radius, 2 * radius, 2 * radius); } if (refSkeletonNearestJoint != null) { e.Graphics.FillEllipse(Brushes.Red, refSkeletonNearestJoint.position.X - radius, refSkeletonNearestJoint.position.Y - radius, 2 * radius, 2 * radius); } }
private void animeView_Paint(object sender, PaintEventArgs e) { e.Graphics.Clear(Color.White); float elapsedTime = 0; int i = -1; for (i = 0; i < animeCells.Count; i++) { elapsedTime += animeCells[i].durationMilliseconds; if (playTime <= elapsedTime) { break; } } if (i < 0 || animeCells.Count <= i) { return; } AnimeCell cell = animeCells[i]; if (!composedImageDict.ContainsKey(cell.key)) { return; } Bitmap bmp = composedImageDict[cell.key]; SizeF size = BitmapHandler.GetFittingSize(bmp, animeView.Width, animeView.Height); float ox = (animeView.Width - size.Width) * 0.5f; float oy = (animeView.Height - size.Height) * 0.5f; e.Graphics.DrawImage(bmp, ox, oy, size.Width, size.Height); }
public void AddCommandMgr() { AddTaskPane(); ICommandGroup cmdGroup; BitmapHandler iBmp = new BitmapHandler(); Assembly thisAssembly; thisAssembly = System.Reflection.Assembly.GetAssembly(this.GetType()); cmdGroup = iCmdMgr.CreateCommandGroup(1, "FTL AMF Visualizer", "FTL AMF Visualizer", "", -1); cmdGroup.LargeIconList = iBmp.CreateFileFromResourceBitmap("qwe.ToolbarLarge.bmp", thisAssembly); cmdGroup.SmallIconList = iBmp.CreateFileFromResourceBitmap("qwe.ToolbarSmall.bmp", thisAssembly); cmdGroup.LargeMainIcon = iBmp.CreateFileFromResourceBitmap("qwe.ToolbarLarge.bmp", thisAssembly); cmdGroup.SmallMainIcon = iBmp.CreateFileFromResourceBitmap("qwe.ToolbarSmall.bmp", thisAssembly); //cmdGroup.AddCommandItem("CreateCube", -1, "Create a cube", "Create cube", 0, "CreateCube", "", 0); //cmdGroup.AddCommandItem("Show PMP", -1, "Display sample property manager", "Show PMP", 2, "ShowPMP", "EnablePMP", 2); cmdGroup.AddCommandItem("ImportDMC", -1, "Import a DMC file", "Import a DMC file", 0, "importDMC", "", 0); //cmdGroup.AddCommandItem("AddTaskPane", -1, "Adds Features and Taskpane and Toolbars", "Adds Features and Taskpane and Toolbars", 2, "AddTaskPane", "", 2); cmdGroup.HasToolbar = true; cmdGroup.HasMenu = true; cmdGroup.Activate(); thisAssembly = null; iBmp.Dispose(); }
private static void RegisterAssembly(Type t) { string KeyPath = string.Format(@"SOFTWARE\SolidWorks\AddIns\{0:b}", t.GUID); RegistryKey rk = Registry.LocalMachine.CreateSubKey(KeyPath); rk.SetValue(null, 1); // 1: Add-in will load at start-up rk.SetValue("Title", "Power-SM"); // Title rk.SetValue("Description", "SolidWorks Add-in for Sheet Metal"); // Description #region Bitmap handling region BitmapHandler iBmp = new BitmapHandler(); Assembly thisAssembly; thisAssembly = System.Reflection.Assembly.GetExecutingAssembly(); var rm = new System.Resources.ResourceManager("PowerSM.Properties.Resources", System.Reflection.Assembly.GetExecutingAssembly()); Bitmap add_in = (Bitmap)rm.GetObject("add_icon"); // Copy the bitmap to a suitable permanent location with a meaningful filename String addInPath = System.IO.Path.GetDirectoryName(thisAssembly.Location); String iconPath = System.IO.Path.Combine(addInPath, "add_icon.bmp"); add_in.Save(iconPath); #endregion // Register the icon location rk.SetValue("Icon Path", iconPath); }
private void DrawAnimeCells(Graphics g, Dictionary <string, Bitmap> imageDict, List <AnimeCell> cells, List <AnimeCell> addingCells, AnimeCell prevCell, List <AnimeCell> selectCells, int fw, int fh) { g.Clear(Color.White); int gw = fw / cellGridWidth; int gh = cells.Count / gw + (cells.Count % gw >= 1 ? 1 : 0); int idx = 0; for (int gy = 0; gy < gh; gy++) { for (int gx = 0; gx < gw; gx++) { Rectangle rect = new Rectangle(gx * cellGridWidth, gy * cellGridHeight, cellWidth, cellHeight); if (idx >= cells.Count) { continue; } g.FillRectangle(Brushes.LightGray, rect); if (imageDict.ContainsKey(cells[idx].key)) { Bitmap bmp = imageDict[cells[idx].key]; SizeF size = BitmapHandler.GetFittingSize(bmp, cellWidth, cellHeight); float ox = (cellWidth - size.Width) * 0.5f; float oy = (cellHeight - size.Height) * 0.5f; g.DrawImage(bmp, rect.X + ox, rect.Y + oy, size.Width, size.Height); } idx++; } } foreach (var cell in selectCells) { if (prevCell != null && !cells.Contains(cell)) { continue; } int i = cells.IndexOf(cell); int gx = i % gw; int gy = i / gw; Rectangle rect = new Rectangle(gx * cellGridWidth, gy * cellGridHeight, cellWidth, cellHeight); g.DrawRectangle(cellHighlightPen, rect); } if (prevCell == null || cells.Contains(prevCell)) { int i = prevCell == null ? -1 : cells.IndexOf(prevCell); i += 1; int gx = i % gw; int gy = i / gw; Rectangle rect = new Rectangle(gx * cellGridWidth, gy * cellGridHeight, 3, cellGridHeight); g.FillRectangle(Brushes.Black, rect); } }
public void AddCommandMgr() { ICommandGroup cmdGroup; if (iBmp == null) { iBmp = new BitmapHandler(); } Assembly thisAssembly; int cmdIndex1, cmdIndex2, cmdIndex3; string Title = "Search 3D Models", ToolTip = "Search 3D Models"; int[] docTypes = new int[] { (int)swDocumentTypes_e.swDocASSEMBLY, (int)swDocumentTypes_e.swDocDRAWING, (int)swDocumentTypes_e.swDocPART, (int)swDocumentTypes_e.swDocNONE }; thisAssembly = System.Reflection.Assembly.GetAssembly(this.GetType()); int cmdGroupErr = 0; bool ignorePrevious = false; object registryIDs; //get the ID information stored in the registry bool getDataResult = iCmdMgr.GetGroupDataFromRegistry(mainCmdGroupID, out registryIDs); int[] knownIDs = new int[3] { mainItemID1, mainItemID2, mainItemID3 }; if (getDataResult) { if (!CompareIDs((int[])registryIDs, knownIDs)) //if the IDs don't match, reset the commandGroup { ignorePrevious = true; } } cmdGroup = iCmdMgr.CreateCommandGroup2(mainCmdGroupID, Title, ToolTip, "", -1, ignorePrevious, ref cmdGroupErr); cmdGroup.LargeIconList = iBmp.CreateFileFromResourceBitmap("Search3dModels.ToolbarLarge.bmp", thisAssembly); cmdGroup.SmallIconList = iBmp.CreateFileFromResourceBitmap("Search3dModels.ToolbarSmall.bmp", thisAssembly); cmdGroup.LargeMainIcon = iBmp.CreateFileFromResourceBitmap("Search3dModels.MainIconLarge.bmp", thisAssembly); cmdGroup.SmallMainIcon = iBmp.CreateFileFromResourceBitmap("Search3dModels.MainIconSmall.bmp", thisAssembly); int menuToolbarOption = (int)(swCommandItemType_e.swMenuItem | swCommandItemType_e.swToolbarItem); cmdIndex1 = cmdGroup.AddCommandItem2("Add Model", -1, "Add your model to data base", "Add Model", 1, "LoadAddModelForm", "", mainItemID1, menuToolbarOption); cmdIndex2 = cmdGroup.AddCommandItem2("Get Models", -1, "Get models from data base", "Get Models", 0, "LoadGetModelsForm", "", mainItemID2, menuToolbarOption); cmdIndex3 = cmdGroup.AddCommandItem2("Connection Settings", -1, "Set preferences to connect to your account", "Connection Settings", 2, "LoadConnectionSettingsForm", "", mainItemID3, menuToolbarOption); cmdGroup.HasToolbar = true; cmdGroup.HasMenu = false; cmdGroup.Activate(); }
public Bitmap GetImage() { if (shouldEndImageContext) { var h = new BitmapHandler(); h.Create(UIGraphics.GetImageFromCurrentImageContext()); return(new Bitmap(null, h)); } throw new InvalidOperationException("Can only call GetImage on a Graphics constructed with a specified size"); }
private void referenceImageView_Paint(object sender, PaintEventArgs e) { e.Graphics.Clear(Color.White); if (composition.referenceImage != null) { SizeF size = BitmapHandler.GetFittingSize(composition.referenceImage, referenceImageView.Width, referenceImageView.Height); float ox = -0.5f * (size.Width - referenceImageView.Width); float oy = -0.5f * (size.Height - referenceImageView.Height); e.Graphics.DrawImage(composition.referenceImage, ox, oy, size.Width, size.Height); } }
public void SetTexture(string texturePath, WindowRenderTarget target) { BitmapHandler bmpHandler = new BitmapHandler(); ImagingFactory factory = new ImagingFactory(); var bmps = bmpHandler.LoadBMPSFromFile(texturePath, factory, ImageFormat.Bmp); FormatConverter formatConverter = new FormatConverter(factory); formatConverter.Initialize(bmps, SharpDX.WIC.PixelFormat.Format32bppPBGRA, BitmapDitherType.Spiral8x8, null, 0f, BitmapPaletteType.MedianCut); ObjectBitmap = SharpDX.Direct2D1.Bitmap.FromWicBitmap(target, formatConverter); }
public AddFeature(ISldWorks _swApp) { swApp = _swApp; Doc = swApp.ActiveDoc; BitmapHandler iBmp = new BitmapHandler(); Assembly thisAssembly; thisAssembly = System.Reflection.Assembly.GetAssembly(this.GetType()); var sbm = iBmp.CreateFileFromResourceBitmap("qwe.ToolbarSmall.bmp", thisAssembly); var lbm = iBmp.CreateFileFromResourceBitmap("qwe.ToolbarLarge.bmp", thisAssembly); Doc.InsertLibraryFeature("Dave's LibFeatPartNameIn"); var tpv = swApp.CreateTaskpaneView2(lbm, "DoesIt"); tpv.AddStandardButton(0, "HERE!"); swApp.ActivateTaskPane(1); //tpv.AddStandardButton(1, "tooltip!"); //var toolbar = swApp.AddToolbar4( //var SelMan = Doc.SelectionManager; //string[] Methods = new string[9]; //int Names = 0; //int Types = 0; //int Values = 0; //int vEditBodies = 0; //long options = 0; //int dimTypes = 0; //int dimValue = 0; //string[] icons = new string[3]; //var ThisFile = "C:/Analytics"; //Methods[0] = ThisFile; //Methods[1] = "FeatureModule"; //Methods[2] = "swmRebuild"; //Methods[3] = ThisFile; //Methods[4] = "FeatureModule"; //Methods[5] = "swmEditDefinition"; //Methods[6] = ""; //Methods[7] = ""; //Methods[8] = ""; //A security routine is optional; //var pathname = ThisFile; //icons[0] = pathname + "/FeatureIcon.bmp"; //icons[1] = pathname + "/FeatureIcon.bmp"; //icons[2] = pathname + "/FeatureIcon.bmp"; //options = (long)swMacroFeatureOptions_e.swMacroFeatureByDefault; //Feature selFeat = SelMan.GetSelectedObject6(1, -1); //IFeatureManager swFeatMgr = Doc.FeatureManager; //swFeatMgr.InsertMacroFeature3("EmptyFeature", "", (object)Methods, (object)Names, (object)Types, (object)Values, (object)dimTypes, (object)dimValue, (object)vEditBodies, (object)icons, (int)options); //var boolstatus = feat.MakeSubFeature(selFeat); }
public bool ConnectToSW(object ThisSW, int cookie) { m_App = (ISldWorks)ThisSW; m_AddinID = cookie; m_Bmp = new BitmapHandler(); m_App.SetAddinCallbackInfo(0, this, m_AddinID); m_CmdMgr = m_App.GetCommandManager(cookie); AddCommandMgr(); return(true); }
public SettingsDialog() { InitializeComponent(); // Initialize the merge process combo box comboMergeProcess.DataSource = BitmapHandler.GetAvailableProcesses(); // Load data chkEnableVerboseLogging.Checked = EnableVerboseLogging; chkClearLogOnJobRun.Checked = ClearLogOnJobStart; trackBarNThreads.Value = MaxNumberThreads; comboMergeProcess.SelectedItem = EnabledMergeProcess; }
public static void RegisterFunction(Type t) { Microsoft.Win32.RegistryKey hklm = Microsoft.Win32.Registry.LocalMachine; Microsoft.Win32.RegistryKey hkcu = Microsoft.Win32.Registry.CurrentUser; string keyname = "SOFTWARE\\SOLIDWORKS\\Addins\\{" + t.GUID.ToString() + "}"; Microsoft.Win32.RegistryKey addinkey = hklm.CreateSubKey(keyname); addinkey.SetValue(null, 0); addinkey.SetValue("Description", SWattr.Description); addinkey.SetValue("Title", SWattr.Title); #region Extract icon during registration BitmapHandler iBmp = new BitmapHandler(); Assembly thisAssembly; thisAssembly = System.Reflection.Assembly.GetExecutingAssembly(); String tempPath = iBmp.CreateFileFromResourceBitmap("_2012_PMP_Interfaces.AddInMgrIcon.bmp", thisAssembly); // Copy the bitmap to a suitable permanent location with a meaningful filename String addInPath = System.IO.Path.GetDirectoryName(thisAssembly.Location); String iconPath = System.IO.Path.Combine(addInPath, "AddInMgrIcon.bmp"); System.IO.File.Copy(tempPath, iconPath, true); // Register the icon location addinkey.SetValue("Icon Path", iconPath); #endregion keyname = "Software\\SOLIDWORKS\\AddInsStartup\\{" + t.GUID.ToString() + "}"; addinkey = hkcu.CreateSubKey(keyname); addinkey.SetValue(null, Convert.ToInt32(SWattr.LoadAtStartup), Microsoft.Win32.RegistryValueKind.DWord); }
/// <summary> /// Sets the Drawstate of the window. Can the user draw or interact with desktop and/or see what was drawn earlier. /// </summary> /// <param name="state"></param> internal void ShowState(DrawState state) { switch (state) { case DrawState.TransparentCanDrawNoDesktopInteraction: //This first state is not really transparent, a bitmap of the desktop is used as //background. Necessary to use the InkCanvas to draw. InkCanvas cannot be used if the //window is truly transparent DrawArea.EditingMode = InkCanvasEditingMode.Ink; MakeOpaqueToEvents(); IsHitTestVisible = true; Opacity = 1; using (BitmapHandler handler = new BitmapHandler()) { BackGroundImage.Source = handler.GetDesktopBitmapSource((int)Left, (int)Top, (int)Width, (int)Height); } ClearValue(Window.BackgroundProperty); Show(); CurrentState = state; break; case DrawState.SemitransparentDrawingFixed: //Changes to a semitransparent state where the drawing is fixed. But it is possible to interact //with the desktop. DrawArea.EditingMode = InkCanvasEditingMode.Ink; MakeTransparentToEvents(); IsHitTestVisible = false; Opacity = 0.5; BackGroundImage.ClearValue(Image.SourceProperty); Background = Brushes.White; Show(); CurrentState = state; break; case DrawState.TransparentNoDrawing: DrawArea.EditingMode = InkCanvasEditingMode.Ink; MakeOpaqueToEvents(); IsHitTestVisible = true; Opacity = 0; BackGroundImage.ClearValue(Image.SourceProperty); Background = Brushes.Transparent; Show(); CurrentState = state; break; default: throw new ArgumentOutOfRangeException("state"); } }
public SWCMDGroupService(ISolidWorksAddin addin, ISWAddinCommand addinCommand, ICommandManager iCmdMgr, IStartup startup) { _addin = addin; this.iCmdMgr = iCmdMgr; _startup = startup; _addinCommand = addinCommand; if (_addinCommand.CommandInstances == null) { _addinCommand.CommandInstances = new Dictionary <string, object>(); } if (_addinCommand.CmdGroupIDs == null) { _addinCommand.CmdGroupIDs = new List <int>(); } iBmp = new BitmapHandler(); }
// 示例方法 不进行单元测试 public void BitmapHandlerTest() { var bitmap = System.Drawing.Bitmap.FromStream(new MemoryStream()) .ToBytes(System.Drawing.Imaging.ImageFormat.Bmp).ToBitmap(); var bitmapHanddler = new BitmapHandler(bitmap); bitmapHanddler.ResizeImage(100, 100); bitmap = bitmapHanddler.Cut(0, 0, 100, 100); bitmapHanddler = bitmapHanddler .GrayByPixels() .ClearPicBorder(1) .GrayByLine() .GetPicValidByValue(0) .GetPicValidByValue(0, 1); bitmap = bitmapHanddler.GetPicValidByValue(bitmap, 0); var bitmaps = bitmapHanddler.GetSplitPics(2, 2); var str = bitmapHanddler.GetSingleBmpCode(bitmap, 0); }
public bool ConnectToSW(object thisSw, int cookie) { SwApp = (SldWorks)thisSw; Active = this; SwApp.SetAddinCallbackInfo2(0, this, cookie); CommandManager = SwApp.GetCommandManager(cookie); _Bmp = new BitmapHandler(); AppDomain.CurrentDomain.AssemblyResolve += ResolveAssembly; var d0 = Disposable.Create(() => AppDomain.CurrentDomain.AssemblyResolve -= ResolveAssembly); var d1 = OpenGlRenderer.Setup((SldWorks)SwApp); var d2 = new CompositeDisposable(Setup()); _Disposable = new CompositeDisposable(_Bmp, d0, d1, d2); return(true); }
private void ImportFile(string type, TileSet.TileSetDataType tsetType) { using (OpenFileDialog ofd = new OpenFileDialog()) { ofd.Filter = "PNG files|*.png|All Files|*.*"; ofd.Title = "Select a " + type + " tilset file"; if (ofd.ShowDialog() != DialogResult.OK) { return; } if (!ofd.CheckPathExists) { throw new FileNotFoundException(); } byte[] data = File.ReadAllBytes(ofd.FileName); Bitmap inImage = BitmapHandler.LoadBitmap(data); byte[] tsetData = DecodeIndices(inImage); var room = MapManager.Instance.MapAreas.Single(a => a.Index == currentArea).Rooms.First(); room.tileSet.SetTileSetData(tsetType, tsetData); RedrawTiles(room); switch (tsetType) { case TileSet.TileSetDataType.BG1: Project.Instance.AddPendingChange(new Bg1TileSetChange(currentArea)); break; case TileSet.TileSetDataType.BG2: Project.Instance.AddPendingChange(new Bg2TileSetChange(currentArea)); break; case TileSet.TileSetDataType.COMMON: Project.Instance.AddPendingChange(new CommonTileSetChange(currentArea)); break; } } }
public bool ConnectToSW(object ThisSW, int cookie) { m_App = (ISldWorks)ThisSW; m_AddinID = cookie; m_App.SetAddinCallbackInfo(0, this, m_AddinID); m_Bmp = new BitmapHandler(); m_CmdMgr = m_App.GetCommandManager(cookie); AddCommandMgr(); m_ActivePage = new PropertyManagerPageEx <PropertyPageEventsHandler, DataModel>(m_App); m_ActiveTabPage = new PropertyManagerPageEx <PropertyPageEventsHandler, TabDataModel>(m_App); m_ActivePage.Handler.DataChanged += OnDataChanged; m_ActivePage.Handler.Closing += OnPageClosing; m_ActivePage.Handler.Closed += OnClosed; return(true); }
public static void UpdateImageView(Dictionary <string, Bitmap> imageDict, ImageList imageList, ListView imageView, bool reflesh) { if (reflesh) { for (int i = 0; i < imageList.Images.Count; i++) { imageList.Images[i].Dispose(); } imageList.Images.Clear(); imageView.Items.Clear(); } foreach (var kv in imageDict) { string key = kv.Key; // キーが同じだったら上書き bool exist = false; for (int i = imageView.Items.Count - 1; i >= 0; i--) { string key1 = imageView.Items[i].ImageKey; if (key == key1) { exist = true; if (reflesh) { imageList.Images[imageView.Items[i].ImageKey].Dispose(); imageList.Images.RemoveByKey(imageView.Items[i].ImageKey); imageView.Items.RemoveAt(i); exist = false; } } } if (!exist) { imageList.Images.Add(kv.Key, BitmapHandler.CreateThumbnail(kv.Value, imageList.ImageSize.Width, imageList.ImageSize.Height)); imageView.Items.Add(key, kv.Key); } } }
public void Dispose() { if (_disposed) { return; } if (_bitmapHandler != null) { _bitmapHandler.Dispose(); _bitmapHandler = null; } if (_commandManager != null) { _commandManager.RemoveCommandGroup(_userGroupId); Marshal.ReleaseComObject(_commandManager); _commandManager = null; } _disposed = true; }
private void pictureBox1_Paint(object sender, PaintEventArgs e) { if (an == null) { return; } if (an.bmp == null) { return; } transform = new Matrix(); var fitSize = BitmapHandler.GetFittingSize(an.bmp, pictureBox1.Width, pictureBox1.Height); transform.Scale(fitSize.Width / an.bmp.Width, fitSize.Height / an.bmp.Height); e.Graphics.Transform = transform; e.Graphics.Clear(Color.White); // bmp e.Graphics.DrawImage(an.bmp, Point.Empty); // joints foreach (JointAnnotation joint in an.joints) { e.Graphics.FillEllipse(Brushes.Orange, new RectangleF(joint.position.X - 5, joint.position.Y - 5, 10, 10)); } // nearestJoint if (nearestJoint != null) { e.Graphics.FillEllipse(Brushes.Red, new RectangleF(nearestJoint.position.X - 5, nearestJoint.position.Y - 5, 10, 10)); } // selectJoint if (selectJoint != null) { e.Graphics.FillEllipse(Brushes.Yellow, new RectangleF(selectJoint.position.X - 5, selectJoint.position.Y - 5, 10, 10)); } }
private CommandGroup CreateCommandGroup(bool ignorePrevious, out Dictionary <int, int> commandsDictionary) { var createCommandGroup2Errors = 0; var commandGroup = CommandManager.CreateCommandGroup2(_userGroupId, SolidWorksAddin.AddinTitle, SolidWorksAddin.AddinDescription, string.Empty, _lastItemIndex, ignorePrevious, ref createCommandGroup2Errors); var icons = new string[3]; icons[0] = BitmapHandler.CreateFileFromResourceBitmap("SimpleCadDms.SolidWorks.Addin.Images.IconList_20.png", Assembly.GetExecutingAssembly()); icons[1] = BitmapHandler.CreateFileFromResourceBitmap("SimpleCadDms.SolidWorks.Addin.Images.IconList_32.png", Assembly.GetExecutingAssembly()); icons[2] = BitmapHandler.CreateFileFromResourceBitmap("SimpleCadDms.SolidWorks.Addin.Images.IconList_40.png", Assembly.GetExecutingAssembly()); var mainIcons = new string[3]; mainIcons[0] = BitmapHandler.CreateFileFromResourceBitmap("SimpleCadDms.SolidWorks.Addin.Images.MainIconList_20.png", Assembly.GetExecutingAssembly()); mainIcons[1] = BitmapHandler.CreateFileFromResourceBitmap("SimpleCadDms.SolidWorks.Addin.Images.MainIconList_32.png", Assembly.GetExecutingAssembly()); mainIcons[2] = BitmapHandler.CreateFileFromResourceBitmap("SimpleCadDms.SolidWorks.Addin.Images.MainIconList_40.png", Assembly.GetExecutingAssembly()); commandGroup.IconList = icons; commandGroup.MainIconList = mainIcons; commandsDictionary = new Dictionary <int, int>(); var menuToolbarOption = (int)(swCommandItemType_e.swMenuItem | swCommandItemType_e.swToolbarItem); commandsDictionary[_generateNewIdCmdId] = AddGenerateNewIdCommand(commandGroup); commandsDictionary[_saveWithNewIdCmdId] = AddSaveWithNewIdCommand(commandGroup); commandsDictionary[_saveWithNewIdAndUploadCmdId] = AddSaveWithNewIdAndUploadCommand(commandGroup); commandsDictionary[_deleteDocument] = AddDeleteDocumentCommand(commandGroup); commandGroup.AddSpacer2(_lastItemIndex, menuToolbarOption); commandsDictionary[_saveAndUploadToServerCmdId] = AddSaveAndUploadCommand(commandGroup); commandsDictionary[_downloadFromServerCmdId] = AddDownloadFromServerCommand(commandGroup); commandGroup.HasToolbar = true; commandGroup.HasMenu = true; commandGroup.Activate(); return(commandGroup); }
public void AddCommandMgr() { ICommandGroup cmdGroup; if (iBmp == null) { iBmp = new BitmapHandler(); } Assembly thisAssembly; int cmdIndex0, cmdIndex1; string Title = "C# Addin", ToolTip = "C# Addin"; int[] docTypes = new int[] { (int)swDocumentTypes_e.swDocASSEMBLY, (int)swDocumentTypes_e.swDocDRAWING, (int)swDocumentTypes_e.swDocPART }; thisAssembly = System.Reflection.Assembly.GetAssembly(this.GetType()); int cmdGroupErr = 0; bool ignorePrevious = false; object registryIDs; //get the ID information stored in the registry bool getDataResult = iCmdMgr.GetGroupDataFromRegistry(mainCmdGroupID, out registryIDs); int[] knownIDs = new int[2] { mainItemID1, mainItemID2 }; if (getDataResult) { if (!CompareIDs((int[])registryIDs, knownIDs)) //if the IDs don't match, reset the commandGroup { ignorePrevious = true; } } cmdGroup = iCmdMgr.CreateCommandGroup2(mainCmdGroupID, Title, ToolTip, "", -1, ignorePrevious, ref cmdGroupErr); cmdGroup.LargeIconList = iBmp.CreateFileFromResourceBitmap("SolidWorks_AddIn_Example.ToolbarLarge.bmp", thisAssembly); cmdGroup.SmallIconList = iBmp.CreateFileFromResourceBitmap("SolidWorks_AddIn_Example.ToolbarSmall.bmp", thisAssembly); cmdGroup.LargeMainIcon = iBmp.CreateFileFromResourceBitmap("SolidWorks_AddIn_Example.MainIconLarge.bmp", thisAssembly); cmdGroup.SmallMainIcon = iBmp.CreateFileFromResourceBitmap("SolidWorks_AddIn_Example.MainIconSmall.bmp", thisAssembly); int menuToolbarOption = (int)(swCommandItemType_e.swMenuItem | swCommandItemType_e.swToolbarItem); cmdIndex0 = cmdGroup.AddCommandItem2("CreateCube", -1, "Create a cube", "Create cube", 0, "CreateCube", "", mainItemID1, menuToolbarOption); cmdIndex1 = cmdGroup.AddCommandItem2("Show PMP", -1, "Display sample property manager", "Show PMP", 2, "ShowPMP", "EnablePMP", mainItemID2, menuToolbarOption); cmdGroup.HasToolbar = true; cmdGroup.HasMenu = true; cmdGroup.Activate(); bool bResult; FlyoutGroup flyGroup = iCmdMgr.CreateFlyoutGroup(flyoutGroupID, "Dynamic Flyout", "Flyout Tooltip", "Flyout Hint", cmdGroup.SmallMainIcon, cmdGroup.LargeMainIcon, cmdGroup.SmallIconList, cmdGroup.LargeIconList, "FlyoutCallback", "FlyoutEnable"); flyGroup.AddCommandItem("FlyoutCommand 1", "test", 0, "FlyoutCommandItem1", "FlyoutEnableCommandItem1"); flyGroup.FlyoutType = (int)swCommandFlyoutStyle_e.swCommandFlyoutStyle_Simple; foreach (int type in docTypes) { CommandTab cmdTab; cmdTab = iCmdMgr.GetCommandTab(type, Title); if (cmdTab != null & !getDataResult | ignorePrevious)//if tab exists, but we have ignored the registry info (or changed command group ID), re-create the tab. Otherwise the ids won't matchup and the tab will be blank { bool res = iCmdMgr.RemoveCommandTab(cmdTab); cmdTab = null; } //if cmdTab is null, must be first load (possibly after reset), add the commands to the tabs if (cmdTab == null) { cmdTab = iCmdMgr.AddCommandTab(type, Title); CommandTabBox cmdBox = cmdTab.AddCommandTabBox(); int[] cmdIDs = new int[3]; int[] TextType = new int[3]; cmdIDs[0] = cmdGroup.get_CommandID(cmdIndex0); TextType[0] = (int)swCommandTabButtonTextDisplay_e.swCommandTabButton_TextHorizontal; cmdIDs[1] = cmdGroup.get_CommandID(cmdIndex1); TextType[1] = (int)swCommandTabButtonTextDisplay_e.swCommandTabButton_TextHorizontal; cmdIDs[2] = cmdGroup.ToolbarId; TextType[2] = (int)swCommandTabButtonTextDisplay_e.swCommandTabButton_TextHorizontal | (int)swCommandTabButtonFlyoutStyle_e.swCommandTabButton_ActionFlyout; bResult = cmdBox.AddCommands(cmdIDs, TextType); CommandTabBox cmdBox1 = cmdTab.AddCommandTabBox(); cmdIDs = new int[1]; TextType = new int[1]; cmdIDs[0] = flyGroup.CmdID; TextType[0] = (int)swCommandTabButtonTextDisplay_e.swCommandTabButton_TextBelow | (int)swCommandTabButtonFlyoutStyle_e.swCommandTabButton_ActionFlyout; bResult = cmdBox1.AddCommands(cmdIDs, TextType); cmdTab.AddSeparator(cmdBox1, cmdIDs[0]); } } thisAssembly = null; }
public void setVideoFrameHandler(BitmapHandler videoFrame) { this.videoFrameHandler = videoFrame; }
/// <summary> /// Merges two tiles together. /// </summary> /// <param name="tileA">The first tile for the merge</param> /// <param name="tileB">The second tile for the merge</param> /// <param name="outputDir">The directory to output to</param> /// <returns></returns> private string MergeTiles(Tile tileA, Tile tileB, string outputDir) { Bitmap resultingBitmap = BitmapHandler.MergeBitmaps(tileA.GetBitmap(), tileB.GetBitmap()); return(FS.WriteBitmapToJpeg(resultingBitmap, outputDir, tileA.GetName())); }
public Bitmap GetImage() { if (shouldEndImageContext) { var h = new BitmapHandler(); h.Create(UIGraphics.GetImageFromCurrentImageContext()); return new Bitmap(null, h); } throw new InvalidOperationException("Can only call GetImage on a Graphics constructed with a specified size"); }
public void AddCommandMgr() { ICommandGroup cmdGroup; if (iBmp == null) { iBmp = new BitmapHandler(); } Assembly thisAssembly; int cmdIndex0, cmdIndex1, cmdIndex2, cmdIndex3, cmdIndex4, cmdIndex5, cmdIndex6, cmdIndex7; string Title = "WATEASY", ToolTip = "fast and easy"; int[] docTypes = new int[] { (int)swDocumentTypes_e.swDocASSEMBLY, (int)swDocumentTypes_e.swDocDRAWING, (int)swDocumentTypes_e.swDocPART }; thisAssembly = System.Reflection.Assembly.GetAssembly(this.GetType()); int cmdGroupErr = 0; bool ignorePrevious = false; object registryIDs; //get the ID information stored in the registry bool getDataResult = iCmdMgr.GetGroupDataFromRegistry(mainCmdGroupID, out registryIDs); int[] knownIDs = new int[2] { mainItemID1, mainItemID2 }; if (getDataResult) { if (!CompareIDs((int[])registryIDs, knownIDs)) //if the IDs don't match, reset the commandGroup { ignorePrevious = true; } } cmdGroup = iCmdMgr.CreateCommandGroup2(mainCmdGroupID, Title, ToolTip, "", -1, ignorePrevious, ref cmdGroupErr); cmdGroup.LargeIconList = iBmp.CreateFileFromResourceBitmap("SwCSharpAddinByStanley.ToolbarLarge.bmp", thisAssembly); cmdGroup.SmallIconList = iBmp.CreateFileFromResourceBitmap("SwCSharpAddinByStanley.ToolbarSmall.bmp", thisAssembly); cmdGroup.LargeMainIcon = iBmp.CreateFileFromResourceBitmap("SwCSharpAddinByStanley.MainIconLarge.bmp", thisAssembly); cmdGroup.SmallMainIcon = iBmp.CreateFileFromResourceBitmap("SwCSharpAddinByStanley.MainIconSmall.bmp", thisAssembly); int menuToolbarOption = (int)(swCommandItemType_e.swMenuItem | swCommandItemType_e.swToolbarItem); cmdIndex0 = cmdGroup.AddCommandItem2("清空属性", -1, "清空属性", "清空属性", 0, "PropertyClear", "", mainItemID1, menuToolbarOption); //cmdIndex0 = cmdGroup.AddCommandItem2("CreateCube", -1, "Create a cube", "Create cube", 0, "CreateCube", "", mainItemID1, menuToolbarOption); //cmdIndex1 = cmdGroup.AddCommandItem2("Show PMP", -1, "Display sample property manager", "Show PMP", 2, "ShowPMP", "EnablePMP", mainItemID2, menuToolbarOption); cmdIndex1 = cmdGroup.AddCommandItem2("填写图号", -1, "填写图号", "填写图号", 1, "DrawingNoInput", "", mainItemID2, menuToolbarOption); cmdIndex2 = cmdGroup.AddCommandItem2("配置插件", -1, "配置插件", "配置插件", 2, "ConfigModify", "", mainItemID3, menuToolbarOption); cmdIndex3 = cmdGroup.AddCommandItem2("随机颜色", -1, "随机颜色", "随机颜色", 3, "PartDye", "", mainItemID4, menuToolbarOption); cmdIndex4 = cmdGroup.AddCommandItem2("检查配孔", -1, "检查配孔", "检查配孔", 4, "HoleCheck", "", mainItemID5, menuToolbarOption); cmdIndex5 = cmdGroup.AddCommandItem2("外包尺寸", -1, "外包尺寸", "外包尺寸", 5, "GetBoundingBox", "", mainItemID6, menuToolbarOption); cmdIndex6 = cmdGroup.AddCommandItem2("关联打开", -1, "关联打开", "关联打开", 7, "OpenRelvantFile", "", mainItemID7, menuToolbarOption); cmdIndex7 = cmdGroup.AddCommandItem2("关于我", -1, "关于我", "关于我", 6, "SaveAs", "", mainItemID8, menuToolbarOption); cmdGroup.HasToolbar = true; cmdGroup.HasMenu = true; cmdGroup.Activate(); bool bResult; FlyoutGroup flyGroup = iCmdMgr.CreateFlyoutGroup(flyoutGroupID, "Dynamic Flyout", "Flyout Tooltip", "Flyout Hint", cmdGroup.SmallMainIcon, cmdGroup.LargeMainIcon, cmdGroup.SmallIconList, cmdGroup.LargeIconList, "FlyoutCallback", "FlyoutEnable"); flyGroup.AddCommandItem("FlyoutCommand 1", "test", 0, "FlyoutCommandItem1", "FlyoutEnableCommandItem1"); flyGroup.FlyoutType = (int)swCommandFlyoutStyle_e.swCommandFlyoutStyle_Simple; foreach (int type in docTypes) { CommandTab cmdTab; cmdTab = iCmdMgr.GetCommandTab(type, Title); if (cmdTab != null & !getDataResult | ignorePrevious)//if tab exists, but we have ignored the registry info (or changed command group ID), re-create the tab. Otherwise the ids won't matchup and the tab will be blank { bool res = iCmdMgr.RemoveCommandTab(cmdTab); cmdTab = null; } //if cmdTab is null, must be first load (possibly after reset), add the commands to the tabs //TODO: 将命令添加到tab上 if (cmdTab == null) { cmdTab = iCmdMgr.AddCommandTab(type, Title); CommandTabBox cmdBox = cmdTab.AddCommandTabBox(); int[] cmdIDs = new int[8]; int[] TextType = new int[8]; cmdIDs[0] = cmdGroup.get_CommandID(cmdIndex0); TextType[0] = (int)swCommandTabButtonTextDisplay_e.swCommandTabButton_TextHorizontal; cmdIDs[1] = cmdGroup.get_CommandID(cmdIndex1); TextType[1] = (int)swCommandTabButtonTextDisplay_e.swCommandTabButton_TextHorizontal; cmdIDs[2] = cmdGroup.get_CommandID(cmdIndex2); TextType[2] = (int)swCommandTabButtonTextDisplay_e.swCommandTabButton_TextHorizontal; cmdIDs[3] = cmdGroup.get_CommandID(cmdIndex3); TextType[3] = (int)swCommandTabButtonTextDisplay_e.swCommandTabButton_TextHorizontal; cmdIDs[4] = cmdGroup.get_CommandID(cmdIndex4); TextType[4] = (int)swCommandTabButtonTextDisplay_e.swCommandTabButton_TextHorizontal; cmdIDs[5] = cmdGroup.get_CommandID(cmdIndex5); TextType[5] = (int)swCommandTabButtonTextDisplay_e.swCommandTabButton_TextHorizontal; cmdIDs[6] = cmdGroup.get_CommandID(cmdIndex6); TextType[6] = (int)swCommandTabButtonTextDisplay_e.swCommandTabButton_TextHorizontal; cmdIDs[7] = cmdGroup.get_CommandID(cmdIndex7); TextType[7] = (int)swCommandTabButtonTextDisplay_e.swCommandTabButton_TextHorizontal; //cmdIDs[2] = cmdGroup.ToolbarId; //TextType[2] = (int)swCommandTabButtonTextDisplay_e.swCommandTabButton_TextHorizontal | (int)swCommandTabButtonFlyoutStyle_e.swCommandTabButton_ActionFlyout; bResult = cmdBox.AddCommands(cmdIDs, TextType); CommandTabBox cmdBox1 = cmdTab.AddCommandTabBox(); cmdIDs = new int[1]; TextType = new int[1]; cmdIDs[0] = flyGroup.CmdID; TextType[0] = (int)swCommandTabButtonTextDisplay_e.swCommandTabButton_TextBelow | (int)swCommandTabButtonFlyoutStyle_e.swCommandTabButton_ActionFlyout; bResult = cmdBox1.AddCommands(cmdIDs, TextType); cmdTab.AddSeparator(cmdBox1, cmdIDs[0]); } } thisAssembly = null; }
/// <summary> /// 添加命令栏 /// </summary> public void AddCommandMgr() { ICommandGroup cmdGroup; if (iBmp == null) { iBmp = new BitmapHandler(); } Assembly thisAssembly; int cmdIndex0; int cmdIndex1; int cmdIndex2; int cmdIndex3; int cmdIndex4; string Title = "ZQ插件", ToolTip = "ZQ插件"; int[] docTypes = new int[] { (int)swDocumentTypes_e.swDocASSEMBLY, (int)swDocumentTypes_e.swDocDRAWING, (int)swDocumentTypes_e.swDocPART }; thisAssembly = System.Reflection.Assembly.GetAssembly(this.GetType()); int cmdGroupErr = 0; bool ignorePrevious = false; object registryIDs; //get the ID information stored in the registry bool getDataResult = iCmdMgr.GetGroupDataFromRegistry(mainCmdGroupID, out registryIDs); int[] knownIDs = new int[5] { mainItemID1, mainItemID2, mainItemID3, mainItemID4, mainItemID5 }; if (getDataResult) { //if the IDs don't match, reset the commandGroup if (!CompareIDs((int[])registryIDs, knownIDs)) { ignorePrevious = true; } } //定义图标的显示(SwCSharpAddin1.icon.ToolbarLarge.bmp代表项目目录,→) cmdGroup = iCmdMgr.CreateCommandGroup2(mainCmdGroupID, Title, ToolTip, "", -1, ignorePrevious, ref cmdGroupErr); cmdGroup.LargeIconList = iBmp.CreateFileFromResourceBitmap("ZQaddin.icon.ToolbarLarge.bmp", thisAssembly); cmdGroup.SmallIconList = iBmp.CreateFileFromResourceBitmap("ZQaddin.icon.ToolbarSmall.bmp", thisAssembly); cmdGroup.LargeMainIcon = iBmp.CreateFileFromResourceBitmap("ZQaddin.icon.MainIconLarge.bmp", thisAssembly); cmdGroup.SmallMainIcon = iBmp.CreateFileFromResourceBitmap("ZQaddin.icon.MainIconSmall.bmp", thisAssembly); int menuToolbarOption = (int)(swCommandItemType_e.swMenuItem | swCommandItemType_e.swToolbarItem); //工具栏1:申请编码 cmdIndex0 = cmdGroup.AddCommandItem2("申请编码", -1, "申请编码", "申请编码", 0, "GetMyCode", "申请编码", mainItemID1, menuToolbarOption); //工具栏2:打印图纸 cmdIndex1 = cmdGroup.AddCommandItem2("打印图纸", -1, "打印图纸", "打印图纸", 1, "MyPrinter", "打印图纸", mainItemID5, menuToolbarOption); //工具栏3:查找缺失文件 cmdIndex2 = cmdGroup.AddCommandItem2("查找缺失文件", -1, "查找缺失文件", "查找缺失文件", 2, "MySearch", "查找缺失文件", mainItemID3, menuToolbarOption); //工具栏4:模型打包 cmdIndex3 = cmdGroup.AddCommandItem2("模型打包", -1, "模型打包", "模型打包", 3, "MyPackage", "模型打包", mainItemID4, menuToolbarOption); cmdGroup.HasToolbar = true; //显示工具栏 cmdGroup.HasMenu = true; //显示菜单栏 cmdGroup.Activate(); bool bResult; foreach (int type in docTypes) { CommandTab cmdTab; cmdTab = iCmdMgr.GetCommandTab(type, Title); if (cmdTab != null & !getDataResult | ignorePrevious)//if tab exists, but we have ignored the registry info (or changed command group ID), re-create the tab. Otherwise the ids won't matchup and the tab will be blank { bool res = iCmdMgr.RemoveCommandTab(cmdTab); cmdTab = null; } //if cmdTab is null, must be first load (possibly after reset), add the commands to the tabs if (cmdTab == null) { cmdTab = iCmdMgr.AddCommandTab(type, Title); CommandTabBox cmdBox = cmdTab.AddCommandTabBox(); int[] cmdIDs = new int[5]; int[] TextType = new int[5]; //工具栏1 cmdIDs[0] = cmdGroup.get_CommandID(cmdIndex0); TextType[0] = (int)swCommandTabButtonTextDisplay_e.swCommandTabButton_TextBelow; //工具栏2 cmdIDs[1] = cmdGroup.get_CommandID(cmdIndex1); TextType[1] = (int)swCommandTabButtonTextDisplay_e.swCommandTabButton_TextBelow; //工具栏3 cmdIDs[2] = cmdGroup.get_CommandID(cmdIndex2); TextType[2] = (int)swCommandTabButtonTextDisplay_e.swCommandTabButton_TextBelow; //工具栏4 cmdIDs[3] = cmdGroup.get_CommandID(cmdIndex3); TextType[3] = (int)swCommandTabButtonTextDisplay_e.swCommandTabButton_TextBelow; //cmdIDs[2] = cmdGroup.ToolbarId; //TextType[2] = (int)swCommandTabButtonTextDisplay_e.swCommandTabButton_TextHorizontal | (int)swCommandTabButtonFlyoutStyle_e.swCommandTabButton_ActionFlyout; bResult = cmdBox.AddCommands(cmdIDs, TextType); CommandTabBox cmdBox1 = cmdTab.AddCommandTabBox(); cmdIDs = new int[1]; TextType = new int[1]; //cmdIDs[0] = flyGroup.CmdID; //TextType[0] = (int)swCommandTabButtonTextDisplay_e.swCommandTabButton_TextBelow | (int)swCommandTabButtonFlyoutStyle_e.swCommandTabButton_ActionFlyout; bResult = cmdBox1.AddCommands(cmdIDs, TextType); cmdTab.AddSeparator(cmdBox1, cmdIDs[0]); } } thisAssembly = null; }
public void AddCommandMgr() { ICommandGroup cmdGroup; BitmapHandler iBmp = new BitmapHandler(); Assembly thisAssembly; int cmdIndex0, cmdIndex1, cmdIndex2; string Title = "EDS设计平台", ToolTip = "EDS设计平台"; int[] docTypes = new int[] { (int)swDocumentTypes_e.swDocASSEMBLY, (int)swDocumentTypes_e.swDocDRAWING, (int)swDocumentTypes_e.swDocPART }; thisAssembly = System.Reflection.Assembly.GetAssembly(this.GetType()); cmdGroup = iCmdMgr.CreateCommandGroup(1, Title, ToolTip, "", -1); cmdGroup.LargeIconList = iBmp.CreateFileFromResourceBitmap("CAD3dSW.Resources.ToolbarLarge.bmp", thisAssembly); cmdGroup.SmallIconList = iBmp.CreateFileFromResourceBitmap("CAD3dSW.Resources.ToolbarSmall.bmp", thisAssembly); cmdGroup.LargeMainIcon = iBmp.CreateFileFromResourceBitmap("CAD3dSW.Resources.MainIconLarge.bmp", thisAssembly); cmdGroup.SmallMainIcon = iBmp.CreateFileFromResourceBitmap("CAD3dSW.Resources.MainIconSmall.bmp", thisAssembly); cmdIndex0 = cmdGroup.AddCommandItem("重命名组件", -1, "重命名组件", "重命名组件", 3, "RenameComponent", "", 0); cmdIndex1 = cmdGroup.AddCommandItem("启动CAD工作站", -1, "启动CAD工作站,自动处理任务", "CAD工作站", 2, "RunCADworkstation", "EnablePMP", 1); cmdIndex2 = cmdGroup.AddCommandItem("修改为此配置", -1, "修改全部尺寸为此配置", "修改为此配置", 1, "Testing", "", 2); //cmdIndex3 = cmdGroup.AddCommandItem("功能测试", -1, "开发中功能测试", "功能测试", 1, "Test", "", 3); cmdGroup.HasToolbar = true; cmdGroup.HasMenu = true; cmdGroup.Activate(); bool bResult; foreach (int type in docTypes) { ICommandTab cmdTab; cmdTab = iCmdMgr.GetCommandTab(type, Title); if (cmdTab == null) { cmdTab = (ICommandTab)iCmdMgr.AddCommandTab(type, Title); CommandTabBox cmdBox = cmdTab.AddCommandTabBox(); int[] cmdIDs = new int[4]; int[] TextType = new int[4]; cmdIDs[0] = cmdGroup.get_CommandID(cmdIndex0); System.Diagnostics.Debug.Print(cmdGroup.get_CommandID(cmdIndex0).ToString()); TextType[0] = (int)swCommandTabButtonTextDisplay_e.swCommandTabButton_TextHorizontal; cmdIDs[1] = cmdGroup.get_CommandID(cmdIndex1); System.Diagnostics.Debug.Print(cmdGroup.get_CommandID(cmdIndex1).ToString()); TextType[1] = (int)swCommandTabButtonTextDisplay_e.swCommandTabButton_TextHorizontal; cmdIDs[2] = cmdGroup.get_CommandID(cmdIndex2); System.Diagnostics.Debug.Print(cmdGroup.get_CommandID(cmdIndex2).ToString()); TextType[2] = (int)swCommandTabButtonTextDisplay_e.swCommandTabButton_TextHorizontal; bResult = cmdBox.AddCommands(cmdIDs, TextType); CommandTabBox cmdBox1 = cmdTab.AddCommandTabBox(); cmdIDs = new int[1]; TextType = new int[1]; //cmdIDs[0] = cmdGroup.ToolbarId; //TextType[0] = (int)swCommandTabButtonTextDisplay_e.swCommandTabButton_TextBelow | (int)swCommandTabButtonFlyoutStyle_e.swCommandTabButton_ActionFlyout; bResult = cmdBox1.AddCommands(cmdIDs, TextType); cmdTab.AddSeparator(cmdBox1, cmdGroup.ToolbarId); } } thisAssembly = null; iBmp.Dispose(); }
public void AddCommandMgr() { ICommandGroup cmdGroup; if (m_iBmp == null) { m_iBmp = new BitmapHandler(); } Assembly thisAssembly; int cmdIndex0, cmdIndex1; string Title = "C# Addin", ToolTip = "C# Addin"; int[] docTypes = new int[] { (int)swDocumentTypes_e.swDocASSEMBLY, (int)swDocumentTypes_e.swDocDRAWING, (int)swDocumentTypes_e.swDocPART }; thisAssembly = System.Reflection.Assembly.GetAssembly(this.GetType()); int cmdGroupErr = 0; bool ignorePrevious = false; object registryIDs; //get the ID information stored in the registry bool getDataResult = m_iCmdMgr.GetGroupDataFromRegistry(mainCmdGroupID, out registryIDs); int[] knownIDs = new int[2] { mainItemID1, mainItemID2 }; if (getDataResult) { if (!CompareIDs((int[])registryIDs, knownIDs)) //if the IDs don't match, reset the commandGroup { ignorePrevious = true; } } cmdGroup = m_iCmdMgr.CreateCommandGroup2(mainCmdGroupID, Title, ToolTip, "", -1, ignorePrevious, ref cmdGroupErr); // Add bitmaps to your project and set them as embedded resources or provide a direct path to the bitmaps. icons[0] = m_iBmp.CreateFileFromResourceBitmap("SwCSharpAddin1.toolbar20x.png", thisAssembly); icons[1] = m_iBmp.CreateFileFromResourceBitmap("SwCSharpAddin1.toolbar32x.png", thisAssembly); icons[2] = m_iBmp.CreateFileFromResourceBitmap("SwCSharpAddin1.toolbar40x.png", thisAssembly); icons[3] = m_iBmp.CreateFileFromResourceBitmap("SwCSharpAddin1.toolbar64x.png", thisAssembly); icons[4] = m_iBmp.CreateFileFromResourceBitmap("SwCSharpAddin1.toolbar96x.png", thisAssembly); icons[5] = m_iBmp.CreateFileFromResourceBitmap("SwCSharpAddin1.toolbar128x.png", thisAssembly); mainIcons[0] = m_iBmp.CreateFileFromResourceBitmap("SwCSharpAddin1.mainicon_20.png", thisAssembly); mainIcons[1] = m_iBmp.CreateFileFromResourceBitmap("SwCSharpAddin1.mainicon_32.png", thisAssembly); mainIcons[2] = m_iBmp.CreateFileFromResourceBitmap("SwCSharpAddin1.mainicon_40.png", thisAssembly); mainIcons[3] = m_iBmp.CreateFileFromResourceBitmap("SwCSharpAddin1.mainicon_64.png", thisAssembly); mainIcons[4] = m_iBmp.CreateFileFromResourceBitmap("SwCSharpAddin1.mainicon_96.png", thisAssembly); mainIcons[5] = m_iBmp.CreateFileFromResourceBitmap("SwCSharpAddin1.mainicon_128.png", thisAssembly); cmdGroup.MainIconList = mainIcons; cmdGroup.IconList = icons; int menuToolbarOption = (int)(swCommandItemType_e.swMenuItem | swCommandItemType_e.swToolbarItem); cmdIndex0 = cmdGroup.AddCommandItem2("CreateCube", -1, "Create a cube", "Create cube", 0, "CreateCube", "", mainItemID1, menuToolbarOption); cmdIndex1 = cmdGroup.AddCommandItem2("Show PMP", -1, "Display sample property manager", "Show PMP", 2, "ShowPMP", "EnablePMP", mainItemID2, menuToolbarOption); cmdGroup.HasToolbar = true; cmdGroup.HasMenu = true; cmdGroup.Activate(); bool bResult; FlyoutGroup flyGroup = m_iCmdMgr.CreateFlyoutGroup2(flyoutGroupID, "Dynamic Flyout", "Flyout Tooltip", "Flyout Hint", cmdGroup.MainIconList, cmdGroup.IconList, "FlyoutCallback", "FlyoutEnable"); flyGroup.AddCommandItem("FlyoutCommand 1", "test", 0, "FlyoutCommandItem1", "FlyoutEnableCommandItem1"); flyGroup.FlyoutType = (int)swCommandFlyoutStyle_e.swCommandFlyoutStyle_Simple; foreach (int type in docTypes) { CommandTab cmdTab; cmdTab = m_iCmdMgr.GetCommandTab(type, Title); if (cmdTab != null & !getDataResult | ignorePrevious)//if tab exists, but we have ignored the registry info (or changed command group ID), re-create the tab. Otherwise the ids won't matchup and the tab will be blank { bool res = m_iCmdMgr.RemoveCommandTab(cmdTab); cmdTab = null; } //if cmdTab is null, must be first load (possibly after reset), add the commands to the tabs if (cmdTab == null) { cmdTab = m_iCmdMgr.AddCommandTab(type, Title); CommandTabBox cmdBox = cmdTab.AddCommandTabBox(); int[] cmdIDs = new int[3]; int[] TextType = new int[3]; cmdIDs[0] = cmdGroup.get_CommandID(cmdIndex0); TextType[0] = (int)swCommandTabButtonTextDisplay_e.swCommandTabButton_TextHorizontal; cmdIDs[1] = cmdGroup.get_CommandID(cmdIndex1); TextType[1] = (int)swCommandTabButtonTextDisplay_e.swCommandTabButton_TextHorizontal; cmdIDs[2] = cmdGroup.ToolbarId; TextType[2] = (int)swCommandTabButtonTextDisplay_e.swCommandTabButton_TextHorizontal | (int)swCommandTabButtonFlyoutStyle_e.swCommandTabButton_ActionFlyout; bResult = cmdBox.AddCommands(cmdIDs, TextType); CommandTabBox cmdBox1 = cmdTab.AddCommandTabBox(); cmdIDs = new int[1]; TextType = new int[1]; cmdIDs[0] = flyGroup.CmdID; TextType[0] = (int)swCommandTabButtonTextDisplay_e.swCommandTabButton_TextBelow | (int)swCommandTabButtonFlyoutStyle_e.swCommandTabButton_ActionFlyout; bResult = cmdBox1.AddCommands(cmdIDs, TextType); cmdTab.AddSeparator(cmdBox1, cmdIDs[0]); } } // Create a third-party icon in the context-sensitive menus of faces in parts // To see this menu, right click on any face in the part Frame swFrame; swFrame = m_iSwApp.Frame(); bResult = swFrame.AddMenuPopupIcon3((int)swDocumentTypes_e.swDocPART, (int)swSelectType_e.swSelFACES, "third-party context-sensitive CSharp", m_addinID, "PopupCallbackFunction", "PopupEnable", "", cmdGroup.MainIconList); // create and register the shortcut menu registerID = m_iSwApp.RegisterThirdPartyPopupMenu(); // add a menu break at the top of the shortcut menu bResult = m_iSwApp.AddItemToThirdPartyPopupMenu2(registerID, (int)swDocumentTypes_e.swDocPART, "Menu Break", m_addinID, "", "", "", "", "", (int)swMenuItemType_e.swMenuItemType_Break); // add a couple of items to the shortcut menu bResult = m_iSwApp.AddItemToThirdPartyPopupMenu2(registerID, (int)swDocumentTypes_e.swDocPART, "Test1", m_addinID, "TestCallback", "EnableTest", "", "Test1", mainIcons[0], (int)swMenuItemType_e.swMenuItemType_Default); bResult = m_iSwApp.AddItemToThirdPartyPopupMenu2(registerID, (int)swDocumentTypes_e.swDocPART, "Test2", m_addinID, "TestCallback", "EnableTest", "", "Test2", mainIcons[0], (int)swMenuItemType_e.swMenuItemType_Default); // add a separator bar to the shortcut menu bResult = m_iSwApp.AddItemToThirdPartyPopupMenu2(registerID, (int)swDocumentTypes_e.swDocPART, "separator", m_addinID, "", "", "", "", "", (int)swMenuItemType_e.swMenuItemType_Separator); // add another item to the shortcut menu bResult = m_iSwApp.AddItemToThirdPartyPopupMenu2(registerID, (int)swDocumentTypes_e.swDocPART, "Test3", m_addinID, "TestCallback", "EnableTest", "", "Test3", mainIcons[0], (int)swMenuItemType_e.swMenuItemType_Default); // add an icon to a menu bar of the shortcut menu bResult = m_iSwApp.AddItemToThirdPartyPopupMenu2(registerID, (int)swDocumentTypes_e.swDocPART, "", m_addinID, "TestCallback", "EnableTest", "", "NoOp", mainIcons[0], (int)swMenuItemType_e.swMenuItemType_Default); thisAssembly = null; }