001/*
002 *   Entity404_Drawing  -- This Entity defines a drawing space coordinate system.
003 *
004 *   Copyright (C) 2010-2016, Joseph A. Huwaldt.
005 *   All rights reserved.
006 *   
007 *   This library is free software; you can redistribute it and/or
008 *   modify it under the terms of the GNU Lesser General Public
009 *   License as published by the Free Software Foundation; either
010 *   version 2.1 of the License, or (at your option) any later version.
011 *   
012 *   This library is distributed in the hope that it will be useful,
013 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
014 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
015 *   Lesser General Public License for more details.
016 *
017 *   You should have received a copy of the GNU Lesser General Public License
018 *   along with this program; if not, write to the Free Software
019 *   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
020 *   Or visit:  http://www.gnu.org/licenses/lgpl.html
021 *
022 *   Based on, but heavily modified from, IGESView ( http://ts.nist.gov/Standards/IGES/igesTools.cfm )
023 */
024package geomss.geom.reader.iges;
025
026import java.io.IOException;
027import java.io.RandomAccessFile;
028import java.text.MessageFormat;
029import java.util.ArrayList;
030import java.util.List;
031
032/**
033 * <b><i>DRAWING ENTITY</i></b> - This entity defines drawing space coordinate system. A
034 * View Entity may also be used in conjunction with this entity to position entities in
035 * the defined drawing space. The Drawing Entity specifies a drawing as a collection of
036 * annotation entities i.e., any entity with its Entity Use Flag set to 01) defined in
037 * drawing space, and views (i.e., projections of model space data in view space).
038 * 
039 * <p> Modified by: Joseph A. Huwaldt </p>
040 * 
041 * @author JDN, Version 1.0
042 * @version September 13, 2016
043 */
044public class Entity404_Drawing extends Entity {
045
046    protected int n;                // Number of views
047    protected List<View> views;     // List of views
048    protected int m;                // Number of annotation entities
049    protected List<Integer> dptr;   // List of annotation entities
050
051    /**
052     * Default constructor.
053     *
054     * @param p  part to which this entity is contained
055     * @param de Directory Entry for this entity
056     */
057    public Entity404_Drawing(Part p, DirEntry de) {
058        super(p, de);
059
060        if (Constants.DEBUG) {
061            System.out.println("Entity404 constructor called");
062        }
063
064        views = new ArrayList();
065        dptr = new ArrayList();
066    }
067
068    /**
069     * Checks to see if the entity should be drawn. The following restrictions are
070     * imposed:
071     *
072     * - Number of view pointers shall be 1 - Number of annotation entities shall be 0 -
073     * Number of associativity pointers shall be 0 - Number of property pointers shall be
074     * 0, 1, 2, or 3
075     */
076    @Override
077    public void check() {
078        DirEntry DE = getDirectoryEntry();
079
080        // Number of view pointers shall be 1
081        if (n != 1) {
082            String msg = MessageFormat.format(RESOURCES.getString("numViewPointers"), n);
083            addErrorMessage(getWarningString(msg));
084        }
085
086        // Number of annotation entities shall be 0
087        if (m != 0) {
088            String msg = MessageFormat.format(RESOURCES.getString("numAnnEntities"), m);
089            addErrorMessage(getWarningString(msg));
090        }
091
092        // Number of associativity pointers shall be 0
093        int num_assoc = associativities.size();
094        if (num_assoc != 0) {
095            String msg = MessageFormat.format(RESOURCES.getString("numAssocPointers"), num_assoc);
096            addErrorMessage(getWarningString(msg));
097        }
098
099        // Number of property pointers shall be 0
100        int num_props = properties.size();
101        if ((num_props < 0) || (num_props > 3)) {
102            String msg = MessageFormat.format(RESOURCES.getString("numPropPointers"), num_props);
103            addErrorMessage(getWarningString(msg));
104        }
105
106    }
107
108    /**
109     * Read the Parameter Data from the String read in by the superclass.
110     *
111     * @param in input file
112     * @throws java.io.IOException
113     */
114    @Override
115    public void read(RandomAccessFile in) throws IOException {
116
117        if (Constants.DEBUG) {
118            System.out.println("Entity404.read() called");
119        }
120
121        super.read(in);
122        String s = getPDString();
123
124        if (Constants.DEBUG) {
125            System.out.println("PD String = \"" + s + "\"");
126        }
127
128        n = getInt(s);
129
130        for (int i = 0; i < n; i++) {
131            views.add(new View(getView(s, getDirectoryEntry().getForm())));
132        }
133
134        m = getInt(s);
135
136        for (int i = 0; i < m; i++) {
137            dptr.add(getInt(s));
138        }
139
140        super.read_additional();
141    }
142
143    /**
144     * Returns a short String describing this Entity object's type.
145     *
146     * @return A short String describing this Entity object's type.
147     */
148    @Override
149    public String getTypeString() {
150        return "Entity404 - Drawing";
151    }
152
153    /**
154     * Dump to String.
155     *
156     * @return String containing the resulting text.
157     */
158    @Override
159    public String toString() {
160        StringBuilder outStr = new StringBuilder(super.toString());
161        outStr.append("\n");
162
163        outStr.append("n = ");  outStr.append(n);   outStr.append("\n");
164
165        if (n > 0) {
166            for (int i = 0; i < n; i++) {
167                outStr.append("vptr(");     outStr.append(i);   outStr.append(") =\n");
168                outStr.append(views.get(i).toString());         outStr.append("\n");
169            }
170            outStr.append("\n");
171        }
172
173        if (m > 0) {
174            for (int i = 0; i < m; i++) {
175                outStr.append("dptr(");     outStr.append(i);   outStr.append(") =\n");
176                outStr.append(dptr.get(i).intValue());          outStr.append("\n");
177            }
178            outStr.append("\n");
179        }
180
181        return outStr.toString();
182    }
183
184}