Skip to content

Commit

Permalink
Added line width scaling on map zoom
Browse files Browse the repository at this point in the history
  • Loading branch information
SanPen committed Jun 27, 2024
1 parent 4cb5b13 commit dec2854
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 13 deletions.
25 changes: 13 additions & 12 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions src/GridCal/Gui/Diagrams/MapWidget/Branches/map_line_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,16 @@ def __init__(self,
self.enabled = True
self.original = True

def setWidthScale(self, val: float):
"""
Set the width scale of the line
:param val:
"""
for segment in self.segments_list:
pen = segment.pen() # get the current pen
pen.setWidthF(val) # Set the fractional thickness of the line
segment.setPen(pen) # Assign the pen to the line item

def clean_segments(self) -> None:
"""
Remove all segments from the scene
Expand Down
23 changes: 22 additions & 1 deletion src/GridCal/Gui/Diagrams/MapWidget/grid_map_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
from collections.abc import Callable
from PySide6.QtSvg import QSvgGenerator
from PySide6.QtCore import (Qt, QSize, QRect, QMimeData, QIODevice, QByteArray, QDataStream, QModelIndex)
from PySide6.QtGui import (QIcon, QPixmap, QImage, QPainter, QStandardItemModel, QStandardItem, QColor, QDropEvent)
from PySide6.QtGui import (QIcon, QPixmap, QImage, QPainter, QStandardItemModel, QStandardItem, QColor, QDropEvent,
QWheelEvent)

from GridCalEngine.Devices.Diagrams.map_location import MapLocation
from GridCalEngine.Devices.Substation import Bus
Expand Down Expand Up @@ -819,6 +820,26 @@ def dropEvent(self, event: QDropEvent):
self.circuit.add_substation(obj=api_object)
self.add_api_substation(api_object=api_object, lat=lat, lon=lon, r=0.01)

def wheelEvent(self, event: QWheelEvent):
"""
:param event:
:return:
"""
max_zoom = self.map.max_level
min_zoom = self.map.min_level
zoom = self.map.zoom_factor
scale = 0.1 + zoom / (max_zoom - min_zoom)

# rescale lines
for dev_tpe in [DeviceType.LineDevice,
DeviceType.DCLineDevice,
DeviceType.HVDCLineDevice,
DeviceType.FluidPathDevice]:
graphics_dict = self.graphics_manager.get_device_type_dict(device_type=dev_tpe)
for key, lne in graphics_dict.items():
lne.setWidthScale(scale)

def change_size_and_pen_width_all(self, new_radius, pen_width):
"""
Change the size and pen width of all elements in Schema.
Expand Down
1 change: 1 addition & 0 deletions src/GridCal/Gui/Diagrams/MapWidget2/map_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,7 @@ def wheelEvent(self, event: QWheelEvent):
"""
Handle a mouse wheel rotation.
"""
self.editor.wheelEvent(event)

def resizeEvent(self, event: QResizeEvent = None, updateDiagram: bool = True):
"""
Expand Down

0 comments on commit dec2854

Please sign in to comment.