-
-
Notifications
You must be signed in to change notification settings - Fork 768
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added actions for jogging to the entities extents
- Loading branch information
Showing
59 changed files
with
3,331 additions
and
167 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
...igner/src/main/java/com/willwinder/ugs/nbp/designer/actions/JogMachineAbstractAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.willwinder.ugs.nbp.designer.actions; | ||
|
||
import com.willwinder.ugs.nbp.designer.entities.selection.SelectionEvent; | ||
import com.willwinder.ugs.nbp.designer.entities.selection.SelectionListener; | ||
import com.willwinder.ugs.nbp.designer.entities.selection.SelectionManager; | ||
import com.willwinder.ugs.nbp.designer.logic.ControllerFactory; | ||
import com.willwinder.ugs.nbp.lib.lookup.CentralLookup; | ||
import com.willwinder.universalgcodesender.listeners.ControllerState; | ||
import com.willwinder.universalgcodesender.listeners.UGSEventListener; | ||
import com.willwinder.universalgcodesender.model.BackendAPI; | ||
import com.willwinder.universalgcodesender.model.UGSEvent; | ||
import com.willwinder.universalgcodesender.model.events.ControllerStateEvent; | ||
|
||
import javax.swing.SwingUtilities; | ||
|
||
public abstract class JogMachineAbstractAction extends AbstractDesignAction implements SelectionListener, UGSEventListener { | ||
|
||
private final transient BackendAPI backend; | ||
|
||
protected JogMachineAbstractAction() { | ||
backend = CentralLookup.getDefault().lookup(BackendAPI.class); | ||
backend.addUGSEventListener(this); | ||
registerControllerListener(); | ||
setEnabled(isEnabled()); | ||
} | ||
|
||
private void registerControllerListener() { | ||
SelectionManager selectionManager = ControllerFactory.getController().getSelectionManager(); | ||
selectionManager.addSelectionListener(this); | ||
setEnabled(isEnabled()); | ||
} | ||
|
||
@Override | ||
public boolean isEnabled() { | ||
SelectionManager selectionManager = ControllerFactory.getController().getSelectionManager(); | ||
boolean hasSelection = !selectionManager.getSelection().isEmpty(); | ||
boolean isIdle = backend.getControllerState() == ControllerState.IDLE; | ||
return hasSelection && isIdle; | ||
} | ||
|
||
@Override | ||
public void onSelectionEvent(SelectionEvent selectionEvent) { | ||
setEnabled(isEnabled()); | ||
} | ||
|
||
@Override | ||
public void UGSEvent(UGSEvent event) { | ||
if (event instanceof ControllerStateEvent) { | ||
SwingUtilities.invokeLater(() -> setEnabled(isEnabled())); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
.../main/java/com/willwinder/ugs/nbp/designer/actions/JogMachineToLowerLeftCornerAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
Copyright 2023 Will Winder | ||
This file is part of Universal Gcode Sender (UGS). | ||
UGS is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
UGS is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with UGS. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package com.willwinder.ugs.nbp.designer.actions; | ||
|
||
import com.willwinder.ugs.nbp.designer.logic.ControllerFactory; | ||
import com.willwinder.ugs.nbp.lib.lookup.CentralLookup; | ||
import com.willwinder.ugs.nbp.lib.services.LocalizingService; | ||
import com.willwinder.universalgcodesender.model.PartialPosition; | ||
import static com.willwinder.universalgcodesender.model.UnitUtils.Units.MM; | ||
import com.willwinder.universalgcodesender.services.JogService; | ||
import com.willwinder.universalgcodesender.utils.ThreadHelper; | ||
import org.openide.awt.ActionID; | ||
import org.openide.awt.ActionRegistration; | ||
import org.openide.util.ImageUtilities; | ||
|
||
import java.awt.event.ActionEvent; | ||
import java.awt.geom.Rectangle2D; | ||
|
||
/** | ||
* @author Joacim Breiler | ||
*/ | ||
@ActionID( | ||
category = LocalizingService.CATEGORY_DESIGNER, | ||
id = "JogMachineToLowerLeftCornerAction") | ||
@ActionRegistration( | ||
iconBase = JogMachineToLowerLeftCornerAction.SMALL_ICON_PATH, | ||
displayName = "Jog machine to lower left", | ||
lazy = false) | ||
public class JogMachineToLowerLeftCornerAction extends JogMachineAbstractAction { | ||
public static final String SMALL_ICON_PATH = "img/jog-to-lower-left.svg"; | ||
public static final String LARGE_ICON_PATH = "img/jog-to-lower-left24.svg"; | ||
|
||
public JogMachineToLowerLeftCornerAction() { | ||
super(); | ||
putValue("menuText", "Jog to lower left corner"); | ||
putValue(NAME, "Jog to lower left corner"); | ||
putValue("iconBase", SMALL_ICON_PATH); | ||
putValue(SMALL_ICON, ImageUtilities.loadImageIcon(SMALL_ICON_PATH, false)); | ||
putValue(LARGE_ICON_KEY, ImageUtilities.loadImageIcon(LARGE_ICON_PATH, false)); | ||
} | ||
|
||
@Override | ||
public void actionPerformed(ActionEvent e) { | ||
ThreadHelper.invokeLater(() -> { | ||
Rectangle2D bounds = ControllerFactory.getController().getSelectionManager().getBounds(); | ||
PartialPosition centerPosition = new PartialPosition(bounds.getMinX(), bounds.getMinY(), MM); | ||
|
||
JogService jogService = CentralLookup.getDefault().lookup(JogService.class); | ||
jogService.jogTo(centerPosition); | ||
}); | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
...main/java/com/willwinder/ugs/nbp/designer/actions/JogMachineToLowerRightCornerAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
Copyright 2023 Will Winder | ||
This file is part of Universal Gcode Sender (UGS). | ||
UGS is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
UGS is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with UGS. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package com.willwinder.ugs.nbp.designer.actions; | ||
|
||
import com.willwinder.ugs.nbp.designer.logic.ControllerFactory; | ||
import com.willwinder.ugs.nbp.lib.lookup.CentralLookup; | ||
import com.willwinder.ugs.nbp.lib.services.LocalizingService; | ||
import com.willwinder.universalgcodesender.model.PartialPosition; | ||
import static com.willwinder.universalgcodesender.model.UnitUtils.Units.MM; | ||
import com.willwinder.universalgcodesender.services.JogService; | ||
import com.willwinder.universalgcodesender.utils.ThreadHelper; | ||
import org.openide.awt.ActionID; | ||
import org.openide.awt.ActionRegistration; | ||
import org.openide.util.ImageUtilities; | ||
|
||
import java.awt.event.ActionEvent; | ||
import java.awt.geom.Rectangle2D; | ||
|
||
/** | ||
* @author Joacim Breiler | ||
*/ | ||
@ActionID( | ||
category = LocalizingService.CATEGORY_DESIGNER, | ||
id = "JogMachineToLowerRightCornerAction") | ||
@ActionRegistration( | ||
iconBase = JogMachineToLowerRightCornerAction.SMALL_ICON_PATH, | ||
displayName = "Jog machine to lower right", | ||
lazy = false) | ||
public class JogMachineToLowerRightCornerAction extends JogMachineAbstractAction { | ||
public static final String SMALL_ICON_PATH = "img/jog-to-lower-right.svg"; | ||
public static final String LARGE_ICON_PATH = "img/jog-to-lower-right24.svg"; | ||
|
||
public JogMachineToLowerRightCornerAction() { | ||
super(); | ||
putValue("menuText", "Jog to lower right corner"); | ||
putValue(NAME, "Jog to lower right corner"); | ||
putValue("iconBase", SMALL_ICON_PATH); | ||
putValue(SMALL_ICON, ImageUtilities.loadImageIcon(SMALL_ICON_PATH, false)); | ||
putValue(LARGE_ICON_KEY, ImageUtilities.loadImageIcon(LARGE_ICON_PATH, false)); | ||
} | ||
|
||
@Override | ||
public void actionPerformed(ActionEvent e) { | ||
ThreadHelper.invokeLater(() -> { | ||
Rectangle2D bounds = ControllerFactory.getController().getSelectionManager().getBounds(); | ||
PartialPosition centerPosition = new PartialPosition(bounds.getMaxX(), bounds.getMinY(), MM); | ||
|
||
JogService jogService = CentralLookup.getDefault().lookup(JogService.class); | ||
jogService.jogTo(centerPosition); | ||
}); | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
...rc/main/java/com/willwinder/ugs/nbp/designer/actions/JogMachineToTopLeftCornerAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
Copyright 2023 Will Winder | ||
This file is part of Universal Gcode Sender (UGS). | ||
UGS is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
UGS is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with UGS. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package com.willwinder.ugs.nbp.designer.actions; | ||
|
||
import com.willwinder.ugs.nbp.designer.logic.ControllerFactory; | ||
import com.willwinder.ugs.nbp.lib.lookup.CentralLookup; | ||
import com.willwinder.ugs.nbp.lib.services.LocalizingService; | ||
import com.willwinder.universalgcodesender.model.PartialPosition; | ||
import static com.willwinder.universalgcodesender.model.UnitUtils.Units.MM; | ||
import com.willwinder.universalgcodesender.services.JogService; | ||
import com.willwinder.universalgcodesender.utils.ThreadHelper; | ||
import org.openide.awt.ActionID; | ||
import org.openide.awt.ActionRegistration; | ||
import org.openide.util.ImageUtilities; | ||
|
||
import java.awt.event.ActionEvent; | ||
import java.awt.geom.Rectangle2D; | ||
|
||
/** | ||
* @author Joacim Breiler | ||
*/ | ||
@ActionID( | ||
category = LocalizingService.CATEGORY_DESIGNER, | ||
id = "JogMachineToTopLeftCornerAction") | ||
@ActionRegistration( | ||
iconBase = JogMachineToTopLeftCornerAction.SMALL_ICON_PATH, | ||
displayName = "Jog machine to top left", | ||
lazy = false) | ||
public class JogMachineToTopLeftCornerAction extends JogMachineAbstractAction { | ||
public static final String SMALL_ICON_PATH = "img/jog-to-top-left.svg"; | ||
public static final String LARGE_ICON_PATH = "img/jog-to-top-left24.svg"; | ||
|
||
public JogMachineToTopLeftCornerAction() { | ||
super(); | ||
putValue("menuText", "Jog to top left corner"); | ||
putValue(NAME, "Jog to top left corner"); | ||
putValue("iconBase", SMALL_ICON_PATH); | ||
putValue(SMALL_ICON, ImageUtilities.loadImageIcon(SMALL_ICON_PATH, false)); | ||
putValue(LARGE_ICON_KEY, ImageUtilities.loadImageIcon(LARGE_ICON_PATH, false)); | ||
} | ||
|
||
@Override | ||
public void actionPerformed(ActionEvent e) { | ||
ThreadHelper.invokeLater(() -> { | ||
Rectangle2D bounds = ControllerFactory.getController().getSelectionManager().getBounds(); | ||
PartialPosition centerPosition = new PartialPosition(bounds.getMinX(), bounds.getMaxY(), MM); | ||
|
||
JogService jogService = CentralLookup.getDefault().lookup(JogService.class); | ||
jogService.jogTo(centerPosition); | ||
}); | ||
} | ||
} |
Oops, something went wrong.