COPASI API  4.16.103
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
Expression2PresentationMMLUnits Class Reference

#include <Expression2PresentationMMLUnits.h>

Inheritance diagram for Expression2PresentationMMLUnits:
Inheritance graph
[legend]
Collaboration diagram for Expression2PresentationMMLUnits:
Collaboration graph
[legend]

Public Member Functions

 Expression2PresentationMMLUnits (const ASTNode *rootnode)
 
std::string getMathML (const CSBMLunitInformation &ui) const
 
void setUnitInterface (CSBMLunitInterface *unitInterface, CSBMLunitInterface *unitInterface2)
 
- Public Member Functions inherited from Expression2PresentationMML
 Expression2PresentationMML (const ASTNode *rootnode)
 
void setModel (const Model *m)
 
void setReaction (const Reaction *m)
 
void setUseReactionNameInLocalParameters (bool b)
 
void writeMathML (std::ostream &out) const
 
virtual ~Expression2PresentationMML ()
 

Protected Member Functions

std::string getMathML (const UnitDefinition &ud) const
 
std::string getMathML (const Unit *u, bool absExp) const
 
void writeMathMLBox (std::ostream &out, const std::string &a, const std::string &b, const std::string &color, size_t l) const
 
void writeMathMLBox (std::ostream &out, const std::string &a, const std::string &b, const std::string &c, const std::string &color, size_t l) const
 
virtual void writeMathMLName (std::ostream &out, const ASTNode *node, size_t l) const
 
virtual void writeMathMLNumber (std::ostream &out, const ASTNode *node, size_t l) const
 
- Protected Member Functions inherited from Expression2PresentationMML
void writeMathML (std::ostream &out, const ASTNode *node, size_t l) const
 
virtual void writeMathMLFunction (std::ostream &out, const ASTNode *node, size_t l) const
 

Protected Attributes

CSBMLunitInterfacempUnitInterface
 
CSBMLunitInterfacempUnitInterface2
 
- Protected Attributes inherited from Expression2PresentationMML
const Model * mpModel
 
const Reaction * mpReaction
 
const ASTNode * mRootNode
 
bool mUseReactionNameInLocalParameters
 

Detailed Description

Definition at line 24 of file Expression2PresentationMMLUnits.h.

Constructor & Destructor Documentation

Expression2PresentationMMLUnits::Expression2PresentationMMLUnits ( const ASTNode *  rootnode)

Definition at line 18 of file Expression2PresentationMMLUnits.cpp.

19  : Expression2PresentationMML(rootnode),
20  mpUnitInterface(NULL)
21 {
22 }
Expression2PresentationMML(const ASTNode *rootnode)

Member Function Documentation

std::string Expression2PresentationMMLUnits::getMathML ( const CSBMLunitInformation ui) const

Definition at line 115 of file Expression2PresentationMMLUnits.cpp.

References CSBMLunitInformation::DEFAULT, CSBMLunitInformation::DERIVED, CSBMLunitInformation::getInfo(), CSBMLunit::getSBMLUnitDefinition(), CSBMLunit::getSymbolicExpExp(), CSBMLunit::getSymbolicExponent(), CSBMLunitInformation::GLOBAL, CSBMLunitInformation::isConflict(), CSBMLunitInformation::PROVIDED, and CSBMLunitInformation::UNKNOWN.

Referenced by getMathML(), writeMathMLName(), and writeMathMLNumber().

