Draft/InitGui.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 - Init file"
00025 __author__ = "Yorik van Havre <yorik@uncreated.net>"
00026 __url__ = ["http://free-cad.sourceforge.net"]
00027 
00028 import os
00029 
00030 
00031 class DraftWorkbench (Workbench):
00032     "the Draft Workbench"
00033     Icon = """
00034         /* XPM */
00035         static char * draft_xpm[] = {
00036         "14 16 96 2",
00037         "       c None",
00038         ".      c #584605",
00039         "+      c #513E03",
00040         "@      c #E6B50D",
00041         "#      c #C29F0E",
00042         "$      c #6E5004",
00043         "%      c #F7BD0B",
00044         "&      c #8F7008",
00045         "*      c #F3C711",
00046         "=      c #B1950F",
00047         "-      c #785402",
00048         ";      c #946C05",
00049         ">      c #FABF0B",
00050         ",      c #F7C20E",
00051         "'      c #8D740A",
00052         ")      c #F8D115",
00053         "!      c #9F8A0F",
00054         "~      c #593D00",
00055         "{      c #FEB304",
00056         "]      c #F3B208",
00057         "^      c #987407",
00058         "/      c #FDC70E",
00059         "(      c #EFC311",
00060         "_      c #8F790C",
00061         ":      c #FBDA18",
00062         "<      c #8B7C0F",
00063         "[      c #B88203",
00064         "}      c #FEBA08",
00065         "|      c #E7B00A",
00066         "1      c #A17E09",
00067         "2      c #FCCE12",
00068         "3      c #E6C213",
00069         "4      c #96830E",
00070         "5      c #FBE11C",
00071         "6      c #786F0F",
00072         "7      c #CA9406",
00073         "8      c #FDC10B",
00074         "9      c #D8AA0C",
00075         "0      c #AE8E0C",
00076         "a      c #FCD415",
00077         "b      c #DBBF15",
00078         "c      c #A09012",
00079         "d      c #F9E61F",
00080         "e      c #69650E",
00081         "f      c #4B3702",
00082         "g      c #DAA609",
00083         "h      c #CAA50E",
00084         "i      c #BB9D10",
00085         "j      c #FCDB18",
00086         "k      c #CEB817",
00087         "l      c #AB9E15",
00088         "m      c #F2E821",
00089         "n      c #5E5C0E",
00090         "o      c #503D03",
00091         "p      c #E8B60D",
00092         "q      c #CAAF13",
00093         "r      c #C1B218",
00094         "s      c #B6AE19",
00095         "t      c #EAE625",
00096         "u      c #575723",
00097         "v      c #594605",
00098         "w      c #F1C511",
00099         "x      c #AB9510",
00100         "y      c #D7C018",
00101         "z      c #FBE81F",
00102         "A      c #B3AC18",
00103         "B      c #BCB81D",
00104         "C      c #7F8051",
00105         "D      c #645207",
00106         "E      c #9D8C11",
00107         "F      c #E4D31C",
00108         "G      c #BEB62F",
00109         "H      c #6C6A3F",
00110         "I      c #E1E1E1",
00111         "J      c #73610A",
00112         "K      c #7C720F",
00113         "L      c #A1A084",
00114         "M      c #FFFFFF",
00115         "N      c #565656",
00116         "O      c #887921",
00117         "P      c #988F44",
00118         "Q      c #BFBEB7",
00119         "R      c #EEEEEC",
00120         "S      c #C0C0C0",
00121         "T      c #323232",
00122         "U      c #4D4B39",
00123         "V      c #C7C7C7",
00124         "W      c #FBFBFB",
00125         "X      c #BFBFBF",
00126         "Y      c #141414",
00127         "Z      c #222222",
00128         "`      c #303030",
00129         " .     c #313131",
00130         "..     c #282828",
00131         "+.     c #121212",
00132         "@.     c #000000",
00133         "        .                   ",
00134         "      + @ #                 ",
00135         "    $ % & * =               ",
00136         "  - ; > , ' ) !             ",
00137         "~ { ] ^ / ( _ : <           ",
00138         "  [ } | 1 2 3 4 5 6         ",
00139         "    7 8 9 0 a b c d e       ",
00140         "    f g / h i j k l m n     ",
00141         "      o p 2 i q 5 r s t u   ",
00142         "        v w a x y z A B C   ",
00143         "          D ) j E F G H I   ",
00144         "            J : 5 K L M M N ",
00145         "              O P Q R M S T ",
00146         "                U V W X Y Z ",
00147         "                    `  ...+.",
00148         "    @.@.@.@.@.@.@.@.        "};
00149         """
00150 
00151     MenuText = "Draft"
00152     ToolTip = "The Draft module is used for basic 2D CAD Drafting"
00153 
00154     def Initialize(self):
00155         # run self-tests
00156         depsOK = False
00157         try:
00158             from pivy import coin
00159             if FreeCADGui.getSoDBVersion() != coin.SoDB.getVersion():
00160                 raise AssertionError("FreeCAD and Pivy use different versions of Coin. This will lead to unexpected behaviour.")
00161         except AssertionError:
00162             FreeCAD.Console.PrintWarning("Error: FreeCAD and Pivy use different versions of Coin. This will lead to unexpected behaviour.\n")
00163         except ImportError:
00164             FreeCAD.Console.PrintWarning("Error: Pivy not found, Draft workbench will be disabled.\n")
00165         except:
00166             FreeCAD.Console.PrintWarning("Error: Unknown error while trying to load Pivy\n")
00167         else:
00168             try:
00169                 import PyQt4
00170             except ImportError:
00171                 FreeCAD.Console.PrintWarning("Error: PyQt4 not found, Draft workbench will be disabled.\n")
00172             else:
00173                 depsOK = True
00174                 
00175         if depsOK:
00176             import Draft_rc
00177             FreeCADGui.addLanguagePath(":/translations")
00178             FreeCADGui.addIconPath(":/icons")
00179             FreeCADGui.addPreferencePage(":/ui/userprefs-base.ui","Draft")
00180             FreeCADGui.addPreferencePage(":/ui/userprefs-import.ui","Draft")
00181         else:
00182             return
00183         Log ('Loading Draft GUI...\n')
00184         try:
00185             import draftTools,draftGui,macros
00186             self.appendMenu(["&Macro","Installed Macros"],macros.macrosList)
00187         except:
00188             pass
00189         self.cmdList = ["Draft_Line","Draft_Wire","Draft_Circle","Draft_Arc",
00190                         "Draft_Polygon","Draft_Rectangle", "Draft_Text",
00191                         "Draft_Dimension", "Draft_BSpline"]
00192         self.modList = ["Draft_Move","Draft_Rotate","Draft_Offset",
00193                         "Draft_Trimex", "Draft_Upgrade", "Draft_Downgrade", "Draft_Scale",
00194                         "Draft_Drawing","Draft_Edit","Draft_WireToBSpline","Draft_AddPoint",
00195                         "Draft_DelPoint","Draft_Shape2DView"]
00196         self.treecmdList = ["Draft_ApplyStyle","Draft_ToggleDisplayMode","Draft_AddToGroup","Draft_SelectGroup"]
00197         self.lineList = ["Draft_UndoLine","Draft_FinishLine","Draft_CloseLine"]
00198         self.appendToolbar("Draft tools",self.cmdList+self.modList)
00199         self.appendMenu("Draft",self.cmdList+self.modList)
00200         self.appendMenu(["Draft","Display options"],self.treecmdList)
00201         self.appendMenu(["Draft","Wire tools"],self.lineList)
00202                                         
00203     def Activated(self):
00204         FreeCADGui.draftToolBar.Activated()
00205 
00206     def Deactivated(self):
00207         FreeCADGui.draftToolBar.Deactivated()
00208 
00209     def ContextMenu(self, recipient):
00210         if (recipient == "View"):
00211             if (FreeCAD.activeDraftCommand == None):
00212                 if (FreeCADGui.Selection.getSelection() != []):
00213                     self.appendContextMenu("Draft",self.cmdList+self.modList)
00214                     self.appendContextMenu("Display options",self.treecmdList)
00215                 else:
00216                     self.appendContextMenu("Draft",self.cmdList)
00217             else:
00218                 if (FreeCAD.activeDraftCommand.featureName == "Line"):
00219                     self.appendContextMenu("",self.lineList)
00220         else:
00221             if (FreeCADGui.Selection.getSelection() != []):
00222                 self.appendContextMenu("Display options",self.treecmdList)
00223 
00224     def GetClassName(self): 
00225         return "Gui::PythonWorkbench"
00226 
00227 FreeCADGui.addWorkbench(DraftWorkbench)
00228 App.addImportType("Autodesk DXF (*.dxf)","importDXF") 
00229 App.addImportType("SVG as geometry (*.svg)","importSVG")
00230 App.addImportType("Open CAD Format (*.oca *.gcad)","importOCA")
00231 App.addImportType("Common airfoil data (*.dat)","importAirfoilDAT")
00232 App.addExportType("Autodesk DXF (*.dxf)","importDXF")
00233 App.addExportType("Flattened SVG (*.svg)","importSVG")
00234 App.addExportType("Open CAD Format (*.oca)","importOCA")
00235 

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