From 3f970c85ce4cbf3d84b72ee102a8a07f17a6c04e Mon Sep 17 00:00:00 2001 From: charras Date: Mon, 25 May 2009 11:53:55 +0000 Subject: [PATCH] more cleanup and enhancements about rats nest (work in progress) --- common/CMakeLists.txt | 2 +- include/pcbstruct.h | 2 +- include/wxPcbStruct.h | 2 +- pcbnew/class_board.h | 2 +- pcbnew/{class_equipot.h => class_netinfo.h} | 424 +++++++++--------- ...ass_equipot.cpp => class_netinfo_item.cpp} | 30 +- pcbnew/editrack.cpp | 4 +- pcbnew/move_or_drag_track.cpp | 6 +- pcbnew/protos.h | 2 +- pcbnew/ratsnest.cpp | 283 +++++------- 10 files changed, 349 insertions(+), 408 deletions(-) rename pcbnew/{class_equipot.h => class_netinfo.h} (97%) rename pcbnew/{class_equipot.cpp => class_netinfo_item.cpp} (85%) diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index ca2c033b78..030ab1e94b 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -56,7 +56,7 @@ set(PCB_COMMON_SRCS ../pcbnew/class_drawsegment.cpp ../pcbnew/class_drc_item.cpp ../pcbnew/class_edge_mod.cpp - ../pcbnew/class_equipot.cpp + ../pcbnew/class_netinfo_item.cpp ../pcbnew/class_netinfolist.cpp ../pcbnew/class_marker.cpp ../pcbnew/class_mire.cpp diff --git a/include/pcbstruct.h b/include/pcbstruct.h index b30b22517b..20099de98f 100644 --- a/include/pcbstruct.h +++ b/include/pcbstruct.h @@ -250,7 +250,7 @@ public: #include "class_edge_mod.h" // Class for footprint graphic elements #include "class_text_mod.h" // Class for footprint fields #include "class_module.h" // Class for the footprint -#include "class_equipot.h" +#include "class_netinfo.h" // Class for nets /***********************************/ diff --git a/include/wxPcbStruct.h b/include/wxPcbStruct.h index 3240e6b52e..eaf7ffe873 100644 --- a/include/wxPcbStruct.h +++ b/include/wxPcbStruct.h @@ -286,7 +286,7 @@ public: void Build_Board_Ratsnest( wxDC* DC ); void DrawGeneralRatsnest( wxDC* DC, int net_code = 0 ); void trace_ratsnest_pad( wxDC* DC ); - int* build_ratsnest_pad( EDA_BaseStruct* ref, + void build_ratsnest_pad( BOARD_ITEM* ref, const wxPoint& refpos, bool init ); diff --git a/pcbnew/class_board.h b/pcbnew/class_board.h index 7d36042204..0a423631e9 100644 --- a/pcbnew/class_board.h +++ b/pcbnew/class_board.h @@ -7,7 +7,7 @@ #include "dlist.h" -#include "class_equipot.h" +#include "class_netinfo.h" class ZONE_CONTAINER; diff --git a/pcbnew/class_equipot.h b/pcbnew/class_netinfo.h similarity index 97% rename from pcbnew/class_equipot.h rename to pcbnew/class_netinfo.h index 76c9ce7f29..16ae1030a9 100644 --- a/pcbnew/class_equipot.h +++ b/pcbnew/class_netinfo.h @@ -1,212 +1,212 @@ -/************************/ -/* file class_equipot.h */ -/************************/ - -/* - * Classes to handle info on nets - */ - -#ifndef __CLASSES_NETINFO__ -#define __CLASSES_NETINFO__ - -// Forward declaration: -class NETINFO_ITEM; - - -/* Class RATSNEST_ITEM: describes a ratsnest line: a straight line connecting 2 pads */ - -class RATSNEST_ITEM -{ -private: - int m_NetCode; // netcode ( = 1.. n , 0 is the value used for not connected items) - -public: - int m_Status; // etat: voir defines précédents (CH_ ...) - D_PAD* m_PadStart; // pointer to the starting pad - D_PAD* m_PadEnd; // pointer to ending pad - int m_Lenght; // lenght of the line - - /** - * Function GetNet - * @return int - the net code. - */ - int GetNet() const - { - return m_NetCode; - } - - - void SetNet( int aNetCode ) - { - m_NetCode = aNetCode; - } - - /** function Draw - */ - void Draw( WinEDA_DrawPanel* panel, wxDC* DC, int aDrawMode, const wxPoint& offset ); - -}; - -/***************************************************************/ -/******************* class NETINFO *****************************/ -/***************************************************************/ - - -class NETINFO_LIST -{ -private: - BOARD* m_Parent; - -// boost::ptr_vector m_NetBuffer; // nets buffer list (name, design constraints .. - std::vector m_NetBuffer; // nets buffer list (name, design constraints .. -public: - NETINFO_LIST( BOARD* aParent ); - ~NETINFO_LIST(); - - /** Function GetItem - * @param aNetcode = netcode to identify a given NETINFO_ITEM - * @return a NETINFO_ITEM pointer to the selected NETINFO_ITEM by its netcode, or NULL if not found - */ - NETINFO_ITEM* GetItem( int aNetcode ); - - /** Function GetCount() - * @return the number of nets ( always >= 1 ) - * the first net is the "not connected" net - */ - unsigned GetCount() { return m_NetBuffer.size(); } - - /** - * Function Append - * adds \a aNewElement to the end of the list. - */ - void Append( NETINFO_ITEM* aNewElement ); - - /** Function Clear - * delete the list of nets (and free memory) - */ - void Clear(); - - /** Function BuildListOfNets - * initialize the list of NETINFO_ITEM m_NetBuffer - * The list is sorted by names. - */ - void BuildListOfNets(); -}; - -/** class NETINFO_ITEM - * @info This class handle the data relative to a given net - */ - -class NETINFO_ITEM -{ -private: - int m_NetCode; // this is a number equivalent to the net name - // Used for fast comparisons in rastnest and DRC computations. - wxString m_Netname; // Full net name like /mysheet/mysubsheet/vout used by eeschema - wxString m_ShortNetname; // short net name, like vout from /mysheet/mysubsheet/vout - - -public: - int m_NbNodes; // Pads count for this net - int m_NbLink; // Ratsnets count for this net - int m_NbNoconn; // Ratsnets remaining to route count - int m_ForceWidth; // specific width (O = default width) - std::vector m_ListPad; // List of pads connected to this net - RATSNEST_ITEM* m_RatsnestStart; // pointeur sur debut de liste ratsnests du net - RATSNEST_ITEM* m_RatsnestEnd; // pointeur sur fin de liste ratsnests du net - std::vector m_ListRatsnest; // List of Ratsnests for this net - - NETINFO_ITEM( BOARD_ITEM* aParent ); - ~NETINFO_ITEM(); - - - /* Readind and writing data on files */ - int ReadDescr( FILE* File, int* LineNum ); - - /** - * Function Save - * writes the data structures for this object out to a FILE in "*.brd" format. - * @param aFile The FILE to write to. - * @return bool - true if success writing else false. - */ - bool Save( FILE* aFile ) const; - - - /** function Draw - * @todo we actually could show a NET, simply show all the tracks and pads or net name on pad and vias - */ - void Draw( WinEDA_DrawPanel* panel, wxDC* DC, int aDrawMode, const wxPoint& offset ); - - - /** - * Function GetNet - * @return int - the netcode - */ - int GetNet() const { return m_NetCode; } - void SetNet( int aNetCode ) { m_NetCode = aNetCode; } - - int GetNodesCount() const { return m_ListPad.size(); } - - /** - * Function GetNetname - * @return const wxString * , a pointer to the full netname - */ - wxString GetNetname() const { return m_Netname; } - - /** - * Function GetShortNetname - * @return const wxString * , a pointer to the short netname - */ - wxString GetShortNetname() const { return m_ShortNetname; } - - /** - * Function SetNetname - * @param const wxString : the new netname - */ - void SetNetname( const wxString& aNetname ); - - -/** - * Function DisplayInfo - * has knowledge about the frame and how and where to put status information - * about this object into the frame's message panel. - * Is virtual from EDA_BaseStruct. - * @param frame A WinEDA_DrawFrame in which to print status information. - */ - void DisplayInfo( WinEDA_DrawFrame* frame ); -}; - - -/*****************************/ -/* flags for a RATSNEST_ITEM */ -/*****************************/ -#define CH_VISIBLE 1 /* affichage permanent demande */ -#define CH_UNROUTABLE 2 /* non route par l'autorouteur */ -#define CH_ROUTE_REQ 4 /* doit etre route par l'autorouteur */ -#define CH_ACTIF 8 /* chevelu non encore routé */ -#define LOCAL_RATSNEST_ITEM 0x8000 /* indique un chevelu reliant 2 pins d'un meme - * module pour le calcul des chevelus relatifs a 1 seul module */ - - -/****************************************************************/ -/* description d'un point de piste pour le suivi des connexions */ -/****************************************************************/ -#define START_ON_PAD 0x10 -#define END_ON_PAD 0x20 -#define START_ON_TRACK 0x40 -#define END_ON_TRACK 0x80 - - -/* Status bit (OR'ed bits) for class BOARD member .m_Status_Pcb */ -enum StatusPcbFlags { - LISTE_PAD_OK = 1, /* Pad list is Ok */ - LISTE_RATSNEST_ITEM_OK = 2, /* General Rastnest is Ok */ - RATSNEST_ITEM_LOCAL_OK = 4, /* current MODULE rastnest is Ok */ - CONNEXION_OK = 8, /* Bit indicant que la liste des connexions existe */ - NET_CODES_OK = 0x10, /* Bit indicant que les netcodes sont OK ( pas de modif - * de noms de net */ - DO_NOT_SHOW_GENERAL_RASTNEST = 0x20 /* Do not display the general rastnest (used in module moves) */ -}; - - -#endif // __CLASSES_NETINFO__ +/************************/ +/* file class_equipot.h */ +/************************/ + +/* + * Classes to handle info on nets + */ + +#ifndef __CLASSES_NETINFO__ +#define __CLASSES_NETINFO__ + +// Forward declaration: +class NETINFO_ITEM; + + +/* Class RATSNEST_ITEM: describes a ratsnest line: a straight line connecting 2 pads */ + +class RATSNEST_ITEM +{ +private: + int m_NetCode; // netcode ( = 1.. n , 0 is the value used for not connected items) + +public: + int m_Status; // etat: voir defines précédents (CH_ ...) + D_PAD* m_PadStart; // pointer to the starting pad + D_PAD* m_PadEnd; // pointer to ending pad + int m_Lenght; // lenght of the line + + /** + * Function GetNet + * @return int - the net code. + */ + int GetNet() const + { + return m_NetCode; + } + + + void SetNet( int aNetCode ) + { + m_NetCode = aNetCode; + } + + /** function Draw + */ + void Draw( WinEDA_DrawPanel* panel, wxDC* DC, int aDrawMode, const wxPoint& offset ); + +}; + +/***************************************************************/ +/******************* class NETINFO *****************************/ +/***************************************************************/ + + +class NETINFO_LIST +{ +private: + BOARD* m_Parent; + +// boost::ptr_vector m_NetBuffer; // nets buffer list (name, design constraints .. + std::vector m_NetBuffer; // nets buffer list (name, design constraints .. +public: + NETINFO_LIST( BOARD* aParent ); + ~NETINFO_LIST(); + + /** Function GetItem + * @param aNetcode = netcode to identify a given NETINFO_ITEM + * @return a NETINFO_ITEM pointer to the selected NETINFO_ITEM by its netcode, or NULL if not found + */ + NETINFO_ITEM* GetItem( int aNetcode ); + + /** Function GetCount() + * @return the number of nets ( always >= 1 ) + * the first net is the "not connected" net + */ + unsigned GetCount() { return m_NetBuffer.size(); } + + /** + * Function Append + * adds \a aNewElement to the end of the list. + */ + void Append( NETINFO_ITEM* aNewElement ); + + /** Function Clear + * delete the list of nets (and free memory) + */ + void Clear(); + + /** Function BuildListOfNets + * initialize the list of NETINFO_ITEM m_NetBuffer + * The list is sorted by names. + */ + void BuildListOfNets(); +}; + +/** class NETINFO_ITEM + * @info This class handle the data relative to a given net + */ + +class NETINFO_ITEM +{ +private: + int m_NetCode; // this is a number equivalent to the net name + // Used for fast comparisons in rastnest and DRC computations. + wxString m_Netname; // Full net name like /mysheet/mysubsheet/vout used by eeschema + wxString m_ShortNetname; // short net name, like vout from /mysheet/mysubsheet/vout + + +public: + int m_NbNodes; // Pads count for this net + int m_NbLink; // Ratsnets count for this net + int m_NbNoconn; // Ratsnets remaining to route count + int m_ForceWidth; // specific width (O = default width) + std::vector m_ListPad; // List of pads connected to this net + RATSNEST_ITEM* m_RatsnestStart; // pointeur sur debut de liste ratsnests du net + RATSNEST_ITEM* m_RatsnestEnd; // pointeur sur fin de liste ratsnests du net + std::vector m_ListRatsnest; // List of Ratsnests for this net + + NETINFO_ITEM( BOARD_ITEM* aParent ); + ~NETINFO_ITEM(); + + + /* Readind and writing data on files */ + int ReadDescr( FILE* File, int* LineNum ); + + /** + * Function Save + * writes the data structures for this object out to a FILE in "*.brd" format. + * @param aFile The FILE to write to. + * @return bool - true if success writing else false. + */ + bool Save( FILE* aFile ) const; + + + /** function Draw + * @todo we actually could show a NET, simply show all the tracks and pads or net name on pad and vias + */ + void Draw( WinEDA_DrawPanel* panel, wxDC* DC, int aDrawMode, const wxPoint& offset ); + + + /** + * Function GetNet + * @return int - the netcode + */ + int GetNet() const { return m_NetCode; } + void SetNet( int aNetCode ) { m_NetCode = aNetCode; } + + int GetNodesCount() const { return m_ListPad.size(); } + + /** + * Function GetNetname + * @return const wxString * , a pointer to the full netname + */ + wxString GetNetname() const { return m_Netname; } + + /** + * Function GetShortNetname + * @return const wxString * , a pointer to the short netname + */ + wxString GetShortNetname() const { return m_ShortNetname; } + + /** + * Function SetNetname + * @param const wxString : the new netname + */ + void SetNetname( const wxString& aNetname ); + + +/** + * Function DisplayInfo + * has knowledge about the frame and how and where to put status information + * about this object into the frame's message panel. + * Is virtual from EDA_BaseStruct. + * @param frame A WinEDA_DrawFrame in which to print status information. + */ + void DisplayInfo( WinEDA_DrawFrame* frame ); +}; + + +/*****************************/ +/* flags for a RATSNEST_ITEM */ +/*****************************/ +#define CH_VISIBLE 1 /* affichage permanent demande */ +#define CH_UNROUTABLE 2 /* non route par l'autorouteur */ +#define CH_ROUTE_REQ 4 /* doit etre route par l'autorouteur */ +#define CH_ACTIF 8 /* chevelu non encore routé */ +#define LOCAL_RATSNEST_ITEM 0x8000 /* indique un chevelu reliant 2 pins d'un meme + * module pour le calcul des chevelus relatifs a 1 seul module */ + + +/****************************************************************/ +/* description d'un point de piste pour le suivi des connexions */ +/****************************************************************/ +#define START_ON_PAD 0x10 +#define END_ON_PAD 0x20 +#define START_ON_TRACK 0x40 +#define END_ON_TRACK 0x80 + + +/* Status bit (OR'ed bits) for class BOARD member .m_Status_Pcb */ +enum StatusPcbFlags { + LISTE_PAD_OK = 1, /* Pad list is Ok */ + LISTE_RATSNEST_ITEM_OK = 2, /* General Rastnest is Ok */ + RATSNEST_ITEM_LOCAL_OK = 4, /* current MODULE rastnest is Ok */ + CONNEXION_OK = 8, /* Bit indicant que la liste des connexions existe */ + NET_CODES_OK = 0x10, /* Bit indicant que les netcodes sont OK ( pas de modif + * de noms de net */ + DO_NOT_SHOW_GENERAL_RASTNEST = 0x20 /* Do not display the general rastnest (used in module moves) */ +}; + + +#endif // __CLASSES_NETINFO__ diff --git a/pcbnew/class_equipot.cpp b/pcbnew/class_netinfo_item.cpp similarity index 85% rename from pcbnew/class_equipot.cpp rename to pcbnew/class_netinfo_item.cpp index fa22f90cd9..436ae6af57 100644 --- a/pcbnew/class_equipot.cpp +++ b/pcbnew/class_netinfo_item.cpp @@ -3,14 +3,14 @@ /*************************************************************************/ #include "fctsys.h" -#include "wxstruct.h" +#include "class_drawpanel.h" #include "common.h" #include "kicad_string.h" #include "pcbnew.h" /*********************************************************/ -/* class NETINFO_ITEM: hand data relative to a given net */ +/* class NETINFO_ITEM: handle data relative to a given net */ /*********************************************************/ /* Constructor */ @@ -24,7 +24,7 @@ NETINFO_ITEM::NETINFO_ITEM( BOARD_ITEM* aParent ) } -/* destructot */ +/* destructor */ NETINFO_ITEM::~NETINFO_ITEM() { @@ -107,9 +107,8 @@ void NETINFO_ITEM::SetNetname( const wxString & aNetname ) /** function Draw (TODO) - * we actually could show a NET, simply show all the tracks and pads or net name on pad and vias */ -void NETINFO_ITEM::Draw( WinEDA_DrawPanel* panel, wxDC* DC, int aDrawMode, const wxPoint& offset ) +void NETINFO_ITEM::Draw( WinEDA_DrawPanel* panel, wxDC* DC, int aDrawMode, const wxPoint& aOffset ) { } @@ -169,3 +168,24 @@ void NETINFO_ITEM::Draw( WinEDA_DrawPanel* panel, wxDC* DC, int aDrawMode, const valeur_param( (int) lengthnet, txt ); Affiche_1_Parametre( frame, 60, _( "Net Length" ), txt, RED ); } + + +/***********************/ +/* class RATSNEST_ITEM */ +/***********************/ + +/** function Draw + * Draws a line from the starting pad to the ending pad + */ +void RATSNEST_ITEM::Draw( WinEDA_DrawPanel* panel, wxDC* DC, int aDrawMode, const wxPoint& aOffset ) +{ + EDA_Colors color = (EDA_Colors) g_DesignSettings.m_RatsnestColor; + if ( (m_Status & LOCAL_RATSNEST_ITEM) ) + color = YELLOW; + GRLine( &panel->m_ClipBox, DC, m_PadStart->m_Pos.x + aOffset.x, + m_PadStart->m_Pos.y + aOffset.y, + m_PadEnd->m_Pos.x + aOffset.x, + m_PadEnd->m_Pos.y + aOffset.y, + 0, color ); +} + diff --git a/pcbnew/editrack.cpp b/pcbnew/editrack.cpp index c7e8e6321e..ad78c4c87a 100644 --- a/pcbnew/editrack.cpp +++ b/pcbnew/editrack.cpp @@ -86,7 +86,7 @@ TRACK* WinEDA_PcbFrame::Begin_Route( TRACK* aTrack, wxDC* DC ) D_PAD* pt_pad = NULL; TRACK* TrackOnStartPoint = NULL; int masquelayer = g_TabOneLayerMask[((PCB_SCREEN*)GetScreen())->m_Active_Layer]; - EDA_BaseStruct* LockPoint; + BOARD_ITEM* LockPoint; wxPoint pos = GetScreen()->m_Curseur; static int InitialTrackWidthValue; /* first track segment width. @@ -457,7 +457,7 @@ void WinEDA_PcbFrame::End_Route( TRACK* aTrack, wxDC* DC ) * ceci contribue a la reduction du temps de calcul */ /* Accrochage de la fin de la piste */ - EDA_BaseStruct* LockPoint = LocateLockPoint( GetBoard(), pos, masquelayer ); + BOARD_ITEM* LockPoint = LocateLockPoint( GetBoard(), pos, masquelayer ); if( LockPoint ) /* La fin de la piste est sur un PAD */ { diff --git a/pcbnew/move_or_drag_track.cpp b/pcbnew/move_or_drag_track.cpp index 6779efdaec..74ac9a2d67 100644 --- a/pcbnew/move_or_drag_track.cpp +++ b/pcbnew/move_or_drag_track.cpp @@ -924,7 +924,7 @@ bool WinEDA_PcbFrame::PlaceDraggedTrackSegment( TRACK* Track, wxDC* DC ) Track->SetState( EDIT, OFF ); Track->Draw( DrawPanel, DC, draw_mode ); - /* Tracage des segments dragges */ + /* Draw ddragged tracks */ pt_drag = g_DragSegmentList; for( ; pt_drag; pt_drag = pt_drag->Pnext ) { @@ -954,10 +954,10 @@ bool WinEDA_PcbFrame::PlaceDraggedTrackSegment( TRACK* Track, wxDC* DC ) /************************************************************************/ -EDA_BaseStruct* LocateLockPoint( BOARD* Pcb, wxPoint pos, int LayerMask ) +BOARD_ITEM* LocateLockPoint( BOARD* Pcb, wxPoint pos, int LayerMask ) /************************************************************************/ -/* Routine trouvant le point " d'accrochage " d'une extremite de piste. +/* Routine trouvant le point "d'accrochage" d'une extremite de piste. * Ce point peut etre un PAD ou un autre segment de piste * Retourne: * - pointeur sur ce PAD ou: diff --git a/pcbnew/protos.h b/pcbnew/protos.h index b6764d73fc..e2ca2771e7 100644 --- a/pcbnew/protos.h +++ b/pcbnew/protos.h @@ -353,7 +353,7 @@ void MasqueAttributs( int* masque_set, int* masque_clr ); /* DUPLTRAC.CPP */ /***************/ -EDA_BaseStruct* LocateLockPoint( BOARD* Pcb, wxPoint pos, int LayerMask ); +BOARD_ITEM* LocateLockPoint( BOARD* Pcb, wxPoint pos, int LayerMask ); /* Routine trouvant le point " d'accrochage " d'une extremite de piste. * Ce point peut etre un PAD ou un autre segment de piste diff --git a/pcbnew/ratsnest.cpp b/pcbnew/ratsnest.cpp index bf815d9e7b..4adc145293 100644 --- a/pcbnew/ratsnest.cpp +++ b/pcbnew/ratsnest.cpp @@ -13,20 +13,20 @@ #include "protos.h" -extern char* adr_lowmem; /* adresse de base memoire de calcul disponible */ +extern char* adr_lowmem; /* adresse de base memoire de calcul disponible */ /* exported variables */ -RATSNEST_ITEM* g_pt_chevelu; -RATSNEST_ITEM* local_liste_chevelu; // Buffer address for local ratsnest +RATSNEST_ITEM* g_pt_chevelu; +RATSNEST_ITEM* local_liste_chevelu; // Buffer address for local ratsnest // (ratnest relative to one footprint while moving it -int nb_local_chevelu; // link count (active ratnest count) for the footprint beeing moved +int nb_local_chevelu; // link count (active ratnest count) for the footprint beeing moved /* local variables */ -static int nb_pads_ref; // node count (node = pad with a net code) for the footprint beeing moved -static int nb_pads_externes; // Connected pads count ( pads which are +static int nb_pads_ref; // node count (node = pad with a net code) for the footprint beeing moved +static int nb_pads_externes; // Connected pads count ( pads which are // in other footprints and connected to a pad of the footprint beeing moved -static bool DisplayRastnestInProgress; // Enable the display of the ratsnest during the ratsnest computations +static bool DisplayRastnestInProgress; // Enable the display of the ratsnest during the ratsnest computations /* Note about the ratsnest computation: * Building the general ratsnest: @@ -211,8 +211,8 @@ static int gen_rats_block_to_block( WinEDA_DrawPanel* DrawPanel, wxDC* DC, * @return blocks not connected count */ { - int dist_min, current_dist; - int current_num_block = 1; + int dist_min, current_dist; + int current_num_block = 1; D_PAD** pt_liste_pad_tmp; D_PAD** pt_liste_pad_aux; D_PAD** pt_liste_pad_block1 = NULL; @@ -285,17 +285,13 @@ static int gen_rats_block_to_block( WinEDA_DrawPanel* DrawPanel, wxDC* DC, /* Create the new ratsnet */ (*nblinks)++; g_pt_chevelu->SetNet( (*pt_liste_pad)->GetNet() ); - g_pt_chevelu->m_Status = CH_ACTIF | CH_VISIBLE; - g_pt_chevelu->m_Lenght = dist_min; + g_pt_chevelu->m_Status = CH_ACTIF | CH_VISIBLE; + g_pt_chevelu->m_Lenght = dist_min; g_pt_chevelu->m_PadStart = *pt_liste_pad; g_pt_chevelu->m_PadEnd = *pt_liste_pad_tmp; if( DisplayRastnestInProgress && DC ) - GRLine( &DrawPanel->m_ClipBox, DC, g_pt_chevelu->m_PadStart->m_Pos.x, - g_pt_chevelu->m_PadStart->m_Pos.y, - g_pt_chevelu->m_PadEnd->m_Pos.x, - g_pt_chevelu->m_PadEnd->m_Pos.y, - 0, g_DesignSettings.m_RatsnestColor ); + g_pt_chevelu->Draw( DrawPanel, DC, GR_XOR, wxPoint( 0, 0 ) ); g_pt_chevelu++; } @@ -331,17 +327,14 @@ static int gen_rats_pad_to_pad( WinEDA_DrawPanel* DrawPanel, wxDC* DC, * last block number used */ { - int dist_min, current_dist; + int dist_min, current_dist; D_PAD** pt_liste_pad_tmp; D_PAD** pt_liste_pad_aux; D_PAD** pt_start_liste; - D_PAD* ref_pad, * pad; + D_PAD* ref_pad, * pad; pt_start_liste = pt_liste_pad; - if( DC ) - GRSetDrawMode( DC, GR_XOR ); - for( ; pt_liste_pad < pt_limite; pt_liste_pad++ ) { ref_pad = *pt_liste_pad; @@ -394,19 +387,14 @@ static int gen_rats_pad_to_pad( WinEDA_DrawPanel* DrawPanel, wxDC* DC, (*nblinks)++; g_pt_chevelu->SetNet( ref_pad->GetNet() ); - g_pt_chevelu->m_Status = CH_ACTIF | CH_VISIBLE; - g_pt_chevelu->m_Lenght = dist_min; + g_pt_chevelu->m_Status = CH_ACTIF | CH_VISIBLE; + g_pt_chevelu->m_Lenght = dist_min; g_pt_chevelu->m_PadStart = ref_pad; g_pt_chevelu->m_PadEnd = pad; if( DisplayRastnestInProgress && DC ) - { - GRLine( &DrawPanel->m_ClipBox, DC, g_pt_chevelu->m_PadStart->m_Pos.x, - g_pt_chevelu->m_PadStart->m_Pos.y, - g_pt_chevelu->m_PadEnd->m_Pos.x, - g_pt_chevelu->m_PadEnd->m_Pos.y, - 0, g_DesignSettings.m_RatsnestColor ); - } + g_pt_chevelu->Draw( DrawPanel, DC, GR_XOR, wxPoint( 0, 0 ) ); + g_pt_chevelu++; } } @@ -477,7 +465,8 @@ void WinEDA_BasePcbFrame::Build_Board_Ratsnest( wxDC* DC ) if( m_Pcb->m_NbNodes == 0 ) return; /* pas de connexions utiles */ - m_Pcb->m_Ratsnest = (RATSNEST_ITEM*) MyZMalloc( (m_Pcb->m_NbNodes + 10 ) * sizeof(RATSNEST_ITEM) ); + m_Pcb->m_Ratsnest = + (RATSNEST_ITEM*) MyZMalloc( (m_Pcb->m_NbNodes + 10 ) * sizeof(RATSNEST_ITEM) ); if( m_Pcb->m_Ratsnest == NULL ) return; @@ -505,10 +494,10 @@ void WinEDA_BasePcbFrame::Build_Board_Ratsnest( wxDC* DC ) /* Compute the ratsnest relative to the current net */ /* a - first pass : create the blocks from not already in block pads */ - D_PAD ** pstart = &net->m_ListPad[0]; - D_PAD ** pend = pstart + net->m_ListPad.size(); - int icnt = gen_rats_pad_to_pad( DrawPanel, DC, pstart, pend, - num_block, &noconn ); + D_PAD** pstart = &net->m_ListPad[0]; + D_PAD** pend = pstart + net->m_ListPad.size(); + int icnt = gen_rats_pad_to_pad( DrawPanel, DC, pstart, pend, + num_block, &noconn ); /* b - blocks connection (Iteration) */ while( icnt > 1 ) @@ -530,19 +519,13 @@ void WinEDA_BasePcbFrame::Build_Board_Ratsnest( wxDC* DC ) // erase the ratsnest displayed on screen if needed RATSNEST_ITEM* Chevelu = m_Pcb->m_Ratsnest; - if( DC ) - GRSetDrawMode( DC, GR_XOR ); - for( int ii = m_Pcb->GetNumRatsnests(); ii > 0 && Chevelu; ii--, Chevelu++ ) { if( !g_Show_Ratsnest ) Chevelu->m_Status &= ~CH_VISIBLE; if( DC ) - GRLine( &DrawPanel->m_ClipBox, DC, - Chevelu->m_PadStart->m_Pos.x, Chevelu->m_PadStart->m_Pos.y, - Chevelu->m_PadEnd->m_Pos.x, Chevelu->m_PadEnd->m_Pos.y, - 0, g_DesignSettings.m_RatsnestColor ); + Chevelu->Draw( DrawPanel, DC, GR_XOR, wxPoint( 0, 0 ) ); } } @@ -569,7 +552,7 @@ void WinEDA_BasePcbFrame::DrawGeneralRatsnest( wxDC* DC, int net_code ) * @param netcode if > 0, Display only the ratsnest relative to the correponding net_code */ { - int ii; + int ii; RATSNEST_ITEM* Chevelu; if( (m_Pcb->m_Status_Pcb & LISTE_RATSNEST_ITEM_OK) == 0 ) @@ -583,19 +566,13 @@ void WinEDA_BasePcbFrame::DrawGeneralRatsnest( wxDC* DC, int net_code ) if( Chevelu == NULL ) return; - GRSetDrawMode( DC, GR_XOR ); for( ii = m_Pcb->GetNumRatsnests(); ii > 0; Chevelu++, ii-- ) { if( ( Chevelu->m_Status & (CH_VISIBLE | CH_ACTIF) ) != (CH_VISIBLE | CH_ACTIF) ) continue; if( (net_code <= 0) || ( net_code == Chevelu->GetNet() ) ) - { - GRLine( &DrawPanel->m_ClipBox, DC, - Chevelu->m_PadStart->m_Pos.x, Chevelu->m_PadStart->m_Pos.y, - Chevelu->m_PadEnd->m_Pos.x, Chevelu->m_PadEnd->m_Pos.y, - 0, g_DesignSettings.m_RatsnestColor ); - } + Chevelu->Draw( DrawPanel, DC, GR_XOR, wxPoint( 0, 0 ) ); } } @@ -621,7 +598,7 @@ static int tst_rats_block_to_block( WinEDA_DrawPanel* DrawPanel, wxDC* DC, NETIN * @return blocks not connected count */ { - int current_num_block, min_block; + int current_num_block, min_block; RATSNEST_ITEM* chevelu, * min_chevelu; /* Search a link from a block to an other block */ @@ -644,7 +621,7 @@ static int tst_rats_block_to_block( WinEDA_DrawPanel* DrawPanel, wxDC* DC, NETIN * we must set its status to ACTIVE and merge the 2 blocks */ min_chevelu->m_Status |= CH_ACTIF; - current_num_block = min_chevelu->m_PadStart->GetSubRatsnest(); + current_num_block = min_chevelu->m_PadStart->GetSubRatsnest(); min_block = min_chevelu->m_PadEnd->GetSubRatsnest(); if( min_block > current_num_block ) @@ -688,7 +665,7 @@ static int tst_rats_pad_to_pad( WinEDA_DrawPanel* DrawPanel, wxDC* DC, * @return new block number */ { - D_PAD* pad_start, * pad_end; + D_PAD* pad_start, * pad_end; RATSNEST_ITEM* chevelu; for( chevelu = start_rat_list; chevelu < end_rat_list; chevelu++ ) @@ -732,14 +709,14 @@ void WinEDA_BasePcbFrame::Tst_Ratsnest( wxDC* DC, int ref_netcode ) * if ref_netcode == 0, test all nets, else test only ref_netcode */ { - RATSNEST_ITEM* chevelu; - D_PAD* pad; - int net_code; - NETINFO_ITEM* net; + RATSNEST_ITEM* chevelu; + D_PAD* pad; + int net_code; + NETINFO_ITEM* net; if( m_Pcb->m_Pads.size() == 0 ) return; - if ( (m_Pcb->m_Status_Pcb & LISTE_RATSNEST_ITEM_OK) == 0 ) + if( (m_Pcb->m_Status_Pcb & LISTE_RATSNEST_ITEM_OK) == 0 ) Build_Board_Ratsnest( DC ); for( net_code = 1; ; net_code++ ) @@ -760,21 +737,21 @@ void WinEDA_BasePcbFrame::Tst_Ratsnest( wxDC* DC, int ref_netcode ) num_block = MAX( num_block, subnet ); } - for( chevelu = net->m_RatsnestStart; chevelu < net->m_RatsnestEnd; chevelu++ ) + for( chevelu = net->m_RatsnestStart; chevelu < net->m_RatsnestEnd; chevelu++ ) { - chevelu->m_Status &= ~CH_ACTIF; + chevelu->m_Status &= ~CH_ACTIF; } /* a - tst connection between pads */ int ii = tst_rats_pad_to_pad( DrawPanel, DC, num_block, - net->m_RatsnestStart, net->m_RatsnestEnd ); + net->m_RatsnestStart, net->m_RatsnestEnd ); /* b - test connexion between blocks (Iteration) */ while( ii > 1 ) { ii = tst_rats_block_to_block( DrawPanel, DC, net ); } - } + } m_Pcb->m_NbNoconnect = 0; RATSNEST_ITEM* Chevelu = m_Pcb->m_Ratsnest; @@ -823,21 +800,21 @@ char* WinEDA_BasePcbFrame::build_ratsnest_module( wxDC* DC, MODULE* Module ) * The ratsnest section must be computed for each new position */ { - D_PAD** pt_liste_pad; - D_PAD** pt_liste_ref; - D_PAD** pt_liste_generale; - D_PAD* pad_ref; - D_PAD* pad_externe; - D_PAD** pt_liste_pad_limite; - D_PAD** pt_start_liste; - D_PAD** pt_end_liste; - int ii, jj; + D_PAD** pt_liste_pad; + D_PAD** pt_liste_ref; + D_PAD** pt_liste_generale; + D_PAD* pad_ref; + D_PAD* pad_externe; + D_PAD** pt_liste_pad_limite; + D_PAD** pt_start_liste; + D_PAD** pt_end_liste; + int ii, jj; RATSNEST_ITEM* local_chevelu; - static RATSNEST_ITEM* pt_fin_int_chevelu; // End list for "internal" ratsnest - static int nb_int_chevelu; // "internal" ratsnest count - int current_net_code; - int increment, distance; // variables de calcul de ratsnest - int pad_pos_X, pad_pos_Y; // True pad position according to the current footprint position + static RATSNEST_ITEM* pt_fin_int_chevelu; // End list for "internal" ratsnest + static int nb_int_chevelu; // "internal" ratsnest count + int current_net_code; + int increment, distance; // variables de calcul de ratsnest + int pad_pos_X, pad_pos_Y; // True pad position according to the current footprint position if( (GetBoard()->m_Status_Pcb & LISTE_PAD_OK) == 0 ) @@ -983,8 +960,8 @@ calcul_chevelu_ext: pt_liste_ref = (D_PAD**) adr_lowmem; pad_ref = *pt_liste_ref; - current_net_code = pad_ref->GetNet(); - local_chevelu->m_Lenght = 0x7FFFFFFF; + current_net_code = pad_ref->GetNet(); + local_chevelu->m_Lenght = 0x7FFFFFFF; local_chevelu->m_Status = 0; increment = 0; for( ii = 0; ii < nb_pads_ref; ii++ ) @@ -998,7 +975,7 @@ calcul_chevelu_ext: nb_local_chevelu++; local_chevelu++; } increment = 0; - current_net_code = pad_ref->GetNet(); + current_net_code = pad_ref->GetNet(); local_chevelu->m_Lenght = 0x7FFFFFFF; } @@ -1025,7 +1002,7 @@ calcul_chevelu_ext: local_chevelu->m_PadStart = pad_ref; local_chevelu->m_PadEnd = pad_externe; local_chevelu->SetNet( pad_ref->GetNet() ); - local_chevelu->m_Lenght = distance; + local_chevelu->m_Lenght = distance; local_chevelu->m_Status = 0; increment = 1; @@ -1039,7 +1016,7 @@ calcul_chevelu_ext: local_chevelu++; } - return (char*)(local_chevelu + 1); /* the struct pointed by local_chevelu is used + return (char*) (local_chevelu + 1); /* the struct pointed by local_chevelu is used * in temporary computations, so we skip it */ } @@ -1054,7 +1031,7 @@ void WinEDA_BasePcbFrame::trace_ratsnest_module( wxDC* DC ) */ { RATSNEST_ITEM* local_chevelu; - int ii; + int ii; if( DC == NULL ) return; @@ -1064,34 +1041,15 @@ void WinEDA_BasePcbFrame::trace_ratsnest_module( wxDC* DC ) local_chevelu = local_liste_chevelu; ii = nb_local_chevelu; - GRSetDrawMode( DC, GR_XOR ); - while( ii-- > 0 ) { - if( local_chevelu->m_Status & LOCAL_RATSNEST_ITEM ) - { - GRLine( &DrawPanel->m_ClipBox, DC, - local_chevelu->m_PadStart->m_Pos.x - g_Offset_Module.x, - local_chevelu->m_PadStart->m_Pos.y - g_Offset_Module.y, - local_chevelu->m_PadEnd->m_Pos.x - g_Offset_Module.x, - local_chevelu->m_PadEnd->m_Pos.y - g_Offset_Module.y, - 0, YELLOW ); - } - else - { - GRLine( &DrawPanel->m_ClipBox, DC, - local_chevelu->m_PadStart->m_Pos.x - g_Offset_Module.x, - local_chevelu->m_PadStart->m_Pos.y - g_Offset_Module.y, - local_chevelu->m_PadEnd->m_Pos.x, - local_chevelu->m_PadEnd->m_Pos.y, - 0, g_DesignSettings.m_RatsnestColor ); - } + local_chevelu->Draw( DrawPanel, DC, GR_XOR, wxPoint( 0, 0 ) ); local_chevelu++; } } -/** +/* * construction de la liste en mode de calcul rapide pour affichage * en temps reel du chevelu d'un pad lors des tracés d'une piste démarrant * sur ce pad. @@ -1102,61 +1060,53 @@ void WinEDA_BasePcbFrame::trace_ratsnest_module( wxDC* DC ) * init (flag) * = 0 : mise a jour des chevelu * <> 0: creation de la liste - * retourne: adresse memoire disponible */ -/* Used by build_ratsnest_pad(): sort function by link lenght (manathan distance)*/ -static int sort_by_localnetlength( const void* o1, const void* o2 ) +/* Buffer to store pads coordinates when creating a track. + * these pads are members of the net + * and when the mouse is moved, the g_MaxLinksShowed links to neightbors are drawn + */ +static std::vector s_RatsnestMouseToPads; +static wxPoint s_CursorPos; // Coordinate of the moving point (mouse cursor and end of current track segment) + +/* Used by build_ratsnest_pad(): sort function by link lenght (manhattan distance)*/ +static bool sort_by_localnetlength( const wxPoint& ref, const wxPoint& compare ) { - int* ref = (int*) o1; - int* compare = (int*) o2; + wxPoint deltaref = ref - s_CursorPos; + wxPoint deltacmp = compare - s_CursorPos; - int* org = (int*) adr_lowmem; // ref coordinate (todo : change for a betted code: used an external wxPoint variable) - int ox = *org++; - int oy = *org++; - int lengthref, lengthcmp; + // = distance between ref coordinate and pad ref + int lengthref = abs( deltaref.x ) + abs( deltaref.y ); - lengthref = abs( *ref - ox ); - ref++; + // distance between ref coordinate and the other pad + int lengthcmp = abs( deltacmp.x ) + abs( deltacmp.y ); - lengthref += abs( *ref - oy ); // = distance between ref coordinate and pad ref - - lengthcmp = abs( *compare - ox ); - - compare++; - - lengthcmp += abs( *compare - oy ); // = distance between ref coordinate and the other pad - - return lengthref - lengthcmp; + return lengthref < lengthcmp; } /****************************************************************************************/ -int* WinEDA_BasePcbFrame::build_ratsnest_pad( EDA_BaseStruct* ref, +void WinEDA_BasePcbFrame::build_ratsnest_pad( BOARD_ITEM* ref, const wxPoint& refpos, bool init ) /****************************************************************************************/ { - int ii; - int* pt_coord, * base_data; - int current_net_code = 0, conn_number = 0; - D_PAD** padlist; - D_PAD* pad_ref = NULL; + int current_net_code = 0, conn_number = 0; + D_PAD* pad_ref = NULL; if( ( (m_Pcb->m_Status_Pcb & LISTE_RATSNEST_ITEM_OK) == 0 ) - || ( (m_Pcb->m_Status_Pcb & LISTE_PAD_OK) == 0 ) ) + || ( (m_Pcb->m_Status_Pcb & LISTE_PAD_OK) == 0 ) || ( (m_Pcb->m_Status_Pcb & NET_CODES_OK) == 0 ) ) { - nb_local_chevelu = 0; - return NULL; + s_RatsnestMouseToPads.clear(); + return; } - base_data = pt_coord = (int*) adr_lowmem; - local_liste_chevelu = (RATSNEST_ITEM*) pt_coord; + s_CursorPos = refpos; if( init ) { - nb_local_chevelu = 0; + s_RatsnestMouseToPads.clear(); if( ref == NULL ) - return NULL; + return; switch( ref->Type() ) { @@ -1180,41 +1130,26 @@ int* WinEDA_BasePcbFrame::build_ratsnest_pad( EDA_BaseStruct* ref, } if( current_net_code <= 0 ) - return NULL; + return; - *pt_coord++ = refpos.x; - *pt_coord++ = refpos.y; - - if( m_Pcb->m_Ratsnest == NULL ) - return NULL; - - padlist = &m_Pcb->m_Pads[0]; - for( ii = 0; ii < (int) m_Pcb->m_Pads.size(); padlist++, ii++ ) + NETINFO_ITEM * net = m_Pcb->FindNet(current_net_code); + if ( net == NULL ) + return; + + // Create a list of pads candidates ( pads not already connected to the current track: + for( unsigned ii = 0; ii < net->m_ListPad.size(); ii++ ) { - D_PAD* pad = *padlist; - if( pad->GetNet() != current_net_code ) - continue; - + D_PAD* pad = net->m_ListPad[ii]; if( pad == pad_ref ) continue; if( !pad->GetSubNet() || (pad->GetSubNet() != conn_number) ) - { - *pt_coord = pad->m_Pos.x; pt_coord++; - *pt_coord = pad->m_Pos.y; pt_coord++; - nb_local_chevelu++; - } + s_RatsnestMouseToPads.push_back( pad->m_Pos ); } } /* end if Init */ - else if( nb_local_chevelu ) - { - *pt_coord = refpos.x; - *(pt_coord + 1) = refpos.y; - } - qsort( base_data + 2, nb_local_chevelu, 2 * sizeof(int), - sort_by_localnetlength ); - return pt_coord; + if( s_RatsnestMouseToPads.size() > 1) + sort( s_RatsnestMouseToPads.begin(), s_RatsnestMouseToPads.end(), sort_by_localnetlength ); } @@ -1226,35 +1161,21 @@ void WinEDA_BasePcbFrame::trace_ratsnest_pad( wxDC* DC ) * Displays a "ratsnest" during track creation */ { - int* pt_coord; - int ii; - int refX, refY; - if( DC == NULL ) return; - if( (m_Pcb->m_Status_Pcb & LISTE_RATSNEST_ITEM_OK) == 0 ) + if( s_RatsnestMouseToPads.size() == 0) return; - if( nb_local_chevelu == 0 ) - return; - - if( local_liste_chevelu == NULL ) - return; - - pt_coord = (int*) local_liste_chevelu; - - refX = *pt_coord++; - refY = *pt_coord++; - + GRSetDrawMode( DC, GR_XOR ); - for( ii = 0; ii < nb_local_chevelu; ii++ ) + for( int ii = 0; ii < (int)s_RatsnestMouseToPads.size(); ii++ ) { if( ii >= g_MaxLinksShowed ) break; - GRLine( &DrawPanel->m_ClipBox, DC, refX, refY, *pt_coord, *(pt_coord + 1), + GRLine( &DrawPanel->m_ClipBox, DC, s_CursorPos.x, s_CursorPos.y, + s_RatsnestMouseToPads[ii].x, s_RatsnestMouseToPads[ii].y, 0, YELLOW ); - pt_coord += 2; } }