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

A widget class for Functions branch. More...

#include <FunctionWidget1.h>

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

Public Member Functions

 FunctionWidget1 (QWidget *parent, const char *name=0, Qt::WFlags f=0)
 
virtual bool leave ()
 
virtual bool update (ListViews::ObjectType objectType, ListViews::Action action, const std::string &key)
 Function to update the COPASI widgets. More...
 
virtual ~FunctionWidget1 ()
 Destructor. More...
 
- 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 void setFramework (int framework)
 
void setIgnoreUpdates (bool v)
 

Protected Slots

void slotBtnCopy ()
 
void slotBtnDelete ()
 Slot for being activated whenever Delete button is clicked. More...
 
void slotBtnNew ()
 Slot for being activated wehenver New button is clicked. More...
 
virtual void slotFcnDescriptionChanged (bool)
 Slot for changing the function description. More...
 
virtual void slotReversibilityChanged ()
 Slot for changing the reversibility of the function. More...
 
void slotTableValueChanged (const QString &)
 Slot for changing the table value. More...
 
- Protected Slots inherited from CopasiWidget
virtual bool protectedNotify (ListViews::ObjectType objectType, ListViews::Action action, const std::string &key="")
 

Protected Member Functions

bool copyFunctionContentsToFunction (const CFunction *src, CFunction *target)
 
virtual bool enterProtected ()
 
bool functionParametersChanged ()
 
bool loadFromFunction (const CFunction *=NULL)
 
bool loadParameterTable ()
 
bool loadReversibility (TriLogic rev)
 
bool loadUsageTable ()
 Function to generate the text representation of the usage restrictions. More...
 
bool saveToFunction ()
 
void updateApplication ()
 

Protected Attributes

bool flagChanged
 
bool isValid
 
bool mIgnoreFcnDescriptionChange
 
CFunctionmpFunction
 
- Protected Attributes inherited from CopasiWidget
int mFramework
 
bool mIgnoreUpdates
 
std::string mKey
 
CCopasiDataModelmpDataModel
 
ListViewsmpListView
 
CCopasiObjectmpObject
 

Private Member Functions

void init ()
 

Private Attributes

std::string mKeyToCopy
 
bool mReadOnly
 

Detailed Description

A widget class for Functions branch.

This widget shows detailed description of an individual function

Definition at line 29 of file FunctionWidget1.h.

Constructor & Destructor Documentation

FunctionWidget1::FunctionWidget1 ( QWidget *  parent,
const char *  name = 0,
Qt::WFlags  f = 0 
)

Definition at line 49 of file FunctionWidget1.cpp.

References init().

49  :
50  CopasiWidget(parent, name, fl),
51  flagChanged(false),
52  isValid(false),
54  mpFunction(NULL),
55  mKeyToCopy("")
56 {
57  setupUi(this);
58 
59  init();
60 }
bool mIgnoreFcnDescriptionChange
CFunction * mpFunction
CopasiWidget(QWidget *parent=0, const char *name=0, Qt::WFlags f=0)
bool fl(const C_FLOAT64 &d1, const C_FLOAT64 &d2)
std::string mKeyToCopy
FunctionWidget1::~FunctionWidget1 ( )
virtual

Destructor.

Definition at line 63 of file FunctionWidget1.cpp.

References mpFunction, and pdelete.

64 {
65  //pdelete(mMmlWidget);
66  //pdelete(mScrollView);
68 }
#define pdelete(p)
Definition: copasi.h:215
CFunction * mpFunction

Member Function Documentation

bool FunctionWidget1::copyFunctionContentsToFunction ( const CFunction src,
CFunction target 
)
protected

Definition at line 447 of file FunctionWidget1.cpp.

References CFunctionParameters::add(), C_INVALID_INDEX, CFunctionParameters::findParameterByName(), CEvaluationTree::getInfix(), CCopasiObject::getObjectName(), CFunction::getVariables(), CFunctionParameters::remove(), CFunction::setInfix(), and CFunctionParameters::size().

Referenced by saveToFunction().

448 {
449  //Parameters
450  CFunctionParameters &functParam = target->getVariables();
451  const CFunctionParameters &pfunctParam = src->getVariables();
453  size_t index;
454  size_t i, j;
455 
456  if (src->getInfix() != target->getInfix())
457  target->setInfix(src->getInfix());
458 
459  for (i = 0; i < pfunctParam.size(); i++)
460  {
461  // check if function parameter exists in pFunctionParameter
462  if ((index = functParam.findParameterByName(pfunctParam[i]->getObjectName(),
463  Type)) != C_INVALID_INDEX)
464  // match found
465  {
466  if (functParam[index]->getUsage() != pfunctParam[i]->getUsage())
467  {
468  //changed = true;
469  // update usage
470  functParam[index]->setUsage(pfunctParam[i]->getUsage());
471  //functParam[pfunctParam[i]->getObjectName()]->setUsage(functParam[i]->getUsage());
472  }
473 
474  if (functParam[index]->getType() != pfunctParam[i]->getType())
475  {
476  //changed = true;
477  // update type
478  functParam[index]->setType(pfunctParam[i]->getType());
479  }
480  }
481  else
482  {
483  // match not found
484  //changed = true;
485  functParam.add(*pfunctParam[i]);
486  }
487  }
488 
489  // remove extra parameters existing in functParam, compare functParam to pfunctParam
490  if (pfunctParam.size() != functParam.size())
491  {
492  for (j = 0; j < functParam.size(); j++)
493  {
494  if ((index = pfunctParam.findParameterByName(functParam[j]->getObjectName(),
495  Type)) == C_INVALID_INDEX)
496  // the lines below occurs if new functionParameter does not exist in pfunctParam
497  {
498  //changed = true;
499  // remove the extra parameter in functParam
500  functParam.remove(functParam[j]->getObjectName());
501  }
502  }
503  } //TODO: this is probably much too complicated
504 
505  return true;
506 }
const std::string & getObjectName() const
size_t findParameterByName(const std::string &name, CFunctionParameter::DataType &dataType) const
#define C_INVALID_INDEX
Definition: copasi.h:222
virtual bool setInfix(const std::string &infix)
Definition: CFunction.cpp:73
void add(const CFunctionParameter &parameter)
void remove(const std::string &name)
const std::string & getInfix() const
CFunctionParameters & getVariables()
Definition: CFunction.cpp:148
bool FunctionWidget1::enterProtected ( )
protectedvirtual

