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>
13 #include <ModelAPI_Document.h>
14 #include <ModelAPI_ResultConstruction.h>
18 //--------------------------------------------------------------------------------------
19 std::shared_ptr<ModelAPI_Document> moduleDocument()
21 return ModelAPI_Session::get()->moduleDocument();
24 //--------------------------------------------------------------------------------------
25 std::shared_ptr<ModelAPI_Document> activeDocument()
27 return ModelAPI_Session::get()->activeDocument();
30 //--------------------------------------------------------------------------------------
31 std::shared_ptr<GeomAPI_Ax3> defaultPlane( const std::string& theName )
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));
46 return std::shared_ptr<GeomAPI_Ax3>(new GeomAPI_Ax3(o, x, n));
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)
53 static const double aTol = 1.e-10;
55 if (fabs(theOrigin->x()) > aTol || fabs(theOrigin->y()) > aTol || fabs(theOrigin->z()) > aTol)
59 if (fabs(theNormal->x()) < aTol &&
60 fabs(theDirX->x() - 1.0) < aTol && fabs(theDirX->y()) < aTol && fabs(theDirX->z()) < aTol) {
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");
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");
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));
82 //--------------------------------------------------------------------------------------
85 ModelAPI_Session::get()->startOperation();
89 ModelAPI_Session::get()->finishOperation();
93 auto aSession = ModelAPI_Session::get();
94 aSession->finishOperation();
95 aSession->startOperation();
98 //--------------------------------------------------------------------------------------
101 ModelAPI_Session::get()->undo();
105 ModelAPI_Session::get()->redo();
108 //--------------------------------------------------------------------------------------
111 ModelAPI_Session::get()->closeAll();
114 //--------------------------------------------------------------------------------------