]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Files to reproduce bug with Current feature
authorvsv <vitaly.smetannikov@opencascade.com>
Tue, 12 May 2015 07:46:54 +0000 (10:46 +0300)
committervsv <vitaly.smetannikov@opencascade.com>
Tue, 12 May 2015 07:46:54 +0000 (10:46 +0300)
src/PartSet/PartSet_DocumentDataModel.cpp
src/PartSet/PartSet_DocumentDataModel.h
src/PartSet/PartSet_MenuMgr.cpp
src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_PartDataModel.cpp
src/PartSet/PartSet_PartDataModel.h

index fcf37a140e9f5c1029dd24afd510b63c8c8e7bf5..64ac554c25c40f504a760d5d02b8960bbb29411f 100644 (file)
@@ -36,7 +36,7 @@ QMap<QString, QString> PartSet_DocumentDataModel::myIcons;
 
 PartSet_DocumentDataModel::PartSet_DocumentDataModel(QObject* theParent)
     : ModuleBase_IDocumentDataModel(theParent),
-      myActivePartId(-1), myHistoryBackOffset(0)
+      myActivePartId(-1)
 {
   // Create a top part of data tree model
   myModel = new PartSet_TopDataModel(this);
@@ -598,34 +598,6 @@ bool PartSet_DocumentDataModel::activatePart(const QModelIndex& theIndex)
     myActivePartId = aRootDoc->index(aFeature);
     myPartModels[myActivePartId]->setItemsColor(ACTIVE_COLOR);
   } 
-  //QModelIndex* aIndex = toSourceModelIndex(theIndex);
-  //if (!aIndex)
-  //  return false;
-
-  //const QAbstractItemModel* aModel = aIndex->model();
-
-  //if (isPartSubModel(aModel)) {
-  //  // if this is root node (Part item index)
-  //  if (!aIndex->parent().isValid()) {
-  //    if (myActivePart)
-  //      myActivePart->setItemsColor(PASSIVE_COLOR);
-
-  //      if (myActivePart == aModel) {
-  //        myActivePart = 0;
-  //        myActivePartIndex = QModelIndex();
-  //      } else {
-  //        myActivePart = (PartSet_PartModel*)aModel;
-  //        myActivePartIndex = theIndex;
-  //      }
-
-  //      if (myActivePart) {
-  //        myActivePart->setItemsColor(ACTIVE_COLOR);
-  //        myModel->setItemsColor(PASSIVE_COLOR);
-  //      } else
-  //        myModel->setItemsColor(ACTIVE_COLOR);
-  //      return true;
-  //    }
-  //  }
   return true;
 }
 
@@ -745,12 +717,21 @@ void PartSet_DocumentDataModel::clear()
 
 int PartSet_DocumentDataModel::lastHistoryRow() const
 {
-  return rowCount() - 1 - myHistoryBackOffset;
+  DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
+  FeaturePtr aFeature = aRootDoc->currentFeature();
+  return historyOffset() + aRootDoc->index(aFeature);
 }
 
 void PartSet_DocumentDataModel::setLastHistoryItem(const QModelIndex& theIndex)
 {
-  myHistoryBackOffset = rowCount() - 1 - theIndex.row();
+  if (theIndex.internalId() == HistoryNode) {
+    ObjectPtr aObject = object(theIndex);
+    SessionPtr aMgr = ModelAPI_Session::get();
+    DocumentPtr aRootDoc = aMgr->moduleDocument();
+    aMgr->startOperation(tr("History change").toStdString());
+    aRootDoc->setCurrentFeature(std::dynamic_pointer_cast<ModelAPI_Feature>(aObject));
+    aMgr->finishOperation();
+  }
 }
 
 QModelIndex PartSet_DocumentDataModel::lastHistoryItem() const
index 6ab69bf3c1ae52fa6d9da0c642dbcf257db5e1e9..6692d085add1cd8b91147b4f77465914e15e3af0 100644 (file)
@@ -197,8 +197,6 @@ Q_OBJECT
   //! List of saved QModelIndexes created by sub-models
   QList<QModelIndex*> myIndexes;
 
-  int myHistoryBackOffset;
-
   static QMap<QString, QString> myIcons;
 };
 
index e453a552554d43bf271df38a0370c5203fbd917c..1664be7692736498a7cd55c83dd4d6c7c301c247 100644 (file)
@@ -9,6 +9,8 @@
 #include "PartSet_SketcherMgr.h"
 #include "PartSet_Tools.h"
 
+#include <PartSetPlugin_Part.h>
+
 #include <GeomAPI_Pnt2d.h>
 #include <GeomDataAPI_Point2D.h>
 
