--- /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 (by feature) in group selection
+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, "Faces", [model.selection("COMPOUND", "all-in-Box_1")])
+Group_2 = model.addGroup(Part_1_doc, "Faces", [model.selection("FACE", "Box_1_1/Left"), model.selection("FACE", "Box_1_1/Top")])
+GroupSubstraction_1 = model.addGroupSubstraction(Part_1_doc, [model.selection("COMPOUND", "Group_1")], [model.selection("COMPOUND", "Group_2")])
+model.end()
+
+aResultShape = GroupSubstraction_1.feature().firstResult().shape()
+
+from GeomAPI import GeomAPI_ShapeIterator
+anIter = GeomAPI_ShapeIterator(aResultShape)
+aNum = 0
+while anIter.more():
+ aFace = anIter.current()
+ assert(aFace.isFace())
+ aNum = aNum + 1
+ anIter.next()
+
+assert(aNum == 4) # 6 from the whole result minus 2 from the second group (local selection)
+
+
+assert(model.checkPythonDump())
// if context is in results, return true
for(int a = 0; a < theSelection->size(); a++) {
AttributeSelectionPtr anAttr = theSelection->value(a);
- ResultBodyPtr aSelected= std::dynamic_pointer_cast<ModelAPI_ResultBody>(anAttr->context());
- if (aSelected.get() && theCashedResults.count(aSelected))
+ ResultPtr aContext = anAttr->context();
+ // check is it group selected for groups BOP
+ if (aContext.get() && aContext->groupName() == ModelAPI_ResultGroup::group()) {
+ // it is impossible by used results check which result is used in this group result,
+ // so check the results shapes is it in results of this document or not
+ FeaturePtr aSelFeature =
+ std::dynamic_pointer_cast<ModelAPI_Feature>(theSelection->owner());
+ if (!aSelFeature.get() || aSelFeature->results().empty())
+ continue;
+ GeomShapePtr aGroupResShape = aSelFeature->firstResult()->shape();
+
+ std::set<ResultPtr>::iterator allResultsIter = theCashedResults.begin();
+ for(; allResultsIter != theCashedResults.end(); allResultsIter++) {
+ GeomShapePtr aResultShape = (*allResultsIter)->shape();
+
+ GeomAPI_Shape::ShapeType aType =
+ GeomAPI_Shape::shapeTypeByStr(theSelection->selectionType());
+ GeomAPI_ShapeExplorer aGroupResExp(aGroupResShape, aType);
+ for(; aGroupResExp.more(); aGroupResExp.next()) {
+ if (aResultShape->isSubShape(aGroupResExp.current(), false))
+ return true; // at least one shape of the group is in the used results
+ }
+ }
+ }
+ ResultBodyPtr aSelected = std::dynamic_pointer_cast<ModelAPI_ResultBody>(anAttr->context());
+ if (!aSelected.get()) { // try to get selected feature and all its results
+ FeaturePtr aContextFeature = anAttr->contextFeature();
+ if (aContextFeature.get() && !aContextFeature->results().empty()) {
+ const std::list<ResultPtr>& allResluts = aContextFeature->results();
+ std::list<ResultPtr>::const_iterator aResIter = allResluts.cbegin();
+ for(; aResIter != allResluts.cend(); aResIter++) {
+ if (aResIter->get() && theCashedResults.count(*aResIter))
+ return true;
+ }
+ }
+ } else if (aSelected.get() && theCashedResults.count(aSelected))
return true;
}
return false;
for (int aGroupIndex = 0; aGroupIndex < aGroupCount; ++aGroupIndex) {
ResultGroupPtr aResultGroup = std::dynamic_pointer_cast<ModelAPI_ResultGroup>(
(*aDoc)->object(ModelAPI_ResultGroup::group(), aGroupIndex));
+ if (!aResultGroup.get() || !aResultGroup->shape().get())
+ continue;
FeaturePtr aGroupFeature = (*aDoc)->feature(aResultGroup);
aResultGroup->data()->name());
try {
- for (int aSelectionIndex = 0; aSelectionIndex < aSelectionList->size(); ++aSelectionIndex){
- AttributeSelectionPtr aSelection = aSelectionList->value(aSelectionIndex);
- GeomShapePtr aSelShape = aSelection->value();
- if (!aSelShape.get() && aSelection->context().get()) {
- aSelShape = aSelection->context()->shape();
- }
-
- std::list<GeomShapePtr> allSubs;
- allSubShapes(aSelShape, aSelType, allSubs);
-
- std::list<GeomShapePtr>::iterator anIter = allSubs.begin();
- for(; anIter != allSubs.end(); anIter++) {
- int aReferenceID = GeomAlgoAPI_CompoundBuilder::id(aShape, *anIter);
- if (aReferenceID == 0) // selected value does not found in the exported shape
- continue;
- std::string aReferenceString = XAO::XaoUtils::intToString(aReferenceID);
- int anElementID =
- aXao.getGeometry()->getElementIndexByReference(aGroupDimension, aReferenceString);
- aXaoGroup->add(anElementID);
- }
+ GeomAPI_ShapeExplorer aGroupResExplorer(aResultGroup->shape(), aSelType);
+ for(; aGroupResExplorer.more(); aGroupResExplorer.next()) {
+ int aReferenceID = GeomAlgoAPI_CompoundBuilder::id(aShape, aGroupResExplorer.current());
+ if (aReferenceID == 0) // selected value does not found in the exported shape
+ continue;
+ std::string aReferenceString = XAO::XaoUtils::intToString(aReferenceID);
+ int anElementID =
+ aXao.getGeometry()->getElementIndexByReference(aGroupDimension, aReferenceString);
+ aXaoGroup->add(anElementID);
}
} catch (XAO::XAO_Exception& e) {
// LCOV_EXCL_START