Skip to content
Snippets Groups Projects
ApplicationWindow.cpp 579 KiB
Newer Older
  //plotTools->addAction(btnRemovePoints); disabled until fixed (#2783)

  if (mantidUI->fitFunctionBrowser())
  {
    btnMultiPeakPick = new QAction(tr("Select Multiple Peaks..."), this);
    btnMultiPeakPick->setActionGroup(dataTools);
    btnMultiPeakPick->setCheckable( true );
    btnMultiPeakPick->setIcon(QIcon(getQPixmap("Fit_xpm")));
    plotTools->addAction(btnMultiPeakPick);
  }
  else
  {
    btnMultiPeakPick = NULL;
  }

  connect( dataTools, SIGNAL( triggered( QAction* ) ), this, SLOT( pickDataTool( QAction* ) ) );
  plotTools->addSeparator ();

  btnArrow = new QAction(tr("Draw &Arrow"), this);
  btnArrow->setShortcut( tr("CTRL+ALT+A") );
  btnArrow->setActionGroup(dataTools);
  btnArrow->setCheckable( true );
  btnArrow->setIcon(QIcon(getQPixmap("arrow_xpm")) );
  plotTools->addAction(btnArrow);

  btnLine = new QAction(tr("Draw &Line"), this);
  btnLine->setShortcut( tr("CTRL+ALT+L") );
  btnLine->setActionGroup(dataTools);
  btnLine->setCheckable( true );
  btnLine->setIcon(QIcon(getQPixmap("lPlot_xpm")) );
  plotTools->addAction(btnLine);

  plotTools->hide();

  displayBar = new QToolBar( tr( "Data Display" ), this );
  displayBar->setAllowedAreas( Qt::TopToolBarArea | Qt::BottomToolBarArea );
  displayBar->setObjectName("displayBar"); // this is needed for QMainWindow::restoreState()
  info = new QLineEdit( this );
  displayBar->addWidget( info );
  info->setReadOnly(true);
  QPalette palette;
  palette.setColor(QPalette::Text, QColor(Qt::green));
  palette.setColor(QPalette::HighlightedText, QColor(Qt::darkGreen));
  palette.setColor(QPalette::Base, QColor(Qt::black));
  info->setPalette(palette);

  addToolBar( Qt::TopToolBarArea, displayBar );
  displayBar->hide();

  insertToolBarBreak (displayBar);

  formatToolBar = new QToolBar(tr( "Format" ), this);
  formatToolBar->setObjectName("formatToolBar");
  addToolBar(Qt::TopToolBarArea, formatToolBar);

  QFontComboBox *fb = new QFontComboBox();
  connect(fb, SIGNAL(currentFontChanged(const QFont &)), this, SLOT(setFontFamily(const QFont &)));
  actionFontBox = formatToolBar->addWidget(fb);

  QSpinBox *sb = new QSpinBox();
  connect(sb, SIGNAL(valueChanged(int)), this, SLOT(setFontSize(int)));
  actionFontSize = formatToolBar->addWidget(sb);

  actionFontBold->addTo(formatToolBar);
  actionFontItalic->addTo(formatToolBar);

  actionUnderline->addTo(formatToolBar);
  actionSuperscript->addTo(formatToolBar);
  actionSubscript->addTo(formatToolBar);
  actionGreekSymbol->addTo(formatToolBar);
  actionGreekMajSymbol->addTo(formatToolBar);
  actionMathSymbol->addTo(formatToolBar);

  formatToolBar->setEnabled(false);
  formatToolBar->hide();



}

void ApplicationWindow::insertTranslatedStrings()
{
  if (projectname == "untitled")
    setWindowTitle(tr("MantidPlot - untitled"));//Mantid

  lv->setColumnText (0, tr("Name"));
  lv->setColumnText (1, tr("Type"));
  lv->setColumnText (2, tr("View"));
  lv->setColumnText (3, tr("Size"));
  lv->setColumnText (4, tr("Created"));
  lv->setColumnText (5, tr("Label"));

  explorerWindow->setWindowTitle(tr("Project Explorer"));
  logWindow->setWindowTitle(tr("Results Log"));
  undoStackWindow->setWindowTitle(tr("Undo Stack"));
  consoleWindow->setWindowTitle(tr("Scripting Console"));
  displayBar->setWindowTitle(tr("Data Display"));
  plotTools->setWindowTitle(tr("Plot"));
  fileTools->setWindowTitle(tr("File"));
  editTools->setWindowTitle(tr("Edit"));
  plot3DTools->setWindowTitle(tr("3D Surface"));
  formatToolBar->setWindowTitle(tr("Format"));

  fileMenu->changeItem(recentMenuID, tr("&Recent Projects"));

  translateActionsStrings();
  customMenu(activeWindow());
}