Reimplemented from CopasiWidget.

Definition at line 922 of file FunctionWidget1.cpp.

References CKeyFactory::get(), CCopasiRootContainer::getKeyFactory(), loadFromFunction(), mKeyToCopy, CopasiWidget::mpListView, CopasiWidget::mpObject, and ListViews::switchToOtherWidget().

923 {
924  CFunction * func = NULL;
925 
926  if (mKeyToCopy != "")
927  {
928  func = dynamic_cast<CFunction*>(CCopasiRootContainer::getKeyFactory()->get(mKeyToCopy));
929  mKeyToCopy = "";
930  }
931  else
932  {
933  func = dynamic_cast<CFunction*>(mpObject);
934  }
935 
936  if (func)
937  return loadFromFunction(func);
938 
940  return false;
941 }
void switchToOtherWidget(const size_t &id, const std::string &key)
Definition: listviews.cpp:926
CCopasiObject * get(const std::string &key)
CCopasiObject * mpObject
Definition: copasiWidget.h:64
ListViews * mpListView
Definition: copasiWidget.h:62
static CKeyFactory * getKeyFactory()
The class for handling a chemical kinetic function.
Definition: CFunction.h:29
bool loadFromFunction(const CFunction *=NULL)
std::string mKeyToCopy
bool FunctionWidget1::functionParametersChanged ( )
protected

Definition at line 508 of file FunctionWidget1.cpp.

References CKeyFactory::get(), CCopasiRootContainer::getKeyFactory(), CFunction::getVariables(), CopasiWidget::mKey, and mpFunction.

Referenced by leave().

509 {
510  CFunction* func = dynamic_cast<CFunction*>(CCopasiRootContainer::getKeyFactory()->get(mKey));
511 
512  if (!func) return false;
513 
514  return (!(func->getVariables() == mpFunction->getVariables()));
515 }
CCopasiObject * get(const std::string &key)
CFunction * mpFunction
static CKeyFactory * getKeyFactory()
The class for handling a chemical kinetic function.
Definition: CFunction.h:29
std::string mKey
Definition: copasiWidget.h:63
CFunctionParameters & getVariables()
Definition: CFunction.cpp:148
void FunctionWidget1::init ( )
private

Definition at line 70 of file FunctionWidget1.cpp.

References mpFunction, and slotFcnDescriptionChanged().

Referenced by FunctionWidget1().

71 {
72  // change the default signal-slot connection
73  // disconnect(mpExpressionEMSW->mpExpressionWidget,
74  // SIGNAL(textChanged()),
75  // mpExpressionEMSW->mpExpressionWidget,
76  // SLOT(slotTextChanged()));
77  mpExpressionEMSW->mpExpressionWidget->setFunction("");
78  connect(mpExpressionEMSW->mpExpressionWidget->getValidator(), SIGNAL(stateChanged(bool)), this, SLOT(slotFcnDescriptionChanged(bool)));
79 
80  // hide all unnecessary buttons
81  mpExpressionEMSW->mpBtnExpressionObject->hide();
82  // mpExpressionEMSW->mpBtnViewExpression->hide();
83 
84  // overwrite the tip
85  mpExpressionEMSW->mpBtnSaveExpression->setToolTip(tr("save formula"));
86  mpExpressionEMSW->mpBtnEditExpression->setToolTip(tr("edit formula"));
87 
88  mpFunction = NULL;
89 }
virtual void slotFcnDescriptionChanged(bool)
Slot for changing the function description.
CFunction * mpFunction
bool FunctionWidget1::leave ( )
virtual

Reimplemented from CopasiWidget.

Definition at line 753 of file FunctionWidget1.cpp.

References CFunctionDB::appendDependentFunctions(), CModel::appendDependentModelObjects(), FROM_UTF8, functionParametersChanged(), CKeyFactory::get(), CCopasiRootContainer::getDatamodelList(), CEvaluationTree::getDeletedObjects(), CCopasiRootContainer::getFunctionList(), CCopasiRootContainer::getKeyFactory(), CCopasiObject::getObjectName(), CQMessageBox::information(), isValid, CopasiWidget::mKey, and saveToFunction().

