summaryrefslogtreecommitdiff
path: root/src/Graphic2d/Graphic2d_View.cxx
blob: 6019bd687abade73caf5c89a3935f556427ccdc4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
// File:  Graphic2d_View.cxx
// Created: Mon Nov 22 18:50:16 1993
// Author:  Stephane CALLEGARI
//    <cal@sparc5>
// Modified     23/07/98 : DCB ; Remove WNT specific since WNT_DDriver
//                        inherits from PlotterDriver

#define xTRACE

#define CSR_PRO12324        //SYL_030798
//                      No plot if object not plottable                      
//
// Modified     17/12/1998 SYL pour S3604
//              Aspect_PlotterDriver devient PlotMgt_PlotterDriver

#define BUC60639        //GG_220300
//              the Remove() method must sets correctly
//              all GraphicObjects fields

#define G002		//GG_180400
//			-> Drawer become a TransientManager for
//			  open detection and dragging facilities

#define OCC154 // jfa 06/03/2002 // for correct erasing

#define OCC402  // SAV 14/11/01 Added PickByCircle().

#include <Standard_Type.hxx>
#include <Graphic2d_View.ixx>
#include <Aspect_WindowDriver.hxx>
#include <PlotMgt_PlotterDriver.hxx>
#include <Aspect_Window.hxx>
#include <Aspect_Units.hxx>
#include <Graphic2d_DetectionColorError.hxx>

Graphic2d_View::Graphic2d_View ():
        myGraphicObjects (),
        myGraphicAltitudes (),
        myBuffers (),
        myOverrideColorIsDef (Standard_False),
        myDeflection (0.001 METER),
        myDeflectionCoefficient (1./3000.),
        myTypeOfDeflection (Aspect_TOD_RELATIVE),
        myXCenter (0.),
        myYCenter (0.),
        mySize (1. METER), 
        myXPosition (0.),
        myYPosition (0.),
        myScale (1.),
        myTextPrecision (0.0015 METER) {
#ifdef G002
        myDrawer        = new Graphic2d_TransientManager(this);
#else
        myDrawer        = new Graphic2d_Drawer;
#endif
}

void Graphic2d_View::Add (const Handle(Graphic2d_Buffer)& aBuffer) { 
Standard_Integer i,l = myBuffers.Length ();

        for ( i=1; i<=l ; i++) {
          if (myBuffers.Value (i) == aBuffer) break;
        }

        if (i > l) myBuffers.Append (aBuffer);
}

Standard_Integer Graphic2d_View::Add (const Handle(Graphic2d_GraphicObject)& aGraphicObject,const Standard_Integer anAltitude) { 
Standard_Integer i,l = myGraphicAltitudes.Length();

        for( i=l ; i>0 ; --i ) {
          if( anAltitude >= myGraphicAltitudes.Value(i) ) break;
        }
        if( i < l ) {
          myGraphicObjects.InsertAfter (i, aGraphicObject);
          myGraphicAltitudes.InsertAfter (i, anAltitude);
          i++;
        } else {
          myGraphicObjects.Append (aGraphicObject);
          myGraphicAltitudes.Append (anAltitude);
          i = l+1;
        }
        return i;
}

Standard_Integer Graphic2d_View::Change (const Handle(Graphic2d_GraphicObject)& aGraphicObject,const Standard_Integer anAltitude) { 
Standard_Integer i,l = myGraphicObjects.Length ();

        for ( i=1; i<=l ; i++) {
          if (myGraphicObjects.Value (i) == aGraphicObject) break;
        }

        if ( i > l ) i = 0;
        else if( myGraphicAltitudes.Value (i) != anAltitude ) {
          myGraphicObjects.Remove (i);
          myGraphicAltitudes.Remove (i);
          i = 0;
        }

        if( i == 0 ) {
          i = Add(aGraphicObject,anAltitude);
        }

        return i;
}

