1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #include "ModelHighAPI_Services.h"
22 //--------------------------------------------------------------------------------------
23 #include <GeomAPI_Ax3.h>
24 #include <GeomAPI_Pnt.h>
25 #include <ModelAPI_Session.h>
26 #include <ModelAPI_Document.h>
27 #include <ModelAPI_ResultConstruction.h>
28 #include <ModelAPI_Events.h>
32 //--------------------------------------------------------------------------------------
33 std::shared_ptr<ModelAPI_Document> moduleDocument()
35 return ModelAPI_Session::get()->moduleDocument();
38 //--------------------------------------------------------------------------------------
39 std::shared_ptr<ModelAPI_Document> activeDocument()
41 return ModelAPI_Session::get()->activeDocument();
44 //--------------------------------------------------------------------------------------
45 std::shared_ptr<GeomAPI_Ax3> defaultPlane( const std::string& theName )
47 std::shared_ptr<GeomAPI_Pnt> o(new GeomAPI_Pnt(0, 0, 0));
48 std::shared_ptr<GeomAPI_Dir> n, x;
49 if (theName == "XOY") {
50 n.reset(new GeomAPI_Dir(0, 0, 1));
51 x.reset(new GeomAPI_Dir(1, 0, 0));
52 } else if (theName == "XOZ") {
53 n.reset(new GeomAPI_Dir(0, -1, 0));
54 x.reset(new GeomAPI_Dir(1, 0, 0));
55 } else if (theName == "YOZ") {
56 n.reset(new GeomAPI_Dir(1, 0, 0));
57 x.reset(new GeomAPI_Dir(0, 1, 0));
60 return std::shared_ptr<GeomAPI_Ax3>(new GeomAPI_Ax3(o, x, n));
63 std::string defaultPlane(const std::shared_ptr<GeomAPI_Pnt>& theOrigin,
64 const std::shared_ptr<GeomAPI_Dir>& theNormal,
65 const std::shared_ptr<GeomAPI_Dir>& theDirX)
67 static const double aTol = 1.e-10;
69 if (fabs(theOrigin->x()) > aTol || fabs(theOrigin->y()) > aTol || fabs(theOrigin->z()) > aTol)
73 if (fabs(theNormal->x()) < aTol &&
74 fabs(theDirX->x() - 1.0) < aTol && fabs(theDirX->y()) < aTol && fabs(theDirX->z()) < aTol) {
76 if (fabs(theNormal->y()) < aTol && fabs(theNormal->z() - 1.0) < aTol)
77 return std::string("XOY");
78 else if (fabs(theNormal->y() + 1.0) < aTol && fabs(theNormal->z()) < aTol)
79 return std::string("XOZ");
82 else if (fabs(theNormal->x() - 1.0) < aTol &&
83 fabs(theNormal->y()) < aTol && fabs(theNormal->z()) < aTol &&
84 fabs(theDirX->x()) < aTol && fabs(theDirX->y() - 1.0) < aTol &&
85 fabs(theDirX->z()) < aTol)
86 return std::string("YOZ");
91 std::shared_ptr<ModelAPI_Result> standardPlane(const std::string & theName){
92 DocumentPtr aPartSet = ModelAPI_Session::get()->moduleDocument();
93 // searching for the construction element
94 return std::dynamic_pointer_cast<ModelAPI_Result>(
95 aPartSet->objectByName(ModelAPI_ResultConstruction::group(), theName));
98 //--------------------------------------------------------------------------------------
101 ModelAPI_Session::get()->startOperation();
106 ModelAPI_Session::get()->finishOperation();
107 // to update data tree in the end of dumped script execution
108 ModelAPI_EventCreator::get()->sendReordered(FeaturePtr());
112 auto aSession = ModelAPI_Session::get();
113 aSession->finishOperation();
114 aSession->startOperation();
117 void updateFeatures()
119 Events_Loop* aLoop = Events_Loop::loop();
120 aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
121 aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
124 //--------------------------------------------------------------------------------------
127 ModelAPI_Session::get()->undo();
131 ModelAPI_Session::get()->redo();
134 //--------------------------------------------------------------------------------------
137 ModelAPI_Session::get()->closeAll();
140 //--------------------------------------------------------------------------------------