Skip to content

Commit

Permalink
beautification
Browse files Browse the repository at this point in the history
  • Loading branch information
birchera committed Aug 23, 2016
1 parent e82211f commit 17f1fd6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
27 changes: 23 additions & 4 deletions src/MissionManager/SurveyMissionItem.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const char* SurveyMissionItem::_jsonGridAltitudeKey = "gridAltitude";
const char* SurveyMissionItem::_jsonGridAltitudeRelativeKey = "gridAltitudeRelative";
const char* SurveyMissionItem::_jsonGridAngleKey = "gridAngle";
const char* SurveyMissionItem::_jsonGridSpacingKey = "gridSpacing";
const char* SurveyMissionItem::_jsonTurnaroundDistKey = "turnaroundDist";
const char* SurveyMissionItem::_jsonCameraTriggerKey = "cameraTrigger";
const char* SurveyMissionItem::_jsonCameraTriggerDistanceKey = "cameraTriggerDistance";

Expand All @@ -43,6 +44,7 @@ SurveyMissionItem::SurveyMissionItem(Vehicle* vehicle, QObject* parent)
, _gridAltitudeFact (0, "Altitude:", FactMetaData::valueTypeDouble)
, _gridAngleFact (0, "Grid angle:", FactMetaData::valueTypeDouble)
, _gridSpacingFact (0, "Grid spacing:", FactMetaData::valueTypeDouble)
, _turnaroundDistFact (0, "Turnaround dist.:", FactMetaData::valueTypeDouble)
, _cameraTriggerDistanceFact(0, "Camera trigger distance", FactMetaData::valueTypeDouble)

