COPASI API  4.16.103
Public Slots | Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | List of all members
CQDifferentialEquations Class Reference

#include <CQDifferentialEquations.h>

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

Public Slots

virtual void slotSave ()
 
virtual void slotUpdateWidget ()
 

Public Member Functions

 CQDifferentialEquations (QWidget *parent=0, const char *name=0)
 
 ~CQDifferentialEquations ()
 
- Public Member Functions inherited from CopasiWidget
 CopasiWidget (QWidget *parent=0, const char *name=0, Qt::WFlags f=0)
 
bool enter (const std::string &key)
 
CCopasiDataModelgetDataModel ()
 
bool getIgnoreUpdates ()
 
virtual bool leave ()
 
virtual void setFramework (int framework)
 
void setIgnoreUpdates (bool v)
 
virtual bool update (ListViews::ObjectType objectType, ListViews::Action action, const std::string &key)
 

Protected Member Functions

virtual bool enterProtected ()
 

Protected Attributes

std::ostringstream mml
 
- Protected Attributes inherited from CopasiWidget
int mFramework
 
bool mIgnoreUpdates
 
std::string mKey
 
CCopasiDataModelmpDataModel
 
ListViewsmpListView
 
CCopasiObjectmpObject
 

Private Member Functions

void init ()
 
virtual void newFunction ()
 
virtual void saveMML (const QString filename)
 
virtual void savePNG (const QString filename)
 
virtual void saveTeX (const QString filename)
 

Additional Inherited Members

- Protected Slots inherited from CopasiWidget
virtual bool protectedNotify (ListViews::ObjectType objectType, ListViews::Action action, const std::string &key="")
 

Detailed Description

Definition at line 29 of file CQDifferentialEquations.h.

Constructor & Destructor Documentation

CQDifferentialEquations::CQDifferentialEquations ( QWidget *  parent = 0,
const char *  name = 0 
)

Definition at line 51 of file CQDifferentialEquations.cpp.

References init().

52  : CopasiWidget(parent, name)
53 {
54  setupUi(this);
55 
56 #ifdef WIN32
57  // on windows there ought to be a border around the MML widget
58  // otherwise it is difficult to distinguish the formula from the rest of the
59  // dialog
60  mpScrollView->setFrameShape(QFrame::Panel);
61  mpScrollView->setFrameStyle(QFrame::Panel | QFrame::Plain);
62 #endif
63 
64  init();
65 }
CopasiWidget(QWidget *parent=0, const char *name=0, Qt::WFlags f=0)
CQDifferentialEquations::~CQDifferentialEquations ( )

Definition at line 70 of file CQDifferentialEquations.cpp.

71 {
72  // no need to delete child widgets, Qt does it all for us
73 }

Member Function Documentation

bool CQDifferentialEquations::enterProtected ( )
protectedvirtual

Reimplemented from CopasiWidget.

Definition at line 144 of file CQDifferentialEquations.cpp.

References slotUpdateWidget().

145 {
147  return true;
148 }
void CQDifferentialEquations::init ( )
private

Definition at line 75 of file CQDifferentialEquations.cpp.

Referenced by CQDifferentialEquations().

76 {
77  comboBoxFunctions->setCurrentIndex(1);
78 }
void CQDifferentialEquations::newFunction ( )
privatevirtual

Definition at line 150 of file CQDifferentialEquations.cpp.

151 {}
void CQDifferentialEquations::saveMML ( const QString  filename)
privatevirtual

Definition at line 80 of file CQDifferentialEquations.cpp.

References CLocaleString::fromUtf8(), mml, and TO_UTF8.

Referenced by slotSave().

81 {
82  std::ofstream ofile;
83  ofile.open(CLocaleString::fromUtf8(TO_UTF8(outfilename)).c_str(), std::ios::trunc);
84 
85  ofile << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << std::endl;
86  ofile << "<!DOCTYPE math PUBLIC \"-//W3C//DTD MathML 2.0//EN\" \"http://www.w3.org/Math/DTD/mathml2/mathml2.dtd\">" << std::endl;
87  ofile << "<math xmlns=\"http://www.w3.org/1998/Math/MathML\">" << std::endl;
88 
89  ofile << mml.str();
90 
91  ofile << "</math>" << std::endl;
92 
93  ofile.close();
94 }
#define TO_UTF8(__x)
Definition: qtUtilities.h:74
static CLocaleString fromUtf8(const std::string &utf8)
void CQDifferentialEquations::savePNG ( const QString  filename)
privatevirtual

Definition at line 169 of file CQDifferentialEquations.cpp.

References FROM_UTF8, and mml.

Referenced by slotSave().

170 {
171  QtMmlDocument doc;
172  doc.setBaseFontPointSize(20);
173  doc.setFontName(QtMmlWidget::NormalFont, qApp->font().family());
174  doc.setContent(FROM_UTF8(mml.str()));
175 
176  const QSize &size = doc.size();
177  QPixmap pixmap(size.width(), size.height());
178  QPainter painter(&pixmap);
179  painter.setRenderHint(QPainter::Antialiasing);
180  painter.setRenderHint(QPainter::SmoothPixmapTransform);
181  painter.setRenderHint(QPainter::HighQualityAntialiasing);
182  painter.fillRect(0, 0, size.width(), size.height(), Qt::white);
183  doc.paint(&painter, QPoint(0, 0));
184  pixmap.save(outfilename, "PNG");
185 }
#define FROM_UTF8(__x)
Definition: qtUtilities.h:73
void CQDifferentialEquations::saveTeX ( const QString  filename)
privatevirtual

