public static bool KLGetPatternsFromLinearPath_Assembly(List <MyRepeatedComponent> listOfComponentsOnThePath,
                                                                MyPathGeometricObject pathObject, ref List <MyPathOfPoints> listOfPathOfPoints,
                                                                List <MyVertex> listOfOrigins, ref List <MyMatrAdj> listOfMatrAdj,
                                                                ref List <MyPatternOfComponents> listOfOutputPattern, ref List <MyPatternOfComponents> listOfOutputPatternTwo)
        {
            // Se non uso listOfComponentsOnThePath probabilmente dovrò aggiornare listOfOrigins con il numero effettivo di elementi che appartengono al pattern selezionato.
            var numOfCompOnThisPath = listOfComponentsOnThePath.Count;
            //var numOfCompOnThisPath = listOfOrigins.Count;

            var noStop = true;

            //const string nameFile = "GetTranslationalPatterns.txt";
            //KLdebug.Print(" ", nameFile);
            //KLdebug.Print("VERIFICA DELLE POSSIBILI TRASLAZIONI TRA " + numOfCompOnThisPath + " COMPONENTS:", nameFile);
            //KLdebug.Print(" ", nameFile);

            var i = 0;

            while (i < (numOfCompOnThisPath - 1))
            {
                var newPattern      = new MyPatternOfComponents();
                var foundNewPattern = KLGetMaximumTranslation_Assembly(listOfComponentsOnThePath, pathObject, ref i, ref numOfCompOnThisPath,
                                                                       ref noStop, ref newPattern);

                if (foundNewPattern)
                {
                    if (newPattern.listOfMyRCOfMyPattern.Count == numOfCompOnThisPath ||
                        newPattern.listOfMyRCOfMyPattern.Count == numOfCompOnThisPath - 1)
                    {
                        noStop = true;
                    }

                    var listREofRcomponents = new List <MyRepeatedEntity>(listOfComponentsOnThePath.Select(comp => comp.RepeatedEntity).ToList());
                    //var listGS = new List<Surface>();
                    var newPatternPoint = new MyPattern(listREofRcomponents, newPattern.pathOfMyPattern,
                                                        newPattern.typeOfMyPattern);

                    KLCheckAndUpdate_Assembly(newPattern, ref listOfPathOfPoints,
                                              listOfOrigins, ref listOfMatrAdj,
                                              ref listOfOutputPattern, ref listOfOutputPatternTwo);
                }
            }
            //KLdebug.Print(" ", nameFile);
            //KLdebug.Print("FINE LISTA :) ", nameFile);

            if (noStop)
            {
                //KLdebug.Print("NESSUNA INTERRUZIONE: PATTERN DI LUNGHEZZA MASSIMA SU QUESTO PATH!", nameFile);
                return(true);
            }
            return(false);
        }
        public static bool  GetPatternsFromCircularPath_Assembly(List <MyRepeatedComponent> listOfComponentsOnThePath,
                                                                 MyPathGeometricObject pathObject, ref List <MyPathOfPoints> listOfPathOfPoints,
                                                                 List <MyVertex> listOfOrigins, ref List <MyMatrAdj> listOfMatrAdj,
                                                                 ref List <MyPatternOfComponents> listOfOutputPattern, ref List <MyPatternOfComponents> listOfOutputPatternTwo)
        {
            var numOfCompOnThisPath = listOfComponentsOnThePath.Count;
            var noStop = true;

            const string nameFile = "GetCircularPatterns.txt";

            var i = 0;

            while (i < (numOfCompOnThisPath - 1))
            {
                var newPattern      = new MyPatternOfComponents();
                var j               = i;
                var foundNewPattern = GetMaximumTranslation_Assembly(listOfComponentsOnThePath, pathObject, ref j, ref numOfCompOnThisPath,
                                                                     ref noStop, ref newPattern);

                if (foundNewPattern == false)
                {
                    var pathCircumference = (MyCircumForPath)pathObject;
                    foundNewPattern = GetMaximumRotation_Assembly(listOfComponentsOnThePath, pathCircumference, ref i, ref numOfCompOnThisPath,
                                                                  ref noStop, ref newPattern);
                }
                else
                {
                    i = j;
                }

                if (foundNewPattern)
                {
                    if (newPattern.listOfMyRCOfMyPattern.Count == numOfCompOnThisPath ||
                        newPattern.listOfMyRCOfMyPattern.Count == numOfCompOnThisPath - 1)
                    {
                        noStop = true;
                    }

                    CheckAndUpdate_Assembly(newPattern, ref listOfPathOfPoints,
                                            listOfOrigins, ref listOfMatrAdj,
                                            ref listOfOutputPattern, ref listOfOutputPatternTwo);
                }
            }

            if (noStop)
            {
                return(true);
            }
            return(false);
        }
        public static void CheckAndUpdate_Assembly(MyPatternOfComponents newPattern,
                                                   ref List <MyPathOfPoints> listOfPathOfPoints,
                                                   List <MyVertex> listOfOrigins, ref List <MyMatrAdj> listOfMatrAdj,
                                                   ref List <MyPatternOfComponents> listOfOutputPattern, ref List <MyPatternOfComponents> listOfOutputPatternTwo)
        {
            var lengthOfPattern = newPattern.listOfMyRCOfMyPattern.Count;

            // if lengthOfPattern = 2, I add the newPattern only if there is not another pattern in listOfOutputPatternTwo
            // containing one of the two RE in the newPattern.
            if (lengthOfPattern == 2)
            {
                int i        = 0;
                var addOrNot = true;
                while (addOrNot == true && i < 2)
                {
                    var currentRC  = newPattern.listOfMyRCOfMyPattern[i];
                    var indOfFound =
                        listOfOutputPatternTwo.FindIndex(
                            pattern =>
                            pattern.listOfMyRCOfMyPattern.FindIndex(
                                comp => Equals(comp.Transform, currentRC.Transform)) != -1);
                    if (indOfFound != -1)
                    {
                        addOrNot = false;
                    }
                    i++;
                }

                if (addOrNot == true)
                {
                    listOfOutputPatternTwo.Add(newPattern);
                }
            }
            // if lengthOfPattern > 2, I add the newPattern and I update the other data
            // (aiming not to find pattern containing RE already set in this newPattern)
            else
            {
                listOfOutputPattern.Add(newPattern);

                UpdateOtherData_Assembly(newPattern, ref listOfPathOfPoints, listOfOrigins, ref listOfMatrAdj,
                                         ref listOfOutputPatternTwo);
            }
        }