, _gridAltitudeMetaData (FactMetaData::valueTypeDouble)
Expand All @@ -52,6 +54,7 @@ SurveyMissionItem::SurveyMissionItem(Vehicle* vehicle, QObject* parent)
{
_gridAltitudeFact.setRawValue(25);
_gridSpacingFact.setRawValue(10);
_turnaroundDistFact.setRawValue(60);
_cameraTriggerDistanceFact.setRawValue(25);

_gridAltitudeMetaData.setRawUnits("m");
Expand All @@ -71,6 +74,7 @@ SurveyMissionItem::SurveyMissionItem(Vehicle* vehicle, QObject* parent)

connect(&_gridSpacingFact, &Fact::valueChanged, this, &SurveyMissionItem::_generateGrid);
connect(&_gridAngleFact, &Fact::valueChanged, this, &SurveyMissionItem::_generateGrid);
connect(&_turnaroundDistFact, &Fact::valueChanged, this, &SurveyMissionItem::_generateGrid);
connect(&_cameraTriggerDistanceFact, &Fact::valueChanged, this, &SurveyMissionItem::_generateGrid);

connect(this, &SurveyMissionItem::cameraTriggerChanged, this, &SurveyMissionItem::_cameraTriggerChanged);
Expand Down Expand Up @@ -196,6 +200,7 @@ void SurveyMissionItem::save(QJsonObject& saveObject) const
saveObject[_jsonGridAltitudeRelativeKey] = _gridAltitudeRelative;
saveObject[_jsonGridAngleKey] = _gridAngleFact.rawValue().toDouble();
saveObject[_jsonGridSpacingKey] = _gridSpacingFact.rawValue().toDouble();
saveObject[_jsonTurnaroundDistKey] = _turnaroundDistFact.rawValue().toDouble();
saveObject[_jsonCameraTriggerKey] = _cameraTrigger;
saveObject[_jsonCameraTriggerDistanceKey] = _cameraTriggerDistanceFact.rawValue().toDouble();

Expand Down Expand Up @@ -246,9 +251,9 @@ bool SurveyMissionItem::load(const QJsonObject& complexObject, QString& errorStr
// Validate types
QStringList keyList;
QList<QJsonValue::Type> typeList;
keyList << _jsonVersionKey << _jsonTypeKey << _jsonIdKey << _jsonPolygonKey << _jsonGridAltitudeKey << _jsonGridAngleKey << _jsonGridSpacingKey <<
keyList << _jsonVersionKey << _jsonTypeKey << _jsonIdKey << _jsonPolygonKey << _jsonGridAltitudeKey << _jsonGridAngleKey << _jsonGridSpacingKey << _jsonTurnaroundDistKey <<
_jsonCameraTriggerKey << _jsonCameraTriggerDistanceKey << _jsonGridAltitudeRelativeKey;
typeList << QJsonValue::Double << QJsonValue::String << QJsonValue::Double << QJsonValue::Array << QJsonValue::Double << QJsonValue::Double<< QJsonValue::Double <<
typeList << QJsonValue::Double << QJsonValue::String << QJsonValue::Double << QJsonValue::Array << QJsonValue::Double << QJsonValue::Double<< QJsonValue::Double << QJsonValue::Double <<
QJsonValue::Bool << QJsonValue::Double << QJsonValue::Bool;
if (!JsonHelper::validateKeyTypes(complexObject, keyList, typeList, errorString)) {
_clear();
Expand Down Expand Up @@ -276,6 +281,7 @@ bool SurveyMissionItem::load(const QJsonObject& complexObject, QString& errorStr
_gridAltitudeFact.setRawValue (complexObject[_jsonGridAltitudeKey].toDouble());
_gridAngleFact.setRawValue (complexObject[_jsonGridAngleKey].toDouble());
_gridSpacingFact.setRawValue (complexObject[_jsonGridSpacingKey].toDouble());
_turnaroundDistFact.setRawValue (complexObject[_jsonTurnaroundDistKey].toDouble());
_cameraTriggerDistanceFact.setRawValue (complexObject[_jsonCameraTriggerDistanceKey].toDouble());

// Polygon shape
Expand Down Expand Up @@ -565,13 +571,26 @@ void SurveyMissionItem::_gridGenerator(const QList<QPointF>& polygonPoints, QLi
_adjustLineDirection(intersectLines, resultLines);

// Turn into a path
float turnaroundDist = _turnaroundDistFact.rawValue().toDouble();

for (int i=0; i<resultLines.count(); i++) {
const QLineF& line = resultLines[i];

QPointF turnaroundOffset = line.p2() - line.p1();
turnaroundOffset = turnaroundOffset * turnaroundDist / sqrt(pow(turnaroundOffset.x(),2.0) + pow(turnaroundOffset.y(),2.0));

if (i & 1) {
gridPoints << line.p2() << line.p1();
if (turnaroundDist > 0.0) {
gridPoints << line.p2() + turnaroundOffset << line.p2() << line.p1() << line.p1() - turnaroundOffset;
} else {
gridPoints << line.p2() << line.p1();
}
} else {
gridPoints << line.p1() << line.p2();
if (turnaroundDist > 0.0) {
gridPoints << line.p1() - turnaroundOffset << line.p1() << line.p2() << line.p2() + turnaroundOffset;
} else {
gridPoints << line.p1() << line.p2();
}
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/MissionManager/SurveyMissionItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class SurveyMissionItem : public ComplexMissionItem
Q_PROPERTY(bool gridAltitudeRelative MEMBER _gridAltitudeRelative NOTIFY gridAltitudeRelativeChanged)
Q_PROPERTY(Fact* gridAngle READ gridAngle CONSTANT)
Q_PROPERTY(Fact* gridSpacing READ gridSpacing CONSTANT)
Q_PROPERTY(Fact* turnaroundDist READ turnaroundDist CONSTANT)
Q_PROPERTY(bool cameraTrigger MEMBER _cameraTrigger NOTIFY cameraTriggerChanged)
Q_PROPERTY(Fact* cameraTriggerDistance READ cameraTriggerDistance CONSTANT)
Q_PROPERTY(QVariantList polygonPath READ polygonPath NOTIFY polygonPathChanged)
Expand All @@ -48,6 +49,7 @@ class SurveyMissionItem : public ComplexMissionItem
Fact* gridAltitude(void) { return &_gridAltitudeFact; }
Fact* gridAngle(void) { return &_gridAngleFact; }
Fact* gridSpacing(void) { return &_gridSpacingFact; }
Fact* turnaroundDist(void) { return &_turnaroundDistFact; }
Fact* cameraTriggerDistance(void) { return &_cameraTriggerDistanceFact; }

int cameraShots(void) const;
Expand Down Expand Up @@ -128,6 +130,7 @@ private slots:
Fact _gridAltitudeFact;
Fact _gridAngleFact;
Fact _gridSpacingFact;
Fact _turnaroundDistFact;
Fact _cameraTriggerDistanceFact;
FactMetaData _gridAltitudeMetaData;
FactMetaData _gridAngleMetaData;
Expand All @@ -142,6 +145,7 @@ private slots:
static const char* _jsonGridAltitudeRelativeKey;
static const char* _jsonGridAngleKey;
static const char* _jsonGridSpacingKey;
static const char* _jsonTurnaroundDistKey;
static const char* _jsonCameraTriggerKey;
static const char* _jsonCameraTriggerDistanceKey;

Expand Down

0 comments on commit 17f1fd6

Please sign in to comment.