14 #include "xrubysupport.h"
19 #include <QDesktopWidget>
20 #include <QApplication>
21 #include <QDockWidget>
22 #include <QCloseEvent>
24 #include <QMdiSubWindow>
25 #include <QMainWindow>
26 #include <QMessageBox>
27 #include <QFileDialog>
29 #include <kstandarddirs.h>
31 #include <QStandardPaths>
36 #include "xscheduler.h"
38 #include "interface.h"
39 #include "xrubywriter.h"
40 #include "xdotwriter.h"
41 #include "xrubythreadconnector.h"
42 #include "ui_rubythreadtool.h"
43 #include "ui_caltableform.h"
44 #include "ui_recordreaderform.h"
45 #include "ui_nodebrowserform.h"
46 #include "ui_interfacetool.h"
47 #include "ui_graphtool.h"
48 #include "ui_drivertool.h"
49 #include "ui_scalarentrytool.h"
51 #include "messagebox.h"
53 QWidget *g_pFrmMain = 0L;
56 FrmKameMain::FrmKameMain()
59 std::min(1280, QApplication::desktop()->width()),
60 height()).expandedTo(sizeHint()) );
62 setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
72 m_pMdiCentral =
new QMdiArea(
this );
73 setCentralWidget( m_pMdiCentral );
74 m_pMdiCentral->setViewMode(QMdiArea::TabbedView);
75 m_pMdiCentral->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
79 QDockWidget* dock =
new QDockWidget(i18n(
"KAME Toolbox West"),
this);
80 dock->setFeatures(QDockWidget::DockWidgetFloatable);
81 dock->setWindowIcon(*g_pIconDriver);
82 m_pMdiLeft =
new QMdiArea(
this );
83 m_pMdiLeft->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
84 m_pMdiLeft->setViewMode(QMdiArea::TabbedView);
85 m_pMdiLeft->setTabPosition(QTabWidget::West);
86 dock->setWidget(m_pMdiLeft);
87 addDockWidget(Qt::LeftDockWidgetArea, dock);
90 dock =
new QDockWidget(i18n(
"KAME Toolbox East"),
this);
91 dock->setFeatures(QDockWidget::DockWidgetFloatable);
92 dock->setWindowIcon(*g_pIconInterface);
93 m_pMdiRight=
new QMdiArea(
this );
94 m_pMdiRight->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
95 m_pMdiRight->setViewMode(QMdiArea::TabbedView);
96 m_pMdiRight->setTabPosition(QTabWidget::East);
97 dock->setWidget(m_pMdiRight);
98 addDockWidget(Qt::RightDockWidgetArea, dock);
103 m_pFrmDriver->setWindowIcon(*g_pIconDriver);
104 QMdiSubWindow* swnd = addDockableWindow(m_pMdiLeft, m_pFrmDriver,
false);
107 m_pFrmGraphList->setWindowIcon(*g_pIconGraph);
108 addDockableWindow(m_pMdiLeft, m_pFrmGraphList,
false);
111 m_pFrmCalTable->setWindowIcon( *g_pIconRoverT);
112 addDockableWindow(m_pMdiLeft, m_pFrmCalTable,
false);
115 m_pFrmNodeBrowser->setWindowIcon(QApplication::style()->standardIcon(QStyle::SP_FileDialogContentsView));
116 addDockableWindow(m_pMdiLeft, m_pFrmNodeBrowser,
false);
118 m_pMdiLeft->activatePreviousSubWindow();
119 m_pMdiLeft->activatePreviousSubWindow();
120 m_pMdiLeft->activatePreviousSubWindow();
123 m_pFrmInterface ->setWindowIcon(*g_pIconInterface);
124 swnd = addDockableWindow(m_pMdiRight, m_pFrmInterface,
false);
126 m_pFrmScalarEntry =
new FrmEntry(
this);
127 m_pFrmScalarEntry->setWindowIcon(*g_pIconScalar);
128 addDockableWindow(m_pMdiRight, m_pFrmScalarEntry,
false);
131 m_pFrmRecordReader->setWindowIcon(*g_pIconReader);
132 addDockableWindow(m_pMdiRight, m_pFrmRecordReader,
false);
134 m_pMdiRight->activatePreviousSubWindow();
135 m_pMdiRight->activatePreviousSubWindow();
138 m_pViewMenu->addSeparator();
139 QAction *act =
new QAction( *g_pIconInfo, XMessageBox::form()->windowTitle(),
this);
140 connect(act, SIGNAL(triggered()), XMessageBox::form(), SLOT(showNormal()));
141 m_pViewMenu->addAction(act);
143 resize(QSize(std::min(1280, width()), 560));
146 m_measure = XNode::createOrphan<XMeasure>(
"Measurement",
false);
149 connect( m_pFileCloseAction, SIGNAL( triggered() ),
this, SLOT( fileCloseAction_activated() ) );
150 connect( m_pFileExitAction, SIGNAL( triggered() ),
this, SLOT( fileExitAction_activated() ) );
151 connect( m_pFileOpenAction, SIGNAL( triggered() ),
this, SLOT( fileOpenAction_activated() ) );
152 connect( m_pFileSaveAction, SIGNAL( triggered() ),
this, SLOT( fileSaveAction_activated() ) );
153 connect( m_pHelpAboutAction, SIGNAL( triggered() ),
this, SLOT( helpAboutAction_activated() ) );
154 connect( m_pHelpContentsAction, SIGNAL( triggered() ),
this, SLOT( helpContentsAction_activated() ) );
155 connect( m_pHelpIndexAction, SIGNAL( triggered() ),
this, SLOT( helpIndexAction_activated() ) );
157 connect( m_pMesStopAction, SIGNAL( triggered() ),
this, SLOT( mesStopAction_activated() ) );
158 connect( m_pScriptRunAction, SIGNAL( triggered() ),
this, SLOT( scriptRunAction_activated() ) );
159 connect( m_pScriptLineShellAction, SIGNAL( triggered() ),
this, SLOT( scriptLineShellAction_activated() ) );
160 connect( m_pScriptDotSaveAction, SIGNAL( triggered() ),
this, SLOT( scriptDotSaveAction_activated() ) );
161 connect( m_pFileLogAction, SIGNAL( toggled(
bool) ),
this, SLOT( fileLogAction_toggled(
bool) ) );
163 connect(qApp, SIGNAL(aboutToQuit()),
this, SLOT(aboutToQuit()));
164 connect(qApp, SIGNAL( lastWindowClosed() ), qApp, SLOT( quit() ) );
166 m_pTimer =
new QTimer(
this);
167 connect(m_pTimer, SIGNAL (timeout() ),
this, SLOT(processSignals()));
170 scriptLineShellAction_activated();
174 void closeEvent(QCloseEvent *e) {
179 FrmKameMain::addDockableWindow(QMdiArea *area, QWidget *widget,
bool closable) {
182 wnd =
new QMdiSubWindow();
183 wnd->setAttribute(Qt::WA_DeleteOnClose);
187 QAction *act =
new QAction(widget->windowIcon(), widget->windowTitle(),
this);
188 connect(act, SIGNAL(triggered()), wnd, SLOT(showMaximized()));
189 m_pViewMenu->addAction(act);
191 wnd->setWidget(widget);
192 area->addSubWindow(wnd);
193 wnd->setWindowIcon(widget->windowIcon());
194 wnd->setWindowTitle(widget->windowTitle());
195 wnd->showMaximized();
199 FrmKameMain::~FrmKameMain() {
203 g_signalBuffer.reset();
204 delete s_pMessageBox; s_pMessageBox = 0L;
208 FrmKameMain::aboutToQuit() {
212 FrmKameMain::createActions() {
214 m_pFileOpenAction =
new QAction(
this );
216 m_pFileOpenAction->setIcon(QApplication::style()->standardIcon(QStyle::SP_DirOpenIcon));
217 m_pFileSaveAction =
new QAction(
this );
218 m_pFileSaveAction->setEnabled(
true );
219 m_pFileSaveAction->setIcon(QApplication::style()->standardIcon(QStyle::SP_DialogSaveButton));
220 m_pFileCloseAction =
new QAction(
this );
221 m_pFileCloseAction->setEnabled(
true );
223 m_pFileCloseAction->setIcon(QApplication::style()->standardIcon(QStyle::SP_DirClosedIcon));
224 m_pFileExitAction =
new QAction(
this );
226 m_pFileExitAction->setIcon(QApplication::style()->standardIcon(QStyle::SP_DialogCloseButton));
227 m_pHelpContentsAction =
new QAction(
this );
228 m_pHelpIndexAction =
new QAction(
this );
229 m_pHelpAboutAction =
new QAction(
this );
230 m_pHelpAboutAction->setIcon(QApplication::style()->standardIcon(QStyle::SP_DialogHelpButton));
231 m_pFileLogAction =
new QAction(
this );
232 m_pFileLogAction->setCheckable(
true );
233 m_pFileLogAction->setChecked( g_bLogDbgPrint );
234 m_pFileLogAction->setIcon(QApplication::style()->standardIcon(QStyle::SP_DriveCDIcon));
238 m_pMesStopAction =
new QAction(
this );
239 m_pMesStopAction->setEnabled(
true );
240 m_pMesStopAction->setIcon( QIcon( *g_pIconStop) );
241 m_pScriptRunAction =
new QAction(
this );
242 m_pScriptRunAction->setEnabled(
true );
243 m_pScriptRunAction->setIcon( QIcon( *g_pIconScript) );
244 m_pScriptLineShellAction =
new QAction(
this );
245 m_pScriptLineShellAction->setEnabled(
true );
246 m_pScriptLineShellAction->setIcon(QApplication::style()->standardIcon(QStyle::SP_FileDialogDetailedView));
247 m_pScriptDotSaveAction =
new QAction(
this );
248 m_pScriptDotSaveAction->setEnabled(
true );
249 m_pScriptDotSaveAction->setIcon(QApplication::style()->standardIcon(QStyle::SP_DialogSaveButton));
251 m_pFileOpenAction->setText( i18n(
"&Open..." ) );
252 m_pFileOpenAction->setShortcut( i18n(
"Ctrl+O" ) );
253 m_pFileSaveAction->setText( tr(
"&Save..." ) );
254 m_pFileSaveAction->setShortcut( i18n(
"Ctrl+S" ) );
255 m_pFileExitAction->setText( i18n(
"E&xit" ) );
256 m_pHelpContentsAction->setText( i18n(
"&Contents..." ) );
257 m_pHelpIndexAction->setText( i18n(
"&Index..." ) );
258 m_pHelpAboutAction->setText( i18n(
"&About" ) );
259 m_pFileLogAction->setText( i18n(
"&Log Debugging Info" ) );
260 m_pMesStopAction->setText( i18n(
"&Stop" ) );
261 m_pScriptRunAction->setText( i18n(
"&Run..." ) );
262 m_pScriptLineShellAction->setText( i18n(
"&New Line Shell" ) );
263 m_pScriptDotSaveAction->setText( i18n(
"&Graphviz Save .dot..." ) );
264 m_pFileCloseAction->setText( i18n(
"&Close" ) );
267 FrmKameMain::createMenus() {
270 m_pFileMenu = menuBar()->addMenu(i18n(
"&File" ) );
271 m_pFileMenu->addAction(m_pFileOpenAction);
272 m_pFileMenu->addAction(m_pFileSaveAction);
273 m_pFileMenu->addAction(m_pFileCloseAction);
274 m_pFileMenu->addSeparator();
275 m_pFileMenu->addAction(m_pFileLogAction);
276 m_pFileMenu->addSeparator();
277 m_pFileMenu->addAction(m_pFileExitAction);
279 m_pMeasureMenu = menuBar()->addMenu(i18n(
"&Measure" ));
280 m_pMeasureMenu->addAction(m_pMesStopAction);
282 m_pScriptMenu = menuBar()->addMenu( i18n(
"&Script" ) );
283 m_pScriptMenu->addAction(m_pScriptRunAction);
284 m_pScriptMenu->addAction(m_pScriptLineShellAction);
285 m_pScriptMenu->addSeparator();
286 m_pScriptMenu->addAction(m_pScriptDotSaveAction);
288 m_pViewMenu = menuBar()->addMenu(i18n(
"&View" ) );
290 m_pHelpMenu = menuBar()->addMenu(i18n(
"&Help" ) );
291 m_pHelpMenu->addAction(m_pHelpContentsAction);
292 m_pHelpMenu->addAction(m_pHelpIndexAction );
293 m_pHelpMenu->addSeparator();
294 m_pHelpMenu->addAction(m_pHelpAboutAction);
298 FrmKameMain::processSignals() {
299 bool idle = g_signalBuffer->synchronize();
303 static XTime last = XTime::now();
304 if(XTime::now() - last > 3) {
314 FrmKameMain::closeEvent( QCloseEvent* ce ) {
317 Snapshot shot( *m_measure->interfaces());
320 for(
auto it = list.begin(); it != list.end(); it++) {
321 auto intf = dynamic_pointer_cast<
XInterface>( *it);
322 if(intf->isOpened()) opened =
true;
327 QMessageBox::warning(
this,
"KAME", i18n(
"Stop running first.") );
333 m_conMeasRubyThread.reset();
334 m_measure->terminate();
340 void FrmKameMain::fileCloseAction_activated() {
341 m_conMeasRubyThread.reset();
342 m_measure->terminate();
346 void FrmKameMain::fileExitAction_activated() {
350 void FrmKameMain::fileOpenAction_activated() {
351 QString filename = QFileDialog::getOpenFileName (
352 this, i18n(
"Open Measurement File"),
"",
353 "KAME2 Measurement files (*.kam);;"
354 "KAME1 Measurement files (*.mes);;"
361 void FrmKameMain::fileSaveAction_activated() {
362 QString filter =
"KAME2 Measurement files (*.kam)";
363 #if QT_VERSION < QT_VERSION_CHECK(5,0,0)
364 QString filename = QFileDialog::getSaveFileName (
365 this, i18n(
"Save Measurement File"),
"", filter);
368 QFileDialog dialog(
this);
369 dialog.setWindowTitle(i18n(
"Save Measurement File"));
370 dialog.setViewMode(QFileDialog::Detail);
371 dialog.setNameFilter(filter);
372 dialog.setConfirmOverwrite(
true);
373 dialog.setDefaultSuffix(
"kam");
374 dialog.setAcceptMode(QFileDialog::AcceptSave);
377 QString filename = dialog.selectedFiles().at(0);
379 if( !filename.isEmpty()) {
380 std::ofstream ofs(filename.toLocal8Bit().data(), std::ios::out);
389 void FrmKameMain::helpAboutAction_activated() {
390 QMessageBox::about(
this,
391 i18n(
"K's Adaptive Measurement Engine."),
"KAME");
394 void FrmKameMain::helpContentsAction_activated() {
398 void FrmKameMain::helpIndexAction_activated() {
412 void FrmKameMain::mesStopAction_activated() {
423 FrmKameMain::openMes(
const XString &filename) {
424 if( !filename.empty()) {
425 runNewScript(
"Open Measurement", filename );
436 shared_ptr<XRubyThread>
437 FrmKameMain::runNewScript(
const XString &label,
const XString &filename) {
438 shared_ptr<XRubyThread> rbthread = m_measure->ruby()->
439 create<XRubyThread>(label.c_str(),
true, filename );
441 m_conRubyThreadList.push_back(xqcon_create<XRubyThreadConnector>(
442 rbthread, form, m_measure->ruby()));
443 addDockableWindow(m_pMdiCentral, form,
true);
446 for(
auto it = m_conRubyThreadList.begin(); it != m_conRubyThreadList.end(); ) {
447 if((*it)->isAlive()) {
451 it = m_conRubyThreadList.erase(it);
456 void FrmKameMain::scriptRunAction_activated() {
457 QString filename = QFileDialog::getOpenFileName (
459 i18n(
"Open Script File"),
460 "KAME Script files (*.seq);;"
461 "Ruby Script files (*.rb)"
463 if( !filename.isEmpty()) {
464 static unsigned int thread_no = 1;
465 runNewScript(formatString(
"Thread%d", thread_no), filename );
470 #define RUBYLINESHELL_FILE "rubylineshell.rb"
472 void FrmKameMain::scriptLineShellAction_activated() {
475 KStandardDirs::locate(
"appdata", RUBYLINESHELL_FILE);
477 QStandardPaths::locate(QStandardPaths::DataLocation, RUBYLINESHELL_FILE);
478 if(filename.isEmpty()) {
480 QDir dir(QApplication::applicationDirPath());
481 #if defined __MACOSX__ || defined __APPLE__
485 QString path = RUBYLINESHELL_DIR RUBYLINESHELL_FILE;
488 filename = dir.absoluteFilePath(path);
491 if(filename.isEmpty()) {
492 g_statusPrinter->printError(
"No KAME ruby support file installed.");
495 static unsigned int int_no = 1;
496 runNewScript(formatString(
"Line Shell%d", int_no), filename );
501 void FrmKameMain::scriptDotSaveAction_activated() {
502 QString filename = QFileDialog::getSaveFileName (
504 i18n(
"Save Graphviz dot File"),
"",
505 "Graphviz dot files (*.dot);;"
508 if( !filename.isEmpty()) {
509 std::ofstream ofs(filename.toLocal8Bit().data(), std::ios::out);
517 void FrmKameMain::fileLogAction_toggled(
bool var) {
518 g_bLogDbgPrint = var;