def drawcorner(self): BGL.glBegin(BGL.GL_LINES) BGL.glColor3f(self.col[0],self.col[1],self.col[2]) BGL.glVertex2i(self.x+4*self.xflip,self.y+1*self.yflip) BGL.glVertex2i(self.x+8*self.xflip,self.y+1*self.yflip) BGL.glVertex2i(self.x+3*self.xflip,self.y+2*self.yflip) BGL.glVertex2i(self.x+8*self.xflip,self.y+2*self.yflip) BGL.glVertex2i(self.x+2*self.xflip,self.y+3*self.yflip) BGL.glVertex2i(self.x+8*self.xflip,self.y+3*self.yflip) BGL.glVertex2i(self.x+1*self.xflip,self.y+4*self.yflip) BGL.glVertex2i(self.x+8*self.xflip,self.y+4*self.yflip) # change colour for border, if needed BGL.glColor3f(self.bcol[0],self.bcol[1],self.bcol[2]) BGL.glVertex2i(self.x+5*self.xflip,self.y) BGL.glVertex2i(self.x+8*self.xflip,self.y) BGL.glVertex2i(self.x+5*self.xflip,self.y) BGL.glVertex2i(self.x,self.y+5*self.yflip) BGL.glVertex2i(self.x,self.y+5*self.yflip) BGL.glVertex2i(self.x,self.y+8*self.yflip) BGL.glEnd()
def drawpanel(self): ## Draw the main part of the panel. BGL.glColor3f(self.col[0],self.col[1],self.col[2]) BGL.glRecti(self.left+5,self.base,self.right-5,self.top) ## Large middle bit. BGL.glRecti(self.left,self.base+4,self.left+8,self.top-4) ## Left small side strip. BGL.glRecti(self.right-8,self.base+4,self.right,self.top-4) ## Right small side strip. ## Draw the borders. BGL.glColor3f(self.bcol[0],self.bcol[1],self.bcol[2]) ## Change to border colour. BGL.glBegin(BGL.GL_LINES) BGL.glVertex2i(self.left+6,self.base) ## Base border. BGL.glVertex2i(self.right-6,self.base) BGL.glVertex2i(self.left+6,self.top) ## Top border. BGL.glVertex2i(self.right-6,self.top) BGL.glVertex2i(self.left,self.base+6) ## Left border. BGL.glVertex2i(self.left,self.top-6) BGL.glVertex2i(self.right,self.base+6) ## Right border. BGL.glVertex2i(self.right,self.top-6) BGL.glEnd()
def DrawBox(x, y, w, h): BGL.glBegin(BGL.GL_LINE_LOOP) BGL.glVertex2i(x,y) BGL.glVertex2i(x+w,y) BGL.glVertex2i(x+w,y-h) BGL.glVertex2i(x,y-h) BGL.glEnd()
def Draw_Border(X1,Y1,X2,Y2): # X1,Y1 = Top Left X2,Y2 = Bottom Right """ Draw a border given a top left corner (X1, X2) and bottom right (X2, Y2) """ INDENT = 3 BGL.glColor3f(1.0,1.0,1.0) BGL.glBegin(BGL.GL_LINES) BGL.glVertex2i(X1+INDENT,Y1-INDENT) #top line BGL.glVertex2i(X2-INDENT,Y1-INDENT) BGL.glVertex2i(X1+INDENT,Y1-INDENT) #left line BGL.glVertex2i(X1+INDENT,Y2+INDENT) BGL.glEnd() BGL.glColor3f(0.5,0.5,0.5) BGL.glBegin(BGL.GL_LINES) BGL.glVertex2i(X2-INDENT,Y1-INDENT) #Right line BGL.glVertex2i(X2-INDENT,Y2+INDENT) BGL.glVertex2i(X1+INDENT,Y2+INDENT) #bottom line BGL.glVertex2i(X2-INDENT,Y2+INDENT) BGL.glEnd()
def drawcorner(self): BGL.glColor3f(self.col[0],self.col[1],self.col[2]) for i in range(8): BGL.glBegin(BGL.GL_LINES) BGL.glVertex2i(self.x,self.y+i*self.yflip) BGL.glVertex2i(self.x+8*self.xflip,self.y+i*self.yflip) BGL.glEnd() # change colour for border, if needed BGL.glColor3f(self.bcol[0],self.bcol[1],self.bcol[2]) BGL.glBegin(BGL.GL_LINES) BGL.glVertex2i(self.x,self.y) BGL.glVertex2i(self.x+9*self.xflip,self.y) BGL.glVertex2i(self.x,self.y) BGL.glVertex2i(self.x,self.y+9*self.yflip) BGL.glEnd()
def coversides(self): ## This function draws lines to cover up border lines designated by the sides arguement. BGL.glColor3f(self.col[0],self.col[1],self.col[2]) if self.sides[0]: # left border BGL.glBegin(BGL.GL_LINES) BGL.glVertex2i(self.left,self.base+1) BGL.glVertex2i(self.left,self.top) BGL.glEnd() if self.sides[1]: # top border BGL.glBegin(BGL.GL_LINES) BGL.glVertex2i(self.left+1,self.top) BGL.glVertex2i(self.right,self.top) BGL.glEnd() if self.sides[2]: # right border BGL.glBegin(BGL.GL_LINES) BGL.glVertex2i(self.right,self.base+1) BGL.glVertex2i(self.right,self.top) BGL.glEnd() if self.sides[3]: # base border BGL.glBegin(BGL.GL_LINES) BGL.glVertex2i(self.left+1,self.base) BGL.glVertex2i(self.right,self.base) BGL.glEnd()
def renderGUI(): """ Renders the GUI for the script. """ global G # find the selection set and update some selection # related flags haveEmpty = False haveCamera = False emptyName = "" G.selection = Object.GetSelected() G.curempty = None if G.selection is not None and len(G.selection) > 0: mso = G.selection[0] msotype = mso.getType() if msotype == 'Empty': haveEmpty = True G.curempty = mso emptyName = G.curempty.getName() elif msotype == 'Camera': haveCamera = True emptyHasCoords = G.coordmap.has_key(emptyName) removeUnknownsFromCoords() # clear any buttons that need to have set states G.buttons.add = G.buttons.delete = None # clear the window c = COLOR_BACKGROUND BGL.glClearColor(c[0], c[1], c[2], c[3]) BGL.glClear(BGL.GL_COLOR_BUFFER_BIT) # paint the image in the background if G.image is not None: #drawImage(G.image, G.imgpos, G.iw, G.ih, G.zoom) Draw.Image(G.image, G.imgpos[0], G.imgpos[1], G.zoom, G.zoom) # paint 2D vertices in the image BGL.glPushAttrib(BGL.GL_POINT_BIT | BGL.GL_CURRENT_BIT) BGL.glPointSize(POINT_SIZE) x0 = int(G.imgpos[0] / G.zoom) y0 = int(G.imgpos[1] / G.zoom) def drawvc(ec): emptyname, coord = ec if Object.Get(emptyname) in G.selection: c = COLOR_VERTSEL else: c = COLOR_VERTUNSEL BGL.glColor4f(c[0], c[1], c[2], c[3]) BGL.glVertex2f(G.zoom*(coord[0]+x0), G.zoom*(coord[1]+y0)) BGL.glBegin(BGL.GL_POINTS) map(drawvc, G.coordmap.items()) BGL.glEnd() BGL.glPopAttrib() # if we're in add mode then draw some extra stuff if G.mode == MODE_ADD: xm,ym = map(int, getWMCoords()) xm -= 10 ym += 10 (xw,yw,ww,hw) = getWinRect() # draw crosshairs c = COLOR_CROSSHAIRS BGL.glColor4f(c[0], c[1], c[2], c[3]) verts = [ (xm,0), (xm,hw), (0,ym), (ww,ym) ] BGL.glBegin(BGL.GL_LINES) map(lambda x: BGL.glVertex2d(x[0],x[1]), verts) BGL.glEnd() ############################################# # UNCOMMENT THIS SECTION FOR A COOL MINIMAP # EFFECT - NOT VERY USEFUL THOUGH # ## draw "minimap" background #c = COLOR_MINIMAP #BGL.glColor4f(c[0], c[1], c[2], c[3]) #verts = [ (119,10), (221,10), (221,111), (119,111) ] #BGL.glBegin(BGL.GL_QUADS) #map(lambda x: BGL.glVertex2i(x[0],x[1]), verts) #BGL.glEnd() # ## paint the image into the minimap #ix,iy = wc2ic((xm,ym)) #ix,iy = map(int, [ix, iy]) #drawImage(G.ibuf, (120,10), G.iw, G.ih, 10.0, (ix-5,iy-5,10,10)) # # END OF MINIMAP SECTION ############################################# # paint the current empty name if haveEmpty: c = COLOR_TEXT BGL.glColor4d(c[0], c[1], c[2], c[3]) BGL.glRasterPos2i(220, 10) Draw.Text(emptyName, 'small') # paint the normal GUI buttons G.buttons.quit = Draw.PushButton('Quit', BUTTON_QUIT, 5, 5, 100, 20, 'Exits the script.') G.buttons.load = Draw.PushButton('Load Image', BUTTON_LOAD, 5, 25, 100, 20, 'Loads an image.') G.buttons.zoom = Draw.Number('Zoom', BUTTON_ZOOM, 5, 45, 100, 20, G.zoom, ZOOM_MIN, ZOOM_MAX, 'Adjusts image zoom.') # paint camera-specific stuff if haveCamera: G.buttons.fullopt = Draw.Toggle('Full Optimization', BUTTON_FULLOPT, 110, 5, 120, 20, G.fullopt, 'Full or partial optimization.') G.buttons.coplanar = Draw.Toggle('Coplanar', BUTTON_COPLANAR, 110, 25, 120, 20, G.coplanar, 'Coplanar or non-coplanar target.') # Origin offset is not currently working in the Tsai module. # It should be brought back here when it is. #G.buttons.ofsz = Draw.Number('OfsZ', BUTTON_OFSZ, 110, 50, 100, 20, G.ofsz, OFS_MIN, OFS_MAX, 'Z origin offset.') #G.buttons.ofsy = Draw.Number('OfsY', BUTTON_OFSY, 110, 70, 100, 20, G.ofsy, OFS_MIN, OFS_MAX, 'Y origin offset.') #G.buttons.ofsx = Draw.Number('OfsX', BUTTON_OFSX, 110, 90, 100, 20, G.ofsx, OFS_MIN, OFS_MAX, 'X origin offset.') G.buttons.calibrate = Draw.PushButton('Calibrate', BUTTON_CALIBRATE, 235, 5, 100, 20, 'Calibrates the selected camera.') # paint empty-specific stuff elif haveEmpty and (G.mode == MODE_NORMAL): if emptyHasCoords: G.buttons.delete = Draw.PushButton('Delete', BUTTON_DELETE, 110, 5, 100, 20, 'Adds an image calibration coordinate.') else: G.buttons.add = Draw.PushButton('Add', BUTTON_ADD, 110, 5, 100, 20, 'Removes an image calibration coordinate.')
def renderGUI(): """ Renders the GUI for the script. """ global G # find the selection set and update some selection # related flags haveEmpty = False haveCamera = False emptyName = "" G.selection = Object.GetSelected() G.curempty = None if G.selection is not None and len(G.selection) > 0: mso = G.selection[0] msotype = mso.getType() if msotype == 'Empty': haveEmpty = True G.curempty = mso emptyName = G.curempty.getName() elif msotype == 'Camera': haveCamera = True emptyHasCoords = G.coordmap.has_key(emptyName) removeUnknownsFromCoords() # clear any buttons that need to have set states G.buttons.add = G.buttons.delete = None # clear the window c = COLOR_BACKGROUND BGL.glClearColor(c[0], c[1], c[2], c[3]) BGL.glClear(BGL.GL_COLOR_BUFFER_BIT) # paint the image in the background if G.image is not None: #drawImage(G.image, G.imgpos, G.iw, G.ih, G.zoom) Draw.Image(G.image, G.imgpos[0], G.imgpos[1], G.zoom, G.zoom) # paint 2D vertices in the image BGL.glPushAttrib(BGL.GL_POINT_BIT | BGL.GL_CURRENT_BIT) BGL.glPointSize(POINT_SIZE) x0 = int(G.imgpos[0] / G.zoom) y0 = int(G.imgpos[1] / G.zoom) def drawvc(ec): emptyname, coord = ec if Object.Get(emptyname) in G.selection: c = COLOR_VERTSEL else: c = COLOR_VERTUNSEL BGL.glColor4f(c[0], c[1], c[2], c[3]) BGL.glVertex2f(G.zoom * (coord[0] + x0), G.zoom * (coord[1] + y0)) BGL.glBegin(BGL.GL_POINTS) map(drawvc, G.coordmap.items()) BGL.glEnd() BGL.glPopAttrib() # if we're in add mode then draw some extra stuff if G.mode == MODE_ADD: xm, ym = map(int, getWMCoords()) xm -= 10 ym += 10 (xw, yw, ww, hw) = getWinRect() # draw crosshairs c = COLOR_CROSSHAIRS BGL.glColor4f(c[0], c[1], c[2], c[3]) verts = [(xm, 0), (xm, hw), (0, ym), (ww, ym)] BGL.glBegin(BGL.GL_LINES) map(lambda x: BGL.glVertex2d(x[0], x[1]), verts) BGL.glEnd() ############################################# # UNCOMMENT THIS SECTION FOR A COOL MINIMAP # EFFECT - NOT VERY USEFUL THOUGH # ## draw "minimap" background #c = COLOR_MINIMAP #BGL.glColor4f(c[0], c[1], c[2], c[3]) #verts = [ (119,10), (221,10), (221,111), (119,111) ] #BGL.glBegin(BGL.GL_QUADS) #map(lambda x: BGL.glVertex2i(x[0],x[1]), verts) #BGL.glEnd() # ## paint the image into the minimap #ix,iy = wc2ic((xm,ym)) #ix,iy = map(int, [ix, iy]) #drawImage(G.ibuf, (120,10), G.iw, G.ih, 10.0, (ix-5,iy-5,10,10)) # # END OF MINIMAP SECTION ############################################# # paint the current empty name if haveEmpty: c = COLOR_TEXT BGL.glColor4d(c[0], c[1], c[2], c[3]) BGL.glRasterPos2i(220, 10) Draw.Text(emptyName, 'small') # paint the normal GUI buttons G.buttons.quit = Draw.PushButton('Quit', BUTTON_QUIT, 5, 5, 100, 20, 'Exits the script.') G.buttons.load = Draw.PushButton('Load Image', BUTTON_LOAD, 5, 25, 100, 20, 'Loads an image.') G.buttons.zoom = Draw.Number('Zoom', BUTTON_ZOOM, 5, 45, 100, 20, G.zoom, ZOOM_MIN, ZOOM_MAX, 'Adjusts image zoom.') # paint camera-specific stuff if haveCamera: G.buttons.fullopt = Draw.Toggle('Full Optimization', BUTTON_FULLOPT, 110, 5, 120, 20, G.fullopt, 'Full or partial optimization.') G.buttons.coplanar = Draw.Toggle('Coplanar', BUTTON_COPLANAR, 110, 25, 120, 20, G.coplanar, 'Coplanar or non-coplanar target.') # Origin offset is not currently working in the Tsai module. # It should be brought back here when it is. #G.buttons.ofsz = Draw.Number('OfsZ', BUTTON_OFSZ, 110, 50, 100, 20, G.ofsz, OFS_MIN, OFS_MAX, 'Z origin offset.') #G.buttons.ofsy = Draw.Number('OfsY', BUTTON_OFSY, 110, 70, 100, 20, G.ofsy, OFS_MIN, OFS_MAX, 'Y origin offset.') #G.buttons.ofsx = Draw.Number('OfsX', BUTTON_OFSX, 110, 90, 100, 20, G.ofsx, OFS_MIN, OFS_MAX, 'X origin offset.') G.buttons.calibrate = Draw.PushButton( 'Calibrate', BUTTON_CALIBRATE, 235, 5, 100, 20, 'Calibrates the selected camera.') # paint empty-specific stuff elif haveEmpty and (G.mode == MODE_NORMAL): if emptyHasCoords: G.buttons.delete = Draw.PushButton( 'Delete', BUTTON_DELETE, 110, 5, 100, 20, 'Adds an image calibration coordinate.') else: G.buttons.add = Draw.PushButton( 'Add', BUTTON_ADD, 110, 5, 100, 20, 'Removes an image calibration coordinate.')