116 {
117  std::string tmp;
118  tmp += "<mrow>";
119 
120  if (ui.isConflict())
121  tmp += "<mi mathcolor = \"red\">conflict!</mi>";
122 
123  if (ui.getSymbolicExpExp() > 0)
124  tmp += "<mfenced>";
125 
126  switch (ui.getInfo())
127  {
129  tmp += "<mi mathcolor = \"orange\">unknown</mi>";
130  break;
131 
133  tmp += "<mstyle mathcolor=\"#000060\">" + getMathML(ui.getSBMLUnitDefinition()) + "</mstyle>";
134  break;
135 
137  tmp += "<mstyle mathcolor=\"#0000a0\">" + getMathML(ui.getSBMLUnitDefinition()) + "</mstyle>";
138  break;
139 
141  tmp += "<mstyle mathcolor=\"#2020ff\">" + getMathML(ui.getSBMLUnitDefinition()) + "</mstyle>";
142  break;
143 
145  tmp += "<mstyle mathcolor=\"green\">" + getMathML(ui.getSBMLUnitDefinition()) + "</mstyle>";
146  break;
147  }
148 
149  if (ui.getSymbolicExpExp() > 0)
150  {
151  std::ostringstream ttt; ttt << ui.getSymbolicExpExp();
152  tmp += "</mfenced><mo>^</mo><mi mathcolor = \"#c06000\">" + ui.getSymbolicExponent() + "</mi><mo>^</mo><mn>" + ttt.str() + "</mn>";
153  }
154 
155  tmp += "</mrow>";
156  return tmp;
157 }
the units is determined from the sbml defaults
Definition: CSBMLunit.h:108
the units is unknown
Definition: CSBMLunit.h:106
the units is determined from the model-wide definitions
Definition: CSBMLunit.h:110
INFO getInfo() const
get the status information
Definition: CSBMLunit.h:130
int getSymbolicExpExp() const
Definition: CSBMLunit.h:72
the units if provided for a specific object explicitly
Definition: CSBMLunit.h:112
std::string getMathML(const CSBMLunitInformation &ui) const
UnitDefinition & getSBMLUnitDefinition()
Definition: CSBMLunit.h:69
the units was determined by reasoning
Definition: CSBMLunit.h:114
const std::string & getSymbolicExponent() const
Definition: CSBMLunit.h:73
bool isConflict() const
retrieve the conflict flag
Definition: CSBMLunit.h:136
std::string Expression2PresentationMMLUnits::getMathML ( const UnitDefinition &  ud) const
protected

Definition at line 192 of file Expression2PresentationMMLUnits.cpp.

References getMathML().

193 {
194  std::string tmp;
195 
196  /*tmp += "<mrow>";
197  size_t i, imax = ud.getNumUnits();
198  for (i=0; i<imax; ++i)
199  {
200  if (i) tmp += "<mo>&CenterDot;</mo>";
201  tmp += getMathML(ud.getUnit(i), false);
202  }
203  tmp += "</mrow>";*/
204 
205  tmp += "<mrow>";
206  bool isFirst = true;
207  size_t i, imax = ud.getNumUnits();
208 
209  for (i = 0; i < imax; ++i)
210  {
211  if (ud.getUnit((unsigned int) i)->getExponent() >= 0)
212  {
213  if (!isFirst) tmp += "<mo>&CenterDot;</mo>";
214 
215  tmp += getMathML(ud.getUnit((unsigned int) i), true);
216  isFirst = false;
217  }
218  }
219 
220  if (isFirst) tmp += "<mn>1</mn>"; //there are no units with pos. exponent
221 
222  std::string tmp2;
223  isFirst = true;
224 
225  for (i = 0; i < imax; ++i)
226  {
227  if (ud.getUnit((unsigned int) i)->getExponent() < 0)
228  {
229  if (!isFirst) tmp2 += "<mo>&CenterDot;</mo>";
230 
231  tmp2 += getMathML(ud.getUnit((unsigned int) i), true);
232  isFirst = false;
233  }
234  }
235 
236  if (!isFirst) tmp += "<mo>/</mo>" + tmp2; //only create fraction when there is a denominator
237 
238  tmp += "</mrow>";
239 
240  return tmp;
241 }
std::string getMathML(const CSBMLunitInformation &ui) const
std::string Expression2PresentationMMLUnits::getMathML ( const Unit *  u,
bool  absExp 
) const
protected

Definition at line 243 of file Expression2PresentationMMLUnits.cpp.

References abs.

