Salome HOME
Union of validator and filter functionalities.
authornds <natalia.donis@opencascade.com>
Wed, 25 Mar 2015 14:59:51 +0000 (17:59 +0300)
committernds <natalia.donis@opencascade.com>
Wed, 25 Mar 2015 14:59:51 +0000 (17:59 +0300)
External edges correction

13 files changed:
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_WidgetConstraintShapeSelector.cpp
src/PartSet/PartSet_WidgetConstraintShapeSelector.h
src/PartSet/PartSet_WidgetShapeSelector.cpp
src/PartSet/PartSet_WidgetShapeSelector.h
src/PartSet/PartSet_WidgetSketchLabel.cpp
src/PartSet/PartSet_WidgetSketchLabel.h
src/SketchPlugin/plugin-Sketch.xml

index ff8bafdea6a8746a9ca85a9063af9e2cc62cbe73..8b53074f961a4755a1cd02fc478c41e85979d420 100644 (file)
@@ -9,7 +9,6 @@
 
 #include <ModuleBase_WidgetMultiSelector.h>
 #include <ModuleBase_WidgetShapeSelector.h>
-#include <ModuleBase_FilterNoDegeneratedEdge.h>
 #include <ModuleBase_ISelection.h>
 #include <ModuleBase_IWorkshop.h>
 #include <ModuleBase_IViewer.h>
@@ -159,7 +158,7 @@ bool ModuleBase_WidgetMultiSelector::restoreValue()
 }
 
 //********************************************************************
