All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines
Public Slots | Signals | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | Properties
SciFigs::XYColorLines Class Reference

A XYColorLines is a layer to draw polylines of color (static) More...

#include <XYColorLines.h>

Inheritance diagram for SciFigs::XYColorLines:
SciFigs::GraphContentLayer QGpGuiTools::PropertyItem QGpCoreTools::XMLClass SciFigs::XYValueLines

List of all members.

Public Slots

void setColor (int curveIndex, int red, int green, int blue)

Signals

void dataSelected (int id, const QVector< int > *indexList)

Public Member Functions

virtual void addProperties (PropertyProxy *pp)
Rect boundingRect () const
const QColor * colors () const
int curveCount ()
void divYbyX (double constant)
virtual bool hasProperties ()
double lineWeight () const
double lineWeightMM () const
void mulYbyX (double constant)
Point2Dpoints ()
const Point2Dpoints () const
virtual void properties (PropertyWidget *w) const
virtual void removeProperties (PropertyProxy *pp)
void setColor (int index, const QColor &col)
void setColors (QColor *col)
void setLineWeight (double lw)
void setPointCount (int nPoints, int nCurves, int *pointCounts)
void setPointCount (int nPoints, const QVector< int > &pointCounts)
void setPoints (const QVector< Point2D > &points)
virtual void setProperty (uint wid, int pid, QVariant val)
virtual bool trackRectangle (int, double rx1, double ry1, double rx2, double ry2, Qt::KeyboardModifiers)
virtual const QString & xml_tagName () const
 XYColorLines (AxisWindow *parent=0, bool autoDelete=false)
 ~XYColorLines ()

Static Public Member Functions

static void restoreBinaryColorVector (QDataStream &s, QColor *&colors, int count, XMLContext *context)
static void saveBinaryColorVector (QDataStream &s, const QColor *colors, int count)

Static Public Attributes

static uint _tab = PropertyProxy::uniqueId()
static const QString xmlXYColorLinesTag = "XYColorLines"

Protected Member Functions

void clear ()
virtual void paintData (const LayerPainterRequest &lp, QPainter &p, double dotpercm) const
virtual bool xml_setBinaryData (XML_SETBINARYDATA_ARGS)
virtual bool xml_setBinaryData200411 (XML_SETBINARYDATA_ARGS)
virtual void xml_writeBinaryData (XML_WRITEBINARYDATA_ARGS) const
virtual void xml_writeProperties (XML_WRITEPROPERTIES_ARGS) const

Protected Attributes

bool _autoDelete
QColor * _colors
int _curveCount
double _lineWeight
int * _pointCounts
Point2D_points
XYColorLinesProperties_propertiesTab

Properties

double lineWeight

Detailed Description

A XYColorLines is a layer to draw polylines of color (static)


Constructor & Destructor Documentation

SciFigs::XYColorLines::XYColorLines ( AxisWindow parent = 0,
bool  autoDelete = false 
)

References clear(), and TRACE.

{
  TRACE;
  clear();
}

Member Function Documentation

Setup property editor

Reimplemented from SciFigs::GraphContentLayer.

Reimplemented in SciFigs::XYValueLines.

References _tab, QGpGuiTools::PropertyProxy::addReference(), QGpGuiTools::PropertyProxy::addTab(), QGpGuiTools::PropertyProxy::setCurrentTab(), QGpCoreTools::tr(), TRACE, and w.

{
  TRACE;
  if(pp->setCurrentTab(_tab)) {
    pp->addReference(this);
  } else {
    XYColorLinesProperties * w=new XYColorLinesProperties;
    pp->addTab(_tab, tr("Color Lines"), w, this);
  }
}

Implements SciFigs::GraphContentLayer.

References _curveCount, _pointCounts, _points, TRACE, QGpCoreTools::Point2D::x(), and QGpCoreTools::Point2D::y().

Referenced by DinverDCGui::DCModelViewer::setLimits().

{
  TRACE;
  if(_curveCount==0) return Rect();
  Point2D *p=_points;
  Rect r(p->x(), p->y(), p->x(), p->y());
  for(int i=0;i < _curveCount;i++ ) {
    int countPoints=_pointCounts[ i ];
    for(int j=0;j < countPoints;j++ ) r.add( *(p++ ));
  }
  return r;
}
void SciFigs::XYColorLines::clear ( ) [protected]

