# OpenCAD Context Project Goal: To build an open source cross-platform Fusion 360 3D CAD clone using C++, Qt, and OpenGL. Features should be as close to Fusion 360 as possible. Don't ask for unrelated files to be added to the chat. ## Architecture ... ## Development Summary: 1 Initial Setup: We created the basic application structure with a MainWindow class. This window was set up with a top toolbar to act as a banner for tools and a central widget area as a placeholder for the 3D viewport. 2 3D Viewport Implementation: We created a ViewportWidget class (inheriting from QOpenGLWidget) to handle 3D rendering. This widget replaced the initial placeholder. To test functionality, we rendered a simple, multi-colored 3D cube in the center of the viewport. 3 Camera Controls: We implemented mouse-based camera controls in the ViewportWidget: • Zoom: Mouse scroll wheel. • Rotate: Middle mouse button drag. • Pan: Shift + Middle mouse button drag. 4 View Cube: We added a view orientation cube (like in Fusion 360) to the top-right corner of the viewport. • The first version used QPainter to draw 2D text labels ("TOP", "FRONT", etc.) over the 3D cube. • We then improved this by rendering the labels as textures directly onto the faces of the 3D view cube, so they rotate with the cube. 5 Refactoring: To improve code organization, all logic related to the view cube (drawing, texturing, and axis lines) was extracted from ViewportWidget into its own dedicated ViewCube class. 6 UI Toolbar: We implemented a tabbed toolbar in the MainWindow to mimic the Fusion 360 UI. • Created "SOLID", "SURFACE", and "TOOLS" tabs. • Added "Create Sketch" and "Extrude" QToolButtons to the "SOLID" tab, complete with custom SVG icons loaded via a Qt resource file (.qrc). 7 Code Cleanup & Bug Fixes: • Removed the initial colorful test cube from the main scene. • Fixed a build error caused by a typo (QMatrix4xá4 instead of QMatrix4x4) that was introduced during the cleanup. • Resolved a Qt6 compatibility issue by replacing a legacy Qt5 OpenGL header include with its modern equivalent. 8 Sketch Creation Workflow: • Implemented a sketch creation dialog that prompts the user to select a plane (XY, XZ, YZ). • The viewport camera automatically orients itself to be normal to the chosen plane. • Created a dedicated `SketchGrid` class to draw a 2D grid on the active sketch plane, complete with major/minor grid lines, labeled axes, and an origin point. • Fixed a bug where the XY and XZ camera orientations were incorrect. 9 Data Model and File Persistence: • Designed and implemented a feature-based dependency graph model. • Created a base `Feature` class and a concrete `SketchFeature` class. • A `Document` class was created to manage the collection of features (the feature graph). • Implemented JSON serialization for the document, allowing models to be saved to and loaded from disk. • Added "New", "Open", "Save", and "Save As" functionality to the main file menu. 10 Feature Browser UI: • Added a dockable feature browser (tree view) to the left side of the main window. • The browser displays the current document as the root node and lists all features (e.g., "Sketch") as children. • The `Document` class now uses Qt signals and slots to notify the `MainWindow` of changes, ensuring the feature browser is always synchronized with the underlying data model. 11 Floating Feature Browser: • Replaced the dockable feature browser with a floating, semi-transparent overlay inside the viewport, mimicking Fusion 360's UI. • The drawing logic was encapsulated into a dedicated `FeatureBrowser` class to improve modularity. • Position was set to the top-left corner and font size was increased for better visibility. • Fixed a linker error by adding the new `FeatureBrowser.cpp` source file to the `CMakeLists.txt` build configuration. 12 View Cube Rendering Fix: • Resolved a rendering glitch where the View Cube appeared transparent on startup by enabling the OpenGL depth test (`GL_DEPTH_TEST`) and face culling (`GL_CULL_FACE`) at the beginning of each frame's render cycle. 13 Sketch Mode UI and State Management: • Implemented a dedicated "SKETCH" UI mode. When a sketch is created, the main toolbar tabs are replaced with a single "SKETCH" tab. • Added "Line", "Rectangle", "Circle", and "Save Sketch" tool buttons to the sketch tab, complete with new SVG icons. • Fixed an issue where tool buttons only showed icons; they now display text labels below the icons for clarity. • The sketch grid is now only rendered when in sketch mode. 14 Camera Animation and View Presets: • Implemented smooth camera transitions when entering and exiting sketch mode. The camera animates to a view normal to the sketch plane and animates back to its original position when the sketch is saved. • This was achieved by converting camera parameters into Qt properties and using `QPropertyAnimation`. • Resolved a C++ build error caused by naming conflicts between camera state member variables and their accessor methods. • The default startup camera view was changed to a standard isometric angle for a better initial perspective.