/// <summary> /// 插入宏特征 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="featMgr">特征管理器</param> /// <param name="featureName">特征名</param> /// <param name="parameterNames">参数名</param> /// <param name="parameterTypes">特征类型</param> /// <param name="parameterValues">特征值</param> /// <param name="opts">选项</param> /// <param name="editBodies">编辑实体</param> /// <returns></returns> private static Feature InsertMacroFeature <T>( this IFeatureManager featMgr, string featureName, string[] parameterNames, int[] parameterTypes, string[] parameterValues, swMacroFeatureOptions_e opts, IBody2[] editBodies = null) { var macroFeature = featMgr.InsertMacroFeature3( featureName, typeof(T).FullName, null, parameterNames, parameterTypes, parameterValues, null, null, editBodies, null, (int)opts); if (macroFeature == null) { #if DEBUG var message = GetFeatureInsertError(typeof(T), parameterNames, parameterTypes, parameterValues); #else var message = ""; #endif throw new Exception($"Unable to create feature {typeof(T).FullName}. {message}"); } return(macroFeature); }
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 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); } }