|
From: <le...@us...> - 2007-01-20 12:33:57
|
Revision: 203
http://svn.sourceforge.net/qcell/?rev=203&view=rev
Author: lessm
Date: 2007-01-20 04:33:55 -0800 (Sat, 20 Jan 2007)
Log Message:
-----------
- CalculationData have toXmlString string method
Modified Paths:
--------------
trunk/qcell/baseheaders/CalculationData.h
trunk/qcell/basesources/CalculationData.cpp
trunk/qcell/parsers/KI/KIParserPlugin.cpp
trunk/qcell/visgui/MainWindow.cpp
Modified: trunk/qcell/baseheaders/CalculationData.h
===================================================================
--- trunk/qcell/baseheaders/CalculationData.h 2007-01-20 12:33:20 UTC (rev 202)
+++ trunk/qcell/baseheaders/CalculationData.h 2007-01-20 12:33:55 UTC (rev 203)
@@ -7,6 +7,7 @@
#include <QVector>
#include <QDomDocument>
#include <QDomElement>
+#include <QStringList>
#include "BaseDataTypes.h"
class CalculationData : public baseDataTypes
@@ -75,9 +76,10 @@
/*const*/ char *getDataPointer(void);
void fillData(char *dataPointer);
+ void fillData(int value);
void setForeignDataPointer(char *dataPointer, bool silent=0);
- QString createXmlHeader(void);
+ QString toXmlString(void);
bool setFromXmlString(QString *xmlString);
bool parseXmlElement(QDomElement *root);
Modified: trunk/qcell/basesources/CalculationData.cpp
===================================================================
--- trunk/qcell/basesources/CalculationData.cpp 2007-01-20 12:33:20 UTC (rev 202)
+++ trunk/qcell/basesources/CalculationData.cpp 2007-01-20 12:33:55 UTC (rev 203)
@@ -725,6 +725,45 @@
}
}
+void CalculationData::fillData(int value)
+{
+ int counter = 0;
+ if(data)
+ {
+ switch(dimension)
+ {
+ case 1:
+ counter = sizeX;
+ break;
+ case 2:
+ counter = sizeX * sizeY;
+ break;
+ case 3:
+ counter = sizeX * sizeY * sizeZ;
+ break;
+ case 4:
+ counter = sizeX * sizeY * sizeZ * sizeT;
+ break;
+ }
+
+ switch(dataType)
+ {
+ case baseDataTypes::CHAR:
+ for(int i=0;i<counter;++i)
+ *((char *)data + i) = (char)value;
+ break;
+ case baseDataTypes::SHORT:
+ for(int i=0;i<counter;++i)
+ *((short *)data + i) = (short)value;
+ break;
+ case baseDataTypes::INT:
+ for(int i=0;i<counter;++i)
+ *((int *)data + i) = value;
+ break;
+ }
+ }
+}
+
void CalculationData::setForeignDataPointer(char *dataPointer, bool silent)
{
clearData();
@@ -734,19 +773,160 @@
emit dataUpdated();
}
-QString CalculationData::createXmlHeader(void)
+QString CalculationData::toXmlString(void)
{
- return QString::number((int)this);
+ QDomDocument doc;
+ QVector<QString> elements;
+ QVector<int> counters;
+ QDomElement root, element;
+ QDomText text;
+ int maxValue=-1;
+ int curent, prev = -1;
+ int higest=-1, hindex=0;
+ root = doc.createElement("CalculationData");
+ switch(dataType)
+ {
+ case baseDataTypes::CHAR:
+ root.setAttribute("DataType", "char");
+ break;
+
+ case baseDataTypes::SHORT:
+ root.setAttribute("DataType", "short");
+ break;
+
+ case baseDataTypes::INT:
+ root.setAttribute("DataType", "int");
+ break;
+ }
+
+ switch(dimension)
+ {
+ case 4:
+ root.setAttribute("time", sizeT);
+ case 3:
+ root.setAttribute("depth", sizeZ);
+ case 2:
+ root.setAttribute("hight", sizeY);
+ case 1:
+ root.setAttribute("width", sizeX);
+ break;
+ }
+
+ for(int i=0;i<getSizeInByte() / dataSize;++i)
+ {
+ curent = getValueAt_i(i);
+ if(curent>maxValue)
+ {
+ maxValue = curent;
+ elements.resize(maxValue+1);
+ counters.resize(maxValue+1);
+ counters[curent] = 1;
+ elements[curent] += tr("%1;").arg(i);
+ }
+ else
+ {
+ counters[curent] += 1;
+ elements[curent] += tr("%1;").arg(i);
+ }
+ }
+ for(int i=0;i<counters.size();++i)
+ {
+ if(counters[i]>higest)
+ {
+ higest = counters[i];
+ hindex = i;
+ }
+ }
+
+ root.setAttribute("fill", hindex);
+
+ for(int i=0;i<elements.size();++i)
+ {
+ if(i!=hindex)
+ {
+ element = doc.createElement("Section");
+ element.setAttribute("value", i);
+ element.appendChild(doc.createTextNode(elements[i]));
+ root.appendChild(element);
+ }
+ }
+
+ doc.appendChild(root);
+ return doc.toString();
}
bool CalculationData::setFromXmlString(QString *xmlString)
{
-
- return 1;
+ QDomDocument doc;
+ doc.setContent(*xmlString);
+ QDomElement element = doc.firstChildElement();
+ return parseXmlElement(&element);
}
bool CalculationData::parseXmlElement(QDomElement *root)
{
+ QDomNode node;
+ QDomElement element;
+ QString temp;
+ QStringList sList;
+ int value;
+ if(root->tagName()=="CalculationData")
+ {
+ if(root->attribute("DataType")=="char")
+ setDataType(baseDataTypes::CHAR);
+ else
+ if(root->attribute("DataType")=="short")
+ setDataType(baseDataTypes::SHORT);
+ else
+ if(root->attribute("DataType")=="int")
+ setDataType(baseDataTypes::INT);
+ else
+ return 0;
+
+ if(root->hasAttribute("time"))
+ {
+ resizeData(root->attribute("width").toInt(), root->attribute("hight").toInt(), root->attribute("depth").toInt(), root->attribute("time").toInt());
+ }
+ else
+ if(root->hasAttribute("depth"))
+ {
+ resizeData(root->attribute("width").toInt(), root->attribute("hight").toInt(), root->attribute("depth").toInt());
+
+ }
+ else
+ if(root->hasAttribute("hight"))
+ {
+ resizeData(root->attribute("width").toInt(), root->attribute("hight").toInt());
+
+ }
+ else
+ if(root->hasAttribute("width"))
+ {
+ resizeData(root->attribute("width").toInt());
+ }
+ else
+ return 0;
+
+ if(root->hasAttribute("fill"))
+ fillData(root->attribute("fill").toInt());
+
+ node = root->firstChild();
+ while(!node.isNull())
+ {
+ element = node.toElement();
+ if(element.tagName()=="Section")
+ {
+ value = element.attribute("value").toInt();
+ sList = element.text().split(';', QString::SkipEmptyParts);
+ foreach(temp, sList)
+ {
+ setValueAt(value, temp.toInt());
+
+ }
+ }
+ node = node.nextSibling();
+ }
+ }
return 1;
}
Modified: trunk/qcell/parsers/KI/KIParserPlugin.cpp
===================================================================
--- trunk/qcell/parsers/KI/KIParserPlugin.cpp 2007-01-20 12:33:20 UTC (rev 202)
+++ trunk/qcell/parsers/KI/KIParserPlugin.cpp 2007-01-20 12:33:55 UTC (rev 203)
@@ -160,7 +160,7 @@
}
- return cd->createXmlHeader();
+ return cd->toXmlString();
}
QByteArray KIParserPlugin::parseOut(QString content, const QString type, const QString subtype)
Modified: trunk/qcell/visgui/MainWindow.cpp
===================================================================
--- trunk/qcell/visgui/MainWindow.cpp 2007-01-20 12:33:20 UTC (rev 202)
+++ trunk/qcell/visgui/MainWindow.cpp 2007-01-20 12:33:55 UTC (rev 203)
@@ -351,7 +351,10 @@
}
// Internal data settings
- data.append((CalculationData*)world_parsers[subtype]->parse(file_content, type, subtype).toInt());
+ //data.append((CalculationData*)world_parsers[subtype]->parse(file_content, type, subtype).toInt());
+ CalculationData *tempCD = new CalculationData();
+ tempCD->setFromXmlString(&XMLString);
+ data.append(tempCD);
*(CalculationData*)&calc = *data.last();
iteration=0;
@@ -427,7 +430,7 @@
}
/// @todo Wait for toXmlString
- file.write(world_parsers[subtype]->parseOut(sw->getStorage()->createXmlHeader(), type, subtype));
+ file.write(world_parsers[subtype]->parseOut(sw->getStorage()->toXmlString(), type, subtype));
}
else
{
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|