From: <adr...@us...> - 2010-09-07 14:25:38
|
Revision: 3780 http://reprap.svn.sourceforge.net/reprap/?rev=3780&view=rev Author: adrian-bowyer Date: 2010-09-07 14:25:32 +0000 (Tue, 07 Sep 2010) Log Message: ----------- Added ability to decide PCB position on the bed at run time. Modified Paths: -------------- trunk/software/host/src/org/reprap/geometry/polygons/RrRectangle.java trunk/software/host/src/org/reprap/gui/RepRapBuild.java trunk/software/host/src/org/reprap/pcb/PCB.java Modified: trunk/software/host/src/org/reprap/geometry/polygons/RrRectangle.java =================================================================== --- trunk/software/host/src/org/reprap/geometry/polygons/RrRectangle.java 2010-09-06 23:27:18 UTC (rev 3779) +++ trunk/software/host/src/org/reprap/geometry/polygons/RrRectangle.java 2010-09-07 14:25:32 UTC (rev 3780) @@ -220,6 +220,17 @@ } /** + * Move somewhere else + * @param p + * @return + */ + public RrRectangle translate(Rr2Point p) + { + return new RrRectangle(new RrInterval(x.low() + p.x(), x.high() + p.x()), + new RrInterval(y.low() + p.y(), y.high() + p.y())); + } + + /** * @param a */ public void expand(Rr2Point a) Modified: trunk/software/host/src/org/reprap/gui/RepRapBuild.java =================================================================== --- trunk/software/host/src/org/reprap/gui/RepRapBuild.java 2010-09-06 23:27:18 UTC (rev 3779) +++ trunk/software/host/src/org/reprap/gui/RepRapBuild.java 2010-09-07 14:25:32 UTC (rev 3780) @@ -109,6 +109,7 @@ import javax.swing.ButtonGroup; import javax.swing.JButton; import javax.swing.JComponent; +import javax.swing.JDialog; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JTextField; @@ -138,7 +139,7 @@ class MaterialRadioButtons extends JPanel { private static final long serialVersionUID = 1L; private static Attributes att; - private static JFrame frame; + private static JDialog dialog; private static JTextField copies; private static RepRapBuild rrb; private static int stlIndex; @@ -209,7 +210,7 @@ int number = Integer.parseInt(copies.getText().trim()) - 1; STLObject stl = rrb.getSTLs().get(stlIndex); rrb.moreCopies(stl, att, number); - frame.dispose(); + dialog.dispose(); } public static void createAndShowGUI(Attributes a, RepRapBuild r, int index) @@ -218,18 +219,20 @@ rrb = r; stlIndex = index; //Create and set up the window. - frame = new JFrame("Material selector"); - frame.setLocation(500, 400); - frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + JFrame f = new JFrame(); + dialog = new JDialog(f, "Material selector"); + dialog.setLocation(500, 400); + dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); //Create and set up the content pane. JComponent newContentPane = new MaterialRadioButtons(); newContentPane.setOpaque(true); //content panes must be opaque - frame.setContentPane(newContentPane); + dialog.setContentPane(newContentPane); //Display the window. - frame.pack(); - frame.setVisible(true); + dialog.pack(); + dialog.setModalityType(JDialog.DEFAULT_MODALITY_TYPE); + dialog.setVisible(true); } } Modified: trunk/software/host/src/org/reprap/pcb/PCB.java =================================================================== --- trunk/software/host/src/org/reprap/pcb/PCB.java 2010-09-06 23:27:18 UTC (rev 3779) +++ trunk/software/host/src/org/reprap/pcb/PCB.java 2010-09-07 14:25:32 UTC (rev 3780) @@ -1,15 +1,28 @@ package org.reprap.pcb; +import java.awt.BorderLayout; +import java.awt.GridLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; import java.io.BufferedReader; -import java.io.BufferedWriter; import java.io.FileNotFoundException; import java.io.IOException; import java.io.PrintStream; import java.io.FileReader; -import java.io.FileWriter; import java.io.File; import java.util.Date; import java.text.SimpleDateFormat; + +import javax.swing.BorderFactory; +import javax.swing.JButton; +import javax.swing.JComponent; +import javax.swing.JDialog; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JTextField; +import javax.swing.SwingConstants; + import org.reprap.Extruder; import org.reprap.Attributes; import org.reprap.Preferences; @@ -20,6 +33,101 @@ //import java.io.IOException; + +class PCBOffsets extends JPanel { + private static final long serialVersionUID = 1L; + private static JDialog dialog; + private static JTextField xo; + private static JTextField yo; + private static double xoff = 10; + private static double yoff = 10; + + private PCBOffsets(RrRectangle rec) + { + super(new BorderLayout()); + JPanel radioPanel; + radioPanel = new JPanel(new GridLayout(0, 1)); + radioPanel.setSize(300,200); + + JLabel jLabel2 = new JLabel(); + radioPanel.add(jLabel2); + jLabel2.setText(" PCB dimensions: " + org.reprap.machines.GCodeRepRap.round(rec.ne().x() - rec.sw().x(), 1) + + "(X) x " + org.reprap.machines.GCodeRepRap.round(rec.ne().y() - rec.sw().y(), 1) + "(Y) mm"); + jLabel2.setHorizontalAlignment(SwingConstants.CENTER); + JLabel jLabel3 = new JLabel(); + radioPanel.add(jLabel3); + jLabel3.setText(" Offsets (X and Y) in mm:"); + jLabel3.setHorizontalAlignment(SwingConstants.CENTER); + xo = new JTextField("10"); + radioPanel.add(xo); + xo.setHorizontalAlignment(SwingConstants.CENTER); + yo = new JTextField("10"); + radioPanel.add(yo); + yo.setHorizontalAlignment(SwingConstants.CENTER); + + + try + { + + JButton okButton = new JButton(); + radioPanel.add(okButton); + okButton.setText("OK"); + okButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent evt) { + OKHandler(); + } + }); + + add(radioPanel, BorderLayout.LINE_START); + setBorder(BorderFactory.createEmptyBorder(20,20,20,20)); + + } catch (Exception ex) + { + System.err.println(ex.toString()); + ex.printStackTrace(); + } + } + + public static void OKHandler() + { + xoff = Double.parseDouble(xo.getText().trim()); + yoff = Double.parseDouble(yo.getText().trim()); + dialog.dispose(); + } + + public static void pcbo(RrRectangle rec) + { + //Create and set up the window. + JFrame f = new JFrame(); + dialog = new JDialog(f, "PCB Offsets"); + dialog.setLocation(500, 400); + dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); + + //Create and set up the content pane. + JComponent newContentPane = new PCBOffsets(rec); + newContentPane.setOpaque(true); //content panes must be opaque + dialog.setContentPane(newContentPane); + + //Display the window. + dialog.pack(); + dialog.setModalityType(JDialog.DEFAULT_MODALITY_TYPE); + dialog.setVisible(true); + } + + + + public static double getXoff() + { + return xoff; + } + + public static double getYoff() + { + return yoff; + } + +} + public class PCB { GerberGCode gerberGcode; @@ -35,8 +143,8 @@ double zFeedRate = 50; double zDown = 0; static final double centreWidth = 0.9; - static final double offsetX=10; - static final double offsetY=10; + static double offsetX=0; + static double offsetY=0; File inputTracksAndPads; File inputDrill; File outputGCodes; @@ -60,8 +168,6 @@ Debug.d("Input: " + inputTracksAndPads.getName()); Debug.d("Output: " + outputGCodes.getName()+"\n"); Debug.d("Pen Width: " + penWidth + " mm"); - Debug.d("Offset X: " + offsetX + " mm"); - Debug.d("Offset Y: " + offsetY + " mm"); createBitmap(); @@ -71,7 +177,7 @@ try { - if(Preferences.loadGlobalBool("DisplaySimulation")) + if(Preferences.loadGlobalBool("DisplaySimulation") && penPaths.size() > 0) { RrGraphics simulationPlot2 = new RrGraphics("PCB pen plotlines"); // if(currentPolygon != null) @@ -218,9 +324,15 @@ bigBox = RrRectangle.union(bigBox, r); } - Debug.d("Surrounding reactangle: " + bigBox); in.close(); + PCBOffsets.pcbo(bigBox); + + offsetX = PCBOffsets.getXoff() - bigBox.sw().x(); + offsetY = PCBOffsets.getYoff() - bigBox.sw().y(); + + bigBox = bigBox.translate(new Rr2Point(PCBOffsets.getXoff(), PCBOffsets.getYoff())); + in = new BufferedReader(new FileReader(inputTracksAndPads)); BooleanGrid pattern = new BooleanGrid(RrCSG.nothing(), bigBox, new Attributes(null, null, null, pcbPen.getAppearance())); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |