예제 #1
0
        /// <summary>
        /// Create rounded chamfer in regular polygon sketch by base sketch,
        /// regular polygon parameters and base plane coordinates in plane
        /// </summary>
        /// <param name="doc3D">Kompas document 3D</param>
        /// <param name="doc3DPart">Kompas document 3D part with detail</param>
        /// <param name="regPolySketch">Sketch of regular polygon</param>
        /// <param name="regPolyParam">An object with parameters of regular polygon</param>
        /// <param name="basePlanePoint">Base plane point of regular polygon</param>
        /// <param name="directionType">Direction type</param>
        /// <returns>Entity of rounded chamfer or null in case of error</returns>
        public RoundedChamfer(KompasApplication kompasApp, RoundedChamferParameters figureParameters)
        {
            if (kompasApp == null ||
                figureParameters.Document3DPart == null ||
                figureParameters.RegularPolygonSketch == null ||
                figureParameters.RegularPolygonParameters == null
                )
            {
                LastErrorCode = ErrorCodes.ArgumentNull;
                return;
            }

            // KompasApplication kompasApp, ksPart doc3DPart, ksEntity regPolySketch, RegularPolygonParameter regPolyParam, KompasPoint2D basePlanePoint, Direction_Type directionType

            _figureParameters = figureParameters;

            _kompasApp = kompasApp;

            if (!DoubleValidator.Validate(_figureParameters.BasePlanePoint.X) ||
                !DoubleValidator.Validate(_figureParameters.BasePlanePoint.Y)
                )
            {
                LastErrorCode = ErrorCodes.DoubleValueValidationError;
                return;
            }
        }
예제 #2
0
        /// <summary>
        /// Create base of rounded chamfer
        /// </summary>
        /// <param name="figureParameters">Parameters of rounded chamfer</param>
        /// <returns>Extruded entity of base of rounded chamfer</returns>
        private ksEntity CreateBase(RoundedChamferParameters figureParameters)
        {
            // 1.1 Base of rounded chamfer
            var innerCircleSketch = new KompasSketch(figureParameters.Document3DPart, figureParameters.RegularPolygonSketch);

            if (innerCircleSketch.LastErrorCode != ErrorCodes.OK)
            {
                LastErrorCode = innerCircleSketch.LastErrorCode;
                return(null);
            }

            var innerCircleEdit = innerCircleSketch.BeginEntityEdit();

            if (innerCircleEdit == null)
            {
                LastErrorCode = innerCircleSketch.LastErrorCode;
                return(null);
            }

            if (innerCircleEdit.ksCircle(figureParameters.BasePlanePoint.X, figureParameters.BasePlanePoint.Y, _kompasApp.Parameters[1] / 2.0, 1) == 0)             // d
            {
                LastErrorCode = ErrorCodes.Document2DCircleCreatingError;
                return(null);
            }

            innerCircleSketch.EndEntityEdit();

            // 1.2 Hat rounded chamfer base extrusion
            var extrusionParameters  = new KompasExtrusionParameters(figureParameters.Document3DPart, Obj3dType.o3d_baseExtrusion, innerCircleSketch.Entity, figureParameters.Direction, _kompasApp.Parameters[4] * 0.16);
            var innerCircleExtrusion = new KompasExtrusion(extrusionParameters, ExtrusionType.ByEntity);             // Height of chamfer is 0.16 * H

            if (innerCircleExtrusion.LastErrorCode != ErrorCodes.OK)
            {
                LastErrorCode = innerCircleExtrusion.LastErrorCode;
                return(null);
            }

            innerCircleExtrusion.BaseFaceAreaState = KompasFaces.BaseFaceAreaState.BaseFaceAreaLower;
            var extruded = innerCircleExtrusion.ExtrudedEntity;

            if (extruded == null)
            {
                LastErrorCode = innerCircleExtrusion.LastErrorCode;
                return(null);
            }

            return(extruded);
        }
