/// <summary> /// Muffler parameters /// </summary> /// <param name="document3DPart">Part with detail in 3D document</param> /// <param name="basePlaneAxis">Axis of base plane of muffler</param> /// <param name="direction">Direction type of muffler</param> /// <param name="basePlanePoint">Point of base plane of muffler</param> public MufflerParameters(ksPart document3DPart, Obj3dType basePlaneAxis, Direction_Type direction, KompasPoint2D basePlanePoint) { Document3DPart = document3DPart; BasePlaneAxis = basePlaneAxis; Direction = direction; BasePlanePoint = basePlanePoint; }
/// <summary> /// Rounded chamfer parameters /// </summary> /// <param name="document3DPart">Part with detail in 3D document</param> /// <param name="regularPolygonSketch">Sketch of regular polygon -- base of rounded chamfer</param> /// <param name="regularPolygonParameters">Parameters of regular polygon -- base of rounded chamfer</param> /// <param name="basePlanePoint">2D point of base plane</param> /// <param name="direction">Direction of rounded chamfer</param> public RoundedChamferParameters(ksPart document3DPart, ksEntity regularPolygonSketch, RegularPolygonParameter regularPolygonParameters, KompasPoint2D basePlanePoint, Direction_Type direction) { Document3DPart = document3DPart; RegularPolygonSketch = regularPolygonSketch; RegularPolygonParameters = regularPolygonParameters; BasePlanePoint = basePlanePoint; Direction = direction; }
/// <summary> /// Spin parameters contstructor /// </summary> /// <param name="document3DPart">Part of document with detail</param> /// <param name="beginSpinFace">Begin face of spin</param> /// <param name="endSpinFace">End face of spin</param> /// <param name="spinLocationPoint">Spin location point</param> /// <param name="diameterSize">Size of diameter of spin</param> /// <param name="spinStep">Step of spin</param> public SpinParameters(ksPart document3DPart, ksEntity beginSpinFace, ksEntity endSpinFace, KompasPoint2D spinLocationPoint, double diameterSize, double spinStep) { Document3DPart = document3DPart; BeginSpinFace = beginSpinFace; EndSpinFace = endSpinFace; SpinLocationPoint = spinLocationPoint; DiameterSize = diameterSize; SpinStep = spinStep; }
/// <summary> /// Метод отрисовки скетчей основных частей винта /// гладкой и основы под резьбу /// </summary> /// <param name="screwBase"></param> /// <param name="screwBasePoint"> установка базовых точек для скетча</param> /// <param name="extrusionHeight">длинв на которую будет производиться выдавливание</param> /// <param name="LineStyle">стиль линии</param> /// <returns></returns> private bool DrawScrew(KompasSketch screwBase, KompasPoint2D screwBasePoint, Double extrusionHeight, Int32 LineStyle = 1) { var screwSketchEdit = screwBase.BeginEntityEdit(); if (screwSketchEdit.ksCircle(screwBasePoint.X, screwBasePoint.Y, extrusionHeight, LineStyle) == 0) { LastErrorCode = ErrorCodes.Document2DCircleCreatingError; return(false); } screwBase.EndEntityEdit(); return(true); }
/// <summary> /// Get regular polygon param /// </summary> /// <param name="_kompas">Kompas object</param> /// <param name="anglesCount">Angles count</param> /// <param name="inscribedCircleRadius">Inscribed circle radius</param> /// <param name="point2D">Two-dimensional point of figure base</param> public RegularPolygonParameter(KompasApplication kompasApp, int anglesCount, double inscribedCircleRadius, KompasPoint2D point2D) { if (kompasApp == null) { LastErrorCode = ErrorCodes.ArgumentNull; return; } if (anglesCount <= 2 || anglesCount >= 13 || !DoubleValidator.Validate(anglesCount) || inscribedCircleRadius <= 0.0 || !DoubleValidator.Validate(inscribedCircleRadius) || !DoubleValidator.Validate(point2D.X) || !DoubleValidator.Validate(point2D.Y) ) { LastErrorCode = ErrorCodes.ArgumentInvalid; return; } ksRegularPolygonParam polyParam; polyParam = kompasApp.KompasObject.GetParamStruct( (short)StructType2DEnum.ko_RegularPolygonParam); if (polyParam == null) { LastErrorCode = ErrorCodes.EntityDefinitionNull; return; } polyParam.count = anglesCount; polyParam.ang = 0; polyParam.describe = true; polyParam.radius = inscribedCircleRadius; polyParam.style = 1; polyParam.xc = point2D.X; polyParam.yc = point2D.Y; FigureParam = polyParam; }
/// <summary> /// Create cutoff for flathead screwdriver /// </summary> /// <returns>Created entity of cutoff</returns> protected ksEntity CreateCutout(double[] parameters) { var offsetX = parameters[0]; var offsetY = parameters[1]; var width = parameters[2]; var height = parameters[3]; var gost = 0.84; var rectangleSketch = new KompasSketch(_kompasApp.ScrewPart, Obj3dType.o3d_planeYOZ); var rectangleSketchEdit = rectangleSketch.BeginEntityEdit(); var rectanglePoint = new KompasPoint2D(offsetX, offsetY); var rectangleParam = new RectangleParameter(_kompasApp, width, height, rectanglePoint); if (rectangleSketchEdit.ksRectangle(rectangleParam.FigureParam, 0) == 0) { LastErrorCode = ErrorCodes.Document2DRegPolyCreateError; return(null); } rectangleSketch.EndEntityEdit(); var extrusionParameters = new KompasExtrusionParameters ( _kompasApp.ScrewPart, Obj3dType.o3d_cutExtrusion, rectangleSketch.Entity, Direction_Type.dtNormal, _kompasApp.Parameters[1] * gost ); var rectangleExtrusion = new KompasExtrusion( extrusionParameters, ExtrusionType.ByEntity); return(rectangleExtrusion.ExtrudedEntity); }
/// <summary> /// Set rectangle param /// </summary> /// <param name="kompas">KompasObject</param> /// <param name="width">Rectangle width</param> /// <param name="height">Rectangle height</param> /// <param name="point2D">2D point of rectangle position on sketch</param> public RectangleParameter(KompasApplication kompasApp, double width, double height, KompasPoint2D point2D) { if (kompasApp == null || point2D.LastErrorCode != ErrorCodes.OK ) { LastErrorCode = ErrorCodes.ArgumentNull; return; } if (width <= 0.0 || !DoubleValidator.Validate(width) || height <= 0.0 || !DoubleValidator.Validate(height) || !DoubleValidator.Validate(point2D.X) || !DoubleValidator.Validate(point2D.Y) ) { LastErrorCode = ErrorCodes.ArgumentInvalid; return; } ksRectangleParam rectangleParam; rectangleParam = kompasApp.KompasObject.GetParamStruct( (short)StructType2DEnum.ko_RectangleParam); rectangleParam.width = width; rectangleParam.height = height; rectangleParam.ang = 0; rectangleParam.style = 1; rectangleParam.x = point2D.X; rectangleParam.y = point2D.Y; if (rectangleParam == null) { LastErrorCode = ErrorCodes.EntityDefinitionNull; return; } FigureParam = rectangleParam; }
public void Normal(ErrorCodes errorCode, double xc, double yc) { var point2D = new KompasPoint2D(xc, yc); Assert.AreEqual(point2D.LastErrorCode, errorCode); }
/// <summary> /// Get regular polygon param /// </summary> /// <param name="_kompas">Kompas object</param> /// <param name="anglesCount">Angles count</param> /// <param name="inscribedCircleRadius">Inscribed circle radius</param> /// <param name="point2D">Two-dimensional point of figure base</param> public RegularPolygonParameter(KompasApplication kompasApp, int anglesCount, double inscribedCircleRadius, KompasPoint2D point2D) { if (kompasApp == null) { LastErrorCode = ErrorCodes.ArgumentNull; return; } // Angles amount must be from 3 to 12 if (anglesCount <= 2 || anglesCount >= 13 || !DoubleValidator.Validate(anglesCount) || inscribedCircleRadius <= 0.0 || !DoubleValidator.Validate(inscribedCircleRadius) || !DoubleValidator.Validate(point2D.X) || !DoubleValidator.Validate(point2D.Y) ) { LastErrorCode = ErrorCodes.ArgumentInvalid; return; } // Regular polygon is base of hat ksRegularPolygonParam polyParam; polyParam = kompasApp.KompasObject.GetParamStruct((short)StructType2DEnum.ko_RegularPolygonParam); if (polyParam == null) { LastErrorCode = ErrorCodes.EntityDefinitionNull; return; } polyParam.count = anglesCount; // Count of angles polyParam.ang = 0; // Radius-vector angle from center to first top polyParam.describe = true; // The polygon is DEscribed polyParam.radius = inscribedCircleRadius; // INscribed circle radius, / W3 / polyParam.style = 1; // Line style polyParam.xc = point2D.X; polyParam.yc = point2D.Y; // Plane coordinates FigureParam = polyParam; }
/// <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); }
/// <summary> /// Create screw base with extrusion operation /// </summary> /// Width of screw base cylinder is 0.7 * W3 /// <param name="basePlaneofHat">Base plane of hat of screw</param> /// <returns> /// Carving entities: smooth part end and thread part end, /// these ones need for thread operation /// </returns> private ksEntity[] CreateBase(ksEntity basePlaneOfHat) { // 1. Screw base creation // 1.1 Screw base entity var screwBase = new KompasSketch(_kompasApp.ScrewPart, basePlaneOfHat); if (screwBase.LastErrorCode != ErrorCodes.OK) { LastErrorCode = screwBase.LastErrorCode; return(null); } var screwBasePoint = new KompasPoint2D(0, 0); if (screwBasePoint.LastErrorCode != ErrorCodes.OK) { LastErrorCode = screwBasePoint.LastErrorCode; return(null); } var screwBaseSketchEdit = screwBase.BeginEntityEdit(); if (screwBaseSketchEdit == null) { LastErrorCode = ErrorCodes.ArgumentNull; return(null); } if (screwBaseSketchEdit.ksCircle(screwBasePoint.X, screwBasePoint.Y, _kompasApp.Parameters[0] * 0.7 / 2.0, 1) == 0) // / 0.7 * W3 / { LastErrorCode = ErrorCodes.Document2DCircleCreatingError; return(null); } screwBase.EndEntityEdit(); // 1.2 Screw base extrusion var extrusionParameters = new KompasExtrusionParameters(_kompasApp.ScrewPart, Obj3dType.o3d_baseExtrusion, screwBase.Entity, Direction_Type.dtNormal, _kompasApp.Parameters[2]); var screwBaseExtrusion = new KompasExtrusion(extrusionParameters, ExtrusionType.ByEntity); // W1 if (screwBaseExtrusion.LastErrorCode != ErrorCodes.OK) { LastErrorCode = screwBaseExtrusion.LastErrorCode; return(null); } screwBaseExtrusion.BaseFaceAreaState = KompasFaces.BaseFaceAreaState.BaseFaceAreaLower; var extruded = screwBaseExtrusion.ExtrudedEntity; if (extruded == null) { LastErrorCode = ErrorCodes.ArgumentNull; return(null); } // 1.3 Screw base carving var screwCarving = new KompasSketch(_kompasApp.ScrewPart, screwBaseExtrusion.ExtrudedEntity); // Last entity in last extrusion if (screwCarving.LastErrorCode != ErrorCodes.OK) { LastErrorCode = screwCarving.LastErrorCode; return(null); } var screwCarvingSketchEdit = screwCarving.BeginEntityEdit(); if (screwCarvingSketchEdit == null) { LastErrorCode = ErrorCodes.ArgumentNull; return(null); } // Carving is 1/4 of 70 % (i.e. is 0.525) of W3 if (screwCarvingSketchEdit.ksCircle(0, 0, (_kompasApp.Parameters[0] * 0.525 / 2.0), 1) == 0) // / W1 thread / { LastErrorCode = ErrorCodes.Document2DCircleCreatingError; return(null); } screwCarving.EndEntityEdit(); // 1.4 Screw base carving extrusion extrusionParameters = new KompasExtrusionParameters(_kompasApp.ScrewPart, Obj3dType.o3d_baseExtrusion, screwCarving.Entity, Direction_Type.dtNormal, _kompasApp.Parameters[3]); var screwCarvingExtrusion = new KompasExtrusion(extrusionParameters, ExtrusionType.ByEntity); // / W2 / if (screwCarvingExtrusion.LastErrorCode != ErrorCodes.OK) { LastErrorCode = screwCarvingExtrusion.LastErrorCode; return(null); } screwCarvingExtrusion.BaseFaceAreaState = KompasFaces.BaseFaceAreaState.BaseFaceAreaLower; extruded = screwCarvingExtrusion.ExtrudedEntity; if (extruded == null) { LastErrorCode = screwCarvingExtrusion.LastErrorCode; return(null); } return(new ksEntity[2] { screwCarving.Entity, extruded }); }
/// <summary> /// Создание шляпки винта с методом выдавливания /// </summary> /// <returns>Выдавленная шляпки винта для базовой части винта</returns> private ksEntity CreateHat() { // 0.1 Create muffler, which base point is (D / 5, D / 5) var basePoint = -(_kompasApp.Parameters[0] / 5.0); var mufflerParameters = new MufflerParameters { Document3DPart = _kompasApp.ScrewPart, Direction = Direction_Type.dtNormal, BasePlaneAxis = Obj3dType.o3d_planeYOZ, 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 Create hat var screwHat = new KompasSketch(_kompasApp.ScrewPart, Obj3dType.o3d_planeYOZ); if (screwHat.LastErrorCode != ErrorCodes.OK) { LastErrorCode = screwHat.LastErrorCode; return(null); } var screwHatSketchEdit = screwHat.BeginEntityEdit(); if (screwHatSketchEdit == null) { LastErrorCode = screwHat.LastErrorCode; return(null); } var screwHatPoint = new KompasPoint2D(0, 0); if (screwHatSketchEdit.ksCircle(screwHatPoint.X, screwHatPoint.Y, _kompasApp.Parameters[0] / 2, 1) == 0) { LastErrorCode = ErrorCodes.Document2DCircleCreatingError; return(null); } screwHat.EndEntityEdit(); // 1.2 Screw base extrusion var extrusionParameters = new KompasExtrusionParameters(_kompasApp.ScrewPart, Obj3dType.o3d_baseExtrusion, screwHat.Entity, Direction_Type.dtReverse, _kompasApp.Parameters[4] * 0.84); var screwHatExtrusion = new KompasExtrusion(extrusionParameters, ExtrusionType.ByEntity); // H if (screwHatExtrusion.LastErrorCode != ErrorCodes.OK) { LastErrorCode = screwHatExtrusion.LastErrorCode; return(null); } screwHatExtrusion.BaseFaceAreaState = KompasFaces.BaseFaceAreaState.BaseFaceAreaLower; var extruded = screwHatExtrusion.ExtrudedEntity; if (extruded == null) { LastErrorCode = screwHatExtrusion.LastErrorCode; return(null); } // 0.2 Delete muffler if (!mufflerManager.DeleteDetail()) { LastErrorCode = mufflerManager.LastErrorCode; return(null); } //Create slot var rectangleSketch = new KompasSketch(_kompasApp.ScrewPart, Obj3dType.o3d_planeYOZ); if (rectangleSketch.LastErrorCode != ErrorCodes.OK) { LastErrorCode = rectangleSketch.LastErrorCode; return(null); } var rectangleSketchEdit = rectangleSketch.BeginEntityEdit(); if (rectangleSketchEdit == null) { LastErrorCode = rectangleSketch.LastErrorCode; return(null); } var rectanglePoint = new KompasPoint2D(-_kompasApp.Parameters[0], -_kompasApp.Parameters[5] / 2); var rectangleParam = new RectangleParameter(_kompasApp, _kompasApp.Parameters[0] * 2, _kompasApp.Parameters[5], rectanglePoint); if (rectangleSketchEdit.ksRectangle(rectangleParam.FigureParam, 0) == 0) { LastErrorCode = ErrorCodes.EntityDefinitionNull; return(null); } rectangleSketch.EndEntityEdit(); extrusionParameters = new KompasExtrusionParameters(_kompasApp.ScrewPart, Obj3dType.o3d_cutExtrusion, rectangleSketch.Entity, Direction_Type.dtNormal, _kompasApp.Parameters[1] * 0.84); var rectangleExtrusion = new KompasExtrusion(extrusionParameters, ExtrusionType.ByEntity); // m; выдавливание шлица методом вырезания на глубину m if (rectangleExtrusion.LastErrorCode != ErrorCodes.OK) { LastErrorCode = rectangleExtrusion.LastErrorCode; return(null); } return(extruded); }
/// <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 }); }