1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-29 14:00:49 +03:00

0023710: Simplification of presentation managment classes

Merge PrsMgr_Presentation3d into PrsMgr_Presentation
Cosmetics
This commit is contained in:
kgv
2014-04-03 15:33:26 +04:00
committed by apn
parent 4349c10e18
commit af324faa80
20 changed files with 746 additions and 899 deletions

View File

@@ -13,10 +13,387 @@
// commercial license or contractual agreement.
#include <PrsMgr_Presentation.ixx>
#include <PrsMgr_PresentationManager.hxx>
#include <PrsMgr_Prs.hxx>
#include <PrsMgr_ModedPresentation.hxx>
PrsMgr_Presentation::PrsMgr_Presentation
(const Handle(PrsMgr_PresentationManager)& aPresentationManager)
:myPresentationManager(aPresentationManager),myMustBeUpdated(Standard_False) {}
#include <Graphic3d_Structure.hxx>
#include <Visual3d_View.hxx>
#include <Precision.hxx>
void PrsMgr_Presentation::Destroy () {
//=======================================================================
//function : PrsMgr_Presentation
//purpose :
//=======================================================================
PrsMgr_Presentation::PrsMgr_Presentation (const Handle(PrsMgr_PresentationManager3d)& thePrsMgr,
const Handle(PrsMgr_PresentableObject)& thePrsObject)
: myPresentationManager (thePrsMgr),
myPresentableObject (thePrsObject.operator->()),
myMustBeUpdated (Standard_False),
myDisplayReason (Standard_False)
{
myStructure = new PrsMgr_Prs (thePrsMgr->StructureManager(),
this, thePrsObject->TypeOfPresentation3d());
myStructure->SetOwner (myPresentableObject);
}
//=======================================================================
//function : Display
//purpose :
//=======================================================================
void PrsMgr_Presentation::Display()
{
Display (Standard_False);
myDisplayReason = Standard_False;
}
//=======================================================================
//function : Display
//purpose :
//=======================================================================
void PrsMgr_Presentation::Display (const Standard_Boolean theIsHighlight)
{
if (!myStructure->IsDisplayed())
{
myStructure->Display();
myDisplayReason = theIsHighlight;
}
else if (!myStructure->IsVisible())
{
myStructure->SetVisible (Standard_True);
myDisplayReason = theIsHighlight;
}
}
//=======================================================================
//function : Erase
//purpose :
//=======================================================================
void PrsMgr_Presentation::Erase()
{
if (myStructure.IsNull())
{
return;
}
// Erase structure from structure manager
myStructure->Erase();
myStructure->Clear();
// Disconnect other structures
myStructure->DisconnectAll (Graphic3d_TOC_DESCENDANT);
// Clear groups and remove graphic structure
myStructure.Nullify();
}
//=======================================================================
//function : SetVisible
//purpose :
//=======================================================================
void PrsMgr_Presentation::SetVisible (const Standard_Boolean theValue)
{
myStructure->SetVisible (theValue);
}
//=======================================================================
//function : Highlight
//purpose :
//=======================================================================
void PrsMgr_Presentation::Highlight()
{
Display (Standard_True);
myStructure->Highlight();
}
//=======================================================================
//function : Unhighlight
//purpose :
//=======================================================================
void PrsMgr_Presentation::Unhighlight() const
{
myStructure->UnHighlight();
if (myDisplayReason)
{
myStructure->SetVisible (Standard_False);
}
}
//=======================================================================
//function : Clear
//purpose :
//=======================================================================
void PrsMgr_Presentation::Clear()
{
// This modification remove the contain of the structure:
// Consequence:
// 1. The memory zone of the group is reused
// 2. The speed for animation is constant
//myPresentableObject = NULL;
SetUpdateStatus (Standard_True);
if (myStructure.IsNull())
{
return;
}
myStructure->Clear (Standard_True);
// myStructure->Clear(Standard_False);
myStructure->RemoveAll();
}
//=======================================================================
//function : Color
//purpose :
//=======================================================================
void PrsMgr_Presentation::Color (const Quantity_NameOfColor theColor)
{
Display (Standard_True);
myStructure->Color (theColor);
}
//=======================================================================
//function : BoundBox
//purpose :
//=======================================================================
void PrsMgr_Presentation::BoundBox() const
{
myStructure->BoundBox();
}
//=======================================================================
//function : IsDisplayed
//purpose :
//=======================================================================
Standard_Boolean PrsMgr_Presentation::IsDisplayed() const
{
return myStructure->IsDisplayed()
&& myStructure->IsVisible()
&& !myDisplayReason;
}
//=======================================================================
//function : IsHighlighted
//purpose :
//=======================================================================
Standard_Boolean PrsMgr_Presentation::IsHighlighted() const
{
return myStructure->IsHighlighted();
}
//=======================================================================
//function : DisplayPriority
//purpose :
//=======================================================================
Standard_Integer PrsMgr_Presentation::DisplayPriority() const
{
return myStructure->DisplayPriority();
}
//=======================================================================
//function : SetDisplayPriority
//purpose :
//=======================================================================
void PrsMgr_Presentation::SetDisplayPriority (const Standard_Integer theNewPrior)
{
myStructure->SetDisplayPriority (theNewPrior);
}
//=======================================================================
//function : Connect
//purpose :
//=======================================================================
void PrsMgr_Presentation::Connect (const Handle(PrsMgr_Presentation)& theOther) const
{
myStructure->Connect (theOther->Presentation());
}
//=======================================================================
//function : Transform
//purpose :
//=======================================================================
void PrsMgr_Presentation::Transform (const Handle(Geom_Transformation)& theTrsf) const
{
myStructure->Transform (theTrsf);
}
//=======================================================================
//function : Place
//purpose :
//=======================================================================
void PrsMgr_Presentation::Place (const Quantity_Length theX,
const Quantity_Length theY,
const Quantity_Length theZ) const
{
myStructure->Place (theX, theY, theZ);
}
//=======================================================================
//function : Multiply
//purpose :
//=======================================================================
void PrsMgr_Presentation::Multiply (const Handle(Geom_Transformation)& theTrsf) const
{
myStructure->Multiply (theTrsf);
}
//=======================================================================
//function : Move
//purpose :
//=======================================================================
void PrsMgr_Presentation::Move (const Quantity_Length theX,
const Quantity_Length theY,
const Quantity_Length theZ) const
{
myStructure->Move (theX, theY, theZ);
}
//=======================================================================
//function : SetShadingAspect
//purpose :
//=======================================================================
void PrsMgr_Presentation::SetShadingAspect (const Handle(Prs3d_ShadingAspect)& theShadingAspect) const
{
myStructure->SetShadingAspect (theShadingAspect);
}
//=======================================================================
//function : Compute
//purpose : Methods for hidden parts...
//=======================================================================
Handle(Graphic3d_Structure) PrsMgr_Presentation::Compute (const Handle(Graphic3d_DataStructureManager)& theProjector)
{
Handle(Prs3d_Presentation) aPrs = new Prs3d_Presentation (myPresentationManager->StructureManager());
myPresentableObject->Compute (Projector (theProjector), aPrs);
return aPrs;
}
//=======================================================================
//function : Compute
//purpose :
//=======================================================================
void PrsMgr_Presentation::Compute (const Handle(Graphic3d_Structure)& theStructure)
{
Standard_Integer aDispMode = 0;
Standard_Integer aPresentationsNumber = myPresentableObject->myPresentations.Length();
for (Standard_Integer anIter = 1; anIter <= aPresentationsNumber; ++anIter)
{
const PrsMgr_ModedPresentation& aModedPresentation = myPresentableObject->myPresentations.Value (anIter);
if (aModedPresentation.Presentation().operator->() == this)
{
aDispMode = aModedPresentation.Mode();
break;
}
}
Handle(Prs3d_Presentation) aPrs3d = Handle(Prs3d_Presentation)::DownCast (theStructure);
myPresentableObject->Compute (myPresentationManager, aPrs3d, aDispMode);
}
//=======================================================================
//function : Compute
//purpose :
//=======================================================================
void PrsMgr_Presentation::Compute (const Handle(Graphic3d_DataStructureManager)& theProjector,
const Handle(Graphic3d_Structure)& theStructToFill)
{
theStructToFill->Clear();
const Handle(Prs3d_Presentation)& aPrs = *((Handle(Prs3d_Presentation)* )&theStructToFill);
myPresentableObject->Compute (Projector (theProjector), aPrs);
}
//=======================================================================
//function : Compute
//purpose :
//=======================================================================
Handle(Graphic3d_Structure) PrsMgr_Presentation::Compute (const Handle(Graphic3d_DataStructureManager)& theProjector,
const Handle(Geom_Transformation)& theTrsf)
{
Handle(Prs3d_Presentation) aPrs3d = new Prs3d_Presentation (myPresentationManager->StructureManager());
if (theTrsf->Form() == gp_Translation)
{
myPresentableObject->Compute (Projector (theProjector), aPrs3d);
aPrs3d->Transform (theTrsf);
return aPrs3d;
}
// waiting that something is done in gp_Trsf...rob
for (Standard_Integer i = 1; i <= 3; ++i)
{
for (Standard_Integer j = 1; j <= 3; ++j)
{
if (i != j)
{
if (Abs (theTrsf->Value (i, j)) > Precision::Confusion())
{
myPresentableObject->Compute (Projector (theProjector), theTrsf, aPrs3d);
return aPrs3d;
}
}
}
}
myPresentableObject->Compute (Projector (theProjector), aPrs3d);
aPrs3d->Transform (theTrsf);
return aPrs3d;
}
//=======================================================================
//function : Compute
//purpose :
//=======================================================================
void PrsMgr_Presentation::Compute (const Handle(Graphic3d_DataStructureManager)& theProjector,
const Handle(Geom_Transformation)& theTrsf,
const Handle(Graphic3d_Structure)& theStructToFill)
{
// recompute HLR after transformation in all the case
Handle(Prs3d_Presentation) aPrs = *((Handle(Prs3d_Presentation)*)&theStructToFill);
theStructToFill->Clear();
myPresentableObject->Compute (Projector (theProjector), theTrsf, aPrs);
}
//=======================================================================
//function : Projector
//purpose :
//=======================================================================
Handle(Prs3d_Projector) PrsMgr_Presentation::Projector (const Handle(Graphic3d_DataStructureManager)& theProjector)
{
const Handle(Graphic3d_Camera)& aCamera = Handle(Visual3d_View)::DownCast (theProjector)->Camera();
const gp_Dir aDir = aCamera->Direction().Reversed();
const gp_Pnt anAt = aCamera->Center();
const gp_Dir anUp = aCamera->Up();
Handle(Prs3d_Projector) aProj = new Prs3d_Projector (!aCamera->IsOrthographic(),
aCamera->Scale(),
aDir.X(), aDir.Y(), aDir.Z(),
anAt.X(), anAt.Y(), anAt.Z(),
anUp.X(), anUp.Y(), anUp.Z());
return aProj;
}
//=======================================================================
//function : Destroy
//purpose :
//=======================================================================
void PrsMgr_Presentation::Destroy()
{
if (!myStructure.IsNull())
{
myStructure->Clear();
myStructure.Nullify();
}
}
//=======================================================================
//function : SetZLayer
//purpose :
//=======================================================================
void PrsMgr_Presentation::SetZLayer (Standard_Integer theLayerId)
{
myStructure->SetZLayer (theLayerId);
}
//=======================================================================
//function : GetZLayer
//purpose :
//=======================================================================
Standard_Integer PrsMgr_Presentation::GetZLayer() const
{
return myStructure->GetZLayer();
}