Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
tiagohm committed Aug 25, 2024
2 parents 4ef43d9 + 55fc2aa commit 53838ce
Show file tree
Hide file tree
Showing 12 changed files with 113 additions and 66 deletions.
25 changes: 9 additions & 16 deletions api/src/main/kotlin/nebulosa/api/stacker/StackerService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import kotlin.io.path.isDirectory
import kotlin.io.path.isRegularFile

@Service
class StackerService(private val messageService: MessageService) {
class StackerService(private val messageService: MessageService?) {

@Synchronized
fun stack(request: StackingRequest, cancellationToken: CancellationToken = CancellationToken.NONE): Path? {
Expand Down Expand Up @@ -52,7 +52,7 @@ class StackerService(private val messageService: MessageService) {
combinedPath
}
} finally {
messageService.sendMessage(StackerEvent.IDLE)
messageService?.sendMessage(StackerEvent.IDLE)
stacker.unregisterAutoStackerListener(autoStackerMessageHandler)
}
}
Expand All @@ -77,7 +77,7 @@ class StackerService(private val messageService: MessageService) {
stackedLuminancePath ?: stackedRGBPath
}
} finally {
messageService.sendMessage(StackerEvent.IDLE)
messageService?.sendMessage(StackerEvent.IDLE)
stacker.unregisterAutoStackerListener(autoStackerMessageHandler)
}
}
Expand All @@ -102,7 +102,7 @@ class StackerService(private val messageService: MessageService) {
stackedLuminancePath ?: stackedMonoPath
}
} finally {
messageService.sendMessage(StackerEvent.IDLE)
messageService?.sendMessage(StackerEvent.IDLE)
stacker.unregisterAutoStackerListener(autoStackerMessageHandler)
}
} else {
Expand Down Expand Up @@ -148,19 +148,13 @@ class StackerService(private val messageService: MessageService) {

private val numberOfTargets = luminance.size + red.size + green.size + blue.size + mono.size + rgb.size

override fun onCalibrated(stackCount: Int, path: Path, calibratedPath: Path) {
sendNotification(StackerState.CALIBRATING, path, stackCount)
}
override fun onCalibrationStarted(stackCount: Int, path: Path) = sendNotification(StackerState.CALIBRATING, path, stackCount)

override fun onAligned(stackCount: Int, path: Path, alignedPath: Path) {
sendNotification(StackerState.ALIGNING, path, stackCount)
}
override fun onAlignStarted(stackCount: Int, path: Path) = sendNotification(StackerState.ALIGNING, path, stackCount)

override fun onIntegrated(stackCount: Int, path: Path, alignedPath: Path) {
sendNotification(StackerState.INTEGRATING, path, stackCount)
}
override fun onIntegrationStarted(stackCount: Int, path: Path) = sendNotification(StackerState.INTEGRATING, path, stackCount)

fun sendNotification(state: StackerState, path: Path, stackCount: Int) {
private fun sendNotification(state: StackerState, path: Path, stackCount: Int) {
val type = if (luminance.any { it.path === path }) StackerGroupType.LUMINANCE
else if (red.any { it.path === path }) StackerGroupType.RED
else if (green.any { it.path === path }) StackerGroupType.GREEN
Expand All @@ -169,8 +163,7 @@ class StackerService(private val messageService: MessageService) {
else if (rgb.any { it.path === path }) StackerGroupType.RGB
else return

val message = StackerEvent(state, type, stackCount + 1, numberOfTargets)
messageService.sendMessage(message)
messageService?.sendMessage(StackerEvent(state, type, stackCount + 1, numberOfTargets))
}
}
}
2 changes: 1 addition & 1 deletion api/src/test/kotlin/StackerServiceTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class StackerServiceTest {

const val BASE_DIR = "/home/tiagohm/Imagens/Astrophotos/Light/Algieba/2024-05-13"

@JvmStatic private val SERVICE = StackerService()
@JvmStatic private val SERVICE = StackerService(null)

@JvmStatic private val PATHS = listOf(
Path.of("$BASE_DIR/20240513.213424625-LIGHT.fits"),
Expand Down
4 changes: 2 additions & 2 deletions desktop/src/app/atlas/atlas.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,7 @@ export class AtlasComponent implements OnInit, AfterContentInit, AfterViewInit,
}

private loadPreference() {
Object.assign(this.preference, this.preferenceService.skyAtlasPreference.get())
Object.assign(this.preference, this.preferenceService.skyAtlas.get())
this.satellite.search.filter.groups = this.preference.satellites
this.dateTimeAndLocation.location = this.preference.location

Expand All @@ -871,7 +871,7 @@ export class AtlasComponent implements OnInit, AfterContentInit, AfterViewInit,

protected savePreference() {
this.preference.location = this.dateTimeAndLocation.location
this.preferenceService.skyAtlasPreference.set(this.preference)
this.preferenceService.skyAtlas.set(this.preference)
}

private static removePointsBelowZero(points: AltitudeDataPoint[]) {
Expand Down
4 changes: 2 additions & 2 deletions desktop/src/app/calibration/calibration.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -395,11 +395,11 @@ export class CalibrationComponent implements AfterViewInit, OnDestroy {
}

private loadPreference() {
Object.assign(this.preference, this.preferenceService.calibrationPreference.get())
Object.assign(this.preference, this.preferenceService.calibration.get())
}

protected savePreference() {
this.preferenceService.calibrationPreference.set(this.preference)
this.preferenceService.calibration.set(this.preference)
}

private markFrameListBoxesForCheck() {
Expand Down
10 changes: 8 additions & 2 deletions desktop/src/app/home/home.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -507,9 +507,15 @@ export class HomeComponent implements AfterContentInit {
case 'ALIGNMENT':
await this.browserWindowService.openAlignment({ bringToFront: true })
break
case 'SEQUENCER':
await this.browserWindowService.openSequencer({ bringToFront: true })
case 'SEQUENCER': {
const device = await this.deviceMenu.show(this.cameras, undefined, 'CAMERA')

if (device && device !== 'NONE') {
await this.browserWindowService.openSequencer(device, { bringToFront: true })
}

break
}
case 'AUTO_FOCUS':
await this.browserWindowService.openAutoFocus({ bringToFront: true })
break
Expand Down
4 changes: 2 additions & 2 deletions desktop/src/app/image/image.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1336,7 +1336,7 @@ export class ImageComponent implements AfterViewInit, OnDestroy {
}

private loadPreference() {
Object.assign(this.preference, this.preferenceService.imagePreference.get())
Object.assign(this.preference, this.preferenceService.image.get())
this.solver.request = this.preference.solver
this.starDetector.request = this.preference.starDetector
this.settings.preference = this.preference
Expand All @@ -1355,7 +1355,7 @@ export class ImageComponent implements AfterViewInit, OnDestroy {
}

protected savePreference() {
this.preferenceService.imagePreference.set(this.preference)
this.preferenceService.image.set(this.preference)
}

private async executeCamera(action: (camera: Camera) => void | Promise<void>, showConfirmation: boolean = true) {
Expand Down
7 changes: 0 additions & 7 deletions desktop/src/app/sequencer/sequencer.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,6 @@
</ng-template>
<div class="grid px-4 pt-3">
<div class="col-12 align-items-center justify-content-center flex-nowrap overflow-y-hidden gap-2">
<neb-device-chooser
title="CAMERA"
icon="mdi mdi-camera-iris"
[devices]="cameras"
[(device)]="plan.camera"
[hasNone]="true"
(deviceChange)="cameraChanged()" />
<neb-device-chooser
title="MOUNT"
icon="mdi mdi-telescope"
Expand Down
66 changes: 51 additions & 15 deletions desktop/src/app/sequencer/sequencer.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { CdkDragDrop, moveItemInArray } from '@angular/cdk/drag-drop'
import { AfterContentInit, Component, HostListener, NgZone, OnDestroy, QueryList, ViewChildren, ViewEncapsulation } from '@angular/core'
import { ActivatedRoute } from '@angular/router'
import { dirname } from 'path'
import { CameraExposureComponent } from '../../shared/components/camera-exposure/camera-exposure.component'
import { DialogMenuComponent } from '../../shared/components/dialog-menu/dialog-menu.component'
Expand Down Expand Up @@ -44,6 +45,7 @@ export class SequencerComponent implements AfterContentInit, OnDestroy, Tickable
protected plan = this.preference.plan
protected event?: SequencerEvent
protected running = false
protected path?: string

// NOTE: Remove the "plan.sequences.length <= 1" on layout if add more options
protected readonly sequenceModel: SlideMenuItem[] = [
Expand Down Expand Up @@ -118,7 +120,9 @@ export class SequencerComponent implements AfterContentInit, OnDestroy, Tickable
this.preference.loadPath = undefined
this.savePreference()

this.app.subTitle = undefined
this.path = undefined
this.updateSubTitle()

this.saveMenuItem.visible = false
this.saveMenuItem.disabled = true

Expand Down Expand Up @@ -187,6 +191,7 @@ export class SequencerComponent implements AfterContentInit, OnDestroy, Tickable
private readonly preferenceService: PreferenceService,
private readonly angularService: AngularService,
private readonly ticker: Ticker,
private readonly route: ActivatedRoute,
ngZone: NgZone,
) {
app.title = 'Sequencer'
Expand All @@ -197,7 +202,7 @@ export class SequencerComponent implements AfterContentInit, OnDestroy, Tickable
app.topMenu.push(this.loadMenuItem)

app.beforeClose = async () => {
if (this.app.subTitle && !this.saveMenuItem.disabled) {
if (this.path && !this.saveMenuItem.disabled) {
return !(await angularService.confirm('Are you sure you want to close the window? Please make sure to save before exiting to avoid losing any important changes.'))
} else {
return true
Expand Down Expand Up @@ -287,9 +292,15 @@ export class SequencerComponent implements AfterContentInit, OnDestroy, Tickable
this.calibrationGroups.push({ label: 'None', value: undefined })
calibrationGroups.forEach((e) => this.calibrationGroups.push({ label: e, value: e }))

this.loadPreference()

await this.loadPlanFromPath()
this.route.queryParams.subscribe(async (e) => {
const data = JSON.parse(decodeURIComponent(e['data'] as string)) as Camera
this.plan.camera = this.cameras.find((e) => e.id === data.id)
this.updateSubTitle()
this.loadPreference()
await this.loadPlanFromPath()
await this.cameraChanged()
console.log(data, this.plan.camera)
})
}

@HostListener('window:unload')
Expand All @@ -305,6 +316,19 @@ export class SequencerComponent implements AfterContentInit, OnDestroy, Tickable
if (this.plan.rotator?.id) await this.api.rotatorListen(this.plan.rotator)
}

private updateSubTitle() {
let title = ''

if (this.plan.camera) {
title = this.plan.camera.name
}
if (this.path) {
title += ` · ${this.path}`
}

this.app.subTitle = title
}

private enableOrDisableTopbarMenu(enabled: boolean) {
this.createNewMenuItem.disabled = !enabled
this.loadMenuItem.disabled = !enabled
Expand Down Expand Up @@ -347,7 +371,9 @@ export class SequencerComponent implements AfterContentInit, OnDestroy, Tickable
this.preference.loadPath = file.path
this.savePreference()

this.app.subTitle = file.path
this.path = file.path
this.updateSubTitle()

this.saveMenuItem.visible = !!file.path
this.saveMenuItem.disabled = true
}
Expand Down Expand Up @@ -375,11 +401,13 @@ export class SequencerComponent implements AfterContentInit, OnDestroy, Tickable
}

private loadPlan(plan: SequencerPlan) {
const camera = this.plan.camera

if (this.plan !== plan) {
Object.assign(this.plan, plan)
}

this.plan.camera = this.cameras.find((e) => e.id === plan.camera?.id)
this.plan.camera = camera // this.cameras.find((e) => e.id === plan.camera?.id)
this.plan.mount = this.mounts.find((e) => e.id === plan.mount?.id)
this.plan.wheel = this.wheels.find((e) => e.id === plan.wheel?.id)
this.plan.focuser = this.focusers.find((e) => e.id === plan.focuser?.id)
Expand All @@ -402,7 +430,9 @@ export class SequencerComponent implements AfterContentInit, OnDestroy, Tickable
this.preference.loadPath = file.path
this.savePreference()

this.app.subTitle = file.path
this.path = file.path
this.updateSubTitle()

this.saveMenuItem.disabled = true
}
}
Expand Down Expand Up @@ -637,18 +667,24 @@ export class SequencerComponent implements AfterContentInit, OnDestroy, Tickable
}

private loadPreference() {
Object.assign(this.preference, this.preferenceService.sequencerPreference.get())
this.plan = this.preference.plan
this.property.properties = this.preference.properties
if (this.plan.camera) {
Object.assign(this.preference, this.preferenceService.sequencer(this.plan.camera).get())
const camera = this.plan.camera
this.plan = this.preference.plan
this.plan.camera = camera
this.property.properties = this.preference.properties

this.loadPlan(this.plan)
this.loadPlan(this.plan)
}
}

protected savePreference() {
this.preferenceService.sequencerPreference.set(this.preference)
if (this.plan.camera) {
this.preferenceService.sequencer(this.plan.camera).set(this.preference)

if (this.preference.loadPath) {
this.saveMenuItem.disabled = false
if (this.preference.loadPath) {
this.saveMenuItem.disabled = false
}
}
}
}
4 changes: 2 additions & 2 deletions desktop/src/shared/services/browser-window.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ export class BrowserWindowService {
return this.openWindow({ preference, id: 'alignment', path: 'alignment' })
}

openSequencer(preference: WindowPreference = {}) {
openSequencer(camera: Camera, preference: WindowPreference = {}) {
Object.assign(preference, { icon: 'workflow', width: 628, height: 467, resizable: true, minWidth: 628, minHeight: 328 })
return this.openWindow({ preference, id: 'sequencer', path: 'sequencer' })
return this.openWindow({ preference, data: camera, id: `sequencer.${camera.name}`, path: 'sequencer' })
}

openAutoFocus(preference: WindowPreference = {}) {
Expand Down
20 changes: 11 additions & 9 deletions desktop/src/shared/services/preference.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,10 @@ export class PreferenceData<T> {
@Injectable({ providedIn: 'root' })
export class PreferenceService {
readonly home: PreferenceData<HomePreference>
readonly imagePreference: PreferenceData<ImagePreference>
readonly skyAtlasPreference: PreferenceData<SkyAtlasPreference>
readonly image: PreferenceData<ImagePreference>
readonly skyAtlas: PreferenceData<SkyAtlasPreference>
readonly alignment: PreferenceData<AlignmentPreference>
readonly calibrationPreference: PreferenceData<CalibrationPreference>
readonly sequencerPreference: PreferenceData<SequencerPreference>
readonly calibration: PreferenceData<CalibrationPreference>
readonly stacker: PreferenceData<StackerPreference>
readonly guider: PreferenceData<GuiderPreference>
readonly framing: PreferenceData<FramingPreference>
Expand All @@ -61,16 +60,15 @@ export class PreferenceService {

constructor(private readonly storage: LocalStorageService) {
this.home = this.create<HomePreference>('home', () => structuredClone(DEFAULT_HOME_PREFERENCE), homePreferenceWithDefault)
this.imagePreference = this.create<ImagePreference>('image', () => structuredClone(DEFAULT_IMAGE_PREFERENCE), imagePreferenceWithDefault)
this.skyAtlasPreference = this.create<SkyAtlasPreference>('atlas', () => structuredClone(DEFAULT_SKY_ATLAS_PREFERENCE), skyAtlasPreferenceWithDefault)
this.image = this.create<ImagePreference>('image', () => structuredClone(DEFAULT_IMAGE_PREFERENCE), imagePreferenceWithDefault)
this.skyAtlas = this.create<SkyAtlasPreference>('atlas', () => structuredClone(DEFAULT_SKY_ATLAS_PREFERENCE), skyAtlasPreferenceWithDefault)
this.alignment = this.create<AlignmentPreference>('alignment', () => structuredClone(DEFAULT_ALIGNMENT_PREFERENCE), alignmentPreferenceWithDefault)
this.calibrationPreference = this.create<CalibrationPreference>('calibration', () => structuredClone(DEFAULT_CALIBRATION_PREFERENCE), calibrationPreferenceWithDefault)
this.sequencerPreference = this.create<SequencerPreference>('sequencer', () => structuredClone(DEFAULT_SEQUENCER_PREFERENCE), sequencerPreferenceWithDefault)
this.calibration = this.create<CalibrationPreference>('calibration', () => structuredClone(DEFAULT_CALIBRATION_PREFERENCE), calibrationPreferenceWithDefault)
this.stacker = this.create<StackerPreference>('stacker', () => structuredClone(DEFAULT_STACKER_PREFERENCE), stackerPreferenceWithDefault)
this.guider = this.create<GuiderPreference>('guider', () => structuredClone(DEFAULT_GUIDER_PREFERENCE), guiderPreferenceWithDefault)
this.framing = this.create<FramingPreference>('framing', () => structuredClone(DEFAULT_FRAMING_PREFERENCE), framingPreferenceWithDefault)
this.settings = this.create<SettingsPreference>('settings', () => structuredClone(DEFAULT_SETTINGS_PREFERENCE), settingsPreferenceWithDefault)
this.pathChooser = this.create<Record<string, string | undefined>>('pathChooser', () => ({} as Record<string, string | undefined>))
this.pathChooser = this.create<Record<string, string | undefined>>('pathChooser', () => ({}) as Record<string, string | undefined>)
}

create<T>(key: string, defaultValue: T | (() => T), withDefault?: (value: T) => T) {
Expand Down Expand Up @@ -108,4 +106,8 @@ export class PreferenceService {
autoFocus(camera: Camera) {
return this.create<AutoFocusPreference>(`autoFocus.${camera.name}`, () => structuredClone(DEFAULT_AUTO_FOCUS_PREFERENCE), autoFocusPreferenceWithDefault)
}

sequencer(camera: Camera) {
return this.create<SequencerPreference>(`sequencer.${camera.name}`, () => structuredClone(DEFAULT_SEQUENCER_PREFERENCE), sequencerPreferenceWithDefault)
}
}
Loading

0 comments on commit 53838ce

Please sign in to comment.