001/* 002 * Entity402_Associativity -- Entity that represents an associativity relationship between entities. 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.*; 027import java.io.IOException; 028import java.io.RandomAccessFile; 029import java.util.ArrayList; 030import java.util.List; 031 032/** 033 * <b><i>ASSOCIATIVITY ENTITY</i></b> - This entity defines an associativity relationship 034 * between other entities. 035 * 036 * <p> 037 * This entity, when read from an IGES file, is converted to a list of geometry objects. 038 * This entity type can not be written out to an IGES file. 039 * </p> 040 * 041 * <p> Modified by: Joseph A. Huwaldt </p> 042 * 043 * @author JDN, AED, Version 1.0 044 * @version September 13, 2016 045 */ 046public abstract class Entity402_Associativity extends GeomSSEntity { 047 048 protected List<Integer> pointers = new ArrayList(); // List of entity DE numbers. 049 050 protected GeometryList geom = GeomList.newInstance(); // List of GeomSS geometry objects. 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 Entity402_Associativity(Part p, DirEntry de) { 059 super(p, de); 060 } 061 062 /** 063 * Checks to see if the entity is correct. No restrictions are imposed. 064 */ 065 @Override 066 public void check() { 067 } 068 069 /** 070 * Read the Parameter Data from the String read in by the superclass. 071 * 072 * @param in input file 073 * @throws java.io.IOException 074 */ 075 @Override 076 public void read(RandomAccessFile in) throws IOException { 077 super.read(in); 078 String s = getPDString(); 079 080 if (Constants.DEBUG) { 081 System.out.println("PD String = \"" + s + "\""); 082 } 083 084 int n = getInt(s); 085 for (int i = 0; i < n; ++i) 086 pointers.add(getInt(s)); 087 088 super.read_additional(); 089 } 090 091 /** 092 * The GeomSS geometry element is created from the IGES parameters when this method is 093 * called. 094 */ 095 @Override 096 void createGeometry() { 097 Part part = getPart(); 098 099 // Loop over all the entities in this association. 100 int n = pointers.size(); 101 for (int i = 0; i < n; ++i) { 102 int deNum = pointers.get(i); 103 Entity entity = part.getEntity(deNum); 104 105 if (entity instanceof GeomSSEntity) { 106 // Found a GeomSS geometry Entity. 107 GeomSSEntity geomEntity = (GeomSSEntity)entity; 108 geomEntity.setUsedInList(true); // Indicate that the entity is used by this association. 109 GeomElement element = geomEntity.getGeomElement(GTransform.IDENTITY); 110 geom.add(element); 111 } 112 } 113 } 114 115 /** 116 * Return a reference to the Transformable GeomElement contained in this IGES Entity. 117 * 118 * @return A reference to the Transformable GeomElement contained in this IGES Entity. 119 */ 120 @Override 121 protected Transformable getGeomElement() { 122 return geom; 123 } 124 125 /** 126 * Dump to String. 127 * 128 * @return String containing the resulting text. 129 */ 130 @Override 131 public String toString() { 132 StringBuilder outStr = new StringBuilder(super.toString()); 133 outStr.append("\n"); 134 135 int n = pointers.size(); 136 outStr.append("n = "); 137 outStr.append(n); 138 outStr.append("\n"); 139 140 for (int i = 0; i < n; i++) { 141 outStr.append("entity("); 142 outStr.append(i); 143 outStr.append(") = "); 144 outStr.append(pointers.get(i)); 145 outStr.append("\n"); 146 } 147 148 return outStr.toString(); 149 } 150 151}