1 #include "plottyfile.h" 3 void PlottyFile::addDot(
Dot& dot)
8 void PlottyFile::addDot(
Dot dot)
13 void PlottyFile::setFunctionType(FunctionType function_type)
15 this->function_type = function_type;
18 void PlottyFile::setQuadrant(uint8_t quadrant)
20 if(quadrant < 1 || quadrant > 4)
21 throw std::range_error(
"Ungueltiger Quadrant");
22 this->quadrant = quadrant;
25 void PlottyFile::setRefX(uint16_t ref_x)
30 void PlottyFile::setRefY(uint16_t ref_y)
35 void PlottyFile::setParaFirstCurve(uint16_t para_first)
37 this->para_first = para_first;
40 void PlottyFile::setParaStepWidth(uint16_t para_stepwidth)
42 this->para_stepwidth = para_stepwidth;
45 void PlottyFile::setUnitX(std::string unit_x)
47 this->unit_x = unit_x;
50 void PlottyFile::setDescX(std::string desc_x)
52 this->desc_x = desc_x;
55 void PlottyFile::setUnitY(std::string unit_y)
57 this->unit_y = unit_y;
60 void PlottyFile::setDescY(std::string desc_y)
62 this->desc_y = desc_y;
65 void PlottyFile::setUnitPara(std::string unit_para)
67 this->unit_para = unit_para;
70 void PlottyFile::setDescPara(std::string desc_para)
72 this->desc_para = desc_para;
75 FunctionType PlottyFile::getFunctionType()
const 80 uint8_t PlottyFile::getQuadrant()
const 85 uint16_t PlottyFile::getRefX()
const 90 uint16_t PlottyFile::getRefY()
const 95 uint16_t PlottyFile::getParaFirstCurve()
const 100 uint16_t PlottyFile::getParaStepWidth()
const 102 return para_stepwidth;
105 std::string PlottyFile::getUnitX()
const 110 std::string PlottyFile::getDescX()
const 115 std::string PlottyFile::getUnitY()
const 120 std::string PlottyFile::getDescY()
const 125 std::string PlottyFile::getUnitPara()
const 130 std::string PlottyFile::getDescPara()
const 135 void PlottyFile::prepStr(std::string& str, uint8_t len)
137 if(str.length() > len)
138 throw std::runtime_error(
"Zu grosser String.");
140 if(str.length() != len)
143 while(str.length() < len)
147 void PlottyFile::writeToFile(std::string filename)
149 prepStr(unit_x, STR_LEN_SHORT);
150 prepStr(desc_x, STR_LEN_LARGE);
151 prepStr(unit_y, STR_LEN_SHORT);
152 prepStr(desc_y, STR_LEN_LARGE);
153 prepStr(unit_para, STR_LEN_SHORT);
154 prepStr(desc_para, STR_LEN_LARGE);
156 std::ofstream file(filename);
159 file.write(reinterpret_cast<char*>(&command), 1);
160 file.write(head.c_str(), head.length());
161 file.write(filetype.c_str(), filetype.length());
162 file.write(reinterpret_cast<char*>(&version), 2);
163 file.write(reinterpret_cast<char*>(&subversion), 2);
164 file.put(static_cast<uint8_t>(function_type));
165 file.write(reinterpret_cast<char*>(&quadrant), 1);
166 file.write(reinterpret_cast<char*>(&ref_x), 2);
167 file.write(reinterpret_cast<char*>(&ref_y), 2);
168 file.write(reinterpret_cast<char*>(¶_first), 2);
169 file.write(reinterpret_cast<char*>(¶_stepwidth), 2);
170 file.write(unit_x.c_str(), unit_x.length());
171 file.write(desc_x.c_str(), desc_x.length());
172 file.write(unit_y.c_str(), unit_y.length());
173 file.write(desc_y.c_str(), desc_y.length());
174 file.write(unit_para.c_str(), unit_para.length());
175 file.write(desc_para.c_str(), desc_para.length());
176 file.write(reinterpret_cast<const char*>(&eof), 1);
179 while(file.tellp() < 256)
184 file.put((dot.getX() >> 8) | (static_cast<uint8_t>(dot.getCurve()) << 2));
185 file.put(dot.getX() & 0xFF);
186 file.put(dot.getY() >> 8);
187 file.put(dot.getY() & 0xFF);
193 void PlottyFile::startPlotty(std::string filename)
195 int code = system((
"plotty --in " + filename).c_str());
197 throw std::runtime_error(
"Fehler beim Aufruf von plotty");