]> git.saurik.com Git - wxWidgets.git/blobdiff - utils/ogl/src/basic.cpp
accidentally removed IMPLEMENT_DYNAMIC_CLASS added back
[wxWidgets.git] / utils / ogl / src / basic.cpp
index 5a8b417ee39099f6887d4ecbd12fa37f61c98556..4faa13292579f860bb6060cc25c8bf65a642099c 100644 (file)
 #include <wx/wx.h>
 #endif
 
 #include <wx/wx.h>
 #endif
 
-#ifdef PROLOGIO
 #include <wx/wxexpr.h>
 #include <wx/wxexpr.h>
-#endif
 
 
-#if USE_IOSTREAMH
+#if wxUSE_IOSTREAMH
 #include <iostream.h>
 #else
 #include <iostream>
 #include <iostream.h>
 #else
 #include <iostream>
@@ -127,6 +125,12 @@ void wxShapeEvtHandler::OnDrawContents(wxDC& dc)
     m_previousHandler->OnDrawContents(dc);
 }
 
     m_previousHandler->OnDrawContents(dc);
 }
 
+void wxShapeEvtHandler::OnDrawBranches(wxDC& dc, bool erase)
+{
+  if (m_previousHandler)
+    m_previousHandler->OnDrawBranches(dc, erase);
+}
+
 void wxShapeEvtHandler::OnSize(double x, double y)
 {
   if (m_previousHandler)
 void wxShapeEvtHandler::OnSize(double x, double y)
 {
   if (m_previousHandler)
@@ -171,6 +175,12 @@ void wxShapeEvtHandler::OnLeftClick(double x, double y, int keys, int attachment
     m_previousHandler->OnLeftClick(x, y, keys, attachment);
 }
 
     m_previousHandler->OnLeftClick(x, y, keys, attachment);
 }
 
+void wxShapeEvtHandler::OnLeftDoubleClick(double x, double y, int keys, int attachment)
+{
+  if (m_previousHandler)
+    m_previousHandler->OnLeftDoubleClick(x, y, keys, attachment);
+}
+
 void wxShapeEvtHandler::OnRightClick(double x, double y, int keys, int attachment)
 {
   if (m_previousHandler)
 void wxShapeEvtHandler::OnRightClick(double x, double y, int keys, int attachment)
 {
   if (m_previousHandler)
@@ -276,7 +286,7 @@ wxShape::wxShape(wxShapeCanvas *can)
   m_visible = FALSE;
   m_clientData = NULL;
   m_selected = FALSE;
   m_visible = FALSE;
   m_clientData = NULL;
   m_selected = FALSE;
-  m_attachmentMode = FALSE;
+  m_attachmentMode = ATTACHMENT_MODE_NONE;
   m_spaceAttachments = TRUE;
   m_disableLabel = FALSE;
   m_fixedWidth = FALSE;
   m_spaceAttachments = TRUE;
   m_disableLabel = FALSE;
   m_fixedWidth = FALSE;
@@ -287,16 +297,20 @@ wxShape::wxShape(wxShapeCanvas *can)
   m_parent = NULL;
   m_formatMode = FORMAT_CENTRE_HORIZ | FORMAT_CENTRE_VERT;
   m_shadowMode = SHADOW_NONE;
   m_parent = NULL;
   m_formatMode = FORMAT_CENTRE_HORIZ | FORMAT_CENTRE_VERT;
   m_shadowMode = SHADOW_NONE;
-  m_shadowOffsetX = 6.0;
-  m_shadowOffsetY = 6.0;
+  m_shadowOffsetX = 6;
+  m_shadowOffsetY = 6;
   m_shadowBrush = wxBLACK_BRUSH;
   m_shadowBrush = wxBLACK_BRUSH;
-  m_textMarginX = 5.0;
-  m_textMarginY = 5.0;
+  m_textMarginX = 5;
+  m_textMarginY = 5;
   m_regionName = "0";
   m_centreResize = TRUE;
   m_maintainAspectRatio = FALSE;
   m_highlighted = FALSE;
   m_rotation = 0.0;
   m_regionName = "0";
   m_centreResize = TRUE;
   m_maintainAspectRatio = FALSE;
   m_highlighted = FALSE;
   m_rotation = 0.0;
+  m_branchNeckLength = 10;
+  m_branchStemLength = 10;
+  m_branchSpacing = 10;
+  m_branchStyle = BRANCHING_ATTACHMENT_NORMAL;
 
   // Set up a default region. Much of the above will be put into
   // the region eventually (the duplication is for compatibility)
 
   // Set up a default region. Much of the above will be put into
   // the region eventually (the duplication is for compatibility)
@@ -541,7 +555,6 @@ bool wxShape::HitTest(double x, double y, int *attachment, double *distance)
 
   int nearest_attachment = 0;
 
 
   int nearest_attachment = 0;
 
-
   // If within the bounding box, check the attachment points
   // within the object.
 
   // If within the bounding box, check the attachment points
   // within the object.
 
@@ -550,10 +563,13 @@ bool wxShape::HitTest(double x, double y, int *attachment, double *distance)
     int n = GetNumberOfAttachments();
     double nearest = 999999.0;
 
     int n = GetNumberOfAttachments();
     double nearest = 999999.0;
 
+    // GetAttachmentPosition[Edge] takes a logical attachment position,
+    // i.e. if it's rotated through 90%, position 0 is East-facing.
+
     for (int i = 0; i < n; i++)
     {
       double xp, yp;
     for (int i = 0; i < n; i++)
     {
       double xp, yp;
-      if (GetAttachmentPosition(i, &xp, &yp))
+      if (GetAttachmentPositionEdge(i, &xp, &yp))
       {
         double l = (double)sqrt(((xp - x) * (xp - x)) +
                    ((yp - y) * (yp - y)));
       {
         double l = (double)sqrt(((xp - x) * (xp - x)) +
                    ((yp - y) * (yp - y)));
@@ -1038,7 +1054,8 @@ void wxShape::DrawLinks(wxDC& dc, int attachment, bool recurse)
 // This is the default, rectangular implementation.
 bool wxShape::AttachmentSortTest(int attachmentPoint, const wxRealPoint& pt1, const wxRealPoint& pt2)
 {
 // This is the default, rectangular implementation.
 bool wxShape::AttachmentSortTest(int attachmentPoint, const wxRealPoint& pt1, const wxRealPoint& pt2)
 {
-    switch (attachmentPoint)
+    int physicalAttachment = LogicalToPhysicalAttachment(attachmentPoint);
+    switch (physicalAttachment)
     {
         case 0:
         case 2:
     {
         case 0:
         case 2:
@@ -1060,7 +1077,7 @@ bool wxShape::AttachmentSortTest(int attachmentPoint, const wxRealPoint& pt1, co
 bool wxShape::MoveLineToNewAttachment(wxDC& dc, wxLineShape *to_move,
                                        double x, double y)
 {
 bool wxShape::MoveLineToNewAttachment(wxDC& dc, wxLineShape *to_move,
                                        double x, double y)
 {
-  if (!GetAttachmentMode())
+  if (GetAttachmentMode() == ATTACHMENT_MODE_NONE)
       return FALSE;
 
   int newAttachment, oldAttachment;
       return FALSE;
 
   int newAttachment, oldAttachment;
@@ -1502,6 +1519,7 @@ void wxShape::Draw(wxDC& dc)
     GetEventHandler()->OnDraw(dc);
     GetEventHandler()->OnDrawContents(dc);
     GetEventHandler()->OnDrawControlPoints(dc);
     GetEventHandler()->OnDraw(dc);
     GetEventHandler()->OnDrawContents(dc);
     GetEventHandler()->OnDrawControlPoints(dc);
+    GetEventHandler()->OnDrawBranches(dc);
   }
 }
 
   }
 }
 
@@ -1535,6 +1553,7 @@ void wxShape::Erase(wxDC& dc)
 {
   GetEventHandler()->OnErase(dc);
   GetEventHandler()->OnEraseControlPoints(dc);
 {
   GetEventHandler()->OnErase(dc);
   GetEventHandler()->OnEraseControlPoints(dc);
+  GetEventHandler()->OnDrawBranches(dc, TRUE);
 }
 
 void wxShape::EraseContents(wxDC& dc)
 }
 
 void wxShape::EraseContents(wxDC& dc)
@@ -1758,6 +1777,14 @@ void wxShape::WriteAttributes(wxExpr *clause)
   if (m_rotation != 0.0)
     clause->AddAttributeValue("rotation", m_rotation);
 
   if (m_rotation != 0.0)
     clause->AddAttributeValue("rotation", m_rotation);
 
+  if (!this->IsKindOf(CLASSINFO(wxLineShape)))
+  {
+    clause->AddAttributeValue("neck_length", (long) m_branchNeckLength);
+    clause->AddAttributeValue("stem_length", (long) m_branchStemLength);
+    clause->AddAttributeValue("branch_spacing", (long) m_branchSpacing);
+    clause->AddAttributeValue("branch_style", (long) m_branchStyle);
+  }
+
   // Write user-defined attachment points, if any
   if (m_attachmentPoints.Number() > 0)
   {
   // Write user-defined attachment points, if any
   if (m_attachmentPoints.Number() > 0)
   {
@@ -1798,8 +1825,8 @@ void wxShape::WriteRegions(wxExpr *clause)
     // region1 = (regionName regionText x y width height minWidth minHeight proportionX proportionY
     //            formatMode fontSize fontFamily fontStyle fontWeight textColour)
     wxExpr *regionExpr = new wxExpr(wxExprList);
     // region1 = (regionName regionText x y width height minWidth minHeight proportionX proportionY
     //            formatMode fontSize fontFamily fontStyle fontWeight textColour)
     wxExpr *regionExpr = new wxExpr(wxExprList);
-    regionExpr->Append(new wxExpr(wxExprString, (region->m_regionName ? region->m_regionName : "")));
-    regionExpr->Append(new wxExpr(wxExprString, (region->m_regionText ? region->m_regionText : "")));
+    regionExpr->Append(new wxExpr(wxExprString, region->m_regionName));
+    regionExpr->Append(new wxExpr(wxExprString, region->m_regionText));
 
     regionExpr->Append(new wxExpr(region->m_x));
     regionExpr->Append(new wxExpr(region->m_y));
 
     regionExpr->Append(new wxExpr(region->m_x));
     regionExpr->Append(new wxExpr(region->m_y));
@@ -1817,10 +1844,10 @@ void wxShape::WriteRegions(wxExpr *clause)
     regionExpr->Append(new wxExpr((long)(region->m_font ? region->m_font->GetFamily() : wxDEFAULT)));
     regionExpr->Append(new wxExpr((long)(region->m_font ? region->m_font->GetStyle() : wxDEFAULT)));
     regionExpr->Append(new wxExpr((long)(region->m_font ? region->m_font->GetWeight() : wxNORMAL)));
     regionExpr->Append(new wxExpr((long)(region->m_font ? region->m_font->GetFamily() : wxDEFAULT)));
     regionExpr->Append(new wxExpr((long)(region->m_font ? region->m_font->GetStyle() : wxDEFAULT)));
     regionExpr->Append(new wxExpr((long)(region->m_font ? region->m_font->GetWeight() : wxNORMAL)));
-    regionExpr->Append(new wxExpr(wxExprString, region->m_textColour ? region->m_textColour : "BLACK"));
+    regionExpr->Append(new wxExpr(wxExprString, region->m_textColour));
 
     // New members for pen colour/style
 
     // New members for pen colour/style
-    regionExpr->Append(new wxExpr(wxExprString, region->m_penColour ? region->m_penColour : "BLACK"));
+    regionExpr->Append(new wxExpr(wxExprString, region->m_penColour));
     regionExpr->Append(new wxExpr((long)region->m_penStyle));
 
     // Formatted text:
     regionExpr->Append(new wxExpr((long)region->m_penStyle));
 
     // Formatted text:
@@ -1880,8 +1907,8 @@ void wxShape::ReadAttributes(wxExpr *clause)
       else if (string_expr->Type() == wxExprList)
       {
         wxExpr *first = string_expr->value.first;
       else if (string_expr->Type() == wxExprList)
       {
         wxExpr *first = string_expr->value.first;
-        wxExpr *second = first ? first->next : NULL;
-        wxExpr *third = second ? second->next : NULL;
+        wxExpr *second = first ? first->next : (wxExpr*) NULL;
+        wxExpr *third = second ? second->next : (wxExpr*) NULL;
 
         if (first && second && third &&
             (first->Type() == wxExprReal || first->Type() == wxExprInteger) &&
 
         if (first && second && third &&
             (first->Type() == wxExprReal || first->Type() == wxExprInteger) &&
@@ -1912,7 +1939,7 @@ void wxShape::ReadAttributes(wxExpr *clause)
   int pen_width = 1;
   int pen_style = wxSOLID;
   int brush_style = wxSOLID;
   int pen_width = 1;
   int pen_style = wxSOLID;
   int brush_style = wxSOLID;
-  m_attachmentMode = FALSE;
+  m_attachmentMode = ATTACHMENT_MODE_NONE;
 
   clause->GetAttributeValue("pen_colour", pen_string);
   clause->GetAttributeValue("text_colour", m_textColourName);
 
   clause->GetAttributeValue("pen_colour", pen_string);
   clause->GetAttributeValue("text_colour", m_textColourName);
@@ -1928,7 +1955,7 @@ void wxShape::ReadAttributes(wxExpr *clause)
 
   int iVal = (int) m_attachmentMode;
   clause->GetAttributeValue("use_attachments", iVal);
 
   int iVal = (int) m_attachmentMode;
   clause->GetAttributeValue("use_attachments", iVal);
-  m_attachmentMode = (iVal != 0);
+  m_attachmentMode = iVal;
 
   clause->GetAttributeValue("sensitivity", m_sensitivity);
 
 
   clause->GetAttributeValue("sensitivity", m_sensitivity);
 
@@ -1947,6 +1974,20 @@ void wxShape::ReadAttributes(wxExpr *clause)
   clause->GetAttributeValue("format_mode", m_formatMode);
   clause->GetAttributeValue("shadow_mode", m_shadowMode);
 
   clause->GetAttributeValue("format_mode", m_formatMode);
   clause->GetAttributeValue("shadow_mode", m_shadowMode);
 
+  iVal = m_branchNeckLength;
+  clause->GetAttributeValue("neck_length", iVal);
+  m_branchNeckLength = iVal;
+
+  iVal = m_branchStemLength;
+  clause->GetAttributeValue("stem_length", iVal);
+  m_branchStemLength = iVal;
+
+  iVal = m_branchSpacing;
+  clause->GetAttributeValue("branch_spacing", iVal);
+  m_branchSpacing = iVal;
+
+  clause->GetAttributeValue("branch_style", m_branchStyle);
+
   iVal = (int) m_centreResize;
   clause->GetAttributeValue("centre_resize", iVal);
   m_centreResize = (iVal != 0);
   iVal = (int) m_centreResize;
   clause->GetAttributeValue("centre_resize", iVal);
   m_centreResize = (iVal != 0);
@@ -2035,7 +2076,7 @@ void wxShape::ReadRegions(wxExpr *clause)
 
   m_formatted = TRUE;  // Assume text is formatted unless we prove otherwise
 
 
   m_formatted = TRUE;  // Assume text is formatted unless we prove otherwise
 
-  while (regionExpr = clause->AttributeValue(regionNameBuf))
+  while ((regionExpr = clause->AttributeValue(regionNameBuf)))
   {
     /*
      * Get the region information
   {
     /*
      * Get the region information
@@ -2159,8 +2200,8 @@ void wxShape::ReadRegions(wxExpr *clause)
         else if (string_expr->Type() == wxExprList)
         {
           wxExpr *first = string_expr->value.first;
         else if (string_expr->Type() == wxExprList)
         {
           wxExpr *first = string_expr->value.first;
-          wxExpr *second = first ? first->next : NULL;
-          wxExpr *third = second ? second->next : NULL;
+          wxExpr *second = first ? first->next : (wxExpr*) NULL;
+          wxExpr *third = second ? second->next : (wxExpr*) NULL;
 
           if (first && second && third &&
               (first->Type() == wxExprReal || first->Type() == wxExprInteger) &&
 
           if (first && second && third &&
               (first->Type() == wxExprReal || first->Type() == wxExprInteger) &&
@@ -2251,6 +2292,10 @@ void wxShape::Copy(wxShape& copy)
   copy.m_shadowOffsetY = m_shadowOffsetY;
   copy.m_shadowBrush = m_shadowBrush;
 
   copy.m_shadowOffsetY = m_shadowOffsetY;
   copy.m_shadowBrush = m_shadowBrush;
 
+  copy.m_branchNeckLength = m_branchNeckLength;
+  copy.m_branchStemLength = m_branchStemLength;
+  copy.m_branchSpacing = m_branchSpacing;
+
   // Copy text regions
   copy.ClearRegions();
   wxNode *node = m_regions.First();
   // Copy text regions
   copy.ClearRegions();
   wxNode *node = m_regions.First();
@@ -2631,12 +2676,20 @@ bool wxShape::AttachmentIsValid(int attachment) const
 bool wxShape::GetAttachmentPosition(int attachment, double *x, double *y, 
                                          int nth, int no_arcs, wxLineShape *line)
 {
 bool wxShape::GetAttachmentPosition(int attachment, double *x, double *y, 
                                          int nth, int no_arcs, wxLineShape *line)
 {
-    if (!m_attachmentMode)
+    if (m_attachmentMode == ATTACHMENT_MODE_NONE)
     {
         *x = m_xpos; *y = m_ypos;
         return TRUE;
     }
     {
         *x = m_xpos; *y = m_ypos;
         return TRUE;
     }
-    else
+    else if (m_attachmentMode == ATTACHMENT_MODE_BRANCHING)
+    {
+        wxRealPoint pt, stemPt;
+        GetBranchingAttachmentPoint(attachment, nth, pt, stemPt);
+        *x = pt.x;
+        *y = pt.y;
+        return TRUE;
+    }
+    else if (m_attachmentMode == ATTACHMENT_MODE_EDGE)
     {
         if (m_attachmentPoints.Number() > 0)
         {
     {
         if (m_attachmentPoints.Number() > 0)
         {
@@ -2667,8 +2720,10 @@ bool wxShape::GetAttachmentPosition(int attachment, double *x, double *y,
 
             bool isEnd = (line && line->IsEnd(this));
 
 
             bool isEnd = (line && line->IsEnd(this));
 
+            int physicalAttachment = LogicalToPhysicalAttachment(attachment);
+
             // Simplified code
             // Simplified code
-            switch (attachment)
+            switch (physicalAttachment)
             {
                 case 0:
                 {
             {
                 case 0:
                 {
@@ -2704,7 +2759,7 @@ bool wxShape::GetAttachmentPosition(int attachment, double *x, double *y,
                 }
                 default:
                 {
                 }
                 default:
                 {
-                    return wxShape::GetAttachmentPosition(attachment, x, y, nth, no_arcs, line);
+                    return FALSE;
                     break;
                 }
             }
                     break;
                 }
             }
@@ -2855,3 +2910,365 @@ int wxShape::GetLinePosition(wxLineShape* line)
     return 0;
 }
 
     return 0;
 }
 
+//
+//             |________|
+//                 | <- root
+//                 | <- neck
+// shoulder1 ->---------<- shoulder2
+//             | | | | |
+//                      <- branching attachment point N-1
+
+// This function gets information about where branching connections go.
+// Returns FALSE if there are no lines at this attachment.
+bool wxShape::GetBranchingAttachmentInfo(int attachment, wxRealPoint& root, wxRealPoint& neck,
+    wxRealPoint& shoulder1, wxRealPoint& shoulder2)
+{
+    int physicalAttachment = LogicalToPhysicalAttachment(attachment);
+
+    // Number of lines at this attachment.
+    int lineCount = GetAttachmentLineCount(attachment);
+
+    if (lineCount == 0)
+        return FALSE;
+
+    int totalBranchLength = m_branchSpacing * (lineCount - 1);
+
+    root = GetBranchingAttachmentRoot(attachment);
+
+    // Assume that we have attachment points 0 to 3: top, right, bottom, left.
+    switch (physicalAttachment)
+    {
+        case 0:
+        {
+            neck.x = GetX();
+            neck.y = root.y - m_branchNeckLength;
+
+            shoulder1.x = root.x - (totalBranchLength/2.0) ;
+            shoulder2.x = root.x + (totalBranchLength/2.0) ;
+
+            shoulder1.y = neck.y;
+            shoulder2.y = neck.y;
+            break;
+        }
+        case 1:
+        {
+            neck.x = root.x + m_branchNeckLength;
+            neck.y = root.y;
+
+            shoulder1.x = neck.x ;
+            shoulder2.x = neck.x ;
+
+            shoulder1.y = neck.y - (totalBranchLength/2.0) ;
+            shoulder2.y = neck.y + (totalBranchLength/2.0) ;
+            break;
+        }
+        case 2:
+        {
+            neck.x = GetX();
+            neck.y = root.y + m_branchNeckLength;
+
+            shoulder1.x = root.x - (totalBranchLength/2.0) ;
+            shoulder2.x = root.x + (totalBranchLength/2.0) ;
+
+            shoulder1.y = neck.y;
+            shoulder2.y = neck.y;
+            break;
+        }
+        case 3:
+        {
+            neck.x = root.x - m_branchNeckLength;
+            neck.y = root.y ;
+
+            shoulder1.x = neck.x ;
+            shoulder2.x = neck.x ;
+
+            shoulder1.y = neck.y - (totalBranchLength/2.0) ;
+            shoulder2.y = neck.y + (totalBranchLength/2.0) ;
+            break;
+        }
+        default:
+        {
+            wxFAIL_MSG( "Unrecognised attachment point in GetBranchingAttachmentInfo." );
+            break;
+        }
+    }
+    return TRUE;
+}
+
+// n is the number of the adjoining line, from 0 to N-1 where N is the number of lines
+// at this attachment point.
+// Get the attachment point where the arc joins the stem, and also the point where the
+// the stem meets the shoulder.
+bool wxShape::GetBranchingAttachmentPoint(int attachment, int n, wxRealPoint& pt, wxRealPoint& stemPt)
+{
+    int physicalAttachment = LogicalToPhysicalAttachment(attachment);
+
+    wxRealPoint root, neck, shoulder1, shoulder2;
+    GetBranchingAttachmentInfo(attachment, root, neck, shoulder1, shoulder2);
+
+    // Assume that we have attachment points 0 to 3: top, right, bottom, left.
+    switch (physicalAttachment)
+    {
+        case 0:
+        {
+            pt.y = neck.y - m_branchStemLength;
+            pt.x = shoulder1.x + n*m_branchSpacing;
+
+            stemPt.x = pt.x;
+            stemPt.y = neck.y;
+            break;
+        }
+        case 2:
+        {
+            pt.y = neck.y + m_branchStemLength;
+            pt.x = shoulder1.x + n*m_branchSpacing;
+
+            stemPt.x = pt.x;
+            stemPt.y = neck.y;
+            break;
+        }
+        case 1:
+        {
+            pt.x = neck.x + m_branchStemLength;
+            pt.y = shoulder1.y + n*m_branchSpacing;
+
+            stemPt.x = neck.x;
+            stemPt.y = pt.y;
+            break;
+        }
+        case 3:
+        {
+            pt.x = neck.x - m_branchStemLength;
+            pt.y = shoulder1.y + n*m_branchSpacing;
+
+            stemPt.x = neck.x;
+            stemPt.y = pt.y;
+            break;
+        }
+        default:
+        {
+            wxFAIL_MSG( "Unrecognised attachment point in GetBranchingAttachmentPoint." );
+            break;
+        }
+    }
+
+    return TRUE;
+}
+
+// Get the number of lines at this attachment position.
+int wxShape::GetAttachmentLineCount(int attachment) const
+{
+    int count = 0;
+    wxNode* node = m_lines.First();
+    while (node)
+    {
+        wxLineShape* lineShape = (wxLineShape*) node->Data();
+        if ((lineShape->GetFrom() == this) && (lineShape->GetAttachmentFrom() == attachment))
+            count ++;
+        else if ((lineShape->GetTo() == this) && (lineShape->GetAttachmentTo() == attachment))
+            count ++;
+
+        node = node->Next();
+    }
+    return count;
+}
+
+// This function gets the root point at the given attachment.
+wxRealPoint wxShape::GetBranchingAttachmentRoot(int attachment)
+{
+    int physicalAttachment = LogicalToPhysicalAttachment(attachment);
+
+    wxRealPoint root;
+
+    double width, height;
+    GetBoundingBoxMax(& width, & height);
+
+    // Assume that we have attachment points 0 to 3: top, right, bottom, left.
+    switch (physicalAttachment)
+    {
+        case 0:
+        {
+            root.x = GetX() ;
+            root.y = GetY() - height/2.0;
+            break;
+        }
+        case 1:
+        {
+            root.x = GetX() + width/2.0;
+            root.y = GetY() ;
+            break;
+        }
+        case 2:
+        {
+            root.x = GetX() ;
+            root.y = GetY() + height/2.0;
+            break;
+        }
+        case 3:
+        {
+            root.x = GetX() - width/2.0;
+            root.y = GetY() ;
+            break;
+        }
+        default:
+        {
+            wxFAIL_MSG( "Unrecognised attachment point in GetBranchingAttachmentRoot." );
+            break;
+        }
+    }
+    return root;
+}
+
+// Draw or erase the branches (not the actual arcs though)
+void wxShape::OnDrawBranches(wxDC& dc, int attachment, bool erase)
+{
+    int count = GetAttachmentLineCount(attachment);
+    if (count == 0)
+        return;
+
+    wxRealPoint root, neck, shoulder1, shoulder2;
+    GetBranchingAttachmentInfo(attachment, root, neck, shoulder1, shoulder2);
+
+    if (erase)
+    {
+        dc.SetPen(*wxWHITE_PEN);
+        dc.SetBrush(*wxWHITE_BRUSH);
+    }
+    else
+    {
+        dc.SetPen(*wxBLACK_PEN);
+        dc.SetBrush(*wxBLACK_BRUSH);
+    }
+
+    // Draw neck
+    dc.DrawLine((long) root.x, (long) root.y, (long) neck.x, (long) neck.y);
+
+    if (count > 1)
+    {
+        // Draw shoulder-to-shoulder line
+        dc.DrawLine((long) shoulder1.x, (long) shoulder1.y, (long) shoulder2.x, (long) shoulder2.y);
+    }
+    // Draw all the little branches
+    int i;
+    for (i = 0; i < count; i++)
+    {
+        wxRealPoint pt, stemPt;
+        GetBranchingAttachmentPoint(attachment, i, pt, stemPt);
+        dc.DrawLine((long) stemPt.x, (long) stemPt.y, (long) pt.x, (long) pt.y);
+
+        if ((GetBranchStyle() & BRANCHING_ATTACHMENT_BLOB) && (count > 1))
+        {
+            long blobSize=6;
+//            dc.DrawEllipse((long) (stemPt.x + 0.5 - (blobSize/2.0)), (long) (stemPt.y + 0.5 - (blobSize/2.0)), blobSize, blobSize);
+            dc.DrawEllipse((long) (stemPt.x - (blobSize/2.0)), (long) (stemPt.y - (blobSize/2.0)), blobSize, blobSize);
+        }
+    }
+}
+
+// Draw or erase the branches (not the actual arcs though)
+void wxShape::OnDrawBranches(wxDC& dc, bool erase)
+{
+    if (m_attachmentMode != ATTACHMENT_MODE_BRANCHING)
+        return;
+
+    int count = GetNumberOfAttachments();
+    int i;
+    for (i = 0; i < count; i++)
+        OnDrawBranches(dc, i, erase);
+}
+
+// Only get the attachment position at the _edge_ of the shape, ignoring
+// branching mode. This is used e.g. to indicate the edge of interest, not the point
+// on the attachment branch.
+bool wxShape::GetAttachmentPositionEdge(int attachment, double *x, double *y,
+                                     int nth, int no_arcs, wxLineShape *line)
+{
+    int oldMode = m_attachmentMode;
+
+    // Calculate as if to edge, not branch
+    if (m_attachmentMode == ATTACHMENT_MODE_BRANCHING)
+        m_attachmentMode = ATTACHMENT_MODE_EDGE;
+    bool success = GetAttachmentPosition(attachment, x, y, nth, no_arcs, line);
+    m_attachmentMode = oldMode;
+
+    return success;
+}
+
+// Rotate the standard attachment point from physical (0 is always North)
+// to logical (0 -> 1 if rotated by 90 degrees)
+int wxShape::PhysicalToLogicalAttachment(int physicalAttachment) const
+{
+    const double pi = 3.1415926535897932384626433832795 ;
+    int i;
+    if (oglRoughlyEqual(GetRotation(), 0.0))
+    {
+        i = physicalAttachment;
+    }
+    else if (oglRoughlyEqual(GetRotation(), (pi/2.0)))
+    {
+        i = physicalAttachment - 1;
+    }
+    else if (oglRoughlyEqual(GetRotation(), pi))
+    {
+        i = physicalAttachment - 2;
+    }
+    else if (oglRoughlyEqual(GetRotation(), (3.0*pi/2.0)))
+    {
+        i = physicalAttachment - 3;
+    }
+    else
+        // Can't handle -- assume the same.
+        return physicalAttachment;
+
+    if (i < 0)
+      i += 4;
+
+    return i;
+}
+
+// Rotate the standard attachment point from logical
+// to physical (0 is always North)
+int wxShape::LogicalToPhysicalAttachment(int logicalAttachment) const
+{
+    const double pi = 3.1415926535897932384626433832795 ;
+    int i;
+    if (oglRoughlyEqual(GetRotation(), 0.0))
+    {
+        i = logicalAttachment;
+    }
+    else if (oglRoughlyEqual(GetRotation(), (pi/2.0)))
+    {
+        i = logicalAttachment + 1;
+    }
+    else if (oglRoughlyEqual(GetRotation(), pi))
+    {
+        i = logicalAttachment + 2;
+    }
+    else if (oglRoughlyEqual(GetRotation(), (3.0*pi/2.0)))
+    {
+        i = logicalAttachment + 3;
+    }
+    else
+        // Can't handle -- assume the same.
+        return logicalAttachment;
+
+    if (i > 3)
+      i -= 4;
+
+    return i;
+}
+
+void wxShape::Rotate(double WXUNUSED(x), double WXUNUSED(y), double theta)
+{
+    const double pi = 3.1415926535897932384626433832795 ;
+    m_rotation = theta;
+    if (m_rotation < 0.0)
+    {
+        m_rotation += 2*pi;
+    }
+    else if (m_rotation > 2*pi)
+    {
+        m_rotation -= 2*pi;
+    }
+}
+