Salome HOME
Dump Python in the High Level Parameterized Geometry API (issue #1648)
[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
14 #include <cmath>
15
16 //--------------------------------------------------------------------------------------
17 std::shared_ptr<ModelAPI_Document> moduleDocument()
18 {
19   return ModelAPI_Session::get()->moduleDocument();
20 }
21
22 //--------------------------------------------------------------------------------------
23 std::shared_ptr<ModelAPI_Document> activeDocument()
24 {
25   return ModelAPI_Session::get()->activeDocument();
26 }
27
28 //--------------------------------------------------------------------------------------
29 std::shared_ptr<GeomAPI_Ax3> defaultPlane( const std::string& theName )
30 {
31   std::shared_ptr<GeomAPI_Pnt> o(new GeomAPI_Pnt(0, 0, 0));
32   std::shared_ptr<GeomAPI_Dir> n, x;
33   if (theName == "XOY") {
34       n.reset(new GeomAPI_Dir(0, 0, 1));
35       x.reset(new GeomAPI_Dir(1, 0, 0));
36   } else if (theName == "XOZ") {
37       n.reset(new GeomAPI_Dir(0, -1, 0));
38       x.reset(new GeomAPI_Dir(1, 0, 0));
39   } else if (theName == "YOZ") {
40       n.reset(new GeomAPI_Dir(1, 0, 0));
41       x.reset(new GeomAPI_Dir(0, 1, 0));
42   }
43
44   return std::shared_ptr<GeomAPI_Ax3>(new GeomAPI_Ax3(o, x, n));
45 }
46
47 std::string defaultPlane(const std::shared_ptr<GeomAPI_Pnt>& theOrigin,
48                          const std::shared_ptr<GeomAPI_Dir>& theNormal,
49                          const std::shared_ptr<GeomAPI_Dir>& theDirX)
50 {
51   static const double aTol = 1.e-10;
52
53   if (fabs(theOrigin->x()) > aTol || fabs(theOrigin->y()) > aTol || fabs(theOrigin->z()) > aTol)
54     return std::string();
55
56   // XOY or XOZ
57   if (fabs(theNormal->x()) < aTol && 
58       fabs(theDirX->x() - 1.0) < aTol && fabs(theDirX->y()) < aTol && fabs(theDirX->z()) < aTol) {
59     // XOY
60     if (fabs(theNormal->y()) < aTol && fabs(theNormal->z() - 1.0) < aTol)
61       return std::string("XOY");
62     else if (fabs(theNormal->y() + 1.0) < aTol && fabs(theNormal->z()) < aTol)
63       return std::string("XOZ");
64   }
65   // YOZ
66   else if (fabs(theNormal->x() - 1.0) < aTol && fabs(theNormal->y()) < aTol && fabs(theNormal->z()) < aTol &&
67            fabs(theDirX->x()) < aTol && fabs(theDirX->y() - 1.0) < aTol && fabs(theDirX->z()) < aTol)
68     return std::string("YOZ");
69
70   return std::string();
71 }
72
73 //--------------------------------------------------------------------------------------
74 void begin()
75 {
76   ModelAPI_Session::get()->startOperation();
77 }
78 void end()
79 {
80   ModelAPI_Session::get()->finishOperation();
81 }
82 void apply()
83 {
84   auto aSession = ModelAPI_Session::get();
85   aSession->finishOperation();
86   aSession->startOperation();
87 }
88
89 //--------------------------------------------------------------------------------------
90 void undo()
91 {
92   ModelAPI_Session::get()->undo();
93 }
94 void redo()
95 {
96   ModelAPI_Session::get()->redo();
97 }
98
99 //--------------------------------------------------------------------------------------
100 void reset()
101 {
102   ModelAPI_Session::get()->closeAll();
103 }
104
105 //--------------------------------------------------------------------------------------