From 0d2ee0c023617c27129d7198dc58a87ede9c8fce Mon Sep 17 00:00:00 2001 From: charras Date: Mon, 6 Jul 2009 18:02:26 +0000 Subject: [PATCH] See changelog. work in progress about ERC and markers in eeschema --- CHANGELOG.txt | 16 ++ common/CMakeLists.txt | 1 + common/class_marker_base.cpp | 175 +++++++++++++++++++++ eeschema/block.cpp | 12 +- eeschema/class_schematic_items.cpp | 94 +++--------- eeschema/class_schematic_items.h | 42 +++-- eeschema/controle.cpp | 8 +- eeschema/delete.cpp | 6 +- eeschema/eeredraw.cpp | 52 ------- eeschema/erc.cpp | 63 ++++---- eeschema/find.cpp | 6 +- eeschema/load_one_schematic_file.cpp | 19 +-- eeschema/locate.cpp | 8 +- eeschema/protos.h | 3 - eeschema/schematic_undo_redo.cpp | 4 +- include/class_drc_item.h | 219 +++++++++++++++++++++++++++ include/class_marker_base.h | 147 ++++++++++++++++++ pcbnew/class_marker.cpp | 147 +----------------- pcbnew/class_marker.h | 81 ++-------- pcbnew/dialog_drc.cpp | 4 +- pcbnew/drc.cpp | 2 +- pcbnew/drc_stuff.h | 194 +----------------------- 22 files changed, 700 insertions(+), 603 deletions(-) create mode 100644 common/class_marker_base.cpp create mode 100644 include/class_drc_item.h create mode 100644 include/class_marker_base.h diff --git a/CHANGELOG.txt b/CHANGELOG.txt index ed503d26ed..f1a3fe98cf 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -4,6 +4,22 @@ KiCad ChangeLog 2009 Please add newer entries at the top, list the date and your name with email address. + +2009-july-06 UPDATE Jean-Pierre Charras +================================================================================ +++All: + Use a common class for markers in pcbnew and eeschema: + created a basic class called MARKER_BASE + class DRC_ITEM is also common to pcbnew and eeschema + class MARKER (in pcbnew) and class MARKER_SCH (eeschema) are derived + from this basic class. + The main goal is to use a common class for pcbnew and eeschema to handle + errors and to have similar dialogs + and have more comprehensive ERC messages errors in eeschema + This is a work in progress + + + 2009-july-05 UPDATE Jerry Jacobs Unscale( TrueSize ); + } + + wxPoint pos = m_Pos; + + int dx = refPos.x - pos.x; + int dy = refPos.y - pos.y; + + /* is refPos in the box: Marker size to right an bottom, + or size/2 to left or top */ + if( dx <= TrueSize.x && dy <= TrueSize.y && + dx >= -TrueSize.x/2 && dy >= -TrueSize.y/2 ) + return true; + else + return false; +} + + + +/**********************************************************************/ +void MARKER_BASE::DrawMarker( WinEDA_DrawPanel* panel, wxDC* DC, int DrawMode, + const wxPoint& offset ) +/**********************************************************************/ + +/* + * Trace un repere sur l'ecran au point de coordonnees PCB pos + * Le marqueur est defini par un tableau de 2 + (lig*col) elements: + * 1er element: dim nbre ligne + * 2er element: dim nbre col + * suite: lig * col elements a 0 ou 1 : si 1 mise a color du pixel + */ +{ + int ii, jj; + char* pt_bitmap = m_Bitmap; + + if( pt_bitmap == NULL ) return; + + GRSetDrawMode( DC, DrawMode ); + + wxPoint pos = m_Pos; + pos.x = GRMapX( pos.x ); + pos.y = GRMapY( pos.y ); + + /* Get the bitmap size */ + m_Size.x = *(pt_bitmap++); + m_Size.y = *(pt_bitmap++); + + /* Draw the bitmap */ + for( ii = 0; ii < m_Size.x; ii++ ) + { + for( jj = 0; jj < m_Size.y; jj++, pt_bitmap++ ) + { + if( *pt_bitmap ) + GRSPutPixel( &panel->m_ClipBox, DC, + pos.x + ii, pos.y + jj, m_Color ); + } + } +} diff --git a/eeschema/block.cpp b/eeschema/block.cpp index b12a7bbb33..a6ae0860b8 100644 --- a/eeschema/block.cpp +++ b/eeschema/block.cpp @@ -640,7 +640,7 @@ void MirrorOneStruct( SCH_ITEM* DrawStruct, wxPoint& Center ) SCH_COMPONENT* DrawLibItem; DrawSheetStruct* DrawSheet; Hierarchical_PIN_Sheet_Struct* DrawSheetLabel; - DrawMarkerStruct* DrawMarker; + MARKER_SCH* DrawMarker; DrawNoConnectStruct* DrawNoConnect; SCH_TEXT* DrawText; wxPoint px; @@ -692,7 +692,7 @@ void MirrorOneStruct( SCH_ITEM* DrawStruct, wxPoint& Center ) break; case DRAW_MARKER_STRUCT_TYPE: - DrawMarker = (DrawMarkerStruct*) DrawStruct; + DrawMarker = (MARKER_SCH*) DrawStruct; MirrorYPoint( DrawMarker->m_Pos, Center ); break; @@ -1198,7 +1198,7 @@ void MoveOneStruct( SCH_ITEM* DrawStruct, const wxPoint& move_vector ) SCH_COMPONENT* DrawLibItem; DrawSheetStruct* DrawSheet; Hierarchical_PIN_Sheet_Struct* DrawSheetLabel; - DrawMarkerStruct* DrawMarker; + MARKER_SCH* DrawMarker; DrawNoConnectStruct* DrawNoConnect; if( !DrawStruct ) @@ -1241,7 +1241,7 @@ void MoveOneStruct( SCH_ITEM* DrawStruct, const wxPoint& move_vector ) break; case DRAW_MARKER_STRUCT_TYPE: - DrawMarker = (DrawMarkerStruct*) DrawStruct; + DrawMarker = (MARKER_SCH*) DrawStruct; DrawMarker->m_Pos += move_vector; break; @@ -1337,7 +1337,7 @@ SCH_ITEM* DuplicateStruct( SCH_ITEM* DrawStruct ) break; case DRAW_MARKER_STRUCT_TYPE: - NewDrawStruct = ( (DrawMarkerStruct*) DrawStruct )->GenCopy(); + NewDrawStruct = ( (MARKER_SCH*) DrawStruct )->GenCopy(); break; case DRAW_NOCONNECT_STRUCT_TYPE: @@ -1672,7 +1672,7 @@ static void AddPickedItem( SCH_SCREEN* screen, wxPoint position ) case DRAW_MARKER_STRUCT_TYPE: #undef STRUCT - #define STRUCT ( (DrawMarkerStruct*) Struct ) + #define STRUCT ( (MARKER_SCH*) Struct ) if( Struct->m_Flags & SELECTED ) break; /* Already in list */ if( STRUCT->m_Pos != position ) diff --git a/eeschema/class_schematic_items.cpp b/eeschema/class_schematic_items.cpp index c4e1d1dbbf..4cc69f74a6 100644 --- a/eeschema/class_schematic_items.cpp +++ b/eeschema/class_schematic_items.cpp @@ -363,73 +363,33 @@ void DrawNoConnectStruct::Draw( WinEDA_DrawPanel* panel, wxDC* DC, /**************************/ -/* class DrawMarkerStruct */ +/* class MARKER_SCH */ /**************************/ -char marq_bitmap[] = -{ - 12, 12, 0, 0, /* Dimensions x et y, offsets x et y du bitmap de marqueurs*/ - YELLOW, /* Couleur */ - 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, /* bitmap: >= 1 : color, */ - 1, 1, 1, 0, 1, 0, 1, 1, 0, 0, 0, 0, /* 0 = notrace */ - 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, - 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, - 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, - 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, - 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 -}; -char marqERC_bitmap[] = -{ - 8, 8, 0, 0, /* Dimensions x et y , offsets x et y du bitmap de marqueurs*/ - -1, /* Color: -1 = couleur non pr�cis�e */ - 1, 1, 1, 1, 1, 0, 0, 0, - 1, 1, 1, 0, 1, 0, 0, 0, - 1, 1, 1, 1, 0, 0, 0, 0, - 1, 0, 1, 1, 1, 0, 0, 0, - 1, 1, 0, 1, 1, 1, 0, 0, - 0, 0, 0, 0, 1, 1, 1, 0, - 0, 0, 0, 0, 0, 1, 1, 1, - 0, 0, 0, 0, 0, 0, 1, 0, -}; - - -DrawMarkerStruct::DrawMarkerStruct( const wxPoint& pos, const wxString& text ) : - SCH_ITEM( NULL, DRAW_MARKER_STRUCT_TYPE ) -{ - m_Pos = pos; /* XY coordinates of marker. */ - m_Type = MARQ_UNSPEC; - m_MarkFlags = 0; // complements d'information - m_Comment = text; -} - - -DrawMarkerStruct::~DrawMarkerStruct() +MARKER_SCH::MARKER_SCH( const wxPoint& pos, const wxString& text ) : + SCH_ITEM( NULL, DRAW_MARKER_STRUCT_TYPE ), + MARKER_BASE(0, pos, text, pos) { } -DrawMarkerStruct* DrawMarkerStruct::GenCopy() +MARKER_SCH::~MARKER_SCH() { - DrawMarkerStruct* newitem = new DrawMarkerStruct( m_Pos, m_Comment ); +} - newitem->m_Type = m_Type; - newitem->m_MarkFlags = m_MarkFlags; + +MARKER_SCH* MARKER_SCH::GenCopy() +{ + MARKER_SCH* newitem = new MARKER_SCH( GetPos(), GetErrorText() ); + + newitem->SetMarkerType( GetMarkerType()); + newitem->SetErrorLevel( GetErrorLevel()); return newitem; } -wxString DrawMarkerStruct::GetComment() -{ - return m_Comment; -} - #if defined(DEBUG) @@ -440,10 +400,10 @@ wxString DrawMarkerStruct::GetComment() * of nesting of this object within the overall tree. * @param os The ostream& to output to. */ -void DrawMarkerStruct::Show( int nestLevel, std::ostream& os ) +void MARKER_SCH::Show( int nestLevel, std::ostream& os ) { // for now, make it look like XML: - NestedSpace( nestLevel, os ) << '<' << GetClass().Lower().mb_str() << m_Pos + NestedSpace( nestLevel, os ) << '<' << GetClass().Lower().mb_str() << GetPos() << "/>\n"; } @@ -456,13 +416,13 @@ void DrawMarkerStruct::Show( int nestLevel, std::ostream& os ) * @param aFile The FILE to write to. * @return bool - true if success writing else false. */ -bool DrawMarkerStruct::Save( FILE* aFile ) const +bool MARKER_SCH::Save( FILE* aFile ) const { bool success = true; - + wxString msg = GetErrorText(); if( fprintf( aFile, "Kmarq %c %-4d %-4d \"%s\" F=%X\n", - int(m_Type) + 'A', m_Pos.x, m_Pos.y, - CONV_TO_UTF8( m_Comment ), m_MarkFlags ) == EOF ) + GetMarkerType() + 'A', GetPos().x, GetPos().y, + CONV_TO_UTF8( msg ), GetErrorLevel() ) == EOF ) { success = false; } @@ -471,26 +431,22 @@ bool DrawMarkerStruct::Save( FILE* aFile ) const } -void DrawMarkerStruct::Draw( WinEDA_DrawPanel* panel, wxDC* DC, +void MARKER_SCH::Draw( WinEDA_DrawPanel* panel, wxDC* DC, const wxPoint& offset, int DrawMode, int Color ) { -#define WAR 1 // utilis� aussi dans erc.cpp +#define WAR 1 // see erc.cpp - if( m_Type == MARQ_ERC ) + if( GetMarkerType() == MARQ_ERC ) { - int color = Color; if( Color <= 0 ) { - color = (m_MarkFlags == WAR ) ? + Color = (GetErrorLevel() == WAR ) ? g_LayerDescr.LayerColor[LAYER_ERC_WARN] : g_LayerDescr.LayerColor[LAYER_ERC_ERR]; } - - Draw_Marqueur( panel, DC, m_Pos + offset, marqERC_bitmap, DrawMode, - color ); } - else - Draw_Marqueur( panel, DC, m_Pos + offset, marq_bitmap, DrawMode, Color ); + m_Color = Color; + DrawMarker( panel, DC, DrawMode, offset ); } diff --git a/eeschema/class_schematic_items.h b/eeschema/class_schematic_items.h index 67d137c8a8..56ce15dfd4 100644 --- a/eeschema/class_schematic_items.h +++ b/eeschema/class_schematic_items.h @@ -5,8 +5,9 @@ #ifndef CLASS_SCHEMATIC_ITEMS_H #define CLASS_SCHEMATIC_ITEMS_H +#include "class_marker_base.h" + #define DRAWJUNCTION_DIAMETER 32 /* Size (diameter) of junctions between wires */ -#define DRAWMARKER_SIZE 16 /* Rayon du symbole marqueur */ #define DRAWNOCONNECT_SIZE 48 /* Rayon du symbole No Connexion */ /* flags pour BUS ENTRY (bus to bus ou wire to bus */ @@ -89,32 +90,37 @@ public: }; -class DrawMarkerStruct : public SCH_ITEM /* marqueurs */ +class MARKER_SCH : public SCH_ITEM , public MARKER_BASE { public: - wxPoint m_Pos; /* XY coordinates of marker. */ - TypeMarker m_Type; - int m_MarkFlags; // complements d'information - wxString m_Comment; /* Texte (commentaireassocie eventuel */ - -public: - DrawMarkerStruct( const wxPoint& pos, const wxString& text ); - ~DrawMarkerStruct(); + MARKER_SCH( const wxPoint& aPos, const wxString& aText ); + ~MARKER_SCH(); virtual wxString GetClass() const { - return wxT( "DrawMarker" ); + return wxT( "MARKER_SCH" ); } - DrawMarkerStruct* GenCopy(); - wxString GetComment(); + MARKER_SCH* GenCopy(); virtual void Draw( WinEDA_DrawPanel* panel, wxDC* DC, const wxPoint& offset, int draw_mode, int Color = -1 ); + + wxString GetErrorText( ) const + { + wxString text = m_drc.GetMainText(); + return text; + } + + void SetErrorText( wxString aText) + { + SetData( m_drc.GetErrorCode(), GetPos(), aText, GetPos() ); + } + /** * Function Save - * writes the data structures for this object out to a FILE in "*.brd" + * writes the data structures for this object out to a FILE in "*.sch" * format. * @param aFile The FILE to write to. * @return bool - true if success writing else false. @@ -127,6 +133,14 @@ public: */ virtual int GetPenSize( ) { return 0; }; + /** Function HitTest + * @return true if the point aPosRef is within item area + * @param aPosRef = a wxPoint to test + */ + bool HitTest( const wxPoint& aPosRef ) + { + return HitTestMarker( aPosRef ); + } #if defined(DEBUG) void Show( int nestLevel, std::ostream& os ); #endif diff --git a/eeschema/controle.cpp b/eeschema/controle.cpp index c8173b0a5f..351794d3cd 100644 --- a/eeschema/controle.cpp +++ b/eeschema/controle.cpp @@ -125,11 +125,11 @@ SCH_ITEM* WinEDA_SchematicFrame:: SchematicGeneralLocateAndDisplay( const wxPoin DrawStruct = (SCH_ITEM*) PickStruct( refpoint, GetScreen(), MARKERITEM ); if( DrawStruct ) { - DrawMarkerStruct* Marker = (DrawMarkerStruct*) DrawStruct; - ii = Marker->m_Type; - Text = Marker->GetComment(); + MARKER_SCH* Marker = (MARKER_SCH*) DrawStruct; + Text = Marker->GetErrorText(); if( Text.IsEmpty() ) - Text = wxT( "NoComment" ); + Text = wxT( "???" ); + ii = Marker->GetMarkerType(); msg = NameMarqueurType[ii]; msg << wxT( " << " ) << Text; Affiche_Message( msg ); return DrawStruct; diff --git a/eeschema/delete.cpp b/eeschema/delete.cpp index a4700e6bc4..e4c73aa36e 100644 --- a/eeschema/delete.cpp +++ b/eeschema/delete.cpp @@ -493,7 +493,7 @@ void DeleteAllMarkers( int type ) { SCH_SCREEN* screen; SCH_ITEM * DrawStruct, * NextStruct; - DrawMarkerStruct* Marker; + MARKER_SCH* Marker; EDA_ScreenList ScreenList; @@ -506,8 +506,8 @@ void DeleteAllMarkers( int type ) continue; /* Marqueur trouve */ - Marker = (DrawMarkerStruct*) DrawStruct; - if( Marker->m_Type != type ) + Marker = (MARKER_SCH*) DrawStruct; + if( Marker->GetMarkerType() != type ) continue; /* Suppression du marqueur */ diff --git a/eeschema/eeredraw.cpp b/eeschema/eeredraw.cpp index 9a12b4b1b8..bd18679608 100644 --- a/eeschema/eeredraw.cpp +++ b/eeschema/eeredraw.cpp @@ -15,10 +15,6 @@ #include "general.h" #include "protos.h" - -extern char marq_bitmap[]; - - static EDA_BaseStruct* HighLightStruct = NULL; @@ -309,51 +305,3 @@ void DrawStructsInGhost( WinEDA_DrawPanel* panel, wxDC* DC, } } - - -/* - * Place un repere sur l'ecran au point de coordonnees PCB pos_X, pos_Y - * Le marqueur est defini par un tableau de 2 + (lig*col) elements: - * 1er element: dim nbre ligne - * 2er element: dim nbre col - * suite: lig * col elements a 0 ou 1 : si 1 mise a color du pixel - * - * copie la description du marqueur en current_marqueur (global) - */ -void Draw_Marqueur( WinEDA_DrawPanel* panel, wxDC* DC, - wxPoint pos, char* pt_bitmap, int DrawMode, int Color ) -{ - int px, py, color; - char ii, ii_max, jj, jj_max; - - if( pt_bitmap == NULL ) - pt_bitmap = marq_bitmap; - - px = GRMapX( pos.x ); - py = GRMapY( pos.y ); - - /* Lecture des dimensions */ - ii_max = *(pt_bitmap++); - jj_max = *(pt_bitmap++); - - /* lecture des offsets */ - px += *(pt_bitmap++); - py += *(pt_bitmap++); - - color = *(pt_bitmap++); - if( (Color > 0) ) - color = Color; - if( color < 0 ) - color = 0; - GRSetDrawMode( DC, DrawMode ); - - /* Trace du bitmap */ - for( ii = 0; ii < ii_max; ii++ ) - { - for( jj = 0; jj < jj_max; jj++, pt_bitmap++ ) - { - if( *pt_bitmap ) - GRSPutPixel( &panel->m_ClipBox, DC, px + ii, py + jj, color ); - } - } -} diff --git a/eeschema/erc.cpp b/eeschema/erc.cpp index ff92403b7c..e053844a82 100644 --- a/eeschema/erc.cpp +++ b/eeschema/erc.cpp @@ -26,10 +26,6 @@ */ -/* fonctions exportees */ - -/* fonctions importees */ - /* fonctions locales */ static bool WriteDiagnosticERC( const wxString& FullFileName ); static void Diagnose( WinEDA_DrawPanel* panel, @@ -217,12 +213,12 @@ void DIALOG_ERC::TestErc( wxTextCtrl* aMessagesList ) m_SheetName ) == 0 ) { /* Create a new marker type ERC error*/ - DrawMarkerStruct* Marker = - new DrawMarkerStruct( ( (DrawSheetStruct*) item_to_test )->m_Pos, + MARKER_SCH* Marker = + new MARKER_SCH( ( (DrawSheetStruct*) item_to_test )->m_Pos, _( "Duplicate Sheet name" ) ); - Marker->m_Type = MARQ_ERC; - Marker->m_MarkFlags = ERR; + Marker->SetMarkerType( MARQ_ERC ); + Marker->SetErrorLevel( ERR ); Marker->SetNext( Screen->EEDrawList ); Screen->EEDrawList = Marker; g_EESchemaVar.NbErrorErc++; @@ -356,15 +352,15 @@ void DIALOG_ERC::DisplayERC_MarkersList( ) continue; /* Marqueur trouve */ - DrawMarkerStruct* Marker = (DrawMarkerStruct*) DrawStruct; - if( Marker->m_Type != MARQ_ERC ) + MARKER_SCH* Marker = (MARKER_SCH*) DrawStruct; + if( Marker->GetMarkerType() != MARQ_ERC ) continue; /* Display diag */ wxString msg; msg.Printf(_("sheet %s: %s\n"), Sheet->PathHumanReadable().GetData(), - Marker->GetComment().GetData() ); + Marker->GetErrorText().GetData() ); m_MessagesList->AppendText( msg ); } } @@ -445,7 +441,7 @@ static void Diagnose( WinEDA_DrawPanel* aPanel, * if MinConn < 0: this is an error on labels */ { - DrawMarkerStruct* Marker = NULL; + MARKER_SCH* Marker = NULL; wxString DiagLevel; SCH_SCREEN* screen; int ii, jj; @@ -454,27 +450,30 @@ static void Diagnose( WinEDA_DrawPanel* aPanel, return; /* Creation du nouveau marqueur type Erreur ERC */ - Marker = new DrawMarkerStruct( aNetItemRef->m_Start, wxEmptyString ); + Marker = new MARKER_SCH( aNetItemRef->m_Start, wxEmptyString ); - Marker->m_Type = MARQ_ERC; - Marker->m_MarkFlags = WAR; + Marker->SetMarkerType( MARQ_ERC ); + Marker->SetErrorLevel( WAR ); screen = aNetItemRef->m_SheetList.LastScreen(); Marker->SetNext( screen->EEDrawList ); screen->EEDrawList = Marker; g_EESchemaVar.NbErrorErc++; g_EESchemaVar.NbWarningErc++; + wxString msg; if( aMinConn < 0 ) // Traitement des erreurs sur labels { if( (aNetItemRef->m_Type == NET_HIERLABEL) || (aNetItemRef->m_Type == NET_HIERBUSLABELMEMBER) ) { - Marker->m_Comment.Printf( _( "Warning HLabel %s not connected to SheetLabel" ), + msg.Printf( _( "Warning HLabel %s not connected to SheetLabel" ), aNetItemRef->m_Label->GetData() ); } else - Marker->m_Comment.Printf( _( "Warning SheetLabel %s not connected to HLabel" ), + msg.Printf( _( "Warning SheetLabel %s not connected to HLabel" ), aNetItemRef->m_Label->GetData() ); + + Marker->SetErrorText(msg); return; } @@ -493,8 +492,9 @@ static void Diagnose( WinEDA_DrawPanel* aPanel, { if( aMinConn == NOC ) /* 1 seul element dans le net */ { - Marker->m_Comment.Printf( _( "Warning Cmp %s, Pin %s (%s) Unconnected" ), + msg.Printf( _( "Warning Cmp %s, Pin %s (%s) Unconnected" ), cmp_ref.GetData(), string_pinnum.GetData(), MsgPinElectricType[ii] ); + Marker->SetErrorText(msg); return; } @@ -502,18 +502,20 @@ static void Diagnose( WinEDA_DrawPanel* aPanel, { if ( aNetItemRef->m_Type == NET_PIN && aNetItemRef->m_Link ) cmp_ref = ((SCH_COMPONENT*)aNetItemRef->m_Link)->GetRef( &aNetItemRef->m_SheetList ); - Marker->m_Comment.Printf( + msg.Printf( _( "Warning Cmp %s, Pin %s (%s) not driven (Net %d)" ), cmp_ref.GetData(), string_pinnum.GetData(), MsgPinElectricType[ii], aNetItemRef->GetNet() ); + Marker->SetErrorText(msg); return; } if( aDiag == UNC ) { - Marker->m_Comment.Printf( + msg.Printf( _( "Warning More than 1 Pin connected to UnConnect symbol @X=%f"", Y=%f""" ), - (float)Marker->m_Pos.x/1000, (float)Marker->m_Pos.y/1000); + (float)Marker->GetPos().x/1000, (float)Marker->GetPos().y/1000); + Marker->SetErrorText(msg); return; } } @@ -525,7 +527,7 @@ static void Diagnose( WinEDA_DrawPanel* aPanel, if( aDiag == ERR ) { DiagLevel = _( "Error" ); - Marker->m_MarkFlags = ERR; + Marker->SetErrorLevel( ERR ); g_EESchemaVar.NbWarningErc--; } @@ -535,11 +537,12 @@ static void Diagnose( WinEDA_DrawPanel* aPanel, alt_cmp = wxT("?"); if ( aNetItemTst->m_Type == NET_PIN && aNetItemTst->m_Link ) alt_cmp = ((SCH_COMPONENT*)aNetItemTst->m_Link)->GetRef( &aNetItemTst->m_SheetList ); - Marker->m_Comment.Printf( _("%s: Cmp %s, Pin %s (%s) connected to Cmp %s, Pin %s (%s) (net %d)" ), + msg.Printf( _("%s: Cmp %s, Pin %s (%s) connected to Cmp %s, Pin %s (%s) (net %d)" ), DiagLevel.GetData(), cmp_ref.GetData(), string_pinnum.GetData(), MsgPinElectricType[ii], alt_cmp.GetData(), alt_string_pinnum.GetData(),MsgPinElectricType[jj], aNetItemRef->GetNet() ); + Marker->SetErrorText(msg); } } @@ -641,8 +644,8 @@ static bool WriteDiagnosticERC( const wxString& FullFileName ) /* Create the Diagnostic file (.erc file) */ { - EDA_BaseStruct* DrawStruct; - DrawMarkerStruct* Marker; + SCH_ITEM* DrawStruct; + MARKER_SCH* Marker; char Line[256]; static FILE* OutErc; DrawSheetPath* Sheet; @@ -679,15 +682,15 @@ static bool WriteDiagnosticERC( const wxString& FullFileName ) continue; /* Marqueur trouve */ - Marker = (DrawMarkerStruct*) DrawStruct; - if( Marker->m_Type != MARQ_ERC ) + Marker = (MARKER_SCH*) DrawStruct; + if( Marker->GetMarkerType() != MARQ_ERC ) continue; /* Write diag marqueur */ msg.Printf( _( "ERC: %s (X= %2.3f inches, Y= %2.3f inches\n" ), - Marker->GetComment().GetData(), - (float) Marker->m_Pos.x / 1000, - (float) Marker->m_Pos.y / 1000 ); + Marker->GetErrorText().GetData(), + (float) Marker->GetPos().x / 1000, + (float) Marker->GetPos().y / 1000 ); fprintf( OutErc, "%s", CONV_TO_UTF8( msg ) ); } diff --git a/eeschema/find.cpp b/eeschema/find.cpp index d197a588f2..c5e5a2a38e 100644 --- a/eeschema/find.cpp +++ b/eeschema/find.cpp @@ -267,7 +267,7 @@ SCH_ITEM* WinEDA_SchematicFrame::FindMarker( int SearchType ) { DrawSheetPath* sheet, * FirstSheet = NULL; SCH_ITEM* DrawList, * FirstStruct = NULL, * Struct = NULL; - DrawMarkerStruct* Marker = NULL; + MARKER_SCH* Marker = NULL; int StartCount; bool NotFound; wxPoint firstpos, pos; @@ -292,7 +292,7 @@ SCH_ITEM* WinEDA_SchematicFrame::FindMarker( int SearchType ) { if( DrawList->Type() == DRAW_MARKER_STRUCT_TYPE ) { - Marker = (DrawMarkerStruct*) DrawList; + Marker = (MARKER_SCH*) DrawList; NotFound = FALSE; pos = Marker->m_Pos; if( FirstSheet == NULL ) /* First item found */ @@ -649,7 +649,7 @@ void WinEDA_FindFrame::LocatePartInLibs( wxCommandEvent& event ) Close(); return; } - + int nbitemsFound = 0; for( LibraryStruct* Lib = g_LibraryList; Lib != NULL; Lib = Lib->m_Pnext ) { diff --git a/eeschema/load_one_schematic_file.cpp b/eeschema/load_one_schematic_file.cpp index a4f6a13726..1a33239b98 100644 --- a/eeschema/load_one_schematic_file.cpp +++ b/eeschema/load_one_schematic_file.cpp @@ -49,7 +49,7 @@ bool WinEDA_SchematicFrame::LoadOneEEFile( SCH_SCREEN* screen, DrawPolylineStruct* PolylineStruct; EDA_DrawLineStruct* SegmentStruct; DrawBusEntryStruct* RaccordStruct; - DrawMarkerStruct* MarkerStruct; + MARKER_SCH* Marker; DrawNoConnectStruct* NoConnectStruct; int LineCount; wxString MsgDiag; /* Error and log messages */ @@ -335,22 +335,23 @@ at line %d, aborted" ), { char* text; char BufLine[1024]; - MarkerStruct = new DrawMarkerStruct( pos, wxEmptyString ); + Marker = new MARKER_SCH( pos, wxEmptyString ); ii = ReadDelimitedText( BufLine, Line, 256 ); - MarkerStruct->m_Type = (TypeMarker) ( (Name1[0] & 255) - 'A' ); - if( MarkerStruct->m_Type < 0 ) - MarkerStruct->m_Type = MARQ_UNSPEC; + int type = (TypeMarker) ( (Name1[0] & 255) - 'A' ); + if( type < 0 ) + type = MARQ_UNSPEC; + Marker->SetMarkerType( type ); if( ii ) - MarkerStruct->m_Comment = CONV_FROM_UTF8( BufLine ); + Marker->SetErrorText( CONV_FROM_UTF8( BufLine ) ); text = strstr( Line, " F=" ); if( text ) { sscanf( text + 3, "%X", &ii ); - MarkerStruct->m_MarkFlags = ii; + Marker->SetErrorLevel( ii ); } - MarkerStruct->SetNext( screen->EEDrawList ); - screen->EEDrawList = MarkerStruct; + Marker->SetNext( screen->EEDrawList ); + screen->EEDrawList = Marker; } break; diff --git a/eeschema/locate.cpp b/eeschema/locate.cpp index bd887e4374..aaca166f53 100644 --- a/eeschema/locate.cpp +++ b/eeschema/locate.cpp @@ -297,12 +297,10 @@ bool SnapPoint2( const wxPoint& aPosRef, int SearchMask, case DRAW_MARKER_STRUCT_TYPE: { #undef STRUCT - #define STRUCT ( (DrawMarkerStruct*) DrawList ) + #define STRUCT ( (MARKER_SCH*) DrawList ) if( !(SearchMask & MARKERITEM) ) break; - int size = (int) ( (DRAWMARKER_SIZE / aScaleFactor) / 2 ); - wxPoint dist = aPosRef - STRUCT->m_Pos; - if( (abs( dist.x ) <= size) && (abs( dist.y ) <= size) ) + if( STRUCT->HitTest(aPosRef) ) { LastSnappedStruct = DrawList; return TRUE; @@ -472,7 +470,7 @@ bool DrawStructInBox( int x1, int y1, int x2, int y2, SCH_ITEM* DrawStruct ) case DRAW_MARKER_STRUCT_TYPE: #undef STRUCT - #define STRUCT ( (DrawMarkerStruct*) DrawStruct ) + #define STRUCT ( (MARKER_SCH*) DrawStruct ) if( (STRUCT->m_Pos.x >= x1) && (STRUCT->m_Pos.x <= x2) && (STRUCT->m_Pos.y >= y1) && (STRUCT->m_Pos.y <= y2) ) return TRUE; diff --git a/eeschema/protos.h b/eeschema/protos.h index 50b982b426..838fdf1ce8 100644 --- a/eeschema/protos.h +++ b/eeschema/protos.h @@ -167,9 +167,6 @@ Hierarchical_PIN_Sheet_Struct * LocateAnyPinSheet(const wxPoint & RefPos, void DrawDanglingSymbol(WinEDA_DrawPanel * panel,wxDC * DC, const wxPoint & pos, int Color); -void Draw_Marqueur(WinEDA_DrawPanel * panel, wxDC * DC, - wxPoint pos, char* pt_bitmap, int DrawMode, int Color); - void DrawStructsInGhost(WinEDA_DrawPanel * panel, wxDC * DC, SCH_ITEM * DrawStruct, int dx, int dy ); void SetHighLightStruct(SCH_ITEM *HighLight); diff --git a/eeschema/schematic_undo_redo.cpp b/eeschema/schematic_undo_redo.cpp index f73e7f8251..4892bbf875 100644 --- a/eeschema/schematic_undo_redo.cpp +++ b/eeschema/schematic_undo_redo.cpp @@ -137,8 +137,8 @@ void SwapData( EDA_BaseStruct* Item ) case DRAW_MARKER_STRUCT_TYPE: #undef SOURCE #undef DEST - #define SOURCE ( (DrawMarkerStruct*) Item ) - #define DEST ( (DrawMarkerStruct*) image ) + #define SOURCE ( (MARKER_SCH*) Item ) + #define DEST ( (MARKER_SCH*) image ) EXCHG( SOURCE->m_Pos, DEST->m_Pos ); break; diff --git a/include/class_drc_item.h b/include/class_drc_item.h new file mode 100644 index 0000000000..4a5f81f751 --- /dev/null +++ b/include/class_drc_item.h @@ -0,0 +1,219 @@ +/* + * This program source code file is part of KICAD, a free EDA CAD application. + * + * Copyright (C) 2007 Dick Hollenbeck, dick@softplc.com + * Copyright (C) 2007 Kicad Developers, see change_log.txt for contributors. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, you may find one here: + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * or you may search the http://www.gnu.org website for the version 2 license, + * or you may write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#ifndef _CLASS_DRC_ITEM_H +#define _CLASS_DRC_ITEM_H + +/** + * Class DRC_ITEM + * is a holder for a DRC (in Pcbnew) or ERC (in Eeschema) error item. + * It is generated when two objects are too close (DRC) + * or two connected objects (pins) have incompatibleelectrical type (ERC). + * There are holders for information on two items. The + * information held is the board coordinate and the MenuText for each item. + * 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. + * Some errors involve only one item (item with an incorrect param) so + * m_hasSecondItem is set to false in this case. + */ +class DRC_ITEM +{ +protected: + int m_ErrorCode; ///< the error code's numeric value + wxString m_MainText; ///< text for the first BOARD_ITEM or SCH_ITEM + wxString m_AuxiliaryText; ///< text for the second BOARD_ITEM or SCH_ITEM + wxPoint m_MainPosition; ///< the location of the first (or main ) BOARD_ITEM or SCH_ITEM. This is also the position of the marker + wxPoint m_AuxiliaryPosition; ///< the location of the second BOARD_ITEM or SCH_ITEM + bool m_hasSecondItem; ///< true when 2 items create a DRC/ERC error, false if only one item + + +public: + + DRC_ITEM() + { + m_ErrorCode = 0; + m_hasSecondItem = false; + } + + + DRC_ITEM( int aErrorCode, + const wxString& aMainText, const wxString& bAuxiliaryText, + const wxPoint& aMainPos, const wxPoint& bAuxiliaryPos ) + { + SetData( aErrorCode, + aMainText, bAuxiliaryText, + aMainPos, bAuxiliaryPos ); + } + + + DRC_ITEM( int aErrorCode, + const wxString& aText, const wxPoint& aPos ) + { + SetData( aErrorCode, aText, aPos ); + } + + + void SetData( int aErrorCode, + const wxString& aMainText, const wxPoint& aMainPos ) + { + SetData( aErrorCode, + aMainText, aMainText, + aMainPos, aMainPos ); + m_hasSecondItem = false; + } + + + void SetData( int aErrorCode, + const wxString& aMainText, const wxString& bAuxiliaryText, + const wxPoint& aMainPos, const wxPoint& bAuxiliaryPos ) + { + m_ErrorCode = aErrorCode; + m_MainText = aMainText; + m_AuxiliaryText = bAuxiliaryText; + m_MainPosition = aMainPos; + m_AuxiliaryPosition = bAuxiliaryPos; + m_hasSecondItem = true; + } + + + bool HasSecondItem() const { return m_hasSecondItem; } + + /** acces to A and B texts + */ + wxString GetMainText() const { return m_MainText; } + wxString GetAuxiliaryText() const { return m_AuxiliaryText; } + + /** + * Function ShowHtml + * translates this object into a fragment of HTML suitable for the + * wxWidget's wxHtmlListBox class. + * @return wxString - the html text. + */ + wxString ShowHtml() const + { + wxString ret; + + if( m_hasSecondItem ) + { + // an html fragment for the entire message in the listbox. feel free + // to add color if you want: + ret.Printf( _( "ErrType(%d): %s
  • %s: %s
  • %s: %s
