Salome HOME
Fix for the issue 1526: optimization of isConnectedTopology calls
[modules/shaper.git] / src / PartSet / PartSet_IconFactory.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        PartSet_IconFactory.cpp
4 // Created:     28 Jul 2015
5 // Author:      Vitaly SMETANNIKOV
6
7 #include "PartSet_IconFactory.h"
8 #include <ModuleBase_ActionInfo.h>
9 #include <ModuleBase_Tools.h>
10
11 #include <ModelAPI_ResultPart.h>
12 #include <ModelAPI_ResultConstruction.h>
13 #include <ModelAPI_ResultBody.h>
14
15 #include <Config_FeatureMessage.h>
16 #include <Events_Loop.h>
17
18 QMap<QString, QString> PartSet_IconFactory::myIcons;
19
20 PartSet_IconFactory::PartSet_IconFactory():ModuleBase_IconFactory()
21 {
22   Events_Loop::loop()->registerListener(this, 
23     Events_Loop::eventByName(Config_FeatureMessage::GUI_EVENT()));
24 }
25
26
27 QIcon PartSet_IconFactory::getIcon(ObjectPtr theObj)
28 {
29   QIcon anIcon;
30
31   if (!theObj.get())
32     return anIcon;
33
34   FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theObj);
35   if (aFeature.get()) {
36     std::string aKind = aFeature->getKind();
37     QString aId(aKind.c_str());
38     if (!myIcons.contains(aId))
39       return anIcon;
40
41     QString anIconString = myIcons[aId];
42
43     ModelAPI_ExecState aState = aFeature->data()->execState();
44     switch(aState) {
45       case ModelAPI_StateDone:
46       case ModelAPI_StateNothing: {
47         anIcon = loadIcon(anIconString);
48       }
49       break;
50       case ModelAPI_StateMustBeUpdated: {
51         anIcon = ModuleBase_Tools::lighter(anIconString);
52       }
53       break;
54       case ModelAPI_StateExecFailed: {
55         anIcon = ModuleBase_Tools::composite(":icons/exec_state_failed.png", anIconString);
56       }
57       break;
58       case ModelAPI_StateInvalidArgument: {
59         anIcon = ModuleBase_Tools::composite(":icons/exec_state_invalid_parameters.png",
60                                              anIconString);
61       }
62       break;
63       default: break;  
64     }
65   } 
66
67   if (theObj->data() && theObj->data()->execState() == ModelAPI_StateMustBeUpdated)
68     return QIcon(":pictures/constr_object_modified.png");
69
70   std::string aGroup = theObj->groupName();
71   if (aGroup == ModelAPI_ResultPart::group())
72     return QIcon(":pictures/part_ico.png");
73
74   if (aGroup == ModelAPI_ResultConstruction::group())
75     return QIcon(":pictures/constr_object.png");
76
77   ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObj);
78   if (aResult.get()) {
79     GeomShapePtr aShape = aResult->shape();
80     if(aShape.get()) {
81       switch(aShape->shapeType()) {
82         case GeomAPI_Shape::COMPOUND: {
83           ResultBodyPtr aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aResult);
84           if (aBody.get() && aBody->isConnectedTopology())
85             return QIcon(":pictures/compoundofsolids.png");
86           return QIcon(":pictures/compound.png");
87         }
88         case GeomAPI_Shape::COMPSOLID: return QIcon(":pictures/compsolid.png");
89         case GeomAPI_Shape::SOLID:     return QIcon(":pictures/solid.png");
90         case GeomAPI_Shape::SHELL:     return QIcon(":pictures/shell.png");
91         case GeomAPI_Shape::FACE:      return QIcon(":pictures/face.png");
92         case GeomAPI_Shape::WIRE:      return QIcon(":pictures/wire.png");
93         case GeomAPI_Shape::EDGE:      return QIcon(":pictures/edge.png");
94         case GeomAPI_Shape::VERTEX:    return QIcon(":pictures/vertex.png");
95       }
96     }
97   }
98   return anIcon;
99 }
100
101 void PartSet_IconFactory::processEvent(const std::shared_ptr<Events_Message>& theMessage)
102 {
103   if (theMessage->eventID() == Events_Loop::loop()->eventByName(Config_FeatureMessage::GUI_EVENT())) {
104     std::shared_ptr<Config_FeatureMessage> aFeatureMsg =
105        std::dynamic_pointer_cast<Config_FeatureMessage>(theMessage);
106     if (!aFeatureMsg->isInternal()) {
107       ActionInfo aFeatureInfo;
108       aFeatureInfo.initFrom(aFeatureMsg);
109       // Remember features icons
110       myIcons[QString::fromStdString(aFeatureMsg->id())] = aFeatureInfo.iconFile;
111     }
112   }
113 }