Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

model.cpp

Go to the documentation of this file.
00001 /*
00002 ** ----------------------------------------------------------------
00003 ** model.cpp  -  Primitive model class.
00004 **
00005 ** ----------------------------------------------------------------
00006 */
00007 
00041 /*
00042 ** ---------------------------------------------------------------
00043 ** Global variables and symbols:
00044 */
00045 #include "cd.h"
00046 #include "wd.h"
00047 
00048 #include "dsp.h"
00049 #include "model.h"
00050 #include "prm.h"
00051 #include "prmio.h"
00052 #include "prmed.h"
00053 
00054 
00055 /*
00056 ** ---------------------------------------------------------------
00057 ** Initialization of class variables:
00058 */
00059 
00062 Model* Model::curr_model = 0L;
00063 
00064 /*
00065 ** ---------------------------------------------------------------
00066 ** Public class functions: 
00067 */
00068 /*======================  Model::GetCurrModel  =====================*/
00069 
00070 Model* Model::GetCurrModel( void )
00071 {
00072  return( curr_model );
00073 }
00074 
00075 /*
00076 ** ---------------------------------------------------------------
00077 ** Public constructor and destructor functions:
00078 **
00079 */
00080 /*=========================  Model::Model  =========================*/
00081 
00082 Model::Model( cdCanvas* canvas, Dsp* display )
00083 {
00084  curr_model = this;
00085  PrmEd::InitParams( canvas, display );
00086 }
00087 
00088 /*=========================  Model::~Model  ========================*/
00089 
00090 Model::~Model( )
00091 {
00092  Prm::DeleteList( );
00093 }
00094 
00095 /*
00096 ** ---------------------------------------------------------------
00097 ** Public instance functions:
00098 **
00099 */
00100 
00101 /*======================  Model::ChkEmptyModel  ====================*/
00102 
00103 bool Model::ChkEmptyModel( void )
00104 {
00105  return( Prm::ChkEmptyModel( ) );
00106 }
00107 
00108 /*=========================  Model::Reset  ==========================*/
00109 
00110 void Model::Reset( void )
00111 {
00112  Prm::DeleteList( );
00113  PrmEd::ResetParams( );
00114 }
00115 
00116 /*===========================  Model::Open  =========================*/
00117 
00118 int Model::Open( FILE *fd )
00119 {
00120  int status;
00121 
00122 /* Delete current model (if there is one) and reset primitive
00123  * edition module.
00124  */
00125  Prm::DeleteList( );
00126  PrmEd::ResetParams( );
00127 
00128 /* Read new data file
00129  */
00130  status = PrmIO::Interpret( fd );
00131 
00132  if( status )
00133  {
00134 /* Compute maximum height of primitive edition module
00135  * based on new model bounding box.
00136  */
00137   double xmin, xmax, ymin, ymax;
00138   if( Prm::GetGlobalBox( &xmin, &xmax, &ymin, &ymax ) )
00139   {
00140    double sizex = xmax - xmin;
00141    double sizey = ymax - ymin;
00142    double max_height = ( sizex > sizey ) ? sizex : sizey;
00143    PrmEd::SetMaxHeight( max_height );
00144   }
00145  }
00146 
00147  return( status );
00148 }
00149 
00150 /*==========================  Model::Save  ==========================*/
00151 
00152 void Model::Save( FILE *fd )
00153 {
00154  if( Prm::ChkEmptyModel( ) )
00155   return;
00156 
00157 /* Write primitive list to file.
00158  */
00159  PrmIO::WriteList( fd );
00160 }
00161 
00162 /*======================  Model::GetGlobalBox  =====================*/
00163 
00164 int Model::GetGlobalBox( double* xmin, double* xmax, 
00165                          double* ymin, double* ymax )
00166 {
00167  int status = Prm::GetGlobalBox( xmin, xmax, ymin, ymax );
00168 
00169  return( status );
00170 }
00171 
00172 /*========================  Model::Display  ========================*/
00173 
00174 void Model::Display( cdCanvas* canvas )
00175 {
00176 /* Set mark display parameters.
00177  */
00178  cdCanvasMarkType( canvas, CD_BOX );
00179  cdCanvasMarkSize( canvas, 7 );
00180 
00181 /* Traverse list of primitives in reverse order displaying
00182  * each primitive.  This will display first the primitives
00183  * at the back (the first primitives will appear at the front).
00184  * Also get the pointer to the selected primitive (if there is one).
00185  */
00186  Prm *sel_prm = NULL;
00187 /*** COMPLETE AQUI: MODEL-01 ***/
00188 
00189 
00190 
00191 
00192 
00193 
00194 
00195 
00196 
00197 /*** COMPLETE AQUI: MODEL-01 ***/
00198 
00199 /* Hightlight the selected primitive (if there is one).
00200  */
00201  if( sel_prm )
00202  {
00203   cdCanvasForeground( canvas, CD_RED );
00204 /*** COMPLETE AQUI: MODEL-02 ***/
00205 
00206 /*** COMPLETE AQUI: MODEL-02 ***/
00207  }
00208 }
00209 
00210 /*========================  Model::SetColor  =======================*/
00211 
00212 void Model::SetColor( long int color )
00213 {
00214  PrmEd::SetColor( color );
00215 }
00216 
00217 /*========================  Model::GetColor  =======================*/
00218 
00219 long int Model::GetColor( void )
00220 {
00221  return( PrmEd::GetColor( ) );
00222 }
00223 
00224 /*======================  Model::SetPrmType  =======================*/
00225 
00226 void Model::SetPrmType( Prm::Type type )
00227 {
00228  PrmEd::SetCurType( type );
00229 }
00230 
00231 /*====================  Model::UnselectAllPrm  =====================*/
00232 
00233 void Model::UnselectAllPrm( void )
00234 {
00235  PrmEd::UnselectAllPrm( );
00236 }
00237 
00238 /*====================  Model::InsertPrm1stPt  =====================*/
00239 
00240 void Model::InsertPrm1stPt( double x, double y, double tol )
00241 {
00242  PrmEd::InsertPrm1stPt( x, y, tol );
00243 }
00244 
00245 /*=====================  Model::EchoPrm2ndPt  ======================*/
00246 
00247 void Model::EchoPrm2ndPt( double x, double y )
00248 {
00249  PrmEd::EchoPrm2ndPt( x, y );
00250 }
00251 
00252 /*=====================  Model::InsertPrm2ndPt  =====================*/
00253 
00254 void Model::InsertPrm2ndPt( double x, double y )
00255 {
00256  PrmEd::InsertPrm2ndPt( x, y );
00257 }
00258 
00259 /*======================  Model::SelectDragPrm  ====================*/
00260 
00261 void Model::SelectDragPrm( double x, double y, double tol )
00262 {
00263  PrmEd::SelectDragPrm( x, y, tol );
00264 }
00265 
00266 /*=====================  Model::UpdateDragPrm  =====================*/
00267 
00268 void Model::UpdateDragPrm( double x, double y )
00269 {
00270  PrmEd::UpdateDragPrm( x, y );
00271 }
00272 
00273 /*=====================  Model::FinishDragPrm  =====================*/
00274 
00275 void Model::FinishDragPrm( double x, double y )
00276 {
00277  PrmEd::FinishDragPrm( x, y );
00278 }
00279 
00280 /*======================  Model::DeleteSelPrm  =====================*/
00281 
00282 void Model::DeleteSelPrm( void )
00283 {
00284  PrmEd::DeleteSelPrm( );
00285 }
00286 
00287 /*===================  Model::MoveSelPrmToFront  ===================*/
00288 
00289 void Model::MoveSelPrmToFront( void )
00290 {
00291  PrmEd::MoveSelPrmToFront( );
00292 }
00293 
00294 /*===================  Model::MoveSelPrmToBack  ====================*/
00295 
00296 void Model::MoveSelPrmToBack( void )
00297 {
00298  PrmEd::MoveSelPrmToBack( );
00299 }
00300 
00301 /*=====================  Model::SetHeightFac  ======================*/
00302 
00303 void Model::SetHeightFac( double fac )
00304 {
00305  PrmEd::SetHeightFac( fac );
00306 }
00307 
00308 /*=====================  Model::GetHeightFac  ======================*/
00309 
00310 double Model::GetHeightFac( void )
00311 {
00312  return( PrmEd::GetHeightFac( ) );
00313 }
00314 

Generated on Mon May 16 23:26:01 2011 for Trab7 by  doxygen 1.4.2-20050421