Search in sources :

Example 1 with ObservationManager

use of fr.jmmc.aspro.model.ObservationManager in project aspro by JMMC-OpenDev.

the class TargetEditorDialog method showEditor.

/**
 * Display the model editor using the given target name as the initial selected target
 * @param targetName optional target name to display only the models of this target
 * @param selectedTab name of the selected tab (see TAB_xxx constants)
 * @param userModelFile optional user model file to associate with the current target
 * @return true if the model editor changed anything
 */
public static boolean showEditor(final String targetName, final String selectedTab, final File userModelFile) {
    logger.debug("showing Editor : {}", targetName);
    boolean result = false;
    JDialog dialog = null;
    TargetEditorDialog form = null;
    try {
        final ObservationManager om = ObservationManager.getInstance();
        // Prepare the data model (editable targets and user infos) :
        final TargetEditContext targetEditCtx = om.getMainObservation().createTargetEditContext();
        form = new TargetEditorDialog(targetEditCtx, selectedTab);
        // set target editor instance:
        targetEditor = form;
        // initialise the editor and select the target :
        form.initialize(targetName);
        if (userModelFile != null) {
            form.defineUserModel(userModelFile);
        }
        // 1. Create the dialog
        dialog = new JDialog(App.getFrame(), "Target Editor", true);
        final Dimension dim = new Dimension(800, 700);
        dialog.setMinimumSize(dim);
        dialog.addComponentListener(new ComponentResizeAdapter(dim));
        // 2. Optional: What happens when the dialog closes ?
        dialog.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        // 3. Create components and put them in the dialog
        dialog.add(form);
        // Associate the dialog to the form :
        form.setDialog(dialog);
        // 4. Size the dialog.
        WindowUtils.setClosingKeyboardShortcuts(dialog);
        dialog.pack();
        // Restore, then automatically save window size changes:
        WindowUtils.rememberWindowSize(dialog, TARGET_EDITOR_DIMENSION_KEY);
        // Center it :
        dialog.setLocationRelativeTo(dialog.getOwner());
        // 5. Show it and waits until dialog is not visible or disposed :
        dialog.setVisible(true);
        // get editor result :
        result = form.isResult();
        if (result) {
            logger.debug("update the targets ...");
            // update the complete list of targets and force to update references :
            // and fire target and observation change events :
            om.updateTargets(form.getTargetEditCtx());
        }
    } finally {
        // reset the target editor instance to indicate that the editor is disabled:
        targetEditor = null;
        if (form != null) {
            logger.debug("dispose TargetEditorDialog ...");
            form.dispose();
        }
        if (dialog != null) {
            logger.debug("dispose Model Editor ...");
            dialog.dispose();
        }
    }
    return result;
}
Also used : ComponentResizeAdapter(fr.jmmc.jmcs.gui.component.ComponentResizeAdapter) TargetEditContext(fr.jmmc.aspro.model.TargetEditContext) ObservationManager(fr.jmmc.aspro.model.ObservationManager) Dimension(java.awt.Dimension) JDialog(javax.swing.JDialog)

Example 2 with ObservationManager

use of fr.jmmc.aspro.model.ObservationManager in project aspro by JMMC-OpenDev.

the class ObservabilityPanel method initComponents.

/**
 * Initialize the components (once)
 */
private void initComponents() {
    this.chart = AsproChartUtils.createXYBarChart();
    this.xyPlot = (XYPlot) this.chart.getPlot();
    // change the Range axis (horizontal):
    this.xyPlot.setRangeAxis(new BoundedDateAxis(""));
    // create new JMMC annotation (moving position):
    this.aJMMC = AsproChartUtils.createJMMCAnnotation();
    // define sliding adapter :
    this.slidingXYPlotAdapter = new SlidingXYPlotAdapter(this.chart, this.xyPlot, SlidingXYPlotAdapter.MAX_VIEW_ITEMS, this.aJMMC);
    // add listener :
    this.chart.addProgressListener(this);
    // show tooltips
    this.chartPanel = ChartUtils.createChartPanel(this.chart, true);
    // intercept component resize events:
    this.chartPanel.addComponentListener(new PanelResizeAdapter());
    // zoom options :
    this.chartPanel.setDomainZoomable(true);
    // date axis :
    this.chartPanel.setRangeZoomable(true);
    this.chartPanel.addChartMouseListener(new ChartMouseListener() {

        @Override
        public void chartMouseClicked(final ChartMouseEvent event) {
            final ChartEntity entity = event.getEntity();
            int seriesIndex = -1;
            // only support click on ranges (not text annotations):
            if (entity instanceof XYItemEntity) {
                final XYItemEntity itemEntity = (XYItemEntity) entity;
                seriesIndex = itemEntity.getSeriesIndex();
            } else if (entity instanceof ClickableXYAnnotationEntity) {
                final ClickableXYAnnotationEntity anEntity = (ClickableXYAnnotationEntity) entity;
                seriesIndex = anEntity.getRendererIndex();
                // TODO: finalize interactions
                if (false) {
                    // get object reference:
                    final Object ref = anEntity.getReference();
                    if (ref instanceof Observations) {
                        final Observations obsGroup = (Observations) ref;
                        logger.info("clicked on group [" + obsGroup.getGroupId() + " for " + obsGroup.getTargetId() + "]");
                        StatusBar.show("obs log : " + obsGroup.first().getObsId());
                    /*
                                TODO: show group in table ?
                             */
                    }
                }
            } else if (entity instanceof XYAnnotationEntity) {
                final XYAnnotationEntity anEntity = (XYAnnotationEntity) entity;
                seriesIndex = anEntity.getRendererIndex();
            }
            if (seriesIndex != -1) {
                final ObservationCollectionObsData chartData = getChartData();
                // do not change selection if baseline limits displayed:
                if ((chartData != null) && !chartData.getFirstObsData().isDoBaseLineLimits()) {
                    final int index = slidingXYPlotAdapter.getSeriePosition(seriesIndex);
                    if (logger.isDebugEnabled()) {
                        logger.debug("chartMouseClicked: serie={}, target index={}", seriesIndex, index);
                    }
                    final String targetName = slidingXYPlotAdapter.getTargetName(index);
                    if (targetName != null && !ObjectUtils.areEquals(targetName, selectedTargetName)) {
                        if (logger.isDebugEnabled()) {
                            logger.debug("chartMouseClicked: selectedTargetName={}", targetName);
                        }
                        final ObservationManager om = ObservationManager.getInstance();
                        om.fireTargetSelectionChanged(om.getTarget(targetName));
                    }
                }
            }
        }

        @Override
        public void chartMouseMoved(final ChartMouseEvent event) {
        }
    });
    this.add(this.chartPanel, BorderLayout.CENTER);
    this.scroller = new JScrollBar(JScrollBar.VERTICAL, 0, 0, 0, 0);
    this.scroller.setName("scroller");
    this.scroller.getModel().addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(final ChangeEvent ce) {
            final DefaultBoundedRangeModel model = (DefaultBoundedRangeModel) ce.getSource();
            // update position and repaint the plot:
            slidingXYPlotAdapter.setPosition(model.getValue());
            // update current target from updated position:
            setCurrentTargetName(slidingXYPlotAdapter.getCurrentTargetName());
        }
    });
    // update mouse wheel handler:
    updateMouseWheelHandler(false);
    // Use a panel to define custom margin arround the scroll bar:
    this.scrollerPanel = new JPanel(new BorderLayout());
    this.scrollerPanel.add(this.scroller);
    this.scrollerPanel.setBorder(BorderFactory.createEmptyBorder(20, 0, 20, 0));
    this.scrollerPanel.setBackground(Color.WHITE);
    this.add(this.scrollerPanel, BorderLayout.EAST);
    final JPanel panelOptions = new JPanel(new FlowLayout(FlowLayout.CENTER, 6, 2));
    panelOptions.add(new JLabel("Time:"));
    this.jComboTimeRef = new JComboBox(AsproConstants.TIME_CHOICES);
    this.jComboTimeRef.setName("jComboTimeRef");
    this.jComboTimeRef.setSelectedItem(this.myPreferences.getPreference(Preferences.TIME_REFERENCE));
    this.jComboTimeRef.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent e) {
            refreshPlot();
        }
    });
    panelOptions.add(this.jComboTimeRef);
    this.jCheckBoxNightOnly = new JCheckBox("Night only");
    this.jCheckBoxNightOnly.setName("jCheckBoxNightOnly");
    this.jCheckBoxNightOnly.setSelected(myPreferences.getPreferenceAsBoolean(Preferences.ONLY_NIGHT));
    this.jCheckBoxNightOnly.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(final ItemEvent e) {
            if (getChartData() != null && jCheckBoxNightOnly.isEnabled()) {
                if (e.getStateChange() == ItemEvent.SELECTED) {
                    // Update date axis = zoom on night bounds:
                    if (nightLower != 0d && nightUpper != 0d) {
                        updateDateAxisBounds(nightLower, nightUpper);
                    }
                } else {
                    // full range:
                    final ObservabilityData obsData = getChartData().getFirstObsData();
                    updateDateAxisBounds(obsData.getDateMin().getTime(), obsData.getDateMax().getTime());
                }
            }
        }
    });
    panelOptions.add(this.jCheckBoxNightOnly);
    this.jCheckBoxBaseLineLimits = new JCheckBox("Baseline limits");
    this.jCheckBoxBaseLineLimits.setName("jCheckBoxBaseLineLimits");
    this.jCheckBoxBaseLineLimits.setSelected(DEFAULT_DO_BASELINE_LIMITS);
    this.jCheckBoxBaseLineLimits.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(final ItemEvent e) {
            final boolean doBaseLineLimits = e.getStateChange() == ItemEvent.SELECTED;
            // disable the automatic refresh :
            final boolean prevAutoRefresh = setAutoRefresh(false);
            try {
                if (doBaseLineLimits) {
                    // force LST to compute correctly base line limits :
                    jComboTimeRef.setSelectedItem(TimeRef.LST.getDisplayName());
                    jCheckBoxDetailedOutput.setSelected(false);
                } else {
                    // restore user preference :
                    jComboTimeRef.setSelectedItem(myPreferences.getPreference(Preferences.TIME_REFERENCE));
                }
                jComboTimeRef.setEnabled(!doBaseLineLimits);
                jCheckBoxDetailedOutput.setEnabled(!doBaseLineLimits);
            } finally {
                // restore the automatic refresh :
                setAutoRefresh(prevAutoRefresh);
            }
            refreshPlot();
        }
    });
    panelOptions.add(this.jCheckBoxBaseLineLimits);
    this.jCheckBoxDetailedOutput = new JCheckBox("Details");
    this.jCheckBoxDetailedOutput.setName("jCheckBoxDetailedOutput");
    this.jCheckBoxDetailedOutput.setSelected(DEFAULT_DO_DETAILED_OUTPUT);
    this.jCheckBoxDetailedOutput.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(final ItemEvent e) {
            refreshPlot();
        }
    });
    panelOptions.add(this.jCheckBoxDetailedOutput);
    this.jCheckBoxListFilters = new CheckBoxList(FILTERS) {

        /**
         * default serial UID for Serializable interface
         */
        private static final long serialVersionUID = 1;

        /**
         * This method is called as the cursor moves within the list
         */
        @Override
        public String getToolTipText(final MouseEvent evt) {
            // Get item index :
            final int index = locationToIndex(evt.getPoint());
            if (index != -1) {
                // Get filter:
                final ObservabilityFilter filter = (ObservabilityFilter) getModel().getElementAt(index);
                if (filter != null) {
                    // Return the tool tip text :
                    return filter.getTooltip();
                }
            }
            return getToolTipText();
        }
    };
    this.jCheckBoxListFilters.setName("jCheckBoxListFilters");
    // note: only 1 is ugly on macOS X
    this.jCheckBoxListFilters.setVisibleRowCount(2);
    this.jCheckBoxListFilters.getCheckBoxListSelectionModel().addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(final ListSelectionEvent e) {
            if (!e.getValueIsAdjusting() && getChartData() != null) {
                updatePlot(getChartData());
            }
        }
    });
    panelOptions.add(createSeparator());
    panelOptions.add(new JLabel("Filters:"));
    panelOptions.add(new JScrollPane(this.jCheckBoxListFilters));
    this.jLabelGroups = new JLabel("Groups:");
    panelOptions.add(this.jLabelGroups);
    this.checkBoxListGroups = createCheckBoxList();
    this.checkBoxListGroups.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
    this.checkBoxListGroups.setToolTipText("groups whose target belongs to");
    // note: only 1 is ugly on macOS X
    this.checkBoxListGroups.setVisibleRowCount(2);
    this.checkBoxListGroups.setCellRenderer(TargetGroupRenderer.INSTANCE);
    this.checkBoxListGroups.getCheckBoxListSelectionModel().addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(final ListSelectionEvent e) {
            if (!e.getValueIsAdjusting() && getChartData() != null) {
                updatePlot(getChartData());
            }
        }
    });
    this.jScrollPaneGroups = new JScrollPane(this.checkBoxListGroups);
    panelOptions.add(jScrollPaneGroups);
    this.jCheckBoxShowRelated = new JCheckBox("<html>Show<br>related</html>");
    this.jCheckBoxShowRelated.setName("jCheckBoxShowRelated");
    this.jCheckBoxShowRelated.setToolTipText("If enabled, selected target and its calibrators are always shown (not filtered)");
    this.jCheckBoxShowRelated.setSelected(DEFAULT_DO_SHOW_RELATED);
    this.jCheckBoxShowRelated.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(final ItemEvent e) {
            // refresh the plot:
            updatePlot(getChartData());
        }
    });
    panelOptions.add(this.jCheckBoxShowRelated);
    this.jCheckBoxScrollView = new JCheckBox("Scroll view");
    this.jCheckBoxScrollView.setName("jCheckBoxScrollView");
    this.jCheckBoxScrollView.setToolTipText("<html>If enabled, only few targets are displayed and the plot is scrollable (mousewheel supported)" + "<br>but <b>the exported PDF always contains all targets</b> (multiple page if necessary)" + "<br>If disabled, all targets are displayed and the plot can be zoomed in / out (mouse)" + "<br>but <b>the exported PDF document contains targets as displayed (single page only)</b></html>");
    this.jCheckBoxScrollView.setSelected(DEFAULT_DO_SCROLL_VIEW);
    this.jCheckBoxScrollView.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(final ItemEvent e) {
            // update scrollbar state and repaint the plot:
            updateSliderProperties(false);
        }
    });
    panelOptions.add(createSeparator());
    panelOptions.add(this.jCheckBoxScrollView);
    this.add(panelOptions, BorderLayout.PAGE_END);
    // register this instance as a Preference Observer :
    this.myPreferences.addObserver(this);
}
Also used : JPanel(javax.swing.JPanel) ItemEvent(java.awt.event.ItemEvent) FlowLayout(java.awt.FlowLayout) ObservabilityData(fr.jmmc.aspro.model.observability.ObservabilityData) StarObservabilityData(fr.jmmc.aspro.model.observability.StarObservabilityData) ActionEvent(java.awt.event.ActionEvent) ListSelectionEvent(javax.swing.event.ListSelectionEvent) ObservationManager(fr.jmmc.aspro.model.ObservationManager) ChartMouseEvent(org.jfree.chart.ChartMouseEvent) DefaultBoundedRangeModel(javax.swing.DefaultBoundedRangeModel) JScrollBar(javax.swing.JScrollBar) XYItemEntity(org.jfree.chart.entity.XYItemEntity) BorderLayout(java.awt.BorderLayout) ObservabilityFilter(fr.jmmc.aspro.gui.util.ObservabilityFilter) ChangeListener(javax.swing.event.ChangeListener) ClickableXYAnnotationEntity(fr.jmmc.aspro.gui.chart.ClickableXYAnnotationEntity) XYAnnotationEntity(org.jfree.chart.entity.XYAnnotationEntity) JScrollPane(javax.swing.JScrollPane) ClickableXYAnnotationEntity(fr.jmmc.aspro.gui.chart.ClickableXYAnnotationEntity) ChartMouseEvent(org.jfree.chart.ChartMouseEvent) MouseEvent(java.awt.event.MouseEvent) SlidingXYPlotAdapter(fr.jmmc.aspro.gui.chart.SlidingXYPlotAdapter) JComboBox(javax.swing.JComboBox) BoundedDateAxis(fr.jmmc.oiexplorer.core.gui.chart.BoundedDateAxis) JLabel(javax.swing.JLabel) ChartMouseListener(org.jfree.chart.ChartMouseListener) ListSelectionListener(javax.swing.event.ListSelectionListener) JCheckBox(javax.swing.JCheckBox) ChangeEvent(javax.swing.event.ChangeEvent) ActionListener(java.awt.event.ActionListener) ObservationCollectionObsData(fr.jmmc.aspro.model.ObservationCollectionObsData) CheckBoxList(com.jidesoft.swing.CheckBoxList) ItemListener(java.awt.event.ItemListener) ChartEntity(org.jfree.chart.entity.ChartEntity) Observations(fr.jmmc.aspro.model.rawobs.Observations)

