Exemple #1
0
        public static void FindComposedPatternsOfComponents(
            List <MyPatternOfComponents> listOfPatternsOfComponentsLine,
            List <MyPatternOfComponents> listOfPatternsOfComponentsCircum,
            out List <MyComposedPatternOfComponents> listOfOutputComposedPattern,
            out List <MyComposedPatternOfComponents> listOfOutputComposedPatternTwo,
            ModelDoc2 SwModel, SldWorks mySwApplication, ref StringBuilder fileOutput)
        {
            var toleranceOk              = true;
            var listOfComposedPattern    = new List <MyComposedPatternOfComponents>();
            var listOfComposedPatternTwo = new List <MyComposedPatternOfComponents>();


            // >>>>>>> LINEAR CASE:
            //first I group patterns by same length and same distance:
            var listOfListsOfCoherentPatternsLine = GroupFoundPatternsOfComponentsOfTypeLine(
                listOfPatternsOfComponentsLine, mySwApplication);


            //Then I group coherent patterns in subgroups of parallel patterns:
            foreach (var list in listOfListsOfCoherentPatternsLine)
            {
                //Grouping in lists of parallel patterns
                var listOfListsOfParallelPatterns = GroupPatternsOfComponentsInParallel(list);
                var numOfListsOfParallelPatterns  = listOfListsOfParallelPatterns.Count;

                if (list.Count == 2)
                {
                    //I verify if a composed pattern with these 2 patterns has already been created
                    //in another GS:
                    if (ComposedPatternOfComponentsOfLength2AlreadyExists(listOfComposedPatternTwo, list) == false)
                    {
                        //if a composed pattern does not exist yet AND
                        //the 2 patterns are not parallel, I verify if it is REFLECTION:
                        if (numOfListsOfParallelPatterns == 0)
                        {
                            //if (IsReflectionTwoPatterns(list[0], list[1]))
                            //{
                            //    KLdebug.Print("I 2 Pattern sono legate da RIFLESSIONE!", nameFile);

                            //    var typeOfNewComposedPattern = "Composed REFLECTION of length 2";
                            //    BuildNewComposedPatternOfLength2(fileOutput, typeOfNewComposedPattern,
                            //        ref listOfComposedPattern, ref listOfComposedPatternTwo,
                            //        ref listOfGroupingSurfaceForPatterns, list);
                            //}
                        }
                        else
                        //if a composed pattern does not exist yet AND
                        //the 2 patterns are parallel, I verify if it is TRANSLATION:
                        {
                            if (IsTranslationTwoPatternsOfComponents(list[0], list[1]))
                            {
                                var typeOfNewComposedPattern = "Composed TRANSLATION of length 2";
                                BuildNewComposedPatternOfComponentsOfLength2(fileOutput, typeOfNewComposedPattern,
                                                                             ref listOfComposedPattern, ref listOfComposedPatternTwo, list);
                            }
                        }
                    }
                }
                else
                {
                    foreach (var listOfParallelPatterns in listOfListsOfParallelPatterns)
                    {
                        if (listOfParallelPatterns.Count == 2)
                        {
                            //I verify if a composed pattern with these 2 patterns has already been created
                            //in another GS:
                            if (ComposedPatternOfComponentsOfLength2AlreadyExists(listOfComposedPatternTwo, list))
                            {
                            }
                            else
                            {
                                if (IsTranslationTwoPatternsOfComponents(listOfParallelPatterns[0], listOfParallelPatterns[1]))
                                {
                                    var typeOfNewComposedPattern = "Composed TRANSLATION of length 2";
                                    BuildNewComposedPatternOfComponentsOfLength2(fileOutput, typeOfNewComposedPattern,
                                                                                 ref listOfComposedPattern, ref listOfComposedPatternTwo,
                                                                                 listOfParallelPatterns);
                                }
                            }
                        }
                        else //(listOfParallelPatterns.Count > 2)
                        {
                            var listOfPatternCentroids = listOfParallelPatterns.Select(pattern => pattern.patternCentroid).ToList();
                            fileOutput.AppendLine("");
                            fileOutput.AppendLine("        >>>> CREATION OF ADJECENCY MATRICES FOR COMPOSED PATTERNS:");
                            var listOfMyMatrAdj = Functions.CreateMatrAdj(listOfPatternCentroids, ref fileOutput);

                            var maxPath = false; //it is TRUE if the maximum Pattern is found, FALSE otherwise.
                            while (listOfMyMatrAdj.Count > 0 && maxPath == false && toleranceOk)
                            {
                                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).

                                List <MyPathOfPoints> listOfPathsOfCentroids;
                                bool onlyShortPaths;
                                maxPath = PathCreation_Assembly_ComposedPatterns.Functions.FindPaths_Assembly_ComposedPatterns(currentMatrAdj,
                                                                                                                               listOfParallelPatterns,
                                                                                                                               ref fileOutput, out listOfPathsOfCentroids, out onlyShortPaths, ref toleranceOk,
                                                                                                                               ref listOfMyMatrAdj, ref listOfComposedPattern,
                                                                                                                               ref listOfComposedPatternTwo, SwModel, mySwApplication);

                                if (toleranceOk)
                                {
                                    if (listOfPathsOfCentroids != null)
                                    {
                                        if (maxPath == false)
                                        {
                                            if (onlyShortPaths == false)
                                            {
                                                GetComposedPatternsFromListOfPathsLine_Assembly(listOfPathsOfCentroids,
                                                                                                listOfParallelPatterns, ref listOfMyMatrAdj,
                                                                                                ref listOfComposedPattern, ref listOfComposedPatternTwo, mySwApplication, ref fileOutput);
                                            }
                                            else
                                            {
                                                //non faccio niente e li rimetto in gioco per
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    listOfOutputComposedPattern    = listOfComposedPattern;
                                    listOfOutputComposedPatternTwo = listOfComposedPatternTwo;
                                    return;
                                }
                            }
                        }
                    }

                    //Now coherent linear patterns that have not been set in a composed pattern yet
                    //are examined to see if they consitute any rotation composed pattern:

                    list.RemoveAll(
                        pattern =>
                        listOfComposedPattern.FindIndex(
                            composedPattern =>
                            composedPattern.ListOfMyPatternOfComponents.FindIndex(
                                patternInComposedPattern =>
                                patternInComposedPattern.idMyPattern == pattern.idMyPattern) != -1) != -1);
                    if (list.Count != 0)
                    {
                        if (list.Count == 2)
                        {
                            //  >>> POSSIBLE REFLECTION CAN EXIST

                            //I verify if a composed pattern with these 2 patterns has already been created
                            //in another GS:
                            if (ComposedPatternOfComponentsOfLength2AlreadyExists(listOfComposedPatternTwo, list))
                            {
                            }
                        }
                        else
                        {
                            var listOfPatternCentroids1 = list.Select(pattern => pattern.patternCentroid).ToList();
                            fileOutput.AppendLine("");
                            fileOutput.AppendLine("        >>>> CREATION OF ADJECENCY MATRICES FOR COMPOSED PATTERNS:");
                            var listOfMyMatrAdj1 = Functions.CreateMatrAdj(listOfPatternCentroids1, ref fileOutput);

                            var maxPath = false; //it is TRUE if the maximum Pattern is found, FALSE otherwise.
                            while (listOfMyMatrAdj1.Count > 0 && maxPath == false && toleranceOk)
                            {
                                var currentMatrAdj = new MyMatrAdj(listOfMyMatrAdj1[0].d, listOfMyMatrAdj1[0].matr,
                                                                   listOfMyMatrAdj1[0].nOccur);
                                listOfMyMatrAdj1.Remove(listOfMyMatrAdj1[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).

                                List <MyPathOfPoints> listOfPathsOfCentroids1;
                                bool onlyShortPaths1;

                                var maxPath1 = PathCreation_Assembly_ComposedPatterns.Functions.FindPaths_Assembly_ComposedPatterns(currentMatrAdj,
                                                                                                                                    list, ref fileOutput, out listOfPathsOfCentroids1, out onlyShortPaths1,
                                                                                                                                    ref toleranceOk, ref listOfMyMatrAdj1,
                                                                                                                                    ref listOfComposedPattern, ref listOfComposedPatternTwo, SwModel, mySwApplication);

                                if (toleranceOk)
                                {
                                    if (listOfPathsOfCentroids1 != null)
                                    {
                                        //I ignore every linear path (I look for composed rotational patterns now):
                                        var listOfCircularPaths =
                                            listOfPathsOfCentroids1.FindAll(
                                                path =>
                                                path.pathGeometricObject.GetType() == typeof(MyCircumForPath))
                                            .ToList();

                                        if (maxPath1 == false)
                                        {
                                            if (onlyShortPaths1 == false)
                                            {
                                                GetComposedPatternsFromListOfPathsLine_Assembly(listOfCircularPaths,
                                                                                                list, ref listOfMyMatrAdj1,
                                                                                                ref listOfComposedPattern, ref listOfComposedPatternTwo, mySwApplication, ref fileOutput);
                                            }
                                            else
                                            {
                                                //non faccio niente e li rimetto in gioco per
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }



            listOfOutputComposedPattern    = listOfComposedPattern;
            listOfOutputComposedPatternTwo = listOfComposedPatternTwo;
        }
        public static void FindComposedPatterns(List <MyGroupingSurfaceForPatterns> listOfGroupingSurfaceForPatterns,
                                                out List <MyComposedPattern> listOfOutputComposedPattern,
                                                out List <MyComposedPattern> listOfOutputComposedPatternTwo, ModelDoc2 SwModel,
                                                SldWorks mySwApplication, ref StringBuilder fileOutput)

        {
            var toleranceOk              = true;
            var listOfComposedPattern    = new List <MyComposedPattern>();
            var listOfComposedPatternTwo = new List <MyComposedPattern>();

            //For each MyGroupingSurfaceForPatterns
            while (listOfGroupingSurfaceForPatterns.Count > 0 && toleranceOk)
            {
                var currentGroupingSurfaceForPatterns = new MyGroupingSurfaceForPatterns(
                    listOfGroupingSurfaceForPatterns[0].groupingSurface,
                    listOfGroupingSurfaceForPatterns[0].listOfPatternsLine,
                    listOfGroupingSurfaceForPatterns[0].listOfPatternsCircum);
                listOfGroupingSurfaceForPatterns.RemoveAt(0);

                fileOutput.AppendLine("");
                fileOutput.AppendLine("NUOVA SURFACE OF TYPE: " + currentGroupingSurfaceForPatterns.groupingSurface.Identity());
                fileOutput.AppendLine("(Al momento sono rimaste ancora " + listOfGroupingSurfaceForPatterns.Count +
                                      " superfici (oltre questa).)");

                // >>>>>>> LINEAR CASE:
                //first I group patterns by same length and same distance:
                var listOfListsOfCoherentPatternsLine = GroupFoundPatternsOfTypeLine(
                    currentGroupingSurfaceForPatterns.listOfPatternsLine, mySwApplication);
                if (listOfListsOfCoherentPatternsLine.Count == 0)
                {
                }

                //Then I group coherent patterns in subgroups of parallel patterns:
                foreach (var list in listOfListsOfCoherentPatternsLine)
                {
                    //Grouping in lists of parallel patterns
                    var listOfListsOfParallelPatterns = GroupPatternsInParallel(list);
                    var numOfListsOfParallelPatterns  = listOfListsOfParallelPatterns.Count;

                    if (list.Count == 2)
                    {
                        //I verify if a composed pattern with these 2 patterns has already been created
                        //in another GS:
                        if (ComposedPatternOfLength2AlreadyExists(listOfComposedPatternTwo, list) == false)
                        {
                            //if a composed pattern does not exist yet AND
                            //the 2 patterns are not parallel, I verify if it is REFLECTION:
                            if (numOfListsOfParallelPatterns == 0)
                            {
                                if (IsReflectionTwoPatterns(list[0], list[1]))
                                {
                                    var typeOfNewComposedPattern = "Composed REFLECTION of length 2";
                                    BuildNewComposedPatternOfLength2(fileOutput, typeOfNewComposedPattern,
                                                                     ref listOfComposedPattern, ref listOfComposedPatternTwo,
                                                                     ref listOfGroupingSurfaceForPatterns, list);
                                }
                            }
                            else
                            //if a composed pattern does not exist yet AND
                            //the 2 patterns are parallel, I verify if it is TRANSLARION:
                            {
                                if (IsTranslationTwoPatterns(list[0], list[1]))
                                {
                                    var typeOfNewComposedPattern = "Composed TRANSLATION of length 2";
                                    BuildNewComposedPatternOfLength2(fileOutput, typeOfNewComposedPattern,
                                                                     ref listOfComposedPattern, ref listOfComposedPatternTwo,
                                                                     ref listOfGroupingSurfaceForPatterns, list);
                                }
                                else
                                {
                                    if (IsReflectionTwoPatterns(list[0], list[1]))
                                    {
                                        var typeOfNewComposedPattern = "Composed REFLECTION of length 2";
                                        BuildNewComposedPatternOfLength2(fileOutput, typeOfNewComposedPattern,
                                                                         ref listOfComposedPattern, ref listOfComposedPatternTwo,
                                                                         ref listOfGroupingSurfaceForPatterns, list);
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        foreach (var listOfParallelPatterns in listOfListsOfParallelPatterns)
                        {
                            if (listOfParallelPatterns.Count == 2)
                            {
                                //I verify if a composed pattern with these 2 patterns has already been created
                                //in another GS:
                                if (ComposedPatternOfLength2AlreadyExists(listOfComposedPatternTwo, list))
                                {
                                }
                                else
                                {
                                    if (IsTranslationTwoPatterns(listOfParallelPatterns[0], listOfParallelPatterns[1]))
                                    {
                                        var typeOfNewComposedPattern = "Composed TRANSLATION of length 2";
                                        BuildNewComposedPatternOfLength2(fileOutput, typeOfNewComposedPattern,
                                                                         ref listOfComposedPattern, ref listOfComposedPatternTwo,
                                                                         ref listOfGroupingSurfaceForPatterns, listOfParallelPatterns);
                                    }
                                    else
                                    {
                                        if (IsReflectionTwoPatterns(list[0], list[1]))
                                        {
                                            var typeOfNewComposedPattern = "Composed REFLECTION of length 2";
                                            BuildNewComposedPatternOfLength2(fileOutput, typeOfNewComposedPattern,
                                                                             ref listOfComposedPattern, ref listOfComposedPatternTwo,
                                                                             ref listOfGroupingSurfaceForPatterns, list);
                                        }
                                    }
                                }
                            }
                            else //(listOfParallelPatterns.Count > 2)
                            {
                                var listOfPatternCentroids = listOfParallelPatterns.Select(pattern => pattern.patternCentroid).ToList();
                                fileOutput.AppendLine("");
                                fileOutput.AppendLine("        >>>> CREATION OF ADJECENCY MATRICES FOR COMPOSED PATTERNS:");
                                var listOfMyMatrAdj = Functions.CreateMatrAdj(listOfPatternCentroids, ref fileOutput);

                                var maxPath = false; //it is TRUE if the maximum Pattern is found, FALSE otherwise.
                                while (listOfMyMatrAdj.Count > 0 && maxPath == false && toleranceOk)
                                {
                                    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).
                                    List <MyPathOfPoints> listOfPathsOfCentroids;
                                    bool onlyShortPaths;
                                    maxPath = PathCreation_Part_ComposedPatterns.Functions.FindPaths_ComposedPatterns(currentMatrAdj,
                                                                                                                      listOfParallelPatterns,
                                                                                                                      ref fileOutput, out listOfPathsOfCentroids, out onlyShortPaths, ref toleranceOk,
                                                                                                                      ref listOfMyMatrAdj,
                                                                                                                      ref listOfGroupingSurfaceForPatterns, ref listOfComposedPattern,
                                                                                                                      ref listOfComposedPatternTwo, mySwApplication);
                                    //fileOutput.AppendLine("listOfPathOfCentroids.Count = " + listOfPathOfCentroids.Count, nameFile);

                                    if (toleranceOk)
                                    {
                                        if (listOfPathsOfCentroids != null)
                                        {
                                            if (maxPath == false)
                                            {
                                                if (onlyShortPaths == false)
                                                {
                                                    GetComposedPatternsFromListOfPathsLine(listOfPathsOfCentroids,
                                                                                           listOfParallelPatterns,
                                                                                           ref listOfMyMatrAdj, ref listOfGroupingSurfaceForPatterns,
                                                                                           ref listOfComposedPattern, ref listOfComposedPatternTwo, mySwApplication, ref fileOutput);
                                                }
                                                else
                                                {
                                                    //non faccio niente e li rimetto in gioco per
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }

                        //Now coherent linear patterns that have not been set in a composed pattern yet
                        //are examined to see if they consitute any rotation composed pattern:

                        list.RemoveAll(
                            pattern =>
                            listOfComposedPattern.FindIndex(
                                composedPattern =>
                                composedPattern.listOfMyPattern.FindIndex(
                                    patternInComposedPattern =>
                                    patternInComposedPattern.idMyPattern == pattern.idMyPattern) != -1) != -1);
                        if (list.Count != 0)
                        {
                            if (list.Count == 2)
                            {
                                //  >>> POSSIBLE REFLECTION CAN EXIST

                                //I verify if a composed pattern with these 2 patterns has already been created
                                //in another GS:
                                if (ComposedPatternOfLength2AlreadyExists(listOfComposedPatternTwo, list))
                                {
                                }
                                else
                                {
                                    if (IsReflectionTwoPatterns(list[0], list[1]))
                                    {
                                        var typeOfNewComposedPattern = "Composed REFLECTION of length 2";
                                        BuildNewComposedPatternOfLength2(fileOutput, typeOfNewComposedPattern,
                                                                         ref listOfComposedPattern, ref listOfComposedPatternTwo,
                                                                         ref listOfGroupingSurfaceForPatterns, list);
                                    }
                                }
                            }
                            else
                            {
                                var listOfPatternCentroids1 = list.Select(pattern => pattern.patternCentroid).ToList();
                                fileOutput.AppendLine("");
                                fileOutput.AppendLine("        >>>> CREATION OF ADJECENCY MATRICES FOR COMPOSED PATTERNS:");
                                var listOfMyMatrAdj1 = Functions.CreateMatrAdj(listOfPatternCentroids1, ref fileOutput);

                                var maxPath = false; //it is TRUE if the maximum Pattern is found, FALSE otherwise.
                                while (listOfMyMatrAdj1.Count > 0 && maxPath == false && toleranceOk)
                                {
                                    var currentMatrAdj = new MyMatrAdj(listOfMyMatrAdj1[0].d, listOfMyMatrAdj1[0].matr,
                                                                       listOfMyMatrAdj1[0].nOccur);
                                    listOfMyMatrAdj1.Remove(listOfMyMatrAdj1[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).
                                    List <MyPathOfPoints> listOfPathsOfCentroids1;
                                    bool onlyShortPaths1;

                                    var maxPath1 = PathCreation_Part_ComposedPatterns.Functions.FindPaths_ComposedPatterns(currentMatrAdj,
                                                                                                                           list, ref fileOutput, out listOfPathsOfCentroids1, out onlyShortPaths1,
                                                                                                                           ref toleranceOk, ref listOfMyMatrAdj1, ref listOfGroupingSurfaceForPatterns,
                                                                                                                           ref listOfComposedPattern, ref listOfComposedPatternTwo, mySwApplication);

                                    if (toleranceOk)
                                    {
                                        if (listOfPathsOfCentroids1 != null)
                                        {
                                            //I ignore every linear path (I look for composed rotational patterns now):
                                            var listOfCircularPaths =
                                                listOfPathsOfCentroids1.FindAll(
                                                    path =>
                                                    path.pathGeometricObject.GetType() == typeof(MyCircumForPath))
                                                .ToList();

                                            if (maxPath1 == false)
                                            {
                                                if (onlyShortPaths1 == false)
                                                {
                                                    GetComposedPatternsFromListOfPathsLine(listOfCircularPaths,
                                                                                           list, ref listOfMyMatrAdj1, ref listOfGroupingSurfaceForPatterns,
                                                                                           ref listOfComposedPattern, ref listOfComposedPatternTwo, mySwApplication, ref fileOutput);
                                                }
                                                else
                                                {
                                                    //non faccio niente e li rimetto in gioco per
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                // >>>>>>> CIRCULAR CASE:
                #region da rivedere
                //first I group patterns by same length and same distance:
                var listOfListsOfCoherentPatternsCircum = GroupFoundPatternsOfTypeCircum(
                    currentGroupingSurfaceForPatterns.listOfPatternsCircum, mySwApplication);

                //Then I group coherent patterns in subgroups of patterns:
                foreach (var list in listOfListsOfCoherentPatternsCircum)
                {
                    var listOfListsOfPatternsWithSameCenterAndPlane = GroupPatternsWithSameCenterPlane(list);
                    var numOfListsOfParallelPatterns = listOfListsOfPatternsWithSameCenterAndPlane.Count;
                    //Grouping in lists of parallel patterns
                    foreach (var listOfPatternsWithSameCenterAndPlane in listOfListsOfPatternsWithSameCenterAndPlane)
                    {
                        if (listOfPatternsWithSameCenterAndPlane.Count == 2)
                        {
                            if (IsTranslationTwoPatterns(listOfPatternsWithSameCenterAndPlane[0], listOfPatternsWithSameCenterAndPlane[1]))
                            {
                                var typeOfNewComposedPattern = "Composed ROTATIONAL (same center) of length 2";
                                BuildNewComposedPatternOfLength2(fileOutput, typeOfNewComposedPattern,
                                                                 ref listOfComposedPattern, ref listOfComposedPatternTwo,
                                                                 ref listOfGroupingSurfaceForPatterns, listOfPatternsWithSameCenterAndPlane);
                            }
                        }
                        else //listOfPatternsWithSameCenterAndPlane.Count > 2
                        {
                            //    var listOfPatternCentroids =
                            //        listOfPatternsWithSameCenterAndPlane.Select(pattern => pattern.patternCentroid).ToList();
                            //    KLdebug.Print("", nameFile);
                            //    KLdebug.Print("        >>>> CREATION OF ADJECENCY MATRICES FOR COMPOSED PATTERNS:", nameFile);
                            //    var listOfMyMatrAdj = Functions.CreateMatrAdj(listOfPatternCentroids, ref fileOutput);

                            //    var indOfMatr = 0;
                            //    List<MyPathOfPoints> listOfPathsOfCentroids;
                            //    bool onlyShortPaths;


                            //    //////////////
                            //    var maxPath = Functions.FindPaths_ComposedPatterns(listOfMyMatrAdj[indOfMatr], listOfPatternsWithSameCenterAndPlane,
                            //            ref fileOutput, out listOfPathsOfCentroids, out onlyShortPaths, ref toleranceOk, ref listOfMyMatrAdj,
                            //            ref listOfGroupingSurfaceForPatterns, ref listOfComposedPattern, ref listOfComposedPatternTwo);

                            //    if (toleranceOk)
                            //    {
                            //        if (maxPath == false)
                            //        {
                            //            if (onlyShortPaths == false)
                            //            {
                            //                GetComposedPatternsFromListOfPathsLine(listOfPathsOfCentroids,
                            //                    listOfPatternsWithSameCenterAndPlane,
                            //                    ref listOfMyMatrAdj, ref listOfGroupingSurfaceForPatterns,
                            //                    ref listOfComposedPattern, ref listOfComposedPatternTwo);
                            //            }
                            //            else
                            //            {
                            //                //non faccio niente e li rimetto in gioco per
                            //            }
                            //        }
                            //    }
                            //    else
                            //    {
                            //        KLdebug.Print("===>>    TOLLERANZA NON SUFFICIENTEMENTE PICCOLA. TERMINATO.", nameFile);
                            //    }
                        }
                    }
                }
            }
            #endregion
            listOfOutputComposedPattern    = listOfComposedPattern;
            listOfOutputComposedPatternTwo = listOfComposedPatternTwo;
        }
Exemple #3
0
        public static void KLFindPatternsOfComponents(List <MyRepeatedComponent> listOfComponents,
                                                      List <MyVertex> listOfVertexOrigins,
                                                      ref List <MyPatternOfComponents> listOfMyPattern, ref List <MyPatternOfComponents> listOfMyPatternTwo,
                                                      ModelDoc2 SwModel, SldWorks swApplication, ref StringBuilder fileOutput)
        {
            //per PROVA: parto dal livello delle foglie...

            //I create a list of adjacency matrices at constant distance.
            //The constant distance is the distance between the origin of the coordinate systems
            //(it is computed by computing the Euclidean norm of the difference vector between
            // two origins).
            var numOfComponents = listOfComponents.Count;

            //var listOfVertexOrigins = listOfComponents.Select(component2 => component2.Origin).ToList();

            //foreach (MyVertex origin in listOfVertexOrigins)
            //{
            //    var centroidToPrint = string.Format("{0}, {1}, {2}", origin.x, origin.y, origin.z);
            //    //KLdebug.Print(centroidToPrint, "Centroidi.txt");
            //}

            if (numOfComponents > 2)
            {
                //fileOutput.AppendLine("CREAZIONE MATRICI DI ADIACENZA:");
                var maxPath         = false; //it is TRUE if the maximum Pattern is found, FALSE otherwise.
                var toleranceOk     = true;
                var listOfMyMatrAdj = Functions.CreateMatrAdj(listOfVertexOrigins, 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);
                    //fileOutput.AppendLine("Esamino NUOVA MatrAdj. Al momento sono rimaste " + listOfMyMatrAdj.Count +
                    // " MatrAdj.");
                    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("----> Eliminata NUOVA MatrAdj. Ora sono rimaste " + listOfMyMatrAdj.Count +
                    //                      " MatrAdj.");
                    //fileOutput.AppendLine(" ");

                    List <MyPathOfPoints> listOfPathOfPoints;
                    maxPath = PathCreation_Assembly.Functions.KLFindPaths_Assembly(currentMatrAdj, listOfComponents, listOfVertexOrigins, ref fileOutput,
                                                                                   out listOfPathOfPoints, out onlyShortPath, ref toleranceOk,
                                                                                   ref listOfMyMatrAdj, ref listOfMyPattern, ref listOfMyPatternTwo, SwModel, swApplication);

                    //fileOutput.AppendLine(" ");
                    //fileOutput.AppendLine("PER QUESTA MATRADJ: ");
                    //fileOutput.AppendLine("maxPath = " + maxPath);
                    //fileOutput.AppendLine("listOfMyPattern.Count = " + listOfMyPattern.Count);
                    //fileOutput.AppendLine("listOfMyPatternTwo.Count = " + listOfMyPatternTwo.Count);
                    //fileOutput.AppendLine("onlyShortPath = " + onlyShortPath);
                    //fileOutput.AppendLine("toleranceOK = " + toleranceOk);

                    if (toleranceOk == true)
                    {
                        if (listOfPathOfPoints != null)
                        {
                            if (maxPath == false)
                            {
                                if (onlyShortPath == false)
                                {
                                    GeometryAnalysis.KLGetPatternsFromListOfPaths_Assembly(listOfPathOfPoints,
                                                                                           listOfComponents, listOfVertexOrigins,
                                                                                           ref listOfMyMatrAdj, ref listOfMyPattern, ref listOfMyPatternTwo, SwModel,
                                                                                           swApplication);
                                }
                                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.");
                    }
                }
            }
            else
            {
                if (numOfComponents == 2)
                {
                    //fileOutput.AppendLine("LE COMPONENTI DI QUESTO TIPO SONO 2: ");

                    if (Part.PartUtilities.GeometryAnalysis.IsTranslationTwoRE(listOfComponents[0].RepeatedEntity, listOfComponents[1].RepeatedEntity))
                    {
                        //  fileOutput.AppendLine("Le due COMPONENTI sono legate da TRASLAZIONE!");
                        var listOfPathOfCentroids = new List <MyPathOfPoints>();
                        var listOfMyMatrAdj       = new List <MyMatrAdj>();
                        var newPatternRC          = new List <MyRepeatedComponent> {
                            listOfComponents[0], listOfComponents[1]
                        };
                        if (listOfVertexOrigins.Count < 2)
                        {
                            swApplication.SendMsgToUser("Non ho due origini");
                        }
                        var newPatternGeomObject = FunctionsLC.LinePassingThrough(listOfVertexOrigins[0], listOfVertexOrigins[1]);
                        var newPatternType       = "TRANSLATION of length 2";
                        var newPattern           = new MyPatternOfComponents(newPatternRC, newPatternGeomObject, newPatternType);
                        GeometryAnalysis.KLCheckAndUpdate_Assembly(newPattern, ref listOfPathOfCentroids,
                                                                   listOfVertexOrigins, ref listOfMyMatrAdj,
                                                                   ref listOfMyPattern, ref listOfMyPatternTwo);
                        //swApplication.SendMsgToUser("Pattern da due " + listOfMyPatternTwo.Count);
                    }
                    else
                    {
                        if (Part.PartUtilities.GeometryAnalysis.IsReflectionTwoRE(listOfComponents[0].RepeatedEntity, listOfComponents[1].RepeatedEntity, swApplication))
                        {
                            //fileOutput.AppendLine("Le due COMPONENTI sono legate da RIFLESSIONE!");
                            var listOfPathOfCentroids = new List <MyPathOfPoints>();
                            var listOfMyMatrAdj       = new List <MyMatrAdj>();
                            var newPatternRC          = new List <MyRepeatedComponent>
                            {
                                listOfComponents[0],
                                listOfComponents[1]
                            };
                            var newPatternGeomObject = FunctionsLC.LinePassingThrough(listOfVertexOrigins[0], listOfVertexOrigins[1]);
                            var newPatternType       = "REFLECTION";
                            var newPattern           = new MyPatternOfComponents(newPatternRC, newPatternGeomObject, newPatternType);
                            GeometryAnalysis.KLCheckAndUpdate_Assembly(newPattern, ref listOfPathOfCentroids,
                                                                       listOfVertexOrigins, ref listOfMyMatrAdj,
                                                                       ref listOfMyPattern, ref listOfMyPatternTwo);
                        }
                        //else
                        //{
                        //    fileOutput.AppendLine("PROVO CON LA ROTAZIONE:");
                        //    double[] axisDirection;
                        //    if (GeometryAnalysis.IsRotationTwoComp180degrees_Assembly(listOfComponents[0], listOfComponents[1],
                        //        out axisDirection, SwModel, swApplication))
                        //    {
                        //        fileOutput.AppendLine("Le due COMPONENTI sono legate da ROTAZIONE!");
                        //        var listOfPathOfCentroids = new List<MyPathOfPoints>();
                        //        var listOfMyMatrAdj = new List<MyMatrAdj>();
                        //        var newPatternRC = new List<MyRepeatedComponent>
                        //        {
                        //            listOfComponents[0],
                        //            listOfComponents[1]
                        //        };
                        //        var angle90degrees = Math.PI / 2;
                        //        var thirdVertexOnCircum = listOfVertexOrigins[0].Rotate(angle90degrees, axisDirection);
                        //        var newPatternGeomObject = FunctionsLC.CircumPassingThrough(listOfVertexOrigins[0], listOfVertexOrigins[1], thirdVertexOnCircum, ref fileOutput);
                        //        var newPatternType = "ROTATION";
                        //        var newPattern = new MyPatternOfComponents(newPatternRC, newPatternGeomObject, newPatternType);
                        //        GeometryAnalysis.KLCheckAndUpdate_Assembly(newPattern, ref listOfPathOfCentroids,
                        //            listOfVertexOrigins, ref listOfMyMatrAdj,
                        //            ref listOfMyPattern, ref listOfMyPatternTwo);
                        //    }
                        //}
                    }
                }
            }
        }
Exemple #4
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);
                        }
                    }
                }
            }
        }