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