Example 3 with ObservationManager

use of fr.jmmc.aspro.model.ObservationManager in project aspro by JMMC-OpenDev.

the class RawObservationTablePanel method processInstrumentsValueChanged.

/**
 * Called whenever the instrument selection changes.
 * @param e the event that characterizes the change.
 */
private void processInstrumentsValueChanged(final ListSelectionEvent e) {
    // skip events when the user selection is adjusting :
    if (e.getValueIsAdjusting()) {
        return;
    }
    final List<String> selectedInstruments = getSelectedInstruments();
    logger.info("Selected instruments: {}", selectedInstruments);
    final ObservationManager om = ObservationManager.getInstance();
    // Set filters:
    // TODO: store filters
    om.getMainObservation().setRawObsFilterInsNames(selectedInstruments);
    // filter table:
    filterData();
    om.fireTargetObservationsChangedEvents();
}
Also used : ObservationManager(fr.jmmc.aspro.model.ObservationManager)

Example 4 with ObservationManager

use of fr.jmmc.aspro.model.ObservationManager in project aspro by JMMC-OpenDev.

the class SettingPanel method onProcess.

// End of variables declaration//GEN-END:variables
/**
 * Handle the given event on the given observation =
 * add the missing plot panels
 *
 * @param event event
 */
@Override
public void onProcess(final ObservationEvent event) {
    if (logger.isDebugEnabled()) {
        logger.debug("event [{}] process IN", event.getType());
    }
    final ObservationEventType type = event.getType();
    if (type == ObservationEventType.LOADED || type == ObservationEventType.TARGET_CHANGED || type == ObservationEventType.REFRESH) {
        if (type == ObservationEventType.LOADED) {
            resetRawObsPanel();
            // show interferometer map when a file is loaded or the observation is reset :
            final int idx = this.jTabbedPane.indexOfTab(TAB_INTERFEROMETER_MAP);
            if (idx != -1) {
                this.jTabbedPane.setSelectedIndex(idx);
            }
        }
        final ObservationSetting observation = (type == ObservationEventType.REFRESH) ? event.getObservationCollection().getFirstObservation() : event.getObservation();
        if (type == ObservationEventType.TARGET_CHANGED) {
            // retrieve the selected target from its name:
            final Target target = observation.getTarget(observation.getSelectedTargetName());
            // force refresh content:
            this.onTargetSelectionChange(target);
        }
        // Observability panel :
        if (this.observabilityPanel == null) {
            // create the observability panel :
            this.observabilityPanel = new ObservabilityPanel();
            this.observabilityPanel.setName("observabilityPanel");
            // add the observability panel :
            this.jTabbedPane.addTab(TAB_OBSERVABILITY, this.observabilityPanel);
            // register the observability panel as an observation listener :
            ObservationManager.getInstance().register(this.observabilityPanel);
        }
        // UV coverage panel :
        int uvPanelIndex = -1;
        if (this.uvCoveragePanel != null) {
            uvPanelIndex = this.jTabbedPane.indexOfComponent(this.uvCoveragePanel);
        }
        /* disable UV Coverage & OIFits panels for single dishes */
        if (observation.hasTargets() && observation.getInstrumentConfiguration().getStationList().size() > 1) {
            if (uvPanelIndex == -1) {
                // create the uv coverage panel :
                this.uvCoveragePanel = new UVCoveragePanel();
                this.uvCoveragePanel.setName("uvCoveragePanel");
                // add the uv coverage panel :
                this.jTabbedPane.addTab(TAB_UV_COVERAGE, this.uvCoveragePanel);
                // register the uv coverage panel as an observation listener :
                final ObservationManager om = ObservationManager.getInstance();
                om.register(this.uvCoveragePanel);
                if (type == ObservationEventType.REFRESH) {
                    // Fire events to initialize the UV Coverage panel properly:
                    // target selection:
                    om.fireTargetSelectionChanged(this.uvCoveragePanel);
                    // update the instrument settings:
                    om.fireObservationUpdate();
                }
            }
        } else {
            if (uvPanelIndex != -1) {
                // remove the uv panel :
                this.jTabbedPane.removeTabAt(uvPanelIndex);
                // free uv coverage panel references (listeners):
                this.uvCoveragePanel.dispose();
                this.uvCoveragePanel = null;
            }
            if (this.oiFitsViewPanel != null) {
                // remove the OIFits viewer panel :
                this.jTabbedPane.remove(this.oiFitsViewPanel);
                // free OIFits viewer panel references (listeners):
                this.oiFitsViewPanel.dispose();
                this.oiFitsViewPanel = null;
                this.oiFitsViewPanel = null;
            }
        }
    } else if (type == ObservationEventType.TARGET_SELECTION_CHANGED && event instanceof TargetSelectionEvent) {
        this.onTargetSelectionChange(((TargetSelectionEvent) event).getTarget());
    } else if (type == ObservationEventType.OIFITS_DONE && event instanceof OIFitsEvent && ((OIFitsEvent) event).getOIFitsData() != null) {
        // create the OIFits viewer panel if null :
        if (this.oiFitsViewPanel == null) {
            this.oiFitsViewPanel = new OIFitsViewPanel();
            this.oiFitsViewPanel.setName("oiFitsViewer");
            // add the OIFits viewer panel :
            this.jTabbedPane.addTab(TAB_OIFITS_VIEWER, this.oiFitsViewPanel);
            // register the OIFits viewer panel as an observation listener (listener 4) :
            ObservationManager.getInstance().register(this.oiFitsViewPanel);
        }
    }
    // hide tooltip:
    hideTooltip();
    if (logger.isDebugEnabled()) {
        logger.debug("event [{}] process OUT", event.getType());
    }
}
Also used : Target(fr.jmmc.aspro.model.oi.Target) ObservationSetting(fr.jmmc.aspro.model.oi.ObservationSetting) ObservationEventType(fr.jmmc.aspro.model.event.ObservationEventType) TargetSelectionEvent(fr.jmmc.aspro.model.event.TargetSelectionEvent) OIFitsEvent(fr.jmmc.aspro.model.event.OIFitsEvent) ObservationManager(fr.jmmc.aspro.model.ObservationManager)

