X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/f93ce4dadc287261babbd21a29aae59a8efbed2b..8516328f1bf774bbd96ce400945b0f06be93c397:/utils/ogl/src/ogldiag.cpp diff --git a/utils/ogl/src/ogldiag.cpp b/utils/ogl/src/ogldiag.cpp index 35deb671dd..3961607b18 100644 --- a/utils/ogl/src/ogldiag.cpp +++ b/utils/ogl/src/ogldiag.cpp @@ -24,17 +24,19 @@ #include #endif -#ifdef PROLOGIO #include -#endif -#if USE_IOSTREAMH +#if wxUSE_IOSTREAMH #include +#include #else #include +#include +#ifdef _MSC_VER +using namespace std; +#endif #endif -#include #include #include #include @@ -91,7 +93,7 @@ void wxDiagram::Redraw(wxDC& dc) if (m_shapeList) { if (GetCanvas()) - GetCanvas()->SetCursor(wxHOURGLASS_CURSOR); + GetCanvas()->SetCursor(* wxHOURGLASS_CURSOR); wxNode *current = m_shapeList->First(); while (current) @@ -103,7 +105,7 @@ void wxDiagram::Redraw(wxDC& dc) current = current->Next(); } if (GetCanvas()) - GetCanvas()->SetCursor(wxSTANDARD_CURSOR); + GetCanvas()->SetCursor(* wxSTANDARD_CURSOR); } } @@ -189,20 +191,20 @@ void wxDiagram::DrawOutline(wxDC& dc, double x1, double y1, double x2, double y2 wxPoint points[5]; - points[0].x = x1; - points[0].y = y1; + points[0].x = (int) x1; + points[0].y = (int) y1; - points[1].x = x2; - points[1].y = y1; + points[1].x = (int) x2; + points[1].y = (int) y1; - points[2].x = x2; - points[2].y = y2; + points[2].x = (int) x2; + points[2].y = (int) y2; - points[3].x = x1; - points[3].y = y2; + points[3].x = (int) x1; + points[3].y = (int) y2; - points[4].x = x1; - points[4].y = y1; + points[4].x = (int) x1; + points[4].y = (int) y1; dc.DrawLines(5, points); } @@ -592,3 +594,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(); +} +