001/*
002 *   Entity408_SingularSubfigure  -- Entity that represents a singular subfigure.
003 *
004 *   Copyright (C) 2012-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 */
022package geomss.geom.reader.iges;
023
024import geomss.geom.*;
025import java.io.IOException;
026import java.io.RandomAccessFile;
027
028/**
029 * <b><i>SINGULAR SUBFIGURE INSTANCE ENTITY</i></b> - This entity defines the occurrence
030 * of a single instance of the defined subfigure.
031 *
032 * <p>
033 * This entity, when read from an IGES file, is converted to a list of geometry objects.
034 * This entity type can not be written out to an IGES file.
035 * </p>
036 *
037 * <p> Modified by: Joseph A. Huwaldt </p>
038 *
039 * @author Joseph A. Huwaldt, Date: January 31, 2012
040 * @version September 13, 2016
041 */
042public class Entity408_SingularSubfigure extends GeomSSEntity {
043
044    protected int deNum;                                    //  Entity DE number of subfigure.
045    protected GeometryList geom = GeomList.newInstance();   //  List of GeomSS geometry objects.
046
047    /**
048     * Default constructor.
049     *
050     * @param p  part to which this entity is contained
051     * @param de Directory Entry for this entity
052     */
053    public Entity408_SingularSubfigure(Part p, DirEntry de) {
054        super(p, de);
055
056        if (Constants.DEBUG) {
057            System.out.println("Entity408 constructor called");
058        }
059    }
060
061    /**
062     * Checks to see if the entity is correct. No restrictions are imposed.
063     */
064    @Override
065    public void check() {
066    }
067
068    /**
069     * Read the Parameter Data from the String read in by the superclass.
070     *
071     * @param in input file
072     * @throws java.io.IOException
073     */
074    @Override
075    public void read(RandomAccessFile in) throws IOException {
076        super.read(in);
077        String s = getPDString();
078
079        if (Constants.DEBUG) {
080            System.out.println("PD String = \"" + s + "\"");
081        }
082
083        deNum = getInt(s);      //  Get pointer to the subfigure DE number.
084
085        super.read_additional();
086    }
087
088    /**
089     * The GeomSS geometry element is created from the IGES parameters when this method is
090     * called.
091     */
092    @Override
093    void createGeometry() {
094        Part part = getPart();
095
096        Entity entity = part.getEntity(deNum);
097
098        if (entity instanceof GeomSSEntity) {
099            //  Found a GeomSS geometry Entity.
100            GeomSSEntity geomEntity = (GeomSSEntity)entity;
101            geomEntity.setUsedInList(true); //  Indicate that the entity is used by this association.
102            GeomElement element = geomEntity.getGeomElement(GTransform.IDENTITY);
103            geom.add(element);
104        }
105    }
106
107    /**
108     * Return a reference to the Transformable GeomElement contained in this IGES Entity.
109     *
110     * @return A reference to the Transformable GeomElement contained in this IGES Entity.
111     */
112    @Override
113    protected Transformable getGeomElement() {
114        return geom;
115    }
116
117    /**
118     * Dump to String.
119     *
120     * @return String containing the resulting text.
121     */
122    @Override
123    public String toString() {
124        StringBuilder outStr = new StringBuilder(super.toString());
125        outStr.append("\n");
126
127        outStr.append("subfigure  = "); outStr.append(deNum);   outStr.append("\n");
128
129        return outStr.toString();
130    }
131
132    /**
133     * Returns a short String describing this Entity object's type.
134     *
135     * @return A short String describing this Entity object's type.
136     */
137    @Override
138    public String getTypeString() {
139        return "Entity408 - Singular Subfigure Definition";
140    }
141
142}