# B15F: drv/plottyfile.cpp Source File

plottyfile.cpp
#include "plottyfile.h"
void PlottyFile::addDot(Dot& dot)
{
dots.push_back(dot);
}
void PlottyFile::addDot(Dot dot)
{
dots.push_back(dot);
}
void PlottyFile::setFunctionType(FunctionType function_type)
{
this->function_type = function_type;
}
void PlottyFile::setQuadrant(uint8_t quadrant)
{
if(quadrant < 1 || quadrant > 4)
throw std::range_error("Ungueltiger Quadrant");
this->quadrant = quadrant;
}
void PlottyFile::setRefX(uint16_t ref_x)
{
this->ref_x = ref_x;
}
void PlottyFile::setRefY(uint16_t ref_y)
{
this->ref_y = ref_y;
}
void PlottyFile::setParaFirstCurve(uint16_t para_first)
{
this->para_first = para_first;
}
void PlottyFile::setParaStepWidth(uint16_t para_stepwidth)
{
this->para_stepwidth = para_stepwidth;
}
void PlottyFile::setUnitX(std::string unit_x)
{
this->unit_x = unit_x;
}
void PlottyFile::setDescX(std::string desc_x)
{
this->desc_x = desc_x;
}
void PlottyFile::setUnitY(std::string unit_y)
{
this->unit_y = unit_y;
}
void PlottyFile::setDescY(std::string desc_y)
{
this->desc_y = desc_y;
}
void PlottyFile::setUnitPara(std::string unit_para)
{
this->unit_para = unit_para;
}
void PlottyFile::setDescPara(std::string desc_para)
{
this->desc_para = desc_para;
}
FunctionType PlottyFile::getFunctionType() const
{
return function_type;
}
uint8_t PlottyFile::getQuadrant() const
{
return quadrant;
}
uint16_t PlottyFile::getRefX() const
{
return ref_x;
}
uint16_t PlottyFile::getRefY() const
{
return ref_y;
}
uint16_t PlottyFile::getParaFirstCurve() const
{
return para_first;
}
uint16_t PlottyFile::getParaStepWidth() const
{
return para_stepwidth;
}
std::string PlottyFile::getUnitX() const
{
return unit_x;
}
std::string PlottyFile::getDescX() const
{
return desc_x;
}
std::string PlottyFile::getUnitY() const
{
return unit_y;
}
std::string PlottyFile::getDescY() const
{
return desc_y;
}
std::string PlottyFile::getUnitPara() const
{
return unit_para;
}
std::string PlottyFile::getDescPara() const
{
return desc_para;
}
void PlottyFile::prepStr(std::string& str, uint8_t len)
{
if(str.length() > len)
throw std::runtime_error("Zu grosser String.");
if(str.length() != len)
str += '\n';
while(str.length() < len)
str += '\0';
}
void PlottyFile::writeToFile(std::string filename)
{
if(dots.empty())
throw std::length_error("Es wurden keine Punkte gespeichert.");
prepStr(unit_x, STR_LEN_SHORT);
prepStr(desc_x, STR_LEN_LARGE);
prepStr(unit_y, STR_LEN_SHORT);
prepStr(desc_y, STR_LEN_LARGE);
prepStr(unit_para, STR_LEN_SHORT);
prepStr(desc_para, STR_LEN_LARGE);
std::ofstream file(filename);
// write file header
file.write(reinterpret_cast<char*>(&command), 1);
file.write(head.c_str(), head.length());
file.write(filetype.c_str(), filetype.length());
file.write(reinterpret_cast<char*>(&version), 2);
file.write(reinterpret_cast<char*>(&subversion), 2);
file.put(static_cast<uint8_t>(function_type));
file.write(reinterpret_cast<char*>(&quadrant), 1);
file.write(reinterpret_cast<char*>(&ref_x), 2);
file.write(reinterpret_cast<char*>(&ref_y), 2);
file.write(reinterpret_cast<char*>(&para_first), 2);
file.write(reinterpret_cast<char*>(&para_stepwidth), 2);
file.write(unit_x.c_str(), unit_x.length());
file.write(desc_x.c_str(), desc_x.length());
file.write(unit_y.c_str(), unit_y.length());
file.write(desc_y.c_str(), desc_y.length());
file.write(unit_para.c_str(), unit_para.length());
file.write(desc_para.c_str(), desc_para.length());
file.write(reinterpret_cast<const char*>(&eof), 1);
// make sure header size is 256 Byte
while(file.tellp() < 256)
file.put(0);
for(Dot& dot : dots)
{
file.put((dot.getX() >> 8) | (static_cast<uint8_t>(dot.getCurve()) << 2));
file.put(dot.getX() & 0xFF);
file.put(dot.getY() >> 8);
file.put(dot.getY() & 0xFF);
}
file.close();
}
void PlottyFile::startPlotty(std::string filename)
{
int code = system(("plotty --in " + filename).c_str());
if(code)
throw std::runtime_error("Fehler beim Aufruf von plotty");
}
PlottyFile::setParaStepWidth
void setParaStepWidth(uint16_t para_stepwidth)
Definition: plottyfile.cpp:40
PlottyFile::getQuadrant
uint8_t getQuadrant(void) const
Definition: plottyfile.cpp:80
PlottyFile::startPlotty
void startPlotty(std::string filename)
Definition: plottyfile.cpp:196
PlottyFile::writeToFile
void writeToFile(std::string filename)
Definition: plottyfile.cpp:147
PlottyFile::setUnitX
void setUnitX(std::string unit_x)
Definition: plottyfile.cpp:45
PlottyFile::setUnitPara
void setUnitPara(std::string unit_para)
Definition: plottyfile.cpp:65
PlottyFile::setDescY
void setDescY(std::string desc_y)
Definition: plottyfile.cpp:60
PlottyFile::setQuadrant
void setQuadrant(uint8_t quadrant)
Definition: plottyfile.cpp:18
PlottyFile::getDescY
std::string getDescY(void) const
Definition: plottyfile.cpp:120
PlottyFile::setRefY
void setRefY(uint16_t ref_y)
Definition: plottyfile.cpp:30
PlottyFile::getDescX
std::string getDescX(void) const
Definition: plottyfile.cpp:110
PlottyFile::setFunctionType
void setFunctionType(FunctionType function_type)
Definition: plottyfile.cpp:13
PlottyFile::setDescX
void setDescX(std::string desc_x)
Definition: plottyfile.cpp:50
Dot
Definition: dot.h:12
PlottyFile::setRefX
void setRefX(uint16_t ref_x)
Definition: plottyfile.cpp:25
PlottyFile::setUnitY
void setUnitY(std::string unit_y)
Definition: plottyfile.cpp:55
PlottyFile::addDot
void addDot(Dot &dot)
Definition: plottyfile.cpp:3
PlottyFile::setDescPara
void setDescPara(std::string desc_para)
Definition: plottyfile.cpp:70
PlottyFile::getParaStepWidth
uint16_t getParaStepWidth(void) const
Definition: plottyfile.cpp:100
PlottyFile::getDescPara
std::string getDescPara(void) const
Definition: plottyfile.cpp:130
PlottyFile::setParaFirstCurve
void setParaFirstCurve(uint16_t para_first)
Definition: plottyfile.cpp:35
PlottyFile::getUnitY
std::string getUnitY(void) const
Definition: plottyfile.cpp:115
PlottyFile::getParaFirstCurve
uint16_t getParaFirstCurve(void) const
Definition: plottyfile.cpp:95
PlottyFile::getRefX
uint16_t getRefX(void) const
Definition: plottyfile.cpp:85
PlottyFile::getUnitPara
std::string getUnitPara(void) const
Definition: plottyfile.cpp:125
PlottyFile::getFunctionType
FunctionType getFunctionType(void) const
Definition: plottyfile.cpp:75
PlottyFile::getRefY
uint16_t getRefY(void) const
Definition: plottyfile.cpp:90
PlottyFile::getUnitX
std::string getUnitX(void) const
Definition: plottyfile.cpp:105