Skip to content

Commit

Permalink
Merge branch 'master' of ssh://git.code.sf.net/p/free-cad/code
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmayer committed Aug 13, 2014
2 parents 7939027 + a9b5970 commit ed4f7dc
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 33 deletions.
63 changes: 39 additions & 24 deletions src/Mod/Arch/ArchSectionPlane.py
Expand Up @@ -107,7 +107,8 @@ def __init__(self,obj):

def execute(self,obj):
import Part
l = obj.ViewObject.DisplaySize.Value
l = obj.ViewObject.DisplayLength.Value
h = obj.ViewObject.DisplayHeight.Value
p = Part.makePlane(l,l,Vector(l/2,-l/2,0),Vector(0,0,-1))
# make sure the normal direction is pointing outwards, you never know what OCC will decide...
if p.normalAt(0,0).getAngle(obj.Placement.Rotation.multVec(FreeCAD.Vector(0,0,1))) > 1:
Expand All @@ -131,11 +132,15 @@ def __setstate__(self,state):
class _ViewProviderSectionPlane:
"A View Provider for Section Planes"
def __init__(self,vobj):
vobj.addProperty("App::PropertyLength","DisplaySize","Arch",translate("Arch","The display size of this section plane"))
vobj.addProperty("App::PropertyLength","DisplayLength","Arch",translate("Arch","The display length of this section plane"))
vobj.addProperty("App::PropertyLength","DisplayHeight","Arch",translate("Arch","The display height of this section plane"))
vobj.addProperty("App::PropertyLength","ArrowSize","Arch",translate("Arch","The size of the arrows of this section plane"))
vobj.addProperty("App::PropertyPercent","Transparency","Base","")
vobj.addProperty("App::PropertyFloat","LineWidth","Base","")
vobj.addProperty("App::PropertyColor","LineColor","Base","")
vobj.DisplaySize = 1
vobj.DisplayLength = 1
vobj.DisplayHeight = 1
vobj.ArrowSize = 1
vobj.Transparency = 85
vobj.LineWidth = 1
vobj.LineColor = (0.0,0.0,0.4,1.0)
Expand Down Expand Up @@ -174,7 +179,7 @@ def attach(self,vobj):
sep.addChild(fsep)
sep.addChild(psep)
vobj.addDisplayMode(sep,"Default")
self.onChanged(vobj,"DisplaySize")
self.onChanged(vobj,"DisplayLength")
self.onChanged(vobj,"LineColor")
self.onChanged(vobj,"Transparency")

Expand All @@ -189,7 +194,7 @@ def setDisplayMode(self,mode):

def updateData(self,obj,prop):
if prop in ["Placement"]:
self.onChanged(obj.ViewObject,"DisplaySize")
self.onChanged(obj.ViewObject,"DisplayLength")
return

def onChanged(self,vobj,prop):
Expand All @@ -200,12 +205,13 @@ def onChanged(self,vobj,prop):
elif prop == "Transparency":
if hasattr(vobj,"Transparency"):
self.mat2.transparency.setValue(vobj.Transparency/100.0)
elif prop == "DisplaySize":
hd = vobj.DisplaySize.Value/2
elif prop in ["DisplayLength","DisplayHeight","ArrowSize"]:
ld = vobj.DisplayLength.Value/2
hd = vobj.DisplayHeight.Value/2
verts = []
fverts = []
for v in [[-hd,-hd],[hd,-hd],[hd,hd],[-hd,hd]]:
l1 = hd/3
for v in [[-ld,-hd],[ld,-hd],[ld,hd],[-ld,hd]]:
l1 = vobj.ArrowSize.Value if vobj.ArrowSize.Value > 0 else 0.1
l2 = l1/3
pl = FreeCAD.Placement(vobj.Object.Placement)
p1 = pl.multVec(Vector(v[0],v[1],0))
Expand Down Expand Up @@ -234,15 +240,17 @@ def __setstate__(self,state):
class _ArchDrawingView:
def __init__(self, obj):
obj.addProperty("App::PropertyLink","Source","Base","The linked object")
obj.addProperty("App::PropertyEnumeration","RenderingMode","Drawing View","The rendering mode to use")
obj.addProperty("App::PropertyBool","ShowCut","Drawing View","If cut geometry is shown or not")
obj.addProperty("App::PropertyFloat","LineWidth","Drawing View","The line width of the rendered objects")
obj.addProperty("App::PropertyEnumeration","RenderingMode","Drawing view","The rendering mode to use")
obj.addProperty("App::PropertyBool","ShowCut","Drawing view","If cut geometry is shown or not")
obj.addProperty("App::PropertyFloat","LineWidth","Drawing view","The line width of the rendered objects")
obj.addProperty("App::PropertyLength","FontSize","Drawing view","The size of the texts inside this object")
obj.RenderingMode = ["Solid","Wireframe"]
obj.RenderingMode = "Wireframe"
obj.LineWidth = 0.35
obj.ShowCut = False
obj.Proxy = self
self.Type = "ArchSectionView"
obj.FontSize = 12

