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 if (myStructure.IsNull())
73 // Erase structure from structure manager
76 // Disconnect other structures
77 myStructure->DisconnectAll (Graphic3d_TOC_DESCENDANT);
78 // Clear groups and remove graphic structure
79 myStructure.Nullify();
82 void PrsMgr_Presentation3d::SetVisible (const Standard_Boolean theValue)
84 myStructure->SetVisible (theValue);
87 void PrsMgr_Presentation3d::Highlight () {
88 Display (Standard_True);
89 myStructure->Highlight();}
91 void PrsMgr_Presentation3d::Unhighlight () const {
92 myStructure->UnHighlight();
93 if (myDisplayReason) myStructure->SetVisible (Standard_False);
96 void PrsMgr_Presentation3d::Clear() {
97 // This modification remove the contain of the structure:
99 // 1. The memory zone of the group is reused
100 // 2. The speed for animation is constant
101 //myPresentableObject = NULL;
102 SetUpdateStatus(Standard_True);
103 if (myStructure.IsNull())
108 myStructure->Clear(Standard_True);
109 // myStructure->Clear(Standard_False);
110 myStructure->RemoveAll();
113 void PrsMgr_Presentation3d::Color(const Quantity_NameOfColor aColor){
114 Display (Standard_True);
115 myStructure->Color(aColor);
118 void PrsMgr_Presentation3d::BoundBox() const {
119 myStructure->BoundBox();
122 Standard_Boolean PrsMgr_Presentation3d::IsDisplayed () const {
123 return myStructure->IsDisplayed() && myStructure->IsVisible() && !myDisplayReason;
126 Standard_Boolean PrsMgr_Presentation3d::IsHighlighted () const {
127 return myStructure->IsHighlighted();
131 Standard_Integer PrsMgr_Presentation3d::DisplayPriority() const {
132 return myStructure->DisplayPriority();
135 void PrsMgr_Presentation3d::SetDisplayPriority(const Standard_Integer TheNewPrior)
137 myStructure->SetDisplayPriority(TheNewPrior);
140 Handle(Prs3d_Presentation) PrsMgr_Presentation3d::Presentation() const {
143 void PrsMgr_Presentation3d::Connect(const Handle(PrsMgr_Presentation3d)& anOtherPresentation) const {
144 myStructure->Connect(anOtherPresentation->Presentation());
147 void PrsMgr_Presentation3d::Transform (const Handle(Geom_Transformation)& aTransformation) const {
148 myStructure->Transform(aTransformation);
151 void PrsMgr_Presentation3d::Place (const Quantity_Length X,
152 const Quantity_Length Y,
153 const Quantity_Length Z) const {
154 myStructure->Place(X,Y,Z);
157 void PrsMgr_Presentation3d::Multiply (const Handle(Geom_Transformation)& aTransformation) const {
158 myStructure->Multiply(aTransformation);
161 void PrsMgr_Presentation3d::Move (const Quantity_Length X,
162 const Quantity_Length Y,
163 const Quantity_Length Z) const {
164 myStructure->Move(X,Y,Z);
167 void PrsMgr_Presentation3d::SetShadingAspect(const Handle(Prs3d_ShadingAspect)& aShadingAspect) const {
168 myStructure->SetShadingAspect(aShadingAspect);
173 //=======================================================================
175 //purpose : Methods for hidden parts...
176 //=======================================================================
178 Handle(Graphic3d_Structure) PrsMgr_Presentation3d::
179 Compute(const Handle(Graphic3d_DataStructureManager)& aProjector)
182 cout<<"passage in g = Compute(P) "<<endl;
184 Handle(Prs3d_Presentation) g = new Prs3d_Presentation(Handle(PrsMgr_PresentationManager3d)::DownCast(PresentationManager())->StructureManager());
185 myPresentableObject->Compute(Projector(aProjector),g);
189 //=======================================================================
192 //=======================================================================
194 void PrsMgr_Presentation3d::Compute (const Handle(Graphic3d_Structure)& theStructure)
196 Standard_Integer aDispMode = 0;
198 Standard_Integer aPresentationsNumber = myPresentableObject->myPresentations.Length();
199 for (Standard_Integer anIter = 1; anIter <= aPresentationsNumber; anIter++)
201 const PrsMgr_ModedPresentation& aModedPresentation = myPresentableObject->myPresentations.Value (anIter);
202 Handle(PrsMgr_Presentation) aPresentation = aModedPresentation.Presentation();
203 PrsMgr_Presentation3d* aPresentation3d = (PrsMgr_Presentation3d* )aPresentation.operator->();
204 if (aPresentation3d == this)
206 aDispMode = aModedPresentation.Mode();
211 Handle(Prs3d_Presentation) aPrs3d = Handle(Prs3d_Presentation)::DownCast (theStructure);
213 myPresentableObject->Compute(
214 Handle(PrsMgr_PresentationManager3d)::DownCast (PresentationManager()),
219 //=======================================================================
222 //=======================================================================
224 void PrsMgr_Presentation3d::Compute(const Handle(Graphic3d_DataStructureManager)& aProjector,
225 const Handle(Graphic3d_Structure)& TheStructToFill)
228 cout<<"passage in Compute(P,Str)"<<endl;
230 TheStructToFill->Clear();
231 const Handle(Prs3d_Presentation)& P = *((Handle(Prs3d_Presentation)*) &TheStructToFill);
232 myPresentableObject->Compute(Projector(aProjector),P);
235 //=======================================================================
238 //=======================================================================
239 Handle(Graphic3d_Structure) PrsMgr_Presentation3d::
240 Compute(const Handle(Graphic3d_DataStructureManager)& aProjector,
241 const Handle(Geom_Transformation)& TheTrsf)
244 cout<<"passage in G = Compute(P,Trsf)"<<endl;
246 Handle(Prs3d_Presentation) g = new Prs3d_Presentation(Handle(PrsMgr_PresentationManager3d)::DownCast(PresentationManager())->StructureManager());
249 if(TheTrsf->Form()== gp_Translation){
251 cout<<"\tla Trsf est une translation"<<endl;
254 myPresentableObject->Compute(Projector(aProjector),g);
255 g->Transform(TheTrsf);
258 // waiting that something is done in gp_Trsf...rob
259 Standard_Boolean good (Standard_True);
260 for (Standard_Integer i=1;i<=3 && good ;i++){
261 for (Standard_Integer j=1;j<=3 && good ;j++){
263 if(Abs(TheTrsf->Value(i,j)) > Precision::Confusion())
264 good = Standard_False;
271 cout<<"\t it is checked if Trsf is a Translation"<<endl;
273 myPresentableObject->Compute(Projector(aProjector),g);
274 g->Transform(TheTrsf);
279 cout<<"\t Trsf is not only translation..."<<endl;
281 myPresentableObject->Compute(Projector(aProjector),TheTrsf,g);
287 //=======================================================================
290 //=======================================================================
291 void PrsMgr_Presentation3d::Compute(const Handle(Graphic3d_DataStructureManager)& aProjector,
292 const Handle(Geom_Transformation)& TheTrsf,
293 const Handle(Graphic3d_Structure)& TheStructToFill)
297 cout<<"passage in Compute(P,Trsf,Str)"<<endl;
300 Handle(Prs3d_Presentation) P = *((Handle(Prs3d_Presentation)*)&TheStructToFill);
303 TheStructToFill->Clear();
304 myPresentableObject->Compute(Projector(aProjector),TheTrsf,P);
305 #else //Does not work properly, HLR seems deactivated for view rotation
306 if(TheTrsf->Form()== gp_Translation){
308 cout<<"\t Trsf is a translation"<<endl;
310 // myPresentableObject->Compute(Projector(aProjector),P);
311 P->Transform(TheTrsf);
314 // waiting that something is done in gp_Trsf...rob
315 Standard_Boolean good (Standard_True);
316 for (Standard_Integer i=1;i<=3 && good ;i++){
317 for (Standard_Integer j=1;j<=3 && good ;j++){
319 if(Abs(TheTrsf->Value(i,j)) > Precision::Confusion())
320 good = Standard_False;
324 if(good && !TheStructToFill->IsEmpty()){
326 cout<<"\t it is checked if Trsf is a Translation"<<endl;
329 P->Transform(TheTrsf);
332 TheStructToFill->Clear();
335 cout<<"\t Trsf is not only translation..."<<endl;
338 myPresentableObject->Compute(Projector(aProjector),TheTrsf,P);
349 //=======================================================================
350 //function : Projector
352 //=======================================================================
354 Handle(Prs3d_Projector) PrsMgr_Presentation3d::Projector(const Handle(Graphic3d_DataStructureManager)& aProjector)
356 const Handle(Graphic3d_Camera)& aCamera = Handle(Visual3d_View)::DownCast (aProjector)->Camera();
358 Standard_Real DX, DY, DZ,XAt, YAt , ZAt,XUp, YUp, ZUp;
359 gp_Dir aDir = aCamera->Direction().Reversed();
360 DX = aDir.X(); DY = aDir.Y(); DZ = aDir.Z();
362 gp_Pnt anAt = aCamera->Center();
363 XAt = anAt.X(); YAt = anAt.Y(); ZAt = anAt.Z();
365 gp_Dir anUp = aCamera->Up();
366 XUp = anUp.X(); YUp = anUp.Y(); ZUp = anUp.Z();
368 Standard_Boolean pers = !aCamera->IsOrthographic();
369 Standard_Real focale = aCamera->Scale();
371 Handle(Prs3d_Projector) aProj =
372 new Prs3d_Projector(pers, focale, DX, DY, DZ, XAt, YAt, ZAt, XUp, YUp, ZUp);
377 void PrsMgr_Presentation3d::Destroy () {
378 if (!myStructure.IsNull())
379 myStructure->Clear();
380 myStructure.Nullify();
383 //=======================================================================
384 //function : SetZLayer
386 //=======================================================================
388 void PrsMgr_Presentation3d::SetZLayer (Standard_Integer theLayerId)
390 myStructure->SetZLayer (theLayerId);
393 //=======================================================================
394 //function : GetZLayer
396 //=======================================================================
398 Standard_Integer PrsMgr_Presentation3d::GetZLayer () const
400 return myStructure->GetZLayer ();