Esempio n. 4
0
        public static bool IsRotationTwoPatterns_Assembly(MyPatternOfComponents firstMyPattern,
                                                          MyPatternOfComponents secondMyPattern, double teta,
                                                          double[] axisDirection,
                                                          SldWorks SwApplication, ref StringBuilder fileOutput)
        {
            //check of the length correspondence:
            var firstPatternLength  = firstMyPattern.listOfMyRCOfMyPattern.Count;
            var secondPatternLength = secondMyPattern.listOfMyRCOfMyPattern.Count;

            if (firstPatternLength != secondPatternLength)
            {
                return(false);
            }

            if (AssemblyUtilities.GeometryAnalysis.IsRotationTwoComp_Assembly(firstMyPattern.listOfMyRCOfMyPattern[0],
                                                                              secondMyPattern.listOfMyRCOfMyPattern[0], teta, axisDirection) ||
                AssemblyUtilities.GeometryAnalysis.IsRotationTwoComp_Assembly(firstMyPattern.listOfMyRCOfMyPattern[0],
                                                                              secondMyPattern.listOfMyRCOfMyPattern[secondPatternLength - 1], teta, axisDirection))
            {
                return(true);
            }
            return(false);
        }
        //Update data in case on newPattern of length > 2
        public static void UpdateOtherData_Assembly(MyPatternOfComponents newPattern,
                                                    ref List <MyPathOfPoints> listOfPathOfPoints, List <MyVertex> listOfOrigins,
                                                    ref List <MyMatrAdj> listOfMatrAdj, ref List <MyPatternOfComponents> listOfOutputPatternTwo)
        {
            const string nameFile = "GetTranslationalPatterns.txt";

            //KLdebug.Print("--> AGGIORNAMENTO DI TUTTI GLI ALTRI DATI:", nameFile);

            foreach (var comp in newPattern.listOfMyRCOfMyPattern)
            {
                //var listOfREOnThisSurface =
                //new List<MyRepeatedEntity>(newPattern.listOfMyRCOfMyPattern.Select(re => comp.RepeatedEntity));
                //var indOfThisOrigin = listOfREOnThisSurface.IndexOf(comp.RepeatedEntity);
                var indOfThisOrigin = listOfOrigins.IndexOf(comp.Origin);
                //KLdebug.Print("UPDATE per RE n° " + indOfThisOrigin, nameFile);

                Part.PartUtilities.GeometryAnalysis.UpdateListOfMyPathOfCentroids(ref listOfPathOfPoints, indOfThisOrigin, nameFile);
                Part.PartUtilities.GeometryAnalysis.UpdateListOfMyMatrAdj(ref listOfMatrAdj, indOfThisOrigin, nameFile);
                KLUpdateListOfPatternTwo_Assembly(comp, ref listOfOutputPatternTwo, indOfThisOrigin);

                //KLdebug.Print(" ", nameFile);
            }
        }
        //It detects all the TRANSLATIONAL relations in a set of MyRepeatedComponent
        //whose origins lie on a given line.
        //it saves patterns of length = 2 in a list;
        //it saves patterns of length > 2 in a list.
        //It returns TRUE if only one pattern has been detected and it has maximum length, FALSE otherwise.

        public static bool GetPatternsFromLinearPath_Assembly(List <MyRepeatedComponent> listOfComponentsOnThePath,
                                                              MyPathGeometricObject pathObject, ref List <MyPathOfPoints> listOfPathOfPoints,
                                                              List <MyVertex> listOfOrigins, ref List <MyMatrAdj> listOfMatrAdj,
                                                              ref List <MyPatternOfComponents> listOfOutputPattern, ref List <MyPatternOfComponents> listOfOutputPatternTwo)
        {
            var numOfCompOnThisPath = listOfComponentsOnThePath.Count;
            var noStop = true;


            var i = 0;

            while (i < (numOfCompOnThisPath - 1))
            {
                var newPattern      = new MyPatternOfComponents();
                var foundNewPattern = GetMaximumTranslation_Assembly(listOfComponentsOnThePath, pathObject, ref i, ref numOfCompOnThisPath,
                                                                     ref noStop, ref newPattern);

                if (foundNewPattern)
                {
                    if (newPattern.listOfMyRCOfMyPattern.Count == numOfCompOnThisPath ||
                        newPattern.listOfMyRCOfMyPattern.Count == numOfCompOnThisPath - 1)
                    {
                        noStop = true;
                    }

                    CheckAndUpdate_Assembly(newPattern, ref listOfPathOfPoints,
                                            listOfOrigins, ref listOfMatrAdj,
                                            ref listOfOutputPattern, ref listOfOutputPatternTwo);
                }
            }

            if (noStop)
            {
                return(true);
            }
            return(false);
        }
