]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Union of validator and filter functionalities.
authornds <natalia.donis@opencascade.com>
Fri, 20 Mar 2015 07:34:55 +0000 (10:34 +0300)
committernds <natalia.donis@opencascade.com>
Fri, 20 Mar 2015 07:34:55 +0000 (10:34 +0300)
EdgeFilter and MultiFilter use is replaced by validator.

17 files changed:
src/ModuleBase/CMakeLists.txt
src/ModuleBase/ModuleBase_ISelection.h
src/ModuleBase/ModuleBase_PageWidget.cpp
src/ModuleBase/ModuleBase_ValidatorLinearEdge.cpp [new file with mode: 0644]
src/ModuleBase/ModuleBase_ValidatorLinearEdge.h [new file with mode: 0644]
src/ModuleBase/ModuleBase_ValidatorLinearEdgeOrVertex.cpp [new file with mode: 0644]
src/ModuleBase/ModuleBase_ValidatorLinearEdgeOrVertex.h [new file with mode: 0644]
src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp
src/ModuleBase/ModuleBase_WidgetMultiSelector.h
src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp
src/ModuleBase/ModuleBase_WidgetShapeSelector.h
src/ModuleBase/ModuleBase_WidgetValidated.cpp
src/ModuleBase/ModuleBase_WidgetValidated.h
src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_WidgetShapeSelector.cpp
src/SketchPlugin/plugin-Sketch.xml
src/XGUI/XGUI_Selection.h

