1 #include <AIS2D_LocalContext.ixx>
2 #include <AIS2D_LocalStatus.hxx>
3 #include <AIS2D_ProjShape.hxx>
4 #include <AIS2D_ListOfIO.hxx>
5 #include <AIS2D_DataMapIteratorOfDataMapOfLocStat.hxx>
6 #include <Prs2d_AspectLine.hxx>
7 #include <Prs2d_Drawer.hxx>
8 #include <Prs2d_Point.hxx>
9 #include <TColStd_ListIteratorOfListOfInteger.hxx>
10 #include <AIS2D_ListIteratorOfListOfIO.hxx>
11 #include <TColStd_Array1OfTransient.hxx>
12 #include <TColStd_HArray1OfTransient.hxx>
13 #include <V2d_Viewer.hxx>
14 #include <Graphic2d_TransientManager.hxx>
15 #include <Graphic2d_Line.hxx>
16 #include <Graphic2d_View.hxx>
17 #include <Graphic2d_DisplayList.hxx>
18 #include <AIS2D_HSequenceOfIO.hxx>
20 static Standard_Integer GetHiMod(const Handle(AIS2D_InteractiveObject)& anIO)
22 return anIO->HasHighlightMode() ? anIO->HighlightMode()
23 : anIO->DefaultHighlightMode();
27 AIS2D_LocalContext::AIS2D_LocalContext()
31 AIS2D_LocalContext::AIS2D_LocalContext(
32 const Handle(AIS2D_InteractiveContext)& aCtx,
33 const Standard_Integer /*Index*/,
34 const Standard_Boolean LoadDisplayed,
35 const Standard_Boolean AcceptStdModes,
36 const Standard_Boolean AcceptEraseOfTemp ):
38 myLastPicked( new AIS2D_InteractiveObject()),
39 myLastinMain( new AIS2D_InteractiveObject()),
42 myLoadDisplayed( LoadDisplayed ),
43 myAcceptStdMode( AcceptStdModes ),
44 myAcceptErase( AcceptEraseOfTemp ),
45 myAutoHighlight( Standard_True ),
49 myResetDetect( Standard_True )
52 if ( myLoadDisplayed ) LoadContextObjects();
56 Standard_Boolean AIS2D_LocalContext::Display(
57 const Handle( AIS2D_InteractiveObject)& anIObj,
58 const Standard_Integer WhichMode,
59 const Standard_Boolean /*AllowDecomp*/,
60 const Standard_Integer ActivationMode ) {
62 if ( myActiveObjects.IsBound(anIObj) ) {
63 const Handle( AIS2D_LocalStatus )& LStatus = myActiveObjects( anIObj );
65 if ( LStatus->DisplayMode() == -1) {
66 if ( !anIObj->IsDisplayed() )
68 if ( LStatus->IsTemporary() )
69 LStatus->SetDisplayMode( WhichMode );
70 } else if ( LStatus->DisplayMode() != WhichMode && LStatus -> IsTemporary() ) {
72 LStatus->SetDisplayMode( WhichMode );
73 if ( !anIObj->IsDisplayed() )
77 if ( ActivationMode !=-1 ) {
78 if ( !LStatus->IsActivated( ActivationMode ) ) {
79 LStatus->ClearSelectionModes();
80 //mySelMgr->Load( anIObj, myMainVS );
81 LStatus->AddSelectionMode( ActivationMode );
82 //mySelMgr->Activate( anIObj, ActivationMode, myMainVS );
86 Handle(AIS2D_LocalStatus) LStatus = new AIS2D_LocalStatus();
88 /*if ( anIObj->AcceptDecomposition() && AllowDecomp )
89 LStatus->SetDecomposition(Standard_True);
91 LStatus->SetDecomposition(Standard_False);
93 if( myICTX->DisplayStatus(anIObj) == AIS2D_DS_None ||
94 myICTX->DisplayStatus(anIObj) == AIS2D_DS_Temporary )
95 LStatus->SetTemporary(Standard_True);
97 LStatus->SetTemporary(Standard_False);
98 AIS2D_TypeOfDetection HiMod ;
99 if( !myICTX->IsDisplayed( anIObj, WhichMode) ) {
100 LStatus->SetDisplayMode(WhichMode);
101 if ( ActivationMode != -1 )
102 LStatus->AddSelectionMode(ActivationMode);
103 HiMod = anIObj->HasHighlightMode() ?
104 anIObj->HighlightMode() : anIObj->DefaultHighlightMode();
105 LStatus->SetHighlightMode( HiMod );
106 if( !anIObj->IsDisplayed()) {
107 DrawObject(anIObj,WhichMode);
110 /*if(ActivationMode!=-1) {
111 mySelMgr->Load(anIObj,myMainVS);
112 mySelMgr->Activate(anIObj,ActivationMode,myMainVS);
115 HiMod = anIObj->HasHighlightMode()? anIObj->HighlightMode(): anIObj->DefaultHighlightMode();
116 LStatus->SetHighlightMode( HiMod );
118 myActiveObjects.Bind(anIObj,LStatus);
121 return Standard_True;
125 Standard_Boolean AIS2D_LocalContext::Erase( const Handle(AIS2D_InteractiveObject)& anIObj) {
127 if ( !myActiveObjects.IsBound( anIObj ) ) return Standard_False;
129 const Handle(AIS2D_LocalStatus)& LStatus = myActiveObjects( anIObj );
131 if ( LStatus->IsSubIntensityOn() ) {
132 LStatus->SubIntensityOff();
133 anIObj->Unhighlight();
136 Standard_Boolean stat( Standard_False );
138 if ( LStatus->DisplayMode() != -1 ) {
139 // if ( IsSelected( anIObj ) )
140 // AddOrRemoveSelected( anIObj );
141 if ( anIObj->IsHighlighted() )
142 anIObj->Unhighlight();
144 LStatus->SetDisplayMode(-1);
145 stat = Standard_True;
147 if ( LStatus->IsTemporary() )
148 if ( anIObj->IsDisplayed() )
152 /* TColStd_ListIteratorOfListOfInteger It( * LStatus->SelectionModes() );
153 for ( ; It.More(); It.Next() )
154 mySelMgr->Deactivate( anIObj, It.Value(), myMainVS );
159 Standard_Boolean AIS2D_LocalContext::Load(
160 const Handle(AIS2D_InteractiveObject)& anIObj,
161 const Standard_Boolean /*AllowDecomp*/,
162 const Standard_Integer ActivationMode ) {
164 if ( myActiveObjects.IsBound( anIObj ) ) return Standard_False;
165 Handle(AIS2D_LocalStatus) LStatus = new AIS2D_LocalStatus();
167 /*if ( anIObj->AcceptDecomposition() && AllowDecomp )
168 LStatus->SetDecomposition( Standard_True );
170 LStatus->SetDecomposition( Standard_False );
172 if ( !myICTX->IsDisplayed( anIObj ) )
173 LStatus->SetTemporary( Standard_True );
175 LStatus->SetTemporary( Standard_False );
176 LStatus->SetDisplayMode( -1 );
178 //storing information....
179 if ( ActivationMode !=-1 )
180 LStatus->AddSelectionMode( ActivationMode );
181 AIS2D_TypeOfDetection HiMod = anIObj->HasHighlightMode() ? anIObj->HighlightMode() : anIObj->DefaultHighlightMode();
182 LStatus->SetHighlightMode( HiMod );
184 /*mySelMgr->Load( anIObj, myMainVS );
185 if ( ActivationMode != -1 ) {
186 mySelMgr->Activate( anIObj, ActivationMode, myMainVS );
188 myActiveObjects.Bind( anIObj, LStatus );
190 return Standard_True;
194 Standard_Boolean AIS2D_LocalContext::Remove(const Handle(AIS2D_InteractiveObject)& /*aSelObj*/ ) {
196 return Standard_False;
199 void AIS2D_LocalContext::LoadContextObjects() {
201 AIS2D_ListIteratorOfListOfIO It;
202 if ( myLoadDisplayed ) {
203 AIS2D_ListOfIO theLOI;
204 myICTX->DisplayedObjects( theLOI, Standard_True );
205 Handle(AIS2D_LocalStatus) LStatus;
206 for ( It.Initialize(theLOI); It.More(); It.Next() ) {
207 LStatus = new AIS2D_LocalStatus();
208 // LStatus->SetDecomposition((It.Value()->AcceptDecomposition() && myAcceptStdMode));
209 LStatus->SetTemporary(Standard_False);
210 LStatus->SetHighlightMode( It.Value()->HasHighlightMode() ? It.Value()->HighlightMode(): It.Value()->DefaultHighlightMode() );
212 myActiveObjects.Bind(It.Value(),LStatus);
217 void AIS2D_LocalContext::UnloadContextObjects()
221 void AIS2D_LocalContext::Terminate() {
227 if ( ! myICTX->mySeqOfSelIO->IsEmpty() )
228 for ( int i = 1; i <= myICTX->mySeqOfSelIO->Length(); ++i )
229 myICTX->mySeqOfSelIO->Value(i)->SetState(0);
232 AIS2D_Selection::Select();
233 AIS2D_Selection::Remove(mySelName.ToCString());*/
234 Handle(V2d_Viewer) Vwr = myICTX->CurrentViewer();
235 Handle(V2d_View) curV;
236 for ( Vwr->InitActiveViews(); Vwr->MoreActiveViews(); Vwr->NextActiveViews() ) {
237 curV = Vwr->ActiveView();
242 void AIS2D_LocalContext::Clear(const AIS2D_ClearMode aType) {
249 case AIS2D_CM_Interactive:
252 case AIS2D_CM_StandardModes:
254 while(!myListOfStdMode.IsEmpty())
255 //DeactivateStdMode(AIS2D_Shape::SelectionType(myListOfStdMode.Last()));
258 case AIS2D_CM_TemporaryShapePrs:
264 Standard_Boolean AIS2D_LocalContext::IsSelected( const Handle(AIS2D_InteractiveObject)& anIObj) const {
266 if ( ! myICTX->mySeqOfSelIO->IsEmpty() )
267 for ( int i = 1; i <= myICTX->mySeqOfSelIO->Length(); ++i )
268 if ( myICTX->mySeqOfSelIO->Value(i) == anIObj )
269 return Standard_True;
270 return Standard_False;
273 Handle(AIS2D_InteractiveObject) AIS2D_LocalContext::SelectedIO() const {
278 AIS2D_StatusOfDetection AIS2D_LocalContext::MoveTo(
279 const Standard_Integer XPix,
280 const Standard_Integer YPix,
281 const Handle(V2d_View)& aView ) {
283 if ( aView->Viewer() == myICTX->CurrentViewer() ) {
284 Standard_Integer Dprecision = myICTX->DetectPrecision();
285 Standard_Boolean UpdVwr = Standard_False;
286 Handle(V2d_Viewer) theViewer = aView->Viewer();
288 AIS2D_StatusOfDetection theStat( AIS2D_SOD_Nothing );
290 Handle(Graphic2d_Primitive) thePrim;
291 Handle(Graphic2d_TransientManager) theDrawer =
292 Handle(Graphic2d_TransientManager)::DownCast( theViewer->View()->Drawer() );
294 Handle(Graphic2d_DisplayList) thePickList = aView->Pick( XPix, YPix, Dprecision );
296 if ( thePickList->Length() > 0 ) {
298 if ( thePickList->Length() == 1 ) {
299 Handle(AIS2D_InteractiveObject) theIO = Handle(AIS2D_InteractiveObject)::DownCast(thePickList->Value(1));
300 if ( theIO == myLastPicked )
301 switch ( theIO->HighlightMode() ) {
303 case AIS2D_TOD_OBJECT:
304 return AIS2D_SOD_OnlyOneDetected;
306 case AIS2D_TOD_PRIMITIVE:
307 if ( myLastPicked->Primitive(myLastPicked->PickedIndex()) == myLastPickPrim )
308 return AIS2D_SOD_OnlyOneDetected;
310 case AIS2D_TOD_ELEMENT:
311 if ( ( myLastPicked->Primitive(myLastPicked->PickedIndex()) == myLastPickPrim ) &&
312 ( myLastPicked->Primitive(myLastPicked->PickedIndex())->PickedIndex() == myLastPickElInd ) )
313 return AIS2D_SOD_OnlyOneDetected;
315 case AIS2D_TOD_VERTEX:
316 if ( ( myLastPicked->Primitive(myLastPicked->PickedIndex()) == myLastPickPrim ) &&
317 ( myLastPicked->Primitive(myLastPicked->PickedIndex())->PickedIndex() == myLastPickElInd ) )
318 return AIS2D_SOD_OnlyOneDetected;
323 if ( !myLastPicked.IsNull() )
324 if ( !myLastPicked->State() ) {
326 AIS2D_TypeOfDetection HiMod = myLastPicked->HasHighlightMode() ?
327 myLastPicked->HighlightMode() : myLastPicked->DefaultHighlightMode();
329 myLastPicked->Unhighlight();
330 UpdVwr = Standard_True;
331 } // end if the last picked object isn't selected one
333 if ( myResetDetect ) {
335 theDrawer->SetOverride(Standard_True);
336 theDrawer->SetOverrideColor( theViewer->InitializeColor(myICTX->HighlightColor()) );
337 theDrawer->BeginDraw( aView->Driver() );
339 for ( int i = 1 ; i <= thePickList->Length(); i++ ) {
341 myLastPicked = Handle(AIS2D_InteractiveObject)::DownCast( thePickList->Value(i) );
342 myLastinMain = myLastPicked;
345 if ( myLastPicked->HasHighlightMode() ) {
347 myLastPicked->Highlight(theViewer->InitializeColor(myICTX->HighlightColor()));
348 switch( myLastPicked->HighlightMode() ) {
350 case AIS2D_TOD_OBJECT:
351 if ( myLastPicked->State() != 1 ) {
352 theDrawer->Draw( myLastPicked );
354 theStat = AIS2D_SOD_Selected;
357 case AIS2D_TOD_PRIMITIVE:
358 myLastPickPrim = myLastPicked->Primitive(myLastPicked->PickedIndex());
359 if ( !myLastPickPrim->IsHighlighted() ) {
360 theDrawer->Draw(myLastPickPrim);
362 theStat = AIS2D_SOD_Selected;
365 case AIS2D_TOD_ELEMENT: {
366 Standard_Integer pInd = myLastPicked->PickedIndex();
367 myLastPickPrim = myLastPicked->Primitive(pInd);
368 if ( myLastPickPrim != myLastSelPrim ||
369 ( myLastPickPrim == myLastSelPrim &&
370 myLastPickPrim->PickedIndex() != myLastSelElInd ) ||
371 ( !myLastPickPrim->PickedIndex() &&
372 !myLastPickPrim->IsHighlighted() ) ) {
373 myLastPickElInd = myLastPickPrim->PickedIndex();
374 theDrawer->DrawElement(myLastPickPrim,myLastPickElInd);
376 theStat = AIS2D_SOD_Selected;
380 case AIS2D_TOD_VERTEX: {
381 myLastPickPrim = myLastPicked->Primitive(myLastPicked->PickedIndex());
383 Standard_Integer pInd = myLastPicked->PickedIndex();
385 if ( myLastPickPrim != myLastSelPrim ||
386 ( myLastPickPrim == myLastSelPrim &&
387 myLastPickPrim->PickedIndex() != myLastSelElInd ) ||
388 ( !myLastPickPrim->PickedIndex() &&
389 !myLastPickPrim->IsHighlighted() ) ) {
390 myLastPickElInd = myLastPickPrim->PickedIndex();
391 theDrawer->DrawVertex(myLastPickPrim,-myLastPickElInd);
393 theStat = AIS2D_SOD_Selected;
398 } // end if lastPicked has highlight mode
402 theDrawer->EndDraw();
403 theDrawer->SetOverride(Standard_False);
404 myResetDetect= Standard_False;
406 } // end if myResetDetect is true
410 theStat = AIS2D_SOD_Nothing;
411 theDrawer->RestoreArea( aView->Driver() );
412 myResetDetect= Standard_True;
413 if ( !myLastPicked.IsNull() ) {
414 if ( myLastPicked->HighlightMode() == AIS2D_TOD_ELEMENT ||
415 myLastPicked->HighlightMode() == AIS2D_TOD_VERTEX ) {
416 myLastPicked->Highlight(theViewer->InitializeColor( myICTX->SelectionColor() ));
418 myLastPicked->Unhighlight();
419 UpdVwr = Standard_True;
420 } else if ( !myLastPicked->State() ) {
421 myLastPicked->Unhighlight();
422 UpdVwr = Standard_True;
426 myLastinMain.Nullify();
427 myLastPickPrim.Nullify();
430 } // end if PickList isn't empty
432 //if ( !myLastPicked.IsNull() ) myLastPicked->Unhighlight();
434 if ( UpdVwr ) theViewer->Update();
436 myLastPicked.Nullify();
437 //myLastMoveView = aView;
441 return AIS2D_SOD_Error;
445 AIS2D_StatusOfPick AIS2D_LocalContext::Select( const Standard_Boolean UpdateVwr ) {
447 if ( myAutoHighlight )
448 UnhighlightPicked( Standard_False );
450 Standard_Integer DI = DetectedIndex();
451 // AIS2D_Selection::SetCurrentSelection( mySelName.ToCString() );
452 // Standard_Integer NbSel = AIS2D_Selection::Extent();
453 Standard_Integer NbSel = myICTX->mySeqOfSelIO->Length();
455 ClearSelected( UpdateVwr );
456 return NbSel == 0 ? AIS2D_SOP_NothingSelected : AIS2D_SOP_Removed;
459 if ( myAutoHighlight )
460 HighlightPicked( UpdateVwr );
461 //return ( AIS2D_Selection::Extent() == 1) ? AIS2D_SOP_OneSelected : AIS2D_SOP_SeveralSelected;
462 return ( myICTX->mySeqOfSelIO->Length() == 1) ? AIS2D_SOP_OneSelected : AIS2D_SOP_SeveralSelected;
465 AIS2D_StatusOfPick AIS2D_LocalContext::ShiftSelect( const Standard_Boolean /*UpdateVwr*/ ) {
467 /* Standard_Integer I = DetectedIndex();
469 UnhighlightPicked(Standard_False);
471 AIS2D_Selection::SetCurrentSelection(mySelName.ToCString());
472 const Handle(SelectMgr_EntityOwner)& EntOwr = myMapOfOwner(I);
473 Standard_Integer mod = EntOwr->State() == 0 ? 1 : 0;
476 AIS2D_Selection::Select(EntOwr);
478 if ( myAutoHighlight )
479 HighlightPicked(UpdateVwr);
481 return AIS2D_SOP_Error;
484 void AIS2D_LocalContext::SetDisplayPriority(
485 const Handle(AIS2D_InteractiveObject)& anIObj,
486 const Standard_Integer /*Prior*/ ) {
488 if ( !myActiveObjects.IsBound(anIObj) ) return;
489 const Handle(AIS2D_LocalStatus)& LStatus = myActiveObjects(anIObj);
490 if ( LStatus->DisplayMode() == -1) return;
491 //myMainPM->SetDisplayPriority(anIObj, LStatus->DisplayMode(),Prior);
492 //if ( LStatus->IsSubIntensityOn())
493 // myMainPM->SetDisplayPriority(anIObj, LStatus->HighlightMode(), Prior);
497 Standard_Integer AIS2D_LocalContext::DisplayedObjects(TColStd_MapOfTransient& theMap) const {
499 Standard_Integer NbDisp(0);
500 for ( AIS2D_DataMapIteratorOfDataMapOfLocStat theIt(myActiveObjects); theIt.More(); theIt.Next() ) {
501 const Handle(AIS2D_InteractiveObject)& SObj = theIt.Key();
502 if ( !theMap.Contains(SObj) )
503 if ( theIt.Value()->DisplayMode() != -1 ) {
511 Standard_Boolean AIS2D_LocalContext::IsDisplayed(const Handle(AIS2D_InteractiveObject)& anIObj) const {
513 if ( !myActiveObjects.IsBound(anIObj) )
514 return Standard_False;
515 return ( myActiveObjects(anIObj)->DisplayMode() != -1 );
518 Standard_Boolean AIS2D_LocalContext::IsDisplayed(const Handle(AIS2D_InteractiveObject)& anIObj,
519 const Standard_Integer aMode) const {
521 if (!myActiveObjects.IsBound(anIObj)) return Standard_False;
522 return (myActiveObjects(anIObj)->DisplayMode()==aMode);
525 void AIS2D_LocalContext::Unhighlight(const Handle(AIS2D_InteractiveObject)& /*anIObj*/)
529 Standard_Boolean AIS2D_LocalContext::IsHighlight(const Handle(AIS2D_InteractiveObject)& anIObj) const {
531 if ( !myActiveObjects.IsBound(anIObj) ) return Standard_False;
532 return myActiveObjects( anIObj )->IsSubIntensityOn();
535 Standard_Boolean AIS2D_LocalContext::IsHighlight(const Handle(AIS2D_InteractiveObject)& anIObj,
536 Standard_Boolean& WithColor,
537 Quantity_NameOfColor& HiCol) const
539 if(!myActiveObjects.IsBound(anIObj)) return Standard_False;
540 if( myActiveObjects(anIObj)->IsSubIntensityOn()){
541 HiCol = myActiveObjects(anIObj)->HighlightColor();
542 if(HiCol==Quantity_NOC_WHITE)
543 WithColor = Standard_True;
545 WithColor = Standard_False;
546 return Standard_True;
548 return Standard_False;
551 void AIS2D_LocalContext::SubIntensityOn(const Handle(AIS2D_InteractiveObject)& anIObj) {
553 if ( !myActiveObjects.IsBound(anIObj) ) return;
555 const Handle(AIS2D_LocalStatus)& LStatus = myActiveObjects(anIObj);
556 if ( LStatus->IsTemporary() ) {
557 Quantity_NameOfColor aCol = myICTX->SubIntensityColor();
558 myICTX->HighlightWithColor(anIObj, aCol);
560 LStatus->SubIntensityOn();
563 void AIS2D_LocalContext::SubIntensityOff(const Handle(AIS2D_InteractiveObject)& anIObj) {
565 if ( !myActiveObjects.IsBound(anIObj) ) return;
567 const Handle(AIS2D_LocalStatus)& LStatus = myActiveObjects(anIObj);
569 if ( LStatus->IsTemporary())
570 myICTX->Unhighlight(anIObj);
571 LStatus->SubIntensityOff();
574 Standard_Boolean AIS2D_LocalContext::IsIn( const Handle(AIS2D_InteractiveObject)& anIObj) const {
575 return myActiveObjects.IsBound(anIObj);
578 Standard_Boolean AIS2D_LocalContext::UnhighLastDetect(const Handle(V2d_View)& /*aView*/) {
580 // if ( !IsValidIndex(myLastIndex) ) return Standard_False;
581 /* myMainPM->BeginDraw();
582 const Handle(SelectMgr_EntityOwner)& Ownr = myMapOfOwner(myLastIndex);
583 Standard_Integer HM(0);
584 if ( Ownr->HasSelectable() ) {
585 Handle(SelectMgr_SelectableObject) SO = Ownr->Selectable();
586 HM = GetHiMod(* ( (Handle(AIS2D_InteractiveObject ) * ) & SO ) );
588 myMapOfOwner( myLastIndex )->Unhilight( myMainPM, HM );
589 myMainPM->EndDraw( aView );
592 return Standard_True;
595 void AIS2D_LocalContext::DrawObject( const Handle(AIS2D_InteractiveObject)& anIObj, const Standard_Integer /*aDispMode*/ ) {
597 if ( anIObj->IsKind(STANDARD_TYPE(AIS2D_ProjShape) ) ) {
599 Handle(AIS2D_ProjShape) thePS = Handle(AIS2D_ProjShape)::DownCast(anIObj);
600 Handle(Graphic2d_Line) theLines = thePS->GetPrimitives();
601 Handle(Prs2d_AspectLine) theAspLine;
603 if ( !anIObj->HasAspect(theLines) ) {
604 Handle(Prs2d_AspectRoot) theAspRoot = anIObj->Attributes()->FindAspect(Prs2d_AN_LINE);
605 theAspLine = Handle(Prs2d_AspectLine)::DownCast(theAspRoot);
606 anIObj->SetAspect( theAspLine, theLines );
609 theAspLine = Handle(Prs2d_AspectLine)::DownCast( anIObj->GetAspect(theLines) );
612 Quantity_Color aColor;
613 Aspect_TypeOfLine aType;
614 Aspect_WidthOfLine aWidth;
616 theAspLine->ValuesOfLine( aColor, aType, aWidth );
618 Standard_Integer colorInd = theAspLine->ColorIndex();
619 Standard_Integer typeInd = theAspLine->TypeIndex();
620 Standard_Integer widthInd = theAspLine->WidthIndex();
623 colorInd = myICTX->InitializeColor( aColor );
624 theLines->SetColorIndex( colorInd );
628 typeInd = myICTX->InitializeStyle( aType );
629 theLines->SetTypeIndex( typeInd );
633 widthInd = myICTX->InitializeWidth( aWidth );
634 theLines->SetWidthIndex( widthInd );
637 if ( thePS->IsHLMode() ) {
638 Handle(Graphic2d_Line) theHLines = thePS->GetHLPrimitives();
639 theHLines->SetColorIndex( colorInd );
640 theHLines->SetWidthIndex( widthInd );
641 Standard_Integer theDashInd = myICTX->InitializeStyle( Aspect_TOL_DASH );
642 theHLines->SetTypeIndex( theDashInd );
647 Handle(Graphic2d_Primitive) thePrim;
649 for ( Standard_Integer i = 1; i <= anIObj->Length(); i++ ) {
650 thePrim = anIObj->Primitive( i );
651 if ( thePrim->IsKind(STANDARD_TYPE(Graphic2d_Line) ) ) {
653 Handle(Graphic2d_Line) theLine = Handle(Graphic2d_Line)::DownCast(thePrim);
654 Handle(Prs2d_AspectLine) theAspLine;
656 if ( !anIObj->HasAspect(theLine) ) {
657 Handle(Prs2d_AspectRoot) theAspRoot = anIObj->Attributes()->FindAspect(Prs2d_AN_LINE);
658 theAspLine = Handle(Prs2d_AspectLine)::DownCast(theAspRoot);
659 anIObj->SetAspect( theAspLine, theLine );
662 theAspLine = Handle(Prs2d_AspectLine)::DownCast( anIObj->GetAspect(theLine) );
665 Quantity_Color aColor;
666 Aspect_TypeOfLine aType;
667 Aspect_WidthOfLine aWidth;
669 Quantity_Color aIntColor;
670 Graphic2d_TypeOfPolygonFilling aTypeFill;
671 Standard_Integer aTile;
672 Standard_Boolean aDrawEdge;
674 theAspLine->ValuesOfLine( aColor, aType, aWidth );
675 theAspLine->ValuesOfPoly( aIntColor, aTypeFill, aTile, aDrawEdge );
677 Standard_Integer colorInd = theAspLine->ColorIndex();
678 Standard_Integer typeInd = theAspLine->TypeIndex();
679 Standard_Integer widthInd = theAspLine->WidthIndex();
680 Standard_Integer colorIntInd = theAspLine->InterColorIndex();
683 colorInd = myICTX->InitializeColor( aColor );
684 theLine->SetColorIndex( colorInd );
688 typeInd = myICTX->InitializeStyle( aType );
689 theLine->SetTypeIndex( typeInd );
693 widthInd = myICTX->InitializeWidth( aWidth );
694 theLine->SetWidthIndex( widthInd );
697 if ( !colorIntInd ) {
698 colorIntInd = myICTX->InitializeColor( aIntColor );
699 theLine->SetInteriorColorIndex( colorIntInd );
702 theLine->SetTypeOfPolygonFilling( aTypeFill );
703 theLine->SetInteriorPattern( aTile );
704 theLine->SetDrawEdge( aDrawEdge );
706 if ( theLine->IsKind(STANDARD_TYPE(Prs2d_Point) ) ) {
708 Handle(Prs2d_Point) thePnt = Handle(Prs2d_Point)::DownCast(theLine);
709 thePnt->SetIndex( myICTX->InitializeMarker( thePnt->Marker() ) );
712 } // end if the kind of primitive is Graphic2d_Line
714 } // end for exploration of the interactive object
716 } // end if IO is AIS2D_ProjShape
720 void AIS2D_LocalContext::ClearObjects() {
722 AIS2D_DataMapIteratorOfDataMapOfLocStat It( myActiveObjects );
723 for ( ; It.More(); It.Next() ) {
724 Handle(AIS2D_InteractiveObject) SObj = Handle(AIS2D_InteractiveObject)::DownCast( It.Key() );
726 const Handle(AIS2D_LocalStatus) LStatus = It.Value();
727 // TColStd_ListIteratorOfListOfInteger ItL;
729 AIS2D_DisplayStatus theDS = myICTX->DisplayStatus( SObj );
731 if ( theDS != AIS2D_DS_Displayed){
732 //if ( myMainPM->IsDisplayed( SObj, LStatus->DisplayMode() ) ) {
733 if ( myICTX->IsDisplayed(SObj) ) {
734 if ( LStatus->IsSubIntensityOn() && SObj->IsHighlighted() )
739 if ( LStatus->IsTemporary() )
742 if ( LStatus->IsSubIntensityOn() ) {
743 myICTX->SubIntensityOff(Handle(AIS2D_InteractiveObject)::DownCast(SObj) ); }
744 Standard_Integer DiMo = SObj->HasDisplayMode() ? SObj->DisplayMode() : myICTX->DisplayMode();
745 if ( LStatus->DisplayMode() !=-1 && LStatus->DisplayMode() != DiMo)
751 myActiveObjects.Clear();
756 void AIS2D_LocalContext::ClearDetected() {
758 /*for ( Standard_Integer i = 1; i <= myMapOfOwner.Extent(); i++ ) {
759 if ( !myMapOfOwner(i).IsNull() ) {
760 if ( myMapOfOwner(i)->IsHilighted(myMainPM) )
761 myMapOfOwner(i)->Unhilight(myMainPM);
762 else if ( myMapOfOwner(i)->IsHilighted( myICTX->CollectorPrsMgr() ) )
763 myMapOfOwner(i)->Unhilight( myICTX->CollectorPrsMgr() );
765 const Handle(SelectMgr_SelectableObject)& SO =
766 myMapOfOwner.FindKey(i)->Selectable();
767 if ( myActiveObjects.IsBound(SO) ) {
768 const Handle(AIS2D_LocalStatus)& LStatus = myActiveObjects(SO);
769 if ( LStatus->IsTemporary() &&
770 LStatus->DisplayMode() == -1 &&
771 LStatus->SelectionModes()->IsEmpty() )
773 myMapOfOwner(i)->Clear(myMainPM);
781 void AIS2D_LocalContext::ClearSelected(const Standard_Boolean UpdateVwr) {
783 UnhighlightPicked(UpdateVwr);
784 // AIS2D_Selection::SetCurrentSelection(mySelName.ToCString());
786 // Handle(AIS2D_Selection) Sel = AIS2D_Selection::CurrentSelection();
787 /*Handle(Standard_Transient) Tr;
788 Handle(SelectMgr_EntityOwner) EO;
789 const TColStd_Array1OfTransient& Obj = Sel->Objects()->Array1();
790 for ( Standard_Integer i = Obj.Lower(); i <= Sel->NbStored(); i++ ) {
793 (*((Handle(SelectMgr_EntityOwner)*)&Tr))->State(0);
795 //AIS2D_Selection::Select();
799 void AIS2D_LocalContext::HighlightPicked(const Standard_Boolean /*UpdateVwr*/) {
801 /*Standard_Boolean updMain(Standard_False),updColl(Standard_False);
802 Quantity_NameOfColor SelCol = myICTX->SelectionColor();
804 Handle(AIS2D_Selection) Sel = AIS2D_Selection::Selection(mySelName.ToCString());
805 Handle(Standard_Transient) Tr;
806 Handle(SelectMgr_EntityOwner) Ownr;
807 Handle(PrsMgr_PresentationManager2d) PM = myMainPM;
809 const TColStd_Array1OfTransient& Obj = Sel->Objects()->Array1();
810 for ( Standard_Integer i = Obj.Lower(); i <= Sel->NbStored(); i++ ) {
812 if ( !Tr.IsNull() ) {
813 Ownr = * ( (Handle(SelectMgr_EntityOwner) * ) &Tr );
814 Handle(AIS2D_InteractiveObject) IO;
815 if ( Ownr->HasSelectable() )
816 if ( !Ownr->ComesFromDecomposition() ) {
817 Handle(SelectMgr_SelectableObject) SO = Ownr->Selectable();
818 Handle(AIS2D_InteractiveObject) IO =
819 * ( (Handle(AIS2D_InteractiveObject) * ) &SO );
820 if ( myICTX->IsInCollector(IO) ) {
821 PM = myICTX->CollectorPrsMgr();
822 updColl = Standard_True;
824 updMain = Standard_True;
826 updMain = Standard_True;
828 updMain = Standard_True;
829 // endif HasSelectable
830 Handle(SelectMgr_SelectableObject) SO = Ownr->Selectable();
831 Standard_Integer HM = GetHiMod( * ( (Handle(AIS2D_InteractiveObject ) * ) &SO ) );
832 // Ownr->HilightWithColor( PM, myICTX->SelectionColor(), HM );
833 if ( Ownr->HasSelectable() ) {
834 Quantity_NameOfColor aCol = myICTX->SelectionColor();
835 Standard_Integer indCol = myICTX->CurrentViewer()->InitializeColor( aCol );
836 PM->SetHighlightColor( indCol );
837 PM->ColorHighlight( SO, indCol, HM );
843 if ( updMain ) myICTX->CurrentViewer()->Update();
844 if ( updColl ) myICTX->Collector()->Update();
848 void AIS2D_LocalContext::UnhighlightPicked( const Standard_Boolean /*UpdateVwr*/ ) {
850 /*Standard_Boolean updMain(Standard_False), updColl(Standard_False);
851 Quantity_NameOfColor SelCol = myICTX->SelectionColor();
853 Handle(AIS2D_Selection) Sel = AIS2D_Selection::Selection(mySelName.ToCString());
854 Handle(Standard_Transient) Tr;
855 Handle(SelectMgr_EntityOwner) Ownr;
856 Handle(PrsMgr_PresentationManager2d) PM = myMainPM;
858 const TColStd_Array1OfTransient& Obj = Sel->Objects()->Array1();
859 for ( Standard_Integer i = Obj.Lower(); i <= Sel->NbStored(); i++ ) {
861 if ( !Tr.IsNull() ) {
862 Ownr = * ( (Handle(SelectMgr_EntityOwner) * ) &Tr );
863 Standard_Integer HM(0);
864 if ( Ownr->HasSelectable() )
865 if ( !Ownr->ComesFromDecomposition() ) {
866 Handle(SelectMgr_SelectableObject) SO = Ownr->Selectable();
867 Handle(AIS2D_InteractiveObject) IO =
868 * ( (Handle(AIS2D_InteractiveObject) * ) &SO );
870 if ( myICTX->IsInCollector(IO) ) {
871 PM = myICTX->CollectorPrsMgr();
872 updColl = Standard_True;
874 updMain = Standard_True;
876 updMain = Standard_True;
877 // endif HasSelectable
878 Ownr->Unhilight( PM, HM );
883 if ( updMain ) myICTX->CurrentViewer()->Update();
884 if ( updColl ) myICTX->Collector()->Update();
888 Standard_Boolean AIS2D_LocalContext::IsValidForSelection(const Handle(AIS2D_InteractiveObject)& /*anIObj*/) const {
890 // return myFilter->IsOk(new SelectMgr_EntityOwner(anIObj));
891 return Standard_False;
894 void AIS2D_LocalContext::UpdateSelected(const Standard_Boolean UpdateVwr) {
896 UnhighlightPicked(Standard_False);
897 HighlightPicked(UpdateVwr);
900 void AIS2D_LocalContext::SetSelected( const Handle(AIS2D_InteractiveObject)& /*anIObj*/,
901 const Standard_Boolean /*UpdateVwr*/ ) {
903 /*if ( !IsValidForSelection(anIObj) ) return;
904 UnhighlightPicked(Standard_False);
906 Handle(AIS2D_Selection) sel = AIS2D_Selection::Selection(mySelName.ToCString());
907 Standard_Boolean found(Standard_False);
908 Handle(Standard_Transient) Tr;
909 Handle(SelectMgr_EntityOwner) EntOwr = FindSelectedOwnerFromIO(anIObj);
910 if ( EntOwr.IsNull() ) {
911 if ( anIObj->HasSelection(0) ) {
912 const Handle(SelectMgr_Selection)& SIObj = anIObj->Selection(0);
914 if ( SIObj->More() ) {
915 Handle(SelectBasics_EntityOwner) BO = SIObj->Sensitive()->OwnerId();
916 EntOwr = *( (Handle(SelectMgr_EntityOwner) * ) & BO );
919 if ( EntOwr.IsNull() )
920 EntOwr = new SelectMgr_EntityOwner(anIObj);
923 ClearSelected(Standard_False);
925 AIS2D_Selection::Select(EntOwr);
926 HighlightPicked(UpdateVwr);
930 void AIS2D_LocalContext::AddOrRemoveSelected(
931 const Handle(AIS2D_InteractiveObject)& /*anIObj*/,
932 const Standard_Boolean /*UpdateVwr*/) {
934 /*if ( !IsValidForSelection(anIObj) ) return;
935 UnhighlightPicked(Standard_False);
936 Handle(SelectMgr_EntityOwner) EntOwr;
938 EntOwr = FindSelectedOwnerFromIO(anIObj);
939 if ( !EntOwr.IsNull() )
942 if ( anIObj->HasSelection(0) ) {
943 const Handle(SelectMgr_Selection)& SIObj = anIObj->Selection(0);
945 if ( SIObj->More() ) {
946 Handle(SelectBasics_EntityOwner) BO = SIObj->Sensitive()->OwnerId();
947 EntOwr = * ( ( Handle(SelectMgr_EntityOwner)* )& BO );
950 if ( EntOwr.IsNull() )
951 EntOwr = new SelectMgr_EntityOwner(anIObj);
955 const Handle(AIS2D_Selection)& aSel = AIS2D_Selection::Selection(mySelName.ToCString() );
956 if ( !aSel.IsNull() )
957 aSel->Select(EntOwr);
958 HighlightPicked(UpdateVwr);
962 Standard_Integer AIS2D_LocalContext::DetectedIndex() {
966 const Handle(AIS2D_LocalStatus)& AIS2D_LocalContext::Status(const Handle(AIS2D_InteractiveObject)& anObject) const {
967 return myActiveObjects(anObject);