Commit 243a826b authored by Valentin Platzgummer's avatar Valentin Platzgummer

auto update in wima planer, after load imporved

parent 071506a9
...@@ -204,20 +204,6 @@ bool WimaController::uploadToVehicle() ...@@ -204,20 +204,6 @@ bool WimaController::uploadToVehicle()
// _missionController->removeAll(); // _missionController->removeAll();
// return; // return;
// } // }
for (int i = 1; i < visuals->count(); i++) {
SimpleMissionItem* item = visuals->value<SimpleMissionItem *>(i);
qWarning() << item->coordinate();
qWarning() << item->command();
qWarning() << item->missionItem().param1();
qWarning() << item->missionItem().param2();
qWarning() << item->missionItem().param3();
qWarning() << item->missionItem().param4();
qWarning() << item->missionItem().param5();
qWarning() << item->missionItem().param6();
qWarning() << item->missionItem().param7();
qWarning(" ");
}
_masterController->sendToVehicle(); _masterController->sendToVehicle();
return true; return true;
...@@ -560,11 +546,6 @@ bool WimaController::calcNextPhase() ...@@ -560,11 +546,6 @@ bool WimaController::calcNextPhase()
} }
SimpleMissionItem *visualItemCopy = new SimpleMissionItem(*visualItem, true, this); SimpleMissionItem *visualItemCopy = new SimpleMissionItem(*visualItem, true, this);
qWarning() << visualItem->command();
qWarning() << visualItem->coordinate();
qWarning() << visualItemCopy->command();
qWarning() << visualItemCopy->command();
qWarning(" ");
_currentMissionItems.append(visualItemCopy); _currentMissionItems.append(visualItemCopy);
} }
......
...@@ -12,9 +12,7 @@ public: ...@@ -12,9 +12,7 @@ public:
WimaDataContainer(WimaDataContainer &other, QObject *parent = nullptr) = delete; WimaDataContainer(WimaDataContainer &other, QObject *parent = nullptr) = delete;
WimaDataContainer(WimaDataContainer &other) = delete; WimaDataContainer(WimaDataContainer &other) = delete;
Q_INVOKABLE WimaDataContainer* pointerToThis() {return this;} Q_INVOKABLE WimaDataContainer* pointerToThis() {return this;}
bool dataValid() const;
signals: signals:
void newDataAvailable(void); void newDataAvailable(void);
......
...@@ -9,20 +9,20 @@ const char* WimaPlaner::areaItemsName = "AreaItems"; ...@@ -9,20 +9,20 @@ const char* WimaPlaner::areaItemsName = "AreaItems";
const char* WimaPlaner::missionItemsName = "MissionItems"; const char* WimaPlaner::missionItemsName = "MissionItems";
WimaPlaner::WimaPlaner(QObject *parent) WimaPlaner::WimaPlaner(QObject *parent)
: QObject (parent) : QObject (parent)
, _dirty (false) , _currentAreaIndex (-1)
, _currentAreaIndex (-1) , _container (nullptr)
, _container (nullptr) , _joinedArea (this)
, _joinedArea (this) , _measurementArea (this)
, _measurementArea (this) , _serviceArea (this)
, _serviceArea (this) , _corridor (this)
, _corridor (this) , _circularSurvey (nullptr)
, _circularSurvey (nullptr) , _surveyRefChanging (false)
, _surveyRefChanging (false) , _syncronizedWithController (false)
{ {
connect(this, &WimaPlaner::currentPolygonIndexChanged, this, &WimaPlaner::recalcPolygonInteractivity); connect(this, &WimaPlaner::currentPolygonIndexChanged, this, &WimaPlaner::recalcPolygonInteractivity);
connect(&_updateTimer, &QTimer::timeout, this, &WimaPlaner::updateTimerSlot); connect(&_updateTimer, &QTimer::timeout, this, &WimaPlaner::updateTimerSlot);
_updateTimer.setInterval(250); // 250 ms means: max update time 2*250 ms _updateTimer.setInterval(500); // 250 ms means: max update time 2*250 ms
_updateTimer.start(); _updateTimer.start();
} }
...@@ -77,17 +77,16 @@ void WimaPlaner::setCurrentPolygonIndex(int index) ...@@ -77,17 +77,16 @@ void WimaPlaner::setCurrentPolygonIndex(int index)
void WimaPlaner::setDataContainer(WimaDataContainer *container) void WimaPlaner::setDataContainer(WimaDataContainer *container)
{ {
if (container != nullptr) { if (container != nullptr) {
if (_container != nullptr) {
disconnect(this, &WimaPlaner::dirtyChanged, _container, &WimaDataContainer::newDataAvailable);
}
_container = container; _container = container;
connect(this, &WimaPlaner::dirtyChanged, _container, &WimaDataContainer::newDataAvailable);
emit dataContainerChanged(); emit dataContainerChanged();
} }
} }
bool WimaPlaner::syncronizedWithController()
{
return _syncronizedWithController;
}
void WimaPlaner::removeArea(int index) void WimaPlaner::removeArea(int index)
{ {
if(index >= 0 && index < _visualItems.count()){ if(index >= 0 && index < _visualItems.count()){
...@@ -178,6 +177,10 @@ void WimaPlaner::removeAll() ...@@ -178,6 +177,10 @@ void WimaPlaner::removeAll()
_currentFile = ""; _currentFile = "";
_circularSurvey = nullptr;
_surveyRefChanging = false;
emit currentFileChanged(); emit currentFileChanged();
if ( changesApplied ) if ( changesApplied )
emit visualItemsChanged(); emit visualItemsChanged();
...@@ -213,8 +216,11 @@ bool WimaPlaner::updateMission() ...@@ -213,8 +216,11 @@ bool WimaPlaner::updateMission()
return false; return false;
} }
// establish connections // establish connections
_circularSurvey->setRefPoint(_measurementArea.center()); _circularSurvey->setRefPoint(_measurementArea.center());
_lastSurveyRefPoint = _measurementArea.center();
_surveyRefChanging = false;
_circularSurvey->setAutoGenerated(true); // prevents reinitialisation from gui _circularSurvey->setAutoGenerated(true); // prevents reinitialisation from gui
connect(_circularSurvey->deltaR(), &Fact::rawValueChanged, this, &WimaPlaner::calcArrivalAndReturnPath); connect(_circularSurvey->deltaR(), &Fact::rawValueChanged, this, &WimaPlaner::calcArrivalAndReturnPath);
connect(_circularSurvey->deltaAlpha(), &Fact::rawValueChanged, this, &WimaPlaner::calcArrivalAndReturnPath); connect(_circularSurvey->deltaAlpha(), &Fact::rawValueChanged, this, &WimaPlaner::calcArrivalAndReturnPath);
...@@ -228,8 +234,6 @@ bool WimaPlaner::updateMission() ...@@ -228,8 +234,6 @@ bool WimaPlaner::updateMission()
calcArrivalAndReturnPath(); calcArrivalAndReturnPath();
pushToContainer(); // exchange plan data with the WimaController via the _container
setDirty(false);
return true; return true;
} }
...@@ -414,6 +418,32 @@ bool WimaPlaner::loadFromFile(const QString &filename) ...@@ -414,6 +418,32 @@ bool WimaPlaner::loadFromFile(const QString &filename)
// load from temporary file // load from temporary file
_masterController->loadFromFile(temporaryFileName); _masterController->loadFromFile(temporaryFileName);
QmlObjectListModel *missionItems = _missionController->visualItems();
_circularSurvey = nullptr;
for (int i = 0; i < missionItems->count(); i++) {
_circularSurvey = missionItems->value<CircularSurveyComplexItem *>(i);
if (_circularSurvey != nullptr) {
if ( !recalcJoinedArea(errorString)) {
qgcApp()->showMessage(tr(errorString.toLocal8Bit().data()));
return false;
}
_lastSurveyRefPoint = _circularSurvey->refPoint();
_surveyRefChanging = false;
_circularSurvey->setAutoGenerated(true); // prevents reinitialisation from gui
connect(_circularSurvey->deltaR(), &Fact::rawValueChanged, this, &WimaPlaner::calcArrivalAndReturnPath);
connect(_circularSurvey->deltaAlpha(), &Fact::rawValueChanged, this, &WimaPlaner::calcArrivalAndReturnPath);
connect(_circularSurvey->isSnakePath(), &Fact::rawValueChanged, this, &WimaPlaner::calcArrivalAndReturnPath);
connect(_circularSurvey->transectMinLength(), &Fact::rawValueChanged, this, &WimaPlaner::calcArrivalAndReturnPath);
break;
}
}
if (_circularSurvey == nullptr)
updateMission();
// remove temporary file // remove temporary file
if ( !temporaryFile.remove() ){ if ( !temporaryFile.remove() ){
qWarning("WimaPlaner::loadFromFile(): not able to remove temporary file."); qWarning("WimaPlaner::loadFromFile(): not able to remove temporary file.");
...@@ -454,6 +484,10 @@ bool WimaPlaner::calcArrivalAndReturnPath() ...@@ -454,6 +484,10 @@ bool WimaPlaner::calcArrivalAndReturnPath()
return false; return false;
} }
bool restorePlanViewIndex = false;
if (surveyIndex == _missionController->currentPlanViewIndex())
restorePlanViewIndex = true;
// remove old arrival and return path // remove old arrival and return path
int size = missionItems->count(); int size = missionItems->count();
for (int i = surveyIndex+1; i < size; i++) for (int i = surveyIndex+1; i < size; i++)
...@@ -548,7 +582,9 @@ bool WimaPlaner::calcArrivalAndReturnPath() ...@@ -548,7 +582,9 @@ bool WimaPlaner::calcArrivalAndReturnPath()
return false; return false;
} }
if (restorePlanViewIndex)
_missionController->setCurrentPlanViewIndex(missionItems->indexOf(_circularSurvey), false);
setSyncronizedWithControllerFalse();
return true; return true;
} }
...@@ -593,6 +629,7 @@ void WimaPlaner::pushToContainer() ...@@ -593,6 +629,7 @@ void WimaPlaner::pushToContainer()
if (_container != nullptr) { if (_container != nullptr) {
WimaPlanData planData = toPlanData(); WimaPlanData planData = toPlanData();
_container->push(planData); _container->push(planData);
setSyncronizedWithController(true);
} else { } else {
qWarning("WimaPlaner::uploadToContainer(): no container assigned."); qWarning("WimaPlaner::uploadToContainer(): no container assigned.");
} }
...@@ -665,21 +702,14 @@ WimaPlanData WimaPlaner::toPlanData() ...@@ -665,21 +702,14 @@ WimaPlanData WimaPlaner::toPlanData()
return planData; return planData;
} }
void WimaPlaner::setDirty(bool dirty) void WimaPlaner::setSyncronizedWithController(bool sync)
{ {
if(_dirty != dirty) if (_syncronizedWithController != sync) {
{ _syncronizedWithController = sync;
_dirty = dirty; emit syncronizedWithControllerChanged();
emit dirtyChanged(_dirty);
} }
} }
void WimaPlaner::setDirtyTrue()
{
setDirty(true);
}
void WimaPlaner::updateTimerSlot() void WimaPlaner::updateTimerSlot()
{ {
// General operation of this function: // General operation of this function:
...@@ -704,6 +734,11 @@ void WimaPlaner::updateTimerSlot() ...@@ -704,6 +734,11 @@ void WimaPlaner::updateTimerSlot()
_lastSurveyRefPoint = _circularSurvey->refPoint() ; _lastSurveyRefPoint = _circularSurvey->refPoint() ;
} }
void WimaPlaner::setSyncronizedWithControllerFalse()
{
setSyncronizedWithController(false);
}
QJsonDocument WimaPlaner::saveToJson(FileType fileType) QJsonDocument WimaPlaner::saveToJson(FileType fileType)
{ {
/// This function save all areas (of WimaPlaner) and all mission items (of MissionController) to a QJsonDocument /// This function save all areas (of WimaPlaner) and all mission items (of MissionController) to a QJsonDocument
......
...@@ -59,8 +59,7 @@ public: ...@@ -59,8 +59,7 @@ public:
Q_PROPERTY(QString fileExtension READ fileExtension CONSTANT) Q_PROPERTY(QString fileExtension READ fileExtension CONSTANT)
Q_PROPERTY(QGeoCoordinate joinedAreaCenter READ joinedAreaCenter CONSTANT) Q_PROPERTY(QGeoCoordinate joinedAreaCenter READ joinedAreaCenter CONSTANT)
Q_PROPERTY(WimaDataContainer* dataContainer READ dataContainer WRITE setDataContainer NOTIFY dataContainerChanged) Q_PROPERTY(WimaDataContainer* dataContainer READ dataContainer WRITE setDataContainer NOTIFY dataContainerChanged)
Q_PROPERTY(bool dirty READ dirty NOTIFY dirtyChanged) Q_PROPERTY(bool syncronized READ syncronizedWithController NOTIFY syncronizedWithControllerChanged)
// Property accessors // Property accessors
PlanMasterController* masterController (void) { return _masterController; } PlanMasterController* masterController (void) { return _masterController; }
...@@ -72,7 +71,6 @@ public: ...@@ -72,7 +71,6 @@ public:
QStringList saveNameFilters (void) const; QStringList saveNameFilters (void) const;
QString fileExtension (void) const { return wimaFileExtension; } QString fileExtension (void) const { return wimaFileExtension; }
QGeoCoordinate joinedAreaCenter (void) const; QGeoCoordinate joinedAreaCenter (void) const;
bool dirty (void) const { return _dirty; }
WimaDataContainer* dataContainer (void) { return _container;} WimaDataContainer* dataContainer (void) { return _container;}
// Property setters // Property setters
...@@ -82,6 +80,9 @@ public: ...@@ -82,6 +80,9 @@ public:
void setCurrentPolygonIndex (int index); void setCurrentPolygonIndex (int index);
void setDataContainer (WimaDataContainer* container); void setDataContainer (WimaDataContainer* container);
// Property acessors
bool syncronizedWithController ();
// Member Methodes // Member Methodes
Q_INVOKABLE bool addMeasurementArea(); Q_INVOKABLE bool addMeasurementArea();
/// Removes an area from _visualItems /// Removes an area from _visualItems
...@@ -93,6 +94,8 @@ public: ...@@ -93,6 +94,8 @@ public:
Q_INVOKABLE void removeAll(); Q_INVOKABLE void removeAll();
/// Recalculates vehicle corridor, flight path, etc. /// Recalculates vehicle corridor, flight path, etc.
Q_INVOKABLE bool updateMission(); Q_INVOKABLE bool updateMission();
/// Pushes the generated mission data to the container, for exchange with wimaController
Q_INVOKABLE void pushToContainer();
Q_INVOKABLE void saveToCurrent(); Q_INVOKABLE void saveToCurrent();
Q_INVOKABLE void saveToFile(const QString& filename); Q_INVOKABLE void saveToFile(const QString& filename);
...@@ -112,29 +115,27 @@ public: ...@@ -112,29 +115,27 @@ public:
static const char* missionItemsName; static const char* missionItemsName;
signals: signals:
void masterControllerChanged (void); void masterControllerChanged (void);
void missionControllerChanged (void); void missionControllerChanged (void);
void visualItemsChanged (void); void visualItemsChanged (void);
void currentPolygonIndexChanged (int index); void currentPolygonIndexChanged (int index);
void currentFileChanged (); void currentFileChanged ();
void dataContainerChanged (); void dataContainerChanged ();
void dirtyChanged (bool dirty); void syncronizedWithControllerChanged (void);
private slots: private slots:
void recalcPolygonInteractivity (int index); void recalcPolygonInteractivity (int index);
bool calcArrivalAndReturnPath (void); bool calcArrivalAndReturnPath (void);
bool recalcJoinedArea (QString &errorString); bool recalcJoinedArea (QString &errorString);
void pushToContainer ();
void setDirtyTrue ();
// called by _updateTimer::timeout signal, updates different mission parts, if parameters (e.g. survey or areas) have changed // called by _updateTimer::timeout signal, updates different mission parts, if parameters (e.g. survey or areas) have changed
void updateTimerSlot (); void updateTimerSlot ();
void setSyncronizedWithControllerFalse (void);
private: private:
// Member Functions // Member Functions
WimaPlanData toPlanData(); WimaPlanData toPlanData();
void setDirty(bool ready); void setSyncronizedWithController(bool sync);
// Member Variables // Member Variables
bool _dirty; // set to true if updateMission() was sucessful, set to false if different parameters change
PlanMasterController *_masterController; PlanMasterController *_masterController;
MissionController *_missionController; MissionController *_missionController;
int _currentAreaIndex; int _currentAreaIndex;
...@@ -153,4 +154,6 @@ private: ...@@ -153,4 +154,6 @@ private:
QTimer _updateTimer; // on this timers timeout different mission parts will be updated, if parameters (e.g. survey or areas) have changed QTimer _updateTimer; // on this timers timeout different mission parts will be updated, if parameters (e.g. survey or areas) have changed
QGeoCoordinate _lastSurveyRefPoint; QGeoCoordinate _lastSurveyRefPoint;
bool _surveyRefChanging; bool _surveyRefChanging;
bool _syncronizedWithController; // true if planData is syncronized with wimaController
}; };
...@@ -285,17 +285,17 @@ Rectangle { ...@@ -285,17 +285,17 @@ Rectangle {
anchors.rightMargin: _margins anchors.rightMargin: _margins
anchors.right: parent.right anchors.right: parent.right
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
text: qsTr("Calculate") text: qsTr("Sync WiMA")
enabled: true enabled: true
visible: true visible: true
onClicked: wimaPlaner.updateMission() onClicked: wimaPlaner.pushToContainer()
PropertyAnimation on opacity { PropertyAnimation on opacity {
easing.type: Easing.OutQuart easing.type: Easing.OutQuart
from: 0.5 from: 0.5
to: 1 to: 1
loops: Animation.Infinite loops: Animation.Infinite
running: wimaPlaner.dirty running: !wimaPlaner.syncronized
alwaysRunToEnd: true alwaysRunToEnd: true
duration: 2000 duration: 2000
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment