1 // SALOME QxGraph : build Supervisor viewer into desktop
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
23 #include "QxGraph_Prs.h"
25 #include "QxGraph_Canvas.h"
26 #include "QxGraph_Def.h" // for debug only
28 #include "SUIT_Session.h" // for debug only
33 QxGraph_Prs::QxGraph_Prs(QxGraph_Canvas* theCanvas):
38 myCanvas->addPrs(this);
44 QxGraph_Prs::~QxGraph_Prs()
46 for ( DMode2ItemList::iterator it1 = myDisplayMap.begin();
47 it1 != myDisplayMap.end();
50 for ( std::list<QCanvasItem*>::iterator it2 = (*it1).second.begin();
51 it2 != (*it1).second.end();
54 QCanvasItem* anItem = *it2;
55 if ( anItem ) delete anItem;
63 Add item to display in the view with index theDMode
65 void QxGraph_Prs::addItem(QCanvasItem* theItem, int theDMode)
67 if ( theDMode == -1 ) // add item for the current display mode
68 myDisplayMap[myDMode].push_back(theItem);
70 myDisplayMap[theDMode].push_back(theItem);
74 Remove item from the view with index theDMode
76 void QxGraph_Prs::removeItem(QCanvasItem* theItem, int theDMode)
78 if ( theDMode == -1 ) // remove item from the current display mode
79 myDisplayMap[myDMode].remove(theItem);
81 myDisplayMap[theDMode].remove(theItem);
84 /*! Adds all the items of this presentation for the current display mode
87 void QxGraph_Prs::show()
92 for ( std::list<QCanvasItem*>::iterator it = myDisplayMap[myDMode].begin();
93 it != myDisplayMap[myDMode].end();
96 QCanvasItem* anItem = *it;
99 anItem->setCanvas( myCanvas );
105 /*! Removes all the items belonging to this presentation from the canvas.
107 void QxGraph_Prs::hide()
109 for ( DMode2ItemList::iterator it1 = myDisplayMap.begin();
110 it1 != myDisplayMap.end();
113 for ( std::list<QCanvasItem*>::iterator it2 = (*it1).second.begin();
114 it2 != (*it1).second.end();
117 QCanvasItem* anItem = *it2;
120 anItem->setCanvas( 0 );
126 /*! Prepare for full recomputation of the presentation
128 void QxGraph_Prs::setToUpdate( const bool theFlag )
130 needUpdate = theFlag;
133 /*! Re-fills the presentation with items.
134 * Base implementation just resets <needUpdate> flag.
135 * It should be called at the end by re-implementations.
137 void QxGraph_Prs::update()
139 setToUpdate( false );
143 Add a QCanvasRectangle item for display mode DMode
145 QCanvasItem* QxGraph_Prs::addRectangleItem(QRect theRect, int theDMode)
147 QCanvasRectangle* aRectItem;
150 QCanvasRectangle* aRectItem = new QCanvasRectangle(theRect, myCanvas);
155 // test drawing features: brush, pen ...
156 QBrush aBr(SUIT_Session::session()->resourceMgr()->colorValue( "QxGraph", "NodeBody", RECTANGLE_BODY ));
157 aRectItem->setBrush(aBr);
164 Add a QCanvasPolygon item for display mode DMode
166 QCanvasItem* QxGraph_Prs::addPolygonItem(QPointArray thePA, int theDMode)
168 QCanvasPolygon* aPolyItem;
171 aPolyItem = new QCanvasPolygon(myCanvas);
173 aPolyItem->setPoints(thePA);
177 // test drawing features: brush, pen ...
178 QBrush aBr(SUIT_Session::session()->resourceMgr()->colorValue( "QxGraph", "NodeBody", RECTANGLE_BODY ));
179 aPolyItem->setBrush(aBr);
180 QPen aPen(Qt::black,2);
181 aPolyItem->setPen(aPen);
188 Add a QCanvasLine item for display mode DMode
190 QCanvasItem* QxGraph_Prs::addLineItem(QPoint theStart, QPoint theEnd, int theDMode)
192 QCanvasLine* aLineItem;
195 aLineItem = new QCanvasLine(myCanvas);
197 aLineItem->setPoints(theStart.x(), theStart.y(), theEnd.x(), theEnd.y());
201 // test drawing features: brush, pen ...
202 QPen aPen(Qt::black,2);
203 aLineItem->setPen(aPen);
210 Add a QCanvasEllipse item for display mode DMode
212 QCanvasItem* QxGraph_Prs::addEllipseItem(int theW, int theH, int theStartAngle, int theAngle, int theDMode)
214 QCanvasEllipse* aEllipseItem;
217 aEllipseItem = new QCanvasEllipse(theW, theH, theStartAngle, theAngle, myCanvas);
218 aEllipseItem->setZ(0);
219 aEllipseItem->show();
222 // test drawing features: brush, pen ...
223 QBrush aBr(SUIT_Session::session()->resourceMgr()->colorValue( "QxGraph", "NodeBody", RECTANGLE_BODY ));
224 aEllipseItem->setBrush(aBr);
225 QPen aPen(Qt::black,2);
226 aEllipseItem->setPen(aPen);
228 addItem(aEllipseItem);
233 Add a QCanvasText item for display mode DMode
235 QCanvasItem* QxGraph_Prs::addTextItem(QString theText, int theDMode)
237 QCanvasText* aTextItem;
240 aTextItem = new QCanvasText(theText, myCanvas);
245 // test drawing features: font, color, text flags ...
246 aTextItem->setColor(Qt::darkBlue);
247 //aTextItem->setFont(QFont("Times"/*"Helvetica"*/, 14, QFont::Normal, true));