1 // Created on: 1997-12-16
2 // Created by: Jean Louis Frenkel
3 // Copyright (c) 1997-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 #include <PrsMgr_PresentableObject.ixx>
18 #include <PrsMgr_Presentation.hxx>
19 #include <PrsMgr_ModedPresentation.hxx>
20 #include <PrsMgr_PresentationManager.hxx>
21 #include <TColStd_ListIteratorOfListOfInteger.hxx>
22 #include <TColStd_MapOfInteger.hxx>
23 #include <Graphic3d_TypeOfStructure.hxx>
24 #include <Geom_Transformation.hxx>
26 //=======================================================================
27 //function : PrsMgr_PresentableObject
29 //=======================================================================
30 PrsMgr_PresentableObject::PrsMgr_PresentableObject (const PrsMgr_TypeOfPresentation3d theType)
31 : myTypeOfPresentation3d (theType),
32 myIsMutable (Standard_False)
34 myTransformPersistence.Flag = 0;
35 myTransformPersistence.Point.x = 0.0;
36 myTransformPersistence.Point.y = 0.0;
37 myTransformPersistence.Point.z = 0.0;
40 //=======================================================================
43 //=======================================================================
44 void PrsMgr_PresentableObject::Fill (const Handle(PrsMgr_PresentationManager)& thePrsMgr,
45 const Handle(PrsMgr_Presentation)& thePrs,
46 const Standard_Integer theMode)
48 Handle(Prs3d_Presentation) aStruct3d = thePrs->Presentation();
49 Compute (thePrsMgr, aStruct3d, theMode);
50 UpdateLocation (aStruct3d);
51 aStruct3d->SetClipPlanes (myClipPlanes);
52 aStruct3d->SetTransformPersistence (GetTransformPersistenceMode(), GetTransformPersistencePoint());
55 //=======================================================================
58 //=======================================================================
59 void PrsMgr_PresentableObject::Compute (const Handle(PrsMgr_PresentationManager)& /*aPresentationManager*/,
60 const Handle(Prs3d_Presentation)& /*aPresentation*/,
61 const Standard_Integer /*aMode*/)
63 Standard_NotImplemented::Raise("cannot compute in a 3d visualizer");
66 //=======================================================================
69 //=======================================================================
70 void PrsMgr_PresentableObject::Compute(const Handle(Prs3d_Projector)& /*aProjector*/,
71 const Handle(Prs3d_Presentation)& /*aPresentation*/)
73 Standard_NotImplemented::Raise("cannot compute under a specific projector");
76 //=======================================================================
79 //=======================================================================
80 void PrsMgr_PresentableObject::Compute(const Handle(Prs3d_Projector)& /* aProjector*/,
81 const Handle(Geom_Transformation)& /*aTrsf*/,
82 const Handle(Prs3d_Presentation)& /*aPresentation*/)
84 Standard_NotImplemented::Raise("cannot compute under a specific projector");
87 //=======================================================================
90 //=======================================================================
91 void PrsMgr_PresentableObject::Update (const Standard_Boolean AllModes) {
92 Standard_Integer l = myPresentations.Length();
93 Handle(PrsMgr_PresentationManager) PM;
94 for (Standard_Integer i=1; i <= l; i++) {
95 PM = myPresentations(i).Presentation()->PresentationManager();
97 PM->Update(this,myPresentations(i).Mode());
99 if(PM->IsDisplayed(this,myPresentations(i).Mode()) ||
100 PM->IsHighlighted(this,myPresentations(i).Mode())){
101 PM->Update(this,myPresentations(i).Mode());
104 SetToUpdate(myPresentations(i).Mode());
109 //=======================================================================
112 //=======================================================================
113 void PrsMgr_PresentableObject::Update (const Standard_Integer aMode, const Standard_Boolean ClearOther) {
114 Standard_Integer l = myPresentations.Length();
115 for (Standard_Integer i=1; i <= l; i++) {
116 if( myPresentations(i).Mode() == aMode){
117 Handle(PrsMgr_PresentationManager) PM=
118 myPresentations(i).Presentation()->PresentationManager();
120 if(PM->IsDisplayed(this,aMode) ||
121 PM->IsHighlighted(this,aMode)){
122 PM->Update(this,aMode);
123 myPresentations(i).Presentation()->SetUpdateStatus(Standard_False);
127 SetToUpdate(myPresentations(i).Mode());
132 PrsMgr_Presentations save;
133 save = myPresentations;
134 myPresentations.Clear();
135 for (Standard_Integer i=1; i <= l; i++) {
136 if( save(i).Mode() == aMode) myPresentations.Append(save(i));
142 //=======================================================================
143 //function : Presentations
145 //=======================================================================
146 PrsMgr_Presentations& PrsMgr_PresentableObject::Presentations() {
147 return myPresentations;
150 //=======================================================================
151 //function : HasLocation
153 //=======================================================================
154 Standard_Boolean PrsMgr_PresentableObject::HasLocation() const
156 return !Location().IsIdentity();
159 //=======================================================================
160 //function : SetToUpdate
162 //=======================================================================
163 void PrsMgr_PresentableObject::SetToUpdate(const Standard_Integer aMode)
165 for(Standard_Integer IP =1; IP<=myPresentations.Length();IP++){
166 if(myPresentations(IP).Mode()==aMode)
167 myPresentations(IP).Presentation()->SetUpdateStatus(Standard_True);
171 //=======================================================================
172 //function : SetToUpdate
174 //=======================================================================
175 void PrsMgr_PresentableObject::SetToUpdate()
177 for(Standard_Integer IP =1; IP<=myPresentations.Length();IP++){
178 myPresentations(IP).Presentation()->SetUpdateStatus(Standard_True);
182 //=======================================================================
183 //function : ToBeUpdated
184 //purpose : gets the list of modes to be updated
185 //=======================================================================
186 void PrsMgr_PresentableObject::ToBeUpdated(TColStd_ListOfInteger& OutList) const
189 // on dimensionne les buckets a la taille de la seq.
190 static TColStd_MapOfInteger MI(myPresentations.Length());
192 for(Standard_Integer IP =1; IP<=myPresentations.Length();IP++){
193 const PrsMgr_ModedPresentation& MP = myPresentations(IP);
194 if(MP.Presentation()->MustBeUpdated())
195 if(!MI.Contains(MP.Mode())){
196 OutList.Append(MP.Mode());
203 //=======================================================================
204 //function : SetTypeOfPresentation
206 //=======================================================================
207 void PrsMgr_PresentableObject::SetTypeOfPresentation (const PrsMgr_TypeOfPresentation3d theType)
209 myTypeOfPresentation3d = theType;
210 for(Standard_Integer aPrsIter = 1; aPrsIter <= myPresentations.Length(); ++aPrsIter)
212 const Handle(PrsMgr_Presentation)& aPrs = myPresentations (aPrsIter).Presentation();
213 aPrs->Presentation()->SetVisual (myTypeOfPresentation3d == PrsMgr_TOP_ProjectorDependant
214 ? Graphic3d_TOS_COMPUTED
215 : Graphic3d_TOS_ALL);
219 //=======================================================================
220 //function : SetLocation
221 //purpose : WARNING : use with only 3D objects...
222 //=======================================================================
223 void PrsMgr_PresentableObject::SetLocation(const TopLoc_Location& aLoc)
225 if(aLoc.IsIdentity()) return;
230 //=======================================================================
231 //function : ReSetLocation
233 //=======================================================================
234 void PrsMgr_PresentableObject::ResetLocation()
236 TopLoc_Location aLoc;
237 Handle(Geom_Transformation) aTrsf = new Geom_Transformation (aLoc.Transformation());
238 for (Standard_Integer aPrsIter = 1; aPrsIter <= myPresentations.Length(); ++aPrsIter)
240 myPresentations (aPrsIter).Presentation()->Transform (aTrsf);
245 //=======================================================================
246 //function : UpdateLocation
248 //=======================================================================
249 void PrsMgr_PresentableObject::UpdateLocation()
256 Handle(Geom_Transformation) aTrsf = new Geom_Transformation (Location().Transformation());
257 if (aTrsf->Trsf().Form() == gp_Identity)
262 for (Standard_Integer aPrsIter = 1; aPrsIter <= myPresentations.Length(); ++aPrsIter)
264 myPresentations (aPrsIter).Presentation()->Transform (aTrsf);
268 //=======================================================================
269 //function : UpdateLocation
271 //=======================================================================
272 void PrsMgr_PresentableObject::UpdateLocation(const Handle(Prs3d_Presentation)& P)
274 if(myLocation.IsIdentity()) return;
275 Handle(Geom_Transformation) G = new Geom_Transformation(Location().Transformation());
280 //=======================================================================
281 //function : SetTransformPersistence
283 //=======================================================================
284 void PrsMgr_PresentableObject::SetTransformPersistence (const Graphic3d_TransModeFlags& theFlag,
285 const gp_Pnt& thePoint)
287 myTransformPersistence.Flag = theFlag;
288 myTransformPersistence.Point.x = (Standard_ShortReal )thePoint.X();
289 myTransformPersistence.Point.y = (Standard_ShortReal )thePoint.Y();
290 myTransformPersistence.Point.z = (Standard_ShortReal )thePoint.Z();
291 for (Standard_Integer aPrsIter = 1; aPrsIter <= myPresentations.Length(); ++aPrsIter)
293 const Handle(PrsMgr_Presentation)& aPrs3d = myPresentations (aPrsIter).Presentation();
295 && !aPrs3d->Presentation().IsNull())
297 aPrs3d->Presentation()->SetTransformPersistence (theFlag, thePoint);
298 aPrs3d->Presentation()->ReCompute();
303 //=======================================================================
304 //function : SetTransformPersistence
306 //=======================================================================
307 void PrsMgr_PresentableObject::SetTransformPersistence(
308 const Graphic3d_TransModeFlags& TheFlag )
310 SetTransformPersistence( TheFlag, gp_Pnt(0,0,0) );
313 //=======================================================================
314 //function : GetTransformPersistence
316 //=======================================================================
317 Graphic3d_TransModeFlags PrsMgr_PresentableObject::GetTransformPersistenceMode() const
319 return myTransformPersistence.Flag;
322 //=======================================================================
323 //function : GetTransformPersistence
325 //=======================================================================
326 gp_Pnt PrsMgr_PresentableObject::GetTransformPersistencePoint() const
328 return gp_Pnt( myTransformPersistence.Point.x, myTransformPersistence.Point.y, myTransformPersistence.Point.z );
331 //=======================================================================
332 //function : SetZLayer
334 //=======================================================================
335 void PrsMgr_PresentableObject::SetZLayer
336 (const Handle(PrsMgr_PresentationManager)& thePrsMgr,
337 const Standard_Integer theLayerId)
339 if (!thePrsMgr.IsNull())
340 thePrsMgr->SetZLayer (this, theLayerId);
343 //=======================================================================
344 //function : GetZLayer
346 //=======================================================================
347 Standard_Integer PrsMgr_PresentableObject::GetZLayer
348 (const Handle(PrsMgr_PresentationManager)& thePrsMgr) const
350 if (!thePrsMgr.IsNull())
351 return thePrsMgr->GetZLayer (this);
356 // =======================================================================
357 // function : AddClipPlane
359 // =======================================================================
360 void PrsMgr_PresentableObject::AddClipPlane (const Handle(Graphic3d_ClipPlane)& thePlane)
362 // add to collection and process changes
363 myClipPlanes.Append (thePlane);
367 // =======================================================================
368 // function : RemoveClipPlane
370 // =======================================================================
371 void PrsMgr_PresentableObject::RemoveClipPlane (const Handle(Graphic3d_ClipPlane)& thePlane)
373 // remove from collection and process changes
374 Graphic3d_SequenceOfHClipPlane::Iterator aPlaneIt (myClipPlanes);
375 for (; aPlaneIt.More(); aPlaneIt.Next())
377 const Handle(Graphic3d_ClipPlane)& aPlane = aPlaneIt.Value();
378 if (aPlane != thePlane)
381 myClipPlanes.Remove (aPlaneIt);
387 // =======================================================================
388 // function : SetClipPlanes
390 // =======================================================================
391 void PrsMgr_PresentableObject::SetClipPlanes (const Graphic3d_SequenceOfHClipPlane& thePlanes)
393 // change collection and process changes
394 myClipPlanes = thePlanes;
398 // =======================================================================
399 // function : UpdateClipping
401 // =======================================================================
402 void PrsMgr_PresentableObject::UpdateClipping()
404 // affect generated structures
405 for (Standard_Integer aPrsIt = 1; aPrsIt <= myPresentations.Length(); ++aPrsIt)
407 // pass over presentation manager 3d mechanism right to the structures -
408 // we do not interested in display mode collections.
409 const PrsMgr_ModedPresentation& aModedPrs = myPresentations (aPrsIt);
410 if (aModedPrs.Presentation().IsNull()
411 || aModedPrs.Presentation()->Presentation().IsNull())
416 aModedPrs.Presentation()->Presentation()->SetClipPlanes (myClipPlanes);
420 // =======================================================================
421 // function : SetMutable
423 // =======================================================================
424 void PrsMgr_PresentableObject::SetMutable (const Standard_Boolean theIsMutable)
426 if (myIsMutable == theIsMutable)
431 myIsMutable = theIsMutable;
432 for (Standard_Integer aPrsIter = 1; aPrsIter <= myPresentations.Length(); ++aPrsIter)
434 const PrsMgr_ModedPresentation& aModedPrs = myPresentations (aPrsIter);
435 if (aModedPrs.Presentation().IsNull()
436 || aModedPrs.Presentation()->Presentation().IsNull())
441 aModedPrs.Presentation()->Presentation()->SetMutable (theIsMutable);
445 // =======================================================================
446 // function : IsMutable
448 // =======================================================================
449 const Standard_Boolean PrsMgr_PresentableObject::IsMutable() const