예제 #1
0
        //It verifies if a symmetry TRANSLATIONAL relation of translational vector between two MyRepeatedComponent
        public static bool IsTranslationTwoRC(MyRepeatedComponent firstComponent,
                                              MyRepeatedComponent secondComponent)
        {
            const string nameFile = "GetTranslationalPatterns.txt";
            string       whatToWrite;
            int          i = 0;

            //for (var j = 0; j < 3; j++)
            //{
            //    double[] firstVector =
            //    {
            //        firstComponent.Transform.RotationMatrix[0, j],
            //        firstComponent.Transform.RotationMatrix[1, j],
            //        firstComponent.Transform.RotationMatrix[2, j]
            //    };
            //    double[] secondVector =
            //    {
            //        secondComponent.Transform.RotationMatrix[0, j],
            //        secondComponent.Transform.RotationMatrix[1, j],
            //        secondComponent.Transform.RotationMatrix[2, j]
            //    };

            //    whatToWrite = string.Format("Versore 1^ componente: ({0},{1},{2})", firstVector[0], firstVector[1], firstVector[2]);
            //    KLdebug.Print(whatToWrite, nameFile);
            //    whatToWrite = string.Format("Versore 2^ componente: ({0},{1},{2})", secondVector[0], secondVector[1], secondVector[2]);
            //    KLdebug.Print(whatToWrite, nameFile);
            //    KLdebug.Print("", nameFile);

            //}

            while (i < 3)
            {
                double[] firstVector =
                {
                    firstComponent.Transform.RotationMatrix[0, i],
                    firstComponent.Transform.RotationMatrix[1, i],
                    firstComponent.Transform.RotationMatrix[2, i]
                };
                double[] secondVector =
                {
                    secondComponent.Transform.RotationMatrix[0, i],
                    secondComponent.Transform.RotationMatrix[1, i],
                    secondComponent.Transform.RotationMatrix[2, i]
                };


                if (FunctionsLC.MyEqualsArray(firstVector, secondVector))
                {
                    i++;
                }
                else
                {
                    return(false);
                }
            }

            return(true);
        }
        //Update list of Pattern geometrically verified of length = 2: delete the ones containing
        //a RE of the newPattern
        public static void UpdateListOfPatternTwo_Assembly(MyRepeatedComponent comp,
                                                           ref List <MyPatternOfComponents> listOfOutputPatternTwo, int indOfThisOrigin)
        {
            var found = listOfOutputPatternTwo.Find(
                pattern =>
                pattern.listOfMyRCOfMyPattern.FindIndex(
                    compInPattern => Equals(compInPattern.Transform, comp.Transform)) != -1);

            if (found != null)
            {
                listOfOutputPatternTwo.Remove(found);
            }
        }
        //It verifies if a symmetry REFLECTIONAL relation between two MyRepeatedEntity exists
        public static bool IsReflectionTwoComp_Assembly(MyRepeatedComponent firstComponent,
                                                        MyRepeatedComponent secondComponent)
        {
            int i = 0;

            for (var j = 0; j < 3; j++)
            {
                double[] firstVector =
                {
                    firstComponent.Transform.RotationMatrix[0, j],
                    firstComponent.Transform.RotationMatrix[1, j],
                    firstComponent.Transform.RotationMatrix[2, j]
                };
                double[] secondVector =
                {
                    secondComponent.Transform.RotationMatrix[0, j],
                    secondComponent.Transform.RotationMatrix[1, j],
                    secondComponent.Transform.RotationMatrix[2, j]
                };
            }

            var candidateReflMyPlane = Part.PartUtilities.GeometryAnalysis.GetCandidateReflectionalMyPlane(firstComponent.RepeatedEntity.centroid,
                                                                                                           secondComponent.RepeatedEntity.centroid, null);

            while (i < 3)
            {
                var firstVector = new double[] {
                    firstComponent.Transform.RotationMatrix[0, i],
                    firstComponent.Transform.RotationMatrix[1, i],
                    firstComponent.Transform.RotationMatrix[2, i]
                };
                var secondVector = new double[] {
                    secondComponent.Transform.RotationMatrix[0, i],
                    secondComponent.Transform.RotationMatrix[1, i],
                    secondComponent.Transform.RotationMatrix[2, i]
                };


                var reflectedNormal = Part.PartUtilities.GeometryAnalysis.ReflectNormal(firstVector, candidateReflMyPlane);
                if (FunctionsLC.MyEqualsArray(secondVector, reflectedNormal))
                {
                    i++;
                }
                else
                {
                    return(false);
                }
            }

            return(true);
        }
        public static void KLUpdateListOfPatternTwo_Assembly(MyRepeatedComponent comp,
                                                             ref List <MyPatternOfComponents> listOfOutputPatternTwo, int indOfThisOrigin)
        {
            //const string nameFile = "GetTranslationalPatterns.txt";
            //KLdebug.Print("     ---> UpdateListOfPatternTwo", nameFile);

            var found = listOfOutputPatternTwo.Find(
                pattern => pattern.listOfMyRCOfMyPattern.FindIndex(reInPattern => reInPattern.RepeatedEntity.idRE == comp.RepeatedEntity.idRE) != -1);

            if (found != null)
            {
                listOfOutputPatternTwo.Remove(found);
                //KLdebug.Print(" RIMOSSO dalla lista listOfOutputPatternTwo!", nameFile);
            }
            //KLdebug.Print(" ", nameFile);
        }
