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 void V3d_Viewer::SetViewOff( ) {
130 for (InitDefinedViews();MoreDefinedViews();NextDefinedViews()){
131 SetViewOff(ActiveView());};
134 void V3d_Viewer::SetViewOn( const Handle(V3d_View)& TheView ) {
136 Handle(Visual3d_View) MyView = TheView->View() ;
137 if( MyView->IsDefined() && !IsActive(TheView)) {
138 MyActiveViews.Append(TheView) ;
140 for (InitActiveLights();MoreActiveLights();NextActiveLights()){
141 TheView->SetLightOn(ActiveLight());}
143 TheView->SetGrid (myPrivilegedPlane, Grid ());
144 TheView->SetGridActivity (Grid ()->IsActive ());
150 void V3d_Viewer::SetViewOff( const Handle(V3d_View)& TheView ) {
152 Handle(Visual3d_View) MyView =TheView->View();
153 if( MyView->IsDefined() && IsActive(TheView) ) {
154 MyActiveViews.Remove(TheView);
155 MyView->Deactivate() ;
159 Standard_Boolean V3d_Viewer::ComputedMode() const {
160 return myComputedMode;
163 Standard_Boolean V3d_Viewer::DefaultComputedMode() const {
164 return myDefaultComputedMode;
167 void V3d_Viewer::Update() {
172 void V3d_Viewer::Redraw()const {
177 void V3d_Viewer::Remove() {
182 void V3d_Viewer::Erase() const {
187 void V3d_Viewer::UnHighlight() const {
189 //FMN MyViewer->UnHighlight();
192 void V3d_Viewer::SetDefaultBackgroundColor(const Quantity_TypeOfColor Type, const Standard_Real v1, const Standard_Real v2, const Standard_Real v3) {
193 Standard_Real V1 = v1 ;
194 Standard_Real V2 = v2 ;
195 Standard_Real V3 = v3 ;
197 if( V1 < 0. ) V1 = 0. ; else if( V1 > 1. ) V1 = 1. ;
198 if( V2 < 0. ) V2 = 0. ; else if( V2 > 1. ) V2 = 1. ;
199 if( V3 < 0. ) V3 = 0. ; else if( V3 > 1. ) V3 = 1. ;
201 Quantity_Color C(V1,V2,V3,Type) ;
202 SetDefaultBackgroundColor(C);
205 void V3d_Viewer::SetDefaultBackgroundColor(const Quantity_NameOfColor Name)
207 Quantity_Color C(Name) ;
208 SetDefaultBackgroundColor(C);
211 void V3d_Viewer::SetDefaultBackgroundColor(const Quantity_Color &Color)
213 MyBackground.SetColor(Color) ;
216 void V3d_Viewer::SetDefaultBgGradientColors( const Quantity_NameOfColor Name1,
217 const Quantity_NameOfColor Name2,
218 const Aspect_GradientFillMethod FillStyle){
220 Quantity_Color C1(Name1) ;
221 Quantity_Color C2(Name2) ;
222 MyGradientBackground.SetColors(C1, C2, FillStyle);
226 void V3d_Viewer::SetDefaultBgGradientColors( const Quantity_Color& Color1,
227 const Quantity_Color& Color2,
228 const Aspect_GradientFillMethod FillStyle ){
230 MyGradientBackground.SetColors(Color1, Color2, FillStyle);
235 void V3d_Viewer::SetDefaultViewSize(const Standard_Real Size) {
237 V3d_BadValue_Raise_if( Size <= 0. ,"V3d_Viewer::SetDefaultViewSize, bad size");
241 void V3d_Viewer::SetDefaultViewProj(const V3d_TypeOfOrientation Orientation) {
243 MyViewProj = Orientation ;
246 void V3d_Viewer::SetDefaultVisualization(const V3d_TypeOfVisualization Type) {
248 MyVisualization = Type ;
250 void V3d_Viewer::SetZBufferManagment(const Standard_Boolean Automatic) {
251 MyViewer->SetZBufferAuto (Automatic);
253 Standard_Boolean V3d_Viewer::ZBufferManagment() const {
254 return MyViewer->ZBufferAuto();
257 void V3d_Viewer::SetDefaultShadingModel(const V3d_TypeOfShadingModel Type) {
259 MyShadingModel = Type ;
262 void V3d_Viewer::SetDefaultSurfaceDetail(const V3d_TypeOfSurfaceDetail Type) {
264 MySurfaceDetail = Type ;
267 void V3d_Viewer::SetDefaultAngle(const Quantity_PlaneAngle Angle) {
268 MyDefaultAngle = Angle;
271 void V3d_Viewer::SetDefaultTypeOfView(const V3d_TypeOfView Type) {
272 MyDefaultTypeOfView = Type;}
275 void V3d_Viewer::SetUpdateMode(const V3d_TypeOfUpdate Mode) {
277 MyViewer->SetUpdateMode((Aspect_TypeOfUpdate)Mode) ;
280 void V3d_Viewer::DefaultBackgroundColor(const Quantity_TypeOfColor Type,Standard_Real &V1,Standard_Real &V2,Standard_Real &V3) const
282 Quantity_Color C = DefaultBackgroundColor();
283 C.Values(V1,V2,V3,Type) ;
286 Quantity_Color V3d_Viewer::DefaultBackgroundColor() const
288 return MyBackground.Color() ;
291 void V3d_Viewer::DefaultBgGradientColors(Quantity_Color& Color1,Quantity_Color& Color2) const
293 MyGradientBackground.Colors(Color1,Color2);
296 Standard_Real V3d_Viewer::DefaultViewSize() const {
300 V3d_TypeOfOrientation V3d_Viewer::DefaultViewProj() const {
304 V3d_TypeOfVisualization V3d_Viewer::DefaultVisualization() const {
305 return MyVisualization ;
308 V3d_TypeOfShadingModel V3d_Viewer::DefaultShadingModel() const {
309 return MyShadingModel ;
312 V3d_TypeOfSurfaceDetail V3d_Viewer::DefaultSurfaceDetail() const {
313 return MySurfaceDetail ;
316 Quantity_PlaneAngle V3d_Viewer::DefaultAngle() const {
317 return MyDefaultAngle;
320 V3d_TypeOfUpdate V3d_Viewer::UpdateMode() const {
322 V3d_TypeOfUpdate Mode = (V3d_TypeOfUpdate) MyViewer->UpdateMode() ;
326 Standard_Boolean V3d_Viewer::IfMoreViews() const {
327 Standard_Boolean TheStatus = Standard_False ;
330 if( MyActiveViews->Length() < Visual3d_View::Limit() )
332 TheStatus = Standard_True ;
336 Handle(Visual3d_ViewManager) V3d_Viewer::Viewer() const {
340 Aspect_Background V3d_Viewer::GetBackgroundColor() const {
341 return MyBackground ;
344 Aspect_GradientBackground V3d_Viewer::GetGradientBackground() const {
345 return MyGradientBackground;
348 void V3d_Viewer::AddView( const Handle(V3d_View)& TheView ) {
350 MyDefinedViews.Append(TheView);
354 void V3d_Viewer::DelView( const Handle(V3d_View)& TheView ) {
356 MyActiveViews.Remove(TheView);
357 MyDefinedViews.Remove(TheView);
360 //=======================================================================
361 //function : AddZLayer
363 //=======================================================================
365 Standard_Boolean V3d_Viewer::AddZLayer (Standard_Integer& theLayerId)
367 return MyViewer->AddZLayer (theLayerId);
370 //=======================================================================
371 //function : RemoveZLayer
373 //=======================================================================
375 Standard_Boolean V3d_Viewer::RemoveZLayer (const Standard_Integer theLayerId)
377 return MyViewer->RemoveZLayer (theLayerId);
380 //=======================================================================
381 //function : GetAllZLayers
383 //=======================================================================
385 void V3d_Viewer::GetAllZLayers (TColStd_SequenceOfInteger& theLayerSeq) const
387 MyViewer->GetAllZLayers (theLayerSeq);
390 //=======================================================================
393 //=======================================================================
395 Standard_CString V3d_Viewer::Domain() const
397 return myDomain.ToCString();
400 //=======================================================================
403 //=======================================================================
405 const Handle(Graphic3d_GraphicDriver)& V3d_Viewer::Driver() const
410 //=======================================================================
411 //function : NextName
413 //=======================================================================
415 Standard_ExtString V3d_Viewer::NextName() const
417 TCollection_ExtendedString aNextName = TCollection_ExtendedString (myName.ToExtString());
418 aNextName.AssignCat (TCollection_ExtendedString (myNextCount));
420 return aNextName.ToExtString();
423 //=======================================================================
424 //function : IncrCount
426 //=======================================================================
428 void V3d_Viewer::IncrCount()