diff --git a/flight/Modules/Actuator/actuator.c b/flight/Modules/Actuator/actuator.c index 775b71360..e59d50957 100644 --- a/flight/Modules/Actuator/actuator.c +++ b/flight/Modules/Actuator/actuator.c @@ -65,24 +65,25 @@ static xQueueHandle queue; static xTaskHandle taskHandle; static float lastResult[MAX_MIX_ACTUATORS]={0,0,0,0,0,0,0,0}; -static float lastFilteredResult[MAX_MIX_ACTUATORS]={0,0,0,0,0,0,0,0}; static float filterAccumulator[MAX_MIX_ACTUATORS]={0,0,0,0,0,0,0,0}; // used to inform the actuator thread that actuator update rate is changed -static uint8_t updateRateChanged = 0; +static volatile bool actuator_settings_updated; +// used to inform the actuator thread that mixer settings are changed +static volatile bool mixer_settings_updated; // Private functions static void actuatorTask(void* parameters); -static void actuator_update_rate(UAVObjEvent *); static int16_t scaleChannel(float value, int16_t max, int16_t min, int16_t neutral); -static void setFailsafe(); +static void setFailsafe(const ActuatorSettingsData * actuatorSettings, const MixerSettingsData * mixerSettings); static float MixerCurve(const float throttle, const float* curve, uint8_t elements); -static bool set_channel(uint8_t mixer_channel, uint16_t value); -static void change_update_rate(); +static bool set_channel(uint8_t mixer_channel, uint16_t value, const ActuatorSettingsData * actuatorSettings); +static void actuator_update_rate_if_changed(const ActuatorSettingsData * actuatorSettings, bool force_update); +static void MixerSettingsUpdatedCb(UAVObjEvent * ev); +static void ActuatorSettingsUpdatedCb(UAVObjEvent * ev); float ProcessMixer(const int index, const float curve1, const float curve2, - MixerSettingsData* mixerSettings, ActuatorDesiredData* desired, + const MixerSettingsData* mixerSettings, ActuatorDesiredData* desired, const float period); -static uint16_t lastChannelUpdateFreq[ACTUATORSETTINGS_CHANNELUPDATEFREQ_NUMELEM] = {0,0,0,0}; //this structure is equivalent to the UAVObjects for one mixer. typedef struct { uint8_t type; @@ -109,22 +110,26 @@ int32_t ActuatorStart() */ int32_t ActuatorInitialize() { - // Create object queue - queue = xQueueCreate(MAX_QUEUE_SIZE, sizeof(UAVObjEvent)); - + // Register for notification of changes to ActuatorSettings ActuatorSettingsInitialize(); - ActuatorDesiredInitialize(); - MixerSettingsInitialize(); - ActuatorCommandInitialize(); -#if defined(DIAGNOSTICS) - MixerStatusInitialize(); -#endif + ActuatorSettingsConnectCallback(ActuatorSettingsUpdatedCb); - // Listen for ExampleObject1 updates + // Register for notification of changes to MixerSettings + MixerSettingsInitialize(); + MixerSettingsConnectCallback(MixerSettingsUpdatedCb); + + // Listen for ActuatorDesired updates (Primary input to this module) + ActuatorDesiredInitialize(); + queue = xQueueCreate(MAX_QUEUE_SIZE, sizeof(UAVObjEvent)); ActuatorDesiredConnectQueue(queue); - // If settings change, update the output rate - ActuatorSettingsConnectCallback(actuator_update_rate); + // Primary output of this module + ActuatorCommandInitialize(); + +#if defined(DIAGNOSTICS) + // UAVO only used for inspecting the internal status of the mixer during debug + MixerStatusInitialize(); +#endif return 0; } @@ -151,22 +156,25 @@ static void actuatorTask(void* parameters) float dT = 0.0f; ActuatorCommandData command; - MixerSettingsData mixerSettings; ActuatorDesiredData desired; MixerStatusData mixerStatus; FlightStatusData flightStatus; - uint8_t MotorsSpinWhileArmed; - int16_t ChannelMax[ACTUATORCOMMAND_CHANNEL_NUMELEM]; - int16_t ChannelMin[ACTUATORCOMMAND_CHANNEL_NUMELEM]; - int16_t ChannelNeutral[ACTUATORCOMMAND_CHANNEL_NUMELEM]; + /* Read initial values of ActuatorSettings */ + ActuatorSettingsData actuatorSettings; + actuator_settings_updated = false; + ActuatorSettingsGet(&actuatorSettings); - change_update_rate(); - - float * status = (float *)&mixerStatus; //access status objects as an array of floats + /* Read initial values of MixerSettings */ + MixerSettingsData mixerSettings; + mixer_settings_updated = false; + MixerSettingsGet(&mixerSettings); + + /* Force an initial configuration of the actuator update rates */ + actuator_update_rate_if_changed(&actuatorSettings, true); // Go to the neutral (failsafe) values until an ActuatorDesired update is received - setFailsafe(); + setFailsafe(&actuatorSettings, &mixerSettings); // Main task loop lastSysTime = xTaskGetTickCount(); @@ -174,19 +182,26 @@ static void actuatorTask(void* parameters) { PIOS_WDG_UpdateFlag(PIOS_WDG_ACTUATOR); - // Wait until the ActuatorDesired object is updated, if a timeout then go to failsafe - if ( xQueueReceive(queue, &ev, FAILSAFE_TIMEOUT_MS / portTICK_RATE_MS) != pdTRUE ) - { - setFailsafe(); + // Wait until the ActuatorDesired object is updated + uint8_t rc = xQueueReceive(queue, &ev, FAILSAFE_TIMEOUT_MS / portTICK_RATE_MS); + + /* Process settings updated events even in timeout case so we always act on the latest settings */ + if (actuator_settings_updated) { + actuator_settings_updated = false; + ActuatorSettingsGet (&actuatorSettings); + actuator_update_rate_if_changed (&actuatorSettings, false); + } + if (mixer_settings_updated) { + mixer_settings_updated = false; + MixerSettingsGet (&mixerSettings); + } + + if (rc != pdTRUE) { + /* Update of ActuatorDesired timed out. Go to failsafe */ + setFailsafe(&actuatorSettings, &mixerSettings); continue; } - if(updateRateChanged!=0) - { - change_update_rate(); - updateRateChanged=0; - } - // Check how long since last update thisSysTime = xTaskGetTickCount(); if(thisSysTime > lastSysTime) // reuse dt in case of wraparound @@ -194,18 +209,12 @@ static void actuatorTask(void* parameters) lastSysTime = thisSysTime; FlightStatusGet(&flightStatus); - MixerSettingsGet (&mixerSettings); ActuatorDesiredGet(&desired); ActuatorCommandGet(&command); #if defined(DIAGNOSTICS) MixerStatusGet(&mixerStatus); #endif - ActuatorSettingsMotorsSpinWhileArmedGet(&MotorsSpinWhileArmed); - ActuatorSettingsChannelMaxGet(ChannelMax); - ActuatorSettingsChannelMinGet(ChannelMin); - ActuatorSettingsChannelNeutralGet(ChannelNeutral); - int nMixers = 0; Mixer_t * mixers = (Mixer_t *)&mixerSettings.Mixer1Type; for(int ct=0; ct < MAX_MIX_ACTUATORS; ct++) @@ -217,7 +226,7 @@ static void actuatorTask(void* parameters) } if((nMixers < 2) && !ActuatorCommandReadOnly()) //Nothing can fly with less than two mixers. { - setFailsafe(); // So that channels like PWM buzzer keep working + setFailsafe(&actuatorSettings, &mixerSettings); // So that channels like PWM buzzer keep working continue; } @@ -225,7 +234,7 @@ static void actuatorTask(void* parameters) bool armed = flightStatus.Armed == FLIGHTSTATUS_ARMED_ARMED; bool positiveThrottle = desired.Throttle >= 0.00f; - bool spinWhileArmed = MotorsSpinWhileArmed == ACTUATORSETTINGS_MOTORSSPINWHILEARMED_TRUE; + bool spinWhileArmed = actuatorSettings.MotorsSpinWhileArmed == ACTUATORSETTINGS_MOTORSSPINWHILEARMED_TRUE; float curve1 = MixerCurve(desired.Throttle,mixerSettings.ThrottleCurve1,MIXERSETTINGS_THROTTLECURVE1_NUMELEM); @@ -264,6 +273,8 @@ static void actuatorTask(void* parameters) break; } + float * status = (float *)&mixerStatus; //access status objects as an array of floats + for(int ct=0; ct < MAX_MIX_ACTUATORS; ct++) { if(mixers[ct].type == MIXERSETTINGS_MIXER1TYPE_DISABLED) { @@ -337,9 +348,9 @@ static void actuatorTask(void* parameters) for(int i = 0; i < MAX_MIX_ACTUATORS; i++) command.Channel[i] = scaleChannel(status[i], - ChannelMax[i], - ChannelMin[i], - ChannelNeutral[i]); + actuatorSettings.ChannelMax[i], + actuatorSettings.ChannelMin[i], + actuatorSettings.ChannelNeutral[i]); // Store update time command.UpdateTime = 1000.0f*dT; @@ -361,7 +372,7 @@ static void actuatorTask(void* parameters) for (int n = 0; n < ACTUATORCOMMAND_CHANNEL_NUMELEM; ++n) { - success &= set_channel(n, command.Channel[n]); + success &= set_channel(n, command.Channel[n], &actuatorSettings); } if(!success) { @@ -379,15 +390,18 @@ static void actuatorTask(void* parameters) *Process mixing for one actuator */ float ProcessMixer(const int index, const float curve1, const float curve2, - MixerSettingsData* mixerSettings, ActuatorDesiredData* desired, const float period) + const MixerSettingsData* mixerSettings, ActuatorDesiredData* desired, const float period) { - Mixer_t * mixers = (Mixer_t *)&mixerSettings->Mixer1Type; //pointer to array of mixers in UAVObjects - Mixer_t * mixer = &mixers[index]; + static float lastFilteredResult[MAX_MIX_ACTUATORS]; + const Mixer_t * mixers = (Mixer_t *)&mixerSettings->Mixer1Type; //pointer to array of mixers in UAVObjects + const Mixer_t * mixer = &mixers[index]; + float result = (((float)mixer->matrix[MIXERSETTINGS_MIXER1VECTOR_THROTTLECURVE1] / 128.0f) * curve1) + - (((float)mixer->matrix[MIXERSETTINGS_MIXER1VECTOR_THROTTLECURVE2] / 128.0f) * curve2) + - (((float)mixer->matrix[MIXERSETTINGS_MIXER1VECTOR_ROLL] / 128.0f) * desired->Roll) + - (((float)mixer->matrix[MIXERSETTINGS_MIXER1VECTOR_PITCH] / 128.0f) * desired->Pitch) + - (((float)mixer->matrix[MIXERSETTINGS_MIXER1VECTOR_YAW] / 128.0f) * desired->Yaw); + (((float)mixer->matrix[MIXERSETTINGS_MIXER1VECTOR_THROTTLECURVE2] / 128.0f) * curve2) + + (((float)mixer->matrix[MIXERSETTINGS_MIXER1VECTOR_ROLL] / 128.0f) * desired->Roll) + + (((float)mixer->matrix[MIXERSETTINGS_MIXER1VECTOR_PITCH] / 128.0f) * desired->Pitch) + + (((float)mixer->matrix[MIXERSETTINGS_MIXER1VECTOR_YAW] / 128.0f) * desired->Yaw); + if(mixer->type == MIXERSETTINGS_MIXER1TYPE_MOTOR) { if(result < 0.0f) //idle throttle @@ -501,19 +515,13 @@ static int16_t scaleChannel(float value, int16_t max, int16_t min, int16_t neutr /** * Set actuator output to the neutral values (failsafe) */ -static void setFailsafe() +static void setFailsafe(const ActuatorSettingsData * actuatorSettings, const MixerSettingsData * mixerSettings) { - /* grab only the modules parts that we are going to use */ - int16_t ChannelMin[ACTUATORCOMMAND_CHANNEL_NUMELEM]; - ActuatorSettingsChannelMinGet(ChannelMin); - int16_t ChannelNeutral[ACTUATORCOMMAND_CHANNEL_NUMELEM]; - ActuatorSettingsChannelNeutralGet(ChannelNeutral); + /* grab only the parts that we are going to use */ int16_t Channel[ACTUATORCOMMAND_CHANNEL_NUMELEM]; ActuatorCommandChannelGet(Channel); - MixerSettingsData mixerSettings; - MixerSettingsGet (&mixerSettings); - Mixer_t * mixers = (Mixer_t *)&mixerSettings.Mixer1Type; //pointer to array of mixers in UAVObjects + const Mixer_t * mixers = (Mixer_t *)&mixerSettings->Mixer1Type; //pointer to array of mixers in UAVObjects // Reset ActuatorCommand to safe values for (int n = 0; n < ACTUATORCOMMAND_CHANNEL_NUMELEM; ++n) @@ -521,11 +529,11 @@ static void setFailsafe() if(mixers[n].type == MIXERSETTINGS_MIXER1TYPE_MOTOR) { - Channel[n] = ChannelMin[n]; + Channel[n] = actuatorSettings->ChannelMin[n]; } else if(mixers[n].type == MIXERSETTINGS_MIXER1TYPE_SERVO) { - Channel[n] = ChannelNeutral[n]; + Channel[n] = actuatorSettings->ChannelNeutral[n]; } else { @@ -541,54 +549,22 @@ static void setFailsafe() // Update servo outputs for (int n = 0; n < ACTUATORCOMMAND_CHANNEL_NUMELEM; ++n) { - set_channel(n, Channel[n]); + set_channel(n, Channel[n], actuatorSettings); } // Update output object's parts that we changed ActuatorCommandChannelSet(Channel); } - -/** - * @brief Update the servo update rate - */ -static void actuator_update_rate(UAVObjEvent * ev) -{ - uint16_t ChannelUpdateFreq[ACTUATORSETTINGS_CHANNELUPDATEFREQ_NUMELEM]; - // ActuatoSettings are not changed - if ( ev->obj != ActuatorSettingsHandle() ) - return; - - ActuatorSettingsChannelUpdateFreqGet(ChannelUpdateFreq); - // check if the any rate setting is changed - if (lastChannelUpdateFreq[0]!=0 && memcmp(&lastChannelUpdateFreq[0], &ChannelUpdateFreq[0], sizeof(int16_t) * ACTUATORSETTINGS_CHANNELUPDATEFREQ_NUMELEM) ==0) - return; - // signal to the actuator task that ChannelUpdateFreq are changed - updateRateChanged = 1; -} -/** - * @brief Change the update rates according to the ActuatorSettingsChannelUpdateFreq. - */ -static void change_update_rate() -{ - uint16_t ChannelUpdateFreq[ACTUATORSETTINGS_CHANNELUPDATEFREQ_NUMELEM]; - // save the new rates - ActuatorSettingsChannelUpdateFreqGet(ChannelUpdateFreq); - memcpy(lastChannelUpdateFreq, ChannelUpdateFreq, sizeof(int16_t) * ACTUATORSETTINGS_CHANNELUPDATEFREQ_NUMELEM); - PIOS_Servo_SetHz(&ChannelUpdateFreq[0], ACTUATORSETTINGS_CHANNELUPDATEFREQ_NUMELEM); -} - #if defined(ARCH_POSIX) || defined(ARCH_WIN32) -static bool set_channel(uint8_t mixer_channel, uint16_t value) { +static bool set_channel(uint8_t mixer_channel, uint16_t value, const ActuatorSettingsData * actuatorSettings) +{ return true; } #else -static bool set_channel(uint8_t mixer_channel, uint16_t value) { - - ActuatorSettingsData settings; - ActuatorSettingsGet(&settings); - - switch(settings.ChannelType[mixer_channel]) { +static bool set_channel(uint8_t mixer_channel, uint16_t value, const ActuatorSettingsData * actuatorSettings) +{ + switch(actuatorSettings->ChannelType[mixer_channel]) { case ACTUATORSETTINGS_CHANNELTYPE_PWMALARMBUZZER: { // This is for buzzers that take a PWM input @@ -631,18 +607,18 @@ static bool set_channel(uint8_t mixer_channel, uint16_t value) { lastSysTime = thisSysTime; } } - PIOS_Servo_Set( settings.ChannelAddr[mixer_channel], - buzzOn?settings.ChannelMax[mixer_channel]:settings.ChannelMin[mixer_channel]); + PIOS_Servo_Set(actuatorSettings->ChannelAddr[mixer_channel], + buzzOn?actuatorSettings->ChannelMax[mixer_channel]:actuatorSettings->ChannelMin[mixer_channel]); return true; } case ACTUATORSETTINGS_CHANNELTYPE_PWM: - PIOS_Servo_Set(settings.ChannelAddr[mixer_channel], value); + PIOS_Servo_Set(actuatorSettings->ChannelAddr[mixer_channel], value); return true; #if defined(PIOS_INCLUDE_I2C_ESC) case ACTUATORSETTINGS_CHANNELTYPE_MK: - return PIOS_SetMKSpeed(settings.ChannelAddr[mixer_channel],value); + return PIOS_SetMKSpeed(actuatorSettings->ChannelAddr[mixer_channel],value); case ACTUATORSETTINGS_CHANNELTYPE_ASTEC4: - return PIOS_SetAstec4Speed(settings.ChannelAddr[mixer_channel],value); + return PIOS_SetAstec4Speed(actuatorSettings->ChannelAddr[mixer_channel],value); break; #endif default: @@ -654,6 +630,35 @@ static bool set_channel(uint8_t mixer_channel, uint16_t value) { } #endif +/** + * @brief Update the servo update rate + */ +static void actuator_update_rate_if_changed(const ActuatorSettingsData * actuatorSettings, bool force_update) +{ + static uint16_t prevChannelUpdateFreq[ACTUATORSETTINGS_CHANNELUPDATEFREQ_NUMELEM]; + + // check if the any rate setting is changed + if (force_update || + memcmp (prevChannelUpdateFreq, + actuatorSettings->ChannelUpdateFreq, + sizeof(prevChannelUpdateFreq)) != 0) { + /* Something has changed, apply the settings to HW */ + memcpy (prevChannelUpdateFreq, + actuatorSettings->ChannelUpdateFreq, + sizeof(prevChannelUpdateFreq)); + PIOS_Servo_SetHz(actuatorSettings->ChannelUpdateFreq, ACTUATORSETTINGS_CHANNELUPDATEFREQ_NUMELEM); + } +} + +static void ActuatorSettingsUpdatedCb(UAVObjEvent * ev) +{ + actuator_settings_updated = true; +} + +static void MixerSettingsUpdatedCb(UAVObjEvent * ev) +{ + mixer_settings_updated = true; +} /** * @} diff --git a/flight/PiOS.posix/inc/pios_servo.h b/flight/PiOS.posix/inc/pios_servo.h index 7cbf37a7d..952baa5a0 100644 --- a/flight/PiOS.posix/inc/pios_servo.h +++ b/flight/PiOS.posix/inc/pios_servo.h @@ -32,7 +32,7 @@ /* Public Functions */ extern void PIOS_Servo_Init(void); -extern void PIOS_Servo_SetHz(uint16_t * speeds, uint8_t num_banks); +extern void PIOS_Servo_SetHz(const uint16_t * speeds, uint8_t num_banks); extern void PIOS_Servo_Set(uint8_t Servo, uint16_t Position); #endif /* PIOS_SERVO_H */ diff --git a/flight/PiOS.posix/posix/pios_servo.c b/flight/PiOS.posix/posix/pios_servo.c index 93b86a1ed..d0cf530d3 100644 --- a/flight/PiOS.posix/posix/pios_servo.c +++ b/flight/PiOS.posix/posix/pios_servo.c @@ -50,7 +50,7 @@ void PIOS_Servo_Init(void) * \param[in] onetofour Rate for outputs 1 to 4 (Hz) * \param[in] fivetoeight Rate for outputs 5 to 8 (Hz) */ -void PIOS_Servo_SetHz(uint16_t * banks, uint8_t num_banks) +void PIOS_Servo_SetHz(const uint16_t * banks, uint8_t num_banks) { } diff --git a/flight/PiOS.win32/win32/pios_servo.c b/flight/PiOS.win32/win32/pios_servo.c index 93b86a1ed..d0cf530d3 100644 --- a/flight/PiOS.win32/win32/pios_servo.c +++ b/flight/PiOS.win32/win32/pios_servo.c @@ -50,7 +50,7 @@ void PIOS_Servo_Init(void) * \param[in] onetofour Rate for outputs 1 to 4 (Hz) * \param[in] fivetoeight Rate for outputs 5 to 8 (Hz) */ -void PIOS_Servo_SetHz(uint16_t * banks, uint8_t num_banks) +void PIOS_Servo_SetHz(const uint16_t * banks, uint8_t num_banks) { } diff --git a/flight/PiOS/STM32F10x/pios_servo.c b/flight/PiOS/STM32F10x/pios_servo.c index cb7d98292..46be375c2 100644 --- a/flight/PiOS/STM32F10x/pios_servo.c +++ b/flight/PiOS/STM32F10x/pios_servo.c @@ -87,7 +87,7 @@ int32_t PIOS_Servo_Init(const struct pios_servo_cfg * cfg) * \param[in] array of rates in Hz * \param[in] maximum number of banks */ -void PIOS_Servo_SetHz(uint16_t * speeds, uint8_t banks) +void PIOS_Servo_SetHz(const uint16_t * speeds, uint8_t banks) { if (!servo_cfg) { return; diff --git a/flight/PiOS/STM32F4xx/pios_servo.c b/flight/PiOS/STM32F4xx/pios_servo.c index cfcf5c1e5..05188d563 100644 --- a/flight/PiOS/STM32F4xx/pios_servo.c +++ b/flight/PiOS/STM32F4xx/pios_servo.c @@ -87,7 +87,7 @@ int32_t PIOS_Servo_Init(const struct pios_servo_cfg * cfg) * \param[in] array of rates in Hz * \param[in] maximum number of banks */ -void PIOS_Servo_SetHz(uint16_t * speeds, uint8_t banks) +void PIOS_Servo_SetHz(const uint16_t * speeds, uint8_t banks) { if (!servo_cfg) { return; diff --git a/flight/PiOS/inc/pios_servo.h b/flight/PiOS/inc/pios_servo.h index 043d656df..1a33149ea 100644 --- a/flight/PiOS/inc/pios_servo.h +++ b/flight/PiOS/inc/pios_servo.h @@ -31,7 +31,7 @@ #define PIOS_SERVO_H /* Public Functions */ -extern void PIOS_Servo_SetHz(uint16_t * update_rates, uint8_t channels); +extern void PIOS_Servo_SetHz(const uint16_t * update_rates, uint8_t banks); extern void PIOS_Servo_Set(uint8_t Servo, uint16_t Position); #endif /* PIOS_SERVO_H */ diff --git a/flight/UAVObjects/eventdispatcher.c b/flight/UAVObjects/eventdispatcher.c index a5a728b62..e0ffbc99a 100644 --- a/flight/UAVObjects/eventdispatcher.c +++ b/flight/UAVObjects/eventdispatcher.c @@ -280,6 +280,9 @@ static void eventTask() int32_t delayMs; EventCallbackInfo evInfo; + /* Must do this in task context to ensure that TaskMonitor has already finished its init */ + TaskMonitorAdd(TASKINFO_RUNNING_EVENTDISPATCHER, eventTaskHandle); + // Initialize time timeToNextUpdateMs = xTaskGetTickCount()*portTICK_RATE_MS; diff --git a/ground/openpilotgcs/src/app/openpilotgcs.icns b/ground/openpilotgcs/src/app/openpilotgcs.icns index 8785d587f..a7966a960 100644 Binary files a/ground/openpilotgcs/src/app/openpilotgcs.icns and b/ground/openpilotgcs/src/app/openpilotgcs.icns differ diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/opmapcontrol.h b/ground/openpilotgcs/src/libs/opmapcontrol/opmapcontrol.h index 4add132fd..aae8fd5ff 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/opmapcontrol.h +++ b/ground/openpilotgcs/src/libs/opmapcontrol/opmapcontrol.h @@ -1 +1,20 @@ +#ifndef OPMAP_CONTROL_H_ +#define OPMAP_CONTROL_H_ #include "src/mapwidget/opmapwidget.h" +namespace mapcontrol +{ + struct customData + { + float velocity; + int mode; + float mode_params[4]; + int condition; + float condition_params[4]; + int command; + int jumpdestination; + int errordestination; + }; + +} +Q_DECLARE_METATYPE(mapcontrol::customData) +#endif diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/core/accessmode.h b/ground/openpilotgcs/src/libs/opmapcontrol/src/core/accessmode.h index d152936f2..f81efa710 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/core/accessmode.h +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/core/accessmode.h @@ -2,7 +2,7 @@ ****************************************************************************** * * @file accessmode.h -* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @brief * @see The GNU Public License (GPL) Version 3 * @defgroup OPMapWidget diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/core/alllayersoftype.cpp b/ground/openpilotgcs/src/libs/opmapcontrol/src/core/alllayersoftype.cpp index 4a6e87a88..e1b956f9c 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/core/alllayersoftype.cpp +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/core/alllayersoftype.cpp @@ -2,7 +2,7 @@ ****************************************************************************** * * @file alllayersoftype.cpp -* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @brief * @see The GNU Public License (GPL) Version 3 * @defgroup OPMapWidget diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/core/alllayersoftype.h b/ground/openpilotgcs/src/libs/opmapcontrol/src/core/alllayersoftype.h index 94f7442b5..3f351e83d 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/core/alllayersoftype.h +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/core/alllayersoftype.h @@ -2,7 +2,7 @@ ****************************************************************************** * * @file alllayersoftype.h -* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @brief * @see The GNU Public License (GPL) Version 3 * @defgroup OPMapWidget diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/core/cache.cpp b/ground/openpilotgcs/src/libs/opmapcontrol/src/core/cache.cpp index eb910b56a..e4059af55 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/core/cache.cpp +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/core/cache.cpp @@ -2,7 +2,7 @@ ****************************************************************************** * * @file cache.cpp -* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @brief * @see The GNU Public License (GPL) Version 3 * @defgroup OPMapWidget diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/core/cache.h b/ground/openpilotgcs/src/libs/opmapcontrol/src/core/cache.h index 3162de00d..8811d4ae7 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/core/cache.h +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/core/cache.h @@ -2,7 +2,7 @@ ****************************************************************************** * * @file cache.h -* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @brief * @see The GNU Public License (GPL) Version 3 * @defgroup OPMapWidget diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/core/cacheitemqueue.cpp b/ground/openpilotgcs/src/libs/opmapcontrol/src/core/cacheitemqueue.cpp index e926ebf6b..1d7d2b1cd 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/core/cacheitemqueue.cpp +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/core/cacheitemqueue.cpp @@ -2,7 +2,7 @@ ****************************************************************************** * * @file cacheitemqueue.cpp -* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @brief * @see The GNU Public License (GPL) Version 3 * @defgroup OPMapWidget diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/core/cacheitemqueue.h b/ground/openpilotgcs/src/libs/opmapcontrol/src/core/cacheitemqueue.h index 45cf8beb5..89676624b 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/core/cacheitemqueue.h +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/core/cacheitemqueue.h @@ -2,7 +2,7 @@ ****************************************************************************** * * @file cacheitemqueue.h -* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @brief * @see The GNU Public License (GPL) Version 3 * @defgroup OPMapWidget diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/core/diagnostics.cpp b/ground/openpilotgcs/src/libs/opmapcontrol/src/core/diagnostics.cpp index 33bbbcc58..eb345a2c8 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/core/diagnostics.cpp +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/core/diagnostics.cpp @@ -2,7 +2,7 @@ ****************************************************************************** * * @file diagnostics.cpp -* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @brief * @see The GNU Public License (GPL) Version 3 * @defgroup OPMapWidget diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/core/diagnostics.h b/ground/openpilotgcs/src/libs/opmapcontrol/src/core/diagnostics.h index 113faef19..07269b5fa 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/core/diagnostics.h +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/core/diagnostics.h @@ -2,7 +2,7 @@ ****************************************************************************** * * @file diagnostics.h -* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @brief * @see The GNU Public License (GPL) Version 3 * @defgroup OPMapWidget diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/core/geodecoderstatus.h b/ground/openpilotgcs/src/libs/opmapcontrol/src/core/geodecoderstatus.h index 58b653dee..53e4b0c70 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/core/geodecoderstatus.h +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/core/geodecoderstatus.h @@ -2,7 +2,7 @@ ****************************************************************************** * * @file geodecoderstatus.h -* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @brief * @see The GNU Public License (GPL) Version 3 * @defgroup OPMapWidget diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/core/kibertilecache.cpp b/ground/openpilotgcs/src/libs/opmapcontrol/src/core/kibertilecache.cpp index 37c45f83f..af5ae472d 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/core/kibertilecache.cpp +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/core/kibertilecache.cpp @@ -2,7 +2,7 @@ ****************************************************************************** * * @file kibertilecache.cpp -* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @brief * @see The GNU Public License (GPL) Version 3 * @defgroup OPMapWidget diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/core/kibertilecache.h b/ground/openpilotgcs/src/libs/opmapcontrol/src/core/kibertilecache.h index f856dee8b..d117d0361 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/core/kibertilecache.h +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/core/kibertilecache.h @@ -2,7 +2,7 @@ ****************************************************************************** * * @file kibertilecache.h -* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @brief * @see The GNU Public License (GPL) Version 3 * @defgroup OPMapWidget diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/core/languagetype.cpp b/ground/openpilotgcs/src/libs/opmapcontrol/src/core/languagetype.cpp index 2c4ee2a7c..432719c71 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/core/languagetype.cpp +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/core/languagetype.cpp @@ -2,7 +2,7 @@ ****************************************************************************** * * @file languagetype.cpp -* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @brief * @see The GNU Public License (GPL) Version 3 * @defgroup OPMapWidget diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/core/languagetype.h b/ground/openpilotgcs/src/libs/opmapcontrol/src/core/languagetype.h index 4b8411e45..577a0a81a 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/core/languagetype.h +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/core/languagetype.h @@ -2,7 +2,7 @@ ****************************************************************************** * * @file languagetype.h -* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @brief * @see The GNU Public License (GPL) Version 3 * @defgroup OPMapWidget diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/core/maptype.h b/ground/openpilotgcs/src/libs/opmapcontrol/src/core/maptype.h index 741832abc..16ac1a8e1 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/core/maptype.h +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/core/maptype.h @@ -2,7 +2,7 @@ ****************************************************************************** * * @file maptype.h -* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @brief * @see The GNU Public License (GPL) Version 3 * @defgroup OPMapWidget diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/core/memorycache.cpp b/ground/openpilotgcs/src/libs/opmapcontrol/src/core/memorycache.cpp index 94df6d0bc..88f7e3a6b 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/core/memorycache.cpp +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/core/memorycache.cpp @@ -2,7 +2,7 @@ ****************************************************************************** * * @file memorycache.cpp -* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @brief * @see The GNU Public License (GPL) Version 3 * @defgroup OPMapWidget diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/core/memorycache.h b/ground/openpilotgcs/src/libs/opmapcontrol/src/core/memorycache.h index 88a7e6ec6..237bd3a7e 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/core/memorycache.h +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/core/memorycache.h @@ -2,7 +2,7 @@ ****************************************************************************** * * @file memorycache.h -* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @brief * @see The GNU Public License (GPL) Version 3 * @defgroup OPMapWidget diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/core/opmaps.cpp b/ground/openpilotgcs/src/libs/opmapcontrol/src/core/opmaps.cpp index b2db6747d..86660fd3e 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/core/opmaps.cpp +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/core/opmaps.cpp @@ -2,7 +2,7 @@ ****************************************************************************** * * @file OPMaps.cpp -* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @brief * @see The GNU Public License (GPL) Version 3 * @defgroup OPMapWidget diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/core/opmaps.h b/ground/openpilotgcs/src/libs/opmapcontrol/src/core/opmaps.h index f94f3fa06..81b7daf2c 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/core/opmaps.h +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/core/opmaps.h @@ -2,7 +2,7 @@ ****************************************************************************** * * @file OPMaps.h -* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @brief * @see The GNU Public License (GPL) Version 3 * @defgroup OPMapWidget diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/core/placemark.cpp b/ground/openpilotgcs/src/libs/opmapcontrol/src/core/placemark.cpp index 1f8971aae..8bee1b057 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/core/placemark.cpp +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/core/placemark.cpp @@ -2,7 +2,7 @@ ****************************************************************************** * * @file placemark.cpp -* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @brief * @see The GNU Public License (GPL) Version 3 * @defgroup OPMapWidget diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/core/placemark.h b/ground/openpilotgcs/src/libs/opmapcontrol/src/core/placemark.h index 3f338b3f5..3606d9991 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/core/placemark.h +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/core/placemark.h @@ -2,7 +2,7 @@ ****************************************************************************** * * @file placemark.h -* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @brief * @see The GNU Public License (GPL) Version 3 * @defgroup OPMapWidget diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/core/point.cpp b/ground/openpilotgcs/src/libs/opmapcontrol/src/core/point.cpp index a8f43ed0e..145c1b225 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/core/point.cpp +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/core/point.cpp @@ -2,7 +2,7 @@ ****************************************************************************** * * @file point.cpp -* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @brief * @see The GNU Public License (GPL) Version 3 * @defgroup OPMapWidget diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/core/point.h b/ground/openpilotgcs/src/libs/opmapcontrol/src/core/point.h index 83d1f079e..5e46ca926 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/core/point.h +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/core/point.h @@ -2,7 +2,7 @@ ****************************************************************************** * * @file point.h -* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @brief * @see The GNU Public License (GPL) Version 3 * @defgroup OPMapWidget diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/core/providerstrings.cpp b/ground/openpilotgcs/src/libs/opmapcontrol/src/core/providerstrings.cpp index 8d1f63e30..5fda6ac71 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/core/providerstrings.cpp +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/core/providerstrings.cpp @@ -2,7 +2,7 @@ ****************************************************************************** * * @file providerstrings.cpp -* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @brief * @see The GNU Public License (GPL) Version 3 * @defgroup OPMapWidget diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/core/providerstrings.h b/ground/openpilotgcs/src/libs/opmapcontrol/src/core/providerstrings.h index 8759057b4..504453fd0 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/core/providerstrings.h +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/core/providerstrings.h @@ -2,7 +2,7 @@ ****************************************************************************** * * @file providerstrings.h -* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @brief * @see The GNU Public License (GPL) Version 3 * @defgroup OPMapWidget diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/core/pureimage.cpp b/ground/openpilotgcs/src/libs/opmapcontrol/src/core/pureimage.cpp index e938db04d..fe4dabcab 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/core/pureimage.cpp +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/core/pureimage.cpp @@ -2,7 +2,7 @@ ****************************************************************************** * * @file pureimage.cpp -* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @brief * @see The GNU Public License (GPL) Version 3 * @defgroup OPMapWidget diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/core/pureimage.h b/ground/openpilotgcs/src/libs/opmapcontrol/src/core/pureimage.h index 76e1b552f..44e51594b 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/core/pureimage.h +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/core/pureimage.h @@ -2,7 +2,7 @@ ****************************************************************************** * * @file pureimage.h -* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @brief * @see The GNU Public License (GPL) Version 3 * @defgroup OPMapWidget diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/core/pureimagecache.cpp b/ground/openpilotgcs/src/libs/opmapcontrol/src/core/pureimagecache.cpp index be38fcbfa..eb16755ea 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/core/pureimagecache.cpp +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/core/pureimagecache.cpp @@ -2,7 +2,7 @@ ****************************************************************************** * * @file pureimagecache.cpp -* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @brief * @see The GNU Public License (GPL) Version 3 * @defgroup OPMapWidget diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/core/pureimagecache.h b/ground/openpilotgcs/src/libs/opmapcontrol/src/core/pureimagecache.h index 7d8942b31..d92d58090 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/core/pureimagecache.h +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/core/pureimagecache.h @@ -2,7 +2,7 @@ ****************************************************************************** * * @file pureimagecache.h -* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @brief * @see The GNU Public License (GPL) Version 3 * @defgroup OPMapWidget diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/core/rawtile.cpp b/ground/openpilotgcs/src/libs/opmapcontrol/src/core/rawtile.cpp index f357ae50f..12d58e43d 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/core/rawtile.cpp +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/core/rawtile.cpp @@ -2,7 +2,7 @@ ****************************************************************************** * * @file rawtile.cpp -* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @brief * @see The GNU Public License (GPL) Version 3 * @defgroup OPMapWidget diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/core/rawtile.h b/ground/openpilotgcs/src/libs/opmapcontrol/src/core/rawtile.h index 7b3901f6f..1493b2bb5 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/core/rawtile.h +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/core/rawtile.h @@ -2,7 +2,7 @@ ****************************************************************************** * * @file rawtile.h -* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @brief * @see The GNU Public License (GPL) Version 3 * @defgroup OPMapWidget diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/core/size.cpp b/ground/openpilotgcs/src/libs/opmapcontrol/src/core/size.cpp index 65a26fac2..7709de7ee 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/core/size.cpp +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/core/size.cpp @@ -2,7 +2,7 @@ ****************************************************************************** * * @file size.cpp -* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @brief * @see The GNU Public License (GPL) Version 3 * @defgroup OPMapWidget diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/core/size.h b/ground/openpilotgcs/src/libs/opmapcontrol/src/core/size.h index da340b9a6..0a0a5a7dc 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/core/size.h +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/core/size.h @@ -2,7 +2,7 @@ ****************************************************************************** * * @file size.h -* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @brief * @see The GNU Public License (GPL) Version 3 * @defgroup OPMapWidget diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/core/tilecachequeue.cpp b/ground/openpilotgcs/src/libs/opmapcontrol/src/core/tilecachequeue.cpp index 166e66a29..9843f2f45 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/core/tilecachequeue.cpp +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/core/tilecachequeue.cpp @@ -2,7 +2,7 @@ ****************************************************************************** * * @file tilecachequeue.cpp -* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @brief * @see The GNU Public License (GPL) Version 3 * @defgroup OPMapWidget diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/core/tilecachequeue.h b/ground/openpilotgcs/src/libs/opmapcontrol/src/core/tilecachequeue.h index a0bf2b7e0..f53873f3b 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/core/tilecachequeue.h +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/core/tilecachequeue.h @@ -2,7 +2,7 @@ ****************************************************************************** * * @file tilecachequeue.h -* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @brief * @see The GNU Public License (GPL) Version 3 * @defgroup OPMapWidget diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/core/urlfactory.cpp b/ground/openpilotgcs/src/libs/opmapcontrol/src/core/urlfactory.cpp index ca250228b..2ebdeffc5 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/core/urlfactory.cpp +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/core/urlfactory.cpp @@ -2,7 +2,7 @@ ****************************************************************************** * * @file urlfactory.cpp -* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @brief * @see The GNU Public License (GPL) Version 3 * @defgroup OPMapWidget diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/core/urlfactory.h b/ground/openpilotgcs/src/libs/opmapcontrol/src/core/urlfactory.h index 2f4bfbeb1..a40947cc2 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/core/urlfactory.h +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/core/urlfactory.h @@ -2,7 +2,7 @@ ****************************************************************************** * * @file urlfactory.h -* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @brief * @see The GNU Public License (GPL) Version 3 * @defgroup OPMapWidget diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/MouseWheelZoomType.cpp b/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/MouseWheelZoomType.cpp index d36691145..3d67f27ec 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/MouseWheelZoomType.cpp +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/MouseWheelZoomType.cpp @@ -2,7 +2,7 @@ ****************************************************************************** * * @file MouseWheelZoomType.cpp -* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @brief * @see The GNU Public License (GPL) Version 3 * @defgroup OPMapWidget diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/copyrightstrings.h b/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/copyrightstrings.h index 6115297d6..edea169c1 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/copyrightstrings.h +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/copyrightstrings.h @@ -2,7 +2,7 @@ ****************************************************************************** * * @file copyrightstrings.h -* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @brief * @see The GNU Public License (GPL) Version 3 * @defgroup OPMapWidget @@ -31,11 +31,11 @@ #include namespace internals { -static const QString googleCopyright = QString("©%1 Google - Map data ©%1 Tele Atlas, Imagery ©%1 TerraMetrics").arg(QDate::currentDate().year()); -static const QString openStreetMapCopyright = QString("© OpenStreetMap - Map data ©%1 OpenStreetMap").arg(QDate::currentDate().year()); -static const QString yahooMapCopyright = QString("© Yahoo! Inc. - Map data & Imagery ©%1 NAVTEQ").arg(QDate::currentDate().year()); -static const QString virtualEarthCopyright = QString("©%1 Microsoft Corporation, ©%1 NAVTEQ, ©%1 Image courtesy of NASA").arg(QDate::currentDate().year()); -static const QString arcGisCopyright = QString("©%1 ESRI - Map data ©%1 ArcGIS").arg(QDate::currentDate().year()); +static const QString googleCopyright = QString("%1 Google - Map data %1 Tele Atlas, Imagery %1 TerraMetrics").arg(QDate::currentDate().year()); +static const QString openStreetMapCopyright = QString(" OpenStreetMap - Map data %1 OpenStreetMap").arg(QDate::currentDate().year()); +static const QString yahooMapCopyright = QString(" Yahoo! Inc. - Map data & Imagery %1 NAVTEQ").arg(QDate::currentDate().year()); +static const QString virtualEarthCopyright = QString("%1 Microsoft Corporation, %1 NAVTEQ, %1 Image courtesy of NASA").arg(QDate::currentDate().year()); +static const QString arcGisCopyright = QString("%1 ESRI - Map data %1 ArcGIS").arg(QDate::currentDate().year()); } #endif // COPYRIGHTSTRINGS_H diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/core.cpp b/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/core.cpp index 8a3fafc05..b484f2537 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/core.cpp +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/core.cpp @@ -2,7 +2,7 @@ ****************************************************************************** * * @file core.cpp -* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @brief * @see The GNU Public License (GPL) Version 3 * @defgroup OPMapWidget @@ -251,6 +251,7 @@ namespace internals { Matrix.Clear(); GoToCurrentPositionOnZoom(); UpdateBounds(); + keepInBounds(); emit OnMapDrag(); emit OnMapZoomChanged(); emit OnNeedInvalidation(); @@ -572,7 +573,7 @@ namespace internals { { renderOffset.SetX(pt.X() - dragPoint.X()); renderOffset.SetY(pt.Y() - dragPoint.Y()); - + keepInBounds(); UpdateCenterTileXYLocation(); if(centerTileXYLocation != centerTileXYLocationLast) @@ -692,4 +693,18 @@ namespace internals { pxRes1000km = (int) (1000000.0 / rez); // 1000km pxRes5000km = (int) (5000000.0 / rez); // 5000km } + void Core::keepInBounds() + { + if(renderOffset.X()>0) + renderOffset.SetX(0); + if(renderOffset.Y()>0) + renderOffset.SetY(0); + int maxDragY=GetCurrentRegion().Height()-GettileRect().Height()*(maxOfTiles.Height()-minOfTiles.Height()+1); + int maxDragX=GetCurrentRegion().Width()-GettileRect().Width()*(maxOfTiles.Width()-minOfTiles.Width()+1); + + if(maxDragY>renderOffset.Y()) + renderOffset.SetY(maxDragY); + if(maxDragX>renderOffset.X()) + renderOffset.SetX(maxDragX); + } } diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/core.h b/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/core.h index 73c652de5..dca51d646 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/core.h +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/core.h @@ -2,7 +2,7 @@ ****************************************************************************** * * @file core.h -* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @brief * @see The GNU Public License (GPL) Version 3 * @defgroup OPMapWidget @@ -193,6 +193,7 @@ namespace internals { bool isStarted(){return started;} diagnostics GetDiagnostics(); + signals: void OnCurrentPositionChanged(internals::PointLatLng point); void OnTileLoadComplete(); @@ -206,7 +207,7 @@ namespace internals { private: - + void keepInBounds(); PointLatLng currentPosition; core::Point currentPositionPixel; core::Point renderOffset; diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/loadtask.cpp b/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/loadtask.cpp index 0deb23025..00e373cfb 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/loadtask.cpp +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/loadtask.cpp @@ -2,7 +2,7 @@ ****************************************************************************** * * @file loadtask.cpp -* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @brief * @see The GNU Public License (GPL) Version 3 * @defgroup OPMapWidget diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/loadtask.h b/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/loadtask.h index df38337b0..662420d6e 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/loadtask.h +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/loadtask.h @@ -2,7 +2,7 @@ ****************************************************************************** * * @file loadtask.h -* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @brief * @see The GNU Public License (GPL) Version 3 * @defgroup OPMapWidget diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/mousewheelzoomtype.h b/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/mousewheelzoomtype.h index 218815c36..59938129d 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/mousewheelzoomtype.h +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/mousewheelzoomtype.h @@ -2,7 +2,7 @@ ****************************************************************************** * * @file mousewheelzoomtype.h -* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @brief * @see The GNU Public License (GPL) Version 3 * @defgroup OPMapWidget diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/pointlatlng.cpp b/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/pointlatlng.cpp index 850401582..7869a723a 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/pointlatlng.cpp +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/pointlatlng.cpp @@ -2,7 +2,7 @@ ****************************************************************************** * * @file pointlatlng.cpp -* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @brief * @see The GNU Public License (GPL) Version 3 * @defgroup OPMapWidget diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/pointlatlng.h b/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/pointlatlng.h index 190cabec9..2c30cf6ff 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/pointlatlng.h +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/pointlatlng.h @@ -2,7 +2,7 @@ ****************************************************************************** * * @file pointlatlng.h -* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @brief * @see The GNU Public License (GPL) Version 3 * @defgroup OPMapWidget diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/projections/lks94projection.cpp b/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/projections/lks94projection.cpp index f476ba2f1..82a59ab23 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/projections/lks94projection.cpp +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/projections/lks94projection.cpp @@ -2,7 +2,7 @@ ****************************************************************************** * * @file lks94projection.cpp -* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @brief * @see The GNU Public License (GPL) Version 3 * @defgroup OPMapWidget @@ -614,6 +614,9 @@ double LKS94Projection::GetTileMatrixResolution(int const& zoom) return ret; } +/* + * Returns the conversion from pixels to meters + */ double LKS94Projection::GetGroundResolution(int const& zoom, double const& latitude) { Q_UNUSED(zoom); diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/projections/lks94projection.h b/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/projections/lks94projection.h index 4eee20aaa..66581c694 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/projections/lks94projection.h +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/projections/lks94projection.h @@ -2,7 +2,7 @@ ****************************************************************************** * * @file lks94projection.h -* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @brief * @see The GNU Public License (GPL) Version 3 * @defgroup OPMapWidget diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/projections/mercatorprojection.cpp b/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/projections/mercatorprojection.cpp index 30b94d2e4..cd5bbb95b 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/projections/mercatorprojection.cpp +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/projections/mercatorprojection.cpp @@ -2,7 +2,7 @@ ****************************************************************************** * * @file mercatorprojection.cpp -* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @brief * @see The GNU Public License (GPL) Version 3 * @defgroup OPMapWidget diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/projections/mercatorprojection.h b/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/projections/mercatorprojection.h index 1c55f5638..25e52df1b 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/projections/mercatorprojection.h +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/projections/mercatorprojection.h @@ -2,7 +2,7 @@ ****************************************************************************** * * @file mercatorprojection.h -* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @brief * @see The GNU Public License (GPL) Version 3 * @defgroup OPMapWidget diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/projections/mercatorprojectionyandex.cpp b/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/projections/mercatorprojectionyandex.cpp index 0a695308d..54812e60c 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/projections/mercatorprojectionyandex.cpp +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/projections/mercatorprojectionyandex.cpp @@ -2,7 +2,7 @@ ****************************************************************************** * * @file mercatorprojectionyandex.cpp -* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @brief * @see The GNU Public License (GPL) Version 3 * @defgroup OPMapWidget diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/projections/mercatorprojectionyandex.h b/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/projections/mercatorprojectionyandex.h index 949f83f1f..af9cc620e 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/projections/mercatorprojectionyandex.h +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/projections/mercatorprojectionyandex.h @@ -2,7 +2,7 @@ ****************************************************************************** * * @file mercatorprojectionyandex.h -* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @brief * @see The GNU Public License (GPL) Version 3 * @defgroup OPMapWidget diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/projections/platecarreeprojection.cpp b/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/projections/platecarreeprojection.cpp index be3989d92..18688ca06 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/projections/platecarreeprojection.cpp +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/projections/platecarreeprojection.cpp @@ -2,7 +2,7 @@ ****************************************************************************** * * @file platecarreeprojection.cpp -* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @brief * @see The GNU Public License (GPL) Version 3 * @defgroup OPMapWidget diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/projections/platecarreeprojection.h b/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/projections/platecarreeprojection.h index c57285a2f..61454f00d 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/projections/platecarreeprojection.h +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/projections/platecarreeprojection.h @@ -2,7 +2,7 @@ ****************************************************************************** * * @file platecarreeprojection.h -* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @brief * @see The GNU Public License (GPL) Version 3 * @defgroup OPMapWidget diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/projections/platecarreeprojectionpergo.cpp b/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/projections/platecarreeprojectionpergo.cpp index c9ad01d1f..106674ad2 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/projections/platecarreeprojectionpergo.cpp +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/projections/platecarreeprojectionpergo.cpp @@ -2,7 +2,7 @@ ****************************************************************************** * * @file platecarreeprojectionpergo.cpp -* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @brief * @see The GNU Public License (GPL) Version 3 * @defgroup OPMapWidget diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/projections/platecarreeprojectionpergo.h b/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/projections/platecarreeprojectionpergo.h index f0ca29fdf..cf52aa036 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/projections/platecarreeprojectionpergo.h +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/projections/platecarreeprojectionpergo.h @@ -2,7 +2,7 @@ ****************************************************************************** * * @file platecarreeprojectionpergo.h -* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @brief * @see The GNU Public License (GPL) Version 3 * @defgroup OPMapWidget diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/pureprojection.cpp b/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/pureprojection.cpp index 432defd06..b817ff25e 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/pureprojection.cpp +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/pureprojection.cpp @@ -2,7 +2,7 @@ ****************************************************************************** * * @file pureprojection.cpp -* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @brief * @see The GNU Public License (GPL) Version 3 * @defgroup OPMapWidget @@ -103,6 +103,9 @@ Point PureProjection::FromLatLngToPixel(const PointLatLng &p,const int &zoom) return ret; } + /* + * Returns the conversion from pixels to meters + */ double PureProjection::GetGroundResolution(const int &zoom,const double &latitude) { return (cos(latitude * (PI / 180)) * 2 * PI * Axis()) / GetTileMatrixSizePixel(zoom).Width(); @@ -215,6 +218,18 @@ Point PureProjection::FromLatLngToPixel(const PointLatLng &p,const int &zoom) Lat /= (PI / 180); Lng /= (PI / 180); } + double PureProjection::courseBetweenLatLng(PointLatLng const& p1,PointLatLng const& p2) + { + + double lon1=p1.Lng()* (M_PI / 180); + double lat1=p1.Lat()* (M_PI / 180); + double lon2=p2.Lng()* (M_PI / 180); + double lat2=p2.Lat()* (M_PI / 180); + + return 2*M_PI-myfmod(atan2(sin(lon1-lon2)*cos(lat2), + cos(lat1)*sin(lat2)-sin(lat1)*cos(lat2)*cos(lon1-lon2)), 2*M_PI); + } + double PureProjection::DistanceBetweenLatLng(PointLatLng const& p1,PointLatLng const& p2) { double R = 6371; // km @@ -229,4 +244,34 @@ Point PureProjection::FromLatLngToPixel(const PointLatLng &p,const int &zoom) double d = R * c; return d; } + + void PureProjection::offSetFromLatLngs(PointLatLng p1,PointLatLng p2,double &distance,double &bearing) + { + distance=DistanceBetweenLatLng(p1,p2)*1000; + bearing=courseBetweenLatLng(p1,p2); + } + + double PureProjection::myfmod(double x,double y) + { + return x - y*floor(x/y); + } + + PointLatLng PureProjection::translate(PointLatLng p1,double distance,double bearing) + { + PointLatLng ret; + double d=distance; + double tc=bearing; + double lat1=p1.Lat()*M_PI/180; + double lon1=p1.Lng()*M_PI/180; + double R=6378137; + double lat2 = asin(sin(lat1)*cos(d/R) + cos(lat1)*sin(d/R)*cos(tc) ); + double lon2 = lon1 + atan2(sin(tc)*sin(d/R)*cos(lat1), + cos(d/R)-sin(lat1)*sin(lat2)); + lat2=lat2*180/M_PI; + lon2=lon2*180/M_PI; + ret.SetLat(lat2); + ret.SetLng(lon2); + return ret; + } + } diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/pureprojection.h b/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/pureprojection.h index 4ab806a62..5402d13e6 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/pureprojection.h +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/pureprojection.h @@ -2,7 +2,7 @@ ****************************************************************************** * * @file pureprojection.h -* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @brief * @see The GNU Public License (GPL) Version 3 * @defgroup OPMapWidget @@ -33,7 +33,7 @@ #include "pointlatlng.h" #include "cmath" #include "rectlatlng.h" - +#include using namespace core; namespace internals @@ -81,6 +81,9 @@ public: void FromCartesianTGeodetic(const double &X,const double &Y,const double &Z, double &Lat, double &Lng); static double DistanceBetweenLatLng(PointLatLng const& p1,PointLatLng const& p2); + PointLatLng translate(PointLatLng p1, double distance, double bearing); + double courseBetweenLatLng(const PointLatLng &p1, const PointLatLng &p2); + void offSetFromLatLngs(PointLatLng p1, PointLatLng p2, double &dX, double &dY); protected: static const double PI; @@ -103,7 +106,8 @@ protected: static double e3fn(const double &x); static double mlfn(const double &e0,const double &e1,const double &e2,const double &e3,const double &phi); static qlonglong GetUTMzone(const double &lon); - +private: + double myfmod(double x, double y); }; } diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/rectangle.cpp b/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/rectangle.cpp index f513b2271..ac31898af 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/rectangle.cpp +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/rectangle.cpp @@ -2,7 +2,7 @@ ****************************************************************************** * * @file rectangle.cpp -* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @brief * @see The GNU Public License (GPL) Version 3 * @defgroup OPMapWidget diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/rectangle.h b/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/rectangle.h index 78919c1af..0cc20d1ee 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/rectangle.h +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/rectangle.h @@ -2,7 +2,7 @@ ****************************************************************************** * * @file rectangle.h -* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @brief * @see The GNU Public License (GPL) Version 3 * @defgroup OPMapWidget diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/rectlatlng.cpp b/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/rectlatlng.cpp index 2d9877262..4cc98f5e3 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/rectlatlng.cpp +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/rectlatlng.cpp @@ -2,7 +2,7 @@ ****************************************************************************** * * @file rectlatlng.cpp -* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @brief * @see The GNU Public License (GPL) Version 3 * @defgroup OPMapWidget diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/rectlatlng.h b/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/rectlatlng.h index bbc86bac1..8a54cc84b 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/rectlatlng.h +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/rectlatlng.h @@ -2,7 +2,7 @@ ****************************************************************************** * * @file rectlatlng.h -* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @brief * @see The GNU Public License (GPL) Version 3 * @defgroup OPMapWidget diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/sizelatlng.cpp b/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/sizelatlng.cpp index 9222c3704..e22527429 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/sizelatlng.cpp +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/sizelatlng.cpp @@ -2,7 +2,7 @@ ****************************************************************************** * * @file sizelatlng.cpp -* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @brief * @see The GNU Public License (GPL) Version 3 * @defgroup OPMapWidget diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/sizelatlng.h b/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/sizelatlng.h index 4ee5388cc..c22249314 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/sizelatlng.h +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/sizelatlng.h @@ -2,7 +2,7 @@ ****************************************************************************** * * @file sizelatlng.h -* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @brief * @see The GNU Public License (GPL) Version 3 * @defgroup OPMapWidget diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/tile.cpp b/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/tile.cpp index 5d8289e71..b70887d7d 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/tile.cpp +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/tile.cpp @@ -2,7 +2,7 @@ ****************************************************************************** * * @file tile.cpp -* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @brief * @see The GNU Public License (GPL) Version 3 * @defgroup OPMapWidget diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/tile.h b/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/tile.h index 6b1ae2023..5055ca6c6 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/tile.h +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/tile.h @@ -2,7 +2,7 @@ ****************************************************************************** * * @file tile.h -* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @brief * @see The GNU Public License (GPL) Version 3 * @defgroup OPMapWidget diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/tilematrix.cpp b/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/tilematrix.cpp index 658d3be95..9def2e176 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/tilematrix.cpp +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/tilematrix.cpp @@ -2,7 +2,7 @@ ****************************************************************************** * * @file tilematrix.cpp -* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @brief * @see The GNU Public License (GPL) Version 3 * @defgroup OPMapWidget diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/tilematrix.h b/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/tilematrix.h index 0f431567d..dd56e0987 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/tilematrix.h +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/internals/tilematrix.h @@ -2,7 +2,7 @@ ****************************************************************************** * * @file tilematrix.h -* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @brief * @see The GNU Public License (GPL) Version 3 * @defgroup OPMapWidget diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/configuration.cpp b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/configuration.cpp index 2dd1b95b4..d32b8dcb2 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/configuration.cpp +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/configuration.cpp @@ -2,7 +2,7 @@ ****************************************************************************** * * @file configuration.cpp -* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @brief A class that centralizes most of the mapcontrol configurations * @see The GNU Public License (GPL) Version 3 * @defgroup OPMapWidget diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/configuration.h b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/configuration.h index 46dd0d03c..cadb045ca 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/configuration.h +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/configuration.h @@ -2,7 +2,7 @@ ****************************************************************************** * * @file configuration.h -* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @brief A class that centralizes most of the mapcontrol configurations * @see The GNU Public License (GPL) Version 3 * @defgroup OPMapWidget diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/gpsitem.cpp b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/gpsitem.cpp index aeb9055c3..07d75da2a 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/gpsitem.cpp +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/gpsitem.cpp @@ -2,7 +2,7 @@ ****************************************************************************** * * @file gpsitem.cpp -* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @brief A graphicsItem representing a UAV * @see The GNU Public License (GPL) Version 3 * @defgroup OPMapWidget @@ -37,27 +37,27 @@ namespace mapcontrol localposition=map->FromLatLngToLocal(mapwidget->CurrentPosition()); this->setPos(localposition.X(),localposition.Y()); this->setZValue(4); - trail=new QGraphicsItemGroup(); + trail=new QGraphicsItemGroup(this); trail->setParentItem(map); - trailLine=new QGraphicsItemGroup(); + trailLine=new QGraphicsItemGroup(this); trailLine->setParentItem(map); this->setFlag(QGraphicsItem::ItemIgnoresTransformations,true); mapfollowtype=UAVMapFollowType::None; trailtype=UAVTrailType::ByDistance; timer.start(); + connect(map,SIGNAL(childRefreshPosition()),this,SLOT(RefreshPos())); + connect(map,SIGNAL(childSetOpacity(qreal)),this,SLOT(setOpacitySlot(qreal))); } GPSItem::~GPSItem() { - delete trail; + } void GPSItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { Q_UNUSED(option); Q_UNUSED(widget); - // painter->rotate(-90); painter->drawPixmap(-pic.width()/2,-pic.height()/2,pic); - // painter->drawRect(QRectF(-pic.width()/2,-pic.height()/2,pic.width()-1,pic.height()-1)); } QRectF GPSItem::boundingRect()const { @@ -74,9 +74,15 @@ namespace mapcontrol { if(timer.elapsed()>trailtime*1000) { - trail->addToGroup(new TrailItem(position,altitude,Qt::green,this)); + TrailItem * ob=new TrailItem(position,altitude,Qt::green,map); + trail->addToGroup(ob); + connect(this,SIGNAL(setChildPosition()),ob,SLOT(setPosSLOT())); if(!lasttrailline.IsEmpty()) - trailLine->addToGroup((new TrailLineItem(lasttrailline,position,Qt::green,map))); + { + TrailLineItem * obj=new TrailLineItem(lasttrailline,position,Qt::red,map); + trailLine->addToGroup(obj); + connect(this,SIGNAL(setChildLine()),obj,SLOT(setLineSlot())); + } lasttrailline=position; timer.restart(); } @@ -86,10 +92,15 @@ namespace mapcontrol { if(qAbs(internals::PureProjection::DistanceBetweenLatLng(lastcoord,position)*1000)>traildistance) { - trail->addToGroup(new TrailItem(position,altitude,Qt::green,this)); + TrailItem * ob=new TrailItem(position,altitude,Qt::green,map); + trail->addToGroup(ob); + connect(this,SIGNAL(setChildPosition()),ob,SLOT(setPosSLOT())); if(!lasttrailline.IsEmpty()) - - trailLine->addToGroup((new TrailLineItem(lasttrailline,position,Qt::green,this))); + { + TrailLineItem * obj=new TrailLineItem(lasttrailline,position,Qt::red,map); + trailLine->addToGroup(obj); + connect(this,SIGNAL(setChildLine()),obj,SLOT(setLineSlot())); + } lasttrailline=position; lastcoord=position; } @@ -97,48 +108,6 @@ namespace mapcontrol coord=position; this->altitude=altitude; RefreshPos(); - /*if(mapfollowtype==UAVMapFollowType::CenterAndRotateMap||mapfollowtype==UAVMapFollowType::CenterMap) - { - mapwidget->SetCurrentPosition(coord); - }*/ - this->update(); - /*if(autosetreached) - { - foreach(QGraphicsItem* i,map->childItems()) - { - WayPointItem* wp=qgraphicsitem_cast(i); - if(wp) - { - if(Distance3D(wp->Coord(),wp->Altitude())SetReached(true); - emit UAVReachedWayPoint(wp->Number(),wp); - } - } - } - } - if(mapwidget->Home!=0) - { - //verify if the UAV is inside the safety bouble - if(Distance3D(mapwidget->Home->Coord(),mapwidget->Home->Altitude())>mapwidget->Home->SafeArea()) - { - if(mapwidget->Home->safe!=false) - { - mapwidget->Home->safe=false; - mapwidget->Home->update(); - emit UAVLeftSafetyBouble(this->coord); - } - } - else - { - if(mapwidget->Home->safe!=true) - { - mapwidget->Home->safe=true; - mapwidget->Home->update(); - } - } - - }*/ } } @@ -169,20 +138,15 @@ namespace mapcontrol { localposition=map->FromLatLngToLocal(coord); this->setPos(localposition.X(),localposition.Y()); - foreach(QGraphicsItem* i,trail->childItems()) - { - TrailItem* w=qgraphicsitem_cast(i); - if(w) - w->setPos(map->FromLatLngToLocal(w->coord).X(),map->FromLatLngToLocal(w->coord).Y()); - } - foreach(QGraphicsItem* i,trailLine->childItems()) - { - TrailLineItem* ww=qgraphicsitem_cast(i); - if(ww) - ww->setLine(map->FromLatLngToLocal(ww->coord1).X(),map->FromLatLngToLocal(ww->coord1).Y(),map->FromLatLngToLocal(ww->coord2).X(),map->FromLatLngToLocal(ww->coord2).Y()); - } + emit setChildPosition(); + emit setChildLine(); } + + void GPSItem::setOpacitySlot(qreal opacity) + { + setOpacity(opacity); + } void GPSItem::SetTrailType(const UAVTrailType::Types &value) { trailtype=value; diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/gpsitem.h b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/gpsitem.h index 64931ea7f..c78c734aa 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/gpsitem.h +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/gpsitem.h @@ -2,7 +2,7 @@ ****************************************************************************** * * @file gpsitem.h -* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @brief A graphicsItem representing a WayPoint * @see The GNU Public License (GPL) Version 3 * @defgroup OPMapWidget @@ -103,7 +103,6 @@ namespace mapcontrol void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); - void RefreshPos(); QRectF boundingRect() const; /** * @brief Sets the trail time to be used if TrailType is ByTimeElapsed @@ -218,10 +217,13 @@ namespace mapcontrol // QRectF rect; public slots: - + void RefreshPos(); + void setOpacitySlot(qreal opacity); signals: void UAVReachedWayPoint(int const& waypointnumber,WayPointItem* waypoint); void UAVLeftSafetyBouble(internals::PointLatLng const& position); + void setChildPosition(); + void setChildLine(); }; } #endif // GPSITEM_H diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/homeitem.cpp b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/homeitem.cpp index 815aa86f3..6dad1e034 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/homeitem.cpp +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/homeitem.cpp @@ -2,7 +2,7 @@ ****************************************************************************** * * @file homeitem.cpp -* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @brief A graphicsItem representing a trail point * @see The GNU Public License (GPL) Version 3 * @defgroup OPMapWidget @@ -27,17 +27,32 @@ #include "homeitem.h" namespace mapcontrol { - HomeItem::HomeItem(MapGraphicItem* map,OPMapWidget* parent):safe(true),map(map),mapwidget(parent),showsafearea(true),safearea(1000),altitude(0) + HomeItem::HomeItem(MapGraphicItem* map,OPMapWidget* parent):safe(true),map(map),mapwidget(parent), + showsafearea(true),safearea(1000),altitude(0),isDragging(false),toggleRefresh(true) { pic.load(QString::fromUtf8(":/markers/images/home2.svg")); pic=pic.scaled(30,30,Qt::IgnoreAspectRatio); this->setFlag(QGraphicsItem::ItemIgnoresTransformations,true); + this->setFlag(QGraphicsItem::ItemIsMovable,false); + this->setFlag(QGraphicsItem::ItemIsSelectable,false); localposition=map->FromLatLngToLocal(mapwidget->CurrentPosition()); this->setPos(localposition.X(),localposition.Y()); this->setZValue(4); coord=internals::PointLatLng(50,50); + RefreshToolTip(); + setCacheMode(QGraphicsItem::DeviceCoordinateCache); + connect(map,SIGNAL(childRefreshPosition()),this,SLOT(RefreshPos())); + connect(map,SIGNAL(childSetOpacity(qreal)),this,SLOT(setOpacitySlot(qreal))); } + void HomeItem::RefreshToolTip() + { + QString coord_str = " " + QString::number(coord.Lat(), 'f', 6) + " " + QString::number(coord.Lng(), 'f', 6); + + setToolTip(QString("Waypoint: Home\nCoordinate:%1\nAltitude:%2\n").arg(coord_str).arg(QString::number(altitude))); + } + + void HomeItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { Q_UNUSED(option); @@ -56,7 +71,7 @@ namespace mapcontrol } QRectF HomeItem::boundingRect()const { - if(!showsafearea) + if(pic.width()>localsafearea*2 && !toggleRefresh) return QRectF(-pic.width()/2,-pic.height()/2,pic.width(),pic.height()); else return QRectF(-localsafearea,-localsafearea,localsafearea*2,localsafearea*2); @@ -67,6 +82,7 @@ namespace mapcontrol { return Type; } + void HomeItem::RefreshPos() { prepareGeometryChange(); @@ -75,6 +91,56 @@ namespace mapcontrol if(showsafearea) localsafearea=safearea/map->Projection()->GetGroundResolution(map->ZoomTotal(),coord.Lat()); + RefreshToolTip(); + + this->update(); + toggleRefresh=false; + } + void HomeItem::setOpacitySlot(qreal opacity) + { + setOpacity(opacity); + } + + void HomeItem::mousePressEvent(QGraphicsSceneMouseEvent *event) + { + if(event->button()==Qt::LeftButton) + { + isDragging=true; + } + QGraphicsItem::mousePressEvent(event); + } + + void HomeItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) + { + if(event->button()==Qt::LeftButton) + { + coord=map->FromLocalToLatLng(this->pos().x(),this->pos().y()); + isDragging=false; + + emit homePositionChanged(coord,Altitude()); + } + QGraphicsItem::mouseReleaseEvent(event); + + RefreshToolTip(); + } + void HomeItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) + { + if(event->button()==Qt::LeftButton) + { + emit homedoubleclick(this); + } + } + void HomeItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) + { + + if(isDragging) + { + coord=map->FromLocalToLatLng(this->pos().x(),this->pos().y()); + emit homePositionChanged(coord,Altitude()); + } + QGraphicsItem::mouseMoveEvent(event); + } } + diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/homeitem.h b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/homeitem.h index 3c03396ee..4830f9b52 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/homeitem.h +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/homeitem.h @@ -2,7 +2,7 @@ ****************************************************************************** * * @file homeitem.h -* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @brief A graphicsItem representing a WayPoint * @see The GNU Public License (GPL) Version 3 * @defgroup OPMapWidget @@ -47,31 +47,41 @@ namespace mapcontrol QWidget *widget); QRectF boundingRect() const; int type() const; - void RefreshPos(); bool ShowSafeArea()const{return showsafearea;} void SetShowSafeArea(bool const& value){showsafearea=value;} + void SetToggleRefresh(bool const& value){toggleRefresh=value;} int SafeArea()const{return safearea;} void SetSafeArea(int const& value){safearea=value;} bool safe; - void SetCoord(internals::PointLatLng const& value){coord=value;} + void SetCoord(internals::PointLatLng const& value){coord=value;emit homePositionChanged(value,Altitude());} internals::PointLatLng Coord()const{return coord;} - void SetAltitude(int const& value){altitude=value;} - int Altitude()const{return altitude;} + void SetAltitude(float const& value){altitude=value;emit homePositionChanged(Coord(),Altitude());} + float Altitude()const{return altitude;} + void RefreshToolTip(); private: + MapGraphicItem* map; OPMapWidget* mapwidget; QPixmap pic; core::Point localposition; internals::PointLatLng coord; bool showsafearea; + bool toggleRefresh; int safearea; int localsafearea; - int altitude; - + float altitude; + bool isDragging; + protected: + void mouseMoveEvent ( QGraphicsSceneMouseEvent * event ); + void mousePressEvent ( QGraphicsSceneMouseEvent * event ); + void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ); + void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event); public slots: - + void RefreshPos(); + void setOpacitySlot(qreal opacity); signals: - + void homePositionChanged(internals::PointLatLng coord,float); + void homedoubleclick(HomeItem* waypoint); }; } #endif // HOMEITEM_H diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/images/waypoint_marker1.png b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/images/waypoint_marker1.png new file mode 100644 index 000000000..179be2007 Binary files /dev/null and b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/images/waypoint_marker1.png differ diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/images/waypoint_marker2.png b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/images/waypoint_marker2.png new file mode 100644 index 000000000..7834aa543 Binary files /dev/null and b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/images/waypoint_marker2.png differ diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/images/waypoint_marker3.png b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/images/waypoint_marker3.png new file mode 100644 index 000000000..bd86af025 Binary files /dev/null and b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/images/waypoint_marker3.png differ diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/mapgraphicitem.cpp b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/mapgraphicitem.cpp index 91623b03f..587303d6d 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/mapgraphicitem.cpp +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/mapgraphicitem.cpp @@ -2,7 +2,7 @@ ****************************************************************************** * * @file mapgraphicitem.cpp -* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @brief The main graphicsItem used on the widget, contains the map and map logic * @see The GNU Public License (GPL) Version 3 * @defgroup OPMapWidget @@ -42,10 +42,11 @@ namespace mapcontrol this->SetZoom(2); this->setFlag(ItemIsFocusable); connect(core,SIGNAL(OnNeedInvalidation()),this,SLOT(Core_OnNeedInvalidation())); - connect(core,SIGNAL(OnMapDrag()),this,SLOT(ChildPosRefresh())); - connect(core,SIGNAL(OnMapZoomChanged()),this,SLOT(ChildPosRefresh())); - //resize(); + connect(core,SIGNAL(OnMapDrag()),this,SLOT(childPosRefresh())); + connect(core,SIGNAL(OnMapZoomChanged()),this,SLOT(childPosRefresh())); + setCacheMode(QGraphicsItem::ItemCoordinateCache); } + void MapGraphicItem::start() { core->StartSystem(); @@ -78,39 +79,15 @@ namespace mapcontrol void MapGraphicItem::Core_OnNeedInvalidation() { this->update(); - foreach(QGraphicsItem* i,this->childItems()) - { - WayPointItem* w=qgraphicsitem_cast(i); - if(w) - w->RefreshPos(); - UAVItem* ww=qgraphicsitem_cast(i); - if(ww) - ww->RefreshPos(); - HomeItem* www=qgraphicsitem_cast(i); - if(www) - www->RefreshPos(); - GPSItem* wwww=qgraphicsitem_cast(i); - if(wwww) - wwww->RefreshPos(); - } + emit childRefreshPosition(); } - void MapGraphicItem::ChildPosRefresh() + void MapGraphicItem::childPosRefresh() { - foreach(QGraphicsItem* i,this->childItems()) - { - WayPointItem* w=qgraphicsitem_cast(i); - if(w) - w->RefreshPos(); - UAVItem* ww=qgraphicsitem_cast(i); - if(ww) - ww->RefreshPos(); - HomeItem* www=qgraphicsitem_cast(i); - if(www) - www->RefreshPos(); - GPSItem* wwww=qgraphicsitem_cast(i); - if(wwww) - wwww->RefreshPos(); - } + emit childRefreshPosition(); + } + void MapGraphicItem::setOverlayOpacity(qreal value) + { + emit childSetOpacity(value); } void MapGraphicItem::ConstructLastImage(int const& zoomdiff) { @@ -118,8 +95,7 @@ namespace mapcontrol QSize size=boundingRect().size().toSize(); size.setWidth(size.width()*2*zoomdiff); size.setHeight(size.height()*2*zoomdiff); - temp=QImage(size, - QImage::Format_ARGB32_Premultiplied); + temp=QImage(size,QImage::Format_ARGB32_Premultiplied); temp.fill(0); QPainter imagePainter(&temp); imagePainter.translate(-boundingRect().topLeft()); @@ -216,7 +192,6 @@ namespace mapcontrol } void MapGraphicItem::mousePressEvent(QGraphicsSceneMouseEvent *event) { - if(!IsMouseOverMarker()) { if(event->button() == config->DragButton && CanDragMap()&& !((event->modifiers()==Qt::ShiftModifier)||(event->modifiers()==Qt::ControlModifier))) @@ -267,6 +242,7 @@ namespace mapcontrol if(!selectedArea.IsEmpty() && event->modifiers() == Qt::ShiftModifier) { SetZoomToFitRect(SelectedArea()); + selectedArea=internals::RectLatLng::Empty; } } @@ -276,6 +252,9 @@ namespace mapcontrol { if(event->modifiers()&(Qt::ShiftModifier|Qt::ControlModifier)) this->setCursor(Qt::CrossCursor); + if(event->key()==Qt::Key_Escape) + selectedArea=internals::RectLatLng::Empty; + QGraphicsItem::keyPressEvent(event); } void MapGraphicItem::keyReleaseEvent(QKeyEvent *event) { @@ -388,7 +367,6 @@ namespace mapcontrol found = true; { painter->drawPixmap(core->tileRect.X(),core->tileRect.Y(), core->tileRect.Width(), core->tileRect.Height(),PureImageProxy::FromStream(img)); - // qDebug()<<"tile:"<tileRect.X()<tileRect.Y(); } } } @@ -402,7 +380,6 @@ namespace mapcontrol painter->setFont(config->MissingDataFont); painter->setPen(Qt::red); painter->drawText(QRectF(core->tileRect.X(), core->tileRect.Y(), core->tileRect.Width(), core->tileRect.Height()),Qt::AlignCenter,(core->GettilePoint() == core->GetcenterTileXYLocation()? "CENTER: " :"TILE: ")+core->GettilePoint().ToString()); - //qDebug()<<"ShowTileGridLine:"<GettilePoint().ToString()<<"=="<GetcenterTileXYLocation().ToString(); } } @@ -509,7 +486,6 @@ namespace mapcontrol float scaleValue = zoomDigi+remainder + 1; { MapRenderTransform = scaleValue; - // qDebug()<<"scale="<MaxZoom()) integer=MaxZoom(); diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/mapgraphicitem.h b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/mapgraphicitem.h index c3c235617..a87450dd1 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/mapgraphicitem.h +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/mapgraphicitem.h @@ -2,7 +2,7 @@ ****************************************************************************** * * @file mapgraphicitem.h -* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @brief The main graphicsItem used on the widget, contains the map and map logic * @see The GNU Public License (GPL) Version 3 * @defgroup OPMapWidget @@ -40,8 +40,10 @@ #include #include "waypointitem.h" //#include "uavitem.h" + namespace mapcontrol { + class WayPointItem; class OPMapWidget; /** * @brief The main graphicsItem used on the widget, contains the map and map logic @@ -92,7 +94,6 @@ namespace mapcontrol bool IsDragging()const{return core->IsDragging();} QImage lastimage; -// QPainter* imagePainter; core::Point lastimagepoint; void paintImage(QPainter* painter); void ConstructLastImage(int const& zoomdiff); @@ -100,7 +101,7 @@ namespace mapcontrol double Zoom(); double ZoomDigi(); double ZoomTotal(); - + void setOverlayOpacity(qreal value); protected: void mouseMoveEvent ( QGraphicsSceneMouseEvent * event ); void mousePressEvent ( QGraphicsSceneMouseEvent * event ); @@ -199,7 +200,7 @@ namespace mapcontrol void SetMapType(MapType::Types const& value){core->SetMapType(value);} private slots: void Core_OnNeedInvalidation(); - void ChildPosRefresh(); + void childPosRefresh(); public slots: /** * @brief To be called when the scene size changes @@ -213,7 +214,10 @@ namespace mapcontrol * * @param zoom */ + void wpdoubleclicked(WayPointItem * wp); void zoomChanged(double zoomtotal,double zoomreal,double zoomdigi); + void childRefreshPosition(); + void childSetOpacity(qreal value); }; } #endif // MAPGRAPHICITEM_H diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/mapresources.qrc b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/mapresources.qrc index b7a0b985c..b7709e2cc 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/mapresources.qrc +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/mapresources.qrc @@ -12,6 +12,9 @@ images/mapquad.png images/dragons1.jpg images/dragons2.jpeg + images/waypoint_marker1.png + images/waypoint_marker2.png + images/waypoint_marker3.png images/airplanepip.png diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/mapripform.cpp b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/mapripform.cpp index b2baf5b21..55eadacc2 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/mapripform.cpp +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/mapripform.cpp @@ -2,7 +2,7 @@ ****************************************************************************** * * @file mapripform.cpp -* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @brief Form to be used with the MapRipper class * @see The GNU Public License (GPL) Version 3 * @defgroup OPMapWidget diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/mapripform.h b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/mapripform.h index 6f150fd4d..d3df3f881 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/mapripform.h +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/mapripform.h @@ -2,7 +2,7 @@ ****************************************************************************** * * @file mapripform.h -* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @brief Form to be used with the MapRipper class * @see The GNU Public License (GPL) Version 3 * @defgroup OPMapWidget diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/mapripper.cpp b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/mapripper.cpp index bbda543d6..4c8bbcd1c 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/mapripper.cpp +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/mapripper.cpp @@ -2,7 +2,7 @@ ****************************************************************************** * * @file mapripper.cpp -* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @brief A class that allows ripping of a selection of the map * @see The GNU Public License (GPL) Version 3 * @defgroup OPMapWidget @@ -49,7 +49,11 @@ MapRipper::MapRipper(internals::Core * core, const internals::RectLatLng & rect) emit numberOfTilesChanged(0,0); } else - QMessageBox::information(new QWidget(),"No valid selection","Please select the area of the map to rip with Mouse+Control key"); +#ifdef Q_OS_DARWIN + QMessageBox::information(new QWidget(),"No valid selection","This pre-caches map data.\n\nPlease first select the area of the map to rip with +Left mouse click"); +#else + QMessageBox::information(new QWidget(),"No valid selection","This pre-caches map data.\n\nPlease first select the area of the map to rip with +Left mouse click"); +#endif } void MapRipper::finish() { diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/mapripper.h b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/mapripper.h index 2c426d3d1..a53c443f5 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/mapripper.h +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/mapripper.h @@ -2,7 +2,7 @@ ****************************************************************************** * * @file mapripper.h -* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @brief A class that allows ripping of a selection of the map * @see The GNU Public License (GPL) Version 3 * @defgroup OPMapWidget diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/mapwidget.pro b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/mapwidget.pro index b2098fb78..93627ddc5 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/mapwidget.pro +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/mapwidget.pro @@ -1,50 +1,54 @@ -TEMPLATE = lib -TARGET = opmapwidget -DEFINES += OPMAPWIDGET_LIBRARY -include(../../../../openpilotgcslibrary.pri) - -# DESTDIR = ../build -SOURCES += mapgraphicitem.cpp \ - opmapwidget.cpp \ - configuration.cpp \ - waypointitem.cpp \ - uavitem.cpp \ - gpsitem.cpp \ - trailitem.cpp \ - homeitem.cpp \ - mapripform.cpp \ - mapripper.cpp \ - traillineitem.cpp - -LIBS += -L../build \ - -lcore \ - -linternals \ - -lcore - -# order of linking matters -include(../../../utils/utils.pri) - -POST_TARGETDEPS += ../build/libcore.a -POST_TARGETDEPS += ../build/libinternals.a - -HEADERS += mapgraphicitem.h \ - opmapwidget.h \ - configuration.h \ - waypointitem.h \ - uavitem.h \ - gpsitem.h \ - uavmapfollowtype.h \ - uavtrailtype.h \ - trailitem.h \ - homeitem.h \ - mapripform.h \ - mapripper.h \ - traillineitem.h -QT += opengl -QT += network -QT += sql -QT += svg -RESOURCES += mapresources.qrc - -FORMS += \ - mapripform.ui +TEMPLATE = lib +TARGET = opmapwidget +DEFINES += OPMAPWIDGET_LIBRARY +include(../../../../openpilotgcslibrary.pri) + +# DESTDIR = ../build +SOURCES += mapgraphicitem.cpp \ + opmapwidget.cpp \ + configuration.cpp \ + waypointitem.cpp \ + uavitem.cpp \ + gpsitem.cpp \ + trailitem.cpp \ + homeitem.cpp \ + mapripform.cpp \ + mapripper.cpp \ + traillineitem.cpp \ + waypointline.cpp \ + waypointcircle.cpp + +LIBS += -L../build \ + -lcore \ + -linternals \ + -lcore + +# order of linking matters +include(../../../utils/utils.pri) + +POST_TARGETDEPS += ../build/libcore.a +POST_TARGETDEPS += ../build/libinternals.a + +HEADERS += mapgraphicitem.h \ + opmapwidget.h \ + configuration.h \ + waypointitem.h \ + uavitem.h \ + gpsitem.h \ + uavmapfollowtype.h \ + uavtrailtype.h \ + trailitem.h \ + homeitem.h \ + mapripform.h \ + mapripper.h \ + traillineitem.h \ + waypointline.h \ + waypointcircle.h +QT += opengl +QT += network +QT += sql +QT += svg +RESOURCES += mapresources.qrc + +FORMS += \ + mapripform.ui diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/opmapwidget.cpp b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/opmapwidget.cpp index c506532d4..30eea862d 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/opmapwidget.cpp +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/opmapwidget.cpp @@ -2,7 +2,7 @@ ****************************************************************************** * * @file opmapwidget.cpp -* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @brief The Map Widget, this is the part exposed to the user * @see The GNU Public License (GPL) Version 3 * @defgroup OPMapWidget @@ -33,13 +33,18 @@ namespace mapcontrol { - OPMapWidget::OPMapWidget(QWidget *parent, Configuration *config):QGraphicsView(parent),configuration(config),UAV(0),GPS(0),Home(0),followmouse(true),compass(0),showuav(false),showhome(false),showDiag(false),diagGraphItem(0),diagTimer(0) + OPMapWidget::OPMapWidget(QWidget *parent, Configuration *config):QGraphicsView(parent),configuration(config),UAV(0),GPS(0),Home(0) + ,followmouse(true),compass(0),showuav(false),showhome(false),showDiag(false),diagGraphItem(0),diagTimer(0),overlayOpacity(1) { setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); core=new internals::Core; map=new MapGraphicItem(core,config); mscene.addItem(map); this->setScene(&mscene); + Home=new HomeItem(map,this); + Home->setParentItem(map); + Home->setZValue(-1); + setStyleSheet("QToolTip {font-size:8pt; color:blue;opacity: 223; padding:2px; border-width:2px; border-style:solid; border-color: rgb(170, 170, 127);border-radius:4px }"); this->adjustSize(); connect(map,SIGNAL(zoomChanged(double,double,double)),this,SIGNAL(zoomChanged(double,double,double))); connect(map->core,SIGNAL(OnCurrentPositionChanged(internals::PointLatLng)),this,SIGNAL(OnCurrentPositionChanged(internals::PointLatLng))); @@ -50,10 +55,12 @@ namespace mapcontrol connect(map->core,SIGNAL(OnTileLoadComplete()),this,SIGNAL(OnTileLoadComplete())); connect(map->core,SIGNAL(OnTileLoadStart()),this,SIGNAL(OnTileLoadStart())); connect(map->core,SIGNAL(OnTilesStillToLoad(int)),this,SIGNAL(OnTilesStillToLoad(int))); + connect(map,SIGNAL(wpdoubleclicked(WayPointItem*)),this,SIGNAL(OnWayPointDoubleClicked(WayPointItem*))); + connect(&mscene,SIGNAL(selectionChanged()),this,SLOT(OnSelectionChanged())); SetShowDiagnostics(showDiag); this->setMouseTracking(followmouse); SetShowCompass(true); - + QPixmapCache::setCacheLimit(64*1024); } void OPMapWidget::SetShowDiagnostics(bool const& value) { @@ -70,12 +77,24 @@ namespace mapcontrol delete diagTimer; diagTimer=0; } + + if(GPS!=0) + { + delete GPS; + GPS=0; + } } else { diagTimer=new QTimer(); connect(diagTimer,SIGNAL(timeout()),this,SLOT(diagRefresh())); diagTimer->start(500); + if(GPS==0) + { + GPS=new GPSItem(map,this); + GPS->setParentItem(map); + setOverlayOpacity(overlayOpacity); + } } } @@ -85,8 +104,40 @@ namespace mapcontrol UAV->SetUavPic(UAVPic); if(GPS!=0) GPS->SetUavPic(UAVPic); + } + WayPointLine * OPMapWidget::WPLineCreate(WayPointItem *from, WayPointItem *to,QColor color) + { + if(!from|!to) + return NULL; + WayPointLine* ret= new WayPointLine(from,to,map,color); + ret->setOpacity(overlayOpacity); + return ret; + } + WayPointLine * OPMapWidget::WPLineCreate(HomeItem *from, WayPointItem *to,QColor color) + { + if(!from|!to) + return NULL; + WayPointLine* ret= new WayPointLine(from,to,map,color); + ret->setOpacity(overlayOpacity); + return ret; + } + WayPointCircle * OPMapWidget::WPCircleCreate(WayPointItem *center, WayPointItem *radius, bool clockwise,QColor color) + { + if(!center|!radius) + return NULL; + WayPointCircle* ret= new WayPointCircle(center,radius,clockwise,map,color); + ret->setOpacity(overlayOpacity); + return ret; + } + WayPointCircle *OPMapWidget::WPCircleCreate(HomeItem *center, WayPointItem *radius, bool clockwise,QColor color) + { + if(!center|!radius) + return NULL; + WayPointCircle* ret= new WayPointCircle(center,radius,clockwise,map,color); + ret->setOpacity(overlayOpacity); + return ret; } void OPMapWidget::SetShowUAV(const bool &value) { @@ -96,47 +147,21 @@ namespace mapcontrol UAV->setParentItem(map); connect(this,SIGNAL(UAVLeftSafetyBouble(internals::PointLatLng)),UAV,SIGNAL(UAVLeftSafetyBouble(internals::PointLatLng))); connect(this,SIGNAL(UAVReachedWayPoint(int,WayPointItem*)),UAV,SIGNAL(UAVReachedWayPoint(int,WayPointItem*))); + UAV->setOpacity(overlayOpacity); } else if(!value) { if(UAV!=0) { delete UAV; - UAV=0; - } - - } - if(value && GPS==0) - { - GPS=new GPSItem(map,this); - GPS->setParentItem(map); - } - else if(!value) - { - if(GPS!=0) - { - delete GPS; - GPS=0; + UAV=NULL; } } } void OPMapWidget::SetShowHome(const bool &value) { - if(value && Home==0) - { - Home=new HomeItem(map,this); - Home->setParentItem(map); - } - else if(!value) - { - if(Home!=0) - { - delete Home; - Home=0; - } - - } + Home->setVisible(value); } void OPMapWidget::resizeEvent(QResizeEvent *event) @@ -161,14 +186,20 @@ namespace mapcontrol } OPMapWidget::~OPMapWidget() { - delete UAV; - delete Home; - delete map; - delete core; - delete configuration; + if(UAV) + delete UAV; + if(Home) + delete Home; + if(map) + delete map; + if(core) + delete core; + if(configuration) + delete configuration; foreach(QGraphicsItem* i,this->items()) { - delete i; + if(i) + delete i; } } void OPMapWidget::closeEvent(QCloseEvent *event) @@ -203,18 +234,33 @@ namespace mapcontrol WayPointItem* item=new WayPointItem(this->CurrentPosition(),0,map); ConnectWP(item); item->setParentItem(map); + int position=item->Number(); + emit WPCreated(position,item); + return item; + } + WayPointItem* OPMapWidget::magicWPCreate() + { + WayPointItem* item=new WayPointItem(map,true); + item->SetShowNumber(false); + item->setParentItem(map); return item; } void OPMapWidget::WPCreate(WayPointItem* item) { ConnectWP(item); item->setParentItem(map); + int position=item->Number(); + emit WPCreated(position,item); + setOverlayOpacity(overlayOpacity); } WayPointItem* OPMapWidget::WPCreate(internals::PointLatLng const& coord,int const& altitude) { WayPointItem* item=new WayPointItem(coord,altitude,map); ConnectWP(item); item->setParentItem(map); + int position=item->Number(); + emit WPCreated(position,item); + setOverlayOpacity(overlayOpacity); return item; } WayPointItem* OPMapWidget::WPCreate(internals::PointLatLng const& coord,int const& altitude, QString const& description) @@ -222,6 +268,19 @@ namespace mapcontrol WayPointItem* item=new WayPointItem(coord,altitude,description,map); ConnectWP(item); item->setParentItem(map); + int position=item->Number(); + emit WPCreated(position,item); + setOverlayOpacity(overlayOpacity); + return item; + } + WayPointItem* OPMapWidget::WPCreate(const distBearingAltitude &relativeCoord, const QString &description) + { + WayPointItem* item=new WayPointItem(relativeCoord,description,map); + ConnectWP(item); + item->setParentItem(map); + int position=item->Number(); + emit WPCreated(position,item); + setOverlayOpacity(overlayOpacity); return item; } WayPointItem* OPMapWidget::WPInsert(const int &position) @@ -231,6 +290,7 @@ namespace mapcontrol ConnectWP(item); item->setParentItem(map); emit WPInserted(position,item); + setOverlayOpacity(overlayOpacity); return item; } void OPMapWidget::WPInsert(WayPointItem* item,const int &position) @@ -239,7 +299,7 @@ namespace mapcontrol ConnectWP(item); item->setParentItem(map); emit WPInserted(position,item); - + setOverlayOpacity(overlayOpacity); } WayPointItem* OPMapWidget::WPInsert(internals::PointLatLng const& coord,int const& altitude,const int &position) { @@ -248,29 +308,131 @@ namespace mapcontrol ConnectWP(item); item->setParentItem(map); emit WPInserted(position,item); + setOverlayOpacity(overlayOpacity); return item; } WayPointItem* OPMapWidget::WPInsert(internals::PointLatLng const& coord,int const& altitude, QString const& description,const int &position) { - WayPointItem* item=new WayPointItem(coord,altitude,description,map); + internals::PointLatLng mcoord; + bool reloc=false; + if(mcoord==internals::PointLatLng(0,0)) + { + mcoord=CurrentPosition(); + reloc=true; + } + else + mcoord=coord; + WayPointItem* item=new WayPointItem(mcoord,altitude,description,map); item->SetNumber(position); ConnectWP(item); item->setParentItem(map); emit WPInserted(position,item); + if(reloc) + emit WPValuesChanged(item); + setOverlayOpacity(overlayOpacity); + return item; + } + WayPointItem* OPMapWidget::WPInsert(distBearingAltitude const& relative, QString const& description,const int &position) + { + WayPointItem* item=new WayPointItem(relative,description,map); + item->SetNumber(position); + ConnectWP(item); + item->setParentItem(map); + emit WPInserted(position,item); + setOverlayOpacity(overlayOpacity); return item; } void OPMapWidget::WPDelete(WayPointItem *item) { - emit WPDeleted(item->Number()); + emit WPDeleted(item->Number(),item); delete item; } - void OPMapWidget::WPDeleteAll() + void OPMapWidget::WPDelete(int number) { foreach(QGraphicsItem* i,map->childItems()) { WayPointItem* w=qgraphicsitem_cast(i); if(w) - delete w; + { + if(w->Number()==number) + { + emit WPDeleted(w->Number(),w); + delete w; + return; + } + } + } + } + WayPointItem * OPMapWidget::WPFind(int number) + { + foreach(QGraphicsItem* i,map->childItems()) + { + WayPointItem* w=qgraphicsitem_cast(i); + if(w) + { + if(w->Number()==number) + { + return w; + } + } + } + return NULL; + } + void OPMapWidget::WPSetVisibleAll(bool value) + { + foreach(QGraphicsItem* i,map->childItems()) + { + WayPointItem* w=qgraphicsitem_cast(i); + if(w) + { + if(w->Number()!=-1) + w->setVisible(value); + } + } + } + void OPMapWidget::WPDeleteAll() + { + int x=0; + foreach(QGraphicsItem* i,map->childItems()) + { + WayPointItem* w=qgraphicsitem_cast(i); + if(w) + { + if(w->Number()!=-1) + { + emit WPDeleted(w->Number(),w); + delete w; + } + } + } + } + bool OPMapWidget::WPPresent() + { + foreach(QGraphicsItem* i,map->childItems()) + { + WayPointItem* w=qgraphicsitem_cast(i); + if(w) + { + if(w->Number()!=-1) + { + return true; + } + } + } + } + void OPMapWidget::deleteAllOverlays() + { + foreach(QGraphicsItem* i,map->childItems()) + { + WayPointLine* w=qgraphicsitem_cast(i); + if(w) + w->deleteLater(); + else + { + WayPointCircle* ww=qgraphicsitem_cast(i); + if(ww) + ww->deleteLater(); + } } } QList OPMapWidget::WPSelected() @@ -291,11 +453,13 @@ namespace mapcontrol void OPMapWidget::ConnectWP(WayPointItem *item) { - connect(item,SIGNAL(WPNumberChanged(int,int,WayPointItem*)),this,SIGNAL(WPNumberChanged(int,int,WayPointItem*))); - connect(item,SIGNAL(WPValuesChanged(WayPointItem*)),this,SIGNAL(WPValuesChanged(WayPointItem*))); - connect(this,SIGNAL(WPInserted(int,WayPointItem*)),item,SLOT(WPInserted(int,WayPointItem*))); - connect(this,SIGNAL(WPNumberChanged(int,int,WayPointItem*)),item,SLOT(WPRenumbered(int,int,WayPointItem*))); - connect(this,SIGNAL(WPDeleted(int)),item,SLOT(WPDeleted(int))); + connect(item,SIGNAL(WPNumberChanged(int,int,WayPointItem*)),this,SIGNAL(WPNumberChanged(int,int,WayPointItem*)),Qt::DirectConnection); + connect(item,SIGNAL(WPValuesChanged(WayPointItem*)),this,SIGNAL(WPValuesChanged(WayPointItem*)),Qt::DirectConnection); + connect(item,SIGNAL(localPositionChanged(QPointF,WayPointItem*)),this,SIGNAL(WPLocalPositionChanged(QPointF,WayPointItem*)),Qt::DirectConnection); + connect(item,SIGNAL(manualCoordChange(WayPointItem*)),this,SIGNAL(WPManualCoordChange(WayPointItem*)),Qt::DirectConnection); + connect(this,SIGNAL(WPInserted(int,WayPointItem*)),item,SLOT(WPInserted(int,WayPointItem*)),Qt::DirectConnection); + connect(this,SIGNAL(WPNumberChanged(int,int,WayPointItem*)),item,SLOT(WPRenumbered(int,int,WayPointItem*)),Qt::DirectConnection); + connect(this,SIGNAL(WPDeleted(int,WayPointItem*)),item,SLOT(WPDeleted(int,WayPointItem*)),Qt::DirectConnection); } void OPMapWidget::diagRefresh() { @@ -329,12 +493,12 @@ namespace mapcontrol compass->setScale(0.1+0.05*(qreal)(this->size().width())/1000*(qreal)(this->size().height())/600); // compass->setTransformOriginPoint(compass->boundingRect().width(),compass->boundingRect().height()); compass->setFlag(QGraphicsItem::ItemIsMovable,true); + compass->setFlag(QGraphicsItem::ItemIsSelectable,true); mscene.addItem(compass); compass->setTransformOriginPoint(compass->boundingRect().width()/2,compass->boundingRect().height()/2); compass->setPos(55-compass->boundingRect().width()/2,55-compass->boundingRect().height()/2); compass->setZValue(3); compass->setOpacity(0.7); - } if(!value && compass) { @@ -342,6 +506,12 @@ namespace mapcontrol compass=0; } } + + void OPMapWidget::setOverlayOpacity(qreal value) + { + map->setOverlayOpacity(value); + overlayOpacity=value; + } void OPMapWidget::SetRotate(qreal const& value) { map->mapRotate(value); @@ -353,4 +523,28 @@ namespace mapcontrol { new MapRipper(core,map->SelectedArea()); } + + void OPMapWidget::setSelectedWP(QListlist) + { + this->scene()->clearSelection(); + foreach(WayPointItem * wp,list) + { + wp->setSelected(true); + } + } + + void OPMapWidget::OnSelectionChanged() + { + QList list; + QList wplist; + list=this->scene()->selectedItems(); + foreach(QGraphicsItem* item,list) + { + WayPointItem * wp=qgraphicsitem_cast(item); + if(wp) + wplist.append(wp); + } + if(wplist.length()>0) + emit selectedWPChanged(wplist); + } } diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/opmapwidget.h b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/opmapwidget.h index 5fd906de1..020f3831b 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/opmapwidget.h +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/opmapwidget.h @@ -2,7 +2,7 @@ ****************************************************************************** * * @file opmapwidget.h -* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @brief The Map Widget, this is the part exposed to the user * @see The GNU Public License (GPL) Version 3 * @defgroup OPMapWidget @@ -41,6 +41,9 @@ #include "gpsitem.h" #include "homeitem.h" #include "mapripper.h" +#include "waypointline.h" +#include "waypointcircle.h" +#include "waypointitem.h" namespace mapcontrol { class UAVItem; @@ -279,6 +282,15 @@ namespace mapcontrol */ WayPointItem* WPCreate(internals::PointLatLng const& coord,int const& altitude, QString const& description); /** + * @brief Creates a new WayPoint + * + * @param coord the offset in meters to the home position + * @param altitude the Altitude of the WayPoint + * @param description the description of the WayPoint + * @return WayPointItem a pointer to the WayPoint created + */ + WayPointItem *WPCreate(const distBearingAltitude &relativeCoord, const QString &description); + /** * @brief Inserts a new WayPoint on the specified position * * @param position index of the WayPoint @@ -311,6 +323,7 @@ namespace mapcontrol * @return WayPointItem a pointer to the WayPoint Inserted */ WayPointItem* WPInsert(internals::PointLatLng const& coord,int const& altitude, QString const& description,int const& position); + WayPointItem *WPInsert(const distBearingAltitude &relative, const QString &description, const int &position); /** * @brief Deletes the WayPoint @@ -340,6 +353,8 @@ namespace mapcontrol void SetShowCompass(bool const& value); + void setOverlayOpacity(qreal value); + UAVItem* UAV; GPSItem* GPS; HomeItem* Home; @@ -349,7 +364,18 @@ namespace mapcontrol bool ShowHome()const{return showhome;} void SetShowDiagnostics(bool const& value); void SetUavPic(QString UAVPic); - private: + WayPointLine * WPLineCreate(WayPointItem *from,WayPointItem *to, QColor color); + WayPointLine * WPLineCreate(HomeItem *from,WayPointItem *to, QColor color); + WayPointCircle *WPCircleCreate(WayPointItem *center, WayPointItem *radius,bool clockwise,QColor color); + WayPointCircle *WPCircleCreate(HomeItem *center, WayPointItem *radius,bool clockwise,QColor color); + void deleteAllOverlays(); + void WPSetVisibleAll(bool value); + WayPointItem *magicWPCreate(); + bool WPPresent(); + void WPDelete(int number); + WayPointItem *WPFind(int number); + void setSelectedWP(QList list); + private: internals::Core *core; MapGraphicItem *map; QGraphicsScene mscene; @@ -366,6 +392,7 @@ namespace mapcontrol QTimer * diagTimer; QGraphicsTextItem * diagGraphItem; bool showDiag; + qreal overlayOpacity; private slots: void diagRefresh(); // WayPointItem* item;//apagar @@ -398,6 +425,9 @@ namespace mapcontrol * @param waypoint WayPoint inserted */ void WPReached(WayPointItem* waypoint); + + void WPCreated(int const& number,WayPointItem* waypoint); + /** * @brief Fires when a new WayPoint is inserted * @@ -410,7 +440,10 @@ namespace mapcontrol * * @param number number of the deleted WayPoint */ - void WPDeleted(int const& number); + void WPDeleted(int const& number,WayPointItem* waypoint); + + void WPLocalPositionChanged(QPointF,WayPointItem*); + void WPManualCoordChange(WayPointItem*); /** * @brief Fires When a WayPoint is Reached * @@ -469,11 +502,14 @@ namespace mapcontrol * @param number the number of tiles still in the queue */ void OnTilesStillToLoad(int number); + void OnWayPointDoubleClicked(WayPointItem * waypoint); + void selectedWPChanged(QList); public slots: /** * @brief Ripps the current selection to the DB */ void RipMap(); + void OnSelectionChanged(); }; } diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/trailitem.cpp b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/trailitem.cpp index 41e50c29b..fabf6ee9a 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/trailitem.cpp +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/trailitem.cpp @@ -2,7 +2,7 @@ ****************************************************************************** * * @file trailitem.cpp -* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @brief A graphicsItem representing a trail point * @see The GNU Public License (GPL) Version 3 * @defgroup OPMapWidget @@ -28,9 +28,8 @@ #include namespace mapcontrol { - TrailItem::TrailItem(internals::PointLatLng const& coord,int const& altitude, QBrush color, QGraphicsItem* parent):QGraphicsItem(parent),coord(coord) +TrailItem::TrailItem(internals::PointLatLng const& coord,int const& altitude, QBrush color, MapGraphicItem *map):QGraphicsItem(map),coord(coord),m_brush(color),m_map(map) { - m_brush=color; QDateTime time=QDateTime::currentDateTime(); QString coord_str = " " + QString::number(coord.Lat(), 'f', 6) + " " + QString::number(coord.Lng(), 'f', 6); setToolTip(QString(tr("Position:")+"%1\n"+tr("Altitude:")+"%2\n"+tr("Time:")+"%3").arg(coord_str).arg(QString::number(altitude)).arg(time.toString())); @@ -38,7 +37,6 @@ namespace mapcontrol void TrailItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { - // painter->drawRect(QRectF(-3,-3,6,6)); painter->setBrush(m_brush); painter->drawEllipse(-2,-2,4,4); } @@ -53,5 +51,8 @@ namespace mapcontrol return Type; } - + void TrailItem::setPosSLOT() + { + setPos(m_map->FromLatLngToLocal(this->coord).X(),m_map->FromLatLngToLocal(this->coord).Y()); + } } diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/trailitem.h b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/trailitem.h index 4af8282d5..f926d61fc 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/trailitem.h +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/trailitem.h @@ -2,7 +2,7 @@ ****************************************************************************** * * @file trailitem.h -* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @brief A graphicsItem representing a WayPoint * @see The GNU Public License (GPL) Version 3 * @defgroup OPMapWidget @@ -32,6 +32,7 @@ #include #include "../internals/pointlatlng.h" #include +#include "mapgraphicitem.h" namespace mapcontrol { @@ -42,7 +43,7 @@ namespace mapcontrol Q_INTERFACES(QGraphicsItem) public: enum { Type = UserType + 3 }; - TrailItem(internals::PointLatLng const& coord,int const& altitude, QBrush color, QGraphicsItem* parent); + TrailItem(internals::PointLatLng const& coord,int const& altitude, QBrush color,MapGraphicItem * map); void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); QRectF boundingRect() const; @@ -50,10 +51,9 @@ namespace mapcontrol internals::PointLatLng coord; private: QBrush m_brush; - - + MapGraphicItem * m_map; public slots: - + void setPosSLOT(); signals: }; diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/traillineitem.cpp b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/traillineitem.cpp index c7cd05694..4550613db 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/traillineitem.cpp +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/traillineitem.cpp @@ -2,7 +2,7 @@ ****************************************************************************** * * @file trailitem.cpp -* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @brief A graphicsItem representing a trail point * @see The GNU Public License (GPL) Version 3 * @defgroup OPMapWidget @@ -28,29 +28,21 @@ namespace mapcontrol { - TrailLineItem::TrailLineItem(internals::PointLatLng const& coord1,internals::PointLatLng const& coord2, QBrush color, QGraphicsItem* parent):QGraphicsLineItem(parent),coord1(coord1),coord2(coord2) +TrailLineItem::TrailLineItem(internals::PointLatLng const& coord1,internals::PointLatLng const& coord2, QBrush color, MapGraphicItem * map):QGraphicsLineItem(map),coord1(coord1),coord2(coord2),m_brush(color),m_map(map) { - m_brush=color; QPen pen; pen.setBrush(m_brush); pen.setWidth(1); this->setPen(pen); } -/* - void TrailLineItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) - { - // painter->drawRect(QRectF(-3,-3,6,6)); - painter->setBrush(m_brush); - QPen pen; - pen.setBrush(m_brush); - pen.setWidth(2); - painter->drawLine(this->line().x1(),this->line().y1(),this->line().x2(),this->line().y2()); - } -*/ + int TrailLineItem::type()const { return Type; } - + void TrailLineItem::setLineSlot() + { + setLine(m_map->FromLatLngToLocal(this->coord1).X(),m_map->FromLatLngToLocal(this->coord1).Y(),m_map->FromLatLngToLocal(this->coord2).X(),m_map->FromLatLngToLocal(this->coord2).Y()); + } } diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/traillineitem.h b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/traillineitem.h index f749e51bd..0243907fa 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/traillineitem.h +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/traillineitem.h @@ -2,7 +2,7 @@ ****************************************************************************** * * @file traillineitem.h -* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @brief A graphicsItem representing a WayPoint * @see The GNU Public License (GPL) Version 3 * @defgroup OPMapWidget @@ -32,6 +32,7 @@ #include #include "../internals/pointlatlng.h" #include +#include "mapgraphicitem.h" namespace mapcontrol { @@ -42,18 +43,15 @@ namespace mapcontrol Q_INTERFACES(QGraphicsItem) public: enum { Type = UserType + 7 }; - TrailLineItem(internals::PointLatLng const& coord1,internals::PointLatLng const& coord2, QBrush color, QGraphicsItem* parent); + TrailLineItem(internals::PointLatLng const& coord1,internals::PointLatLng const& coord2, QBrush color,MapGraphicItem * map); int type() const; - // void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, - // QWidget *widget); internals::PointLatLng coord1; internals::PointLatLng coord2; private: QBrush m_brush; - - + MapGraphicItem * m_map; public slots: - + void setLineSlot(); signals: }; diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/uavitem.cpp b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/uavitem.cpp index b28230da5..08697c505 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/uavitem.cpp +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/uavitem.cpp @@ -2,7 +2,7 @@ ****************************************************************************** * * @file uavitem.cpp -* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @brief A graphicsItem representing a UAV * @see The GNU Public License (GPL) Version 3 * @defgroup OPMapWidget @@ -26,45 +26,224 @@ */ #include "../internals/pureprojection.h" #include "uavitem.h" +#include + namespace mapcontrol { + + double UAVItem::groundspeed_mps_filt = 0; + UAVItem::UAVItem(MapGraphicItem* map,OPMapWidget* parent,QString uavPic):map(map),mapwidget(parent),showtrail(true),showtrailline(true),trailtime(5),traildistance(50),autosetreached(true) - ,autosetdistance(100) + ,autosetdistance(100),altitude(0),showUAVInfo(false) { - //QDir dir(":/uavs/images/"); - //QStringList list=dir.entryList(); pic.load(uavPic); - // Don't scale but trust the image we are given - // pic=pic.scaled(50,33,Qt::IgnoreAspectRatio); + this->setFlag(QGraphicsItem::ItemIsMovable,false); + this->setFlag(QGraphicsItem::ItemIsSelectable,false); localposition=map->FromLatLngToLocal(mapwidget->CurrentPosition()); this->setPos(localposition.X(),localposition.Y()); this->setZValue(4); - trail=new QGraphicsItemGroup(); + trail=new QGraphicsItemGroup(this); trail->setParentItem(map); - trailLine=new QGraphicsItemGroup(); + trailLine=new QGraphicsItemGroup(this); trailLine->setParentItem(map); this->setFlag(QGraphicsItem::ItemIgnoresTransformations,true); + setCacheMode(QGraphicsItem::ItemCoordinateCache); mapfollowtype=UAVMapFollowType::None; trailtype=UAVTrailType::ByDistance; timer.start(); + generateArrowhead(); + double pixels2meters = map->Projection()->GetGroundResolution(map->ZoomTotal(),coord.Lat()); + meters2pixels=1.0 / pixels2meters; + setCacheMode(QGraphicsItem::DeviceCoordinateCache); + connect(map,SIGNAL(childRefreshPosition()),this,SLOT(RefreshPos())); + connect(map,SIGNAL(childSetOpacity(qreal)),this,SLOT(setOpacitySlot(qreal))); + connect(map,SIGNAL(zoomChanged(double,double,double)),this,SLOT(zoomChangedSlot())); } UAVItem::~UAVItem() { - delete trail; + } void UAVItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { Q_UNUSED(option); Q_UNUSED(widget); - // painter->rotate(-90); + + //Draw plane painter->drawPixmap(-pic.width()/2,-pic.height()/2,pic); - // painter->drawRect(QRectF(-pic.width()/2,-pic.height()/2,pic.width()-1,pic.height()-1)); + + //Return if UAV Info context menu is turned off + if(!showUAVInfo){ + return; + } + + QPen myPen; + + //Turn on anti-aliasing so the fonts don't look terrible + painter->setRenderHint(QPainter::Antialiasing, true); + + //Set pen attributes + QColor myColor(Qt::red); + myPen.setWidth(3); + myPen.setColor(myColor); + painter->setPen(myPen); + painter->drawPolygon(arrowHead); + painter->setPen(myPen); + painter->drawLine(arrowShaft); + + //Set trend arc's color + myPen.setColor(Qt::magenta); + painter->setPen(myPen); + + if (trendSpanAngle > 0){ + QRectF rect(0, -trendRadius, trendRadius*2, trendRadius*2); + painter->drawArc(rect, 180*16, -trendSpanAngle*16); + } + else{ + QRectF rect(-2*trendRadius, -trendRadius, trendRadius*2, trendRadius*2); + painter->drawArc(rect, 0*16, -trendSpanAngle*16); + } + + //*********** Create time rings + if(groundspeed_mps_filt > 0){ //Don't clutter the display with rings that are only one pixel wide + myPen.setWidth(2); + + myPen.setColor(QColor(0, 0, 0, 100)); + painter->setPen(myPen); + painter->drawEllipse(QPointF(0,0),precalcRings,precalcRings); + + myPen.setColor(QColor(0, 0, 0, 110)); + painter->setPen(myPen); + painter->drawEllipse(QPointF(0,0),precalcRings*2,precalcRings*2); + + myPen.setColor(QColor(0, 0, 0, 120)); + painter->setPen(myPen); + painter->drawEllipse(QPointF(0,0),precalcRings*4,precalcRings*4); + } + //Rotate the text back to vertical + qreal rot=this->rotation(); + painter->rotate(-1*rot); + + myPen.setWidth(1); + myPen.setColor(Qt::white); + painter->setBrush(Qt::white); + painter->setPen(myPen); + painter->drawPath(textPath); } + + void UAVItem::updateTextOverlay() + { + QPainterPath temp; + if(!showUAVInfo) + { + temp.swap(textPath); + return; + } + + QFont borderfont( "Arial", 14, QFont::Normal, false ); + + //Top left corner of text + int textAnchorX = 20; + int textAnchorY = 20; + + QString uavoInfoStrLine1, uavoInfoStrLine2; + QString uavoInfoStrLine3, uavoInfoStrLine4; + QString uavoInfoStrLine5; + + uavoInfoStrLine2.append(QString("Groundspeed: %1 kph").arg(groundspeed_kph, 0, 'f',1)); + uavoInfoStrLine3.append(QString("Lat-Lon: %1, %2").arg(coord.Lat(), 0, 'f',7).arg(coord.Lng(), 0, 'f',7)); + uavoInfoStrLine4.append(QString("North-East: %1 m, %2 m").arg(NED[0], 0, 'f',1).arg(NED[1], 0, 'f',1)); + uavoInfoStrLine5.append(QString("Altitude: %1 m").arg(-NED[2], 0, 'f',1)); + temp.addText(textAnchorX, textAnchorY+16*0, borderfont, uavoInfoStrLine1); + temp.addText(textAnchorX, textAnchorY+16*1, borderfont, uavoInfoStrLine2); + temp.addText(textAnchorX, textAnchorY+16*2, borderfont, uavoInfoStrLine3); + temp.addText(textAnchorX, textAnchorY+16*3, borderfont, uavoInfoStrLine4); + temp.addText(textAnchorX, textAnchorY+16*4, borderfont, uavoInfoStrLine5); + + //Add text for time rings. + if(groundspeed_mps > 0){ + //Always add the left side... + temp.addText(-(groundspeed_mps_filt*ringTime*1*meters2pixels+10), 0, borderfont, QString("%1 s").arg(ringTime,0,'f',0)); + temp.addText(-(groundspeed_mps_filt*ringTime*2*meters2pixels+10), 0, borderfont, QString("%1 s").arg(ringTime*2,0,'f',0)); + temp.addText(-(groundspeed_mps_filt*ringTime*4*meters2pixels+10), 0, borderfont, QString("%1 s").arg(ringTime*4,0,'f',0)); + //... and add the right side, only if it doesn't interfere with the uav info text + if(groundspeed_mps_filt*ringTime*4*meters2pixels > 200){ + if(groundspeed_mps_filt*ringTime*2*meters2pixels > 200){ + if(groundspeed_mps_filt*ringTime*1*meters2pixels > 200){ + temp.addText(groundspeed_mps_filt*ringTime*1*meters2pixels-8, 0, borderfont, QString("%1 s").arg(ringTime,0,'f',0)); + } + temp.addText(groundspeed_mps_filt*ringTime*2*meters2pixels-8, 0, borderfont, QString("%1 s").arg(ringTime*2,0,'f',0)); + } + temp.addText(groundspeed_mps_filt*ringTime*4*meters2pixels-8, 0, borderfont, QString("%1 s").arg(ringTime*4,0,'f',0)); + } + } + temp.swap(textPath); + } + QRectF UAVItem::boundingRect()const { - return QRectF(-pic.width()/2,-pic.height()/2,pic.width(),pic.height()); + if(showUAVInfo){ + if (boundingRectSize < 220){ + //In case the bounding rectangle isn't big enough to get the whole of the UAV Info graphic + return QRectF(-boundingRectSize,-80,boundingRectSize+220,180); + } + else{ + return QRectF(-boundingRectSize,-boundingRectSize,2*boundingRectSize,2*boundingRectSize); + } + } + else{ + return QRectF(-pic.width()/2,-pic.height()/2,pic.width(),pic.height()); + } } + + void UAVItem::SetNED(double NED[3]){ + this->NED[0] = NED[0]; + this->NED[1] = NED[1]; + this->NED[2] = NED[2]; + } + + void UAVItem::SetYawRate(double yawRate_dps){ + this->yawRate_dps=yawRate_dps; + + if (fabs(this->yawRate_dps) < 5e-1){ //This number is really the smallest we can go. Any smaller, and it might have problems if we forecast a shorter distance into the future + this->yawRate_dps=5e-1; + } + + //*********** Create trend arc + trendSpanAngle = this->yawRate_dps * 5; //Forecast 5 seconds into the future + + //Calculate radius in [m], and then convert to pixels in local frame (not the same frame as is displayed on the map widget) + trendRadius=fabs(groundspeed_mps/(this->yawRate_dps*M_PI/180))*meters2pixels; + } + + void UAVItem::SetCAS(double CAS_mps){ + this->CAS_mps=CAS_mps; + } + + void UAVItem::SetGroundspeed(double vNED[3], int m_maxUpdateRate_ms){ + this->vNED[0] = vNED[0]; + this->vNED[1] = vNED[1]; + this->vNED[2] = vNED[2]; + groundspeed_kph=sqrt(vNED[0]*vNED[0] + vNED[1]*vNED[1] + vNED[2]*vNED[2])*3.6; + groundspeed_mps=groundspeed_kph/3.6; + //On the first pass, set the filtered speed to the reported speed. + static bool firstGroundspeed=true; + if (firstGroundspeed){ + groundspeed_mps_filt=groundspeed_kph/3.6; + firstGroundspeed=false; + } + else{ + int riseTime_ms=1000; + double alpha= m_maxUpdateRate_ms/(double)(m_maxUpdateRate_ms+riseTime_ms); + groundspeed_mps_filt= alpha*groundspeed_mps_filt + (1-alpha)*(groundspeed_kph/3.6); + } + ringTime=10*pow(2,17-map->ZoomTotal()); //Basic ring is 10 seconds wide at zoom level 17 + precalcRings=groundspeed_mps_filt*ringTime*meters2pixels; + boundingRectSize=groundspeed_mps_filt*ringTime*4*meters2pixels+20; + prepareGeometryChange(); + } + + void UAVItem::SetUAVPos(const internals::PointLatLng &position, const int &altitude) { if(coord.IsEmpty()) @@ -76,9 +255,15 @@ namespace mapcontrol { if(timer.elapsed()>trailtime*1000) { - trail->addToGroup(new TrailItem(position,altitude,Qt::red,this)); + TrailItem * ob=new TrailItem(position,altitude,Qt::green,map); + trail->addToGroup(ob); + connect(this,SIGNAL(setChildPosition()),ob,SLOT(setPosSLOT())); if(!lasttrailline.IsEmpty()) - trailLine->addToGroup((new TrailLineItem(lasttrailline,position,Qt::red,map))); + { + TrailLineItem * obj=new TrailLineItem(lasttrailline,position,Qt::red,map); + trailLine->addToGroup(obj); + connect(this,SIGNAL(setChildLine()),obj,SLOT(setLineSlot())); + } lasttrailline=position; timer.restart(); } @@ -88,9 +273,15 @@ namespace mapcontrol { if(qAbs(internals::PureProjection::DistanceBetweenLatLng(lastcoord,position)*1000)>traildistance) { - trail->addToGroup(new TrailItem(position,altitude,Qt::red,this)); + TrailItem * ob=new TrailItem(position,altitude,Qt::green,map); + trail->addToGroup(ob); + connect(this,SIGNAL(setChildPosition()),ob,SLOT(setPosSLOT())); if(!lasttrailline.IsEmpty()) - trailLine->addToGroup((new TrailLineItem(lasttrailline,position,Qt::red,map))); + { + TrailLineItem * obj=new TrailLineItem(lasttrailline,position,Qt::red,map); + trailLine->addToGroup(obj); + connect(this,SIGNAL(setChildLine()),obj,SLOT(setLineSlot())); + } lasttrailline=position; lastcoord=position; } @@ -102,7 +293,6 @@ namespace mapcontrol { mapwidget->SetCurrentPosition(coord); } - this->update(); if(autosetreached) { foreach(QGraphicsItem* i,map->childItems()) @@ -170,19 +360,24 @@ namespace mapcontrol { localposition=map->FromLatLngToLocal(coord); this->setPos(localposition.X(),localposition.Y()); - foreach(QGraphicsItem* i,trail->childItems()) - { - TrailItem* w=qgraphicsitem_cast(i); - if(w) - w->setPos(map->FromLatLngToLocal(w->coord).X(),map->FromLatLngToLocal(w->coord).Y()); - } - foreach(QGraphicsItem* i,trailLine->childItems()) - { - TrailLineItem* ww=qgraphicsitem_cast(i); - if(ww) - ww->setLine(map->FromLatLngToLocal(ww->coord1).X(),map->FromLatLngToLocal(ww->coord1).Y(),map->FromLatLngToLocal(ww->coord2).X(),map->FromLatLngToLocal(ww->coord2).Y()); - } + emit setChildPosition(); + emit setChildLine(); + updateTextOverlay(); + } + void UAVItem::setOpacitySlot(qreal opacity) + { + this->setOpacity(opacity); + } + + void UAVItem::zoomChangedSlot() + { + double pixels2meters = map->Projection()->GetGroundResolution(map->ZoomTotal(),coord.Lat()); + meters2pixels=1.0 / pixels2meters; + boundingRectSize=groundspeed_mps_filt*ringTime*4*meters2pixels+20; + prepareGeometryChange(); + updateTextOverlay(); + update(); } void UAVItem::SetTrailType(const UAVTrailType::Types &value) { @@ -217,4 +412,40 @@ namespace mapcontrol { pic.load(":/uavs/images/"+UAVPic); } + + void UAVItem::SetShowUAVInfo(bool const& value) + { + showUAVInfo=value; + showJustChanged=true; + update(); + } + + void UAVItem::generateArrowhead(){ + qreal arrowSize = 10; + + //Create line from (0,0), to (1,1). Later, we'll scale and rotate it + arrowShaft=QLineF(0,0,1.0,1.0); + + //Set the starting point to (0,0) + arrowShaft.setP1(QPointF(0,0)); + + //Set angle and length + arrowShaft.setLength(60.0); + arrowShaft.setAngle(90.0); + + //Form arrowhead + double angle = ::acos(arrowShaft.dx() / arrowShaft.length()); + if (arrowShaft.dy() <= 0) + angle = (M_PI * 2) - angle; + + QPointF arrowP1 = arrowShaft.pointAt(1) + QPointF(sin(angle + M_PI / 3) * arrowSize, + cos(angle + M_PI / 3) * arrowSize); + QPointF arrowP2 = arrowShaft.pointAt(1) + QPointF(sin(angle + M_PI - M_PI / 3) * arrowSize, + cos(angle + M_PI - M_PI / 3) * arrowSize); + + //Assemble arrowhead + arrowHead.clear(); + arrowHead << arrowShaft.pointAt(1) << arrowP1 << arrowP2; + + } } diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/uavitem.h b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/uavitem.h index ca41a3d3d..472563f37 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/uavitem.h +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/uavitem.h @@ -2,7 +2,7 @@ ****************************************************************************** * * @file uavitem.h -* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @brief A graphicsItem representing a WayPoint * @see The GNU Public License (GPL) Version 3 * @defgroup OPMapWidget @@ -57,6 +57,31 @@ namespace mapcontrol enum { Type = UserType + 2 }; UAVItem(MapGraphicItem* map,OPMapWidget* parent, QString uavPic=QString::fromUtf8(":/uavs/images/mapquad.png")); ~UAVItem(); + + /** + * @brief Sets the UAV NED position + * + * @param NED + */ + void SetNED(double NED[3]); + /** + * @brief Sets the UAV groundspeed + * + * @param NED + */ + void SetGroundspeed(double vNED[3], int m_maxUpdateRate); + /** + * @brief Sets the UAV Calibrated Airspeed + * + * @param NED + */ + void SetCAS(double CAS); + /** + * @brief Sets the UAV yaw rate + * + * @param NED + */ + void SetYawRate(double yawRate_dps); /** * @brief Sets the UAV position * @@ -103,7 +128,6 @@ namespace mapcontrol void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); - void RefreshPos(); QRectF boundingRect() const; /** * @brief Sets the trail time to be used if TrailType is ByTimeElapsed @@ -193,17 +217,32 @@ namespace mapcontrol int type() const; void SetUavPic(QString UAVPic); + void SetShowUAVInfo(bool const& value); + void updateTextOverlay(); private: + void generateArrowhead(); MapGraphicItem* map; - + OPMapWidget* mapwidget; + QPolygonF arrowHead; + QLineF arrowShaft; int altitude; UAVMapFollowType::Types mapfollowtype; UAVTrailType::Types trailtype; internals::PointLatLng coord; internals::PointLatLng lastcoord; + double NED[3]; + double vNED[3]; + double CAS_mps; + double groundspeed_kph; + double groundspeed_mps; + double yawRate_dps; + double trendRadius; + double trendSpanAngle; + float meters2pixels; + double precalcRings; + double ringTime; QPixmap pic; core::Point localposition; - OPMapWidget* mapwidget; QGraphicsItemGroup* trail; QGraphicsItemGroup * trailLine; internals::PointLatLng lasttrailline; @@ -215,13 +254,24 @@ namespace mapcontrol bool autosetreached; double Distance3D(internals::PointLatLng const& coord, int const& altitude); double autosetdistance; - // QRectF rect; + bool showUAVInfo; + static double groundspeed_mps_filt; + float boundingRectSize; + bool showJustChanged; + + bool refreshPaint_flag; + + QPainterPath textPath; public slots: - + void RefreshPos(); + void setOpacitySlot(qreal opacity); + void zoomChangedSlot(); signals: void UAVReachedWayPoint(int const& waypointnumber,WayPointItem* waypoint); void UAVLeftSafetyBouble(internals::PointLatLng const& position); + void setChildPosition(); + void setChildLine(); }; } #endif // UAVITEM_H diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/uavmapfollowtype.h b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/uavmapfollowtype.h index a2321a4c3..5fca96b68 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/uavmapfollowtype.h +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/uavmapfollowtype.h @@ -2,7 +2,7 @@ ****************************************************************************** * * @file uavmapfollowtype.h -* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @brief An enum representing the various map follow modes * @see The GNU Public License (GPL) Version 3 * @defgroup OPMapWidget diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/uavtrailtype.h b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/uavtrailtype.h index e9a852960..df8489aa7 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/uavtrailtype.h +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/uavtrailtype.h @@ -2,7 +2,7 @@ ****************************************************************************** * * @file uavtrailtype.h -* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @brief An enum representing the uav trailing modes * @see The GNU Public License (GPL) Version 3 * @defgroup OPMapWidget diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/waypointcircle.cpp b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/waypointcircle.cpp new file mode 100644 index 000000000..9f045a701 --- /dev/null +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/waypointcircle.cpp @@ -0,0 +1,116 @@ +/** +****************************************************************************** +* +* @file waypointcircle.cpp +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. +* @brief A graphicsItem representing a circle connecting 2 waypoints +* @see The GNU Public License (GPL) Version 3 +* @defgroup OPMapWidget +* @{ +* +*****************************************************************************/ +/* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +* for more details. +* +* You should have received a copy of the GNU General Public License along +* with this program; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ +#include "waypointcircle.h" +#include +#include "homeitem.h" + +namespace mapcontrol +{ +WayPointCircle::WayPointCircle(WayPointItem *center, WayPointItem *radius,bool clockwise, MapGraphicItem *map,QColor color):my_center(center), + my_radius(radius),my_map(map),QGraphicsEllipseItem(map),myColor(color),myClockWise(clockwise) +{ + connect(center,SIGNAL(localPositionChanged(QPointF,WayPointItem*)),this,SLOT(refreshLocations())); + connect(radius,SIGNAL(localPositionChanged(QPointF,WayPointItem*)),this,SLOT(refreshLocations())); + connect(center,SIGNAL(aboutToBeDeleted(WayPointItem*)),this,SLOT(waypointdeleted())); + connect(radius,SIGNAL(aboutToBeDeleted(WayPointItem*)),this,SLOT(waypointdeleted())); + refreshLocations(); + connect(map,SIGNAL(childSetOpacity(qreal)),this,SLOT(setOpacitySlot(qreal))); + +} + +WayPointCircle::WayPointCircle(HomeItem *radius, WayPointItem *center, bool clockwise, MapGraphicItem *map, QColor color):my_center(center), + my_radius(radius),my_map(map),QGraphicsEllipseItem(map),myColor(color),myClockWise(clockwise) +{ + connect(radius,SIGNAL(homePositionChanged(internals::PointLatLng,float)),this,SLOT(refreshLocations())); + connect(center,SIGNAL(localPositionChanged(QPointF)),this,SLOT(refreshLocations())); + connect(center,SIGNAL(aboutToBeDeleted(WayPointItem*)),this,SLOT(waypointdeleted())); + refreshLocations(); + connect(map,SIGNAL(childSetOpacity(qreal)),this,SLOT(setOpacitySlot(qreal))); +} + +int WayPointCircle::type() const +{ + // Enable the use of qgraphicsitem_cast with this item. + return Type; +} + +void WayPointCircle::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) +{ + QPointF p1; + QPointF p2; + p1=QPointF(line.p1().x(),line.p1().y()+line.length()); + p2=QPointF(line.p1().x(),line.p1().y()-line.length()); + QPen myPen = pen(); + myPen.setColor(myColor); + qreal arrowSize = 10; + painter->setPen(myPen); + QBrush brush=painter->brush(); + painter->setBrush(myColor); + double angle =0; + if(!myClockWise) + angle+=M_PI; + + QPointF arrowP1 = p1 + QPointF(sin(angle + M_PI / 3) * arrowSize, + cos(angle + M_PI / 3) * arrowSize); + QPointF arrowP2 = p1 + QPointF(sin(angle + M_PI - M_PI / 3) * arrowSize, + cos(angle + M_PI - M_PI / 3) * arrowSize); + + QPointF arrowP21 = p2 + QPointF(sin(angle + M_PI + M_PI / 3) * arrowSize, + cos(angle + M_PI + M_PI / 3) * arrowSize); + QPointF arrowP22 = p2 + QPointF(sin(angle + M_PI + M_PI - M_PI / 3) * arrowSize, + cos(angle + M_PI + M_PI - M_PI / 3) * arrowSize); + + arrowHead.clear(); + arrowHead << p1 << arrowP1 << arrowP2; + painter->drawPolygon(arrowHead); + arrowHead.clear(); + arrowHead << p2 << arrowP21 << arrowP22; + painter->drawPolygon(arrowHead); + painter->translate(-line.length(),-line.length()); + painter->setBrush(brush); + painter->drawEllipse(this->rect()); + +} + +void WayPointCircle::refreshLocations() +{ + line=QLineF(my_center->pos(),my_radius->pos()); + this->setRect(my_center->pos().x(),my_center->pos().y(),2*line.length(),2*line.length()); + this->update(); +} + +void WayPointCircle::waypointdeleted() +{ + this->deleteLater(); +} + +void WayPointCircle::setOpacitySlot(qreal opacity) +{ + setOpacity(opacity); +} + +} diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/waypointcircle.h b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/waypointcircle.h new file mode 100644 index 000000000..db839819d --- /dev/null +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/waypointcircle.h @@ -0,0 +1,69 @@ +/** +****************************************************************************** +* +* @file waypointcircle.h +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. +* @brief A graphicsItem representing a circle connecting 2 waypoints +* @see The GNU Public License (GPL) Version 3 +* @defgroup OPMapWidget +* @{ +* +*****************************************************************************/ +/* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +* for more details. +* +* You should have received a copy of the GNU General Public License along +* with this program; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ +#ifndef WAYPOINTCIRCLE_H +#define WAYPOINTCIRCLE_H +#include +#include +#include +#include "../internals/pointlatlng.h" +#include "mapgraphicitem.h" +#include "waypointitem.h" +#include +#include + +namespace mapcontrol +{ + +class WayPointCircle:public QObject,public QGraphicsEllipseItem +{ + Q_OBJECT + Q_INTERFACES(QGraphicsItem) +public: + enum { Type = UserType + 9 }; + WayPointCircle(WayPointItem * center, WayPointItem * radius,bool clockwise,MapGraphicItem * map,QColor color=Qt::green); + WayPointCircle(HomeItem * center, WayPointItem * radius,bool clockwise,MapGraphicItem * map,QColor color=Qt::green); + int type() const; + void setColor(const QColor &color) + { myColor = color; } +private: + QGraphicsItem * my_center; + QGraphicsItem * my_radius; + MapGraphicItem * my_map; + QPolygonF arrowHead; + QColor myColor; + bool myClockWise; + QLineF line; +protected: + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); +public slots: + void refreshLocations(); + void waypointdeleted(); + void setOpacitySlot(qreal opacity); +}; +} + +#endif // WAYPOINTCIRCLE_H diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/waypointitem.cpp b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/waypointitem.cpp index 5fd972502..280d88d0c 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/waypointitem.cpp +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/waypointitem.cpp @@ -2,7 +2,7 @@ ****************************************************************************** * * @file waypointitem.cpp -* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @brief A graphicsItem representing a WayPoint * @see The GNU Public License (GPL) Version 3 * @defgroup OPMapWidget @@ -25,39 +25,167 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "waypointitem.h" +#include "homeitem.h" + namespace mapcontrol { - WayPointItem::WayPointItem(const internals::PointLatLng &coord,int const& altitude, MapGraphicItem *map):coord(coord),reached(false),description(""),shownumber(true),isDragging(false),altitude(altitude),map(map) +WayPointItem::WayPointItem(const internals::PointLatLng &coord,int const& altitude, MapGraphicItem *map,wptype type):coord(coord),reached(false),description(""),shownumber(true),isDragging(false),altitude(altitude),map(map),myType(type) { text=0; numberI=0; + isMagic=false; picture.load(QString::fromUtf8(":/markers/images/marker.png")); number=WayPointItem::snumber; ++WayPointItem::snumber; this->setFlag(QGraphicsItem::ItemIsMovable,true); this->setFlag(QGraphicsItem::ItemIgnoresTransformations,true); this->setFlag(QGraphicsItem::ItemIsSelectable,true); - // transf.translate(picture.width()/2,picture.height()); - // this->setTransform(transf); SetShowNumber(shownumber); RefreshToolTip(); RefreshPos(); + myHome=NULL; + QList list=map->childItems(); + foreach(QGraphicsItem * obj,list) + { + HomeItem* h=qgraphicsitem_cast (obj); + if(h) + myHome=h; + } + + if(myHome) + { + map->Projection()->offSetFromLatLngs(myHome->Coord(),coord,relativeCoord.distance,relativeCoord.bearing); + relativeCoord.altitudeRelative=Altitude()-myHome->Altitude(); + connect(myHome,SIGNAL(homePositionChanged(internals::PointLatLng,float)),this,SLOT(onHomePositionChanged(internals::PointLatLng,float))); + } + connect(this,SIGNAL(waypointdoubleclick(WayPointItem*)),map,SIGNAL(wpdoubleclicked(WayPointItem*))); + emit manualCoordChange(this); + connect(map,SIGNAL(childRefreshPosition()),this,SLOT(RefreshPos())); + connect(map,SIGNAL(childSetOpacity(qreal)),this,SLOT(setOpacitySlot(qreal))); +} + +WayPointItem::WayPointItem(MapGraphicItem *map, bool magicwaypoint):reached(false),description(""),shownumber(true),isDragging(false),altitude(0),map(map) +{ + relativeCoord.bearing=0; + relativeCoord.distance=0; + relativeCoord.altitudeRelative=0; + myType=relative; + if(magicwaypoint) + { + isMagic=true; + picture.load(QString::fromUtf8(":/opmap/images/waypoint_marker3.png")); + number=-1; } - WayPointItem::WayPointItem(const internals::PointLatLng &coord,int const& altitude, const QString &description, MapGraphicItem *map):coord(coord),reached(false),description(description),shownumber(true),isDragging(false),altitude(altitude),map(map) + else + { + isMagic=false; + number=WayPointItem::snumber; + ++WayPointItem::snumber; + } + text=0; + numberI=0; + this->setFlag(QGraphicsItem::ItemIsMovable,true); + this->setFlag(QGraphicsItem::ItemIgnoresTransformations,true); + this->setFlag(QGraphicsItem::ItemIsSelectable,true); + SetShowNumber(shownumber); + RefreshToolTip(); + RefreshPos(); + myHome=NULL; + QList list=map->childItems(); + foreach(QGraphicsItem * obj,list) + { + HomeItem* h=qgraphicsitem_cast (obj); + if(h) + myHome=h; + } + + if(myHome) + { + coord=map->Projection()->translate(myHome->Coord(),relativeCoord.distance,relativeCoord.bearing); + SetAltitude(myHome->Altitude()+relativeCoord.altitudeRelative); + connect(myHome,SIGNAL(homePositionChanged(internals::PointLatLng,float)),this,SLOT(onHomePositionChanged(internals::PointLatLng,float))); + } + connect(this,SIGNAL(waypointdoubleclick(WayPointItem*)),map,SIGNAL(wpdoubleclicked(WayPointItem*))); + emit manualCoordChange(this); + connect(map,SIGNAL(childRefreshPosition()),this,SLOT(RefreshPos())); + connect(map,SIGNAL(childSetOpacity(qreal)),this,SLOT(setOpacitySlot(qreal))); +} + WayPointItem::WayPointItem(const internals::PointLatLng &coord,int const& altitude, const QString &description, MapGraphicItem *map,wptype type):coord(coord),reached(false),description(description),shownumber(true),isDragging(false),altitude(altitude),map(map),myType(type) { text=0; numberI=0; + isMagic=false; picture.load(QString::fromUtf8(":/markers/images/marker.png")); number=WayPointItem::snumber; ++WayPointItem::snumber; this->setFlag(QGraphicsItem::ItemIsMovable,true); this->setFlag(QGraphicsItem::ItemIgnoresTransformations,true); this->setFlag(QGraphicsItem::ItemIsSelectable,true); - //transf.translate(picture.width()/2,picture.height()); - // this->setTransform(transf); SetShowNumber(shownumber); RefreshToolTip(); RefreshPos(); + myHome=NULL; + QList list=map->childItems(); + foreach(QGraphicsItem * obj,list) + { + HomeItem* h=qgraphicsitem_cast (obj); + if(h) + myHome=h; + } + if(myHome) + { + map->Projection()->offSetFromLatLngs(myHome->Coord(),coord,relativeCoord.distance,relativeCoord.bearing); + relativeCoord.altitudeRelative=Altitude()-myHome->Altitude(); + connect(myHome,SIGNAL(homePositionChanged(internals::PointLatLng,float)),this,SLOT(onHomePositionChanged(internals::PointLatLng,float))); + } + connect(this,SIGNAL(waypointdoubleclick(WayPointItem*)),map,SIGNAL(wpdoubleclicked(WayPointItem*))); + emit manualCoordChange(this); + connect(map,SIGNAL(childRefreshPosition()),this,SLOT(RefreshPos())); + connect(map,SIGNAL(childSetOpacity(qreal)),this,SLOT(setOpacitySlot(qreal))); + } + + WayPointItem::WayPointItem(const distBearingAltitude &relativeCoordenate, const QString &description, MapGraphicItem *map):relativeCoord(relativeCoordenate),reached(false),description(description),shownumber(true),isDragging(false),map(map) + { + myHome=NULL; + QList list=map->childItems(); + foreach(QGraphicsItem * obj,list) + { + HomeItem* h=qgraphicsitem_cast (obj); + if(h) + myHome=h; + } + if(myHome) + { + connect(myHome,SIGNAL(homePositionChanged(internals::PointLatLng,float)),this,SLOT(onHomePositionChanged(internals::PointLatLng,float))); + coord=map->Projection()->translate(myHome->Coord(),relativeCoord.distance,relativeCoord.bearing); + SetAltitude(myHome->Altitude()+relativeCoord.altitudeRelative); + } + myType=relative; + text=0; + numberI=0; + isMagic=false; + picture.load(QString::fromUtf8(":/markers/images/marker.png")); + number=WayPointItem::snumber; + ++WayPointItem::snumber; + this->setFlag(QGraphicsItem::ItemIsMovable,true); + this->setFlag(QGraphicsItem::ItemIgnoresTransformations,true); + this->setFlag(QGraphicsItem::ItemIsSelectable,true); + SetShowNumber(shownumber); + RefreshToolTip(); + RefreshPos(); + connect(this,SIGNAL(waypointdoubleclick(WayPointItem*)),map,SIGNAL(wpdoubleclicked(WayPointItem*))); + emit manualCoordChange(this); + connect(map,SIGNAL(childRefreshPosition()),this,SLOT(RefreshPos())); + connect(map,SIGNAL(childSetOpacity(qreal)),this,SLOT(setOpacitySlot(qreal))); + } + + void WayPointItem::setWPType(wptype type) + { + myType=type; + emit WPValuesChanged(this); + RefreshPos(); + RefreshToolTip(); + this->update(); } QRectF WayPointItem::boundingRect() const @@ -69,28 +197,34 @@ namespace mapcontrol Q_UNUSED(option); Q_UNUSED(widget); painter->drawPixmap(-picture.width()/2,-picture.height(),picture); + painter->setPen(Qt::green); if(this->isSelected()) painter->drawRect(QRectF(-picture.width()/2,-picture.height(),picture.width()-1,picture.height()-1)); } + void WayPointItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) + { + if(event->button()==Qt::LeftButton) + { + emit waypointdoubleclick(this); + } + } + void WayPointItem::mousePressEvent(QGraphicsSceneMouseEvent *event) { if(event->button()==Qt::LeftButton) { - text=new QGraphicsSimpleTextItem(this); + text=new QGraphicsSimpleTextItem(this); textBG=new QGraphicsRectItem(this); -// textBG->setBrush(Qt::white); -// textBG->setOpacity(0.5); + textBG->setBrush(Qt::yellow); - textBG->setBrush(QColor(255, 255, 255, 128)); - - text->setPen(QPen(Qt::red)); - text->setPos(10,-picture.height()); - textBG->setPos(10,-picture.height()); - text->setZValue(3); - RefreshToolTip(); - isDragging=true; - } + text->setPen(QPen(Qt::red)); + text->setPos(10,-picture.height()); + textBG->setPos(10,-picture.height()); + text->setZValue(3); + RefreshToolTip(); + isDragging=true; + } QGraphicsItem::mousePressEvent(event); } void WayPointItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) @@ -98,18 +232,22 @@ namespace mapcontrol QGraphicsItem::mouseReleaseEvent(event); if(event->button()==Qt::LeftButton) { - if(text) { + if(text) + { delete text; - text = NULL; + text=NULL; } - if(textBG) { + if(textBG) + { delete textBG; - textBG = NULL; + textBG=NULL; } coord=map->FromLocalToLatLng(this->pos().x(),this->pos().y()); + isDragging=false; RefreshToolTip(); - + emit manualCoordChange(this); + emit localPositionChanged(this->pos(),this); emit WPValuesChanged(this); emit WPDropped(this); } @@ -121,31 +259,77 @@ namespace mapcontrol { coord=map->FromLocalToLatLng(this->pos().x(),this->pos().y()); QString coord_str = " " + QString::number(coord.Lat(), 'f', 6) + " " + QString::number(coord.Lng(), 'f', 6); - text->setText(coord_str); + if(myHome) + { + map->Projection()->offSetFromLatLngs(myHome->Coord(),coord,relativeCoord.distance,relativeCoord.bearing); + } + QString relativeCoord_str = QString::number(relativeCoord.distance) + "m " + QString::number(relativeCoord.bearing*180/M_PI)+"deg"; + text->setText(coord_str+"\n"+relativeCoord_str); textBG->setRect(text->boundingRect()); - + emit localPositionChanged(this->pos(),this); emit WPValuesChanged(this); } QGraphicsItem::mouseMoveEvent(event); } - void WayPointItem::SetAltitude(const int &value) + void WayPointItem::SetAltitude(const float &value) { + if(altitude==value) + return; altitude=value; + if(myHome) + { + relativeCoord.altitudeRelative=altitude-myHome->Altitude(); + } RefreshToolTip(); - emit WPValuesChanged(this); this->update(); } + + void WayPointItem::setRelativeCoord(distBearingAltitude value) + { + if(qAbs(value.distance-relativeCoord.distance)<0.1 + && qAbs(value.bearing-relativeCoord.bearing)<0.01 && value.altitudeRelative==relativeCoord.altitudeRelative) + return; + relativeCoord=value; + if(myHome) + { + SetCoord(map->Projection()->translate(myHome->Coord(),relativeCoord.distance,relativeCoord.bearing)); + SetAltitude(myHome->Altitude()+relativeCoord.altitudeRelative); + } + RefreshPos(); + RefreshToolTip(); + emit WPValuesChanged(this); + this->update(); + } + void WayPointItem::SetCoord(const internals::PointLatLng &value) { + qDebug()<<"1 SetCoord("<Projection()->offSetFromLatLngs(myHome->Coord(),Coord(),back.distance,back.bearing); + if(qAbs(back.bearing-relativeCoord.bearing)>0.01 || qAbs(back.distance-relativeCoord.distance)>0.1) + { + qDebug()<<"4 setCoord-relative coordinates where also updated"; + relativeCoord=back; + } emit WPValuesChanged(this); RefreshPos(); RefreshToolTip(); this->update(); + qDebug()<<"5 setCoord EXIT"; } void WayPointItem::SetDescription(const QString &value) { + if(description==value) + return; description=value; RefreshToolTip(); emit WPValuesChanged(this); @@ -153,12 +337,13 @@ namespace mapcontrol } void WayPointItem::SetNumber(const int &value) { - emit WPNumberChanged(number,value,this); + int oldnumber=number; number=value; RefreshToolTip(); - numberI->setText(QString::number(number)); + numberI->setText(QString::number(numberAdjusted())); numberIBG->setRect(numberI->boundingRect().adjusted(-2,0,1,0)); this->update(); + emit WPNumberChanged(oldnumber,value,this); } void WayPointItem::SetReached(const bool &value) { @@ -167,8 +352,20 @@ namespace mapcontrol if(value) picture.load(QString::fromUtf8(":/markers/images/bigMarkerGreen.png")); else - picture.load(QString::fromUtf8(":/markers/images/marker.png")); - this->update(); + { + if(!isMagic) + { + if(this->flags() & QGraphicsItem::ItemIsMovable==QGraphicsItem::ItemIsMovable) + picture.load(QString::fromUtf8(":/markers/images/marker.png")); + else + picture.load(QString::fromUtf8(":/markers/images/waypoint_marker2.png")); + } + else + { + picture.load(QString::fromUtf8(":/opmap/images/waypoint_marker3.png")); + } + } + this->update(); } void WayPointItem::SetShowNumber(const bool &value) @@ -184,7 +381,7 @@ namespace mapcontrol numberI->setPen(QPen(Qt::blue)); numberI->setPos(0,-13-picture.height()); numberIBG->setPos(0,-13-picture.height()); - numberI->setText(QString::number(number)); + numberI->setText(QString::number(numberAdjusted())); numberIBG->setRect(numberI->boundingRect().adjusted(-2,0,1,0)); } else if (!value && numberI) @@ -194,49 +391,61 @@ namespace mapcontrol } this->update(); } - void WayPointItem::WPDeleted(const int &onumber) + void WayPointItem::WPDeleted(const int &onumber,WayPointItem *waypoint) { - if(number>onumber) --number; - numberI->setText(QString::number(number)); - numberIBG->setRect(numberI->boundingRect().adjusted(-2,0,1,0)); - RefreshToolTip(); - this->update(); + Q_UNUSED(waypoint); + int n=number; + if(number>onumber) SetNumber(--n); } void WayPointItem::WPInserted(const int &onumber, WayPointItem *waypoint) { + if(Number()==-1) + return; + if(waypoint!=this) { - if(onumber<=number) ++number; - numberI->setText(QString::number(number)); + if(onumber<=number) SetNumber(++number); + } + } + + void WayPointItem::onHomePositionChanged(internals::PointLatLng homepos, float homeAltitude) + { + if(myType==relative) + { + coord=map->Projection()->translate(homepos,relativeCoord.distance,relativeCoord.bearing); + SetAltitude(relativeCoord.altitudeRelative+homeAltitude); + emit WPValuesChanged(this); + RefreshPos(); RefreshToolTip(); this->update(); } + else + { + if(myHome) + { + map->Projection()->offSetFromLatLngs(myHome->Coord(),coord,relativeCoord.distance,relativeCoord.bearing); + relativeCoord.altitudeRelative=Altitude()-homeAltitude; + } + emit WPValuesChanged(this); + } } + void WayPointItem::WPRenumbered(const int &oldnumber, const int &newnumber, WayPointItem *waypoint) { if (waypoint!=this) { if(((oldnumber>number) && (newnumber<=number))) { - ++number; - numberI->setText(QString::number(number)); - numberIBG->setRect(numberI->boundingRect().adjusted(-2,0,1,0)); - RefreshToolTip(); + SetNumber(++number); } else if (((oldnumbernumber))) { - --number; - numberI->setText(QString::number(number)); - numberIBG->setRect(numberI->boundingRect().adjusted(-2,0,1,0)); - RefreshToolTip(); + SetNumber(--number); } else if (newnumber==number) { - ++number; - numberI->setText(QString::number(number)); - RefreshToolTip(); + SetNumber(++number); } - this->update(); } } int WayPointItem::type() const @@ -247,17 +456,51 @@ namespace mapcontrol WayPointItem::~WayPointItem() { + emit aboutToBeDeleted(this); --WayPointItem::snumber; } void WayPointItem::RefreshPos() { core::Point point=map->FromLatLngToLocal(coord); this->setPos(point.X(),point.Y()); + emit localPositionChanged(this->pos(),this); + } + + void WayPointItem::setOpacitySlot(qreal opacity) + { + setOpacity(opacity); } void WayPointItem::RefreshToolTip() { + QString type_str; + if(myType==relative) + type_str="Relative"; + else + type_str="Absolute"; QString coord_str = " " + QString::number(coord.Lat(), 'f', 6) + " " + QString::number(coord.Lng(), 'f', 6); - setToolTip(QString("WayPoint Number:%1\nDescription:%2\nCoordinate:%4\nAltitude:%5").arg(QString::number(WayPointItem::number)).arg(description).arg(coord_str).arg(QString::number(altitude))); + QString relativeCoord_str = " Distance:" + QString::number(relativeCoord.distance) + " Bearing:" + QString::number(relativeCoord.bearing*180/M_PI); + QString relativeAltitude_str=QString::number(relativeCoord.altitudeRelative); + if(Number()!=-1) + setToolTip(QString("WayPoint Number:%1\nDescription:%2\nCoordinate:%4\nFrom Home:%5\nRelative altitude:%6\nAltitude:%7\nType:%8\n%9").arg(QString::number(numberAdjusted())).arg(description).arg(coord_str).arg(relativeCoord_str).arg(relativeAltitude_str).arg(QString::number(altitude)).arg(type_str).arg(myCustomString)); + else + setToolTip(QString("Magic WayPoint\nCoordinate:%1\nFrom Home:%2\nAltitude:%3\nType:%4\n%5").arg(coord_str).arg(relativeCoord_str).arg(QString::number(altitude)).arg(type_str).arg(myCustomString)); + } + + void WayPointItem::setFlag(QGraphicsItem::GraphicsItemFlag flag, bool enabled) + { + if(isMagic) + { + QGraphicsItem::setFlag(flag,enabled); + return; + } + else if(flag==QGraphicsItem::ItemIsMovable) + { + if(enabled) + picture.load(QString::fromUtf8(":/markers/images/marker.png")); + else + picture.load(QString::fromUtf8(":/markers/images/waypoint_marker2.png")); + } + QGraphicsItem::setFlag(flag,enabled); } int WayPointItem::snumber=0; diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/waypointitem.h b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/waypointitem.h index b8fbd70cb..f4351b71d 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/waypointitem.h +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/waypointitem.h @@ -2,7 +2,7 @@ ****************************************************************************** * * @file waypointitem.h -* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @brief A graphicsItem representing a WayPoint * @see The GNU Public License (GPL) Version 3 * @defgroup OPMapWidget @@ -33,8 +33,19 @@ #include "../internals/pointlatlng.h" #include "mapgraphicitem.h" #include +#include + namespace mapcontrol { +struct distBearingAltitude +{ + double distance; + double bearing; + float altitudeRelative; + double bearingToDegrees(){return bearing*180/M_PI;} + void setBearingFromDegrees(double degrees){bearing=degrees*M_PI/180;} +}; +class HomeItem; /** * @brief A QGraphicsItem representing a WayPoint * @@ -46,15 +57,17 @@ class WayPointItem:public QObject,public QGraphicsItem Q_INTERFACES(QGraphicsItem) public: enum { Type = UserType + 1 }; + enum wptype {absolute,relative}; /** * @brief Constructer * * @param coord coordinates in LatLng of the Waypoint * @param altitude altitude of the WayPoint * @param map pointer to map to use - * @return + * @return */ - WayPointItem(internals::PointLatLng const& coord,int const& altitude,MapGraphicItem* map); + WayPointItem(internals::PointLatLng const& coord,int const& altitude,MapGraphicItem* map,wptype type=absolute); + WayPointItem(MapGraphicItem* map,bool magicwaypoint); /** * @brief Constructer * @@ -64,7 +77,9 @@ public: * @param map pointer to map to use * @return */ - WayPointItem(internals::PointLatLng const& coord,int const& altitude,QString const& description,MapGraphicItem* map); + WayPointItem(internals::PointLatLng const& coord,int const& altitude,QString const& description,MapGraphicItem* map,wptype type=absolute); + WayPointItem(distBearingAltitude const& relativeCoord,QString const& description,MapGraphicItem* map); + /** * @brief Returns the WayPoint description * @@ -94,6 +109,7 @@ public: * */ int Number(){return number;} + int numberAdjusted(){return number+1;} /** * @brief Sets WayPoint number * @@ -127,45 +143,54 @@ public: * * @return int */ - int Altitude(){return altitude;} + float Altitude(){return altitude;} /** * @brief Sets the WayPoint Altitude * * @param value */ - void SetAltitude(int const& value); + void SetAltitude(const float &value); + void setRelativeCoord(distBearingAltitude value); + distBearingAltitude getRelativeCoord(){return relativeCoord;} int type() const; QRectF boundingRect() const; void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); - void RefreshPos(); void RefreshToolTip(); QPixmap picture; + QString customString(){return myCustomString;} + void setCustomString(QString arg){myCustomString=arg;} + void setFlag(GraphicsItemFlag flag, bool enabled); ~WayPointItem(); static int snumber; + void setWPType(wptype type); + wptype WPType(){return myType;} protected: void mouseMoveEvent ( QGraphicsSceneMouseEvent * event ); void mousePressEvent ( QGraphicsSceneMouseEvent * event ); void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ); - - + void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event); private: internals::PointLatLng coord;//coordinates of this WayPoint + distBearingAltitude relativeCoord; bool reached; QString description; bool shownumber; bool isDragging; - int altitude; + float altitude; MapGraphicItem* map; int number; - + bool isMagic; QGraphicsSimpleTextItem* text; QGraphicsRectItem* textBG; QGraphicsSimpleTextItem* numberI; QGraphicsRectItem* numberIBG; QTransform transf; + HomeItem * myHome; + wptype myType; + QString myCustomString; public slots: /** @@ -173,7 +198,7 @@ public slots: * * @param number number of the WayPoint that was deleted */ - void WPDeleted(int const& number); + void WPDeleted(int const& number,WayPointItem *waypoint); /** * @brief Called when a WayPoint is renumbered * @@ -189,6 +214,10 @@ public slots: * @param waypoint a pointer to the WayPoint inserted */ void WPInserted(int const& number,WayPointItem* waypoint); + + void onHomePositionChanged(internals::PointLatLng,float altitude); + void RefreshPos(); + void setOpacitySlot(qreal opacity); signals: /** * @brief fires when this WayPoint number changes (not fired if due to a auto-renumbering) @@ -204,7 +233,6 @@ signals: * * @param waypoint a pointer to this WayPoint */ - void WPValuesChanged(WayPointItem* waypoint); /** * @brief Fired when the waypoint is dropped somewhere @@ -213,6 +241,11 @@ signals: */ void WPDropped(WayPointItem* waypoint); + void WPValuesChanged(WayPointItem* waypoint); + void waypointdoubleclick(WayPointItem* waypoint); + void localPositionChanged(QPointF point,WayPointItem* waypoint); + void manualCoordChange(WayPointItem *); + void aboutToBeDeleted(WayPointItem *); }; } #endif // WAYPOINTITEM_H diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/waypointline.cpp b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/waypointline.cpp new file mode 100644 index 000000000..527ca46f9 --- /dev/null +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/waypointline.cpp @@ -0,0 +1,122 @@ +/** +****************************************************************************** +* +* @file waypointline.cpp +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. +* @brief A graphicsItem representing a line connecting 2 waypoints +* @see The GNU Public License (GPL) Version 3 +* @defgroup OPMapWidget +* @{ +* +*****************************************************************************/ +/* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +* for more details. +* +* You should have received a copy of the GNU General Public License along +* with this program; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ +#include "waypointline.h" +#include +#include "homeitem.h" + +namespace mapcontrol +{ +WayPointLine::WayPointLine(WayPointItem *from, WayPointItem *to, MapGraphicItem *map,QColor color):source(from), + destination(to),my_map(map),QGraphicsLineItem(map),myColor(color) +{ + this->setLine(to->pos().x(),to->pos().y(),from->pos().x(),from->pos().y()); + connect(from,SIGNAL(localPositionChanged(QPointF,WayPointItem*)),this,SLOT(refreshLocations())); + connect(to,SIGNAL(localPositionChanged(QPointF,WayPointItem*)),this,SLOT(refreshLocations())); + connect(from,SIGNAL(aboutToBeDeleted(WayPointItem*)),this,SLOT(waypointdeleted())); + connect(to,SIGNAL(aboutToBeDeleted(WayPointItem*)),this,SLOT(waypointdeleted())); + if(myColor==Qt::green) + this->setZValue(10); + else if(myColor==Qt::yellow) + this->setZValue(9); + else if(myColor==Qt::red) + this->setZValue(8); + connect(map,SIGNAL(childSetOpacity(qreal)),this,SLOT(setOpacitySlot(qreal))); +} + +WayPointLine::WayPointLine(HomeItem *from, WayPointItem *to, MapGraphicItem *map, QColor color):source(from), + destination(to),my_map(map),QGraphicsLineItem(map),myColor(color) +{ + this->setLine(to->pos().x(),to->pos().y(),from->pos().x(),from->pos().y()); + connect(from,SIGNAL(homePositionChanged(internals::PointLatLng,float)),this,SLOT(refreshLocations())); + connect(to,SIGNAL(localPositionChanged(QPointF,WayPointItem*)),this,SLOT(refreshLocations())); + connect(to,SIGNAL(aboutToBeDeleted(WayPointItem*)),this,SLOT(waypointdeleted())); + if(myColor==Qt::green) + this->setZValue(10); + else if(myColor==Qt::yellow) + this->setZValue(9); + else if(myColor==Qt::red) + this->setZValue(8); + connect(map,SIGNAL(childSetOpacity(qreal)),this,SLOT(setOpacitySlot(qreal))); +} +int WayPointLine::type() const +{ + // Enable the use of qgraphicsitem_cast with this item. + return Type; +} +QPainterPath WayPointLine::shape() const +{ + QPainterPath path = QGraphicsLineItem::shape(); + path.addPolygon(arrowHead); + return path; +} +void WayPointLine::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) +{ + + QPen myPen = pen(); + myPen.setColor(myColor); + qreal arrowSize = 10; + painter->setPen(myPen); + painter->setBrush(myColor); + + double angle = ::acos(line().dx() / line().length()); + if (line().dy() >= 0) + angle = (M_PI * 2) - angle; + + QPointF arrowP1 = line().pointAt(0.5) + QPointF(sin(angle + M_PI / 3) * arrowSize, + cos(angle + M_PI / 3) * arrowSize); + QPointF arrowP2 = line().pointAt(0.5) + QPointF(sin(angle + M_PI - M_PI / 3) * arrowSize, + cos(angle + M_PI - M_PI / 3) * arrowSize); + arrowHead.clear(); + arrowHead << line().pointAt(0.5) << arrowP1 << arrowP2; + painter->drawPolygon(arrowHead); + if(myColor==Qt::red) + myPen.setWidth(3); + else if(myColor==Qt::yellow) + myPen.setWidth(2); + else if(myColor==Qt::green) + myPen.setWidth(1); + painter->setPen(myPen); + painter->drawLine(line()); + +} + +void WayPointLine::refreshLocations() +{ + this->setLine(destination->pos().x(),destination->pos().y(),source->pos().x(),source->pos().y()); +} + +void WayPointLine::waypointdeleted() +{ + this->deleteLater(); +} + +void WayPointLine::setOpacitySlot(qreal opacity) +{ + setOpacity(opacity); +} + +} diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/waypointline.h b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/waypointline.h new file mode 100644 index 000000000..6b6bc4133 --- /dev/null +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/waypointline.h @@ -0,0 +1,66 @@ +/** +****************************************************************************** +* +* @file waypointline.h +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. +* @brief A graphicsItem representing a line connecting 2 waypoints +* @see The GNU Public License (GPL) Version 3 +* @defgroup OPMapWidget +* @{ +* +*****************************************************************************/ +/* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +* for more details. +* +* You should have received a copy of the GNU General Public License along +* with this program; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ +#ifndef WAYPOINTLINE_H +#define WAYPOINTLINE_H +#include +#include +#include +#include "../internals/pointlatlng.h" +#include "mapgraphicitem.h" +#include "waypointitem.h" +#include +#include + +namespace mapcontrol +{ +class WayPointLine:public QObject,public QGraphicsLineItem +{ + Q_OBJECT + Q_INTERFACES(QGraphicsItem) +public: + enum { Type = UserType + 8 }; + WayPointLine(WayPointItem * from, WayPointItem * to,MapGraphicItem * map,QColor color=Qt::green); + WayPointLine(HomeItem * from, WayPointItem * to,MapGraphicItem * map,QColor color=Qt::green); + int type() const; + QPainterPath shape() const; + void setColor(const QColor &color) + { myColor = color; } +private: + QGraphicsItem * source; + QGraphicsItem * destination; + MapGraphicItem * my_map; + QPolygonF arrowHead; + QColor myColor; +protected: + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); +public slots: + void refreshLocations(); + void waypointdeleted(); + void setOpacitySlot(qreal opacity); +}; +} +#endif // WAYPOINTLINE_H diff --git a/ground/openpilotgcs/src/libs/utils/coordinateconversions.cpp b/ground/openpilotgcs/src/libs/utils/coordinateconversions.cpp index 62579bddc..e0922f665 100644 --- a/ground/openpilotgcs/src/libs/utils/coordinateconversions.cpp +++ b/ground/openpilotgcs/src/libs/utils/coordinateconversions.cpp @@ -121,10 +121,10 @@ int CoordinateConversions::ECEF2LLA(double ECEF[3], double LLA[3]) } /** - * Get the current location in Longitude, Latitude Altitude (above WSG-48 ellipsoid) - * @param[in] BaseECEF the ECEF of the home location (in cm) + * Get the current location in Longitude, Latitude Altitude (above WSG-84 ellipsoid) + * @param[in] BaseECEF the ECEF of the home location (in m) * @param[in] NED the offset from the home location (in m) - * @param[out] position three element double for position in degrees and meters + * @param[out] position three element double for position in decimal degrees and altitude in meters * @returns * @arg 0 success * @arg -1 for failure diff --git a/ground/openpilotgcs/src/plugins/config/camerastabilization.ui b/ground/openpilotgcs/src/plugins/config/camerastabilization.ui index e535faa50..a394820e7 100644 --- a/ground/openpilotgcs/src/plugins/config/camerastabilization.ui +++ b/ground/openpilotgcs/src/plugins/config/camerastabilization.ui @@ -27,8 +27,8 @@ 0 0 - 696 - 635 + 702 + 660 @@ -107,6 +107,16 @@ have to define channel output range using Output configuration tab. 20 + + + objname:CameraStabSettings + fieldname:OutputRange + element:Yaw + haslimits:no + scale:1 + buttongroup:1 + + @@ -126,6 +136,16 @@ have to define channel output range using Output configuration tab. 20 + + + objname:CameraStabSettings + fieldname:OutputRange + element:Pitch + haslimits:no + scale:1 + buttongroup:1 + + @@ -145,6 +165,16 @@ have to define channel output range using Output configuration tab. 20 + + + objname:CameraStabSettings + fieldname:OutputRange + element:Roll + haslimits:no + scale:1 + buttongroup:1 + + @@ -339,6 +369,14 @@ margin:1px; Don't forget to map this channel using Input configuration tab. + + + objname:CameraStabSettings + fieldname:Input + element:Yaw + buttongroup:1 + + None @@ -356,6 +394,14 @@ Don't forget to map this channel using Input configuration tab. Don't forget to map this channel using Input configuration tab. + + + objname:CameraStabSettings + fieldname:Input + element:Pitch + buttongroup:1 + + None @@ -373,6 +419,14 @@ Don't forget to map this channel using Input configuration tab. Don't forget to map this channel using Input configuration tab. + + + objname:CameraStabSettings + fieldname:Input + element:Roll + buttongroup:1 + + None @@ -398,6 +452,14 @@ Don't forget to map this channel using Input configuration tab. Attitude: camera tracks level for the axis. Input controls the deflection. AxisLock: camera remembers tracking attitude. Input controls the rate of deflection. + + + objname:CameraStabSettings + fieldname:StabilizationMode + element:Yaw + buttongroup:1 + + Attitude @@ -419,6 +481,16 @@ AxisLock: camera remembers tracking attitude. Input controls the rate of deflect 20 + + + objname:CameraStabSettings + fieldname:InputRange + element:Yaw + haslimits:no + scale:1 + buttongroup:1 + + @@ -435,6 +507,16 @@ AxisLock: camera remembers tracking attitude. Input controls the rate of deflect 50 + + + objname:CameraStabSettings + fieldname:InputRate + element:Yaw + haslimits:no + scale:1 + buttongroup:1 + + @@ -453,6 +535,16 @@ This option smoothes the stick input. Zero value disables LPF. 150 + + + objname:CameraStabSettings + fieldname:ResponseTime + element:Yaw + haslimits:no + scale:1 + buttongroup:1 + + @@ -466,6 +558,14 @@ This option smoothes the stick input. Zero value disables LPF. Attitude: camera tracks level for the axis. Input controls the deflection. AxisLock: camera remembers tracking attitude. Input controls the rate of deflection. + + + objname:CameraStabSettings + fieldname:StabilizationMode + element:Pitch + buttongroup:1 + + Attitude @@ -487,6 +587,16 @@ AxisLock: camera remembers tracking attitude. Input controls the rate of deflect 20 + + + objname:CameraStabSettings + fieldname:InputRange + element:Pitch + haslimits:no + scale:1 + buttongroup:1 + + @@ -503,6 +613,16 @@ AxisLock: camera remembers tracking attitude. Input controls the rate of deflect 50 + + + objname:CameraStabSettings + fieldname:InputRate + element:Pitch + haslimits:no + scale:1 + buttongroup:1 + + @@ -521,6 +641,16 @@ This option smoothes the stick input. Zero value disables LPF. 150 + + + objname:CameraStabSettings + fieldname:ResponseTime + element:Pitch + haslimits:no + scale:1 + buttongroup:1 + + @@ -534,6 +664,14 @@ This option smoothes the stick input. Zero value disables LPF. Attitude: camera tracks level for the axis. Input controls the deflection. AxisLock: camera remembers tracking attitude. Input controls the rate of deflection. + + + objname:CameraStabSettings + fieldname:StabilizationMode + element:Roll + buttongroup:1 + + Attitude @@ -555,6 +693,16 @@ AxisLock: camera remembers tracking attitude. Input controls the rate of deflect 20 + + + objname:CameraStabSettings + fieldname:InputRange + element:Roll + haslimits:no + scale:1 + buttongroup:1 + + @@ -571,6 +719,16 @@ AxisLock: camera remembers tracking attitude. Input controls the rate of deflect 50 + + + objname:CameraStabSettings + fieldname:InputRate + element:Roll + haslimits:no + scale:1 + buttongroup:1 + + @@ -589,6 +747,16 @@ This option smoothes the stick input. Zero value disables LPF. 150 + + + objname:CameraStabSettings + fieldname:ResponseTime + element:Roll + haslimits:no + scale:1 + buttongroup:1 + + @@ -657,6 +825,15 @@ value. 1.000000000000000 + + + objname:CameraStabSettings + fieldname:MaxAxisLockRate + haslimits:no + scale:1 + buttongroup:1 + + @@ -754,12 +931,18 @@ value. true + + + button:help + url:http://wiki.openpilot.org/display/Doc/Camera+Stabilization+Configuration + + - Load default CameraStabilization settings except output channels + Load default CameraStabilization settings except output channels into GCS. Loaded settings are not applied automatically. You have to click the Apply or Save button afterwards. @@ -767,6 +950,33 @@ Apply or Save button afterwards. Reset To Defaults + + + button:default + buttongroup:1 + + + + + + + + Reloads saved CameraStabilization settings except output channels +from board into GCS. Useful if you have accidentally changed some +settings. + +Loaded settings are not applied automatically. You have to click the +Apply or Save button afterwards. + + + Reload Board Data + + + + button:reload + buttongroup:1 + + @@ -777,6 +987,11 @@ Apply or Save button afterwards. Apply + + + button:apply + + @@ -790,6 +1005,11 @@ Apply or Save button afterwards. false + + + button:save + + @@ -823,7 +1043,6 @@ Apply or Save button afterwards. yawResponseTime MaxAxisLockRate camerastabilizationHelp - camerastabilizationResetToDefaults camerastabilizationSaveRAM camerastabilizationSaveSD scrollArea diff --git a/ground/openpilotgcs/src/plugins/config/configcamerastabilizationwidget.cpp b/ground/openpilotgcs/src/plugins/config/configcamerastabilizationwidget.cpp index 3e757de63..ae5712f5e 100644 --- a/ground/openpilotgcs/src/plugins/config/configcamerastabilizationwidget.cpp +++ b/ground/openpilotgcs/src/plugins/config/configcamerastabilizationwidget.cpp @@ -2,7 +2,7 @@ ****************************************************************************** * * @file configcamerastabilizationwidget.cpp - * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2011. + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2011-2012. * @addtogroup GCSPlugins GCS Plugins * @{ * @addtogroup ConfigPlugin Config Plugin @@ -24,71 +24,65 @@ * with this program; if not, write to the Free Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + +/* + * IMPORTANT: This module is meant to be a reference implementation which + * demostrates the use of ConfigTaskWidget API for widgets which are not directly + * related to UAVObjects. It contains a lot of comments including some commented + * out code samples. Please DO NOT COPY/PASTE them into any other module based + * on this. + */ + #include "configcamerastabilizationwidget.h" #include "camerastabsettings.h" #include "hwsettings.h" #include "mixersettings.h" #include "actuatorcommand.h" -#include -#include -#include - ConfigCameraStabilizationWidget::ConfigCameraStabilizationWidget(QWidget *parent) : ConfigTaskWidget(parent) { - // TODO: this widget should use the addUAVObjectToWidgetRelation() m_camerastabilization = new Ui_CameraStabilizationWidget(); m_camerastabilization->setupUi(this); - QComboBox *outputs[3] = { + // These widgets don't have direct relation to UAVObjects + // and need special processing + QComboBox *outputs[] = { m_camerastabilization->rollChannel, m_camerastabilization->pitchChannel, m_camerastabilization->yawChannel, }; + const int NUM_OUTPUTS = sizeof(outputs) / sizeof(outputs[0]); - QComboBox *inputs[3] = { - m_camerastabilization->rollInputChannel, - m_camerastabilization->pitchInputChannel, - m_camerastabilization->yawInputChannel, - }; - - QComboBox *stabilizationMode[3] = { - m_camerastabilization->rollStabilizationMode, - m_camerastabilization->pitchStabilizationMode, - m_camerastabilization->yawStabilizationMode, - }; - - CameraStabSettings *cameraStab = CameraStabSettings::GetInstance(getObjectManager()); - CameraStabSettings::DataFields cameraStabData = cameraStab->getData(); - - for (int i = 0; i < 3; i++) { + // Populate widgets with channel numbers + for (int i = 0; i < NUM_OUTPUTS; i++) { outputs[i]->clear(); outputs[i]->addItem("None"); for (quint32 j = 0; j < ActuatorCommand::CHANNEL_NUMELEM; j++) outputs[i]->addItem(QString("Channel %1").arg(j+1)); - - UAVObjectField *field; - - field = cameraStab->getField("Input"); - Q_ASSERT(field); - inputs[i]->clear(); - inputs[i]->addItems(field->getOptions()); - inputs[i]->setCurrentIndex(cameraStabData.Input[i]); - - field = cameraStab->getField("StabilizationMode"); - Q_ASSERT(field); - stabilizationMode[i]->clear(); - stabilizationMode[i]->addItems(field->getOptions()); - stabilizationMode[i]->setCurrentIndex(cameraStabData.StabilizationMode[i]); } - connectUpdates(); + // Load UAVObjects to widget relations from UI file + // using objrelation dynamic property + autoLoadWidgets(); - // Connect buttons - connect(m_camerastabilization->camerastabilizationResetToDefaults, SIGNAL(clicked()), this, SLOT(resetToDefaults())); - connect(m_camerastabilization->camerastabilizationSaveRAM, SIGNAL(clicked()), this, SLOT(applySettings())); - connect(m_camerastabilization->camerastabilizationSaveSD, SIGNAL(clicked()), this, SLOT(saveSettings())); - connect(m_camerastabilization->camerastabilizationHelp, SIGNAL(clicked()), this, SLOT(openHelp())); + // Add some widgets to track their UI dirty state and handle smartsave + addWidget(m_camerastabilization->enableCameraStabilization); + addWidget(m_camerastabilization->rollChannel); + addWidget(m_camerastabilization->pitchChannel); + addWidget(m_camerastabilization->yawChannel); + + // Add some UAVObjects to monitor their changes in addition to autoloaded ones. + // Note also that we want to reload some UAVObjects by "Reload" button and have + // to pass corresponding reload group numbers (defined also in objrelation property) + // to the montitor. We don't reload HwSettings (module enable state) but reload + // output channels. + QList reloadGroups; + reloadGroups << 1; + addUAVObject("HwSettings"); + addUAVObject("MixerSettings", &reloadGroups); + + // To set special widgets to defaults when requested + connect(this, SIGNAL(defaultRequested(int)), this, SLOT(defaultRequestedSlot(int))); disableMouseWheelEvents(); } @@ -98,52 +92,32 @@ ConfigCameraStabilizationWidget::~ConfigCameraStabilizationWidget() // Do nothing } -void ConfigCameraStabilizationWidget::connectUpdates() +/* + * This overridden function refreshes widgets which have no direct relation + * to any of UAVObjects. It saves their dirty state first because update comes + * from UAVObjects, and then restores it. Aftewards it calls base class + * function to take care of other widgets which were dynamically added. + */ +void ConfigCameraStabilizationWidget::refreshWidgetsValues(UAVObject *obj) { - // Now connect the widget to the StabilizationSettings object - connect(MixerSettings::GetInstance(getObjectManager()), SIGNAL(objectUpdated(UAVObject *)), this, SLOT(refreshValues())); - connect(CameraStabSettings::GetInstance(getObjectManager()), SIGNAL(objectUpdated(UAVObject *)), this, SLOT(refreshValues())); - // TODO: This will need to support both CC and OP later - connect(HwSettings::GetInstance(getObjectManager()), SIGNAL(objectUpdated(UAVObject *)), this, SLOT(refreshValues())); -} + bool dirty = isDirty(); -void ConfigCameraStabilizationWidget::disconnectUpdates() -{ - // Now connect the widget to the StabilizationSettings object - disconnect(MixerSettings::GetInstance(getObjectManager()), SIGNAL(objectUpdated(UAVObject *)), this, SLOT(refreshValues())); - disconnect(CameraStabSettings::GetInstance(getObjectManager()), SIGNAL(objectUpdated(UAVObject *)), this, SLOT(refreshValues())); - // TODO: This will need to support both CC and OP later - disconnect(HwSettings::GetInstance(getObjectManager()), SIGNAL(objectUpdated(UAVObject *)), this, SLOT(refreshValues())); -} - -/** - * @brief Populate the gui settings into the appropriate - * UAV structures - */ -void ConfigCameraStabilizationWidget::applySettings() -{ - // Enable or disable the settings + // Set module enable checkbox from OptionalModules UAVObject item. + // It needs special processing because ConfigTaskWidget uses TRUE/FALSE + // for QCheckBox, but OptionalModules uses Enabled/Disabled enum values. HwSettings *hwSettings = HwSettings::GetInstance(getObjectManager()); HwSettings::DataFields hwSettingsData = hwSettings->getData(); - hwSettingsData.OptionalModules[HwSettings::OPTIONALMODULES_CAMERASTAB] = - m_camerastabilization->enableCameraStabilization->isChecked() ? - HwSettings::OPTIONALMODULES_ENABLED : - HwSettings::OPTIONALMODULES_DISABLED; - // Update the mixer settings + m_camerastabilization->enableCameraStabilization->setChecked( + hwSettingsData.OptionalModules[HwSettings::OPTIONALMODULES_CAMERASTAB] == HwSettings::OPTIONALMODULES_ENABLED); + + // Load mixer outputs which are mapped to camera controls MixerSettings *mixerSettings = MixerSettings::GetInstance(getObjectManager()); MixerSettings::DataFields mixerSettingsData = mixerSettings->getData(); - const int NUM_MIXERS = 10; - - QComboBox *outputs[3] = { - m_camerastabilization->rollChannel, - m_camerastabilization->pitchChannel, - m_camerastabilization->yawChannel, - }; // TODO: Need to reformat object so types are an // array themselves. This gets really awkward - quint8 * mixerTypes[NUM_MIXERS] = { + quint8 *mixerTypes[] = { &mixerSettingsData.Mixer1Type, &mixerSettingsData.Mixer2Type, &mixerSettingsData.Mixer3Type, @@ -155,187 +129,144 @@ void ConfigCameraStabilizationWidget::applySettings() &mixerSettingsData.Mixer9Type, &mixerSettingsData.Mixer10Type, }; + const int NUM_MIXERS = sizeof(mixerTypes) / sizeof(mixerTypes[0]); - m_camerastabilization->message->setText(""); - for (int i = 0; i < 3; i++) - { - // Channel 1 is second entry, so becomes zero - int mixerNum = outputs[i]->currentIndex() - 1; - - if ( mixerNum >= 0 && // Short circuit in case of none - *mixerTypes[mixerNum] != MixerSettings::MIXER1TYPE_DISABLED && - (*mixerTypes[mixerNum] != MixerSettings::MIXER1TYPE_CAMERAROLL + i) ) { - // If the mixer channel already to something that isn't what we are - // about to set it to reset to none - outputs[i]->setCurrentIndex(0); - m_camerastabilization->message->setText("One of the channels is already assigned, reverted to none"); - } else { - // Make sure no other channels have this output set - for (int j = 0; j < NUM_MIXERS; j++) - if (*mixerTypes[j] == (MixerSettings::MIXER1TYPE_CAMERAROLL + i)) - *mixerTypes[j] = MixerSettings::MIXER1TYPE_DISABLED; - - // If this channel is assigned to one of the outputs that is not disabled - // set it - if(mixerNum >= 0 && mixerNum < NUM_MIXERS) - *mixerTypes[mixerNum] = MixerSettings::MIXER1TYPE_CAMERAROLL + i; - } - } - - // Update the settings - CameraStabSettings *cameraStab = CameraStabSettings::GetInstance(getObjectManager()); - CameraStabSettings::DataFields cameraStabData = cameraStab->getData(); - - cameraStabData.OutputRange[CameraStabSettings::OUTPUTRANGE_ROLL] = m_camerastabilization->rollOutputRange->value(); - cameraStabData.OutputRange[CameraStabSettings::OUTPUTRANGE_PITCH] = m_camerastabilization->pitchOutputRange->value(); - cameraStabData.OutputRange[CameraStabSettings::OUTPUTRANGE_YAW] = m_camerastabilization->yawOutputRange->value(); - - cameraStabData.Input[CameraStabSettings::INPUT_ROLL] = m_camerastabilization->rollInputChannel->currentIndex(); - cameraStabData.Input[CameraStabSettings::INPUT_PITCH] = m_camerastabilization->pitchInputChannel->currentIndex(); - cameraStabData.Input[CameraStabSettings::INPUT_YAW] = m_camerastabilization->yawInputChannel->currentIndex(); - - cameraStabData.StabilizationMode[CameraStabSettings::STABILIZATIONMODE_ROLL] = m_camerastabilization->rollStabilizationMode->currentIndex(); - cameraStabData.StabilizationMode[CameraStabSettings::STABILIZATIONMODE_PITCH] = m_camerastabilization->pitchStabilizationMode->currentIndex(); - cameraStabData.StabilizationMode[CameraStabSettings::STABILIZATIONMODE_YAW] = m_camerastabilization->yawStabilizationMode->currentIndex(); - - cameraStabData.InputRange[CameraStabSettings::INPUTRANGE_ROLL] = m_camerastabilization->rollInputRange->value(); - cameraStabData.InputRange[CameraStabSettings::INPUTRANGE_PITCH] = m_camerastabilization->pitchInputRange->value(); - cameraStabData.InputRange[CameraStabSettings::INPUTRANGE_YAW] = m_camerastabilization->yawInputRange->value(); - - cameraStabData.InputRate[CameraStabSettings::INPUTRATE_ROLL] = m_camerastabilization->rollInputRate->value(); - cameraStabData.InputRate[CameraStabSettings::INPUTRATE_PITCH] = m_camerastabilization->pitchInputRate->value(); - cameraStabData.InputRate[CameraStabSettings::INPUTRATE_YAW] = m_camerastabilization->yawInputRate->value(); - - cameraStabData.ResponseTime[CameraStabSettings::RESPONSETIME_ROLL] = m_camerastabilization->rollResponseTime->value(); - cameraStabData.ResponseTime[CameraStabSettings::RESPONSETIME_PITCH] = m_camerastabilization->pitchResponseTime->value(); - cameraStabData.ResponseTime[CameraStabSettings::RESPONSETIME_YAW] = m_camerastabilization->yawResponseTime->value(); - - cameraStabData.MaxAxisLockRate = m_camerastabilization->MaxAxisLockRate->value(); - - // Because multiple objects are updated, and all of them trigger the callback - // they must be done together (if update one then load settings from second - // the first update would wipe the UI controls). However to be extra cautious - // I'm also disabling updates during the setting to the UAVObjects - disconnectUpdates(); - hwSettings->setData(hwSettingsData); - mixerSettings->setData(mixerSettingsData); - cameraStab->setData(cameraStabData); - connectUpdates(); -} - -/** - * Push settings into UAV objects then save them - */ -void ConfigCameraStabilizationWidget::saveSettings() -{ - applySettings(); - UAVObject *obj = HwSettings::GetInstance(getObjectManager()); - saveObjectToSD(obj); - obj = MixerSettings::GetInstance(getObjectManager()); - saveObjectToSD(obj); - obj = CameraStabSettings::GetInstance(getObjectManager()); - saveObjectToSD(obj); -} - -/** - * Refresh UI with new settings of CameraStabSettings object - * (either from active configuration or just loaded defaults - * to be applied or saved) - */ -void ConfigCameraStabilizationWidget::refreshUIValues(CameraStabSettings::DataFields &cameraStabData) -{ - m_camerastabilization->rollOutputRange->setValue(cameraStabData.OutputRange[CameraStabSettings::OUTPUTRANGE_ROLL]); - m_camerastabilization->pitchOutputRange->setValue(cameraStabData.OutputRange[CameraStabSettings::OUTPUTRANGE_PITCH]); - m_camerastabilization->yawOutputRange->setValue(cameraStabData.OutputRange[CameraStabSettings::OUTPUTRANGE_YAW]); - - m_camerastabilization->rollInputChannel->setCurrentIndex(cameraStabData.Input[CameraStabSettings::INPUT_ROLL]); - m_camerastabilization->pitchInputChannel->setCurrentIndex(cameraStabData.Input[CameraStabSettings::INPUT_PITCH]); - m_camerastabilization->yawInputChannel->setCurrentIndex(cameraStabData.Input[CameraStabSettings::INPUT_YAW]); - - m_camerastabilization->rollStabilizationMode->setCurrentIndex(cameraStabData.StabilizationMode[CameraStabSettings::STABILIZATIONMODE_ROLL]); - m_camerastabilization->pitchStabilizationMode->setCurrentIndex(cameraStabData.StabilizationMode[CameraStabSettings::STABILIZATIONMODE_PITCH]); - m_camerastabilization->yawStabilizationMode->setCurrentIndex(cameraStabData.StabilizationMode[CameraStabSettings::STABILIZATIONMODE_YAW]); - - m_camerastabilization->rollInputRange->setValue(cameraStabData.InputRange[CameraStabSettings::INPUTRANGE_ROLL]); - m_camerastabilization->pitchInputRange->setValue(cameraStabData.InputRange[CameraStabSettings::INPUTRANGE_PITCH]); - m_camerastabilization->yawInputRange->setValue(cameraStabData.InputRange[CameraStabSettings::INPUTRANGE_YAW]); - - m_camerastabilization->rollInputRate->setValue(cameraStabData.InputRate[CameraStabSettings::INPUTRATE_ROLL]); - m_camerastabilization->pitchInputRate->setValue(cameraStabData.InputRate[CameraStabSettings::INPUTRATE_PITCH]); - m_camerastabilization->yawInputRate->setValue(cameraStabData.InputRate[CameraStabSettings::INPUTRATE_YAW]); - - m_camerastabilization->rollResponseTime->setValue(cameraStabData.ResponseTime[CameraStabSettings::RESPONSETIME_ROLL]); - m_camerastabilization->pitchResponseTime->setValue(cameraStabData.ResponseTime[CameraStabSettings::RESPONSETIME_PITCH]); - m_camerastabilization->yawResponseTime->setValue(cameraStabData.ResponseTime[CameraStabSettings::RESPONSETIME_YAW]); - - m_camerastabilization->MaxAxisLockRate->setValue(cameraStabData.MaxAxisLockRate); -} - -void ConfigCameraStabilizationWidget::refreshValues() -{ - HwSettings *hwSettings = HwSettings::GetInstance(getObjectManager()); - HwSettings::DataFields hwSettingsData = hwSettings->getData(); - m_camerastabilization->enableCameraStabilization->setChecked( - hwSettingsData.OptionalModules[HwSettings::OPTIONALMODULES_CAMERASTAB] == - HwSettings::OPTIONALMODULES_ENABLED); - - CameraStabSettings *cameraStabSettings = CameraStabSettings::GetInstance(getObjectManager()); - CameraStabSettings::DataFields cameraStabData = cameraStabSettings->getData(); - refreshUIValues(cameraStabData); - - MixerSettings *mixerSettings = MixerSettings::GetInstance(getObjectManager()); - MixerSettings::DataFields mixerSettingsData = mixerSettings->getData(); - const int NUM_MIXERS = 10; - QComboBox *outputs[3] = { + QComboBox *outputs[] = { m_camerastabilization->rollChannel, m_camerastabilization->pitchChannel, m_camerastabilization->yawChannel }; + const int NUM_OUTPUTS = sizeof(outputs) / sizeof(outputs[0]); - // TODO: Need to reformat object so types are an - // array themselves. This gets really awkward - quint8 * mixerTypes[NUM_MIXERS] = { - &mixerSettingsData.Mixer1Type, - &mixerSettingsData.Mixer2Type, - &mixerSettingsData.Mixer3Type, - &mixerSettingsData.Mixer4Type, - &mixerSettingsData.Mixer5Type, - &mixerSettingsData.Mixer6Type, - &mixerSettingsData.Mixer7Type, - &mixerSettingsData.Mixer8Type, - &mixerSettingsData.Mixer9Type, - &mixerSettingsData.Mixer10Type, - }; - - for (int i = 0; i < 3; i++) - { - // Default to none if not found. Then search for any mixer channels set to - // this + for (int i = 0; i < NUM_OUTPUTS; i++) { + // Default to none if not found. + // Then search for any mixer channels set to this outputs[i]->setCurrentIndex(0); for (int j = 0; j < NUM_MIXERS; j++) if (*mixerTypes[j] == (MixerSettings::MIXER1TYPE_CAMERAROLL + i) && outputs[i]->currentIndex() != (j + 1)) outputs[i]->setCurrentIndex(j + 1); } + + setDirty(dirty); + + ConfigTaskWidget::refreshWidgetsValues(obj); } -void ConfigCameraStabilizationWidget::resetToDefaults() +/* + * This overridden function updates UAVObjects which have no direct relation + * to any of widgets. Aftewards it calls base class function to take care of + * other object to widget relations which were dynamically added. + */ +void ConfigCameraStabilizationWidget::updateObjectsFromWidgets() { - CameraStabSettings cameraStabDefaults; - CameraStabSettings::DataFields defaults = cameraStabDefaults.getData(); - refreshUIValues(defaults); + // Save state of the module enable checkbox first. + // Do not use setData() member on whole object, if possible, since it triggers + // unnessesary UAVObect update. + quint8 enableModule = m_camerastabilization->enableCameraStabilization->isChecked() ? + HwSettings::OPTIONALMODULES_ENABLED : HwSettings::OPTIONALMODULES_DISABLED; + HwSettings *hwSettings = HwSettings::GetInstance(getObjectManager()); + hwSettings->setOptionalModules(HwSettings::OPTIONALMODULES_CAMERASTAB, enableModule); + + // Update mixer channels which were mapped to camera outputs in case they are + // not used for other function yet + MixerSettings *mixerSettings = MixerSettings::GetInstance(getObjectManager()); + MixerSettings::DataFields mixerSettingsData = mixerSettings->getData(); + + // TODO: Need to reformat object so types are an + // array themselves. This gets really awkward + quint8 *mixerTypes[] = { + &mixerSettingsData.Mixer1Type, + &mixerSettingsData.Mixer2Type, + &mixerSettingsData.Mixer3Type, + &mixerSettingsData.Mixer4Type, + &mixerSettingsData.Mixer5Type, + &mixerSettingsData.Mixer6Type, + &mixerSettingsData.Mixer7Type, + &mixerSettingsData.Mixer8Type, + &mixerSettingsData.Mixer9Type, + &mixerSettingsData.Mixer10Type, + }; + const int NUM_MIXERS = sizeof(mixerTypes) / sizeof(mixerTypes[0]); + + QComboBox *outputs[] = { + m_camerastabilization->rollChannel, + m_camerastabilization->pitchChannel, + m_camerastabilization->yawChannel + }; + const int NUM_OUTPUTS = sizeof(outputs) / sizeof(outputs[0]); + + m_camerastabilization->message->setText(""); + bool widgetUpdated; + do { + widgetUpdated = false; + + for (int i = 0; i < NUM_OUTPUTS; i++) { + // Channel 1 is second entry, so becomes zero + int mixerNum = outputs[i]->currentIndex() - 1; + + if ((mixerNum >= 0) && // Short circuit in case of none + (*mixerTypes[mixerNum] != MixerSettings::MIXER1TYPE_DISABLED) && + (*mixerTypes[mixerNum] != MixerSettings::MIXER1TYPE_CAMERAROLL + i) ) { + // If the mixer channel already mapped to something, it should not be + // used for camera output, we reset it to none + outputs[i]->setCurrentIndex(0); + m_camerastabilization->message->setText("One of the channels is already assigned, reverted to none"); + + // Loop again or we may have inconsistent widget and UAVObject + widgetUpdated = true; + } else { + // Make sure no other channels have this output set + for (int j = 0; j < NUM_MIXERS; j++) + if (*mixerTypes[j] == (MixerSettings::MIXER1TYPE_CAMERAROLL + i)) + *mixerTypes[j] = MixerSettings::MIXER1TYPE_DISABLED; + + // If this channel is assigned to one of the outputs that is not disabled + // set it + if ((mixerNum >= 0) && (mixerNum < NUM_MIXERS)) + *mixerTypes[mixerNum] = MixerSettings::MIXER1TYPE_CAMERAROLL + i; + } + } + } while(widgetUpdated); + + // FIXME: Should not use setData() to prevent double updates. + // It should be refactored after the reformatting of MixerSettings UAVObject. + mixerSettings->setData(mixerSettingsData); + + ConfigTaskWidget::updateObjectsFromWidgets(); } -void ConfigCameraStabilizationWidget::openHelp() +/* + * This slot function is called when "Default" button is clicked. + * All special widgets which belong to the group passed should be set here. + */ +void ConfigCameraStabilizationWidget::defaultRequestedSlot(int group) { - QDesktopServices::openUrl( QUrl("http://wiki.openpilot.org/display/Doc/Camera+Stabilization+Configuration", QUrl::StrictMode) ); -} + Q_UNUSED(group); -void ConfigCameraStabilizationWidget::enableControls(bool enable) -{ - m_camerastabilization->camerastabilizationResetToDefaults->setEnabled(enable); - m_camerastabilization->camerastabilizationSaveSD->setEnabled(enable); - m_camerastabilization->camerastabilizationSaveRAM->setEnabled(enable); + // Here is the example of how to reset the state of QCheckBox. It is + // commented out because we normally don't want to reset the module + // enable state to default "disabled" (or we don't care about values at all). + // But if you want, you could use the dirtyClone() function to get default + // values of an object and then use them to set a widget state. + // + //HwSettings *hwSettings = HwSettings::GetInstance(getObjectManager()); + //HwSettings *hwSettingsDefault=(HwSettings*)hwSettings->dirtyClone(); + //HwSettings::DataFields hwSettingsData = hwSettingsDefault->getData(); + //m_camerastabilization->enableCameraStabilization->setChecked( + // hwSettingsData.OptionalModules[HwSettings::OPTIONALMODULES_CAMERASTAB] == HwSettings::OPTIONALMODULES_ENABLED); + + // For outputs we set them all to none, so don't use any UAVObject to get defaults + QComboBox *outputs[] = { + m_camerastabilization->rollChannel, + m_camerastabilization->pitchChannel, + m_camerastabilization->yawChannel, + }; + const int NUM_OUTPUTS = sizeof(outputs) / sizeof(outputs[0]); + + for (int i = 0; i < NUM_OUTPUTS; i++) { + outputs[i]->setCurrentIndex(0); + } } /** diff --git a/ground/openpilotgcs/src/plugins/config/configcamerastabilizationwidget.h b/ground/openpilotgcs/src/plugins/config/configcamerastabilizationwidget.h index 743435adb..871193e82 100644 --- a/ground/openpilotgcs/src/plugins/config/configcamerastabilizationwidget.h +++ b/ground/openpilotgcs/src/plugins/config/configcamerastabilizationwidget.h @@ -41,21 +41,14 @@ class ConfigCameraStabilizationWidget: public ConfigTaskWidget public: ConfigCameraStabilizationWidget(QWidget *parent = 0); ~ConfigCameraStabilizationWidget(); + private: Ui_CameraStabilizationWidget *m_camerastabilization; - virtual void enableControls(bool enable); - void refreshUIValues(CameraStabSettings::DataFields &cameraStabData); + void refreshWidgetsValues(UAVObject *obj); + void updateObjectsFromWidgets(); private slots: - void openHelp(); - void resetToDefaults(); - void applySettings(); - void saveSettings(); - void refreshValues(); - -protected: - void connectUpdates(); - void disconnectUpdates(); + void defaultRequestedSlot(int group); }; #endif // CONFIGCAMERASTABILIZATIONWIDGET_H diff --git a/ground/openpilotgcs/src/plugins/config/configccattitudewidget.cpp b/ground/openpilotgcs/src/plugins/config/configccattitudewidget.cpp index 10064b835..fe1f517bf 100644 --- a/ground/openpilotgcs/src/plugins/config/configccattitudewidget.cpp +++ b/ground/openpilotgcs/src/plugins/config/configccattitudewidget.cpp @@ -63,29 +63,29 @@ ConfigCCAttitudeWidget::~ConfigCCAttitudeWidget() delete ui; } -void ConfigCCAttitudeWidget::accelsUpdated(UAVObject * obj) { +void ConfigCCAttitudeWidget::sensorsUpdated(UAVObject * obj) { QMutexLocker locker(&startStop); - ui->zeroBiasProgress->setValue((float) updates / NUM_ACCEL_UPDATES * 100); + ui->zeroBiasProgress->setValue((float) qMin(accelUpdates,gyroUpdates) / NUM_SENSOR_UPDATES * 100); - if(updates < NUM_ACCEL_UPDATES) { - updates++; - Accels * accels = Accels::GetInstance(getObjectManager()); + Accels * accels = Accels::GetInstance(getObjectManager()); + Gyros * gyros = Gyros::GetInstance(getObjectManager()); + + if(obj->getObjID() == Accels::OBJID && accelUpdates < NUM_SENSOR_UPDATES) { + accelUpdates++; Accels::DataFields accelsData = accels->getData(); x_accum.append(accelsData.x); y_accum.append(accelsData.y); z_accum.append(accelsData.z); - - Gyros * gyros = Gyros::GetInstance(getObjectManager()); + } else if (obj->getObjID() == Gyros::OBJID && gyroUpdates < NUM_SENSOR_UPDATES) { + gyroUpdates++; Gyros::DataFields gyrosData = gyros->getData(); - x_gyro_accum.append(gyrosData.x); y_gyro_accum.append(gyrosData.y); z_gyro_accum.append(gyrosData.z); - } else if ( updates == NUM_ACCEL_UPDATES ) { - updates++; + } else if ( accelUpdates >= NUM_SENSOR_UPDATES && gyroUpdates >= NUM_SENSOR_UPDATES) { timer.stop(); - disconnect(obj,SIGNAL(objectUpdated(UAVObject*)),this,SLOT(accelsUpdated(UAVObject*))); + disconnect(obj,SIGNAL(objectUpdated(UAVObject*)),this,SLOT(sensorsUpdated(UAVObject*))); disconnect(&timer,SIGNAL(timeout()),this,SLOT(timeout())); float x_bias = listMean(x_accum) / ACCEL_SCALE; @@ -95,7 +95,8 @@ void ConfigCCAttitudeWidget::accelsUpdated(UAVObject * obj) { float x_gyro_bias = listMean(x_gyro_accum) * 100.0f; float y_gyro_bias = listMean(y_gyro_accum) * 100.0f; float z_gyro_bias = listMean(z_gyro_accum) * 100.0f; - obj->setMetadata(initialMdata); + accels->setMetadata(initialAccelsMdata); + gyros->setMetadata(initialGyrosMdata); AttitudeSettings::DataFields attitudeSettingsData = AttitudeSettings::GetInstance(getObjectManager())->getData(); // We offset the gyro bias by current bias to help precision @@ -108,17 +109,22 @@ void ConfigCCAttitudeWidget::accelsUpdated(UAVObject * obj) { attitudeSettingsData.BiasCorrectGyro = AttitudeSettings::BIASCORRECTGYRO_TRUE; AttitudeSettings::GetInstance(getObjectManager())->setData(attitudeSettingsData); } else { - // Possible to get here if weird threading stuff happens. Just ignore updates. - qDebug("Unexpected accel update received."); + // Possible to get here if weird threading stuff happens. Just ignore updates. + qDebug("Unexpected accel update received."); } } void ConfigCCAttitudeWidget::timeout() { QMutexLocker locker(&startStop); UAVDataObject * obj = Accels::GetInstance(getObjectManager()); - disconnect(obj,SIGNAL(objectUpdated(UAVObject*)),this,SLOT(accelsUpdated(UAVObject*))); + disconnect(obj,SIGNAL(objectUpdated(UAVObject*)),this,SLOT(sensorsUpdated(UAVObject*))); disconnect(&timer,SIGNAL(timeout()),this,SLOT(timeout())); + Accels * accels = Accels::GetInstance(getObjectManager()); + Gyros * gyros = Gyros::GetInstance(getObjectManager()); + accels->setMetadata(initialAccelsMdata); + gyros->setMetadata(initialGyrosMdata); + QMessageBox msgBox; msgBox.setText(tr("Calibration timed out before receiving required updates.")); msgBox.setStandardButtons(QMessageBox::Ok); @@ -130,7 +136,8 @@ void ConfigCCAttitudeWidget::timeout() { void ConfigCCAttitudeWidget::startAccelCalibration() { QMutexLocker locker(&startStop); - updates = 0; + accelUpdates = 0; + gyroUpdates = 0; x_accum.clear(); y_accum.clear(); z_accum.clear(); @@ -144,19 +151,27 @@ void ConfigCCAttitudeWidget::startAccelCalibration() { AttitudeSettings::GetInstance(getObjectManager())->setData(attitudeSettingsData); // Set up to receive updates - UAVDataObject * obj = Accels::GetInstance(getObjectManager()); - connect(obj,SIGNAL(objectUpdated(UAVObject*)),this,SLOT(accelsUpdated(UAVObject*))); + UAVDataObject * accels = Accels::GetInstance(getObjectManager()); + UAVDataObject * gyros = Gyros::GetInstance(getObjectManager()); + connect(accels,SIGNAL(objectUpdated(UAVObject*)),this,SLOT(sensorsUpdated(UAVObject*))); + connect(gyros,SIGNAL(objectUpdated(UAVObject*)),this,SLOT(sensorsUpdated(UAVObject*))); // Set up timeout timer timer.start(10000); connect(&timer,SIGNAL(timeout()),this,SLOT(timeout())); // Speed up updates - initialMdata = obj->getMetadata(); - UAVObject::Metadata mdata = initialMdata; - UAVObject::SetFlightTelemetryUpdateMode(mdata, UAVObject::UPDATEMODE_PERIODIC); - mdata.flightTelemetryUpdatePeriod = 100; - obj->setMetadata(mdata); + initialAccelsMdata = accels->getMetadata(); + UAVObject::Metadata accelsMdata = initialAccelsMdata; + UAVObject::SetFlightTelemetryUpdateMode(accelsMdata, UAVObject::UPDATEMODE_PERIODIC); + accelsMdata.flightTelemetryUpdatePeriod = 30; + accels->setMetadata(accelsMdata); + + initialGyrosMdata = gyros->getMetadata(); + UAVObject::Metadata gyrosMdata = initialGyrosMdata; + UAVObject::SetFlightTelemetryUpdateMode(gyrosMdata, UAVObject::UPDATEMODE_PERIODIC); + gyrosMdata.flightTelemetryUpdatePeriod = 30; + gyros->setMetadata(gyrosMdata); } diff --git a/ground/openpilotgcs/src/plugins/config/configccattitudewidget.h b/ground/openpilotgcs/src/plugins/config/configccattitudewidget.h index 28d389df6..fc1a7f623 100644 --- a/ground/openpilotgcs/src/plugins/config/configccattitudewidget.h +++ b/ground/openpilotgcs/src/plugins/config/configccattitudewidget.h @@ -49,7 +49,7 @@ public: virtual void updateObjectsFromWidgets(); private slots: - void accelsUpdated(UAVObject * obj); + void sensorsUpdated(UAVObject * obj); void timeout(); void startAccelCalibration(); void openHelp(); @@ -58,14 +58,16 @@ private: QMutex startStop; Ui_ccattitude *ui; QTimer timer; - UAVObject::Metadata initialMdata; + UAVObject::Metadata initialAccelsMdata; + UAVObject::Metadata initialGyrosMdata; - int updates; + int accelUpdates; + int gyroUpdates; QList x_accum, y_accum, z_accum; QList x_gyro_accum, y_gyro_accum, z_gyro_accum; - static const int NUM_ACCEL_UPDATES = 60; + static const int NUM_SENSOR_UPDATES = 60; static const float ACCEL_SCALE = 0.004f * 9.81f; protected: virtual void enableControls(bool enable); diff --git a/ground/openpilotgcs/src/plugins/config/configgadgetwidget.h b/ground/openpilotgcs/src/plugins/config/configgadgetwidget.h index 5e9dc6e67..9e5156198 100644 --- a/ground/openpilotgcs/src/plugins/config/configgadgetwidget.h +++ b/ground/openpilotgcs/src/plugins/config/configgadgetwidget.h @@ -34,11 +34,9 @@ #include "objectpersistence.h" #include #include -//#include #include #include "utils/pathutils.h" #include -//#include "fancytabwidget.h" #include "utils/mytabbedstackwidget.h" #include "../uavobjectwidgetutils/configtaskwidget.h" diff --git a/ground/openpilotgcs/src/plugins/hitlnew/il2simulator.cpp b/ground/openpilotgcs/src/plugins/hitlnew/il2simulator.cpp index 78f78ffac..b49028d53 100644 --- a/ground/openpilotgcs/src/plugins/hitlnew/il2simulator.cpp +++ b/ground/openpilotgcs/src/plugins/hitlnew/il2simulator.cpp @@ -333,7 +333,7 @@ void IL2Simulator::processUpdate(const QByteArray& inp) NED[0] = current.Y; NED[1] = current.X; NED[2] = -current.Z; - Utils::CoordinateConversions().GetLLA(ECEF,NED,LLA); + //Utils::CoordinateConversions().NED2LLA_HomeECEF(ECEF,NED,LLA); gpsData.Latitude = LLA[0] * 10e6; gpsData.Longitude = LLA[1] * 10e6; gpsData.Satellites = 7; diff --git a/ground/openpilotgcs/src/plugins/hitlnew/xplanesimulator.cpp b/ground/openpilotgcs/src/plugins/hitlnew/xplanesimulator.cpp index 66dbfd1d6..1546b862e 100644 --- a/ground/openpilotgcs/src/plugins/hitlnew/xplanesimulator.cpp +++ b/ground/openpilotgcs/src/plugins/hitlnew/xplanesimulator.cpp @@ -210,9 +210,9 @@ void XplaneSimulator::processUpdate(const QByteArray& dataBuf) float accX = 0; float accY = 0; float accZ = 0; - float rollRate=0; - float pitchRate=0; - float yawRate=0; + float rollRate_rad=0; + float pitchRate_rad=0; + float yawRate_rad=0; QString str; QByteArray& buf = const_cast(dataBuf); @@ -269,10 +269,10 @@ void XplaneSimulator::processUpdate(const QByteArray& dataBuf) velZ = *((float*)(buf.data()+4*5)); break; - case XplaneSimulator::AngularVelocities: - pitchRate = *((float*)(buf.data()+4*1)); - rollRate = *((float*)(buf.data()+4*2)); - yawRate = *((float*)(buf.data()+4*3)); + case XplaneSimulator::AngularVelocities: //In [rad/s] + pitchRate_rad = *((float*)(buf.data()+4*1)); + rollRate_rad = *((float*)(buf.data()+4*2)); + yawRate_rad = *((float*)(buf.data()+4*3)); break; case XplaneSimulator::Gload: @@ -380,8 +380,8 @@ void XplaneSimulator::processUpdate(const QByteArray& dataBuf) //memset(&rawData, 0, sizeof(AttitudeRaw::DataFields)); //rawData = attRaw->getData(); //rawData.gyros[0] = rollRate; - //rawData.gyros_filtered[1] = cos(DEG2RAD * roll) * pitchRate + sin(DEG2RAD * roll) * yawRate; - //rawData.gyros_filtered[2] = cos(DEG2RAD * roll) * yawRate - sin(DEG2RAD * roll) * pitchRate; + //rawData.gyros_filtered[1] = cos(DEG2RAD * roll) * pitchRate_rad + sin(DEG2RAD * roll) * yawRate_rad; + //rawData.gyros_filtered[2] = cos(DEG2RAD * roll) * yawRate_rad - sin(DEG2RAD * roll) * pitchRate_rad; //rawData.gyros[1] = pitchRate; //rawData.gyros[2] = yawRate; //rawData.accels[0] = accX; @@ -390,9 +390,10 @@ void XplaneSimulator::processUpdate(const QByteArray& dataBuf) //attRaw->setData(rawData); Gyros::DataFields gyroData; memset(&gyroData, 0, sizeof(Gyros::DataFields)); - gyroData.x = rollRate; - gyroData.y = pitchRate; - gyroData.z = yawRate; +#define Pi 3.141529654 + gyroData.x = rollRate_rad*180/Pi; + gyroData.y = pitchRate_rad*180/Pi; + gyroData.z = yawRate_rad*180/Pi; gyros->setData(gyroData); Accels::DataFields accelData; @@ -420,7 +421,7 @@ void TraceBuf(const char* buf,int len) { if(i>0) { - qDebug() << str; +// qDebug() << str; str.clear(); reminder=false; } @@ -429,6 +430,7 @@ void TraceBuf(const char* buf,int len) str+=QString(" 0x%1").arg((quint8)buf[i],2,16,QLatin1Char('0')); } - if(reminder) - qDebug() << str; + if(reminder){ +// qDebug() << str; + } } diff --git a/ground/openpilotgcs/src/plugins/opmap/flightdatamodel.cpp b/ground/openpilotgcs/src/plugins/opmap/flightdatamodel.cpp new file mode 100644 index 000000000..04bcdd93c --- /dev/null +++ b/ground/openpilotgcs/src/plugins/opmap/flightdatamodel.cpp @@ -0,0 +1,639 @@ +/** + ****************************************************************************** + * + * @file flightdatamodel.cpp + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. + * @addtogroup GCSPlugins GCS Plugins + * @{ + * @addtogroup OPMapPlugin OpenPilot Map Plugin + * @{ + * @brief The OpenPilot Map plugin + *****************************************************************************/ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "flightdatamodel.h" +#include +#include +flightDataModel::flightDataModel(QObject *parent):QAbstractTableModel(parent) +{ + +} + +int flightDataModel::rowCount(const QModelIndex &/*parent*/) const +{ + return dataStorage.length(); +} + +int flightDataModel::columnCount(const QModelIndex &parent) const +{ + if (parent.isValid()) + return 0; + return 23; +} + +QVariant flightDataModel::data(const QModelIndex &index, int role) const +{ + if (role == Qt::DisplayRole||role==Qt::EditRole) + { + int rowNumber=index.row(); + int columnNumber=index.column(); + if(rowNumber>dataStorage.length()-1 || rowNumber<0) + return QVariant::Invalid; + pathPlanData * myRow=dataStorage.at(rowNumber); + QVariant ret=getColumnByIndex(myRow,columnNumber); + return ret; + } + /* + else if (role == Qt::BackgroundRole) { + // WaypointActive::DataFields waypointActive = waypointActiveObj->getData(); + + if(index.row() == waypointActive.Index) { + return QBrush(Qt::lightGray); + } else + return QVariant::Invalid; + }*/ + else { + return QVariant::Invalid; + } +} + +bool flightDataModel::setColumnByIndex(pathPlanData *row,const int index,const QVariant value) +{ + switch(index) + { + case WPDESCRITPTION: + row->wpDescritption=value.toString(); + return true; + break; + case LATPOSITION: + row->latPosition=value.toDouble(); + return true; + break; + case LNGPOSITION: + row->lngPosition=value.toDouble(); + return true; + break; + case DISRELATIVE: + row->disRelative=value.toDouble(); + return true; + break; + case BEARELATIVE: + row->beaRelative=value.toDouble(); + return true; + break; + case ALTITUDERELATIVE: + row->altitudeRelative=value.toFloat(); + return true; + break; + case ISRELATIVE: + row->isRelative=value.toDouble(); + return true; + break; + case ALTITUDE: + row->altitude=value.toDouble(); + return true; + break; + case VELOCITY: + row->velocity=value.toFloat(); + return true; + break; + case MODE: + row->mode=value.toInt(); + return true; + break; + case MODE_PARAMS0: + row->mode_params[0]=value.toInt(); + return true; + break; + case MODE_PARAMS1: + row->mode_params[1]=value.toInt(); + return true; + break; + case MODE_PARAMS2: + row->mode_params[2]=value.toInt(); + return true; + break; + case MODE_PARAMS3: + row->mode_params[3]=value.toInt(); + return true; + break; + case CONDITION: + row->condition=value.toInt(); + return true; + break; + case CONDITION_PARAMS0: + row->condition_params[0]=value.toInt(); + return true; + break; + case CONDITION_PARAMS1: + row->condition_params[1]=value.toInt(); + return true; + break; + case CONDITION_PARAMS2: + row->condition_params[2]=value.toInt(); + return true; + break; + case CONDITION_PARAMS3: + row->condition_params[3]=value.toInt(); + return true; + break; + case COMMAND: + row->command=value.toInt(); + break; + case JUMPDESTINATION: + row->jumpdestination=value.toInt(); + return true; + break; + case ERRORDESTINATION: + row->errordestination=value.toInt(); + return true; + break; + case LOCKED: + row->locked=value.toBool(); + return true; + break; + default: + return false; + } +} +QVariant flightDataModel::getColumnByIndex(const pathPlanData *row,const int index) const +{ + switch(index) + { + case WPDESCRITPTION: + return row->wpDescritption; + break; + case LATPOSITION: + return row->latPosition; + break; + case LNGPOSITION: + return row->lngPosition; + break; + case DISRELATIVE: + return row->disRelative; + break; + case BEARELATIVE: + return row->beaRelative; + break; + case ALTITUDERELATIVE: + return row->altitudeRelative; + break; + case ISRELATIVE: + return row->isRelative; + break; + case ALTITUDE: + return row->altitude; + break; + case VELOCITY: + return row->velocity; + break; + case MODE: + return row->mode; + break; + case MODE_PARAMS0: + return row->mode_params[0]; + break; + case MODE_PARAMS1: + return row->mode_params[1]; + break; + case MODE_PARAMS2: + return row->mode_params[2]; + break; + case MODE_PARAMS3: + return row->mode_params[3]; + break; + case CONDITION: + return row->condition; + break; + case CONDITION_PARAMS0: + return row->condition_params[0]; + break; + case CONDITION_PARAMS1: + return row->condition_params[1]; + break; + case CONDITION_PARAMS2: + return row->condition_params[2]; + break; + case CONDITION_PARAMS3: + return row->condition_params[3]; + break; + case COMMAND: + return row->command; + break; + case JUMPDESTINATION: + return row->jumpdestination; + break; + case ERRORDESTINATION: + return row->errordestination; + break; + case LOCKED: + return row->locked; + } +} +QVariant flightDataModel::headerData(int section, Qt::Orientation orientation, int role) const + { + if (role == Qt::DisplayRole) + { + if(orientation==Qt::Vertical) + { + return QString::number(section+1); + } + else if (orientation == Qt::Horizontal) { + switch (section) + { + case WPDESCRITPTION: + return QString("Description"); + break; + case LATPOSITION: + return QString("Latitude"); + break; + case LNGPOSITION: + return QString("Longitude"); + break; + case DISRELATIVE: + return QString("Distance to home"); + break; + case BEARELATIVE: + return QString("Bearing from home"); + break; + case ALTITUDERELATIVE: + return QString("Altitude above home"); + break; + case ISRELATIVE: + return QString("Relative to home"); + break; + case ALTITUDE: + return QString("Altitude"); + break; + case VELOCITY: + return QString("Velocity"); + break; + case MODE: + return QString("Mode"); + break; + case MODE_PARAMS0: + return QString("Mode parameter 0"); + break; + case MODE_PARAMS1: + return QString("Mode parameter 1"); + break; + case MODE_PARAMS2: + return QString("Mode parameter 2"); + break; + case MODE_PARAMS3: + return QString("Mode parameter 3"); + break; + case CONDITION: + return QString("Condition"); + break; + case CONDITION_PARAMS0: + return QString("Condition parameter 0"); + break; + case CONDITION_PARAMS1: + return QString("Condition parameter 1"); + break; + case CONDITION_PARAMS2: + return QString("Condition parameter 2"); + break; + case CONDITION_PARAMS3: + return QString("Condition parameter 3"); + break; + case COMMAND: + return QString("Command"); + break; + case JUMPDESTINATION: + return QString("Jump Destination"); + break; + case ERRORDESTINATION: + return QString("Error Destination"); + break; + case LOCKED: + return QString("Locked"); + break; + default: + return QString(); + break; + } + } + } + else + return QAbstractTableModel::headerData(section, orientation, role); +} +bool flightDataModel::setData(const QModelIndex &index, const QVariant &value, int role) +{ + if (role == Qt::EditRole) + { + int columnIndex=index.column(); + int rowIndex=index.row(); + if(rowIndex>dataStorage.length()-1) + return false; + pathPlanData * myRow=dataStorage.at(rowIndex); + setColumnByIndex(myRow,columnIndex,value); + emit dataChanged(index,index); + } + return true; +} + +Qt::ItemFlags flightDataModel::flags(const QModelIndex & /*index*/) const + { + return Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled ; +} + +bool flightDataModel::insertRows(int row, int count, const QModelIndex &/*parent*/) +{ + pathPlanData * data; + beginInsertRows(QModelIndex(),row,row+count-1); + for(int x=0; xlatPosition=0; + data->lngPosition=0; + data->disRelative=0; + data->beaRelative=0; + data->altitudeRelative=0; + data->isRelative=0; + data->altitude=0; + data->velocity=0; + data->mode=0; + data->mode_params[0]=0; + data->mode_params[1]=0; + data->mode_params[2]=0; + data->mode_params[3]=0; + data->condition=0; + data->condition_params[0]=0; + data->condition_params[1]=0; + data->condition_params[2]=0; + data->condition_params[3]=0; + data->command=0; + data->jumpdestination=0; + data->errordestination=0; + data->locked=false; + dataStorage.insert(row,data); + } + endInsertRows(); +} + +bool flightDataModel::removeRows(int row, int count, const QModelIndex &/*parent*/) +{ + if(row<0) + return false; + beginRemoveRows(QModelIndex(),row,row+count-1); + for(int x=0; xwpDescritption); + field.setAttribute("name","description"); + waypoint.appendChild(field); + + field=doc.createElement("field"); + field.setAttribute("value",obj->latPosition); + field.setAttribute("name","latitude"); + waypoint.appendChild(field); + + field=doc.createElement("field"); + field.setAttribute("value",obj->lngPosition); + field.setAttribute("name","longitude"); + waypoint.appendChild(field); + + field=doc.createElement("field"); + field.setAttribute("value",obj->disRelative); + field.setAttribute("name","distance_to_home"); + waypoint.appendChild(field); + + field=doc.createElement("field"); + field.setAttribute("value",obj->beaRelative); + field.setAttribute("name","bearing_from_home"); + waypoint.appendChild(field); + + field=doc.createElement("field"); + field.setAttribute("value",obj->altitudeRelative); + field.setAttribute("name","altitude_above_home"); + waypoint.appendChild(field); + + field=doc.createElement("field"); + field.setAttribute("value",obj->isRelative); + field.setAttribute("name","is_relative_to_home"); + waypoint.appendChild(field); + + field=doc.createElement("field"); + field.setAttribute("value",obj->altitude); + field.setAttribute("name","altitude"); + waypoint.appendChild(field); + + field=doc.createElement("field"); + field.setAttribute("value",obj->velocity); + field.setAttribute("name","velocity"); + waypoint.appendChild(field); + + field=doc.createElement("field"); + field.setAttribute("value",obj->mode); + field.setAttribute("name","mode"); + waypoint.appendChild(field); + + field=doc.createElement("field"); + field.setAttribute("value",obj->mode_params[0]); + field.setAttribute("name","mode_param0"); + waypoint.appendChild(field); + + field=doc.createElement("field"); + field.setAttribute("value",obj->mode_params[1]); + field.setAttribute("name","mode_param1"); + waypoint.appendChild(field); + + field=doc.createElement("field"); + field.setAttribute("value",obj->mode_params[2]); + field.setAttribute("name","mode_param2"); + waypoint.appendChild(field); + + field=doc.createElement("field"); + field.setAttribute("value",obj->mode_params[3]); + field.setAttribute("name","mode_param3"); + waypoint.appendChild(field); + + field=doc.createElement("field"); + field.setAttribute("value",obj->condition); + field.setAttribute("name","condition"); + waypoint.appendChild(field); + + field=doc.createElement("field"); + field.setAttribute("value",obj->condition_params[0]); + field.setAttribute("name","condition_param0"); + waypoint.appendChild(field); + + field=doc.createElement("field"); + field.setAttribute("value",obj->condition_params[1]); + field.setAttribute("name","condition_param1"); + waypoint.appendChild(field); + + field=doc.createElement("field"); + field.setAttribute("value",obj->condition_params[2]); + field.setAttribute("name","condition_param2"); + waypoint.appendChild(field); + + field=doc.createElement("field"); + field.setAttribute("value",obj->condition_params[3]); + field.setAttribute("name","condition_param3"); + waypoint.appendChild(field); + + field=doc.createElement("field"); + field.setAttribute("value",obj->command); + field.setAttribute("name","command"); + waypoint.appendChild(field); + + field=doc.createElement("field"); + field.setAttribute("value",obj->jumpdestination); + field.setAttribute("name","jumpdestination"); + waypoint.appendChild(field); + + field=doc.createElement("field"); + field.setAttribute("value",obj->errordestination); + field.setAttribute("name","errordestination"); + waypoint.appendChild(field); + + field=doc.createElement("field"); + field.setAttribute("value",obj->locked); + field.setAttribute("name","is_locked"); + waypoint.appendChild(field); + + } + file.write(doc.toString().toAscii()); + file.close(); + return true; +} +void flightDataModel::readFromFile(QString fileName) +{ + //TODO warning message + removeRows(0,rowCount()); + QFile file(fileName); + QDomDocument doc("PathPlan"); + if (!doc.setContent(file.readAll())) { + QMessageBox msgBox; + msgBox.setText(tr("File Parsing Failed.")); + msgBox.setInformativeText(tr("This file is not a correct XML file")); + msgBox.setStandardButtons(QMessageBox::Ok); + msgBox.exec(); + return; + } + file.close(); + + QDomElement root = doc.documentElement(); + + if (root.isNull() || (root.tagName() != "waypoints")) { + QMessageBox msgBox; + msgBox.setText(tr("Wrong file contents")); + msgBox.setInformativeText(tr("This file does not contain correct UAVSettings")); + msgBox.setStandardButtons(QMessageBox::Ok); + msgBox.exec(); + return; + } + + pathPlanData * data=NULL; + QDomNode node = root.firstChild(); + while (!node.isNull()) { + QDomElement e = node.toElement(); + if (e.tagName() == "waypoint") { + QDomNode fieldNode=e.firstChild(); + data=new pathPlanData; + while (!fieldNode.isNull()) { + QDomElement field = fieldNode.toElement(); + if (field.tagName() == "field") { + if(field.attribute("name")=="altitude") + data->altitude=field.attribute("value").toDouble(); + else if(field.attribute("name")=="description") + data->wpDescritption=field.attribute("value"); + else if(field.attribute("name")=="latitude") + data->latPosition=field.attribute("value").toDouble(); + else if(field.attribute("name")=="longitude") + data->lngPosition=field.attribute("value").toDouble(); + else if(field.attribute("name")=="distance_to_home") + data->disRelative=field.attribute("value").toDouble(); + else if(field.attribute("name")=="bearing_from_home") + data->beaRelative=field.attribute("value").toDouble(); + else if(field.attribute("name")=="altitude_above_home") + data->altitudeRelative=field.attribute("value").toFloat(); + else if(field.attribute("name")=="is_relative_to_home") + data->isRelative=field.attribute("value").toInt(); + else if(field.attribute("name")=="altitude") + data->altitude=field.attribute("value").toDouble(); + else if(field.attribute("name")=="velocity") + data->velocity=field.attribute("value").toDouble(); + else if(field.attribute("name")=="mode") + data->mode=field.attribute("value").toInt(); + else if(field.attribute("name")=="mode_param0") + data->mode_params[0]=field.attribute("value").toDouble(); + else if(field.attribute("name")=="mode_param1") + data->mode_params[1]=field.attribute("value").toDouble(); + else if(field.attribute("name")=="mode_param2") + data->mode_params[2]=field.attribute("value").toDouble(); + else if(field.attribute("name")=="mode_param3") + data->mode_params[3]=field.attribute("value").toDouble(); + else if(field.attribute("name")=="condition") + data->condition=field.attribute("value").toDouble(); + else if(field.attribute("name")=="condition_param0") + data->condition_params[0]=field.attribute("value").toFloat(); + else if(field.attribute("name")=="condition_param1") + data->condition_params[1]=field.attribute("value").toFloat(); + else if(field.attribute("name")=="condition_param2") + data->condition_params[2]=field.attribute("value").toFloat(); + else if(field.attribute("name")=="condition_param3") + data->condition_params[3]=field.attribute("value").toFloat(); + else if(field.attribute("name")=="command") + data->command=field.attribute("value").toInt(); + else if(field.attribute("name")=="jumpdestination") + data->jumpdestination=field.attribute("value").toInt(); + else if(field.attribute("name")=="errordestination") + data->errordestination=field.attribute("value").toInt(); + else if(field.attribute("name")=="is_locked") + data->locked=field.attribute("value").toInt(); + + } + fieldNode=fieldNode.nextSibling(); + } + beginInsertRows(QModelIndex(),dataStorage.length(),dataStorage.length()); + dataStorage.append(data); + endInsertRows(); + } + node=node.nextSibling(); + } +} + diff --git a/ground/openpilotgcs/src/plugins/opmap/flightdatamodel.h b/ground/openpilotgcs/src/plugins/opmap/flightdatamodel.h new file mode 100644 index 000000000..3043c607c --- /dev/null +++ b/ground/openpilotgcs/src/plugins/opmap/flightdatamodel.h @@ -0,0 +1,82 @@ +/** + ****************************************************************************** + * + * @file flightdatamodel.h + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. + * @addtogroup GCSPlugins GCS Plugins + * @{ + * @addtogroup OPMapPlugin OpenPilot Map Plugin + * @{ + * @brief The OpenPilot Map plugin + *****************************************************************************/ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#ifndef FLIGHTDATAMODEL_H +#define FLIGHTDATAMODEL_H +#include +#include "opmapcontrol/opmapcontrol.h" + +struct pathPlanData +{ + QString wpDescritption; + double latPosition; + double lngPosition; + double disRelative; + double beaRelative; + double altitudeRelative; + bool isRelative; + double altitude; + float velocity; + int mode; + float mode_params[4]; + int condition; + float condition_params[4]; + int command; + int jumpdestination; + int errordestination; + bool locked; +}; + +class flightDataModel:public QAbstractTableModel +{ + Q_OBJECT +public: + enum pathPlanDataEnum + { + WPDESCRITPTION,LATPOSITION,LNGPOSITION,DISRELATIVE,BEARELATIVE,ALTITUDERELATIVE,ISRELATIVE,ALTITUDE, + VELOCITY,MODE,MODE_PARAMS0,MODE_PARAMS1,MODE_PARAMS2,MODE_PARAMS3, + CONDITION,CONDITION_PARAMS0,CONDITION_PARAMS1,CONDITION_PARAMS2,CONDITION_PARAMS3, + COMMAND,JUMPDESTINATION,ERRORDESTINATION,LOCKED + }; + flightDataModel(QObject *parent); + int rowCount(const QModelIndex &parent = QModelIndex()) const ; + int columnCount(const QModelIndex &parent = QModelIndex()) const; + QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; + QVariant headerData(int section, Qt::Orientation orientation, int role) const; + + bool setData(const QModelIndex & index, const QVariant & value, int role = Qt::EditRole); + Qt::ItemFlags flags(const QModelIndex & index) const ; + bool insertRows ( int row, int count, const QModelIndex & parent = QModelIndex() ); + bool removeRows ( int row, int count, const QModelIndex & parent = QModelIndex() ); + bool writeToFile(QString filename); + void readFromFile(QString fileName); +private: + QList dataStorage; + QVariant getColumnByIndex(const pathPlanData *row, const int index) const; + bool setColumnByIndex(pathPlanData *row, const int index, const QVariant value); +}; + +#endif // FLIGHTDATAMODEL_H diff --git a/ground/openpilotgcs/src/plugins/opmap/homeeditor.cpp b/ground/openpilotgcs/src/plugins/opmap/homeeditor.cpp new file mode 100644 index 000000000..47b5466f0 --- /dev/null +++ b/ground/openpilotgcs/src/plugins/opmap/homeeditor.cpp @@ -0,0 +1,62 @@ +/** + ****************************************************************************** + * + * @file homeeditor.cpp + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. + * @addtogroup GCSPlugins GCS Plugins + * @{ + * @addtogroup OPMapPlugin OpenPilot Map Plugin + * @{ + * @brief The OpenPilot Map plugin + *****************************************************************************/ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#include "homeeditor.h" +#include "ui_homeeditor.h" + +homeEditor::homeEditor(HomeItem *home, QWidget *parent) : + QDialog(parent), + ui(new Ui::homeEditor), + myhome(home) +{ + if(!home) + { + deleteLater(); + return; + } + ui->setupUi(this); + this->setAttribute(Qt::WA_DeleteOnClose,true); + ui->altitude->setValue(home->Altitude()); + ui->latitude->setValue(home->Coord().Lat()); + ui->longitude->setValue(home->Coord().Lng()); + this->show(); +} + +homeEditor::~homeEditor() +{ + delete ui; +} + +void homeEditor::on_buttonBox_accepted() +{ + myhome->SetCoord(internals::PointLatLng(ui->latitude->value(),ui->longitude->value())); + myhome->SetAltitude(ui->altitude->value()); +} + +void homeEditor::on_buttonBox_rejected() +{ + this->close(); +} diff --git a/ground/openpilotgcs/src/plugins/opmap/opmap_overlay_widget.h b/ground/openpilotgcs/src/plugins/opmap/homeeditor.h similarity index 68% rename from ground/openpilotgcs/src/plugins/opmap/opmap_overlay_widget.h rename to ground/openpilotgcs/src/plugins/opmap/homeeditor.h index e10525d3d..e0404e6b9 100644 --- a/ground/openpilotgcs/src/plugins/opmap/opmap_overlay_widget.h +++ b/ground/openpilotgcs/src/plugins/opmap/homeeditor.h @@ -1,49 +1,57 @@ -/** - ****************************************************************************** - * - * @file opmap_overlay_widget.h - * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. - * @addtogroup GCSPlugins GCS Plugins - * @{ - * @addtogroup OPMapPlugin OpenPilot Map Plugin - * @{ - * @brief The OpenPilot Map plugin - *****************************************************************************/ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef OPMAP_OVERLAY_WIDGET_H -#define OPMAP_OVERLAY_WIDGET_H - -#include - -namespace Ui { - class opmap_overlay_widget; -} - -class opmap_overlay_widget : public QWidget -{ - Q_OBJECT - -public: - explicit opmap_overlay_widget(QWidget *parent = 0); - ~opmap_overlay_widget(); - -private: - Ui::opmap_overlay_widget *ui; -}; - -#endif // OPMAP_OVERLAY_WIDGET_H +/** + ****************************************************************************** + * + * @file homeeditor.h + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. + * @addtogroup GCSPlugins GCS Plugins + * @{ + * @addtogroup OPMapPlugin OpenPilot Map Plugin + * @{ + * @brief The OpenPilot Map plugin + *****************************************************************************/ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#ifndef HOMEEDITOR_H +#define HOMEEDITOR_H + +#include +#include "opmapcontrol/opmapcontrol.h" + +using namespace mapcontrol; + +namespace Ui { +class homeEditor; +} + +class homeEditor : public QDialog +{ + Q_OBJECT + +public: + explicit homeEditor(HomeItem * home,QWidget *parent = 0); + ~homeEditor(); + +private slots: + void on_buttonBox_accepted(); + + void on_buttonBox_rejected(); + +private: + Ui::homeEditor *ui; + HomeItem * myhome; +}; + +#endif // HOMEEDITOR_H diff --git a/ground/openpilotgcs/src/plugins/opmap/homeeditor.ui b/ground/openpilotgcs/src/plugins/opmap/homeeditor.ui new file mode 100644 index 000000000..98f5acc58 --- /dev/null +++ b/ground/openpilotgcs/src/plugins/opmap/homeeditor.ui @@ -0,0 +1,151 @@ + + + homeEditor + + + + 0 + 0 + 295 + 159 + + + + Dialog + + + + + + Latitude: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Longitude: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Altitude: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + -999999999.000000000000000 + + + 999999999.000000000000000 + + + 0.100000000000000 + + + + + + + 8 + + + -999999999.000000000000000 + + + 999999999.000000000000000 + + + 0.100000000000000 + + + + + + + + 0 + 0 + + + + + 0 + 0 + + + + 8 + + + -999999999.000000000000000 + + + 999999999.000000000000000 + + + 0.100000000000000 + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + homeEditor + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + homeEditor + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/ground/openpilotgcs/src/plugins/opmap/images/Ekisho Deep Ocean HD1.png b/ground/openpilotgcs/src/plugins/opmap/images/Ekisho Deep Ocean HD1.png new file mode 100644 index 000000000..54cd51b00 Binary files /dev/null and b/ground/openpilotgcs/src/plugins/opmap/images/Ekisho Deep Ocean HD1.png differ diff --git a/ground/openpilotgcs/src/plugins/opmap/images/down_alt.png b/ground/openpilotgcs/src/plugins/opmap/images/down_alt.png new file mode 100644 index 000000000..b77135526 Binary files /dev/null and b/ground/openpilotgcs/src/plugins/opmap/images/down_alt.png differ diff --git a/ground/openpilotgcs/src/plugins/opmap/images/down_alt2.png b/ground/openpilotgcs/src/plugins/opmap/images/down_alt2.png new file mode 100644 index 000000000..b77135526 Binary files /dev/null and b/ground/openpilotgcs/src/plugins/opmap/images/down_alt2.png differ diff --git a/ground/openpilotgcs/src/plugins/opmap/images/forward button white.png b/ground/openpilotgcs/src/plugins/opmap/images/forward button white.png new file mode 100644 index 000000000..e34adc93a Binary files /dev/null and b/ground/openpilotgcs/src/plugins/opmap/images/forward button white.png differ diff --git a/ground/openpilotgcs/src/plugins/opmap/images/forward_alt.png b/ground/openpilotgcs/src/plugins/opmap/images/forward_alt.png new file mode 100644 index 000000000..ddd2e4261 Binary files /dev/null and b/ground/openpilotgcs/src/plugins/opmap/images/forward_alt.png differ diff --git a/ground/openpilotgcs/src/plugins/opmap/images/new archive.png b/ground/openpilotgcs/src/plugins/opmap/images/new archive.png new file mode 100644 index 000000000..326c2bb3a Binary files /dev/null and b/ground/openpilotgcs/src/plugins/opmap/images/new archive.png differ diff --git a/ground/openpilotgcs/src/plugins/opmap/images/plus3.png b/ground/openpilotgcs/src/plugins/opmap/images/plus3.png new file mode 100644 index 000000000..63ce12ba2 Binary files /dev/null and b/ground/openpilotgcs/src/plugins/opmap/images/plus3.png differ diff --git a/ground/openpilotgcs/src/plugins/opmap/images/rewind button white.png b/ground/openpilotgcs/src/plugins/opmap/images/rewind button white.png new file mode 100644 index 000000000..549bd8057 Binary files /dev/null and b/ground/openpilotgcs/src/plugins/opmap/images/rewind button white.png differ diff --git a/ground/openpilotgcs/src/plugins/opmap/images/star.png b/ground/openpilotgcs/src/plugins/opmap/images/star.png new file mode 100644 index 000000000..25ef8b290 Binary files /dev/null and b/ground/openpilotgcs/src/plugins/opmap/images/star.png differ diff --git a/ground/openpilotgcs/src/plugins/opmap/images/stopb.png b/ground/openpilotgcs/src/plugins/opmap/images/stopb.png new file mode 100644 index 000000000..5dad7cdac Binary files /dev/null and b/ground/openpilotgcs/src/plugins/opmap/images/stopb.png differ diff --git a/ground/openpilotgcs/src/plugins/opmap/images/unarchive.png b/ground/openpilotgcs/src/plugins/opmap/images/unarchive.png new file mode 100644 index 000000000..e74f0a31c Binary files /dev/null and b/ground/openpilotgcs/src/plugins/opmap/images/unarchive.png differ diff --git a/ground/openpilotgcs/src/plugins/opmap/images/up_alt.png b/ground/openpilotgcs/src/plugins/opmap/images/up_alt.png new file mode 100644 index 000000000..4d8b67f59 Binary files /dev/null and b/ground/openpilotgcs/src/plugins/opmap/images/up_alt.png differ diff --git a/ground/openpilotgcs/src/plugins/opmap/modelmapproxy.cpp b/ground/openpilotgcs/src/plugins/opmap/modelmapproxy.cpp new file mode 100644 index 000000000..406d8e23d --- /dev/null +++ b/ground/openpilotgcs/src/plugins/opmap/modelmapproxy.cpp @@ -0,0 +1,342 @@ +/** + ****************************************************************************** + * + * @file modelmapproxy.cpp + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. + * @addtogroup GCSPlugins GCS Plugins + * @{ + * @addtogroup OPMapPlugin OpenPilot Map Plugin + * @{ + * @brief The OpenPilot Map plugin + *****************************************************************************/ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "modelmapproxy.h" + +modelMapProxy::modelMapProxy(QObject *parent,OPMapWidget *map,flightDataModel * model,QItemSelectionModel * selectionModel):QObject(parent),myMap(map),model(model),selection(selectionModel) +{ + connect(model,SIGNAL(rowsInserted(const QModelIndex&,int,int)),this,SLOT(rowsInserted(const QModelIndex&,int,int))); + connect(model,SIGNAL(rowsRemoved(const QModelIndex&,int,int)),this,SLOT(rowsRemoved(const QModelIndex&,int,int))); + connect(selection,SIGNAL(currentRowChanged(QModelIndex,QModelIndex)),this,SLOT(currentRowChanged(QModelIndex,QModelIndex))); + connect(model,SIGNAL(dataChanged(QModelIndex,QModelIndex)),this,SLOT(dataChanged(QModelIndex,QModelIndex))); + connect(myMap,SIGNAL(selectedWPChanged(QList)),this,SLOT(selectedWPChanged(QList))); + connect(myMap,SIGNAL(WPValuesChanged(WayPointItem*)),this,SLOT(WPValuesChanged(WayPointItem*))); +} + +void modelMapProxy::WPValuesChanged(WayPointItem * wp) +{ + QModelIndex index; + index=model->index(wp->Number(),flightDataModel::LATPOSITION); + if(!index.isValid()) + return; + model->setData(index,wp->Coord().Lat(),Qt::EditRole); + index=model->index(wp->Number(),flightDataModel::LNGPOSITION); + model->setData(index,wp->Coord().Lng(),Qt::EditRole); + + index=model->index(wp->Number(),flightDataModel::ALTITUDE); + model->setData(index,wp->Altitude(),Qt::EditRole); + + index=model->index(wp->Number(),flightDataModel::DISRELATIVE); + model->setData(index,wp->getRelativeCoord().distance,Qt::EditRole); + index=model->index(wp->Number(),flightDataModel::BEARELATIVE); + model->setData(index,wp->getRelativeCoord().bearingToDegrees(),Qt::EditRole); + index=model->index(wp->Number(),flightDataModel::ALTITUDERELATIVE); + model->setData(index,wp->getRelativeCoord().altitudeRelative,Qt::EditRole); +} + +void modelMapProxy::currentRowChanged(QModelIndex current, QModelIndex previous) +{ + QList list; + WayPointItem * wp=findWayPointNumber(current.row()); + if(!wp) + return; + list.append(wp); + myMap->setSelectedWP(list); +} + +void modelMapProxy::selectedWPChanged(QList list) +{ + selection->clearSelection(); + foreach(WayPointItem * wp,list) + { + QModelIndex index=model->index(wp->Number(),0); + selection->setCurrentIndex(index,QItemSelectionModel::Select | QItemSelectionModel::Rows); + } +} + +modelMapProxy::overlayType modelMapProxy::overlayTranslate(int type) +{ + switch(type) + { + case MapDataDelegate::MODE_FLYENDPOINT: + case MapDataDelegate::MODE_FLYVECTOR: + case MapDataDelegate::MODE_DRIVEENDPOINT: + case MapDataDelegate::MODE_DRIVEVECTOR: + return OVERLAY_LINE; + break; + case MapDataDelegate::MODE_FLYCIRCLERIGHT: + case MapDataDelegate::MODE_DRIVECIRCLERIGHT: + return OVERLAY_CIRCLE_RIGHT; + break; + case MapDataDelegate::MODE_FLYCIRCLELEFT: + case MapDataDelegate::MODE_DRIVECIRCLELEFT: + return OVERLAY_CIRCLE_LEFT; + break; + default: + break; + } +} + +void modelMapProxy::createOverlay(WayPointItem *from, WayPointItem *to, modelMapProxy::overlayType type,QColor color) +{ + if(from==NULL || to==NULL || from==to) + return; + switch(type) + { + case OVERLAY_LINE: + myMap->WPLineCreate(from,to,color); + break; + case OVERLAY_CIRCLE_RIGHT: + myMap->WPCircleCreate(to,from,true,color); + break; + case OVERLAY_CIRCLE_LEFT: + myMap->WPCircleCreate(to,from,false,color); + break; + default: + break; + + } +} +void modelMapProxy::createOverlay(WayPointItem *from, HomeItem *to, modelMapProxy::overlayType type,QColor color) +{ + if(from==NULL || to==NULL) + return; + switch(type) + { + case OVERLAY_LINE: + myMap->WPLineCreate(to,from,color); + break; + case OVERLAY_CIRCLE_RIGHT: + myMap->WPCircleCreate(to,from,true,color); + break; + case OVERLAY_CIRCLE_LEFT: + myMap->WPCircleCreate(to,from,false,color); + break; + default: + break; + + } +} +void modelMapProxy::refreshOverlays() +{ + myMap->deleteAllOverlays(); + if(model->rowCount()<1) + return; + WayPointItem * wp_current=NULL; + WayPointItem * wp_next=NULL; + int wp_jump; + int wp_error; + overlayType wp_next_overlay; + overlayType wp_jump_overlay; + overlayType wp_error_overlay; + wp_current=findWayPointNumber(0); + overlayType wp_current_overlay=overlayTranslate(model->data(model->index(0,flightDataModel::MODE)).toInt()); + createOverlay(wp_current,myMap->Home,wp_current_overlay,Qt::green); + for(int x=0;xrowCount();++x) + { + wp_current=findWayPointNumber(x); + wp_jump=model->data(model->index(x,flightDataModel::JUMPDESTINATION)).toInt()-1; + wp_error=model->data(model->index(x,flightDataModel::ERRORDESTINATION)).toInt()-1; + wp_next_overlay=overlayTranslate(model->data(model->index(x+1,flightDataModel::MODE)).toInt()); + wp_jump_overlay=overlayTranslate(model->data(model->index(wp_jump,flightDataModel::MODE)).toInt()); + wp_error_overlay=overlayTranslate(model->data(model->index(wp_error,flightDataModel::MODE)).toInt()); + createOverlay(wp_current,findWayPointNumber(wp_error),wp_error_overlay,Qt::red); + switch(model->data(model->index(x,flightDataModel::COMMAND)).toInt()) + { + case MapDataDelegate::COMMAND_ONCONDITIONNEXTWAYPOINT: + wp_next=findWayPointNumber(x+1); + createOverlay(wp_current,wp_next,wp_next_overlay,Qt::green); + break; + case MapDataDelegate::COMMAND_ONCONDITIONJUMPWAYPOINT: + wp_next=findWayPointNumber(wp_jump); + createOverlay(wp_current,wp_next,wp_jump_overlay,Qt::green); + break; + case MapDataDelegate::COMMAND_ONNOTCONDITIONJUMPWAYPOINT: + wp_next=findWayPointNumber(wp_jump); + createOverlay(wp_current,wp_next,wp_jump_overlay,Qt::yellow); + break; + case MapDataDelegate::COMMAND_ONNOTCONDITIONNEXTWAYPOINT: + wp_next=findWayPointNumber(x+1); + createOverlay(wp_current,wp_next,wp_next_overlay,Qt::yellow); + break; + case MapDataDelegate::COMMAND_IFCONDITIONJUMPWAYPOINTELSENEXTWAYPOINT: + wp_next=findWayPointNumber(wp_jump); + createOverlay(wp_current,wp_next,wp_jump_overlay,Qt::green); + wp_next=findWayPointNumber(x+1); + createOverlay(wp_current,wp_next,wp_next_overlay,Qt::green); + break; + } + } +} + +WayPointItem * modelMapProxy::findWayPointNumber(int number) +{ + if(number<0) + return NULL; + return myMap->WPFind(number); +} + +void modelMapProxy::rowsRemoved(const QModelIndex &parent, int first, int last) +{ + for(int x=last;x>first-1;x--) + { + myMap->WPDelete(x); + } + refreshOverlays(); +} + +void modelMapProxy::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight) +{ + WayPointItem * item=findWayPointNumber(topLeft.row()); + if(!item) + return; + internals::PointLatLng latlng; + int x=topLeft.row(); + distBearingAltitude distBearing; + double altitude; + bool relative; + QModelIndex index; + QString desc; + switch(topLeft.column()) + { + case flightDataModel::COMMAND: + case flightDataModel::CONDITION: + case flightDataModel::JUMPDESTINATION: + case flightDataModel::ERRORDESTINATION: + case flightDataModel::MODE: + refreshOverlays(); + break; + case flightDataModel::WPDESCRITPTION: + index=model->index(x,flightDataModel::WPDESCRITPTION); + desc=index.data(Qt::DisplayRole).toString(); + item->SetDescription(desc); + break; + case flightDataModel::LATPOSITION: + latlng=item->Coord(); + index=model->index(x,flightDataModel::LATPOSITION); + latlng.SetLat(index.data(Qt::DisplayRole).toDouble()); + item->SetCoord(latlng); + break; + case flightDataModel::LNGPOSITION: + latlng=item->Coord(); + index=model->index(x,flightDataModel::LNGPOSITION); + latlng.SetLng(index.data(Qt::DisplayRole).toDouble()); + item->SetCoord(latlng); + break; + case flightDataModel::BEARELATIVE: + distBearing=item->getRelativeCoord(); + index=model->index(x,flightDataModel::BEARELATIVE); + distBearing.setBearingFromDegrees(index.data(Qt::DisplayRole).toDouble()); + item->setRelativeCoord(distBearing); + break; + case flightDataModel::DISRELATIVE: + distBearing=item->getRelativeCoord(); + index=model->index(x,flightDataModel::DISRELATIVE); + distBearing.distance=index.data(Qt::DisplayRole).toDouble(); + item->setRelativeCoord(distBearing); + break; + case flightDataModel::ALTITUDERELATIVE: + distBearing=item->getRelativeCoord(); + index=model->index(x,flightDataModel::ALTITUDERELATIVE); + distBearing.altitudeRelative=index.data(Qt::DisplayRole).toFloat(); + item->setRelativeCoord(distBearing); + break; + case flightDataModel::ISRELATIVE: + index=model->index(x,flightDataModel::ISRELATIVE); + relative=index.data(Qt::DisplayRole).toBool(); + if(relative) + item->setWPType(mapcontrol::WayPointItem::relative); + else + item->setWPType(mapcontrol::WayPointItem::absolute); + break; + case flightDataModel::ALTITUDE: + index=model->index(x,flightDataModel::ALTITUDE); + altitude=index.data(Qt::DisplayRole).toDouble(); + item->SetAltitude(altitude); + break; + case flightDataModel::LOCKED: + index=model->index(x,flightDataModel::LOCKED); + item->setFlag(QGraphicsItem::ItemIsMovable,!index.data(Qt::DisplayRole).toBool()); + break; + } +} + +void modelMapProxy::rowsInserted(const QModelIndex &parent, int first, int last) +{ + Q_UNUSED(parent); + for(int x=first;xindex(x,flightDataModel::WPDESCRITPTION); + QString desc=index.data(Qt::DisplayRole).toString(); + index=model->index(x,flightDataModel::LATPOSITION); + latlng.SetLat(index.data(Qt::DisplayRole).toDouble()); + index=model->index(x,flightDataModel::LNGPOSITION); + latlng.SetLng(index.data(Qt::DisplayRole).toDouble()); + index=model->index(x,flightDataModel::DISRELATIVE); + distBearing.distance=index.data(Qt::DisplayRole).toDouble(); + index=model->index(x,flightDataModel::BEARELATIVE); + distBearing.setBearingFromDegrees(index.data(Qt::DisplayRole).toDouble()); + index=model->index(x,flightDataModel::ALTITUDERELATIVE); + distBearing.altitudeRelative=index.data(Qt::DisplayRole).toFloat(); + index=model->index(x,flightDataModel::ISRELATIVE); + relative=index.data(Qt::DisplayRole).toBool(); + index=model->index(x,flightDataModel::ALTITUDE); + altitude=index.data(Qt::DisplayRole).toDouble(); + if(relative) + item=myMap->WPInsert(distBearing,desc,x); + else + item=myMap->WPInsert(latlng,altitude,desc,x); + } + refreshOverlays(); +} +void modelMapProxy::deleteWayPoint(int number) +{ + model->removeRow(number,QModelIndex()); +} + +void modelMapProxy::createWayPoint(internals::PointLatLng coord) +{ + model->insertRow(model->rowCount(),QModelIndex()); + QModelIndex index=model->index(model->rowCount()-1,flightDataModel::LATPOSITION,QModelIndex()); + model->setData(index,coord.Lat(),Qt::EditRole); + index=model->index(model->rowCount()-1,flightDataModel::LNGPOSITION,QModelIndex()); + model->setData(index,coord.Lng(),Qt::EditRole); + index=model->index(model->rowCount()-1,flightDataModel::JUMPDESTINATION,QModelIndex()); + model->setData(index,1,Qt::EditRole); + index=model->index(model->rowCount()-1,flightDataModel::ERRORDESTINATION,QModelIndex()); + model->setData(index,1,Qt::EditRole); +} +void modelMapProxy::deleteAll() +{ + model->removeRows(0,model->rowCount(),QModelIndex()); +} diff --git a/ground/openpilotgcs/src/plugins/opmap/modelmapproxy.h b/ground/openpilotgcs/src/plugins/opmap/modelmapproxy.h new file mode 100644 index 000000000..29c61c9b1 --- /dev/null +++ b/ground/openpilotgcs/src/plugins/opmap/modelmapproxy.h @@ -0,0 +1,68 @@ +/** + ****************************************************************************** + * + * @file modelmapproxy.h + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. + * @addtogroup GCSPlugins GCS Plugins + * @{ + * @addtogroup OPMapPlugin OpenPilot Map Plugin + * @{ + * @brief The OpenPilot Map plugin + *****************************************************************************/ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#ifndef MODELMAPPROXY_H +#define MODELMAPPROXY_H +#include +#include "opmapcontrol/opmapcontrol.h" +#include "pathaction.h" +#include "waypoint.h" +#include "QMutexLocker" +#include "QPointer" +#include "flightdatamodel.h" +#include +#include + + +using namespace mapcontrol; +class modelMapProxy:public QObject +{ + typedef enum {OVERLAY_LINE,OVERLAY_CIRCLE_RIGHT,OVERLAY_CIRCLE_LEFT} overlayType; + Q_OBJECT +public: + explicit modelMapProxy(QObject *parent,OPMapWidget * map,flightDataModel * model,QItemSelectionModel * selectionModel); + WayPointItem *findWayPointNumber(int number); + void createWayPoint(internals::PointLatLng coord); + void deleteWayPoint(int number); + void deleteAll(); +private slots: + void dataChanged ( const QModelIndex & topLeft, const QModelIndex & bottomRight ); + void rowsInserted ( const QModelIndex & parent, int first, int last ); + void rowsRemoved ( const QModelIndex & parent, int first, int last ); + void WPValuesChanged(WayPointItem *wp); + void currentRowChanged(QModelIndex,QModelIndex); + void selectedWPChanged(QList); +private: + overlayType overlayTranslate(int type); + void createOverlay(WayPointItem * from,WayPointItem * to,overlayType type,QColor color); + void createOverlay(WayPointItem *from, HomeItem *to, modelMapProxy::overlayType type, QColor color); + OPMapWidget * myMap; + flightDataModel * model; + void refreshOverlays(); + QItemSelectionModel * selection; +}; + +#endif // MODELMAPPROXY_H diff --git a/ground/openpilotgcs/src/plugins/opmap/modeluavoproxy.cpp b/ground/openpilotgcs/src/plugins/opmap/modeluavoproxy.cpp new file mode 100644 index 000000000..8d28bc35e --- /dev/null +++ b/ground/openpilotgcs/src/plugins/opmap/modeluavoproxy.cpp @@ -0,0 +1,248 @@ +/** + ****************************************************************************** + * + * @file modeluavproxy.cpp + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. + * @addtogroup GCSPlugins GCS Plugins + * @{ + * @addtogroup OPMapPlugin OpenPilot Map Plugin + * @{ + * @brief The OpenPilot Map plugin + *****************************************************************************/ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#include "modeluavoproxy.h" +#include "extensionsystem/pluginmanager.h" +#include +modelUavoProxy::modelUavoProxy(QObject *parent,flightDataModel * model):QObject(parent),myModel(model) +{ + ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); + Q_ASSERT(pm != NULL); + objManager = pm->getObject(); + Q_ASSERT(objManager != NULL); + waypointObj = Waypoint::GetInstance(objManager); + Q_ASSERT(waypointObj != NULL); + pathactionObj=PathAction::GetInstance(objManager); + Q_ASSERT(pathactionObj != NULL); +} +void modelUavoProxy::modelToObjects() +{ + PathAction * act=NULL; + Waypoint * wp=NULL; + QModelIndex index; + double distance; + double bearing; + double altitude; + int lastaction=-1; + for(int x=0;xrowCount();++x) + { + int instances=objManager->getNumInstances(waypointObj->getObjID()); + if(x>instances-1) + { + wp=new Waypoint; + wp->initialize(x,wp->getMetaObject()); + objManager->registerObject(wp); + } + else + { + wp=Waypoint::GetInstance(objManager,x); + } + act=new PathAction; + Q_ASSERT(act); + Q_ASSERT(wp); + Waypoint::DataFields waypoint = wp->getData(); + PathAction::DataFields action = act->getData(); + + ///Waypoint object data + index=myModel->index(x,flightDataModel::DISRELATIVE); + distance=myModel->data(index).toDouble(); + index=myModel->index(x,flightDataModel::BEARELATIVE); + bearing=myModel->data(index).toDouble(); + index=myModel->index(x,flightDataModel::ALTITUDERELATIVE); + altitude=myModel->data(index).toFloat(); + index=myModel->index(x,flightDataModel::VELOCITY); + waypoint.Velocity[0]=myModel->data(index).toFloat(); + + waypoint.Position[Waypoint::POSITION_NORTH]=distance*cos(bearing/180*M_PI); + waypoint.Position[Waypoint::POSITION_EAST]=distance*sin(bearing/180*M_PI); + waypoint.Position[Waypoint::POSITION_DOWN]=(-1.0f)*altitude; + + ///PathAction object data + index=myModel->index(x,flightDataModel::MODE); + action.Mode=myModel->data(index).toInt(); + index=myModel->index(x,flightDataModel::MODE_PARAMS0); + action.ModeParameters[0]=myModel->data(index).toFloat(); + index=myModel->index(x,flightDataModel::MODE_PARAMS1); + action.ModeParameters[1]=myModel->data(index).toFloat(); + index=myModel->index(x,flightDataModel::MODE_PARAMS2); + action.ModeParameters[2]=myModel->data(index).toFloat(); + index=myModel->index(x,flightDataModel::MODE_PARAMS3); + action.ModeParameters[3]=myModel->data(index).toFloat(); + + index=myModel->index(x,flightDataModel::CONDITION); + action.EndCondition=myModel->data(index).toInt(); + index=myModel->index(x,flightDataModel::CONDITION_PARAMS0); + action.ConditionParameters[0]=myModel->data(index).toFloat(); + index=myModel->index(x,flightDataModel::CONDITION_PARAMS1); + action.ConditionParameters[1]=myModel->data(index).toFloat(); + index=myModel->index(x,flightDataModel::CONDITION_PARAMS2); + action.ConditionParameters[2]=myModel->data(index).toFloat(); + index=myModel->index(x,flightDataModel::CONDITION_PARAMS3); + action.ConditionParameters[3]=myModel->data(index).toFloat(); + + index=myModel->index(x,flightDataModel::COMMAND); + action.Command=myModel->data(index).toInt(); + index=myModel->index(x,flightDataModel::JUMPDESTINATION); + action.JumpDestination=myModel->data(index).toInt()-1; + index=myModel->index(x,flightDataModel::ERRORDESTINATION); + action.ErrorDestination=myModel->data(index).toInt()-1; + + int actionNumber=addAction(act,action,lastaction); + if(actionNumber>lastaction) + lastaction=actionNumber; + waypoint.Action=actionNumber; + wp->setData(waypoint); + wp->updated(); + } +} + +void modelUavoProxy::objectsToModel() +{ + Waypoint * wp; + Waypoint::DataFields wpfields; + PathAction * action; + QModelIndex index; + double distance; + double bearing; + + PathAction::DataFields actionfields; + + myModel->removeRows(0,myModel->rowCount()); + for(int x=0;xgetNumInstances(waypointObj->getObjID());++x) + { + wp=Waypoint::GetInstance(objManager,x); + Q_ASSERT(wp); + if(!wp) + continue; + wpfields=wp->getData(); + myModel->insertRow(x); + index=myModel->index(x,flightDataModel::VELOCITY); + myModel->setData(index,wpfields.Velocity); + distance=sqrt(wpfields.Position[Waypoint::POSITION_NORTH]*wpfields.Position[Waypoint::POSITION_NORTH]+ + wpfields.Position[Waypoint::POSITION_EAST]*wpfields.Position[Waypoint::POSITION_EAST]); + bearing=acos(wpfields.Position[Waypoint::POSITION_NORTH]/wpfields.Position[Waypoint::POSITION_EAST])*180/M_PI; + if(bearing!=bearing) + bearing=0; + index=myModel->index(x,flightDataModel::DISRELATIVE); + myModel->setData(index,distance); + index=myModel->index(x,flightDataModel::BEARELATIVE); + myModel->setData(index,bearing); + index=myModel->index(x,flightDataModel::ALTITUDERELATIVE); + myModel->setData(index,(-1.0f)*wpfields.Position[Waypoint::POSITION_DOWN]); + + action=PathAction::GetInstance(objManager,wpfields.Action); + Q_ASSERT(action); + if(!action) + continue; + actionfields=action->getData(); + + index=myModel->index(x,flightDataModel::ISRELATIVE); + myModel->setData(index,true); + + index=myModel->index(x,flightDataModel::COMMAND); + myModel->setData(index,actionfields.Command); + + index=myModel->index(x,flightDataModel::CONDITION_PARAMS0); + myModel->setData(index,actionfields.ConditionParameters[0]); + index=myModel->index(x,flightDataModel::CONDITION_PARAMS1); + myModel->setData(index,actionfields.ConditionParameters[1]); + index=myModel->index(x,flightDataModel::CONDITION_PARAMS2); + myModel->setData(index,actionfields.ConditionParameters[2]); + index=myModel->index(x,flightDataModel::CONDITION_PARAMS3); + myModel->setData(index,actionfields.ConditionParameters[3]); + + index=myModel->index(x,flightDataModel::CONDITION); + myModel->setData(index,actionfields.EndCondition); + + index=myModel->index(x,flightDataModel::ERRORDESTINATION); + myModel->setData(index,actionfields.ErrorDestination+1); + + index=myModel->index(x,flightDataModel::JUMPDESTINATION); + myModel->setData(index,actionfields.JumpDestination+1); + + index=myModel->index(x,flightDataModel::MODE); + myModel->setData(index,actionfields.Mode); + + index=myModel->index(x,flightDataModel::MODE_PARAMS0); + myModel->setData(index,actionfields.ModeParameters[0]); + index=myModel->index(x,flightDataModel::MODE_PARAMS1); + myModel->setData(index,actionfields.ModeParameters[1]); + index=myModel->index(x,flightDataModel::MODE_PARAMS2); + myModel->setData(index,actionfields.ModeParameters[2]); + index=myModel->index(x,flightDataModel::MODE_PARAMS3); + myModel->setData(index,actionfields.ModeParameters[3]); + } +} +int modelUavoProxy::addAction(PathAction * actionObj,PathAction::DataFields actionFields,int lastaction) +{ + //check if a similar action already exhists + int instances=objManager->getNumInstances(pathactionObj->getObjID()); + for(int x=0;xgetData(); + if(fields.Command==actionFields.Command + && fields.ConditionParameters[0]==actionFields.ConditionParameters[0] + && fields.ConditionParameters[1]==actionFields.ConditionParameters[1] + && fields.ConditionParameters[2]==actionFields.ConditionParameters[2] + &&fields.EndCondition==actionFields.EndCondition + &&fields.ErrorDestination==actionFields.ErrorDestination + &&fields.JumpDestination==actionFields.JumpDestination + &&fields.Mode==actionFields.Mode + &&fields.ModeParameters[0]==actionFields.ModeParameters[0] + &&fields.ModeParameters[1]==actionFields.ModeParameters[1] + &&fields.ModeParameters[2]==actionFields.ModeParameters[2]) + { + qDebug()<<"ModelUAVProxy:"<<"found similar action instance:"<deleteLater(); + return x; + } + } + //if we get here it means no similar action was found, we have to create it + if(instancesinitialize(instances,actionObj->getMetaObject()); + objManager->registerObject(actionObj); + actionObj->setData(actionFields); + actionObj->updated(); + qDebug()<<"ModelUAVProxy:"<<"created new action instance:"<setData(actionFields); + action->updated(); + actionObj->deleteLater(); + qDebug()<<"ModelUAVProxy:"<<"reused action instance:"<setupUi(this); -} - -opmap_overlay_widget::~opmap_overlay_widget() -{ - delete ui; -} +/** + ****************************************************************************** + * + * @file modeluavproxy.h + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. + * @addtogroup GCSPlugins GCS Plugins + * @{ + * @addtogroup OPMapPlugin OpenPilot Map Plugin + * @{ + * @brief The OpenPilot Map plugin + *****************************************************************************/ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#ifndef MODELUAVOPROXY_H +#define MODELUAVOPROXY_H + +#include +#include "flightdatamodel.h" +#include "pathaction.h" +#include "waypoint.h" + +class modelUavoProxy:public QObject +{ + Q_OBJECT +public: + explicit modelUavoProxy(QObject *parent, flightDataModel *model); + int addAction(PathAction *actionObj, PathAction::DataFields actionFields,int lastaction); +public slots: + void modelToObjects(); + void objectsToModel(); +private: + UAVObjectManager *objManager; + Waypoint * waypointObj; + PathAction * pathactionObj; + flightDataModel * myModel; +}; + +#endif // MODELUAVOPROXY_H diff --git a/ground/openpilotgcs/src/plugins/opmap/opmap.pro b/ground/openpilotgcs/src/plugins/opmap/opmap.pro index 042b35d8e..6132da69f 100644 --- a/ground/openpilotgcs/src/plugins/opmap/opmap.pro +++ b/ground/openpilotgcs/src/plugins/opmap/opmap.pro @@ -1,6 +1,6 @@ +QT += xml TEMPLATE = lib TARGET = OPMapGadget - include(../../openpilotgcsplugin.pri) include(../../plugins/coreplugin/coreplugin.pri) include(../../libs/opmapcontrol/opmapcontrol.pri) @@ -15,11 +15,11 @@ HEADERS += opmapplugin.h \ opmapgadgetconfiguration.h \ opmapgadget.h \ opmapgadgetwidget.h \ -# opmap_waypointeditor_dialog.h \ -# opmap_edit_waypoint_dialog.h \ + opmap_edit_waypoint_dialog.h \ opmap_zoom_slider_widget.h \ opmap_statusbar_widget.h \ - opmap_overlay_widget.h \ + widgetdelegates.h \ + homeeditor.h \ pathcompiler.h SOURCES += opmapplugin.cpp \ @@ -28,23 +28,22 @@ SOURCES += opmapplugin.cpp \ opmapgadgetfactory.cpp \ opmapgadgetconfiguration.cpp \ opmapgadget.cpp \ - # opmap_waypointeditor_dialog.cpp \ - # opmap_edit_waypoint_dialog.cpp \ + pathcompiler.cpp \ + opmap_edit_waypoint_dialog.cpp \ opmap_zoom_slider_widget.cpp \ opmap_statusbar_widget.cpp \ - opmap_overlay_widget.cpp \ - pathcompiler.cpp + widgetdelegates.cpp \ + homeeditor.cpp OTHER_FILES += OPMapGadget.pluginspec FORMS += opmapgadgetoptionspage.ui \ opmap_widget.ui \ - # opmap_waypointeditor_dialog.ui \ - # opmap_edit_waypoint_dialog.ui \ + opmap_edit_waypoint_dialog.ui \ opmap_zoom_slider_widget.ui \ opmap_statusbar_widget.ui \ - opmap_overlay_widget.ui + opmap_overlay_widget.ui \ + pathplanner.ui \ + homeeditor.ui RESOURCES += opmap.qrc - - diff --git a/ground/openpilotgcs/src/plugins/opmap/opmap.qrc b/ground/openpilotgcs/src/plugins/opmap/opmap.qrc index eae9fc9cd..10073e59e 100644 --- a/ground/openpilotgcs/src/plugins/opmap/opmap.qrc +++ b/ground/openpilotgcs/src/plugins/opmap/opmap.qrc @@ -25,5 +25,16 @@ images/home_wp.png images/move_to_wp.png images/center_wp.png + images/Ekisho Deep Ocean HD1.png + images/forward button white.png + images/new archive.png + images/rewind button white.png + images/stopb.png + images/unarchive.png + images/up_alt.png + images/plus3.png + images/forward_alt.png + images/star.png + images/down_alt.png diff --git a/ground/openpilotgcs/src/plugins/opmap/opmap_edit_waypoint_dialog.cpp b/ground/openpilotgcs/src/plugins/opmap/opmap_edit_waypoint_dialog.cpp index c7cbb53b0..cab739b8e 100644 --- a/ground/openpilotgcs/src/plugins/opmap/opmap_edit_waypoint_dialog.cpp +++ b/ground/openpilotgcs/src/plugins/opmap/opmap_edit_waypoint_dialog.cpp @@ -2,7 +2,7 @@ ****************************************************************************** * * @file opmap_edit_waypoint_dialog.cpp - * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @addtogroup GCSPlugins GCS Plugins * @{ * @addtogroup OPMapPlugin OpenPilot Map Plugin @@ -27,131 +27,265 @@ #include "opmap_edit_waypoint_dialog.h" #include "ui_opmap_edit_waypoint_dialog.h" - +#include "opmapcontrol/opmapcontrol.h" +#include "widgetdelegates.h" // ********************************************************************* // constructor -opmap_edit_waypoint_dialog::opmap_edit_waypoint_dialog(QWidget *parent) : - QDialog(parent, Qt::Dialog), +opmap_edit_waypoint_dialog::opmap_edit_waypoint_dialog(QWidget *parent,QAbstractItemModel * model,QItemSelectionModel * selection) : + QWidget(parent,Qt::Window),model(model),itemSelection(selection), ui(new Ui::opmap_edit_waypoint_dialog) -{ +{ ui->setupUi(this); + connect(ui->checkBoxLocked,SIGNAL(toggled(bool)),this,SLOT(enableEditWidgets(bool))); + connect(ui->cbMode,SIGNAL(currentIndexChanged(int)),this,SLOT(setupModeWidgets())); + connect(ui->cbCondition,SIGNAL(currentIndexChanged(int)),this,SLOT(setupConditionWidgets())); + connect(ui->pushButtonApply,SIGNAL(clicked()),this,SLOT(pushButtonApply_clicked())); + connect(ui->pushButtonCancel,SIGNAL(clicked()),this,SLOT(pushButtonCancel_clicked())); + MapDataDelegate::loadComboBox(ui->cbMode,flightDataModel::MODE); + MapDataDelegate::loadComboBox(ui->cbCondition,flightDataModel::CONDITION); + MapDataDelegate::loadComboBox(ui->cbCommand,flightDataModel::COMMAND); + mapper = new QDataWidgetMapper(this); - waypoint_item = NULL; + mapper->setItemDelegate(new MapDataDelegate(this)); + connect(mapper,SIGNAL(currentIndexChanged(int)),this,SLOT(currentIndexChanged(int))); + mapper->setModel(model); + mapper->setSubmitPolicy(QDataWidgetMapper::ManualSubmit); + mapper->addMapping(ui->checkBoxLocked,flightDataModel::LOCKED); + mapper->addMapping(ui->doubleSpinBoxLatitude,flightDataModel::LATPOSITION); + mapper->addMapping(ui->doubleSpinBoxLongitude,flightDataModel::LNGPOSITION); + mapper->addMapping(ui->doubleSpinBoxAltitude,flightDataModel::ALTITUDE); + mapper->addMapping(ui->lineEditDescription,flightDataModel::WPDESCRITPTION); + mapper->addMapping(ui->checkBoxRelative,flightDataModel::ISRELATIVE); + mapper->addMapping(ui->doubleSpinBoxBearing,flightDataModel::BEARELATIVE); + mapper->addMapping(ui->doubleSpinBoxVelocity,flightDataModel::VELOCITY); + mapper->addMapping(ui->doubleSpinBoxDistance,flightDataModel::DISRELATIVE); + mapper->addMapping(ui->doubleSpinBoxRelativeAltitude,flightDataModel::ALTITUDERELATIVE); + mapper->addMapping(ui->cbMode,flightDataModel::MODE); + mapper->addMapping(ui->dsb_modeParam1,flightDataModel::MODE_PARAMS0); + mapper->addMapping(ui->dsb_modeParam2,flightDataModel::MODE_PARAMS1); + mapper->addMapping(ui->dsb_modeParam3,flightDataModel::MODE_PARAMS2); + mapper->addMapping(ui->dsb_modeParam4,flightDataModel::MODE_PARAMS3); + + mapper->addMapping(ui->cbCondition,flightDataModel::CONDITION); + mapper->addMapping(ui->dsb_condParam1,flightDataModel::CONDITION_PARAMS0); + mapper->addMapping(ui->dsb_condParam2,flightDataModel::CONDITION_PARAMS1); + mapper->addMapping(ui->dsb_condParam3,flightDataModel::CONDITION_PARAMS2); + mapper->addMapping(ui->dsb_condParam4,flightDataModel::CONDITION_PARAMS0); + + mapper->addMapping(ui->cbCommand,flightDataModel::COMMAND); + mapper->addMapping(ui->sbJump,flightDataModel::JUMPDESTINATION); + mapper->addMapping(ui->sbError,flightDataModel::ERRORDESTINATION); + connect(itemSelection,SIGNAL(currentRowChanged(QModelIndex,QModelIndex)),this,SLOT(currentRowChanged(QModelIndex,QModelIndex))); +} +void opmap_edit_waypoint_dialog::currentIndexChanged(int index) +{ + ui->lbNumber->setText(QString::number(index+1)); + QModelIndex idx=mapper->model()->index(index,0); + if(index==itemSelection->currentIndex().row()) + return; + itemSelection->clear(); + itemSelection->setCurrentIndex(idx,QItemSelectionModel::Select | QItemSelectionModel::Rows); } -// destrutor opmap_edit_waypoint_dialog::~opmap_edit_waypoint_dialog() { delete ui; } -// ********************************************************************* - -void opmap_edit_waypoint_dialog::changeEvent(QEvent *e) -{ - QDialog::changeEvent(e); - switch (e->type()) { - case QEvent::LanguageChange: - ui->retranslateUi(this); - break; - default: - break; - } -} - void opmap_edit_waypoint_dialog::on_pushButtonOK_clicked() { - int res = saveSettings(); - if (res < 0) return; - - waypoint_item = NULL; - + mapper->submit(); close(); } -void opmap_edit_waypoint_dialog::on_pushButtonApply_clicked() +void opmap_edit_waypoint_dialog::setupModeWidgets() { - saveSettings(); -} - -void opmap_edit_waypoint_dialog::on_pushButtonRevert_clicked() -{ - ui->checkBoxLocked->setChecked(original_locked); - ui->spinBoxNumber->setValue(original_number); - ui->doubleSpinBoxLatitude->setValue(original_coord.Lat()); - ui->doubleSpinBoxLongitude->setValue(original_coord.Lng()); - ui->doubleSpinBoxAltitude->setValue(original_altitude); - ui->lineEditDescription->setText(original_description); - - saveSettings(); -} - -void opmap_edit_waypoint_dialog::on_pushButtonCancel_clicked() -{ - waypoint_item = NULL; - close(); -} - -// ********************************************************************* - -int opmap_edit_waypoint_dialog::saveSettings() -{ - // ******************** - // fetch the various ui item values - - bool locked = ui->checkBoxLocked->isChecked(); - - int number = ui->spinBoxNumber->value(); - if (number < 0) + MapDataDelegate::ModeOptions mode=(MapDataDelegate::ModeOptions)ui->cbMode->itemData(ui->cbMode->currentIndex()).toInt(); + switch(mode) { - return -1; + case MapDataDelegate::MODE_FLYENDPOINT: + case MapDataDelegate::MODE_FLYVECTOR: + case MapDataDelegate::MODE_FLYCIRCLERIGHT: + case MapDataDelegate::MODE_FLYCIRCLELEFT: + case MapDataDelegate::MODE_DRIVEENDPOINT: + case MapDataDelegate::MODE_DRIVEVECTOR: + case MapDataDelegate::MODE_DRIVECIRCLELEFT: + case MapDataDelegate::MODE_DRIVECIRCLERIGHT: + case MapDataDelegate::MODE_DISARMALARM: + ui->modeParam1->setVisible(false); + ui->modeParam2->setVisible(false); + ui->modeParam3->setVisible(false); + ui->modeParam4->setVisible(false); + ui->dsb_modeParam1->setVisible(false); + ui->dsb_modeParam2->setVisible(false); + ui->dsb_modeParam3->setVisible(false); + ui->dsb_modeParam4->setVisible(false); + break; + case MapDataDelegate::MODE_FIXEDATTITUDE: + ui->modeParam1->setText("pitch"); + ui->modeParam2->setText("roll"); + ui->modeParam3->setText("yaw"); + ui->modeParam4->setText("throttle"); + ui->modeParam1->setVisible(true); + ui->modeParam2->setVisible(true); + ui->modeParam3->setVisible(true); + ui->modeParam4->setVisible(true); + ui->dsb_modeParam1->setVisible(true); + ui->dsb_modeParam2->setVisible(true); + ui->dsb_modeParam3->setVisible(true); + ui->dsb_modeParam4->setVisible(true); + break; + case MapDataDelegate::MODE_SETACCESSORY: + ui->modeParam1->setText("Acc.channel"); + ui->modeParam2->setText("Value"); + ui->modeParam1->setVisible(true); + ui->modeParam2->setVisible(true); + ui->modeParam3->setVisible(false); + ui->modeParam4->setVisible(false); + ui->dsb_modeParam1->setVisible(true); + ui->dsb_modeParam2->setVisible(true); + ui->dsb_modeParam3->setVisible(false); + ui->dsb_modeParam4->setVisible(false); + break; } +} +void opmap_edit_waypoint_dialog::setupConditionWidgets() +{ + MapDataDelegate::EndConditionOptions mode=(MapDataDelegate::EndConditionOptions)ui->cbCondition->itemData(ui->cbCondition->currentIndex()).toInt(); + switch(mode) + { + case MapDataDelegate::ENDCONDITION_NONE: + case MapDataDelegate::ENDCONDITION_IMMEDIATE: + case MapDataDelegate::ENDCONDITION_PYTHONSCRIPT: + ui->condParam1->setVisible(false); + ui->condParam2->setVisible(false); + ui->condParam3->setVisible(false); + ui->condParam4->setVisible(false); + ui->dsb_condParam1->setVisible(false); + ui->dsb_condParam2->setVisible(false); + ui->dsb_condParam3->setVisible(false); + ui->dsb_condParam4->setVisible(false); + break; + case MapDataDelegate::ENDCONDITION_TIMEOUT: + ui->condParam1->setVisible(true); + ui->condParam2->setVisible(false); + ui->condParam3->setVisible(false); + ui->condParam4->setVisible(false); + ui->dsb_condParam1->setVisible(true); + ui->dsb_condParam2->setVisible(false); + ui->dsb_condParam3->setVisible(false); + ui->dsb_condParam4->setVisible(false); + ui->condParam1->setText("Timeout(ms)"); + break; + case MapDataDelegate::ENDCONDITION_DISTANCETOTARGET: + ui->condParam1->setVisible(true); + ui->condParam2->setVisible(true); + ui->condParam3->setVisible(false); + ui->condParam4->setVisible(false); + ui->dsb_condParam1->setVisible(true); + ui->dsb_condParam2->setVisible(true); + ui->dsb_condParam3->setVisible(false); + ui->dsb_condParam4->setVisible(false); + ui->condParam1->setText("Distance(m)"); + ui->condParam2->setText("Flag(0=2D,1=3D)");//FIXME + break; + case MapDataDelegate::ENDCONDITION_LEGREMAINING: + ui->condParam1->setVisible(true); + ui->condParam2->setVisible(false); + ui->condParam3->setVisible(false); + ui->condParam4->setVisible(false); + ui->dsb_condParam1->setVisible(true); + ui->dsb_condParam2->setVisible(false); + ui->dsb_condParam3->setVisible(false); + ui->dsb_condParam4->setVisible(false); + ui->condParam1->setText("Relative Distance(0=complete,1=just starting)"); + break; + case MapDataDelegate::ENDCONDITION_ABOVEALTITUDE: + ui->condParam1->setVisible(true); + ui->condParam2->setVisible(false); + ui->condParam3->setVisible(false); + ui->condParam4->setVisible(false); + ui->dsb_condParam1->setVisible(true); + ui->dsb_condParam2->setVisible(false); + ui->dsb_condParam3->setVisible(false); + ui->dsb_condParam4->setVisible(false); + ui->condParam1->setText("Altitude in meters (negative)"); + break; + case MapDataDelegate::ENDCONDITION_POINTINGTOWARDSNEXT: + ui->condParam1->setVisible(true); + ui->condParam2->setVisible(false); + ui->condParam3->setVisible(false); + ui->condParam4->setVisible(false); + ui->dsb_condParam1->setVisible(true); + ui->dsb_condParam2->setVisible(false); + ui->dsb_condParam3->setVisible(false); + ui->dsb_condParam4->setVisible(false); + ui->condParam1->setText("Degrees variation allowed"); + break; + default: - double latitude = ui->doubleSpinBoxLatitude->value(); - double longitude = ui->doubleSpinBoxLongitude->value(); - - double altitude = ui->doubleSpinBoxAltitude->value(); - - QString description = ui->lineEditDescription->displayText().simplified(); - - // ******************** - // transfer the settings to the actual waypoint - - waypoint_item->SetNumber(number); - waypoint_item->SetCoord(internals::PointLatLng(latitude, longitude)); - waypoint_item->SetAltitude(altitude); - waypoint_item->SetDescription(description); - waypoint_item->setFlag(QGraphicsItem::ItemIsMovable, !locked); - - // ******************** - - return 0; // all ok + break; + } } -// ********************************************************************* -// public functions - +void opmap_edit_waypoint_dialog::pushButtonCancel_clicked() +{ + mapper->revert(); + close(); +} +void opmap_edit_waypoint_dialog::pushButtonApply_clicked() +{ + mapper->submit(); +} void opmap_edit_waypoint_dialog::editWaypoint(mapcontrol::WayPointItem *waypoint_item) { if (!waypoint_item) return; - - this->waypoint_item = waypoint_item; - - original_number = this->waypoint_item->Number(); - original_locked = (this->waypoint_item->flags() & QGraphicsItem::ItemIsMovable) == 0; - original_coord = this->waypoint_item->Coord(); - original_altitude = this->waypoint_item->Altitude(); - original_description = this->waypoint_item->Description().simplified(); - - ui->checkBoxLocked->setChecked(original_locked); - ui->spinBoxNumber->setValue(original_number); - ui->doubleSpinBoxLatitude->setValue(original_coord.Lat()); - ui->doubleSpinBoxLongitude->setValue(original_coord.Lng()); - ui->doubleSpinBoxAltitude->setValue(original_altitude); - ui->lineEditDescription->setText(original_description); - - show(); + if(!isVisible()) + show(); + if(isMinimized()) + showNormal(); + if(!isActiveWindow()) + activateWindow(); + raise(); + setFocus(Qt::OtherFocusReason); + mapper->setCurrentIndex(waypoint_item->Number()); } -// ********************************************************************* +void opmap_edit_waypoint_dialog::on_pushButton_clicked() +{ + mapper->toPrevious(); +} + +void opmap_edit_waypoint_dialog::on_pushButton_2_clicked() +{ + mapper->toNext(); +} + +void opmap_edit_waypoint_dialog::enableEditWidgets(bool value) +{ + QWidget * w; + foreach(QWidget * obj,this->findChildren()) + { + w=qobject_cast(obj); + if(w) + w->setEnabled(!value); + w=qobject_cast(obj); + if(w) + w->setEnabled(!value); + w=qobject_cast(obj); + if(w) + w->setEnabled(!value); + w=qobject_cast(obj); + if(w && w!=ui->checkBoxLocked) + w->setEnabled(!value); + w=qobject_cast(obj); + if(w) + w->setEnabled(!value); + } +} + +void opmap_edit_waypoint_dialog::currentRowChanged(QModelIndex current, QModelIndex previous) +{ + mapper->setCurrentIndex(current.row()); +} diff --git a/ground/openpilotgcs/src/plugins/opmap/opmap_edit_waypoint_dialog.h b/ground/openpilotgcs/src/plugins/opmap/opmap_edit_waypoint_dialog.h index 062590fdd..2219de69e 100644 --- a/ground/openpilotgcs/src/plugins/opmap/opmap_edit_waypoint_dialog.h +++ b/ground/openpilotgcs/src/plugins/opmap/opmap_edit_waypoint_dialog.h @@ -1,8 +1,8 @@ /** ****************************************************************************** * - * @file opmap_edit_waypoint_dialog.cpp - * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. + * @file opmap_edit_waypoint_dialog.h + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @addtogroup GCSPlugins GCS Plugins * @{ * @addtogroup OPMapPlugin OpenPilot Map Plugin @@ -29,18 +29,19 @@ #define OPMAP_EDIT_WAYPOINT_DIALOG_H #include - +#include #include "opmapcontrol/opmapcontrol.h" - +#include "flightdatamodel.h" namespace Ui { class opmap_edit_waypoint_dialog; } +using namespace mapcontrol; -class opmap_edit_waypoint_dialog : public QDialog +class opmap_edit_waypoint_dialog : public QWidget { Q_OBJECT public: - opmap_edit_waypoint_dialog(QWidget *parent = 0); + opmap_edit_waypoint_dialog(QWidget *parent,QAbstractItemModel * model,QItemSelectionModel * selection); ~opmap_edit_waypoint_dialog(); /** @@ -50,29 +51,24 @@ public: */ void editWaypoint(mapcontrol::WayPointItem *waypoint_item); -protected: - void changeEvent(QEvent *e); - private: Ui::opmap_edit_waypoint_dialog *ui; - - int original_number; - bool original_locked; - internals::PointLatLng original_coord; - double original_altitude; - QString original_description; - - mapcontrol::WayPointItem *waypoint_item; - - int saveSettings(); - + QDataWidgetMapper *mapper; + QAbstractItemModel * model; + QItemSelectionModel * itemSelection; private slots: private slots: - void on_pushButtonCancel_clicked(); - void on_pushButtonRevert_clicked(); - void on_pushButtonApply_clicked(); + void currentIndexChanged(int index); + void setupModeWidgets(); + void setupConditionWidgets(); + void pushButtonCancel_clicked(); void on_pushButtonOK_clicked(); + void pushButtonApply_clicked(); + void on_pushButton_clicked(); + void on_pushButton_2_clicked(); + void enableEditWidgets(bool); + void currentRowChanged(QModelIndex,QModelIndex); }; #endif // OPMAP_EDIT_WAYPOINT_DIALOG_H diff --git a/ground/openpilotgcs/src/plugins/opmap/opmap_edit_waypoint_dialog.ui b/ground/openpilotgcs/src/plugins/opmap/opmap_edit_waypoint_dialog.ui index 62d228782..13ae47eba 100644 --- a/ground/openpilotgcs/src/plugins/opmap/opmap_edit_waypoint_dialog.ui +++ b/ground/openpilotgcs/src/plugins/opmap/opmap_edit_waypoint_dialog.ui @@ -1,36 +1,27 @@ opmap_edit_waypoint_dialog - + + + false + - Qt::ApplicationModal + Qt::NonModal 0 0 - 500 - 187 + 606 + 420 - + 0 0 - - - 500 - 187 - - - - - 500 - 187 - - OpenPilot GCS Edit Waypoint @@ -38,179 +29,755 @@ :/core/images/openpilot_logo_128.png:/core/images/openpilot_logo_128.png - - true - - - - - - - 0 - 0 - - - - Number - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - - 0 - 0 - - - - Latitude - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - - 0 - 0 - - - - Longitude - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - - 0 - 0 - - - - Altitude - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - meters - - - - - - - - 0 - 0 - - - - Description - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - - - - Qt::RightToLeft - - - Locked - - - - - - - 200 - - - - - - - - 0 - 0 - - - - 7 - - - -90.000000000000000 - - - 90.000000000000000 - - - - - - - 7 - - - -180.000000000000000 - - - 180.000000000000000 - - - - - - - -5000.000000000000000 - - - 5000.000000000000000 - - - - - - - degrees - - - - - - - degrees - - - - + + + + 0 + 0 + + + + 0 + + + + Position + + + + + + + + + 0 + 0 + + + + Latitude + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + true + + + + 0 + 0 + + + + Longitude + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 0 + + + + Description + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + + 0 + 0 + + + + 5 + + + -90.000000000000000 + + + 90.000000000000000 + + + + + + + 5 + + + -180.000000000000000 + + + 180.000000000000000 + + + + + + + degrees + + + + + + + degrees + + + + + + + + 0 + 0 + + + + Relative to Home + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + meters + + + + + + + degrees + + + + + + + Bearing + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + 2 + + + 360.000000000000000 + + + + + + + + 0 + 0 + + + + Distance + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Qt::LeftToRight + + + Locked + + + + + + + Number + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + 0 + + + + + + + + + + + + + + Velocity + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + 999999999.000000000000000 + + + + + + + + 0 + 0 + + + + Altitude + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + meters + + + + + + + Relative altitude + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + -999999999.000000000000000 + + + 999999999.000000000000000 + + + + + + + meters + + + + + + + 2 + + + 999999999.000000000000000 + + + + + + + -5000.000000000000000 + + + 5000.000000000000000 + + + + + + + m/s + + + + + + + + + + Mode + + + + + + + + + 0 + 0 + + + + + 100 + 0 + + + + Qt::LeftToRight + + + Mode + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + 999999999.000000000000000 + + + + + + + + 0 + 0 + + + + Qt::LeftToRight + + + param1 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 0 + + + + Qt::LeftToRight + + + param2 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 0 + + + + Qt::LeftToRight + + + param3 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 0 + + + + Qt::LeftToRight + + + param4 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + 999999999.000000000000000 + + + + + + + 999999999.000000000000000 + + + + + + + 999999999.000000000000000 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + End condition + + + + + + QLayout::SetDefaultConstraint + + + + + + 0 + 0 + + + + + 100 + 0 + + + + Qt::LeftToRight + + + Condition + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + 999999999.000000000000000 + + + + + + + + 0 + 0 + + + + Qt::LeftToRight + + + param1 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 0 + + + + Qt::LeftToRight + + + param2 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 0 + + + + Qt::LeftToRight + + + param3 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 0 + + + + Qt::LeftToRight + + + param4 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + 999999999.000000000000000 + + + + + + + 999999999.000000000000000 + + + + + + + 999999999.000000000000000 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + Command + + + + + + QLayout::SetDefaultConstraint + + + + + + 0 + 0 + + + + + 100 + 0 + + + + Qt::LeftToRight + + + Command + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + + 0 + 0 + + + + Qt::LeftToRight + + + Jump Destination + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 0 + + + + Qt::LeftToRight + + + Error Destination + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + + + + + + + Previous + + + + + + + Next + + + @@ -238,13 +805,6 @@ - - - - Revert - - - diff --git a/ground/openpilotgcs/src/plugins/opmap/opmap_statusbar_widget.cpp b/ground/openpilotgcs/src/plugins/opmap/opmap_statusbar_widget.cpp index 4a8740794..a4135467d 100644 --- a/ground/openpilotgcs/src/plugins/opmap/opmap_statusbar_widget.cpp +++ b/ground/openpilotgcs/src/plugins/opmap/opmap_statusbar_widget.cpp @@ -2,7 +2,7 @@ ****************************************************************************** * * @file opmap_statusbar_widget.cpp - * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @addtogroup GCSPlugins GCS Plugins * @{ * @addtogroup OPMapPlugin OpenPilot Map Plugin diff --git a/ground/openpilotgcs/src/plugins/opmap/opmap_statusbar_widget.h b/ground/openpilotgcs/src/plugins/opmap/opmap_statusbar_widget.h index ecb2d6206..705961b48 100644 --- a/ground/openpilotgcs/src/plugins/opmap/opmap_statusbar_widget.h +++ b/ground/openpilotgcs/src/plugins/opmap/opmap_statusbar_widget.h @@ -2,7 +2,7 @@ ****************************************************************************** * * @file opmap_statusbar_widget.h - * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @addtogroup GCSPlugins GCS Plugins * @{ * @addtogroup OPMapPlugin OpenPilot Map Plugin diff --git a/ground/openpilotgcs/src/plugins/opmap/opmap_waypointeditor_dialog.cpp b/ground/openpilotgcs/src/plugins/opmap/opmap_waypointeditor_dialog.cpp deleted file mode 100644 index 64ce36c23..000000000 --- a/ground/openpilotgcs/src/plugins/opmap/opmap_waypointeditor_dialog.cpp +++ /dev/null @@ -1,184 +0,0 @@ -/** - ****************************************************************************** - * - * @file opmap_waypointeditor_dialog.cpp - * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. - * @addtogroup GCSPlugins GCS Plugins - * @{ - * @addtogroup OPMapPlugin OpenPilot Map Plugin - * @{ - * @brief The OpenPilot Map plugin - *****************************************************************************/ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include -#include - -#include "opmap_waypointeditor_dialog.h" -#include "ui_opmap_waypointeditor_dialog.h" - -#include "extensionsystem/pluginmanager.h" - -// *************************************************************** -// Waypoint object - -WaypointItem::WaypointItem(QString name, double latitude, double longitude, double height, int time, int hold) : - waypoint_name(name), - latitude_degress(latitude), - longitude_degress(longitude), - height_feet(height), - time_seconds(time), - hold_seconds(hold) -{ - setToolTip(waypoint_name); - setFlag(QGraphicsItem::ItemIsMovable, true); - setFlag(QGraphicsItem::ItemIsSelectable, true); - setFlag(QGraphicsItem::ItemSendsScenePositionChanges, true); - - pixmap.load(QString::fromUtf8(":/opmap/images/waypoint_marker1.png")); -} - -QRectF WaypointItem::boundingRect() const -{ -// return QRectF(-6, -10, 12, 20); - return QRectF(-pixmap.width() / 2, -pixmap.height(), pixmap.width(), pixmap.height()); -} -/* -QPainterPath WaypointItem::shape() const -{ - QPainterPath path; -// path.addEllipse(QPointF(0, 0), 6, 10); - path.addRect(pixmap.rect()); - return path; -} -*/ - void WaypointItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) -{ -// painter->setPen(Qt::black); -// painter->setBrush(QColor(255, 0, 0, 128)); -// painter->drawEllipse(QPointF(0, 0), 6, 10); - - painter->drawPixmap(-pixmap.width() / 2, -pixmap.height(), pixmap); -} - -void WaypointItem::setPixmap(QPixmap pixmap) -{ - this->pixmap = pixmap.copy(pixmap.rect()); -} - -// *************************************************************** -// Scene object - -OurScene::OurScene(QObject *parent) : QGraphicsScene(parent) -{ - movingItem = 0; -} - -void OurScene::mousePressEvent(QGraphicsSceneMouseEvent *event) -{ - QPointF mousePos(event->buttonDownScenePos(Qt::LeftButton).x(), event->buttonDownScenePos(Qt::LeftButton).y()); - - movingItem = itemAt(mousePos.x(), mousePos.y()); - - if (movingItem != 0 && event->button() == Qt::LeftButton) - { - oldPos = movingItem->pos(); - } - - clearSelection(); - - QGraphicsScene::mousePressEvent(event); - } - - void OurScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) - { - if (movingItem != 0 && event->button() == Qt::LeftButton) - { - if (oldPos != movingItem->pos()) - emit itemMoved(qgraphicsitem_cast(movingItem), oldPos); - - movingItem = 0; - } - - QGraphicsScene::mouseReleaseEvent(event); - } - -// *************************************************************** -// main dialogue - -opmap_waypointeditor_dialog::opmap_waypointeditor_dialog(QWidget *parent) : - QDialog(parent), - ui(new Ui::opmap_waypointeditor_dialog) -{ - ui->setupUi(this); - setWindowFlags(Qt::Dialog); - - view = ui->graphicsViewWaypointHeightAndTimeline; - - scene = new OurScene(); - scene->setSceneRect(QRect(0, 0, 500, 500)); - view->setScene(scene); - - waypoint_pixmap1.load(QString::fromUtf8(":/opmap/images/waypoint_marker1.png")); - waypoint_pixmap2.load(QString::fromUtf8(":/opmap/images/waypoint_marker2.png")); - - undoStack = new QUndoStack(); - - connect(scene, SIGNAL(itemMoved(WaypointItem *, const QPointF &)), this, SLOT(itemMoved(WaypointItem *, const QPointF &))); - - // ***** - // test - - WaypointItem *waypoint1 = new WaypointItem(tr("Waypoint 1"), 0, 0, 10, 5, 10); - waypoint1->setPos(scene->width() / 2, scene->height() / 2); - scene->addItem(waypoint1); - - WaypointItem *waypoint2 = new WaypointItem(tr("Waypoint 2"), 0, 0, 50, 8, 5); - waypoint2->setPos(scene->width() / 2 + 30, scene->height() / 2); - scene->addItem(waypoint2); - - WaypointItem *waypoint3 = new WaypointItem(tr("Waypoint 3"), 0, 0, 100, 8, 5); - waypoint3->setPixmap(waypoint_pixmap2); - waypoint3->setPos(scene->width() / 2 + 60, scene->height() / 2); - scene->addItem(waypoint3); - - // ***** -} - -opmap_waypointeditor_dialog::~opmap_waypointeditor_dialog() -{ - delete ui; -} - -void opmap_waypointeditor_dialog::changeEvent(QEvent *e) -{ - QDialog::changeEvent(e); - switch (e->type()) { - case QEvent::LanguageChange: - ui->retranslateUi(this); - break; - default: - break; - } -} - -void opmap_waypointeditor_dialog::itemMoved(WaypointItem *movedItem, const QPointF &oldPosition) -{ -// undoStack->push(new MoveCommand(movedItem, oldPosition)); -} - -// *************************************************************** diff --git a/ground/openpilotgcs/src/plugins/opmap/opmap_waypointeditor_dialog.h b/ground/openpilotgcs/src/plugins/opmap/opmap_waypointeditor_dialog.h deleted file mode 100644 index fd1ae72ea..000000000 --- a/ground/openpilotgcs/src/plugins/opmap/opmap_waypointeditor_dialog.h +++ /dev/null @@ -1,130 +0,0 @@ -/** - ****************************************************************************** - * - * @file opmap_waypointeditor_dialog.h - * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. - * @addtogroup GCSPlugins GCS Plugins - * @{ - * @addtogroup OPMapPlugin OpenPilot Map Plugin - * @{ - * @brief The OpenPilot Map plugin - *****************************************************************************/ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef OPMAP_WAYPOINTEDITOR_DIALOG_H -#define OPMAP_WAYPOINTEDITOR_DIALOG_H - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "uavobjectmanager.h" -#include "positionactual.h" - -namespace Ui { - class opmap_waypointeditor_dialog; -} - -// *************************************************************** -// Waypoint object - -class WaypointItem : public QObject, public QGraphicsItem -{ - Q_OBJECT - Q_INTERFACES(QGraphicsItem) - - public: - WaypointItem(QString name = "", double latitude = 0, double longitude = 0, double height_feet = 0, int time_seconds = 0, int hold_seconds = 0); - - void setPixmap(QPixmap pixmap); - - QString waypoint_name; - double latitude_degress; - double longitude_degress; - double height_feet; - int time_seconds; - int hold_seconds; - - QPixmap pixmap; - - protected: - QRectF boundingRect() const; -// QPainterPath shape() const; - void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); -// void timerEvent(QTimerEvent *event); - - private: - -}; - -// *************************************************************** - -class OurScene : public QGraphicsScene - { - Q_OBJECT - - public: - OurScene(QObject *parent = 0); - - signals: - void itemMoved(WaypointItem *movedItem, const QPointF &movedFromPosition); - - protected: - void mousePressEvent(QGraphicsSceneMouseEvent *event); - void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); - - private: - QGraphicsItem *movingItem; - QPointF oldPos; - }; - -// *************************************************************** -// main dialog widget - -class opmap_waypointeditor_dialog : public QDialog -{ - Q_OBJECT -public: - opmap_waypointeditor_dialog(QWidget *parent = 0); - ~opmap_waypointeditor_dialog(); - - public slots: - void itemMoved(WaypointItem *movedDiagram, const QPointF &moveStartPosition); - -protected: - void changeEvent(QEvent *e); - -private: - QPixmap waypoint_pixmap1; - QPixmap waypoint_pixmap2; - - QGraphicsView *view; - QGraphicsScene *scene; - - QUndoStack *undoStack; - - Ui::opmap_waypointeditor_dialog *ui; -}; - -// *************************************************************** - -#endif // OPMAP_WAYPOINTEDITOR_DIALOG_H diff --git a/ground/openpilotgcs/src/plugins/opmap/opmap_waypointeditor_dialog.ui b/ground/openpilotgcs/src/plugins/opmap/opmap_waypointeditor_dialog.ui deleted file mode 100644 index ea9b65189..000000000 --- a/ground/openpilotgcs/src/plugins/opmap/opmap_waypointeditor_dialog.ui +++ /dev/null @@ -1,248 +0,0 @@ - - - opmap_waypointeditor_dialog - - - - 0 - 0 - 561 - 511 - - - - - 0 - 0 - - - - - 300 - 0 - - - - OpenPilot GCS Waypoint Editor - - - - :/core/images/openpilot_logo_128.png:/core/images/openpilot_logo_128.png - - - true - - - - - - - - QSplitter::handle { -/* image: url(images/splitter.png); */ - background-color: qlineargradient(spread:pad, x1:0.5, y1:0, x2:0.5, y2:1, stop:0 rgba(255, 255, 255, 80), stop:1 rgba(0, 0, 0, 80)); -} - -QSplitter::handle:horizontal { - height: 5px; -} - -QSplitter::handle:vertical { - width: 5px; -} - - - QFrame::NoFrame - - - Qt::Vertical - - - true - - - 5 - - - false - - - - - 0 - 130 - - - - Waypoints - - - true - - - - 0 - - - 0 - - - - - - 0 - 0 - - - - - 0 - 50 - - - - true - - - false - - - false - - - - Num - - - - - Locked - - - - - Latitude - - - - - Longitude - - - - - Altitude - - - - - Time - - - - - Hold Time - - - - - - - - - Height and Timeline - - - true - - - - 0 - - - 0 - - - - - - 0 - 0 - - - - - 0 - 50 - - - - background-color: rgb(191, 191, 191); - - - QFrame::Sunken - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - QPainter::Antialiasing|QPainter::HighQualityAntialiasing|QPainter::TextAntialiasing - - - - - - - - - - - Qt::Horizontal - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - - - - - - - - - - - buttonBox - accepted() - opmap_waypointeditor_dialog - accept() - - - 248 - 254 - - - 157 - 274 - - - - - buttonBox - rejected() - opmap_waypointeditor_dialog - reject() - - - 316 - 260 - - - 286 - 274 - - - - - diff --git a/ground/openpilotgcs/src/plugins/opmap/opmap_widget.ui b/ground/openpilotgcs/src/plugins/opmap/opmap_widget.ui index b42b7fe0a..ece39e353 100644 --- a/ground/openpilotgcs/src/plugins/opmap/opmap_widget.ui +++ b/ground/openpilotgcs/src/plugins/opmap/opmap_widget.ui @@ -49,7 +49,7 @@ 16777215 - 16777215 + 40 @@ -357,6 +357,32 @@ border-radius: 2px; + + + + + 8 + + + + Go To Place: + + + + + + + + + + ... + + + + :/opmap/images/waypoint.png:/opmap/images/waypoint.png + + + @@ -370,6 +396,18 @@ border-radius: 2px; + + + + + 8 + + + + + + + diff --git a/ground/openpilotgcs/src/plugins/opmap/opmap_zoom_slider_widget.cpp b/ground/openpilotgcs/src/plugins/opmap/opmap_zoom_slider_widget.cpp index e73b054ed..dcbdf6a06 100644 --- a/ground/openpilotgcs/src/plugins/opmap/opmap_zoom_slider_widget.cpp +++ b/ground/openpilotgcs/src/plugins/opmap/opmap_zoom_slider_widget.cpp @@ -2,7 +2,7 @@ ****************************************************************************** * * @file opmap_zoom_slider_widget.cpp - * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @addtogroup GCSPlugins GCS Plugins * @{ * @addtogroup OPMapPlugin OpenPilot Map Plugin diff --git a/ground/openpilotgcs/src/plugins/opmap/opmap_zoom_slider_widget.h b/ground/openpilotgcs/src/plugins/opmap/opmap_zoom_slider_widget.h index 83087413e..41b9ff10d 100644 --- a/ground/openpilotgcs/src/plugins/opmap/opmap_zoom_slider_widget.h +++ b/ground/openpilotgcs/src/plugins/opmap/opmap_zoom_slider_widget.h @@ -2,7 +2,7 @@ ****************************************************************************** * * @file opmap_zoom_slider_widget.h - * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @addtogroup GCSPlugins GCS Plugins * @{ * @addtogroup OPMapPlugin OpenPilot Map Plugin diff --git a/ground/openpilotgcs/src/plugins/opmap/opmapgadget.cpp b/ground/openpilotgcs/src/plugins/opmap/opmapgadget.cpp index be2a4e476..a0a92cdc8 100644 --- a/ground/openpilotgcs/src/plugins/opmap/opmapgadget.cpp +++ b/ground/openpilotgcs/src/plugins/opmap/opmapgadget.cpp @@ -2,7 +2,7 @@ ****************************************************************************** * * @file opmapgadget.cpp - * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @addtogroup GCSPlugins GCS Plugins * @{ * @addtogroup OPMapPlugin OpenPilot Map Plugin @@ -26,31 +26,50 @@ */ #include "opmapgadget.h" #include "opmapgadgetwidget.h" -#include "opmapgadgetconfiguration.h" OPMapGadget::OPMapGadget(QString classId, OPMapGadgetWidget *widget, QWidget *parent) : IUAVGadget(classId, parent), - m_widget(widget) + m_widget(widget),m_config(NULL) { + connect(m_widget,SIGNAL(defaultLocationAndZoomChanged(double,double,double)),this,SLOT(saveDefaultLocation(double,double,double))); + connect(m_widget,SIGNAL(overlayOpacityChanged(qreal)),this,SLOT(saveOpacity(qreal))); } OPMapGadget::~OPMapGadget() { delete m_widget; } - -void OPMapGadget::loadConfiguration(IUAVGadgetConfiguration *config) +void OPMapGadget::saveDefaultLocation(double lng,double lat,double zoom) { - OPMapGadgetConfiguration *m = qobject_cast(config); - - m_widget->setMapProvider(m->mapProvider()); - m_widget->setZoom(m->zoom()); - m_widget->setPosition(QPointF(m->longitude(), m->latitude())); - m_widget->setUseOpenGL(m->useOpenGL()); - m_widget->setShowTileGridLines(m->showTileGridLines()); - m_widget->setAccessMode(m->accessMode()); - m_widget->setUseMemoryCache(m->useMemoryCache()); - m_widget->setCacheLocation(m->cacheLocation()); - m_widget->SetUavPic(m->uavSymbol()); + if(m_config) + { + m_config->setLatitude(lat); + m_config->setLongitude(lng); + m_config->setZoom(zoom); + m_config->saveConfig(); + } +} + +void OPMapGadget::saveOpacity(qreal value) +{ + if(m_config) + { + m_config->setOpacity(value); + } +} +void OPMapGadget::loadConfiguration(IUAVGadgetConfiguration *config) +{ + m_config = qobject_cast(config); + m_widget->setMapProvider(m_config->mapProvider()); + m_widget->setUseOpenGL(m_config->useOpenGL()); + m_widget->setShowTileGridLines(m_config->showTileGridLines()); + m_widget->setAccessMode(m_config->accessMode()); + m_widget->setUseMemoryCache(m_config->useMemoryCache()); + m_widget->setCacheLocation(m_config->cacheLocation()); + m_widget->SetUavPic(m_config->uavSymbol()); + m_widget->setZoom(m_config->zoom()); + m_widget->setPosition(QPointF(m_config->longitude(), m_config->latitude())); + m_widget->setHomePosition(QPointF(m_config->longitude(), m_config->latitude())); + m_widget->setOverlayOpacity(m_config->opacity()); } diff --git a/ground/openpilotgcs/src/plugins/opmap/opmapgadget.h b/ground/openpilotgcs/src/plugins/opmap/opmapgadget.h index 030caf986..323e61e5e 100644 --- a/ground/openpilotgcs/src/plugins/opmap/opmapgadget.h +++ b/ground/openpilotgcs/src/plugins/opmap/opmapgadget.h @@ -2,7 +2,7 @@ ****************************************************************************** * * @file opmapgadget.h - * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @addtogroup GCSPlugins GCS Plugins * @{ * @addtogroup OPMapPlugin OpenPilot Map Plugin @@ -30,9 +30,9 @@ #include #include "opmapgadgetwidget.h" +#include "opmapgadgetconfiguration.h" class IUAVGadget; -//class QList; class QWidget; class QString; class OPMapGadgetWidget; @@ -47,10 +47,13 @@ public: ~OPMapGadget(); QWidget *widget() { return m_widget; } - void loadConfiguration(IUAVGadgetConfiguration* config); - + void loadConfiguration(IUAVGadgetConfiguration* m_config); private: OPMapGadgetWidget *m_widget; + OPMapGadgetConfiguration *m_config; +private slots: + void saveOpacity(qreal value); + void saveDefaultLocation(double lng, double lat, double zoom); }; diff --git a/ground/openpilotgcs/src/plugins/opmap/opmapgadgetconfiguration.cpp b/ground/openpilotgcs/src/plugins/opmap/opmapgadgetconfiguration.cpp index 67d1d1f98..b9dec0c97 100644 --- a/ground/openpilotgcs/src/plugins/opmap/opmapgadgetconfiguration.cpp +++ b/ground/openpilotgcs/src/plugins/opmap/opmapgadgetconfiguration.cpp @@ -2,7 +2,7 @@ ****************************************************************************** * * @file opmapgadgetconfiguration.cpp - * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @addtogroup GCSPlugins GCS Plugins * @{ * @addtogroup OPMapPlugin OpenPilot Map Plugin @@ -41,7 +41,9 @@ OPMapGadgetConfiguration::OPMapGadgetConfiguration(QString classId, QSettings* m_useMemoryCache(true), m_cacheLocation(Utils::PathUtils().GetStoragePath() + "mapscache" + QDir::separator()), m_uavSymbol(QString::fromUtf8(":/uavs/images/mapquad.png")), - m_maxUpdateRate(2000) // ms + m_maxUpdateRate(2000), // ms + m_settings(qSettings), + m_opacity(1) { //if a saved configuration exists load it @@ -59,6 +61,8 @@ OPMapGadgetConfiguration::OPMapGadgetConfiguration(QString classId, QSettings* QString uavSymbol=qSettings->value("uavSymbol").toString(); int max_update_rate = qSettings->value("maxUpdateRate").toInt(); + m_opacity=qSettings->value("overlayOpacity",1).toReal(); + if (!mapProvider.isEmpty()) m_mapProvider = mapProvider; m_defaultZoom = zoom; m_defaultLatitude = latitude; @@ -94,10 +98,26 @@ IUAVGadgetConfiguration * OPMapGadgetConfiguration::clone() m->m_cacheLocation = m_cacheLocation; m->m_uavSymbol = m_uavSymbol; m->m_maxUpdateRate = m_maxUpdateRate; + m->m_opacity=m_opacity; return m; } - +void OPMapGadgetConfiguration::saveConfig() const { + if(!m_settings) + return; + m_settings->setValue("mapProvider", m_mapProvider); + m_settings->setValue("defaultZoom", m_defaultZoom); + m_settings->setValue("defaultLatitude", m_defaultLatitude); + m_settings->setValue("defaultLongitude", m_defaultLongitude); + m_settings->setValue("useOpenGL", m_useOpenGL); + m_settings->setValue("showTileGridLines", m_showTileGridLines); + m_settings->setValue("accessMode", m_accessMode); + m_settings->setValue("useMemoryCache", m_useMemoryCache); + m_settings->setValue("uavSymbol", m_uavSymbol); + m_settings->setValue("cacheLocation", Utils::PathUtils().RemoveStoragePath(m_cacheLocation)); + m_settings->setValue("maxUpdateRate", m_maxUpdateRate); + m_settings->setValue("overlayOpacity",m_opacity); +} void OPMapGadgetConfiguration::saveConfig(QSettings* qSettings) const { qSettings->setValue("mapProvider", m_mapProvider); qSettings->setValue("defaultZoom", m_defaultZoom); @@ -110,6 +130,7 @@ void OPMapGadgetConfiguration::saveConfig(QSettings* qSettings) const { qSettings->setValue("uavSymbol", m_uavSymbol); qSettings->setValue("cacheLocation", Utils::PathUtils().RemoveStoragePath(m_cacheLocation)); qSettings->setValue("maxUpdateRate", m_maxUpdateRate); + qSettings->setValue("overlayOpacity",m_opacity); } void OPMapGadgetConfiguration::setCacheLocation(QString cacheLocation){ m_cacheLocation = cacheLocation; diff --git a/ground/openpilotgcs/src/plugins/opmap/opmapgadgetconfiguration.h b/ground/openpilotgcs/src/plugins/opmap/opmapgadgetconfiguration.h index 1e630dc00..9a8a9bd75 100644 --- a/ground/openpilotgcs/src/plugins/opmap/opmapgadgetconfiguration.h +++ b/ground/openpilotgcs/src/plugins/opmap/opmapgadgetconfiguration.h @@ -2,7 +2,7 @@ ****************************************************************************** * * @file opmapgadgetconfiguration.h - * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @addtogroup GCSPlugins GCS Plugins * @{ * @addtogroup OPMapPlugin OpenPilot Map Plugin @@ -48,6 +48,7 @@ Q_PROPERTY(bool useMemoryCache READ useMemoryCache WRITE setUseMemoryCache) Q_PROPERTY(QString cacheLocation READ cacheLocation WRITE setCacheLocation) Q_PROPERTY(QString uavSymbol READ uavSymbol WRITE setUavSymbol) Q_PROPERTY(int maxUpdateRate READ maxUpdateRate WRITE setMaxUpdateRate) +Q_PROPERTY(qreal overlayOpacity READ opacity WRITE setOpacity) public: explicit OPMapGadgetConfiguration(QString classId, QSettings* qSettings = 0, QObject *parent = 0); @@ -65,12 +66,14 @@ public: bool useMemoryCache() const { return m_useMemoryCache; } QString cacheLocation() const { return m_cacheLocation; } QString uavSymbol() const { return m_uavSymbol; } - int maxUpdateRate() const { return m_maxUpdateRate; } - + int maxUpdateRate() const { return m_maxUpdateRate; } + qreal opacity() const { return m_opacity; } + void saveConfig() const; public slots: void setMapProvider(QString provider) { m_mapProvider = provider; } void setZoom(int zoom) { m_defaultZoom = zoom; } void setLatitude(double latitude) { m_defaultLatitude = latitude; } + void setOpacity(qreal value) { m_opacity = value; } void setLongitude(double longitude) { m_defaultLongitude = longitude; } void setUseOpenGL(bool useOpenGL) { m_useOpenGL = useOpenGL; } void setShowTileGridLines(bool showTileGridLines) { m_showTileGridLines = showTileGridLines; } @@ -92,6 +95,8 @@ private: QString m_cacheLocation; QString m_uavSymbol; int m_maxUpdateRate; + QSettings * m_settings; + qreal m_opacity; }; #endif // OPMAP_GADGETCONFIGURATION_H diff --git a/ground/openpilotgcs/src/plugins/opmap/opmapgadgetfactory.cpp b/ground/openpilotgcs/src/plugins/opmap/opmapgadgetfactory.cpp index 5a3908c89..fb4b73efa 100644 --- a/ground/openpilotgcs/src/plugins/opmap/opmapgadgetfactory.cpp +++ b/ground/openpilotgcs/src/plugins/opmap/opmapgadgetfactory.cpp @@ -2,7 +2,7 @@ ****************************************************************************** * * @file opmapgadgetfactory.cpp - * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @addtogroup GCSPlugins GCS Plugins * @{ * @addtogroup OPMapPlugin OpenPilot Map Plugin diff --git a/ground/openpilotgcs/src/plugins/opmap/opmapgadgetfactory.h b/ground/openpilotgcs/src/plugins/opmap/opmapgadgetfactory.h index 4caf96e84..138efcb90 100644 --- a/ground/openpilotgcs/src/plugins/opmap/opmapgadgetfactory.h +++ b/ground/openpilotgcs/src/plugins/opmap/opmapgadgetfactory.h @@ -2,7 +2,7 @@ ****************************************************************************** * * @file opmapgadgetfactory.h - * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @addtogroup GCSPlugins GCS Plugins * @{ * @addtogroup OPMapPlugin OpenPilot Map Plugin diff --git a/ground/openpilotgcs/src/plugins/opmap/opmapgadgetoptionspage.cpp b/ground/openpilotgcs/src/plugins/opmap/opmapgadgetoptionspage.cpp index 2136a24d0..92d676e10 100644 --- a/ground/openpilotgcs/src/plugins/opmap/opmapgadgetoptionspage.cpp +++ b/ground/openpilotgcs/src/plugins/opmap/opmapgadgetoptionspage.cpp @@ -2,7 +2,7 @@ ****************************************************************************** * * @file opmapgadgetoptionspage.cpp - * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @addtogroup GCSPlugins GCS Plugins * @{ * @addtogroup OPMapPlugin OpenPilot Map Plugin diff --git a/ground/openpilotgcs/src/plugins/opmap/opmapgadgetoptionspage.h b/ground/openpilotgcs/src/plugins/opmap/opmapgadgetoptionspage.h index 1deb13617..85a9433db 100644 --- a/ground/openpilotgcs/src/plugins/opmap/opmapgadgetoptionspage.h +++ b/ground/openpilotgcs/src/plugins/opmap/opmapgadgetoptionspage.h @@ -2,7 +2,7 @@ ****************************************************************************** * * @file opmapgadgetoptionspage.h - * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @addtogroup GCSPlugins GCS Plugins * @{ * @addtogroup OPMapPlugin OpenPilot Map Plugin diff --git a/ground/openpilotgcs/src/plugins/opmap/opmapgadgetwidget.cpp b/ground/openpilotgcs/src/plugins/opmap/opmapgadgetwidget.cpp index ebb489a13..4405d2b2e 100644 --- a/ground/openpilotgcs/src/plugins/opmap/opmapgadgetwidget.cpp +++ b/ground/openpilotgcs/src/plugins/opmap/opmapgadgetwidget.cpp @@ -48,9 +48,16 @@ #include "utils/worldmagmodel.h" #include "uavtalk/telemetrymanager.h" +#include "uavobject.h" +#include "uavobjectmanager.h" #include "positionactual.h" #include "homelocation.h" +#include "gpsposition.h" +#include "gyros.h" +#include "attitudeactual.h" +#include "positionactual.h" +#include "velocityactual.h" #define allow_manual_home_location_move @@ -73,12 +80,6 @@ const int max_update_rate_list[] = {100, 200, 500, 1000, 2000, 5000}; // ************************************************************************************* - -// ************************************************************************************* -// NOTE: go back to SVN REV 2137 and earlier to get back to experimental waypoint support. -// ************************************************************************************* - - // constructor OPMapGadgetWidget::OPMapGadgetWidget(QWidget *parent) : QWidget(parent) { @@ -134,21 +135,6 @@ OPMapGadgetWidget::OPMapGadgetWidget(QWidget *parent) : QWidget(parent) m_home_position.altitude = altitude; m_home_position.locked = false; - // ************** - // default magic waypoint params - - m_magic_waypoint.map_wp_item = NULL; - m_magic_waypoint.coord = m_home_position.coord; - m_magic_waypoint.altitude = altitude; - m_magic_waypoint.description = "Magic waypoint"; - m_magic_waypoint.locked = false; - m_magic_waypoint.time_seconds = 0; - m_magic_waypoint.hold_time_seconds = 0; - - // Connect to the path compiler to get updates from the waypoints - pathCompiler = new PathCompiler(this); - connect(pathCompiler,SIGNAL(visualizationChanged(QList)), - this, SLOT(doVisualizationChanged(QList))); // ************** // create the widget that holds the user controls and the map @@ -179,19 +165,21 @@ OPMapGadgetWidget::OPMapGadgetWidget(QWidget *parent) : QWidget(parent) m_map->Home->SetSafeArea(safe_area_radius_list[0]); // set radius (meters) m_map->Home->SetShowSafeArea(true); // show the safe area + m_map->Home->SetToggleRefresh(true); + if(m_map->Home) + connect(m_map->Home,SIGNAL(homedoubleclick(HomeItem*)),this,SLOT(onHomeDoubleClick(HomeItem*))); m_map->UAV->SetTrailTime(uav_trail_time_list[0]); // seconds m_map->UAV->SetTrailDistance(uav_trail_distance_list[1]); // meters m_map->UAV->SetTrailType(UAVTrailType::ByTimeElapsed); - // m_map->UAV->SetTrailType(UAVTrailType::ByDistance); - - m_map->GPS->SetTrailTime(uav_trail_time_list[0]); // seconds - m_map->GPS->SetTrailDistance(uav_trail_distance_list[1]); // meters - - m_map->GPS->SetTrailType(UAVTrailType::ByTimeElapsed); - // m_map->GPS->SetTrailType(UAVTrailType::ByDistance); + if(m_map->GPS) + { + m_map->GPS->SetTrailTime(uav_trail_time_list[0]); // seconds + m_map->GPS->SetTrailDistance(uav_trail_distance_list[1]); // meters + m_map->GPS->SetTrailType(UAVTrailType::ByTimeElapsed); + } // ************** setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); @@ -202,11 +190,6 @@ OPMapGadgetWidget::OPMapGadgetWidget(QWidget *parent) : QWidget(parent) layout->addWidget(m_map); m_widget->mapWidget->setLayout(layout); - // ************** - // set the user control options - - // TODO: this switch does not make sense, does it?? - switch (m_map_mode) { case Normal_MapMode: @@ -234,58 +217,30 @@ OPMapGadgetWidget::OPMapGadgetWidget(QWidget *parent) : QWidget(parent) m_widget->labelMousePos->setText("---"); m_widget->labelMapZoom->setText("---"); - - // Splitter is not used at the moment: - // m_widget->splitter->setCollapsible(1, false); - - // set the size of the collapsable widgets - //QList m_SizeList; - //m_SizeList << 0 << 0 << 0; - //m_widget->splitter->setSizes(m_SizeList); - m_widget->progressBarMap->setMaximum(1); - /* - #if defined(Q_OS_MAC) - #elif defined(Q_OS_WIN) - m_widget->comboBoxFindPlace->clear(); - loadComboBoxLines(m_widget->comboBoxFindPlace, QCoreApplication::applicationDirPath() + "/opmap_find_place_history.txt"); - m_widget->comboBoxFindPlace->setCurrentIndex(-1); - #else - #endif -*/ - - - // ************** - // map stuff - connect(m_map, SIGNAL(zoomChanged(double, double, double)), this, SLOT(zoomChanged(double, double, double))); // map zoom change signals connect(m_map, SIGNAL(OnCurrentPositionChanged(internals::PointLatLng)), this, SLOT(OnCurrentPositionChanged(internals::PointLatLng))); // map poisition change signals connect(m_map, SIGNAL(OnTileLoadComplete()), this, SLOT(OnTileLoadComplete())); // tile loading stop signals connect(m_map, SIGNAL(OnTileLoadStart()), this, SLOT(OnTileLoadStart())); // tile loading start signals - connect(m_map, SIGNAL(OnMapDrag()), this, SLOT(OnMapDrag())); // map drag signals - connect(m_map, SIGNAL(OnMapZoomChanged()), this, SLOT(OnMapZoomChanged())); // map zoom changed - connect(m_map, SIGNAL(OnMapTypeChanged(MapType::Types)), this, SLOT(OnMapTypeChanged(MapType::Types))); // map type changed - connect(m_map, SIGNAL(OnEmptyTileError(int, core::Point)), this, SLOT(OnEmptyTileError(int, core::Point))); // tile error connect(m_map, SIGNAL(OnTilesStillToLoad(int)), this, SLOT(OnTilesStillToLoad(int))); // tile loading signals - connect(m_map, SIGNAL(WPNumberChanged(int const&,int const&,WayPointItem*)), this, SLOT(WPNumberChanged(int const&,int const&,WayPointItem*))); - connect(m_map, SIGNAL(WPValuesChanged(WayPointItem*)), this, SLOT(WPValuesChanged(WayPointItem*))); - connect(m_map, SIGNAL(WPInserted(int const&, WayPointItem*)), this, SLOT(WPInserted(int const&, WayPointItem*))); - connect(m_map, SIGNAL(WPDeleted(int const&)), this, SLOT(WPDeleted(int const&))); - m_map->SetCurrentPosition(m_home_position.coord); // set the map position - m_map->Home->SetCoord(m_home_position.coord); // set the HOME position - m_map->UAV->SetUAVPos(m_home_position.coord, 0.0); // set the UAV position - m_map->GPS->SetUAVPos(m_home_position.coord, 0.0); // set the UAV position + connect(m_map,SIGNAL(OnWayPointDoubleClicked(WayPointItem*)),this,SLOT(wpDoubleClickEvent(WayPointItem*))); + m_map->SetCurrentPosition(m_home_position.coord); // set the map position + m_map->Home->SetCoord(m_home_position.coord); // set the HOME position + m_map->UAV->SetUAVPos(m_home_position.coord, 0.0); // set the UAV position + m_map->UAV->update(); + if(m_map->GPS) + m_map->GPS->SetUAVPos(m_home_position.coord, 0.0); // set the GPS position + magicWayPoint=m_map->magicWPCreate(); + magicWayPoint->setVisible(false); + + m_map->setOverlayOpacity(0.5); + - // ************** // create various context menu (mouse right click menu) actions - createActions(); - // ************** - // connect to the UAVObject updates we require to become a bit aware of our environment: - Q_ASSERT(pm); Q_ASSERT(obm); @@ -300,55 +255,40 @@ OPMapGadgetWidget::OPMapGadgetWidget(QWidget *parent) : QWidget(parent) connect(telMngr, SIGNAL(connected()), this, SLOT(onTelemetryConnect())); connect(telMngr, SIGNAL(disconnected()), this, SLOT(onTelemetryDisconnect())); - // ************** // create the desired timers - m_updateTimer = new QTimer(); m_updateTimer->setInterval(m_maxUpdateRate); connect(m_updateTimer, SIGNAL(timeout()), this, SLOT(updatePosition())); m_updateTimer->start(); m_statusUpdateTimer = new QTimer(); - m_statusUpdateTimer->setInterval(200); - // m_statusUpdateTimer->setInterval(m_maxUpdateRate); - connect(m_statusUpdateTimer, SIGNAL(timeout()), this, SLOT(updateMousePos())); + m_statusUpdateTimer->setInterval(200); + connect(m_statusUpdateTimer, SIGNAL(timeout()), this, SLOT(updateMousePos())); m_statusUpdateTimer->start(); - // ************** - m_map->setFocus(); + + // Create the path compiler and connect the signals to it + pathCompiler = new PathCompiler(this); + connect(pathCompiler, SIGNAL(visualizationChanged(QList)), + this, SLOT(doVisualizationChanged(QList))); } // destructor OPMapGadgetWidget::~OPMapGadgetWidget() { - if (m_map) - { - disconnect(m_map, 0, 0, 0); - m_map->SetShowHome(false); // doing this appears to stop the map lib crashing on exit - m_map->SetShowUAV(false); // " " - } + if (m_map) + { + disconnect(m_map, 0, 0, 0); + m_map->SetShowHome(false); // doing this appears to stop the map lib crashing on exit + m_map->SetShowUAV(false); // " " + } - - m_waypoint_list_mutex.lock(); - foreach (t_waypoint *wp, m_waypoint_list) - { - if (!wp) continue; - - - // todo: - - - delete wp->map_wp_item; - } - m_waypoint_list_mutex.unlock(); - m_waypoint_list.clear(); - - if (m_map) - { - delete m_map; - m_map = NULL; - } + if (m_map) + { + delete m_map; + m_map = NULL; + } } // ************************************************************************************* @@ -356,25 +296,13 @@ OPMapGadgetWidget::~OPMapGadgetWidget() void OPMapGadgetWidget::resizeEvent(QResizeEvent *event) { - qDebug("opmap: resizeEvent"); - QWidget::resizeEvent(event); } -void OPMapGadgetWidget::mouseMoveEvent(QMouseEvent *event) +void OPMapGadgetWidget::wpDoubleClickEvent(WayPointItem *wp) { - qDebug("opmap: mouseMoveEvent"); - - if (m_widget && m_map) - { - } - - if (event->buttons() & Qt::LeftButton) - { - // QPoint pos = event->pos(); - } - - QWidget::mouseMoveEvent(event); + m_mouse_waypoint = wp; + onEditWayPointAct_triggered(); } void OPMapGadgetWidget::contextMenuEvent(QContextMenuEvent *event) @@ -391,7 +319,6 @@ void OPMapGadgetWidget::contextMenuEvent(QContextMenuEvent *event) // current mouse position QPoint p = m_map->mapFromGlobal(event->globalPos()); m_context_menu_lat_lon = m_map->GetFromLocalToLatLng(p); - // m_context_menu_lat_lon = m_map->currentMousePosition(); if (!m_map->contentsRect().contains(p)) return; // the mouse click was not on the map @@ -412,26 +339,19 @@ void OPMapGadgetWidget::contextMenuEvent(QContextMenuEvent *event) // **************** // Dynamically create the popup menu - QMenu menu(this); - - menu.addAction(closeAct1); - - menu.addSeparator(); - - menu.addAction(reloadAct); - - menu.addSeparator(); - - menu.addAction(ripAct); - - menu.addSeparator(); + contextMenu.addAction(closeAct1); + contextMenu.addSeparator(); + contextMenu.addAction(reloadAct); + contextMenu.addSeparator(); + contextMenu.addAction(ripAct); + contextMenu.addSeparator(); QMenu maxUpdateRateSubMenu(tr("&Max Update Rate ") + "(" + QString::number(m_maxUpdateRate) + " ms)", this); for (int i = 0; i < maxUpdateRateAct.count(); i++) maxUpdateRateSubMenu.addAction(maxUpdateRateAct.at(i)); - menu.addMenu(&maxUpdateRateSubMenu); + contextMenu.addMenu(&maxUpdateRateSubMenu); - menu.addSeparator(); + contextMenu.addSeparator(); switch (m_map_mode) { @@ -449,219 +369,162 @@ void OPMapGadgetWidget::contextMenuEvent(QContextMenuEvent *event) QMenu mapModeSubMenu(tr("Map mode") + s, this); for (int i = 0; i < mapModeAct.count(); i++) mapModeSubMenu.addAction(mapModeAct.at(i)); - menu.addMenu(&mapModeSubMenu); + contextMenu.addMenu(&mapModeSubMenu); - menu.addSeparator(); + contextMenu.addSeparator(); QMenu copySubMenu(tr("Copy"), this); copySubMenu.addAction(copyMouseLatLonToClipAct); copySubMenu.addAction(copyMouseLatToClipAct); copySubMenu.addAction(copyMouseLonToClipAct); - menu.addMenu(©SubMenu); + contextMenu.addMenu(©SubMenu); - menu.addSeparator(); + contextMenu.addSeparator(); + contextMenu.addAction(changeDefaultLocalAndZoom); + contextMenu.addSeparator(); - /* - menu.addAction(findPlaceAct); - - menu.addSeparator(); - */ QMenu safeArea("Safety Area definitions"); - // menu.addAction(showSafeAreaAct); QMenu safeAreaSubMenu(tr("Safe Area Radius") + " (" + QString::number(m_map->Home->SafeArea()) + "m)", this); for (int i = 0; i < safeAreaAct.count(); i++) safeAreaSubMenu.addAction(safeAreaAct.at(i)); safeArea.addMenu(&safeAreaSubMenu); safeArea.addAction(showSafeAreaAct); - menu.addMenu(&safeArea); + contextMenu.addMenu(&safeArea); - menu.addSeparator(); + contextMenu.addSeparator(); - menu.addAction(showCompassAct); + contextMenu.addAction(showCompassAct); - menu.addAction(showDiagnostics); + contextMenu.addAction(showDiagnostics); - menu.addSeparator()->setText(tr("Zoom")); + contextMenu.addAction(showUAVInfo); - menu.addAction(zoomInAct); - menu.addAction(zoomOutAct); + contextMenu.addSeparator()->setText(tr("Zoom")); + + contextMenu.addAction(zoomInAct); + contextMenu.addAction(zoomOutAct); QMenu zoomSubMenu(tr("&Zoom ") + "(" + QString::number(m_map->ZoomTotal()) + ")", this); for (int i = 0; i < zoomAct.count(); i++) zoomSubMenu.addAction(zoomAct.at(i)); - menu.addMenu(&zoomSubMenu); + contextMenu.addMenu(&zoomSubMenu); - menu.addSeparator(); + contextMenu.addSeparator(); - menu.addAction(goMouseClickAct); + contextMenu.addAction(goMouseClickAct); - menu.addSeparator()->setText(tr("HOME")); + contextMenu.addSeparator()->setText(tr("HOME")); - menu.addAction(setHomeAct); - menu.addAction(showHomeAct); - menu.addAction(goHomeAct); + contextMenu.addAction(setHomeAct); + contextMenu.addAction(showHomeAct); + contextMenu.addAction(goHomeAct); // **** // uav trails - - menu.addSeparator()->setText(tr("UAV Trail")); - - QMenu uavTrailSubMenu(tr("UAV Trail"), this); - + QMenu uav_menu(tr("UAV")); + uav_menu.addSeparator()->setText(tr("UAV Trail")); + contextMenu.addMenu(&uav_menu); QMenu uavTrailTypeSubMenu(tr("UAV trail type") + " (" + mapcontrol::Helper::StrFromUAVTrailType(m_map->UAV->GetTrailType()) + ")", this); for (int i = 0; i < uavTrailTypeAct.count(); i++) uavTrailTypeSubMenu.addAction(uavTrailTypeAct.at(i)); - uavTrailSubMenu.addMenu(&uavTrailTypeSubMenu); + uav_menu.addMenu(&uavTrailTypeSubMenu); QMenu uavTrailTimeSubMenu(tr("UAV trail time") + " (" + QString::number(m_map->UAV->TrailTime()) + " sec)", this); for (int i = 0; i < uavTrailTimeAct.count(); i++) uavTrailTimeSubMenu.addAction(uavTrailTimeAct.at(i)); - uavTrailSubMenu.addMenu(&uavTrailTimeSubMenu); + uav_menu.addMenu(&uavTrailTimeSubMenu); QMenu uavTrailDistanceSubMenu(tr("UAV trail distance") + " (" + QString::number(m_map->UAV->TrailDistance()) + " meters)", this); for (int i = 0; i < uavTrailDistanceAct.count(); i++) uavTrailDistanceSubMenu.addAction(uavTrailDistanceAct.at(i)); - uavTrailSubMenu.addMenu(&uavTrailDistanceSubMenu); - uavTrailSubMenu.addAction(showUAVtrailAct); +// QMenu gpsTrailSubMenu(tr("GPS Trail"), this); - uavTrailSubMenu.addAction(showUAVtrailLineAct); +// QMenu gpsTrailTypeSubMenu(tr("GPS trail type") + " (" + mapcontrol::Helper::StrFromUAVTrailType(m_map->GPS->GetTrailType()) + ")", this); +// for (int i = 0; i < gpsTrailTypeAct.count(); i++) +// gpsTrailTypeSubMenu.addAction(gpsTrailTypeAct.at(i)); +// gpsTrailSubMenu.addMenu(&gpsTrailTypeSubMenu); - uavTrailSubMenu.addAction(clearUAVtrailAct); - menu.addMenu(&uavTrailSubMenu); +// QMenu gpsTrailTimeSubMenu(tr("GPS trail time") + " (" + QString::number(m_map->GPS->TrailTime()) + " sec)", this); +// for (int i = 0; i < gpsTrailTimeAct.count(); i++) +// gpsTrailTimeSubMenu.addAction(gpsTrailTimeAct.at(i)); +// gpsTrailSubMenu.addMenu(&gpsTrailTimeSubMenu); - // gps trails +// QMenu gpsTrailDistanceSubMenu(tr("GPS trail distance") + " (" + QString::number(m_map->GPS->TrailDistance()) + " meters)", this); +// for (int i = 0; i < gpsTrailDistanceAct.count(); i++) +// gpsTrailDistanceSubMenu.addAction(gpsTrailDistanceAct.at(i)); +// gpsTrailSubMenu.addMenu(&gpsTrailDistanceSubMenu); - //menu.addSeparator()->setText(tr("GPS Trail")); +// gpsTrailSubMenu.addAction(showGPStrailAct); - QMenu gpsTrailSubMenu(tr("GPS Trail"), this); +// gpsTrailSubMenu.addAction(showGPStrailLineAct); - QMenu gpsTrailTypeSubMenu(tr("GPS trail type") + " (" + mapcontrol::Helper::StrFromUAVTrailType(m_map->GPS->GetTrailType()) + ")", this); - for (int i = 0; i < gpsTrailTypeAct.count(); i++) - gpsTrailTypeSubMenu.addAction(gpsTrailTypeAct.at(i)); - gpsTrailSubMenu.addMenu(&gpsTrailTypeSubMenu); +// gpsTrailSubMenu.addAction(clearGPStrailAct); +// menu.addMenu(&gpsTrailSubMenu); - QMenu gpsTrailTimeSubMenu(tr("GPS trail time") + " (" + QString::number(m_map->GPS->TrailTime()) + " sec)", this); - for (int i = 0; i < gpsTrailTimeAct.count(); i++) - gpsTrailTimeSubMenu.addAction(gpsTrailTimeAct.at(i)); - gpsTrailSubMenu.addMenu(&gpsTrailTimeSubMenu); + uav_menu.addMenu(&uavTrailDistanceSubMenu); + //uav_menu.addAction(showTrailAct); + //uav_menu.addAction(showTrailLineAct); + uav_menu.addAction(showGPSAct); + uav_menu.addAction(clearUAVtrailAct); + uav_menu.addSeparator()->setText(tr("UAV")); - QMenu gpsTrailDistanceSubMenu(tr("GPS trail distance") + " (" + QString::number(m_map->GPS->TrailDistance()) + " meters)", this); - for (int i = 0; i < gpsTrailDistanceAct.count(); i++) - gpsTrailDistanceSubMenu.addAction(gpsTrailDistanceAct.at(i)); - gpsTrailSubMenu.addMenu(&gpsTrailDistanceSubMenu); - - gpsTrailSubMenu.addAction(showGPStrailAct); - - gpsTrailSubMenu.addAction(showGPStrailLineAct); - - gpsTrailSubMenu.addAction(clearGPStrailAct); - menu.addMenu(&gpsTrailSubMenu); - - // **** - - menu.addSeparator()->setText(tr("UAV")); - - menu.addAction(showUAVAct); - menu.addAction(showGPSAct); - menu.addAction(followUAVpositionAct); - menu.addAction(followUAVheadingAct); - menu.addAction(goUAVAct); + uav_menu.addAction(showUAVAct); + uav_menu.addAction(followUAVpositionAct); + uav_menu.addAction(followUAVheadingAct); + uav_menu.addAction(goUAVAct); // ********* - - qDebug() << "Testing mode"; switch (m_map_mode) { case Normal_MapMode: - qDebug() << "Normal mode"; - // only show the waypoint stuff if not in 'magic waypoint' mode - menu.addSeparator()->setText(tr("Waypoints")); - menu.addAction(wayPointEditorAct); - menu.addAction(addWayPointAct); + contextMenu.addSeparator()->setText(tr("Waypoints")); + + contextMenu.addAction(addWayPointAct); if (m_mouse_waypoint) { // we have a waypoint under the mouse - menu.addAction(editWayPointAct); - lockWayPointAct->setChecked(waypoint_locked); - menu.addAction(lockWayPointAct); + contextMenu.addAction(lockWayPointAct); if (!waypoint_locked) - menu.addAction(deleteWayPointAct); + contextMenu.addAction(deleteWayPointAct); } - m_waypoint_list_mutex.lock(); - if (m_waypoint_list.count() > 0) - menu.addAction(clearWayPointsAct); // we have waypoints - m_waypoint_list_mutex.unlock(); + contextMenu.addAction(clearWayPointsAct); // we have waypoints break; case MagicWaypoint_MapMode: - menu.addSeparator()->setText(tr("Waypoints")); - menu.addAction(homeMagicWaypointAct); + contextMenu.addSeparator()->setText(tr("Waypoints")); + contextMenu.addAction(homeMagicWaypointAct); break; } - // ********* + QMenu overlaySubMenu(tr("&Overlay Opacity "),this); + for (int i = 0; i < overlayOpacityAct.count(); i++) + overlaySubMenu.addAction(overlayOpacityAct.at(i)); + contextMenu.addMenu(&overlaySubMenu); + contextMenu.addSeparator(); - menu.addSeparator(); + contextMenu.addAction(closeAct2); - menu.addAction(closeAct2); - - menu.exec(event->globalPos()); // popup the menu - - // **************** + contextMenu.exec(event->globalPos()); // popup the menu } -void OPMapGadgetWidget::keyPressEvent(QKeyEvent* event) +void OPMapGadgetWidget::closeEvent(QCloseEvent *event) { - qDebug() << "opmap: keyPressEvent, key =" << event->key() << endl; - - switch (event->key()) - { - case Qt::Key_Escape: - break; - - case Qt::Key_F1: - break; - - case Qt::Key_F2: - break; - - case Qt::Key_Up: - break; - - case Qt::Key_Down: - break; - - case Qt::Key_Left: - break; - - case Qt::Key_Right: - break; - - case Qt::Key_PageUp: - break; - - case Qt::Key_PageDown: - break; - } + QWidget::closeEvent(event); } // ************************************************************************************* // timer signals /** - Updates the UAV position on the map. It is called every 200ms - by a timer. - - TODO: consider updating upon object update, not timer. - - from Pip: No don't update on object update - had reports that peoples PC's can't cope with high update rates - have had to allow user to set map update from 100ms to 5 seconds (depending on their PC's graphics processing ability), so this needs to be kept on a timer. - */ + Updates the UAV position on the map. It is called at a user-defined frequency, + as set inside the map widget. +*/ void OPMapGadgetWidget::updatePosition() { double uav_latitude, uav_longitude, uav_altitude, uav_yaw; @@ -674,13 +537,6 @@ void OPMapGadgetWidget::updatePosition() return; QMutexLocker locker(&m_map_mutex); - // Pip I'm sorry, I know this was here with a purpose vvv - // from Pip: let you off :) - //if (!telemetry_connected) - // return; - - // ************* - // get the current UAV details // get current UAV position if (!getUAVPosition(uav_latitude, uav_longitude, uav_altitude)) @@ -691,44 +547,74 @@ void OPMapGadgetWidget::updatePosition() uav_pos = internals::PointLatLng(uav_latitude, uav_longitude); - // ************* - // get the current GPS details + // ************* + // get the current GPS position and heading + GPSPosition *gpsPositionObj = GPSPosition::GetInstance(obm); + Q_ASSERT(gpsPositionObj); - // get current GPS position - if (!getGPSPosition(gps_latitude, gps_longitude, gps_altitude)) - return; + GPSPosition::DataFields gpsPositionData = gpsPositionObj->getData(); - // get current GPS heading - // gps_heading = getGPS_Heading(); - gps_heading = 0; + gps_heading = gpsPositionData.Heading; + gps_latitude = gpsPositionData.Latitude; + gps_longitude = gpsPositionData.Longitude; + gps_altitude = gpsPositionData.Altitude; gps_pos = internals::PointLatLng(gps_latitude, gps_longitude); - // ************* - // display the UAV position + //********************** + // get the current position and heading estimates + AttitudeActual *attitudeActualObj = AttitudeActual::GetInstance(obm); + PositionActual *positionActualObj = PositionActual::GetInstance(obm); + VelocityActual *velocityActualObj = VelocityActual::GetInstance(obm); + Gyros *gyrosObj = Gyros::GetInstance(obm); + Q_ASSERT(positionActualObj); + Q_ASSERT(velocityActualObj); + Q_ASSERT(gyrosObj); + + AttitudeActual::DataFields attitudeActualData = attitudeActualObj->getData(); + PositionActual::DataFields positionActualData = positionActualObj->getData(); + VelocityActual::DataFields velocityActualData = velocityActualObj->getData(); + Gyros::DataFields gyrosData = gyrosObj->getData(); + + double NED[3]={positionActualData.North, positionActualData.East, positionActualData.Down}; + double vNED[3]={velocityActualData.North, velocityActualData.East, velocityActualData.Down}; + + //Set the position and heading estimates in the painter module + m_map->UAV->SetNED(NED); + m_map->UAV->SetGroundspeed(vNED, m_maxUpdateRate); + + //Convert angular velocities into a rotationg rate around the world-frame yaw axis. This is found by simply taking the dot product of the angular Euler-rate matrix with the angular rates. + float psiRate_dps=0*gyrosData.z + sin(attitudeActualData.Roll*deg_to_rad)/cos(attitudeActualData.Pitch*deg_to_rad)*gyrosData.y + cos(attitudeActualData.Roll*deg_to_rad)/cos(attitudeActualData.Pitch*deg_to_rad)*gyrosData.z; + + //Set the angular rate in the painter module + m_map->UAV->SetYawRate(psiRate_dps); //Not correct, but I'm being lazy right now. + + // ************* + // display the UAV position QString str = "lat: " + QString::number(uav_pos.Lat(), 'f', 7) + " lon: " + QString::number(uav_pos.Lng(), 'f', 7) + " " + QString::number(uav_yaw, 'f', 1) + "deg" + " " + QString::number(uav_altitude, 'f', 1) + "m"; - // " " + QString::number(uav_ground_speed_meters_per_second, 'f', 1) + "m/s"; m_widget->labelUAVPos->setText(str); // ************* // set the UAV icon position on the map m_map->UAV->SetUAVPos(uav_pos, uav_altitude); // set the maps UAV position - // qDebug()<<"UAVPOSITION"<UAV->SetUAVHeading(uav_yaw); // set the maps UAV heading - // ************* - // set the GPS icon position on the map - - m_map->GPS->SetUAVPos(gps_pos, gps_altitude); // set the maps GPS position - m_map->GPS->SetUAVHeading(gps_heading); // set the maps GPS heading - - // ************* + // ************* + // set the GPS icon position on the map + if(m_map->GPS) + { + m_map->GPS->SetUAVPos(gps_pos, gps_altitude); // set the maps GPS position + m_map->GPS->SetUAVHeading(gps_heading); // set the maps GPS heading + } + m_map->UAV->updateTextOverlay(); + m_map->UAV->update(); + // ************* } /** @@ -744,7 +630,7 @@ void OPMapGadgetWidget::updateMousePos() QPoint p = m_map->mapFromGlobal(QCursor::pos()); internals::PointLatLng lat_lon = m_map->GetFromLocalToLatLng(p); // fetch the current lat/lon mouse position - + lastLatLngMouse=lat_lon; if (!m_map->contentsRect().contains(p)) return; // the mouse is not on the map @@ -755,9 +641,6 @@ void OPMapGadgetWidget::updateMousePos() // find out if we are over the home position mapcontrol::HomeItem *home = qgraphicsitem_cast(item); - // find out if we are over the UAV - mapcontrol::UAVItem *uav = qgraphicsitem_cast(item); - // find out if we have a waypoint under the mouse cursor mapcontrol::WayPointItem *wp = qgraphicsitem_cast(item); @@ -771,41 +654,22 @@ void OPMapGadgetWidget::updateMousePos() QString s = QString::number(m_mouse_lat_lon.Lat(), 'f', 7) + " " + QString::number(m_mouse_lat_lon.Lng(), 'f', 7); if (wp) { - s += " wp[" + QString::number(wp->Number()) + "]"; + s += " wp[" + QString::number(wp->numberAdjusted()) + "]"; double dist = distance(home_lat_lon, wp->Coord()); double bear = bearing(home_lat_lon, wp->Coord()); s += " " + QString::number(dist * 1000, 'f', 1) + "m"; s += " " + QString::number(bear, 'f', 1) + "deg"; } - else - if (home) - { - s += " home"; + else if (home) + { + s += " home"; - double dist = distance(home_lat_lon, m_mouse_lat_lon); - double bear = bearing(home_lat_lon, m_mouse_lat_lon); - s += " " + QString::number(dist * 1000, 'f', 1) + "m"; - s += " " + QString::number(bear, 'f', 1) + "deg"; - } - else - if (uav) - { - s += " uav"; - - double latitude; - double longitude; - double altitude; - if (getUAVPosition(latitude, longitude, altitude)) // get current UAV position - { - internals::PointLatLng uav_pos = internals::PointLatLng(latitude, longitude); - - // double dist = distance(home_lat_lon, uav_pos); - // double bear = bearing(home_lat_lon, uav_pos); - // s += " " + QString::number(dist * 1000, 'f', 1) + "m"; - // s += " " + QString::number(bear, 'f', 1) + "deg"; - } - } + double dist = distance(home_lat_lon, m_mouse_lat_lon); + double bear = bearing(home_lat_lon, m_mouse_lat_lon); + s += " " + QString::number(dist * 1000, 'f', 1) + "m"; + s += " " + QString::number(bear, 'f', 1) + "deg"; + } m_widget->labelMousePos->setText(s); } @@ -835,11 +699,7 @@ void OPMapGadgetWidget::zoomChanged(double zoomt, double zoom, double zoomd) int index0_zoom = i_zoom - m_min_zoom; // zoom level starting at index level '0' if (index0_zoom < zoomAct.count()) - zoomAct.at(index0_zoom)->setChecked(true); // set the right-click context menu zoom level -} - -void OPMapGadgetWidget::OnMapDrag() -{ + zoomAct.at(index0_zoom)->setChecked(true); // set the right-click context menu zoom level } void OPMapGadgetWidget::OnCurrentPositionChanged(internals::PointLatLng point) @@ -859,17 +719,12 @@ void OPMapGadgetWidget::OnTilesStillToLoad(int number) if (!m_widget || !m_map) return; - // if (prev_tile_number < number || m_widget->progressBarMap->maximum() < number) - // m_widget->progressBarMap->setMaximum(number); - - if (m_widget->progressBarMap->maximum() < number) + if (m_widget->progressBarMap->maximum() < number) m_widget->progressBarMap->setMaximum(number); m_widget->progressBarMap->setValue(m_widget->progressBarMap->maximum() - number); // update the progress bar - // m_widget->labelNumTilesToLoad->setText(QString::number(number)); - - m_prev_tile_number = number; + m_prev_tile_number = number; } /** @@ -877,9 +732,8 @@ void OPMapGadgetWidget::OnTilesStillToLoad(int number) */ void OPMapGadgetWidget::OnTileLoadStart() { - if (!m_widget || !m_map) - return; - + if (!m_widget || !m_map) + return; m_widget->progressBarMap->setVisible(true); } @@ -897,77 +751,6 @@ void OPMapGadgetWidget::OnTileLoadComplete() m_widget->progressBarMap->setVisible(false); } -void OPMapGadgetWidget::OnMapZoomChanged() -{ -} - -void OPMapGadgetWidget::OnMapTypeChanged(MapType::Types type) -{ - Q_UNUSED(type); -} - -void OPMapGadgetWidget::OnEmptyTileError(int zoom, core::Point pos) -{ - Q_UNUSED(zoom); - Q_UNUSED(pos); -} - -void OPMapGadgetWidget::WPNumberChanged(int const &oldnumber, int const &newnumber, WayPointItem *waypoint) -{ - Q_UNUSED(oldnumber); - Q_UNUSED(newnumber); - Q_UNUSED(waypoint); -} - -/** - * Called whenever a waypoint item is changed on the mapcontrol. Needs to update - * the backend appropriately - */ -void OPMapGadgetWidget::WPValuesChanged(WayPointItem *waypoint) -{ - switch (m_map_mode) - { - case Normal_MapMode: - { - // TODO: We don't parse changes in position here as it's too dense - // however a change in something like - } - break; - - case MagicWaypoint_MapMode: - // update our copy of the magic waypoint - if (m_magic_waypoint.map_wp_item && m_magic_waypoint.map_wp_item == waypoint) - { - m_magic_waypoint.coord = waypoint->Coord(); - m_magic_waypoint.altitude = waypoint->Altitude(); - m_magic_waypoint.description = waypoint->Description(); - - // move the UAV to the magic waypoint position - // moveToMagicWaypointPosition(); - } - break; - } - -} - -/** - TODO: slot to do something upon Waypoint insertion - */ -void OPMapGadgetWidget::WPInserted(int const &number, WayPointItem *waypoint) -{ - Q_UNUSED(number); - Q_UNUSED(waypoint); -} - -/** - TODO: slot to do something upon Waypoint deletion - */ -void OPMapGadgetWidget::WPDeleted(int const &number) -{ - Q_UNUSED(number); -} - - void OPMapGadgetWidget::on_toolButtonZoomP_clicked() { QMutexLocker locker(&m_map_mutex); @@ -1053,7 +836,7 @@ void OPMapGadgetWidget::onTelemetryConnect() if (obum->getHomeLocation(set, LLA) < 0) return; // error - setHome(internals::PointLatLng(LLA[0], LLA[1])); + setHome(internals::PointLatLng(LLA[0], LLA[1]),LLA[2]); if (m_map) m_map->SetCurrentPosition(m_home_position.coord); // set the map position @@ -1069,12 +852,14 @@ void OPMapGadgetWidget::onTelemetryDisconnect() // Updates the Home position icon whenever the HomePosition object is updated void OPMapGadgetWidget::homePositionUpdated(UAVObject *hp) { - if (!hp) - return; + Q_UNUSED(hp); + if (!obum) return; + bool set; + double LLA[3]; + if (obum->getHomeLocation(set, LLA) < 0) + return; // error + setHome(internals::PointLatLng(LLA[0], LLA[1]),LLA[2]); - double lat = hp->getField("Latitude")->getDouble() * 1e-7; - double lon = hp->getField("Longitude")->getDouble() * 1e-7; - setHome(internals::PointLatLng(lat, lon)); } // ************************************************************************************* @@ -1101,13 +886,13 @@ void OPMapGadgetWidget::setHome(QPointF pos) else if (longitude < -180) longitude = -180; - setHome(internals::PointLatLng(latitude, longitude)); + setHome(internals::PointLatLng(latitude, longitude),0); } /** Sets the home position on the map widget */ -void OPMapGadgetWidget::setHome(internals::PointLatLng pos_lat_lon) +void OPMapGadgetWidget::setHome(internals::PointLatLng pos_lat_lon,double altitude) { if (!m_widget || !m_map) return; @@ -1126,15 +911,17 @@ void OPMapGadgetWidget::setHome(internals::PointLatLng pos_lat_lon) if (longitude != longitude) longitude = 0; // nan detection else - if (longitude > 180) longitude = 180; - else - if (longitude < -180) longitude = -180; + if (longitude > 180) longitude = 180; + else + if (longitude < -180) longitude = -180; + else if(altitude != altitude) altitude=0; // ********* m_home_position.coord = internals::PointLatLng(latitude, longitude); - m_map->Home->SetCoord(m_home_position.coord); + m_map->Home->SetCoord(m_home_position.coord); + m_map->Home->SetAltitude(altitude); m_map->Home->RefreshPos(); // move the magic waypoint to keep it within the safe area boundry @@ -1223,6 +1010,35 @@ void OPMapGadgetWidget::setZoom(int zoom) m_map->SetMouseWheelZoomType(zoom_type); } +void OPMapGadgetWidget::setOverlayOpacity(qreal value) +{ + if (!m_widget || !m_map) + return; + m_map->setOverlayOpacity(value); + overlayOpacityAct.at(value*10)->setChecked(true); +} + +void OPMapGadgetWidget::setHomePosition(QPointF pos) +{ + if (!m_widget || !m_map) + return; + + double latitude = pos.y(); + double longitude = pos.x(); + + if (latitude != latitude || longitude != longitude) + return; // nan prevention + + if (latitude > 90) latitude = 90; + else + if (latitude < -90) latitude = -90; + + if (longitude > 180) longitude = 180; + else + if (longitude < -180) longitude = -180; + + m_map->Home->SetCoord(internals::PointLatLng(latitude, longitude)); +} void OPMapGadgetWidget::setPosition(QPointF pos) { @@ -1295,21 +1111,12 @@ void OPMapGadgetWidget::setCacheLocation(QString cacheLocation) if (cacheLocation.isEmpty()) return; - // #if defined(Q_WS_WIN) - // if (!cacheLocation.endsWith('\\')) cacheLocation += '\\'; - // #elif defined(Q_WS_X11) if (!cacheLocation.endsWith(QDir::separator())) cacheLocation += QDir::separator(); - // #elif defined(Q_WS_MAC) - // if (!cacheLocation.endsWith(QDir::separator())) cacheLocation += QDir::separator(); - // #endif QDir dir; if (!dir.exists(cacheLocation)) if (!dir.mkpath(cacheLocation)) return; - - // qDebug() << "opmap: map cache dir: " << cacheLocation; - m_map->configuration->SetCacheLocation(cacheLocation); } @@ -1347,15 +1154,8 @@ void OPMapGadgetWidget::setMapMode(opMapModeType mode) hideMagicWaypointControls(); - // delete the magic waypoint from the map - if (m_magic_waypoint.map_wp_item) - { - m_magic_waypoint.coord = m_magic_waypoint.map_wp_item->Coord(); - m_magic_waypoint.altitude = m_magic_waypoint.map_wp_item->Altitude(); - m_magic_waypoint.description = m_magic_waypoint.map_wp_item->Description(); - m_magic_waypoint.map_wp_item = NULL; - } - m_map->WPDeleteAll(); + magicWayPoint->setVisible(false); + m_map->WPSetVisibleAll(true); break; @@ -1368,25 +1168,8 @@ void OPMapGadgetWidget::setMapMode(opMapModeType mode) showMagicWaypointControls(); // delete the normal waypoints from the map - m_waypoint_list_mutex.lock(); - foreach (t_waypoint *wp, m_waypoint_list) - { - if (!wp) continue; - if (!wp->map_wp_item) continue; - wp->coord = wp->map_wp_item->Coord(); - wp->altitude = wp->map_wp_item->Altitude(); - wp->description = wp->map_wp_item->Description(); - wp->locked = (wp->map_wp_item->flags() & QGraphicsItem::ItemIsMovable) == 0; - wp->map_wp_item = NULL; - } - m_map->WPDeleteAll(); - m_waypoint_list_mutex.unlock(); - - // restore the magic waypoint on the map - m_magic_waypoint.map_wp_item = m_map->WPCreate(m_magic_waypoint.coord, m_magic_waypoint.altitude, m_magic_waypoint.description); - m_magic_waypoint.map_wp_item->setZValue(10 + m_magic_waypoint.map_wp_item->Number()); - m_magic_waypoint.map_wp_item->SetShowNumber(false); - m_magic_waypoint.map_wp_item->picture.load(QString::fromUtf8(":/opmap/images/waypoint_marker3.png")); + m_map->WPSetVisibleAll(false); + magicWayPoint->setVisible(true); break; } @@ -1415,6 +1198,7 @@ void OPMapGadgetWidget::createActions() reloadAct->setShortcut(tr("F5")); reloadAct->setStatusTip(tr("Reload the map tiles")); connect(reloadAct, SIGNAL(triggered()), this, SLOT(onReloadAct_triggered())); + this->addAction(reloadAct); ripAct = new QAction(tr("&Rip map"), this); ripAct->setStatusTip(tr("Rip the map tiles")); @@ -1432,13 +1216,6 @@ void OPMapGadgetWidget::createActions() copyMouseLonToClipAct->setStatusTip(tr("Copy the mouse longitude to the clipboard")); connect(copyMouseLonToClipAct, SIGNAL(triggered()), this, SLOT(onCopyMouseLonToClipAct_triggered())); - /* - findPlaceAct = new QAction(tr("&Find place"), this); - findPlaceAct->setShortcut(tr("Ctrl+F")); - findPlaceAct->setStatusTip(tr("Find a location")); - connect(findPlaceAct, SIGNAL(triggered()), this, SLOT(onFindPlaceAct_triggered())); - */ - showCompassAct = new QAction(tr("Show compass"), this); showCompassAct->setStatusTip(tr("Show/Hide the compass")); showCompassAct->setCheckable(true); @@ -1451,21 +1228,39 @@ void OPMapGadgetWidget::createActions() showDiagnostics->setChecked(false); connect(showDiagnostics, SIGNAL(toggled(bool)), this, SLOT(onShowDiagnostics_toggled(bool))); + showUAVInfo = new QAction(tr("Show UAV Info"), this); + showUAVInfo->setStatusTip(tr("Show/Hide the UAV info")); + showUAVInfo->setCheckable(true); + showUAVInfo->setChecked(false); + connect(showUAVInfo, SIGNAL(toggled(bool)), this, SLOT(onShowUAVInfo_toggled(bool))); + showHomeAct = new QAction(tr("Show Home"), this); showHomeAct->setStatusTip(tr("Show/Hide the Home location")); showHomeAct->setCheckable(true); showHomeAct->setChecked(true); connect(showHomeAct, SIGNAL(toggled(bool)), this, SLOT(onShowHomeAct_toggled(bool))); + showUAVAct = new QAction(tr("Show UAV"), this); + showUAVAct->setStatusTip(tr("Show/Hide the UAV")); + showUAVAct->setCheckable(true); + showUAVAct->setChecked(true); + connect(showUAVAct, SIGNAL(toggled(bool)), this, SLOT(onShowUAVAct_toggled(bool))); + + changeDefaultLocalAndZoom = new QAction(tr("Set default zoom and location"), this); + changeDefaultLocalAndZoom->setStatusTip(tr("Changes the map default zoom and location to the current values")); + connect(changeDefaultLocalAndZoom, SIGNAL(triggered()), this, SLOT(onChangeDefaultLocalAndZoom())); + zoomInAct = new QAction(tr("Zoom &In"), this); zoomInAct->setShortcut(Qt::Key_PageUp); zoomInAct->setStatusTip(tr("Zoom the map in")); connect(zoomInAct, SIGNAL(triggered()), this, SLOT(onGoZoomInAct_triggered())); + this->addAction(zoomInAct); zoomOutAct = new QAction(tr("Zoom &Out"), this); zoomOutAct->setShortcut(Qt::Key_PageDown); zoomOutAct->setStatusTip(tr("Zoom the map out")); connect(zoomOutAct, SIGNAL(triggered()), this, SLOT(onGoZoomOutAct_triggered())); + this->addAction(zoomOutAct); goMouseClickAct = new QAction(tr("Go to where you right clicked the mouse"), this); goMouseClickAct->setStatusTip(tr("Center the map onto where you right clicked the mouse")); @@ -1502,38 +1297,16 @@ void OPMapGadgetWidget::createActions() followUAVheadingAct->setChecked(false); connect(followUAVheadingAct, SIGNAL(toggled(bool)), this, SLOT(onFollowUAVheadingAct_toggled(bool))); - /* Waypoint stuff */ - wayPointEditorAct = new QAction(tr("&Waypoint editor"), this); - wayPointEditorAct->setShortcut(tr("Ctrl+W")); - wayPointEditorAct->setStatusTip(tr("Open the waypoint editor")); - wayPointEditorAct->setEnabled(false); // temporary - //connect(wayPointEditorAct, SIGNAL(triggered()), this, SLOT(onOpenWayPointEditorAct_triggered())); - - addWayPointAct = new QAction(tr("&Add waypoint"), this); - addWayPointAct->setShortcut(tr("Ctrl+A")); - addWayPointAct->setStatusTip(tr("Add waypoint")); - connect(addWayPointAct, SIGNAL(triggered()), this, SLOT(onAddWayPointAct_triggered())); - - editWayPointAct = new QAction(tr("&Edit waypoint"), this); - editWayPointAct->setShortcut(tr("Ctrl+E")); - editWayPointAct->setStatusTip(tr("Edit waypoint")); - connect(editWayPointAct, SIGNAL(triggered()), this, SLOT(onEditWayPointAct_triggered())); - - lockWayPointAct = new QAction(tr("&Lock waypoint"), this); - lockWayPointAct->setStatusTip(tr("Lock/Unlock a waypoint")); - lockWayPointAct->setCheckable(true); - lockWayPointAct->setChecked(false); - connect(lockWayPointAct, SIGNAL(triggered()), this, SLOT(onLockWayPointAct_triggered())); - - deleteWayPointAct = new QAction(tr("&Delete waypoint"), this); - deleteWayPointAct->setShortcut(tr("Ctrl+D")); - deleteWayPointAct->setStatusTip(tr("Delete waypoint")); - connect(deleteWayPointAct, SIGNAL(triggered()), this, SLOT(onDeleteWayPointAct_triggered())); - - clearWayPointsAct = new QAction(tr("&Clear waypoints"), this); - clearWayPointsAct->setShortcut(tr("Ctrl+C")); - clearWayPointsAct->setStatusTip(tr("Clear waypoints")); - connect(clearWayPointsAct, SIGNAL(triggered()), this, SLOT(onClearWayPointsAct_triggered())); + overlayOpacityActGroup = new QActionGroup(this); + connect(overlayOpacityActGroup, SIGNAL(triggered(QAction *)), this, SLOT(onOverlayOpacityActGroup_triggered(QAction *))); + overlayOpacityAct.clear(); + for (int i = 0; i <= 10; i++) + { + QAction *overlayAct = new QAction(QString::number(i*10), overlayOpacityActGroup); + overlayAct->setCheckable(true); + overlayAct->setData(i*10); + overlayOpacityAct.append(overlayAct); + } homeMagicWaypointAct = new QAction(tr("Home magic waypoint"), this); homeMagicWaypointAct->setStatusTip(tr("Move the magic waypoint to the home position")); @@ -1635,12 +1408,6 @@ void OPMapGadgetWidget::createActions() showUAVtrailAct->setChecked(true); connect(showUAVtrailAct, SIGNAL(toggled(bool)), this, SLOT(onShowUAVtrailAct_toggled(bool))); - showUAVtrailLineAct = new QAction(tr("Show Trail lines"), this); - showUAVtrailLineAct->setStatusTip(tr("Show/Hide the Trail lines")); - showUAVtrailLineAct->setCheckable(true); - showUAVtrailLineAct->setChecked(true); - connect(showUAVtrailLineAct, SIGNAL(toggled(bool)), this, SLOT(onShowUAVtrailLineAct_toggled(bool))); - clearUAVtrailAct = new QAction(tr("Clear UAV trail"), this); clearUAVtrailAct->setStatusTip(tr("Clear the UAV trail")); connect(clearUAVtrailAct, SIGNAL(triggered()), this, SLOT(onClearUAVtrailAct_triggered())); @@ -1673,78 +1440,30 @@ void OPMapGadgetWidget::createActions() uavTrailDistanceAct.append(uavTrailDistance_act); } - // ***** - - // ***** - // GPS trail + //GPS trail showGPSAct = new QAction(tr("Show GPS"), this); showGPSAct->setStatusTip(tr("Show/Hide the GPS")); showGPSAct->setCheckable(true); showGPSAct->setChecked(false); connect(showGPSAct, SIGNAL(toggled(bool)), this, SLOT(onShowGPSAct_toggled(bool))); - gpsTrailTypeActGroup = new QActionGroup(this); - connect(gpsTrailTypeActGroup, SIGNAL(triggered(QAction *)), this, SLOT(onGPStrailTypeActGroup_triggered(QAction *))); - gpsTrailTypeAct.clear(); - QStringList gps_trail_type_list = mapcontrol::Helper::UAVTrailTypes(); - for (int i = 0; i < gps_trail_type_list.count(); i++) - { - mapcontrol::UAVTrailType::Types gps_trail_type = mapcontrol::Helper::UAVTrailTypeFromString(gps_trail_type_list[i]); - QAction *gpsTrailType_act = new QAction(mapcontrol::Helper::StrFromUAVTrailType(gps_trail_type), gpsTrailTypeActGroup); - gpsTrailType_act->setCheckable(true); - gpsTrailType_act->setChecked(gps_trail_type == m_map->GPS->GetTrailType()); - gpsTrailType_act->setData(i); - gpsTrailTypeAct.append(gpsTrailType_act); - } + /** Actions for way points **/ + addWayPointAct = new QAction(tr("&Add waypoint"), this); + addWayPointAct->setShortcut(tr("Ctrl+A")); + addWayPointAct->setStatusTip(tr("Add waypoint")); + connect(addWayPointAct, SIGNAL(triggered()), this, SLOT(onAddWayPointAct_triggered())); - showGPStrailAct = new QAction(tr("Show Trail dots"), this); - showGPStrailAct->setStatusTip(tr("Show/Hide the Trail dots")); - showGPStrailAct->setCheckable(true); - showGPStrailAct->setChecked(false); - connect(showGPStrailAct, SIGNAL(toggled(bool)), this, SLOT(onShowGPStrailAct_toggled(bool))); + clearWayPointsAct = new QAction(tr("&Clear waypoints"), this); + clearWayPointsAct->setStatusTip(tr("Clear all the waypoints")); + connect(clearWayPointsAct, SIGNAL(triggered()),this, SLOT(onClearWayPointsAct_triggered())); - showGPStrailLineAct = new QAction(tr("Show Trail lines"), this); - showGPStrailLineAct->setStatusTip(tr("Show/Hide the Trail lines")); - showGPStrailLineAct->setCheckable(true); - showGPStrailLineAct->setChecked(true); - connect(showGPStrailLineAct, SIGNAL(toggled(bool)), this, SLOT(onShowGPStrailLineAct_toggled(bool))); + deleteWayPointAct = new QAction(tr("&Del waypoint"), this); + deleteWayPointAct->setStatusTip(tr("Delete this waypoint")); + connect(deleteWayPointAct, SIGNAL(triggered()), this, SLOT(onDeleteWayPointAct_triggered())); - clearGPStrailAct = new QAction(tr("Clear GPS trail"), this); - clearGPStrailAct->setStatusTip(tr("Clear the GPS trail")); - connect(clearGPStrailAct, SIGNAL(triggered()), this, SLOT(onClearGPStrailAct_triggered())); - - gpsTrailTimeActGroup = new QActionGroup(this); - connect(gpsTrailTimeActGroup, SIGNAL(triggered(QAction *)), this, SLOT(onGPStrailTimeActGroup_triggered(QAction *))); - gpsTrailTimeAct.clear(); - list_size = sizeof(uav_trail_time_list) / sizeof(uav_trail_time_list[0]); - for (int i = 0; i < list_size; i++) - { - int gps_trail_time = uav_trail_time_list[i]; - QAction *gpsTrailTime_act = new QAction(QString::number(gps_trail_time) + " sec", gpsTrailTimeActGroup); - gpsTrailTime_act->setCheckable(true); - gpsTrailTime_act->setChecked(gps_trail_time == m_map->GPS->TrailTime()); - gpsTrailTime_act->setData(gps_trail_time); - gpsTrailTimeAct.append(gpsTrailTime_act); - } - - gpsTrailDistanceActGroup = new QActionGroup(this); - connect(gpsTrailDistanceActGroup, SIGNAL(triggered(QAction *)), this, SLOT(onGPStrailDistanceActGroup_triggered(QAction *))); - gpsTrailDistanceAct.clear(); - list_size = sizeof(uav_trail_distance_list) / sizeof(uav_trail_distance_list[0]); - for (int i = 0; i < list_size; i++) - { - int gps_trail_distance = uav_trail_distance_list[i]; - QAction *gpsTrailDistance_act = new QAction(QString::number(gps_trail_distance) + " meters", gpsTrailDistanceActGroup); - gpsTrailDistance_act->setCheckable(true); - gpsTrailDistance_act->setChecked(gps_trail_distance == m_map->GPS->TrailDistance()); - gpsTrailDistance_act->setData(gps_trail_distance); - gpsTrailDistanceAct.append(gpsTrailDistance_act); - } - - // ***** - - - // *********************** + lockWayPointAct = new QAction(tr("&Lock waypoints"), this); + lockWayPointAct->setStatusTip(tr("Lock a waypoint location")); + connect(lockWayPointAct, SIGNAL(triggered()), this, SLOT(onLockWayPointAct_triggered())); } void OPMapGadgetWidget::onReloadAct_triggered() @@ -1790,11 +1509,19 @@ void OPMapGadgetWidget::onShowCompassAct_toggled(bool show) void OPMapGadgetWidget::onShowDiagnostics_toggled(bool show) { if (!m_widget || !m_map) - return; + return; m_map->SetShowDiagnostics(show); } +void OPMapGadgetWidget::onShowUAVInfo_toggled(bool show) +{ + if (!m_widget || !m_map) + return; + + m_map->UAV->SetShowUAVInfo(show); +} + void OPMapGadgetWidget::onShowHomeAct_toggled(bool show) { if (!m_widget || !m_map) @@ -1803,13 +1530,12 @@ void OPMapGadgetWidget::onShowHomeAct_toggled(bool show) m_map->Home->setVisible(show); } -void OPMapGadgetWidget::onShowTrailAct_toggled(bool show) +void OPMapGadgetWidget::onShowUAVAct_toggled(bool show) { - if (!m_widget || !m_map) - return; + if (!m_widget || !m_map) + return; - m_map->UAV->SetShowTrail(show); - m_map->GPS->SetShowTrail(show); + m_map->UAV->setVisible(show); } void OPMapGadgetWidget::onShowTrailLineAct_toggled(bool show) @@ -1818,7 +1544,8 @@ void OPMapGadgetWidget::onShowTrailLineAct_toggled(bool show) return; m_map->UAV->SetShowTrailLine(show); - m_map->GPS->SetShowTrailLine(show); + if(m_map->GPS) + m_map->GPS->SetShowTrailLine(show); } void OPMapGadgetWidget::onMapModeActGroup_triggered(QAction *action) @@ -1857,6 +1584,11 @@ void OPMapGadgetWidget::onMaxUpdateRateActGroup_triggered(QAction *action) setMaxUpdateRate(action->data().toInt()); } +void OPMapGadgetWidget::onChangeDefaultLocalAndZoom() +{ + emit defaultLocationAndZoomChanged(m_map->CurrentPosition().Lng(),m_map->CurrentPosition().Lat(),m_map->ZoomTotal()); +} + void OPMapGadgetWidget::onGoMouseClickAct_triggered() { if (!m_widget || !m_map) @@ -1870,7 +1602,7 @@ void OPMapGadgetWidget::onSetHomeAct_triggered() if (!m_widget || !m_map) return; - setHome(m_context_menu_lat_lon); + setHome(m_context_menu_lat_lon,0); setHomeLocationObject(); // update the HomeLocation UAVObject } @@ -1920,15 +1652,8 @@ void OPMapGadgetWidget::onFollowUAVheadingAct_toggled(bool checked) setMapFollowingMode(); } -/* UAV */ -void OPMapGadgetWidget::onShowUAVAct_toggled(bool show) -{ - if (!m_widget || !m_map) - return; - - m_map->UAV->setVisible(show); -} +//! Toggle whether the UAV trail is shown void OPMapGadgetWidget::onShowUAVtrailAct_toggled(bool show) { if (!m_widget || !m_map) @@ -1937,20 +1662,14 @@ void OPMapGadgetWidget::onShowUAVtrailAct_toggled(bool show) m_map->UAV->SetShowTrail(show); } -void OPMapGadgetWidget::onShowUAVtrailLineAct_toggled(bool show) -{ - if (!m_widget || !m_map) - return; - - m_map->UAV->SetShowTrailLine(show); -} - void OPMapGadgetWidget::onClearUAVtrailAct_triggered() { if (!m_widget || !m_map) return; m_map->UAV->DeleteTrail(); + if(m_map->GPS) + m_map->GPS->DeleteTrail(); } void OPMapGadgetWidget::onUAVtrailTimeActGroup_triggered(QAction *action) @@ -2073,12 +1792,7 @@ void OPMapGadgetWidget::onAddWayPointAct_triggered() pathCompiler->doAddWaypoint(newWaypoint); } -/** - * Called when the user asks to edit a waypoint from the map - * - * TODO: should open an interface to edit waypoint properties, or - * propagate the signal to a specific WP plugin (tbd). - **/ +//! Called when the user asks to edit a waypoint from the map void OPMapGadgetWidget::onEditWayPointAct_triggered() { if (!m_widget || !m_map) @@ -2090,8 +1804,7 @@ void OPMapGadgetWidget::onEditWayPointAct_triggered() if (!m_mouse_waypoint) return; - //waypoint_edit_dialog.editWaypoint(m_mouse_waypoint); - + //waypoint_edit_dialog->editWaypoint(m_mouse_waypoint); m_mouse_waypoint = NULL; } @@ -2146,9 +1859,7 @@ void OPMapGadgetWidget::onDeleteWayPointAct_triggered() m_mouse_waypoint = NULL; } -/** - * TODO: No Waypoint support in v1.0 - */ +//! Trigger the path compiler to delete all waypoints void OPMapGadgetWidget::onClearWayPointsAct_triggered() { Q_ASSERT(m_widget); @@ -2160,6 +1871,18 @@ void OPMapGadgetWidget::onClearWayPointsAct_triggered() if (m_map_mode != Normal_MapMode) return; + //First, ask to ensure this is what the user wants to do + QMessageBox msgBox; + msgBox.setText(tr("Are you sure you want to clear waypoints?")); + msgBox.setInformativeText(tr("All associated data will be lost.")); + msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No); + int ret = msgBox.exec(); + + if (ret == QMessageBox::No) + { + return; + } + Q_ASSERT(pathCompiler); if(pathCompiler) pathCompiler->doDelAllWaypoints(); @@ -2177,6 +1900,7 @@ void OPMapGadgetWidget::onShowSafeAreaAct_toggled(bool show) return; m_map->Home->SetShowSafeArea(show); // show the safe area + m_map->Home->SetToggleRefresh(true); m_map->Home->RefreshPos(); } @@ -2194,9 +1918,7 @@ void OPMapGadgetWidget::onSafeAreaActGroup_triggered(QAction *action) keepMagicWaypointWithInSafeArea(); } -/** -* move the magic waypoint to the home position -**/ +//! Move the magic waypoint to the home position void OPMapGadgetWidget::homeMagicWaypoint() { if (!m_widget || !m_map) @@ -2205,15 +1927,10 @@ void OPMapGadgetWidget::homeMagicWaypoint() if (m_map_mode != MagicWaypoint_MapMode) return; - m_magic_waypoint.coord = m_home_position.coord; - - if (m_magic_waypoint.map_wp_item) - m_magic_waypoint.map_wp_item->SetCoord(m_magic_waypoint.coord); + magicWayPoint->SetCoord(m_home_position.coord); } -// ************************************************************************************* -// move the UAV to the magic waypoint position - +//! Move the UAV to the magic waypoint position void OPMapGadgetWidget::moveToMagicWaypointPosition() { if (!m_widget || !m_map) @@ -2222,64 +1939,10 @@ void OPMapGadgetWidget::moveToMagicWaypointPosition() if (m_map_mode != MagicWaypoint_MapMode) return; - // internals::PointLatLng coord = magic_waypoint.coord; - // double altitude = magic_waypoint.altitude; - - - // ToDo: - + // TODO } -// ************************************************************************************* -// temporary until an object is created for managing the save/restore - -// load the contents of a simple text file into a combobox -void OPMapGadgetWidget::loadComboBoxLines(QComboBox *comboBox, QString filename) -{ - if (!comboBox) return; - if (filename.isNull() || filename.isEmpty()) return; - - QFile file(filename); - if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) - return; - - QTextStream in(&file); - - while (!in.atEnd()) - { - QString line = in.readLine().simplified(); - if (line.isNull() || line.isEmpty()) continue; - comboBox->addItem(line); - } - - file.close(); -} - -// save a combobox text contents to a simple text file -void OPMapGadgetWidget::saveComboBoxLines(QComboBox *comboBox, QString filename) -{ - if (!comboBox) return; - if (filename.isNull() || filename.isEmpty()) return; - - QFile file(filename); - if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) - return; - - QTextStream out(&file); - - for (int i = 0; i < comboBox->count(); i++) - { - QString line = comboBox->itemText(i).simplified(); - if (line.isNull() || line.isEmpty()) continue; - out << line << "\n"; - } - - file.close(); -} - -// ************************************************************************************* -// show/hide the magic waypoint controls - +//! Hide the magic waypoint controls void OPMapGadgetWidget::hideMagicWaypointControls() { m_widget->lineWaypoint->setVisible(false); @@ -2287,6 +1950,7 @@ void OPMapGadgetWidget::hideMagicWaypointControls() m_widget->toolButtonMoveToWP->setVisible(false); } +//! Show the magic waypoint controls void OPMapGadgetWidget::showMagicWaypointControls() { m_widget->lineWaypoint->setVisible(true); @@ -2299,38 +1963,29 @@ void OPMapGadgetWidget::showMagicWaypointControls() #endif } -// ************************************************************************************* -// move the magic waypoint to keep it within the safe area boundry - +//! Move the magic waypoint to keep it within the safe area boundry void OPMapGadgetWidget::keepMagicWaypointWithInSafeArea() { // calcute the bearing and distance from the home position to the magic waypoint - double dist = distance(m_home_position.coord, m_magic_waypoint.coord); - double bear = bearing(m_home_position.coord, m_magic_waypoint.coord); + double dist = distance(m_home_position.coord, magicWayPoint->Coord()); + double bear = bearing(m_home_position.coord, magicWayPoint->Coord()); // get the maximum safe distance - in kilometers double boundry_dist = (double)m_map->Home->SafeArea() / 1000; - // if (dist <= boundry_dist) - // return; // the magic waypoint is still within the safe area, don't move it - if (dist > boundry_dist) dist = boundry_dist; - // move the magic waypoint - - m_magic_waypoint.coord = destPoint(m_home_position.coord, bear, dist); + // move the magic waypoint; if (m_map_mode == MagicWaypoint_MapMode) { // move the on-screen waypoint - if (m_magic_waypoint.map_wp_item) - m_magic_waypoint.map_wp_item->SetCoord(m_magic_waypoint.coord); + if (magicWayPoint) + magicWayPoint->SetCoord(destPoint(m_home_position.coord, bear, dist)); } } -// ************************************************************************************* -// return the distance between two points .. in kilometers - +//! Return the distance between two points .. in kilometers double OPMapGadgetWidget::distance(internals::PointLatLng from, internals::PointLatLng to) { double lat1 = from.Lat() * deg_to_rad; @@ -2339,30 +1994,10 @@ double OPMapGadgetWidget::distance(internals::PointLatLng from, internals::Point double lat2 = to.Lat() * deg_to_rad; double lon2 = to.Lng() * deg_to_rad; - // *********************** - // Haversine formula - /* - double delta_lat = lat2 - lat1; - double delta_lon = lon2 - lon1; - - double t1 = sin(delta_lat / 2); - double t2 = sin(delta_lon / 2); - double a = (t1 * t1) + cos(lat1) * cos(lat2) * (t2 * t2); - double c = 2 * atan2(sqrt(a), sqrt(1 - a)); - - return (earth_mean_radius * c); -*/ - // *********************** - // Spherical Law of Cosines - return (acos(sin(lat1) * sin(lat2) + cos(lat1) * cos(lat2) * cos(lon2 - lon1)) * earth_mean_radius); - - // *********************** } -// ************************************************************************************* -// return the bearing from one point to another .. in degrees - +//! Return the bearing from one point to another .. in degrees double OPMapGadgetWidget::bearing(internals::PointLatLng from, internals::PointLatLng to) { double lat1 = from.Lat() * deg_to_rad; @@ -2385,9 +2020,7 @@ double OPMapGadgetWidget::bearing(internals::PointLatLng from, internals::PointL return bear; } -// ************************************************************************************* -// return a destination lat/lon point given a source lat/lon point and the bearing and distance from the source point - +//! Return a destination lat/lon point given a source lat/lon point and the bearing and distance from the source point internals::PointLatLng OPMapGadgetWidget::destPoint(internals::PointLatLng source, double bear, double dist) { double lat1 = source.Lat() * deg_to_rad; @@ -2417,8 +2050,8 @@ bool OPMapGadgetWidget::getUAVPosition(double &latitude, double &longitude, doub Q_ASSERT(homeLocation != NULL); HomeLocation::DataFields homeLocationData = homeLocation->getData(); - homeLLA[0] = homeLocationData.Latitude / 10e6; - homeLLA[1] = homeLocationData.Longitude / 10e6; + homeLLA[0] = homeLocationData.Latitude / 1e7; + homeLLA[1] = homeLocationData.Longitude / 1e7; homeLLA[2] = homeLocationData.Altitude; PositionActual *positionActual = PositionActual::GetInstance(obm); @@ -2532,7 +2165,7 @@ void OPMapGadgetWidget::SetUavPic(QString UAVPic) */ void OPMapGadgetWidget::doVisualizationChanged(QList waypoints) { - disconnect(this,SLOT(WPDropped(WayPointItem*))); + disconnect(this,SLOT(onWPDragged(WayPointItem*))); m_map->WPDeleteAll(); int index = 0; foreach (PathCompiler::waypoint waypoint, waypoints) { @@ -2546,7 +2179,7 @@ void OPMapGadgetWidget::doVisualizationChanged(QList way wayPointItem->picture.load(QString::fromUtf8(":/opmap/images/waypoint_marker1.png")); index++; } - connect(wayPointItem, SIGNAL(WPDropped(WayPointItem*)), this, SLOT(WPDropped(WayPointItem*))); + connect(wayPointItem, SIGNAL(WPDropped(WayPointItem*)), this, SLOT(onWPDragged(WayPointItem*))); } } @@ -2556,7 +2189,7 @@ void OPMapGadgetWidget::doVisualizationChanged(QList way * can't be used as it is updated too frequently and we don't want to * overload the pathcompiler with unnecessary updates */ -void OPMapGadgetWidget::WPDropped(WayPointItem *waypoint) +void OPMapGadgetWidget::onWPDragged(WayPointItem *waypoint) { switch (m_map_mode) { @@ -2568,3 +2201,18 @@ void OPMapGadgetWidget::WPDropped(WayPointItem *waypoint) break; } } + +//! Open a home editor when double click on home +void OPMapGadgetWidget::onHomeDoubleClick(HomeItem *) +{ + new homeEditor(m_map->Home,this); +} + +void OPMapGadgetWidget::onOverlayOpacityActGroup_triggered(QAction *action) +{ + if (!m_widget || !m_map || !action) + return; + + m_map->setOverlayOpacity(action->data().toReal()/100); + emit overlayOpacityChanged(action->data().toReal()/100); +} diff --git a/ground/openpilotgcs/src/plugins/opmap/opmapgadgetwidget.h b/ground/openpilotgcs/src/plugins/opmap/opmapgadgetwidget.h index 4f04ad5da..f2413a418 100644 --- a/ground/openpilotgcs/src/plugins/opmap/opmapgadgetwidget.h +++ b/ground/openpilotgcs/src/plugins/opmap/opmapgadgetwidget.h @@ -2,7 +2,7 @@ ****************************************************************************** * * @file opmapgadgetwidget.h - * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @addtogroup GCSPlugins GCS Plugins * @{ * @addtogroup OPMapPlugin OpenPilot Map Plugin @@ -30,6 +30,12 @@ // ****************************************************** + +#include "flightdatamodel.h" +#include "pathplanner.h" +#include "modelmapproxy.h" +#include "modeluavoproxy.h" + #include #include #include @@ -41,7 +47,6 @@ #include "opmapcontrol/opmapcontrol.h" -#include "opmap_overlay_widget.h" #include "opmap_zoom_slider_widget.h" #include "opmap_statusbar_widget.h" @@ -52,6 +57,10 @@ #include "uavobjectmanager.h" #include "uavobject.h" #include "objectpersistence.h" +#include +#include "opmap_edit_waypoint_dialog.h" + +#include "homeeditor.h" #include // ****************************************************** @@ -72,18 +81,6 @@ typedef struct t_home bool locked; } t_home; -// local waypoint list item structure -typedef struct t_waypoint -{ - mapcontrol::WayPointItem *map_wp_item; - internals::PointLatLng coord; - double altitude; - QString description; - bool locked; - int time_seconds; - int hold_time_seconds; -} t_waypoint; - // ****************************************************** enum opMapModeType { Normal_MapMode = 0, @@ -105,7 +102,7 @@ public: * @param */ void setHome(QPointF pos); - void setHome(internals::PointLatLng pos_lat_lon); + void setHome(internals::PointLatLng pos_lat_lon, double altitude); void goHome(); void setZoom(int zoom); void setPosition(QPointF pos); @@ -116,8 +113,13 @@ public: void setUseMemoryCache(bool useMemoryCache); void setCacheLocation(QString cacheLocation); void setMapMode(opMapModeType mode); - void SetUavPic(QString UAVPic); + void SetUavPic(QString UAVPic); void setMaxUpdateRate(int update_rate); + void setHomePosition(QPointF pos); + void setOverlayOpacity(qreal value); +signals: + void defaultLocationAndZoomChanged(double lng,double lat,double zoom); + void overlayOpacityChanged(qreal); public slots: void homePositionUpdated(UAVObject *); @@ -126,11 +128,10 @@ public slots: protected: void resizeEvent(QResizeEvent *event); - void mouseMoveEvent(QMouseEvent *event); void contextMenuEvent(QContextMenuEvent *event); - void keyPressEvent(QKeyEvent* event); - + void closeEvent(QCloseEvent *); private slots: + void wpDoubleClickEvent(WayPointItem *wp); void updatePosition(); void updateMousePos(); @@ -143,26 +144,17 @@ private slots: * * Some are currently disabled for the v1.0 plugin version. */ - // void comboBoxFindPlace_returnPressed(); - // void on_toolButtonFindPlace_clicked(); void on_toolButtonZoomM_clicked(); void on_toolButtonZoomP_clicked(); void on_toolButtonMapHome_clicked(); void on_toolButtonMapUAV_clicked(); void on_toolButtonMapUAVheading_clicked(); void on_horizontalSliderZoom_sliderMoved(int position); - // void on_toolButtonAddWaypoint_clicked(); - // void on_treeViewWaypoints_clicked(QModelIndex index); - // void on_toolButtonHome_clicked(); - // void on_toolButtonNextWaypoint_clicked(); - // void on_toolButtonPrevWaypoint_clicked(); - // void on_toolButtonHoldPosition_clicked(); - // void on_toolButtonGo_clicked(); void on_toolButtonMagicWaypointMapMode_clicked(); void on_toolButtonNormalMapMode_clicked(); void on_toolButtonHomeWaypoint_clicked(); void on_toolButtonMoveToWP_clicked(); - + void onLockWayPointAct_triggered(); /** * @brief signals received from the map object */ @@ -170,21 +162,15 @@ private slots: void OnCurrentPositionChanged(internals::PointLatLng point); void OnTileLoadComplete(); void OnTileLoadStart(); - void OnMapDrag(); - void OnMapZoomChanged(); - void OnMapTypeChanged(MapType::Types type); - void OnEmptyTileError(int zoom, core::Point pos); void OnTilesStillToLoad(int number); - /** - * Unused for now, hooks for future waypoint support - */ - void WPDropped(WayPointItem *waypoint); - void WPNumberChanged(int const& oldnumber,int const& newnumber, WayPointItem* waypoint); - void WPValuesChanged(WayPointItem* waypoint); - void WPInserted(int const& number, WayPointItem* waypoint); - void WPDeleted(int const& number); + /**** Methods related to the path compiler ****/ + + //! Called whenever a waypoint is moved void doVisualizationChanged(QList); + void onWPDragged(WayPointItem *waypoint); + void onDeleteWayPointAct_triggered(); + void onClearWayPointsAct_triggered(); /** * @brief mouse right click context menu signals @@ -194,9 +180,9 @@ private slots: void onCopyMouseLatLonToClipAct_triggered(); void onCopyMouseLatToClipAct_triggered(); void onCopyMouseLonToClipAct_triggered(); - // void onFindPlaceAct_triggered(); void onShowCompassAct_toggled(bool show); void onShowDiagnostics_toggled(bool show); + void onShowUAVInfo_toggled(bool show); void onShowHomeAct_toggled(bool show); void onGoZoomInAct_triggered(); void onGoZoomOutAct_triggered(); @@ -206,26 +192,20 @@ private slots: void onGoUAVAct_triggered(); void onFollowUAVpositionAct_toggled(bool checked); void onFollowUAVheadingAct_toggled(bool checked); - //void onOpenWayPointEditorAct_triggered(); void onAddWayPointAct_triggered(); void onEditWayPointAct_triggered(); - void onLockWayPointAct_triggered(); - void onDeleteWayPointAct_triggered(); - void onClearWayPointsAct_triggered(); void onMapModeActGroup_triggered(QAction *action); void onZoomActGroup_triggered(QAction *action); void onHomeMagicWaypointAct_triggered(); void onShowSafeAreaAct_toggled(bool show); void onSafeAreaActGroup_triggered(QAction *action); - void onMaxUpdateRateActGroup_triggered(QAction *action); /*UAV*/ - void onShowTrailAct_toggled(bool show); void onShowTrailLineAct_toggled(bool); void onShowUAVAct_toggled(bool show); - void onShowUAVtrailLineAct_toggled(bool show); void onShowUAVtrailAct_toggled(bool show); void onClearUAVtrailAct_triggered(); + void onUAVtrailTimeActGroup_triggered(QAction *action); void onUAVtrailDistanceActGroup_triggered(QAction *action); void onUAVtrailTypeActGroup_triggered(QAction *action); @@ -239,74 +219,53 @@ private slots: void onGPStrailDistanceActGroup_triggered(QAction *action); void onGPStrailTypeActGroup_triggered(QAction *action); - + void onMaxUpdateRateActGroup_triggered(QAction *action); + void onChangeDefaultLocalAndZoom(); + void onHomeDoubleClick(HomeItem*); + void onOverlayOpacityActGroup_triggered(QAction *action); private: - - // ***** - - int m_min_zoom; - int m_max_zoom; - + int m_min_zoom; + int m_max_zoom; double m_heading; // uav heading - - internals::PointLatLng m_mouse_lat_lon; - internals::PointLatLng m_context_menu_lat_lon; - - int m_prev_tile_number; - + internals::PointLatLng m_mouse_lat_lon; + internals::PointLatLng m_context_menu_lat_lon; + int m_prev_tile_number; opMapModeType m_map_mode; - - int m_maxUpdateRate; - - t_home m_home_position; - - t_waypoint m_magic_waypoint; - + int m_maxUpdateRate; + t_home m_home_position; QStringList findPlaceWordList; - QCompleter *findPlaceCompleter; + QCompleter *findPlaceCompleter; QTimer *m_updateTimer; QTimer *m_statusUpdateTimer; - Ui::OPMap_Widget *m_widget; - mapcontrol::OPMapWidget *m_map; ExtensionSystem::PluginManager *pm; - UAVObjectManager *obm; - UAVObjectUtilManager *obum; - - //opmap_waypointeditor_dialog waypoint_editor_dialog; - - //opmap_edit_waypoint_dialog waypoint_edit_dialog; + UAVObjectManager *obm; + UAVObjectUtilManager *obum; QStandardItemModel wayPoint_treeView_model; - mapcontrol::WayPointItem *m_mouse_waypoint; PathCompiler *pathCompiler; - QList m_waypoint_list; QMutex m_waypoint_list_mutex; QMutex m_map_mutex; - bool m_telemetry_connected; - - // ***** - - void createActions(); + bool m_telemetry_connected; QAction *closeAct1; QAction *closeAct2; QAction *reloadAct; QAction *ripAct; - QAction *copyMouseLatLonToClipAct; + QAction *copyMouseLatLonToClipAct; QAction *copyMouseLatToClipAct; QAction *copyMouseLonToClipAct; - QAction *findPlaceAct; QAction *showCompassAct; QAction *showDiagnostics; + QAction *showUAVInfo; QAction *showHomeAct; QAction *zoomInAct; QAction *zoomOutAct; @@ -316,15 +275,17 @@ private: QAction *goUAVAct; QAction *followUAVpositionAct; QAction *followUAVheadingAct; - QAction *wayPointEditorAct; + QAction *homeMagicWaypointAct; + + // Waypoint actions QAction *addWayPointAct; QAction *editWayPointAct; QAction *lockWayPointAct; QAction *deleteWayPointAct; QAction *clearWayPointsAct; - QAction *homeMagicWaypointAct; QAction *showSafeAreaAct; + QAction *changeDefaultLocalAndZoom; QActionGroup *safeAreaActGroup; QList safeAreaAct; @@ -357,23 +318,20 @@ private: QList mapModeAct; QActionGroup *zoomActGroup; + QActionGroup *overlayOpacityActGroup; QList zoomAct; + QList overlayOpacityAct; QActionGroup *maxUpdateRateActGroup; QList maxUpdateRateAct; // ***** - void homeMagicWaypoint(); - + void createActions(); + void homeMagicWaypoint(); void moveToMagicWaypointPosition(); - - void loadComboBoxLines(QComboBox *comboBox, QString filename); - void saveComboBoxLines(QComboBox *comboBox, QString filename); - void hideMagicWaypointControls(); void showMagicWaypointControls(); - void keepMagicWaypointWithInSafeArea(); double distance(internals::PointLatLng from, internals::PointLatLng to); @@ -386,7 +344,10 @@ private: void setMapFollowingMode(); - bool setHomeLocationObject(); + bool setHomeLocationObject(); + QMenu contextMenu; + internals::PointLatLng lastLatLngMouse; + WayPointItem * magicWayPoint; }; #endif /* OPMAP_GADGETWIDGET_H_ */ diff --git a/ground/openpilotgcs/src/plugins/opmap/opmapplugin.cpp b/ground/openpilotgcs/src/plugins/opmap/opmapplugin.cpp index 5f78b8bf8..1c0f5e057 100644 --- a/ground/openpilotgcs/src/plugins/opmap/opmapplugin.cpp +++ b/ground/openpilotgcs/src/plugins/opmap/opmapplugin.cpp @@ -2,7 +2,7 @@ ****************************************************************************** * * @file opmapplugin.cpp - * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @addtogroup GCSPlugins GCS Plugins * @{ * @addtogroup OPMapPlugin OpenPilot Map Plugin diff --git a/ground/openpilotgcs/src/plugins/opmap/opmapplugin.h b/ground/openpilotgcs/src/plugins/opmap/opmapplugin.h index 93b9351ac..3da9926cf 100644 --- a/ground/openpilotgcs/src/plugins/opmap/opmapplugin.h +++ b/ground/openpilotgcs/src/plugins/opmap/opmapplugin.h @@ -2,7 +2,7 @@ ****************************************************************************** * * @file opmapplugin.h - * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @addtogroup GCSPlugins GCS Plugins * @{ * @addtogroup OPMapPlugin OpenPilot Map Plugin diff --git a/ground/openpilotgcs/src/plugins/opmap/pathplanner.cpp b/ground/openpilotgcs/src/plugins/opmap/pathplanner.cpp new file mode 100644 index 000000000..aed5eed6e --- /dev/null +++ b/ground/openpilotgcs/src/plugins/opmap/pathplanner.cpp @@ -0,0 +1,119 @@ +/** + ****************************************************************************** + * + * @file pathplanner.cpp + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. + * @addtogroup GCSPlugins GCS Plugins + * @{ + * @addtogroup OPMapPlugin OpenPilot Map Plugin + * @{ + * @brief The OpenPilot Map plugin + *****************************************************************************/ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "pathplanner.h" +#include "ui_pathplanner.h" +#include "widgetdelegates.h" +#include +#include + +pathPlanner::pathPlanner(QWidget *parent) : + QWidget(parent), + ui(new Ui::pathPlannerUI),wid(NULL),myModel(NULL) +{ + ui->setupUi(this); +} + +pathPlanner::~pathPlanner() +{ + delete ui; + if(wid) + delete wid; +} +void pathPlanner::setModel(flightDataModel *model,QItemSelectionModel *selection) +{ + myModel=model; + ui->tableView->setModel(model); + ui->tableView->setSelectionModel(selection); + ui->tableView->setSelectionBehavior(QAbstractItemView::SelectRows); + ui->tableView->setItemDelegate(new MapDataDelegate(this)); + connect(model,SIGNAL(rowsInserted(const QModelIndex&,int,int)),this,SLOT(rowsInserted(const QModelIndex&,int,int))); + wid=new opmap_edit_waypoint_dialog(NULL,model,selection); + ui->tableView->resizeColumnsToContents(); +} + +void pathPlanner::rowsInserted ( const QModelIndex & parent, int start, int end ) +{ + Q_UNUSED(parent); + for(int x=start;xtableView->model()->index(x,flightDataModel::MODE); + ui->tableView->openPersistentEditor(index); + index=ui->tableView->model()->index(x,flightDataModel::CONDITION); + ui->tableView->openPersistentEditor(index); + index=ui->tableView->model()->index(x,flightDataModel::COMMAND); + ui->tableView->openPersistentEditor(index); + ui->tableView->size().setHeight(10); + } +} + +void pathPlanner::on_tbAdd_clicked() +{ + ui->tableView->model()->insertRow(ui->tableView->model()->rowCount()); +} + +void pathPlanner::on_tbDelete_clicked() +{ + ui->tableView->model()->removeRow(ui->tableView->selectionModel()->currentIndex().row()); +} + +void pathPlanner::on_tbInsert_clicked() +{ + ui->tableView->model()->insertRow(ui->tableView->selectionModel()->currentIndex().row()); +} + +void pathPlanner::on_tbReadFromFile_clicked() +{ + if(!myModel) + return; + QString fileName = QFileDialog::getOpenFileName(this, tr("Open File")); + myModel->readFromFile(fileName); +} + +void pathPlanner::on_tbSaveToFile_clicked() +{ + if(!myModel) + return; + QString fileName = QFileDialog::getSaveFileName(this, tr("Save File")); + myModel->writeToFile(fileName); +} + +void pathPlanner::on_tbDetails_clicked() +{ + if(wid) + wid->show(); +} + +void pathPlanner::on_tbSendToUAV_clicked() +{ + emit sendPathPlanToUAV(); +} + +void pathPlanner::on_tbFetchFromUAV_clicked() +{ + emit receivePathPlanFromUAV(); +} diff --git a/ground/openpilotgcs/src/plugins/opmap/pathplanner.h b/ground/openpilotgcs/src/plugins/opmap/pathplanner.h new file mode 100644 index 000000000..274e0ae67 --- /dev/null +++ b/ground/openpilotgcs/src/plugins/opmap/pathplanner.h @@ -0,0 +1,75 @@ +/** + ****************************************************************************** + * + * @file pathplanner.h + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. + * @addtogroup GCSPlugins GCS Plugins + * @{ + * @addtogroup OPMapPlugin OpenPilot Map Plugin + * @{ + * @brief The OpenPilot Map plugin + *****************************************************************************/ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef PATHPLANNER_H +#define PATHPLANNER_H + +#include +#include "flightdatamodel.h" +#include "opmap_edit_waypoint_dialog.h" +namespace Ui { +class pathPlannerUI; +} + +class pathPlanner : public QWidget +{ + Q_OBJECT + +public: + explicit pathPlanner(QWidget *parent = 0); + ~pathPlanner(); + + void setModel(flightDataModel *model,QItemSelectionModel *selection); +private slots: + void rowsInserted ( const QModelIndex & parent, int start, int end ); + + void on_tbAdd_clicked(); + + void on_tbDelete_clicked(); + + void on_tbInsert_clicked(); + + void on_tbReadFromFile_clicked(); + + void on_tbSaveToFile_clicked(); + + void on_tbDetails_clicked(); + + void on_tbSendToUAV_clicked(); + + void on_tbFetchFromUAV_clicked(); + +private: + Ui::pathPlannerUI *ui; + opmap_edit_waypoint_dialog * wid; + flightDataModel * myModel; +signals: + void sendPathPlanToUAV(); + void receivePathPlanFromUAV(); +}; + +#endif // PATHPLANNER_H diff --git a/ground/openpilotgcs/src/plugins/opmap/pathplanner.ui b/ground/openpilotgcs/src/plugins/opmap/pathplanner.ui new file mode 100644 index 000000000..fbb59a4e3 --- /dev/null +++ b/ground/openpilotgcs/src/plugins/opmap/pathplanner.ui @@ -0,0 +1,164 @@ + + + pathPlannerUI + + + + 0 + 0 + 536 + 262 + + + + PathPlanner + + + + :/core/images/openpilot_logo_64.png:/core/images/openpilot_logo_64.png + + + + + + + + Add Leg + + + ... + + + + :/opmap/images/plus3.png:/opmap/images/plus3.png + + + + + + + Delete Leg + + + ... + + + + :/opmap/images/stopb.png:/opmap/images/stopb.png + + + + + + + Insert Leg + + + ... + + + + :/opmap/images/forward_alt.png:/opmap/images/forward_alt.png + + + + + + + Read from file + + + ... + + + + :/opmap/images/unarchive.png:/opmap/images/unarchive.png + + + + + + + Save to file + + + ... + + + + :/opmap/images/Ekisho Deep Ocean HD1.png:/opmap/images/Ekisho Deep Ocean HD1.png + + + + + + + Send to UAV + + + ... + + + + :/opmap/images/up_alt.png:/opmap/images/up_alt.png + + + + + + + Fetch from UAV + + + ... + + + + :/opmap/images/down_alt.png:/opmap/images/down_alt.png + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Open Details + + + ... + + + + :/opmap/images/star.png:/opmap/images/star.png + + + + + + + + + QAbstractItemView::SelectRows + + + + + + + + + + + diff --git a/ground/openpilotgcs/src/plugins/opmap/widgetdelegates.cpp b/ground/openpilotgcs/src/plugins/opmap/widgetdelegates.cpp new file mode 100644 index 000000000..7bd385842 --- /dev/null +++ b/ground/openpilotgcs/src/plugins/opmap/widgetdelegates.cpp @@ -0,0 +1,143 @@ +/** + ****************************************************************************** + * + * @file widgetdelegates.cpp + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. + * @addtogroup GCSPlugins GCS Plugins + * @{ + * @addtogroup OPMapPlugin OpenPilot Map Plugin + * @{ + * @brief The OpenPilot Map plugin + *****************************************************************************/ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#include "widgetdelegates.h" +#include +#include +#include +QWidget *MapDataDelegate::createEditor(QWidget *parent, + const QStyleOptionViewItem & option, + const QModelIndex & index) const +{ + int column=index.column(); + QComboBox * box; + switch(column) + { + case flightDataModel::MODE: + box=new QComboBox(parent); + MapDataDelegate::loadComboBox(box,flightDataModel::MODE); + return box; + break; + case flightDataModel::CONDITION: + box=new QComboBox(parent); + MapDataDelegate::loadComboBox(box,flightDataModel::CONDITION); + return box; + break; + + case flightDataModel::COMMAND: + box=new QComboBox(parent); + MapDataDelegate::loadComboBox(box,flightDataModel::COMMAND); + return box; + break; + default: + return QItemDelegate::createEditor(parent,option,index); + break; + } + + QComboBox *editor = new QComboBox(parent); + return editor; +} + +void MapDataDelegate::setEditorData(QWidget *editor, + const QModelIndex &index) const +{ + if(!index.isValid()) + return; + QString className=editor->metaObject()->className(); + if (className.contains("QComboBox")) { + int value = index.model()->data(index, Qt::EditRole).toInt(); + QComboBox *comboBox = static_cast(editor); + int x=comboBox->findData(value); + qDebug()<<"VALUE="<setCurrentIndex(x); + } + else + QItemDelegate::setEditorData(editor, index); +} + +void MapDataDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, + const QModelIndex &index) const +{ + QString className=editor->metaObject()->className(); + if (className.contains("QComboBox")) { + QComboBox *comboBox = static_cast(editor); + int value = comboBox->itemData(comboBox->currentIndex()).toInt(); + model->setData(index, value, Qt::EditRole); + } + else + QItemDelegate::setModelData(editor,model,index); +} + +void MapDataDelegate::updateEditorGeometry(QWidget *editor, + const QStyleOptionViewItem &option, const QModelIndex &/* index */) const +{ + editor->setGeometry(option.rect); +} + +void MapDataDelegate::loadComboBox(QComboBox *combo, flightDataModel::pathPlanDataEnum type) +{ + switch(type) + { + case flightDataModel::MODE: + combo->addItem("Fly Direct",MODE_FLYENDPOINT); + combo->addItem("Fly Vector",MODE_FLYVECTOR); + combo->addItem("Fly Circle Right",MODE_FLYCIRCLERIGHT); + combo->addItem("Fly Circle Left",MODE_FLYCIRCLELEFT); + + combo->addItem("Drive Direct",MODE_DRIVEENDPOINT); + combo->addItem("Drive Vector",MODE_DRIVEVECTOR); + combo->addItem("Drive Circle Right",MODE_DRIVECIRCLELEFT); + combo->addItem("Drive Circle Left",MODE_DRIVECIRCLERIGHT); + + combo->addItem("Fixed Attitude",MODE_FIXEDATTITUDE); + combo->addItem("Set Accessory",MODE_SETACCESSORY); + combo->addItem("Disarm Alarm",MODE_DISARMALARM); + break; + case flightDataModel::CONDITION: + combo->addItem("None",ENDCONDITION_NONE); + combo->addItem("Timeout",ENDCONDITION_TIMEOUT); + combo->addItem("Distance to tgt",ENDCONDITION_DISTANCETOTARGET); + combo->addItem("Leg remaining",ENDCONDITION_LEGREMAINING); + combo->addItem("Above Altitude",ENDCONDITION_ABOVEALTITUDE); + combo->addItem("Pointing towards next",ENDCONDITION_POINTINGTOWARDSNEXT); + combo->addItem("Python script",ENDCONDITION_PYTHONSCRIPT); + combo->addItem("Immediate",ENDCONDITION_IMMEDIATE); + break; + case flightDataModel::COMMAND: + combo->addItem("On conditon next wp",COMMAND_ONCONDITIONNEXTWAYPOINT); + combo->addItem("On NOT conditon next wp",COMMAND_ONNOTCONDITIONNEXTWAYPOINT); + combo->addItem("On conditon jump wp",COMMAND_ONCONDITIONJUMPWAYPOINT); + combo->addItem("On NOT conditon jump wp",COMMAND_ONNOTCONDITIONJUMPWAYPOINT); + combo->addItem("On conditon jump wp else next wp",COMMAND_IFCONDITIONJUMPWAYPOINTELSENEXTWAYPOINT); + break; + default: + break; + } +} + +MapDataDelegate::MapDataDelegate(QObject *parent):QItemDelegate(parent) +{ +} diff --git a/ground/openpilotgcs/src/plugins/opmap/widgetdelegates.h b/ground/openpilotgcs/src/plugins/opmap/widgetdelegates.h new file mode 100644 index 000000000..ae29bc975 --- /dev/null +++ b/ground/openpilotgcs/src/plugins/opmap/widgetdelegates.h @@ -0,0 +1,64 @@ +/** + ****************************************************************************** + * + * @file widgetdelegates.h + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. + * @addtogroup GCSPlugins GCS Plugins + * @{ + * @addtogroup OPMapPlugin OpenPilot Map Plugin + * @{ + * @brief The OpenPilot Map plugin + *****************************************************************************/ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef WIDGETDELEGATES_H +#define WIDGETDELEGATES_H +#include +#include +#include "flightdatamodel.h" + + +class MapDataDelegate : public QItemDelegate + { + Q_OBJECT + + public: + typedef enum { MODE_FLYENDPOINT=0, MODE_FLYVECTOR=1, MODE_FLYCIRCLERIGHT=2, MODE_FLYCIRCLELEFT=3, + MODE_DRIVEENDPOINT=4, MODE_DRIVEVECTOR=5, MODE_DRIVECIRCLELEFT=6, MODE_DRIVECIRCLERIGHT=7, + MODE_FIXEDATTITUDE=8, MODE_SETACCESSORY=9, MODE_DISARMALARM=10 } ModeOptions; + typedef enum { ENDCONDITION_NONE=0, ENDCONDITION_TIMEOUT=1, ENDCONDITION_DISTANCETOTARGET=2, + ENDCONDITION_LEGREMAINING=3, ENDCONDITION_ABOVEALTITUDE=4, ENDCONDITION_POINTINGTOWARDSNEXT=5, + ENDCONDITION_PYTHONSCRIPT=6, ENDCONDITION_IMMEDIATE=7 } EndConditionOptions; + typedef enum { COMMAND_ONCONDITIONNEXTWAYPOINT=0, COMMAND_ONNOTCONDITIONNEXTWAYPOINT=1, + COMMAND_ONCONDITIONJUMPWAYPOINT=2, COMMAND_ONNOTCONDITIONJUMPWAYPOINT=3, + COMMAND_IFCONDITIONJUMPWAYPOINTELSENEXTWAYPOINT=4 } CommandOptions; + + MapDataDelegate(QObject *parent = 0); + + QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, + const QModelIndex &index) const; + + void setEditorData(QWidget *editor, const QModelIndex &index) const; + void setModelData(QWidget *editor, QAbstractItemModel *model, + const QModelIndex &index) const; + + void updateEditorGeometry(QWidget *editor, + const QStyleOptionViewItem &option, const QModelIndex &index) const; + static void loadComboBox(QComboBox * combo,flightDataModel::pathPlanDataEnum type); + }; + +#endif // WIDGETDELEGATES_H diff --git a/ground/openpilotgcs/src/plugins/uavobjects/uavobject.cpp b/ground/openpilotgcs/src/plugins/uavobjects/uavobject.cpp index d01caba21..101ce5d54 100644 --- a/ground/openpilotgcs/src/plugins/uavobjects/uavobject.cpp +++ b/ground/openpilotgcs/src/plugins/uavobjects/uavobject.cpp @@ -485,6 +485,14 @@ void UAVObject::emitTransactionCompleted(bool success) emit transactionCompleted(this, success); } +/** + * Emit the newInstance event + */ +void UAVObject::emitNewInstance(UAVObject * obj) +{ + emit newInstance(obj); +} + /** * Initialize a UAVObjMetadata object. * \param[in] metadata The metadata object diff --git a/ground/openpilotgcs/src/plugins/uavobjects/uavobject.h b/ground/openpilotgcs/src/plugins/uavobjects/uavobject.h index d092c6731..cae6d95a0 100644 --- a/ground/openpilotgcs/src/plugins/uavobjects/uavobject.h +++ b/ground/openpilotgcs/src/plugins/uavobjects/uavobject.h @@ -126,6 +126,7 @@ public: QString toStringBrief(); QString toStringData(); void emitTransactionCompleted(bool success); + void emitNewInstance(UAVObject *); // Metadata accessors static void MetadataInitialize(Metadata& meta); @@ -154,6 +155,7 @@ signals: void objectUnpacked(UAVObject* obj); void updateRequested(UAVObject* obj); void transactionCompleted(UAVObject* obj, bool success); + void newInstance(UAVObject* obj); private slots: void fieldUpdated(UAVObjectField* field); diff --git a/ground/openpilotgcs/src/plugins/uavobjects/uavobjectmanager.cpp b/ground/openpilotgcs/src/plugins/uavobjects/uavobjectmanager.cpp index c4f6f656e..5038b7bba 100644 --- a/ground/openpilotgcs/src/plugins/uavobjects/uavobjectmanager.cpp +++ b/ground/openpilotgcs/src/plugins/uavobjects/uavobjectmanager.cpp @@ -89,6 +89,7 @@ bool UAVObjectManager::registerObject(UAVDataObject* obj) UAVDataObject* cobj = obj->clone(instidx); cobj->initialize(mobj); objects[objidx].append(cobj); + getObject(cobj->getObjID())->emitNewInstance(cobj); emit newInstance(cobj); } // Finally, initialize the actual object instance @@ -105,6 +106,7 @@ bool UAVObjectManager::registerObject(UAVDataObject* obj) } // Add the actual object instance in the list objects[objidx].append(obj); + getObject(obj->getObjID())->emitNewInstance(obj); emit newInstance(obj); return true; } diff --git a/ground/openpilotgcs/src/plugins/uavobjects/uavobjects.pro b/ground/openpilotgcs/src/plugins/uavobjects/uavobjects.pro index 70f120115..8b5b7deb3 100755 --- a/ground/openpilotgcs/src/plugins/uavobjects/uavobjects.pro +++ b/ground/openpilotgcs/src/plugins/uavobjects/uavobjects.pro @@ -90,11 +90,12 @@ HEADERS += $$UAVOBJECT_SYNTHETICS/accessorydesired.h \ $$UAVOBJECT_SYNTHETICS/attitudesettings.h \ $$UAVOBJECT_SYNTHETICS/txpidsettings.h \ $$UAVOBJECT_SYNTHETICS/cameradesired.h \ - $$UAVOBJECT_SYNTHETICS/waypoint.h \ - $$UAVOBJECT_SYNTHETICS/waypointactive.h \ $$UAVOBJECT_SYNTHETICS/faultsettings.h \ $$UAVOBJECT_SYNTHETICS/pipxsettings.h \ - $$UAVOBJECT_SYNTHETICS/pipxstatus.h + $$UAVOBJECT_SYNTHETICS/pipxstatus.h \ + $$UAVOBJECT_SYNTHETICS/waypoint.h \ + $$UAVOBJECT_SYNTHETICS/waypointactive.h \ + $$UAVOBJECT_SYNTHETICS/pathaction.h SOURCES += $$UAVOBJECT_SYNTHETICS/accessorydesired.cpp \ $$UAVOBJECT_SYNTHETICS/baroaltitude.cpp \ @@ -164,8 +165,9 @@ SOURCES += $$UAVOBJECT_SYNTHETICS/accessorydesired.cpp \ $$UAVOBJECT_SYNTHETICS/attitudesettings.cpp \ $$UAVOBJECT_SYNTHETICS/txpidsettings.cpp \ $$UAVOBJECT_SYNTHETICS/cameradesired.cpp \ - $$UAVOBJECT_SYNTHETICS/waypoint.cpp \ - $$UAVOBJECT_SYNTHETICS/waypointactive.cpp \ $$UAVOBJECT_SYNTHETICS/faultsettings.cpp \ $$UAVOBJECT_SYNTHETICS/pipxsettings.cpp \ - $$UAVOBJECT_SYNTHETICS/pipxstatus.cpp + $$UAVOBJECT_SYNTHETICS/pipxstatus.cpp \ + $$UAVOBJECT_SYNTHETICS/waypoint.cpp \ + $$UAVOBJECT_SYNTHETICS/waypointactive.cpp \ + $$UAVOBJECT_SYNTHETICS/pathaction.cpp diff --git a/ground/openpilotgcs/src/plugins/uavobjectwidgetutils/configtaskwidget.cpp b/ground/openpilotgcs/src/plugins/uavobjectwidgetutils/configtaskwidget.cpp index 09d6e21a5..74737c019 100644 --- a/ground/openpilotgcs/src/plugins/uavobjectwidgetutils/configtaskwidget.cpp +++ b/ground/openpilotgcs/src/plugins/uavobjectwidgetutils/configtaskwidget.cpp @@ -58,9 +58,18 @@ void ConfigTaskWidget::addWidget(QWidget * widget) * Add an object to the management system * @param objectName name of the object to add to the management system */ -void ConfigTaskWidget::addUAVObject(QString objectName) +void ConfigTaskWidget::addUAVObject(QString objectName,QList * reloadGroups) { - addUAVObjectToWidgetRelation(objectName,"",NULL); + addUAVObjectToWidgetRelation(objectName,"",NULL,0,1,false,reloadGroups); +} + +void ConfigTaskWidget::addUAVObject(UAVObject *objectName, QList *reloadGroups) +{ + QString objstr; + if(objectName) + objstr=objectName->getName(); + addUAVObject(objstr, reloadGroups); + } /** * Add an UAVObject field to widget relation to the management system @@ -79,6 +88,17 @@ void ConfigTaskWidget::addUAVObjectToWidgetRelation(QString object, QString fiel Q_ASSERT(_field); addUAVObjectToWidgetRelation(object,field,widget,_field->getElementNames().indexOf(index)); } + +void ConfigTaskWidget::addUAVObjectToWidgetRelation(UAVObject *obj, UAVObjectField * field, QWidget *widget, QString index) +{ + QString objstr; + QString fieldstr; + if(obj) + objstr=obj->getName(); + if(field) + fieldstr=field->getName(); + addUAVObjectToWidgetRelation(objstr, fieldstr, widget, index); +} /** * Add a UAVObject field to widget relation to the management system * @param object name of the object to add @@ -104,6 +124,28 @@ void ConfigTaskWidget::addUAVObjectToWidgetRelation(QString object, QString fiel } addUAVObjectToWidgetRelation(object, field, widget,index,scale,isLimited,defaultReloadGroups,instID); } + +void ConfigTaskWidget::addUAVObjectToWidgetRelation(UAVObject *obj, UAVObjectField *field, QWidget *widget, QString element, double scale, bool isLimited, QList *defaultReloadGroups, quint32 instID) +{ + QString objstr; + QString fieldstr; + if(obj) + objstr=obj->getName(); + if(field) + fieldstr=field->getName(); + addUAVObjectToWidgetRelation(objstr, fieldstr, widget, element, scale, isLimited, defaultReloadGroups, instID); +} +void ConfigTaskWidget::addUAVObjectToWidgetRelation(UAVObject * obj,UAVObjectField * field, QWidget * widget, int index,double scale,bool isLimited,QList* defaultReloadGroups, quint32 instID) +{ + QString objstr; + QString fieldstr; + if(obj) + objstr=obj->getName(); + if(field) + fieldstr=field->getName(); + addUAVObjectToWidgetRelation(objstr,fieldstr,widget,index,scale,isLimited,defaultReloadGroups,instID); +} + /** * Add an UAVObject field to widget relation to the management system * @param object name of the object to add @@ -149,7 +191,21 @@ void ConfigTaskWidget::addUAVObjectToWidgetRelation(QString object, QString fiel } if(widget==NULL) { - // do nothing + if(defaultReloadGroups && obj) + { + foreach(int i,*defaultReloadGroups) + { + if(this->defaultReloadGroups.contains(i)) + { + this->defaultReloadGroups.value(i)->append(ow); + } + else + { + this->defaultReloadGroups.insert(i,new QList()); + this->defaultReloadGroups.value(i)->append(ow); + } + } + } } else { @@ -203,7 +259,6 @@ UAVObjectManager* ConfigTaskWidget::getObjectManager() { Q_ASSERT(objMngr); return objMngr; } - /** * Utility function which calculates the Mean value of a list of values * @param list list of double values @@ -572,7 +627,7 @@ bool ConfigTaskWidget::addShadowWidget(QString object, QString field, QWidget *w { foreach(objectToWidget * oTw,objOfInterest) { - if(!oTw->object || !oTw->widget) + if(!oTw->object || !oTw->widget || !oTw->field) continue; if(oTw->object->getName()==object && oTw->field->getName()==field && oTw->index==index && oTw->object->getInstID()==instID) { @@ -727,6 +782,16 @@ void ConfigTaskWidget::autoLoadWidgets() } refreshWidgetsValues(); forceShadowUpdates(); + foreach(objectToWidget * ow,objOfInterest) + { + if(ow->widget) + qDebug()<<"Master:"<widget->objectName(); + foreach(shadow * sh,ow->shadowsList) + { + if(sh->widget) + qDebug()<<"Child"<widget->objectName(); + } + } } /** * Adds a widget to a list of default/reload groups @@ -793,10 +858,11 @@ void ConfigTaskWidget::addReloadButton(QPushButton *button, int buttonGroup) void ConfigTaskWidget::defaultButtonClicked() { int group=sender()->property("group").toInt(); + emit defaultRequested(group); QList * list=defaultReloadGroups.value(group); foreach(objectToWidget * oTw,*list) { - if(!oTw->object) + if(!oTw->object || !oTw->field) continue; UAVDataObject * temp=((UAVDataObject*)oTw->object)->dirtyClone(); setWidgetFromField(oTw->widget,temp->getField(oTw->field->getName()),oTw->index,oTw->scale,oTw->isLimited); @@ -807,6 +873,8 @@ void ConfigTaskWidget::defaultButtonClicked() */ void ConfigTaskWidget::reloadButtonClicked() { + if(timeOut) + return; int group=sender()->property("group").toInt(); QList * list=defaultReloadGroups.value(group,NULL); if(!list) @@ -832,7 +900,8 @@ void ConfigTaskWidget::reloadButtonClicked() if(timeOut->isActive()) { oTw->object->requestUpdate(); - setWidgetFromField(oTw->widget,oTw->field,oTw->index,oTw->scale,oTw->isLimited); + if(oTw->widget) + setWidgetFromField(oTw->widget,oTw->field,oTw->index,oTw->scale,oTw->isLimited); } timeOut->stop(); } diff --git a/ground/openpilotgcs/src/plugins/uavobjectwidgetutils/configtaskwidget.h b/ground/openpilotgcs/src/plugins/uavobjectwidgetutils/configtaskwidget.h index 72c24adeb..2b56b8678 100644 --- a/ground/openpilotgcs/src/plugins/uavobjectwidgetutils/configtaskwidget.h +++ b/ground/openpilotgcs/src/plugins/uavobjectwidgetutils/configtaskwidget.h @@ -94,12 +94,19 @@ public: static double listMean(QList list); static double listVar(QList list); - void addUAVObject(QString objectName); + void addUAVObject(QString objectName, QList *reloadGroups=NULL); + void addUAVObject(UAVObject * objectName, QList *reloadGroups=NULL); + void addWidget(QWidget * widget); void addUAVObjectToWidgetRelation(QString object,QString field,QWidget * widget,int index=0,double scale=1,bool isLimited=false,QList* defaultReloadGroups=0,quint32 instID=0); + void addUAVObjectToWidgetRelation(UAVObject *obj, UAVObjectField * field, QWidget *widget, int index=0, double scale=1, bool isLimited=false, QList *defaultReloadGroups=0, quint32 instID=0); + void addUAVObjectToWidgetRelation(QString object,QString field,QWidget * widget,QString element,double scale,bool isLimited=false,QList* defaultReloadGroups=0,quint32 instID=0); + void addUAVObjectToWidgetRelation(UAVObject *obj, UAVObjectField * field,QWidget * widget,QString element,double scale,bool isLimited=false,QList* defaultReloadGroups=0,quint32 instID=0); + void addUAVObjectToWidgetRelation(QString object, QString field, QWidget *widget, QString index); + void addUAVObjectToWidgetRelation(UAVObject *obj, UAVObjectField * field, QWidget *widget, QString index); //BUTTONS// void addApplySaveButtons(QPushButton * update,QPushButton * save); @@ -140,6 +147,7 @@ signals: void autoPilotConnected(); //fired when the autopilot disconnects void autoPilotDisconnected(); + void defaultRequested(int group); private slots: void objectUpdated(UAVObject*); void defaultButtonClicked(); diff --git a/ground/openpilotgcs/src/plugins/uavobjectwidgetutils/mixercurveline.h b/ground/openpilotgcs/src/plugins/uavobjectwidgetutils/mixercurveline.h index 80fb50e0c..417f5b1ca 100644 --- a/ground/openpilotgcs/src/plugins/uavobjectwidgetutils/mixercurveline.h +++ b/ground/openpilotgcs/src/plugins/uavobjectwidgetutils/mixercurveline.h @@ -51,7 +51,7 @@ public: void adjust(); - enum { Type = UserType + 2 }; + enum { Type = UserType + 12 }; int type() const { return Type; } protected: diff --git a/ground/openpilotgcs/src/plugins/uavobjectwidgetutils/mixercurvepoint.h b/ground/openpilotgcs/src/plugins/uavobjectwidgetutils/mixercurvepoint.h index eca445d32..8c658b993 100644 --- a/ground/openpilotgcs/src/plugins/uavobjectwidgetutils/mixercurvepoint.h +++ b/ground/openpilotgcs/src/plugins/uavobjectwidgetutils/mixercurvepoint.h @@ -45,7 +45,7 @@ public: void addEdge(Edge *edge); QList edges() const; - enum { Type = UserType + 1 }; + enum { Type = UserType + 10 }; int type() const { return Type; } diff --git a/ground/openpilotgcs/src/plugins/uavobjectwidgetutils/smartsavebutton.cpp b/ground/openpilotgcs/src/plugins/uavobjectwidgetutils/smartsavebutton.cpp index 9b0268a4e..28fe3c997 100644 --- a/ground/openpilotgcs/src/plugins/uavobjectwidgetutils/smartsavebutton.cpp +++ b/ground/openpilotgcs/src/plugins/uavobjectwidgetutils/smartsavebutton.cpp @@ -151,6 +151,7 @@ void smartSaveButton::setObjects(QList list) void smartSaveButton::addObject(UAVDataObject * obj) { + Q_ASSERT(obj); if(!objects.contains(obj)) objects.append(obj); } diff --git a/overo b/overo index 21ff30e62..335a3486d 160000 --- a/overo +++ b/overo @@ -1 +1 @@ -Subproject commit 21ff30e625e699bc1a150e5a7fa86588d9df6262 +Subproject commit 335a3486dd41e48345209d0a65d49a8cc8b442a1 diff --git a/shared/uavobjectdefinition/hwsettings.xml b/shared/uavobjectdefinition/hwsettings.xml index 052c011eb..0408c7032 100644 --- a/shared/uavobjectdefinition/hwsettings.xml +++ b/shared/uavobjectdefinition/hwsettings.xml @@ -2,7 +2,7 @@ Selection of optional hardware configurations. - + diff --git a/shared/uavobjectdefinition/pathaction.xml b/shared/uavobjectdefinition/pathaction.xml new file mode 100644 index 000000000..8261c170c --- /dev/null +++ b/shared/uavobjectdefinition/pathaction.xml @@ -0,0 +1,30 @@ + + + A waypoint command the pathplanner is to use at a certain waypoint + + + + + + + + + + + + + + + + diff --git a/shared/uavobjectdefinition/taskinfo.xml b/shared/uavobjectdefinition/taskinfo.xml index 355a1b1a2..2e972c7e6 100644 --- a/shared/uavobjectdefinition/taskinfo.xml +++ b/shared/uavobjectdefinition/taskinfo.xml @@ -1,9 +1,9 @@ Task information - - - + + +