0022922: Clean up warnings on uninitialized / unused variables
[occt.git] / src / AIS2D / AIS2D_LocalContext.cxx
CommitLineData
7fd59977 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>
19
20static Standard_Integer GetHiMod(const Handle(AIS2D_InteractiveObject)& anIO)
21{
22 return anIO->HasHighlightMode() ? anIO->HighlightMode()
23 : anIO->DefaultHighlightMode();
24}
25
26
27AIS2D_LocalContext::AIS2D_LocalContext()
28{
29}
30
31AIS2D_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 ):
37 myICTX( aCtx ),
38 myLastPicked( new AIS2D_InteractiveObject()),
39 myLastinMain( new AIS2D_InteractiveObject()),
40 myLastPickElInd( 0 ),
41 myLastSelElInd( 0 ),
42 myLoadDisplayed( LoadDisplayed ),
43 myAcceptStdMode( AcceptStdModes ),
44 myAcceptErase( AcceptEraseOfTemp ),
45 myAutoHighlight( Standard_True ),
46 myLastIndex( 0 ),
47 myLastGood( 0 ),
48 myCurDetected( 0 ),
49 myResetDetect( Standard_True )
50
51{
52 if ( myLoadDisplayed ) LoadContextObjects();
53}
54
55
56Standard_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 ) {
61
62 if ( myActiveObjects.IsBound(anIObj) ) {
63 const Handle( AIS2D_LocalStatus )& LStatus = myActiveObjects( anIObj );
64
65 if ( LStatus->DisplayMode() == -1) {
66 if ( !anIObj->IsDisplayed() )
67 anIObj->Display();
68 if ( LStatus->IsTemporary() )
69 LStatus->SetDisplayMode( WhichMode );
70 } else if ( LStatus->DisplayMode() != WhichMode && LStatus -> IsTemporary() ) {
71 anIObj->Remove();
72 LStatus->SetDisplayMode( WhichMode );
73 if ( !anIObj->IsDisplayed() )
74 anIObj->Display();
75 }
76
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 );
83 }
84 }
85 } else {
86 Handle(AIS2D_LocalStatus) LStatus = new AIS2D_LocalStatus();
87
88 /*if ( anIObj->AcceptDecomposition() && AllowDecomp )
89 LStatus->SetDecomposition(Standard_True);
90 else
91 LStatus->SetDecomposition(Standard_False);
92 */
93 if( myICTX->DisplayStatus(anIObj) == AIS2D_DS_None ||
94 myICTX->DisplayStatus(anIObj) == AIS2D_DS_Temporary )
95 LStatus->SetTemporary(Standard_True);
96 else
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);
108 anIObj->Display();
109 }
110 /*if(ActivationMode!=-1) {
111 mySelMgr->Load(anIObj,myMainVS);
112 mySelMgr->Activate(anIObj,ActivationMode,myMainVS);
113 } */
114 } else {
115 HiMod = anIObj->HasHighlightMode()? anIObj->HighlightMode(): anIObj->DefaultHighlightMode();
116 LStatus->SetHighlightMode( HiMod );
117 }
118 myActiveObjects.Bind(anIObj,LStatus);
119 }
120
121 return Standard_True;
122
123}
124
125Standard_Boolean AIS2D_LocalContext::Erase( const Handle(AIS2D_InteractiveObject)& anIObj) {
126
127 if ( !myActiveObjects.IsBound( anIObj ) ) return Standard_False;
128
129 const Handle(AIS2D_LocalStatus)& LStatus = myActiveObjects( anIObj );
130
131 if ( LStatus->IsSubIntensityOn() ) {
132 LStatus->SubIntensityOff();
133 anIObj->Unhighlight();
134 }
135
136 Standard_Boolean stat( Standard_False );
137
138 if ( LStatus->DisplayMode() != -1 ) {
139 // if ( IsSelected( anIObj ) )
140 // AddOrRemoveSelected( anIObj );
141 if ( anIObj->IsHighlighted() )
142 anIObj->Unhighlight();
143 anIObj->Remove();
144 LStatus->SetDisplayMode(-1);
145 stat = Standard_True;
146 }
147 if ( LStatus->IsTemporary() )
148 if ( anIObj->IsDisplayed() )
149 anIObj->Remove();
150
151
152/* TColStd_ListIteratorOfListOfInteger It( * LStatus->SelectionModes() );
153 for ( ; It.More(); It.Next() )
154 mySelMgr->Deactivate( anIObj, It.Value(), myMainVS );
155 */
156 return stat;
157}
158
159Standard_Boolean AIS2D_LocalContext::Load(
160 const Handle(AIS2D_InteractiveObject)& anIObj,
161 const Standard_Boolean /*AllowDecomp*/,
162 const Standard_Integer ActivationMode ) {
163
164 if ( myActiveObjects.IsBound( anIObj ) ) return Standard_False;
165 Handle(AIS2D_LocalStatus) LStatus = new AIS2D_LocalStatus();
166
167 /*if ( anIObj->AcceptDecomposition() && AllowDecomp )
168 LStatus->SetDecomposition( Standard_True );
169 else
170 LStatus->SetDecomposition( Standard_False );
171 */
172 if ( !myICTX->IsDisplayed( anIObj ) )
173 LStatus->SetTemporary( Standard_True );
174 else
175 LStatus->SetTemporary( Standard_False );
176 LStatus->SetDisplayMode( -1 );
177
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 );
183
184 /*mySelMgr->Load( anIObj, myMainVS );
185 if ( ActivationMode != -1 ) {
186 mySelMgr->Activate( anIObj, ActivationMode, myMainVS );
187 } */
188 myActiveObjects.Bind( anIObj, LStatus );
189
190 return Standard_True;
191
192}
193
194Standard_Boolean AIS2D_LocalContext::Remove(const Handle(AIS2D_InteractiveObject)& /*aSelObj*/ ) {
195
196 return Standard_False;
197}
198
199void AIS2D_LocalContext::LoadContextObjects() {
200
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() );
211
212 myActiveObjects.Bind(It.Value(),LStatus);
213 }
214 }
215}
216
217void AIS2D_LocalContext::UnloadContextObjects()
218{}
219
220
221void AIS2D_LocalContext::Terminate() {
222
223 ClearDetected();
224 Clear();
225 myLastIndex = 0;
226
227 if ( ! myICTX->mySeqOfSelIO->IsEmpty() )
228 for ( int i = 1; i <= myICTX->mySeqOfSelIO->Length(); ++i )
229 myICTX->mySeqOfSelIO->Value(i)->SetState(0);
230
231 /*
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();
238 }
239
240}
241
242void AIS2D_LocalContext::Clear(const AIS2D_ClearMode aType) {
243 switch (aType){
244 case AIS2D_CM_All:
245 {
246 ClearObjects();
247 break;
248 }
249 case AIS2D_CM_Interactive:
250 ClearObjects();
251 break;
252 case AIS2D_CM_StandardModes:
253 {
254 while(!myListOfStdMode.IsEmpty())
255 //DeactivateStdMode(AIS2D_Shape::SelectionType(myListOfStdMode.Last()));
256 break;
257 }
258 case AIS2D_CM_TemporaryShapePrs:
259 ClearDetected();
260 }
261 //UpdateSort();
262}
263
264Standard_Boolean AIS2D_LocalContext::IsSelected( const Handle(AIS2D_InteractiveObject)& anIObj) const {
265
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;
271}
272
273Handle(AIS2D_InteractiveObject) AIS2D_LocalContext::SelectedIO() const {
274 return myLastPicked;
275}
276
277
278AIS2D_StatusOfDetection AIS2D_LocalContext::MoveTo(
279 const Standard_Integer XPix,
280 const Standard_Integer YPix,
281 const Handle(V2d_View)& aView ) {
282
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();
287
288 AIS2D_StatusOfDetection theStat( AIS2D_SOD_Nothing );
289
290 Handle(Graphic2d_Primitive) thePrim;
291 Handle(Graphic2d_TransientManager) theDrawer =
292 Handle(Graphic2d_TransientManager)::DownCast( theViewer->View()->Drawer() );
293
294 Handle(Graphic2d_DisplayList) thePickList = aView->Pick( XPix, YPix, Dprecision );
295
296 if ( thePickList->Length() > 0 ) {
297
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() ) {
302 default:
303 case AIS2D_TOD_OBJECT:
304 return AIS2D_SOD_OnlyOneDetected;
305 break;
306 case AIS2D_TOD_PRIMITIVE:
307 if ( myLastPicked->Primitive(myLastPicked->PickedIndex()) == myLastPickPrim )
308 return AIS2D_SOD_OnlyOneDetected;
309 break;
310 case AIS2D_TOD_ELEMENT:
311 if ( ( myLastPicked->Primitive(myLastPicked->PickedIndex()) == myLastPickPrim ) &&
312 ( myLastPicked->Primitive(myLastPicked->PickedIndex())->PickedIndex() == myLastPickElInd ) )
313 return AIS2D_SOD_OnlyOneDetected;
314 break;
315 case AIS2D_TOD_VERTEX:
316 if ( ( myLastPicked->Primitive(myLastPicked->PickedIndex()) == myLastPickPrim ) &&
317 ( myLastPicked->Primitive(myLastPicked->PickedIndex())->PickedIndex() == myLastPickElInd ) )
318 return AIS2D_SOD_OnlyOneDetected;
319 break;
320
321 }
322 }
323 if ( !myLastPicked.IsNull() )
324 if ( !myLastPicked->State() ) {
6e6cd5d9 325 myLastPicked->Unhighlight();
7fd59977 326 UpdVwr = Standard_True;
327 } // end if the last picked object isn't selected one
328
329 if ( myResetDetect ) {
330
331 theDrawer->SetOverride(Standard_True);
332 theDrawer->SetOverrideColor( theViewer->InitializeColor(myICTX->HighlightColor()) );
333 theDrawer->BeginDraw( aView->Driver() );
334
335 for ( int i = 1 ; i <= thePickList->Length(); i++ ) {
336
337 myLastPicked = Handle(AIS2D_InteractiveObject)::DownCast( thePickList->Value(i) );
338 myLastinMain = myLastPicked;
339
340
341 if ( myLastPicked->HasHighlightMode() ) {
342
343 myLastPicked->Highlight(theViewer->InitializeColor(myICTX->HighlightColor()));
344 switch( myLastPicked->HighlightMode() ) {
345 default:
346 case AIS2D_TOD_OBJECT:
347 if ( myLastPicked->State() != 1 ) {
348 theDrawer->Draw( myLastPicked );
349 } else {
350 theStat = AIS2D_SOD_Selected;
351 }
352 break;
353 case AIS2D_TOD_PRIMITIVE:
354 myLastPickPrim = myLastPicked->Primitive(myLastPicked->PickedIndex());
355 if ( !myLastPickPrim->IsHighlighted() ) {
356 theDrawer->Draw(myLastPickPrim);
357 } else {
358 theStat = AIS2D_SOD_Selected;
359 }
360 break;
361 case AIS2D_TOD_ELEMENT: {
362 Standard_Integer pInd = myLastPicked->PickedIndex();
363 myLastPickPrim = myLastPicked->Primitive(pInd);
364 if ( myLastPickPrim != myLastSelPrim ||
365 ( myLastPickPrim == myLastSelPrim &&
366 myLastPickPrim->PickedIndex() != myLastSelElInd ) ||
367 ( !myLastPickPrim->PickedIndex() &&
368 !myLastPickPrim->IsHighlighted() ) ) {
369 myLastPickElInd = myLastPickPrim->PickedIndex();
370 theDrawer->DrawElement(myLastPickPrim,myLastPickElInd);
371 } else {
372 theStat = AIS2D_SOD_Selected;
373 }
374 break;
375 }
376 case AIS2D_TOD_VERTEX: {
377 myLastPickPrim = myLastPicked->Primitive(myLastPicked->PickedIndex());
7fd59977 378 if ( myLastPickPrim != myLastSelPrim ||
379 ( myLastPickPrim == myLastSelPrim &&
380 myLastPickPrim->PickedIndex() != myLastSelElInd ) ||
381 ( !myLastPickPrim->PickedIndex() &&
382 !myLastPickPrim->IsHighlighted() ) ) {
383 myLastPickElInd = myLastPickPrim->PickedIndex();
384 theDrawer->DrawVertex(myLastPickPrim,-myLastPickElInd);
385 } else {
386 theStat = AIS2D_SOD_Selected;
387 }
388 break;
389 }
390 } //end switch
391 } // end if lastPicked has highlight mode
392
393 } // end for
394
395 theDrawer->EndDraw();
396 theDrawer->SetOverride(Standard_False);
397 myResetDetect= Standard_False;
398
399 } // end if myResetDetect is true
400
401 } else {
402
403 theStat = AIS2D_SOD_Nothing;
404 theDrawer->RestoreArea( aView->Driver() );
405 myResetDetect= Standard_True;
406 if ( !myLastPicked.IsNull() ) {
407 if ( myLastPicked->HighlightMode() == AIS2D_TOD_ELEMENT ||
408 myLastPicked->HighlightMode() == AIS2D_TOD_VERTEX ) {
409 myLastPicked->Highlight(theViewer->InitializeColor( myICTX->SelectionColor() ));
410
411 myLastPicked->Unhighlight();
412 UpdVwr = Standard_True;
413 } else if ( !myLastPicked->State() ) {
414 myLastPicked->Unhighlight();
415 UpdVwr = Standard_True;
416 }
417 }
418
419 myLastinMain.Nullify();
420 myLastPickPrim.Nullify();
421 myLastPickElInd = 0;
422
423 } // end if PickList isn't empty
424
425 //if ( !myLastPicked.IsNull() ) myLastPicked->Unhighlight();
426
427 if ( UpdVwr ) theViewer->Update();
428
429 myLastPicked.Nullify();
430 //myLastMoveView = aView;
431 return theStat;
432
433 } else
434 return AIS2D_SOD_Error;
435
436}
437
438AIS2D_StatusOfPick AIS2D_LocalContext::Select( const Standard_Boolean UpdateVwr ) {
439
440 if ( myAutoHighlight )
441 UnhighlightPicked( Standard_False );
442
443 Standard_Integer DI = DetectedIndex();
444// AIS2D_Selection::SetCurrentSelection( mySelName.ToCString() );
445// Standard_Integer NbSel = AIS2D_Selection::Extent();
446 Standard_Integer NbSel = myICTX->mySeqOfSelIO->Length();
447 if ( DI <= 0 ) {
448 ClearSelected( UpdateVwr );
449 return NbSel == 0 ? AIS2D_SOP_NothingSelected : AIS2D_SOP_Removed;
450 }
451
452 if ( myAutoHighlight )
453 HighlightPicked( UpdateVwr );
454 //return ( AIS2D_Selection::Extent() == 1) ? AIS2D_SOP_OneSelected : AIS2D_SOP_SeveralSelected;
455 return ( myICTX->mySeqOfSelIO->Length() == 1) ? AIS2D_SOP_OneSelected : AIS2D_SOP_SeveralSelected;
456}
457
458AIS2D_StatusOfPick AIS2D_LocalContext::ShiftSelect( const Standard_Boolean /*UpdateVwr*/ ) {
459
460/* Standard_Integer I = DetectedIndex();
461 if ( I > 0 ) {
462 UnhighlightPicked(Standard_False);
463
464 AIS2D_Selection::SetCurrentSelection(mySelName.ToCString());
465 const Handle(SelectMgr_EntityOwner)& EntOwr = myMapOfOwner(I);
466 Standard_Integer mod = EntOwr->State() == 0 ? 1 : 0;
467 EntOwr->State(mod);
468
469 AIS2D_Selection::Select(EntOwr);
470
471 if ( myAutoHighlight )
472 HighlightPicked(UpdateVwr);
473 }*/
474 return AIS2D_SOP_Error;
475}
476
477void AIS2D_LocalContext::SetDisplayPriority(
478 const Handle(AIS2D_InteractiveObject)& anIObj,
479 const Standard_Integer /*Prior*/ ) {
480
481 if ( !myActiveObjects.IsBound(anIObj) ) return;
482 const Handle(AIS2D_LocalStatus)& LStatus = myActiveObjects(anIObj);
483 if ( LStatus->DisplayMode() == -1) return;
484 //myMainPM->SetDisplayPriority(anIObj, LStatus->DisplayMode(),Prior);
485 //if ( LStatus->IsSubIntensityOn())
486 // myMainPM->SetDisplayPriority(anIObj, LStatus->HighlightMode(), Prior);
487
488}
489
490Standard_Integer AIS2D_LocalContext::DisplayedObjects(TColStd_MapOfTransient& theMap) const {
491
492 Standard_Integer NbDisp(0);
493 for ( AIS2D_DataMapIteratorOfDataMapOfLocStat theIt(myActiveObjects); theIt.More(); theIt.Next() ) {
494 const Handle(AIS2D_InteractiveObject)& SObj = theIt.Key();
495 if ( !theMap.Contains(SObj) )
496 if ( theIt.Value()->DisplayMode() != -1 ) {
497 theMap.Add(SObj);
498 NbDisp++;
499 }
500 }
501 return NbDisp;
502}
503
504Standard_Boolean AIS2D_LocalContext::IsDisplayed(const Handle(AIS2D_InteractiveObject)& anIObj) const {
505
506 if ( !myActiveObjects.IsBound(anIObj) )
507 return Standard_False;
508 return ( myActiveObjects(anIObj)->DisplayMode() != -1 );
509}
510
511Standard_Boolean AIS2D_LocalContext::IsDisplayed(const Handle(AIS2D_InteractiveObject)& anIObj,
512 const Standard_Integer aMode) const {
513
514 if (!myActiveObjects.IsBound(anIObj)) return Standard_False;
515 return (myActiveObjects(anIObj)->DisplayMode()==aMode);
516}
517
518void AIS2D_LocalContext::Unhighlight(const Handle(AIS2D_InteractiveObject)& /*anIObj*/)
519{
520}
521
522Standard_Boolean AIS2D_LocalContext::IsHighlight(const Handle(AIS2D_InteractiveObject)& anIObj) const {
523
524 if ( !myActiveObjects.IsBound(anIObj) ) return Standard_False;
525 return myActiveObjects( anIObj )->IsSubIntensityOn();
526}
527
528Standard_Boolean AIS2D_LocalContext::IsHighlight(const Handle(AIS2D_InteractiveObject)& anIObj,
529 Standard_Boolean& WithColor,
530 Quantity_NameOfColor& HiCol) const
531{
532 if(!myActiveObjects.IsBound(anIObj)) return Standard_False;
533 if( myActiveObjects(anIObj)->IsSubIntensityOn()){
534 HiCol = myActiveObjects(anIObj)->HighlightColor();
535 if(HiCol==Quantity_NOC_WHITE)
536 WithColor = Standard_True;
537 else
538 WithColor = Standard_False;
539 return Standard_True;
540 }
541 return Standard_False;
542}
543
544void AIS2D_LocalContext::SubIntensityOn(const Handle(AIS2D_InteractiveObject)& anIObj) {
545
546 if ( !myActiveObjects.IsBound(anIObj) ) return;
547
548 const Handle(AIS2D_LocalStatus)& LStatus = myActiveObjects(anIObj);
549 if ( LStatus->IsTemporary() ) {
550 Quantity_NameOfColor aCol = myICTX->SubIntensityColor();
551 myICTX->HighlightWithColor(anIObj, aCol);
552 }
553 LStatus->SubIntensityOn();
554}
555
556void AIS2D_LocalContext::SubIntensityOff(const Handle(AIS2D_InteractiveObject)& anIObj) {
557
558 if ( !myActiveObjects.IsBound(anIObj) ) return;
559
560 const Handle(AIS2D_LocalStatus)& LStatus = myActiveObjects(anIObj);
561
562 if ( LStatus->IsTemporary())
563 myICTX->Unhighlight(anIObj);
564 LStatus->SubIntensityOff();
565}
566
567Standard_Boolean AIS2D_LocalContext::IsIn( const Handle(AIS2D_InteractiveObject)& anIObj) const {
568 return myActiveObjects.IsBound(anIObj);
569}
570
571Standard_Boolean AIS2D_LocalContext::UnhighLastDetect(const Handle(V2d_View)& /*aView*/) {
572
573// if ( !IsValidIndex(myLastIndex) ) return Standard_False;
574/* myMainPM->BeginDraw();
575 const Handle(SelectMgr_EntityOwner)& Ownr = myMapOfOwner(myLastIndex);
576 Standard_Integer HM(0);
577 if ( Ownr->HasSelectable() ) {
578 Handle(SelectMgr_SelectableObject) SO = Ownr->Selectable();
579 HM = GetHiMod(* ( (Handle(AIS2D_InteractiveObject ) * ) & SO ) );
580 }
581 myMapOfOwner( myLastIndex )->Unhilight( myMainPM, HM );
582 myMainPM->EndDraw( aView );
583 */
584 myLastIndex =0;
585 return Standard_True;
586}
587
588void AIS2D_LocalContext::DrawObject( const Handle(AIS2D_InteractiveObject)& anIObj, const Standard_Integer /*aDispMode*/ ) {
589
590 if ( anIObj->IsKind(STANDARD_TYPE(AIS2D_ProjShape) ) ) {
591
592 Handle(AIS2D_ProjShape) thePS = Handle(AIS2D_ProjShape)::DownCast(anIObj);
593 Handle(Graphic2d_Line) theLines = thePS->GetPrimitives();
594 Handle(Prs2d_AspectLine) theAspLine;
595
596 if ( !anIObj->HasAspect(theLines) ) {
597 Handle(Prs2d_AspectRoot) theAspRoot = anIObj->Attributes()->FindAspect(Prs2d_AN_LINE);
598 theAspLine = Handle(Prs2d_AspectLine)::DownCast(theAspRoot);
599 anIObj->SetAspect( theAspLine, theLines );
600
601 } else {
602 theAspLine = Handle(Prs2d_AspectLine)::DownCast( anIObj->GetAspect(theLines) );
603 }
604
605 Quantity_Color aColor;
606 Aspect_TypeOfLine aType;
607 Aspect_WidthOfLine aWidth;
608
609 theAspLine->ValuesOfLine( aColor, aType, aWidth );
610
611 Standard_Integer colorInd = theAspLine->ColorIndex();
612 Standard_Integer typeInd = theAspLine->TypeIndex();
613 Standard_Integer widthInd = theAspLine->WidthIndex();
614
615 if ( !colorInd ) {
616 colorInd = myICTX->InitializeColor( aColor );
617 theLines->SetColorIndex( colorInd );
618 }
619
620 if ( !typeInd ) {
621 typeInd = myICTX->InitializeStyle( aType );
622 theLines->SetTypeIndex( typeInd );
623 }
624
625 if ( !widthInd ) {
626 widthInd = myICTX->InitializeWidth( aWidth );
627 theLines->SetWidthIndex( widthInd );
628 }
629
630 if ( thePS->IsHLMode() ) {
631 Handle(Graphic2d_Line) theHLines = thePS->GetHLPrimitives();
632 theHLines->SetColorIndex( colorInd );
633 theHLines->SetWidthIndex( widthInd );
634 Standard_Integer theDashInd = myICTX->InitializeStyle( Aspect_TOL_DASH );
635 theHLines->SetTypeIndex( theDashInd );
636 }
637
638 } else {
639
640 Handle(Graphic2d_Primitive) thePrim;
641
642 for ( Standard_Integer i = 1; i <= anIObj->Length(); i++ ) {
643 thePrim = anIObj->Primitive( i );
644 if ( thePrim->IsKind(STANDARD_TYPE(Graphic2d_Line) ) ) {
645
646 Handle(Graphic2d_Line) theLine = Handle(Graphic2d_Line)::DownCast(thePrim);
647 Handle(Prs2d_AspectLine) theAspLine;
648
649 if ( !anIObj->HasAspect(theLine) ) {
650 Handle(Prs2d_AspectRoot) theAspRoot = anIObj->Attributes()->FindAspect(Prs2d_AN_LINE);
651 theAspLine = Handle(Prs2d_AspectLine)::DownCast(theAspRoot);
652 anIObj->SetAspect( theAspLine, theLine );
653
654 } else {
655 theAspLine = Handle(Prs2d_AspectLine)::DownCast( anIObj->GetAspect(theLine) );
656 }
657
658 Quantity_Color aColor;
659 Aspect_TypeOfLine aType;
660 Aspect_WidthOfLine aWidth;
661
662 Quantity_Color aIntColor;
663 Graphic2d_TypeOfPolygonFilling aTypeFill;
664 Standard_Integer aTile;
665 Standard_Boolean aDrawEdge;
666
667 theAspLine->ValuesOfLine( aColor, aType, aWidth );
668 theAspLine->ValuesOfPoly( aIntColor, aTypeFill, aTile, aDrawEdge );
669
670 Standard_Integer colorInd = theAspLine->ColorIndex();
671 Standard_Integer typeInd = theAspLine->TypeIndex();
672 Standard_Integer widthInd = theAspLine->WidthIndex();
673 Standard_Integer colorIntInd = theAspLine->InterColorIndex();
674
675 if ( !colorInd ) {
676 colorInd = myICTX->InitializeColor( aColor );
677 theLine->SetColorIndex( colorInd );
678 }
679
680 if ( !typeInd ) {
681 typeInd = myICTX->InitializeStyle( aType );
682 theLine->SetTypeIndex( typeInd );
683 }
684
685 if ( !widthInd ) {
686 widthInd = myICTX->InitializeWidth( aWidth );
687 theLine->SetWidthIndex( widthInd );
688 }
689
690 if ( !colorIntInd ) {
691 colorIntInd = myICTX->InitializeColor( aIntColor );
692 theLine->SetInteriorColorIndex( colorIntInd );
693 }
694
695 theLine->SetTypeOfPolygonFilling( aTypeFill );
696 theLine->SetInteriorPattern( aTile );
697 theLine->SetDrawEdge( aDrawEdge );
698
699 if ( theLine->IsKind(STANDARD_TYPE(Prs2d_Point) ) ) {
700
701 Handle(Prs2d_Point) thePnt = Handle(Prs2d_Point)::DownCast(theLine);
702 thePnt->SetIndex( myICTX->InitializeMarker( thePnt->Marker() ) );
703 }
704
705 } // end if the kind of primitive is Graphic2d_Line
706
707 } // end for exploration of the interactive object
708
709 } // end if IO is AIS2D_ProjShape
710
711}
712
713void AIS2D_LocalContext::ClearObjects() {
714
715 AIS2D_DataMapIteratorOfDataMapOfLocStat It( myActiveObjects );
716 for ( ; It.More(); It.Next() ) {
717 Handle(AIS2D_InteractiveObject) SObj = Handle(AIS2D_InteractiveObject)::DownCast( It.Key() );
718
719 const Handle(AIS2D_LocalStatus) LStatus = It.Value();
720// TColStd_ListIteratorOfListOfInteger ItL;
721
722 AIS2D_DisplayStatus theDS = myICTX->DisplayStatus( SObj );
723
724 if ( theDS != AIS2D_DS_Displayed){
725 //if ( myMainPM->IsDisplayed( SObj, LStatus->DisplayMode() ) ) {
726 if ( myICTX->IsDisplayed(SObj) ) {
727 if ( LStatus->IsSubIntensityOn() && SObj->IsHighlighted() )
728 SObj->Unhighlight();
729 SObj->Remove();
730 }
731
732 if ( LStatus->IsTemporary() )
733 SObj->Remove();
734 } else {
735 if ( LStatus->IsSubIntensityOn() ) {
736 myICTX->SubIntensityOff(Handle(AIS2D_InteractiveObject)::DownCast(SObj) ); }
737 Standard_Integer DiMo = SObj->HasDisplayMode() ? SObj->DisplayMode() : myICTX->DisplayMode();
738 if ( LStatus->DisplayMode() !=-1 && LStatus->DisplayMode() != DiMo)
739 SObj->Remove();
740 }
741
742 }
743 ClearSelected();
744 myActiveObjects.Clear();
745
746}
747
748
749void AIS2D_LocalContext::ClearDetected() {
750
751 /*for ( Standard_Integer i = 1; i <= myMapOfOwner.Extent(); i++ ) {
752 if ( !myMapOfOwner(i).IsNull() ) {
753 if ( myMapOfOwner(i)->IsHilighted(myMainPM) )
754 myMapOfOwner(i)->Unhilight(myMainPM);
755 else if ( myMapOfOwner(i)->IsHilighted( myICTX->CollectorPrsMgr() ) )
756 myMapOfOwner(i)->Unhilight( myICTX->CollectorPrsMgr() );
757 else {
758 const Handle(SelectMgr_SelectableObject)& SO =
759 myMapOfOwner.FindKey(i)->Selectable();
760 if ( myActiveObjects.IsBound(SO) ) {
761 const Handle(AIS2D_LocalStatus)& LStatus = myActiveObjects(SO);
762 if ( LStatus->IsTemporary() &&
763 LStatus->DisplayMode() == -1 &&
764 LStatus->SelectionModes()->IsEmpty() )
765
766 myMapOfOwner(i)->Clear(myMainPM);
767
768 }
769 }
770 }
771 } */
772}
773
774void AIS2D_LocalContext::ClearSelected(const Standard_Boolean UpdateVwr) {
775
776 UnhighlightPicked(UpdateVwr);
777 // AIS2D_Selection::SetCurrentSelection(mySelName.ToCString());
778
779 // Handle(AIS2D_Selection) Sel = AIS2D_Selection::CurrentSelection();
780 /*Handle(Standard_Transient) Tr;
781 Handle(SelectMgr_EntityOwner) EO;
782 const TColStd_Array1OfTransient& Obj = Sel->Objects()->Array1();
783 for ( Standard_Integer i = Obj.Lower(); i <= Sel->NbStored(); i++ ) {
784 Tr = Obj(i);
785 if ( !Tr.IsNull() )
786 (*((Handle(SelectMgr_EntityOwner)*)&Tr))->State(0);
787 } */
788 //AIS2D_Selection::Select();
789 myLastIndex = 0;
790}
791
792void AIS2D_LocalContext::HighlightPicked(const Standard_Boolean /*UpdateVwr*/) {
793
794 /*Standard_Boolean updMain(Standard_False),updColl(Standard_False);
795 Quantity_NameOfColor SelCol = myICTX->SelectionColor();
796
797 Handle(AIS2D_Selection) Sel = AIS2D_Selection::Selection(mySelName.ToCString());
798 Handle(Standard_Transient) Tr;
799 Handle(SelectMgr_EntityOwner) Ownr;
800 Handle(PrsMgr_PresentationManager2d) PM = myMainPM;
801
802 const TColStd_Array1OfTransient& Obj = Sel->Objects()->Array1();
803 for ( Standard_Integer i = Obj.Lower(); i <= Sel->NbStored(); i++ ) {
804 Tr = Obj(i);
805 if ( !Tr.IsNull() ) {
806 Ownr = * ( (Handle(SelectMgr_EntityOwner) * ) &Tr );
807 Handle(AIS2D_InteractiveObject) IO;
808 if ( Ownr->HasSelectable() )
809 if ( !Ownr->ComesFromDecomposition() ) {
810 Handle(SelectMgr_SelectableObject) SO = Ownr->Selectable();
811 Handle(AIS2D_InteractiveObject) IO =
812 * ( (Handle(AIS2D_InteractiveObject) * ) &SO );
813 if ( myICTX->IsInCollector(IO) ) {
814 PM = myICTX->CollectorPrsMgr();
815 updColl = Standard_True;
816 } else
817 updMain = Standard_True;
818 } else
819 updMain = Standard_True;
820 else
821 updMain = Standard_True;
822 // endif HasSelectable
823 Handle(SelectMgr_SelectableObject) SO = Ownr->Selectable();
824 Standard_Integer HM = GetHiMod( * ( (Handle(AIS2D_InteractiveObject ) * ) &SO ) );
825 // Ownr->HilightWithColor( PM, myICTX->SelectionColor(), HM );
826 if ( Ownr->HasSelectable() ) {
827 Quantity_NameOfColor aCol = myICTX->SelectionColor();
828 Standard_Integer indCol = myICTX->CurrentViewer()->InitializeColor( aCol );
829 PM->SetHighlightColor( indCol );
830 PM->ColorHighlight( SO, indCol, HM );
831 }
832
833 } //endif
834 } //end for
835 if (UpdateVwr) {
836 if ( updMain ) myICTX->CurrentViewer()->Update();
837 if ( updColl ) myICTX->Collector()->Update();
838 } */
839}
840
841void AIS2D_LocalContext::UnhighlightPicked( const Standard_Boolean /*UpdateVwr*/ ) {
842
843 /*Standard_Boolean updMain(Standard_False), updColl(Standard_False);
844 Quantity_NameOfColor SelCol = myICTX->SelectionColor();
845
846 Handle(AIS2D_Selection) Sel = AIS2D_Selection::Selection(mySelName.ToCString());
847 Handle(Standard_Transient) Tr;
848 Handle(SelectMgr_EntityOwner) Ownr;
849 Handle(PrsMgr_PresentationManager2d) PM = myMainPM;
850
851 const TColStd_Array1OfTransient& Obj = Sel->Objects()->Array1();
852 for ( Standard_Integer i = Obj.Lower(); i <= Sel->NbStored(); i++ ) {
853 Tr = Obj(i);
854 if ( !Tr.IsNull() ) {
855 Ownr = * ( (Handle(SelectMgr_EntityOwner) * ) &Tr );
856 Standard_Integer HM(0);
857 if ( Ownr->HasSelectable() )
858 if ( !Ownr->ComesFromDecomposition() ) {
859 Handle(SelectMgr_SelectableObject) SO = Ownr->Selectable();
860 Handle(AIS2D_InteractiveObject) IO =
861 * ( (Handle(AIS2D_InteractiveObject) * ) &SO );
862 HM = GetHiMod(IO);
863 if ( myICTX->IsInCollector(IO) ) {
864 PM = myICTX->CollectorPrsMgr();
865 updColl = Standard_True;
866 } else
867 updMain = Standard_True;
868 } else
869 updMain = Standard_True;
870 // endif HasSelectable
871 Ownr->Unhilight( PM, HM );
872 } //end if
873 } //end for
874
875 if ( UpdateVwr ) {
876 if ( updMain ) myICTX->CurrentViewer()->Update();
877 if ( updColl ) myICTX->Collector()->Update();
878 } */
879}
880
881Standard_Boolean AIS2D_LocalContext::IsValidForSelection(const Handle(AIS2D_InteractiveObject)& /*anIObj*/) const {
882
883 // return myFilter->IsOk(new SelectMgr_EntityOwner(anIObj));
884 return Standard_False;
885}
886
887void AIS2D_LocalContext::UpdateSelected(const Standard_Boolean UpdateVwr) {
888
889 UnhighlightPicked(Standard_False);
890 HighlightPicked(UpdateVwr);
891}
892
893void AIS2D_LocalContext::SetSelected( const Handle(AIS2D_InteractiveObject)& /*anIObj*/,
894 const Standard_Boolean /*UpdateVwr*/ ) {
895
896 /*if ( !IsValidForSelection(anIObj) ) return;
897 UnhighlightPicked(Standard_False);
898
899 Handle(AIS2D_Selection) sel = AIS2D_Selection::Selection(mySelName.ToCString());
900 Standard_Boolean found(Standard_False);
901 Handle(Standard_Transient) Tr;
902 Handle(SelectMgr_EntityOwner) EntOwr = FindSelectedOwnerFromIO(anIObj);
903 if ( EntOwr.IsNull() ) {
904 if ( anIObj->HasSelection(0) ) {
905 const Handle(SelectMgr_Selection)& SIObj = anIObj->Selection(0);
906 SIObj->Init();
907 if ( SIObj->More() ) {
908 Handle(SelectBasics_EntityOwner) BO = SIObj->Sensitive()->OwnerId();
909 EntOwr = *( (Handle(SelectMgr_EntityOwner) * ) & BO );
910 }
911 }
912 if ( EntOwr.IsNull() )
913 EntOwr = new SelectMgr_EntityOwner(anIObj);
914 }
915
916 ClearSelected(Standard_False);
917 EntOwr->State(1);
918 AIS2D_Selection::Select(EntOwr);
919 HighlightPicked(UpdateVwr);
920 */
921}
922
923void AIS2D_LocalContext::AddOrRemoveSelected(
924 const Handle(AIS2D_InteractiveObject)& /*anIObj*/,
925 const Standard_Boolean /*UpdateVwr*/) {
926
927 /*if ( !IsValidForSelection(anIObj) ) return;
928 UnhighlightPicked(Standard_False);
929 Handle(SelectMgr_EntityOwner) EntOwr;
930
931 EntOwr = FindSelectedOwnerFromIO(anIObj);
932 if ( !EntOwr.IsNull() )
933 EntOwr->State(0);
934 else {
935 if ( anIObj->HasSelection(0) ) {
936 const Handle(SelectMgr_Selection)& SIObj = anIObj->Selection(0);
937 SIObj->Init();
938 if ( SIObj->More() ) {
939 Handle(SelectBasics_EntityOwner) BO = SIObj->Sensitive()->OwnerId();
940 EntOwr = * ( ( Handle(SelectMgr_EntityOwner)* )& BO );
941 }
942 }
943 if ( EntOwr.IsNull() )
944 EntOwr = new SelectMgr_EntityOwner(anIObj);
945 EntOwr->State(1);
946 }
947
948 const Handle(AIS2D_Selection)& aSel = AIS2D_Selection::Selection(mySelName.ToCString() );
949 if ( !aSel.IsNull() )
950 aSel->Select(EntOwr);
951 HighlightPicked(UpdateVwr);
952 */
953}
954
955Standard_Integer AIS2D_LocalContext::DetectedIndex() {
956 return myLastIndex;
957}
958
959const Handle(AIS2D_LocalStatus)& AIS2D_LocalContext::Status(const Handle(AIS2D_InteractiveObject)& anObject) const {
960 return myActiveObjects(anObject);
961}
962