COPASI API  4.16.103
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
Arguments Class Reference

#include <arguments.h>

Collaboration diagram for Arguments:
Collaboration graph
[legend]

Public Member Functions

 Arguments (int argc, char *argv[])
 
const std::string & getFilename () const
 
const std::string & getFileType () const
 
char ** getInitArgs () const
 
const std::string & getOutputDir () const
 
int getOutputToGenerate () const
 
const std::string & getReportFile () const
 
const std::string & getTaskName () const
 
int getTaskToSwitchTo () const
 
bool handleCommandLine () const
 
bool haveFile () const
 
bool haveOutputDir () const
 
bool haveReportFile () const
 
bool haveTaskName () const
 
bool isDisablePlots () const
 
bool isDisableRandomizeStartValues () const
 
bool isDisableStatistic () const
 
bool isGenerateOutput () const
 
bool isHideWindow () const
 
bool isQuitAfterTaskExecution () const
 
bool isRunScheduled () const
 
bool isSaveLayout () const
 
bool isSolutionStatistic () const
 
bool isSwitchToTask () const
 
bool isValid () const
 
std::string prepareModel () const
 

Static Public Member Functions

static CCopasiTaskgetFirstScheduledTask ()
 

Private Member Functions

CCopasiTaskgetTask () const
 
CCopasiTaskgetTaskForName (const std::string &name) const
 
void parseArgs (int arc, char *argv[])
 

Private Attributes

int mArgc
 
char ** mArgv
 
bool mClearTargets
 
bool mDisablePlots
 
bool mDisableRandomizeStartValues
 
bool mDisableStatistic
 
std::string mFilename
 
std::string mFileType
 
int mGenerateOutput
 
bool mHideWindow
 
std::string mOutputDir
 
bool mQuitAfterTaskExecution
 
std::string mReportFile
 
bool mRunScheduled
 
bool mSaveLayout
 
bool mSetSolutionStatistic
 
int mSwitchToTask
 
std::string mTask
 

Detailed Description

Definition at line 13 of file arguments.h.

Constructor & Destructor Documentation

Arguments::Arguments ( int  argc,
char *  argv[] 
)

Definition at line 31 of file arguments.cpp.

References parseArgs().

32  : mFilename("")
33  , mOutputDir("")
34  , mTask("")
35  , mReportFile("")
36  , mFileType("pdf")
37  , mRunScheduled(false)
38  , mSetSolutionStatistic(false)
39  , mDisableStatistic(false)
40  , mDisablePlots(false)
42  , mHideWindow(false)
44  , mClearTargets(false)
45  , mSwitchToTask(-1)
46  , mGenerateOutput(-1)
47  , mArgc(argc)
48  , mArgv(argv)
49 {
50  parseArgs(argc, argv);
51 }
std::string mTask
Definition: arguments.h:84
bool mClearTargets
Definition: arguments.h:106
void parseArgs(int arc, char *argv[])
Definition: arguments.cpp:156
bool mDisableStatistic
Definition: arguments.h:96
std::string mFileType
Definition: arguments.h:88
char ** mArgv
Definition: arguments.h:114
int mSwitchToTask
Definition: arguments.h:108
bool mDisablePlots
Definition: arguments.h:98
std::string mOutputDir
Definition: arguments.h:82
bool mDisableRandomizeStartValues
Definition: arguments.h:100
int mArgc
Definition: arguments.h:112
bool mSetSolutionStatistic
Definition: arguments.h:94
bool mQuitAfterTaskExecution
Definition: arguments.h:104
std::string mFilename
Definition: arguments.h:80
bool mHideWindow
Definition: arguments.h:102
int mGenerateOutput
Definition: arguments.h:110
std::string mReportFile
Definition: arguments.h:86
bool mRunScheduled
Definition: arguments.h:90

Member Function Documentation

const std::string & Arguments::getFilename ( ) const

Definition at line 255 of file arguments.cpp.

References mFilename.

Referenced by prepareModel(), and Worker::Worker().

256 {
257  return mFilename;
258 }
std::string mFilename
Definition: arguments.h:80
const std::string & Arguments::getFileType ( ) const

Definition at line 260 of file arguments.cpp.

References mFileType.

Referenced by Worker::slotNotify().

