Salome HOME
Validator for partition
[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   setFactory(this);
23   Events_Loop::loop()->registerListener(this, 
24     Events_Loop::eventByName(Config_FeatureMessage::GUI_EVENT()));
25 }
26
27
28 QIcon PartSet_IconFactory::getIcon(ObjectPtr theObj)
29 {
30   QIcon anIcon;
31
32   FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theObj);
33   if (aFeature.get()) {
34     std::string aKind = aFeature->getKind();
35     QString aId(aKind.c_str());
36     if (!myIcons.contains(aId))
37       return anIcon;
38
39     QString anIconString = myIcons[aId];
40
41     ModelAPI_ExecState aState = aFeature->data()->execState();
42     switch(aState) {
43       case ModelAPI_StateDone:
44       case ModelAPI_StateNothing: {
45         anIcon = QIcon(anIconString);
46       }
47       break;
48       case ModelAPI_StateMustBeUpdated: {
49         anIcon = ModuleBase_Tools::lighter(anIconString);
50       }
51       break;
52       case ModelAPI_StateExecFailed: {
53         anIcon = ModuleBase_Tools::composite(":icons/exec_state_failed.png", anIconString);
54       }
55       break;
56       case ModelAPI_StateInvalidArgument: {
57         anIcon = ModuleBase_Tools::composite(":icons/exec_state_invalid_parameters.png",
58                                              anIconString);
59       }
60       break;
61       default: break;  
62     }
63   } else {
64     std::string aGroup = theObj->groupName();
65     if (aGroup == ModelAPI_ResultPart::group()) {
66       return QIcon(":pictures/part_ico.png");
67     } else {
68       if (theObj && theObj->data() && theObj->data()->execState() == ModelAPI_StateMustBeUpdated)
69         return QIcon(":pictures/constr_object_modified.png");
70       return QIcon(":pictures/constr_object.png");
71     }
72   }
73   return anIcon;  
74 }
75
76 void PartSet_IconFactory::processEvent(const std::shared_ptr<Events_Message>& theMessage)
77 {
78   if (theMessage->eventID() == Events_Loop::loop()->eventByName(Config_FeatureMessage::GUI_EVENT())) {
79     std::shared_ptr<Config_FeatureMessage> aFeatureMsg =
80        std::dynamic_pointer_cast<Config_FeatureMessage>(theMessage);
81     if (!aFeatureMsg->isInternal()) {
82       ActionInfo aFeatureInfo;
83       aFeatureInfo.initFrom(aFeatureMsg);
84       // Remember features icons
85       myIcons[QString::fromStdString(aFeatureMsg->id())] = aFeatureInfo.iconFile;
86     }
87   }
88 }