index a7ad900d1a3e73c31a83527e2fe0868fa27a53d8..4508cf3c46b7af2148a938b2b7b2bd0f06f79b45 100644 (file)
@@ -37,6 +37,8 @@ SET(PROJECT_HEADERS
        ModuleBase_IViewer.h
        ModuleBase_WidgetLineEdit.h
        ModuleBase_WidgetMultiSelector.h
+       ModuleBase_ValidatorLinearEdge.h
+       ModuleBase_ValidatorLinearEdgeOrVertex.h
        ModuleBase_ViewerFilters.h
        ModuleBase_ResultPrs.h
        ModuleBase_IViewWindow.h
@@ -80,6 +82,8 @@ SET(PROJECT_SOURCES
        ModuleBase_DoubleSpinBox.cpp
        ModuleBase_WidgetLineEdit.cpp
        ModuleBase_WidgetMultiSelector.cpp
+       ModuleBase_ValidatorLinearEdge.cpp
+       ModuleBase_ValidatorLinearEdgeOrVertex.cpp
        ModuleBase_ViewerFilters.cpp
        ModuleBase_ResultPrs.cpp
        ModuleBase_WidgetLabel.cpp
index 29829a39e51f55031ce5732dd7e58d564633e368..a444e586713e2929c848feca2cc2342e2b5b050b 100644 (file)
@@ -18,6 +18,8 @@
 
 #include <QList>
 
+class Handle_SelectMgr_EntityOwner;
+
 /**
 * \ingroup GUI
 * A class which provides access to selection.
@@ -35,6 +37,12 @@ class ModuleBase_ISelection
   /// \return list of presentations
   virtual QList<ModuleBase_ViewerPrs> getHighlighted() const = 0;
 
+  /// Fills the viewer presentation parameters by the parameters from the owner
+  /// \param thePrs a container for selection
+  /// \param theOwner a selection owner
+  virtual void fillPresentation(ModuleBase_ViewerPrs& thePrs,
+                                const Handle_SelectMgr_EntityOwner& theOwner) const = 0;
+
   /**
    * Returns list of features currently selected in object browser
    */
index d3039cac5b12dcb8988409d01083463fc4bf62a3..9d32e79e7946699d7bb6c9f0d7e8866389eb5ee8 100644 (file)
@@ -11,6 +11,8 @@
 
 #include <QGridLayout>
 
+#include <iostream>
+
 ModuleBase_PageWidget::ModuleBase_PageWidget(QWidget* theParent)
 : QFrame(theParent)
 {
diff --git a/src/ModuleBase/ModuleBase_ValidatorLinearEdge.cpp b/src/ModuleBase/ModuleBase_ValidatorLinearEdge.cpp
new file mode 100644 (file)
index 0000000..cf2d280
--- /dev/null
@@ -0,0 +1,65 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+
+#include "ModuleBase_ValidatorLinearEdge.h"
+#include "ModuleBase_WidgetShapeSelector.h"
+
+#include <GeomAPI_Curve.h>
+
+#include <Events_Error.h>
+
+#include <StdSelect_TypeOfEdge.hxx>
+
+#include <QString>
+#include <QMap>
+
+
+typedef QMap<QString, ModuleBase_ValidatorLinearEdge::TypeOfEdge> EdgeTypes;
+static EdgeTypes MyEdgeTypes;
+
+ModuleBase_ValidatorLinearEdge::TypeOfEdge ModuleBase_ValidatorLinearEdge::edgeType(const std::string& theType)
+{
+  if (MyEdgeTypes.count() == 0) {
+    MyEdgeTypes["line"] = Line;
+    MyEdgeTypes["circle"] = Circle;
+  }
+  QString aType = QString(theType.c_str()).toLower();
+  if (MyEdgeTypes.contains(aType))
+    return MyEdgeTypes[aType];
+  
+  Events_Error::send("Edge type defined in XML is not implemented!");
+  return AnyEdge;
+}
+
+bool ModuleBase_ValidatorLinearEdge::isValid(const AttributePtr& theAttribute,
+                                             const std::list<std::string>& theArguments) const
+{
+  bool aValid = false;
+
+  TypeOfEdge anEdgeType = AnyEdge;
+  if (theArguments.size() == 1) {
+    std::string anArgument = theArguments.front();
+    anEdgeType = edgeType(anArgument);
+  }
+
+  ObjectPtr anObject = ModuleBase_WidgetShapeSelector::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 && aShape->isEdge()) {
+        aValid = anEdgeType == AnyEdge;
+        if (!aValid) {
+          bool isCircle = GeomAPI_Curve(aShape).isCircle();
+          aValid = (isCircle && anEdgeType == Circle) ||
+                   (!isCircle && anEdgeType == Line);
+        }
+      }
+    }
+  }
+  else {
+    //AttributeRefAttrPtr anAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
+  }
+  return aValid;
+}
diff --git a/src/ModuleBase/ModuleBase_ValidatorLinearEdge.h b/src/ModuleBase/ModuleBase_ValidatorLinearEdge.h
new file mode 100644 (file)
index 0000000..f88527a
--- /dev/null
@@ -0,0 +1,43 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        ModuleBase_ValidatorLinearEdge.h
+// Created:     19 Mar 2015
+// Author:      Natalia ERMOLAEVA
+
+#ifndef ModuleBase_ValidatorLinearEdge_H
+#define ModuleBase_ValidatorLinearEdge_H
+
+#include "ModuleBase.h"
+#include "ModelAPI_AttributeValidator.h"
+
+#include <StdSelect_TypeOfEdge.hxx>
+
+/**
+* \ingroup Validators
+* A validator of selection
+*/
+class ModuleBase_ValidatorLinearEdge : public ModelAPI_AttributeValidator
+{
+ public:
+  //  the edge type
+  enum TypeOfEdge
+  {
+    AnyEdge,
+    Line,
+    Circle
+  };
+
+ public:
+   MODULEBASE_EXPORT ModuleBase_ValidatorLinearEdge() {}
+  //! returns true if attribute is valid
+  //! \param theAttribute the checked attribute
+  //! \param theArguments arguments of the attribute
+  MODULEBASE_EXPORT virtual bool isValid(const AttributePtr& theAttribute,
+                                         const std::list<std::string>& theArguments) const;
+protected:
+  /// Convert string to StdSelect_TypeOfFace value
+  /// \param theType a string value
+  static TypeOfEdge edgeType(const std::string& theType);
+};
+
+#endif
diff --git a/src/ModuleBase/ModuleBase_ValidatorLinearEdgeOrVertex.cpp b/src/ModuleBase/ModuleBase_ValidatorLinearEdgeOrVertex.cpp
new file mode 100644 (file)
index 0000000..b9c8ce1
--- /dev/null
@@ -0,0 +1,61 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+
+#include "ModuleBase_ValidatorLinearEdgeOrVertex.h"
+#include "ModuleBase_WidgetShapeSelector.h"
+#include "ModuleBase_ValidatorLinearEdge.h"
+
+#include "ModelAPI_AttributeRefAttr.h"
+
+#include <ModelAPI_Session.h>
+
+#include <GeomAPI_Curve.h>
+#include <GeomDataAPI_Point2D.h>
+
+#include <Events_Error.h>
+
+#include <StdSelect_TypeOfEdge.hxx>
+
+#include <QString>
+#include <QMap>
+
+
+bool ModuleBase_ValidatorLinearEdgeOrVertex::isValid(const AttributePtr& theAttribute,
+                                             const std::list<std::string>& theArguments) const
+{
+  bool aValid = false;
+
+  // 1. check whether the attribute is a linear edge
+    // there is a check whether the feature contains a point and a linear edge or two point values
+  SessionPtr aMgr = ModelAPI_Session::get();
+  ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
+
+  const ModuleBase_ValidatorLinearEdge* aLinearEdgeValidator =
+    dynamic_cast<const ModuleBase_ValidatorLinearEdge*>(aFactory->validator("ModuleBase_ValidatorLinearEdge"));
+
+  std::list<std::string> anArguments;
+  anArguments.push_back("line");
+  aValid = aLinearEdgeValidator->isValid(theAttribute, anArguments);
+  if (!aValid) {
+    //2. check whether the attribute is a vertex
+    ObjectPtr anObject = ModuleBase_WidgetShapeSelector::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) {
+          aValid = aShape->isVertex();
+        }
+      }
+    }
+    else {
+      AttributeRefAttrPtr anAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
+      if (anAttr.get() != NULL) {
+        AttributePtr aRefAttr = anAttr->attr();
+        aValid = aRefAttr.get() != NULL && aRefAttr->attributeType() == GeomDataAPI_Point2D::type();
+      }
+    }
+  }
+  return aValid;
+}
diff --git a/src/ModuleBase/ModuleBase_ValidatorLinearEdgeOrVertex.h b/src/ModuleBase/ModuleBase_ValidatorLinearEdgeOrVertex.h
new file mode 100644 (file)
index 0000000..0df6c88
--- /dev/null
@@ -0,0 +1,30 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        ModuleBase_ValidatorLinearEdgeOrVertex.h
+// Created:     19 Mar 2015
+// Author:      Natalia ERMOLAEVA
+
+#ifndef ModuleBase_ValidatorLinearEdgeOrVertex_H
+#define ModuleBase_ValidatorLinearEdgeOrVertex_H
+
+#include "ModuleBase.h"
+#include "ModelAPI_AttributeValidator.h"
+
+#include <StdSelect_TypeOfEdge.hxx>
+
+/**
+* \ingroup Validators
+* A validator of selection
+*/
+class ModuleBase_ValidatorLinearEdgeOrVertex : public ModelAPI_AttributeValidator
+{
+ public:
+   MODULEBASE_EXPORT ModuleBase_ValidatorLinearEdgeOrVertex() {}
+  //! returns true if attribute is valid
+  //! \param theAttribute the checked attribute
+  //! \param theArguments arguments of the attribute
+  MODULEBASE_EXPORT virtual bool isValid(const AttributePtr& theAttribute,
+                                         const std::list<std::string>& theArguments) const;
+};
+
+#endif
index c3bf95327950ba72585b4ba20e8238517d12e462..bba656f87aa87f59edb02a351750e380f8d6cfb7 100644 (file)
@@ -178,9 +178,9 @@ void ModuleBase_WidgetMultiSelector::backupAttributeValue(const bool isBackup)
 }
 
 //********************************************************************
