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