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