1 // Copyright (c) 1999-2012 OPEN CASCADE SAS
3 // The content of this file is subject to the Open CASCADE Technology Public
4 // License Version 6.5 (the "License"). You may not use the content of this file
5 // except in compliance with the License. Please obtain a copy of the License
6 // at http://www.opencascade.org and read it completely before using this file.
8 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
9 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
11 // The Original Code and all software distributed under the License is
12 // distributed on an "AS IS" basis, without warranty of any kind, and the
13 // Initial Developer hereby disclaims all such warranties, including without
14 // limitation, any warranties of merchantability, fitness for a particular
15 // purpose or non-infringement. Please see the License for the specific terms
16 // and conditions governing the rights and limitations under the License.
18 /***********************************************************************
24 HISTORIQUE DES MODIFICATIONS :
25 --------------------------------
26 00-09-92 : GG ; Creation.
27 15-11-97 : FMN ; Ajout texture mapping
28 02-02-98 : FMN ; Mise a niveau WNT
29 23-02-98 : FMN ; Remplacement PI par Standard_PI
30 16-07-98 : CAL ; S3892. Ajout grilles 3d.
32 ************************************************************************/
34 //GER61351 //GG_15/12/99 Adds SetDefaultBackgroundColor() and DefaultBackgroundColor() methods
36 #define IMP240100 //GG
37 // Initalize grid echo fields
39 /*----------------------------------------------------------------------*/
45 #include <Visual3d_View.hxx>
46 #include <Visual3d_Light.hxx>
47 #include <V3d_Viewer.ixx>
48 #include <V3d_View.hxx>
49 #include <Viewer_BadValue.hxx>
50 #include <V3d_OrthographicView.hxx>
51 #include <V3d_PerspectiveView.hxx>
53 /*----------------------------------------------------------------------*/
56 V3d_Viewer::V3d_Viewer(const Handle(Graphic3d_GraphicDriver)& theDriver , const Standard_ExtString aName, const Standard_CString aDomain,const Standard_Real ViewSize , const V3d_TypeOfOrientation ViewProj , const Quantity_NameOfColor ViewBackground , const V3d_TypeOfVisualization Visualization , const V3d_TypeOfShadingModel ShadingModel , const V3d_TypeOfUpdate UpdateMode, const Standard_Boolean ComputedMode , const Standard_Boolean DefaultComputedMode , const V3d_TypeOfSurfaceDetail SurfaceDetail )
57 :Viewer_Viewer(theDriver,aName,aDomain,-1),
63 myActiveViewsIterator(),
64 myDefinedViewsIterator(),
65 myActiveLightsIterator(),
66 myDefinedLightsIterator(),
67 myDefinedPlanesIterator(),
68 myComputedMode(ComputedMode),
69 myDefaultComputedMode(DefaultComputedMode),
70 myPrivilegedPlane(gp_Ax3(gp_Pnt(0.,0.,0),gp_Dir(0.,0.,1.),gp_Dir(1.,0.,0.))),
71 myDisplayPlane(Standard_False),
72 myDisplayPlaneLength(ViewSize)
74 ,myGridEcho(Standard_True),myGridEchoStructure(),myGridEchoGroup()
78 MyViewer = new Visual3d_ViewManager(theDriver) ;
79 // san (16/09/2010): It has been decided to turn depth test ON
80 // by default, as this is important for new font rendering
81 // (without it, there are numerous texture rendering artefacts)
82 MyViewer->SetZBufferAuto (Standard_False);
83 SetUpdateMode( UpdateMode ) ;
84 SetDefaultViewSize(ViewSize) ;
85 SetDefaultViewProj(ViewProj) ;
86 SetDefaultBackgroundColor(ViewBackground) ;
87 SetDefaultVisualization(Visualization) ;
88 SetDefaultShadingModel(ShadingModel) ;
89 SetDefaultSurfaceDetail(SurfaceDetail) ;
90 SetDefaultAngle(M_PI / 2.);
91 SetDefaultTypeOfView(V3d_ORTHOGRAPHIC);
93 Quantity_Color Color1 (Quantity_NOC_GRAY50);
94 Quantity_Color Color2 (Quantity_NOC_GRAY70);
95 // Quantity_Color White (Quantity_NOC_WHITE);
96 myRGrid = new V3d_RectangularGrid(this,Color1,Color2);
97 myCGrid = new V3d_CircularGrid(this,Color1,Color2);
98 myGridType = Aspect_GT_Rectangular;
104 Handle(V3d_View) V3d_Viewer::CreateView () {
105 if (MyDefaultTypeOfView == V3d_ORTHOGRAPHIC)
106 return new V3d_OrthographicView(this);
108 return new V3d_PerspectiveView(this);
111 void V3d_Viewer::SetViewOn( ) {
113 for (InitDefinedViews();MoreDefinedViews();NextDefinedViews()){
114 SetViewOn(ActiveView());};
117 Handle(V3d_OrthographicView) V3d_Viewer::DefaultOrthographicView() {
119 return MyDefaultOrthographicView;
122 Handle(V3d_PerspectiveView) V3d_Viewer::DefaultPerspectiveView () {
124 return MyDefaultPerspectiveView;
127 void V3d_Viewer::SetViewOff( ) {
129 for (InitDefinedViews();MoreDefinedViews();NextDefinedViews()){
130 SetViewOff(ActiveView());};
133 void V3d_Viewer::SetViewOn( const Handle(V3d_View)& TheView ) {
135 Handle(Visual3d_View) MyView = TheView->View() ;
136 if( MyView->IsDefined() && !IsActive(TheView)) {
137 MyActiveViews.Append(TheView) ;
139 for (InitActiveLights();MoreActiveLights();NextActiveLights()){
140 TheView->SetLightOn(ActiveLight());}
142 TheView->SetGrid (myPrivilegedPlane, Grid ());
143 TheView->SetGridActivity (Grid ()->IsActive ());
149 void V3d_Viewer::SetViewOff( const Handle(V3d_View)& TheView ) {
151 Handle(Visual3d_View) MyView =TheView->View();
152 if( MyView->IsDefined() && IsActive(TheView) ) {
153 MyActiveViews.Remove(TheView);
154 MyView->Deactivate() ;
158 Standard_Boolean V3d_Viewer::ComputedMode() const {
159 return myComputedMode;
162 Standard_Boolean V3d_Viewer::DefaultComputedMode() const {
163 return myDefaultComputedMode;
166 void V3d_Viewer::Update() {
171 void V3d_Viewer::Redraw()const {
176 void V3d_Viewer::Remove() {
181 void V3d_Viewer::Erase() const {
186 void V3d_Viewer::UnHighlight() const {
188 //FMN MyViewer->UnHighlight();
191 void V3d_Viewer::SetDefaultBackgroundColor(const Quantity_TypeOfColor Type, const Standard_Real v1, const Standard_Real v2, const Standard_Real v3) {
192 Standard_Real V1 = v1 ;
193 Standard_Real V2 = v2 ;
194 Standard_Real V3 = v3 ;
196 if( V1 < 0. ) V1 = 0. ; else if( V1 > 1. ) V1 = 1. ;
197 if( V2 < 0. ) V2 = 0. ; else if( V2 > 1. ) V2 = 1. ;
198 if( V3 < 0. ) V3 = 0. ; else if( V3 > 1. ) V3 = 1. ;
200 Quantity_Color C(V1,V2,V3,Type) ;
201 SetDefaultBackgroundColor(C);
204 void V3d_Viewer::SetDefaultBackgroundColor(const Quantity_NameOfColor Name)
206 Quantity_Color C(Name) ;
207 SetDefaultBackgroundColor(C);
210 void V3d_Viewer::SetDefaultBackgroundColor(const Quantity_Color &Color)
212 MyBackground.SetColor(Color) ;
215 void V3d_Viewer::SetDefaultBgGradientColors( const Quantity_NameOfColor Name1,
216 const Quantity_NameOfColor Name2,
217 const Aspect_GradientFillMethod FillStyle){
219 Quantity_Color C1(Name1) ;
220 Quantity_Color C2(Name2) ;
221 MyGradientBackground.SetColors(C1, C2, FillStyle);
225 void V3d_Viewer::SetDefaultBgGradientColors( const Quantity_Color& Color1,
226 const Quantity_Color& Color2,
227 const Aspect_GradientFillMethod FillStyle ){
229 MyGradientBackground.SetColors(Color1, Color2, FillStyle);
234 void V3d_Viewer::SetDefaultViewSize(const Standard_Real Size) {
236 Viewer_BadValue_Raise_if( Size <= 0. ,"V3d_Viewer::SetDefaultViewSize, bad size");
240 void V3d_Viewer::SetDefaultViewProj(const V3d_TypeOfOrientation Orientation) {
242 MyViewProj = Orientation ;
245 void V3d_Viewer::SetDefaultVisualization(const V3d_TypeOfVisualization Type) {
247 MyVisualization = Type ;
249 void V3d_Viewer::SetZBufferManagment(const Standard_Boolean Automatic) {
250 MyViewer->SetZBufferAuto (Automatic);
252 Standard_Boolean V3d_Viewer::ZBufferManagment() const {
253 return MyViewer->ZBufferAuto();
256 void V3d_Viewer::SetDefaultShadingModel(const V3d_TypeOfShadingModel Type) {
258 MyShadingModel = Type ;
261 void V3d_Viewer::SetDefaultSurfaceDetail(const V3d_TypeOfSurfaceDetail Type) {
263 MySurfaceDetail = Type ;
266 void V3d_Viewer::SetDefaultAngle(const Quantity_PlaneAngle Angle) {
267 MyDefaultAngle = Angle;
270 void V3d_Viewer::SetDefaultTypeOfView(const V3d_TypeOfView Type) {
271 MyDefaultTypeOfView = Type;}
274 void V3d_Viewer::SetUpdateMode(const V3d_TypeOfUpdate Mode) {
276 MyViewer->SetUpdateMode((Aspect_TypeOfUpdate)Mode) ;
279 void V3d_Viewer::DefaultBackgroundColor(const Quantity_TypeOfColor Type,Standard_Real &V1,Standard_Real &V2,Standard_Real &V3) const
281 Quantity_Color C = DefaultBackgroundColor();
282 C.Values(V1,V2,V3,Type) ;
285 Quantity_Color V3d_Viewer::DefaultBackgroundColor() const
287 return MyBackground.Color() ;
290 void V3d_Viewer::DefaultBgGradientColors(Quantity_Color& Color1,Quantity_Color& Color2) const
292 MyGradientBackground.Colors(Color1,Color2);
295 Standard_Real V3d_Viewer::DefaultViewSize() const {
299 V3d_TypeOfOrientation V3d_Viewer::DefaultViewProj() const {
303 V3d_TypeOfVisualization V3d_Viewer::DefaultVisualization() const {
304 return MyVisualization ;
307 V3d_TypeOfShadingModel V3d_Viewer::DefaultShadingModel() const {
308 return MyShadingModel ;
311 V3d_TypeOfSurfaceDetail V3d_Viewer::DefaultSurfaceDetail() const {
312 return MySurfaceDetail ;
315 Quantity_PlaneAngle V3d_Viewer::DefaultAngle() const {
316 return MyDefaultAngle;
319 V3d_TypeOfUpdate V3d_Viewer::UpdateMode() const {
321 V3d_TypeOfUpdate Mode = (V3d_TypeOfUpdate) MyViewer->UpdateMode() ;
325 Standard_Boolean V3d_Viewer::IfMoreViews() const {
326 Standard_Boolean TheStatus = Standard_False ;
329 if( MyActiveViews->Length() < Visual3d_View::Limit() )
331 TheStatus = Standard_True ;
335 Handle(Visual3d_ViewManager) V3d_Viewer::Viewer() const {
339 Aspect_Background V3d_Viewer::GetBackgroundColor() const {
340 return MyBackground ;
343 Aspect_GradientBackground V3d_Viewer::GetGradientBackground() const {
344 return MyGradientBackground;
347 void V3d_Viewer::AddView( const Handle(V3d_View)& TheView ) {
349 MyDefinedViews.Append(TheView);
353 void V3d_Viewer::DelView( const Handle(V3d_View)& TheView ) {
355 MyActiveViews.Remove(TheView);
356 MyDefinedViews.Remove(TheView);
359 void V3d_Viewer::AddPlane( const Handle(V3d_Plane)& ThePlane ) {
361 MyDefinedPlanes.Append(ThePlane) ;
364 void V3d_Viewer::DelPlane( const Handle(V3d_Plane)& ThePlane ) {
366 MyDefinedPlanes.Remove(ThePlane);
369 //=======================================================================
370 //function : AddZLayer
372 //=======================================================================
374 Standard_Boolean V3d_Viewer::AddZLayer (Standard_Integer& theLayerId)
376 return MyViewer->AddZLayer (theLayerId);
379 //=======================================================================
380 //function : RemoveZLayer
382 //=======================================================================
384 Standard_Boolean V3d_Viewer::RemoveZLayer (const Standard_Integer theLayerId)
386 return MyViewer->RemoveZLayer (theLayerId);
389 //=======================================================================
390 //function : GetAllZLayers
392 //=======================================================================
394 void V3d_Viewer::GetAllZLayers (TColStd_SequenceOfInteger& theLayerSeq) const
396 MyViewer->GetAllZLayers (theLayerSeq);