b311480e |
1 | // Copyright (c) 1998-1999 Matra Datavision |
973c2be1 |
2 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
3 | // |
973c2be1 |
4 | // This file is part of Open CASCADE Technology software library. |
b311480e |
5 | // |
d5f74e42 |
6 | // This library is free software; you can redistribute it and/or modify it under |
7 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
8 | // by the Free Software Foundation, with special exception defined in the file |
9 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
10 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
11 | // |
973c2be1 |
12 | // Alternatively, this file may be used under the terms of Open CASCADE |
13 | // commercial license or contractual agreement. |
7fd59977 |
14 | |
15 | #include <PrsMgr_PresentationManager3d.ixx> |
16 | #include <PrsMgr_Presentation3d.hxx> |
17 | #include <Prs3d_ShadingAspect.hxx> |
18 | #include <Visual3d_TransientManager.hxx> |
19 | #include <V3d_View.hxx> |
20 | #include <TColStd_ListIteratorOfListOfTransient.hxx> |
21 | |
22 | PrsMgr_PresentationManager3d::PrsMgr_PresentationManager3d (const Handle(Graphic3d_StructureManager)& aStructureManager):myStructureManager(aStructureManager) {} |
23 | |
24 | Standard_Boolean PrsMgr_PresentationManager3d::Is3D() const |
25 | {return Standard_True;} |
26 | |
27 | Handle(PrsMgr_Presentation) PrsMgr_PresentationManager3d::newPresentation (const Handle(PrsMgr_PresentableObject) & aPresentableObject) { |
28 | |
29 | return new PrsMgr_Presentation3d(this,aPresentableObject); |
30 | } |
31 | |
32 | void PrsMgr_PresentationManager3d::Connect(const Handle(PrsMgr_PresentableObject)& aPresentableObject, const Handle(PrsMgr_PresentableObject)& anOtherObject, const Standard_Integer aMode, const Standard_Integer anOtherMode) { |
33 | if (!HasPresentation(aPresentableObject,aMode)){ |
34 | AddPresentation(aPresentableObject,aMode); |
35 | } |
36 | if (!HasPresentation(anOtherObject,anOtherMode)){ |
37 | AddPresentation(anOtherObject,anOtherMode); |
38 | } |
39 | CastPresentation(aPresentableObject,aMode)->Connect(CastPresentation(anOtherObject,aMode)); |
40 | } |
41 | |
42 | //======================================================================= |
43 | //function : Transform |
44 | //purpose : |
45 | //======================================================================= |
46 | void PrsMgr_PresentationManager3d::Transform(const Handle(PrsMgr_PresentableObject)& aPresentableObject,const Handle(Geom_Transformation)& aTransformation, const Standard_Integer aMode) { |
47 | CastPresentation(aPresentableObject,aMode)->Transform(aTransformation); |
48 | } |
49 | |
50 | //======================================================================= |
51 | //function : Place |
52 | //purpose : |
53 | //======================================================================= |
54 | |
55 | 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) { |
56 | CastPresentation(aPresentableObject,aMode)->Place(X,Y,Z); |
57 | } |
58 | |
59 | //======================================================================= |
60 | //function : Multiply |
61 | //purpose : |
62 | //======================================================================= |
63 | |
64 | void PrsMgr_PresentationManager3d::Multiply(const Handle(PrsMgr_PresentableObject)& aPresentableObject,const Handle(Geom_Transformation)& aTransformation, const Standard_Integer aMode) { |
65 | CastPresentation(aPresentableObject,aMode)->Multiply(aTransformation); |
66 | } |
67 | |
68 | //======================================================================= |
69 | //function : Move |
70 | //purpose : |
71 | //======================================================================= |
72 | |
73 | 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) { |
74 | CastPresentation(aPresentableObject,aMode)->Move(X,Y,Z); |
75 | } |
76 | |
77 | //======================================================================= |
78 | //function : Color |
79 | //purpose : |
80 | //======================================================================= |
81 | |
82 | void PrsMgr_PresentationManager3d::Color(const Handle(PrsMgr_PresentableObject)& aPresentableObject, const Quantity_NameOfColor aColor, const Standard_Integer aMode) { |
83 | if (!HasPresentation(aPresentableObject,aMode)){ |
84 | AddPresentation(aPresentableObject,aMode); |
85 | } |
86 | else if(Presentation(aPresentableObject,aMode)->MustBeUpdated()){ |
87 | Update(aPresentableObject,aMode); |
88 | } |
89 | CastPresentation(aPresentableObject,aMode)->Color(aColor); |
90 | |
91 | if(myImmediateMode) |
92 | Add(aPresentableObject,aMode); |
93 | |
94 | } |
95 | |
96 | //======================================================================= |
97 | //function : BoundBox |
98 | //purpose : |
99 | //======================================================================= |
100 | |
101 | void PrsMgr_PresentationManager3d::BoundBox(const Handle(PrsMgr_PresentableObject)& aPresentableObject, const Standard_Integer aMode) { |
102 | if (!HasPresentation(aPresentableObject,aMode)){ |
103 | AddPresentation(aPresentableObject,aMode); |
104 | } |
105 | else if(Presentation(aPresentableObject,aMode)->MustBeUpdated()){ |
106 | Update(aPresentableObject,aMode); |
107 | } |
108 | CastPresentation(aPresentableObject,aMode)->BoundBox(); |
109 | } |
110 | //======================================================================= |
111 | //function : SetShadingAspect |
112 | //purpose : |
113 | //======================================================================= |
114 | |
115 | //POP pour K4L |
116 | void PrsMgr_PresentationManager3d::SetShadingAspect(const Handle(PrsMgr_PresentableObject)& aPresentableObject, const Quantity_NameOfColor aColor, const Graphic3d_NameOfMaterial aMaterial, const Standard_Integer aMode) { |
117 | //void PrsMgr_PresentationManager3d::SetShadingAspect(const Handle(PrsMgr_PresentableObject)& aPresentableObject, const Quantity_NameOfColor aColor, const Graphic3d_NameOfPhysicalMaterial aMaterial, const Standard_Integer aMode) { |
118 | |
119 | Handle(Prs3d_ShadingAspect) sa = new Prs3d_ShadingAspect; |
120 | sa->SetColor(aColor); |
121 | sa->SetMaterial(aMaterial); |
122 | SetShadingAspect(aPresentableObject,sa,aMode); |
123 | } |
124 | |
125 | void PrsMgr_PresentationManager3d::SetShadingAspect(const Handle(PrsMgr_PresentableObject)& aPresentableObject, const Handle(Prs3d_ShadingAspect)& aShadingAspect, const Standard_Integer aMode) { |
126 | |
127 | if (HasPresentation(aPresentableObject,aMode)){ |
128 | CastPresentation(aPresentableObject,aMode)->SetShadingAspect(aShadingAspect); |
129 | } |
130 | } |
131 | |
132 | |
133 | //======================================================================= |
134 | //function : CastPresentation |
135 | //purpose : |
136 | //======================================================================= |
137 | |
138 | Handle(PrsMgr_Presentation3d) PrsMgr_PresentationManager3d::CastPresentation(const Handle(PrsMgr_PresentableObject)& aPresentableObject, const Standard_Integer aMode) const { |
139 | return Handle(PrsMgr_Presentation3d)::DownCast(Presentation(aPresentableObject,aMode)); |
140 | } |
141 | |
142 | |
143 | |
144 | //======================================================================= |
145 | //function : BeginDraw |
146 | //purpose : |
147 | //======================================================================= |
148 | |
149 | void PrsMgr_PresentationManager3d::BeginDraw() |
150 | { |
151 | PrsMgr_PresentationManager::BeginDraw(); |
152 | myStrList.Clear(); |
153 | } |
154 | |
155 | //======================================================================= |
156 | //function : EndDraw |
157 | //purpose : |
158 | //======================================================================= |
159 | |
6942f04a |
160 | void PrsMgr_PresentationManager3d::EndDraw(const Handle(V3d_View)& theView, const Standard_Boolean DoubleBuffer) |
161 | { |
162 | if (!theView->TransientManagerBeginDraw (DoubleBuffer, Standard_True)) |
7fd59977 |
163 | { |
164 | myImmediateMode = Standard_False; |
165 | return; |
166 | } |
167 | if(myImmediateList.IsEmpty() && myStrList.IsEmpty()) { |
168 | Visual3d_TransientManager::EndDraw(); |
169 | myImmediateMode = Standard_False; |
170 | return; |
171 | } |
172 | TColStd_ListIteratorOfListOfTransient it(myImmediateList); |
173 | Handle(PrsMgr_Presentation3d) P3d; |
174 | for (; it.More(); it.Next()) { |
175 | P3d = *((Handle(PrsMgr_Presentation3d)*)&(it.Value())); |
176 | Visual3d_TransientManager::DrawStructure(P3d->Presentation()); |
177 | } |
178 | |
179 | Handle(Standard_Transient) Tr; |
180 | for(it.Initialize(myStrList);it.More();it.Next()){ |
181 | Tr = it.Value(); |
182 | Visual3d_TransientManager::DrawStructure(*((Handle(Prs3d_Presentation)*)&Tr)); |
183 | } |
184 | |
185 | Visual3d_TransientManager::EndDraw(); |
186 | myImmediateMode = Standard_False; |
187 | |
188 | } |
189 | |
190 | //======================================================================= |
191 | //function : Add |
192 | //purpose : |
193 | //======================================================================= |
194 | void PrsMgr_PresentationManager3d::AddToImmediateList(const Handle(Prs3d_Presentation)& P){ |
195 | myStrList.Append(P); |
196 | } |