}
}
-//********************************************************************
-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<ModelAPI_AttributeRefAttrList>(anAttribute);
- bool isDone = false;
- if (!thePrs.shape().IsNull()) {
- GeomShapePtr aGeomShape = std::shared_ptr<GeomAPI_Shape>(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)
{
aRefListAttr->append(theSelectedObject);
}
else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
- //AttributeRefAttrListPtr aRefAttrListAttr =
- // std::dynamic_pointer_cast<ModelAPI_AttributeRefAttrList>(anAttribute);
- //aRefAttrListAttr->clear();
+ AttributeRefAttrListPtr aRefAttrListAttr =
+ std::dynamic_pointer_cast<ModelAPI_AttributeRefAttrList>(anAttribute);
+
+ AttributePtr anAttribute = myWorkshop->module()->findAttribute(theSelectedObject, theShape);
+ if (anAttribute.get())
+ aRefAttrListAttr->append(anAttribute);
+ else
+ aRefAttrListAttr->append(theSelectedObject);
}
}
/// 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();
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()
{
/// \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();
#include <ModuleBase_Tools.h>
#include <ModuleBase_FilterFactory.h>
#include <ModuleBase_Filter.h>
+#include <ModuleBase_IModule.h>
#include <Config_WidgetAPI.h>
#include <Events_Loop.h>
}
} 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());
aRefAttr->setAttr(myRefAttribute);
}
}
-
-//********************************************************************
-bool ModuleBase_WidgetShapeSelector::setSelectionCustom(const ModuleBase_ViewerPrs& thePrs)
-{
- ObjectPtr anObject;
- GeomShapePtr aShape;
- getGeomSelection(thePrs, anObject, aShape);
-
- setObject(anObject, aShape);
- return true;
-}
/// \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
AttributePtr PartSet_Module::findAttribute(const ObjectPtr& theObject,
const GeomShapePtr& theGeomShape)
{
- TopoDS_Shape aTDSShape = theGeomShape->impl<TopoDS_Shape>();
- 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<ModelAPI_Result>(theObject);
+ if (aResult.get()) {
+ aGeomShape = aResult->shape();
+ }
+ }
+
+ if (aGeomShape.get()) {
+ TopoDS_Shape aTDSShape = aGeomShape->impl<TopoDS_Shape>();
+ return PartSet_Tools::findAttributeBy2dPoint(theObject, aTDSShape,
+ mySketchMgr->activeSketch());
+ }
+ return anAttribute;
}
//******************************************************
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<SketchPlugin_Feature> aSPFeature =
- std::dynamic_pointer_cast<SketchPlugin_Feature>(aSelectedFeature);
- // Processing of sketch object
- if (aSPFeature.get() != NULL) {
- GeomShapePtr aShape = theShape;
- if (!aShape.get()) {
- ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(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)
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<ModelAPI_AttributeRefAttr>(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<ModelAPI_Result>(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<TopoDS_Shape>();
- 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);
- }
-}
/// \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
/// \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;