Search in sources :

Example 6 with Settings

use of com.willwinder.universalgcodesender.utils.Settings in project Universal-G-Code-Sender by winder.

the class PendantUITest method testStart.

@Test
public void testStart() throws Exception {
    // This is what we're about to do...
    /* 1. Send two gcode commands via a single http request "G91;G90"
         * expect it to result in two separate calls to sendGcodeCommand, one for each gCode command
         * and because we call substituteValues(), it'll also call updateSystemState
         */
    mockBackend.updateSystemState(EasyMock.anyObject(SystemStateBean.class));
    EasyMock.expect(EasyMock.expectLastCall()).once();
    mockBackend.sendGcodeCommand("G91");
    EasyMock.expect(EasyMock.expectLastCall()).once();
    mockBackend.sendGcodeCommand("G90");
    EasyMock.expect(EasyMock.expectLastCall()).once();
    // 2. Commands
    mockBackend.performHomingCycle();
    EasyMock.expect(EasyMock.expectLastCall()).once();
    mockBackend.killAlarmLock();
    EasyMock.expect(EasyMock.expectLastCall()).once();
    mockBackend.toggleCheckMode();
    EasyMock.expect(EasyMock.expectLastCall()).once();
    mockBackend.send();
    EasyMock.expect(EasyMock.expectLastCall()).once();
    // 3. Call some invalid commands which wont reach the backend.
    // 4. Change the mode to sending and call pause/resume and cancel.
    mockBackend.pauseResume();
    EasyMock.expect(EasyMock.expectLastCall()).once();
    mockBackend.cancel();
    EasyMock.expect(EasyMock.expectLastCall()).once();
    // 5. Adjust machine location.
    mockBackend.adjustManualLocation(1, 2, 3, 4.0, 1.0, UnitUtils.Units.UNKNOWN);
    EasyMock.expect(EasyMock.expectLastCall()).once();
    // 6. Get system state
    mockBackend.updateSystemState(EasyMock.anyObject(SystemStateBean.class));
    EasyMock.expect(EasyMock.expectLastCall()).times(2);
    // 7. Get settings
    Settings settings = new Settings();
    settings.getPendantConfig().getStepSizeList().add(new StepSizeOption("newStepSizeOptionValue", "newStepSizeOptionLabel", false));
    EasyMock.expect(mockBackend.getSettings()).andReturn(settings).once();
    // /////////////////////////
    // Start mock and do it! //
    // /////////////////////////
    EasyMock.replay(mockBackend);
    pendantUI.setPort(23123);
    String url = pendantUI.start().get(0).getUrlString();
    systemState.setControlState(ControlState.COMM_IDLE);
    pendantUI.setSystemState(systemState);
    // test resource handler
    String indexPage = getResponse(url);
    assertTrue(indexPage.contains("$(function()"));
    // 1. Send a command
    getResponse(url + "/sendGcode?gCode=G91%3BG90");
    // 2. Send commands
    getResponse(url + "/sendGcode?gCode=$H");
    getResponse(url + "/sendGcode?gCode=$X");
    getResponse(url + "/sendGcode?gCode=$C");
    getResponse(url + "/sendGcode?gCode=SEND_FILE");
    // 3. Call some invalid commands which wont reach the backend.
    getResponse(url + "/sendGcode?gCode=PAUSE_RESUME_FILE");
    getResponse(url + "/sendGcode?gCode=CANCEL_FILE");
    // 4. Change the mode to sending and call pause/resume and cancel.
    systemState.setControlState(ControlState.COMM_SENDING);
    getResponse(url + "/sendGcode?gCode=PAUSE_RESUME_FILE");
    getResponse(url + "/sendGcode?gCode=CANCEL_FILE");
    // 5. Adjust machine location.
    systemState.setControlState(ControlState.COMM_IDLE);
    String adjustManualLocationResponse = getResponse(url + "/adjustManualLocation?dirX=1&dirY=2&dirZ=3&stepSize=4.0");
    // 6. Get system state
    SystemStateBean systemStateTest = new Gson().fromJson(getResponse(url + "/getSystemState"), SystemStateBean.class);
    assertEquals(ControlState.COMM_IDLE, systemStateTest.getControlState());
    systemState.setControlState(ControlState.COMM_SENDING);
    systemStateTest = new Gson().fromJson(getResponse(url + "/getSystemState"), SystemStateBean.class);
    assertEquals(ControlState.COMM_SENDING, systemStateTest.getControlState());
    // 7. Get settings
    String configResponse = getResponse(url + "/config");
    assertTrue(configResponse.contains("shortCutButtonList"));
    assertTrue(configResponse.contains("newStepSizeOptionValue"));
    // Wrap up.
    pendantUI.stop();
    assertTrue(pendantUI.getServer().isStopped());
    // Verify that all the EasyMock functions were called.
    EasyMock.verify(mockBackend);
}
Also used : StepSizeOption(com.willwinder.universalgcodesender.pendantui.PendantConfigBean.StepSizeOption) Gson(com.google.gson.Gson) Settings(com.willwinder.universalgcodesender.utils.Settings) Test(org.junit.Test)

Example 7 with Settings

use of com.willwinder.universalgcodesender.utils.Settings in project Universal-G-Code-Sender by winder.

the class ConnectionSettingsPanel method restoreDefaults.

@Override
public void restoreDefaults() throws Exception {
    updateComponents(new Settings());
    SettingsFactory.saveSettings(settings);
    save();
}
Also used : AbstractUGSSettings(com.willwinder.universalgcodesender.uielements.helpers.AbstractUGSSettings) Settings(com.willwinder.universalgcodesender.utils.Settings)

Example 8 with Settings

