Salome HOME
Merge remote-tracking branch 'remotes/origin/occ/19115' into fixes_for_950
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetShapeSelector.cpp
index 1bcedc636d2b0f5b1aab86c694cf2c79e844104c..89c506e8616a6ab567b72501212f57e68f76ff70 100644 (file)
@@ -1,8 +1,21 @@
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-// File:        ModuleBase_WidgetShapeSelector.cpp
-// Created:     2 June 2014
-// Author:      Vitaly Smetannikov
+// Copyright (C) 2014-2020  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_WidgetShapeSelector.h>
 #include <ModuleBase_Definitions.h>
 #include <ModuleBase_IWorkshop.h>
 #include <ModuleBase_IViewer.h>
 #include <ModuleBase_Tools.h>
-#include <ModuleBase_FilterFactory.h>
 #include <ModuleBase_Filter.h>
 #include <ModuleBase_IModule.h>
+#include <ModuleBase_ViewerPrs.h>
+#include <ModuleBase_IconFactory.h>
 
+#include <Config_Translator.h>
 #include <Config_WidgetAPI.h>
 #include <Events_Loop.h>
 #include <Events_Message.h>
@@ -37,7 +52,6 @@
 #include <ModelAPI_AttributeValidator.h>
 
 #include <Config_WidgetAPI.h>
-#include <Events_Error.h>
 
 #include <GeomAPI_Shape.h>
 
@@ -72,14 +86,14 @@ ModuleBase_WidgetShapeSelector::ModuleBase_WidgetShapeSelector(QWidget* theParen
   QFormLayout* aLayout = new QFormLayout(this);
   ModuleBase_Tools::adjustMargins(aLayout);
 
-  QString aLabelText = QString::fromStdString(theData->widgetLabel());
+  QString aLabelText = translate(theData->widgetLabel());
   QString aLabelIcon = QString::fromStdString(theData->widgetIcon());
   myLabel = new QLabel(aLabelText, this);
   if (!aLabelIcon.isEmpty())
-    myLabel->setPixmap(QPixmap(aLabelIcon));
+    myLabel->setPixmap(ModuleBase_IconFactory::loadPixmap(aLabelIcon));
 
 
-  QString aToolTip = QString::fromStdString(theData->widgetTooltip());
+  QString aToolTip = translate(theData->widgetTooltip());
   myTextLine = new QLineEdit(this);
   QString anObjName = QString::fromStdString(attributeID());
   myTextLine->setObjectName(anObjName);
@@ -100,23 +114,24 @@ ModuleBase_WidgetShapeSelector::~ModuleBase_WidgetShapeSelector()
 }
 
 //********************************************************************
-bool ModuleBase_WidgetShapeSelector::storeValueCustom() const
+bool ModuleBase_WidgetShapeSelector::storeValueCustom()
 {
-  // the value is stored on the selection changed signal processing 
+  // the value is stored on the selection changed signal processing
   return true;
 }
 
 //********************************************************************
-bool ModuleBase_WidgetShapeSelector::setSelection(QList<ModuleBase_ViewerPrs>& theValues,
+bool ModuleBase_WidgetShapeSelector::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(ModuleBase_ViewerPrs());
+    setSelectionCustom(std::shared_ptr<ModuleBase_ViewerPrs>(new ModuleBase_ViewerPrs(
+                                                  ObjectPtr(), GeomShapePtr(), NULL)));
     return false;
   }
   // it removes the processed value from the parameters list
-  ModuleBase_ViewerPrs aValue = theValues.takeFirst();
+  ModuleBase_ViewerPrsPtr aValue = theValues.takeFirst();
   bool isDone = false;
 
   if (!theToValidate || isValidInFilters(aValue)) {
@@ -131,16 +146,16 @@ bool ModuleBase_WidgetShapeSelector::setSelection(QList<ModuleBase_ViewerPrs>& t
 }
 
 //********************************************************************
-QList<ModuleBase_ViewerPrs> ModuleBase_WidgetShapeSelector::getAttributeSelection() const
+QList<ModuleBase_ViewerPrsPtr> ModuleBase_WidgetShapeSelector::getAttributeSelection() const
 {
-  QList<ModuleBase_ViewerPrs> aSelected;
+  QList<ModuleBase_ViewerPrsPtr> aSelected;
   if(myFeature) {
     DataPtr aData = myFeature->data();
     AttributePtr anAttribute = myFeature->attribute(attributeID());
 
     ObjectPtr anObject = ModuleBase_Tools::getObject(anAttribute);
     std::shared_ptr<GeomAPI_Shape> aShapePtr = getShape();
-    ModuleBase_ViewerPrs aPrs(anObject, aShapePtr, NULL);
+    ModuleBase_ViewerPrsPtr aPrs(new ModuleBase_ViewerPrs(anObject, aShapePtr, NULL));
     aSelected.append(aPrs);
   }
   return aSelected;
@@ -170,7 +185,7 @@ void ModuleBase_WidgetShapeSelector::updateFocus()
 }
 
 //********************************************************************
-QIntList ModuleBase_WidgetShapeSelector::getShapeTypes() const
+QIntList ModuleBase_WidgetShapeSelector::shapeTypes() const
 {
   QIntList aShapeTypes;
   foreach(QString aType, myShapeTypes) {
@@ -201,7 +216,8 @@ void ModuleBase_WidgetShapeSelector::updateSelectionName()
   bool isNameUpdated = false;
   AttributeSelectionPtr aSelect = aData->selection(attributeID());
   if (aSelect) {
-    myTextLine->setText(QString::fromStdString(aSelect->namingName(getDefaultValue())));
+    std::string aDefault = translate(getDefaultValue()).toStdString();
+    myTextLine->setText(QString::fromStdString(aSelect->namingName(aDefault)));
     isNameUpdated = true;
   }
   if (!isNameUpdated) {
@@ -213,12 +229,18 @@ void ModuleBase_WidgetShapeSelector::updateSelectionName()
       AttributeRefAttrPtr aRefAttr = aData->refattr(attributeID());
       if (aRefAttr && aRefAttr->attr().get() != NULL) {
         //myIsObject = aRefAttr->isObject();
-        std::string anAttrName = generateName(aRefAttr->attr(), myWorkshop);
+        std::string anAttrName = ModuleBase_Tools::generateName(aRefAttr->attr(), myWorkshop);
         myTextLine->setText(QString::fromStdString(anAttrName));
       }
       else {
-        myTextLine->setText(getDefaultValue().c_str());
+        myTextLine->setText(translate(getDefaultValue()));
       }
     }
   }
 }
+
+//********************************************************************
+bool ModuleBase_WidgetShapeSelector::isModified() const
+{
+  return !myTextLine->text().isEmpty();
+}
\ No newline at end of file