예제 #5
0
        public static MyRepeatedComponent ComputeNewRepeatedComponent(SldWorks swApplication, Component2 component2, int idCorrespondingNode,
                                                                      MyTransformMatrix newRelativeTransformMatrix, int indexRepEntity, bool newIsLeaf)
        {
            // Aggiunto calcolo dell'entità ripetuta alla parte.
            var currentModel = component2.GetModelDoc2();
            var entityList   =
                (List <Entity>)AssemblyTraverse.KL_GetPartFaces(currentModel, component2.Name2,
                                                                swApplication);

            double[,] compositionMatrixOfComponentPart =
                new double[4, 4]
            {
                {
                    (double)newRelativeTransformMatrix.RotationMatrix[0, 0],
                    (double)newRelativeTransformMatrix.RotationMatrix[0, 1],
                    (double)newRelativeTransformMatrix.RotationMatrix[0, 2],
                    (double)newRelativeTransformMatrix.TranslationVector[0]
                },
                {
                    (double)newRelativeTransformMatrix.RotationMatrix[1, 0],
                    (double)newRelativeTransformMatrix.RotationMatrix[1, 1],
                    (double)newRelativeTransformMatrix.RotationMatrix[1, 2],
                    (double)newRelativeTransformMatrix.TranslationVector[1]
                },
                {
                    (double)newRelativeTransformMatrix.RotationMatrix[2, 0],
                    (double)newRelativeTransformMatrix.RotationMatrix[2, 1],
                    (double)newRelativeTransformMatrix.RotationMatrix[2, 2],
                    (double)newRelativeTransformMatrix.TranslationVector[2]
                },
                { 0.0, 0.0, 0.0, 1 }
            };

            //swApplication.SendMsgToUser("Calcolo repeated entity di " + component2.Name2 + "\nnumero facce " + entityList.Count);
            MyRepeatedEntity newRepeatedEntity = ExtractInfoFromBRep.KLBuildRepeatedEntity(
                entityList, indexRepEntity, compositionMatrixOfComponentPart, swApplication);
            //swApplication.SendMsgToUser("Ha " + newRepeatedEntity.listOfVertices.Count + " vertici\n" + newRepeatedEntity.listOfAddedVertices.Count + " vertici aggiunti");

            // Fine calcolo entità rip da aggiungere alla componente.
            var newMyComponent = new MyRepeatedComponent(component2, idCorrespondingNode, newRelativeTransformMatrix, newIsLeaf,
                                                         newRepeatedEntity);

            return(newMyComponent);
        }
        public static bool IsRotationTwoComp_Assembly(MyRepeatedComponent firstComponent,
                                                      MyRepeatedComponent secondComponent, double teta, double[] axisDirection)
        {
            const string nameFile = "GetRotationalPatterns.txt";
            int          i        = 0;

            while (i < 3)
            {
                var firstVector = new MyVertex(
                    //firstComponent.Transform.RotationMatrix[i, 0],
                    //firstComponent.Transform.RotationMatrix[i, 1],
                    //firstComponent.Transform.RotationMatrix[i, 2]
                    firstComponent.Transform.RotationMatrix[0, i],
                    firstComponent.Transform.RotationMatrix[1, i],
                    firstComponent.Transform.RotationMatrix[2, i]
                    );
                var secondVector = new MyVertex(
                    //secondComponent.Transform.RotationMatrix[i, 0],
                    //secondComponent.Transform.RotationMatrix[i, 1],
                    //secondComponent.Transform.RotationMatrix[i, 2]
                    secondComponent.Transform.RotationMatrix[0, i],
                    secondComponent.Transform.RotationMatrix[1, i],
                    secondComponent.Transform.RotationMatrix[2, i]
                    );



                if (secondVector.IsRotationOf(firstVector, teta, axisDirection))
                {
                    i++;
                }
                else
                {
                    return(false);
                }
            }


            return(true);
        }
        public static bool IsRotationTwoComp180degrees_Assembly(MyRepeatedComponent firstComponent,
                                                                MyRepeatedComponent secondComponent, out double[] axisDirectionVersor)
        {
            const string nameFile = "GetRotationalPatterns.txt";

            //Rotation axis computation:
            //we need to find 2 vertices for each of the 2 components:
            //one is the origin, the second is a chosen point/versor from x,y, or z.
            //Then we need to compute the mean point between the origins
            //and the mean point between the chosen versors.
            //The rotation axis corresponds to the line passing through the two mean points.

            var originMeanPoint = new double[] { (firstComponent.Origin.x + secondComponent.Origin.x) / 2,
                                                 (firstComponent.Origin.y + secondComponent.Origin.y) / 2,
                                                 (firstComponent.Origin.z + secondComponent.Origin.z) / 2 };

            //SwModel = (ModelDoc2)SwApplication.ActiveDoc;
            //SwModel.ClearSelection2(true);
            //SwModel.Insert3DSketch();
            //SwModel.CreatePoint2(originMeanPoint[0], originMeanPoint[1], originMeanPoint[2]);
            //SwModel.InsertSketch();

            var xVersorCorrespondingPointFirst = new double[] {
                firstComponent.Origin.x + firstComponent.Transform.RotationMatrix[0, 0],
                firstComponent.Origin.y + firstComponent.Transform.RotationMatrix[1, 0],
                firstComponent.Origin.z + firstComponent.Transform.RotationMatrix[2, 0]
            };

            var xVersorCorrespondingPointSecond = new double[] {
                secondComponent.Origin.x + secondComponent.Transform.RotationMatrix[0, 0],
                secondComponent.Origin.y + secondComponent.Transform.RotationMatrix[1, 0],
                secondComponent.Origin.z + secondComponent.Transform.RotationMatrix[2, 0]
            };

            var versorMeanPoint = new double[] { (xVersorCorrespondingPointFirst[0] + xVersorCorrespondingPointSecond[0]) / 2,
                                                 (xVersorCorrespondingPointFirst[1] + xVersorCorrespondingPointSecond[1]) / 2,
                                                 (xVersorCorrespondingPointFirst[2] + xVersorCorrespondingPointSecond[2]) / 2 };

            // if the mean point of the origins and the mean point of the x versors correspond
            // I compute the mean point referred to the y coordinate versors:
            var i = 0;

            while (FunctionsLC.MyEqualsArray(versorMeanPoint, originMeanPoint) && i < 2)
            {
                i++;

                xVersorCorrespondingPointFirst.SetValue(firstComponent.Origin.x + firstComponent.Transform.RotationMatrix[0, i], 0);
                xVersorCorrespondingPointFirst.SetValue(firstComponent.Origin.y + firstComponent.Transform.RotationMatrix[1, i], 1);
                xVersorCorrespondingPointFirst.SetValue(firstComponent.Origin.z + firstComponent.Transform.RotationMatrix[2, i], 2);

                xVersorCorrespondingPointSecond.SetValue(secondComponent.Origin.x + secondComponent.Transform.RotationMatrix[0, i], 0);
                xVersorCorrespondingPointSecond.SetValue(secondComponent.Origin.y + secondComponent.Transform.RotationMatrix[1, i], 1);
                xVersorCorrespondingPointSecond.SetValue(secondComponent.Origin.z + secondComponent.Transform.RotationMatrix[2, i], 2);

                versorMeanPoint.SetValue((xVersorCorrespondingPointFirst[0] + xVersorCorrespondingPointSecond[0]) / 2, 0);
                versorMeanPoint.SetValue((xVersorCorrespondingPointFirst[1] + xVersorCorrespondingPointSecond[1]) / 2, 1);
                versorMeanPoint.SetValue((xVersorCorrespondingPointFirst[2] + xVersorCorrespondingPointSecond[2]) / 2, 2);
            }
            ;
            //SwModel = (ModelDoc2)SwApplication.ActiveDoc;
            //SwModel.ClearSelection2(true);
            //SwModel.Insert3DSketch();
            //SwModel.CreatePoint2(versorMeanPoint[0], versorMeanPoint[1], versorMeanPoint[2]);
            //SwModel.InsertSketch();

            var axisDirectionVector = new double[] { originMeanPoint[0] - versorMeanPoint[0], originMeanPoint[1] - versorMeanPoint[1],
                                                     originMeanPoint[2] - versorMeanPoint[2] };

            axisDirectionVersor = GeometricUtilities.FunctionsLC.Normalize(axisDirectionVector);
            var teta = Math.PI; // the angle is fixed at 180°

            // Now i got the direction axis and the the rotation angle: I use the existing verifying function
            return(IsRotationTwoComp_Assembly(firstComponent, secondComponent, teta, axisDirectionVersor));
        }
