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