END_TEST START_TEST ( test_RenderExtension_writeL3Render ) { RenderPkgNamespaces renderns; LayoutPkgNamespaces layoutns; SBMLDocument doc(3,1); doc.enablePackage(layoutns.getURI(), "layout", true); doc.enablePackage(renderns.getURI(), "render", true); Model* model = doc.createModel(); LayoutModelPlugin *lPlugin = (LayoutModelPlugin*)model->getPlugin("layout"); fail_unless(lPlugin != NULL); Layout* layout = lPlugin->createLayout(); Dimensions dim(&layoutns, 100,100 ); layout->setDimensions(&dim); GraphicalObject* additional = layout->createAdditionalGraphicalObject(); additional->setId("go1"); BoundingBox bb(&layoutns, "bb1", 10, 10, 90, 90); additional->setBoundingBox(&bb); RenderLayoutPlugin *rPlugin = (RenderLayoutPlugin*)layout->getPlugin("render"); fail_unless(rPlugin != NULL); LocalRenderInformation* local = rPlugin->createLocalRenderInformation(); ColorDefinition *black = local->createColorDefinition(); black->setId("black"); black->setColorValue("#000000"); LocalStyle *lStyle = local->createStyle("style_go1"); lStyle->addId("go1"); RenderGroup* group = lStyle->getGroup(); group->setStroke("black"); std::string sbml = writeSBMLToStdString(&doc); fail_unless (sbml.length() != 0); }
bool RenderExtension::isInUse(SBMLDocument *doc) const { if (doc == NULL || doc->getModel() == NULL) return false; LayoutModelPlugin* plugin = (LayoutModelPlugin*)doc->getModel()->getPlugin("layout"); if (plugin == NULL || plugin->getNumLayouts() == 0) return false; RenderListOfLayoutsPlugin* lolPlugin = (RenderListOfLayoutsPlugin*) plugin->getListOfLayouts()->getPlugin("render"); if (lolPlugin != NULL && lolPlugin->getNumGlobalRenderInformationObjects() > 0) return true; for(int i = 0; i < plugin->getNumLayouts(); i++) { Layout* layout = plugin->getLayout(i); RenderLayoutPlugin* rPlugin = (RenderLayoutPlugin*)layout->getPlugin("render"); if (rPlugin != NULL && rPlugin->getNumLocalRenderInformationObjects() > 0) return true; } return false; }
void updateNs(Layout *layout) { layout->setSBMLNamespaces(layoutNs); updateNs(layout->getDimensions()); updateNs(layout->getListOfAdditionalGraphicalObjects()); updateNs(layout->getListOfCompartmentGlyphs()); updateNs(layout->getListOfReactionGlyphs()); updateNs(layout->getListOfSpeciesGlyphs()); updateNs(layout->getListOfTextGlyphs()); #ifdef CONVERT_RENDER RenderLayoutPlugin* layoutPlugin = (RenderLayoutPlugin*)layout->getPlugin("render"); if (layoutPlugin != NULL) { updateNs(layoutPlugin->getListOfLocalRenderInformation()); layoutPlugin->setElementNamespace(renderNsUri); } #endif }
LIBSBML_CPP_NAMESPACE_USE void deleteRenderInformationFromLayout(LayoutModelPlugin *lPlugin) { if (lPlugin == NULL) return; RenderListOfLayoutsPlugin *lolPlugin = (RenderListOfLayoutsPlugin*)lPlugin->getListOfLayouts()->getPlugin("render"); if (lolPlugin != NULL) { lolPlugin->getListOfGlobalRenderInformation()->clear(); } for (int i = 0; i < lPlugin->getNumLayouts(); i++) { Layout* current = lPlugin->getLayout(i); if (current == NULL) continue; RenderLayoutPlugin *rPlugins = (RenderLayoutPlugin*) current->getPlugin("render"); if (rPlugins == NULL) continue; rPlugins->getListOfLocalRenderInformation()->clear(); } }
//static CLayout * SBMLDocumentLoader::createLayout(const Layout & sbmlLayout, const std::map<std::string, std::string> & modelmap, std::map<std::string, std::string> & layoutmap #ifdef USE_CRENDER_EXTENSION , const std::map<std::string, std::string>& globalIdToKeyMap //,const std::map<std::string,std::map<std::string,std::string> >& globalColorIdToKeyMapMap //,const std::map<std::string,std::map<std::string,std::string> >& globalGradientIdToKeyMapMap //,const std::map<std::string,std::map<std::string,std::string> >& globalLineEndingIdToKeyMapMap #endif /* USE_CRENDER_EXTENSION */ , const CCopasiContainer * pParent ) { CLayout* layout = new CLayout(sbmlLayout, layoutmap, pParent); //compartments unsigned C_INT32 i, iMax = sbmlLayout.getListOfCompartmentGlyphs()->size(); for (i = 0; i < iMax; ++i) { const CompartmentGlyph* tmp = dynamic_cast<const CompartmentGlyph*>(sbmlLayout.getListOfCompartmentGlyphs()->get(i)); if (tmp) layout->addCompartmentGlyph(new CLCompartmentGlyph(*tmp, modelmap, layoutmap)); } //species iMax = sbmlLayout.getListOfSpeciesGlyphs()->size(); for (i = 0; i < iMax; ++i) { const SpeciesGlyph* tmp = dynamic_cast<const SpeciesGlyph*>(sbmlLayout.getListOfSpeciesGlyphs()->get(i)); if (tmp) layout->addMetaboliteGlyph(new CLMetabGlyph(*tmp, modelmap, layoutmap)); } //reactions iMax = sbmlLayout.getListOfReactionGlyphs()->size(); for (i = 0; i < iMax; ++i) { const ReactionGlyph* tmp = dynamic_cast<const ReactionGlyph*>(sbmlLayout.getListOfReactionGlyphs()->get(i)); if (tmp) layout->addReactionGlyph(new CLReactionGlyph(*tmp, modelmap, layoutmap)); } //text iMax = sbmlLayout.getListOfTextGlyphs()->size(); for (i = 0; i < iMax; ++i) { const TextGlyph* tmp = dynamic_cast<const TextGlyph*>(sbmlLayout.getListOfTextGlyphs()->get(i)); if (tmp) layout->addTextGlyph(new CLTextGlyph(*tmp, modelmap, layoutmap)); } //additional iMax = sbmlLayout.getListOfAdditionalGraphicalObjects()->size(); for (i = 0; i < iMax; ++i) { const GraphicalObject* graphical = dynamic_cast<const GraphicalObject*>(sbmlLayout.getListOfAdditionalGraphicalObjects()->get(i)); if (graphical) layout->addGeneralGlyph(new CLGeneralGlyph(*graphical, modelmap, layoutmap)); } //second pass text (the text glyph can refer to other glyphs. These references can) //only be resolved after all glyphs are created). iMax = sbmlLayout.getListOfTextGlyphs()->size(); for (i = 0; i < iMax; ++i) { const TextGlyph* tmp = dynamic_cast<const TextGlyph*>(sbmlLayout.getListOfTextGlyphs()->get(i)); if (tmp) postprocessTextGlyph(*tmp, layoutmap); } #ifdef USE_CRENDER_EXTENSION RenderLayoutPlugin* rlPlugin = (RenderLayoutPlugin*) sbmlLayout.getPlugin("render"); assert(rlPlugin != NULL); // import the local render information iMax = rlPlugin->getNumLocalRenderInformationObjects(); std::map<std::string, std::string> idToKeyMap; CLLocalRenderInformation* pLRI = NULL; //std::map<std::string,std::string> colorIdToKeyMap; //std::map<std::string,std::string> gradientIdToKeyMap; //std::map<std::string,std::string> lineEndingIdToKeyMap; //std::map<std::string,std::map<std::string,std::string> > colorIdToKeyMapMap; //std::map<std::string,std::map<std::string,std::string> > gradientIdToKeyMapMap; //std::map<std::string,std::map<std::string,std::string> > lineEndingIdToKeyMapMap; for (i = 0; i < iMax; ++i) { //colorIdToKeyMap.clear(); //gradientIdToKeyMap.clear(); //lineEndingIdToKeyMap.clear(); //pLRI=new CLLocalRenderInformation(*sbmlLayout.getRenderInformation(i),colorIdToKeyMap,gradientIdToKeyMap,lineEndingIdToKeyMap,layout); pLRI = new CLLocalRenderInformation(*rlPlugin->getRenderInformation(i), layout); if (rlPlugin->getRenderInformation(i)->isSetId()) idToKeyMap.insert(std::pair<std::string, std::string>(rlPlugin->getRenderInformation(i)->getId(), pLRI->getKey())); else idToKeyMap.insert(std::pair<std::string, std::string>(pLRI->getKey(), pLRI->getKey())); //colorIdToKeyMapMap.insert(std::pair<std::string,std::map<std::string,std::string> >(pLRI->getKey(),colorIdToKeyMap)); //gradientIdToKeyMapMap.insert(std::pair<std::string,std::map<std::string,std::string> >(pLRI->getKey(),gradientIdToKeyMap)); //lineEndingIdToKeyMapMap.insert(std::pair<std::string,std::map<std::string,std::string> >(pLRI->getKey(),lineEndingIdToKeyMap)); // fix the references to layout objects in id lists size_t j, jMax = pLRI->getNumStyles(); for (j = 0; j < jMax; j++) { SBMLDocumentLoader::convertLayoutObjectIds(*(pLRI->getStyle(j)), layoutmap); } layout->addLocalRenderInformation(pLRI); } // fix the references // we have to consider the global ids as well // since all ids in these two map should be unique, we can just combine them size_t count = idToKeyMap.size() + globalIdToKeyMap.size(); idToKeyMap.insert(globalIdToKeyMap.begin(), globalIdToKeyMap.end()); // make sure the ids were really unique assert(idToKeyMap.size() == count); SBMLDocumentLoader::convertRenderInformationReferencesIds<CLLocalRenderInformation>(layout->getListOfLocalRenderInformationObjects(), idToKeyMap); // fix the color ids, gradient ids and line ending ids. /* std::map<std::string,std::map<std::string,std::string> >::const_iterator mapPos; std::map<std::string,std::map<std::string,std::string> > expandedColorIdToKeyMapMap, expandedGradientIdToKeyMapMap, expandedLineEndingIdToKeyMapMap; for(i=0;i < iMax; ++i) { pLRI=dynamic_cast<CLLocalRenderInformation*>(layout->getRenderInformation(i)); assert(pLRI != NULL); std::set<std::string> chain; SBMLDocumentLoader::expandIdToKeyMaps<CLLocalRenderInformation>(pLRI, layout->getListOfLocalRenderInformationObjects(), expandedColorIdToKeyMapMap, expandedGradientIdToKeyMapMap, expandedLineEndingIdToKeyMapMap, colorIdToKeyMapMap, gradientIdToKeyMapMap, lineEndingIdToKeyMapMap, chain, globalColorIdToKeyMapMap, globalGradientIdToKeyMapMap, globalLineEndingIdToKeyMapMap ); SBMLDocumentLoader::convertPropertyKeys<CLLocalRenderInformation>(pLRI,expandedColorIdToKeyMapMap[pLRI->getKey()],expandedGradientIdToKeyMapMap[pLRI->getKey()],expandedLineEndingIdToKeyMapMap[pLRI->getKey()]); } */ #endif /* USE_CRENDER_EXTENSION */ return layout; }
END_TEST START_TEST ( test_RenderExtension_gradient ) { RenderPkgNamespaces renderns; LayoutPkgNamespaces layoutns; SBMLDocument doc(3,1); doc.enablePackage(layoutns.getURI(), "layout", true); doc.enablePackage(renderns.getURI(), "render", true); Model* model = doc.createModel(); LayoutModelPlugin *lPlugin = (LayoutModelPlugin*)model->getPlugin("layout"); fail_unless(lPlugin != NULL); Layout* layout = lPlugin->createLayout(); Dimensions dim(&layoutns, 100,100 ); layout->setDimensions(&dim); GraphicalObject* additional = layout->createAdditionalGraphicalObject(); additional->setId("go1"); BoundingBox bb(&layoutns, "bb1", 10, 10, 90, 90); additional->setBoundingBox(&bb); RenderGraphicalObjectPlugin* goPlugin = (RenderGraphicalObjectPlugin*)additional->getPlugin("render"); fail_unless(goPlugin != NULL); goPlugin->setObjectRole("myRole"); RenderLayoutPlugin *rPlugin = (RenderLayoutPlugin*)layout->getPlugin("render"); fail_unless(rPlugin != NULL); LocalRenderInformation* local = rPlugin->createLocalRenderInformation(); ColorDefinition *black = local->createColorDefinition(); black->setId("black"); black->setColorValue("#000000"); ColorDefinition *grey = local->createColorDefinition(); grey->setId("grey"); grey->setColorValue("#F0F0F0"); LinearGradient* gradient = local->createLinearGradientDefinition(); gradient->setId("test"); gradient->setPoint1(RelAbsVector(), RelAbsVector()); gradient->setPoint2(RelAbsVector(0,100), RelAbsVector(0,100)); GradientStop *stop = gradient->createGradientStop(); stop->setOffset(RelAbsVector()); stop->setStopColor("white"); stop = gradient->createGradientStop(); stop->setOffset(RelAbsVector(0, 100)); stop->setStopColor("silver"); std::string smodel = writeSBMLToStdString(&doc); fail_unless( stop->getStopColor() == "silver" ); }