void Graphic2d_View::Remove (const Handle(Graphic2d_Buffer)& aBuffer) { 
Standard_Integer i,l = myBuffers.Length ();

        for ( i=1; i<=l ; i++) {
          if (myBuffers.Value (i) == aBuffer) break;
        }

        if (i <= l) myBuffers.Remove (i);
}

Standard_Integer Graphic2d_View::Remove (const Handle(Graphic2d_GraphicObject)& aGraphicObject) { 
Standard_Integer i,l = myGraphicObjects.Length ();

        for ( i=1; i<=l ; i++) {
          if (myGraphicObjects.Value (i) == aGraphicObject) break;
        }

        if ( i > l ) i = 0;
        else {
          myGraphicObjects.Remove (i);
          myGraphicAltitudes.Remove (i);
        }

        return i;
}

void Graphic2d_View::Destroy () {
Standard_Integer Length = myGraphicObjects.Length();
Standard_Integer i;

  for (i=1; i<=Length; i++)
    myGraphicObjects.Value(i)->RemovePrimitives ();
  myGraphicObjects.Clear();
  myGraphicAltitudes.Clear();
}

void Graphic2d_View::SetDefaultOverrideColor (const Standard_Integer anIndex) {

        myOverrideColorIsDef    = Standard_True;
        myDefaultOverrideColor  = anIndex;

}

Standard_Integer Graphic2d_View::DefaultOverrideColor() const { 

        if (! myOverrideColorIsDef)
                Graphic2d_OverrideColorError::Raise
                        ("No defined override color index");

        return myDefaultOverrideColor;

}

Standard_Boolean Graphic2d_View::IsDefinedColor() const { 

        return myOverrideColorIsDef;

}

void Graphic2d_View::Update (const Handle(Aspect_Driver)& aDriver,
                             const Handle(Graphic2d_ViewMapping)& aViewMapping,
                             const Standard_Real aXPosition, 
                             const Standard_Real aYPosition, 
                             const Standard_Real aScale,
                             const Standard_Boolean ClearBefore) {

#ifdef TRACE
cout << "Graphic2d_View::Update (Aspect_Driver)\n" << flush;
#endif

Standard_Integer GOLength       = myGraphicObjects.Length();
Standard_Integer GBLength       = myBuffers.Length();
Standard_Integer i;
Standard_Real XCenter, YCenter, Size;

        aViewMapping->ViewMapping(XCenter, YCenter, Size);
        myXCenter       = Standard_ShortReal (XCenter);
        myYCenter       = Standard_ShortReal (YCenter);
        mySize  = Standard_ShortReal (Size);
        myXPosition     = Standard_ShortReal (aXPosition);
        myYPosition     = Standard_ShortReal (aYPosition);
        myScale = Standard_ShortReal (aScale);
        myZoom  = Standard_ShortReal (aViewMapping->Zoom());

        myDrawer->SetValues (XCenter, YCenter, Size, 
                                aXPosition, aYPosition, myScale, myZoom);
        myDrawer->SetDrawPrecision
                (myDeflection, myDeflectionCoefficient, myTypeOfDeflection);
        myDrawer->SetTextPrecision(myTextPrecision);
        myDrawer->SetDriver(aDriver);

        if( aDriver->IsKind(STANDARD_TYPE(Aspect_WindowDriver)) ) {
          Handle(Aspect_WindowDriver) theDriver =
                *(Handle(Aspect_WindowDriver) *) &aDriver;
          theDriver->BeginDraw(Standard_True);
          if( ClearBefore ) {
            theDriver->Window()->Clear();
          }
          for (i=1; i<=GOLength; i++)
                myGraphicObjects.Value(i)->Redraw (myDrawer);
          aDriver->EndDraw();
          for (i=1; i<=GBLength; i++) {
            Handle(Graphic2d_Buffer) theBuffer = myBuffers.Value(i);
            if( theBuffer->IsPosted(theDriver) ) {
              theBuffer->ReLoad (Standard_True);
            }
          }
        } else if( aDriver->IsKind(STANDARD_TYPE(PlotMgt_PlotterDriver)) ) {
          Handle(PlotMgt_PlotterDriver) theDriver =
                *(Handle(PlotMgt_PlotterDriver) *) &aDriver;
          theDriver->BeginDraw();
          for (i=1; i<=GOLength; i++)
#ifdef CSR_PRO12324     
            if( myGraphicObjects.Value(i)->IsPlottable())             
#endif
                myGraphicObjects.Value(i)->Redraw (myDrawer);
          aDriver->EndDraw();
        }
}

