1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2 // Name : ModelHighAPI_Services.cpp
6 // 17/06/16 - Sergey POKHODENKO - Creation of the file
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>
20 //--------------------------------------------------------------------------------------
21 std::shared_ptr<ModelAPI_Document> moduleDocument()
23 return ModelAPI_Session::get()->moduleDocument();
26 //--------------------------------------------------------------------------------------
27 std::shared_ptr<ModelAPI_Document> activeDocument()
29 return ModelAPI_Session::get()->activeDocument();
32 //--------------------------------------------------------------------------------------
33 std::shared_ptr<GeomAPI_Ax3> defaultPlane( const std::string& theName )
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));
48 return std::shared_ptr<GeomAPI_Ax3>(new GeomAPI_Ax3(o, x, n));
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)
55 static const double aTol = 1.e-10;
57 if (fabs(theOrigin->x()) > aTol || fabs(theOrigin->y()) > aTol || fabs(theOrigin->z()) > aTol)
61 if (fabs(theNormal->x()) < aTol &&
62 fabs(theDirX->x() - 1.0) < aTol && fabs(theDirX->y()) < aTol && fabs(theDirX->z()) < aTol) {
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");
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");
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));
86 //--------------------------------------------------------------------------------------
89 ModelAPI_Session::get()->startOperation();
94 ModelAPI_Session::get()->finishOperation();
95 // to update data tree in the end of dumped script execution
96 ModelAPI_EventCreator::get()->sendReordered(FeaturePtr());
100 auto aSession = ModelAPI_Session::get();
101 aSession->finishOperation();
102 aSession->startOperation();
105 //--------------------------------------------------------------------------------------
108 ModelAPI_Session::get()->undo();
112 ModelAPI_Session::get()->redo();
115 //--------------------------------------------------------------------------------------
118 ModelAPI_Session::get()->closeAll();
121 //--------------------------------------------------------------------------------------