Commit 3668f4cc authored by jean-pierre charras's avatar jean-pierre charras

Pcbnew: cleanup functions: now, cleanup uses same algorithm as connectivity...

Pcbnew: cleanup functions: now, cleanup uses same algorithm as connectivity calculations to detect pads connections, and is faster.
therefore tracks which have a end point inside a pad, but not necessaryexactly  to the pad position are seen as connected, and are no more removed.
Side effect: reconnect to pads option is removed, because it is useless.
TODO: use this algorithm in drag functions.
Minor other fixes
parent 5aec4604
......@@ -55,6 +55,13 @@
double s_HerscheyScaleFactor = HERSHEY_SCALE_FACTOR;
/* Helper function for texts with over bar
*/
int OverbarPositionY( int size_v, int thickness )
{
return KiROUND( ( (double) size_v * 1.1 ) + ( (double) thickness * 1.5 ) );
}
/**
* Function GetPensizeForBold
* @return the "best" value for a pen size to draw/plot a bold text
......@@ -68,7 +75,7 @@ int GetPenSizeForBold( int aTextSize )
/**
* Function Clamp_Text_PenSize
*As a rule, pen width should not be >1/4em, otherwise the character
* As a rule, pen width should not be >1/4em, otherwise the character
* will be cluttered up in its own fatness
* so pen width max is aSize/4 for bold text, and aSize/6 for normal text
* The "best" pen width is aSize/5 for bold texts,
......@@ -219,14 +226,6 @@ static void DrawGraphicTextPline(
}
/* Helper function for texts with over bar
*/
static int overbar_position( int size_v, int thickness )
{
return KiROUND( ( (double) size_v * 26 * s_HerscheyScaleFactor ) + ( (double) thickness * 1.5 ) );
}
/**
* Function DrawGraphicText
* Draw a graphic text (like module texts)
......@@ -271,7 +270,6 @@ void DrawGraphicText( EDA_DRAW_PANEL* aPanel,
int dx, dy; // Draw coordinate for segments to draw. also used in some other calculation
wxPoint current_char_pos; // Draw coordinates for the current char
wxPoint overbar_pos; // Start point for the current overbar
int overbars; // Number of ~ seen
int overbar_italic_comp; // Italic compensation for overbar
EDA_RECT* clipBox; // Clip box used in basic draw functions
......@@ -400,7 +398,7 @@ void DrawGraphicText( EDA_DRAW_PANEL* aPanel,
if( aItalic )
{
overbar_italic_comp = overbar_position( size_v, aWidth ) / 8;
overbar_italic_comp = OverbarPositionY( size_v, aWidth ) / 8;
if( italic_reverse )
{
overbar_italic_comp = -overbar_italic_comp;
......@@ -411,7 +409,7 @@ void DrawGraphicText( EDA_DRAW_PANEL* aPanel,
overbar_italic_comp = 0;
};
overbars = 0;
int overbars = 0; // Number of ~ seen
ptr = 0; /* ptr = text index */
while( ptr < char_count )
{
......@@ -420,12 +418,12 @@ void DrawGraphicText( EDA_DRAW_PANEL* aPanel,
/* Found an overbar, adjust the pointers */
overbars++;
if( overbars % 2 )
if( overbars & 1 ) // odd overbars count
{
/* Starting the overbar */
overbar_pos = current_char_pos;
overbar_pos.x += overbar_italic_comp;
overbar_pos.y -= overbar_position( size_v, aWidth );
overbar_pos.y -= OverbarPositionY( size_v, aWidth );
RotatePoint( &overbar_pos, aPos, aOrient );
}
else
......@@ -434,7 +432,7 @@ void DrawGraphicText( EDA_DRAW_PANEL* aPanel,
coord[0] = overbar_pos;
overbar_pos = current_char_pos;
overbar_pos.x += overbar_italic_comp;
overbar_pos.y -= overbar_position( size_v, aWidth );
overbar_pos.y -= OverbarPositionY( size_v, aWidth );
RotatePoint( &overbar_pos, aPos, aOrient );
coord[1] = overbar_pos;
/* Plot the overbar segment */
......@@ -516,7 +514,7 @@ void DrawGraphicText( EDA_DRAW_PANEL* aPanel,
/* Close the last overbar */
coord[0] = overbar_pos;
overbar_pos = current_char_pos;
overbar_pos.y -= overbar_position( size_v, aWidth );
overbar_pos.y -= OverbarPositionY( size_v, aWidth );
RotatePoint( &overbar_pos, aPos, aOrient );
coord[1] = overbar_pos;
/* Plot the overbar segment */
......
......@@ -44,6 +44,7 @@
extern void IncrementLabelMember( wxString& name );
extern int OverbarPositionY( int size_v, int thickness );
/* Names of sheet label types. */
......@@ -273,19 +274,19 @@ void SCH_TEXT::Rotate( wxPoint aPosition )
switch( GetOrientation() )
{
case 0: /* horizontal text */
case 0: // horizontal text
dy = m_Size.y;
break;
case 1: /* Vert Orientation UP */
case 1: // Vert Orientation UP
dy = 0;
break;
case 2: /* invert horizontal text*/
case 2: // invert horizontal text
dy = m_Size.y;
break;
case 3: /* Vert Orientation BOTTOM */
case 3: // Vert Orientation BOTTOM
dy = 0;
break;
......@@ -1241,8 +1242,14 @@ void SCH_GLOBALLABEL::CreateGraphicShape( std::vector <wxPoint>& aPoints, const
// Create outline shape : 6 points
int x = symb_len + linewidth + 3;
// 50% more for negation bar
int y = KiROUND( (double) HalfSize * 1.5 + (double) linewidth + 3.0 );
// Use negation bar Y position to calculate full vertical size
#define Y_CORRECTION 1.22
// Note: this factor is due to the fact the negation bar Y position
// does not give exactly the full Y size of text
// and is experimentally set to this value
int y = KiROUND( OverbarPositionY( HalfSize, linewidth ) * Y_CORRECTION );
// add room for line thickness and space between top of text and graphic shape
y += linewidth;
// Starting point(anchor)
aPoints.push_back( wxPoint( 0, 0 ) );
......
This diff is collapsed.
......@@ -34,11 +34,10 @@
#include <macros.h>
#include <wxBasePcbFrame.h>
#include <class_track.h>
#include <class_board.h>
#include <pcbnew.h>
// Helper classes to handle connection points
#include <connect.h>
extern void Merge_SubNets_Connected_By_CopperAreas( BOARD* aPcb );
extern void Merge_SubNets_Connected_By_CopperAreas( BOARD* aPcb, int aNetcode );
......@@ -47,204 +46,6 @@ extern void Merge_SubNets_Connected_By_CopperAreas( BOARD* aPcb, int aNetcode );
static void RebuildTrackChain( BOARD* pcb );
// A helper class to handle connection points (i.e. candidates) for tracks
class CONNECTED_POINT
{
private:
BOARD_CONNECTED_ITEM * m_item; // a link to the parent item (track, via or pad)
wxPoint m_point; // the connection point
public:
CONNECTED_POINT( TRACK * aTrack, const wxPoint & aPoint)
{
m_item = aTrack;
m_point = aPoint;
}
CONNECTED_POINT( D_PAD * aPad, const wxPoint & aPoint)
{
m_item = aPad;
m_point = aPoint;
}
TRACK * GetTrack() const
{
return m_item->Type() != PCB_PAD_T ? (TRACK*) m_item : NULL ;
}
D_PAD * GetPad() const
{
return m_item->Type() == PCB_PAD_T ? (D_PAD*) m_item : NULL;
}
const wxPoint & GetPoint() const { return m_point; }
};
// A helper class to handle connections calculations:
class CONNECTIONS
{
private:
std::vector <TRACK*> m_connected; // List of connected tracks/vias
// to a given track or via
std::vector <CONNECTED_POINT> m_candidates; // List of points to test
// (end points of tracks or vias location )
BOARD * m_brd; // the master board.
const TRACK * m_firstTrack; // The first track used to build m_Candidates
const TRACK * m_lastTrack; // The last track used to build m_Candidates
std::vector<D_PAD*> m_sortedPads; // list of sorted pads by X (then Y) coordinate
public:
CONNECTIONS( BOARD * aBrd );
~CONNECTIONS() {};
/** Function BuildPadsList
* Fills m_sortedPads with all pads that be connected to tracks
* pads are sorted by > then Y coordinates to allow fast binary search in list
* @param aNetcode = net code to use to filter pads
* if aNetcode < 0, all pads will be put in list (default)
*/
void BuildPadsList( int aNetcode = -1 );
/**
* @return the pads list used in connections calculations
*/
std::vector<D_PAD*>& GetPadsList() { return m_sortedPads; }
/**
* Function Build_CurrNet_SubNets_Connections
* should be called after a track change (delete or add a track):
* Connections to pads and to tracks are recalculated
* If a track is deleted, the other pointers to pads do not change.
* When a new track is added in track list, its pointers to pads are already initialized
* Builds the subnets inside a net (tracks from aFirstTrack to aFirstTrack).
* subnets are clusters of pads and tracks that are connected together.
* When all tracks are created relative to the net, there is only a cluster
* when not tracks there are a cluster per pad
* @param aFirstTrack = first track of the given net
* @param aLastTrack = last track of the given net
* @param aNetcode = the netcode of the given net
*/
void Build_CurrNet_SubNets_Connections( TRACK* aFirstTrack, TRACK* aLastTrack, int aNetcode );
/**
* Function BuildTracksCandidatesList
* Fills m_Candidates with all connecting points (track ends or via location)
* with tracks from aBegin to aEnd.
* if aEnd == NULL, uses all tracks from aBegin
*/
void BuildTracksCandidatesList( TRACK * aBegin, TRACK * aEnd = NULL);
/**
* Function BuildPadsCandidatesList
* Fills m_Candidates with all pads connecting points (pads position)
* m_sortedPads must be built
*/
void BuildPadsCandidatesList();
/**
* function SearchConnectedTracks
* Fills m_Connected with tracks/vias connected to aTrack
* @param aTrack = track or via to use as reference
*/
int SearchConnectedTracks( const TRACK * aTrack );
/**
* Function GetConnectedTracks
* Copy m_Connected that contains the list of tracks connected
* calculated by SearchConnectedTracks
* in aTrack->m_TracksConnected
* @param aTrack = track or via to fill with connected tracks
*/
void GetConnectedTracks(TRACK * aTrack)
{
aTrack->m_TracksConnected = m_connected;
}
/**
* function SearchConnectionsPadsToIntersectingPads
* Explores the list of pads and adds to m_PadsConnected member
* of each pad pads connected to
* Here, connections are due to intersecting pads, not tracks
* m_sortedPads must be initialized
*/
void SearchConnectionsPadsToIntersectingPads();
/**
* function SearchTracksConnectedToPads
* Explores the list of pads.
* Adds to m_PadsConnected member of each track the pad(s) connected to
* Adds to m_TracksConnected member of each pad the track(s) connected to
* D_PAD::m_TracksConnected is cleared before adding items
* TRACK::m_PadsConnected is not cleared
*/
void SearchTracksConnectedToPads();
/**
* function CollectItemsNearTo
* Used by SearchTracksConnectedToPads
* Fills aList with pads near to aPosition
* near means aPosition to pad position <= aDistMax
* @param aList = list to fill
* @param aPosition = aPosition to use as reference
* @param aDistMax = dist max from aPosition to a candidate to select it
*/
void CollectItemsNearTo( std::vector<CONNECTED_POINT*>& aList,
const wxPoint& aPosition, int aDistMax );
/**
* Function Propagate_SubNets
* Test a list of tracks, to create or propagate a sub netcode to pads and
* segments connected together.
* The track list must be sorted by nets, and all segments
* from m_firstTrack to m_lastTrack have the same net.
* When 2 items are connected (a track to a pad, or a track to an other track),
* they are grouped in a cluster.
* For pads, this is the .m_physical_connexion member which is a cluster identifier
* For tracks, this is the .m_Subnet member which is a cluster identifier
* For a given net, if all tracks are created, there is only one cluster.
* but if not all tracks are created, there are more than one cluster,
* and some ratsnests will be left active.
*/
void Propagate_SubNets();
private:
/**
* function searchEntryPointInCandidatesList
* Search an item in m_Connected connected to aPoint
* note m_Connected containts usually more than one candidate
* and searchEntryPointInCandidatesList returns an index to one of these candidates
* Others are neightbor of the indexed item.
* @param aPoint is the reference coordinates
* @return the index of item found or -1 if no candidate
*/
int searchEntryPointInCandidatesList( const wxPoint & aPoint);
/**
* Function Merge_SubNets
* Change a subnet old value to a new value, for tracks and pads which are connected to
* tracks from m_firstTrack to m_lastTrack and their connected pads.
* and modify the subnet parameter (change the old value to the new value).
* After that, 2 cluster (or subnets) are merged into only one.
* Note: the resulting sub net value is the smallest between aOldSubNet and aNewSubNet
* @return modification count
* @param aOldSubNet = subnet value to modify
* @param aNewSubNet = new subnet value for each item which have old_val as subnet value
*/
int Merge_SubNets( int aOldSubNet, int aNewSubNet );
/**
* Function Merge_PadsSubNets
* Change a subnet value to a new value, in m_sortedPads pad list
* After that, 2 cluster (or subnets) are merged into only one.
* Note: the resulting subnet value is the smallest between aOldSubNet et aNewSubNet
* @return modification count
* @param aOldSubNet = subnet value to modify
* @param aNewSubNet = new subnet value for each item which have old_val as subnet value
*/
int Merge_PadsSubNets( int aOldSubNet, int aNewSubNet );
};
CONNECTIONS::CONNECTIONS( BOARD * aBrd )
{
m_brd = aBrd;
......@@ -441,10 +242,6 @@ static bool sortConnectedPointByXthenYCoordinates( const CONNECTED_POINT & aRef,
void CONNECTIONS::BuildTracksCandidatesList( TRACK * aBegin, TRACK * aEnd)
{
m_candidates.clear();
// if( aBegin == NULL )
// aBegin = m_brd->m_Track;
m_firstTrack = m_lastTrack = aBegin;
unsigned ii = 0;
......
This diff is collapsed.
/////////////////////////////////////////////////////////////////////////////
// Name: dialog_cleaning_options.cpp
// Author: jean-pierre Charras
/////////////////////////////////////////////////////////////////////////////
/**
* @file dialog_cleaning_options.cpp
*/
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 1992-20112 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
*/
#include <wx/wx.h>
#include <dialog_cleaning_options.h>
......@@ -14,7 +35,6 @@ DIALOG_CLEANING_OPTIONS::DIALOG_CLEANING_OPTIONS( wxWindow* parent ):
m_cleanViasOpt->SetValue( cleanVias );
m_mergeSegmOpt->SetValue( mergeSegments );
m_deleteUnconnectedOpt->SetValue( deleteUnconnectedSegm );
m_reconnectToPadsOpt->SetValue( connectToPads );
m_sdbSizerOK->SetDefault();
GetSizer()->SetSizeHints(this);
......@@ -25,5 +45,4 @@ DIALOG_CLEANING_OPTIONS::DIALOG_CLEANING_OPTIONS( wxWindow* parent ):
bool DIALOG_CLEANING_OPTIONS::cleanVias = true;
bool DIALOG_CLEANING_OPTIONS::mergeSegments = true;
bool DIALOG_CLEANING_OPTIONS::deleteUnconnectedSegm = true;
bool DIALOG_CLEANING_OPTIONS::connectToPads = false;
......@@ -14,7 +14,6 @@ public:
static bool cleanVias;
static bool mergeSegments;
static bool deleteUnconnectedSegm;
static bool connectToPads;
public:
DIALOG_CLEANING_OPTIONS( wxWindow* parent );
......@@ -44,7 +43,6 @@ private:
cleanVias = m_cleanViasOpt->GetValue( );
mergeSegments = m_mergeSegmOpt->GetValue( );
deleteUnconnectedSegm = m_deleteUnconnectedOpt->GetValue( );
connectToPads = m_reconnectToPadsOpt->GetValue( );
}
};
......
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Sep 8 2010)
// C++ code generated with wxFormBuilder (version Apr 10 2012)
// http://www.wxformbuilder.org/
//
// PLEASE DO "NOT" EDIT THIS FILE!
......@@ -24,7 +24,7 @@ DIALOG_CLEANING_OPTIONS_BASE::DIALOG_CLEANING_OPTIONS_BASE( wxWindow* parent, wx
bSizerUpper->Add( m_cleanViasOpt, 0, wxALL, 5 );
m_mergeSegmOpt = new wxCheckBox( this, wxID_ANY, _("Merge segments"), wxDefaultPosition, wxDefaultSize, 0 );
m_mergeSegmOpt = new wxCheckBox( this, wxID_ANY, _("Merge colinear segments"), wxDefaultPosition, wxDefaultSize, 0 );
m_mergeSegmOpt->SetToolTip( _("merge aligned track segments, and remove null segments") );
bSizerUpper->Add( m_mergeSegmOpt, 0, wxALL, 5 );
......@@ -34,10 +34,6 @@ DIALOG_CLEANING_OPTIONS_BASE::DIALOG_CLEANING_OPTIONS_BASE( wxWindow* parent, wx
bSizerUpper->Add( m_deleteUnconnectedOpt, 0, wxALL, 5 );
m_reconnectToPadsOpt = new wxCheckBox( this, wxID_ANY, _("Connect to pads"), wxDefaultPosition, wxDefaultSize, 0 );
m_reconnectToPadsOpt->SetToolTip( _("Extend dangling tracks which partially cover a pad or via, all the way to pad or via center") );
bSizerUpper->Add( m_reconnectToPadsOpt, 0, wxALL, 5 );
bSizerMain->Add( bSizerUpper, 1, wxEXPAND|wxALL, 5 );
......@@ -50,8 +46,10 @@ DIALOG_CLEANING_OPTIONS_BASE::DIALOG_CLEANING_OPTIONS_BASE( wxWindow* parent, wx
m_sdbSizerCancel = new wxButton( this, wxID_CANCEL );
m_sdbSizer->AddButton( m_sdbSizerCancel );
m_sdbSizer->Realize();
bSizerMain->Add( m_sdbSizer, 0, wxALIGN_RIGHT|wxALL, 5 );
this->SetSizer( bSizerMain );
this->Layout();
......
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Sep 8 2010)
// C++ code generated with wxFormBuilder (version Apr 10 2012)
// http://www.wxformbuilder.org/
//
// PLEASE DO "NOT" EDIT THIS FILE!
///////////////////////////////////////////////////////////////////////////
#ifndef __dialog_cleaning_options_base__
#define __dialog_cleaning_options_base__
#ifndef __DIALOG_CLEANING_OPTIONS_BASE_H__
#define __DIALOG_CLEANING_OPTIONS_BASE_H__
#include <wx/artprov.h>
#include <wx/xrc/xmlres.h>
#include <wx/intl.h>
#include <wx/string.h>
#include <wx/checkbox.h>
#include <wx/gdicmn.h>
......@@ -35,7 +36,6 @@ class DIALOG_CLEANING_OPTIONS_BASE : public wxDialog
wxCheckBox* m_cleanViasOpt;
wxCheckBox* m_mergeSegmOpt;
wxCheckBox* m_deleteUnconnectedOpt;
wxCheckBox* m_reconnectToPadsOpt;
wxStaticLine* m_staticline;
wxStdDialogButtonSizer* m_sdbSizer;
wxButton* m_sdbSizerOK;
......@@ -51,11 +51,10 @@ class DIALOG_CLEANING_OPTIONS_BASE : public wxDialog
bool cleanVias;
bool mergeSegments;
bool deleteUnconnectedSegm;
bool connectToPads;
DIALOG_CLEANING_OPTIONS_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Cleaning options"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 243,181 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER );
DIALOG_CLEANING_OPTIONS_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Cleaning options"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 243,146 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER );
~DIALOG_CLEANING_OPTIONS_BASE();
};
#endif //__dialog_cleaning_options_base__
#endif //__DIALOG_CLEANING_OPTIONS_BASE_H__
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment