20 #include <QFileDialog>
21 #include <QMessageBox>
65 _semiStaticPartitioning(false),
99 _models =
new QList<ModelInfo>();
117 QString _mname(tr(
"New Model"));
119 QSettings settings(QCoreApplication::applicationDirPath() +
"/qss-solver.ini", QSettings::IniFormat);
120 int _tab = settings.value(
"Editor/tab",
"Value not found in file qss-solver.ini").toInt();
121 _textEditor->setTabStopDistance(_tab);
122 if (!file.fileName().isEmpty()) {
124 _mname = fi.fileName();
125 QIODevice::OpenModeFlag om = QIODevice::ReadWrite;
127 _textEditor->setPlainText(file.readAll());
129 QMessageBox::critical(
this, QString(tr(
"Error")), QString(tr(
"Can't open file.")));
133 QTextDocument *td =
new QTextDocument(_textEditor->toPlainText(),
this);
135 QPlainTextDocumentLayout *layout =
new QPlainTextDocumentLayout(td);
136 td->setDocumentLayout(layout);
137 _textEditor->setDocument(td);
138 if (name.endsWith(QString(
".log"))) {
144 setWindowTitle(_mname);
152 if (event->nativeScanCode() == 117 && (event->nativeModifiers() & 4)) {
154 }
else if (event->nativeScanCode() == 112 && (event->nativeModifiers() & 4)) {
157 QWidget::keyReleaseEvent(event);
173 return _models->value(idx).dirty();
181 return _models->value(idx).name();
195 return _models->value(idx).baseName();
206 if (idx < 0)
return QString();
207 return _models->value(idx).fullname();
219 if (!
_models->value(idx).name().endsWith(
".log")) {
220 if (!
_models->value(idx).dirty()) {
244 QMessageBox::StandardButton res = QMessageBox::question(
this,
"Save", QString(
"Save changes to file ") + mi.
name() + QString(
"?"),
245 QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);
246 if (res == QMessageBox::Save) {
248 }
else if (res == QMessageBox::Cancel) {
270 QTextEdit *_textEditor = qobject_cast<QTextEdit *>(
_model_editor_tab->widget(tab));
273 emit
done(name, ext);
337 if (!file.open(QIODevice::ReadWrite | QIODevice::Truncate)) {
338 QMessageBox::critical(
this, QString(tr(
"Error")), QString(tr(
"Can't open file ")) + mi.
name());
344 QMessageBox::critical(
this, QString(tr(
"Error")), QString(tr(
"Can't open text editor.")));
348 QString _data = _textEditor->toPlainText();
349 if (file.write(_data.toStdString().c_str()) == -1) {
350 QMessageBox::critical(
this, QString(tr(
"Error")), QString(tr(
"Can't write data ")) + mi.
name());
355 QMessageBox::critical(
this, QString(tr(
"Error")), QString(tr(
"Can't save file ")) + mi.
name());
360 _textEditor->document()->setModified(
false);
367 QStringList values = value.split(
"=");
369 if (token ==
"MMO_Output" || token ==
"MMO_BDF_Part") {
370 int index = value.indexOf(
"=");
371 for (
int a = index + 1; a < value.size(); a++) {
372 tmpValue += value[a];
375 tmpValue = values[1];
377 if (tmpValue.size() == 1) {
380 values = tmpValue.split(
"{");
381 if (values.size() > 1) {
382 return values[1].split(
"}")[0];
384 return tmpValue.split(
",")[0];
391 QTextCursor tc = _textEditor->textCursor();
392 tc.movePosition(QTextCursor::Start);
393 _textEditor->setTextCursor(tc);
394 if (_textEditor->find(token)) {
395 return _textEditor->textCursor().position();
413 QTextCursor tc = _textEditor->textCursor();
414 tc.select(QTextCursor::LineUnderCursor);
415 QString line = tc.selection().toPlainText();
416 return line.isEmpty();
422 if (tag ==
"Tolerance" || tag ==
"AbsTolerance" || tag ==
"MMO_Output" || tag ==
"MMO_Period" || tag ==
"MMO_PatohSettings" ||
423 tag ==
"MMO_ScotchSettings" || tag ==
"MMO_BDF_Part" || tag ==
"MMO_MetisSettings") {
428 addLine(QString(
"\t\t").append(tag).append(
"=").append(add).append(
","));
430 addLine(QString(
"\t\t").append(tag).append(
"=").append(add));
438 QTextCursor tc = _textEditor->textCursor();
439 tc.movePosition(QTextCursor::Start);
440 _textEditor->setTextCursor(tc);
441 return _textEditor->find(str);
450 QTextCursor tc = _textEditor->textCursor();
451 tc.movePosition(QTextCursor::Start);
452 _textEditor->setTextCursor(tc);
454 QString end =
"end ";
455 end.append(mName).append(
";");
456 if (_textEditor->find(
"model ")) {
457 tc = _textEditor->textCursor();
461 _textEditor->setTextCursor(tc);
462 if (_textEditor->find(QString(
"experiment"))) {
463 QString annotEnd(
"));");
464 tc = _textEditor->textCursor();
465 if (tc.position() > endModelPos) {
468 tc.select(QTextCursor::LineUnderCursor);
469 line = tc.selection().toPlainText();
470 if (!line.endsWith(annotEnd)) {
471 _textEditor->moveCursor(QTextCursor::Down);
472 tc = _textEditor->textCursor();
473 tc.select(QTextCursor::LineUnderCursor);
474 line = tc.selection().toPlainText();
476 while (!line.endsWith(annotEnd) && c < 100) {
477 _textEditor->moveCursor(QTextCursor::Down);
478 tc = _textEditor->textCursor();
479 tc.select(QTextCursor::LineUnderCursor);
480 line = tc.selection().toPlainText();
484 _textEditor->moveCursor(QTextCursor::Down);
485 tc = _textEditor->textCursor();
486 tc.select(QTextCursor::LineUnderCursor);
487 line = tc.selection().toPlainText();
489 while (line.isEmpty() && c < 100) {
490 _textEditor->moveCursor(QTextCursor::Down);
491 tc = _textEditor->textCursor();
492 tc.select(QTextCursor::LineUnderCursor);
493 line = tc.selection().toPlainText();
496 return line.contains(end);
508 QTextCursor tc = _textEditor->textCursor();
509 tc.movePosition(QTextCursor::Start);
510 _textEditor->setTextCursor(tc);
512 QString end =
"end ";
513 end.append(mName).append(
";");
515 if (_textEditor->find(end)) {
516 if (_textEditor->find(
"experiment", QTextDocument::FindBackward)) {
517 tc = _textEditor->textCursor();
518 if (_textEditor->find(
"annotation", QTextDocument::FindBackward)) {
519 tc = _textEditor->textCursor();
520 if (tc.position() > endModelPos) {
523 int np = tc.position();
524 tc.select(QTextCursor::BlockUnderCursor);
525 line = tc.selection().toPlainText();
526 if (!line.contains(
"experiment")) {
527 _textEditor->moveCursor(QTextCursor::Down);
528 tc = _textEditor->textCursor();
530 if (ep > endModelPos) {
534 tc.select(QTextCursor::BlockUnderCursor);
535 line = tc.selection().toPlainText();
536 if (!line.contains(
"experiment")) {
541 tc.select(QTextCursor::BlockUnderCursor);
542 line = tc.selection().toPlainText();
543 if (line.contains(end))
return QString();
544 tc = _textEditor->textCursor();
545 tc.select(QTextCursor::BlockUnderCursor);
546 line = tc.selection().toPlainText();
548 while (!line.contains(end) && c < 100) {
549 tc.select(QTextCursor::BlockUnderCursor);
550 _textEditor->moveCursor(QTextCursor::Down);
551 tc = _textEditor->textCursor();
552 tc.select(QTextCursor::BlockUnderCursor);
553 line = tc.selection().toPlainText();
554 annotations.append(line.trimmed());
558 _textEditor->moveCursor(QTextCursor::Down);
562 QStringList annotationValue = annotations.split(str);
564 if (annotationValue.size() > 1) {
586 QTextCursor tc = _textEditor->textCursor();
587 tc.setPosition(modelInit);
588 _textEditor->setTextCursor(tc);
589 if (_textEditor->find(
"function ")) {
591 tc = _textEditor->textCursor();
592 if (tc.position() <= modelEnd) {
593 tc.select(QTextCursor::LineUnderCursor);
594 fname = tc.selection().toPlainText().remove(
"function ").trimmed();
595 int lastFunction = tc.position();
596 _textEditor->moveCursor(QTextCursor::Down);
597 while (_textEditor->find(
"function ")) {
598 tc = _textEditor->textCursor();
599 if (tc.position() > modelEnd) {
602 tc.select(QTextCursor::LineUnderCursor);
603 fname = tc.selection().toPlainText().remove(
"function ").trimmed();
604 lastFunction = tc.position();
605 _textEditor->moveCursor(QTextCursor::Down);
607 tc.setPosition(lastFunction);
608 _textEditor->setTextCursor(tc);
609 if (_textEditor->find(
"end " + fname)) {
610 return _textEditor->textCursor().position();
621 QTextCursor tc = _textEditor->textCursor();
622 tc.setPosition(position);
623 _textEditor->setTextCursor(tc);
624 tc.select(QTextCursor::LineUnderCursor);
625 QString line = tc.selection().toPlainText();
627 while (line.isEmpty() && c < 100) {
628 _textEditor->moveCursor(QTextCursor::Down);
629 tc = _textEditor->textCursor();
630 tc.select(QTextCursor::LineUnderCursor);
631 line = tc.selection().toPlainText();
634 return tc.position();
640 QMessageBox::information(
this,
"Simulation Settings",
"Simulation annotations must be located at the end of the file.");
647 QTextCursor tc = _textEditor->textCursor();
648 tc.movePosition(QTextCursor::Start);
649 _textEditor->setTextCursor(tc);
651 QString end =
"end ";
652 end.append(mName).append(
";");
653 if (_textEditor->find(end)) {
654 if (_textEditor->find(
"experiment", QTextDocument::FindBackward)) {
655 tc = _textEditor->textCursor();
656 if (_textEditor->find(
"annotation", QTextDocument::FindBackward)) {
657 tc = _textEditor->textCursor();
658 if (tc.position() > endModelPos) {
661 int np = tc.position();
662 tc.select(QTextCursor::BlockUnderCursor);
663 line = tc.selection().toPlainText();
664 if (!line.contains(
"experiment")) {
665 _textEditor->moveCursor(QTextCursor::Down);
666 tc = _textEditor->textCursor();
668 if (ep > endModelPos) {
672 tc.select(QTextCursor::BlockUnderCursor);
673 line = tc.selection().toPlainText();
674 if (!line.contains(
"experiment")) {
679 tc.select(QTextCursor::BlockUnderCursor);
680 line = tc.selection().toPlainText();
681 tc.removeSelectedText();
682 if (line.contains(end))
return;
683 tc = _textEditor->textCursor();
684 tc.select(QTextCursor::BlockUnderCursor);
685 line = tc.selection().toPlainText();
687 while (!line.contains(end) && c < 100) {
688 tc.removeSelectedText();
689 tc.select(QTextCursor::BlockUnderCursor);
690 _textEditor->moveCursor(QTextCursor::Down);
691 tc = _textEditor->textCursor();
692 tc.select(QTextCursor::BlockUnderCursor);
693 line = tc.selection().toPlainText();
697 _textEditor->moveCursor(QTextCursor::Down);
699 QString text = _textEditor->toPlainText();
700 text = text.trimmed();
701 _textEditor->setPlainText(text);
710 QString path = mi.
path();
711 QFile file(path +
"/" +
"pkg_" + bfn +
".moo");
719 QTextCursor tc = _textEditor->textCursor();
720 tc.movePosition(QTextCursor::Start);
721 _textEditor->setTextCursor(tc);
723 if (_textEditor->find(QString(
"model "))) {
724 tc = _textEditor->textCursor();
725 tc.select(QTextCursor::LineUnderCursor);
726 line = tc.selection().toPlainText();
727 return line.remove(
"model ").trimmed();
734 for (
const auto &annotation : annotations) {
736 if (!annot_value.isEmpty()) {
758 QString end =
"end ";
759 end.append(mName).append(
";");
760 addLine(QString(
"\tannotation("));
761 addLine(QString(
"\texperiment("));
796 QTextCursor tc = _textEditor->textCursor();
797 tc.movePosition(QTextCursor::Start);
798 _textEditor->setTextCursor(tc);
799 if (_textEditor->find(end)) {
800 tc = _textEditor->textCursor();
801 tc.select(QTextCursor::LineUnderCursor);
802 tc.removeSelectedText();
803 _textEditor->moveCursor(QTextCursor::Up);
804 tc = _textEditor->textCursor();
805 tc.select(QTextCursor::LineUnderCursor);
806 QString line = tc.selection().toPlainText();
808 while (line.isEmpty() && c < 100) {
809 _textEditor->moveCursor(QTextCursor::Up);
810 tc = _textEditor->textCursor();
811 tc.select(QTextCursor::LineUnderCursor);
812 line = tc.selection().toPlainText();
815 _textEditor->moveCursor(QTextCursor::Down);
817 tc = _textEditor->textCursor();
819 _textEditor->insertPlainText(
"\n");
821 tc.select(QTextCursor::LineUnderCursor);
822 line = tc.selection().toPlainText();
823 if (!line.isEmpty()) {
824 _textEditor->moveCursor(QTextCursor::Up);
825 _textEditor->insertPlainText(
"\n");
828 _textEditor->insertPlainText(an);
829 _textEditor->moveCursor(QTextCursor::Down);
831 tc = _textEditor->textCursor();
833 _textEditor->insertPlainText(
"\n");
835 tc.select(QTextCursor::LineUnderCursor);
836 line = tc.selection().toPlainText();
837 if (!line.isEmpty()) {
838 _textEditor->moveCursor(QTextCursor::Up);
839 _textEditor->insertPlainText(
"\n");
842 _textEditor->insertPlainText(end);
843 tc = _textEditor->textCursor();
845 _textEditor->insertPlainText(
"\n");