Draft Workbench
Relevant source files
The following files were used as context for generating this wiki page:
The Draft Workbench provides tools for 2D drafting and the modification of 2D and 3D geometry within the Parashell environment. It focuses on precision-based geometric construction, offering a variety of creation tools (lines, arcs, polygons) and modification utilities (moving, rotating, scaling, and arraying).
Architecturally, the workbench has undergone significant refactoring to move away from large monolithic modules like Draft.py and DraftTools.py toward a distributed structure where logic is separated into specialized directories such as draftguitools, drafttaskpanels, draftfunctions, and draftutils.
Sources: src/Mod/Draft/draftguitools/README.md, src/Mod/Draft/draftutils/README.md
System Architecture and Modularization
The Draft Workbench is organized into several distinct layers to handle geometry creation, GUI interaction, and auxiliary utilities. This modular design prevents circular dependencies and improves maintainability by keeping files under 1000 lines.
Component Breakdown
- GuiCommands (
draftguitools/): Defines classes that handle graphical interactions. These classes respond to button clicks or menu actions, capturing user input in the 3D view (like point selection) and passing that data to underlying Python functions. - Task Panels (
drafttaskpanels/): Contains the logic for the UI panels that appear when a command is active. Modern tools use.uifiles created with Qt Designer, while legacy tools are still migrating away from the monolithicDraftGui.py. - Core Functions (
draftfunctions/&draftmake/): These modules contain the actual geometric logic for creating and modifying objects, independent of the graphical interface. - Utilities (
draftutils/): Provides generic, reusable functions for tasks such as translation, coordinate conversion, and message printing.
Sources: src/Mod/Draft/coding_conventions.md:21-25, src/Mod/Draft/draftguitools/README.md, src/Mod/Draft/drafttaskpanels/README.md, src/Mod/Draft/draftutils/README.md
Command Execution Flow
The following diagram illustrates how a user interaction in the GUI triggers geometric logic:
The process separates the capture of graphical data from the actual creation or modification of document objects.
Sources: src/Mod/Draft/draftguitools/README.md, src/Mod/Draft/drafttaskpanels/README.md
Implementation Standards
Draft Workbench development follows specific coding conventions derived from PEP 8 and PEP 257 to ensure code quality across its many modules.
Python Coding Conventions
| Rule Category | Requirement |
|---|---|
| Indentation | 4 spaces per level; no tabs allowed. |
| Line Length | Maximum of 80 characters (100 for some tests). |
| Naming | snake_case for modules/methods; CamelCase for classes. |
| Imports | Grouped by Standard Library, Third Party, then FreeCAD specific. |
| Refactoring | Nesting deeper than 3 levels requires refactoring. |
Sources: src/Mod/Draft/coding_conventions.md:14-60
Directory Organization (CMake)
The workbench structure is defined in CMakeLists.txt, grouping source files into logical sets for compilation and installation:
- Draft_SRCS_base: Core files like
Draft.py,InitGui.py, andWorkingPlane.py. - Draft_geoutils: Specialized geometry utilities for intersections, edges, and algebraic operations.
- Draft_objects: Definitions for Draft-specific object types (Array, BezCurve, Dimension, etc.).
- Draft_view_providers: Logic for rendering Draft objects in the 3D view.
Sources: src/Mod/Draft/CMakeLists.txt:12-140
Key Feature Modules
The workbench provides a wide array of tools categorized by their primary function.
Creation Tools
These tools, defined in Creator_tools and implemented via draftmake, generate new geometric entities.
| Tool Name | Description |
|---|---|
| Line / Wire | Creates 2-point lines or multiple-point polylines. |
| Circle / Arc | Generates circular geometry via center/radius or 3 points. |
| Polygon / Ellipse | Creates regular polygons or elliptical shapes. |
| ShapeString | Generates geometry from text strings using font files. |
| Dimension | Creates linear, radial, or angular measurements. |
Sources: src/Mod/Draft/CMakeLists.txt:142-159, src/Mod/Draft/Resources/translations/Draft.ts:2050-2200
Modification and Array Tools
These tools, defined in Modifier_tools, manipulate existing shapes or create patterns.
Draft supports complex patterning through orthogonal, polar, and circular arrays, which can be created as standard arrays or more efficient "Link arrays."
Sources: src/Mod/Draft/Resources/translations/Draft.ts:150-450, src/Mod/Draft/CMakeLists.txt:161-188
User Interface and Interaction
The UI layer relies on "Snappers" and "Trackers" to assist users during 2D drafting.
Snapping System
The snapping system allows users to lock onto specific geometric features:
- Endpoint/Midpoint: Snaps to the ends or centers of edges.
- Center: Snaps to the center of circles and arcs.
- Intersection: Snaps where two edges cross.
- Working Plane: Projects all snap points onto the current active working plane.
Sources: src/Mod/Draft/Resources/translations/Draft.ts:3100-3350
Status Bar and Widgets
The draftutils/init_draft_statusbar.py module initializes UI elements in the status bar, including:
- Draft Snap Widget: A quick-access menu for toggling snapping modes.
- Draft Scale Widget: Allows setting the scale factor for annotations and dimensions.
Sources: src/Mod/Draft/draftutils/README.md, src/Mod/Draft/Resources/translations/Draft.ts:1650-1750
Conclusion
The Draft Workbench serves as the foundational 2D drafting module in Parashell. Its architecture emphasizes a clean separation between the graphical interface (draftguitools), task management (drafttaskpanels), and geometric logic (draftmake/draftfunctions). By adhering to strict modularity and PEP 8 conventions, the workbench maintains extensibility for both manual drafting and automated scripting workflows.
Sources: src/Mod/Draft/draftguitools/README.md, src/Mod/Draft/draftutils/README.md