1 // Copyright (C) 2007-2013 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
23 // SALOME QxGraph : build Supervisor viewer into desktop
25 #include "QxGraph_Prs.h"
27 #include "QxGraph_Canvas.h"
28 #include "QxGraph_Def.h" // for debug only
30 #include "SUIT_Session.h" // for debug only
35 QxGraph_Prs::QxGraph_Prs(QxGraph_Canvas* theCanvas):
40 myCanvas->addPrs(this);
46 QxGraph_Prs::~QxGraph_Prs()
48 for ( DMode2ItemList::iterator it1 = myDisplayMap.begin();
49 it1 != myDisplayMap.end();
52 for ( std::list<QCanvasItem*>::iterator it2 = (*it1).second.begin();
53 it2 != (*it1).second.end();
56 QCanvasItem* anItem = *it2;
57 if ( anItem ) delete anItem;
65 Add item to display in the view with index theDMode
67 void QxGraph_Prs::addItem(QCanvasItem* theItem, int theDMode)
69 if ( theDMode == -1 ) // add item for the current display mode
70 myDisplayMap[myDMode].push_back(theItem);
72 myDisplayMap[theDMode].push_back(theItem);
76 Remove item from the view with index theDMode
78 void QxGraph_Prs::removeItem(QCanvasItem* theItem, int theDMode)
80 if ( theDMode == -1 ) // remove item from the current display mode
81 myDisplayMap[myDMode].remove(theItem);
83 myDisplayMap[theDMode].remove(theItem);
86 /*! Adds all the items of this presentation for the current display mode
89 void QxGraph_Prs::show()
94 for ( std::list<QCanvasItem*>::iterator it = myDisplayMap[myDMode].begin();
95 it != myDisplayMap[myDMode].end();
98 QCanvasItem* anItem = *it;
101 anItem->setCanvas( myCanvas );
107 /*! Removes all the items belonging to this presentation from the canvas.
109 void QxGraph_Prs::hide()
111 for ( DMode2ItemList::iterator it1 = myDisplayMap.begin();
112 it1 != myDisplayMap.end();
115 for ( std::list<QCanvasItem*>::iterator it2 = (*it1).second.begin();
116 it2 != (*it1).second.end();
119 QCanvasItem* anItem = *it2;
122 anItem->setCanvas( 0 );
128 /*! Prepare for full recomputation of the presentation
130 void QxGraph_Prs::setToUpdate( const bool theFlag )
132 needUpdate = theFlag;
135 /*! Re-fills the presentation with items.
136 * Base implementation just resets <needUpdate> flag.
137 * It should be called at the end by re-implementations.
139 void QxGraph_Prs::update()
141 setToUpdate( false );
145 Add a QCanvasRectangle item for display mode DMode
147 QCanvasItem* QxGraph_Prs::addRectangleItem(QRect theRect, int theDMode)
149 QCanvasRectangle* aRectItem;
152 QCanvasRectangle* aRectItem = new QCanvasRectangle(theRect, myCanvas);
157 // test drawing features: brush, pen ...
158 QBrush aBr(SUIT_Session::session()->resourceMgr()->colorValue( "QxGraph", "NodeBody", RECTANGLE_BODY ));
159 aRectItem->setBrush(aBr);
166 Add a QCanvasPolygon item for display mode DMode
168 QCanvasItem* QxGraph_Prs::addPolygonItem(QPointArray thePA, int theDMode)
170 QCanvasPolygon* aPolyItem;
173 aPolyItem = new QCanvasPolygon(myCanvas);
175 aPolyItem->setPoints(thePA);
179 // test drawing features: brush, pen ...
180 QBrush aBr(SUIT_Session::session()->resourceMgr()->colorValue( "QxGraph", "NodeBody", RECTANGLE_BODY ));
181 aPolyItem->setBrush(aBr);
182 QPen aPen(Qt::black,2);
183 aPolyItem->setPen(aPen);
190 Add a QCanvasLine item for display mode DMode
192 QCanvasItem* QxGraph_Prs::addLineItem(QPoint theStart, QPoint theEnd, int theDMode)
194 QCanvasLine* aLineItem;
197 aLineItem = new QCanvasLine(myCanvas);
199 aLineItem->setPoints(theStart.x(), theStart.y(), theEnd.x(), theEnd.y());
203 // test drawing features: brush, pen ...
204 QPen aPen(Qt::black,2);
205 aLineItem->setPen(aPen);
212 Add a QCanvasEllipse item for display mode DMode
214 QCanvasItem* QxGraph_Prs::addEllipseItem(int theW, int theH, int theStartAngle, int theAngle, int theDMode)
216 QCanvasEllipse* aEllipseItem;
219 aEllipseItem = new QCanvasEllipse(theW, theH, theStartAngle, theAngle, myCanvas);
220 aEllipseItem->setZ(0);
221 aEllipseItem->show();
224 // test drawing features: brush, pen ...
225 QBrush aBr(SUIT_Session::session()->resourceMgr()->colorValue( "QxGraph", "NodeBody", RECTANGLE_BODY ));
226 aEllipseItem->setBrush(aBr);
227 QPen aPen(Qt::black,2);
228 aEllipseItem->setPen(aPen);
230 addItem(aEllipseItem);
235 Add a QCanvasText item for display mode DMode
237 QCanvasItem* QxGraph_Prs::addTextItem(QString theText, int theDMode)
239 QCanvasText* aTextItem;
242 aTextItem = new QCanvasText(theText, myCanvas);
247 // test drawing features: font, color, text flags ...
248 aTextItem->setColor(Qt::darkBlue);
249 //aTextItem->setFont(QFont("Times"/*"Helvetica"*/, 14, QFont::Normal, true));