COPASI API  4.16.103
Static Public Member Functions | Static Protected Member Functions | List of all members
CLRenderFlattener Class Reference

#include <CLRenderFlattener.h>

Static Public Member Functions

static CLGlobalRenderInformationflatten_render_information (const CLGlobalRenderInformation &globalRenderInformation, const CCopasiVector< CLGlobalRenderInformation > &globalList) throw (CLUnresolvedReferenceException)
 
static CLLocalRenderInformationflatten_render_information (const CLLocalRenderInformation &localRenderInformation, const CCopasiVector< CLLocalRenderInformation > &localList, const CCopasiVector< CLGlobalRenderInformation > &globalList) throw (CLUnresolvedReferenceException)
 

Static Protected Member Functions

static CLLocalStyleconvertGlobalToLocalStyle (const CLGlobalStyle *pGlobal)
 
static CLRenderInformationBaseflatten (const CLRenderInformationBase &renderInformation, const CCopasiVector< CLGlobalRenderInformation > &globalList, const CCopasiVector< CLLocalRenderInformation > &localList=CCopasiVector< CLLocalRenderInformation >()) throw (CLUnresolvedReferenceException)
 

Detailed Description

Definition at line 31 of file CLRenderFlattener.h.

Member Function Documentation

CLLocalStyle * CLRenderFlattener::convertGlobalToLocalStyle ( const CLGlobalStyle pGlobal)
staticprotected

Method takes a global style object and converts it to a local style object. The caller is responsible for freeing the memory of the returned object once it is no longer needed.

Definition at line 414 of file CLRenderFlattener.cpp.

References CLStyle::getGroup(), CCopasiObject::getObjectName(), CLStyle::getRoleList(), CLStyle::getTypeList(), pResult, CLStyle::setGroup(), CCopasiObject::setObjectName(), CLStyle::setRoleList(), and CLStyle::setTypeList().

415 {
417  // we need to copy all elements from Style
418  // mGroup, mRoleList, mTypeList
419  pResult->setGroup(pGlobal->getGroup());
420  pResult->setRoleList(pGlobal->getRoleList());
421  pResult->setTypeList(pGlobal->getTypeList());
422  // we need to copy all elements from SBase
423  // for our purposes here, all we need is the name and the id
424  //pResult->setId(pGlobal->getKey());
425  pResult->setObjectName(pGlobal->getObjectName());
426  return pResult;
427 }
void setGroup(const CLGroup *pGroup)
Definition: CLStyle.cpp:75
const std::string & getObjectName() const
const std::set< std::string > & getRoleList() const
Definition: CLStyle.cpp:201
const std::set< std::string > & getTypeList() const
Definition: CLStyle.cpp:206
const CLGroup * getGroup() const
Definition: CLStyle.cpp:91
void setTypeList(const std::set< std::string > &typeList)
Definition: CLStyle.cpp:218
const CArrayAnnotation * pResult
void setRoleList(const std::set< std::string > &roleList)
Definition: CLStyle.cpp:211
bool setObjectName(const std::string &name)
CLRenderInformationBase * CLRenderFlattener::flatten ( const CLRenderInformationBase renderInformation,
const CCopasiVector< CLGlobalRenderInformation > &  globalList,
const CCopasiVector< CLLocalRenderInformation > &  localList = CCopasiVector<CLLocalRenderInformation>() 
)
throw (CLUnresolvedReferenceException
)
staticprotected

Takes a reference to any type of render information and two lists. The first list is a list of global render information objects, the second list is a list of local render information objects. If the object that is passed in is a global render information object, the second list is not considered.

Definition at line 60 of file CLRenderFlattener.cpp.

