001/* 002 * Entity106_12_3DLinearString -- Entity that represents a consecutive series (string) of 3D points. 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 geomss.geom.GeomList; 026import geomss.geom.GeomPoint; 027import geomss.geom.PointString; 028import geomss.geom.Transformable; 029import java.io.IOException; 030import java.io.PrintWriter; 031 032/** 033 * <b><i>COPIOUS DATA ENTITY - LINEAR STRING</i></b> - This entity defines a series of 034 * linear segments along the consecutive points of the path which may be isolated or used 035 * as a component of a Subfigure Entity. The segments may cross, or be coincident with, 036 * each other. Paths may close; i.e., the first path point may be coincident with the 037 * last. Form 12 indicates that the points are 3-dimensional. 038 * 039 * <p> 040 * This entity, when read from an IGES file, is converted to a list of points (a 041 * PointString object). This entity type <b>can</b> 042 * 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 10, 2013 048 * @version February 22, 2025 049 * @see Entity106_CopiousData 050 */ 051public class Entity106_12_3DLinearString extends Entity106_CopiousData { 052 053 /** 054 * Default constructor. 055 * 056 * @param p part to which this entity is contained 057 * @param de Directory Entry for this entity 058 */ 059 public Entity106_12_3DLinearString(Part p, DirEntry de) { 060 super(p, de); 061 062 if (Constants.DEBUG) { 063 System.out.println("Entity106_12 constructor called"); 064 } 065 } 066 067 /** 068 * Create this entity from the specified GeomSS geometry element. 069 * 070 * @param part The Part in which this entity is contained. 071 * @param DEnum The line count from the start of the Directory Entry Section for this 072 * entry (odd number). 073 * @param geom The GeomSS PointString geometry to return an Entity for. 074 */ 075 public Entity106_12_3DLinearString(Part part, int DEnum, PointString geom) { 076 super(part, new DirEntry(106, 12, DEnum, 0, geom.getName())); 077 ip = 2; 078 points.addAll(geom); 079 } 080 081 /** 082 * Returns <code>true</code> if the Entity can be written to an exchange file. 083 * 084 * @return true 085 */ 086 @Override 087 public boolean canWrite() { 088 return true; 089 } 090 091 /** 092 * Write this entities parameter data to the specified PrintWriter. 093 * 094 * @param writer The PrintWriter to write the parameter data for this entity to. 095 * @param PDnum The starting Parameter Data row index number. 096 * @return The Parameter Data row index number for the next row. 097 * @throws java.io.IOException if the parameter data could not be written out. 098 */ 099 @Override 100 public int write(PrintWriter writer, int PDnum) throws IOException { 101 102 // Build up the parameter data string. 103 GeomList<GeomPoint> points2 = (GeomList<GeomPoint>)points.to(Constants.unit); 104 StringBuilder buffer = new StringBuilder(); 105 buffer.append(106); buffer.append(Constants.Delim); 106 buffer.append(ip); buffer.append(Constants.Delim); 107 int n = points2.size(); 108 buffer.append(n); buffer.append(Constants.Delim); 109 for (GeomPoint p : points2) { 110 appendPoint3(buffer, p); 111 } 112 buffer.setLength(buffer.length() - 1); // Replace Delim with Term for last entry. 113 buffer.append(Constants.Term); 114 115 // Write it out. 116 int oldPDnum = PDnum; 117 PDnum = Constants.writeSection(writer, PDnum, Constants.makeSequenceNumber(getDENum()), 118 'P', buffer); 119 120 // Store the PD line number and line count in the directory entry. 121 getDirectoryEntry().setPDNumber(oldPDnum, PDnum - oldPDnum); 122 123 return PDnum; 124 } 125 126 /** 127 * Return a reference to the Transformable GeomElement contained in this IGES Entity. 128 * 129 * @return A reference to the Transformable GeomElement contained in this IGES Entity. 130 */ 131 @Override 132 protected Transformable getGeomElement() { 133 PointString<GeomPoint> str = PointString.newInstance(); 134 int size = points.size(); 135 for (int i = 0; i < size; ++i) { 136 GeomPoint p = (GeomPoint)points.get(i); 137 str.add(p); 138 } 139 return str; 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 "Entity106_12 - Copious Data - 3D Linear String"; 150 } 151 152}