Search in sources :

Example 1 with IMappingExperimentBean

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);
    }
}
Also used : ScanRequest(org.eclipse.scanning.api.event.scan.ScanRequest) Shell(org.eclipse.swt.widgets.Shell) ScanBean(org.eclipse.scanning.api.event.scan.ScanBean) IMappingExperimentBean(uk.ac.diamond.daq.mapping.api.IMappingExperimentBean)

Example 2 with IMappingExperimentBean

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");
}
Also used : Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) Label(org.eclipse.swt.widgets.Label) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) IMappingExperimentBean(uk.ac.diamond.daq.mapping.api.IMappingExperimentBean) PostConstruct(javax.annotation.PostConstruct)

Example 3 with IMappingExperimentBean

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();
}
Also used : IMarshallerService(org.eclipse.dawnsci.analysis.api.persistence.IMarshallerService) IMappingExperimentBean(uk.ac.diamond.daq.mapping.api.IMappingExperimentBean) MappingExperimentBean(uk.ac.diamond.daq.mapping.impl.MappingExperimentBean) MappingExperimentView(uk.ac.diamond.daq.mapping.ui.experiment.MappingExperimentView) EPartService(org.eclipse.e4.ui.workbench.modeling.EPartService) IMappingExperimentBeanProvider(uk.ac.diamond.daq.mapping.api.IMappingExperimentBeanProvider) ExecutionException(org.eclipse.core.commands.ExecutionException) IMappingExperimentBean(uk.ac.diamond.daq.mapping.api.IMappingExperimentBean)

Example 4 with IMappingExperimentBean

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"));
}
Also used : IMarshallerService(org.eclipse.dawnsci.analysis.api.persistence.IMarshallerService) ScanRequest(org.eclipse.scanning.api.event.scan.ScanRequest) TomographyCalibrationData(uk.ac.diamond.daq.mapping.api.TomographyCalibrationData) BufferedReader(java.io.BufferedReader) IScriptService(org.eclipse.scanning.api.script.IScriptService) TomographyParams(uk.ac.diamond.daq.mapping.api.TomographyParams) IMappingExperimentBean(uk.ac.diamond.daq.mapping.api.IMappingExperimentBean)

