summaryrefslogtreecommitdiff
path: root/src/Graphic2d/Graphic2d_GraphicObject.cxx
blob: 189be4a157212133a3d4654aed50d9ba94ef2459 (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
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
//
// S3593    //GG_270298
//              Avoid calling IsKind() which is expensive.
//		Add field myIsUpToDate informing if the object is updated.
//		Add field myIsTransformed informing if the object is transformed.
//

#define G002	    //GG_140400
//		Add empty constructor and SetView() method.
//		Manage highlighting.
//      TCL : New method Pick(xmin, ymin, xmax, ymax,...)

#define OCC197 // jfa 01.03.2002

#define OCC154 // jfa 06.03.2002 // to erase instead of removing

#define OCC402   //SAV  14/11/01 Added PickByCircle(). Draw() was modified to be able
                 //              to draw selected elements of SetOfMarker.

#define OCC627   //SAV 16/08/02 new flag added to control visual object state

#include <Graphic2d_GraphicObject.ixx>
#include <Graphic2d_GraphicObject.pxx>

#include <Standard_ErrorHandler.hxx>

#define BASE_PRIORITY 1
#define HIGH_PRIORITY 0x7FFFFFFF
#define MAX_PRIORITY 999

Graphic2d_GraphicObject::Graphic2d_GraphicObject
       (const Handle(Graphic2d_View)& aView)
	:myOverrideColor (0),
	myCurrentIndex (1),
	myOffSet (0),
	myIsUpToDate (Standard_False),
	myIsTransformed (Standard_False),
	myPrimitives (),
    	myLayer (0),
	myTrsf (),
	myPickedIndex (0),
	myPriority(0) ,
    	myPickIndices(new TColStd_HSequenceOfInteger) {

	Plottable	= Standard_True;
	Drawable	= Standard_True;
	Pickable	= Standard_True;
	myIsDisplayed	= Standard_False;
	myIsHighlighted	= Standard_False;
	myViewPtr	= aView.operator->();
#ifdef OCC627
	myDisplayStatus = Graphic2d_DS_NONE;
#endif
}

Graphic2d_GraphicObject::Graphic2d_GraphicObject()
	:myOverrideColor (0),
	myCurrentIndex (1),
	myOffSet (0),
	myIsUpToDate (Standard_False),
	myIsTransformed (Standard_False),
	myPrimitives (),
        myLayer (0),
	myTrsf (),
	myPickedIndex (0),
	myPriority(0) ,
        myPickIndices(new TColStd_HSequenceOfInteger) {

	Plottable	= Standard_True;
	Drawable	= Standard_True;
	Pickable	= Standard_True;
	myIsDisplayed	= Standard_False;
	myIsHighlighted	= Standard_False;
	myViewPtr	= NULL;
#ifdef OCC627
	myDisplayStatus = Graphic2d_DS_NONE;
#endif
}

void Graphic2d_GraphicObject::SetView( const Handle(Graphic2d_View)& aView ) {

    myViewPtr   = aView.operator->();
}

void Graphic2d_GraphicObject::SetTransform (const gp_GTrsf2d& aTrsf,
			const Graphic2d_TypeOfComposition aType) {

        if( aType == Graphic2d_TOC_REPLACE ) {
          myTrsf = aTrsf;
        } else {
          myTrsf = aTrsf.Multiplied(myTrsf);
        }
	myIsTransformed = (aTrsf.Form() == gp_Identity) ? 
					Standard_False : Standard_True;
}

const gp_GTrsf2d& Graphic2d_GraphicObject::Transform () const {

	return myTrsf;

}

Standard_Boolean Graphic2d_GraphicObject::IsTransformed () const {
	return myIsTransformed;
}

void Graphic2d_GraphicObject::SetLayer (const Standard_Integer aLayer) {

	myLayer	= aLayer;

}

Standard_Integer Graphic2d_GraphicObject::Layer () const {

	return myLayer;

}

void Graphic2d_GraphicObject::SetPriority (const Standard_Integer aPriority) {

	if( aPriority < 0 || aPriority > MaxPriority() ) {
            Standard_OutOfRange::Raise (" Bad priority");
	}
	myPriority	= aPriority;
}

Standard_Integer Graphic2d_GraphicObject::Priority () const {

	return myPriority;

}

Standard_Integer Graphic2d_GraphicObject::BasePriority () const {

	return BASE_PRIORITY;

}

Standard_Integer Graphic2d_GraphicObject::MaxPriority () const {

	return MAX_PRIORITY;

}

void Graphic2d_GraphicObject::EnablePlot () {

	Plottable	= Standard_True;

}

void Graphic2d_GraphicObject::DisablePlot () {

	Plottable	= Standard_False;

}

Standard_Boolean Graphic2d_GraphicObject::IsPlottable () const {

	return Plottable;

}

void Graphic2d_GraphicObject::EnableDraw () {

	Drawable	= Standard_True;

}

void Graphic2d_GraphicObject::DisableDraw () {

	Drawable	= Standard_False;

}

Standard_Boolean Graphic2d_GraphicObject::IsDrawable () const {

	return Drawable;

}

Standard_Boolean Graphic2d_GraphicObject::IsIn (const Handle(Graphic2d_Primitive) & aPrimitive) const {
  return myPrimitives.Contains(aPrimitive);
}

void Graphic2d_GraphicObject::EnablePick () {

	Pickable	= Standard_True;

}

void Graphic2d_GraphicObject::DisablePick () {

	Pickable	= Standard_False;

}

Standard_Boolean Graphic2d_GraphicObject::IsPickable () const {

	return Pickable;

}

void Graphic2d_GraphicObject::SetPickedIndex (const Standard_Integer anIndex) {
      myPickedIndex = anIndex;
}

Standard_Integer Graphic2d_GraphicObject::PickedIndex () const {

	return myPickedIndex;
}

void Graphic2d_GraphicObject::Redraw (const Handle(Graphic2d_Drawer)& aDrawer) {

	myCurrentIndex	= 1;
	Draw (aDrawer,Standard_True);

}

void Graphic2d_GraphicObject::Draw (const Handle(Graphic2d_Drawer)& aDrawer, const Standard_Boolean Reset) {

	if (! Drawable) return;

	if (myIsDisplayed || myIsHighlighted) {
#ifdef G002
	  	aDrawer->SetOverrideColor (myOverrideColor);
#endif
		if (myIsHighlighted) {
          aDrawer->SetOverride (Standard_True);
#ifndef G002
          aDrawer->SetOverrideColor (myOverrideColor);
#endif
		} else {
		  aDrawer->SetOffSet (myOffSet);
		}

		Standard_Integer Length = myPrimitives.Extent ();
		Handle(Graphic2d_Primitive) aPrimitive;

		for (Standard_Integer i=myCurrentIndex; i<=Length; i++) {
		  aPrimitive = Primitive (i); 
		  // We draw the boundary rectangle of an image
		  // in a highlighted Graphic2d_GraphicObject
		  Standard_Boolean TheFlag = myIsHighlighted &&
	 			(aPrimitive->Family() == Graphic2d_TOP_IMAGE);
		  if (TheFlag) {
		    Standard_Integer ColorIndexSave = aPrimitive->ColorIndex ();
		    aPrimitive->SetColorIndex (myOverrideColor);
		    aPrimitive->Draw (aDrawer);
		    aPrimitive->SetColorIndex (ColorIndexSave);
		  } else {
#ifdef G002
		    if( aPrimitive->IsHighlighted() && !myIsHighlighted )
                    {
                      Handle(TColStd_HSequenceOfInteger) theHSeq = aPrimitive->HighlightIndices();
#ifdef OCC197
                      aPrimitive->Draw (aDrawer);
#endif
		      for ( Standard_Integer j = 1; j <= theHSeq->Length(); ++j )
                      {
                        Standard_Integer hindex = theHSeq->Value(j);
                        if( hindex != 0 ) {	// Highlight a part of primitive
#ifndef OCC197
// if we draw a primitive in cycle, it hides its own highlighted parts except the last one
		           aPrimitive->Draw (aDrawer);
#endif
		           aDrawer->SetOverride (Standard_True);
		           if( hindex > 0 )
		       	     aPrimitive->DrawElement (aDrawer,hindex);
		           else
				     aPrimitive->DrawVertex (aDrawer,-hindex);
		           aDrawer->SetOverride (Standard_False);
                         } else {	// Highlight the full primitive
		           aDrawer->SetOverride (Standard_True);
		           aPrimitive->Draw (aDrawer);
		           aDrawer->SetOverride (Standard_False);
                         }
                      } // end for 
	} 
#ifdef OCC402
	else
	  if ( aPrimitive->HasSelectedElements() ) {
	    aPrimitive->Draw (aDrawer);
	    aDrawer->SetOverride( Standard_True );
	    aPrimitive->DrawSelectedElements( aDrawer );
	    aDrawer->SetOverride( Standard_False );
	  }
#endif
	  else 
#endif
		    aPrimitive->Draw (aDrawer);
	      }
		}

		if( Reset ) myCurrentIndex = Length + 1;
		myIsUpToDate = Standard_True;
		if (myIsHighlighted) {
			aDrawer->SetOverride (Standard_False);
		}
	}

}

void Graphic2d_GraphicObject::Draw (
	const Handle(Graphic2d_Drawer)& aDrawer,
	const Handle(Graphic2d_Primitive)& aPrimitive) {

	//
	// Test deja effectue dans l'appelant
	//
	// if (! IsIn (aPrimitive)) return;

	if (! Drawable) return;

	if (myIsDisplayed || myIsHighlighted) {
#ifdef G002
		aDrawer->SetOverrideColor (myOverrideColor);
#endif
		if (myIsHighlighted) {
	  	  aDrawer->SetOverride (Standard_True);
#ifndef G002
		  aDrawer->SetOverrideColor (myOverrideColor);
#endif
		} else {
		  aDrawer->SetOffSet (myOffSet);
		}

		// We draw the boundary rectangle of an image
		// in a highlighted Graphic2d_GraphicObject
		Standard_Boolean TheFlag = myIsHighlighted &&
			(aPrimitive->Family() == Graphic2d_TOP_IMAGE);
		if (TheFlag) {
			Standard_Integer ColorIndexSave =
				aPrimitive->ColorIndex ();
			aPrimitive->SetColorIndex (myOverrideColor);
			aPrimitive->Draw (aDrawer);
			aPrimitive->SetColorIndex (ColorIndexSave);
		} else {
#ifdef G002
		    if( aPrimitive->IsHighlighted() && !myIsHighlighted ) {
              Handle(TColStd_HSequenceOfInteger) theHSeq = aPrimitive->HighlightIndices();
		      for ( int i = 1; i <= theHSeq->Length(); ++i ) {
                 Standard_Integer hindex = theHSeq->Value(i);
                 if( hindex != 0 ) {	// Highlight a part of primitive
		           aPrimitive->Draw (aDrawer);
		           aDrawer->SetOverride (Standard_True);
		           if( hindex > 0 )
		       	     aPrimitive->DrawElement (aDrawer,hindex);
		           else
				     aPrimitive->DrawVertex (aDrawer,-hindex);
		           aDrawer->SetOverride (Standard_False);
                 } else {	// Highlight the full primitive
		           aDrawer->SetOverride (Standard_True);
		           aPrimitive->Draw (aDrawer);
		           aDrawer->SetOverride (Standard_False);
                 } 
              } // end for 
		    } else 
#endif
		      aPrimitive->Draw (aDrawer);
		}
		if (myIsHighlighted) {
			aDrawer->SetOverride (Standard_False);
		}
	}
}

void Graphic2d_GraphicObject::Display () {

	if (myIsHighlighted) Unhighlight();
#ifdef OCC627
	if (! myIsDisplayed && ( myDisplayStatus != Graphic2d_DS_ERASED ) ) 
#else
	if (! myIsDisplayed )
#endif
	  myViewPtr->Add (this,myPriority + BasePriority() );
	myIsDisplayed	= Standard_True;
#ifdef OCC627
	myDisplayStatus = Graphic2d_DS_DISPLAYED;
#endif
}

void Graphic2d_GraphicObject::Erase () {

	if (myIsHighlighted) Unhighlight();
#ifndef OCC154
	if (myIsDisplayed) myViewPtr->Remove (this);
#endif
#ifdef OCC627
        if(myIsDisplayed)
          myDisplayStatus = Graphic2d_DS_ERASED;
#endif
	myIsDisplayed	= Standard_False;
	myCurrentIndex	= 1;
}

Standard_Boolean Graphic2d_GraphicObject::IsDisplayed () const {

	return myIsDisplayed;

}


void Graphic2d_GraphicObject::RemovePrimitive (const Handle(Graphic2d_Primitive)& aPrimitive) {

  Standard_Integer Index = myPrimitives.FindIndex(aPrimitive);
  if (Index == 0) return;
  Standard_Integer Length = myPrimitives.Extent ();

  for (Standard_Integer i=Index+1; i<=Length; i++)
    ((Handle(Standard_Transient)&) myPrimitives.FindKey(i-1)) = myPrimitives.FindKey(i);
  
  myPrimitives.RemoveLast ();

  myCurrentIndex = (myCurrentIndex > Index ? Index : myCurrentIndex);

#ifdef OK
	//
	// To retrace whatever is necessary
	// Parse the primitives from 1 to Index
	// and return l'Index of the first primitive
	// with bounding box intersecting the bounding
        // box of the removed primitive.
	//
Standard_Boolean stop = Standard_False;
Standard_ShortReal sMinx, sMiny, sMaxx, sMaxy;
Standard_ShortReal x, y, X, Y;
Standard_ShortReal RF	= ShortRealFirst ();
Standard_ShortReal RL	= ShortRealLast ();

	aPrimitive->MinMax (sMinx, sMaxx, sMiny, sMaxy);
	for (Standard_Integer i=1; i<Index && ! stop; i++) {
		(Primitive (i))->MinMax (x, X, y, Y);
		//
		// Infinite lines
		//
		if ((x == RF) || (X == RL) || (y == RF) || (Y == RL)) {
			// infinite horizontal
			if (y == Y) stop = (sMiny <= y) && (y <= sMaxy);
			// infinite vertical
			if (x == X) stop = (sMinx <= x) && (x <= sMaxx);
			// infinite diagonal
			if ((y != Y) && (x != X)) {
				// no interrogation possible
				// about the content of the primitive.
				stop = Standard_True;
			}
		}
		else {
			if ((x<=sMinx) && (sMinx<=X) &&
			    (y<=sMaxy) && (sMaxy<=Y)) stop = Standard_True;
			if ((x<=sMinx) && (sMinx<=X) &&
			    (y<=sMiny) && (sMiny<=Y)) stop = Standard_True;
			if ((x<=sMaxx) && (sMaxx<=X) &&
			    (y<=sMiny) && (sMiny<=Y)) stop = Standard_True;
			if ((x<=sMaxx) && (sMaxx<=X) &&
			    (y<=sMaxy) && (sMaxy<=Y)) stop = Standard_True;
		}
		if (stop) myCurrentIndex = i;
	}
#endif

}

void Graphic2d_GraphicObject::RemovePrimitives () {

	myPrimitives.Clear ();
	myCurrentIndex	= 1;

}

void Graphic2d_GraphicObject::Remove () {

#ifdef OCC627
	if ( myIsDisplayed || myIsHighlighted || 
	     ( myDisplayStatus == Graphic2d_DS_ERASED ) )
#else
	if (myIsDisplayed || myIsHighlighted) 
#endif
	  myViewPtr->Remove (this);
	myIsHighlighted	= Standard_False;
	myIsDisplayed	= Standard_False;
#ifdef OCC627
	myDisplayStatus = Graphic2d_DS_REMOVED;
#endif
	myCurrentIndex	= 1;

}

void Graphic2d_GraphicObject::Highlight () {

	if (! myViewPtr->IsDefinedColor ())
                Graphic2d_OverrideColorError::Raise
			("Undefined highlight color index");

	if (! myIsHighlighted) {
	  if (! myIsDisplayed ) 
#ifdef OCC627
	    if ( myDisplayStatus != Graphic2d_DS_ERASED )
#endif
		myViewPtr->Add (this,HIGH_PRIORITY);
#ifdef TEST
	  else 
		myViewPtr->Change (this,HIGH_PRIORITY);
#endif
	  myIsHighlighted	= Standard_True;
	}
	myOverrideColor	= myViewPtr->DefaultOverrideColor();
	myCurrentIndex = 1;

}

void Graphic2d_GraphicObject::Highlight (const Standard_Integer aColorIndex) {

	if (! myIsHighlighted) {
	  if (! myIsDisplayed ) 
#ifdef OCC627
	    if ( myDisplayStatus != Graphic2d_DS_ERASED )
#endif
		myViewPtr->Add (this,HIGH_PRIORITY);
#ifdef TEST
	  else 
		myViewPtr->Change (this,HIGH_PRIORITY);
#endif
	  myIsHighlighted	= Standard_True;
	}
	myOverrideColor	= aColorIndex;
	myCurrentIndex = 1;

}

void Graphic2d_GraphicObject::SetOffSet (const Standard_Integer anOffSet) {

	myOffSet	= anOffSet;
	myCurrentIndex	= 1;

}

Standard_Integer Graphic2d_GraphicObject::OffSet () const {

	return myOffSet;

}

Standard_Integer Graphic2d_GraphicObject::OverrideColor () const {

	return myOverrideColor;

}

void Graphic2d_GraphicObject::SetOverrideColor( const Standard_Integer indColor ) {

	 myOverrideColor = indColor;

}

void Graphic2d_GraphicObject::Unhighlight () {

	if( myIsHighlighted ) {
#ifdef TEST
	  if ( myIsDisplayed ) 
		myViewPtr->Change (this,myPriority + BasePriority() );
	  else 
#else
	  if ( !myIsDisplayed )
#endif
		myViewPtr->Remove (this); 
	  myIsHighlighted	= Standard_False;
	}
	myCurrentIndex	= 1;

}

Standard_Boolean Graphic2d_GraphicObject::IsHighlighted () const {

	return myIsHighlighted;

}

Handle(Graphic2d_View) Graphic2d_GraphicObject::View () const {

	return ((Graphic2d_View*) myViewPtr);

}

Standard_Boolean Graphic2d_GraphicObject::Pick (const Standard_Real X, const Standard_Real Y, const Standard_Real aPrecision, const Handle(Graphic2d_Drawer)& aDrawer) {

#ifndef G002
  myPickedIndex = 0;
#else
  myPickIndices->Clear();
#endif
  if (Pickable && (myIsDisplayed || myIsHighlighted))
 {
    Standard_ShortReal XX	= Standard_ShortReal (X);
    Standard_ShortReal YY	= Standard_ShortReal (Y);
    Standard_ShortReal P	= Standard_ShortReal (aPrecision);
    Standard_Integer i;
    Handle(Graphic2d_Primitive) thePrimitive;
    Standard_ShortReal Minx, Maxx, Miny, Maxy;

    for( i=1 ; i<=myPrimitives.Extent () ; i++ ) {
      thePrimitive = Primitive(i);
      thePrimitive->MinMax(Minx, Maxx, Miny, Maxy);
      if(XX < Minx || Maxx < XX || YY < Miny || Maxy < YY)
	continue;
      if( thePrimitive->Pick(XX,YY,P,aDrawer) ) {
#ifdef G002
        SetPickedIndex(i);
#else
        myPickedIndex = i;
#endif
	return Standard_True;
      }
    }
    return Standard_False;
  }
  else
    return Standard_False;
}

Standard_Boolean Graphic2d_GraphicObject
::PickByCircle( const Standard_Real X,
	        const Standard_Real Y,
	        const Standard_Real Radius,
	        const Handle(Graphic2d_Drawer)& aDrawer )
{
#ifdef OCC402

  myPickIndices->Clear();

  if ( Pickable && ( myIsDisplayed || myIsHighlighted ) ) {
    Standard_ShortReal XX	= Standard_ShortReal( X );
    Standard_ShortReal YY	= Standard_ShortReal( Y );
    Standard_ShortReal radius	= Standard_ShortReal( Radius );
    Standard_Integer i;
    Handle(Graphic2d_Primitive) thePrimitive;
    Standard_ShortReal Minx, Maxx, Miny, Maxy;
    
    for( i=1 ; i<=myPrimitives.Extent() ; i++ ) {
      thePrimitive = Primitive( i );
      thePrimitive->MinMax(Minx, Maxx, Miny, Maxy);
      if((XX+radius) < Minx || Maxx < (XX-radius) || (YY+radius) < Miny || Maxy < (YY-radius))
	continue;
      if( thePrimitive->PickByCircle( XX, YY, radius, aDrawer ) )
	myPickIndices->Append(i);
    }
    if ( myPickIndices->Length() > 0 ) 
      return Standard_True;
    return Standard_False;
  }
  else
    return Standard_False;
#else
  return Standard_False;
#endif
}

Standard_Boolean Graphic2d_GraphicObject::Pick( const Standard_Real Xmin,
                                         const Standard_Real Ymin,
                                         const Standard_Real Xmax,
                                         const Standard_Real Ymax,
                                         const Handle(Graphic2d_Drawer)& aDrawer,
                                         const Graphic2d_PickMode aPickMode ) {
  myPickIndices->Clear();

  if ( Pickable && (myIsDisplayed || myIsHighlighted) ) {
    Standard_ShortReal X1 = Standard_ShortReal( (Xmin<Xmax)?Xmin:Xmax );
    Standard_ShortReal Y1 = Standard_ShortReal( (Ymin<Ymax)?Ymin:Ymax );
    Standard_ShortReal X2 = Standard_ShortReal( (Xmin<Xmax)?Xmax:Xmin );
    Standard_ShortReal Y2 = Standard_ShortReal( (Ymin<Ymax)?Ymax:Ymin );
    
    Standard_Integer i;
    
    Handle(Graphic2d_Primitive) thePrimitive;
    Standard_ShortReal Minx, Maxx, Miny, Maxy;

    for ( i = 1; i <= myPrimitives.Extent(); i++ ) {
      thePrimitive = Primitive(i);
      thePrimitive->MinMax(Minx, Maxx, Miny, Maxy);
      if(X2 < Minx || Maxx < X1 || Y2 < Miny || Maxy < Y1)
	continue;
      if ( thePrimitive->Pick( X1,Y1,X2, Y2, aDrawer, aPickMode ) ) 
        myPickIndices->Append(i);
    }
    if ( myPickIndices->Length() > 0 ) 
	       return Standard_True;

    return Standard_False;
 }
  else
    return Standard_False;

}

Handle(TColStd_HSequenceOfInteger) Graphic2d_GraphicObject::PickList() const {

 return myPickIndices;

}

void Graphic2d_GraphicObject::AddPrimitive (const Handle(Graphic2d_Primitive)& aPrimitive) {
  Standard_Integer ColorIndex = aPrimitive->ColorIndex ();
  aPrimitive->SetColorIndex (ColorIndex + myOffSet);
  myPrimitives.Add (aPrimitive);
  myIsUpToDate = Standard_False;
}

Standard_Integer Graphic2d_GraphicObject::Length() const {

	return myPrimitives.Extent() ;
}

Handle(Graphic2d_Primitive) Graphic2d_GraphicObject::Primitive(const Standard_Integer aRank) const {
  // modif : EAV , 23-09-01 
  static Handle(Graphic2d_Primitive) null;
  try {
    OCC_CATCH_SIGNALS
      return Handle(Graphic2d_Primitive)::DownCast(myPrimitives.FindKey(aRank)) ;
  }
  catch( Standard_OutOfRange ) {
    return null;
  }
  // modif end 
}

void Graphic2d_GraphicObject::SetIndex (const Handle(Graphic2d_Primitive)& aPrimitive) {

  Standard_Integer Index = myPrimitives.FindIndex(aPrimitive);

  if (Index == 0) return;
  myCurrentIndex = (myCurrentIndex > Index ? Index : myCurrentIndex);

}

Standard_Boolean Graphic2d_GraphicObject::MinMax (Quantity_Length & Minx, Quantity_Length & Maxx, Quantity_Length & Miny, Quantity_Length & Maxy) const {

  Standard_ShortReal RL, RF, sMinx, sMiny, sMaxx, sMaxy;
  Standard_Boolean status = Standard_True;
  Handle(Graphic2d_Primitive) thePrimitive = NULL;

	RL = sMinx = sMiny = ShortRealLast ();
	RF = sMaxx = sMaxy = ShortRealFirst();

	if (myIsDisplayed || myIsHighlighted) {

		Standard_Integer Length = myPrimitives.Extent ();
		Standard_ShortReal x, y, X, Y;
		Standard_Boolean TheFlag;

		for (Standard_Integer i=1; i<=Length; i++) {
		  thePrimitive = Primitive (i);
		  TheFlag = 
		    (thePrimitive->Family() == Graphic2d_TOP_MARKER);
		    if (! TheFlag) {
		      if( thePrimitive->MinMax (x, X, y, Y) ) {
			// Tests for cause of infinite lines
			if (x != RF) sMinx = (sMinx < x ? sMinx : x);
			if (X != RL) sMaxx = (sMaxx > X ? sMaxx : X);
			if (y != RF) sMiny = (sMiny < y ? sMiny : y);
			if (Y != RL) sMaxy = (sMaxy > Y ? sMaxy : Y);
		      }
		    }
		}
	}

	// Attention, it is possible that :
	// sMinx = sMiny = ShortRealLast (); and
	// sMaxx = sMaxy = ShortRealFirst();
	if (sMinx > sMaxx) {
	  status = Standard_False;
	  sMinx = ShortRealFirst (); sMaxx = ShortRealLast ();
	}
	if (sMiny > sMaxy) {
	  status = Standard_False;
	  sMiny = ShortRealFirst (); sMaxy = ShortRealLast (); 
	}
	Minx	= sMinx;
	Miny	= sMiny;
	Maxx	= sMaxx;
	Maxy	= sMaxy;

	return status;

}

Standard_Boolean Graphic2d_GraphicObject::MarkerMinMax (Quantity_Length & Minx, Quantity_Length & Maxx, Quantity_Length & Miny, Quantity_Length & Maxy) const {

  Standard_ShortReal RL, RF, sMinx, sMiny, sMaxx, sMaxy;
  Standard_Boolean status = Standard_True;
  Handle(Graphic2d_Primitive) thePrimitive = NULL;

	RL = sMinx = sMiny = ShortRealLast ();
	RF = sMaxx = sMaxy = ShortRealFirst();

	if (myIsDisplayed || myIsHighlighted) {

		Standard_Integer Length = myPrimitives.Extent ();
		Standard_ShortReal x, y, X, Y;
		Standard_Boolean TheFlag;

		for (Standard_Integer i=1; i<=Length; i++) {
		  thePrimitive = Primitive(i);
		  TheFlag = 
		    (thePrimitive->Family() == Graphic2d_TOP_MARKER);
		    if (TheFlag) {
		      if( thePrimitive->MinMax (x, X, y, Y) ) {
			// Tests for cause of infinite lines
			if (x != RF) sMinx = (sMinx < x ? sMinx : x);
			if (X != RL) sMaxx = (sMaxx > X ? sMaxx : X);
			if (y != RF) sMiny = (sMiny < y ? sMiny : y);
			if (Y != RL) sMaxy = (sMaxy > Y ? sMaxy : Y);
		      }
		    }
		}
	}

	// Attention, it is possible that :
	// sMinx = sMiny = ShortRealLast (); and
	// sMaxx = sMaxy = ShortRealFirst();
	if (sMinx > sMaxx) {
	  status = Standard_False;
	  sMinx = ShortRealFirst (); sMaxx = ShortRealLast (); 
	}
	if (sMiny > sMaxy) {
	  status = Standard_False;
	  sMiny = ShortRealFirst (); sMaxy = ShortRealLast (); 
	}
	Minx	= sMinx;
	Miny	= sMiny;
	Maxx	= sMaxx;
	Maxy	= sMaxy;

	return status;
}

Standard_Boolean Graphic2d_GraphicObject::IsUpToDate() const {
	
	return myIsUpToDate;
}