Esempio n. 7
0
        //This function verifies if two given patterns are related by translation, with the difference
        //vector between the two pattern centroids as candidate translational vector.
        public static bool IsTranslationTwoPatternsOfComponents(MyPatternOfComponents firstMyPattern,
                                                                MyPatternOfComponents secondMyPattern)
        {
            const string nameFile = "ComposedPatterns_Linear.txt";

            //check of the length correspondence:
            var firstPatternLength  = firstMyPattern.listOfMyRCOfMyPattern.Count;
            var secondPatternLength = secondMyPattern.listOfMyRCOfMyPattern.Count;

            if (firstPatternLength != secondPatternLength)
            {
                return(false);
            }


            if (AssemblyUtilities.GeometryAnalysis.IsTranslationTwoRC(firstMyPattern.listOfMyRCOfMyPattern[0],
                                                                      secondMyPattern.listOfMyRCOfMyPattern[0]) ||
                AssemblyUtilities.GeometryAnalysis.IsTranslationTwoRC(firstMyPattern.listOfMyRCOfMyPattern[0],
                                                                      secondMyPattern.listOfMyRCOfMyPattern[secondPatternLength - 1]))
            {
                return(true);
            }
            return(false);
        }
        public static bool KLGetPatternsFromCircularPath_Assembly(List <MyRepeatedComponent> listOfComponentsOnThePath,
                                                                  MyPathGeometricObject pathObject, ref List <MyPathOfPoints> listOfPathOfPoints,
                                                                  List <MyVertex> listOfOrigins, ref List <MyMatrAdj> listOfMatrAdj,
                                                                  ref List <MyPatternOfComponents> listOfOutputPattern, ref List <MyPatternOfComponents> listOfOutputPatternTwo, ModelDoc2 SwModel, SldWorks SwApplication)
        {
            var numOfCompOnThisPath = listOfComponentsOnThePath.Count;
            var noStop = true;

            //const string nameFile = "GetCircularPatterns.txt";
            //KLdebug.Print(" ", nameFile);
            //KLdebug.Print(
            //    "VERIFICA DELLE POSSIBILI TRASLAZIONI SU CIRCONFERENZA O ROTAZIONI TRA " + numOfCompOnThisPath + " COMPONENTS:",
            //    nameFile);
            //KLdebug.Print(" ", nameFile);

            var i = 0;

            while (i < (numOfCompOnThisPath - 1))
            {
                var newPattern      = new MyPatternOfComponents();
                var j               = i;
                var foundNewPattern = KLGetMaximumTranslation_Assembly(listOfComponentsOnThePath, pathObject, ref j, ref numOfCompOnThisPath,
                                                                       ref noStop, ref newPattern, SwApplication);
                if (foundNewPattern == false)
                {
                    var pathCircumference = (MyCircumForPath)pathObject;

                    foundNewPattern = KLGetMaximumRotation_Assembly(listOfComponentsOnThePath, pathCircumference,
                                                                    ref i, ref numOfCompOnThisPath,
                                                                    ref noStop, ref newPattern, SwModel, SwApplication);
                }
                else
                {
                    i = j;
                }

                if (foundNewPattern)
                {
                    //KLdebug.Print("foundNewPattern vero", nameFile);
                    if (newPattern.listOfMyRCOfMyPattern.Count == numOfCompOnThisPath ||
                        newPattern.listOfMyRCOfMyPattern.Count == numOfCompOnThisPath - 1)
                    {
                        //KLdebug.Print("foundNewPattern vero no stop", nameFile);
                        noStop = true;
                    }

                    KLCheckAndUpdate_Assembly(newPattern, ref listOfPathOfPoints,
                                              listOfOrigins, ref listOfMatrAdj,
                                              ref listOfOutputPattern, ref listOfOutputPatternTwo);
                }
            }

            //KLdebug.Print(" ", nameFile);
            //KLdebug.Print("FINE LISTA :) ", nameFile);

            if (noStop)
            {
                // KLdebug.Print("NESSUNA INTERRUZIONE: PATTERN DI LUNGHEZZA MASSIMA SU QUESTO PATH!", nameFile);
                return(true);
            }
            return(false);
        }
        public static bool KLGetMaximumRotation_Assembly(List <MyRepeatedComponent> listOfComponentsOnThePath,
                                                         MyCircumForPath pathObject,
                                                         ref int i, ref int numOfComp, ref bool noStop, ref MyPatternOfComponents outputPattern)
        {
            //const string nameFile = "GetRotationalPatterns.txt";
            //KLdebug.Print(" ", nameFile);
            //KLdebug.Print("NUOVO AVVIO DI RICERCA ROTAZIONE", nameFile);
            //KLdebug.Print(" ", nameFile);
            //var whatToWrite = "";

            var listOfREOnThePath =
                new List <MyRepeatedEntity>(listOfComponentsOnThePath.Select(comp => comp.RepeatedEntity));

            var listOfREOfNewMyPattern = new List <MyRepeatedEntity> {
                listOfREOnThePath[i]
            };
            var listOfComponetsOfNewMyPattern = new List <MyRepeatedComponent> {
                listOfComponentsOnThePath[i]
            };

            var lengthOfCurrentPath = 1;   // = it represents the number of couples related by translation
            var exit = false;

            if (pathObject.circumplane == null)
            {
                exit   = true;
                noStop = false;
                i++;
                return(false);
            }
            //Computation of the rotation angle:
            double[] planeNormal =
            {
                pathObject.circumplane.a,
                pathObject.circumplane.b,
                pathObject.circumplane.c
            };
            var teta = FunctionsLC.FindAngle(listOfREOnThePath[0].centroid, listOfREOnThePath[1].centroid, pathObject.circumcenter);

            var axisDirection = Part.PartUtilities.GeometryAnalysis.establishAxisDirection(listOfREOnThePath[0].centroid, listOfREOnThePath[1].centroid,
                                                                                           pathObject.circumcenter, planeNormal);

            while (i < (numOfComp - 1) && exit == false) //fino alla penultima RE
            {
                //KLdebug.Print(" ", nameFile);
                //KLdebug.Print(" ", nameFile);
                //whatToWrite = string.Format("         Confronto {0}^ RE e la {1}^ RE: ", i, i + 1);
                //KLdebug.Print(whatToWrite, nameFile);

                if (true)
                //if (Part.PartUtilities.GeometryAnalysis.IsRotationTwoRE(listOfREOnThePath[i], listOfREOnThePath[i + 1], teta, axisDirection, pathObject.circumcenter))
                {
                    listOfREOfNewMyPattern.Add(listOfREOnThePath[i + 1]);
                    listOfComponetsOfNewMyPattern.Add(listOfComponentsOnThePath[i + 1]);
                    lengthOfCurrentPath += 1;
                    //KLdebug.Print("Aggiunta " + (i + 1) + "-esima RE al MYPattern. lengthOfCurrentPath = " + lengthOfCurrentPath, nameFile);
                    i++;
                }
                else
                {
                    exit   = true;
                    noStop = false;

                    //KLdebug.Print(" ", nameFile);
                    //KLdebug.Print("------>>> Interruzione alla posizione: " + i, nameFile);
                    //KLdebug.Print(" ", nameFile);

                    i++;
                }
            }
            // KLdebug.Print(" ", nameFile);

            if (lengthOfCurrentPath > 1)
            {
                outputPattern.listOfMyRCOfMyPattern = listOfComponetsOfNewMyPattern;

                outputPattern.listOfMyRCOfMyPattern = listOfComponentsOnThePath;
                outputPattern.pathOfMyPattern       = pathObject;

                outputPattern.typeOfMyPattern      = "ROTATION";
                outputPattern.constStepOfMyPattern = listOfREOfNewMyPattern[0].centroid.Distance(listOfREOfNewMyPattern[1].centroid);
                //KLdebug.Print("CREATO PATTERN Rotazionale circolare DI LUNGHEZZA = " + lengthOfCurrentPath, nameFile);

                outputPattern.angle = teta;
                return(true);
            }
            //KLdebug.Print("lengthOfCurrentPath = " + lengthOfCurrentPath, nameFile);
            //KLdebug.Print("IL PATTERN TRANS ha LUNGHEZZA NULLA, NON HO CREATO NIENTE.", nameFile);
            //KLdebug.Print(" ", nameFile);
            return(false);

            //const string nameFile = "GetRotationalPatterns.txt";
            //KLdebug.Print(" ", nameFile);
            //KLdebug.Print("NUOVO AVVIO DI RICERCA ROTAZIONE", nameFile);
            //KLdebug.Print(" ", nameFile);
            //var whatToWrite = "";

            ////var newMyPattern = new MyPattern();

            //var listOfCompOfNewMyPattern = new List<MyRepeatedComponent> { listOfComponentsOnThePath[i] };
            //var lengthOfCurrentPath = 1; // = it represents the number of couples related by translation
            //var exit = false;

            ////Computation of the rotation angle:
            //double[] planeNormal =
            //{
            //    pathObject.circumplane.a,
            //    pathObject.circumplane.b,
            //    pathObject.circumplane.c
            //};

            //var teta = FunctionsLC.FindAngle(listOfComponentsOnThePath[0].Origin, listOfComponentsOnThePath[1].Origin,
            //    pathObject.circumcenter);
            //KLdebug.Print("   --->>> TETA = " + teta, nameFile);


            //var axisDirection =
            //    BRepUtilities.GeometryAnalysis.establishAxisDirection(listOfComponentsOnThePath[0].Origin,
            //        listOfComponentsOnThePath[1].Origin,
            //        pathObject.circumcenter, planeNormal);

            //while (i < (numOfComp - 1) && exit == false) //fino alla penultima Comp
            //{
            //    KLdebug.Print(" ", nameFile);
            //    KLdebug.Print(" ", nameFile);
            //    whatToWrite = string.Format("         Confronto {0}^ COMP e la {1}^ COMP: ", i, i + 1);
            //    KLdebug.Print(whatToWrite, nameFile);

            //    KLdebug.PrintTransformMatrix(listOfComponentsOnThePath[i].Transform, nameFile, SwApplication);
            //    KLdebug.PrintTransformMatrix(listOfComponentsOnThePath[i + 1].Transform, nameFile, SwApplication);

            //    if (IsRotationTwoComp_Assembly(listOfComponentsOnThePath[i], listOfComponentsOnThePath[i + 1], teta, axisDirection))
            //    {
            //        listOfCompOfNewMyPattern.Add(listOfComponentsOnThePath[i + 1]);
            //        lengthOfCurrentPath += 1;
            //        KLdebug.Print(
            //            "Aggiunta " + (i + 1) + "-esima COMP al MYPattern. lengthOfCurrentPath = " + lengthOfCurrentPath,
            //            nameFile);
            //        i++;
            //    }
            //    else
            //    {
            //        exit = true;
            //        noStop = false;

            //        KLdebug.Print(" ", nameFile);
            //        KLdebug.Print("------>>> Interruzione alla posizione: " + i, nameFile);
            //        KLdebug.Print(" ", nameFile);

            //        i++;
            //    }
            //}
            //KLdebug.Print(" ", nameFile);

            //if (lengthOfCurrentPath > 1)
            //{
            //    outputPattern.listOfMyRCOfMyPattern = listOfCompOfNewMyPattern;
            //    outputPattern.pathOfMyPattern = pathObject;
            //    KLdebug.Print("lengthOfCurrentPath = " + lengthOfCurrentPath, nameFile);

            //    outputPattern.typeOfMyPattern = "ROTATION";
            //    outputPattern.angle = teta;
            //    KLdebug.Print("CREATO PATTERN Rotazionale circolare DI LUNGHEZZA = " + lengthOfCurrentPath, nameFile);
            //    return true;
            //}
            //KLdebug.Print("lengthOfCurrentPath = " + lengthOfCurrentPath, nameFile);
            //KLdebug.Print("IL PATTERN TRANS ha LUNGHEZZA NULLA, NON HO CREATO NIENTE.", nameFile);
            //KLdebug.Print(" ", nameFile);
            //return false;
        }
