Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/pqt/autorib/rib/RIBDefaultPrimitive.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.rib;
21  
22  import java.util.*;
23  import java.io.*;
24  
25  import org.pqt.autorib.tokenizer.*;
26  import org.pqt.autorib.globals.*;
27  import org.pqt.autorib.util.*;
28  
29  /** this handles all the primitives that do not have their own
30   *  separate class, it handles everything correctly for primitives that obey
31   *  the following rules: they are defined by "P" or "Pw" control points, their 
32   *  parameters may start with a string (such as subdivision mesh) but must
33   *  contain no other strings as part of the main arguments (though arrays of
34   *  strings are allowed and, of course, the general parameters contain strings
35   *  as parameter names). */
36  public class RIBDefaultPrimitive extends RIBPrimitive {
37      
38      /** used for the initial string parameter if there is one*/
39      private String type = null;
40      
41      /** true if this primitive has an initial string parameter*/
42      private boolean hasInitialStringParam = false;
43      
44      /** used for other parameters other than the general parameters*/
45      private Vector content;
46      
47      
48      RIBDefaultPrimitive() {
49          super();
50      }
51      
52      /** Usual constructor
53       *@param in the stream to read from
54       *@param hasInitialStringParam true if the first parameter of this primitive
55       *should be a string*/
56      RIBDefaultPrimitive(Tokenizer in, boolean hasInitialStringParam) 
57          throws FormatException, IOException {
58          this();
59          this.hasInitialStringParam = hasInitialStringParam;
60          read(in);
61      }
62      
63      RIBDefaultPrimitive(Tokenizer in) 
64          throws FormatException, IOException {
65          this(in, false);
66      }
67      
68      /** Write the contents of the RIBCall to a stream
69       * @param out the RIBWReader to write to */
70      public void write(Writer out) throws IOException {
71              Token.write(out, requestName + ' ');
72              if (type != null) 
73                  Token.write(out,"\"" + type + "\" ");
74              Enumeration i = content.elements();
75              while(i.hasMoreElements())
76                  ((Token)i.nextElement()).write(out);
77              params.write(out);
78          if (RIBGlobals.DEBUGBOUNDINGBOX) {
79              Token.writeln(out);
80              Token.writeln(out,"Opacity [0.5 0.5 0.5]");
81              bounds = calculateLocalPPwBounds(params); 
82              Point points[] = bounds.getBoundsAsPoints();
83              RIBPointsPolygonsSubdiv box = new RIBPointsPolygonsSubdiv(points[0], points[1]);
84              box.debugWrite(out);
85          }
86      }
87      
88      public void writeOther(java.io.Writer out) throws java.io.IOException { }
89      
90      /** read an RIB call and store it
91       * @param in a RIBWReader object linked to the input file*/
92      public void read(Tokenizer in) throws IOException, FormatException {
93          content = new Vector(5);
94          boolean doneAllButParams = false;
95          boolean doneAll = false;
96          int t;
97          readRequestName(in);
98          //first read in the string parameter for those that have
99          //an initial string parameter - if we don't do this
100         //it confuses things later
101         /*if ((requestID == RIBGlobals.PATCH) ||
102         (requestID == RIBGlobals.PATCHMESH) ||
103         (requestID == RIBGlobals.SUBDIVISIONMESH) ||
104         (requestID == RIBGlobals.CURVES))*/
105         if (hasInitialStringParam)
106             type = in.getString();
107         //now we read in everything leading up to the parameters
108         //the start of the parameters is recognized by a string
109         while (!doneAll && !doneAllButParams) {
110             t = in.getToken();
111             if ((t == Token.EOF) ||
112             (t == Token.REQUEST) ||
113             (t == Token.CLOSEBRACE)) {
114                 //we've reached the end of this request
115                 doneAll = true;
116                 in.pushBack();
117             }
118             else if (t == Token.STRING) {
119                 //we've hit the start of the parameter list
120                 doneAllButParams = true;
121                 in.pushBack();
122             }
123             else
124                 content.addElement(in.token);
125         }
126         if (!doneAll)
127             params.read(in);
128     }
129     
130     public Bounds3D getLocalBounds() {
131         if (bounds == null)
132             bounds = calculateLocalPPwBounds(params);
133         return bounds;
134     }
135     
136 }
137 
138 
139