From: Sergey Belash Date: Fri, 7 Mar 2014 12:47:48 +0000 (+0400) Subject: "Model" stubs for testing of CMake building procedures X-Git-Tag: V_0.1~63 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=2f25a2c6ff91c2f0aec430c91760268e7c1eb823;p=modules%2Fshaper.git "Model" stubs for testing of CMake building procedures --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 424fe2e6e..2bc0930ea 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,3 +3,6 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.8.11) PROJECT (NewGEOM) SET(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/CMakeCommon" ${CMAKE_MODULE_PATH}) + +ADD_SUBDIRECTORY (src/ModelAPI) +ADD_SUBDIRECTORY (src/Model) diff --git a/src/Model/CMakeLists.txt b/src/Model/CMakeLists.txt new file mode 100644 index 000000000..44badeb68 --- /dev/null +++ b/src/Model/CMakeLists.txt @@ -0,0 +1,24 @@ +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} +) diff --git a/src/Model/Model.hxx b/src/Model/Model.hxx new file mode 100644 index 000000000..b7bf7f206 --- /dev/null +++ b/src/Model/Model.hxx @@ -0,0 +1,18 @@ +#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 diff --git a/src/Model/Model_Application.cxx b/src/Model/Model_Application.cxx new file mode 100644 index 000000000..093b57816 --- /dev/null +++ b/src/Model/Model_Application.cxx @@ -0,0 +1,62 @@ +// File: Model_Application.cxx +// Created: Fri Sep 2 2011 +// Author: Mikhail PONIKAROV + +#include +#include + +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"); +} diff --git a/src/Model/Model_Application.hxx b/src/Model/Model_Application.hxx new file mode 100644 index 000000000..78d6ec106 --- /dev/null +++ b/src/Model/Model_Application.hxx @@ -0,0 +1,51 @@ +// File: Model_Application.hxx +// Created: 28 Dec 2011 +// Author: Mikhail PONIKAROV +// Copyright: CEA 2011 + +#ifndef Model_Application_HeaderFile +#define Model_Application_HeaderFile + +#include +#include +#include + +// 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 diff --git a/src/Model/Model_Document.cxx b/src/Model/Model_Document.cxx new file mode 100644 index 000000000..42ce6f766 --- /dev/null +++ b/src/Model/Model_Document.cxx @@ -0,0 +1,159 @@ +// File: Model_Document.cxx +// Created: 28 Dec 2011 +// 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 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"<SaveAs (aDoc, aPath); + } + catch (Standard_Failure) { + Handle(Standard_Failure) aFail = Standard_Failure::Caught(); + cout<<"OCAFApp_Engine:save Error: "<GetMessageString()< 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() +{ +} diff --git a/src/Model/Model_Document.hxx b/src/Model/Model_Document.hxx new file mode 100644 index 000000000..9fdab8ad3 --- /dev/null +++ b/src/Model/Model_Document.hxx @@ -0,0 +1,78 @@ +// File: Model_Document.hxx +// Created: 28 Dec 2011 +// Author: Mikhail PONIKAROV +// Copyright: CEA 2011 + +#ifndef Model_Document_HeaderFile +#define Model_Document_HeaderFile + +#include +#include +#include + +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 diff --git a/src/ModelAPI/CMakeLists.txt b/src/ModelAPI/CMakeLists.txt new file mode 100644 index 000000000..50f25206d --- /dev/null +++ b/src/ModelAPI/CMakeLists.txt @@ -0,0 +1,14 @@ +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}) diff --git a/src/ModelAPI/ModelAPI.hxx b/src/ModelAPI/ModelAPI.hxx new file mode 100644 index 000000000..b9e811215 --- /dev/null +++ b/src/ModelAPI/ModelAPI.hxx @@ -0,0 +1,18 @@ +#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 diff --git a/src/ModelAPI/ModelAPI_Application.hxx b/src/ModelAPI/ModelAPI_Application.hxx new file mode 100644 index 000000000..b9d5e0c17 --- /dev/null +++ b/src/ModelAPI/ModelAPI_Application.hxx @@ -0,0 +1,27 @@ +// File: Model_Application.hxx +// Created: 28 Dec 2011 +// Author: Mikhail PONIKAROV +// Copyright: CEA 2011 + +#ifndef ModelAPI_Application_HeaderFile +#define ModelAPI_Application_HeaderFile + +#include + +/**\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 diff --git a/src/ModelAPI/ModelAPI_Document.hxx b/src/ModelAPI/ModelAPI_Document.hxx new file mode 100644 index 000000000..02c537df1 --- /dev/null +++ b/src/ModelAPI/ModelAPI_Document.hxx @@ -0,0 +1,59 @@ +// File: Model_Document.hxx +// Created: 28 Dec 2011 +// Author: Mikhail PONIKAROV +// Copyright: CEA 2011 + +#ifndef ModelAPI_Document_HeaderFile +#define ModelAPI_Document_HeaderFile + +#include + +/**\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