use of uk.ac.diamond.daq.mapping.api.IMappingExperimentBean in project gda-core by openGDA.
the class MappingExperimentView method handleOpenRequest.
/**
* @param openRequest
*/
private void handleOpenRequest(OpenRequest openRequest) {
if (!isMappingScanBean(openRequest.getStatusBean())) {
return;
}
ScanBean scanBean = (ScanBean) openRequest.getStatusBean();
String scanName = scanBean.getName();
logger.info("Open Request, Received an open request for ScanBean with the name: {}", scanName);
// Confirm whether this scan should be opened as it will overwrite the contents of the view
Shell shell = (Shell) injectionContext.get(IServiceConstants.ACTIVE_SHELL);
boolean confirm = MessageDialog.openConfirm(shell, "Open Mapping Scan", MessageFormat.format("Do you want to open the scan ''{0}'' in the Mapping Experiment Setup view?\n" + "This will overwrite the current contents of this view.", scanName));
if (!confirm) {
return;
}
// If the scan bean contains a valid reference to a stored mapping bean, use this
if (LocalProperties.isPersistenceServiceAvailable()) {
final ScanManagementController smController = getEclipseContext().get(ScanManagementController.class);
final java.util.Optional<IMappingExperimentBean> savedMappingBean = smController.loadScanMappingBean(scanBean.getMappingBeanId());
if (savedMappingBean.isPresent()) {
mappingBeanProvider.setMappingExperimentBean(savedMappingBean.get());
updateControls();
return;
} else {
logger.warn("No saved mapping bean found for scan id {}. Loading view from ScanRequest", scanBean.getMappingBeanId());
}
}
// Otherwise, get the scan request and merge it into the mapping bean
ScanRequest scanRequest = scanBean.getScanRequest();
try {
scanRequestConverter.mergeIntoMappingBean(scanRequest, mappingBeanProvider.getMappingExperimentBean());
updateControls();
} catch (Exception e) {
logger.error("Error merging scan request into mapping bean.", e);
final String errorMessage = MessageFormat.format("Could not open scan {0}. Could not recreate the mapping view from the queued scan. See the error log for more details.", scanName);
MessageDialog.openError(shell, "Open Results", errorMessage);
}
}
use of uk.ac.diamond.daq.mapping.api.IMappingExperimentBean in project gda-core by openGDA.
the class MappingExperimentView method createView.
@PostConstruct
public void createView(Composite parent, MPart part) {
loadPreviousState(part);
final IMappingExperimentBean mappingBean = mappingBeanProvider.getMappingExperimentBean();
if (mappingBean == null) {
showError("No mapping bean", "Error getting mapping configuration, no mapping bean set");
return;
}
logger.trace("Starting to build the mapping experiment view");
GridLayoutFactory.fillDefaults().applyTo(parent);
GridDataFactory.fillDefaults().applyTo(parent);
parent.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_WHITE));
parent.setBackgroundMode(SWT.INHERIT_FORCE);
scrolledComposite = new ScrolledComposite(parent, SWT.H_SCROLL | SWT.V_SCROLL);
scrolledComposite.setExpandHorizontal(true);
scrolledComposite.setExpandVertical(true);
GridLayoutFactory.fillDefaults().applyTo(scrolledComposite);
GridDataFactory.fillDefaults().grab(true, true).applyTo(scrolledComposite);
Composite alwaysVisible = new Composite(parent, SWT.NONE);
GridLayoutFactory.fillDefaults().applyTo(alwaysVisible);
GridDataFactory.fillDefaults().grab(true, false).applyTo(alwaysVisible);
mainComposite = new Composite(scrolledComposite, SWT.NONE);
GridLayoutFactory.fillDefaults().spacing(SWT.DEFAULT, 1).applyTo(mainComposite);
GridDataFactory.fillDefaults().grab(true, true).applyTo(mainComposite);
scrolledComposite.setContent(mainComposite);
// Separator to distinguish between mainComposite and alwaysVisible composites
GridDataFactory.fillDefaults().span(2, 1).grab(true, false).applyTo(new Label(alwaysVisible, SWT.SEPARATOR | SWT.HORIZONTAL));
// create the controls for sections that should be shown
createSections(mainComposite, getScrolledSections(), part.getPersistedState());
createSections(alwaysVisible, getUnscrolledSections(), part.getPersistedState());
recalculateMinimumSize();
// Check that there is a status panel
statusPanel = getSection(StatusPanel.class);
if (statusPanel == null) {
showError("No status panel", "No status panel defined for this view");
return;
}
statusPanel.setMappingBean(mappingBean);
mainComposite.pack();
logger.trace("Finished building the mapping experiment view");
}
use of uk.ac.diamond.daq.mapping.api.IMappingExperimentBean 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 uk.ac.diamond.daq.mapping.api.IMappingExperimentBean 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 uk.ac.diamond.daq.mapping.api.IMappingExperimentBean in project gda-core by openGDA.
the class ScanRequestConverter method mergeSampleMetadata.
private void mergeSampleMetadata(ScanRequest scanRequest, IMappingExperimentBean mappingBean) {
List<ScanMetadata> scanMetadata = scanRequest.getScanMetadata();
if (scanMetadata == null)
return;
Optional<ScanMetadata> sampleScanMetadataOpt = scanMetadata.stream().filter(metadata -> metadata.getType() == MetadataType.SAMPLE).findFirst();
if (!sampleScanMetadataOpt.isPresent())
return;
ScanMetadata sampleScanMetadata = sampleScanMetadataOpt.get();
SimpleSampleMetadata sampleMetadata = (SimpleSampleMetadata) mappingBean.getSampleMetadata();
if (sampleMetadata == null) {
sampleMetadata = new SimpleSampleMetadata();
mappingBean.setSampleMetadata(sampleMetadata);
}
sampleMetadata.setSampleName((String) sampleScanMetadata.getFieldValue(FIELD_NAME_SAMPLE_NAME));
sampleMetadata.setDescription((String) sampleScanMetadata.getFieldValue(FIELD_NAME_SAMPLE_DESCRIPTION));
}
Aggregations