void ApplicationWindow::initMainMenu()
{
  fileMenu = new QMenu(this);
  fileMenu->setObjectName("fileMenu");
  connect(fileMenu, SIGNAL(aboutToShow()), this, SLOT(fileMenuAboutToShow()));

  recent = new QMenu(this);
  newMenu = new QMenu(this);
  newMenu->setObjectName("newMenu");
  exportPlotMenu = new QMenu(this);
  exportPlotMenu->setObjectName("exportPlotMenu");

  edit = new QMenu(this);
  edit->setObjectName("editMenu");

  edit->insertSeparator();
  edit->addAction(actionCopySelection);
  edit->addAction(actionPasteSelection);
  edit->insertSeparator();
  edit->addAction(actionDeleteFitTables);

  connect(edit, SIGNAL(aboutToShow()), this, SLOT(editMenuAboutToShow()));

  view = new QMenu(this);
  view->setObjectName("viewMenu");

  view->setCheckable(true);

  //view->addAction(actionShowPlotWizard);
  view->addAction(actionShowExplorer);
  view->addAction(actionShowLog);
  //view->addAction(actionShowUndoStack);
  view->addAction(actionShowConsole);

  view->insertSeparator();
  view->addAction(actionShowScriptWindow);//Mantid
  view->addAction(actionShowScriptInterpreter);
  view->addAction(actionIPythonConsole);
  view->insertSeparator();

  mantidUI->addMenuItems(view);

  view->insertSeparator();
  view->addAction(actionToolBars);
  view->addAction(actionShowConfigureDialog);
  view->insertSeparator();
  view->addAction(actionCustomActionDialog);

  graph = new QMenu(this);
  graph->setObjectName("graphMenu");
  graph->setCheckable(true);
  graph->addAction(actionAddErrorBars);
  graph->addAction(actionRemoveErrorBars);
  graph->addAction(actionShowCurvesDialog);
  graph->addAction(actionAddFunctionCurve);
  graph->addAction(actionNewLegend);
  graph->insertSeparator();
  graph->addAction(btnLabel);
  graph->addAction(btnArrow);
  graph->addAction(btnLine);
  graph->addAction(actionTimeStamp);
  graph->addAction(actionAddImage);
  graph->insertSeparator();//layers section
  graph->addAction(actionAddLayer);
  graph->addAction(actionDeleteLayer);
  graph->addAction(actionShowLayerDialog);

  plot3DMenu = new QMenu(this);
  plot3DMenu->setObjectName("plot3DMenu");
  plot3DMenu->addAction(actionPlot3DWireFrame);
  plot3DMenu->addAction(actionPlot3DHiddenLine);
  plot3DMenu->addAction(actionPlot3DPolygons);
  plot3DMenu->addAction(actionPlot3DWireSurface);
  plot3DMenu->insertSeparator();
  plot3DMenu->addAction(actionPlot3DBars);
  plot3DMenu->addAction(actionPlot3DScatter);
  plot3DMenu->insertSeparator();
  plot3DMenu->addAction(actionImagePlot);
  plot3DMenu->addAction(actionColorMap);
  plot3DMenu->addAction(actionNoContourColorMap);
  plot3DMenu->addAction(actionContourMap);
  plot3DMenu->addAction(actionGrayMap);
  plot3DMenu->insertSeparator();
  //plot3DMenu->addAction(actionPlotHistogram);

  matrixMenu = new QMenu(this);
  matrixMenu->setObjectName("matrixMenu");
  connect(matrixMenu, SIGNAL(aboutToShow()), this, SLOT(matrixMenuAboutToShow()));

  plot2DMenu = new QMenu(this);
  plot2DMenu->setObjectName("plot2DMenu");
  connect(plot2DMenu, SIGNAL(aboutToShow()), this, SLOT(plotMenuAboutToShow()));

  plotDataMenu = new QMenu(this);
  plotDataMenu->setObjectName("plotDataMenu");
  plotDataMenu->setCheckable(true);
  connect(plotDataMenu, SIGNAL(aboutToShow()), this, SLOT(plotDataMenuAboutToShow()));

  normMenu = new QMenu(this);
  normMenu->setObjectName("normMenu");

  fillMenu = new QMenu(this);
  fillMenu->setObjectName("fillMenu");

  tableMenu = new QMenu(this);
  tableMenu->setObjectName("tableMenu");
  connect(tableMenu, SIGNAL(aboutToShow()), this, SLOT(tableMenuAboutToShow()));

  smoothMenu = new QMenu(this);
  smoothMenu->setObjectName("smoothMenu");

  filterMenu = new QMenu(this);
  filterMenu->setObjectName("filterMenu");

  decayMenu = new QMenu(this);
  decayMenu->setObjectName("decayMenu");

  multiPeakMenu = new QMenu(this);
  multiPeakMenu->setObjectName("multiPeakMenu");

  analysisMenu = new QMenu(this);
  analysisMenu->setObjectName("analysisMenu");
  connect(analysisMenu, SIGNAL(aboutToShow()), this, SLOT(analysisMenuAboutToShow()));

  format = new QMenu(this);
  format->setObjectName("formatMenu");

  windowsMenu = new QMenu(this);
  windowsMenu->setObjectName("windowsMenu");
  windowsMenu->setCheckable(true);
  connect(windowsMenu, SIGNAL(aboutToShow()), this, SLOT(windowsMenuAboutToShow()));

  foldersMenu = new QMenu(this);
  foldersMenu->setCheckable(true);

  help = new QMenu(this);
  help->setObjectName("helpMenu");

  help->addAction(actionHomePage);
  help->addAction(actionMantidConcepts);
  help->addAction(actionMantidAlgorithms);
  help->addAction(actionmantidplotHelp);
  help->insertSeparator();
  help->addAction(actionHelpBugReports);
  help->insertSeparator();
  help->addAction(actionFirstTimeSetup);
  help->insertSeparator();
Owen Arnold's avatar
Owen Arnold committed

  ///The paraview action should only be available on windows
#ifdef _WIN32
  help->addAction(actionSetupParaview);
Owen Arnold's avatar
Owen Arnold committed
  help->insertSeparator(); 
#endif
  help->addAction(actionAbout);

  icat = new QMenu(this);
  icat->setObjectName("CatalogMenu");
  icat->addAction(actionICatLogin);//Login menu item
  icat->addAction(actionMydataSearch);// my data search menu item
  icat->addAction(actionICatSearch);//search menu item
  icat->addAction(actionAdvancedSearch); //advanced search menu item
  icat->addAction(actionICatLogout);//logout menu item
  disableActions();
}

void ApplicationWindow::tableMenuAboutToShow()
{
  tableMenu->clear();
  fillMenu->clear();

  MdiSubWindow* t = activeWindow();

  QMenu *setAsMenu = tableMenu->addMenu(tr("Set Columns &As"));
  setAsMenu->addAction(actionSetXCol);
  setAsMenu->addAction(actionSetYCol);
  setAsMenu->addAction(actionSetZCol);
  setAsMenu->insertSeparator();
  setAsMenu->addAction(actionSetLabelCol);
  setAsMenu->addAction(actionDisregardCol);
  setAsMenu->insertSeparator();
  setAsMenu->addAction(actionSetXErrCol);
  setAsMenu->addAction(actionSetYErrCol);
  setAsMenu->insertSeparator();
  setAsMenu->addAction(tr("&Read-only"), this, SLOT(setReadOnlyColumns()));
  setAsMenu->addAction(tr("Read/&Write"), this, SLOT(setReadWriteColumns()));

  tableMenu->addAction(actionShowColumnOptionsDialog);
  tableMenu->insertSeparator();

  tableMenu->addAction(actionShowColumnValuesDialog);
  tableMenu->addAction(actionTableRecalculate);

  fillMenu = tableMenu->addMenu (tr("&Fill Columns With"));
  fillMenu->addAction(actionSetAscValues);
  fillMenu->addAction(actionSetRandomValues);

  tableMenu->addAction(actionClearTable);
  tableMenu->insertSeparator();
  tableMenu->addAction(actionAddColToTable);
  tableMenu->addAction(actionShowColsDialog);
  tableMenu->insertSeparator();
  tableMenu->addAction(actionHideSelectedColumns);
  tableMenu->addAction(actionShowAllColumns);
  tableMenu->insertSeparator();
  tableMenu->addAction(actionMoveColFirst);
  tableMenu->addAction(actionMoveColLeft);
  tableMenu->addAction(actionMoveColRight);
  tableMenu->addAction(actionMoveColLast);
  tableMenu->addAction(actionSwapColumns);
  tableMenu->insertSeparator();
  tableMenu->addAction(actionShowRowsDialog);
  tableMenu->addAction(actionDeleteRows);
  tableMenu->insertSeparator();
  tableMenu->addAction(actionGoToRow);
  tableMenu->addAction(actionGoToColumn);
  tableMenu->insertSeparator();
  tableMenu->addAction(actionConvertTable);
  if (t->isA("Table")) // but not MantidTable
  {
    tableMenu->addAction(actionConvertTableToWorkspace);
  }
  tableMenu->addAction(actionConvertTableToMatrixWorkspace);

  tableMenu->insertSeparator();
  tableMenu->addAction(actionShowPlotWizard);

  reloadCustomActions();
}

