1 // Copyright (C) 2014-2019 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>
25 //#define DEBUG_OBJECT_MOVED_MESSAGE
26 #ifdef DEBUG_OBJECT_MOVED_MESSAGE
30 ModelAPI_ObjectUpdatedMessage::ModelAPI_ObjectUpdatedMessage(const Events_ID theID,
31 const void* theSender)
32 : Events_MessageGroup(theID, theSender)
35 ModelAPI_ObjectUpdatedMessage::~ModelAPI_ObjectUpdatedMessage()
38 ModelAPI_ObjectDeletedMessage::ModelAPI_ObjectDeletedMessage(const Events_ID theID,
39 const void* theSender)
40 : Events_MessageGroup(theID, theSender)
43 ModelAPI_ObjectDeletedMessage::~ModelAPI_ObjectDeletedMessage()
46 ModelAPI_OrderUpdatedMessage::ModelAPI_OrderUpdatedMessage(const Events_ID theID,
47 const void* theSender)
48 : Events_Message(theID, theSender)
51 ModelAPI_OrderUpdatedMessage::~ModelAPI_OrderUpdatedMessage()
56 ModelAPI_FeatureStateMessage::ModelAPI_FeatureStateMessage(const Events_ID theID,
57 const void* theSender)
58 : Events_Message(theID, theSender)
60 myCurrentFeature = std::shared_ptr<ModelAPI_Feature>();
63 ModelAPI_FeatureStateMessage::~ModelAPI_FeatureStateMessage()
66 std::shared_ptr<ModelAPI_Feature> ModelAPI_FeatureStateMessage::feature() const
68 return myCurrentFeature;
71 void ModelAPI_FeatureStateMessage::setFeature(std::shared_ptr<ModelAPI_Feature>& theFeature)
73 myCurrentFeature = theFeature;
76 bool ModelAPI_FeatureStateMessage::hasState(const std::string& theKey) const
78 return myFeatureState.find(theKey) != myFeatureState.end();
81 bool ModelAPI_FeatureStateMessage::state(const std::string& theFeatureId, bool theDefault) const
83 if(hasState(theFeatureId)) {
84 return myFeatureState.at(theFeatureId);
89 void ModelAPI_FeatureStateMessage::setState(const std::string& theFeatureId, bool theValue)
91 myFeatureState[theFeatureId] = theValue;
94 std::list<std::string> ModelAPI_FeatureStateMessage::features() const
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);
105 ModelAPI_DocumentCreatedMessage::ModelAPI_DocumentCreatedMessage(
106 const Events_ID theID, const void* theSender)
107 : Events_Message(theID, theSender)
110 ModelAPI_DocumentCreatedMessage::~ModelAPI_DocumentCreatedMessage()
113 DocumentPtr ModelAPI_DocumentCreatedMessage::document() const
118 void ModelAPI_DocumentCreatedMessage::setDocument(DocumentPtr theDocument)
120 myDocument = theDocument;
123 ModelAPI_AttributeEvalMessage::ModelAPI_AttributeEvalMessage(
124 const Events_ID theID, const void* theSender)
125 : Events_Message(theID, theSender)
128 ModelAPI_AttributeEvalMessage::~ModelAPI_AttributeEvalMessage()
131 AttributePtr ModelAPI_AttributeEvalMessage::attribute() const
136 void ModelAPI_AttributeEvalMessage::setAttribute(AttributePtr theAttribute)
138 myAttribute = theAttribute;
141 ModelAPI_ParameterEvalMessage::ModelAPI_ParameterEvalMessage(
142 const Events_ID theID, const void* theSender)
143 : Events_Message(theID, theSender), myIsProcessed(false)
146 ModelAPI_ParameterEvalMessage::~ModelAPI_ParameterEvalMessage()
149 FeaturePtr ModelAPI_ParameterEvalMessage::parameter() const
154 void ModelAPI_ParameterEvalMessage::setParameter(FeaturePtr theParam)
159 void ModelAPI_ParameterEvalMessage::setResults(
160 const std::list<std::shared_ptr<ModelAPI_ResultParameter> >& theParamsList,
161 const double theResult, const std::string& theError)
163 myParamsList = theParamsList;
164 myResult = theResult;
166 myIsProcessed = true;
169 bool ModelAPI_ParameterEvalMessage::isProcessed()
171 return myIsProcessed;
174 const std::list<std::shared_ptr<ModelAPI_ResultParameter> >&
175 ModelAPI_ParameterEvalMessage::params() const
180 const double& ModelAPI_ParameterEvalMessage::result() const
185 const std::string& ModelAPI_ParameterEvalMessage::error() const
190 ModelAPI_ComputePositionsMessage::ModelAPI_ComputePositionsMessage(
191 const Events_ID theID, const void* theSender)
192 : Events_Message(theID, theSender)
195 ModelAPI_ComputePositionsMessage::~ModelAPI_ComputePositionsMessage()
198 const std::string& ModelAPI_ComputePositionsMessage::expression() const
203 const std::string& ModelAPI_ComputePositionsMessage::parameter() const
208 void ModelAPI_ComputePositionsMessage::set(
209 const std::string& theExpression, const std::string& theParameter)
211 myExpression = theExpression;
212 myParamName = theParameter;
215 void ModelAPI_ComputePositionsMessage::setPositions(
216 const std::list<std::pair<int, int> >& thePositions)
218 myPositions = thePositions;
221 const std::list<std::pair<int, int> >& ModelAPI_ComputePositionsMessage::positions() const
227 ModelAPI_ObjectRenamedMessage::ModelAPI_ObjectRenamedMessage(const Events_ID theID,
228 const void* theSender)
229 : Events_Message(theID, theSender)
232 ModelAPI_ObjectRenamedMessage::~ModelAPI_ObjectRenamedMessage()
235 void ModelAPI_ObjectRenamedMessage::send(ObjectPtr theObject,
236 const std::string& theOldName,
237 const std::string& theNewName,
238 const void* theSender)
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);
248 ObjectPtr ModelAPI_ObjectRenamedMessage::object() const
253 void ModelAPI_ObjectRenamedMessage::setObject(ObjectPtr theObject)
255 myObject = theObject;
258 std::string ModelAPI_ObjectRenamedMessage::oldName() const
263 void ModelAPI_ObjectRenamedMessage::setOldName(const std::string& theOldName)
265 myOldName = theOldName;
268 std::string ModelAPI_ObjectRenamedMessage::newName() const
273 void ModelAPI_ObjectRenamedMessage::setNewName(const std::string& theNewName)
275 myNewName = theNewName;
278 ModelAPI_ReplaceParameterMessage::ModelAPI_ReplaceParameterMessage(const Events_ID theID,
279 const void* theSender)
280 : Events_Message(theID, theSender)
283 ModelAPI_ReplaceParameterMessage::~ModelAPI_ReplaceParameterMessage()
286 void ModelAPI_ReplaceParameterMessage::send(ObjectPtr theObject,
287 const void* theSender)
289 std::shared_ptr<ModelAPI_ReplaceParameterMessage> aMessage(
290 new ModelAPI_ReplaceParameterMessage(eventId(), theSender));
291 aMessage->setObject(theObject);
292 Events_Loop::loop()->send(aMessage);
295 ObjectPtr ModelAPI_ReplaceParameterMessage::object() const
300 void ModelAPI_ReplaceParameterMessage::setObject(ObjectPtr theObject)
302 myObject = theObject;
306 // ===== ModelAPI_SolverFailedMessage =====
307 ModelAPI_SolverFailedMessage::ModelAPI_SolverFailedMessage(const Events_ID theID,
308 const void* theSender)
309 : Events_Message(theID, theSender),
313 ModelAPI_SolverFailedMessage::~ModelAPI_SolverFailedMessage()
316 void ModelAPI_SolverFailedMessage::setObjects(const std::set<ObjectPtr>& theObjects)
318 myObjects = theObjects;
321 const std::set<ObjectPtr>& ModelAPI_SolverFailedMessage::objects() const
327 // ===== ModelAPI_ObjectMovedMessage =====
328 ModelAPI_ObjectMovedMessage::ModelAPI_ObjectMovedMessage(const void* theSender)
329 : Events_Message(Events_Loop::eventByName(EVENT_OBJECT_MOVED), theSender)
332 void ModelAPI_ObjectMovedMessage::setMovedObject(const ObjectPtr& theMovedObject)
334 myMovedObject = theMovedObject;
335 myMovedAttribute = AttributePtr();
338 void ModelAPI_ObjectMovedMessage::setMovedAttribute(const AttributePtr& theMovedAttribute,
339 const int thePointIndex)
341 myMovedAttribute = theMovedAttribute;
342 myMovedObject = ObjectPtr();
343 myMovedPointIndex = thePointIndex;
346 void ModelAPI_ObjectMovedMessage::setOriginalPosition(double theX, double theY)
348 myOriginalPosition = std::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(theX, theY));
349 #ifdef DEBUG_OBJECT_MOVED_MESSAGE
350 std::cout << "setOriginalPosition: " << myOriginalPosition->x() << ", "
351 << myOriginalPosition->y() << std::endl;
355 void ModelAPI_ObjectMovedMessage::setOriginalPosition(
356 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint)
358 myOriginalPosition = thePoint;
359 #ifdef DEBUG_OBJECT_MOVED_MESSAGE
360 std::cout << "setOriginalPosition: " << myOriginalPosition->x() << ", "
361 << myOriginalPosition->y() << std::endl;
365 void ModelAPI_ObjectMovedMessage::setCurrentPosition(double theX, double theY)
367 myCurrentPosition = std::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(theX, theY));
368 #ifdef DEBUG_OBJECT_MOVED_MESSAGE
369 std::cout << "setCurrentPosition: " << myCurrentPosition->x() << ", " << myCurrentPosition->y()
370 << ", myCurrentPosition - myOriginalPosition: "
371 << myCurrentPosition->x() - myOriginalPosition->x() << ", "
372 << myCurrentPosition->y() - myOriginalPosition->y() << std::endl;
376 void ModelAPI_ObjectMovedMessage::setCurrentPosition(
377 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint)
379 myCurrentPosition = thePoint;
380 #ifdef DEBUG_OBJECT_MOVED_MESSAGE
381 std::cout << "setCurrentPosition: " << myCurrentPosition->x() << ", " << myCurrentPosition->y()
382 << ", myCurrentPosition - myOriginalPosition: "
383 << myCurrentPosition->x() - myOriginalPosition->x() << ", "
384 << myCurrentPosition->y() - myOriginalPosition->y() << std::endl;