From ec091ee8278311fb7a69c54a68670b66edd8db2d Mon Sep 17 00:00:00 2001 From: nds Date: Thu, 21 May 2015 13:33:10 +0300 Subject: [PATCH] It provides a point attribute restore selection by activation of a shape selection control. --- .../ModuleBase_WidgetShapeSelector.h | 8 +-- src/PartSet/PartSet_WidgetShapeSelector.cpp | 68 +++++++++++++++++++ src/PartSet/PartSet_WidgetShapeSelector.h | 7 ++ src/XGUI/XGUI_Displayer.cpp | 24 +++---- 4 files changed, 89 insertions(+), 18 deletions(-) diff --git a/src/ModuleBase/ModuleBase_WidgetShapeSelector.h b/src/ModuleBase/ModuleBase_WidgetShapeSelector.h index e21d756fd..2dcd3662d 100644 --- a/src/ModuleBase/ModuleBase_WidgetShapeSelector.h +++ b/src/ModuleBase/ModuleBase_WidgetShapeSelector.h @@ -122,10 +122,6 @@ Q_OBJECT /// \param theShape a shape virtual bool acceptSubShape(std::shared_ptr theShape) const; - // Get the shape from the attribute it the attribute contain a shape, e.g. selection attribute - /// \return a shape - GeomShapePtr getShape() const; - /// Clear attribute void clearAttribute(); @@ -136,6 +132,10 @@ Q_OBJECT /// \return true if it is succeed virtual bool setObject(ObjectPtr theSelectedObject, GeomShapePtr theShape); + /// Get the shape from the attribute if the attribute contains a shape, e.g. selection attribute + /// \return a shape + virtual GeomShapePtr getShape() const; + /// Return the attribute values wrapped in a list of viewer presentations /// \return a list of viewer presentations, which contains an attribute result and /// a shape. If the attribute do not uses the shape, it is empty diff --git a/src/PartSet/PartSet_WidgetShapeSelector.cpp b/src/PartSet/PartSet_WidgetShapeSelector.cpp index cea864a6a..a4dbf44f6 100644 --- a/src/PartSet/PartSet_WidgetShapeSelector.cpp +++ b/src/PartSet/PartSet_WidgetShapeSelector.cpp @@ -21,6 +21,13 @@ #include +#include +#include +#include +#include +#include +#include + PartSet_WidgetShapeSelector::PartSet_WidgetShapeSelector(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop, const Config_WidgetAPI* theData, @@ -63,6 +70,67 @@ bool PartSet_WidgetShapeSelector::setObject(ObjectPtr theSelectedObject, GeomSha return ModuleBase_WidgetShapeSelector::setObject(aSelectedObject, theShape); } +//******************************************************************** +GeomShapePtr PartSet_WidgetShapeSelector::getShape() const +{ + // an empty shape by default + GeomShapePtr aShape; + + // 1. find an attribute value in attribute reference attribute value + DataPtr aData = myFeature->data(); + AttributePtr aAttr = aData->attribute(attributeID()); + AttributeRefAttrPtr aRefAttr = + std::dynamic_pointer_cast(aAttr); + if (aRefAttr) { + if (!aRefAttr->isObject()) { + AttributePtr anAttribute = aRefAttr->attr(); + if (anAttribute.get()) { + XGUI_ModuleConnector* aConnector = dynamic_cast(myWorkshop); + XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer(); + + // 2. find visualized vertices of the attribute and if the attribute of the vertex is + // the same, return it + FeaturePtr anAttributeFeature = ModelAPI_Feature::feature(anAttribute->owner()); + // 2.1 get visualized results of the feature + const std::list& aResList = anAttributeFeature->results(); + std::list::const_iterator anIt = aResList.begin(), aLast = aResList.end(); + for (; anIt != aLast; anIt++) { + AISObjectPtr aAISObj = aDisplayer->getAISObject(*anIt); + if (aAISObj.get() != NULL) { + Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl(); + // 2.2 find selected owners of a visualizedd object + SelectMgr_IndexedMapOfOwner aSelectedOwners; + aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners); + for (Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++) { + Handle(SelectMgr_EntityOwner) anOwner = aSelectedOwners(i); + if (!anOwner.IsNull()) { + Handle(StdSelect_BRepOwner) aBRepOwner = Handle(StdSelect_BRepOwner)::DownCast(anOwner); + if (!aBRepOwner.IsNull() && aBRepOwner->HasShape()) { + const TopoDS_Shape& aBRepShape = aBRepOwner->Shape(); + if (aBRepShape.ShapeType() == TopAbs_VERTEX) { + // 2.3 if the owner is vertex and an attribute of the vertex is equal to the initial + // attribute, returns the shape + AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(anAttributeFeature, + aBRepShape, sketch()); + if (aPntAttr.get() != NULL && aPntAttr == anAttribute) { + aShape = std::shared_ptr(new GeomAPI_Shape); + aShape->setImpl(new TopoDS_Shape(aBRepShape)); + break; + } + } + } + } + } + } + } + } + } + } + if (!aShape.get()) + aShape = ModuleBase_WidgetShapeSelector::getShape(); + return aShape; +} + //******************************************************************** void PartSet_WidgetShapeSelector::restoreAttributeValue(const bool theValid) { diff --git a/src/PartSet/PartSet_WidgetShapeSelector.h b/src/PartSet/PartSet_WidgetShapeSelector.h index f300db7e8..050b64e27 100644 --- a/src/PartSet/PartSet_WidgetShapeSelector.h +++ b/src/PartSet/PartSet_WidgetShapeSelector.h @@ -49,6 +49,13 @@ protected: /// \param theShape a selected shape, which is used in the selection attribute virtual bool setObject(ObjectPtr theSelectedObject, GeomShapePtr theShape); + /// Get the shape from the attribute if the attribute contain a shape + /// It processes the ref attr type of attributes. It obtains the referenced attribute, + /// results of the attribute feature. And it founds a vertes in the owners of the results + /// If the vertex is found, it creates a geom shape on it. + /// \return a shape + virtual GeomShapePtr getShape() const; + /// Creates a backup of the current values of the attribute /// It should be realized in the specific widget because of different /// parameters of the current attribute diff --git a/src/XGUI/XGUI_Displayer.cpp b/src/XGUI/XGUI_Displayer.cpp index 5254c1ea6..83fa8010d 100644 --- a/src/XGUI/XGUI_Displayer.cpp +++ b/src/XGUI/XGUI_Displayer.cpp @@ -426,19 +426,16 @@ void XGUI_Displayer::setSelected(const QList& theValues, aContext->ClearSelected(); //if (aSelected.size() > 0) { foreach (ModuleBase_ViewerPrs aPrs, theValues) { - // if (isValidSelection(aPrs)) { - //foreach(ObjectPtr aResult, theResults) { - ObjectPtr anObject = aPrs.object(); - ResultPtr aResult = std::dynamic_pointer_cast(anObject); - if (aResult.get() && isVisible(aResult)) { - AISObjectPtr anObj = myResult2AISObjectMap[aResult]; - Handle(AIS_InteractiveObject) anAIS = anObj->impl(); - if (!anAIS.IsNull()) { - const TopoDS_Shape& aShape = aPrs.shape(); - if (!aShape.IsNull()) { - aContext->AddOrRemoveSelected(aShape, false); - } - else { + const TopoDS_Shape& aShape = aPrs.shape(); + if (!aShape.IsNull()) { + aContext->AddOrRemoveSelected(aShape, false); + } else { + ObjectPtr anObject = aPrs.object(); + ResultPtr aResult = std::dynamic_pointer_cast(anObject); + if (aResult.get() && isVisible(aResult)) { + AISObjectPtr anObj = myResult2AISObjectMap[aResult]; + Handle(AIS_InteractiveObject) anAIS = anObj->impl(); + if (!anAIS.IsNull()) { // The methods are replaced in order to provide multi-selection, e.g. restore selection // by activating multi selector widget. It also gives an advantage that the multi // selection in OB gives multi-selection in the viewer @@ -452,7 +449,6 @@ void XGUI_Displayer::setSelected(const QList& theValues, } else { aContext->UnhilightCurrents(); aContext->ClearCurrents(); - //foreach(ObjectPtr aResult, theResults) { foreach (ModuleBase_ViewerPrs aPrs, theValues) { ObjectPtr anObject = aPrs.object(); ResultPtr aResult = std::dynamic_pointer_cast(anObject); -- 2.39.2