References _autoDelete, _colors, _curveCount, _pointCounts, _points, and TRACE.

Referenced by setPointCount(), and ~XYColorLines().

{
  TRACE;
  delete [] _points;
  if(_autoDelete) {
    delete [] _pointCounts;
    delete [] _colors;
    _pointCounts=0;
    _colors=0;
  }
  _points=0;
  _curveCount=0;
}
const QColor* SciFigs::XYColorLines::colors ( ) const [inline]

Referenced by restoreBinaryColorVector().

{return _colors;}
{return _curveCount;}
void SciFigs::XYColorLines::dataSelected ( int  id,
const QVector< int > *  indexList 
) [signal]

Referenced by trackRectangle().

void SciFigs::XYColorLines::divYbyX ( double  constant)

References _curveCount, _pointCounts, _points, QGpCoreTools::Point2D::setY(), TRACE, QGpCoreTools::Point2D::x(), and QGpCoreTools::Point2D::y().

{
  TRACE;
  Point2D * p=_points;
  LayerLocker ll(this);
  for(int i=0;i < _curveCount;i++ ) {
    int countPoints=_pointCounts[ i ];
    for(int j=0;j < countPoints;j++ ) {
      p->setY(p->y()/(constant * p->x()) );
      p++;
    }
  }
}
virtual bool SciFigs::XYColorLines::hasProperties ( ) [inline, virtual]

Reimplemented from SciFigs::GraphContentLayer.

Reimplemented in SciFigs::XYValueLines.

{return true;}
double SciFigs::XYColorLines::lineWeight ( ) const [inline]
double SciFigs::XYColorLines::lineWeightMM ( ) const [inline]

Referenced by properties().

{return _lineWeight*10.0;}
void SciFigs::XYColorLines::mulYbyX ( double  constant)

References _curveCount, _pointCounts, _points, QGpCoreTools::Point2D::setY(), TRACE, QGpCoreTools::Point2D::x(), and QGpCoreTools::Point2D::y().

{
  TRACE;
  Point2D * p=_points;
  LayerLocker ll(this);
  for(int i=0;i < _curveCount;i++ ) {
    int countPoints=_pointCounts[ i ];
    for(int j=0;j < countPoints;j++ ) {
      p->setY(p->y() * constant * p->x());
      p++;
    }
  }
}
void SciFigs::XYColorLines::paintData ( const LayerPainterRequest lp,
QPainter &  p,
double  dotpercm 
) const [protected, virtual]

Implements SciFigs::GraphContentLayer.

Reimplemented in SciFigs::XYValueLines.

References _colors, _curveCount, _lineWeight, _pointCounts, _points, SciFigs::GraphContentOptions::checkOrigin(), lineWeight(), SciFigs::LayerPainterRequest::options(), SciFigs::GraphContentOptions::r2s(), SciFigs::LayerPainterRequest::size(), SciFigs::LayerPainterRequest::terminated(), and TRACE.

{
  TRACE;
  if( !_curveCount) return ;
  const GraphContentOptions& gc=lp.options();
  int h=lp.size().height();

  Point2D *p1=_points - 1, *p2;
  QPoint pscreen1, pscreen2;
  int lineWeight=(int) floor(_lineWeight * dotpercm + 0.5);
  if(lineWeight<1) lineWeight=1;
  QPen currentPen(Qt::black, lineWeight, Qt::SolidLine, Qt::SquareCap, Qt::RoundJoin);
  for(int i=0;i < _curveCount;i++ ) {
    if(lp.terminated()) return;
    int countPoints=_pointCounts[ i ];
    if(countPoints > 0) {
      QPolygon ap(countPoints);
      if(_colors) currentPen.setColor(_colors[ i ] );
      p.setPen(currentPen);
      p1++;
      int subCurveCount=0;
      for(int j=1;j < countPoints;j++ ) {
        p2=p1 + 1;
        if(gc.r2s( *p1, *p2, pscreen1, pscreen2) ) {
          gc.checkOrigin(pscreen1, pscreen2, h);
          if(subCurveCount==0) {
            ap.setPoint(0, pscreen1);
            subCurveCount=1;
          } else {
            if(ap.point(subCurveCount - 1)!=pscreen1) {
              p.drawPolyline (ap.data(), subCurveCount);
              ap.setPoint(0, pscreen1);
              subCurveCount=1;
            }
          }
          ap.setPoint(subCurveCount, pscreen2);
          subCurveCount++;
        } else if(subCurveCount > 1) {
          p.drawPolyline (ap.data(), subCurveCount);
          subCurveCount=0;
        }
        p1=p2;
      }
      if(subCurveCount > 1) p.drawPolyline (ap.data(), subCurveCount);
    }
  }
}
const Point2D* SciFigs::XYColorLines::points ( ) const [inline]
{return _points;}
void SciFigs::XYColorLines::properties ( PropertyWidget w) const [virtual]

