Back to index

salome-gui  6.5.0
QxGraph_Prs.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 //  SALOME QxGraph : build Supervisor viewer into desktop
00024 //
00025 #include "QxGraph_Prs.h"
00026 
00027 #include "QxGraph_Canvas.h"
00028 #include "QxGraph_Def.h" // for debug only
00029 
00030 #include "SUIT_Session.h" // for debug only
00031 
00035 QxGraph_Prs::QxGraph_Prs(QxGraph_Canvas* theCanvas):
00036   myCanvas(theCanvas),
00037   myDMode(0),
00038   needUpdate(true)
00039 {
00040   myCanvas->addPrs(this);
00041 }
00042 
00046 QxGraph_Prs::~QxGraph_Prs()
00047 {
00048   for ( DMode2ItemList::iterator it1 = myDisplayMap.begin();
00049         it1 != myDisplayMap.end();
00050         it1++ )
00051   {
00052     for ( std::list<QCanvasItem*>::iterator it2 = (*it1).second.begin();
00053           it2 != (*it1).second.end();
00054           it2++ )
00055     {
00056       QCanvasItem* anItem = *it2;
00057       if ( anItem ) delete anItem;
00058     }
00059   }
00060       
00061   myDisplayMap.clear();
00062 }
00063 
00067 void QxGraph_Prs::addItem(QCanvasItem* theItem, int theDMode)
00068 {
00069   if ( theDMode == -1 ) // add item for the current display mode
00070     myDisplayMap[myDMode].push_back(theItem);
00071   else
00072     myDisplayMap[theDMode].push_back(theItem);
00073 }
00074 
00078 void QxGraph_Prs::removeItem(QCanvasItem* theItem, int theDMode)
00079 {
00080   if ( theDMode == -1 ) // remove item from the current display mode
00081     myDisplayMap[myDMode].remove(theItem);
00082   else
00083     myDisplayMap[theDMode].remove(theItem);
00084 }
00085 
00089 void QxGraph_Prs::show()
00090 {
00091   if ( isToUpdate() ) 
00092     update();
00093 
00094   for ( std::list<QCanvasItem*>::iterator it = myDisplayMap[myDMode].begin();
00095         it != myDisplayMap[myDMode].end();
00096         it++ )
00097   {
00098     QCanvasItem* anItem = *it;
00099     if ( anItem )
00100     {
00101       anItem->setCanvas( myCanvas );
00102       anItem->show();
00103     }
00104   }
00105 }
00106 
00109 void QxGraph_Prs::hide()
00110 {
00111   for ( DMode2ItemList::iterator it1 = myDisplayMap.begin();
00112         it1 != myDisplayMap.end();
00113         it1++ )
00114   {
00115     for ( std::list<QCanvasItem*>::iterator it2 = (*it1).second.begin();
00116           it2 != (*it1).second.end();
00117           it2++ )
00118     {
00119       QCanvasItem* anItem = *it2;
00120       if ( anItem )
00121       {
00122         anItem->setCanvas( 0 );
00123       }
00124     }
00125   }
00126 }
00127 
00130 void QxGraph_Prs::setToUpdate( const bool theFlag )
00131 {
00132   needUpdate = theFlag;
00133 }
00134 
00139 void QxGraph_Prs::update()
00140 {
00141   setToUpdate( false );
00142 }
00143 
00147 QCanvasItem* QxGraph_Prs::addRectangleItem(QRect theRect, int theDMode)
00148 {
00149   QCanvasRectangle* aRectItem;
00150   if ( myCanvas )
00151   {
00152     QCanvasRectangle* aRectItem = new QCanvasRectangle(theRect, myCanvas);
00153     aRectItem->setZ(0);
00154     aRectItem->show();
00155     myCanvas->update();
00156     
00157     // test drawing features: brush, pen ...
00158     QBrush aBr(SUIT_Session::session()->resourceMgr()->colorValue( "QxGraph", "NodeBody", RECTANGLE_BODY ));
00159     aRectItem->setBrush(aBr);
00160   }
00161   addItem(aRectItem);
00162   return aRectItem;
00163 }
00164 
00168 QCanvasItem* QxGraph_Prs::addPolygonItem(QPointArray thePA, int theDMode)
00169 {
00170   QCanvasPolygon* aPolyItem;
00171   if ( myCanvas )
00172   {
00173     aPolyItem = new QCanvasPolygon(myCanvas);
00174     aPolyItem->setZ(0);
00175     aPolyItem->setPoints(thePA);
00176     aPolyItem->show();
00177     myCanvas->update();
00178     
00179     // test drawing features: brush, pen ...
00180     QBrush aBr(SUIT_Session::session()->resourceMgr()->colorValue( "QxGraph", "NodeBody", RECTANGLE_BODY ));
00181     aPolyItem->setBrush(aBr);
00182     QPen aPen(Qt::black,2);
00183     aPolyItem->setPen(aPen);
00184   }
00185   addItem(aPolyItem);
00186   return aPolyItem;
00187 }
00188 
00192 QCanvasItem* QxGraph_Prs::addLineItem(QPoint theStart, QPoint theEnd, int theDMode)
00193 {
00194   QCanvasLine* aLineItem;
00195   if ( myCanvas )
00196   {
00197     aLineItem = new QCanvasLine(myCanvas);
00198     aLineItem->setZ(0);
00199     aLineItem->setPoints(theStart.x(), theStart.y(), theEnd.x(), theEnd.y());
00200     aLineItem->show();
00201     myCanvas->update();
00202   
00203     // test drawing features: brush, pen ...
00204     QPen aPen(Qt::black,2);
00205     aLineItem->setPen(aPen);
00206   }
00207   addItem(aLineItem);
00208   return aLineItem;
00209 }
00210 
00214 QCanvasItem* QxGraph_Prs::addEllipseItem(int theW, int theH, int theStartAngle, int theAngle, int theDMode)
00215 {
00216   QCanvasEllipse* aEllipseItem;
00217   if ( myCanvas )
00218   {
00219     aEllipseItem = new QCanvasEllipse(theW, theH, theStartAngle, theAngle, myCanvas);
00220     aEllipseItem->setZ(0);
00221     aEllipseItem->show();
00222     myCanvas->update();
00223     
00224     // test drawing features: brush, pen ...
00225     QBrush aBr(SUIT_Session::session()->resourceMgr()->colorValue( "QxGraph", "NodeBody", RECTANGLE_BODY ));
00226     aEllipseItem->setBrush(aBr);
00227     QPen aPen(Qt::black,2);
00228     aEllipseItem->setPen(aPen);
00229   }
00230   addItem(aEllipseItem);
00231   return aEllipseItem;
00232 }
00233 
00237 QCanvasItem* QxGraph_Prs::addTextItem(QString theText, int theDMode)
00238 {
00239   QCanvasText* aTextItem;
00240   if ( myCanvas )
00241   {
00242     aTextItem = new QCanvasText(theText, myCanvas);
00243     aTextItem->setZ(0);
00244     aTextItem->show();
00245     myCanvas->update();
00246     
00247     // test drawing features: font, color, text flags ...
00248     aTextItem->setColor(Qt::darkBlue);
00249     //aTextItem->setFont(QFont("Times"/*"Helvetica"*/, 14, QFont::Normal, true));
00250   }
00251   addItem(aTextItem);
00252   return aTextItem;
00253 }