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>
28 #include <wx/wxexpr.h>
48 IMPLEMENT_DYNAMIC_CLASS(wxLineShape
, wxShape
)
50 wxLineShape::wxLineShape()
52 m_sensitivity
= OP_CLICK_LEFT
| OP_CLICK_RIGHT
;
57 m_actualTextWidth = 0.0;
58 m_actualTextHeight = 0.0;
63 m_arrowSpacing
= 5.0; // For the moment, don't bother saving this to file.
64 m_ignoreArrowOffsets
= FALSE
;
66 m_maintainStraightLines
= FALSE
;
70 m_lineControlPoints
= NULL
;
72 // Clear any existing regions (created in an earlier constructor)
73 // and make the three line regions.
75 wxShapeRegion
*newRegion
= new wxShapeRegion
;
76 newRegion
->SetName("Middle");
77 newRegion
->SetSize(150, 50);
78 m_regions
.Append((wxObject
*)newRegion
);
80 newRegion
= new wxShapeRegion
;
81 newRegion
->SetName("Start");
82 newRegion
->SetSize(150, 50);
83 m_regions
.Append((wxObject
*)newRegion
);
85 newRegion
= new wxShapeRegion
;
86 newRegion
->SetName("End");
87 newRegion
->SetSize(150, 50);
88 m_regions
.Append((wxObject
*)newRegion
);
90 for (int i
= 0; i
< 3; i
++)
91 m_labelObjects
[i
] = NULL
;
94 wxLineShape::~wxLineShape()
96 if (m_lineControlPoints
)
98 ClearPointList(*m_lineControlPoints
);
99 delete m_lineControlPoints
;
101 for (int i
= 0; i
< 3; i
++)
103 if (m_labelObjects
[i
])
105 m_labelObjects
[i
]->Select(FALSE
);
106 m_labelObjects
[i
]->RemoveFromCanvas(m_canvas
);
107 delete m_labelObjects
[i
];
108 m_labelObjects
[i
] = NULL
;
111 ClearArrowsAtPosition(-1);
114 void wxLineShape::MakeLineControlPoints(int n
)
116 if (m_lineControlPoints
)
118 ClearPointList(*m_lineControlPoints
);
119 delete m_lineControlPoints
;
121 m_lineControlPoints
= new wxList
;
124 for (i
= 0; i
< n
; i
++)
126 wxRealPoint
*point
= new wxRealPoint(-999, -999);
127 m_lineControlPoints
->Append((wxObject
*) point
);
131 wxNode
*wxLineShape::InsertLineControlPoint(wxDC
* dc
)
136 wxNode
*last
= m_lineControlPoints
->Last();
137 wxNode
*second_last
= last
->Previous();
138 wxRealPoint
*last_point
= (wxRealPoint
*)last
->Data();
139 wxRealPoint
*second_last_point
= (wxRealPoint
*)second_last
->Data();
141 // Choose a point half way between the last and penultimate points
142 double line_x
= ((last_point
->x
+ second_last_point
->x
)/2);
143 double line_y
= ((last_point
->y
+ second_last_point
->y
)/2);
145 wxRealPoint
*point
= new wxRealPoint(line_x
, line_y
);
146 wxNode
*node
= m_lineControlPoints
->Insert(last
, (wxObject
*) point
);
150 bool wxLineShape::DeleteLineControlPoint()
152 if (m_lineControlPoints
->Number() < 3)
155 wxNode
*last
= m_lineControlPoints
->Last();
156 wxNode
*second_last
= last
->Previous();
158 wxRealPoint
*second_last_point
= (wxRealPoint
*)second_last
->Data();
159 delete second_last_point
;
165 void wxLineShape::Initialise()
167 if (m_lineControlPoints
)
169 // Just move the first and last control points
170 wxNode
*first
= m_lineControlPoints
->First();
171 wxRealPoint
*first_point
= (wxRealPoint
*)first
->Data();
173 wxNode
*last
= m_lineControlPoints
->Last();
174 wxRealPoint
*last_point
= (wxRealPoint
*)last
->Data();
176 // If any of the line points are at -999, we must
177 // initialize them by placing them half way between the first
179 wxNode
*node
= first
->Next();
182 wxRealPoint
*point
= (wxRealPoint
*)node
->Data();
183 if (point
->x
== -999)
185 double x1
, y1
, x2
, y2
;
186 if (first_point
->x
< last_point
->x
)
187 { x1
= first_point
->x
; x2
= last_point
->x
; }
189 { x2
= first_point
->x
; x1
= last_point
->x
; }
191 if (first_point
->y
< last_point
->y
)
192 { y1
= first_point
->y
; y2
= last_point
->y
; }
194 { y2
= first_point
->y
; y1
= last_point
->y
; }
196 point
->x
= ((x2
- x1
)/2 + x1
);
197 point
->y
= ((y2
- y1
)/2 + y1
);
204 // Format a text string according to the region size, adding
205 // strings with positions to region text list
206 void wxLineShape::FormatText(wxDC
& dc
, const wxString
& s
, int i
)
211 if (m_regions
.Number() < 1)
213 wxNode
*node
= m_regions
.Nth(i
);
217 wxShapeRegion
*region
= (wxShapeRegion
*)node
->Data();
219 dc
.SetFont(* region
->GetFont());
221 region
->GetSize(&w
, &h
);
222 // Initialize the size if zero
223 if (((w
== 0) || (h
== 0)) && (strlen(s
) > 0))
226 region
->SetSize(w
, h
);
229 wxStringList
*string_list
= oglFormatText(dc
, s
, (w
-5), (h
-5), region
->GetFormatMode());
230 node
= string_list
->First();
233 char *s
= (char *)node
->Data();
234 wxShapeTextLine
*line
= new wxShapeTextLine(0.0, 0.0, s
);
235 region
->GetFormattedText().Append((wxObject
*)line
);
241 if (region
->GetFormatMode() & FORMAT_SIZE_TO_CONTENTS
)
243 oglGetCentredTextExtent(dc
, &(region
->GetFormattedText()), m_xpos
, m_ypos
, w
, h
, &actualW
, &actualH
);
244 if ((actualW
!= w
) || (actualH
!= h
))
247 GetLabelPosition(i
, &xx
, &yy
);
248 EraseRegion(dc
, region
, xx
, yy
);
249 if (m_labelObjects
[i
])
251 m_labelObjects
[i
]->Select(FALSE
, &dc
);
252 m_labelObjects
[i
]->Erase(dc
);
253 m_labelObjects
[i
]->SetSize(actualW
, actualH
);
256 region
->SetSize(actualW
, actualH
);
258 if (m_labelObjects
[i
])
260 m_labelObjects
[i
]->Select(TRUE
, & dc
);
261 m_labelObjects
[i
]->Draw(dc
);
265 oglCentreText(dc
, &(region
->GetFormattedText()), m_xpos
, m_ypos
, actualW
, actualH
, region
->GetFormatMode());
269 void wxLineShape::DrawRegion(wxDC
& dc
, wxShapeRegion
*region
, double x
, double y
)
271 if (GetDisableLabel())
276 region
->GetSize(&w
, &h
);
278 // Get offset from x, y
279 region
->GetPosition(&xx
, &yy
);
284 // First, clear a rectangle for the text IF there is any
285 if (region
->GetFormattedText().Number() > 0)
287 dc
.SetPen(* g_oglWhiteBackgroundPen
);
288 dc
.SetBrush(* g_oglWhiteBackgroundBrush
);
291 if (region
->GetFont()) dc
.SetFont(* region
->GetFont());
293 dc
.DrawRectangle((long)(xp
- w
/2.0), (long)(yp
- h
/2.0), (long)w
, (long)h
);
295 if (m_pen
) dc
.SetPen(* m_pen
);
296 dc
.SetTextForeground(* region
->GetActualColourObject());
299 dc
.SetTextBackground(g_oglWhiteBackgroundBrush
->GetColour());
302 oglDrawFormattedText(dc
, &(region
->GetFormattedText()), xp
, yp
, w
, h
, region
->GetFormatMode());
306 void wxLineShape::EraseRegion(wxDC
& dc
, wxShapeRegion
*region
, double x
, double y
)
308 if (GetDisableLabel())
313 region
->GetSize(&w
, &h
);
315 // Get offset from x, y
316 region
->GetPosition(&xx
, &yy
);
321 if (region
->GetFormattedText().Number() > 0)
323 dc
.SetPen(* g_oglWhiteBackgroundPen
);
324 dc
.SetBrush(* g_oglWhiteBackgroundBrush
);
326 dc
.DrawRectangle((long)(xp
- w
/2.0), (long)(yp
- h
/2.0), (long)w
, (long)h
);
330 // Get the reference point for a label. Region x and y
331 // are offsets from this.
332 // position is 0, 1, 2
333 void wxLineShape::GetLabelPosition(int position
, double *x
, double *y
)
339 // Want to take the middle section for the label
340 int n
= m_lineControlPoints
->Number();
341 int half_way
= (int)(n
/2);
343 // Find middle of this line
344 wxNode
*node
= m_lineControlPoints
->Nth(half_way
- 1);
345 wxRealPoint
*point
= (wxRealPoint
*)node
->Data();
346 wxNode
*next_node
= node
->Next();
347 wxRealPoint
*next_point
= (wxRealPoint
*)next_node
->Data();
349 double dx
= (next_point
->x
- point
->x
);
350 double dy
= (next_point
->y
- point
->y
);
351 *x
= (double)(point
->x
+ dx
/2.0);
352 *y
= (double)(point
->y
+ dy
/2.0);
357 wxNode
*node
= m_lineControlPoints
->First();
358 *x
= ((wxRealPoint
*)node
->Data())->x
;
359 *y
= ((wxRealPoint
*)node
->Data())->y
;
364 wxNode
*node
= m_lineControlPoints
->Last();
365 *x
= ((wxRealPoint
*)node
->Data())->x
;
366 *y
= ((wxRealPoint
*)node
->Data())->y
;
375 * Find whether line is supposed to be vertical or horizontal and
379 void GraphicsStraightenLine(wxRealPoint
*point1
, wxRealPoint
*point2
)
381 double dx
= point2
->x
- point1
->x
;
382 double dy
= point2
->y
- point1
->y
;
386 else if (fabs(dy
/dx
) > 1.0)
388 point2
->x
= point1
->x
;
390 else point2
->y
= point1
->y
;
393 void wxLineShape::Straighten(wxDC
*dc
)
395 if (!m_lineControlPoints
|| m_lineControlPoints
->Number() < 3)
401 wxNode
*first_point_node
= m_lineControlPoints
->First();
402 wxNode
*last_point_node
= m_lineControlPoints
->Last();
403 wxNode
*second_last_point_node
= last_point_node
->Previous();
405 wxRealPoint
*last_point
= (wxRealPoint
*)last_point_node
->Data();
406 wxRealPoint
*second_last_point
= (wxRealPoint
*)second_last_point_node
->Data();
408 GraphicsStraightenLine(last_point
, second_last_point
);
410 wxNode
*node
= first_point_node
;
411 while (node
&& (node
!= second_last_point_node
))
413 wxRealPoint
*point
= (wxRealPoint
*)node
->Data();
414 wxRealPoint
*next_point
= (wxRealPoint
*)(node
->Next()->Data());
416 GraphicsStraightenLine(point
, next_point
);
425 void wxLineShape::Unlink()
428 m_to
->GetLines().DeleteObject(this);
430 m_from
->GetLines().DeleteObject(this);
435 void wxLineShape::SetEnds(double x1
, double y1
, double x2
, double y2
)
438 wxNode
*first_point_node
= m_lineControlPoints
->First();
439 wxNode
*last_point_node
= m_lineControlPoints
->Last();
440 wxRealPoint
*first_point
= (wxRealPoint
*)first_point_node
->Data();
441 wxRealPoint
*last_point
= (wxRealPoint
*)last_point_node
->Data();
448 m_xpos
= (double)((x1
+ x2
)/2.0);
449 m_ypos
= (double)((y1
+ y2
)/2.0);
452 // Get absolute positions of ends
453 void wxLineShape::GetEnds(double *x1
, double *y1
, double *x2
, double *y2
)
455 wxNode
*first_point_node
= m_lineControlPoints
->First();
456 wxNode
*last_point_node
= m_lineControlPoints
->Last();
457 wxRealPoint
*first_point
= (wxRealPoint
*)first_point_node
->Data();
458 wxRealPoint
*last_point
= (wxRealPoint
*)last_point_node
->Data();
460 *x1
= first_point
->x
; *y1
= first_point
->y
;
461 *x2
= last_point
->x
; *y2
= last_point
->y
;
464 void wxLineShape::SetAttachments(int from_attach
, int to_attach
)
466 m_attachmentFrom
= from_attach
;
467 m_attachmentTo
= to_attach
;
470 bool wxLineShape::HitTest(double x
, double y
, int *attachment
, double *distance
)
472 if (!m_lineControlPoints
)
475 // Look at label regions in case mouse is over a label
476 bool inLabelRegion
= FALSE
;
477 for (int i
= 0; i
< 3; i
++)
479 wxNode
*regionNode
= m_regions
.Nth(i
);
482 wxShapeRegion
*region
= (wxShapeRegion
*)regionNode
->Data();
483 if (region
->m_formattedText
.Number() > 0)
485 double xp
, yp
, cx
, cy
, cw
, ch
;
486 GetLabelPosition(i
, &xp
, &yp
);
487 // Offset region from default label position
488 region
->GetPosition(&cx
, &cy
);
489 region
->GetSize(&cw
, &ch
);
492 double rLeft
= (double)(cx
- (cw
/2.0));
493 double rTop
= (double)(cy
- (ch
/2.0));
494 double rRight
= (double)(cx
+ (cw
/2.0));
495 double rBottom
= (double)(cy
+ (ch
/2.0));
496 if (x
> rLeft
&& x
< rRight
&& y
> rTop
&& y
< rBottom
)
498 inLabelRegion
= TRUE
;
505 wxNode
*node
= m_lineControlPoints
->First();
507 while (node
&& node
->Next())
509 wxRealPoint
*point1
= (wxRealPoint
*)node
->Data();
510 wxRealPoint
*point2
= (wxRealPoint
*)node
->Next()->Data();
512 // Allow for inaccurate mousing or vert/horiz lines
514 double left
= wxMin(point1
->x
, point2
->x
) - extra
;
515 double right
= wxMax(point1
->x
, point2
->x
) + extra
;
517 double bottom
= wxMin(point1
->y
, point2
->y
) - extra
;
518 double top
= wxMax(point1
->y
, point2
->y
) + extra
;
520 if ((x
> left
&& x
< right
&& y
> bottom
&& y
< top
) || inLabelRegion
)
522 // Work out distance from centre of line
523 double centre_x
= (double)(left
+ (right
- left
)/2.0);
524 double centre_y
= (double)(bottom
+ (top
- bottom
)/2.0);
527 *distance
= (double)sqrt((centre_x
- x
)*(centre_x
- x
) + (centre_y
- y
)*(centre_y
- y
));
536 void wxLineShape::DrawArrows(wxDC
& dc
)
538 // Distance along line of each arrow: space them out evenly.
539 double startArrowPos
= 0.0;
540 double endArrowPos
= 0.0;
541 double middleArrowPos
= 0.0;
543 wxNode
*node
= m_arcArrows
.First();
546 wxArrowHead
*arrow
= (wxArrowHead
*)node
->Data();
547 switch (arrow
->GetArrowEnd())
549 case ARROW_POSITION_START
:
551 if ((arrow
->GetXOffset() != 0.0) && !m_ignoreArrowOffsets
)
552 // If specified, x offset is proportional to line length
553 DrawArrow(dc
, arrow
, arrow
->GetXOffset(), TRUE
);
556 DrawArrow(dc
, arrow
, startArrowPos
, FALSE
); // Absolute distance
557 startArrowPos
+= arrow
->GetSize() + arrow
->GetSpacing();
561 case ARROW_POSITION_END
:
563 if ((arrow
->GetXOffset() != 0.0) && !m_ignoreArrowOffsets
)
564 DrawArrow(dc
, arrow
, arrow
->GetXOffset(), TRUE
);
567 DrawArrow(dc
, arrow
, endArrowPos
, FALSE
);
568 endArrowPos
+= arrow
->GetSize() + arrow
->GetSpacing();
572 case ARROW_POSITION_MIDDLE
:
574 arrow
->SetXOffset(middleArrowPos
);
575 if ((arrow
->GetXOffset() != 0.0) && !m_ignoreArrowOffsets
)
576 DrawArrow(dc
, arrow
, arrow
->GetXOffset(), TRUE
);
579 DrawArrow(dc
, arrow
, middleArrowPos
, FALSE
);
580 middleArrowPos
+= arrow
->GetSize() + arrow
->GetSpacing();
589 void wxLineShape::DrawArrow(wxDC
& dc
, wxArrowHead
*arrow
, double xOffset
, bool proportionalOffset
)
591 wxNode
*first_line_node
= m_lineControlPoints
->First();
592 wxRealPoint
*first_line_point
= (wxRealPoint
*)first_line_node
->Data();
593 wxNode
*second_line_node
= first_line_node
->Next();
594 wxRealPoint
*second_line_point
= (wxRealPoint
*)second_line_node
->Data();
596 wxNode
*last_line_node
= m_lineControlPoints
->Last();
597 wxRealPoint
*last_line_point
= (wxRealPoint
*)last_line_node
->Data();
598 wxNode
*second_last_line_node
= last_line_node
->Previous();
599 wxRealPoint
*second_last_line_point
= (wxRealPoint
*)second_last_line_node
->Data();
601 // Position where we want to start drawing
602 double positionOnLineX
, positionOnLineY
;
604 // Position of start point of line, at the end of which we draw the arrow.
605 double startPositionX
, startPositionY
;
607 switch (arrow
->GetPosition())
609 case ARROW_POSITION_START
:
611 // If we're using a proportional offset, calculate just where this will
613 double realOffset
= xOffset
;
614 if (proportionalOffset
)
617 (double)sqrt((second_line_point
->x
- first_line_point
->x
)*(second_line_point
->x
- first_line_point
->x
) +
618 (second_line_point
->y
- first_line_point
->y
)*(second_line_point
->y
- first_line_point
->y
));
619 realOffset
= (double)(xOffset
* totalLength
);
621 GetPointOnLine(second_line_point
->x
, second_line_point
->y
,
622 first_line_point
->x
, first_line_point
->y
,
623 realOffset
, &positionOnLineX
, &positionOnLineY
);
624 startPositionX
= second_line_point
->x
;
625 startPositionY
= second_line_point
->y
;
628 case ARROW_POSITION_END
:
630 // If we're using a proportional offset, calculate just where this will
632 double realOffset
= xOffset
;
633 if (proportionalOffset
)
636 (double)sqrt((second_last_line_point
->x
- last_line_point
->x
)*(second_last_line_point
->x
- last_line_point
->x
) +
637 (second_last_line_point
->y
- last_line_point
->y
)*(second_last_line_point
->y
- last_line_point
->y
));
638 realOffset
= (double)(xOffset
* totalLength
);
640 GetPointOnLine(second_last_line_point
->x
, second_last_line_point
->y
,
641 last_line_point
->x
, last_line_point
->y
,
642 realOffset
, &positionOnLineX
, &positionOnLineY
);
643 startPositionX
= second_last_line_point
->x
;
644 startPositionY
= second_last_line_point
->y
;
647 case ARROW_POSITION_MIDDLE
:
649 // Choose a point half way between the last and penultimate points
650 double x
= ((last_line_point
->x
+ second_last_line_point
->x
)/2);
651 double y
= ((last_line_point
->y
+ second_last_line_point
->y
)/2);
653 // If we're using a proportional offset, calculate just where this will
655 double realOffset
= xOffset
;
656 if (proportionalOffset
)
659 (double)sqrt((second_last_line_point
->x
- x
)*(second_last_line_point
->x
- x
) +
660 (second_last_line_point
->y
- y
)*(second_last_line_point
->y
- y
));
661 realOffset
= (double)(xOffset
* totalLength
);
664 GetPointOnLine(second_last_line_point
->x
, second_last_line_point
->y
,
665 x
, y
, realOffset
, &positionOnLineX
, &positionOnLineY
);
666 startPositionX
= second_last_line_point
->x
;
667 startPositionY
= second_last_line_point
->y
;
673 * Add yOffset to arrow, if any
676 const double myPi
= (double) 3.14159265;
677 // The translation that the y offset may give
680 if ((arrow
->GetYOffset() != 0.0) && !m_ignoreArrowOffsets
)
686 (x1, y1)--------------(x3, y3)------------------(x2, y2)
687 x4 = x3 - d * sin(theta)
688 y4 = y3 + d * cos(theta)
690 Where theta = tan(-1) of (y3-y1)/(x3-x1)
692 double x1
= startPositionX
;
693 double y1
= startPositionY
;
694 double x3
= positionOnLineX
;
695 double y3
= positionOnLineY
;
696 double d
= -arrow
->GetYOffset(); // Negate so +offset is above line
700 theta
= (double)(myPi
/2.0);
702 theta
= (double)atan((y3
-y1
)/(x3
-x1
));
704 double x4
= (double)(x3
- (d
*sin(theta
)));
705 double y4
= (double)(y3
+ (d
*cos(theta
)));
707 deltaX
= x4
- positionOnLineX
;
708 deltaY
= y4
- positionOnLineY
;
711 switch (arrow
->_GetType())
715 double arrowLength
= arrow
->GetSize();
716 double arrowWidth
= (double)(arrowLength
/3.0);
718 double tip_x
, tip_y
, side1_x
, side1_y
, side2_x
, side2_y
;
719 oglGetArrowPoints(startPositionX
+deltaX
, startPositionY
+deltaY
,
720 positionOnLineX
+deltaX
, positionOnLineY
+deltaY
,
721 arrowLength
, arrowWidth
, &tip_x
, &tip_y
,
722 &side1_x
, &side1_y
, &side2_x
, &side2_y
);
725 points
[0].x
= (int) tip_x
; points
[0].y
= (int) tip_y
;
726 points
[1].x
= (int) side1_x
; points
[1].y
= (int) side1_y
;
727 points
[2].x
= (int) side2_x
; points
[2].y
= (int) side2_y
;
728 points
[3].x
= (int) tip_x
; points
[3].y
= (int) tip_y
;
731 dc
.SetBrush(* m_brush
);
732 dc
.DrawPolygon(4, points
);
735 case ARROW_HOLLOW_CIRCLE
:
736 case ARROW_FILLED_CIRCLE
:
738 // Find point on line of centre of circle, which is a radius away
739 // from the end position
740 double diameter
= (double)(arrow
->GetSize());
742 GetPointOnLine(startPositionX
+deltaX
, startPositionY
+deltaY
,
743 positionOnLineX
+deltaX
, positionOnLineY
+deltaY
,
744 (double)(diameter
/2.0),
747 // Convert ellipse centre to top-left coordinates
748 double x1
= (double)(x
- (diameter
/2.0));
749 double y1
= (double)(y
- (diameter
/2.0));
752 if (arrow
->_GetType() == ARROW_HOLLOW_CIRCLE
)
753 dc
.SetBrush(* g_oglWhiteBackgroundBrush
);
755 dc
.SetBrush(* m_brush
);
757 dc
.DrawEllipse((long) x1
, (long) y1
, (long) diameter
, (long) diameter
);
760 case ARROW_SINGLE_OBLIQUE
:
766 if (arrow
->GetMetaFile())
768 // Find point on line of centre of object, which is a half-width away
769 // from the end position
772 * <-- start pos <-----><-- positionOnLineX
774 * --------------| x | <-- e.g. rectangular arrowhead
778 GetPointOnLine(startPositionX
, startPositionY
,
779 positionOnLineX
, positionOnLineY
,
780 (double)(arrow
->GetMetaFile()->m_width
/2.0),
783 // Calculate theta for rotating the metafile.
786 | o(x2, y2) 'o' represents the arrowhead.
791 |______________________
794 double x1
= startPositionX
;
795 double y1
= startPositionY
;
796 double x2
= positionOnLineX
;
797 double y2
= positionOnLineY
;
799 if ((x1
== x2
) && (y1
== y2
))
802 else if ((x1
== x2
) && (y1
> y2
))
803 theta
= (double)(3.0*myPi
/2.0);
805 else if ((x1
== x2
) && (y2
> y1
))
806 theta
= (double)(myPi
/2.0);
808 else if ((x2
> x1
) && (y2
>= y1
))
809 theta
= (double)atan((y2
- y1
)/(x2
- x1
));
812 theta
= (double)(myPi
+ atan((y2
- y1
)/(x2
- x1
)));
814 else if ((x2
> x1
) && (y2
< y1
))
815 theta
= (double)(2*myPi
+ atan((y2
- y1
)/(x2
- x1
)));
819 wxFatalError("Unknown arrowhead rotation case in lines.cc");
822 // Rotate about the centre of the object, then place
823 // the object on the line.
824 if (arrow
->GetMetaFile()->GetRotateable())
825 arrow
->GetMetaFile()->Rotate(0.0, 0.0, theta
);
829 // If erasing, just draw a rectangle.
830 double minX
, minY
, maxX
, maxY
;
831 arrow
->GetMetaFile()->GetBounds(&minX
, &minY
, &maxX
, &maxY
);
832 // Make erasing rectangle slightly bigger or you get droppings.
834 dc
.DrawRectangle((long)(deltaX
+ x
+ minX
- (extraPixels
/2.0)), (long)(deltaY
+ y
+ minY
- (extraPixels
/2.0)),
835 (long)(maxX
- minX
+ extraPixels
), (long)(maxY
- minY
+ extraPixels
));
838 arrow
->GetMetaFile()->Draw(dc
, x
+deltaX
, y
+deltaY
);
848 void wxLineShape::OnErase(wxDC
& dc
)
850 wxPen
*old_pen
= m_pen
;
851 wxBrush
*old_brush
= m_brush
;
852 SetPen(g_oglWhiteBackgroundPen
);
853 SetBrush(g_oglWhiteBackgroundBrush
);
855 double bound_x
, bound_y
;
856 GetBoundingBoxMax(&bound_x
, &bound_y
);
857 if (m_font
) dc
.SetFont(* m_font
);
859 // Undraw text regions
860 for (int i
= 0; i
< 3; i
++)
862 wxNode
*node
= m_regions
.Nth(i
);
866 wxShapeRegion
*region
= (wxShapeRegion
*)node
->Data();
867 GetLabelPosition(i
, &x
, &y
);
868 EraseRegion(dc
, region
, x
, y
);
873 dc
.SetPen(* g_oglWhiteBackgroundPen
);
874 dc
.SetBrush(* g_oglWhiteBackgroundBrush
);
876 // Drawing over the line only seems to work if the line has a thickness
878 if (old_pen
&& (old_pen
->GetWidth() > 1))
880 dc
.DrawRectangle((long)(m_xpos
- (bound_x
/2.0) - 2.0), (long)(m_ypos
- (bound_y
/2.0) - 2.0),
881 (long)(bound_x
+4.0), (long)(bound_y
+4.0));
886 GetEventHandler()->OnDraw(dc
);
887 GetEventHandler()->OnEraseControlPoints(dc
);
891 if (old_pen
) SetPen(old_pen
);
892 if (old_brush
) SetBrush(old_brush
);
895 void wxLineShape::GetBoundingBoxMin(double *w
, double *h
)
902 wxNode
*node
= m_lineControlPoints
->First();
905 wxRealPoint
*point
= (wxRealPoint
*)node
->Data();
907 if (point
->x
< x1
) x1
= point
->x
;
908 if (point
->y
< y1
) y1
= point
->y
;
909 if (point
->x
> x2
) x2
= point
->x
;
910 if (point
->y
> y2
) y2
= point
->y
;
914 *w
= (double)(x2
- x1
);
915 *h
= (double)(y2
- y1
);
919 * For a node image of interest, finds the position of this arc
920 * amongst all the arcs which are attached to THIS SIDE of the node image,
921 * and the number of same.
923 void wxLineShape::FindNth(wxShape
*image
, int *nth
, int *no_arcs
, bool incoming
)
927 wxNode
*node
= image
->GetLines().First();
930 this_attachment
= m_attachmentTo
;
932 this_attachment
= m_attachmentFrom
;
934 // Find number of lines going into/out of this particular attachment point
937 wxLineShape
*line
= (wxLineShape
*)node
->Data();
939 if (line
->m_from
== image
)
941 // This is the nth line attached to 'image'
942 if ((line
== this) && !incoming
)
945 // Increment num count if this is the same side (attachment number)
946 if (line
->m_attachmentFrom
== this_attachment
)
950 if (line
->m_to
== image
)
952 // This is the nth line attached to 'image'
953 if ((line
== this) && incoming
)
956 // Increment num count if this is the same side (attachment number)
957 if (line
->m_attachmentTo
== this_attachment
)
967 void wxLineShape::OnDrawOutline(wxDC
& dc
, double x
, double y
, double w
, double h
)
969 wxPen
*old_pen
= m_pen
;
970 wxBrush
*old_brush
= m_brush
;
972 wxPen
dottedPen(wxColour(0, 0, 0), 1, wxDOT
);
974 SetBrush( wxTRANSPARENT_BRUSH
);
976 GetEventHandler()->OnDraw(dc
);
978 if (old_pen
) SetPen(old_pen
);
980 if (old_brush
) SetBrush(old_brush
);
984 bool wxLineShape::OnMovePre(wxDC
& dc
, double x
, double y
, double old_x
, double old_y
, bool display
)
986 double x_offset
= x
- old_x
;
987 double y_offset
= y
- old_y
;
989 if (m_lineControlPoints
&& !(x_offset
== 0.0 && y_offset
== 0.0))
991 wxNode
*node
= m_lineControlPoints
->First();
994 wxRealPoint
*point
= (wxRealPoint
*)node
->Data();
995 point
->x
+= x_offset
;
996 point
->y
+= y_offset
;
1002 // Move temporary label rectangles if necessary
1003 for (int i
= 0; i
< 3; i
++)
1005 if (m_labelObjects
[i
])
1007 m_labelObjects
[i
]->Erase(dc
);
1008 double xp
, yp
, xr
, yr
;
1009 GetLabelPosition(i
, &xp
, &yp
);
1010 wxNode
*node
= m_regions
.Nth(i
);
1013 wxShapeRegion
*region
= (wxShapeRegion
*)node
->Data();
1014 region
->GetPosition(&xr
, &yr
);
1021 m_labelObjects
[i
]->Move(dc
, xp
+xr
, yp
+yr
);
1027 void wxLineShape::OnMoveLink(wxDC
& dc
, bool moveControlPoints
)
1029 if (!m_from
|| !m_to
)
1032 if (m_lineControlPoints
->Number() > 2)
1035 // Do each end - nothing in the middle. User has to move other points
1036 // manually if necessary.
1037 double end_x
, end_y
;
1038 double other_end_x
, other_end_y
;
1040 FindLineEndPoints(&end_x
, &end_y
, &other_end_x
, &other_end_y
);
1042 wxNode
*first
= m_lineControlPoints
->First();
1043 wxRealPoint
*first_point
= (wxRealPoint
*)first
->Data();
1044 wxNode
*last
= m_lineControlPoints
->Last();
1045 wxRealPoint
*last_point
= (wxRealPoint
*)last
->Data();
1047 /* This is redundant, surely? Done by SetEnds.
1048 first_point->x = end_x; first_point->y = end_y;
1049 last_point->x = other_end_x; last_point->y = other_end_y;
1052 double oldX
= m_xpos
;
1053 double oldY
= m_ypos
;
1055 SetEnds(end_x
, end_y
, other_end_x
, other_end_y
);
1057 // Do a second time, because one may depend on the other.
1058 FindLineEndPoints(&end_x
, &end_y
, &other_end_x
, &other_end_y
);
1059 SetEnds(end_x
, end_y
, other_end_x
, other_end_y
);
1061 // Try to move control points with the arc
1062 double x_offset
= m_xpos
- oldX
;
1063 double y_offset
= m_ypos
- oldY
;
1065 // if (moveControlPoints && m_lineControlPoints && !(x_offset == 0.0 && y_offset == 0.0))
1066 // Only move control points if it's a self link. And only works if attachment mode is ON.
1067 if ((m_from
== m_to
) && (m_from
->GetAttachmentMode() != ATTACHMENT_MODE_NONE
) && moveControlPoints
&& m_lineControlPoints
&& !(x_offset
== 0.0 && y_offset
== 0.0))
1069 wxNode
*node
= m_lineControlPoints
->First();
1072 if ((node
!= m_lineControlPoints
->First()) && (node
!= m_lineControlPoints
->Last()))
1074 wxRealPoint
*point
= (wxRealPoint
*)node
->Data();
1075 point
->x
+= x_offset
;
1076 point
->y
+= y_offset
;
1078 node
= node
->Next();
1082 Move(dc
, m_xpos
, m_ypos
);
1085 // Finds the x, y points at the two ends of the line.
1086 // This function can be used by e.g. line-routing routines to
1087 // get the actual points on the two node images where the lines will be drawn
1089 void wxLineShape::FindLineEndPoints(double *fromX
, double *fromY
, double *toX
, double *toY
)
1091 if (!m_from
|| !m_to
)
1094 // Do each end - nothing in the middle. User has to move other points
1095 // manually if necessary.
1096 double end_x
, end_y
;
1097 double other_end_x
, other_end_y
;
1099 wxNode
*first
= m_lineControlPoints
->First();
1100 wxRealPoint
*first_point
= (wxRealPoint
*)first
->Data();
1101 wxNode
*last
= m_lineControlPoints
->Last();
1102 wxRealPoint
*last_point
= (wxRealPoint
*)last
->Data();
1104 wxNode
*second
= first
->Next();
1105 wxRealPoint
*second_point
= (wxRealPoint
*)second
->Data();
1107 wxNode
*second_last
= last
->Previous();
1108 wxRealPoint
*second_last_point
= (wxRealPoint
*)second_last
->Data();
1110 if (m_lineControlPoints
->Number() > 2)
1112 if (m_from
->GetAttachmentMode() != ATTACHMENT_MODE_NONE
)
1115 FindNth(m_from
, &nth
, &no_arcs
, FALSE
); // Not incoming
1116 m_from
->GetAttachmentPosition(m_attachmentFrom
, &end_x
, &end_y
, nth
, no_arcs
, this);
1119 (void) m_from
->GetPerimeterPoint(m_from
->GetX(), m_from
->GetY(),
1120 (double)second_point
->x
, (double)second_point
->y
,
1123 if (m_to
->GetAttachmentMode() != ATTACHMENT_MODE_NONE
)
1126 FindNth(m_to
, &nth
, &no_arcs
, TRUE
); // Incoming
1127 m_to
->GetAttachmentPosition(m_attachmentTo
, &other_end_x
, &other_end_y
, nth
, no_arcs
, this);
1130 (void) m_to
->GetPerimeterPoint(m_to
->GetX(), m_to
->GetY(),
1131 (double)second_last_point
->x
, (double)second_last_point
->y
,
1132 &other_end_x
, &other_end_y
);
1136 double fromX
= m_from
->GetX();
1137 double fromY
= m_from
->GetY();
1138 double toX
= m_to
->GetX();
1139 double toY
= m_to
->GetY();
1141 if (m_from
->GetAttachmentMode() != ATTACHMENT_MODE_NONE
)
1144 FindNth(m_from
, &nth
, &no_arcs
, FALSE
);
1145 m_from
->GetAttachmentPosition(m_attachmentFrom
, &end_x
, &end_y
, nth
, no_arcs
, this);
1150 if (m_to
->GetAttachmentMode() != ATTACHMENT_MODE_NONE
)
1153 FindNth(m_to
, &nth
, &no_arcs
, TRUE
);
1154 m_to
->GetAttachmentPosition(m_attachmentTo
, &other_end_x
, &other_end_y
, nth
, no_arcs
, this);
1159 if (m_from
->GetAttachmentMode() == ATTACHMENT_MODE_NONE
)
1160 (void) m_from
->GetPerimeterPoint(m_from
->GetX(), m_from
->GetY(),
1164 if (m_to
->GetAttachmentMode() == ATTACHMENT_MODE_NONE
)
1165 (void) m_to
->GetPerimeterPoint(m_to
->GetX(), m_to
->GetY(),
1167 &other_end_x
, &other_end_y
);
1175 void wxLineShape::OnDraw(wxDC
& dc
)
1177 if (m_lineControlPoints
)
1182 dc
.SetBrush(* m_brush
);
1184 int n
= m_lineControlPoints
->Number();
1185 wxPoint
*points
= new wxPoint
[n
];
1187 for (i
= 0; i
< n
; i
++)
1189 wxRealPoint
* point
= (wxRealPoint
*) m_lineControlPoints
->Nth(i
)->Data();
1190 points
[i
].x
= WXROUND(point
->x
);
1191 points
[i
].y
= WXROUND(point
->y
);
1195 dc
.DrawSpline(n
, points
);
1197 dc
.DrawLines(n
, points
);
1200 // For some reason, last point isn't drawn under Windows.
1201 dc
.DrawPoint(points
[n
-1]);
1207 // Problem with pen - if not a solid pen, does strange things
1208 // to the arrowhead. So make (get) a new pen that's solid.
1209 if (m_pen
&& (m_pen
->GetStyle() != wxSOLID
))
1212 wxThePenList
->FindOrCreatePen(m_pen
->GetColour(), 1, wxSOLID
);
1214 dc
.SetPen(* solid_pen
);
1220 void wxLineShape::OnDrawControlPoints(wxDC
& dc
)
1225 // Draw temporary label rectangles if necessary
1226 for (int i
= 0; i
< 3; i
++)
1228 if (m_labelObjects
[i
])
1229 m_labelObjects
[i
]->Draw(dc
);
1231 wxShape::OnDrawControlPoints(dc
);
1234 void wxLineShape::OnEraseControlPoints(wxDC
& dc
)
1236 // Erase temporary label rectangles if necessary
1237 for (int i
= 0; i
< 3; i
++)
1239 if (m_labelObjects
[i
])
1240 m_labelObjects
[i
]->Erase(dc
);
1242 wxShape::OnEraseControlPoints(dc
);
1245 void wxLineShape::OnDragLeft(bool draw
, double x
, double y
, int keys
, int attachment
)
1249 void wxLineShape::OnBeginDragLeft(double x
, double y
, int keys
, int attachment
)
1253 void wxLineShape::OnEndDragLeft(double x
, double y
, int keys
, int attachment
)
1258 void wxLineShape::SetArrowSize(double length, double width)
1260 arrow_length = length;
1261 arrow_width = width;
1264 void wxLineShape::SetStartArrow(int style)
1266 start_style = style;
1269 void wxLineShape::SetMiddleArrow(int style)
1271 middle_style = style;
1274 void wxLineShape::SetEndArrow(int style)
1280 void wxLineShape::OnDrawContents(wxDC
& dc
)
1282 if (GetDisableLabel())
1285 for (int i
= 0; i
< 3; i
++)
1287 wxNode
*node
= m_regions
.Nth(i
);
1290 wxShapeRegion
*region
= (wxShapeRegion
*)node
->Data();
1292 GetLabelPosition(i
, &x
, &y
);
1293 DrawRegion(dc
, region
, x
, y
);
1298 void wxLineShape::SetTo(wxShape
*object
)
1303 void wxLineShape::SetFrom(wxShape
*object
)
1308 void wxLineShape::MakeControlPoints()
1310 if (m_canvas
&& m_lineControlPoints
)
1312 wxNode
*first
= m_lineControlPoints
->First();
1313 wxNode
*last
= m_lineControlPoints
->Last();
1314 wxRealPoint
*first_point
= (wxRealPoint
*)first
->Data();
1315 wxRealPoint
*last_point
= (wxRealPoint
*)last
->Data();
1317 wxLineControlPoint
*control
= new wxLineControlPoint(m_canvas
, this, CONTROL_POINT_SIZE
,
1318 first_point
->x
, first_point
->y
,
1319 CONTROL_POINT_ENDPOINT_FROM
);
1320 control
->m_point
= first_point
;
1321 m_canvas
->AddShape(control
);
1322 m_controlPoints
.Append(control
);
1325 wxNode
*node
= first
->Next();
1326 while (node
!= last
)
1328 wxRealPoint
*point
= (wxRealPoint
*)node
->Data();
1330 control
= new wxLineControlPoint(m_canvas
, this, CONTROL_POINT_SIZE
,
1332 CONTROL_POINT_LINE
);
1333 control
->m_point
= point
;
1335 m_canvas
->AddShape(control
);
1336 m_controlPoints
.Append(control
);
1338 node
= node
->Next();
1340 control
= new wxLineControlPoint(m_canvas
, this, CONTROL_POINT_SIZE
,
1341 last_point
->x
, last_point
->y
,
1342 CONTROL_POINT_ENDPOINT_TO
);
1343 control
->m_point
= last_point
;
1344 m_canvas
->AddShape(control
);
1345 m_controlPoints
.Append(control
);
1351 void wxLineShape::ResetControlPoints()
1353 if (m_canvas
&& m_lineControlPoints
&& m_controlPoints
.Number() > 0)
1355 wxNode
*node
= m_controlPoints
.First();
1356 wxNode
*control_node
= m_lineControlPoints
->First();
1357 while (node
&& control_node
)
1359 wxRealPoint
*point
= (wxRealPoint
*)control_node
->Data();
1360 wxLineControlPoint
*control
= (wxLineControlPoint
*)node
->Data();
1361 control
->SetX(point
->x
);
1362 control
->SetY(point
->y
);
1364 node
= node
->Next();
1365 control_node
= control_node
->Next();
1371 void wxLineShape::WriteAttributes(wxExpr
*clause
)
1373 wxShape::WriteAttributes(clause
);
1376 clause
->AddAttributeValue("from", m_from
->GetId());
1378 clause
->AddAttributeValue("to", m_to
->GetId());
1380 if (m_attachmentTo
!= 0)
1381 clause
->AddAttributeValue("attachment_to", (long)m_attachmentTo
);
1382 if (m_attachmentFrom
!= 0)
1383 clause
->AddAttributeValue("attachment_from", (long)m_attachmentFrom
);
1385 if (m_alignmentStart
!= 0)
1386 clause
->AddAttributeValue("align_start", (long)m_alignmentStart
);
1387 if (m_alignmentEnd
!= 0)
1388 clause
->AddAttributeValue("align_end", (long)m_alignmentEnd
);
1390 clause
->AddAttributeValue("is_spline", (long)m_isSpline
);
1391 if (m_maintainStraightLines
)
1392 clause
->AddAttributeValue("keep_lines_straight", (long)m_maintainStraightLines
);
1394 // Make a list of lists for the (sp)line controls
1395 wxExpr
*list
= new wxExpr(wxExprList
);
1396 wxNode
*node
= m_lineControlPoints
->First();
1399 wxRealPoint
*point
= (wxRealPoint
*)node
->Data();
1400 wxExpr
*point_list
= new wxExpr(wxExprList
);
1401 wxExpr
*x_expr
= new wxExpr((double) point
->x
);
1402 wxExpr
*y_expr
= new wxExpr((double) point
->y
);
1403 point_list
->Append(x_expr
);
1404 point_list
->Append(y_expr
);
1405 list
->Append(point_list
);
1407 node
= node
->Next();
1409 clause
->AddAttributeValue("controls", list
);
1411 // Write arc arrows in new OGL format, if there are any.
1412 // This is a list of lists. Each sublist comprises:
1413 // (arrowType arrowEnd xOffset arrowSize)
1414 if (m_arcArrows
.Number() > 0)
1416 wxExpr
*arrow_list
= new wxExpr(wxExprList
);
1417 node
= m_arcArrows
.First();
1420 wxArrowHead
*head
= (wxArrowHead
*)node
->Data();
1421 wxExpr
*head_list
= new wxExpr(wxExprList
);
1422 head_list
->Append(new wxExpr((long)head
->_GetType()));
1423 head_list
->Append(new wxExpr((long)head
->GetArrowEnd()));
1424 head_list
->Append(new wxExpr(head
->GetXOffset()));
1425 head_list
->Append(new wxExpr(head
->GetArrowSize()));
1426 head_list
->Append(new wxExpr(wxExprString
, head
->GetName()));
1427 head_list
->Append(new wxExpr(head
->GetId()));
1429 // New members of wxArrowHead
1430 head_list
->Append(new wxExpr(head
->GetYOffset()));
1431 head_list
->Append(new wxExpr(head
->GetSpacing()));
1433 arrow_list
->Append(head_list
);
1435 node
= node
->Next();
1437 clause
->AddAttributeValue("arrows", arrow_list
);
1441 void wxLineShape::ReadAttributes(wxExpr
*clause
)
1443 wxShape::ReadAttributes(clause
);
1445 int iVal
= (int) m_isSpline
;
1446 clause
->AssignAttributeValue("is_spline", &iVal
);
1447 m_isSpline
= (iVal
!= 0);
1449 iVal
= (int) m_maintainStraightLines
;
1450 clause
->AssignAttributeValue("keep_lines_straight", &iVal
);
1451 m_maintainStraightLines
= (iVal
!= 0);
1453 clause
->AssignAttributeValue("align_start", &m_alignmentStart
);
1454 clause
->AssignAttributeValue("align_end", &m_alignmentEnd
);
1456 // Compatibility: check for no regions.
1457 if (m_regions
.Number() == 0)
1459 wxShapeRegion
*newRegion
= new wxShapeRegion
;
1460 newRegion
->SetName("Middle");
1461 newRegion
->SetSize(150, 50);
1462 m_regions
.Append((wxObject
*)newRegion
);
1463 if (m_text
.Number() > 0)
1465 newRegion
->ClearText();
1466 wxNode
*node
= m_text
.First();
1469 wxShapeTextLine
*textLine
= (wxShapeTextLine
*)node
->Data();
1470 wxNode
*next
= node
->Next();
1471 newRegion
->GetFormattedText().Append((wxObject
*)textLine
);
1477 newRegion
= new wxShapeRegion
;
1478 newRegion
->SetName("Start");
1479 newRegion
->SetSize(150, 50);
1480 m_regions
.Append((wxObject
*)newRegion
);
1482 newRegion
= new wxShapeRegion
;
1483 newRegion
->SetName("End");
1484 newRegion
->SetSize(150, 50);
1485 m_regions
.Append((wxObject
*)newRegion
);
1489 m_attachmentFrom
= 0;
1491 clause
->AssignAttributeValue("attachment_to", &m_attachmentTo
);
1492 clause
->AssignAttributeValue("attachment_from", &m_attachmentFrom
);
1494 wxExpr
*line_list
= NULL
;
1496 // When image is created, there are default control points. Override
1497 // them if there are some in the file.
1498 clause
->AssignAttributeValue("controls", &line_list
);
1502 // Read a list of lists for the spline controls
1503 if (m_lineControlPoints
)
1505 ClearPointList(*m_lineControlPoints
);
1508 m_lineControlPoints
= new wxList
;
1510 wxExpr
*node
= line_list
->value
.first
;
1514 wxExpr
*xexpr
= node
->value
.first
;
1515 double x
= xexpr
->RealValue();
1517 wxExpr
*yexpr
= xexpr
->next
;
1518 double y
= yexpr
->RealValue();
1520 wxRealPoint
*point
= new wxRealPoint(x
, y
);
1521 m_lineControlPoints
->Append((wxObject
*) point
);
1527 // Read arrow list, for new OGL code
1528 wxExpr
*arrow_list
= NULL
;
1530 clause
->AssignAttributeValue("arrows", &arrow_list
);
1533 wxExpr
*node
= arrow_list
->value
.first
;
1537 WXTYPE arrowType
= ARROW_ARROW
;
1539 double xOffset
= 0.0;
1540 double arrowSize
= 0.0;
1541 wxString
arrowName("");
1544 wxExpr
*type_expr
= node
->Nth(0);
1545 wxExpr
*end_expr
= node
->Nth(1);
1546 wxExpr
*dist_expr
= node
->Nth(2);
1547 wxExpr
*size_expr
= node
->Nth(3);
1548 wxExpr
*name_expr
= node
->Nth(4);
1549 wxExpr
*id_expr
= node
->Nth(5);
1551 // New members of wxArrowHead
1552 wxExpr
*yOffsetExpr
= node
->Nth(6);
1553 wxExpr
*spacingExpr
= node
->Nth(7);
1556 arrowType
= (int)type_expr
->IntegerValue();
1558 arrowEnd
= (int)end_expr
->IntegerValue();
1560 xOffset
= dist_expr
->RealValue();
1562 arrowSize
= size_expr
->RealValue();
1564 arrowName
= name_expr
->StringValue();
1566 arrowId
= id_expr
->IntegerValue();
1569 arrowId
= wxNewId();
1571 wxRegisterId(arrowId
);
1573 wxArrowHead
*arrowHead
= AddArrow(arrowType
, arrowEnd
, arrowSize
, xOffset
, (char*) (const char*) arrowName
, NULL
, arrowId
);
1575 arrowHead
->SetYOffset(yOffsetExpr
->RealValue());
1577 arrowHead
->SetSpacing(spacingExpr
->RealValue());
1585 void wxLineShape::Copy(wxShape
& copy
)
1587 wxShape::Copy(copy
);
1589 wxASSERT( copy
.IsKindOf(CLASSINFO(wxLineShape
)) );
1591 wxLineShape
& lineCopy
= (wxLineShape
&) copy
;
1593 lineCopy
.m_to
= m_to
;
1594 lineCopy
.m_from
= m_from
;
1595 lineCopy
.m_attachmentTo
= m_attachmentTo
;
1596 lineCopy
.m_attachmentFrom
= m_attachmentFrom
;
1597 lineCopy
.m_isSpline
= m_isSpline
;
1598 lineCopy
.m_alignmentStart
= m_alignmentStart
;
1599 lineCopy
.m_alignmentEnd
= m_alignmentEnd
;
1600 lineCopy
.m_maintainStraightLines
= m_maintainStraightLines
;
1601 lineCopy
.m_lineOrientations
.Clear();
1603 wxNode
*node
= m_lineOrientations
.First();
1606 lineCopy
.m_lineOrientations
.Append(node
->Data());
1607 node
= node
->Next();
1610 if (lineCopy
.m_lineControlPoints
)
1612 ClearPointList(*lineCopy
.m_lineControlPoints
);
1613 delete lineCopy
.m_lineControlPoints
;
1616 lineCopy
.m_lineControlPoints
= new wxList
;
1618 node
= m_lineControlPoints
->First();
1621 wxRealPoint
*point
= (wxRealPoint
*)node
->Data();
1622 wxRealPoint
*new_point
= new wxRealPoint(point
->x
, point
->y
);
1623 lineCopy
.m_lineControlPoints
->Append((wxObject
*) new_point
);
1624 node
= node
->Next();
1628 lineCopy
.ClearArrowsAtPosition(-1);
1629 node
= m_arcArrows
.First();
1632 wxArrowHead
*arrow
= (wxArrowHead
*)node
->Data();
1633 lineCopy
.m_arcArrows
.Append(new wxArrowHead(*arrow
));
1634 node
= node
->Next();
1638 // Override select, to create/delete temporary label-moving objects
1639 void wxLineShape::Select(bool select
, wxDC
* dc
)
1641 wxShape::Select(select
, dc
);
1644 for (int i
= 0; i
< 3; i
++)
1646 wxNode
*node
= m_regions
.Nth(i
);
1649 wxShapeRegion
*region
= (wxShapeRegion
*)node
->Data();
1650 if (region
->m_formattedText
.Number() > 0)
1652 double w
, h
, x
, y
, xx
, yy
;
1653 region
->GetSize(&w
, &h
);
1654 region
->GetPosition(&x
, &y
);
1655 GetLabelPosition(i
, &xx
, &yy
);
1656 if (m_labelObjects
[i
])
1658 m_labelObjects
[i
]->Select(FALSE
);
1659 m_labelObjects
[i
]->RemoveFromCanvas(m_canvas
);
1660 delete m_labelObjects
[i
];
1662 m_labelObjects
[i
] = OnCreateLabelShape(this, region
, w
, h
);
1663 m_labelObjects
[i
]->AddToCanvas(m_canvas
);
1664 m_labelObjects
[i
]->Show(TRUE
);
1666 m_labelObjects
[i
]->Move(*dc
, (double)(x
+ xx
), (double)(y
+ yy
));
1667 m_labelObjects
[i
]->Select(TRUE
, dc
);
1674 for (int i
= 0; i
< 3; i
++)
1676 if (m_labelObjects
[i
])
1678 m_labelObjects
[i
]->Select(FALSE
, dc
);
1679 m_labelObjects
[i
]->Erase(*dc
);
1680 m_labelObjects
[i
]->RemoveFromCanvas(m_canvas
);
1681 delete m_labelObjects
[i
];
1682 m_labelObjects
[i
] = NULL
;
1689 * Line control point
1693 IMPLEMENT_DYNAMIC_CLASS(wxLineControlPoint
, wxControlPoint
)
1695 wxLineControlPoint::wxLineControlPoint(wxShapeCanvas
*theCanvas
, wxShape
*object
, double size
, double x
, double y
, int the_type
):
1696 wxControlPoint(theCanvas
, object
, size
, x
, y
, the_type
)
1704 wxLineControlPoint::~wxLineControlPoint()
1708 void wxLineControlPoint::OnDraw(wxDC
& dc
)
1710 wxRectangleShape::OnDraw(dc
);
1713 // Implement movement of Line point
1714 void wxLineControlPoint::OnDragLeft(bool draw
, double x
, double y
, int keys
, int attachment
)
1716 m_shape
->GetEventHandler()->OnSizingDragLeft(this, draw
, x
, y
, keys
, attachment
);
1719 void wxLineControlPoint::OnBeginDragLeft(double x
, double y
, int keys
, int attachment
)
1721 m_shape
->GetEventHandler()->OnSizingBeginDragLeft(this, x
, y
, keys
, attachment
);
1724 void wxLineControlPoint::OnEndDragLeft(double x
, double y
, int keys
, int attachment
)
1726 m_shape
->GetEventHandler()->OnSizingEndDragLeft(this, x
, y
, keys
, attachment
);
1729 // Control points ('handles') redirect control to the actual shape, to make it easier
1730 // to override sizing behaviour.
1731 void wxLineShape::OnSizingDragLeft(wxControlPoint
* pt
, bool draw
, double x
, double y
, int keys
, int attachment
)
1733 wxLineControlPoint
* lpt
= (wxLineControlPoint
*) pt
;
1735 wxClientDC
dc(GetCanvas());
1736 GetCanvas()->PrepareDC(dc
);
1738 dc
.SetLogicalFunction(OGLRBLF
);
1740 wxPen
dottedPen(wxColour(0, 0, 0), 1, wxDOT
);
1741 dc
.SetPen(dottedPen
);
1742 dc
.SetBrush((* wxTRANSPARENT_BRUSH
));
1744 if (lpt
->m_type
== CONTROL_POINT_LINE
)
1746 m_canvas
->Snap(&x
, &y
);
1748 lpt
->SetX(x
); lpt
->SetY(y
);
1749 lpt
->m_point
->x
= x
; lpt
->m_point
->y
= y
;
1751 wxLineShape
*lineShape
= (wxLineShape
*)this;
1753 wxPen
*old_pen
= lineShape
->GetPen();
1754 wxBrush
*old_brush
= lineShape
->GetBrush();
1756 wxPen
dottedPen(wxColour(0, 0, 0), 1, wxDOT
);
1757 lineShape
->SetPen(& dottedPen
);
1758 lineShape
->SetBrush(wxTRANSPARENT_BRUSH
);
1760 lineShape
->GetEventHandler()->OnMoveLink(dc
, FALSE
);
1762 lineShape
->SetPen(old_pen
);
1763 lineShape
->SetBrush(old_brush
);
1766 if (lpt
->m_type
== CONTROL_POINT_ENDPOINT_FROM
|| lpt
->m_type
== CONTROL_POINT_ENDPOINT_TO
)
1768 // lpt->SetX(x); lpt->SetY(y);
1773 void wxLineShape::OnSizingBeginDragLeft(wxControlPoint
* pt
, double x
, double y
, int keys
, int attachment
)
1775 wxLineControlPoint
* lpt
= (wxLineControlPoint
*) pt
;
1777 wxClientDC
dc(GetCanvas());
1778 GetCanvas()->PrepareDC(dc
);
1780 wxLineShape
*lineShape
= (wxLineShape
*)this;
1781 if (lpt
->m_type
== CONTROL_POINT_LINE
)
1783 lpt
->m_originalPos
= * (lpt
->m_point
);
1784 m_canvas
->Snap(&x
, &y
);
1788 // Redraw start and end objects because we've left holes
1789 // when erasing the line
1790 lineShape
->GetFrom()->OnDraw(dc
);
1791 lineShape
->GetFrom()->OnDrawContents(dc
);
1792 lineShape
->GetTo()->OnDraw(dc
);
1793 lineShape
->GetTo()->OnDrawContents(dc
);
1795 this->SetDisableLabel(TRUE
);
1796 dc
.SetLogicalFunction(OGLRBLF
);
1798 lpt
->m_xpos
= x
; lpt
->m_ypos
= y
;
1799 lpt
->m_point
->x
= x
; lpt
->m_point
->y
= y
;
1801 wxPen
*old_pen
= lineShape
->GetPen();
1802 wxBrush
*old_brush
= lineShape
->GetBrush();
1804 wxPen
dottedPen(wxColour(0, 0, 0), 1, wxDOT
);
1805 lineShape
->SetPen(& dottedPen
);
1806 lineShape
->SetBrush(wxTRANSPARENT_BRUSH
);
1808 lineShape
->GetEventHandler()->OnMoveLink(dc
, FALSE
);
1810 lineShape
->SetPen(old_pen
);
1811 lineShape
->SetBrush(old_brush
);
1814 if (lpt
->m_type
== CONTROL_POINT_ENDPOINT_FROM
|| lpt
->m_type
== CONTROL_POINT_ENDPOINT_TO
)
1816 m_canvas
->SetCursor(* g_oglBullseyeCursor
);
1817 lpt
->m_oldCursor
= wxSTANDARD_CURSOR
;
1821 void wxLineShape::OnSizingEndDragLeft(wxControlPoint
* pt
, double x
, double y
, int keys
, int attachment
)
1823 wxLineControlPoint
* lpt
= (wxLineControlPoint
*) pt
;
1825 wxClientDC
dc(GetCanvas());
1826 GetCanvas()->PrepareDC(dc
);
1828 this->SetDisableLabel(FALSE
);
1829 wxLineShape
*lineShape
= (wxLineShape
*)this;
1831 if (lpt
->m_type
== CONTROL_POINT_LINE
)
1833 m_canvas
->Snap(&x
, &y
);
1835 wxRealPoint pt
= wxRealPoint(x
, y
);
1837 // Move the control point back to where it was;
1838 // MoveControlPoint will move it to the new position
1839 // if it decides it wants. We only moved the position
1840 // during user feedback so we could redraw the line
1841 // as it changed shape.
1842 lpt
->m_xpos
= lpt
->m_originalPos
.x
; lpt
->m_ypos
= lpt
->m_originalPos
.y
;
1843 lpt
->m_point
->x
= lpt
->m_originalPos
.x
; lpt
->m_point
->y
= lpt
->m_originalPos
.y
;
1845 OnMoveMiddleControlPoint(dc
, lpt
, pt
);
1847 if (lpt
->m_type
== CONTROL_POINT_ENDPOINT_FROM
)
1849 if (lpt
->m_oldCursor
)
1850 m_canvas
->SetCursor(* lpt
->m_oldCursor
);
1854 // lpt->m_xpos = x; lpt->m_ypos = y;
1856 if (lineShape
->GetFrom())
1858 lineShape
->GetFrom()->MoveLineToNewAttachment(dc
, lineShape
, x
, y
);
1861 if (lpt
->m_type
== CONTROL_POINT_ENDPOINT_TO
)
1863 if (lpt
->m_oldCursor
)
1864 m_canvas
->SetCursor(* lpt
->m_oldCursor
);
1866 // lpt->m_xpos = x; lpt->m_ypos = y;
1868 if (lineShape
->GetTo())
1870 lineShape
->GetTo()->MoveLineToNewAttachment(dc
, lineShape
, x
, y
);
1877 for (i
= 0; i
< lineShape
->GetLineControlPoints()->Number(); i
++)
1878 if (((wxRealPoint
*)(lineShape
->GetLineControlPoints()->Nth(i
)->Data())) == lpt
->m_point
)
1881 // N.B. in OnMoveControlPoint, an event handler in Hardy could have deselected
1882 // the line and therefore deleted 'this'. -> GPF, intermittently.
1883 // So assume at this point that we've been blown away.
1885 lineShape
->OnMoveControlPoint(i
+1, x
, y
);
1889 // This is called only when a non-end control point is moved.
1890 bool wxLineShape::OnMoveMiddleControlPoint(wxDC
& dc
, wxLineControlPoint
* lpt
, const wxRealPoint
& pt
)
1892 lpt
->m_xpos
= pt
.x
; lpt
->m_ypos
= pt
.y
;
1893 lpt
->m_point
->x
= pt
.x
; lpt
->m_point
->y
= pt
.y
;
1895 GetEventHandler()->OnMoveLink(dc
);
1900 // Implement movement of endpoint to a new attachment
1901 // OBSOLETE: done by dragging with the left button.
1904 void wxLineControlPoint::OnDragRight(bool draw
, double x
, double y
, int keys
, int attachment
)
1906 if (m_type
== CONTROL_POINT_ENDPOINT_FROM
|| m_type
== CONTROL_POINT_ENDPOINT_TO
)
1908 m_xpos
= x
; m_ypos
= y
;
1912 void wxLineControlPoint::OnBeginDragRight(double x
, double y
, int keys
, int attachment
)
1914 wxClientDC
dc(GetCanvas());
1915 GetCanvas()->PrepareDC(dc
);
1917 wxLineShape
*lineShape
= (wxLineShape
*)m_shape
;
1918 if (m_type
== CONTROL_POINT_ENDPOINT_FROM
|| m_type
== CONTROL_POINT_ENDPOINT_TO
)
1921 lineShape
->GetEventHandler()->OnDraw(dc
);
1922 if (m_type
== CONTROL_POINT_ENDPOINT_FROM
)
1924 lineShape
->GetFrom()->GetEventHandler()->OnDraw(dc
);
1925 lineShape
->GetFrom()->GetEventHandler()->OnDrawContents(dc
);
1929 lineShape
->GetTo()->GetEventHandler()->OnDraw(dc
);
1930 lineShape
->GetTo()->GetEventHandler()->OnDrawContents(dc
);
1932 m_canvas
->SetCursor(g_oglBullseyeCursor
);
1933 m_oldCursor
= wxSTANDARD_CURSOR
;
1937 void wxLineControlPoint::OnEndDragRight(double x
, double y
, int keys
, int attachment
)
1939 wxClientDC
dc(GetCanvas());
1940 GetCanvas()->PrepareDC(dc
);
1942 wxLineShape
*lineShape
= (wxLineShape
*)m_shape
;
1943 if (m_type
== CONTROL_POINT_ENDPOINT_FROM
)
1946 m_canvas
->SetCursor(m_oldCursor
);
1948 m_xpos
= x
; m_ypos
= y
;
1950 if (lineShape
->GetFrom())
1952 lineShape
->GetFrom()->EraseLinks(dc
);
1957 if (lineShape
->GetFrom()->HitTest(x
, y
, &new_attachment
, &distance
))
1958 lineShape
->SetAttachments(new_attachment
, lineShape
->GetAttachmentTo());
1960 lineShape
->GetFrom()->MoveLinks(dc
);
1963 if (m_type
== CONTROL_POINT_ENDPOINT_TO
)
1966 m_canvas
->SetCursor(m_oldCursor
);
1969 m_xpos
= x
; m_ypos
= y
;
1971 if (lineShape
->GetTo())
1973 lineShape
->GetTo()->EraseLinks(dc
);
1977 if (lineShape
->GetTo()->HitTest(x
, y
, &new_attachment
, &distance
))
1978 lineShape
->SetAttachments(lineShape
->GetAttachmentFrom(), new_attachment
);
1980 lineShape
->GetTo()->MoveLinks(dc
);
1984 for (i
= 0; i
< lineShape
->GetLineControlPoints()->Number(); i
++)
1985 if (((wxRealPoint
*)(lineShape
->GetLineControlPoints()->Nth(i
)->Data())) == m_point
)
1987 lineShape
->OnMoveControlPoint(i
+1, x
, y
);
1988 if (!m_canvas
->GetQuickEditMode()) m_canvas
->Redraw(dc
);
1993 * Get the point on the given line (x1, y1) (x2, y2)
1994 * distance 'length' along from the end,
1995 * returned values in x and y
1998 void GetPointOnLine(double x1
, double y1
, double x2
, double y2
,
1999 double length
, double *x
, double *y
)
2001 double l
= (double)sqrt((x2
- x1
)*(x2
- x1
) + (y2
- y1
)*(y2
- y1
));
2006 double i_bar
= (x2
- x1
)/l
;
2007 double j_bar
= (y2
- y1
)/l
;
2009 *x
= (- length
*i_bar
) + x2
;
2010 *y
= (- length
*j_bar
) + y2
;
2013 wxArrowHead
*wxLineShape::AddArrow(WXTYPE type
, int end
, double size
, double xOffset
,
2014 const wxString
& name
, wxPseudoMetaFile
*mf
, long arrowId
)
2016 wxArrowHead
*arrow
= new wxArrowHead(type
, end
, size
, xOffset
, name
, mf
, arrowId
);
2017 m_arcArrows
.Append(arrow
);
2022 * Add arrowhead at a particular position in the arrowhead list.
2024 bool wxLineShape::AddArrowOrdered(wxArrowHead
*arrow
, wxList
& referenceList
, int end
)
2026 wxNode
*refNode
= referenceList
.First();
2027 wxNode
*currNode
= m_arcArrows
.First();
2028 wxString
targetName(arrow
->GetName());
2029 if (!refNode
) return FALSE
;
2031 // First check whether we need to insert in front of list,
2032 // because this arrowhead is the first in the reference
2033 // list and should therefore be first in the current list.
2034 wxArrowHead
*refArrow
= (wxArrowHead
*)refNode
->Data();
2035 if (refArrow
->GetName() == targetName
)
2037 m_arcArrows
.Insert(arrow
);
2041 while (refNode
&& currNode
)
2043 wxArrowHead
*currArrow
= (wxArrowHead
*)currNode
->Data();
2044 refArrow
= (wxArrowHead
*)refNode
->Data();
2046 // Matching: advance current arrow pointer
2047 if ((currArrow
->GetArrowEnd() == end
) &&
2048 (currArrow
->GetName() == refArrow
->GetName()))
2050 currNode
= currNode
->Next(); // Could be NULL now
2052 currArrow
= (wxArrowHead
*)currNode
->Data();
2055 // Check if we're at the correct position in the
2057 if (targetName
== refArrow
->GetName())
2060 m_arcArrows
.Insert(currNode
, arrow
);
2062 m_arcArrows
.Append(arrow
);
2065 refNode
= refNode
->Next();
2067 m_arcArrows
.Append(arrow
);
2071 void wxLineShape::ClearArrowsAtPosition(int end
)
2073 wxNode
*node
= m_arcArrows
.First();
2076 wxArrowHead
*arrow
= (wxArrowHead
*)node
->Data();
2077 wxNode
*next
= node
->Next();
2086 case ARROW_POSITION_START
:
2088 if (arrow
->GetArrowEnd() == ARROW_POSITION_START
)
2095 case ARROW_POSITION_END
:
2097 if (arrow
->GetArrowEnd() == ARROW_POSITION_END
)
2104 case ARROW_POSITION_MIDDLE
:
2106 if (arrow
->GetArrowEnd() == ARROW_POSITION_MIDDLE
)
2118 bool wxLineShape::ClearArrow(const wxString
& name
)
2120 wxNode
*node
= m_arcArrows
.First();
2123 wxArrowHead
*arrow
= (wxArrowHead
*)node
->Data();
2124 if (arrow
->GetName() == name
)
2130 node
= node
->Next();
2136 * Finds an arrowhead at the given position (if -1, any position)
2140 wxArrowHead
*wxLineShape::FindArrowHead(int position
, const wxString
& name
)
2142 wxNode
*node
= m_arcArrows
.First();
2145 wxArrowHead
*arrow
= (wxArrowHead
*)node
->Data();
2146 if (((position
== -1) || (position
== arrow
->GetArrowEnd())) &&
2147 (arrow
->GetName() == name
))
2149 node
= node
->Next();
2154 wxArrowHead
*wxLineShape::FindArrowHead(long arrowId
)
2156 wxNode
*node
= m_arcArrows
.First();
2159 wxArrowHead
*arrow
= (wxArrowHead
*)node
->Data();
2160 if (arrowId
== arrow
->GetId())
2162 node
= node
->Next();
2168 * Deletes an arrowhead at the given position (if -1, any position)
2172 bool wxLineShape::DeleteArrowHead(int position
, const wxString
& name
)
2174 wxNode
*node
= m_arcArrows
.First();
2177 wxArrowHead
*arrow
= (wxArrowHead
*)node
->Data();
2178 if (((position
== -1) || (position
== arrow
->GetArrowEnd())) &&
2179 (arrow
->GetName() == name
))
2185 node
= node
->Next();
2190 // Overloaded DeleteArrowHead: pass arrowhead id.
2191 bool wxLineShape::DeleteArrowHead(long id
)
2193 wxNode
*node
= m_arcArrows
.First();
2196 wxArrowHead
*arrow
= (wxArrowHead
*)node
->Data();
2197 if (arrow
->GetId() == id
)
2203 node
= node
->Next();
2209 * Calculate the minimum width a line
2210 * occupies, for the purposes of drawing lines in tools.
2214 double wxLineShape::FindMinimumWidth()
2216 double minWidth
= 0.0;
2217 wxNode
*node
= m_arcArrows
.First();
2220 wxArrowHead
*arrowHead
= (wxArrowHead
*)node
->Data();
2221 minWidth
+= arrowHead
->GetSize();
2223 minWidth
+= arrowHead
->GetSpacing();
2225 node
= node
->Next();
2227 // We have ABSOLUTE minimum now. So
2228 // scale it to give it reasonable aesthetics
2229 // when drawing with line.
2231 minWidth
= (double)(minWidth
* 1.4);
2235 SetEnds(0.0, 0.0, minWidth
, 0.0);
2241 // Find which position we're talking about at this (x, y).
2242 // Returns ARROW_POSITION_START, ARROW_POSITION_MIDDLE, ARROW_POSITION_END
2243 int wxLineShape::FindLinePosition(double x
, double y
)
2245 double startX
, startY
, endX
, endY
;
2246 GetEnds(&startX
, &startY
, &endX
, &endY
);
2248 // Find distances from centre, start and end. The smallest wins.
2249 double centreDistance
= (double)(sqrt((x
- m_xpos
)*(x
- m_xpos
) + (y
- m_ypos
)*(y
- m_ypos
)));
2250 double startDistance
= (double)(sqrt((x
- startX
)*(x
- startX
) + (y
- startY
)*(y
- startY
)));
2251 double endDistance
= (double)(sqrt((x
- endX
)*(x
- endX
) + (y
- endY
)*(y
- endY
)));
2253 if (centreDistance
< startDistance
&& centreDistance
< endDistance
)
2254 return ARROW_POSITION_MIDDLE
;
2255 else if (startDistance
< endDistance
)
2256 return ARROW_POSITION_START
;
2258 return ARROW_POSITION_END
;
2261 // Set alignment flags
2262 void wxLineShape::SetAlignmentOrientation(bool isEnd
, bool isHoriz
)
2266 if (isHoriz
&& ((m_alignmentEnd
& LINE_ALIGNMENT_HORIZ
) != LINE_ALIGNMENT_HORIZ
))
2267 m_alignmentEnd
|= LINE_ALIGNMENT_HORIZ
;
2268 else if (!isHoriz
&& ((m_alignmentEnd
& LINE_ALIGNMENT_HORIZ
) == LINE_ALIGNMENT_HORIZ
))
2269 m_alignmentEnd
-= LINE_ALIGNMENT_HORIZ
;
2273 if (isHoriz
&& ((m_alignmentStart
& LINE_ALIGNMENT_HORIZ
) != LINE_ALIGNMENT_HORIZ
))
2274 m_alignmentStart
|= LINE_ALIGNMENT_HORIZ
;
2275 else if (!isHoriz
&& ((m_alignmentStart
& LINE_ALIGNMENT_HORIZ
) == LINE_ALIGNMENT_HORIZ
))
2276 m_alignmentStart
-= LINE_ALIGNMENT_HORIZ
;
2280 void wxLineShape::SetAlignmentType(bool isEnd
, int alignType
)
2284 if (alignType
== LINE_ALIGNMENT_TO_NEXT_HANDLE
)
2286 if ((m_alignmentEnd
& LINE_ALIGNMENT_TO_NEXT_HANDLE
) != LINE_ALIGNMENT_TO_NEXT_HANDLE
)
2287 m_alignmentEnd
|= LINE_ALIGNMENT_TO_NEXT_HANDLE
;
2289 else if ((m_alignmentEnd
& LINE_ALIGNMENT_TO_NEXT_HANDLE
) == LINE_ALIGNMENT_TO_NEXT_HANDLE
)
2290 m_alignmentEnd
-= LINE_ALIGNMENT_TO_NEXT_HANDLE
;
2294 if (alignType
== LINE_ALIGNMENT_TO_NEXT_HANDLE
)
2296 if ((m_alignmentStart
& LINE_ALIGNMENT_TO_NEXT_HANDLE
) != LINE_ALIGNMENT_TO_NEXT_HANDLE
)
2297 m_alignmentStart
|= LINE_ALIGNMENT_TO_NEXT_HANDLE
;
2299 else if ((m_alignmentStart
& LINE_ALIGNMENT_TO_NEXT_HANDLE
) == LINE_ALIGNMENT_TO_NEXT_HANDLE
)
2300 m_alignmentStart
-= LINE_ALIGNMENT_TO_NEXT_HANDLE
;
2304 bool wxLineShape::GetAlignmentOrientation(bool isEnd
)
2307 return ((m_alignmentEnd
& LINE_ALIGNMENT_HORIZ
) == LINE_ALIGNMENT_HORIZ
);
2309 return ((m_alignmentStart
& LINE_ALIGNMENT_HORIZ
) == LINE_ALIGNMENT_HORIZ
);
2312 int wxLineShape::GetAlignmentType(bool isEnd
)
2315 return (m_alignmentEnd
& LINE_ALIGNMENT_TO_NEXT_HANDLE
);
2317 return (m_alignmentStart
& LINE_ALIGNMENT_TO_NEXT_HANDLE
);
2320 wxRealPoint
*wxLineShape::GetNextControlPoint(wxShape
*nodeObject
)
2322 int n
= m_lineControlPoints
->Number();
2324 if (m_to
== nodeObject
)
2326 // Must be END of line, so we want (n - 1)th control point.
2327 // But indexing ends at n-1, so subtract 2.
2331 wxNode
*node
= m_lineControlPoints
->Nth(nn
);
2334 return (wxRealPoint
*)node
->Data();
2345 IMPLEMENT_DYNAMIC_CLASS(wxArrowHead
, wxObject
)
2347 wxArrowHead::wxArrowHead(WXTYPE type
, int end
, double size
, double dist
, const wxString
& name
,
2348 wxPseudoMetaFile
*mf
, long arrowId
)
2350 m_arrowType
= type
; m_arrowEnd
= end
; m_arrowSize
= size
;
2362 wxArrowHead::wxArrowHead(wxArrowHead
& toCopy
)
2364 m_arrowType
= toCopy
.m_arrowType
; m_arrowEnd
= toCopy
.GetArrowEnd();
2365 m_arrowSize
= toCopy
.m_arrowSize
;
2366 m_xOffset
= toCopy
.m_xOffset
;
2367 m_yOffset
= toCopy
.m_yOffset
;
2368 m_spacing
= toCopy
.m_spacing
;
2369 m_arrowName
= toCopy
.m_arrowName
;
2370 if (toCopy
.m_metaFile
)
2371 m_metaFile
= new wxPseudoMetaFile(*(toCopy
.m_metaFile
));
2377 wxArrowHead::~wxArrowHead()
2379 if (m_metaFile
) delete m_metaFile
;
2382 void wxArrowHead::SetSize(double size
)
2385 if ((m_arrowType
== ARROW_METAFILE
) && m_metaFile
)
2387 double oldWidth
= m_metaFile
->m_width
;
2388 if (oldWidth
== 0.0)
2391 double scale
= (double)(size
/oldWidth
);
2393 m_metaFile
->Scale(scale
, scale
);
2397 // Can override this to create a different class of label shape
2398 wxLabelShape
* wxLineShape::OnCreateLabelShape(wxLineShape
*parent
, wxShapeRegion
*region
, double w
, double h
)
2400 return new wxLabelShape(parent
, region
, w
, h
);
2408 IMPLEMENT_DYNAMIC_CLASS(wxLabelShape
, wxRectangleShape
)
2410 wxLabelShape::wxLabelShape(wxLineShape
*parent
, wxShapeRegion
*region
, double w
, double h
):wxRectangleShape(w
, h
)
2412 m_lineShape
= parent
;
2413 m_shapeRegion
= region
;
2414 SetPen(wxThePenList
->FindOrCreatePen(wxColour(0, 0, 0), 1, wxDOT
));
2417 wxLabelShape::~wxLabelShape()
2421 void wxLabelShape::OnDraw(wxDC
& dc
)
2423 if (m_lineShape
&& !m_lineShape
->GetDrawHandles())
2426 double x1
= (double)(m_xpos
- m_width
/2.0);
2427 double y1
= (double)(m_ypos
- m_height
/2.0);
2431 if (m_pen
->GetWidth() == 0)
2432 dc
.SetPen(* g_oglTransparentPen
);
2436 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
2438 if (m_cornerRadius
> 0.0)
2439 dc
.DrawRoundedRectangle(WXROUND(x1
), WXROUND(y1
), WXROUND(m_width
), WXROUND(m_height
), m_cornerRadius
);
2441 dc
.DrawRectangle(WXROUND(x1
), WXROUND(y1
), WXROUND(m_width
), WXROUND(m_height
));
2444 void wxLabelShape::OnDrawContents(wxDC
& dc
)
2448 void wxLabelShape::OnDragLeft(bool draw
, double x
, double y
, int keys
, int attachment
)
2450 wxRectangleShape::OnDragLeft(draw
, x
, y
, keys
, attachment
);
2453 void wxLabelShape::OnBeginDragLeft(double x
, double y
, int keys
, int attachment
)
2455 wxRectangleShape::OnBeginDragLeft(x
, y
, keys
, attachment
);
2458 void wxLabelShape::OnEndDragLeft(double x
, double y
, int keys
, int attachment
)
2460 wxRectangleShape::OnEndDragLeft(x
, y
, keys
, attachment
);
2463 bool wxLabelShape::OnMovePre(wxDC
& dc
, double x
, double y
, double old_x
, double old_y
, bool display
)
2465 return m_lineShape
->OnLabelMovePre(dc
, this, x
, y
, old_x
, old_y
, display
);
2468 bool wxLineShape::OnLabelMovePre(wxDC
& dc
, wxLabelShape
* labelShape
, double x
, double y
, double old_x
, double old_y
, bool display
)
2470 labelShape
->m_shapeRegion
->SetSize(labelShape
->GetWidth(), labelShape
->GetHeight());
2472 // Find position in line's region list
2474 wxNode
*node
= GetRegions().First();
2477 if (labelShape
->m_shapeRegion
== (wxShapeRegion
*)node
->Data())
2481 node
= node
->Next();
2486 GetLabelPosition(i
, &xx
, &yy
);
2487 // Set the region's offset, relative to the default position for
2489 labelShape
->m_shapeRegion
->SetPosition((double)(x
- xx
), (double)(y
- yy
));
2491 labelShape
->SetX(x
);
2492 labelShape
->SetY(y
);
2494 // Need to reformat to fit region.
2495 if (labelShape
->m_shapeRegion
->GetText())
2498 wxString
s(labelShape
->m_shapeRegion
->GetText());
2499 labelShape
->FormatText(dc
, s
, i
);
2500 DrawRegion(dc
, labelShape
->m_shapeRegion
, xx
, yy
);
2505 // Divert left and right clicks to line object
2506 void wxLabelShape::OnLeftClick(double x
, double y
, int keys
, int attachment
)
2508 m_lineShape
->GetEventHandler()->OnLeftClick(x
, y
, keys
, attachment
);
2511 void wxLabelShape::OnRightClick(double x
, double y
, int keys
, int attachment
)
2513 m_lineShape
->GetEventHandler()->OnRightClick(x
, y
, keys
, attachment
);