0024023: Revamp the OCCT Handle - gcc and clang
[occt.git] / src / V3d / V3d_LayerMgr.cxx
1 // Created on: 2008-04-17
2 // Created by: Customer Support
3 // Copyright (c) 2008-2014 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
17 #include <Aspect_ColorScale.hxx>
18 #include <Aspect_Window.hxx>
19 #include <Font_NameOfFont.hxx>
20 #include <Standard_Type.hxx>
21 #include <V3d_ColorScale.hxx>
22 #include <V3d_ColorScaleLayerItem.hxx>
23 #include <V3d_LayerMgr.hxx>
24 #include <V3d_View.hxx>
25 #include <Visual3d_Layer.hxx>
26 #include <Visual3d_View.hxx>
27
28 V3d_LayerMgr::V3d_LayerMgr( const Handle(V3d_View)& AView )
29 : myView(AView.operator->())
30 {
31   Handle(Visual3d_View) theView = View()->View();
32   if ( !theView.IsNull() ) {
33     Handle(Visual3d_ViewManager) theViewMgr = theView->ViewManager();
34     if ( !theViewMgr.IsNull() ) {
35       V3d_LayerMgr* that = (V3d_LayerMgr*)this;
36       that->myOverlay = new Visual3d_Layer( theViewMgr, Aspect_TOL_OVERLAY, Standard_False );
37     }
38   }
39 }
40
41 void V3d_LayerMgr::Compute()
42 {
43   if (Begin())
44   {
45     Redraw();
46     End();
47   }
48 }
49
50 void V3d_LayerMgr::Resized()
51 {
52   Compute();
53 }
54
55 void V3d_LayerMgr::ColorScaleDisplay()
56 {
57   if (ColorScaleIsDisplayed())
58     return;
59   ColorScale();
60   myColorScale->Display();
61   myOverlay->AddLayerItem( myColorScaleLayerItem );
62 }
63
64 void V3d_LayerMgr::ColorScaleErase()
65 {
66   if ( !myColorScale.IsNull() )
67     myColorScale->Erase();
68   myOverlay->RemoveLayerItem( myColorScaleLayerItem );
69 }
70
71 Standard_Boolean V3d_LayerMgr::ColorScaleIsDisplayed() const
72 {
73   return ( myColorScale.IsNull() ? Standard_False : myColorScale->IsDisplayed() );
74 }
75
76 Handle(Aspect_ColorScale) V3d_LayerMgr::ColorScale() const
77 {
78   if ( myColorScale.IsNull() ) {
79     Handle(V3d_LayerMgr) that = this;
80     that->myColorScale = new V3d_ColorScale( this );
81     that->myColorScaleLayerItem = new V3d_ColorScaleLayerItem( that->myColorScale );
82   }
83
84   return Handle(Aspect_ColorScale) (myColorScale);
85 }
86
87 Standard_Boolean V3d_LayerMgr::Begin()
88 {
89   if ( myOverlay.IsNull() )
90     return Standard_False;
91
92   const Handle(Aspect_Window) &theWin = View()->Window();
93   if ( theWin.IsNull() )
94     return Standard_False;
95
96   Standard_Integer aW( 0 ), aH( 0 );
97   theWin->Size( aW, aH );
98
99   myOverlay->Clear();
100   myOverlay->SetViewport( aW, aH ); //szv:!!!
101   myOverlay->Begin();
102   myOverlay->SetTextAttributes( Font_NOF_ASCII_MONO, Aspect_TODT_NORMAL, Quantity_Color() );
103   myOverlay->SetOrtho( 0, Max( aW, aH ), Max( aW, aH ), 0, Aspect_TOC_TOP_LEFT );
104
105   return Standard_True;
106 }
107
108 void V3d_LayerMgr::Redraw()
109 {
110
111 }
112
113 void V3d_LayerMgr::End()
114 {
115   if ( !myOverlay.IsNull() )
116     myOverlay->End();
117 }