Example 5 with IMappingExperimentBean

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));
}
Also used : Arrays(java.util.Arrays) IMappingExperimentBean(uk.ac.diamond.daq.mapping.api.IMappingExperimentBean) ScanRegion(org.eclipse.scanning.api.points.models.ScanRegion) LoggerFactory(org.slf4j.LoggerFactory) ScanRequest(org.eclipse.scanning.api.event.scan.ScanRequest) CompoundModel(org.eclipse.scanning.api.points.models.CompoundModel) TemplateFileWrapper(uk.ac.diamond.daq.mapping.api.TemplateFileWrapper) ScriptFiles(uk.ac.diamond.daq.mapping.impl.ScriptFiles) Map(java.util.Map) ScannableMotionUnits(gda.device.ScannableMotionUnits) Finder(gda.factory.Finder) PolygonMappingRegion(uk.ac.diamond.daq.mapping.region.PolygonMappingRegion) ConfigWrapper(uk.ac.diamond.daq.mapping.api.ConfigWrapper) Collection(java.util.Collection) Set(java.util.Set) ISampleMetadata(uk.ac.diamond.daq.mapping.api.ISampleMetadata) RectangularROI(org.eclipse.dawnsci.analysis.dataset.roi.RectangularROI) MapPosition(org.eclipse.scanning.api.points.MapPosition) Objects(java.util.Objects) List(java.util.List) IROI(org.eclipse.dawnsci.analysis.api.roi.IROI) IScanModelWrapper(uk.ac.diamond.daq.mapping.api.IScanModelWrapper) ProcessingRequest(org.eclipse.scanning.api.event.scan.ProcessingRequest) ScanMetadata(org.eclipse.scanning.api.scan.models.ScanMetadata) SimpleSampleMetadata(uk.ac.diamond.daq.mapping.impl.SimpleSampleMetadata) Optional(java.util.Optional) ScanBean(org.eclipse.scanning.api.event.scan.ScanBean) CircularMappingRegion(uk.ac.diamond.daq.mapping.region.CircularMappingRegion) IMappingScanRegion(uk.ac.diamond.daq.mapping.api.IMappingScanRegion) LinearROI(org.eclipse.dawnsci.analysis.dataset.roi.LinearROI) IScriptFiles(uk.ac.diamond.daq.mapping.api.IScriptFiles) HashMap(java.util.HashMap) RectangularMappingRegion(uk.ac.diamond.daq.mapping.region.RectangularMappingRegion) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) IDetectorModel(org.eclipse.scanning.api.device.models.IDetectorModel) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) Collectors.toCollection(java.util.stream.Collectors.toCollection) LineMappingRegion(uk.ac.diamond.daq.mapping.region.LineMappingRegion) IScanDefinition(uk.ac.diamond.daq.mapping.api.IScanDefinition) PointROI(org.eclipse.dawnsci.analysis.dataset.roi.PointROI) IGuiGeneratorService(org.eclipse.richbeans.api.generator.IGuiGeneratorService) CircularROI(org.eclipse.dawnsci.analysis.dataset.roi.CircularROI) DetectorModelWrapper(uk.ac.diamond.daq.mapping.impl.DetectorModelWrapper) PointMappingRegion(uk.ac.diamond.daq.mapping.region.PointMappingRegion) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) MetadataType(org.eclipse.scanning.api.scan.models.ScanMetadata.MetadataType) ScriptRequest(org.eclipse.scanning.api.script.ScriptRequest) File(java.io.File) IMapPathModel(org.eclipse.scanning.api.points.models.IMapPathModel) ScriptLanguage(org.eclipse.scanning.api.script.ScriptLanguage) PolygonalROI(org.eclipse.dawnsci.analysis.dataset.roi.PolygonalROI) Collections(java.util.Collections) MappingStageInfo(uk.ac.diamond.daq.mapping.impl.MappingStageInfo) ScanPathModelWrapper(uk.ac.diamond.daq.mapping.impl.ScanPathModelWrapper) IMappingScanRegionShape(uk.ac.diamond.daq.mapping.api.IMappingScanRegionShape) IScanPointGeneratorModel(org.eclipse.scanning.api.points.models.IScanPointGeneratorModel) ScanMetadata(org.eclipse.scanning.api.scan.models.ScanMetadata) SimpleSampleMetadata(uk.ac.diamond.daq.mapping.impl.SimpleSampleMetadata)

Aggregations

IMappingExperimentBean (uk.ac.diamond.daq.mapping.api.IMappingExperimentBean)18 ScanRequest (org.eclipse.scanning.api.event.scan.ScanRequest)7 ScanBean (org.eclipse.scanning.api.event.scan.ScanBean)6 PersistableMappingExperimentBean (uk.ac.diamond.daq.mapping.api.PersistableMappingExperimentBean)6 IMarshallerService (org.eclipse.dawnsci.analysis.api.persistence.IMarshallerService)4 Composite (org.eclipse.swt.widgets.Composite)4 PersistenceException (uk.ac.diamond.daq.application.persistence.service.PersistenceException)4 File (java.io.File)3 Map (java.util.Map)3 Set (java.util.Set)3 PersistenceServiceWrapper (uk.ac.diamond.daq.persistence.manager.PersistenceServiceWrapper)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2 List (java.util.List)2 Optional (java.util.Optional)2 BiFunction (java.util.function.BiFunction)2 Binding (org.eclipse.core.databinding.Binding)2 DataBindingContext (org.eclipse.core.databinding.DataBindingContext)2 IStatus (org.eclipse.core.runtime.IStatus)2