FileOM.cc 24 KB
Newer Older
Jan Möbius's avatar
 
Jan Möbius committed
1
/*===========================================================================*\
Jan Möbius's avatar
Jan Möbius committed
2 3
*                                                                            *
*                              OpenFlipper                                   *
Jan Möbius's avatar
Jan Möbius committed
4
*      Copyright (C) 2001-2011 by Computer Graphics Group, RWTH Aachen       *
Jan Möbius's avatar
Jan Möbius committed
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
*                           www.openflipper.org                              *
*                                                                            *
*--------------------------------------------------------------------------- *
*  This file is part of OpenFlipper.                                         *
*                                                                            *
*  OpenFlipper is free software: you can redistribute it and/or modify       *
*  it under the terms of the GNU Lesser General Public License as            *
*  published by the Free Software Foundation, either version 3 of            *
*  the License, or (at your option) any later version with the               *
*  following exceptions:                                                     *
*                                                                            *
*  If other files instantiate templates or use macros                        *
*  or inline functions from this file, or you compile this file and          *
*  link it with other files to produce an executable, this file does         *
*  not by itself cause the resulting executable to be covered by the         *
*  GNU Lesser General Public License. This exception does not however        *
*  invalidate any other reasons why the executable file might be             *
*  covered by the GNU Lesser General Public License.                         *
*                                                                            *
*  OpenFlipper is distributed in the hope that it will be useful,            *
*  but WITHOUT ANY WARRANTY; without even the implied warranty of            *
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *
*  GNU Lesser General Public License for more details.                       *
*                                                                            *
*  You should have received a copy of the GNU LesserGeneral Public           *
*  License along with OpenFlipper. If not,                                   *
*  see <http://www.gnu.org/licenses/>.                                       *
*                                                                            *
Jan Möbius's avatar
 
Jan Möbius committed
33 34 35
\*===========================================================================*/

/*===========================================================================*\
Jan Möbius's avatar
Jan Möbius committed
36 37 38 39 40
*                                                                            *
*   $Revision$                                                       *
*   $LastChangedBy$                                                *
*   $Date$                     *
*                                                                            *
Jan Möbius's avatar
 
Jan Möbius committed
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
\*===========================================================================*/

#include <QtGui>
#include <QFileInfo>
#include <QSettings>
#include <QPushButton>

#include "FileOM.hh"

#include <iostream>
#include <ACG/GL/GLState.hh>

#include "OpenFlipper/BasePlugin/PluginFunctions.hh"
#include "OpenFlipper/common/GlobalOptions.hh"

#include <OpenMesh/Core/IO/IOManager.hh>

#include <OpenFlipper/ACGHelper/DrawModeConverter.hh>

60 61 62 63 64 65
// Defines for the type handling drop down box
#define TYPEAUTODETECT 0
#define TYPEASK        1
#define TYPEPOLY       2
#define TYPETRIANGLE   3

Jan Möbius's avatar
 
Jan Möbius committed
66
/// Constructor
Jan Möbius's avatar
Jan Möbius committed
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
FileOMPlugin::FileOMPlugin() :
        loadOptions_(0),
        saveOptions_(0),
        saveBinary_(0),
        saveVertexNormal_(0),
        saveVertexTexCoord_(0),
        saveVertexColor_(0),
        saveFaceColor_(0),
        saveFaceNormal_(0),
        saveDefaultButton_(0),
        triMeshHandling_(0),
        loadVertexNormal_(0),
        loadVertexTexCoord_(0),
        loadVertexColor_(0),
        loadFaceColor_(0),
        loadFaceNormal_(0),
        loadDefaultButton_(0)

{
Jan Möbius's avatar
 
Jan Möbius committed
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
}

//-----------------------------------------------------------------------------------------------------

void FileOMPlugin::initializePlugin() {
}

//-----------------------------------------------------------------------------------------------------

QString FileOMPlugin::getLoadFilters() {
    return QString( tr("OpenMesh Format files ( *.om )") );
};

