Ejemplo n.º 1
0
        //--------------------------------------------------------------------------------------------------

        bool _Make3D()
        {
            // We work with solid shape and face as source
            var solid = GetOperandBRep(0);

            if (solid == null || _Face == null)
            {
                return(false);
            }

            // If extrusion vector has zero length, just copy the source shape converted to faces
            if (Depth == 0)
            {
                BRep = solid;
                return(base.MakeInternal(MakeFlags.NoTransformation));
            }

            // Get face
            var face = GetOperandFace(0, _Face);

            if (face == null)
            {
                Messages.Error("The selected face is lost, please reselect.");
                return(false);
            }

            // Generate direction vector
            var direction = FaceAlgo.GetFaceCenterNormal(face).Direction;

            // Do it!
            var makePrism = new BRepFeat_MakePrism(solid, face, face, direction, Depth > 0 ? 1 : 0, false);

            makePrism.Perform(Depth);
            if (!makePrism.IsDone())
            {
                Messages.Error("Failed extruding the selected face with this parameters.");
                return(false);
            }

            var bRep = makePrism.Shape();

            if (bRep.Solids().Count == 0)
            {
                Messages.Error("Failed extruding the selected face with this parameters.");
                return(false);
            }

            UpdateModifiedSubshapes(solid, makePrism);

            // Get final shape
            BRep = bRep;
            return(true);
        }
Ejemplo n.º 2
0
        //--------------------------------------------------------------------------------------------------

        #endregion

        #region Make

        protected override bool MakeInternal(MakeFlags flags)
        {
            ClearSubshapeLists();

            // Currently we work with 2 source shape only
            if ((Operands.Count != 2) || (_Face == null))
                return false;

            // Get Target
            var targetShape = GetOperandBRep(0);
            if (targetShape == null)
                return false;

            var faceShape = GetOperandFace(0, _Face);
            if (faceShape == null)
                return false;

            if (!FaceAlgo.GetCenteredPlaneFromFace(faceShape, out var facePlane))
            {
                Messages.Error("Target face is not planar.");
                return false;
            }

            var baseFacesShape = GetOperand2DFaces(1, facePlane);
            if (baseFacesShape == null)
            {
                Messages.Error("Cannot create faces from 2D operand.");
                return false;
            }

            // If extrusion vector has zero length, or the shape is empty, just copy the source shape
            if (Depth == 0 || !baseFacesShape.Faces().Any())
            {
                return Skip();
            }

            // Do it!
            if (DraftAngle != 0)
            {
                // DraftPrism needs to change the sign of depth and draft angle
                var sign = _Mode == ImprintMode.Raise ? 1 : -1;

                // Make with draft 
                var singleBaseFaces = baseFacesShape.Faces();
                foreach (var singleBaseFace in singleBaseFaces)
                {
                    var makePrism = new BRepFeat_MakeDPrism(targetShape, singleBaseFace, faceShape, _DraftAngle.ToRad()*sign, _Mode == ImprintMode.Raise ? 1 : 0, true);
                    if (_Mode == ImprintMode.Cutout)
                        makePrism.PerformThruAll();
                    else
                        makePrism.Perform(Depth*sign);

                    UpdateModifiedSubshapes(targetShape, makePrism);
                    UpdateModifiedSubshapes(singleBaseFace, makePrism);
                    targetShape = makePrism.Shape();
                }
                BRep = targetShape;
            }
            else
            {
                // Generate direction
                var direction = _Mode == ImprintMode.Raise ? facePlane.Axis.Direction : facePlane.Axis.Direction.Reversed();

                // Make w/o draft
                var makePrism = new BRepFeat_MakePrism(targetShape, baseFacesShape, faceShape, direction, _Mode == ImprintMode.Raise ? 1 : 0, true);
                if (_Mode == ImprintMode.Cutout)
                    makePrism.PerformThruAll();
                else
                    makePrism.Perform(Depth);

                UpdateModifiedSubshapes(targetShape, makePrism);
                UpdateModifiedSubshapes(baseFacesShape, makePrism);
                BRep = makePrism.Shape();
            }

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

        #endregion

        #region Make

        protected override bool MakeInternal(MakeFlags flags)
        {
            ClearSubshapeLists();

            // Currently we work with 2 source shape only
            if ((Operands.Count != 2) || (_Face == null))
            {
                return(false);
            }

            // Get Target
            var targetShape = GetOperandBRep(0);

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

            var faceShape = GetOperandFace(0, _Face);

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

            if (!FaceAlgo.GetCenteredPlaneFromFace(faceShape, out var facePlane))
            {
                Messages.Error("Target face is not planar.");
                return(false);
            }

            var baseFacesShape = GetOperand2DFaces(1, facePlane);

            if (baseFacesShape == null)
            {
                Messages.Error("Cannot create faces from 2D operand.");
                return(false);
            }

            // Check if we have inner wires (holes), the algo will not work with them when using BRepFeat_MakeDPrism
            bool useDraft = DraftAngle != 0;

            if (useDraft)
            {
                foreach (var face in baseFacesShape.Faces())
                {
                    if (face.Wires().Count > 1)
                    {
                        Messages.Warning("Imprinting a face with holes and draft angle isn't supported. Remove holes and imprint them in a second imprint.");
                        useDraft = false;
                        break;
                    }
                }
            }

            // If extrusion vector has zero length, or the shape is empty, just copy the source shape
            if (Depth == 0 || !baseFacesShape.Faces().Any())
            {
                return(Skip());
            }

            // Do it!
            if (useDraft)
            {
                // DraftPrism needs to change the sign of depth and draft angle
                var sign = _Mode == ImprintMode.Raise ? 1 : -1;

                // Make with draft
                var singleBaseFaces = baseFacesShape.Faces();
                foreach (var singleBaseFace in singleBaseFaces)
                {
                    var makePrism = new BRepFeat_MakeDPrism(targetShape, singleBaseFace, faceShape, _DraftAngle.ToRad() * sign, _Mode == ImprintMode.Raise ? 1 : 0, true);
                    if (_Mode == ImprintMode.Cutout)
                    {
                        makePrism.PerformThruAll();
                    }
                    else
                    {
                        makePrism.Perform(Depth * sign);
                    }

                    UpdateModifiedSubshapes(targetShape, makePrism);
                    UpdateModifiedSubshapes(singleBaseFace, makePrism);
                    targetShape = makePrism.Shape();
                }
                BRep = targetShape;
            }
            else
            {
                // Generate direction
                var direction = _Mode == ImprintMode.Raise ? facePlane.Axis.Direction : facePlane.Axis.Direction.Reversed();

                // Make w/o draft
                var makePrism = new BRepFeat_MakePrism(targetShape, baseFacesShape, faceShape, direction, _Mode == ImprintMode.Raise ? 1 : 0, true);
                if (_Mode == ImprintMode.Cutout)
                {
                    makePrism.PerformThruAll();
                }
                else
                {
                    makePrism.Perform(Depth);
                }

                UpdateModifiedSubshapes(targetShape, makePrism);
                UpdateModifiedSubshapes(baseFacesShape, makePrism);
                BRep = makePrism.Shape();
            }

            return(base.MakeInternal(flags));
        }