コード例 #1
0
        //this method crashes SOLIDWORKS - need to research
        private void UpdateIconsIfRequired(ISldWorks app, IModelDoc2 model, IFeature feat)
        {
            var data = (feat as IFeature).GetDefinition() as IMacroFeatureData;

            data.AccessSelections(model, null);
            var icons = data.IconFiles as string[];

            if (icons != null)
            {
                if (icons.Any(i =>
                {
                    string iconPath = "";

                    if (Path.IsPathRooted(i))
                    {
                        iconPath = i;
                    }
                    else
                    {
                        iconPath = Path.Combine(
                            Path.GetDirectoryName(this.GetType().Assembly.Location), i);
                    }

                    return(!File.Exists(iconPath));
                }))
                {
                    data.IconFiles = MacroFeatureIconInfo.GetIcons(this.GetType(), app.SupportsHighResIcons());
                    feat.ModifyDefinition(data, model, null);
                }
            }
        }
コード例 #2
0
        private void LoadButtons(ITaskpaneView taskPaneView, ISldWorks app)
        {
            if (Spec.Buttons?.Any() == true)
            {
                using (var iconsConv = m_SvcProvider.GetService <IIconsCreator>())
                {
                    foreach (var btn in Spec.Buttons)
                    {
                        var tooltip = btn.Tooltip;

                        if (string.IsNullOrEmpty(tooltip))
                        {
                            tooltip = btn.Title;
                        }

                        if (btn.StandardIcon.HasValue)
                        {
                            if (!taskPaneView.AddStandardButton((int)btn.StandardIcon, tooltip))
                            {
                                throw new InvalidOperationException($"Failed to add standard button for '{tooltip}'");
                            }
                        }
                        else
                        {
                            var icon = btn.Icon;

                            if (icon == null)
                            {
                                icon = Defaults.Icon;
                            }

                            //NOTE: unlike task pane icon, command icons must have the same transparency key as command manager commands
                            if (app.SupportsHighResIcons(CompatibilityUtils.HighResIconsScope_e.TaskPane))
                            {
                                var imageList = iconsConv.ConvertIcon(new CommandGroupHighResIcon(icon));
                                if (!taskPaneView.AddCustomButton2(imageList, tooltip))
                                {
                                    throw new InvalidOperationException($"Failed to create task pane button for '{tooltip}' with highres icon");
                                }
                            }
                            else
                            {
                                var imagePath = iconsConv.ConvertIcon(new CommandGroupIcon(icon)).First();
                                if (!taskPaneView.AddCustomButton(imagePath, tooltip))
                                {
                                    throw new InvalidOperationException($"Failed to create task pane button for {tooltip}");
                                }
                            }
                        }
                    }
                }
            }
        }
コード例 #3
0
        private void CreateIcons(CommandGroup cmdGroup, Type cmdGroupType, Enum[] cmds, IconsConverter iconsConv)
        {
            IIcon mainIcon = null;

            if (!cmdGroupType.TryGetAttribute <IconAttribute>(a => mainIcon = a.Icon))
            {
                //TODO: add default icon
                mainIcon = new MasterIcon()
                {
                    Icon = new System.Drawing.Bitmap(12, 12)
                };
            }

            var iconList = cmds.Select(c =>
            {
                IIcon cmdIcon = null;
                if (!c.TryGetAttribute <IconAttribute>(a => cmdIcon = a.Icon))
                {
                    //TODO: add default icon
                    cmdIcon = new MasterIcon()
                    {
                        Icon = new System.Drawing.Bitmap(12, 12)
                    };
                }
                return(cmdIcon);
            }).ToArray();

            if (m_App.SupportsHighResIcons())
            {
                var iconsList = iconsConv.ConvertIcon(mainIcon, true);
                cmdGroup.MainIconList = iconsList;
                cmdGroup.IconList     = iconsConv.ConvertIconsGroup(iconList, true);
            }
            else
            {
                var mainIconPath = iconsConv.ConvertIcon(mainIcon, false);

                var smallIcon = mainIconPath[0];
                var largeIcon = mainIconPath[1];

                cmdGroup.SmallMainIcon = smallIcon;
                cmdGroup.LargeMainIcon = largeIcon;

                var iconListPath  = iconsConv.ConvertIconsGroup(iconList, true);
                var smallIconList = iconListPath[0];
                var largeIconList = iconListPath[1];

                cmdGroup.SmallIconList = smallIconList;
                cmdGroup.LargeIconList = largeIconList;
            }
        }
