AttributeSelectionListPtr anAttrList = aBase->selectionList(CollectionPlugin_Group::LIST_ID());
- theDumper << aBase << " = model.addGroup(" << aDocName << ", " << anAttrList;
+ theDumper << aBase << " = model.addGroup(" << aDocName << ", ";
+ if (anAttrList->isWholeResultAllowed())
+ theDumper<<"\""<<anAttrList->selectionType()<<"\", ";
+ theDumper << anAttrList;
if (anAttrList->isGeometricalSelection())
theDumper <<", True";
theDumper << ")" << std::endl;
aFeature->selectionList(CollectionPlugin_Group::LIST_ID())->setGeometricalSelection(true);
return GroupPtr(new CollectionAPI_Group(aFeature, theGroupList));
}
+
+//==================================================================================================
+GroupPtr addGroup(const std::shared_ptr<ModelAPI_Document>& thePart,
+ const std::string& theSelectionType,
+ const std::list<ModelHighAPI_Selection>& theGroupList,
+ const bool theShareSameTopology)
+{
+ std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(CollectionAPI_Group::ID());
+ aFeature->selectionList(CollectionPlugin_Group::LIST_ID())->setSelectionType(theSelectionType);
+ if (theShareSameTopology)
+ aFeature->selectionList(CollectionPlugin_Group::LIST_ID())->setGeometricalSelection(true);
+ return GroupPtr(new CollectionAPI_Group(aFeature, theGroupList));
+}
const std::list<ModelHighAPI_Selection>& theGroupList,
const bool theShareSameTopology = false);
+/// \ingroup CPPHighAPI
+/// \brief Create Group with the additional selection type for case the whole result selected.
+COLLECTIONAPI_EXPORT
+GroupPtr addGroup(const std::shared_ptr<ModelAPI_Document>& thePart,
+ const std::string& theSelectionType,
+ const std::list<ModelHighAPI_Selection>& theGroupList,
+ const bool theShareSameTopology = false);
+
#endif // CollectionAPI_Group_H_
TestGroupSubstraction_Error1.py
TestGroupSubstraction_Error2.py
Test2977.py
+ TestGroupWholeResult1.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
+#
+
+# Tests python API for the whole result in group selection
+
+from salome.shaper import model
+
+model.begin()
+partSet = model.moduleDocument()
+Part_1 = model.addPart(partSet)
+Part_1_doc = Part_1.document()
+Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
+SketchLine_1 = Sketch_1.addLine(-16, -4, -4, 29)
+SketchLine_2 = Sketch_1.addLine(-4, 29, 21, -9)
+SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint())
+SketchLine_3 = Sketch_1.addLine(21, -9, -16, -4)
+SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchLine_2.endPoint(), SketchLine_3.startPoint())
+SketchConstraintCoincidence_3 = Sketch_1.setCoincident(SketchLine_1.startPoint(), SketchLine_3.endPoint())
+model.do()
+Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("FACE", "Sketch_1/Face-SketchLine_3r-SketchLine_2r-SketchLine_1r")], model.selection(), 10, 0)
+Group_1 = model.addGroup(Part_1_doc, "EDGE", [model.selection("SOLID", "Extrusion_1_1")])
+model.end()
+
+# check the group result: it must be compound of 9 edges
+assert(Group_1.groupList().selectionType() == "EDGE")
+assert(len(Group_1.results()) == 1)
+assert(Group_1.result().shapeType() == "COMPOUND")
+
+from GeomAPI import GeomAPI_ShapeIterator
+aResultShape = Group_1.feature().firstResult().shape()
+anIter = GeomAPI_ShapeIterator(aResultShape)
+aNum = 0
+while anIter.more():
+ anEdge = anIter.current()
+ assert(anEdge.isEdge())
+ aNum = aNum + 1
+ anIter.next()
+
+assert(aNum == 9)
+
+assert(model.checkPythonDump())
#include <ModelAPI_AttributeSelectionList.h>
#include <GeomAlgoAPI_CompoundBuilder.h>
+#include <GeomAPI_ShapeExplorer.h>
#include <Config_PropManager.h>
if (!aResult && myOwnerData) {
AttributeSelectionListPtr aList = myOwnerData->selectionList("group_list");
if (aList) {
+ GeomAPI_DataMapOfShapeShape aShapesMap; // to avoid shapes duplication
std::list<std::shared_ptr<GeomAPI_Shape> > aSubs;
for(int a = aList->size() - 1; a >= 0; a--) {
std::shared_ptr<GeomAPI_Shape> aSelection = aList->value(a)->value();
- if (aSelection && !aSelection->isNull()) {
- aSubs.push_back(aSelection);
+ if (aList->isWholeResultAllowed()) { // whole result selection, explode to sub-shapes
+ if (!aSelection.get() || aSelection->isNull()) {
+ ResultPtr aContext = aList->value(a)->context();
+ if (aContext)
+ aSelection = aContext->shape();
+ }
+ if (aSelection && !aSelection->isNull()) {
+ GeomAPI_Shape::ShapeType aType = GeomAPI_Shape::shapeTypeByStr(aList->selectionType());
+ if (aType == aSelection->shapeType()) {
+ if (aShapesMap.bind(aSelection, aSelection))
+ aSubs.push_back(aSelection);
+ } else {
+ for(GeomAPI_ShapeExplorer anExp(aSelection, aType); anExp.more(); anExp.next()) {
+ if (aShapesMap.bind(anExp.current(), anExp.current()))
+ aSubs.push_back(anExp.current());
+ }
+ }
+ }
+ } else { // take selection as it is
+ if (aSelection && !aSelection->isNull()) {
+ if (aShapesMap.bind(aSelection, aSelection))
+ aSubs.push_back(aSelection);
+ }
}
}
if (!aSubs.empty()) {
{
theAttribute->clear();
- if(!theValue.empty()) {
+ if(!theValue.empty() && theAttribute->selectionType().empty()) {
const ModelHighAPI_Selection& aSelection = theValue.front();
GeomAPI_Shape::ShapeType aSelectionType = getShapeType(aSelection);
theAttribute->setSelectionType(strByShapeType(aSelectionType));
if (aDump.get()) {
aDump->string("file_path")->setValue(theFilename);
aDump->string("file_format")->setValue("py");
- aDump->boolean("topological_naming")->setValue(theSelectionType & CHECK_NAMING);
- aDump->boolean("geometric_selection")->setValue(theSelectionType & CHECK_GEOMETRICAL);
- aDump->boolean("weak_naming")->setValue(theSelectionType & CHECK_WEAK);
+ aDump->boolean("topological_naming")->setValue((theSelectionType & CHECK_NAMING) != 0);
+ aDump->boolean("geometric_selection")->setValue((theSelectionType & CHECK_GEOMETRICAL) != 0);
+ aDump->boolean("weak_naming")->setValue((theSelectionType & CHECK_WEAK) != 0);
}
bool isProblem = !aDump.get() || !aDump->error().empty(); // after "finish" dump will be removed
if (isProblem && aDump.get()) {