My Project  0.0.16
QUCS Mapping
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
diagram.h
Go to the documentation of this file.
1 /***************************************************************************
2  diagram.h
3  -----------
4  begin : Thu Oct 2 2003
5  copyright : (C) 2003 by Michael Margraf
6  email : michael.margraf@alumni.tu-berlin.de
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #ifndef DIAGRAM_H
19 #define DIAGRAM_H
20 
21 #include "graph.h"
22 #include "marker.h"
23 #include "element.h"
24 #include "viewpainter.h"
25 
26 #include <qfile.h>
27 
28 #define MIN_SCROLLBAR_SIZE 8
29 
30 #define INVALID_STR QObject::tr(" <invalid>")
31 
32 // ------------------------------------------------------------
33 // Enlarge memory block if neccessary.
34 #define FIT_MEMORY_SIZE \
35  if(p >= p_end) { \
36  Size += 256; \
37  tmp = p - g->ScrPoints; \
38  p = p_end = g->ScrPoints = (float*)realloc(g->ScrPoints, Size*sizeof(float)); \
39  p += tmp; \
40  p_end += Size - 9; \
41  } \
42 
43 
44 struct Axis {
45  double min, max; // least and greatest values of all graph data
46  double low, up; // the limits of the diagram
47  bool log; // in "rectdiagram": logarithmic or linear
48  QString Label;
49  int numGraphs; // counts number of graphs using this axis
50  bool GridOn;
51 
52  bool autoScale; // manual limits or auto-scale ?
53  double limit_min, limit_max, step; // if not auto-scale
54 };
55 
56 
57 class Diagram : public Element {
58 public:
59  Diagram(int _cx=0, int _cy=0);
60  virtual ~Diagram();
61 
62  virtual Diagram* newOne();
63  virtual int calcDiagram() { return 0; };
64  virtual void calcCoordinate
65  (double* &, double* &, double* &, float*, float*, Axis*) {};
66  virtual void calcLimits() {};
67 
68  virtual void paint(ViewPainter*);
69  void setCenter(int, int, bool relative=false);
70  void getCenter(int&, int&);
71  void paintScheme(QPainter*);
72  void Bounding(int&, int&, int&, int&);
73  bool getSelected(int, int);
74  bool resizeTouched(float, float, float);
75  QString save();
76  bool load(const QString&, QTextStream*);
77 
78  void getAxisLimits(Graph*);
79  void updateGraphData();
80  void loadGraphData(const QString&);
81  void recalcGraphData();
82  int loadVarData(const QString&, Graph*);
83  int loadIndepVarData(const QString&, char*, Axis*, Graph*);
84  bool sameDependencies(Graph*, Graph*);
85  int checkColumnWidth(const QString&, const QFontMetrics&, int, int, int);
86 
87  virtual bool insideDiagram(float, float);
88 
89  QString Name; // identity of diagram type (e.g. Polar), used for saving etc.
90  QPen GridPen;
91 
92  QPtrList<Graph> Graphs;
93  QPtrList<struct Arc> Arcs;
94  QPtrList<Line> Lines;
95  QPtrList<Text> Texts;
96 
97  int x3, y3;
98  Axis xAxis, yAxis, zAxis; // axes (x, y left, y right)
99  int State; // to remember which resize area was touched
100 
101  bool hideLines; // for "Rect3D": hide invisible lines ?
102  int rotX, rotY, rotZ; // for "Rect3D": rotation around x, y and z axis
103 
104 
105 protected:
106  void calcSmithAxisScale(Axis*, int&, int&);
107  void createSmithChart(Axis*, int Mode=7);
108  void calcPolarAxisScale(Axis*, double&, double&, double&);
109  void createPolarDiagram(Axis*, int Mode=3);
110 
111  bool calcAxisScale(Axis*, double&, double&, double&, double&, double);
112  bool calcAxisLogScale(Axis*, int&, double&, double&, double&, int);
113  bool calcYAxis(Axis*, int);
114  virtual void createAxisLabels();
115 
116  int regionCode(float, float);
117  virtual void clip(float* &);
118  void rectClip(float* &);
119 
120  virtual void calcData(Graph*);
121 
122 private:
123  int Bounding_x1, Bounding_x2, Bounding_y1, Bounding_y2;
124 };
125 
126 #endif