void Graphic2d_View::TinyUpdate (const Handle(Aspect_Driver)& aDriver,
                             const Handle(Graphic2d_ViewMapping)& aViewMapping,
                             const Standard_Real aXPosition, 
                             const Standard_Real aYPosition, 
                             const Standard_Real aScale,
                             const Standard_Boolean Reset) {

#ifdef TRACE
cout << "Graphic2d_View::TinyUpdate (Aspect_Driver)\n" << flush;
#endif

Standard_Integer i,Length       = myGraphicObjects.Length ();
Standard_Real XCenter, YCenter, Size;

        aViewMapping->ViewMapping(XCenter, YCenter, Size);
        myXCenter       = Standard_ShortReal (XCenter);
        myYCenter       = Standard_ShortReal (YCenter);
        mySize  = Standard_ShortReal (Size);
        myXPosition     = Standard_ShortReal (aXPosition);
        myYPosition     = Standard_ShortReal (aYPosition);
        myScale = Standard_ShortReal (aScale);
        myZoom  = Standard_ShortReal (aViewMapping->Zoom());

        myDrawer->SetValues (XCenter, YCenter, Size, 
                                aXPosition, aYPosition, myScale, myZoom);
        myDrawer->SetDrawPrecision
                (myDeflection, myDeflectionCoefficient, myTypeOfDeflection);
        myDrawer->SetTextPrecision(myTextPrecision);
        myDrawer->SetDriver(aDriver);

        if( aDriver->IsKind(STANDARD_TYPE(Aspect_WindowDriver)) ) {
          Handle(Aspect_WindowDriver) theDriver =
                *(Handle(Aspect_WindowDriver) *) &aDriver;
          theDriver->BeginDraw(Standard_True);
        } else if( aDriver->IsKind(STANDARD_TYPE(PlotMgt_PlotterDriver)) ) {
          Handle(PlotMgt_PlotterDriver) theDriver =
                *(Handle(PlotMgt_PlotterDriver) *) &aDriver;
          theDriver->BeginDraw();
        }
        for (i=1; i<=Length; i++)
#ifdef CSR_PRO12324     
          if( myGraphicObjects.Value(i)->IsPlottable())               
#endif
            myGraphicObjects.Value (i)->Draw (myDrawer,Reset);
        aDriver->EndDraw ();
}

