From: mpv Date: Wed, 26 Mar 2014 12:21:06 +0000 (+0400) Subject: Migration to Boost shared_ptr and first python launch-tests X-Git-Tag: V_0.1~49 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=c38397a5dd4d35001147a9dfbf649771c6f22229;p=modules%2Fshaper.git Migration to Boost shared_ptr and first python launch-tests --- diff --git a/CMakeCommon/Common.cmake b/CMakeCommon/Common.cmake index b1e5384de..b9cf4596f 100644 --- a/CMakeCommon/Common.cmake +++ b/CMakeCommon/Common.cmake @@ -8,5 +8,6 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin) set(CMAKE_INCLUDE_CURRENT_DIR ON) IF(WIN32) - ADD_DEFINITIONS(-DWIN32 -D_WINDOWS) + ## Specific definitions: EHsc to avoid exceptions-linkage unresolved symbols + ADD_DEFINITIONS(-DWIN32 -D_WINDOWS /EHsc) ENDIF(WIN32) diff --git a/CMakeCommon/FindBoost.cmake b/CMakeCommon/FindBoost.cmake new file mode 100644 index 000000000..e8d34a11e --- /dev/null +++ b/CMakeCommon/FindBoost.cmake @@ -0,0 +1,30 @@ +# Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +#find_package(Boost) + +SET(BOOSTDIR $ENV{BOOST_ROOT_DIR}) +INCLUDE_DIRECTORIES(${BOOSTDIR}/include/boost-1_52) +LINK_DIRECTORIES (${BOOSTDIR}/lib) + +#SET(BOOST_LIBRARIES ${BOOSTDIR}/lib/lib.lib) + +IF(WIN32) + SET(BOOST_DEFINITIONS -DBOOST_DISABLE_ASSERTS -DBOOST_ALL_DYN_LINK) +ENDIF() diff --git a/CMakeLists.txt b/CMakeLists.txt index bc48f8c8c..1a43d598d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,8 +8,8 @@ INCLUDE(Common) INCLUDE(FindQt5) ADD_SUBDIRECTORY (src/Event) +ADD_SUBDIRECTORY (src/Model) +ADD_SUBDIRECTORY (src/ModelAPI) ADD_SUBDIRECTORY (src/Config) -#ADD_SUBDIRECTORY (src/ModelAPI) -#ADD_SUBDIRECTORY (src/Model) ADD_SUBDIRECTORY (src/PartSet) ADD_SUBDIRECTORY (src/XGUI) diff --git a/CMakeLists.txt.orig b/CMakeLists.txt.orig new file mode 100644 index 000000000..bec6bea0a --- /dev/null +++ b/CMakeLists.txt.orig @@ -0,0 +1,20 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.8.11) + +PROJECT (NewGEOM) + +SET(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/CMakeCommon" ${CMAKE_MODULE_PATH}) + +INCLUDE(Common) +INCLUDE(FindQt5) + +ADD_SUBDIRECTORY (src/Event) +<<<<<<< Updated upstream +ADD_SUBDIRECTORY (src/Config) +#ADD_SUBDIRECTORY (src/ModelAPI) +#ADD_SUBDIRECTORY (src/Model) +ADD_SUBDIRECTORY (src/PartSet) +======= +ADD_SUBDIRECTORY (src/ModelAPI) +ADD_SUBDIRECTORY (src/Model) +>>>>>>> Stashed changes +ADD_SUBDIRECTORY (src/XGUI) diff --git a/buildNewGEOM.bat b/buildNewGEOM.bat index 51e29adda..a82fa4afe 100644 --- a/buildNewGEOM.bat +++ b/buildNewGEOM.bat @@ -13,6 +13,6 @@ call %SRC_DIR%\env.bat mkdir %ROOT_DIR%\build cd %ROOT_DIR%\build -cmake %SRC_DIR% -G "Visual Studio 10" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX:PATH=%ROOT_DIR%\install +cmake %SRC_DIR% -G "Visual Studio 10" -DWIN32 -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX:PATH=%ROOT_DIR%\install start "" %MSVC_EXE% NewGEOM.sln diff --git a/env.bat b/env.bat index ac6d75d7c..b0d1e3dec 100644 --- a/env.bat +++ b/env.bat @@ -120,6 +120,12 @@ if "%QTDIR%" == "" ( @SET PATH=%PDIR%\swig-2.0.9\bin;%PATH% @REM ------------------------- +@REM ------------------------- +@REM BOOST +@SET BOOST_ROOT_DIR=%PDIR%\boost-1.52.0 +@SET PATH=%BOOST_ROOT_DIR%\lib;%PATH% +@REM ------------------------- + @SET PATH=D:\NewGEOM\build-eclipse\bin;%PATH% rem -------- Visual Studio -------------------- diff --git a/src/Config/CMakeLists.txt b/src/Config/CMakeLists.txt index 63f5a9631..01be1d384 100644 --- a/src/Config/CMakeLists.txt +++ b/src/Config/CMakeLists.txt @@ -27,7 +27,7 @@ SET(XML_RESOURCES SET(PROJECT_LIBRARIES Event - ${LIBXML2_LIBRARIES} + ${LIBXML2_LIBRARIES} ) SOURCE_GROUP ("Resource Files" FILES ${XML_RESOURCES}) diff --git a/src/Config/Config_XMLReader.cpp b/src/Config/Config_XMLReader.cpp index c235c3355..fd625fc3f 100644 --- a/src/Config/Config_XMLReader.cpp +++ b/src/Config/Config_XMLReader.cpp @@ -111,6 +111,8 @@ xmlNodePtr Config_XMLReader::findRoot() */ void Config_XMLReader::readRecursively(xmlNodePtr theParent) { + static Event_ID aFeatureEvent = Event_Loop::EventByName("Feature"); + if(!theParent) return; xmlNodePtr aNode = theParent->xmlChildrenNode; @@ -118,6 +120,7 @@ void Config_XMLReader::readRecursively(xmlNodePtr theParent) processNode(aNode); if(processChildren(aNode)) { readRecursively(aNode); + Config_FeatureMessage aMessage(aFeatureEvent, this); } } } diff --git a/src/Config/Config_XMLReader.cpp.orig b/src/Config/Config_XMLReader.cpp.orig new file mode 100644 index 000000000..a0ee3aa7f --- /dev/null +++ b/src/Config/Config_XMLReader.cpp.orig @@ -0,0 +1,201 @@ +/* + * Config_XMLReader.cpp + * + * Created on: Mar 14, 2014 + * Author: sbh + */ + +#include + +#include +#include +#include + +#ifdef WIN32 +//For GetModuleFileNameW +#include +#endif + +#ifdef _DEBUG +#include +#endif + + +Config_XMLReader::Config_XMLReader(const std::string& theXmlFileName) +{ + std::string prefix; + //Get path to *.xml files (typically ./bin/../plugins/) +#ifdef WIN32 + HMODULE hModule = GetModuleHandleW(NULL); + WCHAR wchar_path[MAX_PATH]; + GetModuleFileNameW(hModule, wchar_path, MAX_PATH); + char char_path[MAX_PATH]; + char DefChar = ' '; + WideCharToMultiByte(CP_ACP, 0, wchar_path, -1, char_path, MAX_PATH, &DefChar, NULL); + prefix = std::string(char_path); + //chop "bin\XGUI.exe" + unsigned found = prefix.rfind("bin"); + if(found != std::string::npos) + prefix.replace(found, prefix.length(), "plugins\\"); +#else + //TODO(sbh): Find full path to binary on linux + prefix = "../plugins/"; +#endif + + m_DocumentPath = prefix + theXmlFileName; +} + + +Config_XMLReader::~Config_XMLReader() +{ +} + +/* + * Read all nodes (recursively if processChildren() is true + * for a node). For each read node the processNode will be + * called. + */ +void Config_XMLReader::readAll() +{ + xmlNodePtr aRoot = findRoot(); + readRecursively(aRoot); +} + +/* + * Allows to customize reader's behavior for a node. Virtual. + * The default implementation does nothing. (In debug mode prints + * some info) + */ +void Config_XMLReader::processNode(xmlNodePtr aNode) +{ + #ifdef _DEBUG + std::cout << "Config_XMLReader::processNode: " + << aNode->name << " content: " + << aNode->content << std::endl; + #endif +} + +/* + * Defines which nodes should be processed recursively. Virtual. + * The default implementation to read all nodes. + */ +bool Config_XMLReader::processChildren(xmlNodePtr aNode) +{ + return true; +} + +xmlNodePtr Config_XMLReader::findRoot() +{ + xmlDocPtr aDoc; + aDoc = xmlParseFile(m_DocumentPath.c_str()); + if(aDoc == NULL) { + #ifdef _DEBUG + std::cout << "Config_XMLReader::import: " << "Document " << m_DocumentPath + << " is not parsed successfully." << std::endl; + #endif + return NULL; + } + xmlNodePtr aRoot = xmlDocGetRootElement(aDoc); + #ifdef _DEBUG + if(aRoot == NULL) { + std::cout << "Config_XMLReader::import: " << "Error: empty document"; + } + #endif + return aRoot; +} + +/* + * Calls processNode() for each child (for some - recursively) + * of the given node. + * \sa ReadAll() + */ +void Config_XMLReader::readRecursively(xmlNodePtr theParent) +{ +<<<<<<< Updated upstream + if(!theParent) + return; + xmlNodePtr aNode = theParent->xmlChildrenNode; + for(; aNode; aNode = aNode->next) { + processNode(aNode); + if(processChildren(aNode)) { + readRecursively(aNode); +======= + static Event_ID aFeatureEvent = Event_Loop::EventByName("Feature"); + + xmlNodePtr aGroupNode = (static_cast(theRoot))->xmlChildrenNode; + Event_Loop* aEvLoop = Event_Loop::Loop(); + if(!aEvLoop) { + #ifdef _DEBUG + std::cout << "Config_XMLReader::importWorkbench: " + << "No event loop registered" << std::endl; + #endif + return false; + } + for(; aGroupNode; aGroupNode = aGroupNode->next) { // searching for record + if(!IsNode(aGroupNode, "group")) + continue; + std::string aGroupName = getProperty(aGroupNode, FEATURE_GROUP_NAME); + if(aGroupName.empty()) + continue; + xmlNodePtr aFtNode = aGroupNode->xmlChildrenNode; + for(; aFtNode; aFtNode = aFtNode->next) { + if(!IsNode(aFtNode, "feature")) + continue; + //Create feature... + Config_FeatureMessage aMessage(aFeatureEvent, this); + fillFeature(aFtNode, aMessage); + aMessage.m_group = aGroupName; + aEvLoop->Send(aMessage); +>>>>>>> Stashed changes + } + } +} + +/* + * void* -> xmlNodePtr + */ +xmlNodePtr Config_XMLReader::node(void* theNode) +{ + return static_cast(theNode); +} + +/* + * Returns named property for a given node as std::string. + */ +std::string Config_XMLReader::getProperty(xmlNodePtr theNode, const char* name) +{ + std::string result = ""; + char* aPropChars = (char*) xmlGetProp(theNode, BAD_CAST name); + if(!aPropChars || aPropChars[0] == 0) + return result; + result = std::string(aPropChars); + return result; +} + +/* + * Returns true if theNode is XML node with a given name. + */ +bool Config_XMLReader::isNode(xmlNodePtr theNode, const char* theNodeName, ...) +{ + bool result = false; + const xmlChar* aName = theNode->name; + if(!aName || theNode->type != XML_ELEMENT_NODE) + return false; + + if(!xmlStrcmp(aName, (const xmlChar *) theNodeName)) + return true; + + va_list args; // define argument list variable + va_start (args, theNodeName); // init list; point to last defined argument + while(true) { + char *anArg = va_arg (args, char *); // get next argument + if(anArg == NULL) + break; + if(!xmlStrcmp(aName, (const xmlChar *) anArg)) { + va_end (args); // cleanup the system stack + return true; + } + } + va_end (args); // cleanup the system stack + return false; +} diff --git a/src/Model/CMakeLists.txt b/src/Model/CMakeLists.txt index 44badeb68..c7d2585c2 100644 --- a/src/Model/CMakeLists.txt +++ b/src/Model/CMakeLists.txt @@ -2,23 +2,28 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.8.11) INCLUDE(Common) INCLUDE(FindCAS) +INCLUDE(FindBoost) SET(PROJECT_HEADERS Model.hxx - Model_Application.hxx Model_Document.hxx + Model_PluginManager.hxx + Model_Feature.hxx ) SET(PROJECT_SOURCES - Model_Application.cxx Model_Document.cxx + Model_PluginManager.cxx + Model_Feature.cxx ) -ADD_DEFINITIONS(-DMODEL_EXPORTS ${CAS_DEFINITIONS}) +ADD_DEFINITIONS(-DMODEL_EXPORTS ${CAS_DEFINITIONS} ${BOOST_DEFINITIONS}) ADD_LIBRARY(Model SHARED ${PROJECT_SOURCES} ${PROJECT_HEADERS}) -TARGET_LINK_LIBRARIES(Model ${PROJECT_LIBRARIES} ${CAS_OCAF}) +TARGET_LINK_LIBRARIES(Model ${PROJECT_LIBRARIES} ${CAS_OCAF} ModelAPI Event Config) INCLUDE_DIRECTORIES( ../ModelAPI + ../Event + ../Config ${CAS_INCLUDE_DIRS} ) diff --git a/src/Model/Model_Document.cxx b/src/Model/Model_Document.cxx index 42ce6f766..eec9755ab 100644 --- a/src/Model/Model_Document.cxx +++ b/src/Model/Model_Document.cxx @@ -4,7 +4,6 @@ // Copyright: CEA 2011 #include -#include #include @@ -23,6 +22,7 @@ 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 @@ -56,11 +56,14 @@ bool Model_Document::Load(const char* theFileName) } } SetUndoLimit(UNDO_LIMIT); + */ return !myIsError; } bool Model_Document::Save(const char* theFileName) { + bool myIsError = true; + /* TCollection_ExtendedString aPath ((const Standard_CString)theFileName); PCDM_StoreStatus aStatus; try { @@ -72,7 +75,7 @@ bool Model_Document::Save(const char* theFileName) cout<<"OCAFApp_Engine:save Error: "<GetMessageString()< + +using namespace std; + +Model_Feature::Model_Feature() +{ +} + +string Model_Feature::GetKind() +{ + return "Point"; +} diff --git a/src/Model/Model_Feature.hxx b/src/Model/Model_Feature.hxx new file mode 100644 index 000000000..fa632f183 --- /dev/null +++ b/src/Model/Model_Feature.hxx @@ -0,0 +1,27 @@ +// File: Model_Feature.hxx +// Created: 21 Mar 2014 +// Author: Mikhail PONIKAROV + +#ifndef Model_Feature_HeaderFile +#define Model_Feature_HeaderFile + +#include "Model.hxx" +#include + +/**\class Model_Feature + * \ingroup DataModel + * \brief General object of the application that allows + * to get/set attributes from the document and compute result of an operation. + */ + +class Model_Feature: public ModelAPI_Feature +{ + Model_Feature(); + + friend class Model_PluginManager; +public: + /// Returns the kind of a feature (like "Point") + virtual std::string GetKind(); +}; + +#endif diff --git a/src/Model/Model_PluginManager.cxx b/src/Model/Model_PluginManager.cxx new file mode 100644 index 000000000..bf7a06fcd --- /dev/null +++ b/src/Model/Model_PluginManager.cxx @@ -0,0 +1,36 @@ +// File: Model_PluginManager.cxx +// Created: 20 Mar 2014 +// Author: Mikhail PONIKAROV + +#include +#include +#include +#include +#include + +using namespace std; + +boost::shared_ptr Model_PluginManager::CreateFeature(string theFeatureID) +{ + return boost::shared_ptr(new Model_Feature()); +} + +Model_PluginManager::Model_PluginManager() +{ + static Event_ID aFeatureEvent = Event_Loop::EventByName("Feature"); + + static Model_PluginManager* myImpl = new Model_PluginManager(); + ModelAPI_PluginManager::SetPluginManager(boost::shared_ptr(myImpl)); + // register the configuration reading listener + Event_Loop* aLoop = Event_Loop::Loop(); + aLoop->RegisterListener(myImpl, aFeatureEvent); +} + +void Model_PluginManager::ProcessEvent(const Event_Message* theMessage) +{ + const Config_FeatureMessage* aMsg = + dynamic_cast( theMessage ); + if(aMsg) { + // proccess the plugin info, load plugin + } +} diff --git a/src/Model/Model_PluginManager.hxx b/src/Model/Model_PluginManager.hxx new file mode 100644 index 000000000..584eb63c5 --- /dev/null +++ b/src/Model/Model_PluginManager.hxx @@ -0,0 +1,33 @@ +// File: Model_PluginManager.hxx +// Created: 20 Mar 2014 +// Author: Mikhail PONIKAROV + +#ifndef Model_PluginManager_HeaderFile +#define Model_PluginManager_HeaderFile + +#include "Model.hxx" +#include +#include + +/**\class Model_PluginManager + * \ingroup DataModel + * \brief Object that knows (from the initial XML file) which + * plugin contains which feature, loads and stores reference to loaded plugins by + * the feature functionality request. + */ + +class MODEL_EXPORT Model_PluginManager : public ModelAPI_PluginManager, public Event_Listener +{ +public: + /// Creates the feature object using plugins functionality + virtual boost::shared_ptr CreateFeature(std::string theFeatureID); + + /// Processes the configuration file reading + virtual void ProcessEvent(const Event_Message* theMessage); + +private: + /// Is called only once, on startup of the application + Model_PluginManager(); +}; + +#endif diff --git a/src/ModelAPI/CMakeLists.txt b/src/ModelAPI/CMakeLists.txt index dc9e40965..e45b8eece 100644 --- a/src/ModelAPI/CMakeLists.txt +++ b/src/ModelAPI/CMakeLists.txt @@ -4,14 +4,21 @@ INCLUDE(Common) FIND_PACKAGE(SWIG REQUIRED) INCLUDE(${SWIG_USE_FILE}) INCLUDE(FindPython) +INCLUDE(FindBoost) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) SET(PROJECT_HEADERS ModelAPI.hxx - ModelAPI_Application.hxx + ModelAPI_Interface.hxx + ModelAPI_PluginManager.hxx + ModelAPI_Feature.hxx ModelAPI_Document.hxx ) +SET(PROJECT_SOURCES + ModelAPI_PluginManager.cxx +) + ADD_DEFINITIONS(-DMODELAPI_EXPORTS) ADD_LIBRARY(ModelAPI SHARED ${PROJECT_SOURCES} ${PROJECT_HEADERS}) SET_TARGET_PROPERTIES(ModelAPI PROPERTIES LINKER_LANGUAGE CXX) @@ -20,9 +27,10 @@ SET_TARGET_PROPERTIES(ModelAPI PROPERTIES LINKER_LANGUAGE CXX) SET(CMAKE_SWIG_FLAGS "") SET_SOURCE_FILES_PROPERTIES(ModelAPI.i PROPERTIES CPLUSPLUS ON) -SET_SOURCE_FILES_PROPERTIES(ModelAPI.i PROPERTIES SWIG_FLAGS "-includeall") +# "-includeall" is not needed: it starts to follow the standard inludes (like "string") without success +# SET_SOURCE_FILES_PROPERTIES(ModelAPI.i PROPERTIES SWIG_FLAGS) SET_SOURCE_FILES_PROPERTIES(ModelAPI.i PROPERTIES SWIG_DEFINITIONS "-shadow") -#SET_SOURCE_FILES_PROPERTIES(ModelAPIPYTHON_wrap.cxx PROPERTIES COMPILE_FLAGS "-DHAVE_CONFIG_H") +#SET_SOURCE_FILES_PROPERTIES(ModelAPIPYTHON_wrap.cxx PROPERTIES COMPILE_FLAGS "-D_WIN32") SET(SWIG_SCRIPTS ${CMAKE_CURRENT_BINARY_DIR}/ModelAPI.py diff --git a/src/ModelAPI/ModelAPI.i b/src/ModelAPI/ModelAPI.i index ffc072a2f..1f63f6c29 100644 --- a/src/ModelAPI/ModelAPI.i +++ b/src/ModelAPI/ModelAPI.i @@ -2,8 +2,24 @@ %module ModelAPI %{ #include "ModelAPI.hxx" - #include "ModelAPI_Application.hxx" #include "ModelAPI_Document.hxx" + #include "ModelAPI_PluginManager.hxx" + #include "ModelAPI_Feature.hxx" %} -%include "ModelAPI_Application.hxx" + +// to avoid error on this +#define MODELAPI_EXPORT + +// standard definitions +%include "typemaps.i" +%include "std_string.i" + +// boost pointers +%include +%shared_ptr(ModelAPI_PluginManager) +%shared_ptr(ModelAPI_Feature) + +// all supported interfaces %include "ModelAPI_Document.hxx" +%include "ModelAPI_PluginManager.hxx" +%include "ModelAPI_Feature.hxx" diff --git a/src/ModelAPI/ModelAPI_Application.hxx b/src/ModelAPI/ModelAPI_Application.hxx deleted file mode 100644 index 284e5a11d..000000000 --- a/src/ModelAPI/ModelAPI_Application.hxx +++ /dev/null @@ -1,27 +0,0 @@ -// 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 ModelAPI_Document; - -/**\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 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 index 02c537df1..cc8aa70df 100644 --- a/src/ModelAPI/ModelAPI_Document.hxx +++ b/src/ModelAPI/ModelAPI_Document.hxx @@ -49,11 +49,14 @@ public: //! Returns True if there are available Undos MODELAPI_EXPORT virtual bool CanUndo() = 0; //! Undoes last operation - MODELAPI_EXPORT virtual void Undo(); + MODELAPI_EXPORT virtual void Undo() = 0; //! Returns True if there are available Redos MODELAPI_EXPORT virtual bool CanRedo() = 0; //! Redoes last operation MODELAPI_EXPORT virtual void Redo() = 0; + + /// Only for SWIG wrapping it is here + MODELAPI_EXPORT ModelAPI_Document() {}; }; #endif diff --git a/src/ModelAPI/ModelAPI_Feature.hxx b/src/ModelAPI/ModelAPI_Feature.hxx new file mode 100644 index 000000000..ea84802cc --- /dev/null +++ b/src/ModelAPI/ModelAPI_Feature.hxx @@ -0,0 +1,30 @@ +// File: ModelAPI_Feature.hxx +// Created: 21 Mar 2014 +// Author: Mikhail PONIKAROV + +#ifndef ModelAPI_Feature_HeaderFile +#define ModelAPI_Feature_HeaderFile + +#include "ModelAPI.hxx" +#include + +class ModelAPI_Feature; + +/**\class ModelAPI_Feature + * \ingroup DataModel + * \brief General object of the application that allows + * to get/set attributes from the document and compute result of an operation. + */ + +class MODELAPI_EXPORT ModelAPI_Feature +{ +public: + /// Returns the kind of a feature (like "Point") + virtual std::string GetKind() = 0; + + /// Use plugin manager for features creation: this method is + /// defined here only for SWIG-wrapping + ModelAPI_Feature() {} +}; + +#endif diff --git a/src/ModelAPI/ModelAPI_Interface.hxx b/src/ModelAPI/ModelAPI_Interface.hxx new file mode 100644 index 000000000..377b7eab7 --- /dev/null +++ b/src/ModelAPI/ModelAPI_Interface.hxx @@ -0,0 +1,38 @@ +// File: ModelAPI_Interface.hxx +// Created: 20 Mar 2014 +// Author: Mikhail PONIKAROV + +#ifndef ModelAPI_Interface_HeaderFile +#define ModelAPI_Interface_HeaderFile + +#include + +/**\class ModelAPI_Interface + * \ingroup DataModel + * \brief General base class for all interfaces in this package + */ + +class MODELAPI_EXPORT ModelAPI_Interface +{ + void* myImpl; ///< pointer to the internal implementation object + +public: + /// None - constructor + virtual ModelAPI_Interface() {myImpl = 0;} + + /// Constructor by the implementation pointer (used for internal needs) + virtual ModelAPI_Interface(void* theImpl) {myImpl = theImpl;} + + /// Copy-constructor + virtual ModelAPI_Interface(ModelAPI_Interface& theOrig) + {myImpl = theOrig.theImpl; Duplicate();} + + virtual ModelAPI_Interface& operator=(ModelAPI_Interface& const theOrig) + {myImpl = theOrig.theImpl; Duplicate(); return *this;} + + /// Duplicates the objet pointed by myImpl (loosing the old one) + virtual void Duplicate() = 0; + +}; + +#endif diff --git a/src/ModelAPI/ModelAPI_PluginManager.cxx b/src/ModelAPI/ModelAPI_PluginManager.cxx new file mode 100644 index 000000000..889b6e7d6 --- /dev/null +++ b/src/ModelAPI/ModelAPI_PluginManager.cxx @@ -0,0 +1,26 @@ +// File: ModelAPI_PluginManager.hxx +// Created: 20 Mar 2014 +// Author: Mikhail PONIKAROV + +#include +// to avoid unresolved ModelAPI_Document() +#include +// to avoid unresolved ModelAPI_Feature() +#include + +/// Manager that will be initialized from Model package, one per application +boost::shared_ptr MY_MANAGER; + +ModelAPI_PluginManager::ModelAPI_PluginManager() +{} + +boost::shared_ptr ModelAPI_PluginManager::Get() +{ + return MY_MANAGER; +} + +void ModelAPI_PluginManager::SetPluginManager( + boost::shared_ptr theManager) +{ + MY_MANAGER = theManager; +} diff --git a/src/ModelAPI/ModelAPI_PluginManager.hxx b/src/ModelAPI/ModelAPI_PluginManager.hxx new file mode 100644 index 000000000..1d6a2e206 --- /dev/null +++ b/src/ModelAPI/ModelAPI_PluginManager.hxx @@ -0,0 +1,37 @@ +// File: ModelAPI_PluginManager.hxx +// Created: 20 Mar 2014 +// Author: Mikhail PONIKAROV + +#ifndef ModelAPI_PluginManager_HeaderFile +#define ModelAPI_PluginManager_HeaderFile + +#include "ModelAPI.hxx" +#include +#include + +class ModelAPI_Feature; + +/**\class ModelAPI_PluginManager + * \ingroup DataModel + * \brief Object that knows (from the initial XML file) which + * plugin contains which feature, loads and stores reference to loaded plugins by + * the feature functionality request. + */ + +class MODELAPI_EXPORT ModelAPI_PluginManager +{ +public: + /// Creates the feature object using plugins functionality + virtual boost::shared_ptr CreateFeature(std::string theFeatureID) = 0; + + /// Returns the real implementation (the alone instance per application) of the plugin manager + static boost::shared_ptr Get(); + + /// Is needed for python wrapping by swig, call Get to get an instance + ModelAPI_PluginManager(); + +protected: + static void SetPluginManager(boost::shared_ptr theManager); +}; + +#endif