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 under
9 // the terms of the GNU Lesser General Public License 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 <Graphic3d_Structure.hxx>
29 #include <Precision.hxx>
31 PrsMgr_Presentation3d::PrsMgr_Presentation3d (const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
32 const Handle(PrsMgr_PresentableObject)& aPresentableObject)
33 : PrsMgr_Presentation(aPresentationManager),
34 myDisplayReason(Standard_False),
35 myPresentableObject (aPresentableObject.operator->())
37 myStructure = new PrsMgr_Prs(aPresentationManager->StructureManager(),
38 this, aPresentableObject->TypeOfPresentation3d());
39 myStructure->SetOwner(myPresentableObject);
42 PrsMgr_KindOfPrs PrsMgr_Presentation3d::KindOfPresentation() const
43 {return PrsMgr_KOP_3D;}
46 void PrsMgr_Presentation3d::Display()
48 Display (Standard_False);
49 myDisplayReason = Standard_False;
52 void PrsMgr_Presentation3d::Display(const Standard_Boolean theIsHighlight)
54 if (!myStructure->IsDisplayed())
56 myStructure->Display();
57 myDisplayReason = theIsHighlight;
59 else if (!myStructure->IsVisible())
61 myStructure->SetVisible (Standard_True);
62 myDisplayReason = theIsHighlight;
66 void PrsMgr_Presentation3d::Erase ()
68 // Erase structure from structure manager
71 // Disconnect other structures
72 myStructure->DisconnectAll (Graphic3d_TOC_DESCENDANT);
73 // Clear groups and remove graphic structure
74 myStructure.Nullify();
77 void PrsMgr_Presentation3d::SetVisible (const Standard_Boolean theValue)
79 myStructure->SetVisible (theValue);
82 void PrsMgr_Presentation3d::Highlight () {
83 Display (Standard_True);
84 myStructure->Highlight();}
86 void PrsMgr_Presentation3d::Unhighlight () const {
87 myStructure->UnHighlight();
88 if (myDisplayReason) myStructure->SetVisible (Standard_False);
91 void PrsMgr_Presentation3d::Clear() {
92 // This modification remove the contain of the structure:
94 // 1. The memory zone of the group is reused
95 // 2. The speed for animation is constant
96 //myPresentableObject = NULL;
97 SetUpdateStatus(Standard_True);
98 myStructure->Clear(Standard_True);
99 // myStructure->Clear(Standard_False);
101 myStructure->RemoveAll();
104 void PrsMgr_Presentation3d::Color(const Quantity_NameOfColor aColor){
105 Display (Standard_True);
106 myStructure->Color(aColor);
109 void PrsMgr_Presentation3d::BoundBox() const {
110 myStructure->BoundBox();
113 Standard_Boolean PrsMgr_Presentation3d::IsDisplayed () const {
114 return myStructure->IsDisplayed() && myStructure->IsVisible() && !myDisplayReason;
117 Standard_Boolean PrsMgr_Presentation3d::IsHighlighted () const {
118 return myStructure->IsHighlighted();
122 Standard_Integer PrsMgr_Presentation3d::DisplayPriority() const {
123 return myStructure->DisplayPriority();
126 void PrsMgr_Presentation3d::SetDisplayPriority(const Standard_Integer TheNewPrior)
128 myStructure->SetDisplayPriority(TheNewPrior);
131 Handle(Prs3d_Presentation) PrsMgr_Presentation3d::Presentation() const {
134 void PrsMgr_Presentation3d::Connect(const Handle(PrsMgr_Presentation3d)& anOtherPresentation) const {
135 myStructure->Connect(anOtherPresentation->Presentation());
138 void PrsMgr_Presentation3d::Transform (const Handle(Geom_Transformation)& aTransformation) const {
139 myStructure->Transform(aTransformation);
142 void PrsMgr_Presentation3d::Place (const Quantity_Length X,
143 const Quantity_Length Y,
144 const Quantity_Length Z) const {
145 myStructure->Place(X,Y,Z);
148 void PrsMgr_Presentation3d::Multiply (const Handle(Geom_Transformation)& aTransformation) const {
149 myStructure->Multiply(aTransformation);
152 void PrsMgr_Presentation3d::Move (const Quantity_Length X,
153 const Quantity_Length Y,
154 const Quantity_Length Z) const {
155 myStructure->Move(X,Y,Z);
158 void PrsMgr_Presentation3d::SetShadingAspect(const Handle(Prs3d_ShadingAspect)& aShadingAspect) const {
159 myStructure->SetShadingAspect(aShadingAspect);
164 //=======================================================================
166 //purpose : Methods for hidden parts...
167 //=======================================================================
169 Handle(Graphic3d_Structure) PrsMgr_Presentation3d::
170 Compute(const Handle(Graphic3d_DataStructureManager)& aProjector)
173 cout<<"passage in g = Compute(P) "<<endl;
175 Handle(Prs3d_Presentation) g = new Prs3d_Presentation(Handle(PrsMgr_PresentationManager3d)::DownCast(PresentationManager())->StructureManager());
176 myPresentableObject->Compute(Projector(aProjector),g);
180 //=======================================================================
183 //=======================================================================
185 void PrsMgr_Presentation3d::Compute (const Handle(Graphic3d_Structure)& theStructure)
187 Standard_Integer aDispMode = 0;
189 Standard_Integer aPresentationsNumber = myPresentableObject->myPresentations.Length();
190 for (Standard_Integer anIter = 1; anIter <= aPresentationsNumber; anIter++)
192 const PrsMgr_ModedPresentation& aModedPresentation = myPresentableObject->myPresentations.Value (anIter);
193 Handle(PrsMgr_Presentation) aPresentation = aModedPresentation.Presentation();
194 PrsMgr_Presentation3d* aPresentation3d = (PrsMgr_Presentation3d* )aPresentation.operator->();
195 if (aPresentation3d == this)
197 aDispMode = aModedPresentation.Mode();
202 Handle(Prs3d_Presentation) aPrs3d = Handle(Prs3d_Presentation)::DownCast (theStructure);
204 myPresentableObject->Compute(
205 Handle(PrsMgr_PresentationManager3d)::DownCast (PresentationManager()),
210 //=======================================================================
213 //=======================================================================
215 void PrsMgr_Presentation3d::Compute(const Handle(Graphic3d_DataStructureManager)& aProjector,
216 const Handle(Graphic3d_Structure)& TheStructToFill)
219 cout<<"passage in Compute(P,Str)"<<endl;
221 TheStructToFill->Clear();
222 const Handle(Prs3d_Presentation)& P = *((Handle(Prs3d_Presentation)*) &TheStructToFill);
223 myPresentableObject->Compute(Projector(aProjector),P);
226 //=======================================================================
229 //=======================================================================
230 Handle(Graphic3d_Structure) PrsMgr_Presentation3d::
231 Compute(const Handle(Graphic3d_DataStructureManager)& aProjector,
232 const Handle(Geom_Transformation)& TheTrsf)
235 cout<<"passage in G = Compute(P,Trsf)"<<endl;
237 Handle(Prs3d_Presentation) g = new Prs3d_Presentation(Handle(PrsMgr_PresentationManager3d)::DownCast(PresentationManager())->StructureManager());
240 if(TheTrsf->Form()== gp_Translation){
242 cout<<"\tla Trsf est une translation"<<endl;
245 myPresentableObject->Compute(Projector(aProjector),g);
246 g->Transform(TheTrsf);
249 // waiting that something is done in gp_Trsf...rob
250 Standard_Boolean good (Standard_True);
251 for (Standard_Integer i=1;i<=3 && good ;i++){
252 for (Standard_Integer j=1;j<=3 && good ;j++){
254 if(Abs(TheTrsf->Value(i,j)) > Precision::Confusion())
255 good = Standard_False;
262 cout<<"\t it is checked if Trsf is a Translation"<<endl;
264 myPresentableObject->Compute(Projector(aProjector),g);
265 g->Transform(TheTrsf);
270 cout<<"\t Trsf is not only translation..."<<endl;
272 myPresentableObject->Compute(Projector(aProjector),TheTrsf,g);
278 //=======================================================================
281 //=======================================================================
282 void PrsMgr_Presentation3d::Compute(const Handle(Graphic3d_DataStructureManager)& aProjector,
283 const Handle(Geom_Transformation)& TheTrsf,
284 const Handle(Graphic3d_Structure)& TheStructToFill)
288 cout<<"passage in Compute(P,Trsf,Str)"<<endl;
291 Handle(Prs3d_Presentation) P = *((Handle(Prs3d_Presentation)*)&TheStructToFill);
294 TheStructToFill->Clear();
295 myPresentableObject->Compute(Projector(aProjector),TheTrsf,P);
296 #else //Does not work properly, HLR seems deactivated for view rotation
297 if(TheTrsf->Form()== gp_Translation){
299 cout<<"\t Trsf is a translation"<<endl;
301 // myPresentableObject->Compute(Projector(aProjector),P);
302 P->Transform(TheTrsf);
305 // waiting that something is done in gp_Trsf...rob
306 Standard_Boolean good (Standard_True);
307 for (Standard_Integer i=1;i<=3 && good ;i++){
308 for (Standard_Integer j=1;j<=3 && good ;j++){
310 if(Abs(TheTrsf->Value(i,j)) > Precision::Confusion())
311 good = Standard_False;
315 if(good && !TheStructToFill->IsEmpty()){
317 cout<<"\t it is checked if Trsf is a Translation"<<endl;
320 P->Transform(TheTrsf);
323 TheStructToFill->Clear();
326 cout<<"\t Trsf is not only translation..."<<endl;
329 myPresentableObject->Compute(Projector(aProjector),TheTrsf,P);
340 //=======================================================================
341 //function : Projector
343 //=======================================================================
345 Handle(Prs3d_Projector) PrsMgr_Presentation3d::Projector(const Handle(Graphic3d_DataStructureManager)& aProjector)
347 const Handle(Graphic3d_Camera)& aCamera = Handle(Visual3d_View)::DownCast (aProjector)->Camera();
349 Standard_Real DX, DY, DZ,XAt, YAt , ZAt,XUp, YUp, ZUp;
350 gp_Dir aDir = aCamera->Direction().Reversed();
351 DX = aDir.X(); DY = aDir.Y(); DZ = aDir.Z();
353 gp_Pnt anAt = aCamera->Center();
354 XAt = anAt.X(); YAt = anAt.Y(); ZAt = anAt.Z();
356 gp_Dir anUp = aCamera->Up();
357 XUp = anUp.X(); YUp = anUp.Y(); ZUp = anUp.Z();
359 Standard_Boolean pers = !aCamera->IsOrthographic();
360 Standard_Real focale = aCamera->Scale();
362 Handle(Prs3d_Projector) aProj =
363 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 ();