0027398: Integrate Qt Browser Widget to Open CASCADE Technology
[occt.git] / tools / View / View_Viewer.cxx
1 // Created on: 2017-06-16
2 // Created by: Natalia ERMOLAEVA
3 // Copyright (c) 2017 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement. 
15
16 #include <View_Viewer.hxx>
17
18 #include <OpenGl_GraphicDriver.hxx>
19 #include <Standard_ExtString.hxx>
20 #include <Standard_Version.hxx>
21
22 // =======================================================================
23 // function : CreateView
24 // purpose :
25 // =======================================================================
26 void View_Viewer::CreateView()
27 {
28   if (myView.IsNull())
29     myView = myContext->CurrentViewer()->CreateView();
30 }
31
32 // =======================================================================
33 // function : CreateView
34 // purpose :
35 // =======================================================================
36 void View_Viewer::SetWindow(const Handle(Aspect_Window)& theWindow)
37 {
38   myView->SetWindow (theWindow);
39   if (!theWindow->IsMapped())
40     theWindow->Map();
41 }
42
43 // =======================================================================
44 // function : InitStandardViewer
45 // purpose :
46 // =======================================================================
47 void View_Viewer::InitStandardViewer()
48 {
49   Handle(Aspect_DisplayConnection) aDisplayConnection = new Aspect_DisplayConnection();
50   static Handle(OpenGl_GraphicDriver) aGraphicDriver = new OpenGl_GraphicDriver (aDisplayConnection);
51
52 #if OCC_VERSION_HEX > 0x060901
53   myViewer = new V3d_Viewer (aGraphicDriver);
54 #else
55   TCollection_AsciiString a3DName ("Visu3D");
56   myViewer = new V3d_Viewer (aGraphicDriver, a3DName.ToExtString(), "", 1000.0, V3d_XposYnegZpos, Quantity_NOC_GRAY30,
57                              V3d_ZBUFFER, V3d_GOURAUD, V3d_WAIT, Standard_True, Standard_False);
58 #endif
59
60   myViewer->SetDefaultLights();
61   myViewer->SetLightOn();
62   myViewer->SetDefaultBackgroundColor (Quantity_NOC_GRAY30);
63
64   myContext = new AIS_InteractiveContext (myViewer);
65   myContext->UpdateCurrentViewer();
66 }