Version: 9.16.0
SchemaComposedNodeItem.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 <Python.h>
21
22#include "Resource.hxx"
24#include "SchemaNodeItem.hxx"
25#include "SchemaInPortItem.hxx"
26#include "SchemaOutPortItem.hxx"
30#include "SchemaLinkItem.hxx"
34#include "Menus.hxx"
35#include "Message.hxx"
36#include "QtGuiContext.hxx"
37#include "ItemMimeData.hxx"
38#include "GuiEditor.hxx"
39#include "RuntimeSALOME.hxx"
40#include "Catalog.hxx"
41
42#include "commandsProc.hxx"
43#include "ComposedNode.hxx"
44#include "guiObservers.hxx"
45#include "Node.hxx"
46#include "Switch.hxx"
47
48#include <QIcon>
49#include <QMimeData>
50
51#include <cassert>
52
53//#define _DEVDEBUG_
54#include "YacsTrace.hxx"
55
56using namespace std;
57using namespace YACS::ENGINE;
58using namespace YACS::HMI;
59
60SchemaComposedNodeItem::SchemaComposedNodeItem(SchemaItem *parent, QString label, Subject* subject)
61 : SchemaItem(parent, label, subject)
62{
63 DEBTRACE("SchemaComposedNodeItem::SchemaComposedNodeItem");
64 switch (subject->getType())
65 {
66 case YACS::HMI::BLOC:
67 _itemDeco.replace(YLabel, QIcon("icons:block_node.png"));
68 break;
73 _itemDeco.replace(YLabel, QIcon("icons:loop_node.png"));
74 break;
76 _itemDeco.replace(YLabel, QIcon("icons:switch_node.png"));
77 break;
78 default:
79 _itemDeco.replace(YLabel, QIcon("icons:block_node.png"));
80 }
81 _dirTypesItem = 0;
83 _dirLinksItem = 0;
84 Subject *son = 0;
85 int nbsons = childCount();
87
88 model->beginInsertRows(modelIndex(), nbsons, nbsons);
89 if (SubjectProc* sProc = dynamic_cast<SubjectProc*>(subject))
90 {
91 son = new Subject(getSubject());
92 _dirTypesItem = new SchemaDirTypesItem(this, "Types", son);
93 son = new Subject(getSubject());
94 _dirContainersItem = new SchemaDirContainersItem(this, "Containers", son);
95 }
96 son = new Subject(getSubject());
97 _dirLinksItem = new SchemaDirLinksItem(this, "Links", son);
98 model->endInsertRows();
99
100 if (!model->isEdition())
101 {
103 }
104
105 SubjectComposedNode *scn = dynamic_cast<SubjectComposedNode*>(subject);
106 YASSERT(scn);
107 if (scn->hasValue())
108 {
109 _itemData.replace(YType, scn->getValue().c_str());
110 model->setData(modelIndex(YType), 0);
111 }
112
113 setCaseValue();
114}
115
117{
118 DEBTRACE("SchemaComposedNodeItem::~SchemaComposedNodeItem");
119}
120
122{
123 DEBTRACE("SchemaComposedNodeItem::update "<<eventName(event)<<" "<<type<<" "<<son);
125 SchemaItem *item = 0;
126 SubjectNode *snode = 0;
127 SubjectComposedNode *scnode = 0;
128 Node* node = 0;
129 switch (event)
130 {
131 case YACS::HMI::ADD:
132 switch (type)
133 {
134 case YACS::HMI::BLOC:
140 {
141 int nbsons = childCount();
142 model->beginInsertRows(modelIndex(), nbsons, nbsons);
143 item = new SchemaComposedNodeItem(this,
144 son->getName().c_str(),
145 son);
146 model->endInsertRows();
147 }
148 break;
160 {
161 int nbsons = childCount();
162 model->beginInsertRows(modelIndex(), nbsons, nbsons);
163 item = new SchemaNodeItem(this,
164 son->getName().c_str(),
165 son);
166 model->endInsertRows();
167 }
168 break;
171 {
172 int nbsons = childCount();
173 model->beginInsertRows(modelIndex(), nbsons, nbsons);
174 item = new SchemaInPortItem(this,
175 son->getName().c_str(),
176 son);
177 model->endInsertRows();
178 }
179 break;
182 {
183 int nbsons = childCount();
184 model->beginInsertRows(modelIndex(), nbsons, nbsons);
185 item = new SchemaOutPortItem(this,
186 son->getName().c_str(),
187 son);
188 model->endInsertRows();
189 }
190 break;
192 {
195 }
196 break;
198 {
201 }
202 break;
204 {
207 }
208 break;
209 }
210 break;
211
213 switch (type)
214 {
216 {
219 }
220 break;
221 }
222 break;
223
225 snode = dynamic_cast<SubjectNode*>(_subject);
226 YASSERT(snode);
227 node = snode->getNode();
228 YASSERT(node);
229 switch (node->getState())
230 {
231 case YACS::INVALID:
232 _itemForeground.replace(YLabel, QColor("red"));
233 model->setData(modelIndex(YLabel), 0);
234 break;
235 case YACS::READY:
236 _itemForeground.replace(YLabel, QColor("blue"));
237 model->setData(modelIndex(YLabel), 0);
238 break;
239 default:
240 break;
241 }
242 break;
245 {
248 }
249 break;
251 setExecState(type);
252 model->setData(modelIndex(YState), 0);
253 break;
255 scnode = dynamic_cast<SubjectComposedNode*>(_subject);
256 if (scnode->hasValue())
257 {
258 _itemData.replace(YType, scnode->getValue().c_str());
259 model->setData(modelIndex(YType), 0);
260 }
262 {
263 SubjectSwitch *sSwitch = dynamic_cast<SubjectSwitch*>(_subject);
264 if (sSwitch)
265 {
266 Switch *aSwitch = dynamic_cast<Switch*>(sSwitch->getNode());
267 Node *node = aSwitch->edGetNode(type);
268 if (node)
269 {
270 if (GuiContext::getCurrent()->_mapOfSubjectNode.count(node))
271 {
273 if (QtGuiContext::getQtCurrent()->_mapOfSchemaItem.count(sub))
274 {
276 item->setCaseValue();
277 }
278 }
279 }
280 }
281 }
282 break;
284 {
285 SubjectSwitch *sSwitch = dynamic_cast<SubjectSwitch*>(_subject);
286 if (sSwitch && sSwitch->hasValue())
287 {
288 _itemData.replace(YType, sSwitch->getValue().c_str());
289 model->setData(modelIndex(YType), 0);
290 }
291 }
292 break;
293 case YACS::HMI::CUT:
294 {
296 int position = toMove->row();
297 model->beginRemoveRows(modelIndex(), position, position);
298 removeChild(toMove);
299 model->endRemoveRows();
300 }
301 break;
302 case YACS::HMI::PASTE:
303 {
305 int nbsons = childCount();
306 model->beginInsertRows(modelIndex(), nbsons, nbsons);
307 toPaste->reparent(this);
308 model->endInsertRows();
309 }
310 break;
311 default:
312 //DEBTRACE("SchemaComposedNodeItem::update(), event not handled: "<< eventName(event));
313 SchemaItem::update(event, type, son);
314 }
315}
316
317std::list<YACS::ENGINE::Node*> SchemaComposedNodeItem::getDirectDescendants() const
318{
319 SubjectNode* SNode = dynamic_cast<SubjectNode*>(_subject);
320 YASSERT(SNode);
321 ComposedNode* CNode = dynamic_cast<ComposedNode*>(SNode->getNode());
322 YASSERT(CNode);
323 return CNode->edGetDirectDescendants();
324}
325
326void SchemaComposedNodeItem::popupMenu(QWidget *caller, const QPoint &globalPos)
327{
329 m.popupMenu(caller, globalPos);
330}
331
332Qt::ItemFlags SchemaComposedNodeItem::flags(const QModelIndex &index)
333{
334 //DEBTRACE("SchemaComposedNodeItem::flags");
335 Qt::ItemFlags pflag = Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled;
337 return pflag;
338
339 Qt::ItemFlags flagEdit = 0;
340 int column = index.column();
341 switch (column)
342 {
343 case YValue:
344 flagEdit = Qt::ItemIsEditable; // --- item value editable in model view (for node case in switch)
345 break;
346 }
347
348 return pflag | flagEdit;
349
350}
351
356bool SchemaComposedNodeItem::dropMimeData(const QMimeData* data, Qt::DropAction action)
357{
358 DEBTRACE("SchemaComposedNodeItem::dropMimeData");
359 if (!data) return false;
360 const ItemMimeData* myData = dynamic_cast<const ItemMimeData*>(data);
361 if (!myData) return false;
362 bool ret =false;
363 if (myData->hasFormat("yacs/cataService") || myData->hasFormat("yacs/cataNode"))
364 {
365 ret =true;
366 SubjectComposedNode *cnode = dynamic_cast<SubjectComposedNode*>(getSubject());
367 bool createNewComponentInstance=Resource::COMPONENT_INSTANCE_NEW;
368 // by default getControl gives false. In this case we use the user preference COMPONENT_INSTANCE_NEW
369 // to create the node. If getControl gives true we invert the user preference
370 if(myData->getControl())
371 createNewComponentInstance=!Resource::COMPONENT_INSTANCE_NEW;
372 QtGuiContext::getQtCurrent()->getGMain()->_guiEditor->CreateNodeFromCatalog(myData, cnode,createNewComponentInstance);
373 }
374 else if(myData->hasFormat("yacs/subjectNode"))
375 {
376 ret = true;
377 Subject *sub = myData->getSubject();
378 if (!sub) return false;
379 SubjectNode *node = dynamic_cast<SubjectNode*>(sub);
380 if (!node) return false;
381 SubjectComposedNode *cnode = dynamic_cast<SubjectComposedNode*>(getSubject());
382 if (cnode)
383 if (! node->reparent(cnode))
384 Message mess;
385 }
386 else if(myData->hasFormat("yacs/subjectOutGate"))
387 {
388 Subject *subFrom = myData->getSubject();
389 if (!subFrom) return false;
390 SubjectNode* from = dynamic_cast<SubjectNode*>(subFrom);
391
392 SubjectNode *to = dynamic_cast<SubjectNode*>(getSubject());
393 if (!to) return false;
394
395 bool ret =false;
396 if (from && to)
397 {
398 ret =true;
399 if (!SubjectNode::tryCreateLink(from, to))
400 Message mess;
401 }
402 }
403 return ret;
404}
405
411{
412 if (QApplication::mouseButtons() == Qt::MidButton)
413 return "yacs/subjectNode";
414 else
415 return "yacs/subjectOutGate";
416}
417
419{
420 DEBTRACE("SchemaComposedNodeItem::setCaseValue");
422 SubjectSwitch *sSwitch = dynamic_cast<SubjectSwitch*>(sub);
423 if (!sSwitch) return;
424
426 Switch *aSwitch = dynamic_cast<Switch*>(sSwitch->getNode());
427 YASSERT(aSwitch);
428 SubjectNode *sNode = dynamic_cast<SubjectNode*>(_subject);
429 YASSERT(sNode);
430 int rank = aSwitch->getRankOfNode(sNode->getNode());
431 if (rank == Switch::ID_FOR_DEFAULT_NODE)
432 _itemData.replace(YValue, "default");
433 else
434 _itemData.replace(YValue, rank);
435 model->setData(modelIndex(YValue), 0);
436}
437
439{
440 return "<p>To edit the node properties, select the node and use the input panel. <a href=\"modification.html#property-page-for-block-node\">More...</a></p>";
441}
#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
Base class for all composed nodes.
virtual std::list< Node * > edGetDirectDescendants() const =0
Base class for all nodes.
Definition: Node.hxx:70
virtual YACS::StatesForNode getState() const
Definition: Node.hxx:118
Control node that emulates the C switch.
Definition: Switch.hxx:85
Node * edGetNode(int caseId)
Definition: Switch.cxx:527
int getRankOfNode(Node *node) const
Definition: Switch.cxx:752
YACS::HMI::GuiEditor * _guiEditor
Definition: GenericGui.hxx:201
static GuiContext * getCurrent()
Definition: guiContext.hxx:67
std::map< YACS::ENGINE::Node *, YACS::HMI::SubjectNode * > _mapOfSubjectNode
Definition: guiContext.hxx:70
void CreateNodeFromCatalog(const ItemMimeData *myData, SubjectComposedNode *cnode, bool createNewComponentInstance)
Definition: GuiEditor.cxx:83
static std::string eventName(GuiEvent event)
virtual bool getControl() const
virtual Subject * getSubject(int i=0) const
YACS::HMI::SchemaModel * getSchemaModel()
std::map< YACS::HMI::Subject *, YACS::HMI::SchemaItem * > _mapOfSchemaItem
static QtGuiContext * getQtCurrent()
YACS::HMI::GenericGui * getGMain()
static bool COMPONENT_INSTANCE_NEW
Definition: Resource.hxx:206
std::list< YACS::ENGINE::Node * > getDirectDescendants() const
virtual void update(GuiEvent event, int type, Subject *son)
virtual void setCaseValue()
used in node derived classes
virtual void popupMenu(QWidget *caller, const QPoint &globalPos)
virtual bool dropMimeData(const QMimeData *data, Qt::DropAction action)
virtual QVariant editionWhatsThis(int column) const
virtual Qt::ItemFlags flags(const QModelIndex &index)
SchemaComposedNodeItem(SchemaItem *parent, QString label, Subject *subject)
SchemaDirContainersItem * _dirContainersItem
void addLinkItem(Subject *subject)
void addTypeItem(Subject *subject)
void removeTypeItem(Subject *subject)
virtual Subject * getSubject()
Definition: SchemaItem.cxx:169
virtual void setExecState(int execState)
Definition: SchemaItem.cxx:338
virtual int row() const
Definition: SchemaItem.cxx:154
virtual void setCaseValue()
used in node derived classes
Definition: SchemaItem.cxx:297
QModelIndex modelIndex(int column=0)
Definition: SchemaItem.cxx:253
QList< QVariant > _itemDeco
Definition: SchemaItem.hxx:78
SchemaItem * _parentItem
Definition: SchemaItem.hxx:85
virtual void update(GuiEvent event, int type, Subject *son)
Definition: SchemaItem.cxx:174
virtual QVariant data(int column, int role) const
Definition: SchemaItem.cxx:123
virtual void reparent(SchemaItem *parent)
Definition: SchemaItem.cxx:289
QList< QVariant > _itemForeground
Definition: SchemaItem.hxx:79
QList< QVariant > _itemData
Definition: SchemaItem.hxx:77
virtual void removeChild(SchemaItem *child)
Definition: SchemaItem.cxx:93
virtual int childCount() const
Definition: SchemaItem.cxx:111
virtual bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole)
virtual std::string getValue()
virtual bool reparent(Subject *parent)
virtual YACS::ENGINE::Node * getNode()
static bool tryCreateLink(SubjectNode *subOutNode, SubjectNode *subInNode)
virtual std::string getValue()
virtual std::string getName()
virtual TypeOfElem getType()
@ OUTPUTDATASTREAMPORT
@ INPUTDATASTREAMPORT
@ INVALID
Definition: define.hxx:36
@ UNDEFINED
Definition: define.hxx:35
@ READY
Definition: define.hxx:37