Esempio n. 10
0
        public static bool GetMaximumTranslation_Assembly(List <MyRepeatedComponent> listOfComponentsOnThePath, MyPathGeometricObject pathObject,
                                                          ref int i, ref int numOfCompOnThisPath, ref bool noStop, ref MyPatternOfComponents outputPattern)
        {
            const string nameFile = "GetTranslationalPatterns.txt";
            string       whatToWrite;

            var listOfComponentsOfNewMyPattern = new List <MyRepeatedComponent> {
                listOfComponentsOnThePath[i]
            };
            var lengthOfCurrentPath = listOfComponentsOfNewMyPattern.Count;
            var exit = false;

            while (i < (numOfCompOnThisPath - 1) && exit == false)
            {
                if (IsTranslationTwoRC(listOfComponentsOnThePath[i], listOfComponentsOnThePath[i + 1]))
                {
                    listOfComponentsOfNewMyPattern.Add(listOfComponentsOnThePath[i + 1]);
                    lengthOfCurrentPath += 1;
                    i++;
                }
                else
                {
                    exit   = true;
                    noStop = false;

                    i++;
                }
            }

            if (lengthOfCurrentPath > 1)
            {
                outputPattern.listOfMyRCOfMyPattern = listOfComponentsOfNewMyPattern;
                outputPattern.pathOfMyPattern       = pathObject;

                if (pathObject.GetType() == typeof(MyLine))
                {
                    outputPattern.typeOfMyPattern = "linear TRANSLATION";
                }
                else
                {
                    outputPattern.typeOfMyPattern = "circular TRANSLATION";
                }
                outputPattern.constStepOfMyPattern = listOfComponentsOfNewMyPattern[0].Origin.Distance(
                    listOfComponentsOfNewMyPattern[1].Origin);
                return(true);
            }

            return(false);
        }
