Back to index

salome-gui  6.5.0
Enumerations | Functions
Plot2d Namespace Reference

Enumerations

enum  MarkerType {
  None, Circle, Rectangle, Diamond,
  DTriangle, UTriangle, LTriangle, RTriangle,
  Cross, XCross
}
enum  LineType {
  NoPen, Solid, Dash, Dot,
  DashDot, DashDotDot
}

Functions

QwtSymbol::Style plot2qwtMarker (MarkerType)
 Convert Plot2d marker type to Qwt marker type.
MarkerType qwt2plotMarker (QwtSymbol::Style)
 Convert Qwt marker type to Plot2d marker type.
Qt::PenStyle plot2qwtLine (LineType)
 Convert Plot2d line type to Qt/Qwt line type.
LineType qwt2plotLine (Qt::PenStyle)
 Convert Qt/Qwt line type to Plot2d line type.
void drawLine (QPainter *, const QPoint &, const QPoint &, Qt::PenStyle=Qt::SolidLine, const QColor &=Qt::black, int=0)
 Draw line.
void drawLine (QPainter *, const QPoint &, const QPoint &, LineType=Solid, const QColor &=Qt::black, int=0)
 Draw line.
void drawLine (QPainter *, int, int, int, int, Qt::PenStyle=Qt::SolidLine, const QColor &=Qt::black, int=0)
 Draw line.
void drawLine (QPainter *, int, int, int, int, LineType=Solid, const QColor &=Qt::black, int=0)
 Draw line.
void drawMarker (QPainter *, const QPoint &, const QRect &, QwtSymbol::Style=QwtSymbol::Ellipse, const QColor &=Qt::black)
 Draw marker.
void drawMarker (QPainter *, const QPoint &, const QRect &, MarkerType=Circle, const QColor &=Qt::black)
 Draw marker.
void drawMarker (QPainter *, int, int, int, int, QwtSymbol::Style=QwtSymbol::Ellipse, const QColor &=Qt::black)
 Draw marker.
void drawMarker (QPainter *, int, int, int, int, MarkerType=Circle, const QColor &=Qt::black)
 Draw marker.
QPixmap markerIcon (const QSize &, const QColor &, Plot2d::MarkerType)
 Create icon pixmap according to the marker type.
QPixmap lineIcon (const QSize &, const QColor &, Plot2d::LineType)
 Create icon pixmap according to the line type.
void getNextMarker (const int rtti, const QwtPlot *, QwtSymbol::Style &, QColor &, Qt::PenStyle &)
 Gets new unique marker for item if possible.
bool existMarker (const int rtti, const QwtPlot *, const QwtSymbol::Style, const QColor &, const Qt::PenStyle)
 Checks if marker belongs to any enitity.
bool closeColors (const QColor &, const QColor &, int distance=-1)
 Checks if two colors are close to each other uses COLOR_DISTANCE variable as max tolerance for comparing of colors.

Enumeration Type Documentation

Enumerator:
NoPen 
Solid 
Dash 
Dot 
DashDot 
DashDotDot 

Definition at line 84 of file Plot2d.h.

Enumerator:
None 
Circle 
Rectangle 
Diamond 
DTriangle 
UTriangle 
LTriangle 
RTriangle 
Cross 
XCross 

Definition at line 72 of file Plot2d.h.


Function Documentation

bool Plot2d::closeColors ( const QColor &  color1,
const QColor &  color2,
int  distance = -1 
)

Checks if two colors are close to each other uses COLOR_DISTANCE variable as max tolerance for comparing of colors.

Definition at line 548 of file Plot2d.cxx.

{
  long tol = 
    qAbs( color2.red()   - color1.red()   ) + 
    qAbs( color2.green() - color1.green() ) +
    qAbs( color2.blue()  - color1.blue()  ) -
    ( distance < 0 ? COLOR_DISTANCE : distance );

  return tol <= 0;
}

Here is the caller graph for this function:

void Plot2d::drawLine ( QPainter *  painter,
const QPoint &  p1,
const QPoint &  p2,
Qt::PenStyle  type = Qt::SolidLine,
const QColor &  color = Qt::black,
int  width = 0 
)

Draw line.

Parameters:
painterpainter
p1starting point
p2ending point
typeline type
colorline color
widthline width

Definition at line 255 of file Plot2d.cxx.

{
  painter->save();
  QPen pen( type );
  pen.setColor( color );
  pen.setWidth( width );
  painter->setPen( pen );
  painter->drawLine( p1, p2 );
  painter->restore();
}

Here is the caller graph for this function:

void Plot2d::drawLine ( QPainter *  painter,
const QPoint &  p1,
const QPoint &  p2,
Plot2d::LineType  type = Solid,
const QColor &  color = Qt::black,
int  width = 0 
)

Draw line.

