From: nds Date: Wed, 27 May 2015 07:51:38 +0000 (+0300) Subject: The validator shape_type is not used for the multi-selector and shape-selector control. X-Git-Tag: V_1.2.0~63^2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=ead20a0065c5c4552f3e02c7d6f304110dc0e4e6;p=modules%2Fshaper.git The validator shape_type is not used for the multi-selector and shape-selector control. The reason is an extrusion feature. It should accept Sketch selected in the browser, but the Shape filter with the "Face" type deny it. So, temporary, the method acceptSubShape() is used instead of the custom validator mechanizm. --- diff --git a/src/GeomValidators/GeomValidators_ShapeType.cpp b/src/GeomValidators/GeomValidators_ShapeType.cpp index 2fbf7cad7..50c4bcdb2 100644 --- a/src/GeomValidators/GeomValidators_ShapeType.cpp +++ b/src/GeomValidators/GeomValidators_ShapeType.cpp @@ -30,7 +30,6 @@ GeomValidators_ShapeType::TypeOfShape GeomValidators_ShapeType::shapeType(const MyEdgeTypes["circle"] = Circle; MyEdgeTypes["solid"] = Solid; MyEdgeTypes["face"] = Face; - MyEdgeTypes["compound"] = Compound; } std::string aType = std::string(theType.c_str()); if (MyEdgeTypes.find(aType) != MyEdgeTypes.end()) diff --git a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp index 298259260..ff8d200a0 100644 --- a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp @@ -58,10 +58,12 @@ ModuleBase_WidgetMultiSelector::ModuleBase_WidgetMultiSelector(QWidget* theParen QString aTypesStr = aPropertyTypes.c_str(); QStringList aShapeTypes = aTypesStr.split(' '); + //myIsUseChoice = theData->getBooleanAttribute("use_choice", true); + myTypeCombo->addItems(aShapeTypes); aMainLay->addWidget(myTypeCombo, 0, 1); // if the xml definition contains one type, the controls to select a type should not be shown - if (aShapeTypes.size() == 1) { + if (aShapeTypes.size() == 1/* || !myIsUseChoice*/) { aTypeLabel->setVisible(false); myTypeCombo->setVisible(false); } @@ -211,14 +213,47 @@ void ModuleBase_WidgetMultiSelector::customValidators( std::list& theValidators, std::list >& theArguments) const { + return; std::list anArguments; theValidators.push_back(myShapeValidator); - QString aType = myTypeCombo->currentText(); - anArguments.push_back(validatorType(aType)); + if (true/*myIsUseChoice*/) { + QString aType = myTypeCombo->currentText(); + anArguments.push_back(validatorType(aType)); + } + else { + for(int i = 0, aCount = myTypeCombo->count(); i < aCount; i++) { + anArguments.push_back(validatorType(myTypeCombo->itemText(i))); + } + } theArguments.push_back(anArguments); } +//******************************************************************** +bool ModuleBase_WidgetMultiSelector::acceptSubShape(const TopoDS_Shape& theShape) const +{ + bool aValid = true; + if (theShape.IsNull()) { + aValid = true; // do not check the shape type if the shape is empty + // extrusion uses a sketch object selectected in Object browser + } + else { + aValid = false; + TopAbs_ShapeEnum aShapeType = theShape.ShapeType(); + if (myTypeCombo->count() > 1) { + TopAbs_ShapeEnum aType = ModuleBase_Tools::shapeType(myTypeCombo->currentText()); + aValid = aShapeType == aType; + } + else { + for(int i = 0, aCount = myTypeCombo->count(); i < aCount && !aValid; i++) { + TopAbs_ShapeEnum aType = ModuleBase_Tools::shapeType(myTypeCombo->itemText(i)); + aValid = aShapeType == aType; + } + } + } + return aValid; +} + //******************************************************************** bool ModuleBase_WidgetMultiSelector::setSelection(const QList& theValues, int& thePosition) @@ -254,11 +289,9 @@ bool ModuleBase_WidgetMultiSelector::setSelection(const QListcount() > 1) && (!aShape.IsNull())) { - TopAbs_ShapeEnum aType = ModuleBase_Tools::shapeType(myTypeCombo->currentText()); - if (aShape.ShapeType() != aType) - return false; - } + if (!acceptSubShape(aShape)) + return false; + ResultPtr aResult; if (!thePrs.owner().IsNull()) { ObjectPtr anObject = myWorkshop->selection()->getSelectableObject(thePrs.owner()); @@ -392,7 +425,13 @@ void ModuleBase_WidgetMultiSelector::activateShapeSelection(const bool isActivat if (isActivated) { QString aNewType = myTypeCombo->currentText(); QIntList aList; - aList.append(ModuleBase_Tools::shapeType(aNewType)); + if (true /*myIsUseChoice*/) { + aList.append(ModuleBase_Tools::shapeType(aNewType)); + } + else { + for(int i = 0, aCount = myTypeCombo->count(); i < aCount; i++) + aList.append(ModuleBase_Tools::shapeType(myTypeCombo->itemText(i))); + } myWorkshop->activateSubShapesSelection(aList); } else { myWorkshop->deactivateSubShapesSelection(); diff --git a/src/ModuleBase/ModuleBase_WidgetMultiSelector.h b/src/ModuleBase/ModuleBase_WidgetMultiSelector.h index b6fa60aed..1670af098 100644 --- a/src/ModuleBase/ModuleBase_WidgetMultiSelector.h +++ b/src/ModuleBase/ModuleBase_WidgetMultiSelector.h @@ -124,6 +124,10 @@ protected slots: virtual void customValidators(std::list& theValidators, std::list >& theArguments) const; + /// Returns true if selected shape corresponds to requested shape types + /// \param theShape a shape + bool acceptSubShape(const TopoDS_Shape& theShape) const; + /// Set current shape type for selection void setCurrentShapeType(const TopAbs_ShapeEnum theShapeType); @@ -170,6 +174,8 @@ protected slots: /// An instance of the "type_choice" validator. It is returns on validating in customValidator() GeomValidators_ShapeType* myShapeValidator; + + //bool myIsUseChoice; }; #endif /* MODULEBASE_WIDGETFILESELECTOR_H_ */ diff --git a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp index 1441e2957..b021cb0b7 100644 --- a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp @@ -234,17 +234,14 @@ void ModuleBase_WidgetShapeSelector::onSelectionChanged() } //******************************************************************** -/*bool ModuleBase_WidgetShapeSelector::acceptSubShape(std::shared_ptr theShape) const +bool ModuleBase_WidgetShapeSelector::acceptSubShape(const TopoDS_Shape& theShape) const { - return true; - - TopoDS_Shape aShape = theShape->impl(); foreach (QString aType, myShapeTypes) { - if (aShape.ShapeType() == ModuleBase_Tools::shapeType(aType)) + if (theShape.ShapeType() == ModuleBase_Tools::shapeType(aType)) return true; } return false; -}*/ +} //******************************************************************** GeomShapePtr ModuleBase_WidgetShapeSelector::getShape() const @@ -379,6 +376,7 @@ void ModuleBase_WidgetShapeSelector::customValidators( std::list& theValidators, std::list >& theArguments) const { + return; theValidators.push_back(myShapeValidator); std::list anArguments; @@ -435,8 +433,9 @@ bool ModuleBase_WidgetShapeSelector::setSelectionCustom(const ModuleBase_ViewerP aShape->setImpl(new TopoDS_Shape(thePrs.shape())); } // Check that the selection corresponds to selection type - //if (!acceptSubShape(aShape)) - // return false; + TopoDS_Shape aTopoShape = aShape->impl(); + if (!acceptSubShape(aTopoShape)) + return false; setObject(aObject, aShape); return true; diff --git a/src/ModuleBase/ModuleBase_WidgetShapeSelector.h b/src/ModuleBase/ModuleBase_WidgetShapeSelector.h index cd82144c1..7bf94af85 100644 --- a/src/ModuleBase/ModuleBase_WidgetShapeSelector.h +++ b/src/ModuleBase/ModuleBase_WidgetShapeSelector.h @@ -129,7 +129,7 @@ Q_OBJECT /// Returns true if selected shape corresponds to requested shape types /// \param theShape a shape - //virtual bool acceptSubShape(std::shared_ptr theShape) const; + bool acceptSubShape(const TopoDS_Shape& theShape) const; /// Clear attribute void clearAttribute(); diff --git a/src/PartSet/PartSet_WidgetMultiSelector.cpp b/src/PartSet/PartSet_WidgetMultiSelector.cpp index 43f066ea2..355758282 100644 --- a/src/PartSet/PartSet_WidgetMultiSelector.cpp +++ b/src/PartSet/PartSet_WidgetMultiSelector.cpp @@ -82,11 +82,9 @@ void PartSet_WidgetMultiSelector::restoreAttributeValue(const bool theValid) bool PartSet_WidgetMultiSelector::setSelectionCustom(const ModuleBase_ViewerPrs& thePrs) { TopoDS_Shape aShape = thePrs.shape(); - if ((myTypeCombo->count() > 1) && (!aShape.IsNull())) { - TopAbs_ShapeEnum aType = ModuleBase_Tools::shapeType(myTypeCombo->currentText()); - if (aShape.ShapeType() != aType) - return false; - } + if (!acceptSubShape(aShape)) + return false; + ResultPtr aResult; if (!thePrs.owner().IsNull()) { ObjectPtr anObject = myWorkshop->selection()->getSelectableObject(thePrs.owner());