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 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616
|
'CORRECTION DE BUG SUR BESTFIG(VOIR C-APRES
'FACTEUR ZOOM VA DE 0 À 200
'FACTEUR ZOOM NORMAL =100
Imports System.Drawing.Drawing2D
Public Class Form1
'DECLARATION DE VARAIABLES DOIVENT FIGURES AU DEBUT DE CLASSE
Public Structure rectProp
Dim haut As Integer
Dim larg As Integer
Dim nom As String
End Structure
Public Structure modu
Dim haut As Integer
Dim larg As Integer
End Structure
Private Const Ssale As Integer = 10
Dim drawFont As New Font("Arial", 10, FontStyle.Regular)
Dim myBrush As SolidBrush = New SolidBrush(Color.Yellow)
Dim rectBrush As New Drawing2D.LinearGradientBrush(ClientRectangle, Color.Yellow, Color.Blue, Drawing2D.LinearGradientMode.Horizontal)
Dim drawFormat As New StringFormat()
'DECLARATION DE VARAIABLES POUR GERER ZOOM IMMEDIAT
'--------------------------------------------------
Dim boolDraw As Boolean
Dim boolFirstFit As Boolean
Dim boolBestFit As Boolean
Dim boolWorstFit As Boolean
Private Event OnDraw As EventHandler(Of EventArgs)
Private Event OnFirstFit As EventHandler(Of EventArgs)
Private Event OnBestFit As EventHandler(Of EventArgs)
Private Event OnWorstFit As EventHandler(Of EventArgs)
Public Sub New()
' Cet appel est requis par le Concepteur Windows Form.
InitializeComponent()
' Ajoutez une initialisation quelconque après l'appel InitializeComponent().
'RAJOUT DES HANDLERS D'EVENEMENTS POUR GESTION DU ZOOM
'-----------------------------------------------------
AddHandler Me.OnDraw, AddressOf BtnDraw_Click
AddHandler Me.OnFirstFit, AddressOf BtnFirstFit_Click
AddHandler Me.OnBestFit, AddressOf btnBestFit_Click
AddHandler Me.OnWorstFit, AddressOf btnWorstFit_Click
'MODE STRETCH POUR PICTUREBOX
'----------------------------
picResult.SizeMode = PictureBoxSizeMode.StretchImage
'INIT TRACKERBAR
'---------------
trckEchelle.TickFrequency = 1
trckEchelle.Dock = DockStyle.None
trckEchelle.Value = 1 'valeur initiale
trckEchelle.Minimum = 1 'valeur Mini pour Zoom
trckEchelle.Maximum = 20 'valeur Maxi pour Zoom
trckEchelle.LargeChange = 1 'grand increment sur click
trckEchelle.SmallChange = 1 'petit increment sur click
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
txtHauteur.Text = picResult.Height / Ssale
txtLargeur.Text = picResult.Width / Ssale
End Sub
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtInputs.TextChanged
txtInputs.Select(0, 0)
End Sub
Private Sub txtInputs_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtInputs.TextChanged
End Sub
Private Sub GroupBox1_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GroupBox1.Enter
End Sub
Private Sub GroupBox2_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GroupBox2.Enter
End Sub
Private Sub Algorithme_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Algorithme.Enter
End Sub
Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
End Sub
Private Sub btnOk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs, Optional ByVal show_graphically As Boolean = True) Handles btnOK.Click
Dim the_pen As New Pen(Color.Blue, 0)
Dim bin_wid As Integer = txtHauteur.Text
Dim haut As Integer = Val(txtHauteur.Text)
Dim larg As Integer = Val(txtLargeur.Text)
If show_graphically Then
picResult.Width = larg * Ssale + 5
picResult.Height = haut * Ssale
Dim bm As New Bitmap(picResult.Width, picResult.Height)
Dim gr As Graphics = Graphics.FromImage(bm)
gr.ScaleTransform(Ssale, Ssale)
gr.Clear(picResult.BackColor)
' Draw a unit grid.
Dim hgt As Single = picResult.Height / Ssale
Dim white_pen As New Pen(Color.White, 0)
For i As Integer = 1 To bin_wid
gr.DrawLine(white_pen, i, 0, i, hgt)
Next i
For i As Integer = 1 To hgt
gr.DrawLine(white_pen, 0, i, bin_wid, i)
Next i
white_pen.Dispose()
the_pen.Dispose()
gr.Dispose()
picResult.Image = bm
End If
End Sub
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
txtInputs.Text += txtNbLigne.Text + "*" + txtNbCol.Text + vbNewLine
End Sub
Private Sub BtnDraw_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDraw.Click
Dim myGraphics As Graphics
Dim myRectangle As Rectangle
Dim myPen As New Pen(Color.Blue)
'return the current form as a drawing surface
myGraphics = Graphics.FromHwnd(picResult().Handle)
myGraphics.Clear(Color.WhiteSmoke)
'FACTEUR DE ZOOM
'---------------
myGraphics.ScaleTransform(trckEchelle.Value / 10, trckEchelle.Value / 10)
DrawGrid(myGraphics, myPen)
If (txtInputs.Text.Length = 0) Then
MessageBox.Show("Donnez les rectangles!", "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Warning)
Else
Dim txt As String = txtInputs.Text
If txt.EndsWith(vbCrLf) Then
txt = txt.Substring(0, txt.Length - vbCrLf.Length)
End If
Dim lines() As String = txt.Split(vbCrLf)
Dim modules(lines.Length - 1) As rectProp
For i As Integer = 0 To lines.Length - 1
Dim strucRec() As String = lines(i).Split("*")
modules(i).haut = Integer.Parse(strucRec(0))
modules(i).larg = Integer.Parse(strucRec(1))
modules(i).nom = "M" + i.ToString()
Next
Dim XPosition As Integer = 0
Dim YPosition As Integer = 0
myPen = New Pen(Color.Azure)
Dim Ymax As Integer = 0
Dim C As Integer = 0
DataGridView1.RowCount = lines.Length
For i As Integer = 0 To lines.Length - 1
If ((XPosition + (Ssale * modules(i).larg)) > picResult.Width) Then
For j As Integer = C To (i - 1)
If (Ssale * modules(j).haut) > Ymax Then
Ymax = Ssale * modules(j).haut
End If
Next
C = i
XPosition = 0
YPosition += Ymax
Ymax = 0
End If
If Not ((YPosition + (Ssale * modules(i).haut)) > picResult.Height) Then
myRectangle = New Rectangle(x:=XPosition, y:=YPosition, Width:=Ssale * modules(i).larg, Height:=Ssale * modules(i).haut)
myGraphics.DrawRectangle(pen:=myPen, rect:=myRectangle)
myRectangle.Inflate(-1.0, -1.0)
Dim myLinearGradientBrush As New LinearGradientBrush( _
myRectangle, Color.Red, Color.WhiteSmoke, LinearGradientMode.Horizontal)
myGraphics.FillRectangle(myLinearGradientBrush, myRectangle)
myGraphics.DrawString(modules(i).nom, drawFont, myBrush, myRectangle.X, myRectangle.Y, drawFormat)
XPosition += myRectangle.Width
'XPosition += Math.Ceiling(myRectangle.Width / 20) * 20
'Afficher les caractéristiques des Modules
DataGridView1.Rows(i).Cells(0).Value = modules(i).nom
DataGridView1.Rows(i).Cells(1).Value = myRectangle.Height / 10
DataGridView1.Rows(i).Cells(2).Value = myRectangle.Width / 10
DataGridView1.Rows(i).Cells(3).Value = (myRectangle.X) / 10
DataGridView1.Rows(i).Cells(4).Value = (myRectangle.Y) / 10
Else
MessageBox.Show("VOUS AVEZ DEPASSE LA TAILLE DE DISPOSITIF!", "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Warning)
End If
Next
'BOUTON Draw A ETE ACTIVE
'------------------------
boolDraw = True
boolFirstFit = boolBestFit = boolWorstFit = False
End If
End Sub
Private Sub BtnFirstFit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnFirstFit.Click
Dim myGraphics As Graphics
Dim myPen As New Pen(Color.Blue)
Dim myRectangle As Rectangle
'return the current form as a drawing surface
myGraphics = Graphics.FromHwnd(picResult().Handle)
myGraphics.Clear(Color.Transparent)
'FACTEUR DE ZOOM
'---------------
myGraphics.ScaleTransform(trckEchelle.Value / 10, trckEchelle.Value / 10)
DrawGrid(myGraphics, myPen)
If (txtInputs.Text.Length = 0) Then
MessageBox.Show("Donnez les rectangles!", "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Warning)
Else
Dim txt As String = txtInputs.Text
If txt.EndsWith(vbCrLf) Then
txt = txt.Substring(0, txt.Length - vbCrLf.Length)
End If
Dim lines() As String = txt.Split(vbCrLf)
Dim modules(lines.Length - 1) As rectProp
Dim nouveau(lines.Length - 1) As rectProp
For i As Integer = 0 To lines.Length - 1
Dim strucRec() As String = lines(i).Split("*")
modules(i).haut = Integer.Parse(strucRec(0))
modules(i).larg = Integer.Parse(strucRec(1))
modules(i).nom = "M" + i.ToString()
Next
Dim XPosition As Integer = 0
Dim YPosition As Integer = 0
myPen = New Pen(Color.Azure)
Dim Ymax As Integer = 0
Dim C As Integer = 0
Dim k As Integer = 0
Dim existe As Boolean = True
While (existe)
For i As Integer = 0 To modules.Length - 1
If ((modules(i).larg <> 0) And (modules(i).haut <> 0) And (XPosition + (Ssale * modules(i).larg) < picResult.Width)) Then
nouveau(k).haut = modules(i).haut
modules(i).haut = 0
nouveau(k).larg = modules(i).larg
modules(i).larg = 0
nouveau(k).nom = modules(i).nom
k += 1
XPosition += Ssale * nouveau(i).larg
End If
Next
Dim trouver As Integer = 0
For i As Integer = 0 To modules.Length - 1
If ((modules(i).larg = 0) And (modules(i).haut = 0)) Then
trouver += 1
End If
Next
If (trouver = modules.Length) Then
existe = False
End If
XPosition = 0
End While
DataGridView1.RowCount = lines.Length
For i As Integer = 0 To nouveau.Length - 1
If ((XPosition + (Ssale * nouveau(i).larg)) > picResult.Width) Then
For j As Integer = C To (i - 1)
If (Ssale * nouveau(j).haut) > Ymax Then
Ymax = Ssale * nouveau(j).haut
End If
Next
C = i
XPosition = 0
YPosition += Ymax
Ymax = 0
End If
If Not ((YPosition + (Ssale * nouveau(i).haut)) > picResult.Height) Then
myRectangle = New Rectangle(x:=XPosition, y:=YPosition, Width:=Ssale * nouveau(i).larg, Height:=Ssale * nouveau(i).haut)
myGraphics.DrawRectangle(pen:=myPen, rect:=myRectangle)
myRectangle.Inflate(-1.0, -1.0)
Dim myLinearGradientBrush As New LinearGradientBrush( _
myRectangle, Color.Red, Color.WhiteSmoke, LinearGradientMode.Horizontal)
myGraphics.FillRectangle(myLinearGradientBrush, myRectangle)
myGraphics.DrawString(nouveau(i).nom, drawFont, myBrush, myRectangle.X, myRectangle.Y, drawFormat)
'XPosition += myRectangle.Width
XPosition += Math.Ceiling(myRectangle.Width / 40) * 40
'Afficher les caractéristiques des Modules
DataGridView1.Rows(i).Cells(0).Value = nouveau(i).nom
DataGridView1.Rows(i).Cells(1).Value = myRectangle.Height / 10
DataGridView1.Rows(i).Cells(2).Value = myRectangle.Width / 10
DataGridView1.Rows(i).Cells(3).Value = (myRectangle.X) / 10
DataGridView1.Rows(i).Cells(4).Value = (myRectangle.Y) / 10
Else
MessageBox.Show("VOUS AVEZ DEPASSE LA TAILLE DE DISPOSITIF!", "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Warning)
End If
Next
'BOUTON FirstFit A ETE ACTIVE
'---------------------------
boolFirstFit = True
boolDraw = boolBestFit = boolWorstFit = False
End If
End Sub
Private Sub DrawGrid(ByVal myGraphics As Graphics, ByVal myPen As Pen)
Dim myRectangle As Rectangle
'return the current form as a drawing surface
myGraphics = Graphics.FromHwnd(picResult().Handle)
myGraphics.Clear(Color.Transparent)
For posHeight As Integer = 0 To picResult.Height * 2
For posWidth As Integer = 0 To picResult.Width * 2
'create a rectangle based on x,y coordinates, width, & height
myRectangle = New Rectangle(x:=posWidth, y:=posHeight, Width:=Ssale, Height:=Ssale)
'draw rectangle from pen and rectangle objects
myGraphics.DrawRectangle(pen:=myPen, rect:=myRectangle)
posWidth += Ssale - 1
Next posWidth
posHeight += Ssale - 1
Next posHeight
End Sub
'ALGO RECTIFIE CAR VAR "Position" DONNE DES VALEURS NEGATIVES
'voir plus bas la ligne
Private Sub btnBestFit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBestFit.Click
If (txtInputs.Text.Length = 0) Then
MessageBox.Show("Donnez les rectangles!", "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Warning)
Else
Dim txt As String = txtInputs.Text
If txt.EndsWith(vbCrLf) Then
txt = txt.Substring(0, txt.Length - vbCrLf.Length)
End If
Dim lines() As String = txt.Split(vbCrLf)
Dim modules(lines.Length) As rectProp
Dim nouveau(lines.Length) As rectProp
For i As Integer = 0 To lines.Length - 1
Dim strucRec() As String = lines(i).Split("*")
modules(i).haut = Integer.Parse(strucRec(0))
modules(i).larg = Integer.Parse(strucRec(1))
modules(i).nom = "M" + i.ToString()
Next
Dim Matrice((lines.Length), (lines.Length)) As rectProp
'Remplir la Matrice
Dim restligne(lines.Length) As Double
For i As Integer = 0 To modules.Length - 1
restligne(i) = txtLargeur.Text
Next
For i As Integer = 0 To modules.Length - 1
For j As Integer = 0 To modules.Length - 1
Matrice(i, j).haut = 0
Matrice(i, j).larg = 0
Matrice(i, j).nom = ""
Next
Next
Dim colPosition As Integer = 0
For k As Integer = 0 To modules.Length - 1
'chercher le min dans les lignes
'Dim min As Integer = restligne.Min
Dim min As Integer = minTable(restligne)
Dim Position As Integer = 0
Dim copieRestligne(restligne.Length) As Double
For p As Integer = 0 To restligne.Length - 1
copieRestligne(p) = restligne(p)
Next
While (min < modules(k).larg)
'copieRestligne(Position) = copieRestligne.Max + 1
copieRestligne(Position) = maxTable(copieRestligne) + 1
'min = copieRestligne.Min
min = minTable(copieRestligne)
'Position = Array.IndexOf(copieRestligne, copieRestligne.Min)
Position = Array.IndexOf(copieRestligne, min)
'ALGO RECTIFIE CAR VAR "Position" DONNE DES VALEURS NEGATIVES
If Position < 0 Then
Position = 0
End If
End While
'Remplir la matrice des valeurs
Matrice(Position, colPosition).haut = modules(k).haut
Matrice(Position, colPosition).larg = modules(k).larg
Matrice(Position, colPosition).nom = modules(k).nom
colPosition += 1
restligne(Position) -= modules(k).larg
Next
'Dessiner les rectangles
Dim myGraphics As Graphics
Dim myRectangle As Rectangle
Dim myPen As New Pen(Color.Blue)
'return the current form as a drawing surface
myGraphics = Graphics.FromHwnd(picResult().Handle)
myGraphics.Clear(Color.Transparent)
'FACTEUR DE ZOOM
'---------------
myGraphics.ScaleTransform(trckEchelle.Value / 10, trckEchelle.Value / 10)
DrawGrid(myGraphics, myPen)
Dim XPosition As Integer = 0
Dim YPosition As Integer = 0
myPen = New Pen(Color.Azure)
Dim Ymax As Integer = 0
Dim C As Integer = 0
DataGridView1.RowCount = lines.Length
For i As Integer = 0 To lines.Length - 1
For j As Integer = 0 To lines.Length - 1
'si la case de Matrice n'est pas vide
If Not (Matrice(i, j).haut = 0) Then
'Prendre une position sur l'axe des Y
If ((XPosition + (Ssale * Matrice(i, j).larg)) > picResult.Width) Then
For y As Integer = C To (i - 1)
For x As Integer = 0 To lines.Length
If (Ssale * Matrice(y, x).haut) > Ymax Then
Ymax = Ssale * Matrice(y, x).haut
End If
Next
Next
C = i
XPosition = 0
YPosition += Ymax
Ymax = 0
End If
If Not ((YPosition + (Ssale * Matrice(i, j).haut)) > picResult.Height) Then
myRectangle = New Rectangle(x:=XPosition, y:=YPosition, Width:=Ssale * Matrice(i, j).larg, Height:=Ssale * Matrice(i, j).haut)
myGraphics.DrawRectangle(pen:=myPen, rect:=myRectangle)
myRectangle.Inflate(-1.0, -1.0)
Dim myLinearGradientBrush As New LinearGradientBrush( _
myRectangle, Color.Red, Color.WhiteSmoke, LinearGradientMode.Horizontal)
myGraphics.FillRectangle(myLinearGradientBrush, myRectangle)
myGraphics.DrawString(Matrice(i, j).nom, drawFont, myBrush, myRectangle.X, myRectangle.Y, drawFormat)
XPosition += myRectangle.Width
'XPosition += Math.Ceiling(myRectangle.Width / 40) * 40
'Afficher les caractéristiques des Modules
DataGridView1.Rows(i).Cells(0).Value = Matrice(i, j).nom
DataGridView1.Rows(i).Cells(1).Value = myRectangle.Height / 10
DataGridView1.Rows(i).Cells(2).Value = myRectangle.Width / 10
DataGridView1.Rows(i).Cells(3).Value = (myRectangle.X) / 10
DataGridView1.Rows(i).Cells(4).Value = (myRectangle.Y) / 10
Else
MessageBox.Show("VOUS AVEZ DEPASSE LA TAILLE DE DISPOSITIF!", "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Warning)
End If
End If
Next
Next
'BOUTON BestFit A ETE ACTIVE
'---------------------------
boolBestFit = True
boolDraw = boolFirstFit = boolWorstFit = False
End If
End Sub
Private Sub btnWorstFit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnWorstFit.Click
If (txtInputs.Text.Length = 0) Then
MessageBox.Show("Donnez les rectangles!", "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Warning)
Else
Dim txt As String = txtInputs.Text
If txt.EndsWith(vbCrLf) Then
txt = txt.Substring(0, txt.Length - vbCrLf.Length)
End If
Dim lines() As String = txt.Split(vbCrLf)
Dim modules(lines.Length) As rectProp
Dim nouveau(lines.Length) As rectProp
For i As Integer = 0 To lines.Length - 1
Dim strucRec() As String = lines(i).Split("*")
modules(i).haut = Integer.Parse(strucRec(0))
modules(i).larg = Integer.Parse(strucRec(1))
modules(i).nom = "M" + i.ToString()
Next
Dim Matrice((lines.Length), (lines.Length)) As rectProp
'Remplir la Matrice
Dim restligne(lines.Length) As Double
For i As Integer = 0 To modules.Length - 1
restligne(i) = txtLargeur.Text
Next
For i As Integer = 0 To modules.Length - 1
For j As Integer = 0 To modules.Length - 1
Matrice(i, j).haut = 0
Matrice(i, j).larg = 0
Matrice(i, j).nom = ""
Next
Next
Dim colPosition As Integer = 0
For k As Integer = 0 To modules.Length - 1
'chercher le max dans les lignes
'Dim max As Integer = restligne.Min
Dim max As Integer = minTable(restligne)
Dim Position As Integer = 0
If (restligne(Position) < modules(k).larg) Then
'Position = Array.IndexOf(restligne, restligne.Max)
Position = Array.IndexOf(restligne, maxTable(restligne))
End If
'Remplir la matrice des valeurs
Matrice(Position, colPosition).haut = modules(k).haut
Matrice(Position, colPosition).larg = modules(k).larg
Matrice(Position, colPosition).nom = modules(k).nom
colPosition += 1
restligne(Position) -= modules(k).larg
Next
'Dessiner les rectangles
Dim myGraphics As Graphics
Dim myRectangle As Rectangle
Dim myPen As New Pen(Color.Blue)
'return the current form as a drawing surface
myGraphics = Graphics.FromHwnd(picResult().Handle)
myGraphics.Clear(Color.Transparent)
'FACTEUR DE ZOOM
'---------------
myGraphics.ScaleTransform(trckEchelle.Value / 10, trckEchelle.Value / 10)
DrawGrid(myGraphics, myPen)
Dim XPosition As Integer = 0
Dim YPosition As Integer = 0
myPen = New Pen(Color.Azure)
Dim Ymax As Integer = 0
Dim C As Integer = 0
DataGridView1.RowCount = lines.Length
For i As Integer = 0 To lines.Length - 1
For j As Integer = 0 To lines.Length - 1
'si la case de Matrice n'est pas vide
If Not (Matrice(i, j).haut = 0) Then
'Prendre une position sur l'axe des Y
If ((XPosition + (Ssale * Matrice(i, j).larg)) > picResult.Width) Then
For y As Integer = C To (i - 1)
For x As Integer = 0 To lines.Length
If (Ssale * Matrice(y, x).haut) > Ymax Then
Ymax = Ssale * Matrice(y, x).haut
End If
Next
Next
C = i
XPosition = 0
YPosition += picResult.Height
Ymax = 0
End If
If Not ((XPosition + (Ssale * Matrice(i, j).larg)) > picResult.Width) Then
'If Not (((YPosition + (Ssale * Matrice(i, j).haut)) > picResult.Height) Or ((XPosition + (Ssale * Matrice(i, j).larg)) > picResult.Width)) Then
myRectangle = New Rectangle(x:=XPosition, y:=YPosition, Width:=Ssale * Matrice(i, j).larg, Height:=Ssale * Matrice(i, j).haut)
myGraphics.DrawRectangle(pen:=myPen, rect:=myRectangle)
myRectangle.Inflate(-1.0, -1.0)
Dim myLinearGradientBrush As New LinearGradientBrush( _
myRectangle, Color.Red, Color.WhiteSmoke, LinearGradientMode.Horizontal)
myGraphics.FillRectangle(myLinearGradientBrush, myRectangle)
myGraphics.DrawString(Matrice(i, j).nom, drawFont, myBrush, myRectangle.X, myRectangle.Y, drawFormat)
XPosition += myRectangle.Width
'XPosition += Math.Ceiling(myRectangle.Width / 40) * 40
'Afficher les caractéristiques des Modules
DataGridView1.Rows(i).Cells(0).Value = Matrice(i, j).nom
DataGridView1.Rows(i).Cells(1).Value = myRectangle.Height / 10
DataGridView1.Rows(i).Cells(2).Value = myRectangle.Width / 10
DataGridView1.Rows(i).Cells(3).Value = (myRectangle.X) / 10
DataGridView1.Rows(i).Cells(4).Value = (myRectangle.Y) / 10
Else
MessageBox.Show("VOUS AVEZ DEPASSE LA TAILLE DE DISPOSITIF!", "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Warning)
End If
End If
Next
Next
'BOUTON WorstFit A ETE ACTIVE A
'------------------------------
boolWorstFit = True
boolDraw = boolFirstFit = boolBestFit = False
End If
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnQuitter.Click
Me.Close()
End Sub
Private Sub DataGridView1_CellContentClick_1(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
End Sub
Private Sub picResult_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles picResult.Click
End Sub
Private Sub txtLargeur_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtLargeur.TextChanged
End Sub
Friend Sub DisplayResults(ByVal bin_wid As Integer, ByVal rects() As Rectangle, Optional ByVal show_graphically As Boolean = True, Optional ByVal show_textually As Boolean = False)
End Sub
'FONCTION Mini RAJOUTE CAR FONCTION Mini SUR TABLEAU N'EXISTE POUR TABLEAU EN .NET FRAMEWORK 2
Private Shared Function minTable(ByVal tableDouble() As Double) As Double
Dim nbMin As Double = 0.0
Array.Sort(tableDouble)
nbMin = tableDouble(0)
Return nbMin
End Function
'FONCTION Maxi RAJOUTE CAR FONCTION Max SUR TABLEAU N'EXISTE POUR TABLEAU EN .NET FRAMEWORK 2
Private Shared Function maxTable(ByVal tableDouble() As Double) As Double
Dim nbMax As Double = 0.0
Array.Sort(tableDouble)
nbMax = tableDouble(tableDouble.Length - 1)
Return nbMax
End Function
Private Sub trckEchelle_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles trckEchelle.ValueChanged
Dim fact As Integer = trckEchelle.Value
ToolTip1.ToolTipTitle = "Zoom % " & 10 * fact.ToString
'If grapichGlobal IsNot Nothing Then
' Dim ee As PaintEventArgs = New PaintEventArgs(picResult.CreateGraphics, picResult.ClientRectangle)
' picResult.Refresh()
'End If
If boolDraw Then
RaiseEvent OnDraw(Me, EventArgs.Empty)
ElseIf boolFirstFit Then
RaiseEvent OnFirstFit(Me, EventArgs.Empty)
ElseIf boolBestFit Then
RaiseEvent OnBestFit(Me, EventArgs.Empty)
ElseIf boolWorstFit Then
RaiseEvent OnWorstFit(Me, EventArgs.Empty)
End If
End Sub
End Class |
Partager