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>
15 #include <ModelAPI_Events.h>
19 //--------------------------------------------------------------------------------------
20 std::shared_ptr<ModelAPI_Document> moduleDocument()
22 return ModelAPI_Session::get()->moduleDocument();
25 //--------------------------------------------------------------------------------------
26 std::shared_ptr<ModelAPI_Document> activeDocument()
28 return ModelAPI_Session::get()->activeDocument();
31 //--------------------------------------------------------------------------------------
32 std::shared_ptr<GeomAPI_Ax3> defaultPlane( const std::string& theName )
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));
47 return std::shared_ptr<GeomAPI_Ax3>(new GeomAPI_Ax3(o, x, n));
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)
54 static const double aTol = 1.e-10;
56 if (fabs(theOrigin->x()) > aTol || fabs(theOrigin->y()) > aTol || fabs(theOrigin->z()) > aTol)
60 if (fabs(theNormal->x()) < aTol &&
61 fabs(theDirX->x() - 1.0) < aTol && fabs(theDirX->y()) < aTol && fabs(theDirX->z()) < aTol) {
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");
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");
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));
83 //--------------------------------------------------------------------------------------
86 ModelAPI_Session::get()->startOperation();
91 ModelAPI_Session::get()->finishOperation();
92 // to update data tree in the end of dumped script execution
93 ModelAPI_EventCreator::get()->sendReordered(FeaturePtr());
97 auto aSession = ModelAPI_Session::get();
98 aSession->finishOperation();
99 aSession->startOperation();
102 //--------------------------------------------------------------------------------------
105 ModelAPI_Session::get()->undo();
109 ModelAPI_Session::get()->redo();
112 //--------------------------------------------------------------------------------------
115 ModelAPI_Session::get()->closeAll();
118 //--------------------------------------------------------------------------------------