void Graphic2d_View::Update (const Handle(Aspect_Driver)& aDriver, const Handle(Graphic2d_GraphicObject)& aGraphicObject, const Handle(Graphic2d_ViewMapping)& aViewMapping, const Standard_Real aXPosition, const Standard_Real aYPosition, const Standard_Real aScale) {

#ifdef TRACE
cout << "Graphic2d_View::Update (Aspect_Driver, Graphic2d_GraphicObject)\n" << flush;
#endif

      if( IsIn (aGraphicObject) ) {
        Standard_Integer i,Length = aGraphicObject->Length ();
        Handle(Graphic2d_Primitive) aPrimitive;
        Standard_Real XCenter, YCenter, Size;

        aViewMapping->ViewMapping(XCenter, YCenter, Size);
        myXCenter       = Standard_ShortReal (XCenter);
        myYCenter       = Standard_ShortReal (YCenter);
        mySize  = Standard_ShortReal (Size);
        myXPosition     = Standard_ShortReal (aXPosition);
        myYPosition     = Standard_ShortReal (aYPosition);
        myScale = Standard_ShortReal (aScale);
        myZoom  = Standard_ShortReal (aViewMapping->Zoom());

        myDrawer->SetValues (XCenter, YCenter, Size, 
                                aXPosition, aYPosition, myScale, myZoom);
        myDrawer->SetDrawPrecision
                (myDeflection, myDeflectionCoefficient, myTypeOfDeflection);
        myDrawer->SetTextPrecision(myTextPrecision);
        myDrawer->SetDriver(aDriver);

        if( aDriver->IsKind(STANDARD_TYPE(Aspect_WindowDriver)) ) {
          Handle(Aspect_WindowDriver) theDriver =
                *(Handle(Aspect_WindowDriver) *) &aDriver;
          theDriver->BeginDraw(Standard_True);
        } else if( aDriver->IsKind(STANDARD_TYPE(PlotMgt_PlotterDriver)) ) {
          Handle(PlotMgt_PlotterDriver) theDriver =
                *(Handle(PlotMgt_PlotterDriver) *) &aDriver;
          theDriver->BeginDraw();
        }
        for (i=1; i<=Length ; i++) {
          aPrimitive = aGraphicObject->Primitive(i);
#ifdef CSR_PRO12324  
          if( !aDriver->IsKind(STANDARD_TYPE(Aspect_WindowDriver))
             || aGraphicObject->IsPlottable() )     
#endif  
            aGraphicObject->Draw (myDrawer, aPrimitive);
        }
        aDriver->EndDraw ();
      }
}

void Graphic2d_View::Update (const Handle(Aspect_Driver)& aDriver, const Handle(Graphic2d_Primitive)& aPrimitive, const Handle(Graphic2d_ViewMapping)& aViewMapping, const Standard_Real aXPosition, const Standard_Real aYPosition, const Standard_Real aScale) {

#ifdef TRACE
cout << "Graphic2d_View::Update (Aspect_Driver, Graphic2d_Primitive)\n" << flush;
#endif

Standard_Integer i,Length       = myGraphicObjects.Length ();
Standard_Boolean found  = Standard_False;
Standard_Real XCenter, YCenter, Size;

        aViewMapping->ViewMapping(XCenter, YCenter, Size);
        myXCenter       = Standard_ShortReal (XCenter);
        myYCenter       = Standard_ShortReal (YCenter);
        mySize  = Standard_ShortReal (Size);
        myXPosition     = Standard_ShortReal (aXPosition);
        myYPosition     = Standard_ShortReal (aYPosition);
        myScale = Standard_ShortReal (aScale);
        myZoom  = Standard_ShortReal (aViewMapping->Zoom());

        myDrawer->SetValues (XCenter, YCenter, Size, 
                                aXPosition, aYPosition, myScale, myZoom);
        myDrawer->SetDrawPrecision
                (myDeflection, myDeflectionCoefficient, myTypeOfDeflection);
        myDrawer->SetTextPrecision(myTextPrecision);
        myDrawer->SetDriver(aDriver);

        if( aDriver->IsKind(STANDARD_TYPE(Aspect_WindowDriver)) ) {
          Handle(Aspect_WindowDriver) theDriver =
                *(Handle(Aspect_WindowDriver) *) &aDriver;
          theDriver->BeginDraw(Standard_True);
        } else if( aDriver->IsKind(STANDARD_TYPE(PlotMgt_PlotterDriver)) ) {
          Handle(PlotMgt_PlotterDriver) theDriver =
                *(Handle(PlotMgt_PlotterDriver) *) &aDriver;
          theDriver->BeginDraw();
        }
        for (i=1; i<=Length && !found; i++) {
                found   = myGraphicObjects.Value (i)->IsIn (aPrimitive);
                if (found)
#ifdef CSR_PRO12324  
                  if( !aDriver->IsKind(STANDARD_TYPE(Aspect_WindowDriver)) 
                     || myGraphicObjects.Value (i)->IsPlottable() ) 
#endif  
                    myGraphicObjects.Value (i)->Draw (myDrawer, aPrimitive);
        }
        aDriver->EndDraw ();

}