Clean property editor

Reimplemented from SciFigs::GraphContentLayer.

Reimplemented in SciFigs::XYValueLines.

References _tab, QGpGuiTools::PropertyProxy::removeTab(), and TRACE.

{
  TRACE;
  pp->removeTab(_tab, this);
}
void SciFigs::XYColorLines::restoreBinaryColorVector ( QDataStream &  s,
QColor *&  colors,
int  count,
XMLContext context 
) [static]

References colors(), and SciFigs::XMLSciFigs::currentFileVersion().

Referenced by SciFigs::XUniqueYColorLines::xml_setBinaryData(), and xml_setBinaryData().

{
  // Compatibility
  //   before 20091117, a bool was recorded: color or not
  //   Introduction of an unsigned char was required to introduce transparency
  unsigned char colorSize;
  ASSERT(sizeof(bool)==sizeof(unsigned char) && true==1 && false==0);
  XMLSciFigs * scifigsContext=static_cast<XMLSciFigs *>(context);
  Version v(scifigsContext->currentFileVersion());
  static const Version vRef(1, 0, 99);
  if(v>vRef) {
    s >> colorSize;
    if(colorSize==1) colorSize=3;
  } else {
    colorSize=3; // Except for .page generated from PtMotion geopsy module, this value is the correct one
                 // Old .page files generated with PtMotion geopsy module won't display the curves but it won't crash.
                 // This is due to an historical stupid format missing a flag telling if colors were there or not.
  }
  delete [] colors;
  if(colorSize>0) {
    colors=new QColor[count];
    unsigned char * tmpColors=new unsigned char[colorSize*count];
    s.readRawData(( char * ) tmpColors, colorSize*sizeof(unsigned char)*count);
    QColor *& origColors=colors;
    unsigned char * tmpPtr=tmpColors;
    if(colorSize==3) {
      for(int i=0;i<count;i++) {
        origColors[ i ].setRgb(tmpPtr[0], tmpPtr[1], tmpPtr[2]);
        tmpPtr+=3;
      }
    } else {
      for(int i=0;i<count;i++) {
        origColors[ i ].setRgb(tmpPtr[0], tmpPtr[1], tmpPtr[2], tmpPtr[3]);
        tmpPtr+=4;
      }
    }
    delete [] tmpColors;
  } else {
    colors=0;
  }
}
void SciFigs::XYColorLines::saveBinaryColorVector ( QDataStream &  s,
const QColor *  colors,
int  count 
) [static]

Referenced by SciFigs::XUniqueYColorLines::xml_writeBinaryData(), and xml_writeBinaryData().

{
  if(colors) {
    const unsigned char colorSize=4;
    s << colorSize;
    // We cannot save the QColor structure as whole block any longer (bugs)
    // Transform QColor into 4 unsigned char r,g,b,a. Transparency introduced on 20091117
    unsigned char * tmpColors=new unsigned char[colorSize*count];
    unsigned char * tmpPtr=tmpColors;
    for(int i=0; i<count; i++) {
      const QColor& c=colors[i];
      *(tmpPtr++)=(unsigned char)c.red();
      *(tmpPtr++)=(unsigned char)c.green();
      *(tmpPtr++)=(unsigned char)c.blue();
      *(tmpPtr++)=(unsigned char)c.alpha();
    }
    s.writeRawData((const char *) tmpColors, colorSize*sizeof(unsigned char)*count);
    delete [] tmpColors;
  } else {
    const unsigned char colorSize=0;
    s << colorSize;
  }
}
void SciFigs::XYColorLines::setColor ( int  index,
const QColor &  col 
)

References _colors, and TRACE.