Parameters:
painterpainter
p1starting point
p2ending point
typeline type
colorline color
widthline width

Definition at line 276 of file Plot2d.cxx.

{
  drawLine( painter, p1, p2, plot2qwtLine( type ), color, width );
}

Here is the call graph for this function:

void Plot2d::drawLine ( QPainter *  painter,
int  x1,
int  y1,
int  x2,
int  y2,
Qt::PenStyle  type = Qt::SolidLine,
const QColor &  color = Qt::black,
int  width = 0 
)

Draw line.

Parameters:
painterpainter
x1X coordinate of the starting point
y1Y coordinate of the starting point
x2X coordinate of the ending point
y2Y coordinate of the ending point
typeline type
colorline color
widthline width

Definition at line 293 of file Plot2d.cxx.

{
  drawLine( painter, QPoint( x1, y1 ), QPoint( x2, y2 ), type, color, width );
}

Here is the call graph for this function:

void Plot2d::drawLine ( QPainter *  painter,
int  x1,
int  y1,
int  x2,
int  y2,
Plot2d::LineType  type = Solid,
const QColor &  color = Qt::black,
int  width = 0 
)

Draw line.

Parameters:
painterpainter
x1X coordinate of the starting point
y1Y coordinate of the starting point
x2X coordinate of the ending point
y2Y coordinate of the ending point
typeline type
colorline color
widthline width

Definition at line 310 of file Plot2d.cxx.

{
  drawLine( painter, QPoint( x1, y1 ), QPoint( x2, y2 ), 
            plot2qwtLine( type), color, width );
}

Here is the call graph for this function:

void Plot2d::drawMarker ( QPainter *  painter,
const QPoint &  p,
const QRect &  r,
QwtSymbol::Style  type = QwtSymbol::Ellipse,
const QColor &  color = Qt::black 
)

Draw marker.

Parameters:
painterpainter
pcentral point
rmarker rectangle
typemarker type
colormarker color

Definition at line 325 of file Plot2d.cxx.

{
  painter->save();
  painter->setPen( color );
  painter->setBrush( color );
  
  QRect ar = r;
  ar.moveCenter( p );
  const int w2 = ar.width()  / 2;
  const int h2 = ar.height() / 2;

  switch( type ) {
  case QwtSymbol::Ellipse:
    painter->drawEllipse( ar );
    break;
  case QwtSymbol::Rect:
    painter->drawRect( ar );
    painter->fillRect( ar, QBrush( color ) );
    break;
  case QwtSymbol::Diamond:
    {
      QPolygon polygon;
      polygon << QPoint( ar.x() + w2, ar.y() );
      polygon << QPoint( ar.right(), ar.y() + h2 );
      polygon << QPoint( ar.x() + w2, ar.bottom() );
      polygon << QPoint( ar.x(), ar.y() + h2 );
      painter->drawPolygon( polygon );
      break;
    }
  case QwtSymbol::Cross:
    painter->drawLine( ar.left() + w2, ar.top(), ar.left() + w2, ar.bottom() );
    painter->drawLine( ar.left(), ar.top() + h2, ar.right(), ar.top() + h2 );
    break;
  case QwtSymbol::XCross:
    painter->drawLine( ar.left(), ar.top(), ar.right(), ar.bottom() );
    painter->drawLine( ar.left(), ar.bottom(), ar.right(), ar.top() );
    break;
  case QwtSymbol::UTriangle:
    {
      QPolygon polygon;
      polygon << QPoint( ar.left() + w2, ar.top() );
      polygon << QPoint( ar.right(), ar.bottom() );
      polygon << QPoint( ar.left(), ar.bottom() );
      painter->drawPolygon( polygon );
      break;
    }
  case QwtSymbol::DTriangle:
    {
      QPolygon polygon;
      polygon << QPoint( ar.left() + w2, ar.bottom() );
      polygon << QPoint( ar.right(), ar.top() );
      polygon << QPoint( ar.left(), ar.top() );
      painter->drawPolygon( polygon );
      break;
    }
  case QwtSymbol::RTriangle:
    {
      QPolygon polygon;
      polygon << QPoint( ar.left(), ar.top() );
      polygon << QPoint( ar.right(), ar.top() + h2 );
      polygon << QPoint( ar.left(), ar.bottom() );
      painter->drawPolygon( polygon );
      break;
    }
  case QwtSymbol::LTriangle:
    {
      QPolygon polygon;
      polygon << QPoint( ar.left(), ar.top() + h2 );
      polygon << QPoint( ar.right(), ar.top() );
      polygon << QPoint( ar.right(), ar.bottom() );
      painter->drawPolygon( polygon );
      break;
    }
  default:
    break;
  }
  painter->restore();
}

Here is the caller graph for this function:

