]> SALOME platform Git repositories - modules/shaper.git/blob - src/PartSet/PartSet_IconFactory.cpp
Salome HOME
Auto-rebuild management
[modules/shaper.git] / src / PartSet / PartSet_IconFactory.cpp
1 // Copyright (C) 2014-2017  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 //
20
21 #include "PartSet_IconFactory.h"
22 #include <ModuleBase_ActionInfo.h>
23 #include <ModuleBase_Tools.h>
24
25 #include <ModelAPI_ResultPart.h>
26 #include <ModelAPI_ResultConstruction.h>
27 #include <ModelAPI_ResultBody.h>
28
29 #include <Config_FeatureMessage.h>
30 #include <Events_Loop.h>
31
32 #include <CollectionPlugin_Group.h>
33
34 QMap<QString, QString> PartSet_IconFactory::myIcons;
35
36 PartSet_IconFactory::PartSet_IconFactory():ModuleBase_IconFactory()
37 {
38   Events_Loop::loop()->registerListener(this,
39     Events_Loop::eventByName(Config_FeatureMessage::GUI_EVENT()));
40 }
41
42
43 QIcon PartSet_IconFactory::getIcon(ObjectPtr theObj)
44 {
45   QIcon anIcon;
46
47   if (!theObj.get())
48     return anIcon;
49
50   FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theObj);
51   if (aFeature.get()) {
52     std::string aKind = aFeature->getKind();
53     QString aId(aKind.c_str());
54     if (!myIcons.contains(aId))
55       return anIcon;
56
57     QString anIconString = myIcons[aId];
58
59     ModelAPI_ExecState aState = aFeature->data()->execState();
60     switch(aState) {
61       case ModelAPI_StateDone:
62       case ModelAPI_StateNothing: {
63         anIcon = loadIcon(anIconString);
64       }
65       break;
66       case ModelAPI_StateMustBeUpdated: {
67         anIcon = ModuleBase_Tools::composite(":icons/toWork.png", anIconString);
68         //anIcon = ModuleBase_Tools::lighter(anIconString);
69       }
70       break;
71       case ModelAPI_StateExecFailed: {
72         anIcon = ModuleBase_Tools::composite(":icons/isFailed.png", anIconString);
73       }
74       break;
75       case ModelAPI_StateInvalidArgument: {
76         anIcon = ModuleBase_Tools::composite(":icons/exec_state_invalid_parameters.png",
77                                              anIconString);
78       }
79       break;
80       default: break;
81     }
82   }
83
84   //if (theObj->data() && theObj->data()->execState() == ModelAPI_StateMustBeUpdated)
85   //  return QIcon(":pictures/constr_object_modified.png");
86
87   std::string aGroup = theObj->groupName();
88   if (aGroup == ModelAPI_ResultPart::group())
89     return QIcon(":pictures/part_ico.png");
90
91   if (aGroup == ModelAPI_ResultConstruction::group())
92     return QIcon(":pictures/constr_object.png");
93
94   ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObj);
95   if (aResult.get()) {
96     GeomShapePtr aShape = aResult->shape();
97     if(aShape.get()) {
98       switch(aShape->shapeType()) {
99         case GeomAPI_Shape::COMPOUND: {
100           FeaturePtr aFeature = ModelAPI_Feature::feature(theObj);
101           if (aFeature.get() && aFeature->getKind() == CollectionPlugin_Group::ID()) {
102             switch (aShape->typeOfCompoundShapes()) {
103             case GeomAPI_Shape::VERTEX:
104               return QIcon(":icons/group_vertex.png");
105             case GeomAPI_Shape::EDGE:
106               return QIcon(":icons/group_edge.png");
107             case GeomAPI_Shape::FACE:
108               return QIcon(":icons/group_face.png");
109             case GeomAPI_Shape::SOLID:
110               return QIcon(":icons/group_solid.png");
111             }
112           }
113           ResultBodyPtr aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aResult);
114           if (aBody.get() && aBody->isConnectedTopology())
115             return QIcon(":pictures/compoundofsolids.png");
116           return QIcon(":pictures/compound.png");
117         }
118         case GeomAPI_Shape::COMPSOLID: return QIcon(":pictures/compsolid.png");
119         case GeomAPI_Shape::SOLID:     return QIcon(":pictures/solid.png");
120         case GeomAPI_Shape::SHELL:     return QIcon(":pictures/shell.png");
121         case GeomAPI_Shape::FACE:      return QIcon(":pictures/face.png");
122         case GeomAPI_Shape::WIRE:      return QIcon(":pictures/wire.png");
123         case GeomAPI_Shape::EDGE:      return QIcon(":pictures/edge.png");
124         case GeomAPI_Shape::VERTEX:    return QIcon(":pictures/vertex.png");
125       }
126     }
127   }
128   return anIcon;
129 }
130
131 void PartSet_IconFactory::processEvent(const std::shared_ptr<Events_Message>& theMessage)
132 {
133   if (theMessage->eventID() ==
134       Events_Loop::loop()->eventByName(Config_FeatureMessage::GUI_EVENT())) {
135     std::shared_ptr<Config_FeatureMessage> aFeatureMsg =
136        std::dynamic_pointer_cast<Config_FeatureMessage>(theMessage);
137     if (!aFeatureMsg->isInternal()) {
138       ActionInfo aFeatureInfo;
139       aFeatureInfo.initFrom(aFeatureMsg);
140       // Remember features icons
141       myIcons[QString::fromStdString(aFeatureMsg->id())] = aFeatureInfo.iconFile;
142     }
143   }
144 }