diff --git a/cd_utils/cdutils_k_parser.cpp b/cd_utils/cdutils_k_parser.cpp index df306f2..609c003 100644 --- a/cd_utils/cdutils_k_parser.cpp +++ b/cd_utils/cdutils_k_parser.cpp @@ -122,11 +122,14 @@ KSection KParser::parse(PIIODevice * d) { //piCout << "insert" << alias << iarr; int aval = enum_values.value(alias); KSection is = sections.value(iarr.take_front()), ts; + int ibpos = is.name.size_s(); piForeachRC (PIString & a, iarr) { PIVector evals = enumValues(a, sections); //piCout << a << evals; piForeachC (int e, evals) ts.section(e) = is; + ts.name = is.name; + ts.name.insert(ibpos, PIString("[") << evals.size_s() << "]"); is = ts; ts = KSection(); } diff --git a/cd_utils/pult/CMakeLists.txt b/cd_utils/pult/CMakeLists.txt new file mode 100644 index 0000000..3a05de5 --- /dev/null +++ b/cd_utils/pult/CMakeLists.txt @@ -0,0 +1,61 @@ +project(cd_pult) +cmake_minimum_required(VERSION 2.6) +if (NOT LIBPROJECT) + find_package(PIP REQUIRED) +endif () +if (MINGW) + find_package(MinGW REQUIRED) +endif() +find_package(Qt4 REQUIRED) +find_package(OpenGL REQUIRED) +include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR} ${PIP_INCLUDES} ${QT_INCLUDES}) +add_definitions(-DCDPULT) +file(GLOB CPPS "*.cpp") +file(GLOB MOCS "*.h") +file(GLOB UIS "*.ui") +file(GLOB RES "*.qrc") +qt4_wrap_cpp(CMOCS ${MOCS} OPTIONS -nw) +qt4_wrap_ui(CUIS ${UIS}) +qt4_add_resources(RESS ${RES}) +add_executable(${PROJECT_NAME} ${CPPS} ${CMOCS} ${CUIS} ${RESS} ${MOCS}) +set(LIBS ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} ${QT_QTOPENGL_LIBRARY} ${OPENGL_LIBRARIES} ${PIP_LIBRARY} qad_graphic qad_utils qad_widgets) +target_link_libraries(${PROJECT_NAME} ${LIBS} cd_utils) + +# if (NOT DEFINED ENV{QNX_HOST}) + # if (PULT) + # find_package(Qt4 REQUIRED) + # find_package(OpenGL REQUIRED) + # include_directories(${QT_INCLUDES}) + # set(CPPS "kx_pult.cpp" "kx_pult.h" "kx_pult.ui" "main_kx_pult.cpp") + # set(MOCS "kx_pult.h") + # file(GLOB UIS "*.ui") + # file(GLOB RES "*.qrc") + # qt4_wrap_cpp(CMOCS ${MOCS} OPTIONS -nw) + # qt4_wrap_ui(CUIS ${UIS}) + # qt4_add_resources(RESS ${RES}) + # add_executable(${KX_PULT_NAME} WIN32 ${CPPS} ${CMOCS} ${CUIS} ${RESS} ${MOCS}) + # set(LIBS ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} ${QT_QTOPENGL_LIBRARY} ${OPENGL_LIBRARIES} ${PIP_LIBRARY} qad_graphic qad_utils qad_widgets) + # target_link_libraries(${KX_PULT_NAME} ${LIBS} ${PROJECT_NAME}) + # endif () +# endif () +# if (LIB) + # if (WIN32) + # set(CMAKE_INSTALL_PREFIX ${MINGW_DIR}) + # install(FILES ${HDRS_UTILS} DESTINATION ${MINGW_INCLUDE}) + # install(TARGETS ${PROJECT_NAME} DESTINATION ${MINGW_LIB}) + # install(TARGETS ${PROJECT_NAME} DESTINATION ${MINGW_BIN}) + # else () + # set(CMAKE_INSTALL_PREFIX /usr) + # install(FILES ${HDRS_UTILS} DESTINATION ${CMAKE_INSTALL_PREFIX}/include) + # install(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_PREFIX}/lib) + # endif () + # message(STATUS "Install to system \"${CMAKE_INSTALL_PREFIX}\"") +# else () + # install(TARGETS ${PROJECT_NAME} DESTINATION bin) + # message(STATUS "Install to local \"bin\"") +# endif () +# if (NOT DEFINED ENV{QNX_HOST}) + # if (KX_PULT) + # install(TARGETS ${KX_PULT_NAME} DESTINATION ${CMAKE_INSTALL_PREFIX}/bin) + # endif () +# endif () diff --git a/cd_utils/pult/cd_pult.conf b/cd_utils/pult/cd_pult.conf new file mode 100644 index 0000000..e69de29 diff --git a/cd_utils/pult/cd_pult.cpp b/cd_utils/pult/cd_pult.cpp new file mode 100644 index 0000000..3f5c228 --- /dev/null +++ b/cd_utils/pult/cd_pult.cpp @@ -0,0 +1,541 @@ +#include +#include +#include +#include "cd_pult.h" +#include "ui_cd_pult.h" +#include "piqt.h" +#include "qpiconfig.h" + + +CD_Pult::CD_Pult(): QMainWindow(), config_("cd_pult.conf"), +config(piqt(config_), QIODevice::ReadWrite) { + //cout << sizeof(coeffsK.k_protocol->to_k) << endl; + ui = new Ui::CD_Pult(); + ui->setupUi(this); + ui->configWidget->setQPIConfig(&config); + ui->configWidget->expandAll(); + ui->list->viewport()->installEventFilter(this); + ui->treeK->viewport()->installEventFilter(this); + ui->scrollArea->setAutoFillBackground(false); + ui->scrollAreaWidgetContents->setAutoFillBackground(false); + ui->widget->setAutoFillBackground(false); + log_menu.addAction(ui->actionClear); + show_x = config.getValue("show_x", true); + if (!show_x) + ui->tabWidget->removeTab(1); + session.setFile("session_cd_pult.conf"); + session.addEntry(this); + session.addEntry(ui->tabWidget); + session.addEntry(ui->checkKHideNormal); + session.addEntry(ui->checkKHideExpressions); + session.addEntry(ui->checkKAutoCalculate); + needWrite = isPause = false; + timer = 0; + //x.resize(KX_X_PACKET_NUM); + //k.resize(K_NUM); + QPalette pal = palette(); + QColor col; + ui->graphic->setGraphicsCount(0); + //renew(); + ui->treeK->setColumnWidth(0, 60); + ui->treeK->setColumnWidth(1, 250); + ui->treeK->setColumnWidth(3, 100); + ui->treeK->setColumnWidth(4, 100); + //ui->table->setK(coeffsK.k()->data(), coeffsK.count()); + //addToList(trUtf8("Read K file \"%1\": %2 coeffs, %3 bytes").arg(PI2QString(coeffs.fileName())).arg(K.size_s()).arg(coeffs.k_content.size_s()), Qt::darkMagenta); + /*CONNECT(void, &coeffs, sendFailed, this, pip_sendFailed); + CONNECT(void, &coeffs, sendSucceed, this, pip_sendSucceed); + CONNECT(void, &coeffs, receiveFailed, this, pip_receiveFailed); + CONNECT(void, &coeffs, receiveSucceed, this, pip_receiveSucceed);*/ + connect(this, SIGNAL(q_k_sendFailed()), this, SLOT(k_sendFailed()), Qt::QueuedConnection); + connect(this, SIGNAL(q_k_sendSucceed()), this, SLOT(k_sendSucceed()), Qt::QueuedConnection); + connect(this, SIGNAL(q_k_receiveFailed()), this, SLOT(k_receiveFailed()), Qt::QueuedConnection); + connect(this, SIGNAL(q_k_receiveSucceed()), this, SLOT(k_receiveSucceed()), Qt::QueuedConnection); + connect(&timer_diag, SIGNAL(timeout()), this, SLOT(updateDiag())); + connect(&session, SIGNAL(loading(QPIConfig&)), this, SLOT(loading(QPIConfig&))); + connect(&session, SIGNAL(saving(QPIConfig&)), this, SLOT(saving(QPIConfig&))); + connect(ui->checkKHideNormal, SIGNAL(toggled(bool)), this, SLOT(filterTree())); + connect(ui->checkKHideExpressions, SIGNAL(toggled(bool)), this, SLOT(filterTree())); + connect(ui->lineKSearch, SIGNAL(textChanged(QString)), this, SLOT(filterTree())); + session.load(); + updateKDesc(); + updateCDesc(); + timer_diag.start(40); +} + + +CD_Pult::~CD_Pult() { + session.save(); +} + + +void CD_Pult::loading(QPIConfig & conf) { + kdesc_file = conf.getValue("kdesc_file").stringValue(); + cdesc_file = conf.getValue("cdesc_file").stringValue(); +} + + +void CD_Pult::saving(QPIConfig & conf) { + conf.setValue("kdesc_file", kdesc_file); + conf.setValue("cdesc_file", cdesc_file); +} + + +bool CD_Pult::eventFilter(QObject * o, QEvent * e) { + if (o == ui->list->viewport()) { + if (e->type() == QEvent::ContextMenu) { + clear_target = 0; + log_menu.popup(((QContextMenuEvent*)e)->globalPos()); + } + return QMainWindow::eventFilter(o, e); + } + if (o == ui->treeK->viewport()) { + if (e->type() == QEvent::ContextMenu) { + clear_target = 1; + log_menu.popup(((QContextMenuEvent*)e)->globalPos()); + } + return QMainWindow::eventFilter(o, e); + } + int ind = o->property("index").toInt(); + //qDebug() << "event" << i << e->type(); + switch (e->type()) { + case QEvent::Enter: + ui->graphic->setAutoUpdate(false); + //for (int i = 0; i < KX_X_PACKET_NUM; ++i) + // ui->graphic->setGraphicLineWidth(ind == i ? 3. : 1., i); + ui->graphic->setAutoUpdate(true); + ui->graphic->update(); + break; + case QEvent::Leave: + ui->graphic->setAutoUpdate(false); + //for (int i = 0; i < KX_X_PACKET_NUM; ++i) + // ui->graphic->setGraphicLineWidth(1., i); + ui->graphic->setAutoUpdate(true); + ui->graphic->update(); + break; + default: break; + } + return QMainWindow::eventFilter(o, e); +} + + +void CD_Pult::timerEvent(QTimerEvent * e) { + /*if (e->timerId() == timer_update) { + if (need_update) { + need_update = false; + ui->graphic->updateGraphics(); + } + }*/ + if (e->timerId() == timer) { + static QString sPI = QString::number(atan(1) * 4., 'f', 14).leftJustified(14); + static int cnt = 0; + int si = qMax(cnt - 6, 0); + ++cnt; + cnt %= 23; + ui->labelWait->setText(QString(si, QChar(' ')) + sPI.mid(cnt - 6, 6).trimmed()); + //if (!coeffs.isReady()) return; + //ui->table->setK(coeffsK.k()->data(), coeffsK.count()); + //ui->table->showK(); + } +} + + +void CD_Pult::addToList(const QString & s, const QColor & c) { + ui->list->addItem(QDateTime::currentDateTime().toString("dd/MM/yyyy hh:ss - ") + s); + ui->list->item(ui->list->count() - 1)->setTextColor(c); + ui->list->scrollToBottom(); +} + + +void CD_Pult::on_actionClear_triggered() { + switch (clear_target) { + case 0: + ui->list->clear(); + break; + case 1: + clearSelected(); + break; + default: break; + } +} + + +void CD_Pult::clearSelected() { + QList si = ui->treeK->selectedItems(); + ui->treeK->setUpdatesEnabled(false); + ui->treeK->blockSignals(true); + foreach (QTreeWidgetItem * i, si) { + int ki = i->text(0).toInt(); + i->setText(2, ""); + //coeffs.setFormula(ki, ""); + } + ui->treeK->blockSignals(false); + ui->treeK->setUpdatesEnabled(true); + if (ui->checkKAutoCalculate->isChecked()) { + QApplication::processEvents(); + //calculate(); + } +} + + +QString CD_Pult::typeName(const QString & n) const { + if (n.isEmpty()) return ""; + switch (n[0].toLatin1()) { + case 'l': return trUtf8("list"); break; + case 'b': return trUtf8("bool"); break; + case 'n': return trUtf8("int"); break; + case 'f': return trUtf8("double"); break; + case 'c': return trUtf8("color"); break; + case 'r': return trUtf8("rect"); break; + case 'a': return trUtf8("rect"); break; + case 'p': return trUtf8("point"); break; + case 'v': return trUtf8("vector"); break; + case 'i': return trUtf8("IP"); break; + case 'e': return trUtf8("enum"); break; + case 'F': return trUtf8("file"); break; + case 'D': return trUtf8("dir"); break; + } + return ""; +} + + +void CD_Pult::makeTreeSection(KSection & ks, QTreeWidgetItem * pi) { + PIMap::iterator ki; + for (ki = ks.k.begin(); ki != ks.k.end(); ++ki) { + QTreeWidgetItem * ti = new QTreeWidgetItem(pi); + const KType & ck(ki.value()); + ti->setText(0, QString::number(ck.index())); + ti->setText(1, PI2QString(ck.name())); + ti->setText(2, PI2QString(ck.formula())); + ti->setText(4, PI2QString(ck.comment())); + } + PIMap::iterator si; + for (si = ks.s.begin(); si != ks.s.end(); ++si) { + QTreeWidgetItem * ti = new QTreeWidgetItem(pi); + const KSection & cs(si.value()); + ti->setText(0, QString("[%1]").arg(si.key())); + ti->setText(1, PI2QString(cs.name)); + makeTreeSection(const_cast(cs), ti); + } +} + + +void CD_Pult::received(bool ok) { + if (!ok) return; +} + + +void CD_Pult::on_treeK_itemClicked(QTreeWidgetItem * item, int column) { + Qt::ItemFlags f = Qt::ItemIsEnabled | Qt::ItemIsSelectable; + if (column == 2) f |= Qt::ItemIsEditable; + item->setFlags(f); +} + + +void CD_Pult::on_treeK_itemChanged(QTreeWidgetItem * item, int column) { + if (column != 2) return; + int ki = item->text(0).toInt(); + //coeffs.setFormula(ki, piqt(item->text(column))); + if (ui->checkKAutoCalculate->isChecked()) + ;//calculate(); +} + + +void CD_Pult::on_buttonSendK_clicked() { + on_buttonWrite_clicked(); + //coeffs.sendCoeffs(); + if (timer != 0) killTimer(timer); + timer = startTimer(100); +} + + +void CD_Pult::on_buttonReceiveK_clicked() { + //coeffs.receiveCoeffs(); + if (timer != 0) killTimer(timer); + timer = startTimer(100); +} + + +void CD_Pult::on_buttonShowAll_clicked() { + /*for (int i = 0; i < KX_X_PACKET_NUM; ++i) { + checks[i]->check.setChecked(true); + //ui->graphic->setGraphicVisible(true, i); + }*/ +} + + +void CD_Pult::on_buttonHideAll_clicked() { + /*for (int i = 0; i < KX_X_PACKET_NUM; ++i) { + checks[i]->check.setChecked(false); + //ui->graphic->setGraphicVisible(false, i); + }*/ +} + + +void CD_Pult::on_buttonRead_clicked() { + //coeffs.readCoeffs(); + //addToList(trUtf8("Read K file \"%1\": %2 coeffs, %3 bytes").arg(PI2QString(coeffs.fileName())).arg(K.size_s()).arg(coeffs.k_content.size_s()), Qt::darkMagenta); + updateTree(); +} + + +void CD_Pult::on_buttonWrite_clicked() { + //coeffs.writeCoeffs(); + //addToList(trUtf8("Write K file \"%1\": %2 coeffs, %3 bytes").arg(PI2QString(coeffs.fileName())).arg(K.size_s()).arg(coeffs.k_content.size_s()), Qt::darkMagenta); +} + + +void CD_Pult::on_buttonSetKDesc_clicked() { + QString ret = QFileDialog::getOpenFileName(this, trUtf8("Select *.h file with K description"), kdesc_file, "C/C++ header files(*.h *.hpp);;All files(*)"); + if (ret.isEmpty()) return; + kdesc_file = QDir::current().relativeFilePath(ret); + PIFile f(Q2PIString(kdesc_file), PIIODevice::ReadOnly); + K.update(&f); + updateKDesc(true); +} + + +void CD_Pult::on_buttonSetCDesc_clicked() { + QString ret = QFileDialog::getOpenFileName(this, trUtf8("Select *.h file with C description"), cdesc_file, "C/C++ header files(*.h *.hpp);;All files(*)"); + if (ret.isEmpty()) return; + cdesc_file = QDir::current().relativeFilePath(ret); + updateCDesc(); +} + + +void CD_Pult::k_sendFailed() { + stopWait(); + addToList(trUtf8("K not sended"), Qt::darkRed); +} + + +void CD_Pult::k_sendSucceed() { + stopWait(); + addToList(trUtf8("K sended"), Qt::darkGreen); +} + + +void CD_Pult::k_receiveFailed() { + stopWait(); + addToList(trUtf8("K not received"), Qt::darkRed); +} + + +void CD_Pult::k_receiveSucceed() { + stopWait(); + addToList(trUtf8("K received"), Qt::darkGreen); + //addToList(trUtf8("Write K file \"%1\": %2 coeffs, %3 bytes").arg(PI2QString(coeffs.fileName())).arg(K.size_s()).arg(coeffs.k_content.size_s()), Qt::darkMagenta); + //ui->spinSize->setValue(K.size_s()); + updateTree(); + //ui->table->setK(coeffsK.k()->data(), coeffsK.count()); +} + + +void CD_Pult::on_spinBuffer_editingFinished() { + ui->graphic->setHistorySize(ui->spinBuffer->value()); +} + + +void CD_Pult::stopWait() { + killTimer(timer); + timer = 0; + ui->labelWait->setText(" "); +} + + +void CD_Pult::updateGraph() { + ui->graphic->updateGraphics(); +} + + +void CD_Pult::updateDiag() { + /*ui->labelKReceiver->setText(piqt(coeffs.k_protocol->receiverDeviceName() + " - " + coeffs.k_protocol->receiverDeviceState())); + ui->labelKSender->setText(piqt(coeffs.k_protocol->senderDeviceName())); + ui->spinKSended->setValue(coeffs.k_protocol->sendCount()); + ui->spinKReceived->setValue(coeffs.k_protocol->receiveCount()); + ui->spinKWrong->setValue(coeffs.k_protocol->wrongCount()); + ui->spinKMissed->setValue(coeffs.k_protocol->missedCount()); + ui->labelKType->setText("0x" + QString::number(coeffs.k_protocol->from_k.type, 16).toUpper().rightJustified(2, '0')); + ui->labelKAddrPult->setText("0x" + QString::number(coeffs.k_protocol->from_k.addr_to, 16).toUpper().rightJustified(2, '0')); + ui->labelKAddr->setText("0x" + QString::number(coeffs.k_protocol->to_k.addr_to, 16).toUpper().rightJustified(2, '0')); + + ui->labelXReceiver->setText(piqt(prot_x->receiverDeviceName() + " - " + prot_x->receiverDeviceState())); + ui->labelXSender->setText(piqt(prot_x->senderDeviceName())); + ui->spinXSended->setValue(prot_x->sendCount()); + ui->spinXReceived->setValue(prot_x->receiveCount()); + ui->spinXWrong->setValue(prot_x->wrongCount()); + ui->spinXMissed->setValue(prot_x->missedCount()); + ui->labelXType->setText("0x" + QString::number(prot_x->from_x.type, 16).toUpper().rightJustified(2, '0')); + ui->labelXAddrPult->setText("0x" + QString::number(prot_x->from_x.addr_to, 16).toUpper().rightJustified(2, '0')); + ui->labelXAddr->setText("0x" + QString::number(prot_x->to_x.addr_to, 16).toUpper().rightJustified(2, '0')); + + ui->labelCReceiver->setText(piqt(prot_c->receiverDeviceName() + " - " + prot_c->receiverDeviceState())); + ui->labelCSender->setText(piqt(prot_c->senderDeviceName())); + ui->spinCSended->setValue(prot_c->sendCount()); + ui->spinCReceived->setValue(prot_c->receiveCount()); + ui->spinCWrong->setValue(prot_c->wrongCount()); + ui->spinCMissed->setValue(prot_c->missedCount()); + ui->labelCType->setText("0x" + QString::number(prot_c->from_c.type, 16).toUpper().rightJustified(2, '0')); + ui->labelCAddrPult->setText("0x" + QString::number(prot_c->from_c.addr_to, 16).toUpper().rightJustified(2, '0')); + ui->labelCAddr->setText("0x" + QString::number(prot_c->to_c.addr_to, 16).toUpper().rightJustified(2, '0')); + */ +} + + +void CD_Pult::updateKDesc(bool ask_move) { + /*int cind = parseHeader(kdesc_file, kdesc); + if (K.size_s() < cind) { + ui->spinSize->setValue(cind); + ui->spinSize->setStyleSheet("background-color: rgb(220, 220, 255);"); + } + bool move = false; + if (ask_move) + move = (QMessageBox::question(this, "KX Pult", "Save values at associated names?", QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes) == QMessageBox::Yes); + */ + updateTree(ask_move); +} + + +void CD_Pult::updateCDesc() { + //parseHeader(cdesc_file, cdesc); + updateCommands(); +} + + +bool stringComp(const QString & s1, const QString & s2) { + if (s1.size() != s2.size()) + return s1.size() > s2.size(); + return s1 > s2; +} + + +void CD_Pult::updateTree(bool move) { + int sp = ui->treeK->verticalScrollBar()->value(); + QApplication::setOverrideCursor(Qt::WaitCursor); + //qDebug() << "fill tree ..."; + ui->treeK->clear(); + ui->treeK->setUpdatesEnabled(false); + eval.clearCustomVariables(); + makeTreeSection(const_cast(K.root()), ui->treeK->invisibleRootItem()); + /*for (int i = 0; i < K.size_s(); ++i) { + QTreeWidgetItem * ti = new QTreeWidgetItem(); + KDesc kd = kdesc[i]; + QString kn = QString("k%1").arg(i); + knames[kn] = i; + knames_sort << kn; + if (eval.content.findVariable(kn) < 0) + eval.content.addVariable(kn, 0., false); + if (!kd.name.isEmpty()) { + knames[kd.name] = i; + knames_sort << kd.name; + eval.content.addVariable(kd.name, 0., false); + } + if (move && !kd.name.isEmpty()) { + if (prev_val.contains(kd.name)) + coeffs.setFormula(i, Q2PIString(prev_val[kd.name])); + } + ti->setText(0, QString::number(i)); + ti->setText(1, kd.name); + ti->setText(2, PI2QString(coeffs.formula(i))); + ti->setText(3, QString::number(K[i])); + ti->setText(4, typeName(kd.type)); + ti->setText(5, kd.comment); + ui->treeK->addTopLevelItem(ti); + }*/ + eval.content.sortVariables(); + //qDebug() << "fill tree ok"; + //qDebug() << "sort ..."; + qSort(knames_sort.begin(), knames_sort.end(), stringComp); + //qDebug() << "names" << knames_sort; + //qDebug() << "sort ok"; + QApplication::restoreOverrideCursor(); + ui->treeK->setUpdatesEnabled(true); + ui->treeK->verticalScrollBar()->setValue(sp); + //calculate(); + filterTree(); +} + + +void CD_Pult::updateCommands() { + while (ui->layoutCommands->count() > 0) + delete ui->layoutCommands->itemAt(0)->widget(); + /*QMapIterator it(cdesc); + while (it.hasNext()) { + it.next(); + KDesc kd = it.value(); + QPushButton * b = new QPushButton(); + QString text = kd.name; + if (!kd.comment.isEmpty()) + text += QString("\n(%1)").arg(kd.comment); + b->setText(text); + b->setProperty("_command", kd.index); + connect(b, SIGNAL(clicked()), this, SLOT(commandClicked())); + ui->layoutCommands->addWidget(b); + }*/ +} + + +void CD_Pult::filterTree() { + bool hn = ui->checkKHideNormal->isChecked(); + bool hs = ui->checkKHideExpressions->isChecked(); + bool ok = false; + QString fl = ui->lineKSearch->text(); + int lc = ui->treeK->topLevelItemCount(); + for (int i = 0; i < lc; ++i) { + QTreeWidgetItem * ti = ui->treeK->topLevelItem(i); + if (fl.isEmpty()) + ti->setHidden(false); + else + ti->setHidden(!ti->text(0).contains(fl, Qt::CaseInsensitive) && + !ti->text(1).contains(fl, Qt::CaseInsensitive) && + !ti->text(2).contains(fl, Qt::CaseInsensitive) && + !ti->text(3).contains(fl, Qt::CaseInsensitive) && + !ti->text(4).contains(fl, Qt::CaseInsensitive)); + if (hn) + if (ti->data(0, Qt::UserRole).toBool()) + ti->setHidden(true); + if (hs) { + ti->data(2, Qt::DisplayRole).toDouble(&ok); + if (!ok) + ti->setHidden(true); + } + } +} + + +void CD_Pult::markError(QTreeWidgetItem * item, const QString & tool_tip) { + int cc = item->columnCount(); + for (int i = 0; i < cc; ++i) + item->setBackgroundColor(i, QColor(255, 200, 200)); + if (item->toolTip(2).isEmpty()) + item->setToolTip(2, tool_tip); + if (item->toolTip(3).isEmpty()) + item->setToolTip(3, tool_tip); + item->setData(0, Qt::UserRole, false); + item->setText(3, "Error"); +} + + +void CD_Pult::markNormal(QTreeWidgetItem * item) { + int cc = item->columnCount(); + for (int i = 0; i < cc; ++i) + item->setBackground(i, Qt::NoBrush); + item->setToolTip(2, QString()); + item->setToolTip(3, QString()); + item->setData(0, Qt::UserRole, true); +} + + +void CD_Pult::progress(int val, int max) { + if (ctm.elapsed() < 50) return; + ctm.restart(); + ui->progress->setValue(qRound(val * 100. / max)); + QApplication::processEvents(); +} + + +void CD_Pult::commandClicked() { + QPushButton * b = qobject_cast(sender()); + if (!b) return; + //prot_c->sendCommand(b->property("_command").toInt()); +} diff --git a/cd_utils/pult/cd_pult.h b/cd_utils/pult/cd_pult.h new file mode 100644 index 0000000..b420817 --- /dev/null +++ b/cd_utils/pult/cd_pult.h @@ -0,0 +1,121 @@ +#ifndef CD_PULT_H +#define CD_PULT_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "piqt.h" +#include "session_manager.h" +#include "qpievaluator.h" +#include "cdutils_k.h" + +using namespace CDUtils; + +namespace Ui { + class CD_Pult; +}; + +class CD_Pult: public QMainWindow, public PIObject +{ + Q_OBJECT + PIOBJECT(CD_Pult) +public: + CD_Pult(); + ~CD_Pult(); + +private: + bool eventFilter(QObject * o, QEvent * e); + void timerEvent(QTimerEvent * ); + void addToList(const QString & s, const QColor & c); + QColor invertColor(QColor col) {return QColor(255 - col.red(), 255 - col.green(), 255 - col.blue());} + void stopWait(); + bool calculateExpression(int i, QVector trace); + void markError(QTreeWidgetItem * item, const QString & tool_tip = QString()); + void markNormal(QTreeWidgetItem * item); + void progress(int val, int max); + void clearSelected(); + QString typeName(const QString & n) const; + void makeTreeSection(KSection & ks, QTreeWidgetItem * pi); + + EVENT_HANDLER1(void, received, bool, ok); + EVENT_HANDLER(void, pip_sendFailed) {emit q_k_sendFailed();} + EVENT_HANDLER(void, pip_sendSucceed) {emit q_k_sendSucceed();} + EVENT_HANDLER(void, pip_receiveFailed) {emit q_k_receiveFailed();} + EVENT_HANDLER(void, pip_receiveSucceed) {emit q_k_receiveSucceed();} + + Ui::CD_Pult * ui; + PIString config_, name_x, name_c; + QString kdesc_file, cdesc_file, xdesc_file; + QMenu log_menu; + QTime tm, ctm; + QTimer timer_diag; + QMap knames; + QSet calculated; + QStringList knames_sort; + QPIEvaluator eval; + SessionManager session; + QPIConfig config; + //QVector k, x; + int clear_target, timer; + bool needWrite, isPause, need_update, show_x; + +private slots: + void loading(QPIConfig & conf); + void saving(QPIConfig & conf); + void updateGraph(); + void updateDiag(); + void updateKDesc(bool ask_move = false); + void updateCDesc(); + void updateTree(bool move = false); + void updateCommands(); + void filterTree(); + //void calculate(); + //void renew(bool write = true); + void commandClicked(); + void k_sendFailed(); + void k_sendSucceed(); + void k_receiveFailed(); + void k_receiveSucceed(); + void on_spinBuffer_editingFinished(); + void on_buttonSendK_clicked(); + void on_buttonReceiveK_clicked(); + void on_buttonShowAll_clicked(); + void on_buttonHideAll_clicked(); + void on_buttonRead_clicked(); + void on_buttonWrite_clicked(); + void on_buttonSetKDesc_clicked(); + void on_buttonReparseKDesc_clicked() {updateKDesc(true);} + void on_buttonSetCDesc_clicked(); + void on_buttonReparseCDesc_clicked() {updateCDesc();} + //void on_buttonCalculate_clicked() {calculate();} + //void on_buttonApply_clicked() {renew();} + void on_buttonPause_toggled(bool on) {isPause = on;} + void on_treeK_itemClicked(QTreeWidgetItem * item, int column); + void on_treeK_itemChanged(QTreeWidgetItem * item, int column); + void on_actionClear_triggered(); + +signals: + void q_k_sendFailed(); + void q_k_sendSucceed(); + void q_k_receiveFailed(); + void q_k_receiveSucceed(); + +}; + +#endif // CD_PULT_H + diff --git a/cd_utils/pult/cd_pult.qrc b/cd_utils/pult/cd_pult.qrc new file mode 100644 index 0000000..99f4688 --- /dev/null +++ b/cd_utils/pult/cd_pult.qrc @@ -0,0 +1,40 @@ + + + icons/dialog-close.png + icons/edit-clear-.png + icons/edit-guides.png + icons/view-grid.png + icons/zoom-fit-best.png + icons/configure.png + icons/alpha.png + icons/document-save.png + icons/edit-clear-locationbar-rtl.png + icons/edit-find.png + icons/list-add.png + icons/edit-delete.png + icons/item-add.png + icons/item.png + icons/node-add.png + icons/node.png + icons/edit-copy.png + icons/edit-paste.png + icons/expand_s_x.png + icons/expand_s_y.png + icons/expand_x.png + icons/expand_y.png + icons/media-playback-pause.png + icons/media-playback-stop.png + icons/media-record.png + icons/application-exit.png + icons/document-save-.png + icons/view-refresh.png + icons/document-open.png + icons/archive-extract.png + icons/document-export.png + icons/document-import.png + icons/zoom-fit-height.png + icons/layer-visible-off.png + icons/layer-visible-on.png + icons/accessories-calculator.png + + diff --git a/cd_utils/pult/cd_pult.ui b/cd_utils/pult/cd_pult.ui new file mode 100644 index 0000000..4f51a38 --- /dev/null +++ b/cd_utils/pult/cd_pult.ui @@ -0,0 +1,1262 @@ + + + CD_Pult + + + + 0 + 0 + 1034 + 559 + + + + CD Pult + + + + + + + 0 + + + + Coefficients (K) + + + + + + + + Update + + + + :/icons/view-refresh.png:/icons/view-refresh.png + + + + + + + Read + + + + :/icons/archive-extract.png:/icons/archive-extract.png + + + + + + + Send + + + + :/icons/document-export.png:/icons/document-export.png + + + + + + + + 0 + 0 + + + + Qt::CustomContextMenu + + + QAbstractItemView::NoEditTriggers + + + QAbstractItemView::NoSelection + + + QAbstractItemView::ScrollPerPixel + + + QAbstractItemView::ScrollPerPixel + + + + + + + Receive + + + + :/icons/document-import.png:/icons/document-import.png + + + + + + + + 0 + 0 + + + + + 200 + 0 + + + + + + + + + + + Write + + + + :/icons/document-save-.png:/icons/document-save-.png + + + + + + + Make ... + + + + :/icons/document-open.png:/icons/document-open.png + + + + + + + + + + + Hide expressions + + + + + + + Qt::Horizontal + + + QSizePolicy::Preferred + + + + 20 + 20 + + + + + + + + Show only errors + + + + + + + Qt::Horizontal + + + QSizePolicy::Preferred + + + + 20 + 20 + + + + + + + + :/icons/edit-find.png + + + Qt::AlignCenter + + + + + + + Search: + + + + + + + + 0 + 0 + + + + + + + + Qt::Horizontal + + + QSizePolicy::Preferred + + + + 40 + 20 + + + + + + + + Auto calculate + + + true + + + + + + + Qt::Horizontal + + + QSizePolicy::Preferred + + + + 20 + 20 + + + + + + + + Calculate + + + Calculate + + + + :/icons/accessories-calculator.png:/icons/accessories-calculator.png + + + + + + + 100 + + + Calculate %p% + + + + + + + + + Qt::CustomContextMenu + + + QAbstractItemView::AnyKeyPressed|QAbstractItemView::DoubleClicked|QAbstractItemView::EditKeyPressed + + + true + + + QAbstractItemView::ExtendedSelection + + + QAbstractItemView::ScrollPerPixel + + + QAbstractItemView::ScrollPerPixel + + + 6 + + + 200 + + + 20 + + + + Index + + + + + Name + + + + + Expression + + + + + Calculated + + + + + Type + + + + + Comment + + + + + + + + + Commands (C) + + + + + + + + Set C desc file ... + + + + :/icons/document-open.png:/icons/document-open.png + + + + + + + Reparse C desc + + + + :/icons/view-refresh.png:/icons/view-refresh.png + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + Commands + + + + + + QFrame::NoFrame + + + true + + + + + 0 + 0 + 100 + 30 + + + + + 0 + + + 0 + + + + + + + + + + Qt::Vertical + + + QSizePolicy::Expanding + + + + 66 + 441 + + + + + + + + + + + + + + + + + + Graphics (X) + + + + + + + 10 + + + + + + + + + + + 0 + 0 + + + + Show all + + + + :/icons/layer-visible-on.png:/icons/layer-visible-on.png + + + + + + + + 0 + 0 + + + + Hide all + + + + :/icons/layer-visible-off.png:/icons/layer-visible-off.png + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Start record + + + + :/icons/media-record.png:/icons/media-record.png + + + + + + + + + + + Pause + + + + :/icons/media-playback-pause.png:/icons/media-playback-pause.png + + + true + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Show + + + + + + + + 0 + 0 + + + + с + + + 1 + + + 0.100000000000000 + + + 9999.000000000000000 + + + 10.000000000000000 + + + + + + + Qt::Horizontal + + + QSizePolicy::Preferred + + + + 40 + 20 + + + + + + + + Save + + + + + + + + 0 + 0 + + + + с + + + 1 + + + 0.100000000000000 + + + 9999.000000000000000 + + + 60.000000000000000 + + + + + + + + + Graphic::Autofit|Graphic::BorderInputs|Graphic::Clear|Graphic::Configure|Graphic::CursorAxis|Graphic::Grid|Graphic::OnlyExpandX|Graphic::OnlyExpandY|Graphic::Save + + + false + + + false + + + 60.000000000000000 + + + 10.000000000000000 + + + + + + + + Configuration + + + + + + K + + + + QFormLayout::AllNonFixedFieldsGrow + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + + + receiver: + + + + + + + + + + + + + + sender: + + + + + + + + + + + + + + sended count: + + + + + + + true + + + 0 + + + 1999999999 + + + + + + + received count: + + + + + + + true + + + 0 + + + 1999999999 + + + + + + + wrong received count: + + + + + + + true + + + 0 + + + 1999999999 + + + + + + + type: + + + + + + + + + + + + + + address K: + + + + + + + + + + + + + + + + + + + + + missed received count: + + + + + + + true + + + 0 + + + 1999999999 + + + + + + + address pult: + + + + + + + + + + X + + + + QFormLayout::AllNonFixedFieldsGrow + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + + + receiver: + + + + + + + + + + + + + + sender: + + + + + + + + + + + + + + type: + + + + + + + + + + + + + + address X: + + + + + + + address pult: + + + + + + + + + + + + + + sended count: + + + + + + + true + + + 0 + + + 1999999999 + + + + + + + received count: + + + + + + + true + + + 0 + + + 1999999999 + + + + + + + wrong received count: + + + + + + + true + + + 0 + + + 1999999999 + + + + + + + + + + + + + + missed received count: + + + + + + + true + + + 0 + + + 1999999999 + + + + + + + + + + C + + + + QFormLayout::AllNonFixedFieldsGrow + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + + + receiver: + + + + + + + + + + + + + + sender: + + + + + + + + + + + + + + type: + + + + + + + + + + + + + + address C: + + + + + + + address pult: + + + + + + + + + + + + + + sended count: + + + + + + + true + + + 0 + + + 1999999999 + + + + + + + received count: + + + + + + + true + + + 0 + + + 1999999999 + + + + + + + wrong received count: + + + + + + + true + + + 0 + + + 1999999999 + + + + + + + + + + + + + + missed received count: + + + + + + + true + + + 0 + + + 1999999999 + + + + + + + + + + + + true + + + true + + + true + + + false + + + 20 + + + + + + + Apply + + + + :/icons/document-save-.png:/icons/document-save-.png + + + + + + + + + + + + + + + :/icons/edit-clear-.png:/icons/edit-clear-.png + + + Clear + + + + + + Graphic + QFrame +
graphic.h
+
+ + QPIConfigWidget + QTreeWidget +
qpiconfigwidget.h
+
+ + CLineEdit + QLineEdit +
clineedit.h
+
+
+ + + + + + + spinHistory + valueChanged(double) + graphic + setMaxVisibleTime(double) + + + 919 + 107 + + + 932 + 132 + + + + +
diff --git a/cd_utils/pult/icons/accessories-calculator.png b/cd_utils/pult/icons/accessories-calculator.png new file mode 100644 index 0000000..1b1dd1e Binary files /dev/null and b/cd_utils/pult/icons/accessories-calculator.png differ diff --git a/cd_utils/pult/icons/alpha.png b/cd_utils/pult/icons/alpha.png new file mode 100644 index 0000000..5435669 Binary files /dev/null and b/cd_utils/pult/icons/alpha.png differ diff --git a/cd_utils/pult/icons/application-exit.png b/cd_utils/pult/icons/application-exit.png new file mode 100644 index 0000000..ed5f8b2 Binary files /dev/null and b/cd_utils/pult/icons/application-exit.png differ diff --git a/cd_utils/pult/icons/archive-extract.png b/cd_utils/pult/icons/archive-extract.png new file mode 100644 index 0000000..f6f2a5d Binary files /dev/null and b/cd_utils/pult/icons/archive-extract.png differ diff --git a/cd_utils/pult/icons/configure.png b/cd_utils/pult/icons/configure.png new file mode 100644 index 0000000..5ce478b Binary files /dev/null and b/cd_utils/pult/icons/configure.png differ diff --git a/cd_utils/pult/icons/dialog-close.png b/cd_utils/pult/icons/dialog-close.png new file mode 100644 index 0000000..2c2f99e Binary files /dev/null and b/cd_utils/pult/icons/dialog-close.png differ diff --git a/cd_utils/pult/icons/document-export.png b/cd_utils/pult/icons/document-export.png new file mode 100644 index 0000000..9e1b6a6 Binary files /dev/null and b/cd_utils/pult/icons/document-export.png differ diff --git a/cd_utils/pult/icons/document-import.png b/cd_utils/pult/icons/document-import.png new file mode 100644 index 0000000..97e683a Binary files /dev/null and b/cd_utils/pult/icons/document-import.png differ diff --git a/cd_utils/pult/icons/document-open.png b/cd_utils/pult/icons/document-open.png new file mode 100644 index 0000000..8ba5441 Binary files /dev/null and b/cd_utils/pult/icons/document-open.png differ diff --git a/cd_utils/pult/icons/document-save-.png b/cd_utils/pult/icons/document-save-.png new file mode 100644 index 0000000..7fa489c Binary files /dev/null and b/cd_utils/pult/icons/document-save-.png differ diff --git a/cd_utils/pult/icons/document-save.png b/cd_utils/pult/icons/document-save.png new file mode 100644 index 0000000..8072aea Binary files /dev/null and b/cd_utils/pult/icons/document-save.png differ diff --git a/cd_utils/pult/icons/edit-clear-.png b/cd_utils/pult/icons/edit-clear-.png new file mode 100644 index 0000000..631ed44 Binary files /dev/null and b/cd_utils/pult/icons/edit-clear-.png differ diff --git a/cd_utils/pult/icons/edit-clear-locationbar-rtl.png b/cd_utils/pult/icons/edit-clear-locationbar-rtl.png new file mode 100644 index 0000000..6c4b83b Binary files /dev/null and b/cd_utils/pult/icons/edit-clear-locationbar-rtl.png differ diff --git a/cd_utils/pult/icons/edit-clear.png b/cd_utils/pult/icons/edit-clear.png new file mode 100644 index 0000000..19a1665 Binary files /dev/null and b/cd_utils/pult/icons/edit-clear.png differ diff --git a/cd_utils/pult/icons/edit-copy.png b/cd_utils/pult/icons/edit-copy.png new file mode 100644 index 0000000..5cdeb5f Binary files /dev/null and b/cd_utils/pult/icons/edit-copy.png differ diff --git a/cd_utils/pult/icons/edit-delete.png b/cd_utils/pult/icons/edit-delete.png new file mode 100644 index 0000000..87cd0b0 Binary files /dev/null and b/cd_utils/pult/icons/edit-delete.png differ diff --git a/cd_utils/pult/icons/edit-find-.png b/cd_utils/pult/icons/edit-find-.png new file mode 100644 index 0000000..64a1e28 Binary files /dev/null and b/cd_utils/pult/icons/edit-find-.png differ diff --git a/cd_utils/pult/icons/edit-find.png b/cd_utils/pult/icons/edit-find.png new file mode 100644 index 0000000..9a462c0 Binary files /dev/null and b/cd_utils/pult/icons/edit-find.png differ diff --git a/cd_utils/pult/icons/edit-guides.png b/cd_utils/pult/icons/edit-guides.png new file mode 100644 index 0000000..d264839 Binary files /dev/null and b/cd_utils/pult/icons/edit-guides.png differ diff --git a/cd_utils/pult/icons/edit-paste.png b/cd_utils/pult/icons/edit-paste.png new file mode 100644 index 0000000..a4e0a02 Binary files /dev/null and b/cd_utils/pult/icons/edit-paste.png differ diff --git a/cd_utils/pult/icons/expand_s_x.png b/cd_utils/pult/icons/expand_s_x.png new file mode 100644 index 0000000..b66cb40 Binary files /dev/null and b/cd_utils/pult/icons/expand_s_x.png differ diff --git a/cd_utils/pult/icons/expand_s_y.png b/cd_utils/pult/icons/expand_s_y.png new file mode 100644 index 0000000..c2e8f78 Binary files /dev/null and b/cd_utils/pult/icons/expand_s_y.png differ diff --git a/cd_utils/pult/icons/expand_x.png b/cd_utils/pult/icons/expand_x.png new file mode 100644 index 0000000..217e3ea Binary files /dev/null and b/cd_utils/pult/icons/expand_x.png differ diff --git a/cd_utils/pult/icons/expand_y.png b/cd_utils/pult/icons/expand_y.png new file mode 100644 index 0000000..fedf936 Binary files /dev/null and b/cd_utils/pult/icons/expand_y.png differ diff --git a/cd_utils/pult/icons/item-add.png b/cd_utils/pult/icons/item-add.png new file mode 100644 index 0000000..8a422c7 Binary files /dev/null and b/cd_utils/pult/icons/item-add.png differ diff --git a/cd_utils/pult/icons/item.png b/cd_utils/pult/icons/item.png new file mode 100644 index 0000000..50bfddb Binary files /dev/null and b/cd_utils/pult/icons/item.png differ diff --git a/cd_utils/pult/icons/layer-visible-off.png b/cd_utils/pult/icons/layer-visible-off.png new file mode 100644 index 0000000..5f87dce Binary files /dev/null and b/cd_utils/pult/icons/layer-visible-off.png differ diff --git a/cd_utils/pult/icons/layer-visible-on.png b/cd_utils/pult/icons/layer-visible-on.png new file mode 100644 index 0000000..b240552 Binary files /dev/null and b/cd_utils/pult/icons/layer-visible-on.png differ diff --git a/cd_utils/pult/icons/list-add.png b/cd_utils/pult/icons/list-add.png new file mode 100644 index 0000000..1e03be9 Binary files /dev/null and b/cd_utils/pult/icons/list-add.png differ diff --git a/cd_utils/pult/icons/media-playback-pause.png b/cd_utils/pult/icons/media-playback-pause.png new file mode 100644 index 0000000..5c7d128 Binary files /dev/null and b/cd_utils/pult/icons/media-playback-pause.png differ diff --git a/cd_utils/pult/icons/media-playback-stop.png b/cd_utils/pult/icons/media-playback-stop.png new file mode 100644 index 0000000..650874f Binary files /dev/null and b/cd_utils/pult/icons/media-playback-stop.png differ diff --git a/cd_utils/pult/icons/media-record.png b/cd_utils/pult/icons/media-record.png new file mode 100644 index 0000000..f926a8f Binary files /dev/null and b/cd_utils/pult/icons/media-record.png differ diff --git a/cd_utils/pult/icons/node-add.png b/cd_utils/pult/icons/node-add.png new file mode 100644 index 0000000..80b5c61 Binary files /dev/null and b/cd_utils/pult/icons/node-add.png differ diff --git a/cd_utils/pult/icons/node.png b/cd_utils/pult/icons/node.png new file mode 100644 index 0000000..fc8194e Binary files /dev/null and b/cd_utils/pult/icons/node.png differ diff --git a/cd_utils/pult/icons/view-grid.png b/cd_utils/pult/icons/view-grid.png new file mode 100644 index 0000000..0f1d70c Binary files /dev/null and b/cd_utils/pult/icons/view-grid.png differ diff --git a/cd_utils/pult/icons/view-refresh.png b/cd_utils/pult/icons/view-refresh.png new file mode 100644 index 0000000..afa2a9d Binary files /dev/null and b/cd_utils/pult/icons/view-refresh.png differ diff --git a/cd_utils/pult/icons/zoom-fit-best.png b/cd_utils/pult/icons/zoom-fit-best.png new file mode 100644 index 0000000..07cfc98 Binary files /dev/null and b/cd_utils/pult/icons/zoom-fit-best.png differ diff --git a/cd_utils/pult/icons/zoom-fit-height.png b/cd_utils/pult/icons/zoom-fit-height.png new file mode 100644 index 0000000..32e2190 Binary files /dev/null and b/cd_utils/pult/icons/zoom-fit-height.png differ diff --git a/cd_utils/pult/main.cpp b/cd_utils/pult/main.cpp new file mode 100644 index 0000000..4f8e616 --- /dev/null +++ b/cd_utils/pult/main.cpp @@ -0,0 +1,10 @@ +#include +#include "cd_pult.h" + + +int main(int argc, char *argv[]) { + QApplication a(argc, argv); + CD_Pult w; + w.show(); + return a.exec(); +}