]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Fix for the issue #1569 : the moved groups must be updated
authormpv <mpv@opencascade.com>
Thu, 16 Jun 2016 12:03:46 +0000 (15:03 +0300)
committermpv <mpv@opencascade.com>
Thu, 16 Jun 2016 12:03:46 +0000 (15:03 +0300)
src/Model/Model_Document.cpp
src/Model/Model_Events.cpp
src/Model/Model_Events.h
src/Model/Model_Objects.cpp
src/Model/Model_Update.cpp
src/ModelAPI/ModelAPI_Events.cpp
src/ModelAPI/ModelAPI_Events.h
src/XGUI/XGUI_DataModel.cpp

index 8ce08d8ee8442563d1a27a8b27a8ac60f483dcf1..ebc4de9d8871ea39ed8d1e4d6e4a0bf84057ee93 100755 (executable)
@@ -831,12 +831,37 @@ void Model_Document::removeFeature(FeaturePtr theFeature)
   myObjs->removeFeature(theFeature);
 }
 
+// recursive function to check if theSub is a child of theMain composite feature
+// through all the hierarchy of parents
+static bool isSub(const CompositeFeaturePtr theMain, const FeaturePtr theSub) {
+  CompositeFeaturePtr aParent = ModelAPI_Tools::compositeOwner(theSub);
+  if (!aParent.get())
+    return false;
+  if (aParent == theMain)
+    return true;
+  return isSub(theMain, aParent);
+}
+
+
 void Model_Document::moveFeature(FeaturePtr theMoved, FeaturePtr theAfterThis)
 {
   bool aCurrentUp = theMoved == currentFeature(false);
   if (aCurrentUp) {
     setCurrentFeatureUp();
   }
+  // if user adds after high-level feature with nested, add it after all nested (otherwise the nested will be disabled)
+  CompositeFeaturePtr aCompositeAfter = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(theAfterThis);
+  if (aCompositeAfter.get()) {
+    FeaturePtr aSub = aCompositeAfter;
+    do {
+      FeaturePtr aNext = myObjs->nextFeature(aSub);
+      if (!isSub(aCompositeAfter, aNext)) {
+        theAfterThis = aSub;
+        break;
+      }
+      aSub = aNext;
+    } while (aSub.get());
+  }
 
   myObjs->moveFeature(theMoved, theAfterThis);
   if (aCurrentUp) { // make the moved feature enabled or disabled due to the real status
@@ -921,17 +946,6 @@ std::shared_ptr<ModelAPI_Feature> Model_Document::currentFeature(const bool theV
   return std::shared_ptr<ModelAPI_Feature>(); // null feature means the higher than first
 }
 
-// recursive function to check if theSub is a child of theMain composite feature
-// through all the hierarchy of parents
-static bool isSub(const CompositeFeaturePtr theMain, const FeaturePtr theSub) {
-  CompositeFeaturePtr aParent = ModelAPI_Tools::compositeOwner(theSub);
-  if (!aParent.get())
-    return false;
-  if (aParent == theMain)
-    return true;
-  return isSub(theMain, aParent);
-}
-
 void Model_Document::setCurrentFeature(
   std::shared_ptr<ModelAPI_Feature> theCurrent, const bool theVisible)
 {
index 7847f99b10a4fca3e4a00a30ba3ed87f84637df6..34d9522d86c42182630f13c92a9a121754a634d8 100644 (file)
@@ -27,11 +27,10 @@ void Model_EventCreator::sendDeleted(const std::shared_ptr<ModelAPI_Document>& t
   Events_Loop::loop()->send(aMsg, true);
 }
 
-void Model_EventCreator::sendReordered(const std::shared_ptr<ModelAPI_Document>& theDoc,
-                                       const std::string& theGroup) const
+void Model_EventCreator::sendReordered(const std::shared_ptr<ModelAPI_Feature>& theReordered) const
 {
   std::shared_ptr<Model_OrderUpdatedMessage> aMsg(
-    new Model_OrderUpdatedMessage(theDoc, theGroup));
+    new Model_OrderUpdatedMessage(theReordered));
   Events_Loop::loop()->send(aMsg, true);
 }
 
@@ -105,9 +104,9 @@ void Model_ObjectDeletedMessage::Join(const std::shared_ptr<Events_MessageGroup>
 
 /////////////////////// REORDERED MESSAGE /////////////////////////////
 Model_OrderUpdatedMessage::Model_OrderUpdatedMessage(
-    const std::shared_ptr<ModelAPI_Document>& theDoc, const std::string& theGroup)
-    : ModelAPI_OrderUpdatedMessage(messageId(), 0),
-      myDoc(theDoc), myGroup(theGroup)
+    FeaturePtr theReordered, const void* theSender)
+    : ModelAPI_OrderUpdatedMessage(messageId(), theSender),
+    myReordered(theReordered)
 {
 }
 
index 97f4170a4c8f7eadda1d44a5919d9b2207aaadbd..09518c7917b6dfd8c1aff8ba4800a261e5967cda 100644 (file)
@@ -24,8 +24,7 @@ class Model_EventCreator : public ModelAPI_EventCreator
                            const std::string& theGroup) const;
 
   /// creates reordered message and sends to the loop
-  virtual void sendReordered(const std::shared_ptr<ModelAPI_Document>& theDoc,
-                             const std::string& theGroup) const;
+  virtual void sendReordered(const std::shared_ptr<ModelAPI_Feature>& theReordered) const;
 
   /// must be one per application, the constructor for internal usage only
   Model_EventCreator();
@@ -90,25 +89,18 @@ class Model_ObjectDeletedMessage : public ModelAPI_ObjectDeletedMessage
 /// Message that feature was deleted (used for Object Browser update)
 class Model_OrderUpdatedMessage : public ModelAPI_OrderUpdatedMessage
 {
-  std::shared_ptr<ModelAPI_Document> myDoc;  ///< document owner of the feature
-  std::string myGroup;  ///< group identifier that contained the deleted feature
+  std::shared_ptr<ModelAPI_Feature> myReordered;  ///< the feature that was moved
 
   /// Use ModelAPI for creation of this event.
-  Model_OrderUpdatedMessage(const std::shared_ptr<ModelAPI_Document>& theDoc,
-                             const std::string& theGroup);
+  Model_OrderUpdatedMessage(FeaturePtr theReordered,
+                            const void* theSender = 0);
 
   friend class Model_EventCreator;
  public:
   /// Returns the document that has been updated
-  virtual std::shared_ptr<ModelAPI_Document> document() const
-  {
-    return myDoc;
-  }
-
-  /// Returns the group where the objects were reordered
-  virtual const std::string& group() const
+  virtual std::shared_ptr<ModelAPI_Feature> reordered()
   {
-    return myGroup;
+    return myReordered;
   }
 
   /// Returns the identifier of this message
index 0be76f106de57f717d525fceb2b6960113eedc0d..2351c98354891f66baaa69fac77dc1580658c3e7 100644 (file)
@@ -314,10 +314,9 @@ void Model_Objects::moveFeature(FeaturePtr theMoved, FeaturePtr theAfterThis)
   // update the feature and the history
   clearHistory(theMoved);
   // make sure all (selection) attributes of moved feature will be updated
-  theMoved->data()->setUpdateID(0);
   static Events_ID EVENT_UPD = Events_Loop::loop()->eventByName(EVENT_OBJECT_UPDATED);
   ModelAPI_EventCreator::get()->sendUpdated(theMoved, EVENT_UPD);
-  ModelAPI_EventCreator::get()->sendReordered(theMoved->document(), theMoved->groupName());
+  ModelAPI_EventCreator::get()->sendReordered(theMoved);
 }
 
 void Model_Objects::clearHistory(ObjectPtr theObj)
index 98d68fe1de38628d414990f2e1cdf42a052ac674..52cf1d1ba4ee5167763fb2eefaeec423437508fb 100755 (executable)
@@ -56,6 +56,8 @@ Model_Update::Model_Update()
   aLoop->registerListener(this, kPreviewBlockedEvent);
   static const Events_ID kPreviewRequestedEvent = aLoop->eventByName(EVENT_PREVIEW_REQUESTED);
   aLoop->registerListener(this, kPreviewRequestedEvent);
+  static const Events_ID kReorderEvent = aLoop->eventByName(EVENT_ORDER_UPDATED);
+  aLoop->registerListener(this, kReorderEvent);
 
   //  Config_PropManager::findProp("Model update", "automatic_rebuild")->value() == "true";
   myIsParamUpdated = false;
@@ -182,6 +184,7 @@ void Model_Update::processEvent(const std::shared_ptr<Events_Message>& theMessag
   static const Events_ID kStabilityEvent = aLoop->eventByName(EVENT_STABILITY_CHANGED);
   static const Events_ID kPreviewBlockedEvent = aLoop->eventByName(EVENT_PREVIEW_BLOCKED);
   static const Events_ID kPreviewRequestedEvent = aLoop->eventByName(EVENT_PREVIEW_REQUESTED);
+  static const Events_ID kReorderEvent = aLoop->eventByName(EVENT_ORDER_UPDATED);
 
 #ifdef DEB_UPDATE
   std::cout<<"****** Event "<<theMessage->eventID().eventText()<<std::endl;
@@ -298,6 +301,10 @@ void Model_Update::processEvent(const std::shared_ptr<Events_Message>& theMessag
     // in the end of transaction everything is updated, so clear the old objects
     myIsParamUpdated = false;
     myWaitForFinish.clear();
+  } else if (theMessage->eventID() == kReorderEvent) {
+    std::shared_ptr<ModelAPI_OrderUpdatedMessage> aMsg = 
+      std::dynamic_pointer_cast<ModelAPI_OrderUpdatedMessage>(theMessage);
+    addModified(aMsg->reordered(), aMsg->reordered()); // to update all attributes
   }
 }
 
index 45f321509798da7148d9fa5380d1abad96928c23..0b64a091e77c4e02db3c0d246db378121ae51ab9 100644 (file)
@@ -35,7 +35,7 @@ ModelAPI_ObjectDeletedMessage::~ModelAPI_ObjectDeletedMessage()
 }
 
 ModelAPI_OrderUpdatedMessage::ModelAPI_OrderUpdatedMessage(const Events_ID theID,
-                                                             const void* theSender)
+                                                           const void* theSender)
     : Events_Message(theID, theSender)
 {
 
index 93a8870b0b717b2c4eaa7bf5f66450d18a6796f0..f80dd62403021514b87b43367fe1aeaacda33083 100644 (file)
@@ -115,17 +115,14 @@ public:
 class MODELAPI_EXPORT ModelAPI_OrderUpdatedMessage : public Events_Message
 {
 protected:
-  /// Creates an empty message
+  /// Creates a message: 
   ModelAPI_OrderUpdatedMessage(const Events_ID theID, const void* theSender = 0);
   /// The virtual destructor
   virtual ~ModelAPI_OrderUpdatedMessage();
 
 public:
   /// Returns the document that has been updated
-  virtual std::shared_ptr<ModelAPI_Document> document() const = 0;
-
-  /// Returns the groups where the objects were reordered
-  virtual const std::string& group() const = 0;
+  virtual std::shared_ptr<ModelAPI_Feature> reordered() = 0;
 
   /// Returns the identifier of the kind of a message
   virtual const Events_ID messageId() = 0;
@@ -142,8 +139,7 @@ public:
   virtual void sendDeleted(const std::shared_ptr<ModelAPI_Document>& theDoc,
                            const std::string& theGroup) const = 0;
   /// creates reordered message and sends to the loop
-  virtual void sendReordered(const std::shared_ptr<ModelAPI_Document>& theDoc,
-                             const std::string& theGroup) const = 0;
+  virtual void sendReordered(const std::shared_ptr<ModelAPI_Feature>& theReordered) const = 0;
 
   /// returns the creator instance
   static const ModelAPI_EventCreator* get();
index 7b66c2bffe1991b8d0ec0ba93a151c4dcc1b11ca..cc80025fb8a98e5f59e6a9504c813ba226f625b1 100644 (file)
@@ -255,8 +255,8 @@ void XGUI_DataModel::processEvent(const std::shared_ptr<Events_Message>& theMess
   } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_ORDER_UPDATED)) {
     std::shared_ptr<ModelAPI_OrderUpdatedMessage> aUpdMsg =
         std::dynamic_pointer_cast<ModelAPI_OrderUpdatedMessage>(theMessage);
-    DocumentPtr aDoc = aUpdMsg->document();
-    std::string aGroup = aUpdMsg->group();
+    DocumentPtr aDoc = aUpdMsg->reordered()->document();
+    std::string aGroup = aUpdMsg->reordered()->group();
 
     QModelIndex aParent;
     int aStartId = 0;