diff --git a/Polyhedron/demo/Polyhedron/Plugins/IO/VTK_io_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/IO/VTK_io_plugin.cpp index a658d343fe8..a42d02cd3d0 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/IO/VTK_io_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/IO/VTK_io_plugin.cpp @@ -61,9 +61,56 @@ #include #include #include +#include namespace CGAL{ + class ErrorObserverVtk : public vtkCommand + { + public: + ErrorObserverVtk() : + Error(false), + Warning(false), + ErrorMessage(""), + WarningMessage("") {} + static ErrorObserverVtk *New() { return new ErrorObserverVtk; } + + bool GetError() const { return this->Error; } + bool GetWarning() const { return this->Warning; } + std::string GetErrorMessage() { return ErrorMessage; } + std::string GetWarningMessage() { return WarningMessage; } + + void Clear() + { + this->Error = false; + this->Warning = false; + this->ErrorMessage = ""; + this->WarningMessage = ""; + } + virtual void Execute(vtkObject *vtkNotUsed(caller), + unsigned long event, + void *calldata) + { + switch (event) + { + case vtkCommand::ErrorEvent: + ErrorMessage = static_cast(calldata); + this->Error = true; + break; + case vtkCommand::WarningEvent: + WarningMessage = static_cast(calldata); + this->Warning = true; + break; + } + } + + private: + bool Error; + bool Warning; + std::string ErrorMessage; + std::string WarningMessage; + }; + template bool vtkPolyData_to_polygon_mesh(vtkPolyData* poly_data, TM& tmesh, @@ -238,13 +285,20 @@ public: && fileinfo.suffix().toLower() != "vtp") return 0; + std::string input_filename = fileinfo.absoluteFilePath().toStdString(); + Polyhedron poly; boost::unordered_map vmap; boost::unordered_map fmap; // Try to read .vtk in a polyhedron - vtkSmartPointer data; - std::string input_filename = fileinfo.absoluteFilePath().toStdString(); + vtkSmartPointer data + = vtkSmartPointer::New(); + vtkSmartPointer errorObserver = + vtkSmartPointer::New(); + + data->AddObserver(vtkCommand::ErrorEvent, errorObserver); + data->AddObserver(vtkCommand::WarningEvent, errorObserver); char last_char = input_filename[input_filename.size() - 1]; if (last_char != 'p' && last_char != 'P') @@ -263,6 +317,27 @@ public: reader->Update(); data = reader->GetOutput(); } + if (errorObserver->GetError()) + { + QMessageBox msgBox; + msgBox.setText("This type of data can't be opened"); + msgBox.setInformativeText(QString("VTK error message :\n") + .append(QString(errorObserver->GetErrorMessage().data()))); + msgBox.setStandardButtons(QMessageBox::Ok); + msgBox.setIcon(QMessageBox::Critical); + msgBox.exec(); + return new Scene_polyhedron_item(); + } + if (errorObserver->GetWarning()) + { + QMessageBox msgBox; + msgBox.setText("This file generates a warning"); + msgBox.setInformativeText(QString("VTK warning message :\n") + .append(QString(errorObserver->GetWarningMessage().data()))); + msgBox.setStandardButtons(QMessageBox::Ok); + msgBox.setIcon(QMessageBox::Warning); + msgBox.exec(); + } if (CGAL::vtkPolyData_to_polygon_mesh(data, poly, vmap, fmap)) {