" ), + m_ErrorCode, + GetErrorText().GetData(), + ShowCoord( m_MainPosition ).GetData(), m_MainText.GetData(), + ShowCoord( m_AuxiliaryPosition ).GetData(), m_AuxiliaryText.GetData() ); + } + else + { + ret.Printf( _( "ErrType(%d): %s
  • %s: %s
" ), + m_ErrorCode, + GetErrorText().GetData(), + ShowCoord( m_MainPosition ).GetData(), m_MainText.GetData() ); + } + + return ret; + } + + + /** + * Function ShowReport + * translates this object into a text string suitable for saving + * to disk in a report. + * @return wxString - the simple multi-line report text. + */ + wxString ShowReport() const + { + wxString ret; + + if( m_hasSecondItem ) + { + ret.Printf( wxT( "ErrType(%d): %s\n %s: %s\n %s: %s\n" ), + m_ErrorCode, + GetErrorText().GetData(), + ShowCoord( m_MainPosition ).GetData(), m_MainText.GetData(), + ShowCoord( m_AuxiliaryPosition ).GetData(), m_AuxiliaryText.GetData() ); + } + else + { + ret.Printf( wxT( "ErrType(%d): %s\n %s: %s\n" ), + m_ErrorCode, + GetErrorText().GetData(), + ShowCoord( m_MainPosition ).GetData(), m_MainText.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_MainText; + } + + + const wxString& GetTextB() const + { + return m_AuxiliaryText; + } + + + const wxPoint& GetPointA() const + { + return m_MainPosition; + } + + + const wxPoint& GetPointB() const + { + return m_AuxiliaryPosition; + } + + + /** + * Function ShowCoord + * formats a coordinate or position to text. + * @param aPos The position to format + * @return wxString - The formated string + */ + static wxString ShowCoord( const wxPoint& aPos ); +}; + + +#endif // _CLASS_DRC_ITEM_H diff --git a/include/class_marker_base.h b/include/class_marker_base.h new file mode 100644 index 0000000000..2891fefd3d --- /dev/null +++ b/include/class_marker_base.h @@ -0,0 +1,147 @@ +/***************************************/ +/* Markers: used to show a drc problem */ +/***************************************/ + +#ifndef _CLASS_MARKER_BASE_H +#define _CLASS_MARKER_BASE_H + +#include "class_drc_item.h" + +class MARKER_BASE +{ +public: + wxPoint m_Pos; ///< position of the marker +protected: + char* m_Bitmap; ///< Shape (bitmap) + int m_MarkerType; ///< Can be used as a flag + int m_Color; ///< color + wxSize m_Size; ///< Size of the graphic symbol + + DRC_ITEM m_drc; + + void init(); + +public: + + MARKER_BASE( ); + + /** + * Constructor + * @param aErrorCode The categorizing identifier for an error + * @param aMarkerPos The position of the MARKER on the BOARD + * @param aText Text describing the first of two objects + * @param aPos The position of the first of two objects + * @param bText Text describing the second of the two conflicting objects + * @param bPos The position of the second of two objects + */ + MARKER_BASE( int aErrorCode, const wxPoint& aMarkerPos, + const wxString& aText, const wxPoint& aPos, + const wxString& bText, const wxPoint& bPos ); + /** + * Constructor + * @param aErrorCode The categorizing identifier for an error + * @param aMarkerPos The position of the MARKER on the BOARD + * @param aText Text describing the object + * @param aPos The position of the object + */ + MARKER_BASE( int aErrorCode, const wxPoint& aMarkerPos, + const wxString& aText, const wxPoint& aPos ); + + + ~MARKER_BASE(); + + /** Function DrawMarker + */ + void DrawMarker( WinEDA_DrawPanel* panel, wxDC* DC, int DrawMode, const wxPoint& offset ); + + + /** + * Function GetPos + * returns the position of this MARKER, const. + */ + const wxPoint& GetPos() const + { + return m_Pos; + } + + + /** Function to set/get error levels (warning, fatal ..) + * this value is stored in m_MarkerType + */ + void SetErrorLevel(int aErrorLevel ) + { + m_MarkerType &= 0xFF00; + m_MarkerType &= 0xFF; + m_MarkerType |= aErrorLevel << 8; + } + + int GetErrorLevel( ) const + { + return (m_MarkerType >> 8) & 0xFF; + } + + + /** Functions to set/get marker type (DRC, ERC, or other) + * this value is stored in m_MarkerType + */ + void SetMarkerType(int aMarkerType ) + { + m_MarkerType &= 0xFF; + aMarkerType &= 0xFF; + m_MarkerType |= aMarkerType; + } + + int GetMarkerType( ) const + { + return m_MarkerType & 0xFF; + } + + /** + * Function SetData + * fills in all the reportable data associated with a MARKER. + * @param aErrorCode The categorizing identifier for an error + * @param aMarkerPos The position of the MARKER on the BOARD + * @param aText Text describing the first of two objects + * @param aPos The position of the first of two objects + * @param bText Text describing the second of the two conflicting objects + * @param bPos The position of the second of two objects + */ + void SetData( int aErrorCode, const wxPoint& aMarkerPos, + const wxString& aText, const wxPoint& aPos, + const wxString& bText, const wxPoint& bPos ); + + /** + * Function SetData + * fills in all the reportable data associated with a MARKER. + * @param aErrorCode The categorizing identifier for an error + * @param aMarkerPos The position of the MARKER on the BOARD + * @param aText Text describing the object + * @param aPos The position of the object + */ + void SetData( int aErrorCode, const wxPoint& aMarkerPos, + const wxString& aText, const wxPoint& aPos ); + + + /** + * Function GetReporter + * returns the DRC_ITEM held within this MARKER so that its + * interface may be used. + * @return const& DRC_ITEM + */ + const DRC_ITEM& GetReporter() const + { + return m_drc; + } + + + /** + * Function HitTestMarker + * tests if the given wxPoint is within the bounds of this object. + * @param ref_pos A wxPoint to test + * @return bool - true if a hit, else false + */ + bool HitTestMarker( const wxPoint& ref_pos ); +}; + + +#endif // _CLASS_MARKER_BASE_H diff --git a/pcbnew/class_marker.cpp b/pcbnew/class_marker.cpp index f466787110..1d44d873a2 100644 --- a/pcbnew/class_marker.cpp +++ b/pcbnew/class_marker.cpp @@ -13,106 +13,40 @@ #include "class_marker.h" -/* Routines Locales : */ - - -/* Default bitmap shape for markers */ -static char Default_MarkerBitmap[] = -{ - 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, - 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, - 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, - 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, - 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 -}; - /*******************/ /* Classe MARKER */ /*******************/ -void MARKER::init() -{ - m_Bitmap = NULL; - m_Type = 0; - m_Color = RED; - m_Bitmap = Default_MarkerBitmap; - m_Size.x = Default_MarkerBitmap[0]; - m_Size.y = Default_MarkerBitmap[1]; -} - MARKER::MARKER( BOARD_ITEM* aParent ) : BOARD_ITEM( aParent, TYPE_MARKER ), - m_drc() + MARKER_BASE( ) { - init(); } MARKER::MARKER( int aErrorCode, const wxPoint& aMarkerPos, const wxString& aText, const wxPoint& aPos, const wxString& bText, const wxPoint& bPos ) : - BOARD_ITEM( NULL, TYPE_MARKER ) // parent set during BOARD::Add() -{ - init(); + BOARD_ITEM( NULL, TYPE_MARKER ), // parent set during BOARD::Add() + MARKER_BASE( aErrorCode, aMarkerPos, aText, aPos, bText, bPos ) - SetData( aErrorCode, aMarkerPos, - aText, aPos, - bText, bPos ); +{ } MARKER::MARKER( int aErrorCode, const wxPoint& aMarkerPos, const wxString& aText, const wxPoint& aPos ) : - BOARD_ITEM( NULL, TYPE_MARKER ) // parent set during BOARD::Add() + BOARD_ITEM( NULL, TYPE_MARKER ), // parent set during BOARD::Add() + MARKER_BASE( aErrorCode, aMarkerPos, aText, aPos ) { - init(); - - SetData( aErrorCode, aMarkerPos, - aText, aPos ); } /* Effacement memoire de la structure */ MARKER::~MARKER() { -#if defined(DEBUG) - printf("MARKER %p deleted\n", this ); -#endif } - -void MARKER::SetData( int aErrorCode, const wxPoint& aMarkerPos, - const wxString& aText, const wxPoint& aPos, - const wxString& bText, const wxPoint& bPos ) -{ - m_drc.SetData( aErrorCode, aMarkerPos, - aText, bText, - aPos, bPos ); - - // @todo: switch on error code to set error code specific color, and possibly bitmap. - m_Color = WHITE; -} - - -void MARKER::SetData( int aErrorCode, const wxPoint& aMarkerPos, - const wxString& aText, const wxPoint& aPos ) -{ - m_drc.SetData( aErrorCode, aMarkerPos, - aText, aPos ); - - // @todo: switch on error code to set error code specific color, and possibly bitmap. - m_Color = WHITE; -} - - /* supprime du chainage la structure Struct * les structures arrieres et avant sont chainees directement */ @@ -150,72 +84,3 @@ void MARKER::DisplayInfo( WinEDA_DrawFrame* frame ) text_pos = 25; Affiche_1_Parametre( frame, text_pos, txtA, txtB, DARKBROWN ); } - - -/**********************************************/ -bool MARKER::HitTest( const wxPoint& refPos ) -/**********************************************/ -{ - // the MARKER is 12 pixels by 12 pixels, but is not resized with zoom, so - // as zoom changes, the effective real size (in user units) of the MARKER changes. - - wxSize TrueSize = m_Size; - if ( ActiveScreen ) - { - ActiveScreen->Unscale( TrueSize ); - } - - wxPoint pos = GetPosition(); - - int dx = refPos.x - pos.x; - int dy = refPos.y - pos.y; - - /* is refPos in the box: Marker size to right an bottom, - or size/2 to left or top */ - if( dx <= TrueSize.x && dy <= TrueSize.y && - dx >= -TrueSize.x/2 && dy >= -TrueSize.y/2 ) - return true; - else - return false; -} - - - -/**********************************************************************/ -void MARKER::Draw( WinEDA_DrawPanel* panel, wxDC* DC, int DrawMode, const wxPoint& offset ) -/**********************************************************************/ - -/* - * Trace un repere sur l'ecran au point de coordonnees PCB pos - * Le marqueur est defini par un tableau de 2 + (lig*col) elements: - * 1er element: dim nbre ligne - * 2er element: dim nbre col - * suite: lig * col elements a 0 ou 1 : si 1 mise a color du pixel - */ -{ - int px, py; - int ii, jj; - char* pt_bitmap = m_Bitmap; - - if( pt_bitmap == NULL ) return; - - GRSetDrawMode( DC, DrawMode ); - - px = GRMapX( GetPosition().x ); - py = GRMapY( GetPosition().y ); - - /* Get the bitmap size */ - m_Size.x = *(pt_bitmap++); - m_Size.y = *(pt_bitmap++); - - /* Draw the bitmap */ - for( ii = 0; ii < m_Size.x; ii++ ) - { - for( jj = 0; jj < m_Size.y; jj++, pt_bitmap++ ) - { - if( *pt_bitmap ) - GRSPutPixel( &panel->m_ClipBox, DC, - px + ii, py + jj, m_Color ); - } - } -} diff --git a/pcbnew/class_marker.h b/pcbnew/class_marker.h index 7e3237002f..d17158f4c5 100644 --- a/pcbnew/class_marker.h +++ b/pcbnew/class_marker.h @@ -9,17 +9,8 @@ #include "drc_stuff.h" -class MARKER : public BOARD_ITEM +class MARKER : public BOARD_ITEM, public MARKER_BASE { -protected: - char* m_Bitmap; ///< Shape (bitmap) - int m_Type; - int m_Color; ///< color - wxSize m_Size; ///< Size of the graphic symbol - - DRC_ITEM m_drc; - - void init(); public: @@ -50,68 +41,35 @@ public: ~MARKER(); - void UnLink(); - void Draw( WinEDA_DrawPanel* panel, wxDC* DC, int DrawMode, const wxPoint& offset = ZeroOffset ); + void UnLink(); // Deprecated + /** Function Draw + */ + void Draw( WinEDA_DrawPanel* aPanel, wxDC* aDC, int aDrawMode, const wxPoint& aOffset = ZeroOffset ) + { + DrawMarker( aPanel, aDC, aDrawMode, aOffset ); + } + /** * Function GetPosition * returns the position of this MARKER. */ wxPoint& GetPosition() { - return (wxPoint&) m_drc.GetPosition(); + return (wxPoint&) m_Pos; } - /** - * Function GetPos - * returns the position of this MARKER, const. + /** Function HitTest + * @return true if the point aPosRef is within item area + * @param aPosRef = a wxPoint to test */ - const wxPoint& GetPos() const + bool HitTest( const wxPoint& aPosRef ) { - return m_drc.GetPosition(); + return HitTestMarker( aPosRef ); } - - /** - * Function SetData - * fills in all the reportable data associated with a MARKER. - * @param aErrorCode The categorizing identifier for an error - * @param aMarkerPos The position of the MARKER on the BOARD - * @param aText Text describing the first of two objects - * @param aPos The position of the first of two objects - * @param bText Text describing the second of the two conflicting objects - * @param bPos The position of the second of two objects - */ - void SetData( int aErrorCode, const wxPoint& aMarkerPos, - const wxString& aText, const wxPoint& aPos, - const wxString& bText, const wxPoint& bPos ); - - /** - * Function SetData - * fills in all the reportable data associated with a MARKER. - * @param aErrorCode The categorizing identifier for an error - * @param aMarkerPos The position of the MARKER on the BOARD - * @param aText Text describing the object - * @param aPos The position of the object - */ - void SetData( int aErrorCode, const wxPoint& aMarkerPos, - const wxString& aText, const wxPoint& aPos ); - - - /** - * Function GetReporter - * returns the DRC_ITEM held within this MARKER so that its - * interface may be used. - * @return const& DRC_ITEM - */ - const DRC_ITEM& GetReporter() const - { - return m_drc; - } - - /** * Function DisplayInfo * has knowledge about the frame and how and where to put status information @@ -133,15 +91,6 @@ public: // "pure" virtual-ness return true; } - - - /** - * Function HitTest - * tests if the given wxPoint is within the bounds of this object. - * @param ref_pos A wxPoint to test - * @return bool - true if a hit, else false - */ - bool HitTest( const wxPoint& ref_pos ); }; diff --git a/pcbnew/dialog_drc.cpp b/pcbnew/dialog_drc.cpp index 9f6458fce9..5121e1172b 100644 --- a/pcbnew/dialog_drc.cpp +++ b/pcbnew/dialog_drc.cpp @@ -313,7 +313,7 @@ void DIALOG_DRC_CONTROL::OnLeftDClickClearance( wxMouseEvent& event ) * ::wxPostEvent( GetEventHandler(), cmd ); */ - m_Parent->CursorGoto( item->GetPosition() ); + m_Parent->CursorGoto( item->GetPointA() ); // turn control over to m_Parent, hide this DIALOG_DRC_CONTROL window, // no destruction so we can preserve listbox cursor @@ -453,7 +453,7 @@ void DIALOG_DRC_CONTROL::OnLeftDClickUnconnected( wxMouseEvent& event ) const DRC_ITEM* item = m_UnconnectedListBox->GetItem( selection ); if( item ) { - m_Parent->CursorGoto( item->GetPosition() ); + m_Parent->CursorGoto( item->GetPointA() ); Hide(); diff --git a/pcbnew/drc.cpp b/pcbnew/drc.cpp index fdae0a2319..abb4fedb2d 100644 --- a/pcbnew/drc.cpp +++ b/pcbnew/drc.cpp @@ -346,7 +346,7 @@ void DRC::testUnconnected() D_PAD* padStart = rat->m_PadStart; D_PAD* padEnd = rat->m_PadEnd; - DRC_ITEM* uncItem = new DRC_ITEM( DRCE_UNCONNECTED_PADS, padStart->GetPosition(), + DRC_ITEM* uncItem = new DRC_ITEM( DRCE_UNCONNECTED_PADS, padStart->MenuText( m_pcb ), padEnd->MenuText( m_pcb ), padStart->GetPosition(), padEnd->GetPosition() ); diff --git a/pcbnew/drc_stuff.h b/pcbnew/drc_stuff.h index 3f24df8883..4a4f235ee0 100644 --- a/pcbnew/drc_stuff.h +++ b/pcbnew/drc_stuff.h @@ -27,6 +27,7 @@ #include "fctsys.h" +#include "class_marker_base.h" #define OK_DRC 0 @@ -64,199 +65,6 @@ #define DRCE_TOO_SMALL_VIA 28 ///< Too small via size #define DRCE_TOO_SMALL_MICROVIA 29 ///< Too small micro via size -/** - * Class DRC_ITEM - * is a holder for a DRC error item. It is generated when two objects are - * too close. There are holders for information on two items. The - * information held is the board coordinate and the MenuText for each item. - * 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. - * Some errors involve only one item (item with an incorrect param) so - * m_hasSecondItem is set to false in this case. - */ -class DRC_ITEM -{ -protected: - int m_ErrorCode; ///< the error code's numeric value - wxPoint m_Pos; ///< position of the issue - wxString m_AText; ///< text for the first BOARD_ITEM - wxString m_BText; ///< text for the second BOARD_ITEM - wxPoint m_APos; ///< the location of the first (or main ) BOARD_ITEM - wxPoint m_BPos; ///< the location of the second BOARD_ITEM - bool m_hasSecondItem; ///< true when 2 items create a DRC error, false if only one item - - -public: - - DRC_ITEM() : - m_ErrorCode( 0 ) - { - } - - - DRC_ITEM( int aErrorCode, const wxPoint& aIssuePos, - const wxString& aText, const wxString& bText, - const wxPoint& aPos, const wxPoint& bPos ) - { - SetData( aErrorCode, aIssuePos, - aText, bText, - aPos, bPos ); - } - - DRC_ITEM( int aErrorCode, const wxPoint& aIssuePos, - const wxString& aText, const wxPoint& aPos ) - { - SetData( aErrorCode, aIssuePos, aText, aPos ); - } - - - void SetData( int aErrorCode, const wxPoint& aIssuePos, - const wxString& aText, const wxPoint& aPos ) - { - SetData( aErrorCode, aIssuePos, - aText, aText, - aPos, aPos ); - m_hasSecondItem = false; - } - - void SetData( int aErrorCode, const wxPoint& aIssuePos, - const wxString& aText, const wxString& bText, - const wxPoint& aPos, const wxPoint& bPos ) - { - m_ErrorCode = aErrorCode; - m_Pos = aIssuePos; - m_AText = aText; - m_BText = bText; - m_APos = aPos; - m_BPos = bPos; - m_hasSecondItem = true; - } - - bool HasSecondItem() const { return m_hasSecondItem; } - - - /** - * Function ShowHtml - * translates this object into a fragment of HTML suitable for the - * wxWidget's wxHtmlListBox class. - * @return wxString - the html text. - */ - wxString ShowHtml() const - { - wxString ret; - - if( m_hasSecondItem ) - { - // an html fragment for the entire message in the listbox. feel free - // to add color if you want: - 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() ); - } - else - { - ret.Printf( _( "ErrType(%d): %s
  • %s: %s
" ), - m_ErrorCode, - GetErrorText().GetData(), - ShowCoord( m_APos ).GetData(), m_AText.GetData() ); - } - - return ret; - } - - - /** - * Function ShowReport - * translates this object into a text string suitable for saving - * to disk in a report. - * @return wxString - the simple multi-line report text. - */ - wxString ShowReport() const - { - wxString ret; - - if( m_hasSecondItem ) - { - 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() ); - } - else - { - ret.Printf( wxT( "ErrType(%d): %s\n %s: %s\n" ), - m_ErrorCode, - GetErrorText().GetData(), - ShowCoord( m_APos ).GetData(), m_AText.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 - * @return wxPoint& - the position of this report item within - * the drawing. - */ - const wxPoint& GetPosition() const - { - return m_Pos; - } - - - /** - * Function ShowCoord - * formats a coordinate or position to text. - * @param aPos The position to format - * @return wxString - The formated string - */ - static wxString ShowCoord( const wxPoint& aPos ); -}; - class WinEDA_DrawPanel; class MARKER;