Пример #1
0
CLRenderInformationBase* updateRenderInformationList(QComboBox* list, CCopasiDataModel* dataModel, CLayout* layout)
{

  if (list == NULL || dataModel == NULL) return NULL;

  bool skipGlobal = list->count() > 0;
  CLRenderInformationBase* result = NULL;

  // remove oldItems
  if (skipGlobal)
    {
      for (size_t i = list->count(); i > 0; --i)
        {
          QString current = list->itemText(i - 1);
          int type = list->itemData(i - 1).toInt();

          if (type == RENDERINFORMATION_TYPE_LOCAL)
            list->removeItem(i - 1);
        }
    }

  // add local information
  if (layout != NULL)
    {
      CCopasiVector<CLLocalRenderInformation> & render = layout->getListOfLocalRenderInformationObjects();
      CCopasiVector<CLLocalRenderInformation>::iterator it = render.begin();

      while (it != render.end())
        {
          CLLocalRenderInformation* current = *it;

          if (result == NULL) result = current;

          if (current->getName().empty())
            list->insertItem(0, current->getKey().c_str(), QVariant::fromValue(RENDERINFORMATION_TYPE_LOCAL));
          else
            list->insertItem(0, current->getName().c_str(), QVariant::fromValue(RENDERINFORMATION_TYPE_LOCAL));

          ++it;
        }
    }

  // bail
  if (skipGlobal)
    {
      if (result == NULL && dataModel->getListOfLayouts()->getListOfGlobalRenderInformationObjects().size() > 0)
        result = dataModel->getListOfLayouts()->getListOfGlobalRenderInformationObjects()[0];

      if (result == NULL && getNumDefaultStyles() > 0)
        result = getDefaultStyle(0);

      return result;
    }

  // add global ones
  {
    CCopasiVector<CLGlobalRenderInformation> & render = dataModel->getListOfLayouts()->getListOfGlobalRenderInformationObjects();
    CCopasiVector<CLGlobalRenderInformation>::const_iterator it = render.begin();

    while (it != render.end())
      {
        CLGlobalRenderInformation* current = *it;

        if (result == NULL) result = current;

        if (current->getName().empty())
          list->addItem(current->getKey().c_str(), QVariant::fromValue(RENDERINFORMATION_TYPE_GLOBAL));
        else
          list->addItem(current->getName().c_str(), QVariant::fromValue(RENDERINFORMATION_TYPE_GLOBAL));

        ++it;
      }

    // add default ones
    {
      size_t i, iMax = getNumDefaultStyles();
      CLRenderInformationBase* current = NULL;

      for (i = 0; i < iMax; ++i)
        {
          current = getDefaultStyle(i);

          if (result == NULL) result = current;

          std::string text = current->getKey();

          if (!current->getName().empty())
            {
              text = current->getName();
            }

          list->addItem(text.c_str(), QVariant::fromValue(RENDERINFORMATION_TYPE_DEFAULT));
        }
    }
  }

  return result;
}
Пример #2
0
//static
void SBMLDocumentLoader::readListOfLayouts(CListOfLayouts & lol,
    const ListOf & sbmlList,
    const std::map<CCopasiObject*, SBase*> & copasimodelmap)
{
  unsigned C_INT32 i, iMax;
#ifdef USE_CRENDER_EXTENSION
  // read the global render information
  const ListOfLayouts* pLoL = dynamic_cast<const ListOfLayouts*>(&sbmlList);
  assert(pLoL != NULL);
  RenderListOfLayoutsPlugin* rlolPlugin = (RenderListOfLayoutsPlugin*) pLoL ->getPlugin("render");

  if (rlolPlugin == NULL)
    {
      const_cast<SBMLDocument *>(pLoL->getSBMLDocument())->enablePackage(RenderExtension::getXmlnsL3V1V1(), "render", true);
      rlolPlugin = (RenderListOfLayoutsPlugin*) pLoL ->getPlugin("render");
    }

  iMax = rlolPlugin->getNumGlobalRenderInformationObjects();
  std::map<std::string, std::string> idToKeyMap;
  CLGlobalRenderInformation* pGRI = 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();
      //pGRI=new CLGlobalRenderInformation(*pLoL->getRenderInformation(i),colorIdToKeyMap,gradientIdToKeyMap,lineEndingIdToKeyMap,&lol);
      pGRI = new CLGlobalRenderInformation(*rlolPlugin->getRenderInformation(i), &lol);

      if (rlolPlugin->getRenderInformation(i)->isSetId())
        idToKeyMap.insert(std::pair<std::string, std::string>(rlolPlugin->getRenderInformation(i)->getId(), pGRI->getKey()));
      else
        idToKeyMap.insert(std::pair<std::string, std::string>(pGRI->getKey(), pGRI->getKey()));

      //colorIdToKeyMapMap.insert(std::pair<std::string,std::map<std::string,std::string> >(pGRI->getKey(),colorIdToKeyMap));
      //gradientIdToKeyMapMap.insert(std::pair<std::string,std::map<std::string,std::string> >(pGRI->getKey(),gradientIdToKeyMap));
      //lineEndingIdToKeyMapMap.insert(std::pair<std::string,std::map<std::string,std::string> >(pGRI->getKey(),lineEndingIdToKeyMap));
      lol.addGlobalRenderInformation(pGRI);
    }

  // fix the references
  SBMLDocumentLoader::convertRenderInformationReferencesIds<CLGlobalRenderInformation>(lol.getListOfGlobalRenderInformationObjects(), 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;
  std::map<std::string,std::map<std::string,std::string> > tmpMap1,tmpMap2,tmpMap3;
  for(i=0;i < iMax; ++i)
  {
      pGRI=dynamic_cast<CLGlobalRenderInformation*>(lol.getRenderInformation(i));
      assert(pGRI != NULL);

      std::set<std::string> chain;
      SBMLDocumentLoader::expandIdToKeyMaps<CLGlobalRenderInformation>(pGRI,
                         lol.getListOfGlobalRenderInformationObjects(),
                         expandedColorIdToKeyMapMap,
                         expandedGradientIdToKeyMapMap,
                         expandedLineEndingIdToKeyMapMap,
                         colorIdToKeyMapMap,
                         gradientIdToKeyMapMap,
                         lineEndingIdToKeyMapMap,
                         chain,
                         tmpMap1,
                         tmpMap2,
                         tmpMap3
                  );
      SBMLDocumentLoader::convertPropertyKeys<CLGlobalRenderInformation>(pGRI,expandedColorIdToKeyMapMap[pGRI->getKey()],expandedGradientIdToKeyMapMap[pGRI->getKey()],expandedLineEndingIdToKeyMapMap[pGRI->getKey()]);
  }
      */
#endif /* USE_CRENDER_EXTENSION */
  //convert the map as used by the CLxxx constructors
  std::map<std::string, std::string> modelmap;

  std::string s1, s2;
  std::map<CCopasiObject*, SBase*>::const_iterator it;
  std::map<CCopasiObject*, SBase*>::const_iterator itEnd = copasimodelmap.end();

  for (it = copasimodelmap.begin(); it != itEnd; ++it)
    {
      s1 = SBMLUtils::getIdFromSBase(it->second);

      if (it->first)
        s2 = it->first->getKey();
      else
        s2 = "";

      if ((s1 != "") && (s2 != ""))
        modelmap[s1] = s2;
    }

  //iterate through list of layouts
  iMax = sbmlList.size();

  for (i = 0; i < iMax; ++i)
    {
      std::map<std::string, std::string> layoutmap;
      const Layout* tmp
        = dynamic_cast<const Layout*>(sbmlList.get(i));

      if (tmp)
        {
#ifdef USE_CRENDER_EXTENSION
          //CLayout * pLayout = createLayout(*tmp, modelmap, layoutmap,idToKeyMap,expandedColorIdToKeyMapMap,expandedGradientIdToKeyMapMap,expandedLineEndingIdToKeyMapMap);
          CLayout * pLayout = createLayout(*tmp, modelmap, layoutmap, idToKeyMap);
#else
          CLayout * pLayout = createLayout(*tmp, modelmap, layoutmap);
#endif /* USE_CRENDER_EXTENSION */
          lol.addLayout(pLayout, layoutmap);
        }
    }

  //TODO: the layout object should be added to the copasimodelmap. However,
  //if this is done, the object also need to be removed if necessary in the
  //sbml exporter (see comment in CListOfLayouts::exportToSBML()).
}