void Plot2d::drawMarker ( QPainter *  painter,
const QPoint &  p,
const QRect &  r,
Plot2d::MarkerType  type = Circle,
const QColor &  color = Qt::black 
)

Draw marker.

Parameters:
painterpainter
pcentral point
rmarker rectangle
typemarker type
colormarker color

Definition at line 413 of file Plot2d.cxx.

{
  drawMarker( painter, p, r, plot2qwtMarker( type ), color ); 
}

Here is the call graph for this function:

void Plot2d::drawMarker ( QPainter *  painter,
int  x,
int  y,
int  w,
int  h,
QwtSymbol::Style  type = QwtSymbol::Ellipse,
const QColor &  color = Qt::black 
)

Draw marker.

Parameters:
painterpainter
xX coordinate of the central point
yY coordinate of the central point
wmarker rectangle width
hmarker rectangle height
typemarker type
colormarker color

Definition at line 429 of file Plot2d.cxx.

{
  drawMarker( painter, QPoint( x, y ), QRect( 0, 0, w, h ), type, color ); 
}

Here is the call graph for this function:

void Plot2d::drawMarker ( QPainter *  painter,
int  x,
int  y,
int  w,
int  h,
Plot2d::MarkerType  type = Circle,
const QColor &  color = Qt::black 
)

Draw marker.

Parameters:
painterpainter
xX coordinate of the central point
yY coordinate of the central point
wmarker rectangle width
hmarker rectangle height
typemarker type
colormarker color

Definition at line 445 of file Plot2d.cxx.

{
  drawMarker( painter, QPoint( x, y ), QRect( 0, 0, w, h ), plot2qwtMarker( type ), color ); 
}

Here is the call graph for this function:

bool Plot2d::existMarker ( const int  rtti,
const QwtPlot *  thePlot,
const QwtSymbol::Style  typeMarker,
const QColor &  color,
const Qt::PenStyle  typeLine 
)

Checks if marker belongs to any enitity.

Definition at line 514 of file Plot2d.cxx.