//-----------------------------------------------------------------------------------------------------

QString FileOMPlugin::getSaveFilters() {
    return QString( tr("OpenMesh Format files ( *.om )") );
};

//-----------------------------------------------------------------------------------------------------

DataType  FileOMPlugin::supportedType() {
    DataType type = DATA_POLY_MESH | DATA_TRIANGLE_MESH;
    return type;
}

//-----------------------------------------------------------------------------------------------------

int FileOMPlugin::loadObject(QString _filename) {

116
    int triMeshControl = TYPEAUTODETECT; // 0 == Auto-Detect
Jan Möbius's avatar
 
Jan Möbius committed
117
    
118 119
    if ( OpenFlipper::Options::gui() ){
        if ( triMeshHandling_ != 0 ){
120
          triMeshControl = triMeshHandling_->currentIndex();
Jan Möbius's avatar
 
Jan Möbius committed
121
        } else {
122
          triMeshControl = TYPEAUTODETECT;
Jan Möbius's avatar
 
Jan Möbius committed
123
        }
124 125 126 127
    }
    
    int objectId = -1;
    
128
    if(triMeshControl == TYPEAUTODETECT) {
129 130
        // If Auto-Detect is selected (triMeshControl == 0)
        objectId = loadPolyMeshObject(_filename);
Jan Möbius's avatar
 
Jan Möbius committed
131
        
132 133
        PolyMeshObject *object = 0;
        if(!PluginFunctions::getObject(objectId, object))
Jan Möbius's avatar
 
Jan Möbius committed
134
            return -1;
135 136
        
        for ( PolyMesh::FaceIter f_it = object->mesh()->faces_begin(); f_it != object->mesh()->faces_end() ; ++f_it) {
Jan Möbius's avatar
 
Jan Möbius committed
137
            
138 139 140 141
            // Count number of vertices for the current face
            uint count = 0;
            for ( PolyMesh::FaceVertexIter fv_it( *(object->mesh()),f_it); fv_it; ++fv_it )
                ++count;
Jan Möbius's avatar
 
Jan Möbius committed
142
            
143 144
            // Check if it is a triangle. If not, this is really a poly mesh
            if ( count != 3 ) {
145
                
146 147 148 149 150 151
                PolyMeshObject* object(0);
                if(PluginFunctions::getObject( objectId, object )) {
                    
                    object->show();
                    emit openedFile( objectId );
                }
152
                
153
                return objectId;
Jan Möbius's avatar
 
Jan Möbius committed
154 155 156
            }
        }
        
157 158
    } else if (triMeshControl == TYPEASK ) {
      
159 160
        // If Ask is selected -> show dialog
        objectId = loadPolyMeshObject(_filename);
Jan Möbius's avatar
 
Jan Möbius committed
161
        
162 163
        bool triMesh = true;
        
164 165 166
        PolyMeshObject *object = 0;
        if(!PluginFunctions::getObject(objectId, object))
            return -1;
Jan Möbius's avatar
 
Jan Möbius committed
167
        
168 169 170 171 172 173 174 175
        for ( PolyMesh::FaceIter f_it = object->mesh()->faces_begin(); f_it != object->mesh()->faces_end() ; ++f_it) {
            
            // Count number of vertices for the current face
            uint count = 0;
            for ( PolyMesh::FaceVertexIter fv_it( *(object->mesh()),f_it); fv_it; ++fv_it )
                ++count;
            
            // Check if it is a triangle. If not, this is really a poly mesh
176 177 178
            if ( count != 3 ) {
                triMesh = false;
                break;
179
            }
180 181
            
            if(triMesh == false) break;
182
        }
Jan Möbius's avatar
 
Jan Möbius committed
183
        
184
        // Note: If in non-gui mode, we will never enter this case branch
185 186
        QMessageBox msgBox;
        QPushButton *detectButton = msgBox.addButton(tr("Auto-Detect"), QMessageBox::ActionRole);
Dirk Wilden's avatar
Dirk Wilden committed
187
//         QPushButton *triButton    = msgBox.addButton(tr("Open as triangle mesh"), QMessageBox::ActionRole);
188 189 190 191 192 193 194 195 196
        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)) {
197
            
198 199
            PolyMeshObject* object(0);
            if(PluginFunctions::getObject( objectId, object )) {
200
            
201 202 203
                object->show();
                emit openedFile( objectId );
            }
204 205 206
            return objectId;
        }
                                                                     
