12#include <QFileSystemWatcher>
46 QList<GraphicElement *>
findICsByFile(
const QString &fileName)
const;
51 bool hasBlob(
const QString &name)
const;
53 QByteArray
blob(
const QString &name)
const;
55 void setBlob(
const QString &name,
const QByteArray &data);
57 void registerBlob(
const QString &name,
const QByteArray &data);
61 void renameBlob(
const QString &oldName,
const QString &newName);
63 const QMap<QString, QByteArray> &
blobMap()
const {
return m_blobs; }
68 QMap<QString, QByteArray> &
blobMapRef() {
return m_blobs; }
84 IC *
createEmbeddedIC(
const QString &blobName,
const QByteArray &fileBytes,
const QString &contextDir);
87 int embedICsByFile(
const QString &fileName,
const QByteArray &fileBytes,
88 const QString &blobName);
91 int extractToFile(
const QString &blobName,
const QString &filePath);
96 static QByteArray
captureSnapshot(
const QList<GraphicElement *> &targets);
99 static void rollbackElements(
const QList<GraphicElement *> &elements,
const QByteArray &snapshot,
112 void onFileChanged(
const QString &filePath);
119 static constexpr int kMaxBlobNestingDepth = 16;
125 void makeBlobSelfContained(
const QString &name, QSet<QString> &visited,
126 QMap<QString, QByteArray> &blobs,
int depth = 0);
129 static void renameBlobReference(QByteArray &blobData,
const QString &oldName,
const QString &newName);
137 void reloadTargetsAtomically(
const QList<GraphicElement *> &targets,
const QByteArray &oldData,
138 const std::function<
void(
IC *)> &mutate);
141 QMap<QString, QByteArray> m_fileCache;
142 QMap<QString, QByteArray> m_blobs;
143 QFileSystemWatcher m_fileWatcher;
Abstract base class for all graphical circuit elements in wiRedPanda.
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.
int embedICsByFile(const QString &fileName, const QByteArray &fileBytes, const QString &blobName)
Converts all file-backed IC elements referencing fileName to embedded ICs using blobName.
bool initEmbeddedIC(IC *ic, const QString &blobName)
Initializes an embedded IC by looking up its blob in the registry.
QByteArray blob(const QString &name) const
Returns the raw .panda bytes for the embedded IC named name.
void clearBlobs()
Removes all stored blobs.
const QMap< QString, QByteArray > & blobMap() const
Returns a const reference to the full blob map (name → .panda bytes).
QMap< QString, QByteArray > & blobMapRef()
QString uniqueBlobName(const QString &baseName) const
Returns baseName if available, or appends a numeric suffix to avoid collision.
QList< GraphicElement * > findICsByBlobName(const QString &blobName) const
Finds all embedded IC elements with blobName.
int extractToFile(const QString &blobName, const QString &filePath)
Writes the blob to disk and converts all embedded ICs with blobName to file-backed.
void invalidate(const QString &filePath)
Invalidates a cached definition (e.g., after file change).
const QByteArray & cachedFileBytes(const QString &filePath)
Returns cached file bytes, reading from disk on first access. Returns empty on failure.
void definitionChanged(const QString &filePath)
Emitted when an IC definition file changes on disk and its cached definition is invalidated.
void blobRenamed(const QString &oldName, const QString &newName)
void removeBlob(const QString &name)
Removes the blob named name from the registry.
IC * 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.
QList< GraphicElement * > findICsByFile(const QString &fileName) const
Finds all IC elements in the scene that reference fileName.
static void rollbackElements(const QList< GraphicElement * > &elements, const QByteArray &snapshot, Scene *scene)
Restores elements from a previously captured snapshot (used for atomic rollback).
void registerBlob(const QString &name, const QByteArray &data)
Stores blob data under name without invalidating the definition cache.
void watchFile(const QString &filePath)
Registers a file for watching. Called when an IC element is added to the scene.
bool hasBlob(const QString &name) const
Returns true if a blob named name is stored in the registry.
static QByteArray captureSnapshot(const QList< GraphicElement * > &targets)
Serializes targets into a self-contained .panda byte array (used for embedding).
Graphic element representing an Integrated Circuit (sub-circuit) box.
Main circuit editing scene.