Salome HOME
Update copyrights
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetFeatureSelector.cpp
index 74da1b3af54c2d36eaad54e170b7c8be3adfa1e2..c9685bbf0c1d6de5fe22c92fbf233e234cf1b900 100644 (file)
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D\r
-\r
-// File:        ModuleBase_WidgetFeatureSelector.cpp\r
-// Created:     5 Sep 2016\r
-// Author:      Natalia Ermolaeva\r
-\r
-#include <ModuleBase_WidgetFeatureSelector.h>\r
-\r
-#include <ModuleBase_Definitions.h>\r
-#include <ModuleBase_ISelection.h>\r
-#include <ModuleBase_IWorkshop.h>\r
-#include <ModuleBase_IViewer.h>\r
-#include <ModuleBase_Tools.h>\r
-#include <ModuleBase_FilterFactory.h>\r
-#include <ModuleBase_Filter.h>\r
-#include <ModuleBase_IModule.h>\r
-#include <ModuleBase_ViewerPrs.h>\r
-#include <ModuleBase_IconFactory.h>\r
-#include <ModuleBase_ResultPrs.h>\r
-\r
-#include <Config_WidgetAPI.h>\r
-#include <Events_Loop.h>\r
-#include <Events_Message.h>\r
-#include <GeomAPI_Interface.h>\r
-#include <GeomAPI_Shape.h>\r
-\r
-#include <ModelAPI_Data.h>\r
-#include <ModelAPI_Document.h>\r
-#include <ModelAPI_Events.h>\r
-#include <ModelAPI_Feature.h>\r
-#include <ModelAPI_Result.h>\r
-#include <ModelAPI_Session.h>\r
-\r
-#include <Config_WidgetAPI.h>\r
-\r
-#include <GeomAPI_Shape.h>\r
-\r
-#include <QWidget>\r
-#include <QLayout>\r
-#include <QLabel>\r
-#include <QLineEdit>\r
-#include <QToolButton>\r
-#include <QString>\r
-#include <QEvent>\r
-#include <QApplication>\r
-#include <QFormLayout>\r
-\r
-#include <memory>\r
-\r
-#include <list>\r
-#include <string>\r
-\r
-\r
-ModuleBase_WidgetFeatureSelector::ModuleBase_WidgetFeatureSelector(QWidget* theParent,\r
-                                                     ModuleBase_IWorkshop* theWorkshop,\r
-                                                     const Config_WidgetAPI* theData)\r
-: ModuleBase_WidgetValidated(theParent, theWorkshop, theData)\r
-{\r
-  QFormLayout* aLayout = new QFormLayout(this);\r
-  ModuleBase_Tools::adjustMargins(aLayout);\r
-\r
-  QString aLabelText = QString::fromStdString(theData->widgetLabel());\r
-  QString aLabelIcon = QString::fromStdString(theData->widgetIcon());\r
-  myLabel = new QLabel(aLabelText, this);\r
-  if (!aLabelIcon.isEmpty())\r
-    myLabel->setPixmap(ModuleBase_IconFactory::loadPixmap(aLabelIcon));\r
-\r
-\r
-  QString aToolTip = QString::fromStdString(theData->widgetTooltip());\r
-  myTextLine = new QLineEdit(this);\r
-  QString anObjName = QString::fromStdString(attributeID());\r
-  myTextLine->setObjectName(anObjName);\r
-  myTextLine->setReadOnly(true);\r
-  myTextLine->setToolTip(aToolTip);\r
-  myTextLine->installEventFilter(this);\r
-\r
-  aLayout->addRow(myLabel, myTextLine);\r
-  myLabel->setToolTip(aToolTip);\r
-}\r
-\r
-//********************************************************************\r
-ModuleBase_WidgetFeatureSelector::~ModuleBase_WidgetFeatureSelector()\r
-{\r
-}\r
-\r
+// 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_WidgetFeatureSelector.h>
+
+#include <ModuleBase_Definitions.h>
+#include <ModuleBase_ISelection.h>
+#include <ModuleBase_IWorkshop.h>
+#include <ModuleBase_IViewer.h>
+#include <ModuleBase_Tools.h>
+#include <ModuleBase_Filter.h>
+#include <ModuleBase_IModule.h>
+#include <ModuleBase_ViewerPrs.h>
+#include <ModuleBase_IconFactory.h>
+#include <ModuleBase_ResultPrs.h>
+
+#include <Config_WidgetAPI.h>
+#include <Events_Loop.h>
+#include <Events_Message.h>
+#include <GeomAPI_Interface.h>
+#include <GeomAPI_Shape.h>
+
+#include <ModelAPI_Data.h>
+#include <ModelAPI_Document.h>
+#include <ModelAPI_Events.h>
+#include <ModelAPI_Feature.h>
+#include <ModelAPI_Result.h>
+#include <ModelAPI_Session.h>
+
+#include <Config_WidgetAPI.h>
+
+#include <GeomAPI_Shape.h>
+
+#include <QWidget>
+#include <QLayout>
+#include <QLabel>
+#include <QLineEdit>
+#include <QToolButton>
+#include <QString>
+#include <QEvent>
+#include <QApplication>
+#include <QFormLayout>
+
+#include <memory>
+
+#include <list>
+#include <string>
+
+
+ModuleBase_WidgetFeatureSelector::ModuleBase_WidgetFeatureSelector(QWidget* theParent,
+                                                     ModuleBase_IWorkshop* theWorkshop,
+                                                     const Config_WidgetAPI* theData)
+: ModuleBase_WidgetValidated(theParent, theWorkshop, theData)
+{
+  QFormLayout* aLayout = new QFormLayout(this);
+  ModuleBase_Tools::adjustMargins(aLayout);
+
+  QString aLabelText = translate(theData->widgetLabel());
+  QString aLabelIcon = QString::fromStdString(theData->widgetIcon());
+  myLabel = new QLabel(aLabelText, this);
+  if (!aLabelIcon.isEmpty())
+    myLabel->setPixmap(ModuleBase_IconFactory::loadPixmap(aLabelIcon));
+
+
+  QString aToolTip = translate(theData->widgetTooltip());
+  myTextLine = new QLineEdit(this);
+  QString anObjName = QString::fromStdString(attributeID());
+  myTextLine->setObjectName(anObjName);
+  myTextLine->setReadOnly(true);
+  myTextLine->setToolTip(aToolTip);
+  myTextLine->installEventFilter(this);
+
+  aLayout->addRow(myLabel, myTextLine);
+  myLabel->setToolTip(aToolTip);
+}
+
+//********************************************************************
+ModuleBase_WidgetFeatureSelector::~ModuleBase_WidgetFeatureSelector()
+{
+}
+
 //********************************************************************
 bool ModuleBase_WidgetFeatureSelector::setSelectionCustom(const ModuleBase_ViewerPrsPtr& thePrs)
 {
@@ -97,128 +109,120 @@ bool ModuleBase_WidgetFeatureSelector::setSelectionCustom(const ModuleBase_Viewe
 }
 
 //********************************************************************
-void ModuleBase_WidgetFeatureSelector::deactivate()
+void ModuleBase_WidgetFeatureSelector::selectionModes(int& theModuleSelectionModes,
+                                                      QIntList& theModes)
 {
-  ModuleBase_ModelWidget::deactivate();
-  disconnect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
-  activateFilters(false);\r
-  myWorkshop->deactivateSubShapesSelection();
-}\r
-\r
+  theModuleSelectionModes = -1;
+  theModes.push_back(ModuleBase_ResultPrs::Sel_Result);
+}
+
 //********************************************************************
 void ModuleBase_WidgetFeatureSelector::activateCustom()
 {
-  connect(myWorkshop, SIGNAL(selectionChanged()), this,
-          SLOT(onSelectionChanged()), Qt::UniqueConnection);
-  
-  activateFilters(true);\r
-
-  QIntList aShapeTypes;
-  aShapeTypes.push_back(ModuleBase_ResultPrs::Sel_Result);
-  myWorkshop->activateSubShapesSelection(aShapeTypes);
-
   // Restore selection in the viewer by the attribute selection list
   // it should be postponed to have current widget as active to validate restored selection
   //static Events_ID anEvent = Events_Loop::eventByName(EVENT_UPDATE_BY_WIDGET_SELECTION);
   //ModelAPI_EventCreator::get()->sendUpdated(myFeature, anEvent);
 }
