COPASI API  4.16.103
CLTransformation2D.cpp
Go to the documentation of this file.
1 // Begin CVS Header
2 // $Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/layout/CLTransformation2D.cpp,v $
3 // $Revision: 1.4 $
4 // $Name: $
5 // $Author: shoops $
6 // $Date: 2012/04/23 15:44:51 $
7 // End CVS Header
8 
9 // Copyright (C) 2012 - 2010 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 <string.h>
15 #include <stdlib.h>
16 #include <sstream>
17 
18 #include <sbml/packages/render/sbml/Transformation2D.h>
19 
20 #include "CLTransformation2D.h"
21 
22 /**
23  * Constructor.
24  */
26 {
27  unsigned int i;
28 
29  for (i = 0; i < 12; ++i)
30  {
31  mMatrix[i] = IDENTITY3D[i];
32  }
33 
34  this->updateMatrix2D();
35 }
36 
37 /**
38  * Constructor with values for the matrix.
39  */
41 {
42  this->setMatrix2D(matrix);
43 }
44 
45 /**
46  * Constructor to generate object from the corresponding SBML object.
47  */
48 CLTransformation2D::CLTransformation2D(const Transformation2D& source):
50 {
51  if (source.isSetMatrix())
52  {
53  this->setMatrix2D(source.getMatrix2D());
54  }
55  else
56  {
57  this->updateMatrix2D();
58  }
59 }
60 
61 /**
62  * Sets the matrix.
63  */
64 void CLTransformation2D::setMatrix2D(const double m[6])
65 {
66  unsigned int i;
67 
68  for (i = 0; i < 6; ++i)
69  {
70  mMatrix2D[i] = m[i];
71  }
72 
73  this->updateMatrix3D();
74 }
75 
76 /**
77  * Returns the matrix.
78  * The matrix contains 6 values.
79  */
80 const double* CLTransformation2D::getMatrix2D() const
81 {
82  return mMatrix2D;
83 }
84 
85 /**
86  * Returns a 2D identity matrix.
87  * The matrix contains 6 values.
88  */
90 {
91  return IDENTITY2D;
92 }
93 
94 const double CLTransformation2D::IDENTITY2D[6] = {1.0, 0.0, 0.0, 1.0, 0.0, 0.0};
95 
97 {
98  // transform the matrix to a string
99  std::ostringstream os;
100  unsigned int i;
101  os << mMatrix2D[0];
102 
103  for (i = 1; i < 6; ++i)
104  {
105  os << "," << mMatrix2D[i];
106  }
107 
108  return os.str();
109 }
110 
111 /**
112  * Sets the 3D matrix from the 2D matrix.
113  */
115 {
116  mMatrix[0] = mMatrix2D[0];
117  mMatrix[1] = mMatrix2D[1];
118  mMatrix[2] = 0.0;
119  mMatrix[3] = mMatrix2D[2];
120  mMatrix[4] = mMatrix2D[3];
121  mMatrix[5] = 0.0;
122  mMatrix[6] = 0.0;
123  mMatrix[7] = 0.0;
124  mMatrix[8] = 1.0;
125  mMatrix[9] = mMatrix2D[4];
126  mMatrix[10] = mMatrix2D[5];
127  mMatrix[11] = 0.0;
128 }
129 
130 /**
131  * Fills the 2D matrix with data from the 3D matrix.
132  */
134 {
135  mMatrix2D[0] = mMatrix[0];
136  mMatrix2D[1] = mMatrix[1];
137  mMatrix2D[2] = mMatrix[3];
138  mMatrix2D[3] = mMatrix[4];
139  mMatrix2D[4] = mMatrix[9];
140  mMatrix2D[5] = mMatrix[10];
141 }
142 
143 void CLTransformation2D::setMatrix(const double m[12])
144 {
146  this->updateMatrix2D();
147 }
148 
149 void CLTransformation2D::parseTransformation(const std::string& transformationString)
150 {
151  // the string should contain a list of 6 komma seperated numbers
152  // if it doesn't, we try to set the 3D matrix
153  bool result = true;
154  std::string delimiter = ",";
155  std::size_t lastPos = transformationString.find_first_not_of(delimiter);
156  std::size_t pos;
157  unsigned int index = 0;
158 
159  while (lastPos != std::string::npos)
160  {
161  if (index > 5)
162  {
163  result = false;
164  break;
165  }
166 
167  pos = transformationString.find_first_of(delimiter, lastPos);
168  double value = strtod(transformationString.substr(lastPos, pos - lastPos).c_str(), NULL);
169  mMatrix2D[index] = value;
170  index++;
171  lastPos = transformationString.find_first_not_of(delimiter, pos);
172  }
173 
174  if (!result || index != 6)
175  {
176  this->CLTransformation::parseTransformation(transformationString);
177  this->updateMatrix2D();
178  }
179  else
180  {
181  this->updateMatrix3D();
182  }
183 }
184 
185 /**
186  * Adds the attributes for a 2d transformation object to the passed in.
187  * object.
188  */
189 void CLTransformation2D::addSBMLAttributes(Transformation2D* pTransformation) const
190 {
191  pTransformation->setMatrix2D(this->mMatrix2D);
192 }
std::string get2DTransformationString() const
void setMatrix(const double m[12])
static const double IDENTITY3D[12]
virtual void addSBMLAttributes(Transformation2D *pTransformation) const
void setMatrix2D(const double m[6])
static const double IDENTITY2D[6]
virtual void parseTransformation(const std::string &transformationString)
void setMatrix(const double m[12])
const double * getMatrix2D() const
static const double * getIdentityMatrix2D()
virtual void parseTransformation(const std::string &transformationString)