public SwMacroFeatureDefinition()
        {
            string provider = "";

            this.GetType().TryGetAttribute <MissingDefinitionErrorMessage>(a =>
            {
                provider = a.Message;
            });

            m_Provider = provider;

            var svcColl = new ServiceCollection();

            svcColl.AddOrReplace <IXLogger>(() => new TraceLogger($"xCad.MacroFeature.{this.GetType().FullName}"));
            svcColl.AddOrReplace <IIconsCreator>(() => new BaseIconsCreator());

            ConfigureServices?.Invoke(this, svcColl);
            OnConfigureServices(svcColl);

            m_SvcProvider = svcColl.CreateProvider();

            m_Logger = m_SvcProvider.GetService <IXLogger>();

            CustomFeatureDefinitionInstanceCache.RegisterInstance(this);

            var iconsConv = m_SvcProvider.GetService <IIconsCreator>();

            iconsConv.KeepIcons   = true;
            iconsConv.IconsFolder = MacroFeatureIconInfo.GetLocation(this.GetType());
            TryCreateIcons(iconsConv);
        }
        //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);
                }
            }
        }
Esempio n. 3
0
        protected IFeature InsertComFeatureBase(string[] paramNames, int[] paramTypes, string[] paramValues,
                                                int[] dimTypes, double[] dimValues, object[] selection, object[] editBodies)
        {
            if (!typeof(SwMacroFeatureDefinition).IsAssignableFrom(DefinitionType))
            {
                throw new InvalidCastException($"{DefinitionType.FullName} must inherit {typeof(SwMacroFeatureDefinition).FullName}");
            }

            var options  = CustomFeatureOptions_e.Default;
            var provider = "";

            DefinitionType.TryGetAttribute <CustomFeatureOptionsAttribute>(a =>
            {
                options  = a.Flags;
                provider = a.Provider;
            });

            var baseName = MacroFeatureInfo.GetBaseName(DefinitionType);

            var progId = MacroFeatureInfo.GetProgId(DefinitionType);

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

            var icons = MacroFeatureIconInfo.GetIcons(DefinitionType,
                                                      CompatibilityUtils.SupportsHighResIcons(SwMacroFeatureDefinition.Application.Application, CompatibilityUtils.HighResIconsScope_e.MacroFeature));

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

                    Debug.Assert(selRes);
                }

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

                return(feat);
            }
        }
        private void TryCreateIcons()
        {
            var iconsConverter = new IconsConverter(
                MacroFeatureIconInfo.GetLocation(this.GetType()), false);

            IIcon regIcon  = null;
            IIcon highIcon = null;
            IIcon suppIcon = null;

            this.GetType().TryGetAttribute <IconAttribute>(a =>
            {
                regIcon  = a.Regular;
                highIcon = a.Highlighted;
                suppIcon = a.Suppressed;
            });

            if (regIcon == null)
            {
                //TODO: load default
            }

            if (highIcon == null)
            {
                highIcon = regIcon;
            }

            if (suppIcon == null)
            {
                suppIcon = regIcon;
            }

            //Creation of icons may fail if user doesn't have write permissions or icon is locked
            try
            {
                iconsConverter.ConvertIcon(regIcon, true);
                iconsConverter.ConvertIcon(suppIcon, true);
                iconsConverter.ConvertIcon(highIcon, true);
                iconsConverter.ConvertIcon(regIcon, false);
                iconsConverter.ConvertIcon(suppIcon, false);
                iconsConverter.ConvertIcon(highIcon, false);
            }
            catch
            {
            }
        }
Esempio n. 5
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);
            }
        }
Esempio n. 6
0
        private void TryCreateIcons()
        {
            var iconsConverter = new IconsConverter(
                MacroFeatureIconInfo.GetLocation(this.GetType()), false);

            System.Drawing.Image icon = null;

            this.GetType().TryGetAttribute <IconAttribute>(a =>
            {
                icon = IconsConverter.FromXImage(a.Icon);
            });

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

            //TODO: create different icons for highlighted and suppressed
            var regular     = icon;
            var highlighted = icon;
            var suppressed  = icon;

            //Creation of icons may fail if user doesn't have write permissions or icon is locked
            try
            {
                iconsConverter.ConvertIcon(new MacroFeatureIcon(icon, MacroFeatureIconInfo.RegularName));
                iconsConverter.ConvertIcon(new MacroFeatureIcon(highlighted, MacroFeatureIconInfo.HighlightedName));
                iconsConverter.ConvertIcon(new MacroFeatureIcon(suppressed, MacroFeatureIconInfo.SuppressedName));
                iconsConverter.ConvertIcon(new MacroFeatureHighResIcon(icon, MacroFeatureIconInfo.RegularName));
                iconsConverter.ConvertIcon(new MacroFeatureHighResIcon(highlighted, MacroFeatureIconInfo.HighlightedName));
                iconsConverter.ConvertIcon(new MacroFeatureHighResIcon(suppressed, MacroFeatureIconInfo.SuppressedName));
            }
            catch (Exception ex)
            {
                Logger.Log(ex);
            }
        }
Esempio n. 7
0
        private void TryCreateIcons()
        {
            var iconsConverter = new IconsConverter(
                MacroFeatureIconInfo.GetLocation(this.GetType()), false);

            MacroFeatureIcon regIcon  = null;
            MacroFeatureIcon highIcon = null;
            MacroFeatureIcon suppIcon = null;

            this.GetType().TryGetAttribute <FeatureIconAttribute>(a =>
            {
                regIcon  = a.Regular;
                highIcon = a.Highlighted;
                suppIcon = a.Suppressed;
            });

            if (regIcon == null)
            {
                Image icon = null;

                this.GetType().TryGetAttribute <Common.Attributes.IconAttribute>(a =>
                {
                    icon = a.Icon;
                });

                if (icon == null)
                {
                    icon = Resources.default_icon;
                }

                regIcon = new MasterIcon(MacroFeatureIconInfo.RegularName)
                {
                    Icon = icon
                };
            }

            if (highIcon == null)
            {
                highIcon = regIcon.Clone(MacroFeatureIconInfo.HighlightedName);
            }

            if (suppIcon == null)
            {
                suppIcon = regIcon.Clone(MacroFeatureIconInfo.SuppressedName);
            }

            //Creation of icons may fail if user doesn't have write permissions or icon is locked
            try
            {
                iconsConverter.ConvertIcon(regIcon, true);
                iconsConverter.ConvertIcon(suppIcon, true);
                iconsConverter.ConvertIcon(highIcon, true);
                iconsConverter.ConvertIcon(regIcon, false);
                iconsConverter.ConvertIcon(suppIcon, false);
                iconsConverter.ConvertIcon(highIcon, false);
            }
            catch (Exception ex)
            {
                Logger.Log(ex);
            }
        }
Esempio n. 8
0
        internal MacroFeatureParametersParser(Type macroFeatType)
        {
            var app = Context.CurrentApp;

            m_CurrentIcons = MacroFeatureIconInfo.GetIcons(macroFeatType, app.SupportsHighResIcons());
        }