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 <SampleAISSelectJni_SampleAISSelectPackage.h>
23 #include <SampleAISSelectPackage.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 <Standard_Real.hxx>
37 #include <Standard_Boolean.hxx>
38 #include <Quantity_Color.hxx>
44 JNIEXPORT jobject JNICALL Java_SampleAISSelectJni_SampleAISSelectPackage_CreateViewer (JNIEnv *env, jclass, jstring aName)
48 jcas_Locking alock(env);
51 Standard_ExtString the_aName = jcas_ConvertToExtString(env,aName);
52 Handle(V3d_Viewer)* theret = new Handle(V3d_Viewer);
53 *theret = SampleAISSelectPackage::CreateViewer(the_aName);
54 thejret = jcas_CreateObject(env,"CASCADESamplesJni/V3d_Viewer",theret);
57 catch (Standard_Failure) {
59 Err << Standard_Failure::Caught();
61 jcas_ThrowException(env,Err.str().c_str());
70 JNIEXPORT void JNICALL Java_SampleAISSelectJni_SampleAISSelectPackage_SetWindow (JNIEnv *env, jclass, jobject aView, jint hiwin, jint lowin)
73 jcas_Locking alock(env);
76 Handle( V3d_View ) the_aView;
77 void* ptr_aView = jcas_GetHandle(env,aView);
79 if ( ptr_aView != NULL ) the_aView = *( ( Handle( V3d_View )* )ptr_aView );
81 SampleAISSelectPackage::SetWindow(the_aView,(Standard_Integer) hiwin,(Standard_Integer) lowin);
84 catch (Standard_Failure) {
86 Err << Standard_Failure::Caught();
88 jcas_ThrowException(env,Err.str().c_str());
97 JNIEXPORT void JNICALL Java_SampleAISSelectJni_SampleAISSelectPackage_DisplayBox (JNIEnv *env, jclass, jobject aContext, jobject Message)
100 jcas_Locking alock(env);
103 Handle( AIS_InteractiveContext ) the_aContext;
104 void* ptr_aContext = jcas_GetHandle(env,aContext);
106 if ( ptr_aContext != NULL ) the_aContext = *( ( Handle( AIS_InteractiveContext )* )ptr_aContext );
108 TCollection_AsciiString* the_Message = (TCollection_AsciiString*) jcas_GetHandle(env,Message);
109 if ( the_Message == NULL ) {
111 // The following assumes availability of the default constructor (what may not
112 // always be the case). Therefore explicit exception is thrown if the null
113 // object has been passed.
114 // the_Message = new TCollection_AsciiString ();
115 // jcas_SetHandle ( env, Message, the_Message );
116 jcas_ThrowException (env, "NULL object has been passed while expecting an object manipulated by value");
119 SampleAISSelectPackage::DisplayBox(the_aContext,*the_Message);
122 catch (Standard_Failure) {
123 Standard_SStream Err;
124 Err << Standard_Failure::Caught();
126 jcas_ThrowException(env,Err.str().c_str());
135 JNIEXPORT void JNICALL Java_SampleAISSelectJni_SampleAISSelectPackage_DisplayCylinder (JNIEnv *env, jclass, jobject aContext, jobject Message)
138 jcas_Locking alock(env);
141 Handle( AIS_InteractiveContext ) the_aContext;
142 void* ptr_aContext = jcas_GetHandle(env,aContext);
144 if ( ptr_aContext != NULL ) the_aContext = *( ( Handle( AIS_InteractiveContext )* )ptr_aContext );
146 TCollection_AsciiString* the_Message = (TCollection_AsciiString*) jcas_GetHandle(env,Message);
147 if ( the_Message == NULL ) {
149 // The following assumes availability of the default constructor (what may not
150 // always be the case). Therefore explicit exception is thrown if the null
151 // object has been passed.
152 // the_Message = new TCollection_AsciiString ();
153 // jcas_SetHandle ( env, Message, the_Message );
154 jcas_ThrowException (env, "NULL object has been passed while expecting an object manipulated by value");
157 SampleAISSelectPackage::DisplayCylinder(the_aContext,*the_Message);
160 catch (Standard_Failure) {
161 Standard_SStream Err;
162 Err << Standard_Failure::Caught();
164 jcas_ThrowException(env,Err.str().c_str());
173 JNIEXPORT void JNICALL Java_SampleAISSelectJni_SampleAISSelectPackage_SelectVertices (JNIEnv *env, jclass, jobject aContext, jobject Message)
176 jcas_Locking alock(env);
179 Handle( AIS_InteractiveContext ) the_aContext;
180 void* ptr_aContext = jcas_GetHandle(env,aContext);
182 if ( ptr_aContext != NULL ) the_aContext = *( ( Handle( AIS_InteractiveContext )* )ptr_aContext );
184 TCollection_AsciiString* the_Message = (TCollection_AsciiString*) jcas_GetHandle(env,Message);
185 if ( the_Message == NULL ) {
187 // The following assumes availability of the default constructor (what may not
188 // always be the case). Therefore explicit exception is thrown if the null
189 // object has been passed.
190 // the_Message = new TCollection_AsciiString ();
191 // jcas_SetHandle ( env, Message, the_Message );
192 jcas_ThrowException (env, "NULL object has been passed while expecting an object manipulated by value");
195 SampleAISSelectPackage::SelectVertices(the_aContext,*the_Message);
198 catch (Standard_Failure) {
199 Standard_SStream Err;
200 Err << Standard_Failure::Caught();
202 jcas_ThrowException(env,Err.str().c_str());
211 JNIEXPORT void JNICALL Java_SampleAISSelectJni_SampleAISSelectPackage_SelectEdges (JNIEnv *env, jclass, jobject aContext, jobject Message)
214 jcas_Locking alock(env);
217 Handle( AIS_InteractiveContext ) the_aContext;
218 void* ptr_aContext = jcas_GetHandle(env,aContext);
220 if ( ptr_aContext != NULL ) the_aContext = *( ( Handle( AIS_InteractiveContext )* )ptr_aContext );
222 TCollection_AsciiString* the_Message = (TCollection_AsciiString*) jcas_GetHandle(env,Message);
223 if ( the_Message == NULL ) {
225 // The following assumes availability of the default constructor (what may not
226 // always be the case). Therefore explicit exception is thrown if the null
227 // object has been passed.
228 // the_Message = new TCollection_AsciiString ();
229 // jcas_SetHandle ( env, Message, the_Message );
230 jcas_ThrowException (env, "NULL object has been passed while expecting an object manipulated by value");
233 SampleAISSelectPackage::SelectEdges(the_aContext,*the_Message);
236 catch (Standard_Failure) {
237 Standard_SStream Err;
238 Err << Standard_Failure::Caught();
240 jcas_ThrowException(env,Err.str().c_str());
249 JNIEXPORT void JNICALL Java_SampleAISSelectJni_SampleAISSelectPackage_SelectFaces (JNIEnv *env, jclass, jobject aContext, jobject Message)
252 jcas_Locking alock(env);
255 Handle( AIS_InteractiveContext ) the_aContext;
256 void* ptr_aContext = jcas_GetHandle(env,aContext);
258 if ( ptr_aContext != NULL ) the_aContext = *( ( Handle( AIS_InteractiveContext )* )ptr_aContext );
260 TCollection_AsciiString* the_Message = (TCollection_AsciiString*) jcas_GetHandle(env,Message);
261 if ( the_Message == NULL ) {
263 // The following assumes availability of the default constructor (what may not
264 // always be the case). Therefore explicit exception is thrown if the null
265 // object has been passed.
266 // the_Message = new TCollection_AsciiString ();
267 // jcas_SetHandle ( env, Message, the_Message );
268 jcas_ThrowException (env, "NULL object has been passed while expecting an object manipulated by value");
271 SampleAISSelectPackage::SelectFaces(the_aContext,*the_Message);
274 catch (Standard_Failure) {
275 Standard_SStream Err;
276 Err << Standard_Failure::Caught();
278 jcas_ThrowException(env,Err.str().c_str());
287 JNIEXPORT void JNICALL Java_SampleAISSelectJni_SampleAISSelectPackage_SelectNeutral (JNIEnv *env, jclass, jobject aContext, jobject Message)
290 jcas_Locking alock(env);
293 Handle( AIS_InteractiveContext ) the_aContext;
294 void* ptr_aContext = jcas_GetHandle(env,aContext);
296 if ( ptr_aContext != NULL ) the_aContext = *( ( Handle( AIS_InteractiveContext )* )ptr_aContext );
298 TCollection_AsciiString* the_Message = (TCollection_AsciiString*) jcas_GetHandle(env,Message);
299 if ( the_Message == NULL ) {
301 // The following assumes availability of the default constructor (what may not
302 // always be the case). Therefore explicit exception is thrown if the null
303 // object has been passed.
304 // the_Message = new TCollection_AsciiString ();
305 // jcas_SetHandle ( env, Message, the_Message );
306 jcas_ThrowException (env, "NULL object has been passed while expecting an object manipulated by value");
309 SampleAISSelectPackage::SelectNeutral(the_aContext,*the_Message);
312 catch (Standard_Failure) {
313 Standard_SStream Err;
314 Err << Standard_Failure::Caught();
316 jcas_ThrowException(env,Err.str().c_str());
325 JNIEXPORT jint JNICALL Java_SampleAISSelectJni_SampleAISSelectPackage_MakeFillet (JNIEnv *env, jclass, jobject aContext, jdouble aValue, jobject Message)
329 jcas_Locking alock(env);
332 Handle( AIS_InteractiveContext ) the_aContext;
333 void* ptr_aContext = jcas_GetHandle(env,aContext);
335 if ( ptr_aContext != NULL ) the_aContext = *( ( Handle( AIS_InteractiveContext )* )ptr_aContext );
337 TCollection_AsciiString* the_Message = (TCollection_AsciiString*) jcas_GetHandle(env,Message);
338 if ( the_Message == NULL ) {
340 // The following assumes availability of the default constructor (what may not
341 // always be the case). Therefore explicit exception is thrown if the null
342 // object has been passed.
343 // the_Message = new TCollection_AsciiString ();
344 // jcas_SetHandle ( env, Message, the_Message );
345 jcas_ThrowException (env, "NULL object has been passed while expecting an object manipulated by value");
348 thejret = SampleAISSelectPackage::MakeFillet(the_aContext,(Standard_Real) aValue,*the_Message);
351 catch (Standard_Failure) {
352 Standard_SStream Err;
353 Err << Standard_Failure::Caught();
355 jcas_ThrowException(env,Err.str().c_str());
364 JNIEXPORT jboolean JNICALL Java_SampleAISSelectJni_SampleAISSelectPackage_IsCylinderSelected (JNIEnv *env, jclass, jobject aContext)
368 jcas_Locking alock(env);
371 Handle( AIS_InteractiveContext ) the_aContext;
372 void* ptr_aContext = jcas_GetHandle(env,aContext);
374 if ( ptr_aContext != NULL ) the_aContext = *( ( Handle( AIS_InteractiveContext )* )ptr_aContext );
376 thejret = SampleAISSelectPackage::IsCylinderSelected(the_aContext);
379 catch (Standard_Failure) {
380 Standard_SStream Err;
381 Err << Standard_Failure::Caught();
383 jcas_ThrowException(env,Err.str().c_str());
392 JNIEXPORT void JNICALL Java_SampleAISSelectJni_SampleAISSelectPackage_StartSelectFace (JNIEnv *env, jclass, jobject aContext)
395 jcas_Locking alock(env);
398 Handle( AIS_InteractiveContext ) the_aContext;
399 void* ptr_aContext = jcas_GetHandle(env,aContext);
401 if ( ptr_aContext != NULL ) the_aContext = *( ( Handle( AIS_InteractiveContext )* )ptr_aContext );
403 SampleAISSelectPackage::StartSelectFace(the_aContext);
406 catch (Standard_Failure) {
407 Standard_SStream Err;
408 Err << Standard_Failure::Caught();
410 jcas_ThrowException(env,Err.str().c_str());
419 JNIEXPORT jobject JNICALL Java_SampleAISSelectJni_SampleAISSelectPackage_GetFaceColor (JNIEnv *env, jclass, jobject aContext)
423 jcas_Locking alock(env);
426 Handle( AIS_InteractiveContext ) the_aContext;
427 void* ptr_aContext = jcas_GetHandle(env,aContext);
429 if ( ptr_aContext != NULL ) the_aContext = *( ( Handle( AIS_InteractiveContext )* )ptr_aContext );
431 Quantity_Color* theret = new Quantity_Color(SampleAISSelectPackage::GetFaceColor(the_aContext));
432 thejret = jcas_CreateObject(env,"CASCADESamplesJni/Quantity_Color",theret);
435 catch (Standard_Failure) {
436 Standard_SStream Err;
437 Err << Standard_Failure::Caught();
439 jcas_ThrowException(env,Err.str().c_str());
448 JNIEXPORT void JNICALL Java_SampleAISSelectJni_SampleAISSelectPackage_SetFaceColor (JNIEnv *env, jclass, jobject aContext, jobject aColor, jobject Message)
451 jcas_Locking alock(env);
454 Handle( AIS_InteractiveContext ) the_aContext;
455 void* ptr_aContext = jcas_GetHandle(env,aContext);
457 if ( ptr_aContext != NULL ) the_aContext = *( ( Handle( AIS_InteractiveContext )* )ptr_aContext );
459 Quantity_Color* the_aColor = (Quantity_Color*) jcas_GetHandle(env,aColor);
460 if ( the_aColor == NULL ) {
462 // The following assumes availability of the default constructor (what may not
463 // always be the case). Therefore explicit exception is thrown if the null
464 // object has been passed.
465 // the_aColor = new Quantity_Color ();
466 // jcas_SetHandle ( env, aColor, the_aColor );
467 jcas_ThrowException (env, "NULL object has been passed while expecting an object manipulated by value");
470 TCollection_AsciiString* the_Message = (TCollection_AsciiString*) jcas_GetHandle(env,Message);
471 if ( the_Message == NULL ) {
473 // The following assumes availability of the default constructor (what may not
474 // always be the case). Therefore explicit exception is thrown if the null
475 // object has been passed.
476 // the_Message = new TCollection_AsciiString ();
477 // jcas_SetHandle ( env, Message, the_Message );
478 jcas_ThrowException (env, "NULL object has been passed while expecting an object manipulated by value");
481 SampleAISSelectPackage::SetFaceColor(the_aContext,*the_aColor,*the_Message);
484 catch (Standard_Failure) {
485 Standard_SStream Err;
486 Err << Standard_Failure::Caught();
488 jcas_ThrowException(env,Err.str().c_str());
497 JNIEXPORT void JNICALL Java_SampleAISSelectJni_SampleAISSelectPackage_EndSelectFace (JNIEnv *env, jclass, jobject aContext)
500 jcas_Locking alock(env);
503 Handle( AIS_InteractiveContext ) the_aContext;
504 void* ptr_aContext = jcas_GetHandle(env,aContext);
506 if ( ptr_aContext != NULL ) the_aContext = *( ( Handle( AIS_InteractiveContext )* )ptr_aContext );
508 SampleAISSelectPackage::EndSelectFace(the_aContext);
511 catch (Standard_Failure) {
512 Standard_SStream Err;
513 Err << Standard_Failure::Caught();
515 jcas_ThrowException(env,Err.str().c_str());