Esempio n. 1
0
        //Builds the Assembly, Part and Sheetmetal part objects using recursion
        public void TraverseAssembly(AssemblyDocument currentAsmDocument, int parentID)
        {
            int currentID = GetAssemblyID();

            //to stop instantiating a new instance of Assembly with a null AssemblyDocument - should never happen anyway
            if (currentAsmDocument == null)
            {
                return;
            }

            Assembly assembly = NewAssembly(currentAsmDocument, parentID, currentID);

            EventLogger.CreateLogEntry($"Processing assembly document {assembly.AssemblyDocument.DisplayName}");

            AssemblyList.Add(assembly);

            ComponentOccurrences occurrences = currentAsmDocument.ComponentDefinition.Occurrences;

            noOccurrences += occurrences.Count;
            EventLogger.CreateLogEntry($"Current part count {noOccurrences}");

            foreach (ComponentOccurrence occurrence in occurrences)
            {
                //the UI layer is listening for this Event to increment the progress bar
                IncrementProgressBar();

                if (DocumentInfo.IsPartDocument(occurrence.DefinitionDocumentType))
                {
                    PartDocument partDocument = (PartDocument)occurrence.Definition.Document;
                    EventLogger.CreateLogEntry($"processing part document {partDocument.DisplayName}");

                    if (DocumentInfo.IsSheetMetalPart(partDocument.SubType))
                    {
                        assembly.SheetmetalPartList.Add(NewSheetMetalPart(partDocument));
                    }

                    else
                    {
                        assembly.PartList.Add(NewPart(partDocument));
                    }
                }

                if (DocumentInfo.IsAssemblyDocument(occurrence.DefinitionDocumentType))
                {
                    AssemblyDocument subAssemblyDocument = (AssemblyDocument)occurrence.Definition.Document;

                    TraverseAssembly(subAssemblyDocument, assembly.ID);
                }
            }
        }