261 {
262  return mFileType;
263 }
std::string mFileType
Definition: arguments.h:88
CCopasiTask * Arguments::getFirstScheduledTask ( )
static

Definition at line 53 of file arguments.cpp.

References CCopasiRootContainer::getDatamodelList(), CCopasiTask::isScheduled(), and CCopasiVector< T >::size().

Referenced by Worker::finishedLoading(), and getTask().

54 {
55  CCopasiVectorN<CCopasiTask> &taskList = *(*CCopasiRootContainer::getDatamodelList())[0]->getTaskList();
56 
57  for (size_t i = 0; i < taskList.size(); ++i)
58  {
59  CCopasiTask *current = taskList[i];
60 
61  if (current->isScheduled())
62  return current;
63  }
64 
65  return NULL;
66 }
virtual size_t size() const
const bool & isScheduled() const
static CCopasiVector< CCopasiDataModel > * getDatamodelList()
char ** Arguments::getInitArgs ( ) const

Definition at line 247 of file arguments.cpp.

References mArgv, and mFilename.

248 {
249  char ** result = (char**)malloc(sizeof(char*) * 2);
250  result[0] = strdup(mArgv[0]);
251  result[1] = strdup((mFilename + ".view.cps").c_str());
252  return result;
253 }
char ** mArgv
Definition: arguments.h:114
std::string mFilename
Definition: arguments.h:80
const std::string & Arguments::getOutputDir ( ) const

Definition at line 106 of file arguments.cpp.

References mOutputDir.

Referenced by Worker::slotNotify().

107 {
108  return mOutputDir;
109 }
std::string mOutputDir
Definition: arguments.h:82
int Arguments::getOutputToGenerate ( ) const

Definition at line 96 of file arguments.cpp.

References mGenerateOutput.

97 {
98  return mGenerateOutput;
99 }
int mGenerateOutput
Definition: arguments.h:110
const std::string & Arguments::getReportFile ( ) const

Definition at line 151 of file arguments.cpp.

References mReportFile.

152 {
153  return mReportFile;
154 }
std::string mReportFile
Definition: arguments.h:86
CCopasiTask * Arguments::getTask ( ) const
private

Definition at line 83 of file arguments.cpp.

References getFirstScheduledTask(), getTaskForName(), haveTaskName(), and mTask.

Referenced by prepareModel().

84 {
85  if (haveTaskName())
86  return getTaskForName(mTask);
87 
88  return getFirstScheduledTask();
89 }
std::string mTask
Definition: arguments.h:84
static CCopasiTask * getFirstScheduledTask()
Definition: arguments.cpp:53
CCopasiTask * getTaskForName(const std::string &name) const
Definition: arguments.cpp:68
bool haveTaskName() const
Definition: arguments.cpp:275
CCopasiTask * Arguments::getTaskForName ( const std::string &  name) const
private

Definition at line 68 of file arguments.cpp.

References CCopasiRootContainer::getDatamodelList(), CCopasiObject::getObjectName(), and CCopasiVector< T >::size().

Referenced by getTask().

69 {
70  CCopasiVectorN<CCopasiTask> &taskList = *(*CCopasiRootContainer::getDatamodelList())[0]->getTaskList();
71 
72  for (size_t i = 0; i < taskList.size(); ++i)
73  {
74  CCopasiTask *current = taskList[i];
75 
76  if (current->getObjectName() == name)
77  return current;
78  }
79 
80  return NULL;
81 }
const std::string & getObjectName() const
virtual size_t size() const
static CCopasiVector< CCopasiDataModel > * getDatamodelList()
char name[1]
Definition: stdsoap2.h:1342
const std::string & Arguments::getTaskName ( ) const

Definition at line 280 of file arguments.cpp.

References mTask.

281 {
282  return mTask;
283 }
std::string mTask
Definition: arguments.h:84
int Arguments::getTaskToSwitchTo ( ) const

Definition at line 242 of file arguments.cpp.

References mSwitchToTask.

Referenced by Worker::finishedLoading().

243 {
244  return mSwitchToTask;
245 }
int mSwitchToTask
Definition: arguments.h:108
bool Arguments::handleCommandLine ( ) const

Definition at line 116 of file arguments.cpp.

