More wxMotif work, OGL enhancements, USE_ macro corrections, object.cpp delete

operator correction for VC++ 6


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@780 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Julian Smart
1998-09-28 15:42:54 +00:00
parent 23e09f1115
commit f97c985452
44 changed files with 3439 additions and 614 deletions

View File

@@ -127,6 +127,12 @@ void wxShapeEvtHandler::OnDrawContents(wxDC& dc)
m_previousHandler->OnDrawContents(dc);
}
void wxShapeEvtHandler::OnDrawBranches(wxDC& dc, bool erase)
{
if (m_previousHandler)
m_previousHandler->OnDrawBranches(dc, erase);
}
void wxShapeEvtHandler::OnSize(double x, double y)
{
if (m_previousHandler)
@@ -276,7 +282,7 @@ wxShape::wxShape(wxShapeCanvas *can)
m_visible = FALSE;
m_clientData = NULL;
m_selected = FALSE;
m_attachmentMode = FALSE;
m_attachmentMode = ATTACHMENT_MODE_NONE;
m_spaceAttachments = TRUE;
m_disableLabel = FALSE;
m_fixedWidth = FALSE;
@@ -297,6 +303,10 @@ wxShape::wxShape(wxShapeCanvas *can)
m_maintainAspectRatio = FALSE;
m_highlighted = FALSE;
m_rotation = 0.0;
m_branchNeckLength = 10;
m_branchStemLength = 10;
m_branchSpacing = 10;
m_branchStyle = BRANCHING_ATTACHMENT_NORMAL;
// Set up a default region. Much of the above will be put into
// the region eventually (the duplication is for compatibility)
@@ -541,7 +551,6 @@ bool wxShape::HitTest(double x, double y, int *attachment, double *distance)
int nearest_attachment = 0;
// If within the bounding box, check the attachment points
// within the object.
@@ -550,10 +559,13 @@ bool wxShape::HitTest(double x, double y, int *attachment, double *distance)
int n = GetNumberOfAttachments();
double nearest = 999999.0;
// GetAttachmentPosition[Edge] takes a logical attachment position,
// i.e. if it's rotated through 90%, position 0 is East-facing.
for (int i = 0; i < n; i++)
{
double xp, yp;
if (GetAttachmentPosition(i, &xp, &yp))
if (GetAttachmentPositionEdge(i, &xp, &yp))
{
double l = (double)sqrt(((xp - x) * (xp - x)) +
((yp - y) * (yp - y)));
@@ -1038,7 +1050,8 @@ void wxShape::DrawLinks(wxDC& dc, int attachment, bool recurse)
// This is the default, rectangular implementation.
bool wxShape::AttachmentSortTest(int attachmentPoint, const wxRealPoint& pt1, const wxRealPoint& pt2)
{
switch (attachmentPoint)
int physicalAttachment = LogicalToPhysicalAttachment(attachmentPoint);
switch (physicalAttachment)
{
case 0:
case 2:
@@ -1060,7 +1073,7 @@ bool wxShape::AttachmentSortTest(int attachmentPoint, const wxRealPoint& pt1, co
bool wxShape::MoveLineToNewAttachment(wxDC& dc, wxLineShape *to_move,
double x, double y)
{
if (!GetAttachmentMode())
if (GetAttachmentMode() == ATTACHMENT_MODE_NONE)
return FALSE;
int newAttachment, oldAttachment;
@@ -1502,6 +1515,7 @@ void wxShape::Draw(wxDC& dc)
GetEventHandler()->OnDraw(dc);
GetEventHandler()->OnDrawContents(dc);
GetEventHandler()->OnDrawControlPoints(dc);
GetEventHandler()->OnDrawBranches(dc);
}
}
@@ -1535,6 +1549,7 @@ void wxShape::Erase(wxDC& dc)
{
GetEventHandler()->OnErase(dc);
GetEventHandler()->OnEraseControlPoints(dc);
GetEventHandler()->OnDrawBranches(dc, TRUE);
}
void wxShape::EraseContents(wxDC& dc)
@@ -1758,6 +1773,14 @@ void wxShape::WriteAttributes(wxExpr *clause)
if (m_rotation != 0.0)
clause->AddAttributeValue("rotation", m_rotation);
if (!this->IsKindOf(CLASSINFO(wxLineShape)))
{
clause->AddAttributeValue("neck_length", (long) m_branchNeckLength);
clause->AddAttributeValue("stem_length", (long) m_branchStemLength);
clause->AddAttributeValue("branch_spacing", (long) m_branchSpacing);
clause->AddAttributeValue("branch_style", (long) m_branchStyle);
}
// Write user-defined attachment points, if any
if (m_attachmentPoints.Number() > 0)
{
@@ -1912,7 +1935,7 @@ void wxShape::ReadAttributes(wxExpr *clause)
int pen_width = 1;
int pen_style = wxSOLID;
int brush_style = wxSOLID;
m_attachmentMode = FALSE;
m_attachmentMode = ATTACHMENT_MODE_NONE;
clause->GetAttributeValue("pen_colour", pen_string);
clause->GetAttributeValue("text_colour", m_textColourName);
@@ -1928,7 +1951,7 @@ void wxShape::ReadAttributes(wxExpr *clause)
int iVal = (int) m_attachmentMode;
clause->GetAttributeValue("use_attachments", iVal);
m_attachmentMode = (iVal != 0);
m_attachmentMode = iVal;
clause->GetAttributeValue("sensitivity", m_sensitivity);
@@ -1947,6 +1970,20 @@ void wxShape::ReadAttributes(wxExpr *clause)
clause->GetAttributeValue("format_mode", m_formatMode);
clause->GetAttributeValue("shadow_mode", m_shadowMode);
iVal = m_branchNeckLength;
clause->GetAttributeValue("neck_length", iVal);
m_branchNeckLength = iVal;
iVal = m_branchStemLength;
clause->GetAttributeValue("stem_length", iVal);
m_branchStemLength = iVal;
iVal = m_branchSpacing;
clause->GetAttributeValue("branch_spacing", iVal);
m_branchSpacing = iVal;
clause->GetAttributeValue("branch_style", m_branchStyle);
iVal = (int) m_centreResize;
clause->GetAttributeValue("centre_resize", iVal);
m_centreResize = (iVal != 0);
@@ -2251,6 +2288,10 @@ void wxShape::Copy(wxShape& copy)
copy.m_shadowOffsetY = m_shadowOffsetY;
copy.m_shadowBrush = m_shadowBrush;
copy.m_branchNeckLength = m_branchNeckLength;
copy.m_branchStemLength = m_branchStemLength;
copy.m_branchSpacing = m_branchSpacing;
// Copy text regions
copy.ClearRegions();
wxNode *node = m_regions.First();
@@ -2631,12 +2672,20 @@ bool wxShape::AttachmentIsValid(int attachment) const
bool wxShape::GetAttachmentPosition(int attachment, double *x, double *y,
int nth, int no_arcs, wxLineShape *line)
{
if (!m_attachmentMode)
if (m_attachmentMode == ATTACHMENT_MODE_NONE)
{
*x = m_xpos; *y = m_ypos;
return TRUE;
}
else
else if (m_attachmentMode == ATTACHMENT_MODE_BRANCHING)
{
wxRealPoint pt, stemPt;
GetBranchingAttachmentPoint(attachment, nth, pt, stemPt);
*x = pt.x;
*y = pt.y;
return TRUE;
}
else if (m_attachmentMode == ATTACHMENT_MODE_EDGE)
{
if (m_attachmentPoints.Number() > 0)
{
@@ -2667,8 +2716,10 @@ bool wxShape::GetAttachmentPosition(int attachment, double *x, double *y,
bool isEnd = (line && line->IsEnd(this));
int physicalAttachment = LogicalToPhysicalAttachment(attachment);
// Simplified code
switch (attachment)
switch (physicalAttachment)
{
case 0:
{
@@ -2704,7 +2755,7 @@ bool wxShape::GetAttachmentPosition(int attachment, double *x, double *y,
}
default:
{
return wxShape::GetAttachmentPosition(attachment, x, y, nth, no_arcs, line);
return FALSE;
break;
}
}
@@ -2855,3 +2906,365 @@ int wxShape::GetLinePosition(wxLineShape* line)
return 0;
}
//
// |________|
// | <- root
// | <- neck
// shoulder1 ->---------<- shoulder2
// | | | | |
// <- branching attachment point N-1
// This function gets information about where branching connections go.
// Returns FALSE if there are no lines at this attachment.
bool wxShape::GetBranchingAttachmentInfo(int attachment, wxRealPoint& root, wxRealPoint& neck,
wxRealPoint& shoulder1, wxRealPoint& shoulder2)
{
int physicalAttachment = LogicalToPhysicalAttachment(attachment);
// Number of lines at this attachment.
int lineCount = GetAttachmentLineCount(attachment);
if (lineCount == 0)
return FALSE;
int totalBranchLength = m_branchSpacing * (lineCount - 1);
root = GetBranchingAttachmentRoot(attachment);
// Assume that we have attachment points 0 to 3: top, right, bottom, left.
switch (physicalAttachment)
{
case 0:
{
neck.x = GetX();
neck.y = root.y - m_branchNeckLength;
shoulder1.x = root.x - (totalBranchLength/2.0) ;
shoulder2.x = root.x + (totalBranchLength/2.0) ;
shoulder1.y = neck.y;
shoulder2.y = neck.y;
break;
}
case 1:
{
neck.x = root.x + m_branchNeckLength;
neck.y = root.y;
shoulder1.x = neck.x ;
shoulder2.x = neck.x ;
shoulder1.y = neck.y - (totalBranchLength/2.0) ;
shoulder2.y = neck.y + (totalBranchLength/2.0) ;
break;
}
case 2:
{
neck.x = GetX();
neck.y = root.y + m_branchNeckLength;
shoulder1.x = root.x - (totalBranchLength/2.0) ;
shoulder2.x = root.x + (totalBranchLength/2.0) ;
shoulder1.y = neck.y;
shoulder2.y = neck.y;
break;
}
case 3:
{
neck.x = root.x - m_branchNeckLength;
neck.y = root.y ;
shoulder1.x = neck.x ;
shoulder2.x = neck.x ;
shoulder1.y = neck.y - (totalBranchLength/2.0) ;
shoulder2.y = neck.y + (totalBranchLength/2.0) ;
break;
}
default:
{
wxFAIL_MSG( "Unrecognised attachment point in GetBranchingAttachmentInfo." );
break;
}
}
return TRUE;
}
// n is the number of the adjoining line, from 0 to N-1 where N is the number of lines
// at this attachment point.
// Get the attachment point where the arc joins the stem, and also the point where the
// the stem meets the shoulder.
bool wxShape::GetBranchingAttachmentPoint(int attachment, int n, wxRealPoint& pt, wxRealPoint& stemPt)
{
int physicalAttachment = LogicalToPhysicalAttachment(attachment);
wxRealPoint root, neck, shoulder1, shoulder2;
GetBranchingAttachmentInfo(attachment, root, neck, shoulder1, shoulder2);
// Assume that we have attachment points 0 to 3: top, right, bottom, left.
switch (physicalAttachment)
{
case 0:
{
pt.y = neck.y - m_branchStemLength;
pt.x = shoulder1.x + n*m_branchSpacing;
stemPt.x = pt.x;
stemPt.y = neck.y;
break;
}
case 2:
{
pt.y = neck.y + m_branchStemLength;
pt.x = shoulder1.x + n*m_branchSpacing;
stemPt.x = pt.x;
stemPt.y = neck.y;
break;
}
case 1:
{
pt.x = neck.x + m_branchStemLength;
pt.y = shoulder1.y + n*m_branchSpacing;
stemPt.x = neck.x;
stemPt.y = pt.y;
break;
}
case 3:
{
pt.x = neck.x - m_branchStemLength;
pt.y = shoulder1.y + n*m_branchSpacing;
stemPt.x = neck.x;
stemPt.y = pt.y;
break;
}
default:
{
wxFAIL_MSG( "Unrecognised attachment point in GetBranchingAttachmentPoint." );
break;
}
}
return TRUE;
}
// Get the number of lines at this attachment position.
int wxShape::GetAttachmentLineCount(int attachment) const
{
int count = 0;
wxNode* node = m_lines.First();
while (node)
{
wxLineShape* lineShape = (wxLineShape*) node->Data();
if ((lineShape->GetFrom() == this) && (lineShape->GetAttachmentFrom() == attachment))
count ++;
else if ((lineShape->GetTo() == this) && (lineShape->GetAttachmentTo() == attachment))
count ++;
node = node->Next();
}
return count;
}
// This function gets the root point at the given attachment.
wxRealPoint wxShape::GetBranchingAttachmentRoot(int attachment)
{
int physicalAttachment = LogicalToPhysicalAttachment(attachment);
wxRealPoint root;
double width, height;
GetBoundingBoxMax(& width, & height);
// Assume that we have attachment points 0 to 3: top, right, bottom, left.
switch (physicalAttachment)
{
case 0:
{
root.x = GetX() ;
root.y = GetY() - height/2.0;
break;
}
case 1:
{
root.x = GetX() + width/2.0;
root.y = GetY() ;
break;
}
case 2:
{
root.x = GetX() ;
root.y = GetY() + height/2.0;
break;
}
case 3:
{
root.x = GetX() - width/2.0;
root.y = GetY() ;
break;
}
default:
{
wxFAIL_MSG( "Unrecognised attachment point in GetBranchingAttachmentRoot." );
break;
}
}
return root;
}
// Draw or erase the branches (not the actual arcs though)
void wxShape::OnDrawBranches(wxDC& dc, int attachment, bool erase)
{
int count = GetAttachmentLineCount(attachment);
if (count == 0)
return;
wxRealPoint root, neck, shoulder1, shoulder2;
GetBranchingAttachmentInfo(attachment, root, neck, shoulder1, shoulder2);
if (erase)
{
dc.SetPen(*wxWHITE_PEN);
dc.SetBrush(*wxWHITE_BRUSH);
}
else
{
dc.SetPen(*wxBLACK_PEN);
dc.SetBrush(*wxBLACK_BRUSH);
}
// Draw neck
dc.DrawLine((long) root.x, (long) root.y, (long) neck.x, (long) neck.y);
if (count > 1)
{
// Draw shoulder-to-shoulder line
dc.DrawLine((long) shoulder1.x, (long) shoulder1.y, (long) shoulder2.x, (long) shoulder2.y);
}
// Draw all the little branches
int i;
for (i = 0; i < count; i++)
{
wxRealPoint pt, stemPt;
GetBranchingAttachmentPoint(attachment, i, pt, stemPt);
dc.DrawLine((long) stemPt.x, (long) stemPt.y, (long) pt.x, (long) pt.y);
if (GetBranchStyle() & BRANCHING_ATTACHMENT_BLOB)
{
long blobSize=6;
// dc.DrawEllipse((long) (stemPt.x + 0.5 - (blobSize/2.0)), (long) (stemPt.y + 0.5 - (blobSize/2.0)), blobSize, blobSize);
dc.DrawEllipse((long) (stemPt.x - (blobSize/2.0)), (long) (stemPt.y - (blobSize/2.0)), blobSize, blobSize);
}
}
}
// Draw or erase the branches (not the actual arcs though)
void wxShape::OnDrawBranches(wxDC& dc, bool erase)
{
if (m_attachmentMode != ATTACHMENT_MODE_BRANCHING)
return;
int count = GetNumberOfAttachments();
int i;
for (i = 0; i < count; i++)
OnDrawBranches(dc, i, erase);
}
// Only get the attachment position at the _edge_ of the shape, ignoring
// branching mode. This is used e.g. to indicate the edge of interest, not the point
// on the attachment branch.
bool wxShape::GetAttachmentPositionEdge(int attachment, double *x, double *y,
int nth, int no_arcs, wxLineShape *line)
{
int oldMode = m_attachmentMode;
// Calculate as if to edge, not branch
if (m_attachmentMode == ATTACHMENT_MODE_BRANCHING)
m_attachmentMode = ATTACHMENT_MODE_EDGE;
bool success = GetAttachmentPosition(attachment, x, y, nth, no_arcs, line);
m_attachmentMode = oldMode;
return success;
}
// Rotate the standard attachment point from physical (0 is always North)
// to logical (0 -> 1 if rotated by 90 degrees)
int wxShape::PhysicalToLogicalAttachment(int physicalAttachment) const
{
const double pi = 3.1415926535897932384626433832795 ;
int i;
if (oglRoughlyEqual(GetRotation(), 0.0))
{
i = physicalAttachment;
}
else if (oglRoughlyEqual(GetRotation(), (pi/2.0)))
{
i = physicalAttachment - 1;
}
else if (oglRoughlyEqual(GetRotation(), pi))
{
i = physicalAttachment - 2;
}
else if (oglRoughlyEqual(GetRotation(), (3.0*pi/2.0)))
{
i = physicalAttachment - 3;
}
else
// Can't handle -- assume the same.
return physicalAttachment;
if (i < 0)
i += 4;
return i;
}
// Rotate the standard attachment point from logical
// to physical (0 is always North)
int wxShape::LogicalToPhysicalAttachment(int logicalAttachment) const
{
const double pi = 3.1415926535897932384626433832795 ;
int i;
if (oglRoughlyEqual(GetRotation(), 0.0))
{
i = logicalAttachment;
}
else if (oglRoughlyEqual(GetRotation(), (pi/2.0)))
{
i = logicalAttachment + 1;
}
else if (oglRoughlyEqual(GetRotation(), pi))
{
i = logicalAttachment + 2;
}
else if (oglRoughlyEqual(GetRotation(), (3.0*pi/2.0)))
{
i = logicalAttachment + 3;
}
else
// Can't handle -- assume the same.
return logicalAttachment;
if (i > 3)
i -= 4;
return i;
}
void wxShape::Rotate(double WXUNUSED(x), double WXUNUSED(y), double theta)
{
const double pi = 3.1415926535897932384626433832795 ;
m_rotation = theta;
if (m_rotation < 0.0)
{
m_rotation += 2*pi;
}
else if (m_rotation > 2*pi)
{
m_rotation -= 2*pi;
}
}

View File

@@ -94,6 +94,15 @@
#define OP_ALL (OP_CLICK_LEFT | OP_CLICK_RIGHT | OP_DRAG_LEFT | OP_DRAG_RIGHT)
// Attachment modes
#define ATTACHMENT_MODE_NONE 0
#define ATTACHMENT_MODE_EDGE 1
#define ATTACHMENT_MODE_BRANCHING 2
// Sub-modes for branching attachment mode
#define BRANCHING_ATTACHMENT_NORMAL 1
#define BRANCHING_ATTACHMENT_BLOB 2
class wxShapeTextLine;
class wxShapeCanvas;
class wxLineShape;
@@ -127,6 +136,7 @@ class wxShapeEvtHandler: public wxObject
virtual void OnDelete();
virtual void OnDraw(wxDC& dc);
virtual void OnDrawContents(wxDC& dc);
virtual void OnDrawBranches(wxDC& dc, bool erase = FALSE);
virtual void OnMoveLinks(wxDC& dc);
virtual void OnErase(wxDC& dc);
virtual void OnEraseContents(wxDC& dc);
@@ -274,8 +284,8 @@ class wxShape: public wxShapeEvtHandler
inline wxList& GetLines() const { return (wxList&) m_lines; }
inline void SetDisableLabel(bool flag) { m_disableLabel = flag; }
inline bool GetDisableLabel() const { return m_disableLabel; }
inline void SetAttachmentMode(bool flag) { m_attachmentMode = flag; }
inline bool GetAttachmentMode() const { return m_attachmentMode; }
inline void SetAttachmentMode(int mode) { m_attachmentMode = mode; }
inline int GetAttachmentMode() const { return m_attachmentMode; }
inline void SetId(long i) { m_id = i; }
inline long GetId() const { return m_id; }
@@ -382,6 +392,12 @@ class wxShape: public wxShapeEvtHandler
virtual int GetNumberOfAttachments() const;
virtual bool AttachmentIsValid(int attachment) const;
// Only get the attachment position at the _edge_ of the shape, ignoring
// branching mode. This is used e.g. to indicate the edge of interest, not the point
// on the attachment branch.
virtual bool GetAttachmentPositionEdge(int attachment, double *x, double *y,
int nth = 0, int no_arcs = 1, wxLineShape *line = NULL);
// Assuming the attachment lies along a vertical or horizontal line,
// calculate the position on that point.
virtual wxRealPoint CalcSimpleAttachment(const wxRealPoint& pt1, const wxRealPoint& pt2,
@@ -408,6 +424,59 @@ class wxShape: public wxShapeEvtHandler
// Can override this to prevent or intercept line reordering.
virtual void OnChangeAttachment(int attachment, wxLineShape* line, wxList& ordering);
//// New banching attachment code, 24/9/98
//
// |________|
// | <- root
// | <- neck
// shoulder1 ->---------<- shoulder2
// | | | | |<- stem
// <- branching attachment point N-1
// This function gets the root point at the given attachment.
virtual wxRealPoint GetBranchingAttachmentRoot(int attachment);
// This function gets information about where branching connections go (calls GetBranchingAttachmentRoot)
virtual bool GetBranchingAttachmentInfo(int attachment, wxRealPoint& root, wxRealPoint& neck,
wxRealPoint& shoulder1, wxRealPoint& shoulder2);
// n is the number of the adjoining line, from 0 to N-1 where N is the number of lines
// at this attachment point.
// attachmentPoint is where the arc meets the stem, and stemPoint is where the stem meets the
// shoulder.
virtual bool GetBranchingAttachmentPoint(int attachment, int n, wxRealPoint& attachmentPoint,
wxRealPoint& stemPoint);
// Get the number of lines at this attachment position.
virtual int GetAttachmentLineCount(int attachment) const;
// Draw the branches (not the actual arcs though)
virtual void OnDrawBranches(wxDC& dc, int attachment, bool erase = FALSE);
virtual void OnDrawBranches(wxDC& dc, bool erase = FALSE);
// Branching attachment settings
inline void SetBranchNeckLength(int len) { m_branchNeckLength = len; }
inline int GetBranchNeckLength() const { return m_branchNeckLength; }
inline void SetBranchStemLength(int len) { m_branchStemLength = len; }
inline int GetBranchStemLength() const { return m_branchStemLength; }
inline void SetBranchSpacing(int len) { m_branchSpacing = len; }
inline int GetBranchSpacing() const { return m_branchSpacing; }
// Further detail on branching style, e.g. blobs on interconnections
inline void SetBranchStyle(long style) { m_branchStyle = style; }
inline long GetBranchStyle() const { return m_branchStyle; }
// Rotate the standard attachment point from physical (0 is always North)
// to logical (0 -> 1 if rotated by 90 degrees)
virtual int PhysicalToLogicalAttachment(int physicalAttachment) const;
// Rotate the standard attachment point from logical
// to physical (0 is always North)
virtual int LogicalToPhysicalAttachment(int logicalAttachment) const;
// This is really to distinguish between lines and other images.
// For lines, want to pass drag to canvas, since lines tend to prevent
// dragging on a canvas (they get in the way.)
@@ -426,11 +495,8 @@ class wxShape: public wxShapeEvtHandler
// handler data if any. Calls the virtual Copy function.
void CopyWithHandler(wxShape& copy);
// Rotate about the given axis by the given amount in radians
// (does nothing for most objects)
// But even non-rotating objects should record their notional
// rotation in case it's important (e.g. in dog-leg code).
virtual inline void Rotate(double WXUNUSED(x), double WXUNUSED(y), double theta) { m_rotation = theta; }
// Rotate about the given axis by the given amount in radians.
virtual void Rotate(double x, double y, double theta);
virtual inline double GetRotation() const { return m_rotation; }
void ClearAttachments();
@@ -468,7 +534,8 @@ class wxShape: public wxShapeEvtHandler
double m_rotation;
int m_sensitivity;
bool m_draggable;
bool m_attachmentMode; // TRUE if using attachments, FALSE otherwise
int m_attachmentMode; // 0 for no attachments, 1 if using normal attachments,
// 2 for branching attachments
bool m_spaceAttachments; // TRUE if lines at one side should be spaced
bool m_fixedWidth;
bool m_fixedHeight;
@@ -485,6 +552,10 @@ class wxShape: public wxShapeEvtHandler
int m_textMarginY;
wxString m_regionName;
bool m_maintainAspectRatio;
int m_branchNeckLength;
int m_branchStemLength;
int m_branchSpacing;
long m_branchStyle;
};
class wxPolygonShape: public wxShape

View File

@@ -308,7 +308,7 @@ bool wxPolygonShape::HitTest(double x, double y, int *attachment, double *distan
for (i = 0; i < n; i++)
{
double xp, yp;
if (GetAttachmentPosition(i, &xp, &yp))
if (GetAttachmentPositionEdge(i, &xp, &yp))
{
double l = (double)sqrt(((xp - x) * (xp - x)) +
((yp - y) * (yp - y)));
@@ -439,7 +439,7 @@ bool wxPolygonShape::GetPerimeterPoint(double x1, double y1,
// and we would want to connect to a point on that vertical --
// oglFindEndForPolyline can't cope with this (the arrow
// gets drawn to the wrong place).
if ((!m_attachmentMode) && (x1 == x2))
if ((m_attachmentMode == ATTACHMENT_MODE_NONE) && (x1 == x2))
{
// Look for the point we'd be connecting to. This is
// a heuristic...
@@ -785,7 +785,7 @@ int wxPolygonShape::GetNumberOfAttachments() const
bool wxPolygonShape::GetAttachmentPosition(int attachment, double *x, double *y,
int nth, int no_arcs, wxLineShape *line)
{
if (m_attachmentMode && m_points && attachment < m_points->Number())
if ((m_attachmentMode == ATTACHMENT_MODE_EDGE) && m_points && attachment < m_points->Number())
{
wxRealPoint *point = (wxRealPoint *)m_points->Nth(attachment)->Data();
*x = point->x + m_xpos;
@@ -989,61 +989,7 @@ int wxRectangleShape::GetNumberOfAttachments() const
bool wxRectangleShape::GetAttachmentPosition(int attachment, double *x, double *y,
int nth, int no_arcs, wxLineShape *line)
{
if (m_attachmentMode)
{
double top = (double)(m_ypos + m_height/2.0);
double bottom = (double)(m_ypos - m_height/2.0);
double left = (double)(m_xpos - m_width/2.0);
double right = (double)(m_xpos + m_width/2.0);
bool isEnd = (line && line->IsEnd(this));
// Simplified code
switch (attachment)
{
case 0:
{
wxRealPoint pt = CalcSimpleAttachment(wxRealPoint(left, bottom), wxRealPoint(right, bottom),
nth, no_arcs, line);
*x = pt.x; *y = pt.y;
break;
}
case 1:
{
wxRealPoint pt = CalcSimpleAttachment(wxRealPoint(right, bottom), wxRealPoint(right, top),
nth, no_arcs, line);
*x = pt.x; *y = pt.y;
break;
}
case 2:
{
wxRealPoint pt = CalcSimpleAttachment(wxRealPoint(left, top), wxRealPoint(right, top),
nth, no_arcs, line);
*x = pt.x; *y = pt.y;
break;
}
case 3:
{
wxRealPoint pt = CalcSimpleAttachment(wxRealPoint(left, bottom), wxRealPoint(left, top),
nth, no_arcs, line);
*x = pt.x; *y = pt.y;
break;
}
default:
{
return wxShape::GetAttachmentPosition(attachment, x, y, nth, no_arcs, line);
break;
}
}
return TRUE;
}
else
{ *x = m_xpos; *y = m_ypos; return TRUE; }
return wxShape::GetAttachmentPosition(attachment, x, y, nth, no_arcs, line);
}
// Text object (no box)
@@ -1179,13 +1125,19 @@ int wxEllipseShape::GetNumberOfAttachments() const
bool wxEllipseShape::GetAttachmentPosition(int attachment, double *x, double *y,
int nth, int no_arcs, wxLineShape *line)
{
if (m_attachmentMode)
if (m_attachmentMode == ATTACHMENT_MODE_BRANCHING)
return wxShape::GetAttachmentPosition(attachment, x, y, nth, no_arcs, line);
if (m_attachmentMode != ATTACHMENT_MODE_NONE)
{
double top = (double)(m_ypos + m_height/2.0);
double bottom = (double)(m_ypos - m_height/2.0);
double left = (double)(m_xpos - m_width/2.0);
double right = (double)(m_xpos + m_width/2.0);
switch (attachment)
int physicalAttachment = LogicalToPhysicalAttachment(attachment);
switch (physicalAttachment)
{
case 0:
{

View File

@@ -186,7 +186,7 @@ bool wxDividedShape::GetAttachmentPosition(int attachment, double *x, double *y,
wxLineShape *line)
{
int totalNumberAttachments = (GetRegions().Number() * 2) + 2;
if (!GetAttachmentMode() || (attachment >= totalNumberAttachments))
if ((GetAttachmentMode() == ATTACHMENT_MODE_NONE) || (attachment >= totalNumberAttachments))
{
return wxShape::GetAttachmentPosition(attachment, x, y, nth, no_arcs);
}

View File

@@ -1219,7 +1219,7 @@ bool wxOpPolyDraw::GetPerimeterPoint(double x1, double y1,
double x2, double y2,
double *x3, double *y3,
double xOffset, double yOffset,
bool attachmentMode)
int attachmentMode)
{
int n = m_noPoints;
@@ -1227,7 +1227,7 @@ bool wxOpPolyDraw::GetPerimeterPoint(double x1, double y1,
// and we would want to connect to a point on that vertical --
// oglFindEndForPolyline can't cope with this (the arrow
// gets drawn to the wrong place).
if ((!attachmentMode) && (x1 == x2))
if ((attachmentMode == ATTACHMENT_MODE_NONE) && (x1 == x2))
{
// Look for the point we'd be connecting to. This is
// a heuristic...

View File

@@ -79,7 +79,7 @@ public:
double x2, double y2,
double *x3, double *y3,
double xOffset, double yOffset,
bool attachmentMode)
int attachmentMode)
{ return FALSE; }
protected:
@@ -191,7 +191,7 @@ public:
double x2, double y2,
double *x3, double *y3,
double xOffset, double yOffset,
bool attachmentMode);
int attachmentMode);
public:
wxRealPoint* m_points;

View File

@@ -1065,7 +1065,7 @@ void wxLineShape::OnMoveLink(wxDC& dc, bool moveControlPoints)
// if (moveControlPoints && m_lineControlPoints && !(x_offset == 0.0 && y_offset == 0.0))
// Only move control points if it's a self link. And only works if attachment mode is ON.
if ((m_from == m_to) && m_from->GetAttachmentMode() && moveControlPoints && m_lineControlPoints && !(x_offset == 0.0 && y_offset == 0.0))
if ((m_from == m_to) && (m_from->GetAttachmentMode() != ATTACHMENT_MODE_NONE) && moveControlPoints && m_lineControlPoints && !(x_offset == 0.0 && y_offset == 0.0))
{
wxNode *node = m_lineControlPoints->First();
while (node)
@@ -1110,7 +1110,7 @@ void wxLineShape::FindLineEndPoints(double *fromX, double *fromY, double *toX, d
if (m_lineControlPoints->Number() > 2)
{
if (m_from->GetAttachmentMode())
if (m_from->GetAttachmentMode() != ATTACHMENT_MODE_NONE)
{
int nth, no_arcs;
FindNth(m_from, &nth, &no_arcs, FALSE); // Not incoming
@@ -1121,7 +1121,7 @@ void wxLineShape::FindLineEndPoints(double *fromX, double *fromY, double *toX, d
(double)second_point->x, (double)second_point->y,
&end_x, &end_y);
if (m_to->GetAttachmentMode())
if (m_to->GetAttachmentMode() != ATTACHMENT_MODE_NONE)
{
int nth, no_arcs;
FindNth(m_to, &nth, &no_arcs, TRUE); // Incoming
@@ -1139,7 +1139,7 @@ void wxLineShape::FindLineEndPoints(double *fromX, double *fromY, double *toX, d
double toX = m_to->GetX();
double toY = m_to->GetY();
if (m_from->GetAttachmentMode())
if (m_from->GetAttachmentMode() != ATTACHMENT_MODE_NONE)
{
int nth, no_arcs;
FindNth(m_from, &nth, &no_arcs, FALSE);
@@ -1148,7 +1148,7 @@ void wxLineShape::FindLineEndPoints(double *fromX, double *fromY, double *toX, d
fromY = end_y;
}
if (m_to->GetAttachmentMode())
if (m_to->GetAttachmentMode() != ATTACHMENT_MODE_NONE)
{
int nth, no_arcs;
FindNth(m_to, &nth, &no_arcs, TRUE);
@@ -1157,12 +1157,12 @@ void wxLineShape::FindLineEndPoints(double *fromX, double *fromY, double *toX, d
toY = other_end_y;
}
if (!m_from->GetAttachmentMode())
if (m_from->GetAttachmentMode() == ATTACHMENT_MODE_NONE)
(void) m_from->GetPerimeterPoint(m_from->GetX(), m_from->GetY(),
toX, toY,
&end_x, &end_y);
if (!m_to->GetAttachmentMode())
if (m_to->GetAttachmentMode() == ATTACHMENT_MODE_NONE)
(void) m_to->GetPerimeterPoint(m_to->GetX(), m_to->GetY(),
fromX, fromY,
&other_end_x, &other_end_y);

View File

@@ -276,15 +276,11 @@ protected:
// probably be the same)
wxList* m_lineControlPoints;
double m_arrowSpacing; // Separation between adjacent arrows
double m_arrowSpacing; // Separation between adjacent arrows
wxShape* m_to;
wxShape* m_from;
/*
double m_actualTextWidth; // Space the text takes up
double m_actualTextHeight; // (depends on text content unlike nodes)
*/
int m_attachmentTo; // Attachment point at one end
int m_attachmentFrom; // Attachment point at other end

View File

@@ -25,8 +25,8 @@ LOCALDOCDIR=$(WXDIR)\utils\ogl\docs
PROGRAM=test
OBJECTS = basic.obj basic2.obj canvas.obj ogldiag.obj lines.obj misc.obj divided.obj constrnt.obj\
composit.obj drawn.obj bmpshape.obj mfutils.obj
OBJECTS = $(THISDIR)\basic.obj $(THISDIR)\basic2.obj $(THISDIR)\canvas.obj $(THISDIR)\ogldiag.obj $(THISDIR)\lines.obj $(THISDIR)\misc.obj $(THISDIR)\divided.obj $(THISDIR)\constrnt.obj\
$(THISDIR)\composit.obj $(THISDIR)\drawn.obj $(THISDIR)\bmpshape.obj $(THISDIR)\mfutils.obj
LIBTARGET=$(WXDIR)\lib\ogl.lib
@@ -59,57 +59,57 @@ basic.obj: basic.$(SRCSUFF) basic.h lines.h misc.h canvas.h
$(CPPFLAGS) /Od /c /Tp $*.$(SRCSUFF)
<<
basic2.obj: basic2.$(SRCSUFF) basic.h lines.h misc.h canvas.h
$(THISDIR)\basic2.obj: basic2.$(SRCSUFF) basic.h lines.h misc.h canvas.h
cl @<<
$(CPPFLAGS) /Od /c /Tp $*.$(SRCSUFF)
<<
canvas.obj: canvas.$(SRCSUFF) basic.h misc.h canvas.h
$(THISDIR)\canvas.obj: canvas.$(SRCSUFF) basic.h misc.h canvas.h
cl @<<
$(CPPFLAGS) /c /Tp $*.$(SRCSUFF)
<<
ogldiag.obj: ogldiag.$(SRCSUFF) ogldiag.h canvas.h basic.h
$(THISDIR)\ogldiag.obj: ogldiag.$(SRCSUFF) ogldiag.h canvas.h basic.h
cl @<<
$(CPPFLAGS) /c /Tp $*.$(SRCSUFF)
<<
lines.obj: lines.$(SRCSUFF) basic.h misc.h canvas.h lines.h basicp.h linesp.h
$(THISDIR)\lines.obj: lines.$(SRCSUFF) basic.h misc.h canvas.h lines.h basicp.h linesp.h
cl @<<
$(CPPFLAGS) /c /Tp $*.$(SRCSUFF)
<<
misc.obj: misc.$(SRCSUFF) basic.h misc.h constrnt.h basicp.h
$(THISDIR)\misc.obj: misc.$(SRCSUFF) basic.h misc.h constrnt.h basicp.h
cl @<<
$(CPPFLAGS) /c /Tp $*.$(SRCSUFF)
<<
divided.obj: divided.$(SRCSUFF) basic.h misc.h canvas.h divided.h basicp.h
$(THISDIR)\divided.obj: divided.$(SRCSUFF) basic.h misc.h canvas.h divided.h basicp.h
cl @<<
$(CPPFLAGS) /c /Tp $*.$(SRCSUFF)
<<
constrnt.obj: constrnt.$(SRCSUFF) basic.h constrnt.h
$(THISDIR)\constrnt.obj: constrnt.$(SRCSUFF) basic.h constrnt.h
cl @<<
$(CPPFLAGS) /c /Tp $*.$(SRCSUFF)
<<
composit.obj: composit.$(SRCSUFF) basic.h misc.h canvas.h constrnt.h composit.h basicp.h
$(THISDIR)\composit.obj: composit.$(SRCSUFF) basic.h misc.h canvas.h constrnt.h composit.h basicp.h
cl @<<
$(CPPFLAGS) /c /Tp $*.$(SRCSUFF)
<<
drawn.obj: drawn.$(SRCSUFF) basic.h misc.h canvas.h drawn.h drawnp.h basicp.h
$(THISDIR)\drawn.obj: drawn.$(SRCSUFF) basic.h misc.h canvas.h drawn.h drawnp.h basicp.h
cl @<<
$(CPPFLAGS) /c /Tp $*.$(SRCSUFF)
<<
bmpshape.obj: bmpshape.$(SRCSUFF) basic.h misc.h canvas.h bmpshape.h
$(THISDIR)\bmpshape.obj: bmpshape.$(SRCSUFF) basic.h misc.h canvas.h bmpshape.h
cl @<<
$(CPPFLAGS) /c /Tp $*.$(SRCSUFF)
<<
mfutils.obj: mfutils.$(SRCSUFF) mfutils.h
$(THISDIR)\mfutils.obj: mfutils.$(SRCSUFF) mfutils.h
cl @<<
$(CPPFLAGS) /c /Tp $*.$(SRCSUFF)
<<

View File

@@ -592,3 +592,163 @@ wxShape* wxDiagram::FindShape(long id) const
return NULL;
}
//// Crossings classes
wxLineCrossings::wxLineCrossings()
{
}
wxLineCrossings::~wxLineCrossings()
{
ClearCrossings();
}
void wxLineCrossings::FindCrossings(wxDiagram& diagram)
{
ClearCrossings();
wxNode* node1 = diagram.GetShapeList()->First();
while (node1)
{
wxShape* shape1 = (wxShape*) node1->Data();
if (shape1->IsKindOf(CLASSINFO(wxLineShape)))
{
wxLineShape* lineShape1 = (wxLineShape*) shape1;
// Iterate through the segments
wxList* pts1 = lineShape1->GetLineControlPoints();
int i;
for (i = 0; i < (pts1->Number() - 1); i++)
{
wxRealPoint* pt1_a = (wxRealPoint*) (pts1->Nth(i)->Data());
wxRealPoint* pt1_b = (wxRealPoint*) (pts1->Nth(i+1)->Data());
// Now we iterate through the segments again
wxNode* node2 = diagram.GetShapeList()->First();
while (node2)
{
wxShape* shape2 = (wxShape*) node2->Data();
// Assume that the same line doesn't cross itself
if (shape2->IsKindOf(CLASSINFO(wxLineShape)) && (shape1 != shape2))
{
wxLineShape* lineShape2 = (wxLineShape*) shape2;
// Iterate through the segments
wxList* pts2 = lineShape2->GetLineControlPoints();
int j;
for (j = 0; j < (pts2->Number() - 1); j++)
{
wxRealPoint* pt2_a = (wxRealPoint*) (pts2->Nth(j)->Data());
wxRealPoint* pt2_b = (wxRealPoint*) (pts2->Nth(j+1)->Data());
// Now let's see if these two segments cross.
double ratio1, ratio2;
oglCheckLineIntersection(pt1_a->x, pt1_a->y, pt1_b->x, pt1_b->y,
pt2_a->x, pt2_a->y, pt2_b->x, pt2_b->y,
& ratio1, & ratio2);
if ((ratio1 < 1.0) && (ratio1 > -1.0))
{
// Intersection!
wxLineCrossing* crossing = new wxLineCrossing;
crossing->m_intersect.x = (pt1_a->x + (pt1_b->x - pt1_a->x)*ratio1);
crossing->m_intersect.y = (pt1_a->y + (pt1_b->y - pt1_a->y)*ratio1);
crossing->m_pt1 = * pt1_a;
crossing->m_pt2 = * pt1_b;
crossing->m_pt3 = * pt2_a;
crossing->m_pt4 = * pt2_b;
crossing->m_lineShape1 = lineShape1;
crossing->m_lineShape2 = lineShape2;
m_crossings.Append(crossing);
}
}
}
node2 = node2->Next();
}
}
}
node1 = node1->Next();
}
}
void wxLineCrossings::DrawCrossings(wxDiagram& diagram, wxDC& dc)
{
dc.SetBrush(*wxTRANSPARENT_BRUSH);
long arcWidth = 8;
wxNode* node = m_crossings.First();
while (node)
{
wxLineCrossing* crossing = (wxLineCrossing*) node->Data();
// dc.DrawEllipse((long) (crossing->m_intersect.x - (arcWidth/2.0) + 0.5), (long) (crossing->m_intersect.y - (arcWidth/2.0) + 0.5),
// arcWidth, arcWidth);
// Let's do some geometry to find the points on either end of the arc.
/*
(x1, y1)
|\
| \
| \
| \
| \
| |\ c c1
| a | \
| \
| - x <-- centre of arc
a1 | b |\
| | \ c2
| a2 | \
| - \
| b2 \
| \
|_______________\ (x2, y2)
b1
*/
double a1 = wxMax(crossing->m_pt1.y, crossing->m_pt2.y) - wxMin(crossing->m_pt1.y, crossing->m_pt2.y) ;
double b1 = wxMax(crossing->m_pt1.x, crossing->m_pt2.x) - wxMin(crossing->m_pt1.x, crossing->m_pt2.x) ;
double c1 = sqrt( (a1*a1) + (b1*b1) );
double c = arcWidth / 2.0;
double a = c * a1/c1 ;
double b = c * b1/c1 ;
// I'm not sure this is right, since we don't know which direction we should be going in - need
// to know which way the line slopes and choose the sign appropriately.
double arcX1 = crossing->m_intersect.x - b;
double arcY1 = crossing->m_intersect.y - a;
double arcX2 = crossing->m_intersect.x + b;
double arcY2 = crossing->m_intersect.y + a;
dc.SetPen(*wxBLACK_PEN);
dc.DrawArc( (long) arcX1, (long) arcY1, (long) arcX2, (long) arcY2,
(long) crossing->m_intersect.x, (long) crossing->m_intersect.y);
dc.SetPen(*wxWHITE_PEN);
dc.DrawLine( (long) arcX1, (long) arcY1, (long) arcX2, (long) arcY2 );
node = node->Next();
}
}
void wxLineCrossings::ClearCrossings()
{
wxNode* node = m_crossings.First();
while (node)
{
wxLineCrossing* crossing = (wxLineCrossing*) node->Data();
delete crossing;
node = node->Next();
}
m_crossings.Clear();
}

View File

@@ -93,5 +93,32 @@ protected:
wxList* m_shapeList;
};
class wxLineCrossing: public wxObject
{
public:
wxLineCrossing() { m_lineShape1 = NULL; m_lineShape2 = NULL; }
wxRealPoint m_pt1; // First line
wxRealPoint m_pt2;
wxRealPoint m_pt3; // Second line
wxRealPoint m_pt4;
wxRealPoint m_intersect;
wxLineShape* m_lineShape1;
wxLineShape* m_lineShape2;
};
class wxLineCrossings: public wxObject
{
public:
wxLineCrossings();
~wxLineCrossings();
void FindCrossings(wxDiagram& diagram);
void DrawCrossings(wxDiagram& diagram, wxDC& dc);
void ClearCrossings();
public:
wxList m_crossings;
};
#endif
// _OGL_OGLDIAG_H_

View File

@@ -1750,28 +1750,72 @@ bool wxPropertyStringListEditorDialog::dialogCancelled = FALSE;
// Edit the string list.
bool wxListOfStringsListValidator::EditStringList(wxWindow *parent, wxStringList *stringList, const char *title)
{
int largeButtonWidth = 60;
int largeButtonHeight = 25;
wxBeginBusyCursor();
wxPropertyStringListEditorDialog *dialog = new wxPropertyStringListEditorDialog(parent,
title, wxPoint(10, 10), wxSize(400, 400), wxDEFAULT_DIALOG_STYLE|wxDIALOG_MODAL);
dialog->stringList = stringList;
wxButton *okButton = new wxButton(dialog, wxID_OK, "OK", wxPoint(5, 5));
wxButton *cancelButton = new wxButton(dialog, wxID_CANCEL, "Cancel", wxPoint(40, 5));
// wxButton *helpButton = new wxButton(dialog, (wxFunction)StringListEditorHelpProc, "Help");
// helpButton->SetClientData((char *)this);
dialog->listBox = new wxListBox(dialog, wxID_PROP_SL_STRINGS,
wxPoint(5, 30), wxSize(300, 200), 0, NULL, wxLB_SINGLE);
wxPoint(-1, -1), wxSize(-1, -1), 0, NULL, wxLB_SINGLE);
dialog->stringText = new wxPropertyStringListEditorText(dialog,
wxID_PROP_SL_TEXT, "", wxPoint(5, 240),
wxSize(300, -1), wxPROCESS_ENTER);
dialog->stringText->Enable(FALSE);
wxButton *addButton = new wxButton(dialog, wxID_PROP_SL_ADD, "Add", wxPoint(5, 280));
wxButton *deleteButton = new wxButton(dialog, wxID_PROP_SL_DELETE, "Delete", wxPoint(40, 280));
wxButton *addButton = new wxButton(dialog, wxID_PROP_SL_ADD, "Add", wxPoint(-1, -1), wxSize(largeButtonWidth, largeButtonHeight));
wxButton *deleteButton = new wxButton(dialog, wxID_PROP_SL_DELETE, "Delete", wxPoint(-1, -1), wxSize(largeButtonWidth, largeButtonHeight));
wxButton *cancelButton = new wxButton(dialog, wxID_CANCEL, "Cancel", wxPoint(-1, -1), wxSize(largeButtonWidth, largeButtonHeight));
wxButton *okButton = new wxButton(dialog, wxID_OK, "OK", wxPoint(-1, -1), wxSize(largeButtonWidth, largeButtonHeight));
okButton->SetDefault();
wxLayoutConstraints *c = new wxLayoutConstraints;
c->top.SameAs (dialog, wxTop, 2);
c->left.SameAs (dialog, wxLeft, 2);
c->right.SameAs (dialog, wxRight, 2);
c->bottom.SameAs (dialog->stringText, wxTop, 2);
dialog->listBox->SetConstraints(c);
c = new wxLayoutConstraints;
c->left.SameAs (dialog, wxLeft, 2);
c->right.SameAs (dialog, wxRight, 2);
c->bottom.SameAs (addButton, wxTop, 2);
c->height.AsIs();
dialog->stringText->SetConstraints(c);
c = new wxLayoutConstraints;
c->bottom.SameAs (dialog, wxBottom, 2);
c->left.SameAs (dialog, wxLeft, 2);
c->width.AsIs();
c->height.AsIs();
addButton->SetConstraints(c);
c = new wxLayoutConstraints;
c->bottom.SameAs (dialog, wxBottom, 2);
c->left.SameAs (addButton, wxRight, 2);
c->width.AsIs();
c->height.AsIs();
deleteButton->SetConstraints(c);
c = new wxLayoutConstraints;
c->bottom.SameAs (dialog, wxBottom, 2);
c->right.SameAs (dialog, wxRight, 2);
c->width.AsIs();
c->height.AsIs();
cancelButton->SetConstraints(c);
c = new wxLayoutConstraints;
c->bottom.SameAs (dialog, wxBottom, 2);
c->right.SameAs (cancelButton, wxLeft, 2);
c->width.AsIs();
c->height.AsIs();
okButton->SetConstraints(c);
wxNode *node = stringList->First();
while (node)
@@ -1783,6 +1827,7 @@ bool wxListOfStringsListValidator::EditStringList(wxWindow *parent, wxStringList
}
dialog->SetClientSize(310, 305);
dialog->Layout();
dialog->Centre(wxBOTH);
wxEndBusyCursor();