2 # Copyright (c) 2002-2004 Art Haas
4 # This file is part of PythonCAD.
6 # PythonCAD is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # PythonCAD is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with PythonCAD; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 # main routine to start Cocoa-based PythonCad
28 import PythonCAD
.Generic
.image
29 import PythonCAD
.Generic
.imageio
30 import PythonCAD
.Generic
.fileio
31 import PythonCAD
.Generic
.selections
32 import PythonCAD
.Generic
.preferences
33 import PythonCAD
.Generic
.color
34 import PythonCAD
.Generic
.linetype
35 import PythonCAD
.Generic
.style
36 import PythonCAD
.Generic
.segment
37 import PythonCAD
.Generic
.circle
38 import PythonCAD
.Generic
.leader
39 import PythonCAD
.Generic
.polyline
40 import PythonCAD
.Generic
.segjoint
41 import PythonCAD
.Generic
.conobject
42 import PythonCAD
.Generic
.baseobject
43 import PythonCAD
.Generic
.dimension
44 import PythonCAD
.Generic
.units
45 import PythonCAD
.Interface
.Cocoa
.ImageDocument
46 import PythonCAD
.Interface
.Cocoa
.CADView
47 import PythonCAD
.Interface
.Cocoa
.AppController
49 from PyObjCTools
import NibClassBuilder
, AppHelper
52 NibClassBuilder
.extractClasses("ImageDocument")
55 # set up global variables ...
58 PythonCAD
.Generic
.globals.prefs
= PythonCAD
.Generic
.baseobject
.LockedDict(str)
59 PythonCAD
.Generic
.globals.colors
= PythonCAD
.Generic
.baseobject
.TypedDict(PythonCAD
.Generic
.color
.Color
,
60 PythonCAD
.Generic
.color
.Color
)
61 PythonCAD
.Generic
.globals.linetypes
= PythonCAD
.Generic
.baseobject
.TypedDict(PythonCAD
.Generic
.linetype
.Linetype
, PythonCAD
.Generic
.linetype
.Linetype
)
62 PythonCAD
.Generic
.globals.styles
= PythonCAD
.Generic
.baseobject
.TypedDict(PythonCAD
.Generic
.style
.Style
,
63 PythonCAD
.Generic
.style
.Style
)
64 PythonCAD
.Generic
.globals.dimstyles
= []
66 PythonCAD
.Generic
.globals.selectobj
= PythonCAD
.Generic
.selections
.Selection()
69 def _initialize_booleans():
70 PythonCAD
.Generic
.globals.prefs
['HIGHLIGHT_POINTS'] = True
71 PythonCAD
.Generic
.globals.prefs
['AUTOSPLIT'] = False
73 def _initialize_sizes():
74 PythonCAD
.Generic
.globals.prefs
['CHAMFER_LENGTH'] = 1.0
75 PythonCAD
.Generic
.globals.prefs
['FILLET_RADIUS'] = 1.0
76 PythonCAD
.Generic
.globals.prefs
['UNITS'] = PythonCAD
.Generic
.units
.MILLIMETERS
77 PythonCAD
.Generic
.globals.prefs
['LEADER_ARROW_SIZE'] = 1.0
79 def _initialize_image_colors():
80 _color
= PythonCAD
.Generic
.color
.get_color(80, 140, 210) # blueish/purpleish
81 PythonCAD
.Generic
.globals.prefs
['INACTIVE_LAYER_COLOR'] = _color
82 _color
= PythonCAD
.Generic
.color
.get_color(0, 0, 0) # black
83 PythonCAD
.Generic
.globals.prefs
['BACKGROUND_COLOR'] = _color
84 _color
= PythonCAD
.Generic
.color
.get_color(255, 255, 0) #yellow
85 PythonCAD
.Generic
.globals.prefs
['SINGLE_POINT_COLOR'] = _color
86 _color
= PythonCAD
.Generic
.color
.get_color(0, 255, 255) #cyan
87 PythonCAD
.Generic
.globals.prefs
['MULTI_POINT_COLOR'] = _color
89 def _initialize_styles():
90 _color
= PythonCAD
.Generic
.color
.get_color(0xff, 0xff, 0xff) # white
91 _lt
= PythonCAD
.Generic
.linetype
.get_linetype_by_dashes(None)
92 _style
= PythonCAD
.Generic
.style
.Style(u
'Solid White Line', _lt
, _color
, 1.0)
93 PythonCAD
.Generic
.globals.styles
[_style
] = _style
94 PythonCAD
.Generic
.globals.prefs
['LINE_STYLE'] = _style
95 PythonCAD
.Generic
.globals.prefs
['LINE_COLOR'] = _style
.getColor()
96 PythonCAD
.Generic
.globals.prefs
['LINE_TYPE'] = _style
.getLinetype()
97 PythonCAD
.Generic
.globals.prefs
['LINE_THICKNESS'] = _style
.getThickness()
99 # set this style as the class default for the "real" drawing entities
101 # fixme: this should be done with a classmethod or some sort of
104 PythonCAD
.Generic
.segment
.Segment
.__defstyle
= _style
105 PythonCAD
.Generic
.circle
.Circle
.__defstyle
= _style
106 PythonCAD
.Generic
.leader
.Leader
.__defstyle
= _style
107 PythonCAD
.Generic
.polyline
.Polyline
.__defstyle
= _style
108 PythonCAD
.Generic
.segjoint
.SegJoint
.__defstyle
= _style
110 _color
= PythonCAD
.Generic
.color
.get_color(0, 0, 0) # black
111 _style
= PythonCAD
.Generic
.style
.Style(u
'Solid Black Line', _lt
, _color
, 1.0)
112 PythonCAD
.Generic
.globals.styles
[_style
] = _style
113 _color
= PythonCAD
.Generic
.color
.get_color(0xff, 0, 0) # red
114 _lt
= PythonCAD
.Generic
.linetype
.get_linetype_by_dashes([4, 1])
115 _style
= PythonCAD
.Generic
.style
.Style(u
'Dashed Red Line', _lt
, _color
, 1.0)
116 PythonCAD
.Generic
.globals.styles
[_style
] = _style
117 _color
= PythonCAD
.Generic
.color
.get_color(0, 0xff, 0) # green
118 _style
= PythonCAD
.Generic
.style
.Style(u
'Dashed Green Line', _lt
, _color
, 1.0)
119 PythonCAD
.Generic
.globals.styles
[_style
] = _style
120 _color
= PythonCAD
.Generic
.color
.get_color(0, 0, 0xff) # blue
121 _style
= PythonCAD
.Generic
.style
.Style(u
'Dashed Blue Line', _lt
, _color
, 1.0)
122 PythonCAD
.Generic
.globals.styles
[_style
] = _style
123 _color
= PythonCAD
.Generic
.color
.get_color(0xff, 0xff, 0) # yellow
124 _lt
= PythonCAD
.Generic
.linetype
.get_linetype_by_dashes([8, 2])
125 _style
= PythonCAD
.Generic
.style
.Style(u
'Dashed Yellow Line', _lt
, _color
, 1.0)
126 PythonCAD
.Generic
.globals.styles
[_style
] = _style
127 _color
= PythonCAD
.Generic
.color
.get_color(0xff, 0, 0xff) # violet
128 _style
= PythonCAD
.Generic
.style
.Style(u
'Dashed Violet Line', _lt
, _color
, 1.0)
129 PythonCAD
.Generic
.globals.styles
[_style
] = _style
130 _color
= PythonCAD
.Generic
.color
.get_color(0, 0xff, 0xff) # cyan
131 _style
= PythonCAD
.Generic
.style
.Style(u
'Dashed Cyan Line', _lt
, _color
, 1.0)
132 PythonCAD
.Generic
.globals.styles
[_style
] = _style
134 # define and set a construction line style
136 _color
= PythonCAD
.Generic
.color
.get_color(0xff, 0, 0) # red
137 _lt
= PythonCAD
.Generic
.linetype
.Linetype(u
'Construction Lines', [2, 2])
138 _style
= PythonCAD
.Generic
.style
.Style(u
'Construction Objects', _lt
, _color
, 0.0)
139 PythonCAD
.Generic
.conobject
.ConstructionObject
.__defstyle
= _style
141 # define and add the default text style and use values in the
142 # text style to define various global key/value pairs
144 _white
= PythonCAD
.Generic
.color
.get_color(0xff, 0xff, 0xff)
145 _ts
= PythonCAD
.Generic
.text
.TextStyle(u
'Default Text Style', color
=_white
)
146 PythonCAD
.Generic
.globals.prefs
['TEXT_STYLE'] = _ts
147 PythonCAD
.Generic
.globals.prefs
['FONT_COLOR'] = _ts
.getColor()
148 PythonCAD
.Generic
.globals.prefs
['FONT_SIZE'] = _ts
.getSize()
149 PythonCAD
.Generic
.globals.prefs
['FONT_WEIGHT'] = _ts
.getWeight()
150 PythonCAD
.Generic
.globals.prefs
['FONT_STYLE'] = _ts
.getStyle()
151 PythonCAD
.Generic
.globals.prefs
['FONT_FAMILY'] = _ts
.getFamily()
153 # define and add the default dimension style and use the
154 # values in that style to define various global preference
158 _dsdict
['DIM_PRIMARY_FONT_COLOR'] = _white
159 _dsdict
['DIM_SECONDARY_FONT_COLOR'] = _white
160 _dimcolor
= PythonCAD
.Generic
.color
.get_color(255, 165, 0) # orangeish
161 _dsdict
['DIM_COLOR'] = _dimcolor
162 _ds
= PythonCAD
.Generic
.dimension
.DimStyle(u
'Default DimStyle', _dsdict
)
163 PythonCAD
.Generic
.globals.dimstyles
.append(_ds
)
164 PythonCAD
.Generic
.globals.prefs
['DIM_STYLE'] = _ds
165 for _key
in _ds
.getOptions():
166 _value
= _ds
.getOption(_key
)
167 PythonCAD
.Generic
.globals.prefs
[_key
] = _value
170 def _initialize_linetypes():
171 _lt
= PythonCAD
.Generic
.linetype
.Linetype(u
'Solid') # solid
172 PythonCAD
.Generic
.globals.linetypes
[_lt
] = _lt
173 _lt
= PythonCAD
.Generic
.linetype
.Linetype(u
'Dash1', [4, 1]) # dashed line
174 PythonCAD
.Generic
.globals.linetypes
[_lt
] = _lt
175 _lt
= PythonCAD
.Generic
.linetype
.Linetype(u
'Dash2', [8, 2]) # dashed line
176 PythonCAD
.Generic
.globals.linetypes
[_lt
] = _lt
177 _lt
= PythonCAD
.Generic
.linetype
.Linetype(u
'Dash3', [12, 2]) # dashed line
178 PythonCAD
.Generic
.globals.linetypes
[_lt
] = _lt
179 _lt
= PythonCAD
.Generic
.linetype
.Linetype(u
'Dash4', [10, 2, 2, 2]) # dashed line
180 PythonCAD
.Generic
.globals.linetypes
[_lt
] = _lt
181 _lt
= PythonCAD
.Generic
.linetype
.Linetype(u
'Dash5', [15, 5, 5, 5]) # dashed line
182 PythonCAD
.Generic
.globals.linetypes
[_lt
] = _lt
184 def _initialize_colors():
185 _color
= PythonCAD
.Generic
.color
.Color(255, 0, 0) # red
186 PythonCAD
.Generic
.globals.colors
[_color
] = _color
187 _color
= PythonCAD
.Generic
.color
.Color(0, 255, 0) # green
188 PythonCAD
.Generic
.globals.colors
[_color
] = _color
189 _color
= PythonCAD
.Generic
.color
.Color(0, 0, 255) # blue
190 PythonCAD
.Generic
.globals.colors
[_color
] = _color
191 _color
= PythonCAD
.Generic
.color
.Color(255, 0, 255) # violet
192 PythonCAD
.Generic
.globals.colors
[_color
] = _color
193 _color
= PythonCAD
.Generic
.color
.Color(255, 255, 0) # yellow
194 PythonCAD
.Generic
.globals.colors
[_color
] = _color
195 _color
= PythonCAD
.Generic
.color
.Color(0, 255, 255) # cyan
196 PythonCAD
.Generic
.globals.colors
[_color
] = _color
197 _color
= PythonCAD
.Generic
.color
.Color(255, 255, 255) # white
198 PythonCAD
.Generic
.globals.colors
[_color
] = _color
199 _color
= PythonCAD
.Generic
.color
.Color(0, 0, 0) # black
200 PythonCAD
.Generic
.globals.colors
[_color
] = _color
202 def _initialize_globals():
204 _initialize_linetypes()
206 _initialize_image_colors()
208 _initialize_booleans()
212 # load up global and user preferences
215 _initialize_globals()
216 PythonCAD
.Generic
.preferences
.initialize_prefs()
217 PythonCAD
.Generic
.preferences
.load_global_prefs()
218 _user_flag
= PythonCAD
.Generic
.globals.prefs
['USER_PREFS']
220 PythonCAD
.Generic
.preferences
.load_user_prefs()
221 PythonCAD
.Generic
.globals.prefs
.lock() # the globals are now set
224 if __name__
== '__main__':
226 AppHelper
.runEventLoop()
228 # need some version checking for OS X - 10.2? 10.3?
229 # _major, _minor, _micro = gtk.pygtk_version
230 # if ((_major < 2) and
231 # (_minor < 100) and #