Salome HOME
Issue #1502 Select sub-solids in viewer : Compsolid shape selection type should be...
[modules/shaper.git] / src / ModuleBase / ModuleBase_ModelWidget.cpp
index dc56812fc3bc3da50f36fa2dd1fc2cb4f1fa4eb3..ba49483764657583320424eb92c0e78903bb9ba9 100644 (file)
 
 #include <Config_Keywords.h>
 #include <Config_WidgetAPI.h>
+#include <Config_Translator.h>
 
 #include <Events_Loop.h>
 
 #include <QEvent>
 #include <QLabel>
 #include <QFocusEvent>
+#include <QTextCodec>
 
 //#define DEBUG_VALUE_STATE
 
+//#define DEBUG_WIDGET_INSTANCE
+
 ModuleBase_ModelWidget::ModuleBase_ModelWidget(QWidget* theParent,
                                                const Config_WidgetAPI* theData)
     : QWidget(theParent),
       myIsEditing(false),
       myState(Stored),
       myIsValueStateBlocked(false),
+      myFlushUpdateBlocked(false),
       myWidgetValidator(0)
 {
+#ifdef DEBUG_WIDGET_INSTANCE
+  qDebug("ModuleBase_ModelWidget::ModuleBase_ModelWidget");
+#endif
+
   myIsInternal = theData->getBooleanAttribute(ATTR_INTERNAL, false);
 
   myDefaultValue = theData->getProperty(ATTR_DEFAULT);
@@ -46,6 +55,13 @@ ModuleBase_ModelWidget::ModuleBase_ModelWidget(QWidget* theParent,
   connect(this, SIGNAL(valuesModified()), this, SLOT(onWidgetValuesModified()));
 }
 
+ModuleBase_ModelWidget::~ModuleBase_ModelWidget()
+{
+#ifdef DEBUG_WIDGET_INSTANCE
+  qDebug("ModuleBase_ModelWidget::~ModuleBase_ModelWidget");
+#endif
+}
+
 bool ModuleBase_ModelWidget::reset()
 {
   bool aResult = resetCustom();
@@ -60,6 +76,12 @@ bool ModuleBase_ModelWidget::isInitialized(ObjectPtr theObject) const
   return theObject->data()->attribute(attributeID())->isInitialized();
 }
 
+void ModuleBase_ModelWidget::processValueState()
+{
+  if (myState == ModifiedInPP || myState == ModifiedInViewer)
+    storeValue();
+}
+
 QString ModuleBase_ModelWidget::getValueStateError() const
 {
   QString anError = "";
@@ -86,7 +108,7 @@ QString ModuleBase_ModelWidget::getValueStateError() const
   return anError;
 }
 
-QString ModuleBase_ModelWidget::getError() const
+QString ModuleBase_ModelWidget::getError(const bool theValueStateChecked) const
 {
   QString anError;
 
@@ -109,12 +131,26 @@ QString ModuleBase_ModelWidget::getError() const
   }
 
   anError = QString::fromStdString(anErrorMsg);
-  if (anError.isEmpty())
+  if (anError.isEmpty() && theValueStateChecked)
     anError = getValueStateError();
 
+  anError = translateString(anError);
   return anError;
 }
 
+
+QString ModuleBase_ModelWidget::translateString(const QString& theMsg) const
+{
+  if (!theMsg.isEmpty()) {
+    std::string aContext = feature()->getKind();
+    std::string aStr = Config_Translator::translate(aContext, theMsg.toStdString().c_str());
+    std::string aCodec = Config_Translator::codec(aContext);
+    return QTextCodec::codecForName(aCodec.c_str())->toUnicode(aStr.c_str());
+  }
+  return theMsg;
+}
+
+
 void ModuleBase_ModelWidget::enableFocusProcessing()
 {
   QList<QWidget*> aMyControls = getControls();
@@ -138,15 +174,23 @@ void ModuleBase_ModelWidget::setHighlighted(bool isHighlighted)
   }
 }
 
