]> SALOME platform Git repositories - modules/shaper.git/blob - src/ModelHighAPI/ModelHighAPI_Services.cpp
Salome HOME
Fix unit tests for ParametersPlugin
[modules/shaper.git] / src / ModelHighAPI / ModelHighAPI_Services.cpp
1 // Name   : ModelHighAPI_Services.cpp
2 // Purpose: 
3 //
4 // History:
5 // 17/06/16 - Sergey POKHODENKO - Creation of the file
6
7 //--------------------------------------------------------------------------------------
8 #include "ModelHighAPI_Services.h"
9 //--------------------------------------------------------------------------------------
10 #include <GeomAPI_Ax3.h>
11 #include <GeomAPI_Pnt.h>
12 #include <ModelAPI_Session.h>
13 #include <ModelAPI_Document.h>
14 #include <ModelAPI_ResultConstruction.h>
15
16 #include <cmath>
17
18 //--------------------------------------------------------------------------------------
19 std::shared_ptr<ModelAPI_Document> moduleDocument()
20 {
21   return ModelAPI_Session::get()->moduleDocument();
22 }
23
24 //--------------------------------------------------------------------------------------
25 std::shared_ptr<ModelAPI_Document> activeDocument()
26 {
27   return ModelAPI_Session::get()->activeDocument();
28 }
29
30 //--------------------------------------------------------------------------------------
31 std::shared_ptr<GeomAPI_Ax3> defaultPlane( const std::string& theName )
32 {
33   std::shared_ptr<GeomAPI_Pnt> o(new GeomAPI_Pnt(0, 0, 0));
34   std::shared_ptr<GeomAPI_Dir> n, x;
35   if (theName == "XOY") {
36       n.reset(new GeomAPI_Dir(0, 0, 1));
37       x.reset(new GeomAPI_Dir(1, 0, 0));
38   } else if (theName == "XOZ") {
39       n.reset(new GeomAPI_Dir(0, -1, 0));
40       x.reset(new GeomAPI_Dir(1, 0, 0));
41   } else if (theName == "YOZ") {
42       n.reset(new GeomAPI_Dir(1, 0, 0));
43       x.reset(new GeomAPI_Dir(0, 1, 0));
44   }
45
46   return std::shared_ptr<GeomAPI_Ax3>(new GeomAPI_Ax3(o, x, n));
47 }
48
49 std::string defaultPlane(const std::shared_ptr<GeomAPI_Pnt>& theOrigin,
50                          const std::shared_ptr<GeomAPI_Dir>& theNormal,
51                          const std::shared_ptr<GeomAPI_Dir>& theDirX)
52 {
53   static const double aTol = 1.e-10;
54
55   if (fabs(theOrigin->x()) > aTol || fabs(theOrigin->y()) > aTol || fabs(theOrigin->z()) > aTol)
56     return std::string();
57
58   // XOY or XOZ
59   if (fabs(theNormal->x()) < aTol && 
60       fabs(theDirX->x() - 1.0) < aTol && fabs(theDirX->y()) < aTol && fabs(theDirX->z()) < aTol) {
61     // XOY
62     if (fabs(theNormal->y()) < aTol && fabs(theNormal->z() - 1.0) < aTol)
63       return std::string("XOY");
64     else if (fabs(theNormal->y() + 1.0) < aTol && fabs(theNormal->z()) < aTol)
65       return std::string("XOZ");
66   }
67   // YOZ
68   else if (fabs(theNormal->x() - 1.0) < aTol && fabs(theNormal->y()) < aTol && fabs(theNormal->z()) < aTol &&
69            fabs(theDirX->x()) < aTol && fabs(theDirX->y() - 1.0) < aTol && fabs(theDirX->z()) < aTol)
70     return std::string("YOZ");
71
72   return std::string();
73 }
74
75 std::shared_ptr<ModelAPI_Result> standardPlane(const std::string & theName){
76   DocumentPtr aPartSet = ModelAPI_Session::get()->moduleDocument();
77   // searching for the construction element
78   return std::dynamic_pointer_cast<ModelAPI_Result>(
79     aPartSet->objectByName(ModelAPI_ResultConstruction::group(), theName));
80 }
81
82 //--------------------------------------------------------------------------------------
83 void begin()
84 {
85   ModelAPI_Session::get()->startOperation();
86 }
87 void end()
88 {
89   ModelAPI_Session::get()->finishOperation();
90 }
91 void apply()
92 {
93   auto aSession = ModelAPI_Session::get();
94   aSession->finishOperation();
95   aSession->startOperation();
96 }
97
98 //--------------------------------------------------------------------------------------
99 void undo()
100 {
101   ModelAPI_Session::get()->undo();
102 }
103 void redo()
104 {
105   ModelAPI_Session::get()->redo();
106 }
107
108 //--------------------------------------------------------------------------------------
109 void reset()
110 {
111   ModelAPI_Session::get()->closeAll();
112 }
113
114 //--------------------------------------------------------------------------------------