References CCopasiRootContainer::addDatamodel(), CCopasiMessage::getAllMessageText(), CCopasiDataModel::getListOfLayouts(), CCopasiException::getMessage(), CCopasiObject::getObjectName(), haveFile(), haveOutputDir(), CCopasiDataModel::importSBML(), CCopasiRootContainer::init(), CCopasiDataModel::loadModel(), mFilename, mFileType, mOutputDir, mSaveLayout, CQLayoutScene::recreate(), CQLayoutScene::saveToFile(), and CCopasiVector< T >::size().

Referenced by main().

117 {
118  if (!(mSaveLayout && haveFile() && haveOutputDir()))
119  return false;
120 
121  CCopasiRootContainer::init(0, NULL, false);
123 
124  try
125  {
126  if (!model.importSBML(mFilename, NULL))
127  model.loadModel(mFilename, NULL);
128  }
129  catch (CCopasiException &ex)
130  {
131  std::cerr << ex.getMessage().getAllMessageText() << std::endl;
132  return true;
133  }
134 
135  for (size_t i = 0; i < model.getListOfLayouts()->size(); ++i)
136  {
137  CLayout* layout = (*model.getListOfLayouts())[i];
138  CQLayoutScene scene(layout, &model);
139  scene.recreate();
140  scene.saveToFile(mOutputDir + "/" + QFileInfo(mFilename.c_str()).baseName().toStdString() + "_" + layout->getObjectName() + "." + mFileType, mFileType);
141  }
142 
143  return true;
144 }
bool haveOutputDir() const
Definition: arguments.cpp:101
const std::string & getObjectName() const
std::string mFileType
Definition: arguments.h:88
virtual size_t size() const
const CCopasiMessage & getMessage() const
static std::string getAllMessageText(const bool &chronological=true)
bool importSBML(const std::string &fileName, CProcessReport *pImportHandler=NULL, const bool &deleteOldData=true)
std::string mOutputDir
Definition: arguments.h:82
std::string mFilename
Definition: arguments.h:80
bool haveFile() const
Definition: arguments.cpp:265
bool loadModel(std::istream &in, const std::string &pwd, CProcessReport *pProcessReport, const bool &deleteOldData=true)
CListOfLayouts * getListOfLayouts()
static CCopasiDataModel * addDatamodel()
static void init(int argc, char *argv[], const bool &withGui=false)
bool mSaveLayout
Definition: arguments.h:92
bool Arguments::haveFile ( ) const

Definition at line 265 of file arguments.cpp.

References mFilename.

Referenced by handleCommandLine(), and isValid().

266 {
267  return !mFilename.empty();
268 }
std::string mFilename
Definition: arguments.h:80
bool Arguments::haveOutputDir ( ) const

Definition at line 101 of file arguments.cpp.

References mOutputDir.

Referenced by handleCommandLine(), and Worker::slotNotify().

102 {
103  return !mOutputDir.empty();
104 }
std::string mOutputDir
Definition: arguments.h:82
bool Arguments::haveReportFile ( ) const

Definition at line 111 of file arguments.cpp.

References mReportFile.

Referenced by prepareModel().

112 {
113  return !mReportFile.empty();
114 }
std::string mReportFile
Definition: arguments.h:86
bool Arguments::haveTaskName ( ) const

Definition at line 275 of file arguments.cpp.

References mTask.

Referenced by getTask().

276 {
277  return !mTask.empty();
278 }
std::string mTask
Definition: arguments.h:84
bool Arguments::isDisablePlots ( ) const

Definition at line 300 of file arguments.cpp.

References mDisablePlots.

301 {
302  return mDisablePlots;
303 }
bool mDisablePlots
Definition: arguments.h:98
bool Arguments::isDisableRandomizeStartValues ( ) const

Definition at line 295 of file arguments.cpp.

References mDisableRandomizeStartValues.

Referenced by prepareModel().

296 {
298 }
bool mDisableRandomizeStartValues
Definition: arguments.h:100
bool Arguments::isDisableStatistic ( ) const

Definition at line 290 of file arguments.cpp.

References mDisableStatistic.

Referenced by prepareModel().

291 {
292  return mDisableStatistic;
293 }
bool mDisableStatistic
Definition: arguments.h:96
bool Arguments::isGenerateOutput ( ) const

Definition at line 91 of file arguments.cpp.

References mGenerateOutput.

