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 SUPERVGUI_CanvasView::SUPERVGUI_CanvasView(SUPERVGUI_Canvas* theCanvas, SUPERVGUI_Main* theMain):
85 QCanvasView(theCanvas, theMain),
86 myMain(theMain), myCurrentItem(0), myHilighted(0), myLinkBuilder(0)
88 setName("CanvasView");
90 myIsPanBtnClicked = false;
91 myIsPanActivated = false;
92 myIsFitWRActivated = false;
93 myIsZoomActivated = false;
94 myIsLinkCreating = false;
100 myTimer = new QTimer(this);
101 connect(myTimer, SIGNAL(timeout()), this, SLOT(onTimeout()));
103 myPopup = new QPopupMenu(viewport());
105 const bool isEdit = myMain->isEditable();
107 myPopup->insertItem(tr("MSG_ADD_NODE"), myMain, SLOT(addNode()));
109 // Paste Node functionality
110 SUPERVGUI_Clipboard* aCB = SUPERVGUI_Clipboard::getClipboard();
111 myPasteNodeItem = myPopup->insertItem(tr("ITM_PASTE_NODE"), aCB, SLOT(pasteNode()));
113 myPopup->insertItem(tr("MSG_INS_FILE"), myMain, SLOT(insertFile()));
114 myPopup->insertSeparator();
117 QPopupMenu* aViewPopup = new QPopupMenu(viewport());
118 aViewPopup->insertItem(tr("POP_FULLVIEW"), myMain, SLOT(showCanvas()));
119 aViewPopup->insertItem(tr("POP_CONTROLVIEW"), myMain, SLOT(showContolFlow()));
120 aViewPopup->insertItem(tr("POP_TABLEVIEW"), myMain, SLOT(showCanvasTable()));
122 myPopup->insertItem(tr("POP_VIEW"), aViewPopup);
123 myPopup->insertSeparator();
125 QPopupMenu* aZoomPopup = new QPopupMenu(viewport());
126 aZoomPopup->insertItem("200%", this, SLOT(zoomIn()));
127 aZoomPopup->insertItem("100%", this, SLOT(zoomReset()));
128 aZoomPopup->insertItem("50%", this, SLOT(zoomOut()));
129 aZoomPopup->insertSeparator();
130 //mkr: "Fit within rectangle" functionality
131 aZoomPopup->insertItem(tr("POP_FITWITHINRECT"), this, SLOT(fitWithinRect()));
132 aZoomPopup->insertSeparator();
133 aZoomPopup->insertItem(tr("POP_FITALL"), this, SLOT(fitAll()));
136 myPopup->insertItem(tr("POP_ZOOM"), aZoomPopup);
137 myPopup->insertSeparator();
139 myAddStudyItem = myPopup->insertItem(tr("MSG_ADD_STUDY"), myMain, SLOT(addDataflowToStudy()));
140 myPopup->insertItem(tr(isEdit ? "MSG_CHANGE_INFO" : "MSG_INFO"), myMain, SLOT(changeInformation()));
141 myPopup->insertSeparator();
143 myPopup->insertItem(tr("MSG_COPY_DATAFLOW"), myMain, SLOT(copy()));
144 myPopup->insertItem(tr("MSG_FILTER_NOTIFY"), myMain, SLOT(filterNotification()));
146 myPopup->insertSeparator();
147 myPopup->insertItem(tr("MSG_CHANGE_BACKGROUND"), this, SLOT(changeBackground()));
149 viewport()->setMouseTracking(true);
151 //create sketching popup menu
152 mySketchPopup = new QPopupMenu(viewport());
153 mySketchPopup->setCheckable(true);
154 myDelPntItem = mySketchPopup->insertItem(tr("MSG_DEL_LAST_PNT"), this, SLOT(deletePoint()));
155 mySketchPopup->insertItem(tr("MSG_DEL_LINK"), this, SLOT(cancelSketch()));
156 myOrtoItem = mySketchPopup->insertItem(tr("MSG_ORTHO_LINE"), this, SLOT(setOrthoMode()));
159 // add "change dataflow parameters" popup item
160 myPopup->insertSeparator();
161 myDSParamsItem = myPopup->insertItem( tr( "MSG_SET_GRAPHPARAMS" ), myMain, SLOT( changeDSGraphParameters() ) );
163 SUPERVGraph_ViewFrame* anActiveVF = (SUPERVGraph_ViewFrame*)myMain->parent();
165 myPopup->insertSeparator();
166 myShowToolBarItem = myPopup->insertItem( tr( "MEN_SHOW_TOOLBAR" ), myMain, SLOT( onShowToolbar() ) );
170 connect(this, SIGNAL(objectCreated()), myMain, SLOT(onObjectCreatedDeleted()));
174 SUPERVGUI_CanvasView::~SUPERVGUI_CanvasView()
176 SUPERVGUI_Clipboard::setNullClipboard();
179 void SUPERVGUI_CanvasView::contentsMousePressEvent(QMouseEvent* theEvent)
181 myPoint = inverseWorldMatrix().map(theEvent->pos());
182 myGlobalPoint = theEvent->globalPos();
185 // compute collision rectangle
186 QRect aSel(myPoint.x()-MARGIN, myPoint.y()-MARGIN, 1+2*MARGIN, 1+2*MARGIN);
188 if (((theEvent->button() == Qt::MidButton) &&
189 (theEvent->state() == Qt::ControlButton)) ||
191 myIsPanActivated = true;
194 #if QT_VERSION >= 0x030005
195 QCursor pan2Cursor(Qt::SizeAllCursor);
197 QCursor pan2Cursor(SizeAllCursor);
199 setCursor(pan2Cursor);
203 if (((theEvent->button() == Qt::LeftButton) &&
204 (theEvent->state() == Qt::ControlButton)) ||
206 myIsZoomActivated = true;
209 QPixmap zoomPix (imageZoomCursor);
210 QCursor zoom2Cursor (zoomPix);
211 setCursor(zoom2Cursor);
215 if ( theEvent->button() == Qt::RightButton) {
216 if (myIsLinkCreating) {
217 myMain->showPopup(mySketchPopup, theEvent);
221 QCanvasItemList l = canvas()->collisions(aSel);
222 for (QCanvasItemList::Iterator it = l.begin(); it != l.end(); ++it) {
223 if ((*it)->rtti() == SUPERVGUI_Canvas::Rtti_Node) {
224 SUPERVGUI_CanvasNodePrs* aNodePrs = (SUPERVGUI_CanvasNodePrs*) (*it);
225 QObject* anObj = aNodePrs->getObject(myPoint);
226 if (anObj->inherits("SUPERVGUI_CanvasNode")) {
227 myMain->showPopup(((SUPERVGUI_CanvasNode*)anObj)->getPopupMenu(viewport()),
231 else if (anObj->inherits("SUPERVGUI_CanvasPort")) {
232 myMain->showPopup(((SUPERVGUI_CanvasPort*)anObj)->getPopupMenu(viewport()),
237 if (myMain->isEditable() && !myMain->getCanvas()->isControlView()) {
238 if ((*it)->rtti() == SUPERVGUI_Canvas::Rtti_LinkPoint) {
239 SUPERVGUI_CanvasPointPrs* aPrs = (SUPERVGUI_CanvasPointPrs*) (*it);
240 aPrs->getLink()->setSelectedObject(aPrs, myPoint);
241 myMain->showPopup(aPrs->getLink()->getPopupMenu(viewport()), theEvent);
244 if ((*it)->rtti() == SUPERVGUI_Canvas::Rtti_LinkEdge) {
245 SUPERVGUI_CanvasEdgePrs* aPrs = (SUPERVGUI_CanvasEdgePrs*) (*it);
246 aPrs->getLink()->setSelectedObject(aPrs, myPoint);
247 myMain->showPopup(aPrs->getLink()->getPopupMenu(viewport()), theEvent);
253 myPopup->setItemEnabled(myAddStudyItem, !myMain->isDataflowInStudy());
254 // Paste Node functionality
255 SUPERVGUI_Clipboard* aCB = SUPERVGUI_Clipboard::getClipboard();
256 myPopup->setItemEnabled(myPasteNodeItem, aCB->isCopyNode() );
258 myPopup->setItemEnabled( myDSParamsItem, isHavingStreamPort()/*myMain->getDataflow()->IsStreamGraph()*/ );
260 myPopup->setItemEnabled( myShowToolBarItem, !((SUPERVGraph_ViewFrame*)myMain->parent())->getToolBar()->isVisible() );
262 myMain->showPopup(myPopup, theEvent);
266 if (theEvent->button() == Qt::LeftButton) {
267 if (!myIsFitWRActivated) {//not moving items if fit within rectangle
268 //functionality is enable
269 QCanvasItemList l = canvas()->collisions(myPoint);
270 if (myIsLinkCreating) {
271 for (QCanvasItemList::Iterator it = l.begin(); it != l.end(); ++it) {
272 if ((*it)->rtti() == SUPERVGUI_Canvas::Rtti_Node) {
273 SUPERVGUI_CanvasNodePrs* aNodePrs = (SUPERVGUI_CanvasNodePrs*) (*it);
274 QObject* anObj = aNodePrs->getObject(myPoint);
275 if (anObj->inherits("SUPERVGUI_CanvasPort")) {
276 endSketch((SUPERVGUI_CanvasPort*)anObj);
281 ((SUPERVGUI_CanvasNodePrs*)myCurrentItem)->setZ(2);
282 ((SUPERVGUI_CanvasNodePrs*)myCurrentItem)->setMoving(true);
286 if ((*it)->rtti() == SUPERVGUI_Canvas::Rtti_Hook) {
287 SUPERVGUI_CanvasHookPrs* aHookPrs = (SUPERVGUI_CanvasHookPrs*) (*it);
288 QObject* anObj = aHookPrs->getObject();
289 if (anObj->inherits("SUPERVGUI_CanvasPort")) {
290 endSketch((SUPERVGUI_CanvasPort*)anObj);
296 myLinkBuilder->addNextPoint(myPoint, mySketchPopup->isItemChecked(myOrtoItem));
298 mySketchPopup->setItemEnabled(myDelPntItem, true);
303 // if (myMain->isEditable()) { // allow to move nodes and link point on imported graph
304 for (QCanvasItemList::Iterator it = l.begin(); it != l.end(); ++it) {
305 if ((*it)->rtti() == SUPERVGUI_Canvas::Rtti_Node) {
307 ((SUPERVGUI_CanvasNodePrs*)myCurrentItem)->setZ(2);
308 ((SUPERVGUI_CanvasNodePrs*)myCurrentItem)->setMoving(true);
311 if ((*it)->rtti() == SUPERVGUI_Canvas::Rtti_LinkPoint) {
312 SUPERVGUI_CanvasPointPrs* aPrs = (SUPERVGUI_CanvasPointPrs*) (*it);
313 if (aPrs->getIndex() > 0) {
315 aPrs->setMoving(true);
319 if ((*it)->rtti() == SUPERVGUI_Canvas::Rtti_LinkEdge) {
320 //mkr: for moving segment of link
321 SUPERVGUI_CanvasEdgePrs* aPrs = (SUPERVGUI_CanvasEdgePrs*) (*it);
322 if (aPrs->getLink()->getInputPort()->getConnectionPoint() == aPrs->startPoint()
324 aPrs->getLink()->getInputPort()->getConnectionPoint() == aPrs->endPoint()
326 aPrs->getLink()->getOutputPort()->getConnectionPoint() == aPrs->startPoint()
328 aPrs->getLink()->getOutputPort()->getConnectionPoint() == aPrs->endPoint()) {
332 aPrs->setMoving(true);
343 void SUPERVGUI_CanvasView::contentsMouseMoveEvent(QMouseEvent* theEvent)
348 QPoint p = inverseWorldMatrix().map(theEvent->pos());
349 QPoint g = theEvent->globalPos();
351 if (myTimer->isActive()) myTimer->stop();
353 if (myIsLinkCreating && myLinkBuilder) {
354 myLinkBuilder->setFloatPoint(p);
360 if (myCurrentItem->x() && myCurrentItem->y()) {
361 double cx = myCurrentItem->x() - myPoint.x();
362 double cy = myCurrentItem->y() - myPoint.y();
364 if (p.x()+cx < 0) p.setX(-(int)cx);
365 if (p.y()+cy < 0) p.setY(-(int)cy);
367 myCurrentItem->moveBy(p.x() - myPoint.x(),
368 p.y() - myPoint.y());
372 // scroll contents if mouse is outside
373 QRect r(contentsX(), contentsY(), visibleWidth(), visibleHeight());
374 if (!r.contains(theEvent->pos())) {
376 if (theEvent->pos().x() < r.left()) dx = theEvent->pos().x() - r.left();
377 if (theEvent->pos().x() > r.right()) dx = theEvent->pos().x() - r.right();
378 if (theEvent->pos().y() < r.top()) dy = theEvent->pos().y() - r.top();
379 if (theEvent->pos().y() > r.bottom()) dy = theEvent->pos().y() - r.bottom();
381 // start timer to scroll in silent mode
382 myDX = dx; myDY = dy;
389 if (myIsPanActivated) {
391 scrollBy(myGlobalPoint.x() - g.x(),
392 myGlobalPoint.y() - g.y());
398 if (myIsZoomActivated) {
400 double dx = g.x() - myGlobalPoint.x();
401 double s = 1. + fabs(dx)/10.;
402 if (dx < 0) s = 1./s;
404 QWMatrix m = worldMatrix();
413 //mkr: "Fit within rectangle" functionality
414 if (myIsFitWRActivated) {
415 int aLX, aTY; //left x and top y
416 if (myPoint.x() < p.x()) aLX = myPoint.x();
418 if (myPoint.y() < p.y()) aTY = myPoint.y();
420 QRect aRect(aLX, aTY, abs(myPoint.x()-p.x()), abs(myPoint.y()-p.y()));
421 QCanvasRectangle* aRect1 = new QCanvasRectangle(aRect, canvas());
423 //hide old selected rectangle
425 mySelectedRect->hide();
426 //draw new selected rectangle
427 QPen pen(Qt::SolidLine);
433 mySelectedRect = aRect1;
437 if (!myIsLinkCreating && myMain->isEditable() &&
438 !myMain->getCanvas()->isControlView()) {
439 // compute collision rectangle
440 QRect aSel(p.x()-MARGIN, p.y()-MARGIN, 1+2*MARGIN, 1+2*MARGIN);
441 QCanvasItemList l = canvas()->collisions(aSel);
442 for (QCanvasItemList::Iterator it = l.begin(); it != l.end(); ++it) {
443 if ((*it)->rtti() == SUPERVGUI_Canvas::Rtti_LinkPoint) {
444 SUPERVGUI_CanvasPointPrs* aPrs = (SUPERVGUI_CanvasPointPrs*) (*it);
445 setHilighted(aPrs->getLink());
449 if ((*it)->rtti() == SUPERVGUI_Canvas::Rtti_LinkEdge) {
450 SUPERVGUI_CanvasEdgePrs* aPrs = (SUPERVGUI_CanvasEdgePrs*) (*it);
451 setHilighted(aPrs->getLink());
459 // QToolTip for title and label for SUPERVGUI_CanvasNode
460 SUPERVGUI_ToolTip* aTT = new SUPERVGUI_ToolTip(this);
461 aTT->maybeTip(theEvent->pos());
466 void SUPERVGUI_CanvasView::contentsMouseReleaseEvent(QMouseEvent* theEvent)
468 if (myTimer->isActive()) myTimer->stop();
471 if (myCurrentItem->rtti() == SUPERVGUI_Canvas::Rtti_Node) {
472 ((SUPERVGUI_CanvasNodePrs*)myCurrentItem)->setZ(0);
473 ((SUPERVGUI_CanvasNodePrs*)myCurrentItem)->setMoving(false);
476 if (myCurrentItem->rtti() == SUPERVGUI_Canvas::Rtti_LinkPoint) {
477 ((SUPERVGUI_CanvasPointPrs*)myCurrentItem)->setMoving(false);
482 if (myIsPanActivated) {
483 myIsPanActivated = false;
484 myIsPanBtnClicked = false;
488 if (myIsZoomActivated) {
489 myIsZoomActivated = false;
493 //mkr: "Fit within rectangle" functionality
494 if (myIsFitWRActivated) {
495 if (mySelectedRect) {
496 mySelectedRect->hide();
501 //myPoint is the start point for selecting rectangle now
502 QPoint anEndPoint = inverseWorldMatrix().map(theEvent->pos());
503 int aLX, aTY; //left x and top y
504 if (myPoint.x() < anEndPoint.x()) aLX = myPoint.x();
505 else aLX = anEndPoint.x();
506 if (myPoint.y() < anEndPoint.y()) aTY = myPoint.y();
507 else aTY = anEndPoint.y();
509 //calculate width and height for new view and new zoom factor
510 double aXzoom = ((double)visibleWidth())/((double)(abs(myPoint.x()-anEndPoint.x())));
511 double aYzoom = ((double)visibleHeight())/((double)(abs(myPoint.y()-anEndPoint.y())));
512 if (aXzoom > aYzoom) aXzoom = aYzoom;
515 m.scale(aXzoom, aXzoom);
517 setContentsPos((int)(aLX*aXzoom), (int)(aTY*aYzoom));
521 myIsFitWRActivated = false;
522 viewport()->setMouseTracking(true);
527 void SUPERVGUI_CanvasView::contentsMouseDoubleClickEvent(QMouseEvent* theEvent)
529 QPoint p = inverseWorldMatrix().map(theEvent->pos());
531 // compute collision rectangle
532 //QRect aSel(p.x()-MARGIN, p.y()-MARGIN, 1+2*MARGIN, 1+2*MARGIN);
534 if (theEvent->button() == Qt::LeftButton) {
535 QCanvasItemList l = canvas()->collisions(p);
536 for (QCanvasItemList::Iterator it = l.begin(); it != l.end(); ++it) {
537 if ((*it)->rtti() == SUPERVGUI_Canvas::Rtti_Node) {
538 SUPERVGUI_CanvasNodePrs* aNodePrs = (SUPERVGUI_CanvasNodePrs*) (*it);
539 SUPERVGUI_CanvasNode* aNode = aNodePrs->getNode();
540 if (aNode->getEngine()->IsMacro() && !myIsLinkCreating) {
541 myMain->openSubGraph(aNode->getEngine(), true);
549 void SUPERVGUI_CanvasView::onDestroyed(QObject* theObject)
551 if (theObject == myHilighted)
555 void SUPERVGUI_CanvasView::setHilighted(SUPERVGUI_CanvasLink* theLink)
557 if (theLink == myHilighted) return;
559 disconnect(myHilighted, SIGNAL(destroyed(QObject*)), this, SLOT(onDestroyed(QObject*)));
560 myHilighted->setHilighted(false);
564 myHilighted = theLink;
565 myHilighted->setHilighted(true);
566 connect(myHilighted, SIGNAL(destroyed(QObject*)), this, SLOT(onDestroyed(QObject*)));
570 void SUPERVGUI_CanvasView::onTimeout()
573 scrollBy(myDX, myDY);
576 inverseWorldMatrix().map((double)myDX, (double)myDY, &cx, &cy);
577 if (myCurrentItem->x()+cx < 0) cx = -myCurrentItem->x();
578 if (myCurrentItem->y()+cy < 0) cy = -myCurrentItem->y();
579 myCurrentItem->moveBy(cx, cy);
580 myPoint.setX(myPoint.x()+(int)cx);
581 myPoint.setY(myPoint.y()+(int)cy);
586 void SUPERVGUI_CanvasView::changeBackground()
588 QColor aColor = QColorDialog::getColor(canvas()->backgroundColor(), this );
589 if ( aColor.isValid() ) {
590 // change background color for canvas view
591 canvas()->setBackgroundColor(aColor);
592 setPaletteBackgroundColor(aColor.light(120));
593 // change background color for array view
594 getMain()->getArrayView()->canvas()->setBackgroundColor(aColor);
595 getMain()->getArrayView()->setPaletteBackgroundColor(aColor.light(120));
597 // mkr : IPAL10825 -->
598 SUPERVGUI* aSupMod = SUPERVGUI::Supervision();
600 MESSAGE("NULL Supervision module!");
603 aSupMod->setIVFBackgroundColor(aColor);
608 void SUPERVGUI_CanvasView::ActivatePanning()
610 myIsPanBtnClicked = true;
613 void SUPERVGUI_CanvasView::ResetView()
620 void SUPERVGUI_CanvasView::startSketch(SUPERVGUI_CanvasPort* thePort)
622 if (myIsLinkCreating) return;
624 myIsLinkCreating = true;
625 myLinkBuilder = new SUPERVGUI_CanvasLinkBuilder(canvas(), myMain, thePort);
626 mySketchPopup->setItemEnabled(myDelPntItem, false);
629 void SUPERVGUI_CanvasView::endSketch(SUPERVGUI_CanvasPort* thePort)
631 if (!myIsLinkCreating) return;
633 if (myLinkBuilder && myLinkBuilder->canCreateEngine(thePort)) {
634 bool input = thePort->getEngine()->IsInput();
635 SUPERV_Link aLinkEngine;
636 if (thePort->getEngine()->Kind() == SUPERV::DataStreamParameter) {
637 SUPERVGUI_CanvasStreamPortIn* aInPort = (SUPERVGUI_CanvasStreamPortIn*)
638 (input ? thePort : myLinkBuilder->getStartPort());
639 SUPERVGUI_CanvasStreamPortOut* aOutPort = (SUPERVGUI_CanvasStreamPortOut*)
640 (input ? myLinkBuilder->getStartPort() : thePort);
641 // aLinkEngine = myMain->getDataflow()->StreamLink(aOutPort->getStreamEngine(),
642 // aInPort->getStreamEngine());
643 if (myMain->getDataflow()->IsStreamGraph()) {
644 SUPERV_StreamGraph aSGraph = myMain->getDataflow()->ToStreamGraph();
645 if (!SUPERV_isNull(aSGraph))
646 aLinkEngine = aSGraph->StreamLink(aOutPort->getStreamEngine(),
647 aInPort->getStreamEngine());
651 SUPERVGUI_CanvasPort* aInPort = (input ? thePort : myLinkBuilder->getStartPort());
652 SUPERVGUI_CanvasPort* aOutPort = (input ? myLinkBuilder->getStartPort() : thePort);
653 aLinkEngine = myMain->getDataflow()->Link(aOutPort->getEngine(), aInPort->getEngine());
655 if (SUPERV_isNull(aLinkEngine))
658 // here, in fact, aLinkEngine may NOT be a newly created link. If a link already existed between the
659 // the 2 given ports - it will be return (NOT created again).
660 // this should be checked and new presentation should NOT be created for existing link.
661 // Solution 1: NOT to allow creation of a link if it already exists between the ports in
662 // myLinkBuilder->canCreateEngine()
663 // Solution 2: check here if aLinkEngine is "new" or "old"
664 // Implement 2nd solution, because canCreateEngine() checks for types of ports, etc.. - it's another thing
666 QObjectList* canvasLinks = canvas()->queryList("SUPERVGUI_CanvasLink");
667 SUPERVGUI_CanvasLink* canvasLink = 0;
668 QObjectListIt it(*canvasLinks);
669 bool prsAlreadyExists = false;
670 while ( (canvasLink=(SUPERVGUI_CanvasLink*)it.current()) ) {
672 SUPERV_Link existingLinkWithPrs = canvasLink->getEngine();
673 if ( !SUPERV_isNull( existingLinkWithPrs ) ) {
674 if ( existingLinkWithPrs->IsEqual( aLinkEngine ) ) {
675 prsAlreadyExists = true;
681 if ( prsAlreadyExists ) { // aLinkEngine is already bound with a SUPERVGUI_CanvasLink object
682 //return; // -> if return here, than the old CanvasLink is kept
684 // we want to delete old and create a new CanvasLink for this Link
687 // clear old corrdinates in Engine link
688 for ( int i = 1; i <= aLinkEngine->CoordsSize(); i++ )
689 aLinkEngine->RemoveCoord( i );
690 // now we are ready to set coords for a link and create a new CanvasLink presentation that will use them.
693 myLinkBuilder->setCoords(aLinkEngine.in());
695 delete myLinkBuilder;
698 SUPERVGUI_CanvasLink* aLink = new SUPERVGUI_CanvasLink(canvas(), myMain, aLinkEngine);
701 emit objectCreated(); // mkr : PAL8237
704 myIsLinkCreating = false;
706 // asv : 13.12.04 : introducing a check for ports' types compatibility (Bugs and Improvements p.1.16, PAL7380)
707 if ( !aLinkEngine->IsValid() ) {
708 const int id = SUIT_MessageBox::warn2( this, tr( "TLT_INVALID_LINK" ),
709 tr( "MSG_INVALID_LINK" ) + QString(" : ") + QString(myMain->getDataflow()->Messages()),
710 tr( "Keep" ), tr( "Remove" ), 0, 1, 0 );
711 if ( id == 1 ) { // "Remove" was selected in Message Box
712 aLink->remove(); // the new link did not live long...
718 void SUPERVGUI_CanvasView::cancelSketch()
721 delete myLinkBuilder;
725 myIsLinkCreating = false;
728 void SUPERVGUI_CanvasView::deletePoint()
730 if (myIsLinkCreating && myLinkBuilder) {
731 myLinkBuilder->removeLastPoint();
733 mySketchPopup->setItemEnabled(myDelPntItem, myLinkBuilder->getPointCount());
737 void SUPERVGUI_CanvasView::setOrthoMode()
739 bool aIsOrtho = !mySketchPopup->isItemChecked(myOrtoItem);
740 mySketchPopup->setItemChecked(myOrtoItem, aIsOrtho);
743 void SUPERVGUI_CanvasView::zoomIn()
751 void SUPERVGUI_CanvasView::zoomReset()
759 void SUPERVGUI_CanvasView::zoomOut()
767 void SUPERVGUI_CanvasView::fitAll()
770 QCanvasItemList l = canvas()->allItems();
771 for (QCanvasItemList::Iterator it = l.begin(); it != l.end(); ++it) {
772 QRect r = (*it)->boundingRect();
773 if (w < r.right()) w = r.right();
774 if (h < r.bottom()) h = r.bottom();
776 w += GRAPH_MARGIN; h += GRAPH_MARGIN;
777 double s = ((double)visibleWidth())/((double)w);
778 double s1 = ((double)visibleHeight())/((double)h);
788 void SUPERVGUI_CanvasView::fitWithinRect()
790 //mkr: "Fit within rectangle" functionality
791 myIsFitWRActivated = true;
792 viewport()->setMouseTracking(false);
794 QCursor handCursor (Qt::PointingHandCursor);
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) {