754 {
755  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
756  CModel * pModel = (*CCopasiRootContainer::getDatamodelList())[0]->getModel();
757 
758  if (pModel == NULL)
759  return true;
760 
761  // :TODO: We should check what changes have been done to the function //
763 
764  if (pFunctionDB == NULL)
765  return true;
766 
768 
769  if (pFunction == NULL)
770  return true;
771 
772  bool Used = false;
773 
775  {
776  QString msg =
777  QString("Cannot modify function: \n %1\n").arg(FROM_UTF8(pFunction->getObjectName()));
778 
779  std::set< const CCopasiObject * > Functions;
780  std::set< const CCopasiObject * > Reactions;
781  std::set< const CCopasiObject * > Metabolites;
782  std::set< const CCopasiObject * > Values;
783  std::set< const CCopasiObject * > Compartments;
784  std::set< const CCopasiObject * > Events;
785 
786  std::set< const CCopasiObject * > DeletedObjects = pFunction->getDeletedObjects();
787 
788  Used |= pFunctionDB->appendDependentFunctions(DeletedObjects, Functions);
789 
790  if (Functions.size() > 0)
791  {
792  msg.append("Following functions(s) reference above:\n ");
793 
794  std::set< const CCopasiObject * >::const_iterator it = Functions.begin();
795  std::set< const CCopasiObject * >::const_iterator end = Functions.end();
796 
797  for (; it != end; ++it)
798  {
799  msg.append(FROM_UTF8((*it)->getObjectName()));
800  msg.append("\n ");
801  }
802 
803  msg.remove(msg.length() - 2, 2);
804  }
805 
806  Used |= pModel->appendDependentModelObjects(DeletedObjects, Reactions, Metabolites,
807  Compartments, Values, Events);
808 
809  if (Reactions.size() > 0)
810  {
811  msg.append("Following reactions(s) reference above:\n ");
812 
813  std::set< const CCopasiObject * >::const_iterator it = Reactions.begin();
814  std::set< const CCopasiObject * >::const_iterator end = Reactions.end();
815 
816  for (; it != end; ++it)
817  {
818  msg.append(FROM_UTF8((*it)->getObjectName()));
819  msg.append("\n ");
820  }
821 
822  msg.remove(msg.length() - 2, 2);
823  }
824 
825  if (Metabolites.size() > 0)
826  {
827  msg.append("Following species reference above:\n ");
828 
829  std::set< const CCopasiObject * >::const_iterator it = Metabolites.begin();
830  std::set< const CCopasiObject * >::const_iterator end = Metabolites.end();
831 
832  for (; it != end; ++it)
833  {
834  msg.append(FROM_UTF8((*it)->getObjectName()));
835  msg.append("\n ");
836  }
837 
838  msg.remove(msg.length() - 2, 2);
839  }
840 
841  if (Values.size() > 0)
842  {
843  msg.append("Following global quantities reference above:\n ");
844 
845  std::set< const CCopasiObject * >::const_iterator it = Values.begin();
846  std::set< const CCopasiObject * >::const_iterator end = Values.end();
847 
848  for (; it != end; ++it)
849  {
850  msg.append(FROM_UTF8((*it)->getObjectName()));
851  msg.append("\n ");
852  }
853 
854  msg.remove(msg.length() - 2, 2);
855  }
856 
857  if (Compartments.size() > 0)
858  {
859  msg.append("Following compartment(s) reference above:\n ");
860 
861  std::set< const CCopasiObject * >::const_iterator it = Compartments.begin();
862  std::set< const CCopasiObject * >::const_iterator end = Compartments.end();
863 
864  for (; it != end; ++it)
865  {
866  msg.append(FROM_UTF8((*it)->getObjectName()));
867  msg.append("\n ");
868  }
869 
870  msg.remove(msg.length() - 2, 2);
871  }
872 
873  if (Events.size() > 0)
874  {
875  msg.append("Following event(s) reference above:\n ");
876 
877  std::set< const CCopasiObject * >::const_iterator it = Events.begin();
878  std::set< const CCopasiObject * >::const_iterator end = Events.end();
879 
880  for (; it != end; ++it)
881  {
882  msg.append(FROM_UTF8((*it)->getObjectName()));
883  msg.append("\n ");
884  }
885 
886  msg.remove(msg.length() - 2, 2);
887  }
888 
889  if (Used)
890  {
891  CQMessageBox::information(this, "Modification not possible",
892  msg, QMessageBox::Ok, QMessageBox::Ok);
893 
894  return true;
895  }
896  }
897 
898  if (isValid)
899  {
900  saveToFunction();
901  mpExpressionEMSW->updateWidget();
902  }
903 
904  //update pFunction values
905 
906  /* Remove line breaks from the function description */
907  /*std::string desc = TO_UTF8(textBrowser->text());
908  unsigned int loc = 0;
909  while (1)
910  {
911  loc = desc.find('\n', loc);
912  if (loc == std::string::npos)
913  break;
914  desc.erase(loc, 1);
915  }
916  textBrowser->setText(FROM_UTF8(desc));*/
917 
918  //mScrollView->hide();
919  return true;
920 }
#define FROM_UTF8(__x)
Definition: qtUtilities.h:73
const std::string & getObjectName() const
CCopasiObject * get(const std::string &key)
static StandardButton information(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons=Ok, StandardButton defaultButton=NoButton)
bool functionParametersChanged()
bool appendDependentModelObjects(const std::set< const CCopasiObject * > &candidates, std::set< const CCopasiObject * > &dependentReactions, std::set< const CCopasiObject * > &dependentMetabolites, std::set< const CCopasiObject * > &dependentCompartments, std::set< const CCopasiObject * > &dependentModelValues, std::set< const CCopasiObject * > &dependentEvents) const
Definition: CModel.cpp:2364
static CCopasiVector< CCopasiDataModel > * getDatamodelList()
bool appendDependentFunctions(std::set< const CCopasiObject * > candidates, std::set< const CCopasiObject * > &dependentFunctions) const
CCopasiObject::DataObjectSet getDeletedObjects() const
static CFunctionDB * getFunctionList()
static CKeyFactory * getKeyFactory()
Definition: CModel.h:50
std::string mKey
Definition: copasiWidget.h:63
bool FunctionWidget1::loadFromFunction ( const CFunction func = NULL)
protected

