Version: 9.16.0
SceneHeaderNodeItem.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
22#include "SceneProcItem.hxx"
25#include "SceneInPortItem.hxx"
26#include "SceneOutPortItem.hxx"
27#include "Scene.hxx"
28
29#include "QtGuiContext.hxx"
30#include "GuiEditor.hxx"
31#include "Resource.hxx"
32#include "Menus.hxx"
33#include <QGraphicsSceneHoverEvent>
34#include <QGraphicsSceneMouseEvent>
35#include <QPointF>
36
37#include <cassert>
38
39//#define _DEVDEBUG_
40#include "YacsTrace.hxx"
41
42using namespace std;
43using namespace YACS::ENGINE;
44using namespace YACS::HMI;
45
46SceneHeaderNodeItem::SceneHeaderNodeItem(QGraphicsScene *scene, SceneItem *parent,
47 QString label)
48 : SceneHeaderItem(scene, parent, label)
49{
50 _fatherNode= dynamic_cast<SceneNodeItem*>(parent);
53 _maxPorts = 0;
54
55 _header = 0;
56 _controlIn = 0;
57 _controlOut = 0;
58 _label = "H_" + _label;
59 _hasHeader = true;
60
61 _controlIn = new SceneCtrlInPortItem(_scene, this, "in");
63
64 _header = new SceneHeaderItem(_scene, this, "header_"+_label);
65 _header->setText(label);
67
68 _controlOut = new SceneCtrlOutPortItem(_scene, this, "out");
70
71 if (QtGuiContext::getQtCurrent()->isEdition())
73 else
77 _stateDef = "";
78 _isProc = dynamic_cast<SceneProcItem*>(_parent);
79 _isValid = true;
80 _isEdited = false;
81}
82
84{
85}
86
87void SceneHeaderNodeItem::paint(QPainter *painter,
88 const QStyleOptionGraphicsItem *option,
89 QWidget *widget)
90{
91 //DEBTRACE("SceneHeaderNodeItem::paint");
92 painter->save();
93
94 int x = Resource::Border_Margin + 1;
100 QPen pen(getPenColor());
101 pen.setWidth(Resource::Line_Width);
102 painter->setPen(pen);
103 painter->drawLine(x, y, w, y);
104
109 pen.setWidth(Resource::Thickness);
110 painter->setPen(pen);
111
112 bool expanded = (_fatherNode && _fatherNode->isExpanded());
113 QColor baseColor = getBrushColor();
114 if (expanded)
115 painter->setBrush(baseColor);
116 else
117 {
118 int h, s, v, a, h2;
119 baseColor.getHsv(&h, &s, &v, &a);
120 DEBTRACE("h="<<h<<" s="<<s<<" v="<<v);
121 h2 = h+60;
122 if (h>359) h2 = h2-359;
123 QLinearGradient gradient;
124 gradient.setCoordinateMode(QGradient::ObjectBoundingMode);
125 gradient.setColorAt(0, baseColor.darker(200));
126 //gradient.setColorAt(1, baseColor.lighter(150));
127 //gradient.setColorAt(0, QColor::fromHsv(h-60, s, v, a));
128 gradient.setColorAt(1, QColor::fromHsv(h2, s, v, a));
129 QBrush brush(gradient);
130 painter->setBrush(brush);
131 }
132 painter->drawRoundedRect(QRect(x, y, w, h), Resource::Radius, Resource::Radius);
133
134 painter->restore();
135}
136
138{
139 if (_header) _header->setText(label);
140}
141
143{
144 qreal res = 0;
145 if (_hasHeader) {
149 }
150 return res;
151}
152
154{
155}
156
158{
159 DEBTRACE("SceneHeaderNodeItem::autoPosNewPort");
160 SceneInPortItem* inPortItem = dynamic_cast<SceneInPortItem*>(item);
161
162 int nbPorts;
163 qreal xLeft;
164 if (inPortItem) {
166 nbPorts = _inPorts.size();
167 _inPorts.push_back(inPortItem);
168 } else {
171 } else {
173 };
174 nbPorts = _outPorts.size();
175 _outPorts.push_back(dynamic_cast<SceneOutPortItem*>(item));
176 };
177 qreal yTop = Resource::Header_Height;
181 yTop += nbPorts * deltaY;
182 if (nbPorts >=_maxPorts) {
183 _maxPorts = nbPorts+1;
184 };
185 //DEBTRACE("left, top " << xLeft << " " << yTop);
186 QPointF topLeft(xLeft, yTop);
187 item->setTopLeft(topLeft);
188 adaptComposedNode(dynamic_cast<SceneItem*>(item), deltaY);
189}
190
192{
193 DEBTRACE("SceneHeaderNodeItem::reorganizePorts() " << ss << " " << _label.toStdString());
194
195 qreal yTop;
196 qreal href = Resource::Header_Height;
199 bool isShown = (ss != shrinkHidden);
200 if (!isShown) href = Resource::Corner_Margin;
201
202 std::list<SceneInPortItem*>::iterator iti = _inPorts.begin();
203 int nbPorts = 0;
204 for (; iti != _inPorts.end(); ++iti)
205 {
206 yTop = href + nbPorts * (Resource::DataPort_Height + Resource::Space_Margin);
207 QPointF topLeft(Resource::Corner_Margin, yTop);
208 (*iti)->setTopLeft(topLeft);
209 if (isShown) nbPorts++; // otherwise (shrink from ancestor) put all ports at the same position
210 }
211
212 std::list<SceneOutPortItem*>::iterator ito = _outPorts.begin();
213 nbPorts = 0;
214 qreal xLeft;
215 if (ss == expandShown) {
217 } else {
219 };
220 for (; ito != _outPorts.end(); ++ito)
221 {
222 yTop = href + nbPorts * (Resource::DataPort_Height + Resource::Space_Margin);
223 QPointF topLeft(xLeft, yTop);
224 (*ito)->setTopLeft(topLeft);
225 if (isShown) nbPorts++; // otherwise (shrink from ancestor) put all ports at the same position
226 }
227 //updateLinks();
228}
229
230void SceneHeaderNodeItem::popupMenu(QWidget *caller, const QPoint &globalPos)
231{
232 if (_parent) _parent->popupMenu(caller, globalPos);
233// HeaderNodeMenu m;
234// m.popupMenu(caller, globalPos);
235}
236
238{
239 DEBTRACE("SceneHeaderNodeItem::adjustGeometry() " << _label.toStdString());
240 prepareGeometryChange();
244 update();
245}
246
248{
251 if (_controlOut)
252 {
254 if ((ss == expandShown) && (_parent->getWidth() > (x + Resource::Corner_Margin)))
257 };
258 reorganizePorts(ss);
259}
260
262{
265 int nbPorts = _inPorts.size();
266 if (_outPorts.size() > nbPorts) nbPorts = _outPorts.size();
267 if (nbPorts) height += nbPorts*(Resource::DataPort_Height + Resource::Space_Margin);
270 //DEBTRACE(nbPorts << " " << width << " " << height);
271 return QRectF(x(), y(), width, height);
272}
273
275{
276 DEBTRACE("SceneHeaderNodeItem::adaptComposedNode " << deltaY);
277 QPointF oldPos(x(),y() - deltaY);
278 if (_parent)
279 {
280 if (SceneComposedNodeItem *bloc = dynamic_cast<SceneComposedNodeItem*>(_parent))
281 bloc->collisionResolv(port, oldPos);
282 //_parent->checkGeometryChange();
283 }
284}
285
287{
288 DEBTRACE("SceneHeaderNodeItem::setEdited " << isEdited);
289 if (isEdited)
291 else
292 {
293 if (QtGuiContext::getQtCurrent()->isEdition())
295 else
297 }
298 if (isEdited != _isEdited)
299 _parent->update();
300 _isEdited = isEdited;
301}
302
304{
305 DEBTRACE("SceneHeaderNodeItem::setValid " << isValid);
306 if (_isValid != isValid)
307 {
308 _isValid = isValid;
309 _parent->update();
310 }
311}
312
314{
315 DEBTRACE("SceneHeaderNodeItem::setExecState " << execState);
316 _execState = execState;
317 if (!_isValid) return;
318 QColor oldsc = _sc;
319 if (_isProc)
320 switch (_execState)
321 {
322 case YACS::NOTYETINITIALIZED: _sc = Resource::NOTYETINITIALIZED; _stateDef = "Not Yet Initialized"; break;
323 case YACS::INITIALISED: _sc = Resource::INITIALISED ; _stateDef = "Initialized" ; break;
324 case YACS::RUNNING: _sc = Resource::RUNNING ; _stateDef = "Running" ; break;
325 case YACS::WAITINGTASKS: _sc = Resource::WAITINGTASKS ; _stateDef = "Waiting Tasks" ; break;
326 case YACS::PAUSED: _sc = Resource::PAUSED ; _stateDef = "Paused" ; break;
327 case YACS::FINISHED: _sc = Resource::FINISHED ; _stateDef = "Finished" ; break;
328 case YACS::STOPPED: _sc = Resource::STOPPED ; _stateDef = "Stopped" ; break;
329 default: _sc = Resource::UNKNOWN ; _stateDef = "Unknown Status" ;
330 }
331 else
332 switch (_execState)
333 {
334 case YACS::UNDEFINED: _sc = Resource::UNDEFINED ; _stateDef = "UNDEFINED" ; break;
335 case YACS::INVALID: _sc = Resource::INVALID ; _stateDef = "INVALID" ; break;
336 case YACS::READY: _sc = Resource::READY ; _stateDef = "READY" ; break;
337 case YACS::TOLOAD: _sc = Resource::TOLOAD ; _stateDef = "TOLOAD" ; break;
338 case YACS::LOADED: _sc = Resource::LOADED ; _stateDef = "LOADED" ; break;
339 case YACS::TOACTIVATE: _sc = Resource::TOACTIVATE ; _stateDef = "TOACTIVATE" ; break;
340 case YACS::ACTIVATED: _sc = Resource::ACTIVATED ; _stateDef = "ACTIVATED" ; break;
341 case YACS::DESACTIVATED: _sc = Resource::DESACTIVATED ; _stateDef = "DESACTIVATED" ; break;
342 case YACS::DONE: _sc = Resource::DONE ; _stateDef = "DONE" ; break;
343 case YACS::SUSPENDED: _sc = Resource::SUSPENDED ; _stateDef = "SUSPENDED" ; break;
344 case YACS::LOADFAILED: _sc = Resource::LOADFAILED ; _stateDef = "LOADFAILED" ; break;
345 case YACS::EXECFAILED: _sc = Resource::EXECFAILED ; _stateDef = "EXECFAILED" ; break;
346 case YACS::PAUSE: _sc = Resource::PAUSE ; _stateDef = "PAUSE" ; break;
347 case YACS::INTERNALERR: _sc = Resource::INTERNALERR ; _stateDef = "INTERNALERR" ; break;
348 case YACS::DISABLED: _sc = Resource::DISABLED ; _stateDef = "DISABLED" ; break;
349 case YACS::FAILED: _sc = Resource::FAILED ; _stateDef = "FAILED" ; break;
350 case YACS::ERROR: _sc = Resource::ERROR ; _stateDef = "ERROR" ; break;
351 default: _sc = Resource::DEFAULT ; _stateDef = "---" ;
352 }
353 DEBTRACE(" - stateDef = " << _stateDef.toStdString());
354 if(oldsc != _sc)
355 _parent->update();
356}
357
359{
360 return _controlIn;
361}
362
364{
365 return _controlOut;
366}
367
368
369
370void SceneHeaderNodeItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
371{
372 event->ignore();
373}
374
375void SceneHeaderNodeItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
376{
377 event->ignore();
378}
379
381{
382 if (_isValid)
383 return _sc;
384 else
386}
#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 setTopLeft(QPointF topLeft)=0
YACS::HMI::Scene * _scene
Definition: SceneItem.hxx:98
static QtGuiContext * getQtCurrent()
static int DataPort_Width
Definition: Resource.hxx:305
static int Line_Width
Definition: Resource.hxx:314
static QColor DESACTIVATED
Definition: Resource.hxx:243
static int Corner_Margin
Definition: Resource.hxx:318
static int CtrlPort_Width
Definition: Resource.hxx:303
static QColor DONE
Definition: Resource.hxx:244
static QColor PAUSED
Definition: Resource.hxx:231
static int Border_Margin
Definition: Resource.hxx:310
static QColor ACTIVATED
Definition: Resource.hxx:242
static QColor WAITINGTASKS
Definition: Resource.hxx:230
static QColor NOTYETINITIALIZED
Definition: Resource.hxx:227
static QColor DISABLED
Definition: Resource.hxx:250
static QColor FAILED
Definition: Resource.hxx:251
static QColor INVALID
Definition: Resource.hxx:237
static int CtrlPort_Height
Definition: Resource.hxx:304
static QColor EXECFAILED
Definition: Resource.hxx:247
static QColor FINISHED
Definition: Resource.hxx:232
static QColor UNDEFINED
Definition: Resource.hxx:236
static QColor INTERNALERR
Definition: Resource.hxx:249
static int DataPort_Height
Definition: Resource.hxx:306
static QColor LOADED
Definition: Resource.hxx:240
static QColor RUNNING
Definition: Resource.hxx:229
static int Space_Margin
Definition: Resource.hxx:311
static QColor READY
Definition: Resource.hxx:238
static int Thickness
Definition: Resource.hxx:308
static QColor DEFAULT
Definition: Resource.hxx:253
static int Header_Height
Definition: Resource.hxx:319
static QColor normalNodeBrushColor
Definition: Resource.hxx:220
static QColor TOACTIVATE
Definition: Resource.hxx:241
static QColor STOPPED
Definition: Resource.hxx:233
static QColor UNKNOWN
Definition: Resource.hxx:234
static QColor editedNodeBrushColor
Definition: Resource.hxx:219
static QColor validNodeColor
Definition: Resource.hxx:222
static QColor INITIALISED
Definition: Resource.hxx:228
static QColor runNodeBrushColor
Definition: Resource.hxx:221
static QColor LOADFAILED
Definition: Resource.hxx:246
static QColor SUSPENDED
Definition: Resource.hxx:245
static int Line_Space
Definition: Resource.hxx:313
static QColor invalidNodeColor
Definition: Resource.hxx:223
static int progressBar_Height
Definition: Resource.hxx:322
static QColor TOLOAD
Definition: Resource.hxx:239
static QColor ERROR
Definition: Resource.hxx:252
static int Radius
Definition: Resource.hxx:320
static QColor PAUSE
Definition: Resource.hxx:248
virtual void setText(QString label)
SceneHeaderItem(QGraphicsScene *scene, SceneItem *parent, QString label)
virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
virtual void autoPosControl(AbstractSceneItem *item)
virtual void setValid(bool isValid)
virtual QRectF getMinimalBoundingRect() const
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event)
virtual void reorganizePorts(shownState ss)
virtual SceneCtrlPortItem * getCtrlInPortItem()
virtual void setExecState(int execState)
virtual void setText(QString label)
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
virtual void adaptComposedNode(SceneItem *port, qreal deltaY)
virtual void autoPosNewPort(AbstractSceneItem *item)
virtual void setEdited(bool isEdited)
std::list< SceneOutPortItem * > _outPorts
virtual SceneCtrlPortItem * getCtrlOutPortItem()
virtual void popupMenu(QWidget *caller, const QPoint &globalPos)
std::list< SceneInPortItem * > _inPorts
virtual void popupMenu(QWidget *caller, const QPoint &globalPos)
virtual void setTopLeft(QPointF topLeft)
Definition: SceneItem.cxx:241
@ RUNNING
Definition: define.hxx:67
@ PAUSED
Definition: define.hxx:69
@ WAITINGTASKS
Definition: define.hxx:68
@ INITIALISED
Definition: define.hxx:66
@ NOTYETINITIALIZED
Definition: define.hxx:65
@ FINISHED
Definition: define.hxx:70
@ STOPPED
Definition: define.hxx:71
@ INVALID
Definition: define.hxx:36
@ FAILED
Definition: define.hxx:51
@ UNDEFINED
Definition: define.hxx:35
@ DESACTIVATED
Definition: define.hxx:42
@ EXECFAILED
Definition: define.hxx:46
@ TOLOAD
Definition: define.hxx:38
@ LOADED
Definition: define.hxx:39
@ READY
Definition: define.hxx:37
@ ACTIVATED
Definition: define.hxx:41
@ INTERNALERR
Definition: define.hxx:49
@ DONE
Definition: define.hxx:43
@ TOACTIVATE
Definition: define.hxx:40
@ SUSPENDED
Definition: define.hxx:44
@ PAUSE
Definition: define.hxx:47
@ DISABLED
Definition: define.hxx:50
@ LOADFAILED
Definition: define.hxx:45
@ ERROR
Definition: define.hxx:52
def h(x, y, destx, desty)
Definition: graph.py:272