2 # Copyright (c) 2002, 2003, 2004, 2006 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
24 from PythonCAD
.Generic
.point
import Point
25 from PythonCAD
.Generic
.segment
import Segment
26 from PythonCAD
.Generic
.circle
import Circle
27 from PythonCAD
.Generic
.arc
import Arc
28 from PythonCAD
.Generic
.hcline
import HCLine
29 from PythonCAD
.Generic
.vcline
import VCLine
30 from PythonCAD
.Generic
.acline
import ACLine
31 from PythonCAD
.Generic
.segjoint
import Chamfer
, Fillet
32 from PythonCAD
.Generic
.cline
import CLine
33 from PythonCAD
.Generic
.ccircle
import CCircle
34 from PythonCAD
.Generic
.leader
import Leader
35 from PythonCAD
.Generic
.polyline
import Polyline
36 from PythonCAD
.Generic
.text
import TextBlock
37 from PythonCAD
.Generic
.dimension
import DimString
38 from PythonCAD
.Generic
.layer
import Layer
40 def delete_objects(objlist
):
41 """Remove a list of objects from the parent Layer.
43 delete_objects(objlist)
45 The objlist argument must be either a tuple or list.
47 if not isinstance(objlist
, (list, tuple)):
48 raise TypeError, "Invalid object list: " + `
type(objlist
)`
51 if not isinstance(_obj
, DimString
):
52 _parent
= _obj
.getParent()
53 if _parent
is not None and isinstance(_parent
, Layer
):
57 _objdict
[id(_obj
)] = True
59 if isinstance(_obj
, Point
):
61 elif isinstance(_obj
, Segment
):
62 _p1
, _p2
= _obj
.getEndpoints()
65 _objdict
[_pid
] = False
68 _objdict
[_pid
] = False
69 elif isinstance(_obj
, Arc
):
70 _cp
= _obj
.getCenter()
73 _objdict
[_pid
] = False
74 _parent
= _obj
.getParent()
75 for _ep
in _obj
.getEndpoints():
77 _pts
= _parent
.find('point', _ep
[0], _ep
[1])
79 for _user
in _pt
.getUsers():
84 raise RuntimeError, "Arc endpoint missing: " + str(_ep
)
87 _objdict
[_pid
] = False
88 elif isinstance(_obj
, (Circle
, CCircle
)):
89 _cp
= _obj
.getCenter()
92 _objdict
[_pid
] = False
93 elif isinstance(_obj
, (HCLine
, VCLine
, ACLine
)):
94 _lp
= _obj
.getLocation()
97 _objdict
[_pid
] = False
98 elif isinstance(_obj
, CLine
):
99 _p1
, _p2
= _obj
.getKeypoints()
102 _objdict
[_pid
] = False
105 _objdict
[_pid
] = False
106 elif isinstance(_obj
, (Chamfer
, Fillet
)):
107 continue # chamfers/fillets do not delete attached segments
108 elif isinstance(_obj
, (Leader
, Polyline
)):
109 for _pt
in _obj
.getPoints():
112 _objdict
[_pid
] = False
113 elif isinstance(_obj
, TextBlock
):
117 for _obj
in _delobjs
:
118 if _objdict
[id(_obj
)]:
119 _parent
= _obj
.getParent()
121 # if the parent is None then the object has already been
122 # deleted as a result of earlier deletions such as a
123 # dimension being removed when the referenced points were
126 if _parent
is not None:
127 _parent
.delObject(_obj
)