Exemplo n.º 1
0
        //--------------------------------------------------------------------------------------------------

        protected TopoDS_Edge GetOperandEdge(int operandIndex, SubshapeReference edgeRef, TopoDS_Face forFace = null)
        {
            var operand = GetOperand(operandIndex);

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

            // Find target edge
            var edges = operand.FindSubshape(edgeRef, GetCoordinateSystem());

            if (edges == null || edges.Count == 0)
            {
                Messages.Error("The edge index is invalid and must be re-selected.");
                return(null);
            }

            if (forFace == null)
            {
                return(edges[0].ToEdge());
            }

            // Find the proper oriented for the given face
            return(forFace.Edges().Find(e => e.IsSame(edges[0])));
        }
        //--------------------------------------------------------------------------------------------------

        public void RemoveEdge(SubshapeReference reference)
        {
            if (!_Edges.Contains(reference))
            {
                return;
            }
            Edges = _Edges.Where(sr => sr != reference).ToArray();
        }
Exemplo n.º 3
0
        //--------------------------------------------------------------------------------------------------

        public override List <TopoDS_Shape> FindSubshape(SubshapeReference reference, Ax3?targetFrame)
        {
            if (Operands.Count > 1 && Operands[1] is BodyShapeOperand)
            {
                return((Operands[1] as BodyShapeOperand)?.Shape?.FindSubshape(reference, null));
            }

            return(base.FindSubshape(reference, null));
        }
Exemplo n.º 4
0
        //--------------------------------------------------------------------------------------------------

        public static Imprint Create(Body body, SubshapeReference faceRef, Shape sketch)
        {
            Debug.Assert(body != null);
            var modifierShape = new Imprint(){
                _Face = faceRef
            };
            modifierShape.AddOperand(sketch);
            body.AddShape(modifierShape);

            return modifierShape;
        }
Exemplo n.º 5
0
        //--------------------------------------------------------------------------------------------------

        public static Imprint Create(Body body, SubshapeReference faceRef)
        {
            var face = body?.Shape.FindSubshape(faceRef, null).FirstOrDefault()?.ToFace();
            if (face == null)
                return null;

            if (!FaceAlgo.GetCenteredPlaneFromFace(face, out var plane))
            {
                return null;
            }
            return Create(body, faceRef, new Sketch() {Body = body});
        }
        //--------------------------------------------------------------------------------------------------

        public void AddEdge(SubshapeReference reference)
        {
            if (_Edges.Contains(reference))
            {
                return;
            }
            var newEdges = new SubshapeReference[_Edges.Length + 1];

            _Edges.CopyTo(newEdges, 0);
            newEdges[newEdges.Length - 1] = reference;
            Edges = newEdges;
        }
Exemplo n.º 7
0
        //--------------------------------------------------------------------------------------------------

        public static UnfoldSheet Create(Body targetBody, SubshapeReference startFace = null)
        {
            Debug.Assert(targetBody != null);

            var unfoldSheet = new UnfoldSheet()
            {
                _StartFace = startFace
            };

            targetBody.AddShape(unfoldSheet);

            return(unfoldSheet);
        }
        //--------------------------------------------------------------------------------------------------

        public IEnumerable <TopoDS_Edge> GetOcEdges(SubshapeReference edgeRef)
        {
            var edgeList = Operands[0].FindSubshape(edgeRef, GetCoordinateSystem());

            if (edgeList == null)
            {
                yield break;
            }

            foreach (var edge in edgeList.Select(shape => shape.ToEdge()))
            {
                yield return(edge);
            }
        }
Exemplo n.º 9
0
        //--------------------------------------------------------------------------------------------------

        public static Mirror Create(Body targetBody, SubshapeReference mirrorEdgeOrFace)
        {
            Debug.Assert(targetBody != null);
            Debug.Assert(mirrorEdgeOrFace != null);

            var mirror = new Mirror()
            {
                _Mode           = MirrorMode.EdgeOrFace,
                _ReferenceShape = mirrorEdgeOrFace
            };

            targetBody.AddShape(mirror);

            return(mirror);
        }
Exemplo n.º 10
0
        //--------------------------------------------------------------------------------------------------

        public static Extrude Create(Body body, SubshapeReference faceRef)
        {
            Debug.Assert(body != null);
            Debug.Assert(faceRef != null);
            Debug.Assert(body.Shape.ShapeType == ShapeType.Solid);

            var extrude = new Extrude
            {
                Face = faceRef
            };

            body.AddShape(extrude);

            return(extrude);
        }
Exemplo n.º 11
0
        //--------------------------------------------------------------------------------------------------

        public static Taper Create(Body targetBody, SubshapeReference face, SubshapeReference baseEdgeOrVertex, double angle)
        {
            Debug.Assert(targetBody != null);

            var taper = new Taper()
            {
                _Face             = face,
                _BaseEdgeOrVertex = baseEdgeOrVertex,
                _Angle            = angle
            };

            targetBody.AddShape(taper);

            taper.CalculateBaseParameter(0.5);

            return(taper);
        }
