1 #define IMP140901 //GG 14/09/01 goback to avoid a regression
4 // SAV 14/11/01 - modification for detection/highlighting/selection elements of
5 // SetOf<>. Fully used for SetOfMarkers.
7 #define OCC197 // jfa 01/03/2002 // for multiple selection of elements
8 #define OCC146 // jfa 01/03/2002 // for single selection two times
9 #define OCC154 // jfa 06/03/2002 // for correct erasing
10 #define OCC389 // vro 19/06/2002 // for Display(obj,dispMode...) setting a view for the IO
12 #include <Standard_Stream.hxx>
14 #include <AIS2D_InteractiveContext.ixx>
15 #include <Aspect_ColorMap.hxx>
16 #include <Aspect_GenericColorMap.hxx>
17 #include <Aspect_FontMap.hxx>
18 #include <Aspect_MarkMap.hxx>
19 #include <Aspect_TypeMap.hxx>
20 #include <Aspect_WidthMap.hxx>
21 #include <Aspect_FontStyle.hxx>
22 #include <Aspect_LineStyle.hxx>
23 #include <Aspect_TypeOfMarker.hxx>
24 #include <Aspect_TypeOfLine.hxx>
25 #include <Aspect_WidthOfLine.hxx>
26 #include <Aspect_ColorMapEntry.hxx>
27 #include <Aspect_TypeMapEntry.hxx>
28 #include <Aspect_WidthMapEntry.hxx>
29 #include <Aspect_FontMapEntry.hxx>
30 #include <Aspect_MarkMapEntry.hxx>
31 #include <gp_GTrsf2d.hxx>
32 #include <gp_Trsf2d.hxx>
34 #include <Graphic2d_Primitive.hxx>
35 #include <Graphic2d_SequenceOfPrimitives.hxx>
37 #include <Graphic2d_View.hxx>
38 #include <Graphic2d_DisplayList.hxx>
39 #include <V2d_View.hxx>
40 #include <Prs2d_Point.hxx>
41 #include <Prs2d_Drawer.hxx>
42 #include <Prs2d_AspectLine.hxx>
44 #include <TColStd_ListIteratorOfListOfInteger.hxx>
45 #include <TColStd_MapIteratorOfMapOfTransient.hxx>
46 #include <TColStd_MapOfTransient.hxx>
47 #include <TColStd_HSequenceOfInteger.hxx>
48 #include <AIS2D_DataMapIteratorOfDataMapOfLC.hxx>
49 #include <AIS2D_DataMapIteratorOfDataMapOfIOStatus.hxx>
50 #include <AIS2D_ListIteratorOfListOfIO.hxx>
51 #include <AIS2D_PrimitiveArchit.hxx>
52 #include <AIS2D_HSequenceOfPrimArchit.hxx>
53 #include <AIS2D_GlobalStatus.hxx>
54 #include <AIS2D_LocalStatus.hxx>
55 #include <AIS2D_LocalContext.hxx>
56 #include <AIS2D_ProjShape.hxx>
59 #include <TColStd_MapOfInteger.hxx>
60 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
62 static TColStd_ListIteratorOfListOfInteger ItL;
63 static Standard_Boolean RectMoveTo = Standard_False;
65 AIS2D_InteractiveContext::AIS2D_InteractiveContext(const Handle(V2d_Viewer)& MainViewer):
67 myMainVwr( MainViewer ),
68 myDetectPrecision( 4 ),
69 myResetDetect( Standard_True ),
73 mySeqOfDetIO( new AIS2D_HSequenceOfIO() ),
74 mySeqOfSelIO( new AIS2D_HSequenceOfIO() ),
75 myCurDetectMode( AIS2D_TOD_NONE ),
77 myPickMode( Graphic2d_PM_INCLUDE ),
78 myHighlightColor( Quantity_NOC_CYAN1 ),
79 mySelectionColor( Quantity_NOC_GRAY80 ),
80 mySubIntensity( Quantity_NOC_GRAY40 ),
89 myMainVwr->View()->SetDefaultOverrideColor( myMainVwr->InitializeColor( mySelectionColor ) );
92 AIS2D_InteractiveContext::AIS2D_InteractiveContext(const Handle(V2d_Viewer)& MainViewer,const Handle(V2d_Viewer)& aCollector):
94 myMainVwr( MainViewer ),
96 myCollectorVwr( aCollector ),
97 myIsCollClosed( Standard_False ),
98 myDetectPrecision( 4 ),
99 myResetDetect( Standard_True ),
103 mySeqOfDetIO( new AIS2D_HSequenceOfIO() ),
104 mySeqOfSelIO( new AIS2D_HSequenceOfIO() ),
105 myCurDetectMode( AIS2D_TOD_NONE ),
107 myPickMode( Graphic2d_PM_INCLUDE ),
108 myHighlightColor( Quantity_NOC_CYAN1 ),
109 mySelectionColor( Quantity_NOC_GRAY80 ),
110 mySubIntensity( Quantity_NOC_GRAY40 ),
113 myCurLocalIndex( 0 ),
116 myMainVwr->View()->SetDefaultOverrideColor( myMainVwr->InitializeColor( mySelectionColor ) );
117 myCollectorVwr->View()->SetDefaultOverrideColor( myMainVwr->InitializeColor( mySelectionColor ) );
121 //*************************************************************
122 // Management of the Trash Bin Viewer
123 // *************************************************************
125 void AIS2D_InteractiveContext::OpenCollector() {
126 myIsCollClosed = Standard_False;
130 // *************************************************************
131 // Editing general Display Services
132 // *************************************************************
134 void AIS2D_InteractiveContext::Display( const Handle(AIS2D_InteractiveObject)& anIObj,
135 const Standard_Boolean UpdateVwr ) {
137 if ( anIObj.IsNull() ) return;
139 Standard_Integer DispMode, SelMode;
140 AIS2D_TypeOfDetection HiMod;
141 Standard_Boolean UpdateCol;
142 Handle( AIS2D_GlobalStatus ) GStatus;
144 GetDefModes( anIObj, DispMode, HiMod, SelMode );
146 if ( !anIObj->HasInteractiveContext() )
147 anIObj->SetContext( this );
149 anIObj->SetView( myMainVwr->View() );
151 if ( !HasOpenedContext() ) {
153 if ( IsDisplayed( anIObj ) ) return;
154 UpdateCol = Standard_False;
156 if ( !myObjects.IsBound( anIObj ) ) {
158 GStatus = new AIS2D_GlobalStatus( AIS2D_DS_Displayed, DispMode, 0);
159 myObjects.Bind( anIObj, GStatus );
160 DrawObject( anIObj, DispMode ) ;
164 GStatus = myObjects( anIObj );
165 switch ( GStatus->GraphicStatus() ) {
167 case AIS2D_DS_Erased: {
169 if ( GStatus->IsHighlight() )
170 UpdateCol = UpdateVwr ;
172 case AIS2D_DS_FullErased: {
174 for ( ItL.Initialize( * GStatus -> DisplayedModes()); ItL.More(); ItL.Next())
175 if ( GStatus->IsSubIntensityOn() ) {
176 // Standard_Integer indCol = myMainVwr->InitializeColor(mySubIntensity);
177 // myMainPM->SetHighlightColor(indCol);
178 // myMainPM->ColorHighlight( anIObj, indCol, ItL.Value() );
181 for ( ItL.Initialize( * GStatus -> SelectionModes() ); ItL.More();ItL.Next() )
182 // mySelectorMgr->Activate( anIObj, ItL.Value(), myMainSelector );
183 GStatus->SetGraphicStatus( AIS2D_DS_Displayed );
184 if ( GStatus->IsHighlight() )
185 Highlight( anIObj, HiMod );
191 } //endif !myObjects.IsBound
195 if ( UpdateCol && !myCollectorVwr.IsNull() ) myCollectorVwr->UpdateNew();
199 myLocalContexts( myCurLocalIndex )->Display( anIObj, DispMode, Standard_True,SelMode );
201 }//endif !HasOpenedContext
203 if ( UpdateVwr ) myMainVwr->UpdateNew();
207 void AIS2D_InteractiveContext::Display(
208 const Handle(AIS2D_InteractiveObject)& anIObj,
209 const Standard_Integer aDispMode,
210 const Standard_Integer aSelectMode,
211 const Standard_Boolean UpdateVwr,
212 const Standard_Boolean AllowDecomp) {
214 if ( anIObj.IsNull() ) return;
215 if ( !anIObj->HasInteractiveContext() ) anIObj->SetContext(this);
218 anIObj->SetView(myMainVwr->View());
221 if ( !HasOpenedContext() ) {
223 if ( !anIObj->HasDisplayMode() )
224 anIObj->SetDisplayMode(aDispMode);
226 if ( !myObjects.IsBound(anIObj) ) {
227 Handle(AIS2D_GlobalStatus) GStatus=
228 new AIS2D_GlobalStatus( AIS2D_DS_Displayed, aDispMode, aSelectMode );
229 myObjects.Bind( anIObj, GStatus );
230 DrawObject( anIObj, aDispMode );
232 if ( aSelectMode != -1 ) {
233 //if ( !mySelectorMgr->Contains( anIObj ) )
234 // mySelectorMgr->Load( anIObj, myMainSelector,aSelectMode );
235 //mySelectorMgr->Activate( anIObj, aSelectMode, myMainSelector );
238 anIObj->SetSelectionMode(aSelectMode);
242 Handle(AIS2D_GlobalStatus) GStatus = myObjects( anIObj );
243 if ( !GStatus->IsDModeIn( aDispMode ) ) {
244 DrawObject( anIObj, aDispMode );
245 GStatus->AddDisplayMode( aDispMode );
246 if ( GStatus->IsSubIntensityOn() ) {
248 Standard_Integer indCol = myMainVwr->InitializeColor(mySubIntensity);
249 //myMainPM->SetHighlightColor( indCol );
250 //myMainPM->ColorHighlight( anIObj, indCol, aDispMode );
254 if ( aSelectMode != -1 ) {
255 GStatus->AddSelectionMode( aSelectMode );
256 //mySelectorMgr->Activate( anIObj, aSelectMode, myMainSelector );
263 myLocalContexts(myCurLocalIndex)->Display( anIObj, aDispMode, AllowDecomp, aSelectMode);
265 if (UpdateVwr) myMainVwr->Update();
269 void AIS2D_InteractiveContext::Redisplay( const Handle(AIS2D_InteractiveObject)& anIObj,
270 const Standard_Boolean updateVwr,
271 const Standard_Boolean /*allModes*/ ) {
273 if ( anIObj.IsNull() ) return;
274 //anIObj->Update(allModes);
277 if ( HasOpenedContext() )
280 if ( myObjects.IsBound( anIObj ) ) {
281 switch ( myObjects(anIObj)->GraphicStatus() ) {
282 case AIS2D_DS_Displayed:
283 DrawObject( anIObj, 0 );
286 case AIS2D_DS_Erased:
287 if ( !myCollectorVwr.IsNull() )
288 myCollectorVwr->Update();
298 void AIS2D_InteractiveContext::Load(
299 const Handle(AIS2D_InteractiveObject)& anIObj,
300 const Standard_Integer SelMode,
301 const Standard_Boolean AllowDecomp) {
303 if ( anIObj.IsNull() ) return;
304 if ( !anIObj->HasInteractiveContext() ) anIObj->SetContext( this );
306 if ( !HasOpenedContext() ) {
307 if ( SelMode == -1 && !AllowDecomp ) {
308 Standard_Integer DispMode;
309 AIS2D_TypeOfDetection HiMod;
310 Standard_Integer selMode = SelMode;
312 GetDefModes( anIObj, DispMode, HiMod, selMode );
313 Handle(AIS2D_GlobalStatus) GStatus=
314 new AIS2D_GlobalStatus( AIS2D_DS_FullErased, DispMode, selMode );
315 myObjects.Bind( anIObj,GStatus );
319 //endif !HasOpenedContext
320 myLocalContexts(myCurLocalIndex)->Load( anIObj, AllowDecomp, SelMode);
323 void AIS2D_InteractiveContext::Erase(
324 const Handle(AIS2D_InteractiveObject)& anIObj,
325 const Standard_Boolean UpdateVwr,
326 const Standard_Boolean /*PutInCollector*/) {
328 if ( anIObj.IsNull() ) return;
330 if ( !HasOpenedContext() )
334 if (myObjects.IsBound(anIObj))
335 myObjects(anIObj)->SetGraphicStatus(AIS2D_DS_Erased);
340 if ( UpdateVwr ) myMainVwr->UpdateNew();
344 void AIS2D_InteractiveContext::EraseAll (const Standard_Boolean /*PutInCollector*/,
345 const Standard_Boolean UpdateVwr)
347 if ( !HasOpenedContext() )
350 myMainVwr->View()->Erase();
351 AIS2D_DataMapIteratorOfDataMapOfIOStatus anItr (myObjects);
352 for (; anItr.More(); anItr.Next())
354 anItr.Value()->SetGraphicStatus(AIS2D_DS_Erased);
358 myMainVwr->View()->Remove();
360 if ( UpdateVwr ) myMainVwr->Update();
363 void AIS2D_InteractiveContext::DisplayAll (const Standard_Boolean /*OnlyFromCollector*/,
364 const Standard_Boolean /*updateVwr*/) {
368 void AIS2D_InteractiveContext::EraseSelected (const Standard_Boolean PutInCollector,
369 const Standard_Boolean UpdateVwr) {
370 if ( !HasOpenedContext() ) {
371 Standard_Boolean found = Standard_False;
372 if ( mySeqOfSelIO->IsEmpty() ) return;
373 for ( int i = 1; i <= mySeqOfSelIO->Length(); ++i )
374 Erase( mySeqOfSelIO->Value(i), Standard_False, PutInCollector );
375 found = Standard_True;
376 if ( found && UpdateVwr ) {
378 if ( PutInCollector && !myCollectorVwr.IsNull() )
379 myCollectorVwr->Update();
385 void AIS2D_InteractiveContext::DisplaySelected( 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 Display( mySeqOfSelIO->Value(i), Standard_False );
392 found = Standard_True;
394 if ( found && updateVwr ) {
396 if ( !(myIsCollClosed && myCollectorVwr.IsNull()) )
397 myCollectorVwr->Update();
403 Standard_Boolean AIS2D_InteractiveContext::KeepTemporary( const Handle(AIS2D_InteractiveObject)& anIObj,
404 const Standard_Integer WhichContext ) {
406 if ( anIObj.IsNull() ) return Standard_False;
408 if ( !HasOpenedContext() ) return Standard_False;
409 if ( myObjects.IsBound(anIObj) ) return Standard_False;
410 if ( WhichContext != -1 && !myLocalContexts.IsBound(WhichContext) ) return Standard_False;
412 Standard_Integer IsItInLocal = myCurLocalIndex;
413 Standard_Boolean Found( Standard_False );
415 while ( IsItInLocal > 0 && !Found ) {
416 if ( !myLocalContexts.IsBound( IsItInLocal ) )
418 else if ( myLocalContexts(IsItInLocal)->IsIn( anIObj ) )
419 Found = Standard_True;
424 if ( !Found ) return Standard_False;
426 Handle(AIS2D_LocalStatus) LS = myLocalContexts(IsItInLocal)->Status(anIObj);
429 if ( LS->IsTemporary() ){
430 Standard_Integer DM,SM;
431 AIS2D_TypeOfDetection HM;
432 GetDefModes( anIObj, DM, HM, SM );
434 SM = LS->SelectionModes()->IsEmpty() ? SM : LS->SelectionModes()->First();
435 if (LS->DisplayMode() != DM ) {
436 Standard_Integer LSM = LS->SelectionModes()->IsEmpty() ? -1 : LS->SelectionModes()->First();
437 myLocalContexts(IsItInLocal)->Display(anIObj,DM,LS->Decomposed(),LSM);
440 Handle(AIS2D_GlobalStatus) GS = new AIS2D_GlobalStatus( AIS2D_DS_Displayed,
441 DM, SM, Standard_False);
442 myObjects.Bind( anIObj, GS );
444 LS->SetTemporary(Standard_False);
446 return Standard_True;
449 Standard_Boolean AIS2D_InteractiveContext::IsSelected(const Handle(AIS2D_InteractiveObject)& anIObj) const {
451 if ( anIObj.IsNull() ) return Standard_False;
452 if ( !HasOpenedContext() )
453 return ( anIObj->State() == 1 );
455 return myLocalContexts(myCurLocalIndex)->IsSelected(anIObj);
458 Standard_Boolean AIS2D_InteractiveContext::IsCurrent(const Handle(AIS2D_InteractiveObject)& anIObj) const {
460 if ( anIObj.IsNull() ) return Standard_False;
461 return ( anIObj->State() );
464 Standard_Integer AIS2D_InteractiveContext::OpenLocalContext( const Standard_Boolean UseDispObj,
465 const Standard_Boolean AllowDecomposit,
466 const Standard_Boolean AcceptEraseOfObj ) {
467 if ( !IsCurrent( myLastPicked ) )
468 if ( !myLastPicked.IsNull() ) {
470 AIS2D_TypeOfDetection HiMod = myLastPicked -> HasHighlightMode() ?
471 myLastPicked->HighlightMode() : myLastPicked->DefaultHighlightMode();
473 myLastPicked->Unhighlight();
476 if ( !myLastMoveView.IsNull() )
477 if ( myCurLocalIndex > 0 )
478 myLocalContexts( myCurLocalIndex )->UnhighLastDetect( myLastMoveView );
480 myLastinMain.Nullify();
481 myLastinColl.Nullify();
482 myLastPicked.Nullify();
483 myWasLastMain = Standard_True;
485 // Standard_Integer untilNow = myCurLocalIndex;
487 myCurLocalIndex = HighestIndex() + 1;
489 Handle(AIS2D_LocalContext) NewLocal= new AIS2D_LocalContext(this,
495 myLocalContexts.Bind( myCurLocalIndex, NewLocal );
498 if ( AllowDecomposit )
499 cout<<"\t\tDecomposition Authorized for Loaded Shapes"<<endl;
501 cout<<"\t\tNo Decomposition Authorized for Loaded Shapes"<<endl;
503 cout<<"\t\tNo Objects Were Loaded "<<endl;
505 return myCurLocalIndex;
509 void AIS2D_InteractiveContext::CloseLocalContext( const Standard_Integer ind,
510 const Standard_Boolean updateVwr ) {
512 Standard_Integer GoodIndex = ( ind == -1 ) ? myCurLocalIndex : ind;
513 if ( !HasOpenedContext() ) return;
514 if ( !myLocalContexts.IsBound(GoodIndex) ) return;
516 if ( myLocalContexts.Extent() == 1 && GoodIndex == myCurLocalIndex ) {
518 myLocalContexts(myCurLocalIndex)->Terminate();
519 myLocalContexts.UnBind(myCurLocalIndex);
522 ResetOriginalState(Standard_False);
526 myLocalContexts(GoodIndex)->Terminate();
527 myLocalContexts.UnBind(GoodIndex);
529 if ( GoodIndex == myCurLocalIndex ) {
530 myCurLocalIndex = HighestIndex();
532 const Handle(AIS2D_LocalContext)& LocCtx = myLocalContexts(myCurLocalIndex);
538 if ( updateVwr ) myMainVwr->Update();
542 Standard_Integer AIS2D_InteractiveContext::IndexOfCurrentLocal() const {
543 return myCurLocalIndex;
546 void AIS2D_InteractiveContext::CloseAllContext( const Standard_Boolean /*updateVwr*/ ) {
552 void AIS2D_InteractiveContext::SetCurrentObject( const Handle(AIS2D_InteractiveObject)& anIObj,
553 const Standard_Boolean UpdateVwr ) {
555 if ( anIObj.IsNull() ) return;
557 /*if ( NbCurrents() == 1 && anIObj->State() == 1 ) {
558 Quantity_NameOfColor HiCol;
559 Standard_Boolean HasHiCol;
560 if ( IsHighlighted( anIObj, HasHiCol, HiCol ) )
561 if ( HasHiCol && HiCol != mySelectionColor )
562 Highlight( anIObj, UpdateVwr );
566 if ( !HasOpenedContext() ) {
567 if ( !myObjects.IsBound(anIObj) )
568 HighlightWithColor( anIObj, mySelectionColor, Standard_False );
571 Quantity_NameOfColor HiCol;
572 Standard_Boolean HasHiCol;
573 if ( IsHighlighted( anIObj, HasHiCol, HiCol ) ) {
574 if ( HasHiCol && HiCol != mySelectionColor )
575 Highlight( anIObj,UpdateVwr );
577 Highlight( anIObj, UpdateVwr );
580 // UpdateCurrentViewer();
585 void AIS2D_InteractiveContext::AddOrRemoveCurObject( const Handle(AIS2D_InteractiveObject)& anIObj,
586 const Standard_Boolean UpdateVwr ) {
589 if ( !HasOpenedContext() ) {
590 if ( anIObj.IsNull() ) return;
592 switch ( anIObj->HighlightMode() ) {
594 case AIS2D_TOD_OBJECT: {
595 if ( IsIOSelected( anIObj ) ) {
596 Unhighlight( anIObj, Standard_False );
597 anIObj->SetState( 0 );
598 for ( int i = 1; i <= mySeqOfSelIO->Length(); ++i )
599 if ( mySeqOfSelIO->Value(i) == anIObj ) {
600 mySeqOfSelIO->Remove(i);
604 anIObj->SetState( 1 );
605 Highlight( anIObj, Standard_False );
606 mySeqOfSelIO->Append(anIObj);
610 case AIS2D_TOD_PRIMITIVE: {
611 Standard_Boolean found = Standard_False;
612 Handle(AIS2D_HSequenceOfPrimArchit) thePA;
613 Handle(Graphic2d_Primitive) thePrim = anIObj->Primitive(anIObj->PickedIndex());
614 thePA = anIObj->GetSelectedSeqPrim();
615 for ( int i = 1; i <= thePA->Length(); ++i )
616 if ( thePA->Value(i)->GetPrimitive() == thePrim ) {
617 //thePrim->Unhighlight();
618 Unhighlight( anIObj, Standard_False );
620 found = Standard_True;
624 Highlight( anIObj, Standard_False );
625 thePrim->Highlight();
626 anIObj->AddSelectPrim( thePrim, 0 );
627 if ( ! IsIOSelected( anIObj ) ) {
628 mySeqOfSelIO->Append(anIObj);
629 anIObj->SetState( 1 );
634 case AIS2D_TOD_ELEMENT:{
635 Standard_Boolean found = Standard_False;
636 Handle(AIS2D_HSequenceOfPrimArchit) thePA;
637 Handle(Graphic2d_Primitive) thePrim = anIObj->Primitive(anIObj->PickedIndex());
638 Standard_Integer ind = thePrim->PickedIndex();
639 thePA = anIObj->GetSelectedSeqPrim();
640 for ( int i = 1; i <= thePA->Length(); ++i )
641 if ( thePA->Value(i)->GetPrimitive() == thePrim &&
642 thePA->Value(i)->GetIndex() == ind ) {
644 // unhighlight the element
645 // thePrim->Unhighlight(ind);
646 Handle(TColStd_HSequenceOfInteger) aHiInds = thePrim->HighlightIndices();
647 for (int k = 1; k <= aHiInds->Length(); k++)
649 if (aHiInds->Value(k) == ind)
655 // unhighlight entire object only if we remove last selected element of it
656 if (thePA->Length() == 1)
658 Unhighlight( anIObj, Standard_False );
660 found = Standard_True;
664 Highlight( anIObj, Standard_False );
665 thePrim->Highlight( ind );
666 anIObj->AddSelectPrim( thePrim, ind );
667 if ( ! IsIOSelected( anIObj ) ) {
668 mySeqOfSelIO->Append(anIObj);
669 anIObj->SetState( 1 );
674 case AIS2D_TOD_VERTEX: {
675 Standard_Boolean found = Standard_False;
676 Handle(AIS2D_HSequenceOfPrimArchit) thePA;
677 Handle(Graphic2d_Primitive) thePrim = anIObj->Primitive(anIObj->PickedIndex());
678 Standard_Integer ind = thePrim->PickedIndex();
679 thePA = anIObj->GetSelectedSeqPrim();
680 for ( int i = 1; i <= thePA->Length(); ++i )
681 if ( thePA->Value(i)->GetPrimitive() == thePrim &&
682 thePA->Value(i)->GetIndex() == ind ) {
684 // unhighlight the vertex
685 // thePrim->Unhighlight(ind);
686 Handle(TColStd_HSequenceOfInteger) aHiInds = thePrim->HighlightIndices();
687 for (int k = 1; k <= aHiInds->Length(); k++)
689 if (aHiInds->Value(k) == ind)
695 // unhighlight entire object only if we remove last selected vertex of it
696 if (thePA->Length() == 1)
698 Unhighlight( anIObj, Standard_False );
700 found = Standard_True;
704 Highlight( anIObj, Standard_False );
705 thePrim->Highlight( ind );
706 anIObj->AddSelectPrim( thePrim, ind );
707 if ( ! IsIOSelected( anIObj ) ) {
708 mySeqOfSelIO->Append(anIObj);
709 anIObj->SetState( 1 );
718 if ( UpdateVwr ) myWasLastMain ? myMainVwr->Update() : UpdateCollector();
720 if ( UpdateVwr ) UpdateCurrentViewer();
724 // cout<<"Nothing Done : Opened Local Context"<<endl;
729 void AIS2D_InteractiveContext::UpdateCurrent() {
734 void AIS2D_InteractiveContext::SetOkCurrent() {
738 /*Handle(AIS2D_InteractiveObject) AIS2D_InteractiveContext::FirstCurrentObject() {
739 Handle(AIS2D_InteractiveObject) IO ;
746 void AIS2D_InteractiveContext::HighlightCurrent(const Standard_Boolean UpdateVwr) {
747 if ( mySeqOfSelIO->IsEmpty() ) return;
748 Handle(AIS2D_InteractiveObject) IO;
749 AIS2D_TypeOfDetection theTOD;
750 for ( int i = 1; i <= mySeqOfSelIO->Length(); ++i ) {
751 IO = mySeqOfSelIO->Value(i);
752 theTOD = IO->HighlightMode();
753 if ( theTOD == AIS2D_TOD_OBJECT )
754 Highlight(IO,Standard_False);
755 else if ( theTOD == AIS2D_TOD_PRIMITIVE ||
756 theTOD == AIS2D_TOD_ELEMENT ||
757 theTOD == AIS2D_TOD_VERTEX ) {
758 Standard_Integer pLength = IO->PickList()->Length();
760 IO->Highlight(myMainVwr->InitializeColor( mySelectionColor ));
762 for ( int j = 1; j <= pLength; j++ )
763 IO->Primitive(IO->PickList()->Value(j))->Highlight();
768 UpdateCurrentViewer();
772 void AIS2D_InteractiveContext::UnhighlightCurrent(const Standard_Boolean UpdateVwr) {
773 if ( mySeqOfSelIO->IsEmpty() ) return;
774 for ( int i = 1; i <= mySeqOfSelIO->Length(); ++i ) {
775 Unhighlight( mySeqOfSelIO->Value(i), Standard_False );
776 mySeqOfSelIO->Value(i)->SetState(0);
779 UpdateCurrentViewer();
783 void AIS2D_InteractiveContext::ClearCurrent(const Standard_Boolean UpdateVwr) {
784 if ( mySeqOfSelIO->IsEmpty() ) return;
785 for ( int i = 1; i <= mySeqOfSelIO->Length(); ++i )
786 Unhighlight( mySeqOfSelIO->Value(i), Standard_False );
789 UpdateCurrentViewer();
792 void AIS2D_InteractiveContext::SetSelectedCurrent() {
796 // SAV - just appending object
797 void AIS2D_InteractiveContext::SetSelected( const Handle(AIS2D_InteractiveObject)& obj,
798 const Standard_Boolean update )
800 mySeqOfSelIO->Append( obj );
801 for( Standard_Integer i = 1; i <= obj->Length(); i++ )
802 obj->AddSelectPrim( obj->Primitive( i ), i );
805 void AIS2D_InteractiveContext::UpdateSelected( const Standard_Boolean UpdateVwr ) {
807 if ( !HasOpenedContext() ) {
810 myLocalContexts(myCurLocalIndex)->UpdateSelected( UpdateVwr );
813 void AIS2D_InteractiveContext::AddOrRemoveSelected(
814 const Handle(AIS2D_InteractiveObject)& anIObj,
815 const Standard_Boolean UpdateVwr ) {
817 if ( !anIObj->HasInteractiveContext() ) anIObj->SetContext(this);
818 if ( ! HasOpenedContext() )
819 AddOrRemoveCurObject( anIObj, UpdateVwr );
821 myLocalContexts(myCurLocalIndex)->AddOrRemoveSelected( anIObj, UpdateVwr);
825 void AIS2D_InteractiveContext::HighlightSelected( const Standard_Boolean UpdateVwr ) {
827 if ( !HasOpenedContext() ) {
828 if ( ! mySeqOfSelIO->IsEmpty() )
829 for ( int i = 1; i <= mySeqOfSelIO->Length(); ++i )
830 Highlight( mySeqOfSelIO->Value(i), Standard_False );
832 myLocalContexts(myCurLocalIndex)->UnhighlightPicked( UpdateVwr );
835 UpdateCurrentViewer();
838 void AIS2D_InteractiveContext::UnhighlightSelected( const Standard_Boolean UpdateVwr ) {
839 if ( !HasOpenedContext() ) {
840 if ( ! mySeqOfSelIO->IsEmpty() )
841 for ( int i = 1; i <= mySeqOfSelIO->Length(); ++i )
842 Unhighlight( mySeqOfSelIO->Value(i), Standard_False );
844 myLocalContexts(myCurLocalIndex)->UnhighlightPicked( UpdateVwr );
847 UpdateCurrentViewer();
850 void AIS2D_InteractiveContext::ClearSelected( const Standard_Boolean UpdateVwr ) {
851 if ( !HasOpenedContext() )
852 ClearCurrent( UpdateVwr );
854 myLocalContexts(myCurLocalIndex)->ClearSelected( UpdateVwr );
857 AIS2D_DisplayStatus AIS2D_InteractiveContext::DisplayStatus( const Handle(AIS2D_InteractiveObject)& anIObj ) const {
859 if ( anIObj.IsNull() ) return AIS2D_DS_None;
861 if ( myObjects.IsBound(anIObj))
862 return myObjects(anIObj)->GraphicStatus();
864 AIS2D_DataMapIteratorOfDataMapOfLC ItM(myLocalContexts);
865 for ( ; ItM.More(); ItM.Next() )
866 if ( ItM.Value()->IsIn(anIObj) )
867 return AIS2D_DS_Temporary;
869 return AIS2D_DS_None;
873 AIS2D_PToListOfInt AIS2D_InteractiveContext::DisplayedModes( const Handle(AIS2D_InteractiveObject)& anIObj ) const {
874 return myObjects(anIObj)->DisplayedModes();
877 Standard_Boolean AIS2D_InteractiveContext::IsDisplayed( const Handle(AIS2D_InteractiveObject)& anIObj ) const {
879 if ( anIObj.IsNull() ) return Standard_False;
881 if ( myObjects.IsBound(anIObj) )
882 if ( myObjects(anIObj)->GraphicStatus() == AIS2D_DS_Displayed )
883 return Standard_True;
885 AIS2D_DataMapIteratorOfDataMapOfLC ItM(myLocalContexts);
886 for ( ; ItM.More(); ItM.Next() )
887 if ( ItM.Value()->IsDisplayed(anIObj) ) return Standard_True;
889 return Standard_False;
893 Standard_Boolean AIS2D_InteractiveContext::IsDisplayed( const Handle(AIS2D_InteractiveObject)& /*anIObj*/,
894 const Standard_Integer /*aMode*/ ) const {
896 return Standard_False;
900 Standard_Boolean AIS2D_InteractiveContext::IsHighlighted( const Handle(AIS2D_InteractiveObject)& anIObj ) const {
902 if ( anIObj.IsNull() ) return Standard_False;
904 if (!HasOpenedContext()){
906 if (!anIObj->IsHighlighted()) return Standard_False;
908 if(!myObjects.IsBound(anIObj))
909 return Standard_False;
910 return myObjects(anIObj)->IsHighlight();
912 AIS2D_DataMapIteratorOfDataMapOfLC ItM(myLocalContexts);
913 for (;ItM.More();ItM.Next() ) {
914 if (ItM.Value()->IsHighlight(anIObj) )
915 return Standard_True;
917 return Standard_False;
922 Standard_Boolean AIS2D_InteractiveContext::IsHighlighted( const Handle(AIS2D_InteractiveObject)& anIObj,
923 Standard_Boolean& /*WithColor*/,
924 Quantity_NameOfColor& /*theHiCol*/ ) const {
925 if ( anIObj.IsNull() ) return Standard_False;
927 if ( !HasOpenedContext() ) {
929 if (!anIObj->IsHighlighted()) return Standard_False;
931 if ( !myObjects.IsBound(anIObj) )
932 return Standard_False;
933 return myObjects(anIObj)->IsHighlight();
935 AIS2D_DataMapIteratorOfDataMapOfLC ItM(myLocalContexts);
936 for ( ; ItM.More(); ItM.Next() )
937 if ( ItM.Value()->IsHighlight(anIObj) )
938 return Standard_True;
940 return Standard_False;
944 void AIS2D_InteractiveContext::SubIntensityOn(
945 const Handle(AIS2D_InteractiveObject)& anIObj,
946 const Standard_Boolean UpdateVwr) {
948 Standard_Integer indCol;
949 if ( !HasOpenedContext() ) {
950 if ( !myObjects.IsBound(anIObj) ) return;
951 const Handle(AIS2D_GlobalStatus) GStatus = myObjects(anIObj);
952 if ( GStatus->IsSubIntensityOn() ) return;
953 GStatus->SubIntensityOn();
954 Standard_Boolean UpdMain(Standard_False),UpdColl(Standard_False);
956 for (TColStd_ListIteratorOfListOfInteger It( * GStatus->DisplayedModes() ); It.More(); It.Next() ) {
957 if ( GStatus->GraphicStatus()==AIS2D_DS_Displayed) {
958 SetHighlightColor( mySubIntensity );
959 HighlightWithColor( anIObj, mySubIntensity );
960 UpdMain = Standard_True;
961 } else if ( GStatus->GraphicStatus()==AIS2D_DS_Erased ) {
962 indCol = myCollectorVwr->InitializeColor( mySubIntensity );
963 myCollectorVwr->View()->SetDefaultOverrideColor( indCol );
964 HighlightWithColor(anIObj, mySubIntensity );
965 UpdColl=Standard_True;
969 if ( UpdMain) myMainVwr->Update();
970 if ( UpdColl ) myCollectorVwr->Update();
973 if ( myObjects.IsBound(anIObj) ) {
974 const Handle(AIS2D_GlobalStatus)& GStatus = myObjects(anIObj);
975 GStatus->SubIntensityOn();
976 for ( ItL.Initialize( * GStatus->DisplayedModes() ); ItL.More(); ItL.Next() ) {
977 SetHighlightColor( mySubIntensity );
978 HighlightWithColor(anIObj, mySubIntensity );
981 myLocalContexts(myCurLocalIndex)->SubIntensityOn(anIObj);
983 if (UpdateVwr) myMainVwr->Update();
987 void AIS2D_InteractiveContext::SubIntensityOff(
988 const Handle(AIS2D_InteractiveObject)& anIObj,
989 const Standard_Boolean UpdateVwr) {
991 if ( !HasOpenedContext() ) {
992 if ( !myObjects.IsBound(anIObj) ) return;
993 const Handle(AIS2D_GlobalStatus)& GStatus = myObjects(anIObj);
994 if ( !GStatus->IsSubIntensityOn() ) return;
995 GStatus->SubIntensityOff();
996 Standard_Boolean UpdMain(Standard_False),UpdColl(Standard_False);
998 for ( TColStd_ListIteratorOfListOfInteger It( * GStatus->DisplayedModes() ); It.More() ;It.Next() ) {
999 if ( GStatus->GraphicStatus() != AIS2D_DS_Erased ) {
1000 Unhighlight( anIObj );
1001 UpdMain = Standard_True;
1003 Unhighlight( anIObj );
1004 UpdColl=Standard_True;
1008 Standard_Integer DM,SM;
1009 AIS2D_TypeOfDetection HM;
1010 GetDefModes(anIObj,DM,HM,SM);
1011 if ( IsIOSelected(anIObj) )
1012 Highlight(anIObj,HM);
1015 if ( UpdMain ) myMainVwr->Update();
1016 if ( UpdColl ) myCollectorVwr->Update();
1019 if ( myObjects.IsBound(anIObj) ) {
1020 const Handle(AIS2D_GlobalStatus)& GStatus = myObjects(anIObj);
1021 GStatus->SubIntensityOff();
1022 for (ItL.Initialize(* GStatus->DisplayedModes());ItL.More();ItL.Next())
1023 Unhighlight(anIObj);
1024 if (GStatus->IsHighlight())
1027 myLocalContexts(myCurLocalIndex)->SubIntensityOff(anIObj);
1028 if ( IsSelected(anIObj) )
1031 if ( UpdateVwr) myMainVwr->Update();
1035 Standard_Boolean AIS2D_InteractiveContext::IsInCollector( const Handle(AIS2D_InteractiveObject)& anIObj ) const {
1037 if ( anIObj.IsNull() )
1038 return Standard_False;
1040 if ( myObjects.IsBound(anIObj) )
1041 return ( myObjects( anIObj)->GraphicStatus() == AIS2D_DS_Erased );
1042 return Standard_False;
1045 void AIS2D_InteractiveContext::Status( const Handle(AIS2D_InteractiveObject)& anIObj,
1046 TCollection_ExtendedString& aStatus ) const {
1050 if ( anIObj.IsNull() ) return ;
1051 if ( myObjects.IsBound(anIObj) ) {
1052 aStatus += "\t ____________________________________________";
1053 aStatus += "\t| Known at Neutral Point:\n\tDisplayStatus:";
1054 const Handle(AIS2D_GlobalStatus)& theGStat = myObjects(anIObj);
1055 switch ( theGStat->GraphicStatus() ) {
1056 case AIS2D_DS_Displayed: {
1057 aStatus +="\t| -->Displayed\n";
1060 case AIS2D_DS_Erased: {
1061 aStatus +="\t| -->Erased\n";
1064 case AIS2D_DS_FullErased: {
1065 aStatus +="\t| -->Full Erased\n";
1069 case AIS2D_DS_Temporary:
1074 aStatus += "\t| Active Display Modes in the MainViewer :\n";
1075 for ( ItL.Initialize(*(theGStat->DisplayedModes()));
1076 ItL.More(); ItL.Next() ) {
1077 aStatus += "\t|\t Mode ";
1078 aStatus += TCollection_AsciiString(ItL.Value());
1081 if ( IsCurrent(anIObj) )
1082 aStatus +="\t| Current\n";
1083 //if ( IsSelected(anIObj) )
1084 // aStatus +="\t| Selected\n";
1086 aStatus += "\t| Active Selection Modes in the MainViewer :\n";
1087 for ( ItL.Initialize(*(theGStat->SelectionModes() ));
1088 ItL.More(); ItL.Next() ) {
1089 aStatus += "\t\t Mode ";
1090 aStatus += TCollection_AsciiString(ItL.Value());
1093 aStatus += "\t ____________________________________________";
1099 void AIS2D_InteractiveContext::UpdateCurrentViewer() {
1101 if ( !myMainVwr.IsNull() ) myMainVwr->UpdateNew();
1105 void AIS2D_InteractiveContext::UpdateCollector() {
1106 if ( !myCollectorVwr.IsNull() ) myCollectorVwr->UpdateNew();
1109 void AIS2D_InteractiveContext::DisplayedObjects (AIS2D_ListOfIO& aListOfIO,
1110 const Standard_Boolean OnlyFromNeutral) const
1112 AIS2D_DataMapIteratorOfDataMapOfIOStatus It( myObjects );
1114 if ( !HasOpenedContext() || OnlyFromNeutral ) {
1115 for ( ; It.More(); It.Next() )
1116 if ( It.Value()->GraphicStatus() == AIS2D_DS_Displayed )
1117 aListOfIO.Append( It.Key() );
1119 TColStd_MapOfTransient theMap;
1121 for ( ; It.More(); It.Next() ) {
1122 if ( It.Value()->GraphicStatus() == AIS2D_DS_Displayed )
1123 theMap.Add(It.Key());
1126 Standard_Integer NbDisp;
1127 for ( AIS2D_DataMapIteratorOfDataMapOfLC it1(myLocalContexts);
1128 it1.More(); it1.Next() ) {
1129 const Handle(AIS2D_LocalContext)& LC = it1.Value();
1130 NbDisp = LC->DisplayedObjects(theMap);
1133 Handle(AIS2D_InteractiveObject) curIO;
1134 Handle(Standard_Transient) Tr;
1135 for ( TColStd_MapIteratorOfMapOfTransient it2(theMap); it2.More(); it2.Next() ) {
1137 curIO = *((Handle(AIS2D_InteractiveObject)*) &Tr);
1138 aListOfIO.Append(curIO);
1143 void AIS2D_InteractiveContext::GetDefModes( const Handle(AIS2D_InteractiveObject)& anIObj,
1144 Standard_Integer& DispMode,
1145 AIS2D_TypeOfDetection& HiMode,
1146 Standard_Integer& SelMode) const {
1148 if ( anIObj.IsNull() ) return ;
1150 DispMode = anIObj->HasDisplayMode() ? anIObj->DisplayMode() : anIObj->DefaultDisplayMode();
1151 HiMode = anIObj->HasHighlightMode() ? anIObj->HighlightMode() : anIObj->DefaultHighlightMode();
1152 SelMode = anIObj->HasSelectionMode() ? anIObj->SelectionMode() : anIObj->DefaultSelectionMode();
1156 void AIS2D_InteractiveContext::EraseGlobal(
1157 const Handle(AIS2D_InteractiveObject)& anIObj,
1158 const Standard_Boolean /*UpdateVwr*/,
1159 const Standard_Boolean /*PutInCollector*/) {
1161 if ( anIObj.IsNull() ) return ;
1162 if ( !myObjects.IsBound( anIObj ) ) return;
1167 void AIS2D_InteractiveContext::SetHighlightColor( const Quantity_NameOfColor aCol ) {
1169 if ( myHighlightColor != aCol ) {
1170 myHighlightColor = aCol;
1171 Standard_Integer anIndex = myMainVwr->InitializeColor(aCol);
1172 myMainVwr->View()->SetDefaultOverrideColor( anIndex );
1176 void AIS2D_InteractiveContext::SetSelectionColor( const Quantity_NameOfColor aCol ) {
1178 if ( mySelectionColor != aCol ) {
1179 mySelectionColor = aCol;
1180 Standard_Integer anIndex = myMainVwr->InitializeColor(aCol);
1181 myMainVwr->View()->SetDefaultOverrideColor(anIndex);
1185 void AIS2D_InteractiveContext::SetSubIntensityColor( const Quantity_NameOfColor aCol ) {
1186 mySubIntensity = aCol;
1189 Standard_Integer AIS2D_InteractiveContext::HighestIndex() const {
1191 AIS2D_DataMapIteratorOfDataMapOfLC It( myLocalContexts );
1192 Standard_Integer HiInd = 0;
1193 for ( ; It.More(); It.Next() )
1194 HiInd = ( It.Key() > HiInd ) ? It.Key() : HiInd;
1199 Standard_Integer AIS2D_InteractiveContext::InitializeColor( const Quantity_Color& aColor ) {
1202 Handle(Aspect_ColorMap) colormap = myMainVwr->ColorMap();
1204 Handle(Aspect_GenericColorMap) colormap = myMainVwr->ColorMap();
1206 Standard_Integer size = colormap->Size();
1207 Standard_Integer indColor = colormap->AddEntry(aColor);
1208 if( size != colormap->Size() ) {
1209 myMainVwr->SetColorMap( colormap );
1215 Standard_Integer AIS2D_InteractiveContext::InitializeStyle( const Aspect_TypeOfLine aType ) {
1217 Handle(Aspect_TypeMap) typemap = myMainVwr->TypeMap();
1218 Standard_Integer size = typemap->Size();
1219 Standard_Integer indType = typemap->AddEntry(aType);
1220 if( size != typemap->Size() ) {
1221 myMainVwr->SetTypeMap( typemap );
1228 Standard_Integer AIS2D_InteractiveContext::InitializeWidth( const Aspect_WidthOfLine aWidth ) {
1230 Handle(Aspect_WidthMap) widthmap = myMainVwr->WidthMap();
1231 Standard_Integer size = widthmap->Size();
1232 Standard_Integer indWidth = widthmap->AddEntry(aWidth);
1233 if( size != widthmap->Size() ) {
1234 myMainVwr->SetWidthMap( widthmap );
1241 Standard_Integer AIS2D_InteractiveContext::InitializeMarker( const Aspect_TypeOfMarker aMark ) {
1243 Handle(Aspect_MarkMap) markmap = myMainVwr->MarkMap();
1244 Standard_Integer size = markmap->Size();
1245 Standard_Integer indMark = markmap->AddEntry(aMark);
1246 if( size != markmap->Size() ) {
1247 myMainVwr->SetMarkMap( markmap );
1254 Standard_Integer AIS2D_InteractiveContext::InitializeFont( const Aspect_FontStyle& aFont ) {
1256 Handle(Aspect_FontMap) fontmap = myMainVwr->FontMap();
1257 Standard_Integer size = fontmap->Size();
1258 Standard_Integer indFont = fontmap->AddEntry(aFont);
1259 if( size != fontmap->Size() ) {
1260 myMainVwr->SetFontMap( fontmap );
1266 void AIS2D_InteractiveContext::DrawObject( const Handle(AIS2D_InteractiveObject)& anIObj,
1267 const Standard_Integer aDispMode ) {
1269 if ( anIObj->IsKind(STANDARD_TYPE(AIS2D_ProjShape) ) ) {
1271 Handle(AIS2D_ProjShape) thePS = Handle(AIS2D_ProjShape)::DownCast(anIObj);
1272 Handle(Graphic2d_Line) theLines = thePS->GetPrimitives();
1273 Handle(Prs2d_AspectLine) theAspLine;
1275 if ( !anIObj->HasAspect(theLines) ) {
1276 Handle(Prs2d_AspectRoot) theAspRoot = anIObj->Attributes()->FindAspect(Prs2d_AN_LINE);
1277 theAspLine = Handle(Prs2d_AspectLine)::DownCast(theAspRoot);
1278 anIObj->SetAspect( theAspLine, theLines );
1281 theAspLine = Handle(Prs2d_AspectLine)::DownCast( anIObj->GetAspect(theLines) );
1284 Quantity_Color aColor;
1285 Aspect_TypeOfLine aType;
1286 Aspect_WidthOfLine aWidth;
1288 theAspLine->ValuesOfLine( aColor, aType, aWidth );
1290 Standard_Integer colorInd = theAspLine->ColorIndex();
1291 Standard_Integer typeInd = theAspLine->TypeIndex();
1292 Standard_Integer widthInd = theAspLine->WidthIndex();
1295 colorInd = InitializeColor( aColor );
1296 theLines->SetColorIndex( colorInd );
1300 typeInd = InitializeStyle( aType );
1301 theLines->SetTypeIndex( typeInd );
1305 widthInd = InitializeWidth( aWidth );
1306 theLines->SetWidthIndex( widthInd );
1309 if ( thePS->IsHLMode() ) {
1310 Handle(Graphic2d_Line) theHLines = thePS->GetHLPrimitives();
1311 theHLines->SetColorIndex( colorInd );
1312 theHLines->SetWidthIndex( widthInd );
1313 Standard_Integer theDashInd = InitializeStyle( Aspect_TOL_DASH );
1314 theHLines->SetTypeIndex( theDashInd );
1319 Handle(Graphic2d_Primitive) thePrim;
1321 for ( Standard_Integer i = 1; i <= anIObj->Length(); i++ ) {
1322 thePrim = anIObj->Primitive( i );
1323 thePrim->SetDisplayMode(aDispMode);
1324 if ( thePrim->IsKind(STANDARD_TYPE(Graphic2d_Line) ) ) {
1326 Handle(Graphic2d_Line) theLine = Handle(Graphic2d_Line)::DownCast(thePrim);
1327 Handle(Prs2d_AspectLine) theAspLine;
1329 if ( !anIObj->HasAspect(theLine) ) {
1330 Handle(Prs2d_AspectRoot) theAspRoot = anIObj->Attributes()->FindAspect(Prs2d_AN_LINE);
1331 theAspLine = Handle(Prs2d_AspectLine)::DownCast(theAspRoot);
1332 anIObj->SetAspect( theAspLine, theLine );
1335 theAspLine = Handle(Prs2d_AspectLine)::DownCast( anIObj->GetAspect(theLine) );
1338 Quantity_Color aColor;
1339 Aspect_TypeOfLine aType;
1340 Aspect_WidthOfLine aWidth;
1342 Quantity_Color aIntColor;
1343 Graphic2d_TypeOfPolygonFilling aTypeFill;
1344 Standard_Integer aTile;
1345 Standard_Boolean aDrawEdge;
1347 theAspLine->ValuesOfLine( aColor, aType, aWidth );
1348 theAspLine->ValuesOfPoly( aIntColor, aTypeFill, aTile, aDrawEdge );
1350 Standard_Integer colorInd = theAspLine->ColorIndex();
1351 Standard_Integer typeInd = theAspLine->TypeIndex();
1352 Standard_Integer widthInd = theAspLine->WidthIndex();
1353 Standard_Integer colorIntInd = theAspLine->InterColorIndex();
1356 colorInd = InitializeColor( aColor );
1357 theLine->SetColorIndex( colorInd );
1361 typeInd = InitializeStyle( aType );
1362 theLine->SetTypeIndex( typeInd );
1366 widthInd = InitializeWidth( aWidth );
1367 theLine->SetWidthIndex( widthInd );
1370 if ( !colorIntInd ) {
1371 colorIntInd = InitializeColor( aIntColor );
1372 theLine->SetInteriorColorIndex( colorIntInd );
1375 theLine->SetTypeOfPolygonFilling( aTypeFill );
1376 theLine->SetInteriorPattern( aTile );
1377 theLine->SetDrawEdge( aDrawEdge );
1379 if ( theLine->IsKind(STANDARD_TYPE(Prs2d_Point) ) ) {
1381 Handle(Prs2d_Point) thePnt = Handle(Prs2d_Point)::DownCast(theLine);
1382 thePnt->SetIndex( InitializeMarker( thePnt->Marker() ) );
1385 } // end if the kind of primitive is Graphic2d_Line
1387 } // end for exploration of the interactive object
1389 } // end if IO is AIS2D_ProjShape
1393 void AIS2D_InteractiveContext::ResetOriginalState(const Standard_Boolean /*updateviewer*/) {
1395 Standard_Boolean upd_main(Standard_False),upd_col(Standard_False);
1396 TColStd_ListIteratorOfListOfInteger itl;
1398 for (AIS_DataMapIteratorOfDataMapOfIOStatus it(myObjects);it.More();it.Next()){
1399 const Handle(AIS_InteractiveObject)& iobj = it.Key();
1400 const Handle(AIS_GlobalStatus)& STAT = it.Value();
1401 switch(STAT->GraphicStatus()){
1402 case AIS_DS_Displayed:{
1403 upd_main = Standard_True;
1405 // partie display...
1406 for(itl.Initialize(STAT->DisplayedModes());itl.More();itl.Next())
1407 myMainPM->Display(iobj,itl.Value());
1408 if(STAT->IsHilighted()){
1409 if(STAT->HilightColor()!=Quantity_NOC_WHITE)
1410 HilightWithColor(iobj,STAT->HilightColor(),Standard_False);
1412 Hilight(iobj,Standard_False);
1415 for(itl.Initialize(STAT->SelectionModes());itl.More();itl.Next()){
1417 mgrSelector->Activate(iobj,itl.Value(),myMainSel);
1421 case AIS_DS_Erased:{
1422 upd_col = Standard_True;
1423 EraseGlobal(iobj,Standard_False,Standard_True);
1426 case AIS_DS_FullErased:{
1427 EraseGlobal(iobj,Standard_False,Standard_False);
1438 myMainVwr->Update();
1440 myCollectorVwr->Update();
1444 Standard_Boolean AIS2D_InteractiveContext::AvailableToDetect( const Handle(AIS2D_InteractiveObject)& anIO ) const {
1446 if ( anIO->HighlightMode() == AIS2D_TOD_OBJECT)
1447 return ( ! anIO->State() );
1449 return Standard_True;
1452 void AIS2D_InteractiveContext::DoDetectObject( const Handle(AIS2D_InteractiveObject)& theIO,
1453 const Handle(Graphic2d_TransientManager)& theDrawer ) {
1454 theIO->ClearSeqDetPrim();
1456 if (!theIO->State())
1458 theIO->Unhighlight();
1459 myCurDetectMode = theIO->HighlightMode();
1460 switch ( myCurDetectMode ) {
1462 case AIS2D_TOD_OBJECT :
1463 if ( !IsIOSelected( theIO ) ) {
1464 theDrawer->Draw( theIO );
1469 if ( !IsIOPicked( theIO ) )
1470 mySeqOfDetIO->Append( theIO );
1473 case AIS2D_TOD_PRIMITIVE: {
1474 Standard_Integer pLength = theIO->PickList()->Length();
1475 Handle(Graphic2d_Primitive) thePrim;
1478 for ( int i = 1; i <= pLength; i++ ) {
1479 thePrim = theIO->Primitive(theIO->PickList()->Value(i));
1480 if ( ! thePrim->IsHighlighted() &&
1481 ! IsPrimSelected ( theIO, thePrim ) ) {
1482 theDrawer->Draw( thePrim );
1487 if ( ! IsPrimPicked( theIO, thePrim ) ) {
1488 theIO->AddDetectPrim( thePrim, 0 );
1489 if ( !IsIOPicked( theIO ) )
1490 mySeqOfDetIO->Append( theIO );
1496 thePrim = theIO->Primitive( theIO->PickedIndex() );
1497 if ( ! thePrim->IsHighlighted() ) {
1498 theDrawer->Draw( thePrim );
1503 if ( ! IsPrimPicked( theIO, thePrim ) ) {
1504 theIO->AddDetectPrim( thePrim, 0 );
1505 if ( !IsIOPicked( theIO ) )
1506 mySeqOfDetIO->Append( theIO );
1512 case AIS2D_TOD_ELEMENT: {
1513 Standard_Integer theInd, pLength = theIO->PickList()->Length();
1514 Handle(Graphic2d_Primitive) thePrim;
1516 for ( int i = 1; i <= pLength; i++ ) {
1517 thePrim = theIO->Primitive(theIO->PickList()->Value(i));
1518 theInd = thePrim->PickedIndex();
1519 if ( ! thePrim->IsHighlighted() ) {
1522 const TColStd_MapOfInteger& indices = thePrim->PickedIndices();
1524 if ( indices.Extent() ) {
1525 theDrawer->DrawPickedElements( thePrim );
1527 TColStd_MapIteratorOfMapOfInteger it( indices );
1528 theIO->AddDetectPrim( thePrim, it.Key() );
1530 if ( !IsIOPicked( theIO ) )
1531 mySeqOfDetIO->Append( theIO );
1535 for ( int j = 1; j <= thePrim->NumOfElemIndices(); ++j ) {
1536 theDrawer->DrawElement( thePrim, j );
1537 if ( ! IsElemPicked( theIO, thePrim, j ) ) {
1538 theIO->AddDetectPrim( thePrim, j );
1539 if ( !IsIOPicked( theIO ) )
1540 mySeqOfDetIO->Append( theIO );
1546 for ( int j = 1; j <= thePrim->NumOfElemIndices(); ++j ) {
1547 theDrawer->DrawElement( thePrim, j );
1548 if ( ! IsElemPicked( theIO, thePrim, j ) ) {
1549 theIO->AddDetectPrim( thePrim, j );
1550 if ( !IsIOPicked( theIO ) )
1551 mySeqOfDetIO->Append( theIO );
1556 /*if ( ! IsElemSelected( theIO, thePrim, theInd ) ) {
1557 theDrawer->DrawElement( thePrim, theInd );
1558 if ( ! IsElemPicked( theIO, thePrim, theInd ) ) {
1559 theIO->AddDetectPrim( thePrim, theInd );
1560 if ( ! IsIOPicked( theIO ) )
1561 mySeqOfDetIO->Append( theIO );
1568 thePrim = theIO->Primitive(theIO->PickedIndex());
1569 theInd = thePrim->PickedIndex();
1578 if ( ! IsElemSelected( theIO, thePrim, theInd ) ) {
1579 theDrawer->DrawElement( thePrim, theInd );
1584 if ( ! IsElemPicked( theIO, thePrim, theInd ) ) {
1585 theIO->AddDetectPrim( thePrim, theInd );
1586 if ( ! IsIOPicked( theIO ) )
1587 mySeqOfDetIO->Append( theIO );
1596 case AIS2D_TOD_VERTEX: {
1597 Standard_Integer theInd, pLength = theIO->PickList()->Length();
1598 Handle(Graphic2d_Primitive) thePrim;
1600 for ( int i = 1; i <= pLength; i++ ) {
1601 thePrim = theIO->Primitive(theIO->PickList()->Value(i));
1602 theInd = thePrim->PickedIndex();
1603 if ( ! thePrim->IsHighlighted() )
1604 for ( int j = 1; j <= thePrim->NumOfVertIndices(); ++j ) {
1605 theDrawer->DrawVertex( thePrim, j );
1606 if ( ! IsElemPicked( theIO, thePrim, -j ) ) {
1607 theIO->AddDetectPrim( thePrim, -j );
1608 if ( !IsIOPicked( theIO ) )
1609 mySeqOfDetIO->Append( theIO );
1613 /*if ( ! IsElemSelected( theIO, thePrim, theInd ) ) {
1614 theDrawer->DrawVertex( thePrim, -theInd );
1615 if ( ! IsElemPicked( theIO, thePrim, theInd ) ) {
1616 theIO->AddDetectPrim( thePrim, -theInd );
1617 if ( ! IsIOPicked( theIO ) )
1618 mySeqOfDetIO->Append( theIO );
1623 thePrim = theIO->Primitive(theIO->PickedIndex());
1624 theInd = thePrim->PickedIndex();
1629 if ( ! IsElemSelected( theIO, thePrim, theInd ) ) {
1630 theDrawer->DrawVertex( thePrim, -theInd );
1635 if ( ! IsElemPicked( theIO, thePrim, theInd ) ) {
1636 theIO->AddDetectPrim( thePrim, theInd );
1637 if ( !IsIOPicked( theIO ) )
1638 mySeqOfDetIO->Append( theIO );
1652 Standard_Boolean AIS2D_InteractiveContext::IsIOPicked( const Handle(AIS2D_InteractiveObject)& anIO ) const {
1654 for ( int i = 1; i <= mySeqOfDetIO->Length(); i++ )
1655 if ( anIO == mySeqOfDetIO->Value(i) )
1656 return Standard_True;
1657 return Standard_False;
1661 Standard_Boolean AIS2D_InteractiveContext::IsIOSelected( const Handle(AIS2D_InteractiveObject)& anIO ) const {
1663 for ( int i = 1; i <= mySeqOfSelIO->Length(); i++ )
1664 if ( anIO == mySeqOfSelIO->Value(i) )
1665 return Standard_True;
1666 return Standard_False;
1670 Standard_Boolean AIS2D_InteractiveContext::IsPrimSelected( const Handle(AIS2D_InteractiveObject)& anIO,
1671 const Handle(Graphic2d_Primitive)& aPrim ) const {
1673 Handle(AIS2D_HSequenceOfPrimArchit) theSPA = anIO->GetSelectedSeqPrim();
1675 for ( int i = 1; i <= theSPA->Length(); i++ )
1676 if ( aPrim == theSPA->Value(i)->GetPrimitive() )
1677 return Standard_True;
1678 return Standard_False;
1682 Standard_Boolean AIS2D_InteractiveContext::IsPrimPicked( const Handle(AIS2D_InteractiveObject)& anIO,
1683 const Handle(Graphic2d_Primitive)& aPrim ) const {
1684 Handle(AIS2D_HSequenceOfPrimArchit) theSPA = anIO->GetDetectSeqPrim();
1686 for ( int i = 1; i <= theSPA->Length(); i++ )
1687 if ( aPrim == theSPA->Value(i)->GetPrimitive() )
1688 return Standard_True;
1689 return Standard_False;
1692 Standard_Boolean AIS2D_InteractiveContext::IsElemPicked( const Handle(AIS2D_InteractiveObject)& anIO,
1693 const Handle(Graphic2d_Primitive)& aPrim,
1694 const Standard_Integer ind ) const {
1695 Handle(AIS2D_HSequenceOfPrimArchit) theSPA = anIO->GetDetectSeqPrim();
1696 for ( int i = 1; i <= theSPA->Length(); i++ )
1697 if ( aPrim == theSPA->Value(i)->GetPrimitive() &&
1698 ind == theSPA->Value(i)->GetIndex() )
1699 return Standard_True;
1700 return Standard_False;
1703 Standard_Boolean AIS2D_InteractiveContext::IsElemSelected( const Handle(AIS2D_InteractiveObject)& anIO,
1704 const Handle(Graphic2d_Primitive)& aPrim,
1705 const Standard_Integer ind ) const {
1706 Handle(AIS2D_HSequenceOfPrimArchit) theSPA = anIO->GetSelectedSeqPrim();
1707 for ( int i = 1; i <= theSPA->Length(); i++ )
1708 if ( aPrim == theSPA->Value(i)->GetPrimitive() &&
1709 ind == theSPA->Value(i)->GetIndex() )
1710 return Standard_True;
1711 return Standard_False;
1714 void AIS2D_InteractiveContext::Highlight( const Handle(AIS2D_InteractiveObject)& anIObj,
1715 const Standard_Boolean updateVwr ) {
1716 if ( anIObj.IsNull() ) return;
1718 if ( !anIObj->HasInteractiveContext() )
1719 anIObj->SetContext( this );
1720 if ( !HasOpenedContext() ) {
1721 if ( !myObjects.IsBound(anIObj) ) return;
1722 Handle(AIS2D_GlobalStatus) aGS = myObjects(anIObj);
1724 aGS->SetHighlightStatus( Standard_True );
1726 switch ( aGS->GraphicStatus() ) {
1728 case AIS2D_DS_Displayed: {
1730 Standard_Integer DispMode,SelMode;
1731 AIS2D_TypeOfDetection HiMode;
1732 GetDefModes( anIObj, DispMode, HiMode, SelMode );
1733 Standard_Integer pInd;
1734 anIObj->Highlight(myMainVwr->InitializeColor( mySelectionColor ));
1737 case AIS2D_TOD_OBJECT:
1739 case AIS2D_TOD_PRIMITIVE:
1740 pInd = anIObj->PickedIndex();
1741 anIObj->Unhighlight();
1743 case AIS2D_TOD_ELEMENT:
1744 pInd = anIObj->PickedIndex();
1745 anIObj->Unhighlight();
1747 case AIS2D_TOD_VERTEX:
1748 pInd = anIObj->PickedIndex();
1749 anIObj->Unhighlight();
1753 if ( updateVwr) myMainVwr->Update();
1757 case AIS2D_DS_Erased: {
1759 Standard_Integer HiMode = anIObj->HasHighlightMode() ?
1760 anIObj->HighlightMode() : anIObj->DefaultHighlightMode();
1762 anIObj->Highlight(myCollectorVwr->InitializeColor( mySelectionColor ));
1763 if ( updateVwr ) myCollectorVwr->Update();
1766 case AIS2D_DS_FullErased:
1767 case AIS2D_DS_Temporary:
1771 } // end if opened context isn't exists
1773 // myLocalContexts(myCurLocalIndex)->Highlight(anIObj);
1777 void AIS2D_InteractiveContext::HighlightWithColor( const Handle(AIS2D_InteractiveObject)& anIObj,
1778 const Quantity_NameOfColor aCol,
1779 const Standard_Boolean updateVwr ) {
1781 if ( anIObj.IsNull() ) return;
1783 if ( !anIObj->HasInteractiveContext() ) anIObj->SetContext(this);
1785 if ( !HasOpenedContext() ) {
1786 if ( !myObjects.IsBound(anIObj) ) return;
1788 const Handle(AIS2D_GlobalStatus)& aGS = myObjects(anIObj);
1789 //const TColStd_ListOfInteger& LL = * aGS->DisplayedModes();
1791 aGS->SetHighlightStatus (Standard_True);
1793 switch ( aGS->GraphicStatus() ) {
1794 case AIS2D_DS_Displayed:{
1795 Standard_Integer DispMode, SelMode;
1796 AIS2D_TypeOfDetection HiMode;
1797 GetDefModes( anIObj, DispMode, HiMode, SelMode );
1798 Standard_Integer indCol = myMainVwr->InitializeColor( aCol );
1799 anIObj->Highlight(indCol);
1800 //SetSelectionColor(aCol);
1801 aGS->SetHighlightColor(aCol);
1802 // if ( updateVwr ) myMainVwr->Update();
1805 case AIS2D_DS_Erased: {
1807 Standard_Integer HiMode = anIObj->HasHighlightMode()? anIObj->HighlightMode():0;
1808 Standard_Integer indCol = myCollectorVwr->InitializeColor( aCol );
1810 if ( updateVwr) myCollectorVwr->Update();
1813 case AIS2D_DS_FullErased:
1814 case AIS2D_DS_Temporary:
1819 // myLocalContexts(myCurLocalIndex)->Highlight(anIObj,aCol);
1820 if ( updateVwr) myMainVwr->Update();
1824 void AIS2D_InteractiveContext::Unhighlight( const Handle(AIS2D_InteractiveObject)& anIObj,
1825 const Standard_Boolean updateVwr ) {
1826 if ( anIObj.IsNull() ) return;
1827 anIObj->Unhighlight();
1828 switch ( anIObj->HighlightMode() ) {
1830 case AIS2D_TOD_OBJECT:
1832 case AIS2D_TOD_PRIMITIVE:
1833 if ( !anIObj->Primitive(anIObj->PickedIndex()).IsNull() )
1834 anIObj->Primitive(anIObj->PickedIndex())->Unhighlight();
1836 case AIS2D_TOD_ELEMENT:
1837 if ( !anIObj->Primitive(anIObj->PickedIndex()).IsNull() )
1838 anIObj->Primitive(anIObj->PickedIndex())->Unhighlight();
1840 case AIS2D_TOD_VERTEX:
1841 if ( !anIObj->Primitive(anIObj->PickedIndex()).IsNull() )
1842 anIObj->Primitive(anIObj->PickedIndex())->Unhighlight();
1845 if ( updateVwr) myMainVwr->UpdateNew();
1848 void AIS2D_InteractiveContext::Place(
1849 const Standard_Integer XPix,
1850 const Standard_Integer YPix,
1851 const Handle(V2d_View)& aView,
1852 const Handle(AIS2D_InteractiveObject)& anIO,
1853 const Standard_Boolean isTemporary ) {
1855 Standard_Real XPS, YPS;
1856 aView->Convert( XPix, YPix, XPS, YPS );
1857 gp_GTrsf2d theGTrsf;
1859 theTrsf.SetTranslationPart( gp_Vec2d(gp_Pnt2d(0.,0.), gp_Pnt2d(XPS, YPS) ) );
1860 theGTrsf.SetTrsf2d( theTrsf );
1861 anIO->SetTransform( theGTrsf );
1862 Handle(V2d_Viewer) theViewer = aView->Viewer();
1863 if ( isTemporary ) {
1865 Handle(Graphic2d_TransientManager) theDrawer =
1866 Handle(Graphic2d_TransientManager)::DownCast( theViewer->View()->Drawer() );
1867 Standard_Integer ind = theViewer->InitializeColor(myHighlightColor);
1868 theDrawer->SetOverride( Standard_True );
1869 theDrawer->SetOverrideColor( ind );
1870 Display( anIO, Standard_False );
1871 anIO->Highlight( ind );
1872 theDrawer->BeginDraw( aView->Driver() );
1873 theDrawer->Draw( anIO );
1874 theDrawer->EndDraw();
1875 theDrawer->SetOverride( Standard_False );
1878 if ( !IsDisplayed( anIO ) )
1881 theViewer->Update();
1885 void AIS2D_InteractiveContext::Drag(
1886 const Standard_Integer XPix,
1887 const Standard_Integer YPix,
1888 const Handle(V2d_View)& aView,
1889 const Standard_Boolean isTemporary ) {
1891 if ( ! mySeqOfSelIO->IsEmpty() ) {
1892 Handle(AIS2D_InteractiveObject) theIO;
1893 for ( int j = 1; j <= mySeqOfSelIO->Length(); ++j ) {
1894 theIO = mySeqOfSelIO->Value(j);
1895 if ( !isTemporary ) {
1896 Unhighlight( theIO, Standard_False );
1898 mySeqOfSelIO->Remove(j);
1900 Place( XPix, YPix, aView, theIO, isTemporary );
1905 AIS2D_StatusOfDetection AIS2D_InteractiveContext::MoveTo(
1906 const Standard_Integer XPix,
1907 const Standard_Integer YPix,
1908 const Handle(V2d_View)& aView ) {
1910 RectMoveTo = Standard_False;
1911 if ( HasOpenedContext() && aView->Viewer() != myCollectorVwr ) {
1912 myWasLastMain = Standard_True;
1913 return myLocalContexts(myCurLocalIndex)->MoveTo( XPix, YPix, aView );
1915 Standard_Boolean is_main = Standard_True, UpdVwr = Standard_False;
1916 Handle(V2d_Viewer) theViewer = aView->Viewer();
1918 if ( theViewer == myMainVwr ) {
1919 myLastPicked = myLastinMain;
1920 myWasLastMain = Standard_True;
1921 } else if ( theViewer == myCollectorVwr ) {
1922 myLastPicked = myLastinColl;
1923 is_main = Standard_False;
1924 myWasLastMain = Standard_False;
1926 return AIS2D_SOD_Error;
1928 AIS2D_StatusOfDetection theStat( AIS2D_SOD_Nothing );
1930 Handle(Graphic2d_TransientManager) theDrawer =
1931 Handle(Graphic2d_TransientManager)::DownCast( theViewer->View()->Drawer() );
1933 Handle(Graphic2d_DisplayList) thePickList = aView->Pick( XPix, YPix, myDetectPrecision);
1935 if ( ! thePickList->IsEmpty() ) {
1937 if ( thePickList->Length() == 1 ) {
1938 Handle(Graphic2d_GraphicObject) theGO = thePickList->Value(1);
1939 if ( ! theGO->IsKind(STANDARD_TYPE(AIS2D_InteractiveObject) ) )
1940 return AIS2D_SOD_Nothing;
1941 Handle(AIS2D_InteractiveObject) theIO = Handle(AIS2D_InteractiveObject)::DownCast(theGO);
1942 if ( IsIOPicked( theIO ) )
1943 switch ( theIO->HighlightMode() ) {
1945 case AIS2D_TOD_OBJECT:
1946 return AIS2D_SOD_OnlyOneDetected;
1948 case AIS2D_TOD_PRIMITIVE:
1949 if ( IsPrimPicked(theIO, theIO->Primitive(theIO->PickedIndex())) )
1950 return AIS2D_SOD_OnlyOneDetected;
1952 case AIS2D_TOD_ELEMENT: {
1953 Standard_Integer ind = theIO->PickedIndex();
1954 if ( IsElemPicked( theIO, theIO->Primitive(ind), theIO->Primitive(ind)->PickedIndex() ) )
1955 return AIS2D_SOD_OnlyOneDetected;
1957 myResetDetect= Standard_True;
1961 case AIS2D_TOD_VERTEX: {
1962 Standard_Integer ind = theIO->PickedIndex();
1963 if ( IsElemPicked( theIO, theIO->Primitive(ind), theIO->Primitive(ind)->PickedIndex() ) )
1964 return AIS2D_SOD_OnlyOneDetected;
1965 //else if ( ind > 0 )
1966 // myResetDetect= Standard_True;
1973 myResetDetect = Standard_True;
1976 if ( myResetDetect ) {
1977 mySeqOfDetIO->Clear();
1978 Standard_Integer ind = myMainVwr->InitializeColor(myHighlightColor);
1980 for ( int i = 1 ; i <= thePickList->Length(); i++ ) {
1981 Handle(Graphic2d_GraphicObject) theGOi = thePickList->Value(i);
1982 if ( theGOi->IsKind(STANDARD_TYPE(AIS2D_InteractiveObject) ) ) {
1984 myLastPicked = Handle(AIS2D_InteractiveObject)::DownCast( theGOi );
1985 ( is_main ) ? myLastinMain = myLastPicked : myLastinColl = myLastPicked;
1986 if ( myLastPicked->HasHighlightMode() )
1988 if ( AvailableToDetect(myLastPicked) ) {
1989 if ( myLastPicked->HighlightMode() == AIS2D_TOD_OBJECT )
1991 if (!myLastPicked->State())
1993 myLastPicked->Highlight( ind );
1994 theDrawer->SetOverride(Standard_True);
1995 theDrawer->SetOverrideColor(ind);
1996 theDrawer->BeginDraw( aView->Driver() );
1997 DoDetectObject( myLastPicked, theDrawer );
1998 theDrawer->EndDraw();
1999 theDrawer->SetOverride(Standard_False);
2001 } else theStat = AIS2D_SOD_Selected;
2005 myResetDetect= Standard_False;
2007 } // end if myResetDetect is true
2011 theStat = AIS2D_SOD_Nothing;
2012 theDrawer->RestoreArea( aView->Driver() );
2013 myResetDetect= Standard_True;
2015 if ( ! mySeqOfDetIO->IsEmpty() ) {
2016 Handle(AIS2D_InteractiveObject) theIO;
2017 for ( int i = 1; i <= mySeqOfDetIO->Length(); ++i ) {
2018 theIO = mySeqOfDetIO->Value(i);
2019 if ( theIO->HighlightMode() == AIS2D_TOD_ELEMENT ||
2020 theIO->HighlightMode() == AIS2D_TOD_VERTEX ) {
2021 theIO->ClearSeqDetPrim();
2023 if ( ! theIO->State() )
2024 theIO->Unhighlight();
2026 theIO->ClearSeqDetPrim();
2028 UpdVwr = Standard_True;
2030 ( is_main ) ? myLastinMain.Nullify() : myLastinColl.Nullify();
2031 mySeqOfDetIO->Clear();
2033 } // end if PickList isn't empty
2035 //if ( !myLastPicked.IsNull() ) myLastPicked->Unhighlight();
2038 is_main ? myMainVwr->Update() : myCollectorVwr->Update();
2039 myLastPicked.Nullify();
2040 myLastMoveView = aView;
2048 AIS2D_StatusOfDetection AIS2D_InteractiveContext
2049 ::MoveCircleTo( const Standard_Integer XPix,
2050 const Standard_Integer YPix,
2051 const Standard_Integer Radius,
2052 const Handle(V2d_View)& aView )
2054 mySeqOfDetIO->Clear();
2056 Handle(Graphic2d_DisplayList) thePickList =
2057 aView->PickByCircle( XPix, YPix, Radius );
2059 return Detect( thePickList, aView );
2063 AIS2D_StatusOfDetection AIS2D_InteractiveContext::MoveTo(
2064 const Standard_Integer Xmin,
2065 const Standard_Integer Ymin,
2066 const Standard_Integer Xmax,
2067 const Standard_Integer Ymax,
2068 const Handle(V2d_View)& aView ) {
2071 /*if ( HasOpenedContext() && aView->Viewer() != myCollectorVwr ) {
2072 myWasLastMain = Standard_True;
2073 return myLocalContexts(myCurLocalIndex)->MoveTo( Xmin, Ymin, Xmax, Ymax, aView );
2076 mySeqOfDetIO->Clear();
2078 Handle(Graphic2d_DisplayList) thePickList = aView->Pick( Xmin, Ymin, Xmax, Ymax, myPickMode );
2080 return Detect( thePickList, aView );
2084 AIS2D_StatusOfDetection AIS2D_InteractiveContext
2085 ::Detect( const Handle(Graphic2d_DisplayList)& dList,
2086 const Handle(V2d_View)& aView )
2088 AIS2D_StatusOfDetection theStat( AIS2D_SOD_Nothing );
2090 RectMoveTo = Standard_True;
2091 Handle(V2d_Viewer) theViewer = aView->Viewer();
2092 Standard_Boolean is_main = ( theViewer == myCollectorVwr ) ?
2093 Standard_False : Standard_True;
2094 if ( is_main ) myWasLastMain = Standard_True;
2096 Handle(Graphic2d_TransientManager) theDrawer =
2097 Handle(Graphic2d_TransientManager)::DownCast( theViewer->View()->Drawer() );
2100 if ( ! dList->IsEmpty() ) {
2101 Standard_Integer ind = ( is_main ) ?
2102 myMainVwr->InitializeColor(myHighlightColor) :
2103 myCollectorVwr->InitializeColor(myHighlightColor);
2104 Handle(AIS2D_InteractiveObject) theIO;
2105 theDrawer->SetOverride( Standard_True );
2106 theDrawer->SetOverrideColor( ind );
2107 theDrawer->BeginDraw( aView->Driver() );
2109 for ( int i = 1 ; i <= dList->Length(); i++ ) {
2110 Handle(Graphic2d_GraphicObject) theGOi = dList->Value(i);
2111 if ( theGOi->IsKind(STANDARD_TYPE(AIS2D_InteractiveObject))) {
2112 theIO = Handle(AIS2D_InteractiveObject)::DownCast( theGOi );
2113 if ( theIO->HasHighlightMode() )
2114 if ( AvailableToDetect( theIO ) ) {
2115 if ( theIO->HighlightMode() == AIS2D_TOD_OBJECT )
2116 theIO->Highlight( ind );
2118 DoDetectObject( theIO, theDrawer );
2120 } else theStat = AIS2D_SOD_Selected;
2123 theDrawer->EndDraw();
2124 theDrawer->SetOverride( Standard_False );
2127 theStat = AIS2D_SOD_Nothing;
2128 theDrawer->RestoreArea( aView->Driver() );
2129 if ( !mySeqOfDetIO->IsEmpty() )
2130 for ( int i = 1; i<= mySeqOfDetIO->Length(); ++i ) {
2131 mySeqOfDetIO->Value(i)->Unhighlight();
2132 mySeqOfDetIO->Value(i)->ClearSeqDetPrim();
2134 mySeqOfDetIO->Clear();
2135 is_main ? myMainVwr->Update() : myCollectorVwr->Update();
2136 } // end if PickList isn't empty
2142 AIS2D_StatusOfPick AIS2D_InteractiveContext::Select( const Standard_Boolean UpdateVwr ) {
2144 if ( HasOpenedContext() )
2145 if ( myWasLastMain )
2146 return myLocalContexts(myCurLocalIndex)->Select(UpdateVwr);
2148 myLocalContexts( myCurLocalIndex )->SetSelected( myLastPicked, UpdateVwr );
2149 return AIS2D_SOP_OneSelected;
2152 AIS2D_StatusOfPick PS( AIS2D_SOP_NothingSelected );
2155 if ( ! mySeqOfDetIO->IsEmpty() ) {
2156 Handle(AIS2D_InteractiveObject) theIO;
2157 Handle(AIS2D_HSequenceOfPrimArchit) thePA;
2159 switch ( myCurDetectMode ) {
2161 case AIS2D_TOD_OBJECT : {
2162 for ( int i = 1; i <= mySeqOfDetIO->Length(); ++i ) {
2163 theIO = mySeqOfDetIO->Value(i);
2164 if ( ! RectMoveTo ) {
2165 thePA = theIO->GetSelectedSeqPrim();
2166 if ( ! thePA->IsEmpty() ) {
2167 for ( int j = 1; j <= thePA->Length(); ++j )
2168 thePA->Value(j)->GetPrimitive()->Unhighlight();
2169 theIO->ClearSeqSelPrim();
2172 if ( ! mySeqOfSelIO->IsEmpty() )
2173 for ( int j = 1; j <= mySeqOfSelIO->Length(); ++j ) {
2174 Unhighlight( mySeqOfSelIO->Value(i), Standard_False );
2175 mySeqOfSelIO->Value(i)->SetState(0);
2176 mySeqOfSelIO->Remove(i);
2179 if ( ! theIO->State() ) {
2180 SetCurrentObject( theIO, Standard_False );
2181 mySeqOfSelIO->Append(theIO);
2184 theIO->ClearSeqDetPrim();
2188 case AIS2D_TOD_PRIMITIVE:
2190 for ( int i = 1; i <= mySeqOfDetIO->Length(); ++i )
2194 theIO = mySeqOfDetIO->Value(i);
2195 theIO->Highlight(myMainVwr->InitializeColor(mySelectionColor));
2196 theIO->Unhighlight();
2199 // unselect selected
2203 thePA = theIO->GetSelectedSeqPrim();
2204 for ( j = 1; j <= thePA->Length(); ++j )
2206 thePA->Value(j)->GetPrimitive()->Unhighlight();
2208 theIO->ClearSeqSelPrim();
2210 for ( j = 1; j <= mySeqOfSelIO->Length(); ++j )
2213 // Unhighlight( mySeqOfSelIO->Value(j), Standard_False );
2214 mySeqOfSelIO->Value(j)->SetState( 0 );
2215 mySeqOfSelIO->Remove(j);
2220 thePA = theIO->GetDetectSeqPrim();
2221 for ( j = 1; j <= thePA->Length(); ++j )
2223 Handle(Graphic2d_Primitive) thePrim = thePA->Value(j)->GetPrimitive();
2224 if ( !thePrim ->IsHighlighted() ) {
2225 thePrim->Highlight();
2226 theIO->AddSelectPrim( thePrim, 0 );
2229 if ( ! IsIOSelected( theIO ) )
2230 mySeqOfSelIO->Append( mySeqOfDetIO->Value(i) );
2234 theIO->ClearSeqDetPrim();
2238 case AIS2D_TOD_ELEMENT: {
2239 Standard_Integer theInd;
2240 for ( int i = 1; i <= mySeqOfDetIO->Length(); ++i ) {
2241 theIO = mySeqOfDetIO->Value(i);
2242 theIO->Highlight(myMainVwr->InitializeColor(mySelectionColor));
2243 theIO->Unhighlight();
2245 if ( !RectMoveTo ) {
2246 thePA = theIO->GetSelectedSeqPrim();
2247 if ( ! thePA->IsEmpty() ) {
2248 for ( int j = 1; j <= thePA->Length(); ++j )
2249 thePA->Value(j)->GetPrimitive()->Unhighlight();
2250 theIO->ClearSeqSelPrim();
2252 if ( ! mySeqOfSelIO->IsEmpty() )
2253 for ( int j = 1; j <= mySeqOfSelIO->Length(); ++j ) {
2254 Unhighlight( mySeqOfSelIO->Value(i), Standard_False );
2255 mySeqOfSelIO->Value(i)->SetState(0);
2256 mySeqOfSelIO->Remove(i);
2259 thePA = theIO->GetDetectSeqPrim();
2260 if ( ! thePA->IsEmpty() ) {
2261 Handle(Graphic2d_Primitive) thePrim;
2262 for ( int j = 1; j <= thePA->Length(); ++j ) {
2263 thePrim = thePA->Value(j)->GetPrimitive();
2264 theInd = thePA->Value(j)->GetIndex();
2266 //SAV - marking that highlighted elements became selected
2267 // fixing regression of element single selection
2268 if ( !thePrim->SetElementsSelected() )
2269 thePrim->Highlight( theInd );
2271 thePrim->Unhighlight();
2272 theIO->AddSelectPrim( thePrim, theInd );
2275 if ( ! IsIOSelected( theIO ) ) mySeqOfSelIO->Append(mySeqOfDetIO->Value(i));
2278 theIO->ClearSeqDetPrim();
2282 case AIS2D_TOD_VERTEX: {
2283 Standard_Integer theInd;
2284 for ( int i = 1; i <= mySeqOfDetIO->Length(); ++i ) {
2285 theIO = mySeqOfDetIO->Value(i);
2286 theIO->Highlight(myMainVwr->InitializeColor(mySelectionColor));
2287 theIO->Unhighlight();
2289 if ( !RectMoveTo ) {
2290 thePA = theIO->GetSelectedSeqPrim();
2291 if ( ! thePA->IsEmpty() ) {
2292 for ( int j = 1; j <= thePA->Length(); ++j )
2293 thePA->Value(j)->GetPrimitive()->Unhighlight();
2294 theIO->ClearSeqSelPrim();
2296 if ( ! mySeqOfSelIO->IsEmpty() )
2297 for ( int j = 1; j <= mySeqOfSelIO->Length(); ++j ) {
2298 Unhighlight( mySeqOfSelIO->Value(i), Standard_False );
2299 mySeqOfSelIO->Value(i)->SetState(0);
2300 mySeqOfSelIO->Remove(i);
2303 thePA = theIO->GetDetectSeqPrim();
2304 if ( ! thePA->IsEmpty() ) {
2305 Handle(Graphic2d_Primitive) thePrim;
2306 for ( int j = 1; j <= thePA->Length(); ++j ) {
2307 thePrim = thePA->Value(j)->GetPrimitive();
2308 theInd = thePA->Value(j)->GetIndex();
2309 thePrim->Highlight( theInd );
2310 theIO->AddSelectPrim( thePrim, theInd );
2313 if ( ! IsIOSelected( theIO ) ) mySeqOfSelIO->Append(mySeqOfDetIO->Value(i));
2316 theIO->ClearSeqDetPrim();
2322 mySeqOfDetIO->Clear();
2326 // if sequence of detected objects is empty
2327 if ( ! mySeqOfSelIO->IsEmpty() ) {
2328 switch ( myCurDetectMode ) {
2330 case AIS2D_TOD_OBJECT : {
2331 Handle(AIS2D_InteractiveObject) theIO;
2332 for ( int i = 1; i <= mySeqOfSelIO->Length(); ++i ) {
2333 theIO = mySeqOfSelIO->Value(i);
2334 theIO->Unhighlight();
2336 if ( myObjects.IsBound(theIO) )
2337 if ( myObjects(theIO)->IsSubIntensityOn() )
2338 HighlightWithColor( theIO, mySubIntensity, Standard_False );
2342 case AIS2D_TOD_PRIMITIVE: {
2343 Handle(AIS2D_InteractiveObject) theIO;
2344 Handle(AIS2D_HSequenceOfPrimArchit) thePA;
2345 for ( int i = 1; i <= mySeqOfSelIO->Length(); ++i ) {
2346 theIO = mySeqOfSelIO->Value(i);
2347 thePA = theIO->GetSelectedSeqPrim();
2348 theIO->Unhighlight();
2349 if ( ! thePA->IsEmpty() ) {
2350 for ( int j = 1; j <= thePA->Length(); ++j )
2351 thePA->Value(j)->GetPrimitive()->Unhighlight();
2352 theIO->ClearSeqSelPrim();
2355 if ( myObjects.IsBound(theIO) )
2356 if ( myObjects(theIO)->IsSubIntensityOn() )
2357 HighlightWithColor( theIO, mySubIntensity, Standard_False );
2362 case AIS2D_TOD_ELEMENT: {
2363 Handle(AIS2D_InteractiveObject) theIO;
2364 Handle(AIS2D_HSequenceOfPrimArchit) thePA;
2365 for ( int i = 1; i <= mySeqOfSelIO->Length(); ++i ) {
2366 theIO = mySeqOfSelIO->Value(i);
2367 thePA = theIO->GetSelectedSeqPrim();
2368 theIO->Unhighlight();
2369 if ( ! thePA->IsEmpty() ) {
2370 for ( int j = 1; j <= thePA->Length(); ++j ) {
2371 thePA->Value(j)->GetPrimitive()->Unhighlight();
2372 // SAV - unselecting sub primitives
2373 thePA->Value(j)->GetPrimitive()->ClearSelectedElements();
2375 theIO->ClearSeqSelPrim();
2378 if ( myObjects.IsBound(theIO) )
2379 if ( myObjects(theIO)->IsSubIntensityOn() )
2380 HighlightWithColor( theIO, mySubIntensity, Standard_False );
2384 case AIS2D_TOD_VERTEX: {
2385 Handle(AIS2D_InteractiveObject) theIO;
2386 Handle(AIS2D_HSequenceOfPrimArchit) thePA;
2387 for ( int i = 1; i <= mySeqOfSelIO->Length(); ++i ) {
2388 theIO = mySeqOfSelIO->Value(i);
2389 thePA = theIO->GetSelectedSeqPrim();
2390 theIO->Unhighlight();
2391 if ( ! thePA->IsEmpty() ) {
2392 for ( int j = 1; j <= thePA->Length(); ++j )
2393 thePA->Value(j)->GetPrimitive()->Unhighlight();
2394 theIO->ClearSeqSelPrim();
2397 if ( myObjects.IsBound(theIO) )
2398 if ( myObjects(theIO)->IsSubIntensityOn() )
2399 HighlightWithColor( theIO, mySubIntensity, Standard_False );
2404 mySeqOfSelIO->Clear();
2405 } // end if sequence of detected objects isn't empty
2409 if ( UpdateVwr ) myWasLastMain ? myMainVwr->Update() : UpdateCollector();
2411 Standard_Integer NS = mySeqOfSelIO->Length();
2412 if ( !NS ) return AIS2D_SOP_NothingSelected;
2413 if ( NS == 1 ) return AIS2D_SOP_OneSelected;
2415 return AIS2D_SOP_SeveralSelected;
2419 AIS2D_StatusOfPick AIS2D_InteractiveContext::ShiftSelect( const Standard_Boolean UpdateVwr )
2421 if ( HasOpenedContext() ) {
2422 if ( myWasLastMain )
2423 return myLocalContexts( myCurLocalIndex )->ShiftSelect( UpdateVwr );
2425 myLocalContexts( myCurLocalIndex )->AddOrRemoveSelected( myLastPicked, UpdateVwr );
2426 Standard_Integer NS = mySeqOfSelIO->Length();
2427 if ( !NS ) return AIS2D_SOP_NothingSelected;
2428 if ( NS == 1 ) return AIS2D_SOP_OneSelected;
2429 return AIS2D_SOP_SeveralSelected;
2431 } //end if opened local context exists
2433 if ( myWasLastMain && !myLastinMain.IsNull() )
2434 AddOrRemoveCurObject( myLastinMain,UpdateVwr );
2435 else if ( !myWasLastMain && !myLastinColl.IsNull() )
2436 AddOrRemoveCurObject( myLastinColl, UpdateVwr );
2438 Standard_Integer NS = mySeqOfSelIO->Length();
2439 if ( NS == 0 ) return AIS2D_SOP_NothingSelected;
2440 if ( NS == 1 ) return AIS2D_SOP_OneSelected;
2441 return AIS2D_SOP_SeveralSelected;
2445 AIS2D_StatusOfPick AIS2D_InteractiveContext::ShiftSelect(
2446 const Standard_Integer /*XPMin*/,
2447 const Standard_Integer /*YPMin*/,
2448 const Standard_Integer /*XPMax*/,
2449 const Standard_Integer /*YPMax*/,
2450 const Handle(V2d_View)& /*aView*/,
2451 const Standard_Boolean /*UpdateVwr*/ )
2454 if ( HasOpenedContext() )
2455 return myLocalContexts( myCurLocalIndex )->ShiftSelect( XPMin, YPMin, XPMax, YPMax, aView, UpdateVwr );
2457 UnhighlightCurrent(Standard_False);
2458 // static Handle(StdSelect_ViewerSelector2d) aSelector;
2460 if ( aView->Viewer() == myMainVwr) {
2461 // aSelector= myMainSelector;
2462 myWasLastMain = Standard_True;}
2464 else if (aView->Viewer() == myCollectorVwr){
2465 // aSelector= myCollectorSel;
2466 myWasLastMain = Standard_False;}
2468 return AIS2D_SOP_NothingSelected;
2469 aSelector->SetSensitivity( aView->Convert(mySensitivity) );
2470 aSelector->Pick( XPMin, YPMin, XPMax, YPMax, aView );
2471 AIS2D_Selection::SetCurrentSelection( myCurrentName.ToCString() );
2472 for ( aSelector->Init(); aSelector->More(); aSelector->Next() ) {
2473 const Handle(SelectMgr_SelectableObject)& SObj = aSelector->Picked()->Selectable();
2474 if ( !SObj.IsNull() ) {
2475 AIS2D_SelectStatus SelStat = AIS2D_Selection::Select(SObj);
2476 Standard_Integer mod = (SelStat == AIS2D_SS_Added) ? 1 : 0;
2477 ( * ( (Handle(AIS2D_InteractiveObject)* ) & SObj ) )->SetState(mod);
2481 HighlightCurrent( UpdateVwr );
2483 Standard_Integer NS = NbCurrents();
2484 if ( NS == 0 ) return AIS2D_SOP_NothingSelected;
2485 if ( NS == 1 ) return AIS2D_SOP_OneSelected;
2486 return AIS2D_SOP_SeveralSelected;
2488 return AIS2D_SOP_NothingSelected;
2491 Standard_Integer AIS2D_InteractiveContext::NbSelected() const
2493 if ( mySeqOfSelIO->IsEmpty() )
2496 Standard_Integer nsel = 0;
2497 switch ( myCurDetectMode )
2499 case AIS2D_TOD_ELEMENT:
2500 case AIS2D_TOD_VERTEX:
2501 case AIS2D_TOD_PRIMITIVE:
2503 for ( int i = 1; i <= mySeqOfSelIO->Length(); ++i )
2505 Handle( AIS2D_InteractiveObject ) io = mySeqOfSelIO->Value( i );
2507 nsel += io->GetSelectedSeqPrim()->Length();
2512 nsel = mySeqOfSelIO->Length(); break;
2517 void AIS2D_InteractiveContext::InitSelected()
2520 myMaxSelected = NbSelected();
2523 Standard_Boolean AIS2D_InteractiveContext::MoreSelected() const
2525 return myCurSelected <= myMaxSelected;
2528 void AIS2D_InteractiveContext::NextSelected()
2533 Handle( MMgt_TShared ) AIS2D_InteractiveContext::SelectedObject() const
2535 switch ( myCurDetectMode )
2537 case AIS2D_TOD_ELEMENT:
2538 case AIS2D_TOD_VERTEX:
2539 case AIS2D_TOD_PRIMITIVE:
2541 Standard_Integer current = 0;
2542 for ( int i = 1; i <= mySeqOfSelIO->Length(); ++i )
2544 Handle( AIS2D_InteractiveObject ) io = mySeqOfSelIO->Value( i );
2547 Standard_Integer l = io->GetSelectedSeqPrim()->Length();
2548 if ( myCurSelected <= current + l )
2550 return io->GetSelectedSeqPrim()->Value( myCurSelected - current )->GetPrimitive();
2559 return mySeqOfSelIO->Value( myCurSelected );
2562 // *******************************************************************************
2563 // Immediate Mode Management
2564 // *******************************************************************************
2566 void AIS2D_InteractiveContext::BeginImmediateDraw( const Handle(V2d_View)& aView ) {
2568 Handle(V2d_Viewer) theViewer = aView->Viewer();
2569 Handle(Graphic2d_TransientManager) theDrawer =
2570 Handle(Graphic2d_TransientManager)::DownCast( theViewer->View()->Drawer() );
2571 theDrawer->BeginDraw( aView->Driver() );
2575 void AIS2D_InteractiveContext::ImmediateDraw( const Handle(AIS2D_InteractiveObject)& anIObj,
2576 const Handle(V2d_View)& aView ) {
2578 Handle(V2d_Viewer) theViewer = aView->Viewer();
2579 Handle(Graphic2d_TransientManager) theDrawer =
2580 Handle(Graphic2d_TransientManager)::DownCast( theViewer->View()->Drawer() );
2581 theDrawer->Draw( anIObj );
2585 void AIS2D_InteractiveContext::EndImmediateDraw( const Handle(V2d_View)& aView ) {
2586 Handle(V2d_Viewer) theViewer = aView->Viewer();
2587 Handle(Graphic2d_TransientManager) theDrawer =
2588 Handle(Graphic2d_TransientManager)::DownCast( theViewer->View()->Drawer() );
2589 theDrawer->EndDraw();
2592 Standard_Boolean AIS2D_InteractiveContext::IsImmediateModeOn(const Handle(V2d_View)& /*aView*/) const {
2593 return Standard_False;
2597 void AIS2D_InteractiveContext::SetDetectionMode( const AIS2D_TypeOfDetection mode )
2599 myCurDetectMode = mode;