Basic Window
Create a minimal QT window using IGLGraphics Library to import and display a 3D CAD assembly.
This tutorial demonstrates the complete workflow of creating a Qt application, initializing the OpenGL viewer, importing geometry data and displaying the model.
Basic Cad Viewer
# Import necessary modules
import sys # Provides access to system-specific parameters and functions
from PySide6.QtWidgets import QApplication, QMainWindow # Import Qt widgets for GUI application
# Import IGLGraphics modules for display context and viewer
from IGLGraphics.core.IGLDisplayContext import IGLDisplayContext
from IGLGraphics.graphics.IGLViewer import IGLViewer
from IGLGraphics.geometry.IGLImport import IGLImport
# Create the QApplication instance,
# which manages the application's control flow and main settings
app = QApplication(sys.argv)
# Create the main window of the application
win = QMainWindow()
# Set the title of the main window
win.setWindowTitle("IGLGraphics Test")
# Create an instance of IGLViewer, which is a IGLViewer widget for
# displaying models and handling user interactions
view = IGLViewer()
# Create an IGLDisplayContext associated with the viewer, for managing graphics rendering context
thecontext = IGLDisplayContext(view)
# Create an instance of IGLImport to handle importing geometry data from files
importer = IGLImport()
filename = 'Saddle.json'
is_valid, Assemblies = importer.ImportGeo(filename)
thecontext.AddAssembly(Assemblies) # Add the imported assemblies to the display context
# Set the central widget of the main window to the IGLViewer
win.setCentralWidget(view)
# Resize the window to 800x600 pixels
win.resize(800, 600)
# Show the main window
win.show()
view.OnZoomFit() # Adjust the view to fit the entire model in the viewport
# Start the application's event loop and exit when it finishes
sys.exit(app.exec())