]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Using validator in multi selector control for the "type_choice" key.
authornds <natalia.donis@opencascade.com>
Mon, 25 May 2015 11:26:48 +0000 (14:26 +0300)
committernds <natalia.donis@opencascade.com>
Mon, 25 May 2015 11:26:48 +0000 (14:26 +0300)
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.

13 files changed:
src/ExchangePlugin/plugin-Exchange.xml
src/FeaturesPlugin/boolean_widget.xml
src/FeaturesPlugin/extrusion_widget.xml
src/FeaturesPlugin/group_widget.xml
src/GeomAPI/GeomAPI_Shape.cpp
src/GeomAPI/GeomAPI_Shape.h
src/GeomValidators/GeomValidators_ShapeType.cpp
src/GeomValidators/GeomValidators_ShapeType.h
src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp
src/ModuleBase/ModuleBase_WidgetMultiSelector.h
src/ModuleBase/ModuleBase_WidgetValidated.cpp
src/ModuleBase/ModuleBase_WidgetValidated.h
src/SketchPlugin/plugin-Sketch.xml

index f478491fed0f0406b29dafb904437cdbd3fb1143..eb6cbe6d8873c07b491816537ae52e4d2985006c 100644 (file)
@@ -12,7 +12,7 @@
         <export_file_selector id="export_file_selector" type="save" title="Export file" path="">
           <validator id="ExchangePlugin_ExportFormat" parameters="BREP:BREP,STEP|STP:STEP,IGES:IGES-5.1,IGES:IGES-5.3" />
         </export_file_selector>
-        <multi_selector id="selection_list" tooltip="Select a set of objects" type_choice="Vertices Edges Faces Solids" /> 
+        <multi_selector id="selection_list" tooltip="Select a set of objects" type_choice="vertex edge face solid" /> 
       </feature>
     </group>
   </workbench>
index 040124714edbacb11d3476633954099f10dbac0d..b7798d9d91cf0f4890d1c6af39b41e958a1411bb 100644 (file)
@@ -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"
   />
   <multi_selector id="tool_objects" 
     label="Tool object" 
     icon=":icons/cut_tool.png" 
     tooltip="Select a tool solid"
-    type_choice="Solids"
+    type_choice="solid"
     concealment="true" >
        <validator id="PartSet_DifferentObjects"/>
   </multi_selector>-->
index 5783d542c91d650034452da3bccba393a648ea67..63995f9562e457f01797bb0431edc267f01d4ae7 100644 (file)
@@ -5,7 +5,7 @@
     label="Select a sketch face"
     icon=":icons/sketch.png"
     tooltip="Select a sketch face"
-    type_choice="Faces">
+    type_choice="face">
     <validator id="PartSet_SketchEntityValidator" parameters="Sketch"/>
   </multi_selector>
   <groupbox title="From">
@@ -53,7 +53,7 @@
     label="Select a sketch face"
     icon=":icons/sketch.png"
     tooltip="Select a sketch face"
-    type_choice="Faces">
+    type_choice="face">
     <validator id="PartSet_SketchEntityValidator" parameters="Sketch"/>
   </multi_selector>
   <shape_selector id="axis_object"
index 1b1825329df41ef62ca2d60134d503eeaf788bb2..2e7f988726774fbc36d9cf611ed5fc0c0006359e 100644 (file)
@@ -3,5 +3,5 @@
 <source>
   <multi_selector id="group_list" 
     tooltip="Select a set of objects" 
-    type_choice="Vertices Edges Faces Solids" /> 
+    type_choice="vertex edge face solid" /> 
 </source>
