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