예제 #3
0
        /// <summary>
        /// Create screw hat with extrusion operation
        /// </summary>
        /// "regPoly" here is abbreviation of Regular Polygon
        /// Screw hat consists of base of hat (0.84 * H)
        /// and rounded chamfer on the top (0.16 * H)
        /// <returns>Extruded entity of hat for base part of screw</returns>
        private ksEntity CreateHat()
        {
            // 0.1 Create muffler, which base point is (W3 / 5, W3 / 5)
            var basePoint         = -(_kompasApp.Parameters[0] / 5.0);
            var mufflerParameters = new MufflerParameters();

            mufflerParameters.Document3DPart = _kompasApp.ScrewPart;
            mufflerParameters.Direction      = Direction_Type.dtNormal;
            mufflerParameters.BasePlaneAxis  = Obj3dType.o3d_planeYOZ;
            mufflerParameters.BasePlanePoint = new KompasPoint2D(basePoint, basePoint);

            var mufflerManager = new Muffler(_kompasApp, mufflerParameters);

            if (mufflerManager.LastErrorCode != ErrorCodes.OK)
            {
                LastErrorCode = mufflerManager.LastErrorCode;
                return(null);
            }

            var mufflerExtrusion = mufflerManager.Extrusion;

            if (mufflerExtrusion == null)
            {
                LastErrorCode = mufflerManager.LastErrorCode;
                return(null);
            }

            // 1.1 Hat sketch
            var regPolySketch = new KompasSketch(_kompasApp.ScrewPart, Obj3dType.o3d_planeYOZ);

            if (regPolySketch.LastErrorCode != ErrorCodes.OK)
            {
                LastErrorCode = regPolySketch.LastErrorCode;
                return(null);
            }

            var regPolySketchEdit = regPolySketch.BeginEntityEdit();

            if (regPolySketchEdit == null)
            {
                LastErrorCode = regPolySketch.LastErrorCode;
                return(null);
            }

            // Regular polygon center point
            var regPolyPoint = new KompasPoint2D(0, 0);
            // Regular polygon is base of hat
            var regPolyParam = new RegularPolygonParameter(_kompasApp, 6, _kompasApp.Parameters[0] / 2.0, regPolyPoint);              // W3

            if (regPolySketchEdit.ksRegularPolygon(regPolyParam.FigureParam, 0) == 0)
            {
                LastErrorCode = ErrorCodes.Document2DRegPolyCreatingError;
                return(null);
            }

            regPolySketch.EndEntityEdit();

            // 1.2 Hat entity extrusion
            // Screw hat height is equal to nut height
            var extrusionParameters = new KompasExtrusionParameters(_kompasApp.ScrewPart, Obj3dType.o3d_baseExtrusion, regPolySketch.Entity, Direction_Type.dtReverse, _kompasApp.Parameters[4] * 0.84);
            var regPolyExtrusion    = new KompasExtrusion(extrusionParameters, ExtrusionType.ByEntity);          // 0.84 * H

            if (regPolyExtrusion.LastErrorCode != ErrorCodes.OK)
            {
                LastErrorCode = regPolyExtrusion.LastErrorCode;
                return(null);
            }

            /* Main base face area is lower than parallel base face
             * because of muffler partially overlaps main base face area,
             * but not overlaps parallel base face area.
             */
            regPolyExtrusion.BaseFaceAreaState = KompasFaces.BaseFaceAreaState.BaseFaceAreaLower;
            var extruded = regPolyExtrusion.ExtrudedEntity;

            if (extruded == null)
            {
                LastErrorCode = regPolyExtrusion.LastErrorCode;
                return(null);
            }

            // 0.2 Delete muffler
            if (!mufflerManager.DeleteDetail())
            {
                LastErrorCode = mufflerManager.LastErrorCode;
                return(null);
            }

            // 1.3 Rounded chamfer in hat
            var roundedChamferParameters = new RoundedChamferParameters();

            roundedChamferParameters.Document3DPart           = _kompasApp.ScrewPart;
            roundedChamferParameters.RegularPolygonSketch     = regPolySketch.Entity;
            roundedChamferParameters.RegularPolygonParameters = regPolyParam;
            roundedChamferParameters.BasePlanePoint           = new KompasPoint2D(0.0, 0.0);
            roundedChamferParameters.Direction = Direction_Type.dtNormal;
            var roundedChamferManager = new RoundedChamfer(_kompasApp, roundedChamferParameters);

            if (!roundedChamferManager.CreateDetail())
            {
                LastErrorCode = roundedChamferManager.LastErrorCode;
                return(null);
            }

            return(extruded);
        }
