| | 319 | |
| | 320 | === Razširitev programa panela na grafični vmesnik |
| | 321 | |
| | 322 | Celoten program lahko razširimo na grafični vmesnik, da bo lahko uporabnik lažje uporabljal napisani program. Grafični vmesnik je napisan s pomočjo knjižnice ''PyQt5''. Vmesnik bo uporabljal vertikalno razporeditev grafičnih elementov, ki so ''QPushButton'', ''QLineEdit'' in ''QLabel''. |
| | 323 | |
| | 324 | |
| | 325 | * **QPushButton** predstavlja gumb. S klikom nanj se izvede funkcija, ki opravi določeno nalogo. |
| | 326 | |
| | 327 | * **QLineEdit** omogoča vnos teksta v program. |
| | 328 | |
| | 329 | * **QLabel** služi za prikaz besedila in je statični element, ki podaja neko informacijo. |
| | 330 | |
| | 331 | Na sliki je prikazan primer izgleda uporabniškega vmesnika, ki ga bomo napisali v tem poglavju. Ta vmesnik grafične elemente razporedi v vertikalni smeri z metodo ''QVBoxLayout()''. Na vrhu je definiran ''QLabel'', pod njim pa gumb ''QPushButton''. S klikom nanj se izvede funkcija, ki izriše panel in ga pozicionira v prostoru. Nato lahko panel še rotiramo in naredimo kopije panela. V ''QLineEdit'' pod ''Set name:'' zapišemo imena rotiranih panelov, v ''QLineEdit'' pod ''Set rotation angle::'' zapišemo kot rotacije tipa `float`, v ''QLineEdit'' pod ''Set number of rotations:'' pa število panelov tipa `int`. |
| | 332 | |
| | 333 | Na začetku ponovno uvozimo vse potrebne knjižnice, tokrat tudi grafično knjižnico `PyQt5`. |
| | 334 | |
| | 335 | {{{ |
| | 336 | #!python |
| | 337 | # import libraries |
| | 338 | import salome |
| | 339 | import GEOM |
| | 340 | from salome.geom import geomBuilder |
| | 341 | import os |
| | 342 | from functools import partial |
| | 343 | # GUI library |
| | 344 | from PyQt5.QtWidgets import * |
| | 345 | from PyQt5.QtCore import * |
| | 346 | from PyQt5.QtGui import * |
| | 347 | }}} |
| | 348 | |
| | 349 | Sedaj lahko definiramo obe funkciji, kise bosta izvedli, ko bomo pritisnili na oba gumba tipa ''QPushButton''. Funkcija, ki izdela panel in ga premakne v ''y'' osi za -4200 milimetrov, se imenuje ''createPanel'' in je v osnovi isti program kot pri izdelavi panela, le da je shranjen v funkcijo. |
| | 350 | |
| | 351 | {{{ |
| | 352 | #!python |
| | 353 | def createPanel(): |
| | 354 | global panelIsMade |
| | 355 | panelIsMade = True |
| | 356 | # If file is not opened, determine path with os library |
| | 357 | os.chdir(os.path.expanduser('d:/vaje_KT/')) |
| | 358 | with open('data.txt','r') as f: |
| | 359 | fileread = f.readlines() |
| | 360 | content = [x.strip() for x in fileread] |
| | 361 | # Define data list |
| | 362 | data = [] |
| | 363 | for coord in content: |
| | 364 | data.append([x.strip() for x in coord.split(" ")]) |
| | 365 | f.close() |
| | 366 | |
| | 367 | coord_x = [] |
| | 368 | coord_y = [] |
| | 369 | # convert coordinates to mm and to float type |
| | 370 | for i in range(len(data)): |
| | 371 | data[i][0] = float(data[i][0])*(1000) |
| | 372 | data[i][1] = float(data[i][1])*(1000) |
| | 373 | data[i][2] = float(data[i][1])*(1000) |
| | 374 | coord_x.append(data[i][0]) |
| | 375 | coord_y.append(data[i][1]) |
| | 376 | |
| | 377 | |
| | 378 | # mirror x coordinatex over yz - plane |
| | 379 | coord_mirror_x = coord_x[::-1] |
| | 380 | for n in range(len(coord_mirror_x)): |
| | 381 | coord_mirror_x[n] = coord_mirror_x[n]*(-1) |
| | 382 | coord_mirror_y = coord_y[::-1] |
| | 383 | |
| | 384 | # Iterate over coord_x and create geompy vertices and store those |
| | 385 | # vertices into python list. |
| | 386 | points_x = [] |
| | 387 | for i in range(len(coord_x)): |
| | 388 | point_x = geompy.MakeVertex(coord_x[i],coord_y[i],0) |
| | 389 | points_x.append(point_x) |
| | 390 | |
| | 391 | points_y = [] |
| | 392 | for i in range(len(coord_x)): |
| | 393 | point_y = geompy.MakeVertex(coord_mirror_x[i],coord_mirror_y[i],0) |
| | 394 | points_y.append(point_y) |
| | 395 | |
| | 396 | # Create B-Spline curve on the set of points with |
| | 397 | # geompy.MakeInterpol() and add curve to Salome study. |
| | 398 | b_spline = geompy.MakeInterpol(points_x) |
| | 399 | b_splineID = geompy.addToStudy(b_spline,"b_spline_ft") |
| | 400 | |
| | 401 | b_spline_mirror = geompy.MakeInterpol(points_y) |
| | 402 | b_splineID_mirror = geompy.addToStudy(b_spline_mirror,"b_spline_ft_mirrored") |
| | 403 | |
| | 404 | # Create line between both curves. |
| | 405 | ml_point1 = geompy.MakeVertex(-coord_x[0],coord_y[0],0) |
| | 406 | ml_point2 = geompy.MakeVertex(coord_x[0],coord_y[0],0) |
| | 407 | middle_line = geompy.MakeLineTwoPnt(ml_point1,ml_point2) |
| | 408 | middle_lineID = geompy.addToStudy(middle_line,"middle_line") |
| | 409 | |
| | 410 | # Create wire out of all three components |
| | 411 | wire = geompy.MakeWire([b_spline_mirror,middle_line,b_spline]) |
| | 412 | wireID = geompy.addToStudy(wire,"wire") |
| | 413 | |
| | 414 | # Load data for extrusion |
| | 415 | dataExtrusion = [] |
| | 416 | with open('dataPolyline.txt','r') as f: |
| | 417 | fileread = f.readlines() |
| | 418 | content = [x.strip() for x in fileread] |
| | 419 | # Define data list |
| | 420 | for coord in content: |
| | 421 | dataExtrusion.append([x.strip() for x in coord.split(" ")]) |
| | 422 | f.close() |
| | 423 | |
| | 424 | # Read data for extrusion |
| | 425 | coord_xe = [] |
| | 426 | coord_ye = [] |
| | 427 | coord_ze = [] |
| | 428 | for n in range(len(dataExtrusion)): |
| | 429 | coord_xe.append(float(dataExtrusion[n][0])) |
| | 430 | coord_ye.append(float(dataExtrusion[n][1])) |
| | 431 | coord_ze.append(float(dataExtrusion[n][2])) |
| | 432 | |
| | 433 | # Convert data to geompy point and store it in a list. |
| | 434 | points_e = [] |
| | 435 | for coord_e in range(len(coord_xe)): |
| | 436 | point_e = geompy.MakeVertex(coord_xe[coord_e],coord_ye[coord_e],coord_ze[coord_e]) |
| | 437 | points_e.append(point_e) |
| | 438 | |
| | 439 | # Create polyline for extrusion and add it to study. |
| | 440 | polylineVert = geompy.MakePolyline(points_e) |
| | 441 | polylineVertID = geompy.addToStudy(polylineVert,"polyline_ft_vert") |
| | 442 | panel_FW = geompy.MakePipe(wire, polylineVert) |
| | 443 | panel_FW = geompy.MakeTranslation(panel_FW, 0,-4200,0) |
| | 444 | geompy.addToStudy(panel_FW,'Panel') |
| | 445 | salome.sg.updateObjBrowser(True) |
| | 446 | }}} |