Salome HOME
Merge branch 'Pre_2.8.0_development'
[modules/shaper.git] / src / ModelAPI / ModelAPI_Events.cpp
1 // Copyright (C) 2014-2017  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 //
20
21 #include <ModelAPI.h>
22 #include <ModelAPI_Events.h>
23
24 #include <GeomAPI_Pnt2d.h>
25
26 ModelAPI_ObjectUpdatedMessage::ModelAPI_ObjectUpdatedMessage(const Events_ID theID,
27                                                              const void* theSender)
28     : Events_MessageGroup(theID, theSender)
29 {
30
31 }
32
33 ModelAPI_ObjectUpdatedMessage::~ModelAPI_ObjectUpdatedMessage()
34 {
35
36 }
37
38 ModelAPI_ObjectDeletedMessage::ModelAPI_ObjectDeletedMessage(const Events_ID theID,
39                                                              const void* theSender)
40     : Events_MessageGroup(theID, theSender)
41 {
42
43 }
44
45 ModelAPI_ObjectDeletedMessage::~ModelAPI_ObjectDeletedMessage()
46 {
47
48 }
49
50 ModelAPI_OrderUpdatedMessage::ModelAPI_OrderUpdatedMessage(const Events_ID theID,
51                                                            const void* theSender)
52     : Events_Message(theID, theSender)
53 {
54
55 }
56
57 ModelAPI_OrderUpdatedMessage::~ModelAPI_OrderUpdatedMessage()
58 {
59
60 }
61
62 ModelAPI_FeatureStateMessage::ModelAPI_FeatureStateMessage(const Events_ID theID,
63                                                            const void* theSender)
64  : Events_Message(theID, theSender)
65 {
66   myCurrentFeature = std::shared_ptr<ModelAPI_Feature>();
67 }
68
69 ModelAPI_FeatureStateMessage::~ModelAPI_FeatureStateMessage()
70 {
71
72 }
73
74 std::shared_ptr<ModelAPI_Feature> ModelAPI_FeatureStateMessage::feature() const
75 {
76   return myCurrentFeature;
77 }
78
79 void ModelAPI_FeatureStateMessage::setFeature(std::shared_ptr<ModelAPI_Feature>& theFeature)
80 {
81   myCurrentFeature = theFeature;
82 }
83
84 bool ModelAPI_FeatureStateMessage::hasState(const std::string& theKey) const
85 {
86   return myFeatureState.find(theKey) != myFeatureState.end();
87 }
88
89 bool ModelAPI_FeatureStateMessage::state(const  std::string& theFeatureId, bool theDefault) const
90 {
91   if(hasState(theFeatureId)) {
92     return myFeatureState.at(theFeatureId);
93   }
94   return theDefault;
95 }
96
97 void ModelAPI_FeatureStateMessage::setState(const std::string& theFeatureId, bool theValue)
98 {
99   myFeatureState[theFeatureId] = theValue;
100 }
101
102 std::list<std::string> ModelAPI_FeatureStateMessage::features() const
103 {
104   std::list<std::string> result;
105   std::map<std::string, bool>::const_iterator it = myFeatureState.begin();
106   for( ; it != myFeatureState.end(); ++it) {
107     result.push_back(it->first);
108   }
109   return result;
110 }
111
112
113 ModelAPI_DocumentCreatedMessage::ModelAPI_DocumentCreatedMessage(
114   const Events_ID theID, const void* theSender)
115 : Events_Message(theID, theSender)
116 {}
117
118 ModelAPI_DocumentCreatedMessage::~ModelAPI_DocumentCreatedMessage()
119 {}
120
121 DocumentPtr ModelAPI_DocumentCreatedMessage::document() const
122 {
123   return myDocument;
124 }
125
126 void ModelAPI_DocumentCreatedMessage::setDocument(DocumentPtr theDocument)
127 {
128   myDocument = theDocument;
129 }
130
131 ModelAPI_AttributeEvalMessage::ModelAPI_AttributeEvalMessage(
132   const Events_ID theID, const void* theSender)
133 : Events_Message(theID, theSender)
134 {}
135
136 ModelAPI_AttributeEvalMessage::~ModelAPI_AttributeEvalMessage()
137 {}
138
139 AttributePtr ModelAPI_AttributeEvalMessage::attribute() const
140 {
141   return myAttribute;
142 }
143
144 void ModelAPI_AttributeEvalMessage::setAttribute(AttributePtr theAttribute)
145 {
146   myAttribute = theAttribute;
147 }
148
149 ModelAPI_ParameterEvalMessage::ModelAPI_ParameterEvalMessage(
150   const Events_ID theID, const void* theSender)
151   : Events_Message(theID, theSender), myIsProcessed(false)
152 {}
153
154 ModelAPI_ParameterEvalMessage::~ModelAPI_ParameterEvalMessage()
155 {}
156
157 FeaturePtr ModelAPI_ParameterEvalMessage::parameter() const
158 {
159   return myParam;
160 }
161
162 void ModelAPI_ParameterEvalMessage::setParameter(FeaturePtr theParam)
163 {
164   myParam = theParam;
165 }
166
167 void ModelAPI_ParameterEvalMessage::setResults(
168     const std::list<std::shared_ptr<ModelAPI_ResultParameter> >& theParamsList,
169     const double theResult, const std::string& theError)
170 {
171   myParamsList = theParamsList;
172   myResult = theResult;
173   myError = theError;
174   myIsProcessed = true;
175 }
176
177 bool ModelAPI_ParameterEvalMessage::isProcessed()
178 {
179   return myIsProcessed;
180 }
181
182 const std::list<std::shared_ptr<ModelAPI_ResultParameter> >&
183   ModelAPI_ParameterEvalMessage::params() const
184 {
185   return myParamsList;
186 }
187
188 const double& ModelAPI_ParameterEvalMessage::result() const
189 {
190   return myResult;
191 }
192
193 const std::string& ModelAPI_ParameterEvalMessage::error() const
194 {
195   return myError;
196 }
197
198 ModelAPI_ComputePositionsMessage::ModelAPI_ComputePositionsMessage(
199   const Events_ID theID, const void* theSender)
200   : Events_Message(theID, theSender)
201 {}
202
203 ModelAPI_ComputePositionsMessage::~ModelAPI_ComputePositionsMessage()
204 {}
205
206 const std::string& ModelAPI_ComputePositionsMessage::expression() const
207 {
208   return myExpression;
209 }
210
211 const std::string& ModelAPI_ComputePositionsMessage::parameter() const
212 {
213   return myParamName;
214 }
215
216 void ModelAPI_ComputePositionsMessage::set(
217   const std::string& theExpression, const std::string& theParameter)
218 {
219   myExpression = theExpression;
220   myParamName = theParameter;
221 }
222
223 void ModelAPI_ComputePositionsMessage::setPositions(
224   const std::list<std::pair<int, int> >& thePositions)
225 {
226   myPositions = thePositions;
227 }
228
229 const std::list<std::pair<int, int> >& ModelAPI_ComputePositionsMessage::positions() const
230 {
231   return myPositions;
232 }
233
234
235 ModelAPI_ObjectRenamedMessage::ModelAPI_ObjectRenamedMessage(const Events_ID theID,
236                                                              const void* theSender)
237 : Events_Message(theID, theSender)
238 {
239
240 }
241
242 ModelAPI_ObjectRenamedMessage::~ModelAPI_ObjectRenamedMessage()
243 {
244
245 }
246
247 void ModelAPI_ObjectRenamedMessage::send(ObjectPtr theObject,
248                                          const std::string& theOldName,
249                                          const std::string& theNewName,
250                                          const void* theSender)
251 {
252   std::shared_ptr<ModelAPI_ObjectRenamedMessage> aMessage(
253     new ModelAPI_ObjectRenamedMessage(eventId(), theSender));
254   aMessage->setObject(theObject);
255   aMessage->setOldName(theOldName);
256   aMessage->setNewName(theNewName);
257   Events_Loop::loop()->send(aMessage);
258 }
259
260 ObjectPtr ModelAPI_ObjectRenamedMessage::object() const
261 {
262   return myObject;
263 }
264
265 void ModelAPI_ObjectRenamedMessage::setObject(ObjectPtr theObject)
266 {
267   myObject = theObject;
268 }
269
270 std::string ModelAPI_ObjectRenamedMessage::oldName() const
271 {
272   return myOldName;
273 }
274
275 void ModelAPI_ObjectRenamedMessage::setOldName(const std::string& theOldName)
276 {
277   myOldName = theOldName;
278 }
279
280 std::string ModelAPI_ObjectRenamedMessage::newName() const
281 {
282   return myNewName;
283 }
284
285 void ModelAPI_ObjectRenamedMessage::setNewName(const std::string& theNewName)
286 {
287   myNewName = theNewName;
288 }
289
290 ModelAPI_ReplaceParameterMessage::ModelAPI_ReplaceParameterMessage(const Events_ID theID,
291                                                                    const void* theSender)
292 : Events_Message(theID, theSender)
293 {
294
295 }
296
297 ModelAPI_ReplaceParameterMessage::~ModelAPI_ReplaceParameterMessage()
298 {
299
300 }
301
302 void ModelAPI_ReplaceParameterMessage::send(ObjectPtr theObject,
303                                             const void* theSender)
304 {
305   std::shared_ptr<ModelAPI_ReplaceParameterMessage> aMessage(
306       new ModelAPI_ReplaceParameterMessage(eventId(), theSender));
307   aMessage->setObject(theObject);
308   Events_Loop::loop()->send(aMessage);
309 }
310
311 ObjectPtr ModelAPI_ReplaceParameterMessage::object() const
312 {
313   return myObject;
314 }
315
316 void ModelAPI_ReplaceParameterMessage::setObject(ObjectPtr theObject)
317 {
318   myObject = theObject;
319 }
320
321
322 // =====   ModelAPI_SolverFailedMessage   =====
323 ModelAPI_SolverFailedMessage::ModelAPI_SolverFailedMessage(const Events_ID theID,
324                                                            const void* theSender)
325   : Events_Message(theID, theSender),
326     myDOF(-1)
327 {
328 }
329
330 ModelAPI_SolverFailedMessage::~ModelAPI_SolverFailedMessage()
331 {
332 }
333
334 void ModelAPI_SolverFailedMessage::setObjects(const std::set<ObjectPtr>& theObjects)
335 {
336   myObjects = theObjects;
337 }
338
339 const std::set<ObjectPtr>& ModelAPI_SolverFailedMessage::objects() const
340 {
341   return myObjects;
342 }
343
344
345 // =====   ModelAPI_ObjectMovedMessage   =====
346 ModelAPI_ObjectMovedMessage::ModelAPI_ObjectMovedMessage(const void* theSender)
347   : Events_Message(Events_Loop::eventByName(EVENT_OBJECT_MOVED), theSender)
348 {
349 }
350
351 void ModelAPI_ObjectMovedMessage::setMovedObject(const ObjectPtr& theMovedObject)
352 {
353   myMovedObject = theMovedObject;
354   myMovedAttribute = AttributePtr();
355 }
356
357 void ModelAPI_ObjectMovedMessage::setMovedAttribute(const AttributePtr& theMovedAttribute)
358 {
359   myMovedAttribute = theMovedAttribute;
360   myMovedObject = ObjectPtr();
361 }
362
363 void ModelAPI_ObjectMovedMessage::setOriginalPosition(double theX, double theY)
364 {
365   myOriginalPosition = std::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(theX, theY));
366 }
367
368 void ModelAPI_ObjectMovedMessage::setOriginalPosition(
369     const std::shared_ptr<GeomAPI_Pnt2d>& thePoint)
370 {
371   myOriginalPosition = thePoint;
372 }
373
374 void ModelAPI_ObjectMovedMessage::setCurrentPosition(double theX, double theY)
375 {
376   myCurrentPosition = std::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(theX, theY));
377 }
378
379 void ModelAPI_ObjectMovedMessage::setCurrentPosition(
380     const std::shared_ptr<GeomAPI_Pnt2d>& thePoint)
381 {
382   myCurrentPosition = thePoint;
383 }