How astepaniuk/cad-research works
1. Overall shape
- This is a C++/CMake desktop CAD prototype centered on 2D floor-plan editing.
- The code is split into three main product layers: core infrastructure (corecad), domain logic (domain/plan), and GUI/editor (gui).
- Tests are organized by the same boundaries, which makes the intended architecture fairly explicit.
2. Build and dependency boundaries
- The project is built with CMake and uses vcpkg for package management.
- Two bundled third-party dependencies matter architecturally:
- ImGui for the immediate-mode UI.
- freecad-planegcs for geometric/constraint solving in the sketcher-like parts of the model.
- The repository also includes a standalone GitHub Actions workflow for multi-platform CMake builds.
3. CoreCAD: shared modeling infrastructure
- src/corecad is the generic, reusable foundation beneath the plan domain.
- It contains infrastructure for:
- model objects and properties
- registries / stable indexing
- trackable registries
- history/undo-redo transactions
- generic constraints and calculators
- This layer looks intentionally domain-agnostic: it provides the mechanics for state management, referencing, and calculations without knowing about walls or floors.
4. Domain model: floor-plan concepts
- src/domain/plan/model defines the actual business objects:
- floor
- wall
- typed parameters such as distance, point_locator, and wall_border_point_locator
- The domain model is split into subfolders for shape and parameter, which suggests the design separates geometric entities from their editable/derived inputs.
5. Domain generation and resolution
- src/domain/plan/generator/default_floor_generator creates initial floor content.
- src/domain/plan/resolver/point_resolver and the parameter locators suggest a two-step approach:
- resolve abstract/editable parameters into concrete geometric points
- then use those points to drive shape updates
- This is the bridge between user intent and actual geometry.
6. Domain calculation
- src/domain/plan/calculator/wall_calculator is the central computation unit for wall geometry.
- The tests show it calculates wall borders for:
- a single wall
- added walls
- two walls
- multiple joined walls
- That implies the calculation layer is responsible for updating wall extents and intersections when topology changes, not just storing coordinates.
7. GUI application boundary
- src/gui/main.cpp is the application entry point.
- main_window is the top-level UI shell, with a workspace and main_menu around the active editor/document area.
- The GUI is organized around a central document/view/editor structure rather than a generic widget tree.
8. Document and view layer
- src/gui/doc/document.h appears to hold the editable document state for the UI.
- wall_snaps sits in the document layer, hinting that snapping aids are part of document state or derived document services.
- src/gui/view contains rendering-oriented views:
- floor_view
- walls_view
- constraints_view
- parameters_view
- coord_translator indicates a clear separation between screen coordinates and model coordinates.
9. Editor interaction pipeline
- src/gui/editor is the interaction engine for manipulating the model.
- The structure is stateful:
- operation classes represent active tools or modes such as add-wall, idle, and move-wall-handle.
- handler classes encapsulate specialized behaviors like wall joins and T-joins.
- mouse centralizes pointer state.
- This suggests a tool-driven editor architecture where input events are interpreted by the active operation, which then mutates the document/model.
10. Snapping and editing assistance
- src/gui/editor/snap contains snap construction and processing:
- vh_snap_builder
- snap_processor
- i_snap_builder
- These components likely compute candidate alignments or target points before the editor commits a move or placement.
- Snapping sits between raw mouse input and model mutation, acting as an editor-side geometric assistance layer.
11. Calculation pipeline in the GUI
- src/gui/editor/calc_pipeline suggests the GUI has its own orchestration layer around calculations, probably to sequence resolver/calculator passes while editing.
- This is important architecturally because it means geometry updates are not direct UI writes; they likely flow through a staged pipeline that keeps the view/editor responsive and model-consistent.
12. Data flow through the system
- The main flow is:
- user input in the GUI
- active editor operation/handler interprets the input
- snap processing and point resolution refine the edit intent
- domain model changes are applied
- calculators recompute wall/floor geometry and constraints
- views render the updated document
- Undo/redo and transaction history in corecad/model/history wrap this flow so edits are reversible.
13. Testing boundaries mirror the architecture
- corecad_tests focus on history/transaction behavior.
- domain_tests focus on wall calculation correctness.
- common_test_util provides assertion helpers shared across test groups.
- This separation reinforces that the repo’s primary design concerns are model consistency and geometric recalculation, not just UI behavior.
14. Likely diagram boundaries
- A clean architecture diagram should show:
- GUI/editor at the top
- Domain plan model + calculators in the middle
- CoreCAD infrastructure + history/constraints underneath as reusable services
- Third-party geometry/solver libraries as external dependencies feeding the calculation layer
- The most important cross-boundary interactions are editor-to-domain updates, domain-to-calculator recomputation, and history wrapping of state changes.
Main entry points: floor.h Floor · wall_calculator.h Wall calculator · main_window.h Main window · floor_editor.h Editor
Components 22
Build & deps
CMake-based build, package management, and bundled third-party libraries.
- CMake build · Project-wide build orchestration and multi-platform CI configuration.
CMakeLists.txt - vcpkg · Dependency management via manifest-based packages.
vcpkg.json - ImGui · Immediate-mode UI dependency used by the desktop application.
3rd-party/imgui/CMakeLists.txt - PlaneGCS · Geometric constraint-solving dependency for sketch-like plan editing.
3rd-party/freecad-planegcs/CMakeLists.txt
CoreCAD
Reusable modeling infrastructure shared by the plan domain and editor.
- Model base · Shared object, property, collection, registry, and indexing primitives.
src/corecad/model/model_base.h - History · Transaction and model-history support for reversible edits.
src/corecad/model/history/model_history.h - Registries · Stable registries and trackable pools for model references.
src/corecad/model/registry.h - Constraints · Generic constraint types and constraint-taking views.
src/corecad/model/constraint/constraint.h - Constraint calc · Shared calculator utilities for constraint solving and evaluation.
src/corecad/calculator/constraints_calculator.h
Plan domain
Floor-plan model, generation, resolution, and geometry calculation.
- Floor · Top-level editable floor-plan aggregate.
src/domain/plan/model/floor.h - Wall · Primary geometric wall shape in the floor model.
src/domain/plan/model/shape/wall.h - Parameters · Distance and locator parameters used to drive geometry.
src/domain/plan/model/parameter/parameter.h - Default generator · Creates initial floor content and starting geometry.
src/domain/plan/generator/default_floor_generator.h - Point resolver · Resolves abstract locators into concrete points for geometry updates.
src/domain/plan/resolver/point_resolver.h - Wall calculator · Computes wall borders, joins, and intersection-aware wall updates.
src/domain/plan/calculator/wall_calculator.h
GUI/editor
Application shell, document/view layer, and interactive editing pipeline.
- App entry · Program entry point for the CAD prototype.
src/gui/main.cpp - Main window · Top-level application shell containing workspace and menu.
src/gui/main_window/main_window.h - Document · Editable document state and document-level services such as snaps.
src/gui/doc/document.h - Views · Floor, walls, constraints, and parameters views with coordinate translation.
src/gui/view/floor_view.h - Editor · Stateful tool system that interprets input and mutates the model.
src/gui/editor/floor_editor.h - Snapping · Snap builders and processing between mouse input and edits.
src/gui/editor/snap/snap_processor.h - Calc pipeline · Sequenced edit-time calculation pipeline coordinating resolver and calculator passes.
src/gui/editor/calc_pipeline/calc_tools.h
Connections 27
- CMake build → vcpkg: uses · Builds and resolves dependencies through the vcpkg manifest.
- CMake build → ImGui: builds with · The application links against the bundled UI library.
- CMake build → PlaneGCS: builds with · The plan domain links against the bundled geometry solver.
- App entry → Main window: starts · Application entry constructs the top-level shell.
- Main window → Document: hosts · The shell presents the active document and editor context.
- Main window → Views: renders · Workspace and menu coordinate the primary views.
- Main window → Editor: drives · The shell embeds the active floor editor workflow.
- Document → Snapping: contains · Snap state and services live at the document boundary.
- Editor → Snapping: uses · Editing operations consume snapping assistance.
- Editor → Calc pipeline: triggers · Edits flow through an edit-time calculation pipeline.
- Editor → Floor: mutates · Operations update the floor-plan model.
- Snapping → Point resolver: refines to · Snaps help resolve intent into concrete model points.
- Calc pipeline → Point resolver: runs · Pipeline executes point resolution before geometry updates.
- Calc pipeline → Wall calculator: runs · Pipeline sequences wall geometry recalculation.
- Floor → Wall: contains · Floor aggregates wall geometry.
- Floor → Parameters: uses · Floor state is driven by editable parameters.
- Default generator → Floor: creates · Initial content generator seeds a new floor.
- Point resolver → Parameters: resolves · Locator parameters are turned into concrete coordinates.
- Wall calculator → Wall: updates · Calculator recomputes wall borders and joins.
- Wall calculator → Constraint calc: relies on · Domain calculation builds on shared calculator machinery.
- Wall calculator → PlaneGCS: solves with · Geometry constraints are delegated to the external solver.
- Floor → Model base: built on · Domain entities use the shared model base and property system.
- Floor → History: versioned by · Edits are wrapped in undo/redo transactions.
- Floor → Registries: indexed by · Stable registries back model references and lookup.
- Parameters → Constraints: describes · Editable parameters are expressed through generic constraints.
- Views → Model base: reads · Views render shared model state.
- Views → Document: observes · Renderers consume the current document state.