1 // SUPERV SUPERVGUI : GUI for Supervisor component
3 // Copyright (C) 2003 CEA/DEN, EDF R&D
7 // File : SUPERVGUI_CanvasView.cxx
8 // Author : Natalia KOPNOVA
11 #include "SUPERVGUI.h"
12 #include "SUPERVGUI_CanvasView.h"
13 #include "SUPERVGUI_Main.h"
14 #include "SUPERVGUI_CanvasNode.h"
15 #include "SUPERVGUI_CanvasPort.h"
16 #include "SUPERVGUI_CanvasLink.h"
17 #include "SUPERVGUI_CanvasNodePrs.h"
18 #include "SUPERVGUI_Clipboard.h"
20 #include "SUPERVGUI_ArrayView.h" //for tooltip testing
22 #include "SUIT_MessageBox.h"
25 #include <qcolordialog.h>
31 const char* imageZoomCursor[] = {
36 "................................",
37 "................................",
38 ".#######........................",
39 "..aaaaaaa.......................",
40 "................................",
41 ".............#####..............",
42 "...........##.aaaa##............",
43 "..........#.aa.....a#...........",
44 ".........#.a.........#..........",
45 ".........#a..........#a.........",
46 "........#.a...........#.........",
47 "........#a............#a........",
48 "........#a............#a........",
49 "........#a............#a........",
50 "........#a............#a........",
51 ".........#...........#.a........",
52 ".........#a..........#a.........",
53 ".........##.........#.a.........",
54 "........#####.....##.a..........",
55 ".......###aaa#####.aa...........",
56 "......###aa...aaaaa.......#.....",
57 ".....###aa................#a....",
58 "....###aa.................#a....",
59 "...###aa...............#######..",
60 "....#aa.................aa#aaaa.",
61 ".....a....................#a....",
62 "..........................#a....",
63 "...........................a....",
64 "................................",
65 "................................",
66 "................................",
67 "................................"};
69 QPixmap zoomPix(imageZoomCursor);
70 QCursor zoom2Cursor(zoomPix);
71 QCursor handCursor(Qt::PointingHandCursor);
73 #if QT_VERSION >= 0x030005
74 QCursor pan2Cursor(Qt::SizeAllCursor);
76 QCursor pan2Cursor(SizeAllCursor);
79 SUPERVGUI_CanvasView::SUPERVGUI_CanvasView(SUPERVGUI_Canvas* theCanvas, SUPERVGUI_Main* theMain):
80 QCanvasView(theCanvas, theMain),
81 myMain(theMain), myCurrentItem(0), myHilighted(0), myLinkBuilder(0)
83 setName("CanvasView");
85 myIsPanBtnClicked = false;
86 myIsPanActivated = false;
87 myIsFitWRActivated = false;
88 myIsZoomActivated = false;
89 myIsLinkCreating = false;
95 myTimer = new QTimer(this);
96 connect(myTimer, SIGNAL(timeout()), this, SLOT(onTimeout()));
98 myPopup = new QPopupMenu(viewport());
100 const bool isEdit = myMain->isEditable();
102 myPopup->insertItem(tr("MSG_ADD_NODE"), myMain, SLOT(addNode()));
104 // Paste Node functionality
105 SUPERVGUI_Clipboard* aCB = SUPERVGUI_Clipboard::getClipboard();
106 myPasteNodeItem = myPopup->insertItem(tr("ITM_PASTE_NODE"), aCB, SLOT(pasteNode()));
108 myPopup->insertItem(tr("MSG_INS_FILE"), myMain, SLOT(insertFile()));
109 myPopup->insertSeparator();
112 QPopupMenu* aViewPopup = new QPopupMenu(viewport());
113 aViewPopup->insertItem(tr("POP_FULLVIEW"), myMain, SLOT(showCanvas()));
114 aViewPopup->insertItem(tr("POP_CONTROLVIEW"), myMain, SLOT(showContolFlow()));
115 aViewPopup->insertItem(tr("POP_TABLEVIEW"), myMain, SLOT(showCanvasTable()));
117 myPopup->insertItem(tr("POP_VIEW"), aViewPopup);
118 myPopup->insertSeparator();
120 QPopupMenu* aZoomPopup = new QPopupMenu(viewport());
121 aZoomPopup->insertItem("200%", this, SLOT(zoomIn()));
122 aZoomPopup->insertItem("100%", this, SLOT(zoomReset()));
123 aZoomPopup->insertItem("50%", this, SLOT(zoomOut()));
124 aZoomPopup->insertSeparator();
125 //mkr: "Fit within rectangle" functionality
126 aZoomPopup->insertItem(tr("POP_FITWITHINRECT"), this, SLOT(fitWithinRect()));
127 aZoomPopup->insertSeparator();
128 aZoomPopup->insertItem(tr("POP_FITALL"), this, SLOT(fitAll()));
131 myPopup->insertItem(tr("POP_ZOOM"), aZoomPopup);
132 myPopup->insertSeparator();
134 myAddStudyItem = myPopup->insertItem(tr("MSG_ADD_STUDY"), myMain, SLOT(addDataflowToStudy()));
135 myPopup->insertItem(tr(isEdit ? "MSG_CHANGE_INFO" : "MSG_INFO"), myMain, SLOT(changeInformation()));
136 myPopup->insertSeparator();
138 myPopup->insertItem(tr("MSG_COPY_DATAFLOW"), myMain, SLOT(copy()));
139 myPopup->insertItem(tr("MSG_FILTER_NOTIFY"), myMain, SLOT(filterNotification()));
141 myPopup->insertSeparator();
142 myPopup->insertItem(tr("MSG_CHANGE_BACKGROUND"), this, SLOT(changeBackground()));
144 viewport()->setMouseTracking(true);
146 //create sketching popup menu
147 mySketchPopup = new QPopupMenu(viewport());
148 mySketchPopup->setCheckable(true);
149 myDelPntItem = mySketchPopup->insertItem(tr("MSG_DEL_LAST_PNT"), this, SLOT(deletePoint()));
150 mySketchPopup->insertItem(tr("MSG_DEL_LINK"), this, SLOT(cancelSketch()));
151 myOrtoItem = mySketchPopup->insertItem(tr("MSG_ORTHO_LINE"), this, SLOT(setOrthoMode()));
154 // add "change dataflow parameters" popup item
155 myPopup->insertSeparator();
156 myDSParamsItem = myPopup->insertItem( tr( "MSG_SET_GRAPHPARAMS" ), myMain, SLOT( changeDSGraphParameters() ) );
158 SUPERVGraph_ViewFrame* anActiveVF = (SUPERVGraph_ViewFrame*)myMain->parent();
160 myPopup->insertSeparator();
161 myShowToolBarItem = myPopup->insertItem( tr( "MEN_SHOW_TOOLBAR" ), myMain, SLOT( onShowToolbar() ) );
165 connect(this, SIGNAL(objectCreated()), myMain, SLOT(onObjectCreatedDeleted()));
169 SUPERVGUI_CanvasView::~SUPERVGUI_CanvasView()
171 SUPERVGUI_Clipboard::setNullClipboard();
174 void SUPERVGUI_CanvasView::contentsMousePressEvent(QMouseEvent* theEvent)
176 myPoint = inverseWorldMatrix().map(theEvent->pos());
177 myGlobalPoint = theEvent->globalPos();
180 // compute collision rectangle
181 QRect aSel(myPoint.x()-MARGIN, myPoint.y()-MARGIN, 1+2*MARGIN, 1+2*MARGIN);
183 if (((theEvent->button() == Qt::MidButton) &&
184 (theEvent->state() == Qt::ControlButton)) ||
186 myIsPanActivated = true;
188 setCursor(pan2Cursor);
192 if (((theEvent->button() == Qt::LeftButton) &&
193 (theEvent->state() == Qt::ControlButton)) ||
195 myIsZoomActivated = true;
197 setCursor(zoom2Cursor);
201 if ( theEvent->button() == Qt::RightButton) {
202 if (myIsLinkCreating) {
203 myMain->showPopup(mySketchPopup, theEvent);
207 QCanvasItemList l = canvas()->collisions(aSel);
208 for (QCanvasItemList::Iterator it = l.begin(); it != l.end(); ++it) {
209 if ((*it)->rtti() == SUPERVGUI_Canvas::Rtti_Node) {
210 SUPERVGUI_CanvasNodePrs* aNodePrs = (SUPERVGUI_CanvasNodePrs*) (*it);
211 QObject* anObj = aNodePrs->getObject(myPoint);
212 if (anObj->inherits("SUPERVGUI_CanvasNode")) {
213 myMain->showPopup(((SUPERVGUI_CanvasNode*)anObj)->getPopupMenu(viewport()),
217 else if (anObj->inherits("SUPERVGUI_CanvasPort")) {
218 myMain->showPopup(((SUPERVGUI_CanvasPort*)anObj)->getPopupMenu(viewport()),
223 if (myMain->isEditable() && !myMain->getCanvas()->isControlView()) {
224 if ((*it)->rtti() == SUPERVGUI_Canvas::Rtti_LinkPoint) {
225 SUPERVGUI_CanvasPointPrs* aPrs = (SUPERVGUI_CanvasPointPrs*) (*it);
226 aPrs->getLink()->setSelectedObject(aPrs, myPoint);
227 myMain->showPopup(aPrs->getLink()->getPopupMenu(viewport()), theEvent);
230 if ((*it)->rtti() == SUPERVGUI_Canvas::Rtti_LinkEdge) {
231 SUPERVGUI_CanvasEdgePrs* aPrs = (SUPERVGUI_CanvasEdgePrs*) (*it);
232 aPrs->getLink()->setSelectedObject(aPrs, myPoint);
233 myMain->showPopup(aPrs->getLink()->getPopupMenu(viewport()), theEvent);
239 myPopup->setItemEnabled(myAddStudyItem, !myMain->isDataflowInStudy());
240 // Paste Node functionality
241 SUPERVGUI_Clipboard* aCB = SUPERVGUI_Clipboard::getClipboard();
242 myPopup->setItemEnabled(myPasteNodeItem, aCB->isCopyNode() );
244 myPopup->setItemEnabled( myDSParamsItem, isHavingStreamPort()/*myMain->getDataflow()->IsStreamGraph()*/ );
246 myPopup->setItemEnabled( myShowToolBarItem, !((SUPERVGraph_ViewFrame*)myMain->parent())->getToolBar()->isVisible() );
248 myMain->showPopup(myPopup, theEvent);
252 if (theEvent->button() == Qt::LeftButton) {
253 if (!myIsFitWRActivated) {//not moving items if fit within rectangle
254 //functionality is enable
255 QCanvasItemList l = canvas()->collisions(myPoint);
256 if (myIsLinkCreating) {
257 for (QCanvasItemList::Iterator it = l.begin(); it != l.end(); ++it) {
258 if ((*it)->rtti() == SUPERVGUI_Canvas::Rtti_Node) {
259 SUPERVGUI_CanvasNodePrs* aNodePrs = (SUPERVGUI_CanvasNodePrs*) (*it);
260 QObject* anObj = aNodePrs->getObject(myPoint);
261 if (anObj->inherits("SUPERVGUI_CanvasPort")) {
262 endSketch((SUPERVGUI_CanvasPort*)anObj);
267 ((SUPERVGUI_CanvasNodePrs*)myCurrentItem)->setZ(2);
268 ((SUPERVGUI_CanvasNodePrs*)myCurrentItem)->setMoving(true);
272 if ((*it)->rtti() == SUPERVGUI_Canvas::Rtti_Hook) {
273 SUPERVGUI_CanvasHookPrs* aHookPrs = (SUPERVGUI_CanvasHookPrs*) (*it);
274 QObject* anObj = aHookPrs->getObject();
275 if (anObj->inherits("SUPERVGUI_CanvasPort")) {
276 endSketch((SUPERVGUI_CanvasPort*)anObj);
282 myLinkBuilder->addNextPoint(myPoint, mySketchPopup->isItemChecked(myOrtoItem));
284 mySketchPopup->setItemEnabled(myDelPntItem, true);
289 // if (myMain->isEditable()) { // allow to move nodes and link point on imported graph
290 for (QCanvasItemList::Iterator it = l.begin(); it != l.end(); ++it) {
291 if ((*it)->rtti() == SUPERVGUI_Canvas::Rtti_Node) {
293 ((SUPERVGUI_CanvasNodePrs*)myCurrentItem)->setZ(2);
294 ((SUPERVGUI_CanvasNodePrs*)myCurrentItem)->setMoving(true);
297 if ((*it)->rtti() == SUPERVGUI_Canvas::Rtti_LinkPoint) {
298 SUPERVGUI_CanvasPointPrs* aPrs = (SUPERVGUI_CanvasPointPrs*) (*it);
299 if (aPrs->getIndex() > 0) {
301 aPrs->setMoving(true);
305 if ((*it)->rtti() == SUPERVGUI_Canvas::Rtti_LinkEdge) {
306 //mkr: for moving segment of link
307 SUPERVGUI_CanvasEdgePrs* aPrs = (SUPERVGUI_CanvasEdgePrs*) (*it);
308 if (aPrs->getLink()->getInputPort()->getConnectionPoint() == aPrs->startPoint()
310 aPrs->getLink()->getInputPort()->getConnectionPoint() == aPrs->endPoint()
312 aPrs->getLink()->getOutputPort()->getConnectionPoint() == aPrs->startPoint()
314 aPrs->getLink()->getOutputPort()->getConnectionPoint() == aPrs->endPoint()) {
318 aPrs->setMoving(true);
329 void SUPERVGUI_CanvasView::contentsMouseMoveEvent(QMouseEvent* theEvent)
334 QPoint p = inverseWorldMatrix().map(theEvent->pos());
335 QPoint g = theEvent->globalPos();
337 if (myTimer->isActive()) myTimer->stop();
339 if (myIsLinkCreating && myLinkBuilder) {
340 myLinkBuilder->setFloatPoint(p);
346 if (myCurrentItem->x() && myCurrentItem->y()) {
347 double cx = myCurrentItem->x() - myPoint.x();
348 double cy = myCurrentItem->y() - myPoint.y();
350 if (p.x()+cx < 0) p.setX(-(int)cx);
351 if (p.y()+cy < 0) p.setY(-(int)cy);
353 myCurrentItem->moveBy(p.x() - myPoint.x(),
354 p.y() - myPoint.y());
358 // scroll contents if mouse is outside
359 QRect r(contentsX(), contentsY(), visibleWidth(), visibleHeight());
360 if (!r.contains(theEvent->pos())) {
362 if (theEvent->pos().x() < r.left()) dx = theEvent->pos().x() - r.left();
363 if (theEvent->pos().x() > r.right()) dx = theEvent->pos().x() - r.right();
364 if (theEvent->pos().y() < r.top()) dy = theEvent->pos().y() - r.top();
365 if (theEvent->pos().y() > r.bottom()) dy = theEvent->pos().y() - r.bottom();
367 // start timer to scroll in silent mode
368 myDX = dx; myDY = dy;
375 if (myIsPanActivated) {
377 scrollBy(myGlobalPoint.x() - g.x(),
378 myGlobalPoint.y() - g.y());
384 if (myIsZoomActivated) {
386 double dx = g.x() - myGlobalPoint.x();
387 double s = 1. + fabs(dx)/10.;
388 if (dx < 0) s = 1./s;
390 QWMatrix m = worldMatrix();
399 //mkr: "Fit within rectangle" functionality
400 if (myIsFitWRActivated) {
401 int aLX, aTY; //left x and top y
402 if (myPoint.x() < p.x()) aLX = myPoint.x();
404 if (myPoint.y() < p.y()) aTY = myPoint.y();
406 QRect aRect(aLX, aTY, abs(myPoint.x()-p.x()), abs(myPoint.y()-p.y()));
407 QCanvasRectangle* aRect1 = new QCanvasRectangle(aRect, canvas());
409 //hide old selected rectangle
411 mySelectedRect->hide();
412 //draw new selected rectangle
413 QPen pen(Qt::SolidLine);
419 mySelectedRect = aRect1;
423 if (!myIsLinkCreating && myMain->isEditable() &&
424 !myMain->getCanvas()->isControlView()) {
425 // compute collision rectangle
426 QRect aSel(p.x()-MARGIN, p.y()-MARGIN, 1+2*MARGIN, 1+2*MARGIN);
427 QCanvasItemList l = canvas()->collisions(aSel);
428 for (QCanvasItemList::Iterator it = l.begin(); it != l.end(); ++it) {
429 if ((*it)->rtti() == SUPERVGUI_Canvas::Rtti_LinkPoint) {
430 SUPERVGUI_CanvasPointPrs* aPrs = (SUPERVGUI_CanvasPointPrs*) (*it);
431 setHilighted(aPrs->getLink());
435 if ((*it)->rtti() == SUPERVGUI_Canvas::Rtti_LinkEdge) {
436 SUPERVGUI_CanvasEdgePrs* aPrs = (SUPERVGUI_CanvasEdgePrs*) (*it);
437 setHilighted(aPrs->getLink());
445 // QToolTip for title and label for SUPERVGUI_CanvasNode
446 SUPERVGUI_ToolTip* aTT = new SUPERVGUI_ToolTip(this);
452 void SUPERVGUI_CanvasView::contentsMouseReleaseEvent(QMouseEvent* theEvent)
454 if (myTimer->isActive()) myTimer->stop();
457 if (myCurrentItem->rtti() == SUPERVGUI_Canvas::Rtti_Node) {
458 ((SUPERVGUI_CanvasNodePrs*)myCurrentItem)->setZ(0);
459 ((SUPERVGUI_CanvasNodePrs*)myCurrentItem)->setMoving(false);
462 if (myCurrentItem->rtti() == SUPERVGUI_Canvas::Rtti_LinkPoint) {
463 ((SUPERVGUI_CanvasPointPrs*)myCurrentItem)->setMoving(false);
468 if (myIsPanActivated) {
469 myIsPanActivated = false;
470 myIsPanBtnClicked = false;
474 if (myIsZoomActivated) {
475 myIsZoomActivated = false;
479 //mkr: "Fit within rectangle" functionality
480 if (myIsFitWRActivated) {
481 if (mySelectedRect) {
482 mySelectedRect->hide();
487 //myPoint is the start point for selecting rectangle now
488 QPoint anEndPoint = inverseWorldMatrix().map(theEvent->pos());
489 int aLX, aTY; //left x and top y
490 if (myPoint.x() < anEndPoint.x()) aLX = myPoint.x();
491 else aLX = anEndPoint.x();
492 if (myPoint.y() < anEndPoint.y()) aTY = myPoint.y();
493 else aTY = anEndPoint.y();
495 //calculate width and height for new view and new zoom factor
496 double aXzoom = ((double)visibleWidth())/((double)(abs(myPoint.x()-anEndPoint.x())));
497 double aYzoom = ((double)visibleHeight())/((double)(abs(myPoint.y()-anEndPoint.y())));
498 if (aXzoom > aYzoom) aXzoom = aYzoom;
501 m.scale(aXzoom, aXzoom);
503 setContentsPos((int)(aLX*aXzoom), (int)(aTY*aYzoom));
507 myIsFitWRActivated = false;
508 viewport()->setMouseTracking(true);
513 void SUPERVGUI_CanvasView::contentsMouseDoubleClickEvent(QMouseEvent* theEvent)
515 QPoint p = inverseWorldMatrix().map(theEvent->pos());
517 // compute collision rectangle
518 //QRect aSel(p.x()-MARGIN, p.y()-MARGIN, 1+2*MARGIN, 1+2*MARGIN);
520 if (theEvent->button() == Qt::LeftButton) {
521 QCanvasItemList l = canvas()->collisions(p);
522 for (QCanvasItemList::Iterator it = l.begin(); it != l.end(); ++it) {
523 if ((*it)->rtti() == SUPERVGUI_Canvas::Rtti_Node) {
524 SUPERVGUI_CanvasNodePrs* aNodePrs = (SUPERVGUI_CanvasNodePrs*) (*it);
525 SUPERVGUI_CanvasNode* aNode = aNodePrs->getNode();
526 if (aNode->getEngine()->IsMacro() && !myIsLinkCreating) {
527 myMain->openSubGraph(aNode->getEngine(), true);
535 void SUPERVGUI_CanvasView::onDestroyed(QObject* theObject)
537 if (theObject == myHilighted)
541 void SUPERVGUI_CanvasView::setHilighted(SUPERVGUI_CanvasLink* theLink)
543 if (theLink == myHilighted) return;
545 disconnect(myHilighted, SIGNAL(destroyed(QObject*)), this, SLOT(onDestroyed(QObject*)));
546 myHilighted->setHilighted(false);
550 myHilighted = theLink;
551 myHilighted->setHilighted(true);
552 connect(myHilighted, SIGNAL(destroyed(QObject*)), this, SLOT(onDestroyed(QObject*)));
556 void SUPERVGUI_CanvasView::onTimeout()
559 scrollBy(myDX, myDY);
562 inverseWorldMatrix().map((double)myDX, (double)myDY, &cx, &cy);
563 if (myCurrentItem->x()+cx < 0) cx = -myCurrentItem->x();
564 if (myCurrentItem->y()+cy < 0) cy = -myCurrentItem->y();
565 myCurrentItem->moveBy(cx, cy);
566 myPoint.setX(myPoint.x()+(int)cx);
567 myPoint.setY(myPoint.y()+(int)cy);
572 void SUPERVGUI_CanvasView::changeBackground()
574 QColor aColor = QColorDialog::getColor(canvas()->backgroundColor(), this );
575 if ( aColor.isValid() ) {
576 // change background color for canvas view
577 canvas()->setBackgroundColor(aColor);
578 setPaletteBackgroundColor(aColor.light(120));
579 // change background color for array view
580 getMain()->getArrayView()->canvas()->setBackgroundColor(aColor);
581 getMain()->getArrayView()->setPaletteBackgroundColor(aColor.light(120));
583 // mkr : IPAL10825 -->
584 SUPERVGUI* aSupMod = SUPERVGUI::Supervision();
586 MESSAGE("NULL Supervision module!");
589 aSupMod->setIVFBackgroundColor(aColor);
594 void SUPERVGUI_CanvasView::ActivatePanning()
596 myIsPanBtnClicked = true;
599 void SUPERVGUI_CanvasView::ResetView()
606 void SUPERVGUI_CanvasView::startSketch(SUPERVGUI_CanvasPort* thePort)
608 if (myIsLinkCreating) return;
610 myIsLinkCreating = true;
611 myLinkBuilder = new SUPERVGUI_CanvasLinkBuilder(canvas(), myMain, thePort);
612 mySketchPopup->setItemEnabled(myDelPntItem, false);
615 void SUPERVGUI_CanvasView::endSketch(SUPERVGUI_CanvasPort* thePort)
617 if (!myIsLinkCreating) return;
619 if (myLinkBuilder && myLinkBuilder->canCreateEngine(thePort)) {
620 bool input = thePort->getEngine()->IsInput();
621 SUPERV_Link aLinkEngine;
622 if (thePort->getEngine()->Kind() == SUPERV::DataStreamParameter) {
623 SUPERVGUI_CanvasStreamPortIn* aInPort = (SUPERVGUI_CanvasStreamPortIn*)
624 (input ? thePort : myLinkBuilder->getStartPort());
625 SUPERVGUI_CanvasStreamPortOut* aOutPort = (SUPERVGUI_CanvasStreamPortOut*)
626 (input ? myLinkBuilder->getStartPort() : thePort);
627 // aLinkEngine = myMain->getDataflow()->StreamLink(aOutPort->getStreamEngine(),
628 // aInPort->getStreamEngine());
629 if (myMain->getDataflow()->IsStreamGraph()) {
630 SUPERV_StreamGraph aSGraph = myMain->getDataflow()->ToStreamGraph();
631 if (!SUPERV_isNull(aSGraph))
632 aLinkEngine = aSGraph->StreamLink(aOutPort->getStreamEngine(),
633 aInPort->getStreamEngine());
637 SUPERVGUI_CanvasPort* aInPort = (input ? thePort : myLinkBuilder->getStartPort());
638 SUPERVGUI_CanvasPort* aOutPort = (input ? myLinkBuilder->getStartPort() : thePort);
639 aLinkEngine = myMain->getDataflow()->Link(aOutPort->getEngine(), aInPort->getEngine());
641 if (SUPERV_isNull(aLinkEngine))
644 // here, in fact, aLinkEngine may NOT be a newly created link. If a link already existed between the
645 // the 2 given ports - it will be return (NOT created again).
646 // this should be checked and new presentation should NOT be created for existing link.
647 // Solution 1: NOT to allow creation of a link if it already exists between the ports in
648 // myLinkBuilder->canCreateEngine()
649 // Solution 2: check here if aLinkEngine is "new" or "old"
650 // Implement 2nd solution, because canCreateEngine() checks for types of ports, etc.. - it's another thing
652 QObjectList* canvasLinks = canvas()->queryList("SUPERVGUI_CanvasLink");
653 SUPERVGUI_CanvasLink* canvasLink = 0;
654 QObjectListIt it(*canvasLinks);
655 bool prsAlreadyExists = false;
656 while ( (canvasLink=(SUPERVGUI_CanvasLink*)it.current()) ) {
658 SUPERV_Link existingLinkWithPrs = canvasLink->getEngine();
659 if ( !SUPERV_isNull( existingLinkWithPrs ) ) {
660 if ( existingLinkWithPrs->IsEqual( aLinkEngine ) ) {
661 prsAlreadyExists = true;
667 if ( prsAlreadyExists ) { // aLinkEngine is already bound with a SUPERVGUI_CanvasLink object
668 //return; // -> if return here, than the old CanvasLink is kept
670 // we want to delete old and create a new CanvasLink for this Link
673 // clear old corrdinates in Engine link
674 for ( int i = 1; i <= aLinkEngine->CoordsSize(); i++ )
675 aLinkEngine->RemoveCoord( i );
676 // now we are ready to set coords for a link and create a new CanvasLink presentation that will use them.
679 myLinkBuilder->setCoords(aLinkEngine.in());
681 delete myLinkBuilder;
684 SUPERVGUI_CanvasLink* aLink = new SUPERVGUI_CanvasLink(canvas(), myMain, aLinkEngine);
687 emit objectCreated(); // mkr : PAL8237
690 myIsLinkCreating = false;
692 // asv : 13.12.04 : introducing a check for ports' types compatibility (Bugs and Improvements p.1.16, PAL7380)
693 if ( !aLinkEngine->IsValid() ) {
694 const int id = SUIT_MessageBox::warn2( this, tr( "TLT_INVALID_LINK" ),
695 tr( "MSG_INVALID_LINK" ) + QString(" : ") + QString(myMain->getDataflow()->Messages()),
696 tr( "Keep" ), tr( "Remove" ), 0, 1, 0 );
697 if ( id == 1 ) { // "Remove" was selected in Message Box
698 aLink->remove(); // the new link did not live long...
704 void SUPERVGUI_CanvasView::cancelSketch()
707 delete myLinkBuilder;
711 myIsLinkCreating = false;
714 void SUPERVGUI_CanvasView::deletePoint()
716 if (myIsLinkCreating && myLinkBuilder) {
717 myLinkBuilder->removeLastPoint();
719 mySketchPopup->setItemEnabled(myDelPntItem, myLinkBuilder->getPointCount());
723 void SUPERVGUI_CanvasView::setOrthoMode()
725 bool aIsOrtho = !mySketchPopup->isItemChecked(myOrtoItem);
726 mySketchPopup->setItemChecked(myOrtoItem, aIsOrtho);
729 void SUPERVGUI_CanvasView::zoomIn()
737 void SUPERVGUI_CanvasView::zoomReset()
745 void SUPERVGUI_CanvasView::zoomOut()
753 void SUPERVGUI_CanvasView::fitAll()
756 QCanvasItemList l = canvas()->allItems();
757 for (QCanvasItemList::Iterator it = l.begin(); it != l.end(); ++it) {
758 QRect r = (*it)->boundingRect();
759 if (w < r.right()) w = r.right();
760 if (h < r.bottom()) h = r.bottom();
762 w += GRAPH_MARGIN; h += GRAPH_MARGIN;
763 double s = ((double)visibleWidth())/((double)w);
764 double s1 = ((double)visibleHeight())/((double)h);
774 void SUPERVGUI_CanvasView::fitWithinRect()
776 //mkr: "Fit within rectangle" functionality
777 myIsFitWRActivated = true;
778 viewport()->setMouseTracking(false);
780 setCursor(handCursor);
783 bool SUPERVGUI_CanvasView::isHavingStreamPort() const
785 SUPERV::ListOfNodes* aNodesList = myMain->getDataflow()->Nodes();
788 for ( int i = 0 ; i < (int) aNodesList->CNodes.length() ; i++ ) {
789 SUPERV::ListOfStreamPorts aStrPortsList = *( (aNodesList->CNodes)[i]->StreamPorts() );
790 if ((int) aStrPortsList.length() > 0) {
796 for ( int i = 0 ; i < (int) aNodesList->FNodes.length() ; i++ ) {
797 SUPERV::ListOfStreamPorts aStrPortsList = *( (aNodesList->FNodes)[i]->StreamPorts() );
798 if ((int) aStrPortsList.length() > 0) {
804 for ( int i = 0 ; i < (int) aNodesList->INodes.length() ; i++ ) {
805 SUPERV::ListOfStreamPorts aStrPortsList = *( (aNodesList->INodes)[i]->StreamPorts() );
806 if ((int) aStrPortsList.length() > 0) {
812 for ( int i = 0 ; i < (int) aNodesList->GNodes.length() ; i++ ) {
813 SUPERV::ListOfStreamPorts aStrPortsList = *( (aNodesList->GNodes)[i]->StreamPorts() );
814 if ((int) aStrPortsList.length() > 0) {
820 for ( int i = 0 ; i < (int) aNodesList->LNodes.length() ; i++ ) {
821 SUPERV::ListOfStreamPorts aStrPortsList = *( (aNodesList->LNodes)[i]->StreamPorts() );
822 if ((int) aStrPortsList.length() > 0) {
828 for ( int i = 0 ; i < (int) aNodesList->SNodes.length() ; i++ ) {
829 SUPERV::ListOfStreamPorts aStrPortsList = *( (aNodesList->SNodes)[i]->StreamPorts() );
830 if ((int) aStrPortsList.length() > 0) {