Salome HOME
5.2.3 Sketcher: ambiguity of the red cross in case of over-constraint
authorvsv <vsv@opencascade.com>
Fri, 8 Nov 2019 11:04:52 +0000 (14:04 +0300)
committervsv <vsv@opencascade.com>
Fri, 8 Nov 2019 11:04:52 +0000 (14:04 +0300)
src/Config/Config_Keywords.h
src/ModuleBase/CMakeLists.txt
src/ModuleBase/ModuleBase_IWorkshop.h
src/ModuleBase/ModuleBase_WidgetFactory.cpp
src/ModuleBase/ModuleBase_WidgetLabel.cpp
src/ModuleBase/ModuleBase_WidgetUndoLabel.cpp [new file with mode: 0644]
src/ModuleBase/ModuleBase_WidgetUndoLabel.h [new file with mode: 0644]
src/SketchPlugin/plugin-Sketch.xml
src/SketchSolver/SketchSolver_Error.h
src/XGUI/XGUI_ModuleConnector.cpp
src/XGUI/XGUI_ModuleConnector.h

index 0a8f4aba4f06bbc7a154385ca958a818146a6951..5637a989181b0f91a3c55d594435066d2e455d35 100644 (file)
@@ -35,6 +35,7 @@ const static char* PROPERTY_PANEL_ID = "property_panel_id";
 
 // Widgets
 const static char* WDG_INFO = "label";
+const static char* WDG_UNDOLABEL = "undo_label";
 const static char* WDG_DOUBLEVALUE = "doublevalue";
 const static char* WDG_DOUBLEVALUELABEL = "labelvalue";
 const static char* WDG_INTEGERVALUE = "integervalue";
@@ -95,6 +96,7 @@ const static char* ATTR_TOOLTIP = FEATURE_TOOLTIP;
 const static char* ATTR_ICON = FEATURE_ICON;
 const static char* ATTR_LABEL = "label";
 const static char* ATTR_STYLE_SHEET = "styleSheet";
+const static char* ATTR_HTML_STYLE = "isHTML";
 const static char* ATTR_DEFAULT = "default";
 const static char* ATTR_INTERNAL = "internal";
 const static char* ATTR_OBLIGATORY = "obligatory";
