//--------------------------------------------------------------------------------------------------

        bool _MakeSolid(IShapeOperand sourceShape)
        {
            var sourceBRep = GetOperandBRep(0);

            if (sourceBRep == null)
            {
                return(false);
            }

            // Calculate Parameters
            Ax3 axis = _CalculateSolidAxis();

            var(interval, offset) = _CalculateParameters();

            // Build Transformed Shapes
            TopoDS_Compound resultShape = new TopoDS_Compound();
            var             builder     = new TopoDS_Builder();

            builder.MakeCompound(resultShape);

            for (var index = 0; index < Quantity; index++)
            {
                var angle     = (interval * index + offset).ToRad();
                var transform = Trsf.Identity;
                if (_KeepOrientation)
                {
                    // Translation transform
                    transform.SetTranslation(Pnt.Origin.Rotated(axis.Axis, angle).ToVec());
                }
                else
                {
                    // Rotation transform
                    transform.SetRotation(axis.Axis, angle);
                }

                var makeTransform = new BRepBuilderAPI_Transform(sourceBRep, transform);
                if (!makeTransform.IsDone())
                {
                    Messages.Error("Failed transforming shape.");
                    return(false);
                }
                builder.Add(resultShape, makeTransform.Shape());
            }

            // Finalize
            BRep = resultShape;
            return(true);
        }
Ejemplo n.º 2
0
        //--------------------------------------------------------------------------------------------------

        protected override bool MakeInternal(MakeFlags flags)
        {
            if (!Segments.Any() || !Points.Any())
            {
                var makeVertex = new BRepBuilderAPI_MakeVertex(Pnt.Origin);
                BRep      = makeVertex.Vertex();
                HasErrors = false;
                return(base.MakeInternal(flags));
            }

            // Create edges
            var freeSegmentEdges = new Dictionary <SketchSegment, TopoDS_Edge>();

            foreach (var segmentKvp in _Segments)
            {
                var segment = segmentKvp.Value;
                if (segment.IsAuxilliary)
                {
                    continue;
                }

                var segEdge = segment.MakeEdge(_Points);
                if (segEdge == null)
                {
                    Messages.Warning($"The segment {segmentKvp.Key} of type {segment.GetType().Name} failed creating an edge.");
                    continue;
                }
                freeSegmentEdges.Add(segment, segEdge);
                AddNamedSubshape("seg", segEdge, segmentKvp.Key);
            }

            // Create wires
            var wires = new List <TopoDS_Wire>();

            while (freeSegmentEdges.Any())
            {
                var nextSegmentEdge = freeSegmentEdges.First();
                var frontSegment    = nextSegmentEdge.Key;
                freeSegmentEdges.Remove(nextSegmentEdge.Key);

                var makeWire = new BRepBuilderAPI_MakeWire(nextSegmentEdge.Value);

                if ((frontSegment.StartPoint != -1) || (frontSegment.EndPoint != -1))
                {
                    var backSegment = frontSegment;
                    while (freeSegmentEdges.Any())
                    {
                        nextSegmentEdge = freeSegmentEdges.FirstOrDefault(kvp => kvp.Key.IsConnected(frontSegment));
                        if (nextSegmentEdge.Value != null)
                        {
                            frontSegment = nextSegmentEdge.Key;
                        }
                        else
                        {
                            nextSegmentEdge = freeSegmentEdges.FirstOrDefault(kvp => kvp.Key.IsConnected(backSegment));
                            if (nextSegmentEdge.Value != null)
                            {
                                backSegment = nextSegmentEdge.Key;
                            }
                            else
                            {
                                // disconnected segment
                                break;
                            }
                        }

                        makeWire.Add(nextSegmentEdge.Value);
                        freeSegmentEdges.Remove(nextSegmentEdge.Key);
                    }
                }

                // Get wire shape
                var wire = makeWire.Wire();
                if (wire == null)
                {
                    Messages.Error("Error when creating a wire.");
                    return(false);
                }

                wires.Add(wire);
            }

            // Create resulting shape
            var builder = new TopoDS_Builder();
            var shape   = new TopoDS_Compound();

            builder.MakeCompound(shape);

            foreach (var wire in wires)
            {
                builder.Add(shape, wire);
            }

            BRep = shape;

            return(base.MakeInternal(flags));
        }
Ejemplo n.º 3
0
        //--------------------------------------------------------------------------------------------------

        bool _MakeSolid(IShapeOperand sourceShape)
        {
            var sourceBRep = GetOperandBRep(0);

            if (sourceBRep == null)
            {
                return(false);
            }

            // Calculate Offsets
            Ax3 plane;

            switch (Plane)
            {
            case PlaneType.XY:
                plane = Ax3.XOY.Rotated(Ax1.OZ, _Rotation.ToRad());
                break;

            case PlaneType.ZX:
                plane = Ax3.ZOX.Rotated(Ax1.OY, _Rotation.ToRad());
                break;

            case PlaneType.YZ:
                plane = Ax3.YOZ.Rotated(Ax1.OX, _Rotation.ToRad());
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            var bbTransform = new Trsf(new Ax3(Ax2.XOY), plane);
            var extents     = sourceBRep.BoundingBox().Transformed(bbTransform).Extents();

            var offset    = Vec.Zero;
            var interval1 = plane.XDirection.ToVec() * _CalculateOffset(DistanceMode1, Quantity1, Distance1, extents.X);

            switch (_Alignment1)
            {
            case AlignmentMode.Center:
                offset += interval1 * (Quantity1 - 1) * -0.5;
                break;

            case AlignmentMode.Last:
                interval1 *= -1;
                break;
            }

            var interval2 = plane.YDirection.ToVec() * _CalculateOffset(DistanceMode2, Quantity2, Distance2, extents.Y);

            switch (_Alignment2)
            {
            case AlignmentMode.Center:
                offset += interval2 * (Quantity2 - 1) * -0.5;
                break;

            case AlignmentMode.Last:
                interval2 *= -1;
                break;
            }

            // Build Transformed Shapes
            TopoDS_Compound resultShape = new TopoDS_Compound();
            var             builder     = new TopoDS_Builder();

            builder.MakeCompound(resultShape);

            for (var index1 = 0; index1 < Quantity1; index1++)
            {
                for (var index2 = 0; index2 < Quantity2; index2++)
                {
                    if (_Border && index1 != 0 && index1 != Quantity1 - 1 &&
                        index2 != 0 && index2 != Quantity2 - 1)
                    {
                        continue; // Skip inner parts
                    }

                    var transform = new Trsf();
                    transform.SetTranslation(interval1 * index1 + interval2 * index2 + offset);
                    var makeTransform = new BRepBuilderAPI_Transform(sourceBRep, transform);
                    if (!makeTransform.IsDone())
                    {
                        Messages.Error("Failed transforming shape.");
                        return(false);
                    }
                    builder.Add(resultShape, makeTransform.Shape());
                }
            }

            // Finalize
            BRep = resultShape;
            return(true);
        }