Salome HOME
Updated copyright comment
[modules/shaper.git] / src / ModuleBase / ModuleBase_ModelWidget.cpp
index 097f5175d31c949ea1e2ff15f800066dd53179be..d70c6572a49203eff321c0f98dcabd31f91d7c89 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2017  CEA/DEN, EDF R&D
+// Copyright (C) 2014-2024  CEA, EDF
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 //
 // 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
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
-// See http://www.salome-platform.org/ or
-// email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
 #include "ModuleBase_ModelWidget.h"
 
 //**************************************************************
 ModuleBase_ModelWidget::ModuleBase_ModelWidget(QWidget* theParent,
-                                               const Config_WidgetAPI* theData)
-    : QWidget(theParent),
-      myIsEditing(false),
-      myState(Stored),
-      myIsValueStateBlocked(false),
-      myFlushUpdateBlocked(false),
-      myWidgetValidator(0)
+  const Config_WidgetAPI* theData)
+  : QWidget(theParent),
+  myWidgetValidator(0),
+  myState(Stored),
+  myIsEditing(false),
+  myIsValueStateBlocked(false),
+  myFlushUpdateBlocked(false)
 {
 #ifdef DEBUG_WIDGET_INSTANCE
   qDebug("ModuleBase_ModelWidget::ModuleBase_ModelWidget");
@@ -66,9 +65,12 @@ ModuleBase_ModelWidget::ModuleBase_ModelWidget(QWidget* theParent,
   myFeatureId = theData->featureId();
 
   myIsInternal = theData->getBooleanAttribute(ATTR_INTERNAL, false);
+  myUseExternalParts = theData->getBooleanAttribute("allow_parts_content", false);
 
   myIsModifiedInEdit = theData->getProperty(ATTR_MODIFIED_IN_EDIT);
 
+  myUpdateVisualAttributes = theData->getBooleanAttribute(ATTR_VISUAL_CHANGED, false);
+
   myDefaultValue = theData->getProperty(ATTR_DEFAULT);
   myUseReset = theData->getBooleanAttribute(ATTR_USE_RESET, true);
   myIsComputedDefault = theData->getProperty(ATTR_DEFAULT) == DOUBLE_WDG_DEFAULT_COMPUTED;
@@ -119,10 +121,9 @@ void ModuleBase_ModelWidget::selectionModes(int& theModuleSelectionModes, QIntLi
 }
 
 //**************************************************************
-void ModuleBase_ModelWidget::selectionFilters(int& theModuleSelectionFilters,
+void ModuleBase_ModelWidget::selectionFilters(QIntList& theModuleSelectionFilters,
                                               SelectMgr_ListOfFilter& theSelectionFilters)
 {
-  theModuleSelectionFilters = -1;
   if (myWidgetValidator)
     myWidgetValidator->selectionFilters(theModuleSelectionFilters, theSelectionFilters);
 }
@@ -157,6 +158,7 @@ void ModuleBase_ModelWidget::processValueState()
 Events_InfoMessage ModuleBase_ModelWidget::getValueStateError() const
 {
   Events_InfoMessage aMessage;
+  aMessage.setContext(context());
 
   ModuleBase_ModelWidget::ValueState aState = getValueState();
   if (aState != ModuleBase_ModelWidget::Stored) {
@@ -189,7 +191,6 @@ QString ModuleBase_ModelWidget::getError(const bool theValueStateChecked) const
   if (!feature().get())
     return anError;
 
-  std::string aFeatureID = feature()->getKind();
   std::string anAttributeID = attributeID();
   AttributePtr anAttribute = feature()->attribute(anAttributeID);
   if (!anAttribute.get())
@@ -204,7 +205,7 @@ QString ModuleBase_ModelWidget::getError(const bool theValueStateChecked) const
       anErrorMsg = "Unknown error.";
 
     if (anErrorMsg.context().empty()) {
-      anErrorMsg.setContext(aFeatureID + ":" + anAttributeID + ":" + aValidatorID);
+      anErrorMsg.setContext(context() + ":" + aValidatorID);
     }
   }
 
@@ -424,6 +425,12 @@ bool ModuleBase_ModelWidget::blockValueState(const bool theBlocked)
 //**************************************************************
 bool ModuleBase_ModelWidget::restoreValue()
 {
+  if (!isEnabled()) {
+    // This code works in inspection panel
+    ModelAPI_ValidatorsFactory* aValidators = ModelAPI_Session::get()->validators();
+    if (!aValidators->isCase(myFeature, attributeID()))
+      return false; // if it is not an active case for the widget
+  }
   emit beforeValuesRestored();
   bool isDone = restoreValueCustom();
   emit afterValuesRestored();
@@ -438,6 +445,10 @@ void ModuleBase_ModelWidget::updateObject(ObjectPtr theObject)
 #ifdef DEBUG_WIDGET_INSTANCE
     qDebug("ModuleBase_ModelWidget::updateObject");
 #endif
+    if (myFeature.get() && myUpdateVisualAttributes) {
+      static const Events_ID anEvent = Events_Loop::eventByName(EVENT_VISUAL_ATTRIBUTES);
+      ModelAPI_EventCreator::get()->sendUpdated(myFeature, anEvent);
+    }
     ModuleBase_Tools::flushUpdated(theObject);
     emit objectUpdated();
   }