Version: 9.16.0
SchemaOutPortItem.cxx
Go to the documentation of this file.
1// Copyright (C) 2006-2026 CEA, EDF
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
39using namespace std;
40using namespace YACS::ENGINE;
41using namespace YACS::HMI;
42
47SchemaOutPortItem::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();
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
77void 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
123Qt::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
157void SchemaOutPortItem::popupMenu(QWidget *caller, const QPoint &globalPos)
158{
160 m.popupMenu(caller, globalPos);
161}
162
164{
165 return "yacs/subjectOutPort";
166}
#define DEBTRACE(msg)
Definition: YacsTrace.hxx:31
Class for data parameters specification.
Definition: DataNode.hxx:38
TypeCode * edGetType() const
Definition: DataPort.hxx:53
virtual std::string getAsString()
returns port value as a string that can be used in a GUI for example
Definition: DataPort.cxx:84
Class for calculation node (script) inlined (and executed) in the schema.
Definition: InlineNode.hxx:44
Base class for all nodes.
Definition: Node.hxx:70
Node * getNode() const
Definition: Port.hxx:46
virtual const char * name() const
Definition: TypeCode.cxx:72
static TypeOfElem getTypeOfPort(YACS::ENGINE::DataPort *port)
YACS::HMI::SchemaModel * getSchemaModel()
static QtGuiContext * getQtCurrent()
QModelIndex modelIndex(int column=0)
Definition: SchemaItem.cxx:253
QList< QVariant > _itemDeco
Definition: SchemaItem.hxx:78
virtual SchemaItem * parent()
Definition: SchemaItem.cxx:163
virtual void update(GuiEvent event, int type, Subject *son)
Definition: SchemaItem.cxx:174
QList< QVariant > _itemForeground
Definition: SchemaItem.hxx:79
QList< QVariant > _itemData
Definition: SchemaItem.hxx:77
virtual bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole)
virtual void update(GuiEvent event, int type, Subject *son)
virtual Qt::ItemFlags flags(const QModelIndex &index)
virtual void popupMenu(QWidget *caller, const QPoint &globalPos)
virtual YACS::ENGINE::DataPort * getPort()
@ OUTPUTDATASTREAMPORT