From 3465bfeb82b4b974319b4af8b5359dc5799363da Mon Sep 17 00:00:00 2001 From: dickelbeck Date: Sat, 1 Dec 2007 05:37:44 +0000 Subject: [PATCH] 2nd of 3 commits for DrcDialog rework --- include/pcbstruct.h | 11 +++ pcbnew/class_board.cpp | 56 +++++++++++++++ pcbnew/class_marker.cpp | 21 +++++- pcbnew/class_marker.h | 24 +------ pcbnew/drc.cpp | 149 ++++++++++++---------------------------- pcbnew/drc_stuff.h | 136 ++++++++++++++---------------------- 6 files changed, 183 insertions(+), 214 deletions(-) diff --git a/include/pcbstruct.h b/include/pcbstruct.h index 2be35791b7..198e3f0626 100644 --- a/include/pcbstruct.h +++ b/include/pcbstruct.h @@ -281,6 +281,17 @@ public: return m_markers[index]; return NULL; } + + + /** + * Function GetMARKERCount + * @return int - The number of MARKERS. + */ + int GetMARKERCount() const + { + return (int) m_markers.size(); + } + /* Routines de calcul des nombres de segments pistes et zones */ int GetNumSegmTrack(); diff --git a/pcbnew/class_board.cpp b/pcbnew/class_board.cpp index 132b6202b3..75ee5f74ce 100644 --- a/pcbnew/class_board.cpp +++ b/pcbnew/class_board.cpp @@ -9,6 +9,62 @@ #include "bitmaps.h" + +wxString DRC_ITEM::GetErrorText() const +{ + switch( m_ErrorCode ) + { +// case DRCE_: not assigned yet + + case DRCE_UNCONNECTED_PADS: + return wxString( _("Unconnected pads") ); + case DRCE_TRACK_NEAR_THROUGH_HOLE: + return wxString( _("Track near thru-hole") ); + case DRCE_TRACK_NEAR_PAD: + return wxString( _("Track near pad") ); + case DRCE_TRACK_NEAR_VIA: + return wxString( _("Track near via") ); + case DRCE_VIA_NEAR_VIA: + return wxString( _("Via near via") ); + case DRCE_VIA_NEAR_TRACK: + return wxString( _("Via near track") ); + case DRCE_TRACK_ENDS1: + case DRCE_TRACK_ENDS2: + case DRCE_TRACK_ENDS3: + case DRCE_TRACK_ENDS4: + case DRCE_ENDS_PROBLEM1: + case DRCE_ENDS_PROBLEM2: + case DRCE_ENDS_PROBLEM3: + case DRCE_ENDS_PROBLEM4: + case DRCE_ENDS_PROBLEM5: + return wxString( _("Two track ends") ); + case DRCE_TRACK_UNKNOWN1: + return wxString( _("This looks bad") ); ///< @todo check source code and change this comment + case DRCE_TRACKS_CROSSING: + return wxString( _("Tracks crossing") ); + case DRCE_PAD_NEAR_PAD1: + return wxString( _("Pad near pad") ); + + default: + return wxString( wxT("PROGRAM BUG, PLEASE LEAVE THE ROOM.") ); + } +} + + +wxString DRC_ITEM::ShowCoord( const wxPoint& aPos ) +{ + wxString temp; + wxString ret; + + ret << wxT("@(") << valeur_param( aPos.x, temp ); + ret << wxT(",") << valeur_param( aPos.y, temp ); + ret << wxT(")"); + + return ret; +} + + + /*****************/ /* Class BOARD: */ /*****************/ diff --git a/pcbnew/class_marker.cpp b/pcbnew/class_marker.cpp index 5dff99162a..efe695d8e7 100644 --- a/pcbnew/class_marker.cpp +++ b/pcbnew/class_marker.cpp @@ -18,7 +18,7 @@ /* Default bitmap shape for markers */ static char Default_MarkerBitmap[] = { - 12, 12, /* x and y sise of the bitmap */ + 12, 12, /* x and y size of the bitmap */ 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, /* bitmap: 1 = color, 0 = notrace */ 1, 1, 1, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, @@ -106,11 +106,26 @@ void MARKER::Display_Infos( WinEDA_DrawFrame* frame ) frame->MsgPanel->EraseMsgBox(); + const DRC_ITEM& rpt = m_drc; + text_pos = 1; Affiche_1_Parametre( frame, text_pos, _( "Type" ), _("Marker"), DARKCYAN ); - text_pos = 12; - Affiche_1_Parametre( frame, text_pos, _( "Marker Error Text" ), GetOneLineMessage(), RED ); + wxString errorTxt; + + errorTxt << _("ErrType") << wxT("(") << rpt.GetErrorCode() << wxT(")- ") << rpt.GetErrorText() << wxT(":"); + + text_pos = 5; + Affiche_1_Parametre( frame, text_pos, errorTxt, wxEmptyString, RED ); + + wxString txtA; + txtA << DRC_ITEM::ShowCoord( rpt.GetPointA() ) << wxT(": ") << rpt.GetTextA(); + + wxString txtB; + txtB << DRC_ITEM::ShowCoord( rpt.GetPointB() ) << wxT(": ") << rpt.GetTextB(); + + text_pos = 20; // @todo pick a better color here + Affiche_1_Parametre( frame, text_pos, txtA, txtB, BLACK ); } diff --git a/pcbnew/class_marker.h b/pcbnew/class_marker.h index 632b136565..b312eeec4d 100644 --- a/pcbnew/class_marker.h +++ b/pcbnew/class_marker.h @@ -78,37 +78,19 @@ public: const wxString& aText, const wxPoint& aPos, const wxString& bText, const wxPoint& bPos ); - /** - * Function GetMessage - * @return const wxString& - the diagnostic message - */ - const wxString GetOneLineMessage() - { - return m_drc.ShowText(); - } - /** * Function GetReporter - * returns the REPORT_ISSUE held within this MARKER so that its + * returns the DRC_ITEM held within this MARKER so that its * interface may be used. - * @return const& REPORT_ISSUE + * @return const& DRC_ITEM */ - const REPORT_ISSUE& GetReporter() const + const DRC_ITEM& GetReporter() const { return m_drc; } - /* - void SetMessage( const wxString& aMsg ) - { - m_Diag = aMsg; - } - */ - - - /** * Function Display_Infos * has knowledge about the frame and how and where to put status information diff --git a/pcbnew/drc.cpp b/pcbnew/drc.cpp index 49be37258e..7bcd6a45a1 100644 --- a/pcbnew/drc.cpp +++ b/pcbnew/drc.cpp @@ -41,15 +41,12 @@ #include "drc_stuff.h" - - -/* variables locales */ -class DrcDialog; - - #include "dialog_drc.cpp" +#define EC_INC // ++m_errorCount don't need this anymore, vector counts + + /******************************************************/ void WinEDA_PcbFrame::Install_Test_DRC_Frame( wxDC* DC ) /******************************************************/ @@ -67,53 +64,14 @@ void DRC::ShowDialog() if( !m_ui ) { -printf("creating new DrcFrame\n"); m_ui = new DrcDialog( this, m_mainWindow ); } - - // @todo enter retentitive data into the panel. -// m_RptFilenameCtrl->SetValue(s_RptFilename); + // @todo enter retentitive member data into the DrcDialog here m_ui->Show(true); -// int rval = m_ui->ShowModal(); - - -#if defined(DEBUG) -// printf("dialog rval=%d wxID_OK=%d\n", rval, wxID_OK ); -#endif - -// if( rval == wxID_OK ) - { - - // @todo capture the UI entered data into the DRC_TESTER here - /* - - s_Pad2PadTestOpt = m_Pad2PadTestCtrl->IsChecked(); - s_UnconnectedTestOpt = m_UnconnectedTestCtrl->IsChecked(); - s_ZonesTestOpt = m_ZonesTestCtrl->IsChecked(); - s_CreateRptFileOpt = m_CreateRptCtrl->IsChecked(); - - wxBoxSizer* m_MainSizer; - wxBoxSizer* m_CommandSizer; - wxStaticText* m_ClearenceTitle; - wxTextCtrl* m_SetClearance; - wxCheckBox* m_CreateRptCtrl; - wxTextCtrl* m_RptFilenameCtrl; - wxButton* m_BrowseButton; - wxCheckBox* m_Pad2PadTestCtrl; - wxCheckBox* m_UnconnectedTestCtrl; - wxCheckBox* m_ZonesTestCtrl; - wxButton* m_DeleteCurrentMarkerButton; - DRCLISTBOX* m_ClearanceListBox; - DRCLISTBOX* m_UnconnectedListBox; - wxStdDialogButtonSizer* StdDialogButtonSizer; - */ - } - -// m_ui->Destroy(); -// m_ui = 0; + // @todo capture the UI entered data into this DRC object. BUT in the OK handler } @@ -180,7 +138,7 @@ void DrcDialog::CmdDrc() // @todo set the list counts in the DRCLISTITEMS here. - printf("done with tests\n"); + // printf("done with tests\n"); } @@ -194,31 +152,6 @@ void DrcDialog::ListUnconnectedPads( wxCommandEvent& event ) } -const wxString& DRC_ITEM::GetErrorText() const -{ - static const wxString error1( wxT("Items Too Close:") ); - - switch( m_ErrorCode ) - { - default: - case DRCE_: return error1; - } -} - - -wxString DRC_ITEM::ShowCoord( const wxPoint& aPos ) -{ - wxString temp; - wxString ret; - - ret << wxT("@(") << valeur_param( aPos.x, temp ); - ret << wxT(",") << valeur_param( aPos.y, temp ); - ret << wxT(")"); - - return ret; -} - - DRC::DRC( WinEDA_PcbFrame* aPcbWindow ) { m_mainWindow = aPcbWindow; @@ -234,7 +167,7 @@ DRC::DRC( WinEDA_PcbFrame* aPcbWindow ) // m_rptFilename set to empty by its constructor - m_errorCount = 0; + //m_errorCount = 0; m_currentMarker = 0; m_spotcx = 0; @@ -263,9 +196,9 @@ int DRC::Drc( TRACK* aRefSegm, TRACK* aList ) if( !doTrackDrc( aRefSegm, aList ) ) { - wxString msg = m_currentMarker->GetReporter().ShowText(); + wxASSERT( m_currentMarker ); - m_mainWindow->Affiche_Message( msg ); + m_currentMarker->Display_Infos( m_mainWindow ); return BAD_DRC; } @@ -275,20 +208,24 @@ int DRC::Drc( TRACK* aRefSegm, TRACK* aList ) void DRC::WriteReport( FILE* fp ) { - fprintf( fp, "Drc report for %s\n", + fprintf( fp, "** Drc report for %s **\n", CONV_TO_UTF8( m_mainWindow->GetScreen()->m_FileName ) ); char line[256]; - fprintf( fp, "Created on %s\n", DateAndTime( line ) ); + fprintf( fp, "** Created on %s **\n", DateAndTime( line ) ); - - // write report here - int errors = 0; - if( errors ) - fprintf( fp, "** End DRC: %d errors **\n", errors ); - else if( m_unconnectedCount == 0 ) - fprintf( fp, "** End Drc: No Error **\n" ); + fprintf( fp, "** Found %d DRC errors **\n", m_pcb->GetMARKERCount() ); + + for( int i=0; iGetMARKERCount(); ++i ) + fprintf( fp, m_pcb->GetMARKER(i)->GetReporter().ShowReport().mb_str() ); + + // @todo: the unconnected report comes here: + + /* + for( int i=0; iGetOPENNETCount(); ++i ) + fprintf( fp, m_pcb->GetOPENNET(i)->GetReporter().ShowReport().mb_str() ); + */ } @@ -302,7 +239,7 @@ void DRC::RunTests() if( m_doPad2PadTest ) testPad2Pad(); - // test track and via clearnces to other tracks, pads, and vias + // test track and via clearances to other tracks, pads, and vias testTracks(); // test zone clearances to other zones, pads, tracks, and vias @@ -448,7 +385,7 @@ MARKER* DRC::fillMarker( TRACK* aTrack, BOARD_ITEM* aItem, int aErrorCode, MARKE wxPoint endPos = track->m_End; // either of aItem's start or end will be used for the marker position - // first assume start, then swith to end if needed. decision made on + // first assume start, then switch at end if needed. decision made on // distance from end of aTrack. position = track->m_Start; @@ -533,7 +470,7 @@ bool DRC::doTrackDrc( TRACK* aRefSeg, TRACK* aStart ) /* Phase 1 : test DRC track to pads : */ /******************************************/ - D_PAD pseudo_pad( (MODULE*) NULL ); + D_PAD pseudo_pad( (MODULE*) NULL ); // construct this once outside following loop // Compute the min distance to pads w_dist = aRefSeg->m_Width >> 1; @@ -557,7 +494,7 @@ bool DRC::doTrackDrc( TRACK* aRefSeg, TRACK* aStart ) pseudo_pad.SetPosition( pad->GetPosition() ); pseudo_pad.m_PadShape = pad->m_DrillShape; pseudo_pad.m_Orient = pad->m_Orient; - pseudo_pad.ComputeRayon(); // compute the ray length + pseudo_pad.ComputeRayon(); // compute the radius m_spotcx = pseudo_pad.GetPosition().x - org_X; m_spotcy = pseudo_pad.GetPosition().y - org_Y; @@ -565,7 +502,7 @@ bool DRC::doTrackDrc( TRACK* aRefSeg, TRACK* aStart ) if( !checkClearanceSegmToPad( &pseudo_pad, w_dist, g_DesignSettings.m_TrackClearence ) ) { - ++m_errorCount; + EC_INC; m_currentMarker = fillMarker( aRefSeg, pad, DRCE_TRACK_NEAR_THROUGH_HOLE, m_currentMarker ); return false; @@ -586,7 +523,7 @@ bool DRC::doTrackDrc( TRACK* aRefSeg, TRACK* aStart ) m_spotcy = shape_pos.y - org_Y; if( !checkClearanceSegmToPad( pad, w_dist, g_DesignSettings.m_TrackClearence ) ) { - ++m_errorCount; + EC_INC; m_currentMarker = fillMarker( aRefSeg, pad, DRCE_TRACK_NEAR_PAD, m_currentMarker ); return false; @@ -642,7 +579,7 @@ bool DRC::doTrackDrc( TRACK* aRefSeg, TRACK* aStart ) // Test distance between two vias if( (int) hypot( x0, y0 ) < w_dist ) { - ++m_errorCount; + EC_INC; m_currentMarker = fillMarker( aRefSeg, track, DRCE_VIA_NEAR_VIA, m_currentMarker ); return false; @@ -659,7 +596,7 @@ bool DRC::doTrackDrc( TRACK* aRefSeg, TRACK* aStart ) if( !checkMarginToCircle( x0, y0, w_dist, dx ) ) { - ++m_errorCount; + EC_INC; m_currentMarker = fillMarker( aRefSeg, track, DRCE_VIA_NEAR_TRACK, m_currentMarker ); return false; @@ -686,7 +623,7 @@ bool DRC::doTrackDrc( TRACK* aRefSeg, TRACK* aStart ) if( checkMarginToCircle( x0, y0, w_dist, m_segmLength ) ) continue; - ++m_errorCount; + EC_INC; m_currentMarker = fillMarker( aRefSeg, track, DRCE_TRACK_NEAR_VIA, m_currentMarker ); return false; @@ -710,14 +647,14 @@ bool DRC::doTrackDrc( TRACK* aRefSeg, TRACK* aStart ) /* Fine test : we consider the rounded shape of the ends */ if( x0 >= 0 && x0 <= m_segmLength ) { - ++m_errorCount; + EC_INC; m_currentMarker = fillMarker( aRefSeg, track, DRCE_TRACK_ENDS1, m_currentMarker ); return false; } if( !checkMarginToCircle( x0, y0, w_dist, m_segmLength ) ) { - ++m_errorCount; + EC_INC; m_currentMarker = fillMarker( aRefSeg, track, DRCE_TRACK_ENDS2, m_currentMarker ); return false; @@ -728,14 +665,14 @@ bool DRC::doTrackDrc( TRACK* aRefSeg, TRACK* aStart ) /* Fine test : we consider the rounded shape of the ends */ if( xf >= 0 && xf <= m_segmLength ) { - ++m_errorCount; + EC_INC; m_currentMarker = fillMarker( aRefSeg, track, DRCE_TRACK_ENDS3, m_currentMarker ); return false; } if( !checkMarginToCircle( xf, yf, w_dist, m_segmLength ) ) { - ++m_errorCount; + EC_INC; m_currentMarker = fillMarker( aRefSeg, track, DRCE_TRACK_ENDS4, m_currentMarker ); return false; @@ -744,7 +681,7 @@ bool DRC::doTrackDrc( TRACK* aRefSeg, TRACK* aStart ) if( x0 <=0 && xf >= 0 ) { - ++m_errorCount; + EC_INC; m_currentMarker = fillMarker( aRefSeg, track, DRCE_TRACK_UNKNOWN1, m_currentMarker ); return false; @@ -760,7 +697,7 @@ bool DRC::doTrackDrc( TRACK* aRefSeg, TRACK* aStart ) EXCHG( y0, yf ); if( (y0 < 0) && (yf > 0) ) { - ++m_errorCount; + EC_INC; m_currentMarker = fillMarker( aRefSeg, track, DRCE_TRACKS_CROSSING, m_currentMarker ); return false; @@ -769,14 +706,14 @@ bool DRC::doTrackDrc( TRACK* aRefSeg, TRACK* aStart ) // At this point the drc error is due to an end near a reference segm end if( !checkMarginToCircle( x0, y0, w_dist, m_segmLength ) ) { - ++m_errorCount; + EC_INC; m_currentMarker = fillMarker( aRefSeg, track, DRCE_ENDS_PROBLEM1, m_currentMarker ); return false; } if( !checkMarginToCircle( xf, yf, w_dist, m_segmLength ) ) { - ++m_errorCount; + EC_INC; m_currentMarker = fillMarker( aRefSeg, track, DRCE_ENDS_PROBLEM2, m_currentMarker ); return false; @@ -805,7 +742,7 @@ bool DRC::doTrackDrc( TRACK* aRefSeg, TRACK* aStart ) if( !checkLine( x0, y0, xf, yf ) ) { - ++m_errorCount; + EC_INC; m_currentMarker = fillMarker( aRefSeg, track, DRCE_ENDS_PROBLEM3, m_currentMarker ); return false; @@ -841,14 +778,14 @@ bool DRC::doTrackDrc( TRACK* aRefSeg, TRACK* aStart ) RotatePoint( &rxf, &ryf, angle ); if( !checkMarginToCircle( rx0, ry0, w_dist, dx ) ) { - ++m_errorCount; + EC_INC; m_currentMarker = fillMarker( aRefSeg, track, DRCE_ENDS_PROBLEM4, m_currentMarker ); return false; } if( !checkMarginToCircle( rxf, ryf, w_dist, dx ) ) { - ++m_errorCount; + EC_INC; m_currentMarker = fillMarker( aRefSeg, track, DRCE_ENDS_PROBLEM5, m_currentMarker ); return false; @@ -900,7 +837,7 @@ bool DRC::doPadToPadsDrc( D_PAD* aRefPad, LISTE_PAD* aStart, LISTE_PAD* aEnd, if( !checkClearancePadToPad( aRefPad, pad, g_DesignSettings.m_TrackClearence ) ) { // here we have a drc error! - ++m_errorCount; + EC_INC; m_currentMarker = fillMarker( aRefPad, pad, DRCE_PAD_NEAR_PAD1, m_currentMarker ); return false; diff --git a/pcbnew/drc_stuff.h b/pcbnew/drc_stuff.h index 469e1eca2f..708995ef6c 100644 --- a/pcbnew/drc_stuff.h +++ b/pcbnew/drc_stuff.h @@ -34,8 +34,8 @@ /// DRC error codes: -#define DRCE_ 1 -#define DRCE_UNCONNECTED_PADS 2 +#define DRCE_ 1 // not used yet +#define DRCE_UNCONNECTED_PADS 2 ///< pads are unconnected #define DRCE_TRACK_NEAR_THROUGH_HOLE 3 ///< thru hole is too close to track #define DRCE_TRACK_NEAR_PAD 4 ///< pad too close to track #define DRCE_TRACK_NEAR_VIA 5 ///< track too close to via @@ -55,52 +55,6 @@ #define DRCE_PAD_NEAR_PAD1 19 ///< pad too close to pad -/** - * Class REPORT_ISSUE - * is an abstract interface used by DRCLISTBOX. It has functions to return - * either html text or disk file report text on this item. It also can - * return the drawing coordinate of the report item. - */ -class REPORT_ISSUE -{ -public: - - /** - * Function ShowHtml - * translates this object into a fragment of HTML suitable for the - * wxWidget's wxHtmlListBox class. - * @return wxString - the html text. - */ - virtual wxString ShowHtml() const = 0; - - - /** - * Function ShowText - * translates this object into a text string suitable for showing - * in the status panel. - * @return wxString - the simple non-html text. - */ - virtual wxString ShowText() const = 0; - - /** - * Function ShowText - * translates this object into a text string suitable for saving - * to disk in a report. - * @return wxString - the simple non-html text. - */ - virtual wxString ShowReport() const = 0; - - - /** - * Function GetPosition - * @return const wxPoint& - the position of this report item within - * the drawing. - */ - virtual const wxPoint& GetPosition() const = 0; -}; - - - /** * Class DRC_ITEM * is a holder for a DRC error item. It is generated when two objects are @@ -109,7 +63,7 @@ public: * Also held is the type of error by number and the location of the MARKER. * A function is provided to translate that number into text. */ -class DRC_ITEM : public REPORT_ISSUE +class DRC_ITEM { protected: @@ -150,8 +104,6 @@ public: } - //-------------------------------------------- - /** * Function ShowHtml * translates this object into a fragment of HTML suitable for the @@ -162,7 +114,8 @@ public: { wxString ret; - ret.Printf( wxT("%s
  • %s: %s
  • %s: %s
"), + ret.Printf( _("ErrType(%d): %s
  • %s: %s
  • %s: %s
"), + m_ErrorCode, GetErrorText().GetData(), ShowCoord( m_APos ).GetData(), m_AText.GetData(), ShowCoord( m_BPos ).GetData(), m_BText.GetData() ); @@ -170,43 +123,62 @@ public: return ret; } - /** - * Function ShowText - * translates this object into a text string suitable for saving - * to disk in a report. Change this as needed to format the report. - * @return wxString - the simple non-html text. - */ - wxString ShowText() const - { - wxString ret; - - ret.Printf( wxT("%s %s: %s AND %s: %s"), - GetErrorText().GetData(), - ShowCoord( m_APos ).GetData(), m_AText.GetData(), - ShowCoord( m_BPos ).GetData(), m_BText.GetData() ); - - return ret; - } - /** - * Function ShowText + * Function ShowReport * translates this object into a text string suitable for saving * to disk in a report. - * @return wxString - the simple non-html text. + * @return wxString - the simple multi-line report text. */ wxString ShowReport() const { wxString ret; - ret.Printf( wxT("%s\n %s: %s\n %s: %s\n"), + ret.Printf( wxT("ErrType(%d): %s\n %s: %s\n %s: %s\n"), + m_ErrorCode, GetErrorText().GetData(), ShowCoord( m_APos ).GetData(), m_AText.GetData(), ShowCoord( m_BPos ).GetData(), m_BText.GetData() ); return ret; } + + /** + * Function GetErrorCode + * returns the error code. + */ + int GetErrorCode() const + { + return m_ErrorCode; + } + + /** + * Function GetErrorText + * returns the string form of a drc error code. + */ + wxString GetErrorText() const; + + const wxString& GetTextA() const + { + return m_AText; + } + + const wxString& GetTextB() const + { + return m_BText; + } + + + const wxPoint& GetPointA() const + { + return m_APos; + } + + const wxPoint& GetPointB() const + { + return m_BPos; + } /** * Function GetPosition @@ -218,16 +190,6 @@ public: return m_Pos; } - //-----
--------------------------------------- - - - /** - * Function GetErrorText - * returns the string form of a drc error code. - */ - const wxString& GetErrorText() const; - - /** * Function ShowCoord * formats a coordinate or position to text. @@ -268,7 +230,7 @@ private: wxString m_rptFilename; - int m_errorCount; + // int m_errorCount; MARKER* m_currentMarker; @@ -477,6 +439,12 @@ public: m_doCreateRptFile = aSaveReport; } + + /** + * Function RunTests + * will actually run all the tests specified with a previous call to + * SetSettings() + */ void RunTests();