]> SALOME platform Git repositories - modules/yacs.git/blob - src/genericgui/SchemaOutPortItem.cxx
Salome HOME
c55c1cdce620d6abc0dfc3a69c7f10f4800a90f5
[modules/yacs.git] / src / genericgui / SchemaOutPortItem.cxx
1 //  Copyright (C) 2006-2008  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.
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 email : webmaster.salome@opencascade.com
18 //
19 #include "SchemaOutPortItem.hxx"
20 #include "ItemMimeData.hxx"
21 #include "QtGuiContext.hxx"
22 #include "Menus.hxx"
23
24 #include "commandsProc.hxx"
25 #include "DataPort.hxx"
26 #include "TypeCode.hxx"
27 #include "InputPort.hxx"
28 #include "OutputPort.hxx"
29 #include "PresetNode.hxx"
30 #include "DataNode.hxx"
31 #include "InlineNode.hxx"
32
33 #include <QIcon>
34
35 //#define _DEVDEBUG_
36 #include "YacsTrace.hxx"
37
38 using namespace std;
39 using namespace YACS::ENGINE;
40 using namespace YACS::HMI;
41
42 /*! column 1: YLabel = name, set in SchemaItem,
43  *  column 2: YType  = data type, never editable,
44  *  column 3: YValue = value
45  */
46 SchemaOutPortItem::SchemaOutPortItem(SchemaItem *parent, QString label, Subject* subject)
47   : SchemaItem::SchemaItem(parent, label, subject)
48 {
49   SubjectDataPort *subPort = dynamic_cast<SubjectDataPort*>(subject);
50   if (subPort)
51     {
52       DataPort *dport = subPort->getPort();
53       TypeOfElem typort = ProcInvoc::getTypeOfPort(dport);
54 //       _itemData.replace(YType, dport->edGetType()->getKindRepr());
55       _itemData.replace(YType, dport->edGetType()->name());
56       _itemForeground.replace(YType, QColor("black"));
57       OutputPort * outport = 0;
58
59       switch (typort)
60         {
61         case YACS::HMI::OUTPUTPORT:
62           _itemDeco.replace(YLabel, QIcon("icons:out_port.png"));
63           outport = dynamic_cast<OutputPort*>(dport);
64           _itemData.replace(YValue, outport->getAsString().c_str());
65           break;
66         case YACS::HMI::OUTPUTDATASTREAMPORT:
67           _itemDeco.replace(YLabel, QIcon("icons:out_port.png"));
68           _itemData.replace(YValue, "stream");
69           _itemForeground.replace(YValue, QColor("grey"));
70           //_itemDeco.replace(YValue, QColor("grey"));
71           break;
72         }
73     }
74 }
75
76 void SchemaOutPortItem::update(GuiEvent event, int type, Subject* son)
77 {
78   DEBTRACE("SchemaOutPortItem::update");
79   SchemaItem::update(event, type, son);
80   QModelIndex index = QModelIndex();
81   SchemaModel *model = QtGuiContext::getQtCurrent()->getSchemaModel();
82   switch (event)
83     {
84     case SETVALUE:
85       {
86         SubjectOutputPort *sop = dynamic_cast<SubjectOutputPort*>(son);
87         if (sop)
88           {
89             DataFlowPort *port = dynamic_cast<DataFlowPort*>(sop->getPort());
90             DEBTRACE(port->getAsString());
91             _itemData.replace(YValue, port->getAsString().c_str());
92             _itemForeground.replace(YValue, QColor("green"));
93             model->setData(modelIndex(YValue), 0); // --- to emit dataChanged signal
94           }
95       }
96       break;
97     case UPDATEPROGRESS:
98       {
99         SubjectOutputPort *sip = dynamic_cast<SubjectOutputPort*>(son);
100         if (sip)
101           {
102             _itemData.replace(YValue, sip->getExecValue().c_str());
103             _itemForeground.replace(YValue, QColor("darkMagenta"));
104             model->setData(modelIndex(YValue), 0); // --- to emit dataChanged signal
105           }
106       }
107       break;      
108     }
109 }
110
111 Qt::ItemFlags SchemaOutPortItem::flags(const QModelIndex &index)
112 {
113   //DEBTRACE("SchemaOutPortItem::flags");
114   Qt::ItemFlags pflag = Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDropEnabled;
115   if (! QtGuiContext::getQtCurrent()->isEdition())
116     return pflag;
117
118   Qt::ItemFlags flagEdit = 0;
119   int column = index.column();
120   switch (column)
121     {
122     case 0:
123       {
124         SubjectDataPort *sdp = dynamic_cast<SubjectDataPort*>(_subject);
125         Node *parent = sdp->getPort()->getNode();
126         if (parent)
127           if (dynamic_cast<DataNode*>(parent) || dynamic_cast<InlineNode*>(parent))
128             flagEdit = Qt::ItemIsEditable; // --- port name editable
129       }
130       break;
131     case 2:
132       SubjectDataPort *sdp = dynamic_cast<SubjectDataPort*>(_subject);
133       Node *node = sdp->getPort()->getNode();
134       PresetNode *pnode = dynamic_cast<PresetNode*>(node);
135       if (! pnode) break;
136       flagEdit = Qt::ItemIsEditable; // --- port value editable for preset node
137       break;   
138     }
139   return pflag | flagEdit;
140 }
141
142 void SchemaOutPortItem::popupMenu(QWidget *caller, const QPoint &globalPos)
143 {
144   OutPortMenu m;
145   m.popupMenu(caller, globalPos);
146 }
147
148 QString SchemaOutPortItem::getMimeFormat()
149 {
150   return "yacs/subjectOutPort";
151 }