]> SALOME platform Git repositories - modules/shaper.git/blob - src/ModelHighAPI/ModelHighAPI_Interface.cpp
Salome HOME
Issue #2052: Modification of parameters don't work (sketch, extrusion)
[modules/shaper.git] / src / ModelHighAPI / ModelHighAPI_Interface.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2 // Name   : ModelHighAPI_Interface.cpp
3 // Purpose:
4 //
5 // History:
6 // 17/05/16 - Sergey POKHODENKO - Creation of the file
7
8 //--------------------------------------------------------------------------------------
9 #include "ModelHighAPI_Interface.h"
10 //--------------------------------------------------------------------------------------
11 #include <Events_InfoMessage.h>
12
13 #include <ModelAPI_CompositeFeature.h>
14 #include <ModelAPI_Events.h>
15 #include <ModelAPI_Feature.h>
16 #include <ModelAPI_Session.h>
17 #include <ModelAPI_Validator.h>
18
19 #include "ModelHighAPI_Selection.h"
20 //--------------------------------------------------------------------------------------
21 ModelHighAPI_Interface::ModelHighAPI_Interface(
22   const std::shared_ptr<ModelAPI_Feature> & theFeature)
23 : myFeature(theFeature)
24 {
25
26 }
27
28 ModelHighAPI_Interface::~ModelHighAPI_Interface()
29 {
30
31 }
32
33 //--------------------------------------------------------------------------------------
34 std::shared_ptr<ModelAPI_Feature> ModelHighAPI_Interface::feature() const
35 {
36   return myFeature;
37 }
38
39 std::shared_ptr<ModelHighAPI_Interface> ModelHighAPI_Interface::subFeature(const int theIndex) const
40 {
41   CompositeFeaturePtr aCompositeFeature =
42     std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(myFeature);
43   if(!aCompositeFeature.get()) {
44     return InterfacePtr();
45   }
46
47   FeaturePtr aSubFeature = aCompositeFeature->subFeature(theIndex);
48   if(!aSubFeature.get()) {
49     return InterfacePtr();
50   }
51
52   return InterfacePtr(new ModelHighAPI_Interface(aSubFeature));
53 }
54
55 const std::string& ModelHighAPI_Interface::getKind() const
56 {
57   return feature()->getKind();
58 }
59
60 void ModelHighAPI_Interface::execute(bool isForce)
61 {
62   if (isForce) {
63     SessionPtr aMgr = ModelAPI_Session::get();
64     ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
65     FeaturePtr aFeature = feature();
66     if(aFactory->validate(aFeature))
67       aFeature->execute();
68   }
69
70   Events_Loop* aLoop = Events_Loop::loop();
71   aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
72   aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
73   //aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
74   //aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_DELETED));
75 }
76
77 void ModelHighAPI_Interface::setName(const std::string& theName)
78 {
79   feature()->data()->setName(theName);
80 }
81
82 ModelHighAPI_Selection ModelHighAPI_Interface::result() const
83 {
84   const_cast<ModelHighAPI_Interface*>(this)->execute();
85
86   return ModelHighAPI_Selection(feature()->firstResult());
87 }
88
89 std::list<ModelHighAPI_Selection> ModelHighAPI_Interface::results() const
90 {
91   const_cast<ModelHighAPI_Interface*>(this)->execute();
92
93   std::list<ModelHighAPI_Selection> aSelectionList;
94
95   std::list<std::shared_ptr<ModelAPI_Result> > aResults = feature()->results();
96   for (auto it = aResults.begin(), end = aResults.end(); it != end; ++it) {
97     aSelectionList.push_back(ModelHighAPI_Selection(*it));
98   }
99
100   return aSelectionList;
101 }
102
103 std::shared_ptr<ModelAPI_Result> ModelHighAPI_Interface::defaultResult() const
104 {
105   const_cast<ModelHighAPI_Interface*>(this)->execute();
106
107   return feature()->lastResult();
108 }
109
110 void ModelHighAPI_Interface::throwException(const std::string & theDescription)
111 {
112   Events_InfoMessage("ModelHighAPI_Interface", theDescription).send();
113 }
114
115 const std::string& ModelHighAPI_Interface::attributeGetter(const std::string& theAttrName)
116 {
117   return myAttrGetter[theAttrName];
118 }