Referenced by prepareModel().

92 {
93  return mGenerateOutput != -1;
94 }
int mGenerateOutput
Definition: arguments.h:110
bool Arguments::isHideWindow ( ) const

Definition at line 305 of file arguments.cpp.

References mHideWindow.

Referenced by Worker::finishedLoading().

306 {
307  return mHideWindow;
308 }
bool mHideWindow
Definition: arguments.h:102
bool Arguments::isQuitAfterTaskExecution ( ) const

Definition at line 310 of file arguments.cpp.

References mQuitAfterTaskExecution.

Referenced by Worker::slotNotify().

311 {
313 }
bool mQuitAfterTaskExecution
Definition: arguments.h:104
bool Arguments::isRunScheduled ( ) const

Definition at line 270 of file arguments.cpp.

References mRunScheduled.

Referenced by Worker::finishedLoading().

271 {
272  return mRunScheduled;
273 }
bool mRunScheduled
Definition: arguments.h:90
bool Arguments::isSaveLayout ( ) const

Definition at line 146 of file arguments.cpp.

References mSaveLayout.

147 {
148  return mSaveLayout;
149 }
bool mSaveLayout
Definition: arguments.h:92
bool Arguments::isSolutionStatistic ( ) const

Definition at line 285 of file arguments.cpp.

References mSetSolutionStatistic.

286 {
287  return mSetSolutionStatistic;
288 }
bool mSetSolutionStatistic
Definition: arguments.h:94
bool Arguments::isSwitchToTask ( ) const

Definition at line 237 of file arguments.cpp.

References mSwitchToTask.

Referenced by Worker::finishedLoading().

238 {
239  return mSwitchToTask != -1;
240 }
int mSwitchToTask
Definition: arguments.h:108
bool Arguments::isValid ( ) const

Definition at line 315 of file arguments.cpp.

References haveFile(), and mFilename.

Referenced by main(), and prepareModel().

316 {
317  if (!haveFile()) return false;
318 
319  if (!QFile(mFilename.c_str()).exists()) return false;
320 
321  return true;
322 }
std::string mFilename
Definition: arguments.h:80
bool haveFile() const
Definition: arguments.cpp:265
void Arguments::parseArgs ( int  arc,
char *  argv[] 
)
private

Definition at line 156 of file arguments.cpp.

References mClearTargets, mDisablePlots, mDisableRandomizeStartValues, mDisableStatistic, mFilename, mFileType, mGenerateOutput, mHideWindow, mOutputDir, mQuitAfterTaskExecution, mReportFile, mRunScheduled, mSaveLayout, mSetSolutionStatistic, mSwitchToTask, and mTask.

Referenced by Arguments().

157 {
158  for (int i = 1; i < argc; ++i)
159  {
160  QString current(argv[i]);
161  QString lower = current.toLower();
162 
163  if (lower == "-r" || lower == "--run-scheduled")
164  {
165  mRunScheduled = true;
166  }
167  else if (lower == "-q" || lower == "--quit-after-task-execution")
168  {
170  }
171  else if (i + 1 < argc && (lower == "--switch-to-task"))
172  {
173  mSwitchToTask = QString(argv[i + 1]).toInt();
174  ++i;
175  }
176  else if (i + 1 < argc && (lower == "--task"))
177  {
178  mTask = argv[i + 1];
179  ++i;
180  }
181  else if (lower == "--set-solution-statistic")
182  {
183  mSetSolutionStatistic = true;
184  }
185  else if (lower == "--disable-calculate-statistic")
186  {
187  mDisableStatistic = true;
188  }
189  else if (lower == "--disable-other-plots")
190  {
191  mDisablePlots = true;
192  }
193  else if (lower == "--hide")
194  {
195  mHideWindow = true;
196  }
197  else if (lower == "--clear-targets")
198  {
199  mClearTargets = true;
200  }
201  else if (lower == "--disable-randomize-startvalues")
202  {
204  }
205  else if (lower == "--save-layout")
206  {
207  mSaveLayout = true;
208  }
209  else if (i + 1 < argc && (lower == "-g" || lower == "--generate-output"))
210  {
211  mGenerateOutput = QString(argv[i + 1]).toInt();
212  ++i;
213  }
214  else if (i + 1 < argc && (lower == "-f" || lower == "--set-report-file"))
215  {
216  mReportFile = argv[i + 1];
217  ++i;
218  }
219  else if (i + 1 < argc && (lower == "-o" || lower == "--set-output-dir"))
220  {
221  mOutputDir = argv[i + 1];
222  ++i;
223  }
224  else if (i + 1 < argc && (lower == "-t" || lower == "--set-file-type"))
225  {
226  mFileType = argv[i + 1];
227  ++i;
228  }
229  else if (QFile(current).exists() && mFilename.empty())
230  {
231  // only if we don't have a file yet, we assume this to be the copasi file
232  mFilename = current.toStdString();
233  }
234  }
235 }
std::string mTask
Definition: arguments.h:84
bool mClearTargets
Definition: arguments.h:106
bool mDisableStatistic
Definition: arguments.h:96
std::string mFileType
Definition: arguments.h:88
int mSwitchToTask
Definition: arguments.h:108
bool mDisablePlots
Definition: arguments.h:98
std::string mOutputDir
Definition: arguments.h:82
bool mDisableRandomizeStartValues
Definition: arguments.h:100
bool mSetSolutionStatistic
Definition: arguments.h:94
bool mQuitAfterTaskExecution
Definition: arguments.h:104
std::string mFilename
Definition: arguments.h:80
bool mHideWindow
Definition: arguments.h:102
int mGenerateOutput
Definition: arguments.h:110
std::string mReportFile
Definition: arguments.h:86
bool mSaveLayout
Definition: arguments.h:92
bool mRunScheduled
Definition: arguments.h:90
std::string Arguments::prepareModel ( ) const

