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