use of org.eclipse.dawnsci.analysis.api.persistence.IMarshallerService in project gda-core by openGDA.
the class ProcessingSection method configureProcessingModel.
private ConfigWrapper configureProcessingModel() {
final List<IOperationSetupWizardPage> startPages = new ArrayList<>(2);
final AcquireDataWizardPage acquirePage = new AcquireDataWizardPage(getEclipseContext());
DawnConfigBean processingConfig = new DawnConfigBean();
ConfigWrapper w = new ConfigWrapper();
final ProcessingSelectionWizardPage selectionPage = new ProcessingSelectionWizardPage(getEclipseContext(), processingConfig, w, getMappingBean().getDetectorParameters());
startPages.add(selectionPage);
final Supplier<ProcessingSelectionWizardPage.ProcessingMode> selectedMode;
selectedMode = selectionPage::selectedMode;
startPages.add(acquirePage);
try {
IOperationModelWizard wizard = getEclipseContext().get(IOperationUIService.class).getWizard(null, startPages, (String) null, null);
OperationModelWizardDialog dialog = new OperationModelWizardDialog(getShell(), wizard);
dialog.setTitle("Setup Processing");
if (dialog.open() == Window.OK) {
if (ProcessingSelectionWizardPage.ProcessingMode.NEW_DAWN.equals(selectedMode.get())) {
try {
final Path processingFilePath = Paths.get(processingConfig.getProcessingFile());
Files.createDirectories(processingFilePath.getParent());
wizard.saveOutputFile(processingFilePath.toString());
} catch (Exception e) {
logger.error("Could not save template file!", e);
}
}
if (!ProcessingSelectionWizardPage.ProcessingMode.OTHER.equals(selectedMode.get())) {
IMarshallerService ms = getEclipseContext().get(IMarshallerService.class);
String json = ms.marshal(processingConfig, false);
try (BufferedWriter wr = new BufferedWriter(new FileWriter(w.getPathToConfig()))) {
wr.write(json);
} catch (Exception e) {
// TODO: dialog!
}
}
return w;
}
} catch (Exception e) {
logger.error("Could not open operation wizard", e);
}
return null;
}
use of org.eclipse.dawnsci.analysis.api.persistence.IMarshallerService in project gda-core by openGDA.
the class MappingXanesTemplateHandler method loadTemplate.
private void loadTemplate(String templatePath) {
final IMappingExperimentBean template;
try {
final byte[] bytes = Files.readAllBytes(Paths.get(templatePath));
final String json = new String(bytes, "UTF-8");
final IMarshallerService marshaller = getService(IMarshallerService.class);
template = marshaller.unmarshal(json, MappingExperimentBean.class);
} catch (Exception e) {
logger.error("Error loading template", e);
MessageDialog.openError(Display.getCurrent().getActiveShell(), "Mapping template", "Could not load map template. Map parameters have not been changed.");
return;
}
final IMappingExperimentBeanProvider beanProvider = getService(IMappingExperimentBeanProvider.class);
final IMappingExperimentBean currentBean = beanProvider.getMappingExperimentBean();
template.getScanDefinition().setMappingScanRegion(currentBean.getScanDefinition().getMappingScanRegion());
beanProvider.setMappingExperimentBean(template);
final MappingExperimentView view = (MappingExperimentView) getService(EPartService.class).findPart(MappingExperimentView.ID).getObject();
view.updateControls();
}
use of org.eclipse.dawnsci.analysis.api.persistence.IMarshallerService in project gda-core by openGDA.
the class TomographyConfigurationDialog method saveCalibrationToFile.
/**
* Save calibration data to a file, so that the Submit button can read it.
*/
private void saveCalibrationToFile() {
CALIBRATION_DIRECTORY_PATH.toFile().mkdirs();
final File outputFile = CALIBRATION_FILE_PATH.toFile();
try (BufferedWriter outputWriter = Files.newBufferedWriter(CALIBRATION_FILE_PATH, CREATE)) {
final IMarshallerService marshallerService = getService(IMarshallerService.class);
final TomographyCalibrationData tomoCalibration = new TomographyCalibrationData(xCalibration, zCalibration);
outputWriter.write(marshallerService.marshal(tomoCalibration));
logger.debug("Calibration data written to {}", CALIBRATION_FILE_PATH);
unsavedCalibration = false;
setButtonStates();
} catch (Exception e) {
final String message = String.format(getClientMessage(TOMO_CALIBRATE_SAVE_FILE_ERROR), outputFile.getName());
handleException(message, e);
}
}
use of org.eclipse.dawnsci.analysis.api.persistence.IMarshallerService in project gda-core by openGDA.
the class TomographySubmitScanSection method submitScan.
@Override
protected void submitScan() {
// Read parameters from file
try (BufferedReader reader = Files.newBufferedReader(CALIBRATION_FILE_PATH)) {
final IScriptService scriptService = getService(IScriptService.class);
final IMarshallerService marshallerService = getService(IMarshallerService.class);
final IMappingExperimentBean mappingBean = getMappingBean();
final TomographyCalibrationData calibrationParams = marshallerService.unmarshal(reader.readLine(), TomographyCalibrationData.class);
final ScanRequest scanRequest = getScanRequest(mappingBean);
final TomographyParams tomoParams = new TomographyParams();
tomoParams.setTomographyCalibration(calibrationParams);
tomoParams.setProcessingFiles(getProcessingFilesAs(mappingBean));
tomoParams.setVisitId(InterfaceProvider.getBatonStateProvider().getBatonHolder().getVisitID());
populateScriptService(scriptService, marshallerService, scanRequest, tomoParams);
} catch (Exception e) {
handleException(getClientMessage(TOMO_CALIBRATE_SUBMIT_ERROR), e);
return;
}
Async.execute(() -> runScript(tomoScanScript, "tomography scanning script"));
}
use of org.eclipse.dawnsci.analysis.api.persistence.IMarshallerService in project gda-core by openGDA.
the class XanesEdgeParametersSection method saveState.
@Override
public void saveState(Map<String, String> persistedState) {
try {
logger.debug("Saving XANES parameters");
final IMarshallerService marshaller = getService(IMarshallerService.class);
persistedState.put(XANES_SCAN_KEY, marshaller.marshal(scanParameters));
} catch (Exception e) {
logger.error("Error saving XANES scan parameters", e);
}
}
Aggregations