From 706f0caab072744af29c2302cbe2c6c51af973fc Mon Sep 17 00:00:00 2001 From: gobbo_a Date: Thu, 14 Aug 2025 13:23:01 +0200 Subject: [PATCH] Initial Commit --- .gitignore | 18 + athos-screens/build.gradle | 1 + build.gradle | 82 +++ gradle/wrapper/gradle-wrapper.properties | 7 + gradlew | 252 ++++++++ gradlew.bat | 94 +++ psss-panel/build.gradle | 1 + screenpanel-sf/build.gradle | 9 + .../src/main/java/ScreenPanelSF.form | 243 +++++++ .../src/main/java/ScreenPanelSF.java | 582 +++++++++++++++++ screenpanel-sls/build.gradle | 9 + .../src/main/java/ScreenPanelSLS.form | 242 +++++++ .../src/main/java/ScreenPanelSLS.java | 600 ++++++++++++++++++ settings.gradle | 7 + 14 files changed, 2147 insertions(+) create mode 100644 .gitignore create mode 100644 athos-screens/build.gradle create mode 100644 build.gradle create mode 100644 gradle/wrapper/gradle-wrapper.properties create mode 100755 gradlew create mode 100644 gradlew.bat create mode 100644 psss-panel/build.gradle create mode 100644 screenpanel-sf/build.gradle create mode 100755 screenpanel-sf/src/main/java/ScreenPanelSF.form create mode 100755 screenpanel-sf/src/main/java/ScreenPanelSF.java create mode 100644 screenpanel-sls/build.gradle create mode 100755 screenpanel-sls/src/main/java/ScreenPanelSLS.form create mode 100755 screenpanel-sls/src/main/java/ScreenPanelSLS.java create mode 100644 settings.gradle diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7bd6fb7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,18 @@ +**/build +**/target +**/home +**/nbproject +**/.nb-gradle +**/.gradle +**/*.dll +**/.*~ +**/*.jar +**/*.log +**/gradle.properties +**/.nb-gradle-properties +**/nbactions.xml +**/*.class +**/lib/ +**/src/main/python/pshell/__pycache__/ +**/src/main/assembly/script/Lib/__pycache__/ +/.jython_cache/ diff --git a/athos-screens/build.gradle b/athos-screens/build.gradle new file mode 100644 index 0000000..dd6d668 --- /dev/null +++ b/athos-screens/build.gradle @@ -0,0 +1 @@ +description = 'athos-screens' diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..aeb622c --- /dev/null +++ b/build.gradle @@ -0,0 +1,82 @@ +plugins { + id("com.gradleup.shadow") version "8.3.8" + id("com.netflix.nebula.rpm") version "11.11.2" + id("maven-publish") +} + +allprojects { + version = '2.0.0' + group = 'ch.psi' + ext.release = '1' + ext.app_jdk = '21' + ext.jar_suffix = 'fat' + + + repositories { + mavenLocal() + mavenCentral() + maven { url "https://maven.scijava.org/" } + //maven { url 'https://www.jitpack.io' } + maven { + credentials { + username = githubUser + password = githubPwd + } + url "https://maven.pkg.github.com/paulscherrerinstitute/jcae" + } + maven { + credentials { + username = githubUser + password = githubPwd + } + url = "https://maven.pkg.github.com/paulscherrerinstitute/bsread_java" + } + maven { url "https://maven.scijava.org/content/repositories/public/" } + //maven { url "https://artifacts.psi.ch/artifactory/libs-snapshots-local/" } + } + +} + +subprojects { + plugins.apply('java') + plugins.apply('java-library') + plugins.apply('com.gradleup.shadow') + plugins.apply('com.netflix.nebula.rpm') + plugins.apply('maven-publish') + + ext.timestamp = new Date().format("yyMMddHHmm") + ext.manif_addopens = 'java.base/sun.nio.ch java.base/java.io java.desktop/sun.awt java.desktop/javax.swing.text.html java.desktop/sun.swing java.base/jdk.internal.loader jdk.nashorn.internal.runtime java.base/java.util' + ext.run_addopens = 'java.base/jdk.internal.loader=ALL-UNNAMED java.base/java.util=ALL-UNNAMED' + ext.run_addexports = "java.desktop/sun.awt=ALL-UNNAMED" + ext.run_jvargs = ["--add-opens", "java.base/jdk.internal.loader=ALL-UNNAMED", "--add-opens", "java.base/java.util=ALL-UNNAMED", "--add-exports", "java.desktop/sun.awt=ALL-UNNAMED"] + + if (hasProperty('java_exec_jdk')) { + ext.java_exec_jdk= java_exec_jdk + if (java_exec_jdk!=null) System.out.println "Execution JDK:" + java_exec_jdk + } else { + ext.java_exec_jdk = null + } + + if (!hasProperty('runArgs')) { + ext.arguments = '' + } else { + ext.arguments = runArgs.split (" ") + } + + ext.createDefaultTasks = { Project project -> + ['run', 'debug'].each { taskName -> + project.tasks.register(taskName, JavaExec) { + dependsOn 'classes' + systemProperty 'build.time', project.timestamp + mainClass = project.mainClass + classpath = project.sourceSets.main.runtimeClasspath + args project.hasProperty('arguments') ? project.arguments : [] + ignoreExitValue = true + debug = (taskName == 'debug') + executable = project.java_exec_jdk + jvmArgs = project.run_jvargs + } + } + + } +} diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..9355b41 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,7 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip +networkTimeout=10000 +validateDistributionUrl=true +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew new file mode 100755 index 0000000..f5feea6 --- /dev/null +++ b/gradlew @@ -0,0 +1,252 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s +' "$PWD" ) || exit + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..9b42019 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,94 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem +@rem SPDX-License-Identifier: Apache-2.0 +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 0 goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/psss-panel/build.gradle b/psss-panel/build.gradle new file mode 100644 index 0000000..bcf0cc7 --- /dev/null +++ b/psss-panel/build.gradle @@ -0,0 +1 @@ +description = 'psss-panel' diff --git a/screenpanel-sf/build.gradle b/screenpanel-sf/build.gradle new file mode 100644 index 0000000..be9b1d5 --- /dev/null +++ b/screenpanel-sf/build.gradle @@ -0,0 +1,9 @@ +description = 'screenpanel-sf' +ext.mainClass = hasProperty('mainClass') ? mainClass : 'ScreenPanelSF' + +dependencies { + implementation 'ch.psi:workbench:' + version + implementation 'ch.psi:screenpanel:' + version + + createDefaultTasks(project) +} \ No newline at end of file diff --git a/screenpanel-sf/src/main/java/ScreenPanelSF.form b/screenpanel-sf/src/main/java/ScreenPanelSF.form new file mode 100755 index 0000000..65faa3f --- /dev/null +++ b/screenpanel-sf/src/main/java/ScreenPanelSF.form @@ -0,0 +1,243 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/screenpanel-sf/src/main/java/ScreenPanelSF.java b/screenpanel-sf/src/main/java/ScreenPanelSF.java new file mode 100755 index 0000000..5d295e2 --- /dev/null +++ b/screenpanel-sf/src/main/java/ScreenPanelSF.java @@ -0,0 +1,582 @@ +import ch.psi.pshell.bs.StreamCamera; +import ch.psi.pshell.camserver.PipelineSource; +import ch.psi.pshell.data.DataManager; +import ch.psi.pshell.device.Device; +import ch.psi.pshell.epics.DiscretePositioner; +import ch.psi.pshell.epics.ChannelInteger; +import ch.psi.pshell.epics.Epics; +import ch.psi.pshell.imaging.Overlay; +import ch.psi.pshell.imaging.Overlays; +import ch.psi.pshell.imaging.Source; +import ch.psi.pshell.workbench.App; +import ch.psi.pshell.framework.Context; +import ch.psi.pshell.framework.Panel; +import ch.psi.pshell.framework.Setup; +import ch.psi.pshell.utils.Elog; +import ch.psi.pshell.utils.State; +import ch.psi.pshell.swing.SwingUtils; +import ch.psi.pshell.swing.SwingUtils.OptionResult; +import ch.psi.pshell.swing.SwingUtils.OptionType; +import ch.psi.pshell.screenpanel.Options; +import ch.psi.pshell.screenpanel.CamServerViewer; +import ch.psi.pshell.utils.Str; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.io.IOException; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.swing.DefaultComboBoxModel; +import javax.swing.JComboBox; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JTextField; +import javax.swing.SwingUtilities; + +/** + * + */ +public class ScreenPanelSF extends Panel implements CamServerViewer.CamServerViewerListener{ + + public static final String LASER_TYPE = "Laser"; + public static final String ELECTRONS_TYPE = "Electrons"; + public static final String PHOTONICS_TYPE = "Photonics"; + public static final String TWO_PULSES_TYPE = "2Pulses"; + + DiscretePositioner screen; + DiscretePositioner filter; + final Logger logger; + + static public void main(String[] args) { + ch.psi.pshell.workbench.Options.add(); + ch.psi.pshell.screenpanel.Options.add(); + App.init(args); + App.create(); + } + + public ScreenPanelSF() { + logger = Logger.getLogger(getClass().getName()); + initComponents(); + panelPulse.setVisible(false); + panelScreen.setVisible(false); + panelFilter.setVisible(false); + camServerViewer.setListener(this); + this.remove(customPanel); + + camServerViewer.getCustomPanel().add(customPanel); + camServerViewer.applyOptions(); + camServerViewer.setSidePanelVisible(true); + camServerViewer.setShowFit(true); + camServerViewer.setShowProfile(true); + camServerViewer.setShowReticle(true); + } + + @Override + public void onStart() { + super.onStart(); + try { + SwingUtilities.invokeLater(()->{ + try { + camServerViewer.initialize(App.getArgumentValue(Options.SP_MODE.getString(null))); + } catch (Exception ex) { + Logger.getLogger(ScreenPanelSF.class.getName()).log(Level.SEVERE, null, ex); + } + updateDialogTitle(); + }); + + } catch (Exception ex) { + logger.log(Level.SEVERE, null, ex); + } + } + + @Override + public void onStop() { + super.onStop(); + } + + + + @Override + public void onStateChange(State state, State former) { + + } + + @Override + public void onExecutedFile(String fileName, Object result) { + } + + //Callback to perform update - in event thread + @Override + protected void doUpdate() { + } + + Thread devicesInitTask; + + + State state; + void checkAppState(){ + if (Setup.isDetached()){ + State state = App.getInstance().getState(); + StreamCamera camera = camServerViewer.getCamera(); + if (state.isInitialized()){ + state = (camera == null) ? state : camera.getState(); + } + if (state!=this.state){ + App.getInstance().getPropertyChangeSupport().firePropertyChange("appstate", this.state, state); + this.state = state; + } + } + } + + + @Override + protected void onTimer() { + for (Device dev : new Device[]{screen, filter}) { + if (dev != null) { + dev.request(); + } + } + + checkAppState(); + + if (App.hasArgument("s")) { + try { + ((Source) getDevice("image")).initialize(); + } catch (IOException ex) { + logger.log(Level.SEVERE, null, ex); + } catch (InterruptedException ex) { + logger.log(Level.SEVERE, null, ex); + } + } + try { + if (panelPulse.isVisible()){ + CamServerViewer.Frame frame = camServerViewer.getCurrentFrame(); + Object pulse = null; + try{ + pulse = frame.cache.getValue("pulse"); + } catch (Exception ex) { + } + textPulse.setText((pulse==null) ? "" : Str.toString(pulse)); + } + } catch (Exception ex) { + ex.printStackTrace(); + } + } + + @Override + public void onOpeningStream(String name) throws Exception { + System.out.println("Initializing stream " + name); + if ((devicesInitTask != null) && (devicesInitTask.isAlive())) { + devicesInitTask.interrupt(); + } + if (screen != null) { + screen.close(); + screen = null; + } + if (filter != null) { + filter.close(); + filter = null; + } + updateDialogTitle(); + } + + + @Override + public void onOpenedStream(String name, String instance) throws Exception { + + System.out.println("Initialized instance: " + instance); + String cameraName = camServerViewer.getCameraName(); + boolean electrons = (cameraName!=null) && camServerViewer.getCameraTypes(cameraName).contains(ELECTRONS_TYPE); + boolean twoPulses = (cameraName!=null) && camServerViewer.getCameraTypes(cameraName).contains(TWO_PULSES_TYPE); + comboScreen.setModel(new DefaultComboBoxModel()); + comboScreen.setEnabled(false); + comboFilter.setModel(new DefaultComboBoxModel()); + comboFilter.setEnabled(false); + panelFilter.setVisible(electrons); + panelScreen.setVisible(electrons); + panelPulse.setVisible(twoPulses); + textPulse.setText(""); + if (cameraName!=null){ + if (electrons) { + //Parallelizing initialization + devicesInitTask = new Thread(() -> { + try { + if (cameraName.contains("DSRM")) { + screen = new DiscretePositioner("CurrentScreen", cameraName + ":POSITION_SP", cameraName + ":POSITION"); + } else { + screen = new DiscretePositioner("CurrentScreen", cameraName + ":SET_SCREEN1_POS", cameraName + ":GET_SCREEN1_POS"); + } + screen.setMonitored(true); + screen.initialize(); + DefaultComboBoxModel model = new DefaultComboBoxModel(); + for (String pos : screen.getPositions()) { + model.addElement(pos); + } + comboScreen.setModel(model); + comboScreen.setSelectedItem(screen.read()); + + } catch (Exception ex) { + comboScreen.setModel(new DefaultComboBoxModel()); + System.err.println(ex.getMessage()); + screen = null; + } + comboScreen.setEnabled(screen != null); + valueScreen.setDevice(screen); + + try { + filter = new DiscretePositioner("CurrentFilter", cameraName + ":SET_FILTER", cameraName + ":GET_FILTER"); + filter.setMonitored(true); + filter.initialize(); + DefaultComboBoxModel model = new DefaultComboBoxModel(); + for (String pos : filter.getPositions()) { + model.addElement(pos); + } + comboFilter.setModel(model); + comboFilter.setSelectedItem(filter.read()); + } catch (Exception ex) { + System.err.println(ex.getMessage()); + filter = null; + } + comboFilter.setEnabled(filter != null); + valueFilter.setDevice(filter); + }); + devicesInitTask.start(); + } + } + updateDialogTitle(); + } + + public void onSavedSnapshot(String name, String instancee, String snapshotFile) throws Exception { + JPanel panel = new JPanel(); + GridBagLayout layout = new GridBagLayout(); + layout.columnWidths = new int[]{0, 180}; //Minimum width + layout.rowHeights = new int[]{30, 30, 30}; //Minimum height + panel.setLayout(layout); + JComboBox comboLogbook = new JComboBox(new String[]{"SwissFEL commissioning data", "SwissFEL commissioning"}); + JTextField textComment = new JTextField(); + GridBagConstraints c = new GridBagConstraints(); + c.gridx = 0; + c.gridy = 0; + panel.add(new JLabel("Data file:"), c); + c.gridy = 1; + panel.add(new JLabel("Logbook:"), c); + c.gridy = 2; + panel.add(new JLabel("Comment:"), c); + c.fill = GridBagConstraints.HORIZONTAL; + c.gridx = 1; + panel.add(textComment, c); + c.gridy = 1; + panel.add(comboLogbook, c); + c.gridy = 0; + panel.add(new JLabel(Context.getInterpreter().getExecutionPars().getPath()), c); + + if (SwingUtils.showOption(getTopLevel(), "Success", panel, OptionType.OkCancel) == OptionResult.Yes) { + StringBuilder message = new StringBuilder(); + message.append("Camera: ").append(name).append("\n"); + message.append("Screen: ").append(String.valueOf(valueScreen.getLabel().getText())).append("\n"); + message.append("Filter: ").append(String.valueOf(valueFilter.getLabel().getText())).append("\n"); + message.append("Data file: ").append(Context.getInterpreter().getExecutionPars().getPath()).append("\n"); + message.append("Comment: ").append(textComment.getText()).append("\n"); + //Add slicing message + Overlay[] fitOv = camServerViewer.getFitOverlays(); + if ((fitOv != null) && (fitOv.length > 5) && (fitOv[fitOv.length - 1] instanceof Overlays.Text)) { + Overlays.Text text = (Overlays.Text) fitOv[fitOv.length - 1]; + message.append(text.getText()).append("\n"); + } + Elog.log((String) comboLogbook.getSelectedItem(), "ScreenPanel Snapshot", message.toString(), new String[]{snapshotFile}); + } + } + + public void onSavingImages(String name, String instance, DataManager dm, String pathRoot) throws IOException{ + if (camServerViewer.getTypes().contains(ELECTRONS_TYPE)) { + dm.setAttribute(pathRoot, "Screen", String.valueOf(valueScreen.getLabel().getText())); + dm.setAttribute(pathRoot, "Filter", String.valueOf(valueFilter.getLabel().getText())); + } + } + + void updateDialogTitle() { + if (Setup.isDetached()) { + getTopLevel().setTitle(camServerViewer.getInstanceName() == null ? "ScreenPanel" : camServerViewer.getInstanceName()); + } + } + + void setLaserState(int bunch, boolean value) throws Exception { + System.out.println("Setting laser state: " + value + " - bunch" + bunch); + //Epics.putq("SIN-TIMAST-TMA:Beam-Las-Delay-Sel", value ? 0 : 1); + if ((bunch<=0) || (bunch==1)){ + Epics.putq("SIN-TIMAST-TMA:Bunch-1-OnDelay-Sel", value ? 0 : 1); + } + if ((bunch<=0) || (bunch==2)){ + Epics.putq("SIN-TIMAST-TMA:Bunch-2-OnDelay-Sel", value ? 0 : 1); + } + + Epics.putq("SIN-TIMAST-TMA:Beam-Apply-Cmd.PROC", 1); + Thread.sleep(3000); + } + + boolean getLaserState(int bunch) throws Exception { + //return (Epics.get("SIN-TIMAST-TMA:Beam-Las-Delay-Sel", Integer.class) == 0); + try{ + if (bunch<=0){ + return getLaserState(1) && getLaserState(2); + } + if (bunch==2){ + return (Epics.get("SWISSFEL-STATUS:Bunch-2-OnDelay-Sel", Integer.class) == 0); + } + return (Epics.get("SWISSFEL-STATUS:Bunch-1-OnDelay-Sel", Integer.class) == 0); + } catch (Exception ex){ + return false; + } + } + + + //////// + @SuppressWarnings("unchecked") + // //GEN-BEGIN:initComponents + private void initComponents() { + + buttonGroup1 = new javax.swing.ButtonGroup(); + buttonGroup2 = new javax.swing.ButtonGroup(); + buttonGroup3 = new javax.swing.ButtonGroup(); + buttonGroup4 = new javax.swing.ButtonGroup(); + jProgressBar1 = new javax.swing.JProgressBar(); + customPanel = new javax.swing.JPanel(); + panelScreen = new javax.swing.JPanel(); + valueScreen = new ch.psi.pshell.swing.DeviceValuePanel(); + comboScreen = new javax.swing.JComboBox(); + panelFilter = new javax.swing.JPanel(); + valueFilter = new ch.psi.pshell.swing.DeviceValuePanel(); + comboFilter = new javax.swing.JComboBox(); + panelPulse = new javax.swing.JPanel(); + buttonPulse1 = new javax.swing.JButton(); + buttonPulse2 = new javax.swing.JButton(); + textPulse = new javax.swing.JTextField(); + camServerViewer = new ch.psi.pshell.screenpanel.CamServerViewer(); + + setPreferredSize(new java.awt.Dimension(873, 600)); + setLayout(new java.awt.BorderLayout()); + + panelScreen.setBorder(javax.swing.BorderFactory.createTitledBorder("Screen")); + + comboScreen.setEnabled(false); + comboScreen.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + comboScreenActionPerformed(evt); + } + }); + + javax.swing.GroupLayout panelScreenLayout = new javax.swing.GroupLayout(panelScreen); + panelScreen.setLayout(panelScreenLayout); + panelScreenLayout.setHorizontalGroup( + panelScreenLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(panelScreenLayout.createSequentialGroup() + .addContainerGap() + .addGroup(panelScreenLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(valueScreen, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(comboScreen, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addContainerGap()) + ); + panelScreenLayout.setVerticalGroup( + panelScreenLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelScreenLayout.createSequentialGroup() + .addGap(4, 4, 4) + .addComponent(comboScreen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(valueScreen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addContainerGap()) + ); + + panelFilter.setBorder(javax.swing.BorderFactory.createTitledBorder("Filter")); + + comboFilter.setEnabled(false); + comboFilter.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + comboFilterActionPerformed(evt); + } + }); + + javax.swing.GroupLayout panelFilterLayout = new javax.swing.GroupLayout(panelFilter); + panelFilter.setLayout(panelFilterLayout); + panelFilterLayout.setHorizontalGroup( + panelFilterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(panelFilterLayout.createSequentialGroup() + .addContainerGap() + .addGroup(panelFilterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(valueFilter, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(comboFilter, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addContainerGap()) + ); + panelFilterLayout.setVerticalGroup( + panelFilterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelFilterLayout.createSequentialGroup() + .addGap(4, 4, 4) + .addComponent(comboFilter, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(valueFilter, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + ); + + panelPulse.setBorder(javax.swing.BorderFactory.createTitledBorder("Pulse")); + + buttonPulse1.setText("Pulse 1"); + buttonPulse1.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + buttonPulse1ActionPerformed(evt); + } + }); + + buttonPulse2.setText("Pulse 2"); + buttonPulse2.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + buttonPulse2ActionPerformed(evt); + } + }); + + textPulse.setEditable(false); + textPulse.setHorizontalAlignment(javax.swing.JTextField.CENTER); + + javax.swing.GroupLayout panelPulseLayout = new javax.swing.GroupLayout(panelPulse); + panelPulse.setLayout(panelPulseLayout); + panelPulseLayout.setHorizontalGroup( + panelPulseLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(panelPulseLayout.createSequentialGroup() + .addContainerGap() + .addComponent(buttonPulse1) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(buttonPulse2) + .addGap(18, 18, Short.MAX_VALUE) + .addComponent(textPulse, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE) + .addContainerGap()) + ); + + panelPulseLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {buttonPulse1, buttonPulse2}); + + panelPulseLayout.setVerticalGroup( + panelPulseLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(panelPulseLayout.createSequentialGroup() + .addGroup(panelPulseLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(buttonPulse1, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(buttonPulse2, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(textPulse, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addContainerGap()) + ); + + javax.swing.GroupLayout customPanelLayout = new javax.swing.GroupLayout(customPanel); + customPanel.setLayout(customPanelLayout); + customPanelLayout.setHorizontalGroup( + customPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(customPanelLayout.createSequentialGroup() + .addGap(0, 0, 0) + .addGroup(customPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) + .addComponent(panelScreen, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(panelFilter, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(panelPulse, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addGap(0, 0, 0)) + ); + customPanelLayout.setVerticalGroup( + customPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(customPanelLayout.createSequentialGroup() + .addGap(0, 0, 0) + .addComponent(panelScreen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(panelFilter, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(panelPulse, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + ); + + add(customPanel, java.awt.BorderLayout.WEST); + add(camServerViewer, java.awt.BorderLayout.CENTER); + }// //GEN-END:initComponents + + private void comboScreenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboScreenActionPerformed + + comboScreen.setEnabled(false); + new Thread(new Runnable() { + @Override + public void run() { + ChannelInteger setpoint = null; + try { + int index = comboScreen.getSelectedIndex(); + if (index >= 0) { + String cameraName = camServerViewer.getCameraName(); + if (cameraName.contains("DSRM")) { + setpoint = new ChannelInteger(null, cameraName + ":POSITION_SP"); + } else { + setpoint = new ChannelInteger(null, cameraName + ":SET_SCREEN1_POS"); + } + setpoint.initialize(); + Integer readback = setpoint.read(); + if ((readback == null) || (setpoint.read() != index)) { + setpoint.write(index); + } + screen.read(); + } + } catch (Exception ex) { + showException(ex); + } finally { + comboScreen.setEnabled(true); + if (setpoint != null) { + setpoint.close(); + } + } + } + }).start(); + }//GEN-LAST:event_comboScreenActionPerformed + + private void comboFilterActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboFilterActionPerformed + try { + String setpoint = (String) comboFilter.getSelectedItem(); + if (setpoint != null) { + if (!setpoint.equals(filter.read())) { + filter.write(setpoint); + } + } + } catch (Exception ex) { + showException(ex); + } + }//GEN-LAST:event_comboFilterActionPerformed + + private void buttonPulse1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonPulse1ActionPerformed + try { + PipelineSource server = camServerViewer.getServer(); + if ((server != null) && (server.isStarted())) { + server.setInstanceConfigValue("pulse",1); + } + } catch (Exception ex) { + showException(ex); + } + }//GEN-LAST:event_buttonPulse1ActionPerformed + + private void buttonPulse2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonPulse2ActionPerformed + try { + PipelineSource server = camServerViewer.getServer(); + if ((server != null) && (server.isStarted())) { + server.setInstanceConfigValue("pulse",2); + } + } catch (Exception ex) { + showException(ex); + } + }//GEN-LAST:event_buttonPulse2ActionPerformed + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.ButtonGroup buttonGroup1; + private javax.swing.ButtonGroup buttonGroup2; + private javax.swing.ButtonGroup buttonGroup3; + private javax.swing.ButtonGroup buttonGroup4; + private javax.swing.JButton buttonPulse1; + private javax.swing.JButton buttonPulse2; + private ch.psi.pshell.screenpanel.CamServerViewer camServerViewer; + private javax.swing.JComboBox comboFilter; + private javax.swing.JComboBox comboScreen; + private javax.swing.JPanel customPanel; + private javax.swing.JProgressBar jProgressBar1; + private javax.swing.JPanel panelFilter; + private javax.swing.JPanel panelPulse; + private javax.swing.JPanel panelScreen; + private javax.swing.JTextField textPulse; + private ch.psi.pshell.swing.DeviceValuePanel valueFilter; + private ch.psi.pshell.swing.DeviceValuePanel valueScreen; + // End of variables declaration//GEN-END:variables + +} + diff --git a/screenpanel-sls/build.gradle b/screenpanel-sls/build.gradle new file mode 100644 index 0000000..1d880e5 --- /dev/null +++ b/screenpanel-sls/build.gradle @@ -0,0 +1,9 @@ +description = 'screenpanel-sls' +ext.mainClass = hasProperty('mainClass') ? mainClass : 'ScreenPanelSLS' + +dependencies { + implementation 'ch.psi:workbench:' + version + implementation 'ch.psi:screenpanel:' + version + + createDefaultTasks(project) +} \ No newline at end of file diff --git a/screenpanel-sls/src/main/java/ScreenPanelSLS.form b/screenpanel-sls/src/main/java/ScreenPanelSLS.form new file mode 100755 index 0000000..576f6fd --- /dev/null +++ b/screenpanel-sls/src/main/java/ScreenPanelSLS.form @@ -0,0 +1,242 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/screenpanel-sls/src/main/java/ScreenPanelSLS.java b/screenpanel-sls/src/main/java/ScreenPanelSLS.java new file mode 100755 index 0000000..528b005 --- /dev/null +++ b/screenpanel-sls/src/main/java/ScreenPanelSLS.java @@ -0,0 +1,600 @@ +import ch.psi.pshell.bs.StreamCamera; +import ch.psi.pshell.data.DataManager; +import ch.psi.pshell.device.Device; +import ch.psi.pshell.epics.DiscretePositioner; +import ch.psi.pshell.epics.BinaryPositioner; +import ch.psi.pshell.epics.ChannelDouble; +import ch.psi.pshell.epics.Epics; +import ch.psi.pshell.imaging.Overlay; +import ch.psi.pshell.imaging.Overlays; +import ch.psi.pshell.imaging.Source; +import ch.psi.pshell.workbench.App; +import ch.psi.pshell.framework.Context; +import ch.psi.pshell.framework.Panel; +import ch.psi.pshell.framework.Setup; +import ch.psi.pshell.utils.Elog; +import ch.psi.pshell.utils.State; +import ch.psi.pshell.swing.SwingUtils; +import ch.psi.pshell.swing.SwingUtils.OptionResult; +import ch.psi.pshell.swing.SwingUtils.OptionType; +import ch.psi.pshell.screenpanel.Options; +import ch.psi.pshell.screenpanel.CamServerViewer; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.io.IOException; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.swing.DefaultComboBoxModel; +import javax.swing.JComboBox; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JTextField; +import javax.swing.SwingUtilities; + +/** + * + */ +public class ScreenPanelSLS extends Panel implements CamServerViewer.CamServerViewerListener{ + + public static final String BTR_TYPE = "BTR"; + public static final String BOOSTER_TYPE = "Booster"; + public static final String FRONTEND_TYPE = "Frontend"; + public static final String LTB_TYPE = "LTB"; + public static final String LINAC_TYPE = "Linac"; + public static final String RF_TYPE = "RF"; + public static final String RING_TYPE = "Ring"; + public static final String SIMULATION_TYPE = "Simulation"; + + DiscretePositioner screen; + ChannelDouble exposure; + ChannelDouble flStep; + //DiscretePositioner mirror; + BinaryPositioner mirror; + BinaryPositioner ledPower; + + final Logger logger; + + + static public void main(String[] args) { + ch.psi.pshell.workbench.Options.add(); + ch.psi.pshell.screenpanel.Options.add(); + App.init(args); + App.create(); + } + + + public ScreenPanelSLS() { + logger = Logger.getLogger(getClass().getName()); + initComponents(); + panelScreen.setVisible(false); + panelControls.setVisible(false); + camServerViewer.setListener(this); + this.remove(customPanel); + camServerViewer.getCustomPanel().add(customPanel); + camServerViewer.applyOptions(); + camServerViewer.setSidePanelVisible(true); + camServerViewer.setShowFit(true); + camServerViewer.setShowProfile(true); + camServerViewer.setShowReticle(true); + } + + @Override + public void onStart() { + super.onStart(); + try { + SwingUtilities.invokeLater(()->{ + try { + camServerViewer.initialize(App.getArgumentValue(Options.SP_MODE.getString(null))); + } catch (Exception ex) { + Logger.getLogger(ScreenPanelSLS.class.getName()).log(Level.SEVERE, null, ex); + } + updateDialogTitle(); + }); + + } catch (Exception ex) { + logger.log(Level.SEVERE, null, ex); + } + } + + @Override + public void onStop() { + super.onStop(); + } + + + + @Override + public void onStateChange(State state, State former) { + + } + + @Override + public void onExecutedFile(String fileName, Object result) { + } + + //Callback to perform update - in event thread + @Override + protected void doUpdate() { + } + + Thread devicesInitTask; + + + State state; + void checkAppState(){ + if (Setup.isDetached()){ + State state = App.getInstance().getState(); + StreamCamera camera = camServerViewer.getCamera(); + if (state.isInitialized()){ + state = (camera == null) ? state : camera.getState(); + } + if (state!=this.state){ + App.getInstance().getPropertyChangeSupport().firePropertyChange("appstate", this.state, state); + this.state = state; + } + } + } + + + @Override + protected void onTimer() { + //for (Device dev : new Device[]{screen, exposure}) { + // if (dev != null) { + // dev.request(); + // } + //} + + checkAppState(); + + if (App.hasArgument("s")) { + try { + ((Source) getDevice("image")).initialize(); + } catch (IOException ex) { + logger.log(Level.SEVERE, null, ex); + } catch (InterruptedException ex) { + logger.log(Level.SEVERE, null, ex); + } + } + } + + @Override + public void onOpeningStream(String name) throws Exception { + System.out.println("Initializing stream " + name); + if ((devicesInitTask != null) && (devicesInitTask.isAlive())) { + devicesInitTask.interrupt(); + } + for (Device dev : new Device[]{screen, exposure, mirror, ledPower, flStep}) { + if (dev != null) { + dev.close(); + } + } + screen = null; + exposure = null; + mirror=null; + ledPower=null; + flStep=null; + + comboScreen.setModel(new DefaultComboBoxModel()); + comboScreen.setEnabled(false); + valueScreen.setEnabled(false); + panelFlStep.setEnabled(false); + buttonFLDown.setEnabled(false); + buttonFLUp.setEnabled(false); + selLedPower.setEnabled(false); + panelExposure.setEnabled(false); + selMirror.setEnabled(false); + if ((name==null)|| name.isBlank()){ + panelScreen.setVisible(false); + panelControls.setVisible(false); + } + updateDialogTitle(); + } + + + @Override + public void onOpenedStream(String name, String instance) throws Exception { + System.out.println("Initialized instance: " + instance); + String cameraName = camServerViewer.getCameraName(); + List types = camServerViewer.getCameraTypes(cameraName); + boolean btr = (types!=null) && types.contains(BTR_TYPE); + boolean booster = (types!=null) && types.contains(BOOSTER_TYPE); + boolean frontend = (types!=null) && types.contains(FRONTEND_TYPE); + boolean ltb = (types!=null) && types.contains(LTB_TYPE); + boolean linac = (types!=null) && types.contains(LINAC_TYPE); + boolean rf = (types!=null) && types.contains(RF_TYPE); + boolean ring = (types!=null) && types.contains(RING_TYPE); + + boolean cameraControls = linac || ltb || booster || btr || ring; + boolean flipMirror = linac || ltb || booster; + + panelScreen.setVisible(cameraControls); + panelControls.setVisible(cameraControls); + if (cameraName!=null){ + if (cameraControls) { + //Parallelizing initialization + devicesInitTask = new Thread(() -> { + + try { + exposure = new ChannelDouble("Exposure Time", cameraName + ":EXPOSURE"); + exposure.setMonitored(true); + exposure.initialize(); + + } catch (Exception ex) { + System.err.println(ex.getMessage()); + exposure = null; + } + panelExposure.setEnabled(exposure != null); + panelExposure.setDevice(exposure); + + if (flipMirror){ + try { + mirror = new BinaryPositioner("Flip Mirror", cameraName + ":FLIP-MIRROR"); + mirror.setMonitored(true); + mirror.initialize(); + + } catch (Exception ex) { + System.err.println(ex.getMessage()); + mirror = null; + } + } else { + mirror = null; + } + selMirror.setEnabled(mirror != null); + selMirror.setDevice(mirror); + + + try { + ledPower = new BinaryPositioner("Led Power", cameraName + ":LED-POWER"); + ledPower.setMonitored(true); + ledPower.initialize(); + + } catch (Exception ex) { + System.err.println(ex.getMessage()); + ledPower = null; + } + selLedPower.setEnabled(ledPower != null); + selLedPower.setDevice(ledPower); + + try { + flStep = new ChannelDouble("Lens FL Step", cameraName + "-LENS:FL_STEP"); + flStep.setMonitored(true); + flStep.initialize(); + + } catch (Exception ex) { + System.err.println(ex.getMessage()); + flStep = null; + } + panelFlStep.setEnabled(flStep != null); + buttonFLDown.setEnabled(flStep != null); + buttonFLUp.setEnabled(flStep != null); + panelFlStep.setDevice(flStep); + + try{ + screen = new DiscretePositioner("CurrentScreen", cameraName + ":SET_SCREEN1_POS", cameraName + ":GET_SCREEN1_POS"); + screen.setMonitored(true); + screen.initialize(); + DefaultComboBoxModel model = new DefaultComboBoxModel(); + for (String pos : screen.getPositions()) { + model.addElement(pos); + } + comboScreen.setModel(model); + comboScreen.setSelectedItem(screen.read()); + + } catch (Exception ex) { + comboScreen.setModel(new DefaultComboBoxModel()); + System.err.println(ex.getMessage()); + screen = null; + } + comboScreen.setEnabled(screen != null); + valueScreen.setEnabled(screen != null); + valueScreen.setDevice(screen); + + + }); + devicesInitTask.start(); + } + } + updateDialogTitle(); + } + + public void onSavedSnapshot(String name, String instancee, String snapshotFile) throws Exception { + JPanel panel = new JPanel(); + GridBagLayout layout = new GridBagLayout(); + layout.columnWidths = new int[]{0, 180}; //Minimum width + layout.rowHeights = new int[]{30, 30, 30}; //Minimum height + panel.setLayout(layout); + JComboBox comboLogbook = new JComboBox(new String[]{"SLS", "SLS Development", "SLS Measurement Data"}); + JTextField textComment = new JTextField(); + GridBagConstraints c = new GridBagConstraints(); + c.gridx = 0; + c.gridy = 0; + panel.add(new JLabel("Data file:"), c); + c.gridy = 1; + panel.add(new JLabel("Logbook:"), c); + c.gridy = 2; + panel.add(new JLabel("Comment:"), c); + c.fill = GridBagConstraints.HORIZONTAL; + c.gridx = 1; + panel.add(textComment, c); + c.gridy = 1; + panel.add(comboLogbook, c); + c.gridy = 0; + panel.add(new JLabel(Context.getInterpreter().getExecutionPars().getPath()), c); + + if (SwingUtils.showOption(getTopLevel(), "Success", panel, OptionType.OkCancel) == OptionResult.Yes) { + StringBuilder message = new StringBuilder(); + message.append("Camera: ").append(name).append("\n"); + message.append("Screen: ").append(String.valueOf(valueScreen.getLabel().getText())).append("\n"); + message.append("Data file: ").append(Context.getInterpreter().getExecutionPars().getPath()).append("\n"); + message.append("Comment: ").append(textComment.getText()).append("\n"); + //Add slicing message + Overlay[] fitOv = camServerViewer.getFitOverlays(); + if ((fitOv != null) && (fitOv.length > 5) && (fitOv[fitOv.length - 1] instanceof Overlays.Text)) { + Overlays.Text text = (Overlays.Text) fitOv[fitOv.length - 1]; + message.append(text.getText()).append("\n"); + } + Elog.log((String) comboLogbook.getSelectedItem(), "ScreenPanel Snapshot", message.toString(), new String[]{snapshotFile}); + } + } + + public void onSavingImages(String name, String instance, DataManager dm, String pathRoot) throws IOException{ + if (valueScreen.isVisible() && valueScreen.isEnabled()) { + dm.setAttribute(pathRoot, "Screen", String.valueOf(valueScreen.getLabel().getText())); + } + if (panelExposure.isVisible() && panelExposure.isEnabled()) { + dm.setAttribute(pathRoot, "Exposure", String.valueOf(panelExposure.getValue())); + } + if (selMirror.isVisible() && selMirror.isEnabled()) { + dm.setAttribute(pathRoot, "Mirror", String.valueOf(selMirror.getComboBox().getSelectedItem())); + } + if (selLedPower.isVisible() && selLedPower.isEnabled()) { + dm.setAttribute(pathRoot, "LedPower", String.valueOf(selLedPower.getComboBox().getSelectedItem())); + } + } + + void updateDialogTitle() { + if (Setup.isDetached()) { + getTopLevel().setTitle(camServerViewer.getInstanceName() == null ? "ScreenPanel" : camServerViewer.getInstanceName()); + } + } + + + + //////// + @SuppressWarnings("unchecked") + // //GEN-BEGIN:initComponents + private void initComponents() { + + buttonGroup1 = new javax.swing.ButtonGroup(); + buttonGroup2 = new javax.swing.ButtonGroup(); + buttonGroup3 = new javax.swing.ButtonGroup(); + buttonGroup4 = new javax.swing.ButtonGroup(); + jProgressBar1 = new javax.swing.JProgressBar(); + customPanel = new javax.swing.JPanel(); + panelScreen = new javax.swing.JPanel(); + valueScreen = new ch.psi.pshell.swing.DeviceValuePanel(); + comboScreen = new javax.swing.JComboBox(); + panelControls = new javax.swing.JPanel(); + panelExposure = new ch.psi.pshell.swing.RegisterPanel(); + jLabel1 = new javax.swing.JLabel(); + jLabel2 = new javax.swing.JLabel(); + selMirror = new ch.psi.pshell.swing.DiscretePositionerSelector(); + jLabel3 = new javax.swing.JLabel(); + selLedPower = new ch.psi.pshell.swing.DiscretePositionerSelector(); + jLabel4 = new javax.swing.JLabel(); + panelFlStep = new ch.psi.pshell.swing.RegisterPanel(); + buttonFLDown = new javax.swing.JButton(); + buttonFLUp = new javax.swing.JButton(); + camServerViewer = new ch.psi.pshell.screenpanel.CamServerViewer(); + + setPreferredSize(new java.awt.Dimension(873, 600)); + setLayout(new java.awt.BorderLayout()); + + panelScreen.setBorder(javax.swing.BorderFactory.createTitledBorder("Screen")); + + comboScreen.setEnabled(false); + comboScreen.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + comboScreenActionPerformed(evt); + } + }); + + javax.swing.GroupLayout panelScreenLayout = new javax.swing.GroupLayout(panelScreen); + panelScreen.setLayout(panelScreenLayout); + panelScreenLayout.setHorizontalGroup( + panelScreenLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(panelScreenLayout.createSequentialGroup() + .addContainerGap() + .addGroup(panelScreenLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(valueScreen, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(comboScreen, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addContainerGap()) + ); + panelScreenLayout.setVerticalGroup( + panelScreenLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelScreenLayout.createSequentialGroup() + .addGap(4, 4, 4) + .addComponent(comboScreen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(valueScreen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addContainerGap()) + ); + + panelControls.setBorder(javax.swing.BorderFactory.createTitledBorder("Camera Control")); + + jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); + jLabel1.setText("Exposure:"); + + jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); + jLabel2.setText("Flip Mirror:"); + + jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); + jLabel3.setText("Led Power:"); + + jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); + jLabel4.setText("Lens FL:"); + + buttonFLDown.setText("<"); + buttonFLDown.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + buttonFLDownActionPerformed(evt); + } + }); + + buttonFLUp.setText(">"); + buttonFLUp.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + buttonFLUpActionPerformed(evt); + } + }); + + javax.swing.GroupLayout panelControlsLayout = new javax.swing.GroupLayout(panelControls); + panelControls.setLayout(panelControlsLayout); + panelControlsLayout.setHorizontalGroup( + panelControlsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelControlsLayout.createSequentialGroup() + .addContainerGap() + .addGroup(panelControlsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) + .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(panelControlsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(panelExposure, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE) + .addComponent(selMirror, javax.swing.GroupLayout.DEFAULT_SIZE, 0, Short.MAX_VALUE) + .addComponent(selLedPower, javax.swing.GroupLayout.DEFAULT_SIZE, 0, Short.MAX_VALUE) + .addGroup(panelControlsLayout.createSequentialGroup() + .addComponent(buttonFLDown) + .addGap(0, 0, 0) + .addComponent(panelFlStep, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE) + .addGap(0, 0, 0) + .addComponent(buttonFLUp))) + .addContainerGap()) + ); + + panelControlsLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jLabel1, jLabel2}); + + panelControlsLayout.setVerticalGroup( + panelControlsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(panelControlsLayout.createSequentialGroup() + .addGroup(panelControlsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) + .addComponent(panelExposure, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(jLabel1)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(panelControlsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jLabel2) + .addComponent(selMirror, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(panelControlsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jLabel3) + .addComponent(selLedPower, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(panelControlsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(panelControlsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jLabel4) + .addComponent(buttonFLDown)) + .addComponent(panelFlStep, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(buttonFLUp)) + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + ); + + javax.swing.GroupLayout customPanelLayout = new javax.swing.GroupLayout(customPanel); + customPanel.setLayout(customPanelLayout); + customPanelLayout.setHorizontalGroup( + customPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(panelScreen, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(panelControls, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + ); + customPanelLayout.setVerticalGroup( + customPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(customPanelLayout.createSequentialGroup() + .addGap(0, 0, 0) + .addComponent(panelScreen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(panelControls, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addContainerGap(342, Short.MAX_VALUE)) + ); + + add(customPanel, java.awt.BorderLayout.WEST); + add(camServerViewer, java.awt.BorderLayout.CENTER); + }// //GEN-END:initComponents + + private void comboScreenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboScreenActionPerformed + + comboScreen.setEnabled(false); + new Thread(new Runnable() { + @Override + public void run() { + try { + int index = comboScreen.getSelectedIndex(); + if (index >= 0) { + String cameraName = camServerViewer.getCameraName(); + String channel = cameraName + ":SET_SCREEN1_POS"; + Integer readback = Epics.get(channel, Integer.class); + if ((readback == null) || (readback != index)) { + System.out.println("Writing " + index + " to " + channel); + Epics.put(channel, Integer.valueOf(index)); + } + screen.read(); + } + } catch (Exception ex) { + showException(ex); + } finally { + comboScreen.setEnabled(true); + } + } + }).start(); + }//GEN-LAST:event_comboScreenActionPerformed + + private void buttonFLDownActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonFLDownActionPerformed + try { + String cameraName = camServerViewer.getCameraName(); + if ((flStep!=null) && (cameraName!=null)){ + String channel = cameraName + "-LENS:DEC_FL.PROC"; + Epics.putq(channel, Integer.valueOf(1)); + } + } catch (Exception ex) { + showException(ex); + } + }//GEN-LAST:event_buttonFLDownActionPerformed + + private void buttonFLUpActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonFLUpActionPerformed + try { + String cameraName = camServerViewer.getCameraName(); + if ((flStep!=null) && (cameraName!=null)){ + String channel = cameraName + "-LENS:INC_FL.PROC"; + Epics.putq(channel, Integer.valueOf(1)); + } + } catch (Exception ex) { + showException(ex); + } + }//GEN-LAST:event_buttonFLUpActionPerformed + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton buttonFLDown; + private javax.swing.JButton buttonFLUp; + private javax.swing.ButtonGroup buttonGroup1; + private javax.swing.ButtonGroup buttonGroup2; + private javax.swing.ButtonGroup buttonGroup3; + private javax.swing.ButtonGroup buttonGroup4; + private ch.psi.pshell.screenpanel.CamServerViewer camServerViewer; + private javax.swing.JComboBox comboScreen; + private javax.swing.JPanel customPanel; + private javax.swing.JLabel jLabel1; + private javax.swing.JLabel jLabel2; + private javax.swing.JLabel jLabel3; + private javax.swing.JLabel jLabel4; + private javax.swing.JProgressBar jProgressBar1; + private javax.swing.JPanel panelControls; + private ch.psi.pshell.swing.RegisterPanel panelExposure; + private ch.psi.pshell.swing.RegisterPanel panelFlStep; + private javax.swing.JPanel panelScreen; + private ch.psi.pshell.swing.DiscretePositionerSelector selLedPower; + private ch.psi.pshell.swing.DiscretePositionerSelector selMirror; + private ch.psi.pshell.swing.DeviceValuePanel valueScreen; + // End of variables declaration//GEN-END:variables + +} + diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 0000000..ab2f3ca --- /dev/null +++ b/settings.gradle @@ -0,0 +1,7 @@ +rootProject.name = 'pshell-apps' + +include ':screenpanel-sls' +include ':screenpanel-sf' +include ':athos-screens' +include ':psss-panel' +