Definition at line 375 of file FunctionWidget1.cpp.

References CEvaluationTree::copy(), flagChanged, CEvaluationTree::getInfix(), CEvaluationTree::getType(), CFunction::isReversible(), CEvaluationTree::isUsable(), isValid, loadParameterTable(), loadReversibility(), loadUsageTable(), CEvaluationTree::MassAction, mIgnoreFcnDescriptionChange, mpFunction, mReadOnly, pdelete, and CEvaluationTree::PreDefined.

Referenced by enterProtected(), and update().

376 {
377  if (func != NULL)
378  {
380  mpFunction = dynamic_cast<CFunction *>(CEvaluationTree::copy(*func));
381  flagChanged = false;
382  }
383 
384  if (mpFunction == NULL)
385  return false;
386 
387  // function name
388  /* Insert line breaks in the function description */
389  std::string desc = mpFunction->getInfix();
390  size_t l = 0;
391  size_t n = 0;
392  size_t len = desc.length();
393 
394  while (len - l > 65)
395  {
396  n = l;
397  l = l + 65;
398 
399  while (l > n)
400  {
401  char ch = desc.at(l);
402 
403  if ((ch == '+') || (ch == '-') || (ch == '*') || (ch == '/') || (ch == ',') || (ch == ' '))
404  break;
405 
406  l--;
407  }
408 
409  // We did not find a suitable place to break the line
410  if (l == n) l += 65;
411 
412  desc.insert(l, 1, '\n');
413  }
414 
417 
418  RadioButton1->setEnabled(!mReadOnly);
419  RadioButton2->setEnabled(!mReadOnly);
420  RadioButton3->setEnabled(!mReadOnly);
421 
422  mpExpressionEMSW->setReadOnly(mReadOnly);
423 
424  // formula expression
426  mpExpressionEMSW->mpExpressionWidget->setFunction(mpFunction->getInfix());
428 
429  mpExpressionEMSW->updateWidget();
430 
431  //radio buttons
433 
434  //parameter table
436 
437  // application table
438  loadUsageTable(/*pFunction->getVariables().getUsageRanges()*/);
439 
441 
442  flagChanged = false;
443 
444  return true;
445 }
bool mIgnoreFcnDescriptionChange
#define pdelete(p)
Definition: copasi.h:215
bool loadReversibility(TriLogic rev)
const CEvaluationTree::Type & getType() const
CFunction * mpFunction
const TriLogic & isReversible() const
Definition: CFunction.cpp:145
static CEvaluationTree * copy(const CEvaluationTree &src)
bool isUsable() const
The class for handling a chemical kinetic function.
Definition: CFunction.h:29
const std::string & getInfix() const
bool loadUsageTable()
Function to generate the text representation of the usage restrictions.
bool FunctionWidget1::loadParameterTable ( )
protected

Definition at line 91 of file FunctionWidget1.cpp.

References COL_NAME, COL_UNIT, COL_USAGE, CFunctionParameter::DataTypeName, CModel::dimensionlessArea, CModel::dimensionlessLength, CModel::dimensionlessQuantity, CModel::dimensionlessTime, CModel::dimensionlessVolume, FROM_UTF8, CModel::getAreaUnitEnum(), CCopasiRootContainer::getDatamodelList(), CModel::getLengthUnitEnum(), CCopasiDataModel::getModel(), CModel::getQuantityUnitEnum(), CModel::getTimeUnitEnum(), CFunction::getVariables(), CModel::getVolumeUnitEnum(), CFunctionParameter::MODIFIER, mpFunction, mReadOnly, CFunctionParameter::PARAMETER, CFunctionParameter::PRODUCT, CFunctionParameter::RoleNameDisplay, CFindDimensions::setUseHeuristics(), CFunctionParameters::size(), slotTableValueChanged(), CFunctionParameter::SUBSTRATE, CFunctionParameter::TIME, CFunctionParameter::VARIABLE, and CFunctionParameter::VOLUME.

Referenced by loadFromFunction(), slotFcnDescriptionChanged(), and slotTableValueChanged().

