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 <V3d_BadValue.hxx>
50 #include <V3d_OrthographicView.hxx>
51 #include <V3d_PerspectiveView.hxx>
53 /*----------------------------------------------------------------------*/
56 V3d_Viewer::V3d_Viewer (const Handle(Graphic3d_GraphicDriver)& theDriver,
57 const Standard_ExtString theName,
58 const Standard_CString theDomain,
59 const Standard_Real theViewSize,
60 const V3d_TypeOfOrientation theViewProj,
61 const Quantity_NameOfColor theViewBackground,
62 const V3d_TypeOfVisualization theVisualization,
63 const V3d_TypeOfShadingModel theShadingModel,
64 const V3d_TypeOfUpdate theUpdateMode,
65 const Standard_Boolean theComputedMode,
66 const Standard_Boolean theDefaultComputedMode,
67 const V3d_TypeOfSurfaceDetail theSurfaceDetail)
70 myName (TCollection_ExtendedString (theName)),
71 myDomain (TCollection_AsciiString (theDomain)),
76 myActiveViewsIterator(),
77 myDefinedViewsIterator(),
78 myActiveLightsIterator(),
79 myDefinedLightsIterator(),
80 myComputedMode (theComputedMode),
81 myDefaultComputedMode (theDefaultComputedMode),
82 myPrivilegedPlane (gp_Ax3 (gp_Pnt (0.,0.,0), gp_Dir (0.,0.,1.), gp_Dir (1.,0.,0.))),
83 myDisplayPlane (Standard_False),
84 myDisplayPlaneLength (theViewSize)
86 ,myGridEcho (Standard_True), myGridEchoStructure(), myGridEchoGroup()
89 MyViewer = new Visual3d_ViewManager (theDriver);
90 // san (16/09/2010): It has been decided to turn depth test ON
91 // by default, as this is important for new font rendering
92 // (without it, there are numerous texture rendering artefacts)
93 MyViewer->SetZBufferAuto (Standard_False);
94 SetUpdateMode (theUpdateMode);
95 SetDefaultViewSize (theViewSize);
96 SetDefaultViewProj (theViewProj);
97 SetDefaultBackgroundColor (theViewBackground);
98 SetDefaultVisualization (theVisualization);
99 SetDefaultShadingModel (theShadingModel);
100 SetDefaultSurfaceDetail (theSurfaceDetail);
101 SetDefaultAngle (M_PI / 2.);
102 SetDefaultTypeOfView (V3d_ORTHOGRAPHIC);
104 Quantity_Color Color1 (Quantity_NOC_GRAY50);
105 Quantity_Color Color2 (Quantity_NOC_GRAY70);
106 // Quantity_Color White (Quantity_NOC_WHITE);
107 myRGrid = new V3d_RectangularGrid (this, Color1, Color2);
108 myCGrid = new V3d_CircularGrid (this, Color1, Color2);
109 myGridType = Aspect_GT_Rectangular;
115 Handle(V3d_View) V3d_Viewer::CreateView () {
116 if (MyDefaultTypeOfView == V3d_ORTHOGRAPHIC)
117 return new V3d_OrthographicView(this);
119 return new V3d_PerspectiveView(this);
122 void V3d_Viewer::SetViewOn( ) {
124 for (InitDefinedViews();MoreDefinedViews();NextDefinedViews()){
125 SetViewOn(ActiveView());};
128 Handle(V3d_OrthographicView) V3d_Viewer::DefaultOrthographicView() {
130 return MyDefaultOrthographicView;
133 Handle(V3d_PerspectiveView) V3d_Viewer::DefaultPerspectiveView () {
135 return MyDefaultPerspectiveView;
138 void V3d_Viewer::SetViewOff( ) {
140 for (InitDefinedViews();MoreDefinedViews();NextDefinedViews()){
141 SetViewOff(ActiveView());};
144 void V3d_Viewer::SetViewOn( const Handle(V3d_View)& TheView ) {
146 Handle(Visual3d_View) MyView = TheView->View() ;
147 if( MyView->IsDefined() && !IsActive(TheView)) {
148 MyActiveViews.Append(TheView) ;
150 for (InitActiveLights();MoreActiveLights();NextActiveLights()){
151 TheView->SetLightOn(ActiveLight());}
153 TheView->SetGrid (myPrivilegedPlane, Grid ());
154 TheView->SetGridActivity (Grid ()->IsActive ());
160 void V3d_Viewer::SetViewOff( const Handle(V3d_View)& TheView ) {
162 Handle(Visual3d_View) MyView =TheView->View();
163 if( MyView->IsDefined() && IsActive(TheView) ) {
164 MyActiveViews.Remove(TheView);
165 MyView->Deactivate() ;
169 Standard_Boolean V3d_Viewer::ComputedMode() const {
170 return myComputedMode;
173 Standard_Boolean V3d_Viewer::DefaultComputedMode() const {
174 return myDefaultComputedMode;
177 void V3d_Viewer::Update() {
182 void V3d_Viewer::Redraw()const {
187 void V3d_Viewer::Remove() {
192 void V3d_Viewer::Erase() const {
197 void V3d_Viewer::UnHighlight() const {
199 //FMN MyViewer->UnHighlight();
202 void V3d_Viewer::SetDefaultBackgroundColor(const Quantity_TypeOfColor Type, const Standard_Real v1, const Standard_Real v2, const Standard_Real v3) {
203 Standard_Real V1 = v1 ;
204 Standard_Real V2 = v2 ;
205 Standard_Real V3 = v3 ;
207 if( V1 < 0. ) V1 = 0. ; else if( V1 > 1. ) V1 = 1. ;
208 if( V2 < 0. ) V2 = 0. ; else if( V2 > 1. ) V2 = 1. ;
209 if( V3 < 0. ) V3 = 0. ; else if( V3 > 1. ) V3 = 1. ;
211 Quantity_Color C(V1,V2,V3,Type) ;
212 SetDefaultBackgroundColor(C);
215 void V3d_Viewer::SetDefaultBackgroundColor(const Quantity_NameOfColor Name)
217 Quantity_Color C(Name) ;
218 SetDefaultBackgroundColor(C);
221 void V3d_Viewer::SetDefaultBackgroundColor(const Quantity_Color &Color)
223 MyBackground.SetColor(Color) ;
226 void V3d_Viewer::SetDefaultBgGradientColors( const Quantity_NameOfColor Name1,
227 const Quantity_NameOfColor Name2,
228 const Aspect_GradientFillMethod FillStyle){
230 Quantity_Color C1(Name1) ;
231 Quantity_Color C2(Name2) ;
232 MyGradientBackground.SetColors(C1, C2, FillStyle);
236 void V3d_Viewer::SetDefaultBgGradientColors( const Quantity_Color& Color1,
237 const Quantity_Color& Color2,
238 const Aspect_GradientFillMethod FillStyle ){
240 MyGradientBackground.SetColors(Color1, Color2, FillStyle);
245 void V3d_Viewer::SetDefaultViewSize(const Standard_Real Size) {
247 V3d_BadValue_Raise_if( Size <= 0. ,"V3d_Viewer::SetDefaultViewSize, bad size");
251 void V3d_Viewer::SetDefaultViewProj(const V3d_TypeOfOrientation Orientation) {
253 MyViewProj = Orientation ;
256 void V3d_Viewer::SetDefaultVisualization(const V3d_TypeOfVisualization Type) {
258 MyVisualization = Type ;
260 void V3d_Viewer::SetZBufferManagment(const Standard_Boolean Automatic) {
261 MyViewer->SetZBufferAuto (Automatic);
263 Standard_Boolean V3d_Viewer::ZBufferManagment() const {
264 return MyViewer->ZBufferAuto();
267 void V3d_Viewer::SetDefaultShadingModel(const V3d_TypeOfShadingModel Type) {
269 MyShadingModel = Type ;
272 void V3d_Viewer::SetDefaultSurfaceDetail(const V3d_TypeOfSurfaceDetail Type) {
274 MySurfaceDetail = Type ;
277 void V3d_Viewer::SetDefaultAngle(const Quantity_PlaneAngle Angle) {
278 MyDefaultAngle = Angle;
281 void V3d_Viewer::SetDefaultTypeOfView(const V3d_TypeOfView Type) {
282 MyDefaultTypeOfView = Type;}
285 void V3d_Viewer::SetUpdateMode(const V3d_TypeOfUpdate Mode) {
287 MyViewer->SetUpdateMode((Aspect_TypeOfUpdate)Mode) ;
290 void V3d_Viewer::DefaultBackgroundColor(const Quantity_TypeOfColor Type,Standard_Real &V1,Standard_Real &V2,Standard_Real &V3) const
292 Quantity_Color C = DefaultBackgroundColor();
293 C.Values(V1,V2,V3,Type) ;
296 Quantity_Color V3d_Viewer::DefaultBackgroundColor() const
298 return MyBackground.Color() ;
301 void V3d_Viewer::DefaultBgGradientColors(Quantity_Color& Color1,Quantity_Color& Color2) const
303 MyGradientBackground.Colors(Color1,Color2);
306 Standard_Real V3d_Viewer::DefaultViewSize() const {
310 V3d_TypeOfOrientation V3d_Viewer::DefaultViewProj() const {
314 V3d_TypeOfVisualization V3d_Viewer::DefaultVisualization() const {
315 return MyVisualization ;
318 V3d_TypeOfShadingModel V3d_Viewer::DefaultShadingModel() const {
319 return MyShadingModel ;
322 V3d_TypeOfSurfaceDetail V3d_Viewer::DefaultSurfaceDetail() const {
323 return MySurfaceDetail ;
326 Quantity_PlaneAngle V3d_Viewer::DefaultAngle() const {
327 return MyDefaultAngle;
330 V3d_TypeOfUpdate V3d_Viewer::UpdateMode() const {
332 V3d_TypeOfUpdate Mode = (V3d_TypeOfUpdate) MyViewer->UpdateMode() ;
336 Standard_Boolean V3d_Viewer::IfMoreViews() const {
337 Standard_Boolean TheStatus = Standard_False ;
340 if( MyActiveViews->Length() < Visual3d_View::Limit() )
342 TheStatus = Standard_True ;
346 Handle(Visual3d_ViewManager) V3d_Viewer::Viewer() const {
350 Aspect_Background V3d_Viewer::GetBackgroundColor() const {
351 return MyBackground ;
354 Aspect_GradientBackground V3d_Viewer::GetGradientBackground() const {
355 return MyGradientBackground;
358 void V3d_Viewer::AddView( const Handle(V3d_View)& TheView ) {
360 MyDefinedViews.Append(TheView);
364 void V3d_Viewer::DelView( const Handle(V3d_View)& TheView ) {
366 MyActiveViews.Remove(TheView);
367 MyDefinedViews.Remove(TheView);
370 //=======================================================================
371 //function : AddZLayer
373 //=======================================================================
375 Standard_Boolean V3d_Viewer::AddZLayer (Standard_Integer& theLayerId)
377 return MyViewer->AddZLayer (theLayerId);
380 //=======================================================================
381 //function : RemoveZLayer
383 //=======================================================================
385 Standard_Boolean V3d_Viewer::RemoveZLayer (const Standard_Integer theLayerId)
387 return MyViewer->RemoveZLayer (theLayerId);
390 //=======================================================================
391 //function : GetAllZLayers
393 //=======================================================================
395 void V3d_Viewer::GetAllZLayers (TColStd_SequenceOfInteger& theLayerSeq) const
397 MyViewer->GetAllZLayers (theLayerSeq);
400 //=======================================================================
403 //=======================================================================
405 Standard_CString V3d_Viewer::Domain() const
407 return myDomain.ToCString();
410 //=======================================================================
413 //=======================================================================
415 const Handle(Graphic3d_GraphicDriver)& V3d_Viewer::Driver() const
420 //=======================================================================
421 //function : NextName
423 //=======================================================================
425 Standard_ExtString V3d_Viewer::NextName() const
427 TCollection_ExtendedString aNextName = TCollection_ExtendedString (myName.ToExtString());
428 aNextName.AssignCat (TCollection_ExtendedString (myNextCount));
430 return aNextName.ToExtString();
433 //=======================================================================
434 //function : IncrCount
436 //=======================================================================
438 void V3d_Viewer::IncrCount()