From: spo Date: Fri, 17 Jun 2016 16:34:34 +0000 (+0300) Subject: Move functions from Python model.services to C++ ModelHighAPI_Services X-Git-Tag: V_2.4.0~91^2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=refs%2Fheads%2FCPPHighAPI;p=modules%2Fshaper.git Move functions from Python model.services to C++ ModelHighAPI_Services --- diff --git a/src/ModelHighAPI/CMakeLists.txt b/src/ModelHighAPI/CMakeLists.txt index 7b450e5c5..0e47ce3bd 100644 --- a/src/ModelHighAPI/CMakeLists.txt +++ b/src/ModelHighAPI/CMakeLists.txt @@ -10,6 +10,7 @@ SET(PROJECT_HEADERS ModelHighAPI_Macro.h ModelHighAPI_RefAttr.h ModelHighAPI_Selection.h + ModelHighAPI_Services.h ModelHighAPI_Tools.h ) @@ -19,6 +20,7 @@ SET(PROJECT_SOURCES ModelHighAPI_Interface.cpp ModelHighAPI_RefAttr.cpp ModelHighAPI_Selection.cpp + ModelHighAPI_Services.cpp ModelHighAPI_Tools.cpp ) diff --git a/src/ModelHighAPI/ModelHighAPI.i b/src/ModelHighAPI/ModelHighAPI.i index 7ebba1a57..bafdb363c 100644 --- a/src/ModelHighAPI/ModelHighAPI.i +++ b/src/ModelHighAPI/ModelHighAPI.i @@ -123,5 +123,6 @@ %include "ModelHighAPI_Interface.h" %include "ModelHighAPI_RefAttr.h" %include "ModelHighAPI_Selection.h" +%include "ModelHighAPI_Services.h" %include "ModelHighAPI_Macro.h" %include "ModelHighAPI_Tools.h" diff --git a/src/ModelHighAPI/ModelHighAPI_Services.cpp b/src/ModelHighAPI/ModelHighAPI_Services.cpp new file mode 100644 index 000000000..09be73726 --- /dev/null +++ b/src/ModelHighAPI/ModelHighAPI_Services.cpp @@ -0,0 +1,77 @@ +// Name : ModelHighAPI_Services.cpp +// Purpose: +// +// History: +// 17/06/16 - Sergey POKHODENKO - Creation of the file + +//-------------------------------------------------------------------------------------- +#include "ModelHighAPI_Services.h" +//-------------------------------------------------------------------------------------- +#include +#include +#include + +//-------------------------------------------------------------------------------------- +std::shared_ptr moduleDocument() +{ + return ModelAPI_Session::get()->moduleDocument(); +} + +//-------------------------------------------------------------------------------------- +std::shared_ptr activeDocument() +{ + return ModelAPI_Session::get()->activeDocument(); +} + +//-------------------------------------------------------------------------------------- +std::shared_ptr defaultPlane( const std::string& theName ) +{ + std::shared_ptr o(new GeomAPI_Pnt(0, 0, 0)); + std::shared_ptr n, x; + if (theName == "XOY") { + n.reset(new GeomAPI_Dir(0, 0, 1)); + x.reset(new GeomAPI_Dir(1, 0, 0)); + } else if (theName == "XOZ") { + n.reset(new GeomAPI_Dir(0, -1, 0)); + x.reset(new GeomAPI_Dir(1, 0, 0)); + } else if (theName == "YOZ") { + n.reset(new GeomAPI_Dir(1, 0, 0)); + x.reset(new GeomAPI_Dir(0, 1, 0)); + } + + return std::shared_ptr(new GeomAPI_Ax3(o, x, n)); +} + +//-------------------------------------------------------------------------------------- +void begin() +{ + ModelAPI_Session::get()->startOperation(); +} +void end() +{ + ModelAPI_Session::get()->finishOperation(); +} +void apply() +{ + auto aSession = ModelAPI_Session::get(); + aSession->finishOperation(); + aSession->startOperation(); +} + +//-------------------------------------------------------------------------------------- +void undo() +{ + ModelAPI_Session::get()->undo(); +} +void redo() +{ + ModelAPI_Session::get()->redo(); +} + +//-------------------------------------------------------------------------------------- +void reset() +{ + ModelAPI_Session::get()->closeAll(); +} + +//-------------------------------------------------------------------------------------- diff --git a/src/ModelHighAPI/ModelHighAPI_Services.h b/src/ModelHighAPI/ModelHighAPI_Services.h new file mode 100644 index 000000000..4d0578382 --- /dev/null +++ b/src/ModelHighAPI/ModelHighAPI_Services.h @@ -0,0 +1,75 @@ +// Name : ModelHighAPI_Services.h +// Purpose: +// +// History: +// 17/06/16 - Sergey POKHODENKO - Creation of the file + +#ifndef SRC_MODELHIGHAPI_MODELHIGHAPI_SERVICES_H_ +#define SRC_MODELHIGHAPI_MODELHIGHAPI_SERVICES_H_ + +//-------------------------------------------------------------------------------------- +#include "ModelHighAPI.h" + +#include +#include +//-------------------------------------------------------------------------------------- +class GeomAPI_Ax3; +class ModelAPI_Document; +//-------------------------------------------------------------------------------------- +/// Return the main document (the Partset) created or open from the Modeler. +MODELHIGHAPI_EXPORT +std::shared_ptr moduleDocument(); + +/** Return the active document. + * + * This document can be either the main application document (i.e. the Partset) or one of documents + * referred to by the main document (a Part). + */ +MODELHIGHAPI_EXPORT +std::shared_ptr activeDocument(); + +/** Return one of the three planes defined by the global coordinate system. + * + * These planes are respectively referred to by name "XOY" (Z=0), "XOZ" (Y=0) or "YOZ" (X=0). + */ +MODELHIGHAPI_EXPORT +std::shared_ptr defaultPlane(const std::string & theName); + +/** Start a data structure transaction. + * + * Make a control point for being able to discard or undo + * all operations done during this transaction. + */ +MODELHIGHAPI_EXPORT +void begin(); + +/** Commit the data structure transaction. + * + * Make all operations done since the last control point undo-able. + */ +MODELHIGHAPI_EXPORT +void end(); + +/** Commit the data structure transaction and start the new one. + * + * Make all operations done since the last control point undo-able + * and continue with the new transaction. + */ +MODELHIGHAPI_EXPORT +void apply(); + +/// Roll-back the data structure to the previous control point. +MODELHIGHAPI_EXPORT +void undo(); + +/// Restore the data structure rolled-back by the last undo. +MODELHIGHAPI_EXPORT +void redo(); + +/// Reset the data structure to initial state. +MODELHIGHAPI_EXPORT +void reset(); + +//-------------------------------------------------------------------------------------- +//-------------------------------------------------------------------------------------- +#endif /* SRC_MODELHIGHAPI_MODELHIGHAPI_SERVICES_H_ */ diff --git a/src/ModelHighAPI/ModelHighAPI_swig.h b/src/ModelHighAPI/ModelHighAPI_swig.h index 46780acfd..2205a8796 100644 --- a/src/ModelHighAPI/ModelHighAPI_swig.h +++ b/src/ModelHighAPI/ModelHighAPI_swig.h @@ -18,6 +18,7 @@ #include "ModelHighAPI_Macro.h" #include "ModelHighAPI_RefAttr.h" #include "ModelHighAPI_Selection.h" + #include "ModelHighAPI_Services.h" #include "ModelHighAPI_Tools.h" #endif /* SRC_MODELHIGHAPI_MODELHIGHAPI_SWIG_H_ */ diff --git a/src/PythonAPI/model/services.py b/src/PythonAPI/model/services.py deleted file mode 100644 index e328621ea..000000000 --- a/src/PythonAPI/model/services.py +++ /dev/null @@ -1,86 +0,0 @@ -"""General purpose Interface -Author: Daniel Brunier-Coulin -Copyright (C) 2014-20xx CEA/DEN, EDF R&D -""" - -import ModelAPI -import GeomAPI - -def moduleDocument (): - """Return the main document (the Partset) created or open from the Modeler. - - This document is unique in the application session. - """ - return ModelAPI.ModelAPI_Session.get().moduleDocument() - - -def activeDocument (): - """Return the active document. - - This document can be either the main application document (i.e. the Partset) or one of documents - referred to by the main document (a Part). - """ - return ModelAPI.ModelAPI_Session.get().activeDocument() - - -def defaultPlane (name): - """Return one of the three planes defined by the global coordinate system. - - These planes are respectively referred to by name "XOY" (Z=0), "XOZ" (Y=0) or "YOZ" (X=0). - """ - # Temporary implementation before the availability of default planes. - o = GeomAPI.GeomAPI_Pnt(0, 0, 0) - if name == "XOY": - n = GeomAPI.GeomAPI_Dir(0, 0, 1) - x = GeomAPI.GeomAPI_Dir(1, 0, 0) - elif name == "XOZ": - n = GeomAPI.GeomAPI_Dir(0, -1, 0) - x = GeomAPI.GeomAPI_Dir(1, 0, 0) - elif name == "YOZ": - n = GeomAPI.GeomAPI_Dir(1, 0, 0) - x = GeomAPI.GeomAPI_Dir(0, 1, 0) - - return GeomAPI.GeomAPI_Ax3(o, x, n) - - -def begin (): - """Start a data structure transaction. - - Make a control point for being able to discard or undo - all operations done during this transaction. - """ - ModelAPI.ModelAPI_Session.get().startOperation() - - -def end (): - """Commit the data structure transaction. - - Make all operations done since the last control point undo-able. - """ - ModelAPI.ModelAPI_Session.get().finishOperation() - - -def do (): - """Commit the data structure transaction and start the new one. - - Make all operations done since the last control point undo-able - and continue with the new transaction. - """ - session = ModelAPI.ModelAPI_Session.get() - session.finishOperation() - session.startOperation() - - -def undo (): - """Roll-back the data structure to the previous control point.""" - ModelAPI.ModelAPI_Session.get().undo() - - -def redo (): - """Restore the data structure rolled-back by the last undo.""" - ModelAPI.ModelAPI_Session.get().redo() - - -def reset (): - """Reset the data structure to initial state.""" - ModelAPI.ModelAPI_Session.get().closeAll() diff --git a/src/PythonAPI/model/services/__init__.py b/src/PythonAPI/model/services/__init__.py new file mode 100644 index 000000000..e33077b31 --- /dev/null +++ b/src/PythonAPI/model/services/__init__.py @@ -0,0 +1,9 @@ +"""Package for services for the Parametric Geometry API of the Modeler. +""" + +from ModelHighAPI import moduleDocument, activeDocument +from ModelHighAPI import defaultPlane +from ModelHighAPI import begin, end +from ModelHighAPI import apply as do +from ModelHighAPI import undo, redo +from ModelHighAPI import reset \ No newline at end of file