Definition at line 324 of file arguments.cpp.

References COutputAssistant::createDefaultOutput(), CCopasiRootContainer::getDatamodelList(), getFilename(), COutputAssistant::getListOfDefaultOutputDescriptions(), CCopasiDataModel::getPlotDefinitionList(), CCopasiTask::getProblem(), CCopasiTask::getReport(), getTask(), CCopasiDataModel::getTaskList(), haveReportFile(), isDisableRandomizeStartValues(), isDisableStatistic(), isGenerateOutput(), isValid(), CCopasiDataModel::loadModel(), mClearTargets, mDisablePlots, mGenerateOutput, mReportFile, mSetSolutionStatistic, CCopasiDataModel::saveModel(), COptProblem::setCalculateStatistics(), COptTask::setMethodType(), COptProblem::setRandomizeStartValues(), CReport::setTarget(), CCopasiVector< T >::size(), and CCopasiMethod::Statistics.

Referenced by main().

325 {
326  if (!isValid()) return "";
327 
329  model->loadModel(getFilename(), NULL);
330 
331  if (mDisablePlots)
332  {
333  for (size_t index = 0; index < model->getPlotDefinitionList()->size(); ++index)
334  {
335  (*model->getPlotDefinitionList())[index]->setActive(false);
336  }
337  }
338 
339  if (mClearTargets)
340  {
341  for (size_t index = 0; index < model->getTaskList()->size(); ++index)
342  {
343  (*model->getTaskList())[index]->getReport().setTarget("");
344  }
345  }
346 
347  CCopasiTask *task = getTask();
348 
349  if (task != NULL)
350  {
351  if (isGenerateOutput())
352  {
353  // calls initialize which is private
355 
356  // generate the output
358  }
359 
360  if (haveReportFile())
362 
363  COptTask* optTask = dynamic_cast<COptTask*>(task);
364 
365  if (optTask != NULL)
366  {
367  COptProblem *problem = (COptProblem *)optTask->getProblem();
368 
371 
373  problem->setRandomizeStartValues(false);
374 
375  if (isDisableStatistic())
376  problem->setCalculateStatistics(false);
377  }
378  }
379 
380  model->saveModel(getFilename() + ".view.cps", NULL, true);
381  return getFilename() + ".view.cps";
382 }
bool mClearTargets
Definition: arguments.h:106
CCopasiTask * getTask() const
Definition: arguments.cpp:83
CCopasiProblem * getProblem()
virtual size_t size() const
bool isGenerateOutput() const
Definition: arguments.cpp:91
bool isDisableStatistic() const
Definition: arguments.cpp:290
static CCopasiObject * createDefaultOutput(C_INT32 id, CCopasiTask *task, CCopasiDataModel *pDataModel, bool activate=true)
bool mDisablePlots
Definition: arguments.h:98
static std::vector< C_INT32 > getListOfDefaultOutputDescriptions(const CCopasiTask *task=NULL)
bool haveReportFile() const
Definition: arguments.cpp:111
bool mSetSolutionStatistic
Definition: arguments.h:94
const std::string & getFilename() const
Definition: arguments.cpp:255
CCopasiVectorN< CCopasiTask > * getTaskList()
static CCopasiVector< CCopasiDataModel > * getDatamodelList()
bool loadModel(std::istream &in, const std::string &pwd, CProcessReport *pProcessReport, const bool &deleteOldData=true)
bool saveModel(const std::string &fileName, CProcessReport *pProcessReport, bool overwriteFile=false, const bool &autoSave=false)
virtual bool setMethodType(const int &type)
Definition: COptTask.cpp:156
void setTarget(const std::string &target)
Definition: CReport.cpp:92
void setRandomizeStartValues(const bool &randomize)
const COutputDefinitionVector * getPlotDefinitionList() const
CReport & getReport()
int mGenerateOutput
Definition: arguments.h:110
bool isValid() const
Definition: arguments.cpp:315
bool isDisableRandomizeStartValues() const
Definition: arguments.cpp:295
std::string mReportFile
Definition: arguments.h:86
void setCalculateStatistics(const bool &calculate)