{
  TRACE;
  LayerLocker ll(this);
  _colors[index]=col;
}
void SciFigs::XYColorLines::setColor ( int  curveIndex,
int  red,
int  green,
int  blue 
) [slot]

References _colors, _curveCount, and TRACE.

{
  TRACE;
  if(curveIndex < 0 || curveIndex >= _curveCount || !_colors) return ;
  LayerLocker ll(this);
  _colors[ curveIndex ]=QColor(red, green, blue);
}
void SciFigs::XYColorLines::setColors ( QColor *  col)

References _colors, and TRACE.

{
  TRACE;
  LayerLocker ll(this);
  delete _colors;
  _colors=col;
}

References _lineWeight, and TRACE.

Referenced by setProperty().

{
  TRACE;
  LayerLocker ll(this);
  _lineWeight=lw;
}
void SciFigs::XYColorLines::setPointCount ( int  nPoints,
int  nCurves,
int *  pointCounts 
)

This is the unique function you have to call to populate this layer with lines. Never call points() before calling this function.

References _curveCount, _pointCounts, _points, clear(), and TRACE.

Referenced by addManyCurvePlot(), DinverDCGui::DCModelViewer::loadModels(), and DinverDCGui::DCModelViewer::~DCModelViewer().

{
  TRACE;
  LayerLocker ll(this);
  clear();
  _curveCount=nCurves;
  _pointCounts=pointCounts;
  if(nPoints > 0) _points=new Point2D[ nPoints ]; else _points=0;
}
void SciFigs::XYColorLines::setPointCount ( int  nPoints,
const QVector< int > &  pointCounts 
)

Convenience function to set the internal list of point counts from a dynamic vector of int

References _curveCount, _pointCounts, _points, clear(), and TRACE.

{
  TRACE;
  LayerLocker ll(this);
  clear();
  _curveCount=pointCounts.count();
  if(_curveCount>0) {
    _pointCounts=new int[_curveCount];
    for(int i=0; i<_curveCount; i++) {
      _pointCounts[i]=pointCounts[i];
    }
  }
  if(nPoints > 0) _points=new Point2D[ nPoints ]; else _points=0;
}
void SciFigs::XYColorLines::setPoints ( const QVector< Point2D > &  points)

Convenience function to set the internal list of points from a dynamic vector of points

See also:
setPointCount(int nPoints, const QVector<int>& pointCounts)

References _points, and TRACE.

Referenced by addManyCurvePlot().

{
  TRACE;
  int n=points.count();
  LayerLocker ll(this);
  for(int i=0; i<n; i++) {
    _points[i]=points[i];
  }
}
void SciFigs::XYColorLines::setProperty ( uint  wid,
int  pid,
QVariant  val 
) [virtual]
bool SciFigs::XYColorLines::trackRectangle ( int  id,
double  rx1,
double  ry1,
double  rx2,
double  ry2,
Qt::KeyboardModifiers   
) [virtual]

When the user select curve using the mouse pointer

Reimplemented from SciFigs::GraphContentLayer.

References _curveCount, _pointCounts, _points, dataSelected(), QGpCoreTools::Rect::includes(), and TRACE.

{
  TRACE;
  // Select the points inside the rectangle and call editData(QVector * indexList)
  // This trackRectangle function can redefined in sub-classes
  Rect r(rx1, ry1, rx2, ry2);
  //printf("Edit rectangle: %lg %lg %lg %lg\n",rx1,ry1,rx2,ry2);
  QVector<int> * indexList=new QVector<int>;
  Point2D *p1=_points-1, *p2;
  for(int i=0; i<_curveCount; i++) {
    int countPoints=_pointCounts[i];
    if(countPoints>0) {
      p1++;
      //printf("Curve %i: \np1 %lg, %lg\n",i,p1->x(),p1->y());
      for(int j=1;j < countPoints;j++ ) {
        p2=p1 + 1;
        //printf("p2 %lg, %lg\n",p2->x(),p2->y());
        if(r.includes( *p1, *p2) ) {
          indexList->push_back(i);
          //printf("%i included!\n",i);
          p1 += countPoints - j;
          break;
        }
        p1=p2;
      }
    }
  }
  if(indexList->count() > 0) emit dataSelected(id, indexList);
  delete indexList;
  return true;
}

This function must be re-implemented in all classes dealing with binary data that cannot be saved in an ASCII xml file (e.g. due to the amount of data).

