00001 /* 00002 ** ---------------------------------------------------------------- 00003 ** prm.cpp - Primitive class. 00004 ** 00005 ** ---------------------------------------------------------------- 00006 */ 00007 00030 /* 00031 ** --------------------------------------------------------------- 00032 ** Global variables and symbols: 00033 */ 00034 #include <stdlib.h> 00035 #include <stdio.h> 00036 #include "prm.h" 00037 00038 /* 00039 ** --------------------------------------------------------------- 00040 ** Initialization of class variables: 00041 */ 00044 Prm* Prm::prm_head = 0L; 00045 00048 const double Prm::COORD_TOL = 0.001; 00049 00050 /* 00051 ** --------------------------------------------------------------- 00052 ** Public constructor and destructor functions: 00053 ** 00054 */ 00055 /*========================= Prm::Prm =========================*/ 00056 00057 Prm::Prm( ) 00058 { 00059 Reset( ); 00060 InsertFront( ); 00061 } 00062 00063 /*========================= Prm::Prm =========================*/ 00064 00065 Prm::Prm( int back ) 00066 { 00067 Reset( ); 00068 if( !back ) 00069 InsertFront( ); 00070 else 00071 InsertBack( ); 00072 } 00073 00074 /*========================= Prm::~Prm ========================*/ 00075 00076 Prm::~Prm( ) 00077 { 00078 RemoveFromList( ); 00079 } 00080 00081 /* 00082 ** --------------------------------------------------------------- 00083 ** Public class functions: 00084 ** 00085 */ 00086 /*======================= Prm::DeleteList ======================*/ 00087 00088 void Prm::DeleteList( void ) 00089 { 00090 while( prm_head != NULL ) 00091 { 00092 delete prm_head; 00093 } 00094 } 00095 00096 /*========================== Prm::First ========================*/ 00097 00098 Prm* Prm::First( void ) 00099 { 00100 return( prm_head ); 00101 } 00102 00103 /*========================== Prm::Last =========================*/ 00104 00105 Prm* Prm::Last( void ) 00106 { 00107 if( prm_head == NULL ) 00108 return( NULL ); 00109 00110 return( prm_head->prev ); 00111 } 00112 00113 /*======================= Prm::SelectAll =======================*/ 00114 00115 void Prm::SelectAll( ) 00116 { 00117 Prm* prm; 00118 00119 for( prm = First( ); prm != NULL; prm = prm->Next( ) ) 00120 { 00121 prm->sel = 1; 00122 } 00123 } 00124 00125 /*====================== Prm::UnselectAll ======================*/ 00126 00127 void Prm::UnselectAll( ) 00128 { 00129 Prm* prm; 00130 00131 for( prm = First( ); prm != NULL; prm = prm->Next( ) ) 00132 { 00133 prm->sel = 0; 00134 } 00135 } 00136 00137 /*====================== Prm::GetGlobalBox =====================*/ 00138 00139 int Prm::GetGlobalBox( double* xmin, double* xmax, 00140 double* ymin, double* ymax ) 00141 { 00142 /*** COMPLETE HERE: 01 ***/ 00143 00144 00145 00146 00147 00148 00149 00150 00151 00152 00153 00154 00155 00156 00157 00158 00159 /*** COMPLETE HERE: 01 ***/ 00160 00161 return( 1 ); 00162 } 00163 00164 /* 00165 ** --------------------------------------------------------------- 00166 ** Private general instance (object) functions 00167 ** (implemented in base class): 00168 ** 00169 */ 00170 /*======================== Prm::Reset ========================*/ 00171 00172 void Prm::Reset( void ) 00173 { 00174 /* Set default initial values for a primitive. 00175 */ 00176 this->next = NULL; 00177 this->prev = NULL; 00178 this->type = PRM_UNDEF; 00179 this->sel = 0; 00180 this->color = 0L; 00181 this->height = 0.0; 00182 } 00183 00184 /*====================== Prm::InsertFront ======================*/ 00185 00186 void Prm::InsertFront( void ) 00187 { 00188 /*** COMPLETE HERE: 02 ***/ 00189 00190 00191 00192 00193 00194 00195 00196 00197 00198 00199 00200 00201 00202 /*** COMPLETE HERE: 02 ***/ 00203 } 00204 00205 /*====================== Prm::InsertBack =======================*/ 00206 00207 void Prm::InsertBack( void ) 00208 { 00209 /*** COMPLETE HERE: 03 ***/ 00210 00211 00212 00213 00214 00215 00216 00217 00218 00219 00220 00221 00222 00223 /*** COMPLETE HERE: 03 ***/ 00224 } 00225 00226 /*===================== Prm::RemoveFromList ====================*/ 00227 00228 void Prm::RemoveFromList( void ) 00229 { 00230 /*** COMPLETE HERE: 04 ***/ 00231 00232 00233 00234 00235 00236 00237 00238 00239 00240 00241 00242 00243 00244 00245 00246 /*** COMPLETE HERE: 04 ***/ 00247 } 00248 00249 /* 00250 ** --------------------------------------------------------------- 00251 ** Public general instance (object) functions 00252 ** (implemented in base class): 00253 ** 00254 */ 00255 /*========================== Prm::Next =========================*/ 00256 00257 Prm* Prm::Next( void ) 00258 { 00259 if( this == prm_head->prev ) 00260 return( NULL ); 00261 00262 return( this->next ); 00263 } 00264 00265 /*======================== Prm::Previous =======================*/ 00266 00267 Prm* Prm::Previous( void ) 00268 { 00269 if( this == prm_head ) 00270 return( NULL ); 00271 00272 return( this->prev ); 00273 } 00274 00275 /*======================= Prm::MoveFront =======================*/ 00276 00277 void Prm::MoveFront( void ) 00278 { 00279 /* Handle case in which the current primitive is already at the 00280 * beginning of list. This also considers the case of a single 00281 * primitive list. 00282 */ 00283 if( this == prm_head ) 00284 return; 00285 00286 /* When we get here, there are at least two primitives in 00287 * the list and the primitive to move is not the first one. 00288 * Therefore, it is just necessary to remove from its 00289 * current position in the list and inserts it at the beginning 00290 * of list. 00291 */ 00292 this->RemoveFromList( ); 00293 this->InsertFront( ); 00294 } 00295 00296 /*======================== Prm::MoveBack =======================*/ 00297 00298 void Prm::MoveBack( void ) 00299 { 00300 /* Handle case in which the current primitive is already at the 00301 * end of list. This also considers the case of a single 00302 * primitive list. 00303 */ 00304 if( this == prm_head->prev ) 00305 return; 00306 00307 /* When we get here, there are at least two primitives in 00308 * the list and the primitive to move is not the last one. 00309 * Therefore, it is just necessary to remove from its 00310 * current position in the list and inserts it at the end 00311 * of list. 00312 */ 00313 this->RemoveFromList( ); 00314 this->InsertBack( ); 00315 } 00316 00317 /*======================== Prm::GetType ========================*/ 00318 00319 Prm::Type Prm::GetType( void ) 00320 { 00321 return( this->type ); 00322 } 00323 00324 /*========================= Prm::Select ========================*/ 00325 00326 void Prm::Select( void ) 00327 { 00328 this->sel = 1; 00329 } 00330 00331 /*======================== Prm::Unselect =======================*/ 00332 00333 void Prm::Unselect( void ) 00334 { 00335 this->sel = 0; 00336 } 00337 00338 /*===================== Prm::CheckSelected =====================*/ 00339 00340 int Prm::CheckSelected( void ) 00341 { 00342 return( this->sel ); 00343 } 00344 00345 /*======================== Prm::SetColor =======================*/ 00346 00347 void Prm::SetColor( long int color ) 00348 { 00349 this->color = color; 00350 } 00351 00352 /*======================== Prm::GetColor =======================*/ 00353 00354 long int Prm::GetColor( void ) 00355 { 00356 return( this->color ); 00357 } 00358 00359 /*======================== Prm::SetHeight ======================*/ 00360 00361 void Prm::SetHeight( double height ) 00362 { 00363 this->height = height; 00364 } 00365 00366 /*======================== Prm::GetHeight ======================*/ 00367 00368 double Prm::GetHeight( void ) 00369 { 00370 return( this->height ); 00371 } 00372
1.4.2-20050421