-void ModuleBase_WidgetMultiSelector::setSelection(const Handle_SelectMgr_EntityOwner& theOwner)
+bool ModuleBase_WidgetMultiSelector::setSelection(const Handle_SelectMgr_EntityOwner& theOwner)
 {
-
+  return false;
 }
 
 //********************************************************************
index e0b257ca4495790b6d0a872e9730af9b9bc451b4..385eabf3fc4dc9f7f0c5bf138c1ec4059cdd09f2 100644 (file)
@@ -73,6 +73,10 @@ class MODULEBASE_EXPORT ModuleBase_WidgetMultiSelector : public ModuleBase_Widge
   /// The methiod called when widget is deactivated
   virtual void deactivate();
 
+  /// Fills the attribute with the value of the selected owner
+  /// \param theOwner a selected owner
+  virtual bool setSelection(const Handle_SelectMgr_EntityOwner& theOwner);
+
  public slots:
   /// Slot is called on selection type changed
   void onSelectionTypeChanged();
@@ -102,10 +106,6 @@ protected slots:
   /// to backup, otherwise set the backed up values to the attribute
   virtual void backupAttributeValue(const bool isBackup);
 
-  /// Fills the attribute with the value of the selected owner
-  /// \param theOwner a selected owner
-  virtual void setSelection(const Handle_SelectMgr_EntityOwner& theOwner);
-
   /// Set current shape type for selection
   void setCurrentShapeType(const TopAbs_ShapeEnum theShapeType);
 
index ec7defe2285bb1eff1724dc7da1695db04907e54..e60c8cb301559e8c065fe632d7153154f54d32d3 100644 (file)
@@ -215,13 +215,16 @@ void ModuleBase_WidgetShapeSelector::onSelectionChanged()
   //QObjectPtrList aObjects = myWorkshop->selection()->selectedPresentations();
   QList<ModuleBase_ViewerPrs> aSelected = myWorkshop->selection()->getSelected();
   if (aSelected.size() > 0) {
-    if (setSelection(aSelected.first()))
+    Handle(SelectMgr_EntityOwner) anOwner = aSelected.first().owner();
+    if (isValid(anOwner)) {
+      setSelection(anOwner);
       emit focusOutWidget(this);
+    }
   }
 }
 
 //********************************************************************
-bool ModuleBase_WidgetShapeSelector::setSelection(ModuleBase_ViewerPrs theValue)
+bool ModuleBase_WidgetShapeSelector::setSelectionPrs(ModuleBase_ViewerPrs theValue)
 {
   ObjectPtr aObject = theValue.object();
   ObjectPtr aCurrentObject = getObject(myFeature->attribute(attributeID()));
@@ -258,43 +261,26 @@ bool ModuleBase_WidgetShapeSelector::setSelection(ModuleBase_ViewerPrs theValue)
     aShape = std::shared_ptr<GeomAPI_Shape>(new GeomAPI_Shape());
     aShape->setImpl(new TopoDS_Shape(theValue.shape()));
   }
-
   // Check that the selection corresponds to selection type
   if (!acceptSubShape(aShape))
     return false;
-//  if (!acceptObjectShape(aObject))
-//      return false;
-
-  // Check whether the value is valid for the viewer selection filters
-  Handle(SelectMgr_EntityOwner) anOwner = theValue.owner();
-  if (!anOwner.IsNull()) {
-    SelectMgr_ListOfFilter aFilters;
-    selectionFilters(myWorkshop, aFilters);
-    SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
-    for (; aIt.More(); aIt.Next()) {
-      const Handle(SelectMgr_Filter)& aFilter = aIt.Value();
-      if (!aFilter->IsOk(anOwner))
-        return false;
-    }
-  }
-  if (isValid(aObject, aShape)) {
-    setObject(aObject, aShape);
-    return true;
-  }
-  return false;
+
+  setObject(aObject, aShape);
+  return true;
 }
 
 //********************************************************************
 void ModuleBase_WidgetShapeSelector::setObject(ObjectPtr theObj, std::shared_ptr<GeomAPI_Shape> theShape)
 {
-  if (storeAttributeValues(theObj, theShape))
-    updateObject(myFeature);
-
-  if (theObj) {
-    raisePanel();
-  } 
-  updateSelectionName();
-  emit valuesChanged();
+  //if (
+    storeAttributeValues(theObj, theShape);//)
+  //  updateObject(myFeature);
+
+  //if (theObj) {
+  //  raisePanel();
+  //} 
+  //updateSelectionName();
+  //emit valuesChanged();
 }
 
 //********************************************************************
@@ -395,7 +381,17 @@ void ModuleBase_WidgetShapeSelector::updateSelectionName()
       std::string aName = anObject->data()->name();
       myTextLine->setText(QString::fromStdString(aName));
     } else {
-      if (myIsActive) {
+      AttributeRefAttrPtr aRefAttr = aData->refattr(attributeID());
+      if (aRefAttr && aRefAttr->attr().get() != NULL) {
+        //myIsObject = aRefAttr->isObject();
+        AttributePtr anAttr = aRefAttr->attr();
+        if (anAttr.get() != NULL) {
+          std::stringstream aName;
+          aName <<anAttr->owner()->data()->name()<<"/"<<anAttr->id();
+          myTextLine->setText(QString::fromStdString(aName.str()));
+        }
+      }
+      else if (myIsActive) {
         myTextLine->setText("");
       }
     }
@@ -469,18 +465,23 @@ void ModuleBase_WidgetShapeSelector::backupAttributeValue(const bool isBackup)
     storeAttributeValues(myObject, myShape);
     AttributeRefAttrPtr aRefAttr = aData->refattr(attributeID());
     if (aRefAttr) {
-      if (myIsObject)
-        aRefAttr->setObject(myObject);
-      else
+      if (!myIsObject)
         aRefAttr->setAttr(myRefAttribute);
     }
   }
 }
 
 //********************************************************************
