1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348
|
Option Compare Database
Option Explicit
Private WithEvents oGdi As clGdiplus ' Classe pour utilisation de gdiplus
' Facteur de zoom
Private gZoom As Single
' Ratio Largeur/hauteur
Public RatioImg As Single
Public leRatioW As Double, leRatioH As Double
' Coordonnées de sélection
Private gX1 As Long, gY1 As Long
Private gX2 As Long, gY2 As Long
Public Sub FondCarte_AfterUpdate()
Dim rep, chem As String
chem = Dir(CurrentProject.Path & "\test.*")
' Libération de la classe au lancement de la fonction
Set oGdi = Nothing
'supprime le Fichier temporaire
If chem <> "" Then Kill CurrentProject.Path & "\" & chem
'Instanciation objet GDI
Set oGdi = New clGdiplus
'Redim origine ctl Fond & Détail
Fond.Picture = ""
txtZoom = 1
Fond.Width = 14175: Fond.Height = 7369
Me.Section("Détail").Height = 7937
'Mise aux proportions du fond de carte & section détail
rep = CSetProportions
If EstOuvert("F_ParamCarto") = False Then
DoCmd.MoveSize , 150, , Me.Section(0).Height + Me.Section(1).Height + Me.Section(2).Height + 2 + CM2Twips(1.5)
End If
'Dessine les axes sur le fond de carte
CDrawAxes
'Dessine les points (cercle)sur le fond de carte
CDrawDots
'Sauve le fichier tempo
CSave
'Charge le fichier tempo
CRepaint
'Affiche les commandes latérales
ShowLatComs
End Sub
Function CSetProportions() As Boolean
Dim laLargeur As Long, laHauteur As Long, HTDetail As Long, HTFond As Long, LGFond As Long, leRatioImgFic As Long
Dim LGFondPx As Long, HTFondPx As Long, nbTwipsPerPix As Single
CSetProportions = False
If Nz(FondCarte, "") = "" Then
MsgBox ("Fond de carte requis.")
FondCarte.SetFocus
FondCarte.Dropdown
Exit Function
Else
CSetProportions = True
End If
'Chargement de l'image depuis le fichier
oGdi.LoadFile (FondCarte.Column(1))
' Largeur en pixels de l'image
laLargeur = oGdi.ImageWidth
' Hauteur en pixels de l'image
laHauteur = oGdi.ImageHeight
'Calcul des ratios pour redim contrôle Fond
'x/l = H/L => x = (H*l)/L
HTFond = (laHauteur * Fond.Width) / laLargeur
If HTFond > Me.Section("Détail").Height Then
Me.Section("Détail").Height = HTFond + CM2Twips(1)
Fond.Height = HTFond
Else
Fond.Height = HTFond
Me.Section("Détail").Height = HTFond + CM2Twips(1)
End If
'Calcul des ratios pour redim image aux cotes du contrôle
'ratio horizontal à appliquer à l'image pour affichage
nbTwipsPerPix = GetTwipPerPix("X")
LGFond = Fond.Width / nbTwipsPerPix
leRatioW = LGFond / laLargeur
'ratio vertical à appliquer à l'image pour affichage
nbTwipsPerPix = GetTwipPerPix("Y")
HTFond = Fond.Height / nbTwipsPerPix
leRatioH = HTFond / laHauteur
RatioImg = Forms!F_Carto!Fond.Height / Forms!F_Carto!Fond.Width
'Mise à l'échelle de oGdi
oGdi.ScaleI Round(leRatioW, 4), Round(leRatioH, 4)
End Function
Sub CDrawAxes()
Dim LgImg As Long, HtImg As Long, Abs0 As String, Ord0 As String
Dim coulMarge As Long, lgMarge As Long, coulUnit As Long, coulUnitSecondary As Long, Pas As Single, PasPix As Long
Dim lgCarte As Long, htCarte As Long, origCarteX As Long, origCarteY As Long, cpt As Long, nbTwipsPerPix As Single
Dim X As Long
Dim HasGrille As String, HasSecGrille As String, coulGrille As Long, coulSecGrille As Long, tailleSecGrille As Single, tailleGrille As Single, transpSecGrille As Integer, transpGrille As Integer
LgImg = oGdi.ImageWidth
HtImg = oGdi.ImageHeight
lgCarte = FondCarte.Column(2)
htCarte = FondCarte.Column(3)
Abs0 = FondCarte.Column(5)
Ord0 = FondCarte.Column(6)
Pas = 0
lgMarge = CLng(Nz(DLookup("CPAValeur", "T_ParamCarto", "CPAFonction='Marge Carto'"), 50))
coulMarge = CLng(Nz(DLookup("CPAValeur", "T_ParamCarto", "CPAFonction='Couleur marge Carto'"), vbYellow))
coulUnit = Nz(CLng(DLookup("CPAValeur", "T_ParamCarto", "CPAFonction='Couleur Unités grille'")), vbBlack)
coulUnitSecondary = CLng(Nz(DLookup("CPAValeur", "T_ParamCarto", "CPAFonction='Couleur Unités grille secondaire'"), vbBlack))
HasGrille = Nz(DLookup("CPAValeur", "T_ParamCarto", "CPAFonction='Grille Carto'"), "Oui")
HasSecGrille = Nz(DLookup("CPAValeur", "T_ParamCarto", "CPAFonction='Grille Carto secondaire'"), "Oui")
If HasGrille = "Oui" Then
coulGrille = CLng(Nz(DLookup("CPAValeur", "T_ParamCarto", "CPAFonction='Grille Carto Couleur'"), 13553358))
tailleGrille = CDec(Nz(DLookup("CPAValeur", "T_ParamCarto", "CPAFonction='Grille Carto Taille (1-10)'"), 2))
transpGrille = CInt(Nz(DLookup("CPAValeur", "T_ParamCarto", "CPAFonction='Grille Carto Transparence (1-250)'"), 100))
End If
If HasSecGrille = "Oui" Then
coulSecGrille = CLng(Nz(DLookup("CPAValeur", "T_ParamCarto", "CPAFonction='Grille Carto secondaire Couleur'"), 13553358))
tailleSecGrille = CDec(Nz(DLookup("CPAValeur", "T_ParamCarto", "CPAFonction='Grille Carto secondaire Taille (1-10)'"), 13553358))
transpSecGrille = CInt(Nz(DLookup("CPAValeur", "T_ParamCarto", "CPAFonction='Grille Carto secondaire Transparence (1-250)'"), 150))
End If
'Lissage
oGdi.SmoothingMode = GdipSmoothingAntialias
'Absysses
oGdi.DrawLine 0, 0, 0, HtImg, coulMarge, lgMarge, , 150
'Ordonnées
oGdi.DrawLine 0, HtImg, LgImg, HtImg, coulMarge, lgMarge, , 150
'Origine
oGdi.DrawLine 0, HtImg, lgMarge, HtImg - lgMarge, coulUnit, 2
'Coordonnées Origine depuis le point 0
oGdi.DrawText Abs0, 12, "Arial", 25, HtImg - 10
oGdi.DrawText Ord0, 12, "Arial", 20, HtImg - 28
'Unités absisses
Pas = LgImg / (CLng(lgCarte) - CLng(Abs0)) ' en Px (1Pas=1mètre)
nbTwipsPerPix = GetTwipPerPix("X")
cpt = 0
For X = CLng(Abs0) To lgCarte
If X Mod (50) = 0 Then
If X = CLng(Abs0) Then GoTo SuivantX
'Dessine une barre secondaire
cpt = cpt + 1
PasPix = Pas * cpt * 50
oGdi.DrawLine PasPix, HtImg - (lgMarge / 2), PasPix, HtImg - (lgMarge / 2) - 2, coulUnitSecondary, 1
'Affichage conditionnel de la grille secondaire
If HasSecGrille = "Oui" And X Mod (100) <> 0 Then
oGdi.DrawLine PasPix, 0, PasPix, HtImg - (lgMarge / 2), coulSecGrille, tailleSecGrille, GdipDashDASHDOTDOT, transpSecGrille
End If
'Barre principale
If X Mod (100) = 0 Then
oGdi.DrawLine PasPix, HtImg - (lgMarge / 2) - 3, PasPix, HtImg - (lgMarge / 2) + 2, coulUnit, 1
oGdi.DrawText str(X), 10, "Arial", PasPix, HtImg - 8
'Affichage conditionnel de la grille principale
If HasGrille = "Oui" Then
oGdi.DrawLine PasPix, 0, PasPix, HtImg - (lgMarge / 2), coulGrille, tailleGrille, GdipDashDASH, transpGrille
End If
End If
End If
SuivantX:
Next X
'Unités ordonnées
Pas = HtImg / (CLng(htCarte) - CLng(Ord0)) ' en Px (1Pas=1mètre)
nbTwipsPerPix = GetTwipPerPix("Y")
cpt = 0
'For x = htCarte To CLng(Ord0) Step -1
For X = CLng(Ord0) To htCarte
If X Mod (50) = 0 Then
If X = CLng(Ord0) Then GoTo SuivantY
'Dessine une barre secondaire
cpt = cpt + 1
PasPix = Pas * cpt * 50
oGdi.DrawLine (lgMarge / 2) - 2, HtImg - PasPix, (lgMarge / 2) + 2, HtImg - PasPix, coulUnitSecondary, 1
'Affichage conditionnel de la grille secondaire
If HasSecGrille = "Oui" And X Mod (100) <> 0 Then
oGdi.DrawLine (lgMarge / 2), HtImg - PasPix, LgImg, HtImg - PasPix, coulSecGrille, tailleSecGrille, GdipDashDASHDOTDOT, transpSecGrille
End If
'Barre principale
If X Mod (100) = 0 Then
oGdi.DrawLine (lgMarge / 2) - 3, HtImg - PasPix, (lgMarge / 2) + 2, HtImg - PasPix, coulUnit, 1
'Affichage conditionnel de la grille principale
If HasGrille = "Oui" Then
oGdi.DrawLine (lgMarge / 2), HtImg - PasPix, LgImg, HtImg - PasPix, coulGrille, tailleGrille, GdipDashDASH, transpGrille
End If
oGdi.DrawText str(X), 10, "Arial", (lgMarge / 2) + 20, HtImg - PasPix
End If
End If
SuivantY:
Next X
' oGdi.DrawLine 0, 0, LgImg, HtImg, 255, 10, GdipDashDASH, 50
' oGdi.DrawLine 0, HtImg, LgImg, 0, 65280, 10, GdipDashDASHDOTDOT, 50
Fin:
End Sub
Sub CDrawDots()
Dim rst As Recordset, strSQL As String, PasX As Single, PasY As Single
Dim LgImg As Long, HtImg As Long, Abs0 As String, Ord0 As String, lgCarte As Long, htCarte As Long
Dim CoordX As Long, CoordY As Long, HasCoord As String, coordTaille As Long, ptsTaille As Long
LgImg = oGdi.ImageWidth
HtImg = oGdi.ImageHeight
lgCarte = FondCarte.Column(2)
htCarte = FondCarte.Column(3)
Abs0 = FondCarte.Column(5)
Ord0 = FondCarte.Column(6)
PasX = 0: PasY = 0
'Affichage des coordonnées
ptsTaille = Nz(DLookup("CPAValeur", "T_ParamCarto", "CPAFonction='Points Taille'"), "Oui")
HasCoord = Nz(DLookup("CPAValeur", "T_ParamCarto", "CPAFonction='Points coordonnées'"), "Oui")
If HasCoord = "Oui" Then
coordTaille = Nz(DLookup("CPAValeur", "T_ParamCarto", "CPAFonction='Points Taille Police'"), "Oui")
End If
'Unités absisses
PasX = LgImg / (CLng(lgCarte) - CLng(Abs0)) ' en Px (1Pas=1mètre)
'Unités ordonnées
PasY = HtImg / (CLng(htCarte) - CLng(Ord0)) ' en Px (1Pas=1mètre)
'Lissage
oGdi.SmoothingMode = GdipSmoothingAntialias
'Parcours des artefacts filtrés
strSQL = "Rq_Localisation"
Set rst = CurrentDb.OpenRecordset(strSQL, dbOpenDynaset)
With rst
Do While .EOF = False
CoordX = (!XLR - CDec(Abs0)) * PasX
CoordY = HtImg - (!YLR - CDec(Ord0)) * PasY
oGdi.DrawEllipse CoordX, CoordY, ptsTaille, ptsTaille, TypeEllipseCenter, Nz(!CLACol, 0), vbBlue, 1
If HasCoord = "Oui" Then oGdi.DrawText "[" & !XLR & ";" & !YLR & "]", coordTaille, "Arial", CoordX, CoordY + 8
.MoveNext
Loop
.Close
End With
Set rst = Nothing
End Sub
Sub CSave()
'sauve
oGdi.SaveFile (oGdi.ApplicationPath & "test.png")
End Sub
Sub CRepaint()
' Libération de la classe
Set oGdi = Nothing
'Instanciation objet GDI
Set oGdi = New clGdiplus
'Chargement de l'image depuis le fichier test.png
oGdi.LoadFile (oGdi.ApplicationPath & "test.png")
'Affichage ds la contrôle Fond
oGdi.RepaintNoFormRepaint Me.Fond
Me.Repaint
End Sub
Sub ShowLatComs()
'cdes zoom
Commande9.Visible = False
txtZoom = 1: txtZoom.Visible = False
Commande10.Visible = False
XLR.Visible = True: YLR.Visible = True
ZoomOn.Visible = True
End Sub
Private Sub Fond_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If ZoomOn = True And Shift = 1 Then
Zooming = True
gX1 = oGdi.CtrlToImgX(X, Me.Fond)
gY1 = oGdi.CtrlToImgY(Y, Me.Fond)
ZoomFromX = Twips2CoordsX(X)
ZoomFromY = Twips2CoordsY(Y)
End If
End Sub
Private Sub Fond_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim rep, RatioImg As Single
If Nz(FondCarte, "") = "" Then Exit Sub
rep = Dir(CurrentProject.Path & "\test.*")
If rep = "" Then Exit Sub
'Affichage coordonnées / carte
XLR = Twips2CoordsX(X)
YLR = Twips2CoordsY(Y)
'si ZoomOn dessin rectangle
RatioImg = Fond.Height / Fond.Width
If ZoomOn = True And Shift = 1 And Zooming = True Then
gX2 = oGdi.CtrlToImgX(X, Me.Fond)
gY2 = gY1 + ((gX2 - gX1) * RatioImg) 'oGdi.CtrlToImgY(Y, Me.Fond)
Render
oGdi.RepaintFast Me.Fond
End If
End Sub
Private Sub Fond_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim RatioImg As Single
If ZoomOn And Shift = 1 Then
'Dessine le rectangle de Zoom aux proportions du ctl Fond
RatioImg = Fond.Height / Fond.Width
ZoomToX = Twips2CoordsX(X * leRatioW)
ZoomToY = Twips2CoordsY(Y * leRatioH)
gX2 = oGdi.CtrlToImgX(X, Me.Fond)
gY2 = oGdi.CtrlToImgY(Y, Me.Fond)
gY2 = gY1 + ((gX2 - gX1) * RatioImg)
Render
oGdi.RepaintNoFormRepaint Me.Fond
Zooming = False
RectFromX = gX1: RectFromY = gY1
RectToX = gX2: RectToY = gY2
'Affiche la région zommée dans Fond
LoadZoom
End If
End Sub
Sub LoadZoom()
Dim CoordImgX1 As Long, CoordImgY1 As Long, CoordImgX2 As Long, CoordImgY2 As Long
Stop
End Sub |
Partager