Esempio n. 11
0
        public static bool KLGetMaximumTranslation_Assembly(List <MyRepeatedComponent> listOfComponentsOnThePath, MyPathGeometricObject pathObject,
                                                            ref int i, ref int numOfCompOnThisPath, ref bool noStop, ref MyPatternOfComponents outputPattern)
        {
            //const string nameFile = "GetTranslationalPatterns.txt";

            var listOfREOnThePath = new List <MyRepeatedEntity>(listOfComponentsOnThePath.Select(comp => comp.RepeatedEntity));

            var listOfREOfNewMyPattern = new List <MyRepeatedEntity> {
                listOfREOnThePath[i]
            };
            var listOfComponetsOfNewMyPattern = new List <MyRepeatedComponent> {
                listOfComponentsOnThePath[i]
            };

            var lengthOfCurrentPath = listOfREOfNewMyPattern.Count;   // = number of couple possibly related by translation (= number of repetition of distance d)
            var exit = false;

            while (i < (numOfCompOnThisPath - 1) && exit == false) //fino alla penultima RE
            {
                if (true)
                //if (Part.PartUtilities.GeometryAnalysis.IsTranslationTwoRE(listOfREOnThePath[i], listOfREOnThePath[i + 1]))
                {
                    listOfREOfNewMyPattern.Add(listOfREOnThePath[i + 1]);
                    listOfComponetsOfNewMyPattern.Add(listOfComponentsOnThePath[i + 1]);
                    lengthOfCurrentPath += 1;
                    //KLdebug.Print("Aggiunta " + (i + 1) + "-esima COMP al MYPattern. lengthOfCurrentPath = " + listOfComponetsOfNewMyPattern.Count, nameFile);
                    i++;
                }
                else
                {
                    exit   = true;
                    noStop = false;

                    //KLdebug.Print(" ", nameFile);
                    //KLdebug.Print("------>>> Interruzione alla posizione: " + i, nameFile);
                    //KLdebug.Print(" ", nameFile);

                    i++;
                }
            }

            if (lengthOfCurrentPath > 1)
            {
                outputPattern.listOfMyRCOfMyPattern = listOfComponetsOfNewMyPattern;
                outputPattern.pathOfMyPattern       = pathObject;

                if (pathObject.GetType() == typeof(MyLine))
                {
                    outputPattern.typeOfMyPattern = "linear TRANSLATION";
                    //KLdebug.Print("CREATO PATTERN TRANS lineare DI LUNGHEZZA = " + listOfREOfNewMyPattern.Count, nameFile);
                }
                else
                {
                    outputPattern.typeOfMyPattern = "circular TRANSLATION";
                    //KLdebug.Print("CREATO PATTERN TRANS circolare DI LUNGHEZZA = " + lengthOfCurrentPath, nameFile);
                    var teta = FunctionsLC.FindAngle(listOfREOfNewMyPattern[0].centroid,
                                                     listOfREOfNewMyPattern[1].centroid, ((MyCircumForPath)pathObject).circumcenter);
                    outputPattern.angle = teta;
                }
                outputPattern.constStepOfMyPattern = listOfREOfNewMyPattern[0].centroid.Distance(listOfREOfNewMyPattern[1].centroid);
                return(true);
            }

            return(false);
        }
