1 // SUPERV SUPERVGUI : GUI for Supervisor component
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : SUPERVGUI_CanvasView.cxx
23 // Author : Natalia KOPNOVA
26 #include "SUPERVGUI.h"
27 #include "SUPERVGUI_CanvasView.h"
28 #include "SUPERVGUI_Main.h"
29 #include "SUPERVGUI_CanvasNode.h"
30 #include "SUPERVGUI_CanvasPort.h"
31 #include "SUPERVGUI_CanvasLink.h"
32 #include "SUPERVGUI_CanvasNodePrs.h"
33 #include "SUPERVGUI_Clipboard.h"
35 #include "SUPERVGUI_ArrayView.h" //for tooltip testing
37 #include "SUIT_MessageBox.h"
40 #include <qcolordialog.h>
46 const char* imageZoomCursor[] = {
51 "................................",
52 "................................",
53 ".#######........................",
54 "..aaaaaaa.......................",
55 "................................",
56 ".............#####..............",
57 "...........##.aaaa##............",
58 "..........#.aa.....a#...........",
59 ".........#.a.........#..........",
60 ".........#a..........#a.........",
61 "........#.a...........#.........",
62 "........#a............#a........",
63 "........#a............#a........",
64 "........#a............#a........",
65 "........#a............#a........",
66 ".........#...........#.a........",
67 ".........#a..........#a.........",
68 ".........##.........#.a.........",
69 "........#####.....##.a..........",
70 ".......###aaa#####.aa...........",
71 "......###aa...aaaaa.......#.....",
72 ".....###aa................#a....",
73 "....###aa.................#a....",
74 "...###aa...............#######..",
75 "....#aa.................aa#aaaa.",
76 ".....a....................#a....",
77 "..........................#a....",
78 "...........................a....",
79 "................................",
80 "................................",
81 "................................",
82 "................................"};
84 QPixmap zoomPix(imageZoomCursor);
85 QCursor zoom2Cursor(zoomPix);
86 QCursor handCursor(Qt::PointingHandCursor);
88 #if QT_VERSION >= 0x030005
89 QCursor pan2Cursor(Qt::SizeAllCursor);
91 QCursor pan2Cursor(SizeAllCursor);
94 SUPERVGUI_CanvasView::SUPERVGUI_CanvasView(SUPERVGUI_Canvas* theCanvas, SUPERVGUI_Main* theMain):
95 QCanvasView(theCanvas, theMain),
96 myMain(theMain), myCurrentItem(0), myHilighted(0), myLinkBuilder(0)
98 setName("CanvasView");
100 myIsPanBtnClicked = false;
101 myIsPanActivated = false;
102 myIsFitWRActivated = false;
103 myIsZoomActivated = false;
104 myIsLinkCreating = false;
110 myTimer = new QTimer(this);
111 connect(myTimer, SIGNAL(timeout()), this, SLOT(onTimeout()));
113 myPopup = new QPopupMenu(viewport());
115 const bool isEdit = myMain->isEditable();
117 myPopup->insertItem(tr("MSG_ADD_NODE"), myMain, SLOT(addNode()));
119 // Paste Node functionality
120 SUPERVGUI_Clipboard* aCB = SUPERVGUI_Clipboard::getClipboard();
121 myPasteNodeItem = myPopup->insertItem(tr("ITM_PASTE_NODE"), aCB, SLOT(pasteNode()));
123 myPopup->insertItem(tr("MSG_INS_FILE"), myMain, SLOT(insertFile()));
124 myPopup->insertSeparator();
127 QPopupMenu* aViewPopup = new QPopupMenu(viewport());
128 aViewPopup->insertItem(tr("POP_FULLVIEW"), myMain, SLOT(showCanvas()));
129 aViewPopup->insertItem(tr("POP_CONTROLVIEW"), myMain, SLOT(showContolFlow()));
130 aViewPopup->insertItem(tr("POP_TABLEVIEW"), myMain, SLOT(showCanvasTable()));
132 myPopup->insertItem(tr("POP_VIEW"), aViewPopup);
133 myPopup->insertSeparator();
135 QPopupMenu* aZoomPopup = new QPopupMenu(viewport());
136 aZoomPopup->insertItem("200%", this, SLOT(zoomIn()));
137 aZoomPopup->insertItem("100%", this, SLOT(zoomReset()));
138 aZoomPopup->insertItem("50%", this, SLOT(zoomOut()));
139 aZoomPopup->insertSeparator();
140 //mkr: "Fit within rectangle" functionality
141 aZoomPopup->insertItem(tr("POP_FITWITHINRECT"), this, SLOT(fitWithinRect()));
142 aZoomPopup->insertSeparator();
143 aZoomPopup->insertItem(tr("POP_FITALL"), this, SLOT(fitAll()));
146 myPopup->insertItem(tr("POP_ZOOM"), aZoomPopup);
147 myPopup->insertSeparator();
149 myAddStudyItem = myPopup->insertItem(tr("MSG_ADD_STUDY"), myMain, SLOT(addDataflowToStudy()));
150 myPopup->insertItem(tr(isEdit ? "MSG_CHANGE_INFO" : "MSG_INFO"), myMain, SLOT(changeInformation()));
151 myPopup->insertSeparator();
153 myPopup->insertItem(tr("MSG_COPY_DATAFLOW"), myMain, SLOT(copy()));
154 myPopup->insertItem(tr("MSG_FILTER_NOTIFY"), myMain, SLOT(filterNotification()));
156 myPopup->insertSeparator();
157 myPopup->insertItem(tr("MSG_CHANGE_BACKGROUND"), this, SLOT(changeBackground()));
159 viewport()->setMouseTracking(true);
161 //create sketching popup menu
162 mySketchPopup = new QPopupMenu(viewport());
163 mySketchPopup->setCheckable(true);
164 myDelPntItem = mySketchPopup->insertItem(tr("MSG_DEL_LAST_PNT"), this, SLOT(deletePoint()));
165 mySketchPopup->insertItem(tr("MSG_DEL_LINK"), this, SLOT(cancelSketch()));
166 myOrtoItem = mySketchPopup->insertItem(tr("MSG_ORTHO_LINE"), this, SLOT(setOrthoMode()));
169 // add "change dataflow parameters" popup item
170 myPopup->insertSeparator();
171 myDSParamsItem = myPopup->insertItem( tr( "MSG_SET_GRAPHPARAMS" ), myMain, SLOT( changeDSGraphParameters() ) );
173 SUPERVGraph_ViewFrame* anActiveVF = (SUPERVGraph_ViewFrame*)myMain->parent();
175 myPopup->insertSeparator();
176 myShowToolBarItem = myPopup->insertItem( tr( "MEN_SHOW_TOOLBAR" ), myMain, SLOT( onShowToolbar() ) );
180 connect(this, SIGNAL(objectCreated()), myMain, SLOT(onObjectCreatedDeleted()));
184 SUPERVGUI_CanvasView::~SUPERVGUI_CanvasView()
186 SUPERVGUI_Clipboard::setNullClipboard();
189 void SUPERVGUI_CanvasView::contentsMousePressEvent(QMouseEvent* theEvent)
191 myPoint = inverseWorldMatrix().map(theEvent->pos());
192 myGlobalPoint = theEvent->globalPos();
195 // compute collision rectangle
196 QRect aSel(myPoint.x()-MARGIN, myPoint.y()-MARGIN, 1+2*MARGIN, 1+2*MARGIN);
198 if (((theEvent->button() == Qt::MidButton) &&
199 (theEvent->state() == Qt::ControlButton)) ||
201 myIsPanActivated = true;
203 setCursor(pan2Cursor);
207 if (((theEvent->button() == Qt::LeftButton) &&
208 (theEvent->state() == Qt::ControlButton)) ||
210 myIsZoomActivated = true;
212 setCursor(zoom2Cursor);
216 if ( theEvent->button() == Qt::RightButton) {
217 if (myIsLinkCreating) {
218 myMain->showPopup(mySketchPopup, theEvent);
222 QCanvasItemList l = canvas()->collisions(aSel);
223 for (QCanvasItemList::Iterator it = l.begin(); it != l.end(); ++it) {
224 if ((*it)->rtti() == SUPERVGUI_Canvas::Rtti_Node) {
225 SUPERVGUI_CanvasNodePrs* aNodePrs = (SUPERVGUI_CanvasNodePrs*) (*it);
226 QObject* anObj = aNodePrs->getObject(myPoint);
227 if (anObj->inherits("SUPERVGUI_CanvasNode")) {
228 myMain->showPopup(((SUPERVGUI_CanvasNode*)anObj)->getPopupMenu(viewport()),
232 else if (anObj->inherits("SUPERVGUI_CanvasPort")) {
233 myMain->showPopup(((SUPERVGUI_CanvasPort*)anObj)->getPopupMenu(viewport()),
238 if (myMain->isEditable() && !myMain->getCanvas()->isControlView()) {
239 if ((*it)->rtti() == SUPERVGUI_Canvas::Rtti_LinkPoint) {
240 SUPERVGUI_CanvasPointPrs* aPrs = (SUPERVGUI_CanvasPointPrs*) (*it);
241 aPrs->getLink()->setSelectedObject(aPrs, myPoint);
242 myMain->showPopup(aPrs->getLink()->getPopupMenu(viewport()), theEvent);
245 if ((*it)->rtti() == SUPERVGUI_Canvas::Rtti_LinkEdge) {
246 SUPERVGUI_CanvasEdgePrs* aPrs = (SUPERVGUI_CanvasEdgePrs*) (*it);
247 aPrs->getLink()->setSelectedObject(aPrs, myPoint);
248 myMain->showPopup(aPrs->getLink()->getPopupMenu(viewport()), theEvent);
254 myPopup->setItemEnabled(myAddStudyItem, !myMain->isDataflowInStudy());
255 // Paste Node functionality
256 SUPERVGUI_Clipboard* aCB = SUPERVGUI_Clipboard::getClipboard();
257 myPopup->setItemEnabled(myPasteNodeItem, aCB->isCopyNode() );
259 myPopup->setItemEnabled( myDSParamsItem, isHavingStreamPort()/*myMain->getDataflow()->IsStreamGraph()*/ );
261 myPopup->setItemEnabled( myShowToolBarItem, !((SUPERVGraph_ViewFrame*)myMain->parent())->getToolBar()->isVisible() );
263 myMain->showPopup(myPopup, theEvent);
267 if (theEvent->button() == Qt::LeftButton) {
268 if (!myIsFitWRActivated) {//not moving items if fit within rectangle
269 //functionality is enable
270 QCanvasItemList l = canvas()->collisions(myPoint);
271 if (myIsLinkCreating) {
272 for (QCanvasItemList::Iterator it = l.begin(); it != l.end(); ++it) {
273 if ((*it)->rtti() == SUPERVGUI_Canvas::Rtti_Node) {
274 SUPERVGUI_CanvasNodePrs* aNodePrs = (SUPERVGUI_CanvasNodePrs*) (*it);
275 QObject* anObj = aNodePrs->getObject(myPoint);
276 if (anObj->inherits("SUPERVGUI_CanvasPort")) {
277 endSketch((SUPERVGUI_CanvasPort*)anObj);
282 ((SUPERVGUI_CanvasNodePrs*)myCurrentItem)->setZ(2);
283 ((SUPERVGUI_CanvasNodePrs*)myCurrentItem)->setMoving(true);
287 if ((*it)->rtti() == SUPERVGUI_Canvas::Rtti_Hook) {
288 SUPERVGUI_CanvasHookPrs* aHookPrs = (SUPERVGUI_CanvasHookPrs*) (*it);
289 QObject* anObj = aHookPrs->getObject();
290 if (anObj->inherits("SUPERVGUI_CanvasPort")) {
291 endSketch((SUPERVGUI_CanvasPort*)anObj);
297 myLinkBuilder->addNextPoint(myPoint, mySketchPopup->isItemChecked(myOrtoItem));
299 mySketchPopup->setItemEnabled(myDelPntItem, true);
304 // if (myMain->isEditable()) { // allow to move nodes and link point on imported graph
305 for (QCanvasItemList::Iterator it = l.begin(); it != l.end(); ++it) {
306 if ((*it)->rtti() == SUPERVGUI_Canvas::Rtti_Node) {
308 ((SUPERVGUI_CanvasNodePrs*)myCurrentItem)->setZ(2);
309 ((SUPERVGUI_CanvasNodePrs*)myCurrentItem)->setMoving(true);
312 if ((*it)->rtti() == SUPERVGUI_Canvas::Rtti_LinkPoint) {
313 SUPERVGUI_CanvasPointPrs* aPrs = (SUPERVGUI_CanvasPointPrs*) (*it);
314 if (aPrs->getIndex() > 0) {
316 aPrs->setMoving(true);
320 if ((*it)->rtti() == SUPERVGUI_Canvas::Rtti_LinkEdge) {
321 //mkr: for moving segment of link
322 SUPERVGUI_CanvasEdgePrs* aPrs = (SUPERVGUI_CanvasEdgePrs*) (*it);
323 if (aPrs->getLink()->getInputPort()->getConnectionPoint() == aPrs->startPoint()
325 aPrs->getLink()->getInputPort()->getConnectionPoint() == aPrs->endPoint()
327 aPrs->getLink()->getOutputPort()->getConnectionPoint() == aPrs->startPoint()
329 aPrs->getLink()->getOutputPort()->getConnectionPoint() == aPrs->endPoint()) {
333 aPrs->setMoving(true);
344 void SUPERVGUI_CanvasView::contentsMouseMoveEvent(QMouseEvent* theEvent)
349 QPoint p = inverseWorldMatrix().map(theEvent->pos());
350 QPoint g = theEvent->globalPos();
352 if (myTimer->isActive()) myTimer->stop();
354 if (myIsLinkCreating && myLinkBuilder) {
355 myLinkBuilder->setFloatPoint(p);
361 if (myCurrentItem->x() && myCurrentItem->y()) {
362 double cx = myCurrentItem->x() - myPoint.x();
363 double cy = myCurrentItem->y() - myPoint.y();
365 if (p.x()+cx < 0) p.setX(-(int)cx);
366 if (p.y()+cy < 0) p.setY(-(int)cy);
368 myCurrentItem->moveBy(p.x() - myPoint.x(),
369 p.y() - myPoint.y());
373 // scroll contents if mouse is outside
374 QRect r(contentsX(), contentsY(), visibleWidth(), visibleHeight());
375 if (!r.contains(theEvent->pos())) {
377 if (theEvent->pos().x() < r.left()) dx = theEvent->pos().x() - r.left();
378 if (theEvent->pos().x() > r.right()) dx = theEvent->pos().x() - r.right();
379 if (theEvent->pos().y() < r.top()) dy = theEvent->pos().y() - r.top();
380 if (theEvent->pos().y() > r.bottom()) dy = theEvent->pos().y() - r.bottom();
382 // start timer to scroll in silent mode
383 myDX = dx; myDY = dy;
390 if (myIsPanActivated) {
392 scrollBy(myGlobalPoint.x() - g.x(),
393 myGlobalPoint.y() - g.y());
399 if (myIsZoomActivated) {
401 double dx = g.x() - myGlobalPoint.x();
402 double s = 1. + fabs(dx)/10.;
403 if (dx < 0) s = 1./s;
405 QWMatrix m = worldMatrix();
414 //mkr: "Fit within rectangle" functionality
415 if (myIsFitWRActivated) {
416 int aLX, aTY; //left x and top y
417 if (myPoint.x() < p.x()) aLX = myPoint.x();
419 if (myPoint.y() < p.y()) aTY = myPoint.y();
421 QRect aRect(aLX, aTY, abs(myPoint.x()-p.x()), abs(myPoint.y()-p.y()));
422 QCanvasRectangle* aRect1 = new QCanvasRectangle(aRect, canvas());
424 //hide old selected rectangle
426 mySelectedRect->hide();
427 //draw new selected rectangle
428 QPen pen(Qt::SolidLine);
434 mySelectedRect = aRect1;
438 if (!myIsLinkCreating && myMain->isEditable() &&
439 !myMain->getCanvas()->isControlView()) {
440 // compute collision rectangle
441 QRect aSel(p.x()-MARGIN, p.y()-MARGIN, 1+2*MARGIN, 1+2*MARGIN);
442 QCanvasItemList l = canvas()->collisions(aSel);
443 for (QCanvasItemList::Iterator it = l.begin(); it != l.end(); ++it) {
444 if ((*it)->rtti() == SUPERVGUI_Canvas::Rtti_LinkPoint) {
445 SUPERVGUI_CanvasPointPrs* aPrs = (SUPERVGUI_CanvasPointPrs*) (*it);
446 setHilighted(aPrs->getLink());
450 if ((*it)->rtti() == SUPERVGUI_Canvas::Rtti_LinkEdge) {
451 SUPERVGUI_CanvasEdgePrs* aPrs = (SUPERVGUI_CanvasEdgePrs*) (*it);
452 setHilighted(aPrs->getLink());
460 // QToolTip for title and label for SUPERVGUI_CanvasNode
461 SUPERVGUI_ToolTip* aTT = new SUPERVGUI_ToolTip(this);
462 aTT->maybeTip(theEvent->pos());
467 void SUPERVGUI_CanvasView::contentsMouseReleaseEvent(QMouseEvent* theEvent)
469 if (myTimer->isActive()) myTimer->stop();
472 if (myCurrentItem->rtti() == SUPERVGUI_Canvas::Rtti_Node) {
473 ((SUPERVGUI_CanvasNodePrs*)myCurrentItem)->setZ(0);
474 ((SUPERVGUI_CanvasNodePrs*)myCurrentItem)->setMoving(false);
477 if (myCurrentItem->rtti() == SUPERVGUI_Canvas::Rtti_LinkPoint) {
478 ((SUPERVGUI_CanvasPointPrs*)myCurrentItem)->setMoving(false);
483 if (myIsPanActivated) {
484 myIsPanActivated = false;
485 myIsPanBtnClicked = false;
489 if (myIsZoomActivated) {
490 myIsZoomActivated = false;
494 //mkr: "Fit within rectangle" functionality
495 if (myIsFitWRActivated) {
496 if (mySelectedRect) {
497 mySelectedRect->hide();
502 //myPoint is the start point for selecting rectangle now
503 QPoint anEndPoint = inverseWorldMatrix().map(theEvent->pos());
504 int aLX, aTY; //left x and top y
505 if (myPoint.x() < anEndPoint.x()) aLX = myPoint.x();
506 else aLX = anEndPoint.x();
507 if (myPoint.y() < anEndPoint.y()) aTY = myPoint.y();
508 else aTY = anEndPoint.y();
510 //calculate width and height for new view and new zoom factor
511 double aXzoom = ((double)visibleWidth())/((double)(abs(myPoint.x()-anEndPoint.x())));
512 double aYzoom = ((double)visibleHeight())/((double)(abs(myPoint.y()-anEndPoint.y())));
513 if (aXzoom > aYzoom) aXzoom = aYzoom;
516 m.scale(aXzoom, aXzoom);
518 setContentsPos((int)(aLX*aXzoom), (int)(aTY*aYzoom));
522 myIsFitWRActivated = false;
523 viewport()->setMouseTracking(true);
528 void SUPERVGUI_CanvasView::contentsMouseDoubleClickEvent(QMouseEvent* theEvent)
530 QPoint p = inverseWorldMatrix().map(theEvent->pos());
532 // compute collision rectangle
533 //QRect aSel(p.x()-MARGIN, p.y()-MARGIN, 1+2*MARGIN, 1+2*MARGIN);
535 if (theEvent->button() == Qt::LeftButton) {
536 QCanvasItemList l = canvas()->collisions(p);
537 for (QCanvasItemList::Iterator it = l.begin(); it != l.end(); ++it) {
538 if ((*it)->rtti() == SUPERVGUI_Canvas::Rtti_Node) {
539 SUPERVGUI_CanvasNodePrs* aNodePrs = (SUPERVGUI_CanvasNodePrs*) (*it);
540 SUPERVGUI_CanvasNode* aNode = aNodePrs->getNode();
541 if (aNode->getEngine()->IsMacro() && !myIsLinkCreating) {
542 myMain->openSubGraph(aNode->getEngine(), true);
550 void SUPERVGUI_CanvasView::onDestroyed(QObject* theObject)
552 if (theObject == myHilighted)
556 void SUPERVGUI_CanvasView::setHilighted(SUPERVGUI_CanvasLink* theLink)
558 if (theLink == myHilighted) return;
560 disconnect(myHilighted, SIGNAL(destroyed(QObject*)), this, SLOT(onDestroyed(QObject*)));
561 myHilighted->setHilighted(false);
565 myHilighted = theLink;
566 myHilighted->setHilighted(true);
567 connect(myHilighted, SIGNAL(destroyed(QObject*)), this, SLOT(onDestroyed(QObject*)));
571 void SUPERVGUI_CanvasView::onTimeout()
574 scrollBy(myDX, myDY);
577 inverseWorldMatrix().map((double)myDX, (double)myDY, &cx, &cy);
578 if (myCurrentItem->x()+cx < 0) cx = -myCurrentItem->x();
579 if (myCurrentItem->y()+cy < 0) cy = -myCurrentItem->y();
580 myCurrentItem->moveBy(cx, cy);
581 myPoint.setX(myPoint.x()+(int)cx);
582 myPoint.setY(myPoint.y()+(int)cy);
587 void SUPERVGUI_CanvasView::changeBackground()
589 QColor aColor = QColorDialog::getColor(canvas()->backgroundColor(), this );
590 if ( aColor.isValid() ) {
591 // change background color for canvas view
592 canvas()->setBackgroundColor(aColor);
593 setPaletteBackgroundColor(aColor.light(120));
594 // change background color for array view
595 getMain()->getArrayView()->canvas()->setBackgroundColor(aColor);
596 getMain()->getArrayView()->setPaletteBackgroundColor(aColor.light(120));
598 // mkr : IPAL10825 -->
599 SUPERVGUI* aSupMod = SUPERVGUI::Supervision();
601 MESSAGE("NULL Supervision module!");
604 aSupMod->setIVFBackgroundColor(aColor);
609 void SUPERVGUI_CanvasView::ActivatePanning()
611 myIsPanBtnClicked = true;
614 void SUPERVGUI_CanvasView::ResetView()
621 void SUPERVGUI_CanvasView::startSketch(SUPERVGUI_CanvasPort* thePort)
623 if (myIsLinkCreating) return;
625 myIsLinkCreating = true;
626 myLinkBuilder = new SUPERVGUI_CanvasLinkBuilder(canvas(), myMain, thePort);
627 mySketchPopup->setItemEnabled(myDelPntItem, false);
630 void SUPERVGUI_CanvasView::endSketch(SUPERVGUI_CanvasPort* thePort)
632 if (!myIsLinkCreating) return;
634 if (myLinkBuilder && myLinkBuilder->canCreateEngine(thePort)) {
635 bool input = thePort->getEngine()->IsInput();
636 SUPERV_Link aLinkEngine;
637 if (thePort->getEngine()->Kind() == SUPERV::DataStreamParameter) {
638 SUPERVGUI_CanvasStreamPortIn* aInPort = (SUPERVGUI_CanvasStreamPortIn*)
639 (input ? thePort : myLinkBuilder->getStartPort());
640 SUPERVGUI_CanvasStreamPortOut* aOutPort = (SUPERVGUI_CanvasStreamPortOut*)
641 (input ? myLinkBuilder->getStartPort() : thePort);
642 // aLinkEngine = myMain->getDataflow()->StreamLink(aOutPort->getStreamEngine(),
643 // aInPort->getStreamEngine());
644 if (myMain->getDataflow()->IsStreamGraph()) {
645 SUPERV_StreamGraph aSGraph = myMain->getDataflow()->ToStreamGraph();
646 if (!SUPERV_isNull(aSGraph))
647 aLinkEngine = aSGraph->StreamLink(aOutPort->getStreamEngine(),
648 aInPort->getStreamEngine());
652 SUPERVGUI_CanvasPort* aInPort = (input ? thePort : myLinkBuilder->getStartPort());
653 SUPERVGUI_CanvasPort* aOutPort = (input ? myLinkBuilder->getStartPort() : thePort);
654 aLinkEngine = myMain->getDataflow()->Link(aOutPort->getEngine(), aInPort->getEngine());
656 if (SUPERV_isNull(aLinkEngine))
659 // here, in fact, aLinkEngine may NOT be a newly created link. If a link already existed between the
660 // the 2 given ports - it will be return (NOT created again).
661 // this should be checked and new presentation should NOT be created for existing link.
662 // Solution 1: NOT to allow creation of a link if it already exists between the ports in
663 // myLinkBuilder->canCreateEngine()
664 // Solution 2: check here if aLinkEngine is "new" or "old"
665 // Implement 2nd solution, because canCreateEngine() checks for types of ports, etc.. - it's another thing
667 QObjectList* canvasLinks = canvas()->queryList("SUPERVGUI_CanvasLink");
668 SUPERVGUI_CanvasLink* canvasLink = 0;
669 QObjectListIt it(*canvasLinks);
670 bool prsAlreadyExists = false;
671 while ( (canvasLink=(SUPERVGUI_CanvasLink*)it.current()) ) {
673 SUPERV_Link existingLinkWithPrs = canvasLink->getEngine();
674 if ( !SUPERV_isNull( existingLinkWithPrs ) ) {
675 if ( existingLinkWithPrs->IsEqual( aLinkEngine ) ) {
676 prsAlreadyExists = true;
682 if ( prsAlreadyExists ) { // aLinkEngine is already bound with a SUPERVGUI_CanvasLink object
683 //return; // -> if return here, than the old CanvasLink is kept
685 // we want to delete old and create a new CanvasLink for this Link
688 // clear old corrdinates in Engine link
689 for ( int i = 1; i <= aLinkEngine->CoordsSize(); i++ )
690 aLinkEngine->RemoveCoord( i );
691 // now we are ready to set coords for a link and create a new CanvasLink presentation that will use them.
694 myLinkBuilder->setCoords(aLinkEngine.in());
696 delete myLinkBuilder;
699 SUPERVGUI_CanvasLink* aLink = new SUPERVGUI_CanvasLink(canvas(), myMain, aLinkEngine);
702 emit objectCreated(); // mkr : PAL8237
705 myIsLinkCreating = false;
707 // asv : 13.12.04 : introducing a check for ports' types compatibility (Bugs and Improvements p.1.16, PAL7380)
708 if ( !aLinkEngine->IsValid() ) {
709 const int id = SUIT_MessageBox::warn2( this, tr( "TLT_INVALID_LINK" ),
710 tr( "MSG_INVALID_LINK" ) + QString(" : ") + QString(myMain->getDataflow()->Messages()),
711 tr( "Keep" ), tr( "Remove" ), 0, 1, 0 );
712 if ( id == 1 ) { // "Remove" was selected in Message Box
713 aLink->remove(); // the new link did not live long...
719 void SUPERVGUI_CanvasView::cancelSketch()
722 delete myLinkBuilder;
726 myIsLinkCreating = false;
729 void SUPERVGUI_CanvasView::deletePoint()
731 if (myIsLinkCreating && myLinkBuilder) {
732 myLinkBuilder->removeLastPoint();
734 mySketchPopup->setItemEnabled(myDelPntItem, myLinkBuilder->getPointCount());
738 void SUPERVGUI_CanvasView::setOrthoMode()
740 bool aIsOrtho = !mySketchPopup->isItemChecked(myOrtoItem);
741 mySketchPopup->setItemChecked(myOrtoItem, aIsOrtho);
744 void SUPERVGUI_CanvasView::zoomIn()
752 void SUPERVGUI_CanvasView::zoomReset()
760 void SUPERVGUI_CanvasView::zoomOut()
768 void SUPERVGUI_CanvasView::fitAll()
771 QCanvasItemList l = canvas()->allItems();
772 for (QCanvasItemList::Iterator it = l.begin(); it != l.end(); ++it) {
773 QRect r = (*it)->boundingRect();
774 if (w < r.right()) w = r.right();
775 if (h < r.bottom()) h = r.bottom();
777 w += GRAPH_MARGIN; h += GRAPH_MARGIN;
778 double s = ((double)visibleWidth())/((double)w);
779 double s1 = ((double)visibleHeight())/((double)h);
789 void SUPERVGUI_CanvasView::fitWithinRect()
791 //mkr: "Fit within rectangle" functionality
792 myIsFitWRActivated = true;
793 viewport()->setMouseTracking(false);
795 setCursor(handCursor);
798 bool SUPERVGUI_CanvasView::isHavingStreamPort() const
800 SUPERV::ListOfNodes* aNodesList = myMain->getDataflow()->Nodes();
803 for ( int i = 0 ; i < (int) aNodesList->CNodes.length() ; i++ ) {
804 SUPERV::ListOfStreamPorts aStrPortsList = *( (aNodesList->CNodes)[i]->StreamPorts() );
805 if ((int) aStrPortsList.length() > 0) {
811 for ( int i = 0 ; i < (int) aNodesList->FNodes.length() ; i++ ) {
812 SUPERV::ListOfStreamPorts aStrPortsList = *( (aNodesList->FNodes)[i]->StreamPorts() );
813 if ((int) aStrPortsList.length() > 0) {
819 for ( int i = 0 ; i < (int) aNodesList->INodes.length() ; i++ ) {
820 SUPERV::ListOfStreamPorts aStrPortsList = *( (aNodesList->INodes)[i]->StreamPorts() );
821 if ((int) aStrPortsList.length() > 0) {
827 for ( int i = 0 ; i < (int) aNodesList->GNodes.length() ; i++ ) {
828 SUPERV::ListOfStreamPorts aStrPortsList = *( (aNodesList->GNodes)[i]->StreamPorts() );
829 if ((int) aStrPortsList.length() > 0) {
835 for ( int i = 0 ; i < (int) aNodesList->LNodes.length() ; i++ ) {
836 SUPERV::ListOfStreamPorts aStrPortsList = *( (aNodesList->LNodes)[i]->StreamPorts() );
837 if ((int) aStrPortsList.length() > 0) {
843 for ( int i = 0 ; i < (int) aNodesList->SNodes.length() ; i++ ) {
844 SUPERV::ListOfStreamPorts aStrPortsList = *( (aNodesList->SNodes)[i]->StreamPorts() );
845 if ((int) aStrPortsList.length() > 0) {