Definition at line 153 of file CQDifferentialEquations.cpp.

References CMathMLToTeX::convert(), FROM_UTF8, CLocaleString::fromUtf8(), mml, and TO_UTF8.

Referenced by slotSave().

154 {
155  QString latexStr(FROM_UTF8(mml.str()));
156 
157 #ifdef DEBUG_UI
158  qDebug() << latexStr;
159 #endif
160 
161  CMathMLToTeX::convert(latexStr);
162 
163  std::ofstream ofile;
164  ofile.open(CLocaleString::fromUtf8(TO_UTF8(outfilename)).c_str(), std::ios::trunc);
165  ofile << TO_UTF8(latexStr);
166  ofile.close();
167 }
#define FROM_UTF8(__x)
Definition: qtUtilities.h:73
static void convert(QString &text)
convert to TeX
#define TO_UTF8(__x)
Definition: qtUtilities.h:74
static CLocaleString fromUtf8(const std::string &utf8)
void CQDifferentialEquations::slotSave ( )
virtualslot

Definition at line 187 of file CQDifferentialEquations.cpp.

References C_INT32, checkSelection(), CopasiFileDialog::getSaveFileName(), saveMML(), savePNG(), and saveTeX().

188 {
189  QString outfilename;
190 
191  C_INT32 Answer = QMessageBox::No;
192 
193  while (Answer == QMessageBox::No)
194  {
195  outfilename =
197  "Save File Dialog",
198  "untitled.mml",
199  "MathML (*.mml);;TeX (*.tex);;PNG (*.png)",
200  "Save Formula to Disk", new QString);
201 
202  if (outfilename.isEmpty()) return;
203 
204  // Checks whether the file exists
205  Answer = checkSelection(outfilename);
206 
207  if (Answer == QMessageBox::Cancel)
208  return;
209  }
210 
211 #ifdef DEBUG_UI
212  qDebug() << "outfilename = " << outfilename;
213 #endif
214 
215  QApplication::setOverrideCursor(Qt::WaitCursor);
216 
217  if (outfilename.contains(".tex"))
218  {
219  saveTeX(outfilename);
220  }
221  else if (outfilename.contains(".png"))
222  {
223  savePNG(outfilename);
224  }
225  else
226  {
227  saveMML(outfilename);
228  }
229 
230  QApplication::restoreOverrideCursor();
231 }
#define C_INT32
Definition: copasi.h:90
C_INT32 checkSelection(const QString &file)
virtual void savePNG(const QString filename)
virtual void saveMML(const QString filename)
virtual void saveTeX(const QString filename)
static QString getSaveFileName(QWidget *parent=0, const char *name=0, const QString &startWith=QString::null, const QString &filter=QString::null, const QString &caption=QString::null, QString *pSelectedFilter=NULL, QFileDialog::Options options=0)
void CQDifferentialEquations::slotUpdateWidget ( )
virtualslot

Definition at line 96 of file CQDifferentialEquations.cpp.

References FROM_UTF8, CCopasiRootContainer::getDatamodelList(), mml, and CMMLOutput::writeDifferentialEquations().

Referenced by enterProtected().

97 {
98  bool hasContents = true;
99  //std::ostringstream mml;
100  mml.str("");
101 
102  bool expand, expandAll;
103 
104  switch (comboBoxFunctions->currentIndex())
105  {
106  case 0:
107  expand = false;
108  expandAll = false;
109  break;
110 
111  case 1:
112  expand = true;
113  expandAll = false;
114  break;
115 
116  default:
117  expand = true;
118  expandAll = true;
119  break;
120  };
121 
122  bool parameterAsNumbers = false;
123 
124  if (comboBoxParameters->currentIndex() == 0)
125  parameterAsNumbers = true;
126 
127  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
128  CMMLOutput::writeDifferentialEquations(mml, (*CCopasiRootContainer::getDatamodelList())[0]->getModel(), parameterAsNumbers, expand, expandAll);
129 
130  QWidget* tmp = dynamic_cast<QWidget*>(parent());
131 
132  if (tmp) tmp->setCursor(Qt::WaitCursor);
133 
134  mpMMLWidget->setContent(FROM_UTF8(mml.str()));
135  mpMMLWidget->setBaseFontPointSize(qApp->font().pointSize());
136  mpMMLWidget->setFontName(QtMmlWidget::NormalFont, qApp->font().family());
137  mpMMLWidget->setFixedSize(mpMMLWidget->sizeHint().expandedTo(QSize(0, 0)));
138 
139  if (tmp) tmp->unsetCursor();
140 
141  mpSaveButton->setEnabled(hasContents);
142 }
#define FROM_UTF8(__x)
Definition: qtUtilities.h:73
static CCopasiVector< CCopasiDataModel > * getDatamodelList()
static void writeDifferentialEquations(std::ostream &mml, CModel *model, bool localParameterNumbers, bool expand, bool expandFull)
Definition: CMMLOutput.cpp:279

Member Data Documentation

std::ostringstream CQDifferentialEquations::mml
protected

Definition at line 42 of file CQDifferentialEquations.h.

Referenced by saveMML(), savePNG(), saveTeX(), and slotUpdateWidget().


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