0024166: Unable to create file with "Save" menu of voxeldemo Qt sample
[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{
eb4320f2 597 Standard_Boolean updMain(Standard_False);
7fd59977 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);
eb4320f2 629 updMain = Standard_True;
7fd59977 630 }
631 else
632 updMain = Standard_True;
633 }
634 else
635 updMain = Standard_True;
636 Handle(SelectMgr_SelectableObject) SO = Ownr->Selectable();
637 Standard_Integer HM = GetHiMod(*((Handle(AIS_InteractiveObject)*)&SO));
638 if ( Ownr->IsAutoHilight() )
639 Ownr->HilightWithColor(PM,myCTX->SelectionColor(),HM);
640 else if ( aMap.IsBound (SO) )
641 aMap.ChangeFind(SO).Append ( Ownr );
642 else {
643 SelectMgr_SequenceOfOwner aSeq;
644 aSeq.Append ( Ownr );
645 aMap.Bind ( SO, aSeq );
646 }
647 }
648 }
649
650 for ( SelectMgr_DataMapIteratorOfMapOfObjectOwners aMapIter(aMap);
651 aMapIter.More(); aMapIter.Next() )
652 aMapIter.Key()->HilightSelected ( myMainPM, aMapIter.Value() );
653
654 if(updateviewer){
655#ifdef BUC60863
656 myCTX->CurrentViewer()->Update();
657#else
658 if(updMain) myCTX->CurrentViewer()->Update();
659#endif
7fd59977 660 }
661}
662
663//==================================================
664// Function:
665// Purpose :
666//==================================================
667void AIS_LocalContext::
668UnhilightPicked(const Standard_Boolean updateviewer)
669{
eb4320f2 670 Standard_Boolean updMain(Standard_False);
7fd59977 671
672 Handle(AIS_Selection) Sel = AIS_Selection::Selection(mySelName.ToCString());
673#ifdef BUC60765
674 if( Sel.IsNull() ) return;
675#endif
676 Handle (PrsMgr_PresentationManager3d) PM = myMainPM;
677 SelectMgr_DataMapOfObjectOwners anObjMap;
678 SelectMgr_SequenceOfOwner anOwnSeq;
679
680#if !defined OCC189 && !defined USE_MAP
681 const TColStd_Array1OfTransient& Obj = Sel->Objects()->Array1();
682 for(Standard_Integer i =Obj.Lower();i<=Sel->NbStored();i++){
683 const Handle(Standard_Transient)& Tr = Obj(i);
684#else
685 const AIS_NListTransient& Obj = Sel->Objects();
686 AIS_NListTransient::Iterator anIter( Obj );
687 for(; anIter.More(); anIter.Next()){
688 const Handle(Standard_Transient)& Tr = anIter.Value();
689#endif
690 if(!Tr.IsNull()){
691 const Handle(SelectMgr_EntityOwner)& Ownr =
692 *((const Handle(SelectMgr_EntityOwner)*) &Tr);
693 Standard_Integer HM(0);
694 if(Ownr->HasSelectable()){
695#ifdef BUC60876
696 Handle(SelectMgr_SelectableObject) SO = Ownr->Selectable();
697 Handle(AIS_InteractiveObject) IO = *((Handle(AIS_InteractiveObject)*)&SO);
698 anObjMap.Bind ( IO, anOwnSeq );
699
700 HM = GetHiMod(IO);
701#endif
702 Handle(StdSelect_BRepOwner) BROwnr = Handle(StdSelect_BRepOwner)::DownCast(Ownr);
703 if(BROwnr.IsNull() || !BROwnr->ComesFromDecomposition()){
704#ifndef BUC60876
705 Handle(SelectMgr_SelectableObject) SO = Ownr->Selectable();
706 Handle(AIS_InteractiveObject) IO = *((Handle(AIS_InteractiveObject)*)&SO);
707 HM = GetHiMod(IO);
708#endif
eb4320f2 709 updMain = Standard_True;
7fd59977 710 }
711 else
712 updMain = Standard_True;
713 }
714 Ownr->Unhilight(PM,HM);
715 }
716 }
717
718 for ( SelectMgr_DataMapIteratorOfMapOfObjectOwners anIter1 ( anObjMap );
719 anIter1.More(); anIter1.Next() )
720 if ( !anIter1.Key()->IsAutoHilight() )
721 anIter1.Key()->ClearSelected();
722
723 if(updateviewer){
724#ifdef BUC60774
725 myCTX->CurrentViewer()->Update();
726#else
727 if(updMain) myCTX->CurrentViewer()->Update();
728#endif
7fd59977 729 }
730
731}
732
733//=======================================================================
734//function : IsSelected
735//purpose :
736//=======================================================================
737Standard_Boolean AIS_LocalContext::IsSelected(const Handle(AIS_InteractiveObject)& anIObj) const
738{
739 return (!FindSelectedOwnerFromIO(anIObj).IsNull());
740}
741
742//=======================================================================
743//function : IsSelected
744//purpose :
745//=======================================================================
746
747Standard_Boolean AIS_LocalContext::IsSelected(const Handle(SelectMgr_EntityOwner)& Ownr) const
748{
749 if (Ownr.IsNull()) return Standard_False;
750#ifdef BUC60569
751 Standard_Boolean state = (Ownr->State()!=0);
752#else
753 Standard_Boolean state = (Ownr->State()==1);
754#endif
755 return state;
756}
757
758//==================================================
759// Function:
760// Purpose :
761//==================================================
762void AIS_LocalContext::
763InitSelected()
764{
765 AIS_Selection::SetCurrentSelection(mySelName.ToCString());
766 AIS_Selection::CurrentSelection()->Init();
767}
768
769//==================================================
770// Function:
771// Purpose :
772//==================================================
773Standard_Boolean AIS_LocalContext::
774MoreSelected() const
775{
776 return AIS_Selection::CurrentSelection()->More();
777}
778
779//==================================================
780// Function:
781// Purpose :
782//==================================================
783void AIS_LocalContext::
784NextSelected()
785{
786 AIS_Selection::CurrentSelection()->Next();
787}
788
789//==================================================
790// Function:
791// Purpose :
792//==================================================
793Standard_Boolean AIS_LocalContext::
794HasShape() const
795{
796 Handle(Standard_Transient) Tr = AIS_Selection::CurrentSelection()->Value();
797 if( Tr.IsNull() ) return Standard_False;
798 Handle(SelectMgr_EntityOwner) EO = *((Handle(SelectMgr_EntityOwner)*)&Tr);
799 Handle(StdSelect_BRepOwner) BRO = Handle(StdSelect_BRepOwner)::DownCast(EO);
800 if(BRO.IsNull()) return Standard_False;
801 Standard_Boolean hasshape = BRO->HasShape();
802 Standard_Boolean comes = BRO->ComesFromDecomposition();
803 return (hasshape&&comes);
804}
805
806//==================================================
807// Function:
808// Purpose :
809//==================================================
810const TopoDS_Shape& AIS_LocalContext::
811SelectedShape() const
812{
813 static TopoDS_Shape aSh;
814 Handle(Standard_Transient) Tr = AIS_Selection::CurrentSelection()->Value();
815 Handle(SelectMgr_EntityOwner) EO = *((Handle(SelectMgr_EntityOwner)*)&Tr);
816 Handle(StdSelect_BRepOwner) BRO = Handle(StdSelect_BRepOwner)::DownCast(EO);
817 if( BRO.IsNull() )
818 {
819 return aSh;
820 }
821 return BRO->Shape();
822}
823
824//==================================================
825// Function:
826// Purpose :
827//==================================================
828Handle(AIS_InteractiveObject) AIS_LocalContext::
829SelectedInteractive() const
830{
831 Handle(AIS_InteractiveObject) IO;
832 Handle(Standard_Transient) Tr = AIS_Selection::CurrentSelection()->Value();
833 if( !Tr.IsNull() ) {
834 Handle(SelectMgr_EntityOwner) EO = *((Handle(SelectMgr_EntityOwner)*)&Tr);
835 Handle(SelectMgr_SelectableObject) SO;
836 if(EO->HasSelectable()){
837 SO = EO->Selectable();
838 IO = *((Handle(AIS_InteractiveObject)*)&SO);
839 }
840 }
841 return IO;
842}
843//==================================================
844// Function:
845// Purpose :
846//==================================================
847Handle(SelectMgr_EntityOwner) AIS_LocalContext::
848SelectedOwner() const
849{
850 Handle(SelectMgr_EntityOwner) EO;
851 Handle(Standard_Transient) Tr = AIS_Selection::CurrentSelection()->Value();
852 if( !Tr.IsNull() )
853 EO = *((Handle(SelectMgr_EntityOwner)*)&Tr);
854 return EO;
855}
856
857//==================================================
858// Function:
859// Purpose :
860//==================================================
861Standard_Boolean AIS_LocalContext::
862HasApplicative() const
863{
864 Handle(AIS_InteractiveObject) IO = SelectedInteractive();
865 if( IO.IsNull() ) return Standard_False;
866 return IO->HasOwner();
867}
868
869//==================================================
870// Function:
871// Purpose :
872//==================================================
873const Handle(Standard_Transient)& AIS_LocalContext::
874SelectedApplicative() const
875{
876 return SelectedInteractive()->GetOwner();
877}
878
879
880
881//=======================================================================
882//function : UpdateSelection
81bba717 883//purpose : should disappear...
7fd59977 884//=======================================================================
885void AIS_LocalContext::UpdateSelected(const Standard_Boolean updateviewer)
886{
887 UnhilightPicked(Standard_False);
888 HilightPicked(updateviewer);
889}
890
891//================================================================
892// Function : UpdateSelected
893// Purpose : Part of advanced selection mechanism.
894// Highlightes or clears selection presentation for the given IO
895//================================================================
896void AIS_LocalContext::UpdateSelected(const Handle(AIS_InteractiveObject)& anobj,
897 const Standard_Boolean updateviewer)
898{
899 if (anobj.IsNull() || anobj->IsAutoHilight())
900 return;
901
902 AIS_Selection::SetCurrentSelection(mySelName.ToCString());
903 Handle(AIS_Selection) Sel = AIS_Selection::CurrentSelection();
904
905 SelectMgr_SequenceOfOwner aSeq;
906 for ( Sel->Init(); Sel->More(); Sel->Next() ){
907 Handle(SelectMgr_EntityOwner) aOwner = Handle(SelectMgr_EntityOwner)::DownCast(Sel->Value());
908
909 if ( !aOwner.IsNull() && aOwner->HasSelectable() && aOwner->Selectable() == anobj )
910 aSeq.Append( aOwner );
911 }
912
913 if ( aSeq.Length() )
914 anobj->HilightSelected( myMainPM, aSeq );
915 else
916 anobj->ClearSelected();
917
918 if(updateviewer){
919 myCTX->CurrentViewer()->Update();
920 }
921}
922
923//==================================================
924// Function: ClearSelected
925// Purpose :
926//==================================================
927void AIS_LocalContext::ClearSelected(const Standard_Boolean updateviewer)
928{
929 UnhilightPicked(updateviewer);
930 AIS_Selection::SetCurrentSelection(mySelName.ToCString());
931
932 Handle(AIS_Selection) Sel = AIS_Selection::CurrentSelection();
933#if !defined OCC189 && !defined USE_MAP
934 const TColStd_Array1OfTransient& Obj = Sel->Objects()->Array1();
935 for(Standard_Integer i =Obj.Lower();i<=Sel->NbStored();i++){
936 const Handle(Standard_Transient)& Tr = Obj(i);
937#else
938 const AIS_NListTransient& Obj = Sel->Objects();
939 AIS_NListTransient::Iterator anIter( Obj );
940 for(; anIter.More(); anIter.Next()){
941 const Handle(Standard_Transient)& Tr = anIter.Value();
942#endif
943 if(!Tr.IsNull()){
944 (*((const Handle(SelectMgr_EntityOwner)*)&Tr))->State(0);
945 }
946 }
947 AIS_Selection::Select();
948 mylastindex = 0;
949}
950
951
952//=======================================================================
953//function : SetSelected
954//purpose :
955//=======================================================================
956void AIS_LocalContext::SetSelected(const Handle(AIS_InteractiveObject)& anIObj,
957 const Standard_Boolean updateviewer)
958{
959 if(!IsValidForSelection(anIObj)) return;
960 UnhilightPicked(Standard_False);
961
81bba717 962 //1st case, owner already <anIObj> as owner
963 // and not separated is found...
7fd59977 964
965 Handle(AIS_Selection) sel = AIS_Selection::Selection(mySelName.ToCString());
966 //Standard_Boolean found(Standard_False);
967 Handle(Standard_Transient) Tr;
968 Handle(SelectMgr_EntityOwner) EO = FindSelectedOwnerFromIO(anIObj);
969 if(EO.IsNull()){
81bba717 970 //check if in selection number 0 there is an owner that can be triturated...
7fd59977 971 if(anIObj->HasSelection(0)){
972 const Handle(SelectMgr_Selection)& SIOBJ = anIObj->Selection(0);
973 SIOBJ->Init();
974 if(SIOBJ->More()){
975 Handle(SelectBasics_EntityOwner) BO = SIOBJ->Sensitive()->OwnerId();
976 EO = *((Handle(SelectMgr_EntityOwner)*)&BO);
977 }
978 }
979 if(EO.IsNull())
980 EO = new SelectMgr_EntityOwner(anIObj);
981 }
982
983 ClearSelected(Standard_False);
984#ifdef OCC138
985 AIS_Selection::Select(EO);
986 EO->State(1);
987#else
988 EO->State(1);
989 AIS_Selection::Select(EO);
990#endif
991 HilightPicked(updateviewer);
992}
993
994//=======================================================================
995//function : AddOrRemoveSelected
996//purpose :
997//=======================================================================
998
999void AIS_LocalContext::AddOrRemoveSelected(const Handle(AIS_InteractiveObject)& anIObj,
1000 const Standard_Boolean updateviewer)
1001{
1002 if(!IsValidForSelection(anIObj)) return;
1003 UnhilightPicked(Standard_False);
81bba717 1004 // first check if it is selected...
7fd59977 1005 Handle(SelectMgr_EntityOwner) EO;
1006
1007 EO = FindSelectedOwnerFromIO(anIObj);
1008#ifndef OCC138
1009 if(!EO.IsNull())
1010 EO->State(0);
1011 else{
1012#else
1013 if(EO.IsNull()) {
1014#endif
1015 if(anIObj->HasSelection(0)){
1016 const Handle(SelectMgr_Selection)& SIOBJ = anIObj->Selection(0);
1017 SIOBJ->Init();
1018 if(SIOBJ->More()){
1019 Handle(SelectBasics_EntityOwner) BO = SIOBJ->Sensitive()->OwnerId();
1020 EO = *((Handle(SelectMgr_EntityOwner)*)&BO);
1021 }
1022 }
1023 if(EO.IsNull())
1024 EO = new SelectMgr_EntityOwner(anIObj);
1025#ifndef OCC138
1026 EO->State(1);
1027#endif
1028 }
1029
1030// cout<<"AIS_LocalContext::AddOrRemoveSelected : Selection = "<<mySelName<<endl;
1031 const Handle(AIS_Selection)& S = AIS_Selection::Selection(mySelName.ToCString());
1032#ifdef OCC138
1033 if(!S.IsNull()) {
1034 AIS_SelectStatus aStatus = S->Select(EO);
1035 if(aStatus == AIS_SS_Added)
1036 EO->State(1);
1037 else
1038 EO->State(0);
1039 }
1040#else
1041 if(!S.IsNull())
1042 S->Select(EO);
1043#endif
1044 HilightPicked(updateviewer);
1045}
1046
1047//=======================================================================
1048//function : AddOrRemoveSelected
81bba717 1049//purpose : To check...
7fd59977 1050//=======================================================================
1051void AIS_LocalContext::AddOrRemoveSelected(const TopoDS_Shape& Sh,
1052 const Standard_Boolean updateviewer)
1053{
1054 UnhilightPicked(Standard_False);
1055 Handle(SelectMgr_EntityOwner) EO = FindSelectedOwnerFromShape(Sh);
1056 if(!EO.IsNull()){
1057// cout<<"AIS_LocalContext::AddOrRemoveSelected(sh) : Selection = "<<mySelName<<endl;
1058
1059#ifdef OCC138
1060 AIS_Selection::Selection(mySelName.ToCString())->Select(EO);
1061 EO->State(1);
1062#else
1063 EO->State(1);
1064 AIS_Selection::Selection(mySelName.ToCString())->Select(EO);
1065#endif
1066 }
1067 HilightPicked(updateviewer);
1068}
1069
1070void AIS_LocalContext::AddOrRemoveSelected(const Handle(SelectMgr_EntityOwner)& Ownr,
1071 const Standard_Boolean updateviewer)
1072{
1073 //Not Yet Implemented
1074 if(myAutoHilight)
1075 UnhilightPicked(Standard_False);
1076// cout<<"AIS_LocalContext::AddOrRemoveSelected(ownr) : Selection = "<<mySelName<<endl;
1077
1078 Standard_Integer mod = Ownr->State()==0 ? 1 : 0;
1079#ifdef OCC138
1080 AIS_Selection::Selection(mySelName.ToCString())->Select(Ownr);
1081
1082 Ownr->State(mod);
1083#else
1084 Ownr->State(mod);
1085
1086 AIS_Selection::Selection(mySelName.ToCString())->Select(Ownr);
1087#endif
1088 if(myAutoHilight)
1089 HilightPicked(updateviewer);
1090}
1091
1092//==================================================
1093// Function:
1094// Purpose :
1095//==================================================
1096void AIS_LocalContext::ManageDetected(const Handle(SelectMgr_EntityOwner)& aPickOwner,
1097 const Handle(V3d_View)& aview)
1098{
1099#ifdef BUC60818
1100 // Warning : aPickOwner may be null !
1101 if (aPickOwner.IsNull()) return;
1102#else
1103 if(!myAutoHilight) return;
1104#endif
1105// const Handle(SelectMgr_SelectableObject)& SO = aPickOwner->Selectable();
1106 Standard_Boolean okStatus = myFilters->IsOk(aPickOwner);
1107 // OK...
1108 if(okStatus){
1109 //=======================================================================================================
81bba717 1110 // 2 cases : a- object is in the map of picks:
1111 // 1. this is the same index as the last detected: -> Do nothing
1112 // 2. otherwise :
1113 // - if lastindex = 0 (no object was detected at the last step)
1114 // the object presentation is highlighted and lastindex = index(objet)
1115 // - othrwise :
1116 // the presentation of the object corresponding to lastindex is "unhighlighted"
1117 // it is removed if the object is not visualized but only active
1118 // then the presentation of the detected object is highlighted and lastindex = index(objet)
1119 // b- the object is not in the map of picked objects
1120 // - if lastindex != 0 (object detected at the last step) it is unhighlighted ...
1121 // if the object was decomposed, presentation is created for the detected shape and the couple
1122 // (Proprietaire,Prs)is added in the map.
1123 // otherwise the couple(proprietaire, NullPrs) is placed in the map and the interactive object
1124 // itself is highlighted.
7fd59977 1125 //
1126 //=======================================================================================================
1127
1128
1129 //szv:
1130 Standard_Boolean wasContained = myMapOfOwner.Contains(aPickOwner);
1131 Standard_Integer theNewIndex = 0;
1132 if (wasContained)
1133 theNewIndex = myMapOfOwner.FindIndex(aPickOwner);
1134 else
1135 theNewIndex = myMapOfOwner.Add(aPickOwner);
1136
1137 // For the advanced mesh selection mode the owner indices comparison
1138 // is not effective because in that case only one owner manage the
1139 // selection in current selection mode. It is necessary to check the current detected
1140 // entity and hilight it only if the detected entity is not the same as
1141 // previous detected (IsForcedHilight call)
1142 if (theNewIndex != mylastindex || aPickOwner->IsForcedHilight()) {
1143
1144 if (mylastindex && mylastindex <= myMapOfOwner.Extent()) {
1145
1146 const Handle(SelectMgr_EntityOwner)& LastOwnr = myMapOfOwner(mylastindex);
1147#ifdef BUC60863
1148 Unhilight(LastOwnr,aview);
1149#else
1150 if(!IsSelected(LastOwnr))
1151 Unhilight(LastOwnr,aview);
1152#endif
1153 }
1154
1155 if (myAutoHilight) {
1156 // wasContained should not be checked because with this verification different
1157 // behaviour of application may occer depending whether mouse is moved above
1158 // owner first or second time
1159 //if (wasContained) {
1160#ifdef BUC60569
1161 if (aPickOwner->State() <= 0 || myCTX->ToHilightSelected())
1162#else
1163 if(!IsSelected (aPickOwner) || myCTX->ToHilightSelected())
1164#endif
1165 Hilight(aPickOwner,aview);
1166 /*}
1167 else Hilight(aPickOwner,aview);*/
1168 }
1169
1170 mylastindex = theNewIndex;
1171 }
1172 }
1173
1174 if (mylastindex) mylastgood = mylastindex;
1175
1176}
1177
1178
1179//=======================================================================
1180//function : HasDetectedShape
1181//purpose :
1182//=======================================================================
1183
1184Standard_Boolean AIS_LocalContext::HasDetectedShape() const
1185{
1186 if(mylastindex==0) return Standard_False;
1187 return IsShape(mylastindex);
1188}
1189
1190//=======================================================================
1191//function : DetectedShape
1192//purpose :
1193//=======================================================================
1194
1195const TopoDS_Shape&
1196AIS_LocalContext::DetectedShape() const
1197{
1198 static TopoDS_Shape bidsh;
1199 if(mylastindex != 0)
1200 {
1201 Handle(StdSelect_BRepOwner) BROwnr = Handle(StdSelect_BRepOwner)::DownCast(myMapOfOwner(mylastindex));
1202 if(BROwnr.IsNull()) return bidsh;
1203 return BROwnr->Shape();
1204 }
1205 return bidsh;
1206}
1207
1208//=======================================================================
1209//function : DetectedInteractive
1210//purpose :
1211//=======================================================================
1212
1213Handle(AIS_InteractiveObject)
1214AIS_LocalContext::DetectedInteractive() const
1215{
1216 Handle(AIS_InteractiveObject) Iobj;
1217 if(IsValidIndex(mylastindex)){
1218 Handle(SelectMgr_SelectableObject) SO = myMapOfOwner.FindKey(mylastindex)->Selectable();
1219 Iobj = *((Handle(AIS_InteractiveObject)*) &SO);
1220 }
1221 return Iobj;
1222}
1223//=======================================================================
1224//function : DetectedInteractive
1225//purpose :
1226//=======================================================================
1227Handle(SelectMgr_EntityOwner) AIS_LocalContext::DetectedOwner() const
1228{
1229 Handle(SelectMgr_EntityOwner) bid;
1230 if(!IsValidIndex(mylastindex)) return bid;
1231 return myMapOfOwner.FindKey(mylastindex);
1232}
1233
1234
1235//=======================================================================
1236//function : ComesFromDecomposition
1237//purpose :
1238//=======================================================================
1239
1240Standard_Boolean AIS_LocalContext::ComesFromDecomposition(const Standard_Integer PickedIndex) const
1241{
1242 const Handle(SelectMgr_EntityOwner)& OWN = myMapOfOwner.FindKey(PickedIndex);
1243 Handle(SelectMgr_SelectableObject) aSel = OWN->Selectable();
81bba717 1244 if (myActiveObjects.IsBound (aSel)) { // debug of jmi
7fd59977 1245 const Handle(AIS_LocalStatus)& Stat = myActiveObjects(aSel);
1246 return Stat->Decomposed();
1247 }
1248 return Standard_False;
1249}
1250
1251
1252//=======================================================================
1253//function : DisplayAreas
1254//purpose :
1255//=======================================================================
1256
1257void AIS_LocalContext::DisplayAreas(const Handle(V3d_View)& aviou)
1258{
1259 myMainVS->DisplayAreas(aviou);
1260}
1261
1262//=======================================================================
1263//function : ClearAreas
1264//purpose :
1265//=======================================================================
1266
1267void AIS_LocalContext::ClearAreas(const Handle(V3d_View)& aviou)
1268{
1269 myMainVS->ClearAreas(aviou);
1270}
1271
1272//=======================================================================
1273//function : DisplaySensitive
1274//purpose :
1275//=======================================================================
1276
1277void AIS_LocalContext::DisplaySensitive(const Handle(V3d_View)& aviou)
1278{
1279 myMainVS->DisplaySensitive(aviou);
1280}
1281
1282//=======================================================================
1283//function : ClearSensitive
1284//purpose :
1285//=======================================================================
1286
1287void AIS_LocalContext::ClearSensitive(const Handle(V3d_View)& aviou)
1288{
1289 myMainVS->ClearSensitive(aviou);
1290}
1291
1292
1293//=======================================================================
1294//function : IsShape
1295//purpose :
1296//=======================================================================
1297Standard_Boolean AIS_LocalContext::IsShape(const Standard_Integer Index) const
1298{
1299
1300 if(Handle(StdSelect_BRepOwner)::DownCast(myMapOfOwner.FindKey(Index)).IsNull())
1301 return Standard_False;
1302 return
1303 ComesFromDecomposition(Index);
1304}
1305
1306Standard_Boolean AIS_LocalContext::IsValidForSelection(const Handle(AIS_InteractiveObject)& anIObj) const
1307{
1308
1309#ifdef IMP120701
1310 // Shape was not transfered from AIS_Shape to EntityOwner
1311 Handle(AIS_Shape) shape = Handle(AIS_Shape)::DownCast(anIObj);
1312 if( !shape.IsNull() )
1313 return myFilters->IsOk(new StdSelect_BRepOwner(shape->Shape(),shape));
1314#endif
1315 return myFilters->IsOk(new SelectMgr_EntityOwner(anIObj));
1316}
1317
1318
1319//=======================================================================
1320//function : HilightNextDetected
1321//purpose :
1322//=======================================================================
1323
1324Standard_Integer AIS_LocalContext::HilightNextDetected(const Handle(V3d_View)& V)
1325{
81bba717 1326 // go to the next owner
7fd59977 1327
1328 if(myDetectedSeq.IsEmpty()) return Standard_False;
1329 Standard_Integer L = myDetectedSeq.Length();
1330 myCurDetected++;
1331
1332 if(myCurDetected>L)
1333 myCurDetected = 1;
1334 Handle(SelectMgr_EntityOwner) EO = myMainVS->Picked(myCurDetected);
1335#ifdef IMP120402
1336 if( EO.IsNull() ) return 0;
1337#endif
1338
1339 static Standard_Boolean Normal_State(Standard_True);
1340 static Standard_Boolean firsttime(Standard_True);
1341 if(firsttime){
1342 OSD_Environment toto("HITRI");
1343 if(!toto.Value().IsEmpty())
1344 Normal_State = Standard_False;
1345 firsttime = Standard_False;
1346 }
1347
1348
1349 if(Normal_State)
1350 ManageDetected(EO,V);
1351 else
1352 HilightTriangle(myCurDetected,V);
1353 return myCurDetected;
1354}
1355
1356//=======================================================================
1357//function : HilightPreviousDetected
1358//purpose :
1359//=======================================================================
1360Standard_Integer AIS_LocalContext::HilightPreviousDetected(const Handle(V3d_View)& V)
1361{
1362 if(myDetectedSeq.IsEmpty()) return Standard_False;
1363
1364 myCurDetected--;
1365
1366 if(myCurDetected<1)
1367 myCurDetected = 1;
1368 Handle(SelectMgr_EntityOwner) EO = myMainVS->Picked(myCurDetected);
1369#ifdef IMP120402
1370 if( EO.IsNull() ) return 0;
1371#endif
1372
1373 static Standard_Boolean Normal_State(Standard_True);
1374 static Standard_Boolean firsttime(Standard_True);
1375 if(firsttime){
1376 OSD_Environment toto("HITRI");
1377 if(!toto.Value().IsEmpty())
1378 Normal_State = Standard_False;
1379 firsttime = Standard_False;
1380 }
1381
1382
1383
1384 if(Normal_State)
1385 ManageDetected(EO,V);
1386 else
1387 HilightTriangle(myCurDetected,V);
1388 return myCurDetected;
1389}
1390
1391//=======================================================================
1392//function : UnhilightLastDetected
1393//purpose :
1394//=======================================================================
1395Standard_Boolean AIS_LocalContext::UnhilightLastDetected(const Handle(V3d_View)& aview)
1396{
1397 if(!IsValidIndex(mylastindex)) return Standard_False;
1398 myMainPM->BeginDraw();
1399 const Handle(SelectMgr_EntityOwner)& Ownr = myMapOfOwner(mylastindex);
1400 Standard_Integer HM(0);
1401 if(Ownr->HasSelectable()){
1402 Handle(SelectMgr_SelectableObject) SO = Ownr->Selectable();
1403 HM = GetHiMod(*((Handle(AIS_InteractiveObject)*)&SO));
1404 }
1405 myMapOfOwner(mylastindex)->Unhilight(myMainPM,HM);
1406 myMainPM->EndDraw(aview);
1407 mylastindex =0;
1408 return Standard_True;
1409}
1410
1411
1412
1413//=======================================================================
1414//function : HilightTriangle
1415//purpose :
1416//=======================================================================
1417
1418void AIS_LocalContext::HilightTriangle(const Standard_Integer Rank,
1419 const Handle(V3d_View)& view)
1420{
1421 static Standard_Integer PrevRank(0);
1422 if(Rank==PrevRank) return;
7fd59977 1423 Handle(SelectBasics_SensitiveEntity) SE = myMainVS->Primitive(Rank);
b8ddfc2f 1424 if(SE->IsKind(STANDARD_TYPE(Select3D_SensitiveTriangulation)))
1425 {
7fd59977 1426 Handle(Select3D_SensitiveTriangulation) Tr = *((Handle(Select3D_SensitiveTriangulation)*)&SE);
1427 gp_Pnt p1,p2,p3 ; Tr->DetectedTriangle(p1,p2,p3);
7fd59977 1428
b8ddfc2f 1429 Handle(Graphic3d_ArrayOfTriangles) aTris = new Graphic3d_ArrayOfTriangles(3);
1430 aTris->AddVertex(p1);
1431 aTris->AddVertex(p2);
1432 aTris->AddVertex(p3);
1433
1434 static Handle(Prs3d_Presentation) TriPrs =
7fd59977 1435 new Prs3d_Presentation(myMainPM->StructureManager());
1436 TriPrs->Clear();
1437#ifdef IMP300101
1438 Handle(Prs3d_ShadingAspect) asp = myCTX->DefaultDrawer()->ShadingAspect();
1439 asp->SetColor(myCTX->HilightColor());
1440 TriPrs->SetShadingAspect(asp);
1441#endif
b8ddfc2f 1442 Prs3d_Root::CurrentGroup(TriPrs)->AddPrimitiveArray(aTris);
7fd59977 1443
1444#ifndef IMP300101
1445 if(view->TransientManagerBeginDraw())
1446 Visual3d_TransientManager::EndDraw();
1447#endif
1448 if(view->TransientManagerBeginDraw()) {
7fd59977 1449 Visual3d_TransientManager::DrawStructure(TriPrs);
1450 Visual3d_TransientManager::EndDraw();
1451 }
7fd59977 1452 }
7fd59977 1453}
1454
1455//=======================================================================
1456//function : FindSelectedOwnerFromIO
81bba717 1457//purpose : it is checked if one of the selected owners really presents IObj
7fd59977 1458//=======================================================================
1459Handle(SelectMgr_EntityOwner) AIS_LocalContext::FindSelectedOwnerFromIO
1460 (const Handle(AIS_InteractiveObject)& anIObj) const
1461{
1462 Handle(SelectMgr_EntityOwner) EO,bid;
1463 if (anIObj.IsNull()) return EO;
1464
1465 Handle(AIS_Selection) Sel = AIS_Selection::Selection(mySelName.ToCString());
1466 if(Sel.IsNull()) {
1467#ifdef DEB
1468 cout<<"\t\tAIS_LocalCOntext::FindSelectedOwnerFromShape : Selection "
1469 <<mySelName<<" Nulle "<<endl;
1470#endif
1471 return EO;
1472 }
1473 Standard_Boolean found(Standard_False);
1474#if !defined OCC189 && !defined USE_MAP
1475 const TColStd_Array1OfTransient& Obj = Sel->Objects()->Array1();
1476 for(Standard_Integer i =Obj.Lower();i<=Sel->NbStored();i++){
1477 const Handle(Standard_Transient)& Tr = Obj(i);
1478#else
1479 const AIS_NListTransient& Obj = Sel->Objects();
1480 AIS_NListTransient::Iterator anIter( Obj );
1481 for(; anIter.More(); anIter.Next()){
1482 const Handle(Standard_Transient)& Tr = anIter.Value();
1483#endif
1484 if(!Tr.IsNull()){
1485 EO = *((Handle(SelectMgr_EntityOwner)*)&Tr);
1486 if(EO->HasSelectable()){
1487 Handle(StdSelect_BRepOwner) BROwnr = Handle(StdSelect_BRepOwner)::DownCast(EO);
1488 if(BROwnr.IsNull() || !BROwnr->ComesFromDecomposition()){
1489 if (anIObj == EO->Selectable()){
1490 found =Standard_True;
1491 break;
1492 }
1493 }
1494 }
1495 }
1496 }
1497 if(found) return EO;
1498 return bid;
1499}
1500
1501//=======================================================================
1502//function : FindSelectedOwnerFromShape
81bba717 1503//purpose : it is checked if one of the selected owners really presents IObj
7fd59977 1504//=======================================================================
1505Handle(SelectMgr_EntityOwner) AIS_LocalContext::FindSelectedOwnerFromShape(const TopoDS_Shape& sh) const
1506{
1507#ifdef OCC9026
1508 Handle(SelectMgr_EntityOwner) EO, bid;
1509#else
1510 Handle(SelectMgr_EntityOwner) EO;
1511#endif
1512 if (sh.IsNull()) return EO;
1513
1514 Handle(AIS_Selection) Sel = AIS_Selection::Selection(mySelName.ToCString());
1515 if(Sel.IsNull()) {
1516#ifdef DEB
1517 cout<<"\t\tAIS_LocalCOntext::FindSelectedOwnerFromShape : Selection "<<mySelName<<" Nulle "<<endl;
1518#endif
1519 return EO;
1520 }
1521
1522 Standard_Boolean found(Standard_False);
1523
1524#ifdef OCC9026
1525 if (!found) {
7fd59977 1526 SelectMgr_DataMapIteratorOfDataMapOfIntegerSensitive aSensitiveIt (myMainVS->Primitives());
1527 for (; aSensitiveIt.More(); aSensitiveIt.Next()) {
1528 EO = Handle(SelectMgr_EntityOwner)::DownCast (aSensitiveIt.Value()->OwnerId());
1529 Handle(StdSelect_BRepOwner) BROwnr = Handle(StdSelect_BRepOwner)::DownCast(EO);
1530 if (!BROwnr.IsNull() && BROwnr->HasShape() && BROwnr->Shape() == sh) {
1531 found = Standard_True;
1532 break;
1533 }
1534 }
1535 }
1536#else
1537#if !defined OCC189 && !defined USE_MAP
1538 const TColStd_Array1OfTransient& Obj = Sel->Objects()->Array1();
1539 for(Standard_Integer i =Obj.Lower();i<=Sel->NbStored();i++){
1540 const Handle(Standard_Transient)& Tr = Obj(i);
1541#else
1542 const AIS_NListTransient& Obj = Sel->Objects();
1543 AIS_NListTransient::Iterator anIter( Obj );
1544 for(; anIter.More(); anIter.Next()){
1545 const Handle(Standard_Transient)& Tr = anIter.Value();
1546#endif
1547 if(!Tr.IsNull()){
1548
1549 EO = *((Handle(SelectMgr_EntityOwner)*)&Tr);
1550 if(EO->HasShape())
1551 if ( EO->Shape() == sh)
1552 found =Standard_True;
1553 break;
1554 }
1555 }
1556#endif
1557
1558 if(found) return EO;
1559 return bid;
1560}
1561
1562#ifdef IMP160701
1563//=======================================================================
1564//function : AIS_LocalContext::InitDetected
1565//purpose :
1566//=======================================================================
1567
1568void AIS_LocalContext::InitDetected()
1569{
1570 myAISCurDetected = myAISDetectedSeq.Length()? 1 : 0;
1571}
1572
1573//=======================================================================
1574//function : AIS_LocalContext::MoreDetected
1575//purpose :
1576//=======================================================================
1577
1578Standard_Boolean AIS_LocalContext::MoreDetected() const
1579{
1580 return (myAISCurDetected > 0 && myAISCurDetected <= myAISDetectedSeq.Length());
1581}
1582
1583
1584//=======================================================================
1585//function : AIS_LocalContext::NextDetected
1586//purpose :
1587//=======================================================================
1588
1589void AIS_LocalContext::NextDetected()
1590{
1591 if (MoreDetected()) myAISCurDetected++;
1592}
1593
1594//=======================================================================
1595//function : DetectedCurrentShape
1596//purpose :
1597//=======================================================================
1598
1599const TopoDS_Shape& AIS_LocalContext::DetectedCurrentShape() const
1600{
1601 static TopoDS_Shape bidsh;
1602 if (MoreDetected())
1603 return Handle(AIS_Shape)::DownCast(myAISDetectedSeq(myAISCurDetected))->Shape();
1604 return bidsh;
1605}
1606
1607//=======================================================================
1608//function : DetectedCurrentObject
1609//purpose :
1610//=======================================================================
1611
1612Handle(AIS_InteractiveObject) AIS_LocalContext::DetectedCurrentObject() const
1613{
1614 Handle(AIS_InteractiveObject) theIObj;
1615 if (MoreDetected())
1616 theIObj = myAISDetectedSeq(myAISCurDetected);
1617
1618 return theIObj;
1619}
1620#endif