Skip to content

Commit

Permalink
Merge pull request #113 from All4Gis/dev
Browse files Browse the repository at this point in the history
refactor/Clean code
  • Loading branch information
All4Gis authored Apr 15, 2021
2 parents bd7500e + 010fc59 commit ff1f105
Show file tree
Hide file tree
Showing 25 changed files with 6,734 additions and 6,994 deletions.
1 change: 1 addition & 0 deletions code/QgsFmvConstants.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
EARTH_MEAN_RADIUS = 6371008.8
WGS84String = "WGS84"
encoding = "utf-8"
defaultTargetWidth = 200.0

# Klv variables
UASLocalMetadataSet = b"\x06\x0e+4\x02\x0b\x01\x01\x0e\x01\x03\x01\x01\x00\x00\x00"
Expand Down
2 changes: 0 additions & 2 deletions code/geo/QgsGeoUtils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# -*- coding: utf-8 -*-
from math import degrees, radians, sin, cos, asin, atan2

from QGIS_FMV.QgsFmvConstants import EARTH_MEAN_RADIUS


Expand Down
11,634 changes: 5,817 additions & 5,817 deletions code/gui/resources_rc.py

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion code/gui/ui_FmvPlayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1126,5 +1126,5 @@ def retranslateUi(self, PlayerWindow):
)


from QGIS_FMV.video.QgsVideo import VideoWidget
from QGIS_FMV.video.QgsVideoWidget import VideoWidget
from QGIS_FMV.gui import resources_rc
3 changes: 1 addition & 2 deletions code/i18n/qgisfmv.pro
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
FORMS = ../ui/ui_FmvAbout.ui \
../ui/ui_ColorDialog.ui \
../ui/ui_FmvManager.ui \
../ui/ui_FmvMetadata.ui \
../ui/ui_FmvOptions.ui \
Expand All @@ -14,7 +13,7 @@ SOURCES = ../QgsFmv.py \
../manager/QgsManager.py \
../player/QgsFmvOptions.py \
../manager/QgsMultiplexor.py \
../utils/QgsJsonModel.py \
../reports/QgsJsonModel.py \
../utils/QgsFmvInstaller.py \
../manager/QgsFmvOpenStream.py

Expand Down
159 changes: 86 additions & 73 deletions code/i18n/qgisfmv_ca.ts

Large diffs are not rendered by default.

193 changes: 68 additions & 125 deletions code/i18n/qgisfmv_en.ts

Large diffs are not rendered by default.

159 changes: 86 additions & 73 deletions code/i18n/qgisfmv_es.ts

Large diffs are not rendered by default.

193 changes: 68 additions & 125 deletions code/i18n/qgisfmv_fa.ts

Large diffs are not rendered by default.

193 changes: 68 additions & 125 deletions code/i18n/qgisfmv_fr.ts

Large diffs are not rendered by default.

196 changes: 68 additions & 128 deletions code/i18n/qgisfmv_gl.ts

Large diffs are not rendered by default.

193 changes: 68 additions & 125 deletions code/i18n/qgisfmv_it.ts

Large diffs are not rendered by default.

12 changes: 5 additions & 7 deletions code/klvdata/QgsFmvKlvReader.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@
import subprocess
from QGIS_FMV.utils.QgsUtils import QgsUtils as qgsu
from QGIS_FMV.utils.QgsFmvUtils import (
_time_to_seconds,
_seconds_to_time_frac,
_add_secs_to_time,
_spawn,
)

from datetime import datetime

