COPASI API  4.16.103
test000097.cpp
Go to the documentation of this file.
1 // Begin CVS Header
2 // $Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/sbml/unittests/test000097.cpp,v $
3 // $Revision: 1.4 $
4 // $Name: $
5 // $Author: bergmann $
6 // $Date: 2012/04/19 15:00:10 $
7 // End CVS Header
8 
9 // Copyright (C) 2012 - 2011 by Pedro Mendes, Virginia Tech Intellectual
10 // Properties, Inc., University of Heidelberg, and The University
11 // of Manchester.
12 // All rights reserved.
13 
14 #include "test000097.h"
15 
16 #include <sstream>
17 #include "utilities.hpp"
18 
19 #include "sbml/SBMLDocument.h"
20 #include "sbml/Model.h"
21 #include "sbml/xml/XMLNode.h"
22 
25 #include "copasi/model/CModel.h"
27 
28 // layout objects
29 #include "copasi/layout/CLBase.h"
30 #include "copasi/layout/CLGlyphs.h"
31 #include "copasi/layout/CLayout.h"
33 
34 // render objects
38 
39 #include <sbml/xml/XMLInputStream.h>
40 
41 #include <string>
42 #include <map>
43 #include <vector>
44 
46 {
47  // Create the root container.
48  CCopasiRootContainer::init(0, NULL, false);
50 }
51 
53 {
55 }
56 
57 
58 // tests whether we are importing local render information
60 {
61  CPPUNIT_ASSERT(pDataModel != NULL);
62  // import the file and check if we find the
63  // local render information
65  CPPUNIT_ASSERT(pDataModel->getListOfLayouts() != NULL);
66  CPPUNIT_ASSERT(pDataModel->getListOfLayouts()->size() == 1);
67  const CLayout* pLayout = (*pDataModel->getListOfLayouts())[0];
68  CPPUNIT_ASSERT(pLayout != NULL);
69  CPPUNIT_ASSERT(pLayout->getListOfLocalRenderInformationObjects().size() == 1);
70  const CLLocalRenderInformation* pRI = pLayout->getListOfLocalRenderInformationObjects()[0];
71  CPPUNIT_ASSERT(pRI != NULL);
72  CPPUNIT_ASSERT(pRI->getListOfColorDefinitions()->size() == 2);
73 }
74 
75 // tests whether we are importing global render information
77 {
78  CPPUNIT_ASSERT(pDataModel != NULL);
79  // import the file and check if we find the
80  // global render information
82  CPPUNIT_ASSERT(pDataModel->getListOfLayouts() != NULL);
83  CPPUNIT_ASSERT(pDataModel->getListOfLayouts()->size() == 1);
84  const CListOfLayouts* pLayouts = pDataModel->getListOfLayouts();
85  CPPUNIT_ASSERT(pLayouts != NULL);
86  CPPUNIT_ASSERT(pLayouts->size() == 1);
87  CPPUNIT_ASSERT(pLayouts->getListOfGlobalRenderInformationObjects().size() == 1);
88  const CLGlobalRenderInformation* pRI = pLayouts->getListOfGlobalRenderInformationObjects()[0];
89  CPPUNIT_ASSERT(pRI != NULL);
90  CPPUNIT_ASSERT(pRI->getListOfColorDefinitions()->size() == 2);
91 }
92 
93 // tests whether we are exporting local render information
95 {
96  CPPUNIT_ASSERT(pDataModel != NULL);
97  // create a model with local render information and export it
98  this->createModel();
100  // to an SBML string.
101  // Use the XMLNode class to read back the string into an
102  // XMLNode tree and check if it contains the render information
103  std::string s;
104 
105  try
106  {
107  s = pDataModel->exportSBMLToString(NULL, 2, 1);
108  }
109  catch (...)
110  {
111  CPPUNIT_ASSERT(false);
112  }
113 
114  CPPUNIT_ASSERT(!s.empty());
115  XMLInputStream inputstream(s.c_str(), false);
116  XMLNode node(inputstream);
117  CPPUNIT_ASSERT(node.getName() == "sbml");
118  unsigned int i, iMax = node.getNumChildren();
119  CPPUNIT_ASSERT(iMax > 0);
120  const XMLNode* pModelNode = NULL;
121  const XMLNode* pListOfLayoutsNode = NULL;
122  const XMLNode* pLayoutNode = NULL;
123  const XMLNode* pLoLRINode = NULL;
124  const XMLNode* pLRINode = NULL;
125  const XMLNode* pAnnotationNode = NULL;
126 
127  for (i = 0; i < iMax; ++i)
128  {
129  if (node.getChild(i).getName() == "model")
130  {
131  pModelNode = &node.getChild(i);
132  break;
133  }
134  }
135 
136  CPPUNIT_ASSERT(pModelNode != NULL);
137  iMax = pModelNode->getNumChildren();
138  CPPUNIT_ASSERT(iMax > 0);
139 
140  for (i = 0; i < iMax; ++i)
141  {
142  if (pModelNode->getChild(i).getName() == "annotation")
143  {
144  pAnnotationNode = &pModelNode->getChild(i);
145  break;
146  }
147  }
148 
149  CPPUNIT_ASSERT(pAnnotationNode != NULL);
150  iMax = pAnnotationNode->getNumChildren();
151  CPPUNIT_ASSERT(iMax > 0);
152 
153  for (i = 0; i < iMax; ++i)
154  {
155  if (pAnnotationNode->getChild(i).getName() == "listOfLayouts")
156  {
157  pListOfLayoutsNode = &pAnnotationNode->getChild(i);
158  break;
159  }
160  }
161 
162  CPPUNIT_ASSERT(pListOfLayoutsNode != NULL);
163  iMax = pListOfLayoutsNode->getNumChildren();
164  CPPUNIT_ASSERT(iMax > 0);
165 
166  for (i = 0; i < iMax; ++i)
167  {
168  if (pListOfLayoutsNode->getChild(i).getName() == "layout")
169  {
170  pLayoutNode = &pListOfLayoutsNode->getChild(i);
171  }
172  }
173 
174  CPPUNIT_ASSERT(pLayoutNode != NULL);
175  iMax = pLayoutNode->getNumChildren();
176  CPPUNIT_ASSERT(iMax > 0);
177  // the layout node should have an annotation node
178  pAnnotationNode = NULL;
179 
180  for (i = 0; i < iMax; ++i)
181  {
182  if (pLayoutNode->getChild(i).getName() == "annotation")
183  {
184  pAnnotationNode = &pLayoutNode->getChild(i);
185  break;
186  }
187  }
188 
189  CPPUNIT_ASSERT(pAnnotationNode != NULL);
190  iMax = pAnnotationNode->getNumChildren();
191  CPPUNIT_ASSERT(iMax > 0);
192 
193  // the annotation node should have an listOfRenderInformation node
194  for (i = 0; i < iMax; ++i)
195  {
196  if (pAnnotationNode->getChild(i).getName() == "listOfRenderInformation")
197  {
198  pLoLRINode = &pAnnotationNode->getChild(i);
199  }
200  }
201 
202  CPPUNIT_ASSERT(pLoLRINode != NULL);
203  iMax = pLoLRINode->getNumChildren();
204  CPPUNIT_ASSERT(iMax > 0);
205 
206  for (i = 0; i < iMax; ++i)
207  {
208  if (pLoLRINode->getChild(i).getName() == "renderInformation")
209  {
210  pLRINode = &pLoLRINode->getChild(i);
211  break;
212  }
213  }
214 
215  CPPUNIT_ASSERT(pLRINode != NULL);
216  iMax = pLRINode->getNumChildren();
217  CPPUNIT_ASSERT(iMax > 0);
218  const XMLNode* pLoCDNode = NULL;
219  const XMLNode* pCDNode1 = NULL;
220  const XMLNode* pCDNode2 = NULL;
221 
222  for (i = 0; i < iMax; ++i)
223  {
224  if (pLRINode->getChild(i).getName() == "listOfColorDefinitions")
225  {
226  pLoCDNode = &pLRINode->getChild(i);
227  break;
228  }
229  }
230 
231  CPPUNIT_ASSERT(pLoCDNode != NULL);
232  iMax = pLoCDNode->getNumChildren();
233  CPPUNIT_ASSERT(iMax > 0);
234 
235  for (i = 0; i < iMax; ++i)
236  {
237  if (pLoCDNode->getChild(i).getName() == "colorDefinition")
238  {
239  if (pCDNode1 == NULL)
240  {
241  pCDNode1 = &pLoCDNode->getChild(i);
242  }
243  else
244  {
245  pCDNode2 = &pLoCDNode->getChild(i);
246  }
247  }
248  }
249 
250  CPPUNIT_ASSERT(pCDNode1 != NULL);
251  CPPUNIT_ASSERT(pCDNode2 != NULL);
252 }
253 
254 // tests whether we are exporting global render information
256 {
257  CPPUNIT_ASSERT(pDataModel != NULL);
258  // create a model with local render infromation and export it
259  this->createModel();
261  // to an SBML string.
262  // Use the XMLNode class to read back the string into an
263  // XMLNode tree and check if it contains the render information
264  std::string s;
265 
266  try
267  {
268  s = pDataModel->exportSBMLToString(NULL, 2, 1);
269  }
270  catch (...)
271  {
272  CPPUNIT_ASSERT(false);
273  }
274 
275  CPPUNIT_ASSERT(!s.empty());
276  XMLInputStream inputstream(s.c_str(), false);
277  XMLNode node(inputstream);
278  CPPUNIT_ASSERT(node.getName() == "sbml");
279  unsigned int i, iMax = node.getNumChildren();
280  CPPUNIT_ASSERT(iMax > 0);
281  const XMLNode* pModelNode = NULL;
282  const XMLNode* pListOfLayoutsNode = NULL;
283  const XMLNode* pLayoutNode = NULL;
284  const XMLNode* pLoGRINode = NULL;
285  const XMLNode* pGRINode = NULL;
286  const XMLNode* pAnnotationNode = NULL;
287 
288  for (i = 0; i < iMax; ++i)
289  {
290  if (node.getChild(i).getName() == "model")
291  {
292  pModelNode = &node.getChild(i);
293  break;
294  }
295  }
296 
297  CPPUNIT_ASSERT(pModelNode != NULL);
298  iMax = pModelNode->getNumChildren();
299  CPPUNIT_ASSERT(iMax > 0);
300 
301  for (i = 0; i < iMax; ++i)
302  {
303  if (pModelNode->getChild(i).getName() == "annotation")
304  {
305  pAnnotationNode = &pModelNode->getChild(i);
306  break;
307  }
308  }
309 
310  CPPUNIT_ASSERT(pAnnotationNode != NULL);
311  iMax = pAnnotationNode->getNumChildren();
312  CPPUNIT_ASSERT(iMax > 0);
313 
314  for (i = 0; i < iMax; ++i)
315  {
316  if (pAnnotationNode->getChild(i).getName() == "listOfLayouts")
317  {
318  pListOfLayoutsNode = &pAnnotationNode->getChild(i);
319  break;
320  }
321  else if (pAnnotationNode->getChild(i).getName() == "listOfGlobalRenderInformation")
322  {
323  pLoGRINode = &pAnnotationNode->getChild(i);
324  break;
325  }
326  }
327 
328  CPPUNIT_ASSERT(pListOfLayoutsNode != NULL);
329  iMax = pListOfLayoutsNode->getNumChildren();
330  CPPUNIT_ASSERT(iMax > 0);
331  pAnnotationNode = NULL;
332 
333  for (i = 0; i < iMax; ++i)
334  {
335  if (pListOfLayoutsNode->getChild(i).getName() == "layout")
336  {
337  pLayoutNode = &pListOfLayoutsNode->getChild(i);
338  }
339  else if (pListOfLayoutsNode->getChild(i).getName() == "annotation")
340  {
341  pAnnotationNode = &pListOfLayoutsNode->getChild(i);
342  }
343  }
344 
345  CPPUNIT_ASSERT(pLayoutNode != NULL);
346  iMax = pLayoutNode->getNumChildren();
347  CPPUNIT_ASSERT(iMax > 0);
348 
349  CPPUNIT_ASSERT(pAnnotationNode != NULL);
350  iMax = pAnnotationNode->getNumChildren();
351  CPPUNIT_ASSERT(iMax > 0);
352 
353  for (i = 0; i < iMax; ++i)
354  {
355  if (pAnnotationNode->getChild(i).getName() == "listOfGlobalRenderInformation")
356  {
357  pLoGRINode = &pAnnotationNode->getChild(i);
358  break;
359  }
360 
361  }
362 
363  CPPUNIT_ASSERT(pLoGRINode != NULL);
364  iMax = pLoGRINode->getNumChildren();
365  CPPUNIT_ASSERT(iMax > 0);
366 
367  for (i = 0; i < iMax; ++i)
368  {
369  if (pLoGRINode->getChild(i).getName() == "renderInformation")
370  {
371  pGRINode = &pLoGRINode->getChild(i);
372  break;
373  }
374  }
375 
376  CPPUNIT_ASSERT(pGRINode != NULL);
377  iMax = pGRINode->getNumChildren();
378  CPPUNIT_ASSERT(iMax > 0);
379  const XMLNode* pLoCDNode = NULL;
380  const XMLNode* pCDNode1 = NULL;
381  const XMLNode* pCDNode2 = NULL;
382 
383  for (i = 0; i < iMax; ++i)
384  {
385  if (pGRINode->getChild(i).getName() == "listOfColorDefinitions")
386  {
387  pLoCDNode = &pGRINode->getChild(i);
388  break;
389  }
390  }
391 
392  CPPUNIT_ASSERT(pLoCDNode != NULL);
393  iMax = pLoCDNode->getNumChildren();
394  CPPUNIT_ASSERT(iMax > 0);
395 
396  for (i = 0; i < iMax; ++i)
397  {
398  if (pLoCDNode->getChild(i).getName() == "colorDefinition")
399  {
400  if (pCDNode1 == NULL)
401  {
402  pCDNode1 = &pLoCDNode->getChild(i);
403  }
404  else
405  {
406  pCDNode2 = &pLoCDNode->getChild(i);
407  }
408  }
409  }
410 
411  CPPUNIT_ASSERT(pCDNode1 != NULL);
412  CPPUNIT_ASSERT(pCDNode2 != NULL);
413 }
414 
415 // tests whether we are saving local render information
417 {
418  CPPUNIT_ASSERT(pDataModel != NULL);
419  // create a model with local render infromation and export it
420  this->createModel();
422  // to an SBML string.
423  // Use the XMLNode class to read back the string into an
424  // XMLNode tree and check if it contains the render information
425  std::ostringstream os;
427  CPPUNIT_ASSERT(!os.str().empty());
428  XMLInputStream inputstream(os.str().c_str(), false);
429  XMLNode node(inputstream);
430  CPPUNIT_ASSERT(node.getName() == "COPASI");
431  unsigned int i, iMax = node.getNumChildren();
432  CPPUNIT_ASSERT(iMax > 0);
433  const XMLNode* pListOfLayoutsNode = NULL;
434  const XMLNode* pLayoutNode = NULL;
435  const XMLNode* pLoLRINode = NULL;
436  const XMLNode* pLRINode = NULL;
437 
438  for (i = 0; i < iMax; ++i)
439  {
440  if (node.getChild(i).getName() == "ListOfLayouts")
441  {
442  pListOfLayoutsNode = &node.getChild(i);
443  break;
444  }
445  }
446 
447  CPPUNIT_ASSERT(pListOfLayoutsNode != NULL);
448  iMax = pListOfLayoutsNode->getNumChildren();
449  CPPUNIT_ASSERT(iMax > 0);
450 
451  for (i = 0; i < iMax; ++i)
452  {
453  if (pListOfLayoutsNode->getChild(i).getName() == "Layout")
454  {
455  pLayoutNode = &pListOfLayoutsNode->getChild(i);
456  break;
457  }
458  }
459 
460  CPPUNIT_ASSERT(pLayoutNode != NULL);
461  iMax = pLayoutNode->getNumChildren();
462  CPPUNIT_ASSERT(iMax > 0);
463 
464  for (i = 0; i < iMax; ++i)
465  {
466  if (pLayoutNode->getChild(i).getName() == "ListOfRenderInformation")
467  {
468  pLoLRINode = &pLayoutNode->getChild(i);
469  break;
470  }
471  }
472 
473  CPPUNIT_ASSERT(pLoLRINode != NULL);
474  iMax = pLoLRINode->getNumChildren();
475  CPPUNIT_ASSERT(iMax > 0);
476 
477  for (i = 0; i < iMax; ++i)
478  {
479  if (pLoLRINode->getChild(i).getName() == "RenderInformation")
480  {
481  pLRINode = &pLoLRINode->getChild(i);
482  break;
483  }
484  }
485 
486  CPPUNIT_ASSERT(pLRINode != NULL);
487  iMax = pLRINode->getNumChildren();
488  CPPUNIT_ASSERT(iMax > 0);
489  const XMLNode* pLoCDNode = NULL;
490  const XMLNode* pCDNode1 = NULL;
491  const XMLNode* pCDNode2 = NULL;
492 
493  for (i = 0; i < iMax; ++i)
494  {
495  if (pLRINode->getChild(i).getName() == "ListOfColorDefinitions")
496  {
497  pLoCDNode = &pLRINode->getChild(i);
498  break;
499  }
500  }
501 
502  CPPUNIT_ASSERT(pLoCDNode != NULL);
503  iMax = pLoCDNode->getNumChildren();
504  CPPUNIT_ASSERT(iMax > 0);
505 
506  for (i = 0; i < iMax; ++i)
507  {
508  if (pLoCDNode->getChild(i).getName() == "ColorDefinition")
509  {
510  if (pCDNode1 == NULL)
511  {
512  pCDNode1 = &pLoCDNode->getChild(i);
513  }
514  else
515  {
516  pCDNode2 = &pLoCDNode->getChild(i);
517  }
518  }
519  }
520 
521  CPPUNIT_ASSERT(pCDNode1 != NULL);
522  CPPUNIT_ASSERT(pCDNode2 != NULL);
523 }
524 
525 // tests whether we are saving global render information
527 {
528  CPPUNIT_ASSERT(pDataModel != NULL);
529  // create a model with local render infromation and export it
530  this->createModel();
532  // to an SBML string.
533  // Use the XMLNode class to read back the string into an
534  // XMLNode tree and check if it contains the render information
535  std::ostringstream os;
537  CPPUNIT_ASSERT(!os.str().empty());
538  XMLInputStream inputstream(os.str().c_str(), false);
539  XMLNode node(inputstream);
540  CPPUNIT_ASSERT(node.getName() == "COPASI");
541  unsigned int i, iMax = node.getNumChildren();
542  CPPUNIT_ASSERT(iMax > 0);
543  const XMLNode* pListOfLayoutsNode = NULL;
544  const XMLNode* pLayoutNode = NULL;
545  const XMLNode* pLoGRINode = NULL;
546  const XMLNode* pGRINode = NULL;
547 
548  for (i = 0; i < iMax; ++i)
549  {
550  if (node.getChild(i).getName() == "ListOfLayouts")
551  {
552  pListOfLayoutsNode = &node.getChild(i);
553  break;
554  }
555  }
556 
557  CPPUNIT_ASSERT(pListOfLayoutsNode != NULL);
558  iMax = pListOfLayoutsNode->getNumChildren();
559  CPPUNIT_ASSERT(iMax > 0);
560 
561  for (i = 0; i < iMax; ++i)
562  {
563  if (pListOfLayoutsNode->getChild(i).getName() == "Layout")
564  {
565  pLayoutNode = &pListOfLayoutsNode->getChild(i);
566  }
567  else if (pListOfLayoutsNode->getChild(i).getName() == "ListOfGlobalRenderInformation")
568  {
569  pLoGRINode = &pListOfLayoutsNode->getChild(i);
570  }
571  }
572 
573  CPPUNIT_ASSERT(pLayoutNode != NULL);
574  iMax = pLayoutNode->getNumChildren();
575  CPPUNIT_ASSERT(iMax > 0);
576  CPPUNIT_ASSERT(pLoGRINode != NULL);
577  iMax = pLoGRINode->getNumChildren();
578  CPPUNIT_ASSERT(iMax > 0);
579 
580  for (i = 0; i < iMax; ++i)
581  {
582  if (pLoGRINode->getChild(i).getName() == "RenderInformation")
583  {
584  pGRINode = &pLoGRINode->getChild(i);
585  break;
586  }
587  }
588 
589  CPPUNIT_ASSERT(pGRINode != NULL);
590  iMax = pGRINode->getNumChildren();
591  CPPUNIT_ASSERT(iMax > 0);
592  const XMLNode* pLoCDNode = NULL;
593  const XMLNode* pCDNode1 = NULL;
594  const XMLNode* pCDNode2 = NULL;
595 
596  for (i = 0; i < iMax; ++i)
597  {
598  if (pGRINode->getChild(i).getName() == "ListOfColorDefinitions")
599  {
600  pLoCDNode = &pGRINode->getChild(i);
601  break;
602  }
603  }
604 
605  CPPUNIT_ASSERT(pLoCDNode != NULL);
606  iMax = pLoCDNode->getNumChildren();
607  CPPUNIT_ASSERT(iMax > 0);
608 
609  for (i = 0; i < iMax; ++i)
610  {
611  if (pLoCDNode->getChild(i).getName() == "ColorDefinition")
612  {
613  if (pCDNode1 == NULL)
614  {
615  pCDNode1 = &pLoCDNode->getChild(i);
616  }
617  else
618  {
619  pCDNode2 = &pLoCDNode->getChild(i);
620  }
621  }
622  }
623 
624  CPPUNIT_ASSERT(pCDNode1 != NULL);
625  CPPUNIT_ASSERT(pCDNode2 != NULL);
626 }
627 
628 // test whether we are reading local render information
630 {
631  CPPUNIT_ASSERT(pDataModel != NULL);
632  std::istringstream iss(test000097::CPS_MODEL_1);
633  CPPUNIT_ASSERT(load_cps_model_from_stream(iss, *pDataModel) == true);
634  CPPUNIT_ASSERT(pDataModel->getListOfLayouts() != NULL);
635  CPPUNIT_ASSERT(pDataModel->getListOfLayouts()->size() == 1);
636  const CLayout* pLayout = (*pDataModel->getListOfLayouts())[0];
637  CPPUNIT_ASSERT(pLayout != NULL);
638  CPPUNIT_ASSERT(pLayout->getListOfLocalRenderInformationObjects().size() == 1);
639  const CLLocalRenderInformation* pRI = pLayout->getListOfLocalRenderInformationObjects()[0];
640  CPPUNIT_ASSERT(pRI != NULL);
641  CPPUNIT_ASSERT(pRI->getListOfColorDefinitions()->size() == 2);
642 }
643 
644 // test whether we are reading global render information
646 {
647  CPPUNIT_ASSERT(pDataModel != NULL);
648  std::istringstream iss(test000097::CPS_MODEL_2);
649  CPPUNIT_ASSERT(load_cps_model_from_stream(iss, *pDataModel) == true);
650  CPPUNIT_ASSERT(pDataModel->getListOfLayouts() != NULL);
651  CPPUNIT_ASSERT(pDataModel->getListOfLayouts()->size() == 1);
652  const CListOfLayouts* pLayouts = pDataModel->getListOfLayouts();
653  CPPUNIT_ASSERT(pLayouts != NULL);
654  CPPUNIT_ASSERT(pLayouts->size() == 1);
655  CPPUNIT_ASSERT(pLayouts->getListOfGlobalRenderInformationObjects().size() == 1);
656  const CLGlobalRenderInformation* pRI = pLayouts->getListOfGlobalRenderInformationObjects()[0];
657  CPPUNIT_ASSERT(pRI != NULL);
658  CPPUNIT_ASSERT(pRI->getListOfColorDefinitions()->size() == 2);
659 }
660 
661 // method the create a model with a single compartment
662 // and a small layout
664 {
665  CPPUNIT_ASSERT(pDataModel != NULL);
666  // get the model from the datamodel
667  CModel* pModel = pDataModel->getModel();
668  CPPUNIT_ASSERT(pModel != NULL);
669  pModel->setTimeUnit(CModel::s);
670  pModel->setVolumeUnit(CModel::microl);
671  pModel->setQuantityUnit(CModel::nMol);
672 
673  // add a compartment
674  std::set<const CCopasiObject*> changedObjects;
675  CCompartment* pCompartment = pModel->createCompartment("cell", 5.0);
676  CPPUNIT_ASSERT(pCompartment != NULL);
677  const CCopasiObject* pObject = pCompartment->getInitialValueReference();
678  CPPUNIT_ASSERT(pObject != NULL);
679  changedObjects.insert(pObject);
680 
681  // finally compile the model
682  // compile needs to be done before updating all initial values for
683  // the model with the refresh sequence
684  pModel->compileIfNecessary(NULL);
685 
686  // now that we are done building the model, we have to make sure all
687  // initial values are updated according to their dependencies
688  std::vector<Refresh*> refreshes = pModel->buildInitialRefreshSequence(changedObjects);
689  std::vector<Refresh*>::iterator it2 = refreshes.begin(), endit2 = refreshes.end();
690 
691  while (it2 != endit2)
692  {
693  // call each refresh
694  (**it2)();
695  ++it2;
696  }
697 
698  // add a layout
699  CLayout* pLayout = new CLayout();
700  pLayout->setDimensions(CLDimensions(100.0, 100.0));
701  // with a compartment glyph
702  CLCompartmentGlyph* pGlyph = new CLCompartmentGlyph();
703  pGlyph->setModelObjectKey(pCompartment->getKey());
704  pGlyph->setBoundingBox(CLBoundingBox(CLPoint(20.0, 20.0), CLDimensions(60.0, 60.0)));
705  pLayout->addCompartmentGlyph(pGlyph);
706  // the map is not used right now so we pass an empty map
707  pDataModel->getListOfLayouts()->addLayout(pLayout, std::map<std::string, std::string>());
708  CPPUNIT_ASSERT(pDataModel->getListOfLayouts()->size() == 1);
709  CPPUNIT_ASSERT((*pDataModel->getListOfLayouts())[0]->getListOfCompartmentGlyphs().size() == 1);
710 }
711 
712 // method to add a local render information object
713 // to the given model
715 {
717  CPPUNIT_ASSERT(pLRI != NULL);
718  pLRI->setName("my_local_render_info");
719  CLColorDefinition* pCDef = pLRI->createColorDefinition();
720  CPPUNIT_ASSERT(pCDef != NULL);
721  pCDef->setId("black");
722  pCDef->setRGBA(0, 0, 0, 255);
723  pCDef = pLRI->createColorDefinition();
724  CPPUNIT_ASSERT(pCDef != NULL);
725  pCDef->setId("red");
726  pCDef->setRGBA(255, 0, 0, 255);
727  CPPUNIT_ASSERT(pDataModel->getListOfLayouts()->size() == 1);
728  CLayout* pLayout = (*pDataModel->getListOfLayouts())[0];
729  CPPUNIT_ASSERT(pLayout != NULL);
730  pLayout->addLocalRenderInformation(pLRI);
731  CPPUNIT_ASSERT(pLayout->getListOfLocalRenderInformationObjects().size() == 1);
732  CPPUNIT_ASSERT(pLayout->getListOfLocalRenderInformationObjects()[0]->getListOfColorDefinitions()->size() == 2);
733 }
734 
735 // method to add a global render information object
736 // to the given model
738 {
740  CPPUNIT_ASSERT(pGRI != NULL);
741  pGRI->setName("my_global_render_info");
742  CLColorDefinition* pCDef = pGRI->createColorDefinition();
743  CPPUNIT_ASSERT(pCDef != NULL);
744  pCDef->setId("black");
745  pCDef->setRGBA(0, 0, 0, 255);
746  pCDef = pGRI->createColorDefinition();
747  CPPUNIT_ASSERT(pCDef != NULL);
748  pCDef->setId("red");
749  pCDef->setRGBA(255, 0, 0, 255);
752  CPPUNIT_ASSERT(pDataModel->getListOfLayouts()->getListOfGlobalRenderInformationObjects()[0]->getListOfColorDefinitions()->size() == 2);
753 }
754 
755 
756 // SBML model with local render information
757 const char* test000097::SBML_MODEL_1 =
758  "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
759  "<sbml xmlns=\"http://www.sbml.org/sbml/level2\" level=\"2\" version=\"1\">\n"
760  " <model id=\"TestModel\">\n"
761  " <annotation>\n"
762  " <listOfLayouts xmlns=\"http://projects.eml.org/bcb/sbml/level2\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n"
763  " <layout id=\"Layout_1\">\n"
764  " <annotation>\n"
765  " <listOfRenderInformation xmlns=\"http://projects.eml.org/bcb/sbml/render/level2\">\n"
766  " <renderInformation id=\"highlightGlucose\" programName=\"Ralph Gauges\" programVersion=\"1.0\">\n"
767  " <listOfColorDefinitions>\n"
768  " <colorDefinition id=\"lightRed\" value=\"#E6ADD8\"/>\n"
769  " <colorDefinition id=\"white\" value=\"#FFFFFF\"/>\n"
770  " </listOfColorDefinitions>\n"
771  " </renderInformation>\n"
772  " </listOfRenderInformation>\n"
773  " </annotation>\n"
774  " <dimensions width=\"400\" height=\"230\"/>\n"
775  " <listOfCompartmentGlyphs>\n"
776  " <compartmentGlyph id=\"CompartmentGlyph_1\" compartment=\"Yeast\">\n"
777  " <boundingBox id=\"bb1\">\n"
778  " <position x=\"5\" y=\"5\"/>\n"
779  " <dimensions width=\"390\" height=\"220\"/>\n"
780  " </boundingBox>\n"
781  " </compartmentGlyph>\n"
782  " </listOfCompartmentGlyphs>\n"
783  " </layout>\n"
784  " </listOfLayouts>\n"
785  " </annotation>\n"
786  " <listOfCompartments>\n"
787  " <compartment id=\"Yeast\" size=\"1\" />\n"
788  " </listOfCompartments>\n"
789  " </model>\n"
790  "</sbml>\n"
791  ;
792 
793 // SBML model with global render information
794 const char* test000097::SBML_MODEL_2 =
795  "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
796  "<sbml xmlns=\"http://www.sbml.org/sbml/level2\" level=\"2\" version=\"1\">\n"
797  " <model id=\"TestModel\">\n"
798  " <annotation>\n"
799  " <listOfLayouts xmlns=\"http://projects.eml.org/bcb/sbml/level2\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n"
800  " <annotation>\n"
801  " <listOfGlobalRenderInformation xmlns=\"http://projects.eml.org/bcb/sbml/render/level2\">\n"
802  " <renderInformation id=\"wireFrame\" name=\"wireframe style\" programName=\"Ralph Gauges\" programVersion=\"1.0\">\n"
803  " <listOfColorDefinitions>\n"
804  " <colorDefinition id=\"white\" value=\"#FFFFFF\"/>\n"
805  " <colorDefinition id=\"black\" value=\"#000000\"/>\n"
806  " </listOfColorDefinitions>\n"
807  " </renderInformation>\n"
808  " </listOfGlobalRenderInformation>\n"
809  " </annotation>\n"
810  " <layout id=\"Layout_1\">\n"
811  " <dimensions width=\"400\" height=\"230\"/>\n"
812  " <listOfCompartmentGlyphs>\n"
813  " <compartmentGlyph id=\"CompartmentGlyph_1\" compartment=\"Yeast\">\n"
814  " <boundingBox id=\"bb1\">\n"
815  " <position x=\"5\" y=\"5\"/>\n"
816  " <dimensions width=\"390\" height=\"220\"/>\n"
817  " </boundingBox>\n"
818  " </compartmentGlyph>\n"
819  " </listOfCompartmentGlyphs>\n"
820  " </layout>\n"
821  " </listOfLayouts>\n"
822  " </annotation>\n"
823  " <listOfCompartments>\n"
824  " <compartment id=\"Yeast\" size=\"1\" />\n"
825  " </listOfCompartments>\n"
826  " </model>\n"
827  "</sbml>\n"
828  ;
829 
830 // COPASI model with local render information
831 const char* test000097::CPS_MODEL_1 =
832  "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
833  "<!-- generated with COPASI 4.6.34 (Debug) (http://www.copasi.org) at 2011-04-22 10:08:31 UTC -->\n"
834  "<?oxygen RNGSchema=\"http://www.copasi.org/static/schema/CopasiML.rng\" type=\"xml\"?>\n"
835  "<COPASI xmlns=\"http://www.copasi.org/static/schema\" versionMajor=\"1\" versionMinor=\"0\" versionDevel=\"34\">\n"
836  " <Model key=\"Model_1\" name=\"NoName\" simulationType=\"time\" timeUnit=\"s\" volumeUnit=\"l\" areaUnit=\"m²\" lengthUnit=\"m\" quantityUnit=\"mol\" type=\"deterministic\" avogadroConstant=\"6.02214179e+23\">\n"
837  " <ListOfCompartments>\n"
838  " <Compartment key=\"Compartment_0\" name=\"Yeast\" simulationType=\"fixed\" dimensionality=\"3\">\n"
839  " </Compartment>\n"
840  " </ListOfCompartments>\n"
841  " <StateTemplate>\n"
842  " <StateTemplateVariable objectReference=\"Model_1\"/>\n"
843  " <StateTemplateVariable objectReference=\"Compartment_0\"/>\n"
844  " </StateTemplate>\n"
845  " <InitialState type=\"initialState\">\n"
846  " 0 1 \n"
847  " </InitialState>\n"
848  " </Model>\n"
849  " <ListOfLayouts xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n"
850  " <Layout key=\"Layout_2\" name=\"Layout_1\">\n"
851  " <Dimensions width=\"400\" height=\"230\"/>\n"
852  " <ListOfCompartmentGlyphs>\n"
853  " <CompartmentGlyph key=\"Layout_3\" name=\"CompartmentGlyph_1\" compartment=\"Compartment_0\">\n"
854  " <BoundingBox>\n"
855  " <Position x=\"5\" y=\"5\"/>\n"
856  " <Dimensions width=\"390\" height=\"220\"/>\n"
857  " </BoundingBox>\n"
858  " </CompartmentGlyph>\n"
859  " </ListOfCompartmentGlyphs>\n"
860  " <ListOfRenderInformation>\n"
861  " <RenderInformation key=\"LocalRenderInformation_0\" backgroundColor=\"#FFFFFFFF\">\n"
862  " <ListOfColorDefinitions>\n"
863  " <ColorDefinition id=\"lightRed\" value=\"#e6add8\"/>\n"
864  " <ColorDefinition id=\"white\" value=\"#ffffff\"/>\n"
865  " </ListOfColorDefinitions>\n"
866  " </RenderInformation>\n"
867  " </ListOfRenderInformation>\n"
868  " </Layout>\n"
869  " </ListOfLayouts>\n"
870  "</COPASI>\n"
871  ;
872 
873 // COPASI model with global render information
874 const char* test000097::CPS_MODEL_2 =
875  "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
876  "<!-- generated with COPASI 4.6.34 (Debug) (http://www.copasi.org) at 2011-04-22 10:09:16 UTC -->\n"
877  "<?oxygen RNGSchema=\"http://www.copasi.org/static/schema/CopasiML.rng\" type=\"xml\"?>\n"
878  "<COPASI xmlns=\"http://www.copasi.org/static/schema\" versionMajor=\"1\" versionMinor=\"0\" versionDevel=\"34\">\n"
879  " <Model key=\"Model_1\" name=\"NoName\" simulationType=\"time\" timeUnit=\"s\" volumeUnit=\"l\" areaUnit=\"m²\" lengthUnit=\"m\" quantityUnit=\"mol\" type=\"deterministic\" avogadroConstant=\"6.02214179e+23\">\n"
880  " <ListOfCompartments>\n"
881  " <Compartment key=\"Compartment_0\" name=\"Yeast\" simulationType=\"fixed\" dimensionality=\"3\">\n"
882  " </Compartment>\n"
883  " </ListOfCompartments>\n"
884  " <StateTemplate>\n"
885  " <StateTemplateVariable objectReference=\"Model_1\"/>\n"
886  " <StateTemplateVariable objectReference=\"Compartment_0\"/>\n"
887  " </StateTemplate>\n"
888  " <InitialState type=\"initialState\">\n"
889  " 0 1 \n"
890  " </InitialState>\n"
891  " </Model>\n"
892  " <ListOfLayouts xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n"
893  " <Layout key=\"Layout_2\" name=\"Layout_1\">\n"
894  " <Dimensions width=\"400\" height=\"230\"/>\n"
895  " <ListOfCompartmentGlyphs>\n"
896  " <CompartmentGlyph key=\"Layout_3\" name=\"CompartmentGlyph_1\" compartment=\"Compartment_0\">\n"
897  " <BoundingBox>\n"
898  " <Position x=\"5\" y=\"5\"/>\n"
899  " <Dimensions width=\"390\" height=\"220\"/>\n"
900  " </BoundingBox>\n"
901  " </CompartmentGlyph>\n"
902  " </ListOfCompartmentGlyphs>\n"
903  " </Layout>\n"
904  " <ListOfGlobalRenderInformation>\n"
905  " <RenderInformation key=\"GlobalRenderInformation_0\" name=\"wireframe style\" backgroundColor=\"#FFFFFFFF\">\n"
906  " <ListOfColorDefinitions>\n"
907  " <ColorDefinition id=\"white\" value=\"#ffffff\"/>\n"
908  " <ColorDefinition id=\"black\" value=\"#000000\"/>\n"
909  " </ListOfColorDefinitions>\n"
910  " </RenderInformation>\n"
911  " </ListOfGlobalRenderInformation>\n"
912  " </ListOfLayouts>\n"
913  "</COPASI>\n"
914  ;
915 
916 // tests whether we are exporting local render information
917 // that has been read
919 {
920  CPPUNIT_ASSERT(pDataModel != NULL);
921  // read a model with local render information and export it
922  // to an SBML string.
923  std::istringstream iss(test000097::CPS_MODEL_1);
924  CPPUNIT_ASSERT(load_cps_model_from_stream(iss, *pDataModel) == true);
925  CPPUNIT_ASSERT(pDataModel->getListOfLayouts() != NULL);
926  CPPUNIT_ASSERT(pDataModel->getListOfLayouts()->size() == 1);
927  // Use the XMLNode class to read back the string into an
928  // XMLNode tree and check if it contains the render information
929  std::string s;
930 
931  try
932  {
933  s = pDataModel->exportSBMLToString(NULL, 2, 1);
934  }
935  catch (...)
936  {
937  CPPUNIT_ASSERT(false);
938  }
939 
940  CPPUNIT_ASSERT(!s.empty());
941  XMLInputStream inputstream(s.c_str(), false);
942  XMLNode node(inputstream);
943  CPPUNIT_ASSERT(node.getName() == "sbml");
944  unsigned int i, iMax = node.getNumChildren();
945  CPPUNIT_ASSERT(iMax > 0);
946  const XMLNode* pModelNode = NULL;
947  const XMLNode* pListOfLayoutsNode = NULL;
948  const XMLNode* pLayoutNode = NULL;
949  const XMLNode* pLoLRINode = NULL;
950  const XMLNode* pLRINode = NULL;
951  const XMLNode* pAnnotationNode = NULL;
952 
953  for (i = 0; i < iMax; ++i)
954  {
955  if (node.getChild(i).getName() == "model")
956  {
957  pModelNode = &node.getChild(i);
958  break;
959  }
960  }
961 
962  CPPUNIT_ASSERT(pModelNode != NULL);
963  iMax = pModelNode->getNumChildren();
964  CPPUNIT_ASSERT(iMax > 0);
965 
966  for (i = 0; i < iMax; ++i)
967  {
968  if (pModelNode->getChild(i).getName() == "annotation")
969  {
970  pAnnotationNode = &pModelNode->getChild(i);
971  break;
972  }
973  }
974 
975  CPPUNIT_ASSERT(pAnnotationNode != NULL);
976  iMax = pAnnotationNode->getNumChildren();
977  CPPUNIT_ASSERT(iMax > 0);
978 
979  for (i = 0; i < iMax; ++i)
980  {
981  if (pAnnotationNode->getChild(i).getName() == "listOfLayouts")
982  {
983  pListOfLayoutsNode = &pAnnotationNode->getChild(i);
984  break;
985  }
986  }
987 
988  CPPUNIT_ASSERT(pListOfLayoutsNode != NULL);
989  iMax = pListOfLayoutsNode->getNumChildren();
990  CPPUNIT_ASSERT(iMax > 0);
991 
992  for (i = 0; i < iMax; ++i)
993  {
994  if (pListOfLayoutsNode->getChild(i).getName() == "layout")
995  {
996  pLayoutNode = &pListOfLayoutsNode->getChild(i);
997  }
998  }
999 
1000  CPPUNIT_ASSERT(pLayoutNode != NULL);
1001  iMax = pLayoutNode->getNumChildren();
1002  CPPUNIT_ASSERT(iMax > 0);
1003  // the layout node should have an annotation node
1004  pAnnotationNode = NULL;
1005 
1006  for (i = 0; i < iMax; ++i)
1007  {
1008  if (pLayoutNode->getChild(i).getName() == "annotation")
1009  {
1010  pAnnotationNode = &pLayoutNode->getChild(i);
1011  break;
1012  }
1013  }
1014 
1015  CPPUNIT_ASSERT(pAnnotationNode != NULL);
1016  iMax = pAnnotationNode->getNumChildren();
1017  CPPUNIT_ASSERT(iMax > 0);
1018 
1019  // the annotation node should have an listOfRenderInformation node
1020  for (i = 0; i < iMax; ++i)
1021  {
1022  if (pAnnotationNode->getChild(i).getName() == "listOfRenderInformation")
1023  {
1024  pLoLRINode = &pAnnotationNode->getChild(i);
1025  }
1026  }
1027 
1028  CPPUNIT_ASSERT(pLoLRINode != NULL);
1029  iMax = pLoLRINode->getNumChildren();
1030  CPPUNIT_ASSERT(iMax > 0);
1031 
1032  for (i = 0; i < iMax; ++i)
1033  {
1034  if (pLoLRINode->getChild(i).getName() == "renderInformation")
1035  {
1036  pLRINode = &pLoLRINode->getChild(i);
1037  break;
1038  }
1039  }
1040 
1041  CPPUNIT_ASSERT(pLRINode != NULL);
1042  iMax = pLRINode->getNumChildren();
1043  CPPUNIT_ASSERT(iMax > 0);
1044  const XMLNode* pLoCDNode = NULL;
1045  const XMLNode* pCDNode1 = NULL;
1046  const XMLNode* pCDNode2 = NULL;
1047 
1048  for (i = 0; i < iMax; ++i)
1049  {
1050  if (pLRINode->getChild(i).getName() == "listOfColorDefinitions")
1051  {
1052  pLoCDNode = &pLRINode->getChild(i);
1053  break;
1054  }
1055  }
1056 
1057  CPPUNIT_ASSERT(pLoCDNode != NULL);
1058  iMax = pLoCDNode->getNumChildren();
1059  CPPUNIT_ASSERT(iMax > 0);
1060 
1061  for (i = 0; i < iMax; ++i)
1062  {
1063  if (pLoCDNode->getChild(i).getName() == "colorDefinition")
1064  {
1065  if (pCDNode1 == NULL)
1066  {
1067  pCDNode1 = &pLoCDNode->getChild(i);
1068  }
1069  else
1070  {
1071  pCDNode2 = &pLoCDNode->getChild(i);
1072  }
1073  }
1074  }
1075 
1076  CPPUNIT_ASSERT(pCDNode1 != NULL);
1077  CPPUNIT_ASSERT(pCDNode2 != NULL);
1078 }
1079 
1080 
1081 // tests whether we are exporting global render information
1082 // that has been read
1084 {
1085  CPPUNIT_ASSERT(pDataModel != NULL);
1086  // read a model with local render infromation and export it
1087  // to an SBML string.
1088  std::istringstream iss(test000097::CPS_MODEL_2);
1089  CPPUNIT_ASSERT(load_cps_model_from_stream(iss, *pDataModel) == true);
1090  CPPUNIT_ASSERT(pDataModel->getListOfLayouts() != NULL);
1091  CPPUNIT_ASSERT(pDataModel->getListOfLayouts()->size() == 1);
1092  // Use the XMLNode class to read back the string into an
1093  // XMLNode tree and check if it contains the render information
1094  std::string s;
1095 
1096  try
1097  {
1098  s = pDataModel->exportSBMLToString(NULL, 2, 1);
1099  }
1100  catch (...)
1101  {
1102  CPPUNIT_ASSERT(false);
1103  }
1104 
1105  CPPUNIT_ASSERT(!s.empty());
1106  XMLInputStream inputstream(s.c_str(), false);
1107  XMLNode node(inputstream);
1108  CPPUNIT_ASSERT(node.getName() == "sbml");
1109  unsigned int i, iMax = node.getNumChildren();
1110  CPPUNIT_ASSERT(iMax > 0);
1111  const XMLNode* pModelNode = NULL;
1112  const XMLNode* pListOfLayoutsNode = NULL;
1113  const XMLNode* pLayoutNode = NULL;
1114  const XMLNode* pLoGRINode = NULL;
1115  const XMLNode* pGRINode = NULL;
1116  const XMLNode* pAnnotationNode = NULL;
1117 
1118  for (i = 0; i < iMax; ++i)
1119  {
1120  if (node.getChild(i).getName() == "model")
1121  {
1122  pModelNode = &node.getChild(i);
1123  break;
1124  }
1125  }
1126 
1127  CPPUNIT_ASSERT(pModelNode != NULL);
1128  iMax = pModelNode->getNumChildren();
1129  CPPUNIT_ASSERT(iMax > 0);
1130 
1131  for (i = 0; i < iMax; ++i)
1132  {
1133  if (pModelNode->getChild(i).getName() == "annotation")
1134  {
1135  pAnnotationNode = &pModelNode->getChild(i);
1136  break;
1137  }
1138  }
1139 
1140  CPPUNIT_ASSERT(pAnnotationNode != NULL);
1141  iMax = pAnnotationNode->getNumChildren();
1142  CPPUNIT_ASSERT(iMax > 0);
1143 
1144  for (i = 0; i < iMax; ++i)
1145  {
1146  if (pAnnotationNode->getChild(i).getName() == "listOfLayouts")
1147  {
1148  pListOfLayoutsNode = &pAnnotationNode->getChild(i);
1149  break;
1150  }
1151  else if (pAnnotationNode->getChild(i).getName() == "listOfGlobalRenderInformation")
1152  {
1153  pLoGRINode = &pAnnotationNode->getChild(i);
1154  break;
1155  }
1156  }
1157 
1158  CPPUNIT_ASSERT(pListOfLayoutsNode != NULL);
1159  iMax = pListOfLayoutsNode->getNumChildren();
1160  CPPUNIT_ASSERT(iMax > 0);
1161  pAnnotationNode = NULL;
1162 
1163  for (i = 0; i < iMax; ++i)
1164  {
1165  if (pListOfLayoutsNode->getChild(i).getName() == "layout")
1166  {
1167  pLayoutNode = &pListOfLayoutsNode->getChild(i);
1168  }
1169  else if (pListOfLayoutsNode->getChild(i).getName() == "annotation")
1170  {
1171  pAnnotationNode = &pListOfLayoutsNode->getChild(i);
1172  }
1173  }
1174 
1175  CPPUNIT_ASSERT(pLayoutNode != NULL);
1176  iMax = pLayoutNode->getNumChildren();
1177  CPPUNIT_ASSERT(iMax > 0);
1178 
1179  CPPUNIT_ASSERT(pAnnotationNode != NULL);
1180  iMax = pAnnotationNode->getNumChildren();
1181  CPPUNIT_ASSERT(iMax > 0);
1182 
1183  for (i = 0; i < iMax; ++i)
1184  {
1185  if (pAnnotationNode->getChild(i).getName() == "listOfGlobalRenderInformation")
1186  {
1187  pLoGRINode = &pAnnotationNode->getChild(i);
1188  break;
1189  }
1190 
1191  }
1192 
1193  CPPUNIT_ASSERT(pLoGRINode != NULL);
1194  iMax = pLoGRINode->getNumChildren();
1195  CPPUNIT_ASSERT(iMax > 0);
1196 
1197  for (i = 0; i < iMax; ++i)
1198  {
1199  if (pLoGRINode->getChild(i).getName() == "renderInformation")
1200  {
1201  pGRINode = &pLoGRINode->getChild(i);
1202  break;
1203  }
1204  }
1205 
1206  CPPUNIT_ASSERT(pGRINode != NULL);
1207  iMax = pGRINode->getNumChildren();
1208  CPPUNIT_ASSERT(iMax > 0);
1209  const XMLNode* pLoCDNode = NULL;
1210  const XMLNode* pCDNode1 = NULL;
1211  const XMLNode* pCDNode2 = NULL;
1212 
1213  for (i = 0; i < iMax; ++i)
1214  {
1215  if (pGRINode->getChild(i).getName() == "listOfColorDefinitions")
1216  {
1217  pLoCDNode = &pGRINode->getChild(i);
1218  break;
1219  }
1220  }
1221 
1222  CPPUNIT_ASSERT(pLoCDNode != NULL);
1223  iMax = pLoCDNode->getNumChildren();
1224  CPPUNIT_ASSERT(iMax > 0);
1225 
1226  for (i = 0; i < iMax; ++i)
1227  {
1228  if (pLoCDNode->getChild(i).getName() == "colorDefinition")
1229  {
1230  if (pCDNode1 == NULL)
1231  {
1232  pCDNode1 = &pLoCDNode->getChild(i);
1233  }
1234  else
1235  {
1236  pCDNode2 = &pLoCDNode->getChild(i);
1237  }
1238  }
1239  }
1240 
1241  CPPUNIT_ASSERT(pCDNode1 != NULL);
1242  CPPUNIT_ASSERT(pCDNode2 != NULL);
1243 }
1244 
1245 // tests whether we are exporting local render information
1246 // that has been import
1248 {
1249  CPPUNIT_ASSERT(pDataModel != NULL);
1250  // import a model with local render information and export it
1251  // to an SBML string.
1252  CPPUNIT_ASSERT(pDataModel->importSBMLFromString(SBML_MODEL_1));
1253  CPPUNIT_ASSERT(pDataModel->getListOfLayouts() != NULL);
1254  CPPUNIT_ASSERT(pDataModel->getListOfLayouts()->size() == 1);
1255  // Use the XMLNode class to read back the string into an
1256  // XMLNode tree and check if it contains the render information
1257  std::string s;
1258 
1259  try
1260  {
1261  s = pDataModel->exportSBMLToString(NULL, 2, 1);
1262  }
1263  catch (...)
1264  {
1265  CPPUNIT_ASSERT(false);
1266  }
1267 
1268  CPPUNIT_ASSERT(!s.empty());
1269  XMLInputStream inputstream(s.c_str(), false);
1270  XMLNode node(inputstream);
1271  CPPUNIT_ASSERT(node.getName() == "sbml");
1272  unsigned int i, iMax = node.getNumChildren();
1273  CPPUNIT_ASSERT(iMax > 0);
1274  const XMLNode* pModelNode = NULL;
1275  const XMLNode* pListOfLayoutsNode = NULL;
1276  const XMLNode* pLayoutNode = NULL;
1277  const XMLNode* pLoLRINode = NULL;
1278  const XMLNode* pLRINode = NULL;
1279  const XMLNode* pAnnotationNode = NULL;
1280 
1281  for (i = 0; i < iMax; ++i)
1282  {
1283  if (node.getChild(i).getName() == "model")
1284  {
1285  pModelNode = &node.getChild(i);
1286  break;
1287  }
1288  }
1289 
1290  CPPUNIT_ASSERT(pModelNode != NULL);
1291  iMax = pModelNode->getNumChildren();
1292  CPPUNIT_ASSERT(iMax > 0);
1293 
1294  for (i = 0; i < iMax; ++i)
1295  {
1296  if (pModelNode->getChild(i).getName() == "annotation")
1297  {
1298  pAnnotationNode = &pModelNode->getChild(i);
1299  break;
1300  }
1301  }
1302 
1303  CPPUNIT_ASSERT(pAnnotationNode != NULL);
1304  iMax = pAnnotationNode->getNumChildren();
1305  CPPUNIT_ASSERT(iMax > 0);
1306 
1307  for (i = 0; i < iMax; ++i)
1308  {
1309  if (pAnnotationNode->getChild(i).getName() == "listOfLayouts")
1310  {
1311  pListOfLayoutsNode = &pAnnotationNode->getChild(i);
1312  break;
1313  }
1314  }
1315 
1316  CPPUNIT_ASSERT(pListOfLayoutsNode != NULL);
1317  iMax = pListOfLayoutsNode->getNumChildren();
1318  CPPUNIT_ASSERT(iMax > 0);
1319 
1320  for (i = 0; i < iMax; ++i)
1321  {
1322  if (pListOfLayoutsNode->getChild(i).getName() == "layout")
1323  {
1324  pLayoutNode = &pListOfLayoutsNode->getChild(i);
1325  }
1326  }
1327 
1328  CPPUNIT_ASSERT(pLayoutNode != NULL);
1329  iMax = pLayoutNode->getNumChildren();
1330  CPPUNIT_ASSERT(iMax > 0);
1331  // the layout node should have an annotation node
1332  pAnnotationNode = NULL;
1333 
1334  for (i = 0; i < iMax; ++i)
1335  {
1336  if (pLayoutNode->getChild(i).getName() == "annotation")
1337  {
1338  pAnnotationNode = &pLayoutNode->getChild(i);
1339  break;
1340  }
1341  }
1342 
1343  CPPUNIT_ASSERT(pAnnotationNode != NULL);
1344  iMax = pAnnotationNode->getNumChildren();
1345  CPPUNIT_ASSERT(iMax > 0);
1346 
1347  // the annotation node should have an listOfRenderInformation node
1348  for (i = 0; i < iMax; ++i)
1349  {
1350  if (pAnnotationNode->getChild(i).getName() == "listOfRenderInformation")
1351  {
1352  pLoLRINode = &pAnnotationNode->getChild(i);
1353  }
1354  }
1355 
1356  CPPUNIT_ASSERT(pLoLRINode != NULL);
1357  iMax = pLoLRINode->getNumChildren();
1358  CPPUNIT_ASSERT(iMax > 0);
1359 
1360  for (i = 0; i < iMax; ++i)
1361  {
1362  if (pLoLRINode->getChild(i).getName() == "renderInformation")
1363  {
1364  pLRINode = &pLoLRINode->getChild(i);
1365  break;
1366  }
1367  }
1368 
1369  CPPUNIT_ASSERT(pLRINode != NULL);
1370  iMax = pLRINode->getNumChildren();
1371  CPPUNIT_ASSERT(iMax > 0);
1372  const XMLNode* pLoCDNode = NULL;
1373  const XMLNode* pCDNode1 = NULL;
1374  const XMLNode* pCDNode2 = NULL;
1375 
1376  for (i = 0; i < iMax; ++i)
1377  {
1378  if (pLRINode->getChild(i).getName() == "listOfColorDefinitions")
1379  {
1380  pLoCDNode = &pLRINode->getChild(i);
1381  break;
1382  }
1383  }
1384 
1385  CPPUNIT_ASSERT(pLoCDNode != NULL);
1386  iMax = pLoCDNode->getNumChildren();
1387  CPPUNIT_ASSERT(iMax > 0);
1388 
1389  for (i = 0; i < iMax; ++i)
1390  {
1391  if (pLoCDNode->getChild(i).getName() == "colorDefinition")
1392  {
1393  if (pCDNode1 == NULL)
1394  {
1395  pCDNode1 = &pLoCDNode->getChild(i);
1396  }
1397  else
1398  {
1399  pCDNode2 = &pLoCDNode->getChild(i);
1400  }
1401  }
1402  }
1403 
1404  CPPUNIT_ASSERT(pCDNode1 != NULL);
1405  CPPUNIT_ASSERT(pCDNode2 != NULL);
1406 }
1407 
1408 
1409 // tests whether we are exporting global render information
1410 // that has been import
1412 {
1413  CPPUNIT_ASSERT(pDataModel != NULL);
1414  // import a model with global render infromation and export it
1415  CPPUNIT_ASSERT(pDataModel->importSBMLFromString(SBML_MODEL_2));
1416  CPPUNIT_ASSERT(pDataModel->getListOfLayouts() != NULL);
1417  CPPUNIT_ASSERT(pDataModel->getListOfLayouts()->size() == 1);
1418  // to an SBML string.
1419  // Use the XMLNode class to read back the string into an
1420  // XMLNode tree and check if it contains the render information
1421  std::string s;
1422 
1423  try
1424  {
1425  s = pDataModel->exportSBMLToString(NULL, 2, 1);
1426  }
1427  catch (...)
1428  {
1429  CPPUNIT_ASSERT(false);
1430  }
1431 
1432  CPPUNIT_ASSERT(!s.empty());
1433  XMLInputStream inputstream(s.c_str(), false);
1434  XMLNode node(inputstream);
1435  CPPUNIT_ASSERT(node.getName() == "sbml");
1436  unsigned int i, iMax = node.getNumChildren();
1437  CPPUNIT_ASSERT(iMax > 0);
1438  const XMLNode* pModelNode = NULL;
1439  const XMLNode* pListOfLayoutsNode = NULL;
1440  const XMLNode* pLayoutNode = NULL;
1441  const XMLNode* pLoGRINode = NULL;
1442  const XMLNode* pGRINode = NULL;
1443  const XMLNode* pAnnotationNode = NULL;
1444 
1445  for (i = 0; i < iMax; ++i)
1446  {
1447  if (node.getChild(i).getName() == "model")
1448  {
1449  pModelNode = &node.getChild(i);
1450  break;
1451  }
1452  }
1453 
1454  CPPUNIT_ASSERT(pModelNode != NULL);
1455  iMax = pModelNode->getNumChildren();
1456  CPPUNIT_ASSERT(iMax > 0);
1457 
1458  for (i = 0; i < iMax; ++i)
1459  {
1460  if (pModelNode->getChild(i).getName() == "annotation")
1461  {
1462  pAnnotationNode = &pModelNode->getChild(i);
1463  break;
1464  }
1465  }
1466 
1467  CPPUNIT_ASSERT(pAnnotationNode != NULL);
1468  iMax = pAnnotationNode->getNumChildren();
1469  CPPUNIT_ASSERT(iMax > 0);
1470 
1471  for (i = 0; i < iMax; ++i)
1472  {
1473  if (pAnnotationNode->getChild(i).getName() == "listOfLayouts")
1474  {
1475  pListOfLayoutsNode = &pAnnotationNode->getChild(i);
1476  break;
1477  }
1478  else if (pAnnotationNode->getChild(i).getName() == "listOfGlobalRenderInformation")
1479  {
1480  pLoGRINode = &pAnnotationNode->getChild(i);
1481  break;
1482  }
1483  }
1484 
1485  CPPUNIT_ASSERT(pListOfLayoutsNode != NULL);
1486  iMax = pListOfLayoutsNode->getNumChildren();
1487  CPPUNIT_ASSERT(iMax > 0);
1488  pAnnotationNode = NULL;
1489 
1490  for (i = 0; i < iMax; ++i)
1491  {
1492  if (pListOfLayoutsNode->getChild(i).getName() == "layout")
1493  {
1494  pLayoutNode = &pListOfLayoutsNode->getChild(i);
1495  }
1496  else if (pListOfLayoutsNode->getChild(i).getName() == "annotation")
1497  {
1498  pAnnotationNode = &pListOfLayoutsNode->getChild(i);
1499  }
1500  }
1501 
1502  CPPUNIT_ASSERT(pLayoutNode != NULL);
1503  iMax = pLayoutNode->getNumChildren();
1504  CPPUNIT_ASSERT(iMax > 0);
1505 
1506  CPPUNIT_ASSERT(pAnnotationNode != NULL);
1507  iMax = pAnnotationNode->getNumChildren();
1508  CPPUNIT_ASSERT(iMax > 0);
1509 
1510  for (i = 0; i < iMax; ++i)
1511  {
1512  if (pAnnotationNode->getChild(i).getName() == "listOfGlobalRenderInformation")
1513  {
1514  pLoGRINode = &pAnnotationNode->getChild(i);
1515  break;
1516  }
1517 
1518  }
1519 
1520  CPPUNIT_ASSERT(pLoGRINode != NULL);
1521  iMax = pLoGRINode->getNumChildren();
1522  CPPUNIT_ASSERT(iMax > 0);
1523 
1524  for (i = 0; i < iMax; ++i)
1525  {
1526  if (pLoGRINode->getChild(i).getName() == "renderInformation")
1527  {
1528  pGRINode = &pLoGRINode->getChild(i);
1529  break;
1530  }
1531  }
1532 
1533  CPPUNIT_ASSERT(pGRINode != NULL);
1534  iMax = pGRINode->getNumChildren();
1535  CPPUNIT_ASSERT(iMax > 0);
1536  const XMLNode* pLoCDNode = NULL;
1537  const XMLNode* pCDNode1 = NULL;
1538  const XMLNode* pCDNode2 = NULL;
1539 
1540  for (i = 0; i < iMax; ++i)
1541  {
1542  if (pGRINode->getChild(i).getName() == "listOfColorDefinitions")
1543  {
1544  pLoCDNode = &pGRINode->getChild(i);
1545  break;
1546  }
1547  }
1548 
1549  CPPUNIT_ASSERT(pLoCDNode != NULL);
1550  iMax = pLoCDNode->getNumChildren();
1551  CPPUNIT_ASSERT(iMax > 0);
1552 
1553  for (i = 0; i < iMax; ++i)
1554  {
1555  if (pLoCDNode->getChild(i).getName() == "colorDefinition")
1556  {
1557  if (pCDNode1 == NULL)
1558  {
1559  pCDNode1 = &pLoCDNode->getChild(i);
1560  }
1561  else
1562  {
1563  pCDNode2 = &pLoCDNode->getChild(i);
1564  }
1565  }
1566  }
1567 
1568  CPPUNIT_ASSERT(pCDNode1 != NULL);
1569  CPPUNIT_ASSERT(pCDNode2 != NULL);
1570 }
1571 
1572 
1573 // test whether we are writing local render information
1574 // that has been read
1576 {
1577  CPPUNIT_ASSERT(pDataModel != NULL);
1578  // create a model with local render infromation and export it
1579  std::istringstream iss(test000097::CPS_MODEL_1);
1580  CPPUNIT_ASSERT(load_cps_model_from_stream(iss, *pDataModel) == true);
1581  CPPUNIT_ASSERT(pDataModel->getListOfLayouts() != NULL);
1582  CPPUNIT_ASSERT(pDataModel->getListOfLayouts()->size() == 1);
1583  // to an SBML string.
1584  // Use the XMLNode class to read back the string into an
1585  // XMLNode tree and check if it contains the render information
1586  std::ostringstream os;
1588  CPPUNIT_ASSERT(!os.str().empty());
1589  XMLInputStream inputstream(os.str().c_str(), false);
1590  XMLNode node(inputstream);
1591  CPPUNIT_ASSERT(node.getName() == "COPASI");
1592  unsigned int i, iMax = node.getNumChildren();
1593  CPPUNIT_ASSERT(iMax > 0);
1594  const XMLNode* pListOfLayoutsNode = NULL;
1595  const XMLNode* pLayoutNode = NULL;
1596  const XMLNode* pLoLRINode = NULL;
1597  const XMLNode* pLRINode = NULL;
1598 
1599  for (i = 0; i < iMax; ++i)
1600  {
1601  if (node.getChild(i).getName() == "ListOfLayouts")
1602  {
1603  pListOfLayoutsNode = &node.getChild(i);
1604  break;
1605  }
1606  }
1607 
1608  CPPUNIT_ASSERT(pListOfLayoutsNode != NULL);
1609  iMax = pListOfLayoutsNode->getNumChildren();
1610  CPPUNIT_ASSERT(iMax > 0);
1611 
1612  for (i = 0; i < iMax; ++i)
1613  {
1614  if (pListOfLayoutsNode->getChild(i).getName() == "Layout")
1615  {
1616  pLayoutNode = &pListOfLayoutsNode->getChild(i);
1617  break;
1618  }
1619  }
1620 
1621  CPPUNIT_ASSERT(pLayoutNode != NULL);
1622  iMax = pLayoutNode->getNumChildren();
1623  CPPUNIT_ASSERT(iMax > 0);
1624 
1625  for (i = 0; i < iMax; ++i)
1626  {
1627  if (pLayoutNode->getChild(i).getName() == "ListOfRenderInformation")
1628  {
1629  pLoLRINode = &pLayoutNode->getChild(i);
1630  break;
1631  }
1632  }
1633 
1634  CPPUNIT_ASSERT(pLoLRINode != NULL);
1635  iMax = pLoLRINode->getNumChildren();
1636  CPPUNIT_ASSERT(iMax > 0);
1637 
1638  for (i = 0; i < iMax; ++i)
1639  {
1640  if (pLoLRINode->getChild(i).getName() == "RenderInformation")
1641  {
1642  pLRINode = &pLoLRINode->getChild(i);
1643  break;
1644  }
1645  }
1646 
1647  CPPUNIT_ASSERT(pLRINode != NULL);
1648  iMax = pLRINode->getNumChildren();
1649  CPPUNIT_ASSERT(iMax > 0);
1650  const XMLNode* pLoCDNode = NULL;
1651  const XMLNode* pCDNode1 = NULL;
1652  const XMLNode* pCDNode2 = NULL;
1653 
1654  for (i = 0; i < iMax; ++i)
1655  {
1656  if (pLRINode->getChild(i).getName() == "ListOfColorDefinitions")
1657  {
1658  pLoCDNode = &pLRINode->getChild(i);
1659  break;
1660  }
1661  }
1662 
1663  CPPUNIT_ASSERT(pLoCDNode != NULL);
1664  iMax = pLoCDNode->getNumChildren();
1665  CPPUNIT_ASSERT(iMax > 0);
1666 
1667  for (i = 0; i < iMax; ++i)
1668  {
1669  if (pLoCDNode->getChild(i).getName() == "ColorDefinition")
1670  {
1671  if (pCDNode1 == NULL)
1672  {
1673  pCDNode1 = &pLoCDNode->getChild(i);
1674  }
1675  else
1676  {
1677  pCDNode2 = &pLoCDNode->getChild(i);
1678  }
1679  }
1680  }
1681 
1682  CPPUNIT_ASSERT(pCDNode1 != NULL);
1683  CPPUNIT_ASSERT(pCDNode2 != NULL);
1684 }
1685 
1686 // test whether we are writing global render information
1687 // that has been read
1689 {
1690  CPPUNIT_ASSERT(pDataModel != NULL);
1691  // create a model with local render infromation and export it
1692  std::istringstream iss(test000097::CPS_MODEL_2);
1693  CPPUNIT_ASSERT(load_cps_model_from_stream(iss, *pDataModel) == true);
1694  CPPUNIT_ASSERT(pDataModel->getListOfLayouts() != NULL);
1695  CPPUNIT_ASSERT(pDataModel->getListOfLayouts()->size() == 1);
1696  // to an SBML string.
1697  // Use the XMLNode class to read back the string into an
1698  // XMLNode tree and check if it contains the render information
1699  std::ostringstream os;
1701  CPPUNIT_ASSERT(!os.str().empty());
1702  XMLInputStream inputstream(os.str().c_str(), false);
1703  XMLNode node(inputstream);
1704  CPPUNIT_ASSERT(node.getName() == "COPASI");
1705  unsigned int i, iMax = node.getNumChildren();
1706  CPPUNIT_ASSERT(iMax > 0);
1707  const XMLNode* pListOfLayoutsNode = NULL;
1708  const XMLNode* pLayoutNode = NULL;
1709  const XMLNode* pLoGRINode = NULL;
1710  const XMLNode* pGRINode = NULL;
1711 
1712  for (i = 0; i < iMax; ++i)
1713  {
1714  if (node.getChild(i).getName() == "ListOfLayouts")
1715  {
1716  pListOfLayoutsNode = &node.getChild(i);
1717  break;
1718  }
1719  }
1720 
1721  CPPUNIT_ASSERT(pListOfLayoutsNode != NULL);
1722  iMax = pListOfLayoutsNode->getNumChildren();
1723  CPPUNIT_ASSERT(iMax > 0);
1724 
1725  for (i = 0; i < iMax; ++i)
1726  {
1727  if (pListOfLayoutsNode->getChild(i).getName() == "Layout")
1728  {
1729  pLayoutNode = &pListOfLayoutsNode->getChild(i);
1730  }
1731  else if (pListOfLayoutsNode->getChild(i).getName() == "ListOfGlobalRenderInformation")
1732  {
1733  pLoGRINode = &pListOfLayoutsNode->getChild(i);
1734  }
1735  }
1736 
1737  CPPUNIT_ASSERT(pLayoutNode != NULL);
1738  iMax = pLayoutNode->getNumChildren();
1739  CPPUNIT_ASSERT(iMax > 0);
1740  CPPUNIT_ASSERT(pLoGRINode != NULL);
1741  iMax = pLoGRINode->getNumChildren();
1742  CPPUNIT_ASSERT(iMax > 0);
1743 
1744  for (i = 0; i < iMax; ++i)
1745  {
1746  if (pLoGRINode->getChild(i).getName() == "RenderInformation")
1747  {
1748  pGRINode = &pLoGRINode->getChild(i);
1749  break;
1750  }
1751  }
1752 
1753  CPPUNIT_ASSERT(pGRINode != NULL);
1754  iMax = pGRINode->getNumChildren();
1755  CPPUNIT_ASSERT(iMax > 0);
1756  const XMLNode* pLoCDNode = NULL;
1757  const XMLNode* pCDNode1 = NULL;
1758  const XMLNode* pCDNode2 = NULL;
1759 
1760  for (i = 0; i < iMax; ++i)
1761  {
1762  if (pGRINode->getChild(i).getName() == "ListOfColorDefinitions")
1763  {
1764  pLoCDNode = &pGRINode->getChild(i);
1765  break;
1766  }
1767  }
1768 
1769  CPPUNIT_ASSERT(pLoCDNode != NULL);
1770  iMax = pLoCDNode->getNumChildren();
1771  CPPUNIT_ASSERT(iMax > 0);
1772 
1773  for (i = 0; i < iMax; ++i)
1774  {
1775  if (pLoCDNode->getChild(i).getName() == "ColorDefinition")
1776  {
1777  if (pCDNode1 == NULL)
1778  {
1779  pCDNode1 = &pLoCDNode->getChild(i);
1780  }
1781  else
1782  {
1783  pCDNode2 = &pLoCDNode->getChild(i);
1784  }
1785  }
1786  }
1787 
1788  CPPUNIT_ASSERT(pCDNode1 != NULL);
1789  CPPUNIT_ASSERT(pCDNode2 != NULL);
1790 }
1791 
1792 // test whether we are writing local render information
1793 // that has been imported
1795 {
1796  CPPUNIT_ASSERT(pDataModel != NULL);
1797  // create a model with local render infromation and export it
1798  CPPUNIT_ASSERT(pDataModel->importSBMLFromString(SBML_MODEL_1));
1799  CPPUNIT_ASSERT(pDataModel->getListOfLayouts() != NULL);
1800  CPPUNIT_ASSERT(pDataModel->getListOfLayouts()->size() == 1);
1801  // to an SBML string.
1802  // Use the XMLNode class to read back the string into an
1803  // XMLNode tree and check if it contains the render information
1804  std::ostringstream os;
1806  CPPUNIT_ASSERT(!os.str().empty());
1807  XMLInputStream inputstream(os.str().c_str(), false);
1808  XMLNode node(inputstream);
1809  CPPUNIT_ASSERT(node.getName() == "COPASI");
1810  unsigned int i, iMax = node.getNumChildren();
1811  CPPUNIT_ASSERT(iMax > 0);
1812  const XMLNode* pListOfLayoutsNode = NULL;
1813  const XMLNode* pLayoutNode = NULL;
1814  const XMLNode* pLoLRINode = NULL;
1815  const XMLNode* pLRINode = NULL;
1816 
1817  for (i = 0; i < iMax; ++i)
1818  {
1819  if (node.getChild(i).getName() == "ListOfLayouts")
1820  {
1821  pListOfLayoutsNode = &node.getChild(i);
1822  break;
1823  }
1824  }
1825 
1826  CPPUNIT_ASSERT(pListOfLayoutsNode != NULL);
1827  iMax = pListOfLayoutsNode->getNumChildren();
1828  CPPUNIT_ASSERT(iMax > 0);
1829 
1830  for (i = 0; i < iMax; ++i)
1831  {
1832  if (pListOfLayoutsNode->getChild(i).getName() == "Layout")
1833  {
1834  pLayoutNode = &pListOfLayoutsNode->getChild(i);
1835  break;
1836  }
1837  }
1838 
1839  CPPUNIT_ASSERT(pLayoutNode != NULL);
1840  iMax = pLayoutNode->getNumChildren();
1841  CPPUNIT_ASSERT(iMax > 0);
1842 
1843  for (i = 0; i < iMax; ++i)
1844  {
1845  if (pLayoutNode->getChild(i).getName() == "ListOfRenderInformation")
1846  {
1847  pLoLRINode = &pLayoutNode->getChild(i);
1848  break;
1849  }
1850  }
1851 
1852  CPPUNIT_ASSERT(pLoLRINode != NULL);
1853  iMax = pLoLRINode->getNumChildren();
1854  CPPUNIT_ASSERT(iMax > 0);
1855 
1856  for (i = 0; i < iMax; ++i)
1857  {
1858  if (pLoLRINode->getChild(i).getName() == "RenderInformation")
1859  {
1860  pLRINode = &pLoLRINode->getChild(i);
1861  break;
1862  }
1863  }
1864 
1865  CPPUNIT_ASSERT(pLRINode != NULL);
1866  iMax = pLRINode->getNumChildren();
1867  CPPUNIT_ASSERT(iMax > 0);
1868  const XMLNode* pLoCDNode = NULL;
1869  const XMLNode* pCDNode1 = NULL;
1870  const XMLNode* pCDNode2 = NULL;
1871 
1872  for (i = 0; i < iMax; ++i)
1873  {
1874  if (pLRINode->getChild(i).getName() == "ListOfColorDefinitions")
1875  {
1876  pLoCDNode = &pLRINode->getChild(i);
1877  break;
1878  }
1879  }
1880 
1881  CPPUNIT_ASSERT(pLoCDNode != NULL);
1882  iMax = pLoCDNode->getNumChildren();
1883  CPPUNIT_ASSERT(iMax > 0);
1884 
1885  for (i = 0; i < iMax; ++i)
1886  {
1887  if (pLoCDNode->getChild(i).getName() == "ColorDefinition")
1888  {
1889  if (pCDNode1 == NULL)
1890  {
1891  pCDNode1 = &pLoCDNode->getChild(i);
1892  }
1893  else
1894  {
1895  pCDNode2 = &pLoCDNode->getChild(i);
1896  }
1897  }
1898  }
1899 
1900  CPPUNIT_ASSERT(pCDNode1 != NULL);
1901  CPPUNIT_ASSERT(pCDNode2 != NULL);
1902 }
1903 
1904 // test whether we are writing global render information
1905 // that has been importer
1907 {
1908  CPPUNIT_ASSERT(pDataModel != NULL);
1909  // create a model with local render infromation and export it
1910  CPPUNIT_ASSERT(pDataModel->importSBMLFromString(SBML_MODEL_2));
1911  CPPUNIT_ASSERT(pDataModel->getListOfLayouts() != NULL);
1912  CPPUNIT_ASSERT(pDataModel->getListOfLayouts()->size() == 1);
1913  // to an SBML string.
1914  // Use the XMLNode class to read back the string into an
1915  // XMLNode tree and check if it contains the render information
1916  std::ostringstream os;
1918  CPPUNIT_ASSERT(!os.str().empty());
1919  XMLInputStream inputstream(os.str().c_str(), false);
1920  XMLNode node(inputstream);
1921  CPPUNIT_ASSERT(node.getName() == "COPASI");
1922  unsigned int i, iMax = node.getNumChildren();
1923  CPPUNIT_ASSERT(iMax > 0);
1924  const XMLNode* pListOfLayoutsNode = NULL;
1925  const XMLNode* pLayoutNode = NULL;
1926  const XMLNode* pLoGRINode = NULL;
1927  const XMLNode* pGRINode = NULL;
1928 
1929  for (i = 0; i < iMax; ++i)
1930  {
1931  if (node.getChild(i).getName() == "ListOfLayouts")
1932  {
1933  pListOfLayoutsNode = &node.getChild(i);
1934  break;
1935  }
1936  }
1937 
1938  CPPUNIT_ASSERT(pListOfLayoutsNode != NULL);
1939  iMax = pListOfLayoutsNode->getNumChildren();
1940  CPPUNIT_ASSERT(iMax > 0);
1941 
1942  for (i = 0; i < iMax; ++i)
1943  {
1944  if (pListOfLayoutsNode->getChild(i).getName() == "Layout")
1945  {
1946  pLayoutNode = &pListOfLayoutsNode->getChild(i);
1947  }
1948  else if (pListOfLayoutsNode->getChild(i).getName() == "ListOfGlobalRenderInformation")
1949  {
1950  pLoGRINode = &pListOfLayoutsNode->getChild(i);
1951  }
1952  }
1953 
1954  CPPUNIT_ASSERT(pLayoutNode != NULL);
1955  iMax = pLayoutNode->getNumChildren();
1956  CPPUNIT_ASSERT(iMax > 0);
1957  CPPUNIT_ASSERT(pLoGRINode != NULL);
1958  iMax = pLoGRINode->getNumChildren();
1959  CPPUNIT_ASSERT(iMax > 0);
1960 
1961  for (i = 0; i < iMax; ++i)
1962  {
1963  if (pLoGRINode->getChild(i).getName() == "RenderInformation")
1964  {
1965  pGRINode = &pLoGRINode->getChild(i);
1966  break;
1967  }
1968  }
1969 
1970  CPPUNIT_ASSERT(pGRINode != NULL);
1971  iMax = pGRINode->getNumChildren();
1972  CPPUNIT_ASSERT(iMax > 0);
1973  const XMLNode* pLoCDNode = NULL;
1974  const XMLNode* pCDNode1 = NULL;
1975  const XMLNode* pCDNode2 = NULL;
1976 
1977  for (i = 0; i < iMax; ++i)
1978  {
1979  if (pGRINode->getChild(i).getName() == "ListOfColorDefinitions")
1980  {
1981  pLoCDNode = &pGRINode->getChild(i);
1982  break;
1983  }
1984  }
1985 
1986  CPPUNIT_ASSERT(pLoCDNode != NULL);
1987  iMax = pLoCDNode->getNumChildren();
1988  CPPUNIT_ASSERT(iMax > 0);
1989 
1990  for (i = 0; i < iMax; ++i)
1991  {
1992  if (pLoCDNode->getChild(i).getName() == "ColorDefinition")
1993  {
1994  if (pCDNode1 == NULL)
1995  {
1996  pCDNode1 = &pLoCDNode->getChild(i);
1997  }
1998  else
1999  {
2000  pCDNode2 = &pLoCDNode->getChild(i);
2001  }
2002  }
2003  }
2004 
2005  CPPUNIT_ASSERT(pCDNode1 != NULL);
2006  CPPUNIT_ASSERT(pCDNode2 != NULL);
2007 }
2008 
void addLocalRenderInformation()
Definition: test000097.cpp:714
bool setVolumeUnit(const std::string &name)
Definition: CModel.cpp:2159
std::string exportSBMLToString(CProcessReport *pExportHandler, int sbmlLevel, int sbmlVersion)
virtual size_t size() const
void test_import_local_render_information()
Definition: test000097.cpp:59
CCopasiObject * getInitialValueReference() const
void addGlobalRenderInformation()
Definition: test000097.cpp:737
bool save_cps_model_to_stream(std::ostream &os, CCopasiDataModel *pDataModel)
Definition: utilities.cpp:26
bool setTimeUnit(const std::string &name)
Definition: CModel.cpp:2227
void test_read_local_render_information()
Definition: test000097.cpp:629
void setDimensions(const CLDimensions &d)
Definition: CLayout.h:77
void test_import_global_render_information()
Definition: test000097.cpp:76
void test_save_global_render_information()
Definition: test000097.cpp:526
void test_readexport_global_render_information()
void test_importexport_global_render_information()
static const char * SBML_MODEL_1
Definition: test000097.h:51
void addGlobalRenderInformation(CLGlobalRenderInformation *pRenderInfo)
void test_readwrite_global_render_information()
static const char * CPS_MODEL_2
Definition: test000097.h:57
bool load_cps_model_from_stream(std::istream &is, CCopasiDataModel &dataModel)
Definition: utilities.cpp:21
void test_importexport_local_render_information()
void test_importwrite_global_render_information()
void setModelObjectKey(const std::string &k)
static const char * CPS_MODEL_1
Definition: test000097.h:55
void test_readwrite_local_render_information()
void test_importwrite_local_render_information()
void setUp()
Definition: test000097.cpp:45
Definition: CLBase.h:54
virtual const std::string & getKey() const
void setRGBA(unsigned char r, unsigned char g, unsigned char b, unsigned char a=255)
void test_save_local_render_information()
Definition: test000097.cpp:416
void setName(const std::string &name)
CLColorDefinition * createColorDefinition()
CListOfLayouts * getListOfLayouts()
void test_export_global_render_information()
Definition: test000097.cpp:255
CCopasiDataModel * pDataModel
Definition: test000097.h:59
void setId(const std::string &id)
void addLayout(CLayout *layout, const std::map< std::string, std::string > &m)
void addCompartmentGlyph(CLCompartmentGlyph *glyph)
Definition: CLayout.cpp:239
static CCopasiDataModel * addDatamodel()
void setBoundingBox(const CLBoundingBox &bb)
void test_export_local_render_information()
Definition: test000097.cpp:94
void tearDown()
Definition: test000097.cpp:52
bool compileIfNecessary(CProcessReport *pProcessReport)
Definition: CModel.cpp:612
static const char * SBML_MODEL_2
Definition: test000097.h:53
bool importSBMLFromString(const std::string &sbmlDocumentText, CProcessReport *pImportHandler=NULL, const bool &deleteOldData=true)
bool setQuantityUnit(const std::string &name)
Definition: CModel.cpp:2250
static void init(int argc, char *argv[], const bool &withGui=false)
void createModel()
Definition: test000097.cpp:663
Definition: CModel.h:50
std::vector< Refresh * > buildInitialRefreshSequence(std::set< const CCopasiObject * > &changedObjects)
Definition: CModel.cpp:4164
void test_read_global_render_information()
Definition: test000097.cpp:645
CCompartment * createCompartment(const std::string &name, const C_FLOAT64 &volume=1.0)
Definition: CModel.cpp:2698
void test_readexport_local_render_information()
Definition: test000097.cpp:918
const CCopasiVector< CLGlobalRenderInformation > & getListOfGlobalRenderInformationObjects() const