mirror of https://gitlab.com/pamhyr/pamhyr2
geometry: Fix some guidelines display.
parent
a45e43a2ca
commit
1fb42a73fa
|
|
@ -8,7 +8,7 @@ from copy import deepcopy
|
|||
from operator import itemgetter
|
||||
from functools import reduce
|
||||
|
||||
from tools import flatten
|
||||
from tools import flatten, timer
|
||||
|
||||
from Model.Geometry.Profile import Profile
|
||||
from Model.Geometry.ProfileXYZ import ProfileXYZ
|
||||
|
|
@ -167,10 +167,13 @@ class Reach:
|
|||
|
||||
# Guidelines
|
||||
|
||||
@timer
|
||||
def _compute_guidelines_cache(self, guide_set, named_points,
|
||||
complete, incomplete):
|
||||
# Reset guide lines cache
|
||||
self._guidelines = {}
|
||||
self._complete_guidelines = complete.copy()
|
||||
self._incomplete_guidelines = incomplete.copy()
|
||||
self._guidelines_is_valid = len(incomplete) == 0
|
||||
|
||||
# Make a list of point for each guideline
|
||||
|
|
@ -189,6 +192,7 @@ class Reach:
|
|||
)
|
||||
)
|
||||
|
||||
@timer
|
||||
def compute_guidelines(self):
|
||||
"""Compute reach guideline and check if is valid for all profiles
|
||||
|
||||
|
|
@ -229,9 +233,9 @@ class Reach:
|
|||
|
||||
return (complete, incomplete)
|
||||
|
||||
def _map_guidelines_points(self, func, _filter=None):
|
||||
def _map_guidelines_points(self, func, full=False):
|
||||
if len(self._guidelines) == 0:
|
||||
_ = compute_guidelines()
|
||||
_ = self.compute_guidelines()
|
||||
|
||||
return list(
|
||||
# Map for each guideline
|
||||
|
|
@ -243,13 +247,17 @@ class Reach:
|
|||
self._guidelines[k],
|
||||
)
|
||||
),
|
||||
self._guidelines if not _filter else filter(
|
||||
_filter,
|
||||
# Get only guide lines if FULL False
|
||||
self._guidelines if full else filter(
|
||||
lambda x: x in self._complete_guidelines,
|
||||
self._guidelines
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
def _complete_filter(self, gl):
|
||||
return gl in self._complete_guidelines
|
||||
|
||||
def get_guidelines_x(self):
|
||||
return self._map_guidelines_points(lambda p: p.x)
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@ import sys
|
|||
import csv
|
||||
import time
|
||||
|
||||
from tools import timer
|
||||
|
||||
from PyQt5 import QtWidgets
|
||||
from PyQt5.QtCore import (
|
||||
QModelIndex, Qt, QSettings, pyqtSlot,
|
||||
|
|
@ -220,9 +222,12 @@ class GeometryWindow(QMainWindow, WindowToolKit):
|
|||
self.list_second_window = []
|
||||
self.list_row = []
|
||||
|
||||
@timer
|
||||
def graphic_1(self):
|
||||
self.ui.canvas_1.axes.cla()
|
||||
self.ui.canvas_1.axes.grid(color='grey', linestyle='--', linewidth=0.5)
|
||||
|
||||
# Axes
|
||||
self.ui.canvas_1.axes.set_xlabel(
|
||||
_translate("MainWindow_reach", "X (m)"), color='green', fontsize=12
|
||||
)
|
||||
|
|
@ -230,13 +235,17 @@ class GeometryWindow(QMainWindow, WindowToolKit):
|
|||
_translate("MainWindow_reach", "Y (m)"), color='green', fontsize=12
|
||||
)
|
||||
|
||||
# Draw line for each profile
|
||||
self.line_xy = [
|
||||
self.ui.canvas_1.axes.plot(x, y, color='r', lw=1.,
|
||||
markersize=3, marker='+')
|
||||
self.ui.canvas_1.axes.plot(
|
||||
x, y,
|
||||
color='r', lw=1.,
|
||||
markersize=3, marker='+'
|
||||
)
|
||||
for x, y in zip(self._reach.get_x(), self._reach.get_y())
|
||||
]
|
||||
|
||||
|
||||
# Guide lines
|
||||
self.x_complete = self._reach.get_guidelines_x()
|
||||
self.y_complete = self._reach.get_guidelines_y()
|
||||
|
||||
|
|
|
|||
16
src/tools.py
16
src/tools.py
|
|
@ -23,10 +23,10 @@ def display_timers():
|
|||
global _timers
|
||||
global _calls
|
||||
|
||||
print(" +--Timers----------------------------------------+")
|
||||
print(" +---------------------------------------------------------Timers--+")
|
||||
for func in _timers:
|
||||
print(f" | {func:<15} | {_timers[func]:>10.6f} sec | {_calls[func]:>5} calls |")
|
||||
print(" +------------------------------------------------+")
|
||||
print(f" | {func:<32} | {_timers[func]:>10.6f} sec | {_calls[func]:>5} calls |")
|
||||
print(" +-----------------------------------------------------------------+")
|
||||
|
||||
def timer(func):
|
||||
"""Function wrapper to register function runtime"""
|
||||
|
|
@ -39,12 +39,12 @@ def timer(func):
|
|||
end_time = time.perf_counter()
|
||||
run_time = end_time - start_time
|
||||
|
||||
if func.__name__ not in _timers:
|
||||
_timers[func.__name__] = 0
|
||||
_calls[func.__name__] = 0
|
||||
if func.__qualname__ not in _timers:
|
||||
_timers[func.__qualname__] = 0
|
||||
_calls[func.__qualname__] = 0
|
||||
|
||||
_timers[func.__name__] += run_time
|
||||
_calls[func.__name__] += 1
|
||||
_timers[func.__qualname__] += run_time
|
||||
_calls[func.__qualname__] += 1
|
||||
|
||||
return value
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue