OSDN Git Service

Initial Commit
[qcad/qcad.git] / qcadwin / QDrawGraph.h
1 //---------------------------------------------------------------------------\r
2 // Show qbits' states\r
3 //---------------------------------------------------------------------------\r
4 #ifndef QDrawGraphH\r
5 #define QDrawGraphH\r
6 //---------------------------------------------------------------------------\r
7 #include <vector>\r
8 #include "QBits.h"\r
9 \r
10 //---------------------------------------------------------------------------\r
11 class QDrawGraph {\r
12 public:\r
13 \r
14   static const int DS_NO   = 0;\r
15   static const int DS_UP   = 1;\r
16 \r
17   static const int DM_ALL  = 0;// DrawMode :DrawAll\r
18   static const int DM_NONZERO  = 1;// DrawMode :Draw Onlye NonZero\r
19 \r
20   static const int FSIZE_INDEX = 12;//TODO:\r
21 \r
22   static const double EPS;\r
23 \r
24   QDrawGraph(TCanvas *_Canvas);\r
25   ~QDrawGraph();\r
26 \r
27   void    DrawAll(const QBits *qbit, const int type=DS_NO);\r
28   void    Paint(const QBits *qbit);\r
29 \r
30   void    SetCanvas(TCanvas *_Canvas) {mCanvas = _Canvas;}\r
31   void    SetSizeOfArrow(const int size) {mSizeOfArrow = size;}\r
32   void    SetFontSizeOfQbit(const int size) {mFontSizeOfQbit = size;}\r
33   void    SetFontSizeOfValue(const int size) {mFontSizeOfValue = size;}\r
34   void    SetPrecision(const int val) {mPrecision = val;}\r
35   void    SetSize(const QBits *qbits);\r
36   void    SetSizeNonZero(const QBits *qbits);\r
37   void    SetImageSize(int w,int h) {mImageWidth=w;mImageHeight=h;};\r
38   int     GetViewingTop(void) {return mViewingTop;};\r
39   void    SetViewingTop(int t);\r
40   double  GetViewingTopRatio(void) {return (double)mViewingTop/(double)(mHeight- mImageHeight);};\r
41   void    SetViewingTopRatio(double r) {mViewingTop = int ((double)(mHeight- mImageHeight))*r;};\r
42   void    SetDrawMode(int Mode, const QBits *qbits);\r
43   int     GetDrawMode(void) {return mDrawMode;};\r
44 \r
45 // NonZero\r
46   void DrawNonZero(const QBits *qbits);\r
47   int GetNonZeroCount(const QBits *qbits);\r
48 \r
49 \r
50 private:\r
51   TCanvas *mCanvas;\r
52 \r
53 //Draw Mode\r
54 \r
55   int     mDrawMode;\r
56 \r
57 //Margin\r
58   int     mTopWindowMargin;\r
59   int     mTopMargin;\r
60   int     mLeftMargin;\r
61   int     mRowMargin;\r
62   int     mRightMargin;\r
63   int     mBottomMargin;\r
64   int     mIAMargin;\r
65   int     mAVMargin;\r
66   int     mVQMargin;\r
67   int     mStrOffset;\r
68 \r
69 //Size of Image\r
70   int     mImageHeight;\r
71   int     mImageWidth;\r
72 \r
73 //View Control\r
74 \r
75   int     mViewingTop;\r
76   int     mHeight;\r
77   int     mWidth;\r
78 \r
79 //Size of elements\r
80   int     mSizeOfArrow;\r
81   int     mFontSizeOfValue;\r
82   int     mFontSizeOfQbit;\r
83   int     mPrecision;\r
84 \r
85 //Below members are set automatically\r
86   int     mWidthOfIndex;\r
87   int     mHeightOfIndex;\r
88   int     mWidthOfArrow;\r
89   int     mHeightOfArrow;\r
90   int     mWidthOfValue;\r
91   int     mHeightOfValue;\r
92   int     mWidthOfQbits;\r
93   int     mHeightOfQbits;\r
94 \r
95 //---------------------------------------------------------------------------\r
96 // Utility functions\r
97 //---------------------------------------------------------------------------\r
98   int  GetRowHeight(void) const;\r
99   void SetPageFormat(const QBits *qbits);\r
100   void DrawNthRow(const QBits *qbits, const int nq, const int nrow) const;\r
101   void DrawIndex(const int x, const int y, const int num) const;\r
102   void DrawArrow(const int x, const int y, const double re, const double im) const;\r
103   void DrawValue(const int x, const int y, double re, double im) const;\r
104   void DrawQbit(const int x, const int y, const int ntotal, int nth) const;\r
105 \r
106 \r
107 };\r
108 \r
109 \r
110 //---------------------------------------------------------------------------\r
111 class QBitSortElement {\r
112 private:\r
113   int index;\r
114   double re;\r
115   double im;\r
116 \r
117 public:\r
118   QBitSortElement(const int _index) {index = _index; re = 0.0; im = 0.0;}\r
119   QBitSortElement(const int _index, const double _re, const double _im) {index = _index; re = _re; im = _im;}\r
120   ~QBitSortElement() {}\r
121   int GetIndex(void) {return index;}\r
122 \r
123 //===========================================================================\r
124 // Warning, Operator < is redefined for sort (shoddy construction)\r
125 //===========================================================================\r
126   bool operator<(const QBitSortElement &qelem) const {return re * re + im * im > qelem.re * qelem.re + qelem.im * qelem.im;}\r
127 };\r
128 \r
129 typedef std::vector<QBitSortElement> QBitSortList;\r
130 \r
131 //---------------------------------------------------------------------------\r
132 #endif\r