]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
The validator shape_type is not used for the multi-selector and shape-selector control.
authornds <natalia.donis@opencascade.com>
Wed, 27 May 2015 07:51:38 +0000 (10:51 +0300)
committernds <natalia.donis@opencascade.com>
Wed, 27 May 2015 07:51:38 +0000 (10:51 +0300)
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.

src/GeomValidators/GeomValidators_ShapeType.cpp
src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp
src/ModuleBase/ModuleBase_WidgetMultiSelector.h
src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp
src/ModuleBase/ModuleBase_WidgetShapeSelector.h
src/PartSet/PartSet_WidgetMultiSelector.cpp

index 2fbf7cad7ba16e2edd33b6adeade542d1e326ef6..50c4bcdb232b93fa3d077c2e057713a41ed6b842 100644 (file)
@@ -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())
index 298259260674750e49ed815e300f7e068512185d..ff8d200a09b138a54c8f0701a963fe927faade28 100644 (file)
@@ -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<ModelAPI_Validator*>& theValidators,
                                         std::list<std::list<std::string> >& theArguments) const
 {
+  return;
   std::list<std::string> 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<ModuleBase_ViewerPrs>& theValues,
                                                   int& thePosition)
@@ -254,11 +289,9 @@ bool ModuleBase_WidgetMultiSelector::setSelection(const QList<ModuleBase_ViewerP
 bool ModuleBase_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());
@@ -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();
index b6fa60aed30361c8faea0168cb6ad26a770a350d..1670af098406575f8cf8a34756c964f865fc40c8 100644 (file)
@@ -124,6 +124,10 @@ protected slots:
   virtual void customValidators(std::list<ModelAPI_Validator*>& theValidators,
                                 std::list<std::list<std::string> >& 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_ */
index 1441e29579bc62ba5ff71b0b2c2388084366d04f..b021cb0b7e26ee335e0ec2a2bd350974258998e9 100644 (file)
@@ -234,17 +234,14 @@ void ModuleBase_WidgetShapeSelector::onSelectionChanged()
 }
 
 //********************************************************************
-/*bool ModuleBase_WidgetShapeSelector::acceptSubShape(std::shared_ptr<GeomAPI_Shape> theShape) const
+bool ModuleBase_WidgetShapeSelector::acceptSubShape(const TopoDS_Shape& theShape) const
 {
-  return true;
-
-  TopoDS_Shape aShape = theShape->impl<TopoDS_Shape>();
   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<ModelAPI_Validator*>& theValidators,
                                     std::list<std::list<std::string> >& theArguments) const
 {
+  return;
   theValidators.push_back(myShapeValidator);
 
   std::list<std::string> 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<TopoDS_Shape>();
+  if (!acceptSubShape(aTopoShape))
+    return false;
 
   setObject(aObject, aShape);
   return true;
index cd82144c1a50b8b247843f16177b43a9630bbab0..7bf94af85c8508783c2db72c934aa06b15299bc7 100644 (file)
@@ -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<GeomAPI_Shape> theShape) const;
+  bool acceptSubShape(const TopoDS_Shape& theShape) const;
 
   /// Clear attribute
   void clearAttribute();
index 43f066ea2337b8e935f502013489d968d4328e9f..3557582824af7eb5a5501986f1cef40f13cb8d91 100644 (file)
@@ -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());