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>
38 #include "wx/ogl/ogl.h"
42 IMPLEMENT_DYNAMIC_CLASS(wxLineShape
, wxShape
)
44 wxLineShape::wxLineShape()
46 m_sensitivity
= OP_CLICK_LEFT
| OP_CLICK_RIGHT
;
51 m_actualTextWidth = 0.0;
52 m_actualTextHeight = 0.0;
57 m_arrowSpacing
= 5.0; // For the moment, don't bother saving this to file.
58 m_ignoreArrowOffsets
= false;
60 m_maintainStraightLines
= false;
64 m_lineControlPoints
= NULL
;
66 // Clear any existing regions (created in an earlier constructor)
67 // and make the three line regions.
69 wxShapeRegion
*newRegion
= new wxShapeRegion
;
70 newRegion
->SetName(wxT("Middle"));
71 newRegion
->SetSize(150, 50);
72 m_regions
.Append((wxObject
*)newRegion
);
74 newRegion
= new wxShapeRegion
;
75 newRegion
->SetName(wxT("Start"));
76 newRegion
->SetSize(150, 50);
77 m_regions
.Append((wxObject
*)newRegion
);
79 newRegion
= new wxShapeRegion
;
80 newRegion
->SetName(wxT("End"));
81 newRegion
->SetSize(150, 50);
82 m_regions
.Append((wxObject
*)newRegion
);
84 for (int i
= 0; i
< 3; i
++)
85 m_labelObjects
[i
] = NULL
;
88 wxLineShape::~wxLineShape()
90 if (m_lineControlPoints
)
92 ClearPointList(*m_lineControlPoints
);
93 delete m_lineControlPoints
;
95 for (int i
= 0; i
< 3; i
++)
97 if (m_labelObjects
[i
])
99 m_labelObjects
[i
]->Select(false);
100 m_labelObjects
[i
]->RemoveFromCanvas(m_canvas
);
101 delete m_labelObjects
[i
];
102 m_labelObjects
[i
] = NULL
;
105 ClearArrowsAtPosition(-1);
108 void wxLineShape::MakeLineControlPoints(int n
)
110 if (m_lineControlPoints
)
112 ClearPointList(*m_lineControlPoints
);
113 delete m_lineControlPoints
;
115 m_lineControlPoints
= new wxList
;
117 for (int i
= 0; i
< n
; i
++)
119 wxRealPoint
*point
= new wxRealPoint(-999, -999);
120 m_lineControlPoints
->Append((wxObject
*) point
);
124 wxNode
*wxLineShape::InsertLineControlPoint(wxDC
* dc
)
129 wxNode
*last
= m_lineControlPoints
->GetLast();
130 wxNode
*second_last
= last
->GetPrevious();
131 wxRealPoint
*last_point
= (wxRealPoint
*)last
->GetData();
132 wxRealPoint
*second_last_point
= (wxRealPoint
*)second_last
->GetData();
134 // Choose a point half way between the last and penultimate points
135 double line_x
= ((last_point
->x
+ second_last_point
->x
)/2);
136 double line_y
= ((last_point
->y
+ second_last_point
->y
)/2);
138 wxRealPoint
*point
= new wxRealPoint(line_x
, line_y
);
139 wxNode
*node
= m_lineControlPoints
->Insert(last
, (wxObject
*) point
);
143 bool wxLineShape::DeleteLineControlPoint()
145 if (m_lineControlPoints
->GetCount() < 3)
148 wxNode
*last
= m_lineControlPoints
->GetLast();
149 wxNode
*second_last
= last
->GetPrevious();
151 wxRealPoint
*second_last_point
= (wxRealPoint
*)second_last
->GetData();
152 delete second_last_point
;
158 void wxLineShape::Initialise()
160 if (m_lineControlPoints
)
162 // Just move the first and last control points
163 wxNode
*first
= m_lineControlPoints
->GetFirst();
164 wxRealPoint
*first_point
= (wxRealPoint
*)first
->GetData();
166 wxNode
*last
= m_lineControlPoints
->GetLast();
167 wxRealPoint
*last_point
= (wxRealPoint
*)last
->GetData();
169 // If any of the line points are at -999, we must
170 // initialize them by placing them half way between the first
172 wxNode
*node
= first
->GetNext();
175 wxRealPoint
*point
= (wxRealPoint
*)node
->GetData();
176 if (point
->x
== -999)
178 double x1
, y1
, x2
, y2
;
179 if (first_point
->x
< last_point
->x
)
180 { x1
= first_point
->x
; x2
= last_point
->x
; }
182 { x2
= first_point
->x
; x1
= last_point
->x
; }
184 if (first_point
->y
< last_point
->y
)
185 { y1
= first_point
->y
; y2
= last_point
->y
; }
187 { y2
= first_point
->y
; y1
= last_point
->y
; }
189 point
->x
= ((x2
- x1
)/2 + x1
);
190 point
->y
= ((y2
- y1
)/2 + y1
);
192 node
= node
->GetNext();
197 // Format a text string according to the region size, adding
198 // strings with positions to region text list
199 void wxLineShape::FormatText(wxDC
& dc
, const wxString
& s
, int i
)
204 if (m_regions
.GetCount() < 1)
206 wxNode
*node
= m_regions
.Item(i
);
210 wxShapeRegion
*region
= (wxShapeRegion
*)node
->GetData();
212 dc
.SetFont(* region
->GetFont());
214 region
->GetSize(&w
, &h
);
215 // Initialize the size if zero
216 if (((w
== 0) || (h
== 0)) && (s
.Length() > 0))
219 region
->SetSize(w
, h
);
222 wxStringList
*string_list
= oglFormatText(dc
, s
, (w
-5), (h
-5), region
->GetFormatMode());
223 node
= (wxNode
*)string_list
->GetFirst();
226 wxChar
*s
= (wxChar
*)node
->GetData();
227 wxShapeTextLine
*line
= new wxShapeTextLine(0.0, 0.0, s
);
228 region
->GetFormattedText().Append((wxObject
*)line
);
229 node
= node
->GetNext();
234 if (region
->GetFormatMode() & FORMAT_SIZE_TO_CONTENTS
)
236 oglGetCentredTextExtent(dc
, &(region
->GetFormattedText()), m_xpos
, m_ypos
, w
, h
, &actualW
, &actualH
);
237 if ((actualW
!= w
) || (actualH
!= h
))
240 GetLabelPosition(i
, &xx
, &yy
);
241 EraseRegion(dc
, region
, xx
, yy
);
242 if (m_labelObjects
[i
])
244 m_labelObjects
[i
]->Select(false, &dc
);
245 m_labelObjects
[i
]->Erase(dc
);
246 m_labelObjects
[i
]->SetSize(actualW
, actualH
);
249 region
->SetSize(actualW
, actualH
);
251 if (m_labelObjects
[i
])
253 m_labelObjects
[i
]->Select(true, & dc
);
254 m_labelObjects
[i
]->Draw(dc
);
258 oglCentreText(dc
, &(region
->GetFormattedText()), m_xpos
, m_ypos
, actualW
, actualH
, region
->GetFormatMode());
262 void wxLineShape::DrawRegion(wxDC
& dc
, wxShapeRegion
*region
, double x
, double y
)
264 if (GetDisableLabel())
269 region
->GetSize(&w
, &h
);
271 // Get offset from x, y
272 region
->GetPosition(&xx
, &yy
);
277 // First, clear a rectangle for the text IF there is any
278 if (region
->GetFormattedText().GetCount() > 0)
280 dc
.SetPen(GetBackgroundPen());
281 dc
.SetBrush(GetBackgroundBrush());
284 if (region
->GetFont()) dc
.SetFont(* region
->GetFont());
286 dc
.DrawRectangle((long)(xp
- w
/2.0), (long)(yp
- h
/2.0), (long)w
, (long)h
);
288 if (m_pen
) dc
.SetPen(* m_pen
);
289 dc
.SetTextForeground(region
->GetActualColourObject());
292 dc
.SetTextBackground(GetBackgroundBrush().GetColour());
295 oglDrawFormattedText(dc
, &(region
->GetFormattedText()), xp
, yp
, w
, h
, region
->GetFormatMode());
299 void wxLineShape::EraseRegion(wxDC
& dc
, wxShapeRegion
*region
, double x
, double y
)
301 if (GetDisableLabel())
306 region
->GetSize(&w
, &h
);
308 // Get offset from x, y
309 region
->GetPosition(&xx
, &yy
);
314 if (region
->GetFormattedText().GetCount() > 0)
316 dc
.SetPen(GetBackgroundPen());
317 dc
.SetBrush(GetBackgroundBrush());
319 dc
.DrawRectangle((long)(xp
- w
/2.0), (long)(yp
- h
/2.0), (long)w
, (long)h
);
323 // Get the reference point for a label. Region x and y
324 // are offsets from this.
325 // position is 0, 1, 2
326 void wxLineShape::GetLabelPosition(int position
, double *x
, double *y
)
332 // Want to take the middle section for the label
333 int n
= m_lineControlPoints
->GetCount();
334 int half_way
= (int)(n
/2);
336 // Find middle of this line
337 wxNode
*node
= m_lineControlPoints
->Item(half_way
- 1);
338 wxRealPoint
*point
= (wxRealPoint
*)node
->GetData();
339 wxNode
*next_node
= node
->GetNext();
340 wxRealPoint
*next_point
= (wxRealPoint
*)next_node
->GetData();
342 double dx
= (next_point
->x
- point
->x
);
343 double dy
= (next_point
->y
- point
->y
);
344 *x
= (double)(point
->x
+ dx
/2.0);
345 *y
= (double)(point
->y
+ dy
/2.0);
350 wxNode
*node
= m_lineControlPoints
->GetFirst();
351 *x
= ((wxRealPoint
*)node
->GetData())->x
;
352 *y
= ((wxRealPoint
*)node
->GetData())->y
;
357 wxNode
*node
= m_lineControlPoints
->GetLast();
358 *x
= ((wxRealPoint
*)node
->GetData())->x
;
359 *y
= ((wxRealPoint
*)node
->GetData())->y
;
368 * Find whether line is supposed to be vertical or horizontal and
372 void GraphicsStraightenLine(wxRealPoint
*point1
, wxRealPoint
*point2
)
374 double dx
= point2
->x
- point1
->x
;
375 double dy
= point2
->y
- point1
->y
;
379 else if (fabs(dy
/dx
) > 1.0)
381 point2
->x
= point1
->x
;
383 else point2
->y
= point1
->y
;
386 void wxLineShape::Straighten(wxDC
*dc
)
388 if (!m_lineControlPoints
|| m_lineControlPoints
->GetCount() < 3)
394 wxNode
*first_point_node
= m_lineControlPoints
->GetFirst();
395 wxNode
*last_point_node
= m_lineControlPoints
->GetLast();
396 wxNode
*second_last_point_node
= last_point_node
->GetPrevious();
398 wxRealPoint
*last_point
= (wxRealPoint
*)last_point_node
->GetData();
399 wxRealPoint
*second_last_point
= (wxRealPoint
*)second_last_point_node
->GetData();
401 GraphicsStraightenLine(last_point
, second_last_point
);
403 wxNode
*node
= first_point_node
;
404 while (node
&& (node
!= second_last_point_node
))
406 wxRealPoint
*point
= (wxRealPoint
*)node
->GetData();
407 wxRealPoint
*next_point
= (wxRealPoint
*)(node
->GetNext()->GetData());
409 GraphicsStraightenLine(point
, next_point
);
410 node
= node
->GetNext();
418 void wxLineShape::Unlink()
421 m_to
->GetLines().DeleteObject(this);
423 m_from
->GetLines().DeleteObject(this);
428 void wxLineShape::SetEnds(double x1
, double y1
, double x2
, double y2
)
431 wxNode
*first_point_node
= m_lineControlPoints
->GetFirst();
432 wxNode
*last_point_node
= m_lineControlPoints
->GetLast();
433 wxRealPoint
*first_point
= (wxRealPoint
*)first_point_node
->GetData();
434 wxRealPoint
*last_point
= (wxRealPoint
*)last_point_node
->GetData();
441 m_xpos
= (double)((x1
+ x2
)/2.0);
442 m_ypos
= (double)((y1
+ y2
)/2.0);
445 // Get absolute positions of ends
446 void wxLineShape::GetEnds(double *x1
, double *y1
, double *x2
, double *y2
)
448 wxNode
*first_point_node
= m_lineControlPoints
->GetFirst();
449 wxNode
*last_point_node
= m_lineControlPoints
->GetLast();
450 wxRealPoint
*first_point
= (wxRealPoint
*)first_point_node
->GetData();
451 wxRealPoint
*last_point
= (wxRealPoint
*)last_point_node
->GetData();
453 *x1
= first_point
->x
; *y1
= first_point
->y
;
454 *x2
= last_point
->x
; *y2
= last_point
->y
;
457 void wxLineShape::SetAttachments(int from_attach
, int to_attach
)
459 m_attachmentFrom
= from_attach
;
460 m_attachmentTo
= to_attach
;
463 bool wxLineShape::HitTest(double x
, double y
, int *attachment
, double *distance
)
465 if (!m_lineControlPoints
)
468 // Look at label regions in case mouse is over a label
469 bool inLabelRegion
= false;
470 for (int i
= 0; i
< 3; i
++)
472 wxNode
*regionNode
= m_regions
.Item(i
);
475 wxShapeRegion
*region
= (wxShapeRegion
*)regionNode
->GetData();
476 if (region
->m_formattedText
.GetCount() > 0)
478 double xp
, yp
, cx
, cy
, cw
, ch
;
479 GetLabelPosition(i
, &xp
, &yp
);
480 // Offset region from default label position
481 region
->GetPosition(&cx
, &cy
);
482 region
->GetSize(&cw
, &ch
);
485 double rLeft
= (double)(cx
- (cw
/2.0));
486 double rTop
= (double)(cy
- (ch
/2.0));
487 double rRight
= (double)(cx
+ (cw
/2.0));
488 double rBottom
= (double)(cy
+ (ch
/2.0));
489 if (x
> rLeft
&& x
< rRight
&& y
> rTop
&& y
< rBottom
)
491 inLabelRegion
= true;
498 wxNode
*node
= m_lineControlPoints
->GetFirst();
500 while (node
&& node
->GetNext())
502 wxRealPoint
*point1
= (wxRealPoint
*)node
->GetData();
503 wxRealPoint
*point2
= (wxRealPoint
*)node
->GetNext()->GetData();
505 // For inaccurate mousing allow 8 pixel corridor
508 double dx
= point2
->x
- point1
->x
;
509 double dy
= point2
->y
- point1
->y
;
510 double seg_len
= sqrt(dx
*dx
+dy
*dy
);
511 double distance_from_seg
=
512 seg_len
*((x
-point1
->x
)*dy
-(y
-point1
->y
)*dx
)/(dy
*dy
+dx
*dx
);
513 double distance_from_prev
=
514 seg_len
*((y
-point1
->y
)*dy
+(x
-point1
->x
)*dx
)/(dy
*dy
+dx
*dx
);
516 if ((fabs(distance_from_seg
) < extra
&&
517 distance_from_prev
>= 0 && distance_from_prev
<= seg_len
)
521 *distance
= distance_from_seg
;
525 node
= node
->GetNext();
530 void wxLineShape::DrawArrows(wxDC
& dc
)
532 // Distance along line of each arrow: space them out evenly.
533 double startArrowPos
= 0.0;
534 double endArrowPos
= 0.0;
535 double middleArrowPos
= 0.0;
537 wxNode
*node
= m_arcArrows
.GetFirst();
540 wxArrowHead
*arrow
= (wxArrowHead
*)node
->GetData();
541 switch (arrow
->GetArrowEnd())
543 case ARROW_POSITION_START
:
545 if ((arrow
->GetXOffset() != 0.0) && !m_ignoreArrowOffsets
)
546 // If specified, x offset is proportional to line length
547 DrawArrow(dc
, arrow
, arrow
->GetXOffset(), true);
550 DrawArrow(dc
, arrow
, startArrowPos
, false); // Absolute distance
551 startArrowPos
+= arrow
->GetSize() + arrow
->GetSpacing();
555 case ARROW_POSITION_END
:
557 if ((arrow
->GetXOffset() != 0.0) && !m_ignoreArrowOffsets
)
558 DrawArrow(dc
, arrow
, arrow
->GetXOffset(), true);
561 DrawArrow(dc
, arrow
, endArrowPos
, false);
562 endArrowPos
+= arrow
->GetSize() + arrow
->GetSpacing();
566 case ARROW_POSITION_MIDDLE
:
568 arrow
->SetXOffset(middleArrowPos
);
569 if ((arrow
->GetXOffset() != 0.0) && !m_ignoreArrowOffsets
)
570 DrawArrow(dc
, arrow
, arrow
->GetXOffset(), true);
573 DrawArrow(dc
, arrow
, middleArrowPos
, false);
574 middleArrowPos
+= arrow
->GetSize() + arrow
->GetSpacing();
579 node
= node
->GetNext();
583 void wxLineShape::DrawArrow(wxDC
& dc
, wxArrowHead
*arrow
, double xOffset
, bool proportionalOffset
)
585 wxNode
*first_line_node
= m_lineControlPoints
->GetFirst();
586 wxRealPoint
*first_line_point
= (wxRealPoint
*)first_line_node
->GetData();
587 wxNode
*second_line_node
= first_line_node
->GetNext();
588 wxRealPoint
*second_line_point
= (wxRealPoint
*)second_line_node
->GetData();
590 wxNode
*last_line_node
= m_lineControlPoints
->GetLast();
591 wxRealPoint
*last_line_point
= (wxRealPoint
*)last_line_node
->GetData();
592 wxNode
*second_last_line_node
= last_line_node
->GetPrevious();
593 wxRealPoint
*second_last_line_point
= (wxRealPoint
*)second_last_line_node
->GetData();
595 // Position where we want to start drawing
596 double positionOnLineX
= 0.0, positionOnLineY
= 0.0;
598 // Position of start point of line, at the end of which we draw the arrow.
599 double startPositionX
= 0.0 , startPositionY
= 0.0;
601 switch (arrow
->GetPosition())
603 case ARROW_POSITION_START
:
605 // If we're using a proportional offset, calculate just where this will
607 double realOffset
= xOffset
;
608 if (proportionalOffset
)
611 (double)sqrt((second_line_point
->x
- first_line_point
->x
)*(second_line_point
->x
- first_line_point
->x
) +
612 (second_line_point
->y
- first_line_point
->y
)*(second_line_point
->y
- first_line_point
->y
));
613 realOffset
= (double)(xOffset
* totalLength
);
615 GetPointOnLine(second_line_point
->x
, second_line_point
->y
,
616 first_line_point
->x
, first_line_point
->y
,
617 realOffset
, &positionOnLineX
, &positionOnLineY
);
618 startPositionX
= second_line_point
->x
;
619 startPositionY
= second_line_point
->y
;
622 case ARROW_POSITION_END
:
624 // If we're using a proportional offset, calculate just where this will
626 double realOffset
= xOffset
;
627 if (proportionalOffset
)
630 (double)sqrt((second_last_line_point
->x
- last_line_point
->x
)*(second_last_line_point
->x
- last_line_point
->x
) +
631 (second_last_line_point
->y
- last_line_point
->y
)*(second_last_line_point
->y
- last_line_point
->y
));
632 realOffset
= (double)(xOffset
* totalLength
);
634 GetPointOnLine(second_last_line_point
->x
, second_last_line_point
->y
,
635 last_line_point
->x
, last_line_point
->y
,
636 realOffset
, &positionOnLineX
, &positionOnLineY
);
637 startPositionX
= second_last_line_point
->x
;
638 startPositionY
= second_last_line_point
->y
;
641 case ARROW_POSITION_MIDDLE
:
643 // Choose a point half way between the last and penultimate points
644 double x
= ((last_line_point
->x
+ second_last_line_point
->x
)/2);
645 double y
= ((last_line_point
->y
+ second_last_line_point
->y
)/2);
647 // If we're using a proportional offset, calculate just where this will
649 double realOffset
= xOffset
;
650 if (proportionalOffset
)
653 (double)sqrt((second_last_line_point
->x
- x
)*(second_last_line_point
->x
- x
) +
654 (second_last_line_point
->y
- y
)*(second_last_line_point
->y
- y
));
655 realOffset
= (double)(xOffset
* totalLength
);
658 GetPointOnLine(second_last_line_point
->x
, second_last_line_point
->y
,
659 x
, y
, realOffset
, &positionOnLineX
, &positionOnLineY
);
660 startPositionX
= second_last_line_point
->x
;
661 startPositionY
= second_last_line_point
->y
;
667 * Add yOffset to arrow, if any
670 const double myPi
= (double) M_PI
;
671 // The translation that the y offset may give
674 if ((arrow
->GetYOffset() != 0.0) && !m_ignoreArrowOffsets
)
680 (x1, y1)--------------(x3, y3)------------------(x2, y2)
681 x4 = x3 - d * sin(theta)
682 y4 = y3 + d * cos(theta)
684 Where theta = tan(-1) of (y3-y1)/(x3-x1)
686 double x1
= startPositionX
;
687 double y1
= startPositionY
;
688 double x3
= positionOnLineX
;
689 double y3
= positionOnLineY
;
690 double d
= -arrow
->GetYOffset(); // Negate so +offset is above line
694 theta
= (double)(myPi
/2.0);
696 theta
= (double)atan((y3
-y1
)/(x3
-x1
));
698 double x4
= (double)(x3
- (d
*sin(theta
)));
699 double y4
= (double)(y3
+ (d
*cos(theta
)));
701 deltaX
= x4
- positionOnLineX
;
702 deltaY
= y4
- positionOnLineY
;
705 switch (arrow
->_GetType())
709 double arrowLength
= arrow
->GetSize();
710 double arrowWidth
= (double)(arrowLength
/3.0);
712 double tip_x
, tip_y
, side1_x
, side1_y
, side2_x
, side2_y
;
713 oglGetArrowPoints(startPositionX
+deltaX
, startPositionY
+deltaY
,
714 positionOnLineX
+deltaX
, positionOnLineY
+deltaY
,
715 arrowLength
, arrowWidth
, &tip_x
, &tip_y
,
716 &side1_x
, &side1_y
, &side2_x
, &side2_y
);
719 points
[0].x
= (int) tip_x
; points
[0].y
= (int) tip_y
;
720 points
[1].x
= (int) side1_x
; points
[1].y
= (int) side1_y
;
721 points
[2].x
= (int) side2_x
; points
[2].y
= (int) side2_y
;
722 points
[3].x
= (int) tip_x
; points
[3].y
= (int) tip_y
;
725 dc
.SetBrush(* m_brush
);
726 dc
.DrawPolygon(4, points
);
729 case ARROW_HOLLOW_CIRCLE
:
730 case ARROW_FILLED_CIRCLE
:
732 // Find point on line of centre of circle, which is a radius away
733 // from the end position
734 double diameter
= (double)(arrow
->GetSize());
736 GetPointOnLine(startPositionX
+deltaX
, startPositionY
+deltaY
,
737 positionOnLineX
+deltaX
, positionOnLineY
+deltaY
,
738 (double)(diameter
/2.0),
741 // Convert ellipse centre to top-left coordinates
742 double x1
= (double)(x
- (diameter
/2.0));
743 double y1
= (double)(y
- (diameter
/2.0));
746 if (arrow
->_GetType() == ARROW_HOLLOW_CIRCLE
)
747 dc
.SetBrush(GetBackgroundBrush());
749 dc
.SetBrush(* m_brush
);
751 dc
.DrawEllipse((long) x1
, (long) y1
, (long) diameter
, (long) diameter
);
754 case ARROW_SINGLE_OBLIQUE
:
760 if (arrow
->GetMetaFile())
762 // Find point on line of centre of object, which is a half-width away
763 // from the end position
766 * <-- start pos <-----><-- positionOnLineX
768 * --------------| x | <-- e.g. rectangular arrowhead
772 GetPointOnLine(startPositionX
, startPositionY
,
773 positionOnLineX
, positionOnLineY
,
774 (double)(arrow
->GetMetaFile()->m_width
/2.0),
777 // Calculate theta for rotating the metafile.
780 | o(x2, y2) 'o' represents the arrowhead.
785 |______________________
788 double x1
= startPositionX
;
789 double y1
= startPositionY
;
790 double x2
= positionOnLineX
;
791 double y2
= positionOnLineY
;
793 if ((x1
== x2
) && (y1
== y2
))
796 else if ((x1
== x2
) && (y1
> y2
))
797 theta
= (double)(3.0*myPi
/2.0);
799 else if ((x1
== x2
) && (y2
> y1
))
800 theta
= (double)(myPi
/2.0);
802 else if ((x2
> x1
) && (y2
>= y1
))
803 theta
= (double)atan((y2
- y1
)/(x2
- x1
));
806 theta
= (double)(myPi
+ atan((y2
- y1
)/(x2
- x1
)));
808 else if ((x2
> x1
) && (y2
< y1
))
809 theta
= (double)(2*myPi
+ atan((y2
- y1
)/(x2
- x1
)));
813 wxLogFatalError(wxT("Unknown arrowhead rotation case in lines.cc"));
816 // Rotate about the centre of the object, then place
817 // the object on the line.
818 if (arrow
->GetMetaFile()->GetRotateable())
819 arrow
->GetMetaFile()->Rotate(0.0, 0.0, theta
);
823 // If erasing, just draw a rectangle.
824 double minX
, minY
, maxX
, maxY
;
825 arrow
->GetMetaFile()->GetBounds(&minX
, &minY
, &maxX
, &maxY
);
826 // Make erasing rectangle slightly bigger or you get droppings.
828 dc
.DrawRectangle((long)(deltaX
+ x
+ minX
- (extraPixels
/2.0)), (long)(deltaY
+ y
+ minY
- (extraPixels
/2.0)),
829 (long)(maxX
- minX
+ extraPixels
), (long)(maxY
- minY
+ extraPixels
));
832 arrow
->GetMetaFile()->Draw(dc
, x
+deltaX
, y
+deltaY
);
842 void wxLineShape::OnErase(wxDC
& dc
)
844 wxPen
*old_pen
= m_pen
;
845 wxBrush
*old_brush
= m_brush
;
846 wxPen bg_pen
= GetBackgroundPen();
847 wxBrush bg_brush
= GetBackgroundBrush();
851 double bound_x
, bound_y
;
852 GetBoundingBoxMax(&bound_x
, &bound_y
);
853 if (m_font
) dc
.SetFont(* m_font
);
855 // Undraw text regions
856 for (int i
= 0; i
< 3; i
++)
858 wxNode
*node
= m_regions
.Item(i
);
862 wxShapeRegion
*region
= (wxShapeRegion
*)node
->GetData();
863 GetLabelPosition(i
, &x
, &y
);
864 EraseRegion(dc
, region
, x
, y
);
869 dc
.SetPen(GetBackgroundPen());
870 dc
.SetBrush(GetBackgroundBrush());
872 // Drawing over the line only seems to work if the line has a thickness
874 if (old_pen
&& (old_pen
->GetWidth() > 1))
876 dc
.DrawRectangle((long)(m_xpos
- (bound_x
/2.0) - 2.0), (long)(m_ypos
- (bound_y
/2.0) - 2.0),
877 (long)(bound_x
+4.0), (long)(bound_y
+4.0));
882 GetEventHandler()->OnDraw(dc
);
883 GetEventHandler()->OnEraseControlPoints(dc
);
887 if (old_pen
) SetPen(old_pen
);
888 if (old_brush
) SetBrush(old_brush
);
891 void wxLineShape::GetBoundingBoxMin(double *w
, double *h
)
898 wxNode
*node
= m_lineControlPoints
->GetFirst();
901 wxRealPoint
*point
= (wxRealPoint
*)node
->GetData();
903 if (point
->x
< x1
) x1
= point
->x
;
904 if (point
->y
< y1
) y1
= point
->y
;
905 if (point
->x
> x2
) x2
= point
->x
;
906 if (point
->y
> y2
) y2
= point
->y
;
908 node
= node
->GetNext();
910 *w
= (double)(x2
- x1
);
911 *h
= (double)(y2
- y1
);
915 * For a node image of interest, finds the position of this arc
916 * amongst all the arcs which are attached to THIS SIDE of the node image,
917 * and the number of same.
919 void wxLineShape::FindNth(wxShape
*image
, int *nth
, int *no_arcs
, bool incoming
)
923 wxNode
*node
= image
->GetLines().GetFirst();
926 this_attachment
= m_attachmentTo
;
928 this_attachment
= m_attachmentFrom
;
930 // Find number of lines going into/out of this particular attachment point
933 wxLineShape
*line
= (wxLineShape
*)node
->GetData();
935 if (line
->m_from
== image
)
937 // This is the nth line attached to 'image'
938 if ((line
== this) && !incoming
)
941 // Increment num count if this is the same side (attachment number)
942 if (line
->m_attachmentFrom
== this_attachment
)
946 if (line
->m_to
== image
)
948 // This is the nth line attached to 'image'
949 if ((line
== this) && incoming
)
952 // Increment num count if this is the same side (attachment number)
953 if (line
->m_attachmentTo
== this_attachment
)
957 node
= node
->GetNext();
963 void wxLineShape::OnDrawOutline(wxDC
& dc
, double WXUNUSED(x
), double WXUNUSED(y
), double WXUNUSED(w
), double WXUNUSED(h
))
965 wxPen
*old_pen
= m_pen
;
966 wxBrush
*old_brush
= m_brush
;
968 wxPen
dottedPen(wxColour(0, 0, 0), 1, wxDOT
);
970 SetBrush( wxTRANSPARENT_BRUSH
);
972 GetEventHandler()->OnDraw(dc
);
974 if (old_pen
) SetPen(old_pen
);
976 if (old_brush
) SetBrush(old_brush
);
980 bool wxLineShape::OnMovePre(wxDC
& dc
, double x
, double y
, double old_x
, double old_y
, bool WXUNUSED(display
))
982 double x_offset
= x
- old_x
;
983 double y_offset
= y
- old_y
;
985 if (m_lineControlPoints
&& !(x_offset
== 0.0 && y_offset
== 0.0))
987 wxNode
*node
= m_lineControlPoints
->GetFirst();
990 wxRealPoint
*point
= (wxRealPoint
*)node
->GetData();
991 point
->x
+= x_offset
;
992 point
->y
+= y_offset
;
993 node
= node
->GetNext();
998 // Move temporary label rectangles if necessary
999 for (int i
= 0; i
< 3; i
++)
1001 if (m_labelObjects
[i
])
1003 m_labelObjects
[i
]->Erase(dc
);
1004 double xp
, yp
, xr
, yr
;
1005 GetLabelPosition(i
, &xp
, &yp
);
1006 wxNode
*node
= m_regions
.Item(i
);
1009 wxShapeRegion
*region
= (wxShapeRegion
*)node
->GetData();
1010 region
->GetPosition(&xr
, &yr
);
1017 m_labelObjects
[i
]->Move(dc
, xp
+xr
, yp
+yr
);
1023 void wxLineShape::OnMoveLink(wxDC
& dc
, bool moveControlPoints
)
1025 if (!m_from
|| !m_to
)
1028 if (m_lineControlPoints
->GetCount() > 2)
1031 // Do each end - nothing in the middle. User has to move other points
1032 // manually if necessary.
1033 double end_x
, end_y
;
1034 double other_end_x
, other_end_y
;
1036 FindLineEndPoints(&end_x
, &end_y
, &other_end_x
, &other_end_y
);
1038 wxNode
*first
= m_lineControlPoints
->GetFirst();
1039 /* wxRealPoint *first_point = */ (wxRealPoint
*)first
->GetData();
1040 wxNode
*last
= m_lineControlPoints
->GetLast();
1041 /* wxRealPoint *last_point = */ (wxRealPoint
*)last
->GetData();
1043 /* This is redundant, surely? Done by SetEnds.
1044 first_point->x = end_x; first_point->y = end_y;
1045 last_point->x = other_end_x; last_point->y = other_end_y;
1048 double oldX
= m_xpos
;
1049 double oldY
= m_ypos
;
1051 SetEnds(end_x
, end_y
, other_end_x
, other_end_y
);
1053 // Do a second time, because one may depend on the other.
1054 FindLineEndPoints(&end_x
, &end_y
, &other_end_x
, &other_end_y
);
1055 SetEnds(end_x
, end_y
, other_end_x
, other_end_y
);
1057 // Try to move control points with the arc
1058 double x_offset
= m_xpos
- oldX
;
1059 double y_offset
= m_ypos
- oldY
;
1061 // if (moveControlPoints && m_lineControlPoints && !(x_offset == 0.0 && y_offset == 0.0))
1062 // Only move control points if it's a self link. And only works if attachment mode is ON.
1063 if ((m_from
== m_to
) && (m_from
->GetAttachmentMode() != ATTACHMENT_MODE_NONE
) && moveControlPoints
&& m_lineControlPoints
&& !(x_offset
== 0.0 && y_offset
== 0.0))
1065 wxNode
*node
= m_lineControlPoints
->GetFirst();
1068 if ((node
!= m_lineControlPoints
->GetFirst()) && (node
!= m_lineControlPoints
->GetLast()))
1070 wxRealPoint
*point
= (wxRealPoint
*)node
->GetData();
1071 point
->x
+= x_offset
;
1072 point
->y
+= y_offset
;
1074 node
= node
->GetNext();
1078 Move(dc
, m_xpos
, m_ypos
);
1081 // Finds the x, y points at the two ends of the line.
1082 // This function can be used by e.g. line-routing routines to
1083 // get the actual points on the two node images where the lines will be drawn
1085 void wxLineShape::FindLineEndPoints(double *fromX
, double *fromY
, double *toX
, double *toY
)
1087 if (!m_from
|| !m_to
)
1090 // Do each end - nothing in the middle. User has to move other points
1091 // manually if necessary.
1092 double end_x
= 0.0, end_y
= 0.0;
1093 double other_end_x
= 0.0, other_end_y
= 0.0;
1095 wxNode
*first
= m_lineControlPoints
->GetFirst();
1096 /* wxRealPoint *first_point = */ (wxRealPoint
*)first
->GetData();
1097 wxNode
*last
= m_lineControlPoints
->GetLast();
1098 /* wxRealPoint *last_point = */ (wxRealPoint
*)last
->GetData();
1100 wxNode
*second
= first
->GetNext();
1101 wxRealPoint
*second_point
= (wxRealPoint
*)second
->GetData();
1103 wxNode
*second_last
= last
->GetPrevious();
1104 wxRealPoint
*second_last_point
= (wxRealPoint
*)second_last
->GetData();
1106 if (m_lineControlPoints
->GetCount() > 2)
1108 if (m_from
->GetAttachmentMode() != ATTACHMENT_MODE_NONE
)
1111 FindNth(m_from
, &nth
, &no_arcs
, false); // Not incoming
1112 m_from
->GetAttachmentPosition(m_attachmentFrom
, &end_x
, &end_y
, nth
, no_arcs
, this);
1115 (void) m_from
->GetPerimeterPoint(m_from
->GetX(), m_from
->GetY(),
1116 (double)second_point
->x
, (double)second_point
->y
,
1119 if (m_to
->GetAttachmentMode() != ATTACHMENT_MODE_NONE
)
1122 FindNth(m_to
, &nth
, &no_arcs
, true); // Incoming
1123 m_to
->GetAttachmentPosition(m_attachmentTo
, &other_end_x
, &other_end_y
, nth
, no_arcs
, this);
1126 (void) m_to
->GetPerimeterPoint(m_to
->GetX(), m_to
->GetY(),
1127 (double)second_last_point
->x
, (double)second_last_point
->y
,
1128 &other_end_x
, &other_end_y
);
1132 double fromX
= m_from
->GetX();
1133 double fromY
= m_from
->GetY();
1134 double toX
= m_to
->GetX();
1135 double toY
= m_to
->GetY();
1137 if (m_from
->GetAttachmentMode() != ATTACHMENT_MODE_NONE
)
1140 FindNth(m_from
, &nth
, &no_arcs
, false);
1141 m_from
->GetAttachmentPosition(m_attachmentFrom
, &end_x
, &end_y
, nth
, no_arcs
, this);
1146 if (m_to
->GetAttachmentMode() != ATTACHMENT_MODE_NONE
)
1149 FindNth(m_to
, &nth
, &no_arcs
, true);
1150 m_to
->GetAttachmentPosition(m_attachmentTo
, &other_end_x
, &other_end_y
, nth
, no_arcs
, this);
1155 if (m_from
->GetAttachmentMode() == ATTACHMENT_MODE_NONE
)
1156 (void) m_from
->GetPerimeterPoint(m_from
->GetX(), m_from
->GetY(),
1160 if (m_to
->GetAttachmentMode() == ATTACHMENT_MODE_NONE
)
1161 (void) m_to
->GetPerimeterPoint(m_to
->GetX(), m_to
->GetY(),
1163 &other_end_x
, &other_end_y
);
1171 void wxLineShape::OnDraw(wxDC
& dc
)
1173 if (m_lineControlPoints
)
1178 dc
.SetBrush(* m_brush
);
1180 int n
= m_lineControlPoints
->GetCount();
1181 wxPoint
*points
= new wxPoint
[n
];
1183 for (i
= 0; i
< n
; i
++)
1185 wxRealPoint
* point
= (wxRealPoint
*) m_lineControlPoints
->Item(i
)->GetData();
1186 points
[i
].x
= WXROUND(point
->x
);
1187 points
[i
].y
= WXROUND(point
->y
);
1191 dc
.DrawSpline(n
, points
);
1193 dc
.DrawLines(n
, points
);
1196 // For some reason, last point isn't drawn under Windows.
1197 dc
.DrawPoint(points
[n
-1]);
1203 // Problem with pen - if not a solid pen, does strange things
1204 // to the arrowhead. So make (get) a new pen that's solid.
1205 if (m_pen
&& (m_pen
->GetStyle() != wxSOLID
))
1208 wxThePenList
->FindOrCreatePen(m_pen
->GetColour(), 1, wxSOLID
);
1210 dc
.SetPen(* solid_pen
);
1216 void wxLineShape::OnDrawControlPoints(wxDC
& dc
)
1221 // Draw temporary label rectangles if necessary
1222 for (int i
= 0; i
< 3; i
++)
1224 if (m_labelObjects
[i
])
1225 m_labelObjects
[i
]->Draw(dc
);
1227 wxShape::OnDrawControlPoints(dc
);
1230 void wxLineShape::OnEraseControlPoints(wxDC
& dc
)
1232 // Erase temporary label rectangles if necessary
1233 for (int i
= 0; i
< 3; i
++)
1235 if (m_labelObjects
[i
])
1236 m_labelObjects
[i
]->Erase(dc
);
1238 wxShape::OnEraseControlPoints(dc
);
1241 void wxLineShape::OnDragLeft(bool WXUNUSED(draw
), double WXUNUSED(x
), double WXUNUSED(y
), int WXUNUSED(keys
), int WXUNUSED(attachment
))
1245 void wxLineShape::OnBeginDragLeft(double WXUNUSED(x
), double WXUNUSED(y
), int WXUNUSED(keys
), int WXUNUSED(attachment
))
1249 void wxLineShape::OnEndDragLeft(double WXUNUSED(x
), double WXUNUSED(y
), int WXUNUSED(keys
), int WXUNUSED(attachment
))
1254 void wxLineShape::SetArrowSize(double length, double width)
1256 arrow_length = length;
1257 arrow_width = width;
1260 void wxLineShape::SetStartArrow(int style)
1262 start_style = style;
1265 void wxLineShape::SetMiddleArrow(int style)
1267 middle_style = style;
1270 void wxLineShape::SetEndArrow(int style)
1276 void wxLineShape::OnDrawContents(wxDC
& dc
)
1278 if (GetDisableLabel())
1281 for (int i
= 0; i
< 3; i
++)
1283 wxNode
*node
= m_regions
.Item(i
);
1286 wxShapeRegion
*region
= (wxShapeRegion
*)node
->GetData();
1288 GetLabelPosition(i
, &x
, &y
);
1289 DrawRegion(dc
, region
, x
, y
);
1294 void wxLineShape::SetTo(wxShape
*object
)
1299 void wxLineShape::SetFrom(wxShape
*object
)
1304 void wxLineShape::MakeControlPoints()
1306 if (m_canvas
&& m_lineControlPoints
)
1308 wxNode
*first
= m_lineControlPoints
->GetFirst();
1309 wxNode
*last
= m_lineControlPoints
->GetLast();
1310 wxRealPoint
*first_point
= (wxRealPoint
*)first
->GetData();
1311 wxRealPoint
*last_point
= (wxRealPoint
*)last
->GetData();
1313 wxLineControlPoint
*control
= new wxLineControlPoint(m_canvas
, this, CONTROL_POINT_SIZE
,
1314 first_point
->x
, first_point
->y
,
1315 CONTROL_POINT_ENDPOINT_FROM
);
1316 control
->m_point
= first_point
;
1317 m_canvas
->AddShape(control
);
1318 m_controlPoints
.Append(control
);
1321 wxNode
*node
= first
->GetNext();
1322 while (node
!= last
)
1324 wxRealPoint
*point
= (wxRealPoint
*)node
->GetData();
1326 control
= new wxLineControlPoint(m_canvas
, this, CONTROL_POINT_SIZE
,
1328 CONTROL_POINT_LINE
);
1329 control
->m_point
= point
;
1331 m_canvas
->AddShape(control
);
1332 m_controlPoints
.Append(control
);
1334 node
= node
->GetNext();
1336 control
= new wxLineControlPoint(m_canvas
, this, CONTROL_POINT_SIZE
,
1337 last_point
->x
, last_point
->y
,
1338 CONTROL_POINT_ENDPOINT_TO
);
1339 control
->m_point
= last_point
;
1340 m_canvas
->AddShape(control
);
1341 m_controlPoints
.Append(control
);
1347 void wxLineShape::ResetControlPoints()
1349 if (m_canvas
&& m_lineControlPoints
&& m_controlPoints
.GetCount() > 0)
1351 wxNode
*node
= m_controlPoints
.GetFirst();
1352 wxNode
*control_node
= m_lineControlPoints
->GetFirst();
1353 while (node
&& control_node
)
1355 wxRealPoint
*point
= (wxRealPoint
*)control_node
->GetData();
1356 wxLineControlPoint
*control
= (wxLineControlPoint
*)node
->GetData();
1357 control
->SetX(point
->x
);
1358 control
->SetY(point
->y
);
1360 node
= node
->GetNext();
1361 control_node
= control_node
->GetNext();
1367 void wxLineShape::WriteAttributes(wxExpr
*clause
)
1369 wxShape::WriteAttributes(clause
);
1372 clause
->AddAttributeValue(_T("from"), m_from
->GetId());
1374 clause
->AddAttributeValue(_T("to"), m_to
->GetId());
1376 if (m_attachmentTo
!= 0)
1377 clause
->AddAttributeValue(_T("attachment_to"), (long)m_attachmentTo
);
1378 if (m_attachmentFrom
!= 0)
1379 clause
->AddAttributeValue(_T("attachment_from"), (long)m_attachmentFrom
);
1381 if (m_alignmentStart
!= 0)
1382 clause
->AddAttributeValue(_T("align_start"), (long)m_alignmentStart
);
1383 if (m_alignmentEnd
!= 0)
1384 clause
->AddAttributeValue(_T("align_end"), (long)m_alignmentEnd
);
1386 clause
->AddAttributeValue(_T("is_spline"), (long)m_isSpline
);
1387 if (m_maintainStraightLines
)
1388 clause
->AddAttributeValue(_T("keep_lines_straight"), (long)m_maintainStraightLines
);
1390 // Make a list of lists for the (sp)line controls
1391 wxExpr
*list
= new wxExpr(wxExprList
);
1392 wxNode
*node
= m_lineControlPoints
->GetFirst();
1395 wxRealPoint
*point
= (wxRealPoint
*)node
->GetData();
1396 wxExpr
*point_list
= new wxExpr(wxExprList
);
1397 wxExpr
*x_expr
= new wxExpr((double) point
->x
);
1398 wxExpr
*y_expr
= new wxExpr((double) point
->y
);
1399 point_list
->Append(x_expr
);
1400 point_list
->Append(y_expr
);
1401 list
->Append(point_list
);
1403 node
= node
->GetNext();
1405 clause
->AddAttributeValue(_T("controls"), list
);
1407 // Write arc arrows in new OGL format, if there are any.
1408 // This is a list of lists. Each sublist comprises:
1409 // (arrowType arrowEnd xOffset arrowSize)
1410 if (m_arcArrows
.GetCount() > 0)
1412 wxExpr
*arrow_list
= new wxExpr(wxExprList
);
1413 node
= m_arcArrows
.GetFirst();
1416 wxArrowHead
*head
= (wxArrowHead
*)node
->GetData();
1417 wxExpr
*head_list
= new wxExpr(wxExprList
);
1418 head_list
->Append(new wxExpr((long)head
->_GetType()));
1419 head_list
->Append(new wxExpr((long)head
->GetArrowEnd()));
1420 head_list
->Append(new wxExpr(head
->GetXOffset()));
1421 head_list
->Append(new wxExpr(head
->GetArrowSize()));
1422 head_list
->Append(new wxExpr(wxExprString
, head
->GetName()));
1423 head_list
->Append(new wxExpr(head
->GetId()));
1425 // New members of wxArrowHead
1426 head_list
->Append(new wxExpr(head
->GetYOffset()));
1427 head_list
->Append(new wxExpr(head
->GetSpacing()));
1429 arrow_list
->Append(head_list
);
1431 node
= node
->GetNext();
1433 clause
->AddAttributeValue(_T("arrows"), arrow_list
);
1437 void wxLineShape::ReadAttributes(wxExpr
*clause
)
1439 wxShape::ReadAttributes(clause
);
1441 int iVal
= (int) m_isSpline
;
1442 clause
->AssignAttributeValue(wxT("is_spline"), &iVal
);
1443 m_isSpline
= (iVal
!= 0);
1445 iVal
= (int) m_maintainStraightLines
;
1446 clause
->AssignAttributeValue(wxT("keep_lines_straight"), &iVal
);
1447 m_maintainStraightLines
= (iVal
!= 0);
1449 clause
->AssignAttributeValue(wxT("align_start"), &m_alignmentStart
);
1450 clause
->AssignAttributeValue(wxT("align_end"), &m_alignmentEnd
);
1452 // Compatibility: check for no regions.
1453 if (m_regions
.GetCount() == 0)
1455 wxShapeRegion
*newRegion
= new wxShapeRegion
;
1456 newRegion
->SetName(_T("Middle"));
1457 newRegion
->SetSize(150, 50);
1458 m_regions
.Append((wxObject
*)newRegion
);
1459 if (m_text
.GetCount() > 0)
1461 newRegion
->ClearText();
1462 wxNode
*node
= m_text
.GetFirst();
1465 wxShapeTextLine
*textLine
= (wxShapeTextLine
*)node
->GetData();
1466 wxNode
*next
= node
->GetNext();
1467 newRegion
->GetFormattedText().Append((wxObject
*)textLine
);
1473 newRegion
= new wxShapeRegion
;
1474 newRegion
->SetName(wxT("Start"));
1475 newRegion
->SetSize(150, 50);
1476 m_regions
.Append((wxObject
*)newRegion
);
1478 newRegion
= new wxShapeRegion
;
1479 newRegion
->SetName(wxT("End"));
1480 newRegion
->SetSize(150, 50);
1481 m_regions
.Append((wxObject
*)newRegion
);
1485 m_attachmentFrom
= 0;
1487 clause
->AssignAttributeValue(wxT("attachment_to"), &m_attachmentTo
);
1488 clause
->AssignAttributeValue(wxT("attachment_from"), &m_attachmentFrom
);
1490 wxExpr
*line_list
= NULL
;
1492 // When image is created, there are default control points. Override
1493 // them if there are some in the file.
1494 clause
->AssignAttributeValue(wxT("controls"), &line_list
);
1498 // Read a list of lists for the spline controls
1499 if (m_lineControlPoints
)
1501 ClearPointList(*m_lineControlPoints
);
1504 m_lineControlPoints
= new wxList
;
1506 wxExpr
*node
= line_list
->value
.first
;
1510 wxExpr
*xexpr
= node
->value
.first
;
1511 double x
= xexpr
->RealValue();
1513 wxExpr
*yexpr
= xexpr
->next
;
1514 double y
= yexpr
->RealValue();
1516 wxRealPoint
*point
= new wxRealPoint(x
, y
);
1517 m_lineControlPoints
->Append((wxObject
*) point
);
1523 // Read arrow list, for new OGL code
1524 wxExpr
*arrow_list
= NULL
;
1526 clause
->AssignAttributeValue(wxT("arrows"), &arrow_list
);
1529 wxExpr
*node
= arrow_list
->value
.first
;
1533 WXTYPE arrowType
= ARROW_ARROW
;
1535 double xOffset
= 0.0;
1536 double arrowSize
= 0.0;
1540 wxExpr
*type_expr
= node
->Nth(0);
1541 wxExpr
*end_expr
= node
->Nth(1);
1542 wxExpr
*dist_expr
= node
->Nth(2);
1543 wxExpr
*size_expr
= node
->Nth(3);
1544 wxExpr
*name_expr
= node
->Nth(4);
1545 wxExpr
*id_expr
= node
->Nth(5);
1547 // New members of wxArrowHead
1548 wxExpr
*yOffsetExpr
= node
->Nth(6);
1549 wxExpr
*spacingExpr
= node
->Nth(7);
1552 arrowType
= (int)type_expr
->IntegerValue();
1554 arrowEnd
= (int)end_expr
->IntegerValue();
1556 xOffset
= dist_expr
->RealValue();
1558 arrowSize
= size_expr
->RealValue();
1560 arrowName
= name_expr
->StringValue();
1562 arrowId
= id_expr
->IntegerValue();
1565 arrowId
= wxNewId();
1567 wxRegisterId(arrowId
);
1569 wxArrowHead
*arrowHead
= AddArrow(arrowType
, arrowEnd
, arrowSize
, xOffset
, arrowName
, NULL
, arrowId
);
1571 arrowHead
->SetYOffset(yOffsetExpr
->RealValue());
1573 arrowHead
->SetSpacing(spacingExpr
->RealValue());
1581 void wxLineShape::Copy(wxShape
& copy
)
1583 wxShape::Copy(copy
);
1585 wxASSERT( copy
.IsKindOf(CLASSINFO(wxLineShape
)) );
1587 wxLineShape
& lineCopy
= (wxLineShape
&) copy
;
1589 lineCopy
.m_to
= m_to
;
1590 lineCopy
.m_from
= m_from
;
1591 lineCopy
.m_attachmentTo
= m_attachmentTo
;
1592 lineCopy
.m_attachmentFrom
= m_attachmentFrom
;
1593 lineCopy
.m_isSpline
= m_isSpline
;
1594 lineCopy
.m_alignmentStart
= m_alignmentStart
;
1595 lineCopy
.m_alignmentEnd
= m_alignmentEnd
;
1596 lineCopy
.m_maintainStraightLines
= m_maintainStraightLines
;
1597 lineCopy
.m_lineOrientations
.Clear();
1599 wxNode
*node
= m_lineOrientations
.GetFirst();
1602 lineCopy
.m_lineOrientations
.Append(node
->GetData());
1603 node
= node
->GetNext();
1606 if (lineCopy
.m_lineControlPoints
)
1608 ClearPointList(*lineCopy
.m_lineControlPoints
);
1609 delete lineCopy
.m_lineControlPoints
;
1612 lineCopy
.m_lineControlPoints
= new wxList
;
1614 node
= m_lineControlPoints
->GetFirst();
1617 wxRealPoint
*point
= (wxRealPoint
*)node
->GetData();
1618 wxRealPoint
*new_point
= new wxRealPoint(point
->x
, point
->y
);
1619 lineCopy
.m_lineControlPoints
->Append((wxObject
*) new_point
);
1620 node
= node
->GetNext();
1624 lineCopy
.ClearArrowsAtPosition(-1);
1625 node
= m_arcArrows
.GetFirst();
1628 wxArrowHead
*arrow
= (wxArrowHead
*)node
->GetData();
1629 lineCopy
.m_arcArrows
.Append(new wxArrowHead(*arrow
));
1630 node
= node
->GetNext();
1634 // Override select, to create/delete temporary label-moving objects
1635 void wxLineShape::Select(bool select
, wxDC
* dc
)
1637 wxShape::Select(select
, dc
);
1640 for (int i
= 0; i
< 3; i
++)
1642 wxNode
*node
= m_regions
.Item(i
);
1645 wxShapeRegion
*region
= (wxShapeRegion
*)node
->GetData();
1646 if (region
->m_formattedText
.GetCount() > 0)
1648 double w
, h
, x
, y
, xx
, yy
;
1649 region
->GetSize(&w
, &h
);
1650 region
->GetPosition(&x
, &y
);
1651 GetLabelPosition(i
, &xx
, &yy
);
1652 if (m_labelObjects
[i
])
1654 m_labelObjects
[i
]->Select(false);
1655 m_labelObjects
[i
]->RemoveFromCanvas(m_canvas
);
1656 delete m_labelObjects
[i
];
1658 m_labelObjects
[i
] = OnCreateLabelShape(this, region
, w
, h
);
1659 m_labelObjects
[i
]->AddToCanvas(m_canvas
);
1660 m_labelObjects
[i
]->Show(true);
1662 m_labelObjects
[i
]->Move(*dc
, (double)(x
+ xx
), (double)(y
+ yy
));
1663 m_labelObjects
[i
]->Select(true, dc
);
1670 for (int i
= 0; i
< 3; i
++)
1672 if (m_labelObjects
[i
])
1674 m_labelObjects
[i
]->Select(false, dc
);
1675 m_labelObjects
[i
]->Erase(*dc
);
1676 m_labelObjects
[i
]->RemoveFromCanvas(m_canvas
);
1677 delete m_labelObjects
[i
];
1678 m_labelObjects
[i
] = NULL
;
1685 * Line control point
1689 IMPLEMENT_DYNAMIC_CLASS(wxLineControlPoint
, wxControlPoint
)
1691 wxLineControlPoint::wxLineControlPoint(wxShapeCanvas
*theCanvas
, wxShape
*object
, double size
, double x
, double y
, int the_type
):
1692 wxControlPoint(theCanvas
, object
, size
, x
, y
, the_type
)
1700 wxLineControlPoint::~wxLineControlPoint()
1704 void wxLineControlPoint::OnDraw(wxDC
& dc
)
1706 wxRectangleShape::OnDraw(dc
);
1709 // Implement movement of Line point
1710 void wxLineControlPoint::OnDragLeft(bool draw
, double x
, double y
, int keys
, int attachment
)
1712 m_shape
->GetEventHandler()->OnSizingDragLeft(this, draw
, x
, y
, keys
, attachment
);
1715 void wxLineControlPoint::OnBeginDragLeft(double x
, double y
, int keys
, int attachment
)
1717 m_shape
->GetEventHandler()->OnSizingBeginDragLeft(this, x
, y
, keys
, attachment
);
1720 void wxLineControlPoint::OnEndDragLeft(double x
, double y
, int keys
, int attachment
)
1722 m_shape
->GetEventHandler()->OnSizingEndDragLeft(this, x
, y
, keys
, attachment
);
1725 // Control points ('handles') redirect control to the actual shape, to make it easier
1726 // to override sizing behaviour.
1727 void wxLineShape::OnSizingDragLeft(wxControlPoint
* pt
, bool WXUNUSED(draw
), double x
, double y
, int WXUNUSED(keys
), int WXUNUSED(attachment
))
1729 wxLineControlPoint
* lpt
= (wxLineControlPoint
*) pt
;
1731 wxClientDC
dc(GetCanvas());
1732 GetCanvas()->PrepareDC(dc
);
1734 dc
.SetLogicalFunction(OGLRBLF
);
1736 wxPen
dottedPen(wxColour(0, 0, 0), 1, wxDOT
);
1737 dc
.SetPen(dottedPen
);
1738 dc
.SetBrush((* wxTRANSPARENT_BRUSH
));
1740 if (lpt
->m_type
== CONTROL_POINT_LINE
)
1742 m_canvas
->Snap(&x
, &y
);
1744 lpt
->SetX(x
); lpt
->SetY(y
);
1745 lpt
->m_point
->x
= x
; lpt
->m_point
->y
= y
;
1747 wxLineShape
*lineShape
= (wxLineShape
*)this;
1749 wxPen
*old_pen
= lineShape
->GetPen();
1750 wxBrush
*old_brush
= lineShape
->GetBrush();
1752 wxPen
dottedPen(wxColour(0, 0, 0), 1, wxDOT
);
1753 lineShape
->SetPen(& dottedPen
);
1754 lineShape
->SetBrush(wxTRANSPARENT_BRUSH
);
1756 lineShape
->GetEventHandler()->OnMoveLink(dc
, false);
1758 lineShape
->SetPen(old_pen
);
1759 lineShape
->SetBrush(old_brush
);
1762 if (lpt
->m_type
== CONTROL_POINT_ENDPOINT_FROM
|| lpt
->m_type
== CONTROL_POINT_ENDPOINT_TO
)
1764 // lpt->SetX(x); lpt->SetY(y);
1769 void wxLineShape::OnSizingBeginDragLeft(wxControlPoint
* pt
, double x
, double y
, int WXUNUSED(keys
), int WXUNUSED(attachment
))
1771 wxLineControlPoint
* lpt
= (wxLineControlPoint
*) pt
;
1773 wxClientDC
dc(GetCanvas());
1774 GetCanvas()->PrepareDC(dc
);
1776 wxLineShape
*lineShape
= (wxLineShape
*)this;
1777 if (lpt
->m_type
== CONTROL_POINT_LINE
)
1779 lpt
->m_originalPos
= * (lpt
->m_point
);
1780 m_canvas
->Snap(&x
, &y
);
1784 // Redraw start and end objects because we've left holes
1785 // when erasing the line
1786 lineShape
->GetFrom()->OnDraw(dc
);
1787 lineShape
->GetFrom()->OnDrawContents(dc
);
1788 lineShape
->GetTo()->OnDraw(dc
);
1789 lineShape
->GetTo()->OnDrawContents(dc
);
1791 this->SetDisableLabel(true);
1792 dc
.SetLogicalFunction(OGLRBLF
);
1794 lpt
->m_xpos
= x
; lpt
->m_ypos
= y
;
1795 lpt
->m_point
->x
= x
; lpt
->m_point
->y
= y
;
1797 wxPen
*old_pen
= lineShape
->GetPen();
1798 wxBrush
*old_brush
= lineShape
->GetBrush();
1800 wxPen
dottedPen(wxColour(0, 0, 0), 1, wxDOT
);
1801 lineShape
->SetPen(& dottedPen
);
1802 lineShape
->SetBrush(wxTRANSPARENT_BRUSH
);
1804 lineShape
->GetEventHandler()->OnMoveLink(dc
, false);
1806 lineShape
->SetPen(old_pen
);
1807 lineShape
->SetBrush(old_brush
);
1810 if (lpt
->m_type
== CONTROL_POINT_ENDPOINT_FROM
|| lpt
->m_type
== CONTROL_POINT_ENDPOINT_TO
)
1812 m_canvas
->SetCursor(wxCursor(wxCURSOR_BULLSEYE
));
1813 lpt
->m_oldCursor
= wxSTANDARD_CURSOR
;
1817 void wxLineShape::OnSizingEndDragLeft(wxControlPoint
* pt
, double x
, double y
, int WXUNUSED(keys
), int WXUNUSED(attachment
))
1819 wxLineControlPoint
* lpt
= (wxLineControlPoint
*) pt
;
1821 wxClientDC
dc(GetCanvas());
1822 GetCanvas()->PrepareDC(dc
);
1824 this->SetDisableLabel(false);
1825 wxLineShape
*lineShape
= (wxLineShape
*)this;
1827 if (lpt
->m_type
== CONTROL_POINT_LINE
)
1829 m_canvas
->Snap(&x
, &y
);
1831 wxRealPoint pt
= wxRealPoint(x
, y
);
1833 // Move the control point back to where it was;
1834 // MoveControlPoint will move it to the new position
1835 // if it decides it wants. We only moved the position
1836 // during user feedback so we could redraw the line
1837 // as it changed shape.
1838 lpt
->m_xpos
= lpt
->m_originalPos
.x
; lpt
->m_ypos
= lpt
->m_originalPos
.y
;
1839 lpt
->m_point
->x
= lpt
->m_originalPos
.x
; lpt
->m_point
->y
= lpt
->m_originalPos
.y
;
1841 OnMoveMiddleControlPoint(dc
, lpt
, pt
);
1843 if (lpt
->m_type
== CONTROL_POINT_ENDPOINT_FROM
)
1845 if (lpt
->m_oldCursor
)
1846 m_canvas
->SetCursor(* lpt
->m_oldCursor
);
1850 // lpt->m_xpos = x; lpt->m_ypos = y;
1852 if (lineShape
->GetFrom())
1854 lineShape
->GetFrom()->MoveLineToNewAttachment(dc
, lineShape
, x
, y
);
1857 if (lpt
->m_type
== CONTROL_POINT_ENDPOINT_TO
)
1859 if (lpt
->m_oldCursor
)
1860 m_canvas
->SetCursor(* lpt
->m_oldCursor
);
1862 // lpt->m_xpos = x; lpt->m_ypos = y;
1864 if (lineShape
->GetTo())
1866 lineShape
->GetTo()->MoveLineToNewAttachment(dc
, lineShape
, x
, y
);
1873 for (i
= 0; i
< lineShape
->GetLineControlPoints()->GetCount(); i
++)
1874 if (((wxRealPoint
*)(lineShape
->GetLineControlPoints()->Item(i
)->GetData())) == lpt
->m_point
)
1877 // N.B. in OnMoveControlPoint, an event handler in Hardy could have deselected
1878 // the line and therefore deleted 'this'. -> GPF, intermittently.
1879 // So assume at this point that we've been blown away.
1881 lineShape
->OnMoveControlPoint(i
+1, x
, y
);
1885 // This is called only when a non-end control point is moved.
1886 bool wxLineShape::OnMoveMiddleControlPoint(wxDC
& dc
, wxLineControlPoint
* lpt
, const wxRealPoint
& pt
)
1888 lpt
->m_xpos
= pt
.x
; lpt
->m_ypos
= pt
.y
;
1889 lpt
->m_point
->x
= pt
.x
; lpt
->m_point
->y
= pt
.y
;
1891 GetEventHandler()->OnMoveLink(dc
);
1896 // Implement movement of endpoint to a new attachment
1897 // OBSOLETE: done by dragging with the left button.
1900 void wxLineControlPoint::OnDragRight(bool draw
, double x
, double y
, int keys
, int attachment
)
1902 if (m_type
== CONTROL_POINT_ENDPOINT_FROM
|| m_type
== CONTROL_POINT_ENDPOINT_TO
)
1904 m_xpos
= x
; m_ypos
= y
;
1908 void wxLineControlPoint::OnBeginDragRight(double x
, double y
, int keys
, int attachment
)
1910 wxClientDC
dc(GetCanvas());
1911 GetCanvas()->PrepareDC(dc
);
1913 wxLineShape
*lineShape
= (wxLineShape
*)m_shape
;
1914 if (m_type
== CONTROL_POINT_ENDPOINT_FROM
|| m_type
== CONTROL_POINT_ENDPOINT_TO
)
1917 lineShape
->GetEventHandler()->OnDraw(dc
);
1918 if (m_type
== CONTROL_POINT_ENDPOINT_FROM
)
1920 lineShape
->GetFrom()->GetEventHandler()->OnDraw(dc
);
1921 lineShape
->GetFrom()->GetEventHandler()->OnDrawContents(dc
);
1925 lineShape
->GetTo()->GetEventHandler()->OnDraw(dc
);
1926 lineShape
->GetTo()->GetEventHandler()->OnDrawContents(dc
);
1928 m_canvas
->SetCursor(wxCursor(wxCURSOR_BULLSEYE
));
1929 m_oldCursor
= wxSTANDARD_CURSOR
;
1933 void wxLineControlPoint::OnEndDragRight(double x
, double y
, int keys
, int attachment
)
1935 wxClientDC
dc(GetCanvas());
1936 GetCanvas()->PrepareDC(dc
);
1938 wxLineShape
*lineShape
= (wxLineShape
*)m_shape
;
1939 if (m_type
== CONTROL_POINT_ENDPOINT_FROM
)
1942 m_canvas
->SetCursor(m_oldCursor
);
1944 m_xpos
= x
; m_ypos
= y
;
1946 if (lineShape
->GetFrom())
1948 lineShape
->GetFrom()->EraseLinks(dc
);
1953 if (lineShape
->GetFrom()->HitTest(x
, y
, &new_attachment
, &distance
))
1954 lineShape
->SetAttachments(new_attachment
, lineShape
->GetAttachmentTo());
1956 lineShape
->GetFrom()->MoveLinks(dc
);
1959 if (m_type
== CONTROL_POINT_ENDPOINT_TO
)
1962 m_canvas
->SetCursor(m_oldCursor
);
1965 m_xpos
= x
; m_ypos
= y
;
1967 if (lineShape
->GetTo())
1969 lineShape
->GetTo()->EraseLinks(dc
);
1973 if (lineShape
->GetTo()->HitTest(x
, y
, &new_attachment
, &distance
))
1974 lineShape
->SetAttachments(lineShape
->GetAttachmentFrom(), new_attachment
);
1976 lineShape
->GetTo()->MoveLinks(dc
);
1980 for (i
= 0; i
< lineShape
->GetLineControlPoints()->GetCount(); i
++)
1981 if (((wxRealPoint
*)(lineShape
->GetLineControlPoints()->Item(i
)->GetData())) == m_point
)
1983 lineShape
->OnMoveControlPoint(i
+1, x
, y
);
1984 if (!m_canvas
->GetQuickEditMode()) m_canvas
->Redraw(dc
);
1989 * Get the point on the given line (x1, y1) (x2, y2)
1990 * distance 'length' along from the end,
1991 * returned values in x and y
1994 void GetPointOnLine(double x1
, double y1
, double x2
, double y2
,
1995 double length
, double *x
, double *y
)
1997 double l
= (double)sqrt((x2
- x1
)*(x2
- x1
) + (y2
- y1
)*(y2
- y1
));
2002 double i_bar
= (x2
- x1
)/l
;
2003 double j_bar
= (y2
- y1
)/l
;
2005 *x
= (- length
*i_bar
) + x2
;
2006 *y
= (- length
*j_bar
) + y2
;
2009 wxArrowHead
*wxLineShape::AddArrow(WXTYPE type
, int end
, double size
, double xOffset
,
2010 const wxString
& name
, wxPseudoMetaFile
*mf
, long arrowId
)
2012 wxArrowHead
*arrow
= new wxArrowHead(type
, end
, size
, xOffset
, name
, mf
, arrowId
);
2013 m_arcArrows
.Append(arrow
);
2018 * Add arrowhead at a particular position in the arrowhead list.
2020 bool wxLineShape::AddArrowOrdered(wxArrowHead
*arrow
, wxList
& referenceList
, int end
)
2022 wxNode
*refNode
= referenceList
.GetFirst();
2023 wxNode
*currNode
= m_arcArrows
.GetFirst();
2024 wxString
targetName(arrow
->GetName());
2025 if (!refNode
) return false;
2027 // First check whether we need to insert in front of list,
2028 // because this arrowhead is the first in the reference
2029 // list and should therefore be first in the current list.
2030 wxArrowHead
*refArrow
= (wxArrowHead
*)refNode
->GetData();
2031 if (refArrow
->GetName() == targetName
)
2033 m_arcArrows
.Insert(arrow
);
2037 wxArrowHead
*currArrow
= (wxArrowHead
*)currNode
->GetData();
2038 while (refNode
&& currNode
)
2040 refArrow
= (wxArrowHead
*)refNode
->GetData();
2042 // Matching: advance current arrow pointer
2043 if ((currArrow
->GetArrowEnd() == end
) &&
2044 (currArrow
->GetName() == refArrow
->GetName()))
2046 currNode
= currNode
->GetNext(); // Could be NULL now
2048 currArrow
= (wxArrowHead
*)currNode
->GetData();
2051 // Check if we're at the correct position in the
2053 if (targetName
== refArrow
->GetName())
2056 m_arcArrows
.Insert(currNode
, arrow
);
2058 m_arcArrows
.Append(arrow
);
2061 refNode
= refNode
->GetNext();
2063 m_arcArrows
.Append(arrow
);
2067 void wxLineShape::ClearArrowsAtPosition(int end
)
2069 wxNode
*node
= m_arcArrows
.GetFirst();
2072 wxArrowHead
*arrow
= (wxArrowHead
*)node
->GetData();
2073 wxNode
*next
= node
->GetNext();
2082 case ARROW_POSITION_START
:
2084 if (arrow
->GetArrowEnd() == ARROW_POSITION_START
)
2091 case ARROW_POSITION_END
:
2093 if (arrow
->GetArrowEnd() == ARROW_POSITION_END
)
2100 case ARROW_POSITION_MIDDLE
:
2102 if (arrow
->GetArrowEnd() == ARROW_POSITION_MIDDLE
)
2114 bool wxLineShape::ClearArrow(const wxString
& name
)
2116 wxNode
*node
= m_arcArrows
.GetFirst();
2119 wxArrowHead
*arrow
= (wxArrowHead
*)node
->GetData();
2120 if (arrow
->GetName() == name
)
2126 node
= node
->GetNext();
2132 * Finds an arrowhead at the given position (if -1, any position)
2136 wxArrowHead
*wxLineShape::FindArrowHead(int position
, const wxString
& name
)
2138 wxNode
*node
= m_arcArrows
.GetFirst();
2141 wxArrowHead
*arrow
= (wxArrowHead
*)node
->GetData();
2142 if (((position
== -1) || (position
== arrow
->GetArrowEnd())) &&
2143 (arrow
->GetName() == name
))
2145 node
= node
->GetNext();
2150 wxArrowHead
*wxLineShape::FindArrowHead(long arrowId
)
2152 wxNode
*node
= m_arcArrows
.GetFirst();
2155 wxArrowHead
*arrow
= (wxArrowHead
*)node
->GetData();
2156 if (arrowId
== arrow
->GetId())
2158 node
= node
->GetNext();
2164 * Deletes an arrowhead at the given position (if -1, any position)
2168 bool wxLineShape::DeleteArrowHead(int position
, const wxString
& name
)
2170 wxNode
*node
= m_arcArrows
.GetFirst();
2173 wxArrowHead
*arrow
= (wxArrowHead
*)node
->GetData();
2174 if (((position
== -1) || (position
== arrow
->GetArrowEnd())) &&
2175 (arrow
->GetName() == name
))
2181 node
= node
->GetNext();
2186 // Overloaded DeleteArrowHead: pass arrowhead id.
2187 bool wxLineShape::DeleteArrowHead(long id
)
2189 wxNode
*node
= m_arcArrows
.GetFirst();
2192 wxArrowHead
*arrow
= (wxArrowHead
*)node
->GetData();
2193 if (arrow
->GetId() == id
)
2199 node
= node
->GetNext();
2205 * Calculate the minimum width a line
2206 * occupies, for the purposes of drawing lines in tools.
2210 double wxLineShape::FindMinimumWidth()
2212 double minWidth
= 0.0;
2213 wxNode
*node
= m_arcArrows
.GetFirst();
2216 wxArrowHead
*arrowHead
= (wxArrowHead
*)node
->GetData();
2217 minWidth
+= arrowHead
->GetSize();
2218 if (node
->GetNext())
2219 minWidth
+= arrowHead
->GetSpacing();
2221 node
= node
->GetNext();
2223 // We have ABSOLUTE minimum now. So
2224 // scale it to give it reasonable aesthetics
2225 // when drawing with line.
2227 minWidth
= (double)(minWidth
* 1.4);
2231 SetEnds(0.0, 0.0, minWidth
, 0.0);
2237 // Find which position we're talking about at this (x, y).
2238 // Returns ARROW_POSITION_START, ARROW_POSITION_MIDDLE, ARROW_POSITION_END
2239 int wxLineShape::FindLinePosition(double x
, double y
)
2241 double startX
, startY
, endX
, endY
;
2242 GetEnds(&startX
, &startY
, &endX
, &endY
);
2244 // Find distances from centre, start and end. The smallest wins.
2245 double centreDistance
= (double)(sqrt((x
- m_xpos
)*(x
- m_xpos
) + (y
- m_ypos
)*(y
- m_ypos
)));
2246 double startDistance
= (double)(sqrt((x
- startX
)*(x
- startX
) + (y
- startY
)*(y
- startY
)));
2247 double endDistance
= (double)(sqrt((x
- endX
)*(x
- endX
) + (y
- endY
)*(y
- endY
)));
2249 if (centreDistance
< startDistance
&& centreDistance
< endDistance
)
2250 return ARROW_POSITION_MIDDLE
;
2251 else if (startDistance
< endDistance
)
2252 return ARROW_POSITION_START
;
2254 return ARROW_POSITION_END
;
2257 // Set alignment flags
2258 void wxLineShape::SetAlignmentOrientation(bool isEnd
, bool isHoriz
)
2262 if (isHoriz
&& ((m_alignmentEnd
& LINE_ALIGNMENT_HORIZ
) != LINE_ALIGNMENT_HORIZ
))
2263 m_alignmentEnd
|= LINE_ALIGNMENT_HORIZ
;
2264 else if (!isHoriz
&& ((m_alignmentEnd
& LINE_ALIGNMENT_HORIZ
) == LINE_ALIGNMENT_HORIZ
))
2265 m_alignmentEnd
-= LINE_ALIGNMENT_HORIZ
;
2269 if (isHoriz
&& ((m_alignmentStart
& LINE_ALIGNMENT_HORIZ
) != LINE_ALIGNMENT_HORIZ
))
2270 m_alignmentStart
|= LINE_ALIGNMENT_HORIZ
;
2271 else if (!isHoriz
&& ((m_alignmentStart
& LINE_ALIGNMENT_HORIZ
) == LINE_ALIGNMENT_HORIZ
))
2272 m_alignmentStart
-= LINE_ALIGNMENT_HORIZ
;
2276 void wxLineShape::SetAlignmentType(bool isEnd
, int alignType
)
2280 if (alignType
== LINE_ALIGNMENT_TO_NEXT_HANDLE
)
2282 if ((m_alignmentEnd
& LINE_ALIGNMENT_TO_NEXT_HANDLE
) != LINE_ALIGNMENT_TO_NEXT_HANDLE
)
2283 m_alignmentEnd
|= LINE_ALIGNMENT_TO_NEXT_HANDLE
;
2285 else if ((m_alignmentEnd
& LINE_ALIGNMENT_TO_NEXT_HANDLE
) == LINE_ALIGNMENT_TO_NEXT_HANDLE
)
2286 m_alignmentEnd
-= LINE_ALIGNMENT_TO_NEXT_HANDLE
;
2290 if (alignType
== LINE_ALIGNMENT_TO_NEXT_HANDLE
)
2292 if ((m_alignmentStart
& LINE_ALIGNMENT_TO_NEXT_HANDLE
) != LINE_ALIGNMENT_TO_NEXT_HANDLE
)
2293 m_alignmentStart
|= LINE_ALIGNMENT_TO_NEXT_HANDLE
;
2295 else if ((m_alignmentStart
& LINE_ALIGNMENT_TO_NEXT_HANDLE
) == LINE_ALIGNMENT_TO_NEXT_HANDLE
)
2296 m_alignmentStart
-= LINE_ALIGNMENT_TO_NEXT_HANDLE
;
2300 bool wxLineShape::GetAlignmentOrientation(bool isEnd
)
2303 return ((m_alignmentEnd
& LINE_ALIGNMENT_HORIZ
) == LINE_ALIGNMENT_HORIZ
);
2305 return ((m_alignmentStart
& LINE_ALIGNMENT_HORIZ
) == LINE_ALIGNMENT_HORIZ
);
2308 int wxLineShape::GetAlignmentType(bool isEnd
)
2311 return (m_alignmentEnd
& LINE_ALIGNMENT_TO_NEXT_HANDLE
);
2313 return (m_alignmentStart
& LINE_ALIGNMENT_TO_NEXT_HANDLE
);
2316 wxRealPoint
*wxLineShape::GetNextControlPoint(wxShape
*nodeObject
)
2318 int n
= m_lineControlPoints
->GetCount();
2320 if (m_to
== nodeObject
)
2322 // Must be END of line, so we want (n - 1)th control point.
2323 // But indexing ends at n-1, so subtract 2.
2327 wxNode
*node
= m_lineControlPoints
->Item(nn
);
2330 return (wxRealPoint
*)node
->GetData();
2341 IMPLEMENT_DYNAMIC_CLASS(wxArrowHead
, wxObject
)
2343 wxArrowHead::wxArrowHead(WXTYPE type
, int end
, double size
, double dist
, const wxString
& name
,
2344 wxPseudoMetaFile
*mf
, long arrowId
)
2346 m_arrowType
= type
; m_arrowEnd
= end
; m_arrowSize
= size
;
2358 wxArrowHead::wxArrowHead(wxArrowHead
& toCopy
)
2360 m_arrowType
= toCopy
.m_arrowType
; m_arrowEnd
= toCopy
.GetArrowEnd();
2361 m_arrowSize
= toCopy
.m_arrowSize
;
2362 m_xOffset
= toCopy
.m_xOffset
;
2363 m_yOffset
= toCopy
.m_yOffset
;
2364 m_spacing
= toCopy
.m_spacing
;
2365 m_arrowName
= toCopy
.m_arrowName
;
2366 if (toCopy
.m_metaFile
)
2367 m_metaFile
= new wxPseudoMetaFile(*(toCopy
.m_metaFile
));
2373 wxArrowHead::~wxArrowHead()
2375 if (m_metaFile
) delete m_metaFile
;
2378 void wxArrowHead::SetSize(double size
)
2381 if ((m_arrowType
== ARROW_METAFILE
) && m_metaFile
)
2383 double oldWidth
= m_metaFile
->m_width
;
2384 if (oldWidth
== 0.0)
2387 double scale
= (double)(size
/oldWidth
);
2389 m_metaFile
->Scale(scale
, scale
);
2393 // Can override this to create a different class of label shape
2394 wxLabelShape
* wxLineShape::OnCreateLabelShape(wxLineShape
*parent
, wxShapeRegion
*region
, double w
, double h
)
2396 return new wxLabelShape(parent
, region
, w
, h
);
2404 IMPLEMENT_DYNAMIC_CLASS(wxLabelShape
, wxRectangleShape
)
2406 wxLabelShape::wxLabelShape(wxLineShape
*parent
, wxShapeRegion
*region
, double w
, double h
):wxRectangleShape(w
, h
)
2408 m_lineShape
= parent
;
2409 m_shapeRegion
= region
;
2410 SetPen(wxThePenList
->FindOrCreatePen(wxColour(0, 0, 0), 1, wxDOT
));
2413 wxLabelShape::~wxLabelShape()
2417 void wxLabelShape::OnDraw(wxDC
& dc
)
2419 if (m_lineShape
&& !m_lineShape
->GetDrawHandles())
2422 double x1
= (double)(m_xpos
- m_width
/2.0);
2423 double y1
= (double)(m_ypos
- m_height
/2.0);
2427 if (m_pen
->GetWidth() == 0)
2428 dc
.SetPen(* g_oglTransparentPen
);
2432 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
2434 if (m_cornerRadius
> 0.0)
2435 dc
.DrawRoundedRectangle(WXROUND(x1
), WXROUND(y1
), WXROUND(m_width
), WXROUND(m_height
), m_cornerRadius
);
2437 dc
.DrawRectangle(WXROUND(x1
), WXROUND(y1
), WXROUND(m_width
), WXROUND(m_height
));
2440 void wxLabelShape::OnDrawContents(wxDC
& WXUNUSED(dc
))
2444 void wxLabelShape::OnDragLeft(bool draw
, double x
, double y
, int keys
, int attachment
)
2446 wxRectangleShape::OnDragLeft(draw
, x
, y
, keys
, attachment
);
2449 void wxLabelShape::OnBeginDragLeft(double x
, double y
, int keys
, int attachment
)
2451 wxRectangleShape::OnBeginDragLeft(x
, y
, keys
, attachment
);
2454 void wxLabelShape::OnEndDragLeft(double x
, double y
, int keys
, int attachment
)
2456 wxRectangleShape::OnEndDragLeft(x
, y
, keys
, attachment
);
2459 bool wxLabelShape::OnMovePre(wxDC
& dc
, double x
, double y
, double old_x
, double old_y
, bool display
)
2461 return m_lineShape
->OnLabelMovePre(dc
, this, x
, y
, old_x
, old_y
, display
);
2464 bool wxLineShape::OnLabelMovePre(wxDC
& dc
, wxLabelShape
* labelShape
, double x
, double y
, double WXUNUSED(old_x
), double WXUNUSED(old_y
), bool WXUNUSED(display
))
2466 labelShape
->m_shapeRegion
->SetSize(labelShape
->GetWidth(), labelShape
->GetHeight());
2468 // Find position in line's region list
2470 wxNode
*node
= GetRegions().GetFirst();
2473 if (labelShape
->m_shapeRegion
== (wxShapeRegion
*)node
->GetData())
2477 node
= node
->GetNext();
2482 GetLabelPosition(i
, &xx
, &yy
);
2483 // Set the region's offset, relative to the default position for
2485 labelShape
->m_shapeRegion
->SetPosition((double)(x
- xx
), (double)(y
- yy
));
2487 labelShape
->SetX(x
);
2488 labelShape
->SetY(y
);
2490 // Need to reformat to fit region.
2491 if (labelShape
->m_shapeRegion
->GetText())
2494 wxString
s(labelShape
->m_shapeRegion
->GetText());
2495 labelShape
->FormatText(dc
, s
, i
);
2496 DrawRegion(dc
, labelShape
->m_shapeRegion
, xx
, yy
);
2501 // Divert left and right clicks to line object
2502 void wxLabelShape::OnLeftClick(double x
, double y
, int keys
, int attachment
)
2504 m_lineShape
->GetEventHandler()->OnLeftClick(x
, y
, keys
, attachment
);
2507 void wxLabelShape::OnRightClick(double x
, double y
, int keys
, int attachment
)
2509 m_lineShape
->GetEventHandler()->OnRightClick(x
, y
, keys
, attachment
);