def __loadLDrawColors(self): self.colorDict = LicColorDict() try: LicImporters.LDrawImporter.importColorFile(self.getProxy()) self.colorDict.licColors = False; except IOError as e: # Could not load LDConfig.ldr. Fall back to internal color definitions from LDrawColors.py (TODO: update those colors!) self.colorDict.licColors = True; for colorCode, color in LDrawColors.colors.iteritems(): newColor = None if color[0] is None else LicColor(*color) self.colorDict[colorCode] = newColor if (newColor): newColor.originalRGBA = list(newColor.rgba) newColor.edgeColor = LicColor.black()
def createPartLine(color, matrix, filename): lDrawCode = color.code() if color else LicColor.black().code() l = [PartCommand, str(lDrawCode)] m = GLToLDMatrix(matrix) l += [str(x)[:-2] if str(x).endswith(".0") else str(x) for x in m] l.append(filename) line = ' '.join(l) return line + lineTerm
def createPart(self, fn, colorCode, matrix, invert=False, rgba=()): partDictionary = self.__instructions.partDictionary # assigned custom color data <tuple>(r,g,b,a) ,otherwise stay <integer>colorCode AS IS if 16 == colorCode and rgba: color = LicColor(rgba[0], rgba[1], rgba[2], rgba[3], "Custom") else: color = self.__instructions.colorDict[colorCode] part = Part(fn, color, matrix, invert) if fn in partDictionary: part.abstractPart = partDictionary[fn] elif fn.upper() in partDictionary: part.abstractPart = partDictionary[fn.upper()] elif fn.lower() in partDictionary: part.abstractPart = partDictionary[fn.lower()] return part
def lineToPart(line): """ If you don't specify base=0, python defaults to base=10 which gets your error. This is desired, so say int('077') == 77 ('077' is interpreted as decimal), while int('077',0) == 63 (interpreted as try guessing the base from the string so its octal) Apparently, int("0xdeadbeef", 0) works only if you have exactly 10 characters in the string; for instance, I get: "ValueError: invalid literal for int() with base 10: '0x1630'", if I don't specify base 16. """ filename = ' '.join(line[15:]) rgba = () color = 16 if line[2].startswith("0x"): rgba = LicColor.RGBAfromCustom(line[2]) else: color = int(line[2] , base=0) matrix = LDToGLMatrix(line[3:15]) return (filename, color, matrix, rgba)
def doOverflowLayout(self): self.resetRect() # If this PLI is empty, nothing to do here if len(self.pliItems) < 1: return [] # Initialize each item in this PLI, so they have good rects and properly positioned quantity labels for item in self.pliItems: item.initLayout() partList = list(self.pliItems) partList.sort(key=lambda x: (x.color.sortKey() if (x.color) else LicColor.red().sortKey(), x.rect().width())) columnWidth = 0 mx, my = PLI.margin.x(), PLI.margin.y() x, y = mx, my for item in partList: newHeight = item.rect().height() + my if y + newHeight > self.rect().height(): # Start new column x += columnWidth + (mx * 2) y = my columnWidth = item.rect().width() if x + item.rect().width() > self.rect().width(): # This item overflowed the right edge of page - abort index = partList.index(item) return partList[index:] item.setPos(x, y) y += newHeight columnWidth = max(columnWidth, item.rect().width()) return [] # All items fit on this page
def addColor(self, colorCode, r = 1.0, g = 1.0, b = 1.0, a = 1.0, name = 'Black'): newColor = None if r is None else LicColor(r, g, b, a, name, colorCode) self.__instructions.colorDict[colorCode] = newColor if (newColor): newColor.originalRGBA = list(newColor.rgba) newColor.edgeColor = LicColor.black()
def addColor(self, colorCode, r=1.0, g=1.0, b=1.0, a=1.0, name='Black'): cd = self.__instructions.colorDict cd[colorCode] = None if r is None else LicColor( r, g, b, a, name, colorCode)