Commit 4230ac4c authored by Wayne Stambaugh's avatar Wayne Stambaugh

Remove sine and cosine look up tables and other minor fixes.

* Remove sine and cosine look up tables from trigo.cpp and replace them with
  sin() and cos() math functions.
* Large include file clean up to prevent header ordering dependency build
  failures.
* Translate French code names and comments.
* Lots of coding style policy and doxygen comment fixes.
parent 657a71a4
/******************************************/ /**
/* Kicad: Common plot GERBER Routines */ * @file common_plotGERBER_functions.cpp
/******************************************/ * @brief Common GERBER plot routines.
*/
#include "fctsys.h" #include "fctsys.h"
#include "gr_basic.h" #include "gr_basic.h"
...@@ -49,18 +50,18 @@ bool GERBER_PLOTTER::start_plot( FILE* aFile ) ...@@ -49,18 +50,18 @@ bool GERBER_PLOTTER::start_plot( FILE* aFile )
final_file = aFile; final_file = aFile;
// Create a temporary filename to store gerber file // Create a temporary filename to store gerber file
// note tmpfile() does not work under Vista and W7 un user mode // note tmpfile() does not work under Vista and W7 in user mode
m_workFilename = filename + wxT(".tmp"); m_workFilename = filename + wxT(".tmp");
work_file = wxFopen( m_workFilename, wxT( "wt" )); work_file = wxFopen( m_workFilename, wxT( "wt" ));
output_file = work_file; output_file = work_file;
wxASSERT( output_file ); wxASSERT( output_file );
if( output_file == NULL ) if( output_file == NULL )
return false; return false;
DateAndTime( Line ); DateAndTime( Line );
wxString Title = creator + wxT( " " ) + GetBuildVersion(); wxString Title = creator + wxT( " " ) + GetBuildVersion();
fprintf( output_file, "G04 (created by %s) date %s*\n", fprintf( output_file, "G04 (created by %s) date %s*\n", TO_UTF8( Title ), Line );
TO_UTF8( Title ), Line );
// Specify linear interpol (G01), unit = INCH (G70), abs format (G90): // Specify linear interpol (G01), unit = INCH (G70), abs format (G90):
fputs( "G01*\nG70*\nG90*\n", output_file ); fputs( "G01*\nG70*\nG90*\n", output_file );
...@@ -84,20 +85,22 @@ bool GERBER_PLOTTER::end_plot() ...@@ -84,20 +85,22 @@ bool GERBER_PLOTTER::end_plot()
wxString msg; wxString msg;
wxASSERT( output_file ); wxASSERT( output_file );
/* Outfile is actually a temporary file! */ /* Outfile is actually a temporary file! */
fputs( "M02*\n", output_file ); fputs( "M02*\n", output_file );
fflush( output_file ); fflush( output_file );
// rewind( work_file ); // work_file == output_file !!! // rewind( work_file ); // work_file == output_file !!!
fclose( work_file ); fclose( work_file );
work_file = wxFopen( m_workFilename, wxT( "rt" )); work_file = wxFopen( m_workFilename, wxT( "rt" ));
wxASSERT( work_file ); wxASSERT( work_file );
output_file = final_file; output_file = final_file;
// Placement of apertures in RS274X // Placement of apertures in RS274X
while( fgets( line, 1024, work_file ) ) while( fgets( line, 1024, work_file ) )
{ {
fputs( line, output_file ); fputs( line, output_file );
if( strcmp( strtok( line, "\n\r" ), "G04 APERTURE LIST*" ) == 0 ) if( strcmp( strtok( line, "\n\r" ), "G04 APERTURE LIST*" ) == 0 )
{ {
write_aperture_list(); write_aperture_list();
...@@ -146,12 +149,14 @@ std::vector<APERTURE>::iterator GERBER_PLOTTER::get_aperture( const wxSize& ...@@ -146,12 +149,14 @@ std::vector<APERTURE>::iterator GERBER_PLOTTER::get_aperture( const wxSize&
// Search an existing aperture // Search an existing aperture
std::vector<APERTURE>::iterator tool = apertures.begin(); std::vector<APERTURE>::iterator tool = apertures.begin();
while( tool != apertures.end() ) while( tool != apertures.end() )
{ {
last_D_code = tool->D_code; last_D_code = tool->D_code;
if( (tool->type == type)
&& (tool->size == size) ) if( (tool->type == type) && (tool->size == size) )
return tool; return tool;
tool++; tool++;
} }
...@@ -214,8 +219,7 @@ void GERBER_PLOTTER::write_aperture_list() ...@@ -214,8 +219,7 @@ void GERBER_PLOTTER::write_aperture_list()
break; break;
case APERTURE::Oval: case APERTURE::Oval:
sprintf( text, "O,%fX%f*%%\n", tool->size.x * fscale, sprintf( text, "O,%fX%f*%%\n", tool->size.x * fscale, tool->size.y * fscale );
tool->size.y * fscale );
break; break;
} }
...@@ -275,23 +279,22 @@ void GERBER_PLOTTER::rect( wxPoint p1, wxPoint p2, FILL_T fill, int width ) ...@@ -275,23 +279,22 @@ void GERBER_PLOTTER::rect( wxPoint p1, wxPoint p2, FILL_T fill, int width )
* not used here: circles are always not filled the gerber. Filled circles are flashed * not used here: circles are always not filled the gerber. Filled circles are flashed
* @param aWidth = line width * @param aWidth = line width
*/ */
void GERBER_PLOTTER::circle( wxPoint aCentre, int aDiameter, FILL_T aFill, void GERBER_PLOTTER::circle( wxPoint aCentre, int aDiameter, FILL_T aFill, int aWidth )
int aWidth )
{ {
wxASSERT( output_file ); wxASSERT( output_file );
wxPoint start, end; wxPoint start, end;
double radius = aDiameter / 2; double radius = aDiameter / 2;
const int delta = 3600 / 32; /* increment (in 0.1 degrees) to draw const int delta = 3600 / 32; /* increment (in 0.1 degrees) to draw circles */
* circles */
start.x = aCentre.x + wxRound( radius ); start.x = aCentre.x + wxRound( radius );
start.y = aCentre.y; start.y = aCentre.y;
set_current_line_width( aWidth ); set_current_line_width( aWidth );
move_to( start ); move_to( start );
for( int ii = delta; ii < 3600; ii += delta ) for( int ii = delta; ii < 3600; ii += delta )
{ {
end.x = aCentre.x + (int) ( radius * fcosinus[ii] ); end.x = aCentre.x + (int) ( radius * cos( DEG2RAD( (double)ii / 10.0 ) ) );
end.y = aCentre.y + (int) ( radius * fsinus[ii] ); end.y = aCentre.y + (int) ( radius * sin( DEG2RAD( (double)ii / 10.0 ) ) );
line_to( end ); line_to( end );
} }
...@@ -317,6 +320,7 @@ void GERBER_PLOTTER::PlotPoly( std::vector< wxPoint >& aCornerList, FILL_T aFill ...@@ -317,6 +320,7 @@ void GERBER_PLOTTER::PlotPoly( std::vector< wxPoint >& aCornerList, FILL_T aFill
fputs( "G36*\n", output_file ); fputs( "G36*\n", output_file );
move_to( aCornerList[0] ); move_to( aCornerList[0] );
for( unsigned ii = 1; ii < aCornerList.size(); ii++ ) for( unsigned ii = 1; ii < aCornerList.size(); ii++ )
{ {
line_to( aCornerList[ii] ); line_to( aCornerList[ii] );
...@@ -367,8 +371,7 @@ void GERBER_PLOTTER::PlotImage( wxImage & aImage, wxPoint aPos, double aScaleFac ...@@ -367,8 +371,7 @@ void GERBER_PLOTTER::PlotImage( wxImage & aImage, wxPoint aPos, double aScaleFac
/* Function flash_pad_circle /* Function flash_pad_circle
* Plot a circular pad or via at the user position pos * Plot a circular pad or via at the user position pos
*/ */
void GERBER_PLOTTER::flash_pad_circle( wxPoint pos, int diametre, void GERBER_PLOTTER::flash_pad_circle( wxPoint pos, int diametre, GRTraceMode trace_mode )
GRTraceMode trace_mode )
{ {
wxASSERT( output_file ); wxASSERT( output_file );
wxSize size( diametre, diametre ); wxSize size( diametre, diametre );
...@@ -408,6 +411,7 @@ void GERBER_PLOTTER::flash_pad_oval( wxPoint pos, wxSize size, int orient, ...@@ -408,6 +411,7 @@ void GERBER_PLOTTER::flash_pad_oval( wxPoint pos, wxSize size, int orient,
{ {
if( orient == 900 || orient == 2700 ) /* orientation turned 90 deg. */ if( orient == 900 || orient == 2700 ) /* orientation turned 90 deg. */
EXCHG( size.x, size.y ); EXCHG( size.x, size.y );
user_to_device_coordinates( pos ); user_to_device_coordinates( pos );
select_aperture( size, APERTURE::Oval ); select_aperture( size, APERTURE::Oval );
fprintf( output_file, "X%5.5dY%5.5dD03*\n", pos.x, pos.y ); fprintf( output_file, "X%5.5dY%5.5dD03*\n", pos.x, pos.y );
...@@ -417,11 +421,13 @@ void GERBER_PLOTTER::flash_pad_oval( wxPoint pos, wxSize size, int orient, ...@@ -417,11 +421,13 @@ void GERBER_PLOTTER::flash_pad_oval( wxPoint pos, wxSize size, int orient,
if( size.x > size.y ) if( size.x > size.y )
{ {
EXCHG( size.x, size.y ); EXCHG( size.x, size.y );
if( orient < 2700 ) if( orient < 2700 )
orient += 900; orient += 900;
else else
orient -= 2700; orient -= 2700;
} }
if( trace_mode == FILLED ) if( trace_mode == FILLED )
{ {
/* The pad is reduced to an oval with dy > dx */ /* The pad is reduced to an oval with dy > dx */
...@@ -437,8 +443,10 @@ void GERBER_PLOTTER::flash_pad_oval( wxPoint pos, wxSize size, int orient, ...@@ -437,8 +443,10 @@ void GERBER_PLOTTER::flash_pad_oval( wxPoint pos, wxSize size, int orient,
size.x, trace_mode ); size.x, trace_mode );
} }
else else
{
sketch_oval( pos, size, orient, -1 ); sketch_oval( pos, size, orient, -1 );
} }
}
} }
...@@ -533,6 +541,7 @@ void GERBER_PLOTTER::flash_pad_rect( wxPoint pos, wxSize size, ...@@ -533,6 +541,7 @@ void GERBER_PLOTTER::flash_pad_rect( wxPoint pos, wxSize size,
RotatePoint( &cornerList[ii], aPadOrient ); RotatePoint( &cornerList[ii], aPadOrient );
cornerList[ii] += aPadPos; cornerList[ii] += aPadPos;
} }
// Close the polygon // Close the polygon
cornerList.push_back( cornerList[0] ); cornerList.push_back( cornerList[0] );
...@@ -540,6 +549,7 @@ void GERBER_PLOTTER::flash_pad_rect( wxPoint pos, wxSize size, ...@@ -540,6 +549,7 @@ void GERBER_PLOTTER::flash_pad_rect( wxPoint pos, wxSize size,
PlotPoly( cornerList, aTrace_Mode==FILLED ? FILLED_SHAPE : NO_FILL ); PlotPoly( cornerList, aTrace_Mode==FILLED ? FILLED_SHAPE : NO_FILL );
} }
void GERBER_PLOTTER::SetLayerPolarity( bool aPositive ) void GERBER_PLOTTER::SetLayerPolarity( bool aPositive )
{ {
if( aPositive ) if( aPositive )
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -112,7 +112,6 @@ enum SEARCH_RESULT { ...@@ -112,7 +112,6 @@ enum SEARCH_RESULT {
class EDA_ITEM; class EDA_ITEM;
class EDA_DRAW_FRAME; class EDA_DRAW_FRAME;
class BOARD;
class EDA_RECT; class EDA_RECT;
class EDA_DRAW_PANEL; class EDA_DRAW_PANEL;
...@@ -136,12 +135,11 @@ public: ...@@ -136,12 +135,11 @@ public:
* Function Inspect * Function Inspect
* is the examining function within the INSPECTOR which is passed to the * is the examining function within the INSPECTOR which is passed to the
* Iterate function. It is used primarily for searching, but not limited * Iterate function. It is used primarily for searching, but not limited
*to * to that. It can also collect or modify the scanned objects.
* that. It can also collect or modify the scanned objects.
* *
* @param testItem An EDA_ITEM to examine. * @param testItem An EDA_ITEM to examine.
* @param testData is arbitrary data needed by the inspector to determine * @param testData is arbitrary data needed by the inspector to determine
* if the BOARD_ITEM under test meets its match criteria. * if the EDA_ITEM under test meets its match criteria.
* @return SEARCH_RESULT - SEARCH_QUIT if the Iterator is to stop the scan, * @return SEARCH_RESULT - SEARCH_QUIT if the Iterator is to stop the scan,
* else SCAN_CONTINUE; * else SCAN_CONTINUE;
*/ */
......
...@@ -131,11 +131,12 @@ public: ...@@ -131,11 +131,12 @@ public:
~BASE_SCREEN(); ~BASE_SCREEN();
/** /**
* Function setCurItem * Function SetCurItem
* sets the currently selected object, m_CurrentItem. * sets the currently selected object, m_CurrentItem.
* @param aItem Any object derived from EDA_ITEM * @param aItem Any object derived from EDA_ITEM
*/ */
void SetCurItem( EDA_ITEM* aItem ) { m_CurrentItem = aItem; } void SetCurItem( EDA_ITEM* aItem ) { m_CurrentItem = aItem; }
EDA_ITEM* GetCurItem() const { return m_CurrentItem; } EDA_ITEM* GetCurItem() const { return m_CurrentItem; }
/** /**
......
/**********************************************************************************************/ /**
/* board_item_struct.h : Classes BOARD_ITEM and BOARD_CONNECTED_ITEM */ * @file class_board_item.h
/**********************************************************************************************/ * @brief Classes BOARD_ITEM and BOARD_CONNECTED_ITEM.
*/
#ifndef BOARD_ITEM_STRUCT_H #ifndef BOARD_ITEM_STRUCT_H
#define BOARD_ITEM_STRUCT_H #define BOARD_ITEM_STRUCT_H
#include "base_struct.h"
#include <boost/ptr_container/ptr_vector.hpp> #include <boost/ptr_container/ptr_vector.hpp>
class BOARD;
class EDA_DRAW_PANEL;
/* Shapes for segments (graphic segments and tracks) ( .m_Shape member ) */ /* Shapes for segments (graphic segments and tracks) ( .m_Shape member ) */
enum Track_Shapes { enum Track_Shapes {
S_SEGMENT = 0, /* usual segment : line with rounded ends */ S_SEGMENT = 0, /* usual segment : line with rounded ends */
......
/****************/ /**
/* pcbstruct.h */ * @file class_pcb_screen.h
/****************/ */
#ifndef __CLASSPCB_SCREEN_H__ #ifndef __CLASSPCB_SCREEN_H__
#define __CLASSPCB_SCREEN_H__ #define __CLASSPCB_SCREEN_H__
#include "class_base_screen.h"
#include "class_board_item.h"
class UNDO_REDO_CONTAINER;
/* Handle info to display a board */ /* Handle info to display a board */
class PCB_SCREEN : public BASE_SCREEN class PCB_SCREEN : public BASE_SCREEN
{ {
...@@ -41,7 +49,7 @@ public: ...@@ -41,7 +49,7 @@ public:
* sets the currently selected object, m_CurrentItem. * sets the currently selected object, m_CurrentItem.
* @param aItem Any object derived from BOARD_ITEM * @param aItem Any object derived from BOARD_ITEM
*/ */
void SetCurItem( BOARD_ITEM* aItem ) { BASE_SCREEN::SetCurItem( aItem ); } void SetCurItem( BOARD_ITEM* aItem ) { BASE_SCREEN::SetCurItem( (EDA_ITEM*)aItem ); }
/* full undo redo management : */ /* full undo redo management : */
......
/*************/ /**
/* trigo.h */ * @file trigo.h
/*************/ */
#ifndef TRIGO_H #ifndef TRIGO_H
#define TRIGO_H #define TRIGO_H
/*
* Calculate the new point of coord coord pX, pY,
* for a rotation center 0, 0, and angle in (1 / 10 degree)
*/
void RotatePoint( int *pX, int *pY, int angle ); void RotatePoint( int *pX, int *pY, int angle );
/*
* Calculate the new point of coord coord pX, pY,
* for a rotation center cx, cy, and angle in (1 / 10 degree)
*/
void RotatePoint( int *pX, int *pY, int cx, int cy, int angle ); void RotatePoint( int *pX, int *pY, int cx, int cy, int angle );
/*
* Calculates the new coord point point
* for a rotation angle in (1 / 10 degree)
*/
void RotatePoint( wxPoint* point, int angle ); void RotatePoint( wxPoint* point, int angle );
/*
* Calculates the new coord point point
* for a center rotation center and angle in (1 / 10 degree)
*/
void RotatePoint( wxPoint *point, const wxPoint & centre, int angle ); void RotatePoint( wxPoint *point, const wxPoint & centre, int angle );
void RotatePoint( double *pX, double *pY, int angle ); void RotatePoint( double *pX, double *pY, int angle );
void RotatePoint( double *pX, double *pY, double cx, double cy, int angle ); void RotatePoint( double *pX, double *pY, double cx, double cy, int angle );
/* Return the arc tangent of 0.1 degrees coord vector dx, dy /* Return the arc tangent of 0.1 degrees coord vector dx, dy
...@@ -20,6 +41,11 @@ void RotatePoint( double *pX, double *pY, double cx, double cy, int angle ); ...@@ -20,6 +41,11 @@ void RotatePoint( double *pX, double *pY, double cx, double cy, int angle );
*/ */
int ArcTangente( int dy, int dx ); int ArcTangente( int dy, int dx );
/**
* Function DistanceTest
* Calculate the distance from mouse cursor to a line segment.
* @return False if distance > threshold or true if distance <= threshold.
*/
bool DistanceTest( int seuil, int dx, int dy, int spot_cX, int spot_cY ); bool DistanceTest( int seuil, int dx, int dy, int spot_cX, int spot_cY );
//! @brief Compute the distance between a line and a reference point //! @brief Compute the distance between a line and a reference point
...@@ -82,7 +108,7 @@ double GetLineLength( const wxPoint& aPointA, const wxPoint& aPointB ); ...@@ -82,7 +108,7 @@ double GetLineLength( const wxPoint& aPointA, const wxPoint& aPointB );
* either: xrot = (y + x * tg) * cos * either: xrot = (y + x * tg) * cos
* yrot = (y - x * tg) * cos * yrot = (y - x * tg) * cos
* *
* Cosine coefficients are loaded from a trigometric table by 16 bit values. * Cosine coefficients are loaded from a trigonometric table by 16 bit values.
*/ */
#define NEW_COORD( x0, y0 ) \ #define NEW_COORD( x0, y0 ) \
do { \ do { \
...@@ -95,7 +121,4 @@ double GetLineLength( const wxPoint& aPointA, const wxPoint& aPointB ); ...@@ -95,7 +121,4 @@ double GetLineLength( const wxPoint& aPointA, const wxPoint& aPointB );
} while( 0 ); } while( 0 );
extern double fsinus[];
extern double fcosinus[];
#endif #endif
...@@ -21,23 +21,13 @@ ...@@ -21,23 +21,13 @@
/* Forward declarations of classes. */ /* Forward declarations of classes. */
class WinEDA_CvpcbFrame; class WinEDA_CvpcbFrame;
class PCB_EDIT_FRAME;
class FOOTPRINT_EDIT_FRAME; class FOOTPRINT_EDIT_FRAME;
class BOARD; class BOARD;
class TEXTE_PCB;
class MODULE; class MODULE;
class TRACK; class TRACK;
class SEGZONE;
class SEGVIA;
class D_PAD; class D_PAD;
class TEXTE_MODULE; class TEXTE_MODULE;
class MIREPCB;
class DIMENSION;
class EDGE_MODULE;
class EDA_3D_FRAME; class EDA_3D_FRAME;
class DRC;
class ZONE_CONTAINER;
class DRAWSEGMENT;
class GENERAL_COLLECTOR; class GENERAL_COLLECTOR;
class GENERAL_COLLECTORS_GUIDE; class GENERAL_COLLECTORS_GUIDE;
......
...@@ -6,12 +6,12 @@ ...@@ -6,12 +6,12 @@
#define WXPCB_STRUCT_H #define WXPCB_STRUCT_H
#include "wxstruct.h" #include "wxBasePcbFrame.h"
#include "base_struct.h"
#include "param_config.h" #include "param_config.h"
#include "class_layer_box_selector.h" #include "class_layer_box_selector.h"
#include "class_macros_record.h" #include "class_macros_record.h"
#include "richio.h" #include "class_undoredo_container.h"
#ifndef PCB_INTERNAL_UNIT #ifndef PCB_INTERNAL_UNIT
#define PCB_INTERNAL_UNIT 10000 #define PCB_INTERNAL_UNIT 10000
...@@ -37,6 +37,8 @@ class DRAWSEGMENT; ...@@ -37,6 +37,8 @@ class DRAWSEGMENT;
class GENERAL_COLLECTOR; class GENERAL_COLLECTOR;
class GENERAL_COLLECTORS_GUIDE; class GENERAL_COLLECTORS_GUIDE;
class PCB_LAYER_WIDGET; class PCB_LAYER_WIDGET;
class MARKER_PCB;
class BOARD_ITEM;
/** /**
...@@ -389,23 +391,20 @@ public: ...@@ -389,23 +391,20 @@ public:
* Function IsElementVisible * Function IsElementVisible
* tests whether a given element category is visible. Keep this as an * tests whether a given element category is visible. Keep this as an
* inline function. * inline function.
* @param aPCB_VISIBLE is from the enum by the same name * @param aElement is from the enum by the same name
* @return bool - true if the element is visible. * @return bool - true if the element is visible.
* @see enum PCB_VISIBLE * @see enum PCB_VISIBLE
*/ */
bool IsElementVisible( int aPCB_VISIBLE ) bool IsElementVisible( int aElement );
{
return GetBoard()->IsElementVisible( aPCB_VISIBLE );
}
/** /**
* Function SetElementVisibility * Function SetElementVisibility
* changes the visibility of an element category * changes the visibility of an element category
* @param aPCB_VISIBLE is from the enum by the same name * @param aElement is from the enum by the same name
* @param aNewState = The new visibility state of the element category * @param aNewState = The new visibility state of the element category
* @see enum PCB_VISIBLE * @see enum PCB_VISIBLE
*/ */
void SetElementVisibility( int aPCB_VISIBLE, bool aNewState ); void SetElementVisibility( int aElement, bool aNewState );
/** /**
* Function SetVisibleAlls * Function SetVisibleAlls
...@@ -1212,10 +1211,42 @@ public: ...@@ -1212,10 +1211,42 @@ public:
void LockModule( MODULE* aModule, bool aLocked ); void LockModule( MODULE* aModule, bool aLocked );
void AutoMoveModulesOnPcb( bool PlaceModulesHorsPcb ); void AutoMoveModulesOnPcb( bool PlaceModulesHorsPcb );
void AutoPlaceModule( MODULE* Module, int place_mode, wxDC* DC ); void AutoPlaceModule( MODULE* Module, int place_mode, wxDC* DC );
int RecherchePlacementModule( MODULE* Module, wxDC* DC );
/**
* Function GetOptimalModulePlacement
* searches for the optimal position of the \a aModule.
*
* @param aModule A pointer to the MODULE object to get the optimal placement.
* @param aDC The device context to draw on.
* @return 1 if placement impossible or 0 if OK.
*/
int GetOptimalModulePlacement( MODULE* aModule, wxDC* aDC );
void GenModuleOnBoard( MODULE* Module ); void GenModuleOnBoard( MODULE* Module );
float Compute_Ratsnest_PlaceModule( wxDC* DC ); float Compute_Ratsnest_PlaceModule( wxDC* DC );
/**
* Function GenPlaceBoard
* generates board board (component side copper + rating):
* Allocate the memory needed to represent in "bitmap" on the grid
* Current:
* - The size of clearance area of component (the board)
* - The bitmap PENALTIES
* And initialize the cells of the board has
* - Hole in the cells occupied by a segment EDGE
* - CELL_is_ZONE for cell internal contour EDGE (if closed)
*
* Placement surface (board) gives the cells internal to the contour
* PCB, and among the latter the free cells and cells already occupied
*
* The bitmap PENALTIES give cells occupied by the modules,
* Plus a surface penalty related to the number of pads of the module
*
* Bitmap of the penalty is set to 0
* Occupation cell is a 0 leaves
*/
int GenPlaceBoard(); int GenPlaceBoard();
void DrawInfoPlace( wxDC* DC ); void DrawInfoPlace( wxDC* DC );
// Autorouting: // Autorouting:
......
/**************/ /**
/* ar-proto.h */ * @file ar_protos.h
/**************/ */
#ifndef _AR_PROTOS_H_
#define _AR_PROTOS_H_
#include "autorout.h"
class PCB_EDIT_FRAME;
class BOARD;
class D_PAD;
class RATSNEST_ITEM;
int Propagation( PCB_EDIT_FRAME* frame ); int Propagation( PCB_EDIT_FRAME* frame );
/* Initialize a value type, the cells included in the board surface of the /* Initialize a color value, the cells included in the board edge of the
* pad edge by pt_pad, with the margin reserved for isolation. */ * pad surface by pt_pad, with the margin reserved for isolation and the
void Place_1_Pad_Board( BOARD * Pcb, D_PAD * pt_pad, int type, int marge, * half width of the runway
int op_logique ); * Parameters:
* Pt_pad: pointer to the description of the pad
* color: mask write in cells
* margin: add a value to the radius or half the score pad
* op_logic: type of writing in the cell (WRITE, OR)
*/
void PlacePad( BOARD* Pcb, D_PAD* pt_pad, int type, int marge, int op_logic );
/* Draws a segment of track on the board. */ /* Draws a segment of track on the board. */
void TraceSegmentPcb( BOARD * Pcb, TRACK * pt_segm, int type, int marge, void TraceSegmentPcb( BOARD* Pcb, TRACK* pt_segm, int type, int marge, int op_logic );
int op_logique );
void TraceLignePcb( int x0, int y0, int x1, int y1, int layer, int type,
int op_logique );
/* Uses the color value of all cells included in the board /* Uses the color value of all cells included in the board
* coord of the rectangle ux0, uy0 (top right corner) * coord of the rectangle ux0, uy0 (top right corner)
* a ux1, uy1 (lower left corner) (coord PCB) * a ux1, uy1 (lower left corner) (coord PCB)
* the rectangle is horizontal (or vertical) * the rectangle is horizontal (or vertical)
* masque_layer = mask layers; * masque_layer = mask layers;
* op_logique = WRITE_CELL, WRITE_OR_CELL, WRITE_XOR_CELL, WRITE_AND_CELL * op_logic = WRITE_CELL, WRITE_OR_CELL, WRITE_XOR_CELL, WRITE_AND_CELL
*/ */
void TraceFilledRectangle( BOARD * Pcb, int ux0, int uy0, int ux1, int uy1, void TraceFilledRectangle( BOARD* Pcb, int ux0, int uy0, int ux1, int uy1,
int side, int color, int op_logique); int side, int color, int op_logic);
/* Same as above, but the rectangle is inclined angle angle. */ /* Same as above, but the rectangle is inclined angle angle. */
void TraceFilledRectangle( BOARD * Pcb, int ux0, int uy0, int ux1, int uy1, void TraceFilledRectangle( BOARD* Pcb, int ux0, int uy0, int ux1, int uy1,
int angle, int masque_layer, int color, int angle, int masque_layer, int color, int op_logic );
int op_logique );
/* Fills all BOARD cells contained in the arc of "L" angle half-width lg
* ux center, starting in ux y0, y1 is set to color. Coordinates are in
* PCB units (0.1 mil) relating to the origin pt_pcb-> Pcb_oX, Y's board.
*/
void TraceArc( int ux0,int uy0, int ux1, int uy1, int ArcAngle, int lg,
int layer, int color, int op_logique);
/* QUEUE.CPP */ /* QUEUE.CPP */
void FreeQueue(); void FreeQueue();
...@@ -72,3 +79,6 @@ DIST_CELL GetDist( int aRow, int aCol, int aSide ); ...@@ -72,3 +79,6 @@ DIST_CELL GetDist( int aRow, int aCol, int aSide );
void SetDist( int aRow, int aCol, int aSide, DIST_CELL ); void SetDist( int aRow, int aCol, int aSide, DIST_CELL );
int GetDir( int aRow, int aCol, int aSide ); int GetDir( int aRow, int aCol, int aSide );
void SetDir( int aRow, int aCol, int aSide, int aDir); void SetDir( int aRow, int aCol, int aSide, int aDir);
#endif // _AR_PROTOS_H_
/*******************************************/ /**
/* Routines to automatically place MODULES */ * @file autoplac.cpp
/*******************************************/ * @brief Routiness to automatically place MODULES on a board.
*/
#include "fctsys.h" #include "fctsys.h"
#include "class_drawpanel.h" #include "class_drawpanel.h"
#include "confirm.h" #include "confirm.h"
#include "pcbnew.h" #include "pcbnew.h"
#include "wxPcbStruct.h" #include "wxPcbStruct.h"
#include "protos.h"
#include "ar_protos.h"
#include "autorout.h" #include "autorout.h"
#include "cell.h" #include "cell.h"
#include "class_board_design_settings.h" #include "class_board_design_settings.h"
#include "colors_selection.h" #include "colors_selection.h"
#include "protos.h"
#define GAIN 16 #define GAIN 16
#define PENALITE 500 #define KEEP_OUT_MARGIN 500
/* Penalty for guidance given by CntRot90 and CntRot180: /* Penalty for guidance given by CntRot90 and CntRot180:
* graduated from 0 (rotation allowed) to 10 (rotation count null) * graduated from 0 (rotation allowed) to 10 (rotation count null)
...@@ -41,8 +44,7 @@ static const float OrientPenality[11] = ...@@ -41,8 +44,7 @@ static const float OrientPenality[11] =
#define OUT_OF_BOARD -2 #define OUT_OF_BOARD -2
#define OCCUPED_By_MODULE -1 #define OCCUPED_By_MODULE -1
static wxPoint CurrPosition; // Current position of the current module static wxPoint CurrPosition; // Current position of the current module placement
// placement
static bool AutoPlaceShowAll = true; static bool AutoPlaceShowAll = true;
float MinCout; float MinCout;
...@@ -55,8 +57,9 @@ static void CreateKeepOutRectangle( BOARD* Pcb, ...@@ -55,8 +57,9 @@ static void CreateKeepOutRectangle( BOARD* Pcb,
int ux1, int ux1,
int uy1, int uy1,
int marge, int marge,
int Penalite, int aKeepOut,
int aLayerMask ); int aLayerMask );
static MODULE* PickModule( PCB_EDIT_FRAME* pcbframe, wxDC* DC ); static MODULE* PickModule( PCB_EDIT_FRAME* pcbframe, wxDC* DC );
...@@ -169,7 +172,8 @@ void PCB_EDIT_FRAME::AutoPlaceModule( MODULE* Module, int place_mode, wxDC* DC ) ...@@ -169,7 +172,8 @@ void PCB_EDIT_FRAME::AutoPlaceModule( MODULE* Module, int place_mode, wxDC* DC )
case PLACE_INCREMENTAL: case PLACE_INCREMENTAL:
if( Module->m_ModuleStatus & MODULE_is_LOCKED ) if( Module->m_ModuleStatus & MODULE_is_LOCKED )
{ {
Module->m_ModuleStatus &= ~MODULE_is_PLACED; break; Module->m_ModuleStatus &= ~MODULE_is_PLACED;
break;
} }
if( !(Module->m_ModuleStatus & MODULE_is_PLACED) ) if( !(Module->m_ModuleStatus & MODULE_is_PLACED) )
...@@ -204,7 +208,7 @@ void PCB_EDIT_FRAME::AutoPlaceModule( MODULE* Module, int place_mode, wxDC* DC ) ...@@ -204,7 +208,7 @@ void PCB_EDIT_FRAME::AutoPlaceModule( MODULE* Module, int place_mode, wxDC* DC )
/* Display fill area of interest, barriers, penalties. */ /* Display fill area of interest, barriers, penalties. */
DrawInfoPlace( DC ); DrawInfoPlace( DC );
error = RecherchePlacementModule( Module, DC ); error = GetOptimalModulePlacement( Module, DC );
BestScore = MinCout; BestScore = MinCout;
PosOK = CurrPosition; PosOK = CurrPosition;
...@@ -219,7 +223,7 @@ void PCB_EDIT_FRAME::AutoPlaceModule( MODULE* Module, int place_mode, wxDC* DC ) ...@@ -219,7 +223,7 @@ void PCB_EDIT_FRAME::AutoPlaceModule( MODULE* Module, int place_mode, wxDC* DC )
int Angle_Rot_Module = 1800; int Angle_Rot_Module = 1800;
Rotate_Module( DC, Module, Angle_Rot_Module, false ); Rotate_Module( DC, Module, Angle_Rot_Module, false );
Module->CalculateBoundingBox(); Module->CalculateBoundingBox();
error = RecherchePlacementModule( Module, DC ); error = GetOptimalModulePlacement( Module, DC );
MinCout *= OrientPenality[ii]; MinCout *= OrientPenality[ii];
if( BestScore > MinCout ) /* This orientation is best. */ if( BestScore > MinCout ) /* This orientation is best. */
...@@ -244,7 +248,7 @@ void PCB_EDIT_FRAME::AutoPlaceModule( MODULE* Module, int place_mode, wxDC* DC ) ...@@ -244,7 +248,7 @@ void PCB_EDIT_FRAME::AutoPlaceModule( MODULE* Module, int place_mode, wxDC* DC )
{ {
int Angle_Rot_Module = 900; int Angle_Rot_Module = 900;
Rotate_Module( DC, Module, Angle_Rot_Module, false ); Rotate_Module( DC, Module, Angle_Rot_Module, false );
error = RecherchePlacementModule( Module, DC ); error = GetOptimalModulePlacement( Module, DC );
MinCout *= OrientPenality[ii]; MinCout *= OrientPenality[ii];
if( BestScore > MinCout ) /* This orientation is best. */ if( BestScore > MinCout ) /* This orientation is best. */
...@@ -269,7 +273,7 @@ void PCB_EDIT_FRAME::AutoPlaceModule( MODULE* Module, int place_mode, wxDC* DC ) ...@@ -269,7 +273,7 @@ void PCB_EDIT_FRAME::AutoPlaceModule( MODULE* Module, int place_mode, wxDC* DC )
{ {
int Angle_Rot_Module = 2700; int Angle_Rot_Module = 2700;
Rotate_Module( DC, Module, Angle_Rot_Module, false ); Rotate_Module( DC, Module, Angle_Rot_Module, false );
error = RecherchePlacementModule( Module, DC ); error = GetOptimalModulePlacement( Module, DC );
MinCout *= OrientPenality[ii]; MinCout *= OrientPenality[ii];
if( BestScore > MinCout ) /* This orientation is best. */ if( BestScore > MinCout ) /* This orientation is best. */
...@@ -368,24 +372,6 @@ void PCB_EDIT_FRAME::DrawInfoPlace( wxDC* DC ) ...@@ -368,24 +372,6 @@ void PCB_EDIT_FRAME::DrawInfoPlace( wxDC* DC )
} }
/* Generate board (component side copper + rating):
* Allocate the memory needed to represent in "bitmap" on the grid
* Current:
* - The size of clearance area of component (the board)
* - The bitmap PENALTIES
* And initialize the cells of the board has
* - Hole in the cells occupied by a segment EDGE
* - CELL_is_ZONE for cell internal contour EDGE (if closed)
*
* Placement surface (board) gives the cells internal to the contour
* PCB, and among the latter the free cells and cells already occupied
*
* The bitmap PENALTIES give cells occupied by the modules,
* Plus a surface penalty related to the number of pads of the module
*
* Bitmap of the penalty is set to 0
* Occupation cell is a 0 leaves
*/
int PCB_EDIT_FRAME::GenPlaceBoard() int PCB_EDIT_FRAME::GenPlaceBoard()
{ {
int jj, ii; int jj, ii;
...@@ -406,6 +392,7 @@ int PCB_EDIT_FRAME::GenPlaceBoard() ...@@ -406,6 +392,7 @@ int PCB_EDIT_FRAME::GenPlaceBoard()
Board.m_GridRouting; Board.m_GridRouting;
GetBoard()->m_BoundaryBox.m_Pos.y -= GetBoard()->m_BoundaryBox.m_Pos.y % GetBoard()->m_BoundaryBox.m_Pos.y -= GetBoard()->m_BoundaryBox.m_Pos.y %
Board.m_GridRouting; Board.m_GridRouting;
/* The boundary box must have its end point on placing grid: */ /* The boundary box must have its end point on placing grid: */
wxPoint end = GetBoard()->m_BoundaryBox.GetEnd(); wxPoint end = GetBoard()->m_BoundaryBox.GetEnd();
end.x -= end.x % Board.m_GridRouting; end.x -= end.x % Board.m_GridRouting;
...@@ -509,7 +496,7 @@ int PCB_EDIT_FRAME::GenPlaceBoard() ...@@ -509,7 +496,7 @@ int PCB_EDIT_FRAME::GenPlaceBoard()
*/ */
void PCB_EDIT_FRAME::GenModuleOnBoard( MODULE* Module ) void PCB_EDIT_FRAME::GenModuleOnBoard( MODULE* Module )
{ {
int ox, oy, fx, fy, Penalite; int ox, oy, fx, fy;
int marge = Board.m_GridRouting / 2; int marge = Board.m_GridRouting / 2;
int layerMask; int layerMask;
D_PAD* Pad; D_PAD* Pad;
...@@ -562,45 +549,36 @@ void PCB_EDIT_FRAME::GenModuleOnBoard( MODULE* Module ) ...@@ -562,45 +549,36 @@ void PCB_EDIT_FRAME::GenModuleOnBoard( MODULE* Module )
for( Pad = Module->m_Pads; Pad != NULL; Pad = Pad->Next() ) for( Pad = Module->m_Pads; Pad != NULL; Pad = Pad->Next() )
{ {
Place_1_Pad_Board( GetBoard(), Pad, CELL_is_MODULE, marge, WRITE_OR_CELL ); ::PlacePad( GetBoard(), Pad, CELL_is_MODULE, marge, WRITE_OR_CELL );
} }
/* Trace clearance. */ /* Trace clearance. */
marge = ( Board.m_GridRouting * Module->m_PadNum ) / GAIN; marge = ( Board.m_GridRouting * Module->m_PadNum ) / GAIN;
Penalite = PENALITE; CreateKeepOutRectangle( GetBoard(), ox, oy, fx, fy, marge, KEEP_OUT_MARGIN, layerMask );
CreateKeepOutRectangle( GetBoard(), ox, oy, fx, fy, marge, Penalite, layerMask );
} }
/* int PCB_EDIT_FRAME::GetOptimalModulePlacement( MODULE* aModule, wxDC* aDC )
* Search for the optimal position of the module.
* Entree:
* Module tip MODULE struct module's place.
* Returns:
* 1 if placement impossible, 0 if OK
* = MinCout and external variable = cost of best placement
*/
int PCB_EDIT_FRAME::RecherchePlacementModule( MODULE* Module, wxDC* DC )
{ {
int cx, cy; int cx, cy;
int ox, oy, fx, fy; /* occupying part of the module focuses on the cursor */ int ox, oy, fx, fy; /* occupying part of the module focuses on the cursor */
int error = 1; int error = 1;
int DisplayChevelu = 0; int showRat = 0;
wxPoint LastPosOK; wxPoint LastPosOK;
float mincout, cout, Score; float mincout, cout, Score;
int Penalite; int keepOut;
bool TstOtherSide; bool TstOtherSide;
Module->DisplayInfo( this ); aModule->DisplayInfo( this );
LastPosOK.x = GetBoard()->m_BoundaryBox.m_Pos.x; LastPosOK.x = GetBoard()->m_BoundaryBox.m_Pos.x;
LastPosOK.y = GetBoard()->m_BoundaryBox.m_Pos.y; LastPosOK.y = GetBoard()->m_BoundaryBox.m_Pos.y;
cx = Module->m_Pos.x; cy = Module->m_Pos.y; cx = aModule->m_Pos.x; cy = aModule->m_Pos.y;
ox = Module->m_BoundaryBox.m_Pos.x - cx; ox = aModule->m_BoundaryBox.m_Pos.x - cx;
fx = Module->m_BoundaryBox.m_Size.x + ox; fx = aModule->m_BoundaryBox.m_Size.x + ox;
oy = Module->m_BoundaryBox.m_Pos.y - cy; oy = aModule->m_BoundaryBox.m_Pos.y - cy;
fy = Module->m_BoundaryBox.m_Size.y + oy; fy = aModule->m_BoundaryBox.m_Size.y + oy;
CurrPosition.x = GetBoard()->m_BoundaryBox.m_Pos.x - ox; CurrPosition.x = GetBoard()->m_BoundaryBox.m_Pos.x - ox;
CurrPosition.y = GetBoard()->m_BoundaryBox.m_Pos.y - oy; CurrPosition.y = GetBoard()->m_BoundaryBox.m_Pos.y - oy;
...@@ -624,10 +602,10 @@ int PCB_EDIT_FRAME::RecherchePlacementModule( MODULE* Module, wxDC* DC ) ...@@ -624,10 +602,10 @@ int PCB_EDIT_FRAME::RecherchePlacementModule( MODULE* Module, wxDC* DC )
D_PAD* Pad; D_PAD* Pad;
int otherLayerMask = LAYER_BACK; int otherLayerMask = LAYER_BACK;
if( Module->GetLayer() == LAYER_N_BACK ) if( aModule->GetLayer() == LAYER_N_BACK )
otherLayerMask = LAYER_FRONT; otherLayerMask = LAYER_FRONT;
for( Pad = Module->m_Pads; Pad != NULL; Pad = Pad->Next() ) for( Pad = aModule->m_Pads; Pad != NULL; Pad = Pad->Next() )
{ {
if( ( Pad->m_layerMask & otherLayerMask ) == 0 ) if( ( Pad->m_layerMask & otherLayerMask ) == 0 )
continue; continue;
...@@ -637,7 +615,7 @@ int PCB_EDIT_FRAME::RecherchePlacementModule( MODULE* Module, wxDC* DC ) ...@@ -637,7 +615,7 @@ int PCB_EDIT_FRAME::RecherchePlacementModule( MODULE* Module, wxDC* DC )
} }
} }
DrawModuleOutlines( DrawPanel, DC, Module ); DrawModuleOutlines( DrawPanel, aDC, aModule );
mincout = -1.0; mincout = -1.0;
SetStatusText( wxT( "Score ??, pos ??" ) ); SetStatusText( wxT( "Score ??, pos ??" ) );
...@@ -655,43 +633,44 @@ int PCB_EDIT_FRAME::RecherchePlacementModule( MODULE* Module, wxDC* DC ) ...@@ -655,43 +633,44 @@ int PCB_EDIT_FRAME::RecherchePlacementModule( MODULE* Module, wxDC* DC )
DrawPanel->m_AbortRequest = false; DrawPanel->m_AbortRequest = false;
} }
cx = Module->m_Pos.x; cy = Module->m_Pos.y; cx = aModule->m_Pos.x; cy = aModule->m_Pos.y;
Module->m_BoundaryBox.m_Pos.x = ox + CurrPosition.x; aModule->m_BoundaryBox.m_Pos.x = ox + CurrPosition.x;
Module->m_BoundaryBox.m_Pos.y = oy + CurrPosition.y; aModule->m_BoundaryBox.m_Pos.y = oy + CurrPosition.y;
DrawModuleOutlines( DrawPanel, DC, Module ); DrawModuleOutlines( DrawPanel, aDC, aModule );
g_Offset_Module.x = cx - CurrPosition.x; g_Offset_Module.x = cx - CurrPosition.x;
CurrPosition.y = GetBoard()->m_BoundaryBox.m_Pos.y - oy; CurrPosition.y = GetBoard()->m_BoundaryBox.m_Pos.y - oy;
/* Placement on grid. */ /* Placement on grid. */
CurrPosition.y -= CurrPosition.y % Board.m_GridRouting; CurrPosition.y -= CurrPosition.y % Board.m_GridRouting;
DrawModuleOutlines( DrawPanel, DC, Module ); DrawModuleOutlines( DrawPanel, aDC, aModule );
for( ; CurrPosition.y < GetBoard()->m_BoundaryBox.GetBottom() - fy; for( ; CurrPosition.y < GetBoard()->m_BoundaryBox.GetBottom() - fy;
CurrPosition.y += Board.m_GridRouting ) CurrPosition.y += Board.m_GridRouting )
{ {
/* Erase traces. */ /* Erase traces. */
DrawModuleOutlines( DrawPanel, DC, Module ); DrawModuleOutlines( DrawPanel, aDC, aModule );
if( DisplayChevelu ) if( showRat )
Compute_Ratsnest_PlaceModule( DC ); Compute_Ratsnest_PlaceModule( aDC );
DisplayChevelu = 0; showRat = 0;
Module->m_BoundaryBox.m_Pos.x = ox + CurrPosition.x; aModule->m_BoundaryBox.m_Pos.x = ox + CurrPosition.x;
Module->m_BoundaryBox.m_Pos.y = oy + CurrPosition.y; aModule->m_BoundaryBox.m_Pos.y = oy + CurrPosition.y;
g_Offset_Module.y = cy - CurrPosition.y; g_Offset_Module.y = cy - CurrPosition.y;
DrawModuleOutlines( DrawPanel, DC, Module ); DrawModuleOutlines( DrawPanel, aDC, aModule );
Penalite = TstModuleOnBoard( GetBoard(), Module, TstOtherSide ); keepOut = TstModuleOnBoard( GetBoard(), aModule, TstOtherSide );
if( Penalite >= 0 ) /* c a d if the module can be placed. */ if( keepOut >= 0 ) /* c a d if the module can be placed. */
{ {
error = 0; error = 0;
build_ratsnest_module( Module ); build_ratsnest_module( aModule );
cout = Compute_Ratsnest_PlaceModule( DC ); cout = Compute_Ratsnest_PlaceModule( aDC );
DisplayChevelu = 1; showRat = 1;
Score = cout + (float) Penalite; Score = cout + (float) keepOut;
if( (mincout >= Score ) || (mincout < 0 ) ) if( (mincout >= Score ) || (mincout < 0 ) )
{ {
...@@ -706,21 +685,21 @@ int PCB_EDIT_FRAME::RecherchePlacementModule( MODULE* Module, wxDC* DC ) ...@@ -706,21 +685,21 @@ int PCB_EDIT_FRAME::RecherchePlacementModule( MODULE* Module, wxDC* DC )
} }
} }
if( DisplayChevelu ) if( showRat )
Compute_Ratsnest_PlaceModule( DC ); Compute_Ratsnest_PlaceModule( aDC );
DisplayChevelu = 0; showRat = 0;
} }
} }
DrawModuleOutlines( DrawPanel, DC, Module ); /* erasing the last traces */ DrawModuleOutlines( DrawPanel, aDC, aModule ); /* erasing the last traces */
if( DisplayChevelu ) if( showRat )
Compute_Ratsnest_PlaceModule( DC ); Compute_Ratsnest_PlaceModule( aDC );
/* Regeneration of the modified variable. */ /* Regeneration of the modified variable. */
Module->m_BoundaryBox.m_Pos.x = ox + cx; aModule->m_BoundaryBox.m_Pos.x = ox + cx;
Module->m_BoundaryBox.m_Pos.y = oy + cy; aModule->m_BoundaryBox.m_Pos.y = oy + cy;
CurrPosition = LastPosOK; CurrPosition = LastPosOK;
GetBoard()->m_Status_Pcb &= ~( RATSNEST_ITEM_LOCAL_OK | LISTE_PAD_OK ); GetBoard()->m_Status_Pcb &= ~( RATSNEST_ITEM_LOCAL_OK | LISTE_PAD_OK );
...@@ -793,12 +772,11 @@ int TstRectangle( BOARD* Pcb, int ux0, int uy0, int ux1, int uy1, int side ) ...@@ -793,12 +772,11 @@ int TstRectangle( BOARD* Pcb, int ux0, int uy0, int ux1, int uy1, int side )
* (ux, ux .. y0, y1): * (ux, ux .. y0, y1):
* (Sum of cells in terms of distance) * (Sum of cells in terms of distance)
*/ */
unsigned int CalculePenaliteRectangle( BOARD* Pcb, int ux0, int uy0, unsigned int CalculateKeepOutArea( BOARD* Pcb, int ux0, int uy0, int ux1, int uy1, int side )
int ux1, int uy1, int side )
{ {
int row, col; int row, col;
int row_min, row_max, col_min, col_max; int row_min, row_max, col_min, col_max;
unsigned int Penalite; unsigned int keepOut;
ux0 -= Pcb->m_BoundaryBox.m_Pos.x; ux0 -= Pcb->m_BoundaryBox.m_Pos.x;
uy0 -= Pcb->m_BoundaryBox.m_Pos.y; uy0 -= Pcb->m_BoundaryBox.m_Pos.y;
...@@ -829,17 +807,17 @@ unsigned int CalculePenaliteRectangle( BOARD* Pcb, int ux0, int uy0, ...@@ -829,17 +807,17 @@ unsigned int CalculePenaliteRectangle( BOARD* Pcb, int ux0, int uy0,
if( col_max >= ( Ncols - 1 ) ) if( col_max >= ( Ncols - 1 ) )
col_max = Ncols - 1; col_max = Ncols - 1;
Penalite = 0; keepOut = 0;
for( row = row_min; row <= row_max; row++ ) for( row = row_min; row <= row_max; row++ )
{ {
for( col = col_min; col <= col_max; col++ ) for( col = col_min; col <= col_max; col++ )
{ {
Penalite += (int) GetDist( row, col, side ); keepOut += (int) GetDist( row, col, side );
} }
} }
return Penalite; return keepOut;
} }
...@@ -850,7 +828,7 @@ unsigned int CalculePenaliteRectangle( BOARD* Pcb, int ux0, int uy0, ...@@ -850,7 +828,7 @@ unsigned int CalculePenaliteRectangle( BOARD* Pcb, int ux0, int uy0,
int TstModuleOnBoard( BOARD* Pcb, MODULE* Module, bool TstOtherSide ) int TstModuleOnBoard( BOARD* Pcb, MODULE* Module, bool TstOtherSide )
{ {
int ox, oy, fx, fy; int ox, oy, fx, fy;
int error, Penalite, marge, side, otherside; int error, marge, side, otherside;
side = TOP; otherside = BOTTOM; side = TOP; otherside = BOTTOM;
...@@ -879,9 +857,7 @@ int TstModuleOnBoard( BOARD* Pcb, MODULE* Module, bool TstOtherSide ) ...@@ -879,9 +857,7 @@ int TstModuleOnBoard( BOARD* Pcb, MODULE* Module, bool TstOtherSide )
marge = ( Board.m_GridRouting * Module->m_PadNum ) / GAIN; marge = ( Board.m_GridRouting * Module->m_PadNum ) / GAIN;
Penalite = CalculePenaliteRectangle( Pcb, ox - marge, oy - marge, return CalculateKeepOutArea( Pcb, ox - marge, oy - marge, fx + marge, fy + marge, side );
fx + marge, fy + marge, side );
return Penalite;
} }
...@@ -954,10 +930,10 @@ float PCB_EDIT_FRAME::Compute_Ratsnest_PlaceModule( wxDC* DC ) ...@@ -954,10 +930,10 @@ float PCB_EDIT_FRAME::Compute_Ratsnest_PlaceModule( wxDC* DC )
/* Build the cost map. /* Build the cost map.
* Cells ( in Dist mao ) inside the rect x0,y0 a x1,y1 are * Cells ( in Dist mao ) inside the rect x0,y0 a x1,y1 are
* incremented by value Penalite * incremented by value aKeepOut
* Cell outside this rectangle, but inside the rectangle * Cell outside this rectangle, but inside the rectangle
* x0,y0 -marge to x1,y1 + marge sont incrementede by a decreasing value * x0,y0 -marge to x1,y1 + marge sont incrementede by a decreasing value
* (Penalite ... 0). The decreasing value de pends on the distance to the first rectangle * (aKeepOut ... 0). The decreasing value de pends on the distance to the first rectangle
* Therefore the cost is high in rect x0,y0 a x1,y1, and decrease outside this rectangle * Therefore the cost is high in rect x0,y0 a x1,y1, and decrease outside this rectangle
*/ */
static void CreateKeepOutRectangle( BOARD* Pcb, static void CreateKeepOutRectangle( BOARD* Pcb,
...@@ -966,7 +942,7 @@ static void CreateKeepOutRectangle( BOARD* Pcb, ...@@ -966,7 +942,7 @@ static void CreateKeepOutRectangle( BOARD* Pcb,
int ux1, int ux1,
int uy1, int uy1,
int marge, int marge,
int Penalite, int aKeepOut,
int aLayerMask ) int aLayerMask )
{ {
int row, col; int row, col;
...@@ -1034,7 +1010,7 @@ static void CreateKeepOutRectangle( BOARD* Pcb, ...@@ -1034,7 +1010,7 @@ static void CreateKeepOutRectangle( BOARD* Pcb,
for( col = col_min; col <= col_max; col++ ) for( col = col_min; col <= col_max; col++ )
{ {
cgain = 256; cgain = 256;
LocalKeepOut = Penalite; LocalKeepOut = aKeepOut;
if( col < pmarge ) if( col < pmarge )
cgain = ( 256 * col ) / pmarge; cgain = ( 256 * col ) / pmarge;
......
/***************************************/ /**
/* PCBNEW: Autorouting command control */ * @file autorout.cpp
/***************************************/ * @brief Autorouting command and control.
*/
#include "fctsys.h" #include "fctsys.h"
#include "class_drawpanel.h" #include "class_drawpanel.h"
#include "pcbnew.h"
#include "wxPcbStruct.h" #include "wxPcbStruct.h"
#include "pcbnew.h"
#include "autorout.h" #include "autorout.h"
#include "cell.h" #include "cell.h"
#include "zones.h" #include "zones.h"
#include "class_board_design_settings.h" #include "class_board_design_settings.h"
#include "ar_protos.h"
int E_scale; /* Scaling factor of distance tables. */ int E_scale; /* Scaling factor of distance tables. */
...@@ -41,8 +44,7 @@ void PCB_EDIT_FRAME::Autoroute( wxDC* DC, int mode ) ...@@ -41,8 +44,7 @@ void PCB_EDIT_FRAME::Autoroute( wxDC* DC, int mode )
} }
else else
{ {
Route_Layer_TOP = Route_Layer_TOP = Route_Layer_BOTTOM = LAYER_N_BACK;
Route_Layer_BOTTOM = LAYER_N_BACK;
} }
switch( mode ) switch( mode )
...@@ -78,11 +80,13 @@ void PCB_EDIT_FRAME::Autoroute( wxDC* DC, int mode ) ...@@ -78,11 +80,13 @@ void PCB_EDIT_FRAME::Autoroute( wxDC* DC, int mode )
case ROUTE_PAD: case ROUTE_PAD:
Pad = (D_PAD*) GetScreen()->GetCurItem(); Pad = (D_PAD*) GetScreen()->GetCurItem();
if( (Pad == NULL) || (Pad->Type() != TYPE_PAD) ) if( (Pad == NULL) || (Pad->Type() != TYPE_PAD) )
{ {
wxMessageBox( _( "Pad not selected" ) ); wxMessageBox( _( "Pad not selected" ) );
return; return;
} }
break; break;
} }
...@@ -113,6 +117,7 @@ void PCB_EDIT_FRAME::Autoroute( wxDC* DC, int mode ) ...@@ -113,6 +117,7 @@ void PCB_EDIT_FRAME::Autoroute( wxDC* DC, int mode )
{ {
if( ptmp->m_PadStart == pt_pad ) if( ptmp->m_PadStart == pt_pad )
ptmp->m_Status |= CH_ROUTE_REQ; ptmp->m_Status |= CH_ROUTE_REQ;
if( ptmp->m_PadEnd == pt_pad ) if( ptmp->m_PadEnd == pt_pad )
ptmp->m_Status |= CH_ROUTE_REQ; ptmp->m_Status |= CH_ROUTE_REQ;
} }
...@@ -123,6 +128,7 @@ void PCB_EDIT_FRAME::Autoroute( wxDC* DC, int mode ) ...@@ -123,6 +128,7 @@ void PCB_EDIT_FRAME::Autoroute( wxDC* DC, int mode )
case ROUTE_PAD: case ROUTE_PAD:
if( ( ptmp->m_PadStart == Pad ) || ( ptmp->m_PadEnd == Pad ) ) if( ( ptmp->m_PadStart == Pad ) || ( ptmp->m_PadEnd == Pad ) )
ptmp->m_Status |= CH_ROUTE_REQ; ptmp->m_Status |= CH_ROUTE_REQ;
break; break;
} }
} }
...@@ -131,9 +137,13 @@ void PCB_EDIT_FRAME::Autoroute( wxDC* DC, int mode ) ...@@ -131,9 +137,13 @@ void PCB_EDIT_FRAME::Autoroute( wxDC* DC, int mode )
/* Calculation of no fixed routing to 5 mils and more. */ /* Calculation of no fixed routing to 5 mils and more. */
Board.m_GridRouting = (int)GetScreen()->GetGridSize().x; Board.m_GridRouting = (int)GetScreen()->GetGridSize().x;
if( Board.m_GridRouting < 50 ) if( Board.m_GridRouting < 50 )
Board.m_GridRouting = 50; Board.m_GridRouting = 50;
E_scale = Board.m_GridRouting / 50; if( E_scale < 1 )
E_scale = Board.m_GridRouting / 50;
if( E_scale < 1 )
E_scale = 1; E_scale = 1;
/* Calculated ncol and nrow, matrix size for routing. */ /* Calculated ncol and nrow, matrix size for routing. */
...@@ -143,6 +153,7 @@ void PCB_EDIT_FRAME::Autoroute( wxDC* DC, int mode ) ...@@ -143,6 +153,7 @@ void PCB_EDIT_FRAME::Autoroute( wxDC* DC, int mode )
/* Map the board */ /* Map the board */
Nb_Sides = ONE_SIDE; Nb_Sides = ONE_SIDE;
if( Route_Layer_TOP != Route_Layer_BOTTOM ) if( Route_Layer_TOP != Route_Layer_BOTTOM )
Nb_Sides = TWO_SIDES; Nb_Sides = TWO_SIDES;
...@@ -201,25 +212,33 @@ void DisplayBoard( EDA_DRAW_PANEL* panel, wxDC* DC ) ...@@ -201,25 +212,33 @@ void DisplayBoard( EDA_DRAW_PANEL* panel, wxDC* DC )
maxi = 600 / Ncols; maxi = 600 / Ncols;
maxi = ( maxi * 3 ) / 4; maxi = ( maxi * 3 ) / 4;
if( !maxi ) if( !maxi )
maxi = 1; maxi = 1;
GRSetDrawMode( DC, GR_COPY ); GRSetDrawMode( DC, GR_COPY );
for( col = 0; col < Ncols; col++ ) for( col = 0; col < Ncols; col++ )
{ {
for( row = 0; row < Nrows; row++ ) for( row = 0; row < Nrows; row++ )
{ {
color = 0; color = 0;
dcell0 = GetCell( row, col, BOTTOM ); dcell0 = GetCell( row, col, BOTTOM );
if( dcell0 & HOLE ) if( dcell0 & HOLE )
color = GREEN; color = GREEN;
// if( Nb_Sides ) // if( Nb_Sides )
// dcell1 = GetCell( row, col, TOP ); // dcell1 = GetCell( row, col, TOP );
if( dcell1 & HOLE ) if( dcell1 & HOLE )
color |= RED; color |= RED;
// dcell0 |= dcell1; // dcell0 |= dcell1;
if( !color && ( dcell0 & VIA_IMPOSSIBLE ) ) if( !color && ( dcell0 & VIA_IMPOSSIBLE ) )
color = BLUE; color = BLUE;
if( dcell0 & CELL_is_EDGE ) if( dcell0 & CELL_is_EDGE )
color = YELLOW; color = YELLOW;
else if( dcell0 & CELL_is_ZONE ) else if( dcell0 & CELL_is_ZONE )
......
/****************************************************/ /**
/* AUTOROUT.H */ * @file autorout.h
/****************************************************/ */
#ifndef AUTOROUT_H #ifndef AUTOROUT_H
#define AUTOROUT_H #define AUTOROUT_H
class BOARD;
#define TOP 0 #define TOP 0
#define BOTTOM 1 #define BOTTOM 1
#define EMPTY 0 #define EMPTY 0
...@@ -65,13 +68,14 @@ public: ...@@ -65,13 +68,14 @@ public:
bool m_InitBoardDone; bool m_InitBoardDone;
int m_Layers; int m_Layers;
int m_GridRouting; // Size of grid for autoplace/autoroute int m_GridRouting; // Size of grid for autoplace/autoroute
EDA_RECT m_BrdBox; // Actual board bouding box EDA_RECT m_BrdBox; // Actual board bounding box
int m_Nrows, m_Ncols; int m_Nrows, m_Ncols;
int m_MemSize; int m_MemSize;
public: public:
MATRIX_ROUTING_HEAD(); MATRIX_ROUTING_HEAD();
~MATRIX_ROUTING_HEAD(); ~MATRIX_ROUTING_HEAD();
bool ComputeMatrixSize( BOARD* aPcb ); bool ComputeMatrixSize( BOARD* aPcb );
int InitBoard(); int InitBoard();
void UnInitBoard(); void UnInitBoard();
...@@ -88,8 +92,4 @@ extern MATRIX_ROUTING_HEAD Board; /* 2-sided board */ ...@@ -88,8 +92,4 @@ extern MATRIX_ROUTING_HEAD Board; /* 2-sided board */
#define WRITE_ADD_CELL 4 #define WRITE_ADD_CELL 4
#include "ar_protos.h"
#endif // AUTOROUT_H #endif // AUTOROUT_H
/* BOARD.CPP : functions for autorouting */ /**
* @file board.cpp
* @brief Functions for autorouting
*/
#include "fctsys.h" #include "fctsys.h"
#include "common.h" #include "common.h"
#include "pcbnew.h" #include "pcbnew.h"
#include "autorout.h"
#include "cell.h" #include "cell.h"
#include "ar_protos.h"
/* /*
...@@ -19,6 +23,7 @@ bool MATRIX_ROUTING_HEAD::ComputeMatrixSize( BOARD* aPcb ) ...@@ -19,6 +23,7 @@ bool MATRIX_ROUTING_HEAD::ComputeMatrixSize( BOARD* aPcb )
aPcb->m_BoundaryBox.m_Pos.x -= aPcb->m_BoundaryBox.m_Pos.x % m_GridRouting; aPcb->m_BoundaryBox.m_Pos.x -= aPcb->m_BoundaryBox.m_Pos.x % m_GridRouting;
aPcb->m_BoundaryBox.m_Pos.y -= aPcb->m_BoundaryBox.m_Pos.y % m_GridRouting; aPcb->m_BoundaryBox.m_Pos.y -= aPcb->m_BoundaryBox.m_Pos.y % m_GridRouting;
m_BrdBox = aPcb->m_BoundaryBox; m_BrdBox = aPcb->m_BoundaryBox;
/* The boundary box must have its end point on routing grid: */ /* The boundary box must have its end point on routing grid: */
wxPoint end = m_BrdBox.GetEnd(); wxPoint end = m_BrdBox.GetEnd();
end.x -= end.x % m_GridRouting; end.x -= end.x % m_GridRouting;
...@@ -115,19 +120,22 @@ void MATRIX_ROUTING_HEAD::UnInitBoard() ...@@ -115,19 +120,22 @@ void MATRIX_ROUTING_HEAD::UnInitBoard()
/***** de-allocate Dir matrix *****/ /***** de-allocate Dir matrix *****/
if( m_DirSide[ii] ) if( m_DirSide[ii] )
{ {
MyFree( m_DirSide[ii] ); m_DirSide[ii] = NULL; MyFree( m_DirSide[ii] );
m_DirSide[ii] = NULL;
} }
/***** de-allocate Distances matrix *****/ /***** de-allocate Distances matrix *****/
if( m_DistSide[ii] ) if( m_DistSide[ii] )
{ {
MyFree( m_DistSide[ii] ); m_DistSide[ii] = NULL; MyFree( m_DistSide[ii] );
m_DistSide[ii] = NULL;
} }
/**** de-allocate cells matrix *****/ /**** de-allocate cells matrix *****/
if( m_BoardSide[ii] ) if( m_BoardSide[ii] )
{ {
MyFree( m_BoardSide[ii] ); m_BoardSide[ii] = NULL; MyFree( m_BoardSide[ii] );
m_BoardSide[ii] = NULL;
} }
} }
...@@ -168,10 +176,10 @@ void PlaceCells( BOARD* aPcb, int net_code, int flag ) ...@@ -168,10 +176,10 @@ void PlaceCells( BOARD* aPcb, int net_code, int flag )
if( net_code != pad->GetNet() || (flag & FORCE_PADS) ) if( net_code != pad->GetNet() || (flag & FORCE_PADS) )
{ {
Place_1_Pad_Board( aPcb, pad, HOLE, marge, WRITE_CELL ); ::PlacePad( aPcb, pad, HOLE, marge, WRITE_CELL );
} }
Place_1_Pad_Board( aPcb, pad, VIA_IMPOSSIBLE, via_marge, WRITE_OR_CELL ); ::PlacePad( aPcb, pad, VIA_IMPOSSIBLE, via_marge, WRITE_OR_CELL );
} }
// Place outlines of modules on matrix routing, if they are on a copper layer // Place outlines of modules on matrix routing, if they are on a copper layer
...@@ -250,7 +258,8 @@ void PlaceCells( BOARD* aPcb, int net_code, int flag ) ...@@ -250,7 +258,8 @@ void PlaceCells( BOARD* aPcb, int net_code, int flag )
break; break;
EDA_RECT textbox = PtText->GetTextBox( -1 ); EDA_RECT textbox = PtText->GetTextBox( -1 );
ux0 = textbox.GetX(); uy0 = textbox.GetY(); ux0 = textbox.GetX();
uy0 = textbox.GetY();
dx = textbox.GetWidth(); dx = textbox.GetWidth();
dy = textbox.GetHeight(); dy = textbox.GetHeight();
...@@ -310,7 +319,7 @@ int Build_Work( BOARD* Pcb ) ...@@ -310,7 +319,7 @@ int Build_Work( BOARD* Pcb )
{ {
pt_rats = &Pcb->m_FullRatsnest[ii]; pt_rats = &Pcb->m_FullRatsnest[ii];
/* We consider her only ratsnets that are active ( obviously not yet routed) /* We consider her only ratsnest that are active ( obviously not yet routed)
* and routables (that are not yet attempt to be routed and fail * and routables (that are not yet attempt to be routed and fail
*/ */
if( (pt_rats->m_Status & CH_ACTIF) == 0 ) if( (pt_rats->m_Status & CH_ACTIF) == 0 )
......
/**
* @file cell.h
*/
#ifndef _CELL_H_
#define _CELL_H_
/* Bits characterizing cell */ /* Bits characterizing cell */
#define HOLE 0x01 /* a conducting hole or obstacle */ #define HOLE 0x01 /* a conducting hole or obstacle */
#define CELL_is_MODULE 0x02 /* auto placement occupied by a module */ #define CELL_is_MODULE 0x02 /* auto placement occupied by a module */
#define CELL_is_EDGE 0x20 /* Area and auto-placement: limiting cell #define CELL_is_EDGE 0x20 /* Area and auto-placement: limiting cell contour (Board, Zone) */
* contour (Board, Zone) */ #define CELL_is_FRIEND 0x40 /* Area and auto-placement: cell part of the net */
#define CELL_is_FRIEND 0x40 /* Area and auto-placement: cell part of the
* net */
#define CELL_is_ZONE 0x80 /* Area and auto-placement: cell available */ #define CELL_is_ZONE 0x80 /* Area and auto-placement: cell available */
/* Bit masks for presence of obstacles to autorouting */ /* Bit masks for presence of obstacles to autorouting */
...@@ -74,3 +80,7 @@ ...@@ -74,3 +80,7 @@
#define FROM_WEST 7 #define FROM_WEST 7
#define FROM_NORTHWEST 8 #define FROM_NORTHWEST 8
#define FROM_OTHERSIDE 9 #define FROM_OTHERSIDE 9
#endif // _CELL_H_
...@@ -12,7 +12,11 @@ ...@@ -12,7 +12,11 @@
#include "class_board_design_settings.h" #include "class_board_design_settings.h"
class BOARD;
class ZONE_CONTAINER; class ZONE_CONTAINER;
class SEGZONE;
class TRACK;
class PCB_EDIT_FRAME;
// buffer of item candidates when search for items on the same track. // buffer of item candidates when search for items on the same track.
...@@ -1183,7 +1187,7 @@ public: ...@@ -1183,7 +1187,7 @@ public:
/** /**
* Function MarkTrace * Function MarkTrace
* marks a chain of trace segments, connected to \aaTrace. * marks a chain of trace segments, connected to \a aTrace.
* <p> * <p>
* Each segment is marked by setting the BUSY bit into m_Flags. Electrical * Each segment is marked by setting the BUSY bit into m_Flags. Electrical
* continuity is detected by walking each segment, and finally the segments * continuity is detected by walking each segment, and finally the segments
......
/** /**
* @file class_edge_module.h * @file class_edge_mod.h
* @brief EDGE_MODULE class definition. * @brief EDGE_MODULE class definition.
*/ */
......
/**********************************/ /**
/* classes to handle copper zones */ * @file class_zone.h
/**********************************/ * @brief Classes to handle copper zones
*/
#ifndef CLASS_ZONE_H #ifndef CLASS_ZONE_H
#define CLASS_ZONE_H #define CLASS_ZONE_H
#include <vector> #include <vector>
#include "gr_basic.h" #include "gr_basic.h"
#include "PolyLine.h" #include "PolyLine.h"
...@@ -12,15 +14,25 @@ ...@@ -12,15 +14,25 @@
#include "class_zone_setting.h" #include "class_zone_setting.h"
class EDA_RECT;
class EDA_DRAW_FRAME;
class EDA_DRAW_PANEL;
class PCB_EDIT_FRAME;
class BOARD;
class BOARD_CONNECTED_ITEM;
class ZONE_CONTAINER;
/* a small class used when filling areas with segments */ /* a small class used when filling areas with segments */
class SEGMENT class SEGMENT
{ {
public: public:
wxPoint m_Start; // starting point of a segment wxPoint m_Start; // starting point of a segment
wxPoint m_End; // ending point of a segment wxPoint m_End; // ending point of a segment
public: public:
SEGMENT() {} SEGMENT() {}
SEGMENT( const wxPoint & aStart, const wxPoint & aEnd) SEGMENT( const wxPoint& aStart, const wxPoint& aEnd)
{ {
m_Start = aStart; m_Start = aStart;
m_End = aEnd; m_End = aEnd;
......
/** /**
* @file edit_track_width.cpp * @file edit_track_width.cpp
* @breif Functions to modify sizes of segment, track, net , all vias and/or all tracks * @brief Functions to modify sizes of segment, track, net, all vias and/or all tracks.
*/ */
#include "fctsys.h" #include "fctsys.h"
......
/****************************************************/ /**
/* PCB EDITOR: autorouting and "graphics" routines. */ * @file graphpcb.cpp
/****************************************************/ * @brief PCB editor autorouting and "graphics" routines.
*/
#include "fctsys.h" #include "fctsys.h"
#include "common.h" #include "common.h"
#include "pcbnew.h" #include "pcbnew.h"
#include "autorout.h"
#include "trigo.h" #include "trigo.h"
#include "cell.h" #include "cell.h"
#include "ar_protos.h"
int ToMatrixCoordinate( int aPhysicalCoordinate ); int ToMatrixCoordinate( int aPhysicalCoordinate );
void TraceLignePcb( int x0,
int y0, void TracePcbLine( int x0, int y0, int x1, int y1, int layer, int color );
int x1,
int y1,
int layer,
int color );
void TraceArc( int ux0, void TraceArc( int ux0,
int uy0, int uy0,
int ux1, int ux1,
...@@ -25,7 +23,7 @@ void TraceArc( int ux0, ...@@ -25,7 +23,7 @@ void TraceArc( int ux0,
int lg, int lg,
int layer, int layer,
int color, int color,
int op_logique ); int op_logic );
static void DrawSegmentQcq( int ux0, static void DrawSegmentQcq( int ux0,
...@@ -35,17 +33,18 @@ static void DrawSegmentQcq( int ux0, ...@@ -35,17 +33,18 @@ static void DrawSegmentQcq( int ux0,
int lg, int lg,
int layer, int layer,
int color, int color,
int op_logique ); int op_logic );
static void TraceFilledCercle( BOARD* Pcb, static void TraceFilledCircle( BOARD* Pcb,
int cx, int cx,
int cy, int cy,
int radius, int radius,
int aLayerMask, int aLayerMask,
int color, int color,
int op_logique ); int op_logic );
static void TraceCercle( int ux0, int uy0, int ux1, int uy1, int lg, int layer,
int color, int op_logique ); static void TraceCircle( int ux0, int uy0, int ux1, int uy1, int lg, int layer,
int color, int op_logic );
/* Macro call to update cell. */ /* Macro call to update cell. */
#define OP_CELL( layer, dy, dx ) \ #define OP_CELL( layer, dy, dx ) \
...@@ -79,35 +78,24 @@ int ToMatrixCoordinate( int aPhysicalCoordinate ) ...@@ -79,35 +78,24 @@ int ToMatrixCoordinate( int aPhysicalCoordinate )
} }
/* Initialize a color value, the cells included in the board edge of the void PlacePad( BOARD* Pcb, D_PAD* pt_pad, int color, int marge, int op_logic )
* pad surface by pt_pad, with the margin reserved for isolation and the
* half width of the runway
* Parameters:
* Pt_pad: pointer to the description of the pad
* color: mask write in cells
* margin: add a value to the radius or half the score pad
* op_logique: type of writing in the cell (WRITE, OR)
*/
void Place_1_Pad_Board( BOARD* Pcb,
D_PAD* pt_pad,
int color,
int marge,
int op_logique )
{ {
int dx, dy; int dx, dy;
wxPoint shape_pos = pt_pad->ReturnShapePos(); wxPoint shape_pos = pt_pad->ReturnShapePos();
dx = pt_pad->m_Size.x / 2; dx += marge; dx = pt_pad->m_Size.x / 2;
dx += marge;
if( pt_pad->m_PadShape == PAD_CIRCLE ) if( pt_pad->m_PadShape == PAD_CIRCLE )
{ {
TraceFilledCercle( Pcb, shape_pos.x, shape_pos.y, dx, TraceFilledCircle( Pcb, shape_pos.x, shape_pos.y, dx,
pt_pad->m_layerMask, color, op_logique ); pt_pad->m_layerMask, color, op_logic );
return; return;
} }
dy = pt_pad->m_Size.y / 2; dy += marge; dy = pt_pad->m_Size.y / 2;
dy += marge;
if( pt_pad->m_PadShape == PAD_TRAPEZOID ) if( pt_pad->m_PadShape == PAD_TRAPEZOID )
{ {
...@@ -126,33 +114,33 @@ void Place_1_Pad_Board( BOARD* Pcb, ...@@ -126,33 +114,33 @@ void Place_1_Pad_Board( BOARD* Pcb,
TraceFilledRectangle( Pcb, shape_pos.x - dx, shape_pos.y - dy, TraceFilledRectangle( Pcb, shape_pos.x - dx, shape_pos.y - dy,
shape_pos.x + dx, shape_pos.y + dy, shape_pos.x + dx, shape_pos.y + dy,
pt_pad->m_layerMask, color, op_logique ); pt_pad->m_layerMask, color, op_logic );
} }
else else
{ {
TraceFilledRectangle( Pcb, shape_pos.x - dx, shape_pos.y - dy, TraceFilledRectangle( Pcb, shape_pos.x - dx, shape_pos.y - dy,
shape_pos.x + dx, shape_pos.y + dy, shape_pos.x + dx, shape_pos.y + dy,
(int) pt_pad->m_Orient, (int) pt_pad->m_Orient,
pt_pad->m_layerMask, color, op_logique ); pt_pad->m_layerMask, color, op_logic );
} }
} }
/* Initialize a color value, the cells included in the board rea of the /* Initialize a color value, the cells included in the board area of the
* circle center cx, cy. * circle center cx, cy.
* Parameters: * Parameters:
* radius: a value add to the radius or half the score pad * radius: a value add to the radius or half the score pad
* aLayerMask: layer occupied * aLayerMask: layer occupied
* color: mask write in cells * color: mask write in cells
* op_logique: type of writing in the cell (WRITE, OR) * op_logic: type of writing in the cell (WRITE, OR)
*/ */
void TraceFilledCercle( BOARD* Pcb, void TraceFilledCircle( BOARD* Pcb,
int cx, int cx,
int cy, int cy,
int radius, int radius,
int aLayerMask, int aLayerMask,
int color, int color,
int op_logique ) int op_logic )
{ {
int row, col; int row, col;
int ux0, uy0, ux1, uy1; int ux0, uy0, ux1, uy1;
...@@ -179,7 +167,7 @@ void TraceFilledCercle( BOARD* Pcb, ...@@ -179,7 +167,7 @@ void TraceFilledCercle( BOARD* Pcb,
if( trace == 0 ) if( trace == 0 )
return; return;
switch( op_logique ) switch( op_logic )
{ {
default: default:
case WRITE_CELL: case WRITE_CELL:
...@@ -217,23 +205,25 @@ void TraceFilledCercle( BOARD* Pcb, ...@@ -217,23 +205,25 @@ void TraceFilledCercle( BOARD* Pcb,
/* Calculate limit coordinates of cells belonging to the rectangle. */ /* Calculate limit coordinates of cells belonging to the rectangle. */
row_max = uy1 / Board.m_GridRouting; row_max = uy1 / Board.m_GridRouting;
col_max = ux1 / Board.m_GridRouting; col_max = ux1 / Board.m_GridRouting;
row_min = uy0 / Board.m_GridRouting; // if (uy0 > row_min*Board.m_GridRouting row_min = uy0 / Board.m_GridRouting; // if (uy0 > row_min*Board.m_GridRouting) row_min++;
// ) row_min++; col_min = ux0 / Board.m_GridRouting; // if (ux0 > col_min*Board.m_GridRouting) col_min++;
col_min = ux0 / Board.m_GridRouting; // if (ux0 > col_min*Board.m_GridRouting
// ) col_min++;
if( row_min < 0 ) if( row_min < 0 )
row_min = 0; row_min = 0;
if( row_max >= (Nrows - 1) ) if( row_max >= (Nrows - 1) )
row_max = Nrows - 1; row_max = Nrows - 1;
if( col_min < 0 ) if( col_min < 0 )
col_min = 0; col_min = 0;
if( col_max >= (Ncols - 1) ) if( col_max >= (Ncols - 1) )
col_max = Ncols - 1; col_max = Ncols - 1;
/* Calculate coordinate limits of cell belonging to the rectangle. */ /* Calculate coordinate limits of cell belonging to the rectangle. */
if( row_min > row_max ) if( row_min > row_max )
row_max = row_min; row_max = row_min;
if( col_min > col_max ) if( col_min > col_max )
col_max = col_min; col_max = col_min;
...@@ -243,6 +233,7 @@ void TraceFilledCercle( BOARD* Pcb, ...@@ -243,6 +233,7 @@ void TraceFilledCercle( BOARD* Pcb,
{ {
fdisty = (float) ( cy - ( row * Board.m_GridRouting ) ); fdisty = (float) ( cy - ( row * Board.m_GridRouting ) );
fdisty *= fdisty; fdisty *= fdisty;
for( col = col_min; col <= col_max; col++ ) for( col = col_min; col <= col_max; col++ )
{ {
fdistx = (float) ( cx - ( col * Board.m_GridRouting ) ); fdistx = (float) ( cx - ( col * Board.m_GridRouting ) );
...@@ -253,8 +244,10 @@ void TraceFilledCercle( BOARD* Pcb, ...@@ -253,8 +244,10 @@ void TraceFilledCercle( BOARD* Pcb,
if( trace & 1 ) if( trace & 1 )
WriteCell( row, col, BOTTOM, color ); WriteCell( row, col, BOTTOM, color );
if( trace & 2 ) if( trace & 2 )
WriteCell( row, col, TOP, color ); WriteCell( row, col, TOP, color );
tstwrite = 1; tstwrite = 1;
} }
} }
...@@ -266,13 +259,13 @@ void TraceFilledCercle( BOARD* Pcb, ...@@ -266,13 +259,13 @@ void TraceFilledCercle( BOARD* Pcb,
* (Adverse event: pad off grid in the center of the 4 neighboring * (Adverse event: pad off grid in the center of the 4 neighboring
* diagonal) */ * diagonal) */
distmin = Board.m_GridRouting / 2 + 1; distmin = Board.m_GridRouting / 2 + 1;
fdistmin = ( (float) distmin * distmin ) * 2; /* Distance to center point fdistmin = ( (float) distmin * distmin ) * 2; /* Distance to center point diagonally */
* diagonally */
for( row = row_min; row <= row_max; row++ ) for( row = row_min; row <= row_max; row++ )
{ {
fdisty = (float) ( cy - ( row * Board.m_GridRouting ) ); fdisty = (float) ( cy - ( row * Board.m_GridRouting ) );
fdisty *= fdisty; fdisty *= fdisty;
for( col = col_min; col <= col_max; col++ ) for( col = col_min; col <= col_max; col++ )
{ {
fdistx = (float) ( cx - ( col * Board.m_GridRouting ) ); fdistx = (float) ( cx - ( col * Board.m_GridRouting ) );
...@@ -283,6 +276,7 @@ void TraceFilledCercle( BOARD* Pcb, ...@@ -283,6 +276,7 @@ void TraceFilledCercle( BOARD* Pcb,
if( trace & 1 ) if( trace & 1 )
WriteCell( row, col, BOTTOM, color ); WriteCell( row, col, BOTTOM, color );
if( trace & 2 ) if( trace & 2 )
WriteCell( row, col, TOP, color ); WriteCell( row, col, TOP, color );
} }
...@@ -290,18 +284,12 @@ void TraceFilledCercle( BOARD* Pcb, ...@@ -290,18 +284,12 @@ void TraceFilledCercle( BOARD* Pcb,
} }
/* Draws a segment of track on the BOARD. void TraceSegmentPcb( BOARD* Pcb, TRACK* pt_segm, int color, int marge, int op_logic )
*/
void TraceSegmentPcb( BOARD* Pcb,
TRACK* pt_segm,
int color,
int marge,
int op_logique )
{ {
int demi_largeur; int half_width;
int ux0, uy0, ux1, uy1; int ux0, uy0, ux1, uy1;
demi_largeur = ( pt_segm->m_Width / 2 ) + marge; half_width = ( pt_segm->m_Width / 2 ) + marge;
/* Calculate the bounding rectangle of the segment (if H, V or Via) */ /* Calculate the bounding rectangle of the segment (if H, V or Via) */
ux0 = pt_segm->m_Start.x - Pcb->m_BoundaryBox.m_Pos.x; ux0 = pt_segm->m_Start.x - Pcb->m_BoundaryBox.m_Pos.x;
...@@ -313,8 +301,10 @@ void TraceSegmentPcb( BOARD* Pcb, ...@@ -313,8 +301,10 @@ void TraceSegmentPcb( BOARD* Pcb,
if( pt_segm->Type() == TYPE_VIA ) if( pt_segm->Type() == TYPE_VIA )
{ {
int mask_layer = 0; int mask_layer = 0;
if( pt_segm->IsOnLayer( Route_Layer_BOTTOM ) ) if( pt_segm->IsOnLayer( Route_Layer_BOTTOM ) )
mask_layer = 1 << Route_Layer_BOTTOM; mask_layer = 1 << Route_Layer_BOTTOM;
if( pt_segm->IsOnLayer( Route_Layer_TOP ) ) if( pt_segm->IsOnLayer( Route_Layer_TOP ) )
{ {
if( mask_layer == 0 ) if( mask_layer == 0 )
...@@ -327,63 +317,52 @@ void TraceSegmentPcb( BOARD* Pcb, ...@@ -327,63 +317,52 @@ void TraceSegmentPcb( BOARD* Pcb,
mask_layer = -1; mask_layer = -1;
if( mask_layer ) if( mask_layer )
TraceFilledCercle( Pcb, pt_segm->m_Start.x, pt_segm->m_Start.y, TraceFilledCircle( Pcb, pt_segm->m_Start.x, pt_segm->m_Start.y,
demi_largeur, mask_layer, color, op_logique ); half_width, mask_layer, color, op_logic );
return; return;
} }
int layer = pt_segm->GetLayer(); int layer = pt_segm->GetLayer();
if( color == VIA_IMPOSSIBLE ) if( color == VIA_IMPOSSIBLE )
layer = -1; layer = -1;
/* The segment is here a straight line or a circle or an arc.: */ /* The segment is here a straight line or a circle or an arc.: */
if( pt_segm->m_Shape == S_CIRCLE ) if( pt_segm->m_Shape == S_CIRCLE )
{ {
TraceCercle( ux0, uy0, ux1, uy1, demi_largeur, layer, color, TraceCircle( ux0, uy0, ux1, uy1, half_width, layer, color, op_logic );
op_logique );
return; return;
} }
if( pt_segm->m_Shape == S_ARC ) if( pt_segm->m_Shape == S_ARC )
{ {
TraceArc( ux0, uy0, ux1, uy1, pt_segm->m_Param, demi_largeur, layer, TraceArc( ux0, uy0, ux1, uy1, pt_segm->m_Param, half_width, layer, color, op_logic );
color, op_logique );
return; return;
} }
/* The segment is here a line segment. */ /* The segment is here a line segment. */
if( ( ux0 != ux1 ) && ( uy0 != uy1 ) ) // Segment tilts. if( ( ux0 != ux1 ) && ( uy0 != uy1 ) ) // Segment tilts.
{ {
DrawSegmentQcq( ux0, uy0, ux1, uy1, demi_largeur, layer, color, DrawSegmentQcq( ux0, uy0, ux1, uy1, half_width, layer, color, op_logic );
op_logique );
return; return;
} }
// The segment is horizontal or vertical. // The segment is horizontal or vertical.
// DrawHVSegment(ux0,uy0,ux1,uy1,demi_largeur,layer,color,op_logique);
// F4EXB 051018-01 // F4EXB 051018-01
DrawSegmentQcq( ux0, uy0, ux1, uy1, demi_largeur, layer, color, DrawSegmentQcq( ux0, uy0, ux1, uy1, half_width, layer, color, op_logic );
op_logique ); // F4EXB 051018-01
return; // F4EXB 051018-01
} }
/* Draws a line, if layer = -1 on all layers /* Draws a line, if layer = -1 on all layers
*/ */
void TraceLignePcb( int x0, void TracePcbLine( int x0, int y0, int x1, int y1, int layer, int color, int op_logic )
int y0,
int x1,
int y1,
int layer,
int color,
int op_logique )
{ {
int dx, dy, lim; int dx, dy, lim;
int cumul, inc, il, delta; int cumul, inc, il, delta;
void (* WriteCell)( int, int, int, MATRIX_CELL ); void (* WriteCell)( int, int, int, MATRIX_CELL );
switch( op_logique ) switch( op_logic )
{ {
default: default:
case WRITE_CELL: case WRITE_CELL:
...@@ -406,16 +385,21 @@ void TraceLignePcb( int x0, ...@@ -406,16 +385,21 @@ void TraceLignePcb( int x0,
{ {
if( y1 < y0 ) if( y1 < y0 )
EXCHG( y0, y1 ); EXCHG( y0, y1 );
dy = y0 / Board.m_GridRouting; dy = y0 / Board.m_GridRouting;
lim = y1 / Board.m_GridRouting; lim = y1 / Board.m_GridRouting;
dx = x0 / Board.m_GridRouting; dx = x0 / Board.m_GridRouting;
/* Clipping limits of board. */ /* Clipping limits of board. */
if( ( dx < 0 ) || ( dx >= Ncols ) ) if( ( dx < 0 ) || ( dx >= Ncols ) )
return; return;
if( dy < 0 ) if( dy < 0 )
dy = 0; dy = 0;
if( lim >= Nrows ) if( lim >= Nrows )
lim = Nrows - 1; lim = Nrows - 1;
for( ; dy <= lim; dy++ ) for( ; dy <= lim; dy++ )
{ {
OP_CELL( layer, dy, dx ); OP_CELL( layer, dy, dx );
...@@ -428,16 +412,21 @@ void TraceLignePcb( int x0, ...@@ -428,16 +412,21 @@ void TraceLignePcb( int x0,
{ {
if( x1 < x0 ) if( x1 < x0 )
EXCHG( x0, x1 ); EXCHG( x0, x1 );
dx = x0 / Board.m_GridRouting; dx = x0 / Board.m_GridRouting;
lim = x1 / Board.m_GridRouting; lim = x1 / Board.m_GridRouting;
dy = y0 / Board.m_GridRouting; dy = y0 / Board.m_GridRouting;
/* Clipping limits of board. */ /* Clipping limits of board. */
if( ( dy < 0 ) || ( dy >= Nrows ) ) if( ( dy < 0 ) || ( dy >= Nrows ) )
return; return;
if( dx < 0 ) if( dx < 0 )
dx = 0; dx = 0;
if( lim >= Ncols ) if( lim >= Ncols )
lim = Ncols - 1; lim = Ncols - 1;
for( ; dx <= lim; dx++ ) for( ; dx <= lim; dx++ )
{ {
OP_CELL( layer, dy, dx ); OP_CELL( layer, dy, dx );
...@@ -457,15 +446,17 @@ void TraceLignePcb( int x0, ...@@ -457,15 +446,17 @@ void TraceLignePcb( int x0,
dx = x0 / Board.m_GridRouting; dx = x0 / Board.m_GridRouting;
lim = x1 / Board.m_GridRouting; lim = x1 / Board.m_GridRouting;
dy = y0 / Board.m_GridRouting; dy = y0 / Board.m_GridRouting;
inc = 1; if( y1 < y0 ) inc = 1;
if( y1 < y0 )
inc = -1; inc = -1;
il = lim - dx; cumul = il / 2; il = lim - dx; cumul = il / 2;
delta = abs( y1 - y0 ) / Board.m_GridRouting; delta = abs( y1 - y0 ) / Board.m_GridRouting;
for( ; dx <= lim; ) for( ; dx <= lim; )
{ {
if( ( dx >= 0 ) && ( dy >= 0 ) if( ( dx >= 0 ) && ( dy >= 0 ) && ( dx < Ncols ) && ( dy < Nrows ) )
&& ( dx < Ncols ) && ( dy < Nrows ) )
{ {
OP_CELL( layer, dy, dx ); OP_CELL( layer, dy, dx );
} }
...@@ -492,6 +483,7 @@ void TraceLignePcb( int x0, ...@@ -492,6 +483,7 @@ void TraceLignePcb( int x0,
lim = y1 / Board.m_GridRouting; lim = y1 / Board.m_GridRouting;
dx = x0 / Board.m_GridRouting; dx = x0 / Board.m_GridRouting;
inc = 1; inc = 1;
if( x1 < x0 ) if( x1 < x0 )
inc = -1; inc = -1;
...@@ -500,8 +492,7 @@ void TraceLignePcb( int x0, ...@@ -500,8 +492,7 @@ void TraceLignePcb( int x0,
for( ; dy <= lim; ) for( ; dy <= lim; )
{ {
if( ( dx >= 0 ) && ( dy >= 0 ) if( ( dx >= 0 ) && ( dy >= 0 ) && ( dx < Ncols ) && ( dy < Nrows ) )
&& ( dx < Ncols ) && ( dy < Nrows ) )
{ {
OP_CELL( layer, dy, dx ); OP_CELL( layer, dy, dx );
} }
...@@ -519,16 +510,8 @@ void TraceLignePcb( int x0, ...@@ -519,16 +510,8 @@ void TraceLignePcb( int x0,
} }
/* Overloaded functions.
*
* Uses the color value of all cells included in the board coordinate of
* the rectangle ux0, uy0 (top left corner)
* A UX1, UY1 (bottom right corner)
* The rectangle is horizontal (or vertical)
* Contact PCBs.
*/
void TraceFilledRectangle( BOARD* Pcb, int ux0, int uy0, int ux1, int uy1, void TraceFilledRectangle( BOARD* Pcb, int ux0, int uy0, int ux1, int uy1,
int aLayerMask, int color, int op_logique ) int aLayerMask, int color, int op_logic )
{ {
int row, col; int row, col;
int row_min, row_max, col_min, col_max; int row_min, row_max, col_min, col_max;
...@@ -545,7 +528,7 @@ void TraceFilledRectangle( BOARD* Pcb, int ux0, int uy0, int ux1, int uy1, ...@@ -545,7 +528,7 @@ void TraceFilledRectangle( BOARD* Pcb, int ux0, int uy0, int ux1, int uy1,
if( trace == 0 ) if( trace == 0 )
return; return;
switch( op_logique ) switch( op_logic )
{ {
default: default:
case WRITE_CELL: case WRITE_CELL:
...@@ -578,18 +561,24 @@ void TraceFilledRectangle( BOARD* Pcb, int ux0, int uy0, int ux1, int uy1, ...@@ -578,18 +561,24 @@ void TraceFilledRectangle( BOARD* Pcb, int ux0, int uy0, int ux1, int uy1,
row_max = uy1 / Board.m_GridRouting; row_max = uy1 / Board.m_GridRouting;
col_max = ux1 / Board.m_GridRouting; col_max = ux1 / Board.m_GridRouting;
row_min = uy0 / Board.m_GridRouting; row_min = uy0 / Board.m_GridRouting;
if( uy0 > row_min * Board.m_GridRouting ) if( uy0 > row_min * Board.m_GridRouting )
row_min++; row_min++;
col_min = ux0 / Board.m_GridRouting; col_min = ux0 / Board.m_GridRouting;
if( ux0 > col_min * Board.m_GridRouting ) if( ux0 > col_min * Board.m_GridRouting )
col_min++; col_min++;
if( row_min < 0 ) if( row_min < 0 )
row_min = 0; row_min = 0;
if( row_max >= ( Nrows - 1 ) ) if( row_max >= ( Nrows - 1 ) )
row_max = Nrows - 1; row_max = Nrows - 1;
if( col_min < 0 ) if( col_min < 0 )
col_min = 0; col_min = 0;
if( col_max >= ( Ncols - 1 ) ) if( col_max >= ( Ncols - 1 ) )
col_max = Ncols - 1; col_max = Ncols - 1;
...@@ -599,6 +588,7 @@ void TraceFilledRectangle( BOARD* Pcb, int ux0, int uy0, int ux1, int uy1, ...@@ -599,6 +588,7 @@ void TraceFilledRectangle( BOARD* Pcb, int ux0, int uy0, int ux1, int uy1,
{ {
if( trace & 1 ) if( trace & 1 )
WriteCell( row, col, BOTTOM, color ); WriteCell( row, col, BOTTOM, color );
if( trace & 2 ) if( trace & 2 )
WriteCell( row, col, TOP, color ); WriteCell( row, col, TOP, color );
} }
...@@ -606,17 +596,8 @@ void TraceFilledRectangle( BOARD* Pcb, int ux0, int uy0, int ux1, int uy1, ...@@ -606,17 +596,8 @@ void TraceFilledRectangle( BOARD* Pcb, int ux0, int uy0, int ux1, int uy1,
} }
/* Overloaded functions.
*
* Uses the color value of all cells included in the board coordinate of the
* rectangle ux0, uy0 (top right corner)
* a UX1, UY1 (lower left corner)
* the rectangle is the value of turning angle (in degrees 0.1)
* contact PCBs.
*/
void TraceFilledRectangle( BOARD* Pcb, int ux0, int uy0, int ux1, int uy1, void TraceFilledRectangle( BOARD* Pcb, int ux0, int uy0, int ux1, int uy1,
int angle, int aLayerMask, int color, int angle, int aLayerMask, int color, int op_logic )
int op_logique )
{ {
int row, col; int row, col;
int cx, cy; /* Center of rectangle */ int cx, cy; /* Center of rectangle */
...@@ -631,13 +612,15 @@ void TraceFilledRectangle( BOARD* Pcb, int ux0, int uy0, int ux1, int uy1, ...@@ -631,13 +612,15 @@ void TraceFilledRectangle( BOARD* Pcb, int ux0, int uy0, int ux1, int uy1,
trace = 1; /* Trace on BOTTOM */ trace = 1; /* Trace on BOTTOM */
if( aLayerMask & g_TabOneLayerMask[Route_Layer_TOP] ) if( aLayerMask & g_TabOneLayerMask[Route_Layer_TOP] )
{
if( Nb_Sides ) if( Nb_Sides )
trace |= 2; /* Trace on TOP */ trace |= 2; /* Trace on TOP */
}
if( trace == 0 ) if( trace == 0 )
return; return;
switch( op_logique ) switch( op_logic )
{ {
default: default:
case WRITE_CELL: case WRITE_CELL:
...@@ -675,18 +658,24 @@ void TraceFilledRectangle( BOARD* Pcb, int ux0, int uy0, int ux1, int uy1, ...@@ -675,18 +658,24 @@ void TraceFilledRectangle( BOARD* Pcb, int ux0, int uy0, int ux1, int uy1,
row_max = ( cy + radius ) / Board.m_GridRouting; row_max = ( cy + radius ) / Board.m_GridRouting;
col_max = ( cx + radius ) / Board.m_GridRouting; col_max = ( cx + radius ) / Board.m_GridRouting;
row_min = ( cy - radius ) / Board.m_GridRouting; row_min = ( cy - radius ) / Board.m_GridRouting;
if( uy0 > row_min * Board.m_GridRouting ) if( uy0 > row_min * Board.m_GridRouting )
row_min++; row_min++;
col_min = ( cx - radius ) / Board.m_GridRouting; col_min = ( cx - radius ) / Board.m_GridRouting;
if( ux0 > col_min * Board.m_GridRouting ) if( ux0 > col_min * Board.m_GridRouting )
col_min++; col_min++;
if( row_min < 0 ) if( row_min < 0 )
row_min = 0; row_min = 0;
if( row_max >= ( Nrows - 1 ) ) if( row_max >= ( Nrows - 1 ) )
row_max = Nrows - 1; row_max = Nrows - 1;
if( col_min < 0 ) if( col_min < 0 )
col_min = 0; col_min = 0;
if( col_max >= ( Ncols - 1 ) ) if( col_max >= ( Ncols - 1 ) )
col_max = Ncols - 1; col_max = Ncols - 1;
...@@ -697,16 +686,22 @@ void TraceFilledRectangle( BOARD* Pcb, int ux0, int uy0, int ux1, int uy1, ...@@ -697,16 +686,22 @@ void TraceFilledRectangle( BOARD* Pcb, int ux0, int uy0, int ux1, int uy1,
rotrow = row * Board.m_GridRouting; rotrow = row * Board.m_GridRouting;
rotcol = col * Board.m_GridRouting; rotcol = col * Board.m_GridRouting;
RotatePoint( &rotcol, &rotrow, cx, cy, -angle ); RotatePoint( &rotcol, &rotrow, cx, cy, -angle );
if( rotrow <= uy0 ) if( rotrow <= uy0 )
continue; continue;
if( rotrow >= uy1 ) if( rotrow >= uy1 )
continue; continue;
if( rotcol <= ux0 ) if( rotcol <= ux0 )
continue; continue;
if( rotcol >= ux1 ) if( rotcol >= ux1 )
continue; continue;
if( trace & 1 ) if( trace & 1 )
WriteCell( row, col, BOTTOM, color ); WriteCell( row, col, BOTTOM, color );
if( trace & 2 ) if( trace & 2 )
WriteCell( row, col, TOP, color ); WriteCell( row, col, TOP, color );
} }
...@@ -720,7 +715,7 @@ void TraceFilledRectangle( BOARD* Pcb, int ux0, int uy0, int ux1, int uy1, ...@@ -720,7 +715,7 @@ void TraceFilledRectangle( BOARD* Pcb, int ux0, int uy0, int ux1, int uy1,
* coordinates are in PCB units (0.1 mil) are relative to the Board * coordinates are in PCB units (0.1 mil) are relative to the Board
*/ */
void DrawSegmentQcq( int ux0, int uy0, int ux1, int uy1, int lg, int layer, void DrawSegmentQcq( int ux0, int uy0, int ux1, int uy1, int lg, int layer,
int color, int op_logique ) int color, int op_logic )
{ {
int row, col; int row, col;
int inc; int inc;
...@@ -731,7 +726,7 @@ void DrawSegmentQcq( int ux0, int uy0, int ux1, int uy1, int lg, int layer, ...@@ -731,7 +726,7 @@ void DrawSegmentQcq( int ux0, int uy0, int ux1, int uy1, int lg, int layer,
int angle; int angle;
int cx, cy, dx, dy; int cx, cy, dx, dy;
switch( op_logique ) switch( op_logic )
{ {
default: default:
case WRITE_CELL: case WRITE_CELL:
...@@ -764,15 +759,19 @@ void DrawSegmentQcq( int ux0, int uy0, int ux1, int uy1, int lg, int layer, ...@@ -764,15 +759,19 @@ void DrawSegmentQcq( int ux0, int uy0, int ux1, int uy1, int lg, int layer,
/* Calculating the incrementing the Y axis */ /* Calculating the incrementing the Y axis */
inc = 1; inc = 1;
if( uy1 < uy0 ) if( uy1 < uy0 )
inc = -1; inc = -1;
demi_pas = Board.m_GridRouting / 2; demi_pas = Board.m_GridRouting / 2;
col_min = ( ux0 - lg ) / Board.m_GridRouting; col_min = ( ux0 - lg ) / Board.m_GridRouting;
if( col_min < 0 ) if( col_min < 0 )
col_min = 0; col_min = 0;
col_max = ( ux1 + lg + demi_pas ) / Board.m_GridRouting; col_max = ( ux1 + lg + demi_pas ) / Board.m_GridRouting;
if( col_max > ( Ncols - 1 ) ) if( col_max > ( Ncols - 1 ) )
col_max = Ncols - 1; col_max = Ncols - 1;
...@@ -789,10 +788,13 @@ void DrawSegmentQcq( int ux0, int uy0, int ux1, int uy1, int lg, int layer, ...@@ -789,10 +788,13 @@ void DrawSegmentQcq( int ux0, int uy0, int ux1, int uy1, int lg, int layer,
if( row_min < 0 ) if( row_min < 0 )
row_min = 0; row_min = 0;
if( row_min > ( Nrows - 1 ) ) if( row_min > ( Nrows - 1 ) )
row_min = Nrows - 1; row_min = Nrows - 1;
if( row_max < 0 ) if( row_max < 0 )
row_max = 0; row_max = 0;
if( row_max > ( Nrows - 1 ) ) if( row_max > ( Nrows - 1 ) )
row_max = Nrows - 1; row_max = Nrows - 1;
...@@ -800,24 +802,30 @@ void DrawSegmentQcq( int ux0, int uy0, int ux1, int uy1, int lg, int layer, ...@@ -800,24 +802,30 @@ void DrawSegmentQcq( int ux0, int uy0, int ux1, int uy1, int lg, int layer,
dy = uy1 - uy0; dy = uy1 - uy0;
if( dx ) if( dx )
{
angle = (int) ( atan2( (double) dy, (double) dx ) * 1800 / M_PI ); angle = (int) ( atan2( (double) dy, (double) dx ) * 1800 / M_PI );
}
else else
{ {
angle = 900; angle = 900;
if( dy < 0 ) if( dy < 0 )
angle = -900; angle = -900;
} }
RotatePoint( &dx, &dy, angle ); /* dx = length, dy = 0 */ RotatePoint( &dx, &dy, angle ); /* dx = length, dy = 0 */
for( col = col_min; col <= col_max; col++ ) for( col = col_min; col <= col_max; col++ )
{ {
int cxr; int cxr;
cxr = ( col * Board.m_GridRouting ) - ux0; cxr = ( col * Board.m_GridRouting ) - ux0;
for( row = row_min; row <= row_max; row++ ) for( row = row_min; row <= row_max; row++ )
{ {
cy = (row * Board.m_GridRouting) - uy0; cy = (row * Board.m_GridRouting) - uy0;
cx = cxr; cx = cxr;
RotatePoint( &cx, &cy, angle ); RotatePoint( &cx, &cy, angle );
if( abs( cy ) > lg ) if( abs( cy ) > lg )
continue; /* The point is too far on the Y axis. */ continue; /* The point is too far on the Y axis. */
...@@ -829,18 +837,21 @@ void DrawSegmentQcq( int ux0, int uy0, int ux1, int uy1, int lg, int layer, ...@@ -829,18 +837,21 @@ void DrawSegmentQcq( int ux0, int uy0, int ux1, int uy1, int lg, int layer,
OP_CELL( layer, row, col ); OP_CELL( layer, row, col );
continue; continue;
} }
/* Examination of extremities are rounded. */ /* Examination of extremities are rounded. */
if( ( cx < 0 ) && ( cx >= -lg ) ) if( ( cx < 0 ) && ( cx >= -lg ) )
{ {
if( ( ( cx * cx ) + ( cy * cy ) ) <= ( lg * lg ) ) if( ( ( cx * cx ) + ( cy * cy ) ) <= ( lg * lg ) )
OP_CELL( layer, row, col ); OP_CELL( layer, row, col );
continue; continue;
} }
if( ( cx > dx ) && ( cx <= ( dx + lg ) ) ) if( ( cx > dx ) && ( cx <= ( dx + lg ) ) )
{ {
if( ( ( ( cx - dx ) * ( cx - dx ) ) + ( cy * cy ) ) if( ( ( ( cx - dx ) * ( cx - dx ) ) + ( cy * cy ) ) <= ( lg * lg ) )
<= ( lg * lg ) )
OP_CELL( layer, row, col ); OP_CELL( layer, row, col );
continue; continue;
} }
} }
...@@ -853,8 +864,8 @@ void DrawSegmentQcq( int ux0, int uy0, int ux1, int uy1, int lg, int layer, ...@@ -853,8 +864,8 @@ void DrawSegmentQcq( int ux0, int uy0, int ux1, int uy1, int lg, int layer,
* coord in PCB units (0.1 million) relating to the origin * coord in PCB units (0.1 million) relating to the origin
* pt_pcb-> m_PcbBox.m_Xmin, Y's board. * pt_pcb-> m_PcbBox.m_Xmin, Y's board.
*/ */
void TraceCercle( int ux0, int uy0, int ux1, int uy1, int lg, int layer, void TraceCircle( int ux0, int uy0, int ux1, int uy1, int lg, int layer,
int color, int op_logique ) int color, int op_logic )
{ {
int radius, nb_segm; int radius, nb_segm;
int x0, y0, // Starting point of the current segment trace. int x0, y0, // Starting point of the current segment trace.
...@@ -866,36 +877,38 @@ void TraceCercle( int ux0, int uy0, int ux1, int uy1, int lg, int layer, ...@@ -866,36 +877,38 @@ void TraceCercle( int ux0, int uy0, int ux1, int uy1, int lg, int layer,
x0 = x1 = radius; x0 = x1 = radius;
y0 = y1 = 0; y0 = y1 = 0;
if( lg < 1 ) if( lg < 1 )
lg = 1; lg = 1;
nb_segm = ( 2 * radius ) / lg; nb_segm = ( 2 * radius ) / lg;
if( nb_segm < 5 ) if( nb_segm < 5 )
nb_segm = 5; nb_segm = 5;
if( nb_segm > 100 ) if( nb_segm > 100 )
nb_segm = 100; nb_segm = 100;
for( ii = 1; ii < nb_segm; ii++ ) for( ii = 1; ii < nb_segm; ii++ )
{ {
angle = (3600 * ii) / nb_segm; angle = (3600 * ii) / nb_segm;
x1 = (int) ( radius * fcosinus[angle] ); x1 = (int) ( radius * cos( DEG2RAD( (double)angle / 10.0 ) ) );
y1 = (int) ( radius * fsinus[angle] ); y1 = (int) ( radius * sin( DEG2RAD( (double)angle / 10.0 ) ) );
DrawSegmentQcq( x0 + ux0, y0 + uy0, x1 + ux0, y1 + uy0, lg, DrawSegmentQcq( x0 + ux0, y0 + uy0, x1 + ux0, y1 + uy0, lg, layer, color, op_logic );
layer, color, op_logique );
x0 = x1; x0 = x1;
y0 = y1; y0 = y1;
} }
DrawSegmentQcq( x1 + ux0, y1 + uy0, ux0 + radius, uy0, lg, layer, DrawSegmentQcq( x1 + ux0, y1 + uy0, ux0 + radius, uy0, lg, layer, color, op_logic );
color, op_logique );
} }
/* Fills all cells contained in arc with color , using op_logique. /* Fills all BOARD cells contained in the arc of "L" angle half-width lg
* half-width lg ux center, starting in ux y0, y1 is set to color. * ux center, starting in ux y0, y1 is set to color. Coordinates are in
* coord in PCB units (0.1 mil) relating to the origin * PCB units (0.1 mil) relating to the origin pt_pcb-> Pcb_oX, Y's board.
* of the board.
*/ */
void TraceArc( int ux0, int uy0, int ux1, int uy1, int ArcAngle, int lg, void TraceArc( int ux0, int uy0, int ux1, int uy1, int ArcAngle, int lg,
int layer, int color, int op_logique ) int layer, int color, int op_logic )
{ {
int radius, nb_segm; int radius, nb_segm;
int x0, y0, // Starting point of the current segment trace int x0, y0, // Starting point of the current segment trace
...@@ -909,12 +922,16 @@ void TraceArc( int ux0, int uy0, int ux1, int uy1, int ArcAngle, int lg, ...@@ -909,12 +922,16 @@ void TraceArc( int ux0, int uy0, int ux1, int uy1, int ArcAngle, int lg,
x0 = ux1 - ux0; x0 = ux1 - ux0;
y0 = uy1 - uy0; y0 = uy1 - uy0;
StAngle = ArcTangente( uy1 - uy0, ux1 - ux0 ); StAngle = ArcTangente( uy1 - uy0, ux1 - ux0 );
if( lg < 1 ) if( lg < 1 )
lg = 1; lg = 1;
nb_segm = ( 2 * radius ) / lg; nb_segm = ( 2 * radius ) / lg;
nb_segm = ( nb_segm * abs( ArcAngle ) ) / 3600; nb_segm = ( nb_segm * abs( ArcAngle ) ) / 3600;
if( nb_segm < 5 ) if( nb_segm < 5 )
nb_segm = 5; nb_segm = 5;
if( nb_segm > 100 ) if( nb_segm > 100 )
nb_segm = 100; nb_segm = 100;
...@@ -929,14 +946,10 @@ void TraceArc( int ux0, int uy0, int ux1, int uy1, int ArcAngle, int lg, ...@@ -929,14 +946,10 @@ void TraceArc( int ux0, int uy0, int ux1, int uy1, int ArcAngle, int lg,
while( angle < 0 ) while( angle < 0 )
angle += 3600; angle += 3600;
x1 = (int) ( radius * fcosinus[angle] ); x1 = (int) ( radius * cos( DEG2RAD( (double)angle / 10.0 ) ) );
y1 = (int) ( radius * fsinus[angle] ); y1 = (int) ( radius * sin( DEG2RAD( (double)angle / 10.0 ) ) );
DrawSegmentQcq( x0 + ux0, y0 + uy0, x1 + ux0, y1 + uy0, lg, layer, DrawSegmentQcq( x0 + ux0, y0 + uy0, x1 + ux0, y1 + uy0, lg, layer, color, op_logic );
color, op_logique );
x0 = x1; x0 = x1;
y0 = y1; y0 = y1;
} }
// DrawSegmentQcq(x1+ux0,y1+uy0, ux0+radius, uy0,lg,layer, color,
// op_logique);
} }
...@@ -623,10 +623,16 @@ void PCB_EDIT_FRAME::unitsChangeRefresh() ...@@ -623,10 +623,16 @@ void PCB_EDIT_FRAME::unitsChangeRefresh()
} }
void PCB_EDIT_FRAME::SetElementVisibility( int aPCB_VISIBLE, bool aNewState ) bool PCB_EDIT_FRAME::IsElementVisible( int aElement )
{ {
GetBoard()->SetElementVisibility( aPCB_VISIBLE, aNewState ); return GetBoard()->IsElementVisible( aElement );
m_Layers->SetRenderState( aPCB_VISIBLE, aNewState ); }
void PCB_EDIT_FRAME::SetElementVisibility( int aElement, bool aNewState )
{
GetBoard()->SetElementVisibility( aElement, aNewState );
m_Layers->SetRenderState( aElement, aNewState );
} }
......
/*************/ /**
/* solve.cpp */ * @file solve.cpp
/*************/ */
#include "fctsys.h" #include "fctsys.h"
#include "class_drawpanel.h" #include "class_drawpanel.h"
#include "confirm.h" #include "confirm.h"
#include "autorout.h"
#include "wxPcbStruct.h"
#include "pcbnew.h" #include "pcbnew.h"
#include "wxPcbStruct.h"
#include "class_board_design_settings.h" #include "class_board_design_settings.h"
#include "autorout.h"
#include "protos.h" #include "protos.h"
#include "ar_protos.h"
#include "cell.h" #include "cell.h"
...@@ -22,7 +22,7 @@ static int Autoroute_One_Track( PCB_EDIT_FRAME* pcbframe, ...@@ -22,7 +22,7 @@ static int Autoroute_One_Track( PCB_EDIT_FRAME* pcbframe,
int col_source, int col_source,
int row_target, int row_target,
int col_target, int col_target,
RATSNEST_ITEM* pt_chevelu ); RATSNEST_ITEM* pt_rat );
static int Retrace( PCB_EDIT_FRAME* pcbframe, static int Retrace( PCB_EDIT_FRAME* pcbframe,
wxDC* DC, wxDC* DC,
...@@ -372,7 +372,7 @@ static int Autoroute_One_Track( PCB_EDIT_FRAME* pcbframe, ...@@ -372,7 +372,7 @@ static int Autoroute_One_Track( PCB_EDIT_FRAME* pcbframe,
int col_source, int col_source,
int row_target, int row_target,
int col_target, int col_target,
RATSNEST_ITEM* pt_chevelu ) RATSNEST_ITEM* pt_rat )
{ {
int r, c, side, d, apx_dist, nr, nc; int r, c, side, d, apx_dist, nr, nc;
int result, skip; int result, skip;
...@@ -412,8 +412,8 @@ static int Autoroute_One_Track( PCB_EDIT_FRAME* pcbframe, ...@@ -412,8 +412,8 @@ static int Autoroute_One_Track( PCB_EDIT_FRAME* pcbframe,
/* Set active layers mask. */ /* Set active layers mask. */
routeLayerMask = topLayerMask | bottomLayerMask; routeLayerMask = topLayerMask | bottomLayerMask;
pt_cur_ch = pt_chevelu; pt_cur_ch = pt_rat;
current_net_code = pt_chevelu->GetNet(); current_net_code = pt_rat->GetNet();
padLayerMaskStart = pt_cur_ch->m_PadStart->m_layerMask; padLayerMaskStart = pt_cur_ch->m_PadStart->m_layerMask;
padLayerMaskEnd = pt_cur_ch->m_PadEnd->m_layerMask; padLayerMaskEnd = pt_cur_ch->m_PadEnd->m_layerMask;
...@@ -474,13 +474,10 @@ static int Autoroute_One_Track( PCB_EDIT_FRAME* pcbframe, ...@@ -474,13 +474,10 @@ static int Autoroute_One_Track( PCB_EDIT_FRAME* pcbframe,
/* Placing the bit to remove obstacles on 2 pads to a link. */ /* Placing the bit to remove obstacles on 2 pads to a link. */
pcbframe->SetStatusText( wxT( "Gen Cells" ) ); pcbframe->SetStatusText( wxT( "Gen Cells" ) );
Place_1_Pad_Board( pcbframe->GetBoard(), pt_cur_ch->m_PadStart, PlacePad( pcbframe->GetBoard(), pt_cur_ch->m_PadStart, CURRENT_PAD, marge, WRITE_OR_CELL );
CURRENT_PAD, marge, WRITE_OR_CELL ); PlacePad( pcbframe->GetBoard(), pt_cur_ch->m_PadEnd, CURRENT_PAD, marge, WRITE_OR_CELL );
Place_1_Pad_Board( pcbframe->GetBoard(), pt_cur_ch->m_PadEnd,
CURRENT_PAD, marge, WRITE_OR_CELL );
/* Regenerates the remaining barriers (which may encroach on the placement /* Regenerates the remaining barriers (which may encroach on the placement bits precedent)
* bits precedent)
*/ */
i = pcbframe->GetBoard()->GetPadsCount(); i = pcbframe->GetBoard()->GetPadsCount();
...@@ -491,7 +488,7 @@ static int Autoroute_One_Track( PCB_EDIT_FRAME* pcbframe, ...@@ -491,7 +488,7 @@ static int Autoroute_One_Track( PCB_EDIT_FRAME* pcbframe,
if( ( pt_cur_ch->m_PadStart != ptr ) && ( pt_cur_ch->m_PadEnd != ptr ) ) if( ( pt_cur_ch->m_PadStart != ptr ) && ( pt_cur_ch->m_PadEnd != ptr ) )
{ {
Place_1_Pad_Board( pcbframe->GetBoard(), ptr, ~CURRENT_PAD, marge, WRITE_AND_CELL ); PlacePad( pcbframe->GetBoard(), ptr, ~CURRENT_PAD, marge, WRITE_AND_CELL );
} }
} }
...@@ -624,6 +621,7 @@ static int Autoroute_One_Track( PCB_EDIT_FRAME* pcbframe, ...@@ -624,6 +621,7 @@ static int Autoroute_One_Track( PCB_EDIT_FRAME* pcbframe,
for( i = 0; i < 8; i++ ) for( i = 0; i < 8; i++ )
{ {
selfok2[i].present = 0; selfok2[i].present = 0;
if( curcell & selfok2[i].trace ) if( curcell & selfok2[i].trace )
selfok2[i].present = 1; selfok2[i].present = 1;
} }
...@@ -631,7 +629,8 @@ static int Autoroute_One_Track( PCB_EDIT_FRAME* pcbframe, ...@@ -631,7 +629,8 @@ static int Autoroute_One_Track( PCB_EDIT_FRAME* pcbframe,
for( i = 0; i < 8; i++ ) /* consider neighbors */ for( i = 0; i < 8; i++ ) /* consider neighbors */
{ {
nr = r + delta[i][0]; nc = c + delta[i][1]; nr = r + delta[i][0];
nc = c + delta[i][1];
/* off the edge? */ /* off the edge? */
if( nr < 0 || nr >= Nrows || nc < 0 || nc >= Ncols ) if( nr < 0 || nr >= Nrows || nc < 0 || nc >= Ncols )
...@@ -781,10 +780,8 @@ static int Autoroute_One_Track( PCB_EDIT_FRAME* pcbframe, ...@@ -781,10 +780,8 @@ static int Autoroute_One_Track( PCB_EDIT_FRAME* pcbframe,
} }
end_of_route: end_of_route:
Place_1_Pad_Board( pcbframe->GetBoard(), pt_cur_ch->m_PadStart, PlacePad( pcbframe->GetBoard(), pt_cur_ch->m_PadStart, ~CURRENT_PAD, marge, WRITE_AND_CELL );
~CURRENT_PAD, marge, WRITE_AND_CELL ); PlacePad( pcbframe->GetBoard(), pt_cur_ch->m_PadEnd, ~CURRENT_PAD, marge, WRITE_AND_CELL );
Place_1_Pad_Board( pcbframe->GetBoard(), pt_cur_ch->m_PadEnd,
~CURRENT_PAD, marge, WRITE_AND_CELL );
msg.Printf( wxT( "Activity: Open %d Closed %d Moved %d"), msg.Printf( wxT( "Activity: Open %d Closed %d Moved %d"),
OpenNodes, ClosNodes, MoveNodes ); OpenNodes, ClosNodes, MoveNodes );
...@@ -986,8 +983,7 @@ static int Retrace( PCB_EDIT_FRAME* pcbframe, wxDC* DC, ...@@ -986,8 +983,7 @@ static int Retrace( PCB_EDIT_FRAME* pcbframe, wxDC* DC,
y = GetDir( r0, c0, s0 ); y = GetDir( r0, c0, s0 );
/* see if target or hole */ /* see if target or hole */
if( ( ( r1 == row_target ) && ( c1 == col_target ) ) if( ( ( r1 == row_target ) && ( c1 == col_target ) ) || ( s1 != s0 ) )
|| ( s1 != s0 ) )
{ {
int p_dir; int p_dir;
......
/************************/ /**
/* Autorouting routines */ * @file work.cpp
/************************/ * @brief Automatic routing routines
*/
#include "fctsys.h" #include "fctsys.h"
#include "common.h" #include "common.h"
#include "pcbnew.h" #include "pcbnew.h"
#include "autorout.h"
#include "cell.h" #include "cell.h"
#include "ar_protos.h"
struct CWORK /* a unit of work is a hole-pair to connect */ struct CWORK /* a unit of work is a hole-pair to connect */
...@@ -90,14 +91,18 @@ int SetWork( int r1, ...@@ -90,14 +91,18 @@ int SetWork( int r1,
p->Priority = pri; p->Priority = pri;
p->Next = NULL; p->Next = NULL;
if( Head ) /* attach at end */ if( Head ) /* attach at end */
Tail->Next = p; Tail->Next = p;
else /* first in list */ else /* first in list */
Head = Current = p; Head = Current = p;
Tail = p; Tail = p;
return 1; return 1;
} }
else /* can't get any more memory */ else /* can't get any more memory */
{
return 0; return 0;
}
} }
...@@ -137,12 +142,15 @@ void SortWork() ...@@ -137,12 +142,15 @@ void SortWork()
CWORK* r; CWORK* r;
q0 = q1 = NULL; q0 = q1 = NULL;
while( (p = Head) != NULL ) /* prioritize each work item */ while( (p = Head) != NULL ) /* prioritize each work item */
{ {
Head = Head->Next; Head = Head->Next;
if( p->Priority ) /* put at end of priority list */ if( p->Priority ) /* put at end of priority list */
{ {
p->Next = NULL; p->Next = NULL;
if( (r = q0) == NULL ) /* empty list? */ if( (r = q0) == NULL ) /* empty list? */
q0 = p; q0 = p;
else /* attach at end */ else /* attach at end */
...@@ -203,6 +211,7 @@ static int GetCost( int r1, int c1, int r2, int c2 ) ...@@ -203,6 +211,7 @@ static int GetCost( int r1, int c1, int r2, int c2 )
{ {
mx = dy; my = dx; mx = dy; my = dx;
} }
if( mx ) if( mx )
incl += (2 * (float) my / mx); incl += (2 * (float) my / mx);
......
...@@ -6,10 +6,11 @@ ...@@ -6,10 +6,11 @@
#include "class_drawpanel.h" #include "class_drawpanel.h"
#include "confirm.h" #include "confirm.h"
#include "kicad_string.h" #include "kicad_string.h"
#include "pcbnew.h"
#include "wxPcbStruct.h" #include "wxPcbStruct.h"
#include "pcbnew.h"
#include "dialog_exchange_modules_base.h" #include "dialog_exchange_modules_base.h"
#include "ar_protos.h"
int s_SelectionMode = 0; // Remember the last exchange option, when exit dialog. int s_SelectionMode = 0; // Remember the last exchange option, when exit dialog.
...@@ -145,7 +146,6 @@ int DIALOG_EXCHANGE_MODULE::Maj_ListeCmp( const wxString& reference, ...@@ -145,7 +146,6 @@ int DIALOG_EXCHANGE_MODULE::Maj_ListeCmp( const wxString& reference,
FILE* FichCmp, * NewFile; FILE* FichCmp, * NewFile;
char Line[1024]; char Line[1024];
wxString msg; wxString msg;
char* result; // quiet compiler
if( old_name == new_name ) if( old_name == new_name )
return 0; return 0;
...@@ -155,6 +155,7 @@ int DIALOG_EXCHANGE_MODULE::Maj_ListeCmp( const wxString& reference, ...@@ -155,6 +155,7 @@ int DIALOG_EXCHANGE_MODULE::Maj_ListeCmp( const wxString& reference,
fn.SetExt( NetCmpExtBuffer ); fn.SetExt( NetCmpExtBuffer );
FichCmp = wxFopen( fn.GetFullPath(), wxT( "rt" ) ); FichCmp = wxFopen( fn.GetFullPath(), wxT( "rt" ) );
if( FichCmp == NULL ) if( FichCmp == NULL )
{ {
if( ShowError ) if( ShowError )
...@@ -162,12 +163,14 @@ int DIALOG_EXCHANGE_MODULE::Maj_ListeCmp( const wxString& reference, ...@@ -162,12 +163,14 @@ int DIALOG_EXCHANGE_MODULE::Maj_ListeCmp( const wxString& reference,
msg.Printf( _( "file %s not found" ), GetChars( fn.GetFullPath() ) ); msg.Printf( _( "file %s not found" ), GetChars( fn.GetFullPath() ) );
m_WinMessages->AppendText( msg ); m_WinMessages->AppendText( msg );
} }
return 1; return 1;
} }
tmpFileName = fn; tmpFileName = fn;
tmpFileName.SetExt( wxT( "$$$" ) ); tmpFileName.SetExt( wxT( "$$$" ) );
NewFile = wxFopen( tmpFileName.GetFullPath(), wxT( "wt" ) ); NewFile = wxFopen( tmpFileName.GetFullPath(), wxT( "wt" ) );
if( NewFile == NULL ) if( NewFile == NULL )
{ {
if( ShowError ) if( ShowError )
...@@ -176,14 +179,15 @@ int DIALOG_EXCHANGE_MODULE::Maj_ListeCmp( const wxString& reference, ...@@ -176,14 +179,15 @@ int DIALOG_EXCHANGE_MODULE::Maj_ListeCmp( const wxString& reference,
GetChars( tmpFileName.GetFullPath() ) ); GetChars( tmpFileName.GetFullPath() ) );
m_WinMessages->AppendText( msg ); m_WinMessages->AppendText( msg );
} }
return 1; return 1;
} }
result = fgets( Line, sizeof(Line), FichCmp ); fgets( Line, sizeof(Line), FichCmp );
fprintf( NewFile, "Cmp-Mod V01 Genere par PcbNew le %s\n", fprintf( NewFile, "Cmp-Mod V01 Genere par PcbNew le %s\n", DateAndTime( Line ) );
DateAndTime( Line ) );
bool start_descr = false; bool start_descr = false;
while( fgets( Line, sizeof(Line), FichCmp ) != NULL ) while( fgets( Line, sizeof(Line), FichCmp ) != NULL )
{ {
if( strnicmp( Line, "Reference = ", 9 ) == 0 ) if( strnicmp( Line, "Reference = ", 9 ) == 0 )
...@@ -191,14 +195,14 @@ int DIALOG_EXCHANGE_MODULE::Maj_ListeCmp( const wxString& reference, ...@@ -191,14 +195,14 @@ int DIALOG_EXCHANGE_MODULE::Maj_ListeCmp( const wxString& reference,
char buf[1024]; char buf[1024];
strcpy( buf, Line + 12 ); strcpy( buf, Line + 12 );
strtok( buf, ";\n\r" ); strtok( buf, ";\n\r" );
if( stricmp( buf, TO_UTF8( reference ) ) == 0 ) if( stricmp( buf, TO_UTF8( reference ) ) == 0 )
{ {
start_descr = true; start_descr = true;
} }
} }
if( (strnicmp( Line, "Begin", 5 ) == 0) if( (strnicmp( Line, "Begin", 5 ) == 0) || (strnicmp( Line, "End", 3 ) == 0) )
|| (strnicmp( Line, "End", 3 ) == 0) )
{ {
start_descr = false; start_descr = false;
} }
...@@ -212,6 +216,7 @@ int DIALOG_EXCHANGE_MODULE::Maj_ListeCmp( const wxString& reference, ...@@ -212,6 +216,7 @@ int DIALOG_EXCHANGE_MODULE::Maj_ListeCmp( const wxString& reference,
start_descr = false; start_descr = false;
} }
fputs( Line, NewFile ); fputs( Line, NewFile );
} }
...@@ -243,6 +248,7 @@ void DIALOG_EXCHANGE_MODULE::Change_Current_Module() ...@@ -243,6 +248,7 @@ void DIALOG_EXCHANGE_MODULE::Change_Current_Module()
{ {
if( m_Parent->GetBoard()->IsElementVisible( RATSNEST_VISIBLE ) ) if( m_Parent->GetBoard()->IsElementVisible( RATSNEST_VISIBLE ) )
m_Parent->Compile_Ratsnest( NULL, true ); m_Parent->Compile_Ratsnest( NULL, true );
m_Parent->DrawPanel->Refresh(); m_Parent->DrawPanel->Refresh();
} }
...@@ -274,10 +280,12 @@ void DIALOG_EXCHANGE_MODULE::Change_ModuleId( bool aUseValue ) ...@@ -274,10 +280,12 @@ void DIALOG_EXCHANGE_MODULE::Change_ModuleId( bool aUseValue )
if( m_Parent->GetBoard()->m_Modules == NULL ) if( m_Parent->GetBoard()->m_Modules == NULL )
return; return;
if( newmodulename == wxEmptyString ) if( newmodulename == wxEmptyString )
return; return;
lib_reference = m_CurrentModule->m_LibRef; lib_reference = m_CurrentModule->m_LibRef;
if( aUseValue ) if( aUseValue )
{ {
check_module_value = true; check_module_value = true;
...@@ -305,16 +313,20 @@ void DIALOG_EXCHANGE_MODULE::Change_ModuleId( bool aUseValue ) ...@@ -305,16 +313,20 @@ void DIALOG_EXCHANGE_MODULE::Change_ModuleId( bool aUseValue )
* points the board or is NULL * points the board or is NULL
*/ */
Module = m_Parent->GetBoard()->m_Modules.GetLast(); Module = m_Parent->GetBoard()->m_Modules.GetLast();
for( ; Module && ( Module->Type() == TYPE_MODULE ); Module = PtBack ) for( ; Module && ( Module->Type() == TYPE_MODULE ); Module = PtBack )
{ {
PtBack = Module->Back(); PtBack = Module->Back();
if( lib_reference.CmpNoCase( Module->m_LibRef ) != 0 ) if( lib_reference.CmpNoCase( Module->m_LibRef ) != 0 )
continue; continue;
if( check_module_value ) if( check_module_value )
{ {
if( value.CmpNoCase( Module->m_Value->m_Text ) != 0 ) if( value.CmpNoCase( Module->m_Value->m_Text ) != 0 )
continue; continue;
} }
if( Change_1_Module( Module, newmodulename, &pickList, ShowErr ) ) if( Change_1_Module( Module, newmodulename, &pickList, ShowErr ) )
change = true; change = true;
else if( ShowErr ) else if( ShowErr )
...@@ -325,6 +337,7 @@ void DIALOG_EXCHANGE_MODULE::Change_ModuleId( bool aUseValue ) ...@@ -325,6 +337,7 @@ void DIALOG_EXCHANGE_MODULE::Change_ModuleId( bool aUseValue )
{ {
if( m_Parent->GetBoard()->IsElementVisible( RATSNEST_VISIBLE ) ) if( m_Parent->GetBoard()->IsElementVisible( RATSNEST_VISIBLE ) )
m_Parent->Compile_Ratsnest( NULL, true ); m_Parent->Compile_Ratsnest( NULL, true );
m_Parent->DrawPanel->Refresh(); m_Parent->DrawPanel->Refresh();
} }
...@@ -362,9 +375,11 @@ void DIALOG_EXCHANGE_MODULE::Change_ModuleAll() ...@@ -362,9 +375,11 @@ void DIALOG_EXCHANGE_MODULE::Change_ModuleAll()
* points the board or is NULL * points the board or is NULL
*/ */
Module = m_Parent->GetBoard()->m_Modules.GetLast(); Module = m_Parent->GetBoard()->m_Modules.GetLast();
for( ; Module && ( Module->Type() == TYPE_MODULE ); Module = PtBack ) for( ; Module && ( Module->Type() == TYPE_MODULE ); Module = PtBack )
{ {
PtBack = Module->Back(); PtBack = Module->Back();
if( Change_1_Module( Module, Module->m_LibRef, &pickList, ShowErr ) ) if( Change_1_Module( Module, Module->m_LibRef, &pickList, ShowErr ) )
change = true; change = true;
else if( ShowErr ) else if( ShowErr )
...@@ -375,8 +390,10 @@ void DIALOG_EXCHANGE_MODULE::Change_ModuleAll() ...@@ -375,8 +390,10 @@ void DIALOG_EXCHANGE_MODULE::Change_ModuleAll()
{ {
if( m_Parent->GetBoard()->IsElementVisible( RATSNEST_VISIBLE ) ) if( m_Parent->GetBoard()->IsElementVisible( RATSNEST_VISIBLE ) )
m_Parent->Compile_Ratsnest( NULL, true ); m_Parent->Compile_Ratsnest( NULL, true );
m_Parent->DrawPanel->Refresh(); m_Parent->DrawPanel->Refresh();
} }
if( pickList.GetCount() ) if( pickList.GetCount() )
m_Parent->SaveCopyInUndoList( pickList, UR_UNSPECIFIED ); m_Parent->SaveCopyInUndoList( pickList, UR_UNSPECIFIED );
} }
...@@ -434,10 +451,7 @@ bool DIALOG_EXCHANGE_MODULE::Change_1_Module( MODULE* Module, ...@@ -434,10 +451,7 @@ bool DIALOG_EXCHANGE_MODULE::Change_1_Module( MODULE* Module,
m_Parent->Exchange_Module( Module, NewModule, aUndoPickList ); m_Parent->Exchange_Module( Module, NewModule, aUndoPickList );
Maj_ListeCmp( NewModule->m_Reference->m_Text, Maj_ListeCmp( NewModule->m_Reference->m_Text, oldnamecmp, namecmp, ShowError );
oldnamecmp,
namecmp,
ShowError );
return true; return true;
} }
...@@ -460,8 +474,7 @@ void PCB_EDIT_FRAME::Exchange_Module( MODULE* aOldModule, ...@@ -460,8 +474,7 @@ void PCB_EDIT_FRAME::Exchange_Module( MODULE* aOldModule,
wxPoint oldpos; wxPoint oldpos;
D_PAD* pad, * old_pad; D_PAD* pad, * old_pad;
if( ( aOldModule->Type() != TYPE_MODULE ) if( ( aOldModule->Type() != TYPE_MODULE ) || ( aNewModule->Type() != TYPE_MODULE ) )
|| ( aNewModule->Type() != TYPE_MODULE ) )
{ {
wxMessageBox( wxT( "PCB_EDIT_FRAME::Exchange_Module() StuctType error" ) ); wxMessageBox( wxT( "PCB_EDIT_FRAME::Exchange_Module() StuctType error" ) );
return; return;
...@@ -501,15 +514,16 @@ void PCB_EDIT_FRAME::Exchange_Module( MODULE* aOldModule, ...@@ -501,15 +514,16 @@ void PCB_EDIT_FRAME::Exchange_Module( MODULE* aOldModule,
/* Update pad netnames ( when possible) */ /* Update pad netnames ( when possible) */
pad = aNewModule->m_Pads; pad = aNewModule->m_Pads;
for( ; pad != NULL; pad = pad->Next() ) for( ; pad != NULL; pad = pad->Next() )
{ {
pad->SetNetname( wxEmptyString ); pad->SetNetname( wxEmptyString );
pad->SetNet( 0 ); pad->SetNet( 0 );
old_pad = aOldModule->m_Pads; old_pad = aOldModule->m_Pads;
for( ; old_pad != NULL; old_pad = old_pad->Next() ) for( ; old_pad != NULL; old_pad = old_pad->Next() )
{ {
if( strnicmp( pad->m_Padname, old_pad->m_Padname, if( strnicmp( pad->m_Padname, old_pad->m_Padname, sizeof(pad->m_Padname) ) == 0 )
sizeof(pad->m_Padname) ) == 0 )
{ {
pad->SetNetname( old_pad->GetNetname() ); pad->SetNetname( old_pad->GetNetname() );
pad->SetNet( old_pad->GetNet() ); pad->SetNet( old_pad->GetNet() );
...@@ -526,7 +540,9 @@ void PCB_EDIT_FRAME::Exchange_Module( MODULE* aOldModule, ...@@ -526,7 +540,9 @@ void PCB_EDIT_FRAME::Exchange_Module( MODULE* aOldModule,
aUndoPickList->PushItem( picker_new ); aUndoPickList->PushItem( picker_new );
} }
else else
{
aOldModule->DeleteStructure(); aOldModule->DeleteStructure();
}
GetBoard()->m_Status_Pcb = 0; GetBoard()->m_Status_Pcb = 0;
aNewModule->m_Flags = 0; aNewModule->m_Flags = 0;
...@@ -564,7 +580,6 @@ void PCB_EDIT_FRAME::RecreateCmpFileFromBoard( wxCommandEvent& aEvent ) ...@@ -564,7 +580,6 @@ void PCB_EDIT_FRAME::RecreateCmpFileFromBoard( wxCommandEvent& aEvent )
MODULE* Module = GetBoard()->m_Modules; MODULE* Module = GetBoard()->m_Modules;
wxString msg; wxString msg;
wxString wildcard; wxString wildcard;
char* result; // quiet compiler
if( Module == NULL ) if( Module == NULL )
{ {
...@@ -575,8 +590,7 @@ void PCB_EDIT_FRAME::RecreateCmpFileFromBoard( wxCommandEvent& aEvent ) ...@@ -575,8 +590,7 @@ void PCB_EDIT_FRAME::RecreateCmpFileFromBoard( wxCommandEvent& aEvent )
/* Calculation file name by changing the extension name to NetList */ /* Calculation file name by changing the extension name to NetList */
fn = GetScreen()->GetFileName(); fn = GetScreen()->GetFileName();
fn.SetExt( NetCmpExtBuffer ); fn.SetExt( NetCmpExtBuffer );
wildcard = _( "Component files (." ) + NetCmpExtBuffer + wxT( ")|*." ) + wildcard = _( "Component files (." ) + NetCmpExtBuffer + wxT( ")|*." ) + NetCmpExtBuffer;
NetCmpExtBuffer;
wxFileDialog dlg( this, _( "Save Component Files" ), wxGetCwd(), wxFileDialog dlg( this, _( "Save Component Files" ), wxGetCwd(),
fn.GetFullName(), wildcard, fn.GetFullName(), wildcard,
...@@ -588,6 +602,7 @@ void PCB_EDIT_FRAME::RecreateCmpFileFromBoard( wxCommandEvent& aEvent ) ...@@ -588,6 +602,7 @@ void PCB_EDIT_FRAME::RecreateCmpFileFromBoard( wxCommandEvent& aEvent )
fn = dlg.GetPath(); fn = dlg.GetPath();
FichCmp = wxFopen( fn.GetFullPath(), wxT( "wt" ) ); FichCmp = wxFopen( fn.GetFullPath(), wxT( "wt" ) );
if( FichCmp == NULL ) if( FichCmp == NULL )
{ {
msg = _( "Unable to create file " ) + fn.GetFullPath(); msg = _( "Unable to create file " ) + fn.GetFullPath();
...@@ -595,9 +610,8 @@ void PCB_EDIT_FRAME::RecreateCmpFileFromBoard( wxCommandEvent& aEvent ) ...@@ -595,9 +610,8 @@ void PCB_EDIT_FRAME::RecreateCmpFileFromBoard( wxCommandEvent& aEvent )
return; return;
} }
result = fgets( Line, sizeof(Line), FichCmp ); fgets( Line, sizeof(Line), FichCmp );
fprintf( FichCmp, "Cmp-Mod V01 Genere par PcbNew le %s\n", fprintf( FichCmp, "Cmp-Mod V01 Genere par PcbNew le %s\n", DateAndTime( Line ) );
DateAndTime( Line ) );
for( ; Module != NULL; Module = Module->Next() ) for( ; Module != NULL; Module = Module->Next() )
{ {
...@@ -610,8 +624,7 @@ void PCB_EDIT_FRAME::RecreateCmpFileFromBoard( wxCommandEvent& aEvent ) ...@@ -610,8 +624,7 @@ void PCB_EDIT_FRAME::RecreateCmpFileFromBoard( wxCommandEvent& aEvent )
fprintf( FichCmp, "ValeurCmp = %s;\n", fprintf( FichCmp, "ValeurCmp = %s;\n",
!Module->m_Value->m_Text.IsEmpty() ? !Module->m_Value->m_Text.IsEmpty() ?
TO_UTF8( Module->m_Value->m_Text ) : "[NoVal]" ); TO_UTF8( Module->m_Value->m_Text ) : "[NoVal]" );
fprintf( FichCmp, "IdModule = %s;\n", fprintf( FichCmp, "IdModule = %s;\n", TO_UTF8( Module->m_LibRef ) );
TO_UTF8( Module->m_LibRef ) );
fprintf( FichCmp, "EndCmp\n" ); fprintf( FichCmp, "EndCmp\n" );
} }
......
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