/*! * \brief ModelicaEditor::getClassNames * Uses the OMC parseString API to check the class names inside the Modelica Text * \param errorString * \return QStringList a list of class names * \sa ModelWidget::modelicaEditorTextChanged() */ QStringList ModelicaEditor::getClassNames(QString *errorString) { OMCProxy *pOMCProxy = mpMainWindow->getOMCProxy(); QStringList classNames; LibraryTreeItem *pLibraryTreeItem = mpModelWidget->getLibraryTreeItem(); if (mpPlainTextEdit->toPlainText().isEmpty()) { *errorString = tr("Start and End modifiers are different"); return QStringList(); } else { QString modelicaText = mpPlainTextEdit->toPlainText(); QString stringToParse = modelicaText; if (!modelicaText.startsWith("within")) { stringToParse = QString("within %1;%2").arg(pLibraryTreeItem->parent()->getNameStructure()).arg(modelicaText); } classNames = pOMCProxy->parseString(stringToParse, pLibraryTreeItem->getFileName()); } // if user is defining multiple top level classes. if (classNames.size() > 1) { *errorString = QString(GUIMessages::getMessage(GUIMessages::MULTIPLE_TOP_LEVEL_CLASSES)).arg(pLibraryTreeItem->getNameStructure()) .arg(classNames.join(",")); return QStringList(); } bool existModel = false; QStringList existingmodelsList; // check if the class already exists foreach(QString className, classNames) { if (pLibraryTreeItem->getNameStructure().compare(className) != 0) { if (mpMainWindow->getLibraryWidget()->getLibraryTreeModel()->findLibraryTreeItem(className)) { existingmodelsList.append(className); existModel = true; } } } // check if existModel is true if (existModel) { *errorString = QString(GUIMessages::getMessage(GUIMessages::REDEFINING_EXISTING_CLASSES)).arg(existingmodelsList.join(",")).append("\n") .append(GUIMessages::getMessage(GUIMessages::DELETE_AND_LOAD).arg("")); return QStringList(); } return classNames; }
/*! Slot activated when mpOkButton clicked signal is raised.\n Adds or edit the breakpoint. */ void BreakpointDialog::addOrEditBreakpoint() { int lineNumber = mpLineNumberTextBox->text().toInt(); BreakpointMarker *pBreakpointMarker; QFileInfo fileInfo(mpFileNameTextBox->text()); if (fileInfo.exists()) { /* if user has selected a file using Browse File System button. */ if (!mpBreakpointTreeItem) { /* Add Case */ pBreakpointMarker = new BreakpointMarker(mpFileNameTextBox->text(), lineNumber, mpBreakpointsTreeModel); pBreakpointMarker->setEnabled(mpEnableCheckBox->isChecked()); pBreakpointMarker->setIgnoreCount(mpIgnoreCountSpinBox->value()); pBreakpointMarker->setCondition(mpConditionTextBox->text()); mpBreakpointsTreeModel->insertBreakpoint(pBreakpointMarker, 0, mpBreakpointsTreeModel->getRootBreakpointTreeItem()); } else { /* Edit Case */ /* find the BreakpointMarker and update its filepath and lineNumber. */ pBreakpointMarker = mpBreakpointsTreeModel->findBreakpointMarker(mpBreakpointTreeItem->getFilePath(), mpBreakpointTreeItem->getLineNumber().toInt()); pBreakpointMarker->setFilePath(mpFileNameTextBox->text()); pBreakpointMarker->setLineNumber(lineNumber); pBreakpointMarker->setEnabled(mpEnableCheckBox->isChecked()); pBreakpointMarker->setIgnoreCount(mpIgnoreCountSpinBox->value()); pBreakpointMarker->setCondition(mpConditionTextBox->text()); /* the breakpoint is file system breakpoint now so remove the mark from the previous editor and set LibraryTreeItem to 0. */ if (mpBreakpointTreeItem->getLibraryTreeItem() && mpBreakpointTreeItem->getLibraryTreeItem()->getModelWidget()) { mpBreakpointTreeItem->getLibraryTreeItem()->getModelWidget()->getEditor()->getDocumentMarker()->removeMark(pBreakpointMarker); } mpBreakpointTreeItem->setLibraryTreeItem(0); /* update BreakpointTreeItem filePath and lineNumber. */ mpBreakpointsTreeModel->updateBreakpoint(mpBreakpointTreeItem, mpFileNameTextBox->text(), lineNumber, mpEnableCheckBox->isChecked(), mpIgnoreCountSpinBox->value(), mpConditionTextBox->text()); } } else { /* if user has selected a class using Browse Classes button */ LibraryWidget *pLibraryWidget = MainWindow::instance()->getLibraryWidget(); LibraryTreeItem *pLibraryTreeItem = pLibraryWidget->getLibraryTreeModel()->findLibraryTreeItem(mpFileNameTextBox->text()); if (pLibraryTreeItem) { if (!pLibraryTreeItem->isSaved()) { QMessageBox::critical(this, QString(Helper::applicationName).append(" - ").append(Helper::error), GUIMessages::getMessage(GUIMessages::BREAKPOINT_INSERT_NOT_SAVED).arg(pLibraryTreeItem->getNameStructure()), Helper::ok); return; } else if (pLibraryTreeItem->getLibraryType() != LibraryTreeItem::Modelica) { QMessageBox::critical(this, QString(Helper::applicationName).append(" - ").append(Helper::error), GUIMessages::getMessage(GUIMessages::BREAKPOINT_INSERT_NOT_MODELICA_CLASS).arg(pLibraryTreeItem->getNameStructure()), Helper::ok); return; } else if (!mpBreakpointTreeItem) { /* Add Case */ pBreakpointMarker = new BreakpointMarker(pLibraryTreeItem->getFileName(), lineNumber, mpBreakpointsTreeModel); pBreakpointMarker->setEnabled(mpEnableCheckBox->isChecked()); pBreakpointMarker->setIgnoreCount(mpIgnoreCountSpinBox->value()); pBreakpointMarker->setCondition(mpConditionTextBox->text()); mpBreakpointsTreeModel->insertBreakpoint(pBreakpointMarker, pLibraryTreeItem, mpBreakpointsTreeModel->getRootBreakpointTreeItem()); if (pLibraryTreeItem->getModelWidget()) { pLibraryTreeItem->getModelWidget()->getEditor()->getDocumentMarker()->addMark(pBreakpointMarker, lineNumber); } } else { /* Edit Case */ /* find the BreakpointMarker and update its filepath and lineNumber. */ pBreakpointMarker = mpBreakpointsTreeModel->findBreakpointMarker(mpBreakpointTreeItem->getFilePath(), mpBreakpointTreeItem->getLineNumber().toInt()); // first remove the marker if (mpBreakpointTreeItem->getLibraryTreeItem()->getModelWidget() && mpBreakpointTreeItem->getLibraryTreeItem()->getModelWidget()->getEditor()) { mpBreakpointTreeItem->getLibraryTreeItem()->getModelWidget()->getEditor()->getDocumentMarker()->removeMark(pBreakpointMarker); } // set new attributes for the breakpoint marker pBreakpointMarker->setFilePath(pLibraryTreeItem->getFileName()); pBreakpointMarker->setLineNumber(lineNumber); pBreakpointMarker->setEnabled(mpEnableCheckBox->isChecked()); pBreakpointMarker->setIgnoreCount(mpIgnoreCountSpinBox->value()); pBreakpointMarker->setCondition(mpConditionTextBox->text()); /* the breakpoint is not a file system breakpoint now so set LibraryTreeItem. */ mpBreakpointTreeItem->setLibraryTreeItem(pLibraryTreeItem); /* update BreakpointTreeItem filePath and lineNumber. */ mpBreakpointsTreeModel->updateBreakpoint(mpBreakpointTreeItem, pLibraryTreeItem->getFileName(), lineNumber, mpEnableCheckBox->isChecked(), mpIgnoreCountSpinBox->value(), mpConditionTextBox->text()); if (pLibraryTreeItem->getModelWidget()) { if (!pLibraryTreeItem->getModelWidget()->getEditor()) { pLibraryTreeItem->getModelWidget()->createModelWidgetComponents(); } pLibraryTreeItem->getModelWidget()->getEditor()->getDocumentMarker()->addMark(pBreakpointMarker, lineNumber); } } } else { QMessageBox::critical(this, QString(Helper::applicationName).append(" - ").append(Helper::error), GUIMessages::getMessage(GUIMessages::CLASS_NOT_FOUND).arg(mpFileNameTextBox->text()), Helper::ok); return; } } accept(); }