GitHub

Folders and files

NameName

Last commit message

Last commit date

DSL for CAD Bodies and Assemblies

The purpose of this tool is to share 3D parts and assemblies like java class binaries.

As of today, the DSL is not complete to define bodies and assemblies will come later.

Building

Install opencascade binary package (Here on Arch)

yay -S opencascade

Check headers are here, at the expected location:

Many Headers

ls /usr/include/opencascade | wc
   7598   53186 1138547

Launch Main App

./gradlew cad-dsl:test
./gradlew clean (1)
  1. To replay tests, you have to clean the env.

cad builder

Figure 1. Output

Sample

Get inspiration from CAD Query, but using Groovy DSL.

Sample Code

@Test
void "Pillow Block With Counterbored Holes and Prism"() {
    cd().box(length, height, thickness).topZ().wireFrom() {
        double rectSX = length - cboreInset
        double rectSY = height - cboreInset
        [[-rectSX / 2, -rectSY / 2], [0, rectSY],
         [rectSX, 0], [0, -rectSY]].each { double cX, double cY ->
            move(cX, cY)
            circle(centerHoleDia)
        }
    }.toFace().hole(-cboreHoleDiameter).topZ().wireFrom() {
        circle(centerHoleDia)
    }.toFace().prism(cboreHoleDiameter).display()
}

Warning

DSL is evolving

screenshot sketch

Figure 2. Renderer

Packages

There are 3 main packages in cad-dsl src folder (both for tests and implementation).

  • org.taack.cad.binding classes use direct OCCT symbol binding using JExtract. It is considered low-level, and should not be used when composing a new body.

  • org.taack.cad.builder using the builder pattern, quick way to test builder limitation, this step helps to build a good DSL. This package should not be directly used.

  • org.taack.cad.dsl using the visitor pattern to build the DSL. This should be used in production.

DSL Tests

DSL Tests are localised cad-dsl/src/test/groovy/org/taack/cad/dsl it could give an overview of cad-dsl constructions.

Cut Version

@Test
void "Test mix fuse - common - cut"() {
    Vec diagonal = new Vec(1, 1, 1)
    cd().box(2, 2, 1).toCadDsl().cut {
        position(diagonal * 0.4) {
            box(1, 1, 1)
            position(diagonal * 0.3) {
                cylinder(1 / 2, 3)
            }
        }
        position(diagonal * 0.6) {
            box(1, 1, 1)
        }
    }.display()
}

cad cut

Figure 3. Image Displayed

Fuse Version

@Test
void "Test mix fuse - common - fuse"() {
    Vec diagonal = new Vec(1, 1, 1)
    cd().box(2, 2, 1).toCadDsl().fuse {
        position(diagonal * 0.4) {
            box(1, 1, 1)
            position(diagonal * 0.3) {
                cylinder(1 / 2, 3)
            }
        }
        position(diagonal * 0.6) {
            box(1, 1, 1)
        }
    }.display()
}

cad fuse

Figure 4. Fuse Results

Distribution and Usage

cad-dsl has been published on maven for Linux x86 only.

Maven

Artifact coordinates:

Maven

implementation 'org.taack.cad:cad-dsl:0.1'

You can also compile cad-dsl-native for your platform, and put the library in your lib path.

Sample App using artifact

Code completion

Your IDE has to support Groovy @DelegatesTo must be supported.

The language is statically typed. Intellij IDE Community version should do it.

Read the original on github.com ↗