]> SALOME platform Git repositories - modules/gui.git/blob - src/QxGraph/QxGraph_Prs.cxx
Salome HOME
efe4687c0b8f79fc3f350793d5a94a8280d29814
[modules/gui.git] / src / QxGraph / QxGraph_Prs.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //  SALOME QxGraph : build Supervisor viewer into desktop
23 //
24 #include "QxGraph_Prs.h"
25
26 #include "QxGraph_Canvas.h"
27 #include "QxGraph_Def.h" // for debug only
28
29 #include "SUIT_Session.h" // for debug only
30
31 /*!
32   Constructor
33 */
34 QxGraph_Prs::QxGraph_Prs(QxGraph_Canvas* theCanvas):
35   myCanvas(theCanvas),
36   myDMode(0),
37   needUpdate(true)
38 {
39   myCanvas->addPrs(this);
40 }
41
42 /*!
43   Destructor
44 */
45 QxGraph_Prs::~QxGraph_Prs()
46 {
47   for ( DMode2ItemList::iterator it1 = myDisplayMap.begin();
48         it1 != myDisplayMap.end();
49         it1++ )
50   {
51     for ( std::list<QCanvasItem*>::iterator it2 = (*it1).second.begin();
52           it2 != (*it1).second.end();
53           it2++ )
54     {
55       QCanvasItem* anItem = *it2;
56       if ( anItem ) delete anItem;
57     }
58   }
59       
60   myDisplayMap.clear();
61 }
62
63 /*!
64   Add item to display in the view with index theDMode
65 */
66 void QxGraph_Prs::addItem(QCanvasItem* theItem, int theDMode)
67 {
68   if ( theDMode == -1 ) // add item for the current display mode
69     myDisplayMap[myDMode].push_back(theItem);
70   else
71     myDisplayMap[theDMode].push_back(theItem);
72 }
73
74 /*!
75   Remove item from the view with index theDMode
76 */
77 void QxGraph_Prs::removeItem(QCanvasItem* theItem, int theDMode)
78 {
79   if ( theDMode == -1 ) // remove item from the current display mode
80     myDisplayMap[myDMode].remove(theItem);
81   else
82     myDisplayMap[theDMode].remove(theItem);
83 }
84
85 /*! Adds all the items of this presentation for the current display mode
86  *  to the canvas.
87  */
88 void QxGraph_Prs::show()
89 {
90   if ( isToUpdate() ) 
91     update();
92
93   for ( std::list<QCanvasItem*>::iterator it = myDisplayMap[myDMode].begin();
94         it != myDisplayMap[myDMode].end();
95         it++ )
96   {
97     QCanvasItem* anItem = *it;
98     if ( anItem )
99     {
100       anItem->setCanvas( myCanvas );
101       anItem->show();
102     }
103   }
104 }
105
106 /*! Removes all the items belonging to this presentation from the canvas.
107  */
108 void QxGraph_Prs::hide()
109 {
110   for ( DMode2ItemList::iterator it1 = myDisplayMap.begin();
111         it1 != myDisplayMap.end();
112         it1++ )
113   {
114     for ( std::list<QCanvasItem*>::iterator it2 = (*it1).second.begin();
115           it2 != (*it1).second.end();
116           it2++ )
117     {
118       QCanvasItem* anItem = *it2;
119       if ( anItem )
120       {
121         anItem->setCanvas( 0 );
122       }
123     }
124   }
125 }
126
127 /*! Prepare for full recomputation of the presentation
128  */
129 void QxGraph_Prs::setToUpdate( const bool theFlag )
130 {
131   needUpdate = theFlag;
132 }
133
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.
137  */
138 void QxGraph_Prs::update()
139 {
140   setToUpdate( false );
141 }
142
143 /*!
144   Add a QCanvasRectangle item for display mode DMode
145 */
146 QCanvasItem* QxGraph_Prs::addRectangleItem(QRect theRect, int theDMode)
147 {
148   QCanvasRectangle* aRectItem;
149   if ( myCanvas )
150   {
151     QCanvasRectangle* aRectItem = new QCanvasRectangle(theRect, myCanvas);
152     aRectItem->setZ(0);
153     aRectItem->show();
154     myCanvas->update();
155     
156     // test drawing features: brush, pen ...
157     QBrush aBr(SUIT_Session::session()->resourceMgr()->colorValue( "QxGraph", "NodeBody", RECTANGLE_BODY ));
158     aRectItem->setBrush(aBr);
159   }
160   addItem(aRectItem);
161   return aRectItem;
162 }
163
164 /*!
165   Add a QCanvasPolygon item for display mode DMode
166 */
167 QCanvasItem* QxGraph_Prs::addPolygonItem(QPointArray thePA, int theDMode)
168 {
169   QCanvasPolygon* aPolyItem;
170   if ( myCanvas )
171   {
172     aPolyItem = new QCanvasPolygon(myCanvas);
173     aPolyItem->setZ(0);
174     aPolyItem->setPoints(thePA);
175     aPolyItem->show();
176     myCanvas->update();
177     
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);
183   }
184   addItem(aPolyItem);
185   return aPolyItem;
186 }
187
188 /*!
189   Add a QCanvasLine item for display mode DMode
190 */
191 QCanvasItem* QxGraph_Prs::addLineItem(QPoint theStart, QPoint theEnd, int theDMode)
192 {
193   QCanvasLine* aLineItem;
194   if ( myCanvas )
195   {
196     aLineItem = new QCanvasLine(myCanvas);
197     aLineItem->setZ(0);
198     aLineItem->setPoints(theStart.x(), theStart.y(), theEnd.x(), theEnd.y());
199     aLineItem->show();
200     myCanvas->update();
201   
202     // test drawing features: brush, pen ...
203     QPen aPen(Qt::black,2);
204     aLineItem->setPen(aPen);
205   }
206   addItem(aLineItem);
207   return aLineItem;
208 }
209
210 /*!
211   Add a QCanvasEllipse item for display mode DMode
212 */
213 QCanvasItem* QxGraph_Prs::addEllipseItem(int theW, int theH, int theStartAngle, int theAngle, int theDMode)
214 {
215   QCanvasEllipse* aEllipseItem;
216   if ( myCanvas )
217   {
218     aEllipseItem = new QCanvasEllipse(theW, theH, theStartAngle, theAngle, myCanvas);
219     aEllipseItem->setZ(0);
220     aEllipseItem->show();
221     myCanvas->update();
222     
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);
228   }
229   addItem(aEllipseItem);
230   return aEllipseItem;
231 }
232
233 /*!
234   Add a QCanvasText item for display mode DMode
235 */
236 QCanvasItem* QxGraph_Prs::addTextItem(QString theText, int theDMode)
237 {
238   QCanvasText* aTextItem;
239   if ( myCanvas )
240   {
241     aTextItem = new QCanvasText(theText, myCanvas);
242     aTextItem->setZ(0);
243     aTextItem->show();
244     myCanvas->update();
245     
246     // test drawing features: font, color, text flags ...
247     aTextItem->setColor(Qt::darkBlue);
248     //aTextItem->setFont(QFont("Times"/*"Helvetica"*/, 14, QFont::Normal, true));
249   }
250   addItem(aTextItem);
251   return aTextItem;
252 }