1 // Name : ModelHighAPI_Services.cpp
5 // 17/06/16 - Sergey POKHODENKO - Creation of the file
7 //--------------------------------------------------------------------------------------
8 #include "ModelHighAPI_Services.h"
9 //--------------------------------------------------------------------------------------
10 #include <GeomAPI_Ax3.h>
11 #include <GeomAPI_Pnt.h>
12 #include <ModelAPI_Session.h>
16 //--------------------------------------------------------------------------------------
17 std::shared_ptr<ModelAPI_Document> moduleDocument()
19 return ModelAPI_Session::get()->moduleDocument();
22 //--------------------------------------------------------------------------------------
23 std::shared_ptr<ModelAPI_Document> activeDocument()
25 return ModelAPI_Session::get()->activeDocument();
28 //--------------------------------------------------------------------------------------
29 std::shared_ptr<GeomAPI_Ax3> defaultPlane( const std::string& theName )
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));
44 return std::shared_ptr<GeomAPI_Ax3>(new GeomAPI_Ax3(o, x, n));
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)
51 static const double aTol = 1.e-10;
53 if (fabs(theOrigin->x()) > aTol || fabs(theOrigin->y()) > aTol || fabs(theOrigin->z()) > aTol)
57 if (fabs(theNormal->x()) < aTol &&
58 fabs(theDirX->x() - 1.0) < aTol && fabs(theDirX->y()) < aTol && fabs(theDirX->z()) < aTol) {
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");
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");
73 //--------------------------------------------------------------------------------------
76 ModelAPI_Session::get()->startOperation();
80 ModelAPI_Session::get()->finishOperation();
84 auto aSession = ModelAPI_Session::get();
85 aSession->finishOperation();
86 aSession->startOperation();
89 //--------------------------------------------------------------------------------------
92 ModelAPI_Session::get()->undo();
96 ModelAPI_Session::get()->redo();
99 //--------------------------------------------------------------------------------------
102 ModelAPI_Session::get()->closeAll();
105 //--------------------------------------------------------------------------------------