예제 #4
0
        /// <summary>
        /// Create rounded chamfers inside nut
        /// </summary>
        /// <param name="nutBasePoint">Nut base point</param>
        /// <param name="regPolyParam">Regular polygon parameters</param>
        /// <param name="nutBaseEntities">Nut base entities: sketch and extrusion</param>
        /// <returns>Chamfers entities from left and right sides of nut</returns>
        private ksEntity[] CreateNutChamferEntities(KompasPoint3D nutBasePoint, RegularPolygonParameter regPolyParam, ksEntity[] nutBaseEntities)
        {
            // 1.3 Nut rounded chamfers creation:
            // 1.3.1 Right rounded chamfer
            var rightChamferPoint = new KompasPoint2D(Math.Abs(nutBasePoint.Y), Math.Abs(nutBasePoint.Z));

            // Nut width is equal to W3 (screw hat width)
            var rightChamferRegPoly = new RegularPolygonParameter(_kompasApp, 6, _kompasApp.Parameters[0] / 2.0, rightChamferPoint);

            if (rightChamferRegPoly == null)
            {
                LastErrorCode = rightChamferRegPoly.LastErrorCode;
                return(null);
            }

            var rightChamferSketch = new KompasSketch(_kompasApp.NutPart, nutBaseEntities[1]);

            if (rightChamferSketch.LastErrorCode != ErrorCodes.OK)
            {
                LastErrorCode = rightChamferSketch.LastErrorCode;
                return(null);
            }

            var rightChamferParameters = new RoundedChamferParameters();

            rightChamferParameters.Document3DPart           = _kompasApp.NutPart;
            rightChamferParameters.RegularPolygonSketch     = rightChamferSketch.Entity;
            rightChamferParameters.RegularPolygonParameters = rightChamferRegPoly;
            rightChamferParameters.BasePlanePoint           = rightChamferPoint;
            rightChamferParameters.Direction = Direction_Type.dtNormal;

            var rightChamferManager = new RoundedChamfer(_kompasApp, rightChamferParameters);

            if (!rightChamferManager.CreateDetail())
            {
                LastErrorCode = rightChamferManager.LastErrorCode;
                return(null);
            }

            if (rightChamferManager.LastErrorCode != ErrorCodes.OK)
            {
                LastErrorCode = rightChamferManager.LastErrorCode;
                return(null);
            }

            var rightChamferEntity = rightChamferManager.Entity;

            if (rightChamferEntity == null)
            {
                LastErrorCode = rightChamferManager.LastErrorCode;
                return(null);
            }

            // 1.3.2 Left rounded chamfer
            var leftChamferParameters = new RoundedChamferParameters();

            leftChamferParameters.Document3DPart           = _kompasApp.NutPart;
            leftChamferParameters.RegularPolygonSketch     = nutBaseEntities[0];
            leftChamferParameters.RegularPolygonParameters = regPolyParam;
            leftChamferParameters.BasePlanePoint           = new KompasPoint2D(nutBasePoint.Y, nutBasePoint.Z);
            leftChamferParameters.Direction = Direction_Type.dtNormal;

            var leftChamferManager = new RoundedChamfer(_kompasApp, leftChamferParameters);

            if (!leftChamferManager.CreateDetail())
            {
                LastErrorCode = leftChamferManager.LastErrorCode;
                return(null);
            }

            if (leftChamferManager.LastErrorCode != ErrorCodes.OK)
            {
                LastErrorCode = leftChamferManager.LastErrorCode;
                return(null);
            }

            var leftChamferEntity = leftChamferManager.Entity;

            if (leftChamferEntity == null)
            {
                LastErrorCode = leftChamferManager.LastErrorCode;
                return(null);
            }

            return(new ksEntity[2] {
                leftChamferEntity, rightChamferEntity
            });
        }
