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