1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: ModelAPI_Tools.cpp
4 // Created: 06 Aug 2014
5 // Author: Vitaly Smetannikov
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>
16 namespace ModelAPI_Tools {
18 std::shared_ptr<GeomAPI_Shape> shape(const ResultPtr& theResult)
21 ResultBodyPtr aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(theResult);
23 return aBody->shape();
25 ResultConstructionPtr aConstruct = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(
28 return aConstruct->shape();
30 ResultGroupPtr aGroup = std::dynamic_pointer_cast<ModelAPI_ResultGroup>(theResult);
32 return aGroup->shape();
33 return std::shared_ptr<GeomAPI_Shape>();
35 return theResult->shape();
38 bool findVariable(const std::string& theName, double& outValue)
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);
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);
53 AttributeDoublePtr aValueAttribute = aParam->data()->real(ModelAPI_ResultParameter::VALUE());
54 outValue = aValueAttribute->value();
60 } // namespace ModelAPI_Tools