7fd59977 |
1 | // |
2 | // Copyright (C) 1991 - 2000 by |
3 | // Matra Datavision SA. All rights reserved. |
4 | // |
5 | // Copyright (C) 2001 - 2004 by |
6 | // Open CASCADE SA. All rights reserved. |
7 | // |
8 | // This file is part of the Open CASCADE Technology software. |
9 | // |
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. |
13 | // |
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 |
19 | // License. |
20 | |
21 | |
22 | #include <SampleAISBasicJni_SampleAISBasicPackage.h> |
23 | #include <SampleAISBasicPackage.hxx> |
24 | #include <jcas.hxx> |
25 | #include <stdlib.h> |
26 | #include <Standard_ErrorHandler.hxx> |
27 | #include <Standard_Failure.hxx> |
28 | #include <Standard_SStream.hxx> |
29 | |
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 | |
37 | |
38 | extern "C" { |
39 | |
40 | |
41 | JNIEXPORT jobject JNICALL Java_SampleAISBasicJni_SampleAISBasicPackage_CreateViewer (JNIEnv *env, jclass, jstring aName) |
42 | { |
43 | jobject thejret; |
44 | |
45 | jcas_Locking alock(env); |
46 | { |
47 | try { |
48 | Standard_ExtString the_aName = jcas_ConvertToExtString(env,aName); |
49 | Handle(V3d_Viewer)* theret = new Handle(V3d_Viewer); |
50 | *theret = SampleAISBasicPackage::CreateViewer(the_aName); |
51 | thejret = jcas_CreateObject(env,"CASCADESamplesJni/V3d_Viewer",theret); |
52 | |
53 | } |
54 | catch (Standard_Failure) { |
55 | Standard_SStream Err; |
56 | Err << Standard_Failure::Caught(); |
57 | Err << (char) 0; |
58 | jcas_ThrowException(env,Err.str().c_str()); |
59 | } |
60 | } |
61 | alock.Release(); |
62 | return thejret; |
63 | } |
64 | |
65 | |
66 | |
67 | JNIEXPORT void JNICALL Java_SampleAISBasicJni_SampleAISBasicPackage_SetWindow (JNIEnv *env, jclass, jobject aView, jint hiwin, jint lowin) |
68 | { |
69 | |
70 | jcas_Locking alock(env); |
71 | { |
72 | try { |
73 | Handle( V3d_View ) the_aView; |
74 | void* ptr_aView = jcas_GetHandle(env,aView); |
75 | |
76 | if ( ptr_aView != NULL ) the_aView = *( ( Handle( V3d_View )* )ptr_aView ); |
77 | |
78 | SampleAISBasicPackage::SetWindow(the_aView,(Standard_Integer) hiwin,(Standard_Integer) lowin); |
79 | |
80 | } |
81 | catch (Standard_Failure) { |
82 | Standard_SStream Err; |
83 | Err << Standard_Failure::Caught(); |
84 | Err << (char) 0; |
85 | jcas_ThrowException(env,Err.str().c_str()); |
86 | } |
87 | } |
88 | alock.Release(); |
89 | |
90 | } |
91 | |
92 | |
93 | |
94 | JNIEXPORT void JNICALL Java_SampleAISBasicJni_SampleAISBasicPackage_DisplayTrihedron (JNIEnv *env, jclass, jobject aContext) |
95 | { |
96 | |
97 | jcas_Locking alock(env); |
98 | { |
99 | try { |
100 | Handle( AIS_InteractiveContext ) the_aContext; |
101 | void* ptr_aContext = jcas_GetHandle(env,aContext); |
102 | |
103 | if ( ptr_aContext != NULL ) the_aContext = *( ( Handle( AIS_InteractiveContext )* )ptr_aContext ); |
104 | |
105 | SampleAISBasicPackage::DisplayTrihedron(the_aContext); |
106 | |
107 | } |
108 | catch (Standard_Failure) { |
109 | Standard_SStream Err; |
110 | Err << Standard_Failure::Caught(); |
111 | Err << (char) 0; |
112 | jcas_ThrowException(env,Err.str().c_str()); |
113 | } |
114 | } |
115 | alock.Release(); |
116 | |
117 | } |
118 | |
119 | |
120 | |
121 | JNIEXPORT void JNICALL Java_SampleAISBasicJni_SampleAISBasicPackage_DisplayCircle (JNIEnv *env, jclass, jobject aContext, jobject Message) |
122 | { |
123 | |
124 | jcas_Locking alock(env); |
125 | { |
126 | try { |
127 | Handle( AIS_InteractiveContext ) the_aContext; |
128 | void* ptr_aContext = jcas_GetHandle(env,aContext); |
129 | |
130 | if ( ptr_aContext != NULL ) the_aContext = *( ( Handle( AIS_InteractiveContext )* )ptr_aContext ); |
131 | |
132 | TCollection_AsciiString* the_Message = (TCollection_AsciiString*) jcas_GetHandle(env,Message); |
133 | if ( the_Message == NULL ) { |
134 | |
135 | // The following assumes availability of the default constructor (what may not |
136 | // always be the case). Therefore explicit exception is thrown if the null |
137 | // object has been passed. |
138 | // the_Message = new TCollection_AsciiString (); |
139 | // jcas_SetHandle ( env, Message, the_Message ); |
140 | jcas_ThrowException (env, "NULL object has been passed while expecting an object manipulated by value"); |
141 | |
142 | } // end if |
143 | SampleAISBasicPackage::DisplayCircle(the_aContext,*the_Message); |
144 | |
145 | } |
146 | catch (Standard_Failure) { |
147 | Standard_SStream Err; |
148 | Err << Standard_Failure::Caught(); |
149 | Err << (char) 0; |
150 | jcas_ThrowException(env,Err.str().c_str()); |
151 | } |
152 | } |
153 | alock.Release(); |
154 | |
155 | } |
156 | |
157 | |
158 | |
159 | JNIEXPORT void JNICALL Java_SampleAISBasicJni_SampleAISBasicPackage_DisplayLine (JNIEnv *env, jclass, jobject aContext, jobject Message) |
160 | { |
161 | |
162 | jcas_Locking alock(env); |
163 | { |
164 | try { |
165 | Handle( AIS_InteractiveContext ) the_aContext; |
166 | void* ptr_aContext = jcas_GetHandle(env,aContext); |
167 | |
168 | if ( ptr_aContext != NULL ) the_aContext = *( ( Handle( AIS_InteractiveContext )* )ptr_aContext ); |
169 | |
170 | TCollection_AsciiString* the_Message = (TCollection_AsciiString*) jcas_GetHandle(env,Message); |
171 | if ( the_Message == NULL ) { |
172 | |
173 | // The following assumes availability of the default constructor (what may not |
174 | // always be the case). Therefore explicit exception is thrown if the null |
175 | // object has been passed. |
176 | // the_Message = new TCollection_AsciiString (); |
177 | // jcas_SetHandle ( env, Message, the_Message ); |
178 | jcas_ThrowException (env, "NULL object has been passed while expecting an object manipulated by value"); |
179 | |
180 | } // end if |
181 | SampleAISBasicPackage::DisplayLine(the_aContext,*the_Message); |
182 | |
183 | } |
184 | catch (Standard_Failure) { |
185 | Standard_SStream Err; |
186 | Err << Standard_Failure::Caught(); |
187 | Err << (char) 0; |
188 | jcas_ThrowException(env,Err.str().c_str()); |
189 | } |
190 | } |
191 | alock.Release(); |
192 | |
193 | } |
194 | |
195 | |
196 | |
197 | JNIEXPORT void JNICALL Java_SampleAISBasicJni_SampleAISBasicPackage_DisplaySphere (JNIEnv *env, jclass, jobject aContext, jobject Message) |
198 | { |
199 | |
200 | jcas_Locking alock(env); |
201 | { |
202 | try { |
203 | Handle( AIS_InteractiveContext ) the_aContext; |
204 | void* ptr_aContext = jcas_GetHandle(env,aContext); |
205 | |
206 | if ( ptr_aContext != NULL ) the_aContext = *( ( Handle( AIS_InteractiveContext )* )ptr_aContext ); |
207 | |
208 | TCollection_AsciiString* the_Message = (TCollection_AsciiString*) jcas_GetHandle(env,Message); |
209 | if ( the_Message == NULL ) { |
210 | |
211 | // The following assumes availability of the default constructor (what may not |
212 | // always be the case). Therefore explicit exception is thrown if the null |
213 | // object has been passed. |
214 | // the_Message = new TCollection_AsciiString (); |
215 | // jcas_SetHandle ( env, Message, the_Message ); |
216 | jcas_ThrowException (env, "NULL object has been passed while expecting an object manipulated by value"); |
217 | |
218 | } // end if |
219 | SampleAISBasicPackage::DisplaySphere(the_aContext,*the_Message); |
220 | |
221 | } |
222 | catch (Standard_Failure) { |
223 | Standard_SStream Err; |
224 | Err << Standard_Failure::Caught(); |
225 | Err << (char) 0; |
226 | jcas_ThrowException(env,Err.str().c_str()); |
227 | } |
228 | } |
229 | alock.Release(); |
230 | |
231 | } |
232 | |
233 | |
234 | |
235 | JNIEXPORT void JNICALL Java_SampleAISBasicJni_SampleAISBasicPackage_DisplayCylinder (JNIEnv *env, jclass, jobject aContext, jobject Message) |
236 | { |
237 | |
238 | jcas_Locking alock(env); |
239 | { |
240 | try { |
241 | Handle( AIS_InteractiveContext ) the_aContext; |
242 | void* ptr_aContext = jcas_GetHandle(env,aContext); |
243 | |
244 | if ( ptr_aContext != NULL ) the_aContext = *( ( Handle( AIS_InteractiveContext )* )ptr_aContext ); |
245 | |
246 | TCollection_AsciiString* the_Message = (TCollection_AsciiString*) jcas_GetHandle(env,Message); |
247 | if ( the_Message == NULL ) { |
248 | |
249 | // The following assumes availability of the default constructor (what may not |
250 | // always be the case). Therefore explicit exception is thrown if the null |
251 | // object has been passed. |
252 | // the_Message = new TCollection_AsciiString (); |
253 | // jcas_SetHandle ( env, Message, the_Message ); |
254 | jcas_ThrowException (env, "NULL object has been passed while expecting an object manipulated by value"); |
255 | |
256 | } // end if |
257 | SampleAISBasicPackage::DisplayCylinder(the_aContext,*the_Message); |
258 | |
259 | } |
260 | catch (Standard_Failure) { |
261 | Standard_SStream Err; |
262 | Err << Standard_Failure::Caught(); |
263 | Err << (char) 0; |
264 | jcas_ThrowException(env,Err.str().c_str()); |
265 | } |
266 | } |
267 | alock.Release(); |
268 | |
269 | } |
270 | |
271 | |
272 | } |