* updates
Signed-off-by: Jess Frazelle <github@jessfraz.com>
* updates
Signed-off-by: Jess Frazelle <github@jessfraz.com>
* updates
Signed-off-by: Jess Frazelle <github@jessfraz.com>
* make tsc happ
* better error msg
* fix control point issue
* basic code gen working for tangentialArc
* partical fix for move with arcs
* tangential arc move
* fix
* make eslint rules less annoying
* inital refactor of some xstate stuff
* more old tangential arc clean up stuff
* more tweaks
* add testing
* tweak xstate inspect
* temp remove test
* update formating for less conflicts
* fix state machine layout after merge
* shrug, something weird with xstate typegen
* renaming some xstate events
* tweak numbers to make CI playwright happ
* CI hacks
* more CI hacks
* more CI hacks
* new hack strategy
* run tests agian
* make cmd bar less flaky
* ci hacks
* CI hacks
* CI hacks
* CI hacks
* clean up
* fix
* still have constraint stuff to deal with
* progress on move rules
* update source ranges after no execute code-mod
* typo
* mvp working
* hide show sketch overlay
* match scaling
* update arrow head style
* animate line tool
* bypass xstate for animations, much smoother
* add new segment working with refactor needed for setup paper sketch
* refactor setup paper sketch
* tangantialArcTo drag animations working
* tangential arc polish
* cargo fmt
* clippy
* more clippy
* mock canvas
* last of clippy?
* typo
* more clippy stuff
* move util function so they are shareable with typescript
* migrate a bunch to rust and only rust
* add arc center point for draft tangential ac
* clippy tweak
* delete uneeded test
* Rough start to scaling arrow heads.
The tangent arrow heads are basically nuked and replaced while the
straight line sections are just rotated and repositioned, this means they
miss out on updating scaling number after a screen size changes.
Needs fixing
* fix bug with tool tips
* fix draft line start position
Having drag the end of teh path before selecting a tooltip would result in the draft line starting where the path used to end, stale data
* some progress with pan maybe
* fmt
* inital camera sync working
For perspective camera at least
* change three.js to use z-up
* add grid
* orthographic camera working with polish items TODO
* fix zoom level when swapping camera
* fix up camera/orbit changing on cam change (pan wasn't being respected)
* tidy up
* use orbit target instead of assuming scene center
* dynamic fov working
* animate orthographic to perspective and reverse
* fix import
* temp fix for batch commands
* initial client side scene sketch working
* remove hover log
* FOV adjust fix
* fix comment
* tear down sketch and small tweaks
* some progress with camera tweening
* combine dollyZoom engine commands
see
https://github.com/KittyCAD/modeling-api/compare/kurt-perspective-settings?expand=1
and
https://github.com/KittyCAD/engine/compare/kurt-perspective-settings?expand=1
* make tests happy (mocks)
* fix tween to vertical/camera-up bug
* tween to each axis with hacky solutions in there
* fix startSketchOn planes
* tidy startSketchOn
* tweening okay for now I think
* get sketching on default planes working
* allow editing on all default planes
* clean up enter and exit sketch logic
* tidy
* tidy
* remove more default plane stuff
* start of draft line
* remove some annoying parts of the paper.js implementation
* fix drag than equip line bug
* comment
* don't animate on skech tear down since it's used for draft line
* remove more default plane shit
* style draft line
* refine dashed line
* draft line set up and tear down mostly happy
* add on click logic ready for draft lines
* sketch mode with drag and draft mode working solidly now, straight segments only
* default planes match colors, hover and select still TODO
* hover and click logic working for default planes
Now just need the code mode to fire to 'startSketchOn(...)'
* select default planes
* remove some logs
* fix update infinite loop
* start of orbitControls port to Franks control guards
* hiding scenes at different times
* scene hide on camera move should be respected by scroll zoom
* basic hover working
* Hook up user camera settings to ClientSideScene (#1334)
* Refactor to not import utilities from Router.tsx
* Stop tracking changes or formatting *.typegen.ts
* Hook up cameraControls to ClientSideScene
* Remove camera controls toggle from temp debug panel
---------
Co-authored-by: Kurt Hutten Irev-Dev <k.hutten@protonmail.ch>
* add select segment moves cursor
* highlight segments yellow on hover
* cursor ranges effect 2d line colors
* fix constrainst i.e. make sure the sketch is rejiged
* selecting nothing should remove selections
* remove hardcoded strings
* update get_tangential_arc_to_info rust util
* initial drawing of tangential arcs in client scene
* fix tangentialArc arrow head direction
* correct userData types for tangential arcs
* get tangential arc updates working
Doesn't include draging the head of the tangential arc itself yet
* spot of clean up
* make selections work with tangential arcs
* get draft tangential segment animated
* fix initial click weirdness for adding new tangential line
* couple tweaks
* add grace pixels /threshold to raycast
* redo arc dashes so that they spawn from the ccenter of the arc
* fix multi drag bug
* fmt
* add temp solution for close
* add default axis hover colors, still needs select logic
* selection of axis works, just with out selection color
* get axis selection colors working
* fix outdate source ranges after drag problem
* update moreNodePathFromSourceRange
* fix ts-rs issue/workaround
* fix default plane weirdness
* fix tangential arc rounding issue
* review clean up part 1
* review clean up part 2
Big state-diagram cull
* clippy
* typo
* clippy
* fix xstate types with typegen
* fix types
* clippy
* catch error
* fix test import issue
Not sure exactly what was happening but guessing circular import that vite didn't like
* add axis/plane info to sketch group tests
* case changes because of rs-ts bug, can probably revert this later
* start of playwright test fixes
* reduce geo complexity for straight segments
* fix cam adjust tests
* Revert "Clean up vite build warnings (#1332)"
This reverts commit c1f661ab52
.
* selection e2e test fixed<
* remove camToggle to allow playwright tests to pass
* remove drag test
too brittle and needs to be redone from the ground up anyway
* trigger CI
* A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu)
* fix last test
* clean up part 3
* clean up part 4
* clean up part 5
* clean up sketch enter exit logic
* fix engine side selections
* default plane should not be selected form 'onDragEnd'
i.e. rotating the camera should not mean the user acidently selects a plane
* clean up state diagram around animating to sketch mode
Embracing that the animation is async and puting the interdiate steps in the state diagram clean up some logic and solved some bugs at the same time
* add test for multiple sketches
* typo
* make highlight more robust
* type tweak
* scale segmenst with distance from camera so they have a consistent pixel size/ screenspace size
* Jess's advice
* tsc and fmt
* clean up part 6
remove integer from xstate names
* clean up part 7
* integrate sequency in to camera moves
* fix tests
* update snapshot e2e
* small snapshot change
* A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu)
* trigger ci
* Fix HomeLoaderData types
* update std stuff
* update kittycad rs client lib
---------
Signed-off-by: Jess Frazelle <github@jessfraz.com>
Co-authored-by: Jess Frazelle <github@jessfraz.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
303 lines
8.5 KiB
TypeScript
303 lines
8.5 KiB
TypeScript
import {
|
|
FileEntry,
|
|
createDir,
|
|
exists,
|
|
readDir,
|
|
writeTextFile,
|
|
} from '@tauri-apps/api/fs'
|
|
import { documentDir, homeDir, sep } from '@tauri-apps/api/path'
|
|
import { isTauri } from './isTauri'
|
|
import { type ProjectWithEntryPointMetadata } from 'lib/types'
|
|
import { metadata } from 'tauri-plugin-fs-extra-api'
|
|
|
|
const PROJECT_FOLDER = 'zoo-modeling-app-projects'
|
|
export const FILE_EXT = '.kcl'
|
|
export const PROJECT_ENTRYPOINT = 'main' + FILE_EXT
|
|
const INDEX_IDENTIFIER = '$n' // $nn.. will pad the number with 0s
|
|
export const MAX_PADDING = 7
|
|
const RELEVANT_FILE_TYPES = ['kcl']
|
|
|
|
// Initializes the project directory and returns the path
|
|
export async function initializeProjectDirectory(directory: string) {
|
|
if (!isTauri()) {
|
|
throw new Error(
|
|
'initializeProjectDirectory() can only be called from a Tauri app'
|
|
)
|
|
}
|
|
|
|
if (directory) {
|
|
const dirExists = await exists(directory)
|
|
if (!dirExists) {
|
|
await createDir(directory, { recursive: true })
|
|
}
|
|
return directory
|
|
}
|
|
|
|
let docDirectory: string
|
|
try {
|
|
docDirectory = await documentDir()
|
|
} catch (e) {
|
|
console.log('error', e)
|
|
docDirectory = `${await homeDir()}Documents/` // for headless Linux (eg. Github Actions)
|
|
}
|
|
|
|
const INITIAL_DEFAULT_DIR = docDirectory + PROJECT_FOLDER
|
|
|
|
const defaultDirExists = await exists(INITIAL_DEFAULT_DIR)
|
|
|
|
if (!defaultDirExists) {
|
|
await createDir(INITIAL_DEFAULT_DIR, { recursive: true })
|
|
}
|
|
|
|
return INITIAL_DEFAULT_DIR
|
|
}
|
|
|
|
export function isProjectDirectory(fileOrDir: Partial<FileEntry>) {
|
|
return (
|
|
fileOrDir.children?.length &&
|
|
fileOrDir.children.some((child) => child.name === PROJECT_ENTRYPOINT)
|
|
)
|
|
}
|
|
|
|
// Read the contents of a directory
|
|
// and return the valid projects
|
|
export async function getProjectsInDir(projectDir: string) {
|
|
const readProjects = (
|
|
await readDir(projectDir, {
|
|
recursive: true,
|
|
})
|
|
).filter(isProjectDirectory)
|
|
|
|
const projectsWithMetadata = await Promise.all(
|
|
readProjects.map(async (p) => ({
|
|
entrypointMetadata: await metadata(p.path + sep + PROJECT_ENTRYPOINT),
|
|
...p,
|
|
}))
|
|
)
|
|
|
|
return projectsWithMetadata
|
|
}
|
|
|
|
export const isHidden = (fileOrDir: FileEntry) =>
|
|
!!fileOrDir.name?.startsWith('.')
|
|
|
|
export const isDir = (fileOrDir: FileEntry) =>
|
|
'children' in fileOrDir && fileOrDir.children !== undefined
|
|
|
|
export function deepFileFilter(
|
|
entries: FileEntry[],
|
|
filterFn: (f: FileEntry) => boolean
|
|
): FileEntry[] {
|
|
const filteredEntries: FileEntry[] = []
|
|
for (const fileOrDir of entries) {
|
|
if ('children' in fileOrDir && fileOrDir.children !== undefined) {
|
|
const filteredChildren = deepFileFilter(fileOrDir.children, filterFn)
|
|
if (filterFn(fileOrDir)) {
|
|
filteredEntries.push({
|
|
...fileOrDir,
|
|
children: filteredChildren,
|
|
})
|
|
}
|
|
} else if (filterFn(fileOrDir)) {
|
|
filteredEntries.push(fileOrDir)
|
|
}
|
|
}
|
|
return filteredEntries
|
|
}
|
|
|
|
export function deepFileFilterFlat(
|
|
entries: FileEntry[],
|
|
filterFn: (f: FileEntry) => boolean
|
|
): FileEntry[] {
|
|
const filteredEntries: FileEntry[] = []
|
|
for (const fileOrDir of entries) {
|
|
if ('children' in fileOrDir && fileOrDir.children !== undefined) {
|
|
const filteredChildren = deepFileFilterFlat(fileOrDir.children, filterFn)
|
|
if (filterFn(fileOrDir)) {
|
|
filteredEntries.push({
|
|
...fileOrDir,
|
|
children: filteredChildren,
|
|
})
|
|
}
|
|
filteredEntries.push(...filteredChildren)
|
|
} else if (filterFn(fileOrDir)) {
|
|
filteredEntries.push(fileOrDir)
|
|
}
|
|
}
|
|
return filteredEntries
|
|
}
|
|
|
|
// Read the contents of a project directory
|
|
// and return all relevant files and sub-directories recursively
|
|
export async function readProject(projectDir: string) {
|
|
const readFiles = await readDir(projectDir, {
|
|
recursive: true,
|
|
})
|
|
|
|
return deepFileFilter(readFiles, isRelevantFileOrDir)
|
|
}
|
|
|
|
// Given a read project, return the number of .kcl files,
|
|
// both in the root directory and in sub-directories,
|
|
// and folders that contain at least one .kcl file
|
|
export function getPartsCount(project: FileEntry[]) {
|
|
const flatProject = deepFileFilterFlat(project, isRelevantFileOrDir)
|
|
|
|
const kclFileCount = flatProject.filter((f) =>
|
|
f.name?.endsWith(FILE_EXT)
|
|
).length
|
|
const kclDirCount = flatProject.filter((f) => f.children !== undefined).length
|
|
|
|
return {
|
|
kclFileCount,
|
|
kclDirCount,
|
|
}
|
|
}
|
|
|
|
// Determines if a file or directory is relevant to the project
|
|
// i.e. not a hidden file or directory, and is a relevant file type
|
|
// or contains at least one relevant file (even if it's nested)
|
|
// or is a completely empty directory
|
|
export function isRelevantFileOrDir(fileOrDir: FileEntry) {
|
|
let isRelevantDir = false
|
|
if ('children' in fileOrDir && fileOrDir.children !== undefined) {
|
|
isRelevantDir =
|
|
!isHidden(fileOrDir) &&
|
|
(fileOrDir.children.some(isRelevantFileOrDir) ||
|
|
fileOrDir.children.length === 0)
|
|
}
|
|
const isRelevantFile =
|
|
!isHidden(fileOrDir) &&
|
|
RELEVANT_FILE_TYPES.some((ext) => fileOrDir.name?.endsWith(ext))
|
|
|
|
return (
|
|
(isDir(fileOrDir) && isRelevantDir) || (!isDir(fileOrDir) && isRelevantFile)
|
|
)
|
|
}
|
|
|
|
// Deeply sort the files and directories in a project like VS Code does:
|
|
// The main.kcl file is always first, then files, then directories
|
|
// Files and directories are sorted alphabetically
|
|
export function sortProject(project: FileEntry[]): FileEntry[] {
|
|
const sortedProject = project.sort((a, b) => {
|
|
if (a.name === PROJECT_ENTRYPOINT) {
|
|
return -1
|
|
} else if (b.name === PROJECT_ENTRYPOINT) {
|
|
return 1
|
|
} else if (a.children === undefined && b.children !== undefined) {
|
|
return -1
|
|
} else if (a.children !== undefined && b.children === undefined) {
|
|
return 1
|
|
} else if (a.name && b.name) {
|
|
return a.name.localeCompare(b.name)
|
|
} else {
|
|
return 0
|
|
}
|
|
})
|
|
|
|
return sortedProject.map((fileOrDir: FileEntry) => {
|
|
if ('children' in fileOrDir && fileOrDir.children !== undefined) {
|
|
return {
|
|
...fileOrDir,
|
|
children: sortProject(fileOrDir.children),
|
|
}
|
|
} else {
|
|
return fileOrDir
|
|
}
|
|
})
|
|
}
|
|
|
|
// Creates a new file in the default directory with the default project name
|
|
// Returns the path to the new file
|
|
export async function createNewProject(
|
|
path: string,
|
|
initCode = ''
|
|
): Promise<ProjectWithEntryPointMetadata> {
|
|
if (!isTauri) {
|
|
throw new Error('createNewProject() can only be called from a Tauri app')
|
|
}
|
|
|
|
const dirExists = await exists(path)
|
|
if (!dirExists) {
|
|
await createDir(path, { recursive: true }).catch((err) => {
|
|
console.error('Error creating new directory:', err)
|
|
throw err
|
|
})
|
|
}
|
|
|
|
await writeTextFile(path + sep + PROJECT_ENTRYPOINT, initCode).catch(
|
|
(err) => {
|
|
console.error('Error creating new file:', err)
|
|
throw err
|
|
}
|
|
)
|
|
|
|
const m = await metadata(path)
|
|
|
|
return {
|
|
name: path.slice(path.lastIndexOf(sep) + 1),
|
|
path: path,
|
|
entrypointMetadata: m,
|
|
children: [
|
|
{
|
|
name: PROJECT_ENTRYPOINT,
|
|
path: path + sep + PROJECT_ENTRYPOINT,
|
|
children: [],
|
|
},
|
|
],
|
|
}
|
|
}
|
|
|
|
// create a regex to match the project name
|
|
// replacing any instances of "$n" with a regex to match any number
|
|
function interpolateProjectName(projectName: string) {
|
|
const regex = new RegExp(
|
|
projectName.replace(getPaddedIdentifierRegExp(), '([0-9]+)')
|
|
)
|
|
return regex
|
|
}
|
|
|
|
// Returns the next available index for a project name
|
|
export function getNextProjectIndex(projectName: string, files: FileEntry[]) {
|
|
const regex = interpolateProjectName(projectName)
|
|
const matches = files.map((file) => file.name?.match(regex))
|
|
const indices = matches
|
|
.filter(Boolean)
|
|
.map((match) => match![1])
|
|
.map(Number)
|
|
const maxIndex = Math.max(...indices, -1)
|
|
return maxIndex + 1
|
|
}
|
|
|
|
// Interpolates the project name with the next available index,
|
|
// padding the index with 0s if necessary
|
|
export function interpolateProjectNameWithIndex(
|
|
projectName: string,
|
|
index: number
|
|
) {
|
|
const regex = getPaddedIdentifierRegExp()
|
|
|
|
const matches = projectName.match(regex)
|
|
const padStartLength = Math.min(
|
|
matches !== null ? matches[1]?.length || 0 : 0,
|
|
MAX_PADDING
|
|
)
|
|
return projectName.replace(
|
|
regex,
|
|
index.toString().padStart(padStartLength + 1, '0')
|
|
)
|
|
}
|
|
|
|
export function doesProjectNameNeedInterpolated(projectName: string) {
|
|
return projectName.includes(INDEX_IDENTIFIER)
|
|
}
|
|
|
|
function escapeRegExpChars(string: string) {
|
|
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
|
|
}
|
|
|
|
function getPaddedIdentifierRegExp() {
|
|
const escapedIdentifier = escapeRegExpChars(INDEX_IDENTIFIER)
|
|
return new RegExp(`${escapedIdentifier}(${escapedIdentifier.slice(-1)}*)`)
|
|
}
|