src/ldDocument.cpp

changeset 984
a7b6f987d269
parent 983
05ba93066194
child 985
ed7b31b9f904
equal deleted inserted replaced
983:05ba93066194 984:a7b6f987d269
309 QFile* OpenLDrawFile (QString relpath, bool subdirs, QString* pathpointer) 309 QFile* OpenLDrawFile (QString relpath, bool subdirs, QString* pathpointer)
310 { 310 {
311 print ("Opening %1...\n", relpath); 311 print ("Opening %1...\n", relpath);
312 QString path = FindDocumentPath (relpath, subdirs); 312 QString path = FindDocumentPath (relpath, subdirs);
313 313
314 if (pathpointer != null) 314 if (pathpointer != nullptr)
315 *pathpointer = path; 315 *pathpointer = path;
316 316
317 if (path.isEmpty()) 317 if (path.isEmpty())
318 return null; 318 return nullptr;
319 319
320 QFile* fp = new QFile (path); 320 QFile* fp = new QFile (path);
321 321
322 if (fp->open (QIODevice::ReadOnly)) 322 if (fp->open (QIODevice::ReadOnly))
323 return fp; 323 return fp;
324 324
325 fp->deleteLater(); 325 fp->deleteLater();
326 return null; 326 return nullptr;
327 } 327 }
328 328
329 // ============================================================================= 329 // =============================================================================
330 // 330 //
331 LDObjectList LoadFileContents (QFile* fp, int* numWarnings, bool* ok) 331 LDObjectList LoadFileContents (QFile* fp, int* numWarnings, bool* ok)
382 } 382 }
383 383
384 if (not fp) 384 if (not fp)
385 return nullptr; 385 return nullptr;
386 386
387 LDDocument* load = (fileToOverride != null ? fileToOverride : g_win->newDocument (implicit)); 387 LDDocument* load = (fileToOverride != nullptr ? fileToOverride : g_win->newDocument (implicit));
388 load->setFullPath (fullpath); 388 load->setFullPath (fullpath);
389 load->setName (LDDocument::shortenName (load->fullPath())); 389 load->setName (LDDocument::shortenName (load->fullPath()));
390 390
391 // Loading the file shouldn't count as actual edits to the document. 391 // Loading the file shouldn't count as actual edits to the document.
392 load->history()->setIgnoring (true); 392 load->history()->setIgnoring (true);
531 } 531 }
532 } 532 }
533 533
534 // We cannot open this file if the document this would replace is not 534 // We cannot open this file if the document this would replace is not
535 // safe to close. 535 // safe to close.
536 if (documentToReplace != null and not documentToReplace->isSafeToClose()) 536 if (documentToReplace != nullptr and not documentToReplace->isSafeToClose())
537 return; 537 return;
538 538
539 g_loadingMainFile = true; 539 g_loadingMainFile = true;
540 540
541 // If we're replacing an existing document, clear the document and 541 // If we're replacing an existing document, clear the document and
542 // make it ready for being loaded to. 542 // make it ready for being loaded to.
543 if (documentToReplace != null) 543 if (documentToReplace != nullptr)
544 { 544 {
545 file = documentToReplace; 545 file = documentToReplace;
546 file->clear(); 546 file->clear();
547 } 547 }
548 548
549 bool aborted; 549 bool aborted;
550 file = OpenDocument (path, false, false, file, &aborted); 550 file = OpenDocument (path, false, false, file, &aborted);
551 551
552 if (file == null) 552 if (file == nullptr)
553 { 553 {
554 if (not aborted) 554 if (not aborted)
555 { 555 {
556 // Tell the user loading failed. 556 // Tell the user loading failed.
557 setlocale (LC_ALL, "C"); 557 setlocale (LC_ALL, "C");
611 path = fullPath(); 611 path = fullPath();
612 612
613 // If the second object in the list holds the file name, update that now. 613 // If the second object in the list holds the file name, update that now.
614 LDObject* nameObject = getObject (1); 614 LDObject* nameObject = getObject (1);
615 615
616 if (nameObject != null and nameObject->type() == OBJ_Comment) 616 if (nameObject != nullptr and nameObject->type() == OBJ_Comment)
617 { 617 {
618 LDComment* nameComment = static_cast<LDComment*> (nameObject); 618 LDComment* nameComment = static_cast<LDComment*> (nameObject);
619 619
620 if (nameComment->text().left (6) == "Name: ") 620 if (nameComment->text().left (6) == "Name: ")
621 { 621 {
625 } 625 }
626 } 626 }
627 627
628 QByteArray data; 628 QByteArray data;
629 629
630 if (sizeptr != null) 630 if (sizeptr != nullptr)
631 *sizeptr = 0; 631 *sizeptr = 0;
632 632
633 // File is open, now save the model to it. Note that LDraw requires files to have DOS line endings. 633 // File is open, now save the model to it. Note that LDraw requires files to have DOS line endings.
634 for (LDObject* obj : objects()) 634 for (LDObject* obj : objects())
635 { 635 {
636 QByteArray subdata ((obj->asText() + "\r\n").toUtf8()); 636 QByteArray subdata ((obj->asText() + "\r\n").toUtf8());
637 data.append (subdata); 637 data.append (subdata);
638 638
639 if (sizeptr != null) 639 if (sizeptr != nullptr)
640 *sizeptr += subdata.size(); 640 *sizeptr += subdata.size();
641 } 641 }
642 642
643 QFile f (path); 643 QFile f (path);
644 644
713 Vertex v; 713 Vertex v;
714 v.apply ([&] (Axis ax, double& a) { a = s[n + ax].toDouble(); }); 714 v.apply ([&] (Axis ax, double& a) { a = s[n + ax].toDouble(); });
715 return v; 715 return v;
716 } 716 }
717 717
718 static int32 StringToNumber (QString a, bool* ok = null) 718 static int32 StringToNumber (QString a, bool* ok = nullptr)
719 { 719 {
720 int base = 10; 720 int base = 10;
721 721
722 if (a.startsWith ("0x")) 722 if (a.startsWith ("0x"))
723 { 723 {
931 if (obj->type() == OBJ_Subfile) 931 if (obj->type() == OBJ_Subfile)
932 { 932 {
933 LDSubfile* ref = static_cast<LDSubfile*> (obj); 933 LDSubfile* ref = static_cast<LDSubfile*> (obj);
934 LDDocument* fileInfo = GetDocument (ref->fileInfo()->name()); 934 LDDocument* fileInfo = GetDocument (ref->fileInfo()->name());
935 935
936 if (fileInfo != null) 936 if (fileInfo != nullptr)
937 { 937 {
938 ref->setFileInfo (fileInfo); 938 ref->setFileInfo (fileInfo);
939 } 939 }
940 else 940 else
941 { 941 {
972 // 972 //
973 void LDDocument::addObjects (const LDObjectList& objs) 973 void LDDocument::addObjects (const LDObjectList& objs)
974 { 974 {
975 for (LDObject* obj : objs) 975 for (LDObject* obj : objs)
976 { 976 {
977 if (obj != null) 977 if (obj != nullptr)
978 addObject (obj); 978 addObject (obj);
979 } 979 }
980 } 980 }
981 981
982 // ============================================================================= 982 // =============================================================================
1124 continue; 1124 continue;
1125 } 1125 }
1126 1126
1127 LDPolygon* data = obj->getPolygon(); 1127 LDPolygon* data = obj->getPolygon();
1128 1128
1129 if (data != null) 1129 if (data != nullptr)
1130 { 1130 {
1131 m_polygonData << *data; 1131 m_polygonData << *data;
1132 delete data; 1132 delete data;
1133 } 1133 }
1134 } 1134 }
1182 if (m_config->useLogoStuds() and renderinline) 1182 if (m_config->useLogoStuds() and renderinline)
1183 { 1183 {
1184 // Ensure logoed studs are loaded first 1184 // Ensure logoed studs are loaded first
1185 LoadLogoStuds(); 1185 LoadLogoStuds();
1186 1186
1187 if (name() == "stud.dat" and g_logoedStud != null) 1187 if (name() == "stud.dat" and g_logoedStud != nullptr)
1188 return g_logoedStud->inlineContents (deep, renderinline); 1188 return g_logoedStud->inlineContents (deep, renderinline);
1189 else if (name() == "stud2.dat" and g_logoedStud2 != null) 1189 else if (name() == "stud2.dat" and g_logoedStud2 != nullptr)
1190 return g_logoedStud2->inlineContents (deep, renderinline); 1190 return g_logoedStud2->inlineContents (deep, renderinline);
1191 } 1191 }
1192 1192
1193 LDObjectList objs, objcache; 1193 LDObjectList objs, objcache;
1194 1194

mercurial