]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Several improvement of the filters functionality, correct work with shapes types...
authormpv <mpv@opencascade.com>
Tue, 11 Jun 2019 09:37:13 +0000 (12:37 +0300)
committermpv <mpv@opencascade.com>
Tue, 11 Jun 2019 09:37:13 +0000 (12:37 +0300)
src/FeaturesPlugin/FeaturesPlugin_Validators.cpp
src/FiltersPlugin/FiltersPlugin_Selection.cpp
src/FiltersPlugin/FiltersPlugin_Selection.h
src/GeomAPI/GeomAPI_Shape.cpp
src/Model/Model_AttributeSelectionList.cpp
src/Model/Model_AttributeSelectionList.h
src/Model/Model_Document.h
src/Model/Model_Filter.cpp
src/ModelAPI/ModelAPI_AttributeSelectionList.h
src/ModelAPI/ModelAPI_Filter.h
src/ModuleBase/ModuleBase_WidgetSelectionFilter.cpp

index 30993f225bd44544afc1544cedc0f00bb8a5a095..d7755548e1b5e6aa279a78b9ac64fcafd465a31b 100644 (file)
@@ -30,7 +30,7 @@
 #include <Events_InfoMessage.h>
 
 #include <ModelAPI_Attribute.h>
-#include <ModelAPI_AttributeDouble.h>>
+#include <ModelAPI_AttributeDouble.h>
 #include <ModelAPI_AttributeInteger.h>
 #include <ModelAPI_AttributeSelectionList.h>
 #include <ModelAPI_AttributeString.h>
index fefedb084edc842ae483316134810cdd7b4329b3..4b656d847d900f1bbeaa04a47881869ff4b94d92 100644 (file)
@@ -21,6 +21,7 @@
 
 #include <ModelAPI_Session.h>
 #include <ModelAPI_AttributeBoolean.h>
+#include <ModelAPI_AttributeSelectionList.h>
 
 // identifier of the reverse flag of a filter
 static const std::string kReverseAttrID("");
@@ -79,3 +80,39 @@ std::list<AttributePtr> FiltersPlugin_Selection::filterArgs(const std::string th
   data()->attributesOfGroup(theFilterID, aList);
   return aList;
 }
+
+void FiltersPlugin_Selection::setAttribute(const AttributePtr& theAttr)
+{
+  if (myBase != theAttr) { // clear all filters if the attribute is changed or defined a new
+    std::list<std::string> aFilters;
+    data()->allGroups(aFilters);
+    std::list<std::string>::iterator aFIter = aFilters.begin();
+    for(; aFIter != aFilters.end(); aFIter++) {
+      data()->removeAttributes(*aFIter);
+    }
+  }
+  myBase = theAttr;
+  if (myBase.get()) { // check that the type of sub-elements is supported by all existing filters
+    std::shared_ptr<ModelAPI_AttributeSelectionList> aSelList =
+      std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttr);
+    if (aSelList.get()) {
+      std::string aStrType = aSelList->selectionType();
+      GeomAPI_Shape::ShapeType aType = GeomAPI_Shape::shapeTypeByStr(aStrType);
+      std::list<std::string> aFilters;
+      data()->allGroups(aFilters);
+      ModelAPI_FiltersFactory* aFactory = ModelAPI_Session::get()->filters();
+      std::list<std::string>::iterator aFIter = aFilters.begin();
+      for(; aFIter != aFilters.end(); aFIter++) {
+        FilterPtr aFilter = aFactory->filter(*aFIter);
+        if (aFilter.get() && !aFilter->isSupported(aType)) {
+          data()->removeAttributes(*aFIter);
+        }
+      }
+    }
+  }
+}
+
+const AttributePtr& FiltersPlugin_Selection::baseAttribute() const
+{
+  return myBase;
+}
index 46a88089107aba6f9a5b2ec05b2048ec0ddcc068..0e68ac9bbb8e19f06e0c7027e1dfa78199b8bd7c 100644 (file)
@@ -60,22 +60,36 @@ public:
   // methods related to the filters management
 
   /// Adds a filter to the feature. Also initializes arguments of this filter.
-  FILTERS_EXPORT virtual void addFilter(const std::string theFilterID);
+  FILTERS_EXPORT virtual void addFilter(const std::string theFilterID) override;
 
   /// Removes an existing filter from the feature.
