summaryrefslogtreecommitdiff
path: root/src/PrsMgr/PrsMgr_Presentation3d.cxx
blob: e60c05b6fc7012e0cb4a39beb6e62dbcc71b58cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
// File:	PrsMgr_Presentation3d.cxx
// Created:	Thu Oct 21 13:11:19 1993
// Author:	Jean-Louis FRENKEL
// Modified by  rob 09-oct-96
//		<jlf@stylox>


#define IMP040200	//GG Recompute HLR after transformation
//			in all the case.

#include <PrsMgr_Presentation3d.ixx>
#include <PrsMgr_PresentationManager.hxx>
#include <PrsMgr_Prs.hxx>
#include <Visual3d_View.hxx>
#include <Visual3d_ViewOrientation.hxx>
#include <Graphic3d_Structure.hxx>
#include <Precision.hxx>

PrsMgr_Presentation3d::PrsMgr_Presentation3d (const Handle(PrsMgr_PresentationManager3d)& aPresentationManager, 
                                              const Handle(PrsMgr_PresentableObject)& aPresentableObject)
: PrsMgr_Presentation(aPresentationManager), 
  myDisplayReason(Standard_False),
  myPresentableObject (aPresentableObject.operator->())
{
  myStructure = new PrsMgr_Prs(aPresentationManager->StructureManager(),
                               this, aPresentableObject->TypeOfPresentation3d());
  myStructure->SetOwner(myPresentableObject);
}

PrsMgr_KindOfPrs PrsMgr_Presentation3d::KindOfPresentation() const
{return PrsMgr_KOP_3D;}


void PrsMgr_Presentation3d::Display () {
  myStructure->Display();
  myDisplayReason = Standard_False;
}

void PrsMgr_Presentation3d::Erase () const {
  myStructure->Erase();}

void PrsMgr_Presentation3d::Highlight () {
  if(!myStructure->IsDisplayed()) {
    myStructure->Display();
    myDisplayReason = Standard_True;
  }
  myStructure->Highlight();}

void PrsMgr_Presentation3d::Unhighlight () const {
  myStructure->UnHighlight();
  if(myDisplayReason) myStructure->Erase();
}

void PrsMgr_Presentation3d::Clear() {
  // This modification remove the contain of the structure:
  // Consequence: 
  //    1. The memory zone of the group is reused
  //    2. The speed for animation is constant
  //myPresentableObject = NULL;
  SetUpdateStatus(Standard_True);
  myStructure->Clear(Standard_True);
  //  myStructure->Clear(Standard_False);

  myStructure->RemoveAll();
}

void PrsMgr_Presentation3d::Color(const Quantity_NameOfColor aColor){
  Standard_Boolean ImmMode = myPresentationManager->IsImmediateModeOn();
  if(!ImmMode){
    if(!myStructure->IsDisplayed()) {
      myStructure->Display();
      myDisplayReason = Standard_True;
    }
  }
  myStructure->Color(aColor);
}

void PrsMgr_Presentation3d::BoundBox() const {
   myStructure->BoundBox();
}

Standard_Boolean PrsMgr_Presentation3d::IsDisplayed () const {
  return myStructure->IsDisplayed() && !myDisplayReason;
}        

Standard_Boolean PrsMgr_Presentation3d::IsHighlighted () const {
  return myStructure->IsHighlighted();
}


Standard_Integer PrsMgr_Presentation3d::DisplayPriority() const {
return myStructure->DisplayPriority();
}

void PrsMgr_Presentation3d::SetDisplayPriority(const Standard_Integer TheNewPrior)
{
  myStructure->SetDisplayPriority(TheNewPrior);
}

Handle(Prs3d_Presentation) PrsMgr_Presentation3d::Presentation() const {
  return myStructure;
}
void PrsMgr_Presentation3d::Connect(const Handle(PrsMgr_Presentation3d)& anOtherPresentation) const {
  myStructure->Connect(anOtherPresentation->Presentation());
}

void PrsMgr_Presentation3d::Transform (const Handle(Geom_Transformation)& aTransformation) const {
  myStructure->Transform(aTransformation);
}

void PrsMgr_Presentation3d::Place (const Quantity_Length X,
			      const Quantity_Length Y,
			      const Quantity_Length Z) const {
  myStructure->Place(X,Y,Z);
}

void PrsMgr_Presentation3d::Multiply (const Handle(Geom_Transformation)& aTransformation) const {
  myStructure->Multiply(aTransformation);
}

void PrsMgr_Presentation3d::Move (const Quantity_Length X,
			      const Quantity_Length Y,
			      const Quantity_Length Z) const {
  myStructure->Move(X,Y,Z);
}

void PrsMgr_Presentation3d::SetShadingAspect(const Handle(Prs3d_ShadingAspect)& aShadingAspect) const {
  myStructure->SetShadingAspect(aShadingAspect);
}



//=======================================================================
//function : Compute
//purpose  : Methods for hidden parts...
//=======================================================================

Handle(Graphic3d_Structure) PrsMgr_Presentation3d::
Compute(const Handle(Graphic3d_DataStructureManager)& aProjector)
{
#ifdef DEB
  cout<<"passage in g = Compute(P) "<<endl;
#endif
  Handle(Prs3d_Presentation) g = new Prs3d_Presentation(Handle(PrsMgr_PresentationManager3d)::DownCast(PresentationManager())->StructureManager());
  myPresentableObject->Compute(Projector(aProjector),g);
  return g;
}

//=======================================================================
//function : Compute
//purpose  : 
//=======================================================================