References CLRenderInformationBase::addColorDefinition(), CLRenderInformationBase::addGradientDefinition(), CLRenderInformationBase::addLineEnding(), CCopasiMessage::EXCEPTION, CLLineEnding::getId(), CLGradientBase::getId(), CLColorDefinition::getId(), CLLocalStyle::getKeyList(), CLLocalRenderInformation::getListOfStyles(), CLGlobalRenderInformation::getListOfStyles(), CLRenderInformationBase::getReferenceRenderInformationKey(), CLStyle::getRoleList(), CLLocalRenderInformation::getStyle(), CLGlobalRenderInformation::getStyle(), CLStyle::getTypeList(), pResult, CLRenderInformationBase::setBackgroundColor(), and CCopasiVector< T >::size().

Referenced by flatten_render_information().

61 {
63 
64  // the result should be of the same type as the type that is passed in
65  bool local = dynamic_cast<const CLLocalRenderInformation*>(&renderInformation) != NULL;
66 
67 
68  // create a list of referenced render information objects
69  std::vector< const CLRenderInformationBase * > referenceChain;
70  const CLRenderInformationBase* pCurrent = &renderInformation;
71  const CLRenderInformationBase* pNext = NULL;
72 
73  while (pCurrent != NULL)
74  {
75  // check for reference loops in reference chain
76  if (std::find(referenceChain.begin(), referenceChain.end(), pCurrent) != referenceChain.end())
77  {
78  // we have a loop
79  CCopasiMessage(CCopasiMessage::EXCEPTION, "Fatal Error. Found a loop in the referenceRenderInformation attribute chain of the render information");
80  }
81 
82  referenceChain.push_back(pCurrent);
83  std::string referenceKey = pCurrent->getReferenceRenderInformationKey();
84 
85  // search the local list if we are dealing with local render information
86  if (!referenceKey.empty())
87  {
88  if (local && localList.size() != 0)
89  {
90  size_t j = 0, jMax = localList.size();
91 
92  while (j < jMax)
93  {
94  if (localList[j]->getKey() == referenceKey)
95  {
96  pNext = dynamic_cast<const CLRenderInformationBase*>(localList[j]);
97  break;
98  }
99 
100  ++j;
101  }
102  }
103 
104  // search the global list if necessary
105  if (!pNext && globalList.size() != 0)
106  {
107  size_t j = 0, jMax = globalList.size();
108 
109  while (j < jMax)
110  {
111  if (globalList[j]->getKey() == referenceKey)
112  {
113  pNext = dynamic_cast<const CLRenderInformationBase*>(globalList[j]);
114  break;
115  }
116 
117  ++j;
118  }
119  }
120 
121  // make sure, we actually find the referenced render information
122  if (pNext)
123  {
124  pCurrent = pNext;
125  pNext = NULL;
126  }
127  else
128  {
129  throw CLUnresolvedReferenceException(referenceKey);
130  }
131  }
132  else
133  {
134  // we are at the end
135  pCurrent = NULL;
136  }
137  }
138 
139  // no we have to create a flattened version of the list.
140  std::map<std::string, const CLStyle*> keyMap;
141  std::map<std::string, const CLStyle*> typeMap;
142  std::map<std::string, const CLStyle*> roleMap;
143  std::map<std::string, const CLColorDefinition*> colors;
144  std::map<std::string, const CLLineEnding*> lineEndings;
145  std::map<std::string, const CLGradientBase*> gradients;
146  std::vector< const CLRenderInformationBase * >::const_iterator it = referenceChain.begin(), endit = referenceChain.end();
147  size_t i, iMax;
148  const CLColorDefinition* pColorDefinition = NULL;
149  const CLGradientBase* pGradientBase = NULL;
150  const CLLineEnding* pLineEnding = NULL;
151 
152  while (it != endit)
153  {
154  // go through all styles in the current render information
155  // and add each style to one or more maps, depending on whether it
156  // specifies an id, a role and/or a type list
157  // it is only added to the list, if the list doesn't already contain
158  // an item for the id, role or type
159  iMax = (*it)->getListOfColorDefinitions()->size();
160 
161  for (i = 0; i < iMax; ++i)
162  {
163  pColorDefinition = (*it)->getColorDefinition(i);
164 
165  if (colors.find(pColorDefinition->getId()) == colors.end())
166  {
167  colors.insert(std::pair<std::string, const CLColorDefinition*>(pColorDefinition->getId(), pColorDefinition));
168  }
169  }
170 
171  iMax = (*it)->getListOfGradientDefinitions()->size();
172 
173  for (i = 0; i < iMax; ++i)
174  {
175  pGradientBase = (*it)->getGradientDefinition(i);
176 
177  if (gradients.find(pGradientBase->getId()) == gradients.end())
178  {
179  gradients.insert(std::pair<std::string, const CLGradientBase*>(pGradientBase->getId(), pGradientBase));
180  }
181  }
182 
183  iMax = (*it)->getListOfLineEndings()->size();
184 
185  for (i = 0; i < iMax; ++i)
186  {
187  pLineEnding = (*it)->getLineEnding(i);
188 
189  if (lineEndings.find(pLineEnding->getId()) == lineEndings.end())
190  {
191  lineEndings.insert(std::pair<std::string, const CLLineEnding*>(pLineEnding->getId(), pLineEnding));
192  }
193  }
194 
195  const CLLocalRenderInformation* pRenderInformation = dynamic_cast<const CLLocalRenderInformation*>(*it);
196 
197  if (pRenderInformation)
198  {
199  const CLLocalStyle* pStyle = NULL;
200  iMax = pRenderInformation->getListOfStyles()->size();
201 
202  for (i = 0; i < iMax; ++i)
203  {
204  pStyle = pRenderInformation->getStyle(i);
205  const std::set<std::string>& idSet = pStyle->getKeyList();
206  std::set<std::string>::const_iterator sIt = idSet.begin(), sEndit = idSet.end();
207 
208  while (sIt != sEndit)
209  {
210  if (keyMap.find(*sIt) == keyMap.end())
211  {
212  keyMap.insert(std::pair<std::string, const CLStyle*>(*sIt, pStyle));
213  }
214 
215  ++sIt;
216  }
217 
218  const std::set<std::string>& roleSet = pStyle->getRoleList();
219 
220  sIt = roleSet.begin();
221 
222  sEndit = roleSet.end();
223 
224  while (sIt != sEndit)
225  {
226  if (roleMap.find(*sIt) == roleMap.end())
227  {
228  roleMap.insert(std::pair<std::string, const CLStyle*>(*sIt, pStyle));
229  }
230 
231  ++sIt;
232  }
233 
234  const std::set<std::string>& typeSet = pStyle->getTypeList();
235 
236  sIt = typeSet.begin();
237 
238  sEndit = typeSet.end();
239 
240  while (sIt != sEndit)
241  {
242  if (typeMap.find(*sIt) == typeMap.end())
243  {
244  typeMap.insert(std::pair<std::string, const CLStyle*>(*sIt, pStyle));
245  }
246 
247  ++sIt;
248  }
249  }
250  }
251  else
252  {
253  const CLGlobalRenderInformation* pGlobalRenderInformation = dynamic_cast<const CLGlobalRenderInformation*>(*it);
254  assert(pGlobalRenderInformation);
255  const CLStyle* pStyle = NULL;
256  iMax = pGlobalRenderInformation->getListOfStyles()->size();
257 
258  for (i = 0; i < iMax; ++i)
259  {
260  pStyle = pGlobalRenderInformation->getStyle(i);
261  const std::set<std::string>& roleSet = pStyle->getRoleList();
262  std::set<std::string>::const_iterator sIt = roleSet.begin(), sEndit = roleSet.end();
263 
264  while (sIt != sEndit)
265  {
266  if (roleMap.find(*sIt) == roleMap.end())
267  {
268  roleMap.insert(std::pair<std::string, const CLStyle*>(*sIt, pStyle));
269  }
270 
271  ++sIt;
272  }
273 
274  const std::set<std::string>& typeSet = pStyle->getTypeList();
275 
276  sIt = typeSet.begin();
277 
278  sEndit = typeSet.end();
279 
280  while (sIt != sEndit)
281  {
282  if (typeMap.find(*sIt) == typeMap.end())
283  {
284  typeMap.insert(std::pair<std::string, const CLStyle*>(*sIt, pStyle));
285  }
286 
287  ++sIt;
288  }
289  }
290  }
291 
292  ++it;
293  }
294 
295  // first we collect all styles
296  std::map<const CLStyle*, std::vector<std::set<std::string> > > styles;
297  std::map<std::string, const CLStyle*>::const_iterator mapIt = keyMap.begin(), mapEndit = keyMap.end();
298 
299  while (mapIt != mapEndit)
300  {
301  if (styles.find(mapIt->second) == styles.end())
302  {
303  // add a new vector of sets to the map
304  // the first set is for ids, the esecond for roles and the third
305  // for types
306  styles[mapIt->second] = std::vector<std::set<std::string> >(3);
307  }
308 
309  styles[mapIt->second][0].insert(mapIt->first);
310  ++mapIt;
311  }
312 
313  mapIt = roleMap.begin();
314  mapEndit = roleMap.end();
315 
316  while (mapIt != mapEndit)
317  {
318  if (styles.find(mapIt->second) == styles.end())
319  {
320  // add a new vector of sets to the map
321  // the first set is for ids, the esecond for roles and the third
322  // for types
323  styles[mapIt->second] = std::vector<std::set<std::string> >(3);
324  }
325 
326  styles[mapIt->second][1].insert(mapIt->first);
327  ++mapIt;
328  }
329 
330  mapIt = typeMap.begin();
331  mapEndit = typeMap.end();
332 
333  while (mapIt != mapEndit)
334  {
335  if (styles.find(mapIt->second) == styles.end())
336  {
337  // add a new vector of sets to the map
338  // the first set is for ids, the esecond for roles and the third
339  // for types
340  styles[mapIt->second] = std::vector<std::set<std::string> >(3);
341  }
342 
343  styles[mapIt->second][2].insert(mapIt->first);
344  ++mapIt;
345  }
346 
347  // now we create and fill the result render information
348  if (local)
349  {
350  pResult = new CLLocalRenderInformation();
351  std::map<const CLStyle*, std::vector<std::set<std::string> > >::const_iterator styleIt = styles.begin(), styleEndit = styles.end();
352  CLLocalStyle* pLocalStyle = NULL;
353 
354  while (styleIt != styleEndit)
355  {
356  // check if the style is a local style
357  // if yes, we can just clone it,
358  // else it gets more complicated
359  if (dynamic_cast<const CLLocalStyle*>(styleIt->first))
360  {
361  dynamic_cast<CLLocalRenderInformation*>(pResult)->addStyle(static_cast<const CLLocalStyle*>(styleIt->first));
362  }
363  else
364  {
365  pLocalStyle = convertGlobalToLocalStyle(static_cast<const CLGlobalStyle*>(styleIt->first));
366  dynamic_cast<CLLocalRenderInformation*>(pResult)->addStyle(pLocalStyle);
367  delete pLocalStyle;
368  }
369 
370  ++styleIt;
371  }
372  }
373  else
374  {
375  pResult = new CLGlobalRenderInformation();
376  std::map<const CLStyle*, std::vector<std::set<std::string> > >::const_iterator styleIt = styles.begin(), styleEndit = styles.end();
377 
378  while (styleIt != styleEndit)
379  {
380  static_cast<CLGlobalRenderInformation*>(pResult)->addStyle(dynamic_cast<const CLGlobalStyle*>(styleIt->first));
381  ++styleIt;
382  }
383  }
384 
385  // fill the color, gradients and line endings
386  std::map<std::string, const CLColorDefinition*>::const_iterator colorIt = colors.begin(), colorEndit = colors.end();
387 
388  while (colorIt != colorEndit)
389  {
390  pResult->addColorDefinition(colorIt->second);
391  ++colorIt;
392  }
393 
394  std::map<std::string, const CLGradientBase*>::const_iterator gradientIt = gradients.begin(), gradientEndit = gradients.end();
395 
396  while (gradientIt != gradientEndit)
397  {
398  pResult->addGradientDefinition(gradientIt->second);
399  ++gradientIt;
400  }
401 
402  std::map<std::string, const CLLineEnding*>::const_iterator lineIt = lineEndings.begin(), lineEndit = lineEndings.end();
403 
404  while (lineIt != lineEndit)
405  {
406  pResult->addLineEnding(lineIt->second);
407  ++lineIt;
408  }
409 
410  pResult->setBackgroundColor(renderInformation.getBackgroundColor());
411  return pResult;
412 }
void addLineEnding(const CLLineEnding *le)
virtual size_t size() const
const std::string & getBackgroundColor() const
CCopasiVector< CLGlobalStyle > * getListOfStyles()
const std::string & getId() const
const std::set< std::string > & getKeyList() const
CLLocalStyle * getStyle(size_t i)
void addGradientDefinition(const CLGradientBase *gradient)
void setBackgroundColor(const std::string &bg)
const std::string & getReferenceRenderInformationKey() const
const std::set< std::string > & getRoleList() const
Definition: CLStyle.cpp:201
static CLLocalStyle * convertGlobalToLocalStyle(const CLGlobalStyle *pGlobal)
const std::set< std::string > & getTypeList() const
Definition: CLStyle.cpp:206
const std::string & getId() const
const CArrayAnnotation * pResult
CCopasiVector< CLLocalStyle > * getListOfStyles()
void addColorDefinition(const CLColorDefinition *cd)
const std::string & getId() const
CLGlobalRenderInformation * CLRenderFlattener::flatten_render_information ( const CLGlobalRenderInformation globalRenderInformation,
const CCopasiVector< CLGlobalRenderInformation > &  globalList 
)
throw (CLUnresolvedReferenceException
)
static

