void CQReportDefinition::btnCopyReportClicked() { btnCommitClicked(); CCopasiDataModel* pDataModel = mpObject->getObjectDataModel(); if (pDataModel == NULL) return; CReportDefinition * pRep = new CReportDefinition(*dynamic_cast<CReportDefinition*>(CCopasiRootContainer::getKeyFactory()->get(mKey))); std::string baseName = pRep->getObjectName() + "_copy"; std::string name = baseName; int i = 1; while (pDataModel->getReportDefinitionList()->getIndex(name) != C_INVALID_INDEX) { i++; name = baseName + TO_UTF8(QString::number(i)); } pRep->setObjectName(name); pDataModel->getReportDefinitionList()->add(pRep, true); std::string key = pRep->getKey(); protectedNotify(ListViews::REPORT, ListViews::ADD, key); enter(key); mpListView->switchToOtherWidget(C_INVALID_INDEX, key); }
bool CQReportDM::removeRows(QModelIndexList rows, const QModelIndex&) { if (rows.isEmpty()) return false; assert(mpDataModel != NULL); CCopasiVector< CReportDefinition > * pReportList = mpDataModel->getReportDefinitionList(); if (pReportList == NULL) return false; QList< CReportDefinition * > Reports; QModelIndexList::const_iterator i; for (i = rows.begin(); i != rows.end(); ++i) { if (!isDefaultRow(*i) && &pReportList->operator[](i->row())) Reports.append(&pReportList->operator[](i->row())); } QList< CReportDefinition * >::const_iterator j; for (j = Reports.begin(); j != Reports.end(); ++j) { CReportDefinition * pReport = *j; size_t delRow = pReportList->getIndex(pReport); if (delRow != C_INVALID_INDEX) { std::set< const CCopasiObject * > DeletedObjects; DeletedObjects.insert(pReport); QMessageBox::StandardButton choice = CQMessageBox::confirmDelete(NULL, "report", FROM_UTF8(pReport->getObjectName()), DeletedObjects); if (choice == QMessageBox::Ok) { removeRow((int) delRow); } } } return true; }
QVariant CQReportDM::data(const QModelIndex &index, int role) const { if (!index.isValid()) return QVariant(); if (index.row() >= rowCount()) return QVariant(); if (index.column() > 0 && role == Qt::ForegroundRole && !(flags(index) & Qt::ItemIsEditable)) return QColor(Qt::darkGray); if (role == Qt::DisplayRole || role == Qt::EditRole) { if (isDefaultRow(index)) { switch (index.column()) { case COL_ROW_NUMBER: return QVariant(QString("")); case COL_NAME_REPORTS: return QVariant(QString("New Report")); default: return QVariant(QString("")); } } else { CReportDefinition *pRepDef = &mpDataModel->getReportDefinitionList()->operator[](index.row()); switch (index.column()) { case COL_ROW_NUMBER: return QVariant(index.row() + 1); case COL_NAME_REPORTS: return QVariant(QString(FROM_UTF8(pRepDef->getObjectName()))); } } } return QVariant(); }
/** * Creates the data generators for SEDML. */ void CSEDMLExporter::createDataGenerators(CCopasiDataModel & dataModel, std::string & taskId, CCopasiTask* task) { const CModel* pModel = dataModel.getModel(); std::vector<std::string> stringsContainer; //split string container if (pModel == NULL) CCopasiMessage(CCopasiMessage::ERROR, "SED-ML: No model for this SED-ML document. An SBML model must exist for every SED-ML document."); SedPlot2D* pPSedPlot; SedCurve* pCurve; // = pPSedPlot->createCurve(); //create generator for special varibale time const CCopasiObject* pTime = static_cast<const CCopasiObject *>(dataModel.getModel()->getObject(CCopasiObjectName("Reference=Time"))); SedDataGenerator *pTimeDGenp = this->mpSEDMLDocument->createDataGenerator(); pTimeDGenp->setId("time"); pTimeDGenp->setName(pTime->getObjectName()); SedVariable *pTimeVar = pTimeDGenp->createVariable(); pTimeVar->setId("var_time"); pTimeVar->setTaskReference(taskId); pTimeVar->setSymbol(SEDML_TIME_URN); pTimeDGenp->setMath(SBML_parseFormula(pTimeVar->getId().c_str())); size_t i, imax = dataModel.getPlotDefinitionList()->size(); SedDataGenerator *pPDGen; if (imax == 0 && (task == NULL || task->getReport().getTarget().empty())) CCopasiMessage(CCopasiMessage::ERROR, "SED-ML: No plot/report definition for this SED-ML document."); // export report if (task != NULL && !task->getReport().getTarget().empty()) { CReportDefinition* def = task->getReport().getReportDefinition(); if (def != NULL) { SedReport* pReport = mpSEDMLDocument->createReport(); std::string name = def->getObjectName(); SEDMLUtils::removeCharactersFromString(name, "[]"); // pReport->setId(SEDMLUtils::getNextId("report", mpSEDMLDocument->getNumOutputs())); pReport->setName(name); std::vector<CRegisteredObjectName> header = *def->getHeaderAddr(); std::vector<CRegisteredObjectName> body = def->isTable() ? *def->getTableAddr() : *def->getBodyAddr(); int dsCount = 0; for (size_t i = 0; i < body.size(); ++i) { CRegisteredObjectName& current = body[i]; if (current == def->getSeparator().getCN()) continue; CCopasiObject *object = dataModel.getDataObject(current); if (object == NULL) continue; const std::string& typeX = object->getObjectName(); std::string xAxis = object->getObjectDisplayName(); std::string targetXPathStringX = SEDMLUtils::getXPathAndName(xAxis, typeX, pModel, dataModel); if (object->getCN() == pTime->getCN()) pPDGen = pTimeDGenp; else pPDGen = createDataGenerator( this->mpSEDMLDocument, xAxis, targetXPathStringX, taskId, i, 0 ); SedDataSet* pDS = pReport->createDataSet(); pDS->setId(SEDMLUtils::getNextId("ds", ++dsCount)); if (def->isTable()) { CCopasiObject *headerObj = NULL; if (header.size() > i) headerObj = dataModel.getDataObject(header[i]); else headerObj = dataModel.getDataObject(body[i]); if (headerObj != NULL) pDS->setLabel(headerObj->getObjectDisplayName()); else pDS->setLabel(xAxis); } else pDS->setLabel(xAxis); pDS->setDataReference(pPDGen->getId()); } } } // export plots for (i = 0; i < imax; i++) { pPSedPlot = this->mpSEDMLDocument->createPlot2D(); const CPlotSpecification* pPlot = (*dataModel.getPlotDefinitionList())[i]; std::string plotName = pPlot->getObjectName(); SEDMLUtils::removeCharactersFromString(plotName, "[]"); pPSedPlot->setId(SEDMLUtils::getNextId("plot", mpSEDMLDocument->getNumOutputs())); pPSedPlot->setName(plotName); size_t j, jmax = pPlot->getItems().size(); for (j = 0; j < jmax; j++) { const CPlotItem* pPlotItem = pPlot->getItems()[j]; CCopasiObject *objectX, *objectY; if (pPlotItem->getChannels().size() >= 1) { objectX = dataModel.getDataObject(pPlotItem->getChannels()[0]); } else { CCopasiMessage(CCopasiMessage::WARNING, "SED-ML: Can't export plotItem '%s', as it has no data channel.", pPlotItem->getObjectName().c_str()); continue; } if (objectX == NULL) { CCopasiMessage(CCopasiMessage::WARNING, "SED-ML: Can't export plotItem '%s' variable '%s', as it cannot be resolved.", pPlotItem->getObjectName().c_str(), pPlotItem->getChannels()[0].c_str()); continue; } bool xIsTime = objectX->getCN() == pTime->getCN(); if (pPlotItem->getChannels().size() >= 2) { objectY = dataModel.getDataObject(pPlotItem->getChannels()[1]); } else { CCopasiMessage(CCopasiMessage::WARNING, "SED-ML: Can't export plotItem '%s', as it has only 1 data channel.", pPlotItem->getObjectName().c_str()); continue; } if (objectY == NULL) { CCopasiMessage(CCopasiMessage::WARNING, "SED-ML: Can't export plotItem '%s' variable '%s', as it cannot be resolved.", pPlotItem->getObjectName().c_str(), pPlotItem->getChannels()[1].c_str()); continue; } const std::string& type = objectY->getObjectName(); std::string yAxis = objectY->getObjectDisplayName(); std::string sbmlId = yAxis; std::string targetXPathString = SEDMLUtils::getXPathAndName(sbmlId, type, pModel, dataModel); if (targetXPathString.empty()) { CCopasiMessage(CCopasiMessage::WARNING, "SED-ML: Can't export plotItem '%s' variable '%s', as no xpath expression for it could be generated.", pPlotItem->getObjectName().c_str(), pPlotItem->getChannels()[1].c_str()); continue; } pPDGen = createDataGenerator( this->mpSEDMLDocument, sbmlId, targetXPathString, taskId, i, j ); pPDGen->setName(yAxis); pCurve = pPSedPlot->createCurve(); std::ostringstream idCurveStrStream; idCurveStrStream << "p"; idCurveStrStream << i + 1; idCurveStrStream << "_curve_"; idCurveStrStream << j + 1; pCurve->setId(idCurveStrStream.str()); pCurve->setLogX(pPlot->isLogX()); pCurve->setLogY(pPlot->isLogY()); pCurve->setName(yAxis); pCurve->setYDataReference(pPDGen->getId()); if (xIsTime) { pCurve->setXDataReference(pTimeDGenp->getId()); } else { const std::string& typeX = objectX->getObjectName(); std::string xAxis = objectX->getObjectDisplayName(); std::string targetXPathStringX = SEDMLUtils::getXPathAndName(xAxis, typeX, pModel, dataModel); pPDGen = createDataGenerator( this->mpSEDMLDocument, xAxis, targetXPathStringX, taskId, i, j ); pCurve->setXDataReference(pPDGen->getId()); } } } }