-  FILTERS_EXPORT virtual void removeFilter(const std::string theFilterID);
+  FILTERS_EXPORT virtual void removeFilter(const std::string theFilterID) override;
 
   /// Returns the list of existing filters in the feature.
-  FILTERS_EXPORT virtual std::list<std::string> filters() const;
+  FILTERS_EXPORT virtual std::list<std::string> filters() const override;
 
   /// Stores the reversed flag for the filter.
-  FILTERS_EXPORT virtual void setReversed(const std::string theFilterID, const bool theReversed);
+  FILTERS_EXPORT virtual void setReversed
+  (const std::string theFilterID, const bool theReversed) override;
 
   /// Returns the reversed flag value for the filter.
-  FILTERS_EXPORT virtual bool isReversed(const std::string theFilterID);
+  FILTERS_EXPORT virtual bool isReversed(const std::string theFilterID) override;
 
   /// Returns the ordered list of attributes related to the filter.
-  FILTERS_EXPORT virtual std::list<AttributePtr> filterArgs(const std::string theFilterID) const;
+  FILTERS_EXPORT virtual std::list<AttributePtr>
+    filterArgs(const std::string theFilterID) const override;
+
+  /// Sets the attribute (not-persistent field) that contains this filters feature.
+  /// The filter feature may make synchronization by this method call.
+  FILTERS_EXPORT virtual void setAttribute(const AttributePtr& theAttr) override;
+
+  /// Returns the attribute (not-persistent field) that contains this filters feature.
+  FILTERS_EXPORT virtual const AttributePtr& baseAttribute() const override;
+
+protected:
+
+  AttributePtr myBase; ///< the attribute related to this filter
+
 };
 
 #endif
index 3b0709eac3e91cd144dc81583b24ab0e6f947fe6..98bfdcf9ea22993bd7d5555c395f9ed1334b1078 100644 (file)
@@ -460,21 +460,21 @@ GeomAPI_Shape::ShapeType GeomAPI_Shape::shapeType() const
 GeomAPI_Shape::ShapeType GeomAPI_Shape::shapeTypeByStr(std::string theType)
 {
   std::transform(theType.begin(), theType.end(), theType.begin(), ::toupper);
-  if (theType == "COMPOUND")
+  if (theType == "COMPOUND" || theType == "COMPOUNDS")
     return COMPOUND;
-  if (theType == "COMPSOLID")
+  if (theType == "COMPSOLID" || theType == "COMPSOLIDS")
     return COMPSOLID;
-  if (theType == "SOLID")
+  if (theType == "SOLID" || theType == "SOLIDS")
     return SOLID;
-  if (theType == "SHELL")
+  if (theType == "SHELL" || theType == "SHELLS")
     return SHELL;
-  if (theType == "FACE")
+  if (theType == "FACE" || theType == "FACES")
     return FACE;
-  if (theType == "WIRE")
+  if (theType == "WIRE" || theType == "WIRES")
     return WIRE;
-  if (theType == "EDGE")
+  if (theType == "EDGE" || theType == "EDGES")
     return EDGE;
-  if (theType == "VERTEX")
+  if (theType == "VERTEX" || theType == "VERTICES")
     return VERTEX;
   return SHAPE; // default
 }
index 0ef7aeff351e869d8975bff2aff5d56d7d9ba7b1..50b04d3c35d967dd388f9b8637f60d340a5aa19f 100644 (file)
@@ -22,6 +22,7 @@
 #include "Model_Application.h"
 #include "Model_Events.h"
 #include "Model_Data.h"
+#include "Model_Objects.h"
 
 #include <GeomAPI_Pnt.h>
 #include <GeomAPI_Shape.h>
@@ -32,6 +33,7 @@
 #include <TDF_RelocationTable.hxx>
 #include <TDF_DeltaOnAddition.hxx>
 #include <TDataStd_UAttribute.hxx>
+#include <TDataStd_ReferenceList.hxx>
 #include <TopAbs_ShapeEnum.hxx>
 #include <TopoDS.hxx>
 #include <TopoDS_Shape.hxx>
 /// topology" flag enabled
 static const Standard_GUID kIS_GEOMETRICAL_SELECTION("f16987b6-e6c8-435c-99fa-03a7e0b06e83");
 
+/// GUID for TDataStd_ReferenceList attribute that refers the selection filters feature
+static const Standard_GUID kSELECTION_FILTERS_REF("ea5b1dbf-a740-4a0b-a1b2-3c3c756e691a");
+
+
 void Model_AttributeSelectionList::append(
     const ObjectPtr& theContext, const std::shared_ptr<GeomAPI_Shape>& theSubShape,
     const bool theTemporarily)
