]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #1425: Delete referenced features on deletion of parameter
authorvsv <vitaly.smetannikov@opencascade.com>
Thu, 21 Apr 2016 14:54:35 +0000 (17:54 +0300)
committervsv <vitaly.smetannikov@opencascade.com>
Thu, 21 Apr 2016 14:54:48 +0000 (17:54 +0300)
src/ParametersPlugin/ParametersPlugin_WidgetParamsMgr.cpp
src/ParametersPlugin/ParametersPlugin_WidgetParamsMgr.h

index c360eddee31151e31a1c5d460f99cd5216b8afa9..183708fdb11c1b54949a5c59d226123c623dfccb 100644 (file)
@@ -281,6 +281,43 @@ void ParametersPlugin_WidgetParamsMgr::activateCustom()
 }
 
 
+void ParametersPlugin_WidgetParamsMgr::rebuildFeatures()
+{
+  myFeatures->takeChildren(); // Clear list
+
+  ResultParameterPtr aParam;
+  QTreeWidgetItem* aItem;
+  foreach(FeaturePtr aParameter, myParametersList) {
+    aParam = std::dynamic_pointer_cast<ModelAPI_ResultParameter>(aParameter->firstResult());
+    const std::set<std::shared_ptr<ModelAPI_Attribute>>& aRefs = aParam->data()->refsToMe();
+    std::set<std::shared_ptr<ModelAPI_Attribute> >::const_iterator aIt;
+    for(aIt = aRefs.cbegin(); aIt != aRefs.cend(); aIt++) {
+      std::shared_ptr<ModelAPI_Attribute> aAttr = (*aIt);
+      FeaturePtr aReferenced = std::dynamic_pointer_cast<ModelAPI_Feature>(aAttr->owner());
+      if (aReferenced.get()) {
+        QStringList aValNames;
+        aValNames << aReferenced->data()->name().c_str();
+
+        AttributeDoublePtr aDouble = std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aAttr);
+        if (aDouble.get()) {
+          aValNames << aDouble->text().c_str();
+          aValNames << QString::number(aDouble->value());
+        } else {
+          AttributeIntegerPtr aInt = std::dynamic_pointer_cast<ModelAPI_AttributeInteger>(aAttr);
+          if (aInt.get()) {
+            aValNames << aInt->text().c_str();
+            aValNames << QString::number(aInt->value());
+          }
+        }
+
+        aItem = new QTreeWidgetItem(aValNames);
+        myFeatures->addChild(aItem);
+      }
+    }
+  }
+}
+
+
 void ParametersPlugin_WidgetParamsMgr::onDoubleClick(const QModelIndex& theIndex)
 {
   if (myDelegate->isEditable(theIndex)) {
@@ -490,7 +527,23 @@ void ParametersPlugin_WidgetParamsMgr::onRemove()
       aIndirectRefFeatures, this, doDeleteReferences)) {
     myParametersList.removeOne(aCurFeature);
     myParameters->removeChild(aCurrentItem);
+
+    std::set<FeaturePtr> aFeaturesToDelete;
+    if (doDeleteReferences) {
+      aFeaturesToDelete = aDirectRefFeatures;
+      aFeaturesToDelete.insert(aIndirectRefFeatures.begin(), aIndirectRefFeatures.end());
+    }
     aDoc->removeFeature(aCurFeature);
+    std::set<FeaturePtr>::const_iterator anIt = aFeaturesToDelete.begin(),
+                                         aLast = aFeaturesToDelete.end();
+    for (; anIt != aLast; anIt++) {
+      FeaturePtr aFeature = (*anIt);
+      DocumentPtr aDoc = aFeature->document();
+      aDoc->removeFeature(aFeature);
+    }
+
+    Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY));
+    rebuildFeatures();
   }
 }
 
index 1ddd00d485eb40852266fe8f81815df46af84d62..ff4d5abb00f1b8b4dc1017da6860dbf837d70240 100644 (file)
@@ -71,20 +71,34 @@ private slots:
   /// Slot for reaction on shift down
   void onDown();
 
+  /// Slot to show message on closing of editor
   void sendWarning();
 
+  /// Slot for reaction on selection in the table
   void onSelectionChanged();
 
 private:
+  /// Creates a new parameter feature
   FeaturePtr createParameter() const;
+
+  /// Creates a new item
   QTreeWidgetItem* createNewItem() const;
+
+  /// Returns currently selected item
   QTreeWidgetItem* selectedItem() const;
+
+  /// Select the given Item and scroll the table to make it visible
   void selectItemScroll(QTreeWidgetItem* aItem);
 
+  /// Update values in features part
   void updateFeaturesPart();
 
+  /// Returns true if parameter with the given name already exists
   bool hasName(const QString& theName) const;
 
+  /// Clear and rebuild children of Features item
+  void rebuildFeatures();
+
   QTreeWidget* myTable;
   QTreeWidgetItem* myFeatures;
   QTreeWidgetItem* myParameters;