void ApplicationWindow::plotDataMenuAboutToShow()
{
  plotDataMenu->clear();
  plotDataMenu->addAction(btnPointer);
  plotDataMenu->addAction(btnZoomIn);
  plotDataMenu->addAction(btnZoomOut);
  plotDataMenu->addAction(actionMagnify);
  plotDataMenu->addAction(actionUnzoom);
  plotDataMenu->insertSeparator();
  plotDataMenu->addAction(btnCursor);
  plotDataMenu->addAction(btnSelect);
  plotDataMenu->addAction(btnPicker);
  plotDataMenu->insertSeparator();
  plotDataMenu->addAction(actionDrawPoints);
  plotDataMenu->addAction(btnMovePoints);
  plotDataMenu->addAction(btnRemovePoints);


  reloadCustomActions();
}

void ApplicationWindow::plotMenuAboutToShow()
{
  plot2DMenu->clear();

  plot2DMenu->addAction(actionPlotL);
  plot2DMenu->addAction(actionPlotP);
  plot2DMenu->addAction(actionPlotLP);

  QMenu *specialPlotMenu = plot2DMenu->addMenu (tr("Special Line/Symb&ol"));
  specialPlotMenu->addAction(actionWaterfallPlot);
  specialPlotMenu->addAction(actionPlotVerticalDropLines);
  specialPlotMenu->addAction(actionPlotSpline);
  specialPlotMenu->addAction(actionPlotVertSteps);
  specialPlotMenu->addAction(actionPlotHorSteps);
  plot2DMenu->insertSeparator();
  plot2DMenu->addAction(actionPlotVerticalBars);
  plot2DMenu->addAction(actionPlotHorizontalBars);
  plot2DMenu->addAction(actionPlotArea);
  plot2DMenu->addAction(actionPlotPie);
  plot2DMenu->addAction(actionPlotVectXYXY);
  plot2DMenu->addAction(actionPlotVectXYAM);
  plot2DMenu->insertSeparator();

  QMenu *statMenu = plot2DMenu->addMenu (tr("Statistical &Graphs"));
  statMenu->addAction(actionBoxPlot);
  statMenu->addAction(actionPlotHistogram);
  statMenu->addAction(actionPlotStackedHistograms);
  statMenu->insertSeparator();
  statMenu->addAction(actionStemPlot);

  QMenu *panelsMenu = plot2DMenu->addMenu (tr("Pa&nel"));
  panelsMenu->addAction(actionPlot2VerticalLayers);
  panelsMenu->addAction(actionPlot2HorizontalLayers);
  panelsMenu->addAction(actionPlot4Layers);
  panelsMenu->addAction(actionPlotStackedLayers);

  QMenu *plot3D = plot2DMenu->addMenu (tr("3&D Plot"));
  plot3D->addAction(actionPlot3DRibbon);
  plot3D->addAction(actionPlot3DBars);
  plot3D->addAction(actionPlot3DScatter);
  plot3D->addAction(actionPlot3DTrajectory);

  reloadCustomActions();
}

void ApplicationWindow::customMenu(MdiSubWindow* w)
{
  myMenuBar()->clear();
  myMenuBar()->insertItem(tr("&File"), fileMenu);
  fileMenuAboutToShow();
  myMenuBar()->insertItem(tr("&Edit"), edit);
  editMenuAboutToShow();
  myMenuBar()->insertItem(tr("&View"), view);

  // these use the same keyboard shortcut (Ctrl+Return) and should not be enabled at the same time
  actionTableRecalculate->setEnabled(false);

  // clear undo stack view (in case window is not a matrix)
  d_undo_view->setStack(0);
  actionUndo->setEnabled(false);
  actionRedo->setEnabled(false);

  if(w){
    actionPrintAllPlots->setEnabled(projectHas2DPlots());
    actionPrint->setEnabled(true);
    actionCutSelection->setEnabled(true);
    actionCopySelection->setEnabled(true);
    actionPasteSelection->setEnabled(true);
    actionClearSelection->setEnabled(true);
    actionSaveTemplate->setEnabled(true);
    QStringList tables = tableNames() + matrixNames();
    if (!tables.isEmpty())
      actionShowExportASCIIDialog->setEnabled(true);
    else
      actionShowExportASCIIDialog->setEnabled(false);

    if (w->isA("MultiLayer")) {
      myMenuBar()->insertItem(tr("&Graph"), graph);
      myMenuBar()->insertItem(tr("&Data"), plotDataMenu);
      plotDataMenuAboutToShow();
      if (m_enableQtiPlotFitting)
      {
        myMenuBar()->insertItem(tr("&Analysis"), analysisMenu);
        analysisMenuAboutToShow();
      }
      myMenuBar()->insertItem(tr("For&mat"), format);

      format->clear();
      format->addAction(actionShowPlotDialog);
      format->insertSeparator();
      format->addAction(actionShowScaleDialog);
      format->addAction(actionShowAxisDialog);
      actionShowAxisDialog->setEnabled(true);
      format->insertSeparator();
      format->addAction(actionShowGridDialog);
      format->addAction(actionShowTitleDialog);
  
    } else if (w->isA("Graph3D")) {
      disableActions();

      myMenuBar()->insertItem(tr("For&mat"), format);

      actionPrint->setEnabled(true);
      actionSaveTemplate->setEnabled(true);

      format->clear();
      format->addAction(actionShowPlotDialog);
      format->addAction(actionShowScaleDialog);
      format->addAction(actionShowAxisDialog);
      format->addAction(actionShowTitleDialog);
      if (dynamic_cast<Graph3D*>(w)->coordStyle() == Qwt3D::NOCOORD)
        actionShowAxisDialog->setEnabled(false);
    } else if (w->inherits("Table")) {
      myMenuBar()->insertItem(tr("&Plot"), plot2DMenu);
      myMenuBar()->insertItem(tr("&Analysis"), analysisMenu);
      analysisMenuAboutToShow();
      myMenuBar()->insertItem(tr("&Table"), tableMenu);
      tableMenuAboutToShow();
      actionTableRecalculate->setEnabled(true);

    } else if (w->isA("Matrix")){
      actionTableRecalculate->setEnabled(true);
      myMenuBar()->insertItem(tr("3D &Plot"), plot3DMenu);
      myMenuBar()->insertItem(tr("&Matrix"), matrixMenu);
      matrixMenuAboutToShow();
      myMenuBar()->insertItem(tr("&Analysis"), analysisMenu);
      analysisMenuAboutToShow();
      d_undo_view->setEmptyLabel(w->objectName() + ": " + tr("Empty Stack"));
      QUndoStack *stack = dynamic_cast<Matrix *>(w)->undoStack();
      d_undo_view->setStack(stack);

    } else if (w->isA("Note")) {
      actionSaveTemplate->setEnabled(false);

    } else if (!mantidUI->menuAboutToShow(w)) // Note that this call has a side-effect (it enables menus)
        disableActions();
   
  } else
    disableActions();

  myMenuBar()->insertItem(tr("&Windows"), windowsMenu);
  windowsMenuAboutToShow();
  // -- Mantid: add script actions, if any exist --
  QListIterator<QMenu*> mIter(d_user_menus);
  while( mIter.hasNext() )
  {
    QMenu* item = mIter.next();
    myMenuBar()->insertItem(tr(item->title()), item);

  }

  myMenuBar()->insertItem(tr("&Catalog"),icat);

  // Interface menu. Build the interface from the user sub windows list.
  // Modifications will be done through the ManageCustomMenus dialog and
  // remembered through QSettings.
  QStringList user_windows = MantidQt::API::InterfaceManager::Instance().getUserSubWindowKeys();
  QStringListIterator itr(user_windows);
  QString menuName = "&Interfaces";
  addUserMenu(menuName);
  while( itr.hasNext() )
  {
      QString itemName = itr.next();
      // Check whether the menu item was flagged in the QSettings.
      if (getMenuSettingsFlag(itemName))
          addUserMenuAction( menuName, itemName, itemName);
  }

  // Go through PyQt interfaces
  QString scriptsDir = QString::fromStdString(Mantid::Kernel::ConfigService::Instance().getString("mantidqt.python_interfaces_directory"));
  QStringListIterator pyqt_itr(pyqt_interfaces);
  while( pyqt_itr.hasNext() )
  {
    QString itemName = pyqt_itr.next();
    QString scriptPath = scriptsDir + '/' + itemName;

    if( QFileInfo(scriptPath).exists() ) {
      QString baseName = QFileInfo(scriptPath).baseName();
      // Need to use "nice" name to check if scripts has been removed by user.
      QString niceName = baseName.replace("_", " ");
      if (getMenuSettingsFlag(niceName))
1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000
        addUserMenuAction(menuName, baseName, scriptPath);
    }
    else
    {
      Mantid::Kernel::Logger& g_log = Mantid::Kernel::Logger::get("ConfigService");
      g_log.warning() << "Could not find interface script: " << scriptPath.ascii() << "\n";
    }
  }

  myMenuBar()->insertItem(tr("&Help"), help );

  reloadCustomActions();
}

