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)
def polarArray(self,shape,center,angle,num,axis):
print "angle ",angle," num ",num
import Part
fraction = angle/num
if angle == 360:
fraction = angle/num
else:
if num == 0:
return shape
fraction = angle/(num-1)
base = [shape.copy()]
for i in range(num):
for i in range(num-1):
currangle = fraction + (i*fraction)
nshape = shape.copy()
nshape.rotate(DraftVecUtils.tup(center), DraftVecUtils.tup(axis), currangle)

View File

@ -2176,6 +2176,7 @@ class Upgrade(Modifier):
groups = []
curves = []
facewires = []
loneedges = 0
# determining what we have in our selection
for ob in self.sel:
@ -2186,11 +2187,15 @@ class Upgrade(Modifier):
for f in ob.Shape.Faces:
faces.append(f)
facewires.extend(f.Wires)
wedges = 0
for w in ob.Shape.Wires:
wedges += len(w.Edges)
if w.isClosed():
wires.append(w)
else:
openwires.append(w)
if wedges < len(ob.Shape.Edges):
loneedges += (len(ob.Shape.Edges)-wedges)
for e in ob.Shape.Edges:
if not isinstance(e.Curve,Part.Line):
curves.append(e)
@ -2311,34 +2316,44 @@ class Upgrade(Modifier):
Draft.formatObject(newob,lastob)
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!"
p0 = openwires[0].Vertexes[0].Point
p1 = openwires[0].Vertexes[-1].Point
edges = openwires[0].Edges
if len(edges) > 1:
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)
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:
msg(translate("draft", "Found 1 open wire: closing it\n"))
if not curves:
newob = Draft.makeWire(w,closed=True)
edges = openwires[0].Edges
if len(edges) > 1:
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:
# if not possible, we do a non-parametric union
newob = self.doc.addObject("Part::Feature","Wire")
newob.Shape = w
Draft.formatObject(newob,lastob)
msg(translate("draft", "Found 1 open wire: closing it\n"))
if not curves:
newob = Draft.makeWire(w,closed=True)
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):
# only open wires and edges: we try to join their edges
@ -2347,23 +2362,38 @@ class Upgrade(Modifier):
edges.append(e)
newob = None
nedges = DraftGeomUtils.sortEdges(edges[:])
# for e in nedges: print "debug: ",e.Curve,e.Vertexes[0].Point,e.Vertexes[-1].Point
w = Part.Wire(nedges)
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)
#for e in nedges: print "debug: ",e.Curve,e.Vertexes[0].Point,e.Vertexes[-1].Point
try:
w = Part.Wire(nedges)
except:
msg(translate("draft", "Error: unable to join edges\n"))
else:
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:
print "no new object found"
msg(translate("draft", "Found several non-connected edges: making compound\n"))
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"))
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()
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:
# deleting original objects, if needed

View File

@ -200,21 +200,35 @@ svgcolors = {
'MediumAquamarine': (102, 205, 170),
'OldLace': (253, 245, 230)
}
svgcolorslower = dict((key.lower(),value) for key,value in \
svgcolors.items())
def getcolor(color):
"checks if the given string is a RGB value, or if it is a named color. returns 1-based RGBA tuple."
if (color[:1] == "#"):
r = float(int(color[1:3],16)/255.0)
g = float(int(color[3:5],16)/255.0)
b = float(int(color[5:],16)/255.0)
return (r,g,b,0.0)
else:
for k,v in svgcolors.iteritems():
if (k.lower() == color.lower()):
r = float(v[0]/255.0)
g = float(v[1]/255.0)
b = float(v[2]/255.0)
return (r,g,b,0.0)
"checks if the given string is a RGB value, or if it is a named color. returns 1-based RGBA tuple."
if (color[0] == "#"):
if len(color) == 7:
r = float(int(color[1:3],16)/255.0)
g = float(int(color[3: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)
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):
"""parses length values containing number and unit