From: nds Date: Thu, 21 Jan 2016 10:22:07 +0000 (+0300) Subject: ModuleBase_WidgetShapeSelector correction to process AttrRefAtt like MultiSelector... X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=c32e09dd5d71eb56fab9c23801ebf7c8e4cf31bb;p=modules%2Fshaper.git ModuleBase_WidgetShapeSelector correction to process AttrRefAtt like MultiSelector do. Remove this processing on PartSet level as ModelAPI is a common interface. --- diff --git a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp index c8250969a..1144a30a3 100755 --- a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp @@ -241,44 +241,6 @@ void ModuleBase_WidgetMultiSelector::storeAttributeValue() } } -//******************************************************************** -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); - ObjectPtr anObject; - GeomShapePtr aShape; - getGeomSelection(thePrs, anObject, aShape); - setObject(anObject, aShape); - } - } - else { - //ModuleBase_WidgetSelector::setSelectionCustom(thePrs); - - ObjectPtr anObject; - GeomShapePtr aShape; - getGeomSelection(thePrs, anObject, aShape); - setObject(anObject, aShape); - } - return true; -} - //******************************************************************** void ModuleBase_WidgetMultiSelector::restoreAttributeValue(bool theValid) { @@ -354,9 +316,14 @@ void ModuleBase_WidgetMultiSelector::setObject(ObjectPtr theSelectedObject, aRefListAttr->append(theSelectedObject); } else if (aType == ModelAPI_AttributeRefAttrList::typeId()) { - //AttributeRefAttrListPtr aRefAttrListAttr = - // std::dynamic_pointer_cast(anAttribute); - //aRefAttrListAttr->clear(); + AttributeRefAttrListPtr aRefAttrListAttr = + std::dynamic_pointer_cast(anAttribute); + + AttributePtr anAttribute = myWorkshop->module()->findAttribute(theSelectedObject, theShape); + if (anAttribute.get()) + aRefAttrListAttr->append(anAttribute); + else + aRefAttrListAttr->append(theSelectedObject); } } diff --git a/src/ModuleBase/ModuleBase_WidgetMultiSelector.h b/src/ModuleBase/ModuleBase_WidgetMultiSelector.h index 54ff6ddcf..7156e0517 100755 --- a/src/ModuleBase/ModuleBase_WidgetMultiSelector.h +++ b/src/ModuleBase/ModuleBase_WidgetMultiSelector.h @@ -116,10 +116,6 @@ 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 c5be67919..0f0b2c15a 100755 --- a/src/ModuleBase/ModuleBase_WidgetSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetSelector.cpp @@ -150,6 +150,17 @@ bool ModuleBase_WidgetSelector::isValidSelectionCustom(const ModuleBase_ViewerPr return aValid; } +//******************************************************************** +bool ModuleBase_WidgetSelector::setSelectionCustom(const ModuleBase_ViewerPrs& thePrs) +{ + ObjectPtr anObject; + GeomShapePtr aShape; + getGeomSelection(thePrs, anObject, aShape); + + setObject(anObject, aShape); + return true; +} + //******************************************************************** void ModuleBase_WidgetSelector::deactivate() { diff --git a/src/ModuleBase/ModuleBase_WidgetSelector.h b/src/ModuleBase/ModuleBase_WidgetSelector.h index 8a282c362..150a0ce34 100755 --- a/src/ModuleBase/ModuleBase_WidgetSelector.h +++ b/src/ModuleBase/ModuleBase_WidgetSelector.h @@ -51,6 +51,10 @@ Q_OBJECT /// \return a boolean value virtual bool isValidSelectionCustom(const ModuleBase_ViewerPrs& thePrs); + /// Fills the attribute with the value of the selected owner + /// \param thePrs a selected owner + virtual bool setSelectionCustom(const ModuleBase_ViewerPrs& thePrs); + /// The methiod called when widget is deactivated virtual void deactivate(); diff --git a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp index e062d4f09..1047536e9 100644 --- a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -120,9 +121,15 @@ void ModuleBase_WidgetShapeSelector::setObject(ObjectPtr theSelectedObject, } } else if (aType == ModelAPI_AttributeRefAttr::typeId()) { AttributeRefAttrPtr aRefAttr = aData->refattr(attributeID()); - ObjectPtr aObject = aRefAttr->object(); - if (!(aObject && aObject->isSame(theSelectedObject))) { - aRefAttr->setObject(theSelectedObject); + + AttributePtr anAttribute = myWorkshop->module()->findAttribute(theSelectedObject, theShape); + if (anAttribute.get()) + aRefAttr->setAttr(anAttribute); + else { + ObjectPtr aObject = aRefAttr->object(); + if (!(aObject && aObject->isSame(theSelectedObject))) { + aRefAttr->setObject(theSelectedObject); + } } } else if (aType == ModelAPI_AttributeSelection::typeId()) { AttributeSelectionPtr aSelectAttr = aData->selection(attributeID()); @@ -274,14 +281,3 @@ void ModuleBase_WidgetShapeSelector::restoreAttributeValue(bool theValid) aRefAttr->setAttr(myRefAttribute); } } - -//******************************************************************** -bool ModuleBase_WidgetShapeSelector::setSelectionCustom(const ModuleBase_ViewerPrs& thePrs) -{ - ObjectPtr anObject; - GeomShapePtr aShape; - getGeomSelection(thePrs, anObject, aShape); - - setObject(anObject, aShape); - return true; -} diff --git a/src/ModuleBase/ModuleBase_WidgetShapeSelector.h b/src/ModuleBase/ModuleBase_WidgetShapeSelector.h index a750c8033..2c8a10363 100644 --- a/src/ModuleBase/ModuleBase_WidgetShapeSelector.h +++ b/src/ModuleBase/ModuleBase_WidgetShapeSelector.h @@ -104,10 +104,6 @@ Q_OBJECT /// \return a list of shapes virtual QIntList getShapeTypes() const; - /// Fills the attribute with the value of the selected owner - /// \param thePrs a selected owner - virtual bool setSelectionCustom(const ModuleBase_ViewerPrs& thePrs); - /// Store the values to the model attribute of the widget. It casts this attribute to /// the specific type and set the given values /// \param theSelectedObject an object diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index e7502e84d..3dd75c7b7 100755 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -1046,9 +1046,23 @@ GeomShapePtr PartSet_Module::findShape(const AttributePtr& theAttribute) AttributePtr PartSet_Module::findAttribute(const ObjectPtr& theObject, const GeomShapePtr& theGeomShape) { - TopoDS_Shape aTDSShape = theGeomShape->impl(); - return PartSet_Tools::findAttributeBy2dPoint(theObject, aTDSShape, - mySketchMgr->activeSketch()); + AttributePtr anAttribute; + GeomShapePtr aGeomShape = theGeomShape; + if (!aGeomShape.get()) { + // processing shape of result, e.g. sketch circle center is selected, this is a result + // the geom shape is empty, the shape of result should be used + ResultPtr aResult = std::dynamic_pointer_cast(theObject); + if (aResult.get()) { + aGeomShape = aResult->shape(); + } + } + + if (aGeomShape.get()) { + TopoDS_Shape aTDSShape = aGeomShape->impl(); + return PartSet_Tools::findAttributeBy2dPoint(theObject, aTDSShape, + mySketchMgr->activeSketch()); + } + return anAttribute; } //****************************************************** diff --git a/src/PartSet/PartSet_WidgetShapeSelector.cpp b/src/PartSet/PartSet_WidgetShapeSelector.cpp index 0bbeb05e8..79e32272d 100755 --- a/src/PartSet/PartSet_WidgetShapeSelector.cpp +++ b/src/PartSet/PartSet_WidgetShapeSelector.cpp @@ -53,28 +53,6 @@ bool PartSet_WidgetShapeSelector::isValidSelectionCustom(const ModuleBase_Viewer return aValid; } -//******************************************************************** -void PartSet_WidgetShapeSelector::setObject(ObjectPtr theSelectedObject, GeomShapePtr theShape) -{ - FeaturePtr aSelectedFeature = ModelAPI_Feature::feature(theSelectedObject); - // Do check using of external feature - std::shared_ptr aSPFeature = - std::dynamic_pointer_cast(aSelectedFeature); - // Processing of sketch object - if (aSPFeature.get() != NULL) { - GeomShapePtr aShape = theShape; - if (!aShape.get()) { - ResultPtr aResult = std::dynamic_pointer_cast(theSelectedObject); - if (aResult.get()) { - aShape = aResult->shape(); - } - } - setPointAttribute(theSelectedObject, aShape); - } - else - ModuleBase_WidgetShapeSelector::setObject(theSelectedObject, theShape); -} - void PartSet_WidgetShapeSelector::getGeomSelection(const ModuleBase_ViewerPrs& thePrs, ObjectPtr& theObject, GeomShapePtr& theShape) @@ -118,39 +96,3 @@ void PartSet_WidgetShapeSelector::restoreAttributeValue(const bool theValid) myExternalObjectMgr->removeExternal(sketch(), myFeature, myWorkshop, true); } -//******************************************************************** -void PartSet_WidgetShapeSelector::setPointAttribute(ObjectPtr theSelectedObject, GeomShapePtr theShape) -{ - DataPtr aData = myFeature->data(); - AttributePtr aAttr = aData->attribute(attributeID()); - AttributeRefAttrPtr aRefAttr = - std::dynamic_pointer_cast(aAttr); - if (aRefAttr) { - // it is possible that the point feature is selected. It should be used itself - // instead of searching an attribute for the shape - bool aShapeIsResult = false; - /*ResultPtr aResult = std::dynamic_pointer_cast(theSelectedObject); - if (aResult.get() != NULL) { - GeomShapePtr aShapePtr = aResult->shape(); - // it is important to call isEqual of the shape of result. - // It is a GeomAPI_Vertex shape for the point. The shape of the parameter is - // GeomAPI_Shape. It is important to use the realization of the isEqual method from - // GeomAPI_Vertex class - aShapeIsResult = aShapePtr.get() != NULL && aShapePtr->isEqual(theShape); - }*/ - - AttributePtr aPntAttr; - if (!aShapeIsResult) { - TopoDS_Shape aTDSShape = theShape->impl(); - aPntAttr = PartSet_Tools::findAttributeBy2dPoint(theSelectedObject, aTDSShape, mySketch); - } - // this is an alternative, whether the attribute should be set or object in the attribute - // the first check is the attribute because the object already exist - // the object is set only if there is no selected attribute - // test case is - preselection for distance operation, which contains two points selected on lines - if (aPntAttr) - aRefAttr->setAttr(aPntAttr); - else - aRefAttr->setObject(theSelectedObject); - } -} diff --git a/src/PartSet/PartSet_WidgetShapeSelector.h b/src/PartSet/PartSet_WidgetShapeSelector.h index 4d2da507b..f6b836e2e 100644 --- a/src/PartSet/PartSet_WidgetShapeSelector.h +++ b/src/PartSet/PartSet_WidgetShapeSelector.h @@ -48,13 +48,6 @@ protected: /// \return a boolean value virtual bool isValidSelectionCustom(const ModuleBase_ViewerPrs& thePrs); - /// Store the values to the model attribute of the widget. It casts this attribute to - /// the specific type and set the given values - /// \param theSelectedObject an object - /// \param theShape a selected shape, which is used in the selection attribute - /// \return true if it is succeed - virtual void setObject(ObjectPtr theSelectedObject, GeomShapePtr theShape); - /// Return an object and geom shape by the viewer presentation /// \param thePrs a selection /// \param theObject an output object @@ -76,12 +69,6 @@ protected: /// \param theValid a boolean flag, if restore happens for valid parameters void restoreAttributeValue(const bool theValid); - /// Found the sketch point attribute by the shape and set it in the feature attribute - /// otherwise set the selected object - /// \param theSelectedObject an object - /// \param theShape a selected shape, which is used in the selection attribute - void setPointAttribute(ObjectPtr theSelectedObject, GeomShapePtr theShape); - protected: /// A reference to external objects manager PartSet_ExternalObjectsMgr* myExternalObjectMgr;