/**
 * Returns whether a custom interface should be added to the Interfaces menu.
 * @param menu_item: name of the custom interface
 */
bool ApplicationWindow::getMenuSettingsFlag(const QString & menu_item)
{
  // Look for the interface in the user menu list
  // If we found the item in the user menu list, return true
  QMenu *menu = NULL;
  foreach(menu, d_user_menus)
  {
    if( menu->title() == menu_item ) return true;
  }

  // If we didn't find it, check whether is was manually removed
  if( removed_interfaces.contains(menu_item) ) return false;
  return true;
}

void ApplicationWindow::disableActions()
{
  actionSaveTemplate->setEnabled(false);
  actionPrintAllPlots->setEnabled(false);
  actionPrint->setEnabled(false);

  actionCutSelection->setEnabled(false);
  actionCopySelection->setEnabled(false);
  actionPasteSelection->setEnabled(false);
  actionClearSelection->setEnabled(false);
}

void ApplicationWindow::customColumnActions()
{
  actionMoveColFirst->setEnabled(false);
  actionMoveColLeft->setEnabled(false);
  actionMoveColRight->setEnabled(false);
  actionMoveColLast->setEnabled(false);
  actionSetXCol->setEnabled(false);
  actionSetYCol->setEnabled(false);
  actionSetZCol->setEnabled(false);
  actionSetLabelCol->setEnabled(false);
  actionSetYErrCol->setEnabled(false);
  actionDisregardCol->setEnabled(false);
  actionSwapColumns->setEnabled(false);
  actionSetAscValues->setEnabled(false);
  actionSetRandomValues->setEnabled(false);

  Table *t = dynamic_cast<Table*>(activeWindow(TableWindow));
  if (!t)
    return;

  int selectedCols = t->selectedColsNumber();
  if (selectedCols == 1){
    int col = t->selectedColumn();
    if (col > 0){
      actionMoveColFirst->setEnabled(true);
      actionMoveColLeft->setEnabled(true);
    }

    if (col < t->numCols() - 1){
      actionMoveColRight->setEnabled(true);
      actionMoveColLast->setEnabled(true);
    }
  }

  if (selectedCols >= 1){
    actionSetAscValues->setEnabled(true);
    actionSetRandomValues->setEnabled(true);
    actionSetXCol->setEnabled(true);
    actionSetYCol->setEnabled(true);
    actionSetZCol->setEnabled(true);
    actionSetYErrCol->setEnabled(true);
    actionSetLabelCol->setEnabled(true);
    actionDisregardCol->setEnabled(true);
  }

  if (selectedCols == 2)
    actionSwapColumns->setEnabled(true);
}


/** Set the exit code to be returned by the application at
 * exit. Used by MantidPlot unit tests to signal failure.
 *
 * @param code :: int code, non-zero for failure
 */
void ApplicationWindow::setExitCode(int code)
{
  m_exitCode = code;
}

/** Get the exit code to be returned by the application at
 * exit. Used by MantidPlot unit tests to signal failure.
 *
 * @return code :: int code, non-zero for failure
 */
int ApplicationWindow::getExitCode()
{
  return m_exitCode;
}


void ApplicationWindow::customToolBars(MdiSubWindow* w)
{
  disableToolbars();
  if (!w)
    return;

  if (w->isA("MultiLayer") && d_plot_tool_bar){
    if(!plotTools->isVisible())
      plotTools->show();
    plotTools->setEnabled (true);
    customMultilayerToolButtons(dynamic_cast<MultiLayer*>(w));
    if(d_format_tool_bar && !formatToolBar->isVisible()){
      formatToolBar->setEnabled (true);
      formatToolBar->show();
    }
  } else if (w->isA("Graph3D") && d_plot3D_tool_bar){
    if(!plot3DTools->isVisible())
      plot3DTools->show();

    if (dynamic_cast<Graph3D*>(w)->plotStyle() == Qwt3D::NOPLOT)
      plot3DTools->setEnabled(false);
    else
      plot3DTools->setEnabled(true);
    custom3DActions(w);
  }
}

void ApplicationWindow::disableToolbars()
{
  plotTools->setEnabled(false);
  plot3DTools->setEnabled(false);
}

void ApplicationWindow::hideToolbars()
{
  fileTools->setVisible(false);
  displayBar->setVisible(false);
  editTools->setVisible(false);
  plotTools->setVisible(false);
  plot3DTools->setVisible(false);
  formatToolBar->setVisible(false);
}

