TechDraw & 2D Drafting
Relevant source files
The following files were used as context for generating this wiki page:
The TechDraw module is designed to create 2D technical drawings from 3D models. It provides tools to project 3D shapes onto a 2D plane, manage drawing pages based on SVG templates, and apply various annotations such as dimensions, centerlines, and balloons. The system integrates closely with the modeling workflow, allowing for live updates of drawing pages when the underlying 3D geometry changes.
The architecture follows a container-component pattern where a DrawPage serves as the primary container for various DrawView objects. These views can represent part geometry, spreadsheets, symbols, or complex projections like section and detail views.
Core Architecture and Components
The TechDraw system is structured around several key classes that manage the application logic (App) and the graphical user interface (Gui).
Class Hierarchy
The foundational objects are defined in the App namespace and are exposed to the GUI through commands.
The diagram shows the relationship between pages, templates, and the various view types used to build a technical drawing.
Sources: src/Mod/TechDraw/App/CMakeLists.txt:41-86, src/Mod/TechDraw/Gui/Command.cpp:115-125
Drawing Pages
A DrawPage represents a single sheet of paper. It requires a DrawSVGTemplate to define borders, title blocks, and editable fields. Pages can be created using a default template or a user-selected SVG file.
Sources: src/Mod/TechDraw/Gui/Command.cpp:112-210
| Feature | Description |
|---|---|
| Default Page | Created via CmdTechDrawPageDefault, utilizing the system's default SVG template path. |
| Template Page | Created via CmdTechDrawPageTemplate, allowing users to browse for custom SVG/DXF templates. |
| Redraw | The redrawCommand() function forces a refresh of all views and geometry on a specific page. |
View Types and Projections
TechDraw supports multiple methods of projecting 3D data into 2D views. The system distinguishes between direct 3D projections and auxiliary views.
Standard Projections
The DrawViewPart class is the primary component for projecting Part geometry. It uses properties like Direction and XDirection to define the camera orientation relative to the 3D object.
Sources: src/Mod/TechDraw/Gui/Command.cpp:308-410
Specialized Views
Additional view types allow for more complex drafting requirements:
- Active View: Inserts a bitmap or vectorized image of the current 3D view window.
- Section View: Creates a cross-section of a part based on a cutting plane.
- Detail View: Magnifies a specific area of a base view, controlled by a
Detail Anchor. - Projection Group: Creates a multi-view layout (e.g., Top, Front, Side) that maintains alignment between related projections.
Sources: src/Mod/TechDraw/Gui/Command.cpp:452-590, src/Mod/TechDraw/Gui/Resources/translations/TechDraw_fil.ts:1680-1710
Logic flow for inserting a new view into a TechDraw page.
Sources: src/Mod/TechDraw/Gui/Command.cpp:308-410
Annotations and 2D Drafting Tools
Beyond geometry projection, TechDraw provides extensive tools for adding technical information to the drawing.
Dimensions
Dimensions are added to measure distances, radii, and angles. They can be linked directly to the projected 2D geometry or the underlying 3D model.
- Linear: Horizontal, Vertical, and Oblique distances.
- Curvature: Radius and Diameter dimensions for circles and arcs.
- Angular: 3-point or 2-edge angle measurements.
Sources: src/Mod/TechDraw/Gui/Resources/translations/TechDraw_fil.ts:1820-1860
Decoration and Cosmetic Elements
Cosmetic elements are 2D-only objects added to a view to aid in drafting:
- Centerlines: Added between two lines, two points, or to circular faces.
- Cosmetic Vertices: Added at intersections, midpoints, or quadrant points.
- Threading: Symbols representing internal or external screw threads.
- Hatching: Applying PAT or SVG patterns to faces.
Sources: src/Mod/TechDraw/Gui/Command.cpp:1126-1140, src/Mod/TechDraw/Gui/Resources/translations/TechDraw_fil.ts:1920-1950
File Access and Export
The module supports exporting completed pages to standard exchange formats.
Supported Formats
| Format | Description | Implementation Detail |
|---|---|---|
| SVG | Scalable Vector Graphics | Exports the page exactly as rendered in the GUI, maintaining vector data for lines and text. |
| DXF | Drawing Exchange Format | Exports the page to CAD-compatible format via TechDraw.writeDXFPage. |
| Portable Document Format | Utilizes system print drivers to generate document files. | |
| Sources: src/Mod/TechDraw/Gui/Command.cpp:1547-1640 |
Sequence of events during the DXF export process.
Sources: src/Mod/TechDraw/Gui/Command.cpp:1592-1640
Conclusion
TechDraw & 2D Drafting provides a comprehensive bridge between 3D design and traditional 2D technical documentation. By leveraging a hierarchy of pages and views, and providing specialized tools for projection and annotation, it enables the creation of industry-standard drawings that remain synchronized with the original 3D models.