Exemplo n.º 1
0
bool TaskFileManagerOld::saveTaskList( QList<FlightTask*>& flightTaskList,
                                    QString fileName )
{
  QString fn;

  if( fileName.isEmpty() )
    {
      // Use task default file name
      fn = m_taskFileName;
    }

  QFile f( fn );

  if ( ! f.open( QIODevice::WriteOnly ) )
    {
      qWarning() << __PRETTY_FUNCTION__ << "Could not write to task-file:" << fn;
      return false;
    }

  QTextStream stream( &f );

  // writing file-header
  QDateTime dt = QDateTime::currentDateTime();
  QString dtStr = dt.toString("yyyy-MM-dd hh:mm:ss");

  stream << "# Cumulus-Task-File V4.0, created at "
         << dtStr << " by Cumulus "
         << QCoreApplication::applicationVersion() << endl << endl;

  for ( int i=0; i < flightTaskList.count(); i++ )
    {
      FlightTask *task = flightTaskList.at(i);
      QList<TaskPoint *> tpList = task->getTpList();

      stream << "TS," << task->getTaskName() << "," << tpList.count() << endl;

      for ( int j=0; j < tpList.count(); j++ )
        {
          // saving each task point ...
          TaskPoint* tp = tpList.at(j);
          stream << "TW,"
                 << tp->getWGSPosition().x() << ","
                 << tp->getWGSPosition().y() << ","
                 << tp->getElevation() << ","
                 << tp->getWPName() << ","
                 << tp->getName() << ","
                 << tp->getTypeID() << ","
                 << tp->getActiveTaskPointFigureScheme() << ","
                 << tp->getTaskLineLength().getMeters() << ","
                 << tp->getTaskCircleRadius().getMeters() << ","
                 << tp->getTaskSectorInnerRadius().getMeters() << ","
                 << tp->getTaskSectorOuterRadius().getMeters() << ","
                 << tp->getTaskSectorAngle() << ","
                 << tp->getAutoZoom() << ","
                 << tp->getUserEditFlag()
                 << endl;
        }

      stream << "TE" << endl;
    }

  f.close();

  qDebug() << "TFM:" << flightTaskList.size()
           << "task objects saved to file"
           << fn;

  return true;
}
Exemplo n.º 2
0
bool TaskFileManagerOld::loadTaskListNew( QList<FlightTask*>& flightTaskList,
                                          QString fileName )
{
  while( ! flightTaskList.isEmpty() )
    {
      // Clears the list as first.
      delete flightTaskList.takeFirst();
    }

  QString fn;

  if( fileName.isEmpty() )
    {
      // Use task default file name
      fn = m_taskFileName;
    }

  QFile f( fn );

  if ( ! f.open( QIODevice::ReadOnly ) )
    {
      qWarning() << __FUNCTION__ << "Could not open task-file:" << fn;
      return false;
    }

  QTextStream stream( &f );

  bool isTask = false;

  QString taskName;
  QStringList tmpList;
  QList<TaskPoint *> *tpList = 0;

  while ( !stream.atEnd() )
    {
      QString line = stream.readLine().trimmed();

      if ( line.isEmpty() || line.mid( 0, 1 ) == "#" )
        {
          // Ignore empty and comment lines
          continue;
        }

      if ( line.mid( 0, 2 ) == "TS" )
        {
          // new task ...
          isTask = true;

          if ( tpList != 0 )
            {
              // remove all elements from previous incomplete steps
              qDeleteAll(*tpList);
              tpList->clear();
            }
          else
            {
              tpList = new QList<TaskPoint *>;
            }

          tmpList = line.split( ",", QString::KeepEmptyParts );

          if( tmpList.size() < 2 ) continue;

          taskName = tmpList.at(1);
        }
      else
        {
          if ( line.mid( 0, 2 ) == "TW" && isTask )
            {
              // new task point
              TaskPoint* tp = new TaskPoint;
              tpList->append( tp );

              tmpList = line.split( ",", QString::KeepEmptyParts );

              if( tmpList.size() < 14 ) continue;

              WGSPoint wgsp( tmpList.at( 1 ).toInt(), tmpList.at( 2 ) .toInt() );

              int i = 3;

              tp->setWGSPosition( wgsp );
              tp->setPosition( _globalMapMatrix->wgsToMap( wgsp ) );
              tp->setElevation( tmpList.at( i++ ).toInt() );
              tp->setWPName( tmpList.at( i++ ) );
              tp->setName( tmpList.at( i++ ) );
              tp->setTypeID( (BaseMapElement::objectType) tmpList.at( i++ ).toShort() ) ;

              tp->setActiveTaskPointFigureScheme( static_cast<enum GeneralConfig::ActiveTaskFigureScheme> (tmpList.at( i++ ).toInt()) );
              tp->setTaskLineLength( tmpList.at( i++ ).toDouble() );
              tp->setTaskCircleRadius( tmpList.at( i++ ).toDouble() );
              tp->setTaskSectorInnerRadius( tmpList.at( i++ ).toDouble() );
              tp->setTaskSectorOuterRadius( tmpList.at( i++ ).toDouble() );
              tp->setTaskSectorAngle( tmpList.at( i++ ).toInt() );
              tp->setAutoZoom( tmpList.at( i++ ).toInt() > 0 ? true : false );
              tp->setUserEditFlag( tmpList.at( i++ ).toInt() > 0 ? true : false );

              // Check active task figure schema
              switch( tp->getActiveTaskPointFigureScheme() )
              {
        	case GeneralConfig::Circle:
        	case GeneralConfig::Sector:
        	case GeneralConfig::Line:
        	case GeneralConfig::Keyhole:
        	  break;
        	default:
        	  tp->setActiveTaskPointFigureScheme( GeneralConfig::Circle );
        	  break;
              }
            }
          else
            {
              if ( line.mid( 0, 2 ) == "TE" && isTask )
                {
                  // task complete
                  isTask = false;

                  FlightTask* task = new FlightTask( tpList, true, taskName, m_tas );
                  flightTaskList.append( task );

                  // ownership about the list is taken over by FlighTask
                  tpList = 0;
                }
            }
        }
    }

  if ( tpList != 0 )
    {
      // remove all elements from a previous incomplete step
      qDeleteAll(*tpList);
      delete tpList;
    }

  f.close();

  qDebug() << "TFM:" << flightTaskList.size()
           << "task objects read from file"
           << fn;

  return true;
}