| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
from PyQt5.QtWidgets import QDialog, QDialogButtonBox |
| 25 |
|
| 26 |
from .reperage_ui import Ui_DialogReperage |
| 27 |
from .calibrage_ui import Ui_DialogCalibrage |
| 28 |
|
| 29 |
from .. import param |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
class DialogCalibrage(QDialog, Ui_DialogCalibrage): |
| 35 |
def __init__(self, parent): |
| 36 |
QDialog.__init__(self, parent) |
| 37 |
|
| 38 |
self.setupUi(self) |
| 39 |
self.parent = parent |
| 40 |
|
| 41 |
def accept(self): |
| 42 |
longueur = float(self.longueur.text().replace(param.separateur_decimal, '.')) |
| 43 |
. |
| 44 |
|
| 45 |
self.parent.resolution.setText(str(2.54*300/longueur).replace('.', param.separateur_decimal)) |
| 46 |
self.close() |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
class DialogReperage(QDialog, Ui_DialogReperage): |
| 51 |
def __init__(self, parent): |
| 52 |
QDialog.__init__(self, parent) |
| 53 |
|
| 54 |
self.setupUi(self) |
| 55 |
self.canvas = canvas = parent |
| 56 |
gradu = canvas.gradu |
| 57 |
repere = canvas.repere |
| 58 |
|
| 59 |
width, height = canvas.dimensions |
| 60 |
s. |
| 61 |
xmin, xmax, ymin, ymax = canvas.fenetre |
| 62 |
h) |
| 63 |
dpi = canvas.dpi_ecran |
| 64 |
é |
| 65 |
pixels_per_unit_x = width/(xmax - xmin) |
| 66 |
pixels_per_unit_y = height/(ymax - ymin) |
| 67 |
é |
| 68 |
|
| 69 |
cm_per_unit_x = 2.54*pixels_per_unit_x/dpi |
| 70 |
cm_per_unit_y = 2.54*pixels_per_unit_y/dpi |
| 71 |
|
| 72 |
|
| 73 |
self.remplir_champs(repere_O=repere[0], |
| 74 |
repere_I=repere[1], |
| 75 |
repere_J=repere[2], |
| 76 |
gradu_x=gradu[0], |
| 77 |
gradu_y=gradu[1], |
| 78 |
echelle_x=cm_per_unit_x, |
| 79 |
echelle_y=cm_per_unit_y, |
| 80 |
resolution=dpi, |
| 81 |
) |
| 82 |
|
| 83 |
self.rapport.setChecked(canvas.ratio is not None) |
| 84 |
|
| 85 |
self.boutons.button(QDialogButtonBox.Reset).clicked.connect(self.restaurer) |
| 86 |
self.boutons.button(QDialogButtonBox.Apply).clicked.connect(self.appliquer) |
| 87 |
self.calibrage.clicked.connect(self.calibrer) |
| 88 |
|
| 89 |
|
| 90 |
def remplir_champs(self, **champs): |
| 91 |
for nom, valeur in champs.items(): |
| 92 |
string = (str(valeur) if not isinstance(valeur, str) else valeur) |
| 93 |
if isinstance(valeur, float): |
| 94 |
if string.endswith('.0'): |
| 95 |
string = string[:-2] |
| 96 |
string = string.replace('.', param.separateur_decimal) |
| 97 |
getattr(self, nom).setText(string) |
| 98 |
|
| 99 |
|
| 100 |
def accept(self): |
| 101 |
self.appliquer() |
| 102 |
self.close() |
| 103 |
|
| 104 |
def appliquer(self): |
| 105 |
canvas = self.canvas |
| 106 |
|
| 107 |
def str2num(string): |
| 108 |
string = string.replace(param.separateur_decimal, '.').strip() |
| 109 |
if string.endswith('.0'): |
| 110 |
string = string[:-2] |
| 111 |
return (float(string) if '.' in string else int(string)) |
| 112 |
|
| 113 |
repere = (self.repere_O.text().strip(), |
| 114 |
self.repere_I.text().strip(), |
| 115 |
self.repere_J.text().strip(), |
| 116 |
) |
| 117 |
gradu = (str2num(self.gradu_x.text()), |
| 118 |
str2num(self.gradu_y.text()), |
| 119 |
) |
| 120 |
|
| 121 |
canvas.dpi_ecran = dpi = str2num(self.resolution.text()) |
| 122 |
|
| 123 |
. |
| 124 |
mine |
| 125 |
e, |
| 126 |
. |
| 127 |
e |
| 128 |
te. |
| 129 |
|
| 130 |
te. |
| 131 |
xmin, xmax, ymin, ymax = canvas.fenetre |
| 132 |
x_centre = (xmin + xmax)/2 |
| 133 |
y_centre = (ymin + ymax)/2 |
| 134 |
|
| 135 |
cm_per_unit_x = str2num(self.echelle_x.text()) |
| 136 |
cm_per_unit_y = str2num(self.echelle_y.text()) |
| 137 |
dpcm = dpi/2.54 |
| 138 |
pixels_per_unit_x = cm_per_unit_x*dpcm |
| 139 |
pixels_per_unit_y = cm_per_unit_y*dpcm |
| 140 |
|
| 141 |
width, height = canvas.dimensions |
| 142 |
2. |
| 143 |
demi_largeur = width/(2*pixels_per_unit_x) |
| 144 |
demi_hauteur = height/(2*pixels_per_unit_y) |
| 145 |
fenetre = (x_centre - demi_largeur, |
| 146 |
x_centre + demi_largeur, |
| 147 |
y_centre - demi_hauteur, |
| 148 |
y_centre + demi_hauteur, |
| 149 |
) |
| 150 |
|
| 151 |
ratio = (cm_per_unit_x/cm_per_unit_y if self.rapport.isChecked() else None) |
| 152 |
|
| 153 |
commande = ("repere = %s\n" |
| 154 |
"gradu = %s\n" |
| 155 |
"fenetre = %s\n" |
| 156 |
"ratio = %s" |
| 157 |
) % (repere, gradu, fenetre, ratio) |
| 158 |
|
| 159 |
self.canvas.executer(commande) |
| 160 |
|
| 161 |
|
| 162 |
def restaurer(self): |
| 163 |
"Remet les valeurs par défaut dans les champs." |
| 164 |
self.remplir_champs(repere_O=param.repere[0], |
| 165 |
repere_I=param.repere[1], |
| 166 |
repere_J=param.repere[2], |
| 167 |
gradu_x=param.gradu[0], |
| 168 |
gradu_y=param.gradu[1], |
| 169 |
|
| 170 |
|
| 171 |
resolution=param.dpi_ecran, |
| 172 |
) |
| 173 |
self.rapport.setChecked(param.ratio is not None) |
| 174 |
|
| 175 |
|
| 176 |
def calibrer(self): |
| 177 |
DialogCalibrage(self).exec_() |