1 // Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "YACSPrs_ElementaryNode.h"
22 #include "YACSPrs_Link.h"
23 #include "YACSPrs_Def.h"
25 #include "guiContext.hxx"
27 #include "SUIT_ResourceMgr.h"
28 #include "SUIT_Session.h"
30 #include "CAM_Application.h"
34 #include "OutGate.hxx"
35 #include "OutPort.hxx"
36 #include <DataStreamPort.hxx>
38 #include <qpopupmenu.h>
42 #include "YacsTrace.hxx"
44 using namespace YACS::HMI;
45 using namespace YACS::ENGINE;
50 * =========================== YACSPrs_Link ===========================
53 YACSPrs_Link::YACSPrs_Link( SUIT_ResourceMgr* theMgr, QCanvas* theCanvas ):
61 myColor = myMgr->colorValue("YACSGui", "link_draw_color", LINKDRAW_COLOR);
65 YACSPrs_Link::~YACSPrs_Link()
67 DEBTRACE("YACSPrs_Link::~YACSPrs_Link");
68 // remove presentation objects (points and edges)
69 for (QCanvasItemList::Iterator it = myPrs.begin(); it != myPrs.end(); ++it) {
78 void YACSPrs_Link::show()
80 DEBTRACE("YACSPrs_Link::show");
81 if (myPrs.isEmpty()) createPrs();
83 for (QCanvasItemList::Iterator it = myPrs.begin(); it != myPrs.end(); ++it) {
88 void YACSPrs_Link::hide()
90 DEBTRACE("YACSPrs_Link::hide");
91 if (myPrs.isEmpty()) return;
93 for (QCanvasItemList::Iterator it = myPrs.begin(); it != myPrs.end(); ++it) {
98 void YACSPrs_Link::merge()
100 DEBTRACE("YACSPrs_Link::merge");
101 // save z of the link
102 double aZ = ( !myPrs.isEmpty() ? myPrs.first()->z()-1 : 0 ); // the first item is a point
104 // remove old presentation
105 for (QCanvasItemList::Iterator it = myPrs.begin(); it != myPrs.end(); ++it) {
114 // restore z of the link
118 void YACSPrs_Link::setCanvas(QCanvas* theCanvas)
120 myCanvas = theCanvas;
122 // set canvas for all prs items
123 for (QCanvasItemList::Iterator it = myPrs.begin(); it != myPrs.end(); ++it)
124 (*it)->setCanvas(theCanvas);
127 void YACSPrs_Link::updatePoints(QCanvasItem* thePointItem)
129 if ( thePointItem == myPrs.first() || thePointItem == myPrs.last() ) return;
131 YACSPrs_Point* aPoint = dynamic_cast<YACSPrs_Point*>( thePointItem );
134 list<QPoint>::iterator it;
136 for ( it = myPoints.begin(); it != myPoints.end(); it++, id++ )
137 if ( id == aPoint->getIndex() ) {
138 (*it).setX((int)(aPoint->x()));
139 (*it).setY((int)(aPoint->y()));
145 void YACSPrs_Link::setHilighted(bool state)
148 QColor aHilightColor = myMgr->colorValue("YACSGui", "link_hilight_color", LINK_HILIGHT_COLOR);
149 setColor(myHilighted ? aHilightColor : myColor);
150 if (!myPrs.isEmpty()) {
151 bool disp = myPrs.first()->isVisible();
153 for (QCanvasItemList::Iterator it = myPrs.begin(); it != myPrs.end(); ++it) {
154 (*it)->hide(); (*it)->show();
156 if (myCanvas) myCanvas->update();
161 void YACSPrs_Link::setSelected(bool state)
164 setColor(mySelected ? LINK_SELECT_COLOR : myColor);
165 if (!myPrs.isEmpty()) {
166 bool disp = myPrs.first()->isVisible();
168 for (QCanvasItemList::Iterator it = myPrs.begin(); it != myPrs.end(); ++it) {
169 if ( YACSPrs_Point* aPoint = dynamic_cast<YACSPrs_Point*>( *it ) ) aPoint->setSelected(state);
170 else if ( YACSPrs_Edge* anEdge = dynamic_cast<YACSPrs_Edge*>( *it ) ) anEdge->setSelected(state);
171 (*it)->hide(); (*it)->show();
173 if (myCanvas) myCanvas->update();
178 void YACSPrs_Link::setColor(const QColor& theColor)
180 for (QCanvasItemList::Iterator it = myPrs.begin(); it != myPrs.end(); ++it) {
181 YACSPrs_Point* aPoint = dynamic_cast<YACSPrs_Point*>( *it );
182 if ( aPoint ) { //if ((*it)->rtti() == YACSPrs_Canvas::Rtti_Point) {
183 aPoint->setColor(theColor);
185 YACSPrs_Edge* anEdge = dynamic_cast<YACSPrs_Edge*>( *it );
186 if ( anEdge ) { //if ((*it)->rtti() == YACSPrs_Canvas::Rtti_Edge) {
187 anEdge->setColor(theColor);
192 void YACSPrs_Link::setSelectedObject(QCanvasItem* theItem, const QPoint& thePoint)
194 mySelectedItem = theItem;
195 mySelectedPoint = thePoint;
198 QString YACSPrs_Link::getToolTipText() const {
202 void YACSPrs_Link::remove() {
206 void YACSPrs_Link::addPoint() {
207 DEBTRACE("YACSPrs_Link::addPoint");
208 if ( mySelected ) setSelected(false);
210 YACSPrs_Edge* anEdge = dynamic_cast<YACSPrs_Edge*>( mySelectedItem );
213 QCanvasItemList::Iterator it;
214 for (it = myPrs.begin(); it != myPrs.end(); ++it) {
215 if ((*it) == anEdge) break;
217 if (it != myPrs.begin()) {
219 YACSPrs_Point* aPoint = (YACSPrs_Point*) (*it);
220 anIndex = aPoint->getIndex()+1;
221 if (anIndex < 1) anIndex = 1;
223 // TO DO : add point coordinates to link engine
224 if ( myPoints.empty() )
225 myPoints.push_back(mySelectedPoint);
227 list<QPoint>::iterator it;
229 for ( it = myPoints.begin(); it != myPoints.end(); it++, id++ )
230 if ( id == anIndex-1 ) break;
231 myPoints.insert(it, mySelectedPoint);
235 if (myCanvas) myCanvas->update();
238 GuiContext* aContext = GuiContext::getCurrent();
240 if ( aContext->getSubjectProc() )
241 aContext->getSubjectProc()->update( EDIT, DATALINK, 0 );
246 void YACSPrs_Link::removePoint() {
247 if ( mySelected ) setSelected(false);
249 YACSPrs_Point* aPoint = dynamic_cast<YACSPrs_Point*>( mySelectedItem );
251 // TO DO : remove point coordinates from link engine
252 QPoint aP((int)(aPoint->x()), (int)(aPoint->y()));
256 if (myCanvas) myCanvas->update();
259 GuiContext* aContext = GuiContext::getCurrent();
261 if ( aContext->getSubjectProc() )
262 aContext->getSubjectProc()->update( EDIT, DATALINK, 0 );
267 bool YACSPrs_Link::isFirst(QCanvasEllipse* thePoint)
272 myPrs.first()->x() == thePoint->x() && myPrs.first()->y() == thePoint->y() ) aRet = true;
276 bool YACSPrs_Link::isLast(QCanvasEllipse* thePoint)
281 myPrs.last()->x() == thePoint->x() && myPrs.last()->y() == thePoint->y() ) aRet = true;
285 void YACSPrs_Link::setMyZ(double z)
290 double YACSPrs_Link::getMyZ()
295 void YACSPrs_Link::setZ(double z)
297 DEBTRACE("YACSPrs_Link::setZ: " << z);
298 for (QCanvasItemList::Iterator it = myPrs.begin(); it != myPrs.end(); ++it)
299 if ( YACSPrs_Point* pt=dynamic_cast<YACSPrs_Point*>( *it ) )
301 DEBTRACE("YACSPrs_Link::setZ: " << z);
304 else if (YACSPrs_Edge* ed= dynamic_cast<YACSPrs_Edge*>( *it ) )
306 DEBTRACE("YACSPrs_Link::setZ: " << z);
311 double YACSPrs_Link::z()
313 if ( !myPrs.empty() ) return myPrs.first()->z();
317 QPoint YACSPrs_Link::getConnectionPoint(YACSPrs_Port* thePort)
319 DEBTRACE("YACSPrs_Link::getConnectionPoint");
322 YACSPrs_InOutPort* anIOPort = dynamic_cast<YACSPrs_InOutPort*>( thePort );
325 aCP = anIOPort->getConnectionPoint();
326 if ( anIOPort->isGate() )
327 aCP += QPoint( ( anIOPort->isInput() ? -LINKPOINT_SIZE/2-(NODEBOUNDARY_MARGIN+1) :
328 LINKPOINT_SIZE/2+(NODEBOUNDARY_MARGIN+1) ), 0 );
332 YACSPrs_LabelPort* aLPort = dynamic_cast<YACSPrs_LabelPort*>( thePort );
333 if ( aLPort ) aCP = aLPort->getConnectionPoint();
339 void YACSPrs_Link::addPoint(const QPoint& thePoint, const int& theIndex)
341 DEBTRACE("YACSPrs_Link::addPoint");
342 YACSPrs_Point* aPoint;
344 aPoint = new YACSPrs_Point(myCanvas, this, theIndex);
345 aPoint->setColor(myColor);
346 aPoint->move(thePoint.x(), thePoint.y());
349 YACSPrs_Point* aPrev = (YACSPrs_Point*) myPrs.last();
351 YACSPrs_Edge* anEdge = new YACSPrs_Edge(myCanvas, this);
352 anEdge->setColor(myColor);
353 myPrs.append(anEdge);
355 aPoint = new YACSPrs_Point(myCanvas, this, theIndex);
356 aPoint->setColor(myColor);
357 aPoint->move(thePoint.x(), thePoint.y());
359 aPrev->setOutEdge(anEdge);
360 aPoint->setInEdge(anEdge);
362 myPrs.append(aPoint);
365 void YACSPrs_Link::createPrs()
367 QColor aHilightColor = myMgr->colorValue("YACSGui", "link_hilight_color", LINK_HILIGHT_COLOR);
368 setColor(myHilighted ? aHilightColor : myColor);
372 * =========================== YACSPrs_PortLink ===========================
375 YACSPrs_PortLink::YACSPrs_PortLink( SUIT_ResourceMgr* theMgr,
377 YACSPrs_InOutPort* theInputPort,
378 YACSPrs_InOutPort* theOutputPort ):
380 YACSPrs_Link(theMgr, theCanvas),
381 myInputPort(theInputPort),
382 myOutputPort(theOutputPort)
384 DEBTRACE("Construct YACSPrs_PortLink");
385 //change color if datastream link
386 if ( dynamic_cast<DataStreamPort*>(theInputPort->getEngine()))
387 myColor = myMgr->colorValue("YACSGui", "stream_link_draw_color", STREAMLINKDRAW_COLOR);
389 if (myInputPort) myInputPort->addLink(this);
390 if (myOutputPort) myOutputPort->addLink(this);
392 // attach to HMI myself
393 Subject* aSub = getSubject();
395 aSub->attach( this );
398 YACSPrs_PortLink::~YACSPrs_PortLink()
401 YACS::HMI::Subject* aSub = getSubject();
406 myInputPort->removeLink(this);
410 myOutputPort->removeLink(this);
415 void YACSPrs_PortLink::select( bool isSelected )
417 DEBTRACE(">> YACSPrs_PortLink::select");
418 setSelected(isSelected);
421 void YACSPrs_PortLink::update( YACS::HMI::GuiEvent event, int type, YACS::HMI::Subject* son)
423 DEBTRACE(">> YACSPrs_PortLink::update");
426 YACS::HMI::Subject* YACSPrs_PortLink::getSubject() const
430 if ( !myOutputPort || !myInputPort ) return aSub;
432 if ( !myOutputPort->isGate() && !myInputPort->isGate() ) // data link
434 OutPort* anOP = dynamic_cast<OutPort*>( myOutputPort->getEngine() );
435 InPort* anIP = dynamic_cast<InPort*>( myInputPort->getEngine() );
438 GuiContext* aContext = GuiContext::getCurrent();
441 pair<OutPort*,InPort*> aPair(anOP,anIP);
442 if ( aContext->_mapOfSubjectLink.find( aPair ) != aContext->_mapOfSubjectLink.end() )
443 aSub = aContext->_mapOfSubjectLink[ aPair ];
449 OutGate* anOG = dynamic_cast<OutGate*>( myOutputPort->getEngine() );
450 InGate* anIG = dynamic_cast<InGate*>( myInputPort->getEngine() );
453 Node* anON = anOG->getNode();
454 Node* anIN = anIG->getNode();
457 GuiContext* aContext = GuiContext::getCurrent();
460 pair<Node*,Node*> aPair(anON,anIN);
461 if ( aContext->_mapOfSubjectControlLink.find( aPair ) != aContext->_mapOfSubjectControlLink.end() )
462 aSub = aContext->_mapOfSubjectControlLink[ aPair ];
471 void YACSPrs_PortLink::moveByPort(YACSPrs_Port* thePort, bool theMoveInternalLinkPoints, QRect theArea)
473 DEBTRACE("YACSPrs_PortLink::moveByPort");
474 YACSPrs_InOutPort* aPort = dynamic_cast<YACSPrs_InOutPort*>( thePort );
477 QPoint p = getConnectionPoint(aPort);
479 if ( theMoveInternalLinkPoints )
481 // choose and collect only those points from myPoints, which is inside of theArea
482 map<int,QPoint> anIndex2MovePointMap;
484 for ( list<QPoint>::iterator it = myPoints.begin(); it != myPoints.end(); it++, id++)
485 if ( theArea.contains(*it,true) ) anIndex2MovePointMap.insert(make_pair(id,*it));
487 if ( !anIndex2MovePointMap.empty() )
489 QCanvasItemList::Iterator it = myPrs.begin();
490 for (it++; it != myPrs.end(); ++it) {
491 if ( YACSPrs_Point* aPoint = dynamic_cast<YACSPrs_Point*>( *it ) ) {
492 if ( anIndex2MovePointMap.find(aPoint->getIndex()) != anIndex2MovePointMap.end() ) {
494 if ( myInputPort && myInputPort == aPort ) {
495 dx = p.x() - (int)(myPrs.first()->x());
496 dy = p.y() - (int)(myPrs.first()->y());
498 if ( myOutputPort && myOutputPort == aPort ) {
499 if ( getInputPort()->getNode()->isSelfMoving() ) {
500 // move internal points if moveByPort function didn't call yet for the input port of this link
501 // (because we have to move internal points only once on moving link by input or output port)
502 dx = p.x() - (int)(myPrs.last()->x());
503 dy = p.y() - (int)(myPrs.last()->y());
506 aPoint->moveBy( dx, dy );
513 if ( myInputPort && myInputPort == aPort ) {
514 myPrs.first()->move(p.x(), p.y());
517 if ( myOutputPort && myOutputPort == aPort ) {
518 myPrs.last()->move(p.x(), p.y());
524 void YACSPrs_PortLink::moveByPort(YACSPrs_Port* thePort, int dx, int dy)
526 DEBTRACE("YACSPrs_PortLink::moveByPort " << dx << "," << dy);
527 YACSPrs_InOutPort* aPort = dynamic_cast<YACSPrs_InOutPort*>( thePort );
530 if ( myInputPort && myInputPort == aPort ) {
531 myPrs.first()->moveBy(dx, dy);
534 if ( myOutputPort && myOutputPort == aPort ) {
535 myPrs.last()->moveBy(dx, dy);
541 QString YACSPrs_PortLink::getToolTipText() const {
543 if (myInputPort && myOutputPort)
544 aText = myOutputPort->getEngine()->getNode()->getName() + QString(" : ") +
545 myOutputPort->getName() + QString(" => ") +
546 myInputPort->getEngine()->getNode()->getName() + QString(" : ") +
547 myInputPort->getName();
551 void YACSPrs_PortLink::remove() {
552 // for update ports' value after link deletion (only for YACSPrs_InOutPort, i.e. YACSPrs_PortLink)
554 YACSPrs_InOutPort* aPort = dynamic_cast<YACSPrs_InOutPort*>( myInputPort );
556 if (aPort->getEngine()->IsParam() || myInputPort->getEngine()->IsInLine()) {
557 aValue = QString(aPort->getEngine()->ToString());
561 YACSPrs_Link::remove();
563 // for update ports' value after link deletion (only for YACSPrs_InOutPort, i.e. YACSPrs_PortLink)
564 /*if ( aPort && !aValue.isEmpty() ) { //&& GraphLevel() == 0
565 aPort->setValue(aValue);
568 if (myCanvas) myCanvas->update();
571 void YACSPrs_PortLink::createPrs()
573 DEBTRACE("YACSPrs_PortLink::createPrs");
574 // create without internal points now
575 if ( myInputPort ) addPoint(getConnectionPoint(myInputPort),0);
578 for ( list<QPoint>::iterator it = myPoints.begin(); it != myPoints.end(); it++, i++ )
581 if ( myOutputPort ) addPoint(getConnectionPoint(myOutputPort),myPoints.size()+1);
583 // the first and last points is smaller than an internal points
584 if ( QCanvasEllipse* aFP = dynamic_cast<QCanvasEllipse*>( getFirstPoint() ) ) aFP->setSize(LINKPOINT_SIZE/2, LINKPOINT_SIZE/2);
585 if ( QCanvasEllipse* aLP = dynamic_cast<QCanvasEllipse*>( getLastPoint() ) ) aLP->setSize(LINKPOINT_SIZE/2, LINKPOINT_SIZE/2);
587 YACSPrs_Link::createPrs();
590 void YACSPrs_PortLink::setHilighted(bool state)
592 QColor aHilightColor = myMgr->colorValue("YACSGui", "hook_hilight_color", HOOK_HILIGHT_COLOR);
593 QColor aDrawColor = myMgr->colorValue("YACSGui", "hook_color", HOOK_COLOR);
594 QColor aColor = state?aHilightColor:aDrawColor;
597 if (getInputPort()) {
598 YACSPrs_Hook* aHook = getInputPort()->GetHook();
599 if (aHook) aHook->setColor(aColor);
601 if (getOutputPort()) {
602 YACSPrs_Hook* aHook = getOutputPort()->GetHook();
603 if (aHook) aHook->setColor(aColor);
607 YACSPrs_Link::setHilighted(state);
610 void YACSPrs_PortLink::setSelected(bool state)
612 QColor aSelectColor = myMgr->colorValue("YACSGui", "hook_select_color", HOOK_SELECT_COLOR);
613 QColor aDrawColor = myMgr->colorValue("YACSGui", "hook_color", HOOK_COLOR);
614 QColor aColor = state?aSelectColor:aDrawColor;
617 if (getInputPort()) {
618 YACSPrs_Hook* aHook = getInputPort()->GetHook();
620 aHook->setSelected(state);
621 aHook->setColor(aColor);
624 if (getOutputPort()) {
625 YACSPrs_Hook* aHook = getOutputPort()->GetHook();
627 aHook->setSelected(state);
628 aHook->setColor(aColor);
633 YACSPrs_Link::setSelected(state);
637 * =========================== YACSPrs_LabelLink ===========================
640 YACSPrs_LabelLink::YACSPrs_LabelLink( SUIT_ResourceMgr* theMgr,
642 YACSPrs_LabelPort* theOutputPort,
643 YACSPrs_ElementaryNode* theSlaveNode ):
644 YACSPrs_Link(theMgr, theCanvas),
645 myOutputPort(theOutputPort),
646 mySlaveNode(theSlaveNode)
648 DEBTRACE("Construct YACSPrs_LabelLink");
649 if (myOutputPort) myOutputPort->addLink(this);
652 mySlaveNode->addLabelLink(this);
653 mySlaveNode->setMasterPointColor(theOutputPort->Color());
655 myColor = theOutputPort->Color();//LABELLINKDRAW_COLOR;
658 YACSPrs_LabelLink::~YACSPrs_LabelLink()
661 myOutputPort->removeLink(this);
665 mySlaveNode->removeLabelLink();
670 void YACSPrs_LabelLink::moveByPort(YACSPrs_Port* thePort, bool theMoveInternalLinkPoints, QRect theArea)
672 DEBTRACE("YACSPrs_LabelLink::moveByPort");
673 YACSPrs_LabelPort* aPort = dynamic_cast<YACSPrs_LabelPort*>( thePort );
676 QPoint p = getConnectionPoint(aPort);
678 if ( theMoveInternalLinkPoints )
680 // choose and collect only those points from myPoints, which is inside of theArea
681 map<int,QPoint> anIndex2MovePointMap;
683 for ( list<QPoint>::iterator it = myPoints.begin(); it != myPoints.end(); it++, id++)
684 if ( theArea.contains(*it,true) ) anIndex2MovePointMap.insert(make_pair(id,*it));
686 if ( !anIndex2MovePointMap.empty() )
688 QCanvasItemList::Iterator it = myPrs.begin();
689 for (it++; it != myPrs.end(); ++it) {
690 if ( YACSPrs_Point* aPoint = dynamic_cast<YACSPrs_Point*>( *it ) ) {
691 if ( anIndex2MovePointMap.find(aPoint->getIndex()) != anIndex2MovePointMap.end() ) {
693 if ( myOutputPort && myOutputPort == aPort ) {
694 dx = p.x() - (int)(myPrs.last()->x());
695 dy = p.y() - (int)(myPrs.last()->y());
697 aPoint->moveBy( dx, dy );
704 if ( myOutputPort && myOutputPort == aPort ) {
705 myPrs.last()->move(p.x(), p.y());
711 void YACSPrs_LabelLink::moveByPort(YACSPrs_Port* thePort, int dx, int dy)
713 DEBTRACE("YACSPrs_LabelLink::moveByPort " << dx << "," << dy);
714 YACSPrs_LabelPort* aPort = dynamic_cast<YACSPrs_LabelPort*>( thePort );
717 if ( myOutputPort && myOutputPort == aPort ) {
718 myPrs.last()->moveBy(dx, dy);
724 void YACSPrs_LabelLink::moveByNode(YACSPrs_ElementaryNode* theNode)
726 if ( mySlaveNode && mySlaveNode == theNode ) {
727 QPoint p = getConnectionMasterPoint();
728 myPrs.first()->move(p.x(), p.y());
733 void YACSPrs_LabelLink::moveByNode(YACSPrs_ElementaryNode* theNode, int dx, int dy)
735 if ( mySlaveNode && mySlaveNode == theNode ) {
736 myPrs.first()->moveBy(dx, dy);
741 QString YACSPrs_LabelLink::getToolTipText() const {
744 aText = /*<name of node> + QString(" : ") + */
745 myOutputPort->getName() + QString(" => ") +
747 mySlaveNode->getEngine()->getName() + QString("\"");
751 void YACSPrs_LabelLink::remove() {
752 // TO DO : remove slave node from the switch case or loop body
754 YACSPrs_Link::remove();
755 if (myCanvas) myCanvas->update();
758 QPoint YACSPrs_LabelLink::getConnectionMasterPoint()
761 return mySlaveNode->getConnectionMasterPoint() + QPoint(0,HOOKPOINTMASTER_SIZE/4-LINKPOINT_SIZE/2);
766 void YACSPrs_LabelLink::createPrs()
768 // create without internal points now
769 if ( mySlaveNode ) addPoint(getConnectionMasterPoint(),0);
772 for ( list<QPoint>::iterator it = myPoints.begin(); it != myPoints.end(); it++, i++ )
775 if ( myOutputPort ) addPoint(getConnectionPoint(myOutputPort),myPoints.size()+1);
777 // the first and last points is smaller than an internal points
778 if ( QCanvasEllipse* aFP = dynamic_cast<QCanvasEllipse*>( getFirstPoint() ) ) aFP->setSize(LINKPOINT_SIZE/2, LINKPOINT_SIZE/2);
779 if ( QCanvasEllipse* aLP = dynamic_cast<QCanvasEllipse*>( getLastPoint() ) ) aLP->setSize(LINKPOINT_SIZE/2, LINKPOINT_SIZE/2);
781 YACSPrs_Link::createPrs();
784 void YACSPrs_LabelLink::setHilighted(bool state)
786 QColor aHilightColor = myMgr->colorValue("YACSGui", "hook_hilight_color", HOOK_HILIGHT_COLOR);
788 YACSPrs_LabelPort* anOutputPort = getOutputPort();
790 QColor aHookColor = state?aHilightColor:anOutputPort->storeColor();
791 YACSPrs_Hook* aHook = anOutputPort->GetHook();
792 if (aHook) aHook->setColor(aHookColor);
795 if (getSlaveNode()) {
796 QColor aMasterColor = state?aHilightColor:anOutputPort->storeColor();
797 getSlaveNode()->setMasterPointColor(aMasterColor);
800 YACSPrs_Link::setHilighted(state);
803 void YACSPrs_LabelLink::setSelected(bool state)
805 QColor aSelectColor = myMgr->colorValue("YACSGui", "hook_select_color", HOOK_SELECT_COLOR);
807 YACSPrs_LabelPort* anOutputPort = getOutputPort();
809 QColor aHookColor = state?aSelectColor:anOutputPort->storeColor();
810 YACSPrs_Hook* aHook = anOutputPort->GetHook();
812 aHook->setSelected(state);
813 aHook->setColor(aHookColor);
817 if (getSlaveNode()) {
818 if ( getSlaveNode()->getMasterPoint() ) getSlaveNode()->getMasterPoint()->setSelected(state);
819 QColor aMasterColor = state?aSelectColor:anOutputPort->storeColor();
820 getSlaveNode()->setMasterPointColor(aMasterColor);
823 YACSPrs_Link::setSelected(state);
827 * =========================== YACSPrs_Point ===========================
830 YACSPrs_Point::YACSPrs_Point(QCanvas* theCanvas,
831 YACSPrs_Link* theLink,
832 const int& theIndex):
833 QCanvasEllipse(theCanvas),
834 myLink(theLink), myIndex(theIndex),
835 myInEdge(0), myOutEdge(0), myMoving(false), mySelected(false)
837 setSize(LINKPOINT_SIZE, LINKPOINT_SIZE);
841 bool YACSPrs_Point::isMoveable()
843 if ( !myInEdge || !myOutEdge ) return false;
847 void YACSPrs_Point::hilight(const QPoint& theMousePos, const bool toHilight)
849 if ( mySelected ) return;
851 // process the hilighting depending on mouse position
852 if (YACSPrs_Link* aLink = getLink())
853 aLink->setHilighted(toHilight);
856 void YACSPrs_Point::select(const QPoint& theMousePos, const bool toSelect)
858 // unhilight the item under the mouse cursor
859 hilight(theMousePos, false);
861 if (YACSPrs_Link* aLink = getLink())
863 aLink->setSelected(toSelect);
865 YACSPrs_PortLink* aPLink = dynamic_cast<YACSPrs_PortLink*>(aLink);
866 if ( !aPLink ) return;
868 Subject* aSub = aPLink->getSubject();
870 aSub->select(toSelect);
874 void YACSPrs_Point::showPopup(QWidget* theParent, QMouseEvent* theEvent, const QPoint& theMousePos)
876 if ( !getLink() ) return;
878 getLink()->setSelectedObject(this, theMousePos);
880 // construct popup menu
881 QPopupMenu* aPopup = new QPopupMenu(theParent);
882 aPopup->insertItem(QObject::tr("MSG_DEL_POINT"), getLink(), SLOT(removePoint()));
884 CAM_Application* anApp = ( CAM_Application* )(SUIT_Session::session()->activeApplication());
885 if ( !anApp->activeModule() ) return;
886 if ( anApp->activeModule()->moduleName().compare( anApp->moduleTitle( "YACSGui" ) ) !=0 ) return;
888 if (theEvent->button() == RightButton) aPopup->exec(theEvent->globalPos());
891 QString YACSPrs_Point::getToolTipText(const QPoint& theMousePos, QRect& theRect) const
893 if (YACSPrs_Link* aLink = getLink())
895 theRect = QRect(theMousePos.x(), theMousePos.y(), MARGIN, MARGIN);
896 return aLink->getToolTipText();
900 bool YACSPrs_Point::arePartsOfOtherItem(QxGraph_ActiveItem* theSecondItem)
902 if ( YACSPrs_Point* aPoint = dynamic_cast<YACSPrs_Point*>( theSecondItem ) ) {
903 if ( getLink() == aPoint->getLink() ) return true;
905 else if ( YACSPrs_Edge* anEdge = dynamic_cast<YACSPrs_Edge*>( theSecondItem ) ) {
906 if ( getLink() == anEdge->getLink() ) return true;
911 int YACSPrs_Point::rtti() const
913 return 0;//YACSPrs_Canvas::Rtti_Point;
916 void YACSPrs_Point::setInEdge(YACSPrs_Edge* theEdge)
919 theEdge->setFromPoint(this);
922 void YACSPrs_Point::setOutEdge(YACSPrs_Edge* theEdge)
925 theEdge->setToPoint(this);
928 void YACSPrs_Point::moveBy(double dx, double dy)
930 QCanvasEllipse::moveBy(dx, dy);
932 if ( getLink() ) getLink()->updatePoints(this);
934 if (myInEdge) myInEdge->setFromPoint(this);
935 if (myOutEdge) myOutEdge->setToPoint(this);
937 if ( canvas() && getLink() && !getLink()->isEmptyPrs() ) {
938 //resize canvas view if mouse is outside
939 int w = (int)(x()+dx) + width() + GRAPH_MARGIN;
940 int h = (int)(y()+dy) + height() + GRAPH_MARGIN;
941 if (canvas()->width() > w) w = canvas()->width();
942 if (canvas()->height() > h) h = canvas()->height();
943 if (canvas()->width() < w || canvas()->height() < h) canvas()->resize(w, h);
945 //if (myIndex > 0 && isMoving()) {
946 // myLink->getEngine()->ChangeCoord(myIndex, (int)x(), (int)y());
950 void YACSPrs_Point::setColor(const QColor& theColor)
956 * =========================== YACSPrs_Edge ===========================
959 YACSPrs_Edge::YACSPrs_Edge(QCanvas* theCanvas,
960 YACSPrs_Link* theLink):
961 QCanvasLine(theCanvas),
963 myStartPoint(0), myEndPoint(0), mySelected(false)
965 myArrow=new QCanvasPolygon(theCanvas);
969 YACSPrs_Edge::~YACSPrs_Edge()
971 DEBTRACE("YACSPrs_Edge::~YACSPrs_Edge");
972 myArrow->setCanvas(0);
976 bool YACSPrs_Edge::isMoveable()
978 if ( myStartPoint && ( myLink->isFirst(myStartPoint) || myLink->isLast(myStartPoint) )
980 myEndPoint && ( myLink->isFirst(myEndPoint) || myLink->isLast(myEndPoint) ) )
985 void YACSPrs_Edge::hilight(const QPoint& theMousePos, const bool toHilight)
987 if ( mySelected ) return;
989 // process the hilighting depending on mouse position
990 if (YACSPrs_Link* aLink = getLink())
991 aLink->setHilighted(toHilight);
994 void YACSPrs_Edge::select(const QPoint& theMousePos, const bool toSelect)
996 // unhilight the item under the mouse cursor
997 hilight(theMousePos, false);
999 if (YACSPrs_Link* aLink = getLink())
1001 aLink->setSelected(toSelect);
1003 YACSPrs_PortLink* aPLink = dynamic_cast<YACSPrs_PortLink*>(aLink);
1004 if ( !aPLink ) return;
1006 Subject* aSub = aPLink->getSubject();
1008 aSub->select(toSelect);
1012 void YACSPrs_Edge::showPopup(QWidget* theParent, QMouseEvent* theEvent, const QPoint& theMousePos)
1014 if ( !getLink() ) return;
1016 getLink()->setSelectedObject(this, theMousePos);
1018 // construct popup menu
1019 QPopupMenu* aPopup = new QPopupMenu(theParent);
1020 aPopup->insertItem(QObject::tr("MSG_ADD_POINT"), getLink(), SLOT(addPoint()));
1022 CAM_Application* anApp = ( CAM_Application* )(SUIT_Session::session()->activeApplication());
1023 if ( !anApp->activeModule() ) return;
1024 if ( anApp->activeModule()->moduleName().compare( anApp->moduleTitle( "YACSGui" ) ) !=0 ) return;
1026 if (theEvent->button() == RightButton) aPopup->exec(theEvent->globalPos());
1029 QString YACSPrs_Edge::getToolTipText(const QPoint& theMousePos, QRect& theRect) const
1031 if (YACSPrs_Link* aLink = getLink())
1033 theRect = boundingRect();
1034 return aLink->getToolTipText();
1038 bool YACSPrs_Edge::arePartsOfOtherItem(QxGraph_ActiveItem* theSecondItem)
1040 if ( YACSPrs_Point* aPoint = dynamic_cast<YACSPrs_Point*>( theSecondItem ) ) {
1041 if ( getLink() == aPoint->getLink() ) return true;
1043 else if ( YACSPrs_Edge* anEdge = dynamic_cast<YACSPrs_Edge*>( theSecondItem ) ) {
1044 if ( getLink() == anEdge->getLink() ) return true;
1049 int YACSPrs_Edge::rtti() const
1051 return 0;//YACSPrs_Canvas::Rtti_Edge;
1054 void YACSPrs_Edge::setFromPoint(YACSPrs_Point* thePoint)
1056 DEBTRACE("YACSPrs_Edge::setFromPoint");
1057 myStartPoint = thePoint;
1058 setPoints((int)(thePoint->x()), (int)(thePoint->y()), endPoint().x(), endPoint().y());
1062 void YACSPrs_Edge::setToPoint(YACSPrs_Point* thePoint)
1064 DEBTRACE("YACSPrs_Edge::setToPoint");
1065 myEndPoint = thePoint;
1066 setPoints(startPoint().x(), startPoint().y(), (int)(thePoint->x()), (int)(thePoint->y()));
1070 void YACSPrs_Edge::setColor(const QColor& theColor)
1072 setPen(QPen(theColor, LINKEDGE_WIDTH));
1073 myArrow->setBrush(theColor);
1076 void YACSPrs_Edge::moveBy(double dx, double dy)
1078 DEBTRACE("YACSPrs_Edge::moveBy " << dx << "," << dy);
1079 // for moving segment of link
1080 if (myStartPoint && myEndPoint) {
1081 myStartPoint->setMoving(true);
1082 myStartPoint->moveBy(dx, dy);
1084 myEndPoint->setMoving(true);
1085 myEndPoint->moveBy(dx,dy);
1090 void YACSPrs_Edge::setZ(double z)
1092 DEBTRACE("YACSPrs_Edge::setZ: " << z);
1093 QCanvasLine::setZ(z);
1097 void YACSPrs_Edge::setVisible(bool on)
1099 DEBTRACE("YACSPrs_Edge::setVisible " << this << ","<<on);
1100 QCanvasLine::setVisible(on);
1101 myArrow->setVisible(on);
1104 void YACSPrs_Edge::setArrow()
1106 DEBTRACE("YACSPrs_Edge::setArrow");
1107 int x1=startPoint().x();
1108 int y1=startPoint().y();
1109 int x2=endPoint().x();
1110 int y2=endPoint().y();
1111 DEBTRACE(x1 << "," << y1 << "," << x2 << "," << y2 );
1112 double d=hypot(x2-x1,y2-y1);
1113 double x=(x1+x2)/2.;
1114 double y=(y1+y2)/2.;
1127 DEBTRACE(x << "," << y << "," << sina << "," << cosa );
1129 QPointArray pa=QPointArray(3);
1130 pa.setPoint(0, QPoint((int)(x+l*cosa),(int)(y+l*sina)));
1131 pa.setPoint(1, QPoint((int)(x-e*sina),(int)(y+e*cosa)));
1132 pa.setPoint(2, QPoint((int)(x+e*sina),(int)(y-e*cosa)));
1133 myArrow->setPoints(pa);
1137 void YACSPrs_Edge::setCanvas(QCanvas* theCanvas)
1139 DEBTRACE("YACSPrs_Edge::setCanvas");
1140 QCanvasLine::setCanvas(theCanvas);
1141 myArrow->setCanvas(theCanvas);