1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
|
/*
* Copyright (C) 1993-2009 Robert & Jeremy Laine
* See AUTHORS file for a full list of contributors.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "sailwriter-carlson.h"
#include <fstream>
#include <iomanip>
#include <QFile>
/** Write the draw message
*
* @param out the output stream
* @param ct number of points to be written
*/
void CSailCarlsonWriter::writeDraw(ofstream &out, unsigned int ct) const
{
out.setf(ios::left, ios::adjustfield);
out<< setw(16) <<"draw"<< ct << CRLF;
}
/** Write the cut message
*
* @param out the output stream
* @param ct number of points to be written
*/
void CSailCarlsonWriter::writeCut(ofstream &out, unsigned int ct) const
{
out.setf(ios::left, ios::adjustfield);
out<< setw(16) <<"cut"<< ct << CRLF;
}
/** Write a point
*
* @param out the output stream
* @param p0 3d point to be written
*/
void CSailCarlsonWriter::writePoint(ofstream &out, CPoint3d p0) const
{
real x=0, y=0;
x= p0.x();
y= p0.y();
out.setf(ios::left, ios::adjustfield);
out << setw(16) << x << y << CRLF;
}
/** Write panel header to Carlson plotter format
*
* @param out the output stream
* @param panel the number of the panel to write
*
*/
void CSailCarlsonWriter::writePanelHeader(ofstream &out, const CPanel &panel) const
{
//char identity;
//identity = panel.label.name;
unsigned int pencolor = panel.label.color;
unsigned int htx = panel.label.height; // text height in mm
real xoff =0 , yoff = 0, rtx=0; // position and text rotation from x axis.
xoff= panel.label.origin.x();
yoff= panel.label.origin.y();
//rtx = atn2( xoff= panel.label.direction.y(), xoff= _sail[panel].label.direction.x());
out << "panel, "<< panel.label.name <<", "<<pencolor<<", "<< xoff<<", "<<yoff<<", "<<rtx<<", "<<htx << CRLF;
}
/** Write sail to Carlson plotter format.
*
* @param sail the sail to write
* @param filename the file to write to
*/
void CSailCarlsonWriter::write(const CPanelGroup &sail, const QString &filename) const
{
ofstream out;
out.open(QFile::encodeName(filename),ios::out);
if (!out.is_open())
throw write_error("CSailCarlsonWriter::write : unable to write to specified file");
out << "Sailcut Carlson plotter development: Test1" << CRLF;
unsigned int pn = 0;
for (pn = 0; pn < sail.size(); pn++)
writePanel( out, sail[pn] );
out << "EOF" << CRLF;
out.close();
}
/** Write panel to Carlson plotter format
*
* @param out the output stream
* @param panel the number of the panel to write
*
*/
void CSailCarlsonWriter::writePanel(ofstream &out, const CPanel &panel) const
{
CSide top = panel.top;
CSide btm = panel.bottom;
CSide left = panel.left;
CSide right = panel.right;
CSide ctop = panel.cutTop;
CSide cbtm = panel.cutBottom;
CSide cleft = panel.cutLeft;
CSide cright = panel.cutRight;
unsigned int i=0; // ascending counter
int j = 0; // descending counter
//// header of panel
writePanelHeader(out, panel);
//// header for draw line
writeDraw (out, left.size()+top.size()+right.size()+btm.size());
// left edge
for (i = 0; i < left.size(); i++)
{
writePoint( out, left[i] );
}
// panel top edge
for (i = 0; i < top.size(); i++)
{
writePoint( out, top[i] );
}
// panel right edge
for (j = right.size() -1; j> -1; j--)
{
writePoint( out, right[j] );
}
//// panel bottom edge
for (j = btm.size() -1; j > -1; j--)
{
writePoint( out, btm[j] );
}
//// header for cut line
writeCut ( out, left.size()+top.size()+right.size()+btm.size() );
// left edge
for (i = 0; i < left.size(); i++)
{
writePoint( out, cleft[i] );
}
// panel top edge
for (i = 0; i < top.size(); i++)
{
writePoint( out, ctop[i] );
}
// panel right edge
for (j = right.size() -1; j > - 1; j--)
{
writePoint( out, cright[j] );
}
// panel bottom edge
for (j = btm.size() -1; j > -1; j--)
{
writePoint( out, cbtm[j] );
}
}
|