Salome HOME
Provide view transformation signal in Salome viewer
[modules/shaper.git] / src / ModelAPI / ModelAPI_Tools.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        ModelAPI_Tools.cpp
4 // Created:     06 Aug 2014
5 // Author:      Vitaly Smetannikov
6
7 #include "ModelAPI_Tools.h"
8 #include <ModelAPI_Session.h>
9 #include <ModelAPI_Document.h>
10 #include <ModelAPI_Object.h>
11 #include <ModelAPI_AttributeDouble.h>
12 #include <ModelAPI_ResultParameter.h>
13
14 #include <list>
15
16 namespace ModelAPI_Tools {
17
18 std::shared_ptr<GeomAPI_Shape> shape(const ResultPtr& theResult)
19 {
20 /*
21   ResultBodyPtr aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(theResult);
22   if (aBody)
23     return aBody->shape();
24
25   ResultConstructionPtr aConstruct = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(
26     theResult);
27   if (aConstruct)
28     return aConstruct->shape();
29
30   ResultGroupPtr aGroup = std::dynamic_pointer_cast<ModelAPI_ResultGroup>(theResult);
31   if (aGroup)
32     return aGroup->shape();
33   return std::shared_ptr<GeomAPI_Shape>();
34   */
35   return theResult->shape();
36 }
37
38 bool findVariable(const std::string& theName, double& outValue)
39 {
40   SessionPtr aSession = ModelAPI_Session::get();
41   std::list<DocumentPtr> aDocList;
42   DocumentPtr aDocument = aSession->activeDocument();
43   DocumentPtr aRootDocument = aSession->moduleDocument();
44   aDocList.push_back(aDocument);
45   if (aDocument != aRootDocument) {
46     aDocList.push_back(aRootDocument);
47   }
48   for(std::list<DocumentPtr>::const_iterator it = aDocList.begin(); it != aDocList.end(); ++it) {
49     ObjectPtr aParamObj = (*it)->objectByName(ModelAPI_ResultParameter::group(), theName);
50     ResultParameterPtr aParam = std::dynamic_pointer_cast<ModelAPI_ResultParameter>(aParamObj);
51     if(!aParam.get())
52       continue;
53     AttributeDoublePtr aValueAttribute = aParam->data()->real(ModelAPI_ResultParameter::VALUE());
54     outValue = aValueAttribute->value();
55     return true;
56   }
57   return false;
58 }
59
60 } // namespace ModelAPI_Tools