1 // Copyright (C) 2006-2013 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.
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
23 #include "SceneBlocItem.hxx"
24 #include "SceneComposedNodeItem.hxx"
25 #include "SceneElementaryNodeItem.hxx"
26 #include "SceneHeaderItem.hxx"
27 #include "SceneHeaderNodeItem.hxx"
28 #include "SceneInPortItem.hxx"
29 #include "SceneOutPortItem.hxx"
30 #include "SceneLinkItem.hxx"
31 #include "SceneDSLinkItem.hxx"
32 #include "SceneCtrlLinkItem.hxx"
33 #include "LinkMatrix.hxx"
34 #include "LinkAStar.hxx"
35 #include "ItemMimeData.hxx"
36 #include "QtGuiContext.hxx"
38 #include "Message.hxx"
39 #include "guiObservers.hxx"
40 #include "GuiEditor.hxx"
45 #include <QGraphicsSceneDragDropEvent>
49 #include "Resource.hxx"
52 #include "YacsTrace.hxx"
55 using namespace YACS::ENGINE;
56 using namespace YACS::HMI;
58 SceneComposedNodeItem::SceneComposedNodeItem(QGraphicsScene *scene, SceneItem *parent,
59 QString label, Subject *subject)
60 : SceneNodeItem(scene, parent, label, subject)
62 DEBTRACE("SceneComposedNodeItem::SceneComposedNodeItem " <<label.toStdString());
64 _width = 2*Resource::Corner_Margin + 2*Resource::DataPort_Width + Resource::Space_Margin;
65 _height = Resource::Header_Height + Resource::DataPort_Height + Resource::Corner_Margin;
67 _hiBrushColor = Resource::ComposedNode_hiBrush;
68 _penColor = Resource::ComposedNode_pen;
69 _hiPenColor = Resource::ComposedNode_hiPen;
75 SceneComposedNodeItem::~SceneComposedNodeItem()
79 void SceneComposedNodeItem::adjustColors()
81 _brushColor = Resource::ComposedNode_brush.darker(100 +5*_level);
82 for (list<AbstractSceneItem*>::const_iterator it=_children.begin(); it!=_children.end(); ++it)
84 if (SceneComposedNodeItem *scnode = dynamic_cast<SceneComposedNodeItem*>(*it))
85 scnode->adjustColors();
89 QRectF SceneComposedNodeItem::childrenBoundingRect() const
91 QRectF ChildrenBRect =QRectF(x(), y(), 5, 5);
92 if (_header) ChildrenBRect = _header->getMinimalBoundingRect();
93 for (list<AbstractSceneItem*>::const_iterator it=_children.begin(); it!=_children.end(); ++it)
94 ChildrenBRect = ChildrenBRect.united(childBoundingRect(*it));
95 ChildrenBRect.setWidth (ChildrenBRect.width() + Resource::Border_Margin);
96 ChildrenBRect.setHeight(ChildrenBRect.height() + Resource::Border_Margin);
100 void SceneComposedNodeItem::paint(QPainter *painter,
101 const QStyleOptionGraphicsItem *option,
104 //DEBTRACE("SceneComposedNodeItem::paint " << _label.toStdString());
105 // IMN (14/11/2013) below block commented
106 // prevent bad resizing of scene in shrink mode
107 /* if (!isExpanded()) {
108 _width = 2*Resource::Corner_Margin + 2*Resource::DataPort_Width + Resource::Space_Margin;
109 _height = getHeaderBottom() + Resource::Corner_Margin;
113 painter->setPen(getPenColor());
114 painter->setBrush(getBrushColor());
115 painter->drawRect(QRectF(Resource::Border_Margin, Resource::Border_Margin, _width - 2*Resource::Border_Margin, _height - 2*Resource::Border_Margin));
119 void SceneComposedNodeItem::update(GuiEvent event, int type, Subject* son)
121 DEBTRACE("SceneComposedNodeItem::update "<< eventName(event)<<" "<<type<<" "<<son);
122 SceneNodeItem::update(event, type, son);
123 AbstractSceneItem *item;
129 case YACS::HMI::BLOC:
130 item = new SceneBlocItem(_scene,
132 son->getName().c_str(),
135 autoPosNewChild(item, _children, true);
137 case YACS::HMI::FORLOOP:
138 case YACS::HMI::WHILELOOP:
139 case YACS::HMI::SWITCH:
140 case YACS::HMI::FOREACHLOOP:
141 case YACS::HMI::OPTIMIZERLOOP:
142 item = new SceneComposedNodeItem(_scene,
144 son->getName().c_str(),
147 autoPosNewChild(item, _children, true);
149 case YACS::HMI::PYTHONNODE:
150 case YACS::HMI::PYFUNCNODE:
151 case YACS::HMI::CORBANODE:
152 case YACS::HMI::CPPNODE:
153 case YACS::HMI::SALOMENODE:
154 case YACS::HMI::SALOMEPYTHONNODE:
155 case YACS::HMI::XMLNODE:
156 case YACS::HMI::PRESETNODE:
157 case YACS::HMI::OUTNODE:
158 case YACS::HMI::STUDYINNODE:
159 case YACS::HMI::STUDYOUTNODE:
160 item = new SceneElementaryNodeItem(_scene,
162 son->getName().c_str(),
165 autoPosNewChild(item, _children, true);
167 case YACS::HMI::INPUTPORT:
168 case YACS::HMI::INPUTDATASTREAMPORT:
169 item = new SceneInPortItem(_scene,
171 son->getName().c_str(),
173 _header->autoPosNewPort(item);
174 _inPorts.push_back(item);
175 if (Scene::_autoComputeLinks && !QtGuiContext::getQtCurrent()->isLoading())
177 YACS::HMI::SubjectProc* subproc = QtGuiContext::getQtCurrent()->getSubjectProc();
178 SceneItem *item = QtGuiContext::getQtCurrent()->_mapOfSceneItem[subproc];
179 SceneComposedNodeItem *proc = dynamic_cast<SceneComposedNodeItem*>(item);
180 proc->rebuildLinks();
183 case YACS::HMI::OUTPUTPORT:
184 case YACS::HMI::OUTPUTDATASTREAMPORT:
185 item = new SceneOutPortItem(_scene,
187 son->getName().c_str(),
189 _header->autoPosNewPort(item);
190 _outPorts.push_back(item);
191 if (Scene::_autoComputeLinks && !QtGuiContext::getQtCurrent()->isLoading())
193 YACS::HMI::SubjectProc* subproc = QtGuiContext::getQtCurrent()->getSubjectProc();
194 SceneItem *item = QtGuiContext::getQtCurrent()->_mapOfSceneItem[subproc];
195 SceneComposedNodeItem *proc = dynamic_cast<SceneComposedNodeItem*>(item);
196 proc->rebuildLinks();
200 DEBTRACE("SceneComposedNodeItem::update() ADD, type not handled:" << type);
203 case YACS::HMI::ADDLINK:
206 case YACS::HMI::DATALINK:
207 if (SubjectLink* slink = dynamic_cast<SubjectLink*>(son))
209 SubjectDataPort* soutp = slink->getSubjectOutPort();
210 SubjectDataPort* sinp = slink->getSubjectInPort();
211 SceneItem * scout = QtGuiContext::getQtCurrent()->_mapOfSceneItem[soutp];
212 SceneItem * scin = QtGuiContext::getQtCurrent()->_mapOfSceneItem[sinp];
213 ScenePortItem* from = dynamic_cast<ScenePortItem*>(scout);
214 ScenePortItem* to = dynamic_cast<ScenePortItem*>(scin);
215 if (dynamic_cast<SubjectInputDataStreamPort*>(sinp))
217 SceneDSLinkItem* item = new SceneDSLinkItem(_scene,
220 son->getName().c_str(),
226 SceneLinkItem* item = new SceneLinkItem(_scene,
229 son->getName().c_str(),
233 if (Scene::_autoComputeLinks && !QtGuiContext::getQtCurrent()->isLoading())
235 YACS::HMI::SubjectProc* subproc = QtGuiContext::getQtCurrent()->getSubjectProc();
236 SceneItem *item = QtGuiContext::getQtCurrent()->_mapOfSceneItem[subproc];
237 SceneComposedNodeItem *proc = dynamic_cast<SceneComposedNodeItem*>(item);
238 proc->rebuildLinks();
244 case YACS::HMI::ADDCONTROLLINK:
247 case YACS::HMI::CONTROLLINK:
248 if (SubjectControlLink* slink = dynamic_cast<SubjectControlLink*>(son))
250 SubjectNode* soutn = slink->getSubjectOutNode();
251 SubjectNode* sinn = slink->getSubjectInNode();
252 SceneItem * scout = QtGuiContext::getQtCurrent()->_mapOfSceneItem[soutn];
253 SceneItem * scin = QtGuiContext::getQtCurrent()->_mapOfSceneItem[sinn];
254 SceneNodeItem* nodefrom = dynamic_cast<SceneNodeItem*>(scout);
255 SceneNodeItem* nodeto = dynamic_cast<SceneNodeItem*>(scin);
256 if (!nodeto || !nodefrom) DEBTRACE("CONTROLLINK problem -----------------");
257 ScenePortItem* from = nodefrom->getCtrlOutPortItem();
258 ScenePortItem* to = nodeto->getCtrlInPortItem();
259 if (!to || !from) DEBTRACE("CONTROLLINK problem -----------------");
260 SceneCtrlLinkItem* item = new SceneCtrlLinkItem(_scene,
263 son->getName().c_str(),
266 if (Scene::_autoComputeLinks && !QtGuiContext::getQtCurrent()->isLoading())
268 YACS::HMI::SubjectProc* subproc = QtGuiContext::getQtCurrent()->getSubjectProc();
269 SceneItem *item = QtGuiContext::getQtCurrent()->_mapOfSceneItem[subproc];
270 SceneComposedNodeItem *proc = dynamic_cast<SceneComposedNodeItem*>(item);
271 proc->rebuildLinks();
277 case YACS::HMI::REMOVE:
278 //SceneObserverItem::update(event, type, son);
280 case YACS::HMI::SETCASE:
282 SubjectSwitch *sSwitch = dynamic_cast<SubjectSwitch*>(_subject);
285 Switch *aSwitch = dynamic_cast<Switch*>(sSwitch->getNode());
286 Node *node = aSwitch->edGetNode(type);
289 if (GuiContext::getCurrent()->_mapOfSubjectNode.count(node))
291 Subject* sub = GuiContext::getCurrent()->_mapOfSubjectNode[node];
292 if (QtGuiContext::getQtCurrent()->_mapOfSceneItem.count(sub))
294 SceneItem* item = QtGuiContext::getQtCurrent()->_mapOfSceneItem[sub];
295 SceneNodeItem *scnode = dynamic_cast<SceneNodeItem*>(item);
296 if (scnode) scnode->updateName();
305 SceneItem * sinode = QtGuiContext::getQtCurrent()->_mapOfSceneItem[son];
306 removeChildFromList(sinode);
309 case YACS::HMI::PASTE:
311 SceneItem * sinode = QtGuiContext::getQtCurrent()->_mapOfSceneItem[son];
312 sinode->setParent(this);
314 if (SceneComposedNodeItem *scnode = dynamic_cast<SceneComposedNodeItem*>(sinode))
315 scnode->adjustColors();
316 autoPosNewChild(sinode, _children, true);
321 // DEBTRACE("SceneComposedNodeItem::update(), event not handled: "<< eventName(event));
325 void SceneComposedNodeItem::autoPosNewChild(AbstractSceneItem *item,
326 const std::list<AbstractSceneItem*> alreadySet,
329 SceneItem *it = dynamic_cast<SceneItem*>(item);
333 qreal xLeft = Resource::Corner_Margin;
334 qreal yTop = getHeaderBottom() + Resource::Space_Margin;
335 for (list<AbstractSceneItem*>::const_iterator it=alreadySet.begin(); it!=alreadySet.end(); ++it)
337 childrenBox = childrenBox.united(childBoundingRect(*it));
338 DEBTRACE((*it)->getLabel().toStdString());
339 DEBTRACE("childrenBox valid " << childrenBox.right() << " " << childrenBox.bottom());
341 if (childrenBox.isValid())
342 yTop = childrenBox.bottom() + 1.; // +1. to avoid collision with bottom (penwidth)
343 //xLeft += childrenBox.right();
344 DEBTRACE("left, top " << xLeft << " " << yTop);
345 QPointF topLeft(xLeft, yTop);
346 if (isNew) _children.push_back(item);
347 if (_eventPos.isNull())
349 //DEBTRACE("_eventPos.isNull");
350 item->setTopLeft(topLeft);
354 //DEBTRACE("_eventPos " << _eventPos.x() << " " << _eventPos.y());
355 item->setTopLeft(_eventPos);
357 collisionResolv(it, -it->boundingRect().bottomRight()); // as if the new item was coming from top left (previous position outside)
358 if (Scene::_autoComputeLinks && !QtGuiContext::getQtCurrent()->isLoading()) rebuildLinks();
363 void SceneComposedNodeItem::popupMenu(QWidget *caller, const QPoint &globalPos)
366 m.popupMenu(caller, globalPos);
369 std::list<AbstractSceneItem*> SceneComposedNodeItem::getChildren()
374 void SceneComposedNodeItem::removeChildFromList(AbstractSceneItem* child)
376 _children.remove(child);
379 void SceneComposedNodeItem::reorganizeShrinkExpand() {
380 DEBTRACE("SceneComposedNodeItem::reorganizeShrinkExpand " << _expanded << " " << _label.toStdString());
381 bool isExpanding = isExpanded();
383 //update control links
384 std::list<SubjectControlLink*> lscl=dynamic_cast<SubjectNode*>(_subject)->getSubjectControlLinks();
385 for (std::list<SubjectControlLink*>::const_iterator it = lscl.begin(); it != lscl.end(); ++it) {
386 SceneLinkItem* lk = dynamic_cast<SceneLinkItem*>(QtGuiContext::getQtCurrent()->_mapOfSceneItem[*it]);
388 bool b1 = true, b2 = true;
390 SceneNodeItem* no = lk->getFromNode();
392 SceneComposedNodeItem* scni = dynamic_cast<SceneComposedNodeItem*>(no);
398 no = lk->getToNode();
400 SceneComposedNodeItem* scni = dynamic_cast<SceneComposedNodeItem*>(no);
415 shrinkExpandRecursive(isExpanding, true);
416 if (Scene::_autoComputeLinks)
418 SubjectProc* subproc = QtGuiContext::getQtCurrent()->getSubjectProc();
419 SceneItem *item = QtGuiContext::getQtCurrent()->_mapOfSceneItem[subproc];
420 SceneComposedNodeItem *proc = dynamic_cast<SceneComposedNodeItem*>(item);
421 proc->rebuildLinks();
425 void SceneComposedNodeItem::shrinkExpandRecursive(bool isExpanding, bool fromHere)
427 DEBTRACE("SceneComposedNodeItem::shrinkExpandRecursive " << isExpanding << " " << fromHere << " " << isExpanded() << " " << _label.toStdString());
430 { // ---collapsing: hide first children , then resize
431 for (list<AbstractSceneItem*>::const_iterator it=_children.begin(); it!=_children.end(); ++it)
433 SceneItem* item = dynamic_cast<SceneItem*>(*it);
434 item->shrinkExpandRecursive(false, false);
436 DEBTRACE("------------------------------- Hide " << item->getLabel().toStdString());
437 item->shrinkExpandLink(false);
440 if (_shownState == expandShown)
442 _expandedWidth = _width;
443 _expandedHeight = _height;
448 _shownState = shrinkShown;
452 _ancestorShrinked = true;
453 _shownState = shrinkHidden;
456 _width = 2*Resource::Corner_Margin + 2*Resource::DataPort_Width + Resource::Space_Margin;
457 if (_shownState == shrinkShown)
458 _height = getHeaderBottom() + Resource::Corner_Margin;
460 _height = Resource::Header_Height + Resource::Corner_Margin;
462 if (_shownState == shrinkHidden) // shrink of ancestor
465 setPos(_expandedPos);
469 { // --- expanding: resize, then show children
470 _ancestorShrinked = false;
472 for (list<AbstractSceneItem*>::const_iterator it=_children.begin(); it!=_children.end(); ++it)
474 SceneItem* item = dynamic_cast<SceneItem*>(*it);
475 item->shrinkExpandRecursive(isExpanded(), false);
479 DEBTRACE("------------------------------- Show " << item->getLabel().toStdString());
484 DEBTRACE("------------------------------- Hide " << item->getLabel().toStdString());
486 item->shrinkExpandLink(fromHere);
491 _width = _expandedWidth;
492 _height = _expandedHeight;
493 _shownState = expandShown;
497 _shownState = shrinkShown;
498 _width = 2*Resource::Corner_Margin + 2*Resource::DataPort_Width + Resource::Space_Margin;
499 _height = getHeaderBottom() + Resource::Corner_Margin;
501 setPos(_expandedPos);
506 void SceneComposedNodeItem::shrinkExpandLink(bool se) {
507 DEBTRACE("SceneComposedNodeItem::shrinkExpandLink " << se << " " << _label.toStdString());
508 se = se && isExpanded();
509 foreach (QGraphicsItem *child, childItems()) {
510 if (SceneItem *sci = dynamic_cast<SceneItem*>(child)) {
511 sci->shrinkExpandLink(se);
516 void SceneComposedNodeItem::reorganize()
518 DEBTRACE("SceneComposedNodeItem::reorganize() " << _label.toStdString());
519 list<AbstractSceneItem*> alreadySet;
520 for (list<AbstractSceneItem*>::const_iterator it=_children.begin(); it!=_children.end(); ++it)
522 autoPosNewChild(*it, alreadySet);
523 alreadySet.push_back(*it);
527 void SceneComposedNodeItem::setShownState(shownState ss)
530 if (_shownState == shrinkHidden)
532 _ancestorShrinked = true;
537 _ancestorShrinked = false;
543 void SceneComposedNodeItem::collisionResolv(SceneItem* child, QPointF oldPos)
545 //DEBTRACE("SceneComposedNodeItem::collisionResolv " << _label.toStdString());
546 for (list<AbstractSceneItem*>::const_iterator it=_children.begin(); it!=_children.end(); ++it)
548 SceneNodeItem *other = dynamic_cast<SceneNodeItem*>(*it);
549 if (other && (other != child))
551 if (child->collidesWithItem(other))
553 //DEBTRACE("collision detected with " << other->getLabel().toStdString());
554 QRectF otherBR = (other->mapToParent(other->boundingRect())).boundingRect();
555 qreal oldX = oldPos.x();
556 qreal oldY = oldPos.y();
557 qreal newX = child->pos().x();
558 qreal newY = child->pos().y();
559 qreal othX = otherBR.left()+0.5;
560 qreal othY = otherBR.top()+0.5;
561 //DEBTRACE("oldX=" << oldX << " oldY=" << oldY << " newX=" << newX << " newY=" << newY);
562 //DEBTRACE("otherLeft=" << otherBR.left() << " otherRight=" << otherBR.right() <<
563 // " otherTop=" << otherBR.top() << " otherBottom=" << otherBR.bottom());
564 //DEBTRACE("width=" << child->boundingRect().width() <<
565 // " height=" << child->boundingRect().height());
566 bool fromTop = (((oldY + child->boundingRect().height()) <= otherBR.top()+1) &&
567 ((newY + child->boundingRect().height()) >= otherBR.top()));
568 bool fromBottom = (( oldY >= otherBR.bottom()) &&
569 ( newY <= otherBR.bottom()));
570 bool fromRight = (( oldX >= otherBR.right()) &&
571 ( newX <= otherBR.right()));
572 bool fromLeft = (((oldX+ child->boundingRect().width()) <= otherBR.left()+1) &&
573 ((newX+ child->boundingRect().width()) >= otherBR.left()));
574 //DEBTRACE("fromTop=" << fromTop << " fromBottom=" << fromBottom
575 // << " fromRight=" << fromRight << " fromLeft=" << fromLeft);
576 bool pushOther =false;
577 bool blocThis = false;
580 othY = newY + child->boundingRect().height();
582 other->_blocY = false;
586 othX = newX+ child->boundingRect().width();
588 other->_blocX = false;
594 newY = otherBR.bottom() + 1;
600 othY = newY - otherBR.height();
601 if ( othY < Resource::Space_Margin + getHeaderBottom() )
603 othY = Resource::Space_Margin + getHeaderBottom();
604 other->_blocY = true;
605 newY = otherBR.bottom() + 1;
617 newX = otherBR.right()+ 1;
623 othX = newX - otherBR.width();
624 if (othX < Resource::Space_Margin)
626 othX = Resource::Space_Margin;
627 other->_blocX = true;
628 newX = otherBR.right()+ 1;
636 //DEBTRACE("newX=" << newX << " newY=" << newY);
637 if (blocThis) child->setTopLeft(QPointF(newX, newY));
640 other->setTopLeft(QPointF(othX, othY));
647 void SceneComposedNodeItem::rebuildLinks()
649 DEBTRACE("SceneComposedNodeItem::rebuildLinks " << QtGuiContext::_delayCalc);
650 if (QtGuiContext::_delayCalc)
654 LinkMatrix matrix(this);
658 list<linkdef> alist = matrix.getListOfDataLinkDef();
659 list<linkdef> blist = matrix.getListOfCtrlLinkDef(); // add list operator ?
660 for (list<linkdef>::const_iterator ii = blist.begin(); ii != blist.end(); ++ii)
661 alist.push_back(*ii);
665 LinkAStar astar(matrix);
666 for (list<linkdef>::const_iterator it = alist.begin(); it != alist.end(); ++it)
669 DEBTRACE("from("<<ali.from.first<<","<<ali.from.second
670 <<") to ("<<ali.to.first<<","<<ali.to.second
671 <<") " << ali.item->getLabel().toStdString());
672 if(ali.from.first<0||ali.from.second<0||ali.to.first<0||ali.to.second<0) continue;
674 bool isPath = astar.computePath(LNode(ali.from), LNode(ali.to));
677 if (! isPath) DEBTRACE("Link Path not found !");
678 if (! isPath) continue;
679 LNodePath ijPath = astar.givePath();
680 if(Scene::_addRowCols)
681 matrix.incrementCost(ijPath);
682 LinkPath apath = matrix.getPath(ijPath);
683 // DEBTRACE(apath.size());
686 ali.item->setPath(apath);
690 void SceneComposedNodeItem::arrangeNodes(bool isRecursive)
692 DEBTRACE("SceneComposedItem::arrangeNodes " << isRecursive);
694 bool isExtern = !QtGuiContext::_delayCalc;
695 QtGuiContext::_delayCalc = true; // avoid rebuildLinks
697 SubjectComposedNode *scnode = dynamic_cast<SubjectComposedNode*>(getSubject());
699 ComposedNode *cnode = dynamic_cast<ComposedNode*>(scnode->getNode());
704 list<Node*> children = cnode->edGetDirectDescendants();
705 for (list<Node*>::iterator it = children.begin(); it != children.end(); ++it)
707 DEBTRACE("child " << (*it)->getName());
708 SceneComposedNodeItem *scni = 0;
709 ComposedNode *cchild = dynamic_cast<ComposedNode*>(*it);
712 SubjectNode* sn = GuiContext::getCurrent()->_mapOfSubjectNode[cchild];
713 SceneItem* sci = QtGuiContext::getQtCurrent()->_mapOfSceneItem[sn];
714 if (sci) scni = dynamic_cast<SceneComposedNodeItem*>(sci);
716 if (scni && (scni->getShownState() == expandShown))
718 DEBTRACE("call arrangeNode on child " << (*it)->getName());
719 scni->arrangeNodes(isRecursive);
729 QtGuiContext::_delayCalc = false; // allow rebuildLinks
730 if (Scene::_autoComputeLinks)
735 void SceneComposedNodeItem::arrangeChildNodes()
740 void SceneComposedNodeItem::dragEnterEvent(QGraphicsSceneDragDropEvent *event)
742 bool accepted = false;
743 const ItemMimeData *myData = dynamic_cast<const ItemMimeData*>(event->mimeData());
746 if (myData->hasFormat("yacs/cataService") ||
747 myData->hasFormat("yacs/cataNode") ||
748 myData->hasFormat("yacs/subjectNode"))
750 event->setAccepted(true);
752 QGraphicsItem::update();
756 event->setAccepted(accepted);
759 void SceneComposedNodeItem::dragLeaveEvent(QGraphicsSceneDragDropEvent *event)
763 QGraphicsItem::update();
766 void SceneComposedNodeItem::dropEvent(QGraphicsSceneDragDropEvent *event)
770 QGraphicsItem::update();
772 const ItemMimeData *myData = dynamic_cast<const ItemMimeData*>(event->mimeData());
774 setEventPos(event->scenePos());
775 if (myData->hasFormat("yacs/cataService") || myData->hasFormat("yacs/cataNode"))
777 SubjectComposedNode *cnode = dynamic_cast<SubjectComposedNode*>(getSubject());
778 bool createNewComponentInstance=Resource::COMPONENT_INSTANCE_NEW;
779 // by default getControl gives false. In this case we use the user preference COMPONENT_INSTANCE_NEW
780 // to create the node. If getControl gives true we invert the user preference
781 if(myData->getControl())
782 createNewComponentInstance=!Resource::COMPONENT_INSTANCE_NEW;
783 QtGuiContext::getQtCurrent()->getGMain()->_guiEditor->CreateNodeFromCatalog(myData, cnode,createNewComponentInstance);
785 else if(myData->hasFormat("yacs/subjectNode"))
787 Subject *sub = myData->getSubject();
789 SubjectNode *node = dynamic_cast<SubjectNode*>(sub);
791 if (dynamic_cast<SubjectProc*>(node)) return; // --- do not reparent proc !
792 SubjectComposedNode *cnode = dynamic_cast<SubjectComposedNode*>(getSubject());
794 if (!node->reparent(cnode))
799 QColor SceneComposedNodeItem::getPenColor()
802 return Resource::dragOver;
809 QColor SceneComposedNodeItem::getBrushColor()
812 return _hiBrushColor;
816 color = _hiBrushColor;
817 else if (_emphasized)
818 color = Resource::emphasizeBrushColor;
823 color = hoverColor(color);
827 void SceneComposedNodeItem::updateChildItems()
829 SceneNodeItem::updateChildItems();
832 foreach (QGraphicsItem *child, _header->childItems())
834 if (SceneItem *sci = dynamic_cast<SceneItem*>(child))