001/*
002 *   Entity118_1_RuledSurface  -- An entity representing a Parametric Space Ruled Surface Entity.
003 *
004 *   Copyright (C) 2013-2016, 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.Curve;
025import geomss.geom.GTransform;
026import geomss.geom.GeomElement;
027import geomss.geom.LoftedSurface;
028import geomss.geom.nurbs.NurbsCurve;
029import jahuwaldt.js.param.Parameter;
030import java.io.IOException;
031import javax.measure.quantity.Length;
032
033/**
034 * <b><i>RULED SURFACE ENTITY</i></b> - This entity represents a ruled or 2-curve linearly
035 * lofted surface. A ruled surface is formed by moving a line connecting points of equal
036 * relative parametric value (Form 1) on two parametric curves from a start point to a
037 * terminate point on the curves.
038 * 
039 * <p>
040 * This entity, when read from an IGES file, is converted to a LoftedSurface surface. This
041 * entity type can not be written out to an IGES file.
042 * </p>
043 *
044 * <p> Modified by: Joseph A. Huwaldt </p>
045 * 
046 * @author Joseph A. Huwaldt, Date: March 11, 2013
047 * @version September 13, 2016
048 */
049public class Entity118_1_RuledSurface extends Entity118_RuledSurface {
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 Entity118_1_RuledSurface(Part p, DirEntry de) {
058        super(p, de);
059
060        if (Constants.DEBUG) {
061            System.out.println("Entity118_1 constructor called");
062        }
063
064    }
065
066    /**
067     * The GeomSS geometry element is created from the IGES parameters when this method is
068     * called.
069     */
070    @Override
071    void createGeometry() throws IOException {
072        Part part = getPart();
073        Parameter<Length> tol = Parameter.valueOf(Constants.Grain, Constants.unit);
074
075        //  Get the member curves.
076        Entity crv1_entity = part.getEntity(DE1);
077        Entity crv2_entity = part.getEntity(DE2);
078        if (crv1_entity instanceof GeomSSEntity && crv2_entity instanceof GeomSSEntity) {
079            GeomSSEntity gcrv1_entity = (GeomSSEntity)crv1_entity;
080            gcrv1_entity.setUsedInList(true);   //  Indicate that the entity is used by this association.
081            GeomSSEntity gcrv2_entity = (GeomSSEntity)crv2_entity;
082            gcrv2_entity.setUsedInList(true);   //  Indicate that the entity is used by this association.
083
084            GeomElement elem1 = gcrv1_entity.getGeomElement(GTransform.IDENTITY);
085            GeomElement elem2 = gcrv2_entity.getGeomElement(GTransform.IDENTITY);
086            if (elem1 != null && elem2 != null && elem1 instanceof Curve && elem2 instanceof Curve) {
087                //  Convert member curves to NURBS
088                NurbsCurve C1 = ((Curve)elem1).toNurbs(tol);
089                NurbsCurve C2 = ((Curve)elem2).toNurbs(tol);
090
091                //  Deal with the direction flag.
092                if (DIRFLG == 1) {
093                    C2 = C2.reverse();
094                }
095
096                //  Create the ruled/lofted surface.
097                srf = LoftedSurface.valueOf(1, C1, C2);
098            }
099        }
100
101    }
102
103    /**
104     * Returns a short String describing this Entity object's type.
105     *
106     * @return A short String describing this Entity object's type.
107     */
108    @Override
109    public String getTypeString() {
110        return "Entity118_1 - Ruled Surface";
111    }
112
113    /**
114     * Dump to String.
115     *
116     * @return String containing the resulting text.
117     */
118    @Override
119    public String toString() {
120        StringBuilder outStr = new StringBuilder(super.toString());
121        outStr.append("\n");
122
123        return outStr.toString();
124    }
125
126}