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 #define GER61351 //GG_15/12/99 Adds SetDefaultBackgroundColor()
35 // and DefaultBackgroundColor() methods
37 #define IMP240100 //GG
38 // Initalize grid echo fields
40 /*----------------------------------------------------------------------*/
46 #include <Visual3d_View.hxx>
47 #include <Visual3d_Light.hxx>
48 #include <V3d_Viewer.ixx>
49 #include <V3d_View.hxx>
50 #include <Viewer_BadValue.hxx>
51 #include <V3d_OrthographicView.hxx>
52 #include <V3d_PerspectiveView.hxx>
54 #include <WNT_GraphicDevice.hxx>
57 /*----------------------------------------------------------------------*/
60 V3d_Viewer::V3d_Viewer(const Handle(Aspect_GraphicDevice)& Device , 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 )
61 :Viewer_Viewer(Device,aName,aDomain,-1),
67 myActiveViewsIterator(),
68 myDefinedViewsIterator(),
69 myActiveLightsIterator(),
70 myDefinedLightsIterator(),
71 myDefinedPlanesIterator(),
72 myComputedMode(ComputedMode),
73 myDefaultComputedMode(DefaultComputedMode),
74 myPrivilegedPlane(gp_Ax3(gp_Pnt(0.,0.,0),gp_Dir(0.,0.,1.),gp_Dir(1.,0.,0.))),
75 myDisplayPlane(Standard_False),
76 myDisplayPlaneLength(ViewSize)
78 ,myGridEcho(Standard_True),myGridEchoStructure(),myGridEchoGroup()
82 MyViewer = new Visual3d_ViewManager(Device) ;
83 // san (16/09/2010): It has been decided to turn depth test ON
84 // by default, as this is important for new font rendering
85 // (without it, there are numerous texture rendering artefacts)
86 MyViewer->SetZBufferAuto (Standard_False);
87 SetUpdateMode( UpdateMode ) ;
88 SetDefaultViewSize(ViewSize) ;
89 SetDefaultViewProj(ViewProj) ;
90 SetDefaultBackgroundColor(ViewBackground) ;
91 SetDefaultVisualization(Visualization) ;
92 SetDefaultShadingModel(ShadingModel) ;
93 SetDefaultSurfaceDetail(SurfaceDetail) ;
94 SetDefaultAngle(M_PI / 2.);
95 SetDefaultTypeOfView(V3d_ORTHOGRAPHIC);
97 Quantity_Color Color1 (Quantity_NOC_GRAY50);
98 Quantity_Color Color2 (Quantity_NOC_GRAY70);
99 // Quantity_Color White (Quantity_NOC_WHITE);
100 myRGrid = new V3d_RectangularGrid(this,Color1,Color2);
101 myCGrid = new V3d_CircularGrid(this,Color1,Color2);
102 myGridType = Aspect_GT_Rectangular;
108 Handle(V3d_View) V3d_Viewer::CreateView () {
109 if (MyDefaultTypeOfView == V3d_ORTHOGRAPHIC)
110 return new V3d_OrthographicView(this);
112 return new V3d_PerspectiveView(this);
115 void V3d_Viewer::SetViewOn( ) {
117 for (InitDefinedViews();MoreDefinedViews();NextDefinedViews()){
118 SetViewOn(ActiveView());};
121 Handle(V3d_OrthographicView) V3d_Viewer::DefaultOrthographicView() {
123 return MyDefaultOrthographicView;
126 Handle(V3d_PerspectiveView) V3d_Viewer::DefaultPerspectiveView () {
128 return MyDefaultPerspectiveView;
131 void V3d_Viewer::SetViewOff( ) {
133 for (InitDefinedViews();MoreDefinedViews();NextDefinedViews()){
134 SetViewOff(ActiveView());};
137 void V3d_Viewer::SetViewOn( const Handle(V3d_View)& TheView ) {
139 Handle(Visual3d_View) MyView = TheView->View() ;
140 if( MyView->IsDefined() && !IsActive(TheView)) {
141 MyActiveViews.Append(TheView) ;
143 for (InitActiveLights();MoreActiveLights();NextActiveLights()){
144 TheView->SetLightOn(ActiveLight());}
146 TheView->SetGrid (myPrivilegedPlane, Grid ());
147 TheView->SetGridActivity (Grid ()->IsActive ());
153 void V3d_Viewer::SetViewOff( const Handle(V3d_View)& TheView ) {
155 Handle(Visual3d_View) MyView =TheView->View();
156 if( MyView->IsDefined() && IsActive(TheView) ) {
157 MyActiveViews.Remove(TheView);
158 MyView->Deactivate() ;
162 Standard_Boolean V3d_Viewer::ComputedMode() const {
163 return myComputedMode;
166 Standard_Boolean V3d_Viewer::DefaultComputedMode() const {
167 return myDefaultComputedMode;
170 void V3d_Viewer::Update() {
175 void V3d_Viewer::Redraw()const {
180 void V3d_Viewer::Remove() {
185 void V3d_Viewer::Erase() const {
190 void V3d_Viewer::UnHighlight() const {
192 //FMN MyViewer->UnHighlight();
195 void V3d_Viewer::SetDefaultBackgroundColor(const Quantity_TypeOfColor Type, const Standard_Real v1, const Standard_Real v2, const Standard_Real v3) {
196 Standard_Real V1 = v1 ;
197 Standard_Real V2 = v2 ;
198 Standard_Real V3 = v3 ;
200 if( V1 < 0. ) V1 = 0. ; else if( V1 > 1. ) V1 = 1. ;
201 if( V2 < 0. ) V2 = 0. ; else if( V2 > 1. ) V2 = 1. ;
202 if( V3 < 0. ) V3 = 0. ; else if( V3 > 1. ) V3 = 1. ;
204 Quantity_Color C(V1,V2,V3,Type) ;
206 SetDefaultBackgroundColor(C);
208 MyBackground.SetColor(C) ;
212 void V3d_Viewer::SetDefaultBackgroundColor(const Quantity_NameOfColor Name) {
214 Quantity_Color C(Name) ;
216 SetDefaultBackgroundColor(C);
218 MyBackground.SetColor(C) ;
223 void V3d_Viewer::SetDefaultBackgroundColor(const Quantity_Color &Color) {
225 MyBackground.SetColor(Color) ;
229 void V3d_Viewer::SetDefaultBgGradientColors( const Quantity_NameOfColor Name1,
230 const Quantity_NameOfColor Name2,
231 const Aspect_GradientFillMethod FillStyle){
233 Quantity_Color C1(Name1) ;
234 Quantity_Color C2(Name2) ;
235 MyGradientBackground.SetColors(C1, C2, FillStyle);
239 void V3d_Viewer::SetDefaultBgGradientColors( const Quantity_Color& Color1,
240 const Quantity_Color& Color2,
241 const Aspect_GradientFillMethod FillStyle ){
243 MyGradientBackground.SetColors(Color1, Color2, FillStyle);
248 void V3d_Viewer::SetDefaultViewSize(const Standard_Real Size) {
250 Viewer_BadValue_Raise_if( Size <= 0. ,"V3d_Viewer::SetDefaultViewSize, bad size");
254 void V3d_Viewer::SetDefaultViewProj(const V3d_TypeOfOrientation Orientation) {
256 MyViewProj = Orientation ;
259 void V3d_Viewer::SetDefaultVisualization(const V3d_TypeOfVisualization Type) {
261 MyVisualization = Type ;
263 void V3d_Viewer::SetZBufferManagment(const Standard_Boolean Automatic) {
264 MyViewer->SetZBufferAuto (Automatic);
266 Standard_Boolean V3d_Viewer::ZBufferManagment() const {
267 return MyViewer->ZBufferAuto();
270 void V3d_Viewer::SetDefaultShadingModel(const V3d_TypeOfShadingModel Type) {
272 MyShadingModel = Type ;
275 void V3d_Viewer::SetDefaultSurfaceDetail(const V3d_TypeOfSurfaceDetail Type) {
277 MySurfaceDetail = Type ;
280 void V3d_Viewer::SetDefaultAngle(const Quantity_PlaneAngle Angle) {
281 MyDefaultAngle = Angle;
284 void V3d_Viewer::SetDefaultTypeOfView(const V3d_TypeOfView Type) {
285 MyDefaultTypeOfView = Type;}
288 void V3d_Viewer::SetUpdateMode(const V3d_TypeOfUpdate Mode) {
290 MyViewer->SetUpdateMode((Aspect_TypeOfUpdate)Mode) ;
293 void V3d_Viewer::DefaultBackgroundColor(const Quantity_TypeOfColor Type,Standard_Real &V1,Standard_Real &V2,Standard_Real &V3) const {
296 Quantity_Color C = DefaultBackgroundColor();
298 Quantity_Color C = MyBackground.Color() ;
300 C.Values(V1,V2,V3,Type) ;
304 Quantity_Color V3d_Viewer::DefaultBackgroundColor() const {
305 return MyBackground.Color() ;
309 void V3d_Viewer::DefaultBgGradientColors(Quantity_Color& Color1,Quantity_Color& Color2) const{
310 MyGradientBackground.Colors(Color1,Color2);
313 Standard_Real V3d_Viewer::DefaultViewSize() const {
317 V3d_TypeOfOrientation V3d_Viewer::DefaultViewProj() const {
321 V3d_TypeOfVisualization V3d_Viewer::DefaultVisualization() const {
322 return MyVisualization ;
325 V3d_TypeOfShadingModel V3d_Viewer::DefaultShadingModel() const {
326 return MyShadingModel ;
329 V3d_TypeOfSurfaceDetail V3d_Viewer::DefaultSurfaceDetail() const {
330 return MySurfaceDetail ;
333 Quantity_PlaneAngle V3d_Viewer::DefaultAngle() const {
334 return MyDefaultAngle;
337 V3d_TypeOfUpdate V3d_Viewer::UpdateMode() const {
339 V3d_TypeOfUpdate Mode = (V3d_TypeOfUpdate) MyViewer->UpdateMode() ;
343 Standard_Boolean V3d_Viewer::IfMoreViews() const {
344 Standard_Boolean TheStatus = Standard_False ;
347 if( MyActiveViews->Length() < Visual3d_View::Limit() )
349 TheStatus = Standard_True ;
353 Handle(Visual3d_ViewManager) V3d_Viewer::Viewer() const {
357 Aspect_Background V3d_Viewer::GetBackgroundColor() const {
358 return MyBackground ;
361 Aspect_GradientBackground V3d_Viewer::GetGradientBackground() const {
362 return MyGradientBackground;
365 void V3d_Viewer::AddView( const Handle(V3d_View)& TheView ) {
367 MyDefinedViews.Append(TheView);
371 void V3d_Viewer::DelView( const Handle(V3d_View)& TheView ) {
373 MyActiveViews.Remove(TheView);
374 MyDefinedViews.Remove(TheView);
377 void V3d_Viewer::AddPlane( const Handle(V3d_Plane)& ThePlane ) {
379 MyDefinedPlanes.Append(ThePlane) ;
382 void V3d_Viewer::DelPlane( const Handle(V3d_Plane)& ThePlane ) {
384 MyDefinedPlanes.Remove(ThePlane);
387 //=======================================================================
388 //function : AddZLayer
390 //=======================================================================
392 Standard_Boolean V3d_Viewer::AddZLayer (Standard_Integer& theLayerId)
394 return MyViewer->AddZLayer (theLayerId);
397 //=======================================================================
398 //function : RemoveZLayer
400 //=======================================================================
402 Standard_Boolean V3d_Viewer::RemoveZLayer (const Standard_Integer theLayerId)
404 return MyViewer->RemoveZLayer (theLayerId);
407 //=======================================================================
408 //function : GetAllZLayers
410 //=======================================================================
412 void V3d_Viewer::GetAllZLayers (TColStd_SequenceOfInteger& theLayerSeq) const
414 MyViewer->GetAllZLayers (theLayerSeq);