Redesigned circle creation. Now Circle feature is a macro which creates Circle feature with center and radius attributes.
}
}
+void GeomData_Point2D::reset()
+{
+ myIsInitialized = false;
+ for(int aComponent = 0; aComponent < NUM_COMPONENTS; ++aComponent) {
+ myExpression[aComponent]->reset();
+ }
+}
+
void GeomData_Point2D::setCalculatedValue(const double theX, const double theY)
{
if (!myIsInitialized || x() != theX || y() != theY) {
/// Reinitializes the internal state of the attribute (may be needed on undo/redo, abort, etc)
virtual void reinit();
+ /// Resets attribute to deafult state.
+ virtual void reset();
+
friend class Model_Data;
};
myIsInitialized = myExpression->isInitialized();
}
+void Model_AttributeDouble::reset()
+{
+ myExpression->reset();
+ myIsInitialized = false;
+}
+
void Model_AttributeDouble::setCalculatedValue(const double theValue)
{
if (!myIsInitialized || value() != theValue) {
/// Reinitializes the internal state of the attribute (may be needed on undo/redo, abort, etc)
virtual void reinit();
+ /// Resets attribute to deafult state.
+ virtual void reset();
+
friend class Model_Data;
};
}
void ModelAPI_Attribute::reinit() {}
+
+void ModelAPI_Attribute::reset() {}
/// ID of the attribute in Data
MODELAPI_EXPORT const std::string& id() const;
+ /// Resets attribute to deafult state.
+ MODELAPI_EXPORT virtual void reset();
+
protected:
/// Objects are created for features automatically
MODELAPI_EXPORT ModelAPI_Attribute();
MODELAPI_EXPORT ModelAPI_Expression();
/// Reinitializes the internal state of the attribute (may be needed on undo/redo, abort, etc)
MODELAPI_EXPORT virtual void reinit() = 0;
+ /// Resets attribute to deafult state.
+ MODELAPI_EXPORT virtual void reset() {
+ myIsInitialized = false;
+ };
bool myIsInitialized; ///< is some value assigned to this attribute
#include <SketchPlugin_Feature.h>
#include <SketchPlugin_Line.h>
#include <SketchPlugin_Arc.h>
-#include <SketchPlugin_Circle.h>
+#include <SketchPlugin_MacroCircle.h>
#include <SketchPlugin_Point.h>
#include <XGUI_Workshop.h>
aSFData->attribute(SketchPlugin_Line::END_ID()));
aNPoint->setValue(aSPoint->x(), aSPoint->y());
}
- else if (aFeatureKind == SketchPlugin_Circle::ID()) {
+ else if (aFeatureKind == SketchPlugin_MacroCircle::ID()) {
// set circle type
- std::string aTypeAttributeId = SketchPlugin_Circle::CIRCLE_TYPE();
+ std::string aTypeAttributeId = SketchPlugin_MacroCircle::CIRCLE_TYPE();
AttributeStringPtr aSourceFeatureTypeAttr = theSourceFeature->data()->string(aTypeAttributeId);
AttributeStringPtr aNewFeatureTypeAttr = theNewFeature->data()->string(aTypeAttributeId);
aNewFeatureTypeAttr->setValue(aSourceFeatureTypeAttr->value());
static QStringList MyFeaturesForCoincedence;
+#define DEBUG_SELECTION
+
PartSet_WidgetPoint2D::PartSet_WidgetPoint2D(QWidget* theParent,
ModuleBase_IWorkshop* theWorkshop,
const Config_WidgetAPI* theData)
bool isAuxiliaryFeature = false;
if (getPoint2d(aView, aShape, aX, aY)) {
setPoint(aX, aY);
+#ifndef DEBUG_SELECTION
feature()->execute();
+#endif
setConstraintToPoint(aX, aY);
}
if (aVertex.get())
aContainPoint = aPoint->isEqual(aVertex->point());
}
+#ifdef DEBUG_SELECTION
+ return true;
+#else
return aContainPoint;
+#endif
}
AttributeRefAttrPtr PartSet_WidgetPoint2D::attributeRefAttr() const
SketchAPI_Constraint.h
SketchAPI_IntersectionPoint.h
SketchAPI_Line.h
+ SketchAPI_MacroCircle.h
SketchAPI_Mirror.h
SketchAPI_Sketch.h
SketchAPI_SketchEntity.h
SketchAPI_Constraint.cpp
SketchAPI_IntersectionPoint.cpp
SketchAPI_Line.cpp
+ SketchAPI_MacroCircle.cpp
SketchAPI_Mirror.cpp
SketchAPI_Sketch.cpp
SketchAPI_SketchEntity.cpp
// shared pointers
%shared_ptr(SketchAPI_Arc)
%shared_ptr(SketchAPI_Circle)
+%shared_ptr(SketchAPI_MacroCircle)
%shared_ptr(SketchAPI_Constraint)
%shared_ptr(SketchAPI_IntersectionPoint)
%shared_ptr(SketchAPI_Line)
%include "SketchAPI_IntersectionPoint.h"
%include "SketchAPI_Line.h"
%include "SketchAPI_Circle.h"
+%include "SketchAPI_MacroCircle.h"
%include "SketchAPI_Arc.h"
%include "SketchAPI_Projection.h"
%include "SketchAPI_Mirror.h"
}
}
-//==================================================================================================
-SketchAPI_Circle::SketchAPI_Circle(const std::shared_ptr<ModelAPI_Feature>& theFeature,
- double theX1, double theY1,
- double theX2, double theY2,
- double theX3, double theY3)
-: SketchAPI_SketchEntity(theFeature)
-{
- if (initialize()) {
- setByThreePoints(theX1, theY1, theX2, theY2, theX3, theY3);
- }
-}
-
-//==================================================================================================
-SketchAPI_Circle::SketchAPI_Circle(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)
-: SketchAPI_SketchEntity(theFeature)
-{
- if (initialize()) {
- setByThreePoints(thePoint1, thePoint2, thePoint3);
- }
-}
-
//==================================================================================================
SketchAPI_Circle::SketchAPI_Circle(const std::shared_ptr<ModelAPI_Feature>& theFeature,
const ModelHighAPI_Selection& theExternal)
//==================================================================================================
void SketchAPI_Circle::setByCenterAndRadius(double theCenterX, double theCenterY, double theRadius)
{
- fillAttribute(SketchPlugin_Circle::CIRCLE_TYPE_CENTER_AND_RADIUS(), mycircleType);
fillAttribute(center(), theCenterX, theCenterY);
fillAttribute(theRadius, myradius);
void SketchAPI_Circle::setByCenterAndRadius(const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
double theRadius)
{
- fillAttribute(SketchPlugin_Circle::CIRCLE_TYPE_CENTER_AND_RADIUS(), mycircleType);
fillAttribute(theCenter, mycenter);
fillAttribute(theRadius, myradius);
execute();
}
-//==================================================================================================
-void SketchAPI_Circle::setByThreePoints(double theX1, double theY1,
- double theX2, double theY2,
- double theX3, double theY3)
-{
- fillAttribute(SketchPlugin_Circle::CIRCLE_TYPE_THREE_POINTS(), mycircleType);
- fillAttribute(firstPoint(), theX1, theY1);
- fillAttribute(secondPoint(), theX2, theY2);
- fillAttribute(thirdPoint(), theX3, theY3);
-
- execute();
-}
-
-//==================================================================================================
-void SketchAPI_Circle::setByThreePoints(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint1,
- const std::shared_ptr<GeomAPI_Pnt2d>& thePoint2,
- const std::shared_ptr<GeomAPI_Pnt2d>& thePoint3)
-{
- fillAttribute(SketchPlugin_Circle::CIRCLE_TYPE_THREE_POINTS(), mycircleType);
- fillAttribute(thePoint1, myfirstPoint);
- fillAttribute(thePoint2, mysecondPoint);
- fillAttribute(thePoint3, mythirdPoint);
-
- execute();
-}
-
//==================================================================================================
void SketchAPI_Circle::setByExternal(const ModelHighAPI_Selection & theExternal)
{
//==================================================================================================
void SketchAPI_Circle::setCenter(double theX, double theY)
{
- fillAttribute(SketchPlugin_Circle::CIRCLE_TYPE_CENTER_AND_RADIUS(), mycircleType);
fillAttribute(center(), theX, theY);
execute();
//==================================================================================================
void SketchAPI_Circle::setCenter(const std::shared_ptr<GeomAPI_Pnt2d> & theCenter)
{
- fillAttribute(SketchPlugin_Circle::CIRCLE_TYPE_CENTER_AND_RADIUS(), mycircleType);
fillAttribute(theCenter, mycenter);
execute();
//==================================================================================================
void SketchAPI_Circle::setRadius(double theRadius)
{
- fillAttribute(SketchPlugin_Circle::CIRCLE_TYPE_CENTER_AND_RADIUS(), mycircleType);
fillAttribute(ModelHighAPI_Double(theRadius), myradius);
execute();
}
-//==================================================================================================
-void SketchAPI_Circle::setFirstPoint(double theX, double theY)
-{
- fillAttribute(SketchPlugin_Circle::CIRCLE_TYPE_THREE_POINTS(), mycircleType);
- fillAttribute(firstPoint(), theX, theY);
-
- execute();
-}
-
-//==================================================================================================
-void SketchAPI_Circle::setFirstPoint(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint)
-{
- fillAttribute(SketchPlugin_Circle::CIRCLE_TYPE_THREE_POINTS(), mycircleType);
- fillAttribute(thePoint, myfirstPoint);
-
- execute();
-}
-
-//==================================================================================================
-void SketchAPI_Circle::setSecondPoint(double theX, double theY)
-{
- fillAttribute(SketchPlugin_Circle::CIRCLE_TYPE_THREE_POINTS(), mycircleType);
- fillAttribute(secondPoint(), theX, theY);
-
- execute();
-}
-
-//==================================================================================================
-void SketchAPI_Circle::setSecondPoint(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint)
-{
- fillAttribute(SketchPlugin_Circle::CIRCLE_TYPE_THREE_POINTS(), mycircleType);
- fillAttribute(thePoint, mysecondPoint);
-
- execute();
-}
-
-//==================================================================================================
-void SketchAPI_Circle::setThirdPoint(double theX, double theY)
-{
- fillAttribute(SketchPlugin_Circle::CIRCLE_TYPE_THREE_POINTS(), mycircleType);
- fillAttribute(thirdPoint(), theX, theY);
-
- execute();
-}
-
-//==================================================================================================
-void SketchAPI_Circle::setThirdPoint(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint)
-{
- fillAttribute(SketchPlugin_Circle::CIRCLE_TYPE_THREE_POINTS(), mycircleType);
- fillAttribute(thePoint, mythirdPoint);
-
- execute();
-}
-
//==================================================================================================
void SketchAPI_Circle::dump(ModelHighAPI_Dumper& theDumper) const
{
// circle is external
theDumper << aBase << " = " << aSketchName << ".addCircle(" << anExternal << ")" << std::endl;
} else {
- AttributeStringPtr aType = circleType();
- if (aType->value() == SketchPlugin_Circle::CIRCLE_TYPE_CENTER_AND_RADIUS()) {
- // circle given by center and radius
- theDumper << aBase << " = " << aSketchName << ".addCircle("
- << center() << ", " << radius() << ")" << std::endl;
- } else {
- // circle given by three points
- theDumper << aBase << " = " << aSketchName << ".addCircle(" << firstPoint() << ", "
- << secondPoint() << ", " << thirdPoint() << ")" << std::endl;
- }
+ // circle given by center and radius
+ theDumper << aBase << " = " << aSketchName << ".addCircle("
+ << center() << ", " << radius() << ")" << std::endl;
}
// dump "auxiliary" flag if necessary
SketchAPI_SketchEntity::dump(theDumper);
const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
double theRadius);
- /// Constructor with values.
- SKETCHAPI_EXPORT
- SketchAPI_Circle(const std::shared_ptr<ModelAPI_Feature>& theFeature,
- double theX1, double theY1,
- double theX2, double theY2,
- double theX3, double theY3);
-
- /// Constructor with values.
- SKETCHAPI_EXPORT
- SketchAPI_Circle(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);
-
/// Constructor with values.
SKETCHAPI_EXPORT
SketchAPI_Circle(const std::shared_ptr<ModelAPI_Feature>& theFeature,
SKETCHAPI_EXPORT
virtual ~SketchAPI_Circle();
- INTERFACE_7(SketchPlugin_Circle::ID(),
- circleType, SketchPlugin_Circle::CIRCLE_TYPE(),
- ModelAPI_AttributeString, /** Circle type */,
+ INTERFACE_3(SketchPlugin_Circle::ID(),
center, SketchPlugin_Circle::CENTER_ID(),
GeomDataAPI_Point2D, /** Center point */,
radius, SketchPlugin_Circle::RADIUS_ID(),
ModelAPI_AttributeDouble, /** Radius */,
- firstPoint, SketchPlugin_Circle::FIRST_POINT_ID(),
- GeomDataAPI_Point2D, /** First point */,
- secondPoint, SketchPlugin_Circle::SECOND_POINT_ID(),
- GeomDataAPI_Point2D, /** Second point */,
- thirdPoint, SketchPlugin_Circle::THIRD_POINT_ID(),
- GeomDataAPI_Point2D, /** Third point */,
external, SketchPlugin_Circle::EXTERNAL_ID(),
ModelAPI_AttributeSelection, /** External */)
SKETCHAPI_EXPORT
void setByCenterAndRadius(const std::shared_ptr<GeomAPI_Pnt2d>& theCenter, double theRadius);
- /// Set by three points.
- SKETCHAPI_EXPORT
- void setByThreePoints(double theX1, double theY1,
- double theX2, double theY2,
- double theX3, double theY3);
-
- /// Set by three points.
- SKETCHAPI_EXPORT
- void setByThreePoints(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint1,
- const std::shared_ptr<GeomAPI_Pnt2d>& thePoint2,
- const std::shared_ptr<GeomAPI_Pnt2d>& thePoint3);
-
/// Set by external.
SKETCHAPI_EXPORT
void setByExternal(const ModelHighAPI_Selection& theExternal);
SKETCHAPI_EXPORT
void setRadius(double theRadius);
- /// Set first point.
- SKETCHAPI_EXPORT
- void setFirstPoint(double theX, double theY);
-
- /// Set first point.
- SKETCHAPI_EXPORT
- void setFirstPoint(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint);
-
- /// Set second point.
- SKETCHAPI_EXPORT
- void setSecondPoint(double theX, double theY);
-
- /// Set second point.
- SKETCHAPI_EXPORT
- void setSecondPoint(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint);
-
- /// Set third point.
- SKETCHAPI_EXPORT
- void setThirdPoint(double theX, double theY);
-
- /// Set third point.
- SKETCHAPI_EXPORT
- void setThirdPoint(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint);
-
/// Dump wrapped feature
SKETCHAPI_EXPORT
virtual void dump(ModelHighAPI_Dumper& theDumper) const;
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+
+// File: SketchAPI_MacroCircle.cpp
+// Created: 09 June 2016
+// Author: Dmitry Bobylev
+
+#include "SketchAPI_MacroCircle.h"
+
+#include <GeomAPI_Pnt2d.h>
+
+#include <ModelHighAPI_Double.h>
+#include <ModelHighAPI_Dumper.h>
+#include <ModelHighAPI_Selection.h>
+#include <ModelHighAPI_Tools.h>
+
+//==================================================================================================
+SketchAPI_MacroCircle::SketchAPI_MacroCircle(const std::shared_ptr<ModelAPI_Feature>& theFeature)
+: SketchAPI_SketchEntity(theFeature)
+{
+ initialize();
+}
+
+//==================================================================================================
+SketchAPI_MacroCircle::SketchAPI_MacroCircle(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+ double theCenterX,
+ double theCenterY,
+ double thePassedX,
+ double thePassedY)
+: SketchAPI_SketchEntity(theFeature)
+{
+ if(initialize()) {
+ setByCenterAndPassedPoints(theCenterX, theCenterY, thePassedX, thePassedY);
+ }
+}
+
+//==================================================================================================
+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)
+: SketchAPI_SketchEntity(theFeature)
+{
+ if(initialize()) {
+ setByCenterAndPassedPoints(theCenterPoint, thePassedPoint);
+ }
+}
+
+//==================================================================================================
+SketchAPI_MacroCircle::SketchAPI_MacroCircle(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+ double theX1, double theY1,
+ double theX2, double theY2,
+ double theX3, double theY3)
+: SketchAPI_SketchEntity(theFeature)
+{
+ if(initialize()) {
+ setByThreePoints(theX1, theY1, theX2, theY2, theX3, theY3);
+ }
+}
+
+//==================================================================================================
+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)
+: SketchAPI_SketchEntity(theFeature)
+{
+ if(initialize()) {
+ setByThreePoints(thePoint1, thePoint2, thePoint3);
+ }
+}
+
+//==================================================================================================
+SketchAPI_MacroCircle::~SketchAPI_MacroCircle()
+{
+}
+
+//==================================================================================================
+void SketchAPI_MacroCircle::setByCenterAndPassedPoints(double theCenterX,
+ double theCenterY,
+ double thePassedX,
+ double thePassedY)
+{
+ fillAttribute(SketchPlugin_MacroCircle::CIRCLE_TYPE_BY_CENTER_AND_PASSED_POINTS(), mycircleType);
+ fillAttribute(centerPoint(), theCenterX, theCenterY);
+ fillAttribute(passedPoint(), thePassedX, thePassedY);
+
+ execute();
+}
+
+//==================================================================================================
+void SketchAPI_MacroCircle::setByCenterAndPassedPoints(
+ const std::shared_ptr<GeomAPI_Pnt2d>& theCenterPoint,
+ const std::shared_ptr<GeomAPI_Pnt2d>& thePassedPoint)
+{
+ fillAttribute(SketchPlugin_MacroCircle::CIRCLE_TYPE_BY_CENTER_AND_PASSED_POINTS(), mycircleType);
+ fillAttribute(theCenterPoint, mycenterPoint);
+ fillAttribute(thePassedPoint, mypassedPoint);
+
+ execute();
+}
+
+//==================================================================================================
+void SketchAPI_MacroCircle::setByThreePoints(double theX1, double theY1,
+ double theX2, double theY2,
+ double theX3, double theY3)
+{
+ fillAttribute(SketchPlugin_MacroCircle::CIRCLE_TYPE_BY_THREE_POINTS(), mycircleType);
+ fillAttribute(firstPoint(), theX1, theY1);
+ fillAttribute(secondPoint(), theX2, theY2);
+ fillAttribute(thirdPoint(), theX3, theY3);
+
+ 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)
+{
+ fillAttribute(SketchPlugin_MacroCircle::CIRCLE_TYPE_BY_THREE_POINTS(), mycircleType);
+ fillAttribute(thePoint1, myfirstPoint);
+ fillAttribute(thePoint2, mysecondPoint);
+ fillAttribute(thePoint3, mythirdPoint);
+
+ execute();
+}
+
+//==================================================================================================
+void SketchAPI_MacroCircle::setCenterPoint(double theX, double theY)
+{
+ fillAttribute(SketchPlugin_MacroCircle::CIRCLE_TYPE_BY_CENTER_AND_PASSED_POINTS(), mycircleType);
+ fillAttribute(centerPoint(), theX, theY);
+
+ execute();
+}
+
+//==================================================================================================
+void SketchAPI_MacroCircle::setCenterPoint(const std::shared_ptr<GeomAPI_Pnt2d>& theCenterPoint)
+{
+ fillAttribute(SketchPlugin_MacroCircle::CIRCLE_TYPE_BY_CENTER_AND_PASSED_POINTS(), mycircleType);
+ fillAttribute(theCenterPoint, mycenterPoint);
+
+ execute();
+}
+
+//==================================================================================================
+void SketchAPI_MacroCircle::setPassedPoint(double theX, double theY)
+{
+ fillAttribute(SketchPlugin_MacroCircle::CIRCLE_TYPE_BY_CENTER_AND_PASSED_POINTS(), mycircleType);
+ fillAttribute(passedPoint(), theX, theY);
+
+ execute();
+}
+
+//==================================================================================================
+void SketchAPI_MacroCircle::setPassedPoint(const std::shared_ptr<GeomAPI_Pnt2d>& thePassedPoint)
+{
+ fillAttribute(SketchPlugin_MacroCircle::CIRCLE_TYPE_BY_CENTER_AND_PASSED_POINTS(), mycircleType);
+ fillAttribute(thePassedPoint, mypassedPoint);
+
+ execute();
+}
+
+//==================================================================================================
+void SketchAPI_MacroCircle::setFirstPoint(double theX, double theY)
+{
+ fillAttribute(SketchPlugin_MacroCircle::CIRCLE_TYPE_BY_THREE_POINTS(), mycircleType);
+ fillAttribute(firstPoint(), theX, theY);
+
+ execute();
+}
+
+//==================================================================================================
+void SketchAPI_MacroCircle::setFirstPoint(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint)
+{
+ fillAttribute(SketchPlugin_MacroCircle::CIRCLE_TYPE_BY_THREE_POINTS(), mycircleType);
+ fillAttribute(thePoint, myfirstPoint);
+
+ execute();
+}
+
+//==================================================================================================
+void SketchAPI_MacroCircle::setSecondPoint(double theX, double theY)
+{
+ fillAttribute(SketchPlugin_MacroCircle::CIRCLE_TYPE_BY_THREE_POINTS(), mycircleType);
+ fillAttribute(secondPoint(), theX, theY);
+
+ execute();
+}
+
+//==================================================================================================
+void SketchAPI_MacroCircle::setSecondPoint(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint)
+{
+ fillAttribute(SketchPlugin_MacroCircle::CIRCLE_TYPE_BY_THREE_POINTS(), mycircleType);
+ fillAttribute(thePoint, mysecondPoint);
+
+ execute();
+}
+
+//==================================================================================================
+void SketchAPI_MacroCircle::setThirdPoint(double theX, double theY)
+{
+ fillAttribute(SketchPlugin_MacroCircle::CIRCLE_TYPE_BY_THREE_POINTS(), mycircleType);
+ fillAttribute(thirdPoint(), theX, theY);
+
+ execute();
+}
+
+//==================================================================================================
+void SketchAPI_MacroCircle::setThirdPoint(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint)
+{
+ fillAttribute(SketchPlugin_MacroCircle::CIRCLE_TYPE_BY_THREE_POINTS(), mycircleType);
+ fillAttribute(thePoint, mythirdPoint);
+
+ execute();
+}
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+
+// File: SketchAPI_MacroCircle.h
+// Created: 09 June 2016
+// Author: Dmitry Bobylev
+
+#ifndef SketchAPI_MacroCircle_H_
+#define SketchAPI_MacroCircle_H_
+
+#include "SketchAPI.h"
+#include "SketchAPI_SketchEntity.h"
+
+#include <SketchPlugin_MacroCircle.h>
+
+class ModelHighAPI_Selection;
+
+/// \class SketchAPI_MacroCircle
+/// \ingroup CPPHighAPI
+/// \brief Interface for Circle feature.
+class SketchAPI_MacroCircle: public SketchAPI_SketchEntity
+{
+public:
+ /// Constructor without values.
+ SKETCHAPI_EXPORT
+ explicit SketchAPI_MacroCircle(const std::shared_ptr<ModelAPI_Feature>& theFeature);
+
+ /// Constructor with values.
+ SKETCHAPI_EXPORT
+ SketchAPI_MacroCircle(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+ double theCenterX,
+ double theCenterY,
+ double thePassedX,
+ double thePassedY);
+
+ /// 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);
+
+ /// 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);
+
+ /// 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);
+
+ /// Destructor.
+ SKETCHAPI_EXPORT
+ virtual ~SketchAPI_MacroCircle();
+
+ INTERFACE_6(SketchPlugin_MacroCircle::ID(),
+ circleType, SketchPlugin_MacroCircle::CIRCLE_TYPE(),
+ ModelAPI_AttributeString, /** Circle type */,
+ centerPoint, SketchPlugin_MacroCircle::CENTER_POINT_ID(),
+ GeomDataAPI_Point2D, /** Center point */,
+ passedPoint, SketchPlugin_MacroCircle::PASSED_POINT_ID(),
+ GeomDataAPI_Point2D, /** Passed point */,
+ firstPoint, SketchPlugin_MacroCircle::FIRST_POINT_ID(),
+ GeomDataAPI_Point2D, /** First point */,
+ secondPoint, SketchPlugin_MacroCircle::SECOND_POINT_ID(),
+ GeomDataAPI_Point2D, /** Second point */,
+ thirdPoint, SketchPlugin_MacroCircle::THIRD_POINT_ID(),
+ GeomDataAPI_Point2D, /** Third point */)
+
+ /// Set by center and passed points.
+ SKETCHAPI_EXPORT
+ void setByCenterAndPassedPoints(double theCenterX, double theCenterY,
+ double thePassedX, double thePassedY);
+
+ /// Set by center and passed points.
+ SKETCHAPI_EXPORT
+ void setByCenterAndPassedPoints(const std::shared_ptr<GeomAPI_Pnt2d>& theCenterPoint,
+ const std::shared_ptr<GeomAPI_Pnt2d>& thePassedPoint);
+
+ /// Set by three points.
+ SKETCHAPI_EXPORT
+ void setByThreePoints(double theX1, double theY1,
+ double theX2, double theY2,
+ double theX3, double theY3);
+
+ /// Set by three points.
+ SKETCHAPI_EXPORT
+ void setByThreePoints(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint1,
+ const std::shared_ptr<GeomAPI_Pnt2d>& thePoint2,
+ const std::shared_ptr<GeomAPI_Pnt2d>& thePoint3);
+
+ /// Set center point.
+ SKETCHAPI_EXPORT
+ void setCenterPoint(double theX, double theY);
+
+ /// Set center point.
+ SKETCHAPI_EXPORT
+ void setCenterPoint(const std::shared_ptr<GeomAPI_Pnt2d>& theCenterPoint);
+
+ /// Set passed point.
+ SKETCHAPI_EXPORT
+ void setPassedPoint(double theX, double theY);
+
+ /// Set passed point.
+ SKETCHAPI_EXPORT
+ void setPassedPoint(const std::shared_ptr<GeomAPI_Pnt2d>& thePassedPoint);
+
+ /// Set first point.
+ SKETCHAPI_EXPORT
+ void setFirstPoint(double theX, double theY);
+
+ /// Set first point.
+ SKETCHAPI_EXPORT
+ void setFirstPoint(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint);
+
+ /// Set second point.
+ SKETCHAPI_EXPORT
+ void setSecondPoint(double theX, double theY);
+
+ /// Set second point.
+ SKETCHAPI_EXPORT
+ void setSecondPoint(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint);
+
+ /// Set third point.
+ SKETCHAPI_EXPORT
+ void setThirdPoint(double theX, double theY);
+
+ /// Set third point.
+ SKETCHAPI_EXPORT
+ void setThirdPoint(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint);
+};
+
+/// Pointer on Circle object.
+typedef std::shared_ptr<SketchAPI_MacroCircle> MacroCirclePtr;
+
+#endif // SketchAPI_MacroCircle_H_
#include "SketchAPI_Circle.h"
#include "SketchAPI_IntersectionPoint.h"
#include "SketchAPI_Line.h"
+#include "SketchAPI_MacroCircle.h"
#include "SketchAPI_Mirror.h"
#include "SketchAPI_Point.h"
#include "SketchAPI_Projection.h"
return CirclePtr(new SketchAPI_Circle(aFeature, theCenter, theRadius));
}
-std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(double theX1, double theY1,
- double theX2, double theY2,
- double theX3, double theY3)
+std::shared_ptr<SketchAPI_MacroCircle> SketchAPI_Sketch::addCircle(double theCenterX,
+ double theCenterY,
+ double thePassedX,
+ double thePassedY)
{
std::shared_ptr<ModelAPI_Feature> aFeature =
compositeFeature()->addFeature(SketchPlugin_Circle::ID());
- return CirclePtr(new SketchAPI_Circle(aFeature, theX1, theY1, theX2, theY2, theX3, theY3));
+ return MacroCirclePtr(new SketchAPI_MacroCircle(aFeature, theCenterX, theCenterY,
+ thePassedX, thePassedY));
}
-std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(
- const std::shared_ptr<GeomAPI_Pnt2d>& thePoint1,
- const std::shared_ptr<GeomAPI_Pnt2d>& thePoint2,
- const std::shared_ptr<GeomAPI_Pnt2d>& thePoint3)
+std::shared_ptr<SketchAPI_MacroCircle> SketchAPI_Sketch::addCircle(
+ const std::shared_ptr<GeomAPI_Pnt2d>& theCenterPoint,
+ const std::shared_ptr<GeomAPI_Pnt2d>& thePassedPoint)
+{
+ std::shared_ptr<ModelAPI_Feature> aFeature =
+ compositeFeature()->addFeature(SketchPlugin_Circle::ID());
+ return MacroCirclePtr(new SketchAPI_MacroCircle(aFeature, theCenterPoint, thePassedPoint));
+}
+
+std::shared_ptr<SketchAPI_MacroCircle> SketchAPI_Sketch::addCircle(double theX1, double theY1,
+ double theX2, double theY2,
+ double theX3, double theY3)
+{
+ std::shared_ptr<ModelAPI_Feature> aFeature =
+ compositeFeature()->addFeature(SketchPlugin_Circle::ID());
+ return MacroCirclePtr(new SketchAPI_MacroCircle(aFeature, theX1, theY1,
+ theX2, theY2,
+ theX3, theY3));
+}
+
+std::shared_ptr<SketchAPI_MacroCircle> SketchAPI_Sketch::addCircle(
+ const std::shared_ptr<GeomAPI_Pnt2d>& thePoint1,
+ const std::shared_ptr<GeomAPI_Pnt2d>& thePoint2,
+ const std::shared_ptr<GeomAPI_Pnt2d>& thePoint3)
{
std::shared_ptr<ModelAPI_Feature> aFeature =
compositeFeature()->addFeature(SketchPlugin_Circle::ID());
- return CirclePtr(new SketchAPI_Circle(aFeature, thePoint1, thePoint2, thePoint3));
+ return MacroCirclePtr(new SketchAPI_MacroCircle(aFeature, thePoint1, thePoint2, thePoint3));
}
std::shared_ptr<SketchAPI_Circle>
class ModelHighAPI_Selection;
class SketchAPI_Arc;
class SketchAPI_Circle;
+class SketchAPI_MacroCircle;
class SketchAPI_IntersectionPoint;
class SketchAPI_Line;
class SketchAPI_Mirror;
double theRadius);
/// Add circle
SKETCHAPI_EXPORT
- std::shared_ptr<SketchAPI_Circle> addCircle(
+ std::shared_ptr<SketchAPI_MacroCircle> addCircle(
+ double theCenterX, double theCenterY,
+ double thePassedX, double thePassedY);
+ /// 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
+ SKETCHAPI_EXPORT
+ std::shared_ptr<SketchAPI_MacroCircle> addCircle(
double theX1, double theY1,
double theX2, double theY2,
double theX3, double theY3);
/// Add circle
SKETCHAPI_EXPORT
- std::shared_ptr<SketchAPI_Circle> addCircle(
+ 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);
#include "SketchAPI.h"
#include "SketchAPI_Arc.h"
#include "SketchAPI_Circle.h"
+ #include "SketchAPI_MacroCircle.h"
#include "SketchAPI_Constraint.h"
#include "SketchAPI_IntersectionPoint.h"
#include "SketchAPI_Line.h"
SketchPlugin_Feature.h
SketchPlugin_IntersectionPoint.h
SketchPlugin_Line.h
+ SketchPlugin_MacroCircle.h
SketchPlugin_MultiRotation.h
SketchPlugin_MultiTranslation.h
SketchPlugin_Plugin.h
SketchPlugin_Feature.cpp
SketchPlugin_IntersectionPoint.cpp
SketchPlugin_Line.cpp
+ SketchPlugin_MacroCircle.cpp
SketchPlugin_MultiRotation.cpp
SketchPlugin_MultiTranslation.cpp
SketchPlugin_Plugin.cpp
const double tolerance = 1e-7;
-namespace {
- static const std::string& POINT_ID(int theIndex)
- {
- switch (theIndex) {
- case 1: return SketchPlugin_Circle::FIRST_POINT_ID();
- case 2: return SketchPlugin_Circle::SECOND_POINT_ID();
- case 3: return SketchPlugin_Circle::THIRD_POINT_ID();
- }
-
- static const std::string DUMMY;
- return DUMMY;
- }
-}
-
SketchPlugin_Circle::SketchPlugin_Circle()
- : SketchPlugin_SketchEntity()
+: SketchPlugin_SketchEntity()
{
}
{
data()->addAttribute(CENTER_ID(), GeomDataAPI_Point2D::typeId());
data()->addAttribute(RADIUS_ID(), ModelAPI_AttributeDouble::typeId());
+
data()->addAttribute(EXTERNAL_ID(), ModelAPI_AttributeSelection::typeId());
ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), EXTERNAL_ID());
-
- data()->addAttribute(CIRCLE_TYPE(), ModelAPI_AttributeString::typeId());
- data()->addAttribute(FIRST_POINT_ID(), GeomDataAPI_Point2D::typeId());
- data()->addAttribute(SECOND_POINT_ID(), GeomDataAPI_Point2D::typeId());
- data()->addAttribute(THIRD_POINT_ID(), GeomDataAPI_Point2D::typeId());
- std::dynamic_pointer_cast<ModelAPI_AttributeString>(
- data()->attribute(CIRCLE_TYPE()))->setValue(CIRCLE_TYPE_CENTER_AND_RADIUS());
}
void SketchPlugin_Circle::execute()
{
SketchPlugin_Sketch* aSketch = sketch();
- if (aSketch) {
- std::list<std::shared_ptr<GeomAPI_Shape> > aShapes;
-
- // compute a circle point in 3D view
- std::shared_ptr<GeomDataAPI_Point2D> aCenterAttr = std::dynamic_pointer_cast<
- GeomDataAPI_Point2D>(data()->attribute(CENTER_ID()));
- AttributeDoublePtr aRadiusAttr =
- std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(data()->attribute(RADIUS_ID()));
- if (aCenterAttr->isInitialized() && aRadiusAttr->isInitialized()) {
- std::shared_ptr<GeomAPI_Pnt> aCenter(aSketch->to3D(aCenterAttr->x(), aCenterAttr->y()));
- //std::cout<<"Execute circle "<<aCenter->x()<<" "<<aCenter->y()<<" "<<aCenter->z()<<std::endl;
- // make a visible point
- SketchPlugin_Sketch::createPoint2DResult(this, sketch(), CENTER_ID(), 0);
-
- // make a visible circle
- std::shared_ptr<GeomDataAPI_Dir> aNDir = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
- aSketch->data()->attribute(SketchPlugin_Sketch::NORM_ID()));
- std::shared_ptr<GeomAPI_Dir> aNormal(new GeomAPI_Dir(aNDir->x(), aNDir->y(), aNDir->z()));
- // compute the circle radius
- double aRadius = aRadiusAttr->value();
-
- std::shared_ptr<GeomAPI_Shape> aCircleShape = GeomAlgoAPI_EdgeBuilder::lineCircle(
- aCenter, aNormal, aRadius);
- aShapes.push_back(aCircleShape);
- std::shared_ptr<ModelAPI_ResultConstruction> aConstr2 = document()->createConstruction(
- data(), 1);
- aConstr2->setShape(aCircleShape);
- aConstr2->setIsInHistory(false);
- setResult(aConstr2, 1);
- }
+ if(!aSketch) {
+ return;
}
-}
-AISObjectPtr SketchPlugin_Circle::getAISObject(AISObjectPtr thePrevious)
-{
- SketchPlugin_Sketch* aSketch = sketch();
- if (aSketch && !isFeatureValid()) {
- // compute a circle point in 3D view
- std::shared_ptr<GeomDataAPI_Point2D> aCenterAttr = std::dynamic_pointer_cast<
- GeomDataAPI_Point2D>(data()->attribute(CENTER_ID()));
- AttributeDoublePtr aRadiusAttr =
- std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(attribute(RADIUS_ID()));
- if (aCenterAttr->isInitialized() && aRadiusAttr->isInitialized()) {
- std::shared_ptr<GeomAPI_Pnt> aCenter(aSketch->to3D(aCenterAttr->x(), aCenterAttr->y()));
+ // Compute a circle in 3D view.
+ std::shared_ptr<GeomDataAPI_Point2D> aCenterAttr =
+ std::dynamic_pointer_cast<GeomDataAPI_Point2D>(data()->attribute(CENTER_ID()));
+ AttributeDoublePtr aRadiusAttr = real(RADIUS_ID());
+ if(!aCenterAttr->isInitialized() || !aRadiusAttr->isInitialized()) {
+ return;
+ }
- // make a visible circle
- std::shared_ptr<GeomDataAPI_Dir> aNDir = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
- aSketch->data()->attribute(SketchPlugin_Sketch::NORM_ID()));
- std::shared_ptr<GeomAPI_Dir> aNormal = aNDir->dir();
+ double aRadius = aRadiusAttr->value();
+ if(aRadius < tolerance) {
+ return;
+ }
- double aRadius = aRadiusAttr->value();
- std::shared_ptr<GeomAPI_Shape> aCircleShape = GeomAlgoAPI_EdgeBuilder::lineCircle(
- aCenter, aNormal, aRadius);
- if (aCircleShape && aRadius != 0) {
- std::list<std::shared_ptr<GeomAPI_Shape> > aShapes;
- // make a visible point
- std::shared_ptr<GeomAPI_Shape> aCenterPointShape =
- GeomAlgoAPI_PointBuilder::vertex(aCenter);
- aShapes.push_back(aCenterPointShape);
- aShapes.push_back(aCircleShape);
+ // Make a visible point.
+ SketchPlugin_Sketch::createPoint2DResult(this, sketch(), CENTER_ID(), 0);
- std::shared_ptr<GeomAPI_Shape> aCompound = GeomAlgoAPI_CompoundBuilder::compound(aShapes);
- AISObjectPtr anAIS = thePrevious;
- if (!anAIS)
- anAIS = AISObjectPtr(new GeomAPI_AISObject);
- anAIS->createShape(aCompound);
- anAIS->setWidth(3);
- return anAIS;
- }
- }
- }
- return AISObjectPtr();
-}
+ // 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()));
+ std::shared_ptr<GeomAPI_Dir> aNormal(new GeomAPI_Dir(aNDir->x(), aNDir->y(), aNDir->z()));
-bool SketchPlugin_Circle::isFeatureValid()
-{
- std::shared_ptr<GeomDataAPI_Point2D> aCenter =
- std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(CENTER_ID()));
- bool aValid = aCenter->isInitialized();
+ std::shared_ptr<GeomAPI_Shape> aCircleShape =
+ GeomAlgoAPI_EdgeBuilder::lineCircle(aCenter, aNormal, aRadius);
- std::string aType = std::dynamic_pointer_cast<ModelAPI_AttributeString>(
- data()->attribute(CIRCLE_TYPE()))->value();
- if (aType == CIRCLE_TYPE_THREE_POINTS()) {
- std::shared_ptr<GeomDataAPI_Point2D> aFirstPnt =
- std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(FIRST_POINT_ID()));
- std::shared_ptr<GeomDataAPI_Point2D> aSecondPnt =
- std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(SECOND_POINT_ID()));
- std::shared_ptr<GeomDataAPI_Point2D> aThirdPnt =
- std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(THIRD_POINT_ID()));
- aValid = aValid &&
- aFirstPnt->isInitialized() &&
- aSecondPnt->isInitialized() &&
- aThirdPnt->isInitialized();
- }
- return aValid;
+ std::shared_ptr<ModelAPI_ResultConstruction> aResult = document()->createConstruction(data(), 1);
+ aResult->setShape(aCircleShape);
+ aResult->setIsInHistory(false);
+ setResult(aResult, 1);
}
void SketchPlugin_Circle::move(double theDeltaX, double theDeltaY)
{
std::shared_ptr<ModelAPI_Data> aData = data();
- if (!aData->isValid())
+ if(!aData->isValid()) {
return;
+ }
std::shared_ptr<GeomDataAPI_Point2D> aPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
aData->attribute(CENTER_ID()));
- if (aPoint->isInitialized())
- aPoint->move(theDeltaX, theDeltaY);
-
- aPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(FIRST_POINT_ID()));
- if (aPoint->isInitialized())
- aPoint->move(theDeltaX, theDeltaY);
- aPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(SECOND_POINT_ID()));
- if (aPoint->isInitialized())
- aPoint->move(theDeltaX, theDeltaY);
- aPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(THIRD_POINT_ID()));
- if (aPoint->isInitialized())
+ if(aPoint->isInitialized()) {
aPoint->move(theDeltaX, theDeltaY);
+ }
}
bool SketchPlugin_Circle::isFixed() {
real(RADIUS_ID())->setValue(aCirc->radius());
}
}
- else if (theID == CENTER_ID() || theID == RADIUS_ID()) {
- std::string aType = std::dynamic_pointer_cast<ModelAPI_AttributeString>(
- data()->attribute(CIRCLE_TYPE()))->value();
- if (aType == CIRCLE_TYPE_THREE_POINTS() && lastResult()) // adjust data from the solver
- adjustThreePoints();
- } else if (theID == FIRST_POINT_ID() || theID == SECOND_POINT_ID() || theID == THIRD_POINT_ID()) {
- // support the center and radius attributes enev in other mode: solver uses them
- std::string aType = std::dynamic_pointer_cast<ModelAPI_AttributeString>(
- data()->attribute(CIRCLE_TYPE()))->value();
- if (aType == CIRCLE_TYPE_CENTER_AND_RADIUS())
- return;
- bool aWasBlocked = data()->blockSendAttributeUpdated(true); // to modify two attributes at once
- std::shared_ptr<GeomAPI_Pnt2d> aPoints[3];
- int aNbInitialized = 0;
- for (int i = 1; i <= 3; ++i) {
- std::shared_ptr<GeomDataAPI_Point2D> aCurPnt =
- std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(POINT_ID(i)));
- if (aCurPnt->isInitialized())
- aPoints[aNbInitialized++] = aCurPnt->pnt();
- }
-
- std::shared_ptr<GeomDataAPI_Point2D> aCenterAttr = std::dynamic_pointer_cast<
- GeomDataAPI_Point2D>(data()->attribute(CENTER_ID()));
- AttributeDoublePtr aRadiusAttr =
- std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(data()->attribute(RADIUS_ID()));
-
- if (aNbInitialized == 1)
- aCenterAttr->setValue(aPoints[0]->x(), aPoints[0]->y());
- else if (aNbInitialized == 2) {
- std::shared_ptr<GeomAPI_XY> aCoord =
- aPoints[0]->xy()->added(aPoints[1]->xy())->multiplied(0.5);
- double aRadius = aPoints[0]->distance(aPoints[1]) * 0.5;
- aCenterAttr->setValue(aCoord->x(), aCoord->y());
- aRadiusAttr->setValue(aRadius);
- } else {
- std::shared_ptr<GeomAPI_Circ2d> aCircle(
- new GeomAPI_Circ2d(aPoints[0], aPoints[1], aPoints[2]));
-
- std::shared_ptr<GeomAPI_Pnt2d> aCenter = aCircle->center();
- if (aCenter) {
- double aRadius = aCircle->radius();
- aCenterAttr->setValue(aCenter->x(), aCenter->y());
- aRadiusAttr->setValue(aRadius);
- }
- }
- data()->blockSendAttributeUpdated(aWasBlocked, false);
-
- } else if (theID == CIRCLE_TYPE()) { // if switched to 3 points mode, adjust the needed attributes
- std::string aType = std::dynamic_pointer_cast<ModelAPI_AttributeString>(
- data()->attribute(CIRCLE_TYPE()))->value();
- if (aType == CIRCLE_TYPE_THREE_POINTS()) {
- adjustThreePoints();
- }
- }
-}
-
-void SketchPlugin_Circle::adjustThreePoints()
-{
- std::shared_ptr<GeomDataAPI_Point2D> aCenterAttr =
- std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(CENTER_ID()));
- if (!aCenterAttr->isInitialized())
- return;
- AttributeDoublePtr aRadiusAttr =
- std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(attribute(RADIUS_ID()));
- if (!aRadiusAttr->isInitialized())
- return;
-
- bool aWasBlocked = data()->blockSendAttributeUpdated(true);
- std::shared_ptr<GeomDataAPI_Point2D> aFirstPnt =
- std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(FIRST_POINT_ID()));
- std::shared_ptr<GeomDataAPI_Point2D> aSecondPnt =
- std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(SECOND_POINT_ID()));
- std::shared_ptr<GeomDataAPI_Point2D> aThirdPnt =
- std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(THIRD_POINT_ID()));
- double aRadius = aRadiusAttr->value();
-
- bool isInitialized = aFirstPnt->isInitialized() &&
- aSecondPnt->isInitialized() && aThirdPnt->isInitialized();
-
- if (!isInitialized ||
- fabs(aFirstPnt->pnt()->distance(aCenterAttr->pnt()) - aRadius) > tolerance ||
- fabs(aSecondPnt->pnt()->distance(aCenterAttr->pnt()) - aRadius) > tolerance ||
- fabs(aThirdPnt->pnt()->distance(aCenterAttr->pnt()) - aRadius) > tolerance) {
- aFirstPnt->setValue(aCenterAttr->x() + aRadius, aCenterAttr->y());
- aSecondPnt->setValue(aCenterAttr->x(), aCenterAttr->y() + aRadius);
- aThirdPnt->setValue(aCenterAttr->x() - aRadius, aCenterAttr->y());
- }
- data()->blockSendAttributeUpdated(aWasBlocked, false);
}
#include "SketchPlugin.h"
#include <SketchPlugin_SketchEntity.h>
#include <SketchPlugin_Sketch.h>
-#include <GeomAPI_IPresentable.h>
/**\class SketchPlugin_Circle
* \ingroup Plugins
- * \brief Feature for creation of the new circle in PartSet.
+ * \brief Feature for creation of the new circle in Sketch.
*/
-class SketchPlugin_Circle : public SketchPlugin_SketchEntity, public GeomAPI_IPresentable
+class SketchPlugin_Circle: public SketchPlugin_SketchEntity
{
public:
/// Circle feature kind
inline static const std::string& ID()
{
- static const std::string MY_CIRCLE_ID("SketchCircle");
- return MY_CIRCLE_ID;
- }
-
- inline static const std::string& CIRCLE_TYPE()
- {
- static const std::string TYPE("CircleType");
- return TYPE;
- }
-
- /// Creation method by center and radius.
- inline static const std::string& CIRCLE_TYPE_CENTER_AND_RADIUS()
- {
- static const std::string TYPE("CenterRadius");
- return TYPE;
- }
-
- /// Creation method by three points.
- inline static const std::string& CIRCLE_TYPE_THREE_POINTS()
- {
- static const std::string TYPE("ThreePoints");
- return TYPE;
+ static const std::string ID("SketchCircle");
+ return ID;
}
/// 2D point - center of the circle
inline static const std::string& CENTER_ID()
{
- static const std::string MY_CIRCLE_CENTER_ID("CircleCenter");
- return MY_CIRCLE_CENTER_ID;
+ static const std::string ID("circle_center");
+ return ID;
}
/// Radius of the circle
inline static const std::string& RADIUS_ID()
{
- static const std::string MY_CIRCLE_RADIUS_ID("CircleRadius");
- return MY_CIRCLE_RADIUS_ID;
- }
-
- /// First point id.
- inline static const std::string& FIRST_POINT_ID()
- {
- static const std::string FIRST_PNT("FirstPoint");
- return FIRST_PNT;
- }
-
- /// Second point id.
- inline static const std::string& SECOND_POINT_ID()
- {
- static const std::string SECOND_PNT("SecondPoint");
- return SECOND_PNT;
- }
-
- /// Third point id.
- inline static const std::string& THIRD_POINT_ID()
- {
- static const std::string THIRD_PNT("ThirdPoint");
- return THIRD_PNT;
+ static const std::string ID("circle_radius");
+ return ID;
}
/// Returns the kind of a feature
/// Returns true is sketch element is under the rigid constraint
SKETCHPLUGIN_EXPORT virtual bool isFixed();
+ /// Called on change of any argument-attribute of this object
+ SKETCHPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID);
+
/// Creates a new part document if needed
SKETCHPLUGIN_EXPORT virtual void execute();
- /// Adds sub-feature of the higher level feature (sub-element of the sketch)
- /// \param theFeature sub-feature
- SKETCHPLUGIN_EXPORT virtual const void addSub(const FeaturePtr& theFeature)
- {
- }
-
/// Moves the feature
/// \param theDeltaX the delta for X coordinate is moved
/// \param theDeltaY the delta for Y coordinate is moved
SKETCHPLUGIN_EXPORT virtual void move(const double theDeltaX, const double theDeltaY);
- /// Called on change of any argument-attribute of this object
- SKETCHPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID);
-
- /// Returns the AIS preview
- virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious);
-
/// Use plugin manager for features creation
SketchPlugin_Circle();
protected:
/// \brief Initializes attributes of derived class.
virtual void initDerivedClassAttributes();
-
-private:
- /// Returns true if all obligatory attributes are initialized
- bool isFeatureValid();
-
- /// Update coordinates of representation by three points
- void adjustThreePoints();
};
#endif
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+
+// File: SketchPlugin_MacroCircle.cpp
+// Created: 26 May 2014
+// Author: Artem ZHIDKOV
+
+#include "SketchPlugin_MacroCircle.h"
+
+#include "SketchPlugin_Circle.h"
+#include "SketchPlugin_ConstraintCoincidence.h"
+#include "SketchPlugin_Tools.h"
+
+#include <ModelAPI_Data.h>
+#include <ModelAPI_Events.h>
+#include <ModelAPI_ResultConstruction.h>
+#include <ModelAPI_AttributeSelection.h>
+#include <ModelAPI_Validator.h>
+#include <ModelAPI_AttributeDouble.h>
+#include <ModelAPI_AttributeRefAttr.h>
+#include <ModelAPI_AttributeString.h>
+#include <ModelAPI_Session.h>
+
+#include <GeomAPI_Pnt2d.h>
+#include <GeomAPI_Circ.h>
+#include <GeomAPI_Circ2d.h>
+#include <GeomAPI_Vertex.h>
+#include <GeomAPI_XY.h>
+#include <GeomDataAPI_Point2D.h>
+#include <GeomDataAPI_Dir.h>
+#include <GeomAlgoAPI_PointBuilder.h>
+#include <GeomAlgoAPI_EdgeBuilder.h>
+#include <GeomAlgoAPI_CompoundBuilder.h>
+
+
+const double tolerance = 1e-7;
+
+namespace {
+ static const std::string& POINT_ID(int theIndex)
+ {
+ switch (theIndex) {
+ case 1: return SketchPlugin_MacroCircle::FIRST_POINT_ID();
+ case 2: return SketchPlugin_MacroCircle::SECOND_POINT_ID();
+ case 3: return SketchPlugin_MacroCircle::THIRD_POINT_ID();
+ }
+
+ static const std::string DUMMY;
+ return DUMMY;
+ }
+}
+
+
+SketchPlugin_MacroCircle::SketchPlugin_MacroCircle()
+: SketchPlugin_SketchEntity(),
+myRadius(0)
+{
+}
+
+void SketchPlugin_MacroCircle::initAttributes()
+{
+ data()->addAttribute(CIRCLE_TYPE(), ModelAPI_AttributeString::typeId());
+
+ data()->addAttribute(CENTER_POINT_ID(), GeomDataAPI_Point2D::typeId());
+ data()->addAttribute(CENTER_POINT_REF_ID(), ModelAPI_AttributeRefAttr::typeId());
+ data()->addAttribute(PASSED_POINT_ID(), GeomDataAPI_Point2D::typeId());
+ data()->addAttribute(PASSED_POINT_REF_ID(), ModelAPI_AttributeRefAttr::typeId());
+
+ data()->addAttribute(FIRST_POINT_ID(), GeomDataAPI_Point2D::typeId());
+ data()->addAttribute(SECOND_POINT_ID(), GeomDataAPI_Point2D::typeId());
+ data()->addAttribute(THIRD_POINT_ID(), GeomDataAPI_Point2D::typeId());
+
+ data()->addAttribute(CIRCLE_RADIUS_ID(), ModelAPI_AttributeDouble::typeId());
+ data()->addAttribute(AUXILIARY_ID(), ModelAPI_AttributeBoolean::typeId());
+
+ ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), CENTER_POINT_REF_ID());
+ ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), PASSED_POINT_REF_ID());
+}
+
+void SketchPlugin_MacroCircle::execute()
+{
+ // Create circle feature.
+ FeaturePtr aCircleFeature = sketch()->addFeature(SketchPlugin_Circle::ID());
+ std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+ aCircleFeature->attribute(SketchPlugin_Circle::CENTER_ID()))->setValue(myCenter->x(),
+ myCenter->y());
+ aCircleFeature->real(SketchPlugin_Circle::RADIUS_ID())->setValue(myRadius);
+ aCircleFeature->boolean(SketchPlugin_Circle::AUXILIARY_ID())
+ ->setValue(boolean(AUXILIARY_ID())->value());
+ aCircleFeature->execute();
+
+ myCenter.reset();
+ myRadius = 0;
+
+ // Create constraints.
+ SketchPlugin_Tools::createConstraint(this,
+ CENTER_POINT_REF_ID(),
+ aCircleFeature->attribute(SketchPlugin_Circle::CENTER_ID()),
+ NULL,
+ false);
+ SketchPlugin_Tools::createConstraint(this,
+ PASSED_POINT_REF_ID(),
+ NULL,
+ aCircleFeature->lastResult(),
+ true);
+}
+
+AISObjectPtr SketchPlugin_MacroCircle::getAISObject(AISObjectPtr thePrevious)
+{
+ if(!myCenter.get() || myRadius < tolerance) {
+ return AISObjectPtr();
+ }
+
+ SketchPlugin_Sketch* aSketch = sketch();
+ if(!aSketch) {
+ 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::shared_ptr<GeomAPI_Dir> aNormal = aNDir->dir();
+ GeomShapePtr aCircleShape = GeomAlgoAPI_EdgeBuilder::lineCircle(aCenter, aNormal, myRadius);
+ GeomShapePtr aCenterPointShape = GeomAlgoAPI_PointBuilder::vertex(aCenter);
+ if(!aCircleShape.get() || !aCenterPointShape.get()) {
+ return AISObjectPtr();
+ }
+
+ std::list<std::shared_ptr<GeomAPI_Shape> > aShapes;
+ aShapes.push_back(aCircleShape);
+ aShapes.push_back(aCenterPointShape);
+
+ std::shared_ptr<GeomAPI_Shape> aCompound = GeomAlgoAPI_CompoundBuilder::compound(aShapes);
+ AISObjectPtr anAIS = thePrevious;
+ if(!anAIS.get()) {
+ anAIS.reset(new GeomAPI_AISObject());
+ }
+ anAIS->createShape(aCompound);
+ return anAIS;
+}
+
+void SketchPlugin_MacroCircle::attributeChanged(const std::string& theID) {
+ // If circle type switched reset according attributes.
+ if(theID == CIRCLE_TYPE()) {
+ std::string aType = string(CIRCLE_TYPE())->value();
+ if(aType == CIRCLE_TYPE_BY_CENTER_AND_PASSED_POINTS()) {
+ resetAttribute(CENTER_POINT_ID());
+ resetAttribute(PASSED_POINT_ID());
+ } else if(aType == CIRCLE_TYPE_BY_THREE_POINTS()) {
+ resetAttribute(FIRST_POINT_ID());
+ resetAttribute(SECOND_POINT_ID());
+ resetAttribute(THIRD_POINT_ID());
+ }
+ myCenter.reset();
+ myRadius = 0;
+ } else if(theID == CENTER_POINT_ID() || theID == PASSED_POINT_ID()) {
+ std::shared_ptr<GeomDataAPI_Point2D> aCenterPointAttr =
+ std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(CENTER_POINT_ID()));
+ if(!aCenterPointAttr->isInitialized()) {
+ return;
+ }
+ std::shared_ptr<GeomDataAPI_Point2D> aPassedPointAttr =
+ std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(PASSED_POINT_ID()));
+ if(!aPassedPointAttr->isInitialized()) {
+ return;
+ }
+
+ myCenter = aCenterPointAttr->pnt();
+ myRadius = myCenter->distance(aPassedPointAttr->pnt());
+ } else if(theID == FIRST_POINT_ID() || theID == SECOND_POINT_ID() || theID == THIRD_POINT_ID()) {
+ std::shared_ptr<GeomAPI_Pnt2d> aPoints[3];
+ int aNbInitialized = 0;
+ for(int i = 1; i <= 3; ++i) {
+ std::shared_ptr<GeomDataAPI_Point2D> aCurPnt =
+ std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(POINT_ID(i)));
+ if(aCurPnt->isInitialized())
+ aPoints[aNbInitialized++] = aCurPnt->pnt();
+ }
+
+ if(aNbInitialized == 1) {
+ return;
+ } else if(aNbInitialized == 2) {
+ std::shared_ptr<GeomAPI_XY> aCenterXY =
+ aPoints[0]->xy()->added(aPoints[1]->xy())->multiplied(0.5);
+ myCenter.reset(new GeomAPI_Pnt2d(aCenterXY->x(), aCenterXY->y()));
+ myRadius = aPoints[0]->distance(aPoints[1]) * 0.5;
+ } else {
+ std::shared_ptr<GeomAPI_Circ2d> aCircle(
+ new GeomAPI_Circ2d(aPoints[0], aPoints[1], aPoints[2]));
+ myCenter = aCircle->center();
+ if(myCenter.get()) {
+ myRadius = aCircle->radius();
+ }
+ }
+ }
+
+ AttributeDoublePtr aRadiusAttr = real(CIRCLE_RADIUS_ID());
+ bool aWasBlocked = data()->blockSendAttributeUpdated(true);
+ aRadiusAttr->setValue(myRadius);
+ data()->blockSendAttributeUpdated(aWasBlocked, false);
+}
+
+void SketchPlugin_MacroCircle::resetAttribute(const std::string& theId)
+{
+ AttributePtr anAttr = attribute(theId);
+ if(anAttr.get()) {
+ anAttr->reset();
+ }
+}
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+
+// File: SketchPlugin_MacroCircle.h
+// Created: 26 May 2014
+// Author: Artem ZHIDKOV
+
+#ifndef SketchPlugin_MacroCircle_H_
+#define SketchPlugin_MacroCircle_H_
+
+#include "SketchPlugin.h"
+
+#include "SketchPlugin_Sketch.h"
+#include "SketchPlugin_SketchEntity.h"
+
+#include <GeomAPI_IPresentable.h>
+#include <GeomAPI_Pnt2d.h>
+
+/**\class SketchPlugin_MacroCircle
+ * \ingroup Plugins
+ * \brief Feature for creation of the new circle in Sketch.
+ */
+class SketchPlugin_MacroCircle: public SketchPlugin_SketchEntity,
+ public GeomAPI_IPresentable
+{
+ public:
+ /// Circle feature kind
+ inline static const std::string& ID()
+ {
+ static const std::string ID("SketchMacroCircle");
+ return ID;
+ }
+
+ inline static const std::string& CIRCLE_TYPE()
+ {
+ static const std::string ID("circle_type");
+ return ID;
+ }
+
+ /// Creation method by center and passed point.
+ inline static const std::string& CIRCLE_TYPE_BY_CENTER_AND_PASSED_POINTS()
+ {
+ static const std::string ID("circle_type_by_center_and_passed_points");
+ return ID;
+ }
+
+ /// Creation method by three points.
+ inline static const std::string& CIRCLE_TYPE_BY_THREE_POINTS()
+ {
+ static const std::string ID("circle_type_by_three_points");
+ return ID;
+ }
+
+ /// 2D point - center of the circle.
+ inline static const std::string& CENTER_POINT_ID()
+ {
+ static const std::string ID("center_point");
+ return ID;
+ }
+
+ /// Reference for center point selection.
+ inline static const std::string& CENTER_POINT_REF_ID()
+ {
+ static const std::string ID("center_point_ref");
+ return ID;
+ }
+
+ /// 2D point - passed point of the circle
+ inline static const std::string& PASSED_POINT_ID()
+ {
+ static const std::string ID("passed_point");
+ return ID;
+ }
+
+ /// Reference for passed point selection.
+ inline static const std::string& PASSED_POINT_REF_ID()
+ {
+ static const std::string ID("passed_point_ref");
+ return ID;
+ }
+
+ /// First point id.
+ inline static const std::string& FIRST_POINT_ID()
+ {
+ static const std::string ID("first_point");
+ return ID;
+ }
+
+ /// Second point id.
+ inline static const std::string& SECOND_POINT_ID()
+ {
+ static const std::string ID("second_point");
+ return ID;
+ }
+
+ /// Third point id.
+ inline static const std::string& THIRD_POINT_ID()
+ {
+ static const std::string ID("third_point");
+ return ID;
+ }
+
+ /// Radius of the circle
+ inline static const std::string& CIRCLE_RADIUS_ID()
+ {
+ static const std::string ID("circle_radius");
+ return ID;
+ }
+
+ /// Returns the kind of a feature
+ SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
+ {
+ static std::string MY_KIND = SketchPlugin_MacroCircle::ID();
+ return MY_KIND;
+ }
+
+ /// \brief Request for initialization of data model of the feature: adding all attributes.
+ SKETCHPLUGIN_EXPORT virtual void initAttributes();
+
+ /// Called on change of any argument-attribute of this object
+ SKETCHPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID);
+
+ /// Returns the AIS preview
+ virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious);
+
+ /// Creates a new part document if needed
+ SKETCHPLUGIN_EXPORT virtual void execute();
+
+ /// Moves the feature
+ /// \param theDeltaX the delta for X coordinate is moved
+ /// \param theDeltaY the delta for Y coordinate is moved
+ SKETCHPLUGIN_EXPORT virtual void move(const double theDeltaX, const double theDeltaY)
+ {};
+
+ /// Reimplemented from ModelAPI_Feature::isMacro().
+ /// \returns true
+ SKETCHPLUGIN_EXPORT virtual bool isMacro() const {return true;};
+
+ SKETCHPLUGIN_EXPORT virtual bool isPreviewNeeded() const {return false;};
+
+ /// Use plugin manager for features creation
+ SketchPlugin_MacroCircle();
+
+private:
+ void resetAttribute(const std::string& theId);
+
+private:
+ std::shared_ptr<GeomAPI_Pnt2d> myCenter;
+ double myRadius;
+};
+
+#endif
#include <SketchPlugin_ConstraintRigid.h>
#include <SketchPlugin_ConstraintTangent.h>
#include <SketchPlugin_ConstraintVertical.h>
+#include <SketchPlugin_MacroCircle.h>
#include <SketchPlugin_MultiRotation.h>
#include <SketchPlugin_MultiTranslation.h>
#include <SketchPlugin_Trim.h>
return FeaturePtr(new SketchPlugin_ConstraintAngle);
} else if (theFeatureID == SketchPlugin_Trim::ID()) {
return FeaturePtr(new SketchPlugin_Trim);
+ } else if (theFeatureID == SketchPlugin_MacroCircle::ID()) {
+ return FeaturePtr(new SketchPlugin_MacroCircle);
}
// feature of such kind is not found
return FeaturePtr();
aMsg->setState(SketchPlugin_MultiRotation::ID(), aHasSketchPlane);
aMsg->setState(SketchPlugin_MultiTranslation::ID(), aHasSketchPlane);
aMsg->setState(SketchPlugin_Trim::ID(), aHasSketchPlane);
+ aMsg->setState(SketchPlugin_MacroCircle::ID(), aHasSketchPlane);
// SketchRectangle is a python feature, so its ID is passed just as a string
aMsg->setState("SketchRectangle", aHasSketchPlane);
}
#include "SketchPlugin_Tools.h"
+#include "SketchPlugin_ConstraintCoincidence.h"
+#include "SketchPlugin_ConstraintTangent.h"
+#include "SketchPlugin_Point.h"
+#include "SketchPlugin_SketchEntity.h"
+
+#include <SketcherPrs_Tools.h>
+
+#include <ModelAPI_AttributeDouble.h>
+
#include <GeomDataAPI_Point.h>
#include <GeomDataAPI_Point2D.h>
-#include <ModelAPI_AttributeDouble.h>
-#include <SketcherPrs_Tools.h>
-#include <SketchPlugin_ConstraintCoincidence.h>
-#include <SketchPlugin_SketchEntity.h>
namespace SketchPlugin_Tools {
}
}
+void createConstraint(SketchPlugin_Feature* theFeature,
+ const std::string& theId,
+ const AttributePtr theAttr,
+ const ObjectPtr theObject,
+ const bool theIsCanBeTangent)
+{
+ AttributeRefAttrPtr aRefAttr = theFeature->refattr(theId);
+ if(aRefAttr.get() && aRefAttr->isInitialized()) {
+ FeaturePtr aConstraint;
+ if(!theIsCanBeTangent) {
+ aConstraint = theFeature->sketch()
+ ->addFeature(SketchPlugin_ConstraintCoincidence::ID());
+ } else {
+ if(aRefAttr->isObject()) {
+ ObjectPtr anObject = aRefAttr->object();
+ FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
+ if(aFeature->getKind() == SketchPlugin_Point::ID()) {
+ aConstraint = theFeature->sketch()
+ ->addFeature(SketchPlugin_ConstraintCoincidence::ID());
+ } else {
+ aConstraint = theFeature->sketch()
+ ->addFeature(SketchPlugin_ConstraintTangent::ID());
+ }
+ } else {
+ aConstraint = theFeature->sketch()
+ ->addFeature(SketchPlugin_ConstraintCoincidence::ID());
+ }
+ }
+ AttributeRefAttrPtr aRefAttrA = aConstraint->refattr(SketchPlugin_Constraint::ENTITY_A());
+ aRefAttr->isObject() ? aRefAttrA->setObject(aRefAttr->object())
+ : aRefAttrA->setAttr(aRefAttr->attr());
+ AttributeRefAttrPtr aRefAttrB = aConstraint->refattr(SketchPlugin_Constraint::ENTITY_B());
+ if(theObject.get()) {
+ aRefAttrB->setObject(theObject);
+ } else if(theAttr.get()) {
+ aRefAttrB->setAttr(theAttr);
+ }
+ }
+}
} // namespace SketchPlugin_Tools
#include <ModelAPI_Feature.h>
#include <ModelAPI_Attribute.h>
+class SketchPlugin_Feature;
+
namespace SketchPlugin_Tools {
/// Clears text expressions for all attributes of the feature
void findCoincidences(const FeaturePtr theStartCoin,
const std::string& theAttr,
std::set<FeaturePtr>& theList);
+
+/// Creates coincidence or tangent constraint.
+/// \param[in] theFeature to get selected attribute or object
+/// \param[in] theId ID of attribute where selection is.
+/// \param[in] theObject object for constraint
+/// \param[in] theIsCanBeTangent if true constraint can be tangent or coincidence, depending on
+/// the selection in the attribute with passed ID.
+void createConstraint(SketchPlugin_Feature* theFeature,
+ const std::string& theId,
+ const AttributePtr theAttr,
+ const ObjectPtr theObject,
+ const bool theIsCanBeTangent);
}; // namespace SketchPlugin_Tools
#endif // SKETCHPLUGIN_TOOLS_H_
\ No newline at end of file
</context>
<context>
- <name>SketchCircle:CircleRadius:GeomValidators_Positive</name>
+ <name>SketchMacroCircle:CircleRadius:GeomValidators_Positive</name>
<message>
<source>Double is not positive.</source>
<translation>Radius value is not positive</translation>
</message>
</context>
<context>
- <name>SketchCircle:Model_FeatureValidator</name>
+ <name>SketchMacroCircle:Model_FeatureValidator</name>
<message>
<source>Attribute "CircleCenter" is not initialized.</source>
<translation>A center point is not selected</translation>
</message>
</context>
<context>
- <name>SketchCircle:Model_FeatureValidator</name>
+ <name>SketchMacroCircle:Model_FeatureValidator</name>
<message>
<source>Attribute "FirstPoint" is not initialized.</source>
<translation>A first point is not selected</translation>
</message>
</context>
<context>
- <name>SketchCircle:Model_FeatureValidator</name>
+ <name>SketchMacroCircle:Model_FeatureValidator</name>
<message>
<source>Attribute "SecondPoint" is not initialized.</source>
<translation>A second point is not selected</translation>
</message>
</context>
<context>
- <name>SketchCircle:Model_FeatureValidator</name>
+ <name>SketchMacroCircle:Model_FeatureValidator</name>
<message>
<source>Attribute "ThirdPoint" is not initialized.</source>
<translation>A third point is not selected</translation>
</message>
</context>
<context>
- <name>SketchCircle:CircleCenter</name>
+ <name>SketchMacroCircle:CircleCenter</name>
<message>
<source>Attribute "CircleCenter" is locked by modification value in the viewer.</source>
<translation>Select a center point</translation>
</message>
</context>
<context>
- <name>SketchCircle:FirstPoint</name>
+ <name>SketchMacroCircle:FirstPoint</name>
<message>
<source>Attribute "FirstPoint" is locked by modification value in the viewer.</source>
<translation>Select a center point</translation>
</message>
</context>
<context>
- <name>SketchCircle:SecondPoint</name>
+ <name>SketchMacroCircle:SecondPoint</name>
<message>
<source>Attribute "SecondPoint" is locked by modification value in the viewer.</source>
<translation>Select a center point</translation>
</message>
</context>
<context>
- <name>SketchCircle:ThirdPoint</name>
+ <name>SketchMacroCircle:ThirdPoint</name>
<message>
<source>Attribute "ThirdPoint" is locked by modification value in the viewer.</source>
<translation>Select a center point</translation>
</message>
</context>
<context>
- <name>SketchCircle:CircleRadius</name>
+ <name>SketchMacroCircle:CircleRadius</name>
<message>
<source>Attribute "CircleRadius" is locked by modification value in the viewer.</source>
<translation>Select a radius distance</translation>
</message>
</context>
<context>
- <name>SketchCircle:CircleRadius:GeomValidators_Positive</name>
+ <name>SketchMacroCircle:CircleRadius:GeomValidators_Positive</name>
<message>
<source>Integer is not initialized.</source>
<translation>Integer radius is not initialized</translation>
</message>
</context>
<context>
- <name>SketchCircle:CircleRadius:GeomValidators_Positive</name>
+ <name>SketchMacroCircle:CircleRadius:GeomValidators_Positive</name>
<message>
<source>Integer is not positive.</source>
<translation>Integer radius must be set</translation>
</message>
</context>
<context>
- <name>SketchCircle:Model_FeatureValidator</name>
+ <name>SketchMacroCircle:Model_FeatureValidator</name>
<message>
<source>Attribute "CircleRadius" is not initialized.</source>
<translation>Set the circle radius</translation>
<group id="Linear geometry">
<feature
id="Sketch"
- nested="SketchPoint SketchIntersectionPoint SketchLine SketchCircle SketchArc
+ nested="SketchPoint SketchIntersectionPoint SketchLine
+ SketchCircle SketchMacroCircle SketchArc
SketchRectangle
SketchProjection
SketchConstraintLength SketchConstraintRadius SketchConstraintDistance
</feature>
</group>
<group id="Circular geometry">
- <!-- SketchCircle -->
- <feature
- id="SketchCircle"
- title="Circle"
- tooltip="Create circle"
- icon="icons/Sketch/circle.png">
- <toolbox id="CircleType">
- <box id="CenterRadius" title="Center and radius" icon="icons/Sketch/circle_pt_rad_32x32.png">
- <sketch-2dpoint_selector id="CircleCenter" accept_expressions="0" title="Center" tooltip="Center coordinates"
+ <!-- SketchCircle is a hidden feature. It is created inside SketchMacroCircle. -->
+ <feature id="SketchCircle"
+ title="Circle"
+ tooltip="Create circle"
+ icon="icons/Sketch/circle.png"
+ internal="1">
+ <sketch-2dpoint_selector id="circle_center"
+ title="Center"
+ tooltip="Center coordinates"
+ accept_expressions="0"
+ enable_value="enable_by_preferences"/>
+ <labelvalue id="circle_radius"
+ icon="icons/Sketch/radius.png"
+ label="Radius:"
+ tooltip="Set radius"
+ default="computed"
+ accept_expressions="0"
+ enable_value="enable_by_preferences">
+ </labelvalue>
+ <boolvalue id="Auxiliary" label="Auxiliary" default="false" tooltip="Construction element" obligatory="0"/>
+ </feature>
+ <!-- SketchMacroCircle -->
+ <feature id="SketchMacroCircle"
+ icon="icons/Sketch/circle.png"
+ title="Circle"
+ tooltip="Create circle">
+ <toolbox id="circle_type">
+ <box id="circle_type_by_center_and_passed_points"
+ icon="icons/Sketch/circle_pt_rad_32x32.png"
+ title="Center and passed points">
+ <sketch-2dpoint_selector id="center_point"
+ reference_attribute="center_point_ref"
+ title="Center point"
+ tooltip="Center point coordinates"
+ accept_expressions="0"
+ enable_value="enable_by_preferences"/>
+ <sketch-2dpoint_selector id="passed_point"
+ reference_attribute="passed_point_ref"
+ title="Passed point"
+ tooltip="Passed point coordinates"
+ accept_expressions="0"
enable_value="enable_by_preferences"/>
</box>
- <box id="ThreePoints" title="Three points" icon="icons/Sketch/circle_3pt_32x32.png">
- <sketch-2dpoint_selector id="FirstPoint" accept_expressions="0" title="First point" tooltip="First point"
+ <box id="circle_type_by_three_points"
+ icon="icons/Sketch/circle_3pt_32x32.png"
+ title="Three points">
+ <sketch-2dpoint_selector id="first_point"
+ title="First point"
+ tooltip="First point"
+ accept_expressions="0"
enable_value="enable_by_preferences"/>
- <sketch-2dpoint_selector id="SecondPoint" accept_expressions="0" title="Second point" tooltip="Second point"
+ <sketch-2dpoint_selector id="second_point"
+ title="Second point"
+ tooltip="Second point"
+ accept_expressions="0"
enable_value="enable_by_preferences"/>
- <sketch-2dpoint_selector id="ThirdPoint" accept_expressions="0" title="Third point" tooltip="Third point"
+ <sketch-2dpoint_selector id="third_point"
+ title="Third point"
+ tooltip="Third point"
+ accept_expressions="0"
enable_value="enable_by_preferences"/>
</box>
</toolbox>
- <point2ddistance id="CircleRadius" accept_expressions="0" first_point="CircleCenter" label="Radius:" min="0" step="1.0"
- default="0" icon="icons/Sketch/radius.png" tooltip="Set radius"
- enable_value="enable_by_preferences">
+ <labelvalue id="circle_radius"
+ icon="icons/Sketch/radius.png"
+ label="Radius:"
+ tooltip="Set radius"
+ default="computed"
+ accept_expressions="0"
+ obligatory="0"
+ enable_value="enable_by_preferences">
<validator id="GeomValidators_Positive"/>
- </point2ddistance>
- <boolvalue id="Auxiliary" label="Auxiliary" default="false" tooltip="Construction element" obligatory="0"/>
+ </labelvalue>
+ <boolvalue id="Auxiliary"
+ tooltip="Construction element"
+ label="Auxiliary"
+ default="false"
+ obligatory="0"/>
</feature>
<!-- SketchArc -->