2 // Copyright (C) 1991 - 2000 by
3 // Matra Datavision SA. All rights reserved.
5 // Copyright (C) 2001 - 2004 by
6 // Open CASCADE SA. All rights reserved.
8 // This file is part of the Open CASCADE Technology software.
10 // This software may be distributed and/or modified under the terms and
11 // conditions of the Open CASCADE Public License as defined by Open CASCADE SA
12 // and appearing in the file LICENSE included in the packaging of this file.
14 // This software is distributed on an "AS IS" basis, without warranty of any
15 // kind, and Open CASCADE SA hereby disclaims all such warranties,
16 // including without limitation, any warranties of merchantability, fitness
17 // for a particular purpose or non-infringement. Please see the License for
18 // the specific terms and conditions governing rights and limitations under the
22 #include <SampleAISDisplayModeJni_SampleAISDisplayModePackage.h>
23 #include <SampleAISDisplayModePackage.hxx>
26 #include <Standard_ErrorHandler.hxx>
27 #include <Standard_Failure.hxx>
28 #include <Standard_SStream.hxx>
30 #include <V3d_Viewer.hxx>
31 #include <Standard_ExtString.hxx>
32 #include <V3d_View.hxx>
33 #include <Standard_Integer.hxx>
34 #include <AIS_InteractiveContext.hxx>
35 #include <TCollection_AsciiString.hxx>
36 #include <AIS_DisplayMode.hxx>
37 #include <Graphic3d_NameOfMaterial.hxx>
38 #include <Quantity_Color.hxx>
39 #include <Standard_Real.hxx>
45 JNIEXPORT jobject JNICALL Java_SampleAISDisplayModeJni_SampleAISDisplayModePackage_CreateViewer (JNIEnv *env, jclass, jstring aName)
49 jcas_Locking alock(env);
52 Standard_ExtString the_aName = jcas_ConvertToExtString(env,aName);
53 Handle(V3d_Viewer)* theret = new Handle(V3d_Viewer);
54 *theret = SampleAISDisplayModePackage::CreateViewer(the_aName);
55 thejret = jcas_CreateObject(env,"CASCADESamplesJni/V3d_Viewer",theret);
58 catch (Standard_Failure) {
60 Err << Standard_Failure::Caught();
62 jcas_ThrowException(env,Err.str().c_str());
71 JNIEXPORT void JNICALL Java_SampleAISDisplayModeJni_SampleAISDisplayModePackage_SetWindow (JNIEnv *env, jclass, jobject aView, jint hiwin, jint lowin)
74 jcas_Locking alock(env);
77 Handle( V3d_View ) the_aView;
78 void* ptr_aView = jcas_GetHandle(env,aView);
80 if ( ptr_aView != NULL ) the_aView = *( ( Handle( V3d_View )* )ptr_aView );
82 SampleAISDisplayModePackage::SetWindow(the_aView,(Standard_Integer) hiwin,(Standard_Integer) lowin);
85 catch (Standard_Failure) {
87 Err << Standard_Failure::Caught();
89 jcas_ThrowException(env,Err.str().c_str());
98 JNIEXPORT void JNICALL Java_SampleAISDisplayModeJni_SampleAISDisplayModePackage_DisplayBox (JNIEnv *env, jclass, jobject aContext, jobject Message)
101 jcas_Locking alock(env);
104 Handle( AIS_InteractiveContext ) the_aContext;
105 void* ptr_aContext = jcas_GetHandle(env,aContext);
107 if ( ptr_aContext != NULL ) the_aContext = *( ( Handle( AIS_InteractiveContext )* )ptr_aContext );
109 TCollection_AsciiString* the_Message = (TCollection_AsciiString*) jcas_GetHandle(env,Message);
110 if ( the_Message == NULL ) {
112 // The following assumes availability of the default constructor (what may not
113 // always be the case). Therefore explicit exception is thrown if the null
114 // object has been passed.
115 // the_Message = new TCollection_AsciiString ();
116 // jcas_SetHandle ( env, Message, the_Message );
117 jcas_ThrowException (env, "NULL object has been passed while expecting an object manipulated by value");
120 SampleAISDisplayModePackage::DisplayBox(the_aContext,*the_Message);
123 catch (Standard_Failure) {
124 Standard_SStream Err;
125 Err << Standard_Failure::Caught();
127 jcas_ThrowException(env,Err.str().c_str());
136 JNIEXPORT void JNICALL Java_SampleAISDisplayModeJni_SampleAISDisplayModePackage_DisplaySphere (JNIEnv *env, jclass, jobject aContext, jobject Message)
139 jcas_Locking alock(env);
142 Handle( AIS_InteractiveContext ) the_aContext;
143 void* ptr_aContext = jcas_GetHandle(env,aContext);
145 if ( ptr_aContext != NULL ) the_aContext = *( ( Handle( AIS_InteractiveContext )* )ptr_aContext );
147 TCollection_AsciiString* the_Message = (TCollection_AsciiString*) jcas_GetHandle(env,Message);
148 if ( the_Message == NULL ) {
150 // The following assumes availability of the default constructor (what may not
151 // always be the case). Therefore explicit exception is thrown if the null
152 // object has been passed.
153 // the_Message = new TCollection_AsciiString ();
154 // jcas_SetHandle ( env, Message, the_Message );
155 jcas_ThrowException (env, "NULL object has been passed while expecting an object manipulated by value");
158 SampleAISDisplayModePackage::DisplaySphere(the_aContext,*the_Message);
161 catch (Standard_Failure) {
162 Standard_SStream Err;
163 Err << Standard_Failure::Caught();
165 jcas_ThrowException(env,Err.str().c_str());
174 JNIEXPORT void JNICALL Java_SampleAISDisplayModeJni_SampleAISDisplayModePackage_DisplayCylinder (JNIEnv *env, jclass, jobject aContext, jobject Message)
177 jcas_Locking alock(env);
180 Handle( AIS_InteractiveContext ) the_aContext;
181 void* ptr_aContext = jcas_GetHandle(env,aContext);
183 if ( ptr_aContext != NULL ) the_aContext = *( ( Handle( AIS_InteractiveContext )* )ptr_aContext );
185 TCollection_AsciiString* the_Message = (TCollection_AsciiString*) jcas_GetHandle(env,Message);
186 if ( the_Message == NULL ) {
188 // The following assumes availability of the default constructor (what may not
189 // always be the case). Therefore explicit exception is thrown if the null
190 // object has been passed.
191 // the_Message = new TCollection_AsciiString ();
192 // jcas_SetHandle ( env, Message, the_Message );
193 jcas_ThrowException (env, "NULL object has been passed while expecting an object manipulated by value");
196 SampleAISDisplayModePackage::DisplayCylinder(the_aContext,*the_Message);
199 catch (Standard_Failure) {
200 Standard_SStream Err;
201 Err << Standard_Failure::Caught();
203 jcas_ThrowException(env,Err.str().c_str());
212 JNIEXPORT void JNICALL Java_SampleAISDisplayModeJni_SampleAISDisplayModePackage_EraseAll (JNIEnv *env, jclass, jobject aContext, jobject Message)
215 jcas_Locking alock(env);
218 Handle( AIS_InteractiveContext ) the_aContext;
219 void* ptr_aContext = jcas_GetHandle(env,aContext);
221 if ( ptr_aContext != NULL ) the_aContext = *( ( Handle( AIS_InteractiveContext )* )ptr_aContext );
223 TCollection_AsciiString* the_Message = (TCollection_AsciiString*) jcas_GetHandle(env,Message);
224 if ( the_Message == NULL ) {
226 // The following assumes availability of the default constructor (what may not
227 // always be the case). Therefore explicit exception is thrown if the null
228 // object has been passed.
229 // the_Message = new TCollection_AsciiString ();
230 // jcas_SetHandle ( env, Message, the_Message );
231 jcas_ThrowException (env, "NULL object has been passed while expecting an object manipulated by value");
234 SampleAISDisplayModePackage::EraseAll(the_aContext,*the_Message);
237 catch (Standard_Failure) {
238 Standard_SStream Err;
239 Err << Standard_Failure::Caught();
241 jcas_ThrowException(env,Err.str().c_str());
250 JNIEXPORT void JNICALL Java_SampleAISDisplayModeJni_SampleAISDisplayModePackage_InitContext (JNIEnv *env, jclass, jobject aContext)
253 jcas_Locking alock(env);
256 Handle( AIS_InteractiveContext ) the_aContext;
257 void* ptr_aContext = jcas_GetHandle(env,aContext);
259 if ( ptr_aContext != NULL ) the_aContext = *( ( Handle( AIS_InteractiveContext )* )ptr_aContext );
261 SampleAISDisplayModePackage::InitContext(the_aContext);
264 catch (Standard_Failure) {
265 Standard_SStream Err;
266 Err << Standard_Failure::Caught();
268 jcas_ThrowException(env,Err.str().c_str());
277 JNIEXPORT void JNICALL Java_SampleAISDisplayModeJni_SampleAISDisplayModePackage_GetIsosNumber (JNIEnv *env, jclass, jobject aContext, jobject u, jobject v)
280 jcas_Locking alock(env);
283 Handle( AIS_InteractiveContext ) the_aContext;
284 void* ptr_aContext = jcas_GetHandle(env,aContext);
286 if ( ptr_aContext != NULL ) the_aContext = *( ( Handle( AIS_InteractiveContext )* )ptr_aContext );
288 Standard_Integer the_u = jcas_GetInteger(env,u);
289 Standard_Integer the_v = jcas_GetInteger(env,v);
290 SampleAISDisplayModePackage::GetIsosNumber(the_aContext,the_u,the_v);
291 jcas_SetInteger(env,u,the_u);
292 jcas_SetInteger(env,v,the_v);
295 catch (Standard_Failure) {
296 Standard_SStream Err;
297 Err << Standard_Failure::Caught();
299 jcas_ThrowException(env,Err.str().c_str());
308 JNIEXPORT void JNICALL Java_SampleAISDisplayModeJni_SampleAISDisplayModePackage_SetIsosNumber (JNIEnv *env, jclass, jobject aContext, jint u, jint v, jobject Message)
311 jcas_Locking alock(env);
314 Handle( AIS_InteractiveContext ) the_aContext;
315 void* ptr_aContext = jcas_GetHandle(env,aContext);
317 if ( ptr_aContext != NULL ) the_aContext = *( ( Handle( AIS_InteractiveContext )* )ptr_aContext );
319 TCollection_AsciiString* the_Message = (TCollection_AsciiString*) jcas_GetHandle(env,Message);
320 if ( the_Message == NULL ) {
322 // The following assumes availability of the default constructor (what may not
323 // always be the case). Therefore explicit exception is thrown if the null
324 // object has been passed.
325 // the_Message = new TCollection_AsciiString ();
326 // jcas_SetHandle ( env, Message, the_Message );
327 jcas_ThrowException (env, "NULL object has been passed while expecting an object manipulated by value");
330 SampleAISDisplayModePackage::SetIsosNumber(the_aContext,(Standard_Integer) u,(Standard_Integer) v,*the_Message);
333 catch (Standard_Failure) {
334 Standard_SStream Err;
335 Err << Standard_Failure::Caught();
337 jcas_ThrowException(env,Err.str().c_str());
346 JNIEXPORT void JNICALL Java_SampleAISDisplayModeJni_SampleAISDisplayModePackage_SetDisplayMode (JNIEnv *env, jclass, jobject aContext, jshort aMode, jobject Message)
349 jcas_Locking alock(env);
352 Handle( AIS_InteractiveContext ) the_aContext;
353 void* ptr_aContext = jcas_GetHandle(env,aContext);
355 if ( ptr_aContext != NULL ) the_aContext = *( ( Handle( AIS_InteractiveContext )* )ptr_aContext );
357 TCollection_AsciiString* the_Message = (TCollection_AsciiString*) jcas_GetHandle(env,Message);
358 if ( the_Message == NULL ) {
360 // The following assumes availability of the default constructor (what may not
361 // always be the case). Therefore explicit exception is thrown if the null
362 // object has been passed.
363 // the_Message = new TCollection_AsciiString ();
364 // jcas_SetHandle ( env, Message, the_Message );
365 jcas_ThrowException (env, "NULL object has been passed while expecting an object manipulated by value");
368 SampleAISDisplayModePackage::SetDisplayMode(the_aContext,(AIS_DisplayMode) aMode,*the_Message);
371 catch (Standard_Failure) {
372 Standard_SStream Err;
373 Err << Standard_Failure::Caught();
375 jcas_ThrowException(env,Err.str().c_str());
384 JNIEXPORT void JNICALL Java_SampleAISDisplayModeJni_SampleAISDisplayModePackage_SetObjectDisplayMode (JNIEnv *env, jclass, jobject aContext, jshort aMode, jobject Message)
387 jcas_Locking alock(env);
390 Handle( AIS_InteractiveContext ) the_aContext;
391 void* ptr_aContext = jcas_GetHandle(env,aContext);
393 if ( ptr_aContext != NULL ) the_aContext = *( ( Handle( AIS_InteractiveContext )* )ptr_aContext );
395 TCollection_AsciiString* the_Message = (TCollection_AsciiString*) jcas_GetHandle(env,Message);
396 if ( the_Message == NULL ) {
398 // The following assumes availability of the default constructor (what may not
399 // always be the case). Therefore explicit exception is thrown if the null
400 // object has been passed.
401 // the_Message = new TCollection_AsciiString ();
402 // jcas_SetHandle ( env, Message, the_Message );
403 jcas_ThrowException (env, "NULL object has been passed while expecting an object manipulated by value");
406 SampleAISDisplayModePackage::SetObjectDisplayMode(the_aContext,(AIS_DisplayMode) aMode,*the_Message);
409 catch (Standard_Failure) {
410 Standard_SStream Err;
411 Err << Standard_Failure::Caught();
413 jcas_ThrowException(env,Err.str().c_str());
422 JNIEXPORT void JNICALL Java_SampleAISDisplayModeJni_SampleAISDisplayModePackage_SetObjectMaterial (JNIEnv *env, jclass, jobject aContext, jshort aName, jobject Message)
425 jcas_Locking alock(env);
428 Handle( AIS_InteractiveContext ) the_aContext;
429 void* ptr_aContext = jcas_GetHandle(env,aContext);
431 if ( ptr_aContext != NULL ) the_aContext = *( ( Handle( AIS_InteractiveContext )* )ptr_aContext );
433 TCollection_AsciiString* the_Message = (TCollection_AsciiString*) jcas_GetHandle(env,Message);
434 if ( the_Message == NULL ) {
436 // The following assumes availability of the default constructor (what may not
437 // always be the case). Therefore explicit exception is thrown if the null
438 // object has been passed.
439 // the_Message = new TCollection_AsciiString ();
440 // jcas_SetHandle ( env, Message, the_Message );
441 jcas_ThrowException (env, "NULL object has been passed while expecting an object manipulated by value");
444 SampleAISDisplayModePackage::SetObjectMaterial(the_aContext,(Graphic3d_NameOfMaterial) aName,*the_Message);
447 catch (Standard_Failure) {
448 Standard_SStream Err;
449 Err << Standard_Failure::Caught();
451 jcas_ThrowException(env,Err.str().c_str());
460 JNIEXPORT jobject JNICALL Java_SampleAISDisplayModeJni_SampleAISDisplayModePackage_GetObjectColor (JNIEnv *env, jclass, jobject aContext)
464 jcas_Locking alock(env);
467 Handle( AIS_InteractiveContext ) the_aContext;
468 void* ptr_aContext = jcas_GetHandle(env,aContext);
470 if ( ptr_aContext != NULL ) the_aContext = *( ( Handle( AIS_InteractiveContext )* )ptr_aContext );
472 Quantity_Color* theret = new Quantity_Color(SampleAISDisplayModePackage::GetObjectColor(the_aContext));
473 thejret = jcas_CreateObject(env,"CASCADESamplesJni/Quantity_Color",theret);
476 catch (Standard_Failure) {
477 Standard_SStream Err;
478 Err << Standard_Failure::Caught();
480 jcas_ThrowException(env,Err.str().c_str());
489 JNIEXPORT void JNICALL Java_SampleAISDisplayModeJni_SampleAISDisplayModePackage_SetObjectColor (JNIEnv *env, jclass, jobject aContext, jobject aColor, jobject Message)
492 jcas_Locking alock(env);
495 Handle( AIS_InteractiveContext ) the_aContext;
496 void* ptr_aContext = jcas_GetHandle(env,aContext);
498 if ( ptr_aContext != NULL ) the_aContext = *( ( Handle( AIS_InteractiveContext )* )ptr_aContext );
500 Quantity_Color* the_aColor = (Quantity_Color*) jcas_GetHandle(env,aColor);
501 if ( the_aColor == NULL ) {
503 // The following assumes availability of the default constructor (what may not
504 // always be the case). Therefore explicit exception is thrown if the null
505 // object has been passed.
506 // the_aColor = new Quantity_Color ();
507 // jcas_SetHandle ( env, aColor, the_aColor );
508 jcas_ThrowException (env, "NULL object has been passed while expecting an object manipulated by value");
511 TCollection_AsciiString* the_Message = (TCollection_AsciiString*) jcas_GetHandle(env,Message);
512 if ( the_Message == NULL ) {
514 // The following assumes availability of the default constructor (what may not
515 // always be the case). Therefore explicit exception is thrown if the null
516 // object has been passed.
517 // the_Message = new TCollection_AsciiString ();
518 // jcas_SetHandle ( env, Message, the_Message );
519 jcas_ThrowException (env, "NULL object has been passed while expecting an object manipulated by value");
522 SampleAISDisplayModePackage::SetObjectColor(the_aContext,*the_aColor,*the_Message);
525 catch (Standard_Failure) {
526 Standard_SStream Err;
527 Err << Standard_Failure::Caught();
529 jcas_ThrowException(env,Err.str().c_str());
538 JNIEXPORT jdouble JNICALL Java_SampleAISDisplayModeJni_SampleAISDisplayModePackage_GetObjectTransparency (JNIEnv *env, jclass, jobject aContext)
542 jcas_Locking alock(env);
545 Handle( AIS_InteractiveContext ) the_aContext;
546 void* ptr_aContext = jcas_GetHandle(env,aContext);
548 if ( ptr_aContext != NULL ) the_aContext = *( ( Handle( AIS_InteractiveContext )* )ptr_aContext );
550 thejret = SampleAISDisplayModePackage::GetObjectTransparency(the_aContext);
553 catch (Standard_Failure) {
554 Standard_SStream Err;
555 Err << Standard_Failure::Caught();
557 jcas_ThrowException(env,Err.str().c_str());
566 JNIEXPORT void JNICALL Java_SampleAISDisplayModeJni_SampleAISDisplayModePackage_SetObjectTransparency (JNIEnv *env, jclass, jobject aContext, jdouble aValue, jobject Message)
569 jcas_Locking alock(env);
572 Handle( AIS_InteractiveContext ) the_aContext;
573 void* ptr_aContext = jcas_GetHandle(env,aContext);
575 if ( ptr_aContext != NULL ) the_aContext = *( ( Handle( AIS_InteractiveContext )* )ptr_aContext );
577 TCollection_AsciiString* the_Message = (TCollection_AsciiString*) jcas_GetHandle(env,Message);
578 if ( the_Message == NULL ) {
580 // The following assumes availability of the default constructor (what may not
581 // always be the case). Therefore explicit exception is thrown if the null
582 // object has been passed.
583 // the_Message = new TCollection_AsciiString ();
584 // jcas_SetHandle ( env, Message, the_Message );
585 jcas_ThrowException (env, "NULL object has been passed while expecting an object manipulated by value");
588 SampleAISDisplayModePackage::SetObjectTransparency(the_aContext,(Standard_Real) aValue,*the_Message);
591 catch (Standard_Failure) {
592 Standard_SStream Err;
593 Err << Standard_Failure::Caught();
595 jcas_ThrowException(env,Err.str().c_str());
604 JNIEXPORT void JNICALL Java_SampleAISDisplayModeJni_SampleAISDisplayModePackage_CreateLight (JNIEnv *env, jclass, jobject aContext)
607 jcas_Locking alock(env);
610 Handle( AIS_InteractiveContext ) the_aContext;
611 void* ptr_aContext = jcas_GetHandle(env,aContext);
613 if ( ptr_aContext != NULL ) the_aContext = *( ( Handle( AIS_InteractiveContext )* )ptr_aContext );
615 SampleAISDisplayModePackage::CreateLight(the_aContext);
618 catch (Standard_Failure) {
619 Standard_SStream Err;
620 Err << Standard_Failure::Caught();
622 jcas_ThrowException(env,Err.str().c_str());
631 JNIEXPORT void JNICALL Java_SampleAISDisplayModeJni_SampleAISDisplayModePackage_SetFirstPointOfLight (JNIEnv *env, jclass, jobject aContext, jobject aView, jint X, jint Y)
634 jcas_Locking alock(env);
637 Handle( AIS_InteractiveContext ) the_aContext;
638 void* ptr_aContext = jcas_GetHandle(env,aContext);
640 if ( ptr_aContext != NULL ) the_aContext = *( ( Handle( AIS_InteractiveContext )* )ptr_aContext );
642 Handle( V3d_View ) the_aView;
643 void* ptr_aView = jcas_GetHandle(env,aView);
645 if ( ptr_aView != NULL ) the_aView = *( ( Handle( V3d_View )* )ptr_aView );
647 SampleAISDisplayModePackage::SetFirstPointOfLight(the_aContext,the_aView,(Standard_Integer) X,(Standard_Integer) Y);
650 catch (Standard_Failure) {
651 Standard_SStream Err;
652 Err << Standard_Failure::Caught();
654 jcas_ThrowException(env,Err.str().c_str());
663 JNIEXPORT void JNICALL Java_SampleAISDisplayModeJni_SampleAISDisplayModePackage_MoveSecondPointOfLight (JNIEnv *env, jclass, jobject aContext, jobject aView, jint X, jint Y)
666 jcas_Locking alock(env);
669 Handle( AIS_InteractiveContext ) the_aContext;
670 void* ptr_aContext = jcas_GetHandle(env,aContext);
672 if ( ptr_aContext != NULL ) the_aContext = *( ( Handle( AIS_InteractiveContext )* )ptr_aContext );
674 Handle( V3d_View ) the_aView;
675 void* ptr_aView = jcas_GetHandle(env,aView);
677 if ( ptr_aView != NULL ) the_aView = *( ( Handle( V3d_View )* )ptr_aView );
679 SampleAISDisplayModePackage::MoveSecondPointOfLight(the_aContext,the_aView,(Standard_Integer) X,(Standard_Integer) Y);
682 catch (Standard_Failure) {
683 Standard_SStream Err;
684 Err << Standard_Failure::Caught();
686 jcas_ThrowException(env,Err.str().c_str());
695 JNIEXPORT void JNICALL Java_SampleAISDisplayModeJni_SampleAISDisplayModePackage_SetSecondPointOfLight (JNIEnv *env, jclass, jobject aContext)
698 jcas_Locking alock(env);
701 Handle( AIS_InteractiveContext ) the_aContext;
702 void* ptr_aContext = jcas_GetHandle(env,aContext);
704 if ( ptr_aContext != NULL ) the_aContext = *( ( Handle( AIS_InteractiveContext )* )ptr_aContext );
706 SampleAISDisplayModePackage::SetSecondPointOfLight(the_aContext);
709 catch (Standard_Failure) {
710 Standard_SStream Err;
711 Err << Standard_Failure::Caught();
713 jcas_ThrowException(env,Err.str().c_str());