0023510: Integration of test grid "vis" into the new testing system
[occt.git] / src / AIS2D / AIS2D_InteractiveContext.cxx
CommitLineData
b311480e 1// Copyright (c) 1999-2012 OPEN CASCADE SAS
2//
3// The content of this file is subject to the Open CASCADE Technology Public
4// License Version 6.5 (the "License"). You may not use the content of this file
5// except in compliance with the License. Please obtain a copy of the License
6// at http://www.opencascade.org and read it completely before using this file.
7//
8// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
9// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
10//
11// The Original Code and all software distributed under the License is
12// distributed on an "AS IS" basis, without warranty of any kind, and the
13// Initial Developer hereby disclaims all such warranties, including without
14// limitation, any warranties of merchantability, fitness for a particular
15// purpose or non-infringement. Please see the License for the specific terms
16// and conditions governing the rights and limitations under the License.
17
7fd59977 18#define IMP140901 //GG 14/09/01 goback to avoid a regression
19// See V2d_Viewer
20
21// SAV 14/11/01 - modification for detection/highlighting/selection elements of
22// SetOf<>. Fully used for SetOfMarkers.
23
24#define OCC197 // jfa 01/03/2002 // for multiple selection of elements
25#define OCC146 // jfa 01/03/2002 // for single selection two times
26#define OCC154 // jfa 06/03/2002 // for correct erasing
27#define OCC389 // vro 19/06/2002 // for Display(obj,dispMode...) setting a view for the IO
28
29#include <Standard_Stream.hxx>
30
31#include <AIS2D_InteractiveContext.ixx>
32#include <Aspect_ColorMap.hxx>
33#include <Aspect_GenericColorMap.hxx>
34#include <Aspect_FontMap.hxx>
35#include <Aspect_MarkMap.hxx>
36#include <Aspect_TypeMap.hxx>
37#include <Aspect_WidthMap.hxx>
38#include <Aspect_FontStyle.hxx>
39#include <Aspect_LineStyle.hxx>
40#include <Aspect_TypeOfMarker.hxx>
41#include <Aspect_TypeOfLine.hxx>
42#include <Aspect_WidthOfLine.hxx>
43#include <Aspect_ColorMapEntry.hxx>
44#include <Aspect_TypeMapEntry.hxx>
45#include <Aspect_WidthMapEntry.hxx>
46#include <Aspect_FontMapEntry.hxx>
47#include <Aspect_MarkMapEntry.hxx>
48#include <gp_GTrsf2d.hxx>
49#include <gp_Trsf2d.hxx>
50
51#include <Graphic2d_Primitive.hxx>
52#include <Graphic2d_SequenceOfPrimitives.hxx>
53
54#include <Graphic2d_View.hxx>
55#include <Graphic2d_DisplayList.hxx>
56#include <V2d_View.hxx>
57#include <Prs2d_Point.hxx>
58#include <Prs2d_Drawer.hxx>
59#include <Prs2d_AspectLine.hxx>
60
61#include <TColStd_ListIteratorOfListOfInteger.hxx>
62#include <TColStd_MapIteratorOfMapOfTransient.hxx>
63#include <TColStd_MapOfTransient.hxx>
64#include <TColStd_HSequenceOfInteger.hxx>
65#include <AIS2D_DataMapIteratorOfDataMapOfLC.hxx>
66#include <AIS2D_DataMapIteratorOfDataMapOfIOStatus.hxx>
67#include <AIS2D_ListIteratorOfListOfIO.hxx>
68#include <AIS2D_PrimitiveArchit.hxx>
69#include <AIS2D_HSequenceOfPrimArchit.hxx>
70#include <AIS2D_GlobalStatus.hxx>
71#include <AIS2D_LocalStatus.hxx>
72#include <AIS2D_LocalContext.hxx>
73#include <AIS2D_ProjShape.hxx>
74
75//SAV
76#include <TColStd_MapOfInteger.hxx>
77#include <TColStd_MapIteratorOfMapOfInteger.hxx>
78
79static TColStd_ListIteratorOfListOfInteger ItL;
80static Standard_Boolean RectMoveTo = Standard_False;
81
82AIS2D_InteractiveContext::AIS2D_InteractiveContext(const Handle(V2d_Viewer)& MainViewer):
83
84 myMainVwr( MainViewer ),
85 myDetectPrecision( 4 ),
86 myResetDetect( Standard_True ),
87 myLastPicked(),
88 myLastinMain(),
89 myLastinColl(),
90 mySeqOfDetIO( new AIS2D_HSequenceOfIO() ),
91 mySeqOfSelIO( new AIS2D_HSequenceOfIO() ),
92 myCurDetectMode( AIS2D_TOD_NONE ),
93 myWasLastMain(),
94 myPickMode( Graphic2d_PM_INCLUDE ),
95 myHighlightColor( Quantity_NOC_CYAN1 ),
96 mySelectionColor( Quantity_NOC_GRAY80 ),
97 mySubIntensity( Quantity_NOC_GRAY40 ),
98 myDisplayMode( 0 ),
99 myLocalContexts( ),
100 myCurLocalIndex( 0 ),
101 myLastMoveView() ,
102 myCurSelected( 0 ),
103 myMaxSelected( 0 )
104{
105
106 myMainVwr->View()->SetDefaultOverrideColor( myMainVwr->InitializeColor( mySelectionColor ) );
107}
108
109AIS2D_InteractiveContext::AIS2D_InteractiveContext(const Handle(V2d_Viewer)& MainViewer,const Handle(V2d_Viewer)& aCollector):
110
111 myMainVwr( MainViewer ),
112
113 myCollectorVwr( aCollector ),
114 myIsCollClosed( Standard_False ),
115 myDetectPrecision( 4 ),
116 myResetDetect( Standard_True ),
117 myLastPicked(),
118 myLastinMain(),
119 myLastinColl(),
120 mySeqOfDetIO( new AIS2D_HSequenceOfIO() ),
121 mySeqOfSelIO( new AIS2D_HSequenceOfIO() ),
122 myCurDetectMode( AIS2D_TOD_NONE ),
123 myWasLastMain(),
124 myPickMode( Graphic2d_PM_INCLUDE ),
125 myHighlightColor( Quantity_NOC_CYAN1 ),
126 mySelectionColor( Quantity_NOC_GRAY80 ),
127 mySubIntensity( Quantity_NOC_GRAY40 ),
128 myDisplayMode( 0 ),
129 myLocalContexts( ),
130 myCurLocalIndex( 0 ),
131 myLastMoveView()
132{
133 myMainVwr->View()->SetDefaultOverrideColor( myMainVwr->InitializeColor( mySelectionColor ) );
134 myCollectorVwr->View()->SetDefaultOverrideColor( myMainVwr->InitializeColor( mySelectionColor ) );
135}
136
137
138 //*************************************************************
139 // Management of the Trash Bin Viewer
140 // *************************************************************
141
142 void AIS2D_InteractiveContext::OpenCollector() {
143 myIsCollClosed = Standard_False;
144 }
145
146
147 // *************************************************************
148 // Editing general Display Services
149 // *************************************************************
150
151void AIS2D_InteractiveContext::Display( const Handle(AIS2D_InteractiveObject)& anIObj,
152 const Standard_Boolean UpdateVwr ) {
153
154 if ( anIObj.IsNull() ) return;
155
156 Standard_Integer DispMode, SelMode;
157 AIS2D_TypeOfDetection HiMod;
158 Standard_Boolean UpdateCol;
159 Handle( AIS2D_GlobalStatus ) GStatus;
160
161 GetDefModes( anIObj, DispMode, HiMod, SelMode );
162
163 if ( !anIObj->HasInteractiveContext() )
164 anIObj->SetContext( this );
165
166 anIObj->SetView( myMainVwr->View() );
167
168 if ( !HasOpenedContext() ) {
169
170 if ( IsDisplayed( anIObj ) ) return;
171 UpdateCol = Standard_False;
172
173 if ( !myObjects.IsBound( anIObj ) ) {
174
175 GStatus = new AIS2D_GlobalStatus( AIS2D_DS_Displayed, DispMode, 0);
176 myObjects.Bind( anIObj, GStatus );
177 DrawObject( anIObj, DispMode ) ;
178
179 } else {
180
181 GStatus = myObjects( anIObj );
182 switch ( GStatus->GraphicStatus() ) {
183
184 case AIS2D_DS_Erased: {
185
186 if ( GStatus->IsHighlight() )
187 UpdateCol = UpdateVwr ;
188 }
189 case AIS2D_DS_FullErased: {
190
191 for ( ItL.Initialize( * GStatus -> DisplayedModes()); ItL.More(); ItL.Next())
192 if ( GStatus->IsSubIntensityOn() ) {
193 // Standard_Integer indCol = myMainVwr->InitializeColor(mySubIntensity);
194 // myMainPM->SetHighlightColor(indCol);
195 // myMainPM->ColorHighlight( anIObj, indCol, ItL.Value() );
196 }
197
198 for ( ItL.Initialize( * GStatus -> SelectionModes() ); ItL.More();ItL.Next() )
199 // mySelectorMgr->Activate( anIObj, ItL.Value(), myMainSelector );
200 GStatus->SetGraphicStatus( AIS2D_DS_Displayed );
201 if ( GStatus->IsHighlight() )
202 Highlight( anIObj, HiMod );
203 break;
204 }
205 default:
206 break;
207 } // end switch
208 } //endif !myObjects.IsBound
209
210 anIObj->Display();
211
212 if ( UpdateCol && !myCollectorVwr.IsNull() ) myCollectorVwr->UpdateNew();
213
214 } else {
215
216 myLocalContexts( myCurLocalIndex )->Display( anIObj, DispMode, Standard_True,SelMode );
217
218 }//endif !HasOpenedContext
219
220 if ( UpdateVwr ) myMainVwr->UpdateNew();
221
222}
223
224void AIS2D_InteractiveContext::Display(
225 const Handle(AIS2D_InteractiveObject)& anIObj,
226 const Standard_Integer aDispMode,
227 const Standard_Integer aSelectMode,
228 const Standard_Boolean UpdateVwr,
229 const Standard_Boolean AllowDecomp) {
230
231 if ( anIObj.IsNull() ) return;
232 if ( !anIObj->HasInteractiveContext() ) anIObj->SetContext(this);
233
234#ifdef OCC389
235 anIObj->SetView(myMainVwr->View());
236#endif
237
238 if ( !HasOpenedContext() ) {
239
240 if ( !anIObj->HasDisplayMode() )
241 anIObj->SetDisplayMode(aDispMode);
242
243 if ( !myObjects.IsBound(anIObj) ) {
244 Handle(AIS2D_GlobalStatus) GStatus=
245 new AIS2D_GlobalStatus( AIS2D_DS_Displayed, aDispMode, aSelectMode );
246 myObjects.Bind( anIObj, GStatus );
247 DrawObject( anIObj, aDispMode );
248
249 if ( aSelectMode != -1 ) {
250 //if ( !mySelectorMgr->Contains( anIObj ) )
251 // mySelectorMgr->Load( anIObj, myMainSelector,aSelectMode );
252 //mySelectorMgr->Activate( anIObj, aSelectMode, myMainSelector );
253 }
254
255 anIObj->SetSelectionMode(aSelectMode);
256
257 } else {
258
259 Handle(AIS2D_GlobalStatus) GStatus = myObjects( anIObj );
260 if ( !GStatus->IsDModeIn( aDispMode ) ) {
261 DrawObject( anIObj, aDispMode );
262 GStatus->AddDisplayMode( aDispMode );
263 if ( GStatus->IsSubIntensityOn() ) {
264#ifdef DEB
265 Standard_Integer indCol = myMainVwr->InitializeColor(mySubIntensity);
266 //myMainPM->SetHighlightColor( indCol );
267 //myMainPM->ColorHighlight( anIObj, indCol, aDispMode );
268#endif
269 }
270 }
271 if ( aSelectMode != -1 ) {
272 GStatus->AddSelectionMode( aSelectMode );
273 //mySelectorMgr->Activate( anIObj, aSelectMode, myMainSelector );
274 }
275
276 }
277 anIObj->Display();
278 } else
279
280 myLocalContexts(myCurLocalIndex)->Display( anIObj, aDispMode, AllowDecomp, aSelectMode);
281
282 if (UpdateVwr) myMainVwr->Update();
283
284}
285
286void AIS2D_InteractiveContext::Redisplay( const Handle(AIS2D_InteractiveObject)& anIObj,
287 const Standard_Boolean updateVwr,
288 const Standard_Boolean /*allModes*/ ) {
289
290 if ( anIObj.IsNull() ) return;
291 //anIObj->Update(allModes);
292
293 if ( updateVwr ) {
294 if ( HasOpenedContext() )
295 myMainVwr->Update();
296 else {
297 if ( myObjects.IsBound( anIObj ) ) {
298 switch ( myObjects(anIObj)->GraphicStatus() ) {
299 case AIS2D_DS_Displayed:
300 DrawObject( anIObj, 0 );
301 myMainVwr->Update();
302 break;
303 case AIS2D_DS_Erased:
304 if ( !myCollectorVwr.IsNull() )
305 myCollectorVwr->Update();
306 default:
307 break;
308 }
309 }
310 }
311 }
312
313}
314
315void AIS2D_InteractiveContext::Load(
316 const Handle(AIS2D_InteractiveObject)& anIObj,
317 const Standard_Integer SelMode,
318 const Standard_Boolean AllowDecomp) {
319
320 if ( anIObj.IsNull() ) return;
321 if ( !anIObj->HasInteractiveContext() ) anIObj->SetContext( this );
322
323 if ( !HasOpenedContext() ) {
324 if ( SelMode == -1 && !AllowDecomp ) {
325 Standard_Integer DispMode;
326 AIS2D_TypeOfDetection HiMod;
327 Standard_Integer selMode = SelMode;
328
329 GetDefModes( anIObj, DispMode, HiMod, selMode );
330 Handle(AIS2D_GlobalStatus) GStatus=
331 new AIS2D_GlobalStatus( AIS2D_DS_FullErased, DispMode, selMode );
332 myObjects.Bind( anIObj,GStatus );
333 return;
334 }
335 }
336 //endif !HasOpenedContext
337 myLocalContexts(myCurLocalIndex)->Load( anIObj, AllowDecomp, SelMode);
338}
339
340void AIS2D_InteractiveContext::Erase(
341 const Handle(AIS2D_InteractiveObject)& anIObj,
342 const Standard_Boolean UpdateVwr,
343 const Standard_Boolean /*PutInCollector*/) {
344
345 if ( anIObj.IsNull() ) return;
346
347 if ( !HasOpenedContext() )
348#ifdef OCC154
349 {
350 anIObj->Erase();
351 if (myObjects.IsBound(anIObj))
352 myObjects(anIObj)->SetGraphicStatus(AIS2D_DS_Erased);
353 }
354#else
355 anIObj->Remove();
356#endif
357 if ( UpdateVwr ) myMainVwr->UpdateNew();
358
359}
360
7fd59977 361void AIS2D_InteractiveContext::EraseAll (const Standard_Boolean /*PutInCollector*/,
362 const Standard_Boolean UpdateVwr)
363{
364 if ( !HasOpenedContext() )
365#ifdef OCC154
366 {
367 myMainVwr->View()->Erase();
368 AIS2D_DataMapIteratorOfDataMapOfIOStatus anItr (myObjects);
369 for (; anItr.More(); anItr.Next())
370 {
371 anItr.Value()->SetGraphicStatus(AIS2D_DS_Erased);
372 }
373 }
374#else
375 myMainVwr->View()->Remove();
376#endif
377 if ( UpdateVwr ) myMainVwr->Update();
378}
379
380void AIS2D_InteractiveContext::DisplayAll (const Standard_Boolean /*OnlyFromCollector*/,
381 const Standard_Boolean /*updateVwr*/) {
382
383}
384
385void AIS2D_InteractiveContext::EraseSelected (const Standard_Boolean PutInCollector,
386 const Standard_Boolean UpdateVwr) {
387 if ( !HasOpenedContext() ) {
388 Standard_Boolean found = Standard_False;
389 if ( mySeqOfSelIO->IsEmpty() ) return;
390 for ( int i = 1; i <= mySeqOfSelIO->Length(); ++i )
391 Erase( mySeqOfSelIO->Value(i), Standard_False, PutInCollector );
392 found = Standard_True;
393 if ( found && UpdateVwr ) {
394 myMainVwr->Update();
395 if ( PutInCollector && !myCollectorVwr.IsNull() )
396 myCollectorVwr->Update();
397 }
398 }
399
400}
401
402void AIS2D_InteractiveContext::DisplaySelected( const Standard_Boolean updateVwr ) {
403
404 if ( !HasOpenedContext() ) {
405 Standard_Boolean found = Standard_False;
406 if ( mySeqOfSelIO->IsEmpty() ) return;
407 for ( int i = 1; i <= mySeqOfSelIO->Length(); ++i ) {
408 Display( mySeqOfSelIO->Value(i), Standard_False );
409 found = Standard_True;
410 }
411 if ( found && updateVwr ) {
412 myMainVwr->Update();
413 if ( !(myIsCollClosed && myCollectorVwr.IsNull()) )
414 myCollectorVwr->Update();
415 }
416 }
417
418}
419
420Standard_Boolean AIS2D_InteractiveContext::KeepTemporary( const Handle(AIS2D_InteractiveObject)& anIObj,
421 const Standard_Integer WhichContext ) {
422
423 if ( anIObj.IsNull() ) return Standard_False;
424
425 if ( !HasOpenedContext() ) return Standard_False;
426 if ( myObjects.IsBound(anIObj) ) return Standard_False;
427 if ( WhichContext != -1 && !myLocalContexts.IsBound(WhichContext) ) return Standard_False;
428
429 Standard_Integer IsItInLocal = myCurLocalIndex;
430 Standard_Boolean Found( Standard_False );
431
432 while ( IsItInLocal > 0 && !Found ) {
433 if ( !myLocalContexts.IsBound( IsItInLocal ) )
434 IsItInLocal--;
435 else if ( myLocalContexts(IsItInLocal)->IsIn( anIObj ) )
436 Found = Standard_True;
437 else
438 IsItInLocal--;
439 }
440
441 if ( !Found ) return Standard_False;
442
443 Handle(AIS2D_LocalStatus) LS = myLocalContexts(IsItInLocal)->Status(anIObj);
444
445
446 if ( LS->IsTemporary() ){
447 Standard_Integer DM,SM;
448 AIS2D_TypeOfDetection HM;
449 GetDefModes( anIObj, DM, HM, SM );
450
451 SM = LS->SelectionModes()->IsEmpty() ? SM : LS->SelectionModes()->First();
452 if (LS->DisplayMode() != DM ) {
453 Standard_Integer LSM = LS->SelectionModes()->IsEmpty() ? -1 : LS->SelectionModes()->First();
454 myLocalContexts(IsItInLocal)->Display(anIObj,DM,LS->Decomposed(),LSM);
455 }
456
457 Handle(AIS2D_GlobalStatus) GS = new AIS2D_GlobalStatus( AIS2D_DS_Displayed,
458 DM, SM, Standard_False);
459 myObjects.Bind( anIObj, GS );
460
461 LS->SetTemporary(Standard_False);
462 }
463 return Standard_True;
464}
465
466Standard_Boolean AIS2D_InteractiveContext::IsSelected(const Handle(AIS2D_InteractiveObject)& anIObj) const {
467
468 if ( anIObj.IsNull() ) return Standard_False;
469 if ( !HasOpenedContext() )
470 return ( anIObj->State() == 1 );
471 else
472 return myLocalContexts(myCurLocalIndex)->IsSelected(anIObj);
473}
474
475Standard_Boolean AIS2D_InteractiveContext::IsCurrent(const Handle(AIS2D_InteractiveObject)& anIObj) const {
476
477 if ( anIObj.IsNull() ) return Standard_False;
478 return ( anIObj->State() );
479}
480
481Standard_Integer AIS2D_InteractiveContext::OpenLocalContext( const Standard_Boolean UseDispObj,
482 const Standard_Boolean AllowDecomposit,
483 const Standard_Boolean AcceptEraseOfObj ) {
484 if ( !IsCurrent( myLastPicked ) )
485 if ( !myLastPicked.IsNull() ) {
7fd59977 486 myLastPicked->Unhighlight();
487 }
488
489 if ( !myLastMoveView.IsNull() )
490 if ( myCurLocalIndex > 0 )
491 myLocalContexts( myCurLocalIndex )->UnhighLastDetect( myLastMoveView );
492
493 myLastinMain.Nullify();
494 myLastinColl.Nullify();
495 myLastPicked.Nullify();
496 myWasLastMain = Standard_True;
497
498// Standard_Integer untilNow = myCurLocalIndex;
499
500 myCurLocalIndex = HighestIndex() + 1;
501
502 Handle(AIS2D_LocalContext) NewLocal= new AIS2D_LocalContext(this,
503 myCurLocalIndex,
504 UseDispObj,
505 AllowDecomposit,
506 AcceptEraseOfObj );
507
508 myLocalContexts.Bind( myCurLocalIndex, NewLocal );
509
510 if ( UseDispObj ) {
511 if ( AllowDecomposit )
512 cout<<"\t\tDecomposition Authorized for Loaded Shapes"<<endl;
513 else
514 cout<<"\t\tNo Decomposition Authorized for Loaded Shapes"<<endl;
515 } else
516 cout<<"\t\tNo Objects Were Loaded "<<endl;
517
518 return myCurLocalIndex;
519
520}
521
522void AIS2D_InteractiveContext::CloseLocalContext( const Standard_Integer ind,
523 const Standard_Boolean updateVwr ) {
524
525 Standard_Integer GoodIndex = ( ind == -1 ) ? myCurLocalIndex : ind;
526 if ( !HasOpenedContext() ) return;
527 if ( !myLocalContexts.IsBound(GoodIndex) ) return;
528
529 if ( myLocalContexts.Extent() == 1 && GoodIndex == myCurLocalIndex ) {
530
531 myLocalContexts(myCurLocalIndex)->Terminate();
532 myLocalContexts.UnBind(myCurLocalIndex);
533 myCurLocalIndex = 0;
534
535 ResetOriginalState(Standard_False);
536
537 } else {
538
539 myLocalContexts(GoodIndex)->Terminate();
540 myLocalContexts.UnBind(GoodIndex);
541
542 if ( GoodIndex == myCurLocalIndex ) {
543 myCurLocalIndex = HighestIndex();
7fd59977 544 }
545
546 }
547
548 if ( updateVwr ) myMainVwr->Update();
549
550}
551
552Standard_Integer AIS2D_InteractiveContext::IndexOfCurrentLocal() const {
553 return myCurLocalIndex;
554}
555
556void AIS2D_InteractiveContext::CloseAllContext( const Standard_Boolean /*updateVwr*/ ) {
557
558
559
560}
561
562void AIS2D_InteractiveContext::SetCurrentObject( const Handle(AIS2D_InteractiveObject)& anIObj,
563 const Standard_Boolean UpdateVwr ) {
564
565 if ( anIObj.IsNull() ) return;
566
567 /*if ( NbCurrents() == 1 && anIObj->State() == 1 ) {
568 Quantity_NameOfColor HiCol;
569 Standard_Boolean HasHiCol;
570 if ( IsHighlighted( anIObj, HasHiCol, HiCol ) )
571 if ( HasHiCol && HiCol != mySelectionColor )
572 Highlight( anIObj, UpdateVwr );
573 return;
574 }
575 */
576 if ( !HasOpenedContext() ) {
577 if ( !myObjects.IsBound(anIObj) )
578 HighlightWithColor( anIObj, mySelectionColor, Standard_False );
579
580 anIObj->SetState(1);
581 Quantity_NameOfColor HiCol;
582 Standard_Boolean HasHiCol;
583 if ( IsHighlighted( anIObj, HasHiCol, HiCol ) ) {
584 if ( HasHiCol && HiCol != mySelectionColor )
585 Highlight( anIObj,UpdateVwr );
586 } else {
587 Highlight( anIObj, UpdateVwr );
588 }
589 //if (UpdateVwr)
590 // UpdateCurrentViewer();
591 }
592
593}
594
595void AIS2D_InteractiveContext::AddOrRemoveCurObject( const Handle(AIS2D_InteractiveObject)& anIObj,
596 const Standard_Boolean UpdateVwr ) {
597
598
599 if ( !HasOpenedContext() ) {
600 if ( anIObj.IsNull() ) return;
601
602 switch ( anIObj->HighlightMode() ) {
603 default:
604 case AIS2D_TOD_OBJECT: {
605 if ( IsIOSelected( anIObj ) ) {
606 Unhighlight( anIObj, Standard_False );
607 anIObj->SetState( 0 );
608 for ( int i = 1; i <= mySeqOfSelIO->Length(); ++i )
609 if ( mySeqOfSelIO->Value(i) == anIObj ) {
610 mySeqOfSelIO->Remove(i);
611 break;
612 }
613 } else {
614 anIObj->SetState( 1 );
615 Highlight( anIObj, Standard_False );
616 mySeqOfSelIO->Append(anIObj);
617 }
618 }
619 break;
620 case AIS2D_TOD_PRIMITIVE: {
621 Standard_Boolean found = Standard_False;
622 Handle(AIS2D_HSequenceOfPrimArchit) thePA;
623 Handle(Graphic2d_Primitive) thePrim = anIObj->Primitive(anIObj->PickedIndex());
624 thePA = anIObj->GetSelectedSeqPrim();
625 for ( int i = 1; i <= thePA->Length(); ++i )
626 if ( thePA->Value(i)->GetPrimitive() == thePrim ) {
627 //thePrim->Unhighlight();
628 Unhighlight( anIObj, Standard_False );
629 thePA->Remove(i);
630 found = Standard_True;
631 break;
632 }
633 if ( !found ) {
634 Highlight( anIObj, Standard_False );
635 thePrim->Highlight();
636 anIObj->AddSelectPrim( thePrim, 0 );
637 if ( ! IsIOSelected( anIObj ) ) {
638 mySeqOfSelIO->Append(anIObj);
639 anIObj->SetState( 1 );
640 }
641 }
642 }
643 break;
644 case AIS2D_TOD_ELEMENT:{
645 Standard_Boolean found = Standard_False;
646 Handle(AIS2D_HSequenceOfPrimArchit) thePA;
647 Handle(Graphic2d_Primitive) thePrim = anIObj->Primitive(anIObj->PickedIndex());
648 Standard_Integer ind = thePrim->PickedIndex();
649 thePA = anIObj->GetSelectedSeqPrim();
650 for ( int i = 1; i <= thePA->Length(); ++i )
651 if ( thePA->Value(i)->GetPrimitive() == thePrim &&
652 thePA->Value(i)->GetIndex() == ind ) {
653#ifdef OCC197
654 // unhighlight the element
655 // thePrim->Unhighlight(ind);
656 Handle(TColStd_HSequenceOfInteger) aHiInds = thePrim->HighlightIndices();
657 for (int k = 1; k <= aHiInds->Length(); k++)
658 {
659 if (aHiInds->Value(k) == ind)
660 {
661 aHiInds->Remove(k);
662 break;
663 }
664 }
665 // unhighlight entire object only if we remove last selected element of it
666 if (thePA->Length() == 1)
667#endif
668 Unhighlight( anIObj, Standard_False );
669 thePA->Remove(i);
670 found = Standard_True;
671 break;
672 }
673 if ( !found ) {
674 Highlight( anIObj, Standard_False );
675 thePrim->Highlight( ind );
676 anIObj->AddSelectPrim( thePrim, ind );
677 if ( ! IsIOSelected( anIObj ) ) {
678 mySeqOfSelIO->Append(anIObj);
679 anIObj->SetState( 1 );
680 }
681 }
682 }
683 break;
684 case AIS2D_TOD_VERTEX: {
685 Standard_Boolean found = Standard_False;
686 Handle(AIS2D_HSequenceOfPrimArchit) thePA;
687 Handle(Graphic2d_Primitive) thePrim = anIObj->Primitive(anIObj->PickedIndex());
688 Standard_Integer ind = thePrim->PickedIndex();
689 thePA = anIObj->GetSelectedSeqPrim();
690 for ( int i = 1; i <= thePA->Length(); ++i )
691 if ( thePA->Value(i)->GetPrimitive() == thePrim &&
692 thePA->Value(i)->GetIndex() == ind ) {
693#ifdef OCC197
694 // unhighlight the vertex
695 // thePrim->Unhighlight(ind);
696 Handle(TColStd_HSequenceOfInteger) aHiInds = thePrim->HighlightIndices();
697 for (int k = 1; k <= aHiInds->Length(); k++)
698 {
699 if (aHiInds->Value(k) == ind)
700 {
701 aHiInds->Remove(k);
702 break;
703 }
704 }
705 // unhighlight entire object only if we remove last selected vertex of it
706 if (thePA->Length() == 1)
707#endif
708 Unhighlight( anIObj, Standard_False );
709 thePA->Remove(i);
710 found = Standard_True;
711 break;
712 }
713 if ( !found ) {
714 Highlight( anIObj, Standard_False );
715 thePrim->Highlight( ind );
716 anIObj->AddSelectPrim( thePrim, ind );
717 if ( ! IsIOSelected( anIObj ) ) {
718 mySeqOfSelIO->Append(anIObj);
719 anIObj->SetState( 1 );
720 }
721 }
722 }
723 break;
724
725 } // end switch
726
727#ifdef OCC197
728 if ( UpdateVwr ) myWasLastMain ? myMainVwr->Update() : UpdateCollector();
729#else
730 if ( UpdateVwr ) UpdateCurrentViewer();
731#endif
732 } else {
733
734// cout<<"Nothing Done : Opened Local Context"<<endl;
735 }
736
737}
738
739void AIS2D_InteractiveContext::UpdateCurrent() {
740
741
742}
743
744void AIS2D_InteractiveContext::SetOkCurrent() {
745
746}
747
748/*Handle(AIS2D_InteractiveObject) AIS2D_InteractiveContext::FirstCurrentObject() {
749 Handle(AIS2D_InteractiveObject) IO ;
750 InitCurrent();
751 if ( MoreCurrent() )
752 return Current();
753 return IO;
754}
755*/
756void AIS2D_InteractiveContext::HighlightCurrent(const Standard_Boolean UpdateVwr) {
757 if ( mySeqOfSelIO->IsEmpty() ) return;
758 Handle(AIS2D_InteractiveObject) IO;
759 AIS2D_TypeOfDetection theTOD;
760 for ( int i = 1; i <= mySeqOfSelIO->Length(); ++i ) {
761 IO = mySeqOfSelIO->Value(i);
762 theTOD = IO->HighlightMode();
763 if ( theTOD == AIS2D_TOD_OBJECT )
764 Highlight(IO,Standard_False);
765 else if ( theTOD == AIS2D_TOD_PRIMITIVE ||
766 theTOD == AIS2D_TOD_ELEMENT ||
767 theTOD == AIS2D_TOD_VERTEX ) {
768 Standard_Integer pLength = IO->PickList()->Length();
769 if ( pLength ) {
770 IO->Highlight(myMainVwr->InitializeColor( mySelectionColor ));
771 IO->Unhighlight();
772 for ( int j = 1; j <= pLength; j++ )
773 IO->Primitive(IO->PickList()->Value(j))->Highlight();
774 }
775 }
776 } // end for
777 if ( UpdateVwr )
778 UpdateCurrentViewer();
779
780}
781
782void AIS2D_InteractiveContext::UnhighlightCurrent(const Standard_Boolean UpdateVwr) {
783 if ( mySeqOfSelIO->IsEmpty() ) return;
784 for ( int i = 1; i <= mySeqOfSelIO->Length(); ++i ) {
785 Unhighlight( mySeqOfSelIO->Value(i), Standard_False );
786 mySeqOfSelIO->Value(i)->SetState(0);
787 }
788 if ( UpdateVwr )
789 UpdateCurrentViewer();
790}
791
792
793void AIS2D_InteractiveContext::ClearCurrent(const Standard_Boolean UpdateVwr) {
794 if ( mySeqOfSelIO->IsEmpty() ) return;
795 for ( int i = 1; i <= mySeqOfSelIO->Length(); ++i )
796 Unhighlight( mySeqOfSelIO->Value(i), Standard_False );
797
798 if ( UpdateVwr )
799 UpdateCurrentViewer();
800}
801
802void AIS2D_InteractiveContext::SetSelectedCurrent() {
803
804}
805
806// SAV - just appending object
807void AIS2D_InteractiveContext::SetSelected( const Handle(AIS2D_InteractiveObject)& obj,
808 const Standard_Boolean update )
809{
810 mySeqOfSelIO->Append( obj );
811 for( Standard_Integer i = 1; i <= obj->Length(); i++ )
812 obj->AddSelectPrim( obj->Primitive( i ), i );
813}
814
815void AIS2D_InteractiveContext::UpdateSelected( const Standard_Boolean UpdateVwr ) {
816
817 if ( !HasOpenedContext() ) {
818 HighlightSelected();
819 }
820 myLocalContexts(myCurLocalIndex)->UpdateSelected( UpdateVwr );
821}
822
823void AIS2D_InteractiveContext::AddOrRemoveSelected(
824 const Handle(AIS2D_InteractiveObject)& anIObj,
825 const Standard_Boolean UpdateVwr ) {
826
827 if ( !anIObj->HasInteractiveContext() ) anIObj->SetContext(this);
828 if ( ! HasOpenedContext() )
829 AddOrRemoveCurObject( anIObj, UpdateVwr );
830 else
831 myLocalContexts(myCurLocalIndex)->AddOrRemoveSelected( anIObj, UpdateVwr);
832
833}
834
835void AIS2D_InteractiveContext::HighlightSelected( const Standard_Boolean UpdateVwr ) {
836
837 if ( !HasOpenedContext() ) {
838 if ( ! mySeqOfSelIO->IsEmpty() )
839 for ( int i = 1; i <= mySeqOfSelIO->Length(); ++i )
840 Highlight( mySeqOfSelIO->Value(i), Standard_False );
841 } else {
842 myLocalContexts(myCurLocalIndex)->UnhighlightPicked( UpdateVwr );
843 }
844 if( UpdateVwr )
845 UpdateCurrentViewer();
846}
847
848void AIS2D_InteractiveContext::UnhighlightSelected( const Standard_Boolean UpdateVwr ) {
849 if ( !HasOpenedContext() ) {
850 if ( ! mySeqOfSelIO->IsEmpty() )
851 for ( int i = 1; i <= mySeqOfSelIO->Length(); ++i )
852 Unhighlight( mySeqOfSelIO->Value(i), Standard_False );
853 } else {
854 myLocalContexts(myCurLocalIndex)->UnhighlightPicked( UpdateVwr );
855 }
856 if( UpdateVwr )
857 UpdateCurrentViewer();
858}
859
860void AIS2D_InteractiveContext::ClearSelected( const Standard_Boolean UpdateVwr ) {
861 if ( !HasOpenedContext() )
862 ClearCurrent( UpdateVwr );
863 else
864 myLocalContexts(myCurLocalIndex)->ClearSelected( UpdateVwr );
865}
866
867AIS2D_DisplayStatus AIS2D_InteractiveContext::DisplayStatus( const Handle(AIS2D_InteractiveObject)& anIObj ) const {
868
869 if ( anIObj.IsNull() ) return AIS2D_DS_None;
870
871 if ( myObjects.IsBound(anIObj))
872 return myObjects(anIObj)->GraphicStatus();
873
874 AIS2D_DataMapIteratorOfDataMapOfLC ItM(myLocalContexts);
875 for ( ; ItM.More(); ItM.Next() )
876 if ( ItM.Value()->IsIn(anIObj) )
877 return AIS2D_DS_Temporary;
878
879 return AIS2D_DS_None;
880
881}
882
883AIS2D_PToListOfInt AIS2D_InteractiveContext::DisplayedModes( const Handle(AIS2D_InteractiveObject)& anIObj ) const {
884 return myObjects(anIObj)->DisplayedModes();
885}
886
887Standard_Boolean AIS2D_InteractiveContext::IsDisplayed( const Handle(AIS2D_InteractiveObject)& anIObj ) const {
888
889 if ( anIObj.IsNull() ) return Standard_False;
890
891 if ( myObjects.IsBound(anIObj) )
892 if ( myObjects(anIObj)->GraphicStatus() == AIS2D_DS_Displayed )
893 return Standard_True;
894
895 AIS2D_DataMapIteratorOfDataMapOfLC ItM(myLocalContexts);
896 for ( ; ItM.More(); ItM.Next() )
897 if ( ItM.Value()->IsDisplayed(anIObj) ) return Standard_True;
898
899 return Standard_False;
900
901}
902
903Standard_Boolean AIS2D_InteractiveContext::IsDisplayed( const Handle(AIS2D_InteractiveObject)& /*anIObj*/,
904 const Standard_Integer /*aMode*/ ) const {
905
906 return Standard_False;
907
908}
909
910Standard_Boolean AIS2D_InteractiveContext::IsHighlighted( const Handle(AIS2D_InteractiveObject)& anIObj ) const {
911
912 if ( anIObj.IsNull() ) return Standard_False;
913
914 if (!HasOpenedContext()){
915#ifdef OCC146
916 if (!anIObj->IsHighlighted()) return Standard_False;
917#endif
918 if(!myObjects.IsBound(anIObj))
919 return Standard_False;
920 return myObjects(anIObj)->IsHighlight();
921 }
922 AIS2D_DataMapIteratorOfDataMapOfLC ItM(myLocalContexts);
923 for (;ItM.More();ItM.Next() ) {
924 if (ItM.Value()->IsHighlight(anIObj) )
925 return Standard_True;
926 }
927 return Standard_False;
928
929
930}
931
932Standard_Boolean AIS2D_InteractiveContext::IsHighlighted( const Handle(AIS2D_InteractiveObject)& anIObj,
933 Standard_Boolean& /*WithColor*/,
934 Quantity_NameOfColor& /*theHiCol*/ ) const {
935 if ( anIObj.IsNull() ) return Standard_False;
936
937 if ( !HasOpenedContext() ) {
938#ifdef OCC146
939 if (!anIObj->IsHighlighted()) return Standard_False;
940#endif
941 if ( !myObjects.IsBound(anIObj) )
942 return Standard_False;
943 return myObjects(anIObj)->IsHighlight();
944 }
945 AIS2D_DataMapIteratorOfDataMapOfLC ItM(myLocalContexts);
946 for ( ; ItM.More(); ItM.Next() )
947 if ( ItM.Value()->IsHighlight(anIObj) )
948 return Standard_True;
949
950 return Standard_False;
951
952}
953
954void AIS2D_InteractiveContext::SubIntensityOn(
955 const Handle(AIS2D_InteractiveObject)& anIObj,
956 const Standard_Boolean UpdateVwr) {
957
958 Standard_Integer indCol;
959 if ( !HasOpenedContext() ) {
960 if ( !myObjects.IsBound(anIObj) ) return;
961 const Handle(AIS2D_GlobalStatus) GStatus = myObjects(anIObj);
962 if ( GStatus->IsSubIntensityOn() ) return;
963 GStatus->SubIntensityOn();
964 Standard_Boolean UpdMain(Standard_False),UpdColl(Standard_False);
965
966 for (TColStd_ListIteratorOfListOfInteger It( * GStatus->DisplayedModes() ); It.More(); It.Next() ) {
967 if ( GStatus->GraphicStatus()==AIS2D_DS_Displayed) {
968 SetHighlightColor( mySubIntensity );
969 HighlightWithColor( anIObj, mySubIntensity );
970 UpdMain = Standard_True;
971 } else if ( GStatus->GraphicStatus()==AIS2D_DS_Erased ) {
972 indCol = myCollectorVwr->InitializeColor( mySubIntensity );
973 myCollectorVwr->View()->SetDefaultOverrideColor( indCol );
974 HighlightWithColor(anIObj, mySubIntensity );
975 UpdColl=Standard_True;
976 }
977 }
978 if ( UpdateVwr ) {
979 if ( UpdMain) myMainVwr->Update();
980 if ( UpdColl ) myCollectorVwr->Update();
981 }
982 } else {
983 if ( myObjects.IsBound(anIObj) ) {
984 const Handle(AIS2D_GlobalStatus)& GStatus = myObjects(anIObj);
985 GStatus->SubIntensityOn();
986 for ( ItL.Initialize( * GStatus->DisplayedModes() ); ItL.More(); ItL.Next() ) {
987 SetHighlightColor( mySubIntensity );
988 HighlightWithColor(anIObj, mySubIntensity );
989 }
990 } else
991 myLocalContexts(myCurLocalIndex)->SubIntensityOn(anIObj);
992
993 if (UpdateVwr) myMainVwr->Update();
994 }
995}
996
997void AIS2D_InteractiveContext::SubIntensityOff(
998 const Handle(AIS2D_InteractiveObject)& anIObj,
999 const Standard_Boolean UpdateVwr) {
1000
1001 if ( !HasOpenedContext() ) {
1002 if ( !myObjects.IsBound(anIObj) ) return;
1003 const Handle(AIS2D_GlobalStatus)& GStatus = myObjects(anIObj);
1004 if ( !GStatus->IsSubIntensityOn() ) return;
1005 GStatus->SubIntensityOff();
1006 Standard_Boolean UpdMain(Standard_False),UpdColl(Standard_False);
1007
1008 for ( TColStd_ListIteratorOfListOfInteger It( * GStatus->DisplayedModes() ); It.More() ;It.Next() ) {
1009 if ( GStatus->GraphicStatus() != AIS2D_DS_Erased ) {
1010 Unhighlight( anIObj );
1011 UpdMain = Standard_True;
1012 } else {
1013 Unhighlight( anIObj );
1014 UpdColl=Standard_True;
1015 }
1016 }
1017
1018 Standard_Integer DM,SM;
1019 AIS2D_TypeOfDetection HM;
1020 GetDefModes(anIObj,DM,HM,SM);
1021 if ( IsIOSelected(anIObj) )
1022 Highlight(anIObj,HM);
1023
1024 if ( UpdateVwr ) {
1025 if ( UpdMain ) myMainVwr->Update();
1026 if ( UpdColl ) myCollectorVwr->Update();
1027 }
1028 } else {
1029 if ( myObjects.IsBound(anIObj) ) {
1030 const Handle(AIS2D_GlobalStatus)& GStatus = myObjects(anIObj);
1031 GStatus->SubIntensityOff();
1032 for (ItL.Initialize(* GStatus->DisplayedModes());ItL.More();ItL.Next())
1033 Unhighlight(anIObj);
1034 if (GStatus->IsHighlight())
1035 Highlight(anIObj);
1036 } else
1037 myLocalContexts(myCurLocalIndex)->SubIntensityOff(anIObj);
1038 if ( IsSelected(anIObj) )
1039 Highlight(anIObj);
1040
1041 if ( UpdateVwr) myMainVwr->Update();
1042 }
1043}
1044
1045Standard_Boolean AIS2D_InteractiveContext::IsInCollector( const Handle(AIS2D_InteractiveObject)& anIObj ) const {
1046
1047 if ( anIObj.IsNull() )
1048 return Standard_False;
1049
1050 if ( myObjects.IsBound(anIObj) )
1051 return ( myObjects( anIObj)->GraphicStatus() == AIS2D_DS_Erased );
1052 return Standard_False;
1053}
1054
1055void AIS2D_InteractiveContext::Status( const Handle(AIS2D_InteractiveObject)& anIObj,
1056 TCollection_ExtendedString& aStatus ) const {
1057
1058 aStatus = "";
1059
1060 if ( anIObj.IsNull() ) return ;
1061 if ( myObjects.IsBound(anIObj) ) {
1062 aStatus += "\t ____________________________________________";
1063 aStatus += "\t| Known at Neutral Point:\n\tDisplayStatus:";
1064 const Handle(AIS2D_GlobalStatus)& theGStat = myObjects(anIObj);
1065 switch ( theGStat->GraphicStatus() ) {
1066 case AIS2D_DS_Displayed: {
1067 aStatus +="\t| -->Displayed\n";
1068 break;
1069 }
1070 case AIS2D_DS_Erased: {
1071 aStatus +="\t| -->Erased\n";
1072 break;
1073 }
1074 case AIS2D_DS_FullErased: {
1075 aStatus +="\t| -->Full Erased\n";
1076 break;
1077
1078 }
1079 case AIS2D_DS_Temporary:
1080 case AIS2D_DS_None:
1081 break;
1082
1083 }
1084 aStatus += "\t| Active Display Modes in the MainViewer :\n";
1085 for ( ItL.Initialize(*(theGStat->DisplayedModes()));
1086 ItL.More(); ItL.Next() ) {
1087 aStatus += "\t|\t Mode ";
1088 aStatus += TCollection_AsciiString(ItL.Value());
1089 aStatus+="\n";
1090 }
1091 if ( IsCurrent(anIObj) )
1092 aStatus +="\t| Current\n";
1093 //if ( IsSelected(anIObj) )
1094// aStatus +="\t| Selected\n";
1095
1096 aStatus += "\t| Active Selection Modes in the MainViewer :\n";
1097 for ( ItL.Initialize(*(theGStat->SelectionModes() ));
1098 ItL.More(); ItL.Next() ) {
1099 aStatus += "\t\t Mode ";
1100 aStatus += TCollection_AsciiString(ItL.Value());
1101 aStatus+="\n";
1102 }
1103 aStatus += "\t ____________________________________________";
1104
1105 }
1106
1107}
1108
1109void AIS2D_InteractiveContext::UpdateCurrentViewer() {
1110
1111 if ( !myMainVwr.IsNull() ) myMainVwr->UpdateNew();
1112
1113}
1114
1115void AIS2D_InteractiveContext::UpdateCollector() {
1116 if ( !myCollectorVwr.IsNull() ) myCollectorVwr->UpdateNew();
1117}
1118
1119void AIS2D_InteractiveContext::DisplayedObjects (AIS2D_ListOfIO& aListOfIO,
1120 const Standard_Boolean OnlyFromNeutral) const
1121{
1122 AIS2D_DataMapIteratorOfDataMapOfIOStatus It( myObjects );
1123
1124 if ( !HasOpenedContext() || OnlyFromNeutral ) {
1125 for ( ; It.More(); It.Next() )
1126 if ( It.Value()->GraphicStatus() == AIS2D_DS_Displayed )
1127 aListOfIO.Append( It.Key() );
1128 } else {
1129 TColStd_MapOfTransient theMap;
1130
1131 for ( ; It.More(); It.Next() ) {
1132 if ( It.Value()->GraphicStatus() == AIS2D_DS_Displayed )
1133 theMap.Add(It.Key());
1134 }
1135
1136 Standard_Integer NbDisp;
1137 for ( AIS2D_DataMapIteratorOfDataMapOfLC it1(myLocalContexts);
1138 it1.More(); it1.Next() ) {
1139 const Handle(AIS2D_LocalContext)& LC = it1.Value();
1140 NbDisp = LC->DisplayedObjects(theMap);
1141 }
1142
1143 Handle(AIS2D_InteractiveObject) curIO;
1144 Handle(Standard_Transient) Tr;
1145 for ( TColStd_MapIteratorOfMapOfTransient it2(theMap); it2.More(); it2.Next() ) {
1146 Tr = it2.Key();
1147 curIO = *((Handle(AIS2D_InteractiveObject)*) &Tr);
1148 aListOfIO.Append(curIO);
1149 }
1150 }
1151}
1152
1153void AIS2D_InteractiveContext::GetDefModes( const Handle(AIS2D_InteractiveObject)& anIObj,
1154 Standard_Integer& DispMode,
1155 AIS2D_TypeOfDetection& HiMode,
1156 Standard_Integer& SelMode) const {
1157
1158 if ( anIObj.IsNull() ) return ;
1159
1160 DispMode = anIObj->HasDisplayMode() ? anIObj->DisplayMode() : anIObj->DefaultDisplayMode();
1161 HiMode = anIObj->HasHighlightMode() ? anIObj->HighlightMode() : anIObj->DefaultHighlightMode();
1162 SelMode = anIObj->HasSelectionMode() ? anIObj->SelectionMode() : anIObj->DefaultSelectionMode();
1163
1164}
1165
1166void AIS2D_InteractiveContext::EraseGlobal(
1167 const Handle(AIS2D_InteractiveObject)& anIObj,
1168 const Standard_Boolean /*UpdateVwr*/,
1169 const Standard_Boolean /*PutInCollector*/) {
1170
1171 if ( anIObj.IsNull() ) return ;
1172 if ( !myObjects.IsBound( anIObj ) ) return;
1173
1174}
1175
1176
1177void AIS2D_InteractiveContext::SetHighlightColor( const Quantity_NameOfColor aCol ) {
1178
1179 if ( myHighlightColor != aCol ) {
1180 myHighlightColor = aCol;
1181 Standard_Integer anIndex = myMainVwr->InitializeColor(aCol);
1182 myMainVwr->View()->SetDefaultOverrideColor( anIndex );
1183 }
1184}
1185
1186void AIS2D_InteractiveContext::SetSelectionColor( const Quantity_NameOfColor aCol ) {
1187
1188 if ( mySelectionColor != aCol ) {
1189 mySelectionColor = aCol;
1190 Standard_Integer anIndex = myMainVwr->InitializeColor(aCol);
1191 myMainVwr->View()->SetDefaultOverrideColor(anIndex);
1192 }
1193}
1194
1195void AIS2D_InteractiveContext::SetSubIntensityColor( const Quantity_NameOfColor aCol ) {
1196 mySubIntensity = aCol;
1197}
1198
1199Standard_Integer AIS2D_InteractiveContext::HighestIndex() const {
1200
1201 AIS2D_DataMapIteratorOfDataMapOfLC It( myLocalContexts );
1202 Standard_Integer HiInd = 0;
1203 for ( ; It.More(); It.Next() )
1204 HiInd = ( It.Key() > HiInd ) ? It.Key() : HiInd;
1205 return HiInd;
1206
1207}
1208
1209Standard_Integer AIS2D_InteractiveContext::InitializeColor( const Quantity_Color& aColor ) {
1210
1211#ifdef IMP140901
1212 Handle(Aspect_ColorMap) colormap = myMainVwr->ColorMap();
1213#else
1214 Handle(Aspect_GenericColorMap) colormap = myMainVwr->ColorMap();
1215#endif
1216 Standard_Integer size = colormap->Size();
1217 Standard_Integer indColor = colormap->AddEntry(aColor);
1218 if( size != colormap->Size() ) {
1219 myMainVwr->SetColorMap( colormap );
1220 }
1221 return indColor;
1222
1223}
1224
1225Standard_Integer AIS2D_InteractiveContext::InitializeStyle( const Aspect_TypeOfLine aType ) {
1226
1227 Handle(Aspect_TypeMap) typemap = myMainVwr->TypeMap();
1228 Standard_Integer size = typemap->Size();
1229 Standard_Integer indType = typemap->AddEntry(aType);
1230 if( size != typemap->Size() ) {
1231 myMainVwr->SetTypeMap( typemap );
1232 }
1233
1234 return indType;
1235
1236}
1237
1238Standard_Integer AIS2D_InteractiveContext::InitializeWidth( const Aspect_WidthOfLine aWidth ) {
1239
1240 Handle(Aspect_WidthMap) widthmap = myMainVwr->WidthMap();
1241 Standard_Integer size = widthmap->Size();
1242 Standard_Integer indWidth = widthmap->AddEntry(aWidth);
1243 if( size != widthmap->Size() ) {
1244 myMainVwr->SetWidthMap( widthmap );
1245 }
1246
1247 return indWidth;
1248
1249}
1250
1251Standard_Integer AIS2D_InteractiveContext::InitializeMarker( const Aspect_TypeOfMarker aMark ) {
1252
1253 Handle(Aspect_MarkMap) markmap = myMainVwr->MarkMap();
1254 Standard_Integer size = markmap->Size();
1255 Standard_Integer indMark = markmap->AddEntry(aMark);
1256 if( size != markmap->Size() ) {
1257 myMainVwr->SetMarkMap( markmap );
1258 }
1259
1260 return indMark;
1261
1262}
1263
1264Standard_Integer AIS2D_InteractiveContext::InitializeFont( const Aspect_FontStyle& aFont ) {
1265
1266 Handle(Aspect_FontMap) fontmap = myMainVwr->FontMap();
1267 Standard_Integer size = fontmap->Size();
1268 Standard_Integer indFont = fontmap->AddEntry(aFont);
1269 if( size != fontmap->Size() ) {
1270 myMainVwr->SetFontMap( fontmap );
1271 }
1272 return indFont;
1273
1274}
1275
1276void AIS2D_InteractiveContext::DrawObject( const Handle(AIS2D_InteractiveObject)& anIObj,
1277 const Standard_Integer aDispMode ) {
1278
1279 if ( anIObj->IsKind(STANDARD_TYPE(AIS2D_ProjShape) ) ) {
1280
1281 Handle(AIS2D_ProjShape) thePS = Handle(AIS2D_ProjShape)::DownCast(anIObj);
1282 Handle(Graphic2d_Line) theLines = thePS->GetPrimitives();
1283 Handle(Prs2d_AspectLine) theAspLine;
1284
1285 if ( !anIObj->HasAspect(theLines) ) {
1286 Handle(Prs2d_AspectRoot) theAspRoot = anIObj->Attributes()->FindAspect(Prs2d_AN_LINE);
1287 theAspLine = Handle(Prs2d_AspectLine)::DownCast(theAspRoot);
1288 anIObj->SetAspect( theAspLine, theLines );
1289
1290 } else {
1291 theAspLine = Handle(Prs2d_AspectLine)::DownCast( anIObj->GetAspect(theLines) );
1292 }
1293
1294 Quantity_Color aColor;
1295 Aspect_TypeOfLine aType;
1296 Aspect_WidthOfLine aWidth;
1297
1298 theAspLine->ValuesOfLine( aColor, aType, aWidth );
1299
1300 Standard_Integer colorInd = theAspLine->ColorIndex();
1301 Standard_Integer typeInd = theAspLine->TypeIndex();
1302 Standard_Integer widthInd = theAspLine->WidthIndex();
1303
1304 if ( !colorInd ) {
1305 colorInd = InitializeColor( aColor );
1306 theLines->SetColorIndex( colorInd );
1307 }
1308
1309 if ( !typeInd ) {
1310 typeInd = InitializeStyle( aType );
1311 theLines->SetTypeIndex( typeInd );
1312 }
1313
1314 if ( !widthInd ) {
1315 widthInd = InitializeWidth( aWidth );
1316 theLines->SetWidthIndex( widthInd );
1317 }
1318
1319 if ( thePS->IsHLMode() ) {
1320 Handle(Graphic2d_Line) theHLines = thePS->GetHLPrimitives();
1321 theHLines->SetColorIndex( colorInd );
1322 theHLines->SetWidthIndex( widthInd );
1323 Standard_Integer theDashInd = InitializeStyle( Aspect_TOL_DASH );
1324 theHLines->SetTypeIndex( theDashInd );
1325 }
1326
1327 } else {
1328
1329 Handle(Graphic2d_Primitive) thePrim;
1330
1331 for ( Standard_Integer i = 1; i <= anIObj->Length(); i++ ) {
1332 thePrim = anIObj->Primitive( i );
1333 thePrim->SetDisplayMode(aDispMode);
1334 if ( thePrim->IsKind(STANDARD_TYPE(Graphic2d_Line) ) ) {
1335
1336 Handle(Graphic2d_Line) theLine = Handle(Graphic2d_Line)::DownCast(thePrim);
1337 Handle(Prs2d_AspectLine) theAspLine;
1338
1339 if ( !anIObj->HasAspect(theLine) ) {
1340 Handle(Prs2d_AspectRoot) theAspRoot = anIObj->Attributes()->FindAspect(Prs2d_AN_LINE);
1341 theAspLine = Handle(Prs2d_AspectLine)::DownCast(theAspRoot);
1342 anIObj->SetAspect( theAspLine, theLine );
1343
1344 } else {
1345 theAspLine = Handle(Prs2d_AspectLine)::DownCast( anIObj->GetAspect(theLine) );
1346 }
1347
1348 Quantity_Color aColor;
1349 Aspect_TypeOfLine aType;
1350 Aspect_WidthOfLine aWidth;
1351
1352 Quantity_Color aIntColor;
1353 Graphic2d_TypeOfPolygonFilling aTypeFill;
1354 Standard_Integer aTile;
1355 Standard_Boolean aDrawEdge;
1356
1357 theAspLine->ValuesOfLine( aColor, aType, aWidth );
1358 theAspLine->ValuesOfPoly( aIntColor, aTypeFill, aTile, aDrawEdge );
1359
1360 Standard_Integer colorInd = theAspLine->ColorIndex();
1361 Standard_Integer typeInd = theAspLine->TypeIndex();
1362 Standard_Integer widthInd = theAspLine->WidthIndex();
1363 Standard_Integer colorIntInd = theAspLine->InterColorIndex();
1364
1365 if ( !colorInd ) {
1366 colorInd = InitializeColor( aColor );
1367 theLine->SetColorIndex( colorInd );
1368 }
1369
1370 if ( !typeInd ) {
1371 typeInd = InitializeStyle( aType );
1372 theLine->SetTypeIndex( typeInd );
1373 }
1374
1375 if ( !widthInd ) {
1376 widthInd = InitializeWidth( aWidth );
1377 theLine->SetWidthIndex( widthInd );
1378 }
1379
1380 if ( !colorIntInd ) {
1381 colorIntInd = InitializeColor( aIntColor );
1382 theLine->SetInteriorColorIndex( colorIntInd );
1383 }
1384
1385 theLine->SetTypeOfPolygonFilling( aTypeFill );
1386 theLine->SetInteriorPattern( aTile );
1387 theLine->SetDrawEdge( aDrawEdge );
1388
1389 if ( theLine->IsKind(STANDARD_TYPE(Prs2d_Point) ) ) {
1390
1391 Handle(Prs2d_Point) thePnt = Handle(Prs2d_Point)::DownCast(theLine);
1392 thePnt->SetIndex( InitializeMarker( thePnt->Marker() ) );
1393 }
1394
1395 } // end if the kind of primitive is Graphic2d_Line
1396
1397 } // end for exploration of the interactive object
1398
1399 } // end if IO is AIS2D_ProjShape
1400
1401}
1402
1403void AIS2D_InteractiveContext::ResetOriginalState(const Standard_Boolean /*updateviewer*/) {
1404 /*
1405 Standard_Boolean upd_main(Standard_False),upd_col(Standard_False);
1406 TColStd_ListIteratorOfListOfInteger itl;
1407
1408 for (AIS_DataMapIteratorOfDataMapOfIOStatus it(myObjects);it.More();it.Next()){
1409 const Handle(AIS_InteractiveObject)& iobj = it.Key();
1410 const Handle(AIS_GlobalStatus)& STAT = it.Value();
1411 switch(STAT->GraphicStatus()){
1412 case AIS_DS_Displayed:{
1413 upd_main = Standard_True;
1414
1415 // partie display...
1416 for(itl.Initialize(STAT->DisplayedModes());itl.More();itl.Next())
1417 myMainPM->Display(iobj,itl.Value());
1418 if(STAT->IsHilighted()){
1419 if(STAT->HilightColor()!=Quantity_NOC_WHITE)
1420 HilightWithColor(iobj,STAT->HilightColor(),Standard_False);
1421 else
1422 Hilight(iobj,Standard_False);
1423 }
1424 //partie selection
1425 for(itl.Initialize(STAT->SelectionModes());itl.More();itl.Next()){
1426 if(itl.Value()!=-1)
1427 mgrSelector->Activate(iobj,itl.Value(),myMainSel);
1428 }
1429 break;
1430 }
1431 case AIS_DS_Erased:{
1432 upd_col = Standard_True;
1433 EraseGlobal(iobj,Standard_False,Standard_True);
1434 break;
1435 }
1436 case AIS_DS_FullErased:{
1437 EraseGlobal(iobj,Standard_False,Standard_False);
1438 break;
1439 }
1440#ifndef DEB
1441 default:
1442 break;
1443#endif
1444 }
1445 }
1446 if(updateviewer){
1447 if(upd_main)
1448 myMainVwr->Update();
1449 if(upd_col)
1450 myCollectorVwr->Update();
1451 }*/
1452}
1453
1454Standard_Boolean AIS2D_InteractiveContext::AvailableToDetect( const Handle(AIS2D_InteractiveObject)& anIO ) const {
1455#ifndef OCC146
1456 if ( anIO->HighlightMode() == AIS2D_TOD_OBJECT)
1457 return ( ! anIO->State() );
1458#endif
1459 return Standard_True;
1460}
1461
1462void AIS2D_InteractiveContext::DoDetectObject( const Handle(AIS2D_InteractiveObject)& theIO,
1463 const Handle(Graphic2d_TransientManager)& theDrawer ) {
1464 theIO->ClearSeqDetPrim();
1465#ifdef OCC146
1466 if (!theIO->State())
1467#endif
1468 theIO->Unhighlight();
1469 myCurDetectMode = theIO->HighlightMode();
1470 switch ( myCurDetectMode ) {
1471 default :
1472 case AIS2D_TOD_OBJECT :
1473 if ( !IsIOSelected( theIO ) ) {
1474 theDrawer->Draw( theIO );
1475#ifdef OCC146
1476 }
1477 {
1478#endif
1479 if ( !IsIOPicked( theIO ) )
1480 mySeqOfDetIO->Append( theIO );
1481 }
1482 break;
1483 case AIS2D_TOD_PRIMITIVE: {
1484 Standard_Integer pLength = theIO->PickList()->Length();
1485 Handle(Graphic2d_Primitive) thePrim;
1486
1487 if ( pLength ) {
1488 for ( int i = 1; i <= pLength; i++ ) {
1489 thePrim = theIO->Primitive(theIO->PickList()->Value(i));
1490 if ( ! thePrim->IsHighlighted() &&
1491 ! IsPrimSelected ( theIO, thePrim ) ) {
1492 theDrawer->Draw( thePrim );
1493#ifdef OCC146
1494 }
1495 {
1496#endif
1497 if ( ! IsPrimPicked( theIO, thePrim ) ) {
1498 theIO->AddDetectPrim( thePrim, 0 );
1499 if ( !IsIOPicked( theIO ) )
1500 mySeqOfDetIO->Append( theIO );
1501 }
1502 }
1503 }
1504
1505 } else {
1506 thePrim = theIO->Primitive( theIO->PickedIndex() );
1507 if ( ! thePrim->IsHighlighted() ) {
1508 theDrawer->Draw( thePrim );
1509#ifdef OCC146
1510 }
1511 {
1512#endif
1513 if ( ! IsPrimPicked( theIO, thePrim ) ) {
1514 theIO->AddDetectPrim( thePrim, 0 );
1515 if ( !IsIOPicked( theIO ) )
1516 mySeqOfDetIO->Append( theIO );
1517 }
1518 }
1519 }
1520 }
1521 break;
1522 case AIS2D_TOD_ELEMENT: {
1523 Standard_Integer theInd, pLength = theIO->PickList()->Length();
1524 Handle(Graphic2d_Primitive) thePrim;
1525 if ( pLength ) {
1526 for ( int i = 1; i <= pLength; i++ ) {
1527 thePrim = theIO->Primitive(theIO->PickList()->Value(i));
1528 theInd = thePrim->PickedIndex();
1529 if ( ! thePrim->IsHighlighted() ) {
1530
1531 // SAV - begin
1532 const TColStd_MapOfInteger& indices = thePrim->PickedIndices();
1533
1534 if ( indices.Extent() ) {
1535 theDrawer->DrawPickedElements( thePrim );
1536
1537 TColStd_MapIteratorOfMapOfInteger it( indices );
1538 theIO->AddDetectPrim( thePrim, it.Key() );
1539
1540 if ( !IsIOPicked( theIO ) )
1541 mySeqOfDetIO->Append( theIO );
1542 }
1543 else {
1544
1545 for ( int j = 1; j <= thePrim->NumOfElemIndices(); ++j ) {
1546 theDrawer->DrawElement( thePrim, j );
1547 if ( ! IsElemPicked( theIO, thePrim, j ) ) {
1548 theIO->AddDetectPrim( thePrim, j );
1549 if ( !IsIOPicked( theIO ) )
1550 mySeqOfDetIO->Append( theIO );
1551 }
1552 }
1553 }
1554
1555/*
1556 for ( int j = 1; j <= thePrim->NumOfElemIndices(); ++j ) {
1557 theDrawer->DrawElement( thePrim, j );
1558 if ( ! IsElemPicked( theIO, thePrim, j ) ) {
1559 theIO->AddDetectPrim( thePrim, j );
1560 if ( !IsIOPicked( theIO ) )
1561 mySeqOfDetIO->Append( theIO );
1562 }
1563 }
1564*/
1565 }
1566 /*if ( ! IsElemSelected( theIO, thePrim, theInd ) ) {
1567 theDrawer->DrawElement( thePrim, theInd );
1568 if ( ! IsElemPicked( theIO, thePrim, theInd ) ) {
1569 theIO->AddDetectPrim( thePrim, theInd );
1570 if ( ! IsIOPicked( theIO ) )
1571 mySeqOfDetIO->Append( theIO );
1572 }
1573
1574 }
1575 */
1576 }
1577 } else {
1578 thePrim = theIO->Primitive(theIO->PickedIndex());
1579 theInd = thePrim->PickedIndex();
1580#ifdef BUG
1581 if ( theInd > 0 )
1582#else
1583 if ( theInd != 0 )
1584#endif
1585#ifdef OCC146
1586 {
1587#endif
1588 if ( ! IsElemSelected( theIO, thePrim, theInd ) ) {
1589 theDrawer->DrawElement( thePrim, theInd );
1590#ifdef OCC146
1591 }
1592 {
1593#endif
1594 if ( ! IsElemPicked( theIO, thePrim, theInd ) ) {
1595 theIO->AddDetectPrim( thePrim, theInd );
1596 if ( ! IsIOPicked( theIO ) )
1597 mySeqOfDetIO->Append( theIO );
1598 }
1599 }
1600#ifdef OCC146
1601 }
1602#endif
1603 }
1604 }
1605 break;
1606 case AIS2D_TOD_VERTEX: {
1607 Standard_Integer theInd, pLength = theIO->PickList()->Length();
1608 Handle(Graphic2d_Primitive) thePrim;
1609 if ( pLength ) {
1610 for ( int i = 1; i <= pLength; i++ ) {
1611 thePrim = theIO->Primitive(theIO->PickList()->Value(i));
1612 theInd = thePrim->PickedIndex();
1613 if ( ! thePrim->IsHighlighted() )
1614 for ( int j = 1; j <= thePrim->NumOfVertIndices(); ++j ) {
1615 theDrawer->DrawVertex( thePrim, j );
1616 if ( ! IsElemPicked( theIO, thePrim, -j ) ) {
1617 theIO->AddDetectPrim( thePrim, -j );
1618 if ( !IsIOPicked( theIO ) )
1619 mySeqOfDetIO->Append( theIO );
1620 }
1621 }
1622 }
1623 /*if ( ! IsElemSelected( theIO, thePrim, theInd ) ) {
1624 theDrawer->DrawVertex( thePrim, -theInd );
1625 if ( ! IsElemPicked( theIO, thePrim, theInd ) ) {
1626 theIO->AddDetectPrim( thePrim, -theInd );
1627 if ( ! IsIOPicked( theIO ) )
1628 mySeqOfDetIO->Append( theIO );
1629 }
1630 }*/
1631
1632 } else {
1633 thePrim = theIO->Primitive(theIO->PickedIndex());
1634 theInd = thePrim->PickedIndex();
1635 if ( theInd < 0 )
1636#ifdef OCC146
1637 {
1638#endif
1639 if ( ! IsElemSelected( theIO, thePrim, theInd ) ) {
1640 theDrawer->DrawVertex( thePrim, -theInd );
1641#ifdef OCC146
1642 }
1643 {
1644#endif
1645 if ( ! IsElemPicked( theIO, thePrim, theInd ) ) {
1646 theIO->AddDetectPrim( thePrim, theInd );
1647 if ( !IsIOPicked( theIO ) )
1648 mySeqOfDetIO->Append( theIO );
1649 }
1650 }
1651#ifdef OCC146
1652 }
1653#endif
1654
1655 }
1656 }
1657 break;
1658 }
1659
1660}
1661
1662Standard_Boolean AIS2D_InteractiveContext::IsIOPicked( const Handle(AIS2D_InteractiveObject)& anIO ) const {
1663
1664 for ( int i = 1; i <= mySeqOfDetIO->Length(); i++ )
1665 if ( anIO == mySeqOfDetIO->Value(i) )
1666 return Standard_True;
1667 return Standard_False;
1668
1669}
1670
1671Standard_Boolean AIS2D_InteractiveContext::IsIOSelected( const Handle(AIS2D_InteractiveObject)& anIO ) const {
1672
1673 for ( int i = 1; i <= mySeqOfSelIO->Length(); i++ )
1674 if ( anIO == mySeqOfSelIO->Value(i) )
1675 return Standard_True;
1676 return Standard_False;
1677
1678}
1679
1680Standard_Boolean AIS2D_InteractiveContext::IsPrimSelected( const Handle(AIS2D_InteractiveObject)& anIO,
1681 const Handle(Graphic2d_Primitive)& aPrim ) const {
1682
1683 Handle(AIS2D_HSequenceOfPrimArchit) theSPA = anIO->GetSelectedSeqPrim();
1684
1685 for ( int i = 1; i <= theSPA->Length(); i++ )
1686 if ( aPrim == theSPA->Value(i)->GetPrimitive() )
1687 return Standard_True;
1688 return Standard_False;
1689
1690}
1691
1692Standard_Boolean AIS2D_InteractiveContext::IsPrimPicked( const Handle(AIS2D_InteractiveObject)& anIO,
1693 const Handle(Graphic2d_Primitive)& aPrim ) const {
1694 Handle(AIS2D_HSequenceOfPrimArchit) theSPA = anIO->GetDetectSeqPrim();
1695
1696 for ( int i = 1; i <= theSPA->Length(); i++ )
1697 if ( aPrim == theSPA->Value(i)->GetPrimitive() )
1698 return Standard_True;
1699 return Standard_False;
1700}
1701
1702Standard_Boolean AIS2D_InteractiveContext::IsElemPicked( const Handle(AIS2D_InteractiveObject)& anIO,
1703 const Handle(Graphic2d_Primitive)& aPrim,
1704 const Standard_Integer ind ) const {
1705 Handle(AIS2D_HSequenceOfPrimArchit) theSPA = anIO->GetDetectSeqPrim();
1706 for ( int i = 1; i <= theSPA->Length(); i++ )
1707 if ( aPrim == theSPA->Value(i)->GetPrimitive() &&
1708 ind == theSPA->Value(i)->GetIndex() )
1709 return Standard_True;
1710 return Standard_False;
1711}
1712
1713Standard_Boolean AIS2D_InteractiveContext::IsElemSelected( const Handle(AIS2D_InteractiveObject)& anIO,
1714 const Handle(Graphic2d_Primitive)& aPrim,
1715 const Standard_Integer ind ) const {
1716 Handle(AIS2D_HSequenceOfPrimArchit) theSPA = anIO->GetSelectedSeqPrim();
1717 for ( int i = 1; i <= theSPA->Length(); i++ )
1718 if ( aPrim == theSPA->Value(i)->GetPrimitive() &&
1719 ind == theSPA->Value(i)->GetIndex() )
1720 return Standard_True;
1721 return Standard_False;
1722}
1723
1724void AIS2D_InteractiveContext::Highlight( const Handle(AIS2D_InteractiveObject)& anIObj,
1725 const Standard_Boolean updateVwr ) {
1726 if ( anIObj.IsNull() ) return;
1727
1728 if ( !anIObj->HasInteractiveContext() )
1729 anIObj->SetContext( this );
1730 if ( !HasOpenedContext() ) {
1731 if ( !myObjects.IsBound(anIObj) ) return;
1732 Handle(AIS2D_GlobalStatus) aGS = myObjects(anIObj);
1733
1734 aGS->SetHighlightStatus( Standard_True );
1735
1736 switch ( aGS->GraphicStatus() ) {
1737
1738 case AIS2D_DS_Displayed: {
1739
1740 Standard_Integer DispMode,SelMode;
1741 AIS2D_TypeOfDetection HiMode;
1742 GetDefModes( anIObj, DispMode, HiMode, SelMode );
1743 Standard_Integer pInd;
1744 anIObj->Highlight(myMainVwr->InitializeColor( mySelectionColor ));
1745 switch( HiMode ) {
1746 default:
1747 case AIS2D_TOD_OBJECT:
1748 break;
1749 case AIS2D_TOD_PRIMITIVE:
1750 pInd = anIObj->PickedIndex();
1751 anIObj->Unhighlight();
1752 break;
1753 case AIS2D_TOD_ELEMENT:
1754 pInd = anIObj->PickedIndex();
1755 anIObj->Unhighlight();
1756 break;
1757 case AIS2D_TOD_VERTEX:
1758 pInd = anIObj->PickedIndex();
1759 anIObj->Unhighlight();
1760 break;
1761 } //end switch
1762
1763 if ( updateVwr) myMainVwr->Update();
1764
1765 break;
1766 }
1767 case AIS2D_DS_Erased: {
7fd59977 1768 anIObj->Highlight(myCollectorVwr->InitializeColor( mySelectionColor ));
1769 if ( updateVwr ) myCollectorVwr->Update();
1770 break;
1771 }
1772 case AIS2D_DS_FullErased:
1773 case AIS2D_DS_Temporary:
1774 case AIS2D_DS_None:
1775 break;
1776 } //end switch
1777 } // end if opened context isn't exists
1778 //else
1779 // myLocalContexts(myCurLocalIndex)->Highlight(anIObj);
1780
1781}
1782
1783void AIS2D_InteractiveContext::HighlightWithColor( const Handle(AIS2D_InteractiveObject)& anIObj,
1784 const Quantity_NameOfColor aCol,
1785 const Standard_Boolean updateVwr ) {
1786
1787 if ( anIObj.IsNull() ) return;
1788
1789 if ( !anIObj->HasInteractiveContext() ) anIObj->SetContext(this);
1790
1791 if ( !HasOpenedContext() ) {
1792 if ( !myObjects.IsBound(anIObj) ) return;
1793
1794 const Handle(AIS2D_GlobalStatus)& aGS = myObjects(anIObj);
1795 //const TColStd_ListOfInteger& LL = * aGS->DisplayedModes();
1796
1797 aGS->SetHighlightStatus (Standard_True);
1798
1799 switch ( aGS->GraphicStatus() ) {
1800 case AIS2D_DS_Displayed:{
1801 Standard_Integer DispMode, SelMode;
1802 AIS2D_TypeOfDetection HiMode;
1803 GetDefModes( anIObj, DispMode, HiMode, SelMode );
1804 Standard_Integer indCol = myMainVwr->InitializeColor( aCol );
1805 anIObj->Highlight(indCol);
1806 //SetSelectionColor(aCol);
1807 aGS->SetHighlightColor(aCol);
1808 // if ( updateVwr ) myMainVwr->Update();
1809 break;
1810 }
1811 case AIS2D_DS_Erased: {
1812#ifdef DEB
7fd59977 1813 Standard_Integer indCol = myCollectorVwr->InitializeColor( aCol );
1814#endif
1815 if ( updateVwr) myCollectorVwr->Update();
1816 break;
1817 }
1818 case AIS2D_DS_FullErased:
1819 case AIS2D_DS_Temporary:
1820 case AIS2D_DS_None:
1821 break;
1822 }
1823 } // else
1824 // myLocalContexts(myCurLocalIndex)->Highlight(anIObj,aCol);
1825 if ( updateVwr) myMainVwr->Update();
1826
1827}
1828
1829void AIS2D_InteractiveContext::Unhighlight( const Handle(AIS2D_InteractiveObject)& anIObj,
1830 const Standard_Boolean updateVwr ) {
1831 if ( anIObj.IsNull() ) return;
1832 anIObj->Unhighlight();
1833 switch ( anIObj->HighlightMode() ) {
1834 default:
1835 case AIS2D_TOD_OBJECT:
1836 break;
1837 case AIS2D_TOD_PRIMITIVE:
1838 if ( !anIObj->Primitive(anIObj->PickedIndex()).IsNull() )
1839 anIObj->Primitive(anIObj->PickedIndex())->Unhighlight();
1840 break;
1841 case AIS2D_TOD_ELEMENT:
1842 if ( !anIObj->Primitive(anIObj->PickedIndex()).IsNull() )
1843 anIObj->Primitive(anIObj->PickedIndex())->Unhighlight();
1844 break;
1845 case AIS2D_TOD_VERTEX:
1846 if ( !anIObj->Primitive(anIObj->PickedIndex()).IsNull() )
1847 anIObj->Primitive(anIObj->PickedIndex())->Unhighlight();
1848 break;
1849 }
1850 if ( updateVwr) myMainVwr->UpdateNew();
1851}
1852
1853void AIS2D_InteractiveContext::Place(
1854 const Standard_Integer XPix,
1855 const Standard_Integer YPix,
1856 const Handle(V2d_View)& aView,
1857 const Handle(AIS2D_InteractiveObject)& anIO,
1858 const Standard_Boolean isTemporary ) {
1859
1860 Standard_Real XPS, YPS;
1861 aView->Convert( XPix, YPix, XPS, YPS );
1862 gp_GTrsf2d theGTrsf;
1863 gp_Trsf2d theTrsf;
1864 theTrsf.SetTranslationPart( gp_Vec2d(gp_Pnt2d(0.,0.), gp_Pnt2d(XPS, YPS) ) );
1865 theGTrsf.SetTrsf2d( theTrsf );
1866 anIO->SetTransform( theGTrsf );
1867 Handle(V2d_Viewer) theViewer = aView->Viewer();
1868 if ( isTemporary ) {
1869
1870 Handle(Graphic2d_TransientManager) theDrawer =
1871 Handle(Graphic2d_TransientManager)::DownCast( theViewer->View()->Drawer() );
1872 Standard_Integer ind = theViewer->InitializeColor(myHighlightColor);
1873 theDrawer->SetOverride( Standard_True );
1874 theDrawer->SetOverrideColor( ind );
1875 Display( anIO, Standard_False );
1876 anIO->Highlight( ind );
1877 theDrawer->BeginDraw( aView->Driver() );
1878 theDrawer->Draw( anIO );
1879 theDrawer->EndDraw();
1880 theDrawer->SetOverride( Standard_False );
1881 return;
1882 }
1883 if ( !IsDisplayed( anIO ) )
1884 Display( anIO );
1885 else
1886 theViewer->Update();
1887
1888}
1889
1890void AIS2D_InteractiveContext::Drag(
1891 const Standard_Integer XPix,
1892 const Standard_Integer YPix,
1893 const Handle(V2d_View)& aView,
1894 const Standard_Boolean isTemporary ) {
1895
1896 if ( ! mySeqOfSelIO->IsEmpty() ) {
1897 Handle(AIS2D_InteractiveObject) theIO;
1898 for ( int j = 1; j <= mySeqOfSelIO->Length(); ++j ) {
1899 theIO = mySeqOfSelIO->Value(j);
1900 if ( !isTemporary ) {
1901 Unhighlight( theIO, Standard_False );
1902 theIO->SetState(0);
1903 mySeqOfSelIO->Remove(j);
1904 }
1905 Place( XPix, YPix, aView, theIO, isTemporary );
1906 }
1907 }
1908}
1909
1910AIS2D_StatusOfDetection AIS2D_InteractiveContext::MoveTo(
1911 const Standard_Integer XPix,
1912 const Standard_Integer YPix,
1913 const Handle(V2d_View)& aView ) {
1914
1915 RectMoveTo = Standard_False;
1916 if ( HasOpenedContext() && aView->Viewer() != myCollectorVwr ) {
1917 myWasLastMain = Standard_True;
1918 return myLocalContexts(myCurLocalIndex)->MoveTo( XPix, YPix, aView );
1919 }
1920 Standard_Boolean is_main = Standard_True, UpdVwr = Standard_False;
1921 Handle(V2d_Viewer) theViewer = aView->Viewer();
1922
1923 if ( theViewer == myMainVwr ) {
1924 myLastPicked = myLastinMain;
1925 myWasLastMain = Standard_True;
1926 } else if ( theViewer == myCollectorVwr ) {
1927 myLastPicked = myLastinColl;
1928 is_main = Standard_False;
1929 myWasLastMain = Standard_False;
1930 } else
1931 return AIS2D_SOD_Error;
1932
1933 AIS2D_StatusOfDetection theStat( AIS2D_SOD_Nothing );
1934
1935 Handle(Graphic2d_TransientManager) theDrawer =
1936 Handle(Graphic2d_TransientManager)::DownCast( theViewer->View()->Drawer() );
1937
1938 Handle(Graphic2d_DisplayList) thePickList = aView->Pick( XPix, YPix, myDetectPrecision);
1939
1940 if ( ! thePickList->IsEmpty() ) {
1941
1942 if ( thePickList->Length() == 1 ) {
1943 Handle(Graphic2d_GraphicObject) theGO = thePickList->Value(1);
1944 if ( ! theGO->IsKind(STANDARD_TYPE(AIS2D_InteractiveObject) ) )
1945 return AIS2D_SOD_Nothing;
1946 Handle(AIS2D_InteractiveObject) theIO = Handle(AIS2D_InteractiveObject)::DownCast(theGO);
1947 if ( IsIOPicked( theIO ) )
1948 switch ( theIO->HighlightMode() ) {
1949 default:
1950 case AIS2D_TOD_OBJECT:
1951 return AIS2D_SOD_OnlyOneDetected;
1952 break;
1953 case AIS2D_TOD_PRIMITIVE:
1954 if ( IsPrimPicked(theIO, theIO->Primitive(theIO->PickedIndex())) )
1955 return AIS2D_SOD_OnlyOneDetected;
1956 break;
1957 case AIS2D_TOD_ELEMENT: {
1958 Standard_Integer ind = theIO->PickedIndex();
1959 if ( IsElemPicked( theIO, theIO->Primitive(ind), theIO->Primitive(ind)->PickedIndex() ) )
1960 return AIS2D_SOD_OnlyOneDetected;
1961 else if ( ind < 0 )
1962 myResetDetect= Standard_True;
1963
1964 }
1965 break;
1966 case AIS2D_TOD_VERTEX: {
1967 Standard_Integer ind = theIO->PickedIndex();
1968 if ( IsElemPicked( theIO, theIO->Primitive(ind), theIO->Primitive(ind)->PickedIndex() ) )
1969 return AIS2D_SOD_OnlyOneDetected;
1970 //else if ( ind > 0 )
1971 // myResetDetect= Standard_True;
1972
1973 }
1974 break;
1975
1976 }
1977#ifdef OCC146
1978 myResetDetect = Standard_True;
1979#endif
1980 }
1981 if ( myResetDetect ) {
1982 mySeqOfDetIO->Clear();
1983 Standard_Integer ind = myMainVwr->InitializeColor(myHighlightColor);
1984
1985 for ( int i = 1 ; i <= thePickList->Length(); i++ ) {
1986 Handle(Graphic2d_GraphicObject) theGOi = thePickList->Value(i);
1987 if ( theGOi->IsKind(STANDARD_TYPE(AIS2D_InteractiveObject) ) ) {
1988
1989 myLastPicked = Handle(AIS2D_InteractiveObject)::DownCast( theGOi );
1990 ( is_main ) ? myLastinMain = myLastPicked : myLastinColl = myLastPicked;
1991 if ( myLastPicked->HasHighlightMode() )
1992
1993 if ( AvailableToDetect(myLastPicked) ) {
1994 if ( myLastPicked->HighlightMode() == AIS2D_TOD_OBJECT )
1995#ifdef OCC146
1996 if (!myLastPicked->State())
1997#endif
1998 myLastPicked->Highlight( ind );
1999 theDrawer->SetOverride(Standard_True);
2000 theDrawer->SetOverrideColor(ind);
2001 theDrawer->BeginDraw( aView->Driver() );
2002 DoDetectObject( myLastPicked, theDrawer );
2003 theDrawer->EndDraw();
2004 theDrawer->SetOverride(Standard_False);
2005
2006 } else theStat = AIS2D_SOD_Selected;
2007 }
2008 } // end for
2009
2010 myResetDetect= Standard_False;
2011
2012 } // end if myResetDetect is true
2013
2014 } else {
2015
2016 theStat = AIS2D_SOD_Nothing;
2017 theDrawer->RestoreArea( aView->Driver() );
2018 myResetDetect= Standard_True;
2019
2020 if ( ! mySeqOfDetIO->IsEmpty() ) {
2021 Handle(AIS2D_InteractiveObject) theIO;
2022 for ( int i = 1; i <= mySeqOfDetIO->Length(); ++i ) {
2023 theIO = mySeqOfDetIO->Value(i);
2024 if ( theIO->HighlightMode() == AIS2D_TOD_ELEMENT ||
2025 theIO->HighlightMode() == AIS2D_TOD_VERTEX ) {
2026 theIO->ClearSeqDetPrim();
2027 } else {
2028 if ( ! theIO->State() )
2029 theIO->Unhighlight();
2030 }
2031 theIO->ClearSeqDetPrim();
2032 }
2033 UpdVwr = Standard_True;
2034 }
2035 ( is_main ) ? myLastinMain.Nullify() : myLastinColl.Nullify();
2036 mySeqOfDetIO->Clear();
2037
2038 } // end if PickList isn't empty
2039
2040 //if ( !myLastPicked.IsNull() ) myLastPicked->Unhighlight();
2041
2042 if ( UpdVwr )
2043 is_main ? myMainVwr->Update() : myCollectorVwr->Update();
2044 myLastPicked.Nullify();
2045 myLastMoveView = aView;
2046
2047 return theStat;
2048
2049}
2050
2051
2052//SAV
2053AIS2D_StatusOfDetection AIS2D_InteractiveContext
2054::MoveCircleTo( const Standard_Integer XPix,
2055 const Standard_Integer YPix,
2056 const Standard_Integer Radius,
2057 const Handle(V2d_View)& aView )
2058{
2059 mySeqOfDetIO->Clear();
2060
2061 Handle(Graphic2d_DisplayList) thePickList =
2062 aView->PickByCircle( XPix, YPix, Radius );
2063
2064 return Detect( thePickList, aView );
2065}
2066
2067
2068AIS2D_StatusOfDetection AIS2D_InteractiveContext::MoveTo(
2069 const Standard_Integer Xmin,
2070 const Standard_Integer Ymin,
2071 const Standard_Integer Xmax,
2072 const Standard_Integer Ymax,
2073 const Handle(V2d_View)& aView ) {
2074
2075
2076 /*if ( HasOpenedContext() && aView->Viewer() != myCollectorVwr ) {
2077 myWasLastMain = Standard_True;
2078 return myLocalContexts(myCurLocalIndex)->MoveTo( Xmin, Ymin, Xmax, Ymax, aView );
2079 }
2080 */
2081 mySeqOfDetIO->Clear();
2082
2083 Handle(Graphic2d_DisplayList) thePickList = aView->Pick( Xmin, Ymin, Xmax, Ymax, myPickMode );
2084
2085 return Detect( thePickList, aView );
2086}
2087
2088//SAV
2089AIS2D_StatusOfDetection AIS2D_InteractiveContext
2090::Detect( const Handle(Graphic2d_DisplayList)& dList,
2091 const Handle(V2d_View)& aView )
2092{
2093 AIS2D_StatusOfDetection theStat( AIS2D_SOD_Nothing );
2094
2095 RectMoveTo = Standard_True;
2096 Handle(V2d_Viewer) theViewer = aView->Viewer();
2097 Standard_Boolean is_main = ( theViewer == myCollectorVwr ) ?
2098 Standard_False : Standard_True;
2099 if ( is_main ) myWasLastMain = Standard_True;
2100
2101 Handle(Graphic2d_TransientManager) theDrawer =
2102 Handle(Graphic2d_TransientManager)::DownCast( theViewer->View()->Drawer() );
2103
2104
2105 if ( ! dList->IsEmpty() ) {
2106 Standard_Integer ind = ( is_main ) ?
2107 myMainVwr->InitializeColor(myHighlightColor) :
2108 myCollectorVwr->InitializeColor(myHighlightColor);
2109 Handle(AIS2D_InteractiveObject) theIO;
2110 theDrawer->SetOverride( Standard_True );
2111 theDrawer->SetOverrideColor( ind );
2112 theDrawer->BeginDraw( aView->Driver() );
2113
2114 for ( int i = 1 ; i <= dList->Length(); i++ ) {
2115 Handle(Graphic2d_GraphicObject) theGOi = dList->Value(i);
2116 if ( theGOi->IsKind(STANDARD_TYPE(AIS2D_InteractiveObject))) {
2117 theIO = Handle(AIS2D_InteractiveObject)::DownCast( theGOi );
2118 if ( theIO->HasHighlightMode() )
2119 if ( AvailableToDetect( theIO ) ) {
2120 if ( theIO->HighlightMode() == AIS2D_TOD_OBJECT )
2121 theIO->Highlight( ind );
2122
2123 DoDetectObject( theIO, theDrawer );
2124
2125 } else theStat = AIS2D_SOD_Selected;
2126 }
2127 } // end for
2128 theDrawer->EndDraw();
2129 theDrawer->SetOverride( Standard_False );
2130 } else {
2131
2132 theStat = AIS2D_SOD_Nothing;
2133 theDrawer->RestoreArea( aView->Driver() );
2134 if ( !mySeqOfDetIO->IsEmpty() )
2135 for ( int i = 1; i<= mySeqOfDetIO->Length(); ++i ) {
2136 mySeqOfDetIO->Value(i)->Unhighlight();
2137 mySeqOfDetIO->Value(i)->ClearSeqDetPrim();
2138 }
2139 mySeqOfDetIO->Clear();
2140 is_main ? myMainVwr->Update() : myCollectorVwr->Update();
2141 } // end if PickList isn't empty
2142
2143
2144 return theStat;
2145}
2146
2147AIS2D_StatusOfPick AIS2D_InteractiveContext::Select( const Standard_Boolean UpdateVwr ) {
2148
2149 if ( HasOpenedContext() )
2150 if ( myWasLastMain )
2151 return myLocalContexts(myCurLocalIndex)->Select(UpdateVwr);
2152 else {
2153 myLocalContexts( myCurLocalIndex )->SetSelected( myLastPicked, UpdateVwr );
2154 return AIS2D_SOP_OneSelected;
2155 }
6e6cd5d9 2156
7fd59977 2157 if ( ! mySeqOfDetIO->IsEmpty() ) {
2158 Handle(AIS2D_InteractiveObject) theIO;
2159 Handle(AIS2D_HSequenceOfPrimArchit) thePA;
2160
2161 switch ( myCurDetectMode ) {
2162 default :
2163 case AIS2D_TOD_OBJECT : {
2164 for ( int i = 1; i <= mySeqOfDetIO->Length(); ++i ) {
2165 theIO = mySeqOfDetIO->Value(i);
2166 if ( ! RectMoveTo ) {
2167 thePA = theIO->GetSelectedSeqPrim();
2168 if ( ! thePA->IsEmpty() ) {
2169 for ( int j = 1; j <= thePA->Length(); ++j )
2170 thePA->Value(j)->GetPrimitive()->Unhighlight();
2171 theIO->ClearSeqSelPrim();
2172 }
2173
2174 if ( ! mySeqOfSelIO->IsEmpty() )
2175 for ( int j = 1; j <= mySeqOfSelIO->Length(); ++j ) {
2176 Unhighlight( mySeqOfSelIO->Value(i), Standard_False );
2177 mySeqOfSelIO->Value(i)->SetState(0);
2178 mySeqOfSelIO->Remove(i);
2179 }
2180 }
2181 if ( ! theIO->State() ) {
2182 SetCurrentObject( theIO, Standard_False );
2183 mySeqOfSelIO->Append(theIO);
2184 }
2185 }
2186 theIO->ClearSeqDetPrim();
2187 }
2188 break;
2189
2190 case AIS2D_TOD_PRIMITIVE:
2191 {
2192 for ( int i = 1; i <= mySeqOfDetIO->Length(); ++i )
2193 {
2194 Standard_Integer j;
2195
2196 theIO = mySeqOfDetIO->Value(i);
2197 theIO->Highlight(myMainVwr->InitializeColor(mySelectionColor));
2198 theIO->Unhighlight();
2199 theIO->SetState(1);
2200
2201 // unselect selected
2202 if ( !RectMoveTo )
2203 {
2204
2205 thePA = theIO->GetSelectedSeqPrim();
2206 for ( j = 1; j <= thePA->Length(); ++j )
2207 {
2208 thePA->Value(j)->GetPrimitive()->Unhighlight();
2209 }
2210 theIO->ClearSeqSelPrim();
2211
2212 for ( j = 1; j <= mySeqOfSelIO->Length(); ++j )
2213 {
2214 // by EAV: 12.09.01
2215 // Unhighlight( mySeqOfSelIO->Value(j), Standard_False );
2216 mySeqOfSelIO->Value(j)->SetState( 0 );
2217 mySeqOfSelIO->Remove(j);
2218 }
2219 }
2220
2221 // select detected
2222 thePA = theIO->GetDetectSeqPrim();
2223 for ( j = 1; j <= thePA->Length(); ++j )
2224 {
2225 Handle(Graphic2d_Primitive) thePrim = thePA->Value(j)->GetPrimitive();
2226 if ( !thePrim ->IsHighlighted() ) {
2227 thePrim->Highlight();
2228 theIO->AddSelectPrim( thePrim, 0 );
2229 }
2230 }
2231 if ( ! IsIOSelected( theIO ) )
2232 mySeqOfSelIO->Append( mySeqOfDetIO->Value(i) );
2233
2234 } // end for
2235#ifndef OCC146
2236 theIO->ClearSeqDetPrim();
2237#endif
2238 }
2239 break;
2240 case AIS2D_TOD_ELEMENT: {
2241 Standard_Integer theInd;
2242 for ( int i = 1; i <= mySeqOfDetIO->Length(); ++i ) {
2243 theIO = mySeqOfDetIO->Value(i);
2244 theIO->Highlight(myMainVwr->InitializeColor(mySelectionColor));
2245 theIO->Unhighlight();
2246 theIO->SetState(1);
2247 if ( !RectMoveTo ) {
2248 thePA = theIO->GetSelectedSeqPrim();
2249 if ( ! thePA->IsEmpty() ) {
2250 for ( int j = 1; j <= thePA->Length(); ++j )
2251 thePA->Value(j)->GetPrimitive()->Unhighlight();
2252 theIO->ClearSeqSelPrim();
2253 }
2254 if ( ! mySeqOfSelIO->IsEmpty() )
2255 for ( int j = 1; j <= mySeqOfSelIO->Length(); ++j ) {
2256 Unhighlight( mySeqOfSelIO->Value(i), Standard_False );
2257 mySeqOfSelIO->Value(i)->SetState(0);
2258 mySeqOfSelIO->Remove(i);
2259 }
2260 }
2261 thePA = theIO->GetDetectSeqPrim();
2262 if ( ! thePA->IsEmpty() ) {
2263 Handle(Graphic2d_Primitive) thePrim;
2264 for ( int j = 1; j <= thePA->Length(); ++j ) {
2265 thePrim = thePA->Value(j)->GetPrimitive();
2266 theInd = thePA->Value(j)->GetIndex();
2267
2268 //SAV - marking that highlighted elements became selected
2269 // fixing regression of element single selection
2270 if ( !thePrim->SetElementsSelected() )
2271 thePrim->Highlight( theInd );
2272 else
2273 thePrim->Unhighlight();
2274 theIO->AddSelectPrim( thePrim, theInd );
2275 }
2276 }
2277 if ( ! IsIOSelected( theIO ) ) mySeqOfSelIO->Append(mySeqOfDetIO->Value(i));
2278 } // end for
2279#ifndef OCC146
2280 theIO->ClearSeqDetPrim();
2281#endif
2282 }
2283 break;
2284 case AIS2D_TOD_VERTEX: {
2285 Standard_Integer theInd;
2286 for ( int i = 1; i <= mySeqOfDetIO->Length(); ++i ) {
2287 theIO = mySeqOfDetIO->Value(i);
2288 theIO->Highlight(myMainVwr->InitializeColor(mySelectionColor));
2289 theIO->Unhighlight();
2290 theIO->SetState(1);
2291 if ( !RectMoveTo ) {
2292 thePA = theIO->GetSelectedSeqPrim();
2293 if ( ! thePA->IsEmpty() ) {
2294 for ( int j = 1; j <= thePA->Length(); ++j )
2295 thePA->Value(j)->GetPrimitive()->Unhighlight();
2296 theIO->ClearSeqSelPrim();
2297 }
2298 if ( ! mySeqOfSelIO->IsEmpty() )
2299 for ( int j = 1; j <= mySeqOfSelIO->Length(); ++j ) {
2300 Unhighlight( mySeqOfSelIO->Value(i), Standard_False );
2301 mySeqOfSelIO->Value(i)->SetState(0);
2302 mySeqOfSelIO->Remove(i);
2303 }
2304 }
2305 thePA = theIO->GetDetectSeqPrim();
2306 if ( ! thePA->IsEmpty() ) {
2307 Handle(Graphic2d_Primitive) thePrim;
2308 for ( int j = 1; j <= thePA->Length(); ++j ) {
2309 thePrim = thePA->Value(j)->GetPrimitive();
2310 theInd = thePA->Value(j)->GetIndex();
2311 thePrim->Highlight( theInd );
2312 theIO->AddSelectPrim( thePrim, theInd );
2313 }
2314 }
2315 if ( ! IsIOSelected( theIO ) ) mySeqOfSelIO->Append(mySeqOfDetIO->Value(i));
2316 } // end for
2317#ifndef OCC146
2318 theIO->ClearSeqDetPrim();
2319#endif
2320 }
2321 break;
2322 } // end switch
2323#ifndef OCC146
2324 mySeqOfDetIO->Clear();
2325#endif
2326 } else {
2327
2328 // if sequence of detected objects is empty
2329 if ( ! mySeqOfSelIO->IsEmpty() ) {
2330 switch ( myCurDetectMode ) {
2331 default :
2332 case AIS2D_TOD_OBJECT : {
2333 Handle(AIS2D_InteractiveObject) theIO;
2334 for ( int i = 1; i <= mySeqOfSelIO->Length(); ++i ) {
2335 theIO = mySeqOfSelIO->Value(i);
2336 theIO->Unhighlight();
2337 theIO->SetState(0);
2338 if ( myObjects.IsBound(theIO) )
2339 if ( myObjects(theIO)->IsSubIntensityOn() )
2340 HighlightWithColor( theIO, mySubIntensity, Standard_False );
2341 }
2342 }
2343 break;
2344 case AIS2D_TOD_PRIMITIVE: {
2345 Handle(AIS2D_InteractiveObject) theIO;
2346 Handle(AIS2D_HSequenceOfPrimArchit) thePA;
2347 for ( int i = 1; i <= mySeqOfSelIO->Length(); ++i ) {
2348 theIO = mySeqOfSelIO->Value(i);
2349 thePA = theIO->GetSelectedSeqPrim();
2350 theIO->Unhighlight();
2351 if ( ! thePA->IsEmpty() ) {
2352 for ( int j = 1; j <= thePA->Length(); ++j )
2353 thePA->Value(j)->GetPrimitive()->Unhighlight();
2354 theIO->ClearSeqSelPrim();
2355 }
2356 theIO->SetState(0);
2357 if ( myObjects.IsBound(theIO) )
2358 if ( myObjects(theIO)->IsSubIntensityOn() )
2359 HighlightWithColor( theIO, mySubIntensity, Standard_False );
2360 }
2361
2362 }
2363 break;
2364 case AIS2D_TOD_ELEMENT: {
2365 Handle(AIS2D_InteractiveObject) theIO;
2366 Handle(AIS2D_HSequenceOfPrimArchit) thePA;
2367 for ( int i = 1; i <= mySeqOfSelIO->Length(); ++i ) {
2368 theIO = mySeqOfSelIO->Value(i);
2369 thePA = theIO->GetSelectedSeqPrim();
2370 theIO->Unhighlight();
2371 if ( ! thePA->IsEmpty() ) {
2372 for ( int j = 1; j <= thePA->Length(); ++j ) {
2373 thePA->Value(j)->GetPrimitive()->Unhighlight();
2374 // SAV - unselecting sub primitives
2375 thePA->Value(j)->GetPrimitive()->ClearSelectedElements();
2376 }
2377 theIO->ClearSeqSelPrim();
2378 }
2379 theIO->SetState(0);
2380 if ( myObjects.IsBound(theIO) )
2381 if ( myObjects(theIO)->IsSubIntensityOn() )
2382 HighlightWithColor( theIO, mySubIntensity, Standard_False );
2383 }
2384 }
2385 break;
2386 case AIS2D_TOD_VERTEX: {
2387 Handle(AIS2D_InteractiveObject) theIO;
2388 Handle(AIS2D_HSequenceOfPrimArchit) thePA;
2389 for ( int i = 1; i <= mySeqOfSelIO->Length(); ++i ) {
2390 theIO = mySeqOfSelIO->Value(i);
2391 thePA = theIO->GetSelectedSeqPrim();
2392 theIO->Unhighlight();
2393 if ( ! thePA->IsEmpty() ) {
2394 for ( int j = 1; j <= thePA->Length(); ++j )
2395 thePA->Value(j)->GetPrimitive()->Unhighlight();
2396 theIO->ClearSeqSelPrim();
2397 }
2398 theIO->SetState(0);
2399 if ( myObjects.IsBound(theIO) )
2400 if ( myObjects(theIO)->IsSubIntensityOn() )
2401 HighlightWithColor( theIO, mySubIntensity, Standard_False );
2402 }
2403 }
2404 break;
2405 } // end switch
2406 mySeqOfSelIO->Clear();
2407 } // end if sequence of detected objects isn't empty
2408
2409
2410 }
2411 if ( UpdateVwr ) myWasLastMain ? myMainVwr->Update() : UpdateCollector();
2412
2413 Standard_Integer NS = mySeqOfSelIO->Length();
2414 if ( !NS ) return AIS2D_SOP_NothingSelected;
2415 if ( NS == 1 ) return AIS2D_SOP_OneSelected;
2416
2417 return AIS2D_SOP_SeveralSelected;
2418
2419}
2420
2421AIS2D_StatusOfPick AIS2D_InteractiveContext::ShiftSelect( const Standard_Boolean UpdateVwr )
2422{
2423 if ( HasOpenedContext() ) {
2424 if ( myWasLastMain )
2425 return myLocalContexts( myCurLocalIndex )->ShiftSelect( UpdateVwr );
2426 else {
2427 myLocalContexts( myCurLocalIndex )->AddOrRemoveSelected( myLastPicked, UpdateVwr );
2428 Standard_Integer NS = mySeqOfSelIO->Length();
2429 if ( !NS ) return AIS2D_SOP_NothingSelected;
2430 if ( NS == 1 ) return AIS2D_SOP_OneSelected;
2431 return AIS2D_SOP_SeveralSelected;
2432 }
2433 } //end if opened local context exists
2434
2435 if ( myWasLastMain && !myLastinMain.IsNull() )
2436 AddOrRemoveCurObject( myLastinMain,UpdateVwr );
2437 else if ( !myWasLastMain && !myLastinColl.IsNull() )
2438 AddOrRemoveCurObject( myLastinColl, UpdateVwr );
2439
2440 Standard_Integer NS = mySeqOfSelIO->Length();
2441 if ( NS == 0 ) return AIS2D_SOP_NothingSelected;
2442 if ( NS == 1 ) return AIS2D_SOP_OneSelected;
2443 return AIS2D_SOP_SeveralSelected;
2444
2445}
2446
2447AIS2D_StatusOfPick AIS2D_InteractiveContext::ShiftSelect(
2448 const Standard_Integer /*XPMin*/,
2449 const Standard_Integer /*YPMin*/,
2450 const Standard_Integer /*XPMax*/,
2451 const Standard_Integer /*YPMax*/,
2452 const Handle(V2d_View)& /*aView*/,
2453 const Standard_Boolean /*UpdateVwr*/ )
2454{
2455/*
2456 if ( HasOpenedContext() )
2457 return myLocalContexts( myCurLocalIndex )->ShiftSelect( XPMin, YPMin, XPMax, YPMax, aView, UpdateVwr );
2458
2459 UnhighlightCurrent(Standard_False);
2460 // static Handle(StdSelect_ViewerSelector2d) aSelector;
2461
2462 if ( aView->Viewer() == myMainVwr) {
2463 // aSelector= myMainSelector;
2464 myWasLastMain = Standard_True;}
2465
2466 else if (aView->Viewer() == myCollectorVwr){
2467 // aSelector= myCollectorSel;
2468 myWasLastMain = Standard_False;}
2469 else
2470 return AIS2D_SOP_NothingSelected;
2471 aSelector->SetSensitivity( aView->Convert(mySensitivity) );
2472 aSelector->Pick( XPMin, YPMin, XPMax, YPMax, aView );
2473 AIS2D_Selection::SetCurrentSelection( myCurrentName.ToCString() );
2474 for ( aSelector->Init(); aSelector->More(); aSelector->Next() ) {
2475 const Handle(SelectMgr_SelectableObject)& SObj = aSelector->Picked()->Selectable();
2476 if ( !SObj.IsNull() ) {
2477 AIS2D_SelectStatus SelStat = AIS2D_Selection::Select(SObj);
2478 Standard_Integer mod = (SelStat == AIS2D_SS_Added) ? 1 : 0;
2479 ( * ( (Handle(AIS2D_InteractiveObject)* ) & SObj ) )->SetState(mod);
2480 }
2481 }
2482
2483 HighlightCurrent( UpdateVwr );
2484
2485 Standard_Integer NS = NbCurrents();
2486 if ( NS == 0 ) return AIS2D_SOP_NothingSelected;
2487 if ( NS == 1 ) return AIS2D_SOP_OneSelected;
2488 return AIS2D_SOP_SeveralSelected;
2489 */
2490 return AIS2D_SOP_NothingSelected;
2491}
2492
2493 Standard_Integer AIS2D_InteractiveContext::NbSelected() const
2494{
2495 if ( mySeqOfSelIO->IsEmpty() )
2496 return 0;
2497
2498 Standard_Integer nsel = 0;
2499 switch ( myCurDetectMode )
2500 {
2501 case AIS2D_TOD_ELEMENT:
2502 case AIS2D_TOD_VERTEX:
2503 case AIS2D_TOD_PRIMITIVE:
2504 {
2505 for ( int i = 1; i <= mySeqOfSelIO->Length(); ++i )
2506 {
2507 Handle( AIS2D_InteractiveObject ) io = mySeqOfSelIO->Value( i );
2508 if ( !io.IsNull() )
2509 nsel += io->GetSelectedSeqPrim()->Length();
2510 }
2511 break;
2512 }
2513 default :
2514 nsel = mySeqOfSelIO->Length(); break;
2515 }
2516 return nsel;
2517}
2518
2519 void AIS2D_InteractiveContext::InitSelected()
2520{
2521 myCurSelected = 1;
2522 myMaxSelected = NbSelected();
2523}
2524
2525Standard_Boolean AIS2D_InteractiveContext::MoreSelected() const
2526{
2527 return myCurSelected <= myMaxSelected;
2528}
2529
2530void AIS2D_InteractiveContext::NextSelected()
2531{
2532 myCurSelected++;
2533}
2534
2535Handle( MMgt_TShared ) AIS2D_InteractiveContext::SelectedObject() const
2536{
2537 switch ( myCurDetectMode )
2538 {
2539 case AIS2D_TOD_ELEMENT:
2540 case AIS2D_TOD_VERTEX:
2541 case AIS2D_TOD_PRIMITIVE:
2542 {
2543 Standard_Integer current = 0;
2544 for ( int i = 1; i <= mySeqOfSelIO->Length(); ++i )
2545 {
2546 Handle( AIS2D_InteractiveObject ) io = mySeqOfSelIO->Value( i );
2547 if ( !io.IsNull() )
2548 {
2549 Standard_Integer l = io->GetSelectedSeqPrim()->Length();
2550 if ( myCurSelected <= current + l )
2551 {
2552 return io->GetSelectedSeqPrim()->Value( myCurSelected - current )->GetPrimitive();
2553 }
2554 current += l;
2555 }
2556 }
2557 break;
2558 }
2559 default: break;
2560 }
2561 return mySeqOfSelIO->Value( myCurSelected );
2562}
2563
2564// *******************************************************************************
2565// Immediate Mode Management
2566// *******************************************************************************
2567
2568void AIS2D_InteractiveContext::BeginImmediateDraw( const Handle(V2d_View)& aView ) {
2569
2570 Handle(V2d_Viewer) theViewer = aView->Viewer();
2571 Handle(Graphic2d_TransientManager) theDrawer =
2572 Handle(Graphic2d_TransientManager)::DownCast( theViewer->View()->Drawer() );
2573 theDrawer->BeginDraw( aView->Driver() );
2574
2575}
2576
2577void AIS2D_InteractiveContext::ImmediateDraw( const Handle(AIS2D_InteractiveObject)& anIObj,
2578 const Handle(V2d_View)& aView ) {
2579
2580 Handle(V2d_Viewer) theViewer = aView->Viewer();
2581 Handle(Graphic2d_TransientManager) theDrawer =
2582 Handle(Graphic2d_TransientManager)::DownCast( theViewer->View()->Drawer() );
2583 theDrawer->Draw( anIObj );
2584
2585}
2586
2587void AIS2D_InteractiveContext::EndImmediateDraw( const Handle(V2d_View)& aView ) {
2588 Handle(V2d_Viewer) theViewer = aView->Viewer();
2589 Handle(Graphic2d_TransientManager) theDrawer =
2590 Handle(Graphic2d_TransientManager)::DownCast( theViewer->View()->Drawer() );
2591 theDrawer->EndDraw();
2592}
2593
2594Standard_Boolean AIS2D_InteractiveContext::IsImmediateModeOn(const Handle(V2d_View)& /*aView*/) const {
2595return Standard_False;
2596}
2597
2598//SAV
2599void AIS2D_InteractiveContext::SetDetectionMode( const AIS2D_TypeOfDetection mode )
2600{
2601 myCurDetectMode = mode;
2602}