예제 #8
0
        static void Main(string[] args)
        {
            //Console.WriteLine("Starting..");

            //var swApp = new SldWorks();

            //var swAPIWarnings = 0;
            //var swAPIErrors = 0;

            //var importData = (ImportStepData)swApp.GetImportFileData(args[0]);
            //var swActiveDoc = (ModelDoc2)swApp.LoadFile4(args[0], "r", importData, swAPIErrors);

            //if (swActiveDoc == null)
            //{
            //    Console.WriteLine("swActiveDoc nullo " + swAPIWarnings + " " + swAPIErrors);
            //    return;
            //}

            //var swAssemblyDoc = (AssemblyDoc)swActiveDoc;

            //var SwConfiguration = swActiveDoc.GetActiveConfiguration();
            //var rootComponent = (Component2)SwConfiguration.GetRootComponent();
            //var fileName = rootComponent.Name2;

            //Console.WriteLine("Modello attivato " + fileName);

            //var transforation =
            //    (Array)AssemblyTraverse.KL_GetTransformsOfAssemblyComponents(rootComponent, swApp);
            //const string fatherName = KLgraph.RootLabel;
            //var pathComponent = rootComponent.Name2;
            //var componentName = pathComponent.Split('/').Last();
            //var componentPath = rootComponent.GetPathName();
            //var id = rootComponent.GetHashCode();

            //var childrenNumber = rootComponent.IGetChildrenCount();
            //var shape = AssemblyTraverse.KL_GetShapeAssembly(rootComponent, swApp);
            //var statistic = AssemblyTraverse.KL_GetStatisticAssembly(rootComponent, swApp);
            //var nodeAssembly = new KLgraph.KLnodeAssembly(id, transforation, fatherName, -1, rootComponent, pathComponent, componentName, componentPath, -1,
            //    childrenNumber, statistic, shape);

            //Console.WriteLine("Creato il nodo assemblato");

            //var vertexList = new List<KLgraph.KLnode>();
            //var edgeList = new List<KLgraph.KLedge>();
            //vertexList.Add(nodeAssembly);
            //var listOfMyListOfInstances = new List<MyListOfInstances>();

            //AssemblyTraverse.KL_GetGraphOfAssemblyComponents(rootComponent, nodeAssembly,
            //   ref vertexList, edgeList, ref listOfMyListOfInstances, swApp);


            //var partList = new List<KLgraph.KLnode>(vertexList);
            //partList.RemoveAll(v => v.GetType() != typeof(KLgraph.KLnodePart));

            //nodeAssembly.KLstatistic.PrincipalPartNumber = partList.Count();

            //nodeAssembly.Instances.AddRange(listOfMyListOfInstances);


            List <MyPatternOfComponents> listPattern  = new List <MyPatternOfComponents>();
            List <MyPatternOfComponents> listPattern2 = new List <MyPatternOfComponents>();
            StringBuilder fileOutput = new StringBuilder();

            fileOutput.AppendLine("RICERCA PATH");

            var compName           = "DIN";
            var listCentroidWordRF = new List <MyVertex>();
            var v1 = new MyVertex(-0.00302203528372547, -0.0657609306477435, 0.0657609306501929);
            var v2 = new MyVertex(-0.00302203528372547, 0.0930000000026054, 0.0);
            var v3 = new MyVertex(-0.00302203528372547, 0.0, -0.093000000000156);
            var v4 = new MyVertex(-0.00302203528372547, -0.0657609306477435, -0.0657609306505048);
            var v5 = new MyVertex(-0.00302203528372547, -0.0929999999973946, -0.0);
            var v6 = new MyVertex(-0.00302203528372547, 0.0657609306529544, 0.0657609306501929);
            var v7 = new MyVertex(-0.00302203528372547, 0.0657609306529543, -0.0657609306505049);
            var v8 = new MyVertex(-0.00302203528372547, 0.0, 0.0929999999998441);

            listCentroidWordRF.Add(v1);
            listCentroidWordRF.Add(v2);
            listCentroidWordRF.Add(v3);
            listCentroidWordRF.Add(v4);
            listCentroidWordRF.Add(v5);
            listCentroidWordRF.Add(v6);
            listCentroidWordRF.Add(v7);
            listCentroidWordRF.Add(v8);


            var newListOfComponetsNoInfo = new List <MyRepeatedComponent>();

            foreach (var comp in listCentroidWordRF)
            {
                var newComp = new MyRepeatedComponent();
                var newRE   = new MyRepeatedEntity();
                newRE.centroid = comp;
                newComp.Origin = comp;
                newComp.Name   = compName;
                newComp.IdCorrespondingNode = 0;
                newComp.RepeatedEntity      = newRE;


                newListOfComponetsNoInfo.Add(newComp);
            }


            AssemblyPatterns.KLFindPatternsOfComponents(newListOfComponetsNoInfo, listCentroidWordRF,
                                                        ref listPattern, ref listPattern2, ref fileOutput);
            //PatternComputationFunctions.GetAssemblyPatternsOfRepeatedElements(listOfMyListOfInstances, nodeAssembly,
            //    out listPattern, out listPattern2);


            //Console.WriteLine("Istanze trovate " + listOfMyListOfInstances.Count);
            //foreach (var inst in listOfMyListOfInstances)
            //{
            //    Console.WriteLine("Istanza di " + inst.Name + " trovata " + inst.ListOfMyComponent.Count + " volte");
            //}

            Console.WriteLine("Pattern trovati " + listPattern.Count);
            foreach (var patt in listPattern)
            {
                Console.WriteLine("Pattern di tipo " + patt.typeOfMyPattern + " formato da " + patt.listOfMyRCOfMyPattern.First().Name);
            }


            //Console.WriteLine("Ending.. nodi " + graph.VertexCount + " e archi " + graph.EdgeCount);

            /*
             * var fileName = Path.GetFileNameWithoutExtension(args[0]);
             * var storageGraph = new KLgraph.Graph(graph.Vertices.ToList(), graph.Edges.ToList());
             *
             * JsonSerializerSettings setting = new JsonSerializerSettings
             * {
             *  TypeNameHandling = TypeNameHandling.All,
             *  TypeNameAssemblyFormat = FormatterAssemblyStyle.Full
             * };
             *
             * var directoryOutput = Path.GetDirectoryName(args[1]);
             * var fileNameOutput = Path.GetFileNameWithoutExtension(args[1]);
             * //Console.WriteLine(directoryOutput);
             * //Console.WriteLine(fileNameOutput);
             *
             * SaveModel(JsonConvert.SerializeObject(storageGraph, setting), directoryOutput, fileNameOutput + ".json");
             * Console.WriteLine("JSON saved!");
             */
            //swApp.ExitApp();
        }