Salome HOME
Accessibility of constraint operations under editing of sketch elements
authorvsv <vitaly.smetannikov@opencascade.com>
Tue, 1 Jul 2014 15:16:48 +0000 (19:16 +0400)
committervsv <vitaly.smetannikov@opencascade.com>
Tue, 1 Jul 2014 15:16:48 +0000 (19:16 +0400)
13 files changed:
src/ModuleBase/ModuleBase_IOperation.cpp
src/ModuleBase/ModuleBase_IOperation.h
src/ModuleBase/ModuleBase_Operation.cpp
src/ModuleBase/ModuleBase_Operation.h
src/ModuleBase/ModuleBase_WidgetEditor.cpp
src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_OperationFeatureCreate.cpp
src/PartSet/PartSet_OperationSketchBase.cpp
src/SketchPlugin/plugin-Sketch.xml
src/XGUI/XGUI_ActionsMgr.cpp
src/XGUI/XGUI_ActionsMgr.h
src/XGUI/XGUI_OperationMgr.cpp
src/XGUI/XGUI_OperationMgr.h

index bcc697dcb048ab34fac3bb08b823eff1b45696ec..cc398e5b03df0b227fb47b3b153740eb501fe097 100644 (file)
@@ -17,7 +17,7 @@
 #endif
 
 ModuleBase_IOperation::ModuleBase_IOperation(const QString& theId, QObject* theParent)
- : QObject(theParent)
+ : QObject(theParent), myIsEditing(false), myIsModified(false)
 {
   myDescription = new ModuleBase_OperationDescription(theId);
 }
index 77e01083c30ebab40f8cec01fac58e127cd3fc8e..0d304c0a2a7bebc1d684914ef6bba0b4bf48dc2b 100644 (file)
@@ -76,6 +76,12 @@ public:
   //void setModelWidgets(const std::string& theXmlRepresentation,
   //                     QList<ModuleBase_ModelWidget*> theWidgets);
 
+  /// Returns True if data of its feature was modified during operation
+  virtual bool isModified() const { return myIsModified; }
+
+  /// Returns True id the current operation is launched in editing mode
+  bool isEditOperation() const { return myIsEditing; }
+
 signals:
   void started(); /// the operation is started
   void aborted(); /// the operation is aborted
@@ -134,6 +140,12 @@ protected:
   /// Returns pointer to the root document.
   boost::shared_ptr<ModelAPI_Document> document() const;
 
+  /// Editing feature flag
+  bool myIsEditing;
+
+  /// Modified feature flag
+  bool myIsModified;
+
 private:
   ModuleBase_OperationDescription* myDescription; /// the container to have the operation description
 };
index f94c918ddccd3b4fffa9b90e0aa00a9e1d61b918..c1ed4b0d0b2648f55ac2922302a3f79c296bbd78 100644 (file)
@@ -24,7 +24,7 @@
 #endif
 
 ModuleBase_Operation::ModuleBase_Operation(const QString& theId, QObject* theParent)
-: ModuleBase_IOperation(theId, theParent), myIsEditing(false)
+: ModuleBase_IOperation(theId, theParent)
 {
 }
 
