b311480e |
1 | // Created on: 1996-10-30 |
2 | // Created by: Robert COUBLANC |
3 | // Copyright (c) 1996-1999 Matra Datavision |
973c2be1 |
4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
5 | // |
973c2be1 |
6 | // This file is part of Open CASCADE Technology software library. |
b311480e |
7 | // |
d5f74e42 |
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 |
973c2be1 |
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. |
b311480e |
13 | // |
973c2be1 |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
b311480e |
16 | |
7fd59977 |
17 | // Modified by rob Thu Apr 02 1998 |
18 | // - use of optimisation in SelectMgr_ViewerSelector |
19 | // -> Best management in detected entities... |
20 | |
21 | #define BUC60569 //GG_051199 Enable to select the local context |
22 | // in any case and especially in multi selection mode. |
23 | // Note that right now when an hilighted owner is selected |
24 | // this owner is unhilighted,this permits to see the selection! |
25 | // Principle : an owner can have 3 state : |
26 | // 1 : The owner is selected and no more highlightable |
27 | // 0 : The owner is NOT selected |
28 | // -1: The owner is selected but stay highlightable (NEW) |
29 | |
30 | // IMP230600 //GG Add protection on selection methodes |
31 | // when nothing is selected |
32 | |
33 | #define BUC60726 //GG_040900 When nothing is detected, |
34 | // Clear the last temporary stuff in any case |
35 | |
36 | #define BUC60765 //GG_121000 Avoid to raise when the same selection |
37 | // is attached to several local context. |
38 | |
39 | #define BUC60771 //GG_261000 Avoid to crash after closing a view |
40 | // containing a selected entity and creating a new one. |
41 | |
42 | #define BUC60774 //GG_261000 Returns right select status on |
43 | // bounding-box selection type. |
44 | |
45 | #define BUC60818 //GG_300101 Enable detection even if |
46 | // SetAutomaticHilight(FALSE) has been used. |
47 | |
48 | #define IMP300101 //GG Enable to use polygon highlighting |
49 | |
50 | #define BUC60863 //GG_270301 Clear hilight soon after selecting or |
51 | // unselecting something in Local Context mode. |
52 | |
53 | #define BUC60876 //GG_050401 Clear selection always even |
54 | // if the current highlight mode is not 0. |
55 | |
56 | #define BUC60953 //SAV_060701 For Select optimization. Selection by rectangle case. |
b311480e |
57 | // for single selection no optimization done. |
7fd59977 |
58 | |
59 | #define IMP120701 //SZV made a shape valid for selection |
60 | // when required. |
61 | |
62 | #define IMP160701 //SZV Add InitDetected(),MoreDetected(),NextDetected(), |
63 | // DetectedCurrentShape(),DetectedCurrentObject() |
64 | // methods |
65 | |
66 | #define OCC138 //VTN Avoding infinit loop in AddOrRemoveSelected method. |
67 | |
68 | #define OCC189 //SAV: 18/03/02 AIS_Selection::Objects() returns ListOfTransient |
b311480e |
69 | // instead of array. |
70 | |
7fd59977 |
71 | #define USE_MAP //san : 18/04/03 USE_MAP - additional datamap is used to speed up access |
b311480e |
72 | //to certain owners in AIS_Selection::myresult list |
7fd59977 |
73 | |
74 | #define IMP120402 // GG : Add protection in manual detection methods |
75 | // after deselecting any item using ShiftSelect action. |
76 | // Thanks to Ivan FONTAINE of SAMTECH company |
77 | |
78 | #define IMP051001 //GG manage Z detection |
79 | |
80 | #define OCC9026 //AEL Performance optimization of the FindSelectedOwnerFromShape() method. |
81 | |
82 | #include <AIS_LocalContext.jxx> |
83 | #include <StdSelect_BRepOwner.hxx> |
84 | #include <TColStd_MapOfTransient.hxx> |
85 | #include <TColStd_MapIteratorOfMapOfTransient.hxx> |
86 | #include <Prs3d_Presentation.hxx> |
87 | #include <Prs3d_Drawer.hxx> |
88 | #include <Prs3d_ShadingAspect.hxx> |
89 | #include <AIS_LocalStatus.hxx> |
90 | #include <StdPrs_WFShape.hxx> |
91 | #include <Visual3d_TransientManager.hxx> |
b8ddfc2f |
92 | #include <Graphic3d_ArrayOfTriangles.hxx> |
7fd59977 |
93 | #include <Graphic3d_Group.hxx> |
94 | #include <Select3D_SensitiveTriangulation.hxx> |
95 | #include <SelectBasics_SensitiveEntity.hxx> |
96 | #include <TCollection_AsciiString.hxx> |
97 | #ifdef OCC9026 |
98 | #include <SelectMgr_DataMapIteratorOfDataMapOfIntegerSensitive.hxx> |
99 | #endif |
100 | #include <SelectMgr_Selection.hxx> |
101 | #include <OSD_Environment.hxx> |
102 | #include <SelectMgr_DataMapOfObjectOwners.hxx> |
103 | |
104 | #include <Geom_Transformation.hxx> |
105 | #include <AIS_Selection.hxx> |
106 | #ifdef IMP120701 |
107 | #include <AIS_Shape.hxx> |
108 | #endif |
109 | |
110 | |
111 | static Standard_Integer GetHiMod(const Handle(AIS_InteractiveObject)& IO) |
112 | { |
113 | return IO->HasHilightMode() ? IO->HilightMode():0; |
114 | } |
115 | |
116 | //================================================== |
117 | // Function: |
118 | // Purpose : |
119 | //================================================== |
120 | AIS_StatusOfDetection AIS_LocalContext::MoveTo(const Standard_Integer Xpix, |
121 | const Standard_Integer Ypix, |
122 | const Handle(V3d_View)& aview) |
123 | { |
81bba717 |
124 | // check that ViewerSelector gives |
7fd59977 |
125 | if(aview->Viewer()== myCTX->CurrentViewer()) { |
126 | #ifdef IMP160701 |
127 | //Nullify class members storing information about detected AIS objects. |
128 | myAISCurDetected = 0; |
129 | myAISDetectedSeq.Clear(); |
130 | #endif |
131 | myCurDetected = 0; |
132 | myDetectedSeq.Clear(); |
133 | myMainVS->Pick(Xpix,Ypix,aview); |
134 | Standard_Boolean had_nothing = myMainVS->NbPicked()==0; |
135 | Standard_Integer NbDetected = myMainVS->NbPicked(); |
136 | Handle(SelectMgr_EntityOwner) EO; |
137 | |
138 | for(Standard_Integer i_detect = 1;i_detect<=NbDetected;i_detect++){ |
139 | EO = myMainVS->Picked(i_detect); |
140 | if(!EO.IsNull()){ |
141 | if(myFilters->IsOk(EO)) { |
81bba717 |
142 | myDetectedSeq.Append(i_detect); // normallly they are already arranged in correct order... |
7fd59977 |
143 | #ifdef IMP160701 |
144 | Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast(EO->Selectable()); |
145 | if(!Handle(AIS_Shape)::DownCast(anObj).IsNull()) |
146 | myAISDetectedSeq.Append(anObj); |
147 | #endif |
148 | } |
149 | } |
150 | } |
151 | |
81bba717 |
152 | //result of courses.. |
7fd59977 |
153 | if(had_nothing || myDetectedSeq.IsEmpty()){ |
154 | if(mylastindex !=0 && mylastindex <= myMapOfOwner.Extent()){ |
155 | |
156 | #ifdef BUC60863 |
157 | Unhilight(myMapOfOwner(mylastindex),aview); |
158 | #else |
159 | if(!IsSelected(myMapOfOwner(mylastindex))) |
160 | Unhilight(myMapOfOwner(mylastindex),aview); |
161 | #endif |
162 | } |
163 | mylastindex=0; |
164 | return (had_nothing ? AIS_SOD_Nothing : AIS_SOD_AllBad); |
165 | } |
166 | |
81bba717 |
167 | // all owners detected by the selector are passed to the |
168 | // filters and correct ones are preserved... |
7fd59977 |
169 | myCurDetected = 1; |
170 | EO = myMainVS->Picked(myDetectedSeq(myCurDetected)); |
171 | |
172 | static Standard_Boolean Normal_State(Standard_True); |
173 | static Standard_Boolean firsttime(Standard_True); |
174 | if(firsttime){ |
175 | OSD_Environment toto("HITRI"); |
176 | if(!toto.Value().IsEmpty()) |
177 | Normal_State = Standard_False; |
178 | firsttime = Standard_False; |
179 | } |
180 | |
181 | if(Normal_State) |
182 | ManageDetected(EO,aview); |
183 | else |
184 | HilightTriangle(1,aview); |
185 | |
186 | if(myDetectedSeq.Length() == 1){ |
187 | if(NbDetected==1) |
188 | return AIS_SOD_OnlyOneDetected; |
189 | else |
190 | return AIS_SOD_OnlyOneGood; |
191 | } |
192 | else |
193 | return AIS_SOD_SeveralGood; |
194 | |
195 | |
196 | } |
197 | return AIS_SOD_Error; |
198 | } |
199 | |
200 | //================================================== |
201 | // Function: |
202 | // Purpose : |
203 | //================================================== |
204 | AIS_StatusOfPick AIS_LocalContext::Select(const Standard_Boolean updateviewer) |
205 | { |
206 | if(myAutoHilight) |
207 | UnhilightPicked(Standard_False); |
208 | |
209 | Standard_Integer DI = DetectedIndex(); |
210 | AIS_Selection::SetCurrentSelection(mySelName.ToCString()); |
211 | Standard_Integer NbSel = AIS_Selection::Extent(); |
212 | |
213 | if(DI<=0){ |
214 | ClearSelected(updateviewer); |
215 | return NbSel== 0 ? AIS_SOP_NothingSelected : AIS_SOP_Removed; |
216 | } |
217 | |
218 | const Handle(SelectMgr_EntityOwner)& EO = myMapOfOwner(DI); |
219 | |
220 | #ifdef BUC60569 |
221 | ClearSelected(Standard_False); |
222 | Standard_Integer state = EO->State(); |
223 | if( state < 1 ){ |
224 | EO->State(1); |
225 | if( state == 0 ) AIS_Selection::Select(EO); |
226 | } |
227 | #else |
228 | if(!IsSelected(EO)) |
229 | AIS_Selection::ClearAndSelect(EO); |
230 | #endif |
231 | |
232 | if(myAutoHilight) { |
233 | #ifdef BUC60863 |
234 | const Handle(V3d_Viewer)& aViewer = myCTX->CurrentViewer(); |
235 | for(aViewer->InitActiveViews(); aViewer->MoreActiveViews(); aViewer->NextActiveViews()) |
236 | Unhilight(EO, aViewer->ActiveView()); |
237 | |
238 | // san - advanced selection highlighting mechanism |
239 | if (!EO->IsAutoHilight() && EO->HasSelectable()){ |
240 | Handle(AIS_InteractiveObject) anIO = |
241 | Handle(AIS_InteractiveObject)::DownCast(EO->Selectable()); |
242 | UpdateSelected(anIO, Standard_False); |
243 | } |
244 | |
245 | if(updateviewer) |
246 | myCTX->CurrentViewer()->Update(); |
247 | #else |
248 | HilightPicked(updateviewer); |
249 | #endif |
250 | } |
251 | return ( AIS_Selection::Extent() == 1)? AIS_SOP_OneSelected : AIS_SOP_SeveralSelected ; |
252 | } |
253 | //================================================== |
254 | // Function: |
255 | // Purpose : |
256 | //================================================== |
257 | AIS_StatusOfPick AIS_LocalContext::Select(const Standard_Integer XPMin, |
258 | const Standard_Integer YPMin, |
259 | const Standard_Integer XPMax, |
260 | const Standard_Integer YPMax, |
261 | const Handle(V3d_View)& aView, |
262 | const Standard_Boolean updateviewer) |
263 | { |
264 | if(aView->Viewer()== myCTX->CurrentViewer()){ |
265 | myMainVS->Pick( XPMin,YPMin,XPMax,YPMax,aView); |
266 | if (myAutoHilight) UnhilightPicked(Standard_False); |
267 | |
268 | AIS_Selection::SetCurrentSelection(mySelName.ToCString()); |
269 | Standard_Integer LastExt = AIS_Selection::Extent(); |
270 | |
271 | myMainVS->Init(); |
272 | if(!myMainVS->More()) { |
273 | ClearSelected(updateviewer); |
274 | mylastindex=0; |
275 | return LastExt == 0 ? AIS_SOP_NothingSelected:AIS_SOP_Removed; |
276 | } |
277 | |
278 | ClearSelected(Standard_False); |
279 | |
280 | for(myMainVS->Init();myMainVS->More();myMainVS->Next()){ |
281 | const Handle(SelectMgr_EntityOwner)& OWNR = myMainVS->Picked(); |
282 | if(myFilters->IsOk(OWNR)){ |
81bba717 |
283 | // it can be helpfil to classify this owner immediately... |
7fd59977 |
284 | #ifdef BUC60569 |
285 | Standard_Integer state = OWNR->State(); |
286 | if( state < 1 ){ |
287 | #ifdef BUC60953 |
288 | if( state == 0 ) AIS_Selection::Select(OWNR); |
289 | OWNR->State(1); |
290 | #else |
291 | OWNR->State(1); |
292 | if( state == 0 ) AIS_Selection::Select(OWNR); |
293 | #endif //BUC60953 |
294 | } |
295 | #else //BUC60569 |
296 | if(!IsSelected(OWNR)){ |
297 | OWNR->State(1); |
298 | AIS_Selection::Select(OWNR); |
299 | } |
300 | #endif //BUC60569 |
301 | } |
302 | } |
303 | if (myAutoHilight) |
304 | HilightPicked(updateviewer); |
305 | } |
306 | #ifdef BUC60774 |
307 | Standard_Integer NS = AIS_Selection::Extent(); |
308 | if( NS == 1 ) return AIS_SOP_OneSelected; |
309 | else if( NS > 1 ) return AIS_SOP_SeveralSelected; |
310 | #endif |
311 | return AIS_SOP_Error; |
312 | } |
313 | |
314 | |
315 | |
316 | //================================================== |
317 | // Function: |
318 | // Purpose : |
319 | //================================================== |
320 | AIS_StatusOfPick AIS_LocalContext::ShiftSelect(const Standard_Boolean updateviewer) |
321 | { |
322 | Standard_Integer I = DetectedIndex(); |
323 | if(I>0){ |
324 | #ifndef BUC60863 |
325 | if(myAutoHilight) |
326 | UnhilightPicked(Standard_False); |
327 | #endif |
328 | |
329 | AIS_Selection::SetCurrentSelection(mySelName.ToCString()); |
330 | #ifdef BUC60774 |
331 | Standard_Integer NbSel = AIS_Selection::Extent(); |
332 | #endif |
333 | const Handle(SelectMgr_EntityOwner)& EO = myMapOfOwner(I); |
334 | #ifdef BUC60569 |
335 | Standard_Integer mod = EO->State()==0 ? -1 : 0; |
336 | #else |
337 | Standard_Integer mod = EO->State()==0 ? 1 : 0; |
338 | #endif |
339 | |
340 | #ifdef BUC60953 |
341 | AIS_Selection::Select(EO); |
342 | EO->State(mod); |
343 | #else |
344 | EO->State(mod); |
345 | |
346 | AIS_Selection::Select(EO); |
347 | #endif |
348 | |
349 | if(myAutoHilight) { |
350 | #ifdef BUC60863 |
351 | const Handle(V3d_Viewer)& aViewer = myCTX->CurrentViewer(); |
352 | for(aViewer->InitActiveViews(); aViewer->MoreActiveViews(); aViewer->NextActiveViews()) |
353 | Unhilight(EO, aViewer->ActiveView()); |
354 | |
355 | // san - advanced selection highlighting mechanism |
356 | if (!EO->IsAutoHilight() && EO->HasSelectable()){ |
357 | Handle(AIS_InteractiveObject) anIO = |
358 | Handle(AIS_InteractiveObject)::DownCast(EO->Selectable()); |
359 | UpdateSelected(anIO, Standard_False); |
360 | } |
361 | |
362 | if(updateviewer) |
363 | myCTX->CurrentViewer()->Update(); |
364 | #else |
365 | HilightPicked(updateviewer); |
366 | #endif |
367 | } |
368 | #ifdef BUC60774 |
369 | Standard_Integer NS = AIS_Selection::Extent(); |
370 | if( NS == 1 ) return AIS_SOP_OneSelected; |
371 | else if( NS > 1 ) return AIS_SOP_SeveralSelected; |
372 | return NbSel== 0 ? AIS_SOP_NothingSelected : AIS_SOP_Removed; |
373 | #endif |
374 | } |
375 | return AIS_SOP_Error; |
376 | } |
377 | //================================================== |
81bba717 |
378 | // Function: the already selected objects are unselected |
379 | // Purpose : others are selected. |
7fd59977 |
380 | //================================================== |
381 | AIS_StatusOfPick AIS_LocalContext::ShiftSelect(const Standard_Integer XPMin, |
382 | const Standard_Integer YPMin, |
383 | const Standard_Integer XPMax, |
384 | const Standard_Integer YPMax, |
385 | const Handle(V3d_View)& aView, |
386 | const Standard_Boolean updateviewer) |
387 | { |
388 | if(aView->Viewer()== myCTX->CurrentViewer()) { |
389 | myMainVS->Pick( XPMin,YPMin,XPMax,YPMax,aView); |
390 | #ifdef BUC60774 |
391 | AIS_Selection::SetCurrentSelection(mySelName.ToCString()); |
392 | Standard_Integer LastExt = AIS_Selection::Extent(); |
393 | #endif |
394 | myMainVS->Init(); |
395 | if(!myMainVS->More()) |
396 | #ifdef BUC60774 |
397 | return LastExt == 0 ? AIS_SOP_NothingSelected:AIS_SOP_Removed; |
398 | #else |
81bba717 |
399 | return AIS_SOP_NothingSelected; // no effet if click on empty space |
7fd59977 |
400 | #endif |
401 | |
402 | AIS_Selection::SetCurrentSelection(mySelName.ToCString()); |
403 | if (myAutoHilight) UnhilightPicked(Standard_False); |
404 | |
405 | for(myMainVS->Init();myMainVS->More();myMainVS->Next()){ |
406 | const Handle(SelectMgr_EntityOwner)& EO = myMainVS->Picked(); |
407 | if(myFilters->IsOk(EO)){ |
408 | #ifdef BUC60569 |
409 | Standard_Integer mod = EO->State()==0 ? -1 : 0; |
410 | #else |
411 | Standard_Integer mod = EO->State()==0 ? 1 : 0; |
412 | #endif |
413 | |
414 | #ifdef BUC60953 |
415 | AIS_Selection::Select(EO); |
416 | EO->State(mod); |
417 | #else |
418 | EO->State(mod); |
419 | AIS_Selection::Select(EO); |
420 | #endif |
421 | } |
422 | } |
423 | if (myAutoHilight) HilightPicked(updateviewer); |
424 | |
425 | } |
426 | #ifdef BUC60774 |
427 | Standard_Integer NS = AIS_Selection::Extent(); |
428 | if( NS == 1 ) return AIS_SOP_OneSelected; |
429 | else if( NS > 1 ) return AIS_SOP_SeveralSelected; |
430 | #endif |
431 | return AIS_SOP_Error; |
432 | } |
433 | |
434 | //================================================== |
435 | // Function: Select |
436 | // Purpose : Selection by polyline |
437 | //================================================== |
438 | AIS_StatusOfPick AIS_LocalContext::Select(const TColgp_Array1OfPnt2d& aPolyline, |
439 | const Handle(V3d_View)& aView, |
440 | const Standard_Boolean updateviewer) |
441 | { |
442 | if(aView->Viewer()== myCTX->CurrentViewer()){ |
443 | myMainVS->Pick(aPolyline,aView); |
444 | if (myAutoHilight) UnhilightPicked(Standard_False); |
445 | |
446 | AIS_Selection::SetCurrentSelection(mySelName.ToCString()); |
447 | Standard_Integer LastExt = AIS_Selection::Extent(); |
448 | |
449 | myMainVS->Init(); |
450 | if(!myMainVS->More()) { |
451 | ClearSelected(updateviewer); |
452 | mylastindex=0; |
453 | return LastExt == 0 ? AIS_SOP_NothingSelected:AIS_SOP_Removed; |
454 | } |
455 | |
456 | ClearSelected(Standard_False); |
457 | |
458 | for(myMainVS->Init();myMainVS->More();myMainVS->Next()){ |
459 | const Handle(SelectMgr_EntityOwner)& OWNR = myMainVS->Picked(); |
460 | if(myFilters->IsOk(OWNR)){ |
81bba717 |
461 | // it can be helpfil to classify this owner immediately... |
7fd59977 |
462 | #ifdef BUC60953 |
463 | Standard_Integer state = OWNR->State(); |
464 | if( state < 1 ){ |
465 | if( state == 0 ) AIS_Selection::AddSelect(OWNR); |
466 | OWNR->State(1); |
467 | } |
468 | #else |
469 | if(!IsSelected(OWNR)){ |
470 | OWNR->State(1); |
471 | AIS_Selection::AddSelect(OWNR); |
472 | } |
473 | #endif //BUC60953 |
474 | } |
475 | } |
476 | |
477 | if (myAutoHilight) |
478 | HilightPicked(updateviewer); |
479 | } |
480 | #ifdef BUC60774 |
481 | Standard_Integer NS = AIS_Selection::Extent(); |
482 | if( NS == 1 ) return AIS_SOP_OneSelected; |
483 | else if( NS > 1 ) return AIS_SOP_SeveralSelected; |
484 | #endif |
485 | return AIS_SOP_Error; |
486 | } |
487 | |
488 | //================================================== |
489 | // Function: Select |
490 | // Purpose : Selection by polyline |
491 | //================================================== |
492 | AIS_StatusOfPick AIS_LocalContext::ShiftSelect( const TColgp_Array1OfPnt2d& aPolyline, |
493 | const Handle(V3d_View)& aView, |
494 | const Standard_Boolean updateviewer ) |
495 | { |
496 | if( aView->Viewer() == myCTX->CurrentViewer() ) { |
497 | myMainVS->Pick( aPolyline, aView ); |
498 | |
499 | AIS_Selection::SetCurrentSelection( mySelName.ToCString() ); |
500 | Standard_Integer LastExt = AIS_Selection::Extent(); |
501 | myMainVS->Init(); |
502 | if( !myMainVS->More() ) |
503 | return LastExt == 0 ? AIS_SOP_NothingSelected : AIS_SOP_Removed; |
504 | |
505 | AIS_Selection::SetCurrentSelection( mySelName.ToCString() ); |
506 | |
507 | if ( myAutoHilight ) |
508 | UnhilightPicked( Standard_False ); |
509 | for( myMainVS->Init(); myMainVS->More(); myMainVS->Next() ) { |
510 | const Handle(SelectMgr_EntityOwner)& EO = myMainVS->Picked(); |
511 | if( myFilters->IsOk( EO ) ) { |
512 | Standard_Integer mod = EO->State() == 0 ? -1 : 0; |
513 | AIS_Selection::Select(EO); |
514 | EO->State( mod ); |
515 | } |
516 | } |
517 | if ( myAutoHilight ) |
518 | HilightPicked( updateviewer ); |
519 | } |
520 | Standard_Integer NS = AIS_Selection::Extent(); |
521 | if( NS == 1 ) |
522 | return AIS_SOP_OneSelected; |
523 | else if( NS > 1 ) |
524 | return AIS_SOP_SeveralSelected; |
525 | return AIS_SOP_Error; |
526 | } |
527 | |
528 | //================================================== |
529 | // Function: |
530 | // Purpose : |
531 | //================================================== |
532 | void AIS_LocalContext::Hilight(const Handle(SelectMgr_EntityOwner)& Ownr, |
533 | const Handle(V3d_View)& aview) |
534 | { |
535 | #ifdef BUC60863 |
536 | if( aview.IsNull() ) return; |
537 | aview->TransientManagerClearDraw(); |
538 | #else |
539 | if(aview->TransientManagerBeginDraw()) |
540 | Visual3d_TransientManager::EndDraw(); |
541 | #endif |
542 | myMainPM->BeginDraw(); |
543 | Handle(SelectMgr_SelectableObject) SO = Ownr->Selectable(); |
544 | Standard_Integer HM = GetHiMod(*((Handle(AIS_InteractiveObject)*)&SO)); |
545 | Ownr->HilightWithColor(myMainPM,myCTX->HilightColor(),HM); |
546 | #ifdef IMP051001 |
547 | myMainPM->EndDraw(aview,myCTX->ZDetection()); |
548 | #else |
549 | myMainPM->EndDraw(aview); |
550 | #endif |
551 | |
552 | } |
553 | |
554 | //================================================== |
555 | // Function: |
556 | // Purpose : |
557 | //================================================== |
558 | void AIS_LocalContext::Unhilight(const Handle(SelectMgr_EntityOwner)& Ownr, |
559 | const Handle(V3d_View)& aview) |
560 | { |
561 | |
562 | Handle(SelectMgr_SelectableObject) SO = Ownr->Selectable(); |
563 | Standard_Integer HM = GetHiMod(*((Handle(AIS_InteractiveObject)*)&SO)); |
564 | #ifdef BUC60863 |
565 | if( aview.IsNull() ) return; |
566 | if( IsSelected(Ownr) ) { |
567 | if ( Ownr->IsAutoHilight() ) |
568 | Ownr->HilightWithColor(myMainPM,myCTX->SelectionColor(),HM); |
569 | } |
570 | else |
571 | { |
572 | myMainPM->BeginDraw(); |
573 | Ownr->Unhilight(myMainPM,HM); |
574 | myMainPM->EndDraw(aview); |
575 | } |
576 | aview->TransientManagerClearDraw(); |
577 | #else |
578 | if(aview->TransientManagerBeginDraw()) |
579 | Visual3d_TransientManager::EndDraw(); |
580 | myMainPM->BeginDraw(); |
581 | Ownr->Unhilight(myMainPM,HM); |
582 | myMainPM->EndDraw(aview); |
583 | #endif |
584 | |
585 | } |
586 | |
587 | //======================================================================= |
588 | //function : HilightPicked |
589 | //purpose : |
590 | //======================================================================= |
591 | void AIS_LocalContext::HilightPicked(const Standard_Boolean updateviewer) |
592 | { |
eb4320f2 |
593 | Standard_Boolean updMain(Standard_False); |
7fd59977 |
594 | |
595 | Handle(AIS_Selection) Sel = AIS_Selection::Selection(mySelName.ToCString()); |
596 | #ifdef BUC60765 |
597 | if( Sel.IsNull() ) return; |
598 | #endif |
599 | |
600 | Handle (PrsMgr_PresentationManager3d) PM = myMainPM; |
601 | SelectMgr_DataMapOfObjectOwners aMap; |
602 | |
81bba717 |
603 | // to avoid problems when there is a loop searching for selected objects... |
7fd59977 |
604 | #if !defined OCC189 && !defined USE_MAP |
605 | const TColStd_Array1OfTransient& Obj = Sel->Objects()->Array1(); |
606 | for(Standard_Integer i =Obj.Lower();i<=Sel->NbStored();i++) |
607 | { |
608 | const Handle(Standard_Transient)& Tr = Obj(i); |
609 | #else |
610 | const AIS_NListTransient& Obj = Sel->Objects(); |
611 | AIS_NListTransient::Iterator anIter( Obj ); |
612 | for(; anIter.More(); anIter.Next()) |
613 | { |
614 | const Handle(Standard_Transient)& Tr = anIter.Value(); |
615 | #endif |
616 | if(!Tr.IsNull()){ |
617 | const Handle(SelectMgr_EntityOwner)& Ownr = |
618 | *((const Handle(SelectMgr_EntityOwner)*) &Tr); |
619 | Handle(AIS_InteractiveObject) IO; |
620 | if(Ownr->HasSelectable()){ |
621 | Handle(StdSelect_BRepOwner) BROwnr = Handle(StdSelect_BRepOwner)::DownCast(Ownr); |
622 | if(BROwnr.IsNull() || !BROwnr->ComesFromDecomposition()){ |
623 | Handle(SelectMgr_SelectableObject) SO = Ownr->Selectable(); |
624 | IO = *((Handle(AIS_InteractiveObject)*)&SO); |
eb4320f2 |
625 | updMain = Standard_True; |
7fd59977 |
626 | } |
627 | else |
628 | updMain = Standard_True; |
629 | } |
630 | else |
631 | updMain = Standard_True; |
632 | Handle(SelectMgr_SelectableObject) SO = Ownr->Selectable(); |
633 | Standard_Integer HM = GetHiMod(*((Handle(AIS_InteractiveObject)*)&SO)); |
634 | if ( Ownr->IsAutoHilight() ) |
635 | Ownr->HilightWithColor(PM,myCTX->SelectionColor(),HM); |
636 | else if ( aMap.IsBound (SO) ) |
637 | aMap.ChangeFind(SO).Append ( Ownr ); |
638 | else { |
639 | SelectMgr_SequenceOfOwner aSeq; |
640 | aSeq.Append ( Ownr ); |
641 | aMap.Bind ( SO, aSeq ); |
642 | } |
643 | } |
644 | } |
645 | |
646 | for ( SelectMgr_DataMapIteratorOfMapOfObjectOwners aMapIter(aMap); |
647 | aMapIter.More(); aMapIter.Next() ) |
648 | aMapIter.Key()->HilightSelected ( myMainPM, aMapIter.Value() ); |
649 | |
650 | if(updateviewer){ |
651 | #ifdef BUC60863 |
652 | myCTX->CurrentViewer()->Update(); |
653 | #else |
654 | if(updMain) myCTX->CurrentViewer()->Update(); |
655 | #endif |
7fd59977 |
656 | } |
657 | } |
658 | |
659 | //================================================== |
660 | // Function: |
661 | // Purpose : |
662 | //================================================== |
663 | void AIS_LocalContext:: |
664 | UnhilightPicked(const Standard_Boolean updateviewer) |
665 | { |
eb4320f2 |
666 | Standard_Boolean updMain(Standard_False); |
7fd59977 |
667 | |
668 | Handle(AIS_Selection) Sel = AIS_Selection::Selection(mySelName.ToCString()); |
669 | #ifdef BUC60765 |
670 | if( Sel.IsNull() ) return; |
671 | #endif |
672 | Handle (PrsMgr_PresentationManager3d) PM = myMainPM; |
673 | SelectMgr_DataMapOfObjectOwners anObjMap; |
674 | SelectMgr_SequenceOfOwner anOwnSeq; |
675 | |
676 | #if !defined OCC189 && !defined USE_MAP |
677 | const TColStd_Array1OfTransient& Obj = Sel->Objects()->Array1(); |
678 | for(Standard_Integer i =Obj.Lower();i<=Sel->NbStored();i++){ |
679 | const Handle(Standard_Transient)& Tr = Obj(i); |
680 | #else |
681 | const AIS_NListTransient& Obj = Sel->Objects(); |
682 | AIS_NListTransient::Iterator anIter( Obj ); |
683 | for(; anIter.More(); anIter.Next()){ |
684 | const Handle(Standard_Transient)& Tr = anIter.Value(); |
685 | #endif |
686 | if(!Tr.IsNull()){ |
687 | const Handle(SelectMgr_EntityOwner)& Ownr = |
688 | *((const Handle(SelectMgr_EntityOwner)*) &Tr); |
689 | Standard_Integer HM(0); |
690 | if(Ownr->HasSelectable()){ |
691 | #ifdef BUC60876 |
692 | Handle(SelectMgr_SelectableObject) SO = Ownr->Selectable(); |
693 | Handle(AIS_InteractiveObject) IO = *((Handle(AIS_InteractiveObject)*)&SO); |
694 | anObjMap.Bind ( IO, anOwnSeq ); |
695 | |
696 | HM = GetHiMod(IO); |
697 | #endif |
698 | Handle(StdSelect_BRepOwner) BROwnr = Handle(StdSelect_BRepOwner)::DownCast(Ownr); |
699 | if(BROwnr.IsNull() || !BROwnr->ComesFromDecomposition()){ |
700 | #ifndef BUC60876 |
701 | Handle(SelectMgr_SelectableObject) SO = Ownr->Selectable(); |
702 | Handle(AIS_InteractiveObject) IO = *((Handle(AIS_InteractiveObject)*)&SO); |
703 | HM = GetHiMod(IO); |
704 | #endif |
eb4320f2 |
705 | updMain = Standard_True; |
7fd59977 |
706 | } |
707 | else |
708 | updMain = Standard_True; |
709 | } |
710 | Ownr->Unhilight(PM,HM); |
711 | } |
712 | } |
713 | |
714 | for ( SelectMgr_DataMapIteratorOfMapOfObjectOwners anIter1 ( anObjMap ); |
715 | anIter1.More(); anIter1.Next() ) |
716 | if ( !anIter1.Key()->IsAutoHilight() ) |
717 | anIter1.Key()->ClearSelected(); |
718 | |
719 | if(updateviewer){ |
720 | #ifdef BUC60774 |
721 | myCTX->CurrentViewer()->Update(); |
722 | #else |
723 | if(updMain) myCTX->CurrentViewer()->Update(); |
724 | #endif |
7fd59977 |
725 | } |
726 | |
727 | } |
728 | |
729 | //======================================================================= |
730 | //function : IsSelected |
731 | //purpose : |
732 | //======================================================================= |
733 | Standard_Boolean AIS_LocalContext::IsSelected(const Handle(AIS_InteractiveObject)& anIObj) const |
734 | { |
735 | return (!FindSelectedOwnerFromIO(anIObj).IsNull()); |
736 | } |
737 | |
738 | //======================================================================= |
739 | //function : IsSelected |
740 | //purpose : |
741 | //======================================================================= |
742 | |
743 | Standard_Boolean AIS_LocalContext::IsSelected(const Handle(SelectMgr_EntityOwner)& Ownr) const |
744 | { |
745 | if (Ownr.IsNull()) return Standard_False; |
746 | #ifdef BUC60569 |
747 | Standard_Boolean state = (Ownr->State()!=0); |
748 | #else |
749 | Standard_Boolean state = (Ownr->State()==1); |
750 | #endif |
751 | return state; |
752 | } |
753 | |
754 | //================================================== |
755 | // Function: |
756 | // Purpose : |
757 | //================================================== |
758 | void AIS_LocalContext:: |
759 | InitSelected() |
760 | { |
761 | AIS_Selection::SetCurrentSelection(mySelName.ToCString()); |
762 | AIS_Selection::CurrentSelection()->Init(); |
763 | } |
764 | |
765 | //================================================== |
766 | // Function: |
767 | // Purpose : |
768 | //================================================== |
769 | Standard_Boolean AIS_LocalContext:: |
770 | MoreSelected() const |
771 | { |
772 | return AIS_Selection::CurrentSelection()->More(); |
773 | } |
774 | |
775 | //================================================== |
776 | // Function: |
777 | // Purpose : |
778 | //================================================== |
779 | void AIS_LocalContext:: |
780 | NextSelected() |
781 | { |
782 | AIS_Selection::CurrentSelection()->Next(); |
783 | } |
784 | |
785 | //================================================== |
786 | // Function: |
787 | // Purpose : |
788 | //================================================== |
789 | Standard_Boolean AIS_LocalContext:: |
790 | HasShape() const |
791 | { |
792 | Handle(Standard_Transient) Tr = AIS_Selection::CurrentSelection()->Value(); |
793 | if( Tr.IsNull() ) return Standard_False; |
794 | Handle(SelectMgr_EntityOwner) EO = *((Handle(SelectMgr_EntityOwner)*)&Tr); |
795 | Handle(StdSelect_BRepOwner) BRO = Handle(StdSelect_BRepOwner)::DownCast(EO); |
796 | if(BRO.IsNull()) return Standard_False; |
797 | Standard_Boolean hasshape = BRO->HasShape(); |
798 | Standard_Boolean comes = BRO->ComesFromDecomposition(); |
799 | return (hasshape&&comes); |
800 | } |
801 | |
802 | //================================================== |
803 | // Function: |
804 | // Purpose : |
805 | //================================================== |
806 | const TopoDS_Shape& AIS_LocalContext:: |
807 | SelectedShape() const |
808 | { |
809 | static TopoDS_Shape aSh; |
810 | Handle(Standard_Transient) Tr = AIS_Selection::CurrentSelection()->Value(); |
811 | Handle(SelectMgr_EntityOwner) EO = *((Handle(SelectMgr_EntityOwner)*)&Tr); |
812 | Handle(StdSelect_BRepOwner) BRO = Handle(StdSelect_BRepOwner)::DownCast(EO); |
813 | if( BRO.IsNull() ) |
814 | { |
815 | return aSh; |
816 | } |
817 | return BRO->Shape(); |
818 | } |
819 | |
820 | //================================================== |
821 | // Function: |
822 | // Purpose : |
823 | //================================================== |
824 | Handle(AIS_InteractiveObject) AIS_LocalContext:: |
825 | SelectedInteractive() const |
826 | { |
827 | Handle(AIS_InteractiveObject) IO; |
828 | Handle(Standard_Transient) Tr = AIS_Selection::CurrentSelection()->Value(); |
829 | if( !Tr.IsNull() ) { |
830 | Handle(SelectMgr_EntityOwner) EO = *((Handle(SelectMgr_EntityOwner)*)&Tr); |
831 | Handle(SelectMgr_SelectableObject) SO; |
832 | if(EO->HasSelectable()){ |
833 | SO = EO->Selectable(); |
834 | IO = *((Handle(AIS_InteractiveObject)*)&SO); |
835 | } |
836 | } |
837 | return IO; |
838 | } |
839 | //================================================== |
840 | // Function: |
841 | // Purpose : |
842 | //================================================== |
843 | Handle(SelectMgr_EntityOwner) AIS_LocalContext:: |
844 | SelectedOwner() const |
845 | { |
846 | Handle(SelectMgr_EntityOwner) EO; |
847 | Handle(Standard_Transient) Tr = AIS_Selection::CurrentSelection()->Value(); |
848 | if( !Tr.IsNull() ) |
849 | EO = *((Handle(SelectMgr_EntityOwner)*)&Tr); |
850 | return EO; |
851 | } |
852 | |
853 | //================================================== |
854 | // Function: |
855 | // Purpose : |
856 | //================================================== |
857 | Standard_Boolean AIS_LocalContext:: |
858 | HasApplicative() const |
859 | { |
860 | Handle(AIS_InteractiveObject) IO = SelectedInteractive(); |
861 | if( IO.IsNull() ) return Standard_False; |
862 | return IO->HasOwner(); |
863 | } |
864 | |
865 | //================================================== |
866 | // Function: |
867 | // Purpose : |
868 | //================================================== |
869 | const Handle(Standard_Transient)& AIS_LocalContext:: |
870 | SelectedApplicative() const |
871 | { |
872 | return SelectedInteractive()->GetOwner(); |
873 | } |
874 | |
875 | |
876 | |
877 | //======================================================================= |
878 | //function : UpdateSelection |
81bba717 |
879 | //purpose : should disappear... |
7fd59977 |
880 | //======================================================================= |
881 | void AIS_LocalContext::UpdateSelected(const Standard_Boolean updateviewer) |
882 | { |
883 | UnhilightPicked(Standard_False); |
884 | HilightPicked(updateviewer); |
885 | } |
886 | |
887 | //================================================================ |
888 | // Function : UpdateSelected |
889 | // Purpose : Part of advanced selection mechanism. |
890 | // Highlightes or clears selection presentation for the given IO |
891 | //================================================================ |
892 | void AIS_LocalContext::UpdateSelected(const Handle(AIS_InteractiveObject)& anobj, |
893 | const Standard_Boolean updateviewer) |
894 | { |
895 | if (anobj.IsNull() || anobj->IsAutoHilight()) |
896 | return; |
897 | |
898 | AIS_Selection::SetCurrentSelection(mySelName.ToCString()); |
899 | Handle(AIS_Selection) Sel = AIS_Selection::CurrentSelection(); |
900 | |
901 | SelectMgr_SequenceOfOwner aSeq; |
902 | for ( Sel->Init(); Sel->More(); Sel->Next() ){ |
903 | Handle(SelectMgr_EntityOwner) aOwner = Handle(SelectMgr_EntityOwner)::DownCast(Sel->Value()); |
904 | |
905 | if ( !aOwner.IsNull() && aOwner->HasSelectable() && aOwner->Selectable() == anobj ) |
906 | aSeq.Append( aOwner ); |
907 | } |
908 | |
909 | if ( aSeq.Length() ) |
910 | anobj->HilightSelected( myMainPM, aSeq ); |
911 | else |
912 | anobj->ClearSelected(); |
913 | |
914 | if(updateviewer){ |
915 | myCTX->CurrentViewer()->Update(); |
916 | } |
917 | } |
918 | |
919 | //================================================== |
920 | // Function: ClearSelected |
921 | // Purpose : |
922 | //================================================== |
923 | void AIS_LocalContext::ClearSelected(const Standard_Boolean updateviewer) |
924 | { |
925 | UnhilightPicked(updateviewer); |
926 | AIS_Selection::SetCurrentSelection(mySelName.ToCString()); |
927 | |
928 | Handle(AIS_Selection) Sel = AIS_Selection::CurrentSelection(); |
929 | #if !defined OCC189 && !defined USE_MAP |
930 | const TColStd_Array1OfTransient& Obj = Sel->Objects()->Array1(); |
931 | for(Standard_Integer i =Obj.Lower();i<=Sel->NbStored();i++){ |
932 | const Handle(Standard_Transient)& Tr = Obj(i); |
933 | #else |
934 | const AIS_NListTransient& Obj = Sel->Objects(); |
935 | AIS_NListTransient::Iterator anIter( Obj ); |
936 | for(; anIter.More(); anIter.Next()){ |
937 | const Handle(Standard_Transient)& Tr = anIter.Value(); |
938 | #endif |
939 | if(!Tr.IsNull()){ |
940 | (*((const Handle(SelectMgr_EntityOwner)*)&Tr))->State(0); |
941 | } |
942 | } |
943 | AIS_Selection::Select(); |
944 | mylastindex = 0; |
945 | } |
946 | |
947 | |
948 | //======================================================================= |
949 | //function : SetSelected |
950 | //purpose : |
951 | //======================================================================= |
952 | void AIS_LocalContext::SetSelected(const Handle(AIS_InteractiveObject)& anIObj, |
953 | const Standard_Boolean updateviewer) |
954 | { |
955 | if(!IsValidForSelection(anIObj)) return; |
956 | UnhilightPicked(Standard_False); |
957 | |
81bba717 |
958 | //1st case, owner already <anIObj> as owner |
959 | // and not separated is found... |
7fd59977 |
960 | |
961 | Handle(AIS_Selection) sel = AIS_Selection::Selection(mySelName.ToCString()); |
962 | //Standard_Boolean found(Standard_False); |
963 | Handle(Standard_Transient) Tr; |
964 | Handle(SelectMgr_EntityOwner) EO = FindSelectedOwnerFromIO(anIObj); |
965 | if(EO.IsNull()){ |
81bba717 |
966 | //check if in selection number 0 there is an owner that can be triturated... |
7fd59977 |
967 | if(anIObj->HasSelection(0)){ |
968 | const Handle(SelectMgr_Selection)& SIOBJ = anIObj->Selection(0); |
969 | SIOBJ->Init(); |
970 | if(SIOBJ->More()){ |
971 | Handle(SelectBasics_EntityOwner) BO = SIOBJ->Sensitive()->OwnerId(); |
972 | EO = *((Handle(SelectMgr_EntityOwner)*)&BO); |
973 | } |
974 | } |
975 | if(EO.IsNull()) |
976 | EO = new SelectMgr_EntityOwner(anIObj); |
977 | } |
978 | |
979 | ClearSelected(Standard_False); |
980 | #ifdef OCC138 |
981 | AIS_Selection::Select(EO); |
982 | EO->State(1); |
983 | #else |
984 | EO->State(1); |
985 | AIS_Selection::Select(EO); |
986 | #endif |
987 | HilightPicked(updateviewer); |
988 | } |
989 | |
990 | //======================================================================= |
991 | //function : AddOrRemoveSelected |
992 | //purpose : |
993 | //======================================================================= |
994 | |
995 | void AIS_LocalContext::AddOrRemoveSelected(const Handle(AIS_InteractiveObject)& anIObj, |
996 | const Standard_Boolean updateviewer) |
997 | { |
998 | if(!IsValidForSelection(anIObj)) return; |
999 | UnhilightPicked(Standard_False); |
81bba717 |
1000 | // first check if it is selected... |
7fd59977 |
1001 | Handle(SelectMgr_EntityOwner) EO; |
1002 | |
1003 | EO = FindSelectedOwnerFromIO(anIObj); |
1004 | #ifndef OCC138 |
1005 | if(!EO.IsNull()) |
1006 | EO->State(0); |
1007 | else{ |
1008 | #else |
1009 | if(EO.IsNull()) { |
1010 | #endif |
1011 | if(anIObj->HasSelection(0)){ |
1012 | const Handle(SelectMgr_Selection)& SIOBJ = anIObj->Selection(0); |
1013 | SIOBJ->Init(); |
1014 | if(SIOBJ->More()){ |
1015 | Handle(SelectBasics_EntityOwner) BO = SIOBJ->Sensitive()->OwnerId(); |
1016 | EO = *((Handle(SelectMgr_EntityOwner)*)&BO); |
1017 | } |
1018 | } |
1019 | if(EO.IsNull()) |
1020 | EO = new SelectMgr_EntityOwner(anIObj); |
1021 | #ifndef OCC138 |
1022 | EO->State(1); |
1023 | #endif |
1024 | } |
1025 | |
1026 | // cout<<"AIS_LocalContext::AddOrRemoveSelected : Selection = "<<mySelName<<endl; |
1027 | const Handle(AIS_Selection)& S = AIS_Selection::Selection(mySelName.ToCString()); |
1028 | #ifdef OCC138 |
1029 | if(!S.IsNull()) { |
1030 | AIS_SelectStatus aStatus = S->Select(EO); |
1031 | if(aStatus == AIS_SS_Added) |
1032 | EO->State(1); |
1033 | else |
1034 | EO->State(0); |
1035 | } |
1036 | #else |
1037 | if(!S.IsNull()) |
1038 | S->Select(EO); |
1039 | #endif |
1040 | HilightPicked(updateviewer); |
1041 | } |
1042 | |
1043 | //======================================================================= |
1044 | //function : AddOrRemoveSelected |
81bba717 |
1045 | //purpose : To check... |
7fd59977 |
1046 | //======================================================================= |
1047 | void AIS_LocalContext::AddOrRemoveSelected(const TopoDS_Shape& Sh, |
1048 | const Standard_Boolean updateviewer) |
1049 | { |
1050 | UnhilightPicked(Standard_False); |
1051 | Handle(SelectMgr_EntityOwner) EO = FindSelectedOwnerFromShape(Sh); |
1052 | if(!EO.IsNull()){ |
1053 | // cout<<"AIS_LocalContext::AddOrRemoveSelected(sh) : Selection = "<<mySelName<<endl; |
1054 | |
1055 | #ifdef OCC138 |
1056 | AIS_Selection::Selection(mySelName.ToCString())->Select(EO); |
1057 | EO->State(1); |
1058 | #else |
1059 | EO->State(1); |
1060 | AIS_Selection::Selection(mySelName.ToCString())->Select(EO); |
1061 | #endif |
1062 | } |
1063 | HilightPicked(updateviewer); |
1064 | } |
1065 | |
1066 | void AIS_LocalContext::AddOrRemoveSelected(const Handle(SelectMgr_EntityOwner)& Ownr, |
1067 | const Standard_Boolean updateviewer) |
1068 | { |
1069 | //Not Yet Implemented |
1070 | if(myAutoHilight) |
1071 | UnhilightPicked(Standard_False); |
1072 | // cout<<"AIS_LocalContext::AddOrRemoveSelected(ownr) : Selection = "<<mySelName<<endl; |
1073 | |
1074 | Standard_Integer mod = Ownr->State()==0 ? 1 : 0; |
1075 | #ifdef OCC138 |
1076 | AIS_Selection::Selection(mySelName.ToCString())->Select(Ownr); |
1077 | |
1078 | Ownr->State(mod); |
1079 | #else |
1080 | Ownr->State(mod); |
1081 | |
1082 | AIS_Selection::Selection(mySelName.ToCString())->Select(Ownr); |
1083 | #endif |
1084 | if(myAutoHilight) |
1085 | HilightPicked(updateviewer); |
1086 | } |
1087 | |
1088 | //================================================== |
1089 | // Function: |
1090 | // Purpose : |
1091 | //================================================== |
1092 | void AIS_LocalContext::ManageDetected(const Handle(SelectMgr_EntityOwner)& aPickOwner, |
1093 | const Handle(V3d_View)& aview) |
1094 | { |
1095 | #ifdef BUC60818 |
1096 | // Warning : aPickOwner may be null ! |
1097 | if (aPickOwner.IsNull()) return; |
1098 | #else |
1099 | if(!myAutoHilight) return; |
1100 | #endif |
1101 | // const Handle(SelectMgr_SelectableObject)& SO = aPickOwner->Selectable(); |
1102 | Standard_Boolean okStatus = myFilters->IsOk(aPickOwner); |
1103 | // OK... |
1104 | if(okStatus){ |
1105 | //======================================================================================================= |
81bba717 |
1106 | // 2 cases : a- object is in the map of picks: |
1107 | // 1. this is the same index as the last detected: -> Do nothing |
1108 | // 2. otherwise : |
1109 | // - if lastindex = 0 (no object was detected at the last step) |
1110 | // the object presentation is highlighted and lastindex = index(objet) |
1111 | // - othrwise : |
1112 | // the presentation of the object corresponding to lastindex is "unhighlighted" |
1113 | // it is removed if the object is not visualized but only active |
1114 | // then the presentation of the detected object is highlighted and lastindex = index(objet) |
1115 | // b- the object is not in the map of picked objects |
1116 | // - if lastindex != 0 (object detected at the last step) it is unhighlighted ... |
1117 | // if the object was decomposed, presentation is created for the detected shape and the couple |
1118 | // (Proprietaire,Prs)is added in the map. |
1119 | // otherwise the couple(proprietaire, NullPrs) is placed in the map and the interactive object |
1120 | // itself is highlighted. |
7fd59977 |
1121 | // |
1122 | //======================================================================================================= |
1123 | |
1124 | |
1125 | //szv: |
1126 | Standard_Boolean wasContained = myMapOfOwner.Contains(aPickOwner); |
1127 | Standard_Integer theNewIndex = 0; |
1128 | if (wasContained) |
1129 | theNewIndex = myMapOfOwner.FindIndex(aPickOwner); |
1130 | else |
1131 | theNewIndex = myMapOfOwner.Add(aPickOwner); |
1132 | |
1133 | // For the advanced mesh selection mode the owner indices comparison |
1134 | // is not effective because in that case only one owner manage the |
1135 | // selection in current selection mode. It is necessary to check the current detected |
1136 | // entity and hilight it only if the detected entity is not the same as |
1137 | // previous detected (IsForcedHilight call) |
1138 | if (theNewIndex != mylastindex || aPickOwner->IsForcedHilight()) { |
1139 | |
1140 | if (mylastindex && mylastindex <= myMapOfOwner.Extent()) { |
1141 | |
1142 | const Handle(SelectMgr_EntityOwner)& LastOwnr = myMapOfOwner(mylastindex); |
1143 | #ifdef BUC60863 |
1144 | Unhilight(LastOwnr,aview); |
1145 | #else |
1146 | if(!IsSelected(LastOwnr)) |
1147 | Unhilight(LastOwnr,aview); |
1148 | #endif |
1149 | } |
1150 | |
1151 | if (myAutoHilight) { |
1152 | // wasContained should not be checked because with this verification different |
1153 | // behaviour of application may occer depending whether mouse is moved above |
1154 | // owner first or second time |
1155 | //if (wasContained) { |
1156 | #ifdef BUC60569 |
1157 | if (aPickOwner->State() <= 0 || myCTX->ToHilightSelected()) |
1158 | #else |
1159 | if(!IsSelected (aPickOwner) || myCTX->ToHilightSelected()) |
1160 | #endif |
1161 | Hilight(aPickOwner,aview); |
1162 | /*} |
1163 | else Hilight(aPickOwner,aview);*/ |
1164 | } |
1165 | |
1166 | mylastindex = theNewIndex; |
1167 | } |
1168 | } |
1169 | |
1170 | if (mylastindex) mylastgood = mylastindex; |
1171 | |
1172 | } |
1173 | |
1174 | |
1175 | //======================================================================= |
1176 | //function : HasDetectedShape |
1177 | //purpose : |
1178 | //======================================================================= |
1179 | |
1180 | Standard_Boolean AIS_LocalContext::HasDetectedShape() const |
1181 | { |
1182 | if(mylastindex==0) return Standard_False; |
1183 | return IsShape(mylastindex); |
1184 | } |
1185 | |
1186 | //======================================================================= |
1187 | //function : DetectedShape |
1188 | //purpose : |
1189 | //======================================================================= |
1190 | |
1191 | const TopoDS_Shape& |
1192 | AIS_LocalContext::DetectedShape() const |
1193 | { |
1194 | static TopoDS_Shape bidsh; |
1195 | if(mylastindex != 0) |
1196 | { |
1197 | Handle(StdSelect_BRepOwner) BROwnr = Handle(StdSelect_BRepOwner)::DownCast(myMapOfOwner(mylastindex)); |
1198 | if(BROwnr.IsNull()) return bidsh; |
1199 | return BROwnr->Shape(); |
1200 | } |
1201 | return bidsh; |
1202 | } |
1203 | |
1204 | //======================================================================= |
1205 | //function : DetectedInteractive |
1206 | //purpose : |
1207 | //======================================================================= |
1208 | |
1209 | Handle(AIS_InteractiveObject) |
1210 | AIS_LocalContext::DetectedInteractive() const |
1211 | { |
1212 | Handle(AIS_InteractiveObject) Iobj; |
1213 | if(IsValidIndex(mylastindex)){ |
1214 | Handle(SelectMgr_SelectableObject) SO = myMapOfOwner.FindKey(mylastindex)->Selectable(); |
1215 | Iobj = *((Handle(AIS_InteractiveObject)*) &SO); |
1216 | } |
1217 | return Iobj; |
1218 | } |
1219 | //======================================================================= |
1220 | //function : DetectedInteractive |
1221 | //purpose : |
1222 | //======================================================================= |
1223 | Handle(SelectMgr_EntityOwner) AIS_LocalContext::DetectedOwner() const |
1224 | { |
1225 | Handle(SelectMgr_EntityOwner) bid; |
1226 | if(!IsValidIndex(mylastindex)) return bid; |
1227 | return myMapOfOwner.FindKey(mylastindex); |
1228 | } |
1229 | |
1230 | |
1231 | //======================================================================= |
1232 | //function : ComesFromDecomposition |
1233 | //purpose : |
1234 | //======================================================================= |
1235 | |
1236 | Standard_Boolean AIS_LocalContext::ComesFromDecomposition(const Standard_Integer PickedIndex) const |
1237 | { |
1238 | const Handle(SelectMgr_EntityOwner)& OWN = myMapOfOwner.FindKey(PickedIndex); |
1239 | Handle(SelectMgr_SelectableObject) aSel = OWN->Selectable(); |
81bba717 |
1240 | if (myActiveObjects.IsBound (aSel)) { // debug of jmi |
7fd59977 |
1241 | const Handle(AIS_LocalStatus)& Stat = myActiveObjects(aSel); |
1242 | return Stat->Decomposed(); |
1243 | } |
1244 | return Standard_False; |
1245 | } |
1246 | |
1247 | |
1248 | //======================================================================= |
1249 | //function : DisplayAreas |
1250 | //purpose : |
1251 | //======================================================================= |
1252 | |
1253 | void AIS_LocalContext::DisplayAreas(const Handle(V3d_View)& aviou) |
1254 | { |
1255 | myMainVS->DisplayAreas(aviou); |
1256 | } |
1257 | |
1258 | //======================================================================= |
1259 | //function : ClearAreas |
1260 | //purpose : |
1261 | //======================================================================= |
1262 | |
1263 | void AIS_LocalContext::ClearAreas(const Handle(V3d_View)& aviou) |
1264 | { |
1265 | myMainVS->ClearAreas(aviou); |
1266 | } |
1267 | |
1268 | //======================================================================= |
1269 | //function : DisplaySensitive |
1270 | //purpose : |
1271 | //======================================================================= |
1272 | |
1273 | void AIS_LocalContext::DisplaySensitive(const Handle(V3d_View)& aviou) |
1274 | { |
1275 | myMainVS->DisplaySensitive(aviou); |
1276 | } |
1277 | |
1278 | //======================================================================= |
1279 | //function : ClearSensitive |
1280 | //purpose : |
1281 | //======================================================================= |
1282 | |
1283 | void AIS_LocalContext::ClearSensitive(const Handle(V3d_View)& aviou) |
1284 | { |
1285 | myMainVS->ClearSensitive(aviou); |
1286 | } |
1287 | |
1288 | |
1289 | //======================================================================= |
1290 | //function : IsShape |
1291 | //purpose : |
1292 | //======================================================================= |
1293 | Standard_Boolean AIS_LocalContext::IsShape(const Standard_Integer Index) const |
1294 | { |
1295 | |
1296 | if(Handle(StdSelect_BRepOwner)::DownCast(myMapOfOwner.FindKey(Index)).IsNull()) |
1297 | return Standard_False; |
1298 | return |
1299 | ComesFromDecomposition(Index); |
1300 | } |
1301 | |
1302 | Standard_Boolean AIS_LocalContext::IsValidForSelection(const Handle(AIS_InteractiveObject)& anIObj) const |
1303 | { |
1304 | |
1305 | #ifdef IMP120701 |
1306 | // Shape was not transfered from AIS_Shape to EntityOwner |
1307 | Handle(AIS_Shape) shape = Handle(AIS_Shape)::DownCast(anIObj); |
1308 | if( !shape.IsNull() ) |
1309 | return myFilters->IsOk(new StdSelect_BRepOwner(shape->Shape(),shape)); |
1310 | #endif |
1311 | return myFilters->IsOk(new SelectMgr_EntityOwner(anIObj)); |
1312 | } |
1313 | |
1314 | |
1315 | //======================================================================= |
1316 | //function : HilightNextDetected |
1317 | //purpose : |
1318 | //======================================================================= |
1319 | |
1320 | Standard_Integer AIS_LocalContext::HilightNextDetected(const Handle(V3d_View)& V) |
1321 | { |
81bba717 |
1322 | // go to the next owner |
7fd59977 |
1323 | |
1324 | if(myDetectedSeq.IsEmpty()) return Standard_False; |
1325 | Standard_Integer L = myDetectedSeq.Length(); |
1326 | myCurDetected++; |
1327 | |
1328 | if(myCurDetected>L) |
1329 | myCurDetected = 1; |
1330 | Handle(SelectMgr_EntityOwner) EO = myMainVS->Picked(myCurDetected); |
1331 | #ifdef IMP120402 |
1332 | if( EO.IsNull() ) return 0; |
1333 | #endif |
1334 | |
1335 | static Standard_Boolean Normal_State(Standard_True); |
1336 | static Standard_Boolean firsttime(Standard_True); |
1337 | if(firsttime){ |
1338 | OSD_Environment toto("HITRI"); |
1339 | if(!toto.Value().IsEmpty()) |
1340 | Normal_State = Standard_False; |
1341 | firsttime = Standard_False; |
1342 | } |
1343 | |
1344 | |
1345 | if(Normal_State) |
1346 | ManageDetected(EO,V); |
1347 | else |
1348 | HilightTriangle(myCurDetected,V); |
1349 | return myCurDetected; |
1350 | } |
1351 | |
1352 | //======================================================================= |
1353 | //function : HilightPreviousDetected |
1354 | //purpose : |
1355 | //======================================================================= |
1356 | Standard_Integer AIS_LocalContext::HilightPreviousDetected(const Handle(V3d_View)& V) |
1357 | { |
1358 | if(myDetectedSeq.IsEmpty()) return Standard_False; |
1359 | |
1360 | myCurDetected--; |
1361 | |
1362 | if(myCurDetected<1) |
1363 | myCurDetected = 1; |
1364 | Handle(SelectMgr_EntityOwner) EO = myMainVS->Picked(myCurDetected); |
1365 | #ifdef IMP120402 |
1366 | if( EO.IsNull() ) return 0; |
1367 | #endif |
1368 | |
1369 | static Standard_Boolean Normal_State(Standard_True); |
1370 | static Standard_Boolean firsttime(Standard_True); |
1371 | if(firsttime){ |
1372 | OSD_Environment toto("HITRI"); |
1373 | if(!toto.Value().IsEmpty()) |
1374 | Normal_State = Standard_False; |
1375 | firsttime = Standard_False; |
1376 | } |
1377 | |
1378 | |
1379 | |
1380 | if(Normal_State) |
1381 | ManageDetected(EO,V); |
1382 | else |
1383 | HilightTriangle(myCurDetected,V); |
1384 | return myCurDetected; |
1385 | } |
1386 | |
1387 | //======================================================================= |
1388 | //function : UnhilightLastDetected |
1389 | //purpose : |
1390 | //======================================================================= |
1391 | Standard_Boolean AIS_LocalContext::UnhilightLastDetected(const Handle(V3d_View)& aview) |
1392 | { |
1393 | if(!IsValidIndex(mylastindex)) return Standard_False; |
1394 | myMainPM->BeginDraw(); |
1395 | const Handle(SelectMgr_EntityOwner)& Ownr = myMapOfOwner(mylastindex); |
1396 | Standard_Integer HM(0); |
1397 | if(Ownr->HasSelectable()){ |
1398 | Handle(SelectMgr_SelectableObject) SO = Ownr->Selectable(); |
1399 | HM = GetHiMod(*((Handle(AIS_InteractiveObject)*)&SO)); |
1400 | } |
1401 | myMapOfOwner(mylastindex)->Unhilight(myMainPM,HM); |
1402 | myMainPM->EndDraw(aview); |
1403 | mylastindex =0; |
1404 | return Standard_True; |
1405 | } |
1406 | |
1407 | |
1408 | |
1409 | //======================================================================= |
1410 | //function : HilightTriangle |
1411 | //purpose : |
1412 | //======================================================================= |
1413 | |
1414 | void AIS_LocalContext::HilightTriangle(const Standard_Integer Rank, |
1415 | const Handle(V3d_View)& view) |
1416 | { |
1417 | static Standard_Integer PrevRank(0); |
1418 | if(Rank==PrevRank) return; |
7fd59977 |
1419 | Handle(SelectBasics_SensitiveEntity) SE = myMainVS->Primitive(Rank); |
b8ddfc2f |
1420 | if(SE->IsKind(STANDARD_TYPE(Select3D_SensitiveTriangulation))) |
1421 | { |
7fd59977 |
1422 | Handle(Select3D_SensitiveTriangulation) Tr = *((Handle(Select3D_SensitiveTriangulation)*)&SE); |
1423 | gp_Pnt p1,p2,p3 ; Tr->DetectedTriangle(p1,p2,p3); |
7fd59977 |
1424 | |
b8ddfc2f |
1425 | Handle(Graphic3d_ArrayOfTriangles) aTris = new Graphic3d_ArrayOfTriangles(3); |
1426 | aTris->AddVertex(p1); |
1427 | aTris->AddVertex(p2); |
1428 | aTris->AddVertex(p3); |
1429 | |
1430 | static Handle(Prs3d_Presentation) TriPrs = |
7fd59977 |
1431 | new Prs3d_Presentation(myMainPM->StructureManager()); |
1432 | TriPrs->Clear(); |
1433 | #ifdef IMP300101 |
1434 | Handle(Prs3d_ShadingAspect) asp = myCTX->DefaultDrawer()->ShadingAspect(); |
1435 | asp->SetColor(myCTX->HilightColor()); |
1436 | TriPrs->SetShadingAspect(asp); |
1437 | #endif |
b8ddfc2f |
1438 | Prs3d_Root::CurrentGroup(TriPrs)->AddPrimitiveArray(aTris); |
7fd59977 |
1439 | |
1440 | #ifndef IMP300101 |
1441 | if(view->TransientManagerBeginDraw()) |
1442 | Visual3d_TransientManager::EndDraw(); |
1443 | #endif |
1444 | if(view->TransientManagerBeginDraw()) { |
7fd59977 |
1445 | Visual3d_TransientManager::DrawStructure(TriPrs); |
1446 | Visual3d_TransientManager::EndDraw(); |
1447 | } |
7fd59977 |
1448 | } |
7fd59977 |
1449 | } |
1450 | |
1451 | //======================================================================= |
1452 | //function : FindSelectedOwnerFromIO |
81bba717 |
1453 | //purpose : it is checked if one of the selected owners really presents IObj |
7fd59977 |
1454 | //======================================================================= |
1455 | Handle(SelectMgr_EntityOwner) AIS_LocalContext::FindSelectedOwnerFromIO |
1456 | (const Handle(AIS_InteractiveObject)& anIObj) const |
1457 | { |
1458 | Handle(SelectMgr_EntityOwner) EO,bid; |
1459 | if (anIObj.IsNull()) return EO; |
1460 | |
1461 | Handle(AIS_Selection) Sel = AIS_Selection::Selection(mySelName.ToCString()); |
1462 | if(Sel.IsNull()) { |
1463 | #ifdef DEB |
1464 | cout<<"\t\tAIS_LocalCOntext::FindSelectedOwnerFromShape : Selection " |
1465 | <<mySelName<<" Nulle "<<endl; |
1466 | #endif |
1467 | return EO; |
1468 | } |
1469 | Standard_Boolean found(Standard_False); |
1470 | #if !defined OCC189 && !defined USE_MAP |
1471 | const TColStd_Array1OfTransient& Obj = Sel->Objects()->Array1(); |
1472 | for(Standard_Integer i =Obj.Lower();i<=Sel->NbStored();i++){ |
1473 | const Handle(Standard_Transient)& Tr = Obj(i); |
1474 | #else |
1475 | const AIS_NListTransient& Obj = Sel->Objects(); |
1476 | AIS_NListTransient::Iterator anIter( Obj ); |
1477 | for(; anIter.More(); anIter.Next()){ |
1478 | const Handle(Standard_Transient)& Tr = anIter.Value(); |
1479 | #endif |
1480 | if(!Tr.IsNull()){ |
1481 | EO = *((Handle(SelectMgr_EntityOwner)*)&Tr); |
1482 | if(EO->HasSelectable()){ |
1483 | Handle(StdSelect_BRepOwner) BROwnr = Handle(StdSelect_BRepOwner)::DownCast(EO); |
1484 | if(BROwnr.IsNull() || !BROwnr->ComesFromDecomposition()){ |
1485 | if (anIObj == EO->Selectable()){ |
1486 | found =Standard_True; |
1487 | break; |
1488 | } |
1489 | } |
1490 | } |
1491 | } |
1492 | } |
1493 | if(found) return EO; |
1494 | return bid; |
1495 | } |
1496 | |
1497 | //======================================================================= |
1498 | //function : FindSelectedOwnerFromShape |
81bba717 |
1499 | //purpose : it is checked if one of the selected owners really presents IObj |
7fd59977 |
1500 | //======================================================================= |
1501 | Handle(SelectMgr_EntityOwner) AIS_LocalContext::FindSelectedOwnerFromShape(const TopoDS_Shape& sh) const |
1502 | { |
1503 | #ifdef OCC9026 |
1504 | Handle(SelectMgr_EntityOwner) EO, bid; |
1505 | #else |
1506 | Handle(SelectMgr_EntityOwner) EO; |
1507 | #endif |
1508 | if (sh.IsNull()) return EO; |
1509 | |
1510 | Handle(AIS_Selection) Sel = AIS_Selection::Selection(mySelName.ToCString()); |
1511 | if(Sel.IsNull()) { |
1512 | #ifdef DEB |
1513 | cout<<"\t\tAIS_LocalCOntext::FindSelectedOwnerFromShape : Selection "<<mySelName<<" Nulle "<<endl; |
1514 | #endif |
1515 | return EO; |
1516 | } |
1517 | |
1518 | Standard_Boolean found(Standard_False); |
1519 | |
1520 | #ifdef OCC9026 |
1521 | if (!found) { |
7fd59977 |
1522 | SelectMgr_DataMapIteratorOfDataMapOfIntegerSensitive aSensitiveIt (myMainVS->Primitives()); |
1523 | for (; aSensitiveIt.More(); aSensitiveIt.Next()) { |
1524 | EO = Handle(SelectMgr_EntityOwner)::DownCast (aSensitiveIt.Value()->OwnerId()); |
1525 | Handle(StdSelect_BRepOwner) BROwnr = Handle(StdSelect_BRepOwner)::DownCast(EO); |
1526 | if (!BROwnr.IsNull() && BROwnr->HasShape() && BROwnr->Shape() == sh) { |
1527 | found = Standard_True; |
1528 | break; |
1529 | } |
1530 | } |
1531 | } |
1532 | #else |
1533 | #if !defined OCC189 && !defined USE_MAP |
1534 | const TColStd_Array1OfTransient& Obj = Sel->Objects()->Array1(); |
1535 | for(Standard_Integer i =Obj.Lower();i<=Sel->NbStored();i++){ |
1536 | const Handle(Standard_Transient)& Tr = Obj(i); |
1537 | #else |
1538 | const AIS_NListTransient& Obj = Sel->Objects(); |
1539 | AIS_NListTransient::Iterator anIter( Obj ); |
1540 | for(; anIter.More(); anIter.Next()){ |
1541 | const Handle(Standard_Transient)& Tr = anIter.Value(); |
1542 | #endif |
1543 | if(!Tr.IsNull()){ |
1544 | |
1545 | EO = *((Handle(SelectMgr_EntityOwner)*)&Tr); |
1546 | if(EO->HasShape()) |
1547 | if ( EO->Shape() == sh) |
1548 | found =Standard_True; |
1549 | break; |
1550 | } |
1551 | } |
1552 | #endif |
1553 | |
1554 | if(found) return EO; |
1555 | return bid; |
1556 | } |
1557 | |
1558 | #ifdef IMP160701 |
1559 | //======================================================================= |
1560 | //function : AIS_LocalContext::InitDetected |
1561 | //purpose : |
1562 | //======================================================================= |
1563 | |
1564 | void AIS_LocalContext::InitDetected() |
1565 | { |
1566 | myAISCurDetected = myAISDetectedSeq.Length()? 1 : 0; |
1567 | } |
1568 | |
1569 | //======================================================================= |
1570 | //function : AIS_LocalContext::MoreDetected |
1571 | //purpose : |
1572 | //======================================================================= |
1573 | |
1574 | Standard_Boolean AIS_LocalContext::MoreDetected() const |
1575 | { |
1576 | return (myAISCurDetected > 0 && myAISCurDetected <= myAISDetectedSeq.Length()); |
1577 | } |
1578 | |
1579 | |
1580 | //======================================================================= |
1581 | //function : AIS_LocalContext::NextDetected |
1582 | //purpose : |
1583 | //======================================================================= |
1584 | |
1585 | void AIS_LocalContext::NextDetected() |
1586 | { |
1587 | if (MoreDetected()) myAISCurDetected++; |
1588 | } |
1589 | |
1590 | //======================================================================= |
1591 | //function : DetectedCurrentShape |
1592 | //purpose : |
1593 | //======================================================================= |
1594 | |
1595 | const TopoDS_Shape& AIS_LocalContext::DetectedCurrentShape() const |
1596 | { |
1597 | static TopoDS_Shape bidsh; |
1598 | if (MoreDetected()) |
1599 | return Handle(AIS_Shape)::DownCast(myAISDetectedSeq(myAISCurDetected))->Shape(); |
1600 | return bidsh; |
1601 | } |
1602 | |
1603 | //======================================================================= |
1604 | //function : DetectedCurrentObject |
1605 | //purpose : |
1606 | //======================================================================= |
1607 | |
1608 | Handle(AIS_InteractiveObject) AIS_LocalContext::DetectedCurrentObject() const |
1609 | { |
1610 | Handle(AIS_InteractiveObject) theIObj; |
1611 | if (MoreDetected()) |
1612 | theIObj = myAISDetectedSeq(myAISCurDetected); |
1613 | |
1614 | return theIObj; |
1615 | } |
1616 | #endif |