wiRedPanda
Logic Circuit Simulator
Loading...
Searching...
No Matches
ICRegistry Class Reference

Manages IC definitions, file watching, and embedded blob storage. More...

#include <ICRegistry.h>

Inheritance diagram for ICRegistry:
[legend]

Public Member Functions

QByteArray blob (const QString &name) const
 Returns the raw .panda bytes for the embedded IC named name.
const QMap< QString, QByteArray > & blobMap () const
 Returns a const reference to the full blob map (name → .panda bytes).
QMap< QString, QByteArray > & blobMapRef ()
void blobRenamed (const QString &oldName, const QString &newName)
const QByteArray & cachedFileBytes (const QString &filePath)
 Returns cached file bytes, reading from disk on first access. Returns empty on failure.
void clearBlobs ()
 Removes all stored blobs.
ICcreateEmbeddedIC (const QString &blobName, const QByteArray &fileBytes, const QString &contextDir)
 Creates a new embedded IC from file bytes, registers the blob, and pushes an undo command.
void definitionChanged (const QString &filePath)
 Emitted when an IC definition file changes on disk and its cached definition is invalidated.
int embedICsByFile (const QString &fileName, const QByteArray &fileBytes, const QString &blobName)
 Converts all file-backed IC elements referencing fileName to embedded ICs using blobName.
int extractToFile (const QString &blobName, const QString &filePath)
 Writes the blob to disk and converts all embedded ICs with blobName to file-backed.
QList< GraphicElement * > findICsByBlobName (const QString &blobName) const
 Finds all embedded IC elements with blobName.
QList< GraphicElement * > findICsByFile (const QString &fileName) const
 Finds all IC elements in the scene that reference fileName.
bool hasBlob (const QString &name) const
 Returns true if a blob named name is stored in the registry.
 ICRegistry (Scene *scene)
bool initEmbeddedIC (IC *ic, const QString &blobName)
 Initializes an embedded IC by looking up its blob in the registry.
void invalidate (const QString &filePath)
 Invalidates a cached definition (e.g., after file change).
void registerBlob (const QString &name, const QByteArray &data)
 Stores blob data under name without invalidating the definition cache.
void removeBlob (const QString &name)
 Removes the blob named name from the registry.
void renameBlob (const QString &oldName, const QString &newName)
 Renames a blob from oldName to newName, updating the cache key.
void setBlob (const QString &name, const QByteArray &data)
 Stores or replaces the blob data under name and invalidates the cached definition.
QString uniqueBlobName (const QString &baseName) const
 Returns baseName if available, or appends a numeric suffix to avoid collision.
void watchFile (const QString &filePath)
 Registers a file for watching. Called when an IC element is added to the scene.

Static Public Member Functions

static QByteArray captureSnapshot (const QList< GraphicElement * > &targets)
 Serializes targets into a self-contained .panda byte array (used for embedding).
static void rollbackElements (const QList< GraphicElement * > &elements, const QByteArray &snapshot, Scene *scene)
 Restores elements from a previously captured snapshot (used for atomic rollback).

Detailed Description

Manages IC definitions, file watching, and embedded blob storage.

Owned by Scene. Caches ICDefinition objects keyed by canonical file path. Watches IC files for changes and reloads all IC instances referencing a changed file.

Definition at line 29 of file ICRegistry.h.

Constructor & Destructor Documentation

◆ ICRegistry()

ICRegistry::ICRegistry ( Scene * scene)
explicit

Definition at line 25 of file ICRegistry.cpp.

Member Function Documentation

◆ blob()

QByteArray ICRegistry::blob ( const QString & name) const

Returns the raw .panda bytes for the embedded IC named name.

Definition at line 129 of file ICRegistry.cpp.

Referenced by extractToFile(), and initEmbeddedIC().

◆ blobMap()

const QMap< QString, QByteArray > & ICRegistry::blobMap ( ) const
inline

Returns a const reference to the full blob map (name → .panda bytes).

Definition at line 63 of file ICRegistry.h.

Referenced by ElementPalette::updateEmbeddedICList().

◆ blobMapRef()

QMap< QString, QByteArray > & ICRegistry::blobMapRef ( )
inline

Returns a mutable reference to the blob map (used by serialization). Prefer setBlob() for individual updates — it triggers cache invalidation. Use blobMapRef() only when the whole map is being replaced atomically (e.g., during deserialization of a .panda file).

Definition at line 68 of file ICRegistry.h.

◆ blobRenamed()

void ICRegistry::blobRenamed ( const QString & oldName,
const QString & newName )

