]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #326 Distance constraint on 2 preselected segments problem
authornds <natalia.donis@opencascade.com>
Tue, 27 Jan 2015 09:26:31 +0000 (12:26 +0300)
committernds <natalia.donis@opencascade.com>
Tue, 27 Jan 2015 09:26:31 +0000 (12:26 +0300)
src/PartSet/PartSet_WidgetShapeSelector.cpp
src/PartSet/PartSet_WidgetShapeSelector.h
src/SketchPlugin/SketchPlugin_Validators.cpp
src/SketchPlugin/SketchPlugin_Validators.h
src/SketchPlugin/plugin-Sketch.xml
src/XGUI/XGUI_SelectionMgr.cpp
src/XGUI/XGUI_SelectionMgr.h

index 86137696a5b3ee3751119d125c495eb4767e36d2..cd69a1998d2e0620624667848994846ae8003549 100644 (file)
@@ -7,6 +7,11 @@
 #include "PartSet_WidgetShapeSelector.h"
 
 #include <ModelAPI_AttributeRefAttr.h>
+#include <ModelAPI_Session.h>
+#include <ModelAPI_Validator.h>
+#include <ModelAPI_RefAttrValidator.h>
+#include <ModelAPI_ResultValidator.h>
+
 #include <PartSet_Tools.h>
 #include <SketchPlugin_Feature.h>
 
@@ -40,6 +45,7 @@ bool PartSet_WidgetShapeSelector::storeValue() const
       if (aRefAttr) {
         TopoDS_Shape aShape = myShape->impl<TopoDS_Shape>();
         AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(mySelectedObject, aShape, mySketch);
+
         // this is an alternative, whether the attribute should be set or object in the attribute
         // the first check is the attribute because the object already exist
         // the object is set only if there is no selected attribute
@@ -56,6 +62,69 @@ bool PartSet_WidgetShapeSelector::storeValue() const
   return ModuleBase_WidgetShapeSelector::storeValue();
 }
 
+//********************************************************************
+bool PartSet_WidgetShapeSelector::isValid(ObjectPtr theObj, std::shared_ptr<GeomAPI_Shape> theShape)
+{
+  // the method is redefined to analize the selected shape in validators
+  SessionPtr aMgr = ModelAPI_Session::get();
+  ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
+  std::list<ModelAPI_Validator*> aValidators;
+  std::list<std::list<std::string> > anArguments;
+  aFactory->validators(parentID(), attributeID(), aValidators, anArguments);
+
+  // Check the type of selected object
+  std::list<ModelAPI_Validator*>::iterator aValidator = aValidators.begin();
+  bool isValid = true;
+  for (; aValidator != aValidators.end(); aValidator++) {
+    const ModelAPI_ResultValidator* aResValidator =
+        dynamic_cast<const ModelAPI_ResultValidator*>(*aValidator);
+    if (aResValidator) {
+      isValid = false;
+      if (aResValidator->isValid(theObj)) {
+        isValid = true;
+        break;
+      }
+    }
+  }
+  if (!isValid)
+    return false;
+
+  // Check the acceptability of the object and shape as validator attribute
+  AttributePtr aPntAttr;
+  DataPtr aData = myFeature->data();
+  if (theShape.get() != NULL) {
+    AttributePtr aAttr = aData->attribute(attributeID());
+    AttributeRefAttrPtr aRefAttr = 
+      std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aAttr);
+    if (aRefAttr) {
+      TopoDS_Shape aShape = theShape->impl<TopoDS_Shape>();
+      aPntAttr = PartSet_Tools::findAttributeBy2dPoint(theObj, aShape, mySketch);
+    }
+  }
+  // Check the acceptability of the object as attribute
+  aValidator = aValidators.begin();
+  std::list<std::list<std::string> >::iterator aArgs = anArguments.begin();
+  for (; aValidator != aValidators.end(); aValidator++, aArgs++) {
+    const ModelAPI_RefAttrValidator* aAttrValidator =
+        dynamic_cast<const ModelAPI_RefAttrValidator*>(*aValidator);
+    if (aAttrValidator) {
+      if (aPntAttr.get() != NULL)
+      {
+        if (!aAttrValidator->isValid(myFeature, *aArgs, aPntAttr)) {
+          return false;
+        }
+      }
+      else
+      {
+        if (!aAttrValidator->isValid(myFeature, *aArgs, theObj)) {
+          return false;
+        }
+      }
+    }
+  }
+  return true;
+}
+
 //*********************************************
 bool PartSet_WidgetConstraintShapeSelector::storeValue() const
 {
@@ -75,4 +144,3 @@ bool PartSet_WidgetConstraintShapeSelector::storeValue() const
   }
   return ModuleBase_WidgetShapeSelector::storeValue();
 }
-
index d4cf72aff480fa7674bf953a116297c9760bdf41..8f187cd8b47b1d1f8074506210f471f690ce91b6 100644 (file)
@@ -30,6 +30,10 @@ Q_OBJECT
   void setSketcher(CompositeFeaturePtr theSketch) { mySketch = theSketch; }
   CompositeFeaturePtr sketch() const { return mySketch; }
 