def execute(self, obj):
if obj.Source:
Expand Down Expand Up @@ -296,6 +304,15 @@ def buildSVG(self, obj,join=False):
if obj.Source.Objects:
objs = Draft.getGroupContents(obj.Source.Objects,walls=True)
objs = Draft.removeHidden(objs)
# separate spaces
spaces = []
os = []
for o in objs:
if Draft.getType(o) == "Space":
spaces.append(o)
else:
os.append(o)
objs = os
self.svg = ''

# generating SVG
Expand Down Expand Up @@ -348,6 +365,11 @@ def buildSVG(self, obj,join=False):
sol.reverse()
c = sol.cut(cutvolume)
s = sol.section(cutface)
try:
s = Part.Wire(s.Edges)
s = Part.Face(s)
except:
pass
nsh.extend(c.Solids)
sshapes.append(s)
if hasattr(obj,"ShowCut"):
Expand All @@ -374,21 +396,16 @@ def buildSVG(self, obj,join=False):
svgh = svgh.replace('fill="none"','fill="none"\nstroke-dasharray="0.09,0.05"')
self.svg += svgh
if sshapes:
edges = []
for s in sshapes:
edges.extend(s.Edges)
wires = DraftGeomUtils.findWires(edges)
faces = []
for w in wires:
if (w.ShapeType == "Wire") and w.isClosed():
faces.append(Part.Face(w))
sshapes = Part.makeCompound(faces)
sshapes = Part.makeCompound(sshapes)
svgs = Drawing.projectToSVG(sshapes,self.direction)
if svgs:
svgs = svgs.replace('stroke-width="0.35"','stroke-width="SWPlaceholder"')
svgs = svgs.replace('stroke-width="1"','stroke-width="SWPlaceholder"')
svgs = svgs.replace('stroke-width:0.01','stroke-width:SWPlaceholder')
self.svg += svgs

for s in spaces:
self.svg += Draft.getSVG(s,scale=1/obj.Scale,fontsize=obj.FontSize,direction=self.direction)

def updateSVG(self, obj):
"Formats and places the calculated svg stuff on the page"
Expand All @@ -400,9 +417,7 @@ def updateSVG(self, obj):
if not hasattr(self,"svg"):
return ''
linewidth = obj.LineWidth/obj.Scale
st = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Arch").GetFloat("CutLineThickness")
if not st:
st = 2
st = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Arch").GetFloat("CutLineThickness",2)
svg = self.svg.replace('LWPlaceholder', str(linewidth) + 'px')
svg = svg.replace('SWPlaceholder', str(linewidth*st) + 'px')

Expand Down
2 changes: 1 addition & 1 deletion src/Mod/Arch/ArchVRM.py
Expand Up @@ -254,7 +254,7 @@ def cut(self,cutplane,hidden=False):
shapes.append([c]+sh[1:])
for f in c.Faces:
faces.append([f]+sh[1:])
print "iscoplanar:",f.Vertexes[0].Point,f.normalAt(0,0),cutface.Vertexes[0].Point,cutface.normalAt(0,0)
#print "iscoplanar:",f.Vertexes[0].Point,f.normalAt(0,0),cutface.Vertexes[0].Point,cutface.normalAt(0,0)
if DraftGeomUtils.isCoplanar([f,cutface]):
print "COPLANAR"
sections.append([f,fill])
Expand Down
30 changes: 23 additions & 7 deletions src/Mod/Draft/Draft.py
Expand Up @@ -1758,7 +1758,7 @@ def getArrow(arrowtype,point,arrowsize,color,linewidth,angle=0):
print "getSVG: arrow type not implemented"
return svg