Emitted when renameBlob() actually renames a blob (not on its no-op guard cases), so listeners tracking a blob by name (e.g. an open sub-circuit tab's title) can follow the rename.

Referenced by WorkspaceManager::createNewTab(), and renameBlob().

◆ cachedFileBytes()

const QByteArray & ICRegistry::cachedFileBytes ( const QString & filePath)

Returns cached file bytes, reading from disk on first access. Returns empty on failure.

Definition at line 33 of file ICRegistry.cpp.

◆ captureSnapshot()

QByteArray ICRegistry::captureSnapshot ( const QList< GraphicElement * > & targets)
static

Serializes targets into a self-contained .panda byte array (used for embedding).

Definition at line 485 of file ICRegistry.cpp.

References InMemorySnapshot, and Serialization::writePandaHeader().

Referenced by embedICsByFile(), extractToFile(), and WorkSpace::onChildICBlobSaved().

◆ clearBlobs()

void ICRegistry::clearBlobs ( )

Removes all stored blobs.

Definition at line 182 of file ICRegistry.cpp.

◆ createEmbeddedIC()

IC * ICRegistry::createEmbeddedIC ( const QString & blobName,
const QByteArray & fileBytes,
const QString & contextDir )

Creates a new embedded IC from file bytes, registers the blob, and pushes an undo command.

Definition at line 224 of file ICRegistry.cpp.

References IC::loadFromBlob(), and IC::setBlobName().

◆ definitionChanged()

void ICRegistry::definitionChanged ( const QString & filePath)

Emitted when an IC definition file changes on disk and its cached definition is invalidated.

◆ embedICsByFile()

int ICRegistry::embedICsByFile ( const QString & fileName,
const QByteArray & fileBytes,
const QString & blobName )

Converts all file-backed IC elements referencing fileName to embedded ICs using blobName.

Definition at line 238 of file ICRegistry.cpp.

References UpdateBlobCommand::captureConnections(), captureSnapshot(), findICsByFile(), IC::loadFromBlob(), registerBlob(), removeBlob(), and IC::setBlobName().

Referenced by ICController::embedSelectedIC().

◆ extractToFile()

int ICRegistry::extractToFile ( const QString & blobName,
const QString & filePath )

Writes the blob to disk and converts all embedded ICs with blobName to file-backed.

Definition at line 271 of file ICRegistry.cpp.

References blob(), UpdateBlobCommand::captureConnections(), captureSnapshot(), findICsByBlobName(), IC::loadFile(), PANDACEPTION, and removeBlob().

Referenced by ICController::extractSelectedIC().

◆ findICsByBlobName()

QList< GraphicElement * > ICRegistry::findICsByBlobName ( const QString & blobName) const

Finds all embedded IC elements with blobName.

Definition at line 187 of file ICRegistry.cpp.

Referenced by extractToFile().

◆ findICsByFile()

QList< GraphicElement * > ICRegistry::findICsByFile ( const QString & fileName) const

Finds all IC elements in the scene that reference fileName.

Definition at line 66 of file ICRegistry.cpp.

Referenced by embedICsByFile().

◆ hasBlob()

bool ICRegistry::hasBlob ( const QString & name) const

Returns true if a blob named name is stored in the registry.

Definition at line 124 of file ICRegistry.cpp.

Referenced by initEmbeddedIC(), and uniqueBlobName().

◆ initEmbeddedIC()

bool ICRegistry::initEmbeddedIC ( IC * ic,
const QString & blobName )

Initializes an embedded IC by looking up its blob in the registry.

Definition at line 198 of file ICRegistry.cpp.

References blob(), hasBlob(), GraphicElement::label(), IC::loadFromBlob(), IC::setBlobName(), and GraphicElement::setLabel().

◆ invalidate()

void ICRegistry::invalidate ( const QString & filePath)

Invalidates a cached definition (e.g., after file change).

Definition at line 54 of file ICRegistry.cpp.

◆ registerBlob()

void ICRegistry::registerBlob ( const QString & name,
const QByteArray & data )

Stores blob data under name without invalidating the definition cache.

Definition at line 139 of file ICRegistry.cpp.

Referenced by embedICsByFile().

◆ removeBlob()

void ICRegistry::removeBlob ( const QString & name)

Removes the blob named name from the registry.

Definition at line 148 of file ICRegistry.cpp.

Referenced by embedICsByFile(), and extractToFile().

◆ renameBlob()

void ICRegistry::renameBlob ( const QString & oldName,
const QString & newName )

Renames a blob from oldName to newName, updating the cache key.

Definition at line 153 of file ICRegistry.cpp.

References blobRenamed(), and IC::setBlobName().

◆ rollbackElements()

void ICRegistry::rollbackElements ( const QList< GraphicElement * > & elements,
const QByteArray & snapshot,
Scene * scene )
static

Restores elements from a previously captured snapshot (used for atomic rollback).

Definition at line 305 of file ICRegistry.cpp.

References Scene::deserializationContext(), InMemorySnapshot, and Serialization::readPandaHeader().

Referenced by WorkSpace::onChildICBlobSaved().

◆ setBlob()

void ICRegistry::setBlob ( const QString & name,
const QByteArray & data )

Stores or replaces the blob data under name and invalidates the cached definition.

Definition at line 134 of file ICRegistry.cpp.

◆ uniqueBlobName()

QString ICRegistry::uniqueBlobName ( const QString & baseName) const

Returns baseName if available, or appends a numeric suffix to avoid collision.

Definition at line 211 of file ICRegistry.cpp.

References hasBlob().

◆ watchFile()

void ICRegistry::watchFile ( const QString & filePath)

Registers a file for watching. Called when an IC element is added to the scene.

Definition at line 59 of file ICRegistry.cpp.


The documentation for this class was generated from the following files: