Commit 68e8a121 authored by Jan Möbius's avatar Jan Möbius
Browse files

Merge branch 'fixOBJAssertion' into 'master'

Fix obj assertion

this should fix #33

See merge request !68
parents a32fba75 467f290e
Pipeline #886 passed with stage
......@@ -120,7 +120,7 @@ FileOBJPlugin::FileOBJPlugin()
//-----------------------------------------------------------------------------------------------------
void FileOBJPlugin::initializePlugin() {
void FileOBJPlugin::initializePlugin() {
}
//-----------------------------------------------------------------------------------------------------
......@@ -1742,26 +1742,17 @@ void FileOBJPlugin::checkTypes(QByteArray& _bufferedFile, QString _filename, OBJ
// If we do not have a gui, we will always use the last default
// If we need a gui and the triMeshHandling box is not generated (==0) we also use the last default
if ( OpenFlipper::Options::gui() && triMeshHandling_ != 0 ){
QMessageBox msgBox;
QPushButton *detectButton = msgBox.addButton(tr("Auto-Detect"), QMessageBox::ActionRole);
QPushButton *triButton = msgBox.addButton(tr("Open as triangle mesh"), QMessageBox::ActionRole);
QPushButton *polyButton = msgBox.addButton(tr("Open as poly mesh"), QMessageBox::ActionRole);
if ( OpenFlipper::Options::gui() && triMeshHandling_ != 0 ){
switch( triMeshHandling_->currentIndex() ){
case TYPEAUTODETECT : //Detect
break;
case TYPEASK: //ask
msgBox.setWindowTitle( tr("Mesh types in file") );
msgBox.setText( tr("You are about to open a file containing one or more mesh types. \n\n Which mesh type should be used?") );
msgBox.setDefaultButton( detectButton );
msgBox.exec();
if (msgBox.clickedButton() == triButton)
QMetaObject::invokeMethod(this,"handleTrimeshDialog",Qt::BlockingQueuedConnection);
if (trimeshOptions == OBJImporter::TRIMESH )
_importer.forceMeshType( OBJImporter::TRIMESH );
else if (msgBox.clickedButton() == polyButton)
else if (trimeshOptions == OBJImporter::POLYMESH)
_importer.forceMeshType( OBJImporter::POLYMESH );
break;
......@@ -1780,6 +1771,24 @@ void FileOBJPlugin::checkTypes(QByteArray& _bufferedFile, QString _filename, OBJ
}
void FileOBJPlugin::handleTrimeshDialog()
{
QMessageBox msgBox;
QPushButton *detectButton = msgBox.addButton(tr("Auto-Detect"), QMessageBox::ActionRole);
QPushButton *triButton = msgBox.addButton(tr("Open as triangle mesh"), QMessageBox::ActionRole);
QPushButton *polyButton = msgBox.addButton(tr("Open as poly mesh"), QMessageBox::ActionRole);
msgBox.setWindowTitle( tr("Mesh types in file") );
msgBox.setText( tr("You are about to open a file containing one or more mesh types. \n\n Which mesh type should be used?") );
msgBox.setDefaultButton( detectButton );
msgBox.exec();
if (msgBox.clickedButton() == triButton)
trimeshOptions = OBJImporter::TRIMESH ;
else if (msgBox.clickedButton() == polyButton)
trimeshOptions = OBJImporter::POLYMESH ;
}
//-----------------------------------------------------------------------------------------------------
int FileOBJPlugin::loadObject(QString _filename) {
......
......@@ -147,6 +147,8 @@ class FileOBJPlugin : public QObject, BaseInterface, FileInterface, LoadSaveInte
void slotHandleCheckBoxes(bool _checked);
void handleTrimeshDialog();
public :
FileOBJPlugin();
......@@ -251,6 +253,7 @@ class FileOBJPlugin : public QObject, BaseInterface, FileInterface, LoadSaveInte
QString textureIndexPropertyName_;
bool textureIndexPropFetched_;
std::map<int,QString> texIndexFileMap_;
OBJImporter::ObjectOptionsE trimeshOptions;
};
......
......@@ -532,19 +532,11 @@ bool FileOFFPlugin::readOFFFile(QString _filename, OFFImporter& _importer) {
case TYPEASK:
if( !OpenFlipper::Options::nogui() ) {
// Create message box
QMessageBox msgBox;
QPushButton *detectButton = msgBox.addButton(tr("Auto-Detect"), QMessageBox::ActionRole);
QPushButton *triButton = msgBox.addButton(tr("Open as triangle mesh"), QMessageBox::ActionRole);
QPushButton *polyButton = msgBox.addButton(tr("Open as poly mesh"), QMessageBox::ActionRole);
QMetaObject::invokeMethod(this,"handleTrimeshDialog",Qt::BlockingQueuedConnection);
msgBox.setWindowTitle( tr("Mesh types in file") );
msgBox.setText( tr("You are about to open a file containing one or more mesh types. \n\n Which mesh type should be used?") );
msgBox.setDefaultButton( detectButton );
msgBox.exec();
if (msgBox.clickedButton() == triButton)
if (trimeshOptions == OFFImporter::TRIMESH)
type = DATA_TRIANGLE_MESH;
else if (msgBox.clickedButton() == polyButton)
else if (trimeshOptions == OFFImporter::POLYMESH)
type = DATA_POLY_MESH;
else
type = _importer.isTriangleMesh() ? DATA_TRIANGLE_MESH : DATA_POLY_MESH;
......@@ -574,6 +566,24 @@ bool FileOFFPlugin::readOFFFile(QString _filename, OFFImporter& _importer) {
return _importer.isBinary() ? parseBinary(ifile, _importer, type, _filename) : parseASCII(ifile, _importer, type, _filename);
}
void FileOFFPlugin::handleTrimeshDialog()
{
QMessageBox msgBox;
QPushButton *detectButton = msgBox.addButton(tr("Auto-Detect"), QMessageBox::ActionRole);
QPushButton *triButton = msgBox.addButton(tr("Open as triangle mesh"), QMessageBox::ActionRole);
QPushButton *polyButton = msgBox.addButton(tr("Open as poly mesh"), QMessageBox::ActionRole);
msgBox.setWindowTitle( tr("Mesh types in file") );
msgBox.setText( tr("You are about to open a file containing one or more mesh types. \n\n Which mesh type should be used?") );
msgBox.setDefaultButton( detectButton );
msgBox.exec();
if (msgBox.clickedButton() == triButton)
trimeshOptions = OFFImporter::TRIMESH ;
else if (msgBox.clickedButton() == polyButton)
trimeshOptions = OFFImporter::POLYMESH ;
}
//-----------------------------------------------------------------------------------------------------
bool FileOFFPlugin::parseASCII(std::istream& _in, OFFImporter& _importer, DataType _type, QString& _objectName) {
......
......@@ -107,6 +107,8 @@ class FileOFFPlugin : public QObject, BaseInterface, FileInterface, LoadSaveInte
void initializePlugin();
/// Displays a dialog to ask how to load the mesh (triangle, polymesh , autodetect)
void handleTrimeshDialog();
/// Slot called when user wants to save the given Load options as default
void slotLoadDefault();
......@@ -267,6 +269,7 @@ class FileOFFPlugin : public QObject, BaseInterface, FileInterface, LoadSaveInte
bool forceTriangleMesh_;
bool forcePolyMesh_;
bool readColorComp_;
OFFImporter::ObjectOptionsE trimeshOptions;
};
#if defined(INCLUDE_TEMPLATES) && !defined(FILEOFFPLUGIN_C)
......
......@@ -187,18 +187,10 @@ int FileOMPlugin::loadObject(QString _filename) {
}
// Note: If in non-gui mode, we will never enter this case branch
QMessageBox msgBox;
QPushButton *detectButton = msgBox.addButton(tr("Auto-Detect"), QMessageBox::ActionRole);
// QPushButton *triButton = msgBox.addButton(tr("Open as triangle mesh"), QMessageBox::ActionRole);
QPushButton *polyButton = msgBox.addButton(tr("Open as poly mesh"), QMessageBox::ActionRole);
msgBox.setWindowTitle( tr("Mesh types in file") );
msgBox.setText( tr("You are about to open a file containing one or more mesh types. \n\n Which mesh type should be used?") );
msgBox.setDefaultButton( detectButton );
msgBox.exec();
if ((msgBox.clickedButton() == polyButton) ||
(msgBox.clickedButton() == detectButton && !triMesh)) {
QMetaObject::invokeMethod(this,"handleTrimeshDialog",Qt::BlockingQueuedConnection);
if ((trimeshOptions == TYPEPOLY) ||
(trimeshOptions == TYPEASK && !triMesh)) {
PolyMeshObject* object(0);
if(PluginFunctions::getObject( objectId, object )) {
......@@ -251,6 +243,26 @@ int FileOMPlugin::loadObject(QString _filename) {
return objectId;
};
void FileOMPlugin::handleTrimeshDialog()
{
QMessageBox msgBox;
QPushButton *detectButton = msgBox.addButton(tr("Auto-Detect"), QMessageBox::ActionRole);
QPushButton *triButton = msgBox.addButton(tr("Open as triangle mesh"), QMessageBox::ActionRole);
QPushButton *polyButton = msgBox.addButton(tr("Open as poly mesh"), QMessageBox::ActionRole);
msgBox.setWindowTitle( tr("Mesh types in file") );
msgBox.setText( tr("You are about to open a file containing one or more mesh types. \n\n Which mesh type should be used?") );
msgBox.setDefaultButton( detectButton );
msgBox.exec();
if (msgBox.clickedButton() == triButton)
trimeshOptions = TYPETRIANGLE ;
else if (msgBox.clickedButton() == polyButton)
trimeshOptions = TYPEPOLY ;
else
trimeshOptions = TYPEASK;
}
//-----------------------------------------------------------------------------------------------------
/// load a triangle-mesh with given filename
......
......@@ -98,7 +98,10 @@ class FileOMPlugin : public QObject, BaseInterface, FileInterface, LoadSaveInter
void noguiSupported( ) {} ;
void initializePlugin();
void initializePlugin();
/// Displays a dialog to ask how to load the mesh (triangle, polymesh , autodetect)
void handleTrimeshDialog();
/// Slot called when user wants to save the given Load options as default
void slotLoadDefault();
......@@ -166,6 +169,7 @@ class FileOMPlugin : public QObject, BaseInterface, FileInterface, LoadSaveInter
QCheckBox* loadFaceColor_;
QCheckBox* loadFaceNormal_;
QPushButton* loadDefaultButton_;
int trimeshOptions;
};
#endif //FILEOMPLUGIN_HH
......@@ -249,18 +249,9 @@ int FilePLYPlugin::loadObject(QString _filename) {
else if (triMeshControl == TYPEASK) {
// If Ask is selected -> show dialog
QMessageBox msgBox;
QPushButton *detectButton = msgBox.addButton(tr("Auto-Detect"), QMessageBox::ActionRole);
// QPushButton *triButton = msgBox.addButton(tr("Open as triangle mesh"), QMessageBox::ActionRole);
QPushButton *polyButton = msgBox.addButton(tr("Open as poly mesh"), QMessageBox::ActionRole);
msgBox.setWindowTitle( tr("Mesh types in file") );
msgBox.setText( tr("You are about to open a file containing one or more mesh types. \n\n Which mesh type should be used?") );
msgBox.setDefaultButton( detectButton );
msgBox.exec();
if ((msgBox.clickedButton() == polyButton) ||
(msgBox.clickedButton() == detectButton && !isTriMesh)) {
QMetaObject::invokeMethod(this,"handleTrimeshDialog",Qt::BlockingQueuedConnection);
if ((trimeshOptions == TYPEPOLY) ||
(trimeshOptions == TYPEASK && !isTriMesh)) {
PolyMeshObject* object(0);
if(PluginFunctions::getObject( objectId, object )) {
......@@ -313,6 +304,26 @@ int FilePLYPlugin::loadObject(QString _filename) {
return objectId;
};
void FilePLYPlugin::handleTrimeshDialog()
{
QMessageBox msgBox;
QPushButton *detectButton = msgBox.addButton(tr("Auto-Detect"), QMessageBox::ActionRole);
QPushButton *triButton = msgBox.addButton(tr("Open as triangle mesh"), QMessageBox::ActionRole);
QPushButton *polyButton = msgBox.addButton(tr("Open as poly mesh"), QMessageBox::ActionRole);
msgBox.setWindowTitle( tr("Mesh types in file") );
msgBox.setText( tr("You are about to open a file containing one or more mesh types. \n\n Which mesh type should be used?") );
msgBox.setDefaultButton( detectButton );
msgBox.exec();
if (msgBox.clickedButton() == triButton)
trimeshOptions = TYPETRIANGLE ;
else if (msgBox.clickedButton() == polyButton)
trimeshOptions = TYPEPOLY ;
else
trimeshOptions = TYPEASK;
}
//-----------------------------------------------------------------------------------------------------
/// load a triangle-mesh with given filename
......
......@@ -103,6 +103,9 @@ class FilePLYPlugin : public QObject, BaseInterface, FileInterface, LoadSaveInte
void initializePlugin();
/// Displays a dialog to ask how to load the mesh (triangle, polymesh , autodetect)
void handleTrimeshDialog();
/// Slot called when user wants to save the given Load options as default
void slotLoadDefault();
......@@ -172,6 +175,7 @@ class FilePLYPlugin : public QObject, BaseInterface, FileInterface, LoadSaveInte
QCheckBox* loadFaceNormal_;
QCheckBox* loadFaceColor_;
QPushButton* loadDefaultButton_;
int trimeshOptions;
};
#if defined(INCLUDE_TEMPLATES) && !defined(FILEPLYPLUGIN_C)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment