Salome HOME
Construction elements are auxiliary entities:
authornds <natalia.donis@opencascade.com>
Thu, 5 Mar 2015 08:29:28 +0000 (11:29 +0300)
committernds <natalia.donis@opencascade.com>
Thu, 5 Mar 2015 08:29:28 +0000 (11:29 +0300)
Construction attribute change for multi-selected features

src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_Module.h
src/PartSet/PartSet_SketcherMgr.cpp
src/XGUI/XGUI_OperationMgr.cpp
src/XGUI/XGUI_OperationMgr.h

index 999344074774ea3012c6e9217a24a6f66838a5cf..39520d8af82f766a3ffe29a98001cbc0a0d531ca 100644 (file)
@@ -516,8 +516,9 @@ void PartSet_Module::onAction(bool isChecked)
 bool PartSet_Module::deleteObjects()
 {
   ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
-  bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation);
-  if (!isSketchOp && !PartSet_SketcherMgr::isNestedSketchOperation(anOperation))
+  bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
+       isNestedOp = PartSet_SketcherMgr::isNestedSketchOperation(anOperation);
+  if (!isSketchOp && !isNestedOp)
     return false;
 
   // sketch feature should be skipped, only sub-features can be removed
@@ -527,6 +528,7 @@ bool PartSet_Module::deleteObjects()
   // selected objects should be collected before the current operation abort because
   // the abort leads to selection lost on constraint objects. It can be corrected after #386 issue
   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
+  XGUI_Workshop* aWorkshop = aConnector->workshop();
   ModuleBase_ISelection* aSel = aConnector->selection();
   QObjectPtrList aSelectedObj = aSel->selectedPresentations();
 
@@ -536,14 +538,13 @@ bool PartSet_Module::deleteObjects()
   if (aSelectedObj.count() == 0)
     return false;
 
-  XGUI_Workshop* aWorkshop = aConnector->workshop();
-  XGUI_OperationMgr* anOpMgr = aWorkshop->operationMgr();
-  if (!isSketchOp && anOpMgr->canStopOperation()) {
-    ModuleBase_Operation* aCurrentOp = anOpMgr->currentOperation();
-    if (aCurrentOp) {
-      aCurrentOp->abort();
-    }
-  }
+  if (isNestedOp)
+    anOperation->abort();
+
+  // the active nested sketch operation should be aborted unconditionally
+  if (PartSet_SketcherMgr::isNestedSketchOperation(anOperation))
+    anOperation->abort();
+
   std::set<FeaturePtr> aRefFeatures;
   foreach (ObjectPtr aObj, aSelectedObj)
   {
@@ -558,7 +559,8 @@ bool PartSet_Module::deleteObjects()
     }
     //}
   }
