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