index fe127695dd545764b0db4fc78ec1d351b1d8b041..265c140f59b980355517c9a83635ba40e6a4ca59 100644 (file)
@@ -108,6 +108,7 @@ SET(PROJECT_HEADERS
   ModuleBase_WidgetSelectionFilter.h
   ModuleBase_IStepPrs.h
   ModuleBase_SelectionFilterType.h
+  ModuleBase_WidgetUndoLabel.h
 )
 
 SET(PROJECT_MOC_HEADERS
@@ -158,6 +159,7 @@ SET(PROJECT_MOC_HEADERS
   ModuleBase_WidgetRadiobox.h
   ModuleBase_WidgetPointInput.h
   ModuleBase_WidgetSelectionFilter.h
+  ModuleBase_WidgetUndoLabel.h
 )
 
 SET(PROJECT_SOURCES
@@ -228,6 +230,7 @@ SET(PROJECT_SOURCES
   ModuleBase_WidgetPointInput.cpp
   ModuleBase_WidgetSelectionFilter.cpp
   ModuleBase_IStepPrs.cpp
+  ModuleBase_WidgetUndoLabel.cpp
 )
 
 SET(TEXT_RESOURCES
index 56ca626301444da926d7014608a8bb3b5c1d50f6..466b06641d828f285841f64c3e189555e2c5d9cd 100644 (file)
@@ -152,6 +152,15 @@ Q_OBJECT
   //! \param theAIS the object which has to be activated
   virtual void applyCurrentSelectionModes(const AISObjectPtr& theAIS) = 0;
 
+  //! Undo last command
+  virtual void undo() = 0;
+
+  //! Set enabled state of cancel button in property panel
+  virtual void setCancelEnabled(bool toEnable) = 0;
+
+  //! Returns current state of cancel button
+  virtual bool isCancelEnabled() const = 0;
+
 signals:
   /// Signal selection changed.
   void selectionChanged();
index 0cc45bf0947f676388cd9fb748f86c0286a6169e..7f51a61a7cebe597e8b0cb4c1b41f1636c814238 100644 (file)
@@ -40,6 +40,7 @@
 #include <ModuleBase_WidgetMultiSelector.h>
 #include <ModuleBase_WidgetConcealedObjects.h>
 #include <ModuleBase_WidgetLabel.h>
+#include <ModuleBase_WidgetUndoLabel.h>
 #include <ModuleBase_WidgetToolbox.h>
 #include <ModuleBase_WidgetRadiobox.h>
 #include <ModuleBase_PageBase.h>
@@ -303,6 +304,8 @@ ModuleBase_ModelWidget* ModuleBase_WidgetFactory::createWidgetByType(const std::
     result = new ModuleBase_WidgetLabel(theParent, myWidgetApi);
   } else if (theType == WDG_DOUBLEVALUE) {
     result = new ModuleBase_WidgetDoubleValue(theParent, myWidgetApi);
+  } else if (theType == WDG_UNDOLABEL) {
+    result = new ModuleBase_WidgetUndoLabel(theParent, myWorkshop, myWidgetApi);
   } else if (theType == WDG_DOUBLEVALUELABEL) {
     result = new ModuleBase_WidgetLabelValue(theParent, myWidgetApi);
   } else if (theType == WDG_INTEGERVALUE) {
index b717bf1039c7c0dadc958836b56836424e9db179..135d006a3805539ed3403468de543f91c4ddd9b6 100644 (file)
@@ -37,6 +37,8 @@ ModuleBase_WidgetLabel::ModuleBase_WidgetLabel(QWidget* theParent,
 : ModuleBase_ModelWidget(theParent, theData)
 {
   QString aText = translate(theData->getProperty("title"));
+  bool aIsHtml = theData->getBooleanAttribute(ATTR_HTML_STYLE, false);
+
   QString aLabelIcon = QString::fromStdString(theData->getProperty("icon"));
   myLabel = new QLabel(aText, theParent);
   if (!aLabelIcon.isEmpty()) {
@@ -48,13 +50,15 @@ ModuleBase_WidgetLabel::ModuleBase_WidgetLabel(QWidget* theParent,
   myLabel->setWordWrap(true);
   myLabel->setIndent(5);
   myLabel->setContentsMargins(0,0,0,4);
+  if (aIsHtml)
+    myLabel->setTextFormat(Qt::RichText);
 
   QVBoxLayout* aLayout = new QVBoxLayout(this);
   ModuleBase_Tools::zeroMargins(aLayout);
   aLayout->addWidget(myLabel);
   setLayout(aLayout);
 
-  std::string aStyleSheet = theData->getProperty(ATTR_STYLE_SHEET).c_str();
+  std::string aStyleSheet = theData->getProperty(ATTR_STYLE_SHEET);
   if (!aStyleSheet.empty())
     myLabel->setStyleSheet(QString("QLabel {%1}").arg(aStyleSheet.c_str()));
 }
diff --git a/src/ModuleBase/ModuleBase_WidgetUndoLabel.cpp b/src/ModuleBase/ModuleBase_WidgetUndoLabel.cpp
new file mode 100644 (file)
index 0000000..3f5a35b
--- /dev/null
@@ -0,0 +1,54 @@
+// Copyright (C) 2014-2019  CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#include "ModuleBase_WidgetUndoLabel.h"
+#include "ModuleBase_IWorkshop.h"
+
+#include <QPushButton>
+#include <QLayout>
+#include <QString>
+#include <QLabel>
+
+ModuleBase_WidgetUndoLabel::ModuleBase_WidgetUndoLabel(QWidget* theParent,
+  ModuleBase_IWorkshop* theWorkshop,
+  const Config_WidgetAPI* theData)
+  : ModuleBase_WidgetLabel(theParent, theData),
+  myWorkshop(theWorkshop)
+{
+  myUndoBtn = new QPushButton(tr("Undo"), this);
+  myUndoBtn->hide();
+  layout()->addWidget(myUndoBtn);
+  connect(myUndoBtn, SIGNAL(clicked(bool)), SLOT(onUndo()));
+}
+
+
+bool ModuleBase_WidgetUndoLabel::restoreValueCustom()
+{
+  bool aRes = ModuleBase_WidgetLabel::restoreValueCustom();
+  bool aError = myLabel->text().length() > 0;
+  myUndoBtn->setVisible(aError);
+  myWorkshop->setCancelEnabled(!aError);
+  return aRes;
+}
+
+
+void ModuleBase_WidgetUndoLabel::onUndo()
+{
+  myWorkshop->undo();
+}
\ No newline at end of file
diff --git a/src/ModuleBase/ModuleBase_WidgetUndoLabel.h b/src/ModuleBase/ModuleBase_WidgetUndoLabel.h
new file mode 100644 (file)
index 0000000..efa46ee
--- /dev/null
@@ -0,0 +1,55 @@
+// Copyright (C) 2014-2019  CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#ifndef ModuleBase_WidgetUndoLabel_H
+#define ModuleBase_WidgetUndoLabel_H
+
+#include "ModuleBase.h"
+#include "ModuleBase_WidgetLabel.h"
+
+class QPushButton;
+class ModuleBase_IWorkshop;
+
+/**
+* \ingroup GUI
+* Implementation of model widget for a label control
+*/
+class MODULEBASE_EXPORT ModuleBase_WidgetUndoLabel : public ModuleBase_WidgetLabel
+{
+  Q_OBJECT
+public:
+  /// Constructor
+  /// \param theParent the parent object
+  /// \param theData the widget configuation. The attribute of the model widget is obtained from
+  ModuleBase_WidgetUndoLabel(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop,
+    const Config_WidgetAPI* theData);
+
+  virtual ~ModuleBase_WidgetUndoLabel() {}
+
+  virtual bool restoreValueCustom();
+
+private slots:
+  void onUndo();
+
+private:
+  ModuleBase_IWorkshop* myWorkshop;
+  QPushButton* myUndoBtn;
+};
+
+#endif
\ No newline at end of file
index 39f2a2b80cb05ccd28a79f330fc1923fc7210de8..fa1b2ad666965643ea1cdcdb9e4da34686f1e92c 100644 (file)
@@ -25,8 +25,7 @@
         <sketch-start-label id="External" geometrical_selection="true" title="Select a plane on which to create a sketch" tooltip="Select a plane on which to create a sketch">
           <validator id="GeomValidators_Face" parameters="plane"/>
         </sketch-start-label>
-        <!-- <label id="SolverDOF"/>  -->
-        <label id="SolverError" styleSheet="color : red; font : bold"/>
+        <undo_label id="SolverError" isHTML="true" />
         <validator id="SketchPlugin_SolverErrorValidator"/>
       </feature>
 
index e6e3a002ce3f500f4e53583791224a85a4616f0b..f93711e819c9b075d53e350a1ed7cf4783e2d0a1 100644 (file)
@@ -33,16 +33,18 @@ class SketchSolver_Error
   /// The value parameter for the constraint
   inline static const std::string& CONSTRAINTS()
   {
-    static const std::string MY_ERROR_VALUE("The constraint is conflicting with others. "
-      "To fix this, you can either undo your operation or remove a conflicting constraint.");
+    static const std::string MY_ERROR_VALUE("<b>The constraint is conflicting with others. "
+      "To fix this, you can either <font color='red'>undo (Ctrl+Z)</font> your operation or "
+      "<font color='red'>remove</font> a conflicting constraint.</b>");
     return MY_ERROR_VALUE;
   }
   /// Cyclic dependency of copied features with their originals
   inline static const std::string& INFINITE_LOOP()
   {
     static const std::string MY_ERROR_VALUE(
-      "There is a circular reference between copied sketch entities and their originals. "
-      "To fix this, you can either undo your operation or remove wrong constraint.");
+      "<b>There is a circular reference between copied sketch entities and their originals. "
+      "To fix this, you can either <font color='red'>undo (Ctrl+Z)</font> your operation or "
+      "<font color='red'>remove</font> wrong constraint.</b>");
     return MY_ERROR_VALUE;
   }
   /// Constraints should use objects instead of features as attributes
index 61bc814f47c7db8fdfb36ce8cc1bc2104faf7868..36866a91eda927474d490538e3d4e00d5d9bebdc 100644 (file)
@@ -232,4 +232,38 @@ void XGUI_ModuleConnector::applyCurrentSelectionModes(const AISObjectPtr& theAIS
 {
   Handle(AIS_InteractiveObject) anIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
   myWorkshop->selectionActivate()->activate(anIO, false);
-}
\ No newline at end of file
+}
+
+
+void XGUI_ModuleConnector::undo()
+{
+  myWorkshop->onUndo();
+}
+
+void XGUI_ModuleConnector::setCancelEnabled(bool toEnable)
+{
+  XGUI_ActionsMgr* anActionsMgr = workshop()->actionsMgr();
+  QAction* aAbortAction = anActionsMgr->operationStateAction(XGUI_ActionsMgr::AbortAll);
+  QAction* aAbortAllAction = anActionsMgr->operationStateAction(XGUI_ActionsMgr::Abort);
+  if (aAbortAction) {
+    aAbortAction->setEnabled(toEnable);
+  }
+  if (aAbortAllAction) {
+    aAbortAllAction->setEnabled(toEnable);
+  }
+}
+
+bool XGUI_ModuleConnector::isCancelEnabled() const
+{
+  XGUI_ActionsMgr* anActionsMgr = workshop()->actionsMgr();
+  QAction* aAbortAction = anActionsMgr->operationStateAction(XGUI_ActionsMgr::AbortAll);
+  QAction* aAbortAllAction = anActionsMgr->operationStateAction(XGUI_ActionsMgr::Abort);
+  bool isEnabled = false;
+  if (aAbortAction) {
+    isEnabled = true;
+  }
+  if (aAbortAllAction) {
+    isEnabled &= true;
+  }
+  return isEnabled;
+}
index 41415fdf39be9daf4c70fd9d6eed77cd5c516dfb..ca31763a8c95b895eae38cc88635ed6e37173dfb 100644 (file)
@@ -136,6 +136,15 @@ Q_OBJECT
   //! \param theAIS the object which has to be activated
   virtual void applyCurrentSelectionModes(const AISObjectPtr& theAIS);
 
+  //! Undo last command
+  virtual void undo();
+
+  //! Set enabled state of cancel button in property panel
+  virtual void setCancelEnabled(bool toEnable);
+
+  //! Returns current state of cancel button
+  virtual bool isCancelEnabled() const;
+
 private:
   QObjectPtrList activeObjects(const QObjectPtrList& theObjList) const;