1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxLineShape
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "lines.h"
14 #pragma implementation "linesp.h"
17 // For compilers that support precompilation, includes "wx.h".
18 #include "wx/wxprec.h"
29 #include <wx/deprecated/wxexpr.h>
39 #include "wx/ogl/ogl.h"
43 IMPLEMENT_DYNAMIC_CLASS(wxLineShape
, wxShape
)
45 wxLineShape::wxLineShape()
47 m_sensitivity
= OP_CLICK_LEFT
| OP_CLICK_RIGHT
;
52 m_actualTextWidth = 0.0;
53 m_actualTextHeight = 0.0;
58 m_arrowSpacing
= 5.0; // For the moment, don't bother saving this to file.
59 m_ignoreArrowOffsets
= FALSE
;
61 m_maintainStraightLines
= FALSE
;
65 m_lineControlPoints
= NULL
;
67 // Clear any existing regions (created in an earlier constructor)
68 // and make the three line regions.
70 wxShapeRegion
*newRegion
= new wxShapeRegion
;
71 newRegion
->SetName(wxT("Middle"));
72 newRegion
->SetSize(150, 50);
73 m_regions
.Append((wxObject
*)newRegion
);
75 newRegion
= new wxShapeRegion
;
76 newRegion
->SetName(wxT("Start"));
77 newRegion
->SetSize(150, 50);
78 m_regions
.Append((wxObject
*)newRegion
);
80 newRegion
= new wxShapeRegion
;
81 newRegion
->SetName(wxT("End"));
82 newRegion
->SetSize(150, 50);
83 m_regions
.Append((wxObject
*)newRegion
);
85 for (int i
= 0; i
< 3; i
++)
86 m_labelObjects
[i
] = NULL
;
89 wxLineShape::~wxLineShape()
91 if (m_lineControlPoints
)
93 ClearPointList(*m_lineControlPoints
);
94 delete m_lineControlPoints
;
96 for (int i
= 0; i
< 3; i
++)
98 if (m_labelObjects
[i
])
100 m_labelObjects
[i
]->Select(FALSE
);
101 m_labelObjects
[i
]->RemoveFromCanvas(m_canvas
);
102 delete m_labelObjects
[i
];
103 m_labelObjects
[i
] = NULL
;
106 ClearArrowsAtPosition(-1);
109 void wxLineShape::MakeLineControlPoints(int n
)
111 if (m_lineControlPoints
)
113 ClearPointList(*m_lineControlPoints
);
114 delete m_lineControlPoints
;
116 m_lineControlPoints
= new wxList
;
119 for (i
= 0; i
< n
; i
++)
121 wxRealPoint
*point
= new wxRealPoint(-999, -999);
122 m_lineControlPoints
->Append((wxObject
*) point
);
126 wxNode
*wxLineShape::InsertLineControlPoint(wxDC
* dc
)
131 wxNode
*last
= m_lineControlPoints
->GetLast();
132 wxNode
*second_last
= last
->GetPrevious();
133 wxRealPoint
*last_point
= (wxRealPoint
*)last
->GetData();
134 wxRealPoint
*second_last_point
= (wxRealPoint
*)second_last
->GetData();
136 // Choose a point half way between the last and penultimate points
137 double line_x
= ((last_point
->x
+ second_last_point
->x
)/2);
138 double line_y
= ((last_point
->y
+ second_last_point
->y
)/2);
140 wxRealPoint
*point
= new wxRealPoint(line_x
, line_y
);
141 wxNode
*node
= m_lineControlPoints
->Insert(last
, (wxObject
*) point
);
145 bool wxLineShape::DeleteLineControlPoint()
147 if (m_lineControlPoints
->GetCount() < 3)
150 wxNode
*last
= m_lineControlPoints
->GetLast();
151 wxNode
*second_last
= last
->GetPrevious();
153 wxRealPoint
*second_last_point
= (wxRealPoint
*)second_last
->GetData();
154 delete second_last_point
;
160 void wxLineShape::Initialise()
162 if (m_lineControlPoints
)
164 // Just move the first and last control points
165 wxNode
*first
= m_lineControlPoints
->GetFirst();
166 wxRealPoint
*first_point
= (wxRealPoint
*)first
->GetData();
168 wxNode
*last
= m_lineControlPoints
->GetLast();
169 wxRealPoint
*last_point
= (wxRealPoint
*)last
->GetData();
171 // If any of the line points are at -999, we must
172 // initialize them by placing them half way between the first
174 wxNode
*node
= first
->GetNext();
177 wxRealPoint
*point
= (wxRealPoint
*)node
->GetData();
178 if (point
->x
== -999)
180 double x1
, y1
, x2
, y2
;
181 if (first_point
->x
< last_point
->x
)
182 { x1
= first_point
->x
; x2
= last_point
->x
; }
184 { x2
= first_point
->x
; x1
= last_point
->x
; }
186 if (first_point
->y
< last_point
->y
)
187 { y1
= first_point
->y
; y2
= last_point
->y
; }
189 { y2
= first_point
->y
; y1
= last_point
->y
; }
191 point
->x
= ((x2
- x1
)/2 + x1
);
192 point
->y
= ((y2
- y1
)/2 + y1
);
194 node
= node
->GetNext();
199 // Format a text string according to the region size, adding
200 // strings with positions to region text list
201 void wxLineShape::FormatText(wxDC
& dc
, const wxString
& s
, int i
)
206 if (m_regions
.GetCount() < 1)
208 wxNode
*node
= m_regions
.Item(i
);
212 wxShapeRegion
*region
= (wxShapeRegion
*)node
->GetData();
214 dc
.SetFont(* region
->GetFont());
216 region
->GetSize(&w
, &h
);
217 // Initialize the size if zero
218 if (((w
== 0) || (h
== 0)) && (s
.Length() > 0))
221 region
->SetSize(w
, h
);
224 wxStringList
*string_list
= oglFormatText(dc
, s
, (w
-5), (h
-5), region
->GetFormatMode());
225 node
= (wxNode
*)string_list
->GetFirst();
228 wxChar
*s
= (wxChar
*)node
->GetData();
229 wxShapeTextLine
*line
= new wxShapeTextLine(0.0, 0.0, s
);
230 region
->GetFormattedText().Append((wxObject
*)line
);
231 node
= node
->GetNext();
236 if (region
->GetFormatMode() & FORMAT_SIZE_TO_CONTENTS
)
238 oglGetCentredTextExtent(dc
, &(region
->GetFormattedText()), m_xpos
, m_ypos
, w
, h
, &actualW
, &actualH
);
239 if ((actualW
!= w
) || (actualH
!= h
))
242 GetLabelPosition(i
, &xx
, &yy
);
243 EraseRegion(dc
, region
, xx
, yy
);
244 if (m_labelObjects
[i
])
246 m_labelObjects
[i
]->Select(FALSE
, &dc
);
247 m_labelObjects
[i
]->Erase(dc
);
248 m_labelObjects
[i
]->SetSize(actualW
, actualH
);
251 region
->SetSize(actualW
, actualH
);
253 if (m_labelObjects
[i
])
255 m_labelObjects
[i
]->Select(TRUE
, & dc
);
256 m_labelObjects
[i
]->Draw(dc
);
260 oglCentreText(dc
, &(region
->GetFormattedText()), m_xpos
, m_ypos
, actualW
, actualH
, region
->GetFormatMode());
264 void wxLineShape::DrawRegion(wxDC
& dc
, wxShapeRegion
*region
, double x
, double y
)
266 if (GetDisableLabel())
271 region
->GetSize(&w
, &h
);
273 // Get offset from x, y
274 region
->GetPosition(&xx
, &yy
);
279 // First, clear a rectangle for the text IF there is any
280 if (region
->GetFormattedText().GetCount() > 0)
282 dc
.SetPen(GetBackgroundPen());
283 dc
.SetBrush(GetBackgroundBrush());
286 if (region
->GetFont()) dc
.SetFont(* region
->GetFont());
288 dc
.DrawRectangle((long)(xp
- w
/2.0), (long)(yp
- h
/2.0), (long)w
, (long)h
);
290 if (m_pen
) dc
.SetPen(* m_pen
);
291 dc
.SetTextForeground(* region
->GetActualColourObject());
294 dc
.SetTextBackground(GetBackgroundBrush().GetColour());
297 oglDrawFormattedText(dc
, &(region
->GetFormattedText()), xp
, yp
, w
, h
, region
->GetFormatMode());
301 void wxLineShape::EraseRegion(wxDC
& dc
, wxShapeRegion
*region
, double x
, double y
)
303 if (GetDisableLabel())
308 region
->GetSize(&w
, &h
);
310 // Get offset from x, y
311 region
->GetPosition(&xx
, &yy
);
316 if (region
->GetFormattedText().GetCount() > 0)
318 dc
.SetPen(GetBackgroundPen());
319 dc
.SetBrush(GetBackgroundBrush());
321 dc
.DrawRectangle((long)(xp
- w
/2.0), (long)(yp
- h
/2.0), (long)w
, (long)h
);
325 // Get the reference point for a label. Region x and y
326 // are offsets from this.
327 // position is 0, 1, 2
328 void wxLineShape::GetLabelPosition(int position
, double *x
, double *y
)
334 // Want to take the middle section for the label
335 int n
= m_lineControlPoints
->GetCount();
336 int half_way
= (int)(n
/2);
338 // Find middle of this line
339 wxNode
*node
= m_lineControlPoints
->Item(half_way
- 1);
340 wxRealPoint
*point
= (wxRealPoint
*)node
->GetData();
341 wxNode
*next_node
= node
->GetNext();
342 wxRealPoint
*next_point
= (wxRealPoint
*)next_node
->GetData();
344 double dx
= (next_point
->x
- point
->x
);
345 double dy
= (next_point
->y
- point
->y
);
346 *x
= (double)(point
->x
+ dx
/2.0);
347 *y
= (double)(point
->y
+ dy
/2.0);
352 wxNode
*node
= m_lineControlPoints
->GetFirst();
353 *x
= ((wxRealPoint
*)node
->GetData())->x
;
354 *y
= ((wxRealPoint
*)node
->GetData())->y
;
359 wxNode
*node
= m_lineControlPoints
->GetLast();
360 *x
= ((wxRealPoint
*)node
->GetData())->x
;
361 *y
= ((wxRealPoint
*)node
->GetData())->y
;
370 * Find whether line is supposed to be vertical or horizontal and
374 void GraphicsStraightenLine(wxRealPoint
*point1
, wxRealPoint
*point2
)
376 double dx
= point2
->x
- point1
->x
;
377 double dy
= point2
->y
- point1
->y
;
381 else if (fabs(dy
/dx
) > 1.0)
383 point2
->x
= point1
->x
;
385 else point2
->y
= point1
->y
;
388 void wxLineShape::Straighten(wxDC
*dc
)
390 if (!m_lineControlPoints
|| m_lineControlPoints
->GetCount() < 3)
396 wxNode
*first_point_node
= m_lineControlPoints
->GetFirst();
397 wxNode
*last_point_node
= m_lineControlPoints
->GetLast();
398 wxNode
*second_last_point_node
= last_point_node
->GetPrevious();
400 wxRealPoint
*last_point
= (wxRealPoint
*)last_point_node
->GetData();
401 wxRealPoint
*second_last_point
= (wxRealPoint
*)second_last_point_node
->GetData();
403 GraphicsStraightenLine(last_point
, second_last_point
);
405 wxNode
*node
= first_point_node
;
406 while (node
&& (node
!= second_last_point_node
))
408 wxRealPoint
*point
= (wxRealPoint
*)node
->GetData();
409 wxRealPoint
*next_point
= (wxRealPoint
*)(node
->GetNext()->GetData());
411 GraphicsStraightenLine(point
, next_point
);
412 node
= node
->GetNext();
420 void wxLineShape::Unlink()
423 m_to
->GetLines().DeleteObject(this);
425 m_from
->GetLines().DeleteObject(this);
430 void wxLineShape::SetEnds(double x1
, double y1
, double x2
, double y2
)
433 wxNode
*first_point_node
= m_lineControlPoints
->GetFirst();
434 wxNode
*last_point_node
= m_lineControlPoints
->GetLast();
435 wxRealPoint
*first_point
= (wxRealPoint
*)first_point_node
->GetData();
436 wxRealPoint
*last_point
= (wxRealPoint
*)last_point_node
->GetData();
443 m_xpos
= (double)((x1
+ x2
)/2.0);
444 m_ypos
= (double)((y1
+ y2
)/2.0);
447 // Get absolute positions of ends
448 void wxLineShape::GetEnds(double *x1
, double *y1
, double *x2
, double *y2
)
450 wxNode
*first_point_node
= m_lineControlPoints
->GetFirst();
451 wxNode
*last_point_node
= m_lineControlPoints
->GetLast();
452 wxRealPoint
*first_point
= (wxRealPoint
*)first_point_node
->GetData();
453 wxRealPoint
*last_point
= (wxRealPoint
*)last_point_node
->GetData();
455 *x1
= first_point
->x
; *y1
= first_point
->y
;
456 *x2
= last_point
->x
; *y2
= last_point
->y
;
459 void wxLineShape::SetAttachments(int from_attach
, int to_attach
)
461 m_attachmentFrom
= from_attach
;
462 m_attachmentTo
= to_attach
;
465 bool wxLineShape::HitTest(double x
, double y
, int *attachment
, double *distance
)
467 if (!m_lineControlPoints
)
470 // Look at label regions in case mouse is over a label
471 bool inLabelRegion
= FALSE
;
472 for (int i
= 0; i
< 3; i
++)
474 wxNode
*regionNode
= m_regions
.Item(i
);
477 wxShapeRegion
*region
= (wxShapeRegion
*)regionNode
->GetData();
478 if (region
->m_formattedText
.GetCount() > 0)
480 double xp
, yp
, cx
, cy
, cw
, ch
;
481 GetLabelPosition(i
, &xp
, &yp
);
482 // Offset region from default label position
483 region
->GetPosition(&cx
, &cy
);
484 region
->GetSize(&cw
, &ch
);
487 double rLeft
= (double)(cx
- (cw
/2.0));
488 double rTop
= (double)(cy
- (ch
/2.0));
489 double rRight
= (double)(cx
+ (cw
/2.0));
490 double rBottom
= (double)(cy
+ (ch
/2.0));
491 if (x
> rLeft
&& x
< rRight
&& y
> rTop
&& y
< rBottom
)
493 inLabelRegion
= TRUE
;
500 wxNode
*node
= m_lineControlPoints
->GetFirst();
502 while (node
&& node
->GetNext())
504 wxRealPoint
*point1
= (wxRealPoint
*)node
->GetData();
505 wxRealPoint
*point2
= (wxRealPoint
*)node
->GetNext()->GetData();
507 // For inaccurate mousing allow 8 pixel corridor
510 double dx
= point2
->x
- point1
->x
;
511 double dy
= point2
->y
- point1
->y
;
512 double seg_len
= sqrt(dx
*dx
+dy
*dy
);
513 double distance_from_seg
=
514 seg_len
*((x
-point1
->x
)*dy
-(y
-point1
->y
)*dx
)/(dy
*dy
+dx
*dx
);
515 double distance_from_prev
=
516 seg_len
*((y
-point1
->y
)*dy
+(x
-point1
->x
)*dx
)/(dy
*dy
+dx
*dx
);
518 if ((fabs(distance_from_seg
) < extra
&&
519 distance_from_prev
>= 0 && distance_from_prev
<= seg_len
)
523 *distance
= distance_from_seg
;
527 node
= node
->GetNext();
532 void wxLineShape::DrawArrows(wxDC
& dc
)
534 // Distance along line of each arrow: space them out evenly.
535 double startArrowPos
= 0.0;
536 double endArrowPos
= 0.0;
537 double middleArrowPos
= 0.0;
539 wxNode
*node
= m_arcArrows
.GetFirst();
542 wxArrowHead
*arrow
= (wxArrowHead
*)node
->GetData();
543 switch (arrow
->GetArrowEnd())
545 case ARROW_POSITION_START
:
547 if ((arrow
->GetXOffset() != 0.0) && !m_ignoreArrowOffsets
)
548 // If specified, x offset is proportional to line length
549 DrawArrow(dc
, arrow
, arrow
->GetXOffset(), TRUE
);
552 DrawArrow(dc
, arrow
, startArrowPos
, FALSE
); // Absolute distance
553 startArrowPos
+= arrow
->GetSize() + arrow
->GetSpacing();
557 case ARROW_POSITION_END
:
559 if ((arrow
->GetXOffset() != 0.0) && !m_ignoreArrowOffsets
)
560 DrawArrow(dc
, arrow
, arrow
->GetXOffset(), TRUE
);
563 DrawArrow(dc
, arrow
, endArrowPos
, FALSE
);
564 endArrowPos
+= arrow
->GetSize() + arrow
->GetSpacing();
568 case ARROW_POSITION_MIDDLE
:
570 arrow
->SetXOffset(middleArrowPos
);
571 if ((arrow
->GetXOffset() != 0.0) && !m_ignoreArrowOffsets
)
572 DrawArrow(dc
, arrow
, arrow
->GetXOffset(), TRUE
);
575 DrawArrow(dc
, arrow
, middleArrowPos
, FALSE
);
576 middleArrowPos
+= arrow
->GetSize() + arrow
->GetSpacing();
581 node
= node
->GetNext();
585 void wxLineShape::DrawArrow(wxDC
& dc
, wxArrowHead
*arrow
, double xOffset
, bool proportionalOffset
)
587 wxNode
*first_line_node
= m_lineControlPoints
->GetFirst();
588 wxRealPoint
*first_line_point
= (wxRealPoint
*)first_line_node
->GetData();
589 wxNode
*second_line_node
= first_line_node
->GetNext();
590 wxRealPoint
*second_line_point
= (wxRealPoint
*)second_line_node
->GetData();
592 wxNode
*last_line_node
= m_lineControlPoints
->GetLast();
593 wxRealPoint
*last_line_point
= (wxRealPoint
*)last_line_node
->GetData();
594 wxNode
*second_last_line_node
= last_line_node
->GetPrevious();
595 wxRealPoint
*second_last_line_point
= (wxRealPoint
*)second_last_line_node
->GetData();
597 // Position where we want to start drawing
598 double positionOnLineX
, positionOnLineY
;
600 // Position of start point of line, at the end of which we draw the arrow.
601 double startPositionX
, startPositionY
;
603 switch (arrow
->GetPosition())
605 case ARROW_POSITION_START
:
607 // If we're using a proportional offset, calculate just where this will
609 double realOffset
= xOffset
;
610 if (proportionalOffset
)
613 (double)sqrt((second_line_point
->x
- first_line_point
->x
)*(second_line_point
->x
- first_line_point
->x
) +
614 (second_line_point
->y
- first_line_point
->y
)*(second_line_point
->y
- first_line_point
->y
));
615 realOffset
= (double)(xOffset
* totalLength
);
617 GetPointOnLine(second_line_point
->x
, second_line_point
->y
,
618 first_line_point
->x
, first_line_point
->y
,
619 realOffset
, &positionOnLineX
, &positionOnLineY
);
620 startPositionX
= second_line_point
->x
;
621 startPositionY
= second_line_point
->y
;
624 case ARROW_POSITION_END
:
626 // If we're using a proportional offset, calculate just where this will
628 double realOffset
= xOffset
;
629 if (proportionalOffset
)
632 (double)sqrt((second_last_line_point
->x
- last_line_point
->x
)*(second_last_line_point
->x
- last_line_point
->x
) +
633 (second_last_line_point
->y
- last_line_point
->y
)*(second_last_line_point
->y
- last_line_point
->y
));
634 realOffset
= (double)(xOffset
* totalLength
);
636 GetPointOnLine(second_last_line_point
->x
, second_last_line_point
->y
,
637 last_line_point
->x
, last_line_point
->y
,
638 realOffset
, &positionOnLineX
, &positionOnLineY
);
639 startPositionX
= second_last_line_point
->x
;
640 startPositionY
= second_last_line_point
->y
;
643 case ARROW_POSITION_MIDDLE
:
645 // Choose a point half way between the last and penultimate points
646 double x
= ((last_line_point
->x
+ second_last_line_point
->x
)/2);
647 double y
= ((last_line_point
->y
+ second_last_line_point
->y
)/2);
649 // If we're using a proportional offset, calculate just where this will
651 double realOffset
= xOffset
;
652 if (proportionalOffset
)
655 (double)sqrt((second_last_line_point
->x
- x
)*(second_last_line_point
->x
- x
) +
656 (second_last_line_point
->y
- y
)*(second_last_line_point
->y
- y
));
657 realOffset
= (double)(xOffset
* totalLength
);
660 GetPointOnLine(second_last_line_point
->x
, second_last_line_point
->y
,
661 x
, y
, realOffset
, &positionOnLineX
, &positionOnLineY
);
662 startPositionX
= second_last_line_point
->x
;
663 startPositionY
= second_last_line_point
->y
;
669 * Add yOffset to arrow, if any
672 const double myPi
= (double) 3.14159265;
673 // The translation that the y offset may give
676 if ((arrow
->GetYOffset() != 0.0) && !m_ignoreArrowOffsets
)
682 (x1, y1)--------------(x3, y3)------------------(x2, y2)
683 x4 = x3 - d * sin(theta)
684 y4 = y3 + d * cos(theta)
686 Where theta = tan(-1) of (y3-y1)/(x3-x1)
688 double x1
= startPositionX
;
689 double y1
= startPositionY
;
690 double x3
= positionOnLineX
;
691 double y3
= positionOnLineY
;
692 double d
= -arrow
->GetYOffset(); // Negate so +offset is above line
696 theta
= (double)(myPi
/2.0);
698 theta
= (double)atan((y3
-y1
)/(x3
-x1
));
700 double x4
= (double)(x3
- (d
*sin(theta
)));
701 double y4
= (double)(y3
+ (d
*cos(theta
)));
703 deltaX
= x4
- positionOnLineX
;
704 deltaY
= y4
- positionOnLineY
;
707 switch (arrow
->_GetType())
711 double arrowLength
= arrow
->GetSize();
712 double arrowWidth
= (double)(arrowLength
/3.0);
714 double tip_x
, tip_y
, side1_x
, side1_y
, side2_x
, side2_y
;
715 oglGetArrowPoints(startPositionX
+deltaX
, startPositionY
+deltaY
,
716 positionOnLineX
+deltaX
, positionOnLineY
+deltaY
,
717 arrowLength
, arrowWidth
, &tip_x
, &tip_y
,
718 &side1_x
, &side1_y
, &side2_x
, &side2_y
);
721 points
[0].x
= (int) tip_x
; points
[0].y
= (int) tip_y
;
722 points
[1].x
= (int) side1_x
; points
[1].y
= (int) side1_y
;
723 points
[2].x
= (int) side2_x
; points
[2].y
= (int) side2_y
;
724 points
[3].x
= (int) tip_x
; points
[3].y
= (int) tip_y
;
727 dc
.SetBrush(* m_brush
);
728 dc
.DrawPolygon(4, points
);
731 case ARROW_HOLLOW_CIRCLE
:
732 case ARROW_FILLED_CIRCLE
:
734 // Find point on line of centre of circle, which is a radius away
735 // from the end position
736 double diameter
= (double)(arrow
->GetSize());
738 GetPointOnLine(startPositionX
+deltaX
, startPositionY
+deltaY
,
739 positionOnLineX
+deltaX
, positionOnLineY
+deltaY
,
740 (double)(diameter
/2.0),
743 // Convert ellipse centre to top-left coordinates
744 double x1
= (double)(x
- (diameter
/2.0));
745 double y1
= (double)(y
- (diameter
/2.0));
748 if (arrow
->_GetType() == ARROW_HOLLOW_CIRCLE
)
749 dc
.SetBrush(* g_oglWhiteBackgroundBrush
);
751 dc
.SetBrush(* m_brush
);
753 dc
.DrawEllipse((long) x1
, (long) y1
, (long) diameter
, (long) diameter
);
756 case ARROW_SINGLE_OBLIQUE
:
762 if (arrow
->GetMetaFile())
764 // Find point on line of centre of object, which is a half-width away
765 // from the end position
768 * <-- start pos <-----><-- positionOnLineX
770 * --------------| x | <-- e.g. rectangular arrowhead
774 GetPointOnLine(startPositionX
, startPositionY
,
775 positionOnLineX
, positionOnLineY
,
776 (double)(arrow
->GetMetaFile()->m_width
/2.0),
779 // Calculate theta for rotating the metafile.
782 | o(x2, y2) 'o' represents the arrowhead.
787 |______________________
790 double x1
= startPositionX
;
791 double y1
= startPositionY
;
792 double x2
= positionOnLineX
;
793 double y2
= positionOnLineY
;
795 if ((x1
== x2
) && (y1
== y2
))
798 else if ((x1
== x2
) && (y1
> y2
))
799 theta
= (double)(3.0*myPi
/2.0);
801 else if ((x1
== x2
) && (y2
> y1
))
802 theta
= (double)(myPi
/2.0);
804 else if ((x2
> x1
) && (y2
>= y1
))
805 theta
= (double)atan((y2
- y1
)/(x2
- x1
));
808 theta
= (double)(myPi
+ atan((y2
- y1
)/(x2
- x1
)));
810 else if ((x2
> x1
) && (y2
< y1
))
811 theta
= (double)(2*myPi
+ atan((y2
- y1
)/(x2
- x1
)));
815 wxLogFatalError(wxT("Unknown arrowhead rotation case in lines.cc"));
818 // Rotate about the centre of the object, then place
819 // the object on the line.
820 if (arrow
->GetMetaFile()->GetRotateable())
821 arrow
->GetMetaFile()->Rotate(0.0, 0.0, theta
);
825 // If erasing, just draw a rectangle.
826 double minX
, minY
, maxX
, maxY
;
827 arrow
->GetMetaFile()->GetBounds(&minX
, &minY
, &maxX
, &maxY
);
828 // Make erasing rectangle slightly bigger or you get droppings.
830 dc
.DrawRectangle((long)(deltaX
+ x
+ minX
- (extraPixels
/2.0)), (long)(deltaY
+ y
+ minY
- (extraPixels
/2.0)),
831 (long)(maxX
- minX
+ extraPixels
), (long)(maxY
- minY
+ extraPixels
));
834 arrow
->GetMetaFile()->Draw(dc
, x
+deltaX
, y
+deltaY
);
844 void wxLineShape::OnErase(wxDC
& dc
)
846 wxPen
*old_pen
= m_pen
;
847 wxBrush
*old_brush
= m_brush
;
848 wxPen bg_pen
= GetBackgroundPen();
849 wxBrush bg_brush
= GetBackgroundBrush();
853 double bound_x
, bound_y
;
854 GetBoundingBoxMax(&bound_x
, &bound_y
);
855 if (m_font
) dc
.SetFont(* m_font
);
857 // Undraw text regions
858 for (int i
= 0; i
< 3; i
++)
860 wxNode
*node
= m_regions
.Item(i
);
864 wxShapeRegion
*region
= (wxShapeRegion
*)node
->GetData();
865 GetLabelPosition(i
, &x
, &y
);
866 EraseRegion(dc
, region
, x
, y
);
871 dc
.SetPen(GetBackgroundPen());
872 dc
.SetBrush(GetBackgroundBrush());
874 // Drawing over the line only seems to work if the line has a thickness
876 if (old_pen
&& (old_pen
->GetWidth() > 1))
878 dc
.DrawRectangle((long)(m_xpos
- (bound_x
/2.0) - 2.0), (long)(m_ypos
- (bound_y
/2.0) - 2.0),
879 (long)(bound_x
+4.0), (long)(bound_y
+4.0));
884 GetEventHandler()->OnDraw(dc
);
885 GetEventHandler()->OnEraseControlPoints(dc
);
889 if (old_pen
) SetPen(old_pen
);
890 if (old_brush
) SetBrush(old_brush
);
893 void wxLineShape::GetBoundingBoxMin(double *w
, double *h
)
900 wxNode
*node
= m_lineControlPoints
->GetFirst();
903 wxRealPoint
*point
= (wxRealPoint
*)node
->GetData();
905 if (point
->x
< x1
) x1
= point
->x
;
906 if (point
->y
< y1
) y1
= point
->y
;
907 if (point
->x
> x2
) x2
= point
->x
;
908 if (point
->y
> y2
) y2
= point
->y
;
910 node
= node
->GetNext();
912 *w
= (double)(x2
- x1
);
913 *h
= (double)(y2
- y1
);
917 * For a node image of interest, finds the position of this arc
918 * amongst all the arcs which are attached to THIS SIDE of the node image,
919 * and the number of same.
921 void wxLineShape::FindNth(wxShape
*image
, int *nth
, int *no_arcs
, bool incoming
)
925 wxNode
*node
= image
->GetLines().GetFirst();
928 this_attachment
= m_attachmentTo
;
930 this_attachment
= m_attachmentFrom
;
932 // Find number of lines going into/out of this particular attachment point
935 wxLineShape
*line
= (wxLineShape
*)node
->GetData();
937 if (line
->m_from
== image
)
939 // This is the nth line attached to 'image'
940 if ((line
== this) && !incoming
)
943 // Increment num count if this is the same side (attachment number)
944 if (line
->m_attachmentFrom
== this_attachment
)
948 if (line
->m_to
== image
)
950 // This is the nth line attached to 'image'
951 if ((line
== this) && incoming
)
954 // Increment num count if this is the same side (attachment number)
955 if (line
->m_attachmentTo
== this_attachment
)
959 node
= node
->GetNext();
965 void wxLineShape::OnDrawOutline(wxDC
& dc
, double WXUNUSED(x
), double WXUNUSED(y
), double WXUNUSED(w
), double WXUNUSED(h
))
967 wxPen
*old_pen
= m_pen
;
968 wxBrush
*old_brush
= m_brush
;
970 wxPen
dottedPen(wxColour(0, 0, 0), 1, wxDOT
);
972 SetBrush( wxTRANSPARENT_BRUSH
);
974 GetEventHandler()->OnDraw(dc
);
976 if (old_pen
) SetPen(old_pen
);
978 if (old_brush
) SetBrush(old_brush
);
982 bool wxLineShape::OnMovePre(wxDC
& dc
, double x
, double y
, double old_x
, double old_y
, bool WXUNUSED(display
))
984 double x_offset
= x
- old_x
;
985 double y_offset
= y
- old_y
;
987 if (m_lineControlPoints
&& !(x_offset
== 0.0 && y_offset
== 0.0))
989 wxNode
*node
= m_lineControlPoints
->GetFirst();
992 wxRealPoint
*point
= (wxRealPoint
*)node
->GetData();
993 point
->x
+= x_offset
;
994 point
->y
+= y_offset
;
995 node
= node
->GetNext();
1000 // Move temporary label rectangles if necessary
1001 for (int i
= 0; i
< 3; i
++)
1003 if (m_labelObjects
[i
])
1005 m_labelObjects
[i
]->Erase(dc
);
1006 double xp
, yp
, xr
, yr
;
1007 GetLabelPosition(i
, &xp
, &yp
);
1008 wxNode
*node
= m_regions
.Item(i
);
1011 wxShapeRegion
*region
= (wxShapeRegion
*)node
->GetData();
1012 region
->GetPosition(&xr
, &yr
);
1019 m_labelObjects
[i
]->Move(dc
, xp
+xr
, yp
+yr
);
1025 void wxLineShape::OnMoveLink(wxDC
& dc
, bool moveControlPoints
)
1027 if (!m_from
|| !m_to
)
1030 if (m_lineControlPoints
->GetCount() > 2)
1033 // Do each end - nothing in the middle. User has to move other points
1034 // manually if necessary.
1035 double end_x
, end_y
;
1036 double other_end_x
, other_end_y
;
1038 FindLineEndPoints(&end_x
, &end_y
, &other_end_x
, &other_end_y
);
1040 wxNode
*first
= m_lineControlPoints
->GetFirst();
1041 /* wxRealPoint *first_point = */ (wxRealPoint
*)first
->GetData();
1042 wxNode
*last
= m_lineControlPoints
->GetLast();
1043 /* wxRealPoint *last_point = */ (wxRealPoint
*)last
->GetData();
1045 /* This is redundant, surely? Done by SetEnds.
1046 first_point->x = end_x; first_point->y = end_y;
1047 last_point->x = other_end_x; last_point->y = other_end_y;
1050 double oldX
= m_xpos
;
1051 double oldY
= m_ypos
;
1053 SetEnds(end_x
, end_y
, other_end_x
, other_end_y
);
1055 // Do a second time, because one may depend on the other.
1056 FindLineEndPoints(&end_x
, &end_y
, &other_end_x
, &other_end_y
);
1057 SetEnds(end_x
, end_y
, other_end_x
, other_end_y
);
1059 // Try to move control points with the arc
1060 double x_offset
= m_xpos
- oldX
;
1061 double y_offset
= m_ypos
- oldY
;
1063 // if (moveControlPoints && m_lineControlPoints && !(x_offset == 0.0 && y_offset == 0.0))
1064 // Only move control points if it's a self link. And only works if attachment mode is ON.
1065 if ((m_from
== m_to
) && (m_from
->GetAttachmentMode() != ATTACHMENT_MODE_NONE
) && moveControlPoints
&& m_lineControlPoints
&& !(x_offset
== 0.0 && y_offset
== 0.0))
1067 wxNode
*node
= m_lineControlPoints
->GetFirst();
1070 if ((node
!= m_lineControlPoints
->GetFirst()) && (node
!= m_lineControlPoints
->GetLast()))
1072 wxRealPoint
*point
= (wxRealPoint
*)node
->GetData();
1073 point
->x
+= x_offset
;
1074 point
->y
+= y_offset
;
1076 node
= node
->GetNext();
1080 Move(dc
, m_xpos
, m_ypos
);
1083 // Finds the x, y points at the two ends of the line.
1084 // This function can be used by e.g. line-routing routines to
1085 // get the actual points on the two node images where the lines will be drawn
1087 void wxLineShape::FindLineEndPoints(double *fromX
, double *fromY
, double *toX
, double *toY
)
1089 if (!m_from
|| !m_to
)
1092 // Do each end - nothing in the middle. User has to move other points
1093 // manually if necessary.
1094 double end_x
, end_y
;
1095 double other_end_x
, other_end_y
;
1097 wxNode
*first
= m_lineControlPoints
->GetFirst();
1098 /* wxRealPoint *first_point = */ (wxRealPoint
*)first
->GetData();
1099 wxNode
*last
= m_lineControlPoints
->GetLast();
1100 /* wxRealPoint *last_point = */ (wxRealPoint
*)last
->GetData();
1102 wxNode
*second
= first
->GetNext();
1103 wxRealPoint
*second_point
= (wxRealPoint
*)second
->GetData();
1105 wxNode
*second_last
= last
->GetPrevious();
1106 wxRealPoint
*second_last_point
= (wxRealPoint
*)second_last
->GetData();
1108 if (m_lineControlPoints
->GetCount() > 2)
1110 if (m_from
->GetAttachmentMode() != ATTACHMENT_MODE_NONE
)
1113 FindNth(m_from
, &nth
, &no_arcs
, FALSE
); // Not incoming
1114 m_from
->GetAttachmentPosition(m_attachmentFrom
, &end_x
, &end_y
, nth
, no_arcs
, this);
1117 (void) m_from
->GetPerimeterPoint(m_from
->GetX(), m_from
->GetY(),
1118 (double)second_point
->x
, (double)second_point
->y
,
1121 if (m_to
->GetAttachmentMode() != ATTACHMENT_MODE_NONE
)
1124 FindNth(m_to
, &nth
, &no_arcs
, TRUE
); // Incoming
1125 m_to
->GetAttachmentPosition(m_attachmentTo
, &other_end_x
, &other_end_y
, nth
, no_arcs
, this);
1128 (void) m_to
->GetPerimeterPoint(m_to
->GetX(), m_to
->GetY(),
1129 (double)second_last_point
->x
, (double)second_last_point
->y
,
1130 &other_end_x
, &other_end_y
);
1134 double fromX
= m_from
->GetX();
1135 double fromY
= m_from
->GetY();
1136 double toX
= m_to
->GetX();
1137 double toY
= m_to
->GetY();
1139 if (m_from
->GetAttachmentMode() != ATTACHMENT_MODE_NONE
)
1142 FindNth(m_from
, &nth
, &no_arcs
, FALSE
);
1143 m_from
->GetAttachmentPosition(m_attachmentFrom
, &end_x
, &end_y
, nth
, no_arcs
, this);
1148 if (m_to
->GetAttachmentMode() != ATTACHMENT_MODE_NONE
)
1151 FindNth(m_to
, &nth
, &no_arcs
, TRUE
);
1152 m_to
->GetAttachmentPosition(m_attachmentTo
, &other_end_x
, &other_end_y
, nth
, no_arcs
, this);
1157 if (m_from
->GetAttachmentMode() == ATTACHMENT_MODE_NONE
)
1158 (void) m_from
->GetPerimeterPoint(m_from
->GetX(), m_from
->GetY(),
1162 if (m_to
->GetAttachmentMode() == ATTACHMENT_MODE_NONE
)
1163 (void) m_to
->GetPerimeterPoint(m_to
->GetX(), m_to
->GetY(),
1165 &other_end_x
, &other_end_y
);
1173 void wxLineShape::OnDraw(wxDC
& dc
)
1175 if (m_lineControlPoints
)
1180 dc
.SetBrush(* m_brush
);
1182 int n
= m_lineControlPoints
->GetCount();
1183 wxPoint
*points
= new wxPoint
[n
];
1185 for (i
= 0; i
< n
; i
++)
1187 wxRealPoint
* point
= (wxRealPoint
*) m_lineControlPoints
->Item(i
)->GetData();
1188 points
[i
].x
= WXROUND(point
->x
);
1189 points
[i
].y
= WXROUND(point
->y
);
1193 dc
.DrawSpline(n
, points
);
1195 dc
.DrawLines(n
, points
);
1198 // For some reason, last point isn't drawn under Windows.
1199 dc
.DrawPoint(points
[n
-1]);
1205 // Problem with pen - if not a solid pen, does strange things
1206 // to the arrowhead. So make (get) a new pen that's solid.
1207 if (m_pen
&& (m_pen
->GetStyle() != wxSOLID
))
1210 wxThePenList
->FindOrCreatePen(m_pen
->GetColour(), 1, wxSOLID
);
1212 dc
.SetPen(* solid_pen
);
1218 void wxLineShape::OnDrawControlPoints(wxDC
& dc
)
1223 // Draw temporary label rectangles if necessary
1224 for (int i
= 0; i
< 3; i
++)
1226 if (m_labelObjects
[i
])
1227 m_labelObjects
[i
]->Draw(dc
);
1229 wxShape::OnDrawControlPoints(dc
);
1232 void wxLineShape::OnEraseControlPoints(wxDC
& dc
)
1234 // Erase temporary label rectangles if necessary
1235 for (int i
= 0; i
< 3; i
++)
1237 if (m_labelObjects
[i
])
1238 m_labelObjects
[i
]->Erase(dc
);
1240 wxShape::OnEraseControlPoints(dc
);
1243 void wxLineShape::OnDragLeft(bool WXUNUSED(draw
), double WXUNUSED(x
), double WXUNUSED(y
), int WXUNUSED(keys
), int WXUNUSED(attachment
))
1247 void wxLineShape::OnBeginDragLeft(double WXUNUSED(x
), double WXUNUSED(y
), int WXUNUSED(keys
), int WXUNUSED(attachment
))
1251 void wxLineShape::OnEndDragLeft(double WXUNUSED(x
), double WXUNUSED(y
), int WXUNUSED(keys
), int WXUNUSED(attachment
))
1256 void wxLineShape::SetArrowSize(double length, double width)
1258 arrow_length = length;
1259 arrow_width = width;
1262 void wxLineShape::SetStartArrow(int style)
1264 start_style = style;
1267 void wxLineShape::SetMiddleArrow(int style)
1269 middle_style = style;
1272 void wxLineShape::SetEndArrow(int style)
1278 void wxLineShape::OnDrawContents(wxDC
& dc
)
1280 if (GetDisableLabel())
1283 for (int i
= 0; i
< 3; i
++)
1285 wxNode
*node
= m_regions
.Item(i
);
1288 wxShapeRegion
*region
= (wxShapeRegion
*)node
->GetData();
1290 GetLabelPosition(i
, &x
, &y
);
1291 DrawRegion(dc
, region
, x
, y
);
1296 void wxLineShape::SetTo(wxShape
*object
)
1301 void wxLineShape::SetFrom(wxShape
*object
)
1306 void wxLineShape::MakeControlPoints()
1308 if (m_canvas
&& m_lineControlPoints
)
1310 wxNode
*first
= m_lineControlPoints
->GetFirst();
1311 wxNode
*last
= m_lineControlPoints
->GetLast();
1312 wxRealPoint
*first_point
= (wxRealPoint
*)first
->GetData();
1313 wxRealPoint
*last_point
= (wxRealPoint
*)last
->GetData();
1315 wxLineControlPoint
*control
= new wxLineControlPoint(m_canvas
, this, CONTROL_POINT_SIZE
,
1316 first_point
->x
, first_point
->y
,
1317 CONTROL_POINT_ENDPOINT_FROM
);
1318 control
->m_point
= first_point
;
1319 m_canvas
->AddShape(control
);
1320 m_controlPoints
.Append(control
);
1323 wxNode
*node
= first
->GetNext();
1324 while (node
!= last
)
1326 wxRealPoint
*point
= (wxRealPoint
*)node
->GetData();
1328 control
= new wxLineControlPoint(m_canvas
, this, CONTROL_POINT_SIZE
,
1330 CONTROL_POINT_LINE
);
1331 control
->m_point
= point
;
1333 m_canvas
->AddShape(control
);
1334 m_controlPoints
.Append(control
);
1336 node
= node
->GetNext();
1338 control
= new wxLineControlPoint(m_canvas
, this, CONTROL_POINT_SIZE
,
1339 last_point
->x
, last_point
->y
,
1340 CONTROL_POINT_ENDPOINT_TO
);
1341 control
->m_point
= last_point
;
1342 m_canvas
->AddShape(control
);
1343 m_controlPoints
.Append(control
);
1349 void wxLineShape::ResetControlPoints()
1351 if (m_canvas
&& m_lineControlPoints
&& m_controlPoints
.GetCount() > 0)
1353 wxNode
*node
= m_controlPoints
.GetFirst();
1354 wxNode
*control_node
= m_lineControlPoints
->GetFirst();
1355 while (node
&& control_node
)
1357 wxRealPoint
*point
= (wxRealPoint
*)control_node
->GetData();
1358 wxLineControlPoint
*control
= (wxLineControlPoint
*)node
->GetData();
1359 control
->SetX(point
->x
);
1360 control
->SetY(point
->y
);
1362 node
= node
->GetNext();
1363 control_node
= control_node
->GetNext();
1369 void wxLineShape::WriteAttributes(wxExpr
*clause
)
1371 wxShape::WriteAttributes(clause
);
1374 clause
->AddAttributeValue(_T("from"), m_from
->GetId());
1376 clause
->AddAttributeValue(_T("to"), m_to
->GetId());
1378 if (m_attachmentTo
!= 0)
1379 clause
->AddAttributeValue(_T("attachment_to"), (long)m_attachmentTo
);
1380 if (m_attachmentFrom
!= 0)
1381 clause
->AddAttributeValue(_T("attachment_from"), (long)m_attachmentFrom
);
1383 if (m_alignmentStart
!= 0)
1384 clause
->AddAttributeValue(_T("align_start"), (long)m_alignmentStart
);
1385 if (m_alignmentEnd
!= 0)
1386 clause
->AddAttributeValue(_T("align_end"), (long)m_alignmentEnd
);
1388 clause
->AddAttributeValue(_T("is_spline"), (long)m_isSpline
);
1389 if (m_maintainStraightLines
)
1390 clause
->AddAttributeValue(_T("keep_lines_straight"), (long)m_maintainStraightLines
);
1392 // Make a list of lists for the (sp)line controls
1393 wxExpr
*list
= new wxExpr(wxExprList
);
1394 wxNode
*node
= m_lineControlPoints
->GetFirst();
1397 wxRealPoint
*point
= (wxRealPoint
*)node
->GetData();
1398 wxExpr
*point_list
= new wxExpr(wxExprList
);
1399 wxExpr
*x_expr
= new wxExpr((double) point
->x
);
1400 wxExpr
*y_expr
= new wxExpr((double) point
->y
);
1401 point_list
->Append(x_expr
);
1402 point_list
->Append(y_expr
);
1403 list
->Append(point_list
);
1405 node
= node
->GetNext();
1407 clause
->AddAttributeValue(_T("controls"), list
);
1409 // Write arc arrows in new OGL format, if there are any.
1410 // This is a list of lists. Each sublist comprises:
1411 // (arrowType arrowEnd xOffset arrowSize)
1412 if (m_arcArrows
.GetCount() > 0)
1414 wxExpr
*arrow_list
= new wxExpr(wxExprList
);
1415 node
= m_arcArrows
.GetFirst();
1418 wxArrowHead
*head
= (wxArrowHead
*)node
->GetData();
1419 wxExpr
*head_list
= new wxExpr(wxExprList
);
1420 head_list
->Append(new wxExpr((long)head
->_GetType()));
1421 head_list
->Append(new wxExpr((long)head
->GetArrowEnd()));
1422 head_list
->Append(new wxExpr(head
->GetXOffset()));
1423 head_list
->Append(new wxExpr(head
->GetArrowSize()));
1424 head_list
->Append(new wxExpr(wxExprString
, head
->GetName()));
1425 head_list
->Append(new wxExpr(head
->GetId()));
1427 // New members of wxArrowHead
1428 head_list
->Append(new wxExpr(head
->GetYOffset()));
1429 head_list
->Append(new wxExpr(head
->GetSpacing()));
1431 arrow_list
->Append(head_list
);
1433 node
= node
->GetNext();
1435 clause
->AddAttributeValue(_T("arrows"), arrow_list
);
1439 void wxLineShape::ReadAttributes(wxExpr
*clause
)
1441 wxShape::ReadAttributes(clause
);
1443 int iVal
= (int) m_isSpline
;
1444 clause
->AssignAttributeValue(wxT("is_spline"), &iVal
);
1445 m_isSpline
= (iVal
!= 0);
1447 iVal
= (int) m_maintainStraightLines
;
1448 clause
->AssignAttributeValue(wxT("keep_lines_straight"), &iVal
);
1449 m_maintainStraightLines
= (iVal
!= 0);
1451 clause
->AssignAttributeValue(wxT("align_start"), &m_alignmentStart
);
1452 clause
->AssignAttributeValue(wxT("align_end"), &m_alignmentEnd
);
1454 // Compatibility: check for no regions.
1455 if (m_regions
.GetCount() == 0)
1457 wxShapeRegion
*newRegion
= new wxShapeRegion
;
1458 newRegion
->SetName(_T("Middle"));
1459 newRegion
->SetSize(150, 50);
1460 m_regions
.Append((wxObject
*)newRegion
);
1461 if (m_text
.GetCount() > 0)
1463 newRegion
->ClearText();
1464 wxNode
*node
= m_text
.GetFirst();
1467 wxShapeTextLine
*textLine
= (wxShapeTextLine
*)node
->GetData();
1468 wxNode
*next
= node
->GetNext();
1469 newRegion
->GetFormattedText().Append((wxObject
*)textLine
);
1475 newRegion
= new wxShapeRegion
;
1476 newRegion
->SetName(wxT("Start"));
1477 newRegion
->SetSize(150, 50);
1478 m_regions
.Append((wxObject
*)newRegion
);
1480 newRegion
= new wxShapeRegion
;
1481 newRegion
->SetName(wxT("End"));
1482 newRegion
->SetSize(150, 50);
1483 m_regions
.Append((wxObject
*)newRegion
);
1487 m_attachmentFrom
= 0;
1489 clause
->AssignAttributeValue(wxT("attachment_to"), &m_attachmentTo
);
1490 clause
->AssignAttributeValue(wxT("attachment_from"), &m_attachmentFrom
);
1492 wxExpr
*line_list
= NULL
;
1494 // When image is created, there are default control points. Override
1495 // them if there are some in the file.
1496 clause
->AssignAttributeValue(wxT("controls"), &line_list
);
1500 // Read a list of lists for the spline controls
1501 if (m_lineControlPoints
)
1503 ClearPointList(*m_lineControlPoints
);
1506 m_lineControlPoints
= new wxList
;
1508 wxExpr
*node
= line_list
->value
.first
;
1512 wxExpr
*xexpr
= node
->value
.first
;
1513 double x
= xexpr
->RealValue();
1515 wxExpr
*yexpr
= xexpr
->next
;
1516 double y
= yexpr
->RealValue();
1518 wxRealPoint
*point
= new wxRealPoint(x
, y
);
1519 m_lineControlPoints
->Append((wxObject
*) point
);
1525 // Read arrow list, for new OGL code
1526 wxExpr
*arrow_list
= NULL
;
1528 clause
->AssignAttributeValue(wxT("arrows"), &arrow_list
);
1531 wxExpr
*node
= arrow_list
->value
.first
;
1535 WXTYPE arrowType
= ARROW_ARROW
;
1537 double xOffset
= 0.0;
1538 double arrowSize
= 0.0;
1542 wxExpr
*type_expr
= node
->Nth(0);
1543 wxExpr
*end_expr
= node
->Nth(1);
1544 wxExpr
*dist_expr
= node
->Nth(2);
1545 wxExpr
*size_expr
= node
->Nth(3);
1546 wxExpr
*name_expr
= node
->Nth(4);
1547 wxExpr
*id_expr
= node
->Nth(5);
1549 // New members of wxArrowHead
1550 wxExpr
*yOffsetExpr
= node
->Nth(6);
1551 wxExpr
*spacingExpr
= node
->Nth(7);
1554 arrowType
= (int)type_expr
->IntegerValue();
1556 arrowEnd
= (int)end_expr
->IntegerValue();
1558 xOffset
= dist_expr
->RealValue();
1560 arrowSize
= size_expr
->RealValue();
1562 arrowName
= name_expr
->StringValue();
1564 arrowId
= id_expr
->IntegerValue();
1567 arrowId
= wxNewId();
1569 wxRegisterId(arrowId
);
1571 wxArrowHead
*arrowHead
= AddArrow(arrowType
, arrowEnd
, arrowSize
, xOffset
, arrowName
, NULL
, arrowId
);
1573 arrowHead
->SetYOffset(yOffsetExpr
->RealValue());
1575 arrowHead
->SetSpacing(spacingExpr
->RealValue());
1583 void wxLineShape::Copy(wxShape
& copy
)
1585 wxShape::Copy(copy
);
1587 wxASSERT( copy
.IsKindOf(CLASSINFO(wxLineShape
)) );
1589 wxLineShape
& lineCopy
= (wxLineShape
&) copy
;
1591 lineCopy
.m_to
= m_to
;
1592 lineCopy
.m_from
= m_from
;
1593 lineCopy
.m_attachmentTo
= m_attachmentTo
;
1594 lineCopy
.m_attachmentFrom
= m_attachmentFrom
;
1595 lineCopy
.m_isSpline
= m_isSpline
;
1596 lineCopy
.m_alignmentStart
= m_alignmentStart
;
1597 lineCopy
.m_alignmentEnd
= m_alignmentEnd
;
1598 lineCopy
.m_maintainStraightLines
= m_maintainStraightLines
;
1599 lineCopy
.m_lineOrientations
.Clear();
1601 wxNode
*node
= m_lineOrientations
.GetFirst();
1604 lineCopy
.m_lineOrientations
.Append(node
->GetData());
1605 node
= node
->GetNext();
1608 if (lineCopy
.m_lineControlPoints
)
1610 ClearPointList(*lineCopy
.m_lineControlPoints
);
1611 delete lineCopy
.m_lineControlPoints
;
1614 lineCopy
.m_lineControlPoints
= new wxList
;
1616 node
= m_lineControlPoints
->GetFirst();
1619 wxRealPoint
*point
= (wxRealPoint
*)node
->GetData();
1620 wxRealPoint
*new_point
= new wxRealPoint(point
->x
, point
->y
);
1621 lineCopy
.m_lineControlPoints
->Append((wxObject
*) new_point
);
1622 node
= node
->GetNext();
1626 lineCopy
.ClearArrowsAtPosition(-1);
1627 node
= m_arcArrows
.GetFirst();
1630 wxArrowHead
*arrow
= (wxArrowHead
*)node
->GetData();
1631 lineCopy
.m_arcArrows
.Append(new wxArrowHead(*arrow
));
1632 node
= node
->GetNext();
1636 // Override select, to create/delete temporary label-moving objects
1637 void wxLineShape::Select(bool select
, wxDC
* dc
)
1639 wxShape::Select(select
, dc
);
1642 for (int i
= 0; i
< 3; i
++)
1644 wxNode
*node
= m_regions
.Item(i
);
1647 wxShapeRegion
*region
= (wxShapeRegion
*)node
->GetData();
1648 if (region
->m_formattedText
.GetCount() > 0)
1650 double w
, h
, x
, y
, xx
, yy
;
1651 region
->GetSize(&w
, &h
);
1652 region
->GetPosition(&x
, &y
);
1653 GetLabelPosition(i
, &xx
, &yy
);
1654 if (m_labelObjects
[i
])
1656 m_labelObjects
[i
]->Select(FALSE
);
1657 m_labelObjects
[i
]->RemoveFromCanvas(m_canvas
);
1658 delete m_labelObjects
[i
];
1660 m_labelObjects
[i
] = OnCreateLabelShape(this, region
, w
, h
);
1661 m_labelObjects
[i
]->AddToCanvas(m_canvas
);
1662 m_labelObjects
[i
]->Show(TRUE
);
1664 m_labelObjects
[i
]->Move(*dc
, (double)(x
+ xx
), (double)(y
+ yy
));
1665 m_labelObjects
[i
]->Select(TRUE
, dc
);
1672 for (int i
= 0; i
< 3; i
++)
1674 if (m_labelObjects
[i
])
1676 m_labelObjects
[i
]->Select(FALSE
, dc
);
1677 m_labelObjects
[i
]->Erase(*dc
);
1678 m_labelObjects
[i
]->RemoveFromCanvas(m_canvas
);
1679 delete m_labelObjects
[i
];
1680 m_labelObjects
[i
] = NULL
;
1687 * Line control point
1691 IMPLEMENT_DYNAMIC_CLASS(wxLineControlPoint
, wxControlPoint
)
1693 wxLineControlPoint::wxLineControlPoint(wxShapeCanvas
*theCanvas
, wxShape
*object
, double size
, double x
, double y
, int the_type
):
1694 wxControlPoint(theCanvas
, object
, size
, x
, y
, the_type
)
1702 wxLineControlPoint::~wxLineControlPoint()
1706 void wxLineControlPoint::OnDraw(wxDC
& dc
)
1708 wxRectangleShape::OnDraw(dc
);
1711 // Implement movement of Line point
1712 void wxLineControlPoint::OnDragLeft(bool draw
, double x
, double y
, int keys
, int attachment
)
1714 m_shape
->GetEventHandler()->OnSizingDragLeft(this, draw
, x
, y
, keys
, attachment
);
1717 void wxLineControlPoint::OnBeginDragLeft(double x
, double y
, int keys
, int attachment
)
1719 m_shape
->GetEventHandler()->OnSizingBeginDragLeft(this, x
, y
, keys
, attachment
);
1722 void wxLineControlPoint::OnEndDragLeft(double x
, double y
, int keys
, int attachment
)
1724 m_shape
->GetEventHandler()->OnSizingEndDragLeft(this, x
, y
, keys
, attachment
);
1727 // Control points ('handles') redirect control to the actual shape, to make it easier
1728 // to override sizing behaviour.
1729 void wxLineShape::OnSizingDragLeft(wxControlPoint
* pt
, bool WXUNUSED(draw
), double x
, double y
, int WXUNUSED(keys
), int WXUNUSED(attachment
))
1731 wxLineControlPoint
* lpt
= (wxLineControlPoint
*) pt
;
1733 wxClientDC
dc(GetCanvas());
1734 GetCanvas()->PrepareDC(dc
);
1736 dc
.SetLogicalFunction(OGLRBLF
);
1738 wxPen
dottedPen(wxColour(0, 0, 0), 1, wxDOT
);
1739 dc
.SetPen(dottedPen
);
1740 dc
.SetBrush((* wxTRANSPARENT_BRUSH
));
1742 if (lpt
->m_type
== CONTROL_POINT_LINE
)
1744 m_canvas
->Snap(&x
, &y
);
1746 lpt
->SetX(x
); lpt
->SetY(y
);
1747 lpt
->m_point
->x
= x
; lpt
->m_point
->y
= y
;
1749 wxLineShape
*lineShape
= (wxLineShape
*)this;
1751 wxPen
*old_pen
= lineShape
->GetPen();
1752 wxBrush
*old_brush
= lineShape
->GetBrush();
1754 wxPen
dottedPen(wxColour(0, 0, 0), 1, wxDOT
);
1755 lineShape
->SetPen(& dottedPen
);
1756 lineShape
->SetBrush(wxTRANSPARENT_BRUSH
);
1758 lineShape
->GetEventHandler()->OnMoveLink(dc
, FALSE
);
1760 lineShape
->SetPen(old_pen
);
1761 lineShape
->SetBrush(old_brush
);
1764 if (lpt
->m_type
== CONTROL_POINT_ENDPOINT_FROM
|| lpt
->m_type
== CONTROL_POINT_ENDPOINT_TO
)
1766 // lpt->SetX(x); lpt->SetY(y);
1771 void wxLineShape::OnSizingBeginDragLeft(wxControlPoint
* pt
, double x
, double y
, int WXUNUSED(keys
), int WXUNUSED(attachment
))
1773 wxLineControlPoint
* lpt
= (wxLineControlPoint
*) pt
;
1775 wxClientDC
dc(GetCanvas());
1776 GetCanvas()->PrepareDC(dc
);
1778 wxLineShape
*lineShape
= (wxLineShape
*)this;
1779 if (lpt
->m_type
== CONTROL_POINT_LINE
)
1781 lpt
->m_originalPos
= * (lpt
->m_point
);
1782 m_canvas
->Snap(&x
, &y
);
1786 // Redraw start and end objects because we've left holes
1787 // when erasing the line
1788 lineShape
->GetFrom()->OnDraw(dc
);
1789 lineShape
->GetFrom()->OnDrawContents(dc
);
1790 lineShape
->GetTo()->OnDraw(dc
);
1791 lineShape
->GetTo()->OnDrawContents(dc
);
1793 this->SetDisableLabel(TRUE
);
1794 dc
.SetLogicalFunction(OGLRBLF
);
1796 lpt
->m_xpos
= x
; lpt
->m_ypos
= y
;
1797 lpt
->m_point
->x
= x
; lpt
->m_point
->y
= y
;
1799 wxPen
*old_pen
= lineShape
->GetPen();
1800 wxBrush
*old_brush
= lineShape
->GetBrush();
1802 wxPen
dottedPen(wxColour(0, 0, 0), 1, wxDOT
);
1803 lineShape
->SetPen(& dottedPen
);
1804 lineShape
->SetBrush(wxTRANSPARENT_BRUSH
);
1806 lineShape
->GetEventHandler()->OnMoveLink(dc
, FALSE
);
1808 lineShape
->SetPen(old_pen
);
1809 lineShape
->SetBrush(old_brush
);
1812 if (lpt
->m_type
== CONTROL_POINT_ENDPOINT_FROM
|| lpt
->m_type
== CONTROL_POINT_ENDPOINT_TO
)
1814 m_canvas
->SetCursor(wxCursor(wxCURSOR_BULLSEYE
));
1815 lpt
->m_oldCursor
= wxSTANDARD_CURSOR
;
1819 void wxLineShape::OnSizingEndDragLeft(wxControlPoint
* pt
, double x
, double y
, int WXUNUSED(keys
), int WXUNUSED(attachment
))
1821 wxLineControlPoint
* lpt
= (wxLineControlPoint
*) pt
;
1823 wxClientDC
dc(GetCanvas());
1824 GetCanvas()->PrepareDC(dc
);
1826 this->SetDisableLabel(FALSE
);
1827 wxLineShape
*lineShape
= (wxLineShape
*)this;
1829 if (lpt
->m_type
== CONTROL_POINT_LINE
)
1831 m_canvas
->Snap(&x
, &y
);
1833 wxRealPoint pt
= wxRealPoint(x
, y
);
1835 // Move the control point back to where it was;
1836 // MoveControlPoint will move it to the new position
1837 // if it decides it wants. We only moved the position
1838 // during user feedback so we could redraw the line
1839 // as it changed shape.
1840 lpt
->m_xpos
= lpt
->m_originalPos
.x
; lpt
->m_ypos
= lpt
->m_originalPos
.y
;
1841 lpt
->m_point
->x
= lpt
->m_originalPos
.x
; lpt
->m_point
->y
= lpt
->m_originalPos
.y
;
1843 OnMoveMiddleControlPoint(dc
, lpt
, pt
);
1845 if (lpt
->m_type
== CONTROL_POINT_ENDPOINT_FROM
)
1847 if (lpt
->m_oldCursor
)
1848 m_canvas
->SetCursor(* lpt
->m_oldCursor
);
1852 // lpt->m_xpos = x; lpt->m_ypos = y;
1854 if (lineShape
->GetFrom())
1856 lineShape
->GetFrom()->MoveLineToNewAttachment(dc
, lineShape
, x
, y
);
1859 if (lpt
->m_type
== CONTROL_POINT_ENDPOINT_TO
)
1861 if (lpt
->m_oldCursor
)
1862 m_canvas
->SetCursor(* lpt
->m_oldCursor
);
1864 // lpt->m_xpos = x; lpt->m_ypos = y;
1866 if (lineShape
->GetTo())
1868 lineShape
->GetTo()->MoveLineToNewAttachment(dc
, lineShape
, x
, y
);
1875 for (i
= 0; i
< lineShape
->GetLineControlPoints()->GetCount(); i
++)
1876 if (((wxRealPoint
*)(lineShape
->GetLineControlPoints()->Item(i
)->GetData())) == lpt
->m_point
)
1879 // N.B. in OnMoveControlPoint, an event handler in Hardy could have deselected
1880 // the line and therefore deleted 'this'. -> GPF, intermittently.
1881 // So assume at this point that we've been blown away.
1883 lineShape
->OnMoveControlPoint(i
+1, x
, y
);
1887 // This is called only when a non-end control point is moved.
1888 bool wxLineShape::OnMoveMiddleControlPoint(wxDC
& dc
, wxLineControlPoint
* lpt
, const wxRealPoint
& pt
)
1890 lpt
->m_xpos
= pt
.x
; lpt
->m_ypos
= pt
.y
;
1891 lpt
->m_point
->x
= pt
.x
; lpt
->m_point
->y
= pt
.y
;
1893 GetEventHandler()->OnMoveLink(dc
);
1898 // Implement movement of endpoint to a new attachment
1899 // OBSOLETE: done by dragging with the left button.
1902 void wxLineControlPoint::OnDragRight(bool draw
, double x
, double y
, int keys
, int attachment
)
1904 if (m_type
== CONTROL_POINT_ENDPOINT_FROM
|| m_type
== CONTROL_POINT_ENDPOINT_TO
)
1906 m_xpos
= x
; m_ypos
= y
;
1910 void wxLineControlPoint::OnBeginDragRight(double x
, double y
, int keys
, int attachment
)
1912 wxClientDC
dc(GetCanvas());
1913 GetCanvas()->PrepareDC(dc
);
1915 wxLineShape
*lineShape
= (wxLineShape
*)m_shape
;
1916 if (m_type
== CONTROL_POINT_ENDPOINT_FROM
|| m_type
== CONTROL_POINT_ENDPOINT_TO
)
1919 lineShape
->GetEventHandler()->OnDraw(dc
);
1920 if (m_type
== CONTROL_POINT_ENDPOINT_FROM
)
1922 lineShape
->GetFrom()->GetEventHandler()->OnDraw(dc
);
1923 lineShape
->GetFrom()->GetEventHandler()->OnDrawContents(dc
);
1927 lineShape
->GetTo()->GetEventHandler()->OnDraw(dc
);
1928 lineShape
->GetTo()->GetEventHandler()->OnDrawContents(dc
);
1930 m_canvas
->SetCursor(wxCursor(wxCURSOR_BULLSEYE
));
1931 m_oldCursor
= wxSTANDARD_CURSOR
;
1935 void wxLineControlPoint::OnEndDragRight(double x
, double y
, int keys
, int attachment
)
1937 wxClientDC
dc(GetCanvas());
1938 GetCanvas()->PrepareDC(dc
);
1940 wxLineShape
*lineShape
= (wxLineShape
*)m_shape
;
1941 if (m_type
== CONTROL_POINT_ENDPOINT_FROM
)
1944 m_canvas
->SetCursor(m_oldCursor
);
1946 m_xpos
= x
; m_ypos
= y
;
1948 if (lineShape
->GetFrom())
1950 lineShape
->GetFrom()->EraseLinks(dc
);
1955 if (lineShape
->GetFrom()->HitTest(x
, y
, &new_attachment
, &distance
))
1956 lineShape
->SetAttachments(new_attachment
, lineShape
->GetAttachmentTo());
1958 lineShape
->GetFrom()->MoveLinks(dc
);
1961 if (m_type
== CONTROL_POINT_ENDPOINT_TO
)
1964 m_canvas
->SetCursor(m_oldCursor
);
1967 m_xpos
= x
; m_ypos
= y
;
1969 if (lineShape
->GetTo())
1971 lineShape
->GetTo()->EraseLinks(dc
);
1975 if (lineShape
->GetTo()->HitTest(x
, y
, &new_attachment
, &distance
))
1976 lineShape
->SetAttachments(lineShape
->GetAttachmentFrom(), new_attachment
);
1978 lineShape
->GetTo()->MoveLinks(dc
);
1982 for (i
= 0; i
< lineShape
->GetLineControlPoints()->GetCount(); i
++)
1983 if (((wxRealPoint
*)(lineShape
->GetLineControlPoints()->Item(i
)->GetData())) == m_point
)
1985 lineShape
->OnMoveControlPoint(i
+1, x
, y
);
1986 if (!m_canvas
->GetQuickEditMode()) m_canvas
->Redraw(dc
);
1991 * Get the point on the given line (x1, y1) (x2, y2)
1992 * distance 'length' along from the end,
1993 * returned values in x and y
1996 void GetPointOnLine(double x1
, double y1
, double x2
, double y2
,
1997 double length
, double *x
, double *y
)
1999 double l
= (double)sqrt((x2
- x1
)*(x2
- x1
) + (y2
- y1
)*(y2
- y1
));
2004 double i_bar
= (x2
- x1
)/l
;
2005 double j_bar
= (y2
- y1
)/l
;
2007 *x
= (- length
*i_bar
) + x2
;
2008 *y
= (- length
*j_bar
) + y2
;
2011 wxArrowHead
*wxLineShape::AddArrow(WXTYPE type
, int end
, double size
, double xOffset
,
2012 const wxString
& name
, wxPseudoMetaFile
*mf
, long arrowId
)
2014 wxArrowHead
*arrow
= new wxArrowHead(type
, end
, size
, xOffset
, name
, mf
, arrowId
);
2015 m_arcArrows
.Append(arrow
);
2020 * Add arrowhead at a particular position in the arrowhead list.
2022 bool wxLineShape::AddArrowOrdered(wxArrowHead
*arrow
, wxList
& referenceList
, int end
)
2024 wxNode
*refNode
= referenceList
.GetFirst();
2025 wxNode
*currNode
= m_arcArrows
.GetFirst();
2026 wxString
targetName(arrow
->GetName());
2027 if (!refNode
) return FALSE
;
2029 // First check whether we need to insert in front of list,
2030 // because this arrowhead is the first in the reference
2031 // list and should therefore be first in the current list.
2032 wxArrowHead
*refArrow
= (wxArrowHead
*)refNode
->GetData();
2033 if (refArrow
->GetName() == targetName
)
2035 m_arcArrows
.Insert(arrow
);
2039 while (refNode
&& currNode
)
2041 wxArrowHead
*currArrow
= (wxArrowHead
*)currNode
->GetData();
2042 refArrow
= (wxArrowHead
*)refNode
->GetData();
2044 // Matching: advance current arrow pointer
2045 if ((currArrow
->GetArrowEnd() == end
) &&
2046 (currArrow
->GetName() == refArrow
->GetName()))
2048 currNode
= currNode
->GetNext(); // Could be NULL now
2050 currArrow
= (wxArrowHead
*)currNode
->GetData();
2053 // Check if we're at the correct position in the
2055 if (targetName
== refArrow
->GetName())
2058 m_arcArrows
.Insert(currNode
, arrow
);
2060 m_arcArrows
.Append(arrow
);
2063 refNode
= refNode
->GetNext();
2065 m_arcArrows
.Append(arrow
);
2069 void wxLineShape::ClearArrowsAtPosition(int end
)
2071 wxNode
*node
= m_arcArrows
.GetFirst();
2074 wxArrowHead
*arrow
= (wxArrowHead
*)node
->GetData();
2075 wxNode
*next
= node
->GetNext();
2084 case ARROW_POSITION_START
:
2086 if (arrow
->GetArrowEnd() == ARROW_POSITION_START
)
2093 case ARROW_POSITION_END
:
2095 if (arrow
->GetArrowEnd() == ARROW_POSITION_END
)
2102 case ARROW_POSITION_MIDDLE
:
2104 if (arrow
->GetArrowEnd() == ARROW_POSITION_MIDDLE
)
2116 bool wxLineShape::ClearArrow(const wxString
& name
)
2118 wxNode
*node
= m_arcArrows
.GetFirst();
2121 wxArrowHead
*arrow
= (wxArrowHead
*)node
->GetData();
2122 if (arrow
->GetName() == name
)
2128 node
= node
->GetNext();
2134 * Finds an arrowhead at the given position (if -1, any position)
2138 wxArrowHead
*wxLineShape::FindArrowHead(int position
, const wxString
& name
)
2140 wxNode
*node
= m_arcArrows
.GetFirst();
2143 wxArrowHead
*arrow
= (wxArrowHead
*)node
->GetData();
2144 if (((position
== -1) || (position
== arrow
->GetArrowEnd())) &&
2145 (arrow
->GetName() == name
))
2147 node
= node
->GetNext();
2152 wxArrowHead
*wxLineShape::FindArrowHead(long arrowId
)
2154 wxNode
*node
= m_arcArrows
.GetFirst();
2157 wxArrowHead
*arrow
= (wxArrowHead
*)node
->GetData();
2158 if (arrowId
== arrow
->GetId())
2160 node
= node
->GetNext();
2166 * Deletes an arrowhead at the given position (if -1, any position)
2170 bool wxLineShape::DeleteArrowHead(int position
, const wxString
& name
)
2172 wxNode
*node
= m_arcArrows
.GetFirst();
2175 wxArrowHead
*arrow
= (wxArrowHead
*)node
->GetData();
2176 if (((position
== -1) || (position
== arrow
->GetArrowEnd())) &&
2177 (arrow
->GetName() == name
))
2183 node
= node
->GetNext();
2188 // Overloaded DeleteArrowHead: pass arrowhead id.
2189 bool wxLineShape::DeleteArrowHead(long id
)
2191 wxNode
*node
= m_arcArrows
.GetFirst();
2194 wxArrowHead
*arrow
= (wxArrowHead
*)node
->GetData();
2195 if (arrow
->GetId() == id
)
2201 node
= node
->GetNext();
2207 * Calculate the minimum width a line
2208 * occupies, for the purposes of drawing lines in tools.
2212 double wxLineShape::FindMinimumWidth()
2214 double minWidth
= 0.0;
2215 wxNode
*node
= m_arcArrows
.GetFirst();
2218 wxArrowHead
*arrowHead
= (wxArrowHead
*)node
->GetData();
2219 minWidth
+= arrowHead
->GetSize();
2220 if (node
->GetNext())
2221 minWidth
+= arrowHead
->GetSpacing();
2223 node
= node
->GetNext();
2225 // We have ABSOLUTE minimum now. So
2226 // scale it to give it reasonable aesthetics
2227 // when drawing with line.
2229 minWidth
= (double)(minWidth
* 1.4);
2233 SetEnds(0.0, 0.0, minWidth
, 0.0);
2239 // Find which position we're talking about at this (x, y).
2240 // Returns ARROW_POSITION_START, ARROW_POSITION_MIDDLE, ARROW_POSITION_END
2241 int wxLineShape::FindLinePosition(double x
, double y
)
2243 double startX
, startY
, endX
, endY
;
2244 GetEnds(&startX
, &startY
, &endX
, &endY
);
2246 // Find distances from centre, start and end. The smallest wins.
2247 double centreDistance
= (double)(sqrt((x
- m_xpos
)*(x
- m_xpos
) + (y
- m_ypos
)*(y
- m_ypos
)));
2248 double startDistance
= (double)(sqrt((x
- startX
)*(x
- startX
) + (y
- startY
)*(y
- startY
)));
2249 double endDistance
= (double)(sqrt((x
- endX
)*(x
- endX
) + (y
- endY
)*(y
- endY
)));
2251 if (centreDistance
< startDistance
&& centreDistance
< endDistance
)
2252 return ARROW_POSITION_MIDDLE
;
2253 else if (startDistance
< endDistance
)
2254 return ARROW_POSITION_START
;
2256 return ARROW_POSITION_END
;
2259 // Set alignment flags
2260 void wxLineShape::SetAlignmentOrientation(bool isEnd
, bool isHoriz
)
2264 if (isHoriz
&& ((m_alignmentEnd
& LINE_ALIGNMENT_HORIZ
) != LINE_ALIGNMENT_HORIZ
))
2265 m_alignmentEnd
|= LINE_ALIGNMENT_HORIZ
;
2266 else if (!isHoriz
&& ((m_alignmentEnd
& LINE_ALIGNMENT_HORIZ
) == LINE_ALIGNMENT_HORIZ
))
2267 m_alignmentEnd
-= LINE_ALIGNMENT_HORIZ
;
2271 if (isHoriz
&& ((m_alignmentStart
& LINE_ALIGNMENT_HORIZ
) != LINE_ALIGNMENT_HORIZ
))
2272 m_alignmentStart
|= LINE_ALIGNMENT_HORIZ
;
2273 else if (!isHoriz
&& ((m_alignmentStart
& LINE_ALIGNMENT_HORIZ
) == LINE_ALIGNMENT_HORIZ
))
2274 m_alignmentStart
-= LINE_ALIGNMENT_HORIZ
;
2278 void wxLineShape::SetAlignmentType(bool isEnd
, int alignType
)
2282 if (alignType
== LINE_ALIGNMENT_TO_NEXT_HANDLE
)
2284 if ((m_alignmentEnd
& LINE_ALIGNMENT_TO_NEXT_HANDLE
) != LINE_ALIGNMENT_TO_NEXT_HANDLE
)
2285 m_alignmentEnd
|= LINE_ALIGNMENT_TO_NEXT_HANDLE
;
2287 else if ((m_alignmentEnd
& LINE_ALIGNMENT_TO_NEXT_HANDLE
) == LINE_ALIGNMENT_TO_NEXT_HANDLE
)
2288 m_alignmentEnd
-= LINE_ALIGNMENT_TO_NEXT_HANDLE
;
2292 if (alignType
== LINE_ALIGNMENT_TO_NEXT_HANDLE
)
2294 if ((m_alignmentStart
& LINE_ALIGNMENT_TO_NEXT_HANDLE
) != LINE_ALIGNMENT_TO_NEXT_HANDLE
)
2295 m_alignmentStart
|= LINE_ALIGNMENT_TO_NEXT_HANDLE
;
2297 else if ((m_alignmentStart
& LINE_ALIGNMENT_TO_NEXT_HANDLE
) == LINE_ALIGNMENT_TO_NEXT_HANDLE
)
2298 m_alignmentStart
-= LINE_ALIGNMENT_TO_NEXT_HANDLE
;
2302 bool wxLineShape::GetAlignmentOrientation(bool isEnd
)
2305 return ((m_alignmentEnd
& LINE_ALIGNMENT_HORIZ
) == LINE_ALIGNMENT_HORIZ
);
2307 return ((m_alignmentStart
& LINE_ALIGNMENT_HORIZ
) == LINE_ALIGNMENT_HORIZ
);
2310 int wxLineShape::GetAlignmentType(bool isEnd
)
2313 return (m_alignmentEnd
& LINE_ALIGNMENT_TO_NEXT_HANDLE
);
2315 return (m_alignmentStart
& LINE_ALIGNMENT_TO_NEXT_HANDLE
);
2318 wxRealPoint
*wxLineShape::GetNextControlPoint(wxShape
*nodeObject
)
2320 int n
= m_lineControlPoints
->GetCount();
2322 if (m_to
== nodeObject
)
2324 // Must be END of line, so we want (n - 1)th control point.
2325 // But indexing ends at n-1, so subtract 2.
2329 wxNode
*node
= m_lineControlPoints
->Item(nn
);
2332 return (wxRealPoint
*)node
->GetData();
2343 IMPLEMENT_DYNAMIC_CLASS(wxArrowHead
, wxObject
)
2345 wxArrowHead::wxArrowHead(WXTYPE type
, int end
, double size
, double dist
, const wxString
& name
,
2346 wxPseudoMetaFile
*mf
, long arrowId
)
2348 m_arrowType
= type
; m_arrowEnd
= end
; m_arrowSize
= size
;
2360 wxArrowHead::wxArrowHead(wxArrowHead
& toCopy
)
2362 m_arrowType
= toCopy
.m_arrowType
; m_arrowEnd
= toCopy
.GetArrowEnd();
2363 m_arrowSize
= toCopy
.m_arrowSize
;
2364 m_xOffset
= toCopy
.m_xOffset
;
2365 m_yOffset
= toCopy
.m_yOffset
;
2366 m_spacing
= toCopy
.m_spacing
;
2367 m_arrowName
= toCopy
.m_arrowName
;
2368 if (toCopy
.m_metaFile
)
2369 m_metaFile
= new wxPseudoMetaFile(*(toCopy
.m_metaFile
));
2375 wxArrowHead::~wxArrowHead()
2377 if (m_metaFile
) delete m_metaFile
;
2380 void wxArrowHead::SetSize(double size
)
2383 if ((m_arrowType
== ARROW_METAFILE
) && m_metaFile
)
2385 double oldWidth
= m_metaFile
->m_width
;
2386 if (oldWidth
== 0.0)
2389 double scale
= (double)(size
/oldWidth
);
2391 m_metaFile
->Scale(scale
, scale
);
2395 // Can override this to create a different class of label shape
2396 wxLabelShape
* wxLineShape::OnCreateLabelShape(wxLineShape
*parent
, wxShapeRegion
*region
, double w
, double h
)
2398 return new wxLabelShape(parent
, region
, w
, h
);
2406 IMPLEMENT_DYNAMIC_CLASS(wxLabelShape
, wxRectangleShape
)
2408 wxLabelShape::wxLabelShape(wxLineShape
*parent
, wxShapeRegion
*region
, double w
, double h
):wxRectangleShape(w
, h
)
2410 m_lineShape
= parent
;
2411 m_shapeRegion
= region
;
2412 SetPen(wxThePenList
->FindOrCreatePen(wxColour(0, 0, 0), 1, wxDOT
));
2415 wxLabelShape::~wxLabelShape()
2419 void wxLabelShape::OnDraw(wxDC
& dc
)
2421 if (m_lineShape
&& !m_lineShape
->GetDrawHandles())
2424 double x1
= (double)(m_xpos
- m_width
/2.0);
2425 double y1
= (double)(m_ypos
- m_height
/2.0);
2429 if (m_pen
->GetWidth() == 0)
2430 dc
.SetPen(* g_oglTransparentPen
);
2434 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
2436 if (m_cornerRadius
> 0.0)
2437 dc
.DrawRoundedRectangle(WXROUND(x1
), WXROUND(y1
), WXROUND(m_width
), WXROUND(m_height
), m_cornerRadius
);
2439 dc
.DrawRectangle(WXROUND(x1
), WXROUND(y1
), WXROUND(m_width
), WXROUND(m_height
));
2442 void wxLabelShape::OnDrawContents(wxDC
& WXUNUSED(dc
))
2446 void wxLabelShape::OnDragLeft(bool draw
, double x
, double y
, int keys
, int attachment
)
2448 wxRectangleShape::OnDragLeft(draw
, x
, y
, keys
, attachment
);
2451 void wxLabelShape::OnBeginDragLeft(double x
, double y
, int keys
, int attachment
)
2453 wxRectangleShape::OnBeginDragLeft(x
, y
, keys
, attachment
);
2456 void wxLabelShape::OnEndDragLeft(double x
, double y
, int keys
, int attachment
)
2458 wxRectangleShape::OnEndDragLeft(x
, y
, keys
, attachment
);
2461 bool wxLabelShape::OnMovePre(wxDC
& dc
, double x
, double y
, double old_x
, double old_y
, bool display
)
2463 return m_lineShape
->OnLabelMovePre(dc
, this, x
, y
, old_x
, old_y
, display
);
2466 bool wxLineShape::OnLabelMovePre(wxDC
& dc
, wxLabelShape
* labelShape
, double x
, double y
, double WXUNUSED(old_x
), double WXUNUSED(old_y
), bool WXUNUSED(display
))
2468 labelShape
->m_shapeRegion
->SetSize(labelShape
->GetWidth(), labelShape
->GetHeight());
2470 // Find position in line's region list
2472 wxNode
*node
= GetRegions().GetFirst();
2475 if (labelShape
->m_shapeRegion
== (wxShapeRegion
*)node
->GetData())
2479 node
= node
->GetNext();
2484 GetLabelPosition(i
, &xx
, &yy
);
2485 // Set the region's offset, relative to the default position for
2487 labelShape
->m_shapeRegion
->SetPosition((double)(x
- xx
), (double)(y
- yy
));
2489 labelShape
->SetX(x
);
2490 labelShape
->SetY(y
);
2492 // Need to reformat to fit region.
2493 if (labelShape
->m_shapeRegion
->GetText())
2496 wxString
s(labelShape
->m_shapeRegion
->GetText());
2497 labelShape
->FormatText(dc
, s
, i
);
2498 DrawRegion(dc
, labelShape
->m_shapeRegion
, xx
, yy
);
2503 // Divert left and right clicks to line object
2504 void wxLabelShape::OnLeftClick(double x
, double y
, int keys
, int attachment
)
2506 m_lineShape
->GetEventHandler()->OnLeftClick(x
, y
, keys
, attachment
);
2509 void wxLabelShape::OnRightClick(double x
, double y
, int keys
, int attachment
)
2511 m_lineShape
->GetEventHandler()->OnRightClick(x
, y
, keys
, attachment
);