-// Copyright (c) 1999-2012 OPEN CASCADE SAS
+// Copyright (c) 1999-2014 OPEN CASCADE SAS
//
-// The content of this file is subject to the Open CASCADE Technology Public
-// License Version 6.5 (the "License"). You may not use the content of this file
-// except in compliance with the License. Please obtain a copy of the License
-// at http://www.opencascade.org and read it completely before using this file.
+// This file is part of Open CASCADE Technology software library.
//
-// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
-// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
+// This library is free software; you can redistribute it and/or modify it under
+// the terms of the GNU Lesser General Public License version 2.1 as published
+// by the Free Software Foundation, with special exception defined in the file
+// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
+// distribution for complete text of the license and disclaimer of any warranty.
//
-// The Original Code and all software distributed under the License is
-// distributed on an "AS IS" basis, without warranty of any kind, and the
-// Initial Developer hereby disclaims all such warranties, including without
-// limitation, any warranties of merchantability, fitness for a particular
-// purpose or non-infringement. Please see the License for the specific terms
-// and conditions governing the rights and limitations under the License.
-
-/***********************************************************************
-
- FONCTION :
- ----------
- Classe V3d_Viewer :
-
- HISTORIQUE DES MODIFICATIONS :
- --------------------------------
- 00-09-92 : GG ; Creation.
- 15-11-97 : FMN ; Ajout texture mapping
- 02-02-98 : FMN ; Mise a niveau WNT
- 23-02-98 : FMN ; Remplacement PI par Standard_PI
- 16-07-98 : CAL ; S3892. Ajout grilles 3d.
-
-************************************************************************/
-
-#define GER61351 //GG_15/12/99 Adds SetDefaultBackgroundColor()
-// and DefaultBackgroundColor() methods
-
-#define IMP240100 //GG
-// Initalize grid echo fields
-
-/*----------------------------------------------------------------------*/
-/*
- * Includes
- */
-
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
+
+
+#include <Aspect_Background.hxx>
+#include <Aspect_GradientBackground.hxx>
+#include <Aspect_Grid.hxx>
+#include <Aspect_IdentDefinitionError.hxx>
+#include <gp_Ax3.hxx>
+#include <Graphic3d_AspectMarker3d.hxx>
+#include <Graphic3d_GraphicDriver.hxx>
+#include <Graphic3d_Group.hxx>
+#include <Graphic3d_Structure.hxx>
+#include <Quantity_Color.hxx>
+#include <Standard_ErrorHandler.hxx>
+#include <Standard_Type.hxx>
#include <V3d.hxx>
-#include <Visual3d_View.hxx>
-#include <Visual3d_Light.hxx>
-#include <V3d_Viewer.ixx>
+#include <V3d_BadValue.hxx>
+#include <V3d_CircularGrid.hxx>
+#include <V3d_Light.hxx>
+#include <V3d_RectangularGrid.hxx>
#include <V3d_View.hxx>
-#include <Viewer_BadValue.hxx>
-#include <V3d_OrthographicView.hxx>
-#include <V3d_PerspectiveView.hxx>
-#ifdef WNT
-#include <WNT_GraphicDevice.hxx>
-#endif
-
-/*----------------------------------------------------------------------*/
-
-//-Constructor:
-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 )
-:Viewer_Viewer(Device,aName,aDomain,-1),
+#include <V3d_Viewer.hxx>
+
+// ========================================================================
+// function : V3d_Viewer
+// purpose :
+// ========================================================================
+V3d_Viewer::V3d_Viewer (const Handle(Graphic3d_GraphicDriver)& theDriver,
+ const Standard_ExtString theName,
+ const Standard_CString theDomain,
+ const Standard_Real theViewSize,
+ const V3d_TypeOfOrientation theViewProj,
+ const Quantity_NameOfColor theViewBackground,
+ const V3d_TypeOfVisualization theVisualization,
+ const V3d_TypeOfShadingModel theShadingModel,
+ const V3d_TypeOfUpdate theUpdateMode,
+ const Standard_Boolean theComputedMode,
+ const Standard_Boolean theDefaultComputedMode,
+ const V3d_TypeOfSurfaceDetail theSurfaceDetail)
+:myNextCount (-1),
+myDriver (theDriver),
+myName (TCollection_ExtendedString (theName)),
+myDomain (TCollection_AsciiString (theDomain)),
+myStructureManager (new Graphic3d_StructureManager (theDriver)),
MyDefinedViews(),
MyActiveViews(),
MyDefinedLights(),
MyActiveLights(),
-MyDefinedPlanes(),
myActiveViewsIterator(),
myDefinedViewsIterator(),
myActiveLightsIterator(),
myDefinedLightsIterator(),
-myDefinedPlanesIterator(),
-myComputedMode(ComputedMode),
-myDefaultComputedMode(DefaultComputedMode),
-myPrivilegedPlane(gp_Ax3(gp_Pnt(0.,0.,0),gp_Dir(0.,0.,1.),gp_Dir(1.,0.,0.))),
-myDisplayPlane(Standard_False),
-myDisplayPlaneLength(ViewSize)
-#ifdef IMP240100
-,myGridEcho(Standard_True),myGridEchoStructure(),myGridEchoGroup()
-#endif
-{
-
- MyViewer = new Visual3d_ViewManager(Device) ;
- // san (16/09/2010): It has been decided to turn depth test ON
- // by default, as this is important for new font rendering
- // (without it, there are numerous texture rendering artefacts)
- MyViewer->SetZBufferAuto (Standard_False);
- SetUpdateMode( UpdateMode ) ;
- SetDefaultViewSize(ViewSize) ;
- SetDefaultViewProj(ViewProj) ;
- SetDefaultBackgroundColor(ViewBackground) ;
- SetDefaultVisualization(Visualization) ;
- SetDefaultShadingModel(ShadingModel) ;
- SetDefaultSurfaceDetail(SurfaceDetail) ;
- SetDefaultAngle(M_PI / 2.);
- SetDefaultTypeOfView(V3d_ORTHOGRAPHIC);
+myComputedMode (theComputedMode),
+myDefaultComputedMode (theDefaultComputedMode),
+myPrivilegedPlane (gp_Ax3 (gp_Pnt (0.,0.,0), gp_Dir (0.,0.,1.), gp_Dir (1.,0.,0.))),
+myDisplayPlane (Standard_False),
+myDisplayPlaneLength (theViewSize),
+myGridEcho (Standard_True),
+myGridEchoLastVert (ShortRealLast(), ShortRealLast(), ShortRealLast()),
+myZLayerGenId (1, IntegerLast())
+{
+ SetUpdateMode (theUpdateMode);
+ SetDefaultViewSize (theViewSize);
+ SetDefaultViewProj (theViewProj);
+ SetDefaultBackgroundColor (theViewBackground);
+ SetDefaultVisualization (theVisualization);
+ SetDefaultShadingModel (theShadingModel);
+ SetDefaultSurfaceDetail (theSurfaceDetail);
+ SetDefaultAngle (M_PI / 2.);
+ SetDefaultTypeOfView (V3d_ORTHOGRAPHIC);
Quantity_Color Color1 (Quantity_NOC_GRAY50);
Quantity_Color Color2 (Quantity_NOC_GRAY70);
// Quantity_Color White (Quantity_NOC_WHITE);
- myRGrid = new V3d_RectangularGrid(this,Color1,Color2);
- myCGrid = new V3d_CircularGrid(this,Color1,Color2);
+ myRGrid = new V3d_RectangularGrid (this, Color1, Color2);
+ myCGrid = new V3d_CircularGrid (this, Color1, Color2);
myGridType = Aspect_GT_Rectangular;
}
-//-Methods, in order
-
-
-Handle(V3d_View) V3d_Viewer::CreateView () {
- if (MyDefaultTypeOfView == V3d_ORTHOGRAPHIC)
- return new V3d_OrthographicView(this);
- else
- return new V3d_PerspectiveView(this);
-}
-
-void V3d_Viewer::SetViewOn( ) {
-
- for (InitDefinedViews();MoreDefinedViews();NextDefinedViews()){
- SetViewOn(ActiveView());};
-}
-
-Handle(V3d_OrthographicView) V3d_Viewer::DefaultOrthographicView() {
-
- return MyDefaultOrthographicView;
+// ========================================================================
+// function : CreateView
+// purpose :
+// ========================================================================
+Handle(V3d_View) V3d_Viewer::CreateView ()
+{
+ return new V3d_View(this, MyDefaultTypeOfView);
}
-Handle(V3d_PerspectiveView) V3d_Viewer::DefaultPerspectiveView () {
-
- return MyDefaultPerspectiveView;
+// ========================================================================
+// function : SetViewOn
+// purpose :
+// ========================================================================
+void V3d_Viewer::SetViewOn()
+{
+ for (InitDefinedViews();MoreDefinedViews();NextDefinedViews())
+ {
+ SetViewOn (ActiveView());
+ }
}
-void V3d_Viewer::SetViewOff( ) {
-
- for (InitDefinedViews();MoreDefinedViews();NextDefinedViews()){
- SetViewOff(ActiveView());};
+// ========================================================================
+// function : SetViewOff
+// purpose :
+// ========================================================================
+void V3d_Viewer::SetViewOff()
+{
+ for (InitDefinedViews();MoreDefinedViews();NextDefinedViews())
+ {
+ SetViewOff (ActiveView());
+ }
}
-void V3d_Viewer::SetViewOn( const Handle(V3d_View)& TheView ) {
-
- Handle(Visual3d_View) MyView = TheView->View() ;
- if( MyView->IsDefined() && !IsActive(TheView)) {
- MyActiveViews.Append(TheView) ;
- MyView->Activate();
- for (InitActiveLights();MoreActiveLights();NextActiveLights()){
- TheView->SetLightOn(ActiveLight());}
- // Grid
- TheView->SetGrid (myPrivilegedPlane, Grid ());
- TheView->SetGridActivity (Grid ()->IsActive ());
- // Update
- MyView->Redraw() ;
+// ========================================================================
+// function : SetViewOn
+// purpose :
+// ========================================================================
+void V3d_Viewer::SetViewOn (const Handle(V3d_View)& theView)
+{
+ Handle(Graphic3d_CView) aViewImpl = theView->View();
+ if (aViewImpl->IsDefined() && !IsActive (theView))
+ {
+ MyActiveViews.Append (theView);
+ aViewImpl->Activate();
+ for (InitActiveLights();MoreActiveLights();NextActiveLights())
+ {
+ theView->SetLightOn (ActiveLight());
+ }
+
+ theView->SetGrid (myPrivilegedPlane, Grid ());
+ theView->SetGridActivity (Grid ()->IsActive ());
+ theView->Redraw();
}
}
-void V3d_Viewer::SetViewOff( const Handle(V3d_View)& TheView ) {
-
- Handle(Visual3d_View) MyView =TheView->View();
- if( MyView->IsDefined() && IsActive(TheView) ) {
- MyActiveViews.Remove(TheView);
- MyView->Deactivate() ;
+// ========================================================================
+// function : SetViewOff
+// purpose :
+// ========================================================================
+void V3d_Viewer::SetViewOff (const Handle(V3d_View)& theView)
+{
+ Handle(Graphic3d_CView) aViewImpl = theView->View();
+ if (aViewImpl->IsDefined() && IsActive (theView))
+ {
+ MyActiveViews.Remove (theView);
+ aViewImpl->Deactivate() ;
}
}
-Standard_Boolean V3d_Viewer::ComputedMode() const {
+// ========================================================================
+// function : ComputedMode
+// purpose :
+// ========================================================================
+Standard_Boolean V3d_Viewer::ComputedMode() const
+{
return myComputedMode;
}
-Standard_Boolean V3d_Viewer::DefaultComputedMode() const {
+// ========================================================================
+// function : DefaultComputedMode
+// purpose :
+// ========================================================================
+Standard_Boolean V3d_Viewer::DefaultComputedMode() const
+{
return myDefaultComputedMode;
}
-void V3d_Viewer::Update() {
-
- MyViewer->Update();
+// ========================================================================
+// function : Update
+// purpose :
+// ========================================================================
+void V3d_Viewer::Update()
+{
+ // Redraw() is still here for compatibility with old code.
+ // See comments, the method is deprecated - Redraw() should
+ // be used instead.
+ Redraw();
}
-void V3d_Viewer::Redraw()const {
-
- MyViewer->Redraw();
+// ========================================================================
+// function : Redraw
+// purpose :
+// ========================================================================
+void V3d_Viewer::Redraw()const
+{
+ TColStd_ListIteratorOfListOfTransient anIt (MyDefinedViews);
+ for (; anIt.More(); anIt.Next())
+ {
+ Handle(V3d_View)::DownCast (anIt.Value())->Redraw();
+ }
}
-void V3d_Viewer::Remove() {
+// ========================================================================
+// function : RedrawImmediate
+// purpose :
+// ========================================================================
+void V3d_Viewer::RedrawImmediate() const
+{
+ TColStd_ListIteratorOfListOfTransient anIt (MyDefinedViews);
+ for (; anIt.More(); anIt.Next())
+ {
+ Handle(V3d_View)::DownCast (anIt.Value())->RedrawImmediate();
+ }
+}
- MyViewer->Remove();
+// ========================================================================
+// function : Invalidate
+// purpose :
+// ========================================================================
+void V3d_Viewer::Invalidate() const
+{
+ TColStd_ListIteratorOfListOfTransient anIt (MyDefinedViews);
+ for (; anIt.More(); anIt.Next())
+ {
+ Handle(V3d_View)::DownCast (anIt.Value())->Invalidate();
+ }
}
-void V3d_Viewer::Erase() const {
-
- MyViewer->Erase();
+// ========================================================================
+// function : Remove
+// purpose :
+// ========================================================================
+void V3d_Viewer::Remove()
+{
+ myStructureManager->Remove();
}
-void V3d_Viewer::UnHighlight() const {
+// ========================================================================
+// function : Erase
+// purpose :
+// ========================================================================
+void V3d_Viewer::Erase() const
+{
+ myStructureManager->Erase();
+}
- //FMN MyViewer->UnHighlight();
+// ========================================================================
+// function : UnHighlight
+// purpose :
+// ========================================================================
+void V3d_Viewer::UnHighlight() const
+{
+ myStructureManager->UnHighlight();
}
void V3d_Viewer::SetDefaultBackgroundColor(const Quantity_TypeOfColor Type, const Standard_Real v1, const Standard_Real v2, const Standard_Real v3) {
if( V3 < 0. ) V3 = 0. ; else if( V3 > 1. ) V3 = 1. ;
Quantity_Color C(V1,V2,V3,Type) ;
-#ifdef GER61351
SetDefaultBackgroundColor(C);
-#else
- MyBackground.SetColor(C) ;
-#endif
}
-void V3d_Viewer::SetDefaultBackgroundColor(const Quantity_NameOfColor Name) {
-
+void V3d_Viewer::SetDefaultBackgroundColor(const Quantity_NameOfColor Name)
+{
Quantity_Color C(Name) ;
-#ifdef GER61351
SetDefaultBackgroundColor(C);
-#else
- MyBackground.SetColor(C) ;
-#endif
}
-#ifdef GER61351
-void V3d_Viewer::SetDefaultBackgroundColor(const Quantity_Color &Color) {
-
+void V3d_Viewer::SetDefaultBackgroundColor(const Quantity_Color &Color)
+{
MyBackground.SetColor(Color) ;
}
-#endif
void V3d_Viewer::SetDefaultBgGradientColors( const Quantity_NameOfColor Name1,
const Quantity_NameOfColor Name2,
void V3d_Viewer::SetDefaultViewSize(const Standard_Real Size) {
- Viewer_BadValue_Raise_if( Size <= 0. ,"V3d_Viewer::SetDefaultViewSize, bad size");
+ V3d_BadValue_Raise_if( Size <= 0. ,"V3d_Viewer::SetDefaultViewSize, bad size");
MyViewSize = Size ;
}
MyVisualization = Type ;
}
-void V3d_Viewer::SetZBufferManagment(const Standard_Boolean Automatic) {
- MyViewer->SetZBufferAuto (Automatic);
-}
-Standard_Boolean V3d_Viewer::ZBufferManagment() const {
- return MyViewer->ZBufferAuto();
-}
void V3d_Viewer::SetDefaultShadingModel(const V3d_TypeOfShadingModel Type) {
void V3d_Viewer::SetDefaultTypeOfView(const V3d_TypeOfView Type) {
MyDefaultTypeOfView = Type;}
-
-void V3d_Viewer::SetUpdateMode(const V3d_TypeOfUpdate Mode) {
-
- MyViewer->SetUpdateMode((Aspect_TypeOfUpdate)Mode) ;
+// ========================================================================
+// function : SetUpdateMode
+// purpose :
+// ========================================================================
+void V3d_Viewer::SetUpdateMode (const V3d_TypeOfUpdate theMode)
+{
+ myStructureManager->SetUpdateMode (static_cast<Aspect_TypeOfUpdate> (theMode));
}
-void V3d_Viewer::DefaultBackgroundColor(const Quantity_TypeOfColor Type,Standard_Real &V1,Standard_Real &V2,Standard_Real &V3) const {
-
-#ifdef GER61351
+void V3d_Viewer::DefaultBackgroundColor(const Quantity_TypeOfColor Type,Standard_Real &V1,Standard_Real &V2,Standard_Real &V3) const
+{
Quantity_Color C = DefaultBackgroundColor();
-#else
- Quantity_Color C = MyBackground.Color() ;
-#endif
C.Values(V1,V2,V3,Type) ;
}
-#ifdef GER61351
-Quantity_Color V3d_Viewer::DefaultBackgroundColor() const {
+Quantity_Color V3d_Viewer::DefaultBackgroundColor() const
+{
return MyBackground.Color() ;
}
-#endif
-void V3d_Viewer::DefaultBgGradientColors(Quantity_Color& Color1,Quantity_Color& Color2) const{
+void V3d_Viewer::DefaultBgGradientColors(Quantity_Color& Color1,Quantity_Color& Color2) const
+{
MyGradientBackground.Colors(Color1,Color2);
}
return MyDefaultAngle;
}
-V3d_TypeOfUpdate V3d_Viewer::UpdateMode() const {
-
- V3d_TypeOfUpdate Mode = (V3d_TypeOfUpdate) MyViewer->UpdateMode() ;
- return Mode ;
+// ========================================================================
+// function : UpdateMode
+// purpose :
+// ========================================================================
+V3d_TypeOfUpdate V3d_Viewer::UpdateMode() const
+{
+ return static_cast<V3d_TypeOfUpdate> (myStructureManager->UpdateMode());
}
Standard_Boolean V3d_Viewer::IfMoreViews() const {
Standard_Boolean TheStatus = Standard_False ;
#ifdef NEW
- if( MyActiveViews->Length() < Visual3d_View::Limit() )
+ if (MyActiveViews->Length() < myDriver->InquireViewLimit())
#endif /*NEW*/
TheStatus = Standard_True ;
return TheStatus ;
}
-Handle(Visual3d_ViewManager) V3d_Viewer::Viewer() const {
- return MyViewer ;
+// ========================================================================
+// function : StructureManager
+// purpose :
+// ========================================================================
+Handle(Graphic3d_StructureManager) V3d_Viewer::StructureManager() const
+{
+ return myStructureManager;
}
Aspect_Background V3d_Viewer::GetBackgroundColor() const {
MyDefinedViews.Remove(TheView);
}
-void V3d_Viewer::AddPlane( const Handle(V3d_Plane)& ThePlane ) {
+//=======================================================================
+//function : AddZLayer
+//purpose :
+//=======================================================================
+Standard_Boolean V3d_Viewer::AddZLayer (Standard_Integer& theLayerId)
+{
+ try
+ {
+ OCC_CATCH_SIGNALS
+ theLayerId = myZLayerGenId.Next();
+ }
+ catch (Aspect_IdentDefinitionError)
+ {
+ // new index can't be generated
+ return Standard_False;
+ }
+
+ myLayerIds.Add (theLayerId);
+ myDriver->AddZLayer (theLayerId);
- MyDefinedPlanes.Append(ThePlane) ;
+ return Standard_True;
}
-void V3d_Viewer::DelPlane( const Handle(V3d_Plane)& ThePlane ) {
-
- MyDefinedPlanes.Remove(ThePlane);
+//=======================================================================
+//function : RemoveZLayer
+//purpose :
+//=======================================================================
+Standard_Boolean V3d_Viewer::RemoveZLayer (const Standard_Integer theLayerId)
+{
+ if (!myLayerIds.Contains (theLayerId)
+ || theLayerId < myZLayerGenId.Lower()
+ || theLayerId > myZLayerGenId.Upper())
+ {
+ return Standard_False;
+ }
+
+ myDriver->RemoveZLayer (theLayerId);
+ myLayerIds.Remove (theLayerId);
+ myZLayerGenId.Free (theLayerId);
+
+ return Standard_True;
}
//=======================================================================
-//function : AddZLayer
+//function : GetAllZLayers
//purpose :
//=======================================================================
+void V3d_Viewer::GetAllZLayers (TColStd_SequenceOfInteger& theLayerSeq) const
+{
+ myDriver->ZLayers (theLayerSeq);
+}
-Standard_Boolean V3d_Viewer::AddZLayer (Standard_Integer& theLayerId)
+//=======================================================================
+//function : SetZLayerSettings
+//purpose :
+//=======================================================================
+void V3d_Viewer::SetZLayerSettings (const Standard_Integer theLayerId, const Graphic3d_ZLayerSettings& theSettings)
{
- return MyViewer->AddZLayer (theLayerId);
+ myDriver->SetZLayerSettings (theLayerId, theSettings);
}
//=======================================================================
-//function : RemoveZLayer
-//purpose :
+//function : ZLayerSettings
+//purpose :
//=======================================================================
+Graphic3d_ZLayerSettings V3d_Viewer::ZLayerSettings (const Standard_Integer theLayerId)
+{
+ return myDriver->ZLayerSettings (theLayerId);
+}
-Standard_Boolean V3d_Viewer::RemoveZLayer (const Standard_Integer theLayerId)
+//=======================================================================
+//function : Domain
+//purpose :
+//=======================================================================
+Standard_CString V3d_Viewer::Domain() const
{
- return MyViewer->RemoveZLayer (theLayerId);
+ return myDomain.ToCString();
}
//=======================================================================
-//function : GetAllZLayers
+//function : Driver
//purpose :
//=======================================================================
+const Handle(Graphic3d_GraphicDriver)& V3d_Viewer::Driver() const
+{
+ return myDriver;
+}
-void V3d_Viewer::GetAllZLayers (TColStd_SequenceOfInteger& theLayerSeq) const
+//=======================================================================
+//function : NextName
+//purpose :
+//=======================================================================
+Standard_ExtString V3d_Viewer::NextName() const
+{
+ TCollection_ExtendedString aNextName = TCollection_ExtendedString (myName.ToExtString());
+ aNextName.AssignCat (TCollection_ExtendedString (myNextCount));
+
+ return aNextName.ToExtString();
+}
+
+//=======================================================================
+//function : IncrCount
+//purpose :
+//=======================================================================
+void V3d_Viewer::IncrCount()
+{
+ myNextCount++;
+}
+
+//=======================================================================
+//function : DefaultRenderingParams
+//purpose :
+//=======================================================================
+const Graphic3d_RenderingParams& V3d_Viewer::DefaultRenderingParams() const
+{
+ return myDefaultRenderingParams;
+}
+
+//=======================================================================
+//function : SetDefaultRenderingParams
+//purpose :
+//=======================================================================
+void V3d_Viewer::SetDefaultRenderingParams (const Graphic3d_RenderingParams& theParams)
{
- MyViewer->GetAllZLayers (theLayerSeq);
+ myDefaultRenderingParams = theParams;
}