Skip to content

Commit

Permalink
Add "0.0mm" for materials without thickness. Prevents t-oster#123
Browse files Browse the repository at this point in the history
  • Loading branch information
mgmax committed Apr 7, 2013
1 parent 4559a1a commit 70a1795
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/com/t_oster/visicut/gui/MainView.java
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ public void componentHidden(ComponentEvent ce){}
zoomInMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_ADD, java.awt.event.InputEvent.META_MASK));
zoomOutMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_SUBTRACT, java.awt.event.InputEvent.META_MASK));
}

fixMaterialThicknesses();
fillComboBoxes();
refreshMaterialThicknessesComboBox();

Expand Down Expand Up @@ -356,7 +358,7 @@ private void refreshMaterialComboBox()
}
}
this.ignoreMaterialComboBoxChanges = false;
//hide lasercutter combo box if only one lasercutter available
//hide material combo box if only one material available
boolean materialUiVisible = true;
if (this.materialComboBox.getItemCount() == 1 && MaterialManager.getInstance().getAll().get(0).getMaterialThicknesses().size() == 1)
{
Expand All @@ -370,6 +372,25 @@ private void refreshMaterialComboBox()
this.jLabel1.setVisible(materialUiVisible);
this.jLabel5.setVisible(materialUiVisible);
}

// add a "0.0mm" material thickness if the material has an empty list of thicknesses
private void fixMaterialThicknesses() {
List<MaterialProfile> materials = MaterialManager.getInstance().getAll();
for (MaterialProfile mp: materials) {
if (mp.getMaterialThicknesses().isEmpty()) {
LinkedList<Float> l = new LinkedList<Float>();
l.add((float) 0.0);
mp.setMaterialThicknesses(l);
System.err.println("Found material \"" + mp.getName() + "\" without a thickness entry - this should not happen! Adding a thickness 0.0 for this material. Please report if you find a way to create materials without a thickness.");
try {
MaterialManager.getInstance().save(mp);
} catch(IOException e) {
System.err.println("Failed to fix because of exception " + e);
}

}
}
}

/*
* Initially fills LaserCutter, Material, Object and Mapping ComboBox with all possible Elements
Expand Down Expand Up @@ -1787,13 +1808,15 @@ private void materialMenuItemActionPerformed(java.awt.event.ActionEvent evt)//GE
try
{
MaterialManager.getInstance().setAll(result);
fixMaterialThicknesses();
this.refreshMaterialComboBox();
this.visicutModel1.setMaterial(this.materialComboBox.getSelectedItem() instanceof MaterialProfile ? (MaterialProfile) this.materialComboBox.getSelectedItem() : null);
}
catch (Exception ex)
{
dialog.showErrorMessage(ex);
}

}
}//GEN-LAST:event_materialMenuItemActionPerformed

Expand Down

0 comments on commit 70a1795

Please sign in to comment.