Skip to content

Commit

Permalink
Fix print output of polyline.
Browse files Browse the repository at this point in the history
  • Loading branch information
GilesBathgate committed Dec 4, 2014
1 parent 2e98665 commit d67d48f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 25 deletions.
57 changes: 32 additions & 25 deletions src/nodeprinter.cpp
Expand Up @@ -18,48 +18,55 @@

#include "nodeprinter.h"
#include "onceonly.h"
#include "polyhedron.h"

NodePrinter::NodePrinter(QTextStream& s) : result(s)
{
}

void NodePrinter::visit(PrimitiveNode* n)
{

result << "polyhedron([";
Polyhedron* ph = dynamic_cast<Polyhedron*>(n->getPrimitive());
if(ph) {
OnceOnly first;
foreach(Point p, ph->getPoints()) {
if(!first())
result << ",";
result << p.toString();
}
result << "],[";
if(ph)
printPolyhedron(ph);

result << "]);";
}

OnceOnly first_pg;
foreach(Polygon* pg,ph->getPolygons()) {
if(!first_pg())
void NodePrinter::printPolyhedron(Polyhedron* ph)
{
OnceOnly first;
foreach(Point p, ph->getPoints()) {
if(!first())
result << ",";
result << p.toString();
}
result << "],[";

OnceOnly first_pg;
foreach(Polygon* pg,ph->getPolygons()) {
if(!first_pg())
result << ",";
result << "[";

OnceOnly first_p;
foreach(int i,pg->getIndexes()) {
if(!first_p())
result << ",";
result << "[";

OnceOnly first_p;
foreach(int i,pg->getIndexes()) {
if(!first_p())
result << ",";
result << QString().setNum(i);
}
result << "]";
result << QString().setNum(i);
}
result << "]);";
result << "]";
}
}

void NodePrinter::visit(PolylineNode* n)
{
result << "polyline()";
printChildren(n);
result << "polyline([";
Polyhedron* ph = dynamic_cast<Polyhedron*>(n->getPrimitive());
if(ph)
printPolyhedron(ph);

result << "]);";
}

void NodePrinter::visit(UnionNode* n)
Expand Down
2 changes: 2 additions & 0 deletions src/nodeprinter.h
Expand Up @@ -21,6 +21,7 @@

#include <QTextStream>
#include "nodevisitor.h"
#include "polyhedron.h"
#include "node/primitivenode.h"
#include "node/polylinenode.h"
#include "node/unionnode.h"
Expand Down Expand Up @@ -85,6 +86,7 @@ class NodePrinter : public NodeVisitor
void printChildren(Node*);
void printArguments(Point);
void printArguments(Polygon);
void printPolyhedron(Polyhedron*);
private:
QTextStream& result;
};
Expand Down

0 comments on commit d67d48f

Please sign in to comment.