X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModuleBase%2FModuleBase_WidgetMultiSelector.cpp;h=c403a878039e777797e6050a7468cad8ac4aecd5;hb=4c74e5b864eef28128e27b3ece944990ca8f3fbe;hp=d81556ac18bbdd20b80d2ec258f5de0cf3632ecc;hpb=27e18cdd6803be98efed9402d610d59cacae3d69;p=modules%2Fshaper.git diff --git a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp old mode 100755 new mode 100644 index d81556ac1..c403a8780 --- a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2017 CEA/DEN, EDF R&D +// 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 @@ -12,10 +12,9 @@ // // 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 +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // #include @@ -38,6 +37,7 @@ #include #include #include +#include #include #include @@ -62,6 +62,8 @@ #include #include #include +#include +#include #include #include @@ -112,21 +114,21 @@ ModuleBase_WidgetMultiSelector::ModuleBase_WidgetMultiSelector(QWidget* theParen const Config_WidgetAPI* theData) : ModuleBase_WidgetSelector(theParent, theWorkshop, theData), myIsSetSelectionBlocked(false), myCurrentHistoryIndex(-1), - myIsFirst(true) + myIsFirst(true), myFiltersWgt(0) { std::string aPropertyTypes = theData->getProperty("type_choice"); QString aTypesStr = aPropertyTypes.c_str(); myShapeTypes = aTypesStr.split(' ', QString::SkipEmptyParts); myIsUseChoice = theData->getBooleanAttribute("use_choice", false); - QGridLayout* aMainLay = new QGridLayout(this); + QVBoxLayout* aMainLay = new QVBoxLayout(this); ModuleBase_Tools::adjustMargins(aMainLay); QStringList aIconsList = getIconsList(myShapeTypes); myTypeCtrl = new ModuleBase_ChoiceCtrl(this, myShapeTypes, aIconsList); myTypeCtrl->setLabel(tr("Type")); myTypeCtrl->setValue(0); - aMainLay->addWidget(myTypeCtrl, 0, 0, 1, 2); + aMainLay->addWidget(myTypeCtrl); myDefMode = myShapeTypes.first().toStdString(); // There is no sense to parameterize list of types while we can not parameterize selection mode @@ -136,18 +138,25 @@ ModuleBase_WidgetMultiSelector::ModuleBase_WidgetMultiSelector(QWidget* theParen } QString aLabelText = translate(theData->getProperty("label")); - QLabel* aListLabel = new QLabel(aLabelText, this); - aMainLay->addWidget(aListLabel, 1, 0); - // if the xml definition contains one type, an information label - // should be shown near to the latest - if (myShapeTypes.size() <= 1) { - QString aLabelIcon = QString::fromStdString(theData->widgetIcon()); - if (!aLabelIcon.isEmpty()) { - QLabel* aSelectedLabel = new QLabel("", this); - aSelectedLabel->setPixmap(ModuleBase_IconFactory::loadPixmap(aLabelIcon)); - aMainLay->addWidget(aSelectedLabel, 1, 1); + if (aLabelText.size() > 0) { + QWidget* aLabelWgt = new QWidget(this); + QHBoxLayout* aLabelLayout = new QHBoxLayout(aLabelWgt); + aLabelLayout->setContentsMargins(0, 0, 0, 0); + aMainLay->addWidget(aLabelWgt); + + QLabel* aListLabel = new QLabel(aLabelText, this); + aLabelLayout->addWidget(aListLabel); + // if the xml definition contains one type, an information label + // should be shown near to the latest + if (myShapeTypes.size() <= 1) { + QString aLabelIcon = QString::fromStdString(theData->widgetIcon()); + if (!aLabelIcon.isEmpty()) { + QLabel* aSelectedLabel = new QLabel("", this); + aSelectedLabel->setPixmap(ModuleBase_IconFactory::loadPixmap(aLabelIcon)); + aLabelLayout->addWidget(aSelectedLabel); + aLabelLayout->addStretch(1); + } } - aMainLay->setColumnStretch(2, 1); } QString aToolTip = QString::fromStdString(theData->widgetTooltip()); @@ -157,13 +166,37 @@ ModuleBase_WidgetMultiSelector::ModuleBase_WidgetMultiSelector(QWidget* theParen connect(myListView, SIGNAL(deleteActionClicked()), SLOT(onDeleteItem())); connect(myListView, SIGNAL(listActivated()), SLOT(onListActivated())); - aMainLay->addWidget(myListView->getControl(), 2, 0, 1, -1); - aMainLay->setRowStretch(2, 1); - //aMainLay->addWidget(new QLabel(this)); //FIXME(sbh)??? - //aMainLay->setRowMinimumHeight(3, 20); - //this->setLayout(aMainLay); + aMainLay->addWidget(myListView->getControl()); connect(myTypeCtrl, SIGNAL(valueChanged(int)), this, SLOT(onSelectionTypeChanged())); + std::string aUseFilters = theData->getProperty("use_filters"); + if (aUseFilters.length() > 0) { + QWidget* aFltrWgt = new QWidget(this); + QHBoxLayout* aFltrLayout = new QHBoxLayout(aFltrWgt); + + myFiltersWgt = new ModuleBase_FilterStarter(aUseFilters.c_str(), aFltrWgt, theWorkshop); + aFltrLayout->addWidget(myFiltersWgt); + + aFltrLayout->addStretch(); + + QPushButton* aShowBtn = new QPushButton(tr("Show only"), aFltrWgt); + aShowBtn->setCheckable(true); + aShowBtn->setChecked(false); + connect(aShowBtn, SIGNAL(toggled(bool)), SLOT(onShowOnly(bool))); + aFltrLayout->addWidget(aShowBtn); + + aMainLay->addWidget(aFltrWgt); + } + + bool aSameTop = theData->getBooleanAttribute("same_topology", false); + if (aSameTop) { + myGeomCheck = new QCheckBox(tr("Add elements that share the same topology"), this); + aMainLay->addWidget(myGeomCheck); + connect(myGeomCheck, SIGNAL(toggled(bool)), SLOT(onSameTopology(bool))); + } + else + myGeomCheck = 0; + myIsNeutralPointClear = theData->getBooleanAttribute("clear_in_neutral_point", true); if (myShapeTypes.size() > 1 || myIsUseChoice) { if (defaultValues.contains(myFeatureId + attributeID())) { @@ -191,6 +224,8 @@ void ModuleBase_WidgetMultiSelector::activateCustom() void ModuleBase_WidgetMultiSelector::deactivate() { ModuleBase_WidgetSelector::deactivate(); + if (myVisibleObjects.size()) + onShowOnly(false); myWorkshop->module()->deactivateCustomPrs(ModuleBase_IModule::CustomizeHighlightedObjects, true); clearSelectedHistory(); @@ -240,9 +275,9 @@ bool ModuleBase_WidgetMultiSelector::restoreValueCustom() return false; AttributePtr anAttribute = myFeature->data()->attribute(attributeID()); + AttributeSelectionListPtr aSelectionListAttr = myFeature->data()->selectionList(attributeID()); std::string aType = anAttribute->attributeType(); if (aType == ModelAPI_AttributeSelectionList::typeId()) { - AttributeSelectionListPtr aSelectionListAttr = myFeature->data()->selectionList(attributeID()); // Restore shape type std::string aSelectionType = aSelectionListAttr->selectionType().c_str(); if (!aSelectionType.empty()) { @@ -251,6 +286,8 @@ bool ModuleBase_WidgetMultiSelector::restoreValueCustom() myIsFirst = false; } } + if (myGeomCheck) + myGeomCheck->setChecked(aSelectionListAttr->isGeometricalSelection()); updateSelectionList(); return true; } @@ -490,6 +527,7 @@ void ModuleBase_WidgetMultiSelector::onSelectionTypeChanged() { // Clear current selection in order to avoid updating of object browser with obsolete indexes // which can appear because of results deletetion after changing a type of selection + QString aSelectionType = myTypeCtrl->textValue(); QList aEmptyList; myWorkshop->setSelected(aEmptyList); @@ -503,7 +541,7 @@ void ModuleBase_WidgetMultiSelector::onSelectionTypeChanged() std::string aType = anAttribute->attributeType(); if (aType == ModelAPI_AttributeSelectionList::typeId()) { AttributeSelectionListPtr aSelectionListAttr = myFeature->data()->selectionList(attributeID()); - aSelectionListAttr->setSelectionType(myTypeCtrl->textValue().toStdString()); + aSelectionListAttr->setSelectionType(aSelectionType.toStdString()); } // clear attribute values @@ -939,6 +977,8 @@ bool ModuleBase_WidgetMultiSelector::findInSelection(const ObjectPtr& theObject, const std::map >& theGeomSelection, ModuleBase_IWorkshop* theWorkshop) { + if (!theObject.get()) + return false; // issue #2154: we should not remove from list objects hidden in the viewer if selection // was done with SHIFT button if (theWorkshop->hasSHIFTPressed() && !theObject->isDisplayed()) @@ -1040,4 +1080,47 @@ void ModuleBase_WidgetMultiSelector::onListActivated() { //focusTo(); emitFocusInWidget(); -} \ No newline at end of file +} + +void ModuleBase_WidgetMultiSelector::onSameTopology(bool theOn) +{ + AttributePtr anAttribute = myFeature->data()->attribute(attributeID()); + std::string aType = anAttribute->attributeType(); + if (aType == ModelAPI_AttributeSelectionList::typeId()) { + AttributeSelectionListPtr aSelectionListAttr = myFeature->data()->selectionList(attributeID()); + aSelectionListAttr->setGeometricalSelection(theOn); + updateObject(myFeature); + } +} + +void ModuleBase_WidgetMultiSelector::onShowOnly(bool theChecked) +{ + std::list aResults = myFeature->results(); + std::list::const_iterator aIt; + if (theChecked) { + myVisibleObjects = myWorkshop->displayedObjects(); + for (aIt = aResults.cbegin(); aIt != aResults.cend(); aIt++) { + myVisibleObjects.removeAll(*aIt); + } + } + foreach(ObjectPtr aObj, myVisibleObjects) { + aObj->setDisplayed(!theChecked); + } + + if (!theChecked) { + // Hide and show the group result in order to make it above all objects + bool aOldState = myWorkshop->enableUpdateViewer(false); + for (aIt = aResults.cbegin(); aIt != aResults.cend(); aIt++) { + (*aIt)->setDisplayed(false); + } + Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY)); + for (aIt = aResults.cbegin(); aIt != aResults.cend(); aIt++) { + (*aIt)->setDisplayed(true); + } + Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY)); + myWorkshop->enableUpdateViewer(aOldState); + + myVisibleObjects.clear(); + } else + Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY)); +}