Example #1
0
        public void selEdge(string promt, SelectionFilterEnum filter)
        {
            PartFeature pf = CmdMgr.Pick(filter, promt) as PartFeature;
            HoleFeature hf = pf as HoleFeature;

            if (hf == null)
            {
                return;
            }
            //ICollection<Edge> col = null;
            foreach (Face item in hf.SideFaces)
            {
                Edge ed = checkBox1.Checked ? item.Edges[2] : item.Edges[1];
                edges.Add(ed);
            }
//             System.Collections.IEnumerator en = PartCompDef.Features.GetEnumerator();
//             en.Reset();
//             while(en.Current != null)
//             {
//                en.
//             }
            PartCompDef = hf.Parent as PartComponentDefinition;
//             for (int i = 1; i < PartCompDef.Features.Count; i++)
//          {
//                 MirrorFeature mf = PartCompDef.Features[i] as MirrorFeature;
//                 if (mf == null) continue;
//                 HoleFeature holeF = PartCompDef.Features[i - 1] as HoleFeature;
//                 if (hf == null)
//                     holeF = PartCompDef.Features[i - 2] as HoleFeature;
//                 else
//                     continue;
//                 foreach (PartFeature item in mf.ParentFeatures)
//                 {
//                     if (item is HoleFeature && holeF.Equals(item))
//                     {
//                         if (mf.Faces[1].SurfaceType == SurfaceTypeEnum.kCylinderSurface)
//                             edges.Add(mf.Faces[1].Edges[1]);
//                     }
//                 }
//          }
            foreach (MirrorFeature item in PartCompDef.Features.MirrorFeatures)
            {
                foreach (PartFeature m in item.ParentFeatures)
                {
                    if (m.Equals(hf))
                    {
                        if (item.Faces[1].SurfaceType != SurfaceTypeEnum.kCylinderSurface)
                        {
                            continue;
                        }
                        Edge ed = checkBox1.Checked ? item.Faces[1].Edges[2] : item.Faces[1].Edges[1];
                        edges.Add(ed);
                    }
                }
            }
        }
Example #2
0
        /// <summary>
        /// Remove fields with given values
        /// </summary>
        /// <param name="partFeature">PartFeature to remove fields from</param>
        private void RemoveFields(PartFeature partFeature)
        {
            if (DatItemFields.Contains(DatItemField.Part_Feature_Name))
            {
                partFeature.Name = null;
            }

            if (DatItemFields.Contains(DatItemField.Part_Feature_Value))
            {
                partFeature.Value = null;
            }
        }
Example #3
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        //
        //
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        public ReportData(PartDocument document, PartFeature newFeature)
        {
            _Document = document;

            _PartFeature = newFeature;

            _FullFileName = _Document.FullFileName;

            _FeatureName = (_PartFeature != null ? _PartFeature.Name : "");

            _FinalizeAction = FinalizeActionEnum.kNone;
        }
Example #4
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        //
        //
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        public void Load()
        {
            _Document = FeatureUtilities.Application.Documents.Open(_FullFileName, false)
                        as PartDocument;

            if (_FeatureName != "")
            {
                _PartFeature = _Document.ComponentDefinition.Features[_FeatureName];
            }
            else
            {
                _PartFeature = null;
            }
        }
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        //
        //
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        public static void CreateOccurrenceTag(AssemblyDocument AsmDocument, PartFeature PartFeature, ComponentOccurrence occurrence)
        {
            AttributeSet set = PartFeature.AttributeSets[_AttributeSet];

            Byte[] contextData = set["ContextData"].Value as Byte[];

            int keyContext = AsmDocument.ReferenceKeyManager.LoadContextFromArray(ref contextData);

            Byte[] refKey = new byte[] { };

            occurrence.GetReferenceKey(ref refKey, keyContext);

            set.Add("OccurrenceRefKey", ValueTypeEnum.kByteArrayType, refKey);


            PartDocument doc = PartFeature.Parent.Document as PartDocument;

            set = doc.ComponentDefinition.AttributeSets[_AttributeSet];

            string srcDocPath = set["SourcePartDoc"].Value as string;

            PartDocument srcDoc = FeatureUtilities.Application.Documents.Open(srcDocPath, false) as PartDocument;


            foreach (PartFeature feature in doc.ComponentDefinition.Features)
            {
                if (feature.AttributeSets.get_NameIsUsed(_AttributeSet))
                {
                    AttributeSet setFeature = feature.AttributeSets[_AttributeSet];

                    string AsmFeature = setFeature["AsmFeature"].Value as string;

                    if (!setFeature.get_NameIsUsed("OccurrenceRefKey"))
                    {
                        ObjectCollection collec = srcDoc.AttributeManager.FindObjects(_AttributeSet, "AsmFeature", AsmFeature);

                        if (collec.Count > 0)
                        {
                            PartFeature srcFeature = collec[1] as PartFeature;

                            object val = srcFeature.AttributeSets[_AttributeSet]["OccurrenceRefKey"].Value;

                            setFeature.Add("OccurrenceRefKey", ValueTypeEnum.kByteArrayType, val);
                        }
                    }
                }
            }

            srcDoc.Close(true);
        }
Example #6
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        //
        //
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        public FeatureReport(PartFeature assemblyFeature)
        {
            _nbUpToDateHealth = 0;

            _AssemblyFeature = assemblyFeature;

            _assemblyFeatureName = _AssemblyFeature.Name;

            _ReportDataList = new List <ReportData>();

            _UnrefDocuments = new Dictionary <string, bool>();

            _FinalizeAction = FinalizeActionEnum.kNone;
        }
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        //
        //
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        public static bool IsParentAssemblyResolved(PartFeature PartFeature)
        {
            try
            {
                AttributeSet set = PartFeature.AttributeSets[_AttributeSet];

                string FullFileName = set["AsmFile"].Value as string;

                return(System.IO.File.Exists(FullFileName));
            }
            catch
            {
                return(false);
            }
        }
