1 // Copyright (C) 2006-2022 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, or (at your option) any later version.
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 "SchemaOutPortItem.hxx"
21 #include "ItemMimeData.hxx"
22 #include "QtGuiContext.hxx"
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"
37 #include "YacsTrace.hxx"
40 using namespace YACS::ENGINE;
41 using namespace YACS::HMI;
43 /*! column 1: YLabel = name, set in SchemaItem,
44 * column 2: YType = data type, never editable,
45 * column 3: YValue = value
47 SchemaOutPortItem::SchemaOutPortItem(SchemaItem *parent, QString label, Subject* subject)
48 : SchemaItem(parent, label, subject)
50 SubjectDataPort *subPort = dynamic_cast<SubjectDataPort*>(subject);
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;
62 case YACS::HMI::OUTPUTPORT:
63 _itemDeco.replace(YLabel, QIcon("icons:out_port.png"));
64 outport = dynamic_cast<OutputPort*>(dport);
65 _itemData.replace(YValue, outport->getAsString().c_str());
67 case YACS::HMI::OUTPUTDATASTREAMPORT:
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"));
77 void SchemaOutPortItem::update(GuiEvent event, int type, Subject* son)
79 DEBTRACE("SchemaOutPortItem::update");
80 SchemaItem::update(event, type, son);
81 QModelIndex index = QModelIndex();
82 SchemaModel *model = QtGuiContext::getQtCurrent()->getSchemaModel();
87 SubjectOutputPort *sop = dynamic_cast<SubjectOutputPort*>(son);
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
100 SubjectOutputPort *sop = dynamic_cast<SubjectOutputPort*>(son);
103 DataFlowPort *port = dynamic_cast<DataFlowPort*>(sop->getPort());
104 _itemData.replace(YType, port->edGetType()->name());
105 _itemForeground.replace(YType, QColor("black"));
111 SubjectOutputPort *sip = dynamic_cast<SubjectOutputPort*>(son);
114 _itemData.replace(YValue, sip->getExecValue().c_str());
115 _itemForeground.replace(YValue, QColor("darkMagenta"));
116 model->setData(modelIndex(YValue), 0); // --- to emit dataChanged signal
123 Qt::ItemFlags SchemaOutPortItem::flags(const QModelIndex &index)
125 //DEBTRACE("SchemaOutPortItem::flags");
126 Qt::ItemFlags pflag = Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDropEnabled;
127 if (QtGuiContext::getQtCurrent()->isEdition())
128 pflag = pflag | Qt::ItemIsDragEnabled;
132 Qt::ItemFlags flagEdit = 0;
133 int column = index.column();
138 SubjectDataPort *sdp = dynamic_cast<SubjectDataPort*>(_subject);
139 Node *parent = sdp->getPort()->getNode();
141 if (dynamic_cast<DataNode*>(parent) || dynamic_cast<InlineNode*>(parent))
142 flagEdit = Qt::ItemIsEditable; // --- port name editable
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);
151 flagEdit = Qt::ItemIsEditable; // --- port value editable for preset node
154 return pflag | flagEdit;
157 void SchemaOutPortItem::popupMenu(QWidget *caller, const QPoint &globalPos)
160 m.popupMenu(caller, globalPos);
163 QString SchemaOutPortItem::getMimeFormat()
165 return "yacs/subjectOutPort";