from QGIS_FMV.QgsFmvConstants import (
Expand Down Expand Up @@ -232,15 +230,15 @@ def getSize(self, t):
return size

def bufferParalell(self, start, size):
start_sec = _time_to_seconds(start)
start_sec = qgsu._time_to_seconds(start)
start_milisec = int(start_sec * 1000)

for k in range(
start_milisec, start_milisec + (size * self.interval), self.interval
):
cTime = k / 1000.0
nTime = (k + self.pass_time) / 1000.0
new_key = _seconds_to_time_frac(cTime)
new_key = qgsu._seconds_to_time_frac(cTime)
if new_key not in self._meta:
# qgsu.showUserAndLogMessage("QgsFmvUtils", 'buffering: ' + _seconds_to_time_frac(cTime) + " to " + _seconds_to_time_frac(nTime), onlyLog=True)
self._meta[new_key] = callBackMetadataThread(
Expand All @@ -250,7 +248,7 @@ def bufferParalell(self, start, size):
"-ss",
new_key,
"-to",
_seconds_to_time_frac(nTime),
qgsu._seconds_to_time_frac(nTime),
"-map",
"0:d:" + str(self.klv_index),
"-f",
Expand Down Expand Up @@ -282,7 +280,7 @@ def get(self, t):
new_t = s[0] + ".00" + str(r_milis) + "0"
else:
date = datetime.strptime(s[0], "%H:%M:%S")
new_t = _add_secs_to_time(date, 1) + ".0000"
new_t = qgsu._add_secs_to_time(date, 1) + ".0000"
except Exception:
qgsu.showUserAndLogMessage(
"", "wrong value for time, need . decimal" + t, onlyLog=True
Expand Down
9 changes: 3 additions & 6 deletions code/klvdata/streamparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,9 @@ def __iter__(self):
return self

def __next__(self):
try:
key, value = next(self.iter_stream)
# qgsu.showUserAndLogMessage(
# "", "Streamparser key: " + str(key) + " value: " + str(value), onlyLog=True)
except Exception as e:
print("Key {0} , error {1}".format(key, str(e)))
key, value = next(self.iter_stream)
# qgsu.showUserAndLogMessage(
# "", "Streamparser key: " + str(key) + " value: " + str(value), onlyLog=True)
if key in self.parsers:
return self.parsers[key](value)
else:
Expand Down
3 changes: 1 addition & 2 deletions code/manager/QgsManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@
except ImportError:
None

s = QSettings()


class FmvManager(QDockWidget, Ui_ManagerWindow):
""" Video Manager """
Expand Down Expand Up @@ -100,6 +98,7 @@ def loadVideosFromSettings(self):
# Get Video Manager List
VideoList = getVideoManagerList()
for load_id in VideoList:
s = QSettings()
filename = s.value(getNameSpace() + "/Manager_List/" + load_id)
_, name = os.path.split(filename)

Expand Down
109 changes: 56 additions & 53 deletions code/manager/QgsMultiplexor.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
CornerLatitudePoint3Full,
CornerLongitudePoint3Full,
CornerLatitudePoint4Full,
CornerLongitudePoint4Full
CornerLongitudePoint4Full,
)

try:
Expand All @@ -61,6 +61,7 @@
https://gist.github.com/All4Gis/509fbe06ce53a0885744d16595811e6f
"""

# Csv Encoding
encoding = "ISO-8859-1"


Expand All @@ -81,7 +82,7 @@ def __init__(self, iface, parent=None, Exts=None):
def OpenCsvFile(self):
""" Open Csv File """
filename, _ = askForFiles(
self, QCoreApplication.translate("Multiplexor", "Open file"), exts="csv"
self, QCoreApplication.translate("QgsMultiplexor", "Open file"), exts="csv"
)
if filename:
self.csv_file = filename
Expand All @@ -91,7 +92,9 @@ def OpenCsvFile(self):
def OpenVideoFile(self):
""" Open Video File """
filename, _ = askForFiles(
self, QCoreApplication.translate("Multiplexor", "Open file"), exts=self.Exts
self,
QCoreApplication.translate("QgsMultiplexor", "Open file"),
exts=self.Exts,
)
if filename:
self.video_file = filename
Expand Down Expand Up @@ -196,57 +199,49 @@ def CreateMISB(self):
# Platform Pitch Angle
if k == "OSD.pitch":
OSD_pitch = float(v)

_bytes = bytes(PlatformPitchAngle(OSD_pitch))
bufferData += _bytes

# Platform Roll Angle
if k == "OSD.roll":
OSD_roll = float(v)

_bytes = bytes(PlatformRollAngle(OSD_roll))
bufferData += _bytes

# Sensor Latitude
if k == "OSD.latitude":
OSD_latitude = float(v)

_bytes = bytes(SensorLatitude(OSD_latitude))
bufferData += _bytes

# Sensor Longitude
if k == "OSD.longitude":
OSD_longitude = float(v)

_bytes = bytes(SensorLongitude(OSD_longitude))
bufferData += _bytes

# Sensor True Altitude
if k == "OSD.altitude [m]":
OSD_altitude = float(v)

_bytes = bytes(SensorTrueAltitude(OSD_altitude))
bufferData += _bytes

# Sensor Ellipsoid Height
if k == "OSD.height [m]":
OSD_height = float(v)

_bytes = bytes(SensorEllipsoidHeightConversion(OSD_height))
bufferData += _bytes

# Sensor Relative Azimuth Angle
if k == "GIMBAL.yaw":
# GIMBAL_yaw = float(v)
GIMBAL_yaw = 0.0

_bytes = bytes(SensorRelativeAzimuthAngle(GIMBAL_yaw))
bufferData += _bytes

# Sensor Relative Elevation Angle
if k == "GIMBAL.pitch":
GIMBAL_pitch = float(v)

_bytes = bytes(SensorRelativeElevationAngle(GIMBAL_pitch))
bufferData += _bytes

Expand All @@ -257,7 +252,13 @@ def CreateMISB(self):
bufferData += _bytes

except Exception as e:
print("Multiplexer error", e)
qgsu.showUserAndLogMessage(
QCoreApplication.translate(
"Multiplexor", "Multiplexer error"
)
+ e,
onlyLog=True,
)
continue

try:
Expand All @@ -274,13 +275,11 @@ def CreateMISB(self):

# Sensor Horizontal Field of View
v = self.sp_hfov.value()

_bytes = bytes(SensorHorizontalFieldOfView(float(v)))
bufferData += _bytes

# Sensor Vertical Field of View
v = self.sp_vfov.value()

_bytes = bytes(SensorVerticalFieldOfView(float(v)))
bufferData += _bytes

Expand Down Expand Up @@ -332,43 +331,43 @@ def CreateMISB(self):
# CALCULATE CORNERS COORDINATES
# FIXME : If we add this values, the klv parse has a overflow
# Probably the packets is not created correctly
# sensor = (OSD_longitude, OSD_latitude, OSD_altitude)
# frameCenter = (framecenterlongitude, framecenterlatitude, frameCenterElevation)
# FOV = (VFOV, HFOV)
# others = (OSD_yaw, GIMBAL_yaw, targetWidth, slantRange)
# cornerPointUL, cornerPointUR, cornerPointLR, cornerPointLL = CornerEstimationWithoutOffsets(sensor=sensor, frameCenter=frameCenter, FOV=FOV, others=others)
#
# # Corner Latitude Point 1 (Full) CornerLatitudePoint1Full
# _bytes = bytes(CornerLatitudePoint1Full(cornerPointUL[0]))
# bufferData += _bytes
#
# # Corner Longitude Point 1 (Full)
# _bytes = bytes(CornerLongitudePoint1Full(cornerPointUL[1]))
# bufferData += _bytes
#
# # Corner Latitude Point 2 (Full)
# _bytes = bytes(CornerLatitudePoint2Full(cornerPointUR[0]))
# bufferData += _bytes
#
# # Corner Longitude Point 2 (Full)
# _bytes = bytes(CornerLongitudePoint2Full(cornerPointUR[1]))
# bufferData += _bytes
#
# # Corner Latitude Point 3 (Full)
# _bytes = bytes(CornerLatitudePoint3Full(cornerPointLR[0]))
# bufferData += _bytes
#
# # Corner Longitude Point 3 (Full)
# _bytes = bytes(CornerLongitudePoint3Full(cornerPointLR[1]))
# bufferData += _bytes
#
# # Corner Latitude Point 4 (Full)
# _bytes = bytes(CornerLatitudePoint4Full(cornerPointLL[0]))
# bufferData += _bytes
#
# # Corner Longitude Point 4 (Full)
# _bytes = bytes(CornerLongitudePoint4Full(cornerPointLL[1]))
# bufferData += _bytes
# sensor = (OSD_longitude, OSD_latitude, OSD_altitude)
# frameCenter = (framecenterlongitude, framecenterlatitude, frameCenterElevation)
# FOV = (VFOV, HFOV)
# others = (OSD_yaw, GIMBAL_yaw, targetWidth, slantRange)
# cornerPointUL, cornerPointUR, cornerPointLR, cornerPointLL = CornerEstimationWithoutOffsets(sensor=sensor, frameCenter=frameCenter, FOV=FOV, others=others)
#
# # Corner Latitude Point 1 (Full) CornerLatitudePoint1Full
# _bytes = bytes(CornerLatitudePoint1Full(cornerPointUL[0]))
# bufferData += _bytes
#
# # Corner Longitude Point 1 (Full)
# _bytes = bytes(CornerLongitudePoint1Full(cornerPointUL[1]))
# bufferData += _bytes
#
# # Corner Latitude Point 2 (Full)
# _bytes = bytes(CornerLatitudePoint2Full(cornerPointUR[0]))
# bufferData += _bytes
#
# # Corner Longitude Point 2 (Full)
# _bytes = bytes(CornerLongitudePoint2Full(cornerPointUR[1]))
# bufferData += _bytes
#
# # Corner Latitude Point 3 (Full)
# _bytes = bytes(CornerLatitudePoint3Full(cornerPointLR[0]))
# bufferData += _bytes
#
# # Corner Longitude Point 3 (Full)
# _bytes = bytes(CornerLongitudePoint3Full(cornerPointLR[1]))
# bufferData += _bytes
#
# # Corner Latitude Point 4 (Full)
# _bytes = bytes(CornerLatitudePoint4Full(cornerPointLL[0]))
# bufferData += _bytes
#
# # Corner Longitude Point 4 (Full)
# _bytes = bytes(CornerLongitudePoint4Full(cornerPointLL[1]))
# bufferData += _bytes

# Platform Pitch Angle (Full)
_bytes = bytes(PlatformPitchAngleFull(OSD_pitch))
Expand All @@ -394,7 +393,11 @@ def CreateMISB(self):
progress.setValue(cnt)

except Exception as e:
print("Multiplexer error : " + str(e))
qgsu.showUserAndLogMessage(
QCoreApplication.translate("Multiplexor", "Multiplexer error")
+ str(e),
onlyLog=True,
)

QApplication.restoreOverrideCursor()
QApplication.processEvents()
Expand Down Expand Up @@ -461,7 +464,7 @@ def CreateDJICsv(self, rows_list, csv_raw, time_list):
out_record = os.path.join(out_csv, filename + ".csv")
# The column that corresponds to the stop is also removed
with open(csv_raw, "r", encoding=encoding) as f_input, open(
out_record, "w", newline="", encoding="ISO-8859-1"
out_record, "w", newline="", encoding=encoding
) as f_output:
# Prevent “_csv.Error: line contains NULL byte
data = f_input.read()
Expand Down
4 changes: 2 additions & 2 deletions code/player/QgsFmvMetadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from PyQt5.QtGui import QTextFormat

from QGIS_FMV.gui.ui_FmvMetadata import Ui_FmvMetadata
from QGIS_FMV.utils.QgsFmvUtils import askForFiles, _seconds_to_time, BurnDrawingsImage
from QGIS_FMV.utils.QgsFmvUtils import askForFiles, BurnDrawingsImage
from QGIS_FMV.utils.QgsUtils import QgsUtils as qgsu

try:
Expand Down Expand Up @@ -66,7 +66,7 @@ def SaveAsPDF(self):
"""Save Table as pdf
The drawings are saved by default
"""
timestamp = _seconds_to_time(self.player.currentInfo)
timestamp = qgsu._seconds_to_time(self.player.currentInfo)

# Frame save drawings
frame = BurnDrawingsImage(
Expand Down
Loading

0 comments on commit ff1f105

Please sign in to comment.