Esempio n. 1
0
        protected override MacroFeatureRebuildResult OnRebuild(ISldWorks app, IModelDoc2 model,
                                                               IFeature feature, RoundStockFeatureParameters parameters)
        {
            var cylParams = GetCylinderParams(model, parameters);

            //temp
            SetProperties(model, parameters, cylParams);
            //

            parameters.Height = cylParams.Height;
            parameters.Radius = cylParams.Radius;

            var featData = feature.GetDefinition() as IMacroFeatureData;

            MacroFeatureOutdateState_e state;

            SetParameters(model, feature, featData, parameters, out state);

            if (state != MacroFeatureOutdateState_e.UpToDate)
            {
                app.ShowBubbleTooltip("Stock Master",
                                      $"'{feature.Name}' feature is outdated. Edit definition of the feature to update",
                                      BubbleTooltipPosition_e.TopLeft, Resources.warning_icon);
            }

            if (parameters.CreateSolidBody)
            {
                var body = m_StockModel.CreateCylindricalStock(cylParams);
                return(MacroFeatureRebuildResult.FromBody(body, feature.GetDefinition() as IMacroFeatureData));
            }
            else
            {
                return(MacroFeatureRebuildResult.FromStatus(true));
            }
        }
Esempio n. 2
0
        private void PrintFeatureTypes(IFeature feat)
        {
            object featDef = feat.GetDefinition();

            if (featDef != null)
            {
                foreach (Type defType in FindSpecificInterfacesFromDispatch(featDef))
                {
                    Debug.Print("Feature Definition: " + defType.FullName);
                }
            }
            else
            {
                Debug.Print("Feature Definition: None");
            }

            object featSpec = feat.GetSpecificFeature2();

            if (featSpec != null)
            {
                foreach (Type specType in FindSpecificInterfacesFromDispatch(featSpec))
                {
                    Debug.Print("Specific Feature: " + specType.FullName);
                }
            }
            else
            {
                Debug.Print("Specific Feature: None");
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Replaces existing macro feature with a new one preserving the parameters
        /// </summary>
        /// <typeparam name="TMacroFeature">Type of macro feature</typeparam>
        /// <param name="featMgr">Pointer to feature manager</param>
        /// <param name="feat">Pointer to feature to replace</param>
        /// <returns>Ne replaced feature</returns>
        public static IFeature ReplaceComFeature <TMacroFeature>(this IFeatureManager featMgr, IFeature feat)
            where TMacroFeature : MacroFeatureEx
        {
            if (feat == null)
            {
                throw new ArgumentNullException(nameof(feat));
            }

            var featData = feat.GetDefinition() as IMacroFeatureData;

            if (featData == null)
            {
                throw new NullReferenceException("Specified feature not a macro feature");
            }

            var model = featMgr.Document;

            object parameters = null;

            if (typeof(TMacroFeature).IsAssignableToGenericType(typeof(MacroFeatureEx <>)))
            {
                featData.AccessSelections(model, null);

                var paramsType = typeof(TMacroFeature).GetArgumentsOfGenericType(typeof(MacroFeatureEx <>)).First();
                IDisplayDimension[]        dispDims;
                IBody2[]                   editBodies;
                MacroFeatureOutdateState_e state;
                string[]                   dispDimParams;
                parameters = m_ParamsParser.GetParameters(feat, featData, model, paramsType,
                                                          out dispDims, out dispDimParams, out editBodies, out state);
                MacroFeatureParametersParser.ReleaseDisplayDimensions(dispDims);
            }

            return(featMgr.ReplaceComFeatureBase <TMacroFeature>(feat, parameters));
        }
Esempio n. 4
0
        protected override bool OnEditDefinition(ISldWorks app, IModelDoc2 model, IFeature feature)
        {
            var featData = feature.GetDefinition() as IMacroFeatureData;

            featData.AccessSelections(model, (feature as IEntity).GetComponent());

            var parameters = GetParameters(feature, featData, model);

            var addHeight = parameters.AddHeight;

            var newAddHeight = app.SendMsgToUser2("Add extra height (Yes) or remove extra height (No)?", (int)swMessageBoxIcon_e.swMbQuestion, (int)swMessageBoxBtn_e.swMbYesNo) == (int)swMessageBoxResult_e.swMbHitYes;

            if (newAddHeight != addHeight)
            {
                parameters.AddHeight = newAddHeight;

                SetParameters(model, feature, featData, parameters);

                feature.ModifyDefinition(featData, model, (feature as IEntity).GetComponent());
            }
            else
            {
                featData.ReleaseSelectionAccess();
            }

            return(true);
        }
Esempio n. 5
0
        protected sealed override MacroFeatureRebuildResult OnRebuild(ISldWorks app, IModelDoc2 model, IFeature feature)
        {
            Logger.Log("Rebuilding. Getting parameters");

            var featDef = feature.GetDefinition() as IMacroFeatureData;

            IDisplayDimension[] dispDims;
            IBody2[]            editBodies;

            MacroFeatureOutdateState_e state;

            string[] dispDimParams;
            var      parameters = m_ParamsParser.GetParameters <TParams>(feature, featDef, model, out dispDims,
                                                                         out dispDimParams, out editBodies, out state);

            Logger.Log("Rebuilding. Generating bodies");

            var rebuildRes = OnRebuild(app, model, feature, parameters);

            Logger.Log("Rebuilding. Updating dimensions");

            UpdateDimensions(app, model, feature, rebuildRes, dispDims, dispDimParams, parameters);

            Logger.Log("Rebuilding. Releasing dimensions");

            if (dispDims != null)
            {
                for (int i = 0; i < dispDims.Length; i++)
                {
                    dispDims[i] = null;
                }
            }

            return(rebuildRes);
        }
Esempio n. 6
0
        protected override MacroFeatureRebuildResult OnRebuild(ISldWorks app, IModelDoc2 model, IFeature feature)
        {
            //use extension methods of IModeler to create a box body
            IBody2 tempBody = app.IGetModeler().CreateBox(new Point(0, 0, 0), new Vector(1, 0, 0), 0.1, 0.1, 0.1);

            return(MacroFeatureRebuildResult.FromBody(tempBody, feature.GetDefinition() as IMacroFeatureData, false));
        }
Esempio n. 7
0
        protected override MacroFeatureRebuildResult OnRebuild(ISldWorks app, IModelDoc2 model,
                                                               IFeature feature)
        {
            var body = app.IGetModeler().CreateBox(new Point(0.1, 0.2, 0.3), new Vector(0, 0, 1), 0.1, 0.2, 0.3);

            return(MacroFeatureRebuildResult.FromBody(body, feature.GetDefinition() as IMacroFeatureData));
        }
Esempio n. 8
0
        protected override bool OnEditDefinition(ISldWorks app, IModelDoc2 model, IFeature feature)
        {
            var featData = feature.GetDefinition() as IMacroFeatureData;

            //rollback feature
            featData.AccessSelections(model, null);

            //read current parameters
            var parameters = GetParameters(feature, featData, model);

            var res = ShowPage(parameters);

            if (res)
            {
                //set parameters and update feature data
                SetParameters(model, feature, featData, parameters);
                feature.ModifyDefinition(featData, model, null);
            }
            else
            {
                //cancel modifications
                featData.ReleaseSelectionAccess();
            }

            return(true);
        }
Esempio n. 9
0
        protected override MacroFeatureRebuildResult OnRebuild(ISldWorks app, IModelDoc2 model, IFeature feature, DimensionMacroFeatureParams parameters)
        {
            var featData = feature.GetDefinition() as IMacroFeatureData;

            var resBodies  = GetBodies();                                     //generating bodies
            var customData = new MyData();                                    //creating custom data and assigning required values

            return(new CustomRebuildResult(featData, resBodies, customData)); //returning custom rebuild result
        }
Esempio n. 10
0
        private void Initialize()
        {
            IFeature swFeature = ((IModelDoc2)swAssembly).FirstFeature();

            while (swFeature != null)
            {
                /*Console.WriteLine("+++++ " + swFeature.Name + " - " + swFeature.GetID() + " - " + swFeature.IsSuppressed2(
                 *  (int)swInConfigurationOpts_e.swThisConfiguration, null)[0]
                 + "\n \t ++ Created: " + swFeature.DateCreated + "\n \t ++ Modified: " + swFeature.DateModified
                 + "\n \t ++ CreatedBy: " + swFeature.CreatedBy);
                 */
                if (!swFeature.IsSuppressed2((int)swInConfigurationOpts_e.swThisConfiguration, null)[0])
                {
                    var swEntity          = (IEntity)swFeature;
                    var swEntityType      = (swSelectType_e)swEntity.GetType();
                    var featureTypeName   = swFeature.GetTypeName2();
                    var featureDefinition = swFeature.GetDefinition();
                    var specificFeature   = swFeature.GetSpecificFeature2();

                    if (swSelectType_e.swSelBODYFEATURES == swEntityType)
                    {
                        bodyFeatures.Add(new BodyFeature(swFeature)); // swFeature.GetDefinition()
                                                                      // Console.WriteLine("++++ " + swFeature.GetTypeName2() + " - " + swFeature.Name + " - " + (swFeature.GetDefinition() is IExtrudeFeatureData2));
                    }

                    if (swSelectType_e.swSelMATEGROUPS == swEntityType)
                    {
                        //Get first mate, which is a subfeature
                        IFeature swMateFeature = (Feature)swFeature.GetFirstSubFeature();
                        while (null != swMateFeature)
                        {
                            // Console.WriteLine(swMateFeature.IsSuppressed2(1, null)[0]);
                            mates.Add(new Mate(swMateFeature));
                            swMateFeature = swMateFeature.GetNextSubFeature();
                        }
                    }

                    if (swSelectType_e.swSelCOMPONENTS == swEntityType)
                    {
                        var swModelDoc = ((IComponent2)swFeature.GetSpecificFeature2()).GetModelDoc2();
                        // Console.WriteLine(((IComponent2)swFeature.GetSpecificFeature2()).IsSuppressed());

                        if (swModelDoc is IAssemblyDoc)
                        {
                            SwApp.ActivateDocument(swModelDoc);
                            subAssemblies.Add(new Assembly((IAssemblyDoc)swModelDoc, swFeature));
                        }

                        if (swModelDoc is IPartDoc)
                        {
                            parts.Add(new Part((IPartDoc)swModelDoc, swFeature));
                        }
                    }
                }
                swFeature = swFeature.GetNextFeature();
            }
        }
Esempio n. 11
0
        protected override bool OnEditDefinition(ISldWorks app, IModelDoc2 model, IFeature feature)
        {
            var featData = feature.GetDefinition() as IMacroFeatureData;

            featData.AccessSelections(model, null);

            m_Controller.ShowPage(GetParameters(feature, featData, model), model as IPartDoc, feature, featData);

            return(true);
        }
        protected override MacroFeatureRebuildResult OnRebuild(ISldWorks app, IModelDoc2 model,
                                                               IFeature feature, DimensionMacroFeatureParams parameters)
        {
            parameters.RefCalcDimension = parameters.RefDimension * 2;
            parameters.DateTimeStamp    = DateTime.Now.Ticks;

            SetParameters(model, feature, feature.GetDefinition() as IMacroFeatureData, parameters);
            feature.Name = parameters.RefDimension.ToString();

            return(MacroFeatureRebuildResult.FromStatus(true));
        }
        protected override bool OnEditDefinition(ISldWorks app, IModelDoc2 model, IFeature feature)
        {
            var featData = feature.GetDefinition() as IMacroFeatureData;

            featData.AccessSelections(model, null);

            var parameters = GetParameters(feature, featData, model);

            ShowPropertyPage(app, model, feature, featData, parameters, OnFeatureEditCompleted);

            return(true);
        }
        /// <summary>
        /// 获取特定的特征数据 (*Feat)Data
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="feature"></param>
        /// <returns></returns>
        public static T GetDefinition <T>(this IFeature feature)
        {
#if DEBUG
            Debug.Print(typeof(T).Name + " => (通过GetDefinition())" + feature.GetTypeName2());
#else
#endif
            if (!typeof(T).Name.Contains("Data"))
            {
                throw new Exception(string.Format("请确认您的类型{0}是否正确,包含Data的接口需要使用GetSpecFeatData<T>方法", typeof(T).Name));
            }

            return((T)feature.GetDefinition());
        }
        private void SetProvider(ISldWorks app, IFeature feature)
        {
            if (!string.IsNullOrEmpty(m_Provider))
            {
                if (app.IsVersionNewerOrEqual(SwVersion_e.Sw2016))
                {
                    var featData = feature.GetDefinition() as IMacroFeatureData;

                    if (featData.Provider != m_Provider)
                    {
                        featData.Provider = m_Provider;
                    }
                }
            }
        }
        protected override bool OnEditDefinition(ISldWorks app, IModelDoc2 model, IFeature feature)
        {
            var featData = feature.GetDefinition() as IMacroFeatureData;

            if (featData.AccessSelections(model, null))
            {
                var data = featData.GetParameters <DimensionMacroFeatureParams>(feature, model);
                data.RefRadDimension = data.RefRadDimension * 2;
                featData.SetParameters <DimensionMacroFeatureParams>(feature, model, data);
                var res = feature.ModifyDefinition(featData, model, null);
                Debug.Assert(res);
            }

            return(true);
        }
Esempio n. 17
0
        protected override MacroFeatureRebuildResult OnRebuild(ISldWorks app, IModelDoc2 model, IFeature feature, JRTrimFeatureData parameters)
        {
            try
            {
                var swMFD = feature.GetDefinition() as IMacroFeatureData;

                var resBodies = parameters.CreateBodies(app, preview: false).ToArray();

                return(MacroFeatureRebuildResult.FromBodies(resBodies, swMFD));
            }
            catch (Exception ex)
            {
                return(MacroFeatureRebuildResult.FromStatus(false, ex.Message));
            }
        }
Esempio n. 18
0
        protected override MacroFeatureRebuildResult OnRebuild(ISldWorks app, IModelDoc2 model,
                                                               IFeature feature, BoundingCylinderMacroFeatureParams parameters)
        {
            var modeler = app.IGetModeler();

            Point  center;
            Vector axis;
            double radius;
            double height;
            double extraHeight;

            GetCylinderParameters(parameters, out center, out axis, out radius, out height, out extraHeight);

            var cyl = modeler.CreateCylinder(center, axis, radius, height + extraHeight);

            return(MacroFeatureRebuildResult.FromBody(cyl, feature.GetDefinition() as IMacroFeatureData));
        }
        protected override bool OnEditDefinition(ISldWorks app, IModelDoc2 model, IFeature feature)
        {
            var featData = feature.GetDefinition() as IMacroFeatureData;

            featData.AccessSelections(model, null);

            var featParams = GetParameters(feature, featData, model);

            featParams.DateTime = DateTime.Now;
            featParams.Decimal  = (featParams.Decimal + 1M) * 1.002M;
            app.SendMsgToUser($"{nameof(featParams.Param2)} = {featParams.Param2}; {nameof(featParams.EditDefinitionsCount)} = {featParams.EditDefinitionsCount}");
            featParams.EditDefinitionsCount = featParams.EditDefinitionsCount + 1;

            SetParameters(model, feature, featData, featParams);

            feature.ModifyDefinition(featData, model, null);

            return(true);
        }
        protected override MacroFeatureRebuildResult OnRebuild(ISldWorks app, IModelDoc2 model, IFeature feature, TParams parameters)
        {
            try
            {
                var featData = feature.GetDefinition() as IMacroFeatureData;

                return(CreateRebuildResult(app, featData, parameters));
            }
            catch (UserErrorException ex)
            {
                Logger.Log(ex);
                return(MacroFeatureRebuildResult.FromStatus(false, ex.Message));
            }
            catch (Exception ex)
            {
                Logger.Log(ex);
                return(MacroFeatureRebuildResult.FromStatus(false, "Rebuild error"));
            }
        }
Esempio n. 21
0
        private void setLoftTerminalTo(string name)
        {
            IFeature         fov             = fieldOfView.FeatureByName("field of view");
            ILoftFeatureData fieldOfViewLoft = (ILoftFeatureData)fov.GetDefinition();

            fieldOfViewLoft.AccessSelections(swDoc, fieldOfView);

            Object[] fovProfiles    = fieldOfViewLoft.Profiles;
            IFeature sizedSketch    = fieldOfView.FeatureByName(name);
            IFeature originalSketch = fovProfiles[0] as IFeature;

            IFeature[] newProfiles = new IFeature[] { fovProfiles[0] as IFeature, sizedSketch };

            fieldOfViewLoft.Profiles = newProfiles;
            fov.ModifyDefinition(fieldOfViewLoft, swDoc, fieldOfView);

            fieldOfViewLoft.ReleaseSelectionAccess();
            swDoc.EditRebuild3();
            swAssembly.EditAssembly();
        }
Esempio n. 22
0
        private static bool TryGetParameterType(IFeature feat, out Type paramType)
        {
            var featData = feat.GetDefinition() as IMacroFeatureData;
            var progId   = featData.GetProgId();

            if (!string.IsNullOrEmpty(progId))
            {
                var type = Type.GetTypeFromProgID(progId);

                if (type != null)
                {
                    if (type.IsAssignableToGenericType(typeof(SwMacroFeatureDefinition <>)))
                    {
                        paramType = type.GetArgumentsOfGenericType(typeof(SwMacroFeatureDefinition <>)).First();
                        return(true);
                    }
                }
            }

            paramType = null;
            return(false);
        }
Esempio n. 23
0
        public void Main()
        {
            IModelDoc2 model = swApp.IActiveDoc2;

            if (model != null)
            {
                IFeature feat = model.ISelectionManager.GetSelectedObject6(1, -1) as IFeature;

                if (feat != null)
                {
                    IExtrudeFeatureData2 featData = feat.GetDefinition() as IExtrudeFeatureData2;

                    if (featData != null)
                    {
                        if (featData.AccessSelections(model, null))
                        {
                            object fromEntity;
                            int    fromEntType;
                            featData.GetFromEntity(out fromEntity, out fromEntType);

                            Debug.Print(string.Format("From Entity: {0}",
                                                      fromEntity != null ? string.Format("Yes [{0}]", (swSelectType_e)fromEntType) : "No"));

                            int    endCondRefType;
                            object endCondRef = featData.GetEndConditionReference(true, out endCondRefType);

                            Debug.Print(string.Format("End Condition (Direction 1): {0}",
                                                      endCondRef != null ? string.Format("Yes [{0}]", (swSelectType_e)endCondRef) : "No"));

                            endCondRef = featData.GetEndConditionReference(false, out endCondRefType);

                            Debug.Print(string.Format("End Condition (Direction 2): {0}",
                                                      endCondRef != null ? string.Format("Yes [{0}]", (swSelectType_e)endCondRef) : "No"));

                            object firstDirDirRef;
                            int    firstDirDirRefType;
                            object secondDirDirRef;
                            int    secondDirDirRefType;

                            featData.GetDirectionReference(out firstDirDirRef, out firstDirDirRefType, out secondDirDirRef, out secondDirDirRefType);

                            Debug.Print(string.Format("Direction (Direction 1): {0}",
                                                      firstDirDirRef != null ? string.Format("Yes [{0}]", (swSelectType_e)firstDirDirRefType) : "No"));

                            Debug.Print(string.Format("Direction (Direction 2): {0}",
                                                      secondDirDirRef != null ? string.Format("Yes [{0}]", (swSelectType_e)secondDirDirRefType) : "No"));

                            featData.ReleaseSelectionAccess();
                        }
                        else
                        {
                            throw new InvalidOperationException("Failed to access feature selection");
                        }
                    }
                    else
                    {
                        throw new InvalidCastException("Selected feature is not Boss-Extrude");
                    }
                }
                else
                {
                    throw new NullReferenceException("Select feature");
                }
            }
            else
            {
                throw new NullReferenceException("Open model");
            }
        }
Esempio n. 24
0
 protected override MacroFeatureRebuildResult OnRebuild(ISldWorks app, IModelDoc2 model, IFeature feature)
 {
     IBody2[] tempBodies = null; //TODO: create temp bodies
     return(MacroFeatureRebuildResult.FromBodies(tempBodies, feature.GetDefinition() as IMacroFeatureData, true));
 }
Esempio n. 25
0
 internal SwCoordinateSystem(IFeature feat, ISwDocument doc, ISwApplication app, bool created) : base(feat, doc, app, created)
 {
     m_CoordSys = feat.GetDefinition() as ICoordinateSystemFeatureData;
 }