void ApplicationWindow::showToolbars()
{
  fileTools->setVisible(true);
  displayBar->setVisible(true);
  editTools->setVisible(true);
  plotTools->setVisible(true);
  //plot3DTools->setVisible(true);
  formatToolBar->setVisible(true);
}

void ApplicationWindow::plot3DRibbon()
{
  MdiSubWindow *w = activeWindow(TableWindow);
  if (!w)
    return;

  Table *table = static_cast<Table*>(w);
  if(table->selectedColumns().count() == 1){
    if (!validFor3DPlot(table))
      return;
    plotXYZ(table, table->colName(table->selectedColumn()), Graph3D::Ribbon);
  } else
    QMessageBox::warning(this, tr("MantidPLot - Plot error"), tr("You must select exactly one column for plotting!"));
}

void ApplicationWindow::plot3DWireframe()
{
  plot3DMatrix (0, Qwt3D::WIREFRAME);
}

void ApplicationWindow::plot3DHiddenLine()
{
  plot3DMatrix (0, Qwt3D::HIDDENLINE);
}

void ApplicationWindow::plot3DPolygons()
{
  plot3DMatrix (0, Qwt3D::FILLED);
}

void ApplicationWindow::plot3DWireSurface()
{
  plot3DMatrix (0, Qwt3D::FILLEDMESH);
}

void ApplicationWindow::plot3DBars()
{
  MdiSubWindow *w = activeWindow();
  if (!w)
    return;

  if (w->inherits("Table")){
    Table *table = static_cast<Table *>(w);
    if (!validFor3DPlot(table))
      return;

    if(table->selectedColumns().count() == 1)
      plotXYZ(table, table->colName(table->selectedColumn()), Graph3D::Bars);
    else
      QMessageBox::warning(this, tr("MantidPlot - Plot error"),tr("You must select exactly one column for plotting!"));//Mantid
  }
  else if(w->inherits("Matrix"))
    plot3DMatrix(0, Qwt3D::USER);
}

void ApplicationWindow::plot3DScatter()
{
  MdiSubWindow *w = activeWindow();
  if (!w)
    return;

  if (w->inherits("Table"))
  {
    Table *table = static_cast<Table *>(w);
    if (!validFor3DPlot(table))
      return;

    if(table->selectedColumns().count() == 1)
      plotXYZ(table, table->colName(table->selectedColumn()), Graph3D::Scatter);
    else
      QMessageBox::warning(this, tr("MantidPlot - Plot error"),tr("You must select exactly one column for plotting!"));//Mantid
  }
  else if(w->inherits("Matrix"))
    plot3DMatrix (0, Qwt3D::POINTS);
}

void ApplicationWindow::plot3DTrajectory()
{
  Table *table = dynamic_cast<Table *>(activeWindow(TableWindow));
  if (!table)
    return;
  if (!validFor3DPlot(table))
    return;

  if(table->selectedColumns().count() == 1)
    plotXYZ(table, table->colName(table->selectedColumn()), Graph3D::Trajectory);
  else
    QMessageBox::warning(this, tr("MantidPlot - Plot error"), tr("You must select exactly one column for plotting!"));//Mantid
}

void ApplicationWindow::plotBoxDiagram()
{
  generate2DGraph(Graph::Box);
}

void ApplicationWindow::plotVerticalBars()
{
  generate2DGraph(Graph::VerticalBars);
}

void ApplicationWindow::plotHorizontalBars()
{
  generate2DGraph(Graph::HorizontalBars);
}

MultiLayer* ApplicationWindow::plotHistogram()
{
  return generate2DGraph(Graph::Histogram);
}

MultiLayer* ApplicationWindow::plotHistogram(Matrix *m)
{
  if (!m) {
    m = dynamic_cast<Matrix*>(activeWindow(MatrixWindow));
    if (!m)
      return 0;
  }

  QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));

  MultiLayer* g = new MultiLayer(this);
  initMultilayerPlot(g, generateUniqueName(tr("Graph")));

  Graph* plot = g->activeGraph();
  setPreferences(plot);
  plot->addHistogram(m);

  QApplication::restoreOverrideCursor();
  return g;
}

void ApplicationWindow::plotArea()
{
  generate2DGraph(Graph::Area);
}

