PageRenderTime 51ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/ui/ActionDialog.cpp

https://github.com/atraber/RaspExt
C++ | 1262 lines | 909 code | 301 blank | 52 comment | 65 complexity | 8ca723c4f493408f8f96ff9d8956443d MD5 | raw file
  1. #include "ui/ActionDialog.h"
  2. #include "ui_ActionDialog.h"
  3. #include "script/ActionOutput.h"
  4. #include "script/ActionOutputLED.h"
  5. #include "script/ActionOutputDCMotor.h"
  6. #include "script/ActionOutputRelay.h"
  7. #include "script/ActionOutputGPO.h"
  8. #include "script/ActionOutputStepper.h"
  9. #include "script/ActionOutputStepperSoftStop.h"
  10. #include "script/ActionOutputStepperRunVelocity.h"
  11. #include "script/ActionOutputStepperPositioning.h"
  12. #include "script/ActionOutputStepperSetParam.h"
  13. #include "script/ActionVariable.h"
  14. #include "script/ActionSleep.h"
  15. #include "script/ActionCallRule.h"
  16. #include "script/ActionMusic.h"
  17. #include "hw/HWInput.h"
  18. #include "util/Debug.h"
  19. #include <QFileDialog>
  20. ActionDialog::ActionDialog(QWidget *parent, Script *script) :
  21. QDialog(parent),
  22. ui(new Ui::ActionDialog)
  23. {
  24. pi_assert(script != NULL);
  25. ui->setupUi(this);
  26. m_script = script;
  27. m_action = NULL;
  28. m_baseWidget = NULL;
  29. // connect all signals - slots
  30. connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(okPressed()));
  31. connect(ui->buttonBox, SIGNAL(rejected()), this, SLOT(close()));
  32. connect(ui->comboAction, SIGNAL(currentIndexChanged(int)), this, SLOT(actionChanged(int)));
  33. // default values
  34. this->actionChanged( ui->comboAction->currentIndex() );
  35. }
  36. void ActionDialog::actionChanged(int index)
  37. {
  38. if(m_baseWidget != NULL)
  39. {
  40. ui->frameGrid->removeWidget(m_baseWidget);
  41. delete m_baseWidget;
  42. m_baseWidget = NULL;
  43. }
  44. Action::Type type = (Action::Type)index;
  45. switch(type)
  46. {
  47. case Action::Output:
  48. m_baseWidget = new ActionOutputWidget(this, m_script);
  49. break;
  50. case Action::Var:
  51. m_baseWidget = new ActionVariableWidget(this, m_script);
  52. break;
  53. case Action::Sleep:
  54. m_baseWidget = new ActionSleepWidget(this, m_script);
  55. break;
  56. case Action::CallRule:
  57. m_baseWidget = new ActionCallRuleWidget(this, m_script);
  58. break;
  59. case Action::Music:
  60. m_baseWidget = new ActionMusicWidget(this, m_script);
  61. break;
  62. }
  63. if(m_baseWidget != NULL)
  64. {
  65. ui->frameGrid->addWidget(m_baseWidget, 1, 0, 1, 2);
  66. }
  67. }
  68. void ActionDialog::okPressed()
  69. {
  70. pi_assert(m_action == NULL);
  71. pi_assert(m_baseWidget != NULL);
  72. m_action = ((IActionWidget*)m_baseWidget)->assemble();
  73. if(m_action == NULL)
  74. LOG_WARN(Logger::UI, "Assembling Action failed");
  75. this->done(Accepted);
  76. }
  77. void ActionDialog::edit(Action *action)
  78. {
  79. ui->comboAction->setCurrentIndex(action->getType());
  80. if(m_baseWidget != NULL)
  81. {
  82. m_baseWidget->edit(action);
  83. }
  84. }
  85. ActionDialog::~ActionDialog()
  86. {
  87. delete ui;
  88. }
  89. ActionOutputWidget::ActionOutputWidget(QWidget* parent, Script *script) : IActionWidget(parent)
  90. {
  91. m_baseWidget = NULL;
  92. m_script = script;
  93. m_comboOutput = new QComboBox(this);
  94. m_label = new QLabel("Select input", this);
  95. m_labelType = new QLabel("");
  96. // fill combo box with all outputs
  97. std::list<HWOutput*> listOutputs = script->getOutputList();
  98. for(std::list<HWOutput*>::iterator it = listOutputs.begin(); it != listOutputs.end(); it++)
  99. {
  100. m_comboOutput->addItem((*it)->getName().c_str(), qVariantFromValue((void*)*it));
  101. }
  102. m_layout = new QGridLayout(this);
  103. // remove spacing around widget, it looks kind of odd otherwise
  104. m_layout->setContentsMargins(0, 0, 0, 0);
  105. // add our widgets to the layout
  106. m_layout->addWidget(m_labelType, 0, 0);
  107. m_layout->addWidget(m_comboOutput, 0, 1);
  108. m_layout->addWidget(m_labelType, 1, 0, 1, 2);
  109. this->setLayout(m_layout);
  110. // connect all signals - slots
  111. connect(m_comboOutput, SIGNAL(currentIndexChanged(int)), this, SLOT(outputChanged(int)));
  112. // default values
  113. this->outputChanged( m_comboOutput->currentIndex() );
  114. }
  115. void ActionOutputWidget::outputChanged(int index)
  116. {
  117. // if the combobox is empty, then there is nothing to do here
  118. if(m_comboOutput->count() == 0)
  119. return;
  120. QVariant variant = m_comboOutput->itemData( index );
  121. HWOutput* hw = (HWOutput*)variant.value<void*>();
  122. HWOutput::HWOutputType type = hw->getType();
  123. QString outputtype = "Selected output type is ";
  124. outputtype.append( HWOutput::HWOutputTypeToString( type ).c_str() );
  125. m_labelType->setText( outputtype );
  126. // delete old baseWidget if it exists
  127. if(m_baseWidget != NULL)
  128. {
  129. m_layout->removeWidget(m_baseWidget);
  130. delete m_baseWidget;
  131. m_baseWidget = NULL;
  132. }
  133. switch(type)
  134. {
  135. case HWOutput::Relay:
  136. m_baseWidget = new ActionOutputRelayWidget(this, m_script);
  137. break;
  138. case HWOutput::GPO:
  139. m_baseWidget = new ActionOutputGPOWidget(this, m_script);
  140. break;
  141. case HWOutput::DCMotor:
  142. m_baseWidget = new ActionOutputDCMotorWidget(this, m_script);
  143. break;
  144. case HWOutput::LED:
  145. m_baseWidget = new ActionOutputLEDWidget(this, m_script);
  146. break;
  147. case HWOutput::Stepper:
  148. m_baseWidget = new ActionOutputStepperWidget(this, m_script);
  149. break;
  150. default:
  151. LOG_WARN(Logger::UI, "Unknown output type");
  152. break;
  153. }
  154. // add new baseWidget, this should never be NULL. If it is, somewhere something went wrong
  155. if(m_baseWidget != NULL)
  156. {
  157. m_layout->addWidget(m_baseWidget, 2, 0, 1, 2);
  158. }
  159. }
  160. void ActionOutputWidget::edit(Action* act)
  161. {
  162. ActionOutput* action = (ActionOutput*)act;
  163. QString str = QString::fromStdString( action->getHWName() );
  164. for(int i = 0; i < m_comboOutput->count(); i++)
  165. {
  166. if( m_comboOutput->itemText(i).compare(str, Qt::CaseInsensitive) == 0 )
  167. {
  168. m_comboOutput->setCurrentIndex(i);
  169. break;
  170. }
  171. }
  172. if( m_baseWidget != NULL)
  173. {
  174. m_baseWidget->edit(action);
  175. }
  176. }
  177. Action* ActionOutputWidget::assemble()
  178. {
  179. pi_assert(m_baseWidget != NULL);
  180. ActionOutput* action = (ActionOutput*) ((IActionWidget*)m_baseWidget)->assemble();
  181. action->setHWName( m_comboOutput->currentText().toStdString() );
  182. return action;
  183. }
  184. ActionOutputRelayWidget::ActionOutputRelayWidget(QWidget* parent, Script *script) : IActionWidget(parent)
  185. {
  186. // create comboBox and add items
  187. m_combo = new QComboBox(this);
  188. m_combo->addItem("Off");
  189. m_combo->addItem("On");
  190. m_combo->addItem("Toggle");
  191. m_label = new QLabel("Set relay to", this);
  192. QGridLayout* layout = new QGridLayout(this);
  193. // remove spacing around widget, it looks kind of odd otherwise
  194. layout->setContentsMargins(0, 0, 0, 0);
  195. // add our widgets to the layout
  196. layout->addWidget(m_label, 0, 0);
  197. layout->addWidget(m_combo, 0, 1);
  198. this->setLayout(layout);
  199. }
  200. Action* ActionOutputRelayWidget::assemble()
  201. {
  202. ActionOutputRelay* action = new ActionOutputRelay();
  203. action->setState( (ActionOutputRelay::State)m_combo->currentIndex() );
  204. return action;
  205. }
  206. void ActionOutputRelayWidget::edit(Action* act)
  207. {
  208. ActionOutputRelay* action = (ActionOutputRelay*)act;
  209. m_combo->setCurrentIndex( action->getState());
  210. }
  211. ActionOutputGPOWidget::ActionOutputGPOWidget(QWidget* parent, Script *script) : IActionWidget(parent)
  212. {
  213. // create comboBox and add items
  214. m_combo = new QComboBox(this);
  215. m_combo->addItem("Low");
  216. m_combo->addItem("High");
  217. m_combo->addItem("Toggle");
  218. m_label = new QLabel("Set GPO to", this);
  219. QGridLayout* layout = new QGridLayout(this);
  220. // remove spacing around widget, it looks kind of odd otherwise
  221. layout->setContentsMargins(0, 0, 0, 0);
  222. // add our widgets to the layout
  223. layout->addWidget(m_label, 0, 0);
  224. layout->addWidget(m_combo, 0, 1);
  225. this->setLayout(layout);
  226. }
  227. Action* ActionOutputGPOWidget::assemble()
  228. {
  229. ActionOutputGPO* action = new ActionOutputGPO();
  230. action->setState( (ActionOutputGPO::State)m_combo->currentIndex() );
  231. return action;
  232. }
  233. void ActionOutputGPOWidget::edit(Action* act)
  234. {
  235. ActionOutputGPO* action = (ActionOutputGPO*)act;
  236. m_combo->setCurrentIndex( action->getState());
  237. }
  238. ActionOutputLEDWidget::ActionOutputLEDWidget(QWidget* parent, Script *script) : IActionWidget(parent)
  239. {
  240. m_label = new QLabel("Set brightness of LED to ", this);
  241. m_spinBox = new QSpinBox(this);
  242. m_spinBox->setMinimum(0);
  243. m_spinBox->setMaximum(100);
  244. QGridLayout* layout = new QGridLayout(this);
  245. // remove spacing around widget, it looks kind of odd otherwise
  246. layout->setContentsMargins(0, 0, 0, 0);
  247. // add our widgets to the layout
  248. layout->addWidget(m_label, 0, 0);
  249. layout->addWidget(m_spinBox, 0, 1);
  250. this->setLayout(layout);
  251. }
  252. Action* ActionOutputLEDWidget::assemble()
  253. {
  254. ActionOutputLED* action = new ActionOutputLED();
  255. action->setValue( m_spinBox->value() );
  256. return action;
  257. }
  258. void ActionOutputLEDWidget::edit(Action* act)
  259. {
  260. ActionOutputLED* action = (ActionOutputLED*)act;
  261. m_spinBox->setValue( action->getValue() );
  262. }
  263. ActionOutputDCMotorWidget::ActionOutputDCMotorWidget(QWidget* parent, Script* script) : IActionWidget(parent)
  264. {
  265. m_labelState = new QLabel("Set motor to", this);
  266. // create comboBox and add items
  267. m_comboState = new QComboBox(this);
  268. m_comboState->addItem("Standby");
  269. m_comboState->addItem("Reverse");
  270. m_comboState->addItem("Forward");
  271. m_comboState->addItem("Brake");
  272. m_labelSpeed = new QLabel("Set speed to", this);
  273. // create comboBox to select a fader
  274. m_comboSpeed = new QComboBox(this);
  275. m_comboSpeed->addItem("value");
  276. std::list<HWInput*> listInputs = script->getInputList();
  277. for(std::list<HWInput*>::iterator it = listInputs.begin(); it != listInputs.end(); it++)
  278. {
  279. if( (*it)->getType() == HWInput::Fader )
  280. m_comboSpeed->addItem((*it)->getName().c_str());
  281. }
  282. m_spinSpeed = new QSpinBox(this);
  283. m_spinSpeed->setMaximum(100);
  284. m_spinSpeed->setMinimum(0);
  285. QGridLayout* layout = new QGridLayout(this);
  286. // remove spacing around widget, it looks kind of odd otherwise
  287. layout->setContentsMargins(0, 0, 0, 0);
  288. // add our widgets to the layout
  289. layout->addWidget(m_labelState, 0, 0);
  290. layout->addWidget(m_comboState, 0, 1, 1, 2);
  291. layout->addWidget(m_labelSpeed, 1, 0);
  292. layout->addWidget(m_comboSpeed, 1, 1);
  293. layout->addWidget(m_spinSpeed, 1, 2);
  294. this->setLayout(layout);
  295. // connect all signals-slots
  296. connect(m_comboSpeed, SIGNAL(currentIndexChanged(int)), this, SLOT(speedComboChanged(int)));
  297. }
  298. void ActionOutputDCMotorWidget::speedComboChanged(int index)
  299. {
  300. if( index != 0 )
  301. m_spinSpeed->hide();
  302. else
  303. m_spinSpeed->show();
  304. }
  305. Action* ActionOutputDCMotorWidget::assemble()
  306. {
  307. ActionOutputDCMotor* action = new ActionOutputDCMotor();
  308. action->setState( (HWOutputDCMotor::MotorState)m_comboState->currentIndex() );
  309. action->setSpeed( m_spinSpeed->value() );
  310. if( m_comboSpeed->currentIndex() != 0 )
  311. {
  312. action->setInputName( m_comboSpeed->currentText().toStdString() );
  313. }
  314. return action;
  315. }
  316. void ActionOutputDCMotorWidget::edit(Action* act)
  317. {
  318. ActionOutputDCMotor* action = (ActionOutputDCMotor*)act;
  319. m_comboState->setCurrentIndex( action->getState() );
  320. m_spinSpeed->setValue( action->getSpeed() );
  321. // only set this if it is used
  322. if( !action->getInputName().empty() )
  323. {
  324. QString str = QString::fromStdString( action->getInputName() );
  325. for(int i = 0; i < m_comboSpeed->count(); i++)
  326. {
  327. if( m_comboSpeed->itemText(i).compare(str, Qt::CaseInsensitive) == 0 )
  328. {
  329. m_comboSpeed->setCurrentIndex(i);
  330. break;
  331. }
  332. }
  333. }
  334. }
  335. ActionOutputStepperWidget::ActionOutputStepperWidget(QWidget* parent, Script* script) : IActionWidget(parent)
  336. {
  337. m_baseWidget = NULL;
  338. m_label = new QLabel("Select type", this);
  339. // create comboBox for all possible types
  340. m_combo = new QComboBox(this);
  341. m_combo->addItem("Soft stop");
  342. m_combo->addItem("RunVelocity");
  343. m_combo->addItem("Positioning");
  344. m_combo->addItem("Set parameters");
  345. m_layout = new QGridLayout(this);
  346. // remove spacing around widget, it looks kind of odd otherwise
  347. m_layout->setContentsMargins(0, 0, 0, 0);
  348. // add our widgets to the layout
  349. m_layout->addWidget(m_label, 0, 0);
  350. m_layout->addWidget(m_combo, 0, 1);
  351. this->setLayout(m_layout);
  352. // connect all signals-slots
  353. connect(m_combo, SIGNAL(currentIndexChanged(int)), this, SLOT(typeComboChanged(int)));
  354. // default values
  355. this->typeComboChanged( m_combo->currentIndex() );
  356. }
  357. void ActionOutputStepperWidget::typeComboChanged(int index)
  358. {
  359. if(m_baseWidget != NULL)
  360. {
  361. m_layout->removeWidget(m_baseWidget);
  362. delete m_baseWidget;
  363. m_baseWidget = NULL;
  364. }
  365. switch(index)
  366. {
  367. case ActionOutputStepper::SoftStop:
  368. m_baseWidget = new ActionOutputStepperSoftStopWidget(this, NULL); // we do not need Script in this class, so we just take NULL
  369. break;
  370. case ActionOutputStepper::RunVelocity:
  371. m_baseWidget = new ActionOutputStepperRunVelocityWidget(this, NULL); // we do not need Script in this class, so we just take NULL
  372. break;
  373. case ActionOutputStepper::Positioning:
  374. m_baseWidget = new ActionOutputStepperPositioningWidget(this, NULL); // we do not need Script in this class, so we just take NULL
  375. break;
  376. case ActionOutputStepper::SetParam:
  377. m_baseWidget = new ActionOutputStepperSetParamWidget(this, NULL); // we do not need Script in this class, so we just take NULL
  378. break;
  379. }
  380. // add new baseWidget, this should never be NULL. If it is, somewhere something went wrong
  381. if(m_baseWidget != NULL)
  382. {
  383. m_layout->addWidget(m_baseWidget, 2, 0, 1, 2);
  384. }
  385. }
  386. Action* ActionOutputStepperWidget::assemble()
  387. {
  388. if( m_baseWidget != NULL)
  389. return m_baseWidget->assemble();
  390. return NULL;
  391. }
  392. void ActionOutputStepperWidget::edit(Action* act)
  393. {
  394. ActionOutputStepper* action = (ActionOutputStepper*)act;
  395. m_combo->setCurrentIndex( action->getStepperType() );
  396. if( m_baseWidget != NULL)
  397. {
  398. m_baseWidget->edit(action);
  399. }
  400. }
  401. ActionOutputStepperSoftStopWidget::ActionOutputStepperSoftStopWidget(QWidget* parent, Script* script) : IActionWidget(parent)
  402. {
  403. m_label = new QLabel("Do a soft stop", this);
  404. QGridLayout* layout = new QGridLayout(this);
  405. // remove spacing around widget, it looks kind of odd otherwise
  406. layout->setContentsMargins(0, 0, 0, 0);
  407. // add our widgets to the layout
  408. layout->addWidget(m_label, 0, 0);
  409. this->setLayout(layout);
  410. }
  411. Action* ActionOutputStepperSoftStopWidget::assemble()
  412. {
  413. return new ActionOutputStepperSoftStop();
  414. }
  415. void ActionOutputStepperSoftStopWidget::edit(Action* act)
  416. {
  417. // nothing to do
  418. }
  419. ActionOutputStepperRunVelocityWidget::ActionOutputStepperRunVelocityWidget(QWidget* parent, Script* script) : IActionWidget(parent)
  420. {
  421. m_label = new QLabel("Send command RunVelocity to the stepper", this);
  422. QGridLayout* layout = new QGridLayout(this);
  423. // remove spacing around widget, it looks kind of odd otherwise
  424. layout->setContentsMargins(0, 0, 0, 0);
  425. // add our widgets to the layout
  426. layout->addWidget(m_label, 0, 0);
  427. this->setLayout(layout);
  428. }
  429. Action* ActionOutputStepperRunVelocityWidget::assemble()
  430. {
  431. return new ActionOutputStepperRunVelocity();
  432. }
  433. void ActionOutputStepperRunVelocityWidget::edit(Action* act)
  434. {
  435. // nothing to do
  436. }
  437. ActionOutputStepperPositioningWidget::ActionOutputStepperPositioningWidget(QWidget* parent, Script* script) : IActionWidget(parent)
  438. {
  439. QLabel* labelType = new QLabel("Select positioning type", this);
  440. m_comboType = new QComboBox(this);
  441. m_comboType->addItem("Set Position");
  442. m_comboType->addItem("Set Dual Position");
  443. m_comboType->addItem("Reset Position");
  444. m_label = new QLabel("Set target position", this);
  445. m_spinBox = new QSpinBox(this);
  446. m_spinBox->setMinimum( SHRT_MIN );
  447. m_spinBox->setMaximum( SHRT_MAX );
  448. m_label2 = new QLabel("Set target position 2", this);
  449. m_spinBox2 = new QSpinBox(this);
  450. m_spinBox2->setMinimum( SHRT_MIN );
  451. m_spinBox2->setMaximum( SHRT_MAX );
  452. m_labelVmin = new QLabel("Set Vmin", this);
  453. m_spinVmin = new QSpinBox(this);
  454. m_spinVmin->setMinimum( 0 );
  455. m_spinVmin->setMaximum( 15 );
  456. m_labelVmax = new QLabel("Set Vmax", this);
  457. m_spinVmax = new QSpinBox(this);
  458. m_spinVmax->setMinimum( 0 );
  459. m_spinVmax->setMaximum( 15 );
  460. QGridLayout* layout = new QGridLayout(this);
  461. // remove spacing around widget, it looks kind of odd otherwise
  462. layout->setContentsMargins(0, 0, 0, 0);
  463. // add our widgets to the layout
  464. layout->addWidget(labelType, 0, 0);
  465. layout->addWidget(m_comboType, 0, 1);
  466. layout->addWidget(m_label, 1, 0);
  467. layout->addWidget(m_spinBox, 1, 1);
  468. layout->addWidget(m_label2, 2, 0);
  469. layout->addWidget(m_spinBox2, 2, 1);
  470. layout->addWidget(m_labelVmin, 3, 0);
  471. layout->addWidget(m_spinVmin, 3, 1);
  472. layout->addWidget(m_labelVmax, 4, 0);
  473. layout->addWidget(m_spinVmax, 4, 1);
  474. this->setLayout(layout);
  475. // connect all signals - slots
  476. connect(m_comboType, SIGNAL(currentIndexChanged(int)), this, SLOT(comboTypeChanged(int)));
  477. // set default values
  478. this->comboTypeChanged( m_comboType->currentIndex() );
  479. }
  480. void ActionOutputStepperPositioningWidget::comboTypeChanged(int index)
  481. {
  482. if(index == ActionOutputStepperPositioning::SetPosition)
  483. {
  484. m_label->setText("Set target position");
  485. m_label->show();
  486. m_spinBox->show();
  487. m_label2->hide();
  488. m_spinBox2->hide();
  489. m_labelVmin->hide();
  490. m_spinVmin->hide();
  491. m_labelVmax->hide();
  492. m_spinVmax->hide();
  493. }
  494. else if(index == ActionOutputStepperPositioning::SetDualPosition)
  495. {
  496. m_label->setText("Set target position 1");
  497. m_label->show();
  498. m_spinBox->show();
  499. m_label2->show();
  500. m_spinBox2->show();
  501. m_labelVmin->show();
  502. m_spinVmin->show();
  503. m_labelVmax->show();
  504. m_spinVmax->show();
  505. }
  506. else // index == ActionOutputStepperPositioning::ResetPosition
  507. {
  508. m_label->hide();
  509. m_spinBox->hide();
  510. m_label2->hide();
  511. m_spinBox2->hide();
  512. m_labelVmin->hide();
  513. m_spinVmin->hide();
  514. m_labelVmax->hide();
  515. m_spinVmax->hide();
  516. }
  517. }
  518. Action* ActionOutputStepperPositioningWidget::assemble()
  519. {
  520. ActionOutputStepperPositioning* action = new ActionOutputStepperPositioning();
  521. action->setPositioningType( (ActionOutputStepperPositioning::PositioningType) m_comboType->currentIndex() );
  522. action->setDualPosition( m_spinBox->value(), m_spinBox2->value(), m_spinVmin->value(), m_spinVmax->value());
  523. action->setPosition( m_spinBox->value() );
  524. return action;
  525. }
  526. void ActionOutputStepperPositioningWidget::edit(Action* act)
  527. {
  528. ActionOutputStepperPositioning* action = (ActionOutputStepperPositioning*)act;
  529. m_comboType->setCurrentIndex( action->getPositioningType() );
  530. m_spinBox->setValue( action->getPosition() );
  531. m_spinBox2->setValue( action->getDualPosition2() );
  532. m_spinVmin->setValue( action->getDualVmin() );
  533. m_spinVmax->setValue( action->getDualVmax() );
  534. }
  535. ActionOutputStepperSetParamWidget::ActionOutputStepperSetParamWidget(QWidget* parent, Script* script) : IActionWidget(parent)
  536. {
  537. QGridLayout* layout = new QGridLayout(this);
  538. // remove spacing around widget, it looks kind of odd otherwise
  539. layout->setContentsMargins(0, 0, 0, 0);
  540. unsigned int i = 0;
  541. QLabel* m_labelIrun = new QLabel("Irun", this);
  542. m_comboIrun = new QComboBox(this);
  543. m_comboIrun->addItem("keep");
  544. m_comboIrun->addItem("set");
  545. m_spinIrun = new QSpinBox(this);
  546. m_spinIrun->setMinimum(0);
  547. m_spinIrun->setMaximum(0xF);
  548. layout->addWidget(m_labelIrun, i, 0);
  549. layout->addWidget(m_comboIrun, i, 1);
  550. layout->addWidget(m_spinIrun, i, 2);
  551. i++;
  552. QLabel* m_labelIhold = new QLabel("Ihold", this);
  553. m_comboIhold = new QComboBox(this);
  554. m_comboIhold->addItem("keep");
  555. m_comboIhold->addItem("set");
  556. m_spinIhold = new QSpinBox(this);
  557. m_spinIhold->setMinimum(0);
  558. m_spinIhold->setMaximum(0xF);
  559. layout->addWidget(m_labelIhold, i, 0);
  560. layout->addWidget(m_comboIhold, i, 1);
  561. layout->addWidget(m_spinIhold, i, 2);
  562. i++;
  563. QLabel* m_labelVmax = new QLabel("Vmax", this);
  564. m_comboVmax = new QComboBox(this);
  565. m_comboVmax->addItem("keep");
  566. m_comboVmax->addItem("set");
  567. m_spinVmax = new QSpinBox(this);
  568. m_spinVmax->setMinimum(0);
  569. m_spinVmax->setMaximum(0xF);
  570. layout->addWidget(m_labelVmax, i, 0);
  571. layout->addWidget(m_comboVmax, i, 1);
  572. layout->addWidget(m_spinVmax, i, 2);
  573. i++;
  574. QLabel* m_labelVmin = new QLabel("Vmin", this);
  575. m_comboVmin = new QComboBox(this);
  576. m_comboVmin->addItem("keep");
  577. m_comboVmin->addItem("set");
  578. m_spinVmin = new QSpinBox(this);
  579. m_spinVmin->setMinimum(0);
  580. m_spinVmin->setMaximum(0xF);
  581. layout->addWidget(m_labelVmin, i, 0);
  582. layout->addWidget(m_comboVmin, i, 1);
  583. layout->addWidget(m_spinVmin, i, 2);
  584. i++;
  585. QLabel* m_labelMinSamples = new QLabel("Min Samples", this);
  586. m_comboMinSamples = new QComboBox(this);
  587. m_comboMinSamples->addItem("keep");
  588. m_comboMinSamples->addItem("set");
  589. m_spinMinSamples = new QSpinBox(this);
  590. m_spinMinSamples->setMinimum(0);
  591. m_spinMinSamples->setMaximum(0x7);
  592. layout->addWidget(m_labelMinSamples, i, 0);
  593. layout->addWidget(m_comboMinSamples, i, 1);
  594. layout->addWidget(m_spinMinSamples, i, 2);
  595. i++;
  596. QLabel* m_labelShaft = new QLabel("Shaft", this);
  597. m_comboShaft = new QComboBox(this);
  598. m_comboShaft->addItem("keep");
  599. m_comboShaft->addItem("set");
  600. m_spinShaft = new QSpinBox(this);
  601. m_spinShaft->setMinimum(0);
  602. m_spinShaft->setMaximum(1);
  603. layout->addWidget(m_labelShaft, i, 0);
  604. layout->addWidget(m_comboShaft, i, 1);
  605. layout->addWidget(m_spinShaft, i, 2);
  606. i++;
  607. QLabel* m_labelAcc = new QLabel("Acceleration", this);
  608. m_comboAcc = new QComboBox(this);
  609. m_comboAcc->addItem("keep");
  610. m_comboAcc->addItem("set");
  611. m_spinAcc = new QSpinBox(this);
  612. m_spinAcc->setMinimum(0);
  613. m_spinAcc->setMaximum(0xF);
  614. layout->addWidget(m_labelAcc, i, 0);
  615. layout->addWidget(m_comboAcc, i, 1);
  616. layout->addWidget(m_spinAcc, i, 2);
  617. i++;
  618. QLabel* m_labelAbsThr = new QLabel("Absolut Threshold", this);
  619. m_comboAbsThr = new QComboBox(this);
  620. m_comboAbsThr->addItem("keep");
  621. m_comboAbsThr->addItem("set");
  622. m_spinAbsThr = new QSpinBox(this);
  623. m_spinAbsThr->setMinimum(0);
  624. m_spinAbsThr->setMaximum(0xF);
  625. layout->addWidget(m_labelAbsThr, i, 0);
  626. layout->addWidget(m_comboAbsThr, i, 1);
  627. layout->addWidget(m_spinAbsThr, i, 2);
  628. i++;
  629. QLabel* m_labelDelThr = new QLabel("Delta Threshold", this);
  630. m_comboDelThr = new QComboBox(this);
  631. m_comboDelThr->addItem("keep");
  632. m_comboDelThr->addItem("set");
  633. m_spinDelThr = new QSpinBox(this);
  634. m_spinDelThr->setMinimum(0);
  635. m_spinDelThr->setMaximum(0xF);
  636. layout->addWidget(m_labelDelThr, i, 0);
  637. layout->addWidget(m_comboDelThr, i, 1);
  638. layout->addWidget(m_spinDelThr, i, 2);
  639. i++;
  640. QLabel* m_labelFS2StallEn = new QLabel("FS2 Stall Enabled", this);
  641. m_comboFS2StallEn = new QComboBox(this);
  642. m_comboFS2StallEn->addItem("keep");
  643. m_comboFS2StallEn->addItem("set");
  644. m_spinFS2StallEn = new QSpinBox(this);
  645. m_spinFS2StallEn->setMinimum(0);
  646. m_spinFS2StallEn->setMaximum(0x7);
  647. layout->addWidget(m_labelFS2StallEn, i, 0);
  648. layout->addWidget(m_comboFS2StallEn, i, 1);
  649. layout->addWidget(m_spinFS2StallEn, i, 2);
  650. i++;
  651. QLabel* m_labelAccShape = new QLabel("Acceleration Shape", this);
  652. m_comboAccShape = new QComboBox(this);
  653. m_comboAccShape->addItem("keep");
  654. m_comboAccShape->addItem("set");
  655. m_spinAccShape = new QSpinBox(this);
  656. m_spinAccShape->setMinimum(0);
  657. m_spinAccShape->setMaximum(1);
  658. layout->addWidget(m_labelAccShape, i, 0);
  659. layout->addWidget(m_comboAccShape, i, 1);
  660. layout->addWidget(m_spinAccShape, i, 2);
  661. i++;
  662. QLabel* m_labelStepMode= new QLabel("Step Mode", this);
  663. m_comboStepMode = new QComboBox(this);
  664. m_comboStepMode->addItem("keep");
  665. m_comboStepMode->addItem("set");
  666. m_spinStepMode = new QSpinBox(this);
  667. m_spinStepMode->setMinimum(0);
  668. m_spinStepMode->setMaximum(3);
  669. layout->addWidget(m_labelStepMode, i, 0);
  670. layout->addWidget(m_comboStepMode, i, 1);
  671. layout->addWidget(m_spinStepMode, i, 2);
  672. i++;
  673. QLabel* m_labelDC100StEn= new QLabel("DC100StEn", this);
  674. m_comboDC100StEn = new QComboBox(this);
  675. m_comboDC100StEn->addItem("keep");
  676. m_comboDC100StEn->addItem("set");
  677. m_spinDC100StEn = new QSpinBox(this);
  678. m_spinDC100StEn->setMinimum(0);
  679. m_spinDC100StEn->setMaximum(1);
  680. layout->addWidget(m_labelDC100StEn, i, 0);
  681. layout->addWidget(m_comboDC100StEn, i, 1);
  682. layout->addWidget(m_spinDC100StEn, i, 2);
  683. i++;
  684. QLabel* m_labelPWMJEn= new QLabel("PWM Jitter Enable", this);
  685. m_comboPWMJEn = new QComboBox(this);
  686. m_comboPWMJEn->addItem("keep");
  687. m_comboPWMJEn->addItem("set");
  688. m_spinPWMJEn = new QSpinBox(this);
  689. m_spinPWMJEn->setMinimum(0);
  690. m_spinPWMJEn->setMaximum(1);
  691. layout->addWidget(m_labelPWMJEn, i, 0);
  692. layout->addWidget(m_comboPWMJEn, i, 1);
  693. layout->addWidget(m_spinPWMJEn, i, 2);
  694. i++;
  695. QLabel* m_labelPWMfreq= new QLabel("PWM Frequency", this);
  696. QLabel* m_labelPWMfreq2 = new QLabel("set");
  697. m_spinPWMfreq = new QSpinBox(this);
  698. m_spinPWMfreq->setMinimum(0);
  699. m_spinPWMfreq->setMaximum(1);
  700. layout->addWidget(m_labelPWMfreq, i, 0);
  701. layout->addWidget(m_labelPWMfreq2, i, 1);
  702. layout->addWidget(m_spinPWMfreq, i, 2);
  703. i++;
  704. QLabel* m_labelSecPos = new QLabel("Secure Position", this);
  705. m_comboSecPos = new QComboBox(this);
  706. m_comboSecPos->addItem("keep");
  707. m_comboSecPos->addItem("set");
  708. m_spinSecPos = new QSpinBox(this);
  709. m_spinSecPos->setMinimum(0);
  710. m_spinSecPos->setMaximum(0x03FF);
  711. layout->addWidget(m_labelSecPos, i, 0);
  712. layout->addWidget(m_comboSecPos, i, 1);
  713. layout->addWidget(m_spinSecPos, i, 2);
  714. i++;
  715. this->setLayout(layout);
  716. }
  717. Action* ActionOutputStepperSetParamWidget::assemble()
  718. {
  719. ActionOutputStepperSetParam* action = new ActionOutputStepperSetParam();
  720. HWOutputStepper::Param param;
  721. param.irunSet = m_comboIrun->currentIndex();
  722. param.irun = m_spinIrun->value();
  723. param.iholdSet = m_comboIhold->currentIndex();
  724. param.ihold = m_spinIhold->value();
  725. param.vmaxSet = m_comboVmax->currentIndex();
  726. param.vmax = m_spinVmax->value();
  727. param.vminSet = m_comboVmin->currentIndex();
  728. param.vmin = m_spinVmin->value();
  729. param.accShapeSet = m_comboAccShape->currentIndex();
  730. param.accShape = m_spinAccShape->value();
  731. param.stepModeSet = m_comboStepMode->currentIndex();
  732. param.stepMode = m_spinStepMode->value();
  733. param.shaftSet = m_comboShaft->currentIndex();
  734. param.shaft = m_spinShaft->value();
  735. param.accSet = m_comboAcc->currentIndex();
  736. param.acc = m_spinAcc->value();
  737. param.absoluteThresholdSet = m_comboAbsThr->currentIndex();
  738. param.absoluteThreshold = m_spinAbsThr->value();
  739. param.deltaThresholdSet = m_comboDelThr->currentIndex();
  740. param.deltaThreshold = m_spinDelThr->value();
  741. param.securePositionSet = m_comboSecPos->currentIndex();
  742. param.securePosition = m_spinSecPos->value();
  743. param.fs2StallEnabledSet = m_comboFS2StallEn->currentIndex();
  744. param.fs2StallEnabled = m_spinFS2StallEn->value();
  745. param.minSamplesSet = m_comboMinSamples->currentIndex();
  746. param.minSamples = m_spinMinSamples->value();
  747. param.dc100StallEnableSet = m_comboDC100StEn->currentIndex();
  748. param.dc100StallEnable = m_spinDC100StEn->value();
  749. param.PWMJitterEnableSet = m_comboPWMJEn->currentIndex();
  750. param.PWMJitterEnable = m_spinPWMJEn->value();
  751. param.PWMfreqSet = true; // TODO: Make this adjustable
  752. param.PWMfreq = m_spinPWMfreq->value();
  753. action->setParam(param);
  754. return action;
  755. }
  756. void ActionOutputStepperSetParamWidget::edit(Action* act)
  757. {
  758. ActionOutputStepperSetParam* action = (ActionOutputStepperSetParam*)act;
  759. HWOutputStepper::Param param = action->getParam();
  760. m_comboIrun->setCurrentIndex( param.irunSet );
  761. m_spinIrun->setValue( param.irun );
  762. m_comboIhold->setCurrentIndex( param.iholdSet );
  763. m_spinIhold->setValue( param.ihold );
  764. m_comboVmax->setCurrentIndex( param.vmaxSet );
  765. m_spinVmax->setValue( param.vmax );
  766. m_comboVmin->setCurrentIndex( param.vminSet );
  767. m_spinVmin->setValue( param.vmin );
  768. m_comboAccShape->setCurrentIndex( param.accShapeSet );
  769. m_spinAccShape->setValue( param.accShape );
  770. m_comboStepMode->setCurrentIndex( param.stepModeSet );
  771. m_spinStepMode->setValue( param.stepMode );
  772. m_comboShaft->setCurrentIndex( param.shaftSet );
  773. m_spinShaft->setValue( param.shaft );
  774. m_comboAcc->setCurrentIndex( param.accSet );
  775. m_spinAcc->setValue( param.acc );
  776. m_comboAbsThr->setCurrentIndex( param.absoluteThresholdSet );
  777. m_spinAbsThr->setValue( param.absoluteThreshold );
  778. m_comboDelThr->setCurrentIndex( param.deltaThresholdSet );
  779. m_spinDelThr->setValue( param.deltaThreshold );
  780. m_comboSecPos->setCurrentIndex( param.securePositionSet );
  781. m_spinSecPos->setValue( param.securePosition );
  782. m_comboFS2StallEn->setCurrentIndex( param.fs2StallEnabledSet );
  783. m_spinFS2StallEn->setValue( param.fs2StallEnabled );
  784. m_comboMinSamples->setCurrentIndex( param.minSamplesSet );
  785. m_spinMinSamples->setValue( param.minSamples );
  786. m_comboDC100StEn->setCurrentIndex( param.dc100StallEnableSet );
  787. m_spinDC100StEn->setValue( param.dc100StallEnable );
  788. m_comboPWMJEn->setCurrentIndex( param.PWMJitterEnableSet );
  789. m_spinPWMJEn->setValue( param.PWMJitterEnable );
  790. m_spinPWMfreq->setValue( param.PWMfreq );
  791. }
  792. ActionVariableWidget::ActionVariableWidget(QWidget* parent, Script *script) : IActionWidget(parent)
  793. {
  794. m_combo = new QComboBox(this);
  795. m_label = new QLabel("Select variable", this);
  796. // fill combo box with all variables
  797. std::list<Variable*> listVariable = script->getVariableList();
  798. for(std::list<Variable*>::iterator it = listVariable.begin(); it != listVariable.end(); it++)
  799. {
  800. m_combo->addItem((*it)->getName().c_str());
  801. }
  802. m_comboOperator = new QComboBox(this);
  803. m_comboOperator->addItem("=");
  804. m_comboOperator->addItem("+=");
  805. m_comboOperator->addItem("-=");
  806. m_labelOperator = new QLabel("Set variable", this);
  807. m_spinOperand = new QSpinBox(this);
  808. m_spinOperand->setMinimum(-100);
  809. m_spinOperand->setMaximum(100);
  810. m_layout = new QGridLayout(this);
  811. // remove spacing around widget, it looks kind of odd otherwise
  812. m_layout->setContentsMargins(0, 0, 0, 0);
  813. // add our widgets to the layout
  814. m_layout->addWidget(m_label, 0, 0);
  815. m_layout->addWidget(m_combo, 0, 1, 1, 2);
  816. m_layout->addWidget(m_labelOperator, 1, 0);
  817. m_layout->addWidget(m_comboOperator, 1, 1);
  818. m_layout->addWidget(m_spinOperand, 1, 2);
  819. this->setLayout(m_layout);
  820. }
  821. void ActionVariableWidget::edit(Action* act)
  822. {
  823. ActionVariable* action = (ActionVariable*)act;
  824. QString str = QString::fromStdString( action->getVarName() );
  825. for(int i = 0; i < m_combo->count(); i++)
  826. {
  827. if( m_combo->itemText(i).compare(str, Qt::CaseInsensitive) == 0 )
  828. {
  829. m_combo->setCurrentIndex(i);
  830. break;
  831. }
  832. }
  833. m_comboOperator->setCurrentIndex( action->getOperator() );
  834. m_spinOperand->setValue( action->getOperand() );
  835. }
  836. Action* ActionVariableWidget::assemble()
  837. {
  838. ActionVariable* action = new ActionVariable();
  839. action->setVarName( m_combo->currentText().toStdString() );
  840. action->setOperator( (ActionVariable::Operator)m_comboOperator->currentIndex() );
  841. action->setOperand( m_spinOperand->value() );
  842. return action;
  843. }
  844. ActionSleepWidget::ActionSleepWidget(QWidget* parent, Script *script) : IActionWidget(parent)
  845. {
  846. m_label = new QLabel("Sleep for", this);
  847. m_spinWaitMs = new QSpinBox(this);
  848. m_spinWaitMs->setMinimum(0);
  849. m_spinWaitMs->setMaximum(30 * 1000);
  850. m_labelMs = new QLabel("ms", this);
  851. m_layout = new QGridLayout(this);
  852. // remove spacing around widget, it looks kind of odd otherwise
  853. m_layout->setContentsMargins(0, 0, 0, 0);
  854. // add our widgets to the layout
  855. m_layout->addWidget(m_label, 0, 0);
  856. m_layout->addWidget(m_spinWaitMs, 0, 1);
  857. m_layout->addWidget(m_labelMs, 0, 2);
  858. this->setLayout(m_layout);
  859. }
  860. void ActionSleepWidget::edit(Action* act)
  861. {
  862. ActionSleep* action = (ActionSleep*)act;
  863. m_spinWaitMs->setValue( action->getWaitMs() );
  864. }
  865. Action* ActionSleepWidget::assemble()
  866. {
  867. ActionSleep* action = new ActionSleep();
  868. action->setWaitMs( m_spinWaitMs->value() );
  869. return action;
  870. }
  871. ActionCallRuleWidget::ActionCallRuleWidget(QWidget* parent, Script *script) : IActionWidget(parent)
  872. {
  873. m_label = new QLabel("Select rule", this);
  874. m_comboRule = new QComboBox(this);
  875. // fill combo box with all rule names
  876. std::vector<Rule*> list = script->getRuleList();
  877. for(std::vector<Rule*>::iterator it = list.begin(); it != list.end(); it++)
  878. {
  879. m_comboRule->addItem((*it)->getName().c_str());
  880. }
  881. m_layout = new QGridLayout(this);
  882. // remove spacing around widget, it looks kind of odd otherwise
  883. m_layout->setContentsMargins(0, 0, 0, 0);
  884. // add our widgets to the layout
  885. m_layout->addWidget(m_label, 0, 0);
  886. m_layout->addWidget(m_comboRule, 0, 1);
  887. this->setLayout(m_layout);
  888. }
  889. void ActionCallRuleWidget::edit(Action* act)
  890. {
  891. ActionCallRule* action = (ActionCallRule*)act;
  892. QString str = QString::fromStdString( action->getRuleName() );
  893. for(int i = 0; i < m_comboRule->count(); i++)
  894. {
  895. if( m_comboRule->itemText(i).compare(str, Qt::CaseInsensitive) == 0 )
  896. {
  897. m_comboRule->setCurrentIndex(i);
  898. break;
  899. }
  900. }
  901. }
  902. Action* ActionCallRuleWidget::assemble()
  903. {
  904. ActionCallRule* action = new ActionCallRule();
  905. action->setRuleName( m_comboRule->currentText().toStdString() );
  906. return action;
  907. }
  908. ActionMusicWidget::ActionMusicWidget(QWidget* parent, Script *script) : IActionWidget(parent)
  909. {
  910. QLabel* label = new QLabel("Select type", this);
  911. m_combo = new QComboBox(this);
  912. m_combo->addItem( "Play music" );
  913. m_combo->addItem( "Stop music" );
  914. m_labelMusic = new QLabel(this);
  915. m_buttonSelect = new QPushButton("Select", this);
  916. QGridLayout* layout = new QGridLayout(this);
  917. // remove spacing around widget, it looks kind of odd otherwise
  918. layout->setContentsMargins(0, 0, 0, 0);
  919. // add our widgets to the layout
  920. layout->addWidget(label, 0, 0);
  921. layout->addWidget(m_combo, 0, 1);
  922. layout->addWidget(m_labelMusic, 1, 0, 1, 2);
  923. layout->addWidget(m_buttonSelect, 2, 1);
  924. this->setLayout(layout);
  925. // connect all signals-slots
  926. connect(m_buttonSelect, SIGNAL(clicked()), this, SLOT(selectMusic()));
  927. connect(m_combo, SIGNAL(currentIndexChanged(int)), this, SLOT(comboChanged(int)));
  928. }
  929. void ActionMusicWidget::selectMusic()
  930. {
  931. QFileDialog dialog;
  932. dialog.setNameFilter("*.mp3 *.wav *.ogg *.flac");
  933. if( dialog.exec() == QDialog::Accepted )
  934. m_labelMusic->setText( dialog.selectedFiles().front() );
  935. }
  936. void ActionMusicWidget::comboChanged(int index)
  937. {
  938. if(index == ActionMusic::Play)
  939. {
  940. m_labelMusic->show();
  941. m_buttonSelect->show();
  942. }
  943. else
  944. {
  945. m_labelMusic->hide();
  946. m_buttonSelect->hide();
  947. }
  948. }
  949. void ActionMusicWidget::edit(Action* act)
  950. {
  951. ActionMusic* action = (ActionMusic*)act;
  952. m_combo->setCurrentIndex( action->getMusicAction() );
  953. m_labelMusic->setText( QString::fromStdString( action->getFilename() ) );
  954. }
  955. Action* ActionMusicWidget::assemble()
  956. {
  957. ActionMusic* action = new ActionMusic();
  958. action->setMusicAction( (ActionMusic::MusicAction)m_combo->currentIndex() );
  959. action->setFilename( m_labelMusic->text().toStdString() );
  960. return action;
  961. }