Implement Group Intersection feature.
CollectionAPI.h
CollectionAPI_Group.h
CollectionAPI_GroupAddition.h
+ CollectionAPI_GroupIntersection.h
CollectionAPI_Field.h
)
SET(PROJECT_SOURCES
CollectionAPI_Group.cpp
CollectionAPI_GroupAddition.cpp
+ CollectionAPI_GroupIntersection.cpp
CollectionAPI_Field.cpp
)
#include "CollectionAPI.h"
#include "CollectionAPI_Group.h"
#include "CollectionAPI_GroupAddition.h"
+ #include "CollectionAPI_GroupIntersection.h"
#include "CollectionAPI_Field.h"
#endif // CollectionAPI_swig_H_
// shared pointers
%shared_ptr(CollectionAPI_Group)
%shared_ptr(CollectionAPI_GroupAddition)
+%shared_ptr(CollectionAPI_GroupIntersection)
%shared_ptr(CollectionAPI_Field)
// all supported interfaces
%include "CollectionAPI_Group.h"
%include "CollectionAPI_GroupAddition.h"
+%include "CollectionAPI_GroupIntersection.h"
%include "CollectionAPI_Field.h"
/// \class CollectionAPI_GroupAddition
/// \ingroup CPPHighAPI
-/// \brief Interface for Group feature.
+/// \brief Interface for Group Addition feature.
class CollectionAPI_GroupAddition : public ModelHighAPI_Interface
{
public:
GroupAdditionPtr addGroupAddition(const std::shared_ptr<ModelAPI_Document>& thePart,
const std::list<ModelHighAPI_Selection>& theGroupsList);
-#endif // CollectionAPI_Group_H_
+#endif // CollectionAPI_GroupAddition_H_
--- /dev/null
+// 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 "CollectionAPI_GroupIntersection.h"
+
+#include <ModelHighAPI_Dumper.h>
+#include <ModelHighAPI_Tools.h>
+
+CollectionAPI_GroupIntersection::CollectionAPI_GroupIntersection(
+ const std::shared_ptr<ModelAPI_Feature>& theFeature)
+ : ModelHighAPI_Interface(theFeature)
+{
+ initialize();
+}
+
+CollectionAPI_GroupIntersection::CollectionAPI_GroupIntersection(
+ const std::shared_ptr<ModelAPI_Feature>& theFeature,
+ const std::list<ModelHighAPI_Selection>& theGroupList)
+ : ModelHighAPI_Interface(theFeature)
+{
+ if(initialize()) {
+ setGroupList(theGroupList);
+ }
+}
+
+CollectionAPI_GroupIntersection::~CollectionAPI_GroupIntersection()
+{
+}
+
+void CollectionAPI_GroupIntersection::setGroupList(
+ const std::list<ModelHighAPI_Selection>& theGroupList)
+{
+ fillAttribute(theGroupList, mygroupList);
+ execute();
+}
+
+void CollectionAPI_GroupIntersection::dump(ModelHighAPI_Dumper& theDumper) const
+{
+ FeaturePtr aBase = feature();
+ const std::string& aDocName = theDumper.name(aBase->document());
+
+ AttributeSelectionListPtr anAttrList =
+ aBase->selectionList(CollectionPlugin_GroupIntersection::LIST_ID());
+
+ theDumper << aBase << " = model.addGroupIntersection(" << aDocName << ", "
+ << anAttrList << ")" << std::endl;
+}
+
+GroupIntersectionPtr addGroupIntersection(const std::shared_ptr<ModelAPI_Document>& thePart,
+ const std::list<ModelHighAPI_Selection>& theGroupList)
+{
+ std::shared_ptr<ModelAPI_Feature> aFeature =
+ thePart->addFeature(CollectionAPI_GroupIntersection::ID());
+ return GroupIntersectionPtr(new CollectionAPI_GroupIntersection(aFeature, theGroupList));
+}
--- /dev/null
+// 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 CollectionAPI_GroupIntersection_H_
+#define CollectionAPI_GroupIntersection_H_
+
+#include "CollectionAPI.h"
+
+#include <CollectionPlugin_GroupIntersection.h>
+
+#include <ModelHighAPI_Interface.h>
+#include <ModelHighAPI_Macro.h>
+
+class ModelHighAPI_Dumper;
+class ModelHighAPI_Selection;
+
+/// \class CollectionAPI_GroupIntersection
+/// \ingroup CPPHighAPI
+/// \brief Interface for Group Intersection feature.
+class CollectionAPI_GroupIntersection : public ModelHighAPI_Interface
+{
+public:
+ /// Constructor without values.
+ COLLECTIONAPI_EXPORT
+ explicit CollectionAPI_GroupIntersection(const std::shared_ptr<ModelAPI_Feature>& theFeature);
+
+ /// Constructor with values.
+ COLLECTIONAPI_EXPORT
+ CollectionAPI_GroupIntersection(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+ const std::list<ModelHighAPI_Selection>& theGroupList);
+
+ /// Destructor.
+ COLLECTIONAPI_EXPORT
+ virtual ~CollectionAPI_GroupIntersection();
+
+ INTERFACE_1(CollectionPlugin_GroupIntersection::ID(),
+ groupList, CollectionPlugin_GroupIntersection::LIST_ID(),
+ ModelAPI_AttributeSelectionList, /** Group list*/)
+
+ /// Set main objects.
+ COLLECTIONAPI_EXPORT
+ void setGroupList(const std::list<ModelHighAPI_Selection>& theGroupList);
+
+ /// Dump wrapped feature
+ COLLECTIONAPI_EXPORT
+ virtual void dump(ModelHighAPI_Dumper& theDumper) const;
+};
+
+/// Pointer on Group Addition object.
+typedef std::shared_ptr<CollectionAPI_GroupIntersection> GroupIntersectionPtr;
+
+/// \ingroup CPPHighAPI
+/// \brief Create Group Intersection feature.
+COLLECTIONAPI_EXPORT
+GroupIntersectionPtr addGroupIntersection(const std::shared_ptr<ModelAPI_Document>& thePart,
+ const std::list<ModelHighAPI_Selection>& theGroupsList);
+
+#endif // CollectionAPI_GroupIntersection_H_
CollectionPlugin_Plugin.h
CollectionPlugin_Group.h
CollectionPlugin_GroupAddition.h
+ CollectionPlugin_GroupIntersection.h
CollectionPlugin_Field.h
CollectionPlugin_WidgetCreator.h
CollectionPlugin_WidgetField.h
CollectionPlugin_Plugin.cpp
CollectionPlugin_Group.cpp
CollectionPlugin_GroupAddition.cpp
+ CollectionPlugin_GroupIntersection.cpp
CollectionPlugin_Field.cpp
CollectionPlugin_WidgetCreator.cpp
CollectionPlugin_WidgetField.cpp
TestGroupShareTopology.py
TestGroupAddition.py
TestGroupAddition_Error.py
+ TestGroupIntersection.py
+ TestGroupIntersection_Error.py
)
--- /dev/null
+// 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_GroupIntersection.h"
+
+#include <ModelAPI_Data.h>
+#include <ModelAPI_Document.h>
+#include <ModelAPI_AttributeInteger.h>
+#include <ModelAPI_AttributeString.h>
+#include <ModelAPI_AttributeSelectionList.h>
+#include <ModelAPI_ResultGroup.h>
+
+#include <GeomAPI_ShapeIterator.h>
+#include <GeomAlgoAPI_CompoundBuilder.h>
+#include <GeomAlgoAPI_ShapeTools.h>
+
+typedef std::set<GeomShapePtr, GeomAPI_Shape::ComparatorWithOri> SetOfShape;
+
+CollectionPlugin_GroupIntersection::CollectionPlugin_GroupIntersection()
+{
+}
+
+void CollectionPlugin_GroupIntersection::initAttributes()
+{
+ data()->addAttribute(CollectionPlugin_GroupIntersection::LIST_ID(),
+ ModelAPI_AttributeSelectionList::typeId());
+}
+
+static void explodeCompound(const GeomShapePtr& theCompound, SetOfShape& theSet)
+{
+ for (GeomAPI_ShapeIterator anIt(theCompound); anIt.more(); anIt.next())
+ theSet.insert(anIt.current());
+}
+
+static void keepCommonShapes(const GeomShapePtr& theCompound, ListOfShape& theShapes)
+{
+ if (theShapes.empty()) {
+ for (GeomAPI_ShapeIterator anIt(theCompound); anIt.more(); anIt.next())
+ theShapes.push_back(anIt.current());
+ }
+ else {
+ SetOfShape aSubs;
+ explodeCompound(theCompound, aSubs);
+
+ ListOfShape::iterator anIt = theShapes.begin();
+ while (anIt != theShapes.end()) {
+ if (aSubs.find(*anIt) == aSubs.end()) {
+ // the shape is not found
+ ListOfShape::iterator aRemoveIt = anIt++;
+ theShapes.erase(aRemoveIt);
+ }
+ else
+ ++anIt;
+ }
+ }
+}
+
+void CollectionPlugin_GroupIntersection::execute()
+{
+ ResultGroupPtr aGroup = document()->createGroup(data());
+ // clean the result of the operation
+ aGroup->store(GeomShapePtr());
+
+ // shapes containing in each group
+ ListOfShape aCommon;
+
+ // collect shapes containing in all groups
+ AttributeSelectionListPtr aSelectedGroups = selectionList(LIST_ID());
+ for (int anIndex = 0; anIndex < aSelectedGroups->size(); ++anIndex) {
+ AttributeSelectionPtr aCurSelection = aSelectedGroups->value(anIndex);
+ ResultGroupPtr aCurGroup =
+ std::dynamic_pointer_cast<ModelAPI_ResultGroup>(aCurSelection->context());
+ keepCommonShapes(aCurGroup->shape(), aCommon);
+ if (aCommon.empty())
+ break;
+ }
+
+ if (aCommon.empty()) {
+ setError("Error: Empty result.");
+ removeResults(0);
+ }
+ else {
+ GeomShapePtr aCompound = GeomAlgoAPI_CompoundBuilder::compound(aCommon);
+ aGroup->store(aCompound);
+ setResult(aGroup);
+ }
+}
--- /dev/null
+// 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_GROUPINTERSECTION_H_
+#define COLLECTIONPLUGIN_GROUPINTERSECTION_H_
+
+#include "CollectionPlugin.h"
+#include "CollectionPlugin_Group.h"
+
+/**\class CollectionPlugin_GroupIntersection
+ * \ingroup Plugins
+ * \brief Merge several groups of same shape type into single group.
+ */
+class CollectionPlugin_GroupIntersection : public CollectionPlugin_Group
+{
+ public:
+ /// Extrusion kind
+ inline static const std::string& ID()
+ {
+ static const std::string MY_GROUP_ID("GroupIntersection");
+ return MY_GROUP_ID;
+ }
+ /// attribute name of selected entities list
+ inline static const std::string& LIST_ID()
+ {
+ static const std::string MY_GROUP_LIST_ID("group_list");
+ return MY_GROUP_LIST_ID;
+ }
+
+ /// Returns the kind of a feature
+ COLLECTIONPLUGIN_EXPORT virtual const std::string& getKind()
+ {
+ static std::string MY_KIND = CollectionPlugin_GroupIntersection::ID();
+ return MY_KIND;
+ }
+
+ /// Creates a new group result if needed
+ COLLECTIONPLUGIN_EXPORT virtual void execute();
+
+ /// 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();
+
+};
+
+#endif
#include <CollectionPlugin_Group.h>
#include <CollectionPlugin_GroupAddition.h>
+#include <CollectionPlugin_GroupIntersection.h>
#include <CollectionPlugin_Field.h>
#include <CollectionPlugin_Validators.h>
#include <ModelAPI_Session.h>
return FeaturePtr(new CollectionPlugin_Field);
} else if (theFeatureID == CollectionPlugin_GroupAddition::ID()) {
return FeaturePtr(new CollectionPlugin_GroupAddition);
+ } else if (theFeatureID == CollectionPlugin_GroupIntersection::ID()) {
+ return FeaturePtr(new CollectionPlugin_GroupIntersection);
}
// feature of such kind is not found
<translation>Components are not selected</translation>
</message>
</context>
+ <context>
+ <name>GroupIntersection:EmptyResult</name>
+ <message>
+ <source>Error: Empty result.</source>
+ <translation>Error: Empty result.</translation>
+ </message>
+ </context>
</TS>
--- /dev/null
+# 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
+#
+
+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/Top"), model.selection("FACE", "Box_1_1/Left")])
+Group_2 = model.addGroup(Part_1_doc, [model.selection("FACE", "Box_1_1/Front"), model.selection("FACE", "Box_1_1/Top")])
+Group_3_objects = [model.selection("FACE", "Box_1_1/Front"), model.selection("FACE", "Box_1_1/Right"), model.selection("FACE", "Box_1_1/Top")]
+Group_3 = model.addGroup(Part_1_doc, Group_3_objects)
+GroupIntersection_1_objects = [model.selection("COMPOUND", "Group_1"), model.selection("COMPOUND", "Group_2"), model.selection("COMPOUND", "Group_3")]
+GroupIntersection_1 = model.addGroupIntersection(Part_1_doc, GroupIntersection_1_objects)
+model.end()
+
+from GeomAPI import *
+
+model.testNbResults(GroupIntersection_1, 1)
+model.testNbSubResults(GroupIntersection_1, [0])
+model.testNbSubShapes(GroupIntersection_1, GeomAPI_Shape.SOLID, [0])
+model.testNbSubShapes(GroupIntersection_1, GeomAPI_Shape.FACE, [1])
+model.testNbSubShapes(GroupIntersection_1, GeomAPI_Shape.EDGE, [4])
+model.testNbSubShapes(GroupIntersection_1, GeomAPI_Shape.VERTEX, [8])
+model.testResultsVolumes(GroupIntersection_1, [100])
+
+assert(model.checkPythonDump())
--- /dev/null
+# 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
+#
+
+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/Top"), model.selection("FACE", "Box_1_1/Left")])
+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/Front"), model.selection("FACE", "Box_1_1/Right")])
+GroupIntersection_1_objects = [model.selection("COMPOUND", "Group_1"), model.selection("COMPOUND", "Group_2"), model.selection("COMPOUND", "Group_3")]
+GroupIntersection_1 = model.addGroupIntersection(Part_1_doc, GroupIntersection_1_objects)
+model.end()
+
+assert(GroupIntersection_1.feature().error() != "")
type_choice="objects">
<validator id="CollectionPlugin_OperationAttribute"/>
</multi_selector>
-</source>
\ No newline at end of file
+</source>
<source>
<namevalue id="name"
- label="Name"
- placeholder="Please input the group name">
+ label="Name"
+ placeholder="Please input the group name">
</namevalue>
<multi_selector id="group_list"
- tooltip="Select a set of objects"
- type_choice="Vertices Edges Faces Solids"
- use_choice="true"
- clear_in_neutral_point="false"
- filter_points="false"
- same_topology="true">
- <validator id="GeomValidators_BodyShapes"/>
+ tooltip="Select a set of groups"
+ type_choice="objects">
+ <validator id="CollectionPlugin_OperationAttribute"/>
</multi_selector>
-</source>
\ No newline at end of file
+</source>
helpfile="groupAdditionFeature.html">
<source path="group_addition_widget.xml"/>
</feature>
+
+ <feature id="GroupIntersection"
+ title="Group Intersection"
+ tooltip="Get elements existing in all groups"
+ icon="icons/Collection/group_intersection.png"
+ apply_continue="true"
+ helpfile="groupIntersectionFeature.html">
+ <source path="group_intersection_widget.xml"/>
+ </feature>
</group>
</workbench>
</plugin>
"""
from CollectionAPI import addGroup, addField
-from CollectionAPI import addGroupAddition
+from CollectionAPI import addGroupAddition, addGroupIntersection