customgenerator.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #include "customgenerator.h"
  2. #include "ui_customgenerator.h"
  3. #include <IterationCompiler.h>
  4. CustomGenerator::CustomGenerator(mnd::MandelContext& mndCtxt, QWidget *parent) :
  5. QDialog{ parent },
  6. mndCtxt{ mndCtxt },
  7. ui{ new Ui::CustomGenerator }
  8. {
  9. ui->setupUi(this);
  10. }
  11. CustomGenerator::~CustomGenerator()
  12. {
  13. delete ui;
  14. }
  15. void CustomGenerator::compile()
  16. {
  17. QString z0formula = this->ui->formula_z0->text();
  18. QString ziformula = this->ui->formula_zi->text();
  19. mnd::IterationFormula zi{ mnd::parse(ziformula.toStdString()), { "c", "z" } };
  20. mnd::IterationFormula z0{ mnd::parse(z0formula.toStdString()), { "c" } };
  21. mnd::GeneratorCollection cr;
  22. try {
  23. //std::cout << mnd::toString(*z0.expr) << std::endl;
  24. //std::cout << mnd::toString(*zi.expr) << std::endl;
  25. cr = mnd::compileFormula(mndCtxt, z0, zi);
  26. }
  27. catch(const mnd::ParseError& pe) {
  28. printf("Parse error: %s\n", pe.what());
  29. return;
  30. }
  31. catch(const std::string& e) {
  32. printf("error: %s\n", e.c_str());
  33. return;
  34. }
  35. /*catch(const char* e) {
  36. printf("error: %s\n", e);
  37. return;
  38. }*/
  39. fflush(stdout);
  40. fractalDefs.push_back(FractalDef {
  41. "name",
  42. z0formula,
  43. ziformula,
  44. std::move(cr)
  45. });
  46. }
  47. void CustomGenerator::on_compile_clicked()
  48. {
  49. compile();
  50. }
  51. FractalDef* CustomGenerator::getLastCompiled(void)
  52. {
  53. if (!fractalDefs.empty())
  54. return &fractalDefs[fractalDefs.size() - 1];
  55. else
  56. return nullptr;
  57. }
  58. void CustomGenerator::on_buttonBox_accepted()
  59. {
  60. compile();
  61. }