-void ModuleBase_WidgetShapeSelector::setSelection(const Handle_SelectMgr_EntityOwner& theOwner)
+bool ModuleBase_WidgetShapeSelector::setSelection(const Handle_SelectMgr_EntityOwner& theOwner)
 {
-
+  bool isDone = false;
+  //QList<ModuleBase_ViewerPrs> aSelected = myWorkshop->selection()->getSelected();
+  //if (aSelected.size() > 0) {
+  ModuleBase_ViewerPrs aPrs;
+  myWorkshop->selection()->fillPresentation(aPrs, theOwner);
+  isDone = setSelectionPrs(aPrs);
+  //}
+  return isDone;
 }
 
 //********************************************************************
@@ -491,7 +492,7 @@ void ModuleBase_WidgetShapeSelector::deactivate()
 }
 
 //********************************************************************
-bool ModuleBase_WidgetShapeSelector::isValid(ObjectPtr theObj, std::shared_ptr<GeomAPI_Shape> theShape)
+/*bool ModuleBase_WidgetShapeSelector::isValid(ObjectPtr theObj, std::shared_ptr<GeomAPI_Shape> theShape)
 {
   bool isValid = ModuleBase_WidgetValidated::isValid(theObj, theShape);
   if (!isValid)
@@ -529,4 +530,4 @@ bool ModuleBase_WidgetShapeSelector::isValid(ObjectPtr theObj, std::shared_ptr<G
   // 5. enable the model's update
   aData->blockSendAttributeUpdated(false);
   return aValid;
-}
+}*/
index ca735d5324db165b7db91aeae2ffcf43d04d1d07..c430fc17031863292a046fb54979054d667dc60a 100644 (file)
@@ -10,6 +10,7 @@
 #include "ModuleBase.h"
 #include "ModuleBase_WidgetValidated.h"
 #include "ModuleBase_ViewerFilters.h"
+#include <ModuleBase_ViewerPrs.h>
 
 #include <ModelAPI_Object.h>
 #include <ModelAPI_Attribute.h>
@@ -84,7 +85,11 @@ Q_OBJECT
   /// Set the given wrapped value to the current widget
   /// This value should be processed in the widget according to the needs
   /// \param theValue the wrapped widget value
-  virtual bool setSelection(ModuleBase_ViewerPrs theValue);
+  virtual bool setSelectionPrs(ModuleBase_ViewerPrs theValue);
+
+  /// Fills the attribute with the value of the selected owner
+  /// \param theOwner a selected owner
+  virtual bool setSelection(const Handle_SelectMgr_EntityOwner& theOwner);
 
   /// The methiod called when widget is deactivated
   virtual void deactivate();
@@ -117,10 +122,6 @@ Q_OBJECT
   /// to backup, otherwise set the backed up values to the attribute
   virtual void backupAttributeValue(const bool isBackup);
 
-  /// Fills the attribute with the value of the selected owner
-  /// \param theOwner a selected owner
-  virtual void setSelection(const Handle_SelectMgr_EntityOwner& theOwner);
-
   /// Computes and updates name of selected object in the widget
   void updateSelectionName();
 
@@ -143,7 +144,7 @@ Q_OBJECT
   /// Check the selected with validators if installed
   /// \param theObj the object for checking
   /// \param theShape the shape for checking
-  virtual bool isValid(ObjectPtr theObj, std::shared_ptr<GeomAPI_Shape> theShape);
+  //virtual bool isValid(ObjectPtr theObj, std::shared_ptr<GeomAPI_Shape> theShape);
 
   /// Clear attribute
   void clearAttribute();
index d81ec7970855eb8aa3d3d3ff194a371d2f5d63ea..d17cd98e84a2d224342c55deb8920f13a7b9cec0 100644 (file)
@@ -25,6 +25,21 @@ ModuleBase_WidgetValidated::~ModuleBase_WidgetValidated()
 {
 }
 
