[Bprocessor-commit] model/src/net/sourceforge/bprocessor/model Document.java, NONE, 1.1 Instance.ja
Status: Pre-Alpha
Brought to you by:
henryml
From: Michael L. <he...@us...> - 2009-06-29 08:37:40
|
Update of /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv10801/src/net/sourceforge/bprocessor/model Modified Files: Instance.java Space.java Project.java Persistence.java Added Files: Document.java Log Message: Handling of instances Index: Instance.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Instance.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** Instance.java 26 Jun 2009 12:39:50 -0000 1.10 --- Instance.java 29 Jun 2009 08:37:37 -0000 1.11 *************** *** 8,12 **** --- 8,14 ---- package net.sourceforge.bprocessor.model; + import java.util.ArrayList; import java.util.Collection; + import java.util.HashMap; import java.util.HashSet; import java.util.LinkedList; *************** *** 127,130 **** --- 129,146 ---- return copy; } + + /** + * + * @return duplicate of this space + */ + public Space duplicate() { + Space duplicate = proto.copy(new HashMap()); + List<Vertex> vertices = new ArrayList(duplicate.collect()); + anchor.unTranslateIt(vertices); + for (Vertex current : vertices) { + current.update(); + } + return duplicate; + } } Index: Persistence.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Persistence.java,v retrieving revision 1.80 retrieving revision 1.81 diff -C2 -d -r1.80 -r1.81 *** Persistence.java 25 Jun 2009 22:17:30 -0000 1.80 --- Persistence.java 29 Jun 2009 08:37:37 -0000 1.81 *************** *** 85,89 **** import java.io.OutputStream; import java.util.Collection; - import java.util.Collections; import java.util.HashMap; import java.util.HashSet; --- 85,88 ---- *************** *** 118,183 **** private Persistence() { } /** ! * This method internalizes a b-processor document ! * @param document XML */ ! public static void internalize(Bmodel document) { HashMap mapper = new HashMap(); Collection xmls = new LinkedList(); ! ! Space world = internalizeContainer(null, ! (SpaceType) document.getSpace().iterator().next(), mapper, xmls); ! ! Project p = Project.getInstance(); ! p.getMaterials().clear(); ! p.getConstructors().clear(); ! p.setWorld(world); ! p.setActiveCoordinateSystem( ! (CoordinateSystem) get(document.getCs(), mapper)); ! p.setActiveSpace((Space) get(document.getActive(), mapper)); ! p.setName(document.getName()); ! p.changed(p); { List<Attribute> attributes = new LinkedList<Attribute>(); ! for (Object o : document.getGlobal()) { ! if (o instanceof MapElementType) { ! MapElementType elem = (MapElementType)o; ! attributes.add(internalizeKeyValue(elem, mapper)); ! } } ! Collections.sort(attributes, new Attribute.AttributeComparator()); ! Project.getInstance().getGlobals().setAttributes(attributes); } { ! Iterator iter = document.getMaterial().iterator(); while (iter.hasNext()) { MaterialType current = (MaterialType) iter.next(); ! p.add(internalizeMaterial(current, mapper, xmls)); } } { ! p.getCatalogObjects().clear(); ! for (Object o : document.getCatalogObjects()) { ! LibObjType lot = (LibObjType)o; ! Component lo = internalizeLibraryObj(lot, mapper, xmls); ! p.addCalalogObject(lo); } } { ! CameraType current = document.getView(); if (current != null) { Camera camera = internalizeCamera(current); internalizeReferences(camera, current, mapper); ! Project.getInstance().setCurrentCamera(camera); } } { ! Iterator iter = document.getCamera().iterator(); while (iter.hasNext()) { CameraType current = (CameraType) iter.next(); ! Camera cam = internalizeCamera(current); ! p.add(cam); } } { --- 117,206 ---- private Persistence() { } + + /** + * This method loads the Bmodel document from a file + * @param file The input file + * @exception Exception Thrown if an exception occurs + * @return document + */ + public static Document load(File file) throws Exception { + FileInputStream fis = new FileInputStream(file); + Bmodel bp = (Bmodel)loadFile(fis); + fis.close(); + return internalize(bp); + } + /** ! * This method loads the Bmodel document from a file ! * @param is The input stream ! * @return The loaded object (xml document) ! * @exception Exception Thrown if an exception occurs */ ! private static Object loadFile(InputStream is) throws Exception { ! JAXBContext jc = JAXBContext.newInstance("net.sourceforge.bprocessor.model.xml"); ! Unmarshaller u = jc.createUnmarshaller(); ! return u.unmarshal(is); ! } ! ! /** ! * ! * @param xml XML ! * @return document ! */ ! public static Document internalize(Bmodel xml) { ! Document document = new Document(); HashMap mapper = new HashMap(); Collection xmls = new LinkedList(); ! { ! Space world = internalizeContainer(null, ! (SpaceType) xml.getSpace().iterator().next(), mapper, xmls); ! document.setWorld(world); ! } { List<Attribute> attributes = new LinkedList<Attribute>(); ! Iterator iter = xml.getGlobal().iterator(); ! while (iter.hasNext()) { ! MapElementType current = (MapElementType) iter.next(); ! attributes.add(internalizeKeyValue(current, mapper)); } ! document.setAttributes(attributes); } { ! List<Material> materials = new LinkedList(); ! Iterator iter = xml.getMaterial().iterator(); while (iter.hasNext()) { MaterialType current = (MaterialType) iter.next(); ! materials.add(internalizeMaterial(current, mapper, xmls)); } + document.setMaterials(materials); } { ! List<Component> components = new LinkedList(); ! Iterator iter = xml.getCatalogObjects().iterator(); ! while (iter.hasNext()) { ! LibObjType current = (LibObjType)iter.next(); ! Component component = internalizeLibraryObj(current, mapper, xmls); ! components.add(component); } + document.setComponents(components); } { ! CameraType current = xml.getView(); if (current != null) { Camera camera = internalizeCamera(current); internalizeReferences(camera, current, mapper); ! document.setView(camera); } } { ! List<Camera> cameras = new LinkedList(); ! Iterator iter = xml.getCamera().iterator(); while (iter.hasNext()) { CameraType current = (CameraType) iter.next(); ! Camera camera = internalizeCamera(current); ! cameras.add(camera); } + document.setCameras(cameras); } { *************** *** 189,217 **** } } ! } ! ! /** ! * This method loads the Bmodel document from a file ! * @param file The input file ! * @exception Exception Thrown if an exception occurs ! */ ! public static void load(File file) throws Exception { ! FileInputStream fis = new FileInputStream(file); ! Bmodel bp = (Bmodel)loadFile(fis); ! internalize(bp); ! fis.close(); ! } ! ! ! /** ! * This method loads the Bmodel document from a file ! * @param is The input stream ! * @return The loaded object (xml document) ! * @exception Exception Thrown if an exception occurs ! */ ! private static Object loadFile(InputStream is) throws Exception { ! JAXBContext jc = JAXBContext.newInstance("net.sourceforge.bprocessor.model.xml"); ! Unmarshaller u = jc.createUnmarshaller(); ! return u.unmarshal(is); } --- 212,219 ---- } } ! document.setActiveSystem((CoordinateSystem) get(xml.getCs(), mapper)); ! document.setActiveSpace((Space) get(xml.getActive(), mapper)); ! document.setName(xml.getName()); ! return document; } Index: Space.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Space.java,v retrieving revision 1.241 retrieving revision 1.242 diff -C2 -d -r1.241 -r1.242 *** Space.java 26 Jun 2009 15:39:10 -0000 1.241 --- Space.java 29 Jun 2009 08:37:37 -0000 1.242 *************** *** 1672,1674 **** --- 1672,1740 ---- export(containers, out); } + + /** + * Collect spaces + * @return spaces + */ + public List<Instance> collectInstances() { + List<Instance> spaces = new LinkedList(); + for (Item current : getElements()) { + if (current instanceof Space) { + Space space = (Space) current; + space.collectInstances(spaces); + } else { + Instance instance = (Instance) current; + spaces.add(instance); + } + } + return spaces; + } + /** + * Collect spaces + * @param spaces Spaces + */ + public void collectInstances(Collection<Instance> spaces) { + if (isUnion()) { + for (Item item : getElements()) { + if (item instanceof Space) { + Space space = (Space) item; + space.collectInstances(spaces); + } else { + Instance instance = (Instance) item; + spaces.add(instance); + } + } + } + } + + /** + * Collect spaces + * @return spaces + */ + public List<Space> collectSpaces() { + List<Space> spaces = new LinkedList(); + for (Item current : getElements()) { + if (current instanceof Space) { + Space space = (Space) current; + space.collectSpaces(spaces); + } + } + return spaces; + } + /** + * Collect spaces + * @param spaces Spaces + */ + public void collectSpaces(Collection<Space> spaces) { + if (isUnion()) { + for (Item item : getElements()) { + if (item instanceof Space) { + Space space = (Space) item; + space.collectSpaces(spaces); + } + } + } else { + spaces.add(this); + } + } } --- NEW FILE: Document.java --- //--------------------------------------------------------------------------------- // $Id: Document.java,v 1.1 2009/06/29 08:37:37 henryml Exp $ // // Copyright (c) 2005 The BProcessor Team (http://bprocessor.sourceforge.net) // Released under the Lesser GNU Public License v2.1 //--------------------------------------------------------------------------------- package net.sourceforge.bprocessor.model; import java.util.List; /** * */ public class Document { private String name; private Space world; private Space activeSpace; private CoordinateSystem activeSystem; private List<Attribute> attributes; private List<Material> materials; private List<Component> components; private Camera view; private List<Camera> cameras; /** * * @param value String */ public void setName(String value) { name = value; } /** * * @return name */ public String getName() { return name; } /** * * @param value Space */ public void setWorld(Space value) { world = value; } /** * * @return world */ public Space getWorld() { return world; } /** * * @param value Space */ public void setActiveSpace(Space value) { activeSpace = value; } /** * * @return active space */ public Space getActiveSpace() { return activeSpace; } /** * * @param value CoordinateSystem */ public void setActiveSystem(CoordinateSystem value) { activeSystem = value; } /** * * @return active coordinate system */ public CoordinateSystem getActiveSystem() { return activeSystem; } /** * * @param value Attributes */ public void setAttributes(List<Attribute> value) { attributes = value; } /** * * @return attributes */ public List<Attribute> getAttribues() { return attributes; } /** * * @param value List of Materials */ public void setMaterials(List<Material> value) { materials = value; } /** * * @return materials */ public List<Material> getMaterials() { return materials; } /** * * @param value Active camera */ public void setView(Camera value) { view = value; } /** * * @return active camera */ public Camera getView() { return view; } /** * * @param value List of cameras */ public void setCameras(List<Camera> value) { cameras = value; } /** * * @return cameras */ public List<Camera> getCameras() { return cameras; } /** * * @param value List of components */ public void setComponents(List<Component> value) { components = value; } /** * * @return List of components */ public List<Component> getComponents() { return components; } } Index: Project.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Project.java,v retrieving revision 1.179 retrieving revision 1.180 diff -C2 -d -r1.179 -r1.180 *** Project.java 25 Jun 2009 22:17:30 -0000 1.179 --- Project.java 29 Jun 2009 08:37:37 -0000 1.180 *************** *** 851,857 **** public void setState(Bmodel state) { clear(); ! Persistence.internalize(state); } ! /** * Reset the state to currentState --- 851,882 ---- public void setState(Bmodel state) { clear(); ! Document document = Persistence.internalize(state); ! setDocument(document); } ! ! /** ! * ! * @param document Document ! */ ! public void setDocument(Document document) { ! setWorld(document.getWorld()); ! setActiveCoordinateSystem(document.getActiveSystem()); ! setActiveSpace(document.getActiveSpace()); ! setName(document.getName()); ! setCurrentCamera(document.getView()); ! getGlobals().setAttributes(document.getAttribues()); ! for (Material current : document.getMaterials()) { ! add(current); ! } ! for (Component current : document.getComponents()) { ! addCalalogObject(current); ! } ! for (Camera current : document.getCameras()) { ! add(current); ! } ! ! changed(this); ! } ! /** * Reset the state to currentState *************** *** 910,914 **** Selection.primary().clear(); reset(); ! Persistence.load(file); makeClean(); resetHistory(); --- 935,940 ---- Selection.primary().clear(); reset(); ! Document document = Persistence.load(file); ! setDocument(document); makeClean(); resetHistory(); *************** *** 947,962 **** */ public Collection getConstructors() { ! Collection res = new HashSet(); ! Collection spaces = getSpaces(); ! Iterator iter = spaces.iterator(); ! while (iter.hasNext()) { ! Object current = iter.next(); ! if (current instanceof Space) { ! Space space = (Space) current; ! res.addAll(space.getConstructors()); ! } ! } ! res.addAll(world.getConstructors()); ! return res; } --- 973,977 ---- */ public Collection getConstructors() { ! return world.getConstructors(); } *************** *** 1660,1670 **** public void exportOBJ(OutputStream out) { PrintStream printer = new PrintStream(out); List<Space> constructs = new LinkedList(); ! for (Item current : world.getElements()) { ! if (current instanceof Space) { ! if (!current.isVoid() && current.isConstructionSpace()) { ! Space container = (Space) current; ! constructs.add(container); ! } } } --- 1675,1684 ---- public void exportOBJ(OutputStream out) { PrintStream printer = new PrintStream(out); + List<Space> spaces = world.collectSpaces(); + List<Space> constructs = new LinkedList(); ! for (Space current : spaces) { ! if (!current.isVoid() && current.isConstructionSpace()) { ! constructs.add(current); } } |