207
    } else if (triMeshControl == TYPEPOLY) {
208
        // If always open as PolyMesh is selected
Jan Möbius's avatar
 
Jan Möbius committed
209
        
210 211
        objectId = loadPolyMeshObject(_filename);
        
212 213 214 215 216 217
        PolyMeshObject* object(0);
        if(PluginFunctions::getObject( objectId, object )) {
            
            object->show();
            emit openedFile( objectId );
        }
218 219
        
        return objectId;
Jan Möbius's avatar
 
Jan Möbius committed
220
    } else {
221 222
        // If always open as TriMesh is selected
        
223 224
        objectId = loadTriMeshObject(_filename);
        
225 226 227 228 229 230
        TriMeshObject* object(0);
        if(PluginFunctions::getObject( objectId, object )) {
            
            object->show();
            emit openedFile( objectId );
        }
231 232
        
        return objectId;
Jan Möbius's avatar
 
Jan Möbius committed
233
    }
234 235 236
    
    // Load object as triangle mesh
    if(objectId != -1) emit deleteObject(objectId);
237 238 239
    
    objectId = loadTriMeshObject(_filename);
    
240 241 242 243 244 245
    TriMeshObject* object(0);
    if(PluginFunctions::getObject( objectId, object )) {
        
        object->show();
        emit openedFile( objectId );
    }
246 247
    
    return objectId;
Jan Möbius's avatar
 
Jan Möbius committed
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264
};

//-----------------------------------------------------------------------------------------------------

/// load a triangle-mesh with given filename
int FileOMPlugin::loadTriMeshObject(QString _filename){

    int id = -1;
    emit addEmptyObject(DATA_TRIANGLE_MESH, id);
    
    TriMeshObject* object(0);
    if(PluginFunctions::getObject( id, object)) {
        
        if ( PluginFunctions::objectCount() == 1 )
            object->target(true);
        
        object->setFromFileName(_filename);
265
        object->setName(object->filename());
Jan Möbius's avatar
 
Jan Möbius committed
266 267 268 269 270 271
        
        std::string filename = std::string( _filename.toUtf8() );
        
        //set options
        OpenMesh::IO::Options opt = OpenMesh::IO::Options::Default;
        
272
        if ( !OpenFlipper::Options::sceneGraphUpdatesBlocked() &&
Jan Möbius's avatar
 
Jan Möbius committed
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291
            !OpenFlipper::Options::loadingRecentFile() && loadOptions_ != 0){
            
            if (loadVertexNormal_->isChecked())
                opt += OpenMesh::IO::Options::VertexNormal;
            
            if (loadVertexTexCoord_->isChecked())
                opt += OpenMesh::IO::Options::VertexTexCoord;
            
            if (loadVertexColor_->isChecked())
                opt += OpenMesh::IO::Options::VertexColor;
            
            if (loadFaceColor_->isChecked())
                opt += OpenMesh::IO::Options::FaceColor;
            
            if (loadFaceNormal_->isChecked())
                opt += OpenMesh::IO::Options::FaceNormal;
            
        } else {
            
Jan Möbius's avatar
Jan Möbius committed
292
            // Let OpenMesh try to read everything it can
Jan Möbius's avatar
 
Jan Möbius committed
293 294 295 296 297 298 299 300
            opt += OpenMesh::IO::Options::VertexNormal;
            opt += OpenMesh::IO::Options::VertexTexCoord;
            opt += OpenMesh::IO::Options::VertexColor;
            opt += OpenMesh::IO::Options::FaceColor;
            opt += OpenMesh::IO::Options::FaceNormal;
            
        }
        
301 302 303 304 305
        /// \todo only request if needed
        object->mesh()->request_vertex_texcoords2D();
        object->mesh()->request_halfedge_texcoords2D();
        object->mesh()->request_face_texture_index();
        
Jan Möbius's avatar
 
Jan Möbius committed
306 307 308 309 310 311 312 313 314 315 316 317 318
        // load file
        bool ok = OpenMesh::IO::read_mesh( (*object->mesh()) , filename, opt );
        if (!ok)
        {
            std::cerr << "Plugin FileOM : Read error for Triangle Mesh\n";
            emit deleteObject( object->id() );
            return -1;
        }
        
        object->mesh()->update_normals();
        
        object->update();
        
319 320
        backupTextureCoordinates(*(object->mesh()));

Jan Möbius's avatar
 
Jan Möbius committed
321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343
        return object->id();
        
    } else {
        emit log(LOGERR,"Error : Could not create new triangle mesh object.");
        return -1;
    }
}

