Пример #1
0
        /// <summary>
        /// Muffler manager constructor
        /// </summary>
        /// <param name="figureParameters">Parameters of muffler</param>
        /// <param name="kompasApp">Kompas application specimen</param>
        /// <param name="basePlane">Base plane of muffler, by default is null</param>
        public Muffler(KompasApplication kompasApp, MufflerParameters figureParameters, ksEntity basePlane = null)
        {
            if (kompasApp == null ||
                figureParameters.Document3DPart == null ||
                figureParameters.BasePlanePoint.LastErrorCode != ErrorCodes.OK ||
                !(figureParameters.BasePlaneAxis == Obj3dType.o3d_planeXOY ||
                  figureParameters.BasePlaneAxis == Obj3dType.o3d_planeXOZ ||
                  figureParameters.BasePlaneAxis == Obj3dType.o3d_planeYOZ) ||
                !DoubleValidator.Validate(figureParameters.BasePlanePoint.X) ||
                !DoubleValidator.Validate(figureParameters.BasePlanePoint.Y)
                )
            {
                LastErrorCode = ErrorCodes.ArgumentNull;
                return;
            }
            if (!(figureParameters.Direction == Direction_Type.dtNormal ||
                  figureParameters.Direction == Direction_Type.dtReverse)
                )
            {
                LastErrorCode = ErrorCodes.ArgumentInvalid;
                return;
            }

            _kompasApp        = kompasApp;
            _figureParameters = figureParameters;

            Extrusion = CreateMuffler(figureParameters, basePlane);
            if (Extrusion == null)
            {
                return;
            }
        }
Пример #2
0
        /// <summary>
        /// Delete muffler from document 3D part
        /// </summary>
        public bool DeleteDetail()
        {
            if (Extrusion == null)
            {
                LastErrorCode = ErrorCodes.ArgumentNull;
                return(false);
            }

            // Muffler deletion
            Extrusion.BaseFaceAreaState = KompasFaces.BaseFaceAreaState.BaseFaceAreaLower;
            var extruded = Extrusion.ExtrudedEntity;

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

            var extrusionParameters = new KompasExtrusionParameters(_figureParameters.Document3DPart, Obj3dType.o3d_cutExtrusion, extruded, _figureParameters.Direction, _kompasApp.Parameters[4] / 4.0);
            var mufflerDeletion     = new KompasExtrusion(extrusionParameters, ExtrusionType.ByEntity);

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

            return(true);
        }
Пример #3
0
        /// <summary>
        /// Create muffler in detail in base plane axis
        /// </summary>
        /// <param name="figureParameters">Parameters of muffler</param>
        /// <param name="basePlane">Base plane of muffler, by default is null</param>
        /// <returns>Muffler extrusion or null if extrusion returns error</returns>
        private KompasExtrusion CreateMuffler(MufflerParameters figureParameters, ksEntity basePlane = null)
        {
            // Muffler sketch
            var muffler = new KompasSketch(figureParameters.Document3DPart, figureParameters.BasePlaneAxis);

            // If base plane is set --
            // -- create sketch of muffler on it
            // instead of base plane axis
            if (basePlane != null)
            {
                muffler = new KompasSketch(figureParameters.Document3DPart, basePlane);
            }
            if (muffler.LastErrorCode != ErrorCodes.OK)
            {
                LastErrorCode = muffler.LastErrorCode;
                return(null);
            }

            var mufflerSketchEdit = muffler.BeginEntityEdit();

            if (mufflerSketchEdit == null)
            {
                LastErrorCode = ErrorCodes.EntityCreateError;
                return(null);
            }

            // Muffler rectangle, width and height are screw hat width
            var mufflerRectangleParam = new RectangleParameter(_kompasApp, _kompasApp.Parameters[0], _kompasApp.Parameters[0], figureParameters.BasePlanePoint);

            if (mufflerSketchEdit.ksRectangle(mufflerRectangleParam.FigureParam) == 0)
            {
                LastErrorCode = ErrorCodes.Document2DRectangleCreateError;
                return(null);
            }

            muffler.EndEntityEdit();

            // Muffler extrusion, height of muffler is nut height / 4
            var extrusionParameters = new KompasExtrusionParameters(figureParameters.Document3DPart, Obj3dType.o3d_baseExtrusion, muffler.Entity, figureParameters.Direction, _kompasApp.Parameters[4] / 4.0);
            var mufflerExtrusion    = new KompasExtrusion(extrusionParameters, ExtrusionType.ByEntity);

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

            return(mufflerExtrusion);
        }
Пример #4
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);
        }
Пример #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);
        }