예제 #5
0
        /// <summary>
        /// Create section operation of rounded chamfer
        /// </summary>
        /// <returns>true if operation successful; false in case of error</returns>
        private bool CreateSection(RoundedChamferParameters figureParameters, ksEntity baseOfChamfer)
        {
            // 1.3 Hat rounded chamfer sketches for section operation:
            // 1.3.1 Extra inner circle
            var extraInnerCircleSketch = new KompasSketch(figureParameters.Document3DPart, baseOfChamfer);

            if (extraInnerCircleSketch.LastErrorCode != ErrorCodes.OK)
            {
                LastErrorCode = extraInnerCircleSketch.LastErrorCode;
                return(false);
            }

            var extraInnerCircleEdit = extraInnerCircleSketch.BeginEntityEdit();

            if (extraInnerCircleEdit == null)
            {
                LastErrorCode = extraInnerCircleSketch.LastErrorCode;
                return(false);
            }

            if (extraInnerCircleEdit.ksCircle(figureParameters.BasePlanePoint.X, figureParameters.BasePlanePoint.Y, _kompasApp.Parameters[1] / 2.0, 1) == 0)             // d
            {
                LastErrorCode = extraInnerCircleSketch.LastErrorCode;
                return(false);
            }

            extraInnerCircleSketch.EndEntityEdit();

            // 1.3.3.2 Extra regular polygon
            var extraRegPolySketch = new KompasSketch(figureParameters.Document3DPart, figureParameters.RegularPolygonSketch);

            if (extraRegPolySketch.LastErrorCode != ErrorCodes.OK)
            {
                LastErrorCode = extraRegPolySketch.LastErrorCode;
                return(false);
            }

            var extraRegPolyEdit = extraRegPolySketch.BeginEntityEdit();

            if (extraRegPolyEdit == null)
            {
                LastErrorCode = extraRegPolySketch.LastErrorCode;
                return(false);
            }

            if (extraRegPolyEdit.ksRegularPolygon(figureParameters.RegularPolygonParameters.FigureParam, 0) == 0)
            {
                LastErrorCode = extraRegPolySketch.LastErrorCode;
                return(false);
            }

            extraRegPolySketch.EndEntityEdit();

            // 1.3.4 Hat rounded chamfer section operation
            var screwChamferSketches = (ksEntityCollection)_kompasApp.Document3D.EntityCollection((short)Obj3dType.o3d_sketch);

            screwChamferSketches.Clear();
            screwChamferSketches.Add(extraInnerCircleSketch.Entity);
            screwChamferSketches.Add(extraRegPolySketch.Entity);
            screwChamferSketches.refresh();

            if (screwChamferSketches == null)
            {
                LastErrorCode = ErrorCodes.ArgumentNull;
                return(false);
            }

            var extrusionParameters   = new KompasExtrusionParameters(figureParameters.Document3DPart, Obj3dType.o3d_baseLoft, null, screwChamferSketches);
            var screwChamferExtrusion = new KompasExtrusion(extrusionParameters, ExtrusionType.BySketchesCollection);

            if (screwChamferExtrusion.LastErrorCode != ErrorCodes.OK)
            {
                LastErrorCode = screwChamferExtrusion.LastErrorCode;
                return(false);
            }

            if (extraInnerCircleSketch.Entity == null)
            {
                LastErrorCode = ErrorCodes.ArgumentNull;
                return(false);
            }

            Entity = extraInnerCircleSketch.Entity;

            return(true);
        }