00001
00022 #include "DGVTableVTK.h"
00023
00024 #include <QModelIndexList>
00025
00026 #include "DGVFile.h"
00027
00028 DGVTableVTK::DGVTableVTK(QWidget *parent) : QTableWidget(parent)
00029 {
00030 complexData = false;
00031 linkedToImage = false;
00032 viewChanging = false;
00033 verboseMode = true;
00034 consoleAssigned = false;
00035 editable = true;
00036
00037 tablePrecision = 8;
00038
00040 createActions();
00041 complexValuedMode(false);
00042
00043 createConnections();
00044
00045 setAlternatingRowColors(true);
00046 setSortingEnabled(false);
00047 }
00048
00049 DGVTableVTK::~DGVTableVTK()
00050 {
00051
00052 }
00053
00054 void DGVTableVTK::setName(QString filename)
00055 {
00056 name = filename;
00057 setWindowTitle(strippedNamePrefix());
00058 }
00059
00060 void DGVTableVTK::setItem(int row, int column, tableType value)
00061 {
00062 QString tmp;
00063
00064 tmp.setNum(value,'g',tablePrecision);
00065 QTableWidgetItem *item = new QTableWidgetItem(tmp);
00066 if(editable)
00067 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled);
00068 else
00069 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
00070 QTableWidget::setItem(row,column,item);
00071 }
00072
00073 void DGVTableVTK::setItem(int row, int column, QString value)
00074 {
00075 QTableWidgetItem *item = new QTableWidgetItem(value);
00076
00077 if(editable)
00078 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled);
00079 else
00080 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
00081 QTableWidget::setItem(row,column,item);
00082 }
00083
00084 tableType DGVTableVTK::getItem(int x, int y)
00085 {
00086 QString tmp;
00087
00088 tmp = QTableWidget::item(x,y)->text();
00089
00090 return tmp.toDouble();
00091 }
00092
00093 void DGVTableVTK::zapSelection()
00094 {
00095 QList<QTableWidgetItem*> selection;
00096
00097 selection = QTableWidget::selectedItems();
00098 for(int j = 0; j < selection.size(); j ++)
00099 selection[j]->setText("0");
00100 }
00101
00102 void DGVTableVTK::delSelection()
00103 {
00104 QList<QTableWidgetSelectionRange> selectedRange;
00105 int size = 0, start = 0;
00106
00107 selectedRange = QTableWidget::selectedRanges();
00108
00109 for(int j = 0; j < selectedRange.size(); j ++)
00110 {
00111 if(selectedRange[j].columnCount() < selectedRange[j].rowCount())
00112 {
00114 size = selectedRange[j].columnCount();
00115 start = selectedRange[j].leftColumn();
00116
00117
00118
00119 for(int j = start; j < size+start; j ++)
00120 QTableWidget::removeColumn(j);
00121 }
00122 else
00123 {
00124 size = selectedRange[j].rowCount();
00125 start = selectedRange[j].topRow();
00126
00127 for(int j = start; j < size+start; j ++)
00128 QTableWidget::removeRow(j);
00129 }
00130 }
00131 }
00132
00133 void DGVTableVTK::plotSelection()
00134 {
00135 Array<Array<tableType,1>,1> selectedData;
00136 Array<Array<tableType,1>,1> selectedDataX;
00137 DGVPlot *tmpPlot = NULL;
00138
00139 selectionToArray(selectedDataX,selectedData);
00140
00141 tmpPlot = new DGVPlot(parentWidget());
00142 tmpPlot->setName("Selection: " + strippedName());
00143
00144 tmpPlot->setData(selectedDataX,selectedData);
00145 tmpPlot->generatePlot();
00146 tmpPlot->show();
00147
00148 emit plotAvailable(tmpPlot);
00149 }
00150
00151 void DGVTableVTK::fftSelection()
00152 {
00153 Array<Array<complex<tableType>,1>,1> selectedData;
00154 Array<Array<tableType,1>,1> selectedDataX;
00155
00156 selectionToArray(selectedDataX,selectedData);
00157
00158 emit fftSelectionAvailable(selectedData);
00159 }
00160
00161 void DGVTableVTK::ifftSelection()
00162 {
00163 Array<Array<complex<tableType>,1>,1> selectedData;
00164 Array<Array<tableType,1>,1> selectedDataX;
00165
00166 selectionToArray(selectedDataX,selectedData);
00167
00168 emit ifftSelectionAvailable(selectedData);
00169 }
00170
00171 void DGVTableVTK::fftRealSelection()
00172 {
00173 Array<Array<tableType,1>,1> selectedData;
00174 Array<Array<tableType,1>,1> selectedDataX;
00175
00176 selectionToArray(selectedDataX,selectedData);
00177
00178 emit fftRealSelectionAvailable(selectedData);
00179 }
00180
00181 void DGVTableVTK::ifftRealSelection()
00182 {
00183 Array<Array<complex<tableType>,1>,1> selectedData;
00184 Array<Array<tableType,1>,1> selectedDataX;
00185
00186 selectionToArray(selectedDataX,selectedData);
00187
00188 emit ifftRealSelectionAvailable(selectedData);
00189 }
00190
00191 void DGVTableVTK::surfacePlotSelection()
00192 {
00193 DGVSurfacePlotVTK *plot = new DGVSurfacePlotVTK(parentWidget());
00194
00195 printWarning("Warning: Surface Plot will only plot entire table.");
00196
00197 plot->setName(name);
00198 if(consoleAssigned)
00199 plot->setConsole(console);
00200 plot->setData(DGVTableVTK::data());
00201 plot->generatePlot();
00202 plot->generateAxes();
00203 plot->show();
00204
00205 emit surfacePlotAvailable(plot);
00206 }
00207
00208 void DGVTableVTK::scanSelection()
00209 {
00210 bool ok;
00211
00212 double interval = QInputDialog::getDouble(this, tr("Scan Interval Time"), tr("Interval (ms):"), 250, 0, 1000000, 1, &ok);
00213
00214 if(ok)
00215 {
00216 DGVAnimatedScan *ani = new DGVAnimatedScan(tableData,"Scan: " + strippedName(),parentWidget());
00217 ani->setTimerInterval(interval);
00218 ani->show();
00219 emit animationAvailable(ani);
00220 }
00221 }
00222
00223 void DGVTableVTK::saveSelection()
00224 {
00225 QFileDialog *fileSaver = new QFileDialog(this);
00226 int size = 0, start = 0, count = 0;
00227
00228 QString filename = fileSaver->getSaveFileName(this,
00229 tr("Select File Name to Save"),
00230 ".",
00231 tr("Data Files (*.csv)"));
00232
00233 if (!filename.isEmpty())
00234 {
00235 QString tmp;
00236 QList<QTableWidgetItem*> selection;
00237 QList<QTableWidgetSelectionRange> selectedRange;
00238
00240 selection = QTableWidget::selectedItems();
00242 selectedRange = QTableWidget::selectedRanges();
00243 printInfo("Selected a total of " + tmp.setNum(selection.size()) + " items.");
00244
00247
00248 printWarning("Bug Warning: If selections not appearing in plot, use Crtl key instead of Shift key.");
00249
00250 DGVFile outFile;
00251 QString line;
00252 bool ok;
00253
00254 QString sep = QInputDialog::getText(this, tr("Values Separator"), tr("Separator (a comma normally): "), QLineEdit::Normal, ",", &ok);
00255 console->printInfo("Separator: " + sep);
00256
00257 outFile.setSeparator(sep);
00258 if(!outFile.open(filename,"w"))
00259 return;
00260
00261 for(int j = 0; j < selectedRange.size(); j ++)
00262 {
00264 if(selectedRange[j].columnCount() < selectedRange[j].rowCount())
00265 {
00266 size = selectedRange[j].rowCount();
00267 start = selectedRange[j].topRow();
00268 }
00269 else
00270 {
00271 size = selectedRange[j].columnCount();
00272 start = selectedRange[j].leftColumn();
00273 }
00274
00275 for(int k = count; k < count+size; k ++)
00276 {
00277 line += selection[k]->text();
00278 line += sep;
00279 }
00280 outFile.writeLine(line);
00281 line.clear();
00282
00283 count += size;
00284 }
00285
00286 outFile.close();
00287 }
00288 }
00289
00290 void DGVTableVTK::saveAll()
00291 {
00292 QFileDialog *fileSaver = new QFileDialog(this);
00293 QString filename = fileSaver->getSaveFileName(this,
00294 tr("Select File Name to Save"),
00295 ".",
00296 tr("Data Files (*.csv)"));
00297
00298 if (!filename.isEmpty())
00299 {
00300 DGVFile outFile;
00301 QString line;
00302 bool ok;
00303
00304 QString sep = QInputDialog::getText(this, tr("Values Separator"), tr("Separator (a comma normally): "), QLineEdit::Normal, ",", &ok);
00305 console->printInfo("Separator: " + sep);
00306
00307 if(ok)
00308 {
00309 outFile.setSeparator(sep);
00310 if(!outFile.open(filename,"w"))
00311 return;
00312
00313 for(int j = 0; j < QTableWidget::rowCount(); j ++)
00314 {
00315 for(int k = 0; k < QTableWidget::columnCount(); k ++)
00316 {
00317 line += item(j,k)->text();
00318 if(k != QTableWidget::columnCount()-1)
00319 line += sep;
00320 }
00321 outFile.writeLine(line);
00322 line.clear();
00323 }
00324
00325 outFile.close();
00326 emit recentFileAvailable(filename);
00327 }
00328 }
00329 }
00330
00331 bool DGVTableVTK::loadCSV(const QString filename)
00332 {
00333 int cols = 0, rows = 1;
00334 DGVFile inFile;
00335 QStringList line;
00336 QString tmp1, tmp2;
00337 bool ok;
00338
00339 printInfo("Detecting CSV File Structure");
00340
00341 QString sep = QInputDialog::getText(this, tr("Values Separator"), tr("Separator (a comma normally): "), QLineEdit::Normal, ",", &ok);
00342 console->printInfo("Separator: " + sep);
00343
00344 if(ok)
00345 {
00346 inFile.setSeparator(sep);
00347 if(!inFile.open(filename,"r"))
00348 return false;
00349
00350 complexValuedMode(false);
00353 line = inFile.readNextLine();
00354 line[line.size()-1].trimmed();
00355 if(line[line.size()-1].isEmpty() || line[line.size()-1] == " ")
00356 line.removeLast();
00357 cols = line.size();
00358
00359 while(!inFile.atEnd())
00360 {
00361 line = inFile.readNextLine();
00362 rows ++;
00363 }
00364 inFile.close();
00365
00367 printInfo("Loading CSV File: " + filename + ", Table Size: " + tmp1.setNum(rows) + "x" + tmp2.setNum(cols));
00368 if(!inFile.open(filename,"r"))
00369 return false;
00370
00371 tableData.resize(rows,cols);
00372 tableData = 0;
00373
00374 setColumnCount(cols);
00375 setRowCount(rows);
00376 setName(filename);
00377
00378 for(int j = 0; j < rows; j ++)
00379 {
00380 line = inFile.readNextLine();
00381 for(int k = 0; k < cols; k ++)
00382 setItem(j,k,line[k]);
00383 qApp->processEvents();
00384 }
00385
00386 inFile.close();
00387 return true;
00388 }
00389 else
00390 return false;
00391 }
00392
00393 void DGVTableVTK::complexValuedMode(bool complexValues)
00394 {
00395 complexData = complexValues;
00396 absoluteMagnitudeAct->setDisabled(!complexValues);
00397 absoluteMagnitudeAct->setChecked(true);
00398 imaginaryPartAct->setDisabled(!complexValues);
00399 realPartAct->setDisabled(!complexValues);
00400 phaseAct->setDisabled(!complexValues);
00401 }
00402
00403 void DGVTableVTK::linkToImageData(bool link)
00404 {
00405 linkedToImage = link;
00406 }
00407
00408 void DGVTableVTK::reload()
00409 {
00410 viewChanging = true;
00411 QProgressDialog progress("Creating Table...", "Abort", 0, tableData.rows()*tableData.cols(), this);
00412 int counter = 0;
00413
00414 progress.setWindowModality(Qt::WindowModal);
00415 setRowCount(tableData.rows());
00416 setColumnCount(tableData.cols());
00417 scheduleDelayedItemsLayout();
00418 for(int j = 0; j < tableData.rows(); j ++)
00419 {
00420 for(int k = 0; k < tableData.cols(); k ++)
00421 {
00422 progress.setValue(counter);
00423 setItem(j,k,tableData(j,k));
00424 counter ++;
00425
00426 if(progress.wasCanceled())
00427 break;
00428 }
00429 if(progress.wasCanceled())
00430 break;
00431
00432 qApp->processEvents();
00433 }
00434 executeDelayedItemsLayout();
00435 progress.setValue(tableData.rows()*tableData.cols());
00436 editable = true;
00437 viewChanging = false;
00438 }
00439
00440 void DGVTableVTK::setData(Array<tableType,2> &values)
00441 {
00442 complexValuedMode(false);
00443 tableData.resize(values.shape());
00444 tableData = values;
00445 reload();
00446 }
00447
00448 void DGVTableVTK::setData(Array<tableType,1> &values)
00449 {
00450 complexValuedMode(false);
00451 tableData.resize(1,values.size());
00452 tableData(0,Range::all()) = values;
00453 reload();
00454 }
00455
00456 void DGVTableVTK::setData(Array<Array<tableType,1>,1> &values)
00457 {
00458 int maxCols = 0, maxItems = 0;
00459
00460 complexValuedMode(false);
00461 for(int j = 0; j < values.size(); j ++)
00462 {
00463 maxItems += values(j).size();
00464 if(values(j).size() > maxCols)
00465 maxCols = values(j).size();
00466 }
00467
00468 tableData.resize(values.size(),maxCols);
00469 tableData = 0;
00470 for(int j = 0; j < values.size(); j ++)
00471 for(int k = 0; k < values(j).size(); k ++)
00472 tableData(j,k) = values(j)(k);
00473 reload();
00474 }
00475
00476 void DGVTableVTK::setData(Array<complex<tableType>,2> &values)
00477 {
00478 complexValuedMode(true);
00479 tableComplexData.resize(values.shape());
00480 tableComplexData = values;
00481 viewMagnitude();
00482 }
00483
00484 void DGVTableVTK::setData(Array<complex<tableType>,1> &values)
00485 {
00486 complexValuedMode(true);
00487 tableComplexData.resize(1,values.size());
00488 tableComplexData(0,Range::all()) = values;
00489 viewMagnitude();
00490 }
00491
00492 void DGVTableVTK::setData(Array< Array<complex<tableType>,1>,1 > &values)
00493 {
00494 int maxCols = 0;
00495
00496 for(int j = 0; j < values.size(); j ++)
00497 if(values(j).size() > maxCols)
00498 maxCols = values(j).size();
00499 tableComplexData.resize(values.size(),maxCols);
00500
00501 complexValuedMode(true);
00502 for(int j = 0; j < values.size(); j ++)
00503 for(int k = 0; k < values(j).size(); k ++)
00504 tableComplexData(j,k) = values(j)(k);
00505 viewMagnitude();
00506 }
00507
00508 void DGVTableVTK::setDataSize(int rows, int cols)
00509 {
00510 if(complexData)
00511 {
00512 tableComplexData.resize(rows,cols);
00513 tableComplexData = 0;
00514 }
00515 else
00516 {
00517 tableData.resize(rows,cols);
00518 tableData = 0;
00519 }
00520 }
00521
00522 Array<tableType,2>& DGVTableVTK::data()
00523 {
00524 return tableData;
00525 }
00526
00527 Array<complex<imageType>,2>& DGVTableVTK::dataComplex()
00528 {
00529 return tableComplexData;
00530 }
00531
00532 Array<imageType,2>& DGVTableVTK::dataViewing()
00533 {
00534 if(!complexData)
00535 return data();
00536
00537 tableData.resize(tableComplexData.shape());
00538 if(absoluteMagnitudeAct->isChecked())
00539 {
00540 tableData = abs(tableComplexData);
00541 return tableData;
00542 }
00543 else if(imaginaryPartAct->isChecked())
00544 {
00545 tableData = imag(tableComplexData);
00546 return tableData;
00547 }
00548 else if(realPartAct->isChecked())
00549 {
00550 tableData = real(tableComplexData);
00551 return tableData;
00552 }
00553 else if(phaseAct->isChecked())
00554 {
00555 tableData = arg(tableComplexData);
00556 return tableData;
00557 }
00558 else
00559 return tableData;
00560 }
00561
00562 void DGVTableVTK::refresh()
00563 {
00564 printInfo("Refreshing Table: " + strippedName());
00566 QTableWidget::clear();
00567 dataViewing();
00568 if(complexData)
00569 {
00570 if(absoluteMagnitudeAct->isChecked())
00571 {
00572 editable = false;
00573 setWindowTitle(strippedNamePrefix() + "[Abs]");
00574 }
00575 else if(imaginaryPartAct->isChecked())
00576 {
00577 editable = true;
00578 setWindowTitle(strippedNamePrefix() + "[Imag]");
00579 }
00580 else if(realPartAct->isChecked())
00581 {
00582 editable = true;
00583 setWindowTitle(strippedNamePrefix() + "[Real]");
00584 }
00585 else if(phaseAct->isChecked())
00586 {
00587 editable = false;
00588 setWindowTitle(strippedNamePrefix() + "[Phase]");
00589 }
00590 }
00591 reload();
00592 }
00593
00594 void DGVTableVTK::renameData()
00595 {
00596 bool ok;
00597
00598 QString newName = QInputDialog::getText(this, tr("Rename Data"), tr("New Name: "), QLineEdit::Normal, name, &ok);
00599
00600 if(ok)
00601 setName(newName);
00602 }
00603
00604 void DGVTableVTK::updateData(int row, int col)
00605 {
00606
00607 if(!viewChanging)
00608 {
00609 if(!complexData)
00610 tableData(row,col) = item(row,col)->text().toDouble();
00611 else
00612 {
00613 tableType tmpValue;
00614
00615 if(imaginaryPartAct->isChecked())
00616 {
00617 tmpValue = tableComplexData(row,col).real();
00618 tableComplexData(row,col) = complex<tableType>(tmpValue,item(row,col)->text().toDouble());
00619 }
00620 else if(realPartAct->isChecked())
00621 {
00622 tmpValue = tableComplexData(row,col).imag();
00623 tableComplexData(row,col) = complex<tableType>(item(row,col)->text().toDouble(),tmpValue);
00624 }
00625 else if(absoluteMagnitudeAct->isChecked() || phaseAct->isChecked())
00626 printWarning("Ignoring changes to Absolute Magnitude and Phase. Please make changes in Imaginary and Real parts.");
00627 }
00628 }
00629 }
00630
00631 QString DGVTableVTK::strippedName()
00632 {
00633 return QFileInfo(name).fileName();
00634 }
00635
00636 QString DGVTableVTK::strippedNamePrefix()
00637 {
00638 return "Table: " + QFileInfo(name).fileName();
00639 }
00640
00641 void DGVTableVTK::addToContextMenu(QVector<QMenu*> &menus)
00642 {
00643 menusToAdd = menus;
00644 }
00645
00646 void DGVTableVTK::setConsole(DGVConsole *newConsole)
00647 {
00648 if(newConsole != NULL)
00649 {
00650 console = newConsole;
00651 consoleAssigned = true;
00652 }
00653 }
00654
00655 void DGVTableVTK::addContextMenuExtras()
00656 {
00657 for(int j = 0; j < menusToAdd.size(); j ++)
00658 contextMenu->addAction(menusToAdd[j]->menuAction());
00659 }
00660
00661 void DGVTableVTK::contextMenuEvent(QContextMenuEvent *event)
00662 {
00663 contextMenu = new QMenu(this);
00664 selectGroup = new QActionGroup(this);
00665 globalGroup = new QActionGroup(this);
00666
00668 addContextMenuExtras();
00669
00671 contextMenu->addSeparator();
00672 surfacePlotAct = contextMenu->addAction(tr("Surface Plot"));
00673 surfacePlotAct->setToolTip("Surface Plot based on scalar warping");
00674 surfacePlotAct->setStatusTip("Surface Plot based on scalar warping");
00675 globalGroup->addAction(surfacePlotAct);
00676 surfacePlotAct->setShortcut(tr("Ctrl+p"));
00677
00678 scanAct = contextMenu->addAction(tr("Scan"));
00679 scanAct->setToolTip("1D Plot Scan/Animation through the rows of the table");
00680 scanAct->setStatusTip("1D Plot Scan/Animation through the rows of the table");
00681 globalGroup->addAction(scanAct);
00682 scanAct->setShortcut(tr("Ctrl+a"));
00683
00684 contextMenu->addSeparator()->setText("Selection");
00685
00687 zapAct = contextMenu->addAction(tr("Zap to Zero"));
00688 zapAct->setToolTip("Set the selection value to zero, i.e., zap the data");
00689 zapAct->setStatusTip("Set the selection value to zero, i.e., zap the data");
00690 selectGroup->addAction(zapAct);
00691 zapAct->setShortcut(tr("Ctrl+z"));
00692
00693 delAct = contextMenu->addAction(tr("Delete"));
00694 selectGroup->addAction(delAct);
00695 delAct->setShortcut(tr("Ctrl+d"));
00696
00697 plotAct = contextMenu->addAction(tr("1D Plot"));
00698 plotAct->setToolTip("1D Line Plot of the selection");
00699 plotAct->setStatusTip("1D Line Plot of the selection");
00700 selectGroup->addAction(plotAct);
00701 plotAct->setShortcut(tr("Ctrl+Shift+p"));
00702
00703 fft_1DAct = contextMenu->addAction(tr("&1D FFT"));
00704 fft_1DAct->setToolTip("1D Fast Fourier Transform (FFT) on selection");
00705 fft_1DAct->setStatusTip("1D Fast Fourier Transform (FFT) on selection");
00706 selectGroup->addAction(fft_1DAct);
00707 fft_1DAct->setShortcut(tr("Ctrl+f"));
00708 fft_1DAct->setDisabled(!complexData);
00709
00710 ifft_1DAct = contextMenu->addAction(tr("&1D iFFT"));
00711 ifft_1DAct->setToolTip("1D Fast Fourier Transform (iFFT) on selection");
00712 ifft_1DAct->setStatusTip("1D Fast Fourier Transform (iFFT) on selection");
00713 selectGroup->addAction(ifft_1DAct);
00714 ifft_1DAct->setShortcut(tr("Ctrl+i"));
00715 ifft_1DAct->setDisabled(!complexData);
00716
00717 fft_Real_1DAct = contextMenu->addAction(tr("&1D Real2Complex FFT"));
00718 fft_Real_1DAct->setToolTip("1D Real to Complex Fast Fourier Transform (FFT) on selection");
00719 fft_Real_1DAct->setStatusTip("1D Real to Complex Fast Fourier Transform (FFT) on selection");
00720 selectGroup->addAction(fft_Real_1DAct);
00721 fft_Real_1DAct->setShortcut(tr("Ctrl+Shift+f"));
00722 fft_Real_1DAct->setDisabled(complexData);
00723
00724 ifft_Real_1DAct = contextMenu->addAction(tr("&1D Complex2Real iFFT"));
00725 ifft_Real_1DAct->setToolTip("1D Complex to Real Fast Fourier Transform (iFFT) on selection");
00726 ifft_Real_1DAct->setStatusTip("1D Complex to Real Fast Fourier Transform (iFFT) on selection");
00727 selectGroup->addAction(ifft_Real_1DAct);
00728 ifft_Real_1DAct->setShortcut(tr("Ctrl+Shift+i"));
00729 ifft_Real_1DAct->setDisabled(!complexData);
00730
00732 contextMenu->addSeparator()->setText(tr("Complex View"));
00734 contextMenu->addAction(absoluteMagnitudeAct);
00736 contextMenu->addAction(imaginaryPartAct);
00738 contextMenu->addAction(realPartAct);
00740 contextMenu->addAction(phaseAct);
00741 complexGroup->setDisabled(!complexData);
00742
00744 contextMenu->addSeparator();
00745 fitColsAct = contextMenu->addAction(tr("Resize Columns to Content"));
00746 fitRowsAct = contextMenu->addAction(tr("Resize Rows to Content"));
00747 contextMenu->addSeparator();
00748
00750 saveAct = contextMenu->addAction(tr("Save Selection"));
00751
00752 saveAct->setDisabled(true);
00753 saveAllAct = contextMenu->addAction(tr("Save Entire Table"));
00754 saveAllAct->setShortcut(tr("Ctrl+Shift+s"));
00756 refreshAct = contextMenu->addAction(tr("Refresh"));
00757 refreshAct->setShortcut(tr("F5"));
00758 renameAct = contextMenu->addAction(tr("Rename"));
00759 renameAct->setShortcut(tr("Ctrl+r"));
00760 closeAct = contextMenu->addAction(tr("Close"));
00761 closeAct->setShortcut(tr("Ctrl+w"));
00762
00763 connect(zapAct, SIGNAL(triggered()), this, SLOT(zapSelection()));
00764 connect(delAct, SIGNAL(triggered()), this, SLOT(delSelection()));
00765 connect(plotAct, SIGNAL(triggered()), this, SLOT(plotSelection()));
00766 connect(fft_1DAct, SIGNAL(triggered()), this, SLOT(fftSelection()));
00767 connect(ifft_1DAct, SIGNAL(triggered()), this, SLOT(ifftSelection()));
00768 connect(fft_Real_1DAct, SIGNAL(triggered()), this, SLOT(fftRealSelection()));
00769 connect(ifft_Real_1DAct, SIGNAL(triggered()), this, SLOT(ifftRealSelection()));
00770 connect(surfacePlotAct, SIGNAL(triggered()), this, SLOT(surfacePlotSelection()));
00771 connect(scanAct, SIGNAL(triggered()), this, SLOT(scanSelection()));
00772 connect(fitColsAct, SIGNAL(triggered()), this, SLOT(resizeColumnsToContents()));
00773 connect(fitRowsAct, SIGNAL(triggered()), this, SLOT(resizeRowsToContents()));
00774 connect(saveAct, SIGNAL(triggered()), this, SLOT(saveSelection()));
00775 connect(saveAllAct, SIGNAL(triggered()), this, SLOT(saveAll()));
00776 connect(refreshAct, SIGNAL(triggered()), this, SLOT(refresh()));
00777 connect(renameAct, SIGNAL(triggered()), this, SLOT(renameData()));
00778 connect(closeAct, SIGNAL(triggered()), this, SLOT(close()));
00779
00780 contextMenu->exec(event->globalPos());
00781 }
00782
00783 void DGVTableVTK::createConnections()
00784 {
00785 connect(this, SIGNAL(cellChanged(int,int)), this, SLOT(updateData(int,int)));
00786 connect(absoluteMagnitudeAct, SIGNAL(triggered()), this, SLOT(refresh()));
00787 connect(imaginaryPartAct, SIGNAL(triggered()), this, SLOT(refresh()));
00788 connect(realPartAct, SIGNAL(triggered()), this, SLOT(refresh()));
00789 connect(phaseAct, SIGNAL(triggered()), this, SLOT(refresh()));
00790 }
00791
00792 void DGVTableVTK::createActions()
00793 {
00794 absoluteMagnitudeAct = new QAction(this);
00795 absoluteMagnitudeAct->setText(QApplication::translate("Table", "Absolute &Magnitude", 0, QApplication::UnicodeUTF8));
00796 absoluteMagnitudeAct->setShortcut(tr("Alt+m"));
00797 absoluteMagnitudeAct->setCheckable(true);
00798
00799 imaginaryPartAct = new QAction(this);
00800 imaginaryPartAct->setText(QApplication::translate("Table", "&Imaginary Part", 0, QApplication::UnicodeUTF8));
00801 imaginaryPartAct->setShortcut(tr("Alt+i"));
00802 imaginaryPartAct->setCheckable(true);
00803
00804 realPartAct = new QAction(this);
00805 realPartAct->setText(QApplication::translate("Table", "&Real Part", 0, QApplication::UnicodeUTF8));
00806 realPartAct->setShortcut(tr("Alt+r"));
00807 realPartAct->setCheckable(true);
00808
00809 phaseAct = new QAction(this);
00810 phaseAct->setText(QApplication::translate("Table", "&Phase/Argument", 0, QApplication::UnicodeUTF8));
00811 phaseAct->setShortcut(tr("Alt+p"));
00812 phaseAct->setCheckable(true);
00813
00814 complexGroup = new QActionGroup(this);
00815
00816 complexGroup->addAction(absoluteMagnitudeAct);
00817 complexGroup->addAction(imaginaryPartAct);
00818 complexGroup->addAction(realPartAct);
00819 complexGroup->addAction(phaseAct);
00820 complexGroup->setDisabled(!complexData);
00821 }
00822
00823 void DGVTableVTK::selectionToArray(Array<Array<tableType,1>,1> &xData, Array<Array<tableType,1>,1> &selectedData)
00824 {
00825 QList<QTableWidgetItem*> selection;
00826 QList<QTableWidgetSelectionRange> selectedRange;
00827 int size = 0, start = 0, count = 0;
00828
00830 selection = QTableWidget::selectedItems();
00832 selectedRange = QTableWidget::selectedRanges();
00834
00835 printWarning("Bug Warning!: If selections do not appear in operations, use Crtl key instead of Shift key.");
00837 if(selectedRange.size() == 1 && selection.size() != rowCount() && selection.size() != columnCount())
00838 {
00840 printWarning("Detected a large continuous selection.");
00841
00842 bool rowsOk;
00843
00844 printWarning("Applying operation row/column-wise. Enter the size of the ordering.");
00845 int mod = QInputDialog::getInteger(this, tr("Row/Column Length"),
00846 tr("Row/Column Length of Data:"), columnCount(), 0, columnCount()*rowCount(), 1, &rowsOk);
00847
00848 if(rowsOk && mod <= selection.size())
00849 {
00850 int noOfRows = static_cast<int>(selection.size()/mod);
00851
00853 selectedData.resizeAndPreserve(noOfRows);
00854 xData.resizeAndPreserve(noOfRows);
00855
00856 for(int j = 0; j < noOfRows; j ++)
00857 {
00858 selectedData(j).resizeAndPreserve(mod);
00859 xData(j).resizeAndPreserve(mod);
00860 for(int k = 0; k < mod; k ++)
00861 {
00862 selectedData(j)(k) = selection[j*mod+k]->text().toDouble();
00863 xData(j)(k) = k;
00864 }
00865 }
00866 }
00867 }
00868 else
00869 {
00870 printWarning("Detected a fragmented or full selection. Applying operation one at a time.");
00872 selectedData.resizeAndPreserve(selectedRange.size());
00873 xData.resizeAndPreserve(selectedRange.size());
00874 for(int j = 0; j < selectedRange.size(); j ++)
00875 {
00877 if(selectedRange[j].columnCount() < selectedRange[j].rowCount())
00878 {
00879 size = selectedRange[j].rowCount();
00880 start = selectedRange[j].topRow();
00881 }
00882 else
00883 {
00884 size = selectedRange[j].columnCount();
00885 start = selectedRange[j].leftColumn();
00886 }
00887
00888 selectedData(j).resizeAndPreserve(size);
00889 xData(j).resizeAndPreserve(size);
00890 for(int k = count; k < count+size; k ++)
00891 {
00892 selectedData(j)(k-count) = selection[k]->text().toDouble();
00893 xData(j)(k-count) = start+(k-count);
00894 }
00895 count += size;
00896 }
00897 }
00898 }
00899
00900 void DGVTableVTK::selectionToArray(Array<Array<tableType,1>,1> &xData, Array<Array<complex<tableType>,1>,1> &selectedData)
00901 {
00902 QList<QTableWidgetItem*> selection;
00903 QList<QTableWidgetSelectionRange> selectedRange;
00904 int size = 0, start = 0, count = 0;
00905
00906
00907
00909
00911
00912
00914
00915
00916
00918
00919
00921
00922
00923
00924
00925
00926
00927
00928
00929
00930
00931
00932
00933
00934
00935
00936
00937
00938
00939
00940
00941
00943 selection = QTableWidget::selectedItems();
00945 selectedRange = QTableWidget::selectedRanges();
00948
00949 printWarning("Bug Warning!: If selections do not appear in operations, use Crtl key instead of Shift key.");
00951 if(selectedRange.size() == 1 && selection.size() != rowCount() && selection.size() != columnCount())
00952 {
00954 printWarning("Detected a large continuous selection.");
00955
00956 bool rowsOk;
00957
00958 printWarning("Applying operation row/column-wise. Enter the size of the ordering.");
00959 int mod = QInputDialog::getInteger(this, tr("Row/Column Length"),
00960 tr("Row/Column Length of Data:"), rowCount(), 0, columnCount()*rowCount(), 1, &rowsOk);
00961
00962 if(rowsOk && mod <= selection.size())
00963 {
00964 int noOfRows = static_cast<int>(selection.size()/mod);
00965
00967 selectedData.resizeAndPreserve(noOfRows);
00968 xData.resizeAndPreserve(noOfRows);
00969
00970 for(int j = 0; j < noOfRows; j ++)
00971 {
00972 selectedData(j).resizeAndPreserve(mod);
00973 xData(j).resizeAndPreserve(mod);
00974 for(int k = 0; k < mod; k ++)
00975 {
00976 selectedData(j)(k) = tableComplexData(j,k);
00977 xData(j)(k) = k;
00978 }
00979 }
00980 }
00981 }
00982 else
00983 {
00984 printWarning("Detected a fragmented or full selection. Applying operation one at a time.");
00986 selectedData.resizeAndPreserve(selectedRange.size());
00987 xData.resizeAndPreserve(selectedRange.size());
00988 for(int j = 0; j < selectedRange.size(); j ++)
00989 {
00991 if(selectedRange[j].columnCount() < selectedRange[j].rowCount())
00992 {
00993 size = selectedRange[j].rowCount();
00994 start = selectedRange[j].topRow();
00995 }
00996 else
00997 {
00998 size = selectedRange[j].columnCount();
00999 start = selectedRange[j].leftColumn();
01000 }
01001
01002 selectedData(j).resizeAndPreserve(size);
01003 xData(j).resizeAndPreserve(size);
01004 for(int k = count; k < count+size; k ++)
01005 {
01006 selectedData(j)(k-count) = tableComplexData(j,k);
01007 xData(j)(k-count) = start+(k-count);
01008 }
01009 count += size;
01010 }
01011 }
01012 }
01013
01014 void DGVTableVTK::printError(QString msg)
01015 {
01016 if(verboseMode)
01017 {
01018 if(consoleAssigned)
01019 {
01020 console->printError(msg);
01021 }
01022 else
01023 cerr << msg.toStdString() << endl;
01024 }
01025 }
01026
01027 void DGVTableVTK::printWarning(QString msg)
01028 {
01029 if(verboseMode)
01030 {
01031 if(consoleAssigned)
01032 {
01033 console->printWarning(msg);
01034 }
01035 else
01036 cerr << msg.toStdString() << endl;
01037 }
01038 }
01039
01040 void DGVTableVTK::printInfo(QString msg)
01041 {
01042 if(verboseMode)
01043 {
01044 if(consoleAssigned)
01045 {
01046 console->printInfo(msg);
01047 }
01048 else
01049 cerr << msg.toStdString() << endl;
01050 }
01051 }