Commit | Line | Data |
---|---|---|
7fd59977 | 1 | // Copyright: Matra-Datavision 1995 |
2 | // File: SelectMgr_SelectableObject.cxx | |
3 | // Created: Mon Feb 20 17:40:49 1995 | |
4 | // Author: Mister rmi | |
5 | // <rmi> | |
6 | ||
7 | ||
8 | ||
9 | #include <Standard_NotImplemented.hxx> | |
10 | ||
11 | #include <SelectMgr_SelectableObject.ixx> | |
12 | #include <Standard_NoSuchObject.hxx> | |
13 | #include <SelectMgr_Selection.hxx> | |
14 | #include <Select3D_SensitiveEntity.hxx> | |
15 | #include <SelectBasics_EntityOwner.hxx> | |
16 | #include <SelectMgr_EntityOwner.hxx> | |
17 | #include <PrsMgr_PresentationManager3d.hxx> | |
18 | ||
19 | #include <gp_Pnt.hxx> | |
20 | ||
21 | static Standard_Integer Search (const SelectMgr_SequenceOfSelection& seq, | |
22 | const Handle (SelectMgr_Selection)& theSel) | |
23 | { | |
24 | Standard_Integer ifound=0; | |
25 | for (Standard_Integer i=1;i<=seq.Length()&& ifound==0;i++) | |
26 | {if(theSel == seq.Value(i)) ifound=i;} | |
27 | return ifound; | |
28 | } | |
29 | ||
30 | ||
31 | ||
32 | //================================================== | |
33 | // Function: | |
34 | // Purpose : | |
35 | //================================================== | |
36 | ||
37 | SelectMgr_SelectableObject::SelectMgr_SelectableObject( const PrsMgr_TypeOfPresentation3d aTypeOfPresentation3d):PrsMgr_PresentableObject(aTypeOfPresentation3d) | |
38 | { | |
39 | myAutoHilight = Standard_True; | |
40 | } | |
41 | ||
42 | ||
43 | //================================================== | |
44 | // Function: | |
45 | // Purpose : | |
46 | //================================================== | |
47 | ||
48 | Standard_Boolean SelectMgr_SelectableObject | |
49 | ::HasSelection(const Standard_Integer aMode) const | |
50 | { | |
51 | Standard_Boolean Found=Standard_False; | |
52 | for (Standard_Integer I=1;I<= myselections.Length() && !Found;I++) | |
53 | { if(((myselections.Value(I))->Mode())==aMode) | |
54 | return Standard_True; | |
55 | } | |
56 | return Standard_False; | |
57 | } | |
58 | ||
59 | //================================================== | |
60 | // Function: UpdateSelection | |
61 | // Purpose : | |
62 | //================================================== | |
63 | void SelectMgr_SelectableObject::UpdateSelection() | |
64 | { | |
65 | for (Standard_Integer I=1;I<=myselections.Length();I++) | |
66 | { | |
67 | UpdateSelection(myselections.ChangeValue(I)->Mode()); | |
68 | } | |
69 | } | |
70 | ||
71 | Standard_Integer SelectMgr_SelectableObject::NbPossibleSelection() const | |
72 | {return 0;} | |
73 | ||
74 | //================================================== | |
75 | // Function: UpdateSelection | |
76 | // Purpose : | |
77 | //================================================== | |
78 | void SelectMgr_SelectableObject::UpdateSelection(const Standard_Integer aMode) | |
79 | { | |
80 | for (Standard_Integer i =1; i<= myselections.Length(); i++ ) { | |
81 | if (myselections.Value(i)->Mode() == aMode) { | |
82 | myselections(i)->Clear(); | |
83 | ComputeSelection(myselections(i),aMode); | |
84 | myselections(i)->UpdateStatus(SelectMgr_TOU_Partial); | |
85 | return; | |
86 | } | |
87 | } | |
88 | Handle(SelectMgr_Selection) S = new SelectMgr_Selection(aMode); | |
89 | ComputeSelection(S,aMode); | |
90 | S->UpdateStatus(SelectMgr_TOU_Partial); | |
91 | ||
92 | myselections.Append(S); | |
93 | ||
94 | } | |
95 | ||
96 | //================================================== | |
97 | // Function: ClearSelections | |
98 | // Purpose : | |
99 | //================================================== | |
100 | void SelectMgr_SelectableObject::ClearSelections(const Standard_Boolean update) | |
101 | { | |
102 | for (Standard_Integer i =1; i<= myselections.Length(); i++ ) { | |
103 | myselections.Value(i)->Clear(); | |
104 | if(update) | |
105 | myselections.Value(i)->UpdateStatus(SelectMgr_TOU_Full); | |
106 | } | |
107 | } | |
108 | ||
109 | ||
110 | //================================================== | |
111 | // Function: Selection | |
112 | // Purpose : | |
113 | //================================================== | |
114 | ||
115 | const Handle(SelectMgr_Selection)& SelectMgr_SelectableObject | |
116 | ::Selection(const Standard_Integer aMode) const | |
117 | { | |
118 | static Handle(SelectMgr_Selection) bidsel; | |
119 | Standard_Boolean Found = Standard_False; | |
120 | Standard_Integer Rank=0; | |
121 | for (Standard_Integer i=1;i<=myselections.Length() && !Found;i++) | |
122 | { | |
123 | if((myselections.Value(i))->Mode()==aMode){ Found = Standard_True; | |
124 | Rank=i;}} | |
125 | return myselections.Value(Rank); | |
126 | } | |
127 | ||
128 | ||
129 | //================================================== | |
130 | // Function: AddSelection | |
131 | // Purpose : | |
132 | //================================================== | |
133 | ||
134 | void SelectMgr_SelectableObject | |
135 | ::AddSelection(const Handle(SelectMgr_Selection)& aSel, | |
136 | const Standard_Integer aMode) | |
137 | { | |
138 | if(aSel->IsEmpty()){ | |
139 | ComputeSelection(aSel,aMode); | |
140 | aSel->UpdateStatus(SelectMgr_TOU_Partial); | |
141 | } | |
142 | if(HasSelection(aMode)) | |
143 | { | |
144 | const Handle(SelectMgr_Selection)& temp= Selection(aMode); | |
145 | Standard_Integer I = Search(myselections,temp); | |
146 | if(I!=0) myselections.Remove(I); | |
147 | } | |
148 | myselections.Append(aSel); | |
149 | ||
150 | } | |
151 | ||
152 | ||
153 | ||
154 | //======================================================================= | |
155 | //function : ReSetLocation | |
156 | //purpose : | |
157 | //======================================================================= | |
158 | void SelectMgr_SelectableObject::ResetLocation() | |
159 | { | |
160 | TopLoc_Location aLoc; | |
161 | ||
162 | ||
163 | // les selections | |
164 | Handle(Select3D_SensitiveEntity) SE; | |
165 | for(Init();More();Next()){ | |
166 | const Handle(SelectMgr_Selection) & Sel = CurrentSelection(); | |
167 | for(Sel->Init();Sel->More();Sel->Next()){ | |
168 | SE = *((Handle(Select3D_SensitiveEntity)*) &(Sel->Sensitive())); | |
169 | if(!SE.IsNull()){ | |
170 | if(SE->HasLocation()) | |
171 | if( SE->Location()==myLocation){ | |
172 | SE->ResetLocation(); | |
173 | const Handle(SelectBasics_EntityOwner)& EO = SE->OwnerId(); | |
174 | (*((Handle(SelectMgr_EntityOwner)*)&EO))->ResetLocation();} | |
175 | else{ | |
176 | const TopLoc_Location& iniloc =SE->Location(); | |
177 | SE->SetLocation(iniloc*myLocation.Inverted()); | |
178 | const Handle(SelectBasics_EntityOwner)& EO = SE->OwnerId(); | |
179 | (*((Handle(SelectMgr_EntityOwner)*)&EO))->SetLocation(SE->Location());} | |
180 | ||
181 | } | |
182 | } | |
183 | Sel->UpdateStatus(SelectMgr_TOU_None); | |
184 | } | |
185 | ||
186 | PrsMgr_PresentableObject::ResetLocation(); | |
187 | } | |
188 | ||
189 | ||
190 | //======================================================================= | |
191 | //function : UpdateLocation | |
192 | //purpose : | |
193 | //======================================================================= | |
194 | void SelectMgr_SelectableObject::UpdateLocation() | |
195 | { | |
196 | ||
197 | Handle(Select3D_SensitiveEntity) SE; | |
198 | for(Init();More();Next()){ | |
199 | const Handle(SelectMgr_Selection) & Sel = CurrentSelection(); | |
200 | Sel->UpdateStatus(SelectMgr_TOU_Partial); | |
201 | } | |
202 | PrsMgr_PresentableObject::UpdateLocation(); | |
203 | ||
204 | } | |
205 | ||
206 | ||
207 | //======================================================================= | |
208 | //function : UpdateLocation | |
209 | //purpose : | |
210 | //======================================================================= | |
211 | void SelectMgr_SelectableObject::UpdateLocation(const Handle(SelectMgr_Selection)& Sel) | |
212 | { | |
213 | Handle(Select3D_SensitiveEntity) SE; | |
214 | if(myLocation.IsIdentity()) return; | |
215 | for(Sel->Init();Sel->More();Sel->Next()){ | |
216 | SE = *((Handle(Select3D_SensitiveEntity)*) &(Sel->Sensitive())); | |
217 | if(!SE.IsNull()){ | |
218 | SE->UpdateLocation(myLocation); | |
29d43f9c A |
219 | const Handle(SelectBasics_EntityOwner)& aEOwner = SE->OwnerId(); |
220 | Handle(SelectMgr_EntityOwner) aMgrEO = | |
221 | Handle(SelectMgr_EntityOwner)::DownCast (aEOwner); | |
222 | if (!aMgrEO.IsNull()) | |
223 | aMgrEO->SetLocation (myLocation); | |
7fd59977 | 224 | } |
225 | } | |
226 | } | |
227 | ||
228 | //======================================================================= | |
229 | //function : HilightSelected | |
230 | //purpose : | |
231 | //======================================================================= | |
232 | void SelectMgr_SelectableObject::HilightSelected | |
233 | ( const Handle(PrsMgr_PresentationManager3d)&, | |
234 | const SelectMgr_SequenceOfOwner&) | |
235 | { | |
236 | Standard_NotImplemented::Raise ("SelectMgr_SelectableObject::HilightSelected"); | |
237 | } | |
238 | ||
239 | //======================================================================= | |
240 | //function : ClearSelected | |
241 | //purpose : | |
242 | //======================================================================= | |
243 | void SelectMgr_SelectableObject::ClearSelected () | |
244 | { | |
7fd59977 | 245 | if( !mySelectionPrs.IsNull() ) |
2b442de5 | 246 | mySelectionPrs->Clear(); |
7fd59977 | 247 | } |
248 | ||
249 | //======================================================================= | |
250 | //function : HilightOwnerWithColor | |
251 | //purpose : | |
252 | //======================================================================= | |
253 | void SelectMgr_SelectableObject::HilightOwnerWithColor | |
254 | ( const Handle(PrsMgr_PresentationManager3d)&, | |
255 | const Quantity_NameOfColor, | |
256 | const Handle(SelectMgr_EntityOwner)&) | |
257 | { | |
258 | Standard_NotImplemented::Raise ("SelectMgr_SelectableObject::HilightOwnerWithColor"); | |
259 | } | |
260 | ||
261 | //======================================================================= | |
262 | //function : MaxFaceNodes | |
263 | //purpose : | |
264 | //======================================================================= | |
265 | Standard_Boolean SelectMgr_SelectableObject::IsAutoHilight () const | |
266 | { | |
267 | return myAutoHilight; | |
268 | } | |
269 | ||
270 | //======================================================================= | |
271 | //function : MaxFaceNodes | |
272 | //purpose : | |
273 | //======================================================================= | |
274 | void SelectMgr_SelectableObject::SetAutoHilight ( const Standard_Boolean newAutoHilight ) | |
275 | { | |
276 | myAutoHilight = newAutoHilight; | |
277 | } | |
278 | ||
279 | //======================================================================= | |
280 | //function : GetHilightPresentation | |
281 | //purpose : | |
282 | //======================================================================= | |
283 | Handle(Prs3d_Presentation) SelectMgr_SelectableObject::GetHilightPresentation( const Handle(PrsMgr_PresentationManager3d)& TheMgr ) | |
284 | { | |
285 | if( myHilightPrs.IsNull() && !TheMgr.IsNull() ) | |
286 | { | |
287 | myHilightPrs = new Prs3d_Presentation( TheMgr->StructureManager() ); | |
288 | myHilightPrs->SetTransformPersistence( GetTransformPersistenceMode(), | |
289 | GetTransformPersistencePoint() ); | |
290 | } | |
291 | ||
292 | return myHilightPrs; | |
293 | } | |
294 | ||
295 | ||
296 | //======================================================================= | |
297 | //function : GetSelectPresentation | |
298 | //purpose : | |
299 | //======================================================================= | |
300 | Handle(Prs3d_Presentation) SelectMgr_SelectableObject::GetSelectPresentation( const Handle(PrsMgr_PresentationManager3d)& TheMgr ) | |
301 | { | |
302 | if( mySelectionPrs.IsNull() && !TheMgr.IsNull() ) { | |
303 | mySelectionPrs = new Prs3d_Presentation( TheMgr->StructureManager() ); | |
304 | mySelectionPrs->SetTransformPersistence( GetTransformPersistenceMode(), | |
305 | GetTransformPersistencePoint() ); | |
306 | } | |
307 | return mySelectionPrs; | |
308 | } | |
309 | ||
59f45b7c | 310 | //======================================================================= |
311 | //function : SetZLayer | |
312 | //purpose : | |
313 | //======================================================================= | |
314 | void SelectMgr_SelectableObject::SetZLayer | |
315 | (const Handle(PrsMgr_PresentationManager)& thePrsMgr, | |
316 | const Standard_Integer theLayerId) | |
317 | { | |
318 | if (thePrsMgr.IsNull()) | |
319 | return; | |
320 | ||
321 | // update own presentations | |
322 | PrsMgr_PresentableObject::SetZLayer (thePrsMgr, theLayerId); | |
323 | ||
324 | // update selection presentations | |
325 | if (!mySelectionPrs.IsNull()) | |
326 | mySelectionPrs->SetZLayer (theLayerId); | |
327 | ||
328 | if (!myHilightPrs.IsNull()) | |
329 | myHilightPrs->SetZLayer (theLayerId); | |
330 | ||
331 | // update all entity owner presentations | |
332 | for (Init (); More () ;Next ()) | |
333 | { | |
334 | const Handle(SelectMgr_Selection)& aSel = CurrentSelection(); | |
335 | for (aSel->Init (); aSel->More (); aSel->Next ()) | |
336 | { | |
337 | Handle(Select3D_SensitiveEntity) aEntity = | |
338 | Handle(Select3D_SensitiveEntity)::DownCast (aSel->Sensitive()); | |
339 | if (!aEntity.IsNull()) | |
340 | { | |
341 | Handle(SelectMgr_EntityOwner) aOwner = | |
342 | Handle(SelectMgr_EntityOwner)::DownCast (aEntity->OwnerId()); | |
343 | if (!aOwner.IsNull()) | |
344 | aOwner->SetZLayer (thePrsMgr, theLayerId); | |
345 | } | |
346 | } | |
347 | } | |
348 | } |