PROJECT (NewGEOM)
SET(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/CMakeCommon" ${CMAKE_MODULE_PATH})
+
+ADD_SUBDIRECTORY (src/ModelAPI)
+ADD_SUBDIRECTORY (src/Model)
--- /dev/null
+CMAKE_MINIMUM_REQUIRED(VERSION 2.8.11)
+
+INCLUDE(Common)
+INCLUDE(FindCAS)
+
+SET(PROJECT_HEADERS
+ Model.hxx
+ Model_Application.hxx
+ Model_Document.hxx
+)
+
+SET(PROJECT_SOURCES
+ Model_Application.cxx
+ Model_Document.cxx
+)
+
+ADD_DEFINITIONS(-DMODEL_EXPORTS ${CAS_DEFINITIONS})
+ADD_LIBRARY(Model SHARED ${PROJECT_SOURCES} ${PROJECT_HEADERS})
+TARGET_LINK_LIBRARIES(Model ${PROJECT_LIBRARIES} ${CAS_OCAF})
+
+INCLUDE_DIRECTORIES(
+ ../ModelAPI
+ ${CAS_INCLUDE_DIRS}
+)
--- /dev/null
+#ifndef MODEL_H
+#define MODEL_H
+
+#if defined MODEL_EXPORTS
+#if defined WIN32
+#define MODEL_EXPORT __declspec( dllexport )
+#else
+#define MODEL_EXPORT
+#endif
+#else
+#if defined WIN32
+#define MODEL_EXPORT __declspec( dllimport )
+#else
+#define MODEL_EXPORT
+#endif
+#endif
+
+#endif
--- /dev/null
+// File: Model_Application.cxx
+// Created: Fri Sep 2 2011
+// Author: Mikhail PONIKAROV
+
+#include <Model_Application.hxx>
+#include <Model_Document.hxx>
+
+IMPLEMENT_STANDARD_HANDLE(Model_Application,TDocStd_Application)
+IMPLEMENT_STANDARD_RTTIEXT(Model_Application,TDocStd_Application)
+
+static Handle_Model_Application TheApplication = new Model_Application;
+
+//=======================================================================
+//function : getApplication
+//purpose :
+//=======================================================================
+Handle_Model_Application Model_Application::GetApplication()
+{
+ return TheApplication;
+}
+
+//=======================================================================
+//function : getDocument
+//purpose :
+//=======================================================================
+ModelAPI_Document* Model_Application::GetMainDocument()
+{
+
+ if (myMainDoc.IsNull()) {
+ myMainDoc = new Model_Document("BinOcaf");
+ }
+ return *myMainDoc;
+}
+
+//=======================================================================
+//function : OCAFApp_Application
+//purpose :
+//=======================================================================
+Model_Application::Model_Application ()
+{
+ // store handle to the application to avoid nullification
+ static Handle(Model_Application) TheKeepHandle;
+ TheKeepHandle = this;
+}
+
+//=======================================================================
+//function : Formats
+//purpose :
+//=======================================================================
+void Model_Application::Formats(TColStd_SequenceOfExtendedString& theFormats)
+{
+ theFormats.Append(TCollection_ExtendedString ("BinOcaf")); // standard binary schema
+}
+
+//=======================================================================
+//function : ResourcesName
+//purpose :
+//=======================================================================
+Standard_CString Model_Application::ResourcesName()
+{
+ return Standard_CString("Standard");
+}
--- /dev/null
+// File: Model_Application.hxx
+// Created: 28 Dec 2011
+// Author: Mikhail PONIKAROV
+// Copyright: CEA 2011
+
+#ifndef Model_Application_HeaderFile
+#define Model_Application_HeaderFile
+
+#include <Model_Document.hxx>
+#include <ModelAPI_Application.hxx>
+#include <TDocStd_Application.hxx>
+
+// Define handle class
+DEFINE_STANDARD_HANDLE(Model_Application,TDocStd_Application)
+
+ /**\class Model_Application
+ * \ingroup DataModel
+ * \brief Realization of Open CASCADE application abstraction. Class for internal use only.
+ * 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
+{
+public: // useful methods inside of the module
+
+ // CASCADE RTTI
+ 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();
+
+public: // Redefined OCAF methods
+ //! Return name of resource (i.e. "Standard")
+ Standard_CString ResourcesName();
+ //! Return format (i.e "MDTV-Standard")
+ //! \param theFormats sequence of allowed formats for input/output
+ virtual void Formats(TColStd_SequenceOfExtendedString& theFormats);
+ //! Constructor
+ //! Use method GetInstance() method to obtain
+ //! the static instance of the object (or derive your own application)
+ Model_Application();
+
+
+private:
+
+ Handle_Model_Document myMainDoc; ///< main document of an application
+};
+
+#endif
--- /dev/null
+// File: Model_Document.cxx
+// Created: 28 Dec 2011
+// Author: Mikhail PONIKAROV
+// Copyright: CEA 2011
+
+#include <Model_Document.hxx>
+#include <Model_Application.hxx>
+
+#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 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;
+
+bool Model_Document::Load(const char* theFileName)
+{
+ bool myIsError = Standard_False;
+ TCollection_ExtendedString aPath ((const Standard_CString)theFileName);
+ PCDM_ReaderStatus aStatus = (PCDM_ReaderStatus) -1;
+ try
+ {
+ Handle(TDocStd_Document) aDoc = this;
+ aStatus = Model_Application::GetApplication()->Open(aPath, aDoc);
+ }
+ catch (Standard_Failure)
+ {}
+ myIsError = aStatus != PCDM_RS_OK;
+ if (myIsError)
+ {
+ switch (aStatus)
+ {
+ case PCDM_RS_UnknownDocument: cout<<"OCAFApp_Appl_RUnknownDocument"<<endl; break;
+ case PCDM_RS_AlreadyRetrieved: cout<<"OCAFApp_Appl_RAlreadyRetrieved"<<endl; break;
+ case PCDM_RS_AlreadyRetrievedAndModified: cout<<"OCAFApp_Appl_RAlreadyRetrievedAndModified"<<endl; break;
+ case PCDM_RS_NoDriver: cout<<"OCAFApp_Appl_RNoDriver"<<endl; break;
+ case PCDM_RS_UnknownFileDriver: cout<<"OCAFApp_Appl_RNoDriver"<<endl; break;
+ case PCDM_RS_OpenError: cout<<"OCAFApp_Appl_ROpenError"<<endl; break;
+ case PCDM_RS_NoVersion: cout<<"OCAFApp_Appl_RNoVersion"<<endl; break;
+ case PCDM_RS_NoModel: cout<<"OCAFApp_Appl_RNoModel"<<endl; break;
+ case PCDM_RS_NoDocument: cout<<"OCAFApp_Appl_RNoDocument"<<endl; break;
+ case PCDM_RS_FormatFailure: cout<<"OCAFApp_Appl_RFormatFailure"<<endl; break;
+ case PCDM_RS_TypeNotFoundInSchema: cout<<"OCAFApp_Appl_RTypeNotFound"<<endl; break;
+ case PCDM_RS_UnrecognizedFileFormat: cout<<"OCAFApp_Appl_RBadFileFormat"<<endl; break;
+ case PCDM_RS_MakeFailure: cout<<"OCAFApp_Appl_RMakeFailure"<<endl; break;
+ case PCDM_RS_PermissionDenied: cout<<"OCAFApp_Appl_RPermissionDenied"<<endl; break;
+ case PCDM_RS_DriverFailure: cout<<"OCAFApp_Appl_RDriverFailure"<<endl; break;
+ default: cout<<"OCAFApp_Appl_RUnknownFail"<<endl; break;
+ }
+ }
+ SetUndoLimit(UNDO_LIMIT);
+ return !myIsError;
+}
+
+bool Model_Document::Save(const char* theFileName)
+{
+ TCollection_ExtendedString aPath ((const Standard_CString)theFileName);
+ PCDM_StoreStatus aStatus;
+ try {
+ Handle(TDocStd_Document) aDoc = this;
+ aStatus = Model_Application::GetApplication()->SaveAs (aDoc, aPath);
+ }
+ catch (Standard_Failure) {
+ Handle(Standard_Failure) aFail = Standard_Failure::Caught();
+ cout<<"OCAFApp_Engine:save Error: "<<aFail->GetMessageString()<<endl;
+ return false;
+ }
+ bool myIsError = aStatus != PCDM_SS_OK;
+ if (myIsError)
+ {
+ switch (aStatus)
+ {
+ case PCDM_SS_DriverFailure:
+ cout<<"OCAFApp_Appl_SDriverFailure"<<endl;
+ break;
+ case PCDM_SS_WriteFailure:
+ cout<<"OCAFApp_Appl_SWriteFailure"<<endl;
+ break;
+ case PCDM_SS_Failure:
+ default:
+ cout<<"OCAFApp_Appl_SUnknownFailure"<<endl;
+ break;
+ }
+ }
+ myTransactionsAfterSave = 0;
+ Standard::Purge(); // Release free memory
+ return !myIsError;
+}
+
+void Model_Document::Close()
+{
+ TDocStd_Document::Close();
+}
+
+void Model_Document::StartOperation()
+{
+ TDocStd_Document::NewCommand();
+}
+
+void Model_Document::FinishOperation()
+{
+ TDocStd_Document::CommitCommand();
+ myTransactionsAfterSave++;
+}
+
+void Model_Document::AbortOperation()
+{
+ TDocStd_Document::AbortCommand();
+}
+
+bool Model_Document::IsOperation()
+{
+ return TDocStd_Document::HasOpenCommand() == Standard_True;
+}
+
+bool Model_Document::IsModified()
+{
+ return myTransactionsAfterSave != 0;
+}
+
+bool Model_Document::CanUndo()
+{
+ return TDocStd_Document::GetAvailableUndos() > 0;
+}
+
+void Model_Document::Undo()
+{
+ TDocStd_Document::Undo();
+ myTransactionsAfterSave--;
+}
+
+bool Model_Document::CanRedo()
+{
+ return TDocStd_Document::GetAvailableRedos() > 0;
+}
+
+void Model_Document::Redo()
+{
+ TDocStd_Document::Redo();
+ myTransactionsAfterSave++;
+}
+
+Model_Document::Model_Document(const TCollection_ExtendedString& theStorageFormat)
+ : TDocStd_Document(theStorageFormat)
+{
+ SetUndoLimit(UNDO_LIMIT);
+ myTransactionsAfterSave = 0;
+}
+
+Model_Document::~Model_Document()
+{
+}
--- /dev/null
+// File: Model_Document.hxx
+// Created: 28 Dec 2011
+// Author: Mikhail PONIKAROV
+// Copyright: CEA 2011
+
+#ifndef Model_Document_HeaderFile
+#define Model_Document_HeaderFile
+
+#include <Model.hxx>
+#include <ModelAPI_Document.hxx>
+#include <TDocStd_Document.hxx>
+
+class Handle_Model_Document;
+
+/**\class Model_Document
+ * \ingroup DataModel
+ * \brief Document for internal data structure of any object storage. Corresponds to the SALOME study.
+ * Document contains all data of te SALOME Study specific to this module
+ * that must be written into the HDF file.
+ * Also it provides acces to this data: open/save, transactions management etc.
+ * to provide access to all stored data.
+ */
+
+class Model_Document : public TDocStd_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);
+ //! Deletes all high-level data, managed this document
+ ~Model_Document();
+
+ //! Loads the OCAF document from the file.
+ //! \param theFileName full name of the file to load
+ //! \param theStudyID identifier of the SALOME study to associate with loaded file
+ //! \returns true if file was loaded successfully
+ MODEL_EXPORT bool Load(const char* theFileName);
+
+ //! Saves the OCAF document to the file.
+ //! \param theFileName full name of the file to store
+ //! \returns true if file was stored successfully
+ MODEL_EXPORT bool Save(const char* theFileName);
+
+ //! Removes document data
+ MODEL_EXPORT void Close();
+
+ //! Starts a new operation (opens a tansaction)
+ MODEL_EXPORT void StartOperation();
+ //! Finishes the previously started operation (closes the transaction)
+ MODEL_EXPORT void FinishOperation();
+ //! Aborts the operation
+ MODEL_EXPORT void AbortOperation();
+ //! Returns true if operation has been started, but not yet finished or aborted
+ MODEL_EXPORT bool IsOperation();
+ //! Returns true if document was modified (since creation/opening)
+ MODEL_EXPORT bool IsModified();
+
+ //! Returns True if there are available Undos
+ MODEL_EXPORT bool CanUndo();
+ //! Undoes last operation
+ MODEL_EXPORT void Undo();
+ //! Returns True if there are available Redos
+ MODEL_EXPORT bool CanRedo();
+ //! Redoes last operation
+ MODEL_EXPORT void Redo();
+
+protected:
+
+private:
+ 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
--- /dev/null
+CMAKE_MINIMUM_REQUIRED(VERSION 2.8.11)
+
+INCLUDE(Common)
+
+SET(PROJECT_HEADERS
+ ModelAPI.hxx
+ ModelAPI_Application.hxx
+ ModelAPI_Document.hxx
+)
+
+ADD_DEFINITIONS(-DMODELAPI_EXPORTS)
+ADD_LIBRARY(ModelAPI SHARED ${PROJECT_SOURCES} ${PROJECT_HEADERS})
+SET_TARGET_PROPERTIES(ModelAPI PROPERTIES LINKER_LANGUAGE CXX)
+#TARGET_LINK_LIBRARIES(ModelAPI ${PROJECT_LIBRARIES})
--- /dev/null
+#ifndef MODELAPI_H
+#define MODELAPI_H
+
+#if defined MODELAPI_EXPORTS
+#if defined WIN32
+#define MODELAPI_EXPORT __declspec( dllexport )
+#else
+#define MODELAPI_EXPORT
+#endif
+#else
+#if defined WIN32
+#define MODELAPI_EXPORT __declspec( dllimport )
+#else
+#define MODELAPI_EXPORT
+#endif
+#endif
+
+#endif
--- /dev/null
+// File: Model_Application.hxx
+// Created: 28 Dec 2011
+// Author: Mikhail PONIKAROV
+// Copyright: CEA 2011
+
+#ifndef ModelAPI_Application_HeaderFile
+#define ModelAPI_Application_HeaderFile
+
+#include <ModelAPI.hxx>
+
+/**\class Model_Application
+ * \ingroup DataModel
+ * \brief Realization of Open CASCADE application abstraction. Class for internal use only.
+ * Application supports the formats and document management. It is uses OCAF-lke
+ * architecture and just implements specific features of the module.
+ */
+class ModelAPI_Application
+{
+public: // useful methods inside of the module
+
+ //! Retuns the application: one per process
+ MODELAPI_EXPORT virtual static ModelAPI_Application GetApplication() = 0;
+
+ MODELAPI_EXPORT virtual ModelAPI_Document* GetMainDocument() = 0;
+};
+
+#endif
--- /dev/null
+// File: Model_Document.hxx
+// Created: 28 Dec 2011
+// Author: Mikhail PONIKAROV
+// Copyright: CEA 2011
+
+#ifndef ModelAPI_Document_HeaderFile
+#define ModelAPI_Document_HeaderFile
+
+#include <ModelAPI.hxx>
+
+/**\class Model_Document
+ * \ingroup DataModel
+ * \brief Document for internal data structure of any object storage. Corresponds to the SALOME study.
+ * Document contains all data of te SALOME Study specific to this module
+ * that must be written into the HDF file.
+ * Also it provides acces to this data: open/save, transactions management etc.
+ * to provide access to all stored data.
+ */
+
+class ModelAPI_Document
+{
+public:
+
+ //! Loads the OCAF document from the file.
+ //! \param theFileName full name of the file to load
+ //! \param theStudyID identifier of the SALOME study to associate with loaded file
+ //! \returns true if file was loaded successfully
+ MODELAPI_EXPORT virtual bool Load(const char* theFileName) = 0;
+
+ //! Saves the OCAF document to the file.
+ //! \param theFileName full name of the file to store
+ //! \returns true if file was stored successfully
+ MODELAPI_EXPORT virtual bool Save(const char* theFileName) = 0;
+
+ //! Removes document data
+ MODELAPI_EXPORT virtual void Close() = 0;
+
+ //! Starts a new operation (opens a tansaction)
+ MODELAPI_EXPORT virtual void StartOperation() = 0;
+ //! Finishes the previously started operation (closes the transaction)
+ MODELAPI_EXPORT virtual void FinishOperation() = 0;
+ //! Aborts the operation
+ MODELAPI_EXPORT virtual void AbortOperation() = 0;
+ //! Returns true if operation has been started, but not yet finished or aborted
+ MODELAPI_EXPORT virtual bool IsOperation() = 0;
+ //! Returns true if document was modified (since creation/opening)
+ MODELAPI_EXPORT virtual bool IsModified() = 0;
+
+ //! Returns True if there are available Undos
+ MODELAPI_EXPORT virtual bool CanUndo() = 0;
+ //! Undoes last operation
+ MODELAPI_EXPORT virtual void Undo();
+ //! Returns True if there are available Redos
+ MODELAPI_EXPORT virtual bool CanRedo() = 0;
+ //! Redoes last operation
+ MODELAPI_EXPORT virtual void Redo() = 0;
+};
+
+#endif