Skip to content

Commit

Permalink
refactor: removes parts module
Browse files Browse the repository at this point in the history
Signed-off-by: Pedro Lamas <[email protected]>
  • Loading branch information
pedrolamas committed Jan 23, 2025
1 parent d53e1d6 commit 86daf10
Show file tree
Hide file tree
Showing 18 changed files with 103 additions and 265 deletions.
91 changes: 48 additions & 43 deletions src/components/widgets/exclude-objects/ExcludeObjects.vue
Original file line number Diff line number Diff line change
@@ -1,57 +1,74 @@
<template>
<g id="parts">
<g
v-for="name in parts"
:key="name"
:class="iconClasses(name)"
class="layer"
>
<path
class="partOutline"
:d="partSVG(name)"
:shape-rendering="shapeRendering"
/>
<svg
width="7"
height="7"
viewBox="0 0 24 24"
class="partIcon"
:x="partPos(name).x - 7/2"
:y="partPos(name).y - 7/2"
<template v-for="part in parts">
<g
v-if="(
part.polygon &&
part.polygon.length > 0 &&
part.center &&
part.center.length >= 2
)"
:key="part.name"
:class="iconClasses(part)"
class="layer"
>
<path :d="iconCancelled" />
<path
v-if="!isPartExcluded(name)"
v-touch:tap="() => $emit('cancel', name)"
:d="iconCircle"
class="hitarea"
class="partOutline"
:d="partSVG(part)"
:shape-rendering="shapeRendering"
/>
</svg>
</g>
<svg
width="7"
height="7"
viewBox="0 0 24 24"
class="partIcon"
:x="part.center[0] - 7/2"
:y="part.center[1] - 7/2"
>
<path :d="iconCancelled" />
<path
v-if="!part.isExcluded"
v-touch:tap="() => $emit('cancel', part.name)"
:d="iconCircle"
class="hitarea"
/>
</svg>
</g>
</template>
</g>
</template>