//-----------------------------------------------------------------------------------------------------

/// load a poly-mesh with given filename
int FileOMPlugin::loadPolyMeshObject(QString _filename){

    int id = -1;
    emit addEmptyObject(DATA_POLY_MESH, id);
    
    PolyMeshObject* object(0);
    if(PluginFunctions::getObject( id, object)) {
        
        if (PluginFunctions::objectCount() == 1 )
            object->target(true);
        
        object->setFromFileName(_filename);
344
        object->setName(object->filename());
Jan Möbius's avatar
 
Jan Möbius committed
345 346 347 348 349 350
        
        std::string filename = std::string( _filename.toUtf8() );
        
        //set options
        OpenMesh::IO::Options opt = OpenMesh::IO::Options::Default;
        
351
        if ( !OpenFlipper::Options::sceneGraphUpdatesBlocked() &&
Jan Möbius's avatar
 
Jan Möbius committed
352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378
            !OpenFlipper::Options::loadingRecentFile() && loadOptions_ != 0){
            
            if (loadVertexNormal_->isChecked())
                opt += OpenMesh::IO::Options::VertexNormal;
            
            if (loadVertexTexCoord_->isChecked())
                opt += OpenMesh::IO::Options::VertexTexCoord;
            
            if (loadVertexColor_->isChecked())
                opt += OpenMesh::IO::Options::VertexColor;
            
            if (loadFaceColor_->isChecked())
                opt += OpenMesh::IO::Options::FaceColor;
            
            if (loadFaceNormal_->isChecked())
                opt += OpenMesh::IO::Options::FaceNormal;
            
        } else {
            
            // Let openmesh try to read everything it can
            opt += OpenMesh::IO::Options::VertexNormal;
            opt += OpenMesh::IO::Options::VertexTexCoord;
            opt += OpenMesh::IO::Options::VertexColor;
            opt += OpenMesh::IO::Options::FaceColor;
            opt += OpenMesh::IO::Options::FaceNormal;
            
        }
379 380 381 382 383
        
        /// \todo only request if needed
        object->mesh()->request_vertex_texcoords2D();
        object->mesh()->request_halfedge_texcoords2D();
        object->mesh()->request_face_texture_index();
Jan Möbius's avatar
 
Jan Möbius committed
384 385 386 387 388 389 390 391 392 393 394 395 396 397 398
        
        // load file
        bool ok = OpenMesh::IO::read_mesh( (*object->mesh()) , filename, opt );
        if (!ok)
        {
            std::cerr << "Plugin FileOM : Read error for Poly Mesh\n";
            emit deleteObject( object->id() );
            return -1;
            
        }
        
        object->mesh()->update_normals();
        
        object->update();
        
399 400
        backupTextureCoordinates(*(object->mesh()));

Jan Möbius's avatar
 
Jan Möbius committed
401 402 403 404 405 406 407 408 409 410
        return object->id();
        
    } else {
        emit log(LOGERR,"Error : Could not create new poly mesh object.");
        return -1;
    }
}

