1df00902fa838f28e9d775bd71e915e381c4ca1e
[occt.git] / src / PrsMgr / PrsMgr_PresentationManager3d.cxx
1 // Copyright (c) 1998-1999 Matra Datavision
2 // Copyright (c) 1999-2012 OPEN CASCADE SAS
3 //
4 // The content of this file is subject to the Open CASCADE Technology Public
5 // License Version 6.5 (the "License"). You may not use the content of this file
6 // except in compliance with the License. Please obtain a copy of the License
7 // at http://www.opencascade.org and read it completely before using this file.
8 //
9 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
10 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
11 //
12 // The Original Code and all software distributed under the License is
13 // distributed on an "AS IS" basis, without warranty of any kind, and the
14 // Initial Developer hereby disclaims all such warranties, including without
15 // limitation, any warranties of merchantability, fitness for a particular
16 // purpose or non-infringement. Please see the License for the specific terms
17 // and conditions governing the rights and limitations under the License.
18
19
20 #include <PrsMgr_PresentationManager3d.ixx>
21 #include <PrsMgr_Presentation3d.hxx>
22 #include <Prs3d_ShadingAspect.hxx>
23 #include <Visual3d_TransientManager.hxx>
24 #include <V3d_View.hxx>
25 #include <TColStd_ListIteratorOfListOfTransient.hxx>
26
27 PrsMgr_PresentationManager3d::PrsMgr_PresentationManager3d (const Handle(Graphic3d_StructureManager)& aStructureManager):myStructureManager(aStructureManager) {}
28
29 Standard_Boolean PrsMgr_PresentationManager3d::Is3D() const
30 {return Standard_True;}
31
32 Handle(PrsMgr_Presentation) PrsMgr_PresentationManager3d::newPresentation (const Handle(PrsMgr_PresentableObject) & aPresentableObject) {
33   
34   return new PrsMgr_Presentation3d(this,aPresentableObject);
35 }
36
37 void PrsMgr_PresentationManager3d::Connect(const Handle(PrsMgr_PresentableObject)& aPresentableObject, const Handle(PrsMgr_PresentableObject)& anOtherObject, const Standard_Integer aMode, const Standard_Integer anOtherMode)  {
38   if (!HasPresentation(aPresentableObject,aMode)){
39     AddPresentation(aPresentableObject,aMode);
40   }
41   if (!HasPresentation(anOtherObject,anOtherMode)){
42     AddPresentation(anOtherObject,anOtherMode);
43   }
44    CastPresentation(aPresentableObject,aMode)->Connect(CastPresentation(anOtherObject,aMode));
45 }
46
47 //=======================================================================
48 //function : Transform
49 //purpose  : 
50 //=======================================================================
51 void PrsMgr_PresentationManager3d::Transform(const Handle(PrsMgr_PresentableObject)& aPresentableObject,const Handle(Geom_Transformation)& aTransformation, const Standard_Integer aMode) {
52 CastPresentation(aPresentableObject,aMode)->Transform(aTransformation);
53
54
55 //=======================================================================
56 //function : Place
57 //purpose  : 
58 //=======================================================================
59
60 void PrsMgr_PresentationManager3d::Place(const Handle(PrsMgr_PresentableObject)& aPresentableObject, const Quantity_Length X,const Quantity_Length Y,const Quantity_Length Z,const Standard_Integer aMode) {
61   CastPresentation(aPresentableObject,aMode)->Place(X,Y,Z);
62 }
63
64 //=======================================================================
65 //function : Multiply
66 //purpose  : 
67 //=======================================================================
68
69 void PrsMgr_PresentationManager3d::Multiply(const Handle(PrsMgr_PresentableObject)& aPresentableObject,const Handle(Geom_Transformation)& aTransformation, const Standard_Integer aMode) {
70   CastPresentation(aPresentableObject,aMode)->Multiply(aTransformation);
71 }
72
73 //=======================================================================
74 //function : Move
75 //purpose  : 
76 //=======================================================================
77
78 void PrsMgr_PresentationManager3d::Move(const Handle(PrsMgr_PresentableObject)& aPresentableObject, const Quantity_Length X,const Quantity_Length Y,const Quantity_Length Z,const Standard_Integer aMode) {
79   CastPresentation(aPresentableObject,aMode)->Move(X,Y,Z);
80 }
81
82 //=======================================================================
83 //function : Color
84 //purpose  : 
85 //=======================================================================
86
87 void PrsMgr_PresentationManager3d::Color(const Handle(PrsMgr_PresentableObject)& aPresentableObject, const Quantity_NameOfColor aColor, const Standard_Integer aMode) {
88   if (!HasPresentation(aPresentableObject,aMode)){
89     AddPresentation(aPresentableObject,aMode);
90   }
91   else if(Presentation(aPresentableObject,aMode)->MustBeUpdated()){
92     Update(aPresentableObject,aMode);
93   }
94   CastPresentation(aPresentableObject,aMode)->Color(aColor); 
95   
96   if(myImmediateMode)
97     Add(aPresentableObject,aMode);
98
99 }
100
101 //=======================================================================
102 //function : BoundBox
103 //purpose  : 
104 //=======================================================================
105
106 void PrsMgr_PresentationManager3d::BoundBox(const Handle(PrsMgr_PresentableObject)& aPresentableObject, const Standard_Integer aMode) {
107   if (!HasPresentation(aPresentableObject,aMode)){
108     AddPresentation(aPresentableObject,aMode);
109   }
110   else if(Presentation(aPresentableObject,aMode)->MustBeUpdated()){
111     Update(aPresentableObject,aMode);
112   }
113   CastPresentation(aPresentableObject,aMode)->BoundBox();
114 }
115 //=======================================================================
116 //function : SetShadingAspect
117 //purpose  : 
118 //=======================================================================
119
120 //POP pour K4L
121 void PrsMgr_PresentationManager3d::SetShadingAspect(const Handle(PrsMgr_PresentableObject)& aPresentableObject, const Quantity_NameOfColor aColor, const Graphic3d_NameOfMaterial aMaterial, const Standard_Integer aMode) {
122 //void PrsMgr_PresentationManager3d::SetShadingAspect(const Handle(PrsMgr_PresentableObject)& aPresentableObject, const Quantity_NameOfColor aColor, const Graphic3d_NameOfPhysicalMaterial aMaterial, const Standard_Integer aMode) {
123
124   Handle(Prs3d_ShadingAspect) sa = new Prs3d_ShadingAspect;
125   sa->SetColor(aColor);
126   sa->SetMaterial(aMaterial);
127   SetShadingAspect(aPresentableObject,sa,aMode);
128 }
129
130 void PrsMgr_PresentationManager3d::SetShadingAspect(const Handle(PrsMgr_PresentableObject)& aPresentableObject, const Handle(Prs3d_ShadingAspect)& aShadingAspect, const Standard_Integer aMode) {
131
132   if (HasPresentation(aPresentableObject,aMode)){
133     CastPresentation(aPresentableObject,aMode)->SetShadingAspect(aShadingAspect);
134   }
135 }
136
137
138 //=======================================================================
139 //function : CastPresentation
140 //purpose  : 
141 //=======================================================================
142
143 Handle(PrsMgr_Presentation3d) PrsMgr_PresentationManager3d::CastPresentation(const Handle(PrsMgr_PresentableObject)& aPresentableObject, const Standard_Integer aMode) const {
144   return Handle(PrsMgr_Presentation3d)::DownCast(Presentation(aPresentableObject,aMode));
145 }
146
147
148
149 //=======================================================================
150 //function : BeginDraw
151 //purpose  : 
152 //=======================================================================
153
154 void PrsMgr_PresentationManager3d::BeginDraw()
155 {
156   PrsMgr_PresentationManager::BeginDraw();
157   myStrList.Clear();
158 }
159
160 //=======================================================================
161 //function : EndDraw
162 //purpose  : 
163 //=======================================================================
164
165 void PrsMgr_PresentationManager3d::EndDraw(const Handle(Viewer_View)& aView, const Standard_Boolean DoubleBuffer) {
166   
167   
168   Handle(V3d_View) v;
169   v =*((Handle(V3d_View)*)&aView);
170   if (!v->TransientManagerBeginDraw(DoubleBuffer,Standard_True))
171   {
172     myImmediateMode = Standard_False;
173     return;
174   }
175   if(myImmediateList.IsEmpty() && myStrList.IsEmpty()) {
176     Visual3d_TransientManager::EndDraw();
177     myImmediateMode = Standard_False;
178     return;
179   }
180   TColStd_ListIteratorOfListOfTransient it(myImmediateList);
181   Handle(PrsMgr_Presentation3d) P3d;
182   for (; it.More(); it.Next()) {
183     P3d = *((Handle(PrsMgr_Presentation3d)*)&(it.Value()));
184     Visual3d_TransientManager::DrawStructure(P3d->Presentation());
185   }
186   
187   Handle(Standard_Transient) Tr;
188   for(it.Initialize(myStrList);it.More();it.Next()){
189     Tr = it.Value();
190     Visual3d_TransientManager::DrawStructure(*((Handle(Prs3d_Presentation)*)&Tr));
191   }
192   
193   Visual3d_TransientManager::EndDraw();
194   myImmediateMode = Standard_False;
195   
196 }
197
198 //=======================================================================
199 //function : Add
200 //purpose  : 
201 //=======================================================================
202 void PrsMgr_PresentationManager3d::AddToImmediateList(const Handle(Prs3d_Presentation)& P){
203   myStrList.Append(P);
204 }