Example #8
0
        public void SetSuppressedState(TreeNode node, bool Suppressed)
        {
            PartFeature Feature = node.Tag as PartFeature;

            if (Suppressed)
            {
                node.ForeColor          = SystemColors.GrayText;
                node.ImageIndex         = FeatureUtilities.GetFeatureImageIndex(Feature) + 1;
                node.SelectedImageIndex = node.ImageIndex;
                return;
            }

            node.ForeColor          = this.ForeColor;
            node.ImageIndex         = FeatureUtilities.GetFeatureImageIndex(Feature);
            node.SelectedImageIndex = node.ImageIndex;
        }
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        //
        //
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        public static bool FindParentFeature(AssemblyDocument ParentDocument,
                                             PartFeature partFeature,
                                             out PartFeature asmFeature,
                                             out ComponentOccurrence occurrence)
        {
            asmFeature = null;
            occurrence = null;

            try
            {
                AttributeSet set = partFeature.AttributeSets[_AttributeSet];

                Byte[] contextData = set["ContextData"].Value as Byte[];

                int keyContext = ParentDocument.ReferenceKeyManager.LoadContextFromArray(ref contextData);


                Byte[] refKey1 = set["AsmFeatureRefKey"].Value as Byte[];

                object MatchType1;

                asmFeature = ParentDocument.ReferenceKeyManager.BindKeyToObject(ref refKey1,
                                                                                keyContext,
                                                                                out MatchType1) as PartFeature;


                Byte[] refKey2 = set["OccurrenceRefKey"].Value as Byte[];

                object MatchType2;

                occurrence = ParentDocument.ReferenceKeyManager.BindKeyToObject(ref refKey2,
                                                                                keyContext,
                                                                                out MatchType2) as ComponentOccurrence;

                if (asmFeature != null && occurrence != null)
                {
                    return(true);
                }

                return(false);
            }
            catch
            {
                return(false);
            }
        }
Example #10
0
        private static void SuppressOff()
        {
            Inventor.Application application = Marshal.GetActiveObject("Inventor.Application") as Inventor.Application;
            PartDocument         partDoc     = application.Documents.Add(DocumentTypeEnum.kPartDocumentObject,
                                                                         application.FileManager.GetTemplateFile(DocumentTypeEnum.kPartDocumentObject,
                                                                                                                 SystemOfMeasureEnum.kDefaultSystemOfMeasure,
                                                                                                                 DraftingStandardEnum.kDefault_DraftingStandard, null),
                                                                         true) as PartDocument;
            PartFeature partFeature = null;

            for (int i = 0; i < partDoc.ComponentDefinition.Features.Count; i++)
            {
                if (partFeature.Suppressed)
                {
                    partFeature.Suppressed = false;
                }
            }
        }
Example #11
0
        /////////////////////////////////////////////////////////////
        // Use: Returns thread type as string.
        //
        /////////////////////////////////////////////////////////////
        public static string GetThreadTypeStr(PartFeature feature)
        {
            if (feature.Type == ObjectTypeEnum.kHoleFeatureObject)
            {
                return("Standard");
            }

            if (feature.Type == ObjectTypeEnum.kThreadFeatureObject || feature.Type == ObjectTypeEnum.kThreadFeatureProxyObject)
            {
                ThreadFeature thread = feature as ThreadFeature;

                return(thread.ThreadInfoType ==
                       ThreadTypeEnum.kStandardThread ?
                       "Standard" : "Tapered");
            }

            return("Invalid Feature");
        }
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        //
        //
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        public FeatureReport SendToParts(AssemblyDocument ParentDocument,
                                         List <ComponentOccurrence> Participants,
                                         PartFeature AsmFeature)
        {
            RectangularPatternFeature patternFeature = AsmFeature as RectangularPatternFeature;

            switch (_PatternMigrationMode)
            {
            case PatternMigrationModeEnum.kSendToPartsAsCollectionMode:
                return(SendToPartsAsCollection(ParentDocument, Participants, patternFeature));

            case PatternMigrationModeEnum.kSendToPartsAsPatternMode:
                return(SendToPartsAsPattern(ParentDocument, Participants, patternFeature));

            default:
                return(null);
            }
        }