@@ -106,6 +106,7 @@ FeaturePtr ModuleBase_Operation::createFeature(const bool theFlushMessage)
   boost::shared_ptr<ModelAPI_Document> aDoc = document();
   FeaturePtr aFeature = aDoc->addFeature(getDescription()->operationId().toStdString());
   if (aFeature) { // TODO: generate an error if feature was not created
+    myIsModified = true;
     aFeature->execute();
     // Init default values
     /*QList<ModuleBase_ModelWidget*> aWidgets = getDescription()->modelWidgets();
index a40d774e4e1d7ab4db1859ea5f95c7ff9a4e870e..6a95f0085d8e8305c342bbc20f4be0a518fa6f3c 100644 (file)
@@ -72,8 +72,6 @@ public:
   /// Sets the operation feature
   void setEditingFeature(FeaturePtr theFeature);
 
-  bool isEditOperation() const { return myIsEditing; }
-
 public slots:
   /// Slots which listen the mode widget activation
   /// \param theWidget the model widget
@@ -113,8 +111,6 @@ private:
 
 private:
   FeaturePtr myFeature; /// the operation feature to be handled
-
-  bool myIsEditing;
 };
 
 #endif
index dbbe9fd5dbd09d4d8e575a3b8ce5aea6132db054..1e00eb180ea7e65e3ce0d5edad56e11130403f59 100644 (file)
@@ -48,6 +48,7 @@ double editedValue(double theValue, bool& isDone)
   aLay->setContentsMargins(0,0,0,0);
 
   QLineEdit* aEditor = new QLineEdit(QString::number(theValue), &aDlg);
+  aEditor->setValidator(new QDoubleValidator(aEditor));
   QObject::connect(aEditor, SIGNAL(returnPressed()), &aDlg, SLOT(accept()));
   aLay->addWidget(aEditor);
 
index 50c0de49d1a52ce21c0cfff4a4af5f05e917ab3b..dd788f540c534fa49f221028d8ba6b2bf3382ff1 100644 (file)
@@ -524,6 +524,20 @@ void PartSet_Module::onStorePoint2D(FeaturePtr theFeature, const std::string& th
 
 bool PartSet_Module::isFeatureEnabled(const QString& theCmdId) const
 {
-  //qDebug("### isFeatureEnabled %s", qPrintable(theCmdId));
-  return true;
+  XGUI_OperationMgr* aOpMgr = myWorkshop->operationMgr();
+  XGUI_ActionsMgr* aActMgr = myWorkshop->actionsMgr();
+
+  ModuleBase_Operation* aOperation = aOpMgr->currentOperation();
+  if (!aOperation)
+    return !aActMgr->isNested(theCmdId);
+
+  PartSet_OperationFeatureEdit* aSketchEdtOp = dynamic_cast<PartSet_OperationFeatureEdit*>(aOperation);
+  if (aSketchEdtOp) {
+    QStringList aConstraintList;
+    aConstraintList<<"SketchConstraintDistance"<<"SketchConstraintLength"
+      <<"SketchConstraintRadius"<<"SketchConstraintParallel"<<"SketchConstraintPerpendicular";
+    return aConstraintList.contains(theCmdId);
+  }
+  QStringList aList = aActMgr->nestedCommands(aOperation->id());
+  return aList.contains(theCmdId);
 }
index 096f56f40eb1febed05833eeef5e3e8c94f4c304..a1652fc482c575cebb7274b876077ddd138c7aaf 100644 (file)
@@ -286,6 +286,6 @@ bool PartSet_OperationFeatureCreate::setWidgetValue(FeaturePtr theFeature, doubl
   bool isApplyed = myActiveWidget->setValue(aValue);
 
   delete aValue;
-
+  myIsModified = (myIsModified || isApplyed);
   return isApplyed;
 }
index 117195468dec6912ae0ce6843be9687ca736314d..dd66393219a8f95dafba59a4bb06944551b843fb 100644 (file)
@@ -11,6 +11,8 @@
 #include <AIS_DimensionSelectionMode.hxx>
 
 #include <QKeyEvent>
+#include <QMessageBox>
+#include <QApplication>
 
 #ifdef _DEBUG
 #include <QDebug>
@@ -89,7 +91,15 @@ void PartSet_OperationSketchBase::keyReleased(const int theKey)
 {
   switch (theKey) {
     case Qt::Key_Escape: {
-      abort();
+      bool toAbort = true;
+      if (isModified()) {
+        int anAnswer = QMessageBox::question(qApp->activeWindow(), tr("Cancel operation"),
+                                  tr("Operation %1 will be cancelled. Continue?").arg(id()),
+                                  QMessageBox::Yes, QMessageBox::No);
+        toAbort = (anAnswer == QMessageBox::Yes);
+      }
+      if (toAbort)
+        abort();
     }
     break;
     default:
index 6c320ee7195fbb7af6862a906400168469512672..365fb02c3f79fb49eb97e78eacb2efc1f773cc1f 100644 (file)
@@ -21,6 +21,9 @@
         <point_selector id="ArcStartPoint" title="Start point" tooltip="Start point of the arc"/>
         <point_selector id="ArcEndPoint" title="End point" tooltip="End point of the arc"/>
       </feature>
+    </group>
+         
+    <group id="Constraints">
       <feature id="SketchConstraintCoincidence" title="Coincident" tooltip="Create constraint for the coincidence of two points" internal="1"/>
       <feature id="SketchConstraintDistance" title="Distance" tooltip="Create constraint for the distance from a point to an object">
         <label title="Select point and another feature (point or point on line) between which to calculate distance" tooltip="Select point and another feature (point or point on line) between which to calculate distance"/>
index 8722c089649af58c9bd6f1229c8d06ba1e1c8f78..611976e2a91c3da4186b17d8acf72da68f951f9b 100644 (file)
@@ -116,3 +116,20 @@ void XGUI_ActionsMgr::updateCheckState()
     setActionChecked(eachCommand, true);
   }
 }
+
+QStringList XGUI_ActionsMgr::nestedCommands(const QString& theId) const
+{
+  if (myNestedActions.contains(theId))
+    return myNestedActions[theId];
+  return QStringList();
+}
+
+bool XGUI_ActionsMgr::isNested(const QString& theId) const
+{
+  foreach(QString aId, myNestedActions.keys()) {
+    QStringList aList = myNestedActions[aId];
+    if (aList.contains(theId))
+      return true;
+  }
+  return false;
+}
\ No newline at end of file
index 38b8e167d689f86173b6fc3936991704cae9b02f..89e3b70b7ae0139b985285456dd02305940588d0 100644 (file)
@@ -31,6 +31,10 @@ public:
   //! Sets relation between the command (with given Id) and it's nested actions.
   void addNestedCommands(const QString& theId, const QStringList& theCommands);
 
+  QStringList nestedCommands(const QString& theId) const;
+
+  bool isNested(const QString& theId) const;
+
 public slots:
   //! Update workbench actions according to OperationMgr state:
   //! No active operations: all actions but nested are available
index 49faabba5d8014c4bca78b512bf68032355cb244..8a3b36e12ca8755668b625de5c2f3df25eb958ca 100644 (file)
@@ -108,10 +108,16 @@ bool XGUI_OperationMgr::canStartOperation(ModuleBase_Operation* theOperation)
 
 bool XGUI_OperationMgr::canStopOperation()
 {
-  int anAnswer = QMessageBox::question(0, tr("Operation launch"),
-                              tr("Previous operation is not finished and will be aborted"),
-                              QMessageBox::Ok, QMessageBox::Cancel);
-  return anAnswer == QMessageBox::Ok;
+  ModuleBase_Operation* anOperation = currentOperation();
+  if (anOperation) {
+    if (anOperation->isModified()) {
+      int anAnswer = QMessageBox::question(qApp->activeWindow(), tr("Operation launch"),
+                                  tr("Previous operation is not finished and will be aborted"),
+                                  QMessageBox::Ok, QMessageBox::Cancel);
+      return anAnswer == QMessageBox::Ok;
+    }
+  }
+  return true;
 }
 
 void XGUI_OperationMgr::onCommitOperation()
@@ -124,10 +130,22 @@ void XGUI_OperationMgr::onCommitOperation()
 void XGUI_OperationMgr::onAbortOperation()
 {
   ModuleBase_Operation* anOperation = currentOperation();
-  if (anOperation)
+  if (anOperation && canAbortOperation())
     anOperation->abort();
 }
 
+bool XGUI_OperationMgr::canAbortOperation()
+{
+  ModuleBase_Operation* anOperation = currentOperation();
+  if (anOperation && anOperation->isModified()) {
+      int anAnswer = QMessageBox::question(qApp->activeWindow(), tr("Cancel operation"),
+                                  tr("Operation %1 will be cancelled. Continue?").arg(anOperation->id()),
+                                  QMessageBox::Yes, QMessageBox::No);
+      return anAnswer == QMessageBox::Yes;
+  }
+  return true;
+}
+
 void XGUI_OperationMgr::onOperationStopped()
 {
   ModuleBase_Operation* aSenderOperation = dynamic_cast<ModuleBase_Operation*>(sender());
index f47d6aebdab54b2585b91ea89e233f0587f2f281..f6632c161631d3b04c8ea152d09c3632d6b71cd5 100644 (file)
@@ -81,6 +81,9 @@ protected:
   /// Returns whether the operation can be stopped.
   bool canStopOperation();
 
+  /// Returns true if the operation can be aborted
+  bool canAbortOperation();
+
 protected slots:
   /// Slot that commits the current operation.
   void onCommitOperation();