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
// Created: Fri Sep 2 2011
// Author: Mikhail PONIKAROV
-#include <Model_Application.hxx>
-#include <Model_Document.hxx>
+#include <Model_Application.h>
+#include <Model_Document.h>
IMPLEMENT_STANDARD_HANDLE(Model_Application, TDocStd_Application)
IMPLEMENT_STANDARD_RTTIEXT(Model_Application, TDocStd_Application)
//function : getApplication
//purpose :
//=======================================================================
-Handle_Model_Application Model_Application::GetApplication()
+Handle(Model_Application) Model_Application::getApplication()
{
return TheApplication;
}
//function : getDocument
//purpose :
//=======================================================================
-ModelAPI_Document* Model_Application::GetMainDocument()
+boost::shared_ptr<Model_Document> 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<Model_Document> aNew(new Model_Document("BinOcaf"));
+ myDocs[theDocID] = aNew;
+ return aNew;
}
//=======================================================================
#ifndef Model_Application_HeaderFile
#define Model_Application_HeaderFile
-#include <Model_Document.hxx>
-#include <ModelAPI_Application.hxx>
+#include <Model_Document.h>
#include <TDocStd_Application.hxx>
+#include <map>
// Define handle class
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<Model_Document> getDocument(std::string theDocID);
public:
// Redefined OCAF methods
Model_Application();
private:
-
- Handle_Model_Document myMainDoc; ///< main document of an application
+ /// Map from string identifiers to created documents of an application
+ std::map<std::string, boost::shared_ptr<Model_Document> > myDocs;
};
#endif
// File: Model_Document.cxx
-// Created: 28 Dec 2011
+// Created: 28 Feb 2014
// Author: Mikhail PONIKAROV
-// Copyright: CEA 2011
#include <Model_Document.h>
+#include <Model_Feature.h>
#include <TDataStd_Integer.hxx>
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;
myTransactionsAfterSave++;
}
+void Model_Document::AddObject(
+ boost::shared_ptr<ModelAPI_Feature> theFeature, const int theGroupID)
+{
+ boost::shared_ptr<Model_Feature> aModelFeature =
+ boost::dynamic_pointer_cast<Model_Feature>(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)
{
-// 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
{
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);
//! 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<ModelAPI_Feature> theFeature,
+ const int theGroupID);
+
protected:
private:
{
}
-string Model_Feature::GetKind()
+void Model_Feature::setLabel(TDF_Label& theLab)
{
- return "Point";
+ myLab = theLab;
}
#include "Model.h"
#include <ModelAPI_Feature.h>
+#include <TDF_Label.hxx>
/**\class Model_Feature
* \ingroup DataModel
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
#include <ModelAPI_Feature.h>
#include <ModelAPI_Plugin.h>
#include <Model_Feature.h>
+#include <Model_Document.h>
+#include <Model_Application.h>
#include <Event_Loop.h>
#include <Config_FeatureMessage.h>
#include <Config_ModuleReader.h>
loadLibrary(myCurrentPluginName);
}
if (myPluginObjs.find(myCurrentPluginName) != myPluginObjs.end()) {
- return myPluginObjs[myCurrentPluginName]->createFeature(theFeatureID);
+ boost::shared_ptr<ModelAPI_Feature> aCreated =
+ myPluginObjs[myCurrentPluginName]->createFeature(theFeatureID);
}
}
return boost::shared_ptr<ModelAPI_Feature>(); // return nothing
}
+boost::shared_ptr<ModelAPI_Document> Model_PluginManager::rootDocument()
+{
+ return boost::shared_ptr<ModelAPI_Document>(
+ Model_Application::getApplication()->getDocument("root"));
+}
+
+
Model_PluginManager::Model_PluginManager()
{
myPluginsInfoLoaded = false;
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
#include <Event_Listener.h>
#include <map>
+class Model_Document;
+
/**\class Model_PluginManager
* \ingroup DataModel
* \brief Object that knows (from the initial XML file) which
/// Creates the feature object using plugins functionality
MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_Feature> createFeature(std::string theFeatureID);
+ /// Returns the root document of the application (that may contains sub-documents)
+ virtual boost::shared_ptr<ModelAPI_Document> 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)
-// 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 <ModelAPI.h>
+#include <boost/shared_ptr.hpp>
+
+class ModelAPI_Feature;
/**\class Model_Document
* \ingroup DataModel
//! 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<ModelAPI_Feature> theFeature,
+ const int theGroupID) = 0;
+
protected:
/// Only for SWIG wrapping it is here
MODELAPI_EXPORT ModelAPI_Document()
class ModelAPI_Feature;
class ModelAPI_Plugin;
+class ModelAPI_Document;
/**\class ModelAPI_PluginManager
* \ingroup DataModel
/// 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<ModelAPI_Document> 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);
#include "PartSetPlugin_Plugin.h"
#include "PartSetPlugin_NewPart.h"
#include <ModelAPI_PluginManager.h>
+#include <ModelAPI_Document.h>
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();
boost::shared_ptr<ModelAPI_Feature> PartSetPlugin_Plugin::createFeature(string theFeatureID)
{
+ boost::shared_ptr<ModelAPI_Feature> aCreated;
if (theFeatureID == "new_part") {
- return boost::shared_ptr<ModelAPI_Feature>(new PartSetPlugin_NewPart());
+ aCreated = boost::shared_ptr<ModelAPI_Feature>(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<ModelAPI_Feature>();
+ return aCreated;
}