244 {
245  if (!u)
246  return "<mi>EEE</mi>";
247 
248  int exponent = absExp ? abs(u->getExponent()) : u->getExponent();
249  bool flagExp = (exponent != 1);
250  bool flag = (u->getMultiplier() != 1.0) || (u->getScale() != 0); //are brackets needed?
251 
252  std::ostringstream tmp;
253 
254  if (flagExp) tmp << "<msup>";
255 
256  //if (flag) tmp << "<mfenced>";
257  tmp << "<mrow>";
258 
259  if (flag) tmp << "<mo>(</mo>";
260 
261  if (u->getMultiplier() != 1.0)
262  tmp << "<mn>" << u->getMultiplier() << "</mn><mo>&CenterDot;</mo>";
263 
264  if (u->getScale() != 0)
265  tmp << "<msup><mn>10</mn><mn>" << u->getScale() << "</mn></msup><mo>&CenterDot;</mo>";
266 
267  tmp << "<mi>";
268  tmp << UnitKind_toString(u->getKind());
269  tmp << "</mi>";
270 
271  if (flag) tmp << "<mo>)</mo>";
272 
273  tmp << "</mrow>";
274  //if (flag) tmp << "</mfenced>";
275 
276  if (flagExp) tmp << "<mn>" << exponent << "</mn>";
277 
278  if (flagExp) tmp << "</msup>";
279 
280  //tmp << "</mrow>";
281 
282  return tmp.str();
283 }
long int flag
Definition: f2c.h:52
#define abs(x)
Definition: f2c.h:173
void Expression2PresentationMMLUnits::setUnitInterface ( CSBMLunitInterface unitInterface,
CSBMLunitInterface unitInterface2 
)

sets the unit interface to the SBML model so that the units can be displayed. this implicitly also handles setting the model

Definition at line 24 of file Expression2PresentationMMLUnits.cpp.

References CSBMLunitInterface::getModel(), Expression2PresentationMML::mpModel, mpUnitInterface, and mpUnitInterface2.

25 {
26  mpUnitInterface = unitInterface;
27  mpUnitInterface2 = unitInterface2;
29 }
void Expression2PresentationMMLUnits::writeMathMLBox ( std::ostream &  out,
const std::string &  a,
const std::string &  b,
const std::string &  color,
size_t  l 
) const
protected

write the mathML for a box that is used to display an object identifier + its unit information a and b are mathML strings

Definition at line 159 of file Expression2PresentationMMLUnits.cpp.

References SPC.

Referenced by writeMathMLName(), and writeMathMLNumber().

161 {
162  out << SPC(l) << "<mstyle background=\"" << color << "\"><mfrac linethickness=\"0\">" << std::endl;
163  out << a;
164  out << SPC(l + 1) << "<mstyle scriptlevel=\"+1\">" << std::endl;
165  out << SPC(l + 2) << b << std::endl;
166  out << SPC(l + 1) << "</mstyle>" << std::endl;
167  out << SPC(l) << "</mfrac></mstyle>" << std::endl;
168 
169  //formating is done so that it looks best when a is already indented nicely while b
170  //is just a one line string
171 }
#define SPC(level)
void Expression2PresentationMMLUnits::writeMathMLBox ( std::ostream &  out,
const std::string &  a,
const std::string &  b,
const std::string &  c,
const std::string &  color,
size_t  l 
) const
protected

Definition at line 173 of file Expression2PresentationMMLUnits.cpp.

References SPC.

175 {
176  out << SPC(l) << "<mstyle background=\"" << color << "\"><mtable rowspacing=\"0.1 ex\">" << std::endl;
177  out << SPC(l + 1) << "<mtr><mtd>" << std::endl;
178  out << a;
179  out << SPC(l + 1) << "</mtd></mtr>" << std::endl;
180  out << SPC(l + 1) << "<mtr><mtd><mstyle scriptlevel=\"+1\">" << std::endl;
181  out << SPC(l + 2) << b << std::endl;
182  out << SPC(l + 1) << "</mstyle></mtd></mtr>" << std::endl;
183  out << SPC(l + 1) << "<mtr><mtd><mstyle scriptlevel=\"+1\">" << std::endl;
184  out << SPC(l + 2) << c << std::endl;
185  out << SPC(l + 1) << "</mstyle></mtd></mtr>" << std::endl;
186  out << SPC(l) << "</mtable></mstyle>" << std::endl;
187 
188  //formating is done so that it looks best when a is already indented nicely while b
189  //is just a one line string
190 }
#define SPC(level)
void Expression2PresentationMMLUnits::writeMathMLName ( std::ostream &  out,
const ASTNode *  node,
size_t  l 
) const
protectedvirtual

Reimplemented from Expression2PresentationMML.

Definition at line 33 of file Expression2PresentationMMLUnits.cpp.

