Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 2 commits
  • 1 file changed
  • 0 comments
  • 1 contributor

Showing 1 changed file with 45 additions and 21 deletions. Show diff stats Hide diff stats

  1. 66  eagleview.py
66  eagleview.py
@@ -56,8 +56,8 @@ def get_size(self):
56 56
 			maxy = max(maxy, y)
57 57
 		return (minx, miny), (maxx, maxy)
58 58
 
59  
-	def set_color_by_layer(self, cr, item, mirrored, **kwargs):
60  
-		layerno = item.layer if not mirrored else self.layers[item.layer].other
  59
+	def set_color_by_layer(self, cr, item, context, mirrored, **kwargs):
  60
+		layerno = item.layer if not mirrored or context == 'schema' else self.layers[item.layer].other
61 61
 		try:
62 62
 			color = self.colors[self.layers[layerno].color]
63 63
 		except:
@@ -102,7 +102,12 @@ def draw(self, cr):
102 102
 		cr.set_line_cap(cairo.LINE_CAP_ROUND)
103 103
 
104 104
 		#self.draw_grid(cr, self.grid)
105  
-		self.draw_item(cr, self.module, mirrored = False)
  105
+		context = None
  106
+		if isinstance(item, eagle.SchemaSheetSection):
  107
+			context = 'schema'
  108
+		elif isinstance(item, eagle.BoardSection):
  109
+			context = 'board'
  110
+		self.draw_item(cr, self.module, context = context, mirrored = False, spin = False, angle = 0)
106 111
 
107 112
 	def draw_item(self, cr, item, **kwargs):
108 113
 		if isinstance(item, eagle.SchemaSheetSection):
@@ -195,15 +200,26 @@ def draw_package(self, cr, pac, **kwargs):
195 200
 		for item in pac.drawables:
196 201
 			self.draw_item(cr, item, **kwargs)
197 202
 
  203
+	def transform(self, cr, item, mirrored, spin, angle, **kwargs):
  204
+		cr.translate(item.x, item.y)
  205
+		if item.mirrored:
  206
+			mirrored = not mirrored
  207
+			cr.scale(-1, 1)
  208
+		if hasattr(item, 'spin') and item.spin:
  209
+			spin = not spin
  210
+		angle += item.angle if not mirrored else -item.angle
  211
+		cr.rotate(math.radians(360 * item.angle / 4096.))
  212
+		kwargs['mirrored'] = mirrored
  213
+		kwargs['spin'] = spin
  214
+		kwargs['angle'] = angle
  215
+		return kwargs
  216
+
198 217
 	def draw_schemadevice(self, cr, schdev, **kwargs):
199 218
 		for schins in schdev.instances:
200 219
 			if not schins.placed:
201 220
 				continue
202 221
 			cr.save()
203  
-			cr.translate(schins.x, schins.y)
204  
-			if schins.mirrored:
205  
-				cr.scale(-1, 1)
206  
-			cr.rotate(math.radians(360 * schins.angle / 4096.))
  222
+			kwargs = self.transform(cr, schins, **kwargs)
207 223
 			lib = self.libraries[schdev.libno-1]
208 224
 			dev = lib.devices.devices[schdev.devno-1]
209 225
 			devgat = dev.gates[schins.gateno-1]
@@ -211,35 +227,43 @@ def draw_schemadevice(self, cr, schdev, **kwargs):
211 227
 			self.draw_symbol(cr, sym, **kwargs)
212 228
 			cr.restore()
213 229
 
214  
-	def draw_boardpackage(self, cr, item, mirrored, **kwargs):
  230
+	def draw_boardpackage(self, cr, item, **kwargs):
215 231
 		cr.save()
216  
-		cr.translate(item.x, item.y)
217  
-		if item.mirrored:
218  
-			mirrored = not mirrored
219  
-			cr.scale(-1, 1)
220  
-		cr.rotate(math.radians(360 * item.angle / 4096.))
  232
+		kwargs = self.transform(cr, item, **kwargs)
221 233
 		brd = self.module
222 234
 		pacs = brd.definitions[item.libno-1]
223 235
 		pac = pacs.packages[item.pacno-1]
224  
-		self.draw_symbol(cr, pac, mirrored = mirrored, **kwargs)
  236
+		self.draw_symbol(cr, pac, **kwargs)
225 237
 		cr.restore()
226 238
 
227 239
 	def draw_text(self, cr, item, **kwargs):
228 240
 		# XXX: Eh...
229 241
 		self.set_color_by_layer(cr, item, **kwargs)
230 242
 		cr.save()
231  
-		cr.translate(item.x, item.y)
232  
-		if item.mirrored:
233  
-			cr.scale(-1, 1)
234  
-		cr.rotate(math.radians(360 * item.angle / 4096.))
  243
+		kwargs = self.transform(cr, item, **kwargs)
  244
+		context, mirrored, spin, angle = kwargs['context'], kwargs['mirrored'], kwargs['spin'], kwargs['angle']
235 245
 		cr.set_font_size(item.size_2*2)
236 246
 		fascent, fdescent, fheight, fxadvance, fyadvance = cr.font_extents()
237 247
 		xbearing, ybearing, width, height, xadvance, yadvance = cr.text_extents(item.text)
238 248
 		# We have inverted y coordinates relative to cairo, so we have to invert them here to get text rendered correctly
239 249
 		cr.scale(1, -1)
240  
-		if not item.spin and (90 < 360 * item.angle / 4096 <= 270):
241  
-			cr.scale(-1, -1)
242  
-			cr.translate(-width, fascent)
  250
+		if mirrored:
  251
+			if context == 'schema':
  252
+				angle = 2048 + angle
  253
+				cr.scale(1, -1)
  254
+				cr.translate(0, fascent)
  255
+		angle %= 4096
  256
+		if context == 'schema':
  257
+			if (90 < 360 * angle / 4096 <= 270):
  258
+				cr.scale(-1, -1)
  259
+				cr.translate(-width, fascent)
  260
+		elif not spin:
  261
+			if not mirrored and (90 < 360 * angle / 4096 <= 270):
  262
+				cr.scale(-1, -1)
  263
+				cr.translate(-width, fascent)
  264
+			if mirrored and (90 <= 360 * angle / 4096 < 270):
  265
+				cr.scale(-1, -1)
  266
+				cr.translate(-width, fascent)
243 267
 		cr.translate(-xbearing, 0)
244 268
 		cr.show_text(item.text)
245 269
 		cr.fill()

No commit comments for this range

Something went wrong with that request. Please try again.