15 #include "msdevstudio/MSconfig.h"
28 #include <qapplication.h>
35 #include <qdatetime.h>
37 #if QT_VERSION < 0x040000
38 #include <qpointarray.h>
40 #include <QtGui/QPolygon>
41 #include <QtCore/QTextStream>
58 m_font_default (
"helvetica" )
79 m_font_default (
"helvetica" )
96 char * tmp_dir(::getenv(
"TMP"));
115 if ( display == 0 )
return;
152 #if QT_VERSION < 0x040000
155 transformAndFill ( QPolygon & array,
157 const std::vector< double > & x,
158 const std::vector< double > & y,
159 int (
QtViewImp::* xfunc) (
double )
const,
160 int (
QtViewImp::* yfunc) (
double )
const )
162 unsigned int size = x.size();
163 assert ( size == y.size() );
165 for (
unsigned int i = 0; i <
size; i++ ) {
166 int ix = (this->*xfunc) ( x[i] );
167 int iy = (this->*yfunc) ( y[i] );
169 array.setPoint ( i , ix, iy );
179 const std::vector< double > & y,
183 unsigned int size = x.size();
184 assert ( size == y.size() );
186 #if QT_VERSION < 0x040000
189 QPolygon array ( size );
204 const std::vector < double > & y,
209 unsigned int size = x.size();
210 assert ( size == y.size() );
212 #if QT_VERSION < 0x040000
215 QPolygon array ( size );
227 const std::vector<double> & y,
230 const Color & color )
234 int i_sym_size = (int)(sym_size/2);
240 QColor qcolor ( rgb[0], rgb[1], rgb[2] );
244 #if QT_VERSION < 0x040000
247 QPolygon triangleArray ( 3 );
250 for (
unsigned int i = 0; i < x.size(); i++)
252 int originX =
toViewX ( x[i] );
253 int originY =
toViewY ( y[i] );
263 (
toViewY (y[i]) - (i_sym_size) ),
280 triangleArray.setPoint ( 0, (
toViewX (x[i]) ),
281 (
toViewY (y[i]) + (i_sym_size) ) );
283 triangleArray.setPoint ( 1, (
toViewX (x[i]) + (i_sym_size) ),
284 (
toViewY (y[i]) - (i_sym_size) ) );
287 triangleArray.setPoint ( 2, (
toViewX (x[i]) - (i_sym_size) ),
288 (
toViewY (y[i]) - (i_sym_size) ) );
296 triangleArray.setPoint ( 0, (
toViewX (x[i]) ),
297 (
toViewY (y[i]) + (i_sym_size) ) );
299 triangleArray.setPoint ( 1, (
toViewX (x[i]) + (i_sym_size) ),
300 (
toViewY (y[i]) - (i_sym_size) ) );
303 triangleArray.setPoint ( 2, (
toViewX (x[i]) - (i_sym_size) ),
304 (
toViewY (y[i]) - (i_sym_size) ) );
316 (
toViewY (y[i]) - (i_sym_size) ),
317 ( i_sym_size*2 + 1 ),
318 ( i_sym_size*2 + 1 ) );
328 (
toViewY (y[i]) - (i_sym_size) ),
329 ( i_sym_size*2 + 1 ),
330 ( i_sym_size*2 + 1 ),
337 m_painter -> drawLine ( originX - i_sym_size, originY,
338 originX + i_sym_size, originY );
339 m_painter -> drawLine ( originX, originY - i_sym_size,
340 originX, originY + i_sym_size );
344 m_painter -> drawLine ( originX - i_sym_size, originY - i_sym_size,
345 originX + i_sym_size, originY + i_sym_size );
346 m_painter -> drawLine ( originX + i_sym_size, originY - i_sym_size,
347 originX - i_sym_size, originY + i_sym_size );
365 const std::vector< double > &,
382 const std::vector< double > & y,
383 const std::vector< Color > & colors,
387 assert ( x.size() == colors.size() );
390 int i_sym_size = (int)(sym_size/2);
392 if ( i_sym_size == 0 &&
397 #if QT_VERSION < 0x040000
400 QPolygon triangleArray ( 3 );
403 for (
unsigned int i = 0; i < x.size(); i++)
408 const Color & c = colors[i];
416 (
toViewY (y[i]) - (i_sym_size) ),
424 m_painter -> drawRect ( o_x -i_sym_size, o_y - i_sym_size,
425 2 * i_sym_size, 2 * i_sym_size );
431 triangleArray.setPoint ( 0, (
toViewX (x[i]) ),
432 (
toViewY (y[i]) + (i_sym_size) ) );
434 triangleArray.setPoint ( 1, (
toViewX (x[i]) + (i_sym_size) ),
435 (
toViewY (y[i]) - (i_sym_size) ) );
438 triangleArray.setPoint ( 2, (
toViewX (x[i]) - (i_sym_size) ),
439 (
toViewY (y[i]) - (i_sym_size) ) );
450 triangleArray.setPoint ( 0, (
toViewX (x[i]) ),
451 (
toViewY (y[i]) + (i_sym_size) ) );
453 triangleArray.setPoint ( 1, (
toViewX (x[i]) + (i_sym_size) ),
454 (
toViewY (y[i]) - (i_sym_size) ) );
457 triangleArray.setPoint ( 2, (
toViewX (x[i]) - (i_sym_size) ),
458 (
toViewY (y[i]) - (i_sym_size) ) );
470 (
toViewY (y[i]) - (i_sym_size) ),
482 (
toViewY (y[i]) - (i_sym_size) ),
491 m_painter -> drawLine ( o_x - i_sym_size, o_y,
492 o_x + i_sym_size, o_y );
493 m_painter -> drawLine ( o_x, o_y - i_sym_size,
494 o_x, o_y + i_sym_size );
498 m_painter -> drawLine ( o_x - i_sym_size, o_y - i_sym_size,
499 o_x + i_sym_size, o_y + i_sym_size );
500 m_painter -> drawLine ( o_x + i_sym_size, o_y - i_sym_size,
501 o_x - i_sym_size, o_y + i_sym_size );
522 QColor qcolor ( rgb[0], rgb[1], rgb[2] );
524 unsigned int isize = static_cast <
unsigned int > (
size );
527 return QPen ( qcolor, isize, pen_style );
533 const std::vector < double > & y,
540 unsigned int size = x.size();
541 assert ( size == y.size() );
547 QColor qcolor ( rgb[0], rgb[1], rgb[2] );
553 QColor qcolor2 ( rgb2[0], rgb2[1], rgb2[2] );
555 #if QT_VERSION < 0x040000
558 QPolygon array ( size );
574 const std::vector< double > & y,
593 const std::vector< double > & y,
604 unsigned int xsize = x.size();
605 assert ( xsize == y.size() );
607 #if QT_VERSION < 0x040000
610 QPolygon array ( xsize );
624 const std::vector< double > & y,
626 const std::vector < Color > & colors,
629 unsigned int ssize = x.size();
630 assert ( ssize == y.size() );
631 assert ( ssize == colors.size() );
633 for (
unsigned int i = 0; i < ssize; i+=2 ) {
636 const Color & color = colors[i];
638 QPen pen ( qcolor, static_cast < int > (size) );
640 pen.setStyle ( pen_style );
660 const std::vector< double > & y,
670 pen.setStyle ( pen_style );
682 const std::vector< double > & y,
693 unsigned int xsize = x.size();
694 assert ( xsize == y.size() );
696 #if QT_VERSION < 0x040000
699 QPolygon array ( xsize );
713 float xx,
float yy,
float fontsize,
714 float angle,
char xp,
char yp,
bool resize,
717 assert ( fontsize > 0 );
718 int i_x =
static_cast< int > ( xx );
719 int i_y =
static_cast< int > ( yy );
720 int i_font = static_cast <
int > ( fontsize );
722 if ( fontsize > 0 ) {
736 QRect new_rect1 = metrics1.boundingRect ( qstring );
737 int h1 = new_rect1.
height ();
738 if ( fontsize > 0 ) {
739 while ( h1 >= fontsize ){
743 if ( i_font < 1 )
break;
749 int h2 = new_rect2.
height ();
755 if ( resize ==
true ) {
764 #if QT_VERSION < 0x040000
765 int lines = qstring.contains (
"\n" );
767 int lines = qstring.count();
771 #if QT_VERSION < 0x040000
778 maxw = std::max ( maxw, sr.
width () );
780 int w = new_rect.
width ();
781 int h = new_rect.
height ();
786 int delta_y = i_y - static_cast <
int > ( rect.
getY () );
792 int delta_x = i_x - static_cast <
int > ( rect.
getX () );
805 int i_w = static_cast <
int > ( rect.
getWidth () );
806 int i_h = static_cast <
int > ( rect.
getHeight () );
810 Qt::AlignLeft | Qt::AlignTop,
825 dx = i_x - text_rect.width () / 2;
829 dx = i_x - text_rect.width ();
842 dy = i_y - text_rect.height () / 2;
846 dy = i_y - text_rect.height ();
852 text_rect.moveBy ( dx, dy );
853 text_rect.setWidth ( text_rect.width() + 2 );
854 text_rect.setHeight ( text_rect.height() + 2 );
875 dx = 0 - text_rect.width () / 2;
879 dx = 0 - text_rect.width ();
892 dy = 0 - text_rect.height () / 2;
896 dy = 0 - text_rect.height ();
902 text_rect.moveBy ( dx, dy );
903 text_rect.setWidth ( text_rect.width() + 2 );
904 text_rect.setHeight ( text_rect.height() + 2 );
922 float fontsize,
float angle,
923 char xp,
char yp,
bool resize )
926 drawText ( s, xx, yy, fontsize, angle, xp, yp, resize, 0, & black );
933 float fontsize,
float angle,
934 char xp,
char yp,
bool resize,
939 color =
new Color ();
945 const QtFont * qtfont = dynamic_cast <
const QtFont * > ( font );
946 const QFont & qfont = qtfont -> font();
947 QFont & qf = const_cast <
QFont & > ( qfont );
950 (xx + rect.
getX()), (yy + rect.
getY () ),
952 xp, yp, resize, qf, qcolor );
956 (xx + rect.
getX()), (yy + rect.
getY () ),
965 int red,
int green,
int blue )
969 if (x1<x2) std::swap(x1,x2);
971 if (x2<x1) std::swap(x1,x2);
974 if (y2<y1) std::swap(y1,y2);
977 int w =
toViewX ( x2 ) - x + 1;
979 int h =
toViewY ( y1 ) - y + 1;
981 const QColor color ( red, green, blue );
989 int red,
int green,
int blue )
996 QColor color ( red, green, blue );
1034 switch ( position ){
1036 if (pixmap.
load(fn)) {
1038 double x=rect.
getX();
1039 double y=rect.
getY();
1044 static_cast<int>(y),
1045 static_cast<int>(w),
1046 static_cast<int>(h) );
1052 if (pixmap.
load(fn)) {
1056 double y=rect.
getY();
1057 double h=pixmap.
height()*0.8;
1058 double w=pixmap.
width()*0.8;
1067 double ratio = mr.
getWidth() * 0.8 / w ;
1074 static_cast<int>(y),
1075 static_cast<int>(w),
1076 static_cast<int>(h) );
1082 if (pixmap.
load(fn)) {
1086 double y=rect.
getY();
1087 double h=pixmap.
height();
1088 double w=pixmap.
width();
1097 double ratio = mr.
getWidth() * 0.8 / w ;
1106 static_cast<int>(y),
1107 static_cast<int>(w),
1108 static_cast<int>(h) );
1114 if (pixmap.
load(fn)) {
1117 pixmap = pixmap.
xForm(m);
1121 double x=rect.
getX();
1123 double h=pixmap.
height();
1124 double w=pixmap.
width();
1133 double ratio = mr.
getHeight() * 0.8 / h ;
1140 static_cast<int>(y),
1141 static_cast<int>(w),
1142 static_cast<int>(h) );
1148 if ( pixmap.
load ( fn ) ) {
1153 double h=pixmap.
height()*0.7;
1154 double w=pixmap.
width()*0.7;
1163 double ratio = mr.
getWidth() * 0.8 / w ;
1171 static_cast<int>(y),
1172 static_cast<int>(w),
1173 static_cast<int>(h) );
1190 std::map< const std::string, std::string>::iterator it =
m_eq_png.find(eq);
1200 QString tex_filename =
"image"+current_time+
".tex";
1201 QString png_filename =
"image"+current_time+
".png";
1202 QString ps_filename =
"image"+current_time+
".ps";
1203 QString dvi_filename =
"image"+current_time+
".dvi";
1204 QString tmp_filename =
"image"+current_time+
".tmp";
1205 QString aux_filename =
"image"+current_time+
".aux";
1206 QString log_filename =
"image"+current_time+
".log";
1209 QString command1 =
"latex -interaction=nonstopmode "+tex_filename+
" > "+tmp_filename;
1210 QString command2 =
"dvips -q -o "+ps_filename+
" "+dvi_filename;
1211 QString command3 =
"gs < /dev/null -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sDEVICE=ppmraw -sOutputFile=- -r150 -q -dNOPAUSE "+ps_filename+
" | pnmcrop -white | pnmmargin -white 10 | pnmtopng -interlace - >"+png_filename;
1212 QString command4 =
"rm "+tex_filename+
" "+ps_filename+
" "+dvi_filename+
" "+tmp_filename+
" "+aux_filename+
" "+log_filename;
1215 QFile file(tex_filename);
1216 if (file.
open(IO_WriteOnly) ) {
1219 stream <<
"\\documentclass{article}\n";
1220 stream <<
"\\pagestyle{empty}\n";
1221 stream <<
"\\usepackage{xspace,amssymb,amsfonts,amsmath}\n";
1222 stream <<
"\\usepackage{mathptmx}\n";
1223 stream <<
"\\usepackage{color}\n";
1224 stream <<
"\\begin{document}\n";
1225 stream <<
"\\begin{displaymath}\n";
1226 stream << eq.c_str() <<
"\n";
1227 stream <<
"\\end{displaymath}\n";
1228 stream <<
"\\end{document}\n";
1231 system(command1.
latin1());
1232 system(command2.
latin1());
1233 system(command3.
latin1());
1234 system(command4.
latin1());
1236 std::string png_fn = png_filename.latin1();
double getY() const
A shortcut to get origin.Y.
The base class for the PlotterBase hierarchy.
setPointSize(int pointSize)
const Rect & getMarginRect() const
Returns the rectangle area in which data points are drawn.
void setCrossX(double val)
Set the crossX value.
void setInspector(QObject *)
Sets the receiver of update messages.
fillRect(int x, int y, int w, int h, const QBrush &brush)
float userToDrawColor(double c) const
Converts a coordinate in user space to drawing space along the color (X) axis.
virtual int toViewY(double datY) const =0
Converts the data space coordinate Y to the view space coordinate Y.
virtual void drawPolyLine(const std::vector< double > &xpoints, const std::vector< double > &ypoints, hippodraw::Line::Style style, const Color &color, float size)
Draws a polyline.
A abstract base class for font handling.
PlotterBase * m_plotter
The plotter object used by this view.
drawPolyline(const QPointArray &a, int index=0, int npoints=-1)
static std::map< hippodraw::Line::Style, Qt::PenStyle > s_line_style
The mapping from LineStyle::Type to QPen PenStyle.
virtual int toCanvasY(double dy) const =0
Converts coordinate from view space to canvas space.
virtual Rect getDrawRect() const =0
Returns the drawing Rectangle in the devices coordinate system.
drawPolygon(const QPointArray &a, bool winding=FALSE, int index=0, int npoints=-1)
virtual void update(const Observable *display)
Responds to update message from Observable.
void setCrossX(double val)
Set the crossX value.
removePostedEvents(QObject *receiver)
drawLine(int x1, int y1, int x2, int y2)
double getX() const
A shortcut to get origin.X.
virtual void drawImage(const std::string &filename, int position=0)
Draws a image.
An implementation of FontBase that uses a Qt QFont as implementation.
double getWidth() const
A shortcut to get size.width.
virtual int toViewX(double datX) const =0
Converts the data space coordinate X to the view space coordinate X.
virtual float userToMarginX(double x) const
Converts the user X coordinate into the margin X coordinate.
virtual void drawLines(const std::vector< double > &x, const std::vector< double > &y, hippodraw::Line::Style style, const Color &color, float size)
Draws multiple line segments - that is, a line between x0,y0 and x1,y2, another between x2...
hippodraw::PlotterBase class interface.
QObject * m_inspector
The receiver of update messages.
setPixelSize(int pixelSize)
virtual void draw_Text(const std::string &s, float x, float y, float fontsize, float angle, char xp, char yp, bool resize, QFont &font, const QColor &color)
postEvent(QObject *receiver, QEvent *event)
Type
Enumeration of the type of symbols supported by this class.
boundingRect(const QString &str, int len=-1) const
setFont(const QFont &font)
split(const QString &sep, const QString &str, bool allowEmptyEntries=FALSE)
virtual float userToMarginColor(double c) const
Converts the user Z coordinate into the margin color (X) coordinate.
boundingRect(int x, int y, int w, int h, int flags, const QString &, int len=-1, QTextParag **intern=0)
virtual void drawViewSquare(float x1, float y1, float x2, float y2, int red, int green, int blue)
Draws a colored square in view space.
void drawMethod(const std::vector< double > &x, const std::vector< double > &y, int opt1, int opt2)
Draws in the view using the specified method.
virtual float userToInvertedMarginX(double x) const
Converts the user X coordinate into the inverted X coordinate.
hippodraw::Range class interface
drawEllipse(int x, int y, int w, int h)
float userToDrawXAutoInv(double x) const
intp size(numeric::array arr)
QPainter * m_painter
The current Qt QPainter object.
drawPixmap(int x, int y, const QPixmap &pixmap, int sx=0, int sy=0, int sw=-1, int sh=-1)
virtual const QFont & defaultFont()
float userToDrawY(double x) const
Converts a coordinate in user space to drawing space along the Y axis.
virtual void drawSquare(double x1, double y1, double x2, double y2, int red, int green, int blue)
Draws a colored square.
setBrush(const QBrush &brush)
drawText(int x, int y, const QString &, int len=-1, TextDirection dir=Auto)
setCurrent(const QString &path)
PyArray_TYPES type(numeric::array arr)
void transformAndFill(QPointArray &array, const std::vector< double > &x, const std::vector< double > &y, int(QtViewImp::*xfunc)(double) const, int(QtViewImp::*yfunc)(double) const )
Fills the array with QPoint objects whose coordinates are in the QPaintDevice space from the vectors ...
hippodraw::QtViewImp class interface
The abstract base class for views that have a region for drawing data points with area around it for ...
load(const QString &fileName, const char *format=0, ColorMode mode=Auto)
A Color class for creating the color object following the standard RGB color space.
Style
Line style constants.
virtual void drawText(const std::string &s, float x, float y, float fontsize, float angle, char xp, char yp, bool resize)
virtual void setDefaultFont(const QFont &font)
Part of an implementation of the Observable-Observer pattern based on the example in the GOF Patterns...
virtual int toCanvasX(double dx) const =0
Converts coordinate from view space to canvas space.
virtual void drawPoints(const std::vector< double > &x, const std::vector< double > &y, hippodraw::Symbol::Type type, float sym_size, const Color &color)
Draws symbol points.
drawPie(int x, int y, int w, int h, int a, int alen)
float userToDrawX(double x) const
Converts a coordinate in user space to drawing space along the X axis.
void setCrossY(double val)
Set the crossY value.
virtual void drawColorLines(const std::vector< double > &x, const std::vector< double > &y, hippodraw::Line::Style style, const std::vector< Color > &colors, float size)
Draws multiple line segments, each with a different color - that is, a line between x0...
drawLineSegments(const QPointArray &a, int index=0, int nlines=-1)
The class of derived from ViewBase for drawing to the screen and PostScript generation using Qt toolk...
void setCrossY(double val)
Set the crossY value.
double getHeight() const
A shortcut to get size.height.
Class representing a rectangle.
hippodraw::PlotterEvent class interface
translate(double dx, double dy)
void drawViewMethod(const std::vector< double > &x, const std::vector< double > &y, int opt1, int opt2)
Draws in the view using the specified method.
virtual float userToInvertedMarginY(double y) const
Converts the user Y coordinate into the top-left based margin Y coordinate.
virtual void setDrawRect(float x, float y, float w, float h)=0
Sets the drawing Rectangle in the devices coordinate system.
A derived class of QCustomEvent to handle updates from PlotterBase.
DrawBorder class interface.
QPen createPen(const Color &color, float size, hippodraw::Line::Style style)
Creates a QPen object from the arguments.
virtual void drawPolygon(const std::vector< double > &x, const std::vector< double > &y, const Color &color, const Color &edge)
Draws a polygon.
virtual void drawViewLines(const std::vector< double > &x, const std::vector< double > &y, hippodraw::Line::Style style, bool color, float size)
std::map< const std::string, std::string > m_eq_png
The mapping from LaTex equation to PNG filename.
virtual void drawLatex(const std::string &eq, int position=0)
Draws a Latex equation.