0% found this document useful (0 votes)
4 views4 pages

Import Sys

The document is a Python script that implements an IFC (Industry Foundation Classes) viewer using PyQt5 and OpenGL. It allows users to load IFC files, visualize 3D shapes, and interactively adjust the cutting plane along the Z-axis. The main components include the IFCViewer class for rendering and the MainWindow class for the user interface.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views4 pages

Import Sys

The document is a Python script that implements an IFC (Industry Foundation Classes) viewer using PyQt5 and OpenGL. It allows users to load IFC files, visualize 3D shapes, and interactively adjust the cutting plane along the Z-axis. The main components include the IFCViewer class for rendering and the MainWindow class for the user interface.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

import sys

import ifcopenshell

import [Link]

from [Link] import QApplica on, QMainWindow, QFileDialog, QOpenGLWidget,


QPushBu on

from [Link] import Qt

from [Link] import *

from [Link] import *

class IFCViewer(QOpenGLWidget):

def __init__(self, parent=None):

super(IFCViewer, self).__init__(parent)

[Link] = []

self.cut_z = 0.0 # Niveau du plan de coupe

def load_ifc_file(self, filepath):

se ngs = [Link] ngs()

se [Link](se ngs.USE_WORLD_COORDS, True)

model = [Link](filepath)

[Link] = []

for product in model.by_type("IfcProduct"):

try:

shape = [Link].create_shape(se ngs, product)

[Link]([Link])

except:

pass
[Link]()

def ini alizeGL(self):

glClearColor(0.9, 0.9, 0.95, 1.0)

glEnable(GL_DEPTH_TEST)

glEnable(GL_CULL_FACE)

def resizeGL(self, w, h):

glViewport(0, 0, w, h)

glMatrixMode(GL_PROJECTION)

glLoadIden ty()

gluPerspec ve(45.0, w / h if h != 0 else 1, 1.0, 1000.0)

glMatrixMode(GL_MODELVIEW)

def paintGL(self):

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)

glLoadIden ty()

gluLookAt(300, -300, 200, 0, 0, 0, 0, 0, 1)

for shape in [Link]:

glBegin(GL_TRIANGLES)

for i in range(0, len(shape), 9):

z_avg = (shape[i+2] + shape[i+5] + shape[i+8]) / 3

if z_avg >= self.cut_z:

glColor3f(0.5, 0.5, 0.8)

for j in range(0, 9, 3):

glVertex3f(shape[i + j], shape[i + j + 1], shape[i + j + 2])

glEnd()
def keyPressEvent(self, event):

if [Link]() == Qt.Key_Up:

self.cut_z += 10

[Link]()

elif [Link]() == Qt.Key_Down:

self.cut_z -= 10

[Link]()

class MainWindow(QMainWindow):

def __init__(self):

super(MainWindow, self).__init__()

[Link]("Visualiseur IFC avec coupe Z")

[Link](100, 100, 1000, 700)

[Link] = IFCViewer(self)

[Link]([Link])

open_bu on = QPushBu on("Ouvrir IFC", self)

open_bu [Link](self.load_ifc)

open_bu [Link](10, 10)

open_bu [Link](100, 30)

open_bu on.raise_()

def load_ifc(self):

file_path, _ = [Link](self, "Choisir un fichier IFC", "", "Fichiers IFC


(*.ifc)")
if file_path:

[Link].load_ifc_file(file_path)

if __name__ == "__main__":

app = QApplica on([Link])

window = MainWindow()

[Link]()

[Link](app.exec_())

You might also like