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