0024391: Erased AIS object can not be displayed in AIS_InteractiveContext after AIS_I...
[occt.git] / src / PrsMgr / PrsMgr_Presentation3d.cxx
CommitLineData
b311480e 1// Created on: 1993-10-21
2// Created by: Jean-Louis FRENKEL
3// Copyright (c) 1993-1999 Matra Datavision
4// Copyright (c) 1999-2012 OPEN CASCADE SAS
5//
6// The content of this file is subject to the Open CASCADE Technology Public
7// License Version 6.5 (the "License"). You may not use the content of this file
8// except in compliance with the License. Please obtain a copy of the License
9// at http://www.opencascade.org and read it completely before using this file.
10//
11// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13//
14// The Original Code and all software distributed under the License is
15// distributed on an "AS IS" basis, without warranty of any kind, and the
16// Initial Developer hereby disclaims all such warranties, including without
17// limitation, any warranties of merchantability, fitness for a particular
18// purpose or non-infringement. Please see the License for the specific terms
19// and conditions governing the rights and limitations under the License.
20
7fd59977 21// Modified by rob 09-oct-96
81bba717 22
7fd59977 23
24#define IMP040200 //GG Recompute HLR after transformation
25// in all the case.
26
27#include <PrsMgr_Presentation3d.ixx>
28#include <PrsMgr_PresentationManager.hxx>
29#include <PrsMgr_Prs.hxx>
eb4320f2 30#include <PrsMgr_ModedPresentation.hxx>
7fd59977 31#include <Visual3d_View.hxx>
32#include <Visual3d_ViewOrientation.hxx>
33#include <Graphic3d_Structure.hxx>
34#include <Precision.hxx>
35
36PrsMgr_Presentation3d::PrsMgr_Presentation3d (const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
37 const Handle(PrsMgr_PresentableObject)& aPresentableObject)
38: PrsMgr_Presentation(aPresentationManager),
39 myDisplayReason(Standard_False),
40 myPresentableObject (aPresentableObject.operator->())
41{
42 myStructure = new PrsMgr_Prs(aPresentationManager->StructureManager(),
43 this, aPresentableObject->TypeOfPresentation3d());
44 myStructure->SetOwner(myPresentableObject);
45}
46
47PrsMgr_KindOfPrs PrsMgr_Presentation3d::KindOfPresentation() const
48{return PrsMgr_KOP_3D;}
49
50
eb4320f2 51void PrsMgr_Presentation3d::Display()
52{
53 Display (Standard_False);
7fd59977 54 myDisplayReason = Standard_False;
55}
56
eb4320f2 57void PrsMgr_Presentation3d::Display(const Standard_Boolean theIsHighlight)
58{
59 if (!myStructure->IsDisplayed())
60 {
61 myStructure->Display();
62 myDisplayReason = theIsHighlight;
63 }
64 else if (!myStructure->IsVisible())
65 {
66 myStructure->SetVisible (Standard_True);
67 myDisplayReason = theIsHighlight;
68 }
69}
70
eef7fc64 71void PrsMgr_Presentation3d::Erase ()
72{
73 // Erase structure from structure manager
74 myStructure->Erase();
75 // Clear groups and remove graphic structure
76 myStructure.Nullify();
77}
7fd59977 78
eb4320f2 79void PrsMgr_Presentation3d::SetVisible (const Standard_Boolean theValue)
80{
81 myStructure->SetVisible (theValue);
82}
83
7fd59977 84void PrsMgr_Presentation3d::Highlight () {
eb4320f2 85 Display (Standard_True);
7fd59977 86 myStructure->Highlight();}
87
88void PrsMgr_Presentation3d::Unhighlight () const {
89 myStructure->UnHighlight();
eb4320f2 90 if (myDisplayReason) myStructure->SetVisible (Standard_False);
7fd59977 91}
92
93void PrsMgr_Presentation3d::Clear() {
94 // This modification remove the contain of the structure:
95 // Consequence:
96 // 1. The memory zone of the group is reused
97 // 2. The speed for animation is constant
bbf32d01
K
98 //myPresentableObject = NULL;
99 SetUpdateStatus(Standard_True);
7fd59977 100 myStructure->Clear(Standard_True);
101 // myStructure->Clear(Standard_False);
102
103 myStructure->RemoveAll();
104}
105
106void PrsMgr_Presentation3d::Color(const Quantity_NameOfColor aColor){
eb4320f2 107 Display (Standard_True);
7fd59977 108 myStructure->Color(aColor);
109}
110
111void PrsMgr_Presentation3d::BoundBox() const {
112 myStructure->BoundBox();
113}
114
115Standard_Boolean PrsMgr_Presentation3d::IsDisplayed () const {
eb4320f2 116 return myStructure->IsDisplayed() && myStructure->IsVisible() && !myDisplayReason;
7fd59977 117}
118
119Standard_Boolean PrsMgr_Presentation3d::IsHighlighted () const {
120 return myStructure->IsHighlighted();
121}
122
123
124Standard_Integer PrsMgr_Presentation3d::DisplayPriority() const {
125return myStructure->DisplayPriority();
126}
127
128void PrsMgr_Presentation3d::SetDisplayPriority(const Standard_Integer TheNewPrior)
129{
130 myStructure->SetDisplayPriority(TheNewPrior);
131}
132
133Handle(Prs3d_Presentation) PrsMgr_Presentation3d::Presentation() const {
134 return myStructure;
135}
136void PrsMgr_Presentation3d::Connect(const Handle(PrsMgr_Presentation3d)& anOtherPresentation) const {
137 myStructure->Connect(anOtherPresentation->Presentation());
138}
139
140void PrsMgr_Presentation3d::Transform (const Handle(Geom_Transformation)& aTransformation) const {
141 myStructure->Transform(aTransformation);
142}
143
144void PrsMgr_Presentation3d::Place (const Quantity_Length X,
145 const Quantity_Length Y,
146 const Quantity_Length Z) const {
147 myStructure->Place(X,Y,Z);
148}
149
150void PrsMgr_Presentation3d::Multiply (const Handle(Geom_Transformation)& aTransformation) const {
151 myStructure->Multiply(aTransformation);
152}
153
154void PrsMgr_Presentation3d::Move (const Quantity_Length X,
155 const Quantity_Length Y,
156 const Quantity_Length Z) const {
157 myStructure->Move(X,Y,Z);
158}
159
160void PrsMgr_Presentation3d::SetShadingAspect(const Handle(Prs3d_ShadingAspect)& aShadingAspect) const {
161 myStructure->SetShadingAspect(aShadingAspect);
162}
163
164
165
166//=======================================================================
167//function : Compute
81bba717 168//purpose : Methods for hidden parts...
7fd59977 169//=======================================================================
170
171Handle(Graphic3d_Structure) PrsMgr_Presentation3d::
172Compute(const Handle(Graphic3d_DataStructureManager)& aProjector)
173{
174#ifdef DEB
81bba717 175 cout<<"passage in g = Compute(P) "<<endl;
7fd59977 176#endif
177 Handle(Prs3d_Presentation) g = new Prs3d_Presentation(Handle(PrsMgr_PresentationManager3d)::DownCast(PresentationManager())->StructureManager());
178 myPresentableObject->Compute(Projector(aProjector),g);
179 return g;
180}
181
182//=======================================================================
183//function : Compute
184//purpose :
185//=======================================================================
186
eb4320f2 187void PrsMgr_Presentation3d::Compute (const Handle(Graphic3d_Structure)& theStructure)
188{
189 Standard_Integer aDispMode = 0;
190
191 Standard_Integer aPresentationsNumber = myPresentableObject->myPresentations.Length();
192 for (Standard_Integer anIter = 1; anIter <= aPresentationsNumber; anIter++)
193 {
194 const PrsMgr_ModedPresentation& aModedPresentation = myPresentableObject->myPresentations.Value (anIter);
195 Handle(PrsMgr_Presentation) aPresentation = aModedPresentation.Presentation();
196 PrsMgr_Presentation3d* aPresentation3d = (PrsMgr_Presentation3d* )aPresentation.operator->();
197 if (aPresentation3d == this)
198 {
199 aDispMode = aModedPresentation.Mode();
200 break;
201 }
202 }
203
204 Handle(Prs3d_Presentation) aPrs3d = Handle(Prs3d_Presentation)::DownCast (theStructure);
205
206 myPresentableObject->Compute(
207 Handle(PrsMgr_PresentationManager3d)::DownCast (PresentationManager()),
208 aPrs3d,
209 aDispMode);
210}
211
212//=======================================================================
213//function : Compute
214//purpose :
215//=======================================================================
216
7fd59977 217void PrsMgr_Presentation3d::Compute(const Handle(Graphic3d_DataStructureManager)& aProjector,
218 const Handle(Graphic3d_Structure)& TheStructToFill)
219{
220#ifdef DEB
81bba717 221 cout<<"passage in Compute(P,Str)"<<endl;
7fd59977 222#endif
223 TheStructToFill->Clear();
224 const Handle(Prs3d_Presentation)& P = *((Handle(Prs3d_Presentation)*) &TheStructToFill);
225 myPresentableObject->Compute(Projector(aProjector),P);
226}
227
228//=======================================================================
229//function : Compute
230//purpose :
231//=======================================================================
232Handle(Graphic3d_Structure) PrsMgr_Presentation3d::
233Compute(const Handle(Graphic3d_DataStructureManager)& aProjector,
234 const Handle(Geom_Transformation)& TheTrsf)
235{
236#ifdef DEB
81bba717 237 cout<<"passage in G = Compute(P,Trsf)"<<endl;
7fd59977 238#endif
239 Handle(Prs3d_Presentation) g = new Prs3d_Presentation(Handle(PrsMgr_PresentationManager3d)::DownCast(PresentationManager())->StructureManager());
240
241
242 if(TheTrsf->Form()== gp_Translation){
243#ifdef DEB
244 cout<<"\tla Trsf est une translation"<<endl;
245#endif
246
247 myPresentableObject->Compute(Projector(aProjector),g);
248 g->Transform(TheTrsf);
249 }
250 else{
81bba717 251 // waiting that something is done in gp_Trsf...rob
7fd59977 252 Standard_Boolean good (Standard_True);
253 for (Standard_Integer i=1;i<=3 && good ;i++){
254 for (Standard_Integer j=1;j<=3 && good ;j++){
255 if(i!=j){
256 if(Abs(TheTrsf->Value(i,j)) > Precision::Confusion())
257 good = Standard_False;
258 }
259 }
260 }
261
262 if(good){
263#ifdef DEB
81bba717 264 cout<<"\t it is checked if Trsf is a Translation"<<endl;
7fd59977 265#endif
266 myPresentableObject->Compute(Projector(aProjector),g);
267 g->Transform(TheTrsf);
268
269 }
270 else{
271#ifdef DEB
81bba717 272 cout<<"\t Trsf is not only translation..."<<endl;
7fd59977 273#endif
274 myPresentableObject->Compute(Projector(aProjector),TheTrsf,g);
275 }
276 }
277 return g;
278}
279
280//=======================================================================
281//function : Compute
282//purpose :
283//=======================================================================
284void PrsMgr_Presentation3d::Compute(const Handle(Graphic3d_DataStructureManager)& aProjector,
285 const Handle(Geom_Transformation)& TheTrsf,
286 const Handle(Graphic3d_Structure)& TheStructToFill)
287{
288
289#ifdef DEB
81bba717 290 cout<<"passage in Compute(P,Trsf,Str)"<<endl;
7fd59977 291#endif
292
293 Handle(Prs3d_Presentation) P = *((Handle(Prs3d_Presentation)*)&TheStructToFill);
294
295#ifdef IMP040200
296 TheStructToFill->Clear();
297 myPresentableObject->Compute(Projector(aProjector),TheTrsf,P);
81bba717 298#else //Does not work properly, HLR seems deactivated for view rotation
7fd59977 299 if(TheTrsf->Form()== gp_Translation){
300#ifdef DEB
81bba717 301 cout<<"\t Trsf is a translation"<<endl;
7fd59977 302#endif
303// myPresentableObject->Compute(Projector(aProjector),P);
304 P->Transform(TheTrsf);
305 }
306 else{
81bba717 307 // waiting that something is done in gp_Trsf...rob
7fd59977 308 Standard_Boolean good (Standard_True);
309 for (Standard_Integer i=1;i<=3 && good ;i++){
310 for (Standard_Integer j=1;j<=3 && good ;j++){
311 if(i!=j){
312 if(Abs(TheTrsf->Value(i,j)) > Precision::Confusion())
313 good = Standard_False;
314 }
315 }
316 }
317 if(good && !TheStructToFill->IsEmpty()){
318#ifdef DEB
81bba717 319 cout<<"\t it is checked if Trsf is a Translation"<<endl;
7fd59977 320#endif
321
322 P->Transform(TheTrsf);
323 }
324 else{
325 TheStructToFill->Clear();
326
327#ifdef DEB
81bba717 328 cout<<"\t Trsf is not only translation..."<<endl;
7fd59977 329#endif
330
331 myPresentableObject->Compute(Projector(aProjector),TheTrsf,P);
332 }
333 }
334#endif
335}
336
337
338
339
340
341
342//=======================================================================
343//function : Projector
344//purpose :
345//=======================================================================
346
347Handle(Prs3d_Projector) PrsMgr_Presentation3d::Projector(const Handle(Graphic3d_DataStructureManager)& aProjector) {
348 Visual3d_ViewOrientation VO = Handle(Visual3d_View)::DownCast(aProjector)->ViewOrientation();
349 Standard_Real DX, DY, DZ,XAt, YAt , ZAt,XUp, YUp, ZUp;
350 VO.ViewReferencePlane().Coord(DX, DY, DZ);
351 VO.ViewReferencePoint().Coord(XAt,YAt,ZAt);
352 VO.ViewReferenceUp().Coord(XUp, YUp, ZUp);
353 Visual3d_ViewMapping VM = Handle(Visual3d_View)::DownCast(aProjector)->ViewMapping();
354 Standard_Boolean pers = (VM.Projection() == Visual3d_TOP_PERSPECTIVE);
355 Standard_Real focale = 0.0 ;
356 if (pers) {
357 Standard_Real Xrp,Yrp,Zrp,ViewPlane,FrontPlane ;
358 Graphic3d_Vertex Prp = VM.ProjectionReferencePoint() ;
359 Prp.Coord(Xrp,Yrp,Zrp);
360 FrontPlane = VM.FrontPlaneDistance() ;
361 ViewPlane = VM.ViewPlaneDistance() ;
362 focale = FrontPlane + Zrp - ViewPlane ;
363 }
364 Handle(Prs3d_Projector) Proj = new Prs3d_Projector(pers,focale,DX, DY, DZ,XAt, YAt , ZAt,XUp, YUp, ZUp);
365 return Proj;
366
367}
368
369void PrsMgr_Presentation3d::Destroy () {
370 if (!myStructure.IsNull())
371 myStructure->Clear();
372 myStructure.Nullify();
373}
59f45b7c 374
375//=======================================================================
376//function : SetZLayer
377//purpose :
378//=======================================================================
379
380void PrsMgr_Presentation3d::SetZLayer (Standard_Integer theLayerId)
381{
382 myStructure->SetZLayer (theLayerId);
383}
384
385//=======================================================================
386//function : GetZLayer
387//purpose :
388//=======================================================================
389
390Standard_Integer PrsMgr_Presentation3d::GetZLayer () const
391{
392 return myStructure->GetZLayer ();
393}