Merge branch 'master' of git://free-cad.git.sourceforge.net/gitroot/free-cad/free-cad

This commit is contained in:
jrheinlaender 2013-02-07 10:30:18 +04:30
commit fc55b10829
4 changed files with 106 additions and 52 deletions

View File

@ -0,0 +1,4 @@
[Thumbnailer Entry]
TryExec=freecad-thumbnailer
Exec=freecad-thumbnailer -s %s %u %o
MimeType=application/x-extension-fcstd;

View File

@ -3017,10 +3017,16 @@ class _Array(_DraftObject):
return Part.makeCompound(base) return Part.makeCompound(base)
def polarArray(self,shape,center,angle,num,axis): def polarArray(self,shape,center,angle,num,axis):
print "angle ",angle," num ",num
import Part import Part
fraction = angle/num if angle == 360:
fraction = angle/num
else:
if num == 0:
return shape
fraction = angle/(num-1)
base = [shape.copy()] base = [shape.copy()]
for i in range(num): for i in range(num-1):
currangle = fraction + (i*fraction) currangle = fraction + (i*fraction)
nshape = shape.copy() nshape = shape.copy()
nshape.rotate(DraftVecUtils.tup(center), DraftVecUtils.tup(axis), currangle) nshape.rotate(DraftVecUtils.tup(center), DraftVecUtils.tup(axis), currangle)

View File

@ -2176,6 +2176,7 @@ class Upgrade(Modifier):
groups = [] groups = []
curves = [] curves = []
facewires = [] facewires = []
loneedges = 0
# determining what we have in our selection # determining what we have in our selection
for ob in self.sel: for ob in self.sel:
@ -2186,11 +2187,15 @@ class Upgrade(Modifier):
for f in ob.Shape.Faces: for f in ob.Shape.Faces:
faces.append(f) faces.append(f)
facewires.extend(f.Wires) facewires.extend(f.Wires)
wedges = 0
for w in ob.Shape.Wires: for w in ob.Shape.Wires:
wedges += len(w.Edges)
if w.isClosed(): if w.isClosed():
wires.append(w) wires.append(w)
else: else:
openwires.append(w) openwires.append(w)
if wedges < len(ob.Shape.Edges):
loneedges += (len(ob.Shape.Edges)-wedges)
for e in ob.Shape.Edges: for e in ob.Shape.Edges:
if not isinstance(e.Curve,Part.Line): if not isinstance(e.Curve,Part.Line):
curves.append(e) curves.append(e)
@ -2311,34 +2316,44 @@ class Upgrade(Modifier):
Draft.formatObject(newob,lastob) Draft.formatObject(newob,lastob)
newob.ViewObject.DisplayMode = "Flat Lines" newob.ViewObject.DisplayMode = "Flat Lines"
elif (len(openwires) == 1) and (not faces) and (not wires): elif (len(openwires) == 1) and (not faces) and (not wires) and (not loneedges):
# special case, we have only one open wire. We close it, unless it has only 1 edge!" # special case, we have only one open wire. We close it, unless it has only 1 edge!"
p0 = openwires[0].Vertexes[0].Point p0 = openwires[0].Vertexes[0].Point
p1 = openwires[0].Vertexes[-1].Point p1 = openwires[0].Vertexes[-1].Point
edges = openwires[0].Edges if p0 == p1:
if len(edges) > 1: # sometimes an open wire can have its start and end points identical (OCC bug)
edges.append(Part.Line(p1,p0).toShape()) # in that case, although it is not closed, face works...
w = Part.Wire(DraftGeomUtils.sortEdges(edges)) f = Part.Face(openwires[0])
if len(edges) == 1: msg(translate("draft", "Found a closed wire: making a face\n"))
if len(w.Vertexes) == 2: newob = self.doc.addObject("Part::Feature","Face")
msg(translate("draft", "Found 1 open edge: making a line\n")) newob.Shape = f
newob = Draft.makeWire(w,closed=False) Draft.formatObject(newob,lastob)
elif len(w.Vertexes) == 1: newob.ViewObject.DisplayMode = "Flat Lines"
msg(translate("draft", "Found 1 circular edge: making a circle\n"))
c = w.Edges[0].Curve.Center
r = w.Edges[0].Curve.Radius
p = FreeCAD.Placement()
p.move(c)
newob = Draft.makeCircle(r,p)
else: else:
msg(translate("draft", "Found 1 open wire: closing it\n")) edges = openwires[0].Edges
if not curves: if len(edges) > 1:
newob = Draft.makeWire(w,closed=True) edges.append(Part.Line(p1,p0).toShape())
w = Part.Wire(DraftGeomUtils.sortEdges(edges))
if len(edges) == 1:
if len(w.Vertexes) == 2:
msg(translate("draft", "Found 1 open edge: making a line\n"))
newob = Draft.makeWire(w,closed=False)
elif len(w.Vertexes) == 1:
msg(translate("draft", "Found 1 circular edge: making a circle\n"))
c = w.Edges[0].Curve.Center
r = w.Edges[0].Curve.Radius
p = FreeCAD.Placement()
p.move(c)
newob = Draft.makeCircle(r,p)
else: else:
# if not possible, we do a non-parametric union msg(translate("draft", "Found 1 open wire: closing it\n"))
newob = self.doc.addObject("Part::Feature","Wire") if not curves:
newob.Shape = w newob = Draft.makeWire(w,closed=True)
Draft.formatObject(newob,lastob) else:
# if not possible, we do a non-parametric union
newob = self.doc.addObject("Part::Feature","Wire")
newob.Shape = w
Draft.formatObject(newob,lastob)
elif openwires and (not wires) and (not faces): elif openwires and (not wires) and (not faces):
# only open wires and edges: we try to join their edges # only open wires and edges: we try to join their edges
@ -2347,23 +2362,38 @@ class Upgrade(Modifier):
edges.append(e) edges.append(e)
newob = None newob = None
nedges = DraftGeomUtils.sortEdges(edges[:]) nedges = DraftGeomUtils.sortEdges(edges[:])
# for e in nedges: print "debug: ",e.Curve,e.Vertexes[0].Point,e.Vertexes[-1].Point #for e in nedges: print "debug: ",e.Curve,e.Vertexes[0].Point,e.Vertexes[-1].Point
w = Part.Wire(nedges) try:
if len(w.Edges) == len(edges): w = Part.Wire(nedges)
msg(translate("draft", "Found several edges: wiring them\n")) except:
newob = self.doc.addObject("Part::Feature","Wire") msg(translate("draft", "Error: unable to join edges\n"))
newob.Shape = w else:
Draft.formatObject(newob,lastob) if len(w.Edges) == len(edges):
msg(translate("draft", "Found several edges: wiring them\n"))
newob = self.doc.addObject("Part::Feature","Wire")
newob.Shape = w
Draft.formatObject(newob,lastob)
if not newob: if not newob:
print "no new object found" if (len(self.sel) == 1) and (lastob.Shape.ShapeType == "Compound"):
msg(translate("draft", "Found several non-connected edges: making compound\n")) # the selected object is already a compound
msg(translate("draft", "Unable to upgrade more\n"))
self.nodelete = True
else:
# all other cases
#print "no new object found"
msg(translate("draft", "Found several non-connected edges: making compound\n"))
newob = self.compound()
Draft.formatObject(newob,lastob)
else:
if (len(self.sel) == 1) and (lastob.Shape.ShapeType == "Compound"):
# the selected object is already a compound
msg(translate("draft", "Unable to upgrade more\n"))
self.nodelete = True
else:
# all other cases
msg(translate("draft", "Found several non-treatable objects: making compound\n"))
newob = self.compound() newob = self.compound()
Draft.formatObject(newob,lastob) Draft.formatObject(newob,lastob)
else:
# all other cases
msg(translate("draft", "Found several non-treatable objects: making compound\n"))
newob = self.compound()
Draft.formatObject(newob,lastob)
if not self.nodelete: if not self.nodelete:
# deleting original objects, if needed # deleting original objects, if needed

