1 // Copyright (C) 2014-2017 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
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
22 #include <ModelAPI_Events.h>
24 #include <GeomAPI_Pnt2d.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)
38 ModelAPI_ObjectUpdatedMessage::~ModelAPI_ObjectUpdatedMessage()
43 ModelAPI_ObjectDeletedMessage::ModelAPI_ObjectDeletedMessage(const Events_ID theID,
44 const void* theSender)
45 : Events_MessageGroup(theID, theSender)
50 ModelAPI_ObjectDeletedMessage::~ModelAPI_ObjectDeletedMessage()
55 ModelAPI_OrderUpdatedMessage::ModelAPI_OrderUpdatedMessage(const Events_ID theID,
56 const void* theSender)
57 : Events_Message(theID, theSender)
62 ModelAPI_OrderUpdatedMessage::~ModelAPI_OrderUpdatedMessage()
67 ModelAPI_FeatureStateMessage::ModelAPI_FeatureStateMessage(const Events_ID theID,
68 const void* theSender)
69 : Events_Message(theID, theSender)
71 myCurrentFeature = std::shared_ptr<ModelAPI_Feature>();
74 ModelAPI_FeatureStateMessage::~ModelAPI_FeatureStateMessage()
79 std::shared_ptr<ModelAPI_Feature> ModelAPI_FeatureStateMessage::feature() const
81 return myCurrentFeature;
84 void ModelAPI_FeatureStateMessage::setFeature(std::shared_ptr<ModelAPI_Feature>& theFeature)
86 myCurrentFeature = theFeature;
89 bool ModelAPI_FeatureStateMessage::hasState(const std::string& theKey) const
91 return myFeatureState.find(theKey) != myFeatureState.end();
94 bool ModelAPI_FeatureStateMessage::state(const std::string& theFeatureId, bool theDefault) const
96 if(hasState(theFeatureId)) {
97 return myFeatureState.at(theFeatureId);
102 void ModelAPI_FeatureStateMessage::setState(const std::string& theFeatureId, bool theValue)
104 myFeatureState[theFeatureId] = theValue;
107 std::list<std::string> ModelAPI_FeatureStateMessage::features() const
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);
118 ModelAPI_DocumentCreatedMessage::ModelAPI_DocumentCreatedMessage(
119 const Events_ID theID, const void* theSender)
120 : Events_Message(theID, theSender)
123 ModelAPI_DocumentCreatedMessage::~ModelAPI_DocumentCreatedMessage()
126 DocumentPtr ModelAPI_DocumentCreatedMessage::document() const
131 void ModelAPI_DocumentCreatedMessage::setDocument(DocumentPtr theDocument)
133 myDocument = theDocument;
136 ModelAPI_AttributeEvalMessage::ModelAPI_AttributeEvalMessage(
137 const Events_ID theID, const void* theSender)
138 : Events_Message(theID, theSender)
141 ModelAPI_AttributeEvalMessage::~ModelAPI_AttributeEvalMessage()
144 AttributePtr ModelAPI_AttributeEvalMessage::attribute() const
149 void ModelAPI_AttributeEvalMessage::setAttribute(AttributePtr theAttribute)
151 myAttribute = theAttribute;
154 ModelAPI_ParameterEvalMessage::ModelAPI_ParameterEvalMessage(
155 const Events_ID theID, const void* theSender)
156 : Events_Message(theID, theSender), myIsProcessed(false)
159 ModelAPI_ParameterEvalMessage::~ModelAPI_ParameterEvalMessage()
162 FeaturePtr ModelAPI_ParameterEvalMessage::parameter() const
167 void ModelAPI_ParameterEvalMessage::setParameter(FeaturePtr theParam)
172 void ModelAPI_ParameterEvalMessage::setResults(
173 const std::list<std::shared_ptr<ModelAPI_ResultParameter> >& theParamsList,
174 const double theResult, const std::string& theError)
176 myParamsList = theParamsList;
177 myResult = theResult;
179 myIsProcessed = true;
182 bool ModelAPI_ParameterEvalMessage::isProcessed()
184 return myIsProcessed;
187 const std::list<std::shared_ptr<ModelAPI_ResultParameter> >&
188 ModelAPI_ParameterEvalMessage::params() const
193 const double& ModelAPI_ParameterEvalMessage::result() const
198 const std::string& ModelAPI_ParameterEvalMessage::error() const
203 ModelAPI_ComputePositionsMessage::ModelAPI_ComputePositionsMessage(
204 const Events_ID theID, const void* theSender)
205 : Events_Message(theID, theSender)
208 ModelAPI_ComputePositionsMessage::~ModelAPI_ComputePositionsMessage()
211 const std::string& ModelAPI_ComputePositionsMessage::expression() const
216 const std::string& ModelAPI_ComputePositionsMessage::parameter() const
221 void ModelAPI_ComputePositionsMessage::set(
222 const std::string& theExpression, const std::string& theParameter)
224 myExpression = theExpression;
225 myParamName = theParameter;
228 void ModelAPI_ComputePositionsMessage::setPositions(
229 const std::list<std::pair<int, int> >& thePositions)
231 myPositions = thePositions;
234 const std::list<std::pair<int, int> >& ModelAPI_ComputePositionsMessage::positions() const
240 ModelAPI_ObjectRenamedMessage::ModelAPI_ObjectRenamedMessage(const Events_ID theID,
241 const void* theSender)
242 : Events_Message(theID, theSender)
247 ModelAPI_ObjectRenamedMessage::~ModelAPI_ObjectRenamedMessage()
252 void ModelAPI_ObjectRenamedMessage::send(ObjectPtr theObject,
253 const std::string& theOldName,
254 const std::string& theNewName,
255 const void* theSender)
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);
265 ObjectPtr ModelAPI_ObjectRenamedMessage::object() const
270 void ModelAPI_ObjectRenamedMessage::setObject(ObjectPtr theObject)
272 myObject = theObject;
275 std::string ModelAPI_ObjectRenamedMessage::oldName() const
280 void ModelAPI_ObjectRenamedMessage::setOldName(const std::string& theOldName)
282 myOldName = theOldName;
285 std::string ModelAPI_ObjectRenamedMessage::newName() const
290 void ModelAPI_ObjectRenamedMessage::setNewName(const std::string& theNewName)
292 myNewName = theNewName;
295 ModelAPI_ReplaceParameterMessage::ModelAPI_ReplaceParameterMessage(const Events_ID theID,
296 const void* theSender)
297 : Events_Message(theID, theSender)
302 ModelAPI_ReplaceParameterMessage::~ModelAPI_ReplaceParameterMessage()
307 void ModelAPI_ReplaceParameterMessage::send(ObjectPtr theObject,
308 const void* theSender)
310 std::shared_ptr<ModelAPI_ReplaceParameterMessage> aMessage(
311 new ModelAPI_ReplaceParameterMessage(eventId(), theSender));
312 aMessage->setObject(theObject);
313 Events_Loop::loop()->send(aMessage);
316 ObjectPtr ModelAPI_ReplaceParameterMessage::object() const
321 void ModelAPI_ReplaceParameterMessage::setObject(ObjectPtr theObject)
323 myObject = theObject;
327 // ===== ModelAPI_SolverFailedMessage =====
328 ModelAPI_SolverFailedMessage::ModelAPI_SolverFailedMessage(const Events_ID theID,
329 const void* theSender)
330 : Events_Message(theID, theSender),
335 ModelAPI_SolverFailedMessage::~ModelAPI_SolverFailedMessage()
339 void ModelAPI_SolverFailedMessage::setObjects(const std::set<ObjectPtr>& theObjects)
341 myObjects = theObjects;
344 const std::set<ObjectPtr>& ModelAPI_SolverFailedMessage::objects() const
350 // ===== ModelAPI_ObjectMovedMessage =====
351 ModelAPI_ObjectMovedMessage::ModelAPI_ObjectMovedMessage(const void* theSender)
352 : Events_Message(Events_Loop::eventByName(EVENT_OBJECT_MOVED), theSender)
356 void ModelAPI_ObjectMovedMessage::setMovedObject(const ObjectPtr& theMovedObject)
358 myMovedObject = theMovedObject;
359 myMovedAttribute = AttributePtr();
362 void ModelAPI_ObjectMovedMessage::setMovedAttribute(const AttributePtr& theMovedAttribute)
364 myMovedAttribute = theMovedAttribute;
365 myMovedObject = ObjectPtr();
368 void ModelAPI_ObjectMovedMessage::setOriginalPosition(double theX, double theY)
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;
377 void ModelAPI_ObjectMovedMessage::setOriginalPosition(
378 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint)
380 myOriginalPosition = thePoint;
381 #ifdef DEBUG_OBJECT_MOVED_MESSAGE
382 std::cout << "setOriginalPosition: " << myOriginalPosition->x() << ", "
383 << myOriginalPosition->y() << std::endl;
387 void ModelAPI_ObjectMovedMessage::setCurrentPosition(double theX, double theY)
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;
398 void ModelAPI_ObjectMovedMessage::setCurrentPosition(
399 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint)
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;