From: mpv Date: Tue, 1 Apr 2014 07:58:33 +0000 (+0400) Subject: Connection of the feature to the document X-Git-Tag: V_0.1~41^2~5 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=6893c6599d0f6ce7c0b38f40d7dbef3c4fc8951d;p=modules%2Fshaper.git Connection of the feature to the document --- diff --git a/src/Model/CMakeLists.txt b/src/Model/CMakeLists.txt index 42ee4f4c6..5f0b4e883 100644 --- a/src/Model/CMakeLists.txt +++ b/src/Model/CMakeLists.txt @@ -6,12 +6,14 @@ INCLUDE(FindBoost) SET(PROJECT_HEADERS Model.h + Model_Application.h Model_Document.h Model_PluginManager.h Model_Feature.h ) SET(PROJECT_SOURCES + Model_Application.cxx Model_Document.cxx Model_PluginManager.cxx Model_Feature.cxx diff --git a/src/Model/Model_Application.cxx b/src/Model/Model_Application.cxx index dab193d13..560f5805c 100644 --- a/src/Model/Model_Application.cxx +++ b/src/Model/Model_Application.cxx @@ -2,8 +2,8 @@ // Created: Fri Sep 2 2011 // Author: Mikhail PONIKAROV -#include -#include +#include +#include IMPLEMENT_STANDARD_HANDLE(Model_Application, TDocStd_Application) IMPLEMENT_STANDARD_RTTIEXT(Model_Application, TDocStd_Application) @@ -14,7 +14,7 @@ static Handle_Model_Application TheApplication = new Model_Application; //function : getApplication //purpose : //======================================================================= -Handle_Model_Application Model_Application::GetApplication() +Handle(Model_Application) Model_Application::getApplication() { return TheApplication; } @@ -23,13 +23,14 @@ Handle_Model_Application Model_Application::GetApplication() //function : getDocument //purpose : //======================================================================= -ModelAPI_Document* Model_Application::GetMainDocument() +boost::shared_ptr Model_Application::getDocument(std::string theDocID) { + if (myDocs.find(theDocID) != myDocs.end()) + return myDocs[theDocID]; - if (myMainDoc.IsNull()) { - myMainDoc = new Model_Document("BinOcaf"); - } - return *myMainDoc; + boost::shared_ptr aNew(new Model_Document("BinOcaf")); + myDocs[theDocID] = aNew; + return aNew; } //======================================================================= diff --git a/src/Model/Model_Application.h b/src/Model/Model_Application.h index 77d669257..265eafbe1 100644 --- a/src/Model/Model_Application.h +++ b/src/Model/Model_Application.h @@ -6,9 +6,9 @@ #ifndef Model_Application_HeaderFile #define Model_Application_HeaderFile -#include -#include +#include #include +#include // Define handle class DEFINE_STANDARD_HANDLE(Model_Application, TDocStd_Application) @@ -19,19 +19,18 @@ DEFINE_STANDARD_HANDLE(Model_Application, TDocStd_Application) * Application supports the formats and document management. It is uses OCAF-lke * architecture and just implements specific features of the module. */ -class Model_Application: public TDocStd_Application, public ModelAPI_Application +class Model_Application: public TDocStd_Application { public: // useful methods inside of the module // CASCADE RTTI - DEFINE_STANDARD_RTTI(Model_Application) - ; + DEFINE_STANDARD_RTTI(Model_Application); //! Retuns the application: one per process - MODEL_EXPORT static Handle_Model_Application GetApplication(); - //! Returns the main document (on first call creates it) - MODEL_EXPORT ModelAPI_Document* GetMainDocument(); + MODEL_EXPORT static Handle_Model_Application getApplication(); + //! Returns the main document (on first call creates it) by the string identifier + MODEL_EXPORT boost::shared_ptr getDocument(std::string theDocID); public: // Redefined OCAF methods @@ -46,8 +45,8 @@ public: Model_Application(); private: - - Handle_Model_Document myMainDoc; ///< main document of an application + /// Map from string identifiers to created documents of an application + std::map > myDocs; }; #endif diff --git a/src/Model/Model_Document.cxx b/src/Model/Model_Document.cxx index dd34e598b..ddbdfc53a 100644 --- a/src/Model/Model_Document.cxx +++ b/src/Model/Model_Document.cxx @@ -1,21 +1,20 @@ // File: Model_Document.cxx -// Created: 28 Dec 2011 +// Created: 28 Feb 2014 // Author: Mikhail PONIKAROV -// Copyright: CEA 2011 #include +#include #include IMPLEMENT_STANDARD_HANDLE(Model_Document, MMgt_TShared) IMPLEMENT_STANDARD_RTTIEXT(Model_Document, MMgt_TShared) -static const int UNDO_LIMIT = 10; // number of possible undo operations in the module +static const int UNDO_LIMIT = 10; // number of possible undo operations static const int TAG_GENERAL = 1; // general properties tag static const int TAG_OBJECTS = 2; // tag of the objects sub-tree (Root for Model_ObjectsMgr) static const int TAG_HISTORY = 3; // tag of the history sub-tree (Root for Model_History) -static const int TAG_ISOTOPES = 4; // tag of the isotopes sub-tree (Root for MaterialMC_Isotope) using namespace std; @@ -151,6 +150,18 @@ void Model_Document::Redo() myTransactionsAfterSave++; } +void Model_Document::AddObject( + boost::shared_ptr theFeature, const int theGroupID) +{ + boost::shared_ptr aModelFeature = + boost::dynamic_pointer_cast(theFeature); + if (aModelFeature) { + TDF_Label aGroupLab = Main().FindChild(TAG_OBJECTS).FindChild(theGroupID + 1); + TDF_Label anObjLab = aGroupLab.NewChild(); + aModelFeature->setLabel(anObjLab); + } +} + Model_Document::Model_Document(const TCollection_ExtendedString& theStorageFormat) : TDocStd_Document(theStorageFormat) { diff --git a/src/Model/Model_Document.h b/src/Model/Model_Document.h index bdd5d8e0c..3e7c1c980 100644 --- a/src/Model/Model_Document.h +++ b/src/Model/Model_Document.h @@ -1,7 +1,6 @@ -// File: Model_Document.hxx -// Created: 28 Dec 2011 +// File: Model_Document.cxx +// Created: 28 Feb 2014 // Author: Mikhail PONIKAROV -// Copyright: CEA 2011 #ifndef Model_Document_HeaderFile #define Model_Document_HeaderFile @@ -25,8 +24,7 @@ class Model_Document: public TDocStd_Document, public ModelAPI_Document { public: - DEFINE_STANDARD_RTTI(Model_Document) - ; + DEFINE_STANDARD_RTTI(Model_Document); //! Creates new document by the format string of a storage Model_Document(const TCollection_ExtendedString& theStorageFormat); @@ -67,6 +65,12 @@ public: //! Redoes last operation MODEL_EXPORT void Redo(); + //! Adds to the document the new object of the given group id + //! \param theFeature a feature object that will be connected to the document in this method + //! \param theGroupID identifier of the groups of objects (must be greater than zero) + MODEL_EXPORT virtual void AddObject(boost::shared_ptr theFeature, + const int theGroupID); + protected: private: diff --git a/src/Model/Model_Feature.cxx b/src/Model/Model_Feature.cxx index 0ff283892..10455a7fc 100644 --- a/src/Model/Model_Feature.cxx +++ b/src/Model/Model_Feature.cxx @@ -10,7 +10,7 @@ Model_Feature::Model_Feature() { } -string Model_Feature::GetKind() +void Model_Feature::setLabel(TDF_Label& theLab) { - return "Point"; + myLab = theLab; } diff --git a/src/Model/Model_Feature.h b/src/Model/Model_Feature.h index 0b51f725f..ac930c078 100644 --- a/src/Model/Model_Feature.h +++ b/src/Model/Model_Feature.h @@ -7,6 +7,7 @@ #include "Model.h" #include +#include /**\class Model_Feature * \ingroup DataModel @@ -16,12 +17,15 @@ class Model_Feature: public ModelAPI_Feature { - Model_Feature(); + TDF_Label myLab; ///< label of the feature in the document + Model_Feature(); friend class Model_PluginManager; public: /// Returns the kind of a feature (like "Point") - virtual std::string GetKind(); + virtual std::string GetKind() = 0; + + void setLabel(TDF_Label& theLab); }; #endif diff --git a/src/Model/Model_PluginManager.cxx b/src/Model/Model_PluginManager.cxx index c4e28665d..e9990eed4 100644 --- a/src/Model/Model_PluginManager.cxx +++ b/src/Model/Model_PluginManager.cxx @@ -6,6 +6,8 @@ #include #include #include +#include +#include #include #include #include @@ -26,13 +28,21 @@ boost::shared_ptr Model_PluginManager::createFeature(string th loadLibrary(myCurrentPluginName); } if (myPluginObjs.find(myCurrentPluginName) != myPluginObjs.end()) { - return myPluginObjs[myCurrentPluginName]->createFeature(theFeatureID); + boost::shared_ptr aCreated = + myPluginObjs[myCurrentPluginName]->createFeature(theFeatureID); } } return boost::shared_ptr(); // return nothing } +boost::shared_ptr Model_PluginManager::rootDocument() +{ + return boost::shared_ptr( + Model_Application::getApplication()->getDocument("root")); +} + + Model_PluginManager::Model_PluginManager() { myPluginsInfoLoaded = false; @@ -51,7 +61,7 @@ void Model_PluginManager::processEvent(const Event_Message* theMessage) if (aMsg) { // proccess the plugin info, load plugin if (myPlugins.find(aMsg->id()) == myPlugins.end()) { - myPlugins[aMsg->id()] = aMsg->pluginLibrary(); // TO DO: plugin name must be also imported from XMLs + myPlugins[aMsg->id()] = aMsg->pluginLibrary(); } } // plugins information was started to load, so, it will be loaded diff --git a/src/Model/Model_PluginManager.h b/src/Model/Model_PluginManager.h index 5a847abce..5f9fdb73c 100644 --- a/src/Model/Model_PluginManager.h +++ b/src/Model/Model_PluginManager.h @@ -10,6 +10,8 @@ #include #include +class Model_Document; + /**\class Model_PluginManager * \ingroup DataModel * \brief Object that knows (from the initial XML file) which @@ -28,6 +30,9 @@ public: /// Creates the feature object using plugins functionality MODEL_EXPORT virtual boost::shared_ptr createFeature(std::string theFeatureID); + /// Returns the root document of the application (that may contains sub-documents) + virtual boost::shared_ptr rootDocument(); + /// Registers the plugin that creates features. /// It is obligatory for each plugin to call this function on loading to be found by /// the plugin manager on call of the feature) diff --git a/src/ModelAPI/ModelAPI_Document.h b/src/ModelAPI/ModelAPI_Document.h index 911aca068..2f60c2643 100644 --- a/src/ModelAPI/ModelAPI_Document.h +++ b/src/ModelAPI/ModelAPI_Document.h @@ -1,12 +1,14 @@ -// File: Model_Document.hxx -// Created: 28 Dec 2011 +// File: ModelAPI_Document.cxx +// Created: 28 Feb 2014 // Author: Mikhail PONIKAROV -// Copyright: CEA 2011 #ifndef ModelAPI_Document_HeaderFile #define ModelAPI_Document_HeaderFile #include +#include + +class ModelAPI_Feature; /**\class Model_Document * \ingroup DataModel @@ -55,6 +57,12 @@ public: //! Redoes last operation MODELAPI_EXPORT virtual void Redo() = 0; + //! Adds to the document the new object of the given group id + //! \param theFeature a feature object that will be connected to the document in this method + //! \param theGroupID identifier of the groups of objects (must be greater than zero) + MODELAPI_EXPORT virtual void AddObject(boost::shared_ptr theFeature, + const int theGroupID) = 0; + protected: /// Only for SWIG wrapping it is here MODELAPI_EXPORT ModelAPI_Document() diff --git a/src/ModelAPI/ModelAPI_PluginManager.h b/src/ModelAPI/ModelAPI_PluginManager.h index 620501bfd..a7b0c7bcd 100644 --- a/src/ModelAPI/ModelAPI_PluginManager.h +++ b/src/ModelAPI/ModelAPI_PluginManager.h @@ -11,6 +11,7 @@ class ModelAPI_Feature; class ModelAPI_Plugin; +class ModelAPI_Document; /**\class ModelAPI_PluginManager * \ingroup DataModel @@ -33,6 +34,9 @@ public: /// the plugin manager on call of the feature) virtual void registerPlugin(ModelAPI_Plugin* thePlugin) = 0; + /// Returns the root document of the application (that may contains sub-documents) + virtual boost::shared_ptr rootDocument() = 0; + /// loads the library with specific name, appends "lib*.dll" or "*.so" depending on the platform static void ModelAPI_PluginManager::loadLibrary(const std::string theLibName); diff --git a/src/PartSetPlugin/PartSetPlugin_Plugin.cxx b/src/PartSetPlugin/PartSetPlugin_Plugin.cxx index d3d295dc7..d94a74f30 100644 --- a/src/PartSetPlugin/PartSetPlugin_Plugin.cxx +++ b/src/PartSetPlugin/PartSetPlugin_Plugin.cxx @@ -1,9 +1,13 @@ #include "PartSetPlugin_Plugin.h" #include "PartSetPlugin_NewPart.h" #include +#include using namespace std; +// group identification of the newly created parts in the Part Set document +const int MY_PARTS_GROUP = 1; + // the only created instance of this plugin static PartSetPlugin_Plugin* MY_INSTANCE = new PartSetPlugin_Plugin(); @@ -15,9 +19,13 @@ PartSetPlugin_Plugin::PartSetPlugin_Plugin() boost::shared_ptr PartSetPlugin_Plugin::createFeature(string theFeatureID) { + boost::shared_ptr aCreated; if (theFeatureID == "new_part") { - return boost::shared_ptr(new PartSetPlugin_NewPart()); + aCreated = boost::shared_ptr(new PartSetPlugin_NewPart()); } + // add to a root document for the current moment + if (aCreated) + ModelAPI_PluginManager::get()->rootDocument()->AddObject(aCreated, MY_PARTS_GROUP); // feature of such kind is not found - return boost::shared_ptr(); + return aCreated; }