1 // Copyright (C) 2006-2012 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());
107 _width = 2*Resource::Corner_Margin + 2*Resource::DataPort_Width + Resource::Space_Margin;
108 _height = getHeaderBottom() + Resource::Corner_Margin;
112 painter->setPen(getPenColor());
113 painter->setBrush(getBrushColor());
114 painter->drawRect(QRectF(Resource::Border_Margin, Resource::Border_Margin, _width - 2*Resource::Border_Margin, _height - 2*Resource::Border_Margin));
118 void SceneComposedNodeItem::update(GuiEvent event, int type, Subject* son)
120 DEBTRACE("SceneComposedNodeItem::update "<< eventName(event)<<" "<<type<<" "<<son);
121 SceneNodeItem::update(event, type, son);
122 AbstractSceneItem *item;
128 case YACS::HMI::BLOC:
129 item = new SceneBlocItem(_scene,
131 son->getName().c_str(),
134 autoPosNewChild(item, _children, true);
136 case YACS::HMI::FORLOOP:
137 case YACS::HMI::WHILELOOP:
138 case YACS::HMI::SWITCH:
139 case YACS::HMI::FOREACHLOOP:
140 case YACS::HMI::OPTIMIZERLOOP:
141 item = new SceneComposedNodeItem(_scene,
143 son->getName().c_str(),
146 autoPosNewChild(item, _children, true);
148 case YACS::HMI::PYTHONNODE:
149 case YACS::HMI::PYFUNCNODE:
150 case YACS::HMI::CORBANODE:
151 case YACS::HMI::CPPNODE:
152 case YACS::HMI::SALOMENODE:
153 case YACS::HMI::SALOMEPYTHONNODE:
154 case YACS::HMI::XMLNODE:
155 case YACS::HMI::PRESETNODE:
156 case YACS::HMI::OUTNODE:
157 case YACS::HMI::STUDYINNODE:
158 case YACS::HMI::STUDYOUTNODE:
159 item = new SceneElementaryNodeItem(_scene,
161 son->getName().c_str(),
164 autoPosNewChild(item, _children, true);
166 case YACS::HMI::INPUTPORT:
167 case YACS::HMI::INPUTDATASTREAMPORT:
168 item = new SceneInPortItem(_scene,
170 son->getName().c_str(),
172 _header->autoPosNewPort(item);
173 _inPorts.push_back(item);
174 if (Scene::_autoComputeLinks && !QtGuiContext::getQtCurrent()->isLoading())
176 YACS::HMI::SubjectProc* subproc = QtGuiContext::getQtCurrent()->getSubjectProc();
177 SceneItem *item = QtGuiContext::getQtCurrent()->_mapOfSceneItem[subproc];
178 SceneComposedNodeItem *proc = dynamic_cast<SceneComposedNodeItem*>(item);
179 proc->rebuildLinks();
182 case YACS::HMI::OUTPUTPORT:
183 case YACS::HMI::OUTPUTDATASTREAMPORT:
184 item = new SceneOutPortItem(_scene,
186 son->getName().c_str(),
188 _header->autoPosNewPort(item);
189 _outPorts.push_back(item);
190 if (Scene::_autoComputeLinks && !QtGuiContext::getQtCurrent()->isLoading())
192 YACS::HMI::SubjectProc* subproc = QtGuiContext::getQtCurrent()->getSubjectProc();
193 SceneItem *item = QtGuiContext::getQtCurrent()->_mapOfSceneItem[subproc];
194 SceneComposedNodeItem *proc = dynamic_cast<SceneComposedNodeItem*>(item);
195 proc->rebuildLinks();
199 DEBTRACE("SceneComposedNodeItem::update() ADD, type not handled:" << type);
202 case YACS::HMI::ADDLINK:
205 case YACS::HMI::DATALINK:
206 if (SubjectLink* slink = dynamic_cast<SubjectLink*>(son))
208 SubjectDataPort* soutp = slink->getSubjectOutPort();
209 SubjectDataPort* sinp = slink->getSubjectInPort();
210 SceneItem * scout = QtGuiContext::getQtCurrent()->_mapOfSceneItem[soutp];
211 SceneItem * scin = QtGuiContext::getQtCurrent()->_mapOfSceneItem[sinp];
212 ScenePortItem* from = dynamic_cast<ScenePortItem*>(scout);
213 ScenePortItem* to = dynamic_cast<ScenePortItem*>(scin);
214 if (dynamic_cast<SubjectInputDataStreamPort*>(sinp))
216 SceneDSLinkItem* item = new SceneDSLinkItem(_scene,
219 son->getName().c_str(),
225 SceneLinkItem* item = new SceneLinkItem(_scene,
228 son->getName().c_str(),
232 if (Scene::_autoComputeLinks && !QtGuiContext::getQtCurrent()->isLoading())
234 YACS::HMI::SubjectProc* subproc = QtGuiContext::getQtCurrent()->getSubjectProc();
235 SceneItem *item = QtGuiContext::getQtCurrent()->_mapOfSceneItem[subproc];
236 SceneComposedNodeItem *proc = dynamic_cast<SceneComposedNodeItem*>(item);
237 proc->rebuildLinks();
243 case YACS::HMI::ADDCONTROLLINK:
246 case YACS::HMI::CONTROLLINK:
247 if (SubjectControlLink* slink = dynamic_cast<SubjectControlLink*>(son))
249 SubjectNode* soutn = slink->getSubjectOutNode();
250 SubjectNode* sinn = slink->getSubjectInNode();
251 SceneItem * scout = QtGuiContext::getQtCurrent()->_mapOfSceneItem[soutn];
252 SceneItem * scin = QtGuiContext::getQtCurrent()->_mapOfSceneItem[sinn];
253 SceneNodeItem* nodefrom = dynamic_cast<SceneNodeItem*>(scout);
254 SceneNodeItem* nodeto = dynamic_cast<SceneNodeItem*>(scin);
255 if (!nodeto || !nodefrom) DEBTRACE("CONTROLLINK problem -----------------");
256 ScenePortItem* from = nodefrom->getCtrlOutPortItem();
257 ScenePortItem* to = nodeto->getCtrlInPortItem();
258 if (!to || !from) DEBTRACE("CONTROLLINK problem -----------------");
259 SceneCtrlLinkItem* item = new SceneCtrlLinkItem(_scene,
262 son->getName().c_str(),
265 if (Scene::_autoComputeLinks && !QtGuiContext::getQtCurrent()->isLoading())
267 YACS::HMI::SubjectProc* subproc = QtGuiContext::getQtCurrent()->getSubjectProc();
268 SceneItem *item = QtGuiContext::getQtCurrent()->_mapOfSceneItem[subproc];
269 SceneComposedNodeItem *proc = dynamic_cast<SceneComposedNodeItem*>(item);
270 proc->rebuildLinks();
276 case YACS::HMI::REMOVE:
277 //SceneObserverItem::update(event, type, son);
279 case YACS::HMI::SETCASE:
281 SubjectSwitch *sSwitch = dynamic_cast<SubjectSwitch*>(_subject);
284 Switch *aSwitch = dynamic_cast<Switch*>(sSwitch->getNode());
285 Node *node = aSwitch->edGetNode(type);
288 if (GuiContext::getCurrent()->_mapOfSubjectNode.count(node))
290 Subject* sub = GuiContext::getCurrent()->_mapOfSubjectNode[node];
291 if (QtGuiContext::getQtCurrent()->_mapOfSceneItem.count(sub))
293 SceneItem* item = QtGuiContext::getQtCurrent()->_mapOfSceneItem[sub];
294 SceneNodeItem *scnode = dynamic_cast<SceneNodeItem*>(item);
295 if (scnode) scnode->updateName();
304 SceneItem * sinode = QtGuiContext::getQtCurrent()->_mapOfSceneItem[son];
305 removeChildFromList(sinode);
308 case YACS::HMI::PASTE:
310 SceneItem * sinode = QtGuiContext::getQtCurrent()->_mapOfSceneItem[son];
311 sinode->setParent(this);
313 if (SceneComposedNodeItem *scnode = dynamic_cast<SceneComposedNodeItem*>(sinode))
314 scnode->adjustColors();
315 autoPosNewChild(sinode, _children, true);
320 // DEBTRACE("SceneComposedNodeItem::update(), event not handled: "<< eventName(event));
324 void SceneComposedNodeItem::autoPosNewChild(AbstractSceneItem *item,
325 const std::list<AbstractSceneItem*> alreadySet,
328 SceneItem *it = dynamic_cast<SceneItem*>(item);
332 qreal xLeft = Resource::Corner_Margin;
333 qreal yTop = getHeaderBottom() + Resource::Space_Margin;
334 for (list<AbstractSceneItem*>::const_iterator it=alreadySet.begin(); it!=alreadySet.end(); ++it)
336 childrenBox = childrenBox.united(childBoundingRect(*it));
337 DEBTRACE((*it)->getLabel().toStdString());
338 DEBTRACE("childrenBox valid " << childrenBox.right() << " " << childrenBox.bottom());
340 if (childrenBox.isValid())
341 yTop = childrenBox.bottom() + 1.; // +1. to avoid collision with bottom (penwidth)
342 //xLeft += childrenBox.right();
343 DEBTRACE("left, top " << xLeft << " " << yTop);
344 QPointF topLeft(xLeft, yTop);
345 if (isNew) _children.push_back(item);
346 if (_eventPos.isNull())
348 //DEBTRACE("_eventPos.isNull");
349 item->setTopLeft(topLeft);
353 //DEBTRACE("_eventPos " << _eventPos.x() << " " << _eventPos.y());
354 item->setTopLeft(_eventPos);
356 collisionResolv(it, -it->boundingRect().bottomRight()); // as if the new item was coming from top left (previous position outside)
357 if (Scene::_autoComputeLinks && !QtGuiContext::getQtCurrent()->isLoading()) rebuildLinks();
362 void SceneComposedNodeItem::popupMenu(QWidget *caller, const QPoint &globalPos)
365 m.popupMenu(caller, globalPos);
368 std::list<AbstractSceneItem*> SceneComposedNodeItem::getChildren()
373 void SceneComposedNodeItem::removeChildFromList(AbstractSceneItem* child)
375 _children.remove(child);
378 void SceneComposedNodeItem::reorganizeShrinkExpand() {
379 DEBTRACE("SceneComposedNodeItem::reorganizeShrinkExpand " << _expanded << " " << _label.toStdString());
380 bool isExpanding = isExpanded();
382 //update control links
383 std::list<SubjectControlLink*> lscl=dynamic_cast<SubjectNode*>(_subject)->getSubjectControlLinks();
384 for (std::list<SubjectControlLink*>::const_iterator it = lscl.begin(); it != lscl.end(); ++it) {
385 SceneLinkItem* lk = dynamic_cast<SceneLinkItem*>(QtGuiContext::getQtCurrent()->_mapOfSceneItem[*it]);
387 bool b1 = true, b2 = true;
389 SceneNodeItem* no = lk->getFromNode();
391 SceneComposedNodeItem* scni = dynamic_cast<SceneComposedNodeItem*>(no);
397 no = lk->getToNode();
399 SceneComposedNodeItem* scni = dynamic_cast<SceneComposedNodeItem*>(no);
414 shrinkExpandRecursive(isExpanding, true);
415 if (Scene::_autoComputeLinks)
417 SubjectProc* subproc = QtGuiContext::getQtCurrent()->getSubjectProc();
418 SceneItem *item = QtGuiContext::getQtCurrent()->_mapOfSceneItem[subproc];
419 SceneComposedNodeItem *proc = dynamic_cast<SceneComposedNodeItem*>(item);
420 proc->rebuildLinks();
424 void SceneComposedNodeItem::shrinkExpandRecursive(bool isExpanding, bool fromHere)
426 DEBTRACE("SceneComposedNodeItem::shrinkExpandRecursive " << isExpanding << " " << fromHere << " " << isExpanded() << " " << _label.toStdString());
429 { // ---collapsing: hide first children , then resize
430 for (list<AbstractSceneItem*>::const_iterator it=_children.begin(); it!=_children.end(); ++it)
432 SceneItem* item = dynamic_cast<SceneItem*>(*it);
433 item->shrinkExpandRecursive(false, false);
435 DEBTRACE("------------------------------- Hide " << item->getLabel().toStdString());
436 item->shrinkExpandLink(false);
439 if (_shownState == expandShown)
441 _expandedWidth = _width;
442 _expandedHeight = _height;
447 _shownState = shrinkShown;
451 _ancestorShrinked = true;
452 _shownState = shrinkHidden;
455 _width = 2*Resource::Corner_Margin + 2*Resource::DataPort_Width + Resource::Space_Margin;
456 if (_shownState == shrinkShown)
457 _height = getHeaderBottom() + Resource::Corner_Margin;
459 _height = Resource::Header_Height + Resource::Corner_Margin;
461 if (_shownState == shrinkHidden) // shrink of ancestor
464 setPos(_expandedPos);
468 { // --- expanding: resize, then show children
469 _ancestorShrinked = false;
471 for (list<AbstractSceneItem*>::const_iterator it=_children.begin(); it!=_children.end(); ++it)
473 SceneItem* item = dynamic_cast<SceneItem*>(*it);
474 item->shrinkExpandRecursive(isExpanded(), false);
478 DEBTRACE("------------------------------- Show " << item->getLabel().toStdString());
483 DEBTRACE("------------------------------- Hide " << item->getLabel().toStdString());
485 item->shrinkExpandLink(fromHere);
490 _width = _expandedWidth;
491 _height = _expandedHeight;
492 _shownState = expandShown;
496 _shownState = shrinkShown;
497 _width = 2*Resource::Corner_Margin + 2*Resource::DataPort_Width + Resource::Space_Margin;
498 _height = getHeaderBottom() + Resource::Corner_Margin;
500 setPos(_expandedPos);
505 void SceneComposedNodeItem::shrinkExpandLink(bool se) {
506 DEBTRACE("SceneComposedNodeItem::shrinkExpandLink " << se << " " << _label.toStdString());
507 se = se && isExpanded();
508 foreach (QGraphicsItem *child, childItems()) {
509 if (SceneItem *sci = dynamic_cast<SceneItem*>(child)) {
510 sci->shrinkExpandLink(se);
515 void SceneComposedNodeItem::reorganize()
517 DEBTRACE("SceneComposedNodeItem::reorganize() " << _label.toStdString());
518 list<AbstractSceneItem*> alreadySet;
519 for (list<AbstractSceneItem*>::const_iterator it=_children.begin(); it!=_children.end(); ++it)
521 autoPosNewChild(*it, alreadySet);
522 alreadySet.push_back(*it);
526 void SceneComposedNodeItem::setShownState(shownState ss)
529 if (_shownState == shrinkHidden)
531 _ancestorShrinked = true;
536 _ancestorShrinked = false;
542 void SceneComposedNodeItem::collisionResolv(SceneItem* child, QPointF oldPos)
544 //DEBTRACE("SceneComposedNodeItem::collisionResolv " << _label.toStdString());
545 for (list<AbstractSceneItem*>::const_iterator it=_children.begin(); it!=_children.end(); ++it)
547 SceneNodeItem *other = dynamic_cast<SceneNodeItem*>(*it);
548 if (other && (other != child))
550 if (child->collidesWithItem(other))
552 //DEBTRACE("collision detected with " << other->getLabel().toStdString());
553 QRectF otherBR = (other->mapToParent(other->boundingRect())).boundingRect();
554 qreal oldX = oldPos.x();
555 qreal oldY = oldPos.y();
556 qreal newX = child->pos().x();
557 qreal newY = child->pos().y();
558 qreal othX = otherBR.left()+0.5;
559 qreal othY = otherBR.top()+0.5;
560 //DEBTRACE("oldX=" << oldX << " oldY=" << oldY << " newX=" << newX << " newY=" << newY);
561 //DEBTRACE("otherLeft=" << otherBR.left() << " otherRight=" << otherBR.right() <<
562 // " otherTop=" << otherBR.top() << " otherBottom=" << otherBR.bottom());
563 //DEBTRACE("width=" << child->boundingRect().width() <<
564 // " height=" << child->boundingRect().height());
565 bool fromTop = (((oldY + child->boundingRect().height()) <= otherBR.top()+1) &&
566 ((newY + child->boundingRect().height()) >= otherBR.top()));
567 bool fromBottom = (( oldY >= otherBR.bottom()) &&
568 ( newY <= otherBR.bottom()));
569 bool fromRight = (( oldX >= otherBR.right()) &&
570 ( newX <= otherBR.right()));
571 bool fromLeft = (((oldX+ child->boundingRect().width()) <= otherBR.left()+1) &&
572 ((newX+ child->boundingRect().width()) >= otherBR.left()));
573 //DEBTRACE("fromTop=" << fromTop << " fromBottom=" << fromBottom
574 // << " fromRight=" << fromRight << " fromLeft=" << fromLeft);
575 bool pushOther =false;
576 bool blocThis = false;
579 othY = newY + child->boundingRect().height();
581 other->_blocY = false;
585 othX = newX+ child->boundingRect().width();
587 other->_blocX = false;
593 newY = otherBR.bottom() + 1;
599 othY = newY - otherBR.height();
600 if ( othY < Resource::Space_Margin + getHeaderBottom() )
602 othY = Resource::Space_Margin + getHeaderBottom();
603 other->_blocY = true;
604 newY = otherBR.bottom() + 1;
616 newX = otherBR.right()+ 1;
622 othX = newX - otherBR.width();
623 if (othX < Resource::Space_Margin)
625 othX = Resource::Space_Margin;
626 other->_blocX = true;
627 newX = otherBR.right()+ 1;
635 //DEBTRACE("newX=" << newX << " newY=" << newY);
636 if (blocThis) child->setTopLeft(QPointF(newX, newY));
639 other->setTopLeft(QPointF(othX, othY));
646 void SceneComposedNodeItem::rebuildLinks()
648 DEBTRACE("SceneComposedNodeItem::rebuildLinks " << QtGuiContext::_delayCalc);
649 if (QtGuiContext::_delayCalc)
653 LinkMatrix matrix(this);
657 list<linkdef> alist = matrix.getListOfDataLinkDef();
658 list<linkdef> blist = matrix.getListOfCtrlLinkDef(); // add list operator ?
659 for (list<linkdef>::const_iterator ii = blist.begin(); ii != blist.end(); ++ii)
660 alist.push_back(*ii);
664 LinkAStar astar(matrix);
665 for (list<linkdef>::const_iterator it = alist.begin(); it != alist.end(); ++it)
668 DEBTRACE("from("<<ali.from.first<<","<<ali.from.second
669 <<") to ("<<ali.to.first<<","<<ali.to.second
670 <<") " << ali.item->getLabel().toStdString());
671 if(ali.from.first<0||ali.from.second<0||ali.to.first<0||ali.to.second<0) continue;
673 bool isPath = astar.computePath(LNode(ali.from), LNode(ali.to));
676 if (! isPath) DEBTRACE("Link Path not found !");
677 if (! isPath) continue;
678 LNodePath ijPath = astar.givePath();
679 if(Scene::_addRowCols)
680 matrix.incrementCost(ijPath);
681 LinkPath apath = matrix.getPath(ijPath);
682 // DEBTRACE(apath.size());
685 ali.item->setPath(apath);
689 void SceneComposedNodeItem::arrangeNodes(bool isRecursive)
691 DEBTRACE("SceneComposedItem::arrangeNodes " << isRecursive);
693 bool isExtern = !QtGuiContext::_delayCalc;
694 QtGuiContext::_delayCalc = true; // avoid rebuildLinks
696 SubjectComposedNode *scnode = dynamic_cast<SubjectComposedNode*>(getSubject());
698 ComposedNode *cnode = dynamic_cast<ComposedNode*>(scnode->getNode());
703 list<Node*> children = cnode->edGetDirectDescendants();
704 for (list<Node*>::iterator it = children.begin(); it != children.end(); ++it)
706 DEBTRACE("child " << (*it)->getName());
707 SceneComposedNodeItem *scni = 0;
708 ComposedNode *cchild = dynamic_cast<ComposedNode*>(*it);
711 SubjectNode* sn = GuiContext::getCurrent()->_mapOfSubjectNode[cchild];
712 SceneItem* sci = QtGuiContext::getQtCurrent()->_mapOfSceneItem[sn];
713 if (sci) scni = dynamic_cast<SceneComposedNodeItem*>(sci);
715 if (scni && (scni->getShownState() == expandShown))
717 DEBTRACE("call arrangeNode on child " << (*it)->getName());
718 scni->arrangeNodes(isRecursive);
728 QtGuiContext::_delayCalc = false; // allow rebuildLinks
729 if (Scene::_autoComputeLinks)
734 void SceneComposedNodeItem::arrangeChildNodes()
739 void SceneComposedNodeItem::dragEnterEvent(QGraphicsSceneDragDropEvent *event)
741 bool accepted = false;
742 const ItemMimeData *myData = dynamic_cast<const ItemMimeData*>(event->mimeData());
745 if (myData->hasFormat("yacs/cataService") ||
746 myData->hasFormat("yacs/cataNode") ||
747 myData->hasFormat("yacs/subjectNode"))
749 event->setAccepted(true);
751 QGraphicsItem::update();
755 event->setAccepted(accepted);
758 void SceneComposedNodeItem::dragLeaveEvent(QGraphicsSceneDragDropEvent *event)
762 QGraphicsItem::update();
765 void SceneComposedNodeItem::dropEvent(QGraphicsSceneDragDropEvent *event)
769 QGraphicsItem::update();
771 const ItemMimeData *myData = dynamic_cast<const ItemMimeData*>(event->mimeData());
773 setEventPos(event->scenePos());
774 if (myData->hasFormat("yacs/cataService") || myData->hasFormat("yacs/cataNode"))
776 SubjectComposedNode *cnode = dynamic_cast<SubjectComposedNode*>(getSubject());
777 bool createNewComponentInstance=Resource::COMPONENT_INSTANCE_NEW;
778 // by default getControl gives false. In this case we use the user preference COMPONENT_INSTANCE_NEW
779 // to create the node. If getControl gives true we invert the user preference
780 if(myData->getControl())
781 createNewComponentInstance=!Resource::COMPONENT_INSTANCE_NEW;
782 QtGuiContext::getQtCurrent()->getGMain()->_guiEditor->CreateNodeFromCatalog(myData, cnode,createNewComponentInstance);
784 else if(myData->hasFormat("yacs/subjectNode"))
786 Subject *sub = myData->getSubject();
788 SubjectNode *node = dynamic_cast<SubjectNode*>(sub);
790 if (dynamic_cast<SubjectProc*>(node)) return; // --- do not reparent proc !
791 SubjectComposedNode *cnode = dynamic_cast<SubjectComposedNode*>(getSubject());
793 if (!node->reparent(cnode))
798 QColor SceneComposedNodeItem::getPenColor()
801 return Resource::dragOver;
808 QColor SceneComposedNodeItem::getBrushColor()
811 return _hiBrushColor;
815 color = _hiBrushColor;
816 else if (_emphasized)
817 color = Resource::emphasizeBrushColor;
822 color = hoverColor(color);
826 void SceneComposedNodeItem::updateChildItems()
828 SceneNodeItem::updateChildItems();
831 foreach (QGraphicsItem *child, _header->childItems())
833 if (SceneItem *sci = dynamic_cast<SceneItem*>(child))