From 421e05a30e1122e497be417f55cfcaaece238394 Mon Sep 17 00:00:00 2001 From: spo Date: Wed, 8 Jun 2016 12:23:22 +0300 Subject: [PATCH] Add SketchAPI and Line feature. Also fix tests. --- CMakeLists.txt | 1 + src/ModelHighAPI/ModelHighAPI_Tools.cpp | 6 + src/ModelHighAPI/ModelHighAPI_Tools.h | 4 + src/PythonAPI/Test/TestSketcherAddLine.py | 14 +-- src/PythonAPI/model/__init__.py | 2 +- src/PythonAPI/model/services.py | 2 +- src/PythonAPI/model/sketcher/__init__.py | 4 + src/SketchAPI/CMakeLists.txt | 83 ++++++++++++++ src/SketchAPI/SketchAPI.h | 20 ++++ src/SketchAPI/SketchAPI.i | 30 +++++ src/SketchAPI/SketchAPI_Line.cpp | 129 ++++++++++++++++++++++ src/SketchAPI/SketchAPI_Line.h | 98 ++++++++++++++++ src/SketchAPI/SketchAPI_Sketch.cpp | 110 ++++++++++++++++++ src/SketchAPI/SketchAPI_Sketch.h | 103 +++++++++++++++++ src/SketchAPI/SketchAPI_SketchEntity.cpp | 45 ++++++++ src/SketchAPI/SketchAPI_SketchEntity.h | 51 +++++++++ src/SketchAPI/SketchAPI_swig.h | 17 +++ src/SketchAPI/Test/TestSketch.py | 26 +++++ 18 files changed, 736 insertions(+), 9 deletions(-) create mode 100644 src/SketchAPI/CMakeLists.txt create mode 100644 src/SketchAPI/SketchAPI.h create mode 100644 src/SketchAPI/SketchAPI.i create mode 100644 src/SketchAPI/SketchAPI_Line.cpp create mode 100644 src/SketchAPI/SketchAPI_Line.h create mode 100644 src/SketchAPI/SketchAPI_Sketch.cpp create mode 100644 src/SketchAPI/SketchAPI_Sketch.h create mode 100644 src/SketchAPI/SketchAPI_SketchEntity.cpp create mode 100644 src/SketchAPI/SketchAPI_SketchEntity.h create mode 100644 src/SketchAPI/SketchAPI_swig.h create mode 100644 src/SketchAPI/Test/TestSketch.py diff --git a/CMakeLists.txt b/CMakeLists.txt index 854053df0..53625f7bc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -98,6 +98,7 @@ ADD_SUBDIRECTORY (src/PythonAPI) ADD_SUBDIRECTORY (src/ModelHighAPI) ADD_SUBDIRECTORY (src/ConstructionAPI) ADD_SUBDIRECTORY (src/ExchangeAPI) +ADD_SUBDIRECTORY (src/SketchAPI) IF(${HAVE_SALOME}) ADD_SUBDIRECTORY (src/SHAPERGUI) diff --git a/src/ModelHighAPI/ModelHighAPI_Tools.cpp b/src/ModelHighAPI/ModelHighAPI_Tools.cpp index 0c82867a6..46bf241bd 100644 --- a/src/ModelHighAPI/ModelHighAPI_Tools.cpp +++ b/src/ModelHighAPI/ModelHighAPI_Tools.cpp @@ -38,6 +38,12 @@ void fillAttribute(const std::shared_ptr & theValue, theAttribute->setValue(theValue); } +void fillAttribute(const std::shared_ptr & theAttribute, + double theX, double theY) +{ + theAttribute->setValue(theX, theY); +} + //-------------------------------------------------------------------------------------- void fillAttribute(const std::shared_ptr & theValue, const std::shared_ptr & theAttribute) diff --git a/src/ModelHighAPI/ModelHighAPI_Tools.h b/src/ModelHighAPI/ModelHighAPI_Tools.h index fbfd81f97..91163898d 100644 --- a/src/ModelHighAPI/ModelHighAPI_Tools.h +++ b/src/ModelHighAPI/ModelHighAPI_Tools.h @@ -42,6 +42,10 @@ MODELHIGHAPI_EXPORT void fillAttribute(const std::shared_ptr & theValue, const std::shared_ptr & theAttribute); +MODELHIGHAPI_EXPORT +void fillAttribute(const std::shared_ptr & theAttribute, + double theX, double theY); + MODELHIGHAPI_EXPORT void fillAttribute(const std::shared_ptr & theValue, const std::shared_ptr & theAttribute); diff --git a/src/PythonAPI/Test/TestSketcherAddLine.py b/src/PythonAPI/Test/TestSketcherAddLine.py index fa4ed94c6..25f53b338 100644 --- a/src/PythonAPI/Test/TestSketcherAddLine.py +++ b/src/PythonAPI/Test/TestSketcherAddLine.py @@ -2,22 +2,22 @@ import unittest import model from TestSketcher import SketcherTestCase -class SketcherAddLine(SketcherTestCase): +class SketcherAddLine(SketcherTestCase): def test_add_line(self): line = self.sketch.addLine(0, 0, 0, 1) model.do() - self.assertEqual(line.getStartPoint().x(), line.getEndPoint().x()) - self.assertNotEqual(line.getStartPoint().y(), line.getEndPoint().y()) + self.assertEqual(line.startPoint().x(), line.endPoint().x()) + self.assertNotEqual(line.startPoint().y(), line.endPoint().y()) def test_modify_line(self): line = self.sketch.addLine(0, 0, 0, 1) model.do() line.setStartPoint(0, 1) line.setEndPoint(1, 1) - self.assertEqual(line.getStartPoint().x(), 0) - self.assertEqual(line.getStartPoint().y(), 1) - self.assertEqual(line.getEndPoint().x(), 1) - self.assertEqual(line.getEndPoint().y(), 1) + self.assertEqual(line.startPoint().x(), 0) + self.assertEqual(line.startPoint().y(), 1) + self.assertEqual(line.endPoint().x(), 1) + self.assertEqual(line.endPoint().y(), 1) if __name__ == "__main__": diff --git a/src/PythonAPI/model/__init__.py b/src/PythonAPI/model/__init__.py index 3a8c553ae..c5b71cbf4 100644 --- a/src/PythonAPI/model/__init__.py +++ b/src/PythonAPI/model/__init__.py @@ -14,7 +14,7 @@ from tools import Selection # Built-in features -from sketcher.sketch import addSketch +from sketcher import * from connection import * from construction import * from exchange import * diff --git a/src/PythonAPI/model/services.py b/src/PythonAPI/model/services.py index b978bd025..593505f56 100644 --- a/src/PythonAPI/model/services.py +++ b/src/PythonAPI/model/services.py @@ -43,7 +43,7 @@ def defaultPlane (name): n = GeomAPI.GeomAPI_Dir(1, 0, 0) x = GeomAPI.GeomAPI_Dir(0, 1, 0) - return geom.Ax3(o, n, x) + return GeomAPI.GeomAPI_Ax3(o, n, x) def begin (): diff --git a/src/PythonAPI/model/sketcher/__init__.py b/src/PythonAPI/model/sketcher/__init__.py index e69de29bb..ca5243873 100644 --- a/src/PythonAPI/model/sketcher/__init__.py +++ b/src/PythonAPI/model/sketcher/__init__.py @@ -0,0 +1,4 @@ +"""Package for Sketch plugin for the Parametric Geometry API of the Modeler. +""" + +from SketchAPI import addSketch \ No newline at end of file diff --git a/src/SketchAPI/CMakeLists.txt b/src/SketchAPI/CMakeLists.txt new file mode 100644 index 000000000..4a62c018a --- /dev/null +++ b/src/SketchAPI/CMakeLists.txt @@ -0,0 +1,83 @@ +## Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +INCLUDE(Common) + +SET(PROJECT_HEADERS + SketchAPI.h + SketchAPI_Line.h + SketchAPI_Sketch.h + SketchAPI_SketchEntity.h +) + +SET(PROJECT_SOURCES + SketchAPI_Line.cpp + SketchAPI_Sketch.cpp + SketchAPI_SketchEntity.cpp +) + +SET(PROJECT_LIBRARIES + ModelAPI + ModelHighAPI +) + +INCLUDE_DIRECTORIES( + ${PROJECT_SOURCE_DIR}/src/Events + ${PROJECT_SOURCE_DIR}/src/GeomDataAPI + ${PROJECT_SOURCE_DIR}/src/ModelAPI + ${PROJECT_SOURCE_DIR}/src/ModelHighAPI +) + +# Plugin headers dependency +INCLUDE_DIRECTORIES( + # TODO(spo): modify ConstructionPlugin headers to remove dependency on GeomAPI headers + ${PROJECT_SOURCE_DIR}/src/Config + ${PROJECT_SOURCE_DIR}/src/GeomAPI + ${PROJECT_SOURCE_DIR}/src/SketchPlugin +) + +#TODO(spo): is ${CAS_DEFINITIONS} necessary? +ADD_DEFINITIONS(-DSKETCHAPI_EXPORTS ${CAS_DEFINITIONS}) +ADD_LIBRARY(SketchAPI SHARED ${PROJECT_SOURCES} ${PROJECT_HEADERS}) +TARGET_LINK_LIBRARIES(SketchAPI ${PROJECT_LIBRARIES}) + +# SWIG wrapper + +INCLUDE(PythonAPI) + +SET_SOURCE_FILES_PROPERTIES(SketchAPI.i PROPERTIES CPLUSPLUS ON) +SET_SOURCE_FILES_PROPERTIES(SketchAPI.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 + SketchAPI + ModelHighAPI + ModelAPI + ${PYTHON_LIBRARIES} +) + +SET(SWIG_MODULE_SketchAPI_EXTRA_DEPS ${SWIG_MODULE_SketchAPI_EXTRA_DEPS} + ${PROJECT_SOURCE_DIR}/src/ModelHighAPI/ModelHighAPI.i + doxyhelp.i + ${PROJECT_HEADERS} +) + +SWIG_ADD_MODULE(SketchAPI python SketchAPI.i ${PROJECT_HEADERS}) +SWIG_LINK_LIBRARIES(SketchAPI ${SWIG_LINK_LIBRARIES}) + +IF(WIN32) + SET_TARGET_PROPERTIES(_SketchAPI PROPERTIES DEBUG_OUTPUT_NAME _SketchAPI_d) +ENDIF(WIN32) + +INSTALL(TARGETS _SketchAPI DESTINATION ${SHAPER_INSTALL_SWIG}) +INSTALL(TARGETS SketchAPI DESTINATION ${SHAPER_INSTALL_BIN}) +INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/SketchAPI.py DESTINATION ${SHAPER_INSTALL_SWIG}) + +# Tests + +INCLUDE(UnitTest) + +ADD_UNIT_TESTS( + TestSketch.py +) + +# ADD_SUBDIRECTORY (Test) diff --git a/src/SketchAPI/SketchAPI.h b/src/SketchAPI/SketchAPI.h new file mode 100644 index 000000000..f55dd628a --- /dev/null +++ b/src/SketchAPI/SketchAPI.h @@ -0,0 +1,20 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +#ifndef SKETCHAPI_H +#define SKETCHAPI_H + +#if defined SKETCHAPI_EXPORTS +#if defined WIN32 +#define SKETCHAPI_EXPORT __declspec( dllexport ) +#else +#define SKETCHAPI_EXPORT +#endif +#else +#if defined WIN32 +#define SKETCHAPI_EXPORT __declspec( dllimport ) +#else +#define SKETCHAPI_EXPORT +#endif +#endif + +#endif diff --git a/src/SketchAPI/SketchAPI.i b/src/SketchAPI/SketchAPI.i new file mode 100644 index 000000000..854d74fbd --- /dev/null +++ b/src/SketchAPI/SketchAPI.i @@ -0,0 +1,30 @@ +/* SketchAPI.i */ + +%module SketchAPI + +%{ + #include "SketchAPI_swig.h" +%} + +%include "doxyhelp.i" + +// import other modules +%import "ModelHighAPI.i" + +// to avoid error on this +#define SKETCHAPI_EXPORT + +// standard definitions +%include "typemaps.i" +%include "std_list.i" +%include "std_shared_ptr.i" + +// shared pointers +%shared_ptr(SketchAPI_Line) +%shared_ptr(SketchAPI_Sketch) +%shared_ptr(SketchAPI_SketchEntity) + +// all supported interfaces +%include "SketchAPI_Line.h" +%include "SketchAPI_Sketch.h" +%include "SketchAPI_SketchEntity.h" diff --git a/src/SketchAPI/SketchAPI_Line.cpp b/src/SketchAPI/SketchAPI_Line.cpp new file mode 100644 index 000000000..f36c91c88 --- /dev/null +++ b/src/SketchAPI/SketchAPI_Line.cpp @@ -0,0 +1,129 @@ +// Name : SketchAPI_Line.cpp +// Purpose: +// +// History: +// 07/06/16 - Sergey POKHODENKO - Creation of the file + +//-------------------------------------------------------------------------------------- +#include "SketchAPI_Line.h" +//-------------------------------------------------------------------------------------- +#include +//-------------------------------------------------------------------------------------- +#include +#include +//-------------------------------------------------------------------------------------- +SketchAPI_Line::SketchAPI_Line( + const std::shared_ptr & theFeature) +: ModelHighAPI_Interface(theFeature) +{ + initialize(); +} + +SketchAPI_Line::SketchAPI_Line( + const std::shared_ptr & theFeature, + double theX1, double theY1, double theX2, double theY2) +: ModelHighAPI_Interface(theFeature) +{ + if (initialize()) { + setByCoordinates(theX1, theY1, theX2, theY2); + } +} + +SketchAPI_Line::SketchAPI_Line( + const std::shared_ptr & theFeature, + const std::shared_ptr & theStartPoint, + const std::shared_ptr & theEndPoint) +: ModelHighAPI_Interface(theFeature) +{ + if (initialize()) { + setByPoints(theStartPoint, theEndPoint); + } +} + +SketchAPI_Line::SketchAPI_Line( + const std::shared_ptr & theFeature, + const ModelHighAPI_Selection & theExternal ) +: ModelHighAPI_Interface(theFeature) +{ + if (initialize()) { + setByExternal(theExternal); + } +} + +SketchAPI_Line::SketchAPI_Line( + const std::shared_ptr & theFeature, + const std::string & theExternalName ) +: ModelHighAPI_Interface(theFeature) +{ + if (initialize()) { + setByExternalName(theExternalName); + } +} + +SketchAPI_Line::~SketchAPI_Line() +{ + +} + +//-------------------------------------------------------------------------------------- +void SketchAPI_Line::setByCoordinates( + double theX1, double theY1, double theX2, double theY2) +{ + fillAttribute(startPoint(), theX1, theY1); + fillAttribute(endPoint(), theX2, theY2); + + execute(); +} + +void SketchAPI_Line::setByPoints( + const std::shared_ptr & theStartPoint, + const std::shared_ptr & theEndPoint) +{ + fillAttribute(theStartPoint, startPoint()); + fillAttribute(theEndPoint, endPoint()); + + execute(); +} + +void SketchAPI_Line::setByExternal(const ModelHighAPI_Selection & theExternal) +{ + fillAttribute(theExternal, external()); + + execute(); +} + +void SketchAPI_Line::setByExternalName(const std::string & theExternalName) +{ + fillAttribute(ModelHighAPI_Selection("EDGE", theExternalName), external()); + + execute(); +} + +//-------------------------------------------------------------------------------------- +void SketchAPI_Line::setStartPoint(double theX, double theY) +{ + fillAttribute(startPoint(), theX, theY); + + execute(); +} +void SketchAPI_Line::setStartPoint(const std::shared_ptr & thePoint) +{ + fillAttribute(thePoint, startPoint()); + + execute(); +} +void SketchAPI_Line::setEndPoint(double theX, double theY) +{ + fillAttribute(endPoint(), theX, theY); + + execute(); +} +void SketchAPI_Line::setEndPoint(const std::shared_ptr & thePoint) +{ + fillAttribute(thePoint, endPoint()); + + execute(); +} + +//-------------------------------------------------------------------------------------- + diff --git a/src/SketchAPI/SketchAPI_Line.h b/src/SketchAPI/SketchAPI_Line.h new file mode 100644 index 000000000..5796c66be --- /dev/null +++ b/src/SketchAPI/SketchAPI_Line.h @@ -0,0 +1,98 @@ +// Name : SketchAPI_Line.h +// Purpose: +// +// History: +// 07/06/16 - Sergey POKHODENKO - Creation of the file + +#ifndef SRC_SKETCHAPI_SKETCHAPI_LINE_H_ +#define SRC_SKETCHAPI_SKETCHAPI_LINE_H_ + +//-------------------------------------------------------------------------------------- +#include "SketchAPI.h" + +#include + +#include + +#include +#include +//-------------------------------------------------------------------------------------- +class ModelHighAPI_Selection; +//-------------------------------------------------------------------------------------- +/**\class SketchAPI_Line + * \ingroup CPPHighAPI + * \brief Interface for Line feature + */ +class SketchAPI_Line : public ModelHighAPI_Interface +{ +public: + /// Constructor without values + SKETCHAPI_EXPORT + explicit SketchAPI_Line(const std::shared_ptr & theFeature); + /// Constructor with values + SKETCHAPI_EXPORT + SketchAPI_Line(const std::shared_ptr & theFeature, + double theX1, double theY1, double theX2, double theY2); + /// Constructor with values + SKETCHAPI_EXPORT + SketchAPI_Line(const std::shared_ptr & theFeature, + const std::shared_ptr & theStartPoint, + const std::shared_ptr & theEndPoint); + /// Constructor with values + SKETCHAPI_EXPORT + SketchAPI_Line(const std::shared_ptr & theFeature, + const ModelHighAPI_Selection & theExternal); + /// Constructor with values + SKETCHAPI_EXPORT + SketchAPI_Line(const std::shared_ptr & theFeature, + const std::string & theExternalName); + /// Destructor + SKETCHAPI_EXPORT + virtual ~SketchAPI_Line(); + + INTERFACE_3(SketchPlugin_Line::ID(), + startPoint, SketchPlugin_Line::START_ID(), GeomDataAPI_Point2D, /** Start point */, + endPoint, SketchPlugin_Line::END_ID(), GeomDataAPI_Point2D, /** End point */, + external, SketchPlugin_Line::EXTERNAL_ID(), ModelAPI_AttributeSelection, /** External */ + ) + + /// Set by coordinates + SKETCHAPI_EXPORT + void setByCoordinates(double theX1, double theY1, double theX2, double theY2); + + /// Set by points + SKETCHAPI_EXPORT + void setByPoints(const std::shared_ptr & theStartPoint, + const std::shared_ptr & theEndPoint); + + /// Set by external + SKETCHAPI_EXPORT + void setByExternal(const ModelHighAPI_Selection & theExternal); + + /// Set by external name + SKETCHAPI_EXPORT + void setByExternalName(const std::string & theExternalName); + + /// Set start point + SKETCHAPI_EXPORT + void setStartPoint(double theX, double theY); + + /// Set start point + SKETCHAPI_EXPORT + void setStartPoint(const std::shared_ptr & thePoint); + + /// Set end point + SKETCHAPI_EXPORT + void setEndPoint(double theX, double theY); + + /// Set end point + SKETCHAPI_EXPORT + void setEndPoint(const std::shared_ptr & thePoint); +}; + +//! Pointer on Line object +typedef std::shared_ptr LinePtr; + +//-------------------------------------------------------------------------------------- +//-------------------------------------------------------------------------------------- +#endif /* SRC_SKETCHAPI_SKETCHAPI_LINE_H_ */ diff --git a/src/SketchAPI/SketchAPI_Sketch.cpp b/src/SketchAPI/SketchAPI_Sketch.cpp new file mode 100644 index 000000000..93d70ed93 --- /dev/null +++ b/src/SketchAPI/SketchAPI_Sketch.cpp @@ -0,0 +1,110 @@ +// Name : SketchAPI_Sketch.cpp +// Purpose: +// +// History: +// 07/06/16 - Sergey POKHODENKO - Creation of the file + +//-------------------------------------------------------------------------------------- +#include "SketchAPI_Sketch.h" +//-------------------------------------------------------------------------------------- +#include +#include +#include "SketchAPI_Line.h" +//-------------------------------------------------------------------------------------- +SketchAPI_Sketch::SketchAPI_Sketch( + const std::shared_ptr & theFeature) +: ModelHighAPI_Interface(theFeature) +{ + initialize(); +} + +SketchAPI_Sketch::SketchAPI_Sketch( + const std::shared_ptr & theFeature, + const std::shared_ptr & thePlane) +: ModelHighAPI_Interface(theFeature) +{ + if (initialize()) { + setPlane(thePlane); + } +} + +SketchAPI_Sketch::SketchAPI_Sketch( + const std::shared_ptr & theFeature, + const ModelHighAPI_Selection & theExternal) +: ModelHighAPI_Interface(theFeature) +{ + if (initialize()) { + setExternal(theExternal); + } +} + +SketchAPI_Sketch::~SketchAPI_Sketch() +{ + +} + +//-------------------------------------------------------------------------------------- +std::shared_ptr SketchAPI_Sketch::compositeFeature() const +{ + return std::dynamic_pointer_cast(feature()); +} + +//-------------------------------------------------------------------------------------- +void SketchAPI_Sketch::setPlane(const std::shared_ptr & thePlane) +{ + fillAttribute(thePlane->origin(), myorigin); + fillAttribute(thePlane->dirX(), mydirX); + fillAttribute(thePlane->normal(), mynormal); + + execute(); +} + +void SketchAPI_Sketch::setExternal(const ModelHighAPI_Selection & theExternal) +{ + fillAttribute(theExternal, myexternal); + + execute(); +} + +//-------------------------------------------------------------------------------------- +SketchPtr addSketch(const std::shared_ptr & thePart, + const std::shared_ptr & thePlane) +{ + // TODO(spo): check that thePart is not empty + std::shared_ptr aFeature = thePart->addFeature(SketchAPI_Sketch::ID()); + return SketchPtr(new SketchAPI_Sketch(aFeature, thePlane)); +} + +SketchPtr addSketch(const std::shared_ptr & thePart, + const ModelHighAPI_Selection & theExternal) +{ + // TODO(spo): check that thePart is not empty + std::shared_ptr aFeature = thePart->addFeature(SketchAPI_Sketch::ID()); + return SketchPtr(new SketchAPI_Sketch(aFeature, theExternal)); +} + +//-------------------------------------------------------------------------------------- +std::shared_ptr SketchAPI_Sketch::addLine(double theX1, double theY1, double theX2, double theY2) +{ + std::shared_ptr aFeature = compositeFeature()->addFeature(SketchPlugin_Line::ID()); + return LinePtr(new SketchAPI_Line(aFeature, theX1, theY1, theX2, theY2)); +} +std::shared_ptr SketchAPI_Sketch::addLine( + const std::shared_ptr & theStartPoint, + const std::shared_ptr & theEndPoint) +{ + std::shared_ptr aFeature = compositeFeature()->addFeature(SketchPlugin_Line::ID()); + return LinePtr(new SketchAPI_Line(aFeature, theStartPoint, theEndPoint)); +} +std::shared_ptr SketchAPI_Sketch::addLine(const ModelHighAPI_Selection & theExternal) +{ + std::shared_ptr aFeature = compositeFeature()->addFeature(SketchPlugin_Line::ID()); + return LinePtr(new SketchAPI_Line(aFeature, theExternal)); +} +std::shared_ptr SketchAPI_Sketch::addLine(const std::string & theExternalName) +{ + // TODO(spo): Add constraint SketchConstraintRigid like in PythonAPI. Is it necessary? + std::shared_ptr aFeature = compositeFeature()->addFeature(SketchPlugin_Line::ID()); + return LinePtr(new SketchAPI_Line(aFeature, theExternalName)); +} +//-------------------------------------------------------------------------------------- diff --git a/src/SketchAPI/SketchAPI_Sketch.h b/src/SketchAPI/SketchAPI_Sketch.h new file mode 100644 index 000000000..a85e8ef0d --- /dev/null +++ b/src/SketchAPI/SketchAPI_Sketch.h @@ -0,0 +1,103 @@ +// Name : SketchAPI_Sketch.h +// Purpose: +// +// History: +// 07/06/16 - Sergey POKHODENKO - Creation of the file + +#ifndef SRC_SKETCHAPI_SKETCHAPI_SKETCH_H_ +#define SRC_SKETCHAPI_SKETCHAPI_SKETCH_H_ + +//-------------------------------------------------------------------------------------- +#include "SketchAPI.h" + +#include +#include + +#include +#include +//-------------------------------------------------------------------------------------- +class ModelAPI_CompositeFeature; +class ModelHighAPI_Selection; +class SketchAPI_Line; +//-------------------------------------------------------------------------------------- +/**\class SketchAPI_Sketch + * \ingroup CPPHighAPI + * \brief Interface for Sketch feature + */ +class SketchAPI_Sketch : public ModelHighAPI_Interface +{ +public: + /// Constructor without values + SKETCHAPI_EXPORT + explicit SketchAPI_Sketch(const std::shared_ptr & theFeature); + /// Constructor with values + SKETCHAPI_EXPORT + SketchAPI_Sketch(const std::shared_ptr & theFeature, + const std::shared_ptr & thePlane); + /// Constructor with values + SKETCHAPI_EXPORT + SketchAPI_Sketch(const std::shared_ptr & theFeature, + const ModelHighAPI_Selection & theExternal); + /// Destructor + SKETCHAPI_EXPORT + virtual ~SketchAPI_Sketch(); + + INTERFACE_7(SketchPlugin_Sketch::ID(), + origin, SketchPlugin_Sketch::ORIGIN_ID(), GeomDataAPI_Point, /** Origin point */, + dirX, SketchPlugin_Sketch::DIRX_ID(), GeomDataAPI_Dir, /** Direction of X */, + normal, SketchPlugin_Sketch::NORM_ID(), GeomDataAPI_Dir, /** Normal */, + features, SketchPlugin_Sketch::FEATURES_ID(), ModelAPI_AttributeRefList, /** Features */, + external, SketchPlugin_SketchEntity::EXTERNAL_ID(), ModelAPI_AttributeSelection, /** External */, + solverError, SketchPlugin_Sketch::SOLVER_ERROR(), ModelAPI_AttributeString, /** Solver error */, + solverDOF, SketchPlugin_Sketch::SOLVER_DOF(), ModelAPI_AttributeString, /** Solver DOF */ + ) + + /// Set plane + SKETCHAPI_EXPORT + void setPlane(const std::shared_ptr & thePlane); + + /// Set external + SKETCHAPI_EXPORT + void setExternal(const ModelHighAPI_Selection & theExternal); + + /// Add line + SKETCHAPI_EXPORT + std::shared_ptr addLine( + double theX1, double theY1, double theX2, double theY2); + /// Add line + SKETCHAPI_EXPORT + std::shared_ptr addLine( + const std::shared_ptr & theStartPoint, + const std::shared_ptr & theEndPoint); + /// Add line + SKETCHAPI_EXPORT + std::shared_ptr addLine(const ModelHighAPI_Selection & theExternal); + /// Add line + SKETCHAPI_EXPORT + std::shared_ptr addLine(const std::string & theExternalName); + +protected: + std::shared_ptr compositeFeature() const; + +}; + +//! Pointer on Sketch object +typedef std::shared_ptr SketchPtr; + +/**\ingroup CPPHighAPI + * \brief Create Sketch feature + */ +SKETCHAPI_EXPORT +SketchPtr addSketch(const std::shared_ptr & thePart, + const std::shared_ptr & thePlane); + +/**\ingroup CPPHighAPI + * \brief Create Sketch feature + */ +SKETCHAPI_EXPORT +SketchPtr addSketch(const std::shared_ptr & thePart, + const ModelHighAPI_Selection & theExternal); + +//-------------------------------------------------------------------------------------- +//-------------------------------------------------------------------------------------- +#endif /* SRC_SKETCHAPI_SKETCHAPI_SKETCH_H_ */ diff --git a/src/SketchAPI/SketchAPI_SketchEntity.cpp b/src/SketchAPI/SketchAPI_SketchEntity.cpp new file mode 100644 index 000000000..a017576ab --- /dev/null +++ b/src/SketchAPI/SketchAPI_SketchEntity.cpp @@ -0,0 +1,45 @@ +// Name : SketchAPI_SketchEntity.cpp +// Purpose: +// +// History: +// 07/06/16 - Sergey POKHODENKO - Creation of the file + +//-------------------------------------------------------------------------------------- +#include "SketchAPI_SketchEntity.h" +//-------------------------------------------------------------------------------------- +#include +//-------------------------------------------------------------------------------------- +SketchAPI_SketchEntity::SketchAPI_SketchEntity( + const std::shared_ptr & theFeature) +: ModelHighAPI_Interface(theFeature) +{ + initialize(); +} + +SketchAPI_SketchEntity::~SketchAPI_SketchEntity() +{ + +} + +//-------------------------------------------------------------------------------------- +bool SketchAPI_SketchEntity::initialize() +{ + SET_ATTRIBUTE(Auxiliary, ModelAPI_AttributeBoolean, SketchPlugin_SketchEntity::AUXILIARY_ID()) + + return true; +} + +//-------------------------------------------------------------------------------------- +std::shared_ptr SketchAPI_SketchEntity::auxiliary() const +{ + return myAuxiliary; +} + +void SketchAPI_SketchEntity::setAuxiliary(bool theAuxiliary) +{ + fillAttribute(theAuxiliary, myAuxiliary); + + execute(); +} + +//-------------------------------------------------------------------------------------- diff --git a/src/SketchAPI/SketchAPI_SketchEntity.h b/src/SketchAPI/SketchAPI_SketchEntity.h new file mode 100644 index 000000000..5ac166aa3 --- /dev/null +++ b/src/SketchAPI/SketchAPI_SketchEntity.h @@ -0,0 +1,51 @@ +// Name : SketchAPI_SketchEntity.h +// Purpose: +// +// History: +// 07/06/16 - Sergey POKHODENKO - Creation of the file + +#ifndef SRC_SKETCHAPI_SKETCHAPI_SKETCHENTITY_H_ +#define SRC_SKETCHAPI_SKETCHAPI_SKETCHENTITY_H_ + +//-------------------------------------------------------------------------------------- +#include "SketchAPI.h" + +#include + +#include +#include +//-------------------------------------------------------------------------------------- +/**\class SketchAPI_SketchEntity + * \ingroup CPPHighAPI + * \brief Base class for Sketch feature interfaces + */ +class SketchAPI_SketchEntity : public ModelHighAPI_Interface +{ +public: + /// Constructor without values + SKETCHAPI_EXPORT + explicit SketchAPI_SketchEntity(const std::shared_ptr & theFeature); + /// Destructor + SKETCHAPI_EXPORT + virtual ~SketchAPI_SketchEntity(); + + /// Auxiliary + SKETCHAPI_EXPORT + std::shared_ptr auxiliary() const; + + /// Set auxiliary + SKETCHAPI_EXPORT + void setAuxiliary(bool theAuxiliary); + +protected: + std::shared_ptr myAuxiliary; + + bool initialize(); +}; + +//! Pointer on SketchEntity object +typedef std::shared_ptr SketchEntityPtr; + +//-------------------------------------------------------------------------------------- +//-------------------------------------------------------------------------------------- +#endif /* SRC_SKETCHAPI_SKETCHAPI_SKETCHENTITY_H_ */ diff --git a/src/SketchAPI/SketchAPI_swig.h b/src/SketchAPI/SketchAPI_swig.h new file mode 100644 index 000000000..67b27257f --- /dev/null +++ b/src/SketchAPI/SketchAPI_swig.h @@ -0,0 +1,17 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: SketchAPI_swig.h +// Created: 07/06/16 +// Author: Sergey POKHODENKO + +#ifndef SRC_SKETCHAPI_SKETCHAPI_SWIG_H_ +#define SRC_SKETCHAPI_SKETCHAPI_SWIG_H_ + + #include + + #include "SketchAPI.h" + #include "SketchAPI_Line.h" + #include "SketchAPI_Sketch.h" + #include "SketchAPI_SketchEntity.h" + +#endif /* SRC_SKETCHAPI_SKETCHAPI_SWIG_H_ */ diff --git a/src/SketchAPI/Test/TestSketch.py b/src/SketchAPI/Test/TestSketch.py new file mode 100644 index 000000000..5f1576c77 --- /dev/null +++ b/src/SketchAPI/Test/TestSketch.py @@ -0,0 +1,26 @@ +import unittest + +import ModelAPI +import ExchangeAPI + +class PointTestCase(unittest.TestCase): + + def setUp(self): + self.session = ModelAPI.ModelAPI_Session.get() + self.doc = self.session.moduleDocument() + + def tearDown(self): + self.session.closeAll() + + def test_addImport(self): + self.session.startOperation() + self.feature = ExchangeAPI.addImport(self.doc, "file_path") + self.session.finishOperation() + + def test_addExport(self): + self.session.startOperation() + self.feature = ExchangeAPI.exportToFile(self.doc, "file_path", "file_format", []) + self.session.finishOperation() + +if __name__ == "__main__": + unittest.main() -- 2.39.2