Skip to content

Commit

Permalink
feat: adds Moonraker analysis support
Browse files Browse the repository at this point in the history
Signed-off-by: Pedro Lamas <pedrolamas@gmail.com>
  • Loading branch information
pedrolamas committed Feb 12, 2025
1 parent 83ab04a commit dff000d
Show file tree
Hide file tree
Showing 13 changed files with 172 additions and 2 deletions.
21 changes: 21 additions & 0 deletions src/api/socketActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,27 @@ export const SocketActions = {
)
},

async serverAnalysisStatus () {
baseEmit(
'server.analysis.status', {
dispatch: 'analysis/onAnalysisStatus'
}
)
},

async serverAnalysisEstimate (filename: string, estimator_config?: string, update_metadata?: boolean) {
baseEmit(
'server.analysis.estimate', {
params: {
filename,
estimator_config,
update_metadata
},
dispatch: 'analysis/onAnalysisEstimate'
}
)
},

async serverSpoolmanGetSpoolId () {
baseEmit(
'server.spoolman.get_spool_id', {
Expand Down
7 changes: 7 additions & 0 deletions src/components/widgets/filesystem/FileSystem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
@preheat="handlePreheat"
@preview-gcode="handlePreviewGcode"
@refresh-metadata="handleRefreshMetadata"
@perform-time-analysis="handlePerformTimeAnalysis"
@view-thumbnail="handleViewThumbnail"
@enqueue="handleEnqueue"
@create-zip="handleCreateZip"
Expand Down Expand Up @@ -802,6 +803,12 @@ export default class FileSystem extends Mixins(StateMixin, FilesMixin, ServicesM
SocketActions.serverFilesMetadata(filename)
}
handlePerformTimeAnalysis (file: AppFileWithMeta) {
const filename = file.path ? `${file.path}/${file.filename}` : file.filename
SocketActions.serverAnalysisEstimate(filename, undefined, true)
}
async handleViewThumbnail (file: AppFileWithMeta) {
const thumb = this.getThumb(file, this.currentRoot, file.path, true)
Expand Down
24 changes: 24 additions & 0 deletions src/components/widgets/filesystem/FileSystemContextMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,19 @@
</v-list-item-content>
</v-list-item>

<v-list-item
v-if="canPerformTimeAnalysys"
:disabled="!estimatorReady"
@click="$emit('perform-time-analysis', file)"
>
<v-list-item-icon>
<v-icon>$stopwatch</v-icon>
</v-list-item-icon>
<v-list-item-content>
<v-list-item-title>{{ $t('app.general.btn.perform_time_analysis') }}</v-list-item-title>
</v-list-item-content>
</v-list-item>

<v-list-item
v-if="canPreviewGcode"
@click="$emit('preview-gcode', file)"
Expand Down Expand Up @@ -301,5 +314,16 @@ export default class FileSystemContextMenu extends Mixins(StateMixin, FilesMixin
this.$store.getters['server/componentSupport']('job_queue')
)
}
get canPerformTimeAnalysys (): boolean {
return (
this.canPrint &&
this.$store.getters['server/componentSupport']('analysis')
)
}
get estimatorReady (): boolean {
return this.$store.state.analysis.status?.estimator_ready ?? false
}
}
</script>
5 changes: 4 additions & 1 deletion src/globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ import {
mdiTableColumn,
mdiShape,
mdiSync,
mdiTimerOutline,
mdiContentDuplicate,
mdiArchiveLock,
mdiFileImage,
Expand Down Expand Up @@ -219,7 +220,8 @@ export const Globals = Object.freeze({
webcams: { name: 'webcam', dispatch: 'webcams/init' },
jobQueue: { name: 'job_queue', dispatch: 'jobQueue/init' },
spoolman: { name: 'spoolman', dispatch: 'spoolman/init' },
sensors: { name: 'sensor', dispatch: 'sensors/init' }
sensors: { name: 'sensor', dispatch: 'sensors/init' },
analysis: { name: 'analysis', dispatch: 'analysis/init' }
},
// Ordered by weight.
CONFIG_SERVICE_MAP: [
Expand Down Expand Up @@ -374,6 +376,7 @@ export const Icons = Object.freeze({
rename: mdiFormTextbox,
duplicate: mdiContentDuplicate,
sync: mdiSync,
stopwatch: mdiTimerOutline,
delete: mdiDelete,
camera: mdiCamera,
fan: mdiFan,
Expand Down
1 change: 1 addition & 0 deletions src/locales/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ app:
snooze: Snooze
socket_reconnect: Re-Connect
socket_refresh: Force refresh
perform_time_analysis: Perform Time Analysis
thumbnail_size: Thumbnail size
upload: Upload
upload_files: Upload Files
Expand Down
31 changes: 31 additions & 0 deletions src/store/analysis/actions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import type { ActionTree } from 'vuex'
import type { AnalysisState, AnalysisStatus, AnalysisEstimate } from './types'
import type { RootState } from '../types'
import { SocketActions } from '@/api/socketActions'
import type { ObjectWithRequest } from '@/plugins/socketClient'

export const actions: ActionTree<AnalysisState, RootState> = {
async reset ({ commit }) {
commit('setReset')
},

async init () {
SocketActions.serverAnalysisStatus()
},

async onAnalysisStatus ({ commit }, payload: AnalysisStatus) {
if (payload) {
commit('setAnalysisStatus', payload)
}
},

async onAnalysisEstimate (_, payload: ObjectWithRequest<AnalysisEstimate>) {
if (payload) {
const { filename, update_metadata } = payload.__request__.params ?? {}

if (update_metadata) {
SocketActions.serverFilesMetadata(filename)
}
}
}
}
6 changes: 6 additions & 0 deletions src/store/analysis/getters.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import type { GetterTree } from 'vuex'
import type { AnalysisState } from './types'
import type { RootState } from '../types'

export const getters: GetterTree<AnalysisState, RootState> = {
}
17 changes: 17 additions & 0 deletions src/store/analysis/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import type { Module } from 'vuex'
import { state } from './state'
import { getters } from './getters'
import { actions } from './actions'
import { mutations } from './mutations'
import type { AnalysisState } from './types'
import type { RootState } from '../types'

const namespaced = true

export const analysis: Module<AnalysisState, RootState> = {
namespaced,
state,
getters,
actions,
mutations
}
16 changes: 16 additions & 0 deletions src/store/analysis/mutations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import type { MutationTree } from 'vuex'
import type { AnalysisState, AnalysisStatus } from './types'
import { defaultState } from './state'

export const mutations: MutationTree<AnalysisState> = {
/**
* Reset state
*/
setReset (state) {
Object.assign(state, defaultState())
},

setAnalysisStatus (state, payload: AnalysisStatus) {
state.status = payload
}
}
9 changes: 9 additions & 0 deletions src/store/analysis/state.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import type { AnalysisState } from './types'

export const defaultState = (): AnalysisState => {
return {
status: null
}
}

export const state = defaultState()
31 changes: 31 additions & 0 deletions src/store/analysis/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
export interface AnalysisState {
status: AnalysisStatus | null;
}

export interface AnalysisStatus {
estimator_executable: string;
estimator_ready: boolean;
estimator_version: string;
estimator_config_exists: boolean;
using_default_config: boolean;
}

export interface AnalysisEstimate {
total_time: number;
total_distance: number;
total_extrude_distance: number;
max_flow: number;
max_speed: number;
num_moves: number;
total_z_time: number;
total_output_time: number;
total_travel_time: number;
total_extrude_only_time: number;
phase_times: {
acceleration: number;
cruise: number;
deceleration: number;
};
kind_times: Record<string, number>;
layer_times: [number, number][]
}
4 changes: 3 additions & 1 deletion src/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { webcams } from './webcams'
import { jobQueue } from './jobQueue'
import { spoolman } from './spoolman'
import { sensors } from './sensors'
import { analysis } from './analysis'

Vue.use(Vuex)

Expand Down Expand Up @@ -56,7 +57,8 @@ export default new Vuex.Store<RootState>({
webcams,
jobQueue,
spoolman,
sensors
sensors,
analysis
},
mutations: {},
actions: {
Expand Down
2 changes: 2 additions & 0 deletions src/store/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import type { WebcamsState } from './webcams/types'
import type { JobQueueState } from './jobQueue/types'
import type { SpoolmanState } from './spoolman/types'
import type { MoonrakerSensorsState } from './sensors/types'
import type { AnalysisState } from './analysis/types'

export interface RootState {
socket: SocketState;
Expand All @@ -46,4 +47,5 @@ export interface RootState {
jobQueue: JobQueueState;
spoolman: SpoolmanState;
sensors: MoonrakerSensorsState;
analysis: AnalysisState;
}

0 comments on commit dff000d

Please sign in to comment.