Пример #1
0
        //--------------------------------------------------------------------------------------------------

        protected TopoDS_Shape GetOperand2DFaces(int operandIndex, Pln?boundToPlane)
        {
            if (boundToPlane.HasValue)
            {
                GetOperand(operandIndex)?.BindToPlane(GetCoordinateSystem(), this, boundToPlane);
            }

            var sourceBrep = GetOperandBRep(operandIndex);

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

            // Check if we already have faces
            var exp = new TopExp_Explorer(sourceBrep, TopAbs_ShapeEnum.TopAbs_FACE, TopAbs_ShapeEnum.TopAbs_SHAPE);

            if (exp.More())
            {
                return(sourceBrep);
            }

            var baseFacesShape = TopoUtils.CreateFacesFromWires(sourceBrep, Pln.XOY);

            if (boundToPlane != null && baseFacesShape != null)
            {
                var trsf = new Trsf(boundToPlane.Value.Rotation(), boundToPlane.Value.Location.ToVec());
                baseFacesShape = baseFacesShape.Moved(new TopLoc_Location(trsf));
            }

            return(baseFacesShape);
        }
Пример #2
0
        //--------------------------------------------------------------------------------------------------

        TopoDS_Shape _CreateProfile(TopoDS_Edge firstSpineEdge)
        {
            var firstSpineCurve = firstSpineEdge.Curve(out double firstParam, out double secondParam);

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

            Pnt location    = default;
            Vec edgeTangent = default;

            firstSpineCurve.D1(firstParam, ref location, ref edgeTangent);
            Pln plane = new Pln(location, edgeTangent.ToDir());

            // Custom sketch
            if (_Profile == ProfileType.Custom)
            {
                return(_CreateProfileFromSketch(plane));
            }

            // Presets
            var edges = _CreateProfileEdges(plane, _SizeX * 0.5, _SizeY * 0.5);

            if (_Debug_WriteoutProfile)
            {
                TopoDS_Builder  builder  = new();
                TopoDS_Compound compound = new();
                builder.MakeCompound(compound);
                foreach (var edge in edges)
                {
                    builder.Add(compound, edge);
                }
                File.WriteAllBytes(@"_Debug_PipeProfile.brep", BRepExchange.WriteASCII(compound, false));
            }

            BRepBuilderAPI_MakeWire wireMaker = new();

            foreach (var edge in _CreateProfileEdges(plane, _SizeX * 0.5, _SizeY * 0.5))
            {
                wireMaker.Add(edge);
            }
            TopoDS_Shape result = wireMaker.Wire();

            if (_Profile == ProfileType.HollowCircle ||
                _Profile == ProfileType.HollowRectangle)
            {
                var innerSizeX = _SizeX * 0.5 - _Thickness;
                var innerSizeY = _SizeY * 0.5 - _Thickness;
                if (innerSizeX > 0 && (_Flags.HasFlag(PipeFlags.SymmetricProfile) || innerSizeY > 0))
                {
                    TopoDS_Builder  builder  = new();
                    TopoDS_Compound compound = new();
                    builder.MakeCompound(compound);
                    builder.Add(compound, result);

                    wireMaker = new();
                    foreach (var edge in _CreateProfileEdges(plane, innerSizeX, innerSizeY))
                    {
                        wireMaker.Add(edge);
                    }
                    builder.Add(compound, wireMaker.Wire());
                    result = compound;
                }
            }

            var face = TopoUtils.CreateFacesFromWires(result, plane);

            return(face);
        }