/// \param theShape a shape
virtual bool acceptSubShape(std::shared_ptr<GeomAPI_Shape> 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();
/// \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
#include <XGUI_Workshop.h>
+#include <XGUI_ModuleConnector.h>
+#include <XGUI_Displayer.h>
+#include <XGUI_SelectionMgr.h>
+#include <XGUI_Selection.h>
+#include <SelectMgr_IndexedMapOfOwner.hxx>
+#include <StdSelect_BRepOwner.hxx>
+
PartSet_WidgetShapeSelector::PartSet_WidgetShapeSelector(QWidget* theParent,
ModuleBase_IWorkshop* theWorkshop,
const Config_WidgetAPI* theData,
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<ModelAPI_AttributeRefAttr>(aAttr);
+ if (aRefAttr) {
+ if (!aRefAttr->isObject()) {
+ AttributePtr anAttribute = aRefAttr->attr();
+ if (anAttribute.get()) {
+ XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(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<ResultPtr>& aResList = anAttributeFeature->results();
+ std::list<ResultPtr>::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<Handle(AIS_InteractiveObject)>();
+ // 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<GeomAPI_Shape>(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)
{
/// \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
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<ModelAPI_Result>(anObject);
- if (aResult.get() && isVisible(aResult)) {
- AISObjectPtr anObj = myResult2AISObjectMap[aResult];
- Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
- 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<ModelAPI_Result>(anObject);
+ if (aResult.get() && isVisible(aResult)) {
+ AISObjectPtr anObj = myResult2AISObjectMap[aResult];
+ Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
+ 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
} else {
aContext->UnhilightCurrents();
aContext->ClearCurrents();
- //foreach(ObjectPtr aResult, theResults) {
foreach (ModuleBase_ViewerPrs aPrs, theValues) {
ObjectPtr anObject = aPrs.object();
ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);