//-----------------------------------------------------------------------------------------------------

411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440
template <class MeshT>
void FileOMPlugin::backupTextureCoordinates(MeshT& _mesh) {

    // Create a backup of the original per Vertex texture Coordinates
    if (_mesh.has_vertex_texcoords2D()) {

      OpenMesh::VPropHandleT< typename MeshT::TexCoord2D > oldVertexCoords;
      if (!_mesh.get_property_handle(oldVertexCoords, "Original Per Vertex Texture Coords"))
        _mesh.add_property(oldVertexCoords, "Original Per Vertex Texture Coords");

      for (typename MeshT::VertexIter v_it = _mesh.vertices_begin(); v_it != _mesh.vertices_end(); ++v_it)
        _mesh.property(oldVertexCoords, v_it) =  _mesh.texcoord2D(v_it);

    }

    // Create a backup of the original per Face texture Coordinates
    if (_mesh.has_halfedge_texcoords2D()) {

      OpenMesh::HPropHandleT< typename MeshT::TexCoord2D > oldHalfedgeCoords;
      if (!_mesh.get_property_handle(oldHalfedgeCoords,"Original Per Face Texture Coords"))
        _mesh.add_property(oldHalfedgeCoords,"Original Per Face Texture Coords");

      for (typename MeshT::HalfedgeIter he_it = _mesh.halfedges_begin(); he_it != _mesh.halfedges_end(); ++he_it)
        _mesh.property(oldHalfedgeCoords, he_it) =  _mesh.texcoord2D(he_it);

    }
}

//-----------------------------------------------------------------------------------------------------

Jan Möbius's avatar
 
Jan Möbius committed
441 442 443 444 445 446 447 448 449
bool FileOMPlugin::saveObject(int _id, QString _filename)
{
    BaseObjectData* object;
    PluginFunctions::getObject(_id,object);
    
    std::string filename = std::string( _filename.toUtf8() );
    
    if ( object->dataType( DATA_POLY_MESH ) ) {
        
450
        object->setFromFileName(_filename);
451
        object->setName(object->filename());
Jan Möbius's avatar
 
Jan Möbius committed
452 453 454 455
        
        PolyMeshObject* polyObj = dynamic_cast<PolyMeshObject* >( object );
        
        if (OpenMesh::IO::write_mesh(*polyObj->mesh(), filename.c_str()) ){
456
            emit log(LOGINFO, tr("Saved object to ") + _filename );
Jan Möbius's avatar
 
Jan Möbius committed
457 458
            return true;
        }else{
459
            emit log(LOGERR, tr("Unable to save ") + _filename);
Jan Möbius's avatar
 
Jan Möbius committed
460 461 462 463
            return false;
        }
    } else if ( object->dataType( DATA_TRIANGLE_MESH ) ) {
        
464
        object->setFromFileName(_filename);
465
        object->setName(object->filename());
Jan Möbius's avatar
 
Jan Möbius committed
466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493
        
        TriMeshObject* triObj = dynamic_cast<TriMeshObject* >( object );
        
        OpenMesh::IO::Options opt = OpenMesh::IO::Options::Default;
        
        if ( !OpenFlipper::Options::savingSettings() && saveOptions_ != 0){
            
            if (saveBinary_->isChecked())
                opt += OpenMesh::IO::Options::Binary;
            
            if (saveVertexNormal_->isChecked())
                opt += OpenMesh::IO::Options::VertexNormal;
            
            if (saveVertexTexCoord_->isChecked())
                opt += OpenMesh::IO::Options::VertexTexCoord;
            
            if (saveVertexColor_->isChecked())
                opt += OpenMesh::IO::Options::VertexColor;
            
            if (saveFaceColor_->isChecked())
                opt += OpenMesh::IO::Options::FaceColor;
            
            if (saveFaceNormal_->isChecked())
                opt += OpenMesh::IO::Options::FaceNormal;
            
        }
        
        if (OpenMesh::IO::write_mesh(*triObj->mesh(), filename.c_str(),opt) ) {
494
            emit log(LOGINFO, tr("Saved object to ") + _filename );
Jan Möbius's avatar
 
Jan Möbius committed
495 496
            return true;
        } else {
497
            emit log(LOGERR, tr("Unable to save ") + _filename );
Jan Möbius's avatar
 
Jan Möbius committed
498 499 500 501 502 503 504 505 506 507
            return false;
        }
    } else {
        emit log(LOGERR, tr("Unable to save (object is not a compatible mesh type)"));
        return false;
    }
}