コード例 #4
0
        private static IFeature InsertComFeatureBase(IFeatureManager featMgr, Type macroFeatType,
                                                     string[] paramNames, int[] paramTypes, string[] paramValues,
                                                     int[] dimTypes, double[] dimValues, object[] selection, object[] editBodies)
        {
            if (!typeof(MacroFeatureEx).IsAssignableFrom(macroFeatType))
            {
                throw new InvalidCastException($"{macroFeatType.FullName} must inherit {typeof(MacroFeatureEx).FullName}");
            }

            var options  = swMacroFeatureOptions_e.swMacroFeatureByDefault;
            var provider = "";

            macroFeatType.TryGetAttribute <OptionsAttribute>(a =>
            {
                options  = a.Flags;
                provider = a.Provider;
            });

            var baseName = MacroFeatureInfo.GetBaseName(macroFeatType);

            var progId = MacroFeatureInfo.GetProgId(macroFeatType);

            if (string.IsNullOrEmpty(progId))
            {
                throw new NullReferenceException("Prog id for macro feature cannot be extracted");
            }

            var icons = MacroFeatureIconInfo.GetIcons(macroFeatType, m_App.SupportsHighResIcons());

            using (var selSet = new SelectionGroup(featMgr.Document.ISelectionManager))
            {
                if (selection != null && selection.Any())
                {
                    var selRes = selSet.AddRange(selection);

                    Debug.Assert(selRes);
                }

                var feat = featMgr.InsertMacroFeature3(baseName,
                                                       progId, null, paramNames, paramTypes,
                                                       paramValues, dimTypes, dimValues, editBodies, icons, (int)options) as IFeature;

                return(feat);
            }
        }
コード例 #5
0
        internal TaskPaneHandler(ISldWorks app, ITaskpaneView taskPaneView,
                                 Action <TCmdEnum> cmdHandler, IIconsConverter iconsConv, ILogger logger)
        {
            m_Logger = logger;

            m_TaskPaneView = taskPaneView;
            m_CmdHandler   = cmdHandler;

            if (!typeof(TCmdEnum).IsEnum)
            {
                throw new ArgumentException($"{typeof(TCmdEnum)} must be an enumeration");
            }

            if (typeof(TCmdEnum) != typeof(EmptyTaskPaneCommands_e) && cmdHandler != null)
            {
                var enumValues = Enum.GetValues(typeof(TCmdEnum));

                m_Commands = enumValues.Cast <TCmdEnum>().ToArray();

                foreach (Enum cmdEnum in enumValues)
                {
                    //NOTE: unlike task pane icon, command icons must have the same transparency key as command manager commands
                    var icon = DisplayInfoExtractor.ExtractCommandDisplayIcon <CommandIconAttribute, CommandGroupIcon>(
                        cmdEnum,
                        i => new MasterIcon(i),
                        a => a.Icon);

                    var tooltip = "";

                    if (!cmdEnum.TryGetAttribute <DisplayNameAttribute>(a => tooltip = a.DisplayName))
                    {
                        cmdEnum.TryGetAttribute <DescriptionAttribute>(a => tooltip = a.Description);
                    }

                    if (!cmdEnum.TryGetAttribute <TaskPaneStandardButtonAttribute>(a =>
                    {
                        if (!m_TaskPaneView.AddStandardButton((int)a.Icon, tooltip))
                        {
                            throw new InvalidOperationException($"Failed to add standard button for {cmdEnum}");
                        }
                    }))
                    {
                        if (app.SupportsHighResIcons(SldWorksExtension.HighResIconsScope_e.TaskPane))
                        {
                            var imageList = iconsConv.ConvertIcon(icon, true);
                            if (!m_TaskPaneView.AddCustomButton2(imageList, tooltip))
                            {
                                throw new InvalidOperationException($"Failed to create task pane button for {cmdEnum} with highres icon");
                            }
                        }
                        else
                        {
                            var imagePath = iconsConv.ConvertIcon(icon, false)[0];
                            if (!m_TaskPaneView.AddCustomButton(imagePath, tooltip))
                            {
                                throw new InvalidOperationException($"Failed to create task pane button for {cmdEnum}");
                            }
                        }
                    }
                }

                (m_TaskPaneView as TaskpaneView).TaskPaneToolbarButtonClicked += OnTaskPaneToolbarButtonClicked;
            }

            (m_TaskPaneView as TaskpaneView).TaskPaneDestroyNotify += OnTaskPaneDestroyNotify;
        }