def getText(color,fontsize,fontname,angle,base,text,linespacing=0.5,align="center"):
def getText(color,fontsize,fontname,angle,base,text,linespacing=0.5,align="center",flip=True):
if not isinstance(text,list):
text = text.split("\n")
if align.lower() == "center":
Expand All @@ -1776,7 +1776,10 @@ def getText(color,fontsize,fontname,angle,base,text,linespacing=0.5,align="cente
svg += ','+ str(base.x) + ',' + str(base.y) + ') '
svg += 'translate(' + str(base.x) + ',' + str(base.y) + ') '
#svg += 'scale('+str(tmod/2000)+',-'+str(tmod/2000)+') '
svg += 'scale(1,-1) '
if flip:
svg += 'scale(1,-1) '
else:
svg += 'scale(1,1) '
svg += '" freecad:skip="1"'
svg += '>\n'
if len(text) == 1:
Expand Down Expand Up @@ -1814,7 +1817,7 @@ def getText(color,fontsize,fontname,angle,base,text,linespacing=0.5,align="cente
p2 = getProj(prx.p2)
p3 = getProj(prx.p3)
p4 = getProj(prx.p4)
tbase = p2.add(p3.sub(p2).multiply(0.5))
tbase = getProj(prx.tbase)
angle = -DraftVecUtils.angle(p3.sub(p2))

# drawing lines
Expand All @@ -1825,7 +1828,7 @@ def getText(color,fontsize,fontname,angle,base,text,linespacing=0.5,align="cente
tangle = tangle-math.pi
elif (tangle <= -math.pi/2) or (tangle > math.pi/2):
tangle = tangle+math.pi
tbase = tbase.add(DraftVecUtils.rotate(Vector(0,2/scale,0),tangle))
#tbase = tbase.add(DraftVecUtils.rotate(Vector(0,2/scale,0),tangle))
svg += 'd="M '+str(p1.x)+' '+str(p1.y)+' '
svg += 'L '+str(p2.x)+' '+str(p2.y)+' '
svg += 'L '+str(p3.x)+' '+str(p3.y)+' '
Expand Down Expand Up @@ -1947,6 +1950,19 @@ def getText(color,fontsize,fontname,angle,base,text,linespacing=0.5,align="cente
svg += '<tspan>' + obj.ViewObject.Proxy.getNumber(n) + '</tspan>\n'
svg += '</text>\n'
n += 1

elif getType(obj) == "Space":
"returns an SVG fragment for the text of a space"
c = getrgb(obj.ViewObject.TextColor)
n = obj.ViewObject.FontName
a = 0
t1 = obj.ViewObject.Proxy.text1.string.getValues()
t2 = obj.ViewObject.Proxy.text2.string.getValues()
t = t1 + t2
p = FreeCAD.Vector(obj.ViewObject.Proxy.coords.translation.getValue().getValue())
l = obj.ViewObject.LineSpacing/2
j = obj.ViewObject.TextAlign
svg += getText(c,fontsize,n,a,getProj(p),t,l,j,flip=False)

elif obj.isDerivedFrom('Part::Feature'):
if obj.Shape.isNull():
Expand Down Expand Up @@ -3244,11 +3260,11 @@ def updateData(self, obj, prop):
m = ["2D","3D"][getParam("dimstyle",0)]
if m== "3D":
offset = offset.negative()
tbase = (self.p2.add((self.p3.sub(self.p2).multiply(0.5)))).add(offset)
self.tbase = (self.p2.add((self.p3.sub(self.p2).multiply(0.5)))).add(offset)
if hasattr(obj.ViewObject,"TextPosition"):
if not DraftVecUtils.isNull(obj.ViewObject.TextPosition):
tbase = obj.ViewObject.TextPosition
self.textpos.translation.setValue([tbase.x,tbase.y,tbase.z])
self.tbase = obj.ViewObject.TextPosition
self.textpos.translation.setValue([self.tbase.x,self.tbase.y,self.tbase.z])
self.textpos.rotation = coin.SbRotation(rot1[0],rot1[1],rot1[2],rot1[3])
su = True
if hasattr(obj.ViewObject,"ShowUnit"):
Expand Down
2 changes: 1 addition & 1 deletion src/Mod/Draft/DraftGeomUtils.py
Expand Up @@ -906,7 +906,7 @@ def offset(edge,vector):
elif geomType(edge) == "Circle":
rad = edge.Vertexes[0].Point.sub(edge.Curve.Center)
newrad = Vector.add(rad,vector).Length
return Part.Circle(edge.Curve.Center,edge.Curve.Axis,newrad).toShape()
return Part.Circle(edge.Curve.Center,NORM,newrad).toShape()
else:
return None

Expand Down

0 comments on commit ed4f7dc

Please sign in to comment.