Salome HOME
Updated copyright comment
[modules/shaper.git] / src / ModuleBase / ModuleBase_ModelWidget.cpp
index fcba4e0c4b194ca241bfa5dfdd2eee8e9e8897f1..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"
 //#define DEBUG_WIDGET_INSTANCE
 //#define DEBUG_ENABLE_SKETCH_INPUT_FIELDS
 
+//**************************************************************
 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");
@@ -65,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;
@@ -85,6 +88,7 @@ ModuleBase_ModelWidget::ModuleBase_ModelWidget(QWidget* theParent,
   connect(this, SIGNAL(valuesModified()), this, SLOT(onWidgetValuesModified()));
 }
 
+//**************************************************************
 ModuleBase_ModelWidget::~ModuleBase_ModelWidget()
 {
 #ifdef DEBUG_WIDGET_INSTANCE
@@ -92,6 +96,7 @@ ModuleBase_ModelWidget::~ModuleBase_ModelWidget()
 #endif
 }
 
+//**************************************************************
 bool ModuleBase_ModelWidget::reset()
 {
   bool aResult = resetCustom();
@@ -101,11 +106,29 @@ bool ModuleBase_ModelWidget::reset()
   return aResult;
 }
 
+//**************************************************************
 bool ModuleBase_ModelWidget::isInitialized(ObjectPtr theObject) const
 {
   return theObject->data()->attribute(attributeID())->isInitialized();
 }
 
+//**************************************************************
+void ModuleBase_ModelWidget::selectionModes(int& theModuleSelectionModes, QIntList& theModes)
+{
+  theModuleSelectionModes = -1;
+  if (myWidgetValidator)
+    myWidgetValidator->selectionModes(theModuleSelectionModes, theModes);
+}
+
+//**************************************************************
+void ModuleBase_ModelWidget::selectionFilters(QIntList& theModuleSelectionFilters,
+                                              SelectMgr_ListOfFilter& theSelectionFilters)
+{
+  if (myWidgetValidator)
+    myWidgetValidator->selectionFilters(theModuleSelectionFilters, theSelectionFilters);
+}
+
+//**************************************************************
 bool ModuleBase_ModelWidget::isValueEnabled() const
 {
   bool anEnabled = true;
@@ -124,15 +147,18 @@ bool ModuleBase_ModelWidget::isValueEnabled() const
   return anEnabled;
 }
 
+//**************************************************************
 void ModuleBase_ModelWidget::processValueState()
 {
   if (myState == ModifiedInPP || myState == ModifiedInViewer)
     storeValue();
 }
 
+//**************************************************************
 Events_InfoMessage ModuleBase_ModelWidget::getValueStateError() const
 {
   Events_InfoMessage aMessage;
+  aMessage.setContext(context());
 
   ModuleBase_ModelWidget::ValueState aState = getValueState();
   if (aState != ModuleBase_ModelWidget::Stored) {
@@ -157,6 +183,7 @@ Events_InfoMessage ModuleBase_ModelWidget::getValueStateError() const
   return aMessage;
 }
 
+//**************************************************************
 QString ModuleBase_ModelWidget::getError(const bool theValueStateChecked) const
 {
   QString anError;
@@ -164,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())
@@ -179,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);
     }
   }
 
@@ -194,6 +220,7 @@ QString ModuleBase_ModelWidget::getError(const bool theValueStateChecked) const
   return anError;
 }
 
+//**************************************************************
 void ModuleBase_ModelWidget::enableFocusProcessing()
 {
   QList<QWidget*> aMyControls = getControls();
@@ -203,6 +230,7 @@ void ModuleBase_ModelWidget::enableFocusProcessing()
   }
 }
 
+//**************************************************************
 void ModuleBase_ModelWidget::setHighlighted(bool isHighlighted)
 {
   QList<QWidget*> aWidgetList = getControls();
@@ -217,6 +245,7 @@ void ModuleBase_ModelWidget::setHighlighted(bool isHighlighted)
   }
 }
 
+//**************************************************************
 void ModuleBase_ModelWidget::setFeature(const FeaturePtr& theFeature, const bool theToStoreValue,
                                         const bool isUpdateFlushed)
 {
@@ -234,6 +263,7 @@ void ModuleBase_ModelWidget::setFeature(const FeaturePtr& theFeature, const bool
   myFlushUpdateBlocked = false;
 }
 
+//**************************************************************
 bool ModuleBase_ModelWidget::focusTo()
 {
 #ifdef DEBUG_WIDGET_INSTANCE
@@ -252,6 +282,7 @@ bool ModuleBase_ModelWidget::focusTo()
   return isFocusAccepted;
 }
 
+//**************************************************************
 void ModuleBase_ModelWidget::activate()
 {
 #ifdef DEBUG_WIDGET_INSTANCE
@@ -265,13 +296,10 @@ void ModuleBase_ModelWidget::activate()
     if (anAttribute.get() != NULL && !anAttribute->isInitialized())
       initializeValueByActivate();
   }
-
-  if (myWidgetValidator)
-    myWidgetValidator->activateFilters(true);
-
   activateCustom();
 }
 