<script lang="ts">
import { Component, Mixins, Prop } from 'vue-property-decorator'
import StateMixin from '@/mixins/state'
import { Icons } from '@/globals'
import type { ExcludeObjectPart } from '@/store/printer/types'
@Component({})
export default class ExcludeObjects extends Mixins(StateMixin) {
@Prop({ type: String })
readonly shapeRendering?: string
get parts () {
const parts = this.$store.getters['parts/getParts']
return Object.keys(parts)
return this.$store.getters['printer/getExcludeObjectParts'] as ExcludeObjectPart[]
}
iconClasses (name: string) {
return this.isPartExcluded(name) ? 'partExcluded' : this.isPartCurrent(name) ? 'partCurrent' : 'partIncluded'
iconClasses (part: ExcludeObjectPart) {
if (part.isExcluded) {
return 'partExcluded'
} else if (part.isCurrent) {
return 'partCurrent'
} else {
return 'partIncluded'
}
}
partSVG (name: string) {
return this.$store.getters['parts/getPartSVG'](name)
partSVG (part: ExcludeObjectPart) {
const polygonAsString = part.polygon!
.map(point => `${point[0]},${point[1]}`)
.join('L')
return `M${polygonAsString}z`
}
get iconCancelled () {
Expand All @@ -61,18 +78,6 @@ export default class ExcludeObjects extends Mixins(StateMixin) {
get iconCircle () {
return Icons.circle
}
partPos (name: string) {
return this.$store.getters['parts/getPartPos'](name)
}
isPartCurrent (name: string) {
return this.$store.getters['parts/getIsPartCurrent'](name)
}
isPartExcluded (name: string) {
return this.$store.getters['parts/getIsPartExcluded'](name)
}
}
</script>

Expand Down
28 changes: 10 additions & 18 deletions src/components/widgets/exclude-objects/ExcludeObjectsDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@
<v-simple-table>
<tbody>
<tr
v-for="name in parts"
:key="name"
v-for="part in parts"
:key="part.name"
>
<td
:class="{
'text--disabled': isPartExcluded(name),
'info--text': isPartCurrent(name)
'text--disabled': part.isExcluded,
'info--text': part.isCurrent
}"
class="partName"
>
{{ name }}
{{ part.name }}
</td>
<td class="actions">
<app-btn
icon
:disabled="isPartExcluded(name)"
@click="cancelObject(name)"
:disabled="part.isExcluded"
@click="cancelObject(part.name)"
>
<v-icon
dense
Expand All @@ -46,23 +46,15 @@
import { Component, Mixins, VModel } from 'vue-property-decorator'
import StateMixin from '@/mixins/state'
import { encodeGcodeParamValue } from '@/util/gcode-helpers'
import type { ExcludeObjectPart } from '@/store/printer/types'
@Component({})
export default class ExcludeObjectDialog extends Mixins(StateMixin) {
@VModel({ type: Boolean })
open?: boolean
get parts () {
const parts = this.$store.getters['parts/getParts']
return Object.keys(parts)
}
isPartExcluded (name: string) {
return this.$store.getters['parts/getIsPartExcluded'](name)
}
isPartCurrent (name: string) {
return this.$store.getters['parts/getIsPartCurrent'](name)
get parts (): ExcludeObjectPart[] {
return this.$store.getters['printer/getExcludeObjectParts'] as ExcludeObjectPart[]
}
async cancelObject (name: string) {
Expand Down
6 changes: 3 additions & 3 deletions src/components/widgets/gcode-preview/GcodePreview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -503,12 +503,12 @@ export default class GcodePreview extends Mixins(StateMixin, BrowserMixin) {
return this.panning ? 'optimizeSpeed' : 'geometricPrecision'
}
get hasParts (): boolean {
return this.$store.getters['parts/getHasParts'] as boolean
get hasExcludeObjectParts (): boolean {
return this.$store.getters['printer/getHasExcludeObjectParts'] as boolean
}
get showExcludeObjects (): boolean {
if (!this.hasParts) {
if (!this.klippyReady || !this.hasExcludeObjectParts) {
return false
}
Expand Down
4 changes: 0 additions & 4 deletions src/components/widgets/gcode-preview/GcodePreviewCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -404,10 +404,6 @@ export default class GcodePreviewCard extends Mixins(StateMixin, FilesMixin, Bro
}
}
get parts () {
return Object.values(this.$store.getters['parts/getParts'])
}
handleDragOver (event: DragEvent) {
if (
event.dataTransfer &&
Expand Down
6 changes: 3 additions & 3 deletions src/components/widgets/status/StatusControls.vue
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
<template #activator="{ on, attrs }">
<app-btn
v-bind="attrs"
:disabled="!hasParts"
:disabled="!hasExcludeObjectParts"
icon
v-on="on"
@click="showExcludeObjectDialog = true"
Expand Down Expand Up @@ -116,8 +116,8 @@ export default class StatusControls extends Mixins(StateMixin) {
return this.$store.getters['server/componentSupport']('history') as boolean
}
get hasParts (): boolean {
return this.$store.getters['parts/getHasParts'] as boolean
get hasExcludeObjectParts (): boolean {
return this.$store.getters['printer/getHasExcludeObjectParts'] as boolean
}
resetFile () {
Expand Down
16 changes: 0 additions & 16 deletions src/store/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,6 @@ export const handleTrinamicDriversChange = (payload: any, state: RootState, disp
}
}

export const handleExcludeObjectChange = (payload: any, state: RootState, dispatch: Dispatch) => {
// For every notify - if print_stats.state changes from standby -> printing,
// then record an entry in our print history.
// If the state changes from printing -> complete, then record the finish time.
if ('exclude_object' in payload) {
dispatch('parts/onPartUpdate', payload.exclude_object, { root: true })
}

if (
'print_stats' in payload &&
('state' in payload.print_stats || 'filename' in payload.print_stats)
) {
dispatch('parts/onPrintStatsUpdate', payload.print_stats, { root: true })
}
}

export const handlePrintStateChange = (payload: any, state: RootState, dispatch: Dispatch) => {
// For every notify - if print_stats.state changes from standby -> printing,
// then record an entry in our print history.
Expand Down
2 changes: 0 additions & 2 deletions src/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import { announcements } from './announcements'
import { wait } from './wait'
import { gcodePreview } from './gcodePreview'
import { timelapse } from './timelapse'
import { parts } from './parts'
import { webcams } from './webcams'
import { jobQueue } from './jobQueue'
import { spoolman } from './spoolman'
Expand Down Expand Up @@ -54,7 +53,6 @@ export default new Vuex.Store<RootState>({
wait,
gcodePreview,
timelapse,
parts,
webcams,
jobQueue,
spoolman,
Expand Down
20 changes: 0 additions & 20 deletions src/store/parts/actions.ts

This file was deleted.

46 changes: 0 additions & 46 deletions src/store/parts/getters.ts

This file was deleted.

17 changes: 0 additions & 17 deletions src/store/parts/index.ts

This file was deleted.

Loading

0 comments on commit 86daf10

Please sign in to comment.