From: nds Date: Tue, 27 Jan 2015 09:26:31 +0000 (+0300) Subject: Issue #326 Distance constraint on 2 preselected segments problem X-Git-Tag: V_1.0.0~17^2~9 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=c8269cebd1a72045f5c262283613a0143d19704d;p=modules%2Fshaper.git Issue #326 Distance constraint on 2 preselected segments problem --- diff --git a/src/PartSet/PartSet_WidgetShapeSelector.cpp b/src/PartSet/PartSet_WidgetShapeSelector.cpp index 86137696a..cd69a1998 100644 --- a/src/PartSet/PartSet_WidgetShapeSelector.cpp +++ b/src/PartSet/PartSet_WidgetShapeSelector.cpp @@ -7,6 +7,11 @@ #include "PartSet_WidgetShapeSelector.h" #include +#include +#include +#include +#include + #include #include @@ -40,6 +45,7 @@ bool PartSet_WidgetShapeSelector::storeValue() const if (aRefAttr) { TopoDS_Shape aShape = myShape->impl(); AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(mySelectedObject, aShape, 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 @@ -56,6 +62,69 @@ bool PartSet_WidgetShapeSelector::storeValue() const return ModuleBase_WidgetShapeSelector::storeValue(); } +//******************************************************************** +bool PartSet_WidgetShapeSelector::isValid(ObjectPtr theObj, std::shared_ptr theShape) +{ + // the method is redefined to analize the selected shape in validators + SessionPtr aMgr = ModelAPI_Session::get(); + ModelAPI_ValidatorsFactory* aFactory = aMgr->validators(); + std::list aValidators; + std::list > anArguments; + aFactory->validators(parentID(), attributeID(), aValidators, anArguments); + + // Check the type of selected object + std::list::iterator aValidator = aValidators.begin(); + bool isValid = true; + for (; aValidator != aValidators.end(); aValidator++) { + const ModelAPI_ResultValidator* aResValidator = + dynamic_cast(*aValidator); + if (aResValidator) { + isValid = false; + if (aResValidator->isValid(theObj)) { + isValid = true; + break; + } + } + } + if (!isValid) + return false; + + // Check the acceptability of the object and shape as validator attribute + AttributePtr aPntAttr; + DataPtr aData = myFeature->data(); + if (theShape.get() != NULL) { + AttributePtr aAttr = aData->attribute(attributeID()); + AttributeRefAttrPtr aRefAttr = + std::dynamic_pointer_cast(aAttr); + if (aRefAttr) { + TopoDS_Shape aShape = theShape->impl(); + aPntAttr = PartSet_Tools::findAttributeBy2dPoint(theObj, aShape, mySketch); + } + } + // Check the acceptability of the object as attribute + aValidator = aValidators.begin(); + std::list >::iterator aArgs = anArguments.begin(); + for (; aValidator != aValidators.end(); aValidator++, aArgs++) { + const ModelAPI_RefAttrValidator* aAttrValidator = + dynamic_cast(*aValidator); + if (aAttrValidator) { + if (aPntAttr.get() != NULL) + { + if (!aAttrValidator->isValid(myFeature, *aArgs, aPntAttr)) { + return false; + } + } + else + { + if (!aAttrValidator->isValid(myFeature, *aArgs, theObj)) { + return false; + } + } + } + } + return true; +} + //********************************************* bool PartSet_WidgetConstraintShapeSelector::storeValue() const { @@ -75,4 +144,3 @@ bool PartSet_WidgetConstraintShapeSelector::storeValue() const } return ModuleBase_WidgetShapeSelector::storeValue(); } - diff --git a/src/PartSet/PartSet_WidgetShapeSelector.h b/src/PartSet/PartSet_WidgetShapeSelector.h index d4cf72aff..8f187cd8b 100644 --- a/src/PartSet/PartSet_WidgetShapeSelector.h +++ b/src/PartSet/PartSet_WidgetShapeSelector.h @@ -30,6 +30,10 @@ Q_OBJECT void setSketcher(CompositeFeaturePtr theSketch) { mySketch = theSketch; } CompositeFeaturePtr sketch() const { return mySketch; } +protected: + /// Check the selected with validators if installed + virtual bool isValid(ObjectPtr theObj, std::shared_ptr theShape); + private: CompositeFeaturePtr mySketch; }; diff --git a/src/SketchPlugin/SketchPlugin_Validators.cpp b/src/SketchPlugin/SketchPlugin_Validators.cpp index c7117d4a8..d8d056f46 100644 --- a/src/SketchPlugin/SketchPlugin_Validators.cpp +++ b/src/SketchPlugin/SketchPlugin_Validators.cpp @@ -38,14 +38,15 @@ bool SketchPlugin_DistanceAttrValidator::isValid(const FeaturePtr& theFeature, bool SketchPlugin_DistanceAttrValidator::isValid( const AttributePtr& theAttribute, const std::list& theArguments ) const { - std::shared_ptr anAttr = - std::dynamic_pointer_cast(theAttribute); - if (anAttr) { - const ObjectPtr& anObj = theAttribute->owner(); - const FeaturePtr aFeature = std::dynamic_pointer_cast(anObj); - return isValid(aFeature, theArguments, anAttr->object()); - } - return true; // it may be not reference attribute, in this case, it is OK + // any point attribute is acceptable for the distance operation + return true; +} + +bool SketchPlugin_DistanceAttrValidator::isValid(const FeaturePtr& theFeature, + const std::list& theArguments, + const AttributePtr& theAttribute) const +{ + return isValid(theAttribute, theArguments); } bool SketchPlugin_DifferentObjectsValidator::isValid(const FeaturePtr& theFeature, diff --git a/src/SketchPlugin/SketchPlugin_Validators.h b/src/SketchPlugin/SketchPlugin_Validators.h index 2f675c4f4..0b3dcf2b0 100644 --- a/src/SketchPlugin/SketchPlugin_Validators.h +++ b/src/SketchPlugin/SketchPlugin_Validators.h @@ -24,7 +24,7 @@ class SketchPlugin_DistanceAttrValidator : public ModelAPI_RefAttrValidator //! Returns true if the attribute is good for the feature attribute virtual bool isValid(const FeaturePtr& theFeature, const std::list& theArguments, - const AttributePtr& theAttribute) const { return true; }; + const AttributePtr& theAttribute) const; }; /** diff --git a/src/SketchPlugin/plugin-Sketch.xml b/src/SketchPlugin/plugin-Sketch.xml index 712efa282..0f6201227 100644 --- a/src/SketchPlugin/plugin-Sketch.xml +++ b/src/SketchPlugin/plugin-Sketch.xml @@ -58,6 +58,7 @@ tooltip="Select point, line end point, line, center of circle or arc." shape_types="edge vertex"> + diff --git a/src/XGUI/XGUI_SelectionMgr.cpp b/src/XGUI/XGUI_SelectionMgr.cpp index b0d22089f..9eb43d499 100644 --- a/src/XGUI/XGUI_SelectionMgr.cpp +++ b/src/XGUI/XGUI_SelectionMgr.cpp @@ -18,6 +18,8 @@ #include #include +#include + XGUI_SelectionMgr::XGUI_SelectionMgr(XGUI_Workshop* theParent) : QObject(theParent), myWorkshop(theParent) @@ -57,6 +59,31 @@ void XGUI_SelectionMgr::setSelectedOwners(const SelectMgr_IndexedMapOfOwner& the } } +//************************************************************** +#include +void XGUI_SelectionMgr::updateSelectedOwners(bool isUpdateViewer) +{ + Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext(); + const SelectMgr_ListOfFilter& aFilters = aContext->Filters(); + + SelectMgr_IndexedMapOfOwner anOwnersToDeselect; + + SelectMgr_ListIteratorOfListOfFilter anIt(aFilters); + for (; anIt.More(); anIt.Next()) { + Handle(SelectMgr_Filter) aFilter = anIt.Value(); + for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) { + Handle(SelectMgr_EntityOwner) anOwner = aContext->SelectedOwner(); + if (!aFilter->IsOk(anOwner)) + anOwnersToDeselect.Add(aContext->SelectedOwner()); + } + } + + setSelectedOwners(anOwnersToDeselect, false); + + if (isUpdateViewer) + aContext->UpdateCurrentViewer(); +} + //************************************************************** void XGUI_SelectionMgr::onObjectBrowserSelection() { diff --git a/src/XGUI/XGUI_SelectionMgr.h b/src/XGUI/XGUI_SelectionMgr.h index f1665a746..6503f175d 100644 --- a/src/XGUI/XGUI_SelectionMgr.h +++ b/src/XGUI/XGUI_SelectionMgr.h @@ -43,6 +43,10 @@ Q_OBJECT void setSelectedOwners(const SelectMgr_IndexedMapOfOwner& theSelectedOwners, bool isUpdateViewer); + //! Check that the selected owners are valid for the current filters + /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly + void updateSelectedOwners(bool isUpdateViewer); + signals: //! Emited when selection in a one of viewers was changed void selectionChanged();