INCLUDE(Common)
INCLUDE(FindCAS)
-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
)
-ADD_DEFINITIONS(-DMODEL_EXPORTS ${CAS_DEFINITIONS} ${BOOST_DEFINITIONS})
+ADD_DEFINITIONS(-DMODEL_EXPORTS ${CAS_DEFINITIONS})
ADD_LIBRARY(Model SHARED ${PROJECT_SOURCES} ${PROJECT_HEADERS})
TARGET_LINK_LIBRARIES(Model ${PROJECT_LIBRARIES} ${CAS_OCAF} ModelAPI Event Config)
// 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()
+std::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;
+ std::shared_ptr<Model_Document> aNew(new Model_Document);
+ 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 std::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, std::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;
void Model_Document::Close()
{
- TDocStd_Document::Close();
+ myDoc->Close();
}
void Model_Document::StartOperation()
{
- TDocStd_Document::NewCommand();
+ myDoc->NewCommand();
}
void Model_Document::FinishOperation()
{
- TDocStd_Document::CommitCommand();
+ myDoc->CommitCommand();
myTransactionsAfterSave++;
}
void Model_Document::AbortOperation()
{
- TDocStd_Document::AbortCommand();
+ myDoc->AbortCommand();
}
bool Model_Document::IsOperation()
{
- return TDocStd_Document::HasOpenCommand() == Standard_True ;
+ return myDoc->HasOpenCommand() == Standard_True ;
}
bool Model_Document::IsModified()
bool Model_Document::CanUndo()
{
- return TDocStd_Document::GetAvailableUndos() > 0;
+ return myDoc->GetAvailableUndos() > 0;
}
void Model_Document::Undo()
{
- TDocStd_Document::Undo();
+ myDoc->Undo();
myTransactionsAfterSave--;
}
bool Model_Document::CanRedo()
{
- return TDocStd_Document::GetAvailableRedos() > 0;
+ return myDoc->GetAvailableRedos() > 0;
}
void Model_Document::Redo()
{
- TDocStd_Document::Redo();
+ myDoc->Redo();
myTransactionsAfterSave++;
}
-Model_Document::Model_Document(const TCollection_ExtendedString& theStorageFormat)
- : TDocStd_Document(theStorageFormat)
+void Model_Document::AddObject(
+ std::shared_ptr<ModelAPI_Feature> theFeature, const int theGroupID)
+{
+ std::shared_ptr<Model_Feature> aModelFeature =
+ std::dynamic_pointer_cast<Model_Feature>(theFeature);
+ if (aModelFeature) {
+ TDF_Label aGroupLab = myDoc->Main().FindChild(TAG_OBJECTS).FindChild(theGroupID + 1);
+ TDF_Label anObjLab = aGroupLab.NewChild();
+ aModelFeature->setLabel(anObjLab);
+ }
+}
+
+Model_Document::Model_Document()
+ : myDoc(new TDocStd_Document("BinOcaf")) // binary OCAF format
{
- SetUndoLimit(UNDO_LIMIT);
+ myDoc->SetUndoLimit(UNDO_LIMIT);
myTransactionsAfterSave = 0;
}
-// 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
* to provide access to all stored data.
*/
-class Model_Document: public TDocStd_Document, public ModelAPI_Document
+class Model_Document: public ModelAPI_Document
{
public:
- DEFINE_STANDARD_RTTI(Model_Document)
- ;
-
- //! Creates new document by the format string of a storage
- Model_Document(const TCollection_ExtendedString& theStorageFormat);
+ //! Creates new document with binary file format
+ Model_Document();
//! Deletes all high-level data, managed this document
~Model_Document();
//! 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(std::shared_ptr<ModelAPI_Feature> theFeature,
+ const int theGroupID);
+
protected:
private:
+ Handle_TDocStd_Document myDoc; ///< OCAF document
int myTransactionsAfterSave; ///< number of transactions after the last "save" call, used for "IsModified" method
};
-// Define handle class
-DEFINE_STANDARD_HANDLE(Model_Document, TDocStd_Document)
-
#endif
{
}
-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>
static Model_PluginManager* myImpl = new Model_PluginManager();
-boost::shared_ptr<ModelAPI_Feature> Model_PluginManager::createFeature(string theFeatureID)
+std::shared_ptr<ModelAPI_Feature> Model_PluginManager::createFeature(string theFeatureID)
{
if (this != myImpl) return myImpl->createFeature(theFeatureID);
loadLibrary(myCurrentPluginName);
}
if (myPluginObjs.find(myCurrentPluginName) != myPluginObjs.end()) {
- return myPluginObjs[myCurrentPluginName]->createFeature(theFeatureID);
+ std::shared_ptr<ModelAPI_Feature> aCreated =
+ myPluginObjs[myCurrentPluginName]->createFeature(theFeatureID);
}
}
- return boost::shared_ptr<ModelAPI_Feature>(); // return nothing
+ return std::shared_ptr<ModelAPI_Feature>(); // return nothing
}
+std::shared_ptr<ModelAPI_Document> Model_PluginManager::rootDocument()
+{
+ return std::shared_ptr<ModelAPI_Document>(
+ Model_Application::getApplication()->getDocument("root"));
+}
+
+
Model_PluginManager::Model_PluginManager()
{
myPluginsInfoLoaded = false;
static Event_ID aFeatureEvent = Event_Loop::eventByName("RegisterFeature");
- ModelAPI_PluginManager::SetPluginManager(boost::shared_ptr<ModelAPI_PluginManager>(this));
+ ModelAPI_PluginManager::SetPluginManager(std::shared_ptr<ModelAPI_PluginManager>(this));
// register the configuration reading listener
Event_Loop* aLoop = Event_Loop::loop();
aLoop->registerListener(this, aFeatureEvent);
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
std::string myCurrentPluginName; ///< name of the plugin that must be loaded currently
public:
/// Creates the feature object using plugins functionality
- MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_Feature> createFeature(std::string theFeatureID);
+ MODEL_EXPORT virtual std::shared_ptr<ModelAPI_Feature> createFeature(std::string theFeatureID);
+
+ /// Returns the root document of the application (that may contains sub-documents)
+ virtual std::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
FIND_PACKAGE(SWIG REQUIRED)
INCLUDE(${SWIG_USE_FILE})
INCLUDE(FindPython)
-INCLUDE(FindBoost)
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
SET(PROJECT_HEADERS
%include "std_string.i"
// boost pointers
-%include <boost_shared_ptr.i>
-%shared_ptr(ModelAPI_PluginManager)
-%shared_ptr(ModelAPI_Feature)
+// %include <boost_shared_ptr.i>
+// %shared_ptr(ModelAPI_PluginManager)
+// %shared_ptr(ModelAPI_Feature)
// all supported interfaces
%include "ModelAPI_Document.h"
-// 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 <memory>
+
+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(std::shared_ptr<ModelAPI_Feature> theFeature,
+ const int theGroupID) = 0;
+
protected:
/// Only for SWIG wrapping it is here
MODELAPI_EXPORT ModelAPI_Document()
#include "ModelAPI.h"
#include <string>
-#include <boost/shared_ptr.hpp>
+#include <memory>
class ModelAPI_Feature;
{
public:
/// Creates the feature object of this plugin by the feature string ID
- virtual boost::shared_ptr<ModelAPI_Feature> createFeature(std::string theFeatureID) = 0;
+ virtual std::shared_ptr<ModelAPI_Feature> createFeature(std::string theFeatureID) = 0;
protected:
/// Is needed for python wrapping by swig
string library(const string& theLibName);
/// Manager that will be initialized from Model package, one per application
-boost::shared_ptr<ModelAPI_PluginManager> MY_MANAGER;
+std::shared_ptr<ModelAPI_PluginManager> MY_MANAGER;
ModelAPI_PluginManager::ModelAPI_PluginManager()
{
}
void ModelAPI_PluginManager::SetPluginManager(
- boost::shared_ptr<ModelAPI_PluginManager> theManager)
+ std::shared_ptr<ModelAPI_PluginManager> theManager)
{
MY_MANAGER = theManager;
}
-boost::shared_ptr<ModelAPI_PluginManager> ModelAPI_PluginManager::get()
+std::shared_ptr<ModelAPI_PluginManager> ModelAPI_PluginManager::get()
{
if (!MY_MANAGER) { // import Model library that implements this interface of ModelAPI
loadLibrary("Model");
return aLibName;
}
+#include <iostream>
void ModelAPI_PluginManager::loadLibrary(const string theLibName)
{
string aFileName = library(theLibName);
#include "ModelAPI.h"
#include <string>
-#include <boost/shared_ptr.hpp>
+#include <memory>
class ModelAPI_Feature;
class ModelAPI_Plugin;
+class ModelAPI_Document;
/**\class ModelAPI_PluginManager
* \ingroup DataModel
{
public:
/// Creates the feature object using plugins functionality
- virtual boost::shared_ptr<ModelAPI_Feature> createFeature(std::string theFeatureID) = 0;
+ virtual std::shared_ptr<ModelAPI_Feature> createFeature(std::string theFeatureID) = 0;
/// Returns the real implementation (the alone instance per application) of the plugin manager
- static boost::shared_ptr<ModelAPI_PluginManager> get();
+ static std::shared_ptr<ModelAPI_PluginManager> get();
/// 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)
virtual void registerPlugin(ModelAPI_Plugin* thePlugin) = 0;
+ /// Returns the root document of the application (that may contains sub-documents)
+ virtual std::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);
ModelAPI_PluginManager();
protected:
- static void SetPluginManager(boost::shared_ptr<ModelAPI_PluginManager> theManager);
+ static void SetPluginManager(std::shared_ptr<ModelAPI_PluginManager> theManager);
};
#endif
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.11)
INCLUDE(Common)
-INCLUDE(FindBoost)
SET(PROJECT_HEADERS
PartSetPlugin.h
#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();
ModelAPI_PluginManager::get()->registerPlugin(this);
}
-boost::shared_ptr<ModelAPI_Feature> PartSetPlugin_Plugin::createFeature(string theFeatureID)
+std::shared_ptr<ModelAPI_Feature> PartSetPlugin_Plugin::createFeature(string theFeatureID)
{
+ std::shared_ptr<ModelAPI_Feature> aCreated;
if (theFeatureID == "new_part") {
- return boost::shared_ptr<ModelAPI_Feature>(new PartSetPlugin_NewPart());
+ aCreated = std::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;
}
{
public:
/// Creates the feature object of this plugin by the feature string ID
- virtual boost::shared_ptr<ModelAPI_Feature> createFeature(std::string theFeatureID);
+ virtual std::shared_ptr<ModelAPI_Feature> createFeature(std::string theFeatureID);
public:
/// Is needed for python wrapping by swig