X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModuleBase%2FModuleBase_WidgetFeatureSelector.cpp;h=fb24a1715c064ec293dda8c839cb0c21a46126f0;hb=d75b1b5c09b57fd8326d846118fa3246a9857492;hp=9396183d350c154f492bbb486555d94341c04106;hpb=fa2d6e0932a9ef3d391ba4fb99b2608de8fdab33;p=modules%2Fshaper.git diff --git a/src/ModuleBase/ModuleBase_WidgetFeatureSelector.cpp b/src/ModuleBase/ModuleBase_WidgetFeatureSelector.cpp index 9396183d3..fb24a1715 100644 --- a/src/ModuleBase/ModuleBase_WidgetFeatureSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetFeatureSelector.cpp @@ -1,88 +1,87 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D - -// File: ModuleBase_WidgetFeatureSelector.cpp -// Created: 5 Sep 2016 -// Author: Natalia Ermolaeva - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include -#include - - -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 = QString::fromStdString(theData->widgetLabel()); - QString aLabelIcon = QString::fromStdString(theData->widgetIcon()); - myLabel = new QLabel(aLabelText, this); - if (!aLabelIcon.isEmpty()) - myLabel->setPixmap(ModuleBase_IconFactory::loadPixmap(aLabelIcon)); - - - QString aToolTip = QString::fromStdString(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() -{ -} - +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: ModuleBase_WidgetFeatureSelector.cpp +// Created: 5 Sep 2016 +// Author: Natalia Ermolaeva + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include + + +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) { @@ -101,17 +100,17 @@ void ModuleBase_WidgetFeatureSelector::deactivate() { ModuleBase_ModelWidget::deactivate(); disconnect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged())); - activateFilters(false); + activateFilters(false); myWorkshop->deactivateSubShapesSelection(); -} - +} + //******************************************************************** void ModuleBase_WidgetFeatureSelector::activateCustom() { connect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()), Qt::UniqueConnection); - - activateFilters(true); + + activateFilters(true); QIntList aShapeTypes; aShapeTypes.push_back(ModuleBase_ResultPrs::Sel_Result); @@ -122,92 +121,94 @@ void ModuleBase_WidgetFeatureSelector::activateCustom() //static Events_ID anEvent = Events_Loop::eventByName(EVENT_UPDATE_BY_WIDGET_SELECTION); //ModelAPI_EventCreator::get()->sendUpdated(myFeature, anEvent); } - -//******************************************************************** -bool ModuleBase_WidgetFeatureSelector::storeValueCustom() -{ - // the value is stored on the selection changed signal processing - return true; -} - -//******************************************************************** -bool ModuleBase_WidgetFeatureSelector::setSelection(QList& 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(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 ModuleBase_WidgetFeatureSelector::getControls() const -{ - QList aControls; - aControls.append(myTextLine); - return aControls; -} - -void ModuleBase_WidgetFeatureSelector::updateFocus() -{ - 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)); - } -} - -//******************************************************************** -bool ModuleBase_WidgetFeatureSelector::isValidInFilters(const ModuleBase_ViewerPrsPtr& thePrs) -{ - bool aValid = false; - - ObjectPtr anObject = thePrs->object(); - FeaturePtr aFeature = std::dynamic_pointer_cast(anObject); - aValid = aFeature.get(); - if (!aValid) { - ResultPtr aResult = std::dynamic_pointer_cast(anObject); - aValid = aResult.get() && aResult->shape() == thePrs->shape(); - } - - return aValid; -} - -//******************************************************************** + +//******************************************************************** +bool ModuleBase_WidgetFeatureSelector::storeValueCustom() +{ + // the value is stored on the selection changed signal processing + return true; +} + +//******************************************************************** +bool ModuleBase_WidgetFeatureSelector::setSelection(QList& 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(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 ModuleBase_WidgetFeatureSelector::getControls() const +{ + QList aControls; + aControls.append(myTextLine); + return aControls; +} + +void ModuleBase_WidgetFeatureSelector::updateFocus() +{ + 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(anObject); + aValid = aFeature.get(); + if (!aValid) { + ResultPtr aResult = std::dynamic_pointer_cast(anObject); + aValid = aResult.get() && aResult->shape() == thePrs->shape(); + } + + return aValid; +} + +//******************************************************************** void ModuleBase_WidgetFeatureSelector::onSelectionChanged() { - QList aSelected = myWorkshop->selection()->getSelected( - ModuleBase_ISelection::AllControls); + QList aSelected = myWorkshop->selection()->getSelected( + ModuleBase_ISelection::AllControls); bool isDone = setSelection(aSelected, true/*false*/); updateOnSelectionChanged(isDone); @@ -216,7 +217,7 @@ void ModuleBase_WidgetFeatureSelector::onSelectionChanged() //******************************************************************** 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.