static method that takes a const reference to a global render information object and resolves all references. The returned object is a new global render information object and the caller is responsible for freeing the memory once it is no longer used. If references can not be resolved, an unresolved_reference_exception is thrown.

Definition at line 36 of file CLRenderFlattener.cpp.

References flatten().

37 {
38  return dynamic_cast<CLGlobalRenderInformation*>(CLRenderFlattener::flatten(globalRenderInformation, globalList));
39 }
static CLRenderInformationBase * flatten(const CLRenderInformationBase &renderInformation, const CCopasiVector< CLGlobalRenderInformation > &globalList, const CCopasiVector< CLLocalRenderInformation > &localList=CCopasiVector< CLLocalRenderInformation >())
CLLocalRenderInformation * CLRenderFlattener::flatten_render_information ( const CLLocalRenderInformation localRenderInformation,
const CCopasiVector< CLLocalRenderInformation > &  localList,
const CCopasiVector< CLGlobalRenderInformation > &  globalList 
)
throw (CLUnresolvedReferenceException
)
static

static method that takes a const reference to a local render information object and resolves all references. The returned object is a new local render information object and the caller is responsible for freeing the memory once it is no longer used. If references can not be resolved, an unresolved_reference_exception is thrown.

Definition at line 49 of file CLRenderFlattener.cpp.

References flatten().

50 {
51  return dynamic_cast<CLLocalRenderInformation*>(CLRenderFlattener::flatten(localRenderInformation, globalList, localList));
52 }
static CLRenderInformationBase * flatten(const CLRenderInformationBase &renderInformation, const CCopasiVector< CLGlobalRenderInformation > &globalList, const CCopasiVector< CLLocalRenderInformation > &localList=CCopasiVector< CLLocalRenderInformation >())

The documentation for this class was generated from the following files: