1 // Created on: 1993-10-21
2 // Created by: Jean-Louis FRENKEL
3 // Copyright (c) 1993-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and / or modify it
9 // under the terms of the GNU Lesser General Public version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 // Modified by rob 09-oct-96
20 #define IMP040200 //GG Recompute HLR after transformation
23 #include <PrsMgr_Presentation3d.ixx>
24 #include <PrsMgr_PresentationManager.hxx>
25 #include <PrsMgr_Prs.hxx>
26 #include <PrsMgr_ModedPresentation.hxx>
27 #include <Visual3d_View.hxx>
28 #include <Visual3d_ViewOrientation.hxx>
29 #include <Graphic3d_Structure.hxx>
30 #include <Precision.hxx>
32 PrsMgr_Presentation3d::PrsMgr_Presentation3d (const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
33 const Handle(PrsMgr_PresentableObject)& aPresentableObject)
34 : PrsMgr_Presentation(aPresentationManager),
35 myDisplayReason(Standard_False),
36 myPresentableObject (aPresentableObject.operator->())
38 myStructure = new PrsMgr_Prs(aPresentationManager->StructureManager(),
39 this, aPresentableObject->TypeOfPresentation3d());
40 myStructure->SetOwner(myPresentableObject);
43 PrsMgr_KindOfPrs PrsMgr_Presentation3d::KindOfPresentation() const
44 {return PrsMgr_KOP_3D;}
47 void PrsMgr_Presentation3d::Display()
49 Display (Standard_False);
50 myDisplayReason = Standard_False;
53 void PrsMgr_Presentation3d::Display(const Standard_Boolean theIsHighlight)
55 if (!myStructure->IsDisplayed())
57 myStructure->Display();
58 myDisplayReason = theIsHighlight;
60 else if (!myStructure->IsVisible())
62 myStructure->SetVisible (Standard_True);
63 myDisplayReason = theIsHighlight;
67 void PrsMgr_Presentation3d::Erase ()
69 // Erase structure from structure manager
72 // Disconnect other structures
73 myStructure->DisconnectAll (Graphic3d_TOC_DESCENDANT);
74 // Clear groups and remove graphic structure
75 myStructure.Nullify();
78 void PrsMgr_Presentation3d::SetVisible (const Standard_Boolean theValue)
80 myStructure->SetVisible (theValue);
83 void PrsMgr_Presentation3d::Highlight () {
84 Display (Standard_True);
85 myStructure->Highlight();}
87 void PrsMgr_Presentation3d::Unhighlight () const {
88 myStructure->UnHighlight();
89 if (myDisplayReason) myStructure->SetVisible (Standard_False);
92 void PrsMgr_Presentation3d::Clear() {
93 // This modification remove the contain of the structure:
95 // 1. The memory zone of the group is reused
96 // 2. The speed for animation is constant
97 //myPresentableObject = NULL;
98 SetUpdateStatus(Standard_True);
99 myStructure->Clear(Standard_True);
100 // myStructure->Clear(Standard_False);
102 myStructure->RemoveAll();
105 void PrsMgr_Presentation3d::Color(const Quantity_NameOfColor aColor){
106 Display (Standard_True);
107 myStructure->Color(aColor);
110 void PrsMgr_Presentation3d::BoundBox() const {
111 myStructure->BoundBox();
114 Standard_Boolean PrsMgr_Presentation3d::IsDisplayed () const {
115 return myStructure->IsDisplayed() && myStructure->IsVisible() && !myDisplayReason;
118 Standard_Boolean PrsMgr_Presentation3d::IsHighlighted () const {
119 return myStructure->IsHighlighted();
123 Standard_Integer PrsMgr_Presentation3d::DisplayPriority() const {
124 return myStructure->DisplayPriority();
127 void PrsMgr_Presentation3d::SetDisplayPriority(const Standard_Integer TheNewPrior)
129 myStructure->SetDisplayPriority(TheNewPrior);
132 Handle(Prs3d_Presentation) PrsMgr_Presentation3d::Presentation() const {
135 void PrsMgr_Presentation3d::Connect(const Handle(PrsMgr_Presentation3d)& anOtherPresentation) const {
136 myStructure->Connect(anOtherPresentation->Presentation());
139 void PrsMgr_Presentation3d::Transform (const Handle(Geom_Transformation)& aTransformation) const {
140 myStructure->Transform(aTransformation);
143 void PrsMgr_Presentation3d::Place (const Quantity_Length X,
144 const Quantity_Length Y,
145 const Quantity_Length Z) const {
146 myStructure->Place(X,Y,Z);
149 void PrsMgr_Presentation3d::Multiply (const Handle(Geom_Transformation)& aTransformation) const {
150 myStructure->Multiply(aTransformation);
153 void PrsMgr_Presentation3d::Move (const Quantity_Length X,
154 const Quantity_Length Y,
155 const Quantity_Length Z) const {
156 myStructure->Move(X,Y,Z);
159 void PrsMgr_Presentation3d::SetShadingAspect(const Handle(Prs3d_ShadingAspect)& aShadingAspect) const {
160 myStructure->SetShadingAspect(aShadingAspect);
165 //=======================================================================
167 //purpose : Methods for hidden parts...
168 //=======================================================================
170 Handle(Graphic3d_Structure) PrsMgr_Presentation3d::
171 Compute(const Handle(Graphic3d_DataStructureManager)& aProjector)
174 cout<<"passage in g = Compute(P) "<<endl;
176 Handle(Prs3d_Presentation) g = new Prs3d_Presentation(Handle(PrsMgr_PresentationManager3d)::DownCast(PresentationManager())->StructureManager());
177 myPresentableObject->Compute(Projector(aProjector),g);
181 //=======================================================================
184 //=======================================================================
186 void PrsMgr_Presentation3d::Compute (const Handle(Graphic3d_Structure)& theStructure)
188 Standard_Integer aDispMode = 0;
190 Standard_Integer aPresentationsNumber = myPresentableObject->myPresentations.Length();
191 for (Standard_Integer anIter = 1; anIter <= aPresentationsNumber; anIter++)
193 const PrsMgr_ModedPresentation& aModedPresentation = myPresentableObject->myPresentations.Value (anIter);
194 Handle(PrsMgr_Presentation) aPresentation = aModedPresentation.Presentation();
195 PrsMgr_Presentation3d* aPresentation3d = (PrsMgr_Presentation3d* )aPresentation.operator->();
196 if (aPresentation3d == this)
198 aDispMode = aModedPresentation.Mode();
203 Handle(Prs3d_Presentation) aPrs3d = Handle(Prs3d_Presentation)::DownCast (theStructure);
205 myPresentableObject->Compute(
206 Handle(PrsMgr_PresentationManager3d)::DownCast (PresentationManager()),
211 //=======================================================================
214 //=======================================================================
216 void PrsMgr_Presentation3d::Compute(const Handle(Graphic3d_DataStructureManager)& aProjector,
217 const Handle(Graphic3d_Structure)& TheStructToFill)
220 cout<<"passage in Compute(P,Str)"<<endl;
222 TheStructToFill->Clear();
223 const Handle(Prs3d_Presentation)& P = *((Handle(Prs3d_Presentation)*) &TheStructToFill);
224 myPresentableObject->Compute(Projector(aProjector),P);
227 //=======================================================================
230 //=======================================================================
231 Handle(Graphic3d_Structure) PrsMgr_Presentation3d::
232 Compute(const Handle(Graphic3d_DataStructureManager)& aProjector,
233 const Handle(Geom_Transformation)& TheTrsf)
236 cout<<"passage in G = Compute(P,Trsf)"<<endl;
238 Handle(Prs3d_Presentation) g = new Prs3d_Presentation(Handle(PrsMgr_PresentationManager3d)::DownCast(PresentationManager())->StructureManager());
241 if(TheTrsf->Form()== gp_Translation){
243 cout<<"\tla Trsf est une translation"<<endl;
246 myPresentableObject->Compute(Projector(aProjector),g);
247 g->Transform(TheTrsf);
250 // waiting that something is done in gp_Trsf...rob
251 Standard_Boolean good (Standard_True);
252 for (Standard_Integer i=1;i<=3 && good ;i++){
253 for (Standard_Integer j=1;j<=3 && good ;j++){
255 if(Abs(TheTrsf->Value(i,j)) > Precision::Confusion())
256 good = Standard_False;
263 cout<<"\t it is checked if Trsf is a Translation"<<endl;
265 myPresentableObject->Compute(Projector(aProjector),g);
266 g->Transform(TheTrsf);
271 cout<<"\t Trsf is not only translation..."<<endl;
273 myPresentableObject->Compute(Projector(aProjector),TheTrsf,g);
279 //=======================================================================
282 //=======================================================================
283 void PrsMgr_Presentation3d::Compute(const Handle(Graphic3d_DataStructureManager)& aProjector,
284 const Handle(Geom_Transformation)& TheTrsf,
285 const Handle(Graphic3d_Structure)& TheStructToFill)
289 cout<<"passage in Compute(P,Trsf,Str)"<<endl;
292 Handle(Prs3d_Presentation) P = *((Handle(Prs3d_Presentation)*)&TheStructToFill);
295 TheStructToFill->Clear();
296 myPresentableObject->Compute(Projector(aProjector),TheTrsf,P);
297 #else //Does not work properly, HLR seems deactivated for view rotation
298 if(TheTrsf->Form()== gp_Translation){
300 cout<<"\t Trsf is a translation"<<endl;
302 // myPresentableObject->Compute(Projector(aProjector),P);
303 P->Transform(TheTrsf);
306 // waiting that something is done in gp_Trsf...rob
307 Standard_Boolean good (Standard_True);
308 for (Standard_Integer i=1;i<=3 && good ;i++){
309 for (Standard_Integer j=1;j<=3 && good ;j++){
311 if(Abs(TheTrsf->Value(i,j)) > Precision::Confusion())
312 good = Standard_False;
316 if(good && !TheStructToFill->IsEmpty()){
318 cout<<"\t it is checked if Trsf is a Translation"<<endl;
321 P->Transform(TheTrsf);
324 TheStructToFill->Clear();
327 cout<<"\t Trsf is not only translation..."<<endl;
330 myPresentableObject->Compute(Projector(aProjector),TheTrsf,P);
341 //=======================================================================
342 //function : Projector
344 //=======================================================================
346 Handle(Prs3d_Projector) PrsMgr_Presentation3d::Projector(const Handle(Graphic3d_DataStructureManager)& aProjector) {
347 Visual3d_ViewOrientation VO = Handle(Visual3d_View)::DownCast(aProjector)->ViewOrientation();
348 Standard_Real DX, DY, DZ,XAt, YAt , ZAt,XUp, YUp, ZUp;
349 VO.ViewReferencePlane().Coord(DX, DY, DZ);
350 VO.ViewReferencePoint().Coord(XAt,YAt,ZAt);
351 VO.ViewReferenceUp().Coord(XUp, YUp, ZUp);
352 Visual3d_ViewMapping VM = Handle(Visual3d_View)::DownCast(aProjector)->ViewMapping();
353 Standard_Boolean pers = (VM.Projection() == Visual3d_TOP_PERSPECTIVE);
354 Standard_Real focale = 0.0 ;
356 Standard_Real Xrp,Yrp,Zrp,ViewPlane,FrontPlane ;
357 Graphic3d_Vertex Prp = VM.ProjectionReferencePoint() ;
358 Prp.Coord(Xrp,Yrp,Zrp);
359 FrontPlane = VM.FrontPlaneDistance() ;
360 ViewPlane = VM.ViewPlaneDistance() ;
361 focale = FrontPlane + Zrp - ViewPlane ;
363 Handle(Prs3d_Projector) Proj = new Prs3d_Projector(pers,focale,DX, DY, DZ,XAt, YAt , ZAt,XUp, YUp, ZUp);
368 void PrsMgr_Presentation3d::Destroy () {
369 if (!myStructure.IsNull())
370 myStructure->Clear();
371 myStructure.Nullify();
374 //=======================================================================
375 //function : SetZLayer
377 //=======================================================================
379 void PrsMgr_Presentation3d::SetZLayer (Standard_Integer theLayerId)
381 myStructure->SetZLayer (theLayerId);
384 //=======================================================================
385 //function : GetZLayer
387 //=======================================================================
389 Standard_Integer PrsMgr_Presentation3d::GetZLayer () const
391 return myStructure->GetZLayer ();