Exemple #1
0
        //PRIMA DI USARE QUESTO METODO RICORDARSI DI ELIMINARE LA CURRENTgROUPINGSURFACE DALLA LISTA!!!!

        public static void FindPatternsInGS(MyGroupingSurface currentGroupingSurface, ref StringBuilder fileOutput,
                                            ref List <MyPattern> listOfMyPattern, ref List <MyGroupingSurface> listOfMyGroupingSurface,
                                            ref List <MyPattern> listOfMyPatternTwo, ref bool toleranceOK, List <MyGroupingSurface> listOfInitialGroupingSurface)
        {
            var ListOfREOnThisSurface =
                currentGroupingSurface.listOfREOfGS.Select(myRepeatedEntity => myRepeatedEntity).ToList();
            var listOfCentroidsThisGS =
                currentGroupingSurface.listOfREOfGS.Select(myRepeatedEntity => myRepeatedEntity.centroid).ToList();
            var numOfCentroidsOnThisGS = listOfCentroidsThisGS.Count;
            var maxPath = false; //it is TRUE if the maximum Pattern is found, FALSE otherwise.


            if (numOfCentroidsOnThisGS > 2)
            {
                List <MyMatrAdj> listOfMyMatrAdj = Functions.CreateMatrAdj(listOfCentroidsThisGS, ref fileOutput);


                while (listOfMyMatrAdj.Count > 0 && maxPath == false && toleranceOK == true)
                {
                    bool onlyShortPath;

                    var currentMatrAdj = new MyMatrAdj(listOfMyMatrAdj[0].d, listOfMyMatrAdj[0].matr, listOfMyMatrAdj[0].nOccur);
                    listOfMyMatrAdj.Remove(listOfMyMatrAdj[0]);
                    //NOTA: forse la mia MatrAdj non deve essere rimossa ma conservata,
                    //soprattutto nel caso in cui si presenta onlyShortPath = true
                    //(non avrebbe senso cancellarla, ma conservarla per la ricerca di path
                    //di 2 RE).
                    fileOutput.AppendLine("----> Considero NUOVA MatrAdj. Sono rimaste ancora " + listOfMyMatrAdj.Count +
                                          " MatrAdj da controllare.");
                    fileOutput.AppendLine(" ");

                    List <MyPathOfPoints> listOfPathOfCentroids;
                    maxPath = Functions.FindPaths(currentMatrAdj, ListOfREOnThisSurface, ref fileOutput,
                                                  out listOfPathOfCentroids, out onlyShortPath, ref toleranceOK,
                                                  ref listOfMyMatrAdj, ref listOfMyGroupingSurface,
                                                  listOfInitialGroupingSurface, ref listOfMyPattern, ref listOfMyPatternTwo);
                    fileOutput.AppendLine(" ");
                    fileOutput.AppendLine("PER QUESTA MATRADJ prima della ricerca 'ufficiale' di pattern': ");
                    fileOutput.AppendLine("maxPath = " + maxPath);
                    fileOutput.AppendLine("listOfMyPattern.Count = " + listOfMyPattern.Count);
                    fileOutput.AppendLine("listOfMyPatternTwo.Count = " + listOfMyPatternTwo.Count);
                    fileOutput.AppendLine("onlyShortPath = " + onlyShortPath);
                    fileOutput.AppendLine("toleranceOK = " + toleranceOK);
                    //fileOutput.AppendLine("listOfPathOfCentroids.Count = " + listOfPathOfCentroids.Count);

                    if (toleranceOK == true)
                    {
                        if (listOfPathOfCentroids != null)
                        {
                            if (maxPath == false)
                            {
                                if (onlyShortPath == false)
                                {
                                    GetPatternsFromListOfPaths(listOfPathOfCentroids, ListOfREOnThisSurface,
                                                               ref listOfMyMatrAdj, ref listOfMyGroupingSurface, listOfInitialGroupingSurface,
                                                               ref listOfMyPattern, ref listOfMyPatternTwo);
                                }
                                else
                                {
                                    //non faccio niente e li rimetto in gioco per
                                }
                            }
                        }
                        else
                        {
                            fileOutput.AppendLine(" ---> NO PATH FOUND in this adjacency matrix!");
                        }
                    }
                    else
                    {
                        fileOutput.AppendLine("===>>    TOLLERANZA NON SUFFICIENTEMENTE PICCOLA. TERMINATO.");
                        return;
                    }
                }
            }
            else
            {
                //numOfCentroidsOnThisGS = 2
                if (numOfCentroidsOnThisGS == 2)
                {
                    fileOutput.AppendLine("Su QUESTA GS ci sono solo 2 RE: ");

                    if (IsTranslationTwoRE(ListOfREOnThisSurface[0], ListOfREOnThisSurface[1]))
                    {
                        fileOutput.AppendLine("Le due RE sono legate da TRASLAZIONE!");
                        var listOfPathOfCentroids = new List <MyPathOfPoints>();
                        var listOfMyMatrAdj       = new List <MyMatrAdj>();
                        var newPatternRE          = new List <MyRepeatedEntity>();
                        newPatternRE.Add(ListOfREOnThisSurface[0]);
                        newPatternRE.Add(ListOfREOnThisSurface[1]);
                        var newPatternGeomObject = FunctionsLC.LinePassingThrough(listOfCentroidsThisGS[0], listOfCentroidsThisGS[1]);
                        var newPatternType       = "TRANSLATION of length 2";
                        var listOfGroupingSurfaceForThisPattern = findGroupingSurfacesForThisPattern(listOfInitialGroupingSurface,
                                                                                                     newPatternRE, numOfCentroidsOnThisGS);
                        var newPattern = new MyPattern(newPatternRE, newPatternGeomObject, newPatternType, listOfGroupingSurfaceForThisPattern);
                        CheckAndUpdate(newPattern, ref listOfPathOfCentroids,
                                       ListOfREOnThisSurface, ref listOfMyMatrAdj, ref listOfMyGroupingSurface,
                                       ref listOfMyPattern, ref listOfMyPatternTwo);
                    }
                    else
                    {
                        if (IsReflectionTwoRE(ListOfREOnThisSurface[0], ListOfREOnThisSurface[1], null))
                        {
                            fileOutput.AppendLine("Le due RE sono legate da RIFLESSIONE!");
                            var listOfPathOfCentroids = new List <MyPathOfPoints>();
                            var listOfMyMatrAdj       = new List <MyMatrAdj>();
                            var newPatternRE          = new List <MyRepeatedEntity>();
                            newPatternRE.Add(ListOfREOnThisSurface[0]);
                            newPatternRE.Add(ListOfREOnThisSurface[1]);
                            var newPatternGeomObject = FunctionsLC.LinePassingThrough(listOfCentroidsThisGS[0], listOfCentroidsThisGS[1]);
                            var newPatternType       = "REFLECTION";
                            var listOfGroupingSurfaceForThisPattern = findGroupingSurfacesForThisPattern(listOfInitialGroupingSurface,
                                                                                                         newPatternRE, numOfCentroidsOnThisGS);
                            var newPattern = new MyPattern(newPatternRE, newPatternGeomObject, newPatternType, listOfGroupingSurfaceForThisPattern);
                            CheckAndUpdate(newPattern, ref listOfPathOfCentroids,
                                           ListOfREOnThisSurface, ref listOfMyMatrAdj, ref listOfMyGroupingSurface,
                                           ref listOfMyPattern, ref listOfMyPatternTwo);
                        }
                    }
                }
            }
        }
        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);
        }
