From: mpv Date: Wed, 16 Jul 2014 06:31:40 +0000 (+0400) Subject: Make result part as a container of the document X-Git-Tag: V_0.4.4~181 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=63e86d82608e83f49339f946a8a3f5ebcaa0f7b5;p=modules%2Fshaper.git Make result part as a container of the document --- diff --git a/src/Model/Model_ResultPart.cpp b/src/Model/Model_ResultPart.cpp index b3602c0b5..75b2f8b41 100644 --- a/src/Model/Model_ResultPart.cpp +++ b/src/Model/Model_ResultPart.cpp @@ -19,3 +19,11 @@ boost::shared_ptr Model_ResultPart::owner() Model_ResultPart::Model_ResultPart() { } + +void Model_ResultPart::setData(boost::shared_ptr theData) +{ + ModelAPI_Result::setData(theData); + if (theData) { + data()->addAttribute(DOC_REF(), ModelAPI_AttributeDocRef::type()); + } +} diff --git a/src/Model/Model_ResultPart.h b/src/Model/Model_ResultPart.h index 26c19fc0c..4408690d8 100644 --- a/src/Model/Model_ResultPart.h +++ b/src/Model/Model_ResultPart.h @@ -27,6 +27,9 @@ protected: /// makes a result on a temporary feature (an action) Model_ResultPart(); + /// Sets the data manager of an object (document does), here also attributes are initialized + virtual void setData(boost::shared_ptr theData); + friend class Model_Document; }; diff --git a/src/ModelAPI/ModelAPI_Feature.h b/src/ModelAPI/ModelAPI_Feature.h index 59c0e4537..3770c06f0 100644 --- a/src/ModelAPI/ModelAPI_Feature.h +++ b/src/ModelAPI/ModelAPI_Feature.h @@ -46,7 +46,7 @@ public: std::list >& results() {return myResults;} /// returns the first result in the list or NULL reference boost::shared_ptr firstResult() - {return myResults.size() ? *(myResults.begin()) : boost::shared_ptr();} + {return myResults.empty() ? boost::shared_ptr() : *(myResults.begin());} /// sets the alone result void setResult(const boost::shared_ptr& theResult) {myResults.clear(); myResults.push_back(theResult);} diff --git a/src/ModelAPI/ModelAPI_ResultPart.h b/src/ModelAPI/ModelAPI_ResultPart.h index 4e3058b6b..82e0cee5d 100644 --- a/src/ModelAPI/ModelAPI_ResultPart.h +++ b/src/ModelAPI/ModelAPI_ResultPart.h @@ -25,6 +25,13 @@ public: static std::string group() {static std::string MY_GROUP = "Parts"; return MY_GROUP;} + /// part document reference attribute + inline static const std::string& DOC_REF() + { + static const std::string MY_DOC_REF("PartDocument"); + return MY_DOC_REF; + } + /// Returns the part-document of this result virtual boost::shared_ptr partDoc() = 0; }; diff --git a/src/PartSetPlugin/PartSetPlugin_Duplicate.cpp b/src/PartSetPlugin/PartSetPlugin_Duplicate.cpp index d1032abf8..2307e0906 100644 --- a/src/PartSetPlugin/PartSetPlugin_Duplicate.cpp +++ b/src/PartSetPlugin/PartSetPlugin_Duplicate.cpp @@ -7,6 +7,7 @@ #include #include #include +#include using namespace std; @@ -19,7 +20,9 @@ void PartSetPlugin_Duplicate::initAttributes() PartSetPlugin_Part::initAttributes(); data()->addAttribute(PartSetPlugin_Duplicate::DOC_REF(), ModelAPI_AttributeRefAttr::type()); - boost::shared_ptr aRef = data()->refattr(PartSetPlugin_Duplicate::DOC_REF()); + ResultPartPtr aResult = boost::dynamic_pointer_cast(firstResult()); + boost::shared_ptr aRef = + aResult->data()->refattr(ModelAPI_ResultPart::DOC_REF()); if (!aRef->attr()) { // create a copy: if not created yet attribute is not initialized boost::shared_ptr aPManager = ModelAPI_PluginManager::get(); boost::shared_ptr aRoot = aPManager->rootDocument(); @@ -27,13 +30,13 @@ void PartSetPlugin_Duplicate::initAttributes() for(int a = aRoot->size(getGroup()) - 1; a >= 0; a--) { aSource = boost::dynamic_pointer_cast( aRoot->object(ModelAPI_Feature::group(), a)); - if (aSource->data()->docRef(PartSetPlugin_Part::DOC_REF())->value() == aPManager->currentDocument()) + if (aSource->data()->docRef(ModelAPI_ResultPart::DOC_REF())->value() == aPManager->currentDocument()) break; aSource.reset(); } if (aSource) { boost::shared_ptr aCopy = - aPManager->copy(aSource->data()->docRef(PartSetPlugin_Part::DOC_REF())->value(), data()->name()); + aPManager->copy(aSource->data()->docRef(ModelAPI_ResultPart::DOC_REF())->value(), data()->name()); aRef->setObject(aSource); } } diff --git a/src/PartSetPlugin/PartSetPlugin_Part.cpp b/src/PartSetPlugin/PartSetPlugin_Part.cpp index c8beaeac9..e2b47f4ce 100644 --- a/src/PartSetPlugin/PartSetPlugin_Part.cpp +++ b/src/PartSetPlugin/PartSetPlugin_Part.cpp @@ -16,23 +16,24 @@ PartSetPlugin_Part::PartSetPlugin_Part() } void PartSetPlugin_Part::initAttributes() -{ - data()->addAttribute(PartSetPlugin_Part::DOC_REF(), ModelAPI_AttributeDocRef::type()); +{// all is in part result } void PartSetPlugin_Part::execute() { - boost::shared_ptr aDocRef = data()->docRef(PartSetPlugin_Part::DOC_REF()); + ResultPartPtr aResult = boost::dynamic_pointer_cast(firstResult()); + if (!aResult) { + aResult = document()->createPart(data()); + setResult(aResult); + } + boost::shared_ptr aDocRef = + aResult->data()->docRef(ModelAPI_ResultPart::DOC_REF()); + if (!aDocRef->value()) { // create a document if not yet created boost::shared_ptr aPartSetDoc = ModelAPI_PluginManager::get()->rootDocument(); aDocRef->setValue(aPartSetDoc->subDocument(data()->name())); } - // create a result only once - if (results().empty()) { - boost::shared_ptr aResult = document()->createPart(data()); - setResult(aResult); - } } boost::shared_ptr PartSetPlugin_Part::documentToAdd() { diff --git a/src/PartSetPlugin/PartSetPlugin_Part.h b/src/PartSetPlugin/PartSetPlugin_Part.h index cd656b18e..7eb27f5ac 100644 --- a/src/PartSetPlugin/PartSetPlugin_Part.h +++ b/src/PartSetPlugin/PartSetPlugin_Part.h @@ -21,12 +21,6 @@ public: static const std::string MY_PART_KIND("Part"); return MY_PART_KIND; } - /// part reference attribute - inline static const std::string& DOC_REF() - { - static const std::string MY_DOC_REF("PartDocument"); - return MY_DOC_REF; - } /// Returns the kind of a feature PARTSETPLUGIN_EXPORT virtual const std::string& getKind() {static std::string MY_KIND = PartSetPlugin_Part::ID(); return MY_KIND;} diff --git a/src/PartSetPlugin/PartSetPlugin_Remove.cpp b/src/PartSetPlugin/PartSetPlugin_Remove.cpp index ca3173728..f352aa39e 100644 --- a/src/PartSetPlugin/PartSetPlugin_Remove.cpp +++ b/src/PartSetPlugin/PartSetPlugin_Remove.cpp @@ -7,6 +7,7 @@ #include #include #include +#include void PartSetPlugin_Remove::execute() { @@ -20,9 +21,10 @@ void PartSetPlugin_Remove::execute() if (aFeature->getKind() == PartSetPlugin_Part::ID()) { boost::shared_ptr aPart = boost::static_pointer_cast(aFeature); - if (aPart->data()->docRef(PartSetPlugin_Part::DOC_REF())->value() == aPManager->currentDocument()) { + if (aPart->data()->docRef(ModelAPI_ResultPart::DOC_REF())->value() == + aPManager->currentDocument()) { // do remove - aPart->data()->docRef(PartSetPlugin_Part::DOC_REF())->value()->close(); + aPart->data()->docRef(ModelAPI_ResultPart::DOC_REF())->value()->close(); aRoot->removeFeature(aPart); } }