@@ -82,10 +82,10 @@ def __init__(
8282 def draw_lines (self , lines , for_selection , j = 0 , geometry = None ):
8383 """
8484 Returns the list of lines to draw in a format suitable for OpenGL.
85- if line is
85+ if line is
8686 Traverse: [(line number, (start position), (end position), (tlo x, tlo y, tlo z))]
8787 Feed: [(line number, (start position), (end position), feedrate, (tlo x, tlo y, tlo z))]
88- ArcFeed: [(line number, (start position), (end position), feedrate, (tlo x, tlo y, tlo z))]
88+ ArcFeed: [(line number, (start position), (end position), feedrate, (tlo x, tlo y, tlo z))]
8989 """
9090 out_list = []
9191 if len (lines ) < 0 :
@@ -271,16 +271,14 @@ def init_gl(self):
271271 self .VBO_LIMITS_COLORS = glGenBuffers (1 )
272272 self .VBO_BOUND_BOX_COLORS = glGenBuffers (1 )
273273
274- def origin_render (self ):
274+ def origin_render (self , origin_size = 1.0 ):
275275 """
276276 Render the origin axis
277277 """
278278
279279 # Draw the triangle
280280 glBindVertexArray (self .VAO_ORIGIN )
281281
282- # Origin lines
283- origin_size = 1.0
284282 # fmt: off
285283 lines = [
286284 0.0 , 0.0 , 0.0 , origin_size , 0.0 , 0.0 ,
@@ -508,6 +506,29 @@ def load_preview(self, f, canon, *args):
508506 return result , seq
509507
510508
509+ class GraphicsOptions :
510+
511+ def __init__ (self ):
512+ self .show_bounding_box = True
513+ self .show_machine_limits = True
514+ self .show_origin = True
515+ self .show_tool = True
516+ self .show_feed = True
517+ self .show_traverse = True
518+ self .show_arc = True
519+ self .show_dwell = True
520+ self .highlight_line = - 1 # TODO
521+
522+ self .mouse_pan_button = QtCore .Qt .LeftButton
523+ self .mouse_rotate_button = QtCore .Qt .RightButton
524+ self .mouse_zoom_button = None # Personal preference scroll wheel is superior
525+ self .mouse_pan_sensitivity = 0.005
526+ self .mouse_rotate_sensitivity = 0.1
527+ self .mouse_zoom_sensitivity = 0.1
528+
529+ self .origin_size = 1.0
530+
531+
511532class QtShader (QtWidgets .QOpenGLWidget , CanonShaders ):
512533 """
513534 A Qt widget that uses OpenGL to render using CanonShaders.
@@ -526,6 +547,7 @@ def __init__(
526547 ):
527548 CanonShaders .__init__ (self , lp = None , canon = None )
528549 QtWidgets .QOpenGLWidget .__init__ (self )
550+ self .options = GraphicsOptions ()
529551 self .status = linuxcnc .stat ()
530552 self .colors = colors
531553 self .init_canon ()
@@ -579,10 +601,21 @@ def paintGL(self):
579601 MatrixID = glGetUniformLocation (self .shader_program , "MVP" )
580602 glUniformMatrix4fv (MatrixID , 1 , GL_FALSE , mvp_data )
581603
604+ if self .options .show_feed is False :
605+ self .canon .feed = []
606+ if self .options .show_arc is False :
607+ self .canon .arcfeed = []
608+ if self .options .show_traverse is False :
609+ self .canon .traverse = []
610+ if self .options .show_dwell is False :
611+ self .canon .dwells = []
582612 self .gcode_render ()
583- self .origin_render ()
584- self .draw_bounding_box ()
585- self .draw_machine_limits ()
613+ if self .options .show_origin :
614+ self .origin_render (self .options .origin_size )
615+ if self .options .show_bounding_box :
616+ self .draw_bounding_box ()
617+ if self .options .show_machine_limits :
618+ self .draw_machine_limits ()
586619
587620 def load_file (self , filename ):
588621 """
@@ -617,41 +650,41 @@ def load_file(self, filename):
617650
618651 def mousePressEvent (self , e ):
619652
620- if e .button () == QtCore . Qt . LeftButton :
653+ if e .button () == self . options . mouse_pan_button :
621654 self .last_mouse_position = e .pos ()
622- elif e .button () == QtCore . Qt . RightButton :
655+ elif e .button () == self . options . mouse_rotate_button :
623656 self .last_mouse_position = e .pos ()
624657 self .angularSpeed = 0.1
625658 self .update ()
626659
627660 def mouseReleaseEvent (self , e ):
628- if e .button () == QtCore . Qt . LeftButton :
661+ if e .button () == self . options . mouse_pan_button :
629662 new_x = e .pos ().x () - self .last_mouse_position .x ()
630663 new_y = e .pos ().y () - self .last_mouse_position .y ()
631664 # TODO: Fix Scaling
632- self .current_x += new_x * 0.005
633- self .current_y -= new_y * 0.005
665+ self .current_x += new_x * self . options . mouse_pan_sensitivity
666+ self .current_y -= new_y * self . options . mouse_pan_sensitivity
634667 else :
635668 return
636669
637670 def mouseMoveEvent (self , e ):
638- if e .buttons () & QtCore . Qt . LeftButton :
671+ if e .buttons () & self . options . mouse_pan_button :
639672 new_x = e .pos ().x () - self .last_mouse_position .x ()
640673 new_y = e .pos ().y () - self .last_mouse_position .y ()
641- self .current_x += new_x * 0.005
642- self .current_y -= new_y * 0.005
674+ self .current_x += new_x * self . options . mouse_pan_sensitivity
675+ self .current_y -= new_y * self . options . mouse_pan_sensitivity
643676 self .last_mouse_position = e .pos ()
644677
645- elif e .buttons () & QtCore . Qt . RightButton :
678+ elif e .buttons () & self . options . mouse_rotate_button :
646679 fudge = 1.5
647680 new_x = (e .pos ().x () - self .last_mouse_position .x ()) * fudge
648- new_y = (- 1 * (e .pos ().y () - self .last_mouse_position .y ())) * fudge
681+ new_y = (- 1 * (e .pos ().y () - self .last_mouse_position .y ())) * fudge
649682
650683 dist = (new_x ** 2 + new_y ** 2 ) ** 0.5
651684 x_percent = new_x / dist if dist != 0 else 0
652685 y_percent = new_y / dist if dist != 0 else 0
653686
654- self .angularSpeed = dist * 0.1 # Adjust rotation speed based on
687+ self .angularSpeed = dist * self . options . mouse_rotate_sensitivity
655688
656689 # TODO: Fix center of rotation.
657690 self .rotationAxis = QtGui .QVector3D (- 1 * y_percent , x_percent , 0 ) # Update rotation axis
@@ -665,7 +698,7 @@ def wheelEvent(self, e: QtGui.QWheelEvent):
665698 Handle mouse scroll events to zoom in and out.
666699 """
667700 delta = e .angleDelta ().y () / 120
668- self .current_scale += delta * 0.1
701+ self .current_scale += delta * self . options . mouse_zoom_sensitivity
669702 self .current_scale = max (0.1 , min (self .current_scale , 10.0 ))
670703 self .update ()
671704
0 commit comments