00001 #include "BackTrihedronDrawerGL.hxx"
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 namespace org_scilab_modules_renderer_subwinDrawing {
00040
00041
00042
00043 JNIEnv * BackTrihedronDrawerGL::getCurrentEnv() {
00044 JNIEnv * curEnv = NULL;
00045 this->jvm->AttachCurrentThread((void **) &curEnv, NULL);
00046 return curEnv;
00047 }
00048
00049
00050 BackTrihedronDrawerGL::~BackTrihedronDrawerGL() {
00051 JNIEnv * curEnv = NULL;
00052 this->jvm->AttachCurrentThread((void **) &curEnv, NULL);
00053
00054 curEnv->DeleteGlobalRef(this->instance);
00055 curEnv->DeleteGlobalRef(this->instanceClass);
00056 }
00057
00058
00059 BackTrihedronDrawerGL::BackTrihedronDrawerGL(JavaVM * jvm_) {
00060 jmethodID constructObject = NULL ;
00061 jobject localInstance ;
00062 jclass localClass ;
00063 const std::string construct="<init>";
00064 const std::string param="()V";
00065 jvm=jvm_;
00066
00067 JNIEnv * curEnv = getCurrentEnv();
00068
00069 localClass = curEnv->FindClass( this->className().c_str() ) ;
00070 if (localClass == NULL) {
00071 throw GiwsException::JniClassNotFoundException(curEnv, this->className());
00072 }
00073
00074 this->instanceClass = (jclass) curEnv->NewGlobalRef(localClass) ;
00075
00076
00077 curEnv->DeleteLocalRef(localClass);
00078
00079 if (this->instanceClass == NULL) {
00080 throw GiwsException::JniObjectCreationException(curEnv, this->className());
00081 }
00082
00083
00084 constructObject = curEnv->GetMethodID( this->instanceClass, construct.c_str() , param.c_str() ) ;
00085 if(constructObject == NULL){
00086 throw GiwsException::JniObjectCreationException(curEnv, this->className());
00087 }
00088
00089 localInstance = curEnv->NewObject( this->instanceClass, constructObject ) ;
00090 if(localInstance == NULL){
00091 throw GiwsException::JniObjectCreationException(curEnv, this->className());
00092 }
00093
00094 this->instance = curEnv->NewGlobalRef(localInstance) ;
00095 if(this->instance == NULL){
00096 throw GiwsException::JniObjectCreationException(curEnv, this->className());
00097 }
00098
00099 curEnv->DeleteLocalRef(localInstance);
00100
00101
00102 voiddisplayID=NULL;
00103 voidinitializeDrawingjintID=NULL;
00104 voidendDrawingID=NULL;
00105 voidshowjintID=NULL;
00106 voiddestroyjintID=NULL;
00107 voidsetFigureIndexjintID=NULL;
00108 voidsetBoxParametersjintjfloatID=NULL;
00109 voiddrawBoxjdoublejdoublejdoublejdoublejdoublejdoublejintID=NULL;
00110
00111
00112 }
00113
00114 BackTrihedronDrawerGL::BackTrihedronDrawerGL(JavaVM * jvm_, jobject JObj) {
00115 jvm=jvm_;
00116
00117 JNIEnv * curEnv = getCurrentEnv();
00118
00119 jclass localClass = curEnv->GetObjectClass(JObj);
00120 this->instanceClass = (jclass) curEnv->NewGlobalRef(localClass);
00121 curEnv->DeleteLocalRef(localClass);
00122
00123 if (this->instanceClass == NULL) {
00124 throw GiwsException::JniObjectCreationException(curEnv, this->className());
00125 }
00126
00127 this->instance = curEnv->NewGlobalRef(JObj) ;
00128 if(this->instance == NULL){
00129 throw GiwsException::JniObjectCreationException(curEnv, this->className());
00130 }
00131
00132 voiddisplayID=NULL;
00133 voidinitializeDrawingjintID=NULL;
00134 voidendDrawingID=NULL;
00135 voidshowjintID=NULL;
00136 voiddestroyjintID=NULL;
00137 voidsetFigureIndexjintID=NULL;
00138 voidsetBoxParametersjintjfloatID=NULL;
00139 voiddrawBoxjdoublejdoublejdoublejdoublejdoublejdoublejintID=NULL;
00140
00141
00142 }
00143
00144
00145
00146
00147 void BackTrihedronDrawerGL::synchronize() {
00148 if (getCurrentEnv()->MonitorEnter(instance) != JNI_OK) {
00149 std::cerr << "Fail to enter monitor." << std::endl;
00150 exit(EXIT_FAILURE);
00151 }
00152 }
00153
00154
00155 void BackTrihedronDrawerGL::endSynchronize() {
00156 if ( getCurrentEnv()->MonitorExit(instance) != JNI_OK) {
00157 std::cerr << "Fail to exit monitor." << std::endl;
00158 exit(EXIT_FAILURE);
00159 }
00160 }
00161
00162
00163
00164 void BackTrihedronDrawerGL::display (){
00165
00166 JNIEnv * curEnv = getCurrentEnv();
00167
00168 if (voiddisplayID==NULL) { voiddisplayID = curEnv->GetMethodID(this->instanceClass, "display", "()V" ) ;
00169 if (voiddisplayID == NULL) {
00170 throw GiwsException::JniMethodNotFoundException(curEnv, "display");
00171 }
00172 }
00173 curEnv->CallVoidMethod( this->instance, voiddisplayID );
00174 if (curEnv->ExceptionCheck()) {
00175 throw GiwsException::JniCallMethodException(curEnv);
00176 }
00177 }
00178
00179 void BackTrihedronDrawerGL::initializeDrawing (int figureIndex){
00180
00181 JNIEnv * curEnv = getCurrentEnv();
00182
00183 if (voidinitializeDrawingjintID==NULL) { voidinitializeDrawingjintID = curEnv->GetMethodID(this->instanceClass, "initializeDrawing", "(I)V" ) ;
00184 if (voidinitializeDrawingjintID == NULL) {
00185 throw GiwsException::JniMethodNotFoundException(curEnv, "initializeDrawing");
00186 }
00187 }
00188 curEnv->CallVoidMethod( this->instance, voidinitializeDrawingjintID ,figureIndex);
00189 if (curEnv->ExceptionCheck()) {
00190 throw GiwsException::JniCallMethodException(curEnv);
00191 }
00192 }
00193
00194 void BackTrihedronDrawerGL::endDrawing (){
00195
00196 JNIEnv * curEnv = getCurrentEnv();
00197
00198 if (voidendDrawingID==NULL) { voidendDrawingID = curEnv->GetMethodID(this->instanceClass, "endDrawing", "()V" ) ;
00199 if (voidendDrawingID == NULL) {
00200 throw GiwsException::JniMethodNotFoundException(curEnv, "endDrawing");
00201 }
00202 }
00203 curEnv->CallVoidMethod( this->instance, voidendDrawingID );
00204 if (curEnv->ExceptionCheck()) {
00205 throw GiwsException::JniCallMethodException(curEnv);
00206 }
00207 }
00208
00209 void BackTrihedronDrawerGL::show (int figureIndex){
00210
00211 JNIEnv * curEnv = getCurrentEnv();
00212
00213 if (voidshowjintID==NULL) { voidshowjintID = curEnv->GetMethodID(this->instanceClass, "show", "(I)V" ) ;
00214 if (voidshowjintID == NULL) {
00215 throw GiwsException::JniMethodNotFoundException(curEnv, "show");
00216 }
00217 }
00218 curEnv->CallVoidMethod( this->instance, voidshowjintID ,figureIndex);
00219 if (curEnv->ExceptionCheck()) {
00220 throw GiwsException::JniCallMethodException(curEnv);
00221 }
00222 }
00223
00224 void BackTrihedronDrawerGL::destroy (int figureIndex){
00225
00226 JNIEnv * curEnv = getCurrentEnv();
00227
00228 if (voiddestroyjintID==NULL) { voiddestroyjintID = curEnv->GetMethodID(this->instanceClass, "destroy", "(I)V" ) ;
00229 if (voiddestroyjintID == NULL) {
00230 throw GiwsException::JniMethodNotFoundException(curEnv, "destroy");
00231 }
00232 }
00233 curEnv->CallVoidMethod( this->instance, voiddestroyjintID ,figureIndex);
00234 if (curEnv->ExceptionCheck()) {
00235 throw GiwsException::JniCallMethodException(curEnv);
00236 }
00237 }
00238
00239 void BackTrihedronDrawerGL::setFigureIndex (int figureIndex){
00240
00241 JNIEnv * curEnv = getCurrentEnv();
00242
00243 if (voidsetFigureIndexjintID==NULL) { voidsetFigureIndexjintID = curEnv->GetMethodID(this->instanceClass, "setFigureIndex", "(I)V" ) ;
00244 if (voidsetFigureIndexjintID == NULL) {
00245 throw GiwsException::JniMethodNotFoundException(curEnv, "setFigureIndex");
00246 }
00247 }
00248 curEnv->CallVoidMethod( this->instance, voidsetFigureIndexjintID ,figureIndex);
00249 if (curEnv->ExceptionCheck()) {
00250 throw GiwsException::JniCallMethodException(curEnv);
00251 }
00252 }
00253
00254 void BackTrihedronDrawerGL::setBoxParameters (int hiddenAxisColor, float thickness){
00255
00256 JNIEnv * curEnv = getCurrentEnv();
00257
00258 if (voidsetBoxParametersjintjfloatID==NULL) { voidsetBoxParametersjintjfloatID = curEnv->GetMethodID(this->instanceClass, "setBoxParameters", "(IF)V" ) ;
00259 if (voidsetBoxParametersjintjfloatID == NULL) {
00260 throw GiwsException::JniMethodNotFoundException(curEnv, "setBoxParameters");
00261 }
00262 }
00263 curEnv->CallVoidMethod( this->instance, voidsetBoxParametersjintjfloatID ,hiddenAxisColor, thickness);
00264 if (curEnv->ExceptionCheck()) {
00265 throw GiwsException::JniCallMethodException(curEnv);
00266 }
00267 }
00268
00269 void BackTrihedronDrawerGL::drawBox (double xMin, double xMax, double yMin, double yMax, double zMin, double zMax, int concealedCornerIndex){
00270
00271 JNIEnv * curEnv = getCurrentEnv();
00272
00273 if (voiddrawBoxjdoublejdoublejdoublejdoublejdoublejdoublejintID==NULL) { voiddrawBoxjdoublejdoublejdoublejdoublejdoublejdoublejintID = curEnv->GetMethodID(this->instanceClass, "drawBox", "(DDDDDDI)V" ) ;
00274 if (voiddrawBoxjdoublejdoublejdoublejdoublejdoublejdoublejintID == NULL) {
00275 throw GiwsException::JniMethodNotFoundException(curEnv, "drawBox");
00276 }
00277 }
00278 curEnv->CallVoidMethod( this->instance, voiddrawBoxjdoublejdoublejdoublejdoublejdoublejdoublejintID ,xMin, xMax, yMin, yMax, zMin, zMax, concealedCornerIndex);
00279 if (curEnv->ExceptionCheck()) {
00280 throw GiwsException::JniCallMethodException(curEnv);
00281 }
00282 }
00283
00284 }