Skip to content

Commit

Permalink
Added option to fly hexagons anti-clockwise. (#1101)
Browse files Browse the repository at this point in the history
And some minor code improvements.

Fix issue #1099
  • Loading branch information
joernu76 authored Jul 30, 2021
1 parent d4b56a8 commit d00d592
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 19 deletions.
30 changes: 14 additions & 16 deletions mslib/msui/hexagon_dockwidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,16 @@ def __init__(self, error_string):
logging.debug("%s", error_string)


def create_hexagon(center_lat, center_lon, radius, angle=0.):
coords_0 = (radius, 0.)
coords_cart_0 = [rotate_point(coords_0, angle=0. + angle),
rotate_point(coords_0, angle=60. + angle),
rotate_point(coords_0, angle=120. + angle),
rotate_point(coords_0, angle=180. + angle),
rotate_point(coords_0, angle=240. + angle),
rotate_point(coords_0, angle=300. + angle),
rotate_point(coords_0, angle=360. + angle)]
coords_sphere_rot = [
(center_lat + (vec[0] / 110.),
center_lon + (vec[1] / (110. * np.cos(np.deg2rad((vec[0] / 110.) + center_lat)))))
for vec in coords_cart_0]
return coords_sphere_rot
def create_hexagon(center_lat, center_lon, radius, angle=0., clockwise=True):
coords = (radius, 0.)
coords_cart = [rotate_point(coords, angle=_a + angle) for _a in range(0, 361, 60)]
if not clockwise:
coords_cart.reverse()
coords_sphere = [
(center_lat + (_x / 110.),
center_lon + (_y / (110. * np.cos(np.deg2rad((_x / 110.) + center_lat)))))
for _x, _y in coords_cart]
return coords_sphere


class HexagonControlWidget(QtWidgets.QWidget, ui.Ui_HexagonDockWidget):
Expand Down Expand Up @@ -90,7 +86,8 @@ def _get_parameters(self):
"center_lon": self.dsbHexagonLongitude.value(),
"center_lat": self.dsbHexagonLatitude.value(),
"radius": self.dsbHexgaonRadius.value(),
"angle": self.dsbHexagonAngle.value()
"angle": self.dsbHexagonAngle.value(),
"direction": self.cbClock.currentText(),
}

def _add_hexagon(self):
Expand All @@ -102,7 +99,8 @@ def _add_hexagon(self):
QtWidgets.QMessageBox.warning(
self, "Add hexagon", "You cannot create a hexagon with zero radius!")
return
points = create_hexagon(params["center_lat"], params["center_lon"], params["radius"], params["angle"])
points = create_hexagon(params["center_lat"], params["center_lon"], params["radius"],
params["angle"], params["direction"] == "clockwise")
index = table_view.currentIndex()
if not index.isValid():
row = 0
Expand Down
15 changes: 12 additions & 3 deletions mslib/msui/qt5/ui_hexagon_dockwidget.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'ui_hexagon_dockwidget.ui'
# Form implementation generated from reading ui file 'mslib/msui/ui/ui_hexagon_dockwidget.ui'
#
# Created by: PyQt5 UI code generator 5.6
# Created by: PyQt5 UI code generator 5.12.3
#
# WARNING! All changes made in this file will be lost!


from PyQt5 import QtCore, QtGui, QtWidgets


class Ui_HexagonDockWidget(object):
def setupUi(self, HexagonDockWidget):
HexagonDockWidget.setObjectName("HexagonDockWidget")
Expand Down Expand Up @@ -71,6 +73,12 @@ def setupUi(self, HexagonDockWidget):
self.horizontalLayout_6.addWidget(self.pbRemoveHexagon)
spacerItem = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
self.horizontalLayout_6.addItem(spacerItem)
self.cbClock = QtWidgets.QComboBox(HexagonDockWidget)
self.cbClock.setMinimumSize(QtCore.QSize(120, 0))
self.cbClock.setObjectName("cbClock")
self.cbClock.addItem("")
self.cbClock.addItem("")
self.horizontalLayout_6.addWidget(self.cbClock)
self.verticalLayout.addLayout(self.horizontalLayout_6)

self.retranslateUi(HexagonDockWidget)
Expand All @@ -89,4 +97,5 @@ def retranslateUi(self, HexagonDockWidget):
self.dsbHexagonAngle.setSuffix(_translate("HexagonDockWidget", " °"))
self.pbAddHexagon.setText(_translate("HexagonDockWidget", "Add Hexagon"))
self.pbRemoveHexagon.setText(_translate("HexagonDockWidget", "Remove Hexagon"))

self.cbClock.setItemText(0, _translate("HexagonDockWidget", "clockwise"))
self.cbClock.setItemText(1, _translate("HexagonDockWidget", "anti-clockwise"))
20 changes: 20 additions & 0 deletions mslib/msui/ui/ui_hexagon_dockwidget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,26 @@
</property>
</spacer>
</item>
<item>
<widget class="QComboBox" name="cbClock">
<property name="minimumSize">
<size>
<width>120</width>
<height>0</height>
</size>
</property>
<item>
<property name="text">
<string>clockwise</string>
</property>
</item>
<item>
<property name="text">
<string>anti-clockwise</string>
</property>
</item>
</widget>
</item>
</layout>
</item>
</layout>
Expand Down

0 comments on commit d00d592

Please sign in to comment.