src/ldDocument.cpp

changeset 979
880d3fe9ac7c
parent 978
4603d8fd063e
child 980
4a95c6b06ebe
equal deleted inserted replaced
978:4603d8fd063e 979:880d3fe9ac7c
39 enum { MAX_RECENT_FILES = 10 }; 39 enum { MAX_RECENT_FILES = 10 };
40 static bool g_aborted = false; 40 static bool g_aborted = false;
41 static LDDocument* g_logoedStud; 41 static LDDocument* g_logoedStud;
42 static LDDocument* g_logoedStud2; 42 static LDDocument* g_logoedStud2;
43 static bool g_loadingLogoedStuds = false; 43 static bool g_loadingLogoedStuds = false;
44
45 const QStringList g_specialSubdirectories ({ "s", "48", "8" }); 44 const QStringList g_specialSubdirectories ({ "s", "48", "8" });
46 45
47 // =============================================================================
48 //
49 LDDocument::LDDocument (QObject* parent) : 46 LDDocument::LDDocument (QObject* parent) :
50 QObject (parent), 47 QObject (parent),
51 HierarchyElement (parent), 48 HierarchyElement (parent),
52 m_history (new History), 49 m_history (new History),
53 m_isImplicit (true), 50 m_isCache (true),
54 m_flags (0),
55 m_verticesOutdated (true), 51 m_verticesOutdated (true),
56 m_needVertexMerge (true), 52 m_needVertexMerge (true),
53 m_beingDestroyed (false),
57 m_gldata (new LDGLData) 54 m_gldata (new LDGLData)
58 { 55 {
59 setSavePosition (-1); 56 setSavePosition (-1);
60 setTabIndex (-1); 57 setTabIndex (-1);
61 m_history->setDocument (this); 58 m_history->setDocument (this);
62 m_needsReCache = true; 59 m_needsReCache = true;
63 } 60 }
64 61
65 // =============================================================================
66 //
67 LDDocument::~LDDocument() 62 LDDocument::~LDDocument()
68 { 63 {
69 m_flags |= DOCF_IsBeingDestroyed; 64 m_beingDestroyed = true;
70 delete m_history; 65 delete m_history;
71 delete m_gldata; 66 delete m_gldata;
72 } 67 }
73 68
74 // ============================================================================= 69 QString LDDocument::name() const
75 // 70 {
76 void LDDocument::setImplicit (bool const& a) 71 return m_name;
77 { 72 }
78 if (m_isImplicit != a) 73
79 { 74 void LDDocument::setName (QString value)
80 m_isImplicit = a; 75 {
81 76 m_name = value;
82 if (a == false) 77 }
83 { 78
84 print ("Opened %1", name()); 79 const LDObjectList& LDDocument::objects() const
85 80 {
86 // Implicit files are not compiled by the GL renderer. Now that this 81 return m_objects;
87 // part is no longer implicit, it needs to be compiled. 82 }
88 m_window->R()->compiler()->compileDocument (this); 83
89 } 84 History* LDDocument::history() const
90 else 85 {
91 { 86 return m_history;
92 print ("Closed %1", name()); 87 }
93 } 88
94 89 QString LDDocument::fullPath()
90 {
91 return m_fullPath;
92 }
93
94 void LDDocument::setFullPath (QString value)
95 {
96 m_fullPath = value;
97 }
98
99 int LDDocument::tabIndex() const
100 {
101 return m_tabIndex;
102 }
103
104 void LDDocument::setTabIndex (int value)
105 {
106 m_tabIndex = value;
107 }
108
109 const QList<LDPolygon>& LDDocument::polygonData() const
110 {
111 return m_polygonData;
112 }
113
114 long LDDocument::savePosition() const
115 {
116 return m_savePosition;
117 }
118
119 void LDDocument::setSavePosition (long value)
120 {
121 m_savePosition = value;
122 }
123
124 QString LDDocument::defaultName() const
125 {
126 return m_defaultName;
127 }
128
129 void LDDocument::setDefaultName (QString value)
130 {
131 m_defaultName = value;
132 }
133
134 void LDDocument::openForEditing()
135 {
136 if (m_isCache)
137 {
138 m_isCache = false;
139 print ("Opened %1", name());
140
141 // Cache files are not compiled by the GL renderer. Now that this file is open for editing, it needs to be
142 // compiled.
143 m_window->R()->compiler()->compileDocument (this);
95 m_window->updateDocumentList(); 144 m_window->updateDocumentList();
145 }
146 }
147
148 bool LDDocument::isCache() const
149 {
150 return m_isCache;
151 }
152
153 void LDDocument::addHistoryStep()
154 {
155 history()->addStep();
156 }
157
158 void LDDocument::undo()
159 {
160 history()->undo();
161 }
162
163 void LDDocument::redo()
164 {
165 history()->redo();
166 }
167
168 void LDDocument::clearHistory()
169 {
170 history()->clear();
171 }
172
173 void LDDocument::addToHistory (AbstractHistoryEntry* entry)
174 {
175 *history() << entry;
176 }
177
178 void LDDocument::close()
179 {
180 if (not isCache())
181 {
182 m_isCache = true;
183 print ("Closed %1", name());
184 m_window->updateDocumentList();
96 185
97 // If the current document just became implicit (i.e. user closed it), we need to get a new one to show. 186 // If the current document just became implicit (i.e. user closed it), we need to get a new one to show.
98 if (currentDocument() == this and a) 187 if (currentDocument() == this)
99 m_window->currentDocumentClosed(); 188 m_window->currentDocumentClosed();
100 } 189 }
190 }
191
192 LDGLData* LDDocument::glData()
193 {
194 return m_gldata;
101 } 195 }
102 196
103 // ============================================================================= 197 // =============================================================================
104 // 198 //
105 LDDocument* FindDocument (QString name) 199 LDDocument* FindDocument (QString name)
429 fp->close(); 523 fp->close();
430 fp->deleteLater(); 524 fp->deleteLater();
431 525
432 if (not ok) 526 if (not ok)
433 { 527 {
434 load->dismiss(); 528 load->close();
435 return nullptr; 529 return nullptr;
436 } 530 }
437 531
438 load->addObjects (objs); 532 load->addObjects (objs);
439 533
447 load->history()->setIgnoring (false); 541 load->history()->setIgnoring (false);
448 return load; 542 return load;
449 } 543 }
450 544
451 // ============================================================================= 545 // =============================================================================
546 //
547 // Performs safety checks. Do this before closing any files!
452 // 548 //
453 bool LDDocument::isSafeToClose() 549 bool LDDocument::isSafeToClose()
454 { 550 {
455 using msgbox = QMessageBox; 551 using msgbox = QMessageBox;
456 setlocale (LC_ALL, "C"); 552 setlocale (LC_ALL, "C");
507 // ============================================================================= 603 // =============================================================================
508 // 604 //
509 void CloseAllDocuments() 605 void CloseAllDocuments()
510 { 606 {
511 for (LDDocument* file : g_win->allDocuments()) 607 for (LDDocument* file : g_win->allDocuments())
512 file->dismiss(); 608 file->close();
513 } 609 }
514 610
515 // ============================================================================= 611 // =============================================================================
516 // 612 //
517 void AddRecentFile (QString path) 613 void AddRecentFile (QString path)
586 682
587 g_loadingMainFile = false; 683 g_loadingMainFile = false;
588 return; 684 return;
589 } 685 }
590 686
591 file->setImplicit (false); 687 file->openForEditing();
592 g_win->closeInitialDocument(); 688 g_win->closeInitialDocument();
593 g_win->changeDocument (file); 689 g_win->changeDocument (file);
594 g_win->doFullRefresh(); 690 g_win->doFullRefresh();
595 AddRecentFile (path); 691 AddRecentFile (path);
596 g_loadingMainFile = false; 692 g_loadingMainFile = false;
628 724
629 // ============================================================================= 725 // =============================================================================
630 // 726 //
631 bool LDDocument::save (QString path, int64* sizeptr) 727 bool LDDocument::save (QString path, int64* sizeptr)
632 { 728 {
633 if (isImplicit()) 729 if (isCache())
634 return false; 730 return false;
635 731
636 if (not path.length()) 732 if (not path.length())
637 path = fullPath(); 733 path = fullPath();
638 734
1014 obj->setDocument (this); 1110 obj->setDocument (this);
1015 m_window->R()->compileObject (obj); 1111 m_window->R()->compileObject (obj);
1016 1112
1017 1113
1018 #ifdef DEBUG 1114 #ifdef DEBUG
1019 if (not isImplicit()) 1115 if (not isCache())
1020 dprint ("Inserted object #%1 (%2) at %3\n", obj->id(), obj->typeName(), pos); 1116 dprint ("Inserted object #%1 (%2) at %3\n", obj->id(), obj->typeName(), pos);
1021 #endif 1117 #endif
1022 } 1118 }
1023 1119
1024 // ============================================================================= 1120 // =============================================================================
1044 1140
1045 if (m_objects[idx] == obj) 1141 if (m_objects[idx] == obj)
1046 { 1142 {
1047 obj->deselect(); 1143 obj->deselect();
1048 1144
1049 if (not isImplicit() and not (flags() & DOCF_IsBeingDestroyed)) 1145 if (not isCache() and not m_beingDestroyed)
1050 { 1146 {
1051 history()->add (new DelHistory (idx, obj)); 1147 history()->add (new DelHistory (idx, obj));
1052 m_objectVertices.remove (obj); 1148 m_objectVertices.remove (obj);
1053 } 1149 }
1054 1150
1114 1210
1115 // ============================================================================= 1211 // =============================================================================
1116 // 1212 //
1117 bool LDDocument::hasUnsavedChanges() const 1213 bool LDDocument::hasUnsavedChanges() const
1118 { 1214 {
1119 return not isImplicit() and history()->position() != savePosition(); 1215 return not isCache() and history()->position() != savePosition();
1120 } 1216 }
1121 1217
1122 // ============================================================================= 1218 // =============================================================================
1123 // 1219 //
1124 QString LDDocument::getDisplayName() 1220 QString LDDocument::getDisplayName()

mercurial