Add more complete error handling for import/export models

This commit is contained in:
Ryan Huffman 2014-07-31 10:40:45 -07:00
parent 49e35bbc84
commit 3e2bb0f168
5 changed files with 31 additions and 17 deletions

View file

@ -218,7 +218,10 @@ var ExportMenu = function(opts) {
var filename = "models__" + Window.location.hostname + "__" + x + "_" + y + "_" + z + "_" + s + "__.svo"; var filename = "models__" + Window.location.hostname + "__" + x + "_" + y + "_" + z + "_" + s + "__.svo";
filename = Window.save("Select where to save", filename, "*.svo") filename = Window.save("Select where to save", filename, "*.svo")
if (filename) { if (filename) {
Clipboard.exportModels(filename, x, y, z, s); var success = Clipboard.exportModels(filename, x, y, z, s);
if (!succcess) {
WIndow.alert("Export failed: no models found in selected area.");
}
} }
self.close(); self.close();
}; };
@ -431,16 +434,24 @@ var ModelImporter = function(opts) {
} }
} else { } else {
if (Window.confirm(("Would you like to import back to the source location?"))) { if (Window.confirm(("Would you like to import back to the source location?"))) {
Clipboard.importModels(filename); var success = Clipboard.importModels(filename);
Clipboard.pasteModels(x, y, z, 1); if (success) {
Clipboard.pasteModels(x, y, z, 1);
} else {
Window.alert("There was an error importing the model file.");
}
return; return;
} }
} }
} }
Clipboard.importModels(filename); var success = Clipboard.importModels(filename);
self._importing = true; if (success) {
self.setImportVisible(true); self._importing = true;
Overlays.editOverlay(importBoundaries, { size: s }); self.setImportVisible(true);
Overlays.editOverlay(importBoundaries, { size: s });
} else {
Window.alert("There was an error importing the model file.");
}
} }
} }
} }

View file

@ -1614,10 +1614,13 @@ void Application::importVoxels() {
emit importDone(); emit importDone();
} }
void Application::importModels(const QString& filename) { bool Application::importModels(const QString& filename) {
_modelClipboard.eraseAllOctreeElements(); _modelClipboard.eraseAllOctreeElements();
_modelClipboard.readFromSVOFile(filename.toLocal8Bit().constData()); bool success = _modelClipboard.readFromSVOFile(filename.toLocal8Bit().constData());
_modelClipboard.reaverageOctreeElements(); if (success) {
_modelClipboard.reaverageOctreeElements();
}
return success;
} }
void Application::pasteModels(float x, float y, float z) { void Application::pasteModels(float x, float y, float z) {

View file

@ -317,7 +317,7 @@ public slots:
void pasteModels(float x, float y, float z); void pasteModels(float x, float y, float z);
bool exportModels(const QString& filename, float x, float y, float z, float scale); bool exportModels(const QString& filename, float x, float y, float z, float scale);
void importModels(const QString& filename); bool importModels(const QString& filename);
void importVoxels(); // doesn't include source voxel because it goes to clipboard void importVoxels(); // doesn't include source voxel because it goes to clipboard
void cutVoxels(const VoxelDetail& sourceVoxel); void cutVoxels(const VoxelDetail& sourceVoxel);

View file

@ -102,12 +102,12 @@ void ClipboardScriptingInterface::nudgeVoxel(float x, float y, float z, float s,
} }
void ClipboardScriptingInterface::exportModels(const QString& filename, float x, float y, float z, float s) { bool ClipboardScriptingInterface::exportModels(const QString& filename, float x, float y, float z, float s) {
Application::getInstance()->exportModels(filename, x, y, z, s); return Application::getInstance()->exportModels(filename, x, y, z, s);
} }
void ClipboardScriptingInterface::importModels(const QString& filename) { bool ClipboardScriptingInterface::importModels(const QString& filename) {
Application::getInstance()->importModels(filename); return Application::getInstance()->importModels(filename);
} }
void ClipboardScriptingInterface::pasteModels(float x, float y, float z, float s) { void ClipboardScriptingInterface::pasteModels(float x, float y, float z, float s) {

View file

@ -43,8 +43,8 @@ public slots:
void nudgeVoxel(const VoxelDetail& sourceVoxel, const glm::vec3& nudgeVec); void nudgeVoxel(const VoxelDetail& sourceVoxel, const glm::vec3& nudgeVec);
void nudgeVoxel(float x, float y, float z, float s, const glm::vec3& nudgeVec); void nudgeVoxel(float x, float y, float z, float s, const glm::vec3& nudgeVec);
void importModels(const QString& filename); bool importModels(const QString& filename);
void exportModels(const QString& filename, float x, float y, float z, float s); bool exportModels(const QString& filename, float x, float y, float z, float s);
void pasteModels(float x, float y, float z, float s); void pasteModels(float x, float y, float z, float s);
}; };