COPASI API  4.16.103
CLayoutState.cpp
Go to the documentation of this file.
1 // Copyright (C) 2013 by Pedro Mendes, Virginia Tech Intellectual
2 // Properties, Inc., University of Heidelberg, and The University
3 // of Manchester.
4 // All rights reserved.
5 
6 #include <layout/CLayoutState.h>
7 
8 #include <layout/CLBase.h>
9 #include <layout/CLCurve.h>
10 #include <layout/CLayout.h>
11 
12 void tagKey(CLGraphicalObject* element)
13 {
14  element->setTag(element->getKey());
15 }
16 
18 {
19  if (layout == NULL) return;
20 
22  CCopasiVector<CLGeneralGlyph>::iterator generalIt = general.begin();
23 
24  while (generalIt != general.end())
25  {
26  tagKey((*generalIt));
27 
28  CCopasiVector<CLReferenceGlyph>::iterator refIt = (*generalIt)->getListOfReferenceGlyphs().begin();
29 
30  for (; refIt != (*generalIt)->getListOfReferenceGlyphs().end(); ++refIt)
31  tagKey(*refIt);
32 
33  CCopasiVector<CLGraphicalObject>::iterator subIt = (*generalIt)->getListOfSubglyphs().begin();
34 
35  for (; subIt != (*generalIt)->getListOfSubglyphs().end(); ++subIt)
36  tagKey(*subIt);
37 
38  ++generalIt;
39  }
40 
43 
44  while (compIt != comps.end())
45  {
46  tagKey((*compIt));
47  ++compIt;
48  }
49 
51  CCopasiVector<CLReactionGlyph>::iterator reactIt = reactions.begin();
52 
53  while (reactIt != reactions.end())
54  {
55  tagKey((*reactIt));
56 
57  CCopasiVector<CLMetabReferenceGlyph>::iterator refIt = (*reactIt)->getListOfMetabReferenceGlyphs().begin();
58 
59  for (; refIt != (*reactIt)->getListOfMetabReferenceGlyphs().end(); ++refIt)
60  tagKey(*refIt);
61 
62  ++reactIt;
63  }
64 
66  CCopasiVector<CLMetabGlyph>::iterator speciesIt = species.begin();
67 
68  while (speciesIt != species.end())
69  {
70  tagKey((*speciesIt));
71  ++speciesIt;
72  }
73 
76 
77  while (textIt != texts .end())
78  {
79  tagKey((*textIt));
80  ++textIt;
81  }
82 }
83 
85  : mAdditionalState()
86  , mCompartmentState()
87  , mReactionState()
88  , mSpeciesState()
89  , mTextState()
90  , mCurves()
91 {
92  if (layout == NULL) return;
93 
94  const CCopasiVector<CLGeneralGlyph> & general = layout->getListOfGeneralGlyphs();
96 
97  while (generalIt != general.end())
98  {
99  mAdditionalState[(*generalIt)->getTag()] = new CLBoundingBox((*generalIt)->getBoundingBox());
100  ++generalIt;
101  }
102 
105 
106  while (compIt != comps.end())
107  {
108  mCompartmentState[(*compIt)->getTag()] = new CLBoundingBox((*compIt)->getBoundingBox());
109  ++compIt;
110  }
111 
112  const CCopasiVector<CLReactionGlyph> & reactions = layout->getListOfReactionGlyphs();
114 
115  while (reactIt != reactions.end())
116  {
117  mReactionState[(*reactIt)->getTag()] = new CLBoundingBox((*reactIt)->getBoundingBox());
118 
119  mCurves[(*reactIt)->getTag()] = new CLCurve((*reactIt)->getCurve());
120 
121  CCopasiVector<CLMetabReferenceGlyph>::const_iterator refIt = (*reactIt)->getListOfMetabReferenceGlyphs().begin();
122 
123  for (; refIt != (*reactIt)->getListOfMetabReferenceGlyphs().end(); ++refIt)
124  mCurves[(*refIt)->getTag()] = new CLCurve((*refIt)->getCurve());
125 
126  ++reactIt;
127  }
128 
129  const CCopasiVector<CLMetabGlyph> & species = layout->getListOfMetaboliteGlyphs();
131 
132  while (speciesIt != species.end())
133  {
134  mSpeciesState[(*speciesIt)->getTag()] = new CLBoundingBox((*speciesIt)->getBoundingBox());
135  ++speciesIt;
136  }
137 
138  const CCopasiVector<CLTextGlyph> & texts = layout->getListOfTextGlyphs();
140 
141  while (textIt != texts .end())
142  {
143  mTextState[(*textIt)->getTag()] = new CLBoundingBox((*textIt)->getBoundingBox());
144  ++textIt;
145  }
146 }
147 
149 {
150  std::map<const std::string, CLBoundingBox*>::reverse_iterator it;
151 
152  for (it = mAdditionalState.rbegin(); it != mAdditionalState.rend(); ++it)
153  {
154  delete it->second;
155  }
156 
157  for (it = mCompartmentState.rbegin(); it != mCompartmentState.rend(); ++it)
158  {
159  delete it->second;
160  }
161 
162  for (it = mReactionState.rbegin(); it != mReactionState.rend(); ++it)
163  {
164  delete it->second;
165  }
166 
167  for (it = mSpeciesState.rbegin(); it != mSpeciesState.rend(); ++it)
168  {
169  delete it->second;
170  }
171 
172  for (it = mTextState.rbegin(); it != mTextState.rend(); ++it)
173  {
174  delete it->second;
175  }
176 
177  std::map<const std::string, CLCurve*>::reverse_iterator curveIt;
178 
179  for (curveIt = mCurves.rbegin(); curveIt != mCurves.rend(); ++curveIt)
180  {
181  delete curveIt->second;
182  }
183 }
184 
185 #define STATE_SET_POSITIONS(objectMap, it, endIt)\
186  {\
187  for (;it != endIt; ++it)\
188  {\
189  const std::string& key = ((*it)->getTag());\
190  StringBoundMap::const_iterator boundIt = objectMap.find(key);\
191  if (boundIt == objectMap.end()) \
192  continue; \
193  CLBoundingBox* current = boundIt->second;\
194  (*it)->setPosition(current->getPosition());\
195  }\
196  }
197 
198 void CLayoutState::applyTo(CLayout *layout) const
199 {
200  if (layout == NULL) return;
201 
202  CLayoutState current(layout);
203 
205  CCopasiVector<CLGeneralGlyph>::iterator generalIt = general.begin();
206  STATE_SET_POSITIONS(mAdditionalState, generalIt, general.end());
207 
210  STATE_SET_POSITIONS(mCompartmentState, compIt, comps.end());
211 
213  CCopasiVector<CLReactionGlyph>::iterator reactIt = reactions.begin();
214  STATE_SET_POSITIONS(mReactionState, reactIt, reactions.end());
215 
216  for (reactIt = reactions.begin(); reactIt != reactions.end(); ++reactIt)
217  {
218  const std::string& rkey = ((*reactIt)->getTag());
219  StringCurveMap::const_iterator cIt = mCurves.find(rkey);
220 
221  if (cIt != mCurves.end())
222  {
223  CLCurve* current = cIt->second;
224  (*reactIt)->setCurve(*current);
225  }
226 
227  CCopasiVector<CLMetabReferenceGlyph>::iterator refIt = (*reactIt)->getListOfMetabReferenceGlyphs().begin();
228 
229  for (; refIt != (*reactIt)->getListOfMetabReferenceGlyphs().end(); ++refIt)
230  {
231  const std::string& key = ((*refIt)->getTag());
232  cIt = mCurves.find(key);
233 
234  if (cIt == mCurves.end())
235  continue;
236 
237  CLCurve* current = cIt->second;
238  (*refIt)->setCurve(*current);
239  }
240  }
241 
243  CCopasiVector<CLMetabGlyph>::iterator speciesIt = species.begin();
244  STATE_SET_POSITIONS(mSpeciesState, speciesIt, species.end());
245 
248  STATE_SET_POSITIONS(mTextState, textIt, texts.end());
249 }
std::map< const std::string, CLCurve * > mCurves
Definition: CLayoutState.h:34
static void tagLayout(CLayout *layout)
const CCopasiVector< CLTextGlyph > & getListOfTextGlyphs() const
Definition: CLayout.h:120
iterator begin()
#define STATE_SET_POSITIONS(objectMap, it, endIt)
const CCopasiVector< CLCompartmentGlyph > & getListOfCompartmentGlyphs() const
Definition: CLayout.h:81
virtual const std::string & getKey() const
void tagKey(CLGraphicalObject *element)
void applyTo(CLayout *layout) const
iterator end()
std::map< const std::string, CLBoundingBox * > mCompartmentState
Definition: CLayoutState.h:30
const CCopasiVector< CLMetabGlyph > & getListOfMetaboliteGlyphs() const
Definition: CLayout.h:94
const CCopasiVector< CLGeneralGlyph > & getListOfGeneralGlyphs() const
Definition: CLayout.h:133
CLayoutState(const CLayout *layout)
virtual ~CLayoutState()
std::map< const std::string, CLBoundingBox * > mSpeciesState
Definition: CLayoutState.h:32
std::map< const std::string, CLBoundingBox * > mAdditionalState
Definition: CLayoutState.h:29
std::map< const std::string, CLBoundingBox * > mTextState
Definition: CLayoutState.h:33
void setTag(const std::string &tag)
Definition: CLBase.h:44
std::map< const std::string, CLBoundingBox * > mReactionState
Definition: CLayoutState.h:31
const CCopasiVector< CLReactionGlyph > & getListOfReactionGlyphs() const
Definition: CLayout.h:107