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