1 // Copyright (c) 1999-2012 OPEN CASCADE SAS
3 // The content of this file is subject to the Open CASCADE Technology Public
4 // License Version 6.5 (the "License"). You may not use the content of this file
5 // except in compliance with the License. Please obtain a copy of the License
6 // at http://www.opencascade.org and read it completely before using this file.
8 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
9 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
11 // The Original Code and all software distributed under the License is
12 // distributed on an "AS IS" basis, without warranty of any kind, and the
13 // Initial Developer hereby disclaims all such warranties, including without
14 // limitation, any warranties of merchantability, fitness for a particular
15 // purpose or non-infringement. Please see the License for the specific terms
16 // and conditions governing the rights and limitations under the License.
18 #include <AIS2D_LocalContext.ixx>
19 #include <AIS2D_LocalStatus.hxx>
20 #include <AIS2D_ProjShape.hxx>
21 #include <AIS2D_ListOfIO.hxx>
22 #include <AIS2D_DataMapIteratorOfDataMapOfLocStat.hxx>
23 #include <Prs2d_AspectLine.hxx>
24 #include <Prs2d_Drawer.hxx>
25 #include <Prs2d_Point.hxx>
26 #include <TColStd_ListIteratorOfListOfInteger.hxx>
27 #include <AIS2D_ListIteratorOfListOfIO.hxx>
28 #include <TColStd_Array1OfTransient.hxx>
29 #include <TColStd_HArray1OfTransient.hxx>
30 #include <V2d_Viewer.hxx>
31 #include <Graphic2d_TransientManager.hxx>
32 #include <Graphic2d_Line.hxx>
33 #include <Graphic2d_View.hxx>
34 #include <Graphic2d_DisplayList.hxx>
35 #include <AIS2D_HSequenceOfIO.hxx>
37 static Standard_Integer GetHiMod(const Handle(AIS2D_InteractiveObject)& anIO)
39 return anIO->HasHighlightMode() ? anIO->HighlightMode()
40 : anIO->DefaultHighlightMode();
44 AIS2D_LocalContext::AIS2D_LocalContext()
48 AIS2D_LocalContext::AIS2D_LocalContext(
49 const Handle(AIS2D_InteractiveContext)& aCtx,
50 const Standard_Integer /*Index*/,
51 const Standard_Boolean LoadDisplayed,
52 const Standard_Boolean AcceptStdModes,
53 const Standard_Boolean AcceptEraseOfTemp ):
55 myLastPicked( new AIS2D_InteractiveObject()),
56 myLastinMain( new AIS2D_InteractiveObject()),
59 myLoadDisplayed( LoadDisplayed ),
60 myAcceptStdMode( AcceptStdModes ),
61 myAcceptErase( AcceptEraseOfTemp ),
62 myAutoHighlight( Standard_True ),
66 myResetDetect( Standard_True )
69 if ( myLoadDisplayed ) LoadContextObjects();
73 Standard_Boolean AIS2D_LocalContext::Display(
74 const Handle( AIS2D_InteractiveObject)& anIObj,
75 const Standard_Integer WhichMode,
76 const Standard_Boolean /*AllowDecomp*/,
77 const Standard_Integer ActivationMode ) {
79 if ( myActiveObjects.IsBound(anIObj) ) {
80 const Handle( AIS2D_LocalStatus )& LStatus = myActiveObjects( anIObj );
82 if ( LStatus->DisplayMode() == -1) {
83 if ( !anIObj->IsDisplayed() )
85 if ( LStatus->IsTemporary() )
86 LStatus->SetDisplayMode( WhichMode );
87 } else if ( LStatus->DisplayMode() != WhichMode && LStatus -> IsTemporary() ) {
89 LStatus->SetDisplayMode( WhichMode );
90 if ( !anIObj->IsDisplayed() )
94 if ( ActivationMode !=-1 ) {
95 if ( !LStatus->IsActivated( ActivationMode ) ) {
96 LStatus->ClearSelectionModes();
97 //mySelMgr->Load( anIObj, myMainVS );
98 LStatus->AddSelectionMode( ActivationMode );
99 //mySelMgr->Activate( anIObj, ActivationMode, myMainVS );
103 Handle(AIS2D_LocalStatus) LStatus = new AIS2D_LocalStatus();
105 /*if ( anIObj->AcceptDecomposition() && AllowDecomp )
106 LStatus->SetDecomposition(Standard_True);
108 LStatus->SetDecomposition(Standard_False);
110 if( myICTX->DisplayStatus(anIObj) == AIS2D_DS_None ||
111 myICTX->DisplayStatus(anIObj) == AIS2D_DS_Temporary )
112 LStatus->SetTemporary(Standard_True);
114 LStatus->SetTemporary(Standard_False);
115 AIS2D_TypeOfDetection HiMod ;
116 if( !myICTX->IsDisplayed( anIObj, WhichMode) ) {
117 LStatus->SetDisplayMode(WhichMode);
118 if ( ActivationMode != -1 )
119 LStatus->AddSelectionMode(ActivationMode);
120 HiMod = anIObj->HasHighlightMode() ?
121 anIObj->HighlightMode() : anIObj->DefaultHighlightMode();
122 LStatus->SetHighlightMode( HiMod );
123 if( !anIObj->IsDisplayed()) {
124 DrawObject(anIObj,WhichMode);
127 /*if(ActivationMode!=-1) {
128 mySelMgr->Load(anIObj,myMainVS);
129 mySelMgr->Activate(anIObj,ActivationMode,myMainVS);
132 HiMod = anIObj->HasHighlightMode()? anIObj->HighlightMode(): anIObj->DefaultHighlightMode();
133 LStatus->SetHighlightMode( HiMod );
135 myActiveObjects.Bind(anIObj,LStatus);
138 return Standard_True;
142 Standard_Boolean AIS2D_LocalContext::Erase( const Handle(AIS2D_InteractiveObject)& anIObj) {
144 if ( !myActiveObjects.IsBound( anIObj ) ) return Standard_False;
146 const Handle(AIS2D_LocalStatus)& LStatus = myActiveObjects( anIObj );
148 if ( LStatus->IsSubIntensityOn() ) {
149 LStatus->SubIntensityOff();
150 anIObj->Unhighlight();
153 Standard_Boolean stat( Standard_False );
155 if ( LStatus->DisplayMode() != -1 ) {
156 // if ( IsSelected( anIObj ) )
157 // AddOrRemoveSelected( anIObj );
158 if ( anIObj->IsHighlighted() )
159 anIObj->Unhighlight();
161 LStatus->SetDisplayMode(-1);
162 stat = Standard_True;
164 if ( LStatus->IsTemporary() )
165 if ( anIObj->IsDisplayed() )
169 /* TColStd_ListIteratorOfListOfInteger It( * LStatus->SelectionModes() );
170 for ( ; It.More(); It.Next() )
171 mySelMgr->Deactivate( anIObj, It.Value(), myMainVS );
176 Standard_Boolean AIS2D_LocalContext::Load(
177 const Handle(AIS2D_InteractiveObject)& anIObj,
178 const Standard_Boolean /*AllowDecomp*/,
179 const Standard_Integer ActivationMode ) {
181 if ( myActiveObjects.IsBound( anIObj ) ) return Standard_False;
182 Handle(AIS2D_LocalStatus) LStatus = new AIS2D_LocalStatus();
184 /*if ( anIObj->AcceptDecomposition() && AllowDecomp )
185 LStatus->SetDecomposition( Standard_True );
187 LStatus->SetDecomposition( Standard_False );
189 if ( !myICTX->IsDisplayed( anIObj ) )
190 LStatus->SetTemporary( Standard_True );
192 LStatus->SetTemporary( Standard_False );
193 LStatus->SetDisplayMode( -1 );
195 //storing information....
196 if ( ActivationMode !=-1 )
197 LStatus->AddSelectionMode( ActivationMode );
198 AIS2D_TypeOfDetection HiMod = anIObj->HasHighlightMode() ? anIObj->HighlightMode() : anIObj->DefaultHighlightMode();
199 LStatus->SetHighlightMode( HiMod );
201 /*mySelMgr->Load( anIObj, myMainVS );
202 if ( ActivationMode != -1 ) {
203 mySelMgr->Activate( anIObj, ActivationMode, myMainVS );
205 myActiveObjects.Bind( anIObj, LStatus );
207 return Standard_True;
211 Standard_Boolean AIS2D_LocalContext::Remove(const Handle(AIS2D_InteractiveObject)& /*aSelObj*/ ) {
213 return Standard_False;
216 void AIS2D_LocalContext::LoadContextObjects() {
218 AIS2D_ListIteratorOfListOfIO It;
219 if ( myLoadDisplayed ) {
220 AIS2D_ListOfIO theLOI;
221 myICTX->DisplayedObjects( theLOI, Standard_True );
222 Handle(AIS2D_LocalStatus) LStatus;
223 for ( It.Initialize(theLOI); It.More(); It.Next() ) {
224 LStatus = new AIS2D_LocalStatus();
225 // LStatus->SetDecomposition((It.Value()->AcceptDecomposition() && myAcceptStdMode));
226 LStatus->SetTemporary(Standard_False);
227 LStatus->SetHighlightMode( It.Value()->HasHighlightMode() ? It.Value()->HighlightMode(): It.Value()->DefaultHighlightMode() );
229 myActiveObjects.Bind(It.Value(),LStatus);
234 void AIS2D_LocalContext::UnloadContextObjects()
238 void AIS2D_LocalContext::Terminate() {
244 if ( ! myICTX->mySeqOfSelIO->IsEmpty() )
245 for ( int i = 1; i <= myICTX->mySeqOfSelIO->Length(); ++i )
246 myICTX->mySeqOfSelIO->Value(i)->SetState(0);
249 AIS2D_Selection::Select();
250 AIS2D_Selection::Remove(mySelName.ToCString());*/
251 Handle(V2d_Viewer) Vwr = myICTX->CurrentViewer();
252 Handle(V2d_View) curV;
253 for ( Vwr->InitActiveViews(); Vwr->MoreActiveViews(); Vwr->NextActiveViews() ) {
254 curV = Vwr->ActiveView();
259 void AIS2D_LocalContext::Clear(const AIS2D_ClearMode aType) {
266 case AIS2D_CM_Interactive:
269 case AIS2D_CM_StandardModes:
271 while(!myListOfStdMode.IsEmpty())
272 //DeactivateStdMode(AIS2D_Shape::SelectionType(myListOfStdMode.Last()));
275 case AIS2D_CM_TemporaryShapePrs:
281 Standard_Boolean AIS2D_LocalContext::IsSelected( const Handle(AIS2D_InteractiveObject)& anIObj) const {
283 if ( ! myICTX->mySeqOfSelIO->IsEmpty() )
284 for ( int i = 1; i <= myICTX->mySeqOfSelIO->Length(); ++i )
285 if ( myICTX->mySeqOfSelIO->Value(i) == anIObj )
286 return Standard_True;
287 return Standard_False;
290 Handle(AIS2D_InteractiveObject) AIS2D_LocalContext::SelectedIO() const {
295 AIS2D_StatusOfDetection AIS2D_LocalContext::MoveTo(
296 const Standard_Integer XPix,
297 const Standard_Integer YPix,
298 const Handle(V2d_View)& aView ) {
300 if ( aView->Viewer() == myICTX->CurrentViewer() ) {
301 Standard_Integer Dprecision = myICTX->DetectPrecision();
302 Standard_Boolean UpdVwr = Standard_False;
303 Handle(V2d_Viewer) theViewer = aView->Viewer();
305 AIS2D_StatusOfDetection theStat( AIS2D_SOD_Nothing );
307 Handle(Graphic2d_Primitive) thePrim;
308 Handle(Graphic2d_TransientManager) theDrawer =
309 Handle(Graphic2d_TransientManager)::DownCast( theViewer->View()->Drawer() );
311 Handle(Graphic2d_DisplayList) thePickList = aView->Pick( XPix, YPix, Dprecision );
313 if ( thePickList->Length() > 0 ) {
315 if ( thePickList->Length() == 1 ) {
316 Handle(AIS2D_InteractiveObject) theIO = Handle(AIS2D_InteractiveObject)::DownCast(thePickList->Value(1));
317 if ( theIO == myLastPicked )
318 switch ( theIO->HighlightMode() ) {
320 case AIS2D_TOD_OBJECT:
321 return AIS2D_SOD_OnlyOneDetected;
323 case AIS2D_TOD_PRIMITIVE:
324 if ( myLastPicked->Primitive(myLastPicked->PickedIndex()) == myLastPickPrim )
325 return AIS2D_SOD_OnlyOneDetected;
327 case AIS2D_TOD_ELEMENT:
328 if ( ( myLastPicked->Primitive(myLastPicked->PickedIndex()) == myLastPickPrim ) &&
329 ( myLastPicked->Primitive(myLastPicked->PickedIndex())->PickedIndex() == myLastPickElInd ) )
330 return AIS2D_SOD_OnlyOneDetected;
332 case AIS2D_TOD_VERTEX:
333 if ( ( myLastPicked->Primitive(myLastPicked->PickedIndex()) == myLastPickPrim ) &&
334 ( myLastPicked->Primitive(myLastPicked->PickedIndex())->PickedIndex() == myLastPickElInd ) )
335 return AIS2D_SOD_OnlyOneDetected;
340 if ( !myLastPicked.IsNull() )
341 if ( !myLastPicked->State() ) {
342 myLastPicked->Unhighlight();
343 UpdVwr = Standard_True;
344 } // end if the last picked object isn't selected one
346 if ( myResetDetect ) {
348 theDrawer->SetOverride(Standard_True);
349 theDrawer->SetOverrideColor( theViewer->InitializeColor(myICTX->HighlightColor()) );
350 theDrawer->BeginDraw( aView->Driver() );
352 for ( int i = 1 ; i <= thePickList->Length(); i++ ) {
354 myLastPicked = Handle(AIS2D_InteractiveObject)::DownCast( thePickList->Value(i) );
355 myLastinMain = myLastPicked;
358 if ( myLastPicked->HasHighlightMode() ) {
360 myLastPicked->Highlight(theViewer->InitializeColor(myICTX->HighlightColor()));
361 switch( myLastPicked->HighlightMode() ) {
363 case AIS2D_TOD_OBJECT:
364 if ( myLastPicked->State() != 1 ) {
365 theDrawer->Draw( myLastPicked );
367 theStat = AIS2D_SOD_Selected;
370 case AIS2D_TOD_PRIMITIVE:
371 myLastPickPrim = myLastPicked->Primitive(myLastPicked->PickedIndex());
372 if ( !myLastPickPrim->IsHighlighted() ) {
373 theDrawer->Draw(myLastPickPrim);
375 theStat = AIS2D_SOD_Selected;
378 case AIS2D_TOD_ELEMENT: {
379 Standard_Integer pInd = myLastPicked->PickedIndex();
380 myLastPickPrim = myLastPicked->Primitive(pInd);
381 if ( myLastPickPrim != myLastSelPrim ||
382 ( myLastPickPrim == myLastSelPrim &&
383 myLastPickPrim->PickedIndex() != myLastSelElInd ) ||
384 ( !myLastPickPrim->PickedIndex() &&
385 !myLastPickPrim->IsHighlighted() ) ) {
386 myLastPickElInd = myLastPickPrim->PickedIndex();
387 theDrawer->DrawElement(myLastPickPrim,myLastPickElInd);
389 theStat = AIS2D_SOD_Selected;
393 case AIS2D_TOD_VERTEX: {
394 myLastPickPrim = myLastPicked->Primitive(myLastPicked->PickedIndex());
395 if ( myLastPickPrim != myLastSelPrim ||
396 ( myLastPickPrim == myLastSelPrim &&
397 myLastPickPrim->PickedIndex() != myLastSelElInd ) ||
398 ( !myLastPickPrim->PickedIndex() &&
399 !myLastPickPrim->IsHighlighted() ) ) {
400 myLastPickElInd = myLastPickPrim->PickedIndex();
401 theDrawer->DrawVertex(myLastPickPrim,-myLastPickElInd);
403 theStat = AIS2D_SOD_Selected;
408 } // end if lastPicked has highlight mode
412 theDrawer->EndDraw();
413 theDrawer->SetOverride(Standard_False);
414 myResetDetect= Standard_False;
416 } // end if myResetDetect is true
420 theStat = AIS2D_SOD_Nothing;
421 theDrawer->RestoreArea( aView->Driver() );
422 myResetDetect= Standard_True;
423 if ( !myLastPicked.IsNull() ) {
424 if ( myLastPicked->HighlightMode() == AIS2D_TOD_ELEMENT ||
425 myLastPicked->HighlightMode() == AIS2D_TOD_VERTEX ) {
426 myLastPicked->Highlight(theViewer->InitializeColor( myICTX->SelectionColor() ));
428 myLastPicked->Unhighlight();
429 UpdVwr = Standard_True;
430 } else if ( !myLastPicked->State() ) {
431 myLastPicked->Unhighlight();
432 UpdVwr = Standard_True;
436 myLastinMain.Nullify();
437 myLastPickPrim.Nullify();
440 } // end if PickList isn't empty
442 //if ( !myLastPicked.IsNull() ) myLastPicked->Unhighlight();
444 if ( UpdVwr ) theViewer->Update();
446 myLastPicked.Nullify();
447 //myLastMoveView = aView;
451 return AIS2D_SOD_Error;
455 AIS2D_StatusOfPick AIS2D_LocalContext::Select( const Standard_Boolean UpdateVwr ) {
457 if ( myAutoHighlight )
458 UnhighlightPicked( Standard_False );
460 Standard_Integer DI = DetectedIndex();
461 // AIS2D_Selection::SetCurrentSelection( mySelName.ToCString() );
462 // Standard_Integer NbSel = AIS2D_Selection::Extent();
463 Standard_Integer NbSel = myICTX->mySeqOfSelIO->Length();
465 ClearSelected( UpdateVwr );
466 return NbSel == 0 ? AIS2D_SOP_NothingSelected : AIS2D_SOP_Removed;
469 if ( myAutoHighlight )
470 HighlightPicked( UpdateVwr );
471 //return ( AIS2D_Selection::Extent() == 1) ? AIS2D_SOP_OneSelected : AIS2D_SOP_SeveralSelected;
472 return ( myICTX->mySeqOfSelIO->Length() == 1) ? AIS2D_SOP_OneSelected : AIS2D_SOP_SeveralSelected;
475 AIS2D_StatusOfPick AIS2D_LocalContext::ShiftSelect( const Standard_Boolean /*UpdateVwr*/ ) {
477 /* Standard_Integer I = DetectedIndex();
479 UnhighlightPicked(Standard_False);
481 AIS2D_Selection::SetCurrentSelection(mySelName.ToCString());
482 const Handle(SelectMgr_EntityOwner)& EntOwr = myMapOfOwner(I);
483 Standard_Integer mod = EntOwr->State() == 0 ? 1 : 0;
486 AIS2D_Selection::Select(EntOwr);
488 if ( myAutoHighlight )
489 HighlightPicked(UpdateVwr);
491 return AIS2D_SOP_Error;
494 void AIS2D_LocalContext::SetDisplayPriority(
495 const Handle(AIS2D_InteractiveObject)& anIObj,
496 const Standard_Integer /*Prior*/ ) {
498 if ( !myActiveObjects.IsBound(anIObj) ) return;
499 const Handle(AIS2D_LocalStatus)& LStatus = myActiveObjects(anIObj);
500 if ( LStatus->DisplayMode() == -1) return;
501 //myMainPM->SetDisplayPriority(anIObj, LStatus->DisplayMode(),Prior);
502 //if ( LStatus->IsSubIntensityOn())
503 // myMainPM->SetDisplayPriority(anIObj, LStatus->HighlightMode(), Prior);
507 Standard_Integer AIS2D_LocalContext::DisplayedObjects(TColStd_MapOfTransient& theMap) const {
509 Standard_Integer NbDisp(0);
510 for ( AIS2D_DataMapIteratorOfDataMapOfLocStat theIt(myActiveObjects); theIt.More(); theIt.Next() ) {
511 const Handle(AIS2D_InteractiveObject)& SObj = theIt.Key();
512 if ( !theMap.Contains(SObj) )
513 if ( theIt.Value()->DisplayMode() != -1 ) {
521 Standard_Boolean AIS2D_LocalContext::IsDisplayed(const Handle(AIS2D_InteractiveObject)& anIObj) const {
523 if ( !myActiveObjects.IsBound(anIObj) )
524 return Standard_False;
525 return ( myActiveObjects(anIObj)->DisplayMode() != -1 );
528 Standard_Boolean AIS2D_LocalContext::IsDisplayed(const Handle(AIS2D_InteractiveObject)& anIObj,
529 const Standard_Integer aMode) const {
531 if (!myActiveObjects.IsBound(anIObj)) return Standard_False;
532 return (myActiveObjects(anIObj)->DisplayMode()==aMode);
535 void AIS2D_LocalContext::Unhighlight(const Handle(AIS2D_InteractiveObject)& /*anIObj*/)
539 Standard_Boolean AIS2D_LocalContext::IsHighlight(const Handle(AIS2D_InteractiveObject)& anIObj) const {
541 if ( !myActiveObjects.IsBound(anIObj) ) return Standard_False;
542 return myActiveObjects( anIObj )->IsSubIntensityOn();
545 Standard_Boolean AIS2D_LocalContext::IsHighlight(const Handle(AIS2D_InteractiveObject)& anIObj,
546 Standard_Boolean& WithColor,
547 Quantity_NameOfColor& HiCol) const
549 if(!myActiveObjects.IsBound(anIObj)) return Standard_False;
550 if( myActiveObjects(anIObj)->IsSubIntensityOn()){
551 HiCol = myActiveObjects(anIObj)->HighlightColor();
552 if(HiCol==Quantity_NOC_WHITE)
553 WithColor = Standard_True;
555 WithColor = Standard_False;
556 return Standard_True;
558 return Standard_False;
561 void AIS2D_LocalContext::SubIntensityOn(const Handle(AIS2D_InteractiveObject)& anIObj) {
563 if ( !myActiveObjects.IsBound(anIObj) ) return;
565 const Handle(AIS2D_LocalStatus)& LStatus = myActiveObjects(anIObj);
566 if ( LStatus->IsTemporary() ) {
567 Quantity_NameOfColor aCol = myICTX->SubIntensityColor();
568 myICTX->HighlightWithColor(anIObj, aCol);
570 LStatus->SubIntensityOn();
573 void AIS2D_LocalContext::SubIntensityOff(const Handle(AIS2D_InteractiveObject)& anIObj) {
575 if ( !myActiveObjects.IsBound(anIObj) ) return;
577 const Handle(AIS2D_LocalStatus)& LStatus = myActiveObjects(anIObj);
579 if ( LStatus->IsTemporary())
580 myICTX->Unhighlight(anIObj);
581 LStatus->SubIntensityOff();
584 Standard_Boolean AIS2D_LocalContext::IsIn( const Handle(AIS2D_InteractiveObject)& anIObj) const {
585 return myActiveObjects.IsBound(anIObj);
588 Standard_Boolean AIS2D_LocalContext::UnhighLastDetect(const Handle(V2d_View)& /*aView*/) {
590 // if ( !IsValidIndex(myLastIndex) ) return Standard_False;
591 /* myMainPM->BeginDraw();
592 const Handle(SelectMgr_EntityOwner)& Ownr = myMapOfOwner(myLastIndex);
593 Standard_Integer HM(0);
594 if ( Ownr->HasSelectable() ) {
595 Handle(SelectMgr_SelectableObject) SO = Ownr->Selectable();
596 HM = GetHiMod(* ( (Handle(AIS2D_InteractiveObject ) * ) & SO ) );
598 myMapOfOwner( myLastIndex )->Unhilight( myMainPM, HM );
599 myMainPM->EndDraw( aView );
602 return Standard_True;
605 void AIS2D_LocalContext::DrawObject( const Handle(AIS2D_InteractiveObject)& anIObj, const Standard_Integer /*aDispMode*/ ) {
607 if ( anIObj->IsKind(STANDARD_TYPE(AIS2D_ProjShape) ) ) {
609 Handle(AIS2D_ProjShape) thePS = Handle(AIS2D_ProjShape)::DownCast(anIObj);
610 Handle(Graphic2d_Line) theLines = thePS->GetPrimitives();
611 Handle(Prs2d_AspectLine) theAspLine;
613 if ( !anIObj->HasAspect(theLines) ) {
614 Handle(Prs2d_AspectRoot) theAspRoot = anIObj->Attributes()->FindAspect(Prs2d_AN_LINE);
615 theAspLine = Handle(Prs2d_AspectLine)::DownCast(theAspRoot);
616 anIObj->SetAspect( theAspLine, theLines );
619 theAspLine = Handle(Prs2d_AspectLine)::DownCast( anIObj->GetAspect(theLines) );
622 Quantity_Color aColor;
623 Aspect_TypeOfLine aType;
624 Aspect_WidthOfLine aWidth;
626 theAspLine->ValuesOfLine( aColor, aType, aWidth );
628 Standard_Integer colorInd = theAspLine->ColorIndex();
629 Standard_Integer typeInd = theAspLine->TypeIndex();
630 Standard_Integer widthInd = theAspLine->WidthIndex();
633 colorInd = myICTX->InitializeColor( aColor );
634 theLines->SetColorIndex( colorInd );
638 typeInd = myICTX->InitializeStyle( aType );
639 theLines->SetTypeIndex( typeInd );
643 widthInd = myICTX->InitializeWidth( aWidth );
644 theLines->SetWidthIndex( widthInd );
647 if ( thePS->IsHLMode() ) {
648 Handle(Graphic2d_Line) theHLines = thePS->GetHLPrimitives();
649 theHLines->SetColorIndex( colorInd );
650 theHLines->SetWidthIndex( widthInd );
651 Standard_Integer theDashInd = myICTX->InitializeStyle( Aspect_TOL_DASH );
652 theHLines->SetTypeIndex( theDashInd );
657 Handle(Graphic2d_Primitive) thePrim;
659 for ( Standard_Integer i = 1; i <= anIObj->Length(); i++ ) {
660 thePrim = anIObj->Primitive( i );
661 if ( thePrim->IsKind(STANDARD_TYPE(Graphic2d_Line) ) ) {
663 Handle(Graphic2d_Line) theLine = Handle(Graphic2d_Line)::DownCast(thePrim);
664 Handle(Prs2d_AspectLine) theAspLine;
666 if ( !anIObj->HasAspect(theLine) ) {
667 Handle(Prs2d_AspectRoot) theAspRoot = anIObj->Attributes()->FindAspect(Prs2d_AN_LINE);
668 theAspLine = Handle(Prs2d_AspectLine)::DownCast(theAspRoot);
669 anIObj->SetAspect( theAspLine, theLine );
672 theAspLine = Handle(Prs2d_AspectLine)::DownCast( anIObj->GetAspect(theLine) );
675 Quantity_Color aColor;
676 Aspect_TypeOfLine aType;
677 Aspect_WidthOfLine aWidth;
679 Quantity_Color aIntColor;
680 Graphic2d_TypeOfPolygonFilling aTypeFill;
681 Standard_Integer aTile;
682 Standard_Boolean aDrawEdge;
684 theAspLine->ValuesOfLine( aColor, aType, aWidth );
685 theAspLine->ValuesOfPoly( aIntColor, aTypeFill, aTile, aDrawEdge );
687 Standard_Integer colorInd = theAspLine->ColorIndex();
688 Standard_Integer typeInd = theAspLine->TypeIndex();
689 Standard_Integer widthInd = theAspLine->WidthIndex();
690 Standard_Integer colorIntInd = theAspLine->InterColorIndex();
693 colorInd = myICTX->InitializeColor( aColor );
694 theLine->SetColorIndex( colorInd );
698 typeInd = myICTX->InitializeStyle( aType );
699 theLine->SetTypeIndex( typeInd );
703 widthInd = myICTX->InitializeWidth( aWidth );
704 theLine->SetWidthIndex( widthInd );
707 if ( !colorIntInd ) {
708 colorIntInd = myICTX->InitializeColor( aIntColor );
709 theLine->SetInteriorColorIndex( colorIntInd );
712 theLine->SetTypeOfPolygonFilling( aTypeFill );
713 theLine->SetInteriorPattern( aTile );
714 theLine->SetDrawEdge( aDrawEdge );
716 if ( theLine->IsKind(STANDARD_TYPE(Prs2d_Point) ) ) {
718 Handle(Prs2d_Point) thePnt = Handle(Prs2d_Point)::DownCast(theLine);
719 thePnt->SetIndex( myICTX->InitializeMarker( thePnt->Marker() ) );
722 } // end if the kind of primitive is Graphic2d_Line
724 } // end for exploration of the interactive object
726 } // end if IO is AIS2D_ProjShape
730 void AIS2D_LocalContext::ClearObjects() {
732 AIS2D_DataMapIteratorOfDataMapOfLocStat It( myActiveObjects );
733 for ( ; It.More(); It.Next() ) {
734 Handle(AIS2D_InteractiveObject) SObj = Handle(AIS2D_InteractiveObject)::DownCast( It.Key() );
736 const Handle(AIS2D_LocalStatus) LStatus = It.Value();
737 // TColStd_ListIteratorOfListOfInteger ItL;
739 AIS2D_DisplayStatus theDS = myICTX->DisplayStatus( SObj );
741 if ( theDS != AIS2D_DS_Displayed){
742 //if ( myMainPM->IsDisplayed( SObj, LStatus->DisplayMode() ) ) {
743 if ( myICTX->IsDisplayed(SObj) ) {
744 if ( LStatus->IsSubIntensityOn() && SObj->IsHighlighted() )
749 if ( LStatus->IsTemporary() )
752 if ( LStatus->IsSubIntensityOn() ) {
753 myICTX->SubIntensityOff(Handle(AIS2D_InteractiveObject)::DownCast(SObj) ); }
754 Standard_Integer DiMo = SObj->HasDisplayMode() ? SObj->DisplayMode() : myICTX->DisplayMode();
755 if ( LStatus->DisplayMode() !=-1 && LStatus->DisplayMode() != DiMo)
761 myActiveObjects.Clear();
766 void AIS2D_LocalContext::ClearDetected() {
768 /*for ( Standard_Integer i = 1; i <= myMapOfOwner.Extent(); i++ ) {
769 if ( !myMapOfOwner(i).IsNull() ) {
770 if ( myMapOfOwner(i)->IsHilighted(myMainPM) )
771 myMapOfOwner(i)->Unhilight(myMainPM);
772 else if ( myMapOfOwner(i)->IsHilighted( myICTX->CollectorPrsMgr() ) )
773 myMapOfOwner(i)->Unhilight( myICTX->CollectorPrsMgr() );
775 const Handle(SelectMgr_SelectableObject)& SO =
776 myMapOfOwner.FindKey(i)->Selectable();
777 if ( myActiveObjects.IsBound(SO) ) {
778 const Handle(AIS2D_LocalStatus)& LStatus = myActiveObjects(SO);
779 if ( LStatus->IsTemporary() &&
780 LStatus->DisplayMode() == -1 &&
781 LStatus->SelectionModes()->IsEmpty() )
783 myMapOfOwner(i)->Clear(myMainPM);
791 void AIS2D_LocalContext::ClearSelected(const Standard_Boolean UpdateVwr) {
793 UnhighlightPicked(UpdateVwr);
794 // AIS2D_Selection::SetCurrentSelection(mySelName.ToCString());
796 // Handle(AIS2D_Selection) Sel = AIS2D_Selection::CurrentSelection();
797 /*Handle(Standard_Transient) Tr;
798 Handle(SelectMgr_EntityOwner) EO;
799 const TColStd_Array1OfTransient& Obj = Sel->Objects()->Array1();
800 for ( Standard_Integer i = Obj.Lower(); i <= Sel->NbStored(); i++ ) {
803 (*((Handle(SelectMgr_EntityOwner)*)&Tr))->State(0);
805 //AIS2D_Selection::Select();
809 void AIS2D_LocalContext::HighlightPicked(const Standard_Boolean /*UpdateVwr*/) {
811 /*Standard_Boolean updMain(Standard_False),updColl(Standard_False);
812 Quantity_NameOfColor SelCol = myICTX->SelectionColor();
814 Handle(AIS2D_Selection) Sel = AIS2D_Selection::Selection(mySelName.ToCString());
815 Handle(Standard_Transient) Tr;
816 Handle(SelectMgr_EntityOwner) Ownr;
817 Handle(PrsMgr_PresentationManager2d) PM = myMainPM;
819 const TColStd_Array1OfTransient& Obj = Sel->Objects()->Array1();
820 for ( Standard_Integer i = Obj.Lower(); i <= Sel->NbStored(); i++ ) {
822 if ( !Tr.IsNull() ) {
823 Ownr = * ( (Handle(SelectMgr_EntityOwner) * ) &Tr );
824 Handle(AIS2D_InteractiveObject) IO;
825 if ( Ownr->HasSelectable() )
826 if ( !Ownr->ComesFromDecomposition() ) {
827 Handle(SelectMgr_SelectableObject) SO = Ownr->Selectable();
828 Handle(AIS2D_InteractiveObject) IO =
829 * ( (Handle(AIS2D_InteractiveObject) * ) &SO );
830 if ( myICTX->IsInCollector(IO) ) {
831 PM = myICTX->CollectorPrsMgr();
832 updColl = Standard_True;
834 updMain = Standard_True;
836 updMain = Standard_True;
838 updMain = Standard_True;
839 // endif HasSelectable
840 Handle(SelectMgr_SelectableObject) SO = Ownr->Selectable();
841 Standard_Integer HM = GetHiMod( * ( (Handle(AIS2D_InteractiveObject ) * ) &SO ) );
842 // Ownr->HilightWithColor( PM, myICTX->SelectionColor(), HM );
843 if ( Ownr->HasSelectable() ) {
844 Quantity_NameOfColor aCol = myICTX->SelectionColor();
845 Standard_Integer indCol = myICTX->CurrentViewer()->InitializeColor( aCol );
846 PM->SetHighlightColor( indCol );
847 PM->ColorHighlight( SO, indCol, HM );
853 if ( updMain ) myICTX->CurrentViewer()->Update();
854 if ( updColl ) myICTX->Collector()->Update();
858 void AIS2D_LocalContext::UnhighlightPicked( const Standard_Boolean /*UpdateVwr*/ ) {
860 /*Standard_Boolean updMain(Standard_False), updColl(Standard_False);
861 Quantity_NameOfColor SelCol = myICTX->SelectionColor();
863 Handle(AIS2D_Selection) Sel = AIS2D_Selection::Selection(mySelName.ToCString());
864 Handle(Standard_Transient) Tr;
865 Handle(SelectMgr_EntityOwner) Ownr;
866 Handle(PrsMgr_PresentationManager2d) PM = myMainPM;
868 const TColStd_Array1OfTransient& Obj = Sel->Objects()->Array1();
869 for ( Standard_Integer i = Obj.Lower(); i <= Sel->NbStored(); i++ ) {
871 if ( !Tr.IsNull() ) {
872 Ownr = * ( (Handle(SelectMgr_EntityOwner) * ) &Tr );
873 Standard_Integer HM(0);
874 if ( Ownr->HasSelectable() )
875 if ( !Ownr->ComesFromDecomposition() ) {
876 Handle(SelectMgr_SelectableObject) SO = Ownr->Selectable();
877 Handle(AIS2D_InteractiveObject) IO =
878 * ( (Handle(AIS2D_InteractiveObject) * ) &SO );
880 if ( myICTX->IsInCollector(IO) ) {
881 PM = myICTX->CollectorPrsMgr();
882 updColl = Standard_True;
884 updMain = Standard_True;
886 updMain = Standard_True;
887 // endif HasSelectable
888 Ownr->Unhilight( PM, HM );
893 if ( updMain ) myICTX->CurrentViewer()->Update();
894 if ( updColl ) myICTX->Collector()->Update();
898 Standard_Boolean AIS2D_LocalContext::IsValidForSelection(const Handle(AIS2D_InteractiveObject)& /*anIObj*/) const {
900 // return myFilter->IsOk(new SelectMgr_EntityOwner(anIObj));
901 return Standard_False;
904 void AIS2D_LocalContext::UpdateSelected(const Standard_Boolean UpdateVwr) {
906 UnhighlightPicked(Standard_False);
907 HighlightPicked(UpdateVwr);
910 void AIS2D_LocalContext::SetSelected( const Handle(AIS2D_InteractiveObject)& /*anIObj*/,
911 const Standard_Boolean /*UpdateVwr*/ ) {
913 /*if ( !IsValidForSelection(anIObj) ) return;
914 UnhighlightPicked(Standard_False);
916 Handle(AIS2D_Selection) sel = AIS2D_Selection::Selection(mySelName.ToCString());
917 Standard_Boolean found(Standard_False);
918 Handle(Standard_Transient) Tr;
919 Handle(SelectMgr_EntityOwner) EntOwr = FindSelectedOwnerFromIO(anIObj);
920 if ( EntOwr.IsNull() ) {
921 if ( anIObj->HasSelection(0) ) {
922 const Handle(SelectMgr_Selection)& SIObj = anIObj->Selection(0);
924 if ( SIObj->More() ) {
925 Handle(SelectBasics_EntityOwner) BO = SIObj->Sensitive()->OwnerId();
926 EntOwr = *( (Handle(SelectMgr_EntityOwner) * ) & BO );
929 if ( EntOwr.IsNull() )
930 EntOwr = new SelectMgr_EntityOwner(anIObj);
933 ClearSelected(Standard_False);
935 AIS2D_Selection::Select(EntOwr);
936 HighlightPicked(UpdateVwr);
940 void AIS2D_LocalContext::AddOrRemoveSelected(
941 const Handle(AIS2D_InteractiveObject)& /*anIObj*/,
942 const Standard_Boolean /*UpdateVwr*/) {
944 /*if ( !IsValidForSelection(anIObj) ) return;
945 UnhighlightPicked(Standard_False);
946 Handle(SelectMgr_EntityOwner) EntOwr;
948 EntOwr = FindSelectedOwnerFromIO(anIObj);
949 if ( !EntOwr.IsNull() )
952 if ( anIObj->HasSelection(0) ) {
953 const Handle(SelectMgr_Selection)& SIObj = anIObj->Selection(0);
955 if ( SIObj->More() ) {
956 Handle(SelectBasics_EntityOwner) BO = SIObj->Sensitive()->OwnerId();
957 EntOwr = * ( ( Handle(SelectMgr_EntityOwner)* )& BO );
960 if ( EntOwr.IsNull() )
961 EntOwr = new SelectMgr_EntityOwner(anIObj);
965 const Handle(AIS2D_Selection)& aSel = AIS2D_Selection::Selection(mySelName.ToCString() );
966 if ( !aSel.IsNull() )
967 aSel->Select(EntOwr);
968 HighlightPicked(UpdateVwr);
972 Standard_Integer AIS2D_LocalContext::DetectedIndex() {
976 const Handle(AIS2D_LocalStatus)& AIS2D_LocalContext::Status(const Handle(AIS2D_InteractiveObject)& anObject) const {
977 return myActiveObjects(anObject);