From d0a227e8835b402a07478a3aa7597cf6af8e7f8d Mon Sep 17 00:00:00 2001 From: mpv Date: Thu, 30 Oct 2014 12:41:15 +0300 Subject: [PATCH] Fix for undo/redo inside of the sketch --- src/Model/Model_Data.h | 5 ++-- src/Model/Model_Document.cpp | 30 ++++++-------------- src/ModelAPI/ModelAPI_Data.h | 4 +++ src/PartSet/PartSet_OperationFeatureEdit.cpp | 2 +- src/SketchPlugin/SketchPlugin_Feature.cpp | 22 +++++--------- src/SketchPlugin/SketchPlugin_Feature.h | 2 +- 6 files changed, 25 insertions(+), 40 deletions(-) diff --git a/src/Model/Model_Data.h b/src/Model/Model_Data.h index cb7158b75..f23e684ca 100644 --- a/src/Model/Model_Data.h +++ b/src/Model/Model_Data.h @@ -152,13 +152,14 @@ class Model_Data : public ModelAPI_Data /// Returns the identifier of feature-owner, unique in this document MODEL_EXPORT virtual int featureId() const; + // returns all objects referenced to this + MODEL_EXPORT virtual const std::set& refsToMe() {return myRefsToMe;} + private: // removes all information about back references void eraseBackReferences(); // adds a back reference (with identifier which attribute references to this object void addBackReference(FeaturePtr theFeature, std::string theAttrID); - // returns all objects referenced to this - const std::set& refsToMe() {return myRefsToMe;} // returns all references by attributes of this data // \param the returned list of pairs: id of referenced attribute and list of referenced objects void referencesToObjects(std::list > >& theRefs); diff --git a/src/Model/Model_Document.cpp b/src/Model/Model_Document.cpp index cb05a7fbb..6251a36d8 100644 --- a/src/Model/Model_Document.cpp +++ b/src/Model/Model_Document.cpp @@ -702,29 +702,30 @@ void Model_Document::synchronizeFeatures(const bool theMarkUpdated, const bool t TDF_ChildIDIterator aLabIter(featuresLabel(), TDataStd_Comment::GetID()); for (; aLabIter.More(); aLabIter.Next()) { TDF_Label aFeatureLabel = aLabIter.Value()->Label(); + FeaturePtr aFeature; if (!myObjs.IsBound(aFeatureLabel)) { // a new feature is inserted // create a feature - FeaturePtr aNewObj = ModelAPI_Session::get()->createFeature( + aFeature = ModelAPI_Session::get()->createFeature( TCollection_AsciiString(Handle(TDataStd_Comment)::DownCast(aLabIter.Value())->Get()) .ToCString()); - if (!aNewObj) { // somethig is wrong, most probably, the opened document has invalid structure + if (!aFeature) { // somethig is wrong, most probably, the opened document has invalid structure Events_Error::send("Invalid type of object in the document"); aLabIter.Value()->Label().ForgetAllAttributes(); continue; } // this must be before "setData" to redo the sketch line correctly - myObjs.Bind(aFeatureLabel, aNewObj); - aNewFeatures.insert(aNewObj); - initData(aNewObj, aFeatureLabel, TAG_FEATURE_ARGUMENTS); + myObjs.Bind(aFeatureLabel, aFeature); + aNewFeatures.insert(aFeature); + initData(aFeature, aFeatureLabel, TAG_FEATURE_ARGUMENTS); // event: model is updated static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_CREATED); - ModelAPI_EventCreator::get()->sendUpdated(aNewObj, anEvent); + ModelAPI_EventCreator::get()->sendUpdated(aFeature, anEvent); // update results of the appeared feature - updateResults(aNewObj); + updateResults(aFeature); } else { // nothing is changed, both iterators are incremented - FeaturePtr aFeature = myObjs.Find(aFeatureLabel); + aFeature = myObjs.Find(aFeatureLabel); aKeptFeatures.insert(aFeature); if (theMarkUpdated) { static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED); @@ -733,11 +734,6 @@ void Model_Document::synchronizeFeatures(const bool theMarkUpdated, const bool t updateResults(aFeature); } } - // execute new features to restore results: after features creation to make all references valid - /*std::set::iterator aNewIter = aNewFeatures.begin(); - for(; aNewIter != aNewFeatures.end(); aNewIter++) { - (*aNewIter)->execute(); - }*/ // check all features are checked: if not => it was removed NCollection_DataMap::Iterator aFIter(myObjs); while (aFIter.More()) { @@ -752,14 +748,6 @@ void Model_Document::synchronizeFeatures(const bool theMarkUpdated, const bool t static Events_ID EVENT_DISP = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY); const std::list >& aResults = aFeature->results(); std::list >::const_iterator aRIter = aResults.begin(); - /* - for (; aRIter != aResults.cend(); aRIter++) { - boost::shared_ptr aRes = *aRIter; - //aRes->setData(boost::shared_ptr()); // deleted flag - ModelAPI_EventCreator::get()->sendUpdated(aRes, EVENT_DISP); - ModelAPI_EventCreator::get()->sendDeleted(aThis, aRes->groupName()); - } - */ // redisplay also removed feature (used for sketch and AISObject) ModelAPI_EventCreator::get()->sendUpdated(aFeature, EVENT_DISP); aFeature->erase(); diff --git a/src/ModelAPI/ModelAPI_Data.h b/src/ModelAPI/ModelAPI_Data.h index 2acf4fc6b..191345f1a 100644 --- a/src/ModelAPI/ModelAPI_Data.h +++ b/src/ModelAPI/ModelAPI_Data.h @@ -8,6 +8,7 @@ #include "ModelAPI.h" #include #include +#include #include class ModelAPI_AttributeDocRef; @@ -109,6 +110,9 @@ class MODELAPI_EXPORT ModelAPI_Data /// Returns the identifier of feature-owner, unique in this document virtual int featureId() const = 0; + // returns all objects referenced to this + virtual const std::set >& refsToMe() = 0; + protected: /// Objects are created for features automatically ModelAPI_Data() diff --git a/src/PartSet/PartSet_OperationFeatureEdit.cpp b/src/PartSet/PartSet_OperationFeatureEdit.cpp index a9d85bb8c..517c77cae 100644 --- a/src/PartSet/PartSet_OperationFeatureEdit.cpp +++ b/src/PartSet/PartSet_OperationFeatureEdit.cpp @@ -249,7 +249,7 @@ void PartSet_OperationFeatureEdit::mouseMoved(QMouseEvent* theEvent, ModuleBase_ // the feature is moved only if there is no a local selection on this feature if (!isMoved) { // MPV: added condition because it could be external edge of some object, not sketch - if (aSketchFeature && aSketchFeature->sketch() == sketch().get()) { + if (aSketchFeature && sketch()->isSub(aSketchFeature)) { aSketchFeature->move(aDeltaX, aDeltaY); static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY); ModelAPI_EventCreator::get()->sendUpdated(feature(), anEvent); diff --git a/src/SketchPlugin/SketchPlugin_Feature.cpp b/src/SketchPlugin/SketchPlugin_Feature.cpp index da25c0999..2d46d8ca1 100644 --- a/src/SketchPlugin/SketchPlugin_Feature.cpp +++ b/src/SketchPlugin/SketchPlugin_Feature.cpp @@ -11,31 +11,23 @@ SketchPlugin_Feature::SketchPlugin_Feature() mySketch = 0; } -/* SketchPlugin_Sketch* SketchPlugin_Feature::sketch() { if (!mySketch) { // find sketch that references to this feature - int aSketches = document()->size(ModelAPI_Feature::group()); - for (int a = 0; a < aSketches && !mySketch; a++) { - ObjectPtr anObj = document()->object(ModelAPI_Feature::group(), a); + const std::set& aBackRefs = data()->refsToMe(); + std::set::const_iterator aBackRef = aBackRefs.begin(); + for(; aBackRef != aBackRefs.end(); aBackRef++) { boost::shared_ptr aSketch = - boost::dynamic_pointer_cast(anObj); + boost::dynamic_pointer_cast((*aBackRef)->owner()); if (aSketch) { - std::list aList = aSketch->data()->reflist(SketchPlugin_Sketch::FEATURES_ID()) - ->list(); - std::list::iterator aSub = aList.begin(); - for (; aSub != aList.end(); aSub++) { - if ((*aSub)->data()->isEqual(data())) { - mySketch = aSketch.get(); - break; - } - } + mySketch = aSketch.get(); + break; } } } return mySketch; -}*/ +} AISObjectPtr SketchPlugin_Feature::simpleAISObject(boost::shared_ptr theRes, AISObjectPtr thePrevious) diff --git a/src/SketchPlugin/SketchPlugin_Feature.h b/src/SketchPlugin/SketchPlugin_Feature.h index 97a2d423b..8c022ed2b 100644 --- a/src/SketchPlugin/SketchPlugin_Feature.h +++ b/src/SketchPlugin/SketchPlugin_Feature.h @@ -56,7 +56,7 @@ class SketchPlugin_Feature : public ModelAPI_Feature SKETCHPLUGIN_EXPORT virtual bool isFixed() {return false;} /// Returns the sketch of this feature - inline SketchPlugin_Sketch* sketch() {return mySketch;} + SketchPlugin_Sketch* sketch(); protected: /// Sets the higher-level feature for the sub-feature (sketch for line) void setSketch(SketchPlugin_Sketch* theSketch) -- 2.39.2