def nudgePressed(self, direction): unitType = self.currentGridUnitCombo.itemData( self.currentGridUnitCombo.currentIndex()).toInt()[0] offsetx = 0.0 offsety = 0.0 nudgeValue = self.currentNudgeValueSpinBox.value() if direction == self.DIRECTION_UP: offsety = nudgeValue elif direction == self.DIRECTION_DOWN: offsety = -nudgeValue elif direction == self.DIRECTION_RIGHT: offsetx = nudgeValue elif direction == self.DIRECTION_LEFT: offsetx = -nudgeValue script = "" for selectedItem in self.selected: itemx = Eaglepy.eagleToConfigured(selectedItem.x(), unitType) + offsetx itemy = Eaglepy.eagleToConfigured(selectedItem.y(), unitType) + offsety ## Quick Hack to considerable speed this up on multiple calls.. ideally should be a batching option on the server.. selectedItem.x.__dict__["cachedValue"] = Eaglepy.configuredToEagle( itemx, unitType) selectedItem.y.__dict__["cachedValue"] = Eaglepy.configuredToEagle( itemy, unitType) script += "MOVE " + selectedItem.name() + " (%f %f);" % (itemx, itemy) Eaglepy.executescr(script)
def nudgePressed(self, direction): unitType = self.currentGridUnitCombo.itemData(self.currentGridUnitCombo.currentIndex()).toInt()[0] offsetx = 0.0 offsety = 0.0 nudgeValue = self.currentNudgeValueSpinBox.value() if direction == self.DIRECTION_UP: offsety = nudgeValue elif direction == self.DIRECTION_DOWN: offsety = -nudgeValue elif direction == self.DIRECTION_RIGHT: offsetx = nudgeValue elif direction == self.DIRECTION_LEFT: offsetx = -nudgeValue script = "" for selectedItem in self.selected: itemx = Eaglepy.eagleToConfigured(selectedItem.x(), unitType) + offsetx itemy = Eaglepy.eagleToConfigured(selectedItem.y(), unitType) + offsety ## Quick Hack to considerable speed this up on multiple calls.. ideally should be a batching option on the server.. selectedItem.x.__dict__["cachedValue"] = Eaglepy.configuredToEagle(itemx, unitType) selectedItem.y.__dict__["cachedValue"] = Eaglepy.configuredToEagle(itemy, unitType) script += "MOVE " + selectedItem.name() + " (%f %f);" % (itemx, itemy) Eaglepy.executescr(script)
def alignPressed(self, direction): unitType = self.currentGridUnitCombo.itemData( self.currentGridUnitCombo.currentIndex()).toInt()[0] minx = sys.float_info.max maxx = -sys.float_info.max miny = sys.float_info.max maxy = -sys.float_info.max for selectedItem in self.selected: itemx = Eaglepy.eagleToConfigured( selectedItem.x(Eaglepy.REFRESH_VALUE), unitType) if direction in [ self.DIRECTION_LEFT, self.DIRECTION_RIGHT, self.DIRECTION_CENTER_V ] else 0 itemy = Eaglepy.eagleToConfigured( selectedItem.y(Eaglepy.REFRESH_VALUE), unitType) if direction in [ self.DIRECTION_TOP, self.DIRECTION_BOTTOM, self.DIRECTION_CENTER_H ] else 0 minx = itemx if itemx < minx else minx maxx = itemx if itemx > maxx else maxx miny = itemy if itemy < miny else miny maxy = itemy if itemy > maxy else maxy centerx = minx + ((maxx - minx) / 2) centery = miny + ((maxy - miny) / 2) script = "" for selectedItem in self.selected: itemx = Eaglepy.eagleToConfigured( selectedItem.x(Eaglepy.REFRESH_VALUE), unitType) itemy = Eaglepy.eagleToConfigured( selectedItem.y(Eaglepy.REFRESH_VALUE), unitType) if direction == self.DIRECTION_LEFT: script += ("MOVE %s" % selectedItem.name()) + (" (%f %f);" % (minx, itemy)) selectedItem.x.__dict__[ "cachedValue"] = Eaglepy.configuredToEagle(minx, unitType) selectedItem.y.__dict__[ "cachedValue"] = Eaglepy.configuredToEagle( itemy, unitType) elif direction == self.DIRECTION_RIGHT: script += ("MOVE %s" % selectedItem.name()) + (" (%f %f);" % (maxx, itemy)) selectedItem.x.__dict__[ "cachedValue"] = Eaglepy.configuredToEagle(maxx, unitType) selectedItem.y.__dict__[ "cachedValue"] = Eaglepy.configuredToEagle( itemy, unitType) elif direction == self.DIRECTION_CENTER_V: script += ("MOVE %s" % selectedItem.name()) + (" (%f %f);" % (centerx, itemy)) selectedItem.x.__dict__[ "cachedValue"] = Eaglepy.configuredToEagle( centerx, unitType) selectedItem.y.__dict__[ "cachedValue"] = Eaglepy.configuredToEagle( itemy, unitType) elif direction == self.DIRECTION_TOP: script += ("MOVE %s" % selectedItem.name()) + (" (%f %f);" % (itemx, maxy)) selectedItem.x.__dict__[ "cachedValue"] = Eaglepy.configuredToEagle( itemx, unitType) selectedItem.y.__dict__[ "cachedValue"] = Eaglepy.configuredToEagle(maxy, unitType) elif direction == self.DIRECTION_BOTTOM: script += ("MOVE %s" % selectedItem.name()) + (" (%f %f);" % (itemx, miny)) selectedItem.x.__dict__[ "cachedValue"] = Eaglepy.configuredToEagle( itemx, unitType) selectedItem.y.__dict__[ "cachedValue"] = Eaglepy.configuredToEagle(miny, unitType) elif direction == self.DIRECTION_CENTER_H: script += ("MOVE %s" % selectedItem.name()) + (" (%f %f);" % (itemx, centery)) selectedItem.x.__dict__[ "cachedValue"] = Eaglepy.configuredToEagle( itemx, unitType) selectedItem.y.__dict__[ "cachedValue"] = Eaglepy.configuredToEagle( centery, unitType) Eaglepy.executescr(script)
def distributePressed(self, direction): if not self.checkSelected(): return if self.distributeModeValues.isChecked()and (self.distributeValuesHorizontalMinSpinBox.value() >= self.distributeValuesHorizontalMaxSpinBox.value() or \ self.distributeValuesVerticalMinSpinBox.value() >= self.distributeValuesVerticalMaxSpinBox.value()): messageBox = QMessageBox( QMessageBox.Warning, "Invalid Min/Max values", "Minimum values must be less than maximum values for grid distribution", QMessageBox.Ok, self) messageBox.exec_() return unitType = self.currentGridUnitCombo.itemData( self.currentGridUnitCombo.currentIndex()).toInt()[0] distributeValueMode = self.DISTRIBUTE_MINMAX if self.distributeModeMinMax.isChecked( ) else self.DISTRIBUTE_VALUES minx = sys.float_info.max if distributeValueMode == self.DISTRIBUTE_MINMAX else self.distributeValuesHorizontalMinSpinBox.value( ) maxx = -sys.float_info.max if distributeValueMode == self.DISTRIBUTE_MINMAX else self.distributeValuesHorizontalMaxSpinBox.value( ) miny = sys.float_info.max if distributeValueMode == self.DISTRIBUTE_MINMAX else self.distributeValuesVerticalMinSpinBox.value( ) maxy = -sys.float_info.max if distributeValueMode == self.DISTRIBUTE_MINMAX else self.distributeValuesVerticalMaxSpinBox.value( ) spacingx = 0 spacingy = 0 itemPositions = [] for index, selectedItem in enumerate(self.selected): itemx = Eaglepy.eagleToConfigured( selectedItem.x(Eaglepy.REFRESH_VALUE), unitType) if direction in [ self.DIRECTION_HORIZONTAL, self.DIRECTION_GRID ] else 0 itemy = Eaglepy.eagleToConfigured( selectedItem.y(Eaglepy.REFRESH_VALUE), unitType) if direction in [ self.DIRECTION_VERTICAL, self.DIRECTION_GRID ] else 0 itemPositions.append(((itemx, itemy), index)) if distributeValueMode == self.DISTRIBUTE_MINMAX: minx = itemx if itemx < minx else minx maxx = itemx if itemx > maxx else maxx miny = itemy if itemy < miny else miny maxy = itemy if itemy > maxy else maxy if direction in [self.DIRECTION_HORIZONTAL, self.DIRECTION_VERTICAL]: if direction == self.DIRECTION_HORIZONTAL: spacingx = abs((float(maxx) - float(minx)) / (len(self.selected) - 1)) if self.DIRECTION_HORIZONTAL else 0 sortedSelected = sorted(self.selected, key=lambda selected: selected.x()) elif direction == self.DIRECTION_VERTICAL: spacingy = abs( (float(maxy) - float(miny)) / (len(self.selected) - 1)) if self.DIRECTION_VERTICAL else 0 sortedSelected = sorted(self.selected, key=lambda selected: selected.y()) script = "" currentspacingx = 0 currentspacingy = 0 for selectedItem in sortedSelected: itemx = Eaglepy.eagleToConfigured( selectedItem.x(Eaglepy.REFRESH_VALUE), unitType) itemy = Eaglepy.eagleToConfigured( selectedItem.y(Eaglepy.REFRESH_VALUE), unitType) if direction == self.DIRECTION_HORIZONTAL: script += ("MOVE %s" % selectedItem.name()) + ( " (%f %f);" % (minx + currentspacingx, itemy)) selectedItem.x.__dict__[ "cachedValue"] = Eaglepy.configuredToEagle( minx + currentspacingx, unitType) selectedItem.y.__dict__[ "cachedValue"] = Eaglepy.configuredToEagle( itemy, unitType) elif direction == self.DIRECTION_VERTICAL: script += ("MOVE %s" % selectedItem.name()) + ( " (%f %f);" % (itemx, miny + currentspacingy)) selectedItem.x.__dict__[ "cachedValue"] = Eaglepy.configuredToEagle( itemx, unitType) selectedItem.y.__dict__[ "cachedValue"] = Eaglepy.configuredToEagle( miny + currentspacingy, unitType) currentspacingx += spacingx currentspacingy += spacingy elif direction == self.DIRECTION_GRID: rows = self.distributeGridRowsSpinBox.value() columns = self.distributeGridColsSpinBox.value() spacingx = abs((float(maxx) - float(minx)) / (rows - 1)) spacingy = abs((float(maxy) - float(miny)) / (columns - 1)) if rows * columns < len(self.selected): messageBox = QMessageBox( QMessageBox.Warning, "Too many items selected", "%d items exceeds the maximum for the current grid size.\nFor %d rows * %d columns the maximum number of selected items is %d" % (len(self.selected), rows, columns, rows * columns), QMessageBox.Ok, self) return messageBox.exec_() distance = lambda p1, p2: abs( math.sqrt( math.pow(p2[0] - p1[0], 2) + math.pow(p2[1] - p1[1], 2))) script = "" complete = False for rowIndex in range(rows): for colIndex in range(columns): if (rowIndex * columns) + colIndex == len(self.selected): complete = True break newx = minx + rowIndex * spacingx newy = miny + colIndex * spacingy closestItem = min( itemPositions, key=lambda item: distance(item[0], (newx, newy))) itemPositions.remove(closestItem) script += ("MOVE %s" % self.selected[closestItem[1]].name()) + ( " (%f %f);" % (newx, newy)) self.selected[closestItem[1]].x.__dict__[ "cachedValue"] = Eaglepy.configuredToEagle( newx, unitType) self.selected[closestItem[1]].y.__dict__[ "cachedValue"] = Eaglepy.configuredToEagle( newy, unitType) if complete: break Eaglepy.executescr(script)
def alignPressed(self, direction): unitType = self.currentGridUnitCombo.itemData(self.currentGridUnitCombo.currentIndex()).toInt()[0] minx = sys.float_info.max maxx = -sys.float_info.max miny = sys.float_info.max maxy = -sys.float_info.max for selectedItem in self.selected: itemx = ( Eaglepy.eagleToConfigured(selectedItem.x(Eaglepy.REFRESH_VALUE), unitType) if direction in [self.DIRECTION_LEFT, self.DIRECTION_RIGHT, self.DIRECTION_CENTER_V] else 0 ) itemy = ( Eaglepy.eagleToConfigured(selectedItem.y(Eaglepy.REFRESH_VALUE), unitType) if direction in [self.DIRECTION_TOP, self.DIRECTION_BOTTOM, self.DIRECTION_CENTER_H] else 0 ) minx = itemx if itemx < minx else minx maxx = itemx if itemx > maxx else maxx miny = itemy if itemy < miny else miny maxy = itemy if itemy > maxy else maxy centerx = minx + ((maxx - minx) / 2) centery = miny + ((maxy - miny) / 2) script = "" for selectedItem in self.selected: itemx = Eaglepy.eagleToConfigured(selectedItem.x(Eaglepy.REFRESH_VALUE), unitType) itemy = Eaglepy.eagleToConfigured(selectedItem.y(Eaglepy.REFRESH_VALUE), unitType) if direction == self.DIRECTION_LEFT: script += ("MOVE %s" % selectedItem.name()) + (" (%f %f);" % (minx, itemy)) selectedItem.x.__dict__["cachedValue"] = Eaglepy.configuredToEagle(minx, unitType) selectedItem.y.__dict__["cachedValue"] = Eaglepy.configuredToEagle(itemy, unitType) elif direction == self.DIRECTION_RIGHT: script += ("MOVE %s" % selectedItem.name()) + (" (%f %f);" % (maxx, itemy)) selectedItem.x.__dict__["cachedValue"] = Eaglepy.configuredToEagle(maxx, unitType) selectedItem.y.__dict__["cachedValue"] = Eaglepy.configuredToEagle(itemy, unitType) elif direction == self.DIRECTION_CENTER_V: script += ("MOVE %s" % selectedItem.name()) + (" (%f %f);" % (centerx, itemy)) selectedItem.x.__dict__["cachedValue"] = Eaglepy.configuredToEagle(centerx, unitType) selectedItem.y.__dict__["cachedValue"] = Eaglepy.configuredToEagle(itemy, unitType) elif direction == self.DIRECTION_TOP: script += ("MOVE %s" % selectedItem.name()) + (" (%f %f);" % (itemx, maxy)) selectedItem.x.__dict__["cachedValue"] = Eaglepy.configuredToEagle(itemx, unitType) selectedItem.y.__dict__["cachedValue"] = Eaglepy.configuredToEagle(maxy, unitType) elif direction == self.DIRECTION_BOTTOM: script += ("MOVE %s" % selectedItem.name()) + (" (%f %f);" % (itemx, miny)) selectedItem.x.__dict__["cachedValue"] = Eaglepy.configuredToEagle(itemx, unitType) selectedItem.y.__dict__["cachedValue"] = Eaglepy.configuredToEagle(miny, unitType) elif direction == self.DIRECTION_CENTER_H: script += ("MOVE %s" % selectedItem.name()) + (" (%f %f);" % (itemx, centery)) selectedItem.x.__dict__["cachedValue"] = Eaglepy.configuredToEagle(itemx, unitType) selectedItem.y.__dict__["cachedValue"] = Eaglepy.configuredToEagle(centery, unitType) Eaglepy.executescr(script)
def distributePressed(self, direction): if not self.checkSelected(): return if self.distributeModeValues.isChecked() and ( self.distributeValuesHorizontalMinSpinBox.value() >= self.distributeValuesHorizontalMaxSpinBox.value() or self.distributeValuesVerticalMinSpinBox.value() >= self.distributeValuesVerticalMaxSpinBox.value() ): messageBox = QMessageBox( QMessageBox.Warning, "Invalid Min/Max values", "Minimum values must be less than maximum values for grid distribution", QMessageBox.Ok, self, ) messageBox.exec_() return unitType = self.currentGridUnitCombo.itemData(self.currentGridUnitCombo.currentIndex()).toInt()[0] distributeValueMode = ( self.DISTRIBUTE_MINMAX if self.distributeModeMinMax.isChecked() else self.DISTRIBUTE_VALUES ) minx = ( sys.float_info.max if distributeValueMode == self.DISTRIBUTE_MINMAX else self.distributeValuesHorizontalMinSpinBox.value() ) maxx = ( -sys.float_info.max if distributeValueMode == self.DISTRIBUTE_MINMAX else self.distributeValuesHorizontalMaxSpinBox.value() ) miny = ( sys.float_info.max if distributeValueMode == self.DISTRIBUTE_MINMAX else self.distributeValuesVerticalMinSpinBox.value() ) maxy = ( -sys.float_info.max if distributeValueMode == self.DISTRIBUTE_MINMAX else self.distributeValuesVerticalMaxSpinBox.value() ) spacingx = 0 spacingy = 0 itemPositions = [] for index, selectedItem in enumerate(self.selected): itemx = ( Eaglepy.eagleToConfigured(selectedItem.x(Eaglepy.REFRESH_VALUE), unitType) if direction in [self.DIRECTION_HORIZONTAL, self.DIRECTION_GRID] else 0 ) itemy = ( Eaglepy.eagleToConfigured(selectedItem.y(Eaglepy.REFRESH_VALUE), unitType) if direction in [self.DIRECTION_VERTICAL, self.DIRECTION_GRID] else 0 ) itemPositions.append(((itemx, itemy), index)) if distributeValueMode == self.DISTRIBUTE_MINMAX: minx = itemx if itemx < minx else minx maxx = itemx if itemx > maxx else maxx miny = itemy if itemy < miny else miny maxy = itemy if itemy > maxy else maxy if direction in [self.DIRECTION_HORIZONTAL, self.DIRECTION_VERTICAL]: if direction == self.DIRECTION_HORIZONTAL: spacingx = ( abs((float(maxx) - float(minx)) / (len(self.selected) - 1)) if self.DIRECTION_HORIZONTAL else 0 ) sortedSelected = sorted(self.selected, key=lambda selected: selected.x()) elif direction == self.DIRECTION_VERTICAL: spacingy = abs((float(maxy) - float(miny)) / (len(self.selected) - 1)) if self.DIRECTION_VERTICAL else 0 sortedSelected = sorted(self.selected, key=lambda selected: selected.y()) script = "" currentspacingx = 0 currentspacingy = 0 for selectedItem in sortedSelected: itemx = Eaglepy.eagleToConfigured(selectedItem.x(Eaglepy.REFRESH_VALUE), unitType) itemy = Eaglepy.eagleToConfigured(selectedItem.y(Eaglepy.REFRESH_VALUE), unitType) if direction == self.DIRECTION_HORIZONTAL: script += ("MOVE %s" % selectedItem.name()) + (" (%f %f);" % (minx + currentspacingx, itemy)) selectedItem.x.__dict__["cachedValue"] = Eaglepy.configuredToEagle(minx + currentspacingx, unitType) selectedItem.y.__dict__["cachedValue"] = Eaglepy.configuredToEagle(itemy, unitType) elif direction == self.DIRECTION_VERTICAL: script += ("MOVE %s" % selectedItem.name()) + (" (%f %f);" % (itemx, miny + currentspacingy)) selectedItem.x.__dict__["cachedValue"] = Eaglepy.configuredToEagle(itemx, unitType) selectedItem.y.__dict__["cachedValue"] = Eaglepy.configuredToEagle(miny + currentspacingy, unitType) currentspacingx += spacingx currentspacingy += spacingy elif direction == self.DIRECTION_GRID: rows = self.distributeGridRowsSpinBox.value() columns = self.distributeGridColsSpinBox.value() spacingx = abs((float(maxx) - float(minx)) / (rows - 1)) spacingy = abs((float(maxy) - float(miny)) / (columns - 1)) if rows * columns < len(self.selected): messageBox = QMessageBox( QMessageBox.Warning, "Too many items selected", "%d items exceeds the maximum for the current grid size.\nFor %d rows * %d columns the maximum number of selected items is %d" % (len(self.selected), rows, columns, rows * columns), QMessageBox.Ok, self, ) return messageBox.exec_() distance = lambda p1, p2: abs(math.sqrt(math.pow(p2[0] - p1[0], 2) + math.pow(p2[1] - p1[1], 2))) script = "" complete = False for rowIndex in range(rows): for colIndex in range(columns): if (rowIndex * columns) + colIndex == len(self.selected): complete = True break newx = minx + rowIndex * spacingx newy = miny + colIndex * spacingy closestItem = min(itemPositions, key=lambda item: distance(item[0], (newx, newy))) itemPositions.remove(closestItem) script += ("MOVE %s" % self.selected[closestItem[1]].name()) + (" (%f %f);" % (newx, newy)) self.selected[closestItem[1]].x.__dict__["cachedValue"] = Eaglepy.configuredToEagle(newx, unitType) self.selected[closestItem[1]].y.__dict__["cachedValue"] = Eaglepy.configuredToEagle(newy, unitType) if complete: break Eaglepy.executescr(script)