summaryrefslogtreecommitdiff
path: root/branches/sm-unittesting/src/org/reprap/geometry/Producer.java
blob: ac8039cc1dc5b2346bf990b17761ff1dc02c882e (plain)
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
package org.reprap.geometry;

import org.reprap.Printer;
import org.reprap.geometry.polygons.Rr2Point;
import org.reprap.geometry.polygons.RrLine;
import org.reprap.geometry.polygons.RrPolygon;
import org.reprap.geometry.polygons.RrPolygonList;
import org.reprap.gui.PreviewPanel;
import org.reprap.gui.RepRapBuild;
import org.reprap.machines.MachineFactory;

public class Producer {
	
	static private final double layerSpacing = 0.3; ///< Vertical spacing in mm

	protected Printer reprap;
	protected RrLine oddHatchDirection;
	protected RrLine evenHatchDirection;
	
	public Producer(PreviewPanel preview, RepRapBuild builder) throws Exception {
		reprap = MachineFactory.create();
		reprap.setPreviewer(preview);
		
		oddHatchDirection = new RrLine(new Rr2Point(0.0, 0.0), new Rr2Point(1.0, 1.0));
		evenHatchDirection = new RrLine(new Rr2Point(0.0, 1.0), new Rr2Point(1.0, 0.0));
	}
	
	public void produce() throws Exception {
	
		reprap.initialise();
		reprap.selectMaterial(0);
		reprap.setSpeed(230);
		reprap.setExtruderSpeed(180);
		reprap.setTemperature(40);

		// This should now split off layers one at a time
		// and pass them to the LayerProducer.  At the moment,
		// we just construct a simple test layer and produce that.

		boolean isEvenLayer = true;
		for(double z = 0.0; z < 5.0; z += layerSpacing) {
			reprap.moveTo(reprap.getX(), reprap.getY(), z);
			
			if (reprap.isCancelled())
				break;
			RrPolygonList list = new RrPolygonList();

			// Add a square block
			RrPolygon a = new RrPolygon();
			Rr2Point p1 = new Rr2Point(10, 10);
			Rr2Point p2 = new Rr2Point(20, 10);
			Rr2Point p3 = new Rr2Point(20, 20);
			Rr2Point p4 = new Rr2Point(10, 20);
			a.append(p1, 1);
			a.append(p2, 1);
			a.append(p3, 1);
			a.append(p4, 1);
			list.append(a);
	
			// Add a hex block
			RrPolygon b = new RrPolygon();
			double hexSize = 10;
			double hexLongSize = Math.cos(Math.PI * 30. / 180.0);
			double hexShortSize = Math.sin(Math.PI * 30. / 180.0);
			double hexX = 35, hexY = 15;
			Rr2Point h1 = new Rr2Point(hexX - hexSize / 2.0, hexY - hexSize * hexLongSize);
			Rr2Point h2 = new Rr2Point(hexX - hexSize / 2.0 - hexSize * hexShortSize, hexY);
			Rr2Point h3 = new Rr2Point(hexX - hexSize / 2.0, hexY + hexSize * hexLongSize);
			Rr2Point h4 = new Rr2Point(hexX + hexSize / 2.0, hexY + hexSize * hexLongSize);
			Rr2Point h5 = new Rr2Point(hexX + hexSize / 2.0 + hexSize * hexShortSize, hexY);
			Rr2Point h6 = new Rr2Point(hexX + hexSize / 2.0, hexY - hexSize * hexLongSize);
			b.append(h1, 1);
			b.append(h2, 1);
			b.append(h3, 1);
			b.append(h4, 1);
			b.append(h5, 1);
			b.append(h6, 1);
			list.append(b);
	
			LayerProducer layer = new LayerProducer(reprap, list,
					isEvenLayer?evenHatchDirection:oddHatchDirection);
			layer.plot();
			
			isEvenLayer = !isEvenLayer;
		}
		
		reprap.terminate();

	}

	public double getTotalDistanceMoved() {
		return reprap.getTotalDistanceMoved();
	}
	
	public double getTotalDistanceExtruded() {
		return reprap.getTotalDistanceExtruded();
	}
	
	
	public void dispose() {
		reprap.dispose();
	}
	
}