@@ -480,3 +486,44 @@ void Model_AttributeSelectionList::setGeometricalSelection(const bool theIsGeome
   myCash.clear(); // empty list as indicator that cash is not used
   owner()->data()->sendAttributeUpdated(this);
 }
+
+FiltersFeaturePtr Model_AttributeSelectionList::filters() const
+{
+  Handle(TDataStd_ReferenceList) aRef;
+  if (myLab.FindAttribute(kSELECTION_FILTERS_REF, aRef) && !aRef->IsEmpty()) {
+    if (owner().get()) {
+      std::shared_ptr<Model_Document> aDoc = std::dynamic_pointer_cast<Model_Document>(
+        owner()->document());
+      if (aDoc) {
+        const TDF_Label& aRefLab = aRef->First();
+        if (!aRefLab.IsNull()) {  // it may happen with old document, issue #285
+          ObjectPtr anObj = aDoc->objects()->object(aRefLab);
+          FiltersFeaturePtr aFeat = std::dynamic_pointer_cast<ModelAPI_FiltersFeature>(anObj);
+          if (aFeat.get()) {
+            aFeat->setAttribute(owner()->data()->attribute(id()));
+            return aFeat;
+          }
+        }
+      }
+    }
+  }
+  return FiltersFeaturePtr(); // null pointer if nothing is defined
+}
+
+void Model_AttributeSelectionList::setFilters(FiltersFeaturePtr theFeature)
+{
+  Handle(TDataStd_ReferenceList) aRef = TDataStd_ReferenceList::Set(myLab, kSELECTION_FILTERS_REF);
+  if (theFeature.get()) {
+    std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(theFeature->data());
+    if (aData->isValid())  {
+      TDF_Label anObjLab = aData->label().Father(); // object label
+      if (!aRef->IsEmpty())
+        aRef->Clear();
+      aRef->Append(anObjLab);
+      theFeature->setAttribute(owner()->data()->attribute(id()));
+      return;
+    }
+  }
+  // remove attribute if something is wrong
+  myLab.ForgetAttribute(TDataStd_ReferenceList::GetID());
+}
index 839cd431d23cb4049f8ab2547f66d5b941ed89fa..ca797e623d75716d1efc9e0ffcfad5c8a5f41cb1 100644 (file)
@@ -115,6 +115,12 @@ public:
   /// Returns true if is geometrical selection.
   MODEL_EXPORT virtual bool isGeometricalSelection() const override;
 
+  /// Returns a selection filters feature if it is defined for this selection list
+  MODEL_EXPORT virtual FiltersFeaturePtr filters() const;
+
+  /// Sets a selection filters feature if it is defined for this selection list
+  MODEL_EXPORT virtual void setFilters(FiltersFeaturePtr theFeature);
+
 protected:
   /// Objects are created for features automatically
   MODEL_EXPORT Model_AttributeSelectionList(TDF_Label& theLabel);
index a61cc6ad471266c44c5eb343ca8fbf38278992ed..72a570738b5080a167838dc2fa0830d3f43eeebf 100644 (file)
@@ -395,6 +395,7 @@ class Model_Document : public ModelAPI_Document
   friend class Model_AttributeRefList;
   friend class Model_AttributeRefAttrList;
   friend class Model_AttributeSelection;
+  friend class Model_AttributeSelectionList;
   friend class Model_ResultPart;
   friend class Model_ResultBody;
   friend class Model_ResultConstruction;
index 14905d04006d95e2df11012b4dd4cb199d61745a..549bed4da8f9653b4a6b9780153b1fb7c2f94f14 100644 (file)
@@ -20,6 +20,7 @@
 #include "Model_Filter.h"
 
 #include "ModelAPI_AttributeBoolean.h"
+#include "ModelAPI_AttributeSelectionList.h"
 #include <Events_InfoMessage.h>
 
 
