| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | |
|---|
| 25 | |
|---|
| 26 | |
|---|
| 27 | #ifdef HAVE_FSTREAM |
|---|
| 28 | #include <fstream> |
|---|
| 29 | #else |
|---|
| 30 | #include <fstream.h> |
|---|
| 31 | #endif |
|---|
| 32 | #include <math.h> // For fabs() |
|---|
| 33 | #include "general.h" |
|---|
| 34 | #include "fieldmeter.h" |
|---|
| 35 | #include "fieldmetergraph.h" |
|---|
| 36 | #include "xosview.h" |
|---|
| 37 | |
|---|
| 38 | CVSID("$Id: fieldmetergraph.cc,v 1.1.1.1 2008/05/04 15:53:48 emasson Exp $"); |
|---|
| 39 | CVSID_DOT_H(FIELDMETERGRAPH_H_CVSID); |
|---|
| 40 | |
|---|
| 41 | FieldMeterGraph::FieldMeterGraph( XOSView *parent, |
|---|
| 42 | int numfields, const char *title, |
|---|
| 43 | const char *legend, int docaptions, int dolegends, |
|---|
| 44 | int dousedlegends ) |
|---|
| 45 | : FieldMeterDecay (parent, numfields, title, legend, docaptions, |
|---|
| 46 | dolegends, dousedlegends) |
|---|
| 47 | { |
|---|
| 48 | |
|---|
| 49 | useGraph_ = 0; |
|---|
| 50 | heightfield_ = NULL; |
|---|
| 51 | firstTimeDrawn_ = 1; |
|---|
| 52 | |
|---|
| 53 | |
|---|
| 54 | |
|---|
| 55 | setNumCols( 100 ); |
|---|
| 56 | |
|---|
| 57 | } |
|---|
| 58 | |
|---|
| 59 | FieldMeterGraph::~FieldMeterGraph( void ) |
|---|
| 60 | { |
|---|
| 61 | delete [] heightfield_; |
|---|
| 62 | } |
|---|
| 63 | |
|---|
| 64 | void FieldMeterGraph::drawfields( int manditory ) |
|---|
| 65 | { |
|---|
| 66 | int i,j; |
|---|
| 67 | |
|---|
| 68 | if( !useGraph_ ) |
|---|
| 69 | { |
|---|
| 70 | |
|---|
| 71 | |
|---|
| 72 | FieldMeterDecay::drawfields( manditory ); |
|---|
| 73 | return; |
|---|
| 74 | } |
|---|
| 75 | |
|---|
| 76 | if( total_ <= 0.0 ) |
|---|
| 77 | return; |
|---|
| 78 | |
|---|
| 79 | |
|---|
| 80 | |
|---|
| 81 | |
|---|
| 82 | if( heightfield_ == NULL ) |
|---|
| 83 | { |
|---|
| 84 | if( numfields_ > 0 && graphNumCols_ > 0 ) |
|---|
| 85 | { |
|---|
| 86 | heightfield_ = new float [numfields_*graphNumCols_]; |
|---|
| 87 | |
|---|
| 88 | for( i = 0; i < graphNumCols_; i++ ) |
|---|
| 89 | { |
|---|
| 90 | for( j = 0; j < numfields_; j++ ) |
|---|
| 91 | { |
|---|
| 92 | if( j < numfields_-1 ) |
|---|
| 93 | heightfield_[i*numfields_+j] = 0.0; |
|---|
| 94 | else |
|---|
| 95 | heightfield_[i*numfields_+j] = 1.0; |
|---|
| 96 | } |
|---|
| 97 | } |
|---|
| 98 | } |
|---|
| 99 | } |
|---|
| 100 | |
|---|
| 101 | |
|---|
| 102 | if( graphpos_ >= graphNumCols_ ) |
|---|
| 103 | { |
|---|
| 104 | for( i = 0; i < graphNumCols_-1; i++ ) |
|---|
| 105 | { |
|---|
| 106 | for( j = 0; j < numfields_; j++ ) |
|---|
| 107 | { |
|---|
| 108 | heightfield_[i*numfields_+j] = heightfield_[(i+1)*numfields_+j]; |
|---|
| 109 | } |
|---|
| 110 | } |
|---|
| 111 | graphpos_ = graphNumCols_ - 1; |
|---|
| 112 | } |
|---|
| 113 | |
|---|
| 114 | |
|---|
| 115 | for( i = 0; i < numfields_; i++ ) |
|---|
| 116 | { |
|---|
| 117 | float a = fields_[i] / total_; |
|---|
| 118 | if( a <= 0.0 ) |
|---|
| 119 | a = 0.0; |
|---|
| 120 | if( a >= 1.0 ) |
|---|
| 121 | a = 1.0; |
|---|
| 122 | heightfield_[graphpos_*numfields_+i] = a; |
|---|
| 123 | } |
|---|
| 124 | |
|---|
| 125 | |
|---|
| 126 | |
|---|
| 127 | |
|---|
| 128 | |
|---|
| 129 | if( !firstTimeDrawn_ && parent_->hasBeenExposedAtLeastOnce() && !parent_->isExposed() && parent_->isFullyVisible() ) |
|---|
| 130 | { |
|---|
| 131 | |
|---|
| 132 | int col_width = width_/graphNumCols_; |
|---|
| 133 | if( col_width < 1 ) |
|---|
| 134 | { |
|---|
| 135 | col_width = 1; |
|---|
| 136 | } |
|---|
| 137 | |
|---|
| 138 | int sx = x_ + col_width; |
|---|
| 139 | int swidth = width_ - col_width; |
|---|
| 140 | int sheight = height_ + 1; |
|---|
| 141 | if( sx > x_ && swidth > 0 && sheight > 0 ) |
|---|
| 142 | parent_->copyArea( sx, y_, swidth, sheight, x_, y_ ); |
|---|
| 143 | drawBar( graphNumCols_ - 1 ); |
|---|
| 144 | } else { |
|---|
| 145 | if (firstTimeDrawn_ && |
|---|
| 146 | parent_->isAtLeastPartiallyVisible() && |
|---|
| 147 | parent_->hasBeenExposedAtLeastOnce()) { |
|---|
| 148 | XOSDEBUG("True exposure! %d\n", firstTimeDrawn_); |
|---|
| 149 | firstTimeDrawn_ = 0; |
|---|
| 150 | } |
|---|
| 151 | else XOSDEBUG("Full draw: isAtLeastPart %d, hasBeenExposed %d\n", |
|---|
| 152 | parent_->isAtLeastPartiallyVisible(), |
|---|
| 153 | parent_->hasBeenExposedAtLeastOnce()); |
|---|
| 154 | |
|---|
| 155 | for( i = 0; i < graphNumCols_; i++ ) { |
|---|
| 156 | drawBar( i ); |
|---|
| 157 | } |
|---|
| 158 | } |
|---|
| 159 | |
|---|
| 160 | graphpos_++; |
|---|
| 161 | parent_->setStippleN(0); |
|---|
| 162 | if ( dousedlegends_ ) |
|---|
| 163 | { |
|---|
| 164 | drawused( manditory ); |
|---|
| 165 | } |
|---|
| 166 | } |
|---|
| 167 | void FieldMeterGraph::drawBar( int i ) |
|---|
| 168 | { |
|---|
| 169 | int j; |
|---|
| 170 | int y = y_ + height_; |
|---|
| 171 | int x = x_ + i*width_/graphNumCols_; |
|---|
| 172 | int barwidth = (x_ + (i+1)*width_/graphNumCols_)-x; |
|---|
| 173 | |
|---|
| 174 | if( barwidth>0 ) |
|---|
| 175 | { |
|---|
| 176 | int barheight; |
|---|
| 177 | for( j = 0 ; j < numfields_; j++ ) |
|---|
| 178 | { |
|---|
| 179 | |
|---|
| 180 | |
|---|
| 181 | barheight = (int)((heightfield_[i*numfields_+j]*height_)+0.5); |
|---|
| 182 | |
|---|
| 183 | parent_->setForeground( colors_[j] ); |
|---|
| 184 | parent_->setStippleN(j%4); |
|---|
| 185 | |
|---|
| 186 | if( barheight > (y-y_) ) |
|---|
| 187 | barheight = (y-y_); |
|---|
| 188 | |
|---|
| 189 | |
|---|
| 190 | if( j == numfields_-1 ) |
|---|
| 191 | barheight = (y-y_); |
|---|
| 192 | |
|---|
| 193 | y -= barheight; |
|---|
| 194 | if( barheight>0 ) |
|---|
| 195 | parent_->drawFilledRectangle( x, y, barwidth, barheight ); |
|---|
| 196 | } |
|---|
| 197 | } |
|---|
| 198 | } |
|---|
| 199 | void FieldMeterGraph::checkResources( void ) |
|---|
| 200 | { |
|---|
| 201 | FieldMeterDecay::checkResources(); |
|---|
| 202 | |
|---|
| 203 | const char *ptr = parent_->getResource( "graphNumCols" ); |
|---|
| 204 | if( ptr ) |
|---|
| 205 | { |
|---|
| 206 | int i; |
|---|
| 207 | if( sscanf( ptr, "%d", &i ) == 1 ) |
|---|
| 208 | { |
|---|
| 209 | if( i>0 ) |
|---|
| 210 | { |
|---|
| 211 | setNumCols( i ); |
|---|
| 212 | } |
|---|
| 213 | } |
|---|
| 214 | } |
|---|
| 215 | } |
|---|
| 216 | void FieldMeterGraph::setNumCols( int n ) |
|---|
| 217 | { |
|---|
| 218 | graphNumCols_ = n; |
|---|
| 219 | graphpos_ = graphNumCols_-1; |
|---|
| 220 | |
|---|
| 221 | if( heightfield_ ) |
|---|
| 222 | delete [] heightfield_; |
|---|
| 223 | heightfield_ = NULL; |
|---|
| 224 | |
|---|
| 225 | } |
|---|