-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
in this project you can enter gcode commands and it renders the toolpath very rough interface
- Loading branch information
1 parent
22e1520
commit 5f418b4
Showing
11 changed files
with
37,895 additions
and
11,533 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# editor | ||
- grouping commands | ||
- visual representation of groups | ||
- editing commands | ||
- autocomplete/suggest | ||
- saving and loading files | ||
- loops | ||
- variables | ||
- functional blocks | ||
|
||
# viewer | ||
- display shell object | ||
- display printed example | ||
- display build area | ||
- simulate machine movements | ||
- rigging a machine | ||
- reverse kinematics | ||
- autozoom | ||
- play toolpath as animation | ||
|
||
# advanced toolpaths | ||
- 6 DOF | ||
- view different machine operations (temperature, feedrate, ...) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,12 @@ | ||
.App { | ||
text-align: center; | ||
width:100vw; | ||
height:100vh; | ||
display: grid; | ||
grid-template: | ||
'editor' 'viewer' | ||
/ 1fr 1fr; | ||
} | ||
|
||
.App-logo { | ||
height: 40vmin; | ||
pointer-events: none; | ||
} | ||
|
||
@media (prefers-reduced-motion: no-preference) { | ||
.App-logo { | ||
animation: App-logo-spin infinite 20s linear; | ||
} | ||
} | ||
|
||
.App-header { | ||
background-color: #282c34; | ||
min-height: 100vh; | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
justify-content: center; | ||
font-size: calc(10px + 2vmin); | ||
color: white; | ||
} | ||
|
||
.App-link { | ||
color: #61dafb; | ||
} | ||
|
||
@keyframes App-logo-spin { | ||
from { | ||
transform: rotate(0deg); | ||
} | ||
to { | ||
transform: rotate(360deg); | ||
} | ||
* { | ||
box-sizing: border-box; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,18 @@ | ||
import logo from './logo.svg'; | ||
import './App.css'; | ||
import { useState } from 'react'; | ||
import GcodeEditor from './components/GcodeEditor'; | ||
import GcodeViewer from './components/GcodeViewer'; | ||
|
||
|
||
function App() { | ||
return ( | ||
<div className="App"> | ||
<header className="App-header"> | ||
<img src={logo} className="App-logo" alt="logo" /> | ||
<p> | ||
Edit <code>src/App.js</code> and save to reload. | ||
</p> | ||
<a | ||
className="App-link" | ||
href="https://reactjs.org" | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
> | ||
Learn React | ||
</a> | ||
</header> | ||
</div> | ||
); | ||
const [gcode, setGcode] = useState(''); | ||
return ( | ||
<div className="App"> | ||
|
||
<GcodeEditor gcode={gcode} onChange={setGcode} /> | ||
<GcodeViewer gcode={gcode} /> | ||
</div> | ||
); | ||
} | ||
|
||
export default App; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
import './style.css'; | ||
import { useEffect, useState } from 'react'; | ||
|
||
|
||
const GcodeArg = props => { | ||
const { children: arg } = props; | ||
const argType = arg.slice(0, 1); | ||
const argValue = arg.slice(1); | ||
return ( | ||
<div className={`GcodeArg GcodeArg-${argType}`}> | ||
<div className="block"> | ||
<span>{argType}</span> | ||
<span>{argValue}</span> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
const Gcode = props => { | ||
const { children: code } = props; | ||
const [command, ...args] = code.split(' '); | ||
const commandType = command.slice(0, 1); | ||
const commandValue = command.slice(1); | ||
const commands = { | ||
G1: { | ||
name: 'move' | ||
}, | ||
M204: { | ||
name: 'acceleration' | ||
} | ||
} | ||
if (commandType === 'G') { | ||
if (commandValue === '1') { | ||
return ( | ||
<div className={`Gcode Gcode-${commandType}-command`}> | ||
<div className="block"> | ||
Move | ||
{/* XYZEF */} | ||
</div> | ||
{args.length > 0 && args.map(arg => <GcodeArg key={arg}>{arg}</GcodeArg>)} | ||
</div> | ||
); | ||
} | ||
} else if (commandType === 'M') { | ||
if (commandValue === '204') { | ||
return ( | ||
<div className={`Gcode Gcode-${commandType}-command`}> | ||
<div className="block"> | ||
Acceleration | ||
{/* | ||
P: printing | ||
T: travel | ||
R: retraction | ||
*/} | ||
</div> | ||
{args.length > 0 && args.map(arg => <GcodeArg key={arg}>{arg}</GcodeArg>)} | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
return ( | ||
<div className={`Gcode Gcode-${commandType}-command`}> | ||
<div className="block"> | ||
<span>{commandType}</span> | ||
<span>{commandValue}</span> | ||
</div> | ||
{args.length > 0 && args.map(arg => <GcodeArg key={arg}>{arg}</GcodeArg>)} | ||
</div> | ||
); | ||
}; | ||
|
||
const GcodeLine = props => { | ||
const { children: value } = props; | ||
const [code, ...commentParts] = value.split(';'); | ||
const comment = commentParts.join(';').trim(); | ||
const hasCode = Boolean(code.replace(/\s/g, '').length); | ||
return ( | ||
<div className={`GcodeLine ${hasCode ? '' : 'noCode'}`}> | ||
{hasCode && <Gcode>{code.trim()}</Gcode>} | ||
{comment !== '' && <div className="comment">{comment}</div>} | ||
</div> | ||
); | ||
}; | ||
|
||
const GcodeEditor = props => { | ||
const { | ||
gcode, | ||
onChange | ||
} = props; | ||
const [newLine, setNewLine] = useState(null); | ||
const [lineCopy, setLineCopy] = useState(null); | ||
|
||
useEffect(() => { | ||
if (lineCopy > 0 && lineCopy < lines.length) setNewLine(lines[lines.length - lineCopy]); | ||
if (lineCopy === 0 ) { | ||
setNewLine('G1 '); | ||
} | ||
}, [lineCopy]); | ||
|
||
const lines = gcode.split('\n'); | ||
return ( | ||
<div className="GcodeEditor"> | ||
{lines.map((line, index) => | ||
<GcodeLine key={index}>{line}</GcodeLine> | ||
)} | ||
{!newLine && <div onClick={() => setNewLine('G1 ')} className="addLine"><div>+</div>add line</div>} | ||
{newLine && <div className="newLine"><input | ||
type="text" | ||
value={newLine} | ||
onChange={e => setNewLine(e.target.value)} | ||
onKeyUp={e => { | ||
switch (e.key) { | ||
case 'Enter': { | ||
onChange(`${gcode} | ||
${e.target.value}`); | ||
setNewLine('G1 '); | ||
setLineCopy(null); | ||
break; | ||
} | ||
case 'ArrowUp': { | ||
setLineCopy(lineCopy => lineCopy + 1) | ||
break; | ||
} | ||
case 'ArrowDown': { | ||
if (lineCopy !== 0) setLineCopy(lineCopy => lineCopy - 1); | ||
break; | ||
} | ||
default: break; | ||
} | ||
}} | ||
/><div className="closeNewLine" onClick={() => setNewLine(null)}>×</div></div>} | ||
|
||
</div> | ||
); | ||
}; | ||
|
||
export default GcodeEditor; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
.GcodeEditor { | ||
height: 100%; | ||
overflow-y: scroll; | ||
padding: 1rem; | ||
background: lch(9% 0 270 / 1); | ||
color: lch(80% 0 0); | ||
counter-reset: section; | ||
font-family: monospace; | ||
line-height: 1.2rem; | ||
} | ||
|
||
.GcodeEditor .addLine { | ||
display: inline-flex; | ||
gap: .5rem; | ||
padding: .2rem .8rem .2rem .2rem; | ||
margin-top: .1rem; | ||
margin-left: calc(4ch + 1rem); | ||
border-radius: .2rem; | ||
transition: .2s; | ||
line-height: 1rem; | ||
} | ||
.GcodeEditor .addLine:hover { | ||
background: lch(35% 50 270 / .3); | ||
} | ||
.GcodeEditor .addLine div{ | ||
background-color: lch(35% 50 270 / 1); | ||
width: 1rem; | ||
border-radius: 50%; | ||
text-align: center; | ||
} | ||
|
||
.GcodeEditor .newLine { | ||
display: flex; | ||
gap: .5rem; | ||
margin-left: calc(4ch + 1rem); | ||
padding: .15rem 0; | ||
} | ||
|
||
.GcodeEditor .newLine div{ | ||
color: lch(30% 0 0); | ||
border: 1px solid currentColor; | ||
width: 1.4rem; | ||
border-radius: 50%; | ||
text-align: center; | ||
transition: .2s; | ||
} | ||
.GcodeEditor .newLine div:hover{ | ||
color: lch(70% 0 0); | ||
} | ||
|
||
.GcodeEditor .newLine input{ | ||
appearance: none; | ||
border: none; | ||
background: lch(35% 50 270 / .3); | ||
color: lch(80% 0 0); | ||
font-family: monospace; | ||
padding: 0 .4rem; | ||
border-radius: .2rem; | ||
margin: 0; | ||
} | ||
|
||
.GcodeLine { | ||
display: flex; | ||
padding: .15rem 0; | ||
min-height: 1.2rem; | ||
gap: 1rem; | ||
} | ||
.GcodeLine.noCode { | ||
text-indent: calc(4ch + 1rem); | ||
padding: 0; | ||
} | ||
.GcodeLine:not(.noCode):before { | ||
counter-increment: section; | ||
content: counter(section); | ||
color: lch(30% 0 0); | ||
text-align: right; | ||
width: 4ch; | ||
} | ||
|
||
.Gcode { | ||
display: flex; | ||
gap: .6rem; | ||
background-color: lch(30% 0 0); | ||
padding: 0 .4rem; | ||
border-radius: .2rem; | ||
} | ||
|
||
.Gcode-G-command { | ||
background-color: lch(45% 50 30); | ||
} | ||
|
||
.Gcode-M-command { | ||
background-color: lch(45% 50 130); | ||
} | ||
|
||
.GcodeLine .comment { | ||
color: lch(50% 0 0); | ||
white-space: pre-wrap; | ||
} | ||
|
Oops, something went wrong.