CanvasView.cxx
Go to the documentation of this file.
1 
13 // for MEMFUN1 and others
14 #ifdef HAVE_CONFIG_H
15 // for wcslib also
16 #include "config.h"
17 #endif
18 
19 #if QT_VERSION < 0x040000
20 #else
21 //Added by the Qt porting tool:
22 #include <QMouseEvent>
23 #endif
24 
25 #ifdef _MSC_VER
26 #include "msdevstudio/MSconfig.h"
27 #endif
28 
29 #include "CanvasView.h"
30 
31 #include "CanvasSelectionEvent.h"
32 #include "CanvasSettings.h"
33 #include "CanvasWindow.h"
34 #include "Inspector.h"
35 #include "PlotterEvent.h"
36 #include "QtViewFactory.h"
37 #include "PickTable.h"
38 #include "WindowController.h"
39 #include "CreateNTuple.h"
40 #include "QtGroupView.h"
41 
44 #include "datareps/ScatterPlot.h"
47 #include "graphics/EpsView.h"
48 #include "plotters/PlotterBase.h"
49 #include "plotters/Cut1DPlotter.h"
50 #include "plotters/Cut2DPlotter.h"
51 #include "qtxml/QtXMLController.h"
53 
54 #ifdef HAVE_CFITSIO
55 #include "fits/FitsController.h"
56 #endif
57 
58 #ifdef HAVE_ROOT
59 #include "root/RootController.h"
60 #endif
61 
62 #include <qapplication.h>
63 #include <qaction.h>
64 
65 #if QT_VERSION < 0x040000
66 #include <qfiledialog.h>
67 #include <qimage.h>
68 #else
69 #include <q3action.h>
70 #include <q3filedialog.h>
71 #include <QtGui/QImageWriter>
72 #endif
73 
74 #include <qcursor.h>
75 #include <qiconset.h>
76 #include <qmessagebox.h>
77 #include <qpainter.h>
78 #include <qsettings.h>
79 #include <qstatusbar.h>
80 #include <qwaitcondition.h>
81 #include <qfont.h>
82 
83 #include <algorithm>
84 #include <exception>
85 
86 #include <cctype>
87 #include <cmath>
88 
89 #include <cassert>
90 
91 using std::bind2nd;
92 using std::for_each;
93 using std::map;
94 using std::mem_fun;
95 using std::list;
96 using std::string;
97 using std::tolower;
98 using std::vector;
99 
100 namespace {
102 }
103 
104 using namespace hippodraw;
105 
106 /* Use `=' syntax so that Doxygen picks it up. */
107 const string CanvasView::s_app_name = "HippoDraw";
109 
111 
112 #if QT_VERSION < 0x040000
114  const char * name, Qt::WFlags f )
115 #else
116 CanvasView::CanvasView ( Q3Canvas * c, QWidget * parent,
117  const char * name, Qt::WFlags f )
118 #endif
119  : FigureEditor ( c, parent, name, f ),
120  m_inspector ( 0 ),
121  m_image_dialog ( 0 ),
122  m_num_width ( 2 ),
123  m_num_height ( 3 ),
124  m_cut_mode ( 1 ),
125  m_edge ( 0 ),
126  m_clicked( false )
127 
128 {
129  s_xml_controller = QtXMLController::instance ();
130  m_table_map.clear();
131  m_drag_rect = 0;
132 
133  initSettings ();
134 }
135 
136 void
139 {
140  QSettings settings;
141  settings.insertSearchPath ( QSettings::Windows, s_registry );
142 
144  = settings.readNumEntry ( s_app_key + "Canvas/Number/Width", 2 );
146  = settings.readNumEntry ( s_app_key + "Canvas/Number/Height", 3 );
148  = settings.readBoolEntry ( s_app_key + "Canvas/AddSelected" );
150  = settings.readBoolEntry ( s_app_key + "Canvas/IgnoreMargin" );
151 }
152 
153 void
154 CanvasView::
155 #if QT_VERSION < 0x040000
156 initDockWindows ( QMainWindow * mw )
157 #else
158 initDockWindows ( Q3MainWindow * mw )
159 #endif
160 {
161  QSettings settings;
162  settings.insertSearchPath ( QSettings::Windows, s_registry );
163  bool ok = false;
164  QString dockSetting = settings.readEntry ( s_app_key + "DockWindow/Position",
165  QString::null, &ok );
166 
167  if ( ok == false ) return;
168  QTextStream stream( &dockSetting, IO_ReadOnly );
169  stream >> *mw;
170 }
171 
172 void
175 {
176 #if QT_VERSION < 0x040000
177 #else
178  QObject * parent = ag -> parent ();
179 #endif
180  QSettings settings;
181  settings.insertSearchPath ( QSettings::Windows, s_registry );
182  bool ok = false;
183 
184  // Read every entries from the settings.
185  for (unsigned int i = 0; i<5; i++){
186  QString number=QString::number(i);
187  QString entry = settings.readEntry ( s_app_key + "Files/File"+number,
188  QString::null, &ok );
189 
190  // No entry or empty entry.
191  if ((ok==false) || ( entry == "" )) return;
192 
193 
194 #if QT_VERSION < 0x040000
195  QAction * action = new QAction ( "", // text
196  QIconSet(),
197  entry, // menu test
198  0, // accel
199  ag ); // parent
200 #else
201  QAction * action = new QAction ( entry, parent );
202  ag -> addAction ( action );
203 #endif
204  m_recent_list.push_back( action );
205  action -> setToggleAction ( true );
206  }
207 }
208 
209 
210 void
213 {
214  QSettings settings;
215  settings.insertSearchPath ( QSettings::Windows, s_registry );
216  bool ok = false;
217  QString entry = settings.readEntry ( s_app_key + "Fitter/Name",
218  QString::null, &ok );
219  if ( ok == true ) {
220  const string name ( entry.latin1() );
221  try { // might not be available
222  setFitterDefault ( name );
223  if ( m_inspector != 0 ) {
224  m_inspector -> setSelectedFitter ( name );
225  }
226  }
227  catch ( ... ) { // not available in this build
228  // could raise error dialog, but not nice on initialization
229  }
230  }
231 }
232 
233 void
235 setFitterDefault ( const QString & name )
236 {
237  QSettings settings;
238  settings.insertSearchPath ( QSettings::Windows, s_registry );
239  settings.writeEntry ( s_app_key + "Fitter/Name", name );
240 
241  const string fitter ( name.latin1() );
242  setFitterDefault ( fitter );
243 }
244 void
246 setFitterDefault ( const std::string & name )
247 {
249  controller -> setDefaultFitter ( name );
250 }
251 
252 void
255 {
257  initFitterMenu ( ag );
258 }
259 
260 void
263 {
265  const vector < string > & fitters = controller -> getFitterNames ();
266  const string & def_fitter = controller -> getDefaultFitter ();
267 #if QT_VERSION < 0x040000
268 #else
269  QObject * parent = ag -> parent ();
270 #endif
271  for ( unsigned int i = 0; i < fitters.size(); i++ ) {
272 #if QT_VERSION < 0x040000
273  const QString name ( fitters[i].c_str() );
274  QAction * action = new QAction ( "", // text
275  QIconSet(),
276  name, // menu test
277  0, // accel
278  ag ); // parent
279 #else
280  const QString name ( fitters[i].c_str() );
281  QAction * action = new QAction ( name, parent );
282  ag -> addAction ( action );
283 #endif
284  action -> setToggleAction ( true );
285  if ( def_fitter == fitters[i] ) {
286  action -> setOn ( true );
287  }
288  }
289 }
290 
291 
292 void
294 saveSettings () const
295 {
296  QSettings settings;
297  settings.insertSearchPath ( QSettings::Windows, s_registry );
298 
299  int orientation;
300  if( s_printer -> orientation() == QPrinter::Portrait )
301  orientation = 0;
302  else
303  orientation = 1;
304 
305  settings.writeEntry ( s_app_key + "Printer/Orientation", orientation );
306  settings.writeEntry ( s_app_key + "Canvas/Number/Width", m_num_width );
307  settings.writeEntry ( s_app_key + "Canvas/Number/Height", m_num_height );
308  settings.writeEntry ( s_app_key + "Canvas/AddSelected", m_add_selected );
309  settings.writeEntry ( s_app_key + "Canvas/IgnoreMargin", m_ignore_margin );
310 
311  if( m_printer_bounds == false )
312  settings.writeEntry ( s_app_key + "Canvas/Margin", 0 );
313  else
314  settings.writeEntry ( s_app_key + "Canvas/Margin", 1 );
315 }
316 
317 void
320 {
322 }
323 
324 void CanvasView::initFrom ( const std::list < ViewBase * > & views )
325 {
326  std::list < ViewBase * > ::const_iterator first = views.begin();
327  for ( ; first != views.end(); ++first ) {
328  QtView * view = dynamic_cast < QtView * > ( *first );
329  if ( view -> height () < 0 ||
330  view -> width () < 0 ) {
331  sizeAndPlace ( view );
332  }
333  add ( view ); // ignore the rest
334  }
335 
336 #if QT_VERSION < 0x040000
338 #else
340 #endif
341 }
342 
343 void
345 initFromFile ( const std::string & filename )
346 {
347  XmlController::Status status = s_xml_controller->openFile ( filename );
348 
349  // If file not found, change the directory and try again.
350  if ( status == XmlController::NTupleError ) {
351 
352  std::list < std::string > & missing_tuples =
353  s_xml_controller -> getMissingTuples ();
354  std::list< std::string>::iterator it;
355 
356  for ( it=missing_tuples.begin(); it!=missing_tuples.end(); ++it )
357  {
358  string shortFileName;
359  string::size_type pos1 = (*it).find_last_of ("/");
360  string::size_type pos2 = (*it).find_last_of (":");
361  shortFileName = (*it).substr(pos1+1); // get the short filename
362 
363  QString cap ( "Select the DataSource: " );
364  cap += shortFileName.c_str(); // Caption of the open file dialog
365  QString filter ( "All files(*.*);;Text NTuple(*.tnt);;FITS file(*.fits);;Compressed FITS file(*.fits.gz);;ROOT file(*.root)");
366 
367  QString filename =
368 #if QT_VERSION < 0x040000
369  QFileDialog::getOpenFileName ( QString::null, // starting directory
370  filter, // filter
371  this,
372  "Open file dialog",
373  cap ); // caption
374 #else
375  Q3FileDialog::getOpenFileName ( QString::null, // starting directory
376  filter, // filter
377  this,
378  "Open file dialog",
379  cap ); // caption
380 #endif
381 
382  string newFileName = filename.latin1();
383 
384 
385  if ( ( pos2!= string::npos) && (pos2 != 1) ) {
386  ( *it ).replace (0, pos2, newFileName); // keep the name
387  // after ":"
388  // unchanged
389  }
390  else {
391  ( *it )=newFileName; // with no name
392  }
393 
394  }
395 
396  status = s_xml_controller->openUpdatedNTuples ( );
397  }
398 
399 
400  // Second try failed, show failed message.
401  if ( status != XmlController::Success ) {
402  const string & app_name = applicationName ();
403 
404  QString fn = filename.c_str ();
405  QString message;
406  message = QString("Unable to open document file:\n%1\n").arg ( fn );
407  if ( status == XmlController::OpenError ) {
408  message += "\nFile could not be read\n";
409  } else
410  if ( status == XmlController::ParseError ) {
411  message += "\nThere was a XML parsing error\n";
412  } else {
413  message += "\nThere were one or more referenced\n";
414  message += "NTuple files that could not be found.";
415  }
416  QMessageBox::critical ( this, // parent
417  app_name.c_str(), // caption
418  message,
419  QMessageBox::Ok,
420  Qt::NoButton,
421  Qt::NoButton );
422  show ();
423  return;
424  }
425 
426  ViewFactory * factory = QtViewFactory::instance ();
427  const list < ViewBase * > & view_list
428  = s_xml_controller->getViews ( factory );
429 
430  initFrom ( view_list );
431 
432  notifyObservers ();
433 }
434 
435 void
437 invalidImageFormatError ( const std::string & filename )
438 {
439  if ( s_image_filters.empty () ) createImageFilters ();
440 
441  string types;
442  string::size_type size = s_image_filters.size ();
443  for ( string::size_type i = 0; i < size; i++ ) {
444  string::value_type c = s_image_filters[i];
445  if ( c != '(' &&
446  c != ')' &&
447  c != ';' ) types += c;
448  }
449 
450  string message ( "Attempt to save image to file:\n" );
451  message += filename;
452  message += "\nwhose suffix indicates unsupported image format.\n\n";
453  message += "Supported image formats are:\n";
454  message += types;
455 
456  QMessageBox::critical ( this, // parent
457  "Image format error", // caption
458  message.c_str() );
459 
460 }
461 
462 bool
464 existingFileWarning ( const std::string & filename )
465 {
466  string message ( "The file:\n" );
467  message += filename;
468  message += "\nalready exists.\n\n";
469  message += "Over-write existing file?";
470 
471  int yes = QMessageBox::warning ( this, //parent
472  "Existing file warning", // caption
473  message.c_str(),
474  QMessageBox::Yes,
475  QMessageBox::No,
476  Qt::NoButton );
477 
478  return yes == QMessageBox::Yes;
479 }
480 
484 void
487 {
488  const vector < const ViewBase * > & selViews = selectedViews();
489  if ( selViews.empty () ) return;
490 
491  vector < const ViewBase * > view_list;
492  fillSelectedWithObservers ( view_list );
493  s_xml_controller->saveToPasteboard ( view_list );
494 
496 }
497 
498 void
501 {
502  const vector < const ViewBase * > & targets = views ();
503  ViewFactory * factory = QtViewFactory::instance ();
504 
505  const list < ViewBase * > & pb_views
506  = s_xml_controller->getFromPasteboard ( factory, targets );
507  pasteViews ( pb_views );
508 }
509 
510 void
513 {
514  const vector < const ViewBase * > & targets = views ();
515  ViewFactory * factory = QtViewFactory::instance ();
516 
517  const list < ViewBase * > & pb_views
518  = s_xml_controller->getFromPasteboard ( factory, targets );
519  list < ViewBase * >::const_iterator first = pb_views.begin ();
520  while ( first != pb_views.end () ) {
521  ViewBase * view = *first++;
522  QtView * qtview = dynamic_cast < QtView * > ( view );
523  placeGraph ( qtview );
524  addView ( qtview, true );
525  }
526 }
527 
528 void
530 deleteSelected ( bool pasteboard )
531 {
532  const vector < const ViewBase * > & selViews = selectedViews();
533  if ( selViews.empty () ) return;
534 
535  vector < const ViewBase * > view_list;
536  fillSelectedWithObservers ( view_list );
537  if ( pasteboard ) {
538  s_xml_controller->saveToPasteboard ( view_list );
539  }
540 
542  controller->removeTextObservers ( view_list );
543 
544  // Remove views from the canvas.
545 
546 #ifdef ITERATOR_MEMBER_DEFECT
547  std::
548 #endif
549  vector < const ViewBase * > ::const_iterator iter = view_list.begin();
550 
551  // Remove views or group views.
552  while ( iter != view_list.end() ) {
553  const ViewBase * curview = ( * iter++ );
554  const QtView * view = dynamic_cast < const QtView * > ( curview );
555  QtView * v = 0;
556  if (view) v = const_cast < QtView * > ( view );
557  const QtGroupView * groupview =
558  dynamic_cast < const QtGroupView * > ( curview );
559  QtGroupView * gv = 0;
560  if (groupview) gv = const_cast < QtGroupView * > (groupview);
561  if (v) remove ( v );
562  if (gv) remove (gv);
563  }
564 
565  notifyObservers ();
566 }
567 
568 void
571 {
573 
574  notifyObservers ();
575 }
576 
582 {
583  const vector < const ViewBase * > & views = selectedViews ();
584 #ifdef ITERATOR_MEMBER_DEFECT
585  std::
586 #endif
587  vector < const ViewBase * > ::const_iterator first = views.begin();
588  while ( first != views.end() ) {
589  const QtView * view = dynamic_cast < const QtView * > ( *first++ );
590  QtView * v = const_cast < QtView * > ( view );
591  remove ( v );
592  }
593 }
594 
598 void CanvasView::pasteViews ( const std::list < ViewBase * > & views )
599 {
601  std::list < ViewBase * > ::const_iterator first = views.begin();
602  for ( ; first != views.end(); ++first ) {
603  QtView * view = dynamic_cast < QtView * > ( *first );
604  paste ( view );
605  addSelectedItem ( view );
606  }
607 
608  setChanged ( true );
609 }
610 
612 {
613  m_inspector = inspector;
615 }
616 
618 {
619  return m_inspector;
620 }
621 
622 void CanvasView::setChanged ( bool flag )
623 {
624  QWidget * parent = parentWidget ();
625  if ( parent != 0 ) {
626  PlotterEvent * event = new PlotterEvent ( 0 );
627  QApplication::postEvent ( parent, event );
628  }
629 }
630 
632 {
633  setChanged ( true );
634  if ( m_inspector != 0 ) {
635  vector < PlotterBase * > plotters = getSelectedPlotters ();
636 
637  CanvasSelectionEvent * event = new CanvasSelectionEvent ( plotters );
639  }
640 
642  controller -> updateActions ();
643 }
644 
645 vector < PlotterBase * >
648 {
649  vector < PlotterBase * > plotters;
650 
651  const vector < const ViewBase * > & viewList = selectedViews ();
652  unsigned int size = viewList.size ();
653  for ( unsigned int i = 0; i < size; i++ ) {
654  const ViewBase * view = viewList [ i ];
655 
656  const QtGroupView * groupView = dynamic_cast <const QtGroupView *> (view);
657 
658  if (groupView) {
659  const vector <PlotterBase *> groupPlotters = groupView -> getPlotters ();
660  plotters.insert ( plotters.end(),
661  groupPlotters.begin(), groupPlotters.end() );
662  break;
663  }
664 
665  //else
666  PlotterBase * plotter = view -> getPlotter ();
667  if ( plotter != 0 ) {
668  plotters.push_back ( plotter );
669  }
670  }
671 
672  return plotters;
673 }
674 
676 {
677  const vector < const ViewBase * > & viewList = selectedViews ();
678 
679  if ( viewList.size() != 1 )
680  {
681  return 0;
682  }
683 
684  PlotterBase * plotter = viewList[0]->getPlotter ();
685  //assert ( plotter ); // Can return 0, handle by caller.
686 
687  return plotter;
688 }
689 
690 void
692 addView ( QtView * view, bool select )
693 {
694  add ( view ); // in FigureEditor
695  if ( select ) {
696  ensureVisible ( view );
697  setSelectedItem ( view );
698  vector < const ViewBase * > view_list;
699  fillSelectedWithObservers ( view_list );
700  s_xml_controller -> saveToSelectionCopy ( view_list );
701  }
702  notifyObservers ();
703 }
704 
705 void
707 setPlotMatrix ( unsigned int columns, unsigned int rows )
708 {
709  m_num_width = columns;
710  m_num_height = rows;
711 }
712 
713 void
716 {
717 #if QT_VERSION < 0x040000
718  QCanvas * can = canvas();
719 #else
720  Q3Canvas * can = canvas();
721 #endif
722  int numpages = static_cast<int> ( can -> height()
723  / (double) m_apage_h );
724  std::swap( m_upage_w, m_upage_h );
725  std::swap( m_apage_w, m_apage_h );
726 
727  can -> resize ( static_cast<int> ( 1.2 * m_upage_w ),
728  numpages * m_apage_h );
729 
730  showPrinterMargins ( false ); // Delete old ones ( if any )
731  showPrinterMargins ( true ); // Redraw new ones ( if needed )
732 }
733 
734 void
737 {
738  CanvasSettings * cs = new CanvasSettings ( this );
739  cs -> setOrientation ( s_printer -> orientation() );
740  cs -> setWidthNumber ( m_num_width );
741  cs -> setHeightNumber ( m_num_height );
742  cs -> setAddSelected ( m_add_selected );
743  cs -> setPrinterBounds ( m_printer_bounds );
744  cs -> setIgnorePrinterMargin ( m_ignore_margin );
745 
746  int retval = cs -> exec ();
747 
748  if ( retval == CanvasSettings::AcceptedAndRetile ||
749  retval == CanvasSettings::Retile )
750  {
751  m_add_selected = cs -> getAddSelected ();
752 
753 
754  if ( cs -> orientation() != s_printer -> orientation() ) {
755  s_printer -> setOrientation( cs -> orientation() );
756  swapOrientation ();
757  }
758 
759  if( cs -> printerBounds() == false )
760  showPrinterMargins ( false ); // Delete old ones ( if any )
761  else
762  {
763  showPrinterMargins ( false ); // Delete old ones ( if any )
764  showPrinterMargins ( true ); // Redraw new ones ( if needed )
765  }
766 
767  m_ignore_margin = cs -> ignorePrinterMargin ();
768  }
769 
770  if ( retval == CanvasSettings::AcceptedAndRetile ||
771  retval == CanvasSettings::Retile ) {
772  unsigned int columns = cs -> getWidthNumber ();
773  unsigned int rows = cs -> getHeightNumber ();
774  setPlotMatrix ( columns, rows );
775  reTile ();
776  }
777 
778  if ( retval == CanvasSettings::AcceptedAndRetile ) {
779  saveSettings ();
780  }
781 
782  delete cs;
783 }
784 
785 
786 void
788 setFonts( const QFont & font )
789 {
790  const vector < const ViewBase * > & allviews = views();
791 
792  for( unsigned int i = 0; i < allviews.size(); i++ )
793  {
794  const ViewBase * curview = allviews[ i ];
795  const QtView * view = dynamic_cast < const QtView * > ( curview );
796  QtView * v = const_cast < QtView * > ( view );
797  v -> setDefaultFont( font );
798  v -> getPlotter() -> update();
799  }
800 }
801 
802 void
804 calcDefaultSize ( QtView * view, double transform_aspect_ratio )
805 {
806  double width = ( 0.95 * m_upage_w ) / m_num_width;
807  double height = ( 0.95 * m_upage_h ) / m_num_height;
808 
809  if ( transform_aspect_ratio > 0.0 )
810  {
811  width = height * transform_aspect_ratio;
812  }
813 
814  view -> setDrawRect ( 0.0, 0.0, width, height );
815 }
816 
817 
818 void
821 {
822  addPlotDisplay ( plotter, m_add_selected );
823 }
824 
825 QtView *
828 {
829  ViewFactory * factory = QtViewFactory::instance ();
830  ViewBase * view = factory -> createView ( plotter );
831  QtView * qtview = dynamic_cast< QtView * > ( view );
832  qtview -> setSize ( -1, -1 );
833 
834  return qtview;
835 }
836 
837 void CanvasView::addPlotDisplay ( PlotterBase * plotter, bool select )
838 {
839  QtView * qtview = wrapPlotter ( plotter );
840  qtview -> setPageWidth( m_upage_w );
841  qtview -> setInspector( m_inspector );
842  sizeAndPlace ( qtview );
843 
844  addView ( qtview, select );
845 }
846 
847 void
850 {
851  PlotterBase * plotter = view -> getPlotter ();
852  double transform_aspect_ratio = plotter -> getAspectRatio();
853  calcDefaultSize ( view, transform_aspect_ratio );
854  placeGraph ( view );
855 }
856 
857 static bool
858 #if QT_VERSION < 0x040000
859 sortViews ( QCanvasItem * first, QCanvasItem * second )
860 #else
861 sortViews ( Q3CanvasItem * first, Q3CanvasItem * second )
862 #endif
863 {
864  bool yes = false;
865 
866  QRect frect = first -> boundingRect ();
867  QRect srect = second -> boundingRect ();
868 
869  if ( frect.left () < srect.left () ) {
870  if ( frect.top() < srect.bottom () ) {
871  yes = true;
872  }
873  }
874  if ( frect.right () > srect.right () ) {
875  if ( frect.bottom () < srect.top () ) {
876  yes = true;
877  }
878  }
879  else {
880  yes = frect.top () < srect.top ();
881  }
882 
883  return yes;
884 }
885 
886 void
889 {
890 #if QT_VERSION < 0x040000
891  QCanvas temp_canvas;
892 #else
893  Q3Canvas temp_canvas;
894 #endif
895 #ifdef MEMFUN1_DEFECT
896  for_each ( m_items.begin(), m_items.end(),
897 #if QT_VERSION < 0x040000
898  bind2nd ( mem_fun1 ( & QCanvasItem::setCanvas ), &temp_canvas ) );
899 #else
900  bind2nd ( mem_fun1 ( & Q3CanvasItem::setCanvas ),
901  &temp_canvas ) );
902 #endif
903 #else
904  for_each ( m_items.begin(), m_items.end(),
905 #if QT_VERSION < 0x040000
906  bind2nd ( mem_fun ( & QCanvasItem::setCanvas ), &temp_canvas ) );
907 #else
908  bind2nd ( mem_fun ( & Q3CanvasItem::setCanvas ), &temp_canvas ) );
909 #endif
910 #endif
911 
912 #if QT_VERSION < 0x040000
913  vector < QCanvasItem * > items ( m_items );
914 #else
915  vector < Q3CanvasItem * > items ( m_items );
916 #endif
917  m_items.clear();
918 
919  sort ( items.begin(), items.end(), sortViews );
920 
921  placeItems ( items );
922 }
923 
924 void
925 CanvasView::
926 #if QT_VERSION < 0x040000
927 placeItems ( const std::vector < QCanvasItem * > & items )
928 {
929  vector < QCanvasItem * >:: const_iterator first = items.begin();
930 #else
931 placeItems ( const std::vector < Q3CanvasItem * > & items )
932 {
933  vector < Q3CanvasItem * >:: const_iterator first = items.begin();
934 #endif
935 
936  // Place xy plotters before text plotters.
937  vector <QtView *> textViews;
938 
939  while ( first != items.end() )
940  {
941  QtView * view = dynamic_cast < QtView * > ( *first++ );
942 
943  PlotterBase * plotter = view->getPlotter();
944  if (plotter->isTextPlotter()) {
945  // Move back to (0,0) and add to textView list.
946  double x = view -> x ();
947  double y = view -> y ();
948  view->moveBy(-x, -y);
949  textViews.push_back(view);
950  continue;
951  }
952  calcDefaultSize ( view, view -> getAspectRatio() );
953  placeGraph ( view );
954  add ( view );
955  }
956 
957  // Add text plotters to their parent plotters
958  vector <QtView *>::const_iterator it = textViews.begin();
959  while ( it != textViews.end() )
960  {
961  QtView * view = *it++;
962  moveToPlotter(view->getPlotter()->getParentPlotter(), view );
963  add ( view );
964  }
965 }
966 
967 void
970 {
971  int y = contentsY ();
972  int page = y / m_apage_h;
973  QRect rect ( 0, page * m_apage_h, m_apage_w, m_apage_h );
974 #if QT_VERSION < 0x040000
975  QCanvasItemList c_items = m_canvas -> collisions ( rect );
976 
977  // copy to STL vector and remove from item list.
978  vector < QCanvasItem * > v_items;
979  QCanvasItemList:: const_iterator first = c_items.begin();
980  while ( first != c_items.end() ) {
981  QCanvasItem * item = *first++;
982 #else
983  Q3CanvasItemList c_items = m_canvas -> collisions ( rect );
984 
985  // copy to STL vector and remove from item list.
986  vector < Q3CanvasItem * > v_items;
987  Q3CanvasItemList:: const_iterator first = c_items.begin();
988  while ( first != c_items.end() ) {
989  Q3CanvasItem * item = *first++;
990 #endif
991  QtView * view = dynamic_cast < QtView * > ( item );
992 
993  if ( view != 0 ) { // avoid page margin rect
994  v_items.push_back ( item );
995  removeFromItemList ( item );
996  }
997  }
998 
999  placeItems ( v_items );
1000 }
1001 
1002 void CanvasView::moveToPlotter ( const PlotterBase * plotter, QtView * view )
1003 {
1004  QtView * target = getViewFor ( plotter );
1005  QRect rect = target -> boundingRect ();
1006  double x = target -> x ();
1007  double y = target -> y ();
1008  x += 0.25 * rect.width();
1009  y += 0.25 * rect.height();
1010 
1011  view->moveBy ( x, y );
1012 }
1013 
1014 std::pair<double, double>
1016 moveToPlotterAt ( const PlotterBase * plotter,
1017  QtView * view,
1018  double xrel, double yrel )
1019 {
1020  QtView * sel_item = getViewFor ( plotter );
1021  QRect rect = sel_item->boundingRect ();
1022  double x = sel_item->x();
1023  double y = sel_item->y();
1024  x += xrel * rect.width();
1025  y += yrel * rect.height();
1026 
1027  view->moveBy ( x, y );
1028 
1029 // Find the lower left corner of the view.
1030  QRect viewRect = view->boundingRect();
1031  double xLowerLeft = view->x();
1032  double yLowerLeft = view->y() + viewRect.height();
1033 
1034 // Normalize to selectedItem coordinate system.
1035  xLowerLeft = ( xLowerLeft - sel_item->x() ) / rect.width();
1036  yLowerLeft = ( yLowerLeft - sel_item->y() ) / rect.height();
1037 
1038  return std::make_pair<double, double>(xLowerLeft, yLowerLeft);
1039 }
1040 
1041 void
1044  const std::string & s,
1045  const std::string & text )
1046 {
1047  DisplayController * display_controller = DisplayController::instance ();
1048  ViewFactory * factory = QtViewFactory::instance ();
1049 
1050  ViewBase * view
1051  = display_controller->createTextView ( factory, plotter, s, text );
1052  assert ( view != 0 );
1053 
1054  QtView * qtview = dynamic_cast < QtView * > ( view );
1055  assert ( qtview != 0 );
1056 
1057  moveToPlotter ( plotter, qtview );
1058 
1059  addView ( qtview, false );
1060 
1061  // Make sure new view on top of others
1062  double z = maximumZ ();
1063 
1064  // Make sure the new text plotter on top all other text plotters
1065  qtview->setZ(z+101.0);
1066 }
1067 
1068 std::pair<double, double>
1071  const std::string & type,
1072  const std::string & text,
1073  double x, double y )
1074 {
1075  DisplayController * display_controller = DisplayController::instance ();
1076  ViewFactory * factory = QtViewFactory::instance ();
1077 
1078  ViewBase * view
1079  = display_controller->createTextView ( factory, plotter, type, text );
1080 
1081  QtView * qtview = dynamic_cast < QtView * > ( view );
1082 
1083  std::pair<double, double> lowerLeftCorner
1084  = moveToPlotterAt ( plotter, qtview, x, y );
1085 
1086  addView ( qtview, false );
1087 
1088  return lowerLeftCorner;
1089 }
1090 
1091 void
1093 addFuncDisplay ( PlotterBase * plotter, const std::string & s)
1094 {
1096  const ViewFactory * factory = QtViewFactory::instance ();
1097 
1098  ViewBase * view
1099  = controller->createFuncView ( factory, plotter, s );
1100 
1101  QtView * qtview = dynamic_cast < QtView * > ( view );
1102  moveToPlotter ( plotter, qtview );
1103 
1104  addView (qtview, false );
1105 }
1106 
1109 void
1112 {
1113  QtView * view = getViewFor ( plotter );
1114 
1115  if ( view != 0 ) remove ( view );
1116 }
1117 
1118 void
1121 {
1122 #if QT_VERSION < 0x040000
1123  QCanvasItemList items = m_canvas->allItems ();
1124  QCanvasItemList::Iterator first = items.begin();
1125  while ( first != items.end() ) {
1126  QCanvasItem * item = *first++;
1127 #else
1128  Q3CanvasItemList items = m_canvas->allItems ();
1129  Q3CanvasItemList::Iterator first = items.begin();
1130  while ( first != items.end() ) {
1131  Q3CanvasItem * item = *first++;
1132 #endif
1133  QtView * view = dynamic_cast < QtView * > ( item );
1134  if ( view == 0 ) {
1135  item -> setVisible ( yes );
1136  }
1137  }
1138 }
1139 
1140 void
1143 {
1144  setVisibleNonViews ( false );
1146  setVisibleNonViews ( true );
1147 }
1148 
1149 void
1151 print ( const std::string & filename )
1152 {
1153  setVisibleNonViews ( false );
1154  FigureEditor::print ( filename );
1155  setVisibleNonViews ( true );
1156 }
1157 
1158 
1159 const vector < const ViewBase * > &
1162 {
1163  m_sel_views.clear ();
1164 
1165 #if QT_VERSION < 0x040000
1166  vector < QCanvasItem * > :: const_iterator first = m_selected_list.begin();
1167  while ( first != m_selected_list.end() ) {
1168  QCanvasItem * item = *first++;
1169 #else
1170  vector < Q3CanvasItem * > :: const_iterator first = m_selected_list.begin();
1171  while ( first != m_selected_list.end() ) {
1172  Q3CanvasItem * item = *first++;
1173 #endif
1174  QtView * view = dynamic_cast < QtView * > ( item );
1175  if ( view != 0 ) { // may be printer page border
1176  m_sel_views.push_back ( view );
1177  }
1178  QtGroupView * groupview = dynamic_cast < QtGroupView * > ( item );
1179  if ( groupview != 0 ){
1180  m_sel_views.push_back ( groupview );
1181  }
1182  }
1183 
1184  return m_sel_views;
1185 }
1186 
1187 const vector < const ViewBase * > & CanvasView::views () const
1188 {
1189  m_views.clear();
1190 
1191 #if QT_VERSION < 0x040000
1192  QCanvasItemList item_list = m_canvas->allItems();
1193  QCanvasItemList::Iterator it = item_list.begin();
1194 #else
1195  Q3CanvasItemList item_list = m_canvas->allItems();
1196  Q3CanvasItemList::Iterator it = item_list.begin();
1197 #endif
1198  for ( ; it != item_list.end(); ++ it ) {
1199  const QtView * view = dynamic_cast < const QtView * > ( *it );
1200  if ( view != 0 ) {
1201  m_views.push_back ( view );
1202  }
1203  }
1204 
1205  return m_views;
1206 }
1207 
1208 void
1210 fillPlotterList ( std::vector < PlotterBase * > & plotterlist )
1211 {
1212  plotterlist.clear();
1213 
1214  const vector < const ViewBase * > & view_list = views ();
1215 #ifdef ITERATOR_MEMBER_DEFECT
1216  std::
1217 #endif
1218  vector < const ViewBase * >::const_iterator first = view_list.begin ();
1219  for ( ; first != view_list.end(); ++first ) {
1220  const QtView * qtview = dynamic_cast < const QtView * > ( *first );
1221  plotterlist.push_back ( qtview->getPlotter () );
1222  }
1223 }
1224 
1225 
1226 QtView *
1228 getViewFor ( const PlotterBase * target ) const
1229 {
1230  QtView * view = 0;
1231  const vector < const ViewBase * > & all_views = views ();
1232  vector < const ViewBase * > :: const_iterator first = all_views.begin();
1233 
1234  while ( first != all_views.end() ) {
1235  const ViewBase * vb = *first++;
1236  const PlotterBase * plotter = vb->getPlotter();
1237  if ( plotter == target ) {
1238  const QtView * v = dynamic_cast < const QtView * > ( vb );
1239  view = const_cast < QtView * > ( v );
1240  break;
1241  }
1242  }
1243 
1244  return view;
1245 }
1246 
1247 void
1250 {
1251 #ifdef STRING_CLEAR_DEFECT
1252  s_image_filters.erase();
1253 #else
1254  s_image_filters.clear();
1255 #endif
1256 
1257  const string eps ( "eps" );
1258  bool eps_inserted = false;
1259 
1260 #if QT_VERSION < 0x040000
1262  QStringList::Iterator it = slist.begin();
1263 #else
1264  QList < QByteArray > slist = QImageWriter::supportedImageFormats ();
1265  QList < QByteArray > ::const_iterator it = slist.begin();
1266 #endif
1267 
1268  while ( it != slist.end() ) {
1269  QString upper = *it++;
1270  QString lower = upper.lower();
1271 #if QT_VERSION < 0x030100
1272  string low ( lower );
1273 #else
1274  string low = lower.latin1();
1275 #endif
1276 #ifdef Q_OS_MACX
1277 #else // not mac os x
1278  if ( low == "jpeg" ) low = "jpg";
1279 #endif
1280  if ( eps >= low ) {
1281 
1282 #if QT_VERSION < 0x040000
1283  s_image_filters += low +"(*." + low + ");;";
1284 #else
1285  s_image_filters += " (*." + low + ");;";
1286 #endif
1287  }
1288  else {
1289  if ( eps_inserted == false ) {
1290 #if QT_VERSION < 0x040000
1291  s_image_filters += eps + "(*." + eps + ");;";
1292 #else
1293  s_image_filters += "(*." + eps + ");;";
1294 #endif
1295  eps_inserted = true;
1296  }
1297 #if QT_VERSION < 0x040000
1298  s_image_filters += low + "(*." + low + ");;";
1299 #else
1300  s_image_filters += "(*." + low + ");;";
1301 #endif
1302  }
1303  }
1304  // Add FITS file.
1305 #if QT_VERSION < 0x040000
1306  s_image_filters += "FITS(*.fits);;";
1307 #else
1308  s_image_filters += "(*.fits);;";
1309 #endif
1310 
1311 #if QT_VERSION < 0x040000
1312  s_image_filters += "Compressed FITS(*.fits.gz)";
1313 #else
1314  s_image_filters += "(*.fits.gz)";
1315 #endif
1316 }
1317 
1318 #if QT_VERSION < 0x040000
1319 QFileDialog *
1320 #else
1321 Q3FileDialog *
1322 #endif
1325 {
1326  if ( s_image_filters.empty () ) createImageFilters ();
1327 
1328  QString filters = s_image_filters.c_str();
1329 
1330 #if QT_VERSION < 0x040000
1331  QFileDialog * dialog = new QFileDialog ( this );
1332  dialog->setFilters ( filters );
1333  dialog->setMode ( QFileDialog::AnyFile );
1334 #else
1335  Q3FileDialog * dialog = new Q3FileDialog ( this );
1336  dialog->setFilters ( filters );
1337  dialog->setMode ( Q3FileDialog::AnyFile );
1338 #endif
1339 
1340  return dialog;
1341 }
1342 
1343 /* The menu item calling this method is disabled when no plot is
1344  selected so there's no need to see if any plots are selected
1345  here.
1346 */
1347 void
1350 {
1351  setVisibleNonViews ( false );
1352 
1353 #if QT_VERSION < 0x040000
1354  const vector < QCanvasItem * > views = getSelectedItems (); // make copy
1355 #else
1356  const vector < Q3CanvasItem * > views = getSelectedItems (); // make copy
1357 #endif
1358  assert ( views.empty () == false );
1359 
1360  for ( unsigned int i = 0; i < views.size (); i++ ) {
1361  setCollidingSelected ( views[i] );
1362  }
1363 
1364  if ( s_image_filters.empty () ) createImageFilters ();
1365  QString sel_filt;
1366 #if QT_VERSION < 0x040000
1367  QString filename
1368  = QFileDialog::getSaveFileName ( QString::null, // working dir
1369  s_image_filters.c_str(),
1370  this, // parent
1371  0, // name
1372  "Save image as", // caption
1373  & sel_filt ); // selected filter
1374 #else
1375  QString filename
1376  = Q3FileDialog::getSaveFileName ( QString::null, // working dir
1377  s_image_filters.c_str(),
1378  this, // parent
1379  0, // name
1380  "Save image as", // caption
1381  & sel_filt ); // selected filter
1382 #endif
1383 
1384  if ( filename.isEmpty () ) return;
1385 
1386  filename.stripWhiteSpace ();
1387 
1388 #if QT_VERSION < 0x030100
1389  string fn ( filename );
1390 #else
1391  string fn = filename.latin1();
1392 #endif
1393 
1394  int pos = filename.findRev ( '.' );
1395  if ( pos < 0 ) {
1396  string sf = sel_filt.latin1();
1397  string::size_type pos1 = sf.find ( '(' );
1398  string::size_type pos2 = sf.find_last_of ( ')' );
1399  string::size_type len = ( pos2 ) - ( pos1 + 2 );
1400  string suffix = sf.substr ( pos1 + 2, len );
1401  fn += suffix;
1402  }
1403 
1404  saveSelectedImages ( fn, true );
1405 
1406  // Restore original selection flags.
1407  m_selected_list.clear();
1408  for ( unsigned int i = 0; i < views.size(); i++ ) {
1409  m_selected_list.push_back ( views[i] );
1410  }
1411  setSelectedFlags ();
1412  setVisibleNonViews ( true );
1413 }
1414 
1415 void
1417 saveSelectedImages (const std::string & filename)
1418 {
1419  setVisibleNonViews ( false );
1420 
1421 #if QT_VERSION < 0x040000
1422  const vector < QCanvasItem * > views = getSelectedItems (); // make copy
1423 #else
1424  const vector < Q3CanvasItem * > views = getSelectedItems (); // make copy
1425 #endif
1426  if (views.empty()) {
1427  return;
1428  }
1429 
1430  for ( unsigned int i = 0; i < views.size (); i++ ) {
1431  setCollidingSelected ( views[i] );
1432  }
1433 
1434  saveSelectedImages ( filename, false );
1435 
1436  // Restore original selection flags.
1437  m_selected_list.clear();
1438  for ( unsigned int i = 0; i < views.size(); i++ ) {
1439  m_selected_list.push_back ( views[i] );
1440  }
1441  setSelectedFlags ();
1442  setVisibleNonViews ( true );
1443 }
1444 
1449 {
1451  const vector < const ViewBase * > & view_list = views ();
1452  vector < const ViewBase * > ::const_iterator first = view_list.begin ();
1453 
1454  while ( first != view_list.end() ) {
1455  const ViewBase * view = *first++;
1456  PlotterBase * plotter = view->getPlotter();
1457  controller -> setAllIntervalEnabled ( plotter, yes );
1458  }
1459 }
1460 
1461 void
1464 {
1465 
1466  ViewFactory * factory = QtViewFactory::instance ();
1467  const vector < const ViewBase * > & targets = views ();
1468 
1469  const list < ViewBase * > & views
1470  = s_xml_controller->getFromSelectionCopy ( factory, targets );
1471 
1472  if ( views.empty() == false ) {
1473  removeSelected ();
1474  pasteViews ( views );
1475 
1476  notifyObservers ();
1477  }
1478 }
1479 
1481 {
1482 #if QT_VERSION < 0x040000
1483  QCanvasItem * selItem = m_selected_list.front ();
1484 #else
1485  Q3CanvasItem * selItem = m_selected_list.front ();
1486 #endif
1487  QtView * qtview = dynamic_cast < QtView * > ( selItem );
1488  assert ( qtview );
1489 
1490  PlotterBase * plotter = qtview->getPlotter ();
1491  assert ( plotter );
1492 
1493  plotter -> toggleActivePlot ();
1494 }
1495 
1496 void
1498 fillSelectedWithObservers ( std::vector < const ViewBase * > & view_list )
1499 {
1500  const vector < const ViewBase * > & sel_views = selectedViews ();
1501 
1502  view_list.resize ( sel_views.size() );
1503  copy ( sel_views.begin(), sel_views.end(), view_list.begin() );
1504 
1506  const vector < const ViewBase * > & all_views = views ();
1507 
1508  controller->addTextViewToList ( view_list, all_views );
1509 }
1510 
1512 {
1514  if ( (e->button() == Qt::RightButton) ||( e->state() == Qt::RightButton)) {
1515  contentsMouseMoveEvent ( e );
1516  }
1517 
1518  const vector < const ViewBase * > & sel_views = selectedViews ();
1519 
1520  if ( ! sel_views.empty () ) {
1521  vector < const ViewBase * > view_list;
1522  fillSelectedWithObservers ( view_list );
1523  s_xml_controller->saveToSelectionCopy ( view_list );
1524  }
1525 
1526  notifyObservers();
1527 }
1528 
1529 
1534 {
1535 //If right button pressed, get the position and show on the status bar.
1536  if ( (e->button() == Qt::RightButton) ||( e->state() & Qt::RightButton)) {
1537 #if QT_VERSION < 0x040000
1538  QCanvasItem * right_item=FigureEditor::getRightItem ();
1539 #else
1540  Q3CanvasItem * right_item=FigureEditor::getRightItem ();
1541 #endif
1542  if ( right_item == 0 ) return;
1543 
1544 #if QT_VERSION < 0x040000
1545  QCanvasRectangle * rect
1546  = dynamic_cast <QCanvasRectangle *> ( right_item );
1547 #else
1548  Q3CanvasRectangle * rect
1549  = dynamic_cast <Q3CanvasRectangle *> ( right_item );
1550 #endif
1551 
1552 
1553  QPoint p = inverseWorldMatrix().map(e->pos());
1554 
1555  if ( ( p.x() >= rect->x() ) &&
1556  ( p.x() <= rect->x() + rect->width() ) &&
1557  ( p.y() >= rect->y() ) &&
1558  ( p.y() <= rect->y() + rect->height() ) ) {
1559 
1560  QtView * qtview = dynamic_cast < QtView * > ( right_item );
1561  if ( qtview == 0 ) //return;
1562  {
1563  QtGroupView * gv = dynamic_cast <QtGroupView *> (right_item);
1564  const vector <ViewBase * > & views = gv->getViews();
1565  vector < ViewBase * >::const_iterator first = views.begin();
1566  for ( ; first != views.end(); ++first ) {
1567  QtView * v = dynamic_cast < QtView * > ( *first );
1568  if ( ( p.x() >= v->x() ) &&
1569  ( p.x() <= v->x() + v->width() ) &&
1570  ( p.y() >= v->y() ) &&
1571  ( p.y() <= v->y() + v->height() ) ) {
1572  qtview = v;
1573  break;
1574  }
1575  }
1576  if ( qtview == 0 ) return; // click between views
1577  }
1578 
1579 
1580  vector < double > picked;
1581  qtview -> fillPickedPoint ( p.x(), p.y(), picked );
1582  if ( picked.empty () ) return;
1583 
1584  unsigned int size = picked.size();
1585  double datax = picked[1];
1586  double datay = picked[2]; // scaled if needed
1587  double dataz = 0.0;
1588  if ( size >= 4 ) {
1589  dataz = picked[3];
1590  }
1591 
1592  double unscaledDataX = picked[1];
1593  double unscaledDataY = picked[2];
1594  if ( std::abs ( picked[0] - 1.0 ) < 0.5 ) unscaledDataY = picked[3];
1595 
1596  // Set cross cursor for fits image with transfom.
1597  BinaryTransform * tf_fits
1598  = dynamic_cast < BinaryTransform * >
1599  ( qtview->getPlotter()->getFitsTransform() );
1600 
1601  // tf_fits = 0 if the plot is not fits image with transform.
1602  if ( tf_fits ){
1603  tf_fits -> transform ( unscaledDataX, unscaledDataY );
1604  }
1605 
1606  qtview->setCrossX ( unscaledDataX );
1607  qtview->setCrossY ( unscaledDataY );
1608  qtview->setShowCrossHairs ( true );
1609  const QCursor cursor ( Qt::CrossCursor );
1610  QApplication::setOverrideCursor ( cursor, true );
1611  qtview->update(0);
1612 
1613  QString qstr = QString
1614  ( "Coordinates are : ( %1, %2, %3 )" )
1615  .arg ( datax )
1616  .arg ( datay )
1617  .arg ( dataz );
1618 
1619  CanvasWindow * cw = dynamic_cast < CanvasWindow * > ( parentWidget() );
1620  QStatusBar * sb = cw->statusBar();
1621  sb->message ( qstr );
1622 
1623 
1624  // Skip cut setting if in pick mode.
1625  // Add pick table if needed.
1626  if (m_cut_mode == 0 ){
1627  PickTable * table = 0;
1628  map < const QtView*, PickTable * > ::iterator first
1629  = m_table_map.find ( qtview );
1630  if ( first != m_table_map.end () ) {
1631  table = m_table_map [ qtview ];
1632  }
1633  else {
1634  PlotterBase * plotter = qtview->getPlotter ();
1635 
1636  table = new PickTable ( plotter );
1637  m_table_map [ qtview ] = table;
1638  }
1639  return;
1640  }
1641 
1642  // Set the cut range if the current plotter is a cut.
1643  PlotterBase * plotter = qtview->getPlotter();
1644  if ( plotter == 0 ) return;
1645  Cut1DPlotter * cut1d = dynamic_cast < Cut1DPlotter * > (plotter);
1646  Cut2DPlotter * cut2d = dynamic_cast < Cut2DPlotter * > ( plotter );
1647 
1648 
1649  // Set the cut range to be within the plotter range.
1650  // Cut1D plotter
1651  if ( cut1d ) {
1652  double cut_low = cut1d->getCutRange().low();
1653  double cut_high = cut1d->getCutRange().high();
1654  double plotter_low = cut1d->getRange( Axes::X, true ).low();
1655  double plotter_high = cut1d->getRange( Axes::X, true ).high();
1656 
1657  if (m_cut_mode == 1){
1658 
1659  if ( cut_low < plotter_low )
1660  {
1661  Range currentRange = Range ( plotter_low, cut_high );
1662  cut1d -> setCutRangeAt ( currentRange , 0 );
1663  }
1664  if ( cut_high > plotter_high )
1665  {
1666  Range currentRange = Range ( cut_low , plotter_high );
1667  cut1d -> setCutRangeAt ( currentRange , 0 );
1668  }
1669  }
1670 
1671  }
1672 
1673  // Cut2D plotter
1674  else if ( cut2d ) {
1675  double cut_low_x = cut2d->getCutRange().low();
1676  double cut_high_x = cut2d->getCutRange().high();
1677  double plotter_low_x = cut2d->getRange( Axes::X, true ).low();
1678  double plotter_high_x = cut2d->getRange( Axes::X, true ).high();
1679  double cut_low_y = cut2d->getCutRangeY().low();
1680  double cut_high_y = cut2d->getCutRangeY().high();
1681  double plotter_low_y = cut2d->getRange( Axes::Y, true ).low();
1682  double plotter_high_y = cut2d->getRange( Axes::Y, true ).high();
1683 
1684  if ( m_cut_mode == 1 ) {
1685 
1686  if ( cut_low_x < plotter_low_x )
1687  {
1688  Range currentRange = Range ( plotter_low_x, cut_high_x );
1689  cut2d -> setCutRangeAt ( currentRange , 0 );
1690  }
1691  if ( cut_high_x > plotter_high_x )
1692  {
1693  Range currentRange = Range ( cut_low_x , plotter_high_x );
1694  cut2d -> setCutRangeAt ( currentRange , 0 );
1695  }
1696 
1697  if ( cut_low_y < plotter_low_y )
1698  {
1699  Range currentRange = Range ( plotter_low_y, cut_high_y );
1700  cut2d -> setCutRangeAt ( currentRange , 1 );
1701  }
1702  if ( cut_high_y > plotter_high_y )
1703  {
1704  Range currentRange = Range ( cut_low_y , plotter_high_y );
1705  cut2d -> setCutRangeAt ( currentRange , 1 );
1706  }
1707  }
1708  }
1709 
1710 
1711 
1712  // Set cut according to the cut mode.
1713  switch ( m_cut_mode ){
1714  case 1:
1715  if ( cut1d ) {
1716  Range oldRange = cut1d -> getCutRange ();
1717  double old_low = oldRange.low();
1718  double old_high = oldRange.high();
1719 
1720  if ( datax < ( old_low + old_high ) / 2 ) {
1721  Range currentRange = Range ( datax , old_high );
1722  cut1d -> setCutRangeAt ( currentRange , 0 );
1723  }
1724 
1725  else
1726  {
1727  Range currentRange = Range ( old_low , datax );
1728  cut1d -> setCutRangeAt ( currentRange , 0 );
1729  }
1730  notifyObservers();
1731  }
1732 
1733  // Cut2D plotter
1734  else if ( cut2d ) {
1735  Range oldRangeX = cut2d -> getCutRange ();
1736  Range oldRangeY = cut2d -> getCutRangeY ();
1737  double old_low_x = oldRangeX.low();
1738  double old_high_x = oldRangeX.high();
1739  double old_low_y = oldRangeY.low();
1740  double old_high_y = oldRangeY.high();
1741 
1742  // Distances to each edge.
1743  double dis_low_x = std::abs ( datax - old_low_x );
1744  double dis_high_x = std::abs ( datax - old_high_x );
1745  double dis_low_y = std::abs ( datay - old_low_y );
1746  double dis_high_y = std::abs ( datay - old_high_y );
1747 
1748  // Left-bottom
1749  if ( ( dis_low_x <= 0.1 * (old_high_x - old_low_x)) &&
1750  ( dis_low_y <= 0.1 * (old_high_y - old_low_y)) &&
1751  ( m_edge == 0 ) || ( m_edge == 1 ) ) {
1752  Range currentRange = Range ( datax, old_high_x );
1753  cut2d -> setCutRangeAt ( currentRange, 0 );
1754 
1755  // Handle shift drag.
1756  if ( e->state() & Qt::ShiftButton) {
1757  int view_top = qtview->toViewY(old_high_y);
1758  int view_left = qtview->toViewX(datax);
1759  int view_right = qtview->toViewX(old_high_x);
1760  int view_bottom = view_top + view_right - view_left;
1761 
1762  // Not effecient to call fillPickedPoint(), but marginToUser()
1763  // is protected.
1764  vector <double> adjusted;
1765  qtview->fillPickedPoint(view_left, view_bottom, adjusted);
1766  currentRange = Range ( adjusted[2], old_high_y );
1767  }
1768  else
1769  currentRange = Range ( datay, old_high_y );
1770  cut2d -> setCutRangeAt ( currentRange, 1 );
1771  m_edge = 1;
1772  }
1773 
1774  // Left-top
1775  else if ( ( dis_low_x <= 0.1 * (old_high_x - old_low_x)) &&
1776  ( dis_high_y <= 0.1 * (old_high_y - old_low_y)) &&
1777  ( m_edge == 0 ) || ( m_edge == 2 ) ) {
1778  Range currentRange = Range ( datax, old_high_x );
1779  cut2d -> setCutRangeAt ( currentRange, 0 );
1780 
1781  // Handle shift drag
1782  if ( e->state() & Qt::ShiftButton) {
1783  int view_bottom = qtview->toViewY(old_low_y);
1784  int view_left = qtview->toViewX(datax);
1785  int view_right = qtview->toViewX(old_high_x);
1786  int view_top = view_bottom - view_right + view_left;
1787 
1788  // Not effecient to call fillPickedPoint(), but marginToUser()
1789  // is protected.
1790  vector <double> adjusted;
1791  qtview->fillPickedPoint(view_left, view_top, adjusted);
1792  currentRange = Range ( old_low_y, adjusted[2]);
1793  }
1794  else
1795  currentRange = Range ( old_low_y, datay );
1796  cut2d -> setCutRangeAt ( currentRange, 1 );
1797  m_edge = 2;
1798  }
1799 
1800  // Right-bottom
1801  else if ( ( dis_high_x <= 0.1 * (old_high_x - old_low_x)) &&
1802  ( dis_low_y <= 0.1 * (old_high_y - old_low_y)) &&
1803  ( m_edge == 0 ) || ( m_edge == 3 ) ) {
1804  Range currentRange = Range ( old_low_x, datax );
1805  cut2d -> setCutRangeAt ( currentRange, 0 );
1806 
1807  // Handle shift drag.
1808  if ( e->state() & Qt::ShiftButton) {
1809  int view_top = qtview->toViewY(old_high_y);
1810  int view_left = qtview->toViewX(old_low_x);
1811  int view_right = qtview->toViewX(datax);
1812  int view_bottom = view_top + view_right - view_left;
1813 
1814  // Not effecient to call fillPickedPoint(), but marginToUser()
1815  // is protected.
1816  vector <double> adjusted;
1817  qtview->fillPickedPoint(view_right, view_bottom, adjusted);
1818  currentRange = Range ( adjusted[2], old_high_y );
1819  }
1820  else
1821  currentRange = Range ( datay, old_high_y );
1822  cut2d -> setCutRangeAt ( currentRange, 1 );
1823  m_edge = 3;
1824  }
1825 
1826  // Right-top
1827  else if ( ( dis_high_x <= 0.1 * (old_high_x - old_low_x)) &&
1828  ( dis_high_y <= 0.1 * (old_high_y - old_low_y)) &&
1829  ( m_edge == 0) || ( m_edge == 4 ) ) {
1830  Range currentRange = Range ( old_low_x, datax );
1831  cut2d -> setCutRangeAt ( currentRange, 0 );
1832 
1833  // Handle shift drag.
1834  if ( e->state() & Qt::ShiftButton) {
1835  int view_bottom = qtview->toViewY(old_low_y);
1836  int view_left = qtview->toViewX(old_low_x);
1837  int view_right = qtview->toViewX(datax);
1838  int view_top = view_bottom - view_right + view_left;
1839 
1840  // Not effecient to call fillPickedPoint(), but marginToUser()
1841  // is protected.
1842  vector <double> adjusted;
1843  qtview->fillPickedPoint(view_right, view_top, adjusted);
1844  currentRange = Range ( old_low_y, adjusted[2] );
1845  }
1846  else
1847  currentRange = Range ( old_low_y, datay );
1848  cut2d -> setCutRangeAt ( currentRange, 1 );
1849  m_edge = 4;
1850  }
1851 
1852  // Left
1853  else if ( ( dis_low_x <= dis_high_x ) &&
1854  ( dis_low_x <= dis_low_y ) &&
1855  ( dis_low_x <= dis_high_y ) &&
1856  ( m_edge == 0 ) || ( m_edge == 5 ) ) {
1857  Range currentRange = Range ( datax, old_high_x );
1858  cut2d -> setCutRangeAt ( currentRange, 0 );
1859  m_edge = 5;
1860  }
1861 
1862  // Right
1863  else if ( ( dis_high_x <= dis_low_x ) &&
1864  ( dis_high_x <= dis_low_y ) &&
1865  ( dis_high_x <= dis_high_y ) &&
1866  ( m_edge == 0 ) || ( m_edge == 6 ) ) {
1867  Range currentRange = Range ( old_low_x, datax );
1868  cut2d -> setCutRangeAt ( currentRange, 0 );
1869  m_edge = 6;
1870  }
1871 
1872  // Bottom
1873  else if ( ( dis_low_y <= dis_high_x ) &&
1874  ( dis_low_y <= dis_low_x ) &&
1875  ( dis_low_y <= dis_high_y ) &&
1876  ( m_edge == 0 ) || ( m_edge == 7 ) ) {
1877  Range currentRange = Range ( datay, old_high_y );
1878  cut2d -> setCutRangeAt ( currentRange, 1 );
1879  m_edge = 7;
1880  }
1881 
1882  // Top
1883  else
1884  {
1885  Range currentRange = Range ( old_low_y, datay );
1886  cut2d -> setCutRangeAt ( currentRange, 1 );
1887  m_edge = 8;
1888  }
1889  notifyObservers();
1890  }
1891 
1892  break;
1893 
1894 
1895  case 2:
1896  if ( cut1d ) {
1897 
1898  if ( !m_clicked ){
1899  old_pos = datax;
1900  }
1901 
1902  else {
1903  double low, high;
1904 
1905  if ( datax > old_pos ) {
1906  low = old_pos;
1907  high = datax;
1908  }
1909 
1910  else {
1911  low = datax;
1912  high= old_pos;
1913  }
1914 
1915  Range currentRange = Range ( low, high );
1916  cut1d -> setCutRangeAt ( currentRange , 0 );
1917  }
1918  notifyObservers();
1919  }
1920 
1921  // Cut2D plotter.
1922  else if ( cut2d ) {
1923  if ( !m_clicked ){
1924  old_pos_x = datax;
1925  old_pos_y = datay;
1926  }
1927 
1928  else {
1929  double low, high;
1930  if ( datax > old_pos_x ) {
1931  low = old_pos_x;
1932  high = datax;
1933  }
1934  else {
1935  low = datax;
1936  high = old_pos_x;
1937  }
1938  Range currentRange = Range ( low, high );
1939  cut2d -> setCutRangeAt ( currentRange, 0 );
1940 
1941  if ( datay > old_pos_y ) {
1942  low = old_pos_y;
1943  high = datay;
1944  }
1945  else {
1946  low = datay;
1947  high = old_pos_y;
1948  }
1949  currentRange = Range ( low, high );
1950  cut2d -> setCutRangeAt ( currentRange, 1 );
1951  }
1952  notifyObservers();
1953  }
1954 
1955  break;
1956 
1957 
1958  case 3:
1959  if ( cut1d ) {
1960 
1962  Range oldRange = cut1d -> getCutRange ();
1963  double width, low, high;
1964 
1965  // Log X axis.
1966  if ( (controller -> getLog ( plotter, Axes::X )) == true )
1967  {
1968  width = log10(oldRange.high())-log10(oldRange.low());
1969  low = pow ( 10., log10(datax) - ( width/2 ) );
1970  high = pow ( 10., log10(datax) + ( width/2 ) );
1971  }
1972 
1973  // Linear X axis.
1974  else
1975  {
1976  width = oldRange.high() - oldRange.low();
1977  low = datax - width/2;
1978  high = datax + width/2;
1979  }
1980  Range currentRange = Range ( low, high );
1981  cut1d -> setCutRangeAt (currentRange, 0 );
1982  notifyObservers();
1983  }
1984 
1985  // Cut2D plotter.
1986  if ( cut2d ) {
1988  Range oldRangeX = cut2d -> getCutRange ();
1989  Range oldRangeY = cut2d -> getCutRangeY ();
1990  double width_x, width_y, low_x, high_x, low_y, high_y;
1991 
1992  // Log X axis.
1993  if ( (controller -> getLog ( plotter, Axes::X )) == true )
1994  {
1995  width_x = log10(oldRangeX.high())-log10(oldRangeX.low());
1996  low_x = pow ( 10., log10(datax) - ( width_x/2 ) );
1997  high_x = pow ( 10., log10(datax) + ( width_x/2 ) );
1998  }
1999 
2000  // Linear X axis.
2001  else
2002  {
2003  width_x = oldRangeX.high() - oldRangeX.low();
2004  low_x = datax - width_x/2;
2005  high_x = datax + width_x/2;
2006  }
2007 
2008  // Log Y axis.
2009  if ( (controller -> getLog ( plotter, Axes::Y )) == true )
2010  {
2011  width_y = log10(oldRangeY.high())-log10(oldRangeY.low());
2012  low_y = pow ( 10., log10(datay) - ( width_y/2 ) );
2013  high_y = pow ( 10., log10(datay) + ( width_y/2 ) );
2014  }
2015 
2016  // Linear Y axis.
2017  else
2018  {
2019  width_y = oldRangeY.high() - oldRangeY.low();
2020  low_y = datay - width_y/2;
2021  high_y = datay + width_y/2;
2022  }
2023 
2024  Range currentRange = Range ( low_x, high_x );
2025  cut2d -> setCutRangeAt (currentRange, 0 );
2026  currentRange = Range ( low_y, high_y );
2027  cut2d -> setCutRangeAt (currentRange, 1 );
2028  notifyObservers();
2029  }
2030 
2031  break;
2032 
2033  default:
2034  break;
2035  }
2036 
2037 
2038 
2039 
2040  }
2041  }
2042 
2043 
2044  // Left button pressed, do zoom in if in zoom mode.
2045  else{
2046 
2047  if ( isSingleItemSelected () == false )
2048  {
2050  return;
2051  }
2052 
2053 #if QT_VERSION < 0x040000
2054  QCanvasItem * item = selectedItem ();
2055 #else
2056  Q3CanvasItem * item = selectedItem ();
2057 #endif
2058 
2059  if ( item->isActive () ) return;
2060 
2061  QtView * qtview = dynamic_cast < QtView * > ( selectedItem() );
2062 
2063  if (qtview) {
2064  double aspect = qtview->getAspectRatio();
2066  }
2067  else {
2068  QtGroupView * qtgroupview =
2069  dynamic_cast < QtGroupView * > ( selectedItem());
2070  if (qtgroupview) {
2072  }
2073  }
2074 
2075 #if QT_VERSION < 0x040000
2076  QCanvasRectangle * rect
2077  = dynamic_cast <QCanvasRectangle *> ( item );
2078 #else
2079  Q3CanvasRectangle * rect
2080  = dynamic_cast <Q3CanvasRectangle *> ( item );
2081 #endif
2082 
2083  if ( getZoomMode() ){
2084  if ( (e->button() == Qt::LeftButton) ||
2085  ( e->state() & Qt::LeftButton) ) {
2086 
2087  QPoint p = inverseWorldMatrix().map ( e -> pos() );
2088  if ( ( p.x() >= rect->x() ) &&
2089  ( p.x() <= rect->x() + rect->width() ) &&
2090  ( p.y() >= rect->y() ) &&
2091  ( p.y() <= rect->y() + rect->height() ) ) {
2092 
2093 
2094  if (m_drag_rect != 0 ) {
2095  delete m_drag_rect;
2096  }
2097 
2098  QPoint top_left ( std::min ( p.x(), m_zoom_start.x() ),
2099  std::max ( p.y(), m_zoom_start.y() ) );
2100  QPoint bo_right ( std::max ( p.x(), m_zoom_start.x() ),
2101  std::min ( p.y(), m_zoom_start.y() ) );
2102 
2103  // Use square to zoom in
2104  if (e->state() & Qt::ShiftButton) {
2105  if (top_left.y() == m_zoom_start.y()) {
2106  bo_right.setY( top_left.y() - bo_right.x() + top_left.x() );
2107  }
2108 
2109  else { // if (bo_right.y() == m_zoom_start.y()){
2110  top_left.setY( bo_right.y() + bo_right.x() - top_left.x() );
2111  }
2112  }
2113 
2114 #if QT_VERSION < 0x040000
2115  m_drag_rect = new QCanvasRectangle ( QRect( top_left,bo_right ),
2116  canvas ());
2117 #else
2118  m_drag_rect = new Q3CanvasRectangle ( QRect( top_left,bo_right ),
2119  canvas ());
2120 #endif
2121  QColor color ( "black" );
2122  QPen pen ( color, 1, Qt::DotLine );
2123  m_drag_rect->setPen(pen);
2124 
2125  if ( selectedPlotter() == 0 ) {
2126  QString message ( "Can not do range zoom in a group view.\n" );
2127  message += "Please select a single plotter view.";
2128  QMessageBox::information ( this,
2129  s_app_name.c_str(),
2130  message );
2131  return;
2132  }
2133 
2134 
2135  if ( selectedPlotter()->hasAxis(Axes::Z) ){
2136  double z = selectedPlotter()->getRange(Axes::Z,true).high() ;
2137  m_drag_rect -> setZ( z ); // Why setZ? Any thing to do with text plotter?
2138  }
2139  m_drag_rect -> setVisible ( true );
2140  //canvas () -> update ();
2141  }
2142  }
2143  }
2144  }
2145 }
2146 
2147 void
2149 savePlotAsImage ( const PlotterBase * plotter,
2150  const std::string & filename )
2151 {
2152  if ( plotter == 0 ) return;
2153 
2154  string::size_type i = filename.find_last_of ( '.');
2155  if ( i != string::npos ) {
2156  string suffix ( filename.substr ( i + 1 ) );
2157  if ( suffix == "eps" ||
2158  suffix == "EPS" ) {
2159  savePlotAsEps ( plotter, filename );
2160  }
2161  else {
2162  QtView * view = getViewFor ( plotter );
2163  assert ( view != 0 );
2164 
2165  QRect rect = view -> rect ();
2166  saveAreaAsPixmap ( rect, filename );
2167  }
2168  }
2169 }
2170 
2171 void
2173 toLower ( std::string & upper )
2174 {
2175  string::size_type size = upper.size();
2176  for ( string::size_type i = 0; i < size; i++ ) {
2177  upper[i] = std::tolower ( upper[i] );
2178  }
2179 }
2180 
2181 bool
2183 isValidImageFormat ( const std::string & suffix )
2184 {
2185  // Handle gzipped suffix
2186  if (suffix=="gz" || suffix=="GZ") return true;
2187 
2188  if ( s_image_filters.empty () ) createImageFilters ();
2189 
2190  string star ( "*." + suffix );
2191  toLower ( star );
2192 
2193  // following could be 64 bit unsigned int
2194  string::size_type i = s_image_filters.find ( star );
2195 
2196  return i != string::npos;
2197 }
2198 
2199 void
2202 {
2203  QString message ( "Sorry, this installation of " );
2204  message += s_app_name.c_str();
2205  message += " was not\n"
2206  "built with the optional FITS support.";
2207  QMessageBox::information ( const_cast < CanvasView * > ( this ),
2208  s_app_name.c_str(),
2209  message );
2210 }
2211 
2212 void
2214 saveSelectedImages ( const std::string & fn, bool check_existing )
2215 {
2216  string filename = fn;
2217  string::size_type i = filename.find_last_of ( '.' );
2218 
2219  if ( i == string::npos ) { // no suffix given
2220  if ( m_image_dialog != 0 ) {
2222  string filt = s.latin1();
2223  string::size_type ipos = filt.find ( "*." ) + 1;
2224  string::size_type epos = filt.find ( ")" );
2225  string suffix ( filt.substr ( ipos, epos - ipos ) );
2226  filename += suffix;
2227  }
2228  else {
2229  filename += ".jpg";
2230  }
2231  i = filename.find_last_of ( '.' );
2232  }
2233 
2234  string suffix ( filename.substr ( i + 1 ) );
2235  if ( isValidImageFormat ( suffix ) ) {
2236  string base ( filename.substr ( 0, i - 1 ) ); //basename
2237  if ( base.empty () ) filename = "image." + suffix;
2238 
2239  if ( check_existing ) {
2240  QString fn ( filename.c_str() );
2241  bool yes = QFile::exists ( fn );
2242 
2243  if ( yes ) {
2244  yes = existingFileWarning ( filename );
2245  if ( yes == false ) return;
2246  }
2247  }
2248 
2249  setVisibleNonViews ( false );
2250  if ( suffix == "eps" ||
2251  suffix == "EPS" )
2252  {
2253  saveSelectedAsEps ( filename );
2254  }
2255  else if (suffix == "fits" ||
2256  suffix == "FITS" ||
2257  suffix == "gz" ||
2258  suffix == "GZ")
2259  {
2260 #ifdef HAVE_CFITSIO
2261  saveSelectedAsFits ( filename );
2262 #else
2263  showFitsError ();
2264 #endif
2265  }
2266  else
2267  {
2268  setUnselectedVisible ( false );
2269  saveSelectedAsPixmap ( filename );
2270  setUnselectedVisible ( true );
2271  }
2272  setVisibleNonViews ( true );
2273  }
2274  else {
2275  invalidImageFormatError ( filename );
2276  }
2277 }
2278 
2279 void
2281 savePlotAsFits ( const PlotterBase * plotter,
2282  const std::string & filename ) const
2283 {
2284 #ifdef HAVE_CFITSIO
2285  if ( plotter -> isImageConvertable () == false ) {
2286  QString message ( "The contents of this plotter is not\n"
2287  "onvertable to a FITS image." );
2288  QMessageBox::information ( const_cast < CanvasView * > ( this ),
2289  s_app_name.c_str(),
2290  message );
2291  return;
2292  }
2293 
2294  PlotterBase * p = const_cast < PlotterBase * > ( plotter );
2295 
2296  const std::vector <unsigned int> & fitsshape = p->getShape();
2297  const std::vector <double> & fitsdata = p->getZValues();
2298 
2300  ->writeImageToFile ( fitsshape[0], fitsshape[1], fitsdata, filename );
2301 
2302 #else
2303  showFitsError ();
2304 #endif
2305 }
2306 
2307 #ifdef HAVE_CFITSIO
2308 void
2310 saveSelectedAsFits ( const std::string & filename )
2311 {
2312  PlotterBase * plotter = selectedPlotter ();
2313 
2314  if ( !plotter ) {
2315  QString message ( "No plot or more than one plot selected." );
2316  QMessageBox::information ( this,
2317  s_app_name.c_str(),
2318  message );
2319  return;
2320  }
2321 
2322  else {
2323  savePlotAsFits ( plotter, filename );
2324  }
2325 }
2326 #endif
2327 
2328 
2329 void
2331 savePlotAsEps ( const PlotterBase * plotter,
2332  const std::string & filename ) const
2333 {
2334  if ( plotter != 0 ) {
2335  QtView * view = getViewFor ( plotter );
2336  assert ( view != 0 );
2337 
2338  QRect rect = view -> rect ();
2339  EpsView * eps = new EpsView ( filename,
2340  rect.x(), rect.y (),
2341  rect.width(), rect.height() );
2342  const Rect & marg_rect = view -> getMarginRect ();
2343  eps -> setMarginRect ( marg_rect );
2344 
2345  PlotterBase * p = const_cast < PlotterBase * > ( plotter );
2346  eps -> setPlotter ( p );
2347  eps -> setDrawRect ( rect.x(), rect.y(),
2348  rect.width(), rect.height() );
2349  eps -> drawSelf ();
2350  eps -> closeFile ();
2351  delete eps;
2352  }
2353 }
2354 
2355 void
2357 saveSelectedAsEps ( const std::string & filename )
2358 {
2359  QRect rect = getSelectedBounds ();
2360 
2361  EpsView * eps_view
2362  = new EpsView ( filename,
2363  rect.x(), rect.y(), rect.width(), rect.height() );
2364 
2365  const vector < const ViewBase * > & viewList = selectedViews ();
2366 #ifdef ITERATOR_MEMBER_DEFECT
2367  std::
2368 #endif
2369  vector < const ViewBase * > :: const_iterator first = viewList.begin();
2370  while ( first != viewList.end() ) {
2371  const ViewBase * vb = *first++;
2372  const QtView * view = dynamic_cast < const QtView * > ( vb );
2373  PlotterBase * plotter = view->getPlotter ();
2374  QRect rect = view->rect();
2375 
2376  eps_view -> setPlotter ( plotter );
2377  eps_view -> setDrawRect ( rect.x(), rect.y(),
2378  rect.width(), rect.height() );
2379  const Rect & marg_rect = view -> getMarginRect ();
2380  eps_view -> setMarginRect ( marg_rect );
2381 
2382  eps_view -> drawSelf ();
2383  }
2384 
2385  eps_view -> closeFile ();
2386 
2387  delete eps_view;
2388 }
2389 
2392 void
2394 saveAs ( const std::string & filename ) const
2395 {
2396  const vector < const ViewBase * > & view_list = views ();
2397  saveAs ( view_list, filename );
2398 }
2399 
2400 void
2402 saveAs ( const std::vector < PlotterBase * > & plotters,
2403  const std::string & filename )
2404 {
2405  vector < const ViewBase * > views;
2406 
2407  unsigned int size = plotters.size ();
2408  for ( unsigned int i = 0; i < size; i++ ) {
2409  PlotterBase * plotter = plotters [i];
2410  QtView * view = wrapPlotter ( plotter );
2411  views.push_back ( view );
2412  }
2413  saveAs ( views, filename );
2414 }
2415 
2416 void
2418 saveAs ( const std::vector < const ViewBase * > & views,
2419  const std::string & filename )
2420 {
2421  if ( s_xml_controller == 0 ) {
2423  }
2424 
2425  XmlController::Status status
2426  = s_xml_controller->saveToFile ( views, filename );
2427  if ( status != XmlController::Success ) {
2428  return;
2429  }
2430 }
2431 
2435 void
2437 exportTextTuple ( const std::string & data_suffix )
2438 {
2440 
2441  const vector < string > & tuples = controller->getNTupleNames();
2442 
2443  if ( tuples.empty () ) {
2444  QString message ( "There are no NTuples to be exported" );
2445  QMessageBox::information ( this,
2446  s_app_name.c_str(),
2447  message );
2448  return;
2449  }
2450 
2451  QString filename =
2452 #if QT_VERSION < 0x040000
2453  QFileDialog::getSaveFileName ( QString::null, // starting directory
2454  QString::null, // filter
2455  this,
2456  "save file dialog",
2457  "Save data source as ..." ); // caption
2458 #else
2459  Q3FileDialog::getSaveFileName ( QString::null, // starting directory
2460  QString::null, // filter
2461  this,
2462  "save file dialog",
2463  "Save data source as ..." ); // caption
2464 #endif
2465 
2466  if ( filename == QString::null ) return;
2467 
2468  QString suffix ( data_suffix.c_str() );
2469 #if QT_VERSION < 0x030300
2470  QString suffix2 ( suffix );
2471  suffix2.upper ();
2472  if ( filename.endsWith ( suffix ) == false &&
2473  filename.endsWith ( suffix2 ) == false ) {
2474  filename += data_suffix;
2475  }
2476 #else
2477  if ( filename.endsWith ( suffix, false ) == false ) {
2478  filename += data_suffix.c_str();
2479  }
2480 #endif
2481 
2482  const string tuple_name = m_inspector -> getSelectedDataSourceName ();
2483 
2484 #if defined(QT_NO_STL) || QT_VERSION < 0x030100
2485  string tuple_file( filename );
2486 #else
2487  string tuple_file ( filename.latin1() );
2488 #endif
2489 
2490  try {
2492  ->writeNTupleToFile ( tuple_name, tuple_file );
2493  controller -> changeName ( tuple_name, tuple_file );
2494  }
2495  catch ( const std::exception & e ) {
2496  QString message ( "An error occurred in writing file.\n\n" );
2497  message += e.what();
2498  QMessageBox::critical ( this, // parent
2499  QString ( "Write error" ), // caption
2500  message,
2501  QMessageBox::Ok,
2502  QMessageBox::NoButton,
2503  QMessageBox::NoButton );
2504  }
2505 
2506  notifyObservers ();
2507 }
2508 
2509 void
2512 
2514 
2515  std::vector<double> picked;
2516  fillPickedPoint(e, picked);
2517 
2518  QPoint p = inverseWorldMatrix().map(e->pos());
2519 
2520  QtView * qtview(0);
2521 
2522  // For right button, just fill m_mouseData and return...
2523  // Behave differently in different cut modes.
2524  if (e->button() == Qt::RightButton || e->state() == Qt::RightButton) {
2525 
2526 #if QT_VERSION < 0x040000
2527  QCanvasItem * right_item=FigureEditor::getRightItem ();
2528 #else
2529  Q3CanvasItem * right_item=FigureEditor::getRightItem ();
2530 #endif
2531 
2532  if ( right_item == 0 ) {
2533  return;
2534  }
2535 
2536  qtview = dynamic_cast < QtView * > ( right_item );
2537 
2538  // Select a view if a group view is selected.
2539  if ( qtview == 0 )
2540  {
2541  QtGroupView * gv = dynamic_cast <QtGroupView *> (right_item);
2542  const vector <ViewBase * > & views = gv->getViews();
2543  vector < ViewBase * >::const_iterator first = views.begin();
2544  for ( ; first != views.end(); ++first ) {
2545  QtView * v = dynamic_cast < QtView * > ( *first );
2546  if ( ( p.x() >= v->x() ) &&
2547  ( p.x() <= v->x() + v->width() ) &&
2548  ( p.y() >= v->y() ) &&
2549  ( p.y() <= v->y() + v->height() ) ) {
2550  qtview = v;
2551  break;
2552  }
2553  }
2554  if ( qtview == 0 ) return; // click between views
2555  }
2556 
2557 
2558 
2559  fillMouseData(picked);
2560 
2561  // In pick mode, update the pick table.
2562  if ( qtview && ( m_cut_mode == 0 ) ) {
2563 
2564 #if QT_VERSION < 0x040000
2565  QCanvasRectangle * rect
2566  = dynamic_cast <QCanvasRectangle *> ( qtview );
2567 #else
2568  Q3CanvasRectangle * rect
2569  = dynamic_cast <Q3CanvasRectangle *> ( qtview );
2570 #endif
2571 
2572 
2573  if ( ( p.x() >= rect->x() ) &&
2574  ( p.x() <= rect->x() + rect->width() ) &&
2575  ( p.y() >= rect->y() ) &&
2576  ( p.y() <= rect->y() + rect->height() ) ) {
2577 
2578  vector < double > picked2;
2579  qtview -> fillPickedPoint ( p.x(), p.y(), picked2 );
2580  updatePickTable ( qtview, picked2 );
2581  }
2582  }
2583 
2584  // In cut mode 2, up date m_clicked to identify first and second click.
2585  if ( qtview && ( m_cut_mode == 2 ) ) m_clicked=!m_clicked;
2586  if ( qtview && ( m_cut_mode == 1 ) ) m_edge = 0;
2587 
2588  }
2589 
2590  else { // zoom in
2591  qtview = dynamic_cast < QtView * > ( selectedItem() );
2592  if (qtview && !picked.empty() && m_whereClicked != invalid &&
2593  m_drag_rect != 0 ) { // We have a rectangle selected.
2594 
2595  std::vector <double> zoom_top_left;
2596  std::vector <double> zoom_bo_right;
2597 
2598  // Zoom in use the rect instead of the release point.
2599  qtview->fillPickedPoint(m_drag_rect->x(),
2600  m_drag_rect->y(),
2601  zoom_top_left);
2602  qtview->fillPickedPoint(m_drag_rect->x()+m_drag_rect->width(),
2603  m_drag_rect->y()+m_drag_rect->height(),
2604  zoom_bo_right);
2605  setPlotZoom(zoom_top_left, zoom_bo_right);
2606 
2607  delete m_drag_rect; // Erase the rectangle.
2608  m_drag_rect = 0;
2609  canvas()->update();
2610  } else {
2611  m_mouseData.clear();
2612  }
2613  }
2614 
2616 
2617  CanvasWindow * cw = dynamic_cast < CanvasWindow * > ( parentWidget() );
2618  QStatusBar * sb = cw->statusBar();
2619  sb->clear();
2620 
2621  if (qtview) {
2622  qtview->setShowCrossHairs ( false );
2623  qtview->update(0);
2624  }
2625 
2627  notifyObservers ();
2628 }
2629 
2630 bool
2632 fillPickedPoint(QMouseEvent * e, std::vector<double> & picked) {
2633  QPoint p = inverseWorldMatrix().map(e->pos());
2634 
2635 #if QT_VERSION < 0x040000
2637  QCanvasRectangle * rect = dynamic_cast<QCanvasRectangle *>(selItem);
2638 #else
2639  Q3CanvasItem * selItem = FigureEditor::selectedItem();
2640  Q3CanvasRectangle * rect = dynamic_cast<Q3CanvasRectangle *>(selItem);
2641 #endif
2642  if (selItem) {
2643  QtView * qtview = dynamic_cast<QtView *>(selItem);
2644  if (!qtview) return false;
2645  picked.clear();
2646  if ( ( p.x() >= rect->x() ) &&
2647  ( p.x() <= rect->x() + rect->width() ) &&
2648  ( p.y() >= rect->y() ) &&
2649  ( p.y() <= rect->y() + rect->height() ) ) {
2650  qtview -> fillPickedPoint ( p.x(), p.y(), picked );
2651  if (!picked.empty()) {
2652  return true;
2653  }
2654  }
2655  }
2656  return false;
2657 }
2658 
2659 void
2661 fillMouseData(const std::vector<double> & picked) {
2662  if (!picked.empty()) {
2663  m_mouseData.clear();
2664  m_mouseData.reserve(3);
2665  m_mouseData.push_back(picked[1]);
2666  m_mouseData.push_back(picked[2]);
2667  if (picked.size() == 4) {
2668  m_mouseData.push_back(picked[3]);
2669  } else {
2670  m_mouseData.push_back(0);
2671  }
2672  }
2673 }
2674 
2675 void
2677 updatePickTable(QtView * qtview, std::vector<double> & picked) {
2678  if (!picked.empty()){
2679  PickTable * table = 0;
2680  map < const QtView *, PickTable * > ::iterator first
2681  = m_table_map.find ( qtview );
2682  if ( first != m_table_map.end () ) {
2683  table = m_table_map [ qtview ];
2684  }
2685  if ( m_cut_mode == 0 ) {
2686  table -> addItem ( picked );
2687  }
2688  }
2689 }
2690 
2691 /* Note: indexing into the picked vector offset by one because the
2692  first entry is the type. See XyPlotter::fillPickedPointFrom().
2693  */
2694 void
2696 setPlotZoom(const std::vector<double> & start_picked,
2697  const std::vector<double> & picked) {
2698  if (getZoomMode()) {
2699  if ( !(selectedPlotter()->getCurrentRangeSaved()) ) {
2700  setCurrentRange();
2701  }
2702  PlotterBase * plotter = selectedPlotter();
2703  plotter->setRange( "x",
2704  std::min(picked[1], start_picked[1]),
2705  std::max(picked[1], start_picked[1]) );
2706  if (plotter->hasAxis(Axes::Z) || plotter->hasZoomY()) {
2707  plotter->setRange( "y",
2708  std::min(picked[2], start_picked[2]),
2709  std::max(picked[2], start_picked[2]) );
2710  }
2711  plotter -> setCurrentRangeSaved ( false );
2712  }
2713 }
2714 
2715 void
2718 {
2719  if ( ! m_current_range.empty () ){
2720  m_current_range.clear ();
2721  }
2722  PlotterBase * plotter = selectedPlotter ();
2723 
2724  m_current_range.push_back( plotter -> getRange(Axes::X,true).low());
2725  m_current_range.push_back( plotter -> getRange(Axes::X,true).high());
2726  m_current_range.push_back( plotter -> getRange(Axes::Y,true).low());
2727  m_current_range.push_back( plotter -> getRange(Axes::Y,true).high());
2728 
2729  int i = plotter -> currentView();
2730  plotter -> saveViewAtIndex( m_current_range , i + 1 );
2731  plotter -> setCurrentRangeSaved( true );
2732 }
2733 
2734 std::vector<double>&
2737 {
2738  return m_current_range;
2739 }
2740 
2741 void
2744 {
2745  m_inspector -> show ();
2746 }
2747 
2748 void
2751 {
2752 // if ( !isSingleItemSelected() ) return;
2753  if ( isSingleItemSelected () == false ) {
2754  QString message ( "One must select a single plot before showing\n"
2755  "the pick table." );
2756  QMessageBox::information ( this,
2757  s_app_name.c_str(),
2758  message );
2759  return;
2760  }
2761 
2762 #if QT_VERSION < 0x040000
2763  QCanvasItem * selItem = selectedItem();
2764 #else
2765  Q3CanvasItem * selItem = selectedItem();
2766 #endif
2767  QtView * qtview = dynamic_cast < QtView * > ( selItem );
2768  if ( qtview == 0 ) {
2769  QString message ( "Can not show pick table of a group view.\n" );
2770  message += "Please select a single plotter view.";
2771  QMessageBox::information ( this,
2772  s_app_name.c_str(),
2773  message );
2774  return;
2775  }
2776  map < const QtView *, PickTable * > ::iterator first
2777  = m_table_map.find ( qtview );
2778 
2779  if ( first == m_table_map.end() ) {
2780  PlotterBase * plotter = qtview->getPlotter ();
2781 
2782  PickTable * table = new PickTable ( plotter );
2783  m_table_map [ qtview ] = table;
2784  table->show();
2785  }
2786  else {
2787  // Show existing pick table.
2788  m_table_map[qtview]->show();
2789  }
2790 }
2791 
2792 
2793 
2794 const std::vector<double> &
2797 {
2798 #if QT_VERSION < 0x040000
2799  ::mouseEvent.wait();
2800 #else
2801  // need to learn about equivalent
2802  // ::mouseEvent.wait( mutex, time );
2803 #endif
2804  return m_mouseData;
2805 }
2806 
2807 void
2809 {
2810  const std::string & version = WindowController::version ();
2811  std::string about = "<h2>HippoDraw version: ";
2812  about += version;
2813  about += "<h3> Built on ";
2814  about += "<ul>";
2815  about += "<li> Qt ";
2816  about += QT_VERSION_STR;
2817 #ifdef HAVE_CFITSIO
2818  about += "<li> CFITSIO ";
2819  const string & fits_version = FitsController::instance () -> version ();
2820  about += fits_version.c_str();
2821 #endif
2822 
2823 #ifdef HAVE_MINUIT
2824  about += "<li> C++ Minuit";
2825 #endif
2826 
2827 #ifdef HAVE_MINUIT2
2828  about += "<li> Minuit2";
2829 #endif
2830 
2831 #ifdef HAVE_ROOT
2832  about += "<li> ROOT ";
2833  const string & root_version = RootController::instance() -> version ();
2834  about += root_version.c_str();
2835 #endif
2836 
2837 #ifdef HAVE_WCSLIB
2838  about += "<li> WCSlib ";
2839  about += "4.x";
2840 #endif
2841  about += "</ul>";
2842 
2843  about += "<h3>Contributors...";
2844  about += "<ul>";
2845  about += "<li> Stephane Bonneaud";
2846  about += "<li> James Chiang";
2847  about += "<li> Johann Cohen-Tanugi";
2848  about += "<li> Xie Fang";
2849  about += "<li> Kaustuv";
2850  about += "<li> Paul F. Kunz";
2851  about += "<li> Sanket B. Malde";
2852  about += "<li> Matthew D. Langston";
2853  about += "<li> Joy Rajiv";
2854  about += "<li> Matan Shacham";
2855  about += "<li> Oded Wurman";
2856  about += "</ul>";
2857 
2858  static QMessageBox* mbox
2859  = new QMessageBox ( "HippoDraw",
2860  about.c_str(),
2861  QMessageBox::Information, 1, 0, 0, this, 0, false );
2862  mbox->setButtonText ( 1, "OK" );
2863 
2864  mbox -> exec (); // run modal
2865 }
2866 
2867 const std::string &
2870 {
2871  return s_app_name;
2872 }
2873 
2874 
2875 PlotterBase *
2878 {
2879 
2880 #if QT_VERSION < 0x040000
2881  QCanvasItem * right_item=FigureEditor::getRightItem ();
2882 #else
2883  Q3CanvasItem * right_item=FigureEditor::getRightItem ();
2884 #endif
2885 
2886  QtView * view = dynamic_cast <QtView *> (right_item);
2887 
2888  if ( view == 0 ) return 0;
2889  PlotterBase * plotter = view -> getPlotter ();
2890  return plotter;
2891 }
2892 
2893 void
2895 setCutMode ( int mode )
2896 {
2897  m_cut_mode=mode;
2898 }
2899 
2900 void
2903 {
2905 
2906  const vector < string > & tuples = controller->getNTupleNames();
2907 
2908  if ( tuples.empty () ) {
2909  QString message ( "There are no NTuples to be used as source" );
2910  QMessageBox::information ( this,
2911  s_app_name.c_str(),
2912  message );
2913  return;
2914  }
2915 
2916  CreateNTuple * cnt = new CreateNTuple ();
2917  cnt-> show ();
2918 }
2919 
2920 NTuple *
2923 {
2924 
2925  const ViewBase * selview;
2926  if (m_sel_views.size()==1) selview = m_sel_views[0];
2927  else return NULL;
2928 
2929  const QtView * view = dynamic_cast < const QtView * > ( selview );
2930 
2931  PickTable * table=0;
2932  map < const QtView *, PickTable * > ::iterator first
2933  = m_table_map.find ( view );
2934  if ( first != m_table_map.end () ) {
2935  table = m_table_map [ view ];
2936  }
2937  if ( table ) {
2938  return table->getPickTable();
2939  }
2940 
2941  return NULL;
2942 
2943 }
2944 
2945 NTuple *
2947 getPickTable ( const PlotterBase * plotter )
2948 {
2949 
2950  const QtView * view = getViewFor ( plotter );
2951 
2952  PickTable * table = 0;
2953  map < const QtView *, PickTable * > :: iterator first
2954  = m_table_map.find (view);
2955  if ( first !=m_table_map.end() ) {
2956  table = m_table_map [view];
2957  }
2958  if ( table ) {
2959  return table->getPickTable();
2960  }
2961 
2962  return NULL;
2963 }
2964 
2965 void
2968 {
2969  const vector < const ViewBase * > & selViews = selectedViews();
2970  if ( selViews.empty () ) return;
2971 
2972  QRect groupRect = QRect(0,0,0,0);
2973 
2974  QtGroupView * groupView = new QtGroupView ();
2975 
2976  vector < const ViewBase * >::const_iterator it = selViews.begin();
2977  for ( ; it != selViews.end(); ++it ) {
2978  ViewBase * view = const_cast < ViewBase * > ( *it );
2979 
2980  QtView * qtview = dynamic_cast < QtView * > ( view );
2981  if (!qtview) continue; // don't include groupview in groupview
2982 
2983  groupView->addView (view);
2984  removeFromItemList (qtview);
2985  QRect temp = qtview->boundingRect();
2986  groupRect|=temp; // get a rect to contain all QtViews
2987  }
2988 
2989  groupView->setDrawRect(groupRect);
2990  groupView->setPositions(); // set relative position
2991  add(groupView);
2993  addSelectedItem ( groupView );
2994 }
2995 
2996 void
2999 {
3000  const vector < const ViewBase * > & selViews = selectedViews();
3001  if ( selViews.size() != 1 ) return;
3002 
3003  const QtGroupView * groupView =
3004  dynamic_cast < const QtGroupView * > ( selViews[0] );
3005  if (!groupView) return;
3006 
3007  QtGroupView * gv = const_cast < QtGroupView * > ( groupView );
3008  clearSelectedList ();
3009  const vector < ViewBase * > & views = gv->getViews();
3010 
3011  vector < ViewBase * >::const_iterator first = views.begin();
3012  for ( ; first != views.end(); ++first ) {
3013  QtView * qtview = dynamic_cast < QtView * > ( *first );
3014  add (qtview);
3015  gv->removeView(*first);
3016  --first; // a view is removed, decrease the iterator
3017  addSelectedItem (qtview );
3018  }
3019  remove ( gv );
3020 }
3021 
3023 {
3024  const vector < const ViewBase * > & views = selectedViews ();
3025 #ifdef ITERATOR_MEMBER_DEFECT
3026  std::
3027 #endif
3028  vector < const ViewBase * > ::const_iterator first = views.begin();
3029  while ( first != views.end() ) {
3030  const QtView * view = dynamic_cast < const QtView * > ( *first++ );
3031  QtView * v = const_cast < QtView * > ( view );
3032  hide(v);
3033  }
3034 }
3035 
3036 void
3038 addRecentFile (const QString & filename, QActionGroup * ag )
3039 {
3040  #if QT_VERSION < 0x040000
3041 #else
3042  QObject * parent = ag -> parent ();
3043 #endif
3044 
3045  // Avoid duplicate recently opened files.
3046  // Remove old item with same name if needed.
3047  std::list<QAction *>::iterator it=m_recent_list.begin();
3048 
3049  for (; it!=m_recent_list.end(); ++it){
3050  if (((*it)->menuText())==filename){
3051  delete *it; // need removeFrom(ag) ?
3052  it=m_recent_list.erase(it);
3053  break;
3054  }
3055  }
3056 
3057  // Add new item.
3058 #if QT_VERSION < 0x040000
3059  QAction * action = new QAction ( "", // text
3060  QIconSet(),
3061  filename, // menu test
3062  0, // accel
3063  ag ); // parent
3064 #else
3065  QAction * action = new QAction ( filename, parent );
3066  ag -> addAction ( action );
3067 #endif
3068  action -> setToggleAction ( true );
3069  m_recent_list.push_back(action);
3070 
3071  // Remove the first element if size is more than 5.
3072  if (m_recent_list.size() > 5) {
3073  it=m_recent_list.begin();
3074  delete *it; //need removeFrom(ag) ?
3075  m_recent_list.pop_front();
3076  }
3077 }
3078 
3079 void
3080 CanvasView::
3081 #if QT_VERSION < 0x040000
3083 #else
3084 autosaveSettings (Q3MainWindow * mw)
3085 #endif
3086 {
3087  QSettings settings;
3088  settings.insertSearchPath ( QSettings::Windows, s_registry );
3090  list<QAction *>::iterator it;
3091  unsigned int i=0;
3092 
3093 
3094  // Save recently opened files
3095  for ( it=m_recent_list.begin();
3096  it!=m_recent_list.end(); i++, it++ )
3097  {
3098  fn = (*it)->menuText();
3099  QString number=QString::number(i);
3100  settings.writeEntry ( s_app_key + "Files/File"+number, fn );
3101  }
3102 
3103  // Save dock window positions.
3105  QTextStream stream( &dockSetting, IO_WriteOnly );
3106  stream << *mw;
3107  settings.writeEntry(s_app_key+"DockWindow/Position", dockSetting);
3108 }
3109 
3110 void
3113 {
3114  moveDockWindow(toolBar);
3115  moveDockWindow(Toolbar_2);
3116  moveDockWindow(Toolbar);
3117  moveDockWindow(Toolbar_4);
3118 
3119  lineUpDockWindows();
3120 }
m_canvas_view ensureVisible(vv)
int m_edge
For cut mode 1, edge or corner selected.
Definition: CanvasView.h:183
setFilters(const QString &filters)
void notifyObservers()
Notifies observers of a change in CanvasView.
Definition: CanvasView.cxx:631
virtual void contentsMouseMoveEvent(QMouseEvent *)
Overrides the QScrollView event handler.
std::vector< double > & getCurrentRange()
Returns the current range of the selected plotter.
This class manages the Create NTuple dialog.
Definition: CreateNTuple.h:33
const std::vector< const ViewBase * > & selectedViews() const
Returns temporary list of selected QtView objects on the canvas.
unsigned int i
int m_apage_h
The actual Page height in Postscript points.
Definition: FigureEditor.h:130
static XmlController * s_xml_controller
The XML controller.
Definition: CanvasView.h:116
void placeGraph(QCanvasRectangle *)
Moves the QCanvasRectangle object to place on the canvas where it will not collide with existing QCan...
std::pair< double, double > moveToPlotterAt(const PlotterBase *plotter, QtView *view, double x, double y)
Moves the view to the specified position with respect to the currently view for plotter.
hippodraw::CanvasWindow class interface.
virtual const Range & getRange(Axes::Type axis, bool scaled) const
Returns the range on the specified axis.
Definition: XyPlotter.cxx:768
QtViewFactory class interface.
static FitsController * instance()
Returns the singleton instance of the FitsController.
void saveSettings() const
Saves the settings for use in future session.
Definition: CanvasView.cxx:294
void setup()
Raises the settings dialog.
Definition: CanvasView.cxx:736
void deleteSelected(bool paste)
Removes the selected items from canvas and copies them to the pasteboard.
Definition: CanvasView.cxx:530
QCanvas * m_canvas
The canvas object.
Definition: FigureEditor.h:283
A singleton class that is the interface between GUI and the displays.
double high() const
Returns the maximum of the range object.
Definition: Range.cxx:100
void addPlotDisplay(PlotterBase *plotter, bool select)
Creates a QtView object for the display and inserts it onto the canvas in the next available free pla...
Definition: CanvasView.cxx:837
std::vector< PlotterBase * > getSelectedPlotters() const
Returns a list of selected plotters.
Definition: CanvasView.cxx:647
void autosaveSettings(QMainWindow *mw)
Save the recently opened file list.
void clear()
Removes all items from canvas and destroy them.
A Plotter class that plots one-dimensional TupleCut values.
Definition: Cut2DPlotter.h:40
QListViewItem * item
Definition: PickTable.cxx:172
void setFonts(const QFont &font)
Sets the fonts for the views.
Definition: CanvasView.cxx:788
void setCollidingSelected(const QCanvasItem *target)
Sets all QCanvasItems that collide with target to selected state.
hippodraw::RootController class interface.
std::vector< QCanvasItem * > & getSelectedItems()
Return the vector of selected items.
A singleton class for keeping track the window components of HippoDraw.
right() const
void showInspector()
Show the Inspector window.
void add(QCanvasItem *item)
Adds the item to the canvas.
std::map< const QtView *, PickTable * > m_table_map
A map from a view to the PickTable.
Definition: CanvasView.h:113
std::vector< const ViewBase * > m_sel_views
Temporary list of selected QtView objects on the canvas.
Definition: CanvasView.h:110
void initFitterMenu(QActionGroup *group)
Initializes the fitter setting menu items.
Definition: CanvasView.cxx:262
virtual const std::vector< double > & getZValues()
Returns all Z values.
void saveSelectedAsFits(const std::string &filename)
Saves the selected objects as FITS image file filename.
QFileDialog * createImageDialog()
Creates the QFileDialog with supported filters string for supported image types.
int writeNTupleToFile(DataSource *source, const std::string &filename)
Writes the DataSource source to a file given by filename.
exists() const
std::list< QAction * > m_recent_list
List of menu items of recently opened files.
Definition: CanvasView.h:104
void initFrom(const std::list< ViewBase * > &views)
Definition: CanvasView.cxx:324
This class implements additional FigureEditor functionality particular to QtView objects.
Definition: CanvasView.h:96
statusBar() const
PlotterBase * selectedPlotter() const
Returns the selected PlotterBase object.
Definition: CanvasView.cxx:675
arg(long a, int fieldWidth=0, int base=10) const
lower() const
virtual void print()
Prints the view to the printer.
void createNTuple()
Raise the create NTuple dialog.
void setFitterDefault(const std::string &name)
Sets the default fitter in the FitterFactory.
Definition: CanvasView.cxx:246
QRect frect
Definition: CanvasView.cxx:866
void initFitterSettings(QActionGroup *group)
Initializes the fitter settings menu items.
Definition: CanvasView.cxx:254
hippodraw::WindowController class interface
static FunctionController * instance()
Returns the pointer to the singleton instance.
void setCrossY(double val)
Set the crossY value.
Definition: QtViewImp.cxx:1006
void setUnselectedVisible(bool yes)
Sets the unselected items to visible or not.
void initFitterDefault()
Sets the default fitter.
Definition: CanvasView.cxx:212
void writeImageToFile(unsigned int x, unsigned int y, const std::vector< double > &data, const std::string &filename)
Write a image to a FITS image.
virtual void print()
Prints the canvas.
virtual void update(const Observable *)
Responds to Observable update message.
Definition: QtView.cxx:170
void initSettings()
Initialize the settings save from previous session.
Definition: CanvasView.cxx:138
static QtView * wrapPlotter(PlotterBase *plotter)
Wraps the plotter with a new QtView object.
Definition: CanvasView.cxx:827
virtual double getAspectRatio() const
Get the aspect ratio.
Definition: ViewBase.cxx:88
static QString s_registry
The QSettings Windows registry key.
Definition: FigureEditor.h:277
height() const
std::pair< double, double > addTextDisplayAt(PlotterBase *plotter, const std::string &type, const std::string &text, double xrel, double yrel)
Adds a text display at the relative position (xrel, yrel) in the selected item&#39;s coordinates.
x() const
y() const
void setSelectedFlags()
Set the selected flags.
NTuple * getPickTable()
Gets the pick table of selected plotter.
int m_num_height
Number of default sized plots vertically.
Definition: CanvasView.h:168
QRect srect
Definition: CanvasView.cxx:867
hippodraw::FunctionController class interface
Accept new setting and retile.
static QString s_app_key
The QSettings application key for searching for setting.
Definition: FigureEditor.h:272
A singleton class is the interface between an application and the list of FunctionRep objects contain...
void savePlotAsImage(const PlotterBase *plotter, const std::string &filename)
Saves the plotter as image file filename.
virtual const std::vector< unsigned int > & getShape()
void swapOrientation()
Swaps the canvas&#39; orientation from portrait to landscape or visa verse.
Definition: CanvasView.cxx:715
hippodraw::Cut2DPlotter class interface
void setSelectedItem(QCanvasItem *)
Set the selected QCanvasItem.
insertSearchPath(System s, const QString &path)
information(QWidget *parent, const QString &caption, const QString &text, int button0, int button1=0, int button2=0)
void restoreFromSelectCopy()
Restores the selected views from the selection copy.
readEntry(const QString &key, const QString &def=QString::null, bool *ok=0) const
void paste(QCanvasItem *item)
Adds the item to the canvas.
void hide(QCanvasItem *item)
Removes the item from the canvas but not destroys it.
std::vector< double > m_mouseData
3-vector of mouse event data
Definition: CanvasView.h:148
x() const
y() const
QCanvasItem * getRightItem()
Get the QCanvasItem clicked by right mouse button.
QString dockSetting
Definition: CanvasView.cxx:164
void addRecentFile(const QString &filename, QActionGroup *ag)
Add recently opened files.
hippodraw::CanvasView class interface
std::vector< const ViewBase * > m_views
Temporary list of QtView objects on the canvas.
Definition: CanvasView.h:107
A derived class of QCustomEvent with which the CanvasView notifiies clients of changes in selections ...
virtual void setShowCrossHairs(bool flag)
Sets display status of cross-hairs.
Definition: QtView.cxx:106
virtual bool hasZoomY() const
Returns true if the plotter has zoom feature on the Y axis, otherwise returns false.
QString fn
virtual void calcDefaultSize(QtView *view, double aspect_ratio=0.0)
Sets the default size and position for the view.
Definition: CanvasView.cxx:804
const std::list< ViewBase * > & getFromPasteboard(ViewFactory *factory, const std::vector< const ViewBase * > &views)
Creates and returns a list of objects that was copied to the pasteboard.
static std::string s_image_filters
A QFileDialog filters string for supported image types.
Definition: CanvasView.h:126
number(long n, int base=10)
postEvent(QObject *receiver, QEvent *event)
latin1() const
setButtonText(int button, const QString &text)
outputFormatList()
virtual void contentsMouseReleaseEvent(QMouseEvent *)
Overrides inherited method to receive mouse released events.
static QPrinter * s_printer
The single QPrinter instance.
Definition: FigureEditor.h:143
void reTilePage()
Re-tiles the current page.
Definition: CanvasView.cxx:969
virtual Range getCutRange()
Gets the object of current XyPlotter is a TupleCut object, get the range of it.
Definition: XyPlotter.cxx:954
void setIntervalEnabled(bool yes=true)
Sets the display interval feature of all views to enabled if yes is true, otherwise sets the feature ...
void removeFromItemList(QCanvasItem *item)
Removes the item from list of items on the canvas.
const std::list< ViewBase * > & getFromSelectionCopy(ViewFactory *factory, const std::vector< const ViewBase * > &views)
Creates and returns objects that were copied to the selection copy.
bool m_add_selected
Set to true if displays should be selected when added.
Definition: CanvasView.h:172
void fillMouseData(const std::vector< double > &picked)
Fill m_mouseData with the data from fillPickedPoint.
Inspector * getInspector()
Gets the inspector object.
Definition: CanvasView.cxx:617
double old_pos
For cut mode 2, position of first click.
Definition: CanvasView.h:191
NTuple * getPickTable() const
Gets the pick table as a NTuple.
Definition: PickTable.cxx:246
void savePlotAsFits(const PlotterBase *plotter, const std::string &filename) const
Saves the plotter as an FITS image file.
return yes
Definition: CanvasView.cxx:883
top() const
void initRecentFiles(QActionGroup *ag)
Initializes the recently opened files menu items.
Definition: CanvasView.cxx:174
hippodraw::EpsView class interface
static const std::string s_app_name
The application name.
Definition: CanvasView.h:123
setCanvas(QCanvas *c)
void mouseMoveMultiItem(QMouseEvent *e)
Move more than one items in the Canvas.
virtual void controlMousePressEvent()
Overrides inherited method to receive mouse pressed events.
The base class for the PlotterBase hierarchy.
Definition: PlotterBase.h:55
static const std::string & version()
Returns the version number of HippoDraw.
hippodraw::CreateNTuple class interface
hippodraw::Inspector class interface.
const char * version()
Definition: version.cxx:18
left() const
button() const
PlotterBase * getPlotter() const
Returns the plotter used by this view.
Definition: ViewBase.cxx:50
Status saveToFile(const std::vector< const ViewBase * > &views, const std::string &filename)
Saves the document represented by list of ViewBase objects to file with name filename.
virtual void contentsMousePressEvent(QMouseEvent *)
void hideSelected()
Removes the selected objects from the canvas without destroying in.
const std::vector< const ViewBase * > & views() const
Returns temporary list of all QtView objects on the canvas.
int m_cut_mode
Cut mode: 1: normal; 2: click; 3: drag.
Definition: CanvasView.h:176
hippodraw::CanvasSettings class interface
std::vector< QCanvasItem * > m_selected_list
The list of currently selected QCanvasItem objects.
Definition: FigureEditor.h:290
bool ok
Definition: CanvasView.cxx:163
bool m_ignore_margin
a flag set to true if the printer margins should be ignored when adding a plot to the canvas...
Definition: FigureEditor.h:153
PyArray_TYPES type(numeric::array arr)
Definition: num_util.cpp:249
void reTile()
Re-tiles the canvas.
Definition: CanvasView.cxx:888
static ViewFactory * instance()
bool m_printer_bounds
A flag to indicate if rectangle display usable printer boundary should be displayed or not...
Definition: FigureEditor.h:148
CanvasSelectionEvent class interface.
virtual TransformBase * getFitsTransform() const
Returns the fits transform object.
setOverrideCursor(const QCursor &cursor, bool replace=FALSE)
ViewBase * createFuncView(const ViewFactory *factory, PlotterBase *plotter, const std::string &type)
Creates a textual view of function of type type.
virtual void contentsMousePressEvent(QMouseEvent *)
void clearSelectedList()
De-selects all items, making the selection list empty.
This class manages the CanvasView settings dialog.
static WindowController * instance()
Returns the application instance.
wait(unsigned long time=ULONG_MAX)
void addFromPasteboard()
Adds from pasteboard.
Definition: CanvasView.cxx:512
stream * mw
Definition: CanvasView.cxx:169
static void createImageFilters()
Creates the image filters string.
endsWith(const QString &s, bool cs=TRUE) const
hippodraw::BinaryTransform class interface
void enableNewPlotBox(bool yes=true)
Enables the new plot box.
Definition: Inspector.cxx:346
void saveAs(const std::string &filename) const
Saves all the QtView canvas item to a XML file.
Status openFile(const std::string &filename)
Attempts to open and parse the specified HippoDraw document.
hippodraw::FitsController class interface.
void showPrinterMargins(bool on)
Sets showing the printer margins on or off.
void setVisibleNonViews(bool visible)
Sets visible state of QCanvasItem objects that are not also QtView objects to visible.
bool existingFileWarning(const std::string &filename)
Raises dialog to query over writing existing file.
Definition: CanvasView.cxx:464
void pasteViews(const std::list< ViewBase * > &views)
Adds the views to the canvas.
Definition: CanvasView.cxx:598
selectedFilter() const
void fillSelectedWithObservers(std::vector< const ViewBase * > &)
Fills the input vector with selected items and their observers.
void saveToSelectionCopy(const std::vector< const ViewBase * > &views)
Saves the document represented by the list of ViewBase objects to the selection copy.
ViewBase * v
Definition: PlotTable.cxx:104
QtView * getViewFor(const PlotterBase *plotter) const
Returns the QtView object that is the Observer of the plotter.
intp size(numeric::array arr)
Definition: num_util.cpp:296
void setPositions()
Set the positions in percentage of every views.
canvas() const
virtual Status openUpdatedNTuples()
Open the missing tuples updated by GUI.
void addTextDisplay(PlotterBase *plotter, const std::string &s, const std::string &text=std::string())
Add a display of text Adds a display of text to that will be associated with plotter.
void copySelectedToPasteboard()
Copies selected items to pasteboard.
Definition: CanvasView.cxx:486
static Type types[]
An array to allow conversion of integer to enumeration.
Definition: AxesType.cxx:30
void ungroupView()
Ungroup the GroupView object to separated Views.
A derived class of QCustomEvent to handle updates from PlotterBase.
Definition: PlotterEvent.h:39
static bool isValidImageFormat(const std::string &suffix)
Returns true if suffix string is one for valid image format.
writeEntry(const QString &key, bool value)
void savePlotAsEps(const PlotterBase *plotter, const std::string &filename) const
Saves the plotter as an EPS image file.
static void toLower(std::string &upper)
Converts the string to lower case.
bool m_clicked
For cut mode 2, clicked or not.
Definition: CanvasView.h:187
int m_num_width
Number of default sized plots horizontally.
Definition: CanvasView.h:164
Status
Return codes of opening file.
Definition: XmlController.h:59
std::vector< QCanvasItem * > m_items
The list of view items on the canvas.
Definition: FigureEditor.h:238
void moveToPlotter(const PlotterBase *plotter, QtView *view)
Moves the view to a nice position with respect to the plotter&#39;s QCanvasItem.
Class representing a rectangle.
Definition: Rectangle.h:34
bool isSingleItemSelected() const
Returns true if just one item is selected, else returns false.
The class of derived from ViewBase and QCanvasRectangle for drawing on a QCanvas. ...
Definition: QtView.h:41
void saveSelectedAsEps(const std::string &filename)
Saves the selected objects as EPS image file filename.
A singleton class that is the interface between GUI and the DataSource objects.
hippodraw::PickTable class interface
readNumEntry(const QString &key, int def=0, bool *ok=0) const
static DisplayController * instance()
Returns the pointer to the singleton instance.
void setCutMode(int mode)
int m_upage_w
The usable Page width in Postscript points.
Definition: FigureEditor.h:222
static NTupleController * instance()
Returns the pointer to the singleton instance.
A Plotter class that plots one-dimensional TupleCut values.
Definition: Cut1DPlotter.h:34
const std::string & applicationName() const
Returns the name of the application.
The abstract base class for a factory that creates objects closely related to the graphics subsystem ...
Definition: ViewFactory.h:35
A DataSource class implemented with std::vector&lt;double&gt; to store the column data. ...
Definition: NTuple.h:33
hippodraw::PlotterEvent class interface
void ensureVisible(const QCanvasItem *item)
Scrolls the canvas, if needed, so the QCanvasItem item is visible.
QCanvasRectangle * m_drag_rect
Rectangle showing the area which is to be magnified.
Definition: CanvasView.h:131
The abstract base class for views.
Definition: ViewBase.h:62
width() const
virtual PlotterBase * getParentPlotter() const
Returns the parent plotter.
void addFuncDisplay(PlotterBase *plotter, const std::string &s)
Add a text display which displays functions parameters.
void setCrossX(double val)
Set the crossX value.
Definition: QtViewImp.cxx:1001
void saveSelectedImages()
Saves the selected QCanvasItem objects to a image file.
hippodraw::QtGroupView class interface
void saveToPasteboard(const std::vector< const ViewBase * > &)
Saves the document represented by the list of ViewBase objects to the pasteboard. ...
QPoint m_zoom_start
The starting point of a mouse drag.for zoom.
Definition: FigureEditor.h:299
void contentsMouseMoveEvent(QMouseEvent *, double aspect)
Moves or re-sizes the selected QCanvasItem object.
void initFromFile(const std::string &filename)
Initializes canvas from data in file filename.
Definition: CanvasView.cxx:345
std::vector< double > m_current_range
Set to the current range of the selected plotter.
Definition: CanvasView.h:196
void sizeAndPlace(QtView *view)
Calculates the default size and position on the canvas.
Definition: CanvasView.cxx:849
virtual void setRange(Axes::Type axis, const Range &range, bool scaled=false, bool adjust_width=true)
Sets the range on the specified axis.
virtual void fillPickedPoint(double x, double y, std::vector< double > &picked) const
Fills the picked point vector.
Definition: QtView.cxx:245
int toViewY(double datY) const
Converts the data space coordinate Y to the view space coordinate Y.
Definition: QtView.cxx:238
void addView(ViewBase *inView)
Add a view to the group.
int m_upage_h
The usable Page height in Postscript points.
Definition: FigureEditor.h:225
state() const
QCanvasItem * selectedItem() const
Returns the selected QCanvasItem.
A transform that transforms coordinates from one 2D coordinate system to another. ...
virtual void defaultToolbar()
Set the toolbar to default position.
void contentsMouseReleaseEvent(QMouseEvent *)
Handles details of mouse release, right button.
getSaveFileName(const QString &startWith=QString::null, const QString &filter=QString::null, QWidget *parent=0, const char *name=0, const QString &caption=QString::null, QString *selectedFilter=0, bool resolveSymlinks=TRUE)
critical(QWidget *parent, const QString &caption, const QString &text, int button0, int button1, int button2=0)
bottom() const
double low() const
Returns the minimum of the range object.
Definition: Range.cxx:87
static RootController * instance()
Returns the singleton instance of the RootController.
The class of derived from GroupViewBase, QtViewImp and QCanvasRectangle for drawing a grouped view on...
Definition: QtGroupView.h:45
setY(int y)
bool getZoomMode() const
Returns the bool indicating whether zoom mode is enabled or not.
void setAddedSelected(bool yes)
Sets to flag to make plot in its selected state when added to the canvas.
Definition: CanvasView.cxx:319
void setPlotMatrix(unsigned int columns, unsigned int rows)
Sets the number of columns and rows of plots displayed on each page.
Definition: CanvasView.cxx:707
void saveAreaAsPixmap(const QRect &area, const std::string &filename)
Saves the area area as pixmap to file filename.
virtual void getViews()
De-serializes the ViewBase objects.
virtual bool hasAxis(Axes::Type axis) const
Returns true if the plotter has an axis of specified type.
void saveSelectedAsPixmap(const std::string &filename)
Save the selected objects as Pixmap image file filename.
warning(QWidget *parent, const QString &caption, const QString &text, int button0, int button1, int button2=0)
Expresses a range of values.
Definition: Range.h:33
Location m_whereClicked
Location where the mouse cursor clicked the object.
Definition: FigureEditor.h:315
virtual const Range & getRange(Axes::Type axis, bool scaled) const
Returns the range on the specified axis.
hippodraw::NTupleController class interface
pos() const
Cut1DPlotter class interface.
getOpenFileName(const QString &startWith=QString::null, const QString &filter=QString::null, QWidget *parent=0, const char *name=0, const QString &caption=QString::null, QString *selectedFilter=0, bool resolveSymlinks=TRUE)
void clear()
Removes all the QCanvasItem objects from the canvas.
Definition: CanvasView.cxx:570
ScatterPlot class interface.
void setCurrentRange()
Saves the current range of the selected plotter.
void groupView()
Create a GroupView object containing selected views.
void addView(QtView *view, bool select)
Adds a QtView object to the CanvasView.
Definition: CanvasView.cxx:692
void copyFromPasteboard()
Copies from the pasteboard.
Definition: CanvasView.cxx:500
PlotterBase * getRightClickedPlotter()
void placeItems(const std::vector< QCanvasItem * > &items)
Places each item in items on the canvas.
Definition: CanvasView.cxx:927
void removeTextObservers(const std::vector< const ViewBase * > &views)
Removes TextRep Observer objects, if any, from its target.
Inspector * m_inspector
The Inspector object.
Definition: CanvasView.h:119
readBoolEntry(const QString &key, bool def=FALSE, bool *ok=0) const
A derived class of PickTableBase class which is generated by the Qt designer.
Definition: PickTable.h:46
void removeView(ViewBase *inView)
Remove a view in the group.
QFileDialog * m_image_dialog
The QFileDialog for saving images.
Definition: CanvasView.h:142
DataSourceController class interface.
const std::vector< double > & mouseEventData()
Retrieve a vector of (x, y, z) points from the next mouse event.
const std::vector< ViewBase * > & getViews()
Get all views in this group.
void viewShowPickTable()
Show the pick table.
double maximumZ() const
Returns the largest Z value of all the items on the canvas.
void setInspector(Inspector *inspector)
Sets the Inspector object.
Definition: CanvasView.cxx:611
A base class that is the interface between GUI and the XML serialization and deserialization.
Definition: XmlController.h:53
void exportTextTuple(const std::string &suffix)
Saves the DataSource as a text NTuple.
int toViewX(double datX) const
Converts the data space coordinate X to the view space coordinate X.
Definition: QtView.cxx:230
void copySelectedToClipboard()
Adds selected items to system clipboard.
void helpAbout()
Brings up dialog version numbers and contributors.
void setPlotZoom(const std::vector< double > &start_picked, const std::vector< double > &picked)
A concrete window class that contains the canvas and responds to menu item and tool bar events from t...
Definition: CanvasWindow.h:106
void showFitsError() const
Raises a dialog box indicating that FITS support is not available.
void removeSelected()
Removes the selected objects from the canvas.
Definition: CanvasView.cxx:581
void invalidImageFormatError(const std::string &filename)
Raises dialog box for error in image format.
Definition: CanvasView.cxx:437
void setDrawRect(float x, float y, float w, float h)
Sets the drawing rectangle in the paint device space.
Definition: QtGroupView.cxx:66
DisplayController class interface declaration.
int m_apage_w
The actual Page width in Postscript points.
Definition: FigureEditor.h:127
This class implements additional QCanvasView functionality.
Definition: FigureEditor.h:73
inverseWorldMatrix() const
QRect getSelectedBounds() const
Returns a QRect that enclosed the selected QCanvasItem objects.
list< QAction * >::iterator it
A derived class of InspectorBase class which is generated by the Qt designer.
Definition: Inspector.h:234
static QtXMLController * instance()
Returns the pointer to the singleton instance.
bool fillPickedPoint(QMouseEvent *e, std::vector< double > &picked)
Fill the picked vector with the event data.
stripWhiteSpace() const
void removeDisplay(PlotterBase *plotter)
Removes the display from the canvas.
The class of views for Encapsulated Postscript generation.
Definition: EpsView.h:27
hippodraw::PlotterBase class interface.
CanvasView(QCanvas *, QWidget *parent=0, const char *name=0, Qt::WFlags f=0)
Definition: CanvasView.cxx:113
void updatePickTable(QtView *qtview, std::vector< double > &picked)
void addSelectedItem(QCanvasItem *item)
Add an item to the selected list.
void setChanged(bool yes=true)
Sets the canvas as being changed.
Definition: CanvasView.cxx:622
void fillPlotterList(std::vector< PlotterBase * > &plotter_list)
Clears and fills plotter_list with all the PlotterBase objects on the canvas.
const std::vector< std::string > & getNTupleNames() const
Returns a vector of the current DataSource names.
static DataSourceController * instance()
Returns the pointer to the singleton instance.
ViewBase * createTextView(const ViewFactory *factory, hippodraw::DataRep *rep, const std::string &name, const std::string &text=std::string())
Creates an object which is a derived class of ViewBase.

Generated for HippoDraw Class Library by doxygen