From: nds Date: Mon, 15 Jun 2015 09:44:39 +0000 (+0300) Subject: Preselection in shape/multi shape selector controls. X-Git-Tag: V_1.3.0~235 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=82649b17a20b5d5b6a66c876f6450eff1cfc28d6;p=modules%2Fshaper.git Preselection in shape/multi shape selector controls. --- diff --git a/src/ConstructionPlugin/ConstructionPlugin_Plane.cpp b/src/ConstructionPlugin/ConstructionPlugin_Plane.cpp index 13ae2b36d..f5735151a 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Plane.cpp +++ b/src/ConstructionPlugin/ConstructionPlugin_Plane.cpp @@ -95,6 +95,10 @@ std::shared_ptr ConstructionPlugin_Plane::createPlaneByFaceAndDi double aDist = aDistAttr->value(); GeomShapePtr aShape = aFaceAttr->value(); + if (!aShape.get()) { + aShape = aFaceAttr->context()->shape(); + } + if (aShape.get() != NULL) { std::shared_ptr aPln = GeomAlgoAPI_FaceBuilder::plane(aShape); std::shared_ptr aOrig = aPln->location(); diff --git a/src/GeomValidators/GeomValidators_Face.cpp b/src/GeomValidators/GeomValidators_Face.cpp index 95d100d70..c8797278b 100644 --- a/src/GeomValidators/GeomValidators_Face.cpp +++ b/src/GeomValidators/GeomValidators_Face.cpp @@ -46,6 +46,10 @@ bool GeomValidators_Face::isValid(const AttributePtr& theAttribute, AttributeSelectionPtr aSelectionAttr = std::dynamic_pointer_cast (theAttribute); std::shared_ptr aGeomShape = aSelectionAttr->value(); + if (!aGeomShape.get()) { + // if the shape is empty, apply the validator to the shape of result + aGeomShape = aSelectionAttr->context()->shape(); + } // it is necessary to check whether the shape is face in order to set in selection a value // with any type and check the type in this validator // It is realized to select any object in OB and filter it in this validator (sketch plane) diff --git a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp index 59f10daf7..18b88a145 100644 --- a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D /* * ModuleBase_WidgetMultiSelector.cpp @@ -36,6 +36,8 @@ #include #include +//#define DEBUG_SHAPE_VALIDATION_PREVIOUS + ModuleBase_WidgetMultiSelector::ModuleBase_WidgetMultiSelector(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop, const Config_WidgetAPI* theData, @@ -291,22 +293,54 @@ bool ModuleBase_WidgetMultiSelector::setSelection(const QListselection()->getSelectableObject(thePrs.owner()); - aResult = std::dynamic_pointer_cast(anObject); - } +#ifdef DEBUG_SHAPE_VALIDATION_PREVIOUS + return true; +#endif + GeomShapePtr aShape = myWorkshop->selection()->getShape(thePrs); + // if there is no selected shape, the method returns true + bool aValid; + if (!aShape.get()) + aValid = true; else { - aResult = std::dynamic_pointer_cast(thePrs.object()); + // Check that the selection corresponds to selection type + TopoDS_Shape aTopoShape = aShape->impl(); + aValid = acceptSubShape(aTopoShape); } + if (aValid) { + 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) + aValid = false; + } + + } + return aValid; +} + +//******************************************************************** +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(); @@ -320,7 +354,7 @@ bool ModuleBase_WidgetMultiSelector::setSelectionCustom(const ModuleBase_ViewerP } if(isSkipSelf) return false; - } + }*/ // if the result has the similar shap as the parameter shape, just the context is set to the // selection list attribute. @@ -328,7 +362,7 @@ bool ModuleBase_WidgetMultiSelector::setSelectionCustom(const ModuleBase_ViewerP AttributeSelectionListPtr aSelectionListAttr = std::dynamic_pointer_cast(aData->attribute(attributeID())); - const TopoDS_Shape& aTDSShape = thePrs.shape(); + /*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()); @@ -341,7 +375,10 @@ bool ModuleBase_WidgetMultiSelector::setSelectionCustom(const ModuleBase_ViewerP aSelectionListAttr->append(aResult, GeomShapePtr()); else aSelectionListAttr->append(aResult, aShape); - } + }*/ + GeomShapePtr aShape = myWorkshop->selection()->getShape(thePrs); + aSelectionListAttr->append(aResult, aShape); + return true; } @@ -354,13 +391,6 @@ QList ModuleBase_WidgetMultiSelector::getControls() const return result; } -//******************************************************************** -bool ModuleBase_WidgetMultiSelector::eventFilter(QObject* theObj, QEvent* theEvent) -{ - //TODO: Remove maybe? - return ModuleBase_ModelWidget::eventFilter(theObj, theEvent); -} - //******************************************************************** void ModuleBase_WidgetMultiSelector::onSelectionTypeChanged() { diff --git a/src/ModuleBase/ModuleBase_WidgetMultiSelector.h b/src/ModuleBase/ModuleBase_WidgetMultiSelector.h index 42ca970a5..c6c6a5c3b 100644 --- a/src/ModuleBase/ModuleBase_WidgetMultiSelector.h +++ b/src/ModuleBase/ModuleBase_WidgetMultiSelector.h @@ -72,8 +72,6 @@ class MODULEBASE_EXPORT ModuleBase_WidgetMultiSelector : public ModuleBase_Widge /// \return a control list virtual QList getControls() const; - virtual bool eventFilter(QObject* , QEvent* ); - /// The methiod called when widget is deactivated virtual void deactivate(); @@ -83,6 +81,11 @@ class MODULEBASE_EXPORT ModuleBase_WidgetMultiSelector : public ModuleBase_Widge /// \param thePosition an index in the list of values, the values should be get from the index virtual bool setSelection(const QList& theValues, int& thePosition); + /// 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); + /// Fills the attribute with the value of the selected owner /// \param theOwner a selected owner virtual bool setSelectionCustom(const ModuleBase_ViewerPrs& thePrs); diff --git a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp index cf5f6549e..34666e3b8 100644 --- a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D // File: ModuleBase_WidgetShapeSelector.h // Created: 2 June 2014 @@ -67,6 +67,7 @@ #include #include +//#define DEBUG_SHAPE_VALIDATION_PREVIOUS ModuleBase_WidgetShapeSelector::ModuleBase_WidgetShapeSelector(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop, @@ -383,23 +384,45 @@ void ModuleBase_WidgetShapeSelector::customValidators( theArguments.push_back(anArguments); } +//******************************************************************** +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 + if (!aShape.get()) + aValid = true; + else { + // Check that the selection corresponds to selection type + TopoDS_Shape aTopoShape = aShape->impl(); + aValid = acceptSubShape(aTopoShape); + } + 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())); + //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; + //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(); @@ -418,6 +441,7 @@ bool ModuleBase_WidgetShapeSelector::setSelectionCustom(const ModuleBase_ViewerP 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); @@ -429,12 +453,18 @@ bool ModuleBase_WidgetShapeSelector::setSelectionCustom(const ModuleBase_ViewerP 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 - setObject(aObject, aShape); + setObject(aResult, aShape); return true; } diff --git a/src/ModuleBase/ModuleBase_WidgetShapeSelector.h b/src/ModuleBase/ModuleBase_WidgetShapeSelector.h index ac6f0ef92..e2b7f6ad6 100644 --- a/src/ModuleBase/ModuleBase_WidgetShapeSelector.h +++ b/src/ModuleBase/ModuleBase_WidgetShapeSelector.h @@ -1,4 +1,4 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D // File: ModuleBase_WidgetShapeSelector.h // Created: 2 June 2014 @@ -79,6 +79,11 @@ Q_OBJECT /// \return a control list virtual QList getControls() const; + /// 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); + /// Fills the attribute with the value of the selected owner /// \param theOwner a selected owner virtual bool setSelectionCustom(const ModuleBase_ViewerPrs& thePrs); diff --git a/src/PartSet/PartSet_SketcherMgr.cpp b/src/PartSet/PartSet_SketcherMgr.cpp index a84ea1609..caf321882 100644 --- a/src/PartSet/PartSet_SketcherMgr.cpp +++ b/src/PartSet/PartSet_SketcherMgr.cpp @@ -24,8 +24,6 @@ #include #include -#include - #include #include #include