[Bprocessor-commit] model/src/net/sourceforge/bprocessor/model Space.java, 1.182, 1.183 Persistence
Status: Pre-Alpha
Brought to you by:
henryml
Update of /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv15661/src/net/sourceforge/bprocessor/model Modified Files: Space.java Persistence.java Surface.java Material.java Defaults.java Project.java Log Message: Changed material to be placed in the project not in the space, later on there should be a material attached to a space though to make things easier. Made the change to the persistence and all using classes as well Index: Surface.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Surface.java,v retrieving revision 1.192 retrieving revision 1.193 diff -C2 -d -r1.192 -r1.193 *** Surface.java 9 Oct 2007 14:02:16 -0000 1.192 --- Surface.java 15 Oct 2007 12:41:24 -0000 1.193 *************** *** 1334,1338 **** */ public Material getFrontMaterial() { - return frontMaterial; } --- 1334,1337 ---- *************** *** 1852,1858 **** } } else if (a.getName().equals("Front Material")) { ! setFrontMaterial((Material) a.getValue()); } else if (a.getName().equals("Back Material")) { ! setBackMaterial((Material) a.getValue()); } else if (a.getName().equals("Holes")) { continue; --- 1851,1871 ---- } } else if (a.getName().equals("Front Material")) { ! if (a.getValue() instanceof String) { ! String s = (String)a.getValue(); ! for (Material m : Project.getInstance().getMaterials()) { ! if (s.equalsIgnoreCase(m.getName())) { ! setFrontMaterial(m); ! } ! } ! } } else if (a.getName().equals("Back Material")) { ! if (a.getValue() instanceof String) { ! String s = (String)a.getValue(); ! for (Material m : Project.getInstance().getMaterials()) { ! if (s.equalsIgnoreCase(m.getName())) { ! setBackMaterial(m); ! } ! } ! } } else if (a.getName().equals("Holes")) { continue; *************** *** 1885,1893 **** } else { if (getFrontDomain().isConstructionSpace()) { ! res.add(new Attribute("Front Material", new Material("", Defaults.getFrontColor()))); } else if (getFrontDomain().isFunctionalSpace()) { ! res.add(new Attribute("Front Material", new Material("", Defaults.getBackColor()))); } else { ! res.add(new Attribute("Front Material", new Material("", Defaults.getNoneColor()))); } } --- 1898,1906 ---- } else { if (getFrontDomain().isConstructionSpace()) { ! res.add(new Attribute("Front Material", Defaults.getFrontMaterial())); } else if (getFrontDomain().isFunctionalSpace()) { ! res.add(new Attribute("Front Material", Defaults.getBackMaterial())); } else { ! res.add(new Attribute("Front Material", Defaults.getNoneMaterial())); } } *************** *** 1903,1911 **** } else { if (getBackDomain().isConstructionSpace()) { ! res.add(new Attribute("Back Material", new Material("", Defaults.getFrontColor()))); } else if (getBackDomain().isFunctionalSpace()) { ! res.add(new Attribute("Back Material", new Material("", Defaults.getBackColor()))); } else { ! res.add(new Attribute("Back Material", new Material("", Defaults.getNoneColor()))); } } --- 1916,1924 ---- } else { if (getBackDomain().isConstructionSpace()) { ! res.add(new Attribute("Back Material", Defaults.getFrontMaterial())); } else if (getBackDomain().isFunctionalSpace()) { ! res.add(new Attribute("Back Material", Defaults.getBackMaterial())); } else { ! res.add(new Attribute("Back Material", Defaults.getNoneMaterial())); } } Index: Material.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Material.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** Material.java 16 Apr 2007 15:55:22 -0000 1.9 --- Material.java 15 Oct 2007 12:41:24 -0000 1.10 *************** *** 7,11 **** --- 7,15 ---- package net.sourceforge.bprocessor.model; + import java.awt.Color; + import java.awt.color.ColorSpace; import java.io.Serializable; + import java.util.LinkedList; + import java.util.List; /** *************** *** 17,30 **** * usage="read-write" */ ! public class Material implements Serializable { /** The name of the material */ private String name; - /** The color of the material */ - private float[] color; - /** The id */ private Long id; /** --- 21,43 ---- * usage="read-write" */ ! public class Material extends Entity implements Parametric, Serializable { /** The name of the material */ private String name; /** The id */ private Long id; + + private float[] ambientColor; + + private float[] diffuseColor; + + private float[] specularColor; + + private double alpha; + + private double shininess; + + private double illumination; /** *************** *** 33,38 **** --- 46,58 ---- public Material() { setColor(0, 0, 0); + setAmbientColor(new float[]{0.2f, 0.2f, 0.2f}); + setDiffuseColor(new float[]{0.8f, 0.8f, 0.8f}); + setSpecularColor(new float[]{1.0f, 1.0f, 1.0f}); + setAlpha(1.0); + setShininess(0.0); + setIllumination(0.0); } + /** * Constructor for Material *************** *** 41,53 **** */ public Material(String name, float[] color3fv) { ! setName(name); if (color3fv != null) { ! setColor(color3fv); ! } else { ! setColor(0, 0, 0); } } /** * Get the id * @return The id --- 61,120 ---- */ public Material(String name, float[] color3fv) { ! this(); ! this.setName(name); if (color3fv != null) { ! this.setColor(color3fv); } } /** + * Set the degree of illumination + * @param d the illumination degree + */ + public void setIllumination(double d) { + this.illumination = d; + } + + /** + * Set the ambient color of the material + * @param fs The Color + */ + public void setAmbientColor(float[] fs) { + ambientColor = fs; + } + + /** + * Set the diffuse color of the material + * @param fs The Color + */ + public void setDiffuseColor(float[] fs) { + diffuseColor = fs; + } + + /** + * Set the specular color of the material + * @param fs The Color + */ + public void setSpecularColor(float[] fs) { + specularColor = fs; + } + + /** + * Set the alpha of the material + * @param alpha The Color + */ + public void setAlpha(double alpha) { + this.alpha = alpha; + } + + /** + * Set the shininess of the material + * @param value The degree of shininess + */ + public void setShininess(double value) { + this.shininess = value; + } + + /** * Get the id * @return The id *************** *** 91,97 **** */ public void setColor(float[] color3fv) { ! if (color3fv.length >= 3) { ! setColor(color3fv[0], color3fv[1], color3fv[2]); ! } } --- 158,162 ---- */ public void setColor(float[] color3fv) { ! setDiffuseColor(color3fv); } *************** *** 103,112 **** */ public void setColor(float r, float g, float b) { ! if (this.color == null) { ! this.color = new float[3]; } ! this.color[0] = r; ! this.color[1] = g; ! this.color[2] = b; } --- 168,177 ---- */ public void setColor(float r, float g, float b) { ! if (this.diffuseColor == null) { ! this.diffuseColor = new float[3]; } ! this.diffuseColor[0] = r; ! this.diffuseColor[1] = g; ! this.diffuseColor[2] = b; } *************** *** 117,121 **** */ public float[] getColor() { ! return (float[]) color.clone(); } } --- 182,289 ---- */ public float[] getColor() { ! return (float[]) diffuseColor.clone(); ! } ! ! /** ! * @return the alpha ! */ ! public double getAlpha() { ! return alpha; ! } ! ! /** ! * @return the ambientColor ! */ ! public float[] getAmbientColor() { ! return ambientColor; ! } ! ! /** ! * @return the diffuseColor ! */ ! public float[] getDiffuseColor() { ! return diffuseColor; ! } ! ! /** ! * @return the illumination ! */ ! public double getIllumination() { ! return illumination; ! } ! ! /** ! * @return the shininess ! */ ! public double getShininess() { ! return shininess; ! } ! ! /** ! * @return the specularColor ! */ ! public float[] getSpecularColor() { ! return specularColor; ! } ! ! /** ! * {@inheritDoc} ! */ ! @Override ! public void delete() { ! this.setId(null); ! Project.getInstance().remove(this); ! } ! ! /** ! * {@inheritDoc} ! */ ! public List<Attribute> getAttributes() { ! LinkedList<Attribute> res = new LinkedList<Attribute>(); ! res.add(new Attribute("Name", getName(), true)); ! res.add(new Attribute("Id", getId().toString(), false)); ! res.add(new Attribute("diffuseColor", ! new Color(ColorSpace.getInstance(ColorSpace.CS_sRGB), getDiffuseColor(), 1.0f))); ! res.add(new Attribute("ambientColor", ! new Color(ColorSpace.getInstance(ColorSpace.CS_sRGB), getAmbientColor(), 1.0f))); ! res.add(new Attribute("specularColor", ! new Color(ColorSpace.getInstance(ColorSpace.CS_sRGB), getSpecularColor(), 1.0f))); ! res.add(new Attribute("Aplha", alpha)); ! res.add(new Attribute("Shininess", shininess)); ! res.add(new Attribute("Illumination", illumination)); ! return res; ! } ! ! /** ! * {@inheritDoc} ! */ ! public String getGeneralName() { ! return "Material"; ! } ! ! /** ! * {@inheritDoc} ! */ ! public void setAttributes(List<Attribute> attributes) { ! for (Attribute a : attributes) { ! if (a.getName().equalsIgnoreCase("name")) { ! setName((String)a.getValue()); ! } else if (a.getName().equalsIgnoreCase("diffusecolor")) { ! Color c = (Color)a.getValue(); ! setDiffuseColor(c.getColorComponents(null)); ! } else if (a.getName().equalsIgnoreCase("ambientcolor")) { ! Color c = (Color)a.getValue(); ! setAmbientColor(c.getColorComponents(null)); ! } else if (a.getName().equalsIgnoreCase("specularcolor")) { ! Color c = (Color)a.getValue(); ! setSpecularColor(c.getColorComponents(null)); ! } else if (a.getName().equalsIgnoreCase("alpha")) { ! setAlpha((Double)a.getValue()); ! } else if (a.getName().equalsIgnoreCase("illumination")) { ! setIllumination((Double)a.getValue()); ! } else if (a.getName().equalsIgnoreCase("shininess")) { ! setShininess((Double)a.getValue()); ! } ! } } } Index: Project.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Project.java,v retrieving revision 1.134 retrieving revision 1.135 diff -C2 -d -r1.134 -r1.135 *** Project.java 14 Sep 2007 10:11:32 -0000 1.134 --- Project.java 15 Oct 2007 12:41:24 -0000 1.135 *************** *** 16,19 **** --- 16,20 ---- import java.util.LinkedList; import java.util.List; + import java.util.Map; import java.util.Stack; import java.util.StringTokenizer; *************** *** 113,116 **** --- 114,121 ---- /** Flag set when updating */ private boolean updating = false; + + private Map<Long, Material> materials; + + private long nextMaterialId; /** *************** *** 153,156 **** --- 158,166 ---- world = new Space("World", Space.FUNCTIONAL, Space.PROJECT_LEVEL, true); world.setId(new Long(0)); + materials = new HashMap<Long, Material>(); + nextMaterialId = 0; + add(Defaults.getBackMaterial()); + add(Defaults.getFrontMaterial()); + add(Defaults.getNoneMaterial()); activeCoordinateSystem = new CoordinateSystem(new Vertex(1, 0, 0), new Vertex(0, 1, 0), new Vertex(0, 0, 1), new Vertex(0, 0, 0)); *************** *** 452,456 **** */ public void add(Material material) { ! world.add(material); } --- 462,470 ---- */ public void add(Material material) { ! if (material.getId() == null) { ! material.setId(new Long(nextMaterialId)); ! nextMaterialId++; ! } ! materials.put(material.getId(), material); } *************** *** 459,464 **** * @param material The material */ ! private void remove(Material material) { ! world.remove(material); } --- 473,478 ---- * @param material The material */ ! public void remove(Material material) { ! materials.remove(material.getId()); } *************** *** 475,480 **** * @return The Material */ ! public Collection getMaterials() { ! return world.getMaterials(); } --- 489,494 ---- * @return The Material */ ! public Collection<Material> getMaterials() { ! return materials.values(); } *************** *** 485,489 **** */ public Material findMaterialById(long id) { ! return (Material)world.getMaterial(id); } --- 499,503 ---- */ public Material findMaterialById(long id) { ! return materials.get(id); } Index: Defaults.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Defaults.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Defaults.java 10 Apr 2006 11:53:51 -0000 1.1 --- Defaults.java 15 Oct 2007 12:41:24 -0000 1.2 *************** *** 14,25 **** /** Front color for surfaces */ ! private static float[] frontColor = new float[] {0.90f, 0.90f, 0.90f}; ! /** NONE color for surfaces */ ! private static float[] noneColor = new float[] {0.40f, 0.58f, 0.93f}; ! /** Back color for surfaces */ ! private static float[] backColor = new float[] {0.96f, 0.87f, 0.70f}; ! /** * Return front color --- 14,23 ---- /** Front color for surfaces */ ! private static Material frontMaterial = new Material("Front", new float[] {0.90f, 0.90f, 0.90f}); /** NONE color for surfaces */ ! private static Material noneMaterial = new Material("None", new float[] {0.40f, 0.58f, 0.93f}); /** Back color for surfaces */ ! private static Material backMaterial = new Material("Back", new float[] {0.96f, 0.87f, 0.70f}); ! /** * Return front color *************** *** 27,33 **** */ public static float[] getFrontColor() { ! return frontColor; } /** * Return back color --- 25,56 ---- */ public static float[] getFrontColor() { ! return frontMaterial.getColor(); } + + /** + * @return the backMaterial + */ + public static Material getBackMaterial() { + return backMaterial; + } + + + /** + * @return the frontMaterial + */ + public static Material getFrontMaterial() { + return frontMaterial; + } + + + /** + * @return the noneMaterial + */ + public static Material getNoneMaterial() { + return noneMaterial; + } + + /** * Return back color *************** *** 35,39 **** */ public static float[] getBackColor() { ! return backColor; } --- 58,62 ---- */ public static float[] getBackColor() { ! return backMaterial.getColor(); } *************** *** 43,47 **** */ public static float[] getNoneColor() { ! return noneColor; } --- 66,70 ---- */ public static float[] getNoneColor() { ! return backMaterial.getColor(); } Index: Space.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Space.java,v retrieving revision 1.182 retrieving revision 1.183 diff -C2 -d -r1.182 -r1.183 *** Space.java 12 Oct 2007 11:06:58 -0000 1.182 --- Space.java 15 Oct 2007 12:41:24 -0000 1.183 *************** *** 122,130 **** private long nextConstructorId; - /** The materials */ - private HashMap<Long, Material> materials; - /** The next surface id */ - private long nextMaterialId; - /** The transformation */ private TransformStack transform; --- 122,125 ---- *************** *** 195,200 **** elements = new HashMap<Long, Space>(); nextElementId = 1; - materials = new HashMap<Long, Material>(); - nextMaterialId = 1; constructors = new HashMap<Long, Constructor>(); nextConstructorId = 1; --- 190,193 ---- *************** *** 926,974 **** return (Surface) surfaces.get(new Long(id)); } - - /** - * Add a material - * @param material The material - */ - public void add(Material material) { - if (container) { - Long id = new Long(nextMaterialId++); - material.setId(id); - materials.put(id, material); - } else { - throw new Error("adding material to non-container " + this); - } - } - - /** - * Remove a material - * @param material The material - */ - public void remove(Material material) { - edges.remove(material.getId()); - material.setId(null); - } - - /** - * Return the materials - * @return The materials - */ - public Collection getMaterials() { - if (container) { - return materials.values(); - } else { - return Collections.EMPTY_LIST; - } - } - - /** - * Return the material - * @param id The id - * @return The material - */ - public Material getMaterial(long id) { - return (Material) materials.get(new Long(id)); - } - /** --- 919,922 ---- Index: Persistence.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Persistence.java,v retrieving revision 1.48 retrieving revision 1.49 diff -C2 -d -r1.48 -r1.49 *** Persistence.java 12 Oct 2007 08:10:57 -0000 1.48 --- Persistence.java 15 Oct 2007 12:41:24 -0000 1.49 *************** *** 126,138 **** (SpaceType) document.getSpace().iterator().next(), mapper, xmls); - { - Iterator iter = xmls.iterator(); - while (iter.hasNext()) { - EntityType external = (EntityType) iter.next(); - Object object = mapper.get(new Long(external.getId())); - internalizeReferences(object, external, mapper); - } - } Project p = Project.getInstance(); p.setWorld(world); p.setActiveCoordinateSystem( --- 126,132 ---- (SpaceType) document.getSpace().iterator().next(), mapper, xmls); Project p = Project.getInstance(); + p.getMaterials().clear(); + p.getConstructors().clear(); p.setWorld(world); p.setActiveCoordinateSystem( *************** *** 152,156 **** Project.getInstance().getGlobals().setAttributes(attributes); } ! { Iterator iter = document.getCamera().iterator(); --- 146,156 ---- Project.getInstance().getGlobals().setAttributes(attributes); } ! { ! Iterator iter = document.getMaterial().iterator(); ! while (iter.hasNext()) { ! MaterialType current = (MaterialType) iter.next(); ! p.add(internalizeMaterial(current, mapper, xmls)); ! } ! } { Iterator iter = document.getCamera().iterator(); *************** *** 185,188 **** --- 185,196 ---- } } + { + Iterator iter = xmls.iterator(); + while (iter.hasNext()) { + EntityType external = (EntityType) iter.next(); + Object object = mapper.get(new Long(external.getId())); + internalizeReferences(object, external, mapper); + } + } } *************** *** 336,340 **** space.setVertices(vertices); } ! { Iterator iter = xml.getMaterial().iterator(); while (iter.hasNext()) { --- 344,348 ---- space.setVertices(vertices); } ! /*{ Iterator iter = xml.getMaterial().iterator(); while (iter.hasNext()) { *************** *** 342,346 **** space.add(internalizeMaterial(current, mapper, xmls)); } ! } { Iterator iter = xml.getTransforms().iterator(); --- 350,354 ---- space.add(internalizeMaterial(current, mapper, xmls)); } ! }*/ { Iterator iter = xml.getTransforms().iterator(); *************** *** 784,802 **** HashMap mapper = new HashMap(); document.getSpace().add(externalizeSpace(Project.getInstance().world(), mapper)); - { ! Set entries = mapper.entrySet(); ! Iterator iter = entries.iterator(); ! while (iter.hasNext()) { ! Entry current = (Entry) iter.next(); ! Object object = current.getKey(); ! EntityType external = (EntityType) current.getValue(); ! externalizeReferences(object, external, mapper); } } - document.setCs(id(mapper, Project.getInstance().getActiveCoordinateSystem())); - document.setActive(id(mapper, Project.getInstance().getActiveSpace())); - document.setName(Project.getInstance().getName()); - { Collection globals = document.getGlobal(); --- 792,801 ---- HashMap mapper = new HashMap(); document.getSpace().add(externalizeSpace(Project.getInstance().world(), mapper)); { ! Collection materials = document.getMaterial(); ! for (Material m : Project.getInstance().getMaterials()) { ! materials.add(externalizeMaterial(m, mapper)); } } { Collection globals = document.getGlobal(); *************** *** 805,808 **** --- 804,810 ---- } } + document.setCs(id(mapper, Project.getInstance().getActiveCoordinateSystem())); + document.setActive(id(mapper, Project.getInstance().getActiveSpace())); + document.setName(Project.getInstance().getName()); { Collection cams = document.getCamera(); *************** *** 854,857 **** --- 856,869 ---- } } + { + Set entries = mapper.entrySet(); + Iterator iter = entries.iterator(); + while (iter.hasNext()) { + Entry current = (Entry) iter.next(); + Object object = current.getKey(); + EntityType external = (EntityType) current.getValue(); + externalizeReferences(object, external, mapper); + } + } return document; } *************** *** 995,999 **** } } ! { Iterator iter = space.getMaterials().iterator(); while (iter.hasNext()) { --- 1007,1011 ---- } } ! /*{ Iterator iter = space.getMaterials().iterator(); while (iter.hasNext()) { *************** *** 1001,1005 **** xml.getMaterial().add(externalizeMaterial(current, map)); } ! } { Iterator iter = space.getConstructors().iterator(); --- 1013,1017 ---- xml.getMaterial().add(externalizeMaterial(current, map)); } ! }*/ { Iterator iter = space.getConstructors().iterator(); *************** *** 1293,1297 **** externalizeReferences((Vertex) object, (VertexType) xml, map); } else if (object instanceof Material) { ! externalizeMaterial((Material) object, (MaterialType) xml, map); } else if (object instanceof Constructor) { externalizeReferences((Constructor) object, (ConstructorType) xml, map); --- 1305,1309 ---- externalizeReferences((Vertex) object, (VertexType) xml, map); } else if (object instanceof Material) { ! externalizeReference((Material) object, (MaterialType) xml, map); } else if (object instanceof Constructor) { externalizeReferences((Constructor) object, (ConstructorType) xml, map); *************** *** 1457,1461 **** * @param map The map */ ! private static void externalizeMaterial(Material object, MaterialType xml, Map map) { } --- 1469,1473 ---- * @param map The map */ ! private static void externalizeReference(Material object, MaterialType xml, Map map) { } |