[wxPython-users] OGL; question about AttachmentPoints

Pierre Hjälm pierre.hjalm at dis.uu.se
Fri Oct 27 01:20:48 PDT 2006


Guenter Dannoritzer <dannoritzer at web.de> writes:

 > Hi,
 > 
 > I tried to figure out how AttachmentPoints are working under OGL and
 > created a small test application that creates a RectangleShape, enables
 > the use of AttachmentPoints, and prints out the AttachmentPoints of that
 > shape.
 > 
 > Here is the respective code snippet:
 > 
 > 
 >   shape2 = ogl.RectangleShape( 70, 40 )
 >   shape2.SetX( 100.0 )
 >   shape2.SetY( 100.0 )
 > 
 >   # Enable the use of AttachmentPoints
 >   shape2.SetAttachmentMode(ogl.ATTACHMENT_MODE_EDGE)
 >   diagram.AddShape( shape2)
 >   self.shapes.append(shape2)
 > 
 >   # Show all AttachmentPoints
 >   print "AttachementMode ", shape2.GetAttachmentMode()
 >   na = shape2.GetNumberOfAttachments()
 >   print "GetNumberOfAttachments ", na
 >   for i in range(na):
 >     print i, shape2.GetAttachmentPosition(i)
 > 
 > 
 > The print out is as follows:
 > 
 > AttachementMode  1
 > GetNumberOfAttachments  4
 > 0 (100.0, 80.0)
 > 1 (135.0, 100.0)
 > 2 (100.0, 120.0)
 > 3 (65.0, 100.0)
 > 
 > So the rectangle shape has by default 4 AttachmentPoints. I looked
 > through the OGL code and the AttachmentPoints are stored in the attribute:
 > 
 >   self._attachmentPoints
 > 
 > Doing a grep search through all of the source files of my wxPython 2.6
 > installation, there is only one place where points are added to that
 > attribute, but only in the class DrawnShape(RectangleShape).
 > 
 > There is not really a SetAttachmentPoints() function nor is there any
 > assignment in the __init__ function of the RectangleShape class or the
 > Shape class, RectangleShape is derived from.
 > 
 > My question is now, where are the AttachmentPoints created for a given
 > shape?
 > 
Well, that's OGL for you; it works in mysterious ways.

You were sort of on the right track, _attachmentPoints is simply not used as is.

Look at GetAttachmentPosition:

        elif self._attachmentMode == ATTACHMENT_MODE_EDGE:
            if len(self._attachmentPoints):
                for point in self._attachmentPoints:
                    if point._id == attachment:
                        return self._xpos + point._x, self._ypos + point._y
                return None
            else:
                # Assume is rectangular
                w, h = self.GetBoundingBoxMax()
                top = self._ypos + h / 2.0
                bottom = self._ypos - h / 2.0
                left = self._xpos - w / 2.0
                right = self._xpos + w / 2.0

                # wtf?
                line and line.IsEnd(self)

                physicalAttachment = self.LogicalToPhysicalAttachment(attachment)

                # Simplified code
                if physicalAttachment == 0:
                    pt = self.CalcSimpleAttachment((left, bottom), (right, bottom), nth, no_arcs, line)
                elif physicalAttachment == 1:
                    pt = self.CalcSimpleAttachment((right, bottom), (right, top), nth, no_arcs, line)
                elif physicalAttachment == 2:
                    pt = self.CalcSimpleAttachment((left, top), (right, top), nth, no_arcs, line)
                elif physicalAttachment == 3:
                    pt = self.CalcSimpleAttachment((left, bottom), (left, top), nth, no_arcs, line)
                else:
                    return None
                return pt[0], pt[1]

Since _attachmentPoints is empty, it uses the other code path and assumes that
it is a rectangular shape.

However, if you were to write your own class, there nothing stopping you
from simply adding to _attachmentPoints. The code is there to handle them.
Although there might well be bugs since it isn't well-used code.

-- 
  Pierre Hjälm - OGL demystifier




More information about the wxpython-users mailing list