1 // Copyright (C) 2014-2017 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<mailto:webmaster.salome@opencascade.com>
20 #include "PartSet_IconFactory.h"
21 #include <ModuleBase_ActionInfo.h>
22 #include <ModuleBase_Tools.h>
24 #include <ModelAPI_ResultPart.h>
25 #include <ModelAPI_ResultConstruction.h>
26 #include <ModelAPI_ResultBody.h>
28 #include <Config_FeatureMessage.h>
29 #include <Events_Loop.h>
31 QMap<QString, QString> PartSet_IconFactory::myIcons;
33 PartSet_IconFactory::PartSet_IconFactory():ModuleBase_IconFactory()
35 Events_Loop::loop()->registerListener(this,
36 Events_Loop::eventByName(Config_FeatureMessage::GUI_EVENT()));
40 QIcon PartSet_IconFactory::getIcon(ObjectPtr theObj)
47 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theObj);
49 std::string aKind = aFeature->getKind();
50 QString aId(aKind.c_str());
51 if (!myIcons.contains(aId))
54 QString anIconString = myIcons[aId];
56 ModelAPI_ExecState aState = aFeature->data()->execState();
58 case ModelAPI_StateDone:
59 case ModelAPI_StateNothing: {
60 anIcon = loadIcon(anIconString);
63 case ModelAPI_StateMustBeUpdated: {
64 anIcon = ModuleBase_Tools::lighter(anIconString);
67 case ModelAPI_StateExecFailed: {
68 anIcon = ModuleBase_Tools::composite(":icons/exec_state_failed.png", anIconString);
71 case ModelAPI_StateInvalidArgument: {
72 anIcon = ModuleBase_Tools::composite(":icons/exec_state_invalid_parameters.png",
80 if (theObj->data() && theObj->data()->execState() == ModelAPI_StateMustBeUpdated)
81 return QIcon(":pictures/constr_object_modified.png");
83 std::string aGroup = theObj->groupName();
84 if (aGroup == ModelAPI_ResultPart::group())
85 return QIcon(":pictures/part_ico.png");
87 if (aGroup == ModelAPI_ResultConstruction::group())
88 return QIcon(":pictures/constr_object.png");
90 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObj);
92 GeomShapePtr aShape = aResult->shape();
94 switch(aShape->shapeType()) {
95 case GeomAPI_Shape::COMPOUND: {
96 ResultBodyPtr aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aResult);
97 if (aBody.get() && aBody->isConnectedTopology())
98 return QIcon(":pictures/compoundofsolids.png");
99 return QIcon(":pictures/compound.png");
101 case GeomAPI_Shape::COMPSOLID: return QIcon(":pictures/compsolid.png");
102 case GeomAPI_Shape::SOLID: return QIcon(":pictures/solid.png");
103 case GeomAPI_Shape::SHELL: return QIcon(":pictures/shell.png");
104 case GeomAPI_Shape::FACE: return QIcon(":pictures/face.png");
105 case GeomAPI_Shape::WIRE: return QIcon(":pictures/wire.png");
106 case GeomAPI_Shape::EDGE: return QIcon(":pictures/edge.png");
107 case GeomAPI_Shape::VERTEX: return QIcon(":pictures/vertex.png");
114 void PartSet_IconFactory::processEvent(const std::shared_ptr<Events_Message>& theMessage)
116 if (theMessage->eventID() ==
117 Events_Loop::loop()->eventByName(Config_FeatureMessage::GUI_EVENT())) {
118 std::shared_ptr<Config_FeatureMessage> aFeatureMsg =
119 std::dynamic_pointer_cast<Config_FeatureMessage>(theMessage);
120 if (!aFeatureMsg->isInternal()) {
121 ActionInfo aFeatureInfo;
122 aFeatureInfo.initFrom(aFeatureMsg);
123 // Remember features icons
124 myIcons[QString::fromStdString(aFeatureMsg->id())] = aFeatureInfo.iconFile;