]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
#839 Selection of Part sub-results
authornds <nds@opencascade.com>
Thu, 27 Aug 2015 17:35:27 +0000 (20:35 +0300)
committernds <nds@opencascade.com>
Thu, 27 Aug 2015 17:35:27 +0000 (20:35 +0300)
Realization for movement feature

12 files changed:
src/FeaturesPlugin/movement_widget.xml
src/GeomValidators/CMakeLists.txt
src/GeomValidators/GeomValidators_PartSet.cpp [new file with mode: 0755]
src/GeomValidators/GeomValidators_PartSet.h [new file with mode: 0755]
src/GeomValidators/GeomValidators_Tools.cpp
src/GeomValidators/GeomValidators_Tools.h
src/ModuleBase/ModuleBase_Tools.cpp
src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp
src/ModuleBase/ModuleBase_WidgetSelector.cpp
src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp
src/PartSet/PartSet_Filters.cpp
src/PartSet/PartSet_Module.cpp

index 96c16cf3a7644eaa7d6737d5db621b3c491d131e..421a8851d4c311c1e46a157234424652a529e7f8 100644 (file)
@@ -5,8 +5,10 @@
     label="Main objects"
     icon=":icons/cut_shape.png"
     tooltip="Select a solid objects"
-    type_choice="Solids"
+    type_choice="Compounds Solids"
+    use_choice="false"
     concealment="true">
+    <validator id="GeomValidators_PartSet"/>
   </multi_selector>
   <shape_selector id="axis_object"
                   icon=":icons/axis.png"
index ced6fea05a7d4820c01746227c35445591766e87..56c6b1ba4ca44a3e48a2626695108da46c0c1890 100644 (file)
@@ -7,6 +7,7 @@ SET(PROJECT_HEADERS
     GeomValidators_BooleanArguments.h
     GeomValidators_ConstructionComposite.h
     GeomValidators_Face.h
+    GeomValidators_PartSet.h
     GeomValidators_Positive.h
     GeomValidators_ShapeType.h
     GeomValidators_Tools.h
@@ -18,6 +19,7 @@ SET(PROJECT_SOURCES
     GeomValidators_BooleanArguments.cpp
     GeomValidators_ConstructionComposite.cpp
     GeomValidators_Face.cpp
+    GeomValidators_PartSet.cpp
     GeomValidators_Positive.cpp
     GeomValidators_ShapeType.cpp
     GeomValidators_Tools.cpp
diff --git a/src/GeomValidators/GeomValidators_PartSet.cpp b/src/GeomValidators/GeomValidators_PartSet.cpp
new file mode 100755 (executable)
index 0000000..9521b18
--- /dev/null
@@ -0,0 +1,54 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        GeomValidators_PartSet.cpp
+// Created:     27 Aug 2015
+// Author:      Natalia ERMOLAEVA
+
+#include <GeomValidators_PartSet.h>
+#include <GeomValidators_Tools.h>
+
+#include <ModelAPI_AttributeSelectionList.h>
+#include <ModelAPI_Session.h>
+
+#include <TopAbs_ShapeEnum.hxx>
+#include <TopoDS_Shape.hxx>
+#include <TopoDS_Iterator.hxx>
+
+bool GeomValidators_PartSet::isValid(const AttributePtr& theAttribute,
+                                   const std::list<std::string>& theArguments,
+                                   std::string& theError) const
+{
+  bool aValid = false;
+  SessionPtr aMgr = ModelAPI_Session::get();
+  bool isPartSetDocument = aMgr->activeDocument() == aMgr->moduleDocument();
+
+  if (theAttribute->attributeType() == ModelAPI_AttributeSelectionList::typeId()) {
+    AttributeSelectionListPtr aSelectionListAttr = 
+                      std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
+    // all context objects should be sketch entities
+    for (int i = 0, aSize = aSelectionListAttr->size(); i < aSize; i++) {
+      AttributeSelectionPtr aSelectAttr = aSelectionListAttr->value(i);
+
+      GeomShapePtr aShape = aSelectAttr->value();
+      if (!aShape.get()) {
+        ResultPtr aResult = aSelectAttr->context();
+        if (aResult.get())
+          aShape = aResult->shape();
+      }
+      TopoDS_Shape aTopoShape = aShape->impl<TopoDS_Shape>();
+      TopAbs_ShapeEnum aShapeType = aTopoShape.ShapeType();
+
+      if (isPartSetDocument)
+        aValid = aShapeType == TopAbs_COMPOUND;
+      else {
+        TopoDS_Shape aTopoShape = aShape->impl<TopoDS_Shape>();
+        aShapeType = GeomValidators_Tools::getCompoundSubType(aTopoShape);
+
+        aValid = aShapeType == TopAbs_SOLID;
+      }
+    }
+  }
+
+  return aValid;
+}
+
diff --git a/src/GeomValidators/GeomValidators_PartSet.h b/src/GeomValidators/GeomValidators_PartSet.h
new file mode 100755 (executable)
index 0000000..dc80cc5
--- /dev/null
@@ -0,0 +1,28 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        GeomValidators_Face.h
+// Created:     27 Aug 2015
+// Author:      Natalia ERMOLAEVA
+
+#ifndef GeomValidators_PartSet_H
+#define GeomValidators_PartSet_H
+
+#include <GeomValidators.h>
+#include <ModelAPI_AttributeValidator.h>
+
+/**
+* \ingroup Validators
+* A validator for partset objects.
+*/
+class GeomValidators_PartSet : public ModelAPI_AttributeValidator
+{
+public:
+  //! returns true if attribute is valid
+  //! \param theAttribute the checked attribute
+  //! \param theArguments arguments of the attribute
+  GEOMVALIDATORS_EXPORT virtual bool isValid(const AttributePtr& theAttribute,
+                                             const std::list<std::string>& theArguments,
+                                             std::string& theError) const;
+};
+
+#endif
index 9a78b5016b657e7ba80ff19dd66cab3f53c15b23..7f16f08144f74048798b6dd4a902d6fcf8d0be97 100644 (file)
@@ -10,6 +10,8 @@
 #include "ModelAPI_AttributeSelection.h"
 #include "ModelAPI_AttributeReference.h"
 
+#include <TopoDS_Iterator.hxx>
+
 namespace GeomValidators_Tools {
 
   ObjectPtr getObject(const AttributePtr& theAttribute)
@@ -33,4 +35,31 @@ namespace GeomValidators_Tools {
     }
     return anObject;
   }
+
+  TopAbs_ShapeEnum getCompoundSubType(const TopoDS_Shape& theShape)
+  {
+    TopAbs_ShapeEnum aShapeType = theShape.ShapeType();
+
+    // for compounds check sub-shapes: it may be compound of needed type:
+    // Booleans may produce compounds of Solids
+    if (aShapeType == TopAbs_COMPOUND) {
+      for(TopoDS_Iterator aSubs(theShape); aSubs.More(); aSubs.Next()) {
+        if (!aSubs.Value().IsNull()) {
+          TopAbs_ShapeEnum aSubType = aSubs.Value().ShapeType();
+          if (aSubType == TopAbs_COMPOUND) { // compound of compound(s)
+            aShapeType = TopAbs_COMPOUND;
+            break;
+          }
+          if (aShapeType == TopAbs_COMPOUND) {
+            aShapeType = aSubType;
+          } else if (aShapeType != aSubType) { // compound of shapes of different types
+            aShapeType = TopAbs_COMPOUND;
+            break;
+          }
+        }
+      }
+    }
+    return aShapeType;
+  }
+
 }
index bb1db6644187aa3a0507af235fccd1cc8b64ecf7..83a2c3f666b7d9681fb81078f7cc5a7e971f761e 100644 (file)
@@ -11,6 +11,8 @@
 #include "ModelAPI_Object.h"
 #include "ModelAPI_Attribute.h"
 
+#include "TopAbs_ShapeEnum.hxx"
+#include "TopoDS_Shape.hxx"
 
 namespace GeomValidators_Tools
 {
@@ -18,6 +20,10 @@ namespace GeomValidators_Tools
   /// \param theObj an object 
   GEOMVALIDATORS_EXPORT ObjectPtr getObject(const AttributePtr& theAttribute);
 
+  // Returns the object from the attribute
+  /// \param theObj an object 
+  GEOMVALIDATORS_EXPORT TopAbs_ShapeEnum getCompoundSubType(const TopoDS_Shape& theShape);
+
 };
 
 #endif
index e1b25b8844b55e4792ff433ebccc8df1520c1b5b..b0ee536de63e6a1895e294c734241e9ee15ae3bc 100755 (executable)
@@ -216,6 +216,7 @@ TopAbs_ShapeEnum shapeType(const QString& theType)
     MyShapeTypes["shell"] = TopAbs_SHELL;
     MyShapeTypes["solid"] = TopAbs_SOLID;
     MyShapeTypes["solids"] = TopAbs_SOLID;
+    MyShapeTypes["compounds"] = TopAbs_COMPOUND;
   }
   QString aType = theType.toLower();
   if (MyShapeTypes.contains(aType))
index b83e14576ac94d789cb0b7de800aaca559152437..d58a23633d61fc24c469720b5193e08659b31d8b 100755 (executable)
@@ -15,8 +15,6 @@
 #include <ModuleBase_Tools.h>
 #include <ModuleBase_Definitions.h>
 
-#include <GeomValidators_ShapeType.h>
-
 #include <ModelAPI_Data.h>
 #include <ModelAPI_Object.h>
 #include <ModelAPI_AttributeSelectionList.h>
index 5f57ebb15e4338277ac6c0dd60d2330361f9349e..6f9076bfbd7a15b918f5da74d762b5db3ed08e2b 100755 (executable)
@@ -11,6 +11,8 @@
 
 #include <ModelAPI_ResultConstruction.h>
 