Example #13
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        //
        //
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        public FeatureReport SendToParts(AssemblyDocument ParentDocument,
                                         List <ComponentOccurrence> Participants,
                                         PartFeature AsmFeature)
        {
            ExtrudeFeature extrudeFeature = AsmFeature as ExtrudeFeature;

            FeatureReport result = new FeatureReport(AsmFeature);

            if (FeatureUtilities.CreateBackupFile)
            {
                FeatureUtilities.BackupFile(Participants);
            }

            PlanarSketch asmSketch = extrudeFeature.Profile.Parent as PlanarSketch;

            foreach (ComponentOccurrence occurrence in Participants)
            {
                if (!FeatureUtilities.IsValidOccurrence(occurrence))
                {
                    continue;
                }

                Matrix invTransfo = occurrence.Transformation;
                invTransfo.Invert();

                PartComponentDefinition partCompDef = occurrence.Definition as PartComponentDefinition;

                PartFeature newFeature = CopyFeature(partCompDef, AsmFeature, invTransfo);

                //Place Feature Tag: associativity handling
                FeatureAttributeManager.CreatePartFeatureTag(ParentDocument,
                                                             AsmFeature,
                                                             newFeature,
                                                             occurrence);

                ReportData reportData = new ReportData(partCompDef.Document as PartDocument,
                                                       newFeature);

                result.addReportData(reportData);
            }

            return(result);
        }
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        //
        //
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        public static void CreatePartFeatureTag(AssemblyDocument AsmDocument,
                                                PartFeature AsmFeature,
                                                PartFeature PartFeature,
                                                ComponentOccurrence Occurrence)
        {
            if (PartFeature == null)
            {
                return;
            }

            AttributeSet set = PartFeature.AttributeSets.Add(_AttributeSet, true);

            set.Add("AsmFile", ValueTypeEnum.kStringType, AsmDocument.FullFileName);
            set.Add("AsmDoc", ValueTypeEnum.kStringType, AsmDocument.FullDocumentName);
            set.Add("AsmIntName", ValueTypeEnum.kStringType, AsmDocument.InternalName);
            set.Add("AsmFeature", ValueTypeEnum.kStringType, AsmFeature.Name);


            Byte[] contextData = new byte[] { };

            int keyContext = AsmDocument.ReferenceKeyManager.CreateKeyContext();

            AsmDocument.ReferenceKeyManager.SaveContextToArray(keyContext, ref contextData);

            set.Add("ContextData", ValueTypeEnum.kByteArrayType, contextData);


            Byte[] featureRefKey = new byte[] { };

            AsmFeature.GetReferenceKey(ref featureRefKey, keyContext);

            set.Add("AsmFeatureRefKey", ValueTypeEnum.kByteArrayType, featureRefKey);


            Byte[] occRefKey = new byte[] { };

            Occurrence.GetReferenceKey(ref occRefKey, keyContext);

            set.Add("OccurrenceRefKey", ValueTypeEnum.kByteArrayType, occRefKey);
        }
Example #15
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        //
        //
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        public bool IsPartFeatureUpToDate(PartFeature AsmFeature,
                                          PartFeature PartFeature,
                                          Matrix invTransfo)
        {
            ExtrudeFeature asmFeature  = AsmFeature as ExtrudeFeature;
            ExtrudeFeature partFeature = PartFeature as ExtrudeFeature;

            try
            {
                PlanarSketch asmSketch  = asmFeature.Profile.Parent as PlanarSketch;
                PlanarSketch partSketch = partFeature.Profile.Parent as PlanarSketch;

                if (!FeatureUtilities.CompareSketches(asmSketch, partSketch, invTransfo))
                {
                    return(false);
                }

                if (!FeatureUtilities.CompareProfiles(asmFeature.Profile, partFeature.Profile))
                {
                    return(false);
                }

                if (!FeatureUtilities.IsEqual(asmFeature.TaperAngle.Value, partFeature.TaperAngle.Value))
                {
                    return(false);
                }

                if (!FeatureUtilities.CompareFeatureExtents(asmFeature.Extent, partFeature.Extent, invTransfo))
                {
                    return(false);
                }

                return(true);
            }
            catch
            {
                //Something went wrong
                return(false);
            }
        }
