1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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 // SALOME QxGraph : build Supervisor viewer into desktop
24 #include "QxGraph_Prs.h"
26 #include "QxGraph_Canvas.h"
27 #include "QxGraph_Def.h" // for debug only
29 #include "SUIT_Session.h" // for debug only
34 QxGraph_Prs::QxGraph_Prs(QxGraph_Canvas* theCanvas):
39 myCanvas->addPrs(this);
45 QxGraph_Prs::~QxGraph_Prs()
47 for ( DMode2ItemList::iterator it1 = myDisplayMap.begin();
48 it1 != myDisplayMap.end();
51 for ( std::list<QCanvasItem*>::iterator it2 = (*it1).second.begin();
52 it2 != (*it1).second.end();
55 QCanvasItem* anItem = *it2;
56 if ( anItem ) delete anItem;
64 Add item to display in the view with index theDMode
66 void QxGraph_Prs::addItem(QCanvasItem* theItem, int theDMode)
68 if ( theDMode == -1 ) // add item for the current display mode
69 myDisplayMap[myDMode].push_back(theItem);
71 myDisplayMap[theDMode].push_back(theItem);
75 Remove item from the view with index theDMode
77 void QxGraph_Prs::removeItem(QCanvasItem* theItem, int theDMode)
79 if ( theDMode == -1 ) // remove item from the current display mode
80 myDisplayMap[myDMode].remove(theItem);
82 myDisplayMap[theDMode].remove(theItem);
85 /*! Adds all the items of this presentation for the current display mode
88 void QxGraph_Prs::show()
93 for ( std::list<QCanvasItem*>::iterator it = myDisplayMap[myDMode].begin();
94 it != myDisplayMap[myDMode].end();
97 QCanvasItem* anItem = *it;
100 anItem->setCanvas( myCanvas );
106 /*! Removes all the items belonging to this presentation from the canvas.
108 void QxGraph_Prs::hide()
110 for ( DMode2ItemList::iterator it1 = myDisplayMap.begin();
111 it1 != myDisplayMap.end();
114 for ( std::list<QCanvasItem*>::iterator it2 = (*it1).second.begin();
115 it2 != (*it1).second.end();
118 QCanvasItem* anItem = *it2;
121 anItem->setCanvas( 0 );
127 /*! Prepare for full recomputation of the presentation
129 void QxGraph_Prs::setToUpdate( const bool theFlag )
131 needUpdate = theFlag;
134 /*! Re-fills the presentation with items.
135 * Base implementation just resets <needUpdate> flag.
136 * It should be called at the end by re-implementations.
138 void QxGraph_Prs::update()
140 setToUpdate( false );
144 Add a QCanvasRectangle item for display mode DMode
146 QCanvasItem* QxGraph_Prs::addRectangleItem(QRect theRect, int theDMode)
148 QCanvasRectangle* aRectItem;
151 QCanvasRectangle* aRectItem = new QCanvasRectangle(theRect, myCanvas);
156 // test drawing features: brush, pen ...
157 QBrush aBr(SUIT_Session::session()->resourceMgr()->colorValue( "QxGraph", "NodeBody", RECTANGLE_BODY ));
158 aRectItem->setBrush(aBr);
165 Add a QCanvasPolygon item for display mode DMode
167 QCanvasItem* QxGraph_Prs::addPolygonItem(QPointArray thePA, int theDMode)
169 QCanvasPolygon* aPolyItem;
172 aPolyItem = new QCanvasPolygon(myCanvas);
174 aPolyItem->setPoints(thePA);
178 // test drawing features: brush, pen ...
179 QBrush aBr(SUIT_Session::session()->resourceMgr()->colorValue( "QxGraph", "NodeBody", RECTANGLE_BODY ));
180 aPolyItem->setBrush(aBr);
181 QPen aPen(Qt::black,2);
182 aPolyItem->setPen(aPen);
189 Add a QCanvasLine item for display mode DMode
191 QCanvasItem* QxGraph_Prs::addLineItem(QPoint theStart, QPoint theEnd, int theDMode)
193 QCanvasLine* aLineItem;
196 aLineItem = new QCanvasLine(myCanvas);
198 aLineItem->setPoints(theStart.x(), theStart.y(), theEnd.x(), theEnd.y());
202 // test drawing features: brush, pen ...
203 QPen aPen(Qt::black,2);
204 aLineItem->setPen(aPen);
211 Add a QCanvasEllipse item for display mode DMode
213 QCanvasItem* QxGraph_Prs::addEllipseItem(int theW, int theH, int theStartAngle, int theAngle, int theDMode)
215 QCanvasEllipse* aEllipseItem;
218 aEllipseItem = new QCanvasEllipse(theW, theH, theStartAngle, theAngle, myCanvas);
219 aEllipseItem->setZ(0);
220 aEllipseItem->show();
223 // test drawing features: brush, pen ...
224 QBrush aBr(SUIT_Session::session()->resourceMgr()->colorValue( "QxGraph", "NodeBody", RECTANGLE_BODY ));
225 aEllipseItem->setBrush(aBr);
226 QPen aPen(Qt::black,2);
227 aEllipseItem->setPen(aPen);
229 addItem(aEllipseItem);
234 Add a QCanvasText item for display mode DMode
236 QCanvasItem* QxGraph_Prs::addTextItem(QString theText, int theDMode)
238 QCanvasText* aTextItem;
241 aTextItem = new QCanvasText(theText, myCanvas);
246 // test drawing features: font, color, text flags ...
247 aTextItem->setColor(Qt::darkBlue);
248 //aTextItem->setFont(QFont("Times"/*"Helvetica"*/, 14, QFont::Normal, true));