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
13 #include "SUPERVGUI.h"
14 #include "SUPERVGUI_CanvasView.h"
15 #include "SUPERVGUI_Main.h"
16 #include "SUPERVGUI_CanvasNode.h"
17 #include "SUPERVGUI_CanvasPort.h"
18 #include "SUPERVGUI_CanvasLink.h"
19 #include "SUPERVGUI_CanvasNodePrs.h"
20 #include "SUPERVGUI_Clipboard.h"
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() ) );
166 SUPERVGUI_CanvasView::~SUPERVGUI_CanvasView()
168 SUPERVGUI_Clipboard::setNullClipboard();
171 void SUPERVGUI_CanvasView::contentsMousePressEvent(QMouseEvent* theEvent)
173 myPoint = inverseWorldMatrix().map(theEvent->pos());
174 myGlobalPoint = theEvent->globalPos();
177 // compute collision rectangle
178 QRect aSel(myPoint.x()-MARGIN, myPoint.y()-MARGIN, 1+2*MARGIN, 1+2*MARGIN);
180 if (((theEvent->button() == Qt::MidButton) &&
181 (theEvent->state() == Qt::ControlButton)) ||
183 myIsPanActivated = true;
185 setCursor(pan2Cursor);
189 if (((theEvent->button() == Qt::LeftButton) &&
190 (theEvent->state() == Qt::ControlButton)) ||
192 myIsZoomActivated = true;
194 setCursor(zoom2Cursor);
198 if ( theEvent->button() == Qt::RightButton) {
199 if (myIsLinkCreating) {
200 myMain->showPopup(mySketchPopup, theEvent);
204 QCanvasItemList l = canvas()->collisions(aSel);
205 for (QCanvasItemList::Iterator it = l.begin(); it != l.end(); ++it) {
206 if ((*it)->rtti() == SUPERVGUI_Canvas::Rtti_Node) {
207 SUPERVGUI_CanvasNodePrs* aNodePrs = (SUPERVGUI_CanvasNodePrs*) (*it);
208 QObject* anObj = aNodePrs->getObject(myPoint);
209 if (anObj->inherits("SUPERVGUI_CanvasNode")) {
210 myMain->showPopup(((SUPERVGUI_CanvasNode*)anObj)->getPopupMenu(viewport()),
214 else if (anObj->inherits("SUPERVGUI_CanvasPort")) {
215 myMain->showPopup(((SUPERVGUI_CanvasPort*)anObj)->getPopupMenu(viewport()),
220 if (myMain->isEditable() && !myMain->getCanvas()->isControlView()) {
221 if ((*it)->rtti() == SUPERVGUI_Canvas::Rtti_LinkPoint) {
222 SUPERVGUI_CanvasPointPrs* aPrs = (SUPERVGUI_CanvasPointPrs*) (*it);
223 aPrs->getLink()->setSelectedObject(aPrs, myPoint);
224 myMain->showPopup(aPrs->getLink()->getPopupMenu(viewport()), theEvent);
227 if ((*it)->rtti() == SUPERVGUI_Canvas::Rtti_LinkEdge) {
228 SUPERVGUI_CanvasEdgePrs* aPrs = (SUPERVGUI_CanvasEdgePrs*) (*it);
229 aPrs->getLink()->setSelectedObject(aPrs, myPoint);
230 myMain->showPopup(aPrs->getLink()->getPopupMenu(viewport()), theEvent);
236 myPopup->setItemEnabled(myAddStudyItem, !myMain->isDataflowInStudy());
237 // Paste Node functionality
238 SUPERVGUI_Clipboard* aCB = SUPERVGUI_Clipboard::getClipboard();
239 myPopup->setItemEnabled(myPasteNodeItem, aCB->isCopyNode() );
241 myPopup->setItemEnabled( myDSParamsItem, isHavingStreamPort()/*myMain->getDataflow()->IsStreamGraph()*/ );
243 myPopup->setItemEnabled( myShowToolBarItem, !((SUPERVGraph_ViewFrame*)myMain->parent())->getToolBar()->isVisible() );
245 myMain->showPopup(myPopup, theEvent);
249 if (theEvent->button() == Qt::LeftButton) {
250 if (!myIsFitWRActivated) {//not moving items if fit within rectangle
251 //functionality is enable
252 QCanvasItemList l = canvas()->collisions(myPoint);
253 if (myIsLinkCreating) {
254 for (QCanvasItemList::Iterator it = l.begin(); it != l.end(); ++it) {
255 if ((*it)->rtti() == SUPERVGUI_Canvas::Rtti_Node) {
256 SUPERVGUI_CanvasNodePrs* aNodePrs = (SUPERVGUI_CanvasNodePrs*) (*it);
257 QObject* anObj = aNodePrs->getObject(myPoint);
258 if (anObj->inherits("SUPERVGUI_CanvasPort")) {
259 endSketch((SUPERVGUI_CanvasPort*)anObj);
264 ((SUPERVGUI_CanvasNodePrs*)myCurrentItem)->setZ(2);
265 ((SUPERVGUI_CanvasNodePrs*)myCurrentItem)->setMoving(true);
269 if ((*it)->rtti() == SUPERVGUI_Canvas::Rtti_Hook) {
270 SUPERVGUI_CanvasHookPrs* aHookPrs = (SUPERVGUI_CanvasHookPrs*) (*it);
271 QObject* anObj = aHookPrs->getObject();
272 if (anObj->inherits("SUPERVGUI_CanvasPort")) {
273 endSketch((SUPERVGUI_CanvasPort*)anObj);
279 myLinkBuilder->addNextPoint(myPoint, mySketchPopup->isItemChecked(myOrtoItem));
281 mySketchPopup->setItemEnabled(myDelPntItem, true);
286 // if (myMain->isEditable()) { // allow to move nodes and link point on imported graph
287 for (QCanvasItemList::Iterator it = l.begin(); it != l.end(); ++it) {
288 if ((*it)->rtti() == SUPERVGUI_Canvas::Rtti_Node) {
290 ((SUPERVGUI_CanvasNodePrs*)myCurrentItem)->setZ(2);
291 ((SUPERVGUI_CanvasNodePrs*)myCurrentItem)->setMoving(true);
294 if ((*it)->rtti() == SUPERVGUI_Canvas::Rtti_LinkPoint) {
295 SUPERVGUI_CanvasPointPrs* aPrs = (SUPERVGUI_CanvasPointPrs*) (*it);
296 if (aPrs->getIndex() > 0) {
298 aPrs->setMoving(true);
302 if ((*it)->rtti() == SUPERVGUI_Canvas::Rtti_LinkEdge) {
303 //mkr: for moving segment of link
304 SUPERVGUI_CanvasEdgePrs* aPrs = (SUPERVGUI_CanvasEdgePrs*) (*it);
305 if (aPrs->getLink()->getInputPort()->getConnectionPoint() == aPrs->startPoint()
307 aPrs->getLink()->getInputPort()->getConnectionPoint() == aPrs->endPoint()
309 aPrs->getLink()->getOutputPort()->getConnectionPoint() == aPrs->startPoint()
311 aPrs->getLink()->getOutputPort()->getConnectionPoint() == aPrs->endPoint()) {
315 aPrs->setMoving(true);
326 void SUPERVGUI_CanvasView::contentsMouseMoveEvent(QMouseEvent* theEvent)
331 QPoint p = inverseWorldMatrix().map(theEvent->pos());
332 QPoint g = theEvent->globalPos();
334 if (myTimer->isActive()) myTimer->stop();
336 if (myIsLinkCreating && myLinkBuilder) {
337 myLinkBuilder->setFloatPoint(p);
343 if (myCurrentItem->x() && myCurrentItem->y()) {
344 double cx = myCurrentItem->x() - myPoint.x();
345 double cy = myCurrentItem->y() - myPoint.y();
347 if (p.x()+cx < 0) p.setX(-(int)cx);
348 if (p.y()+cy < 0) p.setY(-(int)cy);
350 myCurrentItem->moveBy(p.x() - myPoint.x(),
351 p.y() - myPoint.y());
355 // scroll contents if mouse is outside
356 QRect r(contentsX(), contentsY(), visibleWidth(), visibleHeight());
357 if (!r.contains(theEvent->pos())) {
359 if (theEvent->pos().x() < r.left()) dx = theEvent->pos().x() - r.left();
360 if (theEvent->pos().x() > r.right()) dx = theEvent->pos().x() - r.right();
361 if (theEvent->pos().y() < r.top()) dy = theEvent->pos().y() - r.top();
362 if (theEvent->pos().y() > r.bottom()) dy = theEvent->pos().y() - r.bottom();
364 // start timer to scroll in silent mode
365 myDX = dx; myDY = dy;
372 if (myIsPanActivated) {
374 scrollBy(myGlobalPoint.x() - g.x(),
375 myGlobalPoint.y() - g.y());
381 if (myIsZoomActivated) {
383 double dx = g.x() - myGlobalPoint.x();
384 double s = 1. + fabs(dx)/10.;
385 if (dx < 0) s = 1./s;
387 QWMatrix m = worldMatrix();
396 //mkr: "Fit within rectangle" functionality
397 if (myIsFitWRActivated) {
398 int aLX, aTY; //left x and top y
399 if (myPoint.x() < p.x()) aLX = myPoint.x();
401 if (myPoint.y() < p.y()) aTY = myPoint.y();
403 QRect aRect(aLX, aTY, abs(myPoint.x()-p.x()), abs(myPoint.y()-p.y()));
404 QCanvasRectangle* aRect1 = new QCanvasRectangle(aRect, canvas());
406 //hide old selected rectangle
408 mySelectedRect->hide();
409 //draw new selected rectangle
410 QPen pen(Qt::SolidLine);
416 mySelectedRect = aRect1;
420 if (!myIsLinkCreating && myMain->isEditable() &&
421 !myMain->getCanvas()->isControlView()) {
422 // compute collision rectangle
423 QRect aSel(p.x()-MARGIN, p.y()-MARGIN, 1+2*MARGIN, 1+2*MARGIN);
424 QCanvasItemList l = canvas()->collisions(aSel);
425 for (QCanvasItemList::Iterator it = l.begin(); it != l.end(); ++it) {
426 if ((*it)->rtti() == SUPERVGUI_Canvas::Rtti_LinkPoint) {
427 SUPERVGUI_CanvasPointPrs* aPrs = (SUPERVGUI_CanvasPointPrs*) (*it);
428 setHilighted(aPrs->getLink());
432 if ((*it)->rtti() == SUPERVGUI_Canvas::Rtti_LinkEdge) {
433 SUPERVGUI_CanvasEdgePrs* aPrs = (SUPERVGUI_CanvasEdgePrs*) (*it);
434 setHilighted(aPrs->getLink());
445 void SUPERVGUI_CanvasView::contentsMouseReleaseEvent(QMouseEvent* theEvent)
447 if (myTimer->isActive()) myTimer->stop();
450 if (myCurrentItem->rtti() == SUPERVGUI_Canvas::Rtti_Node) {
451 ((SUPERVGUI_CanvasNodePrs*)myCurrentItem)->setZ(0);
452 ((SUPERVGUI_CanvasNodePrs*)myCurrentItem)->setMoving(false);
455 if (myCurrentItem->rtti() == SUPERVGUI_Canvas::Rtti_LinkPoint) {
456 ((SUPERVGUI_CanvasPointPrs*)myCurrentItem)->setMoving(false);
461 if (myIsPanActivated) {
462 myIsPanActivated = false;
463 myIsPanBtnClicked = false;
467 if (myIsZoomActivated) {
468 myIsZoomActivated = false;
472 //mkr: "Fit within rectangle" functionality
473 if (myIsFitWRActivated) {
474 if (mySelectedRect) {
475 mySelectedRect->hide();
480 //myPoint is the start point for selecting rectangle now
481 QPoint anEndPoint = inverseWorldMatrix().map(theEvent->pos());
482 int aLX, aTY; //left x and top y
483 if (myPoint.x() < anEndPoint.x()) aLX = myPoint.x();
484 else aLX = anEndPoint.x();
485 if (myPoint.y() < anEndPoint.y()) aTY = myPoint.y();
486 else aTY = anEndPoint.y();
488 //calculate width and height for new view and new zoom factor
489 double aXzoom = ((double)visibleWidth())/((double)(abs(myPoint.x()-anEndPoint.x())));
490 double aYzoom = ((double)visibleHeight())/((double)(abs(myPoint.y()-anEndPoint.y())));
491 if (aXzoom > aYzoom) aXzoom = aYzoom;
494 m.scale(aXzoom, aXzoom);
496 setContentsPos((int)(aLX*aXzoom), (int)(aTY*aYzoom));
500 myIsFitWRActivated = false;
501 viewport()->setMouseTracking(true);
506 void SUPERVGUI_CanvasView::contentsMouseDoubleClickEvent(QMouseEvent* theEvent)
508 QPoint p = inverseWorldMatrix().map(theEvent->pos());
510 // compute collision rectangle
511 //QRect aSel(p.x()-MARGIN, p.y()-MARGIN, 1+2*MARGIN, 1+2*MARGIN);
513 if (theEvent->button() == Qt::LeftButton) {
514 QCanvasItemList l = canvas()->collisions(p);
515 for (QCanvasItemList::Iterator it = l.begin(); it != l.end(); ++it) {
516 if ((*it)->rtti() == SUPERVGUI_Canvas::Rtti_Node) {
517 SUPERVGUI_CanvasNodePrs* aNodePrs = (SUPERVGUI_CanvasNodePrs*) (*it);
518 SUPERVGUI_CanvasNode* aNode = aNodePrs->getNode();
519 if (aNode->getEngine()->IsMacro() && !myIsLinkCreating) {
520 myMain->openSubGraph(aNode->getEngine(), true);
528 void SUPERVGUI_CanvasView::onDestroyed(QObject* theObject)
530 if (theObject == myHilighted)
534 void SUPERVGUI_CanvasView::setHilighted(SUPERVGUI_CanvasLink* theLink)
536 if (theLink == myHilighted) return;
538 disconnect(myHilighted, SIGNAL(destroyed(QObject*)), this, SLOT(onDestroyed(QObject*)));
539 myHilighted->setHilighted(false);
543 myHilighted = theLink;
544 myHilighted->setHilighted(true);
545 connect(myHilighted, SIGNAL(destroyed(QObject*)), this, SLOT(onDestroyed(QObject*)));
549 void SUPERVGUI_CanvasView::onTimeout()
552 scrollBy(myDX, myDY);
555 inverseWorldMatrix().map((double)myDX, (double)myDY, &cx, &cy);
556 if (myCurrentItem->x()+cx < 0) cx = -myCurrentItem->x();
557 if (myCurrentItem->y()+cy < 0) cy = -myCurrentItem->y();
558 myCurrentItem->moveBy(cx, cy);
559 myPoint.setX(myPoint.x()+(int)cx);
560 myPoint.setY(myPoint.y()+(int)cy);
565 void SUPERVGUI_CanvasView::changeBackground()
567 QColor aColor = QColorDialog::getColor(canvas()->backgroundColor(), this );
568 if ( aColor.isValid() ) {
569 // change background color for canvas view
570 canvas()->setBackgroundColor(aColor);
571 setPaletteBackgroundColor(aColor.light(120));
572 // change background color for array view
573 getMain()->getArrayView()->canvas()->setBackgroundColor(aColor);
574 getMain()->getArrayView()->setPaletteBackgroundColor(aColor.light(120));
576 // mkr : IPAL10825 -->
577 SUPERVGUI* aSupMod = SUPERVGUI::Supervision();
579 MESSAGE("NULL Supervision module!");
582 aSupMod->setIVFBackgroundColor(aColor);
587 void SUPERVGUI_CanvasView::ActivatePanning()
589 myIsPanBtnClicked = true;
592 void SUPERVGUI_CanvasView::ResetView()
599 void SUPERVGUI_CanvasView::startSketch(SUPERVGUI_CanvasPort* thePort)
601 if (myIsLinkCreating) return;
603 myIsLinkCreating = true;
604 myLinkBuilder = new SUPERVGUI_CanvasLinkBuilder(canvas(), myMain, thePort);
605 mySketchPopup->setItemEnabled(myDelPntItem, false);
608 void SUPERVGUI_CanvasView::endSketch(SUPERVGUI_CanvasPort* thePort)
610 if (!myIsLinkCreating) return;
612 if (myLinkBuilder && myLinkBuilder->canCreateEngine(thePort)) {
613 bool input = thePort->getEngine()->IsInput();
614 SUPERV_Link aLinkEngine;
615 if (thePort->getEngine()->Kind() == SUPERV::DataStreamParameter) {
616 SUPERVGUI_CanvasStreamPortIn* aInPort = (SUPERVGUI_CanvasStreamPortIn*)
617 (input ? thePort : myLinkBuilder->getStartPort());
618 SUPERVGUI_CanvasStreamPortOut* aOutPort = (SUPERVGUI_CanvasStreamPortOut*)
619 (input ? myLinkBuilder->getStartPort() : thePort);
620 // aLinkEngine = myMain->getDataflow()->StreamLink(aOutPort->getStreamEngine(),
621 // aInPort->getStreamEngine());
622 if (myMain->getDataflow()->IsStreamGraph()) {
623 SUPERV_StreamGraph aSGraph = myMain->getDataflow()->ToStreamGraph();
624 if (!SUPERV_isNull(aSGraph))
625 aLinkEngine = aSGraph->StreamLink(aOutPort->getStreamEngine(),
626 aInPort->getStreamEngine());
630 SUPERVGUI_CanvasPort* aInPort = (input ? thePort : myLinkBuilder->getStartPort());
631 SUPERVGUI_CanvasPort* aOutPort = (input ? myLinkBuilder->getStartPort() : thePort);
632 aLinkEngine = myMain->getDataflow()->Link(aOutPort->getEngine(), aInPort->getEngine());
634 if (SUPERV_isNull(aLinkEngine))
637 // here, in fact, aLinkEngine may NOT be a newly created link. If a link already existed between the
638 // the 2 given ports - it will be return (NOT created again).
639 // this should be checked and new presentation should NOT be created for existing link.
640 // Solution 1: NOT to allow creation of a link if it already exists between the ports in
641 // myLinkBuilder->canCreateEngine()
642 // Solution 2: check here if aLinkEngine is "new" or "old"
643 // Implement 2nd solution, because canCreateEngine() checks for types of ports, etc.. - it's another thing
645 QObjectList* canvasLinks = canvas()->queryList("SUPERVGUI_CanvasLink");
646 SUPERVGUI_CanvasLink* canvasLink = 0;
647 QObjectListIt it(*canvasLinks);
648 bool prsAlreadyExists = false;
649 while ( (canvasLink=(SUPERVGUI_CanvasLink*)it.current()) ) {
651 SUPERV_Link existingLinkWithPrs = canvasLink->getEngine();
652 if ( !SUPERV_isNull( existingLinkWithPrs ) ) {
653 if ( existingLinkWithPrs->IsEqual( aLinkEngine ) ) {
654 prsAlreadyExists = true;
660 if ( prsAlreadyExists ) { // aLinkEngine is already bound with a SUPERVGUI_CanvasLink object
661 //return; // -> if return here, than the old CanvasLink is kept
663 // we want to delete old and create a new CanvasLink for this Link
666 // clear old corrdinates in Engine link
667 for ( int i = 1; i <= aLinkEngine->CoordsSize(); i++ )
668 aLinkEngine->RemoveCoord( i );
669 // now we are ready to set coords for a link and create a new CanvasLink presentation that will use them.
672 myLinkBuilder->setCoords(aLinkEngine.in());
674 delete myLinkBuilder;
677 SUPERVGUI_CanvasLink* aLink = new SUPERVGUI_CanvasLink(canvas(), myMain, aLinkEngine);
681 myIsLinkCreating = false;
683 // asv : 13.12.04 : introducing a check for ports' types compatibility (Bugs and Improvements p.1.16, PAL7380)
684 if ( !aLinkEngine->IsValid() ) {
685 const int id = SUIT_MessageBox::warn2( this, tr( "TLT_INVALID_LINK" ),
686 tr( "MSG_INVALID_LINK" ) + QString(" : ") + QString(myMain->getDataflow()->Messages()),
687 tr( "Keep" ), tr( "Remove" ), 0, 1, 0 );
688 if ( id == 1 ) { // "Remove" was selected in Message Box
689 aLink->remove(); // the new link did not live long...
695 void SUPERVGUI_CanvasView::cancelSketch()
698 delete myLinkBuilder;
702 myIsLinkCreating = false;
705 void SUPERVGUI_CanvasView::deletePoint()
707 if (myIsLinkCreating && myLinkBuilder) {
708 myLinkBuilder->removeLastPoint();
710 mySketchPopup->setItemEnabled(myDelPntItem, myLinkBuilder->getPointCount());
714 void SUPERVGUI_CanvasView::setOrthoMode()
716 bool aIsOrtho = !mySketchPopup->isItemChecked(myOrtoItem);
717 mySketchPopup->setItemChecked(myOrtoItem, aIsOrtho);
720 void SUPERVGUI_CanvasView::zoomIn()
728 void SUPERVGUI_CanvasView::zoomReset()
736 void SUPERVGUI_CanvasView::zoomOut()
744 void SUPERVGUI_CanvasView::fitAll()
747 QCanvasItemList l = canvas()->allItems();
748 for (QCanvasItemList::Iterator it = l.begin(); it != l.end(); ++it) {
749 QRect r = (*it)->boundingRect();
750 if (w < r.right()) w = r.right();
751 if (h < r.bottom()) h = r.bottom();
753 w += GRAPH_MARGIN; h += GRAPH_MARGIN;
754 double s = ((double)visibleWidth())/((double)w);
755 double s1 = ((double)visibleHeight())/((double)h);
765 void SUPERVGUI_CanvasView::fitWithinRect()
767 //mkr: "Fit within rectangle" functionality
768 myIsFitWRActivated = true;
769 viewport()->setMouseTracking(false);
771 setCursor(handCursor);
774 bool SUPERVGUI_CanvasView::isHavingStreamPort() const
776 SUPERV::ListOfNodes* aNodesList = myMain->getDataflow()->Nodes();
779 for ( int i = 0 ; i < (int) aNodesList->CNodes.length() ; i++ ) {
780 SUPERV::ListOfStreamPorts aStrPortsList = *( (aNodesList->CNodes)[i]->StreamPorts() );
781 if ((int) aStrPortsList.length() > 0) {
787 for ( int i = 0 ; i < (int) aNodesList->FNodes.length() ; i++ ) {
788 SUPERV::ListOfStreamPorts aStrPortsList = *( (aNodesList->FNodes)[i]->StreamPorts() );
789 if ((int) aStrPortsList.length() > 0) {
795 for ( int i = 0 ; i < (int) aNodesList->INodes.length() ; i++ ) {
796 SUPERV::ListOfStreamPorts aStrPortsList = *( (aNodesList->INodes)[i]->StreamPorts() );
797 if ((int) aStrPortsList.length() > 0) {
803 for ( int i = 0 ; i < (int) aNodesList->GNodes.length() ; i++ ) {
804 SUPERV::ListOfStreamPorts aStrPortsList = *( (aNodesList->GNodes)[i]->StreamPorts() );
805 if ((int) aStrPortsList.length() > 0) {
811 for ( int i = 0 ; i < (int) aNodesList->LNodes.length() ; i++ ) {
812 SUPERV::ListOfStreamPorts aStrPortsList = *( (aNodesList->LNodes)[i]->StreamPorts() );
813 if ((int) aStrPortsList.length() > 0) {
819 for ( int i = 0 ; i < (int) aNodesList->SNodes.length() ; i++ ) {
820 SUPERV::ListOfStreamPorts aStrPortsList = *( (aNodesList->SNodes)[i]->StreamPorts() );
821 if ((int) aStrPortsList.length() > 0) {