1 // Copyright (C) 2014-2020 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 #include <ModelAPI_Events.h>
23 #include <GeomAPI_Pnt2d.h>
24 #include <GeomAPI_Shape.h>
26 //#define DEBUG_OBJECT_MOVED_MESSAGE
27 #ifdef DEBUG_OBJECT_MOVED_MESSAGE
31 ModelAPI_ObjectUpdatedMessage::ModelAPI_ObjectUpdatedMessage(const Events_ID theID,
32 const void* theSender)
33 : Events_MessageGroup(theID, theSender)
36 ModelAPI_ObjectUpdatedMessage::~ModelAPI_ObjectUpdatedMessage()
39 ModelAPI_ObjectDeletedMessage::ModelAPI_ObjectDeletedMessage(const Events_ID theID,
40 const void* theSender)
41 : Events_MessageGroup(theID, theSender)
44 ModelAPI_ObjectDeletedMessage::~ModelAPI_ObjectDeletedMessage()
47 ModelAPI_OrderUpdatedMessage::ModelAPI_OrderUpdatedMessage(const Events_ID theID,
48 const void* theSender)
49 : Events_Message(theID, theSender)
52 ModelAPI_OrderUpdatedMessage::~ModelAPI_OrderUpdatedMessage()
57 ModelAPI_FeatureStateMessage::ModelAPI_FeatureStateMessage(const Events_ID theID,
58 const void* theSender)
59 : Events_Message(theID, theSender)
61 myCurrentFeature = std::shared_ptr<ModelAPI_Feature>();
64 ModelAPI_FeatureStateMessage::~ModelAPI_FeatureStateMessage()
67 std::shared_ptr<ModelAPI_Feature> ModelAPI_FeatureStateMessage::feature() const
69 return myCurrentFeature;
72 void ModelAPI_FeatureStateMessage::setFeature(std::shared_ptr<ModelAPI_Feature>& theFeature)
74 myCurrentFeature = theFeature;
77 bool ModelAPI_FeatureStateMessage::hasState(const std::string& theKey) const
79 return myFeatureState.find(theKey) != myFeatureState.end();
82 bool ModelAPI_FeatureStateMessage::state(const std::string& theFeatureId, bool theDefault) const
84 if(hasState(theFeatureId)) {
85 return myFeatureState.at(theFeatureId);
90 void ModelAPI_FeatureStateMessage::setState(const std::string& theFeatureId, bool theValue)
92 myFeatureState[theFeatureId] = theValue;
95 std::list<std::string> ModelAPI_FeatureStateMessage::features() const
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);
106 ModelAPI_DocumentCreatedMessage::ModelAPI_DocumentCreatedMessage(
107 const Events_ID theID, const void* theSender)
108 : Events_Message(theID, theSender)
111 ModelAPI_DocumentCreatedMessage::~ModelAPI_DocumentCreatedMessage()
114 DocumentPtr ModelAPI_DocumentCreatedMessage::document() const
119 void ModelAPI_DocumentCreatedMessage::setDocument(DocumentPtr theDocument)
121 myDocument = theDocument;
124 ModelAPI_AttributeEvalMessage::ModelAPI_AttributeEvalMessage(
125 const Events_ID theID, const void* theSender)
126 : Events_Message(theID, theSender)
129 ModelAPI_AttributeEvalMessage::~ModelAPI_AttributeEvalMessage()
132 AttributePtr ModelAPI_AttributeEvalMessage::attribute() const
137 void ModelAPI_AttributeEvalMessage::setAttribute(AttributePtr theAttribute)
139 myAttribute = theAttribute;
142 ModelAPI_ParameterEvalMessage::ModelAPI_ParameterEvalMessage(
143 const Events_ID theID, const void* theSender)
144 : Events_Message(theID, theSender), myIsProcessed(false)
147 ModelAPI_ParameterEvalMessage::~ModelAPI_ParameterEvalMessage()
150 FeaturePtr ModelAPI_ParameterEvalMessage::parameter() const
155 void ModelAPI_ParameterEvalMessage::setParameter(FeaturePtr theParam)
160 void ModelAPI_ParameterEvalMessage::setResults(
161 const std::list<std::shared_ptr<ModelAPI_ResultParameter> >& theParamsList,
162 const double theResult, const std::string& theError)
164 myParamsList = theParamsList;
165 myResult = theResult;
167 myIsProcessed = true;
170 bool ModelAPI_ParameterEvalMessage::isProcessed()
172 return myIsProcessed;
175 const std::list<std::shared_ptr<ModelAPI_ResultParameter> >&
176 ModelAPI_ParameterEvalMessage::params() const
181 const double& ModelAPI_ParameterEvalMessage::result() const
186 const std::string& ModelAPI_ParameterEvalMessage::error() const
191 ModelAPI_ComputePositionsMessage::ModelAPI_ComputePositionsMessage(
192 const Events_ID theID, const void* theSender)
193 : Events_Message(theID, theSender)
196 ModelAPI_ComputePositionsMessage::~ModelAPI_ComputePositionsMessage()
199 const std::string& ModelAPI_ComputePositionsMessage::expression() const
204 const std::string& ModelAPI_ComputePositionsMessage::parameter() const
209 void ModelAPI_ComputePositionsMessage::set(
210 const std::string& theExpression, const std::string& theParameter)
212 myExpression = theExpression;
213 myParamName = theParameter;
216 void ModelAPI_ComputePositionsMessage::setPositions(
217 const std::list<std::pair<int, int> >& thePositions)
219 myPositions = thePositions;
222 const std::list<std::pair<int, int> >& ModelAPI_ComputePositionsMessage::positions() const
228 ModelAPI_ObjectRenamedMessage::ModelAPI_ObjectRenamedMessage(const Events_ID theID,
229 const void* theSender)
230 : Events_Message(theID, theSender)
233 ModelAPI_ObjectRenamedMessage::~ModelAPI_ObjectRenamedMessage()
236 void ModelAPI_ObjectRenamedMessage::send(ObjectPtr theObject,
237 const std::string& theOldName,
238 const std::string& theNewName,
239 const void* theSender)
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);
249 ObjectPtr ModelAPI_ObjectRenamedMessage::object() const
254 void ModelAPI_ObjectRenamedMessage::setObject(ObjectPtr theObject)
256 myObject = theObject;
259 std::string ModelAPI_ObjectRenamedMessage::oldName() const
264 void ModelAPI_ObjectRenamedMessage::setOldName(const std::string& theOldName)
266 myOldName = theOldName;
269 std::string ModelAPI_ObjectRenamedMessage::newName() const
274 void ModelAPI_ObjectRenamedMessage::setNewName(const std::string& theNewName)
276 myNewName = theNewName;
279 ModelAPI_ReplaceParameterMessage::ModelAPI_ReplaceParameterMessage(const Events_ID theID,
280 const void* theSender)
281 : Events_Message(theID, theSender)
284 ModelAPI_ReplaceParameterMessage::~ModelAPI_ReplaceParameterMessage()
287 void ModelAPI_ReplaceParameterMessage::send(ObjectPtr theObject,
288 const void* theSender)
290 std::shared_ptr<ModelAPI_ReplaceParameterMessage> aMessage(
291 new ModelAPI_ReplaceParameterMessage(eventId(), theSender));
292 aMessage->setObject(theObject);
293 Events_Loop::loop()->send(aMessage);
296 ObjectPtr ModelAPI_ReplaceParameterMessage::object() const
301 void ModelAPI_ReplaceParameterMessage::setObject(ObjectPtr theObject)
303 myObject = theObject;
307 // ===== ModelAPI_SolverFailedMessage =====
308 ModelAPI_SolverFailedMessage::ModelAPI_SolverFailedMessage(const Events_ID theID,
309 const void* theSender)
310 : Events_Message(theID, theSender),
314 ModelAPI_SolverFailedMessage::~ModelAPI_SolverFailedMessage()
317 void ModelAPI_SolverFailedMessage::setObjects(const std::set<ObjectPtr>& theObjects)
319 myObjects = theObjects;
322 const std::set<ObjectPtr>& ModelAPI_SolverFailedMessage::objects() const
328 // ===== ModelAPI_ObjectMovedMessage =====
329 ModelAPI_ObjectMovedMessage::ModelAPI_ObjectMovedMessage(const void* theSender)
330 : Events_Message(Events_Loop::eventByName(EVENT_OBJECT_MOVED), theSender)
333 void ModelAPI_ObjectMovedMessage::setMovedObject(const ObjectPtr& theMovedObject)
335 myMovedObject = theMovedObject;
336 myMovedAttribute = AttributePtr();
339 void ModelAPI_ObjectMovedMessage::setMovedAttribute(const AttributePtr& theMovedAttribute,
340 const int thePointIndex)
342 myMovedAttribute = theMovedAttribute;
343 myMovedObject = ObjectPtr();
344 myMovedPointIndex = thePointIndex;
347 void ModelAPI_ObjectMovedMessage::setOriginalPosition(double theX, double theY)
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;
356 void ModelAPI_ObjectMovedMessage::setOriginalPosition(
357 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint)
359 myOriginalPosition = thePoint;
360 #ifdef DEBUG_OBJECT_MOVED_MESSAGE
361 std::cout << "setOriginalPosition: " << myOriginalPosition->x() << ", "
362 << myOriginalPosition->y() << std::endl;
366 void ModelAPI_ObjectMovedMessage::setCurrentPosition(double theX, double theY)
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;
377 void ModelAPI_ObjectMovedMessage::setCurrentPosition(
378 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint)
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;
390 // ===== ModelAPI_ShapesFailedMessage =====
391 ModelAPI_ShapesFailedMessage::ModelAPI_ShapesFailedMessage(const Events_ID theID,
392 const void* theSender)
393 : Events_Message(theID, theSender)
396 ModelAPI_ShapesFailedMessage::~ModelAPI_ShapesFailedMessage()
399 void ModelAPI_ShapesFailedMessage::setShapes(const ListOfShape& theShapes)
401 myShapes = theShapes;
404 const ListOfShape& ModelAPI_ShapesFailedMessage::shapes() const