001/*
002 *   Entity118_RuledSurface  -- An entity representing a Ruled Surface Entity.
003 *
004 *   Copyright (C) 2013-2025, Joseph A. Huwaldt.
005 *   All rights reserved.
006 *   
007 *   part 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 *   part 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 part 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.GeomElement;
025import geomss.geom.LoftedSurface;
026import geomss.geom.Transformable;
027import java.io.IOException;
028import java.io.RandomAccessFile;
029
030/**
031 * <b><i>RULED SURFACE ENTITY</i></b> - This entity represents a ruled or 2-curve linearly
032 * lofted surface. A ruled surface is formed by moving a line connecting points of equal
033 * relative arc length (Form 0) or equal relative parametric value (Form 1) on two
034 * parametric curves from a start point to a terminate point on the curves.
035 * 
036 * <p>
037 * This entity, when read from an IGES file, is converted to a LoftedSurface surface. This
038 * entity type can not be written out to an IGES file. The surface parameters are stored
039 * in the user data with the prefix "IGES_118_" followed by the parameter name.
040 * </p>
041 *
042 * <p> Modified by: Joseph A. Huwaldt </p>
043 * 
044 * @author Joseph A. Huwaldt, Date: March 11, 2013
045 * @version February 22, 2025
046 */
047public abstract class Entity118_RuledSurface extends GeomSSEntity {
048
049    protected int DE1;              //  Pointer to the DE of the first curve entity
050    protected int DE2;              //  Pointer to the DE of the second curve entity
051    protected int DIRFLG = 0;       //  Direction flag (0=Join first to first, last to last; 1=Join first to last, last to first)
052    protected int DEVFLG = 0;       //  Developable surface flag (1= Developable, 0=Possibly not)
053
054    protected LoftedSurface srf;    //  The GeomSS surface this entity represents.
055
056    /**
057     * Default constructor.
058     *
059     * @param p  part to which this entity is contained
060     * @param de Directory Entry for this entity
061     */
062    public Entity118_RuledSurface(Part p, DirEntry de) {
063        super(p, de);
064
065        if (Constants.DEBUG) {
066            System.out.println("Entity118_RuledSurface constructor called");
067        }
068
069    }
070
071    /**
072     * Checks to see if the entity is correct.
073     */
074    @Override
075    public void check() {
076    }
077
078    /**
079     * Read the Parameter Data from the String read in by the superclass.
080     *
081     * @param in input file
082     * @throws java.io.IOException if the parameter data could not be read in.
083     */
084    @Override
085    public void read(RandomAccessFile in) throws IOException {
086
087        if (Constants.DEBUG) {
088            System.out.println("Entity118_RuledSurface.read() called");
089        }
090
091        super.read(in);
092        String s = getPDString();
093
094        if (Constants.DEBUG) {
095            System.out.println("PD String = \"" + s + "\"");
096        }
097
098        DE1 = getInt(s);            //  Pointer to the DE of the first curve entity
099        DE2 = getInt(s);            //  Pointer to the DE of the second curve entity
100        DIRFLG = getInt(s);         //  Direction flag (0=Join first to first, last to last; 1=Join first to last, last to first)
101        DEVFLG = getInt(s);         //  Developable surface flag (1= Developable, 0=Possibly not)
102
103        super.read_additional();
104    }
105
106    /**
107     * Method used to apply IGES meta-data to GeomSS elements. This implementation stores
108     * in the user data, in addition to the header info, all the parameter information for
109     * this entity type prefixed by "IGES_118_".
110     */
111    @Override
112    protected void applyMetaData(GeomElement element) {
113        super.applyMetaData(element);
114        element.putUserData("IGES_118_DIRFLG", DIRFLG);
115        element.putUserData("IGES_118_DEVFLG", DEVFLG);
116        element.putUserData("IGES_U0", ZERO);
117        element.putUserData("IGES_U1", ONE);
118        element.putUserData("IGES_V0", ZERO);
119        element.putUserData("IGES_V1", ONE);
120    }
121
122    /**
123     * Return a reference to the Transformable GeomElement contained in this IGES Entity.
124     *
125     * @return A reference to the Transformable GeomElement contained in this IGES Entity.
126     */
127    @Override
128    protected Transformable getGeomElement() {
129        return srf;
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 "Entity118 - Ruled Surface";
140    }
141
142    /**
143     * Dump to String.
144     *
145     * @return String containing the resulting text.
146     */
147    @Override
148    public String toString() {
149        StringBuilder outStr = new StringBuilder(super.toString());
150        outStr.append("\n");
151
152        return outStr.toString();
153    }
154
155}