-  QString aDescription = tr("Delete");
+
+  QString aDescription = aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text();
   /**
   // according to #355 feature, it is not necessary to inform about dependencies during
   // sketch delete operation
index 5a4429857d13f800d956376672c28c34d70765aa..67484a6d7f985e07bb7ed8360166f803906515a6 100644 (file)
@@ -80,6 +80,10 @@ public:
   /// \param theOperation a stopped operation
   virtual void operationStopped(ModuleBase_Operation* theOperation);
 
+  /// Returns action according to the given ID
+  /// \param theId an action identifier, it should be uniqued in the bounds of the module
+  QAction* action(const QString& theId) const;
+
   /// Returns True if there are available Undos and the sketch manager allows undo
   /// \return the boolean result
   virtual bool canUndo() const;
@@ -145,10 +149,6 @@ protected slots:
   /// Put the created actions into an internal map
   void createActions();
 
-  /// Returns action according to the given ID
-  /// \param theId an action identifier, it should be uniqued in the bounds of the module
-  QAction* action(const QString& theId) const;
-
   /// Add action to the internal map
   /// \param theId - string ID of the item
   /// \param theAction - action to add
index 1cfe39ac0319a8e87dcecfe3be01880b42bc57da..3b9e813c2ba6efa80b0280ed04dc5973c70c4943 100644 (file)
@@ -15,6 +15,7 @@
 #include <XGUI_ModuleConnector.h>
 #include <XGUI_Displayer.h>
 #include <XGUI_Workshop.h>
+#include <XGUI_ContextMenuMgr.h>
 #include <XGUI_Selection.h>
 #include <XGUI_SelectionMgr.h>
 #include <ModuleBase_ModelWidget.h>
@@ -55,6 +56,7 @@
 //#include <AIS_Shape.hxx>
 
 #include <ModelAPI_Events.h>
+#include <ModelAPI_Session.h>
 
 #include <QMouseEvent>
 #include <QApplication>
@@ -734,44 +736,105 @@ bool PartSet_SketcherMgr::canDisplayObject() const
 
 bool PartSet_SketcherMgr::canChangeConstruction(bool& isConstruction) const
 {
+  bool anEnabled = false;
   ModuleBase_Operation* anOperation = getCurrentOperation();
 
-  bool anEnabled = PartSet_SketcherMgr::isNestedCreateOperation(anOperation) &&
-                   PartSet_SketcherMgr::isEntityOperation(anOperation);
-  if (anEnabled) {
-    std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
-            std::dynamic_pointer_cast<SketchPlugin_Feature>(anOperation->feature());
-    if (aSketchFeature.get() != NULL) {
-      std::string anAttribute = SketchPlugin_Feature::CONSTRUCTION_ID();
+  bool isActiveSketch = PartSet_SketcherMgr::isSketchOperation(anOperation) ||
+                        PartSet_SketcherMgr::isNestedSketchOperation(anOperation);
+  if (!isActiveSketch)
+    return anEnabled;
 
-      std::shared_ptr<ModelAPI_AttributeBoolean> aConstructionAttr = 
-        std::dynamic_pointer_cast<ModelAPI_AttributeBoolean>(aSketchFeature->data()->attribute(anAttribute));
+  QObjectPtrList anObjects;
+  // 1. change construction type of a created feature
+  if (PartSet_SketcherMgr::isNestedCreateOperation(anOperation) &&
+      PartSet_SketcherMgr::isEntityOperation(anOperation) ) {
+    anObjects.append(anOperation->feature());
+  }
+  else {
+    if (PartSet_SketcherMgr::isNestedSketchOperation(anOperation))
+      anOperation->abort();
+    // 2. change construction type of selected sketch entities
+    ModuleBase_ISelection* aSelection = myModule->workshop()->selection();
+    anObjects = aSelection->selectedPresentations();
+  }
+  anEnabled = anObjects.size() > 0;
+
+  bool isNotConstructedFound = false;
+  if (anObjects.size() > 0) {
+    QObjectPtrList::const_iterator anIt = anObjects.begin(), aLast = anObjects.end();
+    for (; anIt != aLast && !isNotConstructedFound; anIt++) {
+      FeaturePtr aFeature = ModelAPI_Feature::feature(*anIt);
+      if (aFeature.get() != NULL) {
+        std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
+                            std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
+        if (aSketchFeature.get() != NULL) {
+          std::string anAttribute = SketchPlugin_Feature::CONSTRUCTION_ID();
 
-      isConstruction = aConstructionAttr->value();
+          std::shared_ptr<ModelAPI_AttributeBoolean> aConstructionAttr = 
+            std::dynamic_pointer_cast<ModelAPI_AttributeBoolean>(aSketchFeature->data()->attribute(anAttribute));
+          isNotConstructedFound = !aConstructionAttr->value();
+        }
+      }
     }
   }
+  isConstruction = anObjects.size() && !isNotConstructedFound;
   return anEnabled;
 }
   
 void PartSet_SketcherMgr::setConstruction(const bool isChecked)
 {
   ModuleBase_Operation* anOperation = getCurrentOperation();
-  std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
-          std::dynamic_pointer_cast<SketchPlugin_Feature>(anOperation->feature());
-  if (aSketchFeature.get() != NULL) {
-    std::string anAttribute = SketchPlugin_Feature::CONSTRUCTION_ID();
 
-    std::shared_ptr<ModelAPI_AttributeBoolean> aConstructionAttr = 
-      std::dynamic_pointer_cast<ModelAPI_AttributeBoolean>(aSketchFeature->data()->attribute(anAttribute));
-    aConstructionAttr->setValue(isChecked);
+  bool isActiveSketch = PartSet_SketcherMgr::isSketchOperation(anOperation) ||
+                        PartSet_SketcherMgr::isNestedSketchOperation(anOperation);
+  if (!isActiveSketch)
+    return;
 
-    // ModuleBase_ModelWidget::updateObject
-    Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
-    
-    static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY);
-    ModelAPI_EventCreator::get()->sendUpdated(aSketchFeature, anEvent);
-    Events_Loop::loop()->flush(anEvent);
+  QObjectPtrList anObjects;
+  bool isUseTransaction = false;
+  // 1. change construction type of a created feature
+  if (PartSet_SketcherMgr::isNestedCreateOperation(anOperation) &&
+      PartSet_SketcherMgr::isEntityOperation(anOperation) ) {
+    anObjects.append(anOperation->feature());
+  }
+  else {
+    isUseTransaction = true;
+    // 2. change construction type of selected sketch entities
+    ModuleBase_ISelection* aSelection = myModule->workshop()->selection();
+    anObjects = aSelection->selectedPresentations();
+  }
+
+  QAction* anAction = myModule->action("CONSTRUCTION_CMD");
+  SessionPtr aMgr = ModelAPI_Session::get();
+  if (isUseTransaction) {
+    if (PartSet_SketcherMgr::isNestedSketchOperation(anOperation))
+      anOperation->abort();
+    aMgr->startOperation(anAction->text().toStdString());
   }
+  storeSelection();
+
+  if (anObjects.size() > 0) {
+    QObjectPtrList::const_iterator anIt = anObjects.begin(), aLast = anObjects.end();
+    for (; anIt != aLast; anIt++) {
+      FeaturePtr aFeature = ModelAPI_Feature::feature(*anIt);
+      if (aFeature.get() != NULL) {
+        std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
+                            std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
+        if (aSketchFeature.get() != NULL) {
+          std::string anAttribute = SketchPlugin_Feature::CONSTRUCTION_ID();
+
+          std::shared_ptr<ModelAPI_AttributeBoolean> aConstructionAttr = 
+            std::dynamic_pointer_cast<ModelAPI_AttributeBoolean>(aSketchFeature->data()->attribute(anAttribute));
+          aConstructionAttr->setValue(isChecked);
+        }
+      }
+    }
+  }
+  if (isUseTransaction) {
+    aMgr->finishOperation();
+  }
+  Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
+  restoreSelection();
 }
 
 void PartSet_SketcherMgr::onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& thePln)
@@ -969,7 +1032,6 @@ void PartSet_SketcherMgr::visualizeFeature(ModuleBase_Operation* theOperation,
 void PartSet_SketcherMgr::storeSelection(const bool theHighlightedOnly)
 {
   ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
-
   ModuleBase_ISelection* aSelect = aWorkshop->selection();
   QList<ModuleBase_ViewerPrs> aHighlighted = aSelect->getHighlighted();
     
@@ -992,12 +1054,12 @@ void PartSet_SketcherMgr::storeSelection(const bool theHighlightedOnly)
     FeaturePtr aFeature = anIt.key();
     getCurrentSelection(aFeature, myCurrentSketch, aWorkshop, myCurrentSelection);
   }
-  qDebug(QString("  storeSelection: %1").arg(myCurrentSelection.size()).toStdString().c_str());
+  //qDebug(QString("  storeSelection: %1").arg(myCurrentSelection.size()).toStdString().c_str());
 }
 
 void PartSet_SketcherMgr::restoreSelection()
 {
-  qDebug(QString("restoreSelection: %1").arg(myCurrentSelection.size()).toStdString().c_str());
+  //qDebug(QString("restoreSelection: %1").arg(myCurrentSelection.size()).toStdString().c_str());
   ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
   FeatureToSelectionMap::const_iterator aSIt = myCurrentSelection.begin(),
index e767d7f964c053723c057983372d8a552c0685b7..1fe9717fb9bf9f6623b39514ea2c530153f43fa5 100644 (file)
@@ -301,10 +301,6 @@ bool XGUI_OperationMgr::onKeyReleased(QKeyEvent* theEvent)
       commitOperation();
     }
     break;
-    case Qt::Key_Delete: { // the delete button is occupied by the workshop Delete action,
-      // so this button process is realized here
-      emit keyDeleteReleased();
-    }
     default:
       isAccepted = false;
       break;
index 609d8fde4a6c0bf99a3ab7557ed1da3938544222..eb0e7541a753675a929521bc09d0342576d81937 100644 (file)
@@ -135,9 +135,6 @@ signals:
   /// Signal is emitted after the key released click.
   void keyEnterReleased();
 
-  /// Signal is emitted after the key delete released click.
-  void keyDeleteReleased();
-
  protected:
   /// Commits the current operatin if it is valid
   bool commitOperation();