From 39ba1d7a3f3f99ca0c53dfe64526063c5d5bda2d Mon Sep 17 00:00:00 2001 From: mpv Date: Mon, 10 Nov 2014 14:38:17 +0300 Subject: [PATCH] Issue #208 : update the sketch and sub-entities with updated plane in right way: sketch plane, then all subs, then all subs again (after solver processing), then sketch result itself. --- src/Model/Model_Update.cpp | 28 +++++++++++++++++++----- src/SketchPlugin/SketchPlugin_Circle.cpp | 1 + src/SketchPlugin/SketchPlugin_Line.cpp | 2 ++ src/SketchPlugin/SketchPlugin_Sketch.cpp | 2 ++ 4 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/Model/Model_Update.cpp b/src/Model/Model_Update.cpp index 4c23c9c30..cb511c8e3 100644 --- a/src/Model/Model_Update.cpp +++ b/src/Model/Model_Update.cpp @@ -179,12 +179,6 @@ bool Model_Update::updateFeature(FeaturePtr theFeature) if (updateFeature(aComposite->subFeature(a))) aMustbeUpdated = true; } - if (aMustbeUpdated) { - for(int a = 0; a < aSubsNum; a++) { - if (aComposite->subFeature(a) && aFactory->validate(aComposite->subFeature(a))) - aComposite->subFeature(a)->execute(); - } - } } // check all references: if referenced objects are updated, this object also must be updated std::list > > aRefs; @@ -201,6 +195,7 @@ bool Model_Update::updateFeature(FeaturePtr theFeature) } } + //std::cout<<"Update feature "<getKind()<<" must be updated = "<(theFeature->document())->executeFeatures() || @@ -209,6 +204,7 @@ bool Model_Update::updateFeature(FeaturePtr theFeature) if (isAutomatic || (myJustCreatedOrUpdated.find(theFeature) != myJustCreatedOrUpdated.end()) || !theFeature->isPersistentResult() /* execute quick, not persistent results */) { + //std::cout<<"Execute feature "<getKind()< aRefs = theFeature->data()->attributes(ModelAPI_AttributeSelection::type()); @@ -226,6 +222,26 @@ bool Model_Update::updateFeature(FeaturePtr theFeature) aSel->value(a)->update(); } } + // for sketch after update of plane (by update of selection attribute) + // but before execute, all sub-elements also must be updated (due to the plane changes) + if (aComposite) { + int aSubsNum = aComposite->numberOfSubs(); + for(int a = 0; a < aSubsNum; a++) { + FeaturePtr aSub = aComposite->subFeature(a); + bool aWasModified = myUpdated[aSub]; + myUpdated.erase(myUpdated.find(aSub)); // erase to update for sure (plane may be changed) + myInitial.insert(aSub); + updateFeature(aSub); + myUpdated[aSub] = aWasModified; // restore value + } + // re-execute after update: solver may update the previous values, so, shapes must be + // updated + for(int a = 0; a < aSubsNum; a++) { + if (aComposite->subFeature(a) && aFactory->validate(aComposite->subFeature(a))) + aComposite->subFeature(a)->execute(); + } + } + // execute in try-catch to avoid internal problems of the feature try { theFeature->execute(); diff --git a/src/SketchPlugin/SketchPlugin_Circle.cpp b/src/SketchPlugin/SketchPlugin_Circle.cpp index 3669232cb..a65a6b7c6 100644 --- a/src/SketchPlugin/SketchPlugin_Circle.cpp +++ b/src/SketchPlugin/SketchPlugin_Circle.cpp @@ -45,6 +45,7 @@ void SketchPlugin_Circle::execute() boost::dynamic_pointer_cast(data()->attribute(RADIUS_ID())); if (aCenterAttr->isInitialized() && aRadiusAttr->isInitialized()) { boost::shared_ptr aCenter(aSketch->to3D(aCenterAttr->x(), aCenterAttr->y())); + //std::cout<<"Execute circle "<x()<<" "<y()<<" "<z()< aCenterPointShape = GeomAlgoAPI_PointBuilder::point(aCenter); boost::shared_ptr aConstr1 = document()->createConstruction( diff --git a/src/SketchPlugin/SketchPlugin_Line.cpp b/src/SketchPlugin/SketchPlugin_Line.cpp index 22a466815..501478a32 100644 --- a/src/SketchPlugin/SketchPlugin_Line.cpp +++ b/src/SketchPlugin/SketchPlugin_Line.cpp @@ -44,6 +44,8 @@ void SketchPlugin_Line::execute() if (aStartAttr->isInitialized() && anEndAttr->isInitialized()) { boost::shared_ptr aStart(aSketch->to3D(aStartAttr->x(), aStartAttr->y())); boost::shared_ptr anEnd(aSketch->to3D(anEndAttr->x(), anEndAttr->y())); + //std::cout<<"Execute line "<x()<<" "<y()<<" "<z()<<" - " + // <x()<<" "<y()<<" "<z()< anEdge = GeomAlgoAPI_EdgeBuilder::line(aStart, anEnd); // store the result diff --git a/src/SketchPlugin/SketchPlugin_Sketch.cpp b/src/SketchPlugin/SketchPlugin_Sketch.cpp index 813ce28fb..e1ac62b0c 100644 --- a/src/SketchPlugin/SketchPlugin_Sketch.cpp +++ b/src/SketchPlugin/SketchPlugin_Sketch.cpp @@ -314,6 +314,7 @@ void SketchPlugin_Sketch::attributeChanged() { boost::shared_ptr aDir = aPlane->direction(); if (kIsAttrChanged) { + /* now it is in updater // the plane was changed, so reexecute sub-elements to update shapes (located in new plane) ModelAPI_ValidatorsFactory* aFactory = ModelAPI_Session::get()->validators(); list aSubs = data()->reflist(SketchPlugin_Sketch::FEATURES_ID())->list(); @@ -324,6 +325,7 @@ void SketchPlugin_Sketch::attributeChanged() { aFeature->execute(); } } + */ kIsAttrChanged = false; } } -- 2.30.2