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