Salome HOME
DOF is visualized in label widget.
authornds <nds@opencascade.com>
Tue, 19 Apr 2016 14:21:42 +0000 (17:21 +0300)
committernds <nds@opencascade.com>
Tue, 19 Apr 2016 14:22:23 +0000 (17:22 +0300)
XGUI_Workshop correction to have right error solver value by resume sketch operation. Earlier it was done by repaint of this widget.

13 files changed:
src/Config/Config_Keywords.h
src/ModuleBase/CMakeLists.txt
src/ModuleBase/ModuleBase_WidgetErrorLabel.cpp [deleted file]
src/ModuleBase/ModuleBase_WidgetErrorLabel.h [deleted file]
src/ModuleBase/ModuleBase_WidgetFactory.cpp
src/ModuleBase/ModuleBase_WidgetLabel.cpp
src/ModuleBase/ModuleBase_WidgetLabel.h
src/SketchPlugin/SketchPlugin_Sketch.cpp
src/SketchPlugin/SketchPlugin_Sketch.h
src/SketchPlugin/plugin-Sketch.xml
src/SketchSolver/SketchSolver_Group.cpp
src/SketchSolver/SketchSolver_Manager.cpp
src/XGUI/XGUI_Workshop.cpp

index 471d0b9da633e976ba8c2a61a63076d8682925d4..a941f30d2ed5dfbb5ef10fb1b46614a644a9985b 100644 (file)
@@ -26,7 +26,6 @@ const static char* PROPERTY_PANEL_ID = "property_panel_id";
 
 // Widgets
 const static char* WDG_INFO = "label";
-const static char* WDG_ERRORINFO = "error_label";
 const static char* WDG_DOUBLEVALUE = "doublevalue";
 const static char* WDG_INTEGERVALUE = "integervalue";
 const static char* WDG_BOOLVALUE = "boolvalue";
@@ -72,6 +71,7 @@ const static char* _PARAMETERS = "parameters";
 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_DEFAULT = "default";
 const static char* ATTR_INTERNAL = "internal";
 const static char* ATTR_OBLIGATORY = "obligatory";
index 2553a9506b5497b2894d2a15cab89c5a61b92333..0e3066310eb0dfed016bb8e6c189c0f433a0f0e8 100644 (file)
@@ -61,7 +61,6 @@ SET(PROJECT_HEADERS
   ModuleBase_WidgetValidated.h
   ModuleBase_WidgetValidator.h
   ModuleBase_IconFactory.h
-  ModuleBase_WidgetErrorLabel.h
   ModuleBase_Dialog.h
 )
 
@@ -120,7 +119,6 @@ SET(PROJECT_SOURCES
   ModuleBase_WidgetValidated.cpp
   ModuleBase_WidgetValidator.cpp
   ModuleBase_IconFactory.cpp
-  ModuleBase_WidgetErrorLabel.cpp
   ModuleBase_SelectionValidator.cpp
   ModuleBase_Dialog.cpp
 )