Member Data Documentation

int Arguments::mArgc
private

Definition at line 112 of file arguments.h.

char** Arguments::mArgv
private

Definition at line 114 of file arguments.h.

Referenced by getInitArgs().

bool Arguments::mClearTargets
private

Definition at line 106 of file arguments.h.

Referenced by parseArgs(), and prepareModel().

bool Arguments::mDisablePlots
private

Definition at line 98 of file arguments.h.

Referenced by isDisablePlots(), parseArgs(), and prepareModel().

bool Arguments::mDisableRandomizeStartValues
private

Definition at line 100 of file arguments.h.

Referenced by isDisableRandomizeStartValues(), and parseArgs().

bool Arguments::mDisableStatistic
private

Definition at line 96 of file arguments.h.

Referenced by isDisableStatistic(), and parseArgs().

std::string Arguments::mFilename
private

Definition at line 80 of file arguments.h.

Referenced by getFilename(), getInitArgs(), handleCommandLine(), haveFile(), isValid(), and parseArgs().

std::string Arguments::mFileType
private

Definition at line 88 of file arguments.h.

Referenced by getFileType(), handleCommandLine(), and parseArgs().

int Arguments::mGenerateOutput
private

Definition at line 110 of file arguments.h.

Referenced by getOutputToGenerate(), isGenerateOutput(), parseArgs(), and prepareModel().

bool Arguments::mHideWindow
private

Definition at line 102 of file arguments.h.

Referenced by isHideWindow(), and parseArgs().

std::string Arguments::mOutputDir
private

Definition at line 82 of file arguments.h.

Referenced by getOutputDir(), handleCommandLine(), haveOutputDir(), and parseArgs().

bool Arguments::mQuitAfterTaskExecution
private

Definition at line 104 of file arguments.h.

Referenced by isQuitAfterTaskExecution(), and parseArgs().

std::string Arguments::mReportFile
private

Definition at line 86 of file arguments.h.

Referenced by getReportFile(), haveReportFile(), parseArgs(), and prepareModel().

bool Arguments::mRunScheduled
private

Definition at line 90 of file arguments.h.

Referenced by isRunScheduled(), and parseArgs().

bool Arguments::mSaveLayout
private

Definition at line 92 of file arguments.h.

Referenced by handleCommandLine(), isSaveLayout(), and parseArgs().

bool Arguments::mSetSolutionStatistic
private

Definition at line 94 of file arguments.h.

Referenced by isSolutionStatistic(), parseArgs(), and prepareModel().

int Arguments::mSwitchToTask
private

Definition at line 108 of file arguments.h.

Referenced by getTaskToSwitchTo(), isSwitchToTask(), and parseArgs().

std::string Arguments::mTask
private

Definition at line 84 of file arguments.h.

Referenced by getTask(), getTaskName(), haveTaskName(), and parseArgs().


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