Handle(Graphic2d_DisplayList) Graphic2d_View::DisplayList () const {
Standard_Integer Index;
Standard_Integer Length = myGraphicObjects.Length ();
Handle(Graphic2d_DisplayList) DL = new Graphic2d_DisplayList;

         for (Index=1; Index<=Length; Index++)
             DL->Append(myGraphicObjects.Value(Index));
         return DL;
}

Standard_Boolean Graphic2d_View::IsIn (const Handle(Graphic2d_GraphicObject)& aGraphicObject) const {
Standard_Integer Index = 0;
Standard_Integer Length = myGraphicObjects.Length ();

        for (Standard_Integer i=1; i<=Length && Index==0; i++)
                if (myGraphicObjects.Value (i) == aGraphicObject) Index = i;

        return (Index != 0);
}

void Graphic2d_View::MinMax (Quantity_Length& Minx, Quantity_Length& Maxx, Quantity_Length& Miny, Quantity_Length& Maxy) const {

Standard_Integer i,Length = myGraphicObjects.Length ();
Quantity_Length x, y, X, Y;
Standard_Real RL, RF;

        RL = Minx = Miny = ShortRealLast ();
        RF = Maxx = Maxy  = ShortRealFirst ();

        for (i=1; i<=Length; i++) {
                myGraphicObjects.Value (i)->MinMax (x, X, y, Y);
                // GraphicObject can be empty
                if (x > RF) Minx = (Minx < x ? Minx : x); 
                if (X < RL) Maxx = (Maxx > X ? Maxx : X);
                if (y > RF) Miny = (Miny < y ? Miny : y);
                if (Y < RL) Maxy = (Maxy > Y ? Maxy : Y);
        }

        // Attention, it is possible that :
        // Minx = Miny = ShortRealLast (); and
        // Maxx = Maxy = ShortRealFirst();
        if (Minx > Maxx) { Minx = RealFirst (); Maxx = RealLast (); }
        if (Miny > Maxy) { Miny = RealFirst (); Maxy = RealLast (); }
}

void Graphic2d_View::MinMax (const Handle(Graphic2d_DisplayList)& aList, Quantity_Length& Minx, Quantity_Length& Maxx, Quantity_Length& Miny, Quantity_Length& Maxy) const {

Standard_Integer i,Length = aList->Length ();
Quantity_Length x, y, X, Y;
Standard_Real RL, RF;

        RL = Minx = Miny = ShortRealLast ();
        RF = Maxx = Maxy = ShortRealFirst ();

        for (i=1; i<=Length; i++) {
                if (IsIn (aList->Value(i))) {
                        (aList->Value(i))->MinMax (x, X, y, Y);
                        //  GraphicObject can be empty
                        if (x > RF) Minx = (Minx < x ? Minx : x); 
                        if (X < RL) Maxx = (Maxx > X ? Maxx : X);
                        if (y > RF) Miny = (Miny < y ? Miny : y);
                        if (Y < RL) Maxy = (Maxy > Y ? Maxy : Y);
                }
        }

        // Attention, it is possible that :
        // Minx = Miny = ShortRealLast (); and
        // Maxx = Maxy = ShortRealFirst();
        if (Minx > Maxx) { Minx = RealFirst (); Maxx = RealLast (); }
        if (Miny > Maxy) { Miny = RealFirst (); Maxy = RealLast (); }
}