Esempio n. 12
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);
                        //    }
                        //}
                    }
                }
            }
        }
        public static void KLCheckAndUpdate_Assembly(MyPatternOfComponents newPattern,
                                                     ref List <MyPathOfPoints> listOfPathOfPoints,
                                                     List <MyVertex> listOfOrigins, ref List <MyMatrAdj> listOfMatrAdj,
                                                     ref List <MyPatternOfComponents> listOfOutputPattern, ref List <MyPatternOfComponents> listOfOutputPatternTwo)
        {
            //const string nameFile = "GetTranslationalPatterns.txt";
            //KLdebug.Print(" ", nameFile);
            //KLdebug.Print(" ", nameFile);
            //KLdebug.Print("             UPDATE STEP", nameFile);
            //KLdebug.Print("CURRENT SITUATION:", nameFile);
            //KLdebug.Print("listOfOutputPattern.Count = " + listOfOutputPattern.Count, nameFile);
            //KLdebug.Print("listOfOutputPatternTwo.Count = " + listOfOutputPatternTwo.Count, nameFile);
            //KLdebug.Print(" ", nameFile);

            var lengthOfPattern = newPattern.listOfMyRCOfMyPattern.Count;

            // if lengthOfPattern = 2, I add the newPatternPoint only if there is not another pattern in listOfOutputPatternTwo
            // containing one of the two RE in the newPatternPoint.
            if (lengthOfPattern == 2)
            {
                //KLdebug.Print("lengh 2: Entrata nel lengthOfPattern = " + lengthOfPattern, nameFile);

                int i        = 0;
                var addOrNot = true;
                while (addOrNot == true && i < 2)
                {
                    if (i < newPattern.listOfMyRCOfMyPattern.Count)
                    {
                        var currentRE  = newPattern.listOfMyRCOfMyPattern[i];
                        var indOfFound =
                            listOfOutputPatternTwo.FindIndex(
                                pattern =>
                                pattern.listOfMyRCOfMyPattern.FindIndex(
                                    re => re.RepeatedEntity.idRE == currentRE.RepeatedEntity.idRE) != -1);
                        if (indOfFound != -1)
                        {
                            addOrNot = false;
                        }
                    }
                    i++;
                }

                if (addOrNot == true)
                {
                    listOfOutputPatternTwo.Add(newPattern);
                    //KLdebug.Print("AGGIUNTO! Non ho trovato altri Pattern da 2 con intersezione non nulla con il corrente.", nameFile);
                }
                else
                {
                    //KLdebug.Print("NON AGGIUNTO! Trovato altro Pattern da 2 che interseca questo.", nameFile);
                }
            }
            // if lengthOfPattern > 2, I add the newPatternPoint and I update the other data
            // (aiming not to find pattern containing RE already set in this newPatternPoint)
            else
            {
                //KLdebug.Print("Entrata nel lengthOfPattern = " + lengthOfPattern, nameFile);

                listOfOutputPattern.Add(newPattern);
                //KLdebug.Print("AGGIUNTO (senza verifiche..) faccio update", nameFile);

                UpdateOtherData_Assembly(newPattern, ref listOfPathOfPoints, listOfOrigins, ref listOfMatrAdj,
                                         ref listOfOutputPatternTwo);
            }


            //const string nameFile = "GetTranslationalPatterns.txt";
            //KLdebug.Print(" ", nameFile);
            //KLdebug.Print(" ", nameFile);
            //KLdebug.Print("             UPDATE STEP", nameFile);
            //KLdebug.Print("CURRENT SITUATION:", nameFile);
            //KLdebug.Print("listOfOutputPattern.Count = " + listOfOutputPattern.Count, nameFile);
            //KLdebug.Print("listOfOutputPatternTwo.Count = " + listOfOutputPatternTwo.Count, nameFile);
            //KLdebug.Print(" ", nameFile);

            //var lengthOfPattern = newPattern.listOfMyRCOfMyPattern.Count;

            //// if lengthOfPattern = 2, I add the newPattern only if there is not another pattern in listOfOutputPatternTwo
            //// containing one of the two RE in the newPattern.
            //if (lengthOfPattern == 2)
            //{
            //    KLdebug.Print(
            //        "Entrata per aggiornare con l'inserimento di un pattern di lunghezza lengthOfPattern = " +
            //        lengthOfPattern, nameFile);

            //    int i = 0;
            //    var addOrNot = true;
            //    while (addOrNot == true && i < 2)
            //    {
            //        var currentRC = newPattern.listOfMyRCOfMyPattern[i];
            //        var listOfMyREOfMyPattern = new List<MyRepeatedEntity>(
            //            newPattern.listOfMyRCOfMyPattern.Select(ent => ent.RepeatedEntity)).ToList();

            //        var currentRE = currentRC.RepeatedEntity;
            //        var indOfFound = listOfMyREOfMyPattern.FindIndex(re => re.idRE == currentRE.idRE);
            //        if (indOfFound != -1)
            //        {
            //            addOrNot = false;
            //        }
            //        i++;
            //    }

            //    if (addOrNot == true)
            //    {
            //        listOfOutputPatternTwo.Add(newPattern);
            //        KLdebug.Print(
            //            "AGGIUNTO! Non ho trovato altri Pattern da 2 con intersezione non nulla con il corrente.",
            //            nameFile);
            //    }
            //    else
            //    {
            //        KLdebug.Print("NON AGGIUNTO! Trovato altro Pattern da 2 che interseca questo.", nameFile);
            //    }

            //}
            //// if lengthOfPattern > 2, I add the newPattern and I update the other data
            //// (aiming not to find pattern containing RE already set in this newPattern)
            //else
            //{
            //    KLdebug.Print("Entrata nel lengthOfPattern = " + lengthOfPattern, nameFile);

            //    listOfOutputPattern.Add(newPattern);
            //    KLdebug.Print("AGGIUNTO (senza verifiche..)", nameFile);

            //    UpdateOtherData_Assembly(newPattern, ref listOfPathOfPoints, listOfOrigins, ref listOfMatrAdj,
            //        ref listOfOutputPatternTwo);
            //}
        }