//This function prints the detected patterns of components and colors coherently the components in the model. public static void ShowAndPrintResults_Assembly(List <MyPatternOfComponents> listOfOutputPattern, List <MyPatternOfComponents> listOfOutputPatternTwo, ModelDoc2 SwModel, SldWorks swApplication) { if (listOfOutputPattern != null && listOfOutputPatternTwo != null) { if (listOfOutputPattern.Count == 0 && listOfOutputPatternTwo.Count == 0) { //swApplication.SendMsgToUser("NO PATTERN FOUND."); return; } } var listOfOutputPatternLine = new List <MyPatternOfComponents>(); var listOfOutputPatternCircum = new List <MyPatternOfComponents>(); var listOfOutputPatternTwoLine = new List <MyPatternOfComponents>(); var listOfOutputPatternTwoCircum = new List <MyPatternOfComponents>(); foreach (var pattern in listOfOutputPattern) { if (pattern.pathOfMyPattern.GetType() == typeof(MyLine)) { listOfOutputPatternLine.Add(pattern); } else { listOfOutputPatternCircum.Add(pattern); } } if (listOfOutputPatternLine != null) { ColorFace.MyVisualOutput_Assembly(listOfOutputPatternLine, swApplication, SwModel); } if (listOfOutputPatternCircum != null) { ColorFace.MyVisualOutput_Assembly(listOfOutputPatternCircum, swApplication, SwModel); } foreach (var pattern in listOfOutputPatternTwo) { if (pattern.pathOfMyPattern.GetType() == typeof(MyLine)) { listOfOutputPatternTwoLine.Add(pattern); } else { listOfOutputPatternTwoCircum.Add(pattern); } } if (listOfOutputPatternTwoLine != null) { ColorFace.MyVisualOutput_Assembly(listOfOutputPatternTwoLine, swApplication, SwModel); } if (listOfOutputPatternTwoCircum != null) { ColorFace.MyVisualOutput_Assembly(listOfOutputPatternTwoCircum, swApplication, SwModel); } }
public static void MainPatternSearch_Part(bool EntirePart, ref List <MyGroupingSurface> listOfMyGroupingSurface, List <MyGroupingSurface> listOfInitialGroupingSurface, ref StringBuilder fileOutput, SldWorks mySwApplication) { var listOfOutputPattern = new List <MyPattern>(); //list of output patterns found var listOfOutputPatternTwo = new List <MyPattern>(); //list of output patterns of length 2 found var toleranceOK = true; //it is TRUE if the tolerance level is OK during the paths searching, FALSE otherwise while (listOfMyGroupingSurface.Count > 0 && toleranceOK == true) { MyGroupingSurface currentGroupingSurface; if (!EntirePart) { currentGroupingSurface = new MyGroupingSurface(listOfMyGroupingSurface[0].groupingSurface, listOfMyGroupingSurface[0].listOfREOfGS); } else { currentGroupingSurface = new MyGroupingSurface(listOfMyGroupingSurface[0].KLplanareSurface, listOfMyGroupingSurface[0].listOfREOfGS); } listOfMyGroupingSurface.RemoveAt(0); fileOutput.AppendLine(" "); fileOutput.AppendLine("(Al momento sono rimaste " + listOfMyGroupingSurface.Count + " superfici, compresa questa.)"); PartUtilities.GeometryAnalysis.FindPatternsInGS(currentGroupingSurface, ref fileOutput, ref listOfOutputPattern, ref listOfMyGroupingSurface, ref listOfOutputPatternTwo, ref toleranceOK, listOfInitialGroupingSurface); } //Assigning of id numbers to the found MyPattern //(the id will be used in composed pattern search phase) //At the same time, we draw the pattern centroids ModelDoc2 SwModel = mySwApplication.ActiveDoc; SwModel.ClearSelection2(true); SwModel.Insert3DSketch(); var i = 0; foreach (var pattern in listOfOutputPattern) { pattern.idMyPattern = i; i++; var listOfCentroidsOfPattern = pattern.listOfMyREOfMyPattern.Select(re => re.centroid).ToList(); var patternCentroid = ExtractInfoFromBRep.computeCentroidsOfVertices(listOfCentroidsOfPattern); pattern.patternCentroid = patternCentroid; //SwModel.CreatePoint2(pattern.patternCentroid.x, pattern.patternCentroid.y, pattern.patternCentroid.z); } foreach (var pattern in listOfOutputPatternTwo) { pattern.idMyPattern = i; i++; var listOfCentroidsOfPattern = pattern.listOfMyREOfMyPattern.Select(re => re.centroid).ToList(); var patternCentroid = ExtractInfoFromBRep.computeCentroidsOfVertices(listOfCentroidsOfPattern); pattern.patternCentroid = patternCentroid; //SwModel.CreatePoint2(pattern.patternCentroid.x, pattern.patternCentroid.y, pattern.patternCentroid.z); } //SwModel.InsertSketch(); //Patterns are subdivided in Line patterns and in Circle patterns: var listOfOutputPatternLine = new List <MyPattern>(); var listOfOutputPatternCircum = new List <MyPattern>(); foreach (var pattern in listOfOutputPattern) { if (pattern.pathOfMyPattern.GetType() == typeof(MyLine)) { listOfOutputPatternLine.Add(pattern); } else { listOfOutputPatternCircum.Add(pattern); } } //The results are shown giving color to the model: ColorFace.MyVisualOutput(listOfOutputPatternLine, mySwApplication); ColorFace.MyVisualOutput(listOfOutputPatternCircum, mySwApplication); //The same for patterns of length 2: ColorFace.MyVisualOutput(listOfOutputPatternTwo, mySwApplication); //Build the list of MyGroupingSurfaceForPatterns: var listOfGroupingSurfaceForPatterns = new List <MyGroupingSurfaceForPatterns>(); if (!EntirePart) { foreach (var gs in listOfInitialGroupingSurface) { var listOfPatternsLineForThisGS = listOfOutputPatternLine.FindAll( pattern => pattern.listOfGroupingSurfaces.FindIndex( surface => ExtractInfoFromBRep.MyEqualsSurface(surface, gs.groupingSurface, mySwApplication)) != -1); var listOfPatternsTwoForThisGS = listOfOutputPatternTwo.FindAll( pattern => pattern.listOfGroupingSurfaces.FindIndex( surface => ExtractInfoFromBRep.MyEqualsSurface(surface, gs.groupingSurface, mySwApplication)) != -1); listOfPatternsLineForThisGS.AddRange(listOfPatternsTwoForThisGS); var listOfPatternsCircumForThisGS = listOfOutputPatternCircum.FindAll( pattern => pattern.listOfGroupingSurfaces.FindIndex( surface => ExtractInfoFromBRep.MyEqualsSurface(surface, gs.groupingSurface, mySwApplication)) != -1); if (listOfPatternsLineForThisGS.Count > 1 || listOfPatternsCircumForThisGS.Count > 1) { var newGSForPatterns = new MyGroupingSurfaceForPatterns(gs.groupingSurface, listOfPatternsLineForThisGS, listOfPatternsCircumForThisGS); listOfGroupingSurfaceForPatterns.Add(newGSForPatterns); } } } //>>>>>>>COMPOSED PATTERN SEARCH: List <MyComposedPattern> listOfOutputComposedPattern; List <MyComposedPattern> listOfOutputComposedPatternTwo; PartUtilities_ComposedPatterns.GeometryAnalysis.FindComposedPatterns(listOfGroupingSurfaceForPatterns, out listOfOutputComposedPattern, out listOfOutputComposedPatternTwo, SwModel, mySwApplication, ref fileOutput); ColorFace.MyVisualOutput_ComposedPatterns(listOfOutputComposedPattern, listOfOutputComposedPatternTwo, mySwApplication, SwModel); }