choosegenerators.cpp 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. #include "choosegenerators.h"
  2. #include "ui_choosegenerators.h"
  3. #include "Hardware.h"
  4. #include <QComboBox>
  5. #include <QRegExp>
  6. #include <QRegExpValidator>
  7. ChooseGenerators::ChooseGenerators(mnd::MandelContext& mndCtxt, QWidget *parent) :
  8. QDialog{ parent },
  9. ui{ std::make_unique<Ui::ChooseGenerators>() },
  10. mndCtxt{ mndCtxt },
  11. tableContent{}
  12. {
  13. ui->setupUi(this);
  14. QRegExp floatingpoint{ "^[-+]?(\\d*\\.?\\d+|\\d+\\.?\\d*)([eE][-+]\\d+)?$" };
  15. floatValidator = std::make_unique<QRegExpValidator>(floatingpoint, this);
  16. generators = std::map<QString, mnd::Generator*> {
  17. { "float", mndCtxt.getCpuGenerator(mnd::GeneratorType::FLOAT) },
  18. { "double", mndCtxt.getCpuGenerator(mnd::GeneratorType::DOUBLE) },
  19. { "double double", mndCtxt.getCpuGenerator(mnd::GeneratorType::DOUBLE_DOUBLE) },
  20. { "quad double", mndCtxt.getCpuGenerator(mnd::GeneratorType::QUAD_DOUBLE) },
  21. { "float256", mndCtxt.getCpuGenerator(mnd::GeneratorType::FLOAT256) },
  22. };
  23. if (mndCtxt.getCpuInfo().hasSse2()) {
  24. generators.insert({ "float SSE2", mndCtxt.getCpuGenerator(mnd::GeneratorType::FLOAT_SSE2) });
  25. generators.insert({ "double SSE2", mndCtxt.getCpuGenerator(mnd::GeneratorType::DOUBLE_SSE2) });
  26. }
  27. if (mndCtxt.getCpuInfo().hasAvx()) {
  28. generators.insert({ "float AVX", mndCtxt.getCpuGenerator(mnd::GeneratorType::FLOAT_AVX) });
  29. generators.insert({ "double AVX", mndCtxt.getCpuGenerator(mnd::GeneratorType::DOUBLE_AVX) });
  30. }
  31. if (mndCtxt.getCpuInfo().hasNeon()) {
  32. generators.insert({ "float Neon", mndCtxt.getCpuGenerator(mnd::GeneratorType::FLOAT_NEON) });
  33. generators.insert({ "double Neon", mndCtxt.getCpuGenerator(mnd::GeneratorType::DOUBLE_NEON) });
  34. }
  35. for (auto& device : mndCtxt.getDevices()) {
  36. if (mnd::Generator* gen; (gen = device.getGenerator(mnd::GeneratorType::FLOAT))) {
  37. generators.insert({ QString("float ") + QString::fromStdString(device.getName()),
  38. gen });
  39. }
  40. if (mnd::Generator* gen; (gen = device.getGenerator(mnd::GeneratorType::DOUBLE))) {
  41. generators.insert({ QString("double ") + QString::fromStdString(device.getName()),
  42. gen });
  43. }
  44. if (mnd::Generator* gen; (gen = device.getGenerator(mnd::GeneratorType::DOUBLE_DOUBLE))) {
  45. generators.insert({ QString("double double ") + QString::fromStdString(device.getName()),
  46. gen });
  47. }
  48. }
  49. auto& defGen = mndCtxt.getDefaultGenerator();
  50. for (auto it = defGen.getGenerators().rbegin(); it != defGen.getGenerators().rend(); it++) {
  51. auto& [prec, gen] = *it;
  52. ui->table->insertRow(0);
  53. QLineEdit* le = createFloatText();
  54. QComboBox* comboBox = createComboBox();
  55. le->setSizePolicy(QSizePolicy::Policy::Preferred, QSizePolicy::Policy::Preferred);
  56. comboBox->setSizePolicy(QSizePolicy::Policy::Preferred, QSizePolicy::Policy::Preferred);
  57. ui->table->setCellWidget(0, 0, le);
  58. ui->table->setCellWidget(0, 1, comboBox);
  59. tableContent.push_back({ le, comboBox });
  60. for (auto [n, g] : generators) {
  61. if (gen == g) {
  62. comboBox->setCurrentText(n);
  63. }
  64. }
  65. le->setText(QString::number(static_cast<double>(prec)));
  66. comboBox->adjustSize();
  67. le->adjustSize();
  68. }
  69. ui->table->resizeColumnsToContents();
  70. //ui->addRow->setIcon(ui->addRow->style()->standardIcon(QStyle::SP_));
  71. //ui->moveRowUp->setIcon(ui->moveRowUp->style()->standardIcon(QStyle::SP_ArrowUp));
  72. //ui->moveRowDown->setIcon(ui->moveRowDown->style()->standardIcon(QStyle::SP_ArrowDown));
  73. }
  74. ChooseGenerators::~ChooseGenerators()
  75. {
  76. }
  77. QComboBox* ChooseGenerators::createComboBox(void)
  78. {
  79. QComboBox* qcb = new QComboBox(ui->table);
  80. for (auto [name, type] : generators) {
  81. qcb->addItem(name);
  82. }
  83. return qcb;
  84. }
  85. QLineEdit* ChooseGenerators::createFloatText(void)
  86. {
  87. QLineEdit* le = new QLineEdit(ui->table);
  88. le->setValidator(floatValidator.get());
  89. return le;
  90. }
  91. void ChooseGenerators::on_buttonBox_accepted()
  92. {
  93. if (!createdGenerator)
  94. createdGenerator = std::make_unique<mnd::AdaptiveGenerator>();
  95. createdGenerator->clear();
  96. try {
  97. for (size_t i = 0; i < tableContent.size(); i++) {
  98. //std::cout << tableContent.at(i).first << std::endl;
  99. //std::cout << tableContent.at(i).second << std::endl;
  100. QString precString = tableContent.at(i).first->text();
  101. QString genString = tableContent.at(i).second->currentText();
  102. mnd::Real precision = mnd::Real(precString.toStdString().c_str());
  103. mnd::Generator* generator = generators.at(genString);
  104. if (generator)
  105. createdGenerator->addGenerator(precision, *generator);
  106. }
  107. }
  108. catch(...) {
  109. // TODO
  110. createdGenerator = nullptr;
  111. }
  112. }