Wed, 08 Jan 2014 13:43:39 +0200
- corrected relationships between documents: opening a main file with the same name as another document is to overload it and editing the document is to invalidate its cache so that it gets rendered properly in other documents possibly referencing it.
src/document.cc | file | annotate | diff | comparison | revisions | |
src/document.h | file | annotate | diff | comparison | revisions | |
src/gldraw.cc | file | annotate | diff | comparison | revisions | |
src/ldtypes.h | file | annotate | diff | comparison | revisions | |
src/misc/documentPointer.cc | file | annotate | diff | comparison | revisions | |
src/misc/documentPointer.h | file | annotate | diff | comparison | revisions | |
src/property.h | file | annotate | diff | comparison | revisions |
--- a/src/document.cc Tue Jan 07 12:21:46 2014 +0200 +++ b/src/document.cc Wed Jan 08 13:43:39 2014 +0200 @@ -626,6 +626,20 @@ void openMainFile (QString path) { g_loadingMainFile = true; + + // If there's already a file with the same name, this file must replace it. + LDDocument* documentToReplace = null; + QString shortName = LDDocument::shortenName (path); + + for (LDDocument* doc : g_loadedFiles) + { + if (doc->getName() == shortName) + { + documentToReplace = doc; + break; + } + } + LDDocument* file = openDocument (path, false); if (!file) @@ -647,6 +661,19 @@ file->setImplicit (false); + // Replace references to the old file with the new file. + if (documentToReplace != null) + { + for (LDDocumentPointer* ptr : documentToReplace->getReferences()) + { dlog ("ptr: %1 (%2)\n", + ptr, ptr->getPointer() ? ptr->getPointer()->getName() : "<null>"); + + ptr->operator= (file); + } + + assert (documentToReplace->countReferences() == 0); + } + // If we have an anonymous, unchanged file open as the only open file // (aside of the one we just opened), close it now. LDDocument::closeInitialFile(); @@ -1091,7 +1118,7 @@ void LDDocument::closeUnused() { for (LDDocument* file : g_loadedFiles) - if (file->isImplicit() && file->numReferences() == 0) + if (file->isImplicit() && file->countReferences() == 0) delete file; } @@ -1155,8 +1182,14 @@ bool deep = flags & LDSubfile::DeepInline, doCache = flags & LDSubfile::CacheInline; + if (m_needsCache) + { + clearCache(); + doCache = true; + } + // If we have this cached, just create a copy of that - if (deep && getCache().size()) + if (deep && getCache().isEmpty() == false) { for (LDObject* obj : getCache()) objs << obj->createCopy(); @@ -1357,15 +1390,15 @@ // ----------------------------------------------------------------------------- void LDDocument::addReference (LDDocumentPointer* ptr) { - m_refs << ptr; + pushToReferences (ptr); } // ============================================================================= // ----------------------------------------------------------------------------- void LDDocument::removeReference (LDDocumentPointer* ptr) { - m_refs.removeOne (ptr); + removeFromReferences (ptr); - if (m_refs.size() == 0) + if (getReferences().size() == 0) invokeLater (closeUnused); } \ No newline at end of file
--- a/src/document.h Tue Jan 07 12:21:46 2014 +0200 +++ b/src/document.h Wed Jan 08 13:43:39 2014 +0200 @@ -56,16 +56,17 @@ { properties: Q_OBJECT - PROPERTY (private, QList<LDObject*>, Objects, NO_OPS, STOCK_WRITE) - PROPERTY (private, History*, History, NO_OPS, STOCK_WRITE) - PROPERTY (private, QList<LDObject*>, Vertices, NO_OPS, STOCK_WRITE) - PROPERTY (public, QString, Name, STR_OPS, STOCK_WRITE) - PROPERTY (public, QString, FullPath, STR_OPS, STOCK_WRITE) - PROPERTY (public, QString, DefaultName, STR_OPS, STOCK_WRITE) - PROPERTY (public, bool, Implicit, BOOL_OPS, STOCK_WRITE) - PROPERTY (public, QList<LDObject*>, Cache, NO_OPS, STOCK_WRITE) - PROPERTY (public, long, SavePosition, NUM_OPS, STOCK_WRITE) - PROPERTY (public, QListWidgetItem*, ListItem, NO_OPS, STOCK_WRITE) + PROPERTY (private, QList<LDObject*>, Objects, LIST_OPS, STOCK_WRITE) + PROPERTY (private, History*, History, NO_OPS, STOCK_WRITE) + PROPERTY (private, QList<LDObject*>, Vertices, LIST_OPS, STOCK_WRITE) + PROPERTY (private, QList<LDDocumentPointer*>, References, LIST_OPS, STOCK_WRITE) + PROPERTY (public, QString, Name, STR_OPS, STOCK_WRITE) + PROPERTY (public, QString, FullPath, STR_OPS, STOCK_WRITE) + PROPERTY (public, QString, DefaultName, STR_OPS, STOCK_WRITE) + PROPERTY (public, bool, Implicit, BOOL_OPS, STOCK_WRITE) + PROPERTY (public, QList<LDObject*>, Cache, LIST_OPS, STOCK_WRITE) + PROPERTY (public, long, SavePosition, NUM_OPS, STOCK_WRITE) + PROPERTY (public, QListWidgetItem*, ListItem, NO_OPS, STOCK_WRITE) public: LDDocument(); @@ -88,7 +89,6 @@ void setObject (int idx, LDObject* obj); void addReference (LDDocumentPointer* ptr); void removeReference (LDDocumentPointer* ptr); - int numReferences() const { return m_refs.size(); } inline LDDocument& operator<< (LDObject* obj) { @@ -136,8 +136,11 @@ friend class LDObject; private: - QList<LDObject*> m_sel; - QList<LDDocumentPointer*> m_refs; + QList<LDObject*> m_sel; + + // If set to true, next inline of this document discards the cache and + // re-builds it. + bool m_needsCache; static LDDocument* m_curdoc; };
--- a/src/gldraw.cc Tue Jan 07 12:21:46 2014 +0200 +++ b/src/gldraw.cc Wed Jan 08 13:43:39 2014 +0200 @@ -997,10 +997,7 @@ LDSubfile* ref = static_cast<LDSubfile*> (obj); QList<LDObject*> objs; - objs = ref->inlineContents ( - LDSubfile::DeepInline | - LDSubfile::CacheInline | - LDSubfile::RendererInline); + objs = ref->inlineContents (LDSubfile::DeepInline | LDSubfile::RendererInline); bool oldinvert = g_glInvert; if (ref->getTransform().getDeterminant() < 0) @@ -1396,6 +1393,7 @@ continue; // White is background; skip LDObject* obj = LDObject::fromID (idx); + assert (obj != null); // If this is an additive single pick and the object is currently selected, // we remove it from selection instead.
--- a/src/ldtypes.h Tue Jan 07 12:21:46 2014 +0200 +++ b/src/ldtypes.h Wed Jan 08 13:43:39 2014 +0200 @@ -67,13 +67,13 @@ // ============================================================================= class LDObject { - PROPERTY (public, bool, Hidden, BOOL_OPS, STOCK_WRITE) - PROPERTY (public, bool, Selected, BOOL_OPS, STOCK_WRITE) - PROPERTY (public, LDObject*, Parent, NO_OPS, STOCK_WRITE) - PROPERTY (public, LDDocument*, File, NO_OPS, STOCK_WRITE) // TODO: rename~ - PROPERTY (private, int, ID, NUM_OPS, STOCK_WRITE) - PROPERTY (public, int, Color, NUM_OPS, CUSTOM_WRITE) - PROPERTY (public, bool, GLInit, BOOL_OPS, STOCK_WRITE) + PROPERTY (public, bool, Hidden, BOOL_OPS, STOCK_WRITE) + PROPERTY (public, bool, Selected, BOOL_OPS, STOCK_WRITE) + PROPERTY (public, LDObject*, Parent, NO_OPS, STOCK_WRITE) + PROPERTY (public, LDDocument*, File, NO_OPS, STOCK_WRITE) // TODO: rename~ + PROPERTY (private, int, ID, NUM_OPS, STOCK_WRITE) + PROPERTY (public, int, Color, NUM_OPS, CUSTOM_WRITE) + PROPERTY (public, bool, GLInit, BOOL_OPS, STOCK_WRITE) public: // Object type codes. Codes are sorted in order of significance.
--- a/src/misc/documentPointer.cc Tue Jan 07 12:21:46 2014 +0200 +++ b/src/misc/documentPointer.cc Wed Jan 08 13:43:39 2014 +0200 @@ -18,10 +18,10 @@ #include "documentPointer.h" #include "../document.h" +#include "../misc.h" LDDocumentPointer::LDDocumentPointer() : m_Pointer (null) {} - // ============================================================================= // ----------------------------------------------------------------------------- LDDocumentPointer::LDDocumentPointer (LDDocument* ptr) :
--- a/src/misc/documentPointer.h Tue Jan 07 12:21:46 2014 +0200 +++ b/src/misc/documentPointer.h Wed Jan 08 13:43:39 2014 +0200 @@ -21,11 +21,12 @@ #include "../main.h" +class LDSubfile; class LDDocument; class LDDocumentPointer { - PROPERTY (private, LDDocument*, Pointer, NO_OPS, STOCK_WRITE) + PROPERTY (private, LDDocument*, Pointer, NO_OPS, STOCK_WRITE) public: LDDocumentPointer();
--- a/src/property.h Tue Jan 07 12:21:46 2014 +0200 +++ b/src/property.h Wed Jan 08 13:43:39 2014 +0200 @@ -113,6 +113,12 @@ inline void clear##NAME() \ { \ set##NAME( TYPE() ); \ + } \ + \ + public: \ + inline int count##NAME() \ + { \ + return get##NAME().size(); \ } #endif // LDFORGE_PROPERTY_H \ No newline at end of file