From a4995ae786fe805ec1d4c1d6537843000bb5a2df Mon Sep 17 00:00:00 2001 From: dickelbeck Date: Mon, 5 May 2008 19:46:54 +0000 Subject: [PATCH] wrote GetEnd(), GetStart(), GetLength(), embellished Display_Infos() --- pcbnew/class_drawsegment.cpp | 76 +++++++++++++++++++++++++++++++----- pcbnew/class_drawsegment.h | 25 ++++++++++++ 2 files changed, 92 insertions(+), 9 deletions(-) diff --git a/pcbnew/class_drawsegment.cpp b/pcbnew/class_drawsegment.cpp index 65ec934f3f..1356affbca 100644 --- a/pcbnew/class_drawsegment.cpp +++ b/pcbnew/class_drawsegment.cpp @@ -144,6 +144,45 @@ bool DRAWSEGMENT::ReadDrawSegmentDescr( FILE* File, int* LineNum ) } +wxPoint DRAWSEGMENT::GetStart() const +{ + switch( m_Shape ) + { + case S_ARC: + return m_End; // the start of the arc is held in field m_End, center point is in m_Start. + + case S_SEGMENT: + default: + return m_Start; + } +} + + +wxPoint DRAWSEGMENT::GetEnd() const +{ + switch( m_Shape ) + { + case S_ARC: + { + // rotate the starting point of the arc, given by m_End, through the angle m_Angle + // to get the ending point of the arc. + wxPoint center = m_Start; // center point of the arc + wxPoint start = m_End; // start of arc + + RotatePoint( &start.x, &start.y, center.x, center.y, -m_Angle ); + + return start; // after rotation, the end of the arc. + } + break; + + case S_SEGMENT: + default: + return m_End; + } +} + + + void DRAWSEGMENT::Draw( WinEDA_DrawPanel* panel, wxDC* DC, int draw_mode, const wxPoint& notUsed ) { @@ -249,6 +288,7 @@ void DRAWSEGMENT::Display_Infos( WinEDA_DrawFrame* frame ) { int itype; wxString msg; + wxString coords; BOARD* board = (BOARD*) m_Parent; wxASSERT( board ); @@ -261,25 +301,35 @@ void DRAWSEGMENT::Display_Infos( WinEDA_DrawFrame* frame ) Affiche_1_Parametre( frame, 1, _( "Type" ), msg, DARKCYAN ); - Affiche_1_Parametre( frame, 16, _( "Shape" ), wxEmptyString, RED ); + wxString shape = _( "Shape" ); if( m_Shape == S_CIRCLE ) - Affiche_1_Parametre( frame, -1, wxEmptyString, _( "Circle" ), RED ); + Affiche_1_Parametre( frame, 10, shape, _( "Circle" ), RED ); else if( m_Shape == S_ARC ) { - Affiche_1_Parametre( frame, -1, wxEmptyString, _( " Arc " ), RED ); - msg.Printf( wxT( "%d" ), m_Angle ); - Affiche_1_Parametre( frame, 32, wxT( " l.arc " ), msg, RED ); + Affiche_1_Parametre( frame, 10, shape, _( "Arc" ), RED ); + + msg.Printf( wxT( "%d.%d" ), m_Angle/10, m_Angle % 10 ); + Affiche_1_Parametre( frame, 18, _("Angle"), msg, RED ); } else - Affiche_1_Parametre( frame, -1, wxEmptyString, _( "Segment" ), RED ); + Affiche_1_Parametre( frame, 10, shape, _( "Segment" ), RED ); - Affiche_1_Parametre( frame, 48, _( "Layer" ), + wxString start; + start << GetStart(); + + wxString end; + end << GetEnd(); + + Affiche_1_Parametre( frame, 22, start, end, BLACK ); + + Affiche_1_Parametre( frame, 36, _( "Layer" ), board->GetLayerName( m_Layer ), BROWN ); valeur_param( (unsigned) m_Width, msg ); - Affiche_1_Parametre( frame, 60, _( "Width" ), msg, DARKCYAN ); + + Affiche_1_Parametre( frame, 50, _( "Width" ), msg, DARKCYAN ); } @@ -366,10 +416,18 @@ void DRAWSEGMENT::Show( int nestLevel, std::ostream& os ) { NestedSpace( nestLevel, os ) << '<' << GetClass().Lower().mb_str() << + " shape=\"" << m_Shape << '"' << +/* " layer=\"" << GetLayer() << '"' << " width=\"" << m_Width << '"' << + " angle=\"" << m_Angle << '"' << // Used only for Arcs: Arc angle in 1/10 deg +*/ + '>' << "" << - ""; + "" + "" << + "" + ; os << "\n"; } diff --git a/pcbnew/class_drawsegment.h b/pcbnew/class_drawsegment.h index e5feb57181..dc94db3504 100644 --- a/pcbnew/class_drawsegment.h +++ b/pcbnew/class_drawsegment.h @@ -33,6 +33,18 @@ public: } + /** + * Function GetStart + * returns the starting point of the graphic + */ + wxPoint GetStart() const; + + /** + * Function GetEnd + * returns the ending point of the graphic + */ + wxPoint GetEnd() const; + /** * Function Save * writes the data structures for this object out to a FILE in "*.brd" format. @@ -90,6 +102,19 @@ public: } + /** + * Function GetLength + * returns the length of the track using the hypotenuse calculation. + * @return double - the length of the track + */ + double GetLength() const + { + wxPoint delta = GetEnd() - GetStart(); + + return hypot( delta.x, delta.y ); + } + + #if defined(DEBUG) void Show( int nestLevel, std::ostream& os ); #endif