-void ModuleBase_ModelWidget::setFeature(const FeaturePtr& theFeature, const bool theToStoreValue)
+void ModuleBase_ModelWidget::setFeature(const FeaturePtr& theFeature, const bool theToStoreValue,
+                                        const bool isUpdateFlushed)
 {
+  /// it is possible to give this flag as parameter in storeValue/storeCustomValue
+  /// after debug, it may be corrected
+  myFlushUpdateBlocked = !isUpdateFlushed;
   myFeature = theFeature;
   if (theToStoreValue)
     storeValue();
+  myFlushUpdateBlocked = false;
 }
 
 bool ModuleBase_ModelWidget::focusTo()
 {
+#ifdef DEBUG_WIDGET_INSTANCE
+  qDebug("ModuleBase_ModelWidget::focusTo");
+#endif
   QList<QWidget*> aControls = getControls();
   QList<QWidget*>::const_iterator anIt = aControls.begin(), aLast = aControls.end();
   bool isFocusAccepted = false;
@@ -162,6 +206,9 @@ bool ModuleBase_ModelWidget::focusTo()
 
 void ModuleBase_ModelWidget::activate()
 {
+#ifdef DEBUG_WIDGET_INSTANCE
+  qDebug("ModuleBase_ModelWidget::activate");
+#endif
   // the control value is stored to the mode by the focus in on the widget
   // we need the value is initialized in order to enable the apply button in the property panel.
   // It should happens in the creation mode only because all fields are filled in the edition mode
@@ -179,11 +226,11 @@ void ModuleBase_ModelWidget::activate()
 
 void ModuleBase_ModelWidget::deactivate()
 {
+#ifdef DEBUG_WIDGET_INSTANCE
+  qDebug("ModuleBase_ModelWidget::deactivate");
+#endif
   myIsValueStateBlocked = false;
-  if (myState == ModifiedInPP || myState == ModifiedInViewer)
-    storeValue();
   myState = Stored;
-
   if (myWidgetValidator)
     myWidgetValidator->activateFilters(false);
 }
@@ -285,18 +332,23 @@ bool ModuleBase_ModelWidget::restoreValue()
   return isDone;
 }
 
-void ModuleBase_ModelWidget::updateObject(ObjectPtr theObj)
+void ModuleBase_ModelWidget::updateObject(ObjectPtr theObject)
 {
-  blockUpdateViewer(true);
-
-  Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
-
-  blockUpdateViewer(false);
+  if (!myFlushUpdateBlocked) {
+#ifdef DEBUG_WIDGET_INSTANCE
+    qDebug("ModuleBase_ModelWidget::updateObject");
+#endif
+    ModuleBase_Tools::flushUpdated(theObject);
+    emit objectUpdated();
+  }
 }
 
 void ModuleBase_ModelWidget::moveObject(ObjectPtr theObj)
 {
   //blockUpdateViewer(true);
+#ifdef DEBUG_WIDGET_INSTANCE
+  qDebug("ModuleBase_ModelWidget::moveObject");
+#endif
 
   static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_MOVED);
   ModelAPI_EventCreator::get()->sendUpdated(theObj, anEvent);
@@ -360,23 +412,3 @@ void ModuleBase_ModelWidget::onWidgetValuesModified()
 {
   setValueState(ModifiedInPP);
 }
-
-//**************************************************************
-void ModuleBase_ModelWidget::blockUpdateViewer(const bool theValue)
-{
-  // the viewer update should be blocked in order to avoid the temporary feature content
-  // when the solver processes the feature, the redisplay message can be flushed
-  // what caused the display in the viewer preliminary states of object
-  // e.g. fillet feature, angle value change
-  std::shared_ptr<Events_Message> aMsg;
-  if (theValue) {
-    aMsg = std::shared_ptr<Events_Message>(
-        new Events_Message(Events_Loop::eventByName(EVENT_UPDATE_VIEWER_BLOCKED)));
-  }
-  else {
-    // the viewer update should be unblocked
-    aMsg = std::shared_ptr<Events_Message>(
-        new Events_Message(Events_Loop::eventByName(EVENT_UPDATE_VIEWER_UNBLOCKED)));
-  }
-  Events_Loop::loop()->send(aMsg);
-}