//-----------------------------------------------------------------------------------------------------

Dirk Wilden's avatar
Dirk Wilden committed
508
QWidget* FileOMPlugin::saveOptionsWidget(QString /*_currentFilter*/) {
Jan Möbius's avatar
 
Jan Möbius committed
509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565
    
    if (saveOptions_ == 0){
        //generate widget
        saveOptions_ = new QWidget();
        QVBoxLayout* layout = new QVBoxLayout();
        layout->setAlignment(Qt::AlignTop);
        
        saveBinary_ = new QCheckBox("Save Binary");
        layout->addWidget(saveBinary_);
        
        saveVertexNormal_ = new QCheckBox("Save Vertex Normals");
        layout->addWidget(saveVertexNormal_);
        
        saveVertexTexCoord_ = new QCheckBox("Save Vertex TexCoords");
        layout->addWidget(saveVertexTexCoord_);
        
        saveVertexColor_ = new QCheckBox("Save Vertex Colors");
        layout->addWidget(saveVertexColor_);
        
        saveFaceColor_ = new QCheckBox("Save Face Colors");
        layout->addWidget(saveFaceColor_);
        
        saveFaceNormal_ = new QCheckBox("Save Face Normals");
        layout->addWidget(saveFaceNormal_);
      
        saveDefaultButton_ = new QPushButton("Make Default");
        layout->addWidget(saveDefaultButton_);       
        
        saveOptions_->setLayout(layout);
        
        connect(saveDefaultButton_, SIGNAL(clicked()), this, SLOT(slotSaveDefault()));
        
        saveBinary_->setChecked( OpenFlipperSettings().value("FileOM/Save/Binary",true).toBool() );
        saveVertexNormal_->setChecked( OpenFlipperSettings().value("FileOM/Save/Normals",true).toBool() );
        saveVertexTexCoord_->setChecked( OpenFlipperSettings().value("FileOM/Save/TexCoords",true).toBool() );
        saveVertexColor_->setChecked( OpenFlipperSettings().value("FileOM/Save/VertexColor",true).toBool() );
        saveFaceColor_->setChecked( OpenFlipperSettings().value("FileOM/Save/FaceColor",true).toBool() );
        saveFaceNormal_->setChecked( OpenFlipperSettings().value("FileOM/Save/FaceNormal",true).toBool() );

    } 
    
    return saveOptions_;
}

//-----------------------------------------------------------------------------------------------------