+#include <GeomValidators_Tools.h>
+
 #include <TopoDS_Iterator.hxx>
 
 ModuleBase_WidgetSelector::ModuleBase_WidgetSelector(QWidget* theParent,
@@ -64,6 +66,8 @@ bool ModuleBase_WidgetSelector::acceptSubShape(const GeomShapePtr& theShape,
     if (theResult.get())
       aShape = theResult->shape();
   }
+  QIntList aShapeTypes = getShapeTypes();
+
   TopAbs_ShapeEnum aShapeType = TopAbs_SHAPE;
   if (aShape.get()) {
     // Check that the selection corresponds to selection type
@@ -72,25 +76,13 @@ bool ModuleBase_WidgetSelector::acceptSubShape(const GeomShapePtr& theShape,
     // for compounds check sub-shapes: it may be compound of needed type:
     // Booleans may produce compounds of Solids
     if (aShapeType == TopAbs_COMPOUND) {
-      for(TopoDS_Iterator aSubs(aTopoShape); aSubs.More(); aSubs.Next()) {
-        if (!aSubs.Value().IsNull()) {
-          TopAbs_ShapeEnum aSubType = aSubs.Value().ShapeType();
-          if (aSubType == TopAbs_COMPOUND) { // compound of compound(s)
-            aShapeType = TopAbs_COMPOUND;
-            break;
-          }
-          if (aShapeType == TopAbs_COMPOUND) {
-            aShapeType = aSubType;
-          } else if (aShapeType != aSubType) { // compound of shapes of different types
-            aShapeType = TopAbs_COMPOUND;
-            break;
-          }
-        }
-      }
+      if (aShapeTypes.contains(aShapeType))
+        return true;
+
+      aShapeType = GeomValidators_Tools::getCompoundSubType(aTopoShape);
     }
   }
 
-  QIntList aShapeTypes = getShapeTypes();
   QIntList::const_iterator anIt = aShapeTypes.begin(), aLast = aShapeTypes.end();
   for (; anIt != aLast; anIt++) {
     if (aShapeType == *anIt)
index 16e0d2a620a7981077f4a70da738d17d14958055..84c409d5008b2b65b0a8dffd11260f9fd95bce68 100644 (file)
@@ -13,8 +13,6 @@
 #include <ModuleBase_FilterFactory.h>
 #include <ModuleBase_Filter.h>
 
-#include <GeomValidators_ShapeType.h>
-
 #include <Config_WidgetAPI.h>
 #include <Events_Loop.h>
 #include <Events_Message.h>
index d82447430e3757d240e7dacbef36fce48ec17ca5..31f1872c778acce3053fce118629971a8dbbdcb2 100644 (file)
@@ -10,6 +10,8 @@
 #include "ModuleBase_IModule.h"
 
 #include <ModelAPI_Feature.h>
+#include <ModelAPI_ResultPart.h>
+#include <ModelAPI_Session.h>
 #include <FeaturesPlugin_Group.h>
 
 #include <AIS_InteractiveObject.hxx>
@@ -38,11 +40,20 @@ Standard_Boolean PartSet_GlobalFilter::IsOk(const Handle(SelectMgr_EntityOwner)&
       }
       ObjectPtr aObj = myWorkshop->findPresentedObject(aAISObj);
       if (aObj) {
-        FeaturePtr aFeature = ModelAPI_Feature::feature(aObj);
-        if (aFeature) {
-          aValid = aFeature->getKind() != FeaturesPlugin_Group::ID();
-        } else 
-          aValid = Standard_True;
+        ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
+        // result of parts belongs to PartSet document and can be selected only when PartSet is active
+        // in order to do not select the result of the active part.
+        if (aResult.get() && aResult->groupName() == ModelAPI_ResultPart::group()) {
+          SessionPtr aMgr = ModelAPI_Session::get();
+          aValid = aMgr->activeDocument() == aMgr->moduleDocument();
+        }
+        else {
+          FeaturePtr aFeature = ModelAPI_Feature::feature(aObj);
+          if (aFeature) {
+            aValid = aFeature->getKind() != FeaturesPlugin_Group::ID();
+          } else 
+            aValid = Standard_True;
+        }
       } else
         // This is not object controlled by the filter
         aValid = Standard_True;
index 3731b80fd3ee57b3c3dad0a482aaef03b4c7f8ac..361e12d5dde9b2c57fc88a812ed7c7ae7095c839 100755 (executable)
@@ -36,6 +36,7 @@
 #include <ModuleBase_OperationFeature.h>
 
 #include <GeomValidators_ShapeType.h>
+#include <GeomValidators_PartSet.h>
 #include <GeomValidators_Face.h>
 #include <GeomValidators_ConstructionComposite.h>
 #include <GeomValidators_ZeroOffset.h>
@@ -208,6 +209,8 @@ void PartSet_Module::registerValidators()
   aFactory->registerValidator("GeomValidators_ShapeType", new GeomValidators_ShapeType);
   aFactory->registerValidator("GeomValidators_Face", new GeomValidators_Face);
 
+  aFactory->registerValidator("GeomValidators_PartSet", new GeomValidators_PartSet);
+
   aFactory->registerValidator("GeomValidators_ConstructionComposite",
                               new GeomValidators_ConstructionComposite);