Example #16
0
        public Part(IDictionary <string, object> jsonDict, Dictionary <string, RotationSet> rotationSets, Dictionary <string, Material> physicsMaterials)
        {
            if (jsonDict.ContainsKey("uuid"))
            {
                this.ItemUuid = Guid.Parse(jsonDict["uuid"].ToString());

                if (jsonDict.ContainsKey("legacy_id"))
                {
                    if (!int.TryParse(jsonDict["legacy_id"].ToString(), out this.LegacyId))
                    {
                        this.LegacyId = -1;
                    }
                }

                if (jsonDict.ContainsKey("mat"))
                {
                    if (jsonDict["mat"] is string)
                    {
                        this.RenderMaterial.Add(jsonDict["mat"].ToString());
                    }
                    else
                    {
                        foreach (object q in (List <object>)jsonDict["mat"])
                        {
                            this.RenderMaterial.Add(q.ToString());
                        }
                    }
                }
                if (jsonDict.ContainsKey("mesh"))
                {
                    this.MeshFileName = jsonDict["mesh"].ToString();
                }

                // Texture
                if (jsonDict.ContainsKey("asg"))
                {
                    this.TextureAsg = jsonDict["asg"].ToString();
                }
                if (jsonDict.ContainsKey("dif"))
                {
                    this.TextureDif = jsonDict["dif"].ToString();
                }
                if (jsonDict.ContainsKey("nor"))
                {
                    this.TextureNor = jsonDict["nor"].ToString();
                }

                if (jsonDict.ContainsKey("color"))
                {
                    this.Color = RgbColor.FromHtmlNotation(jsonDict["color"].ToString());
                }

                // Collision
                if (jsonDict.ContainsKey("cylinder"))
                {
                    this.Colision = new CylinderCollision(
                        (IDictionary <string, object>)jsonDict["cylinder"]);
                }
                if (jsonDict.ContainsKey("box"))
                {
                    this.Colision = new BoxCollision(
                        (IDictionary <string, object>)jsonDict["box"]);
                }
                if (jsonDict.ContainsKey("hull"))
                {
                    this.Colision = new HullCollision(
                        (IDictionary <string, object>)jsonDict["hull"]);
                }

                // Rotationset
                if (jsonDict.ContainsKey("rotationSet"))
                {
                    string rotSetName = jsonDict["rotationSet"].ToString();
                    if (rotationSets.ContainsKey(rotSetName))
                    {
                        this.RotationSet = rotationSets[rotSetName];
                    }
                    else
                    {
                        throw new Exception("Part has invalid rotation set: " + rotSetName);
                    }
                }

                if (jsonDict.ContainsKey("density"))
                {
                    if (!float.TryParse(jsonDict["density"].ToString(), out this.Density))
                    {
                        this.Density = -1;
                    }
                }

                if (jsonDict.ContainsKey("type"))
                {
                    this.CustomType = jsonDict["type"].ToString();
                }

                // Feature
                if (jsonDict.ContainsKey("bearing"))
                {
                    this.Feature = new Features.Bearing();
                }
                if (jsonDict.ContainsKey("sensor"))
                {
                    this.Feature = new Features.Sensor();
                }
                if (jsonDict.ContainsKey("radio"))
                {
                    this.Feature = new Features.Radio();
                }
                if (jsonDict.ContainsKey("horn"))
                {
                    this.Feature = new Features.Horn();
                }
                if (jsonDict.ContainsKey("timedjoint"))
                {
                    this.Feature = new Features.Controller();
                }
                if (jsonDict.ContainsKey("logic"))
                {
                    this.Feature = new Features.LogicGate();
                }
                if (jsonDict.ContainsKey("timer"))
                {
                    this.Feature = new Features.Timer();
                }
                if (jsonDict.ContainsKey("tone"))
                {
                    this.Feature = new Features.Tone((IDictionary <string, object>)jsonDict["tone"]);
                }
                if (jsonDict.ContainsKey("lever"))
                {
                    this.Feature = new Features.Lever();
                }
                if (jsonDict.ContainsKey("button"))
                {
                    this.Feature = new Features.Button();
                }
                if (jsonDict.ContainsKey("spring"))
                {
                    this.Feature = new Features.Spring((IDictionary <string, object>)jsonDict["spring"]);
                }
                if (jsonDict.ContainsKey("steering"))
                {
                    this.Feature = new Features.Steering((IDictionary <string, object>)jsonDict["steering"]);
                }
                if (jsonDict.ContainsKey("seat"))
                {
                    this.Feature = new Features.Seat((IDictionary <string, object>)jsonDict["seat"]);
                }
                if (jsonDict.ContainsKey("engine"))
                {
                    this.Feature = new Features.Engine((IDictionary <string, object>)jsonDict["engine"]);
                }
                if (jsonDict.ContainsKey("thruster"))
                {
                    this.Feature = new Features.Thruster((IDictionary <string, object>)jsonDict["thruster"]);
                }

                if (jsonDict.ContainsKey("script"))
                {
                    foreach (object q in (List <object>)jsonDict["script"])
                    {
                        this.Script.Add(q.ToString());
                    }
                }

                if (jsonDict.ContainsKey("sticky"))
                {
                    string sticky = jsonDict["sticky"].ToString();
                    for (int i = 0; i < sticky.Length; i += 2)
                    {
                        // -
                        if (sticky[i] == '-')
                        {
                            if (sticky[i + 1] == 'X')
                            {
                                this.NegativeStickyAxes.Add(Axis.X);
                            }
                            else if (sticky[i + 1] == 'Y')
                            {
                                this.NegativeStickyAxes.Add(Axis.Y);
                            }
                            else
                            {
                                this.NegativeStickyAxes.Add(Axis.Z);
                            }
                        }
                        // +
                        else
                        {
                            if (sticky[i + 1] == 'X')
                            {
                                this.PositiveStickyAxes.Add(Axis.X);
                            }
                            else if (sticky[i + 1] == 'Y')
                            {
                                this.PositiveStickyAxes.Add(Axis.Y);
                            }
                            else
                            {
                                this.PositiveStickyAxes.Add(Axis.Z);
                            }
                        }
                    }
                }

                if (jsonDict.ContainsKey("physicsMaterial"))
                {
                    string phyMat = jsonDict["physicsMaterial"].ToString();
                    if (physicsMaterials.ContainsKey(phyMat))
                    {
                        this.PhysicsMaterial = physicsMaterials[phyMat];
                    }
                }
            }
            else
            {
                throw new Exception("Part doesn't have UUID");
            }
        }
 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 //
 //
 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 public bool IsPartFeatureUpToDate(PartFeature AsmFeature,
                                   PartFeature PartFeature,
                                   Matrix invTransfo)
 {
     return(false);
 }
 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 //
 //
 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 public PartFeature CopyFeature(PartComponentDefinition partCompDef,
                                PartFeature AsmFeature,
                                Matrix invTransfo)
 {
     return(null);
 }
