int CItemMulti::Ship_ListObjs( CObjBase ** ppObjList )
{
	// List all the objects in the structure.
	// Move the ship and everything on the deck
	// If too much stuff. then some will fall overboard. hehe.

	if ( ! IsTopLevel())
		return 0;

	int iMaxDist = Multi_GetMaxDist();

	// always list myself first. All other items must see my new region !
	int iCount = 0;
	ppObjList[iCount++] = this;

	CWorldSearch AreaChar( GetTopPoint(), iMaxDist );
	while ( iCount < MAX_MULTI_LIST_OBJS )
	{
		CChar * pChar = AreaChar.GetChar();
		if ( pChar == NULL )
			break;
		if ( pChar->IsClient())
		{
			pChar->GetClient()->addPause();	// get rid of flicker. for anyone even seeing this.
		}
		if ( ! m_pRegion->IsInside2d( pChar->GetTopPoint()))
			continue;
		int zdiff = pChar->GetTopZ() - GetTopZ();
		if ( abs( zdiff ) > 3 )
			continue;
		ppObjList[iCount++] = pChar;
	}

	CWorldSearch AreaItem( GetTopPoint(), iMaxDist );
	while ( iCount < MAX_MULTI_LIST_OBJS )
	{
		CItem * pItem = AreaItem.GetItem();
		if ( pItem == NULL )
			break;
		if ( pItem == this )	// already listed.
			continue;
		if ( ! Multi_IsPartOf( pItem ))
		{
			if ( ! m_pRegion->IsInside2d( pItem->GetTopPoint()))
				continue;
			if ( ! pItem->IsMovable())
				continue;
			int zdiff = pItem->GetTopZ() - GetTopZ();
			if ( abs( zdiff ) > 3 )
				continue;
		}
		ppObjList[iCount++] = pItem;
	}
	return( iCount );
}
Beispiel #2
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 );
}
Beispiel #3
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_ );
}