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. |
b311480e |
14 | |
2831708b |
15 | #include <PrsMgr_Presentation.hxx> |
7fd59977 |
16 | |
42cf5bc1 |
17 | #include <Graphic3d_DataStructureManager.hxx> |
af324faa |
18 | #include <Precision.hxx> |
f838dac4 |
19 | #include <Prs3d_Drawer.hxx> |
42cf5bc1 |
20 | #include <PrsMgr_PresentableObject.hxx> |
42cf5bc1 |
21 | #include <PrsMgr_PresentationManager.hxx> |
42cf5bc1 |
22 | #include <Quantity_Color.hxx> |
92efcf78 |
23 | #include <Graphic3d_CView.hxx> |
24 | |
7dd7c146 |
25 | IMPLEMENT_STANDARD_RTTIEXT(PrsMgr_Presentation, Graphic3d_Structure) |
7fd59977 |
26 | |
3ae59031 |
27 | namespace |
28 | { |
29 | enum BeforeHighlightState |
30 | { |
31 | State_Empty, |
32 | State_Hidden, |
33 | State_Visible |
34 | }; |
35 | |
7dd7c146 |
36 | static BeforeHighlightState StructureState (const Graphic3d_Structure* theStructure) |
3ae59031 |
37 | { |
38 | return !theStructure->IsDisplayed() ? |
39 | State_Empty : !theStructure->IsVisible() ? |
40 | State_Hidden : State_Visible; |
41 | } |
42 | } |
43 | |
af324faa |
44 | //======================================================================= |
45 | //function : PrsMgr_Presentation |
46 | //purpose : |
47 | //======================================================================= |
48 | PrsMgr_Presentation::PrsMgr_Presentation (const Handle(PrsMgr_PresentationManager3d)& thePrsMgr, |
7dd7c146 |
49 | const Handle(PrsMgr_PresentableObject)& thePrsObject, |
50 | const Standard_Integer theMode) |
51 | : Graphic3d_Structure (thePrsMgr->StructureManager()), |
52 | myPresentationManager (thePrsMgr), |
53 | myPresentableObject (thePrsObject.get()), |
54 | myBeforeHighlightState (State_Empty), |
55 | myMode (theMode), |
56 | myMustBeUpdated (Standard_False) |
af324faa |
57 | { |
7dd7c146 |
58 | if (thePrsObject->TypeOfPresentation3d() == PrsMgr_TOP_ProjectorDependant) |
59 | { |
60 | SetVisual (Graphic3d_TOS_COMPUTED); |
61 | } |
62 | SetOwner (myPresentableObject); |
63 | SetMutable (myPresentableObject->IsMutable()); |
af324faa |
64 | } |
65 | |
66 | //======================================================================= |
67 | //function : Display |
68 | //purpose : |
69 | //======================================================================= |
70 | void PrsMgr_Presentation::Display() |
71 | { |
a1954302 |
72 | display (Standard_False); |
3ae59031 |
73 | myBeforeHighlightState = State_Visible; |
af324faa |
74 | } |
75 | |
76 | //======================================================================= |
a1954302 |
77 | //function : display |
af324faa |
78 | //purpose : |
79 | //======================================================================= |
a1954302 |
80 | void PrsMgr_Presentation::display (const Standard_Boolean theIsHighlight) |
af324faa |
81 | { |
7dd7c146 |
82 | if (!base_type::IsDisplayed()) |
af324faa |
83 | { |
49dfdb7a |
84 | base_type::SetIsForHighlight (theIsHighlight); // optimization - disable frustum culling for this presentation |
7dd7c146 |
85 | base_type::Display(); |
af324faa |
86 | } |
7dd7c146 |
87 | else if (!base_type::IsVisible()) |
af324faa |
88 | { |
7dd7c146 |
89 | base_type::SetVisible (Standard_True); |
af324faa |
90 | } |
91 | } |
92 | |
93 | //======================================================================= |
94 | //function : Erase |
95 | //purpose : |
96 | //======================================================================= |
97 | void PrsMgr_Presentation::Erase() |
98 | { |
7dd7c146 |
99 | if (IsDeleted()) |
af324faa |
100 | { |
101 | return; |
102 | } |
103 | |
104 | // Erase structure from structure manager |
dad7fede |
105 | erase(); |
106 | clear (true); |
af324faa |
107 | // Disconnect other structures |
dad7fede |
108 | DisconnectAll (Graphic3d_TOC_DESCENDANT); |
af324faa |
109 | // Clear groups and remove graphic structure |
dad7fede |
110 | Remove(); |
af324faa |
111 | } |
112 | |
113 | //======================================================================= |
114 | //function : Highlight |
115 | //purpose : |
116 | //======================================================================= |
f838dac4 |
117 | void PrsMgr_Presentation::Highlight (const Handle(Prs3d_Drawer)& theStyle) |
af324faa |
118 | { |
3ae59031 |
119 | if (!IsHighlighted()) |
120 | { |
7dd7c146 |
121 | myBeforeHighlightState = StructureState (this); |
3ae59031 |
122 | } |
123 | |
a1954302 |
124 | display (Standard_True); |
7dd7c146 |
125 | base_type::Highlight (theStyle); |
af324faa |
126 | } |
127 | |
128 | //======================================================================= |
129 | //function : Unhighlight |
130 | //purpose : |
131 | //======================================================================= |
7dd7c146 |
132 | void PrsMgr_Presentation::Unhighlight() |
af324faa |
133 | { |
7dd7c146 |
134 | base_type::UnHighlight(); |
3ae59031 |
135 | switch (myBeforeHighlightState) |
af324faa |
136 | { |
7dd7c146 |
137 | case State_Visible: |
138 | return; |
139 | case State_Hidden: |
140 | base_type::SetVisible (Standard_False); |
141 | break; |
142 | case State_Empty: |
dad7fede |
143 | base_type::erase(); |
7dd7c146 |
144 | break; |
af324faa |
145 | } |
146 | } |
147 | |
148 | //======================================================================= |
149 | //function : Clear |
150 | //purpose : |
151 | //======================================================================= |
7dd7c146 |
152 | void PrsMgr_Presentation::Clear (const Standard_Boolean theWithDestruction) |
af324faa |
153 | { |
154 | // This modification remove the contain of the structure: |
155 | // Consequence: |
156 | // 1. The memory zone of the group is reused |
157 | // 2. The speed for animation is constant |
158 | //myPresentableObject = NULL; |
159 | SetUpdateStatus (Standard_True); |
7dd7c146 |
160 | if (IsDeleted()) |
af324faa |
161 | { |
162 | return; |
163 | } |
164 | |
dad7fede |
165 | clear (theWithDestruction); |
166 | DisconnectAll (Graphic3d_TOC_DESCENDANT); |
af324faa |
167 | } |
168 | |
af324faa |
169 | //======================================================================= |
7dd7c146 |
170 | //function : Compute |
af324faa |
171 | //purpose : |
172 | //======================================================================= |
7dd7c146 |
173 | void PrsMgr_Presentation::Compute() |
af324faa |
174 | { |
7dd7c146 |
175 | Standard_Integer aDispMode = 0; |
176 | for (PrsMgr_Presentations::Iterator aPrsIter (myPresentableObject->myPresentations); aPrsIter.More(); aPrsIter.Next()) |
177 | { |
178 | const Handle(PrsMgr_Presentation)& aModedPresentation = aPrsIter.Value(); |
179 | if (aModedPresentation == this) |
180 | { |
181 | aDispMode = aModedPresentation->Mode(); |
182 | break; |
183 | } |
184 | } |
af324faa |
185 | |
7dd7c146 |
186 | myPresentableObject->Compute (myPresentationManager, this, aDispMode); |
af324faa |
187 | } |
188 | |
af324faa |
189 | //======================================================================= |
190 | //function : Compute |
191 | //purpose : |
192 | //======================================================================= |
b5163d2f |
193 | void PrsMgr_Presentation::computeHLR (const Handle(Graphic3d_Camera)& theProjector, |
194 | Handle(Graphic3d_Structure)& theStructToFill) |
af324faa |
195 | { |
b5163d2f |
196 | if (theStructToFill.IsNull()) |
197 | { |
198 | theStructToFill = new Prs3d_Presentation (myPresentationManager->StructureManager()); |
199 | } |
7dd7c146 |
200 | Handle(Graphic3d_Structure) aPrs = theStructToFill; |
af324faa |
201 | theStructToFill->Clear(); |
b5163d2f |
202 | myPresentableObject->computeHLR (theProjector, Transformation(), aPrs); |
af324faa |
203 | } |
204 | |
205 | //======================================================================= |
e6f550da |
206 | //function : ~PrsMgr_Presentation |
af324faa |
207 | //purpose : |
208 | //======================================================================= |
e6f550da |
209 | PrsMgr_Presentation::~PrsMgr_Presentation() |
af324faa |
210 | { |
a69a08ee |
211 | Erase(); |
af324faa |
212 | } |
bc73b006 |
213 | |
214 | // ======================================================================= |
215 | // function : DumpJson |
216 | // purpose : |
217 | // ======================================================================= |
218 | void PrsMgr_Presentation::DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth) const |
219 | { |
220 | OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream) |
221 | OCCT_DUMP_BASE_CLASS (theOStream, theDepth, Graphic3d_Structure) |
222 | |
223 | OCCT_DUMP_FIELD_VALUE_POINTER (theOStream, myPresentableObject) |
224 | |
225 | OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myBeforeHighlightState) |
226 | OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myMode) |
227 | OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myMustBeUpdated) |
228 | } |