Exemple #3
0
        // The function takes as input - a MyRepeatedEntity
        //.                            - the list of MyGroupingSurface to update (ref)
        //It updates the list of MyGroupingSurface, adding the new MyGroupingSurface-s resulting
        //from the current MyRepeatedEntity
        public static void GetSurfacesOfFacesAdjacentToSetOfFaces(MyRepeatedEntity newRepeatedEntity, ref List <MyGroupingSurface> listOfGroupingSurfaces, SldWorks SwApplication)
        {
            const string fileNameBuildRepeatedEntity = "buildRepeatedEntity.txt";
            var          whatToWrite = "";

            var            inputSetOfFaces = newRepeatedEntity.listOfFaces;
            List <Surface> listOfSurfacesAdjacentToAFace = new List <Surface>();
            List <Face2>   listOfOtherFaces = new List <Face2>(inputSetOfFaces);

            foreach (Face2 face in inputSetOfFaces)
            {
                listOfSurfacesAdjacentToAFace.Clear();

                listOfOtherFaces.Remove(face);
                listOfSurfacesAdjacentToAFace = GetSurfacesOfFacesAdjacentToFace(face, listOfOtherFaces,
                                                                                 SwApplication);

                var index    = 0;
                var indexbis = 0;
                foreach (Surface surface in listOfSurfacesAdjacentToAFace)
                {
                    //SwApplication.SendMsgToUser("Ci sono superfici: " + listOfSurfacesAdjacentToAFace.Count);

                    //Find if there already exists this MyGroupingSurface:
                    var indexOfFound =
                        listOfGroupingSurfaces.FindIndex(
                            myGroupingSurface =>
                            MyEqualsSurface(myGroupingSurface.groupingSurface, surface, SwApplication));
                    if (indexOfFound == -1)
                    {
                        //If it does not, create a new MyGroupingSurface:
                        var newListOfRepeatedEntityOfGroupingSurface = new List <MyRepeatedEntity>();
                        newListOfRepeatedEntityOfGroupingSurface.Add(newRepeatedEntity);
                        //var newListOfIdOfRepeatedEntityOfGroupingSurface = new List<int>();
                        //newListOfIdOfRepeatedEntityOfGroupingSurface.Add(idOfNewRepeatedEntity);
                        var newMyGroupingSurface = new MyGroupingSurface(surface,
                                                                         newListOfRepeatedEntityOfGroupingSurface);
                        listOfGroupingSurfaces.Add(newMyGroupingSurface);


                        index++;
                    }
                    else
                    {
                        //If it does, update the corresponding MyGroupingSurface if the current RE is not in the set yet:
                        var myGroupingSurfaceOfFound = listOfGroupingSurfaces[indexOfFound];
                        if (
                            myGroupingSurfaceOfFound.listOfREOfGS.FindIndex(re => re.idRE == newRepeatedEntity.idRE) ==
                            -1)
                        {
                            myGroupingSurfaceOfFound.listOfREOfGS.Add(newRepeatedEntity);
                            //myGroupingSurfaceOfFound.listOfIdOfRE.Add(idOfNewRepeatedEntity);

                            indexbis++;
                        }
                    }
                }

                listOfOtherFaces.Add(face);
            }
        }