Completed initial CAD package guides, tweaked initial code import
This commit is contained in:
17
app/web/src/helpers/cadPackages/cadQuery/initialCode.py
Normal file
17
app/web/src/helpers/cadPackages/cadQuery/initialCode.py
Normal file
@@ -0,0 +1,17 @@
|
||||
# demo shaft coupler
|
||||
|
||||
# ^ first comment is used for download title (i.e. "demo-shaft-coupler.stl")
|
||||
|
||||
# CadQuery docs: https://cadquery.readthedocs.io/
|
||||
|
||||
import cadquery as cq
|
||||
from cadquery import exporters
|
||||
|
||||
diam = 5.0
|
||||
|
||||
result = (cq.Workplane().circle(diam).extrude(20.0)
|
||||
.faces(">Z").workplane(invert=True).circle(1.05).cutBlind(8.0)
|
||||
.faces("<Z").workplane(invert=True).circle(0.8).cutBlind(12.0)
|
||||
.edges("%CIRCLE").chamfer(0.15))
|
||||
|
||||
show_object(result)
|
||||
@@ -1,9 +1,10 @@
|
||||
---
|
||||
"Written with": Python
|
||||
"Kernal type": BREP
|
||||
title: CadQuery
|
||||
Written with: Python
|
||||
Kernal type: BREP
|
||||
Maintained by: [The CadQuery Group](https://github.com/CadQuery)
|
||||
Documentation: [cadquery.readthedocs.io](https://cadquery.readthedocs.io)
|
||||
---
|
||||
# CadQuery
|
||||
|
||||
CadQuery is an intuitive, easy-to-use Python library for building parametric 3D CAD models. It has several goals:
|
||||
|
||||
- Build models with scripts that are as close as possible to how you’d describe the object to a human, using a standard, already established programming language
|
||||
|
||||
33
app/web/src/helpers/cadPackages/jsCad/initialCode.jscad
Normal file
33
app/web/src/helpers/cadPackages/jsCad/initialCode.jscad
Normal file
@@ -0,0 +1,33 @@
|
||||
const jscad = require('@jscad/modeling')
|
||||
// https://openjscad.xyz/docs/module-modeling_primitives.html
|
||||
const { cuboid, cylinder } = jscad.primitives
|
||||
|
||||
const { rotate, translate } = jscad.transforms
|
||||
const { degToRad } = jscad.utils // because jscad uses radians for rotations
|
||||
// https://openjscad.xyz/docs/module-modeling_booleans.html
|
||||
const { subtract } = jscad.booleans
|
||||
|
||||
function main({//@jscad-params
|
||||
// Box example
|
||||
width=40, // Width
|
||||
length=20, // Length
|
||||
height=10, // Height
|
||||
hole=3,// Hole for cables diameter (0=no hole)
|
||||
wall=1, // wall {min:0.5, step:0.5}
|
||||
flip=0, // print orientation {type: 'choice', values: [0, 90, 180]}
|
||||
}){
|
||||
|
||||
let wallOffset = wall * 2
|
||||
let model = subtract(
|
||||
cuboid({size:[width, length, height]}),
|
||||
translate([0,0,wall], cuboid({size:[width-wallOffset, length-wallOffset, height+wall]})),
|
||||
)
|
||||
if(hole){
|
||||
model = subtract( model,
|
||||
translate([width/2-wall/2], rotate([0, degToRad(90), 0 ], cylinder({radius:hole/2, height:wall})))
|
||||
)
|
||||
}
|
||||
return rotate([degToRad(flip), 0, degToRad(90)], model)
|
||||
}
|
||||
|
||||
module.exports = {main}
|
||||
@@ -1,7 +1,8 @@
|
||||
---
|
||||
"Written with": JavaScript
|
||||
"Kernal type": BREP
|
||||
title: JSCAD
|
||||
Written with: JavaScript
|
||||
Kernal type: BREP
|
||||
Maintained by: [Z3 Development + 39 contributors](https://www.github.com/jscad)
|
||||
Documentation: [openjscad.xyz/docs](https://openjscad.xyz/docs/)
|
||||
---
|
||||
# JSCAD
|
||||
|
||||
JSCAD is an open source set of modular, browser and command line tools for creating parametric 2D and 3D designs with Javascript code. It provides a quick, precise and reproducible method for generating 3D models, and is especially useful for 3D printing applications.
|
||||
12
app/web/src/helpers/cadPackages/openScad/initialCode.SCAD
Normal file
12
app/web/src/helpers/cadPackages/openScad/initialCode.SCAD
Normal file
@@ -0,0 +1,12 @@
|
||||
// involute donut
|
||||
|
||||
// ^ first comment is used for download title (i.e "involute-donut.stl")
|
||||
|
||||
// Follow the OpenSCAD tutorial: https://learn.cadhub.xyz/docs/
|
||||
|
||||
radius=3;
|
||||
color(c="DarkGoldenrod")rotate_extrude()translate([20,0])circle(d=30);
|
||||
color(c="hotpink")rotate_extrude()translate([20,0])offset(radius)offset(-radius)difference(){
|
||||
circle(d=34);
|
||||
translate([-200,-500])square([500,500]);
|
||||
}
|
||||
@@ -1,7 +1,8 @@
|
||||
---
|
||||
"Written with": C+-like
|
||||
"Kernal type": BREP
|
||||
title: OpenSCAD
|
||||
Written with: Custom language
|
||||
Kernal type: BREP
|
||||
Maintained by: [Marius Kintel + 15 members](https://github.com/openscad)
|
||||
Documentation: [openscad.org](https://openscad.org/)
|
||||
---
|
||||
# OpenSCAD
|
||||
|
||||
OpenSCAD is a solid 3D modeler that enables the creation of parametric models using its scripting language. Models are created by utilizing a technique called constructive solid geometry. According to this technique, simple objects can be transformed and combined in order to create almost any complex model.
|
||||
@@ -6,6 +6,14 @@ import type {
|
||||
ArtifactTypes,
|
||||
} from 'src/helpers/cadPackages/common'
|
||||
import { CadhubParams } from 'src/components/Customizer/customizerConverter'
|
||||
import openScadGuide from 'src/helpers/cadPackages/openScad/userGuide.md'
|
||||
import openScadInitialCode from 'src/helpers/cadPackages/openScad/initialCode.SCAD'
|
||||
import cadQueryGuide from 'src/helpers/cadPackages/cadQuery/userGuide.md'
|
||||
import cadQueryInitialCode from 'src/helpers/cadPackages/cadQuery/initialCode.py'
|
||||
import jsCadGuide from 'src/helpers/cadPackages/jsCad/userGuide.md'
|
||||
import jsCadInitialCode from 'src/helpers/cadPackages/jsCad/initialCode.jscad'
|
||||
|
||||
console.log('jscad', { jsCadInitialCode })
|
||||
|
||||
function withThunk(dispatch, getState) {
|
||||
return (actionOrThunk) =>
|
||||
@@ -15,74 +23,18 @@ function withThunk(dispatch, getState) {
|
||||
}
|
||||
import { CadPackageType } from 'src/components/CadPackage/CadPackage'
|
||||
|
||||
const initCodeMap: { [key in CadPackageType]: string } = {
|
||||
openscad: `// involute donut
|
||||
|
||||
// ^ first comment is used for download title (i.e "involute-donut.stl")
|
||||
|
||||
// Follow the OpenSCAD tutorial: https://learn.cadhub.xyz/docs/
|
||||
|
||||
radius=3;
|
||||
color(c="DarkGoldenrod")rotate_extrude()translate([20,0])circle(d=30);
|
||||
color(c="hotpink")rotate_extrude()translate([20,0])offset(radius)offset(-radius)difference(){
|
||||
circle(d=34);
|
||||
translate([-200,-500])square([500,500]);
|
||||
}`,
|
||||
cadquery: `# demo shaft coupler
|
||||
|
||||
# ^ first comment is used for download title (i.e. "demo-shaft-coupler.stl")
|
||||
|
||||
# CadQuery docs: https://cadquery.readthedocs.io/
|
||||
|
||||
import cadquery as cq
|
||||
from cadquery import exporters
|
||||
|
||||
diam = 5.0
|
||||
|
||||
result = (cq.Workplane().circle(diam).extrude(20.0)
|
||||
.faces(">Z").workplane(invert=True).circle(1.05).cutBlind(8.0)
|
||||
.faces("<Z").workplane(invert=True).circle(0.8).cutBlind(12.0)
|
||||
.edges("%CIRCLE").chamfer(0.15))
|
||||
|
||||
show_object(result)
|
||||
`,
|
||||
jscad: `
|
||||
|
||||
const jscad = require('@jscad/modeling')
|
||||
// https://openjscad.xyz/docs/module-modeling_primitives.html
|
||||
const { cuboid, cylinder } = jscad.primitives
|
||||
|
||||
const { rotate, translate } = jscad.transforms
|
||||
const { degToRad } = jscad.utils // because jscad uses radians for rotations
|
||||
// https://openjscad.xyz/docs/module-modeling_booleans.html
|
||||
const { subtract } = jscad.booleans
|
||||
|
||||
function main({//@jscad-params
|
||||
// Box example
|
||||
width=40, // Width
|
||||
length=20, // Length
|
||||
height=10, // Height
|
||||
hole=3,// Hole for cables diameter (0=no hole)
|
||||
wall=1, // wall {min:0.5, step:0.5}
|
||||
flip=0, // print orientation {type: 'choice', values: [0, 90, 180]}
|
||||
}){
|
||||
|
||||
let wallOffset = wall * 2
|
||||
let model = subtract(
|
||||
cuboid({size:[width, length, height]}),
|
||||
translate([0,0,wall], cuboid({size:[width-wallOffset, length-wallOffset, height+wall]})),
|
||||
)
|
||||
if(hole){
|
||||
model = subtract( model,
|
||||
translate([width/2-wall/2], rotate([0, degToRad(90), 0 ], cylinder({radius:hole/2, height:wall})))
|
||||
)
|
||||
}
|
||||
return rotate([degToRad(flip), 0, degToRad(90)], model)
|
||||
const initGuideMap: { [key in CadPackageType]: string } = {
|
||||
openscad: openScadGuide,
|
||||
cadquery: cadQueryGuide,
|
||||
jscad: jsCadGuide,
|
||||
INIT: '',
|
||||
}
|
||||
|
||||
module.exports = {main}
|
||||
|
||||
`,
|
||||
const initCodeMap: { [key in CadPackageType]: string } = {
|
||||
openscad: openScadInitialCode,
|
||||
cadquery: cadQueryInitialCode,
|
||||
jscad: jsCadInitialCode,
|
||||
INIT: '',
|
||||
}
|
||||
|
||||
const codeStorageKey = 'Last-editor-code'
|
||||
@@ -103,6 +55,7 @@ interface EditorModel {
|
||||
|
||||
export interface State {
|
||||
ideType: 'INIT' | CadPackageType
|
||||
ideGuide?: string
|
||||
consoleMessages: { type: 'message' | 'error'; message: string; time: Date }[]
|
||||
code: string
|
||||
models: EditorModel[]
|
||||
@@ -144,10 +97,7 @@ export const initialState: State = {
|
||||
{ type: 'message', message: 'Initialising', time: new Date() },
|
||||
],
|
||||
code,
|
||||
models: [
|
||||
{ type: 'code', label: 'Code', },
|
||||
{ type: 'guide', label: 'Test', content: '# Testing!' },
|
||||
],
|
||||
models: [{ type: 'code', label: 'Code' }],
|
||||
currentModel: 0,
|
||||
objectData: {
|
||||
type: 'INIT',
|
||||
@@ -174,6 +124,7 @@ const reducer = (state: State, { type, payload }): State => {
|
||||
initCodeMap[payload.cadPackage] ||
|
||||
'',
|
||||
ideType: payload.cadPackage,
|
||||
ideGuide: initGuideMap[payload.cadPackage],
|
||||
}
|
||||
case 'updateCode':
|
||||
return { ...state, code: payload }
|
||||
@@ -290,10 +241,7 @@ const reducer = (state: State, { type, payload }): State => {
|
||||
case 'addEditorModel':
|
||||
return {
|
||||
...state,
|
||||
models: [
|
||||
...state.models,
|
||||
payload,
|
||||
]
|
||||
models: [...state.models, payload],
|
||||
}
|
||||
case 'removeEditorModel':
|
||||
return {
|
||||
@@ -302,10 +250,10 @@ const reducer = (state: State, { type, payload }): State => {
|
||||
...state.models.slice(0, payload),
|
||||
...state.models.slice(payload + 1),
|
||||
],
|
||||
currentModel: (payload === 0) ? 0 : payload - 1,
|
||||
currentModel: payload === 0 ? 0 : payload - 1,
|
||||
}
|
||||
case 'updateEditorModel': {
|
||||
let newModels = [...state.models]
|
||||
const newModels = [...state.models]
|
||||
newModels[state.currentModel].content = payload
|
||||
return {
|
||||
...state,
|
||||
@@ -313,9 +261,9 @@ const reducer = (state: State, { type, payload }): State => {
|
||||
}
|
||||
}
|
||||
case 'reorderEditorModels': {
|
||||
let newModels = [
|
||||
const newModels = [
|
||||
...state.models.slice(0, state.currentModel),
|
||||
...state.models.slice(state.currentModel + 1)
|
||||
...state.models.slice(state.currentModel + 1),
|
||||
].splice(payload, 0, state.models[state.currentModel])
|
||||
return {
|
||||
...state,
|
||||
|
||||
24
app/web/src/helpers/markdown.ts
Normal file
24
app/web/src/helpers/markdown.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
// Extracts YAML frontmatter from Markdown files
|
||||
// Gotten from this helpful comment on a react-markdown GitHub Issue: https://github.com/remarkjs/react-markdown/issues/164#issuecomment-890497653
|
||||
export function extractMetaData(text: string): Array<any> {
|
||||
const metaData = {} as any
|
||||
|
||||
const metaRegExp = RegExp(/^---[\r\n](((?!---).|[\r\n])*)[\r\n]---$/m)
|
||||
// get metadata
|
||||
const rawMetaData = metaRegExp.exec(text)
|
||||
|
||||
let keyValues
|
||||
|
||||
if (rawMetaData!) {
|
||||
// rawMeta[1] are the stuff between "---"
|
||||
keyValues = rawMetaData[1].split('\n')
|
||||
|
||||
// which returns a list of key values: ["key1: value", "key2: value"]
|
||||
keyValues.forEach((keyValue) => {
|
||||
// split each keyValue to keys and values
|
||||
const [, key, value] = keyValue.split(/(.+): (.+)/)
|
||||
metaData[key] = value.trim()
|
||||
})
|
||||
}
|
||||
return [rawMetaData, metaData]
|
||||
}
|
||||
Reference in New Issue
Block a user