@@ -41,6 +42,17 @@ struct FilterArgs {
 
 bool Model_FiltersFactory::isValid(FeaturePtr theFiltersFeature, GeomShapePtr theShape)
 {
+  // check that the shape type corresponds to the attribute list type
+  AttributePtr aBase =
+    std::dynamic_pointer_cast<ModelAPI_FiltersFeature>(theFiltersFeature)->baseAttribute();
+  if (aBase.get()) {
+    std::shared_ptr<ModelAPI_AttributeSelectionList> aList =
+      std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(aBase);
+    std::string aStrType = aList->selectionType();
+    GeomAPI_Shape::ShapeType aType = GeomAPI_Shape::shapeTypeByStr(aStrType);
+    if (theShape->shapeType() != aType)
+      return false;
+  }
   // prepare all filters args
   ModelAPI_FiltersArgs anArgs;
   std::list<FilterArgs> aFilters; /// all filters and the reverse values
index 5c304db25f06e91d437020d30bee03cc958da748..4280f613aa118f2cbc460041243d799bd41bc5d1 100644 (file)
@@ -115,15 +115,16 @@ class ModelAPI_AttributeSelectionList : public ModelAPI_Attribute
   /// To virtually destroy the fields of successors
   MODELAPI_EXPORT virtual ~ModelAPI_AttributeSelectionList();
 
-  MODELAPI_EXPORT FiltersFeaturePtr filters() const { return myFilters; }
-  MODELAPI_EXPORT void setFilters(FiltersFeaturePtr theFeature) { myFilters = theFeature; }
+  /// Returns a selection filters feature if it is defined for this selection list
+  MODELAPI_EXPORT virtual FiltersFeaturePtr filters() const = 0;
+
+  /// Sets a selection filters feature if it is defined for this selection list
+  MODELAPI_EXPORT virtual void setFilters(FiltersFeaturePtr theFeature) = 0;
 
 protected:
   /// Objects are created for features automatically
   MODELAPI_EXPORT ModelAPI_AttributeSelectionList();
 
-protected:
-  FiltersFeaturePtr myFilters;
 };
 
 //! Pointer on double attribute
index a900548bfaeb768b208b3263d11940fcc635ce6c..08bb82d1e03d23082cf16950049c4cb0c2482195 100644 (file)
@@ -57,6 +57,13 @@ public:
 
   /// Returns the ordered list of attributes related to the filter.
   virtual std::list<AttributePtr> filterArgs(const std::string theFilterID) const = 0;
+
+  /// Sets the attribute (not-persistent field) that contains this filters feature.
+  /// The filter feature may make synchronization by this method call.
+  virtual void setAttribute(const AttributePtr& theAttr) = 0;
+
+  /// Returns the attribute (not-persistent field) that contains this filters feature.
+  virtual const AttributePtr& baseAttribute() const = 0;
 };
 
 typedef std::shared_ptr<ModelAPI_FiltersFeature> FiltersFeaturePtr;
@@ -93,7 +100,9 @@ public:
   /// adds an attribute of the filter
   std::shared_ptr<ModelAPI_Attribute> initAttribute(
     const std::string& theID, const std::string theAttrType) {
-    return myFeature->data()->addFloatingAttribute(theID, theAttrType, myCurrentFilter);
+    AttributePtr aR = myFeature->data()->addFloatingAttribute(theID, theAttrType, myCurrentFilter);
+    aR->setIsArgument(false); // to avoid parametric update
+    return aR;
   }
 };
 
index 4146656b07756456258126ed25151a50c4540407..faf52833cbf3771cce594f6a838c2b81d4f11c67 100644 (file)
@@ -450,13 +450,16 @@ void ModuleBase_WidgetSelectionFilter::onSelect()
     GeomShapePtr aShape = aBody->shape();
     std::list<GeomShapePtr> aSubShapes =
       aShape->subShapes((GeomAPI_Shape::ShapeType)mySelectionType);
+    TopTools_MapOfShape alreadyThere;
     std::list<GeomShapePtr>::const_iterator aShapesIt;
     for (aShapesIt = aSubShapes.cbegin(); aShapesIt != aSubShapes.cend(); aShapesIt++) {
       GeomShapePtr aShape = (*aShapesIt);
-      SessionPtr aSession = ModelAPI_Session::get();
+      TopoDS_Shape aTShape = aShape->impl<TopoDS_Shape>();
+      if (!alreadyThere.Add(aTShape))
+        continue;
+      static SessionPtr aSession = ModelAPI_Session::get();
       bool isValid = aSession->filters()->isValid(myFeature, aShape);
       if (isValid) {
-        TopoDS_Shape aTShape = aShape->impl<TopoDS_Shape>();
         aBuilder.Add(aComp, aTShape);
         ModuleBase_ViewerPrsPtr aValue(new ModuleBase_ViewerPrs(aObj, aShape));
         myValues.append(aValue);