git-svn-id: svn://db.shs.com.ru/libs@387 a8b55f48-bf90-11e4-a774-851b48703e85

This commit is contained in:
2018-05-24 09:22:24 +00:00
parent 7c9a2d0db2
commit 31557d5e5c
7 changed files with 111 additions and 33 deletions

View File

@@ -181,8 +181,13 @@ void CDCore::init(const PIString & configuration, bool pult) {
} }
void CDCore::stop() {
connection.stop();
}
void CDCore::startX(double freq) { void CDCore::startX(double freq) {
piCout << "start x" << x_timer.isRunning() << freq; //piCout << "start x" << x_timer.isRunning() << freq;
if (!x_timer.isRunning()) if (!x_timer.isRunning())
x_timer.start(1000. / piMaxd(freq, 0.01)); x_timer.start(1000. / piMaxd(freq, 0.01));
} }
@@ -194,7 +199,7 @@ void CDCore::stopX() {
void CDCore::sendCommand(const CDType & c) { void CDCore::sendCommand(const CDType & c) {
piCoutObj << "C_sendCommand" << c; //piCoutObj << "C_sendCommand" << c;
PIByteArray sba = makeHeader(CD_Command, 0); PIByteArray sba = makeHeader(CD_Command, 0);
sba << c.path(); sba << c.path();
sendDirect(sba); sendDirect(sba);
@@ -204,7 +209,7 @@ void CDCore::sendCommand(const CDType & c) {
void CDCore::registerCHandler(const CDType & c, PIObject * o, Handler h) { void CDCore::registerCHandler(const CDType & c, PIObject * o, Handler h) {
PIString sp = pathToString(c.path()); PIString sp = pathToString(c.path());
if (sp.isEmpty() || !h) return; if (sp.isEmpty() || !h) return;
piCout << "register" << sp; //piCout << "register" << sp;
c_handlers[sp] = OHPair(o, h); c_handlers[sp] = OHPair(o, h);
} }
@@ -432,14 +437,14 @@ void CDCore::procReceivedPacket(PIByteArray & ba) {
} break; } break;
case CD_XValues: { case CD_XValues: {
if (!x_pult_side) break; if (!x_pult_side) break;
x_mutex.lock();
PIVector<PIDeque<int> > x_vals; PIVector<PIDeque<int> > x_vals;
ba >> x_vals; ba >> x_vals;
x_mutex.lock();
piForeachC (PIDeque<int> & p, x_vals) { piForeachC (PIDeque<int> & p, x_vals) {
x_[p].readX(ba); x_[p].readX(ba);
} }
X_ReceivedX(x_vals); /// WARNING! under mutex
x_mutex.unlock(); x_mutex.unlock();
X_ReceivedX(x_vals);
} break; } break;
case CD_CQuery: case CD_CQuery:
C_Send(); C_Send();

View File

@@ -64,6 +64,7 @@ public:
void initApp(); void initApp();
void initPult(); void initPult();
void init(const PIString & configuration, bool pult = false); void init(const PIString & configuration, bool pult = false);
void stop();
void startX(double freq = 20.); void startX(double freq = 20.);
void stopX(); void stopX();
void sendCommand(const CDType & c); void sendCommand(const CDType & c);

View File

@@ -295,6 +295,7 @@ bool QCodeEdit::eventFilter(QObject * o, QEvent * e) {
int tcpos = 0; int tcpos = 0;
switch (e->type()) { switch (e->type()) {
case QEvent::MouseButtonPress: case QEvent::MouseButtonPress:
if (!isEnabled()) break;
tc = ui->textCode->cursorForPosition(((QMouseEvent*)e)->pos()); tc = ui->textCode->cursorForPosition(((QMouseEvent*)e)->pos());
tc.movePosition(QTextCursor::EndOfLine); tc.movePosition(QTextCursor::EndOfLine);
pos_el_press = tc.anchor(); pos_el_press = tc.anchor();
@@ -305,6 +306,7 @@ bool QCodeEdit::eventFilter(QObject * o, QEvent * e) {
ui->textCode->setTextCursor(tc); ui->textCode->setTextCursor(tc);
return true; return true;
case QEvent::MouseMove: case QEvent::MouseMove:
if (!isEnabled()) break;
tc = ui->textCode->cursorForPosition(((QMouseEvent*)e)->pos()); tc = ui->textCode->cursorForPosition(((QMouseEvent*)e)->pos());
tc.movePosition(QTextCursor::StartOfLine); tc.movePosition(QTextCursor::StartOfLine);
if (pos_press == tc.anchor()) { if (pos_press == tc.anchor()) {
@@ -323,6 +325,7 @@ bool QCodeEdit::eventFilter(QObject * o, QEvent * e) {
ui->textCode->setTextCursor(tc); ui->textCode->setTextCursor(tc);
return true; return true;
case QEvent::Wheel: case QEvent::Wheel:
if (!isEnabled()) break;
QApplication::sendEvent(ui->textCode->viewport(), e); QApplication::sendEvent(ui->textCode->viewport(), e);
return true; return true;
default: break; default: break;

View File

@@ -3,7 +3,7 @@ find_qt(${QtVersions} Core Gui OpenGL)
qt_sources(SRC) qt_sources(SRC)
qt_wrap(${SRC} HDRS out_HDR CPPS out_CPP QMS out_QM) qt_wrap(${SRC} HDRS out_HDR CPPS out_CPP QMS out_QM)
qt_add_executable(${PROJECT_NAME} WIN32 out_CPP) qt_add_executable(${PROJECT_NAME} WIN32 out_CPP)
qt_target_link_libraries(${PROJECT_NAME} qad_utils qad_widgets qad_graphic qcd_utils qad_application) qt_target_link_libraries(${PROJECT_NAME} qad_utils qad_widgets qad_graphic qad_application qcd_utils piqt_utils)
message(STATUS "Building ${PROJECT_NAME}") message(STATUS "Building ${PROJECT_NAME}")
if(LIB) if(LIB)
if(WIN32) if(WIN32)

View File

@@ -9,14 +9,20 @@
#include "qcd_modedialog.h" #include "qcd_modedialog.h"
#include "chunkstream.h" #include "chunkstream.h"
#include "qvariantedit.h" #include "qvariantedit.h"
#include "piqt.h"
#include "piqt_highlighter.h"
#include "qcodeedit.h"
#include <QFileDialog> #include <QFileDialog>
#include <QScrollBar> #include <QScrollBar>
using namespace CDUtils;
CDPultWindow::CDPultWindow(QWidget *parent) : EMainWindow(parent), Ui::CDPultWindow() { CDPultWindow::CDPultWindow(QWidget *parent) : EMainWindow(parent), Ui::CDPultWindow() {
setupUi(this); setupUi(this);
centralWidget()->hide(); centralWidget()->hide();
CDUtils::CDCore::instance()->initPult(); CDCore::instance()->initPult();
new ConfigHighlighter(codeConfig->document());
widgetK->setType(CDUtils::CDType::cdK); widgetK->setType(CDUtils::CDType::cdK);
widgetX->setType(CDUtils::CDType::cdX); widgetX->setType(CDUtils::CDType::cdX);
widgetC->setType(CDUtils::CDType::cdC); widgetC->setType(CDUtils::CDType::cdC);
@@ -51,6 +57,34 @@ void CDPultWindow::loadFile(const QString & fp) {
} }
void CDPultWindow::apply(bool sessions) {
CDCore::instance()->stop();
widgetK->setFile(editFileK->value().value<QAD::File>().file);
widgetX->setFile(editFileX->value().value<QAD::File>().file);
widgetC->setFile(editFileC->value().value<QAD::File>().file);
if (checkDefaultConfig->isChecked())
CDCore::instance()->initPult();
else
CDCore::instance()->init(Q2PIString(codeConfig->text()), true);
widgetX->view->startX();
if (sessions) {
widgetGraphics->load(session_gr);
if (!session_mw.isEmpty())
restoreState(session_mw);
X.lock();
PIVector<PIDeque<int> > x_list = X.enabledList();
X.unlock();
piForeachC (PIDeque<int> & p, x_list)
X.enable(X[p]);
((CDItemModel*)widgetX->view->model())->updateModel();
widgetX->view->expandAll();
}
dockCDKView->setVisible(checkHasK->isChecked());
dockCDXView->setVisible(checkHasX->isChecked());
dockCDCView->setVisible(checkHasC->isChecked());
}
void CDPultWindow::closeEvent(QCloseEvent *e) { void CDPultWindow::closeEvent(QCloseEvent *e) {
EMainWindow::closeEvent(e); EMainWindow::closeEvent(e);
if (!e->isAccepted()) if (!e->isAccepted())
@@ -80,15 +114,20 @@ bool CDPultWindow::load(const QString & path) {
checkHasK->setChecked(conf.getValue("has_k")); checkHasK->setChecked(conf.getValue("has_k"));
checkHasX->setChecked(conf.getValue("has_x")); checkHasX->setChecked(conf.getValue("has_x"));
checkHasC->setChecked(conf.getValue("has_c")); checkHasC->setChecked(conf.getValue("has_c"));
checkDefaultConfig->setChecked(conf.getValue("default_config"));
codeConfig->setText(QByteArray2QString(conf.getValue("config", QByteArray())));
session_gr = conf.getValue("session_gr", QByteArray()); session_gr = conf.getValue("session_gr", QByteArray());
session_mw = conf.getValue("session_mw", QByteArray());
setChanged(false); setChanged(false);
file_name = path; file_name = path;
apply(true);
return true; return true;
} }
bool CDPultWindow::save(const QString & path) { bool CDPultWindow::save(const QString & path) {
session_gr = widgetGraphics->save(); session_gr = widgetGraphics->save();
session_mw = saveState();
QPIConfig conf(path, QIODevice::ReadWrite); QPIConfig conf(path, QIODevice::ReadWrite);
conf.clear(); conf.clear();
conf.setValue("file_k", editFileK->value().value<QAD::File>().file); conf.setValue("file_k", editFileK->value().value<QAD::File>().file);
@@ -99,7 +138,11 @@ bool CDPultWindow::save(const QString & path) {
conf.setValue("has_k", checkHasK->isChecked()); conf.setValue("has_k", checkHasK->isChecked());
conf.setValue("has_x", checkHasX->isChecked()); conf.setValue("has_x", checkHasX->isChecked());
conf.setValue("has_c", checkHasC->isChecked()); conf.setValue("has_c", checkHasC->isChecked());
conf.setValue("has_c", checkHasC->isChecked());
conf.setValue("default_config", checkDefaultConfig->isChecked());
conf.setValue("config", QString2QByteArray(codeConfig->text()));
conf.setValue("session_gr", session_gr); conf.setValue("session_gr", session_gr);
conf.setValue("session_mw", session_mw);
file_name = path; file_name = path;
return true; return true;
@@ -160,22 +203,7 @@ void CDPultWindow::on_editFileK_valueChanged(const QVariant & p) {
void CDPultWindow::on_buttonSessionApply_clicked() { void CDPultWindow::on_buttonSessionApply_clicked() {
// with session or not apply(false);
widgetK->setFile(editFileK->value().value<QAD::File>().file);
widgetX->setFile(editFileX->value().value<QAD::File>().file);
widgetC->setFile(editFileC->value().value<QAD::File>().file);
dockCDKView->setVisible(checkHasK->isChecked());
dockCDXView->setVisible(checkHasX->isChecked());
dockCDCView->setVisible(checkHasC->isChecked());
widgetX->view->startX();
widgetGraphics->load(session_gr);
X.lock();
PIVector<PIDeque<int> > x_list = X.enabledList();
X.unlock();
piForeachC (PIDeque<int> & p, x_list)
X.enable(X[p]);
((CDItemModel*)widgetX->view->model())->updateModel();
widgetX->view->expandAll();
} }

View File

@@ -17,6 +17,7 @@ public:
explicit CDPultWindow(QWidget *parent = 0); explicit CDPultWindow(QWidget *parent = 0);
~CDPultWindow(); ~CDPultWindow();
void loadFile(const QString & fp); void loadFile(const QString & fp);
void apply(bool sessions);
private: private:
@@ -31,7 +32,7 @@ private:
Ribbon * ribbon; Ribbon * ribbon;
QMap<CDViewWidget::LogIcon, QIcon> log_icons; QMap<CDViewWidget::LogIcon, QIcon> log_icons;
QByteArray session_gr; QByteArray session_gr, session_mw;
private slots: private slots:
void addToLog(CDViewWidget::LogIcon icon, const QString & msg); void addToLog(CDViewWidget::LogIcon icon, const QString & msg);

View File

@@ -278,20 +278,37 @@
</item> </item>
</layout> </layout>
</item> </item>
<item row="6" column="0" colspan="2">
<widget class="QCheckBox" name="checkDefaultConfig">
<property name="text">
<string>Default config</string>
</property>
</widget>
</item>
</layout> </layout>
</item> </item>
<item> <item>
<spacer name="verticalSpacer"> <widget class="QCodeEdit" name="codeConfig">
<property name="orientation"> <property name="sizePolicy">
<enum>Qt::Vertical</enum> <sizepolicy hsizetype="Preferred" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property> </property>
<property name="sizeHint" stdset="0"> <property name="text">
<size> <string>include = ip.conf
<width>20</width> [connection]
<height>1</height> device.cd = eth://udp:${ip.pult}:27002:${ip.app}:27001 #s
</size> []
</string>
</property> </property>
</spacer> <property name="editorFont">
<font>
<family>DejaVu Sans Mono</family>
<pointsize>9</pointsize>
</font>
</property>
</widget>
</item> </item>
</layout> </layout>
</widget> </widget>
@@ -445,6 +462,8 @@
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="separator"/>
<addaction name="separator"/>
</widget> </widget>
<customwidgets> <customwidgets>
<customwidget> <customwidget>
@@ -458,6 +477,11 @@
<extends>QLineEdit</extends> <extends>QLineEdit</extends>
<header>clineedit.h</header> <header>clineedit.h</header>
</customwidget> </customwidget>
<customwidget>
<class>QCodeEdit</class>
<extends>QWidget</extends>
<header>qcodeedit.h</header>
</customwidget>
<customwidget> <customwidget>
<class>QVariantEdit</class> <class>QVariantEdit</class>
<extends>QWidget</extends> <extends>QWidget</extends>
@@ -618,5 +642,21 @@
</hint> </hint>
</hints> </hints>
</connection> </connection>
<connection>
<sender>checkDefaultConfig</sender>
<signal>toggled(bool)</signal>
<receiver>codeConfig</receiver>
<slot>setDisabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>579</x>
<y>280</y>
</hint>
<hint type="destinationlabel">
<x>581</x>
<y>304</y>
</hint>
</hints>
</connection>
</connections> </connections>
</ui> </ui>