001/* 002 * Entity108_Plane -- Entity that represents a plane in 3D space. 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 */ 021package geomss.geom.reader.iges; 022 023import geomss.geom.*; 024import java.io.IOException; 025import java.io.RandomAccessFile; 026import java.text.MessageFormat; 027import javax.measure.quantity.Dimensionless; 028 029/** 030 * <b><i>PLANE ENTITY</i></b> - This entity represents a plane. 031 * 032 * <p> 033 * When reading in this entity, all plane parameters are stored in the user data with the 034 * prefix "IGES_108_" followed by the parameter name. 035 * </p> 036 * 037 * <p> Modified by: Joseph A. Huwaldt </p> 038 * 039 * @author Joseph A. Huwaldt, Date: September 6, 2010 040 * @version February 22, 2025 041 */ 042public abstract class Entity108_Plane extends GeomSSEntity { 043 044 protected double A, B, C, D; // Plane coefficients. 045 protected int ptr; // Pointer boundary entity or zero. 046 protected double xt, yt, zt; // Coordinates of location point for display symbol. 047 protected double symbolSize = 0.01; // Size parameter for the display symbol. 048 049 protected GeomPlane plane; // The GeomSS plane. 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 Entity108_Plane(Part p, DirEntry de) { 058 super(p, de); 059 } 060 061 /** 062 * Checks to see if the entity is correct. The following restrictions are imposed: 063 * - The Label Display Pointer shall be 0. 064 */ 065 @Override 066 public void check() { 067 DirEntry DE = getDirectoryEntry(); 068 069 // DE Label Display shall be 0 070 if (DE.getLblDsp() != 0) { 071 String msg = MessageFormat.format(RESOURCES.getString("labelDisplay"), DE.getLblDsp()); 072 addErrorMessage(getWarningString(msg)); 073 } 074 } 075 076 /** 077 * Read the Parameter Data from the String read in by the superclass. 078 * 079 * @param in input file 080 * @throws java.io.IOException if the parameter data could not be read in. 081 */ 082 @Override 083 public void read(RandomAccessFile in) throws IOException { 084 085 super.read(in); 086 String s = getPDString(); 087 088 if (Constants.DEBUG) { 089 System.out.println("PD String = \"" + s + "\""); 090 } 091 092 // Read in the plane coefficients. 093 A = getReal(s); 094 B = getReal(s); 095 C = getReal(s); 096 D = getReal(s); 097 098 // Get the pointer to a bounding curve. 099 ptr = getInt(s); 100 101 // Get the location for the display symbol (in the plane). 102 xt = getReal(s); 103 yt = getReal(s); 104 zt = getReal(s); 105 106 // Get the size of the display symbol. 107 symbolSize = getReal(s); 108 109 super.read_additional(); 110 } 111 112 /** 113 * The GeomSS geometry element is created from the IGES parameters when this method is 114 * called. 115 */ 116 @Override 117 void createGeometry() { 118 // Create the GeomSS plane. The "D" value is redundant. Using xt,yt,zt to create 119 // the plane as this contains more information than D alone. 120 Vector<Dimensionless> nhat = Vector.valueOf(A, B, C).toUnitVector(); 121 Point refPoint = Point.valueOf(xt, yt, zt, Constants.unit); 122 plane = Plane.valueOf(nhat, refPoint); 123 } 124 125 /** 126 * Method used to apply IGES meta-data to GeomSS elements. This implementation stores 127 * in the user data, in addition to the header info, all the parameter information for 128 * this entity type prefixed by "IGES_108_". 129 */ 130 @Override 131 protected void applyMetaData(GeomElement element) { 132 super.applyMetaData(element); 133 element.putUserData("IGES_108_A", A); 134 element.putUserData("IGES_108_B", B); 135 element.putUserData("IGES_108_C", C); 136 element.putUserData("IGES_108_D", D); 137 element.putUserData("IGES_108_X", xt); 138 element.putUserData("IGES_108_Y", yt); 139 element.putUserData("IGES_108_Z", zt); 140 element.putUserData("IGES_108_SIZE", symbolSize); 141 } 142 143 /** 144 * Return a reference to the Transformable GeomElement contained in this IGES Entity. 145 * 146 * @return A reference to the Transformable GeomElement contained in this IGES Entity. 147 */ 148 @Override 149 protected Transformable getGeomElement() { 150 return plane; 151 } 152 153 /** 154 * Dump to String. 155 * 156 * @return String containing the resulting text. 157 */ 158 @Override 159 public String toString() { 160 StringBuilder outStr = new StringBuilder(super.toString()); 161 outStr.append("\n"); 162 163 outStr.append("A = "); outStr.append(A); outStr.append("\n"); 164 outStr.append("B = "); outStr.append(B); outStr.append("\n"); 165 outStr.append("C = "); outStr.append(C); outStr.append("\n"); 166 outStr.append("D = "); outStr.append(D); outStr.append("\n"); 167 outStr.append("ptr = "); outStr.append(ptr); outStr.append("\n"); 168 outStr.append("x = "); outStr.append(xt); outStr.append("\n"); 169 outStr.append("y = "); outStr.append(yt); outStr.append("\n"); 170 outStr.append("z = "); outStr.append(zt); outStr.append("\n"); 171 outStr.append("size = "); outStr.append(symbolSize); outStr.append("\n"); 172 173 return outStr.toString(); 174 } 175 176}