+protected:
+  /// Check the selected with validators if installed
+  virtual bool isValid(ObjectPtr theObj, std::shared_ptr<GeomAPI_Shape> theShape);
+
 private:
   CompositeFeaturePtr mySketch;
 };
index c7117d4a8b7cc6f7dc079b5784f8963f0fca00aa..d8d056f46da98a190e2f48e2e856482ba4c1de20 100644 (file)
@@ -38,14 +38,15 @@ bool SketchPlugin_DistanceAttrValidator::isValid(const FeaturePtr& theFeature,
 bool SketchPlugin_DistanceAttrValidator::isValid(
   const AttributePtr& theAttribute, const std::list<std::string>& theArguments ) const
 {
-  std::shared_ptr<ModelAPI_AttributeRefAttr> anAttr = 
-    std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
-  if (anAttr) {
-    const ObjectPtr& anObj = theAttribute->owner();
-    const FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(anObj);
-    return isValid(aFeature, theArguments, anAttr->object());
-  }
-  return true; // it may be not reference attribute, in this case, it is OK
+  // any point attribute is acceptable for the distance operation
+  return true;
+}
+
+bool SketchPlugin_DistanceAttrValidator::isValid(const FeaturePtr& theFeature,
+                                                 const std::list<std::string>& theArguments,
+                                                 const AttributePtr& theAttribute) const
+{
+  return isValid(theAttribute, theArguments);
 }
 
 bool SketchPlugin_DifferentObjectsValidator::isValid(const FeaturePtr& theFeature,
index 2f675c4f4fcc46150eb1cfc8b70463fb49a1ff20..0b3dcf2b009fda9c283ebf874dfdc5ee868e9035 100644 (file)
@@ -24,7 +24,7 @@ class SketchPlugin_DistanceAttrValidator : public ModelAPI_RefAttrValidator
 
   //! Returns true if the attribute is good for the feature attribute
   virtual bool isValid(const FeaturePtr& theFeature, const std::list<std::string>& theArguments,
-                       const AttributePtr& theAttribute) const { return true; };
+                       const AttributePtr& theAttribute) const;
 };
 
 /**
index 712efa2829f58bd02cb97d496634e4821582890c..0f6201227b8d1027f9e3b2aa12ae990b84e1c364 100644 (file)
@@ -58,6 +58,7 @@
           tooltip="Select point, line end point, line, center of circle or arc." 
                            shape_types="edge vertex">
                        <validator id="SketchPlugin_DifferentObjects"/>
+      <validator id="SketchPlugin_DistanceAttr" parameters="ConstraintEntityA"/>
       <selection_filter id="MultiFilter" parameters="line,vertex"/>
     </sketch_shape_selector>
                
index b0d22089f8c3da6c6c7fe48836be2822bbe9225d..9eb43d499ee60d566e1aab807e23cd0eb6311d8e 100644 (file)
@@ -18,6 +18,8 @@
 #include <ModelAPI_Result.h>
 #include <ModelAPI_Object.h>
 
+#include <SelectMgr_ListIteratorOfListOfFilter.hxx>
+
 XGUI_SelectionMgr::XGUI_SelectionMgr(XGUI_Workshop* theParent)
     : QObject(theParent),
       myWorkshop(theParent)
@@ -57,6 +59,31 @@ void XGUI_SelectionMgr::setSelectedOwners(const SelectMgr_IndexedMapOfOwner& the
   }
 }
 
+//**************************************************************
+#include <SelectMgr_ListIteratorOfListOfFilter.hxx>
+void XGUI_SelectionMgr::updateSelectedOwners(bool isUpdateViewer)
+{
+  Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
+  const SelectMgr_ListOfFilter& aFilters = aContext->Filters();
+
+  SelectMgr_IndexedMapOfOwner anOwnersToDeselect;
+
+  SelectMgr_ListIteratorOfListOfFilter anIt(aFilters);
+  for (; anIt.More(); anIt.Next()) {
+    Handle(SelectMgr_Filter) aFilter = anIt.Value();
+    for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) {
+      Handle(SelectMgr_EntityOwner) anOwner = aContext->SelectedOwner();
+      if (!aFilter->IsOk(anOwner))
+        anOwnersToDeselect.Add(aContext->SelectedOwner());
+    }
+  }
+
+  setSelectedOwners(anOwnersToDeselect, false);
+
+  if (isUpdateViewer)
+    aContext->UpdateCurrentViewer();
+}
+
 //**************************************************************
 void XGUI_SelectionMgr::onObjectBrowserSelection()
 {
index f1665a7465203a6e0670d7d3c19df7272e7810d3..6503f175d93b27fa53d1f694b89d6929837d4b5f 100644 (file)
@@ -43,6 +43,10 @@ Q_OBJECT
   void setSelectedOwners(const SelectMgr_IndexedMapOfOwner& theSelectedOwners,
                          bool isUpdateViewer);
 
+  //! Check that the selected owners are valid for the current filters
+  /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
+  void updateSelectedOwners(bool isUpdateViewer);
+
 signals:
   //! Emited when selection in a one of viewers was changed
   void selectionChanged();