[PythonCAD] [PATCH] Save and restore autosplitting value in layer.py

Art Haas ahaas at airmail.net
Tue May 23 00:54:28 CEST 2006


Hi.

The patch below addresses a problem I found regarding the newly added
autosplitting code. The issue was that a layer would be set to not
perform any autosplitting regardless of what the checkbox in the
Preferences dialog setting.

By default, autosplitting is off when the program starts unless you
install the 'prefs.py' file into /etc/pythoncad and set Autosplit
to True. I'd done that on my development machine, so I didn't see
this problem until running PythonCAD on another machine where
the default autosplit value was still False. Now, when an object
is added to the Layer, the object invokes its setParent() method
to store the Layer as the parent entity. If the newly added object
is a Point, the Image instance containing the Layer will call
the setAutosplit() method of the Layer, and it is at this point
that things break because the autosplitting state variable the
Layer examines - self.__asplit in the code below - gets set
to False and never toggled back to the True value. So, the Layer
ends up never performing autosplitting.

The patch below saves the autosplit state value before the call
to setParent(), and then restores this value at the end of the
routine.

Sorry I didn't catch this prior to the release. The patch below
has been checked into my repo and sent to the public repo so it
is also available via 'svn update'.

Art

Index: PythonCAD/Generic/layer.py
===================================================================
--- PythonCAD/Generic/layer.py	(revision 2319)
+++ PythonCAD/Generic/layer.py	(revision 2320)
@@ -531,6 +531,11 @@
             self.__objects[id(obj)] = obj
             _oid = obj.getID()
             self.__objids[_oid] = obj
+            #
+            # save the autosplit state before calling setParent()
+            # as the value could change
+            #
+            _as = self.__asplit
             obj.setParent(self)
             _log = obj.getLog()
             if _log is not None: # make this an error?
@@ -573,6 +578,10 @@
                         _split, _sobjs = self.__splitObject(_mobj, obj)
                         if _split and len(_sobjs):
                             self.delObject(_mobj)
+            #
+            # restore autosplit state
+            #
+            self.__asplit = _as
 
     def __addPoint(self, p):
         """Add a Point object to the Layer.
-- 
Man once surrendering his reason, has no remaining guard against absurdities
the most monstrous, and like a ship without rudder, is the sport of every wind.

-Thomas Jefferson to James Smith, 1822


More information about the PythonCAD mailing list