Esempio n. 1
0
/** Load a CSV with *.ply format **/
void Mesh::load(const std::string path)
{

  // Create the reader
  CsvReader csvReader(path);

  // Clear previous data
  list_vertex_.clear();
  list_triangles_.clear();

  // Read from .ply file
  csvReader.readPLY(list_vertex_, list_triangles_);

  // Update mesh attributes
  num_vertexs_ = (int)list_vertex_.size();
  num_triangles_ = (int)list_triangles_.size();

}
Esempio n. 2
0
int KEduVocDocument::open( const KUrl& url )
{
    // save csv delimiter to preserve it in case this is a csv document
    QString csv = d->m_csvDelimiter;
    // clear all other properties
    d->init();
    if ( !url.isEmpty() ) {
        d->m_url = url;
    }
    d->m_csvDelimiter = csv;

    bool read = false;
    QString errorMessage = i18n( "<qt>Cannot open file<br /><b>%1</b></qt>", url.path() );
    QString temporaryFile;
    if ( KIO::NetAccess::download( url, temporaryFile, 0 ) ) {
        QIODevice * f = KFilterDev::deviceForFile( temporaryFile );

        if ( !f->open( QIODevice::ReadOnly ) ) {
            kError() << errorMessage;
            delete f;
            return FileCannotRead;
        }

        FileType ft = detectFileType( temporaryFile );

        switch ( ft ) {
            case Kvtml: {
                kDebug(1100) << "Reading KVTML document...";
                KEduVocKvtml2Reader kvtmlReader( f );
                read = kvtmlReader.readDoc( this );
                if ( !read ) {
                    errorMessage = kvtmlReader.errorMessage();
                }
            }
            break;

            case Wql: {
                kDebug(1100) << "Reading WordQuiz (WQL) document...";
                KEduVocWqlReader wqlReader( f );
                d->m_url.setFileName( i18n( "Untitled" ) );
                read = wqlReader.readDoc( this );
                if ( !read ) {
                    errorMessage = wqlReader.errorMessage();
                }
            }
            break;

            case Pauker: {
                kDebug(1100) << "Reading Pauker document...";
                KEduVocPaukerReader paukerReader( this );
                d->m_url.setFileName( i18n( "Untitled" ) );
                read = paukerReader.read( f );
                if ( !read ) {
                    errorMessage = i18n( "Parse error at line %1, column %2:\n%3", paukerReader.lineNumber(), paukerReader.columnNumber(), paukerReader.errorString() );
                }
            }
            break;

            case Vokabeln: {
                kDebug(1100) << "Reading Vokabeln document...";
                KEduVocVokabelnReader vokabelnReader( f );
                d->m_url.setFileName( i18n( "Untitled" ) );
                read = vokabelnReader.readDoc( this );
                if ( !read ) {
                    errorMessage = vokabelnReader.errorMessage();
                }
            }
            break;

            case Csv: {
                kDebug(1100) << "Reading CVS document...";
                KEduVocCsvReader csvReader( f );
                read = csvReader.readDoc( this );
                if ( !read ) {
                    errorMessage = csvReader.errorMessage();
                }
            }
            break;

            case Xdxf: {
                kDebug(1100) << "Reading XDXF document...";
                KEduVocXdxfReader xdxfReader( this );
                d->m_url.setFileName( i18n( "Untitled" ) );
                read = xdxfReader.read( f );
                if ( !read ) {
                    errorMessage = i18n( "Parse error at line %1, column %2:\n%3", xdxfReader.lineNumber(), xdxfReader.columnNumber(), xdxfReader.errorString() );
                }
            }
            break;

            default: {
                kDebug(1100) << "Reading KVTML document (fallback)...";
                KEduVocKvtml2Reader kvtmlReader( f );
                read = kvtmlReader.readDoc( this );
                if ( !read ) {
                    errorMessage = kvtmlReader.errorMessage();
                }
            }
        }

        if ( !read ) {
            QString msg = i18n( "Could not open or properly read \"%1\"\n(Error reported: %2)", url.path(), errorMessage );
            kError() << msg << i18n( "Error Opening File" );
            ///@todo make the readers return int, pass on the error message properly
            delete f;
            return FileReaderFailed;
        }

        f->close();
        delete f;
        KIO::NetAccess::removeTempFile( temporaryFile );
    }

    if ( !read ) {
        return FileReaderFailed;
    }

    setModified(false);
    return 0;
}