[PythonCAD] Patches to highlight selected objects

Art Haas ahaas at airmail.net
Mon Oct 24 19:32:17 CEST 2005


On Sat, Oct 22, 2005 at 11:06:10AM -0400, Stuart Brorson wrote:
> Hi PythonCADsters --
>
> I have made some mods to PythonCAD in order to implement highlighting
> after selection.  That is, my mods change PythonCAD's behavior so that
> when you select a graphic object, it turns white.  This sees to be the
> desired behavior for selection.  I have submitted the patches to Art
> in a separate e-mail.  The diff is against the the latest svn version
> (updated yesterday -- Friday, Oct 21st, 2005).
>  
> Please read about the detailed mods and some other discussion points
> below.
>  
> Code modifications made:
> [ ... snip ... ]

I'll make comments about the changes in another mail. I want to
address some of the comments below.

> Discussion:
>  
> *  My method to set the color upon selection/deselection is a hack.
> This needs to be fixed. I propose that all graphic objects have an
> attribute __default_color.  This can be set in GraphicObject, and
> overridden in the individual classes.  Then, when you select an
> object, it can go white ("obj.setColor(0xffffff)").  When you deselect
> an object, it can revert to its normal default color by
> ("obj.setColor(obj.__default_color)").

Entities do have a default color already - it is part of their default
style. The Style gives them a default color, linetype, and thickness.
See the 'graphicobject.py' file for the default. Entities like Segments,
Circles, etc. that are subclasses of the GraphicObject class can
override the Style values set in GraphicObject.__defstyle by extending
the setStyle() method. Look at Segment::setStyle() as an example. If the
argument to setStyle() is 'None', the Segment.__defstyle value is used
as an argument to GraphicObject::setStyle.

Any GraphicObject entity that has had its color changed from that given
in its default Style can restore the Style color by calling setColor()
without an argument. See the GraphicObject setColor() and getColor()
methods for the details as to how things work.

> *  Sending the signal "color_changed" has the problem that it invokes
> the graphicObjectLog class to store the last color.  When doing a highlight,
> it makes no sense to store the last color.  Therefore, I propose to
> create a different message "highlighted" which will not cause the
> graphicObjectLog class to wake up.
>  
> *  One issue with the current architecture is that the point class
> inherits from Subpart, not from Graphic object.  The issue is that the
> color attribute is set in GraphicObject, so a point doesn't have a
> color, and doesn't have color methods.  I overcame this by
> implementing dummy color methods in the point class, but this is a
> hack.
>  
>    Is there a reason that point can't inherit from GraphicObject?  And
> what distinction is made between GraphicObject and Subpart and Entity?

A GraphicObject is something that has an associated linetype and
thickness as well as a color. Point entities don't have any thickness
nor would they need a Linetype, so when I set things up I made the Point
class be a Subclass of the Subpart class.

The idea behind the Subpart class was to provide a class of Entities
that are used as components in more complex entities. A Segment, for
example, requires two Point entities, so each point is a Subpart of the
Segment. When hatching ever arrives in PythonCAD, I'd expect that
Segments, Circles, and Arcs will all be Subparts of a Hatch entity.
I'd thought at one time about trying to use a parent/child relationship
for expressing the connectivity between entities, but it seemed to be
more useful to use the parent/child idea as a means of expressing which
entities are stored in a Layer, and what Layers are in an Image. This
technique allows for a quick means of testing for entities in an Image.

> *  After doing this I noticed that "Edit -> Select" doesn't do
> anything.  That is, when you try to move an object, you do "Modify ->
> Move -> Horizontal", and you thereafter need to select the objects to
> move.  What is the point behind "Edit -> Select" anyway?  Does it do
> anything?

It puts the program into entity selection mode. Draw a couple of
segments, then do 'Edit'->'Select'. You can then click on each segment
or box some/all of them them, then go to 'Modify'->'Change' and you can
change the selected entity Style, Linetype, Color, or Thickness.

> I propose that any "Modify" actions should use the selected parts,
> instead of requiring the user to re-select the parts to modify.

The CAD package I used at my old job was structured so that move/stretch
type operations were done where the displacement was specfied prior
to selecting which entities to apply the operation upon, so that
behavior is why things are coded like they are now. It isn't consisent,
though, for some operations to be performed by first selecting entities
and then choosing some operation, while other tasks require selecting an
operation and then choosing entities.

Art
-- 
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