From: nds Date: Thu, 18 Jun 2015 07:53:38 +0000 (+0300) Subject: Preselection using in operations: using of external objects correction. X-Git-Tag: V_1.3.0~224 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=712106d47166b3e14b11494b07d112fd35d4e65a;p=modules%2Fshaper.git Preselection using in operations: using of external objects correction. --- diff --git a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp index be3ce6ec6..a74c2758c 100644 --- a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp @@ -195,6 +195,18 @@ void ModuleBase_WidgetMultiSelector::storeAttributeValue() } } +//******************************************************************** +void ModuleBase_WidgetMultiSelector::setObject(ObjectPtr theSelectedObject, + GeomShapePtr theShape) +{ + DataPtr aData = myFeature->data(); + AttributeSelectionListPtr aSelectionListAttr = + std::dynamic_pointer_cast(aData->attribute(attributeID())); + + ResultPtr aResult = std::dynamic_pointer_cast(aResult); + aSelectionListAttr->append(aResult, theShape); +} + //******************************************************************** void ModuleBase_WidgetMultiSelector::restoreAttributeValue(bool/* theValid*/) { @@ -211,7 +223,7 @@ void ModuleBase_WidgetMultiSelector::restoreAttributeValue(bool/* theValid*/) // Store selection in the attribute int aSize = mySelection.size(); foreach (GeomSelection aSelec, mySelection) { - aSelectionListAttr->append(aSelec.first, aSelec.second); + setObject(aSelec.first, aSelec.second); } } @@ -316,50 +328,12 @@ bool ModuleBase_WidgetMultiSelector::isValidSelectionCustom(const ModuleBase_Vie //******************************************************************** bool ModuleBase_WidgetMultiSelector::setSelectionCustom(const ModuleBase_ViewerPrs& thePrs) { - //TopoDS_Shape aShape = thePrs.shape(); - //if (!acceptSubShape(aShape)) - // return false; - - ResultPtr aResult = myWorkshop->selection()->getResult(thePrs); - /* - if (myFeature) { - // We can not select a result of our feature - const std::list& aResList = myFeature->results(); - std::list::const_iterator aIt; - bool isSkipSelf = false; - for (aIt = aResList.cbegin(); aIt != aResList.cend(); ++aIt) { - if ((*aIt) == aResult) { - isSkipSelf = true; - break; - } - } - if(isSkipSelf) - return false; - }*/ + // DEBUG_THE_SAME_AS_SHAPE + ObjectPtr anObject; + GeomShapePtr aShape; + getGeomSelection(thePrs, anObject, aShape); - // if the result has the similar shap as the parameter shape, just the context is set to the - // selection list attribute. - DataPtr aData = myFeature->data(); - AttributeSelectionListPtr aSelectionListAttr = - std::dynamic_pointer_cast(aData->attribute(attributeID())); - - /*const TopoDS_Shape& aTDSShape = thePrs.shape(); - // if only result is selected, an empty shape is set to the model - if (aTDSShape.IsNull()) { - aSelectionListAttr->append(aResult, GeomShapePtr()); - } - else { - GeomShapePtr aShape(new GeomAPI_Shape()); - aShape->setImpl(new TopoDS_Shape(aTDSShape)); - // We can not select a result of our feature - if (aShape->isEqual(aResult->shape())) - aSelectionListAttr->append(aResult, GeomShapePtr()); - else - aSelectionListAttr->append(aResult, aShape); - }*/ - GeomShapePtr aShape = myWorkshop->selection()->getShape(thePrs); - aSelectionListAttr->append(aResult, aShape); - + setObject(anObject, aShape); return true; } @@ -475,6 +449,16 @@ QList ModuleBase_WidgetMultiSelector::getAttributeSelectio return aSelected; } +//******************************************************************** +void ModuleBase_WidgetMultiSelector::getGeomSelection(const ModuleBase_ViewerPrs& thePrs, + ObjectPtr& theObject, + GeomShapePtr& theShape) +{ + // DEBUG_THE_SAME_AS_SHAPE + theObject = myWorkshop->selection()->getResult(thePrs); + theShape = myWorkshop->selection()->getShape(thePrs); +} + //******************************************************************** void ModuleBase_WidgetMultiSelector::updateSelectionList(AttributeSelectionListPtr theList) { diff --git a/src/ModuleBase/ModuleBase_WidgetMultiSelector.h b/src/ModuleBase/ModuleBase_WidgetMultiSelector.h index a9f7c461c..83e37216a 100644 --- a/src/ModuleBase/ModuleBase_WidgetMultiSelector.h +++ b/src/ModuleBase/ModuleBase_WidgetMultiSelector.h @@ -103,7 +103,7 @@ protected slots: /// Slot is called on selection of list of selected items void onListSelection(); - protected: +protected: /// The methiod called when widget is activated virtual void activateCustom(); @@ -116,6 +116,13 @@ protected slots: /// parameters of the current attribute virtual void storeAttributeValue(); + /// Append 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 + void setObject(ObjectPtr theSelectedObject, GeomShapePtr theShape); + /// 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 @@ -138,10 +145,17 @@ protected slots: /// a shape. If the attribute do not uses the shape, it is empty QList getAttributeSelection() const; - protected: /// Update selection list void updateSelectionList(AttributeSelectionListPtr); + /// Return an object and geom shape by the viewer presentation + /// \param thePrs a selection + /// \param theObject an output object + /// \param theShape a shape of the selection + virtual void getGeomSelection(const ModuleBase_ViewerPrs& thePrs, + ObjectPtr& theObject, + GeomShapePtr& theShape); + /// Converts the XML defined type choice to the validator type /// For example, the "Edges" is converted to "edge" std::string validatorType(const QString& theType) const; diff --git a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp index 2fe1ab684..d24d2b65d 100644 --- a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp @@ -67,8 +67,6 @@ #include #include -//#define DEBUG_SHAPE_VALIDATION_PREVIOUS - ModuleBase_WidgetShapeSelector::ModuleBase_WidgetShapeSelector(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop, const Config_WidgetAPI* theData, @@ -114,21 +112,15 @@ bool ModuleBase_WidgetShapeSelector::storeValueCustom() const } //******************************************************************** -bool ModuleBase_WidgetShapeSelector::setObject(ObjectPtr theSelectedObject, +void ModuleBase_WidgetShapeSelector::setObject(ObjectPtr theSelectedObject, GeomShapePtr theShape) { - bool isChanged = false; - FeaturePtr aSelectedFeature = ModelAPI_Feature::feature(theSelectedObject); - if (aSelectedFeature == myFeature) // In order to avoid selection of the same object - return isChanged; - DataPtr aData = myFeature->data(); AttributeReferencePtr aRef = aData->reference(attributeID()); if (aRef) { ObjectPtr aObject = aRef->value(); if (!(aObject && aObject->isSame(theSelectedObject))) { aRef->setValue(theSelectedObject); - isChanged = true; } } else { AttributeRefAttrPtr aRefAttr = aData->refattr(attributeID()); @@ -136,18 +128,15 @@ bool ModuleBase_WidgetShapeSelector::setObject(ObjectPtr theSelectedObject, ObjectPtr aObject = aRefAttr->object(); if (!(aObject && aObject->isSame(theSelectedObject))) { aRefAttr->setObject(theSelectedObject); - isChanged = true; } } else { AttributeSelectionPtr aSelectAttr = aData->selection(attributeID()); ResultPtr aResult = std::dynamic_pointer_cast(theSelectedObject); if (aSelectAttr.get() != NULL) { aSelectAttr->setValue(aResult, theShape); - isChanged = true; } } } - return isChanged; } //******************************************************************** @@ -170,6 +159,15 @@ QList ModuleBase_WidgetShapeSelector::getAttributeSelectio return aSelected; } +//******************************************************************** +void ModuleBase_WidgetShapeSelector::getGeomSelection(const ModuleBase_ViewerPrs& thePrs, + ObjectPtr& theObject, + GeomShapePtr& theShape) +{ + theObject = myWorkshop->selection()->getResult(thePrs); + theShape = myWorkshop->selection()->getShape(thePrs); +} + //******************************************************************** void ModuleBase_WidgetShapeSelector::clearAttribute() { @@ -366,10 +364,6 @@ void ModuleBase_WidgetShapeSelector::restoreAttributeValue(bool theValid) //******************************************************************** bool ModuleBase_WidgetShapeSelector::isValidSelectionCustom(const ModuleBase_ViewerPrs& thePrs) { -#ifdef DEBUG_SHAPE_VALIDATION_PREVIOUS - return true; -#endif - GeomShapePtr aShape = myWorkshop->selection()->getShape(thePrs); bool aValid; // if there is no selected shape, the method returns true @@ -380,70 +374,23 @@ bool ModuleBase_WidgetShapeSelector::isValidSelectionCustom(const ModuleBase_Vie TopoDS_Shape aTopoShape = aShape->impl(); aValid = acceptSubShape(aTopoShape); } + if (aValid) { + // In order to avoid selection of the same object + ResultPtr aResult = myWorkshop->selection()->getResult(thePrs); + FeaturePtr aSelectedFeature = ModelAPI_Feature::feature(aResult); + aValid = aSelectedFeature != myFeature; + } return aValid; } //******************************************************************** bool ModuleBase_WidgetShapeSelector::setSelectionCustom(const ModuleBase_ViewerPrs& thePrs) { - bool isDone = false; - - ResultPtr aResult = myWorkshop->selection()->getResult(thePrs); - - // It should be checked by corresponded validator - //ObjectPtr aObject = thePrs.object(); - //ObjectPtr aCurrentObject = GeomValidators_Tools::getObject(myFeature->attribute(attributeID())); - /* - if ((!aCurrentObject) && (!aObject)) - return false;*/ - - // It should be checked by corresponded validator - // Check that the selected object is result (others can not be accepted) - //ResultPtr aRes = std::dynamic_pointer_cast(aObject); - //if (!aRes) - // return false; - /*if (myFeature) { - // We can not select a result of our feature - const std::list>& aResList = myFeature->results(); - std::list >::const_iterator aIt; - for (aIt = aResList.cbegin(); aIt != aResList.cend(); ++aIt) { - if ((*aIt) == aRes) - return false; - } - } - */ - // It should be checked by corresponded validator - /* - // Check that object belongs to active document or PartSet - DocumentPtr aDoc = aRes->document(); - SessionPtr aMgr = ModelAPI_Session::get(); - if (!(aDoc == aMgr->activeDocument()) && !(aDoc == aMgr->moduleDocument())) - return false;*/ - -#ifdef DEBUG_SHAPE_VALIDATION_PREVIOUS - // It should be checked by corresponded validator - // Check that the result has a shape - GeomShapePtr aShape = ModelAPI_Tools::shape(aRes); - if (!aShape) - return false; - - // Get sub-shapes from local selection - if (!thePrs.shape().IsNull()) { - aShape = std::shared_ptr(new GeomAPI_Shape()); - aShape->setImpl(new TopoDS_Shape(thePrs.shape())); - } - - // Check that the selection corresponds to selection type - TopoDS_Shape aTopoShape = aShape->impl(); - if (!acceptSubShape(aTopoShape)) - return false; -#else - // the difference is that the next method returns an empty shape if the result has the same shape - // to be checked for all cases and uncommented - GeomShapePtr aShape = myWorkshop->selection()->getShape(thePrs); -#endif + ObjectPtr anObject; + GeomShapePtr aShape; + getGeomSelection(thePrs, anObject, aShape); - setObject(aResult, aShape); + setObject(anObject, aShape); return true; } diff --git a/src/ModuleBase/ModuleBase_WidgetShapeSelector.h b/src/ModuleBase/ModuleBase_WidgetShapeSelector.h index 86494eb5d..b015a0bf3 100644 --- a/src/ModuleBase/ModuleBase_WidgetShapeSelector.h +++ b/src/ModuleBase/ModuleBase_WidgetShapeSelector.h @@ -136,7 +136,7 @@ protected: /// \param theSelectedObject an object /// \param theShape a selected shape, which is used in the selection attribute /// \return true if it is succeed - virtual bool setObject(ObjectPtr theSelectedObject, GeomShapePtr theShape); + virtual void setObject(ObjectPtr theSelectedObject, GeomShapePtr theShape); /// Get the shape from the attribute if the attribute contains a shape, e.g. selection attribute /// \return a shape @@ -147,6 +147,14 @@ protected: /// a shape. If the attribute do not uses the shape, it is empty QList getAttributeSelection() const; + /// Return an object and geom shape by the viewer presentation + /// \param thePrs a selection + /// \param theObject an output object + /// \param theShape a shape of the selection + virtual void getGeomSelection(const ModuleBase_ViewerPrs& thePrs, + ObjectPtr& theObject, + GeomShapePtr& theShape); + //----------- Class members ------------- protected: /// Label of the widget diff --git a/src/PartSet/PartSet_ExternalObjectsMgr.cpp b/src/PartSet/PartSet_ExternalObjectsMgr.cpp index bf1eeb9b2..9c3e4105d 100644 --- a/src/PartSet/PartSet_ExternalObjectsMgr.cpp +++ b/src/PartSet/PartSet_ExternalObjectsMgr.cpp @@ -9,6 +9,8 @@ #include +#include + #include PartSet_ExternalObjectsMgr::PartSet_ExternalObjectsMgr(const std::string& theExternal, const bool theDefaultValue) @@ -21,6 +23,22 @@ PartSet_ExternalObjectsMgr::PartSet_ExternalObjectsMgr(const std::string& theExt } } +bool PartSet_ExternalObjectsMgr::isValidObject(const ObjectPtr& theObject) +{ + bool aValid = true; + FeaturePtr aFeature = ModelAPI_Feature::feature(theObject); + // Do check using of external feature + std::shared_ptr aSPFeature = + std::dynamic_pointer_cast(aFeature); + + // Do check that we can use external feature + if (aSPFeature.get() != NULL && aSPFeature->isExternal() && !useExternal()) { + aValid = false; + } + + return aValid; +} + ObjectPtr PartSet_ExternalObjectsMgr::externalObject(const ObjectPtr& theSelectedObject, const GeomShapePtr& theShape, const CompositeFeaturePtr& theSketch) diff --git a/src/PartSet/PartSet_ExternalObjectsMgr.h b/src/PartSet/PartSet_ExternalObjectsMgr.h index 45f89a84c..03b809730 100644 --- a/src/PartSet/PartSet_ExternalObjectsMgr.h +++ b/src/PartSet/PartSet_ExternalObjectsMgr.h @@ -36,6 +36,8 @@ class PARTSET_EXPORT PartSet_ExternalObjectsMgr /// Returns the state whether the external object is used bool useExternal() const { return myUseExternal; } + bool isValidObject(const ObjectPtr& theObject); + /// Finds or create and external object /// \param theSelectedObject an object /// \param theShape a selected shape, which is used in the selection attribute @@ -47,7 +49,6 @@ class PARTSET_EXPORT PartSet_ExternalObjectsMgr ObjectPtr externalObjectValidated(const ObjectPtr& theSelectedObject, const GeomShapePtr& theShape, const CompositeFeaturePtr& theSketch); - // Removes the external presentation from the model /// \param theSketch a current sketch /// \param theFeature a current feature diff --git a/src/PartSet/PartSet_WidgetMultiSelector.cpp b/src/PartSet/PartSet_WidgetMultiSelector.cpp index 139be4ee3..19e6cc379 100644 --- a/src/PartSet/PartSet_WidgetMultiSelector.cpp +++ b/src/PartSet/PartSet_WidgetMultiSelector.cpp @@ -61,6 +61,17 @@ void PartSet_WidgetMultiSelector::onSelectionChanged() myExternalObjectMgr->removeUnusedExternalObjects(aListOfAttributeObjects, sketch(), myFeature); } +//******************************************************************** +bool PartSet_WidgetMultiSelector::isValidSelectionCustom(const ModuleBase_ViewerPrs& thePrs) +{ + bool aValid = ModuleBase_WidgetMultiSelector::isValidSelectionCustom(thePrs); + if (aValid) { + ObjectPtr anObject = myWorkshop->selection()->getResult(thePrs); + aValid = myExternalObjectMgr->isValidObject(anObject); + } + return aValid; +} + //******************************************************************** void PartSet_WidgetMultiSelector::storeAttributeValue() { @@ -78,88 +89,21 @@ void PartSet_WidgetMultiSelector::restoreAttributeValue(const bool theValid) myExternalObjectMgr->removeExternalValidated(sketch(), myFeature); } -//******************************************************************** -bool PartSet_WidgetMultiSelector::setSelectionCustom(const ModuleBase_ViewerPrs& thePrs) -{ - //TopoDS_Shape aShape = thePrs.shape(); - //if (!acceptSubShape(aShape)) - // return false; - - ResultPtr aResult = myWorkshop->selection()->getResult(thePrs); - /*if (myFeature) { - // We can not select a result of our feature - const std::list& aResList = myFeature->results(); - std::list::const_iterator aIt; - bool isSkipSelf = false; - for (aIt = aResList.cbegin(); aIt != aResList.cend(); ++aIt) { - if ((*aIt) == aResult) { - isSkipSelf = true; - break; - } - } - if(isSkipSelf) - return false; - }*/ - - /*GeomShapePtr aGShape = GeomShapePtr(); - const TopoDS_Shape& aTDSShape = thePrs.shape(); - // if only result is selected, an empty shape is set to the model - if (aTDSShape.IsNull()) { - //aSelectionListAttr->append(aResult, GeomShapePtr()); - } - else { - aGShape = std::shared_ptr(new GeomAPI_Shape()); - //GeomShapePtr aShape(new GeomAPI_Shape()); - aGShape->setImpl(new TopoDS_Shape(aTDSShape)); - // We can not select a result of our feature - if (aGShape->isEqual(aResult->shape())) { - //aSelectionListAttr->append(aResult, GeomShapePtr()); - aGShape = GeomShapePtr(); - } - else { - //aSelectionListAttr->append(aResult, aShape); - } - }*/ - - GeomShapePtr aGShape = myWorkshop->selection()->getShape(thePrs); - setObject(aResult, aGShape); - return true; -} - -//******************************************************************** -bool PartSet_WidgetMultiSelector::setObject(const ObjectPtr& theSelectedObject, - const GeomShapePtr& theShape) +void PartSet_WidgetMultiSelector::getGeomSelection(const ModuleBase_ViewerPrs& thePrs, + ObjectPtr& theObject, + GeomShapePtr& theShape) { - ObjectPtr aSelectedObject = theSelectedObject; - GeomShapePtr aShape = theShape; + ModuleBase_WidgetMultiSelector::getGeomSelection(thePrs, theObject, theShape); - FeaturePtr aSelectedFeature = ModelAPI_Feature::feature(aSelectedObject); - //if (aSelectedFeature == myFeature) // In order to avoid selection of the same object - // return false; - - // Do check using of external feature + FeaturePtr aSelectedFeature = ModelAPI_Feature::feature(theObject); std::shared_ptr aSPFeature = std::dynamic_pointer_cast(aSelectedFeature); - - // Do check that we can use external feature - if ((aSPFeature.get() != NULL) && aSPFeature->isExternal() && (!myExternalObjectMgr->useExternal())) - return false; - - if (aSPFeature.get() == NULL && aShape.get() != NULL && !aShape->isNull() && myExternalObjectMgr->useExternal()) { + // there is no a sketch feature is selected, but the shape exists, try to create an exernal object + if (aSPFeature.get() == NULL && theShape.get() != NULL && !theShape->isNull() && + myExternalObjectMgr->useExternal()) { if (myIsInVaildate) - aSelectedObject = myExternalObjectMgr->externalObjectValidated(theSelectedObject, theShape, sketch()); + theObject = myExternalObjectMgr->externalObjectValidated(theObject, theShape, sketch()); else - aSelectedObject = myExternalObjectMgr->externalObject(theSelectedObject, theShape, sketch()); + theObject = myExternalObjectMgr->externalObject(theObject, theShape, sketch()); } - - - ResultPtr aResult = std::dynamic_pointer_cast(aSelectedObject); - - DataPtr aData = myFeature->data(); - AttributeSelectionListPtr aSelectionListAttr = - std::dynamic_pointer_cast(aData->attribute(attributeID())); - - aSelectionListAttr->append(aResult, aShape); - - return true; } diff --git a/src/PartSet/PartSet_WidgetMultiSelector.h b/src/PartSet/PartSet_WidgetMultiSelector.h index 8b71001e8..5e1b4a766 100644 --- a/src/PartSet/PartSet_WidgetMultiSelector.h +++ b/src/PartSet/PartSet_WidgetMultiSelector.h @@ -46,15 +46,16 @@ Q_OBJECT /// Retrurns installed sketcher CompositeFeaturePtr sketch() const { return mySketch; } - /// Fills the attribute with the value of the selected owner - /// \param theOwner a selected owner - virtual bool setSelectionCustom(const ModuleBase_ViewerPrs& thePrs); - public slots: /// Slot is called on selection changed virtual void onSelectionChanged(); protected: + /// Checks the widget validity. By default, it returns true. + /// \param theValue a selected presentation in the view + /// \return a boolean value + virtual bool isValidSelectionCustom(const ModuleBase_ViewerPrs& thePrs); + /// 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 @@ -66,12 +67,13 @@ protected: /// \param theValid a boolean flag, if restore happens for valid parameters void restoreAttributeValue(const bool theValid); - /// 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 - bool setObject(const ObjectPtr& theSelectedObject, const GeomShapePtr& theShape); + /// Return an object and geom shape by the viewer presentation + /// \param thePrs a selection + /// \param theObject an output object + /// \param theShape a shape of the selection + virtual void getGeomSelection(const ModuleBase_ViewerPrs& thePrs, + ObjectPtr& theObject, + GeomShapePtr& theShape); protected: PartSet_ExternalObjectsMgr* myExternalObjectMgr; diff --git a/src/PartSet/PartSet_WidgetShapeSelector.cpp b/src/PartSet/PartSet_WidgetShapeSelector.cpp index a4dbf44f6..7fca13598 100644 --- a/src/PartSet/PartSet_WidgetShapeSelector.cpp +++ b/src/PartSet/PartSet_WidgetShapeSelector.cpp @@ -42,32 +42,44 @@ PartSet_WidgetShapeSelector::~PartSet_WidgetShapeSelector() delete myExternalObjectMgr; } -bool PartSet_WidgetShapeSelector::setObject(ObjectPtr theSelectedObject, GeomShapePtr theShape) +//******************************************************************** +bool PartSet_WidgetShapeSelector::isValidSelectionCustom(const ModuleBase_ViewerPrs& thePrs) { - ObjectPtr aSelectedObject = theSelectedObject; - //GeomShapePtr aShape = theShape; + bool aValid = ModuleBase_WidgetShapeSelector::isValidSelectionCustom(thePrs); + if (aValid) { + ObjectPtr anObject = myWorkshop->selection()->getResult(thePrs); + aValid = myExternalObjectMgr->isValidObject(anObject); + } + return aValid; +} - FeaturePtr aSelectedFeature = ModelAPI_Feature::feature(aSelectedObject); - if (aSelectedFeature == myFeature) // In order to avoid selection of the same object - return false; +//******************************************************************** +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 && theShape.get()) + setPointAttribute(theSelectedObject, theShape); + else + ModuleBase_WidgetShapeSelector::setObject(theSelectedObject, theShape); +} - // Do check that we can use external feature - if ((aSPFeature.get() != NULL) && aSPFeature->isExternal() && (!myExternalObjectMgr->useExternal())) - return false; - - if (aSPFeature.get() == NULL && theShape.get() != NULL && !theShape->isNull() && myExternalObjectMgr->useExternal()) { - aSelectedObject = myExternalObjectMgr->externalObject(theSelectedObject, theShape, sketch()); - } else { - // Processing of sketch object - if (theShape.get()) { - setPointAttribute(theSelectedObject, theShape); - return true; - } - } - return ModuleBase_WidgetShapeSelector::setObject(aSelectedObject, theShape); +void PartSet_WidgetShapeSelector::getGeomSelection(const ModuleBase_ViewerPrs& thePrs, + ObjectPtr& theObject, + GeomShapePtr& theShape) +{ + ModuleBase_WidgetShapeSelector::getGeomSelection(thePrs, theObject, theShape); + + FeaturePtr aSelectedFeature = ModelAPI_Feature::feature(theObject); + std::shared_ptr aSPFeature = + std::dynamic_pointer_cast(aSelectedFeature); + // there is no a sketch feature is selected, but the shape exists, try to create an exernal object + if (aSPFeature.get() == NULL && theShape.get() != NULL && !theShape->isNull() && + myExternalObjectMgr->useExternal()) + theObject = myExternalObjectMgr->externalObject(theObject, theShape, sketch()); } //******************************************************************** diff --git a/src/PartSet/PartSet_WidgetShapeSelector.h b/src/PartSet/PartSet_WidgetShapeSelector.h index 050b64e27..a2ba2d2bd 100644 --- a/src/PartSet/PartSet_WidgetShapeSelector.h +++ b/src/PartSet/PartSet_WidgetShapeSelector.h @@ -43,11 +43,25 @@ Q_OBJECT CompositeFeaturePtr sketch() const { return mySketch; } protected: + /// Checks the widget validity. By default, it returns true. + /// \param theValue a selected presentation in the view + /// \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 - virtual bool setObject(ObjectPtr theSelectedObject, GeomShapePtr theShape); + /// \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 theShape a shape of the selection + virtual void getGeomSelection(const ModuleBase_ViewerPrs& thePrs, + ObjectPtr& theObject, + 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,