You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
137 lines
2.3 KiB
C++
137 lines
2.3 KiB
C++
#include "MLPlineList.h"
|
|
#include "MLPline.h"
|
|
|
|
MLPlineList::MLPlineList()
|
|
{
|
|
|
|
}
|
|
|
|
MLPlineList::~MLPlineList()
|
|
{
|
|
clearPline();
|
|
}
|
|
|
|
void MLPlineList::clearPline()
|
|
{
|
|
/*while (!m_PlineList.isEmpty())
|
|
{
|
|
delete m_PlineList.first();
|
|
}*/
|
|
for (int i = m_PlineList.count() - 1; i >= 0; i--)
|
|
{
|
|
delete m_PlineList[i];
|
|
m_PlineList[i] = nullptr;
|
|
}
|
|
m_PlineList.clear();
|
|
}
|
|
|
|
int MLPlineList::getCount() const
|
|
{
|
|
return m_PlineList.count();
|
|
}
|
|
|
|
void MLPlineList::addPline(MLPline* pPline)
|
|
{
|
|
m_PlineList.push_back(pPline);
|
|
}
|
|
|
|
void MLPlineList::removePline(MLPline* pPline)
|
|
{
|
|
m_PlineList.removeOne(pPline);
|
|
}
|
|
|
|
MLPline* MLPlineList::getPline(int index) const
|
|
{
|
|
if (index >= 0 && index < getCount())
|
|
{
|
|
return m_PlineList[index];
|
|
}
|
|
return nullptr;
|
|
}
|
|
|
|
MLPline* MLPlineList::getPline(char* name) const
|
|
{
|
|
return nullptr;
|
|
}
|
|
|
|
MLPline* MLPlineList::getPline(const QString& sLineName) const
|
|
{
|
|
return nullptr;
|
|
}
|
|
|
|
bool MLPlineList::readPline(const QString& sPath)
|
|
{
|
|
QFile file(sPath);
|
|
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
|
|
{
|
|
return false;
|
|
}
|
|
QTextStream stream(&file);
|
|
|
|
QString sLine;
|
|
while (!stream.atEnd())
|
|
{
|
|
sLine = stream.readLine().simplified();
|
|
if (!sLine.indexOf("New", 0, Qt::CaseInsensitive))
|
|
{
|
|
while (!stream.atEnd())
|
|
{
|
|
sLine = stream.readLine().simplified();
|
|
if (!sLine.indexOf("EndNew", 0, Qt::CaseInsensitive))
|
|
break;
|
|
}
|
|
}
|
|
else if (sLine.indexOf("Pline", 0, Qt::CaseInsensitive) >= 0)
|
|
{
|
|
QString name;
|
|
int p = sLine.indexOf(".");
|
|
if (p > 0 && p < sLine.length() - 1)
|
|
name = sLine.mid(p + 1);
|
|
|
|
MLPline* pPline = new MLPline;
|
|
pPline->setName(name.toLocal8Bit().data());
|
|
|
|
while (!stream.atEnd())
|
|
{
|
|
sLine = stream.readLine().simplified();
|
|
if (sLine.isEmpty())
|
|
break;
|
|
|
|
double x, y;
|
|
sscanf(sLine.toLocal8Bit().data(), "%lf,%lf\n", &x, &y);
|
|
pPline->addTailPt(x, y);
|
|
}
|
|
addPline(pPline);
|
|
}
|
|
}
|
|
|
|
file.close();
|
|
return true;
|
|
}
|
|
|
|
bool MLPlineList::writePline(const QString& sPath)
|
|
{
|
|
QFile file(sPath);
|
|
if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
QTextStream stream(&file);
|
|
|
|
for (MLPline* pPline : m_PlineList)
|
|
{
|
|
pPline->write(stream);
|
|
}
|
|
file.close();
|
|
return true;
|
|
}
|
|
|
|
void MLPlineList::write(QTextStream& out)
|
|
{
|
|
for (MLPline* pPline : m_PlineList)
|
|
{
|
|
pPline->write(out);
|
|
}
|
|
}
|