void Graphic2d_View::MarkerMinMax (Quantity_Length& Minx, Quantity_Length& Maxx, Quantity_Length& Miny, Quantity_Length& Maxy) const {

Standard_Integer i,Length = myGraphicObjects.Length ();
Quantity_Length x, y, X, Y;
Standard_Real RL, RF;

        RL = Minx = Miny = ShortRealLast ();
        RF = Maxx = Maxy = ShortRealFirst ();

        for (i=1; i<=Length; i++) {
                myGraphicObjects.Value (i)->MarkerMinMax (x, X, y, Y);
                // GraphicObject can be empty 
                if (x > RF) Minx = (Minx < x ? Minx : x); 
                if (X < RL) Maxx = (Maxx > X ? Maxx : X);
                if (y > RF) Miny = (Miny < y ? Miny : y);
                if (Y < RL) Maxy = (Maxy > Y ? Maxy : Y);
        }

        // Attention, it is possible that :
        // Minx = Miny = ShortRealLast (); and
        // Maxx = Maxy = ShortRealFirst();
        if (Minx > Maxx) { Minx = RealFirst (); Maxx = RealLast (); }
        if (Miny > Maxy) { Miny = RealFirst (); Maxy = RealLast (); }
}

void Graphic2d_View::MarkerMinMax (const Handle(Graphic2d_DisplayList)& aList, Quantity_Length& Minx, Quantity_Length& Maxx, Quantity_Length& Miny, Quantity_Length& Maxy) const {

Standard_Integer i,Length = aList->Length ();
Quantity_Length x, y, X, Y;
Standard_Real RL, RF;

        RL = Minx = Miny = ShortRealLast ();
        RF = Maxx = Maxy = ShortRealFirst ();

        for (i=1; i<=Length; i++) {
                if (IsIn (aList->Value(i))) {
                        (aList->Value(i))->MarkerMinMax (x, X, y, Y);
                        // GraphicObject can be empty
                        if (x > RF) Minx = (Minx < x ? Minx : x); 
                        if (X < RL) Maxx = (Maxx > X ? Maxx : X);
                        if (y > RF) Miny = (Miny < y ? Miny : y);
                        if (Y < RL) Maxy = (Maxy > Y ? Maxy : Y);
                }
        }

        // Attention, it is possible that :
        // Minx = Miny = ShortRealLast (); and
        // Maxx = Maxy = ShortRealFirst();
        if (Minx > Maxx) { Minx = RealFirst (); Maxx = RealLast (); }
        if (Miny > Maxy) { Miny = RealFirst (); Maxy = RealLast (); }
}

Standard_Integer Graphic2d_View::Position(const Handle(Graphic2d_GraphicObject)& aGraphicObject) const {
Standard_Integer i,l = myGraphicObjects.Length ();

        for ( i=1; i<=l ; i++) {
          if (myGraphicObjects.Value (i) == aGraphicObject) break;
        }

        return (i > l) ? 0 : i;
}

Standard_Integer Graphic2d_View::Altitude(const Handle(Graphic2d_GraphicObject)& aGraphicObject) const {
Standard_Integer i,l = myGraphicObjects.Length ();

        for ( i=1; i<=l ; i++) {
          if (myGraphicObjects.Value (i) == aGraphicObject) break;
        }

        return (i > l) ? -1 : myGraphicAltitudes.Value(i);
}

Handle(Graphic2d_DisplayList) Graphic2d_View::Pick
       (const Handle(Graphic2d_ViewMapping)& aViewMapping,
        const Standard_Real X,
        const Standard_Real Y,
        const Standard_Real aPrecision,
        const Standard_Real aXPosition, 
        const Standard_Real aYPosition, 
        const Standard_Real aScale) {

#ifdef G002
	if( myPickList.IsNull() )
		myPickList = new Graphic2d_DisplayList;
	else myPickList->Clear();
#else
Handle(Graphic2d_DisplayList) DL = new Graphic2d_DisplayList;
#endif
Standard_Integer Length = myGraphicObjects.Length ();
Standard_Integer Index;
Standard_Real XCenter,YCenter,Size,Zoom = aViewMapping->Zoom();

         aViewMapping->ViewMapping(XCenter,YCenter,Size);

         myDrawer->SetDrawPrecision(myDeflection*Zoom,
                                    myDeflectionCoefficient,
                                    myTypeOfDeflection);         
         myDrawer->SetValues (XCenter,YCenter,Size,
                                        aXPosition,aYPosition,aScale,Zoom);
         for (Index=Length; Index>0; --Index) {
           if (myGraphicObjects.Value(Index)->Pick(X,Y,aPrecision,myDrawer))
#ifdef G002
             myPickList->Append(myGraphicObjects.Value(Index));
#else
             DL->Append(myGraphicObjects.Value(Index));
#endif
         }

#ifdef G002
	 return myPickList;
#else
         return DL;
#endif
}

Handle(Graphic2d_DisplayList) Graphic2d_View
::PickByCircle( const Handle(Graphic2d_ViewMapping)& aViewMapping,
	        const Standard_Real X,
	        const Standard_Real Y,
	        const Standard_Real Radius,
	        const Standard_Real aXPosition, 
	        const Standard_Real aYPosition, 
	        const Standard_Real aScale)
{
  if( myPickList.IsNull() )
    myPickList = new Graphic2d_DisplayList;
  else myPickList->Clear();

#ifdef OCC402
  Standard_Integer Length = myGraphicObjects.Length();
  Standard_Integer Index;
  Standard_Real XCenter,YCenter,Size,Zoom = aViewMapping->Zoom();

  aViewMapping->ViewMapping( XCenter, YCenter, Size );

  myDrawer->SetDrawPrecision( myDeflection*Zoom,
			      myDeflectionCoefficient,
			      myTypeOfDeflection );         
  myDrawer->SetValues( XCenter, YCenter, Size,
		       aXPosition, aYPosition, aScale, Zoom );
  for ( Index = Length; Index > 0; --Index )
    if ( myGraphicObjects.Value( Index )->PickByCircle( X, Y, Radius, myDrawer ) )
      myPickList->Append(myGraphicObjects.Value(Index));
#endif
  return myPickList;
}


Handle(Graphic2d_DisplayList) Graphic2d_View::Pick
                  ( const Handle(Graphic2d_ViewMapping)& aViewMapping,
                    const Standard_Real Xmin,
                    const Standard_Real Ymin,
                    const Standard_Real Xmax,
                    const Standard_Real Ymax,
                    const Standard_Real aXPosition, 
                    const Standard_Real aYPosition, 
                    const Standard_Real aScale,
                    const Graphic2d_PickMode aPickMode ) {

#ifdef G002
	if ( myPickList.IsNull() )
		myPickList = new Graphic2d_DisplayList;
	else myPickList->Clear();
#else
    Handle(Graphic2d_DisplayList) DL = new Graphic2d_DisplayList;
#endif

    Standard_Integer Length = myGraphicObjects.Length ();
    Standard_Integer Index;
    Standard_Real XCenter, YCenter, Size, Zoom = aViewMapping->Zoom();

    aViewMapping->ViewMapping( XCenter, YCenter, Size );

    myDrawer->SetDrawPrecision( myDeflection * Zoom,
                                myDeflectionCoefficient,
                                myTypeOfDeflection );
    myDrawer->SetValues( XCenter, YCenter, Size,
                         aXPosition, aYPosition, aScale, Zoom );
    for ( Index = Length; Index > 0; --Index ) {
       if ( myGraphicObjects.Value(Index)->Pick( Xmin, Ymin, Xmax, Ymax, 
                                   myDrawer, aPickMode ) )
#ifdef G002
          myPickList->Append(myGraphicObjects.Value(Index));
#else
          DL->Append(myGraphicObjects.Value(Index));
#endif
    }

#ifdef G002
	 return myPickList;
#else
     return DL;
#endif
}

