001/* 002 * Entity106_CopiousData -- Entity that represents a list of data points, 2D, 3D, closed or open. 003 * 004 * Copyright (C) 2010-2016, Joseph A. Huwaldt. 005 * All rights reserved. 006 * 007 * This 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 * This 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 this 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 * 022 * Based on, but heavily modified from, IGESView ( http://ts.nist.gov/Standards/IGES/igesTools.cfm ) 023 */ 024package geomss.geom.reader.iges; 025 026import geomss.geom.GeomList; 027import geomss.geom.Point; 028import geomss.geom.Transformable; 029import geomss.geom.Vector; 030import java.io.IOException; 031import java.io.RandomAccessFile; 032import java.text.MessageFormat; 033import javax.measure.quantity.Length; 034 035/** 036 * <b><i>COPIOUS DATA ENTITY</i></b> - This entity is a list of data points, either 2D or 037 * 3D, closed or open. 038 * 039 * <p> 040 * All supported forms of this entity, when read from an IGES file, are converted to a 041 * list of points or vectors as appropriate. 042 * </p> 043 * 044 * <p> Modified by: Joseph A. Huwaldt </p> 045 * 046 * @author JDN, AED, Version 1.0 047 * @version September 13, 2016 048 */ 049public abstract class Entity106_CopiousData extends GeomSSEntity { 050 051 protected int ip = 2; // Interpretation flag 052 protected GeomList points = GeomList.newInstance(); // Map all forms to a list of 3D points. 053 054 /** 055 * Default constructor. 056 * 057 * @param p part to which this entity is contained 058 * @param de Directory Entry for this entity 059 */ 060 public Entity106_CopiousData(Part p, DirEntry de) { 061 super(p, de); 062 } 063 064 /** 065 * Checks to see if the entity is correct. The following restrictions are imposed: 066 * 067 * - The Label Display Pointer shall be 0 068 */ 069 @Override 070 public void check() { 071 DirEntry DE = getDirectoryEntry(); 072 073 // DE Label Display shall be 0 074 if (DE.getLblDsp() != 0) { 075 String msg = MessageFormat.format(RESOURCES.getString("labelDisplay"), DE.getLblDsp()); 076 addErrorMessage(getWarningString(msg)); 077 } 078 } 079 080 /** 081 * Read the Parameter Data from the String read in by the superclass. 082 * 083 * @param in input file 084 * @throws java.io.IOException 085 */ 086 @Override 087 public void read(RandomAccessFile in) throws IOException { 088 089 super.read(in); 090 String s = getPDString(); 091 092 if (Constants.DEBUG) { 093 System.out.println("PD String = \"" + s + "\""); 094 } 095 096 ip = getInt(s); 097 int n = getInt(s); 098 099 switch (ip) { 100 case 1: // x,y pairs, common z 101 double z = getReal(s); 102 //if (Math.abs(z) < Constants.Grain) z = 0; 103 104 for (int idx = 0; idx < n; idx++) { 105 Point p = getPoint2(s); 106 points.add(p); 107 } 108 break; 109 110 case 2: // x,y,z coordinates 111 for (int idx = 0; idx < n; idx++) { 112 Point p = getPoint3(s); 113 points.add(p); 114 } 115 break; 116 117 case 3: // x,y,z coordinates and i,j,k vectors 118 for (int idx = 0; idx < n; idx++) { 119 Point p = getPoint3(s); 120 121 double i = getReal(s); 122 double j = getReal(s); 123 double k = getReal(s); 124 125 Vector<Length> v = Vector.valueOf(Constants.unit, i, j, k); 126 v.setOrigin(p); 127 points.add(v); 128 } 129 break; 130 131 default: 132 throw new IOException(MessageFormat.format(RESOURCES.getString("unknownDataTypeCode"), 133 ip, getTypeString())); 134 } 135 136 super.read_additional(); 137 } 138 139 /** 140 * The GeomSS geometry element is created from the IGES parameters when this method is 141 * called. 142 */ 143 @Override 144 void createGeometry() throws IOException { 145 // Already done in read(). 146 } 147 148 /** 149 * Return a reference to the Transformable GeomElement contained in this IGES Entity. 150 * 151 * @return A reference to the Transformable GeomElement contained in this IGES Entity. 152 */ 153 @Override 154 protected Transformable getGeomElement() { 155 return points; 156 } 157 158 /** 159 * Dump to String. 160 * 161 * @return String containing the resulting text. 162 */ 163 @Override 164 public String toString() { 165 StringBuilder outStr = new StringBuilder(super.toString()); 166 outStr.append("\n"); 167 168 int n = points.size(); 169 outStr.append("ip = "); outStr.append(ip); outStr.append("\n"); 170 outStr.append("n = "); outStr.append(n); outStr.append("\n"); 171 172 for (int i = 0; i < n; i++) { 173 outStr.append(i); 174 outStr.append(": "); 175 outStr.append(points.get(i).toString()); 176 outStr.append("\n"); 177 } 178 179 return outStr.toString(); 180 } 181 182}