Example #19
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        //
        //
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        public PartFeature CopyFeature(PartComponentDefinition partCompDef,
                                       PartFeature AsmFeature,
                                       Matrix invTransfo)
        {
            try
            {
                ExtrudeFeature extrudeFeature = AsmFeature as ExtrudeFeature;

                ExtrudeFeature newFeature = null;

                UnitVector xAxis = null;
                UnitVector yAxis = null;

                PlanarSketch asmSketch = extrudeFeature.Profile.Parent as PlanarSketch;

                PlanarSketch partSketch = FeatureUtilities.CopySketch(partCompDef,
                                                                      asmSketch,
                                                                      invTransfo,
                                                                      out xAxis,
                                                                      out yAxis);

                ObjectCollection pathSegments = FeatureUtilities.GetPathSegments(extrudeFeature.Profile,
                                                                                 partSketch);

                Profile partProfile = partSketch.Profiles.AddForSolid(true, pathSegments, null);

                FeatureUtilities.CopyProfile(extrudeFeature.Profile, partProfile);

                switch (extrudeFeature.ExtentType)
                {
                case PartFeatureExtentEnum.kThroughAllExtent:
                {
                    ThroughAllExtent ThroughAllExtent = extrudeFeature.Extent as ThroughAllExtent;

                    newFeature = partCompDef.Features.ExtrudeFeatures.AddByThroughAllExtent(partProfile,
                                                                                            ThroughAllExtent.Direction,
                                                                                            extrudeFeature.Operation,
                                                                                            extrudeFeature.TaperAngle.Value);

                    break;
                }

                case PartFeatureExtentEnum.kDistanceExtent:
                {
                    DistanceExtent DistanceExtent = extrudeFeature.Extent as DistanceExtent;

                    newFeature = partCompDef.Features.ExtrudeFeatures.AddByDistanceExtent(partProfile,
                                                                                          DistanceExtent.Distance.Value,
                                                                                          DistanceExtent.Direction,
                                                                                          extrudeFeature.Operation,
                                                                                          extrudeFeature.TaperAngle.Value);

                    break;
                }

                case PartFeatureExtentEnum.kToExtent:
                {
                    ToExtent ToExtent = extrudeFeature.Extent as ToExtent;

                    object ToEntity = FeatureUtilities.CopyFromToEntity(ToExtent.ToEntity,
                                                                        partCompDef,
                                                                        invTransfo);

                    newFeature = partCompDef.Features.ExtrudeFeatures.AddByToExtent(partProfile,
                                                                                    ToEntity,
                                                                                    extrudeFeature.Operation,
                                                                                    false,
                                                                                    extrudeFeature.TaperAngle.Value);

                    break;
                }

                case PartFeatureExtentEnum.kFromToExtent:
                {
                    FromToExtent FromToExtent = extrudeFeature.Extent as FromToExtent;

                    object FromEntity = FeatureUtilities.CopyFromToEntity(FromToExtent.FromFace,
                                                                          partCompDef,
                                                                          invTransfo);

                    object ToEntity = FeatureUtilities.CopyFromToEntity(FromToExtent.ToFace,
                                                                        partCompDef,
                                                                        invTransfo);

                    newFeature = partCompDef.Features.ExtrudeFeatures.AddByFromToExtent(partProfile,
                                                                                        FromEntity,
                                                                                        false,
                                                                                        ToEntity,
                                                                                        false,
                                                                                        extrudeFeature.Operation,
                                                                                        extrudeFeature.TaperAngle.Value);

                    break;
                }

                default:
                    break;
                }

                return(newFeature as PartFeature);
            }
            catch
            {
                return(null);
            }
        }
 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 //
 //
 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 public bool UpdateFeatureFromAsm(PartFeature AsmFeature,
                                  PartFeature PartFeature,
                                  Matrix invTransfo)
 {
     return(false);
 }
Example #21
0
        /////////////////////////////////////////////////////////////
        // Use: Modelizes a Standard ThreadFeature.
        //
        /////////////////////////////////////////////////////////////
        public static bool ModelizeThreadStandard(PartDocument doc,
                                                  PartFeature feature,
                                                  PlanarSketch templateSketch,
                                                  ThreadInfo threadInfo,
                                                  Face threadedFace,
                                                  double extraPitch)
        {
            Transaction Tx =
                _Application.TransactionManager.StartTransaction(
                    doc as _Document,
                    "Modelizing Thread " + feature.Name);

            try
            {
                double pitch =
                    ThreadWorker.GetThreadPitch(threadInfo);

                Vector threadDirection =
                    threadInfo.ThreadDirection;

                bool isInteriorFace =
                    Toolkit.IsInteriorFace(threadedFace);

                Point basePoint =
                    threadInfo.ThreadBasePoints[1] as Point;

                if (isInteriorFace)
                {
                    Vector normal =
                        Toolkit.GetOrthoVector(
                            threadDirection.AsUnitVector()).AsVector();

                    normal.ScaleBy(
                        ThreadWorker.GetThreadMajorRadiusStandard(
                            threadedFace));

                    basePoint.TranslateBy(normal);
                }

                PlanarSketch newSketch = Toolkit.InsertSketch(doc,
                                                              templateSketch,
                                                              threadDirection.AsUnitVector(),
                                                              Toolkit.GetOrthoVector(
                                                                  threadDirection.AsUnitVector()),
                                                              basePoint);

                Point coilBase =
                    threadInfo.ThreadBasePoints[1] as Point;

                bool rightHanded = threadInfo.RightHanded;

                double taper = 0;

                if (!ThreadWorker.InitializeForCoilStandard(doc,
                                                            threadInfo,
                                                            threadedFace,
                                                            newSketch.Name,
                                                            isInteriorFace, pitch))
                {
                    Tx.Abort();
                    return(false);
                }

                Profile profile =
                    newSketch.Profiles.AddForSolid(true, null, null);

                if (!ThreadWorker.CreateCoilFeature(doc,
                                                    profile,
                                                    threadDirection,
                                                    coilBase,
                                                    rightHanded,
                                                    taper,
                                                    pitch,
                                                    extraPitch))
                {
                    Tx.Abort();
                    return(false);
                }

                newSketch.Shared = false;

                feature.Suppressed = true;

                Tx.End();

                return(true);
            }
            catch
            {
                Tx.Abort();
                return(false);
            }
        }
