Skip to content

UniverLab/cadforge

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

40 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆ β–ˆβ–ˆ β–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–‘β–‘β–ˆβ–ˆβ–ˆ β–‘β–‘β–ˆβ–ˆβ–ˆβ–‘β–‘β–ˆβ–ˆβ–ˆβ–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆβ–ˆ β–‘β–‘β–ˆβ–ˆβ–ˆβ–‘β–‘β–ˆβ–ˆβ–ˆβ–‘β–ˆβ–ˆβ–ˆ β–‘β–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–‘β–ˆβ–ˆβ–ˆβ–‘β–‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆβ–ˆβ–‘ β–‘β–ˆβ–ˆβ–ˆ β–‘β–‘β–‘ β–‘β–ˆβ–ˆβ–ˆ β–‘β–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–‘β–ˆβ–ˆβ–ˆ β–‘β–‘β–‘ β–‘β–ˆβ–ˆβ–ˆ β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–‘β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–‘β–ˆβ–ˆβ–ˆ β–‘β–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆ β–‘β–ˆβ–ˆβ–ˆ β–‘β–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–‘β–‘β–ˆβ–ˆβ–ˆ β–‘β–ˆβ–ˆβ–ˆ β–‘β–ˆβ–ˆβ–ˆ β–‘β–ˆβ–ˆβ–ˆβ–‘β–‘β–‘ β–‘β–ˆβ–ˆβ–ˆβ–‘β–‘β–ˆ β–‘β–ˆβ–ˆβ–ˆ β–‘β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–‘β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–‘β–ˆβ–ˆβ–ˆ β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–‘β–‘β–‘β–‘β–‘β–‘ β–‘β–‘β–‘β–‘β–‘β–‘β–‘ β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘ β–‘β–‘β–‘ β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘ β–‘β–‘β–‘β–‘β–‘β–‘ β–‘β–‘β–‘β–‘β–‘β–‘β–‘

CI Crates.io Status License

cadforge is an Architecture as Code CLI tool and Rust library for declarative 2D CAD modeling. Write geometry as code in .cf TOML format, compile to DXF, and generate PNG previews for AI agents.


Features

🎯 Core Platform

  • πŸ“ Declarative Geometry β€” Define architectural elements (lines, rects, circles, arcs, polylines, text, dimensions) in TOML .cf files. Deterministic, reproducible, version-controlled.
  • πŸ”— Layer System β€” Organize geometry by layer with custom names, colors, and line weights. Compile single layers or full projects.
  • πŸ“„ DXF Export β€” Compile .cf β†’ DXF (AutoCAD-compatible). Full layer support, LWPOLYLINE for polylines, HATCH for solid fills, MTEXT for annotations.
  • πŸ–ΌοΈ PNG Preview β€” Generate raster previews with metadata JSON for AI agent integration. Renders fills, hatches, strokes, and text with boundary resolution. Configurable resolution and layer filtering.
  • βœ… Validation Engine β€” cadforge check validates geometry without generating output. Shows project metadata, layer colors, and entity counts.

πŸ—οΈ Project Management

  • Project Scaffolding β€” cadforge new creates a complete multi-layer project (muros, puertas, mobiliario, cotas) with meaningful architectural examples.
  • Multi-Layer Compilation β€” Compile all layers or target specific layers with --layer. Custom output path with --output.
  • Auto-Rebuild β€” cadforge watch monitors .cf and .toml files and auto-rebuilds on changes with 300ms debounce.
  • Code Formatting β€” cadforge fmt normalizes .cf files. --check mode for CI validation.
  • Boundary Resolution β€” Automatic detection of closed boundaries for hatch generation. Shared boundary resolution across overlapping entities.
  • Polyline Support β€” Full LWPOLYLINE support with bulge factors for arcs. Proper vertex handling and closure detection.

πŸ”§ Architecture

  • Compiler Pipeline β€” Parse β†’ Resolve β†’ Compile β†’ Emit. Modular design for easy extension.
  • DXF Writer β€” Direct DXF entity writing with proper AutoCAD compatibility. Layer/color/lineweight mapping.
  • Preview Renderer β€” Tiny-skia based raster rendering with anti-aliasing. PNG + JSON metadata output.
  • Error Reporting β€” Structured errors with file, line, and context. Fast-fail on validation errors.

Commands

Command Description
cadforge new <name> Create a new project with multi-layer scaffold
cadforge init Initialize CADforge in current directory
cadforge build Compile project to DXF
cadforge build --check Validate project and constraints without generating DXF
cadforge build --output <path> Compile to custom output path
cadforge build --layer <name> Compile specific layer only
cadforge check Validate with project metadata and layer colors
cadforge layers List layers with entity counts and colors
cadforge preview Generate PNG preview + metadata JSON
cadforge preview --width 1024 --height 768 Custom resolution preview
cadforge preview --layer <name> Preview specific layer only
cadforge fmt Format .cf files (normalize whitespace)
cadforge fmt --check Check formatting without modifying (CI)
cadforge watch Auto-rebuild on file changes
cadforge import <file.dxf> Import DXF into .cf layers + project.toml
cadforge import <file.dxf> --layer <name> Import only one DXF layer
cadforge view Open the project in the configured viewer
cadforge view --layer <name> Open only one layer in the viewer
cadforge config set <key> <value> Set global defaults (author, units)
cadforge config show Show global defaults

Viewer controls (MVP)

  • HUD flotante en pantalla con proyecto, vista, distancia, capas, selecciΓ³n y ayuda de atajos
  • T / F / V / R β†’ top / front / right / isometric preset views
  • Q / E / W / S β†’ orbit camera
  • Mouse left-drag β†’ orbit
  • Mouse right-drag / arrows β†’ pan
  • Mouse wheel / + / - β†’ zoom
  • 1..9 β†’ toggle layer visibility
  • Click entity edge β†’ select primitive id
  • Selected entity is highlighted in amber in the viewport HUD context
  • C β†’ copy selected id to clipboard

.cf Format

[layer]
name = "muros"
color = "#FFFFFF"

[[line]]
id = "ln-001"
from = [0.0, 0.0]
to = [8.5, 0.0]
weight = 0.50

[[rect]]
id = "rc-001"
origin = [1.0, 1.0]
width = 3.5
height = 4.0

[[circle]]
id = "ci-001"
center = [4.0, 3.0]
radius = 0.5

[[arc]]
id = "ac-001"
center = [2.0, 2.0]
radius = 0.9
from_angle = 0.0
to_angle = 90.0

[[polyline]]
id = "pl-001"
vertices = [[0, 0], [5, 0], [5, 3], [0, 3]]
closed = true

[[text]]
id = "tx-001"
position = [4.0, 3.0]
content = "SALA"
size = 0.2

[[dim]]
id = "dm-001"
from = [0, 0]
to = [5, 0]
offset = 0.5

Supported Primitives

line, polyline, rect, circle, arc, text, point, dim, hatch, solid


Architecture Overview

.cf file (TOML)
    β”‚
    β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Parser  │───▢│ Resolver  │───▢│Compiler │───▢│ DXF Emitβ”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                     β”‚
                     β–Ό
              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
              β”‚ Boundary │───▢│ Preview PNG β”‚
              β”‚ Resolver β”‚    β”‚ + JSON meta β”‚
              β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
  • Parser β€” TOML parsing with custom array-of-tables detection, primitive validation
  • Resolver β€” Layer dependency resolution, coordinate validation, boundary detection
  • Compiler β€” Entity compilation to DXF format, hatch generation, polyline closure
  • DXF Writer β€” Direct DXF entity emission with proper layer/color/lineweight mapping
  • Preview Renderer β€” Tiny-skia raster rendering with hatch/fill support

Main Modules

  • compiler/ β€” Project compilation pipeline, layer targeting, validation, build stats
  • dxf_writer/ β€” DXF entity writing, LWPOLYLINE, HATCH, MTEXT generation
  • preview/ β€” PNG rendering with configurable resolution, layer filtering, metadata JSON
  • parser/ β€” TOML parsing, primitive extraction, array-of-tables handling
  • model/ β€” Data structures: Layer, Primitive, Project
  • scaffold/ β€” Multi-layer project creation with architectural examples
  • fmt/ β€” .cf file formatting and normalization
  • watch/ β€” File system watcher with auto-rebuild and debounce
  • color/ β€” Color parsing and DXF color mapping

Data Storage

Data Location Format
Project files ./ TOML (.cf + project.toml)
Build output output/ DXF
Preview output output/preview.png PNG
Preview metadata output/preview.json JSON
Build cache target/ Cargo build

Usage

Create a new project:

cadforge new mi-proyecto
cd mi-proyecto

Edit .cf files (TOML format with your geometry)

Format and validate:

cadforge fmt           # normalize .cf files
cadforge check         # validate without generating DXF

Compile to DXF:

cadforge build                        # default output.dxf
cadforge build --output plano.dxf     # custom output path
cadforge build --layer muros          # compile single layer

Preview:

cadforge preview                          # default 2048x1536
cadforge preview --width 1024 --height 768  # custom resolution
cadforge preview --layer muros            # single layer preview

Auto-rebuild on changes:

cadforge watch       # monitors .cf and .toml files

Tech Stack

| Rust 2021 | clap | toml | toml_edit | tiny-skia | dxf | notify | anyhow | serde |


License

MIT β€” see LICENSE for details.


Made with ❀️ by JheisonMB and UniverLab

About

No description or website provided.

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Packages

 
 
 

Contributors