19 #include "sbml/packages/layout/sbml/Layout.h"
20 #include "sbml/packages/render/sbml/LocalRenderInformation.h"
21 #include "sbml/packages/render/extension/RenderLayoutPlugin.h"
22 #include "sbml/packages/render/extension/RenderListOfLayoutsPlugin.h"
24 #if LIBSBML_VERSION >= 50800
25 #include "sbml/packages/layout/sbml/GeneralGlyph.h"
26 #endif // LIBSBML_VERSION >= 50800
44 mvCompartments(
"ListOfCompartmentGlyphs", this),
45 mvMetabs(
"ListOfMetaboliteGlyphs", this),
46 mvReactions(
"ListOfReactionGlyphs", this),
47 mvLabels(
"ListOfTextGlyphs", this),
48 mvGraphicalObjects(
"ListOfGraphicalObjects", this)
49 , mvLocalRenderInformationObjects(
"ListOfLocalRenderInformationObjects", this)
57 mDimensions(src.mDimensions),
58 mvCompartments(
"ListOfCompartmentGlyphs", this),
59 mvMetabs(
"ListOfMetaboliteGlyphs", this),
60 mvReactions(
"ListOfReactionGlyphs", this),
61 mvLabels(
"ListOfTextGlyphs", this),
62 mvGraphicalObjects(
"ListOfGraphicalObjects", this)
63 , mvLocalRenderInformationObjects(src.mvLocalRenderInformationObjects, this)
68 std::map<std::string, std::string> forward;
69 std::map<std::string, std::string> reverse;
77 forward[(*compIt)->getKey()] = comp->
getKey();
78 reverse[comp->
getKey()] = (*compIt)->getKey();
87 forward[(*metabIt)->getKey()] = metab->
getKey();
88 reverse[metab->
getKey()] = (*metabIt)->getKey();
97 forward[(*reactIt)->getKey()] = r->
getKey();
98 reverse[r->
getKey()] = (*reactIt)->getKey();
102 forward[(*reactIt)->getListOfMetabReferenceGlyphs()[i]->getKey()]
105 = (*reactIt)->getListOfMetabReferenceGlyphs()[i]->getKey();
115 forward[(*textIt)->getKey()] = text->
getKey();
116 reverse[text->
getKey()] = (*textIt)->getKey();
125 forward[(*generalIt)->getKey()] = general->
getKey();
126 reverse[general->
getKey()] = (*generalIt)->getKey();
130 forward[(*generalIt)->getListOfReferenceGlyphs()[i]->getKey()]
133 = (*generalIt)->getListOfReferenceGlyphs()[i]->getKey();
138 forward[(*generalIt)->getListOfSubglyphs()[i]->getKey()]
141 = (*generalIt)->getListOfSubglyphs()[i]->getKey();
148 std::map<std::string, std::string>::const_iterator constIt;
155 constIt = forward.find(key);
157 if (constIt == forward.end())
174 constIt = forward.find(key);
176 if (constIt == forward.end())
194 constIt = forward.find(key);
196 if (constIt == forward.end())
217 std::map<std::string, std::string> & layoutmap,
222 mDimensions(*sbml.getDimensions()),
223 mvCompartments(
"ListOfCompartmentGlyphs", this),
224 mvMetabs(
"ListOfMetaboliteGlyphs", this),
225 mvReactions(
"ListOfReactionGlyphs", this),
226 mvLabels(
"ListOfTextGlyphs", this),
227 mvGraphicalObjects(
"ListOfGraphicalObjects", this)
228 , mvLocalRenderInformationObjects(
"ListOfLocalRenderInformationObjects", this)
231 layoutmap[sbml.getId()] =
mKey;
279 os <<
"List of compartment glyphs: \n\n";
281 for (i = 0; i < imax; ++i)
289 os <<
"\nList of species glyphs: \n\n";
291 for (i = 0; i < imax; ++i)
299 os <<
"\nList of reaction glyphs: \n\n";
301 for (i = 0; i < imax; ++i)
309 os <<
"\nList of labels: \n\n";
311 for (i = 0; i < imax; ++i)
319 os <<
"\nList of graphical objects: \n\n";
321 for (i = 0; i < imax; ++i)
333 os <<
"digraph G {\n";
338 for (i = 0; i < imax; ++i)
346 for (i = 0; i < imax; ++i)
352 size_t j, jmax =
mvReactions[i]->getListOfMetabReferenceGlyphs().
size();
354 for (j = 0; j < jmax; ++j)
365 os <<
"}" << std::endl;
369 const std::string & label,
375 tmp =
" shape=point ";
377 os <<
id <<
" [" << tmp <<
" label=\"" << label <<
"\"] \n";
381 const std::string & id2,
389 os << id1 <<
" -> " << id2 << tmp <<
"\n";
393 std::map<std::string, const SBase*>& sbmlIDs
394 ,
const std::map<std::string, std::string>& globalKeyToIdMap
405 sbmlIDs.insert(std::pair<const std::string, const SBase*>(
id, layout));
412 layout->setDimensions(&tmpDim);
422 std::map<const CLBase*, const SBase*> layoutmap;
427 for (i = 0; i < imax; ++i)
432 std::map<const CCopasiObject*, SBase*>::const_iterator it;
433 it = copasimodelmap.find(tmp);
435 CompartmentGlyph * pCG;
437 if (it == copasimodelmap.end())
439 pCG = layout->createCompartmentGlyph();
443 pCG =
dynamic_cast<CompartmentGlyph*
>(it->second);
446 layoutmap.insert(std::pair<const CLBase*, const SBase*>(tmp, pCG));
453 for (i = 0; i < imax; ++i)
458 std::map<const CCopasiObject*, SBase*>::const_iterator it;
459 it = copasimodelmap.find(tmp);
463 if (it == copasimodelmap.end())
465 pG = layout->createSpeciesGlyph();
469 pG =
dynamic_cast<SpeciesGlyph*
>(it->second);
472 layoutmap.insert(std::pair<const CLBase*, const SBase*>(tmp, pG));
479 for (i = 0; i < imax; ++i)
484 std::map<const CCopasiObject*, SBase*>::const_iterator it;
485 it = copasimodelmap.find(tmp);
489 if (it == copasimodelmap.end())
491 pG = layout->createReactionGlyph();
495 pG =
dynamic_cast<ReactionGlyph*
>(it->second);
498 layoutmap.insert(std::pair<const CLBase*, const SBase*>(tmp, pG));
502 tmp->
exportToSBML(pG, copasimodelmap, sbmlIDs, layoutmap);
508 for (i = 0; i < imax; ++i)
513 std::map<const CCopasiObject*, SBase*>::const_iterator it;
514 it = copasimodelmap.find(tmp);
518 if (it == copasimodelmap.end())
520 pG = layout->createTextGlyph();
524 pG =
dynamic_cast<TextGlyph*
>(it->second);
527 layoutmap.insert(std::pair<const CLBase*, const SBase*>(tmp, pG));
534 for (i = 0; i < imax; ++i)
539 std::map<const CCopasiObject*, SBase*>::const_iterator it;
540 it = copasimodelmap.find(tmp);
542 GraphicalObject * pG;
544 if (it == copasimodelmap.end())
546 #if LIBSBML_VERSION >= 50800
549 pG = layout->createGeneralGlyph();
551 #endif // LIBSBML_VERSION >= 50800
552 pG = layout->createAdditionalGraphicalObject();
556 pG =
dynamic_cast<GraphicalObject*
>(it->second);
559 layoutmap.insert(std::pair<const CLBase*, const SBase*>(tmp, pG));
560 tmp->
exportToSBML(pG, copasimodelmap, sbmlIDs, layoutmap);
567 for (i = 0; i < imax; ++i)
572 std::map<const CLBase*, const SBase*>::const_iterator it = layoutmap.find(tmp);
574 if (it != layoutmap.end() && it->second &&
dynamic_cast<const TextGlyph*
>(it->second))
576 tmp->
exportReferenceToSBML(const_cast<TextGlyph*>(dynamic_cast<const TextGlyph*>(it->second)), layoutmap);
582 LocalRenderInformation* pLRI = NULL;
583 std::map<std::string, std::string> keyToIdMap;
593 for (i = 0; i < imax; ++i)
605 std::map<const CLBase*, const SBase*>::const_iterator layoutMapIt = layoutmap.begin(), layoutMapEndit = layoutmap.end();
606 std::map<std::string, std::string> layoutObjectKeyToIdMap;
609 while (layoutMapIt != layoutMapEndit)
613 if (pGObject != NULL)
615 layoutObjectKeyToIdMap.insert(std::pair<std::string, std::string>(pGObject->
getKey(), layoutMapIt->second->getId()));
621 size_t j, jMax = pLRI->getNumStyles();
623 for (j = 0; j < jMax; ++j)
628 RenderLayoutPlugin* rlolPlugin = (RenderLayoutPlugin*) layout->getPlugin(
"render");
630 if (rlolPlugin == NULL)
632 const std::string uri = (layout->getLevel() < 3 ? RenderExtension::getXmlnsL2() : RenderExtension::getXmlnsL3V1V1());
633 layout->enablePackage(uri,
"render",
true);
635 if (layout->getLevel() > 2)
636 layout->getSBMLDocument()->setPackageRequired(
"render",
false);
638 rlolPlugin = (RenderLayoutPlugin*) layout->getPlugin(
"render");
641 if (rlolPlugin != NULL)
642 rlolPlugin->getListOfLocalRenderInformation()->appendAndOwn(pLRI);
699 for (i = 0; i < iMax; ++i)
709 minX = (minX < x) ? minX : x;
710 minY = (minY < y) ? minY : y;
711 maxX = (maxX > x2) ? maxX : x2;
712 maxY = (maxY > y2) ? maxY : y2;
717 for (i = 0; i < iMax; ++i)
727 minX = (minX < x) ? minX : x;
728 minY = (minY < y) ? minY : y;
729 maxX = (maxX > x2) ? maxX : x2;
730 maxY = (maxY > y2) ? maxY : y2;
735 for (i = 0; i < iMax; ++i)
745 minX = (minX < x) ? minX : x;
746 minY = (minY < y) ? minY : y;
747 maxX = (maxX > x2) ? maxX : x2;
748 maxY = (maxY > y2) ? maxY : y2;
756 for (i = 0; i < iMax; ++i)
770 minX = (minX < x) ? minX : x;
771 minY = (minY < y) ? minY : y;
772 maxX = (maxX > x2) ? maxX : x2;
773 maxY = (maxY > y2) ? maxY : y2;
784 minX = (minX < x) ? minX : x;
785 minY = (minY < y) ? minY : y;
786 maxX = (maxX > x2) ? maxX : x2;
787 maxY = (maxY > y2) ? maxY : y2;
792 for (j = 0; j < jMax; ++j)
806 minX = (minX < x) ? minX : x;
807 minY = (minY < y) ? minY : y;
808 maxX = (maxX > x2) ? maxX : x2;
809 maxY = (maxY > y2) ? maxY : y2;
820 minX = (minX < x) ? minX : x;
821 minY = (minY < y) ? minY : y;
822 maxX = (maxX > x2) ? maxX : x2;
823 maxY = (maxY > y2) ? maxY : y2;
834 for (i = 0; i < iMax; ++i)
848 minX = (minX < x) ? minX : x;
849 minY = (minY < y) ? minY : y;
850 maxX = (maxX > x2) ? maxX : x2;
851 maxY = (maxY > y2) ? maxY : y2;
862 minX = (minX < x) ? minX : x;
863 minY = (minY < y) ? minY : y;
864 maxX = (maxX > x2) ? maxX : x2;
865 maxY = (maxY > y2) ? maxY : y2;
870 for (j = 0; j < jMax; ++j)
884 minX = (minX < x) ? minX : x;
885 minY = (minY < y) ? minY : y;
886 maxX = (maxX > x2) ? maxX : x2;
887 maxY = (maxY > y2) ? maxY : y2;
898 minX = (minX < x) ? minX : x;
899 minY = (minY < y) ? minY : y;
900 maxX = (maxX > x2) ? maxX : x2;
901 maxY = (maxY > y2) ? maxY : y2;
916 for (i = 0; i < iMax; ++i)
924 for (i = 0; i < iMax; ++i)
932 for (i = 0; i < iMax; ++i)
940 for (i = 0; i < iMax; ++i)
948 for (i = 0; i < iMax; ++i)
964 moveBy(differenceToOrigin);
CCopasiVector< CLCompartmentGlyph > mvCompartments
bool remove(const std::string &key)
CLBoundingBox calculateBoundingBox() const
void addReactionGlyph(CLReactionGlyph *glyph)
const C_FLOAT64 & getZ() const
const CCopasiVector< CLTextGlyph > & getListOfTextGlyphs() const
const C_FLOAT64 & getWidth() const
virtual void exportToSBML(ReactionGlyph *g, const std::map< const CCopasiObject *, SBase * > &copasimodelmap, std::map< std::string, const SBase * > &sbmlIDs, std::map< const CLBase *, const SBase * > &layoutmap) const
void writeDotEdge(std::ostream &os, const std::string &id1, const std::string &id2, int t=0) const
void addGeneralGlyph(CLGeneralGlyph *glyph)
const CLBoundingBox & getBoundingBox() const
const std::string & getObjectName() const
void addLocalRenderInformation(CLLocalRenderInformation *pRenderInfo)
virtual size_t size() const
CLayout(const std::string &name="Layout", const CCopasiContainer *pParent=NULL)
Dimensions getSBMLDimensions() const
void setDimensions(const CLDimensions &d)
static void convertLayoutObjectKeys(LocalStyle &style, const std::map< std::string, std::string > &keyToIdMap)
CCopasiVector< CLReactionGlyph > mvReactions
std::ostream & operator<<(std::ostream &os, const CLayout &l)
const CCopasiVector< CLGraphicalObject > & getListOfSubglyphs() const
virtual void exportToSBML(CompartmentGlyph *cg, const std::map< const CCopasiObject *, SBase * > &copasimodelmap, std::map< std::string, const SBase * > &sbmlIDs) const
void setTargetGlyphKey(const std::string &k)
const CLLocalRenderInformation * getRenderInformation(size_t index) const
void addMetaboliteGlyph(CLMetabGlyph *glyph)
const CCopasiVector< CLCompartmentGlyph > & getListOfCompartmentGlyphs() const
static const std::string createUniqueId(const std::map< std::string, const SBase * > &idMap, const std::string &prefix, bool addIndexForFirst, const std::string &separator="_")
virtual const std::string & getKey() const
const CLDimensions & getDimensions() const
void addTextGlyph(CLTextGlyph *glyph)
virtual const std::string & getKey() const
void print(std::ostream *ostream) const
const C_FLOAT64 & getX() const
void writeDotNode(std::ostream &os, const std::string &id, const std::string &label, int t=0) const
const CLPoint & getPosition() const
virtual bool add(const CType &src)
void calculateAndAssignBounds()
const CCopasiVector< CLMetabGlyph > & getListOfMetaboliteGlyphs() const
const CCopasiVector< CLReferenceGlyph > & getListOfReferenceGlyphs() const
CLBoundingBox calculateBoundingBox() const
void setGraphicalObjectKey(const std::string &k)
virtual const std::string & getKey() const
const CCopasiVector< CLGeneralGlyph > & getListOfGeneralGlyphs() const
CCopasiVector< CLTextGlyph > mvLabels
CCopasiVector< CLLocalRenderInformation > mvLocalRenderInformationObjects
void addCompartmentGlyph(CLCompartmentGlyph *glyph)
const C_FLOAT64 & getY() const
static CKeyFactory * getKeyFactory()
const C_FLOAT64 & getHeight() const
CCopasiVector< CLMetabGlyph > mvMetabs
virtual void moveBy(const CLPoint &p)
virtual void moveBy(const CLPoint &p)
void exportReferenceToSBML(TextGlyph *g, const std::map< const CLBase *, const SBase * > &layoutmap) const
CCopasiVector< CLGeneralGlyph > mvGraphicalObjects
const CCopasiVector< CLMetabReferenceGlyph > & getListOfMetabReferenceGlyphs() const
void exportToDotFile(std::ostream &os) const
virtual void exportToSBML(TextGlyph *g, const std::map< const CCopasiObject *, SBase * > &copasimodelmap, std::map< std::string, const SBase * > &sbmlIDs) const
virtual void exportToSBML(GraphicalObject *g, const std::map< const CCopasiObject *, SBase * > &copasimodelmap, std::map< std::string, const SBase * > &sbmlIDs, std::map< const CLBase *, const SBase * > &layoutmap) const
void exportToSBML(Layout *layout, const std::map< const CCopasiObject *, SBase * > &copasimodelmap, std::map< std::string, const SBase * > &sbmlIDs, const std::map< std::string, std::string > &globalKeyToIdMap) const
const std::string & getTargetGlyphKey() const
const CLCurve & getCurve() const
size_t getNumCurveSegments() const
const CCopasiVector< CLReactionGlyph > & getListOfReactionGlyphs() const
const std::string & getGraphicalObjectKey() const