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