00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "view.hh"
00026 #include "precompile.hh"
00027 #include <cassert>
00028 #include <iostream>
00029
00030 CPrecompile::CPrecompile(unsigned int ANb) :
00031 FToUpdate (true),
00032 FEnable (true),
00033 FNbView (ANb),
00034 FNbEnabledView(0)
00035 {
00036 #ifndef NO_LIST_OPENGL
00037 FCompiledList = -1;
00038 #endif // NO_LIST_OPENGL
00039 }
00040
00041 CPrecompile::CPrecompile(const CPrecompile & APrecompile) :
00042 FToUpdate (APrecompile.FToUpdate),
00043 FEnable (APrecompile.FEnable),
00044 FNbView (0),
00045 FNbEnabledView(0)
00046 {
00047 #ifndef NO_LIST_OPENGL
00048 FCompiledList = -1;
00049 #endif // NO_LIST_OPENGL
00050 }
00051
00052 CPrecompile::~CPrecompile()
00053 {
00054 #ifndef NO_LIST_OPENGL
00055 glDeleteLists(FCompiledList, 1);
00056 #endif // NO_LIST_OPENGL
00057 }
00058
00059 void CPrecompile::draw()
00060 {
00061 if (isEnabled())
00062 {
00063 #ifndef NO_LIST_OPENGL
00064 glCallList(FCompiledList);
00065 #else
00066 drawModel();
00067 #endif // NO_LIST_OPENGL
00068 }
00069 }
00070
00071 void CPrecompile::update()
00072 {
00073 #ifndef NO_LIST_OPENGL
00074 if (needToUpdate())
00075 {
00076 compileModel ();
00077 unsetToUpdate();
00078 }
00079 #endif // NO_LIST_OPENGL
00080 }
00081
00082 void CPrecompile::pick(int , int , CView* )
00083 {}
00084
00085 bool CPrecompile::needToUpdate()
00086 { return FToUpdate; }
00087
00088 void CPrecompile::setToUpdate()
00089 { if (isEnabled()) FToUpdate = true; }
00090
00091 void CPrecompile::unsetToUpdate()
00092 { FToUpdate = false; }
00093
00094 unsigned int CPrecompile::getNbView()
00095 { return FNbView; }
00096
00097 void CPrecompile::incNbView(unsigned int ADec)
00098 { FNbView+=ADec; }
00099
00100 void CPrecompile::decNbView(unsigned int ADec)
00101 {
00102 assert( ADec<=FNbView );
00103
00104 FNbView-=ADec;
00105 if ( FNbView==0 ) delete this;
00106 }
00107
00108 unsigned int CPrecompile::getNbEnabledView()
00109 { return FNbEnabledView; }
00110
00111 void CPrecompile::incNbEnabledView(unsigned int ADec)
00112 {
00113 if ( FNbEnabledView==0 && FEnable==true ) FToUpdate=true;
00114 FNbEnabledView+=ADec;
00115 }
00116
00117 void CPrecompile::decNbEnabledView(unsigned int ADec)
00118 {
00119 assert( ADec<=FNbEnabledView );
00120
00121 FNbEnabledView-=ADec;
00122 if ( FNbEnabledView==0 && FEnable==true ) FToUpdate=true;
00123 }
00124
00125 bool CPrecompile::isEnabled()
00126 { return ( FEnable && FNbEnabledView>0 ); }
00127
00128 void CPrecompile::enable()
00129 {
00130 if (!FEnable)
00131 {
00132 if (FNbEnabledView>0) FToUpdate=true;
00133 FEnable=true;
00134 }
00135 }
00136
00137 void CPrecompile::disable()
00138 {
00139 if (FEnable)
00140 {
00141 if (FNbEnabledView>0) FToUpdate=true;
00142 FEnable= false;
00143 }
00144 }
00145
00146 void CPrecompile::compileModel()
00147 {
00148 #ifndef NO_LIST_OPENGL
00149 if (FCompiledList == -1)
00150
00151 FCompiledList = glGenLists(1);
00152
00153 glNewList(FCompiledList, GL_COMPILE);
00154
00155 if (isEnabled())
00156 drawModel();
00157
00158 glEndList();
00159 #endif // NO_LIST_OPENGL
00160 }
00161