X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModuleBase%2FModuleBase_WidgetShapeSelector.cpp;h=f5a88190baea4f655d1ed48f88418c76779b4955;hb=fc72d43b677baa05ae7fd317346fd8b723b799ed;hp=13f071c21dca6f64278fd3301edd222514030ec3;hpb=89775a64fb63ba0d7c875c1f7aba41f9b6f89c13;p=modules%2Fshaper.git diff --git a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp index 13f071c21..f5a88190b 100644 --- a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp @@ -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-2023 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 #include @@ -10,10 +23,12 @@ #include #include #include -#include #include #include +#include +#include +#include #include #include #include @@ -37,7 +52,6 @@ #include #include -#include #include @@ -66,21 +80,20 @@ ModuleBase_WidgetShapeSelector::ModuleBase_WidgetShapeSelector(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop, - const Config_WidgetAPI* theData, - const std::string& theParentId) - : ModuleBase_WidgetSelector(theParent, theWorkshop, theData, theParentId) + const Config_WidgetAPI* theData) +: ModuleBase_WidgetSelector(theParent, theWorkshop, theData) { 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); @@ -101,72 +114,53 @@ 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; } //******************************************************************** -void ModuleBase_WidgetShapeSelector::setObject(ObjectPtr theSelectedObject, - GeomShapePtr theShape) +bool ModuleBase_WidgetShapeSelector::setSelection(QList& theValues, + const bool theToValidate) { - DataPtr aData = myFeature->data(); - std::string aType = aData->attribute(attributeID())->attributeType(); - if (aType == ModelAPI_AttributeReference::typeId()) { - AttributeReferencePtr aRef = aData->reference(attributeID()); - ObjectPtr aObject = aRef->value(); - if (!(aObject && aObject->isSame(theSelectedObject))) { - aRef->setValue(theSelectedObject); - } - } else if (aType == ModelAPI_AttributeRefAttr::typeId()) { - AttributeRefAttrPtr aRefAttr = aData->refattr(attributeID()); - - AttributePtr anAttribute = myWorkshop->module()->findAttribute(theSelectedObject, theShape); - if (anAttribute.get()) - aRefAttr->setAttr(anAttribute); - else { - ObjectPtr aObject = aRefAttr->object(); - if (!(aObject && aObject->isSame(theSelectedObject))) { - aRefAttr->setObject(theSelectedObject); - } - } - } else if (aType == ModelAPI_AttributeSelection::typeId()) { - AttributeSelectionPtr aSelectAttr = aData->selection(attributeID()); - ResultPtr aResult = std::dynamic_pointer_cast(theSelectedObject); - if (aSelectAttr.get() != NULL) { - aSelectAttr->setValue(aResult, theShape); - } + if (theValues.empty()) { + // In order to make reselection possible, set empty object and shape should be done + setSelectionCustom(std::shared_ptr(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 || isValidInFilters(aValue)) { + isDone = setSelectionCustom(aValue); + // updateObject - to update/redisplay feature + // it is commented in order to perfom it outside the method + //updateObject(myFeature); + // to storeValue() + //emit valuesChanged(); } + return isDone; } //******************************************************************** -QList ModuleBase_WidgetShapeSelector::getAttributeSelection() const +QList ModuleBase_WidgetShapeSelector::getAttributeSelection() const { - QList aSelected; + QList aSelected; if(myFeature) { DataPtr aData = myFeature->data(); AttributePtr anAttribute = myFeature->attribute(attributeID()); ObjectPtr anObject = ModuleBase_Tools::getObject(anAttribute); - TopoDS_Shape aShape; std::shared_ptr aShapePtr = getShape(); - if (aShapePtr.get()) { - aShape = aShapePtr->impl(); - } - ModuleBase_ViewerPrs aPrs(anObject, aShape, NULL); + ModuleBase_ViewerPrsPtr aPrs(new ModuleBase_ViewerPrs(anObject, aShapePtr, NULL)); aSelected.append(aPrs); } return aSelected; } -//******************************************************************** -void ModuleBase_WidgetShapeSelector::clearAttribute() -{ - // In order to make reselection possible, set empty object and shape should be done - setObject(ObjectPtr(), std::shared_ptr(new GeomAPI_Shape())); -} - //******************************************************************** bool ModuleBase_WidgetShapeSelector::restoreValueCustom() { @@ -191,7 +185,7 @@ void ModuleBase_WidgetShapeSelector::updateFocus() } //******************************************************************** -QIntList ModuleBase_WidgetShapeSelector::getShapeTypes() const +QIntList ModuleBase_WidgetShapeSelector::shapeTypes() const { QIntList aShapeTypes; foreach(QString aType, myShapeTypes) { @@ -205,22 +199,10 @@ GeomShapePtr ModuleBase_WidgetShapeSelector::getShape() const { GeomShapePtr aShape; DataPtr aData = myFeature->data(); - if (!aData->isValid()) - return aShape; - - std::string aType = aData->attribute(attributeID())->attributeType(); - if (aType == ModelAPI_AttributeReference::typeId()) { - } else if (aType == ModelAPI_AttributeRefAttr::typeId()) { - AttributeRefAttrPtr aRefAttr = aData->refattr(attributeID()); - if (aRefAttr.get() && !aRefAttr->isObject()) { - AttributePtr anAttribute = aRefAttr->attr(); - aShape = myWorkshop->module()->findShape(anAttribute); - } - } else if (aType == ModelAPI_AttributeSelection::typeId()) { - AttributeSelectionPtr aSelectAttr = aData->selection(attributeID()); - aShape = aSelectAttr->value(); + if (aData->isValid()) { + AttributePtr anAttribute = myFeature->data()->attribute(attributeID()); + aShape = ModuleBase_Tools::getShape(anAttribute, myWorkshop); } - return aShape; } @@ -234,59 +216,31 @@ void ModuleBase_WidgetShapeSelector::updateSelectionName() bool isNameUpdated = false; AttributeSelectionPtr aSelect = aData->selection(attributeID()); if (aSelect) { - myTextLine->setText(QString::fromStdString(aSelect->namingName(getDefaultValue()))); + std::wstring aDefault = translate(getDefaultValue()).toStdWString(); + myTextLine->setText(QString::fromStdWString(aSelect->namingName(aDefault))); isNameUpdated = true; } if (!isNameUpdated) { ObjectPtr anObject = ModuleBase_Tools::getObject(myFeature->attribute(attributeID())); if (anObject.get() != NULL) { - std::string aName = anObject->data()->name(); - myTextLine->setText(QString::fromStdString(aName)); + std::wstring aName = anObject->data()->name(); + myTextLine->setText(QString::fromStdWString(aName)); } else { AttributeRefAttrPtr aRefAttr = aData->refattr(attributeID()); if (aRefAttr && aRefAttr->attr().get() != NULL) { //myIsObject = aRefAttr->isObject(); - std::string anAttrName = generateName(aRefAttr->attr(), myWorkshop); - myTextLine->setText(QString::fromStdString(anAttrName)); + std::wstring anAttrName = ModuleBase_Tools::generateName(aRefAttr->attr(), myWorkshop); + myTextLine->setText(QString::fromStdWString(anAttrName)); } else { - myTextLine->setText(getDefaultValue().c_str()); + myTextLine->setText(translate(getDefaultValue())); } } } } //******************************************************************** -void ModuleBase_WidgetShapeSelector::storeAttributeValue() +bool ModuleBase_WidgetShapeSelector::isModified() const { - ModuleBase_WidgetValidated::storeAttributeValue(); - - DataPtr aData = myFeature->data(); - AttributePtr anAttribute = myFeature->attribute(attributeID()); - - myObject = ModuleBase_Tools::getObject(anAttribute); - myShape = getShape(); - myRefAttribute = AttributePtr(); - myIsObject = false; - AttributeRefAttrPtr aRefAttr = aData->refattr(attributeID()); - if (aRefAttr) { - myIsObject = aRefAttr->isObject(); - myRefAttribute = aRefAttr->attr(); - } -} - -//******************************************************************** -void ModuleBase_WidgetShapeSelector::restoreAttributeValue(bool theValid) -{ - ModuleBase_WidgetValidated::restoreAttributeValue(theValid); - - DataPtr aData = myFeature->data(); - AttributePtr anAttribute = myFeature->attribute(attributeID()); - - setObject(myObject, myShape); - AttributeRefAttrPtr aRefAttr = aData->refattr(attributeID()); - if (aRefAttr) { - if (!myIsObject) - aRefAttr->setAttr(myRefAttribute); - } -} + return !myTextLine->text().isEmpty(); +} \ No newline at end of file