def __iadd__(self, translation): if (isinstance(translation, Vector2)): self.__dict__["line"] = (LineUtils().transformLine( self.line, Vector2(translation.x, translation.y), None, None, None)) if (isinstance(translation, Vector3)): self.__dict__["line"] = (LineUtils().transformLine( self.line, Vector2(translation.x, translation.y), None, None, None)) if (isinstance(translation, Quaternion)): self.__dict__["line"] = (LineUtils().transformLine( self.line, None, translation, None, None)) if (isinstance(translation, rotation)): tx = None if (translation.around): try: tx = translation.around(self) * -1.0 tx = Vector2(tx[0], tx[1]) except: tx = Vector2(-translation.around[0], -translation.around[1]) else: tx = self.bounds().midpoint2().scale(-1) self.__dict__["line"] = (LineUtils().transformLine( self.line, tx, None, Quaternion().set(Vector3(0, 0, 1), translation.angle), Vector2(tx).scale(-1))) if (isinstance(translation, CoordinateFrame)): self.__dict__["line"] = (LineUtils().transformLine3( self.line, translation)) return self
def drawBox(b): rr = rectForBox(b) outputTo, qq, qq2 = mergeGroup.create( b.get("box").get("id"), rr, VisualElement, PlainDraggableComponent, SplineComputingOverride) outputTo.name = b.get("box").get("id") if (mergeGroup.getLastWasNew()): outputTo.python_source_v = "" if (outputTo.where.python_autoExec_v != outputTo): outputTo.python_autoExec_v = "" outputTo.decoration_frame = ArrayList() if (b.get("box").has("varname")): tt = b.get("box").get("varname") text = PLine().moveTo(0, -9) text.containsText = 1 text.text_v = tt text.font_v = Font("Gill Sans", 2, 10) text.derived = 1 text.alignment_v = -1 text(offsetFromSource=Vector2(1, 0)) text(color=Vector4(0.25, 0, 0, 1)) outputTo.decoration_frame.add(text) hasVarName = 1 outputTo.maxBox = tt outputTo.needsMax = True else: hasVarName = 0 outputTo.setFrame(rr) pp = PLine().roundRect(Rect(0, 0, rr.w, rr.h), radius=15)(offsetFromSource=Vector2(0, 0)) outputTo.noFrame = 1 pp(derived=1, filled=1, color=Vector4([0, 0.25][hasVarName], 0, 0, 0.2)) outputTo.decoration_frame.add(pp) pp = PLine().roundRect(Rect(0, 0, rr.w, rr.h), radius=15)(offsetFromSource=Vector2(0, 0)) outputTo.noFrame = 1 pp(derived=1, filled=0, color=Vector4(0, 0, 0, 0.5), onSourceSelectedOnly=1) outputTo.decoration_frame.add(pp) if (b.get("box").has("text")): tt = b.get("box").get("text") text = PLine().moveTo(5, -3) text.containsText = 1 text.text_v = tt text.font_v = Font("Gill Sans", 0, 12) text.derived = 1 text(offsetFromSource=Vector2(0, 0.5)) outputTo.decoration_frame.add(text)
def polarCubicTo(self, a1, len1, a2, len2, x2, y2): if (self.__dict__["line"].events.size() == 0 or self.__dict__["reset"] == 1): self.moveTo(x, y) self.__dict__["reset"] = 0 return self was = self.__dict__["line"].events[self.__dict__["line"].events.size() - 1].getDestination(None) d1 = Vector2(x2 - was.x, y2 - was.y).scale(len1 / 3.0).rotateBy(a1) d2 = Vector2(x2 - was.x, y2 - was.y).scale(-len2 / 3.0).rotateBy(a2) self.cubicTo(d1.x + was.x, d1.y + was.y, x2 + d2.x, y2 + d2.y, x2, y2) return self
def saveCroppedPNG(filename, rect): """ Saves a png file (cropped by 'rect') from Field's canvas""" _self = getSelf() x = Vector2(rect.x, rect.y) _self.enclosingFrame.transformDrawingToWindow(x) y = Vector2(rect.x + rect.w, rect.y + rect.h) _self.enclosingFrame.transformDrawingToWindow(y) _self.enclosingFrame.saveWindowAsPNGCropped( "/var/tmp/window.png", int(x.x), _self.enclosingFrame.frame.height - int(y.y), int(y.x - x.x), int(y.y - x.y))
def polarCubicTo(self, a1, len1, a2, len2, x2, y2): """Draws a curve segment to x2,y2 that curves relative to the straight line. a1 and a2 control the angle of the curve (measured clockwise from the striaght line; len1, and len2 control the length of the tangent (a1=0,len1=1,a2=0,len2=1 yields a straight even line). Only works (and only makes sense) in 2d. """ was = self.position d1 = Vector2(x2-was.x, y2-was.y).scale(len1/3.0).rotateBy(a1) d2 = Vector2(x2-was.x, y2-was.y).scale(-len2/3.0).rotateBy(a2) self.cubicTo(d1.x+was.x, d1.y+was.y, x2+d2.x, y2+d2.y, x2, y2) return self
def setControl2(self, *p): """Sets the control2 of this (cubic) node""" if (len(p)==2): self.setAt(1, Vector2(p[0], p[1])) elif(len(p)==3): self.setAt(1, Vector2(p[0], p[1])) if (len(self.args)==6): if(self.z_v): self.z_v.y = p[2] else: self.z_v = Vector3(p[2], p[2], p[2]) else: self.z_v = p[2] return self
def setPosition(self, *p): """Sets the position of this node""" if (len(p)==2): self.setAt(-1, Vector2(p[0], p[1])) elif(len(p)==3): self.setAt(-1, Vector2(p[0], p[1])) if (len(self.args)==6): if(self.z_v): self.z_v.z = p[2] else: self.z_v = Vector3(p[2], p[2], p[2]) else: self.z_v = p[2] return self
def minima(self, position): """ Find minimal points on line. returns a list of Cursors that are at all the places where this line reaches points that are minima of the distance function between this line and 'position' """ ll = Cursor.cursorsFromMinimalApproach( self.line, Vector2(position[0], position[1])) return [PCursor(x) for x in ll]
def __imul__(self, scaleBy): translation = scaleBy if (isinstance(translation, Vector2)): tx = self.bounds().midpoint2().scale(-1) self.__dict__["line"] = (LineUtils().transformLine( self.line, tx, Vector2(translation.x, translation.y), None, Vector2(tx).scale(-1))) if (isinstance(translation, scale)): if (translation.around): try: tx = translation.around(self) * -1.0 if (len(tx) == 2): tx = Vector3(tx[0], tx[1], self.averageDepth()) else: tx = Vector3(tx[0], tx[1], tx[2]) except: if (len(translation.around) == 2): tx = Vector3(translation.around[0], translation.around[1], self.averageDepth()) else: tx = Vector3(translation.around[0], translation.around[1], translation.around[2]) else: tx = self.bounds().midpoint2().scale(-1) tx = Vector3(tx[0], tx[1], -self.averageDepth()) self.__dict__["line"] = (LineUtils().transformLine3( self.line, tx, Vector3(1, 1, 1) * translation.amount, None, Vector3(-tx[0], -tx[1], -tx[2]))) if (isinstance(translation, Vector3)): tx = self.bounds().midpoint2().scale(-1) tx = Vector3(tx[0], tx[1], -self.averageDepth()) self.__dict__["line"] = (LineUtils().transformLine3( self.line, tx, translation, None, Vector3(tx).scale(-1))) if (isinstance(translation, CoordinateFrame)): self.__dict__["line"] = (LineUtils().transformLine3( self.line, translation)) return self
def __imul__(self, scaleBy): """ Scale this line. This method scales (in place) this line. The parameter 'scale' can be a Vector2 (or a Vector3) in which case this specifies a non-uniform scale around the midpoint of the bounding box of this line. The parameter 'scale' can also be a scale object, which gives an opportunity to specify a center. For example thisLine *= scale(Vector2(0.5, 0.5), around = centerFunction) scales this line by half around a center (a Vector2) given by the function 'centerFunction(line)' """ translation = scaleBy if (isinstance(translation, Vector2)): tx = self.bounds().midpoint2().scale(-1) self.__dict__["line"] = (LineUtils().transformLine( self.line, tx, Vector2(translation.x, translation.y), None, Vector2(tx).scale(-1))) if (isinstance(translation, scale)): if (translation.around): try: tx = translation.around(self) * -1.0 tx = Vector2(tx[0], tx[1]) except: tx = Vector2(-translation.around[0], -translation.around[1]) else: tx = self.bounds().midpoint2().scale(-1) self.__dict__["line"] = (LineUtils().transformLine( self.line, Vector2(tx[0], tx[1]), Vector2(1, 1) * translation.amount, None, Vector2(-tx[0], -tx[1]))) if (isinstance(translation, Vector3)): tx = self.bounds().midpoint2().scale(-1) self.__dict__["line"] = (LineUtils().transformLine( self.line, tx, Vector2(translation.x, translation.y), None, Vector2(tx).scale(-1))) if (isinstance(translation, CoordinateFrame)): self.__dict__["line"] = (LineUtils().transformLine3( self.line, translation)) return self
def __imul__(self, translation): if (isinstance(translation, Vector2)): tx = self.bounds2().midpoint2().scale(-1) f = (LineUtils().transformLine(self, tx, Vector2(translation.x, translation.y), None, Vector2(tx).scale(-1))) f.remapProperties(self) self.replaceContents(f) elif (isinstance(translation, Vector3)): tx = self.bounds() tx = (tx[0]+tx[1])*-0.5 f = (LineUtils().transformLine3(self, tx, translation, None, tx*-1.0)) f.remapProperties(self) self.replaceContents(f) elif (isinstance(translation, Quaternion)): f = (LineUtils().transformLine3(self, None, translation, None, None)) f.remapProperties(self) self.replaceContents(f) elif (isinstance(translation, CoordinateFrame)): f = (LineUtils().transformLine3(self, translation)); f.remapProperties(self) self.replaceContents(f) return self
def circleTo(self, x1, y1, x2, y2, overShoot=0, limit=500): """Appends an arc segment""" LineUtils.circleTo(self.__dict__["line"], Vector2(x1, y1), Vector2(x2, y2), limit, overShoot) return self
def arcThrough(self, p1x, p1y, p2x, p2y): """Adds a segment from the current position to p2x, p2y by drawing part of a circle. The circle is given by the circle that would pass through the current position, p1 and p2""" c = Circumcenter().circumcenterOf(arced.nodes[-1].position2(), Vector2(p1x, p1y), Vector2(p2x, p2y)) return self.arcTo(c.x, c.y, p2x, p2y)