Example #22
0
        /// <summary>
        /// Read part information
        /// </summary>
        /// <param name="reader">XmlReader representing a part block</param>
        /// <param name="machine">Machine information to pass to contained items</param>
        /// <param name="part">Part information to pass to contained items</param>
        /// <param name="filename">Name of the file to be parsed</param>
        /// <param name="indexId">Index ID for the DAT</param>
        private bool ReadPart(XmlReader reader, Machine machine, Part part, string filename, int indexId)
        {
            // If we have an empty port, skip it
            if (reader == null)
            {
                return(false);
            }

            // Get lists ready
            part.Features = new List <PartFeature>();
            List <DatItem> items = new List <DatItem>();

            while (!reader.EOF)
            {
                // We only want elements
                if (reader.NodeType != XmlNodeType.Element)
                {
                    reader.Read();
                    continue;
                }

                // Get the elements from the software
                switch (reader.Name)
                {
                case "feature":
                    var feature = new PartFeature()
                    {
                        Name  = reader.GetAttribute("name"),
                        Value = reader.GetAttribute("value"),
                    };

                    part.Features.Add(feature);

                    reader.Read();
                    break;

                case "dataarea":
                    var dataArea = new DataArea
                    {
                        Name       = reader.GetAttribute("name"),
                        Size       = Sanitizer.CleanLong(reader.GetAttribute("size")),
                        Width      = Sanitizer.CleanLong(reader.GetAttribute("width")),
                        Endianness = reader.GetAttribute("endianness").AsEndianness(),
                    };

                    List <DatItem> roms = ReadDataArea(reader.ReadSubtree(), dataArea);

                    // If we got valid roms, add them to the list
                    if (roms != null)
                    {
                        items.AddRange(roms);
                    }

                    // Skip the dataarea now that we've processed it
                    reader.Skip();
                    break;

                case "diskarea":
                    var diskArea = new DiskArea
                    {
                        Name = reader.GetAttribute("name"),
                    };

                    List <DatItem> disks = ReadDiskArea(reader.ReadSubtree(), diskArea);

                    // If we got valid disks, add them to the list
                    if (disks != null)
                    {
                        items.AddRange(disks);
                    }

                    // Skip the diskarea now that we've processed it
                    reader.Skip();
                    break;

                case "dipswitch":
                    var dipSwitch = new DipSwitch
                    {
                        Name = reader.GetAttribute("name"),
                        Tag  = reader.GetAttribute("tag"),
                        Mask = reader.GetAttribute("mask"),
                    };

                    // Now read the internal tags
                    ReadDipSwitch(reader.ReadSubtree(), dipSwitch);

                    items.Add(dipSwitch);

                    // Skip the dipswitch now that we've processed it
                    reader.Skip();
                    break;

                default:
                    reader.Read();
                    break;
                }
            }

            // Loop over all of the items, if they exist
            string key = string.Empty;

            foreach (DatItem item in items)
            {
                // Add all missing information
                switch (item.ItemType)
                {
                case ItemType.DipSwitch:
                    (item as DipSwitch).Part = part;
                    break;

                case ItemType.Disk:
                    (item as Disk).Part = part;
                    break;

                case ItemType.Rom:
                    (item as Rom).Part = part;

                    // If the rom is continue or ignore, add the size to the previous rom
                    // TODO: Can this be done on write? We technically lose information this way.
                    // Order is not guaranteed, and since these don't tend to have any way
                    // of determining what the "previous" item was after this, that info would
                    // have to be stored *with* the item somehow
                    if ((item as Rom).LoadFlag == LoadFlag.Continue || (item as Rom).LoadFlag == LoadFlag.Ignore)
                    {
                        int     index   = Items[key].Count - 1;
                        DatItem lastrom = Items[key][index];
                        if (lastrom.ItemType == ItemType.Rom)
                        {
                            (lastrom as Rom).Size += (item as Rom).Size;
                            Items[key].RemoveAt(index);
                            Items[key].Add(lastrom);
                        }

                        continue;
                    }

                    break;
                }

                item.Source = new Source(indexId, filename);
                item.CopyMachineInformation(machine);

                // Finally add each item
                key = ParseAddHelper(item);
            }

            return(items.Any());
        }
Example #23
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        //
        //
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        public bool UpdateFeatureFromAsm(PartFeature AsmFeature,
                                         PartFeature PartFeature,
                                         Matrix invTransfo)
        {
            ExtrudeFeature asmFeature  = AsmFeature as ExtrudeFeature;
            ExtrudeFeature partFeature = PartFeature as ExtrudeFeature;

            try
            {
                PartComponentDefinition partCompDef = partFeature.Parent as PartComponentDefinition;

                PlanarSketch partSketch = partFeature.Profile.Parent as PlanarSketch;

                UnitVector xAxis = null;
                UnitVector yAxis = null;

                FeatureUtilities.UpdateSketch(asmFeature.Profile.Parent as PlanarSketch,
                                              partSketch,
                                              invTransfo,
                                              out xAxis,
                                              out yAxis);

                Document asmDocument = asmFeature.Parent.Document as Document;

                bool suppressed = partFeature.Suppressed;

                //Feature needs to be suppressed if we change the Profile
                partFeature.Suppressed = true;

                Profile newPartProfile = FeatureUtilities.UpdateProfile(asmDocument,
                                                                        partCompDef.Document as Document,
                                                                        asmFeature.Profile,
                                                                        partFeature.Profile,
                                                                        true);

                if (newPartProfile != null)
                {
                    partFeature.Profile = newPartProfile;
                }

                partFeature.Suppressed = suppressed;

                partFeature.TaperAngle.Value = asmFeature.TaperAngle.Value;

                if (FeatureUtilities.UpdateFeatureExtent(asmFeature.Extent, partFeature.Extent, invTransfo))
                {
                    return(true);
                }

                switch (asmFeature.ExtentType)
                {
                case PartFeatureExtentEnum.kThroughAllExtent:
                {
                    ThroughAllExtent asmThroughAllExtent = asmFeature.Extent as ThroughAllExtent;

                    partFeature.SetThroughAllExtent(asmThroughAllExtent.Direction);

                    break;
                }

                case PartFeatureExtentEnum.kDistanceExtent:
                {
                    DistanceExtent asmDistanceExtent = asmFeature.Extent as DistanceExtent;

                    partFeature.SetDistanceExtent(asmDistanceExtent.Distance.Value, asmDistanceExtent.Direction);

                    break;
                }

                case PartFeatureExtentEnum.kToExtent:
                {
                    ToExtent asmToExtent = asmFeature.Extent as ToExtent;

                    object ToEntity = FeatureUtilities.CopyFromToEntity(asmToExtent.ToEntity,
                                                                        partCompDef,
                                                                        invTransfo);

                    partFeature.SetToExtent(ToEntity, false);

                    break;
                }

                case PartFeatureExtentEnum.kFromToExtent:
                {
                    FromToExtent asmFromToExtent = asmFeature.Extent as FromToExtent;

                    object FromEntity = FeatureUtilities.CopyFromToEntity(asmFromToExtent.FromFace,
                                                                          partCompDef,
                                                                          invTransfo);

                    object ToEntity = FeatureUtilities.CopyFromToEntity(asmFromToExtent.ToFace,
                                                                        partCompDef,
                                                                        invTransfo);

                    partFeature.SetFromToExtent(FromEntity, false, ToEntity, false);

                    break;
                }

                default:
                    return(false);
                }

                return(true);
            }
            catch
            {
                //Something went wrong
                return(false);
            }
        }
