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
if angle == 360:
fraction = angle/num 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,10 +2316,20 @@ 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
if p0 == p1:
# sometimes an open wire can have its start and end points identical (OCC bug)
# in that case, although it is not closed, face works...
f = Part.Face(openwires[0])
msg(translate("draft", "Found a closed wire: making a face\n"))
newob = self.doc.addObject("Part::Feature","Face")
newob.Shape = f
Draft.formatObject(newob,lastob)
newob.ViewObject.DisplayMode = "Flat Lines"
else:
edges = openwires[0].Edges edges = openwires[0].Edges
if len(edges) > 1: if len(edges) > 1:
edges.append(Part.Line(p1,p0).toShape()) edges.append(Part.Line(p1,p0).toShape())
@ -2348,17 +2363,32 @@ class Upgrade(Modifier):
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
try:
w = Part.Wire(nedges) w = Part.Wire(nedges)
except:
msg(translate("draft", "Error: unable to join edges\n"))
else:
if len(w.Edges) == len(edges): if len(w.Edges) == len(edges):
msg(translate("draft", "Found several edges: wiring them\n")) msg(translate("draft", "Found several edges: wiring them\n"))
newob = self.doc.addObject("Part::Feature","Wire") newob = self.doc.addObject("Part::Feature","Wire")
newob.Shape = w newob.Shape = w
Draft.formatObject(newob,lastob) 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"):
# 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")) msg(translate("draft", "Found several non-connected edges: making compound\n"))
newob = self.compound() newob = self.compound()
Draft.formatObject(newob,lastob) 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: else:
# all other cases # all other cases
msg(translate("draft", "Found several non-treatable objects: making compound\n")) msg(translate("draft", "Found several non-treatable objects: making compound\n"))

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] == "#"):
if len(color) == 7:
r = float(int(color[1:3],16)/255.0) r = float(int(color[1:3],16)/255.0)
g = float(int(color[3:5],16)/255.0) g = float(int(color[3:5],16)/255.0)
b = float(int(color[5:],16)/255.0) b = float(int(color[5:],16)/255.0)
elif len(color) == 4: #expand the hex digits
r = float(int(color[1],16)*17/255.0)
g = float(int(color[2],16)*17/255.0)
b = float(int(color[3],16)*17/255.0)
return (r,g,b,0.0)
elif color.lower().startswith('rgb('):
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) return (r,g,b,0.0)
else: else:
for k,v in svgcolors.iteritems(): v=svgcolorslower.get(color.lower())
if (k.lower() == color.lower()): if v:
r = float(v[0]/255.0) r,g,b = [float(vf)/255.0 for vf in v]
g = float(v[1]/255.0)
b = float(v[2]/255.0)
return (r,g,b,0.0) 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