summaryrefslogtreecommitdiff
path: root/trunk/software/host/src/org/reprap/Attributes.java
blob: ea4d6a82a2966b20c6ae03ddde2195f7b70d95ab (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
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
package org.reprap;

import javax.media.j3d.Appearance;
import javax.media.j3d.BranchGroup;

import org.reprap.devices.GenericExtruder;
import org.reprap.gui.STLObject;

/**
 * Small class to hold RepRap attributes that are attached to
 * Java3D shapes as user data, primarily to record the material
 * that things are made from.
 * 
 * @author adrian
 *
 */
public class Attributes {
	
	/**
	 * The name of the material
	 */
	private String material;
	
	/**
	 * The STLObject of which this is a part
	 */
	private STLObject parent;
	
	/**
	 * Where this is in the STLObject of which it is a part
	 */
	private BranchGroup part;
	
	/**
	 * The appearance (colour) in the loading and simulation windows
	 */
	private Appearance app;
	
	/**
	 * The extruder corresponsing to this material.  This is lazily evaluated
	 * (I.e. it is not set until there are some extruders around to use).
	 */
	private Extruder e;
	
	/**
	 * Constructor - it is permissible to set any argument null.  If you know
	 * what you're doing of course...
	 * @param s The name of the material
	 * @param p Parent STLObject
	 * @param b Where in p
	 * @param a what it looks like
	 */
	public Attributes(String s, STLObject p, BranchGroup b, Appearance a)
	{
		material = s;
		parent = p;
		part = b;
		app = a;
		e = null;
	}
	
	/**
	 * Just say the name of the material
	 */
	public String toString()
	{
		String result = new String();
		result += "Attributes: material is " + material;
		return result;
	}
	
	/**
	 * @return the name of the material
	 */
	public String getMaterial() { return material; }
	
	/**
	 * @return the parent object
	 */	
	public STLObject getParent() { return parent; }
	
	/**
	 * @return the bit of the STLObject that this is
	 */
	public BranchGroup getPart() { return part; }
	
	/**
	 * @return what colour am I?
	 */
	public Appearance getAppearance() { return app; }
	
	/**
	 * Find my extruder in the list (if not known) or just
	 * return it (if known).
	 * @param es The extruders currently in the printer.
	 * @return my extruder
	 */
	public Extruder getExtruder()
	{
		if(e == null)
		{
			Printer p = org.reprap.Main.gui.getPrinter();
			if(p == null)
			{
				System.err.println("Attributes.getExtruder(): null printer!");
				return null;
			}
			e = p.getExtruder(material); 
			if(e == null)
			{
				System.err.println("Attributes.getExtruder(): null extruder for " + material);
				return null;
			}
		}
		return e;
	}
	
	/**
	 * Change the material name
	 * @param s
	 */
	public void setMaterial(String s) 
	{ 
		material = s;
		e = null;
		app = GenericExtruder.getAppearanceFromMaterial(material);
		if(parent != null)
			parent.restoreAppearance();
	}
	
	/**
	 * Change the parent
	 * @param p
	 */
	public void setParent(STLObject p) { parent = p; }
	
	/**
	 * To be used in conjunction with changing the parent
	 * @param b
	 */
	public void setPart(BranchGroup b) { part = b; }
	
	/**
	 * New colour
	 * @param a
	 */
	public void setAppearance(Appearance a) { app = a; }
}