#include <ModelAPI_Session.h>
#include <GeomAPI_Circ2d.h>
+#include <GeomAPI_Circ.h>
#include <GeomAPI_Pnt2d.h>
#include <GeomDataAPI_Point2D.h>
#include <GeomDataAPI_Dir.h>
const double tolerance = 1e-7;
SketchPlugin_Arc::SketchPlugin_Arc()
- : SketchPlugin_Feature()
+ : SketchPlugin_SketchEntity()
{
myStartUpdate = false;
myEndUpdate = false;
void SketchPlugin_Arc::initAttributes()
{
- data()->addAttribute(CENTER_ID(), GeomDataAPI_Point2D::type());
- data()->addAttribute(START_ID(), GeomDataAPI_Point2D::type());
- data()->addAttribute(END_ID(), GeomDataAPI_Point2D::type());
- data()->addAttribute(EXTERNAL_ID(), ModelAPI_AttributeSelection::type());
+ SketchPlugin_SketchEntity::initAttributes();
+
+ data()->addAttribute(CENTER_ID(), GeomDataAPI_Point2D::typeId());
+ data()->addAttribute(START_ID(), GeomDataAPI_Point2D::typeId());
+ data()->addAttribute(END_ID(), GeomDataAPI_Point2D::typeId());
+ data()->addAttribute(EXTERNAL_ID(), ModelAPI_AttributeSelection::typeId());
ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), EXTERNAL_ID());
}
if (!aData->isValid())
return;
- std::shared_ptr<GeomDataAPI_Point2D> aPoint1 = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
- aData->attribute(SketchPlugin_Arc::CENTER_ID()));
- aPoint1->move(theDeltaX, theDeltaY);
-
myStartUpdate = true;
myEndUpdate = true;
std::shared_ptr<GeomDataAPI_Point2D> aPoint2 = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
aPoint3->move(theDeltaX, theDeltaY);
myStartUpdate = false;
myEndUpdate = false;
+
+ std::shared_ptr<GeomDataAPI_Point2D> aPoint1 = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+ aData->attribute(SketchPlugin_Arc::CENTER_ID()));
+ aPoint1->move(theDeltaX, theDeltaY);
}
double SketchPlugin_Arc::distanceToPoint(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint)
}
bool SketchPlugin_Arc::isFixed() {
- return data()->selection(EXTERNAL_ID())->context().get();
+ return data()->selection(EXTERNAL_ID())->context().get() != NULL;
}
bool SketchPlugin_Arc::isFeatureValid()
{
std::shared_ptr<GeomDataAPI_Point2D> aCenterAttr = std::dynamic_pointer_cast<
GeomDataAPI_Point2D>(data()->attribute(CENTER_ID()));
- if (!aCenterAttr->isInitialized())
- return;
std::shared_ptr<GeomDataAPI_Point2D> aStartAttr = std::dynamic_pointer_cast<
GeomDataAPI_Point2D>(data()->attribute(START_ID()));
- if (!aStartAttr->isInitialized())
- return;
std::shared_ptr<GeomDataAPI_Point2D> anEndAttr = std::dynamic_pointer_cast<
GeomDataAPI_Point2D>(data()->attribute(END_ID()));
+ // the second condition for unability to move external segments anywhere
+ if (theID == EXTERNAL_ID() || isFixed()) {
+ std::shared_ptr<GeomAPI_Shape> aSelection = data()->selection(EXTERNAL_ID())->value();
+ // update arguments due to the selection value
+ if (aSelection && !aSelection->isNull() && aSelection->isEdge()) {
+ std::shared_ptr<GeomAPI_Edge> anEdge( new GeomAPI_Edge(aSelection));
+ std::shared_ptr<GeomAPI_Circ> aCirc = anEdge->circle();
+ if (aCirc.get()) {
+ aStartAttr->setValue(sketch()->to2D(anEdge->firstPoint()));
+ anEndAttr->setValue(sketch()->to2D(anEdge->lastPoint()));
+ aCenterAttr->setValue(sketch()->to2D(aCirc->center()));
+ }
+ }
+ return;
+ }
+ if (!aCenterAttr->isInitialized())
+ return;
+ if (!aStartAttr->isInitialized())
+ return;
if (!anEndAttr->isInitialized())
return;