Salome HOME
Preselection in shape/multi shape selector controls.
authornds <natalia.donis@opencascade.com>
Mon, 15 Jun 2015 09:44:39 +0000 (12:44 +0300)
committernds <natalia.donis@opencascade.com>
Mon, 15 Jun 2015 16:27:54 +0000 (19:27 +0300)
src/ConstructionPlugin/ConstructionPlugin_Plane.cpp
src/GeomValidators/GeomValidators_Face.cpp
src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp
src/ModuleBase/ModuleBase_WidgetMultiSelector.h
src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp
src/ModuleBase/ModuleBase_WidgetShapeSelector.h
src/PartSet/PartSet_SketcherMgr.cpp

index 13ae2b36d65cb7fe6ca22bcdeb2f398b22172352..f5735151a29cab112b01ea15d6ceececd3eaa411 100644 (file)
@@ -95,6 +95,10 @@ std::shared_ptr<GeomAPI_Shape>  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<GeomAPI_Pln> aPln = GeomAlgoAPI_FaceBuilder::plane(aShape);
       std::shared_ptr<GeomAPI_Pnt> aOrig = aPln->location();
index 95d100d706bd4bcd5f5875533fbf8928c569eb51..c8797278b42d94c15b4674c65d4233594deac427 100644 (file)
@@ -46,6 +46,10 @@ bool GeomValidators_Face::isValid(const AttributePtr& theAttribute,
     AttributeSelectionPtr aSelectionAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>
                                                                  (theAttribute);
     std::shared_ptr<GeomAPI_Shape> 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)
index 59f10daf73db3713be30b202d29b58cb3fbe6b60..18b88a1457fe05d2d9f255b6594831d399a39686 100644 (file)
@@ -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 <memory>
 #include <string>
 
+//#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 QList<ModuleBase_ViewerP
 }
 
 //********************************************************************
-bool ModuleBase_WidgetMultiSelector::setSelectionCustom(const ModuleBase_ViewerPrs& thePrs)
+bool ModuleBase_WidgetMultiSelector::isValidSelectionCustom(const ModuleBase_ViewerPrs& thePrs)
 {
-  TopoDS_Shape aShape = thePrs.shape();
-  if (!acceptSubShape(aShape))
-    return false;
-
-  ResultPtr aResult;
-  if (!thePrs.owner().IsNull()) {
-    ObjectPtr anObject = myWorkshop->selection()->getSelectableObject(thePrs.owner());
-    aResult = std::dynamic_pointer_cast<ModelAPI_Result>(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<ModelAPI_Result>(thePrs.object());
+    // Check that the selection corresponds to selection type
+    TopoDS_Shape aTopoShape = aShape->impl<TopoDS_Shape>();
+    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<ResultPtr>& aResList = myFeature->results();
+      std::list<ResultPtr>::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<ResultPtr>& 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<ModelAPI_AttributeSelectionList>(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<QWidget*> 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()
 {
index 42ca970a5214d7d473341a26a5c53193170b26ab..c6c6a5c3b9f13e2cf7481b6352a066705725016b 100644 (file)
@@ -72,8 +72,6 @@ class MODULEBASE_EXPORT ModuleBase_WidgetMultiSelector : public ModuleBase_Widge
   /// \return a control list
   virtual QList<QWidget*> 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<ModuleBase_ViewerPrs>& 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);
index cf5f6549e2d2a230c8d42b28944796b30a615c09..34666e3b862bbfcdf11ef7dbc29be76c4c9ac39d 100644 (file)
@@ -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 <list>
 #include <string>
 
+//#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<TopoDS_Shape>();
+    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<ModelAPI_Result>(aObject);
-  if (!aRes)
-    return false;
+  //ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aObject);
+  //if (!aRes)
+  //  return false;
   /*if (myFeature) {
     // We can not select a result of our feature
     const std::list<std::shared_ptr<ModelAPI_Result>>& 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<GeomAPI_Shape>(new GeomAPI_Shape());
     aShape->setImpl(new TopoDS_Shape(thePrs.shape()));
   }
+
   // Check that the selection corresponds to selection type
   TopoDS_Shape aTopoShape = aShape->impl<TopoDS_Shape>();
   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;
 }
 
index ac6f0ef926b51ee4c2c59ab693c28c49fee956f3..e2b7f6ad6fc820ed8a7c932817ed6b8eb3834852 100644 (file)
@@ -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<QWidget*> 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);
index a84ea16094262d8c94ec20387de814a5eecc43fa..caf3218825096d347e4b7def4495a68105ef09dd 100644 (file)
@@ -24,8 +24,6 @@
 #include <XGUI_PropertyPanel.h>
 #include <XGUI_ViewerProxy.h>
 
-#include <AppElements_MainWindow.h>
-
 #include <ModuleBase_IViewer.h>
 #include <ModuleBase_IWorkshop.h>
 #include <ModuleBase_IViewWindow.h>