Example #24
0
 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 //
 //
 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 public bool IsAssociativitySupported(PartFeature PartFeature)
 {
     return(PartFeature is ExtrudeFeature);
 }
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        //
        //
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        public void SendToParts(object sender, EventArgs e)
        {
            //Check assembly state before the features migration
            switch (FeatureUtilities.CheckAssemblyState(_AssemblyDocument))
            {
            case FeatureUtilities.AssemblyStateEnum.kAssemblyNotSaved:
            {
                string msg = "Assembly and its sub-components need to be saved on the disk" + System.Environment.NewLine +
                             "for the features migration."
                             + System.Environment.NewLine +
                             "Please save each file first and run the command again...";

                System.Windows.Forms.MessageBox.Show(msg,
                                                     "Feature Migrator",
                                                     MessageBoxButtons.OK,
                                                     MessageBoxIcon.Error);

                return;
            }

            case FeatureUtilities.AssemblyStateEnum.kException:
                return;

            default:
                break;
            }

            Transaction Tx = null;

            try
            {
                Tx = FeatureUtilities.Application.TransactionManager.StartTransaction(
                    _AssemblyDocument as _Document,
                    "Send Features");

                List <FeatureReport> results = new List <FeatureReport>();

                foreach (TreeNode node in TreeView.SelectedNodesBottomUp)
                {
                    if (!(node.Tag is PartFeature))
                    {
                        continue;
                    }

                    PartFeature Feature = node.Tag as PartFeature;

                    if (Feature.Suppressed)
                    {
                        //Do not migrate a suppressed feature
                        continue;
                    }

                    List <ComponentOccurrence> Participants = new List <ComponentOccurrence>();

                    foreach (TreeNode occNode in node.Nodes)
                    {
                        //Check if node is enabled
                        if (occNode.Tag != null && occNode.Tag is ComponentOccurrence)
                        {
                            Participants.Add(occNode.Tag as ComponentOccurrence);
                        }
                    }

                    if (Participants.Count != 0)
                    {
                        FeatureReport result = FeatureUtilities.SendToParts(_AssemblyDocument, Feature, Participants);

                        if (result != null)
                        {
                            results.Add(result);
                        }
                    }
                }

                if (results.Count != 0)
                {
                    if (FeatureUtilities.SingleFeatureOptions)
                    {
                        ActionPreFinalize(results);

                        DetailReportControl detailReportControl = new DetailReportControl(_AssemblyDocument, results);

                        detailReportControl.ShowAsChildModal();
                    }
                    else
                    {
                        ActionPreFinalize(results);
                        ActionFinalize(results);
                    }
                    System.IO.FileInfo fi = new System.IO.FileInfo(_AssemblyDocument.FullFileName);

                    string logfile = fi.DirectoryName + "\\" + fi.Name.Substring(0, fi.Name.Length - 4) + ".log";
                    FeatureReport.LogReport(results, logfile);
                }

                Tx.End();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "\n\n" + ex.StackTrace,
                                "Exception occurred!",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Exclamation);

                Tx.Abort();
            }
            finally
            {
                RefreshControl(_AssemblyDocument as Document);
                _AssemblyDocument.Update2(true);
                this.Parent.Refresh();
            }
        }
