From: nds Date: Mon, 25 May 2015 11:26:48 +0000 (+0300) Subject: Using validator in multi selector control for the "type_choice" key. X-Git-Tag: V_1.2.0~97^2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=5bce2e602b6e47f3a56f9e0886baca1703342d2a;p=modules%2Fshaper.git Using validator in multi selector control for the "type_choice" key. The reason is: preselection for translation sketch operation by rectangle. The vertex shapes should not be used in the multi selector control. TODO: to use the same mechanizm for the shape selector control. --- diff --git a/src/ExchangePlugin/plugin-Exchange.xml b/src/ExchangePlugin/plugin-Exchange.xml index f478491fe..eb6cbe6d8 100644 --- a/src/ExchangePlugin/plugin-Exchange.xml +++ b/src/ExchangePlugin/plugin-Exchange.xml @@ -12,7 +12,7 @@ - + diff --git a/src/FeaturesPlugin/boolean_widget.xml b/src/FeaturesPlugin/boolean_widget.xml index 040124714..b7798d9d9 100644 --- a/src/FeaturesPlugin/boolean_widget.xml +++ b/src/FeaturesPlugin/boolean_widget.xml @@ -5,14 +5,14 @@ label="Main object" icon=":icons/cut_shape.png" tooltip="Select an object solid" - type_choice="Solids" + type_choice="solid" concealment="true" /> --> diff --git a/src/FeaturesPlugin/extrusion_widget.xml b/src/FeaturesPlugin/extrusion_widget.xml index 5783d542c..63995f956 100644 --- a/src/FeaturesPlugin/extrusion_widget.xml +++ b/src/FeaturesPlugin/extrusion_widget.xml @@ -5,7 +5,7 @@ label="Select a sketch face" icon=":icons/sketch.png" tooltip="Select a sketch face" - type_choice="Faces"> + type_choice="face"> @@ -53,7 +53,7 @@ label="Select a sketch face" icon=":icons/sketch.png" tooltip="Select a sketch face" - type_choice="Faces"> + type_choice="face"> + type_choice="vertex edge face solid" /> \ No newline at end of file diff --git a/src/GeomAPI/GeomAPI_Shape.cpp b/src/GeomAPI/GeomAPI_Shape.cpp index 78d5105ee..07d3ac09c 100644 --- a/src/GeomAPI/GeomAPI_Shape.cpp +++ b/src/GeomAPI/GeomAPI_Shape.cpp @@ -55,6 +55,12 @@ bool GeomAPI_Shape::isFace() const return aShape.ShapeType() == TopAbs_FACE; } +bool GeomAPI_Shape::isSolid() const +{ + const TopoDS_Shape& aShape = const_cast(this)->impl(); + return aShape.ShapeType() == TopAbs_SOLID; +} + bool GeomAPI_Shape::computeSize(double& theXmin, double& theYmin, double& theZmin, double& theXmax, double& theYmax, double& theZmax) const { diff --git a/src/GeomAPI/GeomAPI_Shape.h b/src/GeomAPI/GeomAPI_Shape.h index 8e2c22f9a..e4e05c476 100644 --- a/src/GeomAPI/GeomAPI_Shape.h +++ b/src/GeomAPI/GeomAPI_Shape.h @@ -36,6 +36,9 @@ class GEOMAPI_EXPORT GeomAPI_Shape : public GeomAPI_Interface /// Returns whether the shape is a face virtual bool isFace() const; + /// Returns whether the shape is a solid + virtual bool isSolid() const; + /// Computes boundary dimensions of the shape /// Returns False if it is not possible bool computeSize(double& theXmin, double& theYmin, double& theZmin, diff --git a/src/GeomValidators/GeomValidators_ShapeType.cpp b/src/GeomValidators/GeomValidators_ShapeType.cpp index f5ce2fd0b..b8012aedf 100644 --- a/src/GeomValidators/GeomValidators_ShapeType.cpp +++ b/src/GeomValidators/GeomValidators_ShapeType.cpp @@ -8,7 +8,9 @@ #include #include -#include "ModelAPI_AttributeRefAttr.h" +#include +#include +#include #include @@ -23,14 +25,17 @@ GeomValidators_ShapeType::TypeOfShape GeomValidators_ShapeType::shapeType(const { if (MyEdgeTypes.size() == 0) { MyEdgeTypes["vertex"] = Vertex; + MyEdgeTypes["edge"] = Edge; MyEdgeTypes["line"] = Line; MyEdgeTypes["circle"] = Circle; + MyEdgeTypes["solid"] = Solid; + MyEdgeTypes["face"] = Face; } std::string aType = std::string(theType.c_str()); if (MyEdgeTypes.find(aType) != MyEdgeTypes.end()) return MyEdgeTypes[aType]; - Events_Error::send("Edge type defined in XML is not implemented!"); + Events_Error::send("Shape type defined in XML is not implemented!"); return AnyShape; } @@ -55,36 +60,98 @@ bool GeomValidators_ShapeType::isValidArgument(const AttributePtr& theAttribute, if (aShapeType == AnyShape) return true; - ObjectPtr anObject = GeomValidators_Tools::getObject(theAttribute); - if (anObject.get() != NULL) { - FeaturePtr aFeature = ModelAPI_Feature::feature(anObject); - ResultPtr aResult = std::dynamic_pointer_cast(anObject); - if (aResult.get() != NULL) { - GeomShapePtr aShape = aResult->shape(); - if (aShape.get() != NULL) { - switch (aShapeType) { - case Line: - aValid = aShape->isEdge() && !GeomAPI_Curve(aShape).isCircle(); - break; - case Circle: - aValid = aShape->isEdge() && GeomAPI_Curve(aShape).isCircle(); - break; - case Vertex: - aValid = aShape->isVertex(); - break; - default: break; - } - } + AttributeSelectionListPtr aListAttr = + std::dynamic_pointer_cast(theAttribute); + if (aListAttr.get()) { + for (int i = 0; i < aListAttr->size(); i++) { + aValid = isValidAttribute(aListAttr->value(i), aShapeType); + if (!aValid) // if at least one attribute is invalid, the result is false + break; } } else { + aValid = isValidAttribute(theAttribute, aShapeType); + } + return aValid; +} + +bool GeomValidators_ShapeType::isValidAttribute(const AttributePtr& theAttribute, + const TypeOfShape theShapeType) const +{ + bool aValid = false; + + std::string anAttributeType = theAttribute->attributeType(); + + if (anAttributeType == ModelAPI_AttributeSelection::typeId()) { + AttributeSelectionPtr anAttr = std::dynamic_pointer_cast(theAttribute); + GeomShapePtr aShape = anAttr->value(); + if (aShape.get()) + aValid = isValidShape(aShape, theShapeType); + else + aValid = isValidObject(anAttr->context(), theShapeType); + } + else if (anAttributeType == ModelAPI_AttributeRefAttr::typeId()) { AttributeRefAttrPtr anAttr = std::dynamic_pointer_cast(theAttribute); if (anAttr.get() != NULL) { - if (aShapeType == Vertex) { + if (anAttr->isObject()) { + aValid = isValidObject(anAttr->object(), theShapeType); + } + else if (theShapeType == Vertex) { AttributePtr aRefAttr = anAttr->attr(); aValid = aRefAttr.get() != NULL && aRefAttr->attributeType() == GeomDataAPI_Point2D::typeId(); } } } + else if (anAttributeType == ModelAPI_AttributeReference::typeId()) { + AttributeReferencePtr anAttr = std::dynamic_pointer_cast(theAttribute); + if (anAttr.get() != NULL) + aValid = isValidObject(anAttr->value(), theShapeType); + } + return aValid; +} + +bool GeomValidators_ShapeType::isValidObject(const ObjectPtr& theObject, + const TypeOfShape theShapeType) const +{ + bool aValid = false; + if (theObject.get() != NULL) { + FeaturePtr aFeature = ModelAPI_Feature::feature(theObject); + ResultPtr aResult = std::dynamic_pointer_cast(theObject); + if (aResult.get() != NULL) { + GeomShapePtr aShape = aResult->shape(); + aValid = isValidShape(aShape, theShapeType); + } + } + return aValid; +} + +bool GeomValidators_ShapeType::isValidShape(const GeomShapePtr theShape, + const TypeOfShape theShapeType) const +{ + bool aValid = false; + + if (theShape.get() != NULL) { + switch (theShapeType) { + case Edge: + aValid = theShape->isEdge(); + break; + case Line: + aValid = theShape->isEdge() && !GeomAPI_Curve(theShape).isCircle(); + break; + case Circle: + aValid = theShape->isEdge() && GeomAPI_Curve(theShape).isCircle(); + break; + case Vertex: + aValid = theShape->isVertex(); + break; + case Solid: + aValid = theShape->isSolid(); + break; + case Face: + aValid = theShape->isFace(); + break; + default: break; + } + } return aValid; } diff --git a/src/GeomValidators/GeomValidators_ShapeType.h b/src/GeomValidators/GeomValidators_ShapeType.h index ce3232d61..c55c4535b 100644 --- a/src/GeomValidators/GeomValidators_ShapeType.h +++ b/src/GeomValidators/GeomValidators_ShapeType.h @@ -10,6 +10,8 @@ #include "GeomValidators.h" #include "ModelAPI_AttributeValidator.h" +#include + #include /** @@ -26,8 +28,11 @@ class GeomValidators_ShapeType : public ModelAPI_AttributeValidator { AnyShape, Vertex, + Edge, Line, - Circle + Circle, + Solid, + Face }; public: @@ -45,6 +50,24 @@ protected: bool isValidArgument(const AttributePtr& theAttribute, const std::string& theArgument) const; + /// Returns true if the attibute's object type satisfies the argument value + /// \param theAttribute a checked attribute + /// \param theArgument a parameter + bool isValidAttribute(const AttributePtr& theAttribute, + const TypeOfShape theShapeType) const; + + /// Returns true if the attibute's object type satisfies the argument value + /// \param theAttribute a checked object + /// \param theShapeType a shape type + bool isValidObject(const ObjectPtr& theObject, + const TypeOfShape theShapeType) const; + + /// Returns true if the attibute's object type satisfies the argument value + /// \param theShape a checked shape + /// \param theShapeType a shape type + bool isValidShape(const GeomShapePtr theShape, + const TypeOfShape theShapeType) const; + }; #endif diff --git a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp index 21518852c..976972a60 100644 --- a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp @@ -15,6 +15,8 @@ #include #include +#include + #include #include @@ -50,6 +52,8 @@ ModuleBase_WidgetMultiSelector::ModuleBase_WidgetMultiSelector(QWidget* theParen myTypeCombo = new QComboBox(this); // There is no sence to paramerize list of types while we can not parametrize selection mode + myShapeValidator = new GeomValidators_ShapeType(); + std::string aPropertyTypes = theData->getProperty("type_choice"); QString aTypesStr = aPropertyTypes.c_str(); QStringList aShapeTypes = aTypesStr.split(' '); @@ -96,6 +100,8 @@ ModuleBase_WidgetMultiSelector::~ModuleBase_WidgetMultiSelector() { activateShapeSelection(false); activateFilters(myWorkshop, false); + + delete myShapeValidator; } //******************************************************************** @@ -200,6 +206,19 @@ void ModuleBase_WidgetMultiSelector::restoreAttributeValue(bool/* theValid*/) } } +//******************************************************************** +void ModuleBase_WidgetMultiSelector::customValidators( + std::list& theValidators, + std::list >& theArguments) const +{ + std::list anArguments; + + theValidators.push_back(myShapeValidator); + QString aType = myTypeCombo->currentText(); + anArguments.push_back(aType.toStdString().c_str()); + theArguments.push_back(anArguments); +} + //******************************************************************** bool ModuleBase_WidgetMultiSelector::setSelection(const QList& theValues, int& thePosition) diff --git a/src/ModuleBase/ModuleBase_WidgetMultiSelector.h b/src/ModuleBase/ModuleBase_WidgetMultiSelector.h index 033b260b4..889500616 100644 --- a/src/ModuleBase/ModuleBase_WidgetMultiSelector.h +++ b/src/ModuleBase/ModuleBase_WidgetMultiSelector.h @@ -24,11 +24,13 @@ #include #include #include +#include class QWidget; class QListWidget; class QComboBox; class ModuleBase_IWorkshop; +class GeomValidators_ShapeType; class QAction; @@ -39,7 +41,7 @@ class QAction; * \code * +* type_choice="vertex edge face solid" /> * \endcode * It uses folloing parameters: * - id - is a name of corresponded attribute @@ -115,6 +117,13 @@ protected slots: /// \param theValid a boolean flag, if restore happens for valid parameters virtual void restoreAttributeValue(const bool theValid); + /// Puts additional validators to the given list. A separate validator is created for each of the + /// "type_choice" value + /// \param theValidators a list of validators + /// \param theArguments a list of validators arguments + virtual void customValidators(std::list& theValidators, + std::list >& theArguments) const; + /// Set current shape type for selection void setCurrentShapeType(const TopAbs_ShapeEnum theShapeType); @@ -154,6 +163,9 @@ protected slots: /// Variable of GeomSelection QList mySelection; + + /// A map of "type_choice" validators. + GeomValidators_ShapeType* myShapeValidator; }; #endif /* MODULEBASE_WIDGETFILESELECTOR_H_ */ diff --git a/src/ModuleBase/ModuleBase_WidgetValidated.cpp b/src/ModuleBase/ModuleBase_WidgetValidated.cpp index 4dcf23973..619548f39 100644 --- a/src/ModuleBase/ModuleBase_WidgetValidated.cpp +++ b/src/ModuleBase/ModuleBase_WidgetValidated.cpp @@ -97,6 +97,8 @@ bool ModuleBase_WidgetValidated::isValidAttribute() const std::list > anArguments; aFactory->validators(myFeature->getKind(), attributeID(), aValidators, anArguments); + customValidators(aValidators, anArguments); + DataPtr aData = myFeature->data(); AttributePtr anAttribute = myFeature->attribute(attributeID()); @@ -125,6 +127,11 @@ void ModuleBase_WidgetValidated::activateFilters(ModuleBase_IWorkshop* theWorksh aViewer->removeSelectionFilter(aSelFilter); } +void ModuleBase_WidgetValidated::customValidators(std::list& theValidators, + std::list >& theArguments) const +{ +} + QList ModuleBase_WidgetValidated::getSelectedEntitiesOrObjects( ModuleBase_ISelection* theSelection) const { diff --git a/src/ModuleBase/ModuleBase_WidgetValidated.h b/src/ModuleBase/ModuleBase_WidgetValidated.h index 95f558029..0ac6657e7 100644 --- a/src/ModuleBase/ModuleBase_WidgetValidated.h +++ b/src/ModuleBase/ModuleBase_WidgetValidated.h @@ -19,6 +19,7 @@ class QWidget; class ModuleBase_IWorkshop; class ModuleBase_ISelection; +class ModelAPI_Validator; class Config_WidgetAPI; class Handle_SelectMgr_EntityOwner; @@ -79,6 +80,12 @@ protected: /// \param toActivate a flag about activation or deactivation the filters virtual void activateFilters(ModuleBase_IWorkshop* theWorkshop, const bool toActivate) const; + /// Puts additional validators to the given list + /// \param theValidators a list of validators + /// \param theArguments a list of validators arguments + virtual void customValidators(std::list& theValidators, + std::list >& theArguments) const; + /// Returns a list of selected presentations. Firstly it is obtained from the viewer, /// if there are not selected objects in the viewer, it get the selection from the object browser. /// If the browser has selected objects, the viewer prs objects are created with only object diff --git a/src/SketchPlugin/plugin-Sketch.xml b/src/SketchPlugin/plugin-Sketch.xml index 97830f944..e8e95315d 100644 --- a/src/SketchPlugin/plugin-Sketch.xml +++ b/src/SketchPlugin/plugin-Sketch.xml @@ -251,7 +251,7 @@ @@ -264,7 +264,7 @@ @@ -293,7 +293,7 @@