其他分享
首页 > 其他分享> > load ifc

load ifc

作者:互联网

 

void TabReadWrite::slotLoadRecentIfcFileClicked()
{
    QPushButton* btn_load = (QPushButton*)sender();
    if( !btn_load )
    {
        return;
    }
    
    int row = m_combo_recent_files->currentIndex();
    if( row < 0 || row >= m_combo_recent_files->count() )
    {
        return;
    }
    
    m_io_widget->setDisabled( true );
    if( row < m_recent_files.size() )
    {
        QString file_name = m_recent_files.at( row );
        slotLoadIfcFile( file_name );
    }
    m_io_widget->setDisabled(false);
}

 

void TabReadWrite::slotLoadIfcFile( QString& path_in )
{
    // redirect message callbacks
    m_system->getGeometryConverter()->setMessageCallBack( this, &TabReadWrite::messageTarget );
    m_system->getModelReader()->setMessageCallBack( this, &TabReadWrite::messageTarget );
    m_system->getModelWriter()->setMessageCallBack( this, &TabReadWrite::messageTarget );
    

    slotTxtOut( QString( "loading file: " ) + path_in );
    QApplication::processEvents();
    clock_t millisecs = clock();
    m_system->notifyModelCleared();
    m_txt_out->clear();
    QSettings settings(QSettings::UserScope, QLatin1String("IfcPlusPlus"));

    if( !QFile::exists(path_in) )
    {
        slotTxtOutError( QString("file ") + path_in + QString(" does not exist\n") );

        // remove all non-existing files from recent files combo
        for( int i=0; i<m_recent_files.size(); )
        {
            const QString& recent_file = m_recent_files[i];
            if( !QFile::exists(recent_file) )
            {
                m_recent_files.takeAt( i );
            }
            else
            {
                ++i;
            }
        }
        settings.setValue("recentFiles",m_recent_files );
        updateRecentFilesCombo();
        return;
    }
    else
    {
        // move to top of recent files list
        int i = m_recent_files.indexOf( path_in );
        if( i > 0 )
        {
            QString current_path = m_recent_files.takeAt( i );
            m_recent_files.insert( 0, current_path );
            m_recent_files.removeDuplicates();
            settings.setValue("recentFiles",m_recent_files );
            updateRecentFilesCombo();
        }
        else
        {
            m_recent_files.insert( 0, path_in );
            m_recent_files.removeDuplicates();
            settings.setValue("recentFiles",m_recent_files );
            updateRecentFilesCombo();
        }
    }

    try
    {
        shared_ptr<LoadIfcFileCommand> cmd_load( new LoadIfcFileCommand( m_system ) );
        std::wstring path_str = path_in.toStdWString();
        cmd_load->setFilePath( path_str );
        cmd_load->doCmd();
    }
    catch( OutOfMemoryException& e)
    {
        slotTxtOutError( e.what() );
    }
    catch( BuildingException& e )
    {
        slotTxtOutError( e.what() );
    }
    catch(std::exception& e)
    {
        slotTxtOutError( e.what() );
    }

    m_viewer->update();
    
    osgViewer::View* main_view = m_viewer->getMainView();
    if( main_view )
    {
        osgGA::CameraManipulator* camera_manip = main_view->getCameraManipulator();
        OrbitCameraManipulator* orbit_manip = dynamic_cast<OrbitCameraManipulator*>( camera_manip );
        if( orbit_manip )
        {
            osg::BoundingSphere bs = m_system->getModelNode()->computeBound();
            orbit_manip->zoomToBoundingSphere( bs );
        }
    }

    clock_t time_diff = clock() - millisecs;
    int num_entities = m_system->getIfcModel()->getMapIfcEntities().size();
    slotTxtOut( tr("File loaded: ") + QString::number(num_entities) + " entities in " + QString::number( round(time_diff*0.1)*0.01 ) + " sec."  );

    m_system->notifyModelLoadingDone();
    slotProgressValue( 1.0, "" );
}

 

标签:load,files,system,QString,ifc,path,recent
来源: https://www.cnblogs.com/herd/p/11242400.html