From f342d014533c99cbd6a81a8cd42de6fb68090a2d Mon Sep 17 00:00:00 2001 From: spo Date: Thu, 16 Jun 2016 16:28:38 +0300 Subject: [PATCH] Add ParametersAPI --- CMakeLists.txt | 1 + src/ParametersAPI/CMakeLists.txt | 69 +++++++++++++++++++ src/ParametersAPI/ParametersAPI.h | 20 ++++++ src/ParametersAPI/ParametersAPI.i | 25 +++++++ src/ParametersAPI/ParametersAPI_Parameter.cpp | 45 ++++++++++++ src/ParametersAPI/ParametersAPI_Parameter.h | 59 ++++++++++++++++ src/ParametersAPI/ParametersAPI_swig.h | 14 ++++ src/PythonAPI/Test/TestFeatures.py | 3 +- src/PythonAPI/model/parameter/__init__.py | 2 +- 9 files changed, 236 insertions(+), 2 deletions(-) create mode 100644 src/ParametersAPI/CMakeLists.txt create mode 100644 src/ParametersAPI/ParametersAPI.h create mode 100644 src/ParametersAPI/ParametersAPI.i create mode 100644 src/ParametersAPI/ParametersAPI_Parameter.cpp create mode 100644 src/ParametersAPI/ParametersAPI_Parameter.h create mode 100644 src/ParametersAPI/ParametersAPI_swig.h diff --git a/CMakeLists.txt b/CMakeLists.txt index bbfe7510c..30b019882 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -99,6 +99,7 @@ ADD_SUBDIRECTORY (src/ModelHighAPI) ADD_SUBDIRECTORY (src/ConstructionAPI) ADD_SUBDIRECTORY (src/ExchangeAPI) ADD_SUBDIRECTORY (src/FeaturesAPI) +ADD_SUBDIRECTORY (src/ParametersAPI) ADD_SUBDIRECTORY (src/PartSetAPI) ADD_SUBDIRECTORY (src/SketchAPI) diff --git a/src/ParametersAPI/CMakeLists.txt b/src/ParametersAPI/CMakeLists.txt new file mode 100644 index 000000000..ee18966a3 --- /dev/null +++ b/src/ParametersAPI/CMakeLists.txt @@ -0,0 +1,69 @@ +## Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +INCLUDE(Common) + +SET(PROJECT_HEADERS + ParametersAPI.h + ParametersAPI_Parameter.h +) + +SET(PROJECT_SOURCES + ParametersAPI_Parameter.cpp +) + +SET(PROJECT_LIBRARIES + ModelAPI + ModelHighAPI +) + +INCLUDE_DIRECTORIES( + ${PROJECT_SOURCE_DIR}/src/Events + ${PROJECT_SOURCE_DIR}/src/ModelAPI + ${PROJECT_SOURCE_DIR}/src/ModelHighAPI +) + +# Plugin headers dependency +INCLUDE_DIRECTORIES( + # TODO(spo): modify ParametersPlugin headers to remove dependency on GeomAPI headers + ${PROJECT_SOURCE_DIR}/src/GeomAPI + # TODO(spo): it is for *_swig.h files. Can we eliminate it? + ${PROJECT_SOURCE_DIR}/src/GeomDataAPI + ${PROJECT_SOURCE_DIR}/src/ParametersPlugin +) + +#TODO(spo): is ${CAS_DEFINITIONS} necessary? +ADD_DEFINITIONS(-DCONSTRUCTIONAPI_EXPORTS ${CAS_DEFINITIONS}) +ADD_LIBRARY(ParametersAPI SHARED ${PROJECT_SOURCES} ${PROJECT_HEADERS}) +TARGET_LINK_LIBRARIES(ParametersAPI ${PROJECT_LIBRARIES}) + +# SWIG wrapper + +INCLUDE(PythonAPI) + +SET_SOURCE_FILES_PROPERTIES(ParametersAPI.i PROPERTIES CPLUSPLUS ON) +SET_SOURCE_FILES_PROPERTIES(ParametersAPI.i PROPERTIES SWIG_DEFINITIONS "-shadow") + +#TODO(spo): is ModelAPI necessary or it could be received by INTERFACE_ (may require modern CMake)? +SET(SWIG_LINK_LIBRARIES + ParametersAPI + ModelHighAPI + ModelAPI + ${PYTHON_LIBRARIES} +) + +SET(SWIG_MODULE_ParametersAPI_EXTRA_DEPS ${SWIG_MODULE_ParametersAPI_EXTRA_DEPS} + ${PROJECT_SOURCE_DIR}/src/ModelHighAPI/ModelHighAPI.i + doxyhelp.i + ${PROJECT_HEADERS} +) + +SWIG_ADD_MODULE(ParametersAPI python ParametersAPI.i ${PROJECT_HEADERS}) +SWIG_LINK_LIBRARIES(ParametersAPI ${SWIG_LINK_LIBRARIES}) + +IF(WIN32) + SET_TARGET_PROPERTIES(_ParametersAPI PROPERTIES DEBUG_OUTPUT_NAME _ParametersAPI_d) +ENDIF(WIN32) + +INSTALL(TARGETS _ParametersAPI DESTINATION ${SHAPER_INSTALL_SWIG}) +INSTALL(TARGETS ParametersAPI DESTINATION ${SHAPER_INSTALL_BIN}) +INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/ParametersAPI.py DESTINATION ${SHAPER_INSTALL_SWIG}) diff --git a/src/ParametersAPI/ParametersAPI.h b/src/ParametersAPI/ParametersAPI.h new file mode 100644 index 000000000..483dcce2f --- /dev/null +++ b/src/ParametersAPI/ParametersAPI.h @@ -0,0 +1,20 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +#ifndef PARAMETERSAPI_H +#define PARAMETERSAPI_H + +#if defined PARAMETERSAPI_EXPORTS +#if defined WIN32 +#define PARAMETERSAPI_EXPORT __declspec( dllexport ) +#else +#define PARAMETERSAPI_EXPORT +#endif +#else +#if defined WIN32 +#define PARAMETERSAPI_EXPORT __declspec( dllimport ) +#else +#define PARAMETERSAPI_EXPORT +#endif +#endif + +#endif diff --git a/src/ParametersAPI/ParametersAPI.i b/src/ParametersAPI/ParametersAPI.i new file mode 100644 index 000000000..b7b72ec44 --- /dev/null +++ b/src/ParametersAPI/ParametersAPI.i @@ -0,0 +1,25 @@ +/* ParametersAPI.i */ + +%module ParametersAPI + +%{ + #include "ParametersAPI_swig.h" +%} + +%include "doxyhelp.i" + +// import other modules +%import "ModelHighAPI.i" + +// to avoid error on this +#define PARAMETERSAPI_EXPORT + +// standard definitions +%include "typemaps.i" +%include "std_shared_ptr.i" + +// shared pointers +%shared_ptr(ParametersAPI_Parameter) + +// all supported interfaces +%include "ParametersAPI_Parameter.h" diff --git a/src/ParametersAPI/ParametersAPI_Parameter.cpp b/src/ParametersAPI/ParametersAPI_Parameter.cpp new file mode 100644 index 000000000..8ea872d37 --- /dev/null +++ b/src/ParametersAPI/ParametersAPI_Parameter.cpp @@ -0,0 +1,45 @@ +// Name : ParametersAPI_Parameter.cpp +// Purpose: +// +// History: +// 16/06/16 - Sergey POKHODENKO - Creation of the file + +//-------------------------------------------------------------------------------------- +#include "ParametersAPI_Parameter.h" +//-------------------------------------------------------------------------------------- +#include +//-------------------------------------------------------------------------------------- +ParametersAPI_Parameter::ParametersAPI_Parameter( + const std::shared_ptr & theFeature) +: ModelHighAPI_Interface(theFeature) +{ + initialize(); +} + +ParametersAPI_Parameter::ParametersAPI_Parameter( + const std::shared_ptr & theFeature, + const std::string & theName, + const ModelHighAPI_Double & theExpression) +: ModelHighAPI_Interface(theFeature) +{ + if (initialize()) { + fillAttribute(theName, name()); + fillAttribute(theExpression, expression()); + + execute(); + } +} + +ParametersAPI_Parameter::~ParametersAPI_Parameter() +{ +} + +//-------------------------------------------------------------------------------------- +ParameterPtr addParameter(const std::shared_ptr & theParameter, + const std::string & theName, + const ModelHighAPI_Double & theExpression) +{ + // TODO(spo): check that theParameter is not empty + std::shared_ptr aFeature = theParameter->addFeature(ParametersAPI_Parameter::ID()); + return ParameterPtr(new ParametersAPI_Parameter(aFeature)); +} diff --git a/src/ParametersAPI/ParametersAPI_Parameter.h b/src/ParametersAPI/ParametersAPI_Parameter.h new file mode 100644 index 000000000..5a3023d9b --- /dev/null +++ b/src/ParametersAPI/ParametersAPI_Parameter.h @@ -0,0 +1,59 @@ +// Name : ParametersAPI_Parameter.h +// Purpose: +// +// History: +// 16/06/16 - Sergey POKHODENKO - Creation of the file + +#ifndef SRC_PARAMETERSAPI_PARAMETERSAPI_PARAMETER_H_ +#define SRC_PARAMETERSAPI_PARAMETERSAPI_PARAMETER_H_ + +//-------------------------------------------------------------------------------------- +#include "ParametersAPI.h" + +#include + +#include +#include +//-------------------------------------------------------------------------------------- +class ModelHighAPI_Double; +//-------------------------------------------------------------------------------------- +/**\class ParametersAPI_Parameter + * \ingroup CPPHighAPI + * \brief Interface for Parameter feature + */ +class ParametersAPI_Parameter : public ModelHighAPI_Interface +{ +public: + /// Constructor without values + PARAMETERSAPI_EXPORT + explicit ParametersAPI_Parameter(const std::shared_ptr & theFeature); + /// Constructor with values + PARAMETERSAPI_EXPORT + explicit ParametersAPI_Parameter(const std::shared_ptr & theFeature, + const std::string & theName, + const ModelHighAPI_Double & theExpression); + /// Destructor + PARAMETERSAPI_EXPORT + virtual ~ParametersAPI_Parameter(); + + INTERFACE_2(ParametersPlugin_Parameter::ID(), + name, ParametersPlugin_Parameter::VARIABLE_ID(), ModelAPI_AttributeString, /** Name */, + expression, ParametersPlugin_Parameter::EXPRESSION_ID(), ModelAPI_AttributeDouble, /** Expression */ + ) + +}; + +//! Pointer on Parameter object +typedef std::shared_ptr ParameterPtr; + +/**\ingroup CPPHighAPI + * \brief Create Parameter feature + */ +PARAMETERSAPI_EXPORT +ParameterPtr addParameter(const std::shared_ptr & thePart, + const std::string & theName, + const ModelHighAPI_Double & theExpression); + +//-------------------------------------------------------------------------------------- +//-------------------------------------------------------------------------------------- +#endif /* SRC_PARAMETERSAPI_PARAMETERSAPI_PARAMETER_H_ */ diff --git a/src/ParametersAPI/ParametersAPI_swig.h b/src/ParametersAPI/ParametersAPI_swig.h new file mode 100644 index 000000000..fc7bf1657 --- /dev/null +++ b/src/ParametersAPI/ParametersAPI_swig.h @@ -0,0 +1,14 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: ParametersAPI_swig.h +// Created: 16/06/16 +// Author: Sergey POKHODENKO + +#ifndef SRC_PARAMETERSAPI_PARAMETERSAPI_SWIG_H_ +#define SRC_PARAMETERSAPI_PARAMETERSAPI_SWIG_H_ + + #include + + #include "ParametersAPI_Parameter.h" + +#endif /* SRC_PARAMETERSAPI_PARAMETERSAPI_SWIG_H_ */ diff --git a/src/PythonAPI/Test/TestFeatures.py b/src/PythonAPI/Test/TestFeatures.py index 8e4f43039..f4ef8e423 100644 --- a/src/PythonAPI/Test/TestFeatures.py +++ b/src/PythonAPI/Test/TestFeatures.py @@ -74,7 +74,8 @@ class FeaturesTestCase(FeaturesFixture): FeaturesAPI.FeaturesAPI_Translation(self.part.addFeature("Translation")) FeaturesAPI.FeaturesAPI_Group(self.part.addFeature("Group")) - model.parameter.Parameter(self.part.addFeature("Parameter")) + import ParametersAPI + ParametersAPI.ParametersAPI_Parameter(self.part.addFeature("Parameter")) #----------------------------------------------------------------------------- diff --git a/src/PythonAPI/model/parameter/__init__.py b/src/PythonAPI/model/parameter/__init__.py index 44bde3f35..fb276792d 100644 --- a/src/PythonAPI/model/parameter/__init__.py +++ b/src/PythonAPI/model/parameter/__init__.py @@ -1,4 +1,4 @@ """Package for Parameter plugin for the Parametric Geometry API of the Modeler. """ -from parameter import addParameter \ No newline at end of file +from ParametersAPI import addParameter \ No newline at end of file -- 2.39.2