| 3090 | } |
| 3091 | |
| 3092 | void MainWindow::startVisualisation(const QString& model, const QStringList& data, const QString& key, const QString& url, const QJsonValue& userData, MznProcess* proc) |
| 3093 | { |
| 3094 | |
| 3095 | QSettings settings; |
| 3096 | settings.beginGroup("ide"); |
| 3097 | bool reuseVis = settings.value("reuseVis", false).toBool(); |
| 3098 | int httpPort = settings.value("visPort", 3000).toInt(); |
| 3099 | int wsPort = settings.value("visWsPort", 3100).toInt(); |
| 3100 | bool printUrl = settings.value("printVisUrl", false).toBool(); |
| 3101 | settings.endGroup(); |
| 3102 | |
| 3103 | if (server == nullptr) { |
| 3104 | server = new Server(this); |
| 3105 | } |
| 3106 | try { |
| 3107 | server->listen(httpPort, wsPort); |
| 3108 | } catch (ServerError& e) { |
| 3109 | QMessageBox::warning(this, "MiniZinc IDE", e.message(), QMessageBox::Ok); |
| 3110 | return; |
| 3111 | } |
| 3112 | |
| 3113 | QFileInfo modelFileInfo(model); |
| 3114 | QStringList files({modelFileInfo.fileName()}); |
| 3115 | for (auto& df : data) { |
| 3116 | QFileInfo fi(df); |
| 3117 | files << fi.fileName(); |
| 3118 | } |
| 3119 | auto workingDir = modelFileInfo.canonicalPath(); |
| 3120 | |
| 3121 | auto label = files.join(", "); |
| 3122 | QStringList roots({workingDir, MznDriver::get().mznStdlibDir()}); |
| 3123 | vis_connector = server->addConnector(label, roots); |
| 3124 | connect(vis_connector, &VisConnector::solveRequested, [=] (const QString& modelFile, bool dataFilesGiven, const QStringList& dataFiles, const QVariantMap& options) { |
| 3125 | auto* origSc = getCurrentSolverConfig(); |
| 3126 | if (origSc == nullptr) { |
| 3127 | return; |
| 3128 | } |
| 3129 | QStringList df; |
| 3130 | bool modelFileGiven = !modelFile.isEmpty(); |
| 3131 | auto m = modelFileGiven ? workingDir + "/" + modelFile : model; |
| 3132 | if (!IDEUtils::isChildPath(workingDir, m)) { |
| 3133 | return; |
| 3134 | } |
| 3135 | if (dataFilesGiven) { |
| 3136 | for (const auto& it : dataFiles) { |
| 3137 | auto d = workingDir + "/" + it; |
| 3138 | if (!IDEUtils::isChildPath(workingDir, d)) { |
| 3139 | return; |
| 3140 | } |
| 3141 | df << d; |
| 3142 | } |
| 3143 | } else if (!modelFileGiven) { |
| 3144 | // No model, no data, so use previous |
| 3145 | df = data; |
| 3146 | } |
| 3147 | SolverConfiguration rsc(*origSc); |
| 3148 | QMapIterator<QString, QVariant> i(options); |
| 3149 | while (i.hasNext()) { |
nothing calls this directly
no test coverage detected