From: mpv Date: Tue, 17 Mar 2015 08:21:15 +0000 (+0300) Subject: Make initialization plugin: X-Git-Tag: V_1.1.0~125^2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=ca1d32b5d900a39c50749271b5dec53ed59c82af;p=modules%2Fshaper.git Make initialization plugin: - make features in every new document (not loaded) - called for PartSet without checking the transactions - creates features without history --- diff --git a/src/Config/plugins.xml b/src/Config/plugins.xml index 7ac11fe50..212647ece 100644 --- a/src/Config/plugins.xml +++ b/src/Config/plugins.xml @@ -1,13 +1,14 @@ + + - diff --git a/src/InitializationPlugin/InitializationPlugin_Plugin.cpp b/src/InitializationPlugin/InitializationPlugin_Plugin.cpp index fce2a1a2d..4ad9d0a95 100644 --- a/src/InitializationPlugin/InitializationPlugin_Plugin.cpp +++ b/src/InitializationPlugin/InitializationPlugin_Plugin.cpp @@ -1,4 +1,3 @@ - // Copyright (C) 2014-20xx CEA/DEN, EDF R&D #include @@ -7,38 +6,23 @@ #include #include #include - +#include #include - -#include -#include +#include #include -#ifdef _DEBUG -#include -#endif - // the only created instance of this plugin static InitializationPlugin_Plugin* MY_INITIALIZATIONPLUGIN_INSTANCE = new InitializationPlugin_Plugin(); InitializationPlugin_Plugin::InitializationPlugin_Plugin() { - // register this plugin - SessionPtr aSession = ModelAPI_Session::get(); - aSession->registerPlugin(this); - Events_Loop* aLoop = Events_Loop::loop(); const Events_ID kDocCreatedEvent = ModelAPI_DocumentCreatedMessage::eventId(); aLoop->registerListener(this, kDocCreatedEvent, NULL, true); } -FeaturePtr InitializationPlugin_Plugin::createFeature(std::string theFeatureID) -{ - return FeaturePtr(); -} - void InitializationPlugin_Plugin::processEvent(const std::shared_ptr& theMessage) { const Events_ID kDocCreatedEvent = ModelAPI_DocumentCreatedMessage::eventId(); @@ -50,11 +34,12 @@ void InitializationPlugin_Plugin::processEvent(const std::shared_ptrflush(Events_Loop::eventByName(EVENT_OBJECT_CREATED)); } else if (theMessage.get()) { - #ifdef _DEBUG - std::cout << "InitializationPlugin_Plugin::processEvent: unhandled message caught: " << std::endl - << theMessage->eventID().eventText() << std::endl; - #endif + Events_Error::send( + std::string("InitializationPlugin_Plugin::processEvent: unhandled message caught: ") + + theMessage->eventID().eventText()); } } @@ -74,6 +59,7 @@ void InitializationPlugin_Plugin::createPlane(DocumentPtr theDoc, double theA, d } else if (theC) { aPlane->data()->setName("X0Y"); } + aPlane->setInHistory(aPlane, false); // don't show automatically created feature in the features history } void InitializationPlugin_Plugin::createPoint(DocumentPtr theDoc) @@ -83,5 +69,5 @@ void InitializationPlugin_Plugin::createPoint(DocumentPtr theDoc) aPoint->real("y")->setValue(0.); aPoint->real("z")->setValue(0.); aPoint->data()->setName("Origin"); + aPoint->setInHistory(aPoint, false); // don't show automatically created feature in the features history } - diff --git a/src/InitializationPlugin/InitializationPlugin_Plugin.h b/src/InitializationPlugin/InitializationPlugin_Plugin.h index bd5c1a219..bbd9e4aa0 100644 --- a/src/InitializationPlugin/InitializationPlugin_Plugin.h +++ b/src/InitializationPlugin/InitializationPlugin_Plugin.h @@ -6,7 +6,6 @@ #include -#include #include #include @@ -14,14 +13,11 @@ /**\class InitializationPlugin_Plugin * TODO: Add documentation */ -class INITIALIZATIONPLUGIN_EXPORT InitializationPlugin_Plugin : public ModelAPI_Plugin, - public Events_Listener +class INITIALIZATIONPLUGIN_EXPORT InitializationPlugin_Plugin : public Events_Listener { public: InitializationPlugin_Plugin(); ~InitializationPlugin_Plugin() {} - /// Creates the feature object of this plugin by the feature string ID - virtual FeaturePtr createFeature(std::string theFeatureID); virtual void processEvent(const std::shared_ptr& theMessage); void createPlane(DocumentPtr theDoc, double theA, double theB, double theC); diff --git a/src/Model/Model_Application.cpp b/src/Model/Model_Application.cpp index f8955ce59..a825e7471 100644 --- a/src/Model/Model_Application.cpp +++ b/src/Model/Model_Application.cpp @@ -30,19 +30,21 @@ const std::shared_ptr& Model_Application::getDocument(string the static const std::string thePartSetKind("PartSet"); static const std::string thePartKind("Part"); + bool isRoot = theDocID == "root"; // the document is root std::shared_ptr aNew( - new Model_Document(theDocID, theDocID == "root" ? thePartSetKind : thePartKind)); + new Model_Document(theDocID, isRoot ? thePartSetKind : thePartKind)); myDocs[theDocID] = aNew; - Events_ID anId = ModelAPI_DocumentCreatedMessage::eventId(); - std::shared_ptr aMessage = - std::shared_ptr(new ModelAPI_DocumentCreatedMessage(anId, this)); - aMessage->setDocument(aNew); - Events_Loop::loop()->send(aMessage); // load it if it must be loaded by demand if (myLoadedByDemand.find(theDocID) != myLoadedByDemand.end() && !myPath.empty()) { aNew->load(myPath.c_str()); myLoadedByDemand.erase(theDocID); // done, don't do it anymore + } else { + static Events_ID anId = ModelAPI_DocumentCreatedMessage::eventId(); + std::shared_ptr aMessage = std::shared_ptr + (new ModelAPI_DocumentCreatedMessage(anId, this)); + aMessage->setDocument(aNew); + Events_Loop::loop()->send(aMessage); } return myDocs[theDocID]; diff --git a/src/Model/Model_Document.cpp b/src/Model/Model_Document.cpp index fb00ed5bf..8f4ac4cb1 100644 --- a/src/Model/Model_Document.cpp +++ b/src/Model/Model_Document.cpp @@ -548,8 +548,12 @@ FeaturePtr Model_Document::addFeature(std::string theID) FeaturePtr aFeature = ModelAPI_Session::get()->createFeature(theID); if (!aFeature) return aFeature; - std::shared_ptr aDocToAdd = std::dynamic_pointer_cast( - aFeature->documentToAdd()); + Model_Document* aDocToAdd; + if (aFeature->documentToAdd().get()) { // use the customized document to add + aDocToAdd = std::dynamic_pointer_cast(aFeature->documentToAdd()).get(); + } else { // if customized is not presented, add to "this" document + aDocToAdd = this; + } if (aFeature) { TDF_Label aFeatureLab; if (!aFeature->isAction()) { // do not add action to the data model @@ -577,7 +581,7 @@ FeaturePtr Model_Document::addFeature(std::string theID) } /// Appenad to the array of references a new referenced label. -/// If theIndex is not -1, removes element at thisindex, not theReferenced. +/// If theIndex is not -1, removes element at this index, not theReferenced. /// \returns the index of removed element static int RemoveFromRefArray(TDF_Label theArrayLab, TDF_Label theReferenced, const int theIndex = -1) @@ -685,6 +689,22 @@ void Model_Document::removeFeature(FeaturePtr theFeature/*, const bool theCheck* } } +void Model_Document::addToHistory(const std::shared_ptr theObject) +{ + TDF_Label aFeaturesLab = featuresLabel(); + std::shared_ptr aData = std::static_pointer_cast(theObject->data()); + if (!aData) { + return; // not found feature => do not remove + } + TDF_Label aFeatureLabel = aData->label().Father(); + // store feature in the history of features array + if (theObject->isInHistory()) { + AddToRefArray(aFeaturesLab, aFeatureLabel); + } else { + RemoveFromRefArray(aFeaturesLab, aFeatureLabel); + } +} + FeaturePtr Model_Document::feature(TDF_Label& theLabel) const { if (myObjs.IsBound(theLabel)) diff --git a/src/Model/Model_Document.h b/src/Model/Model_Document.h index bffcc81bc..7ec9e073e 100644 --- a/src/Model/Model_Document.h +++ b/src/Model/Model_Document.h @@ -208,6 +208,9 @@ class Model_Document : public ModelAPI_Document //! Returns the list of Ids of the operations that can be redoed (called for the root document) std::list redoList() const; + /// Internally makes document know that feature was removed or added in history after creation + MODEL_EXPORT virtual void addToHistory(const std::shared_ptr theObject); + friend class Model_Application; friend class Model_Session; friend class Model_Update; diff --git a/src/Model/Model_Session.cpp b/src/Model/Model_Session.cpp index 1791c3ad6..9618362e8 100644 --- a/src/Model/Model_Session.cpp +++ b/src/Model/Model_Session.cpp @@ -172,8 +172,18 @@ FeaturePtr Model_Session::createFeature(string theFeatureID) std::shared_ptr Model_Session::moduleDocument() { - return std::shared_ptr( + bool aFirstCall = !Model_Application::getApplication()->hasDocument("root"); + if (aFirstCall) { + // creation of the root document is always outside of the transaction, so, avoid checking it + setCheckTransactions(false); + } + std::shared_ptr aDoc = std::shared_ptr( Model_Application::getApplication()->getDocument("root")); + if (aFirstCall) { + // creation of the root document is always outside of the transaction, so, avoid checking it + setCheckTransactions(true); + } + return aDoc; } std::shared_ptr Model_Session::document(std::string theDocID) diff --git a/src/ModelAPI/ModelAPI_Document.h b/src/ModelAPI/ModelAPI_Document.h index bf1fa3832..9ce3ccd48 100644 --- a/src/ModelAPI/ModelAPI_Document.h +++ b/src/ModelAPI/ModelAPI_Document.h @@ -98,6 +98,11 @@ public: protected: /// Only for SWIG wrapping it is here MODELAPI_EXPORT ModelAPI_Document(); + + /// Internally makes document know that feature was removed or added in history after creation + MODELAPI_EXPORT virtual void addToHistory(const std::shared_ptr theObject) = 0; + + friend class ModelAPI_Object; // to add or remove from the history }; //! Pointer on document object diff --git a/src/ModelAPI/ModelAPI_Feature.cpp b/src/ModelAPI/ModelAPI_Feature.cpp index 65cfa361e..1a2e641a2 100644 --- a/src/ModelAPI/ModelAPI_Feature.cpp +++ b/src/ModelAPI/ModelAPI_Feature.cpp @@ -111,7 +111,8 @@ void ModelAPI_Feature::eraseResults() std::shared_ptr ModelAPI_Feature::documentToAdd() { - return ModelAPI_Session::get()->activeDocument(); + // null pointer t ouse the current document + return std::shared_ptr(); } void ModelAPI_Feature::erase() diff --git a/src/ModelAPI/ModelAPI_Feature.h b/src/ModelAPI/ModelAPI_Feature.h index e5701200f..c338e151f 100644 --- a/src/ModelAPI/ModelAPI_Feature.h +++ b/src/ModelAPI/ModelAPI_Feature.h @@ -92,7 +92,7 @@ class ModelAPI_Feature : public ModelAPI_Object } /// Must return document where the new feature must be added to - /// By default it is current document + /// By default it is null document: it is added to the document this method is called to MODELAPI_EXPORT virtual std::shared_ptr documentToAdd(); /// To virtually destroy the fields of successors diff --git a/src/ModelAPI/ModelAPI_Object.cpp b/src/ModelAPI/ModelAPI_Object.cpp index 410c410c7..573b2d12f 100644 --- a/src/ModelAPI/ModelAPI_Object.cpp +++ b/src/ModelAPI/ModelAPI_Object.cpp @@ -5,11 +5,20 @@ // Author: Mikhail PONIKAROV #include "ModelAPI_Object.h" - +#include "ModelAPI_Document.h" bool ModelAPI_Object::isInHistory() { - return true; + return myInHistory; +} + +void ModelAPI_Object::setInHistory( + const std::shared_ptr theObject, const bool theFlag) +{ + if (myInHistory != theFlag) { + myInHistory = theFlag; + myDoc->addToHistory(theObject); + } } std::shared_ptr ModelAPI_Object::data() const @@ -31,6 +40,10 @@ void ModelAPI_Object::attributeChanged(const std::string& theID) { } +ModelAPI_Object::ModelAPI_Object() : myInHistory(true) +{ +} + ModelAPI_Object::~ModelAPI_Object() { } diff --git a/src/ModelAPI/ModelAPI_Object.h b/src/ModelAPI/ModelAPI_Object.h index 485cf2ee1..6abadf9ea 100644 --- a/src/ModelAPI/ModelAPI_Object.h +++ b/src/ModelAPI/ModelAPI_Object.h @@ -28,10 +28,17 @@ class ModelAPI_Object { std::shared_ptr myData; ///< manager of the data model of a feature std::shared_ptr myDoc; ///< document this object belongs to + bool myInHistory; ///< keep the information about the presense of the object in the history tree public: /// By default object is displayed in the object browser. MODELAPI_EXPORT virtual bool isInHistory(); + /// Makes object presented or not in the history of the created objects + /// \param theObject is shared pointer to "this" + /// \param theFlag is boolean value: to add or remove from the history + MODELAPI_EXPORT virtual void setInHistory( + const std::shared_ptr theObject, const bool theFlag); + /// Returns the data manager of this object: attributes MODELAPI_EXPORT virtual std::shared_ptr data() const; @@ -52,6 +59,9 @@ class ModelAPI_Object // MODELAPI_EXPORT MODELAPI_EXPORT virtual void attributeChanged(const std::string& theID); + /// Initializes the default states of the object + MODELAPI_EXPORT ModelAPI_Object(); + /// To use virtuality for destructors MODELAPI_EXPORT virtual ~ModelAPI_Object();