\ No newline at end of file
index 78d5105ee98e9e55bd110eba04b3445c85033c0c..07d3ac09c7bfff111563a5620c749a1ff598b605 100644 (file)
@@ -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<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
+  return aShape.ShapeType() == TopAbs_SOLID;
+}
+
 bool GeomAPI_Shape::computeSize(double& theXmin, double& theYmin, double& theZmin,
                                 double& theXmax, double& theYmax, double& theZmax) const
 {
index 8e2c22f9a41afe72addb07b7cb9c353fb3cf69b7..e4e05c476fd6dc8b626688f6e3439a82977c485b 100644 (file)
@@ -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,
index f5ce2fd0b396d52b27544c5ef3657d4028281391..b8012aedfbe741faef85d0ccb70d0c2e3093ce54 100644 (file)
@@ -8,7 +8,9 @@
 #include <GeomDataAPI_Point2D.h>
 
 #include <ModelAPI_Result.h>
-#include "ModelAPI_AttributeRefAttr.h"
+#include <ModelAPI_AttributeRefAttr.h>
+#include <ModelAPI_AttributeSelectionList.h>
+#include <ModelAPI_AttributeReference.h>
 
 #include <Events_Error.h>
 
@@ -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<ModelAPI_Result>(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<ModelAPI_AttributeSelectionList>(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<ModelAPI_AttributeSelection>(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<ModelAPI_AttributeRefAttr>(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<ModelAPI_AttributeReference>(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<ModelAPI_Result>(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;
 }
index ce3232d61b5074674f621dbff70dcc28a26d23b1..c55c4535b5402caf14f37ae58c30771d19c8c572 100644 (file)
@@ -10,6 +10,8 @@
 #include "GeomValidators.h"
 #include "ModelAPI_AttributeValidator.h"
 
+#include <GeomAPI_Shape.h>
+
 #include <string>
 
 /**
@@ -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
index 21518852ccabc90f2ae13b0049accf256f7aa3a0..976972a6077f72bfa81309459694cb10864464e7 100644 (file)
@@ -15,6 +15,8 @@
 #include <ModuleBase_Tools.h>
 #include <ModuleBase_Definitions.h>
 
+#include <GeomValidators_ShapeType.h>
+
 #include <ModelAPI_Data.h>
 #include <ModelAPI_Object.h>
 
@@ -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<ModelAPI_Validator*>& theValidators,
+                                        std::list<std::list<std::string> >& theArguments) const
+{
+  std::list<std::string> 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<ModuleBase_ViewerPrs>& theValues,
                                                   int& thePosition)
index 033b260b4888c3912ea80ef46cb338fd3cee7407..88950061685a23d5e773978cd1c74d32c8333661 100644 (file)
 #include <QString>
 #include <QStringList>
 #include <QPair>
+#include <QMap>
 
 class QWidget;
 class QListWidget;
 class QComboBox;
 class ModuleBase_IWorkshop;
+class GeomValidators_ShapeType;
 class QAction;
 
 
@@ -39,7 +41,7 @@ class QAction;
 * \code
 * <multi_selector id="group_list" 
 *    tooltip="Select a set of objects" 
-*    type_choice="Vertices Edges Faces Solids" /> 
+*    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<ModelAPI_Validator*>& theValidators,
+                                std::list<std::list<std::string> >& theArguments) const;
+
   /// Set current shape type for selection
   void setCurrentShapeType(const TopAbs_ShapeEnum theShapeType);
 
@@ -154,6 +163,9 @@ protected slots:
 
   /// Variable of GeomSelection
   QList<GeomSelection> mySelection;
+
+  /// A map of "type_choice" validators.
+  GeomValidators_ShapeType* myShapeValidator;
 };
 
 #endif /* MODULEBASE_WIDGETFILESELECTOR_H_ */
index 4dcf23973ff31c7239325deba633f9aa06dfabf9..619548f39916c93f810f1eee8a1267d93794de66 100644 (file)
@@ -97,6 +97,8 @@ bool ModuleBase_WidgetValidated::isValidAttribute() const
   std::list<std::list<std::string> > 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<ModelAPI_Validator*>& theValidators,
+                                          std::list<std::list<std::string> >& theArguments) const
+{
+}
+
 QList<ModuleBase_ViewerPrs> ModuleBase_WidgetValidated::getSelectedEntitiesOrObjects(
                                                   ModuleBase_ISelection* theSelection) const
 {
index 95f558029661cddad8f1bd80aafaa1a936600933..0ac6657e7d302fe66846362903933581a8412ec6 100644 (file)
@@ -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<ModelAPI_Validator*>& theValidators,
+                                std::list<std::list<std::string> >& 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
index 97830f944a99f256685bb442bf106db239ecf5f0..e8e95315dcb7c3b6e2a24433348d83dceb5f7de8 100644 (file)
         <sketch_multi_selector id="ConstraintMirrorList"
             label="List of objects"
             tooltip="Select list of mirroring objects"
-            type_choice="Edges"
+            type_choice="edge"
             use_external="true">
             <validator id="SketchPlugin_MirrorAttr" />
         </sketch_multi_selector>
         <sketch_multi_selector id="MultiTranslationList"
             label="List of objects"
             tooltip="Select list of translating objects"
-            type_choice="Edges"
+            type_choice="edge"
             use_external="true">
           <validator id="SketchPlugin_CopyValidator" />
         </sketch_multi_selector>
         <sketch_multi_selector id="MultiRotationList"
             label="List of objects"
             tooltip="Select list of rotating objects"
-            type_choice="Edges"
+            type_choice="edge"
             use_external="true">
           <validator id="SketchPlugin_CopyValidator" />
         </sketch_multi_selector>