-\r
-//********************************************************************\r
-bool ModuleBase_WidgetFeatureSelector::storeValueCustom()\r
-{\r
-  // the value is stored on the selection changed signal processing \r
-  return true;\r
-}\r
-\r
-//********************************************************************\r
-bool ModuleBase_WidgetFeatureSelector::setSelection(QList<ModuleBase_ViewerPrsPtr>& theValues,\r
-                                                  const bool theToValidate)\r
-{\r
-  if (theValues.empty()) {\r
-    // In order to make reselection possible, set empty object and shape should be done\r
-    setSelectionCustom(std::shared_ptr<ModuleBase_ViewerPrs>(new ModuleBase_ViewerPrs(\r
-                                                  ObjectPtr(), GeomShapePtr(), NULL)));\r
-    return false;\r
-  }\r
-  // it removes the processed value from the parameters list\r
-  ModuleBase_ViewerPrsPtr aValue = theValues.takeFirst();\r
-  bool isDone = false;\r
-\r
-  if (!theToValidate || isValidSelection(aValue))\r
-    isDone = setSelectionCustom(aValue);\r
-\r
-  return isDone;\r
-}\r
-\r
-//********************************************************************\r
-bool ModuleBase_WidgetFeatureSelector::restoreValueCustom()\r
-{\r
-  bool isBlocked = this->blockSignals(true);\r
-  updateSelectionName();\r
-  this->blockSignals(isBlocked);\r
-\r
-  return true;\r
-}\r
-\r
-//********************************************************************\r
-QList<QWidget*> ModuleBase_WidgetFeatureSelector::getControls() const\r
-{\r
-  QList<QWidget*> aControls;\r
-  aControls.append(myTextLine);\r
-  return aControls;\r
-}\r
-\r
-void ModuleBase_WidgetFeatureSelector::updateFocus()\r
-{\r
-  emit focusOutWidget(this);\r
-}\r
-\r
-//********************************************************************\r
-void ModuleBase_WidgetFeatureSelector::updateSelectionName()\r
-{\r
-  DataPtr aData = myFeature->data();\r
-  if (!aData->isValid())\r
-    return;\r
-\r
-  ObjectPtr anObject = ModuleBase_Tools::getObject(myFeature->attribute(attributeID()));\r
-  if (anObject.get() != NULL) {\r
-    std::string aName = anObject->data()->name();\r
-    myTextLine->setText(QString::fromStdString(aName));\r
-  } else {\r
-    myTextLine->clear();\r
-  }\r
-}\r
-\r
-//********************************************************************\r
-bool ModuleBase_WidgetFeatureSelector::isValidInFilters(const ModuleBase_ViewerPrsPtr& thePrs)\r
-{\r
-  bool aValid = false;\r
-\r
-  ObjectPtr anObject = thePrs->object();\r
-  FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(anObject);\r
-  aValid = aFeature.get();\r
-  if (!aValid) {\r
-    ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);\r
-    aValid = aResult.get() && aResult->shape() == thePrs->shape();\r
-  }\r
-\r
-  return aValid;\r
-}\r
-\r
-//********************************************************************\r
-void ModuleBase_WidgetFeatureSelector::onSelectionChanged()
+
+//********************************************************************
+bool ModuleBase_WidgetFeatureSelector::storeValueCustom()
+{
+  // the value is stored on the selection changed signal processing
+  return true;
+}
+
+//********************************************************************
+bool ModuleBase_WidgetFeatureSelector::setSelection(QList<ModuleBase_ViewerPrsPtr>& theValues,
+                                                  const bool theToValidate)
+{
+  if (theValues.empty()) {
+    // In order to make reselection possible, set empty object and shape should be done
+    setSelectionCustom(std::shared_ptr<ModuleBase_ViewerPrs>(new ModuleBase_ViewerPrs(
+                                                  ObjectPtr(), GeomShapePtr(), NULL)));
+    return false;
+  }
+  // it removes the processed value from the parameters list
+  ModuleBase_ViewerPrsPtr aValue = theValues.takeFirst();
+  bool isDone = false;
+
+  if (!theToValidate || isValidSelection(aValue))
+    isDone = setSelectionCustom(aValue);
+
+  return isDone;
+}
+
+//********************************************************************
+bool ModuleBase_WidgetFeatureSelector::restoreValueCustom()
+{
+  bool isBlocked = this->blockSignals(true);
+  updateSelectionName();
+  this->blockSignals(isBlocked);
+
+  return true;
+}
+
+//********************************************************************
+QList<QWidget*> ModuleBase_WidgetFeatureSelector::getControls() const
+{
+  QList<QWidget*> aControls;
+  aControls.append(myTextLine);
+  return aControls;
+}
+
+void ModuleBase_WidgetFeatureSelector::updateFocus()
 {
-  QList<ModuleBase_ViewerPrsPtr> aSelected = myWorkshop->selection()->getSelected(\r
-                                                              ModuleBase_ISelection::AllControls);\r
+  emit focusOutWidget(this);
+}
+
+//********************************************************************
+void ModuleBase_WidgetFeatureSelector::updateSelectionName()
+{
+  DataPtr aData = myFeature->data();
+  if (!aData->isValid())
+    return;
+
+  ObjectPtr anObject = ModuleBase_Tools::getObject(myFeature->attribute(attributeID()));
+  if (anObject.get() != NULL) {
+    std::string aName = anObject->data()->name();
+    myTextLine->setText(QString::fromStdString(aName));
+  } else {
+    myTextLine->clear();
+  }
+}
+
+//********************************************************************
+bool ModuleBase_WidgetFeatureSelector::isValidInFilters(const ModuleBase_ViewerPrsPtr& thePrs)
+{
+  bool aValid = false;
+
+  ObjectPtr anObject = thePrs->object();
+  FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(anObject);
+  aValid = aFeature.get();
+  if (!aValid) {
+    ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
+    aValid = aResult.get() && aResult->shape() == thePrs->shape();
+  }
+
+  return aValid;
+}
+
+//********************************************************************
+bool ModuleBase_WidgetFeatureSelector::processSelection()
+{
+  QList<ModuleBase_ViewerPrsPtr> aSelected = myWorkshop->selection()->getSelected(
+                                                              ModuleBase_ISelection::AllControls);
 
   bool isDone = setSelection(aSelected, true/*false*/);
   updateOnSelectionChanged(isDone);
+
+  return isDone;
 }
 
 //********************************************************************
 void ModuleBase_WidgetFeatureSelector::updateOnSelectionChanged(const bool theDone)
 {
-  // "false" flag should be used here, it connects to the #26658 OCC bug, when the user click in 
+  // "false" flag should be used here, it connects to the #26658 OCC bug, when the user click in
   // the same place repeatedly without mouse moved. In the case validation by filters is not
   // perfromed, so an invalid object is selected. E.g. distance constraint, selection of a point.
   // the 3rd click in the same point allow using this point.