139 LDDocument::~LDDocument() |
140 LDDocument::~LDDocument() |
140 { |
141 { |
141 // Remove this file from the list of files. This MUST be done FIRST, otherwise |
142 // Remove this file from the list of files. This MUST be done FIRST, otherwise |
142 // a ton of other functions will think this file is still valid when it is not! |
143 // a ton of other functions will think this file is still valid when it is not! |
143 g_loadedFiles.removeOne (this); |
144 g_loadedFiles.removeOne (this); |
144 |
145 m_flags |= DOCF_IsBeingDestroyed; |
145 m_history->setIgnoring (true); |
146 m_history->setIgnoring (true); |
146 |
147 |
147 // Clear everything from the model |
148 // Clear everything from the model |
148 for (LDObject* obj : objects()) |
149 for (LDObject* obj : objects()) |
149 obj->destroy(); |
150 obj->destroy(); |
1095 { |
1095 { |
1096 history()->add (new AddHistory (pos, obj)); |
1096 history()->add (new AddHistory (pos, obj)); |
1097 m_objects.insert (pos, obj); |
1097 m_objects.insert (pos, obj); |
1098 obj->setDocument (this); |
1098 obj->setDocument (this); |
1099 g_win->R()->compileObject (obj); |
1099 g_win->R()->compileObject (obj); |
|
1100 addKnownVerticesOf (obj); |
1100 |
1101 |
1101 #ifdef DEBUG |
1102 #ifdef DEBUG |
1102 if (not isImplicit()) |
1103 if (not isImplicit()) |
1103 dprint ("Inserted object #%1 (%2) at %3\n", obj->id(), obj->typeName(), pos); |
1104 dprint ("Inserted object #%1 (%2) at %3\n", obj->id(), obj->typeName(), pos); |
1104 #endif |
1105 #endif |
1105 } |
1106 } |
1106 |
1107 |
1107 // ============================================================================= |
1108 // ============================================================================= |
1108 // |
1109 // |
|
1110 void LDDocument::addKnownVerticesOf (LDObject* obj) |
|
1111 { |
|
1112 if (isImplicit()) |
|
1113 return; |
|
1114 |
|
1115 if (obj->type() == LDObject::ESubfile) |
|
1116 { |
|
1117 for (LDObject* sub : static_cast<LDSubfile*> (obj)->inlineContents (true, false)) |
|
1118 { |
|
1119 addKnownVerticesOf (sub); |
|
1120 sub->destroy(); |
|
1121 } |
|
1122 } |
|
1123 else |
|
1124 { |
|
1125 for (int i = 0; i < obj->vertices(); ++i) |
|
1126 addKnownVertexReference (obj->vertex (i)); |
|
1127 } |
|
1128 } |
|
1129 |
|
1130 // ============================================================================= |
|
1131 // |
|
1132 void LDDocument::removeKnownVerticesOf (LDObject* obj) |
|
1133 { |
|
1134 if (isImplicit()) |
|
1135 return; |
|
1136 |
|
1137 if (obj->type() == LDObject::ESubfile) |
|
1138 { |
|
1139 for (LDObject* sub : static_cast<LDSubfile*> (obj)->inlineContents (true, false)) |
|
1140 { |
|
1141 removeKnownVerticesOf (sub); |
|
1142 sub->destroy(); |
|
1143 } |
|
1144 } |
|
1145 else |
|
1146 { |
|
1147 for (int i = 0; i < obj->vertices(); ++i) |
|
1148 removeKnownVertexReference (obj->vertex (i)); |
|
1149 } |
|
1150 } |
|
1151 |
|
1152 // ============================================================================= |
|
1153 // |
1109 void LDDocument::forgetObject (LDObject* obj) |
1154 void LDDocument::forgetObject (LDObject* obj) |
1110 { |
1155 { |
1111 int idx = obj->lineNumber(); |
1156 int idx = obj->lineNumber(); |
1112 obj->unselect(); |
1157 obj->unselect(); |
1113 assert (m_objects[idx] == obj); |
1158 assert (m_objects[idx] == obj); |
1114 |
1159 |
1115 if (not history()->isIgnoring()) |
1160 if (not isImplicit() && not (flags() & DOCF_IsBeingDestroyed)) |
|
1161 { |
1116 history()->add (new DelHistory (idx, obj)); |
1162 history()->add (new DelHistory (idx, obj)); |
|
1163 removeKnownVerticesOf (obj); |
|
1164 } |
1117 |
1165 |
1118 m_objects.removeAt (idx); |
1166 m_objects.removeAt (idx); |
1119 obj->setDocument (null); |
1167 obj->setDocument (null); |
|
1168 } |
|
1169 |
|
1170 // ============================================================================= |
|
1171 // |
|
1172 void LDDocument::vertexChanged (const Vertex& a, const Vertex& b) |
|
1173 { |
|
1174 removeKnownVertexReference (a); |
|
1175 addKnownVertexReference (b); |
|
1176 } |
|
1177 |
|
1178 // ============================================================================= |
|
1179 // |
|
1180 void LDDocument::addKnownVertexReference (const Vertex& a) |
|
1181 { |
|
1182 if (isImplicit()) |
|
1183 return; |
|
1184 |
|
1185 auto it = m_vertices.find (a); |
|
1186 |
|
1187 if (it == m_vertices.end()) |
|
1188 m_vertices[a] = 1; |
|
1189 else |
|
1190 ++it.value(); |
|
1191 } |
|
1192 |
|
1193 // ============================================================================= |
|
1194 // |
|
1195 void LDDocument::removeKnownVertexReference (const Vertex& a) |
|
1196 { |
|
1197 if (isImplicit()) |
|
1198 return; |
|
1199 |
|
1200 auto it = m_vertices.find (a); |
|
1201 assert (it != m_vertices.end()); |
|
1202 |
|
1203 // If there's no more references to a given vertex, it is to be removed. |
|
1204 if (--it.value() == 0) |
|
1205 m_vertices.erase (it); |
1120 } |
1206 } |
1121 |
1207 |
1122 // ============================================================================= |
1208 // ============================================================================= |
1123 // |
1209 // |
1124 bool safeToCloseAll() |
1210 bool safeToCloseAll() |
1142 QString oldcode = getObject (idx)->asText(); |
1228 QString oldcode = getObject (idx)->asText(); |
1143 QString newcode = obj->asText(); |
1229 QString newcode = obj->asText(); |
1144 *m_history << new EditHistory (idx, oldcode, newcode); |
1230 *m_history << new EditHistory (idx, oldcode, newcode); |
1145 } |
1231 } |
1146 |
1232 |
|
1233 removeKnownVerticesOf (m_objects[idx]); |
1147 m_objects[idx]->unselect(); |
1234 m_objects[idx]->unselect(); |
1148 m_objects[idx]->setDocument (null); |
1235 m_objects[idx]->setDocument (null); |
1149 obj->setDocument (this); |
1236 obj->setDocument (this); |
|
1237 addKnownVerticesOf (obj); |
1150 g_win->R()->compileObject (obj); |
1238 g_win->R()->compileObject (obj); |
1151 m_objects[idx] = obj; |
1239 m_objects[idx] = obj; |
1152 } |
1240 } |
1153 |
1241 |
1154 // ============================================================================= |
1242 // ============================================================================= |
1352 return; |
1440 return; |
1353 |
1441 |
1354 delete g_logoedStud; |
1442 delete g_logoedStud; |
1355 delete g_logoedStud2; |
1443 delete g_logoedStud2; |
1356 |
1444 |
1357 g_logoedStud = openDocument ("stud-logo.dat", true); |
1445 g_logoedStud = openDocument ("stud-logo.dat", true, true); |
1358 g_logoedStud2 = openDocument ("stud2-logo.dat", true); |
1446 g_logoedStud2 = openDocument ("stud2-logo.dat", true, true); |
1359 |
1447 |
1360 print (LDDocument::tr ("Logoed studs loaded.\n")); |
1448 print (LDDocument::tr ("Logoed studs loaded.\n")); |
1361 } |
1449 } |
1362 |
1450 |
1363 // ============================================================================= |
1451 // ============================================================================= |