Integration of OCCT 6.5.0 from SVN
[occt.git] / src / Graphic2d / Graphic2d_GraphicObject.cxx
CommitLineData
7fd59977 1//
2// S3593 //GG_270298
3// Eviter d'appeler IsKind() qui est couteux.
4// Ajouter un champs myIsUpToDate permettant de savoir
5// si l'objet est a jour.
6// Ajouter un champs myIsTransformed permettant de savoir
7// si l'objet est transforme.
8//
9
10#define G002 //GG_140400
11// Add empty constructor and SetView() method.
12// Manage highlighting.
13// TCL : New method Pick(xmin, ymin, xmax, ymax,...)
14
15#define OCC197 // jfa 01.03.2002
16
17#define OCC154 // jfa 06.03.2002 // to erase instead of removing
18
19#define OCC402 //SAV 14/11/01 Added PickByCircle(). Draw() was modified to be able
20 // to draw selected elements of SetOfMarker.
21
22#define OCC627 //SAV 16/08/02 new flag added to control visual object state
23
24#include <Graphic2d_GraphicObject.ixx>
25#include <Graphic2d_GraphicObject.pxx>
26
27#include <Standard_ErrorHandler.hxx>
28
29#define BASE_PRIORITY 1
30#define HIGH_PRIORITY 0x7FFFFFFF
31#define MAX_PRIORITY 999
32
33Graphic2d_GraphicObject::Graphic2d_GraphicObject
34 (const Handle(Graphic2d_View)& aView)
35 :myOverrideColor (0),
36 myCurrentIndex (1),
37 myOffSet (0),
38 myIsUpToDate (Standard_False),
39 myIsTransformed (Standard_False),
40 myPrimitives (),
41 myLayer (0),
42 myTrsf (),
43 myPickedIndex (0),
44 myPriority(0) ,
45 myPickIndices(new TColStd_HSequenceOfInteger) {
46
47 Plottable = Standard_True;
48 Drawable = Standard_True;
49 Pickable = Standard_True;
50 myIsDisplayed = Standard_False;
51 myIsHighlighted = Standard_False;
52 myViewPtr = aView.operator->();
53#ifdef OCC627
54 myDisplayStatus = Graphic2d_DS_NONE;
55#endif
56}
57
58Graphic2d_GraphicObject::Graphic2d_GraphicObject()
59 :myOverrideColor (0),
60 myCurrentIndex (1),
61 myOffSet (0),
62 myIsUpToDate (Standard_False),
63 myIsTransformed (Standard_False),
64 myPrimitives (),
65 myLayer (0),
66 myTrsf (),
67 myPickedIndex (0),
68 myPriority(0) ,
69 myPickIndices(new TColStd_HSequenceOfInteger) {
70
71 Plottable = Standard_True;
72 Drawable = Standard_True;
73 Pickable = Standard_True;
74 myIsDisplayed = Standard_False;
75 myIsHighlighted = Standard_False;
76 myViewPtr = NULL;
77#ifdef OCC627
78 myDisplayStatus = Graphic2d_DS_NONE;
79#endif
80}
81
82void Graphic2d_GraphicObject::SetView( const Handle(Graphic2d_View)& aView ) {
83
84 myViewPtr = aView.operator->();
85}
86
87void Graphic2d_GraphicObject::SetTransform (const gp_GTrsf2d& aTrsf,
88 const Graphic2d_TypeOfComposition aType) {
89
90 if( aType == Graphic2d_TOC_REPLACE ) {
91 myTrsf = aTrsf;
92 } else {
93 myTrsf = aTrsf.Multiplied(myTrsf);
94 }
95 myIsTransformed = (aTrsf.Form() == gp_Identity) ?
96 Standard_False : Standard_True;
97}
98
99const gp_GTrsf2d& Graphic2d_GraphicObject::Transform () const {
100
101 return myTrsf;
102
103}
104
105Standard_Boolean Graphic2d_GraphicObject::IsTransformed () const {
106 return myIsTransformed;
107}
108
109void Graphic2d_GraphicObject::SetLayer (const Standard_Integer aLayer) {
110
111 myLayer = aLayer;
112
113}
114
115Standard_Integer Graphic2d_GraphicObject::Layer () const {
116
117 return myLayer;
118
119}
120
121void Graphic2d_GraphicObject::SetPriority (const Standard_Integer aPriority) {
122
123 if( aPriority < 0 || aPriority > MaxPriority() ) {
124 Standard_OutOfRange::Raise (" Bad priority");
125 }
126 myPriority = aPriority;
127}
128
129Standard_Integer Graphic2d_GraphicObject::Priority () const {
130
131 return myPriority;
132
133}
134
135Standard_Integer Graphic2d_GraphicObject::BasePriority () const {
136
137 return BASE_PRIORITY;
138
139}
140
141Standard_Integer Graphic2d_GraphicObject::MaxPriority () const {
142
143 return MAX_PRIORITY;
144
145}
146
147void Graphic2d_GraphicObject::EnablePlot () {
148
149 Plottable = Standard_True;
150
151}
152
153void Graphic2d_GraphicObject::DisablePlot () {
154
155 Plottable = Standard_False;
156
157}
158
159Standard_Boolean Graphic2d_GraphicObject::IsPlottable () const {
160
161 return Plottable;
162
163}
164
165void Graphic2d_GraphicObject::EnableDraw () {
166
167 Drawable = Standard_True;
168
169}
170
171void Graphic2d_GraphicObject::DisableDraw () {
172
173 Drawable = Standard_False;
174
175}
176
177Standard_Boolean Graphic2d_GraphicObject::IsDrawable () const {
178
179 return Drawable;
180
181}
182
183Standard_Boolean Graphic2d_GraphicObject::IsIn (const Handle(Graphic2d_Primitive) & aPrimitive) const {
184 return myPrimitives.Contains(aPrimitive);
185}
186
187void Graphic2d_GraphicObject::EnablePick () {
188
189 Pickable = Standard_True;
190
191}
192
193void Graphic2d_GraphicObject::DisablePick () {
194
195 Pickable = Standard_False;
196
197}
198
199Standard_Boolean Graphic2d_GraphicObject::IsPickable () const {
200
201 return Pickable;
202
203}
204
205void Graphic2d_GraphicObject::SetPickedIndex (const Standard_Integer anIndex) {
206 myPickedIndex = anIndex;
207}
208
209Standard_Integer Graphic2d_GraphicObject::PickedIndex () const {
210
211 return myPickedIndex;
212}
213
214void Graphic2d_GraphicObject::Redraw (const Handle(Graphic2d_Drawer)& aDrawer) {
215
216 myCurrentIndex = 1;
217 Draw (aDrawer,Standard_True);
218
219}
220
221void Graphic2d_GraphicObject::Draw (const Handle(Graphic2d_Drawer)& aDrawer, const Standard_Boolean Reset) {
222
223 if (! Drawable) return;
224
225 if (myIsDisplayed || myIsHighlighted) {
226#ifdef G002
227 aDrawer->SetOverrideColor (myOverrideColor);
228#endif
229 if (myIsHighlighted) {
230 aDrawer->SetOverride (Standard_True);
231#ifndef G002
232 aDrawer->SetOverrideColor (myOverrideColor);
233#endif
234 } else {
235 aDrawer->SetOffSet (myOffSet);
236 }
237
238 Standard_Integer Length = myPrimitives.Extent ();
239 Handle(Graphic2d_Primitive) aPrimitive;
240
241 for (Standard_Integer i=myCurrentIndex; i<=Length; i++) {
242 aPrimitive = Primitive (i);
243 // We draw the boundary rectangle of an image
244 // in a highlighted Graphic2d_GraphicObject
245 Standard_Boolean TheFlag = myIsHighlighted &&
246 (aPrimitive->Family() == Graphic2d_TOP_IMAGE);
247 if (TheFlag) {
248 Standard_Integer ColorIndexSave = aPrimitive->ColorIndex ();
249 aPrimitive->SetColorIndex (myOverrideColor);
250 aPrimitive->Draw (aDrawer);
251 aPrimitive->SetColorIndex (ColorIndexSave);
252 } else {
253#ifdef G002
254 if( aPrimitive->IsHighlighted() && !myIsHighlighted )
255 {
256 Handle(TColStd_HSequenceOfInteger) theHSeq = aPrimitive->HighlightIndices();
257#ifdef OCC197
258 aPrimitive->Draw (aDrawer);
259#endif
260 for ( Standard_Integer j = 1; j <= theHSeq->Length(); ++j )
261 {
262 Standard_Integer hindex = theHSeq->Value(j);
263 if( hindex != 0 ) { // Highlight a part of primitive
264#ifndef OCC197
265// if we draw a primitive in cycle, it hides its own highlighted parts except the last one
266 aPrimitive->Draw (aDrawer);
267#endif
268 aDrawer->SetOverride (Standard_True);
269 if( hindex > 0 )
270 aPrimitive->DrawElement (aDrawer,hindex);
271 else
272 aPrimitive->DrawVertex (aDrawer,-hindex);
273 aDrawer->SetOverride (Standard_False);
274 } else { // Highlight the full primitive
275 aDrawer->SetOverride (Standard_True);
276 aPrimitive->Draw (aDrawer);
277 aDrawer->SetOverride (Standard_False);
278 }
279 } // end for
280 }
281#ifdef OCC402
282 else
283 if ( aPrimitive->HasSelectedElements() ) {
284 aPrimitive->Draw (aDrawer);
285 aDrawer->SetOverride( Standard_True );
286 aPrimitive->DrawSelectedElements( aDrawer );
287 aDrawer->SetOverride( Standard_False );
288 }
289#endif
290 else
291#endif
292 aPrimitive->Draw (aDrawer);
293 }
294 }
295
296 if( Reset ) myCurrentIndex = Length + 1;
297 myIsUpToDate = Standard_True;
298 if (myIsHighlighted) {
299 aDrawer->SetOverride (Standard_False);
300 }
301 }
302
303}
304
305void Graphic2d_GraphicObject::Draw (
306 const Handle(Graphic2d_Drawer)& aDrawer,
307 const Handle(Graphic2d_Primitive)& aPrimitive) {
308
309 //
310 // Test deja effectue dans l'appelant
311 //
312 // if (! IsIn (aPrimitive)) return;
313
314 if (! Drawable) return;
315
316 if (myIsDisplayed || myIsHighlighted) {
317#ifdef G002
318 aDrawer->SetOverrideColor (myOverrideColor);
319#endif
320 if (myIsHighlighted) {
321 aDrawer->SetOverride (Standard_True);
322#ifndef G002
323 aDrawer->SetOverrideColor (myOverrideColor);
324#endif
325 } else {
326 aDrawer->SetOffSet (myOffSet);
327 }
328
329 // We draw the boundary rectangle of an image
330 // in a highlighted Graphic2d_GraphicObject
331 Standard_Boolean TheFlag = myIsHighlighted &&
332 (aPrimitive->Family() == Graphic2d_TOP_IMAGE);
333 if (TheFlag) {
334 Standard_Integer ColorIndexSave =
335 aPrimitive->ColorIndex ();
336 aPrimitive->SetColorIndex (myOverrideColor);
337 aPrimitive->Draw (aDrawer);
338 aPrimitive->SetColorIndex (ColorIndexSave);
339 } else {
340#ifdef G002
341 if( aPrimitive->IsHighlighted() && !myIsHighlighted ) {
342 Handle(TColStd_HSequenceOfInteger) theHSeq = aPrimitive->HighlightIndices();
343 for ( int i = 1; i <= theHSeq->Length(); ++i ) {
344 Standard_Integer hindex = theHSeq->Value(i);
345 if( hindex != 0 ) { // Highlight a part of primitive
346 aPrimitive->Draw (aDrawer);
347 aDrawer->SetOverride (Standard_True);
348 if( hindex > 0 )
349 aPrimitive->DrawElement (aDrawer,hindex);
350 else
351 aPrimitive->DrawVertex (aDrawer,-hindex);
352 aDrawer->SetOverride (Standard_False);
353 } else { // Highlight the full primitive
354 aDrawer->SetOverride (Standard_True);
355 aPrimitive->Draw (aDrawer);
356 aDrawer->SetOverride (Standard_False);
357 }
358 } // end for
359 } else
360#endif
361 aPrimitive->Draw (aDrawer);
362 }
363 if (myIsHighlighted) {
364 aDrawer->SetOverride (Standard_False);
365 }
366 }
367}
368
369void Graphic2d_GraphicObject::Display () {
370
371 if (myIsHighlighted) Unhighlight();
372#ifdef OCC627
373 if (! myIsDisplayed && ( myDisplayStatus != Graphic2d_DS_ERASED ) )
374#else
375 if (! myIsDisplayed )
376#endif
377 myViewPtr->Add (this,myPriority + BasePriority() );
378 myIsDisplayed = Standard_True;
379#ifdef OCC627
380 myDisplayStatus = Graphic2d_DS_DISPLAYED;
381#endif
382}
383
384void Graphic2d_GraphicObject::Erase () {
385
386 if (myIsHighlighted) Unhighlight();
387#ifndef OCC154
388 if (myIsDisplayed) myViewPtr->Remove (this);
389#endif
390#ifdef OCC627
391 if(myIsDisplayed)
392 myDisplayStatus = Graphic2d_DS_ERASED;
393#endif
394 myIsDisplayed = Standard_False;
395 myCurrentIndex = 1;
396}
397
398Standard_Boolean Graphic2d_GraphicObject::IsDisplayed () const {
399
400 return myIsDisplayed;
401
402}
403
404
405void Graphic2d_GraphicObject::RemovePrimitive (const Handle(Graphic2d_Primitive)& aPrimitive) {
406
407 Standard_Integer Index = myPrimitives.FindIndex(aPrimitive);
408 if (Index == 0) return;
409 Standard_Integer Length = myPrimitives.Extent ();
410
411 for (Standard_Integer i=Index+1; i<=Length; i++)
412 ((Handle(Standard_Transient)&) myPrimitives.FindKey(i-1)) = myPrimitives.FindKey(i);
413
414 myPrimitives.RemoveLast ();
415
416 myCurrentIndex = (myCurrentIndex > Index ? Index : myCurrentIndex);
417
418#ifdef OK
419 //
420 // Pour retracer ce qui est necessaire
421 // On parcourt les primitives de 1 jusqu'a Index
422 // et on recupere l'Index de la premiere primitive
423 // dont le rectangle englobant intersecte celui
424 // de la primitive retiree.
425 //
426Standard_Boolean stop = Standard_False;
427Standard_ShortReal sMinx, sMiny, sMaxx, sMaxy;
428Standard_ShortReal x, y, X, Y;
429Standard_ShortReal RF = ShortRealFirst ();
430Standard_ShortReal RL = ShortRealLast ();
431
432 aPrimitive->MinMax (sMinx, sMaxx, sMiny, sMaxy);
433 for (Standard_Integer i=1; i<Index && ! stop; i++) {
434 (Primitive (i))->MinMax (x, X, y, Y);
435 //
436 // Les lignes infinies
437 //
438 if ((x == RF) || (X == RL) || (y == RF) || (Y == RL)) {
439 // infinie horizontale
440 if (y == Y) stop = (sMiny <= y) && (y <= sMaxy);
441 // infinie verticale
442 if (x == X) stop = (sMinx <= x) && (x <= sMaxx);
443 // infinie oblique
444 if ((y != Y) && (x != X)) {
445 // Pb pas d'interrogation possible
446 // sur le contenu de la primitive.
447 stop = Standard_True;
448 }
449 }
450 else {
451 if ((x<=sMinx) && (sMinx<=X) &&
452 (y<=sMaxy) && (sMaxy<=Y)) stop = Standard_True;
453 if ((x<=sMinx) && (sMinx<=X) &&
454 (y<=sMiny) && (sMiny<=Y)) stop = Standard_True;
455 if ((x<=sMaxx) && (sMaxx<=X) &&
456 (y<=sMiny) && (sMiny<=Y)) stop = Standard_True;
457 if ((x<=sMaxx) && (sMaxx<=X) &&
458 (y<=sMaxy) && (sMaxy<=Y)) stop = Standard_True;
459 }
460 if (stop) myCurrentIndex = i;
461 }
462#endif
463
464}
465
466void Graphic2d_GraphicObject::RemovePrimitives () {
467
468 myPrimitives.Clear ();
469 myCurrentIndex = 1;
470
471}
472
473void Graphic2d_GraphicObject::Remove () {
474
475#ifdef OCC627
476 if ( myIsDisplayed || myIsHighlighted ||
477 ( myDisplayStatus == Graphic2d_DS_ERASED ) )
478#else
479 if (myIsDisplayed || myIsHighlighted)
480#endif
481 myViewPtr->Remove (this);
482 myIsHighlighted = Standard_False;
483 myIsDisplayed = Standard_False;
484#ifdef OCC627
485 myDisplayStatus = Graphic2d_DS_REMOVED;
486#endif
487 myCurrentIndex = 1;
488
489}
490
491void Graphic2d_GraphicObject::Highlight () {
492
493 if (! myViewPtr->IsDefinedColor ())
494 Graphic2d_OverrideColorError::Raise
495 ("Undefined highlight color index");
496
497 if (! myIsHighlighted) {
498 if (! myIsDisplayed )
499#ifdef OCC627
500 if ( myDisplayStatus != Graphic2d_DS_ERASED )
501#endif
502 myViewPtr->Add (this,HIGH_PRIORITY);
503#ifdef TEST
504 else
505 myViewPtr->Change (this,HIGH_PRIORITY);
506#endif
507 myIsHighlighted = Standard_True;
508 }
509 myOverrideColor = myViewPtr->DefaultOverrideColor();
510 myCurrentIndex = 1;
511
512}
513
514void Graphic2d_GraphicObject::Highlight (const Standard_Integer aColorIndex) {
515
516 if (! myIsHighlighted) {
517 if (! myIsDisplayed )
518#ifdef OCC627
519 if ( myDisplayStatus != Graphic2d_DS_ERASED )
520#endif
521 myViewPtr->Add (this,HIGH_PRIORITY);
522#ifdef TEST
523 else
524 myViewPtr->Change (this,HIGH_PRIORITY);
525#endif
526 myIsHighlighted = Standard_True;
527 }
528 myOverrideColor = aColorIndex;
529 myCurrentIndex = 1;
530
531}
532
533void Graphic2d_GraphicObject::SetOffSet (const Standard_Integer anOffSet) {
534
535 myOffSet = anOffSet;
536 myCurrentIndex = 1;
537
538}
539
540Standard_Integer Graphic2d_GraphicObject::OffSet () const {
541
542 return myOffSet;
543
544}
545
546Standard_Integer Graphic2d_GraphicObject::OverrideColor () const {
547
548 return myOverrideColor;
549
550}
551
552void Graphic2d_GraphicObject::SetOverrideColor( const Standard_Integer indColor ) {
553
554 myOverrideColor = indColor;
555
556}
557
558void Graphic2d_GraphicObject::Unhighlight () {
559
560 if( myIsHighlighted ) {
561#ifdef TEST
562 if ( myIsDisplayed )
563 myViewPtr->Change (this,myPriority + BasePriority() );
564 else
565#else
566 if ( !myIsDisplayed )
567#endif
568 myViewPtr->Remove (this);
569 myIsHighlighted = Standard_False;
570 }
571 myCurrentIndex = 1;
572
573}
574
575Standard_Boolean Graphic2d_GraphicObject::IsHighlighted () const {
576
577 return myIsHighlighted;
578
579}
580
581Handle(Graphic2d_View) Graphic2d_GraphicObject::View () const {
582
583 return ((Graphic2d_View*) myViewPtr);
584
585}
586
587Standard_Boolean Graphic2d_GraphicObject::Pick (const Standard_Real X, const Standard_Real Y, const Standard_Real aPrecision, const Handle(Graphic2d_Drawer)& aDrawer) {
588
589#ifndef G002
590 myPickedIndex = 0;
591#else
592 myPickIndices->Clear();
593#endif
594 if (Pickable && (myIsDisplayed || myIsHighlighted))
595 {
596 Standard_ShortReal XX = Standard_ShortReal (X);
597 Standard_ShortReal YY = Standard_ShortReal (Y);
598 Standard_ShortReal P = Standard_ShortReal (aPrecision);
599 Standard_Integer i;
600 Handle(Graphic2d_Primitive) thePrimitive;
601 Standard_ShortReal Minx, Maxx, Miny, Maxy;
602
603 for( i=1 ; i<=myPrimitives.Extent () ; i++ ) {
604 thePrimitive = Primitive(i);
605 thePrimitive->MinMax(Minx, Maxx, Miny, Maxy);
606 if(XX < Minx || Maxx < XX || YY < Miny || Maxy < YY)
607 continue;
608 if( thePrimitive->Pick(XX,YY,P,aDrawer) ) {
609#ifdef G002
610 SetPickedIndex(i);
611#else
612 myPickedIndex = i;
613#endif
614 return Standard_True;
615 }
616 }
617 return Standard_False;
618 }
619 else
620 return Standard_False;
621}
622
623Standard_Boolean Graphic2d_GraphicObject
624::PickByCircle( const Standard_Real X,
625 const Standard_Real Y,
626 const Standard_Real Radius,
627 const Handle(Graphic2d_Drawer)& aDrawer )
628{
629#ifdef OCC402
630
631 myPickIndices->Clear();
632
633 if ( Pickable && ( myIsDisplayed || myIsHighlighted ) ) {
634 Standard_ShortReal XX = Standard_ShortReal( X );
635 Standard_ShortReal YY = Standard_ShortReal( Y );
636 Standard_ShortReal radius = Standard_ShortReal( Radius );
637 Standard_Integer i;
638 Handle(Graphic2d_Primitive) thePrimitive;
639 Standard_ShortReal Minx, Maxx, Miny, Maxy;
640
641 for( i=1 ; i<=myPrimitives.Extent() ; i++ ) {
642 thePrimitive = Primitive( i );
643 thePrimitive->MinMax(Minx, Maxx, Miny, Maxy);
644 if((XX+radius) < Minx || Maxx < (XX-radius) || (YY+radius) < Miny || Maxy < (YY-radius))
645 continue;
646 if( thePrimitive->PickByCircle( XX, YY, radius, aDrawer ) )
647 myPickIndices->Append(i);
648 }
649 if ( myPickIndices->Length() > 0 )
650 return Standard_True;
651 return Standard_False;
652 }
653 else
654 return Standard_False;
655#endif
656 return Standard_False;
657}
658
659Standard_Boolean Graphic2d_GraphicObject::Pick( const Standard_Real Xmin,
660 const Standard_Real Ymin,
661 const Standard_Real Xmax,
662 const Standard_Real Ymax,
663 const Handle(Graphic2d_Drawer)& aDrawer,
664 const Graphic2d_PickMode aPickMode ) {
665 myPickIndices->Clear();
666
667 if ( Pickable && (myIsDisplayed || myIsHighlighted) ) {
668 Standard_ShortReal X1 = Standard_ShortReal( (Xmin<Xmax)?Xmin:Xmax );
669 Standard_ShortReal Y1 = Standard_ShortReal( (Ymin<Ymax)?Ymin:Ymax );
670 Standard_ShortReal X2 = Standard_ShortReal( (Xmin<Xmax)?Xmax:Xmin );
671 Standard_ShortReal Y2 = Standard_ShortReal( (Ymin<Ymax)?Ymax:Ymin );
672
673 Standard_Integer i;
674
675 Handle(Graphic2d_Primitive) thePrimitive;
676 Standard_ShortReal Minx, Maxx, Miny, Maxy;
677
678 for ( i = 1; i <= myPrimitives.Extent(); i++ ) {
679 thePrimitive = Primitive(i);
680 thePrimitive->MinMax(Minx, Maxx, Miny, Maxy);
681 if(X2 < Minx || Maxx < X1 || Y2 < Miny || Maxy < Y1)
682 continue;
683 if ( thePrimitive->Pick( X1,Y1,X2, Y2, aDrawer, aPickMode ) )
684 myPickIndices->Append(i);
685 }
686 if ( myPickIndices->Length() > 0 )
687 return Standard_True;
688
689 return Standard_False;
690 }
691 else
692 return Standard_False;
693
694}
695
696Handle(TColStd_HSequenceOfInteger) Graphic2d_GraphicObject::PickList() const {
697
698 return myPickIndices;
699
700}
701
702void Graphic2d_GraphicObject::AddPrimitive (const Handle(Graphic2d_Primitive)& aPrimitive) {
703 Standard_Integer ColorIndex = aPrimitive->ColorIndex ();
704 aPrimitive->SetColorIndex (ColorIndex + myOffSet);
705 myPrimitives.Add (aPrimitive);
706 myIsUpToDate = Standard_False;
707}
708
709Standard_Integer Graphic2d_GraphicObject::Length() const {
710
711 return myPrimitives.Extent() ;
712}
713
714Handle(Graphic2d_Primitive) Graphic2d_GraphicObject::Primitive(const Standard_Integer aRank) const {
715 // modif : EAV , 23-09-01
716 static Handle(Graphic2d_Primitive) null;
717 try {
718 OCC_CATCH_SIGNALS
719 return Handle(Graphic2d_Primitive)::DownCast(myPrimitives.FindKey(aRank)) ;
720 }
721 catch( Standard_OutOfRange ) {
722 return null;
723 }
724 // modif end
725}
726
727void Graphic2d_GraphicObject::SetIndex (const Handle(Graphic2d_Primitive)& aPrimitive) {
728
729 Standard_Integer Index = myPrimitives.FindIndex(aPrimitive);
730
731 if (Index == 0) return;
732 myCurrentIndex = (myCurrentIndex > Index ? Index : myCurrentIndex);
733
734}
735
736Standard_Boolean Graphic2d_GraphicObject::MinMax (Quantity_Length & Minx, Quantity_Length & Maxx, Quantity_Length & Miny, Quantity_Length & Maxy) const {
737
738 Standard_ShortReal RL, RF, sMinx, sMiny, sMaxx, sMaxy;
739 Standard_Boolean status = Standard_True;
740 Handle(Graphic2d_Primitive) thePrimitive = NULL;
741
742 RL = sMinx = sMiny = ShortRealLast ();
743 RF = sMaxx = sMaxy = ShortRealFirst();
744
745 if (myIsDisplayed || myIsHighlighted) {
746
747 Standard_Integer Length = myPrimitives.Extent ();
748 Standard_ShortReal x, y, X, Y;
749 Standard_Boolean TheFlag;
750
751 for (Standard_Integer i=1; i<=Length; i++) {
752 thePrimitive = Primitive (i);
753 TheFlag =
754 (thePrimitive->Family() == Graphic2d_TOP_MARKER);
755 if (! TheFlag) {
756 if( thePrimitive->MinMax (x, X, y, Y) ) {
757 // Tests pour cause de lignes infinies
758 if (x != RF) sMinx = (sMinx < x ? sMinx : x);
759 if (X != RL) sMaxx = (sMaxx > X ? sMaxx : X);
760 if (y != RF) sMiny = (sMiny < y ? sMiny : y);
761 if (Y != RL) sMaxy = (sMaxy > Y ? sMaxy : Y);
762 }
763 }
764 }
765 }
766
767 // Attention, il se peut que :
768 // sMinx = sMiny = ShortRealLast (); et
769 // sMaxx = sMaxy = ShortRealFirst();
770 if (sMinx > sMaxx) {
771 status = Standard_False;
772 sMinx = ShortRealFirst (); sMaxx = ShortRealLast ();
773 }
774 if (sMiny > sMaxy) {
775 status = Standard_False;
776 sMiny = ShortRealFirst (); sMaxy = ShortRealLast ();
777 }
778 Minx = sMinx;
779 Miny = sMiny;
780 Maxx = sMaxx;
781 Maxy = sMaxy;
782
783 return status;
784
785}
786
787Standard_Boolean Graphic2d_GraphicObject::MarkerMinMax (Quantity_Length & Minx, Quantity_Length & Maxx, Quantity_Length & Miny, Quantity_Length & Maxy) const {
788
789 Standard_ShortReal RL, RF, sMinx, sMiny, sMaxx, sMaxy;
790 Standard_Boolean status = Standard_True;
791 Handle(Graphic2d_Primitive) thePrimitive = NULL;
792
793 RL = sMinx = sMiny = ShortRealLast ();
794 RF = sMaxx = sMaxy = ShortRealFirst();
795
796 if (myIsDisplayed || myIsHighlighted) {
797
798 Standard_Integer Length = myPrimitives.Extent ();
799 Standard_ShortReal x, y, X, Y;
800 Standard_Boolean TheFlag;
801
802 for (Standard_Integer i=1; i<=Length; i++) {
803 thePrimitive = Primitive(i);
804 TheFlag =
805 (thePrimitive->Family() == Graphic2d_TOP_MARKER);
806 if (TheFlag) {
807 if( thePrimitive->MinMax (x, X, y, Y) ) {
808 // Tests pour cause de lignes infinies
809 if (x != RF) sMinx = (sMinx < x ? sMinx : x);
810 if (X != RL) sMaxx = (sMaxx > X ? sMaxx : X);
811 if (y != RF) sMiny = (sMiny < y ? sMiny : y);
812 if (Y != RL) sMaxy = (sMaxy > Y ? sMaxy : Y);
813 }
814 }
815 }
816 }
817
818 // Attention, il se peut que :
819 // sMinx = sMiny = ShortRealLast (); et
820 // sMaxx = sMaxy = ShortRealFirst();
821 if (sMinx > sMaxx) {
822 status = Standard_False;
823 sMinx = ShortRealFirst (); sMaxx = ShortRealLast ();
824 }
825 if (sMiny > sMaxy) {
826 status = Standard_False;
827 sMiny = ShortRealFirst (); sMaxy = ShortRealLast ();
828 }
829 Minx = sMinx;
830 Miny = sMiny;
831 Maxx = sMaxx;
832 Maxy = sMaxy;
833
834 return status;
835}
836
837Standard_Boolean Graphic2d_GraphicObject::IsUpToDate() const {
838
839 return myIsUpToDate;
840}