/// <summary> /// Метод создает эскиз правильного шестиугольника /// </summary> /// <param name="rad">Радиус описанной окружности шестиугольника</param> public bool DrawHexagon(double rad) { try { SketchCreator sketch = new SketchCreator(_app); ksSketchDefinition def = sketch.MakeSketch(); ksDocument2D doc = (ksDocument2D)def.BeginEdit(); short polyParam = (short)StructType2DEnum.ko_RegularPolygonParam; ksRegularPolygonParam param = (ksRegularPolygonParam)_app.Kompas.GetParamStruct(polyParam); param.count = 6; param.xc = 0; param.yc = 0; param.ang = 0; param.radius = rad; param.describe = false; param.style = 1; doc.ksRegularPolygon(param, 0); def.EndEdit(); return(true); } catch { return(false); } }
/// <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> /// 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; }