001/* 002 * Entity116_Point -- A Point entity. 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.GeomPoint; 026import geomss.geom.Transformable; 027import java.io.IOException; 028import java.io.PrintWriter; 029import java.io.RandomAccessFile; 030import java.text.MessageFormat; 031 032/** 033 * <b><i>POINT ENTITY</i></b> - This entity defines a point which may be isolated or used 034 * as a component of a Composite Curve Entity or a subfigure. A point is defined by its 035 * coordinates in definition space. 036 * 037 * <p> 038 * This entity type <b>can</b> be written out to an IGES file. 039 * </p> 040 * 041 * <p> Modified by: Joseph A. Huwaldt </p> 042 * 043 * @author JDN, Version 1.0 044 * @version February 22, 2025 045 */ 046public class Entity116_Point extends GeomSSEntity { 047 048 private GeomPoint p; // Point coordinates 049 private int ptr = 0; // Display symbol 050 051 /** 052 * Default constructor. 053 * 054 * @param prt part to which this entity is contained 055 * @param de Directory Entry for this entity 056 */ 057 public Entity116_Point(Part prt, DirEntry de) { 058 super(prt, de); 059 060 if (Constants.DEBUG) { 061 System.out.println("Entity116 constructor called"); 062 } 063 064 } 065 066 /** 067 * Create this entity from the specified GeomSS geometry element. 068 * 069 * @param part The Part in which this entity is contained. 070 * @param DEnum The line count from the start of the Directory Entry Section for this 071 * entry (odd number). 072 * @param geom The GeomSS GeomPoint geometry to return an Entity for. 073 */ 074 public Entity116_Point(Part part, int DEnum, GeomPoint geom) { 075 super(part, new DirEntry(116, 0, DEnum, 0, geom.getName())); 076 p = geom; 077 } 078 079 /** 080 * Checks to see if the entity is correct. The following restrictions are imposed: 081 * 082 * - The Label Display Pointer shall be 0 083 */ 084 @Override 085 public void check() { 086 DirEntry DE = getDirectoryEntry(); 087 088 // DE Label Display Pointer shall be 0 089 if (DE.getLblDsp() != 0) { 090 String msg = MessageFormat.format(RESOURCES.getString("labelDisplay"), DE.getLblDsp()); 091 addErrorMessage(getWarningString(msg)); 092 } 093 094 } 095 096 /** 097 * Read the Parameter Data from the String read in by the superclass. 098 * 099 * @param in input file 100 * @throws java.io.IOException if the parameter data could not be read in. 101 */ 102 @Override 103 public void read(RandomAccessFile in) throws IOException { 104 if (Constants.DEBUG) { 105 System.out.println("Entity116.read() called"); 106 } 107 108 super.read(in); 109 String s = getPDString(); 110 111 if (Constants.DEBUG) { 112 System.out.println("PD String = \"" + s + "\""); 113 } 114 115 p = getPoint3(s); 116 ptr = getInt(s); 117 118 super.read_additional(); 119 } 120 121 /** 122 * The GeomSS geometry element is created from the IGES parameters when this method is 123 * called. 124 */ 125 @Override 126 void createGeometry() throws IOException { 127 // Already done in read(). 128 } 129 130 /** 131 * Return a reference to the Transformable GeomElement contained in this IGES Entity. 132 * 133 * @return A reference to the Transformable GeomElement contained in this IGES Entity. 134 */ 135 @Override 136 protected Transformable getGeomElement() { 137 return p; 138 } 139 140 /** 141 * Returns <code>true</code> if the Entity can be written to an exchange file. 142 * 143 * @return true 144 */ 145 @Override 146 public boolean canWrite() { 147 return true; 148 } 149 150 /** 151 * Write this entities parameter data to the specified PrintWriter. 152 * 153 * @param writer The PrintWriter to write the parameter data for this entity to. 154 * @param PDnum The starting Parameter Data row index number. 155 * @return The Parameter Data row index number for the next row. 156 * @throws java.io.IOException if the parameter data could not be written out. 157 */ 158 @Override 159 public int write(PrintWriter writer, int PDnum) throws IOException { 160 161 // Build up the parameter data string. 162 GeomPoint point = p.to(Constants.unit); 163 StringBuilder buffer = new StringBuilder(); 164 buffer.append(116); buffer.append(Constants.Delim); 165 appendPoint3(buffer, point); 166 buffer.append(ptr); buffer.append(Constants.Term); 167 168 // Write it out. 169 int oldPDnum = PDnum; 170 PDnum = Constants.writeSection(writer, PDnum, Constants.makeSequenceNumber(getDENum()), 171 'P', buffer); 172 173 // Store the PD line number and line count in the directory entry. 174 getDirectoryEntry().setPDNumber(oldPDnum, PDnum - oldPDnum); 175 176 return PDnum; 177 } 178 179 /** 180 * Returns a short String describing this Entity object's type. 181 * 182 * @return A short String describing this Entity object's type. 183 */ 184 @Override 185 public String getTypeString() { 186 return "Entity116 - Point"; 187 } 188 189 /** 190 * Dump to String. 191 * 192 * @return String containing the resulting text. 193 */ 194 @Override 195 public String toString() { 196 StringBuilder outStr = new StringBuilder(super.toString()); 197 outStr.append("\n"); 198 199 outStr.append("p = "); 200 outStr.append(p.toString()); 201 outStr.append("\n"); 202 203 outStr.append("ptr = "); 204 outStr.append(ptr); 205 206 return outStr.toString(); 207 } 208 209}