diff --git a/changelog.txt b/changelog.txt index 8be6ac6d4..8254c8637 100644 --- a/changelog.txt +++ b/changelog.txt @@ -2,6 +2,7 @@ Contributions: * justjoheinz: turn off control panel and build menu options when disconnected * Erik: added 5D driver for RepRap's and compatible firmwares (Ultimaker) +* Erik: STL preview now is the actual build volumes configured in machines.xml 0020 ReplicatorG Removed: diff --git a/machines.xml.dist b/machines.xml.dist index 40e6105d8..447f795fb 100644 --- a/machines.xml.dist +++ b/machines.xml.dist @@ -4,9 +4,9 @@ 3-Axis Simulator - - - + + + @@ -21,9 +21,9 @@ Cupcake CNC - - - + + + @@ -50,9 +50,9 @@ M18 Cupcake CNC w/ heated build platform - - - + + + @@ -79,9 +79,9 @@ M18 - - - + + + @@ -111,9 +111,9 @@ M18 EXPERIMENTAL - Cupcake CNC (with SMD v2.4) - - - + + + @@ -139,9 +139,9 @@ M18 EXPERIMENTAL - Cupcake CNC (Driver 3.0 and Acme threads) - - - + + + @@ -167,9 +167,9 @@ M18 EXPERIMENTAL - Thingomatic - Gen 4 - - - + + + @@ -195,9 +195,9 @@ M18 EXPERIMENTAL - Thingomatic - Candy - - - + + + @@ -223,9 +223,9 @@ M18 EXPERIMENTAL - Thingomatic Halfstep - - - + + + @@ -251,9 +251,9 @@ M18 Mendel with (5D firmware at 57600 baud) - - - + + + @@ -279,9 +279,9 @@ M108 S0 Ultimaker v1.0 (5D firmware) - - - + + + diff --git a/src/replicatorg/app/ui/MainWindow.java b/src/replicatorg/app/ui/MainWindow.java index c47ad498e..2c5ad2408 100755 --- a/src/replicatorg/app/ui/MainWindow.java +++ b/src/replicatorg/app/ui/MainWindow.java @@ -2371,11 +2371,27 @@ protected void setMachine(MachineController machine) { machine.addMachineStateListener(buttons); } machineStatusPanel.setMachine(this.machine); + // TODO: PreviewPanel: update with new machine + } + public MachineController getMachine(){ + return this.machine; } public void loadMachine(String name) { setMachine(Base.loadMachine(name)); reloadSerialMenu(); + + if(previewPanel instanceof PreviewPanel) + { + /* FIXME: This is probably not the best place to do the reload. We need + * the BuildVolume information (through MachineModel) which apparently + * isn't initialized yet when this is called... + */ + Base.logger.info("RELOADING the machine... removing previewPanel..."); + getPreviewPanel().rebuildScene(); + updateBuild(); + } + if (machine.driver instanceof UsesSerial) { UsesSerial us = (UsesSerial)machine.driver; if (Base.preferences.getBoolean("serial.use_machines",true) && diff --git a/src/replicatorg/app/ui/modeling/EditingModel.java b/src/replicatorg/app/ui/modeling/EditingModel.java index d62f429d4..36fa40d41 100644 --- a/src/replicatorg/app/ui/modeling/EditingModel.java +++ b/src/replicatorg/app/ui/modeling/EditingModel.java @@ -133,7 +133,7 @@ private BranchGroup makeShape(BuildModel model) { return wrapper; } - BuildModel getBuildModel() { return model; } + public BuildModel getBuildModel() { return model; } public BranchGroup getGroup() { if (group == null) { diff --git a/src/replicatorg/app/ui/modeling/PreviewPanel.java b/src/replicatorg/app/ui/modeling/PreviewPanel.java index 93d91a264..7597ff3df 100644 --- a/src/replicatorg/app/ui/modeling/PreviewPanel.java +++ b/src/replicatorg/app/ui/modeling/PreviewPanel.java @@ -11,6 +11,7 @@ import java.awt.event.MouseListener; import java.awt.event.MouseMotionListener; import java.awt.event.MouseWheelListener; +import java.awt.geom.Line2D; import java.util.logging.Level; import javax.media.j3d.AmbientLight; @@ -46,7 +47,11 @@ import net.miginfocom.swing.MigLayout; import replicatorg.app.Base; +import replicatorg.app.MachineController; +import replicatorg.app.Serial; import replicatorg.app.ui.MainWindow; +import replicatorg.machine.model.MachineModel; +import replicatorg.machine.model.BuildVolume; import replicatorg.model.BuildModel; import com.sun.j3d.utils.universe.SimpleUniverse; @@ -61,8 +66,10 @@ public class PreviewPanel extends JPanel { new BoundingSphere(new Point3d(0.0,0.0,0.0), 1000.0); EditingModel model = null; + BranchGroup scene; + BuildVolume buildVol; - EditingModel getModel() { return model; } + public EditingModel getModel() { return model; } public void setModel(BuildModel buildModel) { if (model == null || buildModel != model.getBuildModel()) { @@ -84,6 +91,33 @@ private void setScene(EditingModel model) { sceneGroup.addChild(objectBranch); } + /* + * This is to ensure we can switch between machines with different dimensions + * It is called from MainWindow loadMachine() + */ + public void rebuildScene(){ + if (objectBranch != null) { + sceneGroup.removeChild(objectBranch); + } + scene.detach(); + scene = createSTLScene(); + objectBranch = model.getGroup(); + sceneGroup.addChild(objectBranch); + univ.addBranchGraph(scene); + } + + + private void getBuildVolume(){ + Base.logger.info("Resetting the build volume!"); + MachineController mc = this.mainWindow.getMachine(); + if(mc instanceof MachineController){ + Base.logger.info("Got the MachineController object!"); + MachineModel mm = mc.getModel(); + buildVol = mm.getBuildVolume(); + Base.logger.info("Dimensions:" + buildVol.getX() +','+ buildVol.getY() + ',' + buildVol.getZ()); + } + } + MainWindow mainWindow; enum DragMode { @@ -165,7 +199,7 @@ public PreviewPanel(final MainWindow mainWindow) { add(toolPanel,"dock east,width max(200,20%)"); } // Create the content branch and add it to the universe - BranchGroup scene = createSTLScene(); + scene = createSTLScene(); univ.addBranchGraph(scene); canvas.addKeyListener( new KeyListener() { @@ -317,24 +351,35 @@ private Shape3D makePlatform(Point3d lower, Point3d upper) { public Node makeBoundingBox() { Group boxGroup = new Group(); - Shape3D boxframe = makeBoxFrame(new Point3d(-50,-50,0), new Vector3d(100,100,100)); - - /* - Appearance sides = new Appearance(); - sides.setTransparencyAttributes(new TransparencyAttributes(TransparencyAttributes.NICEST,0.9f)); - Color3f color = new Color3f(0.05f,0.05f,1.0f); - Material m = new Material(color,color,color,color,64.0f); - sides.setMaterial(m); - - Box box = new Box(50,50,50,sides); - Transform3D tf = new Transform3D(); - tf.setTranslation(new Vector3d(0,0,50)); - TransformGroup tg = new TransformGroup(tf); - tg.addChild(box); - tg.addChild(boxframe); - */ - boxGroup.addChild(boxframe); - boxGroup.addChild(this.makePlatform(new Point3d(-50,-50,-0.001), new Point3d(50,50,-0.001))); + // TODO: Change these dimensions if it has a custom buid-volume! Display cut-outs?! + // Same for the platform + if(buildVol == null) + { + Shape3D boxframe = makeBoxFrame(new Point3d(-50,-50,0), new Vector3d(100,100,100)); + boxGroup.addChild(boxframe); + boxGroup.addChild(this.makePlatform(new Point3d(-50,-50,-0.001), new Point3d(50,50,-0.001))); + } else { + Vector3d boxdims = new Vector3d(buildVol.getX(),buildVol.getY(),buildVol.getZ()); + Shape3D boxframe = makeBoxFrame(new Point3d((int) -buildVol.getX()/2,(int) -buildVol.getY()/2,0), boxdims); + boxGroup.addChild(boxframe); + boxGroup.addChild(this.makePlatform(new Point3d((int) -buildVol.getX()/2,(int) -buildVol.getY()/2,-0.001), new Point3d(buildVol.getX()/2,buildVol.getY()/2,-0.001))); + } + + + /* + Appearance sides = new Appearance(); + sides.setTransparencyAttributes(new TransparencyAttributes(TransparencyAttributes.NICEST,0.9f)); + Color3f color = new Color3f(0.05f,0.05f,1.0f); + Material m = new Material(color,color,color,color,64.0f); + sides.setMaterial(m); + + Box box = new Box(50,50,50,sides); + Transform3D tf = new Transform3D(); + tf.setTranslation(new Vector3d(0,0,50)); + TransformGroup tg = new TransformGroup(tf); + tg.addChild(box); + tg.addChild(boxframe); + */ return boxGroup; } @@ -343,25 +388,41 @@ public Node makeBackground() { bg.setApplicationBounds(bounds); return bg; } - - public Node makeBaseGrid() { - Appearance edges = new Appearance(); - edges.setLineAttributes(new LineAttributes(1,LineAttributes.PATTERN_SOLID,true)); - edges.setColoringAttributes(new ColoringAttributes(0.6f,0.6f,0.8f,ColoringAttributes.FASTEST)); - final int LINES = 11; - LineArray grid = new LineArray(4*(LINES-2),GeometryArray.COORDINATES); - for (int i = 1; i < LINES-1; i++) { - double offset = -50 + (100/(LINES-1))*i; - int idx = (i-1)*4; - // Along x axis - grid.setCoordinate(idx++, new Point3d(offset,-50,0)); - grid.setCoordinate(idx++, new Point3d(offset,50,0)); - // Along y axis - grid.setCoordinate(idx++, new Point3d(-50,offset,0)); - grid.setCoordinate(idx++, new Point3d(50,offset,0)); - } - return new Shape3D(grid,edges); - } + + public Node makeBaseGrid(boolean xOrY) { + if(buildVol instanceof BuildVolume) + { + int gridSpacing = 10; + Appearance edges = new Appearance(); + edges.setLineAttributes(new LineAttributes(1,LineAttributes.PATTERN_SOLID,true)); + edges.setColoringAttributes(new ColoringAttributes(0.6f,0.6f,0.8f,ColoringAttributes.FASTEST)); + int lineCountX = (int) 1+(buildVol.getX()/gridSpacing); + int lineCountY = (int) 1+(buildVol.getY()/gridSpacing); + LineArray gridX = new LineArray(4*(lineCountX),GeometryArray.COORDINATES); + LineArray gridY = new LineArray(4*(lineCountY),GeometryArray.COORDINATES); + int idx; + for (int i = 1; i < lineCountX-1; i++) { + double offsetX = -buildVol.getX()/2 + (buildVol.getX()/(lineCountX-1))*i; + idx = (i-1)*4; + // Along x axis + gridX.setCoordinate(idx++, new Point3d(offsetX,-buildVol.getY()/2,0)); + gridX.setCoordinate(idx++, new Point3d(offsetX,buildVol.getY()/2,0)); + } + for (int i = 1; i < lineCountY-1; i++) { + double offsetY = -buildVol.getY()/2 + (buildVol.getY()/(lineCountY-1))*i; + idx = (i-1)*4; + // Along y axis + gridY.setCoordinate(idx++, new Point3d(-buildVol.getX()/2,offsetY,0)); + gridY.setCoordinate(idx++, new Point3d(buildVol.getX()/2,offsetY,0)); + } + + Base.logger.info("LineCountX,Y:"+lineCountX+','+lineCountY); + if(xOrY==true) + return new Shape3D(gridX,edges); + else + return new Shape3D(gridY,edges); + } return null; + } BranchGroup sceneGroup; BranchGroup objectBranch; @@ -376,9 +437,11 @@ public void align() { public BranchGroup createSTLScene() { + getBuildVolume(); // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); - + objRoot.setCapability(BranchGroup.ALLOW_DETACH ); + sceneGroup = new BranchGroup(); sceneGroup.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND); sceneGroup.setCapability(BranchGroup.ALLOW_CHILDREN_WRITE); @@ -387,7 +450,8 @@ public BranchGroup createSTLScene() { sceneGroup.addChild(makeDirectedLight2()); sceneGroup.addChild(makeBoundingBox()); sceneGroup.addChild(makeBackground()); - sceneGroup.addChild(makeBaseGrid()); + sceneGroup.addChild(makeBaseGrid(true)); + sceneGroup.addChild(makeBaseGrid(false)); objRoot.addChild(sceneGroup); diff --git a/src/replicatorg/machine/model/BuildVolume.java b/src/replicatorg/machine/model/BuildVolume.java new file mode 100644 index 000000000..3647b6a17 --- /dev/null +++ b/src/replicatorg/machine/model/BuildVolume.java @@ -0,0 +1,46 @@ +package replicatorg.machine.model; + +public class BuildVolume { + + private int x; + private int y; + private int z; + /* + * TODO: This, more complex class could implement things like a cut-outs and places to avoid such as tool-changers. + * Perhaps managed whether it's confirmed to be empty or contains objects that we need to travel around? + */ + public BuildVolume(){ + } + + public BuildVolume(int x,int y,int z){ + this.setX(x); + this.setY(y); + this.setZ(z); + } + + public void setX(int x){ + this.x = x; + } + + public void setY(int y){ + this.y = y; + } + + public void setZ(int z){ + this.z = z; + } + + public int getX(){ + return this.x; + } + + public int getY(){ + return this.y; + } + + public int getZ(){ + return this.z; + } + + +} diff --git a/src/replicatorg/machine/model/MachineModel.java b/src/replicatorg/machine/model/MachineModel.java index c2e9a9499..d9ac12b3a 100644 --- a/src/replicatorg/machine/model/MachineModel.java +++ b/src/replicatorg/machine/model/MachineModel.java @@ -24,6 +24,7 @@ package replicatorg.machine.model; import java.util.Vector; +import java.util.logging.Logger; import javax.vecmath.Point3d; @@ -32,6 +33,7 @@ import replicatorg.app.Base; import replicatorg.app.tools.XML; +import replicatorg.machine.model.BuildVolume; public class MachineModel { @@ -58,6 +60,9 @@ public class MachineModel //our clamp models protected Vector clamps; + + // our build volume + protected BuildVolume buildVolume; /************************************* * Creates the model object. @@ -66,6 +71,8 @@ public MachineModel() { clamps = new Vector(); tools = new Vector(); +// buildVolume = new BuildVolume((int)(Math.random()*300)+10,(int)(Math.random()*300)+10,(int)(Math.random()*300)+10); // preload it with the default values + buildVolume = new BuildVolume(100,100,100); // preload it with the default values //currentPosition = new Point3d(); minimum = new Point3d(); @@ -84,6 +91,8 @@ public void loadXML(Node node) parseAxes(); parseClamps(); parseTools(); + parseBuildVolume(); + } //load axes configuration @@ -187,6 +196,52 @@ private void parseTools() selectTool(0); } } + //load axes configuration + private void parseBuildVolume() + { +// Base.logger.info("parsing build volume!"); + + if(XML.hasChildNode(xml, "geometry")) + { + Node geometry = XML.getChildNodeByName(xml, "geometry"); + + //look through the axes. + NodeList axes = geometry.getChildNodes(); + for (int i=0; i getTools() {