1 // Copyright (C) 2018-2021 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "FeaturesPlugin_CommonSharedFaces.h"
22 #include <ModelAPI_AttributeSelection.h>
23 #include <ModelAPI_AttributeSelectionList.h>
24 #include <ModelAPI_AttributeString.h>
25 #include <ModelAPI_AttributeBoolean.h>
26 #include <ModelAPI_Tools.h>
28 #include <GeomAlgoAPI_CompoundBuilder.h>
29 #include <GeomAlgoAPI_ShapeTools.h>
33 //=================================================================================================
34 void FeaturesPlugin_CommonSharedFaces::updateFaces()
36 AttributeSelectionPtr aCompSolidAttr =
37 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(attributObject());
38 AttributeSelectionListPtr aFacesListAttr =
39 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList> (attributListFaces());
41 GeomShapePtr aShape = aCompSolidAttr->value();
43 AttributeBooleanPtr anIsCompute =
44 std::dynamic_pointer_cast<ModelAPI_AttributeBoolean>(attributIsCompute());
45 if (!anIsCompute->value()) {
47 anIsCompute->setValue(true);
49 if (aShape.get() && aCompSolidAttr->context().get() && !aShape->isEqual(myShape)) {
50 if (aFacesListAttr->isInitialized())
51 aFacesListAttr->clear();
52 aShape = aCompSolidAttr->context()->shape();
54 ListOfShape aFaces = GeomAlgoAPI_ShapeTools::getSharedFaces(aShape);
56 aFacesListAttr->setSelectionType("face");
57 ListOfShape::const_iterator anIt = aFaces.cbegin();
58 for(; anIt != aFaces.cend(); ++anIt) {
59 GeomShapePtr aFacePtr = *anIt;
60 if (!(aFacesListAttr->isInList(aCompSolidAttr->context(), aFacePtr))) {
61 aFacesListAttr->append(aCompSolidAttr->context(), aFacePtr);
64 std::stringstream aLabel;
65 aLabel << aFacesListAttr->size();
66 AttributeStringPtr aNumberFacesAttr =
67 std::dynamic_pointer_cast<ModelAPI_AttributeString>(attributNumberFaces());
68 aNumberFacesAttr->setValue(aLabel.str());
73 //=================================================================================================
74 void FeaturesPlugin_CommonSharedFaces::setFacesGroup(const std::wstring& theName)
76 std::vector<int> aColor;
77 ResultGroupPtr aGroup = document()->createGroup(data());
78 // Clean the result of the operation
79 aGroup->data()->setName(theName);
80 aGroup->store(GeomShapePtr());
82 // shapes containing in group
84 AttributeSelectionListPtr aFacesListAttr =
85 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList> (attributListFaces());
87 for (int anI =0; anI< aFacesListAttr->size(); anI++) {
88 AttributeSelectionPtr aAtt = aFacesListAttr->value(anI);
89 aFaces.push_back(aAtt->value());
92 GeomShapePtr aCompound = GeomAlgoAPI_CompoundBuilder::compound(aFaces);
93 aGroup->store(aCompound);
96 ModelAPI_Tools::setColor(lastResult(),aColor);