WimaController.cc 5.58 KB
Newer Older
Valentin Platzgummer's avatar
Valentin Platzgummer committed
1
#include "WimaController.h"
2

3 4 5
const char* WimaController::wimaFileExtension   = "wima";
const char* WimaController::areaItemsName       = "AreaItems";
const char* WimaController::missionItemsName    = "MissionItems";
6

7 8 9 10
WimaController::WimaController(QObject *parent)
    : QObject               (parent)
    , _container            (nullptr)
    , _joinedArea           (this)
11 12
    , _measurementArea      (this)
    , _serviceArea          (this)
13
    , _corridor             (this)
14
    , _localPlanDataValid   (false)
15
{
16

17 18
}

19
QmlObjectListModel* WimaController::visualItems()
20
{
21
    return &_visualItems;
22 23
}

Valentin Platzgummer's avatar
Valentin Platzgummer committed
24 25 26 27
QStringList WimaController::loadNameFilters() const
{
    QStringList filters;

28
    filters << tr("Supported types (*.%1 *.%2)").arg(wimaFileExtension).arg(AppSettings::planFileExtension) <<
Valentin Platzgummer's avatar
Valentin Platzgummer committed
29 30
               tr("All Files (*.*)");
    return filters;
31 32 33 34 35
}

QStringList WimaController::saveNameFilters() const
{
    QStringList filters;
Valentin Platzgummer's avatar
Valentin Platzgummer committed
36

37 38
    filters << tr("Supported types (*.%1 *.%2)").arg(wimaFileExtension).arg(AppSettings::planFileExtension);
    return filters;
Valentin Platzgummer's avatar
Valentin Platzgummer committed
39 40
}

41
WimaDataContainer *WimaController::dataContainer() const
42
{
43
    return _container;
44 45
}

46 47 48 49 50 51 52 53 54 55 56 57
void WimaController::setMasterController(PlanMasterController *masterC)
{
    _masterController = masterC;
    emit masterControllerChanged();
}

void WimaController::setMissionController(MissionController *missionC)
{
    _missionController = missionC;
    emit missionControllerChanged();
}

58 59 60 61 62 63
/*!
 * \fn void WimaController::setDataContainer(WimaDataContainer *container)
 * Sets the pointer to the \c WimaDataContainer, which is meant to exchange data between the \c WimaController and the \c WimaPlaner.
 *
 * \sa WimaPlaner, WimaDataContainer, WimaPlanData
 */
64 65
void WimaController::setDataContainer(WimaDataContainer *container)
{
66 67 68 69 70
    if (container != nullptr) {
        if (_container != nullptr) {
           disconnect(_container, &WimaDataContainer::dataValidChanged, this, &WimaController::containerDataValidChanged);
        }

71
        _container = container;
72
        connect(_container, &WimaDataContainer::dataValidChanged, this, &WimaController::containerDataValidChanged);
73 74 75 76 77

        emit dataContainerChanged();
    }
}

78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
void WimaController::startMission()
{

}

void WimaController::abortMission()
{

}

void WimaController::pauseMission()
{

}

void WimaController::resumeMission()
{

}

98 99
bool WimaController::updateMission()
{
100
    return true;
101 102
}

103
void WimaController::saveToCurrent()
104 105 106
{
}

107 108
void WimaController::saveToFile(const QString& filename)
{
109
    QString file = filename;
110 111
}

112
bool WimaController::loadFromCurrent()
113
{
114
    return true;
115 116 117 118
}

bool WimaController::loadFromFile(const QString &filename)
{
119
    QString file = filename;
120
    return true;
121 122 123
}


124

125
QJsonDocument WimaController::saveToJson(FileType fileType)
126
{
127 128 129 130
    if(fileType)
    {

    }
131
    return QJsonDocument();
132 133
}

134 135 136 137 138 139 140 141
/*!
 * \fn void WimaController::containerDataValidChanged(bool valid)
 * Pulls plan data generated by \c WimaPlaner from the \c _container if the data is valid (\a valid equals true).
 * Is connected to the dataValidChanged() signal of the \c WimaDataContainer.
 *
 * \sa WimaDataContainer, WimaPlaner, WimaPlanData
 */
void WimaController::containerDataValidChanged(bool valid)
142
{
143 144 145 146 147
    if ( valid ) {
        if (_container == nullptr) {
            qWarning("WimaController::containerDataValidChanged(): No container assigned!");
        }
        _localPlanDataValid = false;
148
        _visualItems.clear();
149 150 151 152 153 154 155
        WimaPlanData planData = _container->pull();

        // extract list with WimaAreas
        QList<const WimaAreaData*> areaList = planData.areaList();

        int areaCounter = 0;
        int numAreas = 4; // extract only numAreas Areas, if there are more they are invalid and ignored
156
        qWarning() << QString("List Size: %1").arg(areaList.size());
157 158 159
        for (int i = 0; i < areaList.size(); i++) {
            const WimaAreaData *areaData = areaList[i];

160
            qWarning() << areaData->type();
161
            if (areaData->type() == WimaServiceAreaData::typeString) { // is it a service area?
162
                _serviceArea = *qobject_cast<const WimaServiceAreaData*>(areaData);
163
//                qWarning("Service area, wuhuuu!");
164
                areaCounter++;
165
                _visualItems.append(&_serviceArea);
166 167 168 169

                continue;
            }

170 171
            if (areaData->type() == WimaMeasurementAreaData::typeString) { // is it a measurement area?
                _measurementArea =  *qobject_cast<const WimaMeasurementAreaData*>(areaData);
172
//                qWarning("Measurement area, wuhuuu!");
173
                areaCounter++;
174
                _visualItems.append(&_measurementArea);
175 176 177 178

                continue;
            }

179 180
            if (areaData->type() == WimaCorridorData::typeString) { // is it a corridor?
                _corridor =  *qobject_cast<const WimaCorridorData*>(areaData);
181
//                qWarning("WimaCorridorData, wuhuuu!");
182
                areaCounter++;
183
                //_visualItems.append(&_corridor); // not needed
184 185 186 187

                continue;
            }

188 189
            if (areaData->type() == WimaJoinedAreaData::typeString) { // is it a corridor?
                _joinedArea =  *qobject_cast<const WimaJoinedAreaData*>(areaData);
190
//                qWarning("WimaJoinedAreaData, wuhuuu!");
191
                areaCounter++;
192
                _visualItems.append(&_joinedArea);
193 194

                continue;
195
            }
196 197 198 199 200

            if (areaCounter >= numAreas)
                break;
        }

201 202
        if (areaCounter == numAreas)
            _localPlanDataValid = true;
203 204
    } else {
        _localPlanDataValid = false;
205
        _visualItems.clear();        
206
    }
207 208

    emit visualItemsChanged();
209 210
}

211 212


213 214


215 216