void ApplicationWindow::plotPie()
{
  Table *table = dynamic_cast<Table *>(activeWindow(TableWindow));
  if (!table)
    return;

  if(table->selectedColumns().count() != 1){
    QMessageBox::warning(this, tr("MantidPlot - Plot error"),//Mantid
        tr("You must select exactly one column for plotting!"));
    return;
  }

  QStringList s = table->selectedColumns();
  if (s.count()>0){
    Q3TableSelection sel = table->getSelection();
    multilayerPlot(table, s, Graph::Pie, sel.topRow(), sel.bottomRow());
  } else
    QMessageBox::warning(this, tr("MantidPlot - Error"), tr("Please select a column to plot!"));//Mantid
}

void ApplicationWindow::plotL()
{
  generate2DGraph(Graph::Line);
}

void ApplicationWindow::plotP()
{
  generate2DGraph(Graph::Scatter);
}

void ApplicationWindow::plotLP()
{
  generate2DGraph(Graph::LineSymbols);
}

void ApplicationWindow::plotVerticalDropLines()
{
  generate2DGraph(Graph::VerticalDropLines);
}

void ApplicationWindow::plotSpline()
{
  generate2DGraph(Graph::Spline);
}

void ApplicationWindow::plotVertSteps()
{
  generate2DGraph(Graph::VerticalSteps);
}

void ApplicationWindow::plotHorSteps()
{
  generate2DGraph(Graph::HorizontalSteps);
}

void ApplicationWindow::plotVectXYXY()
{
  Table *table = dynamic_cast<Table *>(activeWindow(TableWindow));
  if (!table)
    return;
  if (!validFor2DPlot(table))
    return;

  QStringList s = table->selectedColumns();
  if (s.count() == 4) {
    Q3TableSelection sel = table->getSelection();
    multilayerPlot(table, s, Graph::VectXYXY, sel.topRow(), sel.bottomRow());
  } else
    QMessageBox::warning(this, tr("MantidPlot - Error"), tr("Please select four columns for this operation!"));//Mantid
}

void ApplicationWindow::plotVectXYAM()
{
  Table *table = dynamic_cast<Table *>(activeWindow(TableWindow));
  if (!table)
    return;
  if (!validFor2DPlot(table))
    return;

  QStringList s = table->selectedColumns();
  if (s.count() == 4){
    Q3TableSelection sel = table->getSelection();
    multilayerPlot(table, s, Graph::VectXYAM, sel.topRow(), sel.bottomRow());
  } else
    QMessageBox::warning(this, tr("MantidPlot - Error"), tr("Please select four columns for this operation!"));//Mantid
}

QString ApplicationWindow::stemPlot(Table *t, const QString& colName, int power, int startRow, int endRow)
{
  if (!t)
    return QString();

  int col = t->colIndex(colName);
  if (col < 0){
    QMessageBox::critical(this, tr("MantidPlot - Error"),
    tr("Data set: %1 doesn't exist!").arg(colName));
    return QString();
  }

  startRow--;
  endRow--;
  if (startRow < 0 || startRow >= t->numRows())
    startRow = 0;
  if (endRow < 0 || endRow >= t->numRows())
    endRow = t->numRows() - 1;

  QString result = tr("Stem and leaf plot of dataset") + ": " + colName + " ";
  result += tr("from row") + ": " + QString::number(startRow + 1) + " ";
  result += tr("to row") + ": " + QString::number(endRow + 1) + "\n";

  int rows = 0;
  for (int j = startRow; j <= endRow; j++){
    if (!t->text(j, col).isEmpty())
       rows++;
  }

  if (rows >= 1){
    double *data = (double *)malloc(rows * sizeof (double));
    if (!data){
      result += tr("Not enough memory for this dataset!") + "\n";
      return result;
    }

    result += "\n" + tr("Stem") + " | " + tr("Leaf");
    result += "\n---------------------\n";

    int row = 0;
    for (int j = startRow; j <= endRow; j++){
      if (!t->text(j, col).isEmpty()){
        data[row] = t->cell(j, col);
        row++;
      }
    }
    gsl_sort (data, 1, rows);

    if (power > 1e3){
      power = static_cast<int>(std::ceil(log10(data[rows - 1] - data[0]) - log10(rows - 1.0)));
      bool ok;
      int input = QInputDialog::getInteger(this, tr("Please confirm the stem unit!"),
                                      tr("Data set") + ": " + colName + ", " + tr("stem unit") + " = 10<sup>n</sup>, n = ",
                                      power, -1000, 1000, 1, &ok);
      if (ok)
        power = input;
    }

    double stem_unit = pow(10.0, power);
    double leaf_unit = stem_unit/10.0;

    int prev_stem = int(data[0]/stem_unit);
    result += "      " + QString::number(prev_stem) + " | ";

    for (int j = 0; j <rows; j++){
      double val = data[j];
      int stem = int(val/stem_unit);