@@ -470,10 +472,16 @@ void PartSet_MenuMgr::onActivatePart(bool)
 {
   QObjectPtrList aObjects = myModule->workshop()->selection()->selectedObjects();
   if (aObjects.size() > 0) {
-    ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObjects.first());
-    if (aPart) {
-      aPart->activate();
+    ObjectPtr aObj = aObjects.first();
+    ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
+    if (!aPart.get()) {
+      FeaturePtr aPartFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
+      if (aPartFeature.get() && (aPartFeature->getKind() == PartSetPlugin_Part::ID())) {
+        aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aPartFeature->firstResult());
+      }
     }
+    if (aPart.get())
+      aPart->activate();
   }
 }
 
index 860ca9e37bef4e2c5864635fd8e7acbd26a0109f..ffe80756d07164fc0c67c078c769cee7e93407c8 100644 (file)
@@ -669,8 +669,16 @@ void PartSet_Module::addObjectBrowserMenu(QMenu* theMenu) const
     ObjectPtr aObject = aObjects.first();
     if (aObject) {
       ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
-      if (aPart) {
-        if (aMgr->activeDocument() == aPart->partDoc())
+      FeaturePtr aPartFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObject);
+      bool isPart = aPart.get() || 
+        (aPartFeature.get() && (aPartFeature->getKind() == PartSetPlugin_Part::ID()));
+      if (isPart) {
+        DocumentPtr aPartDoc;
+        if (!aPart.get()) {
+          aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aPartFeature->firstResult());
+        }
+        aPartDoc = aPart->partDoc();
+        if (aMgr->activeDocument() == aPartDoc)
           theMenu->addAction(myMenuMgr->action("DEACTIVATE_PART_CMD"));
         else
           theMenu->addAction(myMenuMgr->action("ACTIVATE_PART_CMD"));
@@ -684,8 +692,10 @@ void PartSet_Module::addObjectBrowserMenu(QMenu* theMenu) const
     }
   } else if (aSelected == 0) {
     // if there is no selection then it means that upper label is selected
-    if (aMgr->activeDocument() != aMgr->moduleDocument())
-      theMenu->addAction(myMenuMgr->action("ACTIVATE_PARTSET_CMD"));
+    QModelIndexList aIndexes = myWorkshop->selection()->selectedIndexes();
+    if (aIndexes.size() == 0) // it means that selection happens in top label outside of tree view
+      if (aMgr->activeDocument() != aMgr->moduleDocument())
+        theMenu->addAction(myMenuMgr->action("ACTIVATE_PARTSET_CMD"));
   }
 }
 
index ec4dabffaccfbcc66badffccf4f7229e11279f2f..1398e59575c4a3378e6d08e4bb8462e4a5b47e1b 100644 (file)
@@ -246,7 +246,7 @@ QModelIndex PartSet_TopDataModel::objectIndex(const ObjectPtr& theObject) const
 //******************************************************************
 //******************************************************************
 PartSet_PartDataModel::PartSet_PartDataModel(QObject* theParent)
-    : PartSet_PartModel(theParent), myHistoryBackOffset(0)
+    : PartSet_PartModel(theParent)
 {
 }
 
@@ -572,13 +572,20 @@ int PartSet_PartDataModel::getRowsNumber() const
 
 int PartSet_PartDataModel::lastHistoryRow() const
 {
-  return rowCount() - 1 - myHistoryBackOffset;
+  DocumentPtr aDoc = partDocument();
+  FeaturePtr aFeature = aDoc->currentFeature();
+  return getRowsNumber() + aDoc->index(aFeature);
 }
 
 void PartSet_PartDataModel::setLastHistoryItem(const QModelIndex& theIndex)
 {
   if (theIndex.internalId() == HistoryObject) {
-    myHistoryBackOffset = rowCount() - 1 - theIndex.row();
+    SessionPtr aMgr = ModelAPI_Session::get();
+    ObjectPtr aObject = object(theIndex);
+    DocumentPtr aDoc = partDocument();
+    aMgr->startOperation(tr("History change").toStdString());
+    aDoc->setCurrentFeature(std::dynamic_pointer_cast<ModelAPI_Feature>(aObject));
+    aMgr->finishOperation();
   }
 }
 
index c821b4b5024826c35b5ad94544dc3bd2f9dca8ed..08be66b308fbe523d5a3f61199fe5bdbd635cfa5 100644 (file)
@@ -198,8 +198,6 @@ Q_OBJECT
     GroupObject,
     HistoryObject
   };
-
-  int myHistoryBackOffset;
 };
 
 #endif