void SolveSpace::ReloadAllImported(void) { allConsistent = false; int i; for(i = 0; i < SK.group.n; i++) { Group *g = &(SK.group.elem[i]); if(g->type != Group::IMPORTED) continue; g->impEntity.Clear(); g->impMesh.Clear(); g->impShell.Clear(); FILE *test = fopen(g->impFile, "rb"); if(test) { fclose(test); // okay, exists } else { // It doesn't exist. Perhaps the entire tree has moved, and we // can use the relative filename to get us back. if(SS.saveFile[0]) { char fromRel[MAX_PATH]; strcpy(fromRel, g->impFileRel); MakePathAbsolute(SS.saveFile, fromRel); test = fopen(fromRel, "rb"); if(test) { fclose(test); // It worked, this is our new absolute path strcpy(g->impFile, fromRel); } } } if(LoadEntitiesFromFile(g->impFile, &(g->impEntity), &(g->impMesh), &(g->impShell))) { if(SS.saveFile[0]) { // Record the imported file's name relative to our filename; // if the entire tree moves, then everything will still work strcpy(g->impFileRel, g->impFile); MakePathRelative(SS.saveFile, g->impFileRel); } else { // We're not yet saved, so can't make it absolute strcpy(g->impFileRel, g->impFile); } } else { Error("Failed to load imported file '%s'", g->impFile); } } }
bool SolveSpaceUI::ReloadAllImported(bool canCancel) { std::map<std::string, std::string> importMap; allConsistent = false; int i; for(i = 0; i < SK.group.n; i++) { Group *g = &(SK.group.elem[i]); if(g->type != Group::IMPORTED) continue; if(isalpha(g->impFile[0]) && g->impFile[1] == ':') { // Make sure that g->impFileRel always contains a relative path // in an UNIX format, even after we load an old file which had // the path in Windows format PathSepNormalize(g->impFileRel); } g->impEntity.Clear(); g->impMesh.Clear(); g->impShell.Clear(); if(importMap.count(g->impFile)) { std::string newPath = importMap[g->impFile]; if(!newPath.empty()) g->impFile = newPath; } FILE *test = ssfopen(g->impFile, "rb"); if(test) { fclose(test); // okay, exists } else { // It doesn't exist. Perhaps the entire tree has moved, and we // can use the relative filename to get us back. if(!SS.saveFile.empty()) { std::string rel = PathSepUNIXToPlatform(g->impFileRel); std::string fromRel = MakePathAbsolute(SS.saveFile, rel); test = ssfopen(fromRel, "rb"); if(test) { fclose(test); // It worked, this is our new absolute path g->impFile = fromRel; } } } try_load_file: if(LoadEntitiesFromFile(g->impFile, &(g->impEntity), &(g->impMesh), &(g->impShell))) { if(!SS.saveFile.empty()) { // Record the imported file's name relative to our filename; // if the entire tree moves, then everything will still work std::string rel = MakePathRelative(SS.saveFile, g->impFile); g->impFileRel = PathSepPlatformToUNIX(rel); } else { // We're not yet saved, so can't make it absolute. // This will only be used for display purposes, as SS.saveFile // is always nonempty when we are actually writing anything. g->impFileRel = g->impFile; } } else if(!importMap.count(g->impFile)) { switch(LocateImportedFileYesNoCancel(g->impFileRel, canCancel)) { case DIALOG_YES: { std::string oldImpFile = g->impFile; if(!GetOpenFile(g->impFile, "", SLVS_PATTERN)) { if(canCancel) return false; break; } else { importMap[oldImpFile] = g->impFile; goto try_load_file; } } case DIALOG_NO: importMap[g->impFile] = ""; /* Geometry will be pruned by GenerateAll(). */ break; case DIALOG_CANCEL: return false; } } else { // User was already asked to and refused to locate a missing // imported file. } } return true; }