From: nds Date: Thu, 21 Jan 2016 07:34:54 +0000 (+0300) Subject: Extending Multi selector for ModelAPI_AttributeRefAttrList X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=8015679889f29957f7b7d3676e3f7a352ad2517b;p=modules%2Fshaper.git Extending Multi selector for ModelAPI_AttributeRefAttrList --- diff --git a/src/ModuleBase/ModuleBase_IModule.h b/src/ModuleBase/ModuleBase_IModule.h index d80620a48..56f7e2bbc 100755 --- a/src/ModuleBase/ModuleBase_IModule.h +++ b/src/ModuleBase/ModuleBase_IModule.h @@ -7,6 +7,9 @@ #include "ModuleBase_IWorkshop.h" #include +#include + +#include #include #include @@ -237,6 +240,18 @@ class MODULEBASE_EXPORT ModuleBase_IModule : public QObject /// Default realization is empty virtual void beforeOperationStopped(ModuleBase_Operation* theOperation) {}; + /// Finds a shape by attribute if it is possible + /// \param theAttribute an attribute + /// \return a geom shape + virtual GeomShapePtr findShape(const AttributePtr& theAttribute) = 0; + + /// Finds an attribute by geom shape if it is possible + /// \param theObject an object of the attribute + /// \param theGeomShape a geom shape + /// \return theAttribute + virtual AttributePtr findAttribute(const ObjectPtr& theObject, + const GeomShapePtr& theGeomShape) = 0; + signals: /// Signal which is emitted when operation is launched void operationLaunched(); diff --git a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp index 00b133402..28d40d282 100755 --- a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include @@ -221,6 +222,7 @@ void ModuleBase_WidgetMultiSelector::storeAttributeValue() AttributePtr anAttribute = myFeature->data()->attribute(attributeID()); std::string aType = anAttribute->attributeType(); + if (aType == ModelAPI_AttributeSelectionList::typeId()) { AttributeSelectionListPtr aSelectionListAttr = std::dynamic_pointer_cast(anAttribute); @@ -232,6 +234,44 @@ void ModuleBase_WidgetMultiSelector::storeAttributeValue() std::dynamic_pointer_cast(anAttribute); mySelectionCount = aRefListAttr->size(); } + else if (aType == ModelAPI_AttributeRefAttrList::typeId()) { + AttributeRefAttrListPtr aRefAttrListAttr = + std::dynamic_pointer_cast(anAttribute); + mySelectionCount = aRefAttrListAttr->size(); + } +} + +//******************************************************************** +bool ModuleBase_WidgetMultiSelector::setSelectionCustom(const ModuleBase_ViewerPrs& thePrs) +{ + AttributePtr anAttribute = myFeature->data()->attribute(attributeID()); + std::string aType = anAttribute->attributeType(); + if (aType == ModelAPI_AttributeRefAttrList::typeId()) { + AttributeRefAttrListPtr aRefAttrListAttr = + std::dynamic_pointer_cast(anAttribute); + + bool isDone = false; + if (!thePrs.shape().IsNull()) { + GeomShapePtr aGeomShape = std::shared_ptr(new GeomAPI_Shape); + aGeomShape->setImpl(new TopoDS_Shape(thePrs.shape())); + + AttributePtr anAttribute = myWorkshop->module()->findAttribute(thePrs.object(), aGeomShape); + if (anAttribute.get()) { + aRefAttrListAttr->append(anAttribute); + isDone = true; + } + } + if (!isDone) + ModuleBase_WidgetSelector::setSelectionCustom(thePrs); + } + else { + ModuleBase_WidgetSelector::setSelectionCustom(thePrs); + /*ObjectPtr anObject; + GeomShapePtr aShape; + getGeomSelection(thePrs, anObject, aShape); + setObject(anObject, aShape);*/ + } + return true; } //******************************************************************** @@ -259,6 +299,14 @@ void ModuleBase_WidgetMultiSelector::restoreAttributeValue(bool theValid) for (int i = 0; i < aCountAppened; i++) aRefListAttr->removeLast(); } + else if (aType == ModelAPI_AttributeRefAttrList::typeId()) { + AttributeRefAttrListPtr aRefAttrListAttr = + std::dynamic_pointer_cast(anAttribute); + // restore objects in the attribute. Indeed there is only one stored object + int aCountAppened = aRefAttrListAttr->size() - mySelectionCount; + for (int i = 0; i < aCountAppened; i++) + aRefAttrListAttr->removeLast(); + } } //******************************************************************** @@ -276,6 +324,11 @@ void ModuleBase_WidgetMultiSelector::clearAttribute() std::dynamic_pointer_cast(anAttribute); aRefListAttr->clear(); } + else if (aType == ModelAPI_AttributeRefAttrList::typeId()) { + AttributeRefAttrListPtr aRefAttrListAttr = + std::dynamic_pointer_cast(anAttribute); + aRefAttrListAttr->clear(); + } } //******************************************************************** @@ -295,6 +348,11 @@ void ModuleBase_WidgetMultiSelector::setObject(ObjectPtr theSelectedObject, std::dynamic_pointer_cast(anAttribute); aRefListAttr->append(theSelectedObject); } + else if (aType == ModelAPI_AttributeRefAttrList::typeId()) { + //AttributeRefAttrListPtr aRefAttrListAttr = + // std::dynamic_pointer_cast(anAttribute); + //aRefAttrListAttr->clear(); + } } //******************************************************************** @@ -377,19 +435,24 @@ bool ModuleBase_WidgetMultiSelector::processDelete() bool aDone = false; AttributePtr anAttribute = myFeature->data()->attribute(attributeID()); std::string aType = anAttribute->attributeType(); + aDone = !anAttributeIds.empty(); if (aType == ModelAPI_AttributeSelectionList::typeId()) { AttributeSelectionListPtr aSelectionListAttr = std::dynamic_pointer_cast(anAttribute); - aDone = !anAttributeIds.empty(); aSelectionListAttr->remove(anAttributeIds); } else if (aType == ModelAPI_AttributeRefList::typeId()) { AttributeRefListPtr aRefListAttr = std::dynamic_pointer_cast(anAttribute); - aDone = !anAttributeIds.empty(); aRefListAttr->remove(anAttributeIds); } + else if (aType == ModelAPI_AttributeRefAttrList::typeId()) { + AttributeRefAttrListPtr aRefAttrListAttr = + std::dynamic_pointer_cast(anAttribute); + aRefAttrListAttr->remove(anAttributeIds); + } + if (aDone) { // update object is necessary to flush update signal. It leads to objects references map update // and the operation presentation will not contain deleted items visualized as parameters of @@ -512,6 +575,27 @@ void ModuleBase_WidgetMultiSelector::updateSelectionList() } } } + else if (aType == ModelAPI_AttributeRefAttrList::typeId()) { + AttributeRefAttrListPtr aRefAttrListAttr = + std::dynamic_pointer_cast(anAttribute); + for (int i = 0; i < aRefAttrListAttr->size(); i++) { + AttributePtr anAttribute = aRefAttrListAttr->attribute(i); + QString aName; + if (anAttribute.get()) { + std::string anAttrName = generateName(anAttribute); + aName = QString::fromStdString(anAttrName); + } + else { + ObjectPtr anObject = aRefAttrListAttr->object(i); + if (anObject.get()) { + aName = anObject->data()->name().c_str(); + } + } + QListWidgetItem* anItem = new QListWidgetItem(aName, myListControl); + anItem->setData(ATTRIBUTE_SELECTION_INDEX_ROLE, i); + myListControl->addItem(anItem); + } + } // We have to call repaint because sometimes the List control is not updated myListControl->repaint(); @@ -618,4 +702,25 @@ void ModuleBase_WidgetMultiSelector::convertIndicesToViewerSelection(std::set(anAttribute); + for (int i = 0; i < aRefAttrListAttr->size(); i++) { + // filter by attribute indices only if the container is not empty otherwise return all items + if (!theAttributeIds.empty() && theAttributeIds.find(i) == theAttributeIds.end()) + continue; + ObjectPtr anObject = aRefAttrListAttr->object(i); + if (!anObject.get()) + continue; + TopoDS_Shape aShape; + AttributePtr anAttribute = aRefAttrListAttr->attribute(i); + if (anAttribute.get()) { + GeomShapePtr aGeomShape = myWorkshop->module()->findShape(anAttribute); + if (aGeomShape.get()) { + aShape = aGeomShape->impl(); + } + theValues.append(ModuleBase_ViewerPrs(anObject, aShape, NULL)); + } + } + } } diff --git a/src/ModuleBase/ModuleBase_WidgetMultiSelector.h b/src/ModuleBase/ModuleBase_WidgetMultiSelector.h index 7156e0517..54ff6ddcf 100755 --- a/src/ModuleBase/ModuleBase_WidgetMultiSelector.h +++ b/src/ModuleBase/ModuleBase_WidgetMultiSelector.h @@ -116,6 +116,10 @@ protected: /// parameters of the current attribute virtual void storeAttributeValue(); + /// Fills the attribute with the value of the selected owner + /// \param thePrs a selected owner + virtual bool setSelectionCustom(const ModuleBase_ViewerPrs& thePrs); + /// Clear attribute virtual void clearAttribute(); diff --git a/src/ModuleBase/ModuleBase_WidgetSelector.cpp b/src/ModuleBase/ModuleBase_WidgetSelector.cpp index 99edfb890..0f0b2c15a 100755 --- a/src/ModuleBase/ModuleBase_WidgetSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetSelector.cpp @@ -170,3 +170,14 @@ void ModuleBase_WidgetSelector::deactivate() ModuleBase_ModelWidget::deactivate(); } +//******************************************************************** +std::string ModuleBase_WidgetSelector::generateName(const AttributePtr& theAttribute) +{ + std::string aName; + if (theAttribute.get() != NULL) { + std::stringstream aStreamName; + aStreamName << theAttribute->owner()->data()->name() << "/"<< theAttribute->id(); + aName = aStreamName.str(); + } + return aName; +} diff --git a/src/ModuleBase/ModuleBase_WidgetSelector.h b/src/ModuleBase/ModuleBase_WidgetSelector.h index 63404f66f..150a0ce34 100755 --- a/src/ModuleBase/ModuleBase_WidgetSelector.h +++ b/src/ModuleBase/ModuleBase_WidgetSelector.h @@ -13,6 +13,7 @@ #include "ModuleBase_Definitions.h" #include +#include #include class Config_WidgetAPI; @@ -107,6 +108,10 @@ Q_OBJECT GeomShapePtr& theShape); //----------- Class members ------------- + /// Returns a name in the next form: attribute_feature_name/attribute_id + /// \param theAttribute a model attribute + /// \return string value + static std::string generateName(const AttributePtr& theAttribite); }; #endif diff --git a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp index 4db52fd2a..a51e16be6 100644 --- a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp @@ -231,12 +231,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()); + myTextLine->setText(QString::fromStdString(anAttrName)); } else { myTextLine->setText(getDefaultValue().c_str()); diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 35c38bc46..e7502e84d 100755 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -1030,6 +1030,27 @@ void PartSet_Module::beforeOperationStopped(ModuleBase_Operation* theOperation) } } +//****************************************************** +GeomShapePtr PartSet_Module::findShape(const AttributePtr& theAttribute) +{ + GeomShapePtr aGeomShape; + + ModuleBase_Operation* anOperation = myWorkshop->currentOperation(); + if (anOperation && PartSet_SketcherMgr::isNestedSketchOperation(anOperation)) { + aGeomShape = PartSet_Tools::findShapeBy2DPoint(theAttribute, myWorkshop); + } + return aGeomShape; +} + +//****************************************************** +AttributePtr PartSet_Module::findAttribute(const ObjectPtr& theObject, + const GeomShapePtr& theGeomShape) +{ + TopoDS_Shape aTDSShape = theGeomShape->impl(); + return PartSet_Tools::findAttributeBy2dPoint(theObject, aTDSShape, + mySketchMgr->activeSketch()); +} + //****************************************************** void PartSet_Module::onBooleanOperationChange(int theOperation) { diff --git a/src/PartSet/PartSet_Module.h b/src/PartSet/PartSet_Module.h index 36424180e..392dfa04e 100755 --- a/src/PartSet/PartSet_Module.h +++ b/src/PartSet/PartSet_Module.h @@ -244,6 +244,17 @@ public: /// Default realization is empty virtual void beforeOperationStopped(ModuleBase_Operation* theOperation); + /// Finds a shape by attribute if it is possible + /// \param theAttribute an attribute + /// \return a geom shape + virtual GeomShapePtr findShape(const AttributePtr& theAttribute); + + /// Finds an attribute by geom shape if it is possible + /// \param theObject an object of the attribute + /// \param theGeomShape a geom shape + /// \return theAttribute + virtual AttributePtr findAttribute(const ObjectPtr& theObject, const GeomShapePtr& theGeomShape); + public slots: /// Redefines the parent method in order to customize the next case: /// If the sketch nested operation is active and the presentation is not visualized in the viewer,