X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModuleBase%2FModuleBase_WidgetShapeSelector.cpp;h=8b07d585103bc4bfa081025d1275d10307b767f8;hb=423f6b0a08a86d5e47115b87603cddeae4468b49;hp=113a6113f8b2d73e5059a7826b64f501baf93192;hpb=e98f5ede19029ac09ae9fe78061a4485bd6b86b5;p=modules%2Fshaper.git diff --git a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp index 113a6113f..8b07d5851 100644 --- a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp @@ -12,13 +12,15 @@ #include #include #include +#include +#include +#include #include #include #include #include #include -#include #include #include @@ -37,7 +39,6 @@ #include #include -#include #include @@ -66,9 +67,8 @@ 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); @@ -77,16 +77,19 @@ ModuleBase_WidgetShapeSelector::ModuleBase_WidgetShapeSelector(QWidget* theParen 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()); 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); std::string aTypes = theData->getProperty("shape_types"); myShapeTypes = QString(aTypes.c_str()).split(' ', QString::SkipEmptyParts); @@ -98,67 +101,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(); - AttributeReferencePtr aRef = aData->reference(attributeID()); - if (aRef) { - ObjectPtr aObject = aRef->value(); - if (!(aObject && aObject->isSame(theSelectedObject))) { - aRef->setValue(theSelectedObject); - } - } else { - AttributeRefAttrPtr aRefAttr = aData->refattr(attributeID()); - if (aRefAttr) { - ObjectPtr aObject = aRefAttr->object(); - if (!(aObject && aObject->isSame(theSelectedObject))) { - aRefAttr->setObject(theSelectedObject); - } - } else { - 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 = GeomValidators_Tools::getObject(anAttribute); - TopoDS_Shape aShape; + ObjectPtr anObject = ModuleBase_Tools::getObject(anAttribute); 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() { @@ -183,7 +172,7 @@ void ModuleBase_WidgetShapeSelector::updateFocus() } //******************************************************************** -QIntList ModuleBase_WidgetShapeSelector::getShapeTypes() const +QIntList ModuleBase_WidgetShapeSelector::shapeTypes() const { QIntList aShapeTypes; foreach(QString aType, myShapeTypes) { @@ -197,13 +186,10 @@ GeomShapePtr ModuleBase_WidgetShapeSelector::getShape() const { GeomShapePtr aShape; DataPtr aData = myFeature->data(); - if (!aData->isValid()) - return aShape; - - AttributeSelectionPtr aSelect = aData->selection(attributeID()); - if (aSelect) - aShape = aSelect->value(); - + if (aData->isValid()) { + AttributePtr anAttribute = myFeature->data()->attribute(attributeID()); + aShape = ModuleBase_Tools::getShape(anAttribute, myWorkshop); + } return aShape; } @@ -221,7 +207,7 @@ void ModuleBase_WidgetShapeSelector::updateSelectionName() isNameUpdated = true; } if (!isNameUpdated) { - ObjectPtr anObject = GeomValidators_Tools::getObject(myFeature->attribute(attributeID())); + ObjectPtr anObject = ModuleBase_Tools::getObject(myFeature->attribute(attributeID())); if (anObject.get() != NULL) { std::string aName = anObject->data()->name(); myTextLine->setText(QString::fromStdString(aName)); @@ -229,12 +215,8 @@ void ModuleBase_WidgetShapeSelector::updateSelectionName() AttributeRefAttrPtr aRefAttr = aData->refattr(attributeID()); if (aRefAttr && aRefAttr->attr().get() != NULL) { //myIsObject = aRefAttr->isObject(); - AttributePtr anAttr = aRefAttr->attr(); - if (anAttr.get() != NULL) { - std::stringstream aName; - aName <owner()->data()->name()<<"/"<id(); - myTextLine->setText(QString::fromStdString(aName.str())); - } + std::string anAttrName = generateName(aRefAttr->attr(), myWorkshop); + myTextLine->setText(QString::fromStdString(anAttrName)); } else { myTextLine->setText(getDefaultValue().c_str()); @@ -242,38 +224,3 @@ void ModuleBase_WidgetShapeSelector::updateSelectionName() } } } - -//******************************************************************** -void ModuleBase_WidgetShapeSelector::storeAttributeValue() -{ - ModuleBase_WidgetValidated::storeAttributeValue(); - - DataPtr aData = myFeature->data(); - AttributePtr anAttribute = myFeature->attribute(attributeID()); - - myObject = GeomValidators_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); - } -}