-void ModuleBase_WidgetMultiSelector::backupAttributeValue(const bool isBackup)
+void ModuleBase_WidgetMultiSelector::storeAttributeValue()
 {
   DataPtr aData = myFeature->data();
   AttributeSelectionListPtr aSelectionListAttr = 
@@ -167,23 +166,32 @@ void ModuleBase_WidgetMultiSelector::backupAttributeValue(const bool isBackup)
   if (aSelectionListAttr.get() == NULL)
     return;
 
-  if (isBackup) {
-    mySelectionType = aSelectionListAttr->selectionType();
-    mySelection.clear();
-    for (int i = 0; i < aSelectionListAttr->size(); i++) {
-      AttributeSelectionPtr aSelectAttr = aSelectionListAttr->value(i);
-      mySelection.append(GeomSelection(aSelectAttr->context(), aSelectAttr->value()));
-    }
+  mySelectionType = aSelectionListAttr->selectionType();
+  mySelection.clear();
+  int aSize = aSelectionListAttr->size();
+  for (int i = 0; i < aSelectionListAttr->size(); i++) {
+    AttributeSelectionPtr aSelectAttr = aSelectionListAttr->value(i);
+    mySelection.append(GeomSelection(aSelectAttr->context(), aSelectAttr->value()));
   }
-  else {
-    aSelectionListAttr->clear();
-    // Store shapes type
-    aSelectionListAttr->setSelectionType(mySelectionType);
+}
 
-    // Store selection in the attribute
-    foreach (GeomSelection aSelec, mySelection) {
-      aSelectionListAttr->append(aSelec.first, aSelec.second);
-    }
+//********************************************************************
+void ModuleBase_WidgetMultiSelector::restoreAttributeValue(bool/* theValid*/)
+{
+  DataPtr aData = myFeature->data();
+  AttributeSelectionListPtr aSelectionListAttr = 
+    std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(aData->attribute(attributeID()));
+  if (aSelectionListAttr.get() == NULL)
+    return;
+  aSelectionListAttr->clear();
+
+  // Store shapes type
+  aSelectionListAttr->setSelectionType(mySelectionType);
+
+  // Store selection in the attribute
+  int aSize = mySelection.size();
+  foreach (GeomSelection aSelec, mySelection) {
+    aSelectionListAttr->append(aSelec.first, aSelec.second);
   }
 }
 
@@ -311,20 +319,8 @@ void ModuleBase_WidgetMultiSelector::activateShapeSelection()
     QIntList aList;
     aList.append(ModuleBase_WidgetShapeSelector::shapeType(aNewType));
     myWorkshop->activateSubShapesSelection(aList);
-
-    // it is necessary to filter the selected edges to be non-degenerated
-    // it is not possible to build naming name for such edges
-    if (aNewType == "Edges") {
-      myEdgesTypeFilter = new ModuleBase_FilterNoDegeneratedEdge();
-      aViewer->addSelectionFilter(myEdgesTypeFilter);
-    }
-    else {
-      aViewer->removeSelectionFilter(myEdgesTypeFilter);
-    }
-
   } else {
     myWorkshop->deactivateSubShapesSelection();
-    aViewer->removeSelectionFilter(myEdgesTypeFilter);
   }
 
   activateFilters(myWorkshop, myIsActive);
index ce904a981c9443e92d6d56f9834905dd56679da2..49ae66b6b85f47e9a333df3dc701ae8c954a0785 100644 (file)
@@ -12,7 +12,6 @@
 
 #include <ModuleBase.h>
 #include <ModuleBase_WidgetValidated.h>
-#include <ModuleBase_FilterNoDegeneratedEdge.h>
 
 #include <GeomAPI_Shape.h>
 #include <ModelAPI_Result.h>
@@ -102,9 +101,13 @@ protected slots:
   /// Creates a backup of the current values of the attribute
   /// It should be realized in the specific widget because of different
   /// parameters of the current attribute
-  /// \param isBackup a boolean flag, if true, store values from the attribute
-  /// to backup, otherwise set the backed up values to the attribute
-  virtual void backupAttributeValue(const bool isBackup);
+  virtual void storeAttributeValue();
+
+  /// Creates a backup of the current values of the attribute
+  /// It should be realized in the specific widget because of different
+  /// parameters of the current attribute
+  /// \param theValid a boolean flag, if restore happens for valid parameters
+  virtual void restoreAttributeValue(const bool theValid);
 
   /// Set current shape type for selection
   void setCurrentShapeType(const TopAbs_ShapeEnum theShapeType);
@@ -134,9 +137,6 @@ protected slots:
   /// An action for pop-up menu in a list control
   QAction* myCopyAction;
 
-  /// A filter for the Edges type, which avoid the generated edges selection
-  Handle(ModuleBase_FilterNoDegeneratedEdge) myEdgesTypeFilter;
-
   /// backup parameters of the model attribute. The class processes three types of attribute:
   /// Reference, RefAttr and Selection. Depending on the attribute type, only the attribute parameter
   /// values are reserved in the backup
index 7fc40261487056aa53dd9085efdb0b54e9cc8d69..b981a9064f1c92dd6544abec6ab6582be780e4e0 100644 (file)
@@ -370,37 +370,33 @@ void ModuleBase_WidgetShapeSelector::activateCustom()
 }
 
 //********************************************************************
