diff --git a/CLAUDE.md b/CLAUDE.md index b0685f1e6..cc10ce958 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -1,2 +1,2 @@ -- Technical research about the codebase can be found in @research/index.md. +- Technical research about the codebase can be found in the `research` directory. See @research/index.md. - Use `nix-shell` to grab temporary tools as needed. diff --git a/research/design-only-fork.md b/research/design-only-fork.md new file mode 100644 index 000000000..b965a1b12 --- /dev/null +++ b/research/design-only-fork.md @@ -0,0 +1,302 @@ +# Plan: Create Design-Only MatterControl Fork + +**Goal:** Strip MatterControl down to a pure 3D design/modeling application, removing all printing, slicing, and cloud features. + +## Feasibility Summary + +| Feature Category | Removal Difficulty | Effort Estimate | +|------------------|-------------------|-----------------| +| **Cloud Features** | Easy | Low - 1-2 days | +| **Printing/Communication** | Moderate | Medium - 1-2 weeks | +| **Slicing (MatterSlice)** | Very Difficult | High - 3-4 weeks | + +The codebase has **good architectural separation** for design vs printing, but slicing is deeply embedded. A "design-only" variant is feasible with moderate effort. + +--- + +## Detailed Analysis + +### 1. Cloud Features - EASY TO REMOVE + +Cloud features use a **nullable delegate pattern** - already designed to be optional: + +```csharp +// All cloud delegates are nullable (ApplicationController.cs) +public static Func> GetPrinterProfileAsync; +public static Func, Task> SyncCloudProfiles; +public static Func GuestUserActive; +public static Func GetAuthPage; +public static Func UserHasPro; +``` + +**To remove:** Simply don't register these delegates. Code already has null checks everywhere. + +**Files to modify:** ~5-10 files to remove registration points + +--- + +### 2. Printing/Communication - MODERATE EFFORT + +**Good separation exists:** +- `DesignTabPage` (design-only) vs `PrinterTabPage` (printing) +- `PartWorkspace` supports `Printer == null` for design workspaces +- Design tools have ZERO printing dependencies + +**Challenges:** +- `PrinterConfig` constructor always creates `PrinterConnection` +- 465+ printer-related null checks throughout codebase +- Print queue, temperature monitoring tightly coupled + +**Approach:** +1. Remove `PrinterTabPage`, `PrinterActionsBar`, `SliceLayerSelector` +2. Remove `PrinterCommunication/` directory +3. Remove `MatterControl.Printing/` project +4. Modify `PrinterConfig` to be optional or remove entirely +5. Keep only `DesignTabPage` workspaces + +**Files affected:** ~50-80 files + +--- + +### 3. Slicing (MatterSlice) - VERY DIFFICULT + +**Deep integration:** +- **248 files** reference slicing functionality +- **150+ settings** mapped in `EngineMappingsMatterSlice` +- `PrinterSettings.SliceEngines` assumed non-empty (crashes if empty) +- Settings validation checks `printer.Settings.Slicer.PrinterType` + +**Critical coupling points:** +- Multi-extruder logic depends on slicer +- Support/raft/brim features depend on slicer +- G-code generation requires active slicer +- 30+ UI field types assume slicer presence + +**If slicing removed, you also lose:** +- All print settings UI (no point without slicing) +- G-code preview/visualization +- Layer-by-layer analysis +- Print time estimation + +--- + +## Architecture Overview + +``` +┌─────────────────────────────────────────────────┐ +│ KEEP: Core Design Features │ +├──────────────────────────────────────────────────┤ +│ DesignTools/ - Primitives, booleans │ +│ View3DWidget - 3D viewport │ +│ Library/ - Content management │ +│ DataStorage/ - SQLite persistence │ +│ SettingsManagement/ - Basic settings │ +│ agg-sharp/ - Rendering, UI, math │ +└──────────────────────────────────────────────────┘ + +┌─────────────────────────────────────────────────┐ +│ REMOVE: Printing-Specific │ +├──────────────────────────────────────────────────┤ +│ PrinterCommunication/ - Serial I/O, drivers │ +│ MatterControl.Printing/- G-code streams │ +│ Queue/ - Print queue │ +│ PrinterControls/ - Printer UI │ +│ SlicerConfiguration/ - Slicer settings (150+) │ +│ MatterSlice/ - Slicer engine │ +│ PrinterTabPage - Printer workspace UI │ +└──────────────────────────────────────────────────┘ +``` + +--- + +## Recommended Approach + +### Option A: Design-Only Fork (Recommended) + +Create a stripped-down version keeping only design features: + +1. **Remove projects:** + - `Submodules/MatterSlice/` + - `MatterControl.Printing/` + +2. **Remove directories:** + - `MatterControlLib/PrinterCommunication/` + - `MatterControlLib/Queue/` + - `MatterControlLib/SlicerConfiguration/` + - `MatterControlLib/PrinterControls/` + - `MatterControlLib/ConfigurationPage/PrintLeveling/` + - `MatterControlLib/SetupWizard/` + +3. **Modify:** + - Remove `PrinterTabPage` from `PartPreviewWindow/` + - Remove printer workspace creation from `ApplicationController` + - Remove printer-related settings from `SettingsManagement/` + - Update `MainViewWidget` to only create design tabs + +4. **Keep intact:** + - `DesignTools/` - All parametric design + - `Library/` - Content management + - `View3DWidget` - 3D viewport + - `DataStorage/` - Persistence + - All `agg-sharp/` modules + +**Estimated effort:** 2-3 weeks for clean separation + +### Option B: Feature Flags (Alternative) + +Add compile-time flags to conditionally include printing: + +```csharp +#if PRINTING_ENABLED + // Printer-specific code +#endif +``` + +**Pros:** Maintains single codebase +**Cons:** More complex maintenance, larger binary + +--- + +## What You'd Lose + +Removing printing/slicing means losing: +- Printer connection and control +- G-code generation and preview +- Layer-by-layer visualization +- Print time/material estimation +- Temperature monitoring +- Print queue management +- Printer setup wizard +- 150+ slicer settings + +## What You'd Keep + +Design-only mode retains: +- Full 3D viewport with camera controls +- All parametric primitives (cube, sphere, cylinder, text, etc.) +- Boolean operations (union, subtract, intersect) +- Mesh operations (repair, decimate, hollow, twist, etc.) +- Transform tools (scale, rotate, mirror, array) +- File I/O (STL, OBJ, AMF, 3MF, MCX) +- Library browsing and management +- Undo/redo system +- Theme system +- Tabbed workspaces (design-only) + +--- + +--- + +## Implementation Plan + +### Phase 1: Remove Submodules & Projects (Day 1) + +**Remove from solution:** +``` +Submodules/MatterSlice/ # Slicing engine +MatterControl.Printing/ # G-code processing +``` + +**Update .gitmodules** to remove MatterSlice reference. + +### Phase 2: Remove Printing Directories (Days 1-2) + +**Delete directories:** +``` +MatterControlLib/PrinterCommunication/ # Serial I/O, drivers +MatterControlLib/Queue/ # Print queue +MatterControlLib/SlicerConfiguration/ # 150+ slicer settings +MatterControlLib/PrinterControls/ # Printer UI widgets +MatterControlLib/ConfigurationPage/PrintLeveling/ +MatterControlLib/SetupWizard/ # Printer setup wizard +MatterControlLib/EeProm/ # Printer EEPROM +``` + +### Phase 3: Modify Core Files (Days 2-5) + +**Key files to modify:** + +1. **ApplicationController.cs** + - Remove cloud delegate registrations + - Remove `PrinterConfig` creation logic + - Remove printer workspace support + - Keep design workspace support only + +2. **MainViewWidget.cs** + - Remove `CreatePrinterTab()` calls + - Keep only `CreateDesignTab()` + - Remove printer-related status bar items + +3. **PartPreviewWindow/PrinterTabPage.cs** + - DELETE entire file (or keep as reference) + +4. **PartPreviewWindow/DesignTabPage.cs** + - Remove any printing-related conditionals + - This becomes the only tab type + +5. **ApplicationView/PrinterConfig.cs** + - DELETE or heavily refactor + - Remove `PrinterConnection` instantiation + +6. **SettingsManagement/** + - Remove slicer-related settings + - Keep only design/application settings + +### Phase 4: Fix Compilation Errors (Days 5-10) + +Expect ~200-300 compilation errors from removed dependencies. Systematically: +1. Remove `using` statements for deleted namespaces +2. Remove printer-related null checks +3. Remove printer-specific UI conditionals +4. Stub or remove features that depended on printing + +### Phase 5: Clean Up & Test (Days 10-14) + +1. Remove dead code and unused references +2. Update project files (.csproj) +3. Test all design features: + - 3D viewport and camera + - All primitives (cube, sphere, cylinder, text, etc.) + - Boolean operations + - Mesh operations (repair, decimate, etc.) + - File I/O (STL, OBJ, AMF, 3MF) + - Library browsing + - Undo/redo +4. Remove printing-related localization strings + +--- + +## Verification Steps + +After implementation, verify: + +1. **Build succeeds** without MatterSlice or Printing references +2. **App launches** without printer setup wizard +3. **Design tab works:** + - Create new design workspace + - Add primitives to scene + - Apply boolean operations + - Save/load files (STL, OBJ, etc.) +4. **Library works:** + - Browse files + - Drag-and-drop import +5. **No printer references** in UI menus or settings + +--- + +## Risk Assessment + +| Risk | Mitigation | +|------|------------| +| Hidden printing dependencies | Incremental removal with frequent builds | +| Broken design features | Comprehensive testing after each phase | +| Missing shared code | Keep agg-sharp, VectorMath, PolygonMesh intact | +| Settings system breakage | Carefully separate design vs printer settings | + +--- + +## Conclusion + +**Feasibility: YES - Estimated 2-3 weeks** + +The architecture supports this well. The main effort is removing ~6 directories and fixing ~200-300 compilation errors from broken references. Design features (DesignTools, View3DWidget, Library) have clean separation and should work unchanged. diff --git a/research/index.md b/research/index.md index 028ff27db..5a86bca90 100644 --- a/research/index.md +++ b/research/index.md @@ -44,6 +44,13 @@ MatterControl is a comprehensive 3D printing workflow application built by Matte |-----------|----------|-------------| | agg-sharp | [agg-sharp.md](agg-sharp.md) | Graphics library: 2D rendering, GUI widgets, 3D mesh, VectorMath, OpenGL, Typography | +## Planning + +| Document | Description | +| -------- | ----------- | +| [Design-Only Fork](design-only-fork.md) | Plan to strip MatterControl down to a pure 3D design/modeling application, removing all printing, slicing, and cloud features. | +| [Linux Migration](linux-migration.md) | Feasibility of migrating the project from its many Windows-only dependencies to cross platform alternatives to fully support Linux. | + ## Key Entry Points | File | Purpose | diff --git a/research/linux-migration.md b/research/linux-migration.md new file mode 100644 index 000000000..66e35426d --- /dev/null +++ b/research/linux-migration.md @@ -0,0 +1,189 @@ +# MatterControl Linux Migration Notes + +## Current State + +The project is a C# .NET 6.0 desktop application for 3D printing control. It currently targets Windows but has cross-platform foundations. + +## Build Errors on Linux + +``` +error NETSDK1100: To build a project targeting Windows on this operating system, set the EnableWindowsTargeting property to true. +``` + +Affected projects: +- `MatterControl.Winforms/MatterControl.Winforms.csproj` +- `Submodules/agg-sharp/PlatformWin32/PlatformWin32.csproj` +- `Submodules/agg-sharp/Tests/TestInvoker/TestInvoker.csproj` + +## Architecture Overview + +### Platform Abstraction Layer + +The project uses a provider pattern for platform-specific functionality: + +1. **Window Providers** (in `Program.cs:167-172`): + - `MatterHackers.GlfwProvider.GlfwWindowProvider` - Cross-platform (GLFW) + - `MatterHackers.MatterControl.WinformsSingleWindowProvider` - Windows-only (WinForms) + +2. **Platform Features** (`Program.cs:276`): + - `MatterHackers.MatterControl.WindowsPlatformsFeatures` - Windows implementation + +### Key Projects + +| Project | Target | Notes | +|---------|--------|-------| +| `MatterControl.csproj` | `net6.0-windows` | Main entry point, needs `net6.0` | +| `MatterControlLib.csproj` | `net6.0-windows` | Core library, needs `net6.0` | +| `MatterControl.Winforms.csproj` | `net6.0-windows` | WinForms provider, Windows-only | +| `GlfwProvider.csproj` | `net6.0` | Already cross-platform! | +| `PlatformWin32.csproj` | `net6.0-windows` | Windows-only | + +### GLFW Provider (Cross-Platform) + +Located at `Submodules/agg-sharp/Glfw/GlfwProvider.csproj` - already targets `net6.0` and provides cross-platform windowing via GLFW library. + +## Windows-Specific Code in Program.cs + +```csharp +// P/Invoke - Windows only +[DllImport("kernel32.dll")] +static extern EXECUTION_STATE SetThreadExecutionState(EXECUTION_STATE esFlags); + +[DllImport("Shcore.dll")] +static extern int SetProcessDpiAwareness(int PROCESS_DPI_AWARENESS); +``` + +These are used for: +- Preventing system sleep during prints (`KeepAwake`) +- High-DPI display support + +## Windows-Specific Code in WindowsPlatformsFeatures.cs + +- `System.Media.SoundPlayer` - Windows-only audio +- `WindowsFormsClipboard` - WinForms clipboard +- `WinformsEventSink.AllowInspector` - Debug inspector +- `InspectForm` - WinForms debug form + +## Migration Strategy + +### Phase 1: Project File Changes + +1. Change target frameworks from `net6.0-windows` to `net6.0`: + - `MatterControl.csproj` + - `MatterControlLib.csproj` + +2. Use conditional project references: + ```xml + + ``` + +3. Remove or conditionally exclude: + - `PrinterDriverInstaller` (Windows driver installer) + - `MatterControl.Winforms` reference on Linux + +### Phase 2: Code Changes + +1. **Program.cs** - Add platform detection: + ```csharp + if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + { + AggContext.Config.ProviderTypes.SystemWindowProvider = + "MatterHackers.GlfwProvider.GlfwWindowProvider, MatterHackers.GlfwProvider"; + // Use Linux platform features + } + ``` + +2. **Create LinuxPlatformFeatures.cs**: + - Implement `INativePlatformFeatures` for Linux + - Handle clipboard via X11/Wayland or cross-platform library + - Stub out Windows-specific features (sound, camera) + +3. **Conditional P/Invoke**: + ```csharp + static void KeepAwake(bool keepAwake) + { + if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + return; + // Windows implementation + } + ``` + +### Phase 3: Dependencies + +1. **GLFW native library**: Need `libglfw.so` on Linux + ```bash + # Debian/Ubuntu + sudo apt-get install libglfw3 + + # Or via Nix + pkgs.glfw + ``` + +2. **OpenGL**: Need OpenGL drivers + ```bash + sudo apt-get install libgl1-mesa-dev + ``` + +3. **Serial ports**: Already have `System.IO.Ports` package (cross-platform) + +### Phase 4: shell.nix Updates + +```nix +{ + pkgs ? import { }, +}: + +pkgs.mkShell { + packages = with pkgs; [ + dotnet-sdk_8 + glfw + libGL + xorg.libX11 + xorg.libXcursor + xorg.libXrandr + xorg.libXinerama + xorg.libXi + ]; + + LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath [ + pkgs.glfw + pkgs.libGL + ]; +} +``` + +## Files to Create + +1. `MatterControl.Linux/LinuxPlatformFeatures.cs` - Linux platform implementation +2. `MatterControl.Linux/MatterControl.Linux.csproj` - Linux-specific project (optional) + +## Files to Modify + +1. `MatterControl.csproj` - Change TFM, conditional references +2. `MatterControlLib/MatterControlLib.csproj` - Change TFM +3. `Program.cs` - Platform detection, conditional code +4. `shell.nix` - Add native dependencies + +## Alternative: Minimal Changes Approach + +Instead of full platform abstraction, use `#if` directives: + +```csharp +#if WINDOWS + // Windows-specific code +#else + // Linux/cross-platform code +#endif +``` + +And build with: +```bash +dotnet build -p:DefineConstants=LINUX +``` + +## Open Questions + +1. Should the GLFW provider be the default for all platforms? +2. What Linux-specific features need implementation (file dialogs, etc.)? +3. Is the old `PlatformGtk` worth updating or should we focus on GLFW? +4. Should we create a separate solution file for Linux builds?