Skip to content

Commit

Permalink
Draft: Grid can now be changed on-the-fly from the Set Working Plane …
Browse files Browse the repository at this point in the history
…button - fixes #2566
  • Loading branch information
yorikvanhavre committed May 29, 2016
1 parent d6f31d5 commit 2938fde
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 2 deletions.
48 changes: 48 additions & 0 deletions src/Mod/Draft/DraftGui.py
Expand Up @@ -468,6 +468,15 @@ def setupToolBar(self,task=False):
self.currentViewButton = self._pushbutton("view", self.layout)
self.resetPlaneButton = self._pushbutton("none", self.layout)
self.isCopy = self._checkbox("isCopy",self.layout,checked=False)
gl = QtGui.QHBoxLayout()
self.layout.addLayout(gl)
self.gridLabel = self._label("gridLabel", gl)
self.gridValue = self._inputfield("gridValue", gl)
self.gridValue.setText(self.FORMAT % 0)
ml = QtGui.QHBoxLayout()
self.layout.addLayout(ml)
self.mainlineLabel = self._label("mainlineLabel", ml)
self.mainlineValue = self._spinbox("mainlineValue", ml)

# spacer
if not self.taskmode:
Expand Down Expand Up @@ -538,6 +547,8 @@ def setupToolBar(self,task=False):
QtCore.QObject.connect(self.SStringValue,QtCore.SIGNAL("returnPressed()"),self.validateSString)
QtCore.QObject.connect(self.chooserButton,QtCore.SIGNAL("pressed()"),self.pickFile)
QtCore.QObject.connect(self.FFileValue,QtCore.SIGNAL("returnPressed()"),self.validateFile)
QtCore.QObject.connect(self.gridValue,QtCore.SIGNAL("textEdited(QString)"),self.setGridSize)
QtCore.QObject.connect(self.mainlineValue,QtCore.SIGNAL("valueChanged(int)"),self.setMainline)

# following lines can cause a crash and are not needed anymore when using the task panel
# http://forum.freecadweb.org/viewtopic.php?f=3&t=6952
Expand Down Expand Up @@ -674,6 +685,10 @@ def retranslateUi(self, widget=None):
self.labelSTrack.setText(translate("draft", "Tracking"))
self.labelFFile.setText(translate("draft", "Full path to font file:"))
self.chooserButton.setToolTip(translate("draft", "Open a FileChooser for font file"))
self.gridLabel.setText(translate("draft", "Grid spacing"))
self.gridValue.setToolTip(translate("draft", "The spacing between the grid lines"))
self.mainlineLabel.setText(translate("draft", "Main line every"))
self.mainlineValue.setToolTip(translate("draft", "The number of lines between main lines"))

# Update the maximum width of the push buttons
maxwidth = 66 # that's the default
Expand Down Expand Up @@ -753,6 +768,17 @@ def selectPlaneUi(self):
self.resetPlaneButton.show()
self.offsetLabel.show()
self.offsetValue.show()
self.gridLabel.show()
self.gridValue.show()
p = Draft.getParam("gridSpacing",1.0)
if FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Units").GetInt("UserSchema",0) == 5:
self.gridValue.setText(FreeCAD.Units.Quantity(p,FreeCAD.Units.Length).UserString)
else:
self.gridValue.setText(self.FORMAT % p)
self.mainlineLabel.show()
self.mainlineValue.show()
p = Draft.getParam("gridEvery",10)
self.mainlineValue.setValue(p)

def extraLineUi(self):
'''shows length and angle controls'''
Expand Down Expand Up @@ -896,6 +922,10 @@ def offUi(self):
self.labelFFile.hide()
self.FFileValue.hide()
self.chooserButton.hide()
self.gridLabel.hide()
self.gridValue.hide()
self.mainlineLabel.hide()
self.mainlineValue.hide()

def trimUi(self,title=translate("draft","Trim")):
self.taskUi(title)
Expand Down Expand Up @@ -1100,6 +1130,24 @@ def reject(self):
FreeCADGui.Control.closeDialog()
panel = TaskPanel(extra,callback)
FreeCADGui.Control.showDialog(panel)

def setGridSize(self,text):
"sets the Draft grid to the given grid size"
try:
q = FreeCAD.Units.Quantity(text)
except:
pass
else:
Draft.setParam("gridSpacing",q.Value)
if hasattr(FreeCADGui,"Snapper"):
FreeCADGui.Snapper.setGrid()

def setMainline(self,val):
"sets the grid main lines"
if val > 1:
Draft.setParam("gridEvery",val)
if hasattr(FreeCADGui,"Snapper"):
FreeCADGui.Snapper.setGrid()

#---------------------------------------------------------------------------
# Processing functions
Expand Down
9 changes: 7 additions & 2 deletions src/Mod/Draft/DraftTrackers.py
Expand Up @@ -783,11 +783,13 @@ def __init__(self):

def update(self):
"redraws the grid"
bound = (self.numlines/2)*self.space
# resize the grid to make sure it fits an exact pair number of main lines
numlines = self.numlines/self.mainlines/2*2*self.mainlines
bound = (numlines/2)*self.space
pts = []
mpts = []
apts = []
for i in range(self.numlines+1):
for i in range(numlines+1):
curr = -bound + i*self.space
z = 0
if i/float(self.mainlines) == i/self.mainlines:
Expand All @@ -809,6 +811,9 @@ def update(self):
midx.append(2)
for ap in range(0,len(apts),2):
aidx.append(2)
self.lines1.numVertices.deleteValues(0)
self.lines2.numVertices.deleteValues(0)
self.lines3.numVertices.deleteValues(0)
self.coords1.point.setValues(pts)
self.lines1.numVertices.setValues(idx)
self.coords2.point.setValues(mpts)
Expand Down

0 comments on commit 2938fde

Please sign in to comment.