QWidget* FileOMPlugin::loadOptionsWidget(QString /*_currentFilter*/) {
    
    if (loadOptions_ == 0){
        //generate widget
        loadOptions_ = new QWidget();
        QVBoxLayout* layout = new QVBoxLayout();
        layout->setAlignment(Qt::AlignTop);
        
        QLabel* label = new QLabel(tr("If PolyMesh is a Triangle Mesh:"));
        
        layout->addWidget(label);
566
                
Jan Möbius's avatar
 
Jan Möbius committed
567
        triMeshHandling_ = new QComboBox();
568
        triMeshHandling_->addItem( tr("Auto-Detect") );
Jan Möbius's avatar
 
Jan Möbius committed
569
        triMeshHandling_->addItem( tr("Ask") );
570 571
        triMeshHandling_->addItem( tr("Always open as PolyMesh") );
        triMeshHandling_->addItem( tr("Always open as TriangleMesh") );
Jan Möbius's avatar
 
Jan Möbius committed
572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597
        
        layout->addWidget(triMeshHandling_);
        
        loadVertexNormal_ = new QCheckBox("Load Vertex Normals");
        layout->addWidget(loadVertexNormal_);
        
        loadVertexTexCoord_ = new QCheckBox("Load Vertex TexCoords");
        layout->addWidget(loadVertexTexCoord_);
                
        loadVertexColor_ = new QCheckBox("Load Vertex Colors");
        layout->addWidget(loadVertexColor_);
        
        loadFaceColor_ = new QCheckBox("Load Face Colors");
        layout->addWidget(loadFaceColor_);
        
        loadFaceNormal_ = new QCheckBox("Load Face Normals");
        layout->addWidget(loadFaceNormal_);

        loadDefaultButton_ = new QPushButton("Make Default");
        layout->addWidget(loadDefaultButton_);
        
        loadOptions_->setLayout(layout);
        
        connect(loadDefaultButton_, SIGNAL(clicked()), this, SLOT(slotLoadDefault()));
        
        
598
        triMeshHandling_->setCurrentIndex(OpenFlipperSettings().value("FileOM/Load/TriMeshHandling",TYPEAUTODETECT).toInt() );
Jan Möbius's avatar
 
Jan Möbius committed
599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619
        
        loadVertexNormal_->setChecked( OpenFlipperSettings().value("FileOM/Load/Normals",true).toBool()  );
        loadVertexTexCoord_->setChecked( OpenFlipperSettings().value("FileOM/Load/TexCoords",true).toBool()  );
        loadVertexColor_->setChecked( OpenFlipperSettings().value("FileOM/Load/VertexColor",true).toBool() );
        loadFaceColor_->setChecked( OpenFlipperSettings().value("FileOM/Load/FaceColor",true).toBool()  );
        loadFaceColor_->setChecked( OpenFlipperSettings().value("FileOM/Load/FaceNormal",true).toBool()  );
        
    }
    
    return loadOptions_;
}

void FileOMPlugin::slotLoadDefault() {
    
    OpenFlipperSettings().setValue( "FileOM/Load/Normals",     loadVertexNormal_->isChecked()  );
    OpenFlipperSettings().setValue( "FileOM/Load/TexCoords",   loadVertexTexCoord_->isChecked()  );
    OpenFlipperSettings().setValue( "FileOM/Load/VertexColor", loadVertexColor_->isChecked()  );
    OpenFlipperSettings().setValue( "FileOM/Load/FaceColor",   loadFaceColor_->isChecked()  );
    OpenFlipperSettings().setValue( "FileOM/Load/FaceNormal",   loadFaceNormal_->isChecked()  );

    OpenFlipperSettings().setValue( "FileOM/Load/TriMeshHandling", triMeshHandling_->currentIndex() );
Jan Möbius's avatar
Jan Möbius committed
620 621
    
    OpenFlipperSettings().setValue( "Core/File/UseLoadDefaults", true );
Jan Möbius's avatar
 
Jan Möbius committed
622 623 624 625 626 627 628 629 630 631 632 633 634
}


void FileOMPlugin::slotSaveDefault() {
    
    OpenFlipperSettings().setValue( "FileOM/Save/Binary",      saveBinary_->isChecked()  );
    OpenFlipperSettings().setValue( "FileOM/Save/Normals",     saveVertexNormal_->isChecked()  );
    OpenFlipperSettings().setValue( "FileOM/Save/TexCoords",   saveVertexTexCoord_->isChecked()  );
    OpenFlipperSettings().setValue( "FileOM/Save/VertexColor", saveVertexColor_->isChecked()  );
    OpenFlipperSettings().setValue( "FileOM/Save/FaceColor",   saveFaceColor_->isChecked()  );
    OpenFlipperSettings().setValue( "FileOM/Save/FaceNormal",   saveFaceNormal_->isChecked()  );
}

Jan Möbius's avatar
Jan Möbius committed
635
Q_EXPORT_PLUGIN2( fileomplugin , FileOMPlugin );