View File

@ -200,21 +200,35 @@ svgcolors = {
'MediumAquamarine': (102, 205, 170), 'MediumAquamarine': (102, 205, 170),
'OldLace': (253, 245, 230) 'OldLace': (253, 245, 230)
} }
svgcolorslower = dict((key.lower(),value) for key,value in \
svgcolors.items())
def getcolor(color): def getcolor(color):
"checks if the given string is a RGB value, or if it is a named color. returns 1-based RGBA tuple." "checks if the given string is a RGB value, or if it is a named color. returns 1-based RGBA tuple."
if (color[:1] == "#"): if (color[0] == "#"):
r = float(int(color[1:3],16)/255.0) if len(color) == 7:
g = float(int(color[3:5],16)/255.0) r = float(int(color[1:3],16)/255.0)
b = float(int(color[5:],16)/255.0) g = float(int(color[3:5],16)/255.0)
return (r,g,b,0.0) b = float(int(color[5:],16)/255.0)
else: elif len(color) == 4: #expand the hex digits
for k,v in svgcolors.iteritems(): r = float(int(color[1],16)*17/255.0)
if (k.lower() == color.lower()): g = float(int(color[2],16)*17/255.0)
r = float(v[0]/255.0) b = float(int(color[3],16)*17/255.0)
g = float(v[1]/255.0) return (r,g,b,0.0)
b = float(v[2]/255.0) elif color.lower().startswith('rgb('):
return (r,g,b,0.0) cvalues=color[3:].lstrip('(').rstrip(')').replace('%',' ').split(',')
if '%' in color:
r,g,b = [int(cv)/100.0 for cv in cvalues]
else:
r,g,b = [int(cv)/255.0 for cv in cvalues]
return (r,g,b,0.0)
else:
v=svgcolorslower.get(color.lower())
if v:
r,g,b = [float(vf)/255.0 for vf in v]
return (r,g,b,0.0)
#for k,v in svgcolors.iteritems():
# if (k.lower() == color.lower()): pass
def getsize(length,mode='discard',base=1): def getsize(length,mode='discard',base=1):
"""parses length values containing number and unit """parses length values containing number and unit