+bool ModuleBase_WidgetValidated::setSelection(ModuleBase_ViewerPrs theValue)
+{
+  bool isDone = false;
+
+  Handle(SelectMgr_EntityOwner) anOwner = theValue.owner();
+  if (isValid(anOwner)) {
+    //storeAttributeValue(anOwner);
+    setSelection(anOwner);
+    updateObject(myFeature);
+    //isDone = setSelection(anOwner);
+    emit valuesChanged();
+  }
+  return isDone;
+}
+
 bool ModuleBase_WidgetValidated::isValid(const Handle_SelectMgr_EntityOwner& theOwner)
 {
   backupAttributeValue(true);
@@ -97,13 +112,13 @@ void ModuleBase_WidgetValidated::activateFilters(ModuleBase_IWorkshop* theWorksh
                                                  const bool toActivate) const
 {
   ModuleBase_IViewer* aViewer = theWorkshop->viewer();
-/*
+
   Handle(SelectMgr_Filter) aSelFilter = theWorkshop->validatorFilter();
   if (toActivate)
     aViewer->addSelectionFilter(aSelFilter);
   else
     aViewer->removeSelectionFilter(aSelFilter);
-*/  
+/*
   // apply filters loaded from the XML definition of the widget
   ModuleBase_FilterFactory* aFactory = theWorkshop->selectionFilters();
   SelectMgr_ListOfFilter aFactoryFilters;
@@ -117,7 +132,7 @@ void ModuleBase_WidgetValidated::activateFilters(ModuleBase_IWorkshop* theWorksh
       aViewer->addSelectionFilter(aSelFilter);
     else
       aViewer->removeSelectionFilter(aSelFilter);
-  }
+  }*/
 }
 
 void ModuleBase_WidgetValidated::selectionFilters(ModuleBase_IWorkshop* theWorkshop,
index 90a83677ead697466b913709069bcf38e764feb3..fdb0941120ba0b647e9f0633492747b967f9423a 100644 (file)
@@ -43,6 +43,11 @@ class MODULEBASE_EXPORT ModuleBase_WidgetValidated : public ModuleBase_ModelWidg
   /// \return a boolean value
   bool isValid(const Handle_SelectMgr_EntityOwner& theOwner);
 
+  /// Set the given wrapped value to the current widget
+  /// This value should be processed in the widget according to the needs
+  /// \param theValue the wrapped widget value
+  virtual bool setSelection(ModuleBase_ViewerPrs theValue);
+
 protected:
   /// Creates a backup of the current values of the attribute
   /// It should be realized in the specific widget because of different
@@ -53,7 +58,7 @@ protected:
 
   /// Fills the attribute with the value of the selected owner
   /// \param theOwner a selected owner
-  virtual void setSelection(const Handle_SelectMgr_EntityOwner& theOwner) = 0;
+  virtual bool setSelection(const Handle_SelectMgr_EntityOwner& theOwner) = 0;
 
   /// Checks the current attibute in all attribute validators
   // \return true if all validators return that the attribute is valid
index 83f59bfe61bab2cde6132c700e168076a81b57df..a04ce1ee1ec8ba67032568d8747b327547a24dcb 100644 (file)
@@ -21,6 +21,9 @@
 #include <ModuleBase_FilterMulti.h>
 #include <ModuleBase_FilterCustom.h>
 #include <ModuleBase_FilterNoConsructionSubShapes.h>
+#include <ModuleBase_ValidatorLinearEdge.h>
+#include <ModuleBase_ValidatorLinearEdgeOrVertex.h>
+
 #include <PartSet_FilterSketchEntity.h>
 
 #include <ModelAPI_Object.h>
@@ -126,6 +129,10 @@ void PartSet_Module::registerValidators()
   aFactory->registerValidator("PartSet_DifferentObjects", new PartSet_DifferentObjectsValidator);
   aFactory->registerValidator("PartSet_DifferentShapes", new ModelAPI_ShapeValidator);
   aFactory->registerValidator("PartSet_SketchValidator", new PartSet_SketchValidator);
+
+  aFactory->registerValidator("ModuleBase_ValidatorLinearEdge", new ModuleBase_ValidatorLinearEdge);
+  aFactory->registerValidator("ModuleBase_ValidatorLinearEdgeOrVertex",
+                              new ModuleBase_ValidatorLinearEdgeOrVertex);
 }
 
 void PartSet_Module::registerFilters()
index 93aac5e0c8b900965f12ed1cfe6a1c7b5ef26155..726f8c160dcca63d3f3a8dc8636cf65febfc59bb 100644 (file)
@@ -25,7 +25,7 @@ bool PartSet_WidgetShapeSelector::storeAttributeValues(ObjectPtr theSelectedObje
     return false;
   std::shared_ptr<SketchPlugin_Feature> aSPFeature = 
           std::dynamic_pointer_cast<SketchPlugin_Feature>(aSelectedFeature);
-  if (aSPFeature.get() != NULL && aShape.get() != NULL && !aShape->isNull()) {
+  if (aSPFeature.get() == NULL && aShape.get() != NULL && !aShape->isNull()) {
     // Processing of external (non-sketch) object
     ObjectPtr aObj = PartSet_Tools::createFixedObjectByExternal(aShape->impl<TopoDS_Shape>(),
                                                                 aSelectedObject, mySketch);
@@ -42,9 +42,24 @@ bool PartSet_WidgetShapeSelector::storeAttributeValues(ObjectPtr theSelectedObje
       AttributeRefAttrPtr aRefAttr = 
         std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aAttr);
       if (aRefAttr) {
-        TopoDS_Shape aTDSShape = aShape->impl<TopoDS_Shape>();
-        AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(aSelectedObject, aTDSShape, mySketch);
+        // it is possible that the point feature is selected. It should be used itself
+        // instead of searching an attribute for the shape
+        bool aShapeIsResult = false;
+        /*ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theSelectedObject);
+        if (aResult.get() != NULL) {
+          GeomShapePtr aShapePtr = aResult->shape();
+          // it is important to call isEqual of the shape of result.
+          // It is a GeomAPI_Vertex shape for the point. The shape of the parameter is 
+          // GeomAPI_Shape. It is important to use the realization of the isEqual method from
+          // GeomAPI_Vertex class
+          aShapeIsResult = aShapePtr.get() != NULL && aShapePtr->isEqual(theShape);
+        }*/
 
+        AttributePtr aPntAttr;
+        if (!aShapeIsResult) {
+          TopoDS_Shape aTDSShape = aShape->impl<TopoDS_Shape>();
+          aPntAttr = PartSet_Tools::findAttributeBy2dPoint(aSelectedObject, aTDSShape, 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
index b4a7ab35b24d03bc609a1e3a0ea7581719d2b886..ed75e1bd9680701f00f1f2d6e67efef9319ac032 100644 (file)
@@ -56,7 +56,7 @@
               tooltip="Select point, line end point, line, center of circle or arc."
               shape_types="edge vertex">
           <validator id="SketchPlugin_ShapeValidator" parameters="ConstraintEntityB"/>
-          <selection_filter id="MultiFilter" parameters="line,vertex"/>
+          <validator id="ModuleBase_ValidatorLinearEdgeOrVertex"/>
         </sketch_shape_selector>/>
         <sketch_shape_selector 
           id="ConstraintEntityB" 
@@ -66,8 +66,8 @@
           <validator id="PartSet_DifferentObjects"/>
           <validator id="SketchPlugin_DistanceAttr" parameters="ConstraintEntityA"/>
           <validator id="SketchPlugin_ShapeValidator" parameters="ConstraintEntityB"/>
-          <selection_filter id="MultiFilter" parameters="line,vertex"/>
-    </sketch_shape_selector>
+          <validator id="ModuleBase_ValidatorLinearEdgeOrVertex"/>
+        </sketch_shape_selector>
         
         <sketch-2dpoint_selector id="ConstraintFlyoutValuePnt"  default="computed" internal="1" obligatory="0"/>
         
@@ -83,7 +83,7 @@
         <shape_selector id="ConstraintEntityA" label="Line" tooltip="Select an line" 
             shape_types="edge" >
             <validator id="SketchPlugin_ResultLine"/>
-      <selection_filter id="EdgeFilter" parameters="line"/>
+            <validator id="ModuleBase_ValidatorLinearEdge" parameters="line"/>
       <validator id="SketchPlugin_ResultLine"/>
     </shape_selector>
         <sketch-2dpoint_selector id="ConstraintFlyoutValuePnt" default="computed" internal="1" obligatory="0"/>
@@ -98,7 +98,7 @@
         <shape_selector id="ConstraintEntityA" label="Circle or Arc" tooltip="Select a circle or an arc" 
             shape_types="edge">
             <validator id="SketchPlugin_ResultArc"/>
-            <selection_filter id="EdgeFilter" parameters="circle"/>
+            <validator id="ModuleBase_ValidatorLinearEdge" parameters="circle"/>
         </shape_selector>
         <sketch-2dpoint_selector id="ConstraintFlyoutValuePnt"  default="computed" internal="1" obligatory="0"/>
         <doublevalue_editor label="Value" tooltip="Radius" id="ConstraintValue" default="computed"/>
       <feature id="SketchConstraintParallel" title="Parallel" tooltip="Create constraint defining two parallel lines" icon=":icons/parallel.png">
         <sketch_constraint_shape_selector id="ConstraintEntityA" 
             label="First line" tooltip="Select a line" shape_types="edge">
-            <selection_filter id="EdgeFilter" parameters="line"/>
-          <validator id="SketchPlugin_ShapeValidator" parameters="ConstraintEntityB"/>
+            <validator id="ModuleBase_ValidatorLinearEdge" parameters="line"/>
+            <validator id="SketchPlugin_ShapeValidator" parameters="ConstraintEntityB"/>
         </sketch_constraint_shape_selector>
         
         <sketch_constraint_shape_selector id="ConstraintEntityB" label="Last line" tooltip="Select a line" 
             shape_types="edge">
-            <selection_filter id="EdgeFilter" parameters="line"/>
+            <validator id="ModuleBase_ValidatorLinearEdge" parameters="line"/>
             <validator id="PartSet_DifferentObjects"/>
             <validator id="SketchPlugin_ShapeValidator" parameters="ConstraintEntityA"/>
         </sketch_constraint_shape_selector>
             label="First line" tooltip="Select an line" 
             shape_types="edge">
           <validator id="SketchPlugin_ShapeValidator" parameters="ConstraintEntityB"/>
-          <selection_filter id="EdgeFilter" parameters="line"/>
-    </sketch_constraint_shape_selector>
+            <validator id="ModuleBase_ValidatorLinearEdge" parameters="line"/>
+        </sketch_constraint_shape_selector>
         
         <sketch_constraint_shape_selector id="ConstraintEntityB" 
             label="Last line" tooltip="Select an line" 
             shape_types="edge">
             <validator id="PartSet_DifferentObjects"/>
           <validator id="SketchPlugin_ShapeValidator" parameters="ConstraintEntityA"/>
-          <selection_filter id="EdgeFilter" parameters="line"/>
-    </sketch_constraint_shape_selector>
+            <validator id="ModuleBase_ValidatorLinearEdge" parameters="line"/>
+        </sketch_constraint_shape_selector>
         <validator id="PartSet_PerpendicularValidator"/>
       </feature>
     <!--  SketchConstraintRigid  -->
       <feature id="SketchConstraintHorizontal" title="Horizontal" tooltip="Create constraint defining horizontal line" icon=":icons/horisontal.png">
         <sketch_constraint_shape_selector id="ConstraintEntityA" 
             label="Line" tooltip="Select a line" shape_types="edge">
-            <selection_filter id="EdgeFilter" parameters="line"/>
+            <validator id="ModuleBase_ValidatorLinearEdge" parameters="line"/>
         </sketch_constraint_shape_selector>
       </feature>
     <!--  SketchConstraintVertical  -->
       <feature id="SketchConstraintVertical" title="Vertical" tooltip="Create constraint defining vertical line" icon=":icons/vertical.png">
         <sketch_constraint_shape_selector id="ConstraintEntityA" 
             label="Line" tooltip="Select a line" shape_types="edge">
-            <selection_filter id="EdgeFilter" parameters="line"/>
+            <validator id="ModuleBase_ValidatorLinearEdge" parameters="line"/>
         </sketch_constraint_shape_selector>
       </feature>
     <!--  SketchConstraintEqual  -->
index 9d6848ccd659fdcff401fe75b01efc5fd64d4708..a782444c81a693a3d12a1318358c2e8ad712126f 100644 (file)
@@ -41,7 +41,8 @@ class XGUI_EXPORT XGUI_Selection : public ModuleBase_ISelection
   /// Fills the viewer presentation parameters by the parameters from the owner
   /// \param thePrs a container for selection
   /// \param theOwner a selection owner
-  void fillPresentation(ModuleBase_ViewerPrs& thePrs, const Handle_SelectMgr_EntityOwner& theOwner) const;
+  virtual void fillPresentation(ModuleBase_ViewerPrs& thePrs,
+                                const Handle_SelectMgr_EntityOwner& theOwner) const;
 
   /// Returns a list of viewer highlited presentations
   /// \return list of presentations