Example 5 with ObservationManager

use of fr.jmmc.aspro.model.ObservationManager in project aspro by JMMC-OpenDev.

the class SearchCalVOTableHandler method processMessage.

/**
 * Process the given votable
 *
 * @param votable votable to process
 * @param searchCalVersion SearchCal GUI version
 * @return true if the votable was processed i.e. contains proper SearchCal data
 *
 * @throws IOException if an I/O exception occured
 * @throws IllegalArgumentException if the file is not an Observation
 */
static boolean processMessage(final String votable, final String searchCalVersion) throws IOException {
    // use an XSLT to transform the SearchCal votable document to an Aspro 2 Observation:
    final long start = System.nanoTime();
    final String document = XslTransform.transform(votable, XSLT_FILE).trim();
    logger.info("VOTable transformation (XSLT) duration = {} ms.", 1e-6d * (System.nanoTime() - start));
    if (document.length() == 0) {
        logger.debug("document is empty (probably not a SearchCal VOTable)");
        return false;
    }
    logger.debug("document:\n{}", document);
    final ObservationManager om = ObservationManager.getInstance();
    try {
        final ObservationSetting searchCalObservation = om.load(new StringReader(document));
        // check GetStar / SearchCal command:
        final String cmdName = searchCalObservation.getName();
        logger.debug("cmdName: {}", cmdName);
        if (!GET_STAR_NAME.equalsIgnoreCase(cmdName)) {
            // SearchCal case:
            final List<Target> calibrators = searchCalObservation.getTargets();
            final Target scienceTarget;
            if (calibrators.isEmpty()) {
                scienceTarget = null;
            } else {
                // first target is the science target (partial information only):
                scienceTarget = calibrators.remove(0);
                // format the target name:
                scienceTarget.updateNameAndIdentifier();
                logger.debug("science target: {}", scienceTarget);
                if (logger.isDebugEnabled()) {
                    logger.debug("calibrators:");
                    for (Target cal : calibrators) {
                        logger.debug(cal.toString());
                    }
                }
                // @note SCIENCE_DISTANCE_CHECK : filter science target if distance is less than science object detection distance preference (1 arcsec):
                for (Iterator<Target> it = calibrators.iterator(); it.hasNext(); ) {
                    final Target cal = it.next();
                    final BaseValue dist = cal.getCalibratorInfos().getField(CalibratorInformations.FIELD_DISTANCE);
                    if (dist != null) {
                        final double rowDistance = dist.getNumber().doubleValue();
                        // If the distance is close enough to be detected as a science object
                        if (rowDistance < SCIENCE_DETECTION_DISTANCE) {
                            if (logger.isInfoEnabled()) {
                                logger.info("calibrator distance is [{}] - skip this calibrator considered as science object: {} - IDS = {}", rowDistance, cal, cal.getIDS());
                            }
                            it.remove();
                            // reuse science target data to update scienceTarget object:
                            Target.merge(scienceTarget, cal);
                        }
                    }
                }
                // Add the SearchCalGuiVersion parameter to calibrators if missing:
                final StringValue paramSearchCalVersion = new StringValue();
                paramSearchCalVersion.setName(CalibratorInformations.PARAMETER_SCL_GUI_VERSION);
                paramSearchCalVersion.setValue(searchCalVersion);
                for (Target cal : calibrators) {
                    if (cal.getCalibratorInfos().getParameter(CalibratorInformations.PARAMETER_SCL_GUI_VERSION) == null) {
                        cal.getCalibratorInfos().getParameters().add(paramSearchCalVersion);
                    }
                }
            }
            // Use invokeLater to avoid concurrency and ensure that
            // data model is modified and fire events using Swing EDT:
            SwingUtils.invokeEDT(new Runnable() {

                @Override
                public void run() {
                    // check the number of calibrators:
                    if (calibrators.isEmpty()) {
                        MessagePane.showErrorMessage("No calibrator found in SearchCal response !");
                        return;
                    }
                    if (!TargetImporter.confirmImport(calibrators.size())) {
                        return;
                    }
                    // find correct diameter among UD_ for the Aspro instrument band ...
                    // or using alternate diameters (in order of priority): UD, LD, UDDK, DIA12
                    om.defineCalibratorDiameter(calibrators);
                    final TargetEditorDialog targetEditor = TargetEditorDialog.getTargetEditor();
                    // Prepare the data model (editable targets and user infos) :
                    final TargetEditContext editTargetCtx = (targetEditor != null) ? targetEditor.getTargetEditCtx() : om.getMainObservation().createTargetEditContext();
                    final List<Target> editTargets = editTargetCtx.getTargets();
                    final TargetUserInformations editTargetUserInfos = editTargetCtx.getTargetUserInfos();
                    if (logger.isDebugEnabled()) {
                        logger.debug("initial targets:");
                        for (Target t : editTargets) {
                            logger.debug(t.toString());
                        }
                    }
                    // Find any target (id + position) within 5 arcsecs:
                    Target currentScienceTarget = Target.matchTarget(scienceTarget, editTargets);
                    if (currentScienceTarget == null) {
                        logger.info("Target '{}' not found in targets; adding it (partial information).", scienceTarget.getName());
                        editTargets.add(scienceTarget);
                        currentScienceTarget = scienceTarget;
                    }
                    final String report = mergeTargets(editTargets, editTargetUserInfos, currentScienceTarget, calibrators);
                    if (logger.isDebugEnabled()) {
                        logger.debug("updated targets:");
                        for (Target t : editTargets) {
                            logger.debug(t.toString());
                        }
                    }
                    if (targetEditor != null) {
                        // refresh target editor:
                        targetEditor.refreshDialog();
                    } else {
                        // update the complete list of targets and force to update references:
                        // needed to replace old target references by the new calibrator targets:
                        om.updateTargets(editTargetCtx);
                    }
                    if (logger.isInfoEnabled()) {
                        logger.info(report);
                    }
                    // display report message:
                    MessagePane.showMessage(report);
                }
            });
        } else {
            // GetStar case:
            final List<Target> targets = searchCalObservation.getTargets();
            if (logger.isDebugEnabled()) {
                logger.debug("targets:");
                for (Target t : targets) {
                    logger.debug(t.toString());
                }
            }
            // Use invokeLater to avoid concurrency and ensure that
            // data model is modified and fire events using Swing EDT:
            SwingUtils.invokeEDT(new Runnable() {

                @Override
                public void run() {
                    // check the number of targets:
                    if (targets.isEmpty()) {
                        MessagePane.showErrorMessage("No target found in GetStar response !");
                        return;
                    }
                    if (!TargetImporter.confirmImport(targets.size())) {
                        return;
                    }
                    // find correct diameter among UD_ for the Aspro instrument band ...
                    // or using alternate diameters (in order of priority): UD, LD, UDDK, DIA12
                    om.defineCalibratorDiameter(targets);
                    final TargetEditorDialog targetEditor = TargetEditorDialog.getTargetEditor();
                    // Prepare the data model (editable targets and user infos) :
                    final TargetEditContext editTargetCtx = (targetEditor != null) ? targetEditor.getTargetEditCtx() : om.getMainObservation().createTargetEditContext();
                    final List<Target> editTargets = editTargetCtx.getTargets();
                    if (logger.isDebugEnabled()) {
                        logger.debug("initial targets:");
                        for (Target t : editTargets) {
                            logger.debug(t.toString());
                        }
                    }
                    final String report = mergeTargets(editTargets, targets);
                    if (logger.isDebugEnabled()) {
                        logger.debug("updated targets:");
                        for (Target t : editTargets) {
                            logger.debug(t.toString());
                        }
                    }
                    if (targetEditor != null) {
                        // refresh target editor:
                        targetEditor.refreshDialog();
                    } else {
                        // update the complete list of targets and force to update references:
                        // needed to replace old target references by the new calibrator targets:
                        om.updateTargets(editTargetCtx);
                    }
                    if (logger.isInfoEnabled()) {
                        logger.info(report);
                    }
                    // display report message:
                    MessagePane.showMessage(report);
                }
            });
        }
    } catch (IllegalArgumentException iae) {
        // Report both Observation and VOTable in a new IllegalArgumentException to get them in the feedback report:
        throw new IllegalArgumentException("Invalid generated Aspro2 Observation:\n\n" + document + "\n\nSAMP VOTable argument:\n\n" + votable, iae);
    }
    // interpreted as SearchCal votable:
    return true;
}
Also used : ObservationSetting(fr.jmmc.aspro.model.oi.ObservationSetting) BaseValue(fr.jmmc.aspro.model.oi.BaseValue) ObservationManager(fr.jmmc.aspro.model.ObservationManager) Target(fr.jmmc.aspro.model.oi.Target) TargetEditContext(fr.jmmc.aspro.model.TargetEditContext) StringReader(java.io.StringReader) List(java.util.List) TargetUserInformations(fr.jmmc.aspro.model.oi.TargetUserInformations) StringValue(fr.jmmc.aspro.model.oi.StringValue) TargetEditorDialog(fr.jmmc.aspro.gui.TargetEditorDialog)

