1 #ifndef __plot_h__
2 #define __plot_h__
3 
4 #include <QVector>
5 
6 #include "qwt3d_coordsys.h"
7 #include "qwt3d_extglwidget.h"
8 #include "qwt3d_enrichment_std.h"
9 
10 namespace Qwt3D
11 {
12     class Curve;
13 
14 //! Base class for all plotting widgets
15 /*!
16   Plot3D handles all the common features for plotting widgets beyond the low-level extensions of
17   ExtGLWidget - coordinate system, labeling and more. It contains some pure virtual functions and is,
18   in this respect, an abstract base class. It's nevertheless no pure interface.
19 	The class provides interfaces for data handling and implements basic data controlled color allocation.
20 */
21 class QWT3D_EXPORT Plot3D : public ExtGLWidget
22 {
23     Q_OBJECT
24 
25 public:
26 
27 #if QT_VERSION < 0x040000
28 	Plot3D( QWidget* parent = 0, const char* name = 0 );
29 #else
30 	Plot3D ( QWidget * parent = 0, const QGLWidget * shareWidget = 0 );
31 #endif
32 	virtual ~Plot3D();
33 
setCurve(Qwt3D::Curve * c)34 	void setCurve(Qwt3D::Curve* c)				{ curve_p = c; }
setTitle(Qwt3D::Label * l)35 	void setTitle(Qwt3D::Label* l)				{ title_p = l; }
curve()36 	Qwt3D::Curve* curve() const					{ return curve_p; }
title()37 	Qwt3D::Label* title() const					{ return title_p; }
38 	void manageConnect(bool connect, Qwt3D::Curve* curve = 0);
39 
40 	QPixmap renderPixmap (int w = 0, int h = 0, bool useContext = false);
41 	void createCoordinateSystem(Qwt3D::Triple beg, Qwt3D::Triple end);
42 
coordinates()43 	Qwt3D::CoordinateSystem* coordinates()		{ return &coordinates_p; }	//!< Returns pointer to CoordinateSystem object
44 
setBackgroundColor(Qwt3D::RGBA rgba)45 	void setBackgroundColor(Qwt3D::RGBA rgba)	{ bgcolor_ = rgba; }		//!< Sets widgets background color
backgroundRGBAColor()46 	Qwt3D::RGBA backgroundRGBAColor() const		{ return bgcolor_; }		//!< Returns the widgets background color
47 
48 	void setDoubleLegend(bool mode = true)		{ doublelegend_ = mode; }	//!< Sets legend drawing mode
isDoubleLegend()49 	bool isDoubleLegend() const					{ return doublelegend_; }	//!< Returns the legend drawing mode
50 
51 	void calculateHull();
hull()52 	Qwt3D::ParallelEpiped hull() const			{ return hull_;}			//!< Returns rectangular hull
53 
54 	void setCoordinateStyle(Qwt3D::COORDSTYLE st);							//!< Sets style of coordinate system.
55 
56 	//! Returns true if valid data available, else false
hasData()57 	bool hasData() const						{ return (!curvelist_p.empty()); }
58 
59 	void addCurve(Qwt3D::Curve* curve);
60 	void addDrawable(Qwt3D::Drawable* drawable);
61 	void addTitle(Qwt3D::Label* label);
62 
63 	bool removeCurve(Qwt3D::Curve* curve);
64 	bool removeDrawable(Qwt3D::Drawable* drawable);
65 	bool removeTitle(Qwt3D::Label* label);
66 
67 	void createCoordinateSystem();
68 	void normaliseScale(Qwt3D::Curve* curve, Qwt3D::Plot3D* parentplot = 0, Qwt3D::ParallelEpiped* curvehull = 0);
69 
70 	typedef QVector<Qwt3D::Curve*> CurveList;
curveList()71 	const CurveList& curveList() const			{ return curvelist_p; }
72 
73 	typedef QVector<Qwt3D::Drawable*> DrawableList;
drawableList()74 	const DrawableList& drawableList() const	{ return drawablelist_p; }
75 
76 	typedef QVector<Qwt3D::Label*> TitleList;
titleList()77 	const TitleList& titleList() const			{ return titlelist_p; }
78 
isExportingVector()79 	bool isExportingVector(){return d_exporting_vector;};
vectorExportFormat()80 	GLint vectorExportFormat(){return gl2ps_export_format_;};
81 	void setExportingVector(bool on = true, GLint format = 0){d_exporting_vector = on; gl2ps_export_format_ = format;};
82 
83 signals:
84 	// Internally sent signals through signal slot mechanism
85 	void setCurveResolution(int);								//!< Emits, resolution change to all connected curves
86 	void setCurvePolygonOffset(double d);						//!< Emits, polygon offset change to all connected curves
87 	void setCurveIsolines(unsigned int isolines);				//!< Emits, number of isolines change to all connected curves
88 	void setCurvePlotStyle(Qwt3D::PLOTSTYLE val);				//!< Emits, plotting style change to all connected curves
89 	void setCurvePlotStyle(Qwt3D::Enrichment& val);				//!< Emits, user defined plotting style change to all connected curves
90 	void setCurveFloorStyle(Qwt3D::FLOORSTYLE val);				//!< Emits, floor style change to all connected curves
91 
92 	void showCurveColorLegend(bool on);							//!< Emits, show colour legend mode to all connected curves
93 	void showCurveNormals(bool on); 							//!< Emits, draw normals to every vertex to all connected curves
94 	void setCurveNormalLength(double val);						//!< Emits, set length of normals in percent per hull diagonale to all connected curves
95 	void setCurveNormalQuality(int val);						//!< Emits, increases plotting quality of normal arrows to all connected curves
96 
97 	void setCurveSmoothMesh(bool val);							//!< Emits, smooth data mesh lines setting to all connected curves
98 	void setCurveMeshColor(Qwt3D::RGBA rgba);					//!< Emits, colour for data mesh to all connected curves
99 	void setCurveMeshLineWidth(double lw);						//!< Emits, line width for data mesh to all connected curves
100 
101 	void setCurveDataColor(Color* col);							//!< Emits, data colour change to all connected curves
102 	void setCurveDataProjection(bool on);						//!< Emits, data point projection on & off to all connected curves
103 	void setCurveProjection(Qwt3D::PROJECTMODE val, bool on);	//!< Emits, projection mode to all connected curves
104 	void setCurveShading(Qwt3D::SHADINGSTYLE val);				//!< Emits, shading mode to all connected curves
105 
106 	void setCurveTitleColor(Qwt3D::RGBA col);					//!< Emits, caption color
107 	void setCurveTitle(const QString& title);					//!< Emits, caption text (one row only)
108 	void setCurveTitlePosition(double rely, double relx, Qwt3D::ANCHOR anchor);
109 	void setCurveTitleFont(const QString& family, int pointSize, int weight, bool italic);
110 
111 	void createEnrichments();
112 	void createData();
113 
114 public slots:
115 	void updateData(bool coord = true);							//!< Recalculate data
116 
setResolution(int val)117 	void setResolution(int val)							{ emit setCurveResolution(val); }		//!< Set resolution for all attached curves
setPolygonOffset(double d)118 	void setPolygonOffset(double d)						{ emit setCurvePolygonOffset(d); }		//!< Set polygon offset for all attached curves
setIsolines(unsigned int isolines)119 	void setIsolines(unsigned int isolines)				{ emit setCurveIsolines(isolines); }	//!< Set number of isolines for all attached curves
setPlotStyle(Qwt3D::PLOTSTYLE val)120 	void setPlotStyle(Qwt3D::PLOTSTYLE val)				{ emit setCurvePlotStyle(val); }		//!< Set plot style for all attached curves
setPlotStyle(Qwt3D::Enrichment & val)121 	void setPlotStyle(Qwt3D::Enrichment& val)			{ emit setCurvePlotStyle(val); }		//!< Set user defined plot style for all attached curves
setFloorStyle(Qwt3D::FLOORSTYLE val)122 	void setFloorStyle(Qwt3D::FLOORSTYLE val)			{ emit setCurveFloorStyle(val); }		//!< Set floor style for all attached curves
setShading(Qwt3D::SHADINGSTYLE val)123 	void setShading(Qwt3D::SHADINGSTYLE val)			{ emit setCurveShading(val); }			//!< Set shading modes for all attached curves
124 
showColorLegend(bool on)125 	void showColorLegend(bool on) 						{ emit showCurveColorLegend(on); }		//!< Draw colour legend for all attached curves
showNormals(bool on)126 	void showNormals(bool on) 							{ emit showCurveNormals(on); }			//!< Draw normals to every vertex for all attached curves
setNormalLength(double val)127 	void setNormalLength(double val)					{ emit setCurveNormalLength(val); }		//!< Set length of normals in percent per hull diagonale for all attached curves
setNormalQuality(int val)128 	void setNormalQuality(int val)						{ emit setCurveNormalQuality(val); }	//!< Set plotting quality of normal arrows for all attached curves
129 
setSmoothMesh(bool val)130 	void setSmoothMesh(bool val)						{ emit setCurveSmoothMesh(val); } 		//!< Enable/disable smooth data mesh lines for all attached curves
setMeshColor(Qwt3D::RGBA rgba)131 	void setMeshColor(Qwt3D::RGBA rgba)					{ emit setCurveMeshColor(rgba); }		//!< Set colour for data mesh for all attached curves
setMeshLineWidth(double lw)132 	void setMeshLineWidth(double lw)					{ emit setCurveMeshLineWidth(lw); }		//!< Set line width for data mesh for all attached curves
133 
setDataColor(Color * col)134 	void setDataColor(Color* col)						{ emit setCurveDataColor(col); }		//!< Set data colour for all attached curves
setDataProjection(bool on)135 	void setDataProjection(bool on)						{ emit setCurveDataProjection(on); }	//!< Set data point projection on & off for all attached curves
setProjection(Qwt3D::PROJECTMODE val,bool on)136 	void setProjection(Qwt3D::PROJECTMODE val, bool on)	{ emit setCurveProjection(val, on); }	//!< Set projection modes for all attached curves
137 
setTitleColor(Qwt3D::RGBA col)138 	void setTitleColor(Qwt3D::RGBA col)					{ emit setCurveTitleColor(col); }		//!< Set caption color
setTitle(const QString & title)139 	void setTitle(const QString& title)					{ emit setCurveTitle(title); }			//!< Set caption text (one row only)
140 	void setTitlePosition(double rely, double relx = 0.5, Qwt3D::ANCHOR anchor = Qwt3D::TopCenter)
141 														{ emit setCurveTitlePosition(rely, relx, anchor); }		//!< Set caption text position
142 	void setTitleFont(const QString& family, int pointSize, int weight = QFont::Normal, bool italic = false)
143 														{ emit setCurveTitleFont(family, pointSize, weight, italic); }	//!< Set caption text font
144 
145     virtual bool savePixmap(QString const& fileName, QString const& format);					//!<  Saves content to pixmap format
146     virtual bool saveVector(QString const& fileName, QString const& format,
147     						VectorWriter::TEXTMODE text, VectorWriter::SORTMODE sortmode);		//!<  Saves content to vector format
148 	virtual bool save(QString const& fileName, QString const& format);							//!<  Saves content
149 
150 protected:
151 	void initializeGL();
152 	void paintGL();
153 	void resizeGL(int w, int h);
setHull(Qwt3D::ParallelEpiped p)154 	void setHull(Qwt3D::ParallelEpiped p) {hull_ = p;}
155 
156 	enum OBJECTS {
157 		LegendObject,
158 		NormalObject,
159 		DisplayListSize // only to have a vector length ...
160 	};
161 
162 	std::vector<GLuint>		displaylists_p;
163 	Qwt3D::CoordinateSystem coordinates_p;
164 
165     Qwt3D::Curve*	curve_p;
166 	Qwt3D::Label*	title_p;
167 
168     CurveList		curvelist_p;
169     DrawableList	drawablelist_p;
170     TitleList		titlelist_p;
171 
172 private:
173 	void childConnect(bool connect);
intScale(double & scale)174 	inline void intScale(double& scale)		{ scale = (scale > 10) ? floor(scale + 0.5) : floor(10*scale + 0.5)/10; }
175 
176     bool			update_coordinate_sys_;
177 	Qwt3D::RGBA		meshcolor_;
178 	double			meshLineWidth_;
179 	Qwt3D::RGBA		bgcolor_;
180 	bool			renderpixmaprequest_;
181 	bool			doublelegend_;
182 	bool			d_exporting_vector;
183 	GLint			gl2ps_export_format_;
184 
185 	Qwt3D::ParallelEpiped	hull_;
186 };
187 
188 } // ns
189 
190 #endif
191