Local filesystem origin implementation #10

Closed
opened 2026-02-05 18:26:29 +00:00 by forbes · 0 comments
Owner

Overview

Implement the FileOrigin interface for local filesystem operations. This wraps the existing FreeCAD file operations into the new origin abstraction, ensuring backwards compatibility while enabling the unified origin system.

Parent Issue

Epic: #8 Unified File Origin System

Goals

  1. Create LocalFileOrigin class implementing FileOrigin interface
  2. Wrap existing FreeCAD file dialog and document operations
  3. Ensure 100% backwards compatibility with current behavior
  4. Register as the default/fallback origin

Detailed Design

LocalFileOrigin Class

// src/Gui/LocalFileOrigin.h

class LocalFileOrigin : public FileOrigin {
    Q_OBJECT
public:
    LocalFileOrigin();
    
    // Identity
    QString id() const override { return QStringLiteral("local"); }
    QString name() const override { return tr("Local Files"); }
    QString nickname() const override { return tr("Local"); }
    QIcon icon() const override;  // folder icon
    OriginType type() const override { return OriginType::Local; }
    
    // Capabilities - local FS has none of the extended features
    bool supportsRevisions() const override { return false; }
    bool supportsBOM() const override { return false; }
    bool supportsPartNumbers() const override { return false; }
    bool requiresAuthentication() const override { return false; }
    
    // Always connected
    ConnectionState connectionState() const override { 
        return ConnectionState::Connected; 
    }
    
    // Core operations - wrap existing FreeCAD behavior
    void newDocument() override;
    void openDocument() override;
    void saveDocument(App::Document* doc) override;
    void saveDocumentAs(App::Document* doc) override;
    void importFile(App::Document* doc) override;
    void exportSelection(App::Document* doc) override;
    
    // Document ownership - checks if doc has a local file path
    bool ownsDocument(App::Document* doc) const override;
    
    // No suffix for local files (or could show path)
    QString documentDisplaySuffix(App::Document* doc) const override;
};

Implementation Notes

The implementation should delegate to existing FreeCAD code:

void LocalFileOrigin::newDocument() {
    // Equivalent to Std_New::activated()
    App::GetApplication().newDocument();
}

void LocalFileOrigin::openDocument() {
    // Equivalent to Std_Open::activated()
    // Use existing file dialog from Application::open()
    Gui::getMainWindow()->open();
}

void LocalFileOrigin::saveDocument(App::Document* doc) {
    // Equivalent to Std_Save::activated()
    if (doc->isSaved()) {
        doc->save();
    } else {
        saveDocumentAs(doc);
    }
}

Icon

Use the existing folder icon from kindred-icons for the local origin.

Implementation Tasks

  • Create LocalFileOrigin class
  • Implement all core file operations
  • Implement ownsDocument() logic (check for local file path)
  • Register with OriginManager at startup
  • Add unit tests
  • Ensure existing file dialogs work unchanged

Files to Create/Modify

  • src/Gui/LocalFileOrigin.h (new)
  • src/Gui/LocalFileOrigin.cpp (new)
  • src/Gui/Application.cpp (register LocalFileOrigin)
  • src/Gui/CMakeLists.txt

Acceptance Criteria

  • LocalFileOrigin implements full FileOrigin interface
  • New/Open/Save/SaveAs work identically to current behavior
  • Import/Export work correctly
  • Origin is registered and available in OriginManager
  • ownsDocument() correctly identifies local documents
  • No regressions in existing file operation behavior

Dependencies

  • #9 Origin abstraction layer

Blocking

  • #12 Modify Std_* commands
## Overview Implement the `FileOrigin` interface for local filesystem operations. This wraps the existing FreeCAD file operations into the new origin abstraction, ensuring backwards compatibility while enabling the unified origin system. ## Parent Issue Epic: #8 Unified File Origin System ## Goals 1. Create `LocalFileOrigin` class implementing `FileOrigin` interface 2. Wrap existing FreeCAD file dialog and document operations 3. Ensure 100% backwards compatibility with current behavior 4. Register as the default/fallback origin ## Detailed Design ### LocalFileOrigin Class ```cpp // src/Gui/LocalFileOrigin.h class LocalFileOrigin : public FileOrigin { Q_OBJECT public: LocalFileOrigin(); // Identity QString id() const override { return QStringLiteral("local"); } QString name() const override { return tr("Local Files"); } QString nickname() const override { return tr("Local"); } QIcon icon() const override; // folder icon OriginType type() const override { return OriginType::Local; } // Capabilities - local FS has none of the extended features bool supportsRevisions() const override { return false; } bool supportsBOM() const override { return false; } bool supportsPartNumbers() const override { return false; } bool requiresAuthentication() const override { return false; } // Always connected ConnectionState connectionState() const override { return ConnectionState::Connected; } // Core operations - wrap existing FreeCAD behavior void newDocument() override; void openDocument() override; void saveDocument(App::Document* doc) override; void saveDocumentAs(App::Document* doc) override; void importFile(App::Document* doc) override; void exportSelection(App::Document* doc) override; // Document ownership - checks if doc has a local file path bool ownsDocument(App::Document* doc) const override; // No suffix for local files (or could show path) QString documentDisplaySuffix(App::Document* doc) const override; }; ``` ### Implementation Notes The implementation should delegate to existing FreeCAD code: ```cpp void LocalFileOrigin::newDocument() { // Equivalent to Std_New::activated() App::GetApplication().newDocument(); } void LocalFileOrigin::openDocument() { // Equivalent to Std_Open::activated() // Use existing file dialog from Application::open() Gui::getMainWindow()->open(); } void LocalFileOrigin::saveDocument(App::Document* doc) { // Equivalent to Std_Save::activated() if (doc->isSaved()) { doc->save(); } else { saveDocumentAs(doc); } } ``` ### Icon Use the existing `folder` icon from kindred-icons for the local origin. ## Implementation Tasks - [ ] Create `LocalFileOrigin` class - [ ] Implement all core file operations - [ ] Implement `ownsDocument()` logic (check for local file path) - [ ] Register with `OriginManager` at startup - [ ] Add unit tests - [ ] Ensure existing file dialogs work unchanged ## Files to Create/Modify - `src/Gui/LocalFileOrigin.h` (new) - `src/Gui/LocalFileOrigin.cpp` (new) - `src/Gui/Application.cpp` (register LocalFileOrigin) - `src/Gui/CMakeLists.txt` ## Acceptance Criteria - [ ] `LocalFileOrigin` implements full `FileOrigin` interface - [ ] New/Open/Save/SaveAs work identically to current behavior - [ ] Import/Export work correctly - [ ] Origin is registered and available in OriginManager - [ ] `ownsDocument()` correctly identifies local documents - [ ] No regressions in existing file operation behavior ## Dependencies - #9 Origin abstraction layer ## Blocking - #12 Modify Std_* commands
forbes referenced this issue from a commit 2026-02-14 16:31:28 +00:00
forbes referenced this issue from a commit 2026-02-14 16:34:32 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: kindred/create#10