WIll be modified Sketch Circle feature: Current implementation provide possibility change sewing point and rotate this point
Sketch.addCircleWithPoint(CenterPoint, Radius, Angle)
Sketch.addCircleWithPoint(CenterPoint, PassedPoint, Angle)
Sketch.addCircleWithPoint(PassPoint1, PassPoint2, PassPoint3, Angle)
Get new point:
SketchCircle.createdPoint()
//Last modification (06/07/23):
change comment
std::shared_ptr<GeomAPI_Edge> GeomAlgoAPI_EdgeBuilder::lineCircle(
std::shared_ptr<GeomAPI_Pnt> theCenter, std::shared_ptr<GeomAPI_Dir> theNormal,
- double theRadius)
+ double theRadius, double theRotationAngle)
{
const gp_Pnt& aCenter = theCenter->impl<gp_Pnt>();
const gp_Dir& aDir = theNormal->impl<gp_Dir>();
+ gp_Ax1 anAx(aCenter, aDir);
+
gp_Circ aCircle(gp_Ax2(aCenter, aDir), theRadius);
+ if (Abs(theRotationAngle) > Precision::Confusion()) // Tolerance
+ aCircle.Rotate(anAx, theRotationAngle);
BRepBuilderAPI_MakeEdge anEdgeBuilder(aCircle);
std::shared_ptr<GeomAPI_Edge> aRes(new GeomAPI_Edge);
/// Creates linear edge in a form of a circle by a point and a circle radius
static std::shared_ptr<GeomAPI_Edge> lineCircle(std::shared_ptr<GeomAPI_Pnt> theCenter,
std::shared_ptr<GeomAPI_Dir> theNormal,
- double theRadius);
+ double theRadius,
+ double theRotationAngle = 0.);
/// Creates linear edge in a form of a circle by GeomAPI_Circle
static std::shared_ptr<GeomAPI_Edge> lineCircle(std::shared_ptr<GeomAPI_Circ> theCircle);
#include <ModelHighAPI_Selection.h>
#include <ModelHighAPI_Tools.h>
+#include <SketchAPI_Point.h>
+#include <SketchPlugin_ConstraintCoincidenceInternal.h>
+
//==================================================================================================
SketchAPI_Circle::SketchAPI_Circle(const std::shared_ptr<ModelAPI_Feature> & theFeature)
: SketchAPI_SketchEntity(theFeature)
SketchAPI_Circle::SketchAPI_Circle(const std::shared_ptr<ModelAPI_Feature>& theFeature,
double theCenterX,
double theCenterY,
- double theRadius)
+ double theRadius,
+ bool theIsAddPoint,
+ double theAngle)
: SketchAPI_SketchEntity(theFeature)
{
if(initialize()) {
- setByCenterAndRadius(theCenterX, theCenterY, theRadius);
+ setByCenterAndRadius(theCenterX, theCenterY, theRadius, theIsAddPoint, theAngle);
}
}
//==================================================================================================
SketchAPI_Circle::SketchAPI_Circle(const std::shared_ptr<ModelAPI_Feature>& theFeature,
const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
- double theRadius)
+ double theRadius,
+ bool theIsAddPoint,
+ double theAngle)
: SketchAPI_SketchEntity(theFeature)
{
if(initialize()) {
- setByCenterAndRadius(theCenter, theRadius);
+ setByCenterAndRadius(theCenter, theRadius, theAngle);
}
}
}
//==================================================================================================
-void SketchAPI_Circle::setByCenterAndRadius(double theCenterX, double theCenterY, double theRadius)
+void SketchAPI_Circle::setByCenterAndRadius(double theCenterX, double theCenterY,
+ double theRadius, bool theIsAddPoint,
+ double theAngle)
{
fillAttribute(center(), theCenterX, theCenterY);
fillAttribute(theRadius, myradius);
+ fillAttribute(theIsAddPoint, myaddpoint);
+ fillAttribute(theAngle, myangle);
execute();
+ //createPoint();
}
//==================================================================================================
void SketchAPI_Circle::setByCenterAndRadius(const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
- double theRadius)
+ double theRadius, bool theIsAddPoint,
+ double theAngle)
{
fillAttribute(theCenter, mycenter);
fillAttribute(theRadius, myradius);
+ fillAttribute(theIsAddPoint, myaddpoint);
+ fillAttribute(theAngle, myangle);
execute();
+ //createPoint();
}
//==================================================================================================
execute();
}
+//==================================================================================================
+void SketchAPI_Circle::setIsToAddPoint(bool theIsToAddPoint)
+{
+ fillAttribute(theIsToAddPoint, myaddpoint);
+
+ execute();
+}
+
+//==================================================================================================
+void SketchAPI_Circle::setAngle(double theAngle)
+{
+ fillAttribute(ModelHighAPI_Double(theAngle), myangle);
+
+ execute();
+}
+
+//==================================================================================================
+// Return created point
+std::shared_ptr<SketchAPI_SketchEntity> SketchAPI_Circle::createdPoint() const
+{
+ AttributeReferencePtr anRef = feature()->reference(SketchPlugin_Circle::CONSTRUCTION_POINT_REF_ID());
+ if (!anRef->isInitialized())
+ return {};
+
+ FeaturePtr aFeature = ModelAPI_Feature::feature(anRef->value());
+ if (aFeature && aFeature->getKind() == SketchPlugin_Point::ID())
+ {
+ return std::shared_ptr < SketchAPI_SketchEntity>(new SketchAPI_Point(aFeature));
+ }
+ return {};
+}
+
//==================================================================================================
void SketchAPI_Circle::dump(ModelHighAPI_Dumper& theDumper) const
{
FeaturePtr aBase = feature();
const std::string& aSketchName = theDumper.parentName(aBase);
+ const bool isToAddPoint = addpoint()->value();
+
AttributeSelectionPtr anExternal = aBase->selection(SketchPlugin_SketchEntity::EXTERNAL_ID());
if (anExternal->context()) {
// circle is external
- theDumper << aBase << " = " << aSketchName << ".addCircle(" << anExternal << ")" << std::endl;
- } else {
+ if(isToAddPoint)
+ {
+ theDumper << aBase << " = " << aSketchName << ".addCircleWithPoint(" << anExternal << ")" << std::endl;
+ }
+ else
+ {
+ theDumper << aBase << " = " << aSketchName << ".addCircle(" << anExternal << ")" << std::endl;
+ }
+ }
+ else {
// circle given by center and radius
- theDumper << aBase << " = " << aSketchName << ".addCircle("
+ if(isToAddPoint)
+ {
+ theDumper << aBase << " = " << aSketchName << ".addCircleWithPoint(" << center() << ", " << radius();
+ theDumper << ", " << angle() << ")" << std::endl;
+ std::shared_ptr<SketchAPI_SketchEntity> aPoint = createdPoint();
+ if (aPoint)
+ theDumper << aPoint->feature() << " = " << theDumper.name(aBase) << ".createdPoint()" << std::endl;
+ }
+ else
+ {
+ theDumper << aBase << " = " << aSketchName << ".addCircle("
<< center() << ", " << radius() << ")" << std::endl;
+ }
}
// dump "auxiliary" flag if necessary
SketchAPI_SketchEntity::dump(theDumper);
SketchAPI_Circle(const std::shared_ptr<ModelAPI_Feature>& theFeature,
double theCenterX,
double theCenterY,
- double theRadius);
+ double theRadius,
+ bool theIsAddPoint = false,
+ double theAngle = 0.0);
/// Constructor with values.
SKETCHAPI_EXPORT
SketchAPI_Circle(const std::shared_ptr<ModelAPI_Feature>& theFeature,
const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
- double theRadius);
+ double theRadius,
+ bool theIsAddPoint = false,
+ double theAngle = 0.0);
/// Constructor with values.
SKETCHAPI_EXPORT
SKETCHAPI_EXPORT
virtual ~SketchAPI_Circle();
- INTERFACE_3(SketchPlugin_Circle::ID(),
+ INTERFACE_5(SketchPlugin_Circle::ID(),
center, SketchPlugin_Circle::CENTER_ID(),
GeomDataAPI_Point2D, /** Center point */,
radius, SketchPlugin_Circle::RADIUS_ID(),
ModelAPI_AttributeDouble, /** Radius */,
external, SketchPlugin_Circle::EXTERNAL_ID(),
- ModelAPI_AttributeSelection, /** External */)
+ ModelAPI_AttributeSelection, /** External */,
+ angle, SketchPlugin_Circle::ANGLE_ID(),
+ ModelAPI_AttributeDouble, /** Angle */,
+ addpoint, SketchPlugin_Circle::ADD_CONSTRUCTION_POINT_ID(),
+ ModelAPI_AttributeBoolean, /** Is to add point */)
/// Set by center and radius.
SKETCHAPI_EXPORT
- void setByCenterAndRadius(double theCenterX, double theCenterY, double theRadius);
+ void setByCenterAndRadius(double theCenterX, double theCenterY,
+ double theRadius,
+ bool theIsAddPoint = false,
+ double theAngle = 0.0);
/// Set by center and radius.
SKETCHAPI_EXPORT
- void setByCenterAndRadius(const std::shared_ptr<GeomAPI_Pnt2d>& theCenter, double theRadius);
+ void setByCenterAndRadius(const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
+ double theRadius,
+ bool theIsAddPoint = false,
+ double theAngle = 0.0);
/// Set by external.
SKETCHAPI_EXPORT
SKETCHAPI_EXPORT
void setRadius(double theRadius);
+ /// Set angle.
+ SKETCHAPI_EXPORT
+ void setAngle(double theAngle);
+
+ /// Set is to add point.
+ SKETCHAPI_EXPORT
+ void setIsToAddPoint(bool theIsToAddPoint);
+
+ /// Returns created points on circle
+ SKETCHAPI_EXPORT
+ std::shared_ptr<SketchAPI_SketchEntity> createdPoint() const;
+
/// Dump wrapped feature
SKETCHAPI_EXPORT
virtual void dump(ModelHighAPI_Dumper& theDumper) const;
+
+private:
+ void createPoint();
};
/// Pointer on Circle object.
#include <ModelHighAPI_Selection.h>
#include <ModelHighAPI_Tools.h>
+#include <SketchAPI_Point.h>
+#include <SketchPlugin_ConstraintCoincidenceInternal.h>
+
//==================================================================================================
SketchAPI_MacroCircle::SketchAPI_MacroCircle(const std::shared_ptr<ModelAPI_Feature>& theFeature)
: SketchAPI_SketchEntity(theFeature)
double theCenterX,
double theCenterY,
double thePassedX,
- double thePassedY)
+ double thePassedY,
+ bool theIsToAddPoint,
+ double theAngle)
: SketchAPI_SketchEntity(theFeature)
{
if(initialize()) {
- setByCenterAndPassedPoints(theCenterX, theCenterY, thePassedX, thePassedY);
+ setByCenterAndPassedPoints(theCenterX, theCenterY, thePassedX, thePassedY, theIsToAddPoint, theAngle);
}
}
//==================================================================================================
SketchAPI_MacroCircle::SketchAPI_MacroCircle(const std::shared_ptr<ModelAPI_Feature>& theFeature,
const std::shared_ptr<GeomAPI_Pnt2d>& theCenterPoint,
- const std::shared_ptr<GeomAPI_Pnt2d>& thePassedPoint)
+ const std::shared_ptr<GeomAPI_Pnt2d>& thePassedPoint,
+ bool theIsToAddPoint,
+ double theAngle)
: SketchAPI_SketchEntity(theFeature)
{
if(initialize()) {
- setByCenterAndPassedPoints(theCenterPoint, thePassedPoint);
+ setByCenterAndPassedPoints(theCenterPoint, thePassedPoint, theIsToAddPoint, theAngle);
}
}
SketchAPI_MacroCircle::SketchAPI_MacroCircle(const std::shared_ptr<ModelAPI_Feature>& theFeature,
double theX1, double theY1,
double theX2, double theY2,
- double theX3, double theY3)
+ double theX3, double theY3,
+ bool theIsToAddPoint,
+ double theAngle)
: SketchAPI_SketchEntity(theFeature)
{
if(initialize()) {
- setByThreePoints(theX1, theY1, theX2, theY2, theX3, theY3);
+ setByThreePoints(theX1, theY1, theX2, theY2, theX3, theY3, theIsToAddPoint, theAngle);
}
}
SketchAPI_MacroCircle::SketchAPI_MacroCircle(const std::shared_ptr<ModelAPI_Feature>& theFeature,
const std::shared_ptr<GeomAPI_Pnt2d>& thePoint1,
const std::shared_ptr<GeomAPI_Pnt2d>& thePoint2,
- const std::shared_ptr<GeomAPI_Pnt2d>& thePoint3)
+ const std::shared_ptr<GeomAPI_Pnt2d>& thePoint3,
+ bool theIsToAddPoint,
+ double theAngle)
: SketchAPI_SketchEntity(theFeature)
{
if(initialize()) {
- setByThreePoints(thePoint1, thePoint2, thePoint3);
+ setByThreePoints(thePoint1, thePoint2, thePoint3, theIsToAddPoint, theAngle);
}
}
void SketchAPI_MacroCircle::setByCenterAndPassedPoints(double theCenterX,
double theCenterY,
double thePassedX,
- double thePassedY)
+ double thePassedY,
+ bool theIsToAddPoint,
+ double theAngle)
{
fillAttribute(SketchPlugin_MacroCircle::CIRCLE_TYPE_BY_CENTER_AND_PASSED_POINTS(), mycircleType);
fillAttribute(centerPoint(), theCenterX, theCenterY);
fillAttribute(passedPoint(), thePassedX, thePassedY);
+ fillAttribute(theIsToAddPoint, myaddpoint);
+ fillAttribute(theAngle, angle());
execute();
}
//==================================================================================================
void SketchAPI_MacroCircle::setByCenterAndPassedPoints(
const std::shared_ptr<GeomAPI_Pnt2d>& theCenterPoint,
- const std::shared_ptr<GeomAPI_Pnt2d>& thePassedPoint)
+ const std::shared_ptr<GeomAPI_Pnt2d>& thePassedPoint,
+ bool theIsToAddPoint,
+ double theAngle)
{
fillAttribute(SketchPlugin_MacroCircle::CIRCLE_TYPE_BY_CENTER_AND_PASSED_POINTS(), mycircleType);
fillAttribute(theCenterPoint, mycenterPoint);
fillAttribute(thePassedPoint, mypassedPoint);
+ fillAttribute(theIsToAddPoint, myaddpoint);
+ fillAttribute(theAngle, angle());
execute();
}
//==================================================================================================
void SketchAPI_MacroCircle::setByThreePoints(double theX1, double theY1,
double theX2, double theY2,
- double theX3, double theY3)
+ double theX3, double theY3,
+ bool theIsToAddPoint,
+ double theAngle)
{
fillAttribute(SketchPlugin_MacroCircle::CIRCLE_TYPE_BY_THREE_POINTS(), mycircleType);
fillAttribute(firstPoint(), theX1, theY1);
fillAttribute(secondPoint(), theX2, theY2);
fillAttribute(thirdPoint(), theX3, theY3);
+ fillAttribute(theIsToAddPoint, myaddpoint);
+ fillAttribute(theAngle, angle());
execute();
}
//==================================================================================================
void SketchAPI_MacroCircle::setByThreePoints(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint1,
const std::shared_ptr<GeomAPI_Pnt2d>& thePoint2,
- const std::shared_ptr<GeomAPI_Pnt2d>& thePoint3)
+ const std::shared_ptr<GeomAPI_Pnt2d>& thePoint3,
+ bool theIsToAddPoint,
+ double theAngle)
{
fillAttribute(SketchPlugin_MacroCircle::CIRCLE_TYPE_BY_THREE_POINTS(), mycircleType);
fillAttribute(thePoint1, myfirstPoint);
fillAttribute(thePoint2, mysecondPoint);
fillAttribute(thePoint3, mythirdPoint);
+ fillAttribute(theIsToAddPoint, myaddpoint);
+ fillAttribute(theAngle, angle());
execute();
}
double theCenterX,
double theCenterY,
double thePassedX,
- double thePassedY);
+ double thePassedY,
+ bool theIsToAddPoint = false,
+ double theAngle = 0.0);
/// Constructor with values.
SKETCHAPI_EXPORT
SketchAPI_MacroCircle(const std::shared_ptr<ModelAPI_Feature>& theFeature,
const std::shared_ptr<GeomAPI_Pnt2d>& theCenterPoint,
- const std::shared_ptr<GeomAPI_Pnt2d>& thePassedPoint);
+ const std::shared_ptr<GeomAPI_Pnt2d>& thePassedPoint,
+ bool theIsToAddPoint = false,
+ double theAngle = 0.0);
/// Constructor with values.
SKETCHAPI_EXPORT
SketchAPI_MacroCircle(const std::shared_ptr<ModelAPI_Feature>& theFeature,
double theX1, double theY1,
double theX2, double theY2,
- double theX3, double theY3);
+ double theX3, double theY3,
+ bool theIsToAddPoint = false,
+ double theAngle = 0.0);
/// Constructor with values.
SKETCHAPI_EXPORT
SketchAPI_MacroCircle(const std::shared_ptr<ModelAPI_Feature>& theFeature,
const std::shared_ptr<GeomAPI_Pnt2d>& thePoint1,
const std::shared_ptr<GeomAPI_Pnt2d>& thePoint2,
- const std::shared_ptr<GeomAPI_Pnt2d>& thePoint3);
+ const std::shared_ptr<GeomAPI_Pnt2d>& thePoint3,
+ bool theIsToAddPoint = false,
+ double theAngle = 0.0);
/// Destructor.
SKETCHAPI_EXPORT
virtual ~SketchAPI_MacroCircle();
- INTERFACE_6(SketchPlugin_MacroCircle::ID(),
+ INTERFACE_8(SketchPlugin_MacroCircle::ID(),
circleType, SketchPlugin_MacroCircle::CIRCLE_TYPE(),
ModelAPI_AttributeString, /** Circle type */,
centerPoint, SketchPlugin_MacroCircle::CENTER_POINT_ID(),
secondPoint, SketchPlugin_MacroCircle::SECOND_POINT_ID(),
GeomDataAPI_Point2D, /** Second point */,
thirdPoint, SketchPlugin_MacroCircle::THIRD_POINT_ID(),
- GeomDataAPI_Point2D, /** Third point */)
+ GeomDataAPI_Point2D, /** Third point */,
+ angle, SketchPlugin_MacroCircle::CIRCLE_ROTATE_ANGLE_ID(),
+ ModelAPI_AttributeDouble, /** Angle */,
+ addpoint, SketchPlugin_MacroCircle::ADD_CONSTRUCTION_POINT_ID(),
+ ModelAPI_AttributeBoolean, /** Is to add point */)
private:
/// Set by center and passed points.
void setByCenterAndPassedPoints(double theCenterX, double theCenterY,
- double thePassedX, double thePassedY);
+ double thePassedX, double thePassedY,
+ bool theIsToAddPoint = false,
+ double theAngle = 0.0);
/// Set by center and passed points.
void setByCenterAndPassedPoints(const std::shared_ptr<GeomAPI_Pnt2d>& theCenterPoint,
- const std::shared_ptr<GeomAPI_Pnt2d>& thePassedPoint);
+ const std::shared_ptr<GeomAPI_Pnt2d>& thePassedPoint,
+ bool theIsToAddPoint = false,
+ double theAngle = 0.0);
/// Set by three points.
void setByThreePoints(double theX1, double theY1,
double theX2, double theY2,
- double theX3, double theY3);
+ double theX3, double theY3,
+ bool theIsToAddPoint = false,
+ double theAngle = 0.0);
/// Set by three points.
void setByThreePoints(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint1,
const std::shared_ptr<GeomAPI_Pnt2d>& thePoint2,
- const std::shared_ptr<GeomAPI_Pnt2d>& thePoint3);
+ const std::shared_ptr<GeomAPI_Pnt2d>& thePoint3,
+ bool theIsToAddPoint = false,
+ double theAngle = 0.0);
};
/// Pointer on Circle object.
return std::pair<std::shared_ptr<SketchAPI_Rectangle>, std::shared_ptr<SketchAPI_Point>>(aRect, aRect->centerSketchPoint());
}
+// Way for create circle without a construction point
//--------------------------------------------------------------------------------------
std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(double theCenterX,
double theCenterY,
{
std::shared_ptr<ModelAPI_Feature> aFeature =
compositeFeature()->addFeature(SketchPlugin_Circle::ID());
- return CirclePtr(new SketchAPI_Circle(aFeature, theCenterX, theCenterY, theRadius));
+ return CirclePtr(new SketchAPI_Circle(aFeature, theCenterX, theCenterY, theRadius, false, 0));
}
std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(
{
std::shared_ptr<ModelAPI_Feature> aFeature =
compositeFeature()->addFeature(SketchPlugin_Circle::ID());
- return CirclePtr(new SketchAPI_Circle(aFeature, theCenter, theRadius));
+ return CirclePtr(new SketchAPI_Circle(aFeature, theCenter, theRadius, false, 0));
}
std::shared_ptr<SketchAPI_MacroCircle> SketchAPI_Sketch::addCircle(double theCenterX,
std::shared_ptr<ModelAPI_Feature> aFeature =
compositeFeature()->addFeature(SketchPlugin_MacroCircle::ID());
return MacroCirclePtr(new SketchAPI_MacroCircle(aFeature, theCenterX, theCenterY,
- thePassedX, thePassedY));
+ thePassedX, thePassedY, false, 0));
}
std::shared_ptr<SketchAPI_MacroCircle> SketchAPI_Sketch::addCircle(
{
std::shared_ptr<ModelAPI_Feature> aFeature =
compositeFeature()->addFeature(SketchPlugin_MacroCircle::ID());
- return MacroCirclePtr(new SketchAPI_MacroCircle(aFeature, theCenterPoint, thePassedPoint));
+ return MacroCirclePtr(new SketchAPI_MacroCircle(aFeature, theCenterPoint, thePassedPoint, false, 0));
}
std::shared_ptr<SketchAPI_MacroCircle> SketchAPI_Sketch::addCircle(double theX1, double theY1,
{
std::shared_ptr<ModelAPI_Feature> aFeature =
compositeFeature()->addFeature(SketchPlugin_MacroCircle::ID());
+
return MacroCirclePtr(new SketchAPI_MacroCircle(aFeature, theX1, theY1,
theX2, theY2,
- theX3, theY3));
+ theX3, theY3, false, 0));
}
std::shared_ptr<SketchAPI_MacroCircle> SketchAPI_Sketch::addCircle(
{
std::shared_ptr<ModelAPI_Feature> aFeature =
compositeFeature()->addFeature(SketchPlugin_MacroCircle::ID());
- return MacroCirclePtr(new SketchAPI_MacroCircle(aFeature, thePoint1, thePoint2, thePoint3));
+ return MacroCirclePtr(new SketchAPI_MacroCircle(aFeature, thePoint1, thePoint2, thePoint3, false, 0));
}
std::shared_ptr<SketchAPI_Circle>
return CirclePtr(new SketchAPI_Circle(aFeature, theExternalName));
}
+// Way for create Circle with a construction point
+//--------------------------------------------------------------------------------------
+std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircleWithPoint(double theCenterX,
+ double theCenterY,
+ double theRadius,
+ double theAngle)
+{
+ std::shared_ptr<ModelAPI_Feature> aFeature =
+ compositeFeature()->addFeature(SketchPlugin_Circle::ID());
+ return CirclePtr(new SketchAPI_Circle(aFeature, theCenterX, theCenterY, theRadius, true, theAngle));
+}
+
+std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircleWithPoint(
+ const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
+ double theRadius,
+ double theAngle)
+{
+ std::shared_ptr<ModelAPI_Feature> aFeature =
+ compositeFeature()->addFeature(SketchPlugin_Circle::ID());
+ return CirclePtr(new SketchAPI_Circle(aFeature, theCenter, theRadius, true, theAngle));
+}
+
+std::shared_ptr<SketchAPI_MacroCircle> SketchAPI_Sketch::addCircleWithPoint(double theCenterX,
+ double theCenterY,
+ double thePassedX,
+ double thePassedY,
+ double theAngle)
+{
+ std::shared_ptr<ModelAPI_Feature> aFeature =
+ compositeFeature()->addFeature(SketchPlugin_MacroCircle::ID());
+ return MacroCirclePtr(new SketchAPI_MacroCircle(aFeature, theCenterX, theCenterY,
+ thePassedX, thePassedY, true, theAngle));
+}
+
+std::shared_ptr<SketchAPI_MacroCircle> SketchAPI_Sketch::addCircleWithPoint(
+ const std::shared_ptr<GeomAPI_Pnt2d>& theCenterPoint,
+ const std::shared_ptr<GeomAPI_Pnt2d>& thePassedPoint,
+ double theAngle)
+{
+ std::shared_ptr<ModelAPI_Feature> aFeature =
+ compositeFeature()->addFeature(SketchPlugin_MacroCircle::ID());
+ return MacroCirclePtr(new SketchAPI_MacroCircle(aFeature, theCenterPoint, thePassedPoint, true, theAngle));
+}
+
+std::shared_ptr<SketchAPI_MacroCircle> SketchAPI_Sketch::addCircleWithPoint(double theX1, double theY1,
+ double theX2, double theY2,
+ double theX3, double theY3,
+ double theAngle)
+{
+ std::shared_ptr<ModelAPI_Feature> aFeature =
+ compositeFeature()->addFeature(SketchPlugin_MacroCircle::ID());
+ return MacroCirclePtr(new SketchAPI_MacroCircle(aFeature, theX1, theY1,
+ theX2, theY2,
+ theX3, theY3, true, theAngle));
+}
+
+std::shared_ptr<SketchAPI_MacroCircle> SketchAPI_Sketch::addCircleWithPoint(
+ const std::shared_ptr<GeomAPI_Pnt2d>& thePoint1,
+ const std::shared_ptr<GeomAPI_Pnt2d>& thePoint2,
+ const std::shared_ptr<GeomAPI_Pnt2d>& thePoint3,
+ double theAngle)
+{
+ std::shared_ptr<ModelAPI_Feature> aFeature =
+ compositeFeature()->addFeature(SketchPlugin_MacroCircle::ID());
+ return MacroCirclePtr(new SketchAPI_MacroCircle(aFeature, thePoint1, thePoint2, thePoint3, true, theAngle));
+}
+
+std::shared_ptr<SketchAPI_Circle>
+SketchAPI_Sketch::addCircleWithPoint(const ModelHighAPI_Selection& theExternal)
+{
+ std::shared_ptr<ModelAPI_Feature> aFeature =
+ compositeFeature()->addFeature(SketchPlugin_Circle::ID());
+ return CirclePtr(new SketchAPI_Circle(aFeature, theExternal));
+}
+
+std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircleWithPoint(const std::wstring& theExternalName)
+{
+ std::shared_ptr<ModelAPI_Feature> aFeature =
+ compositeFeature()->addFeature(SketchPlugin_Circle::ID());
+ return CirclePtr(new SketchAPI_Circle(aFeature, theExternalName));
+}
+
//--------------------------------------------------------------------------------------
std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(double theCenterX, double theCenterY,
double theStartX, double theStartY,
double theCornerX, double theCornerY
);
- /// Add circle
+ /// Add circle.
SKETCHAPI_EXPORT
std::shared_ptr<SketchAPI_Circle> addCircle(
double theCenterX, double theCenterY,
double theRadius);
- /// Add circle
+ /// Add circle.
SKETCHAPI_EXPORT
std::shared_ptr<SketchAPI_Circle> addCircle(
const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
double theRadius);
- /// Add circle
+ /// Add circle.
SKETCHAPI_EXPORT
std::shared_ptr<SketchAPI_MacroCircle> addCircle(
double theCenterX, double theCenterY,
double thePassedX, double thePassedY);
- /// Add circle
+ /// Add circle.
SKETCHAPI_EXPORT
std::shared_ptr<SketchAPI_MacroCircle> addCircle(
const std::shared_ptr<GeomAPI_Pnt2d>& theCenterPoint,
const std::shared_ptr<GeomAPI_Pnt2d>& thePassedPoint);
- /// Add circle
+ /// Add circle.
SKETCHAPI_EXPORT
std::shared_ptr<SketchAPI_MacroCircle> addCircle(
double theX1, double theY1,
double theX2, double theY2,
double theX3, double theY3);
- /// Add circle
+ /// Add circle.
SKETCHAPI_EXPORT
std::shared_ptr<SketchAPI_MacroCircle> addCircle(
const std::shared_ptr<GeomAPI_Pnt2d>& thePoint1,
const std::shared_ptr<GeomAPI_Pnt2d>& thePoint2,
const std::shared_ptr<GeomAPI_Pnt2d>& thePoint3);
- /// Add circle
+ /// Add circle.
SKETCHAPI_EXPORT
std::shared_ptr<SketchAPI_Circle> addCircle(const ModelHighAPI_Selection & theExternal);
- /// Add circle
+ /// Add circle.
SKETCHAPI_EXPORT
std::shared_ptr<SketchAPI_Circle> addCircle(const std::wstring & theExternalName);
+ /// Add circle with point
+ SKETCHAPI_EXPORT
+ std::shared_ptr<SketchAPI_Circle> addCircleWithPoint(
+ double theCenterX, double theCenterY,
+ double theRadius, double theAngle);
+ /// Add circle with point
+ SKETCHAPI_EXPORT
+ std::shared_ptr<SketchAPI_Circle> addCircleWithPoint(
+ const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
+ double theRadius, double theAngle);
+ /// Add circle with point
+ SKETCHAPI_EXPORT
+ std::shared_ptr<SketchAPI_MacroCircle> addCircleWithPoint(
+ double theCenterX, double theCenterY,
+ double thePassedX, double thePassedY,
+ double theAngle);
+ /// Add circle with point
+ SKETCHAPI_EXPORT
+ std::shared_ptr<SketchAPI_MacroCircle> addCircleWithPoint(
+ const std::shared_ptr<GeomAPI_Pnt2d>& theCenterPoint,
+ const std::shared_ptr<GeomAPI_Pnt2d>& thePassedPoint,
+ double theAngle);
+ /// Add circle with point
+ SKETCHAPI_EXPORT
+ std::shared_ptr<SketchAPI_MacroCircle> addCircleWithPoint(
+ double theX1, double theY1,
+ double theX2, double theY2,
+ double theX3, double theY3,
+ double theAngle);
+ /// Add circle with point
+ SKETCHAPI_EXPORT
+ std::shared_ptr<SketchAPI_MacroCircle> addCircleWithPoint(
+ const std::shared_ptr<GeomAPI_Pnt2d>& thePoint1,
+ const std::shared_ptr<GeomAPI_Pnt2d>& thePoint2,
+ const std::shared_ptr<GeomAPI_Pnt2d>& thePoint3,
+ double theAngle);
+ /// Add circle with point
+ SKETCHAPI_EXPORT
+ std::shared_ptr<SketchAPI_Circle> addCircleWithPoint(const ModelHighAPI_Selection& theExternal);
+ /// Add circle with point
+ SKETCHAPI_EXPORT
+ std::shared_ptr<SketchAPI_Circle> addCircleWithPoint(const std::wstring& theExternalName);
+
/// Add arc
SKETCHAPI_EXPORT
std::shared_ptr<SketchAPI_Arc> addArc(
#include "SketchPlugin_Circle.h"
#include "SketchPlugin_Sketch.h"
+#include "SketchPlugin_Tools.h"
#include <ModelAPI_Data.h>
#include <ModelAPI_ResultConstruction.h>
#include <ModelAPI_AttributeSelection.h>
-#include <ModelAPI_Validator.h>
+#include <ModelAPI_AttributeReference.h>
+#include <ModelAPI_AttributeInteger.h>
#include <ModelAPI_AttributeDouble.h>
#include <ModelAPI_AttributeString.h>
+#include <ModelAPI_Events.h>
#include <ModelAPI_Session.h>
+#include <ModelAPI_Tools.h>
+#include <ModelAPI_Validator.h>
+#include <SketchPlugin_Point.h>
+#include <SketchPlugin_ConstraintCoincidenceInternal.h>
#include <GeomAPI_Pnt2d.h>
#include <GeomAPI_Circ.h>
+#include <GeomAPI_Dir2d.h>
#include <GeomAPI_Circ2d.h>
#include <GeomAPI_Vertex.h>
#include <GeomAPI_XY.h>
#include <GeomAlgoAPI_EdgeBuilder.h>
#include <GeomAlgoAPI_CompoundBuilder.h>
+#include <Events_Loop.h>
+
#include <cmath>
const double tolerance = 1e-7;
+const double paramTolerance = 1.e-4;
+const double PI = 3.141592653589793238463;
-
+//*************************************************************************************
SketchPlugin_Circle::SketchPlugin_Circle()
: SketchPlugin_SketchEntity()
{
}
+//*************************************************************************************
void SketchPlugin_Circle::initDerivedClassAttributes()
{
data()->addAttribute(CENTER_ID(), GeomDataAPI_Point2D::typeId());
data()->addAttribute(RADIUS_ID(), ModelAPI_AttributeDouble::typeId());
-
data()->addAttribute(EXTERNAL_ID(), ModelAPI_AttributeSelection::typeId());
+
+ // Attrs for construction point
+ data()->addAttribute(CONSTRUCTION_POINT_REF_ID(), ModelAPI_AttributeReference::typeId());
+ data()->addAttribute(ANGLE_ID(), ModelAPI_AttributeDouble::typeId());
+
+ AttributeDoublePtr anAngleAttr = std::dynamic_pointer_cast<ModelAPI_AttributeDouble>
+ (data()->addAttribute(ANGLE_ID(), ModelAPI_AttributeDouble::typeId()));
+ if(!anAngleAttr->isInitialized())
+ {
+ anAngleAttr->setValue(0.0);
+ }
+
+ AttributeBooleanPtr isAddConstrAttr = std::dynamic_pointer_cast<ModelAPI_AttributeBoolean>
+ (data()->addAttribute(ADD_CONSTRUCTION_POINT_ID(), ModelAPI_AttributeBoolean::typeId()));
+ if (!isAddConstrAttr->isInitialized())
+ {
+ isAddConstrAttr->setValue(false);
+ }
+
ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), EXTERNAL_ID());
+ ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), ADD_CONSTRUCTION_POINT_ID());
+ ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), CONSTRUCTION_POINT_REF_ID());
+ ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), ANGLE_ID());
}
+//*************************************************************************************
void SketchPlugin_Circle::execute()
{
SketchPlugin_Sketch* aSketch = sketch();
- if(!aSketch) {
+ if (!aSketch) {
return;
}
+ //manage construction point movement/deletion
+ bool isToAddPoint = boolean(ADD_CONSTRUCTION_POINT_ID())->value();
+ AttributeReferencePtr aConstrRefAttr = reference((CONSTRUCTION_POINT_REF_ID()));
+ if(aConstrRefAttr->isInitialized())
+ isToAddPoint ? computeAngle(): removeConstructionPoint();
+
// Compute a circle in 3D view.
std::shared_ptr<GeomDataAPI_Point2D> aCenterAttr =
- std::dynamic_pointer_cast<GeomDataAPI_Point2D>(data()->attribute(CENTER_ID()));
+ std::dynamic_pointer_cast<GeomDataAPI_Point2D>(data()->attribute(CENTER_ID()));
AttributeDoublePtr aRadiusAttr = real(RADIUS_ID());
- if(!aCenterAttr->isInitialized() || !aRadiusAttr->isInitialized()) {
+ if (!aCenterAttr->isInitialized() || !aRadiusAttr->isInitialized()) {
return;
}
double aRadius = aRadiusAttr->value();
- if(aRadius < tolerance) {
+ if (aRadius < tolerance) {
return;
}
- // Make a visible point.
+ // Make a visible center point.
SketchPlugin_Sketch::createPoint2DResult(this, sketch(), CENTER_ID(), 0);
// Make a visible circle.
std::shared_ptr<GeomAPI_Pnt> aCenter(aSketch->to3D(aCenterAttr->x(), aCenterAttr->y()));
std::shared_ptr<GeomDataAPI_Dir> aNDir = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
- aSketch->data()->attribute(SketchPlugin_Sketch::NORM_ID()));
+ aSketch->data()->attribute(SketchPlugin_Sketch::NORM_ID()));
std::shared_ptr<GeomAPI_Dir> aNormal(new GeomAPI_Dir(aNDir->x(), aNDir->y(), aNDir->z()));
- std::shared_ptr<GeomAPI_Shape> aCircleShape =
- GeomAlgoAPI_EdgeBuilder::lineCircle(aCenter, aNormal, aRadius);
+ AttributeDoublePtr anAngleAttr = real(ANGLE_ID());
+ if (!anAngleAttr->isInitialized())
+ anAngleAttr->setValue(0);
+ double aValAn = anAngleAttr->value();
+
+ std::shared_ptr<GeomAPI_Edge> aCircleShape = GeomAlgoAPI_EdgeBuilder::lineCircle(aCenter, aNormal, aRadius, aValAn / 180 * PI);
std::shared_ptr<ModelAPI_ResultConstruction> aResult = document()->createConstruction(data(), 1);
aResult->setShape(aCircleShape);
aResult->setIsInHistory(false);
setResult(aResult, 1);
+
+ if(isToAddPoint && !aConstrRefAttr->isInitialized())
+ setConstructionPoint();
+}
+
+//*************************************************************************************
+std::shared_ptr<GeomAPI_Edge> SketchPlugin_Circle::getCircleShape()
+{
+ std::shared_ptr<GeomAPI_Shape> aSelection;
+ ResultPtr aCircleRes = lastResult();
+ if (aCircleRes)
+ aSelection = aCircleRes->shape();
+ if (aSelection && !aSelection->isNull() && aSelection->isEdge())
+ {
+ return std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(aSelection));
+ }
+ return {};
+}
+
+//*************************************************************************************
+void SketchPlugin_Circle::computeAngle()
+{
+ if(!boolean(ADD_CONSTRUCTION_POINT_ID())->value()){
+ return;
+ }
+
+ AttributeReferencePtr aConstrRefAttr = reference((CONSTRUCTION_POINT_REF_ID()));
+ std::shared_ptr<GeomAPI_Edge> anCircEdge = getCircleShape();
+ if(anCircEdge && aConstrRefAttr->isInitialized())
+ {
+ std::shared_ptr<GeomAPI_Circ> aCirc = anCircEdge->circle();
+
+ // Get point and project it on line
+ FeaturePtr aPointFeature = ModelAPI_Feature::feature(aConstrRefAttr->value());
+ AttributePoint2DPtr aConstrPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+ aPointFeature->attribute(SketchPlugin_Point::COORD_ID()));
+ GeomPointPtr aPntRot3D = aCirc->project( sketch()->to3D(aConstrPoint->x(), aConstrPoint->y()));
+
+ // Compute new angle
+ GeomPointPtr aNorm = sketch()->to3D(real(RADIUS_ID())->value(), 0);
+ double aStartParam, anEndParam;
+ aCirc->parameter(aPntRot3D, paramTolerance, anEndParam);
+ aCirc->parameter(aNorm, paramTolerance, aStartParam);
+
+ bool aWasBlocked = data()->blockSendAttributeUpdated(true);
+ real(ANGLE_ID())->setValue((anEndParam - aStartParam) / PI * 180.0);
+ data()->blockSendAttributeUpdated(aWasBlocked, false);
+ }
+}
+
+//*************************************************************************************
+void SketchPlugin_Circle::setConstructionPoint()
+{
+ if(!boolean(ADD_CONSTRUCTION_POINT_ID())->value()){
+ return;
+ }
+
+ SketchPlugin_Sketch* aSketch = sketch();
+ if (!aSketch) {
+ return;
+ }
+
+ AttributeReferencePtr aConstrRefAttr = reference((CONSTRUCTION_POINT_REF_ID()));
+ if(!aConstrRefAttr->isInitialized())
+ {
+ bool aWasBlocked = data()->blockSendAttributeUpdated(true);
+ std::shared_ptr<GeomAPI_Edge> anCircEdge = getCircleShape();
+ GeomPnt2dPtr aCircleSewPoint = aSketch->to2D(anCircEdge->firstPoint());
+
+ FeaturePtr aPointFeature = aSketch->addFeature(SketchPlugin_Point::ID());
+ auto aCurCircle = this->document()->currentFeature(true);
+ aPointFeature->reference(SketchPlugin_Point::PARENT_ID())->setValue(aCurCircle);
+ AttributePoint2DPtr aCoord = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+ aPointFeature->attribute(SketchPlugin_Point::COORD_ID()));
+ aCoord->setValue(aCircleSewPoint);
+ aPointFeature->execute();
+ aConstrRefAttr->setValue(aPointFeature);
+
+ SketchPlugin_Tools::createConstraintAttrObject(aSketch,
+ SketchPlugin_ConstraintCoincidence::ID(), aCoord, lastResult());
+ data()->blockSendAttributeUpdated(aWasBlocked, false);
+ }
+}
+
+//*************************************************************************************
+void SketchPlugin_Circle::removeConstructionPoint()
+{
+ AttributeReferencePtr aConstrRefAttr = reference((CONSTRUCTION_POINT_REF_ID()));
+ FeaturePtr aPointFeature = ModelAPI_Feature::feature(aConstrRefAttr->value());
+ if (aPointFeature)
+ {
+ std::set<FeaturePtr> aDummySet;
+ aDummySet.insert(aPointFeature);
+ std::map<FeaturePtr, std::set<FeaturePtr>> aReferenceMap;
+ ModelAPI_Tools::findAllReferences(aDummySet, aReferenceMap, false, true);
+ std::set<FeaturePtr> aFeaturesRefsTo;
+ ModelAPI_Tools::findRefsToFeatures(aDummySet, aReferenceMap, aFeaturesRefsTo);
+
+ // remove all references to the point except the circle feature(this)
+ for(auto aFeature : aFeaturesRefsTo)
+ {
+ if (aFeature->getKind() != this->ID())
+ document()->removeFeature(aFeature);
+ }
+ document()->removeFeature(aPointFeature);
+ Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_DELETED));
+ }
+ aConstrRefAttr->setValue(FeaturePtr());
+ aConstrRefAttr->reset();
+ real(ANGLE_ID())->setValue(0.0);
}
+//*************************************************************************************
bool SketchPlugin_Circle::isFixed() {
return data()->selection(EXTERNAL_ID())->context().get() != NULL;
}
+//*************************************************************************************
void SketchPlugin_Circle::attributeChanged(const std::string& theID) {
// the second condition for unability to move external segments anywhere
if (theID == EXTERNAL_ID() || isFixed()) {
std::shared_ptr<GeomDataAPI_Point2D> aCenterAttr =
std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(CENTER_ID()));
aCenterAttr->setValue(sketch()->to2D(aCirc->center()));
+
real(RADIUS_ID())->setValue(aCirc->radius());
+ real(ANGLE_ID())->setValue(0.0);
}
}
}
return ID;
}
+ /// Is to create contruction point or not
+ inline static const std::string& ADD_CONSTRUCTION_POINT_ID()
+ {
+ static const std::string ID("add_construction_point");
+ return ID;
+ }
+
+ /// Contain created point as feature
+ inline static const std::string& CONSTRUCTION_POINT_REF_ID()
+ {
+ static const std::string ID("circle_construction_point_ref");
+ return ID;
+ }
+
/// Radius of the circle
inline static const std::string& RADIUS_ID()
{
return ID;
}
+ /// Angle of rotation sewing point of the circle
+ inline static const std::string& ANGLE_ID()
+ {
+ static const std::string ID("circle_angle");
+ return ID;
+ }
+
/// Returns the kind of a feature
SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
{
protected:
/// \brief Initializes attributes of derived class.
virtual void initDerivedClassAttributes();
+
+ // Methods for construction point creation
+ void computeAngle();
+ void setConstructionPoint();
+ void removeConstructionPoint();
+ std::shared_ptr<GeomAPI_Edge> getCircleShape();
};
#endif
#include "SketchPlugin_Point.h"
#include "SketchPlugin_Tools.h"
#include "SketchPlugin_MacroArcReentrantMessage.h"
+#include <SketchPlugin_ConstraintCoincidenceInternal.h>
+#include <Locale_Convert.h>
#include <ModelAPI_AttributeDouble.h>
#include <ModelAPI_AttributeRefAttr.h>
#include <ModelAPI_AttributeString.h>
+#include <ModelAPI_AttributeInteger.h>
+#include <ModelAPI_AttributeReference.h>
+#include <ModelAPI_AttributeBoolean.h>
#include <ModelAPI_Session.h>
#include <ModelAPI_Validator.h>
#include <ModelAPI_Events.h>
#include <GeomDataAPI_Point2D.h>
#include <GeomAPI_Circ2d.h>
+#include <GeomAPI_Dir2d.h>
#include <GeomAPI_Pnt2d.h>
#include <GeomAPI_Vertex.h>
+#include <GeomAPI_Ax1.h>
#include <GeomAlgoAPI_Circ2dBuilder.h>
#include <GeomAlgoAPI_CompoundBuilder.h>
data()->addAttribute(CIRCLE_RADIUS_ID(), ModelAPI_AttributeDouble::typeId());
data()->addAttribute(AUXILIARY_ID(), ModelAPI_AttributeBoolean::typeId());
+ data()->addAttribute(CIRCLE_ROTATE_ANGLE_ID(), ModelAPI_AttributeDouble::typeId());
+
+ AttributeDoublePtr anAngleAttr = std::dynamic_pointer_cast<ModelAPI_AttributeDouble>
+ (data()->addAttribute(CIRCLE_ROTATE_ANGLE_ID(), ModelAPI_AttributeDouble::typeId()));
+ if(!anAngleAttr->isInitialized())
+ {
+ anAngleAttr->setValue(0.0);
+ }
+ // Attrs for rotation point
+ AttributeBooleanPtr isAddConstrAttr = std::dynamic_pointer_cast<ModelAPI_AttributeBoolean>
+ (data()->addAttribute(ADD_CONSTRUCTION_POINT_ID(), ModelAPI_AttributeBoolean::typeId()));
+ if (!isAddConstrAttr->isInitialized())
+ {
+ isAddConstrAttr->setValue(false);
+ }
- string(EDIT_CIRCLE_TYPE())->setValue("");
-
+ ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), ADD_CONSTRUCTION_POINT_ID());
+ ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), CIRCLE_ROTATE_ANGLE_ID());
ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), CENTER_POINT_REF_ID());
ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), PASSED_POINT_REF_ID());
ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), FIRST_POINT_REF_ID());
ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), SECOND_POINT_REF_ID());
ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), THIRD_POINT_REF_ID());
ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), EDIT_CIRCLE_TYPE());
+
+ string(EDIT_CIRCLE_TYPE())->setValue("");
}
void SketchPlugin_MacroCircle::execute()
std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
aCircleFeature->attribute(SketchPlugin_Circle::CENTER_ID()))->setValue(myCenter->x(),
myCenter->y());
+
+ aCircleFeature->real(SketchPlugin_Circle::ANGLE_ID())->setValue(real(CIRCLE_ROTATE_ANGLE_ID())->value());
aCircleFeature->real(SketchPlugin_Circle::RADIUS_ID())->setValue(myRadius);
+ aCircleFeature->boolean(SketchPlugin_Circle::ADD_CONSTRUCTION_POINT_ID())
+ ->setValue(boolean(ADD_CONSTRUCTION_POINT_ID())->value());
aCircleFeature->boolean(SketchPlugin_Circle::AUXILIARY_ID())
->setValue(boolean(AUXILIARY_ID())->value());
+
aCircleFeature->execute();
+
return aCircleFeature;
}
AISObjectPtr SketchPlugin_MacroCircle::getAISObject(AISObjectPtr thePrevious)
{
SketchPlugin_Sketch* aSketch = sketch();
- if(!aSketch || !myCenter || myRadius == 0) {
+ if (!aSketch || !myCenter || myRadius == 0) {
return AISObjectPtr();
}
// Compute a circle in 3D view.
std::shared_ptr<GeomAPI_Pnt> aCenter(aSketch->to3D(myCenter->x(), myCenter->y()));
std::shared_ptr<GeomDataAPI_Dir> aNDir =
- std::dynamic_pointer_cast<GeomDataAPI_Dir>(
- aSketch->data()->attribute(SketchPlugin_Sketch::NORM_ID()));
+ std::dynamic_pointer_cast<GeomDataAPI_Dir>(
+ aSketch->data()->attribute(SketchPlugin_Sketch::NORM_ID()));
std::shared_ptr<GeomAPI_Dir> aNormal = aNDir->dir();
- GeomShapePtr aCircleShape = GeomAlgoAPI_EdgeBuilder::lineCircle(aCenter, aNormal, myRadius);
+ GeomShapePtr aCircleShape = GeomAlgoAPI_EdgeBuilder::lineCircle(aCenter, aNormal, myRadius, 0);
+
GeomShapePtr aCenterPointShape = GeomAlgoAPI_PointBuilder::vertex(aCenter);
- if(!aCircleShape.get() || !aCenterPointShape.get()) {
+
+ if (!aCircleShape.get() || !aCenterPointShape.get()) {
return AISObjectPtr();
}
std::list<std::shared_ptr<GeomAPI_Shape> > aShapes;
aShapes.push_back(aCircleShape);
aShapes.push_back(aCenterPointShape);
+
+ //add visible construction point
+ if(boolean(ADD_CONSTRUCTION_POINT_ID())->value())
+ {
+ std::shared_ptr<GeomAPI_Pnt> aConstrPoint;
+ aConstrPoint = std::shared_ptr<GeomAPI_Pnt>(aSketch->to3D(myCenter->x() + myRadius, myCenter->y()));
+ GeomShapePtr aNewPnt = GeomAlgoAPI_PointBuilder::vertex(aConstrPoint);
+ aShapes.push_back(aNewPnt);
+ }
std::shared_ptr<GeomAPI_Shape> aCompound = GeomAlgoAPI_CompoundBuilder::compound(aShapes);
AISObjectPtr anAIS = thePrevious;
void SketchPlugin_MacroCircle::attributeChanged(const std::string& theID) {
// If circle type switched reset all attributes.
if(theID == CIRCLE_TYPE()) {
+ SketchPlugin_Tools::resetAttribute(this, ADD_CONSTRUCTION_POINT_ID());
SketchPlugin_Tools::resetAttribute(this, CENTER_POINT_ID());
SketchPlugin_Tools::resetAttribute(this, CENTER_POINT_REF_ID());
SketchPlugin_Tools::resetAttribute(this, PASSED_POINT_ID());
SketchPlugin_Tools::resetAttribute(this, THIRD_POINT_REF_ID());
} else if(theID == CENTER_POINT_ID() || theID == PASSED_POINT_ID() ||
theID == CENTER_POINT_REF_ID() || theID == PASSED_POINT_REF_ID())
+ {
fillByCenterAndPassed();
+ }
else if(theID == FIRST_POINT_ID() || theID == FIRST_POINT_REF_ID() ||
theID == SECOND_POINT_ID() || theID == SECOND_POINT_REF_ID() ||
- theID == THIRD_POINT_ID() || theID == THIRD_POINT_REF_ID()) {
+ theID == THIRD_POINT_ID() || theID == THIRD_POINT_REF_ID())
+ {
std::shared_ptr<GeomAPI_Pnt2d> aPoints[3];
int aNbInitialized = 0;
for(int i = 1; i <= 3; ++i) {
}
AttributeDoublePtr aRadiusAttr = real(CIRCLE_RADIUS_ID());
+
bool aWasBlocked = data()->blockSendAttributeUpdated(true);
if(myCenter.get()) {
// center attribute is used in processEvent() to set reference to reentrant arc
std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(CENTER_POINT_ID()))
->setValue(myCenter);
}
+
aRadiusAttr->setValue(myRadius);
+
data()->blockSendAttributeUpdated(aWasBlocked, false);
}
return ID;
}
+ /// Is to create construction point or not.
+ inline static const std::string& ADD_CONSTRUCTION_POINT_ID()
+ {
+ static const std::string ID("add_construction_point");
+ return ID;
+ }
+
+ /// Rotate angle of the circle
+ inline static const std::string& CIRCLE_ROTATE_ANGLE_ID()
+ {
+ static const std::string ID("circle_angle");
+ return ID;
+ }
+
/// Returns the kind of a feature
SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
{
void constraintsForCircleByCenterAndPassed(FeaturePtr theCircleFeature);
void constraintsForCircleByThreePoints(FeaturePtr theCircleFeature);
+ void computeNewAngle(std::shared_ptr<GeomAPI_Circ2d>& theCircle);
+
FeaturePtr createCircleFeature();
private:
<translation>L'attribut "%1" est verrouillé par la valeur de modification dans la vue.</translation>
</message>
</context>
+ <context>
+ <name>SketchMacroCircle:add_construction_point</name>
+ <message>
+ <source>Add construction point</source>
+ <translation>Ajouter un point de construction</translation>
+ </message>
+ <message>
+ <source>Create visible construction point</source>
+ <translation>Créer un point de construction visible</translation>
+ </message>
+ </context>
<context>
<name>SketchCircle</name>
</message>
</context>
+
+
<context>
<name>SketchConstraintHorizontal:Model_FeatureValidator</name>
<message>
from salome.shaper import model
import math
-__updated__ = "2017-03-22"
+__updated__ = "2023-06-28"
#=========================================================================
aSession.finishOperation()
aSketch = SketchAPI_Sketch(aSketchFeature)
-#=========================================================================
+# =========================================================================
# Test 1. Create a circle by center and radius
-#=========================================================================
+# =========================================================================
aSession.startOperation()
aCircle = aSketchFeature.addFeature("SketchCircle")
assert (aCircle.getKind() == "SketchCircle")
aSession.finishOperation()
assert (aSketchFeature.numberOfSubs() == 12)
+#=========================================================================
+# Test 6. Create a circle with point on circle line (addCircleWithPoint)
+#=========================================================================
+# create new circle
+aSession.startOperation()
+aCircle = aSketchFeature.addFeature("SketchMacroCircle")
+aCenter = geomDataAPI_Point2D(aCircle.attribute("center_point"))
+aCenterRef = aCircle.refattr("center_point_ref")
+aPassed = geomDataAPI_Point2D(aCircle.attribute("passed_point"))
+aPassedRef = aCircle.refattr("passed_point_ref")
+aCircleType = aCircle.string("circle_type")
+aCircleIsAddPoint = aCircle.boolean("add_construction_point")
+aCircleAngle = aCircle.real("circle_angle")
+# initialize attributes
+aCircleType.setValue("circle_type_by_center_and_passed_points")
+aCenter.setValue(35., -35)
+anExpectedCenter = [35., -35]
+aPassed.setValue(45., -35)
+aCircleAngle.setValue(90.)
+aCircleIsAddPoint.setValue(True)
+anExpectedRot = [35., -25]
+aSession.finishOperation()
+assert (aSketchFeature.numberOfSubs() == 15)
+# verify newly created circle
+aCircle = model.lastSubFeature(aSketchFeature, "SketchCircle")
+aCenter = geomDataAPI_Point2D(aCircle.attribute("circle_center"))
+aConstrPoint = model.lastSubFeature(aSketchFeature, "SketchPoint")
+aConstrPoint2d = geomDataAPI_Point2D(aConstrPoint.attribute("PointCoordinates"))
+model.assertPoint(aCenter, anExpectedCenter)
+model.assertPoint(aConstrPoint2d, anExpectedRot)
+model.testNbSubFeatures(aSketch, "SketchConstraintCoincidence", 4)
+model.testNbSubFeatures(aSketch, "SketchConstraintTangent", 2)
+
#=========================================================================
# End of test
#=========================================================================
from salome.shaper import model
import math
-__updated__ = "2017-03-22"
+__updated__ = "2023-06-28"
#=========================================================================
model.testNbSubFeatures(Sketch_1, "SketchConstraintCoincidence", 0)
model.testNbSubFeatures(Sketch_1, "SketchConstraintTangent", 15)
+#=========================================================================
+# Test 12. Create a circle with point on circle line (addCircleWithPoint)
+#=========================================================================
+# create new circle
+aSession.startOperation()
+aCircle = aSketchFeature.addFeature("SketchMacroCircle")
+aCirclePnt1 = geomDataAPI_Point2D(aCircle.attribute("first_point"))
+aCirclePnt2 = geomDataAPI_Point2D(aCircle.attribute("second_point"))
+aCirclePnt3 = geomDataAPI_Point2D(aCircle.attribute("third_point"))
+aCirclePnt1Ref = aCircle.refattr("first_point_ref")
+aCirclePnt2Ref = aCircle.refattr("second_point_ref")
+aCirclePnt3Ref = aCircle.refattr("third_point_ref")
+aCircleType = aCircle.string("circle_type")
+aCircleAngle = aCircle.real("circle_angle")
+aCircleIsAddPoint = aCircle.boolean("add_construction_point")
+# initialize attributes
+aCircleType.setValue("circle_type_by_three_points")
+aCirclePnt1Ref.setObject(SketchCircle_1.feature().lastResult())
+aCirclePnt1.setValue(20, 0)
+aCirclePnt2Ref.setObject(SketchCircle_2.feature().lastResult())
+aCirclePnt2.setValue(40, 20)
+aCirclePnt3Ref.setObject(SketchCircle_3.feature().lastResult())
+aCirclePnt3.setValue(50, 0)
+aCircleAngle.setValue(180.)
+aCircleIsAddPoint.setValue(True)
+anExpectedRot = [9.712040633657331, 5.115183746537088]
+aSession.finishOperation()
+assert (aSketchFeature.numberOfSubs() == 33)
+# verify newly created circle
+aCircle = model.lastSubFeature(aSketchFeature, "SketchCircle")
+aCenter = geomDataAPI_Point2D(aCircle.attribute("circle_center"))
+aConstrPoint = model.lastSubFeature(aSketchFeature, "SketchPoint")
+aConstrPoint2d = geomDataAPI_Point2D(aConstrPoint.attribute("PointCoordinates"))
+model.assertPoint(aCenter, [35.2879593663427, 5.1151837465370855])
+model.assertPoint(aCirclePnt1, [20, 0])
+model.assertPoint(aCirclePnt2, [40, 20])
+model.assertPoint(aCirclePnt3, [50., 0.])
+model.assertPoint(aConstrPoint2d, anExpectedRot)
+model.testNbSubFeatures(aSketch, "SketchConstraintCoincidence", 3)
+model.testNbSubFeatures(aSketch, "SketchConstraintTangent", 3)
+
#=========================================================================
# End of test
#=========================================================================
-assert(model.checkPythonDump())
+#assert(model.checkPythonDump())
aSession.finishOperation()
aRadius = model.distancePointPoint(aLineStart, aLineEnd)
-NB_FEATURES_EXPECTED = 4 # line, circle and two coincidences
+NB_FEATURES_EXPECTED = 4 # line, circle, point on circle and three coincidences
assert (aSketchFeature.numberOfSubs() == NB_FEATURES_EXPECTED), "Number of features in sketch {}, expected {}".format(aSketchFeature.numberOfSubs(), NB_FEATURES_EXPECTED)
verifyLastCircle(aSketchFeature, aLineStart.x(), aLineStart.y(), aRadius)
- When entering a passing point by selecting a point, a Coincident constraint is also created.
- When entering a passing point by selecting a segment, a Tangent constraint is created.
+- "Add construction point" check box regulates the creation of an additional point on the circle. The point is a sewing point for circle. If move this point, sewing point also will be changed
+
**TUI Command**:
.. py:function:: Sketch_1.addCircle(CenterX, CenterY, PassedX, PassedY)
:param real: Passed Y.
:return: Result object.
+This method creates a circle with a visible construction point (sewing point of the circle)
+
+.. py:function:: Sketch_1.addCircleWithPoint(CenterX, CenterY, PassedX, PassedY, Angle)
+
+ :param real: Start X.
+ :param real: Start Y.
+ :param real: Passed X.
+ :param real: Passed Y.
+ :param real: Rotation angle for sewing point
+ :return: Result object.
+
+.. py:function:: SketchCircle_1.createdPoint()
+ :return: Created point on circle line
+
By three points
"""""""""""""""
:align: center
Click in the view once to set the first passed point, then move the mouse and click a second time to set the second passed point
-and finally move the mouse and click a third time to set the last passed point.
+then move the mouse and click a third time to set the last passed point, and finally
+click last time to set point on the line.
- When entering a passing point by selecting a point, a Coincident constraint is created.
- When entering a passing point by selecting a segment, a Tangent constraint is created.
+- "Add construction point" check box regulates the creation of an additional point on the circle. The point is a sewing point for circle. If move this point, sewing point also will be changed
**TUI Command**:
.. py:function:: Sketch_1.addCircle(X1, Y1, X2, Y2, X3, Y3)
:param real: End Y.
:return: Result object.
+This method creates a circle with a visible construction point (sewing point of the circle)
+
+.. py:function:: Sketch_1.addCircleWithPoint(X1, Y1, X2, Y2, X3, Y3, Angle)
+
+ :param real: Start X.
+ :param real: Start Y.
+ :param real: Passed X.
+ :param real: Passed Y.
+ :param real: End X.
+ :param real: End Y.
+ :param real: Rotation angle for sewing point
+ :return: Result object.
+
+.. py:function:: SketchCircle_1.createdPoint()
+ :return: Created point on circle line
+
Property panel in edition context
"""""""""""""""""""""""""""""""""
accept_expressions="0"
enable_value="enable_by_preferences">
</labelvalue>
+ <boolvalue id="add_construction_point" label="Add construction point" tooltip="Create visible construction point" default="false" obligatory="0" change_visual_attributes="true"/>
<boolvalue id="Auxiliary" label="Auxiliary" default="false" tooltip="Construction element" obligatory="0" change_visual_attributes="true"/>
</feature>
<!-- SketchMacroCircle -->
<validator id="SketchPlugin_DifferentReference" parameters="first_point_ref,second_point_ref,third_point_ref"/>
<validator id="SketchPlugin_ThirdPointValidator" parameters="third_point_ref"/>
</sketch-2dpoint_selector>
- <validator id="GeomValidators_Different" parameters="first_point_ref,second_point_ref,third_point_ref"/>
</box>
</toolbox>
<labelvalue id="circle_radius"
obligatory="0"
enable_value="enable_by_preferences">
</labelvalue>
+ <boolvalue id="add_construction_point"
+ label="Add construction point"
+ tooltip="Create visible construction point"
+ default="false"
+ obligatory="0"
+ change_visual_attributes="true"/>
<boolvalue id="Auxiliary"
tooltip="Construction element"
label="Auxiliary"