Version: 9.16.0
EditionElementaryNode.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
21#include "ValueDelegate.hxx"
22#include "QtGuiContext.hxx"
23
24#include "Proc.hxx"
25#include "Port.hxx"
26#include "DataPort.hxx"
27#include "TypeCode.hxx"
28
29#include "TablePortsEdition.hxx"
30
31//#define _DEVDEBUG_
32#include "YacsTrace.hxx"
33
34#include <cassert>
35
36using namespace std;
37
38using namespace YACS;
39using namespace YACS::HMI;
40
41EditionElementaryNode::EditionElementaryNode(Subject* subject,
42 QWidget* parent,
43 const char* name)
44 : EditionNode(subject, parent, name)
45{
46 _subElemNode = 0;
47 _twPorts = 0;
48 _tvInPorts = 0;
49 _tvOutPorts = 0;
51
54 _valueDelegate = new ValueDelegate(parent);
55
56 connect(_valueDelegate, SIGNAL(commitData(QWidget*)),
57 this, SLOT(onCommitData(QWidget*)));
58
59}
60
62{
63}
64
66{
68}
69
71{
73}
74
76{
77 DEBTRACE("EditionElementaryNode::onPortIndexChanged " << index);
79}
80
82{
83 //DEBTRACE("EditionElementaryNode::synchronize");
86 if (schemaItem)
87 {
88 QModelIndex parentIndex = schemaItem->modelIndex();
89 int numRows = model->rowCount(parentIndex);
90 if (_tvInPorts)
91 {
92 _tvInPorts->cb_insert->setCurrentIndex(0);
94 _tvInPorts->tv_ports->setRootIndex(parentIndex);
95 for (int row = 0; row < numRows; ++row)
96 {
97 QModelIndex index = model->index(row, 0, parentIndex);
98 SchemaItem *childItem = static_cast<SchemaItem*>(index.internalPointer());
99 bool hidden = true;
100 if (Subject *sub = childItem->getSubject())
101 if (dynamic_cast<SubjectInputPort*>(sub)
102 || dynamic_cast<SubjectInputDataStreamPort*>(sub))
103 hidden = false;
104 _tvInPorts->tv_ports->setRowHidden(row, hidden);
105 }
107 }
108 if (_tvOutPorts)
109 {
110 _tvOutPorts->cb_insert->setCurrentIndex(0);
112 _tvOutPorts->tv_ports->setRootIndex(parentIndex);
113 for (int row = 0; row < numRows; ++row)
114 {
115 QModelIndex index = model->index(row, 0, parentIndex);
116 SchemaItem *childItem = static_cast<SchemaItem*>(index.internalPointer());
117 bool hidden = true;
118 if (Subject *sub = childItem->getSubject())
119 if (dynamic_cast<SubjectOutputPort*>(sub)
120 || dynamic_cast<SubjectOutputDataStreamPort*>(sub))
121 hidden = false;
122 _tvOutPorts->tv_ports->setRowHidden(row, hidden);
123 }
125 }
126 }
127}
128
130{
131 if (_tvInPorts) _tvInPorts->setEditablePorts(isEditable);
132 if (_tvOutPorts) _tvOutPorts->setEditablePorts(isEditable);
133}
134
136{
137 return true;
138}
139
141{
142 return true;
143}
144
146{
147 _twPorts = new QTabWidget(this);
148 layout->addWidget(_twPorts);
150
151 QModelIndex schemIndex = model->index(0, 0, QModelIndex());
152 QModelIndex TypesDirIndex = model->index(0, 0, schemIndex);
153
154 if (hasInputPorts())
155 {
157 _tvInPorts->tv_ports->setModel(model);
158 _tvInPorts->tv_ports->setItemDelegateForColumn(YLabel, _valueDelegate); // --- port label
159 _tvInPorts->tv_ports->setItemDelegateForColumn(YValue, _valueDelegate); // --- port value
160 _tvInPorts->cb_insert->setModel(model);
161 _tvInPorts->cb_insert->setRootModelIndex(TypesDirIndex);
162 _twPorts->addTab(_tvInPorts, "input Ports");
163 }
164
165 if (hasOutputPorts())
166 {
168 _tvOutPorts->tv_ports->setModel(model);
169 _tvOutPorts->tv_ports->setItemDelegateForColumn(YLabel, _valueDelegate); // --- port label
170 _tvOutPorts->tv_ports->setItemDelegateForColumn(YValue, _valueDelegate); // --- port value
171 _tvOutPorts->cb_insert->setModel(model);
172 _tvOutPorts->cb_insert->setRootModelIndex(TypesDirIndex);
173 _twPorts->addTab(_tvOutPorts, "output Ports");
174 }
175
176 connect(_twPorts, SIGNAL(currentChanged(int)),
177 this, SLOT(onPortIndexChanged(int)));
178
179 setEditablePorts(false);
180}
181
190{
191 DEBTRACE("EditionElementaryNode::onCommitData " << editor);
192 GenericEditor* gedit = dynamic_cast<GenericEditor*>(editor);
193 YASSERT(gedit);
194 QString val = gedit->GetStrValue();
195 DEBTRACE(val.toStdString());
196 Subject *sub = gedit->getSubject();
197 YASSERT(sub);
198 SubjectDataPort *sdp = dynamic_cast<SubjectDataPort*>(sub);
199 YASSERT(sdp);
200 string strval = val.toStdString();
201 bool isOk = false;
202
203 if (gedit->getColumnInSubject() == YValue)
204 {
205 DEBTRACE(strval);
206 isOk = sdp->setValue(strval);
207
209 if (executor) executor->setInPortValue(sdp->getPort(), strval);
210 }
211
212 else // --- YLabel
213 {
214 isOk = sdp->setName(strval);
215 }
216
217 if (_valueDelegate)
218 _valueDelegate->setResultEditing(editor, isOk);
219 }
#define YASSERT(val)
YASSERT macro is always defined, used like assert, but throw a YACS::Exception instead of abort.
Definition: YacsTrace.hxx:59
#define DEBTRACE(msg)
Definition: YacsTrace.hxx:31
virtual void createTablePorts(QLayout *layout)
virtual void onCommitData(QWidget *editor)
virtual void onPortIndexChanged(int index)
virtual void setEditablePorts(bool isEditable)
virtual int getColumnInSubject()
virtual Subject * getSubject()
virtual QString GetStrValue()
void setInPortValue(YACS::ENGINE::DataPort *port, std::string value)
virtual void onApply()
virtual void onCancel()
YACS::HMI::SchemaModel * getSchemaModel()
std::map< YACS::HMI::Subject *, YACS::HMI::SchemaItem * > _mapOfSchemaItem
static QtGuiContext * getQtCurrent()
YACS::HMI::GuiExecutor * getGuiExecutor()
virtual Subject * getSubject()
Definition: SchemaItem.cxx:169
QModelIndex modelIndex(int column=0)
Definition: SchemaItem.cxx:253
virtual QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
Definition: SchemaModel.cxx:60
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
Definition: SchemaModel.cxx:92
virtual bool setName(std::string name)
virtual bool setValue(std::string value)
virtual YACS::ENGINE::DataPort * getPort()
void setNode(SubjectElementaryNode *node)
virtual void setEditablePorts(bool isEditable)
virtual void setResultEditing(QWidget *editor, bool isOk)