예제 #1
0
        public static Node TryAutoGroup(Document document, Node addedNewShape)
        {
            var     sketchNode = FindSketchNode(addedNewShape);
            Point3D?firstPoint = null, lastPoint = null;

            GeomUtils.GetExtremasPoints(addedNewShape, ref firstPoint, ref lastPoint);
            if (firstPoint == null || lastPoint == null)
            {
                return(null);
            }
            firstPoint = new Point3D(firstPoint.Value.GpPnt.Transformed(sketchNode.Get <TransformationInterpreter>().CurrTransform));
            lastPoint  = new Point3D(lastPoint.Value.GpPnt.Transformed(sketchNode.Get <TransformationInterpreter>().CurrTransform));
            var connections = new AutoGroupConnectionGraph();

            connections.BuildConnectedLinks(document, addedNewShape.Index);
            var addedEntiy = new SceneSelectedEntity {
                Node = addedNewShape, ShapeType = TopAbsShapeEnum.TopAbs_WIRE
            };
            var groupCandidates = new List <SceneSelectedEntity> {
                addedEntiy
            };

            var interpreter = addedNewShape.Get <TransformationInterpreter>();

            if (interpreter == null)
            {
                return(null);
            }

            return(CandidateProcessing(document, groupCandidates,
                                       (Point3D)firstPoint,
                                       (Point3D)lastPoint,
                                       connections, sketchNode));
        }
예제 #2
0
        private static void BuildShapeList(IList <SceneSelectedEntity> groupCandidates,
                                           AutoGroupConnectionGraph connectionGraph, int topNode, Node root,
                                           Point3D currentPoint, ICollection <Node> shapeList)
        {
            var possibleConnectios = connectionGraph.CanConnect[topNode].Keys;

            foreach (var shapeNodeIndex in possibleConnectios)
            {
                var shapeNode   = root[shapeNodeIndex];
                var isCandidate = IsCandidate(groupCandidates, currentPoint, shapeNode);
                if (isCandidate)
                {
                    shapeList.Add(shapeNode);
                }
            }
        }
예제 #3
0
        private static Node CandidateProcessing(Document document, IList <SceneSelectedEntity> groupCandidates,
                                                Point3D currentPoint, Point3D endPoint,
                                                AutoGroupConnectionGraph connectionGraph, Node sketchNode)
        {
            var shapeList = new List <Node>();
            var root      = document.Root;
            var topNode   = groupCandidates[groupCandidates.Count - 1].Node.Index;

            if (!connectionGraph.CanConnect.ContainsKey(topNode))
            {
                return(null);
            }
            BuildShapeList(groupCandidates, connectionGraph, topNode, root, currentPoint, shapeList);

            foreach (var shapeNode in shapeList)
            {
                var nextPoint = GetNextPoint(shapeNode, currentPoint, sketchNode);
                if (nextPoint == null)
                {
                    continue;
                }
                var entity = new SceneSelectedEntity {
                    Node = shapeNode, ShapeType = TopAbsShapeEnum.TopAbs_WIRE
                };
                groupCandidates.Add(entity);
                if (((Point3D)nextPoint).IsEqual(endPoint))
                {
                    var indexes = groupCandidates.Select(candidate => candidate.Node.Index).ToList();
                    if (!indexesList.Any(item => new HashSet <int>(item).SetEquals(indexes)))
                    {
                        indexesList.Add(indexes);
                    }
                }
                else
                {
                    CandidateProcessing(document, groupCandidates, (Point3D)nextPoint, endPoint,
                                        connectionGraph, sketchNode);
                }
                groupCandidates.RemoveAt(groupCandidates.Count - 1);
            }
            return(null);
        }