Source code: org/pqt/autorib/instr/InstrAppendNumber.java
1 //AutoRIB
2 // Copyright © 1998 - 2002, P W Quint
3 //
4 // Contact: autorib00@aol.com
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public
8 // License as published by the Free Software Foundation; either
9 // version 2 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
20 package org.pqt.autorib.instr;
21 import java.io.*;
22 import java.util.*;
23 import org.pqt.autorib.tokenizer.*;
24 import org.pqt.autorib.globals.*;
25 import org.pqt.autorib.util.*;
26 import org.pqt.autorib.rib.*;
27 import org.pqt.autorib.tokenizer.*;
28 import org.pqt.autorib.globals.*;
29
30 /** class to handle instruction to append a parameter to a shader. It also
31 * contains a number of static utility functions which are called by the various
32 * map creating instructions (e.g shadowdist) to append map names etc to objects*/
33
34 public class InstrAppendNumber extends InstrRequest {
35 private String shaderType;
36 /** name of the parameter to replace */
37 private String name;
38
39 public InstrAppendNumber()
40 { }
41
42 public InstrAppendNumber(InstrWReader in) throws IOException, FormatException {
43 read(in);
44 }
45
46
47 /** read in the append request in the form
48 * Append type name */
49 public void read(InstrWReader in) throws IOException,
50 FormatException {
51 readRequestName(in);
52 shaderType = in.tokenizer.getString();
53 if (in.inLightBlock)
54 throw new FormatException("AppendNumber cannot be applied to lights",in.tokenizer);
55 else if ((in.inObjectBlock) && (RIBAttributeRec.shaderType(shaderType)
56 < 0))
57 throw new FormatException("Unrecognized shader type",in.tokenizer);
58 name = in.tokenizer.getString();
59 }
60
61 public void write(Writer out) throws IOException {
62 writeRequest(out);
63 out.write("\"" + shaderType + "\" \"" + name + "\" ");
64 }
65
66 /** do the append to an object shader nb. static*/
67 public void doAppend(RIBObjectGroup object, String shaderType,
68 String paramName, int number) {
69 Token paramValue = new Token((float) number);
70 RIBShader rs = object.attributes.getShader(shaderType);
71 if (rs != null) {
72 rs = new RIBShader(rs);
73 if (!rs.params.replace(paramName,paramValue))
74 object.attributes.put(new RIBDeclare(paramName,"uniform float"));
75 object.attributes.put(rs);
76 }
77 }
78
79 public void process(InstrWReader rw, RIBLight light) {
80 }
81
82 public void process(InstrWReader rw, RIBObjectGroup object) {
83 doAppend(object, shaderType, name,
84 rw.nameNumberManager.getNumber(object.attributes.name));
85 }
86
87 }//class
88
89
90