-void ModuleBase_WidgetShapeSelector::backupAttributeValue(const bool isBackup)
+void ModuleBase_WidgetShapeSelector::storeAttributeValue()
 {
   DataPtr aData = myFeature->data();
   AttributePtr anAttribute = myFeature->attribute(attributeID());
 
-  if (isBackup) {
-    myObject = GeomValidators_Tools::getObject(anAttribute);
-    myShape = getShape();
-    myRefAttribute = NULL;
-    myIsObject = false;
-    AttributeRefAttrPtr aRefAttr = aData->refattr(attributeID());
-    if (aRefAttr) {
-      myIsObject = aRefAttr->isObject();
-      myRefAttribute = aRefAttr->attr();
-    }
-    myExternalObject = NULL;
+  myObject = GeomValidators_Tools::getObject(anAttribute);
+  myShape = getShape();
+  myRefAttribute = NULL;
+  myIsObject = false;
+  AttributeRefAttrPtr aRefAttr = aData->refattr(attributeID());
+  if (aRefAttr) {
+    myIsObject = aRefAttr->isObject();
+    myRefAttribute = aRefAttr->attr();
   }
-  else {
-    storeAttributeValues(myObject, myShape);
-    AttributeRefAttrPtr aRefAttr = aData->refattr(attributeID());
-    if (aRefAttr) {
-      if (!myIsObject)
-        aRefAttr->setAttr(myRefAttribute);
-    }
-    if (myExternalObject.get()) {
-      DocumentPtr aDoc = myExternalObject->document();
-      FeaturePtr aFeature = ModelAPI_Feature::feature(myExternalObject);
-      if (aFeature.get() != NULL) {
-        aDoc->removeFeature(aFeature);
-      }
-    }
+}
+
+//********************************************************************
+void ModuleBase_WidgetShapeSelector::restoreAttributeValue(bool theValid)
+{
+  DataPtr aData = myFeature->data();
+  AttributePtr anAttribute = myFeature->attribute(attributeID());
+
+  storeAttributeValues(myObject, myShape);
+  AttributeRefAttrPtr aRefAttr = aData->refattr(attributeID());
+  if (aRefAttr) {
+    if (!myIsObject)
+      aRefAttr->setAttr(myRefAttribute);
   }
 }
 
index 34c4c0212545a75448215b15b2ef7ea6cdce03f6..ea5ef10a702b2f4664ba1d8da8bdff2c5e019bc4 100644 (file)
@@ -109,9 +109,13 @@ Q_OBJECT
   /// Creates a backup of the current values of the attribute
   /// It should be realized in the specific widget because of different
   /// parameters of the current attribute
-  /// \param isBackup a boolean flag, if true, store values from the attribute
-  /// to backup, otherwise set the backed up values to the attribute
-  virtual void backupAttributeValue(const bool isBackup);
+  virtual void storeAttributeValue();
+
+  /// Creates a backup of the current values of the attribute
+  /// It should be realized in the specific widget because of different
+  /// parameters of the current attribute
+  /// \param theValid a boolean flag, if restore happens for valid parameters
+  virtual void restoreAttributeValue(const bool theValid);
 
   /// Computes and updates name of selected object in the widget
   void updateSelectionName();
@@ -164,8 +168,6 @@ Q_OBJECT
   AttributePtr myRefAttribute;
   /// A boolean value whether refAttr uses reference of object
   bool myIsObject;
-  /// An external object
-  ObjectPtr myExternalObject;
 };
 
 #endif
index 506eeca2a858427465374e62b80fc41f18cc8bb5..2dd78afc614a4ce83c47426a911bb9c589579986 100644 (file)
@@ -42,7 +42,7 @@ bool ModuleBase_WidgetValidated::setSelection(ModuleBase_ViewerPrs theValue)
 bool ModuleBase_WidgetValidated::isValid(const Handle_SelectMgr_EntityOwner& theOwner)
 {
   // stores the current values of the widget attribute
-  backupAttributeValue(true);
+  storeAttributeValue();
 
   // saves the owner value to the widget attribute
   setSelection(theOwner);
@@ -51,7 +51,7 @@ bool ModuleBase_WidgetValidated::isValid(const Handle_SelectMgr_EntityOwner& the
   bool aValid = isValidAttribute();
 
   // restores the current values of the widget attribute
-  backupAttributeValue(false);
+  restoreAttributeValue(aValid);
 
   return aValid;
 }
index eea1bca0fa2707b69a799cce4d13a3bed144a662..31e7b81ac27a43e2167c06f44355b97db40e129a 100644 (file)
@@ -54,14 +54,20 @@ protected:
   /// Creates a backup of the current values of the attribute
   /// It should be realized in the specific widget because of different
   /// parameters of the current attribute
-  /// \param isBackup a boolean flag, if true, store values from the attribute
-  /// to backup, otherwise set the backed up values to the attribute
-  virtual void backupAttributeValue(const bool isBackup) = 0;
+  virtual void storeAttributeValue() = 0;
+
+  /// Creates a backup of the current values of the attribute
+  /// It should be realized in the specific widget because of different
+  /// parameters of the current attribute
+  /// \param theValid a boolean flag, if restore happens for valid parameters
+  virtual void restoreAttributeValue(const bool theValid) = 0;
 
   /// Fills the attribute with the value of the selected owner
   /// \param theOwner a selected owner
   virtual bool setSelection(const Handle_SelectMgr_EntityOwner& theOwner) = 0;
 
+  virtual void removePresentations() {};
+
   /// Checks the current attibute in all attribute validators
   // \return true if all validators return that the attribute is valid
   bool isValidAttribute() const;
index f54e0fbc338c6903339998bfad411f606ee88b05..ca6f8837af133539eea5461489f6ebb84a86b29d 100644 (file)
@@ -21,11 +21,10 @@ bool PartSet_WidgetConstraintShapeSelector::storeAttributeValues(ObjectPtr theSe
     std::shared_ptr<SketchPlugin_Feature> aSPFeature = 
             std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
     if ((!aSPFeature) && (!theShape->isNull())) {
-      ObjectPtr aObj = PartSet_Tools::createFixedObjectByExternal(theShape->impl<TopoDS_Shape>(),
-                                                                  aSelectedObject, mySketch);
-      if (aObj) {
-        aSelectedObject = aObj;
-        myExternalObject = aObj;
+      createExternal(theSelectedObject, theShape);
+
+      if (myExternalObject) {
+        aSelectedObject = myExternalObject;
       } else 
         return false;
     }
index ea8bbaa9e7a1a2b0eb657e29f897a22826e15b16..c20eee6f35b79139a57a4a874d03020f4bd7cfbe 100644 (file)
 
 #include "PartSet.h"
 
-#include <ModuleBase_WidgetShapeSelector.h>
+#include <PartSet_WidgetShapeSelector.h>
 
 #include <ModelAPI_CompositeFeature.h>
 
 
 /**
 * \ingroup Modules
-* Customosation of ModuleBase_WidgetShapeSelector in order to provide 
+* Customosation of PartSet_WidgetShapeSelector in order to provide 
 * working with constraints.
 */
-class PARTSET_EXPORT PartSet_WidgetConstraintShapeSelector: public ModuleBase_WidgetShapeSelector
+class PARTSET_EXPORT PartSet_WidgetConstraintShapeSelector: public PartSet_WidgetShapeSelector
 {
 Q_OBJECT
  public:
@@ -31,16 +31,16 @@ Q_OBJECT
   /// \param theParentId is Id of a parent of the current attribute
   PartSet_WidgetConstraintShapeSelector(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop,
     const Config_WidgetAPI* theData, const std::string& theParentId)
-    : ModuleBase_WidgetShapeSelector(theParent, theWorkshop, theData, theParentId) {}
+    : PartSet_WidgetShapeSelector(theParent, theWorkshop, theData, theParentId) {}
 
   virtual ~PartSet_WidgetConstraintShapeSelector() {}
 
   /// Set sketcher
   /// \param theSketch a sketcher object
-  void setSketcher(CompositeFeaturePtr theSketch) { mySketch = theSketch; }
+  //void setSketcher(CompositeFeaturePtr theSketch) { mySketch = theSketch; }
 
   /// Retrurns installed sketcher
-  CompositeFeaturePtr sketch() const { return mySketch; }
+  //CompositeFeaturePtr sketch() const { return mySketch; }
 
 protected:
   /// Store the values to the model attribute of the widget. It casts this attribute to
@@ -49,9 +49,9 @@ protected:
   /// \param theShape a selected shape, which is used in the selection attribute
   virtual bool storeAttributeValues(ObjectPtr theSelectedObject, GeomShapePtr theShape);
 
-private:
+//private:
   /// Pointer to a sketch 
-  CompositeFeaturePtr mySketch;
+  //CompositeFeaturePtr mySketch;
 };
 
 #endif
\ No newline at end of file
index a7ada4a646c433a8f79b2a82c518debf7ff881c2..5c68a10159daacf2db318642c05626a5ccddb2f3 100644 (file)
 #include <PartSet_Tools.h>
 #include <SketchPlugin_Feature.h>
 
+#include <ModuleBase_IWorkshop.h>
+#include <XGUI_ModuleConnector.h>
+#include <XGUI_Workshop.h>
+#include <XGUI_Displayer.h>
+
 bool PartSet_WidgetShapeSelector::storeAttributeValues(ObjectPtr theSelectedObject, GeomShapePtr theShape)
 {
   ObjectPtr aSelectedObject = theSelectedObject;
@@ -25,13 +30,10 @@ bool PartSet_WidgetShapeSelector::storeAttributeValues(ObjectPtr theSelectedObje
           std::dynamic_pointer_cast<SketchPlugin_Feature>(aSelectedFeature);
   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);
-    if (aObj) {
-      PartSet_WidgetShapeSelector* that = (PartSet_WidgetShapeSelector*) this;
-      aSelectedObject = aObj;
-      myExternalObject = aObj;
-    } else 
+    createExternal(theSelectedObject, theShape);
+    if (myExternalObject)
+      aSelectedObject = myExternalObject;
+    else
       return false;
   } else {
     // Processing of sketch object
@@ -74,3 +76,51 @@ bool PartSet_WidgetShapeSelector::storeAttributeValues(ObjectPtr theSelectedObje
   return ModuleBase_WidgetShapeSelector::storeAttributeValues(aSelectedObject, aShape);
 }
 
+//********************************************************************
+void PartSet_WidgetShapeSelector::storeAttributeValue()
+{
+  /// this is a temporary code, will be removed when master is merged to this branch
+  /*XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
+  XGUI_Workshop* aWorkshop = aConnector->workshop();
+  aWorkshop->displayer()->enableUpdateViewer(false);
+  */
+  ModuleBase_WidgetShapeSelector::storeAttributeValue();
+}
+
+//********************************************************************
+void PartSet_WidgetShapeSelector::restoreAttributeValue(const bool theValid)
+{
+  ModuleBase_WidgetShapeSelector::restoreAttributeValue(theValid);
+  //if (!theValid)
+  removeExternal();
+  /*
+  XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
+  XGUI_Workshop* aWorkshop = aConnector->workshop();
+  aWorkshop->displayer()->enableUpdateViewer(false);//->erase(myExternalObject);
+  aWorkshop->displayer()->enableUpdateViewer(true);*/
+}
+
+//********************************************************************
+void PartSet_WidgetShapeSelector::createExternal(ObjectPtr theSelectedObject,
+                                                 GeomShapePtr theShape)
+{
+  ObjectPtr aObj = PartSet_Tools::createFixedObjectByExternal(theShape->impl<TopoDS_Shape>(),
+                                                              theSelectedObject, mySketch);
+  if (aObj != myExternalObject) {
+    removeExternal();
+    myExternalObject = aObj;
+  }
+}
+
+//********************************************************************
+void PartSet_WidgetShapeSelector::removeExternal()
+{
+  if (myExternalObject.get()) {
+    DocumentPtr aDoc = myExternalObject->document();
+    FeaturePtr aFeature = ModelAPI_Feature::feature(myExternalObject);
+    if (aFeature.get() != NULL) {
+      aDoc->removeFeature(aFeature);
+    }
+    myExternalObject = NULL;
+  }
+}
index f7d075b48cfa3436574e11db2fb3c8fd15df71cb..c342e07014ccaf0f14ea7e9d45c7f3624e86258f 100644 (file)
@@ -49,9 +49,31 @@ protected:
   /// \param theShape a selected shape, which is used in the selection attribute
   virtual bool storeAttributeValues(ObjectPtr theSelectedObject, GeomShapePtr theShape);
 
-private:
+  /// Creates a backup of the current values of the attribute
+  /// It should be realized in the specific widget because of different
+  /// parameters of the current attribute
+  virtual void storeAttributeValue();
+
+  /// Creates a backup of the current values of the attribute
+  /// It should be realized in the specific widget because of different
+  /// parameters of the current attribute
+  /// \param theValid a boolean flag, if restore happens for valid parameters
+  void restoreAttributeValue(const bool theValid);
+
+  // Removes the external presentation from the model
+  /// \param theSelectedObject an object
+  /// \param theShape a selected shape, which is used in the selection attribute
+  void createExternal(ObjectPtr theSelectedObject, GeomShapePtr theShape);
+
+  // Removes the external presentation from the model
+  void removeExternal();
+
+protected:
   /// Pointer to a sketch 
   CompositeFeaturePtr mySketch;
+
+  /// An external object
+  ObjectPtr myExternalObject;
 };
 
 #endif
\ No newline at end of file
index 9f41c9453966513889e52b16646b6e50adf9ceda..e70a8a0975dedcdab221a48d4d8c8ad9fae1e85f 100644 (file)
@@ -150,18 +150,20 @@ void PartSet_WidgetSketchLabel::enableFocusProcessing()
   myLabel->installEventFilter(this);
 }
 
-void PartSet_WidgetSketchLabel::backupAttributeValue(const bool isBackup)
+void PartSet_WidgetSketchLabel::storeAttributeValue()
+{
+}
+
+void PartSet_WidgetSketchLabel::restoreAttributeValue(const bool theValid)
 {
   // it is not necessary to save the previous plane value because the plane is chosen once
-  if (!isBackup) {
-    DataPtr aData = feature()->data();
-    AttributeSelectionPtr aSelAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>
-      (aData->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID()));
-    if (aSelAttr) {
-      ResultPtr anEmptyResult;
-      GeomShapePtr anEmptyShape;
-      aSelAttr->setValue(anEmptyResult, anEmptyShape);
-    }
+  DataPtr aData = feature()->data();
+  AttributeSelectionPtr aSelAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>
+    (aData->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID()));
+  if (aSelAttr) {
+    ResultPtr anEmptyResult;
+    GeomShapePtr anEmptyShape;
+    aSelAttr->setValue(anEmptyResult, anEmptyShape);
   }
 }
 
index 3e277c68ddd585b59468e6ce4cc2335259eebc3c..a0a069f785d1248ddd8ae637da275c02dfb82904 100644 (file)
@@ -82,9 +82,13 @@ protected:
   /// Creates a backup of the current values of the attribute
   /// It should be realized in the specific widget because of different
   /// parameters of the current attribute
-  /// \param isBackup a boolean flag, if true, store values from the attribute
-  /// to backup, otherwise set the backed up values to the attribute
-  virtual void backupAttributeValue(const bool isBackup);
+  virtual void storeAttributeValue();
+
+  /// Creates a backup of the current values of the attribute
+  /// It should be realized in the specific widget because of different
+  /// parameters of the current attribute
+  /// \param theValid a boolean flag, if restore happens for valid parameters
+  virtual void restoreAttributeValue(const bool theValid);
 
   /// Fills the attribute with the value of the selected owner
   /// \param theOwner a selected owner
index 673816d770f9ea20824b9e86d6f2f614fd1d0a52..f1bc36d9b27c41994d0a79f142c99c07659b778b 100644 (file)
@@ -67,7 +67,7 @@
                 shape_types="edge vertex">
           <validator id="PartSet_DifferentObjects"/>
           <validator id="SketchPlugin_DistanceAttr" parameters="ConstraintEntityA"/>
-          <validator id="SketchPlugin_ShapeValidator" parameters="ConstraintEntityB"/>
+          <validator id="SketchPlugin_ShapeValidator" parameters="ConstraintEntityA"/>
           <validator id="GeomValidators_EdgeOrVertex"/>
         </sketch_shape_selector>