#include <SketchPlugin_Circle.h>
#include <SketchPlugin_Line.h>
#include <SketchPlugin_Sketch.h>
+#include <SketchPlugin_ConstraintRigid.h>
#include <ModelAPI_AttributeRefAttr.h>
#include <ModelAPI_AttributeSelection.h>
static const double tolerance = 1.e-7;
+static std::shared_ptr<GeomAPI_Edge> emptyEdge()
+{
+ static std::shared_ptr<GeomAPI_Edge> anEdge(new GeomAPI_Edge);
+ return anEdge;
+}
+
SketchPlugin_Projection::SketchPlugin_Projection()
: SketchPlugin_SketchEntity(),
myIsComputing(false)
data()->addAttribute(EXTERNAL_ID(), ModelAPI_AttributeSelection::typeId());
ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), EXTERNAL_ID());
+
+ ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), AUXILIARY_ID());
}
void SketchPlugin_Projection::execute()
return;
FeaturePtr aProjection = ModelAPI_Feature::feature(aRefAttr->object());
- if (!lastResult()) {
+ if (!lastResult().get() && aProjection->lastResult().get()) {
ResultConstructionPtr aConstr = document()->createConstruction(data());
- aConstr->setShape(std::shared_ptr<GeomAPI_Edge>());
+ aConstr->setShape(emptyEdge());
aConstr->setIsInHistory(false);
+ aConstr->setDisplayed(false);
setResult(aConstr);
aProjection->selection(EXTERNAL_ID())->setValue(lastResult(), lastResult()->shape());
aProjection = ModelAPI_Feature::feature(aRefAttr->object());
// if the type of feature differs with already selected, remove it and create once again
- if (aProjection) {
+ bool hasPrevProj = aProjection.get() != 0;
+ if (hasPrevProj) {
if ((anEdge->isLine() && aProjection->getKind() != SketchPlugin_Line::ID()) ||
(anEdge->isCircle() && aProjection->getKind() != SketchPlugin_Circle::ID()) ||
(anEdge->isArc() && aProjection->getKind() != SketchPlugin_Arc::ID())) {
std::shared_ptr<GeomAPI_Pln> aSketchPlane = sketch()->plane();
+ ResultConstructionPtr aResult =
+ std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(lastResult());
+ if (aResult && aResult->shape()) {
+ aResult->setShape(std::shared_ptr<GeomAPI_Edge>());
+ aProjection->selection(EXTERNAL_ID())->setValue(lastResult(), lastResult()->shape());
+ }
+
if (anEdge->isLine()) {
std::shared_ptr<GeomAPI_Pnt> aFirst = aSketchPlane->project(anEdge->firstPoint());
std::shared_ptr<GeomAPI_Pnt> aLast = aSketchPlane->project(anEdge->lastPoint());
if (aFirstInSketch->distance(aLastInSketch) < tolerance)
return; // line is semi-orthogonal to the sketch plane
- if (!aProjection)
+ if (!hasPrevProj)
aProjection = sketch()->addFeature(SketchPlugin_Line::ID());
// update attributes of projection
std::shared_ptr<GeomAPI_Pnt> aCenter = aSketchPlane->project(aCircle->center());
std::shared_ptr<GeomAPI_Pnt2d> aCenterInSketch = sketch()->to2D(aCenter);
- if (!aProjection)
+ if (!hasPrevProj)
aProjection = sketch()->addFeature(SketchPlugin_Circle::ID());
// update attributes of projection
std::shared_ptr<GeomAPI_Pnt> aCenter = aSketchPlane->project(aCircle->center());
std::shared_ptr<GeomAPI_Pnt2d> aCenterInSketch = sketch()->to2D(aCenter);
- if (!aProjection)
+ if (!hasPrevProj)
aProjection = sketch()->addFeature(SketchPlugin_Arc::ID());
// update attributes of projection
aProjection->execute();
aRefAttr->setObject(aProjection);
- if (theID == EXTERNAL_FEATURE_ID())
+ if (!hasPrevProj) {
+ FeaturePtr aFixed = sketch()->addFeature(SketchPlugin_ConstraintRigid::ID());
+ aFixed->refattr(SketchPlugin_Constraint::ENTITY_A())->setObject(aProjection->lastResult());
+ aFixed->execute();
+ }
+
+ if (theID == EXTERNAL_FEATURE_ID()) {
selection(EXTERNAL_ID())->setValue(aExtFeature->context(), aExtFeature->context()->shape());
+
+ if (aResult) {
+ aResult->setShape(emptyEdge());
+ setResult(aResult);
+ aProjection->selection(EXTERNAL_ID())->setValue(lastResult(), lastResult()->shape());
+ }
+ }
}