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
6 // rob 18-may-98 : Pb de la Trsf dont le type n'est pas calcule en fonction
9 #define IMP040200 //GG Recompute HLR after transformation
12 #include <PrsMgr_Presentation3d.ixx>
13 #include <PrsMgr_PresentationManager.hxx>
14 #include <PrsMgr_Prs.hxx>
15 #include <Visual3d_View.hxx>
16 #include <Visual3d_ViewOrientation.hxx>
17 #include <Graphic3d_Structure.hxx>
18 #include <Precision.hxx>
20 PrsMgr_Presentation3d::PrsMgr_Presentation3d (const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
21 const Handle(PrsMgr_PresentableObject)& aPresentableObject)
22 : PrsMgr_Presentation(aPresentationManager),
23 myDisplayReason(Standard_False),
24 myPresentableObject (aPresentableObject.operator->())
26 myStructure = new PrsMgr_Prs(aPresentationManager->StructureManager(),
27 this, aPresentableObject->TypeOfPresentation3d());
28 myStructure->SetOwner(myPresentableObject);
31 PrsMgr_KindOfPrs PrsMgr_Presentation3d::KindOfPresentation() const
32 {return PrsMgr_KOP_3D;}
35 void PrsMgr_Presentation3d::Display () {
36 myStructure->Display();
37 myDisplayReason = Standard_False;
40 void PrsMgr_Presentation3d::Erase () const {
41 myStructure->Erase();}
43 void PrsMgr_Presentation3d::Highlight () {
44 if(!myStructure->IsDisplayed()) {
45 myStructure->Display();
46 myDisplayReason = Standard_True;
48 myStructure->Highlight();}
50 void PrsMgr_Presentation3d::Unhighlight () const {
51 myStructure->UnHighlight();
52 if(myDisplayReason) myStructure->Erase();
55 void PrsMgr_Presentation3d::Clear() {
56 // This modification remove the contain of the structure:
58 // 1. The memory zone of the group is reused
59 // 2. The speed for animation is constant
60 myStructure->Clear(Standard_True);
61 // myStructure->Clear(Standard_False);
63 myStructure->RemoveAll();
66 void PrsMgr_Presentation3d::Color(const Quantity_NameOfColor aColor){
67 Standard_Boolean ImmMode = myPresentationManager->IsImmediateModeOn();
69 if(!myStructure->IsDisplayed()) {
70 myStructure->Display();
71 myDisplayReason = Standard_True;
74 myStructure->Color(aColor);
77 void PrsMgr_Presentation3d::BoundBox() const {
78 myStructure->BoundBox();
81 Standard_Boolean PrsMgr_Presentation3d::IsDisplayed () const {
82 return myStructure->IsDisplayed() && !myDisplayReason;
85 Standard_Boolean PrsMgr_Presentation3d::IsHighlighted () const {
86 return myStructure->IsHighlighted();
90 Standard_Integer PrsMgr_Presentation3d::DisplayPriority() const {
91 return myStructure->DisplayPriority();
94 void PrsMgr_Presentation3d::SetDisplayPriority(const Standard_Integer TheNewPrior)
96 myStructure->SetDisplayPriority(TheNewPrior);
99 Handle(Prs3d_Presentation) PrsMgr_Presentation3d::Presentation() const {
102 void PrsMgr_Presentation3d::Connect(const Handle(PrsMgr_Presentation3d)& anOtherPresentation) const {
103 myStructure->Connect(anOtherPresentation->Presentation());
106 void PrsMgr_Presentation3d::Transform (const Handle(Geom_Transformation)& aTransformation) const {
107 myStructure->Transform(aTransformation);
110 void PrsMgr_Presentation3d::Place (const Quantity_Length X,
111 const Quantity_Length Y,
112 const Quantity_Length Z) const {
113 myStructure->Place(X,Y,Z);
116 void PrsMgr_Presentation3d::Multiply (const Handle(Geom_Transformation)& aTransformation) const {
117 myStructure->Multiply(aTransformation);
120 void PrsMgr_Presentation3d::Move (const Quantity_Length X,
121 const Quantity_Length Y,
122 const Quantity_Length Z) const {
123 myStructure->Move(X,Y,Z);
126 void PrsMgr_Presentation3d::SetShadingAspect(const Handle(Prs3d_ShadingAspect)& aShadingAspect) const {
127 myStructure->SetShadingAspect(aShadingAspect);
132 //=======================================================================
134 //purpose : Les methodes pour les parties cachees...
135 //=======================================================================
137 Handle(Graphic3d_Structure) PrsMgr_Presentation3d::
138 Compute(const Handle(Graphic3d_DataStructureManager)& aProjector)
141 cout<<"passage dans g = Compute(P) "<<endl;
143 Handle(Prs3d_Presentation) g = new Prs3d_Presentation(Handle(PrsMgr_PresentationManager3d)::DownCast(PresentationManager())->StructureManager());
144 myPresentableObject->Compute(Projector(aProjector),g);
148 //=======================================================================
151 //=======================================================================
153 void PrsMgr_Presentation3d::Compute(const Handle(Graphic3d_DataStructureManager)& aProjector,
154 const Handle(Graphic3d_Structure)& TheStructToFill)
157 cout<<"passage dans Compute(P,Str)"<<endl;
159 TheStructToFill->Clear();
160 const Handle(Prs3d_Presentation)& P = *((Handle(Prs3d_Presentation)*) &TheStructToFill);
161 myPresentableObject->Compute(Projector(aProjector),P);
164 //=======================================================================
167 //=======================================================================
168 Handle(Graphic3d_Structure) PrsMgr_Presentation3d::
169 Compute(const Handle(Graphic3d_DataStructureManager)& aProjector,
170 const Handle(Geom_Transformation)& TheTrsf)
173 cout<<"passage dans G = Compute(P,Trsf)"<<endl;
175 Handle(Prs3d_Presentation) g = new Prs3d_Presentation(Handle(PrsMgr_PresentationManager3d)::DownCast(PresentationManager())->StructureManager());
178 if(TheTrsf->Form()== gp_Translation){
180 cout<<"\tla Trsf est une translation"<<endl;
183 myPresentableObject->Compute(Projector(aProjector),g);
184 g->Transform(TheTrsf);
187 // en attendant que la chose soit effectue dans gp_Trsf...rob
188 Standard_Boolean good (Standard_True);
189 for (Standard_Integer i=1;i<=3 && good ;i++){
190 for (Standard_Integer j=1;j<=3 && good ;j++){
192 if(Abs(TheTrsf->Value(i,j)) > Precision::Confusion())
193 good = Standard_False;
200 cout<<"\ton a verifie que la Trsf est une Translation"<<endl;
202 myPresentableObject->Compute(Projector(aProjector),g);
203 g->Transform(TheTrsf);
208 cout<<"\tla Trsf n'est pas seulement translation..."<<endl;
210 myPresentableObject->Compute(Projector(aProjector),TheTrsf,g);
216 //=======================================================================
219 //=======================================================================
220 void PrsMgr_Presentation3d::Compute(const Handle(Graphic3d_DataStructureManager)& aProjector,
221 const Handle(Geom_Transformation)& TheTrsf,
222 const Handle(Graphic3d_Structure)& TheStructToFill)
226 cout<<"passage dans Compute(P,Trsf,Str)"<<endl;
229 Handle(Prs3d_Presentation) P = *((Handle(Prs3d_Presentation)*)&TheStructToFill);
232 TheStructToFill->Clear();
233 myPresentableObject->Compute(Projector(aProjector),TheTrsf,P);
234 #else //Does not work properly ,HLR seems deactivated for view rotation
235 if(TheTrsf->Form()== gp_Translation){
237 cout<<"\tla Trsf est une translation"<<endl;
239 // myPresentableObject->Compute(Projector(aProjector),P);
240 P->Transform(TheTrsf);
243 // en attendant que la chose soit effectue dans gp_Trsf...rob
244 Standard_Boolean good (Standard_True);
245 for (Standard_Integer i=1;i<=3 && good ;i++){
246 for (Standard_Integer j=1;j<=3 && good ;j++){
248 if(Abs(TheTrsf->Value(i,j)) > Precision::Confusion())
249 good = Standard_False;
253 if(good && !TheStructToFill->IsEmpty()){
255 cout<<"\ton a verifie que la Trsf est une Translation"<<endl;
258 P->Transform(TheTrsf);
261 TheStructToFill->Clear();
264 cout<<"\tla Trsf n'est pas seulement translation..."<<endl;
267 myPresentableObject->Compute(Projector(aProjector),TheTrsf,P);
278 //=======================================================================
279 //function : Projector
281 //=======================================================================
283 Handle(Prs3d_Projector) PrsMgr_Presentation3d::Projector(const Handle(Graphic3d_DataStructureManager)& aProjector) {
284 Visual3d_ViewOrientation VO = Handle(Visual3d_View)::DownCast(aProjector)->ViewOrientation();
285 Standard_Real DX, DY, DZ,XAt, YAt , ZAt,XUp, YUp, ZUp;
286 VO.ViewReferencePlane().Coord(DX, DY, DZ);
287 VO.ViewReferencePoint().Coord(XAt,YAt,ZAt);
288 VO.ViewReferenceUp().Coord(XUp, YUp, ZUp);
289 Visual3d_ViewMapping VM = Handle(Visual3d_View)::DownCast(aProjector)->ViewMapping();
290 Standard_Boolean pers = (VM.Projection() == Visual3d_TOP_PERSPECTIVE);
291 Standard_Real focale = 0.0 ;
293 Standard_Real Xrp,Yrp,Zrp,ViewPlane,FrontPlane ;
294 Graphic3d_Vertex Prp = VM.ProjectionReferencePoint() ;
295 Prp.Coord(Xrp,Yrp,Zrp);
296 FrontPlane = VM.FrontPlaneDistance() ;
297 ViewPlane = VM.ViewPlaneDistance() ;
298 focale = FrontPlane + Zrp - ViewPlane ;
300 Handle(Prs3d_Projector) Proj = new Prs3d_Projector(pers,focale,DX, DY, DZ,XAt, YAt , ZAt,XUp, YUp, ZUp);
305 void PrsMgr_Presentation3d::Destroy () {
306 if (!myStructure.IsNull())
307 myStructure->Clear();
308 myStructure.Nullify();