92 {
93  QColor subsColor(255, 210, 210);
94  QColor prodColor(210, 255, 210);
95  QColor modiColor(250, 250, 190);
96  QColor paraColor(210, 210, 255);
97  QColor volColor(210, 210, 255);
98  QColor timeColor(210, 210, 210);
99  QColor color;
100 
101  size_t i, j;
103 
104  // list of usages for combobox
105  QStringList Usages;
106 
107  for (i = 0; CFunctionParameter::RoleNameDisplay[i] != ""; i++)
108  {
109  if (dynamic_cast<CKinFunction *>(mpFunction) &&
111 
113  }
114 
115  //create list of data types (for combobox)
116  QStringList functionType;
117 
118  for (i = 0; CFunctionParameter::DataTypeName[i] != ""; i++)
119  functionType += (FROM_UTF8(CFunctionParameter::DataTypeName[i]));
120 
121  //find parameter units
122  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
124  assert(pDataModel != NULL);
125  CModel * pModel = pDataModel->getModel();
126  assert(pModel != NULL);
127 
133  );
134 
135  ddd.setUseHeuristics(true);
136  std::vector<std::string> units = ddd.findDimensionsBoth(pModel);
137 
139  QString qUsage;
140 
141  //C_INT32 noOffunctParams = functParam.size();
142  Table1->setRowCount((int) params.size());
143 
144  for (j = 0; j < params.size(); j++)
145  {
146  usage = params[j]->getUsage();
147 
148  if (usage == CFunctionParameter::VARIABLE &&
149  dynamic_cast<CKinFunction *>(mpFunction))
150  {
152  params[j]->setUsage(usage);
153  }
154 
156 
157  switch (usage)
158  {
160  color = subsColor;
161  break;
162 
164  color = prodColor;
165  break;
166 
168  color = modiColor;
169  break;
170 
172  color = paraColor;
173  break;
174 
176  color = volColor;
177  break;
178 
180  color = timeColor;
181  break;
182 
184  color = QColor(250, 250, 250);
185  break;
186 
187  default :
188  qUsage = "unknown";
189  color = QColor(255, 20, 20);
190  break;
191  }
192 
193  // col. 0 (name)
194  QString Name = FROM_UTF8(params[j]->getObjectName());
195 
196  if (!params[j]->isUsed())
197  Name += " (unused)";
198 
199  if (Table1->item((int) j, COL_NAME) == NULL)
200  {
201  QTableWidgetItem *newItem = new QTableWidgetItem(Name);
202  newItem->setFlags(Qt::ItemIsDragEnabled | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
203  Table1->setItem((int) j, COL_NAME, newItem);
204  }
205  else
206  Table1->item((int) j, COL_NAME)->setText(Name);
207 
208  Table1->item((int) j, COL_NAME)->setBackground(QBrush(color));
209 
210  // col. 1 (description)
211  QTableWidgetItem *newItem2 = new QTableWidgetItem();
212  newItem2->setFlags(Qt::ItemIsDragEnabled | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
213  Table1->setItem((int) j, COL_USAGE, newItem2);
214  Table1->item((int) j, COL_USAGE)->setBackground(QBrush(color));
215 
216  QComboBox *comboItem = new QComboBox(Table1);
217  comboItem->addItems(Usages);
218  comboItem->setCurrentIndex(comboItem->findText(qUsage));
219  comboItem->setDisabled(mReadOnly);
220 
221  Table1->setCellWidget((int) j, COL_USAGE, comboItem);
222 
223  // connection between comboItem and its parent, Table1
224  connect(comboItem, SIGNAL(activated(const QString &)), this, SLOT(slotTableValueChanged(const QString &)));
225  comboItem->setObjectName(QString::number(j)); // just need to save the row index
226 
227  //col. 2 (units)
228  QString strUnit = FROM_UTF8(units[j]);
229 
230  if (Table1->item((int) j, COL_UNIT) == NULL)
231  {
232  QTableWidgetItem *newItem = new QTableWidgetItem(strUnit);
233  newItem->setFlags(Qt::ItemIsDragEnabled | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
234  Table1->setItem((int) j, COL_UNIT, newItem);
235  }
236  else
237  Table1->item((int) j, COL_UNIT)->setText(strUnit);
238 
239  Table1->item((int) j, COL_UNIT)->setBackground(QBrush(color));
240  }
241 
242  Table1->horizontalHeader()->setStretchLastSection(true);
243  Table1->resizeColumnsToContents();
244  Table1->resizeRowsToContents();
245 
246  /*
247  Table1->setFixedSize(Table1->horizontalHeader()->length() + 10,
248  Table1->verticalHeader()->length() + 30);
249  */
250 
251  return true;
252 }
#define COL_USAGE
CModel::AreaUnit getAreaUnitEnum() const
Definition: CModel.cpp:2198
static const std::string DataTypeName[]
#define FROM_UTF8(__x)
Definition: qtUtilities.h:73
CModel::QuantityUnit getQuantityUnitEnum() const
Definition: CModel.cpp:2331
void setUseHeuristics(bool flag)
Definition: CDimension.cpp:330
CFunction * mpFunction
static CCopasiVector< CCopasiDataModel > * getDatamodelList()
CModel::LengthUnit getLengthUnitEnum() const
Definition: CModel.cpp:2220
#define COL_NAME
CModel::TimeUnit getTimeUnitEnum() const
Definition: CModel.cpp:2243
void slotTableValueChanged(const QString &)
Slot for changing the table value.
static const std::string RoleNameDisplay[]
Definition: CModel.h:50
CModel::VolumeUnit getVolumeUnitEnum() const
Definition: CModel.cpp:2175
#define COL_UNIT
CFunctionParameters & getVariables()
Definition: CFunction.cpp:148
bool FunctionWidget1::loadReversibility ( TriLogic  rev)
protected

Definition at line 352 of file FunctionWidget1.cpp.

References TriFalse, TriTrue, and TriUnspecified.

Referenced by loadFromFunction().

353 {
354  switch (rev)
355  {
356  case TriUnspecified:
357  RadioButton3->setEnabled(true);
358  RadioButton3->setChecked(true);
359  break;
360 
361  case TriFalse:
362  RadioButton2->setEnabled(true);
363  RadioButton2->setChecked(true);
364  break;
365 
366  case TriTrue:
367  RadioButton1->setEnabled(true);
368  RadioButton1->setChecked(true);
369  break;
370  }
371 
372  return true;
373 }
bool FunctionWidget1::loadUsageTable ( )
protected

Function to generate the text representation of the usage restrictions.

Definition at line 255 of file FunctionWidget1.cpp.

References FROM_UTF8, CFunctionParameters::getNumberOfParametersByUsage(), CCopasiObject::getObjectName(), CFunction::getVariables(), CFunctionParameters::isVector(), mpFunction, CFunctionParameter::PRODUCT, and CFunctionParameter::SUBSTRATE.

Referenced by loadFromFunction(), slotFcnDescriptionChanged(), slotReversibilityChanged(), and slotTableValueChanged().

256 {
257  std::vector<std::string> stringlist;
258  bool checkSubstrates = false;
259  bool checkProducts = false;
260 
261  if (RadioButton1->isChecked() == true)
262  {
263  stringlist.push_back("Only reversible reactions");
264  checkSubstrates = true;
265  checkProducts = true;
266  }
267  else if (RadioButton2->isChecked() == true)
268  {
269  stringlist.push_back("Only irreversible reactions");
270  checkSubstrates = true;
271  }
272 
273  //substrates
274  if (checkSubstrates)
275  {
277  {
278  stringlist.push_back("At least one substrate");
279  }
280  else if (mpFunction->getObjectName() != "Constant flux (irreversible)" &&
281  mpFunction->getObjectName() != "Constant flux (reversible)")
282  {
283  std::stringstream ss;
284 
286  {
287  ss << "No substrate";
288  }
289  else
290  {
291  ss << "Exactly "
293  << " substrate";
294 
296  ss << "s"; //plural
297  }
298 
299  stringlist.push_back(ss.str());
300  }
301  }
302 
303  //products
304  if (checkProducts)
305  {
307  {
308  stringlist.push_back("At least one product");
309  }
310  else if (mpFunction->getObjectName() != "Constant flux (reversible)")
311  {
312  std::stringstream ss;
313 
315  mpFunction->getObjectName() != "Constant flux (reversible)")
316  {
317  ss << "No product";
318  }
319  else
320  {
321  ss << "Exactly "
323  << " product";
324 
326  ss << "s"; //plural
327  }
328 
329  stringlist.push_back(ss.str());
330  }
331  }
332 
333  if (stringlist.size() == 0)
334  stringlist.push_back("None");
335 
336  size_t row;
337 
338  QString Restrictions("");
339  QString Separator("");
340 
341  for (row = 0; row < stringlist.size(); ++row)
342  {
343  Restrictions += Separator + FROM_UTF8(stringlist[row]);
344  Separator = ", ";
345  }
346 
347  mpEditApplicationRestrictions->setText(Restrictions);
348 
349  return true;
350 }
#define FROM_UTF8(__x)
Definition: qtUtilities.h:73
const std::string & getObjectName() const
bool isVector(CFunctionParameter::Role role) const
size_t getNumberOfParametersByUsage(CFunctionParameter::Role usage) const
CFunction * mpFunction
CFunctionParameters & getVariables()
Definition: CFunction.cpp:148
bool FunctionWidget1::saveToFunction ( )
protected

Definition at line 517 of file FunctionWidget1.cpp.

References ListViews::CHANGE, CCopasiDataModel::changed(), CEvaluationTree::compile(), copyFunctionContentsToFunction(), flagChanged, ListViews::FUNCTION, CKeyFactory::get(), CCopasiRootContainer::getKeyFactory(), CFunction::isReversible(), CopasiWidget::mKey, CopasiWidget::mpDataModel, mpFunction, CopasiWidget::protectedNotify(), CFunction::setReversible(), TriFalse, TriTrue, and TriUnspecified.

Referenced by leave().

518 {
519  CFunction* func = dynamic_cast<CFunction*>(CCopasiRootContainer::getKeyFactory()->get(mKey));
520 
521  if (!func) return false;
522 
523  //radio buttons
524  TriLogic tmpl;
525 
526  if (RadioButton1->isChecked() == true)
527  {
528  tmpl = TriTrue;
529  }
530  else if (RadioButton2->isChecked() == true)
531  {
532  tmpl = TriFalse;
533  }
534  else
535  {
536  tmpl = TriUnspecified;
537  }
538 
539  if (tmpl != func->isReversible())
540  {
541  func->setReversible(tmpl);
542  flagChanged = true;
543  }
544 
545  if (flagChanged)
546  {
548 
550 
551  if (mpDataModel != NULL)
552  {
553  mpDataModel->changed();
554  }
555 
556  flagChanged = false;
557  }
558 
559  func->compile();
560 
561  return true;
562 }
CCopasiObject * get(const std::string &key)
TriLogic
Definition: copasi.h:125
void changed(const bool &changed=true)
void setReversible(const TriLogic &reversible)
Definition: CFunction.cpp:142
CFunction * mpFunction
const TriLogic & isReversible() const
Definition: CFunction.cpp:145
virtual bool protectedNotify(ListViews::ObjectType objectType, ListViews::Action action, const std::string &key="")
CCopasiDataModel * mpDataModel
Definition: copasiWidget.h:65
static CKeyFactory * getKeyFactory()
virtual bool compile()
The class for handling a chemical kinetic function.
Definition: CFunction.h:29
bool copyFunctionContentsToFunction(const CFunction *src, CFunction *target)
std::string mKey
Definition: copasiWidget.h:63
void FunctionWidget1::slotBtnCopy ( )
protectedslot

Definition at line 670 of file FunctionWidget1.cpp.

References CopasiWidget::mKey, and mKeyToCopy.

671 {
672  mKeyToCopy = mKey;
673 }
std::string mKeyToCopy
std::string mKey
Definition: copasiWidget.h:63
void FunctionWidget1::slotBtnDelete ( )
protectedslot

Slot for being activated whenever Delete button is clicked.

Definition at line 676 of file FunctionWidget1.cpp.

References CQMessageBox::confirmDelete(), ListViews::DELETE, FROM_UTF8, ListViews::FUNCTION, CKeyFactory::get(), CEvaluationTree::getDeletedObjects(), CCopasiRootContainer::getFunctionList(), CCopasiRootContainer::getKeyFactory(), CCopasiObject::getObjectName(), CopasiWidget::mKey, CopasiWidget::protectedNotify(), and CFunctionDB::removeFunction().

677 {
679 
680  if (pFunctionDB == NULL)
681  return;
682 
684 
685  if (pFunction == NULL)
686  return;
687 
688  QMessageBox::StandardButton choice =
689  CQMessageBox::confirmDelete(NULL, "function",
690  FROM_UTF8(pFunction->getObjectName()),
691  pFunction->getDeletedObjects());
692 
693  /* Check if user chooses to deleted Functions */
694  switch (choice)
695  {
696  case QMessageBox::Ok: // Yes or Enter
697  {
699 
701  protectedNotify(ListViews::FUNCTION, ListViews::DELETE, "");//Refresh all as there may be dependencies.
702  break;
703  }
704 
705  default: // No or Escape
706  break;
707  }
708 }
#define FROM_UTF8(__x)
Definition: qtUtilities.h:73
const std::string & getObjectName() const
CCopasiObject * get(const std::string &key)
static StandardButton confirmDelete(QWidget *parent, const QString &objectType, const QString &objects, const std::set< const CCopasiObject * > &deletedObjects)
CCopasiObject::DataObjectSet getDeletedObjects() const
static CFunctionDB * getFunctionList()
virtual bool protectedNotify(ListViews::ObjectType objectType, ListViews::Action action, const std::string &key="")
static CKeyFactory * getKeyFactory()
bool removeFunction(size_t index)
std::string mKey
Definition: copasiWidget.h:63
void FunctionWidget1::slotBtnNew ( )
protectedslot

Slot for being activated wehenver New button is clicked.

Definition at line 647 of file FunctionWidget1.cpp.

References CFunctionDB::add(), ListViews::ADD, C_INVALID_INDEX, ListViews::FUNCTION, CCopasiRootContainer::getFunctionList(), CCopasiVectorN< CType >::getIndex(), CFunction::getKey(), CFunctionDB::loadedFunctions(), CopasiWidget::mpListView, CopasiWidget::protectedNotify(), ListViews::switchToOtherWidget(), and TO_UTF8.

648 {
649  std::string name = "function_1";
650  int i = 1;
651  CFunction* pFunc;
652  CCopasiVectorN<CFunction>& FunctionList
654 
655  while (FunctionList.getIndex(name) != C_INVALID_INDEX)
656  {
657  i++;
658  name = "function_";
659  name += TO_UTF8(QString::number(i));
660  }
661 
662  CCopasiRootContainer::getFunctionList()->add(pFunc = new CKinFunction(name), true);
663 
664  std::string key = pFunc->getKey();
666  // enter(key);
668 }
CCopasiVectorN< CFunction > & loadedFunctions()
void switchToOtherWidget(const size_t &id, const std::string &key)
Definition: listviews.cpp:926
#define C_INVALID_INDEX
Definition: copasi.h:222
virtual size_t getIndex(const std::string &name) const
const std::string & getKey() const
Definition: CFunction.cpp:58
ListViews * mpListView
Definition: copasiWidget.h:62
static CFunctionDB * getFunctionList()
virtual bool protectedNotify(ListViews::ObjectType objectType, ListViews::Action action, const std::string &key="")
The class for handling a chemical kinetic function.
Definition: CFunction.h:29
#define TO_UTF8(__x)
Definition: qtUtilities.h:74
bool add(CFunction *pFunction, const bool &adopt)
void FunctionWidget1::slotFcnDescriptionChanged ( bool  valid)
protectedvirtualslot

Slot for changing the function description.

This slot function is called whenever the function description is changed.

Definition at line 571 of file FunctionWidget1.cpp.

References CCopasiMessage::clearDeque(), CEvaluationTree::compile(), CQMessageBox::critical(), flagChanged, CCopasiMessage::getLastMessage(), isValid, loadParameterTable(), loadUsageTable(), MCFunction, mIgnoreFcnDescriptionChange, mpFunction, CCopasiMessage::peekLastMessage(), CFunction::setInfix(), and TO_UTF8.

Referenced by init().

572 {
573 
575  (mpFunction == NULL))
576  return;
577 
578  isValid = valid;
579 
580  if (isValid)
581  {
582  try
583  {
584  if (!mpFunction->setInfix(TO_UTF8(mpExpressionEMSW->getText())) ||
585  !mpFunction->compile())
586  {
587  isValid = true;
588  }
589  }
590  catch (...)
591  {
592  isValid = false;
593  }
594  }
595 
596  if (isValid)
597  {
598  flagChanged = true;
599  //parameter table
601 
602  // application table
603  loadUsageTable();
604  }
605  else
606  {
607  if (CCopasiMessage::peekLastMessage().getNumber() == MCFunction + 4)
608  {
609  CQMessageBox::critical(this, "Function Error",
610  CCopasiMessage::getLastMessage().getText().c_str(),
611  QMessageBox::Ok | QMessageBox::Default,
612  QMessageBox::NoButton);
614  }
615  }
616 }
static const CCopasiMessage & peekLastMessage()
bool mIgnoreFcnDescriptionChange
#define MCFunction
virtual bool setInfix(const std::string &infix)
Definition: CFunction.cpp:73
static void clearDeque()
CFunction * mpFunction
static StandardButton critical(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons=Ok, StandardButton defaultButton=NoButton)
static CCopasiMessage getLastMessage()
virtual bool compile()
#define TO_UTF8(__x)
Definition: qtUtilities.h:74
bool loadUsageTable()
Function to generate the text representation of the usage restrictions.
void FunctionWidget1::slotReversibilityChanged ( )
protectedvirtualslot

Slot for changing the reversibility of the function.

Definition at line 639 of file FunctionWidget1.cpp.

References loadUsageTable().

640 {
641  loadUsageTable();
642 }
bool loadUsageTable()
Function to generate the text representation of the usage restrictions.
void FunctionWidget1::slotTableValueChanged ( const QString &  string)
protectedslot

Slot for changing the table value.

Definition at line 619 of file FunctionWidget1.cpp.

References flagChanged, CFunction::getVariables(), loadParameterTable(), loadUsageTable(), and mpFunction.

Referenced by loadParameterTable().

620 {
621  int curRow = sender()->objectName().toInt();
622 
623  QComboBox *comboItem = (QComboBox *) sender();
624 
625  flagChanged = true;
626 
628 
629  // surely, we are in COL_USAGE... thus we don't need to check it anymore
630  CFunctionParameter::Role usage = (CFunctionParameter::Role)(comboItem->findText(string));
631  functParam[curRow]->setUsage(usage);
632 
633  //update tables
635  loadUsageTable();
636 }
CFunction * mpFunction
CFunctionParameters & getVariables()
Definition: CFunction.cpp:148
bool loadUsageTable()
Function to generate the text representation of the usage restrictions.
bool FunctionWidget1::update ( ListViews::ObjectType  objectType,
ListViews::Action  action,
const std::string &  key 
)
virtual

Function to update the COPASI widgets.

Reimplemented from CopasiWidget.

Definition at line 715 of file FunctionWidget1.cpp.

References ListViews::CHANGE, ListViews::DELETE, ListViews::FUNCTION, CCopasiRootContainer::getKeyFactory(), loadFromFunction(), CopasiWidget::mIgnoreUpdates, CopasiWidget::mKey, and ListViews::MODEL.

716 {
717  if (mIgnoreUpdates) return true;
718 
719  switch (objectType)
720  {
721  case ListViews::MODEL:
722  loadFromFunction(dynamic_cast< CFunction * >(CCopasiRootContainer::getKeyFactory()->get(mKey)));
723  break;
724 
725  case ListViews::FUNCTION:
726 
727  if (key == mKey)
728  {
729  switch (action)
730  {
731  case ListViews::CHANGE:
732  loadFromFunction(dynamic_cast< CFunction * >(CCopasiRootContainer::getKeyFactory()->get(mKey)));
733  break;
734 
735  case ListViews::DELETE:
736  mKey = "";
737  break;
738 
739  default:
740  break;
741  }
742  }
743 
744  break;
745 
746  default:
747  break;
748  }
749 
750  return true;
751 }
objectType
bool mIgnoreUpdates
Definition: copasiWidget.h:67
static CKeyFactory * getKeyFactory()
bool loadFromFunction(const CFunction *=NULL)
std::string mKey
Definition: copasiWidget.h:63
void FunctionWidget1::updateApplication ( )
protected

Member Data Documentation

bool FunctionWidget1::flagChanged
protected
bool FunctionWidget1::isValid
protected

Definition at line 63 of file FunctionWidget1.h.

Referenced by leave(), loadFromFunction(), and slotFcnDescriptionChanged().

bool FunctionWidget1::mIgnoreFcnDescriptionChange
protected

Definition at line 64 of file FunctionWidget1.h.

Referenced by loadFromFunction(), and slotFcnDescriptionChanged().

std::string FunctionWidget1::mKeyToCopy
private

Definition at line 73 of file FunctionWidget1.h.

Referenced by enterProtected(), and slotBtnCopy().

CFunction* FunctionWidget1::mpFunction
protected
bool FunctionWidget1::mReadOnly
private

Definition at line 71 of file FunctionWidget1.h.

Referenced by loadFromFunction(), and loadParameterTable().


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