Aggregations

ObservationManager (fr.jmmc.aspro.model.ObservationManager)9 ObservationSetting (fr.jmmc.aspro.model.oi.ObservationSetting)4 TargetEditContext (fr.jmmc.aspro.model.TargetEditContext)2 FocalInstrumentMode (fr.jmmc.aspro.model.oi.FocalInstrumentMode)2 Target (fr.jmmc.aspro.model.oi.Target)2 TargetConfiguration (fr.jmmc.aspro.model.oi.TargetConfiguration)2 File (java.io.File)2 IOException (java.io.IOException)2 CheckBoxList (com.jidesoft.swing.CheckBoxList)1 TargetEditorDialog (fr.jmmc.aspro.gui.TargetEditorDialog)1 ClickableXYAnnotationEntity (fr.jmmc.aspro.gui.chart.ClickableXYAnnotationEntity)1 SlidingXYPlotAdapter (fr.jmmc.aspro.gui.chart.SlidingXYPlotAdapter)1 ObservabilityFilter (fr.jmmc.aspro.gui.util.ObservabilityFilter)1 ObservationCollectionObsData (fr.jmmc.aspro.model.ObservationCollectionObsData)1 OIFitsEvent (fr.jmmc.aspro.model.event.OIFitsEvent)1 ObservationEventType (fr.jmmc.aspro.model.event.ObservationEventType)1 TargetSelectionEvent (fr.jmmc.aspro.model.event.TargetSelectionEvent)1 ObservabilityData (fr.jmmc.aspro.model.observability.ObservabilityData)1 StarObservabilityData (fr.jmmc.aspro.model.observability.StarObservabilityData)1 BaseValue (fr.jmmc.aspro.model.oi.BaseValue)1