Merge branch 'master' of ssh://git.code.sf.net/p/free-cad/code

This commit is contained in:
wmayer 2014-05-08 17:32:37 +02:00
commit d907d372a4
6 changed files with 128 additions and 68 deletions

View File

@ -573,6 +573,7 @@ def makeCircle(radius, placement=None, face=True, startangle=None, endangle=None
n = "Circle"
obj = FreeCAD.ActiveDocument.addObject("Part::Part2DObjectPython",n)
_Circle(obj)
obj.MakeFace = face
if isinstance(radius,Part.Edge):
edge = radius
if DraftGeomUtils.geomType(edge) == "Circle":
@ -598,7 +599,6 @@ def makeCircle(radius, placement=None, face=True, startangle=None, endangle=None
if placement: obj.Placement = placement
if gui:
_ViewProviderDraft(obj.ViewObject)
if not face: obj.ViewObject.DisplayMode = "Wireframe"
formatObject(obj)
select(obj)
FreeCAD.ActiveDocument.recompute()
@ -616,10 +616,10 @@ def makeRectangle(length, height, placement=None, face=True, support=None):
obj.Length = length
obj.Height = height
obj.Support = support
obj.MakeFace = face
if placement: obj.Placement = placement
if gui:
_ViewProviderRectangle(obj.ViewObject)
if not face: obj.ViewObject.DisplayMode = "Wireframe"
formatObject(obj)
select(obj)
FreeCAD.ActiveDocument.recompute()
@ -752,10 +752,10 @@ def makeWire(pointslist,closed=False,placement=None,face=True,support=None):
obj.Points = pointslist
obj.Closed = closed
obj.Support = support
obj.MakeFace = face
if placement: obj.Placement = placement
if gui:
_ViewProviderWire(obj.ViewObject)
if not face: obj.ViewObject.DisplayMode = "Wireframe"
formatObject(obj)
select(obj)
FreeCAD.ActiveDocument.recompute()
@ -773,6 +773,7 @@ def makePolygon(nfaces,radius=1,inscribed=True,placement=None,face=True,support=
_Polygon(obj)
obj.FacesNumber = nfaces
obj.Radius = radius
obj.MakeFace = face
if inscribed:
obj.DrawMode = "inscribed"
else:
@ -781,7 +782,6 @@ def makePolygon(nfaces,radius=1,inscribed=True,placement=None,face=True,support=
if placement: obj.Placement = placement
if gui:
_ViewProviderDraft(obj.ViewObject)
if not face: obj.ViewObject.DisplayMode = "Wireframe"
formatObject(obj)
select(obj)
FreeCAD.ActiveDocument.recompute()
@ -824,16 +824,16 @@ def makeBSpline(pointslist,closed=False,placement=None,face=True,support=None):
obj.Closed = closed
obj.Points = pointslist
obj.Support = support
obj.MakeFace = face
if placement: obj.Placement = placement
if gui:
_ViewProviderWire(obj.ViewObject)
if not face: obj.ViewObject.DisplayMode = "Wireframe"
formatObject(obj)
select(obj)
FreeCAD.ActiveDocument.recompute()
return obj
def makeBezCurve(pointslist,closed=False,placement=None,support=None,Degree=None):
def makeBezCurve(pointslist,closed=False,placement=None,face=True,support=None,Degree=None):
'''makeBezCurve(pointslist,[closed],[placement]): Creates a Bezier Curve object
from the given list of vectors. Instead of a pointslist, you can also pass a Part Wire.'''
if not isinstance(pointslist,list):
@ -855,12 +855,13 @@ def makeBezCurve(pointslist,closed=False,placement=None,support=None,Degree=None
Part.BezierCurve().MaxDegree)
obj.Closed = closed
obj.Support = support
obj.MakeFace = face
obj.Proxy.resetcontinuity(obj)
if placement: obj.Placement = placement
if gui:
_ViewProviderWire(obj.ViewObject)
# if not face: obj.ViewObject.DisplayMode = "Wireframe"
obj.ViewObject.DisplayMode = "Wireframe"
# obj.ViewObject.DisplayMode = "Wireframe"
formatObject(obj)
select(obj)
FreeCAD.ActiveDocument.recompute()
@ -3095,6 +3096,7 @@ class _ViewProviderDimension(_ViewProviderDraft):
def updateData(self, obj, prop):
"called when the base object is changed"
import DraftGui
if prop in ["Start","End","Dimline","Direction"]:
if obj.Start == obj.End:
@ -3199,10 +3201,9 @@ class _ViewProviderDimension(_ViewProviderDraft):
# set text value
l = self.p3.sub(self.p2).Length
if hasattr(obj.ViewObject,"Decimals"):
fstring = "%." + str(obj.ViewObject.Decimals) + "f"
self.string = DraftGui.displayExternal(l,obj.ViewObject.Decimals,'Length')
else:
fstring = "%." + str(getParam("dimPrecision",2)) + "f"
self.string = (fstring % l)
self.string = DraftGui.displayExternal(l,getParam("dimPrecision",2),'Length')
if hasattr(obj.ViewObject,"Override"):
if obj.ViewObject.Override:
try:
@ -3684,6 +3685,8 @@ class _Rectangle(_DraftObject):
obj.addProperty("App::PropertyDistance","Height","Draft","Height of the rectange")
obj.addProperty("App::PropertyLength","FilletRadius","Draft","Radius to use to fillet the corners")
obj.addProperty("App::PropertyLength","ChamferSize","Draft","Size of the chamfer to give to the corners")
obj.addProperty("App::PropertyBool","MakeFace","Draft","Create a face")
obj.MakeFace = True
obj.Length=1
obj.Height=1
@ -3706,7 +3709,11 @@ class _Rectangle(_DraftObject):
w = DraftGeomUtils.filletWire(shape,obj.FilletRadius.Value)
if w:
shape = w
shape = Part.Face(shape)
if hasattr(obj,"MakeFace"):
if obj.MakeFace:
shape = Part.Face(shape)
else:
shape = Part.Face(shape)
obj.Shape = shape
obj.Placement = plm
@ -3724,6 +3731,8 @@ class _Circle(_DraftObject):
obj.addProperty("App::PropertyAngle","FirstAngle","Draft","Start angle of the arc")
obj.addProperty("App::PropertyAngle","LastAngle","Draft","End angle of the arc (for a full circle, give it same value as First Angle)")
obj.addProperty("App::PropertyLength","Radius","Draft","Radius of the circle")
obj.addProperty("App::PropertyBool","MakeFace","Draft","Create a face")
obj.MakeFace = True
def execute(self, obj):
import Part
@ -3731,7 +3740,11 @@ class _Circle(_DraftObject):
shape = Part.makeCircle(obj.Radius.Value,Vector(0,0,0),Vector(0,0,1),obj.FirstAngle.Value,obj.LastAngle.Value)
if obj.FirstAngle.Value == obj.LastAngle.Value:
shape = Part.Wire(shape)
shape = Part.Face(shape)
if hasattr(obj,"MakeFace"):
if obj.MakeFace:
shape = Part.Face(shape)
else:
shape = Part.Face(shape)
obj.Shape = shape
obj.Placement = plm
@ -3742,6 +3755,8 @@ class _Ellipse(_DraftObject):
_DraftObject.__init__(self,obj,"Ellipse")
obj.addProperty("App::PropertyLength","MinorRadius","Draft","The minor radius of the ellipse")
obj.addProperty("App::PropertyLength","MajorRadius","Draft","The major radius of the ellipse")
obj.addProperty("App::PropertyBool","MakeFace","Draft","Create a face")
obj.MakeFace = True
def execute(self, obj):
import Part
@ -3752,7 +3767,11 @@ class _Ellipse(_DraftObject):
if obj.MajorRadius.Value and obj.MinorRadius.Value:
shape = Part.Ellipse(Vector(0,0,0),obj.MajorRadius.Value,obj.MinorRadius.Value).toShape()
shape = Part.Wire(shape)
shape = Part.Face(shape)
if hasattr(obj,"MakeFace"):
if obj.MakeFace:
shape = Part.Face(shape)
else:
shape = Part.Face(shape)
obj.Shape = shape
obj.Placement = plm
@ -3769,6 +3788,8 @@ class _Wire(_DraftObject):
obj.addProperty("App::PropertyVector","End","Draft","The end point of this line")
obj.addProperty("App::PropertyLength","FilletRadius","Draft","Radius to use to fillet the corners")
obj.addProperty("App::PropertyLength","ChamferSize","Draft","Size of the chamfer to give to the corners")
obj.addProperty("App::PropertyBool","MakeFace","Draft","Create a face if this object is closed")
obj.MakeFace = True
obj.Closed = False
def execute(self, obj):
@ -3778,7 +3799,11 @@ class _Wire(_DraftObject):
if obj.Base.isDerivedFrom("Sketcher::SketchObject"):
shape = obj.Base.Shape.copy()
if obj.Base.Shape.isClosed():
shape = Part.Face(shape)
if hasattr(obj,"MakeFace"):
if obj.MakeFace:
shape = Part.Face(shape)
else:
shape = Part.Face(shape)
obj.Shape = shape
elif obj.Base and obj.Tool:
if obj.Base.isDerivedFrom("Part::Feature") and obj.Tool.isDerivedFrom("Part::Feature"):
@ -3804,7 +3829,11 @@ class _Wire(_DraftObject):
if w:
shape = w
try:
shape = Part.Face(shape)
if hasattr(obj,"MakeFace"):
if obj.MakeFace:
shape = Part.Face(shape)
else:
shape = Part.Face(shape)
except:
pass
else:
@ -3915,6 +3944,8 @@ class _Polygon(_DraftObject):
obj.addProperty("App::PropertyEnumeration","DrawMode","Draft","How the polygon must be drawn from the control circle")
obj.addProperty("App::PropertyLength","FilletRadius","Draft","Radius to use to fillet the corners")
obj.addProperty("App::PropertyLength","ChamferSize","Draft","Size of the chamfer to give to the corners")
obj.addProperty("App::PropertyBool","MakeFace","Draft","Create a face")
obj.MakeFace = True
obj.DrawMode = ['inscribed','circumscribed']
obj.FacesNumber = 0
obj.Radius = 1
@ -3944,7 +3975,11 @@ class _Polygon(_DraftObject):
w = DraftGeomUtils.filletWire(shape,obj.FilletRadius.Value)
if w:
shape = w
shape = Part.Face(shape)
if hasattr(obj,"MakeFace"):
if obj.MakeFace:
shape = Part.Face(shape)
else:
shape = Part.Face(shape)
obj.Shape = shape
obj.Placement = plm
@ -4002,6 +4037,8 @@ class _BSpline(_DraftObject):
_DraftObject.__init__(self,obj,"BSpline")
obj.addProperty("App::PropertyVectorList","Points","Draft", "The points of the b-spline")
obj.addProperty("App::PropertyBool","Closed","Draft","If the b-spline is closed or not")
obj.addProperty("App::PropertyBool","MakeFace","Draft","Create a face if this spline is closed")
obj.MakeFace = True
obj.Closed = False
obj.Points = []
@ -4021,7 +4058,11 @@ class _BSpline(_DraftObject):
# Creating a face from a closed spline cannot be expected to always work
# Usually, if the spline is not flat the call of Part.Face() fails
try:
shape = Part.Face(shape)
if hasattr(obj,"MakeFace"):
if obj.MakeFace:
shape = Part.Face(shape)
else:
shape = Part.Face(shape)
except:
pass
obj.Shape = shape
@ -4047,6 +4088,8 @@ class _BezCurve(_DraftObject):
"Continuity")
obj.addProperty("App::PropertyBool","Closed","Draft",
"If the Bezier curve should be closed or not")
obj.addProperty("App::PropertyBool","MakeFace","Draft","Create a face if this curve is closed")
obj.MakeFace = True
obj.Closed = False
obj.Degree = 3
obj.Continuity = []
@ -4106,7 +4149,11 @@ class _BezCurve(_DraftObject):
w = Part.Wire(edges)
if fp.Closed and w.isClosed():
try:
w = Part.Face(w)
if hasattr(fp,"MakeFace"):
if fp.MakeFace:
w = Part.Face(w)
else:
w = Part.Face(w)
except:
pass
fp.Shape = w
@ -4653,8 +4700,8 @@ class _ShapeString(_DraftObject):
_DraftObject.__init__(self,obj,"ShapeString")
obj.addProperty("App::PropertyString","String","Draft","Text string")
obj.addProperty("App::PropertyFile","FontFile","Draft","Font file name")
obj.addProperty("App::PropertyFloat","Size","Draft","Height of text")
obj.addProperty("App::PropertyFloat","Tracking","Draft",
obj.addProperty("App::PropertyLength","Size","Draft","Height of text")
obj.addProperty("App::PropertyLength","Tracking","Draft",
"Inter-character spacing")
def execute(self, obj):

View File

@ -130,23 +130,24 @@ def makeFormatSpec(decimals=4,dim='Length'):
return fmtSpec
def displayExternal(internValue,decimals=4,dim='Length'):
'''return an internal value (ie mm) Length converted for display according
'''return an internal value (ie mm) Length or Angle converted for display according
to Units Schema in use.'''
from FreeCAD import Units
if dim == 'Length':
qty = FreeCAD.Units.Quantity(internValue,FreeCAD.Units.Length)
parts = (qty.getUserPreferred()[0]).split()
qty = FreeCAD.Units.Quantity(1.0,FreeCAD.Units.Length)
pref = qty.getUserPreferred()
conversion = pref[1]
uom = pref[2]
elif dim == 'Angle':
qty = FreeCAD.Units.Quantity(internValue,FreeCAD.Units.Angle)
qty = FreeCAD.Units.Quantity(1.0,FreeCAD.Units.Angle)
pref=qty.getUserPreferred()
parts = (qty.getUserPreferred()[0]).split()
val = (qty.getUserPreferred()[0]).split()[0]
um = parts[1].decode('latin-1')
parts = (val,um)
conversion = pref[1]
uom = pref[2].decode('latin-1')
else:
parts = (internValue,'??')
fmt = "{0:."+ str(decimals) + "f} "+ parts[1]
displayExt = fmt.format(float(parts[0]))
conversion = 1.0
uom = "??"
fmt = "{0:."+ str(decimals) + "f} "+ uom
displayExt = fmt.format(float(internValue) / float(conversion))
return displayExt
#---------------------------------------------------------------------------
@ -380,11 +381,11 @@ class DraftToolBar:
# shapestring
self.labelSSize = self._label("labelSize", self.layout)
self.SSizeValue = self._lineedit("SSizeValue", self.layout, width=60)
self.SSizeValue.setText("200.0")
self.SSizeValue = self._inputfield("SSizeValue", self.layout) #, width=60)
self.SSizeValue.setText(self.FORMAT % 1.0)
self.labelSTrack = self._label("labelTracking", self.layout)
self.STrackValue = self._lineedit("STrackValue", self.layout, width=60)
self.STrackValue.setText("0")
self.STrackValue = self._inputfield("STrackValue", self.layout) #, width=60)
self.STrackValue.setText(self.FORMAT % 0)
self.labelSString = self._label("labelString", self.layout)
self.SStringValue = self._lineedit("SStringValue", self.layout)
self.SStringValue.setText("")
@ -392,6 +393,8 @@ class DraftToolBar:
self.FFileValue = self._lineedit("FFileValue", self.layout)
self.chooserButton = self._pushbutton("chooserButton", self.layout, width=26)
self.chooserButton.setText("...")
self.SSize = 1
self.STrack = 0
# options
fl = QtGui.QHBoxLayout()
@ -481,8 +484,10 @@ class DraftToolBar:
QtCore.QObject.connect(self.radiusValue,QtCore.SIGNAL("escaped()"),self.escape)
QtCore.QObject.connect(self.baseWidget,QtCore.SIGNAL("resized()"),self.relocate)
QtCore.QObject.connect(self.baseWidget,QtCore.SIGNAL("retranslate()"),self.retranslateUi)
QtCore.QObject.connect(self.SSizeValue,QtCore.SIGNAL("valueChanged(double)"),self.changeSSizeValue)
QtCore.QObject.connect(self.SSizeValue,QtCore.SIGNAL("returnPressed()"),self.validateSNumeric)
QtCore.QObject.connect(self.SSizeValue,QtCore.SIGNAL("escaped()"),self.escape)
QtCore.QObject.connect(self.STrackValue,QtCore.SIGNAL("valueChanged(double)"),self.changeSTrackValue)
QtCore.QObject.connect(self.STrackValue,QtCore.SIGNAL("returnPressed()"),self.validateSNumeric)
QtCore.QObject.connect(self.STrackValue,QtCore.SIGNAL("escaped()"),self.escape)
QtCore.QObject.connect(self.SStringValue,QtCore.SIGNAL("returnPressed()"),self.validateSString)
@ -846,7 +851,7 @@ class DraftToolBar:
self.SStringValue.hide()
self.continueCmd.hide()
self.labelSSize.show()
self.SSizeValue.setText('200.0')
self.SSizeValue.setText(self.FORMAT % 1.0)
self.SSizeValue.show()
self.SSizeValue.setFocus()
@ -855,7 +860,7 @@ class DraftToolBar:
self.labelSSize.hide()
self.SSizeValue.hide()
self.labelSTrack.show()
self.STrackValue.setText('0')
self.STrackValue.setText(self.FORMAT % 0)
self.STrackValue.show()
self.STrackValue.setFocus()
@ -1136,20 +1141,20 @@ class DraftToolBar:
if self.sourceCmd:
if (self.labelSSize.isVisible()):
try:
SSize=float(self.SSizeValue.text())
SSize=float(self.SSize)
except ValueError:
FreeCAD.Console.PrintMessage(translate("draft", "Invalid Size value. Using 200.0."))
self.sourceCmd.numericSSize(unicode("200.0"))
self.sourceCmd.numericSSize(200.0)
else:
self.sourceCmd.numericSSize(unicode(SSize))
self.sourceCmd.numericSSize(SSize)
elif (self.labelSTrack.isVisible()):
try:
track=int(self.STrackValue.text())
track=int(self.STrack)
except ValueError:
FreeCAD.Console.PrintMessage(translate("draft", "Invalid Tracking value. Using 0."))
self.sourceCmd.numericSTrack(unicode("0"))
self.sourceCmd.numericSTrack(0)
else:
self.sourceCmd.numericSTrack(unicode(track))
self.sourceCmd.numericSTrack(track)
def validateSString(self):
''' send a valid text string to ShapeString as unicode '''
@ -1586,6 +1591,12 @@ class DraftToolBar:
def changeOffsetValue(self,d):
self.offset = d
def changeSSizeValue(self,d):
self.SSize = d
def changeSTrackValue(self,d):
self.STrack = d
#---------------------------------------------------------------------------
# TaskView operations
#---------------------------------------------------------------------------

File diff suppressed because one or more lines are too long

View File

@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>487</width>
<height>455</height>
<height>462</height>
</rect>
</property>
<property name="windowTitle">
@ -355,6 +355,26 @@ Values with differences below this value will be treated as same.</string>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_11">
<item>
<widget class="Gui::PrefCheckBox" name="gui::prefcheckbox_6">
<property name="toolTip">
<string>If this is checked, objects will appear as filled as default. Otherwise, they will appear as wireframe</string>
</property>
<property name="text">
<string>Fill objects with faces whenever possible</string>
</property>
<property name="prefEntry" stdset="0">
<cstring>fillmode</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/Draft</cstring>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>

View File

@ -227,26 +227,6 @@
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_8">
<item>
<widget class="Gui::PrefCheckBox" name="gui::prefcheckbox_6">
<property name="toolTip">
<string>If this is checked, objects will appear as filled as default. Otherwise, they will appear as wireframe</string>
</property>
<property name="text">
<string>Fill objects by default</string>
</property>
<property name="prefEntry" stdset="0">
<cstring>fillmode</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/Draft</cstring>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_11">
<item>

View File

@ -1506,6 +1506,8 @@ def getArcData(edge):
a2 = -DraftVecUtils.angle(ve2.sub(ce))
if round(a1,Draft.precision()) == round(a2,Draft.precision()):
return None,None, None, None
if edge.Curve.Axis.z < 0.0:
ang1, ang2 = ang2, ang1
pseudoarc = Part.ArcOfCircle(edge.Curve,a1,a2).toShape()
if round(pseudoarc.Length,Draft.precision()) != round(edge.Length,Draft.precision()):
ang1, ang2 = ang2, ang1
@ -1833,4 +1835,4 @@ dxfUseStandardSize = p.GetBool("dxfStdSize",False)
dxfGetColors = p.GetBool("dxfGetOriginalColors",False)
dxfUseDraftLayers = p.GetBool("dxfUseDraftLayers",False)
dxfBrightBackground = isBrightBackground()
dxfDefaultColor = getColor()
dxfDefaultColor = getColor()