+//**************************************************************
 void ModuleBase_ModelWidget::deactivate()
 {
 #ifdef DEBUG_WIDGET_INSTANCE
@@ -280,9 +308,10 @@ void ModuleBase_ModelWidget::deactivate()
   myIsValueStateBlocked = false;
   myState = Stored;
   if (myWidgetValidator)
-    myWidgetValidator->activateFilters(false);
+    myWidgetValidator->clearValidatedCash();
 }
 
+//**************************************************************
 void ModuleBase_ModelWidget::initializeValueByActivate()
 {
   if (isComputedDefault()) {
@@ -295,6 +324,7 @@ void ModuleBase_ModelWidget::initializeValueByActivate()
   }
 }
 
+//**************************************************************
 QWidget* ModuleBase_ModelWidget::getControlAcceptingFocus(const bool isFirst)
 {
   QWidget* aControl = 0;
@@ -317,11 +347,13 @@ QWidget* ModuleBase_ModelWidget::getControlAcceptingFocus(const bool isFirst)
   return aControl;
 }
 
+//**************************************************************
 void ModuleBase_ModelWidget::setDefaultValue(const std::string& theValue)
 {
   myDefaultValue = theValue;
 }
 
+//**************************************************************
 bool ModuleBase_ModelWidget::storeValue()
 {
   setValueState(Stored);
@@ -348,6 +380,8 @@ bool ModuleBase_ModelWidget::storeValue()
   return isDone;
 }
 #ifdef DEBUG_VALUE_STATE
+
+//**************************************************************
 std::string getDebugInfo(const ModuleBase_ModelWidget::ValueState& theState)
 {
   std::string anInfo;
@@ -360,8 +394,9 @@ std::string getDebugInfo(const ModuleBase_ModelWidget::ValueState& theState)
   }
   return anInfo;
 }
-
 #endif
+
+//**************************************************************
 ModuleBase_ModelWidget::ValueState ModuleBase_ModelWidget::setValueState
                                          (const ModuleBase_ModelWidget::ValueState& theState)
 {
@@ -379,6 +414,7 @@ ModuleBase_ModelWidget::ValueState ModuleBase_ModelWidget::setValueState
   return aState;
 }
 
+//**************************************************************
 bool ModuleBase_ModelWidget::blockValueState(const bool theBlocked)
 {
   bool isBlocked = myIsValueStateBlocked;
@@ -386,8 +422,15 @@ bool ModuleBase_ModelWidget::blockValueState(const bool theBlocked)
   return isBlocked;
 }
 
+//**************************************************************
 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();
@@ -395,36 +438,72 @@ bool ModuleBase_ModelWidget::restoreValue()
   return isDone;
 }
 
+//**************************************************************
 void ModuleBase_ModelWidget::updateObject(ObjectPtr theObject)
 {
   if (!myFlushUpdateBlocked) {
 #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();
   }
 }
 
-void ModuleBase_ModelWidget::moveObject(ObjectPtr theObj)
+//**************************************************************
+bool ModuleBase_ModelWidget::canProcessAction(ModuleBase_ActionType theActionType,
+                                              bool& isActionEnabled)
 {
-  //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);
-  Events_Loop::loop()->flush(anEvent);
+  isActionEnabled = false;
+  switch (theActionType) {
+    case ActionEnter: return false;
+    case ActionEscape: return false;
+    case ActionDelete: return true;
+    case ActionSelection: return true;
+    case ActionUndo:
+    case ActionRedo:
+    default:
+      return false;
+  }
+}
 
-  //blockUpdateViewer(false);
+//**************************************************************
+bool ModuleBase_ModelWidget::processAction(ModuleBase_ActionType theActionType,
+                                           const ActionParamPtr& theParam)
+{
+  switch (theActionType) {
+    case ActionEnter:
+      return processEnter();
+    case ActionEscape:
+      return processEscape();
+    case ActionDelete:
+      return processDelete();
+    case ActionSelection:
+      processSelection();
+    case ActionUndo:
+    case ActionRedo:
+    default:
+      return false;
+  }
 }
 
+//**************************************************************
 bool ModuleBase_ModelWidget::processEnter()
 {
   return false;
 }
 
+//**************************************************************
+bool ModuleBase_ModelWidget::processEscape()
+{
+  return false;
+}
+
+//**************************************************************
 bool ModuleBase_ModelWidget::processDelete()
 {
   // we consider that model objects eats delete key in order to
@@ -432,6 +511,13 @@ bool ModuleBase_ModelWidget::processDelete()
   return true;
 }
 
+//**************************************************************
+bool ModuleBase_ModelWidget::processSelection()
+{
+  return false;
+}
+
+//**************************************************************
 bool ModuleBase_ModelWidget::eventFilter(QObject* theObject, QEvent *theEvent)
 {
   QWidget* aWidget = qobject_cast<QWidget*>(theObject);