copasi API
0.1
|
00001 // Begin CVS Header 00002 // $Source: /fs/turing/cvs/copasi_dev/copasi/UI/objectdebug.ui.h,v $ 00003 // $Revision: 1.42 $ 00004 // $Name: Build-33 $ 00005 // $Author: ssahle $ 00006 // $Date: 2009/07/02 08:48:46 $ 00007 // End CVS Header 00008 00009 // Copyright (C) 2008 by Pedro Mendes, Virginia Tech Intellectual 00010 // Properties, Inc., EML Research, gGmbH, University of Heidelberg, 00011 // and The University of Manchester. 00012 // All rights reserved. 00013 00014 /**************************************************************************** 00015 ** ui.h extension file, included from the uic-generated form implementation. 00016 ** 00017 ** If you wish to add, delete or rename functions or slots use 00018 ** Qt Designer which will update this file, preserving your code. Create an 00019 ** init() function in place of a constructor, and a destroy() function in 00020 ** place of a destructor. 00021 *****************************************************************************/ 00022 00023 #include "copasi.h" 00024 00025 #include "UI/qtUtilities.h" 00026 00027 #include "report/CCopasiObject.h" 00028 #include "report/CCopasiContainer.h" 00029 #include "report/CCopasiObjectName.h" 00030 #include "report/CCopasiRootContainer.h" 00031 00032 class MyListViewItemWithPtr : public Q3ListViewItem 00033 { 00034 public: 00035 00036 MyListViewItemWithPtr(Q3ListViewItem * parent, const CCopasiObject * ptr, 00037 QString label1, QString label2 = QString::null, 00038 QString label3 = QString::null, QString label4 = QString::null, 00039 QString label5 = QString::null, QString label6 = QString::null, 00040 QString label7 = QString::null, QString label8 = QString::null) 00041 : Q3ListViewItem(parent, label1, label2, label3, label4, label5, label6, label7, label8), 00042 mpObject(ptr) 00043 {} 00044 00045 MyListViewItemWithPtr(Q3ListView * parent, const CCopasiObject * ptr, 00046 QString label1, QString label2 = QString::null, 00047 QString label3 = QString::null, QString label4 = QString::null, 00048 QString label5 = QString::null, QString label6 = QString::null, 00049 QString label7 = QString::null, QString label8 = QString::null) 00050 : Q3ListViewItem(parent, label1, label2, label3, label4, label5, label6, label7, label8), 00051 mpObject(ptr) 00052 {} 00053 00054 const CCopasiObject * mpObject; 00055 }; 00056 00057 void ObjectDebug::addObjectRecursive(QWidget * parent, const void * ptr) 00058 { 00059 const CCopasiObject * obj = static_cast<const CCopasiObject *>(ptr); 00060 Q3ListViewItem * element; 00061 00062 std::string cn = obj->getCN(); 00063 const CCopasiDataModel * pDM = obj->getObjectDataModel(); 00064 const CCopasiObject* testObj = NULL; 00065 00066 if (pDM) 00067 testObj = pDM->getObject(cn); 00068 00069 //assert(CCopasiRootContainer::getDatamodelList()->size() > 0); 00070 00071 QString flags; 00072 if (obj->isContainer()) flags += "C"; else flags += " "; 00073 if (obj->isVector()) flags += "V"; else flags += " "; 00074 if (obj->isMatrix()) flags += "M"; else flags += " "; 00075 if (obj->isNameVector()) flags += "N"; else flags += " "; 00076 if (obj->isReference()) flags += "R"; else flags += " "; 00077 if (obj->isNonUniqueName()) flags += " Nun"; else flags += " Unn"; 00078 00079 if (obj->isValueInt()) flags += "Int"; 00080 else if (obj->isValueDbl()) flags += "Dbl"; 00081 else if (obj->isValueBool()) flags += "Boo"; 00082 else if (obj->isValueString()) flags += "Str"; 00083 else if (obj->isStaticString()) flags += "SSt"; 00084 else flags += " "; 00085 00086 if (!(testObj == obj)) flags += "EEE"; 00087 00088 QString value; 00089 00090 if (obj->isValueDbl() && obj->getValuePointer()) 00091 value = QString::number(*(C_FLOAT64*)obj->getValuePointer()); 00092 else if (obj->isValueInt() && obj->getValuePointer()) 00093 value = QString::number(*(C_INT32*)obj->getValuePointer()); 00094 else if (obj->isValueString() && obj->getValuePointer()) 00095 value = FROM_UTF8(*(std::string*)obj->getValuePointer()); 00096 else if (obj->isValueBool() && obj->getValuePointer()) 00097 { 00098 if (*(bool*)obj->getValuePointer()) value = "true"; else value = "false"; 00099 } 00100 else 00101 value = ""; 00102 00103 element = new MyListViewItemWithPtr((Q3ListViewItem*)parent, obj, 00104 FROM_UTF8(obj->getObjectName()), 00105 FROM_UTF8(obj->getObjectType()), 00106 flags, 00107 value, 00108 FROM_UTF8(obj->getObjectDisplayName()), 00109 FROM_UTF8(obj->getCN())); 00110 00111 if (obj->isContainer()) 00112 { 00113 CCopasiContainer* container; 00114 container = (CCopasiContainer*)obj; 00115 00116 CCopasiContainer::objectMap::const_iterator it = container->getObjects().begin(); 00117 // int cnt = container->getObjects().size(); 00118 00119 for (; it != container->getObjects().end(); ++it) 00120 { 00121 //the next line skips name references... 00122 if (it->second->getObjectName() == "Name") continue; 00123 00124 addObjectRecursive((QWidget*)element, (void*)it->second); 00125 } 00126 00127 return; 00128 } 00129 00130 #ifdef XXXX 00131 00132 if (obj->isVector()) 00133 { 00134 CCopasiVector <CCopasiObject> * vect; 00135 vect = (CCopasiVector <CCopasiObject> *)obj; 00136 00137 //CCopasiVector<CCopasiObject>::iterator it = vect->begin(); 00138 int cnt = vect->size(); 00139 00140 int i; 00141 00142 for (i = 0; i != cnt; ++i) 00143 {addObjectRecursive((QWidget*)element, (void*)(*vect)[i]);} 00144 } 00145 00146 #endif // XXXX 00147 } 00148 00149 void ObjectDebug::update() 00150 { 00151 ListOfObjects->clear(); 00152 00153 const CCopasiObject * obj; 00154 00155 Q3ListViewItem * element; 00156 element = new MyListViewItemWithPtr(ListOfObjects, NULL, "*"); 00157 element->setOpen(true); 00158 00159 obj = CCopasiRootContainer::getRoot(); 00160 00161 if (!obj) return; 00162 00163 addObjectRecursive((QWidget*)element, (const void *) obj); 00164 00165 ListOfObjects->show(); 00166 } 00167 00168 void ObjectDebug::init() 00169 { 00170 ListOfObjects->clear(); 00171 ListOfObjects->addColumn("Type", -1); 00172 ListOfObjects->addColumn("Flags", -1); 00173 ListOfObjects->addColumn("Value", -1); 00174 ListOfObjects->addColumn("Display Name", -1); 00175 ListOfObjects->addColumn("CN", -1); 00176 ListOfObjects->addColumn("Unique name", -1); 00177 ListOfObjects->setAllColumnsShowFocus(true); 00178 } 00179 00180 #include "model/CDotOutput.h" 00181 00182 void ObjectDebug::writeDot() 00183 { 00184 00185 CDotOutput dot; 00186 assert(CCopasiRootContainer::getDatamodelList()->size() > 0); 00187 CCopasiDataModel* pDataModel = (*CCopasiRootContainer::getDatamodelList())[0]; 00188 assert(pDataModel != NULL); 00189 dot.simpleCall(pDataModel->getModel()); 00190 } 00191 00192 #include "model/CModelAnalyzer.h" 00193 #include "CopasiDataModel/CCopasiDataModel.h" 00194 #include <q3textedit.h> 00195 #include <sstream> 00196 00197 void ObjectDebug::checkModel() 00198 { 00199 assert(CCopasiRootContainer::getDatamodelList()->size() > 0); 00200 CModelAnalyzer MA((*CCopasiRootContainer::getDatamodelList())[0]->getModel()); 00201 00202 std::ostringstream ss; 00203 MA.writeReport(ss, true, true); 00204 00205 Q3TextEdit* pTE = new Q3TextEdit(FROM_UTF8(ss.str())); 00206 pTE->show(); 00207 }