X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSketchPlugin%2FSketchPlugin_Projection.cpp;h=eaf073c8b7702a9caeda15e061116fb724df09ee;hb=3f1a42a51c7de1911c75453ff7134593d7d2c6b1;hp=c4af99b80e70e34148bbe38c69067424be158264;hpb=0fe7f1dfd08e026cc2a6fe8561724416a7fc82f7;p=modules%2Fshaper.git diff --git a/src/SketchPlugin/SketchPlugin_Projection.cpp b/src/SketchPlugin/SketchPlugin_Projection.cpp index c4af99b80..eaf073c8b 100644 --- a/src/SketchPlugin/SketchPlugin_Projection.cpp +++ b/src/SketchPlugin/SketchPlugin_Projection.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -17,6 +18,7 @@ #include #include #include +#include #include #include @@ -44,6 +46,8 @@ void SketchPlugin_Projection::initDerivedClassAttributes() 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() @@ -53,10 +57,11 @@ 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()); + aConstr->setShape(aProjection->lastResult()->shape()); aConstr->setIsInHistory(false); + aConstr->setDisplayed(false); setResult(aConstr); aProjection->selection(EXTERNAL_ID())->setValue(lastResult(), lastResult()->shape()); @@ -97,12 +102,16 @@ void SketchPlugin_Projection::computeProjection(const std::string& theID) 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())) { DocumentPtr aDoc = sketch()->document(); - aDoc->removeFeature(aProjection); + + std::set aFeaturesToBeRemoved; + aFeaturesToBeRemoved.insert(aProjection); + ModelAPI_Tools::removeFeaturesAndReferences(aFeaturesToBeRemoved); aProjection = FeaturePtr(); aRefAttr->setObject(aProjection); } @@ -110,6 +119,13 @@ void SketchPlugin_Projection::computeProjection(const std::string& theID) std::shared_ptr aSketchPlane = sketch()->plane(); + ResultConstructionPtr aResult = + std::dynamic_pointer_cast(lastResult()); + if (aResult && aResult->shape()) { + aResult->setShape(std::shared_ptr()); + aProjection->selection(EXTERNAL_ID())->setValue(lastResult(), lastResult()->shape()); + } + if (anEdge->isLine()) { std::shared_ptr aFirst = aSketchPlane->project(anEdge->firstPoint()); std::shared_ptr aLast = aSketchPlane->project(anEdge->lastPoint()); @@ -119,7 +135,7 @@ void SketchPlugin_Projection::computeProjection(const std::string& theID) 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 @@ -137,7 +153,7 @@ void SketchPlugin_Projection::computeProjection(const std::string& theID) std::shared_ptr aCenter = aSketchPlane->project(aCircle->center()); std::shared_ptr aCenterInSketch = sketch()->to2D(aCenter); - if (!aProjection) + if (!hasPrevProj) aProjection = sketch()->addFeature(SketchPlugin_Circle::ID()); // update attributes of projection @@ -156,7 +172,7 @@ void SketchPlugin_Projection::computeProjection(const std::string& theID) std::shared_ptr aCenter = aSketchPlane->project(aCircle->center()); std::shared_ptr aCenterInSketch = sketch()->to2D(aCenter); - if (!aProjection) + if (!hasPrevProj) aProjection = sketch()->addFeature(SketchPlugin_Arc::ID()); // update attributes of projection @@ -174,6 +190,19 @@ void SketchPlugin_Projection::computeProjection(const std::string& theID) aProjection->execute(); aRefAttr->setObject(aProjection); - if (theID == EXTERNAL_FEATURE_ID()) - selection(EXTERNAL_ID())->setValue(aExtFeature->context(), aExtFeature->context()->shape()); + 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->value()); + + if (aResult) { + aResult->setShape(aProjection->lastResult()->shape()); + setResult(aResult); + aProjection->selection(EXTERNAL_ID())->setValue(lastResult(), lastResult()->shape()); + } + } }