Exemplo n.º 1
0
/// @throws AbortError, GetRangesError
void DirectSearch::searchComp(Mem::Random &ram, Comparison::t comp, Async::AbortableProgress &progress) {
	assert(mStatus != DirectStatus::NotStarted);
	if (mStatus == DirectStatus::SavedBackup) {
		Mem::Live live(ram);
		Mem::Backup backup(mBackup.get());
		mBackup = boost::none;
		mStatus = DirectStatus::Started;
		Mem::DoubleBlockEnum blocks(backup, live, Number::maxSize);
		progress.start(blocks.totalSize());
		while (blocks.next()) {
			if (mType) {
				mLocLists[mType.get()].appendComp(blocks, comp);
			}
			else {
				for (size_t type = 0; type < Number::Type::count; ++type) {
					mLocLists[type].appendComp(blocks, comp);
				}
			}
			progress.set(blocks.doneSize());
			progress.check();
		}
	}
	else {
		Mem::Random::Lock lock(ram);
		initProgress(progress);
		for (size_t type = 0; type < Number::Type::count; ++type) {
			mLocLists[type].filterComp(lock, comp, progress);
		}
	}
}
Exemplo n.º 2
0
/// @throws AbortError, BackupReadError, BackupWriteError, GetRangesError
void DirectSearch::searchExact(Mem::Random &ram, const Number::Untyped &value, Async::AbortableProgress &progress) {
	if (mStatus == DirectStatus::Started) {
		Mem::Random::Lock lock(ram);
		initProgress(progress);
		for (size_t type = 0; type < Number::Type::count; ++type) {
			mLocLists[type].filterEqual(lock, value, progress);
		}
	}
	else {
		Mem::Live live(ram);
		Mem::SingleBlockEnum block(live, Number::maxSize, NULL);
		mBackup = boost::none;
		mStatus = DirectStatus::Started;
		progress.start(block.totalSize());
		while (block.next()) {
			if (mType) {
				mLocLists[mType.get()].appendEqual(block, value);
			}
			else {
				for (size_t type = 0; type < Number::Type::count; ++type) {
					mLocLists[type].appendEqual(block, value);
				}
			}
			progress.set(block.doneSize());
			progress.check();
		}
	}
}
Exemplo n.º 3
0
int MainWindow::readAreaDataBaseFile( const QString &FilenameADB, QVector<AreaItem> &v_Area, QVector<PositionItem> &v_Position )
{
    int         i                   = 0;
    int         n                   = 0;
    int         stopProgress        = 0;

    int         i_NumOfAreas        = 0;
    int         i_NumOfPositions    = 0;

    QStringList sl_Input;

// **********************************************************************************************
// read file

    if ( ( n = readFile( FilenameADB, sl_Input, _SYSTEM_, 1, -1 ) ) < 1 )
        return( n );

// **********************************************************************************************

    i_NumOfAreas     = sl_Input.at( 2 ).section( "\t", 1, 1 ).toInt();
    i_NumOfPositions = sl_Input.at( 3 ).section( "\t", 1, 1 ).toInt();

    for ( i=7; i<i_NumOfAreas+7; i++ )
        v_Area.append( AreaItem( sl_Input.at( i ).section( "\t", 0, 0 ), sl_Input.at( i ).section( "\t", 1, 1 ).toInt(), sl_Input.at( i ).section( "\t", 2, 2 ).toInt(), sl_Input.at( i ).section( "\t", 5, 5 ).toFloat(), sl_Input.at( i ).section( "\t", 3, 3 ).toFloat(), sl_Input.at( i ).section( "\t", 6, 6 ).toFloat(), sl_Input.at( i ).section( "\t", 4, 4 ).toFloat() ) );

    initProgress( 2, FilenameADB, tr( "Finding area database (read data) ..." ), i_NumOfPositions );

    i = i_NumOfAreas+10;
    i_NumOfPositions += i;

    while ( ( i < i_NumOfPositions ) && ( stopProgress != _APPBREAK_ ) )
    {
        v_Position.append( PositionItem( sl_Input.at( i ).section( "\t", 0, 0 ).toDouble(), sl_Input.at( i ).section( "\t", 1, 1 ).toDouble() ) );

        stopProgress = incProgress( 2, ++i );
    }

    resetProgress( 2 );

    return( i_NumOfAreas );
}
Exemplo n.º 4
0
/// @throws AbortError, BackupReadError, BackupWriteError, GetRangesError
void DirectSearch::saveState(Mem::Random &ram, Async::AbortableProgress &progress) {
	if (mStatus == DirectStatus::Started) {
		Mem::Random::Lock lock(ram);
		initProgress(progress);
		for (size_t type = 0; type < Number::Type::count; ++type) {
			mLocLists[type].refresh(lock, progress);
		}
	}
	else {
		Mem::Live live(ram);
		std::auto_ptr<Mem::BackupData> data(new Mem::BackupData());
		Mem::SingleBlockEnum block(live, 1, data.get());
		mBackup = boost::none;
		mStatus = DirectStatus::NotStarted;
		progress.start(block.totalSize());
		while (block.next()) {
			progress.set(block.doneSize());
			progress.check();
		}
		mBackup = Mem::Backup(data);
		mStatus = DirectStatus::SavedBackup;
	}
}
int MainWindow::GaussKruegerConverter( const QString &s_FilenameIn, const QString &s_FilenameOut, const int i_CodecInput, const int i_CodecOutput, const int i_EOL, const int i_ColumnLatitude, const int i_ColumnLongitude, const int i_ColumnHoch, const int i_ColumnRechts, const int i_ColumnStreifen, const int i_NumOfDigits, const int i_DecimalSeparator, const bool b_DeleteInputFile, const int i_NumOfFiles )
{
    int         i                   = 0;
    int         n                   = 0;
    int         mode                = -1;

    int         stopProgress        = 0;

    QString     s_EOL               = setEOLChar( i_EOL );

    QStringList sl_Input;

    convertPosition *llc = new convertPosition( i_NumOfDigits, i_DecimalSeparator );

// **********************************************************************************************
// read file

    if ( ( n = readFile( s_FilenameIn, sl_Input, i_CodecInput ) ) < 1 )
        return( n );

// **********************************************************************************************

    if ( ( i_ColumnHoch > 0 ) && ( i_ColumnRechts > 0 ) && ( i_ColumnStreifen > 0 ) )
        mode = _GKLL_;

    if ( ( i_ColumnLatitude > 0 ) && ( i_ColumnLongitude > 0 ) )
        mode = _LLGK_;

    if ( mode < 0 )
        return( mode );

// **********************************************************************************************
// open output file

    QFile fout( s_FilenameOut );

    if ( fout.open( QIODevice::WriteOnly | QIODevice::Text) == false )
        return( -20 );

    QTextStream tout( &fout );

    switch ( i_CodecOutput )
    {
    case _SYSTEM_:
        break;
    case _LATIN1_:
        tout.setCodec( QTextCodec::codecForName( "ISO 8859-1" ) );
        break;
    case _APPLEROMAN_:
        tout.setCodec( QTextCodec::codecForName( "Apple Roman" ) );
        break;
    default:
        tout.setCodec( QTextCodec::codecForName( "UTF-8" ) );
        break;
    }

// **********************************************************************************************

    initProgress( i_NumOfFiles, s_FilenameIn, tr( "Converting positions..." ), n );

    switch( mode )
    {
    case _GKLL_:
        tout << "Latitude\tLongitude\t" << sl_Input.at( i++ ) << s_EOL;
        break;
    case _LLGK_:
        tout << "Hoch [m]\tRechts [m]\tStreifen\t" << sl_Input.at( i++ ) << s_EOL;
        break;
    }

    while ( ( i < n ) && ( stopProgress != _APPBREAK_ ) )
    {
        switch( mode )
        {
        case _GKLL_:
            llc->convertGKtoLL( sl_Input.at( i ).section( "\t", i_ColumnStreifen-1, i_ColumnStreifen-1 ), sl_Input.at( i ).section( "\t", i_ColumnRechts-1, i_ColumnRechts-1 ), sl_Input.at( i ).section( "\t", i_ColumnHoch-1, i_ColumnHoch-1 ) );
            tout << sl_Input.at( i ) << "\t" << llc->Latitude() << "\t" << llc->Longitude() << s_EOL;
            break;

        case _LLGK_:
            if ( ( llc->getMode( sl_Input.at( i ).section( "\t", i_ColumnLatitude-1, i_ColumnLatitude-1 ) ) == 1 ) || ( llc->getMode( sl_Input.at( i ).section( "\t", i_ColumnLongitude-1, i_ColumnLongitude-1 ) ) == 1 ) )
            {
                llc->setNumOfDigitsLL( 7 );
                llc->convertLLtoLL( sl_Input.at( i ).section( "\t", i_ColumnLatitude-1, i_ColumnLatitude-1 ), sl_Input.at( i ).section( "\t", i_ColumnLongitude-1, i_ColumnLongitude-1 ) );
                llc->convertLLtoGK( llc->Latitude(), llc->Longitude() );
            }
            else
            {
                llc->convertLLtoGK( sl_Input.at( i ).section( "\t", i_ColumnLatitude-1, i_ColumnLatitude-1 ), sl_Input.at( i ).section( "\t", i_ColumnLongitude-1, i_ColumnLongitude-1 ) );
            }

            tout << QString( "%1" ).arg( llc->Hoch(), 0, 'f', i_NumOfDigits ) << "\t" << QString( "%1" ).arg( llc->Rechts(), 0, 'f', i_NumOfDigits ) << "\t" << llc->Streifen() << "\t" << sl_Input.at( i ) << s_EOL;

            break;
        }

        stopProgress = incProgress( i_NumOfFiles, ++i );
    }

    resetProgress( i_NumOfFiles );

// **********************************************************************************************

    fout.close();

    if ( stopProgress == _APPBREAK_ )
        return( _APPBREAK_ );

    if ( b_DeleteInputFile == true )
        removeFile( s_FilenameIn );

    return( _NOERROR_ );
}
Exemplo n.º 6
0
int MainWindow::CliwocConverter( const QString &s_FilenameIn, const QString &s_FilenameOut,  const QString &s_FilenameConf, const int i_NumOfFiles )
{
    int             k               = 0;
    int             n               = 0;

    QString         InputStr        = "";
    QString         s_EventLabel    = "";

    QStringList     sl_Conf;

    unsigned int	ui_length		= 1;
    unsigned int	ui_filesize		= 1;

// **********************************************************************************************

    n = readFile( s_FilenameConf, sl_Conf );

    if ( n < 9 )
        return( _ERROR_ );

// **********************************************************************************************
// open input file

    QFile fin( s_FilenameIn );

    if ( fin.open( QIODevice::ReadOnly | QIODevice::Text ) == false )
        return( -10 );

    ui_filesize = fin.size();

    QTextStream tin( &fin );

// **********************************************************************************************
// open output file

    QFile fout( s_FilenameOut );

    if ( fout.open( QIODevice::WriteOnly | QIODevice::Text ) == false )
        return( -20 );

    QTextStream tout( &fout );

// **********************************************************************************************

    initProgress( i_NumOfFiles, s_FilenameIn, tr( "Converting..." ), 100 );

// **********************************************************************************************
// read file

// Header
    tout << k++ << "\t" << "Event label" << "\t" << "Date/Time" << "\t" << "Latitude" << "\t" << "Longitude";

    for ( int i=9; i<n; i++ )
    {
        if ( sl_Conf.at( i ).section( "\t", 0, 0 ) == "x" )
            tout << "\t" << sl_Conf.at( i ).section( "\t", 3, 3 ); // Column no 4: Parameter name
    }

    tout << endl;

    while ( ( tin.atEnd() == false ) && ( ui_length != (unsigned int) _APPBREAK_ ) )
    {
        InputStr  = tin.readLine();
        ui_length = incProgress( i_NumOfFiles, ui_filesize, ui_length, InputStr );

// Event label
        s_EventLabel = "@" + InputStr.mid( 34, 9 ).simplified() + "_" + InputStr.mid( 2597, 8 ).simplified() + "_" + InputStr.mid( 297, 30 ).simplified();

        s_EventLabel.replace( "EXTRACT ", "" );
        s_EventLabel.replace( ",", "" );
        s_EventLabel.replace( ".", "" );
        s_EventLabel.replace( "(", "-" );
        s_EventLabel.replace( ")", "" );
        s_EventLabel.replace( " ", "_" );
        s_EventLabel.replace( "_-_", "_" );
        s_EventLabel.replace( "_-", "_" );
        s_EventLabel.replace( "-_", "_" );
        s_EventLabel.replace( "__", "_" );
        s_EventLabel.replace( "'", "" );

        tout << k++ << "\t" << s_EventLabel << "\t";

// Date/Time
        QString s_DateTime = InputStr.mid( 0, 4 ) + tr( "-" ) + InputStr.mid( 4, 2 ) + tr( "-" ) + InputStr.mid( 6, 2 ) + tr( "T" ) + InputStr.mid( 8, 2 ) + tr( ":" ) + InputStr.mid( 10, 2 );
        s_DateTime.replace( " ", "0" );
        tout << s_DateTime << "\t";

// Position
        // Latitude
        if ( InputStr.mid( 12, 5 ) != "     " )
            tout << InputStr.mid( 12, 5 ).toFloat()/100. << "\t";
        else
            tout << "\t";

        // Longitude
        if ( InputStr.mid( 17, 6 ) != "      " )
        {
            float f_Longitude = InputStr.mid( 17, 6 ).toFloat()/100.;

            if ( f_Longitude > 180. )
                f_Longitude -=360;

            tout << f_Longitude;
        }
        else
            tout << "";

        for ( int i=9; i<n; i++ )
        {
            if ( sl_Conf.at( i ).section( "\t", 0, 0 ) == "x" )
            {
                QString s_Factor = sl_Conf.at( i ).section( "\t", 1, 1 );
                QString s_Entry  = InputStr.mid( sl_Conf.at( i ).section( "\t", 4, 4 ).toInt()-1, sl_Conf.at( i ).section( "\t", 6, 6 ).toInt() ).simplified();

                if ( s_Entry.isEmpty() == true )
                {
                    tout << "\t";
                }
                else
                {
                    if ( s_Factor == "T" )
                    {
                        s_Entry.replace( "\"", "''" );
                        tout << "\t~@" << s_Entry;
                    }
                    else
                    {
                        if ( s_Factor.isEmpty() == false )
                            tout << "\t" << s_Entry.toFloat()*s_Factor.toFloat();
                        else
                            tout << "\t" << s_Entry;
                    }
                }
            }
        }

        tout << endl;
    }

    resetProgress( i_NumOfFiles );

    fin.close();
    fout.close();

// **********************************************************************************************

    if ( ui_length == (unsigned int) _APPBREAK_ )
        return( _APPBREAK_ );

    return( _NOERROR_ );
}
Exemplo n.º 7
0
int MainWindow::findArea( const QString &s_FilenameIn, const QString &s_FilenameOut, const int i_CodecInput, const int i_CodecOutput, const int i_EOL, QVector<AreaItem> &v_Area, QVector<PositionItem> &v_Position, const bool b_DeleteInputFile, const int i_NumOfFiles)
{
    int             i                   = 1;
    int             j                   = 0;
    int             n                   = 0;
    int             m                   = 0;
    int             i_LatID             = -1;
    int             i_LongID            = -1;
    int             stopProgress        = -1;

    double          d_Latitude_dummy    = -1000.;
    double          d_Longitude_dummy   = -1000.;
    double          d_Latitude          = -1000.;
    double          d_Longitude         = -1000.;

    QString         s_AreaName          = "???";
    QString         s_EOL               = setEOLChar( i_EOL );

    QStringList     sl_Input;

// **********************************************************************************************
// read file

    if ( ( n = readFile( s_FilenameIn, sl_Input, i_CodecInput ) ) < 1 )
        return( n );

    m = NumOfSections( sl_Input.at( 0 ) );

    j = 0;
    while ( ( i_LatID < 0 ) && ( j < m ) )
    {
        if ( sl_Input.at( 0 ).section( "\t", j, j ).contains( "Latitude", Qt::CaseInsensitive ) == true )
            i_LatID = j;
        else
            j++;
    }

    j = 0;
    while ( ( i_LongID < 0 ) && ( j < m ) )
    {
        if ( sl_Input.at( 0 ).section( "\t", j, j ).contains( "Longitude", Qt::CaseInsensitive ) == true )
            i_LongID = j;
        else
            j++;
    }

    if ( ( i_LatID < 0 ) || ( i_LongID < 0 ) )
        return( -40 );

// **********************************************************************************************
// open output file

    QFile fout( s_FilenameOut );

    if ( fout.open( QIODevice::WriteOnly | QIODevice::Text) == false )
        return( -20 );

    QTextStream tout( &fout );

    switch ( i_CodecOutput )
    {
    case _SYSTEM_:
        break;
    case _LATIN1_:
        tout.setCodec( QTextCodec::codecForName( "ISO 8859-1" ) );
        break;
    case _APPLEROMAN_:
        tout.setCodec( QTextCodec::codecForName( "Apple Roman" ) );
        break;
    default:
        tout.setCodec( QTextCodec::codecForName( "UTF-8" ) );
        break;
    }

// **********************************************************************************************

    initProgress( i_NumOfFiles, s_FilenameIn, tr( "Finding areas..." ), sl_Input.count() );

// **********************************************************************************************

    tout << "Area\t" << sl_Input.at( 0 ) << s_EOL;

    while ( ( i < n ) && ( stopProgress != _APPBREAK_ ) )
    {
        d_Latitude  = (double) qMin( sl_Input.at( i ).section( "\t", i_LatID, i_LatID ).toFloat() + 90., 179.99 );     // 0 - 179.99
        d_Longitude = (double) qMin( sl_Input.at( i ).section( "\t", i_LongID, i_LongID ).toFloat() + 180., 359.99 );  // 0 - 359.99

        if ( ( d_Latitude-d_Latitude_dummy > 0.001 ) || ( d_Longitude-d_Longitude_dummy > 0.001 ) || ( d_Latitude-d_Latitude_dummy < -0.001 ) || ( d_Longitude-d_Longitude_dummy < -0.001 ) )
        {
            int     j               = 0;
            int     k               = 0;
            int     i_InPolygon     = 0;

            while ( j < v_Area.count() )
            {
                if ( ( v_Area.at( j ).maxLatitude() > d_Latitude ) && ( d_Latitude > v_Area.at( j ).minLatitude() ) )
                {
                    if ( ( v_Area.at( j ).maxLongitude() > d_Longitude ) && ( d_Longitude > v_Area.at( j ).minLongitude() ) )
                    {
                        i_InPolygon = PtInPolygon( d_Latitude, d_Longitude, v_Area.at( j ).StartPosition(), v_Area.at( j ).NumOfPoints(), v_Position );

                        if ( i_InPolygon == 1 )
                        {
                            s_AreaName = v_Area.at( j ).AreaName();
                            s_AreaName.replace( ", western part", "" );
                            s_AreaName.replace( ", eastern part", "" );

                            d_Latitude_dummy  = d_Latitude;
                            d_Longitude_dummy = d_Longitude;

                            tout << s_AreaName << "\t" << sl_Input.at( i ) << s_EOL;

                            j = v_Area.count() - 1;
                        }
                    }
                }

                k += v_Area.at( j ).NumOfPoints();
                j += 1;
            }

            if ( i_InPolygon < 1 )
            {
                d_Latitude_dummy  = d_Latitude;
                d_Longitude_dummy = d_Longitude;

                if ( d_Latitude > 160. )
                    s_AreaName = "Arctic Ocean";
                else
                    s_AreaName = "???";

                tout << s_AreaName << "\t" << sl_Input.at( i ) << s_EOL;
            }
        }
        else
        {
            tout << s_AreaName << "\t" << sl_Input.at( i ) << s_EOL;
        }

        stopProgress = incProgress( i_NumOfFiles, ++i );
    }

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

    resetProgress( i_NumOfFiles );

    fout.close();

    if ( stopProgress == _APPBREAK_ )
        return( _APPBREAK_ );

    if ( b_DeleteInputFile == true )
        removeFile( s_FilenameIn );

    return( _NOERROR_ );
}
Exemplo n.º 8
0
int main(int argc,char* argv[]) {
	int width=512;
	int height=512;
	int max;
	int x,y;
	int nowProgress=0;
	FILE* fp=NULL;
	png_structp pngPtr;
	png_infop pngInfoPtr;
	png_bytepp pngImageData;
	/* コマンドライン引数の取得とスクリプトの読み込み */
	if(argc<3) {
		puts("Usage: 3d_gazou_seisei <script file> <output file> [width [height [params...]]");
		return 1;
	}
	if(argc>=4)sscanf(argv[3],"%d",&width);
	if(argc>=5)sscanf(argv[4],"%d",&height);
	if(width<=0 || height<=0) {
		puts("invalid size");
		return 1;
	}
	if(!loadScript(argv[1],argc>5?argc-5:0,argv+5))return 1;

	/* PNGデータを書き込む準備 */
	pngPtr=png_create_write_struct(PNG_LIBPNG_VER_STRING,NULL,NULL,NULL);
	if(!pngPtr) {
		puts("png_create_write_struct failed");
		return 1;
	}
	pngInfoPtr=png_create_info_struct(pngPtr);
	if(!pngInfoPtr) {
		puts("png_create_info_struct failed");
		png_destroy_write_struct(&pngPtr,NULL);
		return 1;
	}
	fp=fopen(argv[2],"wb");
	if(setjmp(png_jmpbuf(pngPtr))) {
		png_destroy_write_struct(&pngPtr,&pngInfoPtr);
		fclose(fp);
		return 1;
	}
	png_init_io(pngPtr,fp);
	png_set_IHDR(pngPtr,pngInfoPtr,width,height,8,PNG_COLOR_TYPE_RGB,
		PNG_INTERLACE_NONE,PNG_COMPRESSION_TYPE_BASE,PNG_FILTER_TYPE_BASE);

	/* 画像を格納するメモリの確保 */
	puts("generating image data...");
	pngImageData=png_malloc(pngPtr,height*sizeof(png_bytep));
	for(y=0;y<height;y++)pngImageData[y]=png_malloc(pngPtr,width*3);

	/* 画像生成の計算本体 */
	initProgress(height);
	max=(width>=height?width:height);
	#ifdef _OPENMP
	#pragma omp parallel for schedule(dynamic) private(x)
	#endif
	for(y=0;y<height;y++) {
		for(x=0;x<width;x++) {
			double xoff=(double)(x-width/2)/(max/2);
			double yoff=(double)(height/2-y)/(max/2);
			double vec[3]={
				theWorld.camera.dir[0]+theWorld.camera.dx[0]*xoff+theWorld.camera.dy[0]*yoff,
				theWorld.camera.dir[1]+theWorld.camera.dx[1]*xoff+theWorld.camera.dy[1]*yoff,
				theWorld.camera.dir[2]+theWorld.camera.dx[2]*xoff+theWorld.camera.dy[2]*yoff
			};
			color_t color=getColorOfOnePoint(theWorld.camera.pos,vec,theWorld.ttl);
			pngImageData[y][x*3+0]=(int)(color.r*255.0+EPS);
			pngImageData[y][x*3+1]=(int)(color.g*255.0+EPS);
			pngImageData[y][x*3+2]=(int)(color.b*255.0+EPS);
		}
		#ifdef _OPENMP
		#pragma omp flush(nowProgress)
		#pragma omp atomic
		#endif
		nowProgress++;
		#ifdef _OPENMP
		#pragma omp flush(nowProgress)
		#endif
		updateProgress(nowProgress);
	}
	putchar('\n');
	png_set_rows(pngPtr,pngInfoPtr,pngImageData);

	/* 画像のファイルへの書き込み */
	png_write_png(pngPtr,pngInfoPtr,PNG_TRANSFORM_IDENTITY,NULL);
	for(y=0;y<height;y++)png_free(pngPtr,pngImageData[y]);
	png_free(pngPtr,pngImageData);
	png_destroy_write_struct(&pngPtr,&pngInfoPtr);
	fclose(fp);
	puts("done");

	/* 確保したテクスチャの開放 */
	freeTheWorld();
	return 0;
}
Exemplo n.º 9
0
void NGSD::annotate(VariantList& variants, QString filename)
{
	initProgress("NGSD annotation", true);

	//get sample ids
	QString s_id = sampleId(filename, false);
	QString ps_id = processedSampleId(filename, false);
	QString sys_id = getValue("SELECT processing_system_id FROM processed_sample WHERE id='" + processedSampleId(filename, false) + "'").toString();

	//check if we could determine the sample
	bool found_in_db = true;
	if (s_id=="" || ps_id=="" || sys_id=="")
	{
		Log::warn("Could not find processed sample in NGSD by name '" + filename + "'. Annotation will be incomplete because processing system could not be determined!");
		found_in_db = false;
	}

	//get sample ids that have processed samples with the same processing system (not same sample, variants imported, same processing system, good quality of sample, not tumor)
	QSet<int> sys_sample_ids;
	SqlQuery tmp = getQuery();
	tmp.exec("SELECT DISTINCT s.id FROM processed_sample as ps, sample s WHERE ps.processing_system_id='" + sys_id + "' AND ps.sample_id=s.id AND s.tumor='0' AND s.quality='good' AND s.id!='" + s_id + "' AND (SELECT count(id) FROM detected_variant as dv WHERE dv.processed_sample_id = ps.id)>0");
	while(tmp.next())
	{
		sys_sample_ids.insert(tmp.value(0).toInt());
	}

	//remove all NGSD-specific columns
	QList<VariantAnnotationHeader> headers = variants.annotations();
	foreach(const VariantAnnotationHeader& header, headers)
	{
		if (header.name().startsWith("ihdb_"))
		{
			removeColumnIfPresent(variants, header.name(), true);
		}
	}
	removeColumnIfPresent(variants, "classification", true);
	removeColumnIfPresent(variants, "classification_comment", true);
	removeColumnIfPresent(variants, "validated", true);
	removeColumnIfPresent(variants, "comment", true);

	//get required column indices
	QString num_samples = QString::number(sys_sample_ids.count());
	int ihdb_hom_idx = addColumn(variants, "ihdb_hom", "Homozygous variant counts in NGSD for the same processing system (" + num_samples + " samples).");
	int ihdb_het_idx = addColumn(variants, "ihdb_het", "Heterozyous variant counts in NGSD for the same processing system (" + num_samples + " samples).");
	int ihdb_wt_idx  = addColumn(variants, "ihdb_wt", "Wildtype variant counts in NGSD for the same processing system (" + num_samples + " samples).");
	int ihdb_all_hom_idx = addColumn(variants, "ihdb_allsys_hom", "Homozygous variant counts in NGSD independent of the processing system.");
	int ihdb_all_het_idx =  addColumn(variants, "ihdb_allsys_het", "Heterozygous variant counts in NGSD independent of the processing system.");
	int class_idx = addColumn(variants, "classification", "Classification from the NGSD.");
	int clacom_idx = addColumn(variants, "classification_comment", "Classification comment from the NGSD.");
	int valid_idx = addColumn(variants, "validated", "Validation information from the NGSD. Validation results of other samples are listed in brackets!");
	if (variants.annotationIndexByName("comment", true, false)==-1) addColumn(variants, "comment", "Comments from the NGSD. Comments of other samples are listed in brackets!");
	int comment_idx = variants.annotationIndexByName("comment", true, false);

	//(re-)annotate the variants
	SqlQuery query = getQuery();
	for (int i=0; i<variants.count(); ++i)
	{
		//QTime timer;
		//timer.start();

		//variant id
		Variant& v = variants[i];
		QByteArray v_id = variantId(v, false).toLatin1();

		//variant classification
		QVariant classification = getValue("SELECT class FROM variant_classification WHERE variant_id='" + v_id + "'", true);
		if (!classification.isNull())
		{
			v.annotations()[class_idx] = classification.toByteArray().replace("n/a", "");
			v.annotations()[clacom_idx] = getValue("SELECT comment FROM variant_classification WHERE variant_id='" + v_id + "'", true).toByteArray().replace("\n", " ").replace("\t", " ");
		}
		//int t_v = timer.elapsed();
		//timer.restart();

		//detected variant infos
		int dv_id = -1;
		QByteArray comment = "";
		if (found_in_db)
		{
			query.exec("SELECT id, comment FROM detected_variant WHERE processed_sample_id='" + ps_id + "' AND variant_id='" + v_id + "'");
			if (query.size()==1)
			{
				query.next();
				dv_id = query.value(0).toInt();
				comment = query.value(1).toByteArray();
			}
		}

		//validation info
		int vv_id = -1;
		QByteArray val_status = "";
		if (found_in_db)
		{
			query.exec("SELECT id, status FROM variant_validation WHERE sample_id='" + s_id + "' AND variant_id='" + v_id + "'");
			if (query.size()==1)
			{
				query.next();
				vv_id = query.value(0).toInt();
				val_status = query.value(1).toByteArray().replace("n/a", "");
			}
		}

		//int t_dv = timer.elapsed();
		//timer.restart();

		//validation info other samples
		int tps = 0;
		int fps = 0;
		query.exec("SELECT id, status FROM variant_validation WHERE variant_id='"+v_id+"' AND status!='n/a'");
		while(query.next())
		{
			if (query.value(0).toInt()==vv_id) continue;
			if (query.value(1).toByteArray()=="true positive") ++tps;
			else if (query.value(1).toByteArray()=="false positive") ++fps;
		}
		if (tps>0 || fps>0)
		{
			if (val_status=="") val_status = "n/a";
			val_status += " (" + QByteArray::number(tps) + "xTP, " + QByteArray::number(fps) + "xFP)";
		}
		//int t_val = timer.elapsed();
		//timer.restart();

		//comments other samples
		QList<QByteArray> comments;
		query.exec("SELECT id, comment FROM detected_variant WHERE variant_id='"+v_id+"' AND comment IS NOT NULL");
		while(query.next())
		{
			if (query.value(0).toInt()==dv_id) continue;
			QByteArray tmp = query.value(1).toByteArray().trimmed();
			if (tmp!="") comments.append(tmp);
		}
		if (comments.size()>0)
		{
			if (comment=="") comment = "n/a";
			comment += " (";
			for (int i=0; i<comments.count(); ++i)
			{
				if (i>0)
				{
					comment += ", ";
				}
				comment += comments[i];
			}
			comment += ")";
		}
		//int t_com = timer.elapsed();
		//timer.restart();

		//genotype counts
		int allsys_hom_count = 0;
		int allsys_het_count = 0;
		int sys_hom_count = 0;
		int sys_het_count = 0;
		QSet<int> s_ids_done;
		int s_id_int = s_id.toInt();
		query.exec("SELECT dv.genotype, ps.sample_id FROM detected_variant as dv, processed_sample ps WHERE dv.processed_sample_id=ps.id AND dv.variant_id='" + v_id + "'");
		while(query.next())
		{
			//skip this sample id
			int current_sample = query.value(1).toInt();
			if (current_sample==s_id_int) continue;

			//skip already seen samples (there could be several processings of the same sample because of different processing systems or because of experment repeats due to quality issues)
			if (s_ids_done.contains(current_sample)) continue;
			s_ids_done.insert(current_sample);

			QByteArray current_geno = query.value(0).toByteArray();
			if (current_geno=="hom")
			{
				++allsys_hom_count;
				if (sys_sample_ids.contains(current_sample))
				{
					++sys_hom_count;
				}
			}
			else if (current_geno=="het")
			{
				++allsys_het_count;
				if (sys_sample_ids.contains(current_sample))
				{
					++sys_het_count;
				}
			}
		}
		//qDebug() << (v.isSNV() ? "S" : "I") << query.size() << t_v << t_dv << t_val << t_com << timer.elapsed();

		v.annotations()[ihdb_all_hom_idx] = QByteArray::number(allsys_hom_count);
		v.annotations()[ihdb_all_het_idx] = QByteArray::number(allsys_het_count);
		if (found_in_db)
		{
			v.annotations()[ihdb_hom_idx] = QByteArray::number((double)sys_hom_count / sys_sample_ids.count(), 'f', 4);
			v.annotations()[ihdb_het_idx] =  QByteArray::number((double)sys_het_count / sys_sample_ids.count(), 'f', 4);
			v.annotations()[ihdb_wt_idx] =  QByteArray::number((double)(sys_sample_ids.count() - sys_hom_count - sys_het_count) / sys_sample_ids.count(), 'f', 4);
			v.annotations()[valid_idx] = val_status;
			v.annotations()[comment_idx] = comment.replace("\n", " ").replace("\t", " ");
		}
		else
		{
			v.annotations()[ihdb_hom_idx] = "n/a";
			v.annotations()[ihdb_het_idx] = "n/a";
			v.annotations()[ihdb_wt_idx] = "n/a";
			v.annotations()[valid_idx] = "n/a";
			v.annotations()[comment_idx] = "n/a";
		}

		emit updateProgress(100*i/variants.count());
	}
}
Exemplo n.º 10
0
int MainWindow::buildAreaDatabase( const QString &s_FilenameIn, const int i_CodecInput, const int i_NumOfFiles )
{
    int         n                   = 0;
    int         stopProgress        = 0;

    int         i                   = 0;

    int         i_NumOfAreas        = 0;
    int         i_NumOfPositions    = 0;
    int         i_StartPosition     = 0;

    int         i_AreaNamePosition  = -1;
    int         i_LatitudePosition  = -1;
    int         i_LongitudePosition = -1;

    double      d_Lat               =    0.;
    double      d_Long              =    0.;
    double      d_minLat            =  180.;
    double      d_maxLat            =    0.;
    double      d_minLong           =  360.;
    double      d_maxLong           =    0.;

    QString     s_AreaName          = "";
    QString     s_Header            = "";

    QStringList sl_Input;

    QVector<AreaItem>       v_Area;
    QVector<PositionItem>   v_Position;

// **********************************************************************************************

    QFileInfo fi( s_FilenameIn );

    QFile fout( fi.absolutePath() + "/" + fi.baseName() + ".adb" );

    if ( fout.open( QIODevice::WriteOnly ) == false )
        return( -20 );

// **********************************************************************************************
// read file

    if ( ( n = readFile( s_FilenameIn, sl_Input, i_CodecInput ) ) < 1 )
        return( n );

    if ( sl_Input.at( i ).contains( "/*" ) == true )
    {
        while ( ( i < n ) && ( sl_Input.at( i ).contains( "*/" ) == false ) )
            i++;
    }

// **********************************************************************************************
// check file format (plain text or doi:10.1594/PANGAEA.777975)

    if ( i > 0 )
    {
        if ( n-i++ < 4 )
            return ( -40 );
    }
    else
    {
        if ( n < 4 )
            return ( -40 );
    }

    s_Header = sl_Input.at( i++ );

    for ( int j=0; j<s_Header.count(); j++ )
    {
        if ( ( s_Header.section( "\t", j, j ) == "Name" ) || ( s_Header.section( "\t", j, j ) == "Name of area" ) || ( s_Header.section( "\t", j, j ) == "Campaign" ) )
            i_AreaNamePosition = j;

        if ( s_Header.section( "\t", j, j ) == "Latitude" )
            i_LatitudePosition = j;

        if ( s_Header.section( "\t", j, j ) == "Longitude" )
            i_LongitudePosition = j;
    }

    if ( ( i_AreaNamePosition < 0 ) || ( i_LatitudePosition < 0 ) || ( i_LongitudePosition < 0 ) )
        return( -40 );

// **********************************************************************************************

    initProgress( i_NumOfFiles, s_FilenameIn, tr( "Building area database (read data) ..." ), n );

    while ( ( i < n ) && ( stopProgress != _APPBREAK_ ) )
    {
        d_minLat	=  1000.0;
        d_maxLat	= -1000.0;
        d_minLong	=  1000.0;
        d_maxLong	= -1000.0;

        i_NumOfPositions = 0;
        i_StartPosition  = v_Position.count();
        s_AreaName       = sl_Input.at( i ).section( "\t", i_AreaNamePosition, i_AreaNamePosition );

        while ( ( i < n ) && ( ( sl_Input.at( i ).section( "\t", i_AreaNamePosition, i_AreaNamePosition ) == s_AreaName ) || ( sl_Input.at( i ).section( "\t", i_AreaNamePosition, i_AreaNamePosition ).isEmpty() == true ) ) && ( stopProgress != _APPBREAK_ ) )
        {
            i_NumOfPositions++;

            d_Lat  = (double) qMin( sl_Input.at( i ).section( "\t", i_LatitudePosition, i_LatitudePosition ).toFloat() + 90., 179.99 );
            d_Long = (double) qMin( sl_Input.at( i ).section( "\t", i_LongitudePosition, i_LongitudePosition ).toFloat() + 180., 359.99 );

            v_Position.append( PositionItem( d_Lat, d_Long ) );

            d_minLat  = qMin( d_minLat, v_Position.last().Latitude() );
            d_maxLat  = qMax( d_maxLat, v_Position.last().Latitude() );
            d_minLong = qMin( d_minLong, v_Position.last().Longitude() );
            d_maxLong = qMax( d_maxLong, v_Position.last().Longitude() );

            stopProgress = incProgress( i_NumOfFiles, ++i );
        }

        v_Area.append( AreaItem( s_AreaName, i_StartPosition, i_NumOfPositions, d_minLat, d_maxLat, d_minLong, d_maxLong ) );
    }

    resetProgress( i_NumOfFiles );

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

    if ( stopProgress != _APPBREAK_ )
    {
        i_NumOfAreas		= v_Area.count();
        i_NumOfPositions	= v_Position.count();

        QByteArray ba( "PanTool area database\n" );                                                             // 0

        ba.append( QString( "Created:\t%1\n" ).arg( QDateTime::currentDateTime().toString( Qt::ISODate ) ) );   // 1
        ba.append( QString( "Number of areas:\t%1\n" ).arg( i_NumOfAreas ) );                                   // 2
        ba.append( QString( "Number of positions:\t%1\n" ).arg( i_NumOfPositions ) );                           // 3

        ba.append( "\n[Areas]\n" );
        ba.append( "Name of area\tStart position\tNumber of positions\tmax Lat\tmax Long\tmin Lat\tmin Long\n" );               // 4

        for ( i=0; i<i_NumOfAreas; i++ )
        {
            ba.append( v_Area.at( i ).AreaName() + "\t" );
            ba.append( QString( "%1\t%2\t%3\t%4\t%5\t%6\n" ).arg( v_Area.at( i ).StartPosition() ).arg( v_Area.at( i ).NumOfPoints() ).arg( v_Area.at( i ).maxLatitude() ).arg( v_Area.at( i ).maxLongitude() ).arg( v_Area.at( i ).minLatitude() ).arg( v_Area.at( i ).minLongitude() ) );
        }

        initProgress( i_NumOfFiles, s_FilenameIn, tr( "Building area database (write data) ..." ), i_NumOfPositions );

        i = 0;

        ba.append( "\n[Positions]\n" );
        ba.append( "Latitude\tLongitude\n" );

        while ( ( i<i_NumOfPositions ) && ( stopProgress != _APPBREAK_ ) )
        {
            ba.append( QString( "%1\t%2\n" ).arg( v_Position.at( i ).Latitude(), 0, 'f', 6 ).arg( v_Position.at( i ).Longitude(), 0, 'f', 6 ) );
            stopProgress = incProgress( i_NumOfFiles, ++i );
        }

        resetProgress( i_NumOfFiles );

        fout.write( qCompress( ba, 9 ) );

        fout.close();
    }

    return( _NOERROR_ );
}
Exemplo n.º 11
0
int MainWindow::addLine( const QString &s_FilenameIn, const QString &s_FilenameOut, const int i_CodecInput, const int i_CodecOutput, const int i_EOL,
                         const QStringList &sl_Text, const int i_LineNo,  const bool b_AddFilename, const bool b_AddFullPath, const bool b_AddOrdinalNumber,
                         const bool b_PrependMetadataColumn, const bool b_AppendMetadataColumn, const bool b_SkipEmptyLines, const bool b_SkipCommentLines, const int i_NumOfFiles )
{
    int         i               = 0;
    int         k               = 0;
    int         n               = 0;
    int         e               = 0;
    int         stopProgress    = 0;

    QString     s_EOL           = setEOLChar( i_EOL );

    QStringList sl_Input;

// **********************************************************************************************
// read file

    if ( ( n = readFile( s_FilenameIn, sl_Input, i_CodecInput ) ) < 1 )
        return( n );

// **********************************************************************************************
// open output file

    QFile fout( s_FilenameOut );

    if ( fout.open( QIODevice::WriteOnly | QIODevice::Text) == false )
        return( -20 );

    QTextStream tout( &fout );

    switch ( i_CodecOutput )
    {
    case _SYSTEM_:
        break;
    case _LATIN1_:
        tout.setCodec( QTextCodec::codecForName( "ISO 8859-1" ) );
        break;
    case _APPLEROMAN_:
        tout.setCodec( QTextCodec::codecForName( "Apple Roman" ) );
        break;
    default:
        tout.setCodec( QTextCodec::codecForName( "UTF-8" ) );
        break;
    }

    QFileInfo fi( s_FilenameIn );

// **********************************************************************************************

    initProgress( i_NumOfFiles, s_FilenameIn, tr( "Adding lines..." ), sl_Input.count() );

    e = i_LineNo - 1;

    if ( b_PrependMetadataColumn == true )
    {
        if ( b_AddFilename == true )
            tout << "Event label" << "\t";

        if ( b_AddFullPath == true )
            tout << "Filename" << "\t";

        if ( b_AddOrdinalNumber == true )
            tout << "No" << "\t";
    }

    tout << sl_Input.at( 0 );

    if ( b_AppendMetadataColumn == true )
    {
        if ( b_AddFilename == true )
            tout << "\t" << "Event label";

        if ( b_AddFullPath == true )
            tout << "\t"<< "Filename";

        if ( b_AddOrdinalNumber == true )
            tout << "\t" << "No";
    }

    tout << s_EOL;

    stopProgress = incProgress( i_NumOfFiles, ++i );

    while ( ( i<e ) && ( stopProgress != _APPBREAK_ ) )
    {
        if ( LineCanBeWritten( sl_Input.at( i ), b_SkipEmptyLines, b_SkipCommentLines ) == true )
        {
            if ( b_PrependMetadataColumn == true )
            {
                if ( b_AddFilename == true )
                    tout << fi.baseName() << "\t";

                if ( b_AddFullPath == true )
                    tout << fi.absoluteFilePath() << "\t";

                if ( b_AddOrdinalNumber == true )
                    tout << QString( "%1" ).arg( ++k ) << "\t";
            }

            tout << sl_Input.at( i );

            if ( b_AppendMetadataColumn == true )
            {
                if ( b_AddFilename == true )
                    tout << "\t" << fi.baseName();

                if ( b_AddFullPath == true )
                    tout << "\t" << fi.absoluteFilePath();

                if ( b_AddOrdinalNumber == true )
                {
                    if ( b_PrependMetadataColumn == false )
                        tout << "\t" << QString( "%1" ).arg( ++k );
                    else
                        tout << "\t" << QString( "%1" ).arg( k );
                }
            }

            tout << s_EOL;
        }

        stopProgress = incProgress( i_NumOfFiles, ++i );
    }

    for ( int j=0; j<sl_Text.count(); j++ )
    {
        if ( b_PrependMetadataColumn == true )
        {
            if ( b_AddFilename == true )
                tout << fi.baseName() << "\t";

            if ( b_AddFullPath == true )
                tout << fi.absoluteFilePath() << "\t";

            if ( b_AddOrdinalNumber == true )
                tout << QString( "%1" ).arg( ++k ) << "\t";
        }

        tout << sl_Text.at( j );

        if ( b_AppendMetadataColumn == true )
        {
            if ( b_AddFilename == true )
                tout << "\t" << fi.baseName();

            if ( b_AddFullPath == true )
                tout << "\t" << fi.absoluteFilePath();

            if ( b_AddOrdinalNumber == true )
            {
                if ( b_PrependMetadataColumn == false )
                    tout << "\t" << QString( "%1" ).arg( ++k );
                else
                    tout << "\t" << QString( "%1" ).arg( k );
            }
        }

        tout << s_EOL;
    }

    while ( ( i < n ) && ( stopProgress != _APPBREAK_ ) )
    {
        if ( LineCanBeWritten( sl_Input.at( i ), b_SkipEmptyLines, b_SkipCommentLines ) == true )
        {
            if ( b_PrependMetadataColumn == true )
            {
                if ( b_AddFilename == true )
                    tout << fi.baseName() << "\t";

                if ( b_AddFullPath == true )
                    tout << fi.absoluteFilePath() << "\t";

                if ( b_AddOrdinalNumber == true )
                    tout << QString( "%1" ).arg( ++k ) << "\t";
            }

            tout << sl_Input.at( i );

            if ( b_AppendMetadataColumn == true )
            {
                if ( b_AddFilename == true )
                    tout << "\t" << fi.baseName();

                if ( b_AddFullPath == true )
                    tout << "\t" << fi.absoluteFilePath();

                if ( b_AddOrdinalNumber == true )
                {
                    if ( b_PrependMetadataColumn == false )
                        tout << "\t" << QString( "%1" ).arg( ++k );
                    else
                        tout << "\t" << QString( "%1" ).arg( k );
                }
            }

            tout << s_EOL;
        }

        stopProgress = incProgress( i_NumOfFiles, ++i );
    }

    resetProgress( i_NumOfFiles );

// **********************************************************************************************

    fout.close();

    if ( stopProgress == _APPBREAK_ )
        return( _APPBREAK_ );

    return( _NOERROR_ );
}
Exemplo n.º 12
0
int MainWindow::getDataMetadata( const int i_CodecInput, const int i_OutputFormat, const QString &s_MetadataIn, QStringList &sl_DataMetadataList, structURL URL[], const int i_NumOfFiles )
{
    int             n                   = 0;

    int             j                   = 0;
    int             i_line              = 0;
    int             stopProgress      = 0;

    int             i_DatePos           = -1;
    int             i_TimePos           = -1;
    int             i_DateTimePos       = -1;
    int             i_ElevationPos      = -1;
    int             i_EventLabelPos     = -1;
    int             i_CampaignLabelPos  = -1;
    int             i_AreaNamePos       = -1;
    int             i_GearNamePos       = -1;
    int             i_LatitudePos       = -1;
    int             i_LongitudePos      = -1;

    QStringList     sl_Input;

    QString         s_Metadata          = "";
    QString         s_EventLabel        = "";
    QString         s_Header            = "";
    QString         s_LatLon            = "";

    bool            b_containsPosition  = false;

    sl_DataMetadataList.clear();

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

    b_containsPosition = getDataMetadataPosition( s_MetadataIn, i_DatePos, i_TimePos, i_DateTimePos, i_ElevationPos, i_EventLabelPos, i_CampaignLabelPos, i_AreaNamePos, i_GearNamePos, i_LatitudePos, i_LongitudePos );

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

    if ( ( n = readFile( s_MetadataIn.section( "\t", _FILENAMEPOS, _FILENAMEPOS ), sl_Input, i_CodecInput ) ) < 1 )
        return( n );

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

    switch ( i_OutputFormat )
    {
      case _FORMAT_KMLFILE:
        initProgress( i_NumOfFiles, s_MetadataIn.section( "\t", _FILENAMEPOS, _FILENAMEPOS ), tr( "Creating Google Earth import file" ), n );
        break;

      case _FORMAT_SHAPE_METADATA:
      case _FORMAT_SHAPE_DATA:
        initProgress( i_NumOfFiles, s_MetadataIn.section( "\t", _FILENAMEPOS, _FILENAMEPOS ), tr( "Creating shapefile" ), n );
        break;

      default:
        initProgress( i_NumOfFiles, s_MetadataIn.section( "\t", _FILENAMEPOS, _FILENAMEPOS ), tr( "Creating file" ), n );
        break;
    }

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

    i_line = s_MetadataIn.section( "\t", _NUMOFHEADERLINESPOS, _NUMOFHEADERLINESPOS ).toInt()-1;

    if ( sl_Input.at( i_line ) == "*/" )
        ++i_line;

    for ( int i=0; i<NumOfSections( sl_Input.at( i_line ) ); ++i )
    {
        s_Header = sl_Input.at( i_line ).section( "\t", i, i );

        if ( ( s_Header.startsWith( "url", Qt::CaseInsensitive ) == true ) || ( s_Header.startsWith( "uri", Qt::CaseInsensitive ) == true ) || ( s_Header.startsWith( "persistent identifier", Qt::CaseInsensitive ) == true ) )
        {
            if ( ++j <= _MAX_NUM_OF_URLS )
            {
                URL[j].position = i;

                if ( s_Header.contains( "@" ) == true )
                    URL[j].TitleURL = s_Header.section( "@", 1, 1 );
                else
                    URL[j].TitleURL = s_Header;
            }
        }
    }

    stopProgress = incProgress( i_NumOfFiles, i_line );

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

    ++i_line;
    parseData( i_line, sl_Input.at( i_line ), s_MetadataIn, i_AreaNamePos, i_CampaignLabelPos, i_EventLabelPos, i_GearNamePos, i_DatePos, i_TimePos, i_DateTimePos, i_LatitudePos, i_LongitudePos, i_ElevationPos, URL, s_Metadata );
    addToMetadataList( s_Metadata, s_EventLabel, s_LatLon, sl_DataMetadataList );

    stopProgress = incProgress( i_NumOfFiles, i_line );

    if ( b_containsPosition == true )
    {
        while ( ( ++i_line < n ) && ( stopProgress != _APPBREAK_ ) )
        {
            parseData( i_line, sl_Input.at( i_line ), s_MetadataIn, i_AreaNamePos, i_CampaignLabelPos, i_EventLabelPos, i_GearNamePos, i_DatePos, i_TimePos, i_DateTimePos, i_LatitudePos, i_LongitudePos, i_ElevationPos, URL, s_Metadata );
            addToMetadataList( s_Metadata, s_EventLabel, s_LatLon, sl_DataMetadataList );

            stopProgress = incProgress( i_NumOfFiles, i_line );
        }
    }

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

    resetProgress( i_NumOfFiles );

    return( _NOERROR_ );
}
Exemplo n.º 13
0
int MainWindow::createKmlFile( const QString &s_FilenameIn,
                               int &i_IconColor, int &i_IconSize,
                               int &i_TracklineColor, int &i_TracklineWidth,
                               QString &s_FilenameGoogleEarthProgram, bool &b_startGoogleEarth,
                               QString &s_FilenameOut, const int i_NumOfFiles )
{
    int         i               = 0;
    int         n               = 0;

    int			stopProgress	= 0;

    int         i_ID            = 0;
    int         i_StartID       = 0;
    int         i_EndID         = 0;

    double      d_Distance      = 0.0;
    double      d_Speed         = 0.0;
    double      d_Latitude      = 0.0;
    double      d_Longitude     = 0.0;
    double      d_Latitude_old  = 0.0;
    double      d_Longitude_old = 0.0;
    double      d_Seconds_old   = 0.0;
    double      d_PlotDistance  = 100.0;

    QString     s_Date          = "";
    QString     s_Time          = "";
    QString     s_Latitude      = "";
    QString     s_Longitude     = "";
    QString     s_TrackName     = "";

    QStringList sl_Input;

    QFileInfo fi( s_FilenameIn );

// **********************************************************************************************
// read file

    QFile fin( s_FilenameIn );

    if ( fin.open( QIODevice::ReadOnly | QIODevice::Text ) == false )
        return( -10 );

    QTextStream tin( &fin );

    while ( tin.atEnd() == false )
        sl_Input.append( tin.readLine().replace( QChar( 0x00 ), "" ) );

    fin.close();

    n = sl_Input.count();

// **********************************************************************************************

    if ( ( n<2 ) || ( sl_Input.at( i++ ) != "INDEX,TAG,DATE,TIME,LATITUDE N/S,LONGITUDE E/W,HEIGHT,SPEED,HEADING,VOX" ) )
        return( _APPBREAK_ );

    i_StartID   = sl_Input.at( 1 ).section( ",", 0, 0 ).toInt();
    i_EndID     = sl_Input.at( sl_Input.count() - 1 ).section( ",", 0, 0 ).toInt();
    s_TrackName = fi.baseName();

    if ( doGPStoKmlOptionsDialog( i_StartID, i_EndID, i_IconColor, i_IconSize, i_TracklineColor, i_TracklineWidth, s_TrackName, s_FilenameGoogleEarthProgram, b_startGoogleEarth ) == QDialog::Rejected )
        return( _APPBREAK_ );

// **********************************************************************************************
// open output file

    s_FilenameOut = fi.absolutePath() + "/" + s_TrackName + ".kml";

    QFile fout( s_FilenameOut );

    if ( fout.open( QIODevice::WriteOnly | QIODevice::Text) == false )
    {
        s_FilenameOut = "";
        return( -20 );
    }

// **********************************************************************************************

    initProgress( i_NumOfFiles, s_FilenameIn, tr( "Creating KML file..." ), 2*sl_Input.count() );

// **********************************************************************************************

    QTextStream tout( &fout );
    tout.setCodec( "UTF-8" );

    tout << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << endl;
    tout << "<kml xmlns=\"http://earth.google.com/kml/2.1\">" << endl;
    tout << "<Document>" << endl;
/*
    tout << "  <ScreenOverlay>" << endl;
    tout << "    <name>Pan2Applic logo</name>" << endl;
    tout << "    <Icon><href>http://epic.awi.de/40953/121/Pan2Applic_logo.png</href></Icon>" << endl;
    tout << "    <overlayXY x=\"0\" y=\"1\" xunits=\"fraction\" yunits=\"fraction\"/>" << endl;
    tout << "    <screenXY x=\"5\" y=\"5\" xunits=\"pixels\" yunits=\"insetPixels\"/>" << endl;
    tout << "    <size x=\"200\" y=\"88\" xunits=\"pixel\" yunits=\"pixel\"/>" << endl;
    tout << "  </ScreenOverlay>" << endl;
*/
    tout << "  <Style id=\"circle-blue\"><IconStyle><Icon><href>http://epic.awi.de/40953/1/circle-blue.png</href></Icon></IconStyle></Style>" << endl;
    tout << "  <Style id=\"circle-green\"><IconStyle><Icon><href>http://epic.awi.de/40953/2/circle-green.png</href></Icon></IconStyle></Style>" << endl;
    tout << "  <Style id=\"circle-orange\"><IconStyle><Icon><href>http://epic.awi.de/40953/3/circle-orange.png</href></Icon></IconStyle></Style>" << endl;
    tout << "  <Style id=\"circle-red\"><IconStyle><Icon><href>http://epic.awi.de/40953/4/circle-red.png</href></Icon></IconStyle></Style>" << endl;
    tout << "  <Style id=\"circle-white\"><IconStyle><Icon><href>http://epic.awi.de/40953/5/circle-white.png</href></Icon></IconStyle></Style>" << endl;
    tout << "  <Style id=\"circle-yellow\"><IconStyle><Icon><href>http://epic.awi.de/40953/6/circle-yellow.png</href></Icon></IconStyle></Style>" << endl;
    tout << "  <Style id=\"square-blue\"><IconStyle><Icon><href>http://epic.awi.de/40953/7/square-blue.png</href></Icon></IconStyle></Style>" << endl;
    tout << "  <Style id=\"square-green\"><IconStyle><Icon><href>http://epic.awi.de/40953/8/square-green.png</href></Icon></IconStyle></Style>" << endl;
    tout << "  <Style id=\"square-orange\"><IconStyle><Icon><href>http://epic.awi.de/40953/9/square-orange.png</href></Icon></IconStyle></Style>" << endl;
    tout << "  <Style id=\"square-red\"><IconStyle><Icon><href>http://epic.awi.de/40953/10/square-red.png</href></Icon></IconStyle></Style>" << endl;
    tout << "  <Style id=\"square-white\"><IconStyle><Icon><href>http://epic.awi.de/40953/11/square-white.png</href></Icon></IconStyle></Style>" << endl;
    tout << "  <Style id=\"square-yellow\"><IconStyle><Icon><href>http://epic.awi.de/40953/12/square-yellow.png</href></Icon></IconStyle></Style>" << endl;
    tout << "  <Style id=\"star-blue\"><IconStyle><Icon><href>http://epic.awi.de/40953/13/star-blue.png</href></Icon></IconStyle></Style>" << endl;
    tout << "  <Style id=\"star-green\"><IconStyle><Icon><href>http://epic.awi.de/40953/14/star-green.png</href></Icon></IconStyle></Style>" << endl;
    tout << "  <Style id=\"star-orange\"><IconStyle><Icon><href>http://epic.awi.de/40953/15/star-orange.png</href></Icon></IconStyle></Style>" << endl;
    tout << "  <Style id=\"star-red\"><IconStyle><Icon><href>http://epic.awi.de/40953/16/star-red.png</href></Icon></IconStyle></Style>" << endl;
    tout << "  <Style id=\"star-white\"><IconStyle><Icon><href>http://epic.awi.de/40953/17/star-white.png</href></Icon></IconStyle></Style>" << endl;
    tout << "  <Style id=\"star-yellow\"><IconStyle><Icon><href>http://epic.awi.de/40953/18/star-yellow.png</href></Icon></IconStyle></Style>" << endl;
    tout << "  <Style id=\"triangle-blue\"><IconStyle><Icon><href>http://epic.awi.de/40953/19/triangle-blue.png</href></Icon></IconStyle></Style>" << endl;
    tout << "  <Style id=\"triangle-green\"><IconStyle><Icon><href>http://epic.awi.de/40953/20/triangle-green.png</href></Icon></IconStyle></Style>" << endl;
    tout << "  <Style id=\"triangle-orange\"><IconStyle><Icon><href>http://epic.awi.de/40953/21/triangle-orange.png</href></Icon></IconStyle></Style>" << endl;
    tout << "  <Style id=\"triangle-red\"><IconStyle><Icon><href>http://epic.awi.de/40953/22/triangle-red.png</href></Icon></IconStyle></Style>" << endl;
    tout << "  <Style id=\"triangle-white\"><IconStyle><Icon><href>http://epic.awi.de/40953/23/triangle-white.png</href></Icon></IconStyle></Style>" << endl;
    tout << "  <Style id=\"triangle-yellow\"><IconStyle><Icon><href>http://epic.awi.de/40953/24/triangle-yellow.png</href></Icon></IconStyle></Style>" << endl;

// **********************************************************************************************
// Way points

    tout << "<Folder>" << endl;
    tout << "<name>Point Set</name>" << endl;
    tout << "<open>0</open>" << endl;

    while ( ( i<n ) && ( stopProgress != _APPBREAK_ ) )
    {
        if ( sl_Input.at( i ).section( ",", 1, 1 ) == "T" )
        {
            i_ID = sl_Input.at( i ).section( ",", 0, 0 ).toInt();

            if ( ( i_StartID <= i_ID ) && ( i_ID <= i_EndID ) )
            {
                s_Time      = sl_Input.at( i ).section( ",", 3, 3 ).left( 2 ) + ":" + sl_Input.at( i ).section( ",", 3, 3 ).mid( 2, 2 ) + ":" + sl_Input.at( i ).section( ",", 3, 3 ).mid( 4, 2 );
                s_Date      = "20" + sl_Input.at( i ).section( ",", 2, 2 ).left( 2 ) + "-" + sl_Input.at( i ).section( ",", 2, 2 ).mid( 2, 2 ) + "-" + sl_Input.at( i ).section( ",", 2, 2 ).mid( 4, 2 );

                s_Latitude  = extractLatitude( sl_Input.at(i) );
                s_Longitude = extractLongitude( sl_Input.at(i) );

                d_Latitude  = s_Latitude.toDouble();
                d_Longitude = s_Longitude.toDouble();

                d_Distance  = calculateDistance( d_Latitude, d_Longitude, d_Latitude_old, d_Longitude_old ); // [m]

                if ( ( i_ID == i_StartID ) || ( i_ID == i_EndID ) || ( d_Distance > d_PlotDistance ) )
                {
                    d_Speed = 3.6 * d_Distance/( (double) i - d_Seconds_old ); // [m/s] -> [km/h]

                    tout << "<Placemark>";
//                  tout << "<name>" << s_Time << "</name>";

                    switch ( i_IconColor )
                    {
                        case _RED_:
                            tout << "<styleUrl>#red</styleUrl>";
                            break;
                        case _GREEN_:
                            tout << "<styleUrl>#green</styleUrl>";
                            break;
                        case _BLUE_:
                            tout << "<styleUrl>#blue</styleUrl>";
                            break;
                        case _ORANGE_:
                            tout << "<styleUrl>#orange</styleUrl>";
                            break;
                        case _YELLOW_:
                            tout << "<styleUrl>#yellow</styleUrl>";
                            break;
                        default:
                            tout << "<styleUrl>#red</styleUrl>";
                            break;
                    }

                    tout << "<Style><IconStyle>" << QString( "<scale>%1</scale>" ).arg( (float) i_IconSize/100. ) << "</IconStyle></Style>";
                    tout << "<Point><coordinates>" << s_Longitude << "," << s_Latitude << "</coordinates></Point>";
                    tout << "<description>" << endl;
                    tout << "<![CDATA[Time: " << s_Time << "<br />Date: " << s_Date << "<br />Latitude: " << d_Latitude << "° N<br />Longitude: " << d_Longitude << "° E<br />Altitude: " << sl_Input.at( i ).section( ",", 6, 6 ).simplified() << " m<br />Speed: " << d_Speed << " km/h<br />ID: " << i_ID << "<br />]]>" << endl;
                    tout << "</description>" << endl;
                    tout << "</Placemark>" << endl;

                    d_Latitude_old  = d_Latitude;
                    d_Longitude_old = d_Longitude;
                    d_Seconds_old   = (double) i;

                    if ( d_Speed < 50. )
                        d_PlotDistance = 100;
                    else
                        d_PlotDistance = 1000;
                }
            }
        }

        stopProgress = incProgress( i_NumOfFiles, ++i );
    }

    tout << "</Folder>" << endl;

// **********************************************************************************************
// Track line

    tout << "<Placemark><name>Trackline</name>" << endl;

    switch ( i_TracklineColor )
    {
        case _RED_:
            tout << "<Style><LineStyle><color>ff0000ff</color>";
            break;
        case _GREEN_:
            tout << "<Style><LineStyle><color>ff00ff00</color>";
            break;
        case _BLUE_:
            tout << "<Style><LineStyle><color>ffff0000</color>";
            break;
        case _ORANGE_:
            tout << "<Style><LineStyle><color>ff0099ff</color>";
            break;
        case _YELLOW_:
            tout << "<Style><LineStyle><color>ff33ffff</color>";
            break;
        default:
            tout << "<Style><LineStyle><color>ff0099ff</color>";
            break;
    }

    tout << "<width>" << (float) i_TracklineWidth/10. << "</width></LineStyle></Style>" << endl;

    tout << "<LineString>" << endl;
    tout << "<tessellate>1</tessellate>" << endl;
    tout << "<coordinates>" << endl;

    i = 1;

    while ( ( i<n ) && ( stopProgress != _APPBREAK_ ) )
    {
        if ( sl_Input.at( i ).section( ",", 1, 1 ) == "T" )
        {
            i_ID = sl_Input.at( i ).section( ",", 0, 0 ).toInt();

            if ( ( i_StartID <= i_ID ) && ( i_ID <= i_EndID ) )
            {
                s_Latitude  = extractLatitude( sl_Input.at(i) );
                s_Longitude = extractLongitude( sl_Input.at(i) );

                tout << s_Longitude << "," << s_Latitude << "," << sl_Input.at( i ).section( ",", 6, 6 ).simplified() << endl;
            }
        }

        stopProgress = incProgress( i_NumOfFiles, ++i+n );
    }

    tout << "</coordinates>" << endl;
    tout << "</LineString>" << endl;
    tout << "</Placemark>" << endl;
    tout << "</Document>" << endl;
    tout << "</kml>" << endl;

    fout.close();

    resetProgress( i_NumOfFiles );

    if ( stopProgress == _APPBREAK_ )
        return( _APPBREAK_ );

    return( _NOERROR_ );
}
Exemplo n.º 14
0
bool SurfaceNetworkBuilder::build(model::Model &model)
{
  bool first = true;
  bool nowarnings = true;
  QVector<openstudio::Handle> used;

  m_logSink.setThreadId(QThread::currentThread());
  m_logSink.resetStringStream();

  std::vector<model::Surface> surfaces = model.getConcreteModelObjects<model::Surface>();

  initProgress(surfaces.size(),"Processing surfaces for network creation");

  for (model::Surface surface : surfaces) {
    if(!first) {
      progress();
    }
    first=false;
    std::string bc = surface.outsideBoundaryCondition();
    if(bc == "Outdoors") {
      // Get the associated thermal zone
      boost::optional<openstudio::model::Space> space = surface.space();
      if(!space) {
        LOG(Warn, "Unattached surface '" << openstudio::toString(surface.handle()) << "'");
        nowarnings = false;
        continue;
      }
      boost::optional<openstudio::model::ThermalZone> thermalZone = space->thermalZone();
      if(!thermalZone) {
        LOG(Warn, "Unzoned space '" << openstudio::toString(space->handle()) << "'");
        nowarnings = false;
        continue;
      }
      // If we made it to here, then the exterior surface is good.
      linkExteriorSurface(thermalZone.get(),space.get(),surface);
      for(model::SubSurface subSurface : surface.subSurfaces()) {
        linkExteriorSubSurface(thermalZone.get(),space.get(),surface,subSurface);
      }
    } else if(!used.contains(surface.handle()) && bc == "Surface") {
      // Get the associated thermal zone
      boost::optional<openstudio::model::Space> space = surface.space();
      if(!space) {
        LOG(Warn, "Unattached surface '" << openstudio::toString(surface.handle()) << "'");
        nowarnings = false;
        continue;
      }
      boost::optional<openstudio::model::ThermalZone> thermalZone = space->thermalZone();
      if(!thermalZone) {
        LOG(Warn, "Unzoned space '" << openstudio::toString(space->handle()) << "'");
        nowarnings = false;
        continue;
      }
      boost::optional<openstudio::model::Surface> adjacentSurface = surface.adjacentSurface();
      if(!adjacentSurface) {
        LOG(Error, "Unable to find adjacent surface for surface '" << openstudio::toString(surface.handle()) << "'");
        nowarnings = false;
        continue;
      }
      boost::optional<openstudio::model::Space> adjacentSpace = adjacentSurface->space();
      if(!adjacentSpace) {
        LOG(Error, "Unattached adjacent surface '" << openstudio::toString(adjacentSurface->handle()) << "'");
        nowarnings = false;
        continue;
      }
      boost::optional<openstudio::model::ThermalZone> adjacentZone = adjacentSpace->thermalZone();
      if(!thermalZone) {
        LOG(Warn, "Unzoned adjacent space '" << openstudio::toString(adjacentSpace->handle()) << "'");
        nowarnings = false;
        continue;
      }
      // We could punt the checking of subsurfaces until later, but it is best to get this out of the way now
      for(model::SubSurface subSurface : surface.subSurfaces()) {
        boost::optional<model::SubSurface> adjacentSubSurface = subSurface.adjacentSubSurface();
        if(!adjacentSubSurface) {
          LOG(Warn, "Unable to find adjacent subsurface for subsurface of '" << openstudio::toString(surface.handle()) << "'");
          nowarnings = false;
          continue;
        }
        if(adjacentSubSurface->surface() != adjacentSurface) {
          LOG(Warn, "Adjacent subsurface for subsurface of '" << openstudio::toString(surface.handle()) << "' is not attached to the expected surface");
          nowarnings = false;
          continue;
        }
      }
      // Ok, now we a surface, a space, a zone, an adjacent surface, an adjacent space, and an adjacent zone. Finally.
      used.push_back(adjacentSurface->handle());
      if(thermalZone == adjacentZone) {
        continue;
      }
      // Now have a surface that is fully connected and separates two zones so it can be linked
      linkInteriorSurface(thermalZone.get(),space.get(),surface,adjacentSurface.get(),adjacentSpace.get(),adjacentZone.get());
      // Link subsurfaces
      for(model::SubSurface subSurface : surface.subSurfaces()) {
        // Now we need to check the connections as we did with the surface
        boost::optional<model::SubSurface> adjacentSubSurface = subSurface.adjacentSubSurface();
        if(!adjacentSubSurface) {
          LOG(Warn, "Unable to find adjacent subsurface for subsurface of '" << openstudio::toString(surface.handle()) << "'");
          nowarnings = false;
          continue;
        }
        if(adjacentSubSurface->surface() != adjacentSurface) {
          LOG(Warn, "Adjacent subsurface for subsurface of '" << openstudio::toString(surface.handle()) << "' is not attached to the expected surface");
          nowarnings = false;
          continue;
        }
        // If we made it here, then the subsurface is fully connected and can be linked
        linkInteriorSubSurface(thermalZone.get(),space.get(),surface,subSurface,adjacentSubSurface.get(),adjacentSurface.get(),
          adjacentSpace.get(),adjacentZone.get());
      }
    }
  }
  if(surfaces.size()>0) {
    progress();
  }
  return nowarnings;
}
Exemplo n.º 15
0
int MainWindow::convertTSG( const QString &s_FilenameIn, const QString &s_FilenameOut, const int i_CodecInput, const int i_CodecOutput, const int i_EOL, const int i_NumOfFiles )
{
    int         i               = 1;
    int         n               = 0;

    int			stopProgress	= 0;

    QString     s               = "";
    QString     s_DateTime      = "";
    QString     s_Position      = "";
    QString     s_EOL           = setEOLChar( i_EOL );

    QStringList sl_Input;

// **********************************************************************************************
// read file

    if ( ( n = readFile( s_FilenameIn, sl_Input, i_CodecInput ) ) < 1 )
        return( -10 );

// **********************************************************************************************
// open output file

    QFile fout( s_FilenameOut );

    if ( fout.open( QIODevice::WriteOnly | QIODevice::Text) == false )
        return( -20 );

    QTextStream tout( &fout );

    switch ( i_CodecOutput )
    {
    case _SYSTEM_:
        break;
    case _LATIN1_:
        tout.setCodec( QTextCodec::codecForName( "ISO 8859-1" ) );
        break;
    case _APPLEROMAN_:
        tout.setCodec( QTextCodec::codecForName( "Apple Roman" ) );
        break;
    default:
        tout.setCodec( QTextCodec::codecForName( "UTF-8" ) );
        break;
    }

// **********************************************************************************************

    initProgress( i_NumOfFiles, s_FilenameIn, tr( "Converting TSG data..." ), sl_Input.count() );

// **********************************************************************************************

    tout << "Event label" << "\t" << "Date/Time" << "\t" << "Latitude" << "\t" << "Longitude" << "\t";
    tout << "Depth, water [m]" << "\t" << "Temperature, water [C]@ITS-90" << "\t" << "Salinity []" << s_EOL;

    tout << "PS-track";

    while ( ( i<sl_Input.count() ) && ( stopProgress != _APPBREAK_ ) )
    {
        s_DateTime = sl_Input.at( i ).section( "\t", 0, 0 );
        s_DateTime.replace( " ", "T" );

        s_Position = sl_Input.at( i ).section( "\t", 1, 2 );
        s_Position.replace( " ", "" );

        s = sl_Input.at( i ).section( "\t", 3, 4 );
        s.replace( " ", "" );
        s.replace( "-999.000000", "" );

        if ( s != "\t" )
            tout << "\t" + s_DateTime << "\t" << s_Position << "\t5\t" << s << s_EOL;

        s = sl_Input.at( i ).section( "\t", 5, 6 );
        s.replace( " ", "" );
        s.replace( "-999.000000", "" );

        if ( s != "\t" )
            tout << "\t" + s_DateTime << "\t" << s_Position << "\t11\t" << s << s_EOL;

        stopProgress = incProgress( i_NumOfFiles, ++i );
    }

    fout.close();

    resetProgress( i_NumOfFiles );

    if ( stopProgress == _APPBREAK_ )
        return( _APPBREAK_ );

    return( _NOERROR_ );
}
Exemplo n.º 16
0
int MainWindow::createOceanDataViewFile( QStringList &sl_MetadataList, QStringList &sl_ParameterList, const QString &s_FilenameOut,
                                         const int i_CodecInput, const int i_Env, const int i_DeviceTypeOceanDataView,
                                         const bool b_showShortName, const bool b_showMethod, const bool b_showComment,
                                         const bool b_usePANGAEAQualityFlags, const bool b_setGeocode, const bool b_addLineNo,
                                         const float f_GEOCODE_min, const float f_GEOCODE_max, const QString &s_GEOCODE_min,
                                         const QString &s_GEOCODE_max, const bool b_setGearID, const int i_GearID, const int i_NumOfFiles )
{
    QVector<int>    vi_pos;
    QVector<int>    vi_posQV;
    QVector<int>    vi_SpecialPos;

    int             i_NumOfRemovedLines = 0;
    int             i_NumOfHeaderItems  = 0;

    int             i_GeocodePos        = -1;
    int             i_GearIDPos         = -1;

    int             i_File              = 0;
    int             i_stopFileProgress  = 0;

    int             stopProgress        = 0;
    int             err                 = _NOERROR_;

    int             i                   = 0;
    int             n                   = 0;

    bool            b_containsDOI       = false;

    QString         s_FieldDelimiter    = "\t";
    QString         s_Environment       = "";
    QString         s_DeviceType        = "*";
    QString         s_Output            = "";
    QString         s_FilenameIn        = sl_MetadataList.at( 1 ).section( "\t", _FILENAMEPOS, _FILENAMEPOS );

    QStringList     sld_ParameterList;
    QStringList     sl_Input;
    QStringList     sl_Output;

    QDateTime       dt_GEOCODE_min( QDateTime::fromString( (QString) s_GEOCODE_min, Qt::ISODate ) );
    QDateTime       dt_GEOCODE_max( QDateTime::fromString( (QString) s_GEOCODE_max, Qt::ISODate ) );

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

    if ( sl_ParameterList.count() == 0 )
        return( -60 );

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

    i_NumOfHeaderItems = buildODVHeader( sl_Output, sl_ParameterList, vi_posQV, i_Env, b_showShortName, b_showMethod, b_showComment, b_usePANGAEAQualityFlags );

    if ( i_NumOfHeaderItems < 0 )
        return( i_NumOfHeaderItems ); // return as error, -70 = Latitude/Longitude not given, -71 = Latitude not given, -72 = Longitude not given

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

    QFile ftext( s_FilenameOut );

    if ( ftext.open( QIODevice::WriteOnly | QIODevice::Text) == false )
        return( -20 );

    QTextStream tout( &ftext );

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

    initFileProgress( i_NumOfFiles, s_FilenameIn, tr( "Creating Ocean Data View file..." ) );

//-----------------------------------------------------------------------------------------------------------------------
// write header

    tout << "//<Version>ODV Spreadsheet V4.0</Version>" << endl;
    tout << "//<Creator>" << "</Creator>" << endl;
    tout << "//<CreateTime>" << QDateTime::currentDateTime().toString( "yyyy-MM-ddThh:mm" ) << "</CreateTime>" << endl;
    tout << "//<Software>" << getApplicationName( true ) << " " << _VERSION_ << "</Software>" << endl;
    tout << "//<Source>" << QDir::toNativeSeparators( s_FilenameOut ) << "</Source>" << endl;
    tout << "//<SourceLastModified>" << QDateTime::currentDateTime().toString( "yyyy-MM-ddThh:mm" ) << "</SourceLastModified>" << endl;
    tout << "//<DataField>GeneralField</DataField>" << endl;
    tout << "//<DataType>GeneralType</DataType>" << endl;
    tout << "//" << endl;

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

    i_GeocodePos   = getGeocodePosition( sl_ParameterList, i_Env );
    i_GearIDPos    = getGearIDPosition( sl_ParameterList );
    b_containsDOI  = sl_Output.contains( "DOI:METAVAR:TEXT:51" );

    tout << sl_Output.join( s_FieldDelimiter ) << endl;

//-----------------------------------------------------------------------------------------------------------------------
// find position of date/time parameters

    getSpecialPos( sl_ParameterList, vi_SpecialPos );

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

    s_DeviceType = setDeviceType( i_DeviceTypeOceanDataView );

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

    i_File = 1;

    while ( ( i_File <= i_NumOfFiles ) && ( err == _NOERROR_ ) && ( i_stopFileProgress != _APPBREAK_ ) )
    {
        if ( containsSelectedEnvironment( _SELECTPARAMETER, sl_MetadataList.at( i_File ).section( "\t", _ENVIRONMENTPOS, _ENVIRONMENTPOS ).toInt(), i_Env ) == true )
        {
            s_FilenameIn = sl_MetadataList.at( i_File ).section( "\t", _FILENAMEPOS, _FILENAMEPOS );

            if ( ( n = readFile( s_FilenameIn, sl_Input, i_CodecInput ) ) > 0 )
            {
                i = 0;

                sld_ParameterList.clear();
                vi_pos.clear();

                initProgress( i_NumOfFiles, s_FilenameIn, tr( "Ocean Data View converter is working..." ), n );

                setStatusBarFileInProgress( s_FilenameIn );

//-----------------------------------------------------------------------------------------------------------------------
// read header and find position of parameter

                s_Environment = sl_MetadataList.at( i_File ).section( "\t", _ENVIRONMENTPOS, _ENVIRONMENTPOS ) + _PSEPARATOR_;

                stopProgress = incProgress( i_NumOfFiles, i );

                if ( sl_Input.at( i ).startsWith( "/* DATA DESCRIPTION:" ) == true ) // file starts with PANGAEA header
                {
                    while ( ( i < n ) && ( sl_Input.at( i ).startsWith( "*/" ) == false ) )
                    {
                        if ( sl_Input.at( i ).startsWith( "Parameter(s):" ) == true )
                        {
                            while ( ( i < n ) && ( ( sl_Input.at( i ).startsWith( "Parameter(s):" ) == true ) || ( sl_Input.at( i ).startsWith( "\t" ) == true ) ) )
                            {
                                sld_ParameterList.append( s_Environment + buildParameter( sl_Input.at( i ).section( "\t", 1, 1 ) ) );

                                if ( ++i < n )
                                    stopProgress = incProgress( i_NumOfFiles, i );
                            }
                        }

                        if ( ++i < n )
                            stopProgress = incProgress( i_NumOfFiles, i );
                    }

                    for ( int j=0; j<sl_ParameterList.count(); ++j )
                        vi_pos.append( containsParameter( true, sld_ParameterList, sl_ParameterList.at( j ), b_showShortName, b_showMethod, b_showComment ) );

                    if ( ++i < n )
                        stopProgress = incProgress( i_NumOfFiles, i );
                }
                else
                {
                    sld_ParameterList = buildParameterList( s_Environment, sl_Input.at( i ) );  // not a PANGAEA dataset

                    for ( int j=0; j<sl_ParameterList.count(); ++j )
                        vi_pos.append( containsParameter( false, sld_ParameterList, sl_ParameterList.at( j ), b_showShortName, b_showMethod, b_showComment ) );
                }

//-----------------------------------------------------------------------------------------------------------------------
// write output string

                if ( ( b_setGeocode == true ) || ( b_setGearID == true ) )
                {
                    while ( ( ++i < n ) && ( stopProgress != _APPBREAK_ ) )
                    {
                        sl_Output = buildODVOutputStr( i+1, b_addLineNo, sl_Input.at( i ), sl_MetadataList.at( i_File ), vi_pos, vi_posQV, vi_SpecialPos, b_usePANGAEAQualityFlags, b_containsDOI, s_DeviceType, s_FieldDelimiter );

                        if ( writeDataLine( b_setGeocode, b_setGearID, i_GeocodePos, i_GearIDPos, sl_Output, i_Env, dt_GEOCODE_min, dt_GEOCODE_max, f_GEOCODE_min, f_GEOCODE_max, i_GearID ) == true )
                        {
                            s_Output = sl_Output.join( s_FieldDelimiter );

                            if ( s_Output.contains( "delete line" ) == false )
                                tout << s_Output  << endl;
                            else
                                ++i_NumOfRemovedLines;
                        }

                        stopProgress = incProgress( i_NumOfFiles, i );
                    }
                }
                else
                {
                    while ( ( ++i < n ) && ( stopProgress != _APPBREAK_ ) )
                    {
                        sl_Output = buildODVOutputStr( i+1, b_addLineNo, sl_Input.at( i ), sl_MetadataList.at( i_File ), vi_pos, vi_posQV, vi_SpecialPos, b_usePANGAEAQualityFlags, b_containsDOI, s_DeviceType, s_FieldDelimiter );
                        s_Output  = sl_Output.join( s_FieldDelimiter );

                        if ( s_Output.contains( "delete line" ) == false )
                            tout << s_Output  << endl;
                        else
                            ++i_NumOfRemovedLines;

                        stopProgress = incProgress( i_NumOfFiles, i );
                    }
                }

                resetProgress( i_NumOfFiles );
            }
        }

        i_stopFileProgress = incFileProgress( i_NumOfFiles, i_File++ );
    }

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

    resetFileProgress( i_NumOfFiles );

    ftext.close();

    return( i_NumOfRemovedLines );
}
int MainWindow::RadiosondeEquipmentConverter( const QString &s_FilenameIn, QStringList &sl_FilenameOut, structMethod *Method_ptr, structStation *Station_ptr, const int i_NumOfFiles )
{
    int				i_Year			= 2000;
    int				i_Month			= 1;
    int				i_Day			= 1;
    int				i_StationNumber	= 0;
    int				i_MethodID		= 0;

    QString			InputStr		= "";

    QString			s_RadiosondeIdentification = "";

    QString			SearchString1	= "*C0005";
    QString			SearchString2	= "*U0005";

    QString			s_StationName	= "";
    QString			s_EventLabel	= "";

    unsigned int	ui_length		= 1;
    unsigned int	ui_filesize		= 1;

    bool			b_Stop			= false;

// ***********************************************************************************************************************

    QFileInfo fi( s_FilenameIn );

    if ( ( fi.exists() == false ) || ( fi.suffix().toLower() == "zip" ) || ( fi.suffix().toLower() == "gz" ) )
        return( _FILENOEXISTS_ );

// ***********************************************************************************************************************

    QFile fin( s_FilenameIn );

    if ( fin.open( QIODevice::ReadOnly | QIODevice::Text ) == false )
        return( -10 );

    ui_filesize = fin.size();

// ***********************************************************************************************************************

    QTextStream tin( &fin );

// ***********************************************************************************************************************

    initProgress( i_NumOfFiles, s_FilenameIn, tr( "Radiosonde equipment converter working ..." ), 100 );

// ***********************************************************************************************************************

    InputStr  = tin.readLine();
    ui_length = incProgress( i_NumOfFiles, ui_filesize, ui_length, InputStr );

    if ( ( InputStr.startsWith( "*C0001" ) == false ) && ( InputStr.startsWith( "*U0001" ) == false ) )
    {
        resetProgress( i_NumOfFiles );
        fin.close();
        return( -40 );
    }

// ***********************************************************************************************************************

    InputStr  = tin.readLine();
    ui_length = incProgress( i_NumOfFiles, ui_filesize, ui_length, InputStr );

    i_StationNumber	= InputStr.left( 3 ).toInt();
    s_StationName	= findStationName( i_StationNumber, Station_ptr );
    s_EventLabel	= findEventLabel( i_StationNumber, Station_ptr );

// ***********************************************************************************************************************

    i_Day   = 1;
    i_Month	= InputStr.mid( 4, 2 ).toInt();
    i_Year	= InputStr.mid( 7, 4 ).toInt();

    QDateTime dt = QDateTime().toUTC();

    dt.setDate( QDate( i_Year, i_Month, i_Day ) );
    dt.setTime( QTime( 0, 0, 0 ) );

// ***********************************************************************************************************************

    if ( checkFilename( fi.fileName(), s_EventLabel, InputStr.mid( 4, 2 ), InputStr.mid( 9, 2 ) ) == false )
    {
        resetProgress( i_NumOfFiles );
        fin.close();
        return( -41 );
    }

// ***********************************************************************************************************************

    QFile fout( fi.absolutePath() + "/" + s_EventLabel + "_" + dt.toString( "yyyy-MM" ) + "_0005.txt" );

    if ( fout.open( QIODevice::WriteOnly | QIODevice::Text ) == false )
    {
        resetProgress( i_NumOfFiles );
        fin.close();
        return( -20 );
    }

    QTextStream tout( &fout );

    appendItem( sl_FilenameOut, fout.fileName() );

// ***********************************************************************************************************************
// LR0005

    tout << "File name\tStation ID\tEvent label\tStation\tYYYY-MM\t";
    tout << "Manufacturer\tLocation\tDistance from radiation site [km]\t";
    tout << "Time of 1st launch [hh]\tTime of 2nd launch [hh]\tTime of 3rd launch [hh]\t";
    tout << "Time of 4th launch [hh]\tIdentification of radiosonde\tRemarks\t";
    tout << "PANGAEA method\tPANGAEA method ID" << endl;

    while ( ( tin.atEnd() == false ) && ( ui_length != (unsigned int) _APPBREAK_ ) && ( b_Stop == false ) )
    {
        InputStr = tin.readLine();
        ui_length = incProgress( i_NumOfFiles, ui_filesize, ui_length, InputStr );

        if ( ( InputStr.startsWith( SearchString1 ) == true ) || ( InputStr.startsWith( SearchString2 ) == true ) )
        {
            tout << s_EventLabel.toLower() << dt.toString( "MMyy" ) << ".dat" << "\t";
            tout << i_StationNumber << "\t" << s_EventLabel << "\t" << s_StationName << "\t" << dt.toString( "yyyy-MM" ) << "\t";

            InputStr = tin.readLine();
            ui_length	= incProgress( i_NumOfFiles, ui_filesize, ui_length, InputStr );

            if ( InputStr.simplified().right( 1 ) == "Y" )
            {
                InputStr	= tin.readLine();
                ui_length	= incProgress( i_NumOfFiles, ui_filesize, ui_length, InputStr );

                tout << InputStr.left( 30 ).simplified() << "\t";
                tout << InputStr.mid( 30, 25 ).simplified() << "\t";
                tout << InputStr.mid( 57, 3 ) << "\t";
                tout << InputStr.mid( 61, 2 ) << "\t";
                tout << InputStr.mid( 64, 2 ) << "\t";
                tout << InputStr.mid( 67, 2 ) << "\t";
                tout << InputStr.mid( 70, 2 ) << "\t";
                tout << InputStr.mid( 73, 5 ).simplified() << "\t";

                s_RadiosondeIdentification = InputStr.left( 30 ).simplified();

                if ( InputStr.mid( 73, 5 ).simplified().isEmpty() == false )
                    s_RadiosondeIdentification += ", " + InputStr.mid( 73, 5 ).simplified();

                i_MethodID	= findMethodID( s_RadiosondeIdentification, Method_ptr );

                InputStr	= tin.readLine();
                ui_length	= incProgress( i_NumOfFiles, ui_filesize, ui_length, InputStr );

                tout << InputStr.simplified() << "\t" << "Radiosonde, " << s_RadiosondeIdentification << "\t";
                tout << i_MethodID << endl;
            }

            b_Stop = true;
        }

        // Abort if first data record reached
        if ( ( InputStr.startsWith( "*C0100" ) == true ) || ( InputStr.startsWith( "*U0100" ) == true ) )
            b_Stop = true;
    }

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

    resetProgress( i_NumOfFiles );

    fin.close();
    fout.close();

    if ( ui_length == (unsigned int) _APPBREAK_ )
        return( _APPBREAK_ );

    return( _NOERROR_ );
}
Exemplo n.º 18
0
int MainWindow::convertSPE( const QString &s_FilenameIn, const QString &s_FilenameOut, const int i_CodecInput, const int i_CodecOutput, const int i_EOL, const int i_NumOfFiles )
{
    int         i               = 1;
    int         j               = 0;
    int         k               = 0;
    int         n               = 0;

    int			stopProgress	= 0;

    bool        b_datafound     = false;

    QString     tempStr         = "";
    QString     s_EOL           = setEOLChar( i_EOL );

    QStringList sl_Input;

// **********************************************************************************************
// read file

    if ( ( n = readFile( s_FilenameIn, sl_Input, i_CodecInput ) ) < 1 )
        return( -10 );

// **********************************************************************************************
// open output file

    QFile fout( s_FilenameOut );

    if ( fout.open( QIODevice::WriteOnly | QIODevice::Text) == false )
        return( -20 );

    QTextStream tout( &fout );

    switch ( i_CodecOutput )
    {
    case _SYSTEM_:
        break;
    case _LATIN1_:
        tout.setCodec( QTextCodec::codecForName( "ISO 8859-1" ) );
        break;
    case _APPLEROMAN_:
        tout.setCodec( QTextCodec::codecForName( "Apple Roman" ) );
        break;
    default:
        tout.setCodec( QTextCodec::codecForName( "UTF-8" ) );
        break;
    }

// **********************************************************************************************

    initProgress( i_NumOfFiles, s_FilenameIn, tr( "Converting SPE data..." ), sl_Input.count() );

// **********************************************************************************************

    while ( ( b_datafound == false ) && ( i<sl_Input.count() ) && ( stopProgress != _APPBREAK_ ) )
    {
        if ( sl_Input.at( i ).startsWith( "$DATA:") == true )
            b_datafound = true;

        stopProgress = incProgress( i_NumOfFiles, ++i );
    }

    if ( b_datafound == true )
    {
        tempStr = sl_Input.at( i++ ).split( QRegularExpression( "\\s+" ) ).join( "\t" );
        k       = tempStr.section( "\t", 1, 1 ).toInt();

        tout << "Channel" << "\t" << "cps" << s_EOL;

        while ( ( i<sl_Input.count() ) && ( stopProgress != _APPBREAK_ ) )
        {
            tempStr = sl_Input.at( i ).split( QRegularExpression( "\\s+" ) ).join( "\t" );

            n = NumOfSections( tempStr );

            for ( j=1; j<n; j++ )
                tout << QString( "%1\t%2" ).arg( k++ ).arg( tempStr.section( "\t", j, j ) ) << s_EOL;

            stopProgress = incProgress( i_NumOfFiles, ++i );
        }
    }
    else
    {
        tout << "No data found! Wrong format." << s_EOL;
    }

// **********************************************************************************************

    fout.close();

    resetProgress( i_NumOfFiles );

    if ( stopProgress == _APPBREAK_ )
        return( _APPBREAK_ );

    return( _NOERROR_ );
}
Exemplo n.º 19
0
int MainWindow::replaceCharactersAtPosition( const QString &s_FilenameIn, const QString &s_FilenameOut, const int i_CodecInput, const int i_CodecOutput, const int i_EOL, const QString &s_CharacterPositionsList, const QString &ReplaceStr, const bool b_SkipEmptyLines, const bool b_SkipCommentLines, const int i_NumOfFiles )
{
    int         i               = 0;
    int         n               = 0;
    int         m               = 0;
    int         stopProgress    = 0;

    QString     s_Output        = "";
    QString     s_EOL           = setEOLChar( i_EOL );

    QStringList sl_Input;

    QList<int>  il_PositionList;

// **********************************************************************************************
// read file

    if ( ( n = readFile( s_FilenameIn, sl_Input, i_CodecInput ) ) < 1 )
        return( n );

    if ( ( m = sl_Input.at( 0 ).length() ) < 1 )
        return( -80 );

    il_PositionList = scanList( _REPLACECHARS, 99999, s_CharacterPositionsList );

    if ( il_PositionList.count() < 1 )
    {
        QFile::remove( s_FilenameOut ); // if exists from older run
        return( -81 );
    }

// **********************************************************************************************
// open output file

    QFile fout( s_FilenameOut );

    if ( fout.open( QIODevice::WriteOnly | QIODevice::Text) == false )
        return( -20 );

    QTextStream tout( &fout );

    switch ( i_CodecOutput )
    {
    case _SYSTEM_:
        break;
    case _LATIN1_:
        tout.setCodec( QTextCodec::codecForName( "ISO 8859-1" ) );
        break;
    case _APPLEROMAN_:
        tout.setCodec( QTextCodec::codecForName( "Apple Roman" ) );
        break;
    default:
        tout.setCodec( QTextCodec::codecForName( "UTF-8" ) );
        break;
    }

// **********************************************************************************************

    initProgress( i_NumOfFiles, s_FilenameIn, tr( "Replace characters at position..." ), sl_Input.count() );

    while ( ( i < n ) && ( stopProgress != _APPBREAK_ ) )
    {
        s_Output = sl_Input.at( i ).left( il_PositionList.at( 0 ) );

        for ( int j=0; j<il_PositionList.count()-1; j++ )
            s_Output.append( ReplaceStr + sl_Input.at( i ).mid( il_PositionList.at( j ) + 1,  il_PositionList.at( j+1 ) - il_PositionList.at( j ) - 1 ) );

        s_Output.append( ReplaceStr + sl_Input.at( i ).mid( il_PositionList.last() + 1 ) );

        s_Output.replace( "^t", "\t" );
        s_Output.replace( "^n", "\n" );

        if ( LineCanBeWritten( s_Output, b_SkipEmptyLines, b_SkipCommentLines ) == true )
            tout << s_Output << s_EOL;

        stopProgress = incProgress( i_NumOfFiles, ++i );
    }

    resetProgress( i_NumOfFiles );

// **********************************************************************************************

    fout.close();

    if ( stopProgress == _APPBREAK_ )
        return( _APPBREAK_ );

    return( _NOERROR_ );
}
Exemplo n.º 20
0
MainWindow::MainWindow() :
	m_workspace( NULL ),
	m_templatesMenu( NULL ),
	m_recentlyOpenedProjectsMenu( NULL ),
	m_toolsMenu( NULL ),
	m_autoSaveTimer( this ),
	m_viewMenu( NULL ),
	m_metronomeToggle( 0 ),
	m_session( Normal )
{
	setAttribute( Qt::WA_DeleteOnClose );

	QWidget * main_widget = new QWidget( this );
	QVBoxLayout * vbox = new QVBoxLayout( main_widget );
	vbox->setSpacing( 0 );
	vbox->setMargin( 0 );

	QWidget * w = new QWidget( main_widget );
	QHBoxLayout * hbox = new QHBoxLayout( w );
	hbox->setSpacing( 0 );
	hbox->setMargin( 0 );

	SideBar * sideBar = new SideBar( Qt::Vertical, w );

	QSplitter * splitter = new QSplitter( Qt::Horizontal, w );
	splitter->setChildrenCollapsible( false );

	ConfigManager* confMgr = ConfigManager::inst();

	emit initProgress(tr("Preparing plugin browser"));
	sideBar->appendTab( new PluginBrowser( splitter ) );
	emit initProgress(tr("Preparing file browsers"));
	sideBar->appendTab( new FileBrowser(
				confMgr->userProjectsDir() + "*" +
				confMgr->factoryProjectsDir(),
					"*.mmp *.mmpz *.xml *.mid",
							tr( "My Projects" ),
					embed::getIconPixmap( "project_file" ).transformed( QTransform().rotate( 90 ) ),
							splitter, false, true ) );
	sideBar->appendTab( new FileBrowser(
				confMgr->userSamplesDir() + "*" +
				confMgr->factorySamplesDir(),
					"*", tr( "My Samples" ),
					embed::getIconPixmap( "sample_file" ).transformed( QTransform().rotate( 90 ) ),
							splitter, false, true ) );
	sideBar->appendTab( new FileBrowser(
				confMgr->userPresetsDir() + "*" +
				confMgr->factoryPresetsDir(),
					"*.xpf *.cs.xml *.xiz",
					tr( "My Presets" ),
					embed::getIconPixmap( "preset_file" ).transformed( QTransform().rotate( 90 ) ),
							splitter , false, true  ) );
	sideBar->appendTab( new FileBrowser( QDir::homePath(), "*",
							tr( "My Home" ),
					embed::getIconPixmap( "home" ).transformed( QTransform().rotate( 90 ) ),
							splitter, false, false ) );


	QStringList root_paths;
	QString title = tr( "Root directory" );
	bool dirs_as_items = false;

#ifdef LMMS_BUILD_APPLE
	title = tr( "Volumes" );
	root_paths += "/Volumes";
#elif defined(LMMS_BUILD_WIN32)
	title = tr( "My Computer" );
	dirs_as_items = true;
#endif

#if ! defined(LMMS_BUILD_APPLE)
	QFileInfoList drives = QDir::drives();
	for( const QFileInfo & drive : drives )
	{
		root_paths += drive.absolutePath();
	}
#endif

	sideBar->appendTab( new FileBrowser( root_paths.join( "*" ), "*", title,
					embed::getIconPixmap( "computer" ).transformed( QTransform().rotate( 90 ) ),
							splitter, dirs_as_items) );

	m_workspace = new QMdiArea( splitter );

	// Load background
	emit initProgress(tr("Loading background artwork"));
	QString bgArtwork = ConfigManager::inst()->backgroundArtwork();
	QImage bgImage;
	if( !bgArtwork.isEmpty() )
	{
		bgImage = QImage( bgArtwork );
	}
	if( !bgImage.isNull() )
	{
		m_workspace->setBackground( bgImage );
	}
	else
	{
		m_workspace->setBackground( Qt::NoBrush );
	}

	m_workspace->setOption( QMdiArea::DontMaximizeSubWindowOnActivation );
	m_workspace->setHorizontalScrollBarPolicy( Qt::ScrollBarAsNeeded );
	m_workspace->setVerticalScrollBarPolicy( Qt::ScrollBarAsNeeded );

	hbox->addWidget( sideBar );
	hbox->addWidget( splitter );


	// create global-toolbar at the top of our window
	m_toolBar = new QWidget( main_widget );
	m_toolBar->setObjectName( "mainToolbar" );
	m_toolBar->setFixedHeight( 64 );
	m_toolBar->move( 0, 0 );

	// add layout for organizing quite complex toolbar-layouting
	m_toolBarLayout = new QGridLayout( m_toolBar/*, 2, 1*/ );
	m_toolBarLayout->setMargin( 0 );
	m_toolBarLayout->setSpacing( 0 );

	vbox->addWidget( m_toolBar );
	vbox->addWidget( w );
	setCentralWidget( main_widget );

	m_updateTimer.start( 1000 / 20, this );  // 20 fps

	if( !ConfigManager::inst()->value( "ui", "disableautosave" ).toInt() )
	{
		// connect auto save
		connect(&m_autoSaveTimer, SIGNAL(timeout()), this, SLOT(autoSave()));
		m_autoSaveInterval = ConfigManager::inst()->value(
					"ui", "saveinterval" ).toInt() < 1 ?
						DEFAULT_AUTO_SAVE_INTERVAL :
				ConfigManager::inst()->value(
					"ui", "saveinterval" ).toInt();

		// The auto save function mustn't run until there is a project
		// to save or it will run over recover.mmp if you hesitate at the
		// recover messagebox for a minute. It is now started in main.
		// See autoSaveTimerReset() in MainWindow.h
	}

	connect( Engine::getSong(), SIGNAL( playbackStateChanged() ),
				this, SLOT( updatePlayPauseIcons() ) );
}
Exemplo n.º 21
0
int MainWindow::transposeTable( const QString &s_FilenameIn, const QString &s_FilenameOut, const int i_CodecInput, const int i_CodecOutput, const int i_EOL, const int i_NumOfFiles )
{
    int         j               = 0;
    int         n               = 0;
    int         m               = 0;

    int         stopProgress    = 0;

    QString     s_EOL           = setEOLChar( i_EOL );

    QStringList sl_Input;

// **********************************************************************************************
// read file

    if ( ( n = readFile( s_FilenameIn, sl_Input, i_CodecInput ) ) < 1 )
        return( n );

// **********************************************************************************************
// open output file

    QFile fout( s_FilenameOut );

    if ( fout.open( QIODevice::WriteOnly | QIODevice::Text) == false )
        return( -20 );

    QTextStream tout( &fout );

    switch ( i_CodecOutput )
    {
    case _SYSTEM_:
        break;
    case _LATIN1_:
        tout.setCodec( QTextCodec::codecForName( "ISO 8859-1" ) );
        break;
    case _APPLEROMAN_:
        tout.setCodec( QTextCodec::codecForName( "Apple Roman" ) );
        break;
    default:
        tout.setCodec( QTextCodec::codecForName( "UTF-8" ) );
        break;
    }

// **********************************************************************************************

    initProgress( i_NumOfFiles, s_FilenameIn, tr( "Transposing table..." ), n );

    for ( int i=0; i<n; i++ )
        m = qMax( m, NumOfSections( sl_Input.at( i ) ) );

    while ( ( j < m ) && ( stopProgress != _APPBREAK_ ) )
    {
        QString s_Output = sl_Input.at( 0 ).section( "\t", j, j );

        for ( int i=1; i<n; i++ )
            s_Output.append( "\t" ).append( sl_Input.at( i ).section( "\t", j, j ) );

        tout << s_Output << s_EOL;

        stopProgress = incProgress( i_NumOfFiles, ++j );
    }

    resetProgress( i_NumOfFiles );

// **********************************************************************************************

    fout.close();

    if ( stopProgress == _APPBREAK_ )
    {
        fout.remove();
        return( _APPBREAK_ );
    }

    return( stopProgress );
}