void Graphic2d_View::Erase() {
Standard_Integer Length = myGraphicObjects.Length ();
Standard_Integer Index;

  for (Index=1; Index<=Length; Index++)
    //myGraphicObjects.Value(Index)->Erase ();
    // CAL le 17/11/97.
    // 1 is set as it is required to remove N times the first from the list
    // Acytually this list is updated by method below
    // called by Graphic2d_GraphicObject::Erase.
#ifdef OCC154
    myGraphicObjects.Value(Index)->Erase();
#else
    myGraphicObjects.Value(1)->Erase ();
#endif
}

void Graphic2d_View::Erase (const Handle(Graphic2d_GraphicObject)& aGraphicObject) {
Standard_Integer Index = 0;
Standard_Integer Length = myGraphicObjects.Length ();

        for (Standard_Integer i=1; i<=Length && Index==0; i++)
                if (myGraphicObjects.Value (i) == aGraphicObject) Index = i;

        if (Index != 0) {
          myGraphicObjects.Remove (Index);
          myGraphicAltitudes.Remove (Index);
        }
}

void Graphic2d_View::Remove () {
#ifdef BUC60639
  Standard_Integer Length = myGraphicObjects.Length ();
  for (Standard_Integer i=1; i<=Length ; i++)
                myGraphicObjects.Value (1)->Remove();
#else
  myGraphicObjects.Clear();
  myGraphicAltitudes.Clear();
#endif
}

void Graphic2d_View::SetTypeOfDeflection(const Aspect_TypeOfDeflection aType) {
  myTypeOfDeflection = aType;
}

Aspect_TypeOfDeflection Graphic2d_View::TypeOfDeflection() const {
  return myTypeOfDeflection;
}


void Graphic2d_View::SetDeflection (const Quantity_Length aDeflection) {

  myDeflection = aDeflection;

}

Quantity_Length Graphic2d_View::Deflection() const { return myDeflection; }

void Graphic2d_View::SetDeflectionCoefficient(const Standard_Real aCoefficient) {
  myDeflectionCoefficient = aCoefficient;
}

Standard_Real Graphic2d_View::DeflectionCoefficient () const {
  return myDeflectionCoefficient;
}

void Graphic2d_View::SetTextPrecision (const Standard_Real aPrecision) {

  myTextPrecision = Standard_ShortReal(aPrecision);

}

Standard_Real Graphic2d_View::TextPrecision() const { return myTextPrecision;
}

void Graphic2d_View::Convert(const Handle(Graphic2d_ViewMapping)& aViewMapping,
                             const Standard_Real aDrawPositionX,
                             const Standard_Real aDrawPositionY,
                             const Standard_Real aXPosition,
                             const Standard_Real aYPosition,
                             const Standard_Real aScale,
                             Standard_Real& aX,
                             Standard_Real& aY) const {

          Standard_Real XCenter,YCenter,Size,Zoom = aViewMapping->Zoom();
          Standard_ShortReal xdraw = Standard_ShortReal(aDrawPositionX);
          Standard_ShortReal ydraw = Standard_ShortReal(aDrawPositionY);
          Standard_ShortReal xpos,ypos ;
          aViewMapping->ViewMapping(XCenter,YCenter,Size);
          myDrawer->SetValues (XCenter,YCenter,Size,
                                        aXPosition,aYPosition,aScale,Zoom);
          myDrawer->UnMapFromTo(xdraw,ydraw,xpos,ypos);
          aX = xpos ;
          aY = ypos ;

}

Standard_Real Graphic2d_View::Convert( const Handle(Graphic2d_ViewMapping)& aViewMapping,
                                      const Standard_Real aScalar,
                                      const Standard_Real aScale) const {

          Standard_Real XCenter,YCenter,Size;
          aViewMapping->ViewMapping(XCenter,YCenter,Size);
          return (aScalar / aScale) * Size;


}

Handle(Graphic2d_Drawer) Graphic2d_View::Drawer() const {

        return myDrawer ;
}