{
  bool ok = false;
  
  QColor bgColor = thePlot->palette().color( QPalette::Background );
  if ( closeColors( color, bgColor ) ) {
    ok = true;
  }
  else {
    QwtPlotItemList anItems = thePlot->itemList();
    QwtPlotItemIterator anIt = anItems.begin(), aLast = anItems.end();
    QwtPlotItem* anItem;
    for ( ; anIt != aLast && !ok; anIt++ ) {
      anItem = *anIt;
      if ( anItem && anItem->rtti() == rtti ) {
       QwtPlotCurve* crv = dynamic_cast<QwtPlotCurve*>( anItem );
       if ( crv ) {
         QwtSymbol::Style aStyle = crv->symbol().style();
         QColor           aColor = crv->pen().color();
         Qt::PenStyle     aLine  = crv->pen().style();
         ok = closeColors( aColor, color ) && aStyle == typeMarker && aLine == typeLine;
       }
      }
    }
  }
  return ok;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void Plot2d::getNextMarker ( const int  rtti,
const QwtPlot *  thePlot,
QwtSymbol::Style &  typeMarker,
QColor &  color,
Qt::PenStyle &  typeLine 
)

Gets new unique marker for item if possible.

Definition at line 491 of file Plot2d.cxx.

{
  bool bOk = false;
  int cnt = 0;
  while ( !bOk ) {
    int aRed    = (int)( 256.0 * rand() / RAND_MAX );  // generate random color
    int aGreen  = (int)( 256.0 * rand() / RAND_MAX );  // ...
    int aBlue   = (int)( 256.0 * rand() / RAND_MAX );  // ...
    int aMarker = (int)( 9.0 * rand() / RAND_MAX ) + 1;// 9 markers types( not including empty )
    int aLine   = (int)( 5.0 * rand() / RAND_MAX ) + 1;// 5 line types ( not including empty )
    
    typeMarker = ( QwtSymbol::Style )aMarker;
    color      = QColor( aRed, aGreen, aBlue );
    typeLine   = ( Qt::PenStyle )aLine;
    
    bOk = ( ++cnt == MAX_ATTEMPTS ) || !existMarker( rtti, thePlot, typeMarker, color, typeLine );
  }
}

Here is the call graph for this function:

QPixmap Plot2d::lineIcon ( const QSize &  size,
const QColor &  color,
Plot2d::LineType  type 
)

Create icon pixmap according to the line type.

Parameters:
sizeicon size
typeline type
coloricon color
Returns:
icon

Definition at line 477 of file Plot2d.cxx.

{

  QPixmap px( size );
  px.fill( QColor( 255, 255, 255, 0 ) );
  QPainter p( &px );
  drawLine( &p, 5, size.height()/2, size.width()-5, size.height()/2, type,
           color, 1 );
  return px;
}

Here is the call graph for this function:

QPixmap Plot2d::markerIcon ( const QSize &  size,
const QColor &  color,
Plot2d::MarkerType  type 
)

Create icon pixmap according to the marker type.

Parameters:
sizeicon size
typemarker type
coloricon color
Returns:
icon

Definition at line 459 of file Plot2d.cxx.

{

  QPixmap px( size );
  px.fill( QColor( 255, 255, 255, 0 ) );
  QPainter p( &px );
  Plot2d::drawMarker( &p, size.width()/2, size.height()/2, MSIZE, MSIZE, type, color );
  return px;
}

Here is the call graph for this function:

Convert Plot2d line type to Qt/Qwt line type.

Parameters:
pPlot2d line type
Returns:
Qt/Qwt line type

Definition at line 199 of file Plot2d.cxx.

{
  Qt::PenStyle ps = Qt::NoPen;
  switch ( p ) {
  case Plot2d::Solid:
    ps = Qt::SolidLine;      break;
  case Plot2d::Dash:
    ps = Qt::DashLine;       break;
  case Plot2d::Dot:
    ps = Qt::DotLine;        break;
  case Plot2d::DashDot:
    ps = Qt::DashDotLine;    break;
  case Plot2d::DashDotDot:
    ps = Qt::DashDotDotLine; break;
  case Plot2d::NoPen:
  default:
    ps = Qt::NoPen;          break;
  }
  return ps;
}

Here is the caller graph for this function:

QwtSymbol::Style Plot2d::plot2qwtMarker ( Plot2d::MarkerType  m)

Convert Plot2d marker type to Qwt marker type.

Parameters:
mPlot2d marker type
Returns:
Qwt marker type

Definition at line 131 of file Plot2d.cxx.

{
  QwtSymbol::Style ms = QwtSymbol::NoSymbol;  
  switch ( m ) {
  case Plot2d::Circle:
    ms = QwtSymbol::Ellipse;   break;
  case Plot2d::Rectangle:
    ms = QwtSymbol::Rect;      break;
  case Plot2d::Diamond:
    ms = QwtSymbol::Diamond;   break;
  case Plot2d::DTriangle:
    ms = QwtSymbol::DTriangle; break;
  case Plot2d::UTriangle:
    ms = QwtSymbol::UTriangle; break;
  case Plot2d::LTriangle:
    ms = QwtSymbol::LTriangle; break;
  case Plot2d::RTriangle:
    ms = QwtSymbol::RTriangle; break;
  case Plot2d::Cross:
    ms = QwtSymbol::Cross;     break;
  case Plot2d::XCross:
    ms = QwtSymbol::XCross;    break;
  case Plot2d::None:
  default:
    ms = QwtSymbol::NoSymbol;  break;
  }
  return ms;
}

Here is the caller graph for this function:

Convert Qt/Qwt line type to Plot2d line type.

Parameters:
pQt/Qwt line type
Returns:
Plot2d line type

Definition at line 225 of file Plot2d.cxx.

{
  Plot2d::LineType ps = Plot2d::NoPen;
  switch ( p ) {
  case Qt::SolidLine:
    ps = Plot2d::Solid;      break;
  case Qt::DashLine:
    ps = Plot2d::Dash;       break;
  case Qt::DotLine:
    ps = Plot2d::Dot;        break;
  case Qt::DashDotLine:
    ps = Plot2d::DashDot;    break;
  case Qt::DashDotDotLine:
    ps = Plot2d::DashDotDot; break;
  case Qt::NoPen:
  default:
    ps = Plot2d::NoPen;      break;
  }
  return ps;
}
Plot2d::MarkerType Plot2d::qwt2plotMarker ( QwtSymbol::Style  m)

Convert Qwt marker type to Plot2d marker type.

Parameters:
mQwt marker type
Returns:
Plot2d marker type

Definition at line 165 of file Plot2d.cxx.

{
  Plot2d::MarkerType ms = Plot2d::None;  
  switch ( m ) {
  case QwtSymbol::Ellipse:
    ms = Plot2d::Circle;    break;
  case QwtSymbol::Rect:
    ms = Plot2d::Rectangle; break;
  case QwtSymbol::Diamond:
    ms = Plot2d::Diamond;   break;
  case QwtSymbol::DTriangle:
    ms = Plot2d::DTriangle; break;
  case QwtSymbol::UTriangle:
    ms = Plot2d::UTriangle; break;
  case QwtSymbol::RTriangle:
    ms = Plot2d::RTriangle; break;
  case QwtSymbol::LTriangle:
    ms = Plot2d::LTriangle; break;
  case QwtSymbol::Cross:
    ms = Plot2d::Cross;     break;
  case QwtSymbol::XCross:
    ms = Plot2d::XCross;    break;
  case QwtSymbol::NoSymbol:
  default:
    ms = Plot2d::None;      break;
  }
  return ms;
}