1 // Copyright (C) 2006-2012 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "SchemaInPortItem.hxx"
21 #include "ItemMimeData.hxx"
22 #include "QtGuiContext.hxx"
24 #include "Message.hxx"
26 #include "commandsProc.hxx"
27 #include "DataPort.hxx"
28 #include "TypeCode.hxx"
29 #include "InputPort.hxx"
30 #include "OutputPort.hxx"
31 #include "DataNode.hxx"
32 #include "InlineNode.hxx"
37 #include "YacsTrace.hxx"
40 using namespace YACS::ENGINE;
41 using namespace YACS::HMI;
43 /*! column 1 = name, set in SchemaItem,
44 * column 2 = data type, never editable,
47 SchemaInPortItem::SchemaInPortItem(SchemaItem *parent, QString label, Subject* subject)
48 : SchemaItem(parent, label, subject)
50 SubjectDataPort *subPort = dynamic_cast<SubjectDataPort*>(subject);
51 _isDataStream = false;
54 DataPort *dport = subPort->getPort();
55 TypeOfElem typort = ProcInvoc::getTypeOfPort(dport);
56 TypeOfElem typnode = ProcInvoc::getTypeOfNode(dport->getNode());
57 // _itemData.replace(YType, dport->edGetType()->getKindRepr());
58 _itemData.replace(YType, dport->edGetType()->name());
59 _itemForeground.replace(YType, QColor("black"));
60 InputPort *inport = 0;
62 if(typnode==YACS::HMI::STUDYOUTNODE)
64 //It's a study out node
65 if(typort==YACS::HMI::INPUTPORT)
67 _itemDeco.replace(YLabel, QIcon("icons:in_port.png"));
68 inport = dynamic_cast<InputPort*>(dport);
69 std::string val=inport->getAsString();
72 _itemData.replace(YValue, val.c_str());
73 if (inport->edGetNumberOfLinks())
74 _itemForeground.replace(YValue, QColor("green"));
76 _itemForeground.replace(YValue, QColor("red"));
80 _itemData.replace(YValue, "not initialized");
81 _itemForeground.replace(YValue, QColor("red"));
89 case YACS::HMI::INPUTPORT:
90 _isDataStream = false;
91 _itemDeco.replace(YLabel, QIcon("icons:in_port.png"));
92 inport = dynamic_cast<InputPort*>(dport);
93 if (inport->edIsManuallyInitialized())
95 _itemData.replace(YValue, inport->getAsString().c_str());
96 _itemForeground.replace(YValue, QColor("green"));
98 else if (inport->edGetNumberOfLinks())
100 _itemData.replace(YValue, "linked");
101 _itemForeground.replace(YValue, QColor("blue"));
105 _itemData.replace(YValue, "not initialized");
106 _itemForeground.replace(YValue, QColor("red"));
109 case YACS::HMI::INPUTDATASTREAMPORT:
110 _isDataStream = true;
111 _itemDeco.replace(YLabel, QIcon("icons:in_port.png"));
112 _itemData.replace(YValue, "stream");
113 _itemForeground.replace(YValue, QColor("grey"));
119 void SchemaInPortItem::update(GuiEvent event, int type, Subject* son)
121 DEBTRACE("SchemaInPortItem::update");
122 SchemaItem::update(event, type, son);
123 QModelIndex index = QModelIndex();
124 SchemaModel *model = QtGuiContext::getQtCurrent()->getSchemaModel();
129 SubjectInputPort *sip = dynamic_cast<SubjectInputPort*>(son);
132 InputPort* port = dynamic_cast<InputPort*>(sip->getPort());
133 TypeOfElem typnode = ProcInvoc::getTypeOfNode(port->getNode());
134 DEBTRACE(port->getAsString());
135 if(typnode==YACS::HMI::STUDYOUTNODE)
137 if(port->getAsString().empty())
139 _itemData.replace(YValue, "not initialized");
140 if (port->edGetNumberOfLinks())
141 _itemForeground.replace(YValue, QColor("blue"));
143 _itemForeground.replace(YValue, QColor("red"));
147 _itemData.replace(YValue, port->getAsString().c_str());
148 if (port->edGetNumberOfLinks())
149 _itemForeground.replace(YValue, QColor("green"));
151 _itemForeground.replace(YValue, QColor("red"));
156 _itemData.replace(YValue, port->getAsString().c_str());
157 _itemForeground.replace(YValue, QColor("green"));
159 model->setData(modelIndex(YValue), 0); // --- to emit dataChanged signal
165 SubjectInputPort *sip = dynamic_cast<SubjectInputPort*>(_subject);
168 InputPort* port = dynamic_cast<InputPort*>(sip->getPort());
169 TypeOfElem typnode = ProcInvoc::getTypeOfNode(port->getNode());
170 TypeOfElem typort = ProcInvoc::getTypeOfPort(port);
171 _itemData.replace(YType, port->edGetType()->name());
172 _itemForeground.replace(YType, QColor("black"));
173 if(typnode==YACS::HMI::STUDYOUTNODE)
175 if(port->getAsString().empty())
177 _itemData.replace(YValue, "not initialized");
178 if (port->edGetNumberOfLinks())
179 _itemForeground.replace(YValue, QColor("blue"));
181 _itemForeground.replace(YValue, QColor("red"));
185 _itemData.replace(YValue, port->getAsString().c_str());
186 if (port->edGetNumberOfLinks())
187 _itemForeground.replace(YValue, QColor("green"));
189 _itemForeground.replace(YValue, QColor("red"));
194 if (port->edGetNumberOfLinks())
196 _itemData.replace(YValue, "linked");
197 _itemForeground.replace(YValue, QColor("blue"));
199 else if (port->edIsManuallyInitialized())
201 _itemData.replace(YValue, port->getAsString().c_str());
202 _itemForeground.replace(YValue, QColor("green"));
206 _itemData.replace(YValue, "not initialized");
207 _itemForeground.replace(YValue, QColor("red"));
210 model->setData(modelIndex(YValue), 0); // --- to emit dataChanged signal
216 SubjectInputPort *sip = dynamic_cast<SubjectInputPort*>(son);
219 _itemData.replace(YValue, sip->getExecValue().c_str());
220 _itemForeground.replace(YValue, QColor("darkCyan"));
221 model->setData(modelIndex(YValue), 0); // --- to emit dataChanged signal
228 Qt::ItemFlags SchemaInPortItem::flags(const QModelIndex &index)
230 //DEBTRACE("SchemaInPortItem::flags");
231 Qt::ItemFlags pflag = Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDropEnabled;
233 Qt::ItemFlags flagEdit = 0;
234 int column = index.column();
239 SubjectDataPort *sdp = dynamic_cast<SubjectDataPort*>(_subject);
240 Node *parent = sdp->getPort()->getNode();
242 if ( (dynamic_cast<DataNode*>(parent) || dynamic_cast<InlineNode*>(parent)) &&
243 QtGuiContext::getQtCurrent()->isEdition() )
244 flagEdit = Qt::ItemIsEditable; // --- port name editable
249 flagEdit = Qt::ItemIsEditable; // --- port value editable
251 return pflag | flagEdit;
254 bool SchemaInPortItem::dropMimeData(const QMimeData* data, Qt::DropAction action)
256 DEBTRACE("SchemaInPortItem::dropMimeData");
257 if (!data) return false;
258 const ItemMimeData* myData = dynamic_cast<const ItemMimeData*>(data);
259 if (!myData) return false;
260 if(!myData->hasFormat("yacs/subjectOutPort")) return false;
261 SubjectDataPort *to = dynamic_cast<SubjectDataPort*>(getSubject());
262 if (!to) return false;
263 InPort *toport = dynamic_cast<InPort*>(to->getPort());
264 if (!toport) return false;
267 TypeOfElem typort = ProcInvoc::getTypeOfPort(toport);
270 case YACS::HMI::INPUTPORT:
271 case YACS::HMI::INPUTDATASTREAMPORT:
274 Subject *sub = myData->getSubject();
276 SubjectDataPort* from = dynamic_cast<SubjectDataPort*>(sub);
278 if (!SubjectDataPort::tryCreateLink(from, to,myData->getControl()))
288 void SchemaInPortItem::popupMenu(QWidget *caller, const QPoint &globalPos)
291 m.popupMenu(caller, globalPos);
294 QVariant SchemaInPortItem::editionWhatsThis(int column) const
298 answer = "Edition, DataStream input port ";
300 answer = "Edition, DataFlow input port ";
305 answer += _itemData.value(column).toString();
306 answer += "\nInput port is edited in the input panel of the node.\n" \
307 "Select the node to get access to it's input panel.";
311 answer += _itemData.value(column).toString();
312 answer += "\nInput port is edited in the input panel of the node.\n" \
313 "Select the node to get access to it's input panel.\n" \
314 "Type is not modifiable, you must delete and recreate the port. Existing links will be lost.";
318 answer += _itemData.value(column).toString();
319 answer += "\nInput port is edited in the input panel of the node.\n" \
320 "Select the node to get access to it's input panel.\n";
322 answer += "DataStream ports have no editable value, they must be linked to an output DataStream port.";
325 answer += "DataFlow ports must be either manually initialized or linked to an output DataFlow port. ";
326 answer += "If the port is manually initialized and linked, the value from the link will prevail ";
327 answer += "if it is available when the node is executed.";