use of com.willwinder.universalgcodesender.utils.Settings in project Universal-G-Code-Sender by winder.

the class AutoLevelerSettingsPanel method updateComponentsInternal.

@Override
protected void updateComponentsInternal(Settings s) {
    this.removeAll();
    Settings.AutoLevelSettings autoLevelSettings = s.getAutoLevelSettings();
    setLayout(new MigLayout("wrap 1", "grow, fill"));
    this.zHeightSpinner.setValue(autoLevelSettings.autoLevelProbeZeroHeight);
    add(this.zHeightSpinner);
    this.probeFeedRate.setValue(autoLevelSettings.probeSpeed);
    add(this.probeFeedRate);
    this.arcSegmentLengthSpinner.setValue(autoLevelSettings.autoLevelArcSliceLength);
    add(this.arcSegmentLengthSpinner);
    this.xOffsetSpinner.setValue(autoLevelSettings.autoLevelProbeOffset.x);
    add(this.xOffsetSpinner);
    this.yOffsetSpinner.setValue(autoLevelSettings.autoLevelProbeOffset.y);
    add(this.yOffsetSpinner);
    this.zOffsetSpinner.setValue(autoLevelSettings.autoLevelProbeOffset.z);
    add(this.zOffsetSpinner);
}
Also used : MigLayout(net.miginfocom.swing.MigLayout) AbstractUGSSettings(com.willwinder.universalgcodesender.uielements.helpers.AbstractUGSSettings) Settings(com.willwinder.universalgcodesender.utils.Settings)

Example 9 with Settings

use of com.willwinder.universalgcodesender.utils.Settings in project Universal-G-Code-Sender by winder.

the class startup method run.

@Override
public void run() {
    System.out.println("Loading LocalizingService...");
    Lookup.getDefault().lookup(LocalizingService.class);
    System.out.println("Loading JogService...");
    Lookup.getDefault().lookup(JogActionService.class);
    System.out.println("Loading ActionService...");
    Lookup.getDefault().lookup(RunActionService.class);
    System.out.println("Loading MacroService...");
    Lookup.getDefault().lookup(MacroService.class);
    System.out.println("Loading SendStatusLineService...");
    Lookup.getDefault().lookup(SendStatusLineService.class);
    System.out.println("Loading SettingsChangedNotificationService...");
    Lookup.getDefault().lookup(SettingsChangedNotificationService.class);
    System.out.println("Loading WindowTitleUpdaterService...");
    Lookup.getDefault().lookup(WindowTitleUpdaterService.class);
    System.out.println("Services loaded!");
    System.out.println("Setting UGP version title.");
    Settings settings = CentralLookup.getDefault().lookup(Settings.class);
    setupVersionInformation(settings);
}
Also used : Settings(com.willwinder.universalgcodesender.utils.Settings)

Example 10 with Settings

use of com.willwinder.universalgcodesender.utils.Settings in project Universal-G-Code-Sender by winder.

the class MacroService method reInitActions.

public void reInitActions() {
    String menuPath = "Menu/Machine/Macros";
    String actionCategory = "Macro";
    String localCategory = Localization.getString("platform.menu.macros");
    String localized = String.format("Menu/%s/%s", Localization.getString("platform.menu.machine"), Localization.getString("platform.menu.macros"));
    try {
        FileObject root = FileUtil.getConfigRoot();
        // Clear out the menu items.
        FileUtil.createFolder(root, menuPath).delete();
        FileUtil.createFolder(root, menuPath);
        String actionPath = "/Actions/" + actionCategory;
        FileUtil.createFolder(root, actionPath).delete();
        // FileObject actionsObject = FileUtil.createFolder(root, actionPath);
        ActionRegistrationService ars = Lookup.getDefault().lookup(ActionRegistrationService.class);
        BackendAPI backend = CentralLookup.getDefault().lookup(BackendAPI.class);
        Settings settings = backend.getSettings();
        int numMacros = settings.getNumMacros();
        for (int i = 0; i < numMacros; i++) {
            Macro m = settings.getMacro(i);
            ars.registerAction(MacroAction.class.getCanonicalName() + "." + m.getName(), m.getName(), actionCategory, localCategory, null, menuPath, localized, new MacroAction(settings, backend, i));
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : BackendAPI(com.willwinder.universalgcodesender.model.BackendAPI) Macro(com.willwinder.universalgcodesender.types.Macro) ActionRegistrationService(com.willwinder.ugs.nbp.lib.services.ActionRegistrationService) FileObject(org.openide.filesystems.FileObject) Settings(com.willwinder.universalgcodesender.utils.Settings)

Aggregations

Settings (com.willwinder.universalgcodesender.utils.Settings)14 Macro (com.willwinder.universalgcodesender.types.Macro)3 IFirmwareSettings (com.willwinder.universalgcodesender.firmware.IFirmwareSettings)2 AbstractUGSSettings (com.willwinder.universalgcodesender.uielements.helpers.AbstractUGSSettings)2 MigLayout (net.miginfocom.swing.MigLayout)2 Test (org.junit.Test)2 Gson (com.google.gson.Gson)1 ActionRegistrationService (com.willwinder.ugs.nbp.lib.services.ActionRegistrationService)1 AbstractController (com.willwinder.universalgcodesender.AbstractController)1 UGSEventListener (com.willwinder.universalgcodesender.listeners.UGSEventListener)1 BackendAPI (com.willwinder.universalgcodesender.model.BackendAPI)1 StepSizeOption (com.willwinder.universalgcodesender.pendantui.PendantConfigBean.StepSizeOption)1 ActionEvent (java.awt.event.ActionEvent)1 Before (org.junit.Before)1 FileObject (org.openide.filesystems.FileObject)1