diff --git a/src/ModuleBase/ModuleBase_WidgetErrorLabel.cpp b/src/ModuleBase/ModuleBase_WidgetErrorLabel.cpp
deleted file mode 100644 (file)
index cbcbae6..0000000
+++ /dev/null
@@ -1,64 +0,0 @@
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-// File:        ModuleBase_WidgetErrorLabel.cpp
-// Created:     03 Dec 2014
-// Author:      Vitaly SMETANNIKOV
-
-#include "ModuleBase_WidgetErrorLabel.h"
-
-#include <Config_WidgetAPI.h>
-#include <ModuleBase_Tools.h>
-#include <ModelAPI_AttributeString.h>
-
-#include <QLabel>
-#include <QEvent>
-
-ModuleBase_WidgetErrorLabel::ModuleBase_WidgetErrorLabel(QWidget* theParent,
-                                                         const Config_WidgetAPI* theData)
-: ModuleBase_WidgetLabel(theParent, theData)
-{
-  myDefaultStyle = myLabel->styleSheet();
-  myLabel->setContentsMargins(0,0,0,4);
-  myLabel->setWordWrap(true);
-  myLabel->installEventFilter(this);
-}
-
-ModuleBase_WidgetErrorLabel::~ModuleBase_WidgetErrorLabel()
-{
-}
-
-bool ModuleBase_WidgetErrorLabel::restoreValueCustom()
-{
-  DataPtr aData = myFeature->data();
-  AttributeStringPtr aStrAttr = aData->string(attributeID());
-  std::string aMsg;
-  if (aStrAttr.get()) {
-    aMsg = aStrAttr->value();
-  }
-  if (aMsg.empty()) {
-    myLabel->setText("");
-    myLabel->setStyleSheet(myDefaultStyle);
-  } else {
-    myLabel->setText(aMsg.c_str());
-    //myLabel->setStyleSheet("QLabel { color : red; font : italic }");
-    myLabel->setStyleSheet("QLabel { color : red; font : bold }");
-    //myLabel->setStyleSheet("QLabel { border: 1px solid red; }");
-  }
-  return true;
-}
-
-
-bool ModuleBase_WidgetErrorLabel::focusTo() 
-{ 
-  restoreValue();
-  return false; 
-}
-
-bool ModuleBase_WidgetErrorLabel::eventFilter(QObject* theObj, QEvent* theEvent)
-{
-  if (theObj == myLabel) {
-    if (theEvent->type() == QEvent::Show)
-      restoreValue();
-  }
-  return ModuleBase_WidgetLabel::eventFilter(theObj, theEvent);
-}
diff --git a/src/ModuleBase/ModuleBase_WidgetErrorLabel.h b/src/ModuleBase/ModuleBase_WidgetErrorLabel.h
deleted file mode 100644 (file)
index 9adee7c..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-// File:        ModuleBase_WidgetErrorLabel.h
-// Created:     03 Dec 2014
-// Author:      Vitaly SMETANNIKOV
-
-#ifndef ModuleBase_WidgetErrorLabel_H
-#define ModuleBase_WidgetErrorLabel_H
-
-#include "ModuleBase.h"
-#include "ModuleBase_WidgetLabel.h"
-
-class QLabel;
-
-/**
-* \ingroup GUI
-* Implementation of model widget for a label with error message
-*/
-class MODULEBASE_EXPORT ModuleBase_WidgetErrorLabel : 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_WidgetErrorLabel(QWidget* theParent, const Config_WidgetAPI* theData);
-
-  virtual ~ModuleBase_WidgetErrorLabel();
-
-  virtual bool restoreValueCustom();
-
-  virtual bool focusTo();
-
-protected:
-  bool eventFilter(QObject* theObj, QEvent* theEvent);
-
-private:
-  QString myDefaultStyle;
-};
-
-#endif
index 7e100f94efc99419002b3e01e7c87923c5d39c0a..d8e6bc26229a8c950ed918a3b6c08f006f3f83e0 100644 (file)
@@ -26,7 +26,6 @@
 #include <ModuleBase_WidgetLineEdit.h>
 #include <ModuleBase_WidgetMultiSelector.h>
 #include <ModuleBase_WidgetLabel.h>
-#include <ModuleBase_WidgetErrorLabel.h>
 #include <ModuleBase_WidgetToolbox.h>
 #include <ModuleBase_PageBase.h>
 #include <ModuleBase_PageGroupBox.h>
