def scaleGhost(self,x,y,z,rel): delta = Vector(x,y,z) if rel: delta = FreeCAD.DraftWorkingPlane.getGlobalCoords(delta) self.ghost.scale(delta) # calculate a correction factor depending on the scaling center corr = Vector(self.node[0].x,self.node[0].y,self.node[0].z) corr.scale(delta.x,delta.y,delta.z) corr = (corr.sub(self.node[0])).negative() self.ghost.move(corr) self.ghost.on()
def scale(shape, delta=Vector(1, 1, 1), center=Vector(0, 0, 0), copy=True): if copy: sh = shape.copy() else: sh = shape if delta == Vector(1, 1, 1): return sh #if len(obj.Shape.Solids) > 0: # sh.Placement.Base = Vector(0,0,0) # sh.Placement.Rotation.Angle = -obj.Placement.Rotation.Angle # delta = sh.Placement.Rotation.multVec(delta) # sh.Placement.Rotation.Angle = 0 m = FreeCAD.Matrix() m.scale(delta) sh = sh.transformGeometry(m) corr = Vector(center.x, center.y, center.z) corr.scale(delta.x, delta.y, delta.z) corr = (corr.sub(center)).negative() sh.translate(corr) sh.Placement = shape.Placement return sh
def makeRibs(self, obj): pl = obj.Placement ribs = [] curvebox = FreeCAD.BoundBox(float("-inf"), float("-inf"), float("-inf"), float("inf"), float("inf"), float("inf")) for n in range(0, len(obj.Hullcurves)): cbbx = obj.Hullcurves[n].Shape.BoundBox if self.doScaleXYZ[n][0]: if cbbx.XMin > curvebox.XMin: curvebox.XMin = cbbx.XMin if cbbx.XMax < curvebox.XMax: curvebox.XMax = cbbx.XMax if self.doScaleXYZ[n][1]: if cbbx.YMin > curvebox.YMin: curvebox.YMin = cbbx.YMin if cbbx.YMax < curvebox.YMax: curvebox.YMax = cbbx.YMax if self.doScaleXYZ[n][2]: if cbbx.ZMin > curvebox.ZMin: curvebox.ZMin = cbbx.ZMin if cbbx.ZMax < curvebox.ZMax: curvebox.ZMax = cbbx.ZMax if curvebox.XMin == float("-inf"): curvebox.XMin = obj.Hullcurves[0].Shape.BoundBox.XMin if curvebox.XMax == float("inf"): curvebox.XMax = obj.Hullcurves[0].Shape.BoundBox.XMax if curvebox.YMin == float("-inf"): curvebox.YMin = obj.Hullcurves[0].Shape.BoundBox.YMin if curvebox.YMax == float("inf"): curvebox.YMax = obj.Hullcurves[0].Shape.BoundBox.YMax if curvebox.ZMin == float("-inf"): curvebox.ZMin = obj.Hullcurves[0].Shape.BoundBox.ZMin if curvebox.ZMax == float("inf"): curvebox.ZMax = obj.Hullcurves[0].Shape.BoundBox.ZMax areavec = Vector(curvebox.XLength, curvebox.YLength, curvebox.ZLength) deltavec = areavec.scale( obj.Axis.x, obj.Axis.y, obj.Axis.z) - (obj.OffsetStart + obj.OffsetEnd) * obj.Axis sections = int(obj.Items) startvec = Vector(curvebox.XMin, curvebox.YMin, curvebox.ZMin) if obj.Axis.x < 0: startvec.x = curvebox.XMax if obj.Axis.y < 0: startvec.y = curvebox.YMax if obj.Axis.z < 0: startvec.z = curvebox.ZMax pos0 = startvec + (obj.OffsetStart * obj.Axis) if (not hasattr(obj, "Positions") or len(obj.Positions) == 0): for x in range(0, sections): if sections > 1: d = CurvedShapes.distribute(x / (sections - 1), obj.Distribution, obj.DistributionReverse) posvec = pos0 + (deltavec * d) else: posvec = pos0 dolly = self.makeRib(obj, posvec) if dolly: if not obj.Twist == 0: dolly.rotate( dolly.BoundBox.Center, obj.Axis, obj.Twist * posvec.Length / areavec.Length) ribs.append(dolly) else: for p in obj.Positions: posvec = pos0 + (deltavec * p) dolly = self.makeRib(obj, posvec) if dolly: if not obj.Twist == 0: dolly.rotate( dolly.BoundBox.Center, obj.Axis, obj.Twist * posvec.Length / areavec.Length) ribs.append(dolly) if (obj.Surface or obj.Solid) and obj.Items > 1: obj.Shape = CurvedShapes.makeSurfaceSolid(ribs, obj.Solid) else: obj.Shape = Part.makeCompound(ribs) obj.Placement = pl if self.extract: CompoundTools.Explode.explodeCompound(obj) obj.ViewObject.hide()
def scale(objectslist,delta=Vector(1,1,1),center=Vector(0,0,0),copy=False,legacy=False): '''scale(objects,vector,[center,copy,legacy]): Scales the objects contained in objects (that can be a list of objects or an object) of the given scale factors defined by the given vector (in X, Y and Z directions) around given center. If legacy is True, direct (old) mode is used, otherwise a parametric copy is made. If copy is True, the actual objects are not moved, but copies are created instead. The objects (or their copies) are returned.''' if not isinstance(objectslist,list): objectslist = [objectslist] if legacy: newobjlist = [] for obj in objectslist: if copy: newobj = makeCopy(obj) else: newobj = obj if obj.isDerivedFrom("Part::Feature"): sh = obj.Shape.copy() m = FreeCAD.Matrix() m.scale(delta) sh = sh.transformGeometry(m) corr = Vector(center.x,center.y,center.z) corr.scale(delta.x,delta.y,delta.z) corr = (corr.sub(center)).negative() sh.translate(corr) if getType(obj) == "Rectangle": p = [] for v in sh.Vertexes: p.append(v.Point) pl = obj.Placement.copy() pl.Base = p[0] diag = p[2].sub(p[0]) bb = p[1].sub(p[0]) bh = p[3].sub(p[0]) nb = DraftVecUtils.project(diag,bb) nh = DraftVecUtils.project(diag,bh) if obj.Length < 0: l = -nb.Length else: l = nb.Length if obj.Height < 0: h = -nh.Length else: h = nh.Length newobj.Length = l newobj.Height = h tr = p[0].sub(obj.Shape.Vertexes[0].Point) newobj.Placement = pl elif getType(obj) == "Wire": p = [] for v in sh.Vertexes: p.append(v.Point) #print(p) newobj.Points = p elif getType(obj) == "BSpline": p = [] for p1 in obj.Points: p2 = p1.sub(center) p2.scale(delta.x,delta.y,delta.z) p.append(p2) newobj.Points = p elif (obj.isDerivedFrom("Part::Feature")): newobj.Shape = sh elif (obj.TypeId == "App::Annotation"): factor = delta.y * obj.ViewObject.FontSize newobj.ViewObject.FontSize = factor d = obj.Position.sub(center) newobj.Position = center.add(Vector(d.x*delta.x,d.y*delta.y,d.z*delta.z)) if copy: formatObject(newobj,obj) newobjlist.append(newobj) if copy and getParam("selectBaseObjects",False): select(objectslist) else: select(newobjlist) if len(newobjlist) == 1: return newobjlist[0] return newobjlist else: obj = FreeCAD.ActiveDocument.addObject("Part::FeaturePython","Scale") _Clone(obj) obj.Objects = objectslist obj.Scale = delta corr = Vector(center.x,center.y,center.z) corr.scale(delta.x,delta.y,delta.z) corr = (corr.sub(center)).negative() p = obj.Placement p.move(corr) obj.Placement = p if not copy: for o in objectslist: o.ViewObject.hide() if gui: _ViewProviderClone(obj.ViewObject) formatObject(obj,objectslist[-1]) select(obj) return obj