See also xml_writeBinaryData().

The difference between xml_setBinaryData() and xml_setBinaryData200410() is detected by the type of tag at the beginning of each block if it can be read with QString ==> 200510, else try with a normal C string, if it match the current tag then execute xml_setBinaryData200411().

See also xml_setBinaryData200411() to maintain compatibility with previous versions of xml storages.

For the arguments of this function use Macro XML_SETBINARYDATA_ARGS.

Reimplemented from QGpCoreTools::XMLClass.

Reimplemented in SciFigs::XYValueLines.

References _autoDelete, _colors, _curveCount, _pointCounts, _points, restoreBinaryColorVector(), and TRACE.

Referenced by xml_setBinaryData200411().

{
  TRACE;
  s >> _curveCount;
  if(_curveCount > 0) {
    _autoDelete=true;
    restoreBinaryColorVector(s, _colors, _curveCount, context);
    _pointCounts=new int[ _curveCount ];
    s.readRawData(( char * ) _pointCounts, sizeof(int) * _curveCount);
    // Count number of points
    int n=0;
    for(int i=0;i < _curveCount;i++ ) {
      if(_pointCounts[ i ]<0) _pointCounts[ i ]=0;
      n += _pointCounts[ i ];
    }
    if(n>0) {
      _points=new Point2D [ n ];
      s.readRawData(( char * ) _points, sizeof(Point2D) * n);
    }
  }
  return true;
}

This function must be re-implemented in all classes dealing with binary data that cannot be saved in an ASCII xml file (e.g. due to the amount of data).

See also xml_setBinaryData().

For the arguments of this function use Macro XML_SETBINARYDATA_ARGS.

This function must not used in new codes. This is only kept for compatibility reasons, to be able to read all xml.bin files generated by releases before November 2006.

Reimplemented from QGpCoreTools::XMLClass.

References TRACE, and xml_setBinaryData().

{
  TRACE;
  s.setByteOrder(QDataStream::LittleEndian);
  bool ret=xml_setBinaryData(s, context);
  s.setByteOrder(QDataStream::BigEndian);
  return ret;
}
virtual const QString& SciFigs::XYColorLines::xml_tagName ( ) const [inline, virtual]

Reimplemented from SciFigs::GraphContentLayer.

Reimplemented in SciFigs::XYValueLines.

This function must be re-implemented in all classes dealing with binary data that cannot be saved in an ASCII xml file (e.g. due to the amount of data).

The way binary data is stored drastically changed in November 2006 with the introduction of tar.gz structures for xml files. Each class willing to store binary data can automatically generate a new file (with an automatic file name) in the .tar.gz structure by sending bytes to s.

See also xml_setBinaryData().

For the arguments of this function use Macro XML_WRITEBINARYDATA_ARGS.

Reimplemented from QGpCoreTools::XMLClass.

Reimplemented in SciFigs::XYValueLines.

References _colors, _curveCount, _pointCounts, _points, saveBinaryColorVector(), and TRACE.

{
  TRACE;
  Q_UNUSED(context);
  s << _curveCount;
  saveBinaryColorVector(s, _colors, _curveCount);
  // Count number of points
  int n=0;
  s.writeRawData(( const char * ) _pointCounts, sizeof(int) * _curveCount);
  for(int i=0;i < _curveCount;i++ ) n += _pointCounts[ i ];
  s.writeRawData(( const char * ) _points, sizeof(Point2D) * n);
}

Reimplemented from SciFigs::GraphContentLayer.

References SciFigs::XMLSciFigs::data(), TRACE, and QGpCoreTools::XMLClass::writeBinaryData().

{
  TRACE;
  GraphContentLayer::xml_writeProperties(s, context);
  XMLSciFigs * scifigsContext=static_cast<XMLSciFigs *>(context);
  if(scifigsContext->data()) writeBinaryData(s, context);
}

Member Data Documentation

QColor* SciFigs::XYColorLines::_colors [protected]

Referenced by XYColorLines().

uint SciFigs::XYColorLines::_tab = PropertyProxy::uniqueId() [static]
const QString SciFigs::XYColorLines::xmlXYColorLinesTag = "XYColorLines" [static]

Property Documentation

double SciFigs::XYColorLines::lineWeight [read, write]

The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines