use of com.willwinder.ugs.nbp.designer.entities.cuttable.Cuttable in project Universal-G-Code-Sender by winder.
the class EntityCellRenderer method getTreeCellRendererComponent.
@Override
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
BackendAPI backendAPI = CentralLookup.getDefault().lookup(BackendAPI.class);
UnitUtils.Units preferredUnits = backendAPI.getSettings().getPreferredUnits();
Object treeObject = getUserObject(value);
if (leaf && treeObject instanceof Cuttable) {
Cuttable cuttable = (Cuttable) treeObject;
CutType cutType = cuttable.getCutType();
double cutDepth = UnitUtils.scaleUnits(UnitUtils.Units.MM, preferredUnits) * cuttable.getTargetDepth();
setIcon(new CutTypeIcon(cutType, CutTypeIcon.Size.SMALL));
if (cutType == CutType.NONE) {
setText(cuttable.getName());
} else {
setText((Utils.toString(cutDepth)) + " " + preferredUnits.abbreviation + " - " + cuttable.getName());
}
} else {
// no tool tip
setToolTipText(null);
}
return this;
}
use of com.willwinder.ugs.nbp.designer.entities.cuttable.Cuttable in project Universal-G-Code-Sender by winder.
the class CuttableEntityV1 method applyCommonAttributes.
@Override
protected void applyCommonAttributes(Entity entity) {
super.applyCommonAttributes(entity);
// We need to make a copy of the transformation to set the affine transformation state and type which is not serialized
entity.setTransform(new AffineTransform(transform.getScaleX(), transform.getShearY(), transform.getShearX(), transform.getScaleY(), transform.getTranslateX(), transform.getTranslateY()));
if (entity instanceof Cuttable) {
((Cuttable) entity).setStartDepth(startDepth);
((Cuttable) entity).setTargetDepth(cutDepth);
((Cuttable) entity).setCutType(CutTypeV1.toCutType(cutType));
}
}
use of com.willwinder.ugs.nbp.designer.entities.cuttable.Cuttable in project Universal-G-Code-Sender by winder.
the class EntityComparatorTest method shouldSortEntitiesForOptimizedDistanceToLargeModels.
@Test
public void shouldSortEntitiesForOptimizedDistanceToLargeModels() {
List<Cuttable> entities = generateEntities(100);
double totalDistance = 0;
for (int i = 1; i < entities.size(); i++) {
totalDistance += entities.get(i - 1).getCenter().distance(entities.get(i).getCenter());
}
double totalDistanceSorted = 0;
entities.sort(new EntityComparator(100, 100));
for (int i = 1; i < entities.size(); i++) {
totalDistanceSorted += entities.get(i - 1).getCenter().distance(entities.get(i).getCenter());
}
assertTrue("Expected optimization of the total distance " + totalDistance + " to be optimized 5 times shorter but was " + totalDistanceSorted, totalDistance / 5 > totalDistanceSorted);
}
use of com.willwinder.ugs.nbp.designer.entities.cuttable.Cuttable in project Universal-G-Code-Sender by winder.
the class SelectionSettingsPanel method stateChanged.
@Override
public void stateChanged(ChangeEvent e) {
if (controller == null || controller.getSelectionManager() == null) {
return;
}
CutType cutType = (CutType) cutTypeComboBox.getSelectedItem();
String fontFamily = (String) fontDropDown.getSelectedItem();
List<Cuttable> cuttables = controller.getSelectionManager().getSelection().stream().filter(Cuttable.class::isInstance).map(Cuttable.class::cast).collect(Collectors.toList());
if (!cuttables.isEmpty()) {
double startDepth = (Double) startDepthSpinner.getValue();
double targetDepth = Math.max((Double) targetDepthSpinner.getValue(), startDepth);
ChangeCutSettingsAction changeCutSettingsAction = new ChangeCutSettingsAction(controller, cuttables, startDepth, targetDepth, cutType);
changeCutSettingsAction.actionPerformed(null);
controller.getUndoManager().addAction(changeCutSettingsAction);
}
controller.getSelectionManager().getSelection().stream().filter(Text.class::isInstance).map(Text.class::cast).forEach(text -> text.setFontFamily(fontFamily));
onEvent(new EntityEvent(controller.getSelectionManager(), EventType.SETTINGS_CHANGED));
}
use of com.willwinder.ugs.nbp.designer.entities.cuttable.Cuttable in project Universal-G-Code-Sender by winder.
the class ChangeCutSettingsAction method actionPerformed.
@Override
public void actionPerformed(ActionEvent e) {
for (Cuttable cuttable : cuttableList) {
cuttable.setStartDepth(newStartDepth);
cuttable.setTargetDepth(newCutDepth);
cuttable.setCutType(newCutType);
}
this.controller.getDrawing().repaint();
}
Aggregations