draftGui.py

Go to the documentation of this file.
00001 
00002 #***************************************************************************
00003 #*                                                                         *
00004 #*   Copyright (c) 2009 Yorik van Havre <yorik@gmx.fr>                     *  
00005 #*                                                                         *
00006 #*   This program is free software; you can redistribute it and/or modify  *
00007 #*   it under the terms of the GNU General Public License (GPL)            *
00008 #*   as published by the Free Software Foundation; either version 2 of     *
00009 #*   the License, or (at your option) any later version.                   *
00010 #*   for detail see the LICENCE text file.                                 *
00011 #*                                                                         *
00012 #*   This program is distributed in the hope that it will be useful,       *
00013 #*   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00014 #*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00015 #*   GNU Library General Public License for more details.                  *
00016 #*                                                                         *
00017 #*   You should have received a copy of the GNU Library General Public     *
00018 #*   License along with this program; if not, write to the Free Software   *
00019 #*   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  *
00020 #*   USA                                                                   *
00021 #*                                                                         *
00022 #***************************************************************************
00023 
00024 __title__="FreeCAD Draft Workbench - GUI part"
00025 __author__ = "Yorik van Havre <yorik@uncreated.net>"
00026 __url__ = ["http://free-cad.sourceforge.net"]
00027 
00028 '''
00029 This is the GUI part of the Draft module.
00030 Report to Draft.py for info
00031 '''
00032 
00033 import FreeCAD, FreeCADGui, os, Draft
00034 
00035 try:
00036     from PyQt4 import QtCore,QtGui,QtSvg        
00037 except:
00038     FreeCAD.Console.PrintMessage("Error: Python-qt4 package must be installed on your system to use the Draft module.")
00039 
00040 def getMainWindow():
00041     "returns the main window"
00042     # using QtGui.qApp.activeWindow() isn't very reliable because if another
00043     # widget than the mainwindow is active (e.g. a dialog) the wrong widget is
00044     # returned
00045     toplevel = QtGui.qApp.topLevelWidgets()
00046     for i in toplevel:
00047         if i.metaObject().className() == "Gui::MainWindow":
00048             return i
00049     raise Exception("No main window found")
00050 
00051 class todo:
00052     ''' static todo class, delays execution of functions.  Use todo.delay
00053     to schedule geometry manipulation that would crash coin if done in the
00054     event callback'''
00055 
00056     '''List of (function, argument) pairs to be executed by
00057     QtCore.QTimer.singleShot(0,doTodo).'''
00058     itinerary = []
00059     commitlist = []
00060     
00061     @staticmethod
00062     def doTasks():
00063         # print "debug: doing delayed tasks: commitlist: ",todo.commitlist," itinerary: ",todo.itinerary
00064         for f, arg in todo.itinerary:
00065             try:
00066                 # print "debug: executing",f
00067                 if arg:
00068                     f(arg)
00069                 else:
00070                     f()
00071             except:
00072                 wrn = "[Draft.todo] Unexpected error:" + sys.exc_info()[0]
00073                 FreeCAD.Console.PrintWarning (wrn)
00074         todo.itinerary = []
00075         if todo.commitlist:
00076             for name,func in todo.commitlist:
00077                 # print "debug: committing ",str(name)
00078                 try:
00079                     name = str(name)
00080                     FreeCAD.ActiveDocument.openTransaction(name)
00081                     func()
00082                     FreeCAD.ActiveDocument.commitTransaction()
00083                 except:
00084                     wrn = "[Draft.todo] Unexpected error:" + sys.exc_info()[0]
00085                     FreeCAD.Console.PrintWarning (wrn)
00086         todo.commitlist = []
00087 
00088     @staticmethod
00089     def delay (f, arg):
00090         # print "debug: delaying",f
00091         if todo.itinerary == []:
00092             QtCore.QTimer.singleShot(0, todo.doTasks)
00093         todo.itinerary.append((f,arg))
00094 
00095     @staticmethod
00096     def delayCommit (cl):
00097         # print "debug: delaying commit",cl
00098         QtCore.QTimer.singleShot(0, todo.doTasks)
00099         todo.commitlist = cl
00100 
00101 def translate(context,text):
00102         "convenience function for Qt translator"
00103         return QtGui.QApplication.translate(context, text, None,
00104                                             QtGui.QApplication.UnicodeUTF8)
00105 
00106 #---------------------------------------------------------------------------
00107 # Customized widgets
00108 #---------------------------------------------------------------------------
00109 
00110 class DraftDockWidget(QtGui.QWidget):
00111     "custom Widget that emits a resized() signal when resized"
00112     def __init__(self,parent = None):
00113         QtGui.QDockWidget.__init__(self,parent)
00114     def resizeEvent(self,event):
00115         self.emit(QtCore.SIGNAL("resized()"))
00116     def changeEvent(self, event):
00117         if event.type() == QtCore.QEvent.LanguageChange:
00118             self.emit(QtCore.SIGNAL("retranslate()"))
00119         else:
00120             QtGui.QWidget.changeEvent(self,event)
00121                         
00122 class DraftLineEdit(QtGui.QLineEdit):
00123     "custom QLineEdit widget that has the power to catch Escape keypress"
00124     def __init__(self, parent=None):
00125         QtGui.QLineEdit.__init__(self, parent)
00126     def keyPressEvent(self, event):
00127         if event.key() == QtCore.Qt.Key_Escape:
00128             self.emit(QtCore.SIGNAL("escaped()"))
00129         elif event.key() == QtCore.Qt.Key_Up:
00130             self.emit(QtCore.SIGNAL("up()"))
00131         elif event.key() == QtCore.Qt.Key_Down:
00132             self.emit(QtCore.SIGNAL("down()"))
00133         elif (event.key() == QtCore.Qt.Key_Z) and QtCore.Qt.ControlModifier:
00134             self.emit(QtCore.SIGNAL("undo()"))
00135         else:
00136             QtGui.QLineEdit.keyPressEvent(self, event)
00137 
00138 class DraftTaskPanel:
00139     def __init__(self,widget):
00140         self.form = widget
00141     def getStandardButtons(self):
00142         return int(QtGui.QDialogButtonBox.Cancel)
00143     def accept(self):
00144         if FreeCAD.activeDraftCommand:
00145             FreeCAD.activeDraftCommand.finish()
00146         return True
00147     def reject(self):
00148         if FreeCAD.activeDraftCommand:
00149             FreeCAD.activeDraftCommand.finish()
00150         return True
00151   
00152 class DraftToolBar:
00153     "main draft Toolbar"
00154     def __init__(self):
00155         self.tray = None
00156         self.sourceCmd = None
00157         self.taskmode = Draft.getParam("UiMode")
00158         self.paramcolor = Draft.getParam("color")>>8
00159         self.color = QtGui.QColor(self.paramcolor)
00160         self.facecolor = QtGui.QColor(204,204,204)
00161         self.linewidth = Draft.getParam("linewidth")
00162         self.fontsize = Draft.getParam("textheight")
00163         self.paramconstr = Draft.getParam("constructioncolor")>>8
00164         self.constrMode = False
00165         self.continueMode = False
00166         self.state = None
00167         self.textbuffer = []
00168         self.crossedViews = []
00169         self.isTaskOn = False
00170         self.fillmode = Draft.getParam("fillmode")
00171         
00172         if self.taskmode:
00173             # only a dummy widget, since widgets are created on demand
00174             self.baseWidget = QtGui.QWidget()
00175         else:
00176             # create the draft Toolbar                
00177             self.draftWidget = QtGui.QDockWidget()
00178             self.baseWidget = DraftDockWidget()
00179             self.draftWidget.setObjectName("draftToolbar")
00180             self.draftWidget.setTitleBarWidget(self.baseWidget)
00181             self.draftWidget.setWindowTitle(translate("draft", "draft Command Bar"))
00182             self.mw = getMainWindow()
00183             self.mw.addDockWidget(QtCore.Qt.TopDockWidgetArea,self.draftWidget)
00184             self.draftWidget.setVisible(False)
00185             self.draftWidget.toggleViewAction().setVisible(False)                
00186             self.mw = getMainWindow()                
00187             self.baseWidget.setObjectName("draftToolbar")
00188             self.layout = QtGui.QHBoxLayout(self.baseWidget)
00189             self.layout.setObjectName("layout")
00190             self.toptray = self.layout
00191             self.bottomtray = self.layout
00192             self.setupToolBar()
00193             self.setupTray()
00194             self.setupStyle()
00195             self.retranslateUi(self.baseWidget)
00196                 
00197 #---------------------------------------------------------------------------
00198 # General UI setup
00199 #---------------------------------------------------------------------------
00200 
00201     def _pushbutton (self,name, layout, hide=True, icon=None, width=66, checkable=False):
00202         button = QtGui.QPushButton(self.baseWidget)
00203         button.setObjectName(name)
00204         button.setMaximumSize(QtCore.QSize(width,26))
00205         if hide:
00206             button.hide()
00207         if icon:
00208             button.setIcon(QtGui.QIcon(':/icons/'+icon+'.svg'))
00209             button.setIconSize(QtCore.QSize(16, 16))
00210         if checkable:
00211             button.setCheckable(True)
00212             button.setChecked(False)
00213         layout.addWidget(button)
00214         return button
00215 
00216     def _label (self,name, layout, hide=True):
00217         label = QtGui.QLabel(self.baseWidget)
00218         label.setObjectName(name)
00219         if hide: label.hide()
00220         layout.addWidget(label)
00221         return label
00222 
00223     def _lineedit (self,name, layout, hide=True, width=None):
00224         lineedit = DraftLineEdit(self.baseWidget)
00225         lineedit.setObjectName(name)
00226         if hide: lineedit.hide()
00227         if not width: width = 800
00228         lineedit.setMaximumSize(QtCore.QSize(width,22))
00229         layout.addWidget(lineedit)
00230         return lineedit
00231 
00232     def _spinbox (self,name, layout, val=None, vmax=None, hide=True, double=False, size=None):
00233         if double:
00234             sbox = QtGui.QDoubleSpinBox(self.baseWidget)
00235             sbox.setDecimals(2)
00236         else:
00237             sbox = QtGui.QSpinBox(self.baseWidget)
00238         sbox.setObjectName(name)
00239         if val: sbox.setValue(val)
00240         if vmax: sbox.setMaximum(vmax)
00241         if size: sbox.setMaximumSize(QtCore.QSize(size[0],size[1]))
00242         if hide: sbox.hide()
00243         layout.addWidget(sbox)
00244         return sbox
00245 
00246     def _checkbox (self,name, layout, checked=True, hide=True):
00247         chk = QtGui.QCheckBox(self.baseWidget)
00248         chk.setChecked(checked)
00249         chk.setObjectName(name)
00250         if hide: chk.hide()
00251         layout.addWidget(chk)
00252         return chk
00253                         
00254     def setupToolBar(self,task=False):
00255         "sets the draft toolbar up"
00256         
00257         # command
00258 
00259         self.promptlabel = self._label("promptlabel", self.layout, hide=task)
00260         self.cmdlabel = self._label("cmdlabel", self.layout, hide=task)
00261         boldtxt = QtGui.QFont()
00262         boldtxt.setWeight(75)
00263         boldtxt.setBold(True)
00264         self.cmdlabel.setFont(boldtxt)
00265 
00266         # subcommands
00267 
00268         self.addButton = self._pushbutton("addButton", self.layout, icon="Draft_AddPoint", width=22, checkable=True)
00269         self.delButton = self._pushbutton("delButton", self.layout, icon="Draft_DelPoint", width=22, checkable=True)
00270 
00271         # point
00272 
00273         xl = QtGui.QHBoxLayout()
00274         yl = QtGui.QHBoxLayout()
00275         zl = QtGui.QHBoxLayout()
00276         self.layout.addLayout(xl)
00277         self.layout.addLayout(yl)
00278         self.layout.addLayout(zl)
00279         self.labelx = self._label("labelx", xl)
00280         self.xValue = self._lineedit("xValue", xl, width=60)
00281         self.xValue.setText("0.00")
00282         self.labely = self._label("labely", yl)
00283         self.yValue = self._lineedit("yValue", yl, width=60)
00284         self.yValue.setText("0.00")
00285         self.labelz = self._label("labelz", zl)
00286         self.zValue = self._lineedit("zValue", zl, width=60)
00287         self.zValue.setText("0.00")
00288         self.textValue = self._lineedit("textValue", self.layout)
00289 
00290         # options
00291 
00292         self.numFaces = self._spinbox("numFaces", self.layout, 3)
00293         self.offsetLabel = self._label("offsetlabel", self.layout)
00294         self.offsetValue = self._lineedit("offsetValue", self.layout, width=60)
00295         self.offsetValue.setText("0.00")
00296         self.labelRadius = self._label("labelRadius", self.layout)
00297         self.radiusValue = self._lineedit("radiusValue", self.layout, width=60)
00298         self.radiusValue.setText("0.00")
00299         self.isRelative = self._checkbox("isRelative",self.layout,checked=True)
00300         self.hasFill = self._checkbox("hasFill",self.layout,checked=self.fillmode)
00301         self.continueCmd = self._checkbox("continueCmd",self.layout,checked=False)
00302         self.occOffset = self._checkbox("occOffset",self.layout,checked=False)
00303         self.undoButton = self._pushbutton("undoButton", self.layout, icon='Draft_Rotate')
00304         self.finishButton = self._pushbutton("finishButton", self.layout, icon='Draft_Finish')
00305         self.closeButton = self._pushbutton("closeButton", self.layout, icon='Draft_Lock')
00306         self.wipeButton = self._pushbutton("wipeButton", self.layout, icon='Draft_Wipe')
00307         self.xyButton = self._pushbutton("xyButton", self.layout)
00308         self.xzButton = self._pushbutton("xzButton", self.layout)
00309         self.yzButton = self._pushbutton("yzButton", self.layout)
00310         self.currentViewButton = self._pushbutton("view", self.layout)
00311         self.resetPlaneButton = self._pushbutton("none", self.layout)
00312         self.isCopy = self._checkbox("isCopy",self.layout,checked=False)
00313 
00314         # spacer
00315         if not self.taskmode:
00316             spacerItem = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding,
00317                                            QtGui.QSizePolicy.Minimum)
00318         else:
00319             spacerItem = QtGui.QSpacerItem(20, 40, QtGui.QSizePolicy.Minimum,
00320                                            QtGui.QSizePolicy.Expanding)
00321         self.layout.addItem(spacerItem)
00322         
00323         QtCore.QObject.connect(self.xValue,QtCore.SIGNAL("returnPressed()"),self.checkx)
00324         QtCore.QObject.connect(self.yValue,QtCore.SIGNAL("returnPressed()"),self.checky)
00325         QtCore.QObject.connect(self.xValue,QtCore.SIGNAL("textEdited(QString)"),self.checkSpecialChars)
00326         QtCore.QObject.connect(self.yValue,QtCore.SIGNAL("textEdited(QString)"),self.checkSpecialChars)
00327         QtCore.QObject.connect(self.zValue,QtCore.SIGNAL("textEdited(QString)"),self.checkSpecialChars)
00328         QtCore.QObject.connect(self.radiusValue,QtCore.SIGNAL("textEdited(QString)"),self.checkSpecialChars)
00329         QtCore.QObject.connect(self.zValue,QtCore.SIGNAL("returnPressed()"),self.validatePoint)
00330         QtCore.QObject.connect(self.radiusValue,QtCore.SIGNAL("returnPressed()"),self.validatePoint)
00331         QtCore.QObject.connect(self.textValue,QtCore.SIGNAL("textChanged(QString)"),self.storeCurrentText)
00332         QtCore.QObject.connect(self.textValue,QtCore.SIGNAL("returnPressed()"),self.sendText)
00333         QtCore.QObject.connect(self.textValue,QtCore.SIGNAL("escaped()"),self.finish)
00334         QtCore.QObject.connect(self.textValue,QtCore.SIGNAL("down()"),self.sendText)
00335         QtCore.QObject.connect(self.textValue,QtCore.SIGNAL("up()"),self.lineUp)
00336         QtCore.QObject.connect(self.zValue,QtCore.SIGNAL("returnPressed()"),self.xValue.setFocus)
00337         QtCore.QObject.connect(self.zValue,QtCore.SIGNAL("returnPressed()"),self.xValue.selectAll)
00338         QtCore.QObject.connect(self.offsetValue,QtCore.SIGNAL("textEdited(QString)"),self.checkSpecialChars)
00339         QtCore.QObject.connect(self.offsetValue,QtCore.SIGNAL("returnPressed()"),self.validatePoint)
00340         QtCore.QObject.connect(self.addButton,QtCore.SIGNAL("toggled(bool)"),self.setAddMode)
00341         QtCore.QObject.connect(self.delButton,QtCore.SIGNAL("toggled(bool)"),self.setDelMode)
00342         QtCore.QObject.connect(self.finishButton,QtCore.SIGNAL("pressed()"),self.finish)
00343         QtCore.QObject.connect(self.closeButton,QtCore.SIGNAL("pressed()"),self.closeLine)
00344         QtCore.QObject.connect(self.wipeButton,QtCore.SIGNAL("pressed()"),self.wipeLine)
00345         QtCore.QObject.connect(self.undoButton,QtCore.SIGNAL("pressed()"),self.undoSegment)
00346         QtCore.QObject.connect(self.xyButton,QtCore.SIGNAL("clicked()"),self.selectXY)
00347         QtCore.QObject.connect(self.xzButton,QtCore.SIGNAL("clicked()"),self.selectXZ)
00348         QtCore.QObject.connect(self.yzButton,QtCore.SIGNAL("clicked()"),self.selectYZ)
00349         QtCore.QObject.connect(self.continueCmd,QtCore.SIGNAL("stateChanged(int)"),self.setContinue)               
00350         QtCore.QObject.connect(self.hasFill,QtCore.SIGNAL("stateChanged(int)"),self.setFill) 
00351         QtCore.QObject.connect(self.currentViewButton,QtCore.SIGNAL("clicked()"),self.selectCurrentView)
00352         QtCore.QObject.connect(self.resetPlaneButton,QtCore.SIGNAL("clicked()"),self.selectResetPlane)
00353         QtCore.QObject.connect(self.xValue,QtCore.SIGNAL("escaped()"),self.finish)
00354         QtCore.QObject.connect(self.xValue,QtCore.SIGNAL("undo()"),self.undoSegment)
00355         QtCore.QObject.connect(self.yValue,QtCore.SIGNAL("escaped()"),self.finish)
00356         QtCore.QObject.connect(self.yValue,QtCore.SIGNAL("undo()"),self.undoSegment)
00357         QtCore.QObject.connect(self.zValue,QtCore.SIGNAL("escaped()"),self.finish)
00358         QtCore.QObject.connect(self.zValue,QtCore.SIGNAL("undo()"),self.undoSegment)
00359         QtCore.QObject.connect(self.radiusValue,QtCore.SIGNAL("escaped()"),self.finish)
00360         QtCore.QObject.connect(self.baseWidget,QtCore.SIGNAL("resized()"),self.relocate)
00361         QtCore.QObject.connect(self.baseWidget,QtCore.SIGNAL("retranslate()"),self.retranslateUi)
00362 
00363     def setupTray(self):
00364         "sets draft tray buttons up"
00365 
00366         self.wplabel = self._pushbutton("wplabel", self.toptray, icon='Draft_SelectPlane',hide=False,width=120)
00367         defaultWP = Draft.getParam("defaultWP")
00368         if defaultWP == 1:
00369             self.wplabel.setText("Top")
00370         elif defaultWP == 2:
00371             self.wplabel.setText("Front")
00372         elif defaultWP == 3:
00373             self.wplabel.setText("Side")
00374         else:
00375             self.wplabel.setText("None")
00376         self.constrButton = self._pushbutton("constrButton", self.toptray, hide=False, icon='Draft_Construction',width=22, checkable=True)
00377         self.constrColor = QtGui.QColor(self.paramconstr)
00378         self.colorButton = self._pushbutton("colorButton",self.bottomtray, hide=False,width=22)
00379         self.colorPix = QtGui.QPixmap(16,16)
00380         self.colorPix.fill(self.color)
00381         self.colorButton.setIcon(QtGui.QIcon(self.colorPix))
00382         self.facecolorButton = self._pushbutton("facecolorButton",self.bottomtray, hide=False,width=22)
00383         self.facecolorPix = QtGui.QPixmap(16,16)
00384         self.facecolorPix.fill(self.facecolor)
00385         self.facecolorButton.setIcon(QtGui.QIcon(self.facecolorPix))
00386         self.widthButton = self._spinbox("widthButton", self.bottomtray, val=self.linewidth,hide=False,size=(50,22))
00387         self.widthButton.setSuffix("px")
00388         self.fontsizeButton = self._spinbox("fontsizeButton",self.bottomtray, val=self.fontsize,hide=False,double=True,size=(50,22))
00389         self.applyButton = self._pushbutton("applyButton", self.toptray, hide=False, icon='Draft_Apply',width=22)
00390 
00391         QtCore.QObject.connect(self.wplabel,QtCore.SIGNAL("pressed()"),self.selectplane)
00392         QtCore.QObject.connect(self.colorButton,QtCore.SIGNAL("pressed()"),self.getcol)
00393         QtCore.QObject.connect(self.facecolorButton,QtCore.SIGNAL("pressed()"),self.getfacecol)
00394         QtCore.QObject.connect(self.widthButton,QtCore.SIGNAL("valueChanged(int)"),self.setwidth)
00395         QtCore.QObject.connect(self.fontsizeButton,QtCore.SIGNAL("valueChanged(double)"),self.setfontsize)
00396         QtCore.QObject.connect(self.applyButton,QtCore.SIGNAL("pressed()"),self.apply)
00397         QtCore.QObject.connect(self.constrButton,QtCore.SIGNAL("toggled(bool)"),self.toggleConstrMode)
00398 
00399     def setupStyle(self):
00400         style = "#constrButton:Checked {background-color: "
00401         style += self.getDefaultColor("constr",rgb=True)+" } "
00402         style += "#addButton:Checked, #delButton:checked {"
00403         style += "background-color: rgb(20,100,250) }"
00404         self.baseWidget.setStyleSheet(style)
00405 
00406 #---------------------------------------------------------------------------
00407 # language tools
00408 #---------------------------------------------------------------------------
00409                                 
00410     def retranslateUi(self, widget=None):
00411         self.promptlabel.setText(translate("draft", "active command:"))
00412         self.cmdlabel.setText(translate("draft", "None"))
00413         self.cmdlabel.setToolTip(translate("draft", "Active Draft command"))
00414         self.xValue.setToolTip(translate("draft", "X coordinate of next point"))
00415         self.labelx.setText(translate("draft", "X"))
00416         self.labely.setText(translate("draft", "Y"))
00417         self.labelz.setText(translate("draft", "Z"))
00418         self.yValue.setToolTip(translate("draft", "Y coordinate of next point"))
00419         self.zValue.setToolTip(translate("draft", "Z coordinate of next point"))
00420         self.labelRadius.setText(translate("draft", "Radius"))
00421         self.radiusValue.setToolTip(translate("draft", "Radius of Circle"))
00422         self.isRelative.setText(translate("draft", "&Relative"))
00423         self.isRelative.setToolTip(translate("draft", "Coordinates relative to last point or absolute (SPACE)"))
00424         self.hasFill.setText(translate("draft", "F&illed"))
00425         self.hasFill.setToolTip(translate("draft", "Check this if the object should appear as filled, otherwise it will appear as wireframe (i)"))
00426         self.finishButton.setText(translate("draft", "&Finish"))
00427         self.finishButton.setToolTip(translate("draft", "Finishes the current drawing or editing operation (F)"))
00428         self.continueCmd.setToolTip(translate("draft", "If checked, command will not finish until you press the command button again"))
00429         self.continueCmd.setText(translate("draft", "&Continue"))
00430         self.occOffset.setToolTip(translate("draft", "If checked, an OCC-style offset will be performed instead of the classic offset"))
00431         self.occOffset.setText(translate("draft", "&OCC-style offset"))
00432         self.addButton.setToolTip(translate("draft", "Add points to the current object"))
00433         self.delButton.setToolTip(translate("draft", "Remove points from the current object"))
00434         self.undoButton.setText(translate("draft", "&Undo"))
00435         self.undoButton.setToolTip(translate("draft", "Undo the last segment (CTRL+Z)"))
00436         self.closeButton.setText(translate("draft", "&Close"))
00437         self.closeButton.setToolTip(translate("draft", "Finishes and closes the current line (C)"))
00438         self.wipeButton.setText(translate("draft", "&Wipe"))
00439         self.wipeButton.setToolTip(translate("draft", "Wipes the existing segments of this line and starts again from the last point (W)"))
00440         self.numFaces.setToolTip(translate("draft", "Number of sides"))
00441         self.offsetLabel.setText(translate("draft", "Offset"))
00442         self.xyButton.setText(translate("draft", "XY"))
00443         self.xyButton.setToolTip(translate("draft", "Select XY plane"))
00444         self.xzButton.setText(translate("draft", "XZ"))
00445         self.xzButton.setToolTip(translate("draft", "Select XZ plane"))
00446         self.yzButton.setText(translate("draft", "YZ"))
00447         self.yzButton.setToolTip(translate("draft", "Select YZ plane"))
00448         self.currentViewButton.setText(translate("draft", "View"))
00449         self.currentViewButton.setToolTip(translate("draft", "Select plane perpendicular to the current view"))
00450         self.resetPlaneButton.setText(translate("draft", "None"))
00451         self.resetPlaneButton.setToolTip(translate("draft", "Do not project points to a drawing plane"))
00452         self.isCopy.setText(translate("draft", "&Copy"))
00453         self.isCopy.setToolTip(translate("draft", "If checked, objects will be copied instead of moved (C)"))
00454         if (not self.taskmode) or self.tray:
00455             self.colorButton.setToolTip(translate("draft", "Line Color"))
00456             self.facecolorButton.setToolTip(translate("draft", "Face Color"))
00457             self.widthButton.setToolTip(translate("draft", "Line Width"))
00458             self.fontsizeButton.setToolTip(translate("draft", "Font Size"))
00459             self.applyButton.setToolTip(translate("draft", "Apply to selected objects"))
00460             self.constrButton.setToolTip(translate("draft", "Toggles Construction Mode"))
00461 
00462 #---------------------------------------------------------------------------
00463 # Interface modes
00464 #---------------------------------------------------------------------------
00465 
00466     def taskUi(self,title):
00467         if self.taskmode:
00468             self.isTaskOn = True
00469             FreeCADGui.Control.closeDialog()
00470             self.baseWidget = QtGui.QWidget()
00471             self.setTitle(title)
00472             self.layout = QtGui.QVBoxLayout(self.baseWidget)
00473             self.setupToolBar(task=True)
00474             self.retranslateUi(self.baseWidget)
00475             self.panel = DraftTaskPanel(self.baseWidget)
00476             FreeCADGui.Control.showDialog(self.panel)
00477         else:
00478             self.setTitle(title)  
00479                 
00480     def selectPlaneUi(self):
00481         self.taskUi(translate("draft", "Select Plane"))
00482         self.xyButton.show()
00483         self.xzButton.show()
00484         self.yzButton.show()
00485         self.currentViewButton.show()
00486         self.resetPlaneButton.show()
00487         self.offsetLabel.show()
00488         self.offsetValue.show()
00489 
00490     def lineUi(self):
00491         self.pointUi(translate("draft", "Line"))
00492         self.xValue.setEnabled(True)
00493         self.yValue.setEnabled(True)
00494         self.isRelative.show()
00495         self.hasFill.show()
00496         self.finishButton.show()
00497         self.closeButton.show()
00498         self.wipeButton.show()
00499         self.undoButton.show()
00500         self.continueCmd.show()
00501 
00502     def circleUi(self):
00503         self.pointUi(translate("draft", "Circle"))
00504         self.continueCmd.show()
00505         self.labelx.setText(translate("draft", "Center X"))
00506         self.hasFill.show()
00507 
00508     def arcUi(self):
00509         self.pointUi(translate("draft", "Arc"))
00510         self.labelx.setText(translate("draft", "Center X"))
00511         self.continueCmd.show()
00512 
00513     def pointUi(self,title=translate("draft","Point")):
00514         self.taskUi(title)
00515         self.xValue.setEnabled(True)
00516         self.yValue.setEnabled(True)
00517         self.labelx.setText(translate("draft", "X"))
00518         self.labelx.show()
00519         self.labely.show()
00520         self.labelz.show()
00521         self.xValue.show()
00522         self.yValue.show()
00523         self.zValue.show()
00524         self.xValue.setFocus()
00525         self.xValue.selectAll()
00526 
00527     def offsetUi(self):
00528         self.taskUi(translate("draft","Offset"))
00529         self.radiusUi()
00530         self.isCopy.show()
00531         self.occOffset.show()
00532         self.labelRadius.setText(translate("draft","Distance"))
00533         self.radiusValue.setFocus()
00534         self.radiusValue.selectAll()
00535 
00536     def offUi(self):
00537         if self.taskmode:
00538             self.isTaskOn = False
00539             todo.delay(FreeCADGui.Control.closeDialog,None)
00540             self.baseWidget = QtGui.QWidget()
00541             # print "UI turned off"
00542         else:
00543             self.setTitle(translate("draft", "None"))
00544             self.labelx.setText(translate("draft", "X"))
00545             self.labelx.hide()
00546             self.labely.hide()
00547             self.labelz.hide()
00548             self.xValue.hide()
00549             self.yValue.hide()
00550             self.zValue.hide()
00551             self.numFaces.hide()
00552             self.isRelative.hide()
00553             self.hasFill.hide()
00554             self.finishButton.hide()
00555             self.addButton.hide()
00556             self.delButton.hide()
00557             self.undoButton.hide()
00558             self.closeButton.hide()
00559             self.wipeButton.hide()
00560             self.xyButton.hide()
00561             self.xzButton.hide()
00562             self.yzButton.hide()
00563             self.currentViewButton.hide()
00564             self.resetPlaneButton.hide()
00565             self.offsetLabel.hide()
00566             self.offsetValue.hide()
00567             self.labelRadius.hide()
00568             self.radiusValue.hide()
00569             self.isCopy.hide()
00570             self.textValue.hide()
00571             self.continueCmd.hide()
00572             self.occOffset.hide()
00573 
00574     def trimUi(self,title=translate("draft","Trim")):
00575         self.taskUi(title)
00576         self.radiusUi()
00577         self.labelRadius.setText(translate("draft","Distance"))
00578         self.radiusValue.setFocus()
00579         self.radiusValue.selectAll()
00580 
00581     def radiusUi(self):
00582         self.labelx.hide()
00583         self.labely.hide()
00584         self.labelz.hide()
00585         self.xValue.hide()
00586         self.yValue.hide()
00587         self.zValue.hide()
00588         self.labelRadius.setText(translate("draft", "Radius"))
00589         self.labelRadius.show()
00590         self.radiusValue.show()
00591 
00592     def textUi(self):
00593         self.labelx.hide()
00594         self.labely.hide()
00595         self.labelz.hide()
00596         self.xValue.hide()
00597         self.yValue.hide()
00598         self.zValue.hide()
00599         self.textValue.show()
00600         self.textValue.setText('')
00601         self.textValue.setFocus()
00602         self.textbuffer=[]
00603         self.textline=0
00604         self.continueCmd.show()
00605                 
00606     def switchUi(self,store=True):
00607         if store:
00608             self.state = []
00609             self.state.append(self.labelx.isVisible())
00610             self.state.append(self.labely.isVisible())
00611             self.state.append(self.labelz.isVisible())
00612             self.state.append(self.xValue.isVisible())
00613             self.state.append(self.yValue.isVisible())
00614             self.state.append(self.zValue.isVisible())
00615             self.labelx.hide()
00616             self.labely.hide()
00617             self.labelz.hide()
00618             self.xValue.hide()
00619             self.yValue.hide()
00620             self.zValue.hide()
00621         else:
00622             if self.state:
00623                 if self.state[0]:self.labelx.show()
00624                 if self.state[1]:self.labely.show()
00625                 if self.state[2]:self.labelz.show()
00626                 if self.state[3]:self.xValue.show()
00627                 if self.state[4]:self.yValue.show()
00628                 if self.state[5]:self.zValue.show()
00629                 self.state = None
00630 
00631     def setTitle(self,title):
00632         if self.taskmode:
00633             self.baseWidget.setWindowTitle(title)
00634         else:
00635             self.cmdlabel.setText(title)
00636 
00637     def selectUi(self):
00638         if not self.taskmode:
00639             self.labelx.setText(translate("draft", "Pick Object"))
00640             self.labelx.show()
00641 
00642     def editUi(self):
00643         self.taskUi(translate("draft", "Edit"))
00644         self.labelx.hide()
00645         self.labely.hide()
00646         self.labelz.hide()
00647         self.xValue.hide()
00648         self.yValue.hide()
00649         self.zValue.hide()
00650         self.numFaces.hide()
00651         self.isRelative.hide()
00652         self.hasFill.hide()
00653         self.addButton.show()
00654         self.delButton.show()
00655         self.finishButton.show()
00656         self.closeButton.show()
00657         
00658     def extUi(self):
00659         self.hasFill.show()
00660         self.continueCmd.show()
00661 
00662     def modUi(self):
00663         self.isCopy.show()
00664         self.continueCmd.show()
00665 
00666     def vertUi(self,addmode=True):
00667         self.addButton.setChecked(addmode)
00668         self.delButton.setChecked(not(addmode))
00669 
00670     def setEditButtons(self,mode):
00671         self.addButton.setEnabled(mode)
00672         self.delButton.setEnabled(mode)
00673 
00674     def setNextFocus(self):
00675         def isThere(widget):
00676             if widget.isEnabled() and widget.isVisible():
00677                 return True
00678             else:
00679                 return False
00680         if (not self.taskmode) or self.isTaskOn:
00681             if isThere(self.xValue):
00682                 self.xValue.setFocus()
00683                 self.xValue.selectAll()
00684             elif isThere(self.yValue):
00685                 self.yValue.setFocus()
00686                 self.yValue.selectAll()
00687             elif isThere(self.zValue):
00688                 self.zValue.setFocus()
00689                 self.zValue.selectAll()
00690             elif isThere(self.radiusValue):
00691                 self.radiusValue.setFocus()
00692                 self.radiusValue.selectAll()
00693 
00694     def setRelative(self):
00695         if (not self.taskmode) or self.isTaskOn:
00696             self.isRelative.show()
00697 
00698     def relocate(self):
00699         "relocates the right-aligned buttons depending on the toolbar size"
00700         if self.baseWidget.geometry().width() < 400:
00701             self.layout.setDirection(QtGui.QBoxLayout.TopToBottom)
00702         else:
00703             self.layout.setDirection(QtGui.QBoxLayout.LeftToRight)
00704 
00705 
00706 #---------------------------------------------------------------------------
00707 # Processing functions
00708 #---------------------------------------------------------------------------
00709                                         
00710     def getcol(self):
00711         "opens a color picker dialog"
00712         self.color=QtGui.QColorDialog.getColor()
00713         self.colorPix.fill(self.color)
00714         self.colorButton.setIcon(QtGui.QIcon(self.colorPix))
00715         if Draft.getParam("saveonexit"):
00716             Draft.setParam("color",self.color.rgb()<<8)
00717         r = float(self.color.red()/255.0)
00718         g = float(self.color.green()/255.0)
00719         b = float(self.color.blue()/255.0)
00720         col = (r,g,b,0.0)
00721         for i in FreeCADGui.Selection.getSelection():
00722             if (i.Type == "App::Annotation"):
00723                 i.ViewObject.TextColor=col
00724             else:
00725                 if "LineColor" in i.ViewObject.PropertiesList:
00726                     i.ViewObject.LineColor = col
00727                 if "PointColor" in i.ViewObject.PropertiesList:
00728                     i.ViewObject.PointColor = col
00729 
00730     def getfacecol(self):
00731         "opens a color picker dialog"
00732         self.facecolor=QtGui.QColorDialog.getColor()
00733         self.facecolorPix.fill(self.facecolor)
00734         self.facecolorButton.setIcon(QtGui.QIcon(self.facecolorPix))
00735         r = float(self.facecolor.red()/255.0)
00736         g = float(self.facecolor.green()/255.0)
00737         b = float(self.facecolor.blue()/255.0)
00738         col = (r,g,b,0.0)
00739         for i in FreeCADGui.Selection.getSelection():
00740             if "ShapeColor" in i.ViewObject.PropertiesList:
00741                 i.ViewObject.ShapeColor = col
00742                                         
00743     def setwidth(self,val):
00744         self.linewidth = float(val)
00745         if Draft.getParam("saveonexit"):
00746             Draft.setParam("linewidth",int(val))
00747         for i in FreeCADGui.Selection.getSelection():
00748             if "LineWidth" in i.ViewObject.PropertiesList:
00749                 i.ViewObject.LineWidth = float(val)
00750 
00751     def setfontsize(self,val):
00752         self.fontsize = float(val)
00753         if Draft.getParam("saveonexit"):
00754             Draft.setParam("textheight",float(val))
00755         for i in FreeCADGui.Selection.getSelection():
00756             if "FontSize" in i.ViewObject.PropertiesList:
00757                 i.ViewObject.FontSize = float(val)
00758 
00759     def setContinue(self,val):
00760         self.continueMode = bool(val)
00761 
00762     def setFill(self,val):
00763         self.fillmode = bool(val)
00764         
00765     def apply(self):
00766         for i in FreeCADGui.Selection.getSelection():
00767             Draft.formatObject(i)       
00768 
00769     def checkx(self):
00770         if self.yValue.isEnabled():
00771             self.yValue.setFocus()
00772             self.yValue.selectAll()
00773         else:
00774             self.checky()
00775 
00776     def checky(self):
00777         if self.zValue.isEnabled():
00778             self.zValue.setFocus()
00779             self.zValue.selectAll()
00780         else:
00781             self.validatePoint()
00782 
00783     def validatePoint(self):
00784         "function for checking and sending numbers entered manually"
00785         if self.sourceCmd != None:
00786             if (self.labelRadius.isVisible()):
00787                 try:
00788                     rad=float(self.radiusValue.text())
00789                 except ValueError:
00790                     pass
00791                 else:
00792                     self.sourceCmd.numericRadius(rad)
00793             elif (self.offsetLabel.isVisible()):
00794                 try:
00795                     offset=float(self.offsetValue.text())
00796                 except ValueError:
00797                     pass
00798                 else:
00799                     self.sourceCmd.offsetHandler(offset)
00800             else:
00801                 try:
00802                     numx=float(self.xValue.text())
00803                     numy=float(self.yValue.text())
00804                     numz=float(self.zValue.text())
00805                 except ValueError:
00806                     pass
00807                 else:
00808                     if self.isRelative.isVisible() and self.isRelative.isChecked():
00809                         if self.sourceCmd.node:
00810                             if self.sourceCmd.featureName == "Rectangle":
00811                                 last = self.sourceCmd.node[0]
00812                             else:
00813                                 last = self.sourceCmd.node[-1]
00814                             numx = last.x + numx
00815                             numy = last.y + numy
00816                             numz = last.z + numz
00817                             if FreeCAD.DraftWorkingPlane:
00818                                 v = FreeCAD.Vector(numx,numy,numz)
00819                                 v = FreeCAD.DraftWorkingPlane.getGlobalCoords(v)
00820                                 numx = v.x
00821                                 numy = v.y
00822                                 numz = v.z
00823                     self.sourceCmd.numericInput(numx,numy,numz)
00824 
00825     def finish(self):
00826         "finish button action"
00827         self.sourceCmd.finish(False)
00828 
00829     def closeLine(self):
00830         "close button action"
00831         self.sourceCmd.finish(True)
00832 
00833     def wipeLine(self):
00834         "wipes existing segments of a line"
00835         self.sourceCmd.wipe()
00836 
00837     def selectXY(self):
00838         self.sourceCmd.selectHandler("XY")
00839 
00840     def selectXZ(self):
00841         self.sourceCmd.selectHandler("XZ")
00842 
00843     def selectYZ(self):
00844         self.sourceCmd.selectHandler("YZ")
00845 
00846     def selectCurrentView(self):
00847         self.sourceCmd.selectHandler("currentView")
00848 
00849     def selectResetPlane(self):
00850         self.sourceCmd.selectHandler("reset")
00851 
00852     def undoSegment(self):
00853         "undo last line segment"
00854         self.sourceCmd.undolast()
00855 
00856     def checkSpecialChars(self,txt):
00857         '''
00858         checks for special characters in the entered coords that mut be
00859         treated as shortcuts
00860         '''
00861         spec = False
00862         if txt.endsWith(" ") or txt.endsWith("r"):
00863             self.isRelative.setChecked(not self.isRelative.isChecked())
00864             spec = True
00865         elif txt.endsWith("i"):
00866             if self.hasFill.isVisible():
00867                 self.hasFill.setChecked(not self.hasFill.isChecked())
00868             spec = True
00869         elif txt.endsWith("f"):
00870             if self.finishButton.isVisible():
00871                 self.finish()
00872             spec = True
00873         elif txt.endsWith("w"):
00874             self.wipeLine()
00875         elif txt.endsWith("c"):
00876             if self.closeButton.isVisible():
00877                 self.closeLine()
00878             elif self.isCopy.isVisible():
00879                 self.isCopy.setChecked(not self.isCopy.isChecked())
00880             elif self.continueCmd.isVisible():
00881                 self.continueCmd.setChecked(not self.continueCmd.isChecked())
00882             spec = True
00883         if spec and (not self.taskmode):
00884             for i in [self.xValue,self.yValue,self.zValue]:
00885                 if (i.text() == txt): i.setText("")
00886 
00887     def storeCurrentText(self,qstr):
00888         self.currEditText = self.textValue.text()
00889 
00890     def setCurrentText(self,tstr):
00891         if (not self.taskmode) or (self.taskmode and self.isTaskOn):
00892             self.textValue.setText(tstr)
00893                                                 
00894     def sendText(self):
00895         '''
00896         this function sends the entered text to the active draft command
00897         if enter has been pressed twice. Otherwise it blanks the line.
00898         '''
00899         if self.textline == len(self.textbuffer):
00900             if self.textline:
00901                 if not self.currEditText:
00902                     self.sourceCmd.text=self.textbuffer
00903                     self.sourceCmd.createObject()
00904             self.textbuffer.append(self.currEditText)
00905             self.textline += 1
00906             self.setCurrentText('')
00907         elif self.textline < len(self.textbuffer):
00908             self.textbuffer[self.textline] = self.currEditText
00909             self.textline += 1
00910             if self.textline < len(self.textbuffer):
00911                 self.setCurrentText(self.textbuffer[self.textline])
00912             else:
00913                 self.setCurrentText('')
00914 
00915     def lineUp(self):
00916         "displays previous line in text editor"
00917         if self.textline:
00918             if self.textline == len(self.textbuffer):
00919                 self.textbuffer.append(self.textValue.text())
00920                 self.textline -= 1
00921                 if self.textValue.text():
00922                     self.textValue.setText(self.textbuffer[self.textline])
00923             elif self.textline < len(self.textbuffer):
00924                 self.textbuffer[self.textline] = self.textValue.text()
00925                 self.textline -= 1
00926                 self.textValue.setText(self.textbuffer[self.textline])
00927 
00928     def displayPoint(self, point, last=None, plane=None):
00929         "this function displays the passed coords in the x, y, and z widgets"
00930         dp = point
00931         if self.isRelative.isChecked() and (last != None):
00932             if plane:
00933                 dp = plane.getLocalCoords(FreeCAD.Vector(point.x-last.x, point.y-last.y, point.z-last.z))
00934             else:
00935                 dp = FreeCAD.Vector(point.x-last.x, point.y-last.y, point.z-last.z)
00936         self.xValue.setText("%.2f" % dp.x)
00937         self.yValue.setText("%.2f" % dp.y)
00938         if self.zValue.isEnabled(): self.zValue.setText("%.2f" % dp.z)
00939         if self.xValue.isEnabled():
00940             self.xValue.setFocus()
00941             self.xValue.selectAll()
00942         else:
00943             self.yValue.setFocus()
00944             self.yValue.selectAll()
00945 
00946     def getDefaultColor(self,type,rgb=False):
00947         "gets color from the preferences or toolbar"
00948         if type == "snap":
00949             color = Draft.getParam("snapcolor")
00950             r = ((color>>24)&0xFF)/255
00951             g = ((color>>16)&0xFF)/255
00952             b = ((color>>8)&0xFF)/255
00953         elif type == "ui":
00954             r = float(self.color.red()/255.0)
00955             g = float(self.color.green()/255.0)
00956             b = float(self.color.blue()/255.0)
00957         elif type == "face":
00958             r = float(self.facecolor.red()/255.0)
00959             g = float(self.facecolor.green()/255.0)
00960             b = float(self.facecolor.blue()/255.0)
00961         elif type == "constr":
00962             color = QtGui.QColor(Draft.getParam("constructioncolor")>>8)
00963             r = color.red()/255.0
00964             g = color.green()/255.0
00965             b = color.blue()/255.0
00966         else: print "draft: error: couldn't get a color for ",type," type."
00967         if rgb:
00968             return("rgb("+str(int(r*255))+","+str(int(g*255))+","+str(int(b*255))+")")
00969         else:
00970             return (r,g,b)
00971 
00972     def cross(self,on=True):
00973         if on:
00974             if not self.crossedViews:
00975                 mw = getMainWindow()
00976                 self.crossedViews = mw.findChildren(QtGui.QFrame,"SoQtWidgetName")
00977             for w in self.crossedViews:
00978                 w.setCursor(QtCore.Qt.CrossCursor)
00979         else:
00980             for w in self.crossedViews:
00981                 w.unsetCursor()
00982             self.crossedViews = []
00983 
00984     def toggleConstrMode(self,checked):
00985         self.baseWidget.setStyleSheet("#constrButton:Checked {background-color: "+self.getDefaultColor("constr",rgb=True)+" }")
00986         self.constrMode = checked
00987 
00988     def isConstructionMode(self):
00989         if self.tray or (not self.taskmode):
00990             return self.constrButton.isChecked()
00991         else:
00992             return False
00993 
00994     def drawPage(self):
00995         self.sourceCmd.draw()
00996 
00997     def changePage(self,index):
00998         pagename = str(self.pageBox.itemText(index))
00999         vobj = FreeCADGui.ActiveDocument.getObject(pagename)
01000         if vobj:
01001             self.scaleBox.setEditText(str(vobj.HintScale))
01002             self.marginXValue.setValue(float(vobj.HintOffsetX))
01003             self.marginYValue.setValue(float(vobj.HintOffsetY))
01004 
01005     def selectplane(self):
01006         FreeCADGui.runCommand("Draft_SelectPlane")
01007 
01008     def popupMenu(self,mlist):
01009         "pops up a menu filled with the given list"
01010         self.groupmenu = QtGui.QMenu()
01011         for i in mlist:
01012             self.groupmenu.addAction(i)
01013         pos = getMainWindow().cursor().pos()
01014         self.groupmenu.popup(pos)
01015         QtCore.QObject.connect(self.groupmenu,QtCore.SIGNAL("triggered(QAction *)"),self.popupTriggered)
01016 
01017     def popupTriggered(self,action):
01018         self.sourceCmd.proceed(str(action.text()))
01019 
01020     def setAddMode(self,bool):
01021         if self.addButton.isChecked():
01022             self.delButton.setChecked(False)
01023 
01024     def setDelMode(self,bool):
01025         if self.delButton.isChecked():
01026             self.addButton.setChecked(False)
01027 
01028     def setRadiusValue(self,val):
01029         self.radiusValue.setText("%.2f" % val)
01030         self.radiusValue.setFocus()
01031         self.radiusValue.selectAll()
01032 
01033     def show(self):
01034         if not self.taskmode:
01035             self.draftWidget.setVisible(True)
01036 
01037     def hide(self):
01038         if not self.taskmode:
01039             self.draftWidget.setVisible(False)
01040 
01041     def getXPM(self,iconname,size=16):
01042         i = QtGui.QIcon(":/icons/"+iconname+".svg")
01043         p = i.pixmap(size,size)
01044         a = QtCore.QByteArray()
01045         b = QtCore.QBuffer(a)
01046         b.open(QtCore.QIODevice.WriteOnly)
01047         p.save(b,"XPM")
01048         b.close()
01049         return str(a)
01050 
01051 
01052 #---------------------------------------------------------------------------
01053 # TaskView operations
01054 #---------------------------------------------------------------------------
01055                         
01056     def setWatchers(self):
01057         print "adding draft widgets to taskview..."
01058         class DraftCreateWatcher:
01059             def __init__(self):
01060                 self.commands = ["Draft_Line","Draft_Wire",
01061                                  "Draft_Rectangle","Draft_Arc",
01062                                  "Draft_Circle","Draft_BSpline",
01063                                  "Draft_Text","Draft_Dimension"]
01064                 self.title = "Create objects"
01065             def shouldShow(self):
01066                 return (FreeCAD.ActiveDocument != None) and (not FreeCADGui.Selection.getSelection())
01067 
01068         class DraftModifyWatcher:
01069             def __init__(self):
01070                 self.commands = ["Draft_Move","Draft_Rotate",
01071                                  "Draft_Scale","Draft_Offset",
01072                                  "Draft_Trimex","Draft_Upgrade",
01073                                  "Draft_Downgrade","Draft_Edit",
01074                                  "Draft_Drawing"]
01075                 self.title = "Modify objects"
01076             def shouldShow(self):
01077                 return (FreeCAD.ActiveDocument != None) and (FreeCADGui.Selection.getSelection() != [])
01078                         
01079         class DraftTrayWatcher:
01080             def __init__(self,traywidget):
01081                 self.form = traywidget
01082                 self.widgets = [self.form]
01083             def shouldShow(self):
01084                 return True
01085 
01086         print "setting tray"
01087         self.traywidget = QtGui.QWidget()
01088         self.tray = QtGui.QVBoxLayout(self.traywidget)
01089         self.tray.setObjectName("traylayout")
01090         self.toptray = QtGui.QHBoxLayout()
01091         self.bottomtray = QtGui.QHBoxLayout()
01092         self.tray.addLayout(self.toptray)
01093         self.tray.addLayout(self.bottomtray)
01094         self.setupTray()
01095         self.setupStyle()
01096         w = DraftTrayWatcher(self.traywidget)        
01097         FreeCADGui.Control.addTaskWatcher([w,DraftCreateWatcher(),DraftModifyWatcher()])
01098                                 
01099     def changeEvent(self, event):
01100         if event.type() == QtCore.QEvent.LanguageChange:
01101             print "Language changed!"
01102             self.ui.retranslateUi(self)
01103 
01104     def Activated(self):
01105         if self.taskmode:
01106             self.setWatchers()
01107         else:
01108             self.draftWidget.setVisible(True)
01109             self.draftWidget.toggleViewAction().setVisible(True)
01110 
01111     def Deactivated(self):
01112         if (FreeCAD.activeDraftCommand != None):
01113             FreeCAD.activeDraftCommand.finish()
01114         if self.taskmode:
01115             FreeCADGui.Control.clearTaskWatcher()
01116             self.tray = None
01117         else:
01118             self.draftWidget.setVisible(False)
01119             self.draftWidget.toggleViewAction().setVisible(False)
01120                         
01121 if not hasattr(FreeCADGui,"draftToolBar"):
01122     FreeCADGui.draftToolBar = DraftToolBar()

Generated on Wed Nov 23 19:00:09 2011 for FreeCAD by  doxygen 1.6.1