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_GroupSharedFaces.h"
22 #include <ModelAPI_AttributeSelection.h>
23 #include <ModelAPI_AttributeSelectionList.h>
24 #include <ModelAPI_AttributeBoolean.h>
25 #include <ModelAPI_AttributeString.h>
26 #include <ModelAPI_AttributeInteger.h>
27 #include <ModelAPI_Session.h>
28 #include <ModelAPI_Tools.h>
29 #include <ModelAPI_Validator.h>
31 #include <Locale_Convert.h>
35 //=================================================================================================
36 FeaturesPlugin_GroupSharedFaces::FeaturesPlugin_GroupSharedFaces()
40 //=================================================================================================
41 void FeaturesPlugin_GroupSharedFaces::initAttributes()
43 data()->addAttribute(OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
44 data()->addAttribute(LIST_FACES_ID(), ModelAPI_AttributeSelectionList::typeId());
45 data()->addAttribute(NUMBER_FACES_ID(), ModelAPI_AttributeString::typeId());
46 data()->addAttribute(TRANSPARENCY_ID(), ModelAPI_AttributeInteger::typeId());
47 data()->addAttribute(GROUP_NAME_ID(), ModelAPI_AttributeString::typeId());
48 data()->addAttribute(COMPUTE_ID(), ModelAPI_AttributeBoolean::typeId());
50 ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), TRANSPARENCY_ID());
51 ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), COMPUTE_ID());
52 ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), NUMBER_FACES_ID());
53 ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), LIST_FACES_ID());
55 data()->boolean(COMPUTE_ID())->setValue(true);
58 //=================================================================================================
59 AttributePtr FeaturesPlugin_GroupSharedFaces::attributObject()
61 return attribute(OBJECT_ID());
64 //=================================================================================================
65 AttributePtr FeaturesPlugin_GroupSharedFaces::attributIsCompute()
67 return attribute(COMPUTE_ID());
70 //=================================================================================================
71 AttributePtr FeaturesPlugin_GroupSharedFaces::attributListFaces()
73 return attribute(LIST_FACES_ID());
76 //=================================================================================================
77 AttributePtr FeaturesPlugin_GroupSharedFaces::attributNumberFaces()
79 return attribute(NUMBER_FACES_ID());
82 //=================================================================================================
83 void FeaturesPlugin_GroupSharedFaces::execute()
85 if (selectionList(LIST_FACES_ID())->isInitialized()
86 && string(GROUP_NAME_ID())->value() != "") {
87 AttributeStringPtr aNameAtt = string(GROUP_NAME_ID()) ;
88 std::wstring aNameFace = aNameAtt->isUValue() ?
89 Locale::Convert::toWString(aNameAtt->valueU()) :
90 Locale::Convert::toWString(aNameAtt->value());
92 if (lastResult().get())
93 eraseResultFromList(lastResult());
94 setFacesGroup(aNameFace);
96 if (lastResult().get()) {
97 eraseResultFromList(lastResult());
100 if (selection(OBJECT_ID())->isInitialized() && integer(TRANSPARENCY_ID())->isInitialized()) {
101 AttributeSelectionPtr aCompSolidAttr = selection(OBJECT_ID());
102 ResultPtr aResult = aCompSolidAttr->context();
104 double aTranparency = integer(TRANSPARENCY_ID())->value() / 100.0;
105 ModelAPI_Tools::setTransparency(aResult, aTranparency);
107 ResultBodyPtr aResultBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aResult);
108 std::list<ResultPtr> allRes;
109 ModelAPI_Tools::allSubs(aResultBody, allRes);
110 std::list<ResultPtr>::iterator aRes;
111 for(aRes = allRes.begin(); aRes != allRes.end(); aRes++) {
112 ModelAPI_Tools::setTransparency(*aRes, aTranparency);
116 // Update the number of shared faces
117 AttributeSelectionListPtr aFacesListAttr =
118 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList> (attributListFaces());
119 AttributeStringPtr aNumberFacesAttr =
120 std::dynamic_pointer_cast<ModelAPI_AttributeString> (attributNumberFaces());
121 std::stringstream aLabel;
122 aLabel << aFacesListAttr->size();
123 aNumberFacesAttr->setValue(aLabel.str());
126 //=================================================================================================
127 void FeaturesPlugin_GroupSharedFaces::attributeChanged(const std::string& theID)
129 if (theID == OBJECT_ID() || theID == LIST_FACES_ID())