Exemplo n.º 12
0
        //--------------------------------------------------------------------------------------------------

        public static FlangeSheet Create(Body targetBody, SubshapeReference face, double angle = 90.0, double length = 10.0, double radius = 0.5)
        {
            Debug.Assert(targetBody != null);
            Debug.Assert(face != null);

            var flangeSheet = new FlangeSheet()
            {
                _Face   = face,
                _Angle  = angle,
                _Length = length,
                _Radius = radius
            };

            targetBody.AddShape(flangeSheet);

            return(flangeSheet);
        }
Exemplo n.º 13
0
        //--------------------------------------------------------------------------------------------------

        protected TopoDS_Face GetOperandFace(int operandIndex, SubshapeReference faceRef)
        {
            var operand = GetOperand(operandIndex);

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

            // Find target face
            var faces = operand.FindSubshape(faceRef, GetCoordinateSystem());

            if (faces == null || faces.Count == 0)
            {
                Messages.Error("The face index is invalid and must be re-selected.");
                return(null);
            }

            return(faces[0].ToFace());
        }
Exemplo n.º 14
0
        //--------------------------------------------------------------------------------------------------

        protected TopoDS_Vertex GetOperandVertex(int operandIndex, SubshapeReference vertexRef)
        {
            var operand = GetOperand(operandIndex);

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

            // Find target vertex
            var vertices = operand.FindSubshape(vertexRef, GetCoordinateSystem());

            if (vertices == null || vertices.Count == 0)
            {
                Messages.Error("The vertex index is invalid and must be re-selected.");
                return(null);
            }

            return(vertices[0].ToVertex());
        }
        //--------------------------------------------------------------------------------------------------

        public void RemoveAllEdges()
        {
            Edges = new SubshapeReference[0];
        }
Exemplo n.º 16
0
        //--------------------------------------------------------------------------------------------------

        public virtual List <TopoDS_Shape> FindSubshape(SubshapeReference reference, Ax3?targetFrame)
        {
            if (reference.Index < 0)
            {
                return(null);
            }

            if (!Guid.Equals(reference.ShapeId))
            {
                return(null);
            }

            EnsureHistory();

            // Named subshape?
            if (!reference.Name.IsNullOrEmpty())
            {
                var namedSubshapeIndex = _NamedSubshapes.FindIndex(ns => ns.Type == reference.Type && ns.Name == reference.Name && ns.Index == reference.Index);
                if (namedSubshapeIndex >= 0)
                {
                    return(new List <TopoDS_Shape>(1)
                    {
                        _NamedSubshapes[namedSubshapeIndex].Shape
                    });
                }
                return(null);
            }

            // Search in shape
            var ocShape = GetBRep();

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

            switch (reference.Type)
            {
            case SubshapeType.Edge:
                var edges = BRep.Edges();     // Get oriented one
                if (reference.Index < edges.Count)
                {
                    return(new List <TopoDS_Shape>(1)
                    {
                        edges[reference.Index]
                    });
                }
                break;

            case SubshapeType.Face:
                var faces = BRep.Faces();
                if (reference.Index < faces.Count)
                {
                    return new List <TopoDS_Shape>(1)
                           {
                               faces[reference.Index]
                           }
                }
                ;
                break;

            case SubshapeType.Vertex:
                var vertices = BRep.Vertices();
                if (reference.Index < vertices.Count)
                {
                    return new List <TopoDS_Shape>(1)
                           {
                               vertices[reference.Index]
                           }
                }
                ;
                break;
            }

            return(null);
        }
Exemplo n.º 17
0
        //--------------------------------------------------------------------------------------------------

        public override List <TopoDS_Shape> FindSubshape(SubshapeReference reference, Ax3?targetFrame)
        {
            if (Guid.Equals(reference.ShapeId))
            {
                return(base.FindSubshape(reference, targetFrame));
            }

            foreach (var operand in Operands)
            {
                var subshapes = operand?.FindSubshape(reference, GetCoordinateSystem());
                if (subshapes == null)
                {
                    continue;
                }

                EnsureHistory();
                if (!IsValid)
                {
                    return(null);
                }

                // Do we have modified this shape?
                var mods = _ModifiedShapes
                           .Where(kvp => subshapes.ContainsSame(kvp.Key))
                           .SelectMany(kvp => kvp.Value).ToList();
                if (mods.Count > 0)
                {
                    subshapes = mods;
                }

                // Unmodified, find in current shape
                var currents = new List <TopoDS_Shape>();
                switch (reference.Type)
                {
                case SubshapeType.Vertex:
                    var vertices = BRep.Vertices();
                    foreach (var shape in subshapes)
                    {
                        int sameIndex = vertices.IndexOfSame(shape);
                        if (sameIndex >= 0)
                        {
                            currents.Add(vertices[sameIndex]);
                        }
                    }
                    break;

                case SubshapeType.Edge:
                    var edges = BRep.Edges();
                    foreach (var shape in subshapes)
                    {
                        int sameIndex = edges.IndexOfSame(shape);
                        if (sameIndex >= 0)
                        {
                            currents.Add(edges[sameIndex]);
                        }
                    }
                    break;

                case SubshapeType.Face:
                    var faces = BRep.Faces();
                    foreach (var shape in subshapes)
                    {
                        int sameIndex = faces.IndexOfSame(shape);
                        if (sameIndex >= 0)
                        {
                            currents.Add(faces[sameIndex]);
                        }
                    }
                    break;
                }

                if (currents.Count > 0)
                {
                    return(currents);
                }
                return(null);
            }
            return(null);
        }