From: David Gow Date: Wed, 15 Oct 2014 14:32:14 +0000 (+0800) Subject: Not working Quadtree object adding. X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=54cbdc5600ed4280f1e33f9f1f4780e48713c352;p=ipdf%2Fcode.git Not working Quadtree object adding. But working better than it did before. Assuming you like turtles_all_the_way_down.script to infinite loop when going back up. --- diff --git a/src/controlpanel.cpp b/src/controlpanel.cpp index daa4b21..0a50114 100644 --- a/src/controlpanel.cpp +++ b/src/controlpanel.cpp @@ -309,7 +309,13 @@ void ControlPanel::InsertTextIntoDocument() string msg = m_text_edit->toPlainText().toStdString(); Real scale = bounds.h / Real(2); Debug("Insert \"%s\" at %f, %f, scale %f", msg.c_str(), Float(xx), Float(yy), Float(scale)); +#ifndef QUADTREE_DISABLED + m_doc.SetQuadtreeInsertNode(m_view.GetCurrentQuadtreeNode()); +#endif m_doc.AddText(msg, scale, xx, yy); +#ifndef QUADTREE_DISABLED + m_doc.PropagateQuadChanges(m_view.GetCurrentQuadtreeNode()); +#endif m_view.ForceRenderDirty(); m_view.ForceBufferDirty(); m_view.ForceBoundsDirty(); @@ -323,7 +329,13 @@ void ControlPanel::InsertSVGIntoDocument() bounds.w /= Real(m_screen.ViewportWidth()); bounds.h /= Real(m_screen.ViewportHeight()); +#ifndef QUADTREE_DISABLED + m_doc.SetQuadtreeInsertNode(m_view.GetCurrentQuadtreeNode()); +#endif m_doc.ParseSVG(m_text_edit->toPlainText().toStdString(), bounds); +#ifndef QUADTREE_DISABLED + m_doc.PropagateQuadChanges(m_view.GetCurrentQuadtreeNode()); +#endif m_view.ForceRenderDirty(); m_view.ForceBufferDirty(); m_view.ForceBoundsDirty(); @@ -347,7 +359,13 @@ void ControlPanel::LoadSVGIntoDocument() bounds.w /= Real(m_screen.ViewportWidth()); bounds.h /= Real(m_screen.ViewportHeight()); +#ifndef QUADTREE_DISABLED + m_doc.SetQuadtreeInsertNode(m_view.GetCurrentQuadtreeNode()); +#endif m_doc.LoadSVG(filename.toStdString(), bounds); +#ifndef QUADTREE_DISABLED + m_doc.PropagateQuadChanges(m_view.GetCurrentQuadtreeNode()); +#endif m_view.ForceRenderDirty(); m_view.ForceBufferDirty(); m_view.ForceBoundsDirty(); diff --git a/src/debugscript.cpp b/src/debugscript.cpp index 9d78b26..64cbf49 100644 --- a/src/debugscript.cpp +++ b/src/debugscript.cpp @@ -251,12 +251,18 @@ bool DebugScript::Execute(View *view, Screen *scr) break; case AT_LoadSVG: { +#ifndef QUADTREE_DISABLED + view->Doc().SetQuadtreeInsertNode(view->GetCurrentQuadtreeNode()); +#endif #ifdef TRANSFORM_OBJECTS_NOT_VIEW view->Doc().LoadSVG(currentAction.textargs, Rect(Real(1)/Real(2),Real(1)/Real(2),Real(1)/Real(800),Real(1)/Real(600))); #else const Rect & bounds = view->GetBounds(); view->Doc().LoadSVG(currentAction.textargs, Rect(bounds.x+bounds.w/Real(2),bounds.y+bounds.h/Real(2),bounds.w/Real(800),bounds.h/Real(600))); #endif +#ifndef QUADTREE_DISABLED + view->Doc().PropagateQuadChanges(view->GetCurrentQuadtreeNode()); +#endif currentAction.type = AT_WaitFrame; view->ForceRenderDirty(); view->ForceBufferDirty(); diff --git a/src/document.cpp b/src/document.cpp index aff9a23..a7fb524 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -422,6 +422,7 @@ unsigned Document::Add(ObjectType type, const Rect & bounds, unsigned data_index m_objects.bounds.push_back(bounds); m_objects.data_indices.push_back(data_index); #ifndef QUADTREE_DISABLED + if (qti == -1) qti = m_current_insert_node; if (qti != -1) { QuadTreeIndex new_qti = qti; @@ -448,7 +449,6 @@ unsigned Document::Add(ObjectType type, const Rect & bounds, unsigned data_index } done: // matches is not amused, but sulix is nice and moved it inside the #ifdef for him. m_count++; - PropagateQuadChanges(qti); } return m_count-1; #else // words fail me (still not amused) diff --git a/src/document.h b/src/document.h index d6f41f3..59beee6 100644 --- a/src/document.h +++ b/src/document.h @@ -29,7 +29,7 @@ namespace IPDF class Document { public: - Document(const std::string & filename = "", const std::string & font_filename = "fonts/DejaVuSansMono.ttf") : m_objects(), m_count(0), m_font_data(NULL), m_font() + Document(const std::string & filename = "", const std::string & font_filename = "fonts/DejaVuSansMono.ttf") : m_objects(), m_current_insert_node(-1), m_count(0), m_font_data(NULL), m_font() { Load(filename); if (font_filename != "") @@ -54,7 +54,7 @@ namespace IPDF unsigned AddPath(unsigned start_index, unsigned end_index, const Colour & shading=Colour(0.6,0.6,0.6,1), const Colour & stroke=Colour(0,0,0,0)); unsigned AddBezier(const Bezier & bezier); - unsigned Add(ObjectType type, const Rect & bounds, unsigned data_index = 0, QuadTreeIndex qtnode = 0); + unsigned Add(ObjectType type, const Rect & bounds, unsigned data_index = 0, QuadTreeIndex qtnode = -1); unsigned AddBezierData(const Bezier & bezier); unsigned AddPathData(const Path & path); @@ -94,6 +94,8 @@ namespace IPDF void PropagateQuadChanges(QuadTreeIndex node); // Returns the number of objects the current object formed when clipped, the objects in question are added to the end of the document. int ClipObjectToQuadChild(int object_id, QuadTreeNodeChildren type); + + void SetQuadtreeInsertNode(QuadTreeIndex node) { m_current_insert_node = node; } #endif void ClearObjects() @@ -109,6 +111,8 @@ namespace IPDF #ifndef QUADTREE_DISABLED QuadTree m_quadtree; void GenBaseQuadtree(); + + QuadTreeIndex m_current_insert_node; #endif unsigned m_count; unsigned char * m_font_data; diff --git a/src/view.h b/src/view.h index 124ae07..f1ac789 100644 --- a/src/view.h +++ b/src/view.h @@ -83,6 +83,9 @@ namespace IPDF void SaveGPUBMP(const char * filename); Document & Doc() {return m_document;} +#ifndef QUADTREE_DISABLED + QuadTreeIndex GetCurrentQuadtreeNode() { return m_current_quadtree_node; } +#endif private: struct GPUObjBounds