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