Example #26
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        //
        //
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        public void SetRenderStyle(AssemblyDocument asmDoc,
                                   PartFeature AssemblyFeature,
                                   string styleName)
        {
            string stylename = "";

            try
            {
                if (styleName == "As Assembly Feature")
                {
                    StyleSourceTypeEnum srcType;
                    RenderStyle         asmStyle = AssemblyFeature.GetRenderStyle(out srcType);

                    RenderStyle style = null;

                    if (asmStyle != null)
                    {
                        stylename = asmStyle.Name;
                        style     = _Document.RenderStyles[stylename];
                    }

                    _PartFeature.SetRenderStyle(srcType, style);
                }
                else if (styleName == "As Part")
                {
                    _PartFeature.SetRenderStyle(StyleSourceTypeEnum.kPartRenderStyle, null);
                }
                else
                {
                    stylename = styleName;

                    RenderStyle style = _Document.RenderStyles[stylename];

                    _PartFeature.SetRenderStyle(StyleSourceTypeEnum.kOverrideRenderStyle, style);
                }
            }
            catch
            {
                try
                {
                    //copy render style from assembly
                    RenderStyle asmStyle = asmDoc.RenderStyles[stylename];

                    RenderStyle newStyle = _Document.RenderStyles.Add(stylename);

                    byte red, green, blue;

                    asmStyle.GetAmbientColor(out red, out green, out blue);
                    newStyle.SetAmbientColor(red, green, blue);

                    asmStyle.GetDiffuseColor(out red, out green, out blue);
                    newStyle.SetDiffuseColor(red, green, blue);

                    asmStyle.GetEmissiveColor(out red, out green, out blue);
                    newStyle.SetEmissiveColor(red, green, blue);

                    asmStyle.GetSpecularColor(out red, out green, out blue);
                    newStyle.SetSpecularColor(red, green, blue);

                    newStyle.DisplayInteriorFaces = asmStyle.DisplayInteriorFaces;
                    newStyle.Opacity = asmStyle.Opacity;

                    newStyle.TextureFilename = asmStyle.TextureFilename;
                    newStyle.TextureRotation = asmStyle.TextureRotation;
                    newStyle.TextureScale    = asmStyle.TextureScale;

                    newStyle.Reflectivity            = asmStyle.Reflectivity;
                    newStyle.ReflectionImageFilename = asmStyle.ReflectionImageFilename;
                    newStyle.Refraction = asmStyle.Refraction;

                    if (styleName == "As Assembly Feature")
                    {
                        StyleSourceTypeEnum srcType;
                        AssemblyFeature.GetRenderStyle(out srcType);

                        _PartFeature.SetRenderStyle(srcType, newStyle);
                    }
                    else
                    {
                        _PartFeature.SetRenderStyle(StyleSourceTypeEnum.kOverrideRenderStyle, newStyle);
                    }
                }
                catch
                {
                    //giving up
                }
            }
        }
Example #27
0
 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 //
 //
 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 public bool IsMigrationSupported(PartFeature AsmFeature)
 {
     return(AsmFeature is ExtrudeFeature);
 }
 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 //
 //
 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 public bool IsMigrationSupported(PartFeature AsmFeature)
 {
     return(AsmFeature is RectangularPatternFeature);
 }
Example #29
0
        /////////////////////////////////////////////////////////////
        // Use: OnSelect ThreadFeature Handler.
        //
        /////////////////////////////////////////////////////////////
        void SelectEvents_OnSelect(
            ObjectsEnumerator JustSelectedEntities,
            SelectionDeviceEnum SelectionDevice,
            Point ModelPosition,
            Point2d ViewPosition,
            Inventor.View View)
        {
            foreach (System.Object obj in JustSelectedEntities)
            {
                PartFeature feature = obj as PartFeature;

                ThreadFeature thread = obj as ThreadFeature;

                ThreadInfo threadInfo = thread.ThreadInfo;

                Face threadedFace = thread.ThreadedFace[1];


                if (feature.Suppressed)
                {
                    continue;
                }

                if (thread.ThreadInfoType == ThreadTypeEnum.kTaperedThread &&
                    threadedFace.SurfaceType != SurfaceTypeEnum.kConeSurface)
                {
                    DialogResult res = MessageBox.Show(
                        "Threaded face surface type is not cone surface but it is applied" +
                        System.Environment.NewLine +
                        "with tapered thread. ThreadModeler cannot modelize this thread.",
                        "Invalid Surface Type",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error);
                    continue;
                }

                string iMateName = string.Empty;

                if (Toolkit.HasiMate(threadedFace,
                                     out iMateName))
                {
                    DialogResult res = MessageBox.Show(
                        "Threaded face or one of its edge has" +
                        " iMate associated to it." +
                        System.Environment.NewLine +
                        "Please delete iMate " + iMateName +
                        " before modelizing this thread.",
                        "Invalid iMate",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error);

                    continue;
                }

                double pitch = ThreadWorker.GetThreadPitch(threadInfo);

                string pitchStr =
                    ThreadWorker.GetThreadPitchStr(threadInfo,
                                                   (Document)_Document);

                string minStr =
                    _Document.UnitsOfMeasure.GetStringFromValue(
                        ThreadWorker.ThresholdPitchCm,
                        UnitsTypeEnum.kDefaultDisplayLengthUnits);

                if (pitch < ThreadWorker.ThresholdPitchCm)
                {
                    DialogResult res = MessageBox.Show(
                        "Selected thread pitch " +
                        "is too small (" + pitchStr + ")." +
                        System.Environment.NewLine +
                        "The minimum thread pitch that can " +
                        "be modelized is " + minStr + " .",
                        "Invalid Thread Pitch",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error);

                    continue;
                }

                ListViewItem item =
                    lvFeatures.Items.Add(feature.Name);

                item.Tag = feature;

                item.SubItems.Add(pitchStr);

                item.SubItems.Add(ThreadWorker.GetThreadTypeStr(
                                      feature));

                item.SubItems.Add(
                    ThreadWorker.GetThreadedFaceTypeStr(
                        threadedFace));
            }

            _selecSetPopulated = (lvFeatures.Items.Count != 0);

            bOk.Enabled = ValidateOkButton();
        }
 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 //
 //
 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 public bool IsAssociativitySupported(PartFeature partFeature)
 {
     return(false);
 }