void PrsMgr_Presentation3d::Compute(const Handle(Graphic3d_DataStructureManager)& aProjector,
				    const Handle(Graphic3d_Structure)& TheStructToFill)
{
#ifdef DEB
  cout<<"passage in Compute(P,Str)"<<endl;
#endif
  TheStructToFill->Clear();
  const Handle(Prs3d_Presentation)& P = *((Handle(Prs3d_Presentation)*) &TheStructToFill);
  myPresentableObject->Compute(Projector(aProjector),P);
}

//=======================================================================
//function : Compute
//purpose  : 
//=======================================================================
Handle(Graphic3d_Structure) PrsMgr_Presentation3d::
Compute(const Handle(Graphic3d_DataStructureManager)& aProjector,
	const Handle(Geom_Transformation)& TheTrsf)
{
#ifdef DEB
  cout<<"passage in G =  Compute(P,Trsf)"<<endl;
#endif
  Handle(Prs3d_Presentation) g = new Prs3d_Presentation(Handle(PrsMgr_PresentationManager3d)::DownCast(PresentationManager())->StructureManager());


  if(TheTrsf->Form()== gp_Translation){
#ifdef DEB
    cout<<"\tla Trsf est une translation"<<endl;
#endif
   
    myPresentableObject->Compute(Projector(aProjector),g);
    g->Transform(TheTrsf);
  }
  else{
    // waiting that something is done in gp_Trsf...rob
    Standard_Boolean good (Standard_True);
    for (Standard_Integer i=1;i<=3 && good ;i++){
      for (Standard_Integer j=1;j<=3 && good ;j++){
	if(i!=j){
	  if(Abs(TheTrsf->Value(i,j)) > Precision::Confusion())
	    good = Standard_False;
	}
      }
    }
    
    if(good){
#ifdef DEB
      cout<<"\t it is checked if Trsf is a Translation"<<endl;
#endif
    myPresentableObject->Compute(Projector(aProjector),g);
    g->Transform(TheTrsf);
      
    }
    else{
#ifdef DEB
      cout<<"\t Trsf is not only translation..."<<endl;
#endif
      myPresentableObject->Compute(Projector(aProjector),TheTrsf,g);
    }
  }
  return g;
}

//=======================================================================
//function : Compute
//purpose  : 
//=======================================================================
void PrsMgr_Presentation3d::Compute(const Handle(Graphic3d_DataStructureManager)& aProjector,
				    const Handle(Geom_Transformation)& TheTrsf,
				    const Handle(Graphic3d_Structure)& TheStructToFill)
{
  
#ifdef DEB
  cout<<"passage in Compute(P,Trsf,Str)"<<endl;
#endif

  Handle(Prs3d_Presentation) P = *((Handle(Prs3d_Presentation)*)&TheStructToFill);
 
#ifdef IMP040200	
  TheStructToFill->Clear();
  myPresentableObject->Compute(Projector(aProjector),TheTrsf,P);
#else	//Does not work properly, HLR seems deactivated for view rotation 
  if(TheTrsf->Form()== gp_Translation){
#ifdef DEB
    cout<<"\t Trsf is a translation"<<endl;
#endif
//    myPresentableObject->Compute(Projector(aProjector),P);
    P->Transform(TheTrsf);
  }
  else{
    //  waiting that something is done in gp_Trsf...rob
    Standard_Boolean good (Standard_True);
    for (Standard_Integer i=1;i<=3 && good ;i++){
      for (Standard_Integer j=1;j<=3 && good ;j++){
	if(i!=j){
	  if(Abs(TheTrsf->Value(i,j)) > Precision::Confusion())
	    good = Standard_False;
	}
      }
    }
    if(good && !TheStructToFill->IsEmpty()){
#ifdef DEB
      cout<<"\t it is checked if Trsf is a Translation"<<endl;
#endif
      
      P->Transform(TheTrsf);
    }
    else{
      TheStructToFill->Clear();
      
#ifdef DEB
      cout<<"\t Trsf is not only translation..."<<endl;
#endif
      
      myPresentableObject->Compute(Projector(aProjector),TheTrsf,P);
    }
  }
#endif
}






//=======================================================================
//function : Projector
//purpose  : 
//=======================================================================

Handle(Prs3d_Projector) PrsMgr_Presentation3d::Projector(const Handle(Graphic3d_DataStructureManager)& aProjector) {
  Visual3d_ViewOrientation VO = Handle(Visual3d_View)::DownCast(aProjector)->ViewOrientation();
  Standard_Real DX, DY, DZ,XAt, YAt , ZAt,XUp, YUp, ZUp;
  VO.ViewReferencePlane().Coord(DX, DY, DZ);
  VO.ViewReferencePoint().Coord(XAt,YAt,ZAt);
  VO.ViewReferenceUp().Coord(XUp, YUp, ZUp);
  Visual3d_ViewMapping VM =  Handle(Visual3d_View)::DownCast(aProjector)->ViewMapping();
  Standard_Boolean pers = (VM.Projection() == Visual3d_TOP_PERSPECTIVE);
    Standard_Real focale = 0.0 ;
  if (pers) {
    Standard_Real Xrp,Yrp,Zrp,ViewPlane,FrontPlane ;
    Graphic3d_Vertex Prp = VM.ProjectionReferencePoint() ;
    Prp.Coord(Xrp,Yrp,Zrp);
    FrontPlane = VM.FrontPlaneDistance() ;
    ViewPlane = VM.ViewPlaneDistance() ;
    focale = FrontPlane + Zrp - ViewPlane ;
  }
  Handle(Prs3d_Projector) Proj = new Prs3d_Projector(pers,focale,DX, DY, DZ,XAt, YAt , ZAt,XUp, YUp, ZUp);
  return Proj;

}

void PrsMgr_Presentation3d::Destroy () {
  if (!myStructure.IsNull())
    myStructure->Clear();
  myStructure.Nullify();
}