0027086: Samples, jniviewer - avoid duplicating viewer redraws
[occt.git] / samples / java / jniviewer / jni / OcctJni_Viewer.cxx
... / ...
CommitLineData
1// Copyright (c) 2014 OPEN CASCADE SAS
2//
3// This file is part of Open CASCADE Technology software library.
4//
5// This library is free software; you can redistribute it and/or modify it under
6// the terms of the GNU Lesser General Public License version 2.1 as published
7// by the Free Software Foundation, with special exception defined in the file
8// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9// distribution for complete text of the license and disclaimer of any warranty.
10//
11// Alternatively, this file may be used under the terms of Open CASCADE
12// commercial license or contractual agreement.
13
14#include <OcctJni_Viewer.hxx>
15#include <OcctJni_MsgPrinter.hxx>
16
17#include <AIS_Shape.hxx>
18#include <Image_AlienPixMap.hxx>
19#include <BRepTools.hxx>
20#include <Message_Messenger.hxx>
21#include <Message_MsgFile.hxx>
22#include <OpenGl_GraphicDriver.hxx>
23#include <OSD_Environment.hxx>
24#include <OSD_Timer.hxx>
25#include <Standard_Version.hxx>
26
27#include <BRepPrimAPI_MakeBox.hxx>
28
29#include <STEPControl_Reader.hxx>
30#include <IGESControl_Reader.hxx>
31#include <XSControl_WorkSession.hxx>
32
33#include <EGL/egl.h>
34
35#include <sys/types.h>
36#include <sys/stat.h>
37
38#include <jni.h>
39
40//! @return true if file exists
41static bool isFileExist (const TCollection_AsciiString& thePath)
42{
43 struct stat64 aStatBuffer;
44 return stat64 (thePath.ToCString(), &aStatBuffer) == 0;
45}
46
47//! Cut-off the last split character from the path and everything after it.
48static TCollection_AsciiString getParentDir (const TCollection_AsciiString& thePath)
49{
50 TCollection_AsciiString aPath = thePath;
51 char* aSplitter = (char* )aPath.ToCString();
52 for (char* anIter = aSplitter; *anIter != '\0'; ++anIter)
53 {
54 if (*anIter == '\\'
55 || *anIter == '/')
56 {
57 aSplitter = anIter;
58 }
59 }
60 *aSplitter = '\0'; // cut off file name or trailing folder
61 return TCollection_AsciiString (aPath.ToCString());
62}
63
64//! Set environment variable theVarName indicating location of resource
65//! file theFile so as to correspond to actual location of this file.
66//!
67//! The resource file is searched in directory where Test.Draw.dll is located,
68//! and if not found - also in subdirectory ../res from there.
69//! If file is found, environment variable is set for C subsystem.
70//! Otherwise, environment is not changed.
71//!
72//! If theToAddFileName is true, complete file name is set as value of the variable,
73//! if theToAddFileName is false, only path is set.
74Standard_Boolean setResourceEnv (const TCollection_AsciiString& theVarName,
75 const TCollection_AsciiString& theRoot,
76 const TCollection_AsciiString& theFile,
77 const Standard_Boolean theToAddFileName)
78{
79 // use location of current assembly to figure out possible location of resource
80 TCollection_AsciiString aBaseDir = theRoot;
81
82 // check the same directory where binary is located
83 if (!isFileExist (aBaseDir + "/" + theFile))
84 {
85 // check subdirectory ../res
86 aBaseDir = getParentDir (aBaseDir) + "/res";
87 if (!isFileExist (aBaseDir + "/" + theFile))
88 {
89 return Standard_False;
90 }
91 }
92
93 // set C library environment
94 if (theToAddFileName)
95 {
96 aBaseDir = aBaseDir + "/" + theFile;
97 }
98
99 OSD_Environment anEnv (theVarName, aBaseDir);
100 anEnv.Build();
101 return Standard_True;
102}
103
104// =======================================================================
105// function : OcctJni_Viewer
106// purpose :
107// =======================================================================
108OcctJni_Viewer::OcctJni_Viewer()
109{
110 // prepare necessary environment
111 TCollection_AsciiString aResRoot = "/data/data/com.opencascade.jnisample/files";
112
113 setResourceEnv ("CSF_TObjMessage", aResRoot + "/TObj", "TObj.msg", Standard_False);
114 setResourceEnv ("CSF_UnitsLexicon", aResRoot + "/UnitsAPI", "Lexi_Expr.dat", Standard_True);
115 setResourceEnv ("CSF_UnitsDefinition", aResRoot + "/UnitsAPI", "Units.dat", Standard_True);
116 setResourceEnv ("CSF_ShadersDirectory", aResRoot + "/Shaders", "Declarations.glsl", Standard_False);
117 setResourceEnv ("CSF_XSMessage", aResRoot + "/XSMessage", "XSTEP.us", Standard_False);
118 setResourceEnv ("CSF_SHMessage", aResRoot + "/XSMessage", "SHAPE.us", Standard_False);
119 //setResourceEnv ("CSF_PluginDefaults", "Plugin", Standard_False);
120
121 // make sure OCCT loads the dictionary
122 //UnitsAPI::SetLocalSystem (UnitsAPI_SI);
123
124 // load messages for TObj
125 Message_MsgFile::LoadFromEnv ("CSF_TObjMessage", "TObj", "msg");
126}
127
128// =======================================================================
129// function : init
130// purpose :
131// =======================================================================
132bool OcctJni_Viewer::init()
133{
134 EGLint aCfgId = 0;
135 int aWidth = 0, aHeight = 0;
136 EGLDisplay anEglDisplay = eglGetCurrentDisplay();
137 EGLContext anEglContext = eglGetCurrentContext();
138 EGLSurface anEglSurf = eglGetCurrentSurface (EGL_DRAW);
139 if (anEglDisplay == EGL_NO_DISPLAY
140 || anEglContext == EGL_NO_CONTEXT
141 || anEglSurf == EGL_NO_SURFACE)
142 {
143 Message::DefaultMessenger()->Send ("Error: No active EGL context!", Message_Fail);
144 release();
145 return false;
146 }
147
148 eglQuerySurface (anEglDisplay, anEglSurf, EGL_WIDTH, &aWidth);
149 eglQuerySurface (anEglDisplay, anEglSurf, EGL_HEIGHT, &aHeight);
150 eglQuerySurface (anEglDisplay, anEglSurf, EGL_CONFIG_ID, &aCfgId);
151 const EGLint aConfigAttribs[] = { EGL_CONFIG_ID, aCfgId, EGL_NONE };
152 EGLint aNbConfigs = 0;
153 void* anEglConfig = NULL;
154 if (eglChooseConfig (anEglDisplay, aConfigAttribs, &anEglConfig, 1, &aNbConfigs) != EGL_TRUE)
155 {
156 Message::DefaultMessenger()->Send ("Error: EGL does not provide compatible configurations!", Message_Fail);
157 release();
158 return false;
159 }
160
161 TCollection_AsciiString anEglInfo = TCollection_AsciiString()
162 + "\n EGLVersion: " + eglQueryString (anEglDisplay, EGL_VERSION)
163 + "\n EGLVendor: " + eglQueryString (anEglDisplay, EGL_VENDOR)
164 + "\n EGLClient APIs: " + eglQueryString (anEglDisplay, EGL_CLIENT_APIS)
165 + "\n GLvendor: " + (const char* )glGetString (GL_VENDOR)
166 + "\n GLdevice: " + (const char* )glGetString (GL_RENDERER)
167 + "\n GLversion: " + (const char* )glGetString (GL_VERSION) + " [GLSL: " + (const char* )glGetString (GL_SHADING_LANGUAGE_VERSION) + "]";
168 ::Message::DefaultMessenger()->Send (anEglInfo, Message_Info);
169
170 if (!myViewer.IsNull())
171 {
172 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast (myViewer->Driver());
173 Handle(OcctJni_Window) aWindow = Handle(OcctJni_Window)::DownCast (myView->Window());
174 if (!aDriver->InitEglContext (anEglDisplay, anEglContext, anEglConfig))
175 {
176 Message::DefaultMessenger()->Send ("Error: OpenGl_GraphicDriver can not be initialized!", Message_Fail);
177 release();
178 return false;
179 }
180
181 aWindow->SetSize (aWidth, aHeight);
182 myView->SetWindow (aWindow, (Aspect_RenderingContext )anEglContext);
183 return true;
184 }
185
186 Handle(OpenGl_GraphicDriver) aDriver = new OpenGl_GraphicDriver (NULL, Standard_False);
187 aDriver->ChangeOptions().buffersNoSwap = Standard_True;
188//aDriver->ChangeOptions().glslWarnings = Standard_True; /// for debug only!
189 if (!aDriver->InitEglContext (anEglDisplay, anEglContext, anEglConfig))
190 {
191 Message::DefaultMessenger()->Send ("Error: OpenGl_GraphicDriver can not be initialized!", Message_Fail);
192 release();
193 return false;
194 }
195
196 // create viewer
197 myViewer = new V3d_Viewer (aDriver, TCollection_ExtendedString("Viewer").ToExtString(), "", 1000.0,
198 V3d_XposYnegZpos, Quantity_NOC_BLACK, V3d_ZBUFFER, V3d_GOURAUD, V3d_WAIT,
199 Standard_True, Standard_False);
200 myViewer->SetDefaultLights();
201 myViewer->SetLightOn();
202
203 // create AIS context
204 myContext = new AIS_InteractiveContext (myViewer);
205 //myContext->SetDisplayMode (AIS_WireFrame);
206 myContext->SetDisplayMode (AIS_Shaded);
207
208 Handle(OcctJni_Window) aWindow = new OcctJni_Window (aWidth, aHeight);
209 myView = myViewer->CreateView();
210
211 myView->SetWindow (aWindow, (Aspect_RenderingContext )anEglContext);
212 myView->TriedronDisplay (Aspect_TOTP_RIGHT_LOWER, Quantity_NOC_WHITE, 0.08, V3d_ZBUFFER);
213
214 initContent();
215 return true;
216}
217
218// =======================================================================
219// function : release
220// purpose :
221// =======================================================================
222void OcctJni_Viewer::release()
223{
224 myContext.Nullify();
225 myView.Nullify();
226 myViewer.Nullify();
227}
228
229// =======================================================================
230// function : resize
231// purpose :
232// =======================================================================
233void OcctJni_Viewer::resize (int theWidth,
234 int theHeight)
235{
236 if (myContext.IsNull())
237 {
238 Message::DefaultMessenger()->Send ("Resize failed - view is unavailable", Message_Fail);
239 return;
240 }
241
242 Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast (myViewer->Driver());
243 Handle(OcctJni_Window) aWindow = Handle(OcctJni_Window)::DownCast (myView->Window());
244 aWindow->SetSize (theWidth, theHeight);
245 //myView->MustBeResized(); // can be used instead of SetWindow() when EGLsurface has not been changed
246
247 EGLContext anEglContext = eglGetCurrentContext();
248 myView->SetImmediateUpdate (Standard_False);
249 myView->SetWindow (aWindow, (Aspect_RenderingContext )anEglContext);
250 //saveSnapshot ("/sdcard/Download/tt.png", theWidth, theHeight);
251}
252
253// =======================================================================
254// function : initContent
255// purpose :
256// =======================================================================
257void OcctJni_Viewer::initContent()
258{
259 myContext->RemoveAll (Standard_False);
260
261 OSD_Timer aTimer;
262 aTimer.Start();
263 if (!myShape.IsNull())
264 {
265 Handle(AIS_Shape) aShapePrs = new AIS_Shape (myShape);
266 myContext->Display (aShapePrs, Standard_False);
267 }
268 else
269 {
270 BRepPrimAPI_MakeBox aBuilder (1.0, 2.0, 3.0);
271 Handle(AIS_Shape) aShapePrs = new AIS_Shape (aBuilder.Shape());
272 myContext->Display (aShapePrs, Standard_False);
273 }
274 myView->FitAll();
275
276 aTimer.Stop();
277 Message::DefaultMessenger()->Send (TCollection_AsciiString() + "Presentation computed in " + aTimer.ElapsedTime() + " seconds", Message_Info);
278}
279
280//! Load shape from IGES file
281static TopoDS_Shape loadIGES (const TCollection_AsciiString& thePath)
282{
283 TopoDS_Shape aShape;
284 IGESControl_Reader aReader;
285 IFSelect_ReturnStatus aReadStatus = IFSelect_RetFail;
286 try
287 {
288 aReadStatus = aReader.ReadFile (thePath.ToCString());
289 }
290 catch (Standard_Failure)
291 {
292 Message::DefaultMessenger()->Send ("Error: IGES reader, computation error", Message_Fail);
293 return aShape;
294 }
295
296 if (aReadStatus != IFSelect_RetDone)
297 {
298 Message::DefaultMessenger()->Send ("Error: IGES reader, bad file format", Message_Fail);
299 return aShape;
300 }
301
302 // now perform the translation
303 aReader.TransferRoots();
304 if (aReader.NbShapes() <= 0)
305 {
306 Handle(XSControl_WorkSession) aWorkSession = new XSControl_WorkSession();
307 aWorkSession->SelectNorm ("IGES");
308 aReader.SetWS (aWorkSession, Standard_True);
309 aReader.SetReadVisible (Standard_False);
310 aReader.TransferRoots();
311 }
312 if (aReader.NbShapes() <= 0)
313 {
314 Message::DefaultMessenger()->Send ("Error: IGES reader, no shapes has been found", Message_Fail);
315 return aShape;
316 }
317 return aReader.OneShape();
318 /*TopoDS_Shape anImportedShape = aReader.OneShape();
319
320 // apply sewing on the imported shape
321 BRepBuilderAPI_Sewing aTool (0.0);
322 aTool.SetNonManifoldMode (Standard_False);
323 aTool.SetFloatingEdgesMode(Standard_True);
324 aTool.Load (anImportedShape);
325 aTool.Perform();
326 TopoDS_Shape aSewedShape = aTool.SewedShape();
327
328 if (aSewedShape.IsNull())
329 {
330 Message::DefaultMessenger()->Send ("Error: Sewing result is empty", Message_Fail);
331 return aShape;
332 }
333 if (aSewedShape.IsSame(anImportedShape))
334 {
335 aShape = anImportedShape;
336 }
337 else
338 {
339 // apply shape healing
340 ShapeFix_Shape aShapeFixer(aSewedShape);
341 aShapeFixer.FixSolidMode() = 1;
342 aShapeFixer.FixFreeShellMode() = 1;
343 aShapeFixer.FixFreeFaceMode() = 1;
344 aShapeFixer.FixFreeWireMode() = 0;
345 aShapeFixer.FixSameParameterMode() = 0;
346 aShapeFixer.FixVertexPositionMode() = 0;
347 aShape = aShapeFixer.Perform() ? aShapeFixer.Shape() : aSewedShape;
348 }
349 return aShape;*/
350}
351
352//! Load shape from STEP file
353static TopoDS_Shape loadSTEP (const TCollection_AsciiString& thePath)
354{
355 STEPControl_Reader aReader;
356 IFSelect_ReturnStatus aReadStatus = IFSelect_RetFail;
357 try
358 {
359 aReadStatus = aReader.ReadFile (thePath.ToCString());
360 }
361 catch (Standard_Failure)
362 {
363 Message::DefaultMessenger()->Send ("Error: STEP reader, computation error", Message_Fail);
364 return TopoDS_Shape();
365 }
366
367 if (aReadStatus != IFSelect_RetDone)
368 {
369 Message::DefaultMessenger()->Send ("Error: STEP reader, bad file format", Message_Fail);
370 return TopoDS_Shape();
371 }
372 else if (aReader.NbRootsForTransfer() <= 0)
373 {
374 Message::DefaultMessenger()->Send ("Error: STEP reader, shape is empty", Message_Fail);
375 return TopoDS_Shape();
376 }
377
378 // now perform the translation
379 aReader.TransferRoots();
380 return aReader.OneShape();
381}
382
383// =======================================================================
384// function : open
385// purpose :
386// =======================================================================
387bool OcctJni_Viewer::open (const TCollection_AsciiString& thePath)
388{
389 myShape.Nullify();
390 if (!myContext.IsNull())
391 {
392 myContext->RemoveAll (Standard_False);
393 }
394 if (thePath.IsEmpty())
395 {
396 return false;
397 }
398
399 OSD_Timer aTimer;
400 aTimer.Start();
401 TCollection_AsciiString aFormatStr;
402 const Standard_Integer aLen = thePath.Length();
403 if (aLen >= 5
404 && thePath.Value (aLen - 4) == '.')
405 {
406 aFormatStr = thePath.SubString (aLen - 3, aLen);
407 }
408 else if (aLen >= 4
409 && thePath.Value (aLen - 3) == '.')
410 {
411 aFormatStr = thePath.SubString (aLen - 2, aLen);
412 }
413 else if (aLen >= 3
414 && thePath.Value (aLen - 2) == '.')
415 {
416 aFormatStr = thePath.SubString (aLen - 1, aLen);
417 }
418 aFormatStr.LowerCase();
419
420 TopoDS_Shape aShape;
421 if (aFormatStr == "stp"
422 || aFormatStr == "step")
423 {
424 aShape = loadSTEP (thePath);
425 }
426 else if (aFormatStr == "igs"
427 || aFormatStr == "iges")
428 {
429 aShape = loadIGES (thePath);
430 }
431 else
432 // if (aFormatStr == "brep"
433 // || aFormatStr == "rle")
434 {
435 BRep_Builder aBuilder;
436 if (!BRepTools::Read (aShape, thePath.ToCString(), aBuilder))
437 {
438 Message::DefaultMessenger()->Send (TCollection_AsciiString() + "Error: file '" + thePath + "' can not be opened!", Message_Info);
439 return false;
440 }
441 }
442 if (aShape.IsNull())
443 {
444 return false;
445 }
446 aTimer.Stop();
447 Message::DefaultMessenger()->Send (TCollection_AsciiString() + "File '" + thePath + "' loaded in " + aTimer.ElapsedTime() + " seconds", Message_Info);
448
449 myShape = aShape;
450 if (myContext.IsNull())
451 {
452 return true;
453 }
454
455 aTimer.Reset();
456 aTimer.Start();
457
458 Handle(AIS_Shape) aShapePrs = new AIS_Shape (aShape);
459 myContext->Display (aShapePrs, Standard_False);
460 myView->FitAll();
461
462 aTimer.Stop();
463 Message::DefaultMessenger()->Send (TCollection_AsciiString() + "Presentation computed in " + aTimer.ElapsedTime() + " seconds", Message_Info);
464 return true;
465}
466
467// =======================================================================
468// function : saveSnapshot
469// purpose :
470// =======================================================================
471bool OcctJni_Viewer::saveSnapshot (const TCollection_AsciiString& thePath,
472 int theWidth,
473 int theHeight)
474{
475 if (myContext.IsNull()
476 || thePath.IsEmpty())
477 {
478 Message::DefaultMessenger()->Send ("Image dump failed - view is unavailable", Message_Fail);
479 return false;
480 }
481
482 if (theWidth < 1
483 || theHeight < 1)
484 {
485 myView->Window()->Size (theWidth, theHeight);
486 }
487 if (theWidth < 1
488 || theHeight < 1)
489 {
490 Message::DefaultMessenger()->Send ("Image dump failed - view is unavailable", Message_Fail);
491 return false;
492 }
493
494 Image_AlienPixMap anAlienImage;
495 if (!anAlienImage.InitTrash (Image_PixMap::ImgBGRA, theWidth, theHeight))
496 {
497 Message::DefaultMessenger()->Send (TCollection_AsciiString() + "RGBA image " + theWidth + "x" + theHeight + " allocation failed", Message_Fail);
498 return false;
499 }
500
501 // OpenGL ES does not support fetching data in BGRA format
502 // while FreeImage does not support RGBA format.
503 Image_PixMap anImage;
504 anImage.InitWrapper (Image_PixMap::ImgRGBA,
505 anAlienImage.ChangeData(),
506 anAlienImage.SizeX(),
507 anAlienImage.SizeY(),
508 anAlienImage.SizeRowBytes());
509 if (!myView->ToPixMap (anImage, theWidth, theHeight, Graphic3d_BT_RGBA))
510 {
511 Message::DefaultMessenger()->Send (TCollection_AsciiString() + "View dump to the image " + theWidth + "x" + theHeight + " failed", Message_Fail);
512 }
513
514 for (Standard_Size aRow = 0; aRow < anAlienImage.SizeY(); ++aRow)
515 {
516 for (Standard_Size aCol = 0; aCol < anAlienImage.SizeX(); ++aCol)
517 {
518 Image_ColorRGBA& aPixel = anAlienImage.ChangeValue<Image_ColorRGBA> (aRow, aCol);
519 std::swap (aPixel.r(), aPixel.b());
520 //aPixel.a() = 1.0;
521 }
522 }
523
524 if (!anAlienImage.Save (thePath))
525 {
526 Message::DefaultMessenger()->Send (TCollection_AsciiString() + "Image saving to path '" + thePath + "' failed", Message_Fail);
527 return false;
528 }
529 Message::DefaultMessenger()->Send (TCollection_AsciiString() + "View " + theWidth + "x" + theHeight + " dumped to image '" + thePath + "'", Message_Info);
530 return true;
531}
532
533// =======================================================================
534// function : redraw
535// purpose :
536// =======================================================================
537void OcctJni_Viewer::redraw()
538{
539 if (myView.IsNull())
540 {
541 return;
542 }
543
544 myView->Redraw();
545}
546
547// =======================================================================
548// function : fitAll
549// purpose :
550// =======================================================================
551void OcctJni_Viewer::fitAll()
552{
553 if (myView.IsNull())
554 {
555 return;
556 }
557
558 myView->FitAll (0.01, Standard_False);
559 myView->Invalidate();
560}
561
562// =======================================================================
563// function : startRotation
564// purpose :
565// =======================================================================
566void OcctJni_Viewer::startRotation (int theStartX,
567 int theStartY)
568{
569 if (myView.IsNull())
570 {
571 return;
572 }
573
574 myView->StartRotation (theStartX, theStartY, 0.45);
575 myView->Invalidate();
576}
577
578// =======================================================================
579// function : onRotation
580// purpose :
581// =======================================================================
582void OcctJni_Viewer::onRotation (int theX,
583 int theY)
584{
585 if (myView.IsNull())
586 {
587 return;
588 }
589
590 myView->Rotation (theX, theY);
591 myView->Invalidate();
592}
593
594// =======================================================================
595// function : onPanning
596// purpose :
597// =======================================================================
598void OcctJni_Viewer::onPanning (int theDX,
599 int theDY)
600{
601 if (myView.IsNull())
602 {
603 return;
604 }
605
606 myView->Pan (theDX, theDY);
607 myView->Invalidate();
608}
609
610// =======================================================================
611// function : onClick
612// purpose :
613// =======================================================================
614void OcctJni_Viewer::onClick (int theX,
615 int theY)
616{
617 if (myView.IsNull())
618 {
619 return;
620 }
621
622 myContext->MoveTo (theX, theY, myView, Standard_False);
623 myContext->Select (Standard_False);
624 myView->Invalidate();
625}
626
627// =======================================================================
628// function : stopAction
629// purpose :
630// =======================================================================
631void OcctJni_Viewer::stopAction()
632{
633 if (myView.IsNull())
634 {
635 return;
636 }
637}
638
639#define jexp extern "C" JNIEXPORT
640
641jexp jlong JNICALL Java_com_opencascade_jnisample_OcctJniRenderer_cppCreate (JNIEnv* theEnv,
642 jobject theObj)
643{
644 return jlong(new OcctJni_Viewer());
645}
646
647jexp void JNICALL Java_com_opencascade_jnisample_OcctJniRenderer_cppDestroy (JNIEnv* theEnv,
648 jobject theObj,
649 jlong theCppPtr)
650{
651 delete (OcctJni_Viewer* )theCppPtr;
652
653 Handle(Message_Messenger) aMsgMgr = Message::DefaultMessenger();
654 aMsgMgr->RemovePrinters (STANDARD_TYPE (OcctJni_MsgPrinter));
655}
656
657jexp void JNICALL Java_com_opencascade_jnisample_OcctJniRenderer_cppRelease (JNIEnv* theEnv,
658 jobject theObj,
659 jlong theCppPtr)
660{
661 ((OcctJni_Viewer* )theCppPtr)->release();
662}
663
664jexp void JNICALL Java_com_opencascade_jnisample_OcctJniRenderer_cppInit (JNIEnv* theEnv,
665 jobject theObj,
666 jlong theCppPtr)
667{
668 Handle(Message_Messenger) aMsgMgr = Message::DefaultMessenger();
669 aMsgMgr->RemovePrinters (STANDARD_TYPE (OcctJni_MsgPrinter));
670 aMsgMgr->AddPrinter (new OcctJni_MsgPrinter (theEnv, theObj));
671 ((OcctJni_Viewer* )theCppPtr)->init();
672}
673
674jexp void JNICALL Java_com_opencascade_jnisample_OcctJniRenderer_cppResize (JNIEnv* theEnv,
675 jobject theObj,
676 jlong theCppPtr,
677 jint theWidth,
678 jint theHeight)
679{
680 ((OcctJni_Viewer* )theCppPtr)->resize (theWidth, theHeight);
681}
682
683jexp void JNICALL Java_com_opencascade_jnisample_OcctJniRenderer_cppOpen (JNIEnv* theEnv,
684 jobject theObj,
685 jlong theCppPtr,
686 jstring thePath)
687{
688 const char* aPathPtr = theEnv->GetStringUTFChars (thePath, 0);
689 const TCollection_AsciiString aPath (aPathPtr);
690 theEnv->ReleaseStringUTFChars (thePath, aPathPtr);
691 ((OcctJni_Viewer* )theCppPtr)->open (aPath);
692}
693
694jexp void JNICALL Java_com_opencascade_jnisample_OcctJniRenderer_cppRedraw (JNIEnv* theEnv,
695 jobject theObj,
696 jlong theCppPtr)
697{
698 ((OcctJni_Viewer* )theCppPtr)->redraw();
699}
700
701jexp void JNICALL Java_com_opencascade_jnisample_OcctJniRenderer_cppSetAxoProj (JNIEnv* theEnv,
702 jobject theObj,
703 jlong theCppPtr)
704{
705 ((OcctJni_Viewer* )theCppPtr)->setProj (V3d_XposYnegZpos);
706}
707
708jexp void JNICALL Java_com_opencascade_jnisample_OcctJniRenderer_cppSetXposProj (JNIEnv* theEnv,
709 jobject theObj,
710 jlong theCppPtr)
711{
712 ((OcctJni_Viewer* )theCppPtr)->setProj (V3d_Xpos);
713}
714
715jexp void JNICALL Java_com_opencascade_jnisample_OcctJniRenderer_cppSetYposProj (JNIEnv* theEnv,
716 jobject theObj,
717 jlong theCppPtr)
718{
719 ((OcctJni_Viewer* )theCppPtr)->setProj (V3d_Ypos);
720}
721
722jexp void JNICALL Java_com_opencascade_jnisample_OcctJniRenderer_cppSetZposProj (JNIEnv* theEnv,
723 jobject theObj,
724 jlong theCppPtr)
725{
726 ((OcctJni_Viewer* )theCppPtr)->setProj (V3d_Zpos);
727}
728
729jexp void JNICALL Java_com_opencascade_jnisample_OcctJniRenderer_cppSetXnegProj (JNIEnv* theEnv,
730 jobject theObj,
731 jlong theCppPtr)
732{
733 ((OcctJni_Viewer* )theCppPtr)->setProj (V3d_Xneg);
734}
735
736jexp void JNICALL Java_com_opencascade_jnisample_OcctJniRenderer_cppSetYnegProj (JNIEnv* theEnv,
737 jobject theObj,
738 jlong theCppPtr)
739{
740 ((OcctJni_Viewer* )theCppPtr)->setProj (V3d_Yneg);
741}
742
743jexp void JNICALL Java_com_opencascade_jnisample_OcctJniRenderer_cppSetZnegProj (JNIEnv* theEnv,
744 jobject theObj,
745 jlong theCppPtr)
746{
747 ((OcctJni_Viewer* )theCppPtr)->setProj (V3d_Zneg);
748}
749
750jexp void JNICALL Java_com_opencascade_jnisample_OcctJniRenderer_cppFitAll (JNIEnv* theEnv,
751 jobject theObj,
752 jlong theCppPtr)
753{
754 ((OcctJni_Viewer* )theCppPtr)->fitAll();
755}
756
757jexp void JNICALL Java_com_opencascade_jnisample_OcctJniRenderer_cppStartRotation (JNIEnv* theEnv,
758 jobject theObj,
759 jlong theCppPtr,
760 jint theStartX,
761 jint theStartY)
762{
763 ((OcctJni_Viewer* )theCppPtr)->startRotation (theStartX, theStartY);
764}
765
766jexp void JNICALL Java_com_opencascade_jnisample_OcctJniRenderer_cppOnRotation (JNIEnv* theEnv,
767 jobject theObj,
768 jlong theCppPtr,
769 jint theX,
770 jint theY)
771{
772 ((OcctJni_Viewer* )theCppPtr)->onRotation (theX, theY);
773}
774
775jexp void JNICALL Java_com_opencascade_jnisample_OcctJniRenderer_cppOnPanning (JNIEnv* theEnv,
776 jobject theObj,
777 jlong theCppPtr,
778 jint theDX,
779 jint theDY)
780{
781 ((OcctJni_Viewer* )theCppPtr)->onPanning (theDX, theDY);
782}
783
784jexp void JNICALL Java_com_opencascade_jnisample_OcctJniRenderer_cppOnClick (JNIEnv* theEnv,
785 jobject theObj,
786 jlong theCppPtr,
787 jint theX,
788 jint theY)
789{
790 ((OcctJni_Viewer* )theCppPtr)->onClick (theX, theY);
791}
792
793jexp void JNICALL Java_com_opencascade_jnisample_OcctJniRenderer_cppStopAction (JNIEnv* theEnv,
794 jobject theObj,
795 jlong theCppPtr)
796{
797 ((OcctJni_Viewer* )theCppPtr)->stopAction();
798}
799
800jexp jlong JNICALL Java_com_opencascade_jnisample_OcctJniActivity_cppOcctMajorVersion (JNIEnv* theEnv,
801 jobject theObj)
802{
803 return OCC_VERSION_MAJOR;
804}
805
806jexp jlong JNICALL Java_com_opencascade_jnisample_OcctJniActivity_cppOcctMinorVersion (JNIEnv* theEnv,
807 jobject theObj)
808{
809 return OCC_VERSION_MINOR;
810}
811
812jexp jlong JNICALL Java_com_opencascade_jnisample_OcctJniActivity_cppOcctMicroVersion (JNIEnv* theEnv,
813 jobject theObj)
814{
815 return OCC_VERSION_MAINTENANCE;
816}