]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #2977: Impossible to select Group in Substract group
authorazv <azv@opencascade.com>
Wed, 21 Aug 2019 08:57:12 +0000 (11:57 +0300)
committerazv <azv@opencascade.com>
Wed, 21 Aug 2019 08:59:43 +0000 (11:59 +0300)
Set correct selection type for the operations on groups.

src/CollectionPlugin/CMakeLists.txt
src/CollectionPlugin/CollectionPlugin_GroupAddition.cpp
src/CollectionPlugin/CollectionPlugin_GroupAddition.h
src/CollectionPlugin/CollectionPlugin_GroupIntersection.cpp
src/CollectionPlugin/CollectionPlugin_GroupIntersection.h
src/CollectionPlugin/CollectionPlugin_GroupOperation.cpp [new file with mode: 0644]
src/CollectionPlugin/CollectionPlugin_GroupOperation.h [new file with mode: 0644]
src/CollectionPlugin/CollectionPlugin_GroupSubstraction.cpp
src/CollectionPlugin/CollectionPlugin_GroupSubstraction.h
src/CollectionPlugin/Test/Test2977.py [new file with mode: 0644]

index cfdaaa8e775422ae838d210e569f3b0fff4613ed..251b91ffea8ef1c42fcb567da8d9a4604bab0b7f 100644 (file)
@@ -33,6 +33,7 @@ SET(PROJECT_HEADERS
     CollectionPlugin_Group.h
     CollectionPlugin_GroupAddition.h
     CollectionPlugin_GroupIntersection.h
+    CollectionPlugin_GroupOperation.h
     CollectionPlugin_GroupSubstraction.h
     CollectionPlugin_Field.h
     CollectionPlugin_WidgetCreator.h
@@ -49,6 +50,7 @@ SET(PROJECT_SOURCES
     CollectionPlugin_Group.cpp
     CollectionPlugin_GroupAddition.cpp
     CollectionPlugin_GroupIntersection.cpp
+    CollectionPlugin_GroupOperation.cpp
     CollectionPlugin_GroupSubstraction.cpp
     CollectionPlugin_Field.cpp
     CollectionPlugin_WidgetCreator.cpp
@@ -144,4 +146,5 @@ ADD_UNIT_TESTS(
                TestGroupSubstraction.py
                TestGroupSubstraction_Error1.py
                TestGroupSubstraction_Error2.py
+               Test2977.py
 )
index c27826ce850af6f1e8bdd791ae540b7a57b10ecf..042633cfe1b4fda26d06ab4b2e4e2345b6624ca6 100644 (file)
@@ -83,5 +83,8 @@ void CollectionPlugin_GroupAddition::execute()
   aCompound = aSubs.empty() ? GeomShapePtr() : GeomAlgoAPI_CompoundBuilder::compound(aSubs);
   aGroup->store(aCompound);
 
+  // update the type of selection
+  updateGroupType(LIST_ID());
+
   setResult(aGroup);
 }
index 17b1ed1c655d6761871cae24663020f0faa5a3b6..850c7d797fa8b946c6d76a5eaeb453dabb74e20d 100644 (file)
 #define COLLECTIONPLUGIN_GROUPADDITION_H_
 
 #include "CollectionPlugin.h"
-#include "CollectionPlugin_Group.h"
+#include "CollectionPlugin_GroupOperation.h"
 
 /**\class CollectionPlugin_GroupAddition
  * \ingroup Plugins
  * \brief Merge several groups of same shape type into single group.
  */
-class CollectionPlugin_GroupAddition : public CollectionPlugin_Group
+class CollectionPlugin_GroupAddition : public CollectionPlugin_GroupOperation
 {
- public:
+public:
   /// Extrusion kind
   inline static const std::string& ID()
   {
@@ -56,9 +56,6 @@ class CollectionPlugin_GroupAddition : public CollectionPlugin_Group
   /// Request for initialization of data model of the feature: adding all attributes
   COLLECTIONPLUGIN_EXPORT virtual void initAttributes();
 
-  /// Result of groups is created on the fly and don't stored to the document
-  COLLECTIONPLUGIN_EXPORT virtual bool isPersistentResult() {return true;}
-
   /// Use plugin manager for features creation
   CollectionPlugin_GroupAddition();
 
index e74ba47861d7bf53013fc850c8ac447dae46634a..55f5200b579c736f2d2ed68e8672c00125948c9b 100644 (file)
@@ -96,6 +96,9 @@ void CollectionPlugin_GroupIntersection::execute()
     removeResults(0);
   }
   else {
+    // update the type of selection
+    updateGroupType(LIST_ID());
+
     GeomShapePtr aCompound = GeomAlgoAPI_CompoundBuilder::compound(aCommon);
     aGroup->store(aCompound);
     setResult(aGroup);
index 115f3f5444475c2fb8764b4029d5b973c5d52633..72b0984a371be045c30b7a0d4ec2e9685ee74893 100644 (file)
 #define COLLECTIONPLUGIN_GROUPINTERSECTION_H_
 
 #include "CollectionPlugin.h"
-#include "CollectionPlugin_Group.h"
+#include "CollectionPlugin_GroupOperation.h"
 
 /**\class CollectionPlugin_GroupIntersection
  * \ingroup Plugins
  * \brief Merge several groups of same shape type into single group.
  */
-class CollectionPlugin_GroupIntersection : public CollectionPlugin_Group
+class CollectionPlugin_GroupIntersection : public CollectionPlugin_GroupOperation
 {
- public:
+public:
   /// Extrusion kind
   inline static const std::string& ID()
   {
@@ -56,9 +56,6 @@ class CollectionPlugin_GroupIntersection : public CollectionPlugin_Group
   /// Request for initialization of data model of the feature: adding all attributes
   COLLECTIONPLUGIN_EXPORT virtual void initAttributes();
 
-  /// Result of groups is created on the fly and don't stored to the document
-  COLLECTIONPLUGIN_EXPORT virtual bool isPersistentResult() {return true;}
-
   /// Use plugin manager for features creation
   CollectionPlugin_GroupIntersection();
 
diff --git a/src/CollectionPlugin/CollectionPlugin_GroupOperation.cpp b/src/CollectionPlugin/CollectionPlugin_GroupOperation.cpp
new file mode 100644 (file)
index 0000000..d8965f1
--- /dev/null
@@ -0,0 +1,36 @@
+// Copyright (C) 2014-2019  CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#include "CollectionPlugin_GroupOperation.h"
+
+#include <ModelAPI_AttributeSelectionList.h>
+
+void CollectionPlugin_GroupOperation::updateGroupType(const std::string& theAttributeName)
+{
+  AttributeSelectionListPtr aSelected = selectionList(theAttributeName);
+  if (aSelected->size()) {
+    FeaturePtr aFirstGroup = ModelAPI_Feature::feature(aSelected->value(0)->context());
+    if (aFirstGroup) {
+      AttributeSelectionListPtr aFirstGroupShapes =
+        aFirstGroup->selectionList(CollectionPlugin_Group::LIST_ID());
+      if (aFirstGroupShapes)
+        aSelected->setSelectionType(aFirstGroupShapes->selectionType());
+    }
+  }
+}
diff --git a/src/CollectionPlugin/CollectionPlugin_GroupOperation.h b/src/CollectionPlugin/CollectionPlugin_GroupOperation.h
new file mode 100644 (file)
index 0000000..fb47e99
--- /dev/null
@@ -0,0 +1,41 @@
+// Copyright (C) 2014-2019  CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#ifndef COLLECTIONPLUGIN_GROUPOPERATION_H_
+#define COLLECTIONPLUGIN_GROUPOPERATION_H_
+
+#include "CollectionPlugin.h"
+#include "CollectionPlugin_Group.h"
+
+/**\class CollectionPlugin_GroupOperation
+ * \ingroup Plugins
+ * \brief Base class for operations on groups.
+ */
+class CollectionPlugin_GroupOperation : public CollectionPlugin_Group
+{
+public:
+  /// Result of groups is created on the fly and don't stored to the document
+  COLLECTIONPLUGIN_EXPORT virtual bool isPersistentResult() {return true;}
+
+protected:
+  /// Updates the type of selection list based on types of selected groups
+  void updateGroupType(const std::string& theAttributeName);
+};
+
+#endif
index 18f0acad5f5e1ac63a8ad231f56059fd9fb0bcf2..9d39711ae52442c9ca2c1c2dc6233f60335210e8 100644 (file)
@@ -101,6 +101,9 @@ void CollectionPlugin_GroupSubstraction::execute()
     removeResults(0);
   }
   else {
+    // update the type of selection
+    updateGroupType(LIST_ID());
+
     GeomShapePtr aCompound = GeomAlgoAPI_CompoundBuilder::compound(aCut);
     aGroup->store(aCompound);
     setResult(aGroup);
index 3fcd74339ea60e882060c484ce042c7575717802..0b4f8ead0d46c3473d86c673a89b933360eebb99 100644 (file)
 #define COLLECTIONPLUGIN_GROUPSUBSTRACTION_H_
 
 #include "CollectionPlugin.h"
-#include "CollectionPlugin_Group.h"
+#include "CollectionPlugin_GroupOperation.h"
 
 /**\class CollectionPlugin_GroupSubstraction
  * \ingroup Plugins
  * \brief Remove all elements in "objects" groups which contain in "tools" groups.
  */
-class CollectionPlugin_GroupSubstraction : public CollectionPlugin_Group
+class CollectionPlugin_GroupSubstraction : public CollectionPlugin_GroupOperation
 {
- public:
+public:
   /// Extrusion kind
   inline static const std::string& ID()
   {
@@ -62,9 +62,6 @@ class CollectionPlugin_GroupSubstraction : public CollectionPlugin_Group
   /// Request for initialization of data model of the feature: adding all attributes
   COLLECTIONPLUGIN_EXPORT virtual void initAttributes();
 
-  /// Result of groups is created on the fly and don't stored to the document
-  COLLECTIONPLUGIN_EXPORT virtual bool isPersistentResult() {return true;}
-
   /// Use plugin manager for features creation
   CollectionPlugin_GroupSubstraction();
 
diff --git a/src/CollectionPlugin/Test/Test2977.py b/src/CollectionPlugin/Test/Test2977.py
new file mode 100644 (file)
index 0000000..26568fe
--- /dev/null
@@ -0,0 +1,44 @@
+# Copyright (C) 2019  CEA/DEN, EDF R&D
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+#
+# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+#
+
+from salome.shaper import model
+
+model.begin()
+partSet = model.moduleDocument()
+Part_1 = model.addPart(partSet)
+Part_1_doc = Part_1.document()
+Box_1 = model.addBox(Part_1_doc, 10, 10, 10)
+Group_1 = model.addGroup(Part_1_doc, [model.selection("FACE", "Box_1_1/Left"), model.selection("FACE", "Box_1_1/Top")])
+Group_2 = model.addGroup(Part_1_doc, [model.selection("FACE", "Box_1_1/Front"), model.selection("FACE", "Box_1_1/Top")])
+Group_3 = model.addGroup(Part_1_doc, [model.selection("FACE", "Box_1_1/Top")])
+GroupAddition_1 = model.addGroupAddition(Part_1_doc, [model.selection("COMPOUND", "Group_1"), model.selection("COMPOUND", "Group_2")])
+GroupSubstraction_1 = model.addGroupSubstraction(Part_1_doc, [model.selection("COMPOUND", "GroupAddition_1")], [model.selection("COMPOUND", "Group_3")])
+model.end()
+
+from GeomAPI import *
+
+model.testNbResults(GroupSubstraction_1, 1)
+model.testNbSubResults(GroupSubstraction_1, [0])
+model.testNbSubShapes(GroupSubstraction_1, GeomAPI_Shape.SOLID, [0])
+model.testNbSubShapes(GroupSubstraction_1, GeomAPI_Shape.FACE, [2])
+model.testNbSubShapes(GroupSubstraction_1, GeomAPI_Shape.EDGE, [8])
+model.testNbSubShapes(GroupSubstraction_1, GeomAPI_Shape.VERTEX, [16])
+model.testResultsVolumes(GroupSubstraction_1, [200])
+
+assert(model.checkPythonDump())