1 // File: PrsMgr_Presentation3d.cxx
2 // Created: Thu Oct 21 13:11:19 1993
3 // Author: Jean-Louis FRENKEL
4 // Modified by rob 09-oct-96
8 #define IMP040200 //GG Recompute HLR after transformation
11 #include <PrsMgr_Presentation3d.ixx>
12 #include <PrsMgr_PresentationManager.hxx>
13 #include <PrsMgr_Prs.hxx>
14 #include <Visual3d_View.hxx>
15 #include <Visual3d_ViewOrientation.hxx>
16 #include <Graphic3d_Structure.hxx>
17 #include <Precision.hxx>
19 PrsMgr_Presentation3d::PrsMgr_Presentation3d (const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
20 const Handle(PrsMgr_PresentableObject)& aPresentableObject)
21 : PrsMgr_Presentation(aPresentationManager),
22 myDisplayReason(Standard_False),
23 myPresentableObject (aPresentableObject.operator->())
25 myStructure = new PrsMgr_Prs(aPresentationManager->StructureManager(),
26 this, aPresentableObject->TypeOfPresentation3d());
27 myStructure->SetOwner(myPresentableObject);
30 PrsMgr_KindOfPrs PrsMgr_Presentation3d::KindOfPresentation() const
31 {return PrsMgr_KOP_3D;}
34 void PrsMgr_Presentation3d::Display () {
35 myStructure->Display();
36 myDisplayReason = Standard_False;
39 void PrsMgr_Presentation3d::Erase () const {
40 myStructure->Erase();}
42 void PrsMgr_Presentation3d::Highlight () {
43 if(!myStructure->IsDisplayed()) {
44 myStructure->Display();
45 myDisplayReason = Standard_True;
47 myStructure->Highlight();}
49 void PrsMgr_Presentation3d::Unhighlight () const {
50 myStructure->UnHighlight();
51 if(myDisplayReason) myStructure->Erase();
54 void PrsMgr_Presentation3d::Clear() {
55 // This modification remove the contain of the structure:
57 // 1. The memory zone of the group is reused
58 // 2. The speed for animation is constant
59 myStructure->Clear(Standard_True);
60 // myStructure->Clear(Standard_False);
62 myStructure->RemoveAll();
65 void PrsMgr_Presentation3d::Color(const Quantity_NameOfColor aColor){
66 Standard_Boolean ImmMode = myPresentationManager->IsImmediateModeOn();
68 if(!myStructure->IsDisplayed()) {
69 myStructure->Display();
70 myDisplayReason = Standard_True;
73 myStructure->Color(aColor);
76 void PrsMgr_Presentation3d::BoundBox() const {
77 myStructure->BoundBox();
80 Standard_Boolean PrsMgr_Presentation3d::IsDisplayed () const {
81 return myStructure->IsDisplayed() && !myDisplayReason;
84 Standard_Boolean PrsMgr_Presentation3d::IsHighlighted () const {
85 return myStructure->IsHighlighted();
89 Standard_Integer PrsMgr_Presentation3d::DisplayPriority() const {
90 return myStructure->DisplayPriority();
93 void PrsMgr_Presentation3d::SetDisplayPriority(const Standard_Integer TheNewPrior)
95 myStructure->SetDisplayPriority(TheNewPrior);
98 Handle(Prs3d_Presentation) PrsMgr_Presentation3d::Presentation() const {
101 void PrsMgr_Presentation3d::Connect(const Handle(PrsMgr_Presentation3d)& anOtherPresentation) const {
102 myStructure->Connect(anOtherPresentation->Presentation());
105 void PrsMgr_Presentation3d::Transform (const Handle(Geom_Transformation)& aTransformation) const {
106 myStructure->Transform(aTransformation);
109 void PrsMgr_Presentation3d::Place (const Quantity_Length X,
110 const Quantity_Length Y,
111 const Quantity_Length Z) const {
112 myStructure->Place(X,Y,Z);
115 void PrsMgr_Presentation3d::Multiply (const Handle(Geom_Transformation)& aTransformation) const {
116 myStructure->Multiply(aTransformation);
119 void PrsMgr_Presentation3d::Move (const Quantity_Length X,
120 const Quantity_Length Y,
121 const Quantity_Length Z) const {
122 myStructure->Move(X,Y,Z);
125 void PrsMgr_Presentation3d::SetShadingAspect(const Handle(Prs3d_ShadingAspect)& aShadingAspect) const {
126 myStructure->SetShadingAspect(aShadingAspect);
131 //=======================================================================
133 //purpose : Methods for hidden parts...
134 //=======================================================================
136 Handle(Graphic3d_Structure) PrsMgr_Presentation3d::
137 Compute(const Handle(Graphic3d_DataStructureManager)& aProjector)
140 cout<<"passage in g = Compute(P) "<<endl;
142 Handle(Prs3d_Presentation) g = new Prs3d_Presentation(Handle(PrsMgr_PresentationManager3d)::DownCast(PresentationManager())->StructureManager());
143 myPresentableObject->Compute(Projector(aProjector),g);
147 //=======================================================================
150 //=======================================================================
152 void PrsMgr_Presentation3d::Compute(const Handle(Graphic3d_DataStructureManager)& aProjector,
153 const Handle(Graphic3d_Structure)& TheStructToFill)
156 cout<<"passage in Compute(P,Str)"<<endl;
158 TheStructToFill->Clear();
159 const Handle(Prs3d_Presentation)& P = *((Handle(Prs3d_Presentation)*) &TheStructToFill);
160 myPresentableObject->Compute(Projector(aProjector),P);
163 //=======================================================================
166 //=======================================================================
167 Handle(Graphic3d_Structure) PrsMgr_Presentation3d::
168 Compute(const Handle(Graphic3d_DataStructureManager)& aProjector,
169 const Handle(Geom_Transformation)& TheTrsf)
172 cout<<"passage in G = Compute(P,Trsf)"<<endl;
174 Handle(Prs3d_Presentation) g = new Prs3d_Presentation(Handle(PrsMgr_PresentationManager3d)::DownCast(PresentationManager())->StructureManager());
177 if(TheTrsf->Form()== gp_Translation){
179 cout<<"\tla Trsf est une translation"<<endl;
182 myPresentableObject->Compute(Projector(aProjector),g);
183 g->Transform(TheTrsf);
186 // waiting that something is done in gp_Trsf...rob
187 Standard_Boolean good (Standard_True);
188 for (Standard_Integer i=1;i<=3 && good ;i++){
189 for (Standard_Integer j=1;j<=3 && good ;j++){
191 if(Abs(TheTrsf->Value(i,j)) > Precision::Confusion())
192 good = Standard_False;
199 cout<<"\t it is checked if Trsf is a Translation"<<endl;
201 myPresentableObject->Compute(Projector(aProjector),g);
202 g->Transform(TheTrsf);
207 cout<<"\t Trsf is not only translation..."<<endl;
209 myPresentableObject->Compute(Projector(aProjector),TheTrsf,g);
215 //=======================================================================
218 //=======================================================================
219 void PrsMgr_Presentation3d::Compute(const Handle(Graphic3d_DataStructureManager)& aProjector,
220 const Handle(Geom_Transformation)& TheTrsf,
221 const Handle(Graphic3d_Structure)& TheStructToFill)
225 cout<<"passage in Compute(P,Trsf,Str)"<<endl;
228 Handle(Prs3d_Presentation) P = *((Handle(Prs3d_Presentation)*)&TheStructToFill);
231 TheStructToFill->Clear();
232 myPresentableObject->Compute(Projector(aProjector),TheTrsf,P);
233 #else //Does not work properly, HLR seems deactivated for view rotation
234 if(TheTrsf->Form()== gp_Translation){
236 cout<<"\t Trsf is a translation"<<endl;
238 // myPresentableObject->Compute(Projector(aProjector),P);
239 P->Transform(TheTrsf);
242 // waiting that something is done in gp_Trsf...rob
243 Standard_Boolean good (Standard_True);
244 for (Standard_Integer i=1;i<=3 && good ;i++){
245 for (Standard_Integer j=1;j<=3 && good ;j++){
247 if(Abs(TheTrsf->Value(i,j)) > Precision::Confusion())
248 good = Standard_False;
252 if(good && !TheStructToFill->IsEmpty()){
254 cout<<"\t it is checked if Trsf is a Translation"<<endl;
257 P->Transform(TheTrsf);
260 TheStructToFill->Clear();
263 cout<<"\t Trsf is not only translation..."<<endl;
266 myPresentableObject->Compute(Projector(aProjector),TheTrsf,P);
277 //=======================================================================
278 //function : Projector
280 //=======================================================================
282 Handle(Prs3d_Projector) PrsMgr_Presentation3d::Projector(const Handle(Graphic3d_DataStructureManager)& aProjector) {
283 Visual3d_ViewOrientation VO = Handle(Visual3d_View)::DownCast(aProjector)->ViewOrientation();
284 Standard_Real DX, DY, DZ,XAt, YAt , ZAt,XUp, YUp, ZUp;
285 VO.ViewReferencePlane().Coord(DX, DY, DZ);
286 VO.ViewReferencePoint().Coord(XAt,YAt,ZAt);
287 VO.ViewReferenceUp().Coord(XUp, YUp, ZUp);
288 Visual3d_ViewMapping VM = Handle(Visual3d_View)::DownCast(aProjector)->ViewMapping();
289 Standard_Boolean pers = (VM.Projection() == Visual3d_TOP_PERSPECTIVE);
290 Standard_Real focale = 0.0 ;
292 Standard_Real Xrp,Yrp,Zrp,ViewPlane,FrontPlane ;
293 Graphic3d_Vertex Prp = VM.ProjectionReferencePoint() ;
294 Prp.Coord(Xrp,Yrp,Zrp);
295 FrontPlane = VM.FrontPlaneDistance() ;
296 ViewPlane = VM.ViewPlaneDistance() ;
297 focale = FrontPlane + Zrp - ViewPlane ;
299 Handle(Prs3d_Projector) Proj = new Prs3d_Projector(pers,focale,DX, DY, DZ,XAt, YAt , ZAt,XUp, YUp, ZUp);
304 void PrsMgr_Presentation3d::Destroy () {
305 if (!myStructure.IsNull())
306 myStructure->Clear();
307 myStructure.Nullify();