1 /*
2     This file is a part of the RepSnapper project.
3     Copyright (C) 2012  martin.dieringer@gmx.de
4 
5     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation; either version 2 of the License, or
8     (at your option) any later version.
9 
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14 
15     You should have received a copy of the GNU General Public License along
16     with this program; if not, write to the Free Software Foundation, Inc.,
17     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19 
20 #pragma once
21 
22 #include "shape.h"
23 #include "files.h"
24 
25 #include <libxml++/libxml++.h>
26 
27 // shape to represent a 2-dimensional Object (SVG file etc.)
28 class FlatShape : public Shape
29 {
30 
31  public:
dimensions()32   virtual short dimensions(){return 2;};
33 
34   FlatShape();
35   FlatShape(string filename);
~FlatShape()36   ~FlatShape(){};
37 
38   /* FlatShape(const FlatShape &rhs); */
39 
40   int loadSVG(istream *text);
41 
42   bool getPolygonsAtZ(const Matrix4d &T, double z,
43   		      vector<Poly> &polys, double &max_grad,
44 		      vector<Poly> &supportpolys,
45 		      double max_supportangle=-1,
46 		      double thickness=-1) const;
47 
48 
49   /* int load(std::string filename); */
50 
51   void clear();
52 
53   /* void displayInfillOld(const Settings &settings, CuttingPlane &plane,  */
54   /* 		      guint LayerNr, vector<int>& altInfillLayers); */
55   /* void draw (const Model *model, const Settings &settings, */
56   /* 	     bool highlight=false); */
57 
58   void draw_geometry (uint max_triangles=0);
59   /* void drawBBox() const;  */
60   /*void CenterAroundXY();*/
61 
62   /* vector<Vector3d> getMostUsedNormals() const; */
63 
64   // Auto-Rotate object to have the largest area surface down for printing:
65   /* void OptimizeRotation();  */
66   void CalcBBox();
67 
68   // Rotation for manual rotate and used by OptimizeRotation:
69   void Rotate(const Vector3d & axis, const double &angle);
70 
71   /* void Scale(double scale_factor); */
72   /* void ScaleX(double scale_factor); */
73   /* void ScaleY(double scale_factor); */
74   /* void ScaleZ(double scale_factor){}; */
75 
76   /* double getScaleFactor(){ return scale_factor; }; */
77   /* double getScaleFactorX(){ return scale_factor_x; }; */
78   /* double getScaleFactorY(){ return scale_factor_y; }; */
79   /* double getScaleFactorZ(){ return 1; };  */
80 
81 
82 
83   void invertNormals();
84   void mirror();
85 
86 
87 
88   double area() const;
89 
90   int loadSVG(std::string filename);
91   void xml_handle_node(const xmlpp::Node* node);
92   string svg_cur_style;
93   string svg_cur_name;
94   string svg_cur_trans;
95   string svg_cur_path;
96   double svg_prescale;
97   int svg_addPolygon();
98 
99 
getFileType(std::string filename)100   static filetype_t getFileType(std::string filename) {return SVG;};
101 
102   void splitshapes(vector<Shape*> &shapes, ViewProgress *progress=NULL);
103 
104   string info() const;
105 
106  private:
107   vector<Poly> polygons;
108 };
109