1 /*=========================================================================
2 
3 Program:   Visualization Toolkit
4 Module:    vtkXYPlotRepresentation.cxx
5 
6 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7 All rights reserved.
8 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10 This software is distributed WITHOUT ANY WARRANTY; without even
11 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12 PURPOSE.  See the above copyright notice for more information.
13 
14 =========================================================================*/
15 
16 // Written by Philippe Pebay, Kitware SAS 2012
17 
18 #include "vtkXYPlotRepresentation.h"
19 
20 #include "vtkObjectFactory.h"
21 #include "vtkPropCollection.h"
22 #include "vtkXYPlotActor.h"
23 #include "vtkSmartPointer.h"
24 #include "vtkTextProperty.h"
25 
26 vtkStandardNewMacro(vtkXYPlotRepresentation);
27 
28 //-----------------------------------------------------------------------------
vtkXYPlotRepresentation()29 vtkXYPlotRepresentation::vtkXYPlotRepresentation()
30 {
31 //    this->PositionCoordinate->SetValue( 0.0, 0.0 );
32 //    this->Position2Coordinate->SetValue( 0.7, 0.65 );
33 
34   this->XYPlotActor = NULL;
35   vtkXYPlotActor *actor = vtkXYPlotActor::New();
36   this->SetXYPlotActor( actor );
37   actor->Delete();
38 
39   this->ShowBorder = vtkBorderRepresentation::BORDER_ACTIVE;
40   this->BWActor->VisibilityOff();
41 }
42 
43 //-----------------------------------------------------------------------------
~vtkXYPlotRepresentation()44 vtkXYPlotRepresentation::~vtkXYPlotRepresentation()
45 {
46   this->SetXYPlotActor( NULL );
47 }
48 
49 //-----------------------------------------------------------------------------
SetXYPlotActor(vtkXYPlotActor * actor)50 void vtkXYPlotRepresentation::SetXYPlotActor( vtkXYPlotActor* actor )
51 {
52   if ( this->XYPlotActor != actor )
53     {
54     vtkSmartPointer<vtkXYPlotActor> oldActor = this->XYPlotActor;
55     vtkSetObjectBodyMacro( XYPlotActor, vtkXYPlotActor, actor );
56     }
57 }
58 
59 //-----------------------------------------------------------------------------
PrintSelf(ostream & os,vtkIndent indent)60 void vtkXYPlotRepresentation::PrintSelf( ostream &os, vtkIndent indent )
61 {
62   this->Superclass::PrintSelf( os, indent );
63 
64   os << indent << "XYPlotActor: " << this->XYPlotActor << endl;
65 }
66 
67 //-----------------------------------------------------------------------------
BuildRepresentation()68 void vtkXYPlotRepresentation::BuildRepresentation()
69 {
70   if ( this->XYPlotActor )
71     {
72     this->XYPlotActor->SetPosition( this->GetPosition() );
73     this->XYPlotActor->SetPosition2( this->GetPosition2() );
74     }
75 
76   this->Superclass::BuildRepresentation();
77 }
78 
79 //-----------------------------------------------------------------------------
WidgetInteraction(double eventPos[2])80 void vtkXYPlotRepresentation::WidgetInteraction( double eventPos[2])
81 {
82   // Let superclass move things around.
83   this->Superclass::WidgetInteraction( eventPos );
84 }
85 
86 //-----------------------------------------------------------------------------
GetVisibility()87 int vtkXYPlotRepresentation::GetVisibility()
88 {
89   return this->XYPlotActor->GetVisibility();
90 }
91 
92 //-----------------------------------------------------------------------------
SetVisibility(int vis)93 void vtkXYPlotRepresentation::SetVisibility( int vis )
94 {
95   this->XYPlotActor->SetVisibility( vis );
96 }
97 
98 //-----------------------------------------------------------------------------
GetActors2D(vtkPropCollection * collection)99 void vtkXYPlotRepresentation::GetActors2D( vtkPropCollection* collection )
100 {
101   if ( this->XYPlotActor )
102     {
103     collection->AddItem( this->XYPlotActor );
104     }
105   this->Superclass::GetActors2D( collection );
106 }
107 
108 //-----------------------------------------------------------------------------
ReleaseGraphicsResources(vtkWindow * w)109 void vtkXYPlotRepresentation::ReleaseGraphicsResources( vtkWindow* w )
110 {
111   if ( this->XYPlotActor )
112     {
113     this->XYPlotActor->ReleaseGraphicsResources( w );
114     }
115   this->Superclass::ReleaseGraphicsResources( w );
116 }
117 
118 //-------------------------------------------------------------------------
RenderOverlay(vtkViewport * w)119 int vtkXYPlotRepresentation::RenderOverlay( vtkViewport* w )
120 {
121   int count = this->Superclass::RenderOverlay( w );
122   if ( this->XYPlotActor )
123     {
124     count += this->XYPlotActor->RenderOverlay( w );
125     }
126   return count;
127 }
128 
129 //-------------------------------------------------------------------------
RenderOpaqueGeometry(vtkViewport * w)130 int vtkXYPlotRepresentation::RenderOpaqueGeometry( vtkViewport* w )
131 {
132   int count = this->Superclass::RenderOpaqueGeometry( w );
133   if ( this->XYPlotActor )
134     {
135     count += this->XYPlotActor->RenderOpaqueGeometry( w );
136     }
137   return count;
138 }
139 
140 //-------------------------------------------------------------------------
RenderTranslucentPolygonalGeometry(vtkViewport * w)141 int vtkXYPlotRepresentation::RenderTranslucentPolygonalGeometry( vtkViewport* w )
142 {
143   int count = this->Superclass::RenderTranslucentPolygonalGeometry( w );
144   if ( this->XYPlotActor )
145     {
146     count += this->XYPlotActor->RenderTranslucentPolygonalGeometry( w );
147     }
148   return count;
149 }
150 
151 //-------------------------------------------------------------------------
HasTranslucentPolygonalGeometry()152 int vtkXYPlotRepresentation::HasTranslucentPolygonalGeometry()
153 {
154   int result = this->Superclass::HasTranslucentPolygonalGeometry();
155   if ( this->XYPlotActor )
156     {
157     result |= this->XYPlotActor->HasTranslucentPolygonalGeometry();
158     }
159   return result;
160 }
161 
162 //-------------------------------------------------------------------------------
SetBorder(int x)163 void vtkXYPlotRepresentation::SetBorder( int x )
164 {
165   if ( this->XYPlotActor )
166     {
167     this->XYPlotActor->SetBorder( x );
168     }
169 }
170 
171 //-------------------------------------------------------------------------------
SetTitle(const char * title)172 void vtkXYPlotRepresentation::SetTitle ( const char* title )
173 {
174   if ( this->XYPlotActor )
175     {
176     this->XYPlotActor->SetTitle( title );
177     }
178 }
179 
180 //-------------------------------------------------------------------------------
SetXTitle(const char * title)181 void vtkXYPlotRepresentation::SetXTitle ( const char* title )
182 {
183   if ( this->XYPlotActor )
184     {
185     this->XYPlotActor->SetXTitle( title );
186     }
187 }
188 
189 //-------------------------------------------------------------------------------
GetXTitle()190 char* vtkXYPlotRepresentation::GetXTitle ()
191 {
192   if ( this->XYPlotActor )
193     {
194     return this->XYPlotActor->GetXTitle();
195     }
196   return 0;
197 }
198 
199 //-------------------------------------------------------------------------------
SetXRange(double xmin,double xmax)200 void vtkXYPlotRepresentation::SetXRange ( double xmin, double xmax )
201 {
202   if ( this->XYPlotActor )
203     {
204     this->XYPlotActor->SetXRange( xmin, xmax );
205     }
206 }
207 
208 //-------------------------------------------------------------------------------
SetYTitle(const char * title)209 void vtkXYPlotRepresentation::SetYTitle ( const char* title )
210 {
211   if ( this->XYPlotActor )
212     {
213     this->XYPlotActor->SetYTitle( title );
214     }
215 }
216 
217 //-------------------------------------------------------------------------------
GetYTitle()218 char* vtkXYPlotRepresentation::GetYTitle ()
219 {
220   if ( this->XYPlotActor )
221     {
222     return this->XYPlotActor->GetXTitle();
223     }
224   return 0;
225 }
226 
227 
228 //-------------------------------------------------------------------------------
SetYRange(double ymin,double ymax)229 void vtkXYPlotRepresentation::SetYRange ( double ymin, double ymax )
230 {
231   if ( this->XYPlotActor )
232     {
233     this->XYPlotActor->SetYRange( ymin, ymax );
234     }
235 }
236 
237 //-------------------------------------------------------------------------------
SetYTitlePosition(int pos)238 void vtkXYPlotRepresentation::SetYTitlePosition ( int pos )
239 {
240   if ( this->XYPlotActor )
241     {
242     switch( pos )
243       {
244       case 0:
245         this->XYPlotActor->SetYTitlePositionToTop();
246         break;
247       case 1:
248         this->XYPlotActor->SetYTitlePositionToHCenter();
249         break;
250       case 2:
251         this->XYPlotActor->SetYTitlePositionToVCenter();
252         break;
253 
254       }
255     }
256 }
257 
258 //-------------------------------------------------------------------------------
GetYTitlePosition() const259 int vtkXYPlotRepresentation::GetYTitlePosition () const
260 {
261   if ( this->XYPlotActor )
262     {
263     return this->XYPlotActor->GetYTitlePosition();
264     }
265   return 0;
266 }
267 
268 
269 //-------------------------------------------------------------------------------
SetXAxisColor(double r,double g,double b)270 void vtkXYPlotRepresentation::SetXAxisColor ( double r, double g, double b )
271 {
272   if ( this->XYPlotActor )
273     {
274     this->XYPlotActor->SetXAxisColor( r, g, b );
275     }
276 }
277 
278 //-------------------------------------------------------------------------------
SetYAxisColor(double r,double g,double b)279 void vtkXYPlotRepresentation::SetYAxisColor ( double r, double g, double b )
280 {
281   if ( this->XYPlotActor )
282     {
283     this->XYPlotActor->SetYAxisColor( r, g, b );
284     }
285 }
286 
287 //-------------------------------------------------------------------------------
SetXValues(int x)288 void vtkXYPlotRepresentation::SetXValues ( int x )
289 {
290   if ( this->XYPlotActor )
291     {
292     this->XYPlotActor->SetXValues( x );
293     }
294 }
295 
296 //-------------------------------------------------------------------------------
SetLegend(int x)297 void vtkXYPlotRepresentation::SetLegend ( int x )
298 {
299   if ( this->XYPlotActor )
300     {
301     this->XYPlotActor->SetLegend( x );
302     }
303 }
304 
305 //-------------------------------------------------------------------------------
SetLegendBorder(int b)306 void vtkXYPlotRepresentation::SetLegendBorder ( int b )
307 {
308   if ( this->XYPlotActor )
309     {
310     this->XYPlotActor->SetLegendBorder( b );
311     }
312 }
313 
314 //-------------------------------------------------------------------------------
SetLegendBox(int b)315 void vtkXYPlotRepresentation::SetLegendBox ( int b )
316 {
317   if ( this->XYPlotActor )
318     {
319     this->XYPlotActor->SetLegendBox( b );
320     }
321 }
322 
323 //-------------------------------------------------------------------------------
SetLegendBoxColor(double r,double g,double b)324 void vtkXYPlotRepresentation::SetLegendBoxColor ( double r, double g, double b )
325 {
326   if ( this->XYPlotActor )
327     {
328     this->XYPlotActor->SetLegendBoxColor( r, g, b );
329     }
330 }
331 
332 //-------------------------------------------------------------------------------
SetLegendPosition(double x,double y)333 void vtkXYPlotRepresentation::SetLegendPosition ( double x, double y )
334 {
335   if ( this->XYPlotActor )
336     {
337     this->XYPlotActor->SetLegendPosition( x, y );
338     }
339 }
340 
341 //-------------------------------------------------------------------------------
SetLegendPosition2(double x,double y)342 void vtkXYPlotRepresentation::SetLegendPosition2 ( double x, double y )
343 {
344   if ( this->XYPlotActor )
345     {
346     this->XYPlotActor->SetLegendPosition2( x, y );
347     }
348 }
349 
350 //-------------------------------------------------------------------------------
SetLineWidth(double w)351 void vtkXYPlotRepresentation::SetLineWidth ( double w )
352 {
353   if ( this->XYPlotActor )
354     {
355     this->XYPlotActor->SetLineWidth( w );
356     }
357 }
358 
359 //-------------------------------------------------------------------------------
SetPlotColor(int i,int r,int g,int b)360 void vtkXYPlotRepresentation::SetPlotColor ( int i, int r, int g, int b )
361 {
362   if ( this->XYPlotActor )
363     {
364     this->XYPlotActor->SetPlotColor( i, r/255.0, g/255.0, b/255.0 );
365     }
366 }
367 
368 //-------------------------------------------------------------------------------
SetPlotLines(int i)369 void vtkXYPlotRepresentation::SetPlotLines ( int i )
370 {
371   if ( this->XYPlotActor )
372     {
373     this->XYPlotActor->SetPlotLines( i );
374     }
375 }
376 
377 
378 //-------------------------------------------------------------------------------
SetPlotPoints(int i)379 void vtkXYPlotRepresentation::SetPlotPoints ( int i )
380 {
381   if ( this->XYPlotActor )
382     {
383     this->XYPlotActor->SetPlotPoints( i );
384     }
385 }
386 
387 //-------------------------------------------------------------------------------
SetPlotLabel(int i,const char * label)388 void vtkXYPlotRepresentation::SetPlotLabel ( int i, const char* label )
389 {
390   if ( this->XYPlotActor )
391     {
392     this->XYPlotActor->SetPlotLabel( i, label );
393     }
394 }
395 
396 //-------------------------------------------------------------------------------
SetPlotGlyphType(int curve,int glyph)397 void vtkXYPlotRepresentation::SetPlotGlyphType( int curve, int glyph )
398 {
399   if ( this->XYPlotActor )
400     {
401     this->XYPlotActor->SetPlotGlyphType( curve, glyph );
402     }
403 }
404 
405 //-------------------------------------------------------------------------------
SetGlyphSize(double x)406 void vtkXYPlotRepresentation::SetGlyphSize( double x )
407 {
408   if ( this->XYPlotActor )
409     {
410     this->XYPlotActor->SetGlyphSize( x );
411     }
412 }
413 
414 //-------------------------------------------------------------------------------
AddUserCurvesPoint(double c,double x,double y)415 void vtkXYPlotRepresentation::AddUserCurvesPoint ( double c, double x, double y )
416 {
417   if ( this->XYPlotActor )
418     {
419     this->XYPlotActor->AddUserCurvesPoint( c, x, y );
420     }
421 }
422 
423 //-------------------------------------------------------------------------------
RemoveAllActiveCurves()424 void vtkXYPlotRepresentation::RemoveAllActiveCurves ()
425 {
426   if ( this->XYPlotActor )
427     {
428     this->XYPlotActor->RemoveAllActiveCurves();
429     }
430 }
431 
432 //-------------------------------------------------------------------------------
SetTitleColor(double r,double g,double b)433 void vtkXYPlotRepresentation::SetTitleColor ( double r, double g, double b )
434 {
435   if ( this->XYPlotActor )
436     {
437     this->XYPlotActor->SetTitleColor( r, g, b );
438     }
439 }
440 
441 //-------------------------------------------------------------------------------
SetTitleFontFamily(int x)442 void vtkXYPlotRepresentation::SetTitleFontFamily ( int x )
443 {
444   if ( this->XYPlotActor )
445     {
446     this->XYPlotActor->SetTitleFontFamily( x );
447     }
448 }
449 
450 //-------------------------------------------------------------------------------
SetTitleBold(int x)451 void vtkXYPlotRepresentation::SetTitleBold ( int x )
452 {
453   if ( this->XYPlotActor )
454     {
455     this->XYPlotActor->SetTitleBold( x );
456     }
457 }
458 
459 //-------------------------------------------------------------------------------
SetTitleItalic(int x)460 void vtkXYPlotRepresentation::SetTitleItalic ( int x )
461 {
462   if ( this->XYPlotActor )
463     {
464     this->XYPlotActor->SetTitleItalic( x );
465     }
466 }
467 
468 //-------------------------------------------------------------------------------
SetTitleShadow(int x)469 void vtkXYPlotRepresentation::SetTitleShadow ( int x )
470 {
471   if ( this->XYPlotActor )
472     {
473     this->XYPlotActor->SetTitleShadow( x );
474     }
475 }
476 
477 //-------------------------------------------------------------------------------
SetTitleFontSize(int x)478 void vtkXYPlotRepresentation::SetTitleFontSize ( int x )
479 {
480   if ( this->XYPlotActor )
481     {
482     this->XYPlotActor->SetTitleFontSize( x );
483     }
484 }
485 
486 //-------------------------------------------------------------------------------
SetTitleJustification(int x)487 void vtkXYPlotRepresentation::SetTitleJustification ( int x )
488 {
489   if ( this->XYPlotActor )
490     {
491     this->XYPlotActor->SetTitleJustification( x );
492     }
493 }
494 
495 //-------------------------------------------------------------------------------
SetTitleVerticalJustification(int x)496 void vtkXYPlotRepresentation::SetTitleVerticalJustification ( int x )
497 {
498   if ( this->XYPlotActor )
499     {
500     this->XYPlotActor->SetTitleVerticalJustification( x );
501     }
502 }
503 
504 //-------------------------------------------------------------------------------
SetAdjustTitlePosition(int x)505 void vtkXYPlotRepresentation::SetAdjustTitlePosition ( int x )
506 {
507   if ( this->XYPlotActor )
508     {
509     this->XYPlotActor->SetAdjustTitlePosition( x );
510     }
511 }
512 
513 //-------------------------------------------------------------------------------
SetTitlePosition(double x,double y)514 void vtkXYPlotRepresentation::SetTitlePosition ( double x, double y )
515 {
516   if ( this->XYPlotActor )
517     {
518     this->XYPlotActor->SetTitlePosition( x, y );
519     }
520 }
521 
522 //-------------------------------------------------------------------------------
SetAxisTitleColor(double r,double g,double b)523 void vtkXYPlotRepresentation::SetAxisTitleColor ( double r, double g, double b )
524 {
525   if ( this->XYPlotActor )
526     {
527     this->XYPlotActor->SetAxisTitleColor( r, g, b );
528     }
529 }
530 
531 //-------------------------------------------------------------------------------
SetAxisTitleFontFamily(int x)532 void vtkXYPlotRepresentation::SetAxisTitleFontFamily ( int x )
533 {
534   if ( this->XYPlotActor )
535     {
536     this->XYPlotActor->SetAxisTitleFontFamily( x );
537     }
538 }
539 
540 //-------------------------------------------------------------------------------
SetAxisTitleBold(int x)541 void vtkXYPlotRepresentation::SetAxisTitleBold ( int x )
542 {
543   if ( this->XYPlotActor )
544     {
545     this->XYPlotActor->SetAxisTitleBold( x );
546     }
547 }
548 
549 //-------------------------------------------------------------------------------
SetAxisTitleItalic(int x)550 void vtkXYPlotRepresentation::SetAxisTitleItalic ( int x )
551 {
552   if ( this->XYPlotActor )
553     {
554     this->XYPlotActor->SetAxisTitleItalic( x );
555     }
556 }
557 
558 //-------------------------------------------------------------------------------
SetAxisTitleShadow(int x)559 void vtkXYPlotRepresentation::SetAxisTitleShadow ( int x )
560 {
561   if ( this->XYPlotActor )
562     {
563     this->XYPlotActor->SetAxisTitleShadow( x );
564     }
565 }
566 
567 //-------------------------------------------------------------------------------
SetAxisTitleFontSize(int x)568 void vtkXYPlotRepresentation::SetAxisTitleFontSize ( int x )
569 {
570   if ( this->XYPlotActor )
571     {
572     this->XYPlotActor->SetAxisTitleFontSize( x );
573     }
574 }
575 
576 //-------------------------------------------------------------------------------
SetAxisTitleJustification(int x)577 void vtkXYPlotRepresentation::SetAxisTitleJustification ( int x )
578 {
579   if ( this->XYPlotActor )
580     {
581     this->XYPlotActor->SetAxisTitleJustification( x );
582     }
583 }
584 
585 //-------------------------------------------------------------------------------
SetAxisTitleVerticalJustification(int x)586 void vtkXYPlotRepresentation::SetAxisTitleVerticalJustification ( int x )
587 {
588   if ( this->XYPlotActor )
589     {
590     this->XYPlotActor->SetAxisTitleVerticalJustification( x );
591     }
592 }
593 
594 //-------------------------------------------------------------------------------
SetAxisLabelColor(double r,double g,double b)595 void vtkXYPlotRepresentation::SetAxisLabelColor ( double r, double g, double b )
596 {
597   if ( this->XYPlotActor )
598     {
599     this->XYPlotActor->SetAxisLabelColor( r, g, b );
600     }
601 }
602 
603 //-------------------------------------------------------------------------------
SetAxisLabelFontFamily(int x)604 void vtkXYPlotRepresentation::SetAxisLabelFontFamily ( int x )
605 {
606   if ( this->XYPlotActor )
607     {
608     this->XYPlotActor->SetAxisLabelFontFamily( x );
609     }
610 }
611 
612 //-------------------------------------------------------------------------------
SetAxisLabelBold(int x)613 void vtkXYPlotRepresentation::SetAxisLabelBold ( int x )
614 {
615   if ( this->XYPlotActor )
616     {
617     this->XYPlotActor->SetAxisLabelBold( x );
618     }
619 }
620 
621 //-------------------------------------------------------------------------------
SetAxisLabelItalic(int x)622 void vtkXYPlotRepresentation::SetAxisLabelItalic ( int x )
623 {
624   if ( this->XYPlotActor )
625     {
626     this->XYPlotActor->SetAxisLabelItalic( x );
627     }
628 }
629 
630 //-------------------------------------------------------------------------------
SetAxisLabelShadow(int x)631 void vtkXYPlotRepresentation::SetAxisLabelShadow ( int x )
632 {
633   if ( this->XYPlotActor )
634     {
635     this->XYPlotActor->SetAxisLabelShadow( x );
636     }
637 }
638 
639 //-------------------------------------------------------------------------------
SetAxisLabelFontSize(int x)640 void vtkXYPlotRepresentation::SetAxisLabelFontSize ( int x )
641 {
642   if ( this->XYPlotActor )
643     {
644     this->XYPlotActor->SetAxisLabelFontSize( x );
645     }
646 }
647 
648 //-------------------------------------------------------------------------------
SetAxisLabelJustification(int x)649 void vtkXYPlotRepresentation::SetAxisLabelJustification ( int x )
650 {
651   if ( this->XYPlotActor )
652     {
653     this->XYPlotActor->SetAxisLabelJustification( x );
654     }
655 }
656 
657 //-------------------------------------------------------------------------------
SetAxisLabelVerticalJustification(int x)658 void vtkXYPlotRepresentation::SetAxisLabelVerticalJustification ( int x )
659 {
660   if ( this->XYPlotActor )
661     {
662     this->XYPlotActor->SetAxisLabelVerticalJustification( x );
663     }
664 }
665 
666 //-------------------------------------------------------------------------------
SetXLabelFormat(const char * arg)667 void vtkXYPlotRepresentation::SetXLabelFormat( const char* arg )
668 {
669   if ( this->XYPlotActor )
670     {
671     this->XYPlotActor->SetXLabelFormat( arg );
672     }
673 }
674 
675 //-------------------------------------------------------------------------------
SetYLabelFormat(const char * arg)676 void vtkXYPlotRepresentation::SetYLabelFormat( const char* arg )
677 {
678   if ( this->XYPlotActor )
679     {
680     this->XYPlotActor->SetYLabelFormat( arg );
681     }
682 }
683