Source Files
Source files are files that contain µcad source code.
Such files must either have the extension .µcad, .mcad or .ucad.
A source file can include the following types of statements which we will all discuss within this book:
| Statement | Purpose | Example |
|---|---|---|
| expression | calculate values | x * 5; |
| assignment | store values | y = x; |
| const assignment | naming constants | const Y = 1; |
| pub assignment | exporting constants | pub Y = 1; |
| function | separate calculations | fn f() { } |
| workbench | build or transform 2D sketches and 3D parts | part P() { } |
| module | modularization of complex code | mod m { } |
| if | process conditions | if x > 1 { } |
| use | use symbols from other modules | use m; |
| call | use functions and workbenches | f(); |
| comment | for documentation | // comment |
In its simplest form, a µcad program consists of a single file containing one or more of the above statements.
A source file can serve as both a module and a workbench. You can use it to provide structure (for example, by organizing submodules) or as a kind of workbench where you add statements to generate outputs—such as a 2D graphic or a 3D model.
The workbench section of the file is only evaluated if it is in the main file
(the one that microcad was called with).
The following examples illustrate this: a circle and a sphere are created, each with a radius of one centimeter.
// simply draw a circle
std::geo2d::Circle(radius = 1cm);
// simply draw a sphere
std::geo3d::Sphere(radius = 1cm);
Statements within a source file can represent either a 2D or a 3D model — but not both at the same time. Mixing 2D and 3D statements in the same file will result in an error:
std::geo2d::Circle(radius = 1cm);
std::geo3d::Sphere(radius = 1cm); // error: can't mix 2D and 3D
However, µcad programs can also be split across multiple files.
To include other files, the mod
statement is used...