Пример #1
0
void placeTextGlyphs(CLayout* pLayout)
{
  size_t i;

  for (i = 0; i < pLayout->getListOfTextGlyphs().size(); ++i)
    {
      CLTextGlyph* pTG = &pLayout->getListOfTextGlyphs()[i];
      CLGraphicalObject* pGO = pTG->getGraphicalObject();

      if (!pGO)
        continue;

      pTG->setPosition(CLPoint(pGO->getX() + 2, pGO->getY() + 2));
    }
}
Пример #2
0
//static
void SBMLDocumentLoader::postprocessTextGlyph(const TextGlyph & sbml,
    const std::map<std::string, std::string> & layoutmap)
{
  //the corresponding CLTextGlyph should already exist. Let's find it...
  CLTextGlyph * pTg = NULL;

  if (sbml.getId() != "")
    {
      std::map<std::string, std::string>::const_iterator it = layoutmap.find(sbml.getId());

      if (it != layoutmap.end())
        pTg = dynamic_cast<CLTextGlyph *>(CCopasiRootContainer::getKeyFactory()->get(it->second));

      if (!pTg)
        {
          //error?
          return;
        }
    }
  else
    {
      //error?
      return;
    }

  //resolve the graphical object reference
  assert(pTg);

  if (sbml.getGraphicalObjectId() != "")
    {
      std::map<std::string, std::string>::const_iterator it = layoutmap.find(sbml.getGraphicalObjectId());

      if (it != layoutmap.end())
        pTg->setGraphicalObjectKey(it->second);
    }
}
Пример #3
0
void CLayout::exportToSBML(Layout * layout, const std::map<CCopasiObject*, SBase*> & copasimodelmap,
                           std::map<std::string, const SBase*>& sbmlIDs) const
{
  if (!layout) return;

  //Name and ID
  std::string id = CSBMLExporter::createUniqueId(sbmlIDs, "layout_");
  layout->setId(id);
  sbmlIDs.insert(std::pair<const std::string, const SBase*>(id, layout));
  //we do not check if the layout is already present in the libsbml data
  //structures. This is no big deal since at the moment no software
  //relies on persistent IDs for layout elements.

  //Dimensions
  Dimensions tmpDim = mDimensions.getSBMLDimensions();
  layout->setDimensions(&tmpDim);

  //some of the following code is not used at the moment:  the COPASI model map
  //does not contain glyphs. Since this may change in the future I leave the code
  //below.

  // create a map from COPASI layout object to SBML objects. We do not put
  //the layout objects into the global map (copasimodelmap) but we need to have
  //access to all objects in the current layout since speciesReferenceGlyph and
  //textGlyph need to reference other graphical objects.
  std::map<const CLBase*, const SBase*> layoutmap;

  //Compartment glyphs
  unsigned C_INT32 i, imax = mvCompartments.size();

  for (i = 0; i < imax; ++i)
    {
      CLCompartmentGlyph * tmp = mvCompartments[i];

      //check if the compartment glyph exists in the libsbml data
      std::map<CCopasiObject*, SBase*>::const_iterator it;
      it = copasimodelmap.find(tmp);

      CompartmentGlyph * pCG;

      if (it == copasimodelmap.end()) //not found
        {
          pCG = new CompartmentGlyph;
          layout->getListOfCompartmentGlyphs()->appendAndOwn(pCG);
        }
      else
        {
          pCG = dynamic_cast<CompartmentGlyph*>(it->second);
        }

      layoutmap.insert(std::pair<const CLBase*, const SBase*>(tmp, pCG));
      tmp->exportToSBML(pCG, copasimodelmap, sbmlIDs);
    }

  //Species glyphs
  imax = mvMetabs.size();

  for (i = 0; i < imax; ++i)
    {
      CLMetabGlyph * tmp = mvMetabs[i];

      //check if the glyph exists in the libsbml data
      std::map<CCopasiObject*, SBase*>::const_iterator it;
      it = copasimodelmap.find(tmp);

      SpeciesGlyph * pG;

      if (it == copasimodelmap.end()) //not found
        {
          pG = new SpeciesGlyph;
          layout->getListOfSpeciesGlyphs()->appendAndOwn(pG);
        }
      else
        {
          pG = dynamic_cast<SpeciesGlyph*>(it->second);
        }

      layoutmap.insert(std::pair<const CLBase*, const SBase*>(tmp, pG));
      tmp->exportToSBML(pG, copasimodelmap, sbmlIDs);
    }

  //Reaction glyphs
  imax = mvReactions.size();

  for (i = 0; i < imax; ++i)
    {
      CLReactionGlyph * tmp = mvReactions[i];

      //check if the glyph exists in the libsbml data
      std::map<CCopasiObject*, SBase*>::const_iterator it;
      it = copasimodelmap.find(tmp);

      ReactionGlyph * pG;

      if (it == copasimodelmap.end()) //not found
        {
          pG = new ReactionGlyph;
          layout->getListOfReactionGlyphs()->appendAndOwn(pG);
        }
      else
        {
          pG = dynamic_cast<ReactionGlyph*>(it->second);
        }

      layoutmap.insert(std::pair<const CLBase*, const SBase*>(tmp, pG));
      //we need to pass the layoutmap here for 2 reasons:
      //1. the metabreferenceglyphs need to be added
      //2. the metabreferenceglyphs need to resolve the reference to the metabglyph
      tmp->exportToSBML(pG, copasimodelmap, sbmlIDs, layoutmap);
    }

  //Text glyphs
  imax = mvLabels.size();

  for (i = 0; i < imax; ++i)
    {
      CLTextGlyph * tmp = mvLabels[i];

      //check if the glyph exists in the libsbml data
      std::map<CCopasiObject*, SBase*>::const_iterator it;
      it = copasimodelmap.find(tmp);

      TextGlyph * pG;

      if (it == copasimodelmap.end()) //not found
        {
          pG = new TextGlyph;
          layout->getListOfTextGlyphs()->appendAndOwn(pG);
        }
      else
        {
          pG = dynamic_cast<TextGlyph*>(it->second);
        }

      layoutmap.insert(std::pair<const CLBase*, const SBase*>(tmp, pG));
      tmp->exportToSBML(pG, copasimodelmap, sbmlIDs);
    }

  //generic glyphs
  imax = mvGraphicalObjects.size();

  for (i = 0; i < imax; ++i)
    {
      CLGraphicalObject * tmp = mvGraphicalObjects[i];

      //check if the glyph exists in the libsbml data
      std::map<CCopasiObject*, SBase*>::const_iterator it;
      it = copasimodelmap.find(tmp);

      GraphicalObject * pG;

      if (it == copasimodelmap.end()) //not found
        {
          pG = new GraphicalObject;
          layout->getListOfAdditionalGraphicalObjects()->appendAndOwn(pG);
        }
      else
        {
          pG = dynamic_cast<GraphicalObject*>(it->second);
        }

      layoutmap.insert(std::pair<const CLBase*, const SBase*>(tmp, pG));
      tmp->exportToSBML(pG, copasimodelmap, sbmlIDs);
    }

  //now that we have all graphical objects in the layoutmap we can resolve the references
  //in the text glyphs
  imax = mvLabels.size();

  for (i = 0; i < imax; ++i)
    {
      const CLTextGlyph * tmp = mvLabels[i];

      //find the corresponding SBML object
      std::map<const CLBase*, const SBase*>::const_iterator it = layoutmap.find(tmp);

      if (it != layoutmap.end() && it->second && dynamic_cast<const TextGlyph*>(it->second))
        {
          tmp->exportReferenceToSBML(const_cast<TextGlyph*>(dynamic_cast<const TextGlyph*>(it->second)), layoutmap);
        }
    }
}
Пример #4
0
void CLGeneralGlyph::exportToSBML(GraphicalObject * g, //TODO
                                  const std::map<const CCopasiObject*, SBase*> & copasimodelmap,
                                  std::map<std::string, const SBase*>& sbmlIDs,
                                  std::map<const CLBase*, const SBase*> & layoutmap) const
{
  if (!g) return;

  //call the coresponding method of the base class
  CLGraphicalObject::exportToSBML(g, copasimodelmap, sbmlIDs);

#if LIBSBML_VERSION >= 50800

  GeneralGlyph *general = dynamic_cast<GeneralGlyph *>(g);

  if (!general) return;

  //reference to model objects
  CCopasiObject* tmp = getModelObject();

  if (tmp)
    {
      std::map<const CCopasiObject*, SBase*>::const_iterator it = copasimodelmap.find(tmp);

      if (it != copasimodelmap.end())
        {
          if (it->second)
            general->setReferenceId(it->second->getId());
        }

      const CLBase* base = dynamic_cast<const CLBase*>(tmp);

      if (base)
        {
          std::map<const CLBase*, const SBase*>::const_iterator it2 = layoutmap.find(base);

          if (it2 != layoutmap.end())
            {
              if (it2->second)
                general->setReferenceId(it2->second->getId());
            }
        }
    }

  //curve
  mCurve.exportToSBML(general->getCurve(), copasimodelmap);

  //reference  glyphs
  size_t i, imax = mvReferences.size();

  for (i = 0; i < imax; ++i)
    {
      CLReferenceGlyph * tmp = mvReferences[i];

      //check if the glyph exists in the libsbml data
      std::map<const CCopasiObject*, SBase*>::const_iterator it;
      it = copasimodelmap.find(tmp);

      ReferenceGlyph * pG;

      if (it == copasimodelmap.end()) //not found
        {
          pG = general->createReferenceGlyph();
        }
      else
        {
          pG = dynamic_cast<ReferenceGlyph*>(it->second);
        }

      layoutmap.insert(std::pair<const CLBase*, const SBase*>(tmp, pG));
      tmp->exportToSBML(pG, copasimodelmap, sbmlIDs, layoutmap);
    }

  imax = mvSubglyphs.size();

  for (i = 0; i < imax; ++i)
    {
      CLGraphicalObject * tmp = mvSubglyphs[i];
      CLMetabGlyph * metab =  dynamic_cast<CLMetabGlyph*>(tmp);
      CLCompartmentGlyph* comp =  dynamic_cast<CLCompartmentGlyph*>(tmp);
      CLGeneralGlyph* gg =  dynamic_cast<CLGeneralGlyph*>(tmp);
      CLTextGlyph* text =  dynamic_cast<CLTextGlyph*>(tmp);

      //check if the glyph exists in the libsbml data
      std::map<const CCopasiObject*, SBase*>::const_iterator it;
      it = copasimodelmap.find(tmp);

      GraphicalObject * pG;

      if (it == copasimodelmap.end()) //not found
        {
          if (metab)
            pG = ((Layout*)g->getParentSBMLObject()->getParentSBMLObject())->createSpeciesGlyph();
          else if (comp)
            pG = ((Layout*)g->getParentSBMLObject()->getParentSBMLObject())->createCompartmentGlyph();
          else if (gg)
            pG = ((Layout*)g->getParentSBMLObject()->getParentSBMLObject())->createGeneralGlyph();
          else if (text)
            pG = ((Layout*)g->getParentSBMLObject()->getParentSBMLObject())->createTextGlyph();
          else
            pG = ((Layout*)g->getParentSBMLObject()->getParentSBMLObject())->createAdditionalGraphicalObject();
        }
      else
        {
          pG = dynamic_cast<GraphicalObject*>(it->second);
        }

      layoutmap.insert(std::pair<const CLBase*, const SBase*>(tmp, pG));

      if (metab)
        metab->exportToSBML(static_cast<SpeciesGlyph*>(pG), copasimodelmap, sbmlIDs);
      else if (comp)
        comp->exportToSBML(static_cast<CompartmentGlyph*>(pG), copasimodelmap, sbmlIDs);
      else if (text)
        text->exportToSBML(static_cast<TextGlyph*>(pG), copasimodelmap, sbmlIDs);
      else if (gg)
        gg->exportToSBML(pG, copasimodelmap, sbmlIDs, layoutmap);
      else
        tmp->exportToSBML(pG, copasimodelmap, sbmlIDs);
    }

#endif // LIBSBML_VERSION >= 50800
}
Пример #5
0
CLayout* CCopasiSpringLayout::createLayout(
  CDataContainer *parent,
  const std::set<const CCompartment*>& compartments,
  const std::set<const CReaction*>& reactions,
  const std::set<const CMetab*>& metabs,
  const std::set<const CMetab*>& sideMetabs,
  Parameters* mParams
)
{
  CLayout *pResult = new CLayout("Layout", parent);

  double fontSize = 16.0;
  double fontHeight = fontSize * 1.5;

  // create a species glyph for each species in metabs

  std::map<const CCompartment*, CompartmentInfo> compInfo;
  std::map<const CMetab*, CLMetabGlyph*> metabMap;

  std::set<const CMetab*>::const_iterator metabIt;

  for (metabIt = metabs.begin(); metabIt != metabs.end(); ++metabIt)
    {
      if (sideMetabs.find(*metabIt) != sideMetabs.end())
        continue;

      //estimate the size of the glyph
      double width = (double)((*metabIt)->getObjectName().length() * fontSize);
      double height = (double)fontHeight;

      if (width < height)
        {
          width = height;
        }

      //create the glyph
      CLMetabGlyph* pMetabGlyph = new CLMetabGlyph;
      pMetabGlyph->setDimensions(CLDimensions(width + 4, height + 4));
      pMetabGlyph->setModelObjectKey((*metabIt)->getKey());

      pResult->addMetaboliteGlyph(pMetabGlyph);
      metabMap[*metabIt] = pMetabGlyph;

      //create the text glyph for the label
      CLTextGlyph* pTextGlyph = new CLTextGlyph;
      pTextGlyph->setDimensions(CLDimensions(width, height));
      pTextGlyph->setGraphicalObjectKey(pMetabGlyph->getKey());
      pTextGlyph->setModelObjectKey((*metabIt)->getKey());

      pResult->addTextGlyph(pTextGlyph);

      //add up the sizes for the compartment
      const CCompartment* pComp = NULL;

      if (compartments.find((*metabIt)->getCompartment()) != compartments.end())
        pComp = (*metabIt)->getCompartment();

      compInfo[pComp].add((width + 4) * (height + 4));
    }

  //now the reaction glyphs
  std::set<const CReaction*>::const_iterator reactIt;

  for (reactIt = reactions.begin(); reactIt != reactions.end(); ++reactIt)
    {
      CLReactionGlyph* pReactionGlyph = new CLReactionGlyph;
      //pResult->setDimensions(CLDimensions(width, height));
      pReactionGlyph->setModelObjectKey((*reactIt)->getKey());
      //pReactionGlyph->getCurve().addCurveSegment(CLLineSegment(CLPoint(x, y),
      //                                             CLPoint(x + length, y)));
      bool isReversible = (*reactIt)->isReversible();
      pResult->addReactionGlyph(pReactionGlyph);

      //now add the species reference glyphs.

      //substrates
      const CDataVector < CChemEqElement >& substrates = (*reactIt)->getChemEq().getSubstrates();
      bool substrateExists = false;
      CDataVector<CChemEqElement>::const_iterator elIt;

      for (elIt = substrates.begin(); elIt != substrates.end(); ++elIt)
        {
          const CMetab* pMetab = elIt->getMetabolite();

          if (!pMetab)
            continue;

          CLMetabGlyph* pMetabGlyph = NULL;
          CLMetabReferenceGlyph::Role role; // = CLMetabReferenceGlyph::SUBSTRATE;
          CLMetabReferenceGlyph::Role functionalRole;

          //is it a side reactant? If yes, create a new metab glyph
          if (sideMetabs.find(pMetab) != sideMetabs.end())
            {
              //estimate the size of the glyph
              double width = (double)((pMetab)->getObjectName().length() * fontSize);
              double height = (double)fontHeight;

              if (width < height)
                {
                  width = height;
                }

              //create the glyph
              pMetabGlyph = new CLMetabGlyph;
              pMetabGlyph->setDimensions(CLDimensions(width + 4, height + 4));
              pMetabGlyph->setModelObjectKey(pMetab->getKey());
              //TODO: mark as duplicate
              pResult->addMetaboliteGlyph(pMetabGlyph);

              //create the text glyph for the label
              CLTextGlyph* pTextGlyph = new CLTextGlyph;
              pTextGlyph->setDimensions(CLDimensions(width, height));
              pTextGlyph->setGraphicalObjectKey(pMetabGlyph->getKey());
              pTextGlyph->setModelObjectKey(pMetab->getKey());

              pResult->addTextGlyph(pTextGlyph);

              //add up the sizes for the compartment
              const CCompartment* pComp = NULL;

              if (compartments.find(pMetab->getCompartment()) != compartments.end())
                pComp = pMetab->getCompartment();

              compInfo[pComp].add((width + 4) * (height + 4));

              role = isReversible
                     ? CLMetabReferenceGlyph::SIDEPRODUCT
                     : CLMetabReferenceGlyph::SIDESUBSTRATE;
              functionalRole = CLMetabReferenceGlyph::SIDESUBSTRATE;
            }
          else
            {
              //find the existing metab glyph
              std::map<const CMetab*, CLMetabGlyph*>::const_iterator mmIt;
              mmIt = metabMap.find(pMetab);

              if (mmIt != metabMap.end())
                pMetabGlyph = mmIt->second;

              role = isReversible
                     ? CLMetabReferenceGlyph::PRODUCT
                     : CLMetabReferenceGlyph::SUBSTRATE;
              functionalRole = CLMetabReferenceGlyph::SUBSTRATE;
            }

          if (!pMetabGlyph)
            continue;

          CLMetabReferenceGlyph* pRefGlyph = new CLMetabReferenceGlyph;
          //pResult->setModelObjectKey(modelobjectkey);
          pRefGlyph->setMetabGlyphKey(pMetabGlyph->getKey());
          pRefGlyph->setRole(role);
          pRefGlyph->setFunctionalRole(functionalRole);
          pReactionGlyph->addMetabReferenceGlyph(pRefGlyph);
          substrateExists = true;
        } //substrates

      // if we have no substrates, add a dummy / invisible node for now
      if (!substrateExists)
        {
          CLMetabGlyph* pMetabGlyph = new CLMetabGlyph;
          pMetabGlyph->setDimensions(CLDimensions(1, 1));
          pMetabGlyph->setObjectRole("invisible");
          pResult->addMetaboliteGlyph(pMetabGlyph);

          CLMetabReferenceGlyph* pRefGlyph = new CLMetabReferenceGlyph;
          //pResult->setModelObjectKey(modelobjectkey);
          pRefGlyph->setMetabGlyphKey(pMetabGlyph->getKey());
          pRefGlyph->setRole(CLMetabReferenceGlyph::SUBSTRATE); //TODO side substr?
          pRefGlyph->setFunctionalRole(CLMetabReferenceGlyph::SUBSTRATE);
          pReactionGlyph->addMetabReferenceGlyph(pRefGlyph);
        }

      //products
      const CDataVector < CChemEqElement >& products = (*reactIt)->getChemEq().getProducts();
      bool productExists = false;

      for (elIt = products.begin(); elIt != products.end(); ++elIt)
        {
          const CMetab* pMetab = elIt->getMetabolite();

          if (!pMetab)
            continue;

          CLMetabGlyph* pMetabGlyph = NULL;
          CLMetabReferenceGlyph::Role role; // = CLMetabReferenceGlyph::SUBSTRATE;
          CLMetabReferenceGlyph::Role functionalRole;

          //is it a side reactant? If yes, create a new metab glyph
          if (sideMetabs.find(pMetab) != sideMetabs.end())
            {
              //estimate the size of the glyph
              double width = (double)((pMetab)->getObjectName().length() * fontSize);
              double height = (double)fontHeight;

              if (width < height)
                {
                  width = height;
                }

              //create the glyph
              pMetabGlyph = new CLMetabGlyph;
              pMetabGlyph->setDimensions(CLDimensions(width + 4, height + 4));
              pMetabGlyph->setModelObjectKey(pMetab->getKey());
              //TODO: mark as duplicate
              pResult->addMetaboliteGlyph(pMetabGlyph);

              //create the text glyph for the label
              CLTextGlyph* pTextGlyph = new CLTextGlyph;
              pTextGlyph->setDimensions(CLDimensions(width, height));
              pTextGlyph->setGraphicalObjectKey(pMetabGlyph->getKey());
              pTextGlyph->setModelObjectKey(pMetab->getKey());

              pResult->addTextGlyph(pTextGlyph);

              //add up the sizes for the compartment
              const CCompartment* pComp = NULL;

              if (compartments.find(pMetab->getCompartment()) != compartments.end())
                pComp = pMetab->getCompartment();

              compInfo[pComp].add((width + 4) * (height + 4));

              role = CLMetabReferenceGlyph::SIDEPRODUCT;
              functionalRole = CLMetabReferenceGlyph::SIDEPRODUCT;
            }
          else
            {
              //find the existing metab glyph
              std::map<const CMetab*, CLMetabGlyph*>::const_iterator mmIt;
              mmIt = metabMap.find(pMetab);

              if (mmIt != metabMap.end())
                pMetabGlyph = mmIt->second;

              role = CLMetabReferenceGlyph::PRODUCT;
              functionalRole = CLMetabReferenceGlyph::PRODUCT;
            }

          if (!pMetabGlyph)
            continue;

          CLMetabReferenceGlyph* pRefGlyph = new CLMetabReferenceGlyph;
          //pResult->setModelObjectKey(modelobjectkey);
          pRefGlyph->setMetabGlyphKey(pMetabGlyph->getKey());
          pRefGlyph->setRole(role);
          pRefGlyph->setFunctionalRole(functionalRole);
          pReactionGlyph->addMetabReferenceGlyph(pRefGlyph);
          productExists = true;
        } //products

      // if we have no substrates, add a dummy / invisible node for now
      if (!productExists)
        {
          CLMetabGlyph* pMetabGlyph = new CLMetabGlyph;
          pMetabGlyph->setDimensions(CLDimensions(1, 1));
          pMetabGlyph->setObjectRole("invisible");
          pResult->addMetaboliteGlyph(pMetabGlyph);

          CLMetabReferenceGlyph* pRefGlyph = new CLMetabReferenceGlyph;
          //pResult->setModelObjectKey(modelobjectkey);
          pRefGlyph->setMetabGlyphKey(pMetabGlyph->getKey());
          pRefGlyph->setRole(CLMetabReferenceGlyph::PRODUCT); //TODO side substr?
          pReactionGlyph->addMetabReferenceGlyph(pRefGlyph);
        }

      //modifiers
      const CDataVector < CChemEqElement >& modifiers = (*reactIt)->getChemEq().getModifiers();

      for (elIt = modifiers.begin(); elIt != modifiers.end(); ++elIt)
        {
          const CMetab* pMetab = elIt->getMetabolite();

          if (!pMetab)
            continue;

          CLMetabGlyph* pMetabGlyph = NULL;
          CLMetabReferenceGlyph::Role role; // = CLMetabReferenceGlyph::SUBSTRATE;

          //is it a side reactant? If yes, create a new metab glyph
          if (sideMetabs.find(pMetab) != sideMetabs.end())
            {
              //estimate the size of the glyph
              double width = (double)((pMetab)->getObjectName().length() * fontSize);
              double height = (double)fontHeight;

              if (width < height)
                {
                  width = height;
                }

              //create the glyph
              pMetabGlyph = new CLMetabGlyph;
              pMetabGlyph->setDimensions(CLDimensions(width + 4, height + 4));
              pMetabGlyph->setModelObjectKey(pMetab->getKey());
              //TODO: mark as duplicate
              pResult->addMetaboliteGlyph(pMetabGlyph);

              //create the text glyph for the label
              CLTextGlyph* pTextGlyph = new CLTextGlyph;
              pTextGlyph->setDimensions(CLDimensions(width, height));
              pTextGlyph->setGraphicalObjectKey(pMetabGlyph->getKey());
              pTextGlyph->setModelObjectKey(pMetab->getKey());

              pResult->addTextGlyph(pTextGlyph);

              //add up the sizes for the compartment
              const CCompartment* pComp = NULL;

              if (compartments.find(pMetab->getCompartment()) != compartments.end())
                pComp = pMetab->getCompartment();

              compInfo[pComp].add((width + 4) * (height + 4));

              role = CLMetabReferenceGlyph::MODIFIER; //TODO SIDEMODIFIER???
            }
          else
            {
              //find the existing metab glyph
              std::map<const CMetab*, CLMetabGlyph*>::const_iterator mmIt;
              mmIt = metabMap.find(pMetab);

              if (mmIt != metabMap.end())
                pMetabGlyph = mmIt->second;

              role = CLMetabReferenceGlyph::MODIFIER;
            }

          if (!pMetabGlyph)
            continue;

          CLMetabReferenceGlyph* pRefGlyph = new CLMetabReferenceGlyph;
          //pResult->setModelObjectKey(modelobjectkey);
          pRefGlyph->setMetabGlyphKey(pMetabGlyph->getKey());
          pRefGlyph->setRole(role);
          pReactionGlyph->addMetabReferenceGlyph(pRefGlyph);
        } //modifiers
    } //reactions

  //rules
  size_t i;

  for (i = 0; i < pResult->getListOfMetaboliteGlyphs().size(); ++i)
    {
      const CLMetabGlyph* pMetabGlyph = &pResult->getListOfMetaboliteGlyphs()[i];
      const CMetab* pMetab = dynamic_cast<const CMetab*>(pMetabGlyph->getModelObject());

      if (!pMetab)
        continue;

      if (pMetab->getStatus() == CModelEntity::Status::ODE || pMetab->getStatus() == CModelEntity::Status::ASSIGNMENT)
        {
          CLGeneralGlyph* pGG = new CLGeneralGlyph;
          pGG->setDimensions(CLDimensions(10, 10));
          pGG->setObjectRole("rule");

          pResult->addGeneralGlyph(pGG);

          CLReferenceGlyph* pRefGlyph = new CLReferenceGlyph;
          pRefGlyph->setDimensions(CLDimensions(10, 10));
          pRefGlyph->setTargetGlyphKey(pMetabGlyph->getKey());
          pRefGlyph->setRole("rule connection");
          pGG->addReferenceGlyph(pRefGlyph);
        }
    }

  //after all other glyphs are created, create the compartment glyphs
  double xxx = 0;
  std::set<const CCompartment*>::const_iterator compIt;

  for (compIt = compartments.begin(); compIt != compartments.end(); ++compIt)
    {
      double compSize = 10000;
      std::map<const CCompartment*, CompartmentInfo>::const_iterator ccIt;
      ccIt = compInfo.find(*compIt);

      if (ccIt != compInfo.end())
        {
          //some glyphs are placed inside this compartment glyph
          compSize = ccIt->second.mAreaSum * 40;
        }

      //create the glyph
      CLCompartmentGlyph* pCompGlyph = new CLCompartmentGlyph;
      pCompGlyph->setModelObjectKey((*compIt)->getKey());
      pCompGlyph->setDimensions(CLDimensions(CLDimensions(sqrt(compSize), sqrt(compSize))));
      pCompGlyph->setPosition(CLPoint(xxx, 5));
      xxx += sqrt(compSize) + 10;

      pResult->addCompartmentGlyph(pCompGlyph);
    }

  //
  // double sss = sqrt(compInfo[NULL].mAreaSum * 40);
  //
  // // determine and set the layout dimensions
  // CLBoundingBox box = pResult->calculateBoundingBox();
  // if (box.getDimensions().getWidth() < sss)
  //   box.getDimensions().setWidth(sss);
  //
  // if (box.getDimensions().getHeight() < sss)
  //   box.getDimensions().setHeight(sss);
  //
  // pResult->setDimensions(CLDimensions(box.getDimensions().getWidth() + 30.0, box.getDimensions().getHeight() + 30.0));

  // randomize
  CCopasiSpringLayout l(pResult, mParams);
  l.randomize();

  // determine and set the layout dimensions
  CLBoundingBox box = pResult->calculateBoundingBox();
  pResult->setDimensions(CLDimensions(box.getDimensions().getWidth() + 30.0, box.getDimensions().getHeight() + 30.0));

  return pResult;
}