@@ -283,8 +282,6 @@ ModuleBase_ModelWidget* ModuleBase_WidgetFactory::createWidgetByType(const std::
 
   if (theType == WDG_INFO) {
     result = new ModuleBase_WidgetLabel(theParent, myWidgetApi);
-  } else if (theType == WDG_ERRORINFO) {
-    result = new ModuleBase_WidgetErrorLabel(theParent, myWidgetApi);
   } else if (theType == WDG_DOUBLEVALUE) {
     result = new ModuleBase_WidgetDoubleValue(theParent, myWidgetApi);
   } else if (theType == WDG_INTEGERVALUE) {
index e1e41ecd186ca107ae1bdaf75b48bac3bc99f1a8..31fe1f6c73f358393d9b57b6216a191cbb8e103f 100644 (file)
@@ -7,8 +7,11 @@
 #include "ModuleBase_WidgetLabel.h"
 
 #include <Config_WidgetAPI.h>
+#include <Config_Keywords.h>
 #include <ModuleBase_Tools.h>
 
+#include <ModelAPI_AttributeString.h>
+
 #include <QLabel>
 #include <QVBoxLayout>
 
@@ -22,10 +25,16 @@ ModuleBase_WidgetLabel::ModuleBase_WidgetLabel(QWidget* theParent,
   myLabel->setWordWrap(true);
   myLabel->setIndent(5);
   myLabel->setAlignment(Qt::AlignLeft | Qt::AlignTop);
+  myLabel->setContentsMargins(0,0,0,4);
+
   QVBoxLayout* aLayout = new QVBoxLayout(this);
   ModuleBase_Tools::zeroMargins(aLayout);
   aLayout->addWidget(myLabel);
   setLayout(aLayout);
+
+  std::string aStyleSheet = theData->getProperty(ATTR_STYLE_SHEET).c_str();
+  if (!aStyleSheet.empty())
+    myLabel->setStyleSheet(QString("QLabel {%1}").arg(aStyleSheet.c_str()));
 }
 
 ModuleBase_WidgetLabel::~ModuleBase_WidgetLabel()
@@ -37,3 +46,22 @@ QList<QWidget*> ModuleBase_WidgetLabel::getControls() const
   return QList<QWidget*>();
 }
 
+bool ModuleBase_WidgetLabel::restoreValueCustom()
+{
+  DataPtr aData = myFeature->data();
+  AttributeStringPtr aStrAttr = aData->string(attributeID());
+  if (aStrAttr.get()) {
+    std::string aMsg;
+    if (aStrAttr.get()) {
+      aMsg = aStrAttr->value();
+    }
+    myLabel->setText(aMsg.c_str());
+  }
+  return true;
+}
+
+bool ModuleBase_WidgetLabel::focusTo() 
+{ 
+  restoreValue();
+  return false; 
+}
index d2ab2d647b1a9f30bf07f7f4dd05d31be28976ce..4812f29b60adee8a41b051c92eae777d2f948836 100644 (file)
@@ -31,15 +31,12 @@ Q_OBJECT
   /// It returns false because this is an info widget
   virtual bool canAcceptFocus() const { return false; };
 
-  virtual bool restoreValueCustom()
-  {
-    return true;
-  }
+  virtual bool restoreValueCustom();
 
   virtual QList<QWidget*> getControls() const;
 
   /// This control doesn't accept focus
-  virtual bool focusTo() { return false; }
+  virtual bool focusTo();
 
 protected:
   /// Saves the internal parameters to the given feature
index 354666bc956fd698908f3a5c1b2fa8c65c782580..e30faa17a22d7cd11caf902d55ee014ab685fb14 100644 (file)
@@ -55,6 +55,7 @@ void SketchPlugin_Sketch::initAttributes()
   ModelAPI_Session::get()->validators()->registerNotObligatory(
     getKind(), SketchPlugin_SketchEntity::EXTERNAL_ID());
   data()->addAttribute(SketchPlugin_Sketch::SOLVER_ERROR(), ModelAPI_AttributeString::typeId());
+  data()->addAttribute(SketchPlugin_Sketch::SOLVER_DOF(), ModelAPI_AttributeString::typeId());
   ModelAPI_Session::get()->validators()->registerNotObligatory(
     getKind(), SketchPlugin_Sketch::SOLVER_ERROR());
 }
index d541415f3e9021fdf1eb408a711c35ac8a2d453e..a67069fe87a743026ed4f0af0b1c7173d48dd670 100644 (file)
@@ -68,6 +68,13 @@ class SketchPlugin_Sketch : public ModelAPI_CompositeFeature, public GeomAPI_ICu
     return MY_SOLVER_ERROR;
   }
 
+  /// Sketch solver error
+  inline static const std::string& SOLVER_DOF()
+  {
+    static const std::string MY_SOLVER_DOF("SolverDOF");
+    return MY_SOLVER_DOF;
+  }
+
   /// Returns the kind of a feature
   SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
   {
index d60744f516648573ae952c3cbbe210e95ddfc7e5..2839741b74160a3152ba5b5def0f752c307bc592 100644 (file)
@@ -13,7 +13,8 @@
         <sketch-start-label id="External" 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>
-        <error_label id="SolverError"/>
+        <label id="SolverDOF"/>
+        <label id="SolverError" styleSheet="color : red; font : bold"/>
         <validator id="SketchPlugin_SolverErrorValidator"/>
       </feature>
 
index c60de6f38b252b4ae427573cde1e6fc3ce58a356..1ee8c9e3dfc9c86fe4d24c662120e3864b451b81 100644 (file)
@@ -363,6 +363,7 @@ bool SketchSolver_Group::resolveConstraints()
     } catch (...) {
 //      Events_Error::send(SketchSolver_Error::SOLVESPACE_CRASH(), this);
       getWorkplane()->string(SketchPlugin_Sketch::SOLVER_ERROR())->setValue(SketchSolver_Error::SOLVESPACE_CRASH());
+      Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
       if (myPrevResult == STATUS_OK || myPrevResult == STATUS_UNKNOWN) {
         // the error message should be changed before sending the message
         sendMessage(EVENT_SOLVER_FAILED);
@@ -376,6 +377,7 @@ bool SketchSolver_Group::resolveConstraints()
       updateMultiConstraints(myConstraints);
       if (myPrevResult != STATUS_OK || myPrevResult == STATUS_UNKNOWN) {
         getWorkplane()->string(SketchPlugin_Sketch::SOLVER_ERROR())->setValue("");
+        Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
         // the error message should be changed before sending the message
         sendMessage(EVENT_SOLVER_REPAIRED, myConflictingConstraints);
         myConflictingConstraints.clear();
@@ -386,6 +388,7 @@ bool SketchSolver_Group::resolveConstraints()
       if (!myConstraints.empty()) {
         // the error message should be changed before sending the message
         getWorkplane()->string(SketchPlugin_Sketch::SOLVER_ERROR())->setValue(SketchSolver_Error::CONSTRAINTS());
+        Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
         if (myPrevResult != aResult || myPrevResult == STATUS_UNKNOWN) {
           // Obtain list of conflicting constraints
           std::set<ObjectPtr> aConflicting = myStorage->getConflictingConstraints(mySketchSolver);
index 2422426e3d23212fd7a27c09b8f2896f8a91b59b..f83e7fe48413165d7bceb71b032a8b0a8db36ad5 100644 (file)
@@ -48,6 +48,7 @@
 #include <list>
 #include <set>
 #include <memory>
+#include <cmath>
 
 static const Events_ID anUpdateEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
 
@@ -234,6 +235,7 @@ void SketchSolver_Manager::checkConflictingConstraints(const std::shared_ptr<Eve
             // reset error message on the sketch
             aGroup->getWorkplane()->string(SketchPlugin_Sketch::SOLVER_ERROR())->setValue(
                 SketchSolver_Error::CONSTRAINTS());
+            Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
             break;
           }
         }
@@ -566,12 +568,12 @@ void SketchSolver_Manager::degreesOfFreedom()
     if (aFound != myDoF.end() && aFound->second == aDoFIt->second)
       continue; // nothing is changed
     myDoF[aDoFIt->first] = aDoFIt->second;
-    // send a message
-    std::shared_ptr<ModelAPI_SolverFailedMessage> aMessage =
-        std::shared_ptr<ModelAPI_SolverFailedMessage>(
-        new ModelAPI_SolverFailedMessage(Events_Loop::eventByName(EVENT_SOLVER_REPAIRED)));
-    aMessage->dof(aDoFIt->second);
-    Events_Loop::loop()->send(aMessage);
+    // change attribute value
+    char aValue[10];
+    _itoa_s(aDoFIt->second, aValue, 10);
+    aDoFIt->first->data()->string(SketchPlugin_Sketch::SOLVER_DOF())->setValue(
+                                                             "DOF(degree of freedom) = "+ std::string(aValue));
+    Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
   }
 }
 
index 33fb1316fc5756aacaf3014fec2619ccb72d0f72..fbdb6379b393f11fddb917661ea703cfa44ac69f 100755 (executable)
@@ -497,6 +497,8 @@ void XGUI_Workshop::setPropertyPanel(ModuleBase_Operation* theOperation)
                         !aWidget->getDefaultValue().empty() &&
                         !aWidget->isComputedDefault();
     aWidget->setFeature(aFeature, isStoreValue, isUpdateFlushed);
+    if (!isStoreValue)
+      aWidget->restoreValue();
     aWidget->enableFocusProcessing();
   }
   ModuleBase_Tools::flushUpdated(aFeature);