References CSBMLunitInterface::getListOfConflictingNodes(), CSBMLunitInterface::getMappedUnitFromIdentifier(), getMathML(), CSBMLunitInformation::isEqual(), Expression2PresentationMML::mpReaction, mpUnitInterface, mpUnitInterface2, writeMathMLBox(), and Expression2PresentationMML::writeMathMLName().

34 {
35  std::string reactionID = mpReaction ? mpReaction->getId() : "";
36  CSBMLunitInformation* unitInformation = mpUnitInterface->getMappedUnitFromIdentifier(node->getName(),
38 
39  if (!unitInformation)
40  {
41  //use the base class implementation
43  return;
44  }
45 
46  std::string color;
47 
50  color = "#f0b0b0";
51  else
52  color = "#d0d0e0";
53 
54  CSBMLunitInformation * unitInformation2 = NULL;
55 
56  if (mpUnitInterface2)
57  unitInformation2 = mpUnitInterface2->getMappedUnitFromIdentifier(node->getName(),
59 
60  std::ostringstream oss;
62 
63  if (unitInformation2 != NULL)
64  {
65  if (CSBMLunitInformation::isEqual(*unitInformation, *unitInformation2))
66  writeMathMLBox(out, oss.str(), getMathML(*unitInformation), "", color, l);
67  else
68  writeMathMLBox(out, oss.str(), getMathML(*unitInformation), getMathML(*unitInformation2), color, l);
69  }
70  else
71  writeMathMLBox(out, oss.str(), getMathML(*unitInformation), color, l);
72 }
CSBMLunitInformation * getMappedUnitFromIdentifier(const std::string &node, const CEnvironmentInformation &ei)
void writeMathMLBox(std::ostream &out, const std::string &a, const std::string &b, const std::string &color, size_t l) const
std::string getMathML(const CSBMLunitInformation &ui) const
static bool isEqual(const CSBMLunitInformation &unit1, const CSBMLunitInformation &unit2)
Definition: CSBMLunit.cpp:240
virtual void writeMathMLName(std::ostream &out, const ASTNode *node, size_t l) const
const std::set< const ASTNode * > & getListOfConflictingNodes() const
void Expression2PresentationMMLUnits::writeMathMLNumber ( std::ostream &  out,
const ASTNode *  node,
size_t  l 
) const
protectedvirtual

Reimplemented from Expression2PresentationMML.

Definition at line 74 of file Expression2PresentationMMLUnits.cpp.

References CSBMLunitInterface::getListOfConflictingNodes(), CSBMLunitInterface::getMappedUnitFromNumberNode(), getMathML(), mpUnitInterface, mpUnitInterface2, writeMathMLBox(), and Expression2PresentationMML::writeMathMLNumber().

75 {
77  CSBMLunitInformation* unitInformation2 = NULL;
78 
79  if (mpUnitInterface2)
80  unitInformation2 = mpUnitInterface2->getMappedUnitFromNumberNode(node);
81 
82  if (!unitInformation && !unitInformation2)
83  {
85  return;
86  }
87 
88  std::string color;
89 
92  color = "#f0b0b0";
93  else
94  color = "#d0e0d0";
95 
96  std::ostringstream oss;
98 
99  if (!unitInformation && unitInformation2)
100  {
101  writeMathMLBox(out, oss.str(), "<mi>unknown</mi>", getMathML(*unitInformation2), color, l);
102  }
103 
104  if (unitInformation && !unitInformation2)
105  {
106  writeMathMLBox(out, oss.str(), getMathML(*unitInformation), color, l);
107  }
108 
109  if (unitInformation && unitInformation2)
110  {
111  writeMathMLBox(out, oss.str(), getMathML(*unitInformation), getMathML(*unitInformation2), color, l);
112  }
113 }
virtual void writeMathMLNumber(std::ostream &out, const ASTNode *node, size_t l) const
void writeMathMLBox(std::ostream &out, const std::string &a, const std::string &b, const std::string &color, size_t l) const
CSBMLunitInformation * getMappedUnitFromNumberNode(const ASTNode *node)
std::string getMathML(const CSBMLunitInformation &ui) const
const std::set< const ASTNode * > & getListOfConflictingNodes() const

Member Data Documentation

CSBMLunitInterface* Expression2PresentationMMLUnits::mpUnitInterface
protected
CSBMLunitInterface* Expression2PresentationMMLUnits::mpUnitInterface2
protected

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