Commit cc7e7fc5 authored by Wayne Stambaugh's avatar Wayne Stambaugh

Memory allocation improvements and other minor fixes.

* Replace C malloc() and free() functions with C++ new and delete
  operators or the appropriate STL container.
* Add option to end mouse capture function to skip executing the end
  mouse capture callback.
* Lots of coding policy and Doxygen comment goodness.
parent 7bd82846
///////////////////////////////////////////////////////////////////////////// /*
// Name: 3d_aux.cpp * This program source code file is part of KiCad, a free EDA CAD application.
///////////////////////////////////////////////////////////////////////////// *
* Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 1992-2011 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @file 3d_aux.cpp
*/
#include "fctsys.h" #include "fctsys.h"
...@@ -23,54 +48,53 @@ ...@@ -23,54 +48,53 @@
#include "trackball.h" #include "trackball.h"
void S3D_MASTER::Set_Object_Coords( S3D_Vertex* coord, int nbcoord ) void S3D_MASTER::Set_Object_Coords( std::vector< S3D_Vertex >& aVertices )
{ {
int ii; unsigned ii;
/* adjust object scale, rotation and offset position */ /* adjust object scale, rotation and offset position */
for( ii = 0; ii < nbcoord; ii++ ) for( ii = 0; ii < aVertices.size(); ii++ )
{ {
coord[ii].x *= m_MatScale.x; aVertices[ii].x *= m_MatScale.x;
coord[ii].y *= m_MatScale.y; aVertices[ii].y *= m_MatScale.y;
coord[ii].z *= m_MatScale.z; aVertices[ii].z *= m_MatScale.z;
/* adjust rotation */ /* adjust rotation */
if( m_MatRotation.x ) if( m_MatRotation.x )
RotatePoint( &coord[ii].y, &coord[ii].z, (int) (m_MatRotation.x * 10) ); RotatePoint( &aVertices[ii].y, &aVertices[ii].z, (int) (m_MatRotation.x * 10) );
if( m_MatRotation.y ) if( m_MatRotation.y )
RotatePoint( &coord[ii].z, &coord[ii].x, (int) (m_MatRotation.y * 10) ); RotatePoint( &aVertices[ii].z, &aVertices[ii].x, (int) (m_MatRotation.y * 10) );
if( m_MatRotation.z ) if( m_MatRotation.z )
RotatePoint( &coord[ii].x, &coord[ii].y, (int) (m_MatRotation.z * 10) ); RotatePoint( &aVertices[ii].x, &aVertices[ii].y, (int) (m_MatRotation.z * 10) );
/* adjust offset position (offset is given in UNIT 3D (0.1 inch) */ /* adjust offset position (offset is given in UNIT 3D (0.1 inch) */
#define SCALE_3D_CONV (PCB_INTERNAL_UNIT / UNITS3D_TO_UNITSPCB) #define SCALE_3D_CONV (PCB_INTERNAL_UNIT / UNITS3D_TO_UNITSPCB)
coord[ii].x += m_MatPosition.x * SCALE_3D_CONV; aVertices[ii].x += m_MatPosition.x * SCALE_3D_CONV;
coord[ii].y += m_MatPosition.y * SCALE_3D_CONV; aVertices[ii].y += m_MatPosition.y * SCALE_3D_CONV;
coord[ii].z += m_MatPosition.z * SCALE_3D_CONV; aVertices[ii].z += m_MatPosition.z * SCALE_3D_CONV;
} }
} }
void Set_Object_Data( const S3D_Vertex* coord, int nbcoord ) void Set_Object_Data( std::vector< S3D_Vertex >& aVertices )
{ {
int ii; unsigned ii;
GLfloat ax, ay, az, bx, by, bz, nx, ny, nz, r; GLfloat ax, ay, az, bx, by, bz, nx, ny, nz, r;
/* ignore faces with less than 3 points */ /* ignore faces with less than 3 points */
if( nbcoord < 3 ) if( aVertices.size() < 3 )
return; return;
/* calculate normal direction */ /* calculate normal direction */
ax = coord[1].x - coord[0].x; ax = aVertices[1].x - aVertices[0].x;
ay = coord[1].y - coord[0].y; ay = aVertices[1].y - aVertices[0].y;
az = coord[1].z - coord[0].z; az = aVertices[1].z - aVertices[0].z;
bx = coord[nbcoord - 1].x - coord[0].x; bx = aVertices[aVertices.size() - 1].x - aVertices[0].x;
by = coord[nbcoord - 1].y - coord[0].y; by = aVertices[aVertices.size() - 1].y - aVertices[0].y;
bz = coord[nbcoord - 1].z - coord[0].z; bz = aVertices[aVertices.size() - 1].z - aVertices[0].z;
nx = ay * bz - az * by; nx = ay * bz - az * by;
ny = az * bx - ax * bz; ny = az * bx - ax * bz;
...@@ -80,12 +104,14 @@ void Set_Object_Data( const S3D_Vertex* coord, int nbcoord ) ...@@ -80,12 +104,14 @@ void Set_Object_Data( const S3D_Vertex* coord, int nbcoord )
if( r >= 0.000001 ) /* avoid division by zero */ if( r >= 0.000001 ) /* avoid division by zero */
{ {
nx /= r; ny /= r; nz /= r; nx /= r;
ny /= r;
nz /= r;
glNormal3f( nx, ny, nz ); glNormal3f( nx, ny, nz );
} }
/* glBegin/glEnd */ /* glBegin/glEnd */
switch( nbcoord ) switch( aVertices.size() )
{ {
case 3: case 3:
glBegin( GL_TRIANGLES ); glBegin( GL_TRIANGLES );
...@@ -101,11 +127,11 @@ void Set_Object_Data( const S3D_Vertex* coord, int nbcoord ) ...@@ -101,11 +127,11 @@ void Set_Object_Data( const S3D_Vertex* coord, int nbcoord )
} }
/* draw polygon/triangle/quad */ /* draw polygon/triangle/quad */
for( ii = 0; ii < nbcoord; ii++ ) for( ii = 0; ii < aVertices.size(); ii++ )
{ {
glVertex3f( coord[ii].x * DataScale3D, glVertex3f( aVertices[ii].x * DataScale3D,
coord[ii].y * DataScale3D, aVertices[ii].y * DataScale3D,
coord[ii].z * DataScale3D ); aVertices[ii].z * DataScale3D );
} }
glEnd(); glEnd();
...@@ -150,10 +176,6 @@ GLuint EDA_3D_CANVAS::DisplayCubeforTest() ...@@ -150,10 +176,6 @@ GLuint EDA_3D_CANVAS::DisplayCubeforTest()
} }
/**********************/
/* class Info_3D_Visu */
/**********************/
Info_3D_Visu::Info_3D_Visu() Info_3D_Visu::Info_3D_Visu()
{ {
int ii; int ii;
...@@ -182,8 +204,6 @@ Info_3D_Visu::~Info_3D_Visu() ...@@ -182,8 +204,6 @@ Info_3D_Visu::~Info_3D_Visu()
} }
/* Display and edit a Vertex (triplet of values) in INCHES or MM or without
* units */
WinEDA_VertexCtrl::WinEDA_VertexCtrl( wxWindow* parent, const wxString& title, WinEDA_VertexCtrl::WinEDA_VertexCtrl( wxWindow* parent, const wxString& title,
wxBoxSizer* BoxSizer, wxBoxSizer* BoxSizer,
EDA_UNITS_T units, int internal_unit ) EDA_UNITS_T units, int internal_unit )
...@@ -262,7 +282,6 @@ WinEDA_VertexCtrl::~WinEDA_VertexCtrl() ...@@ -262,7 +282,6 @@ WinEDA_VertexCtrl::~WinEDA_VertexCtrl()
} }
/* Returns (in internal units) to coordinate between (in user units) */
S3D_Vertex WinEDA_VertexCtrl::GetValue() S3D_Vertex WinEDA_VertexCtrl::GetValue()
{ {
S3D_Vertex value; S3D_Vertex value;
......
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 1992-2011 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/** /**
* @file 3d_draw.cpp * @file 3d_draw.cpp
*/ */
...@@ -62,6 +87,7 @@ static void CALLBACK tessErrorCB( GLenum errorCode ); ...@@ -62,6 +87,7 @@ static void CALLBACK tessErrorCB( GLenum errorCode );
static void CALLBACK tessCPolyPt2Vertex( const GLvoid* data ); static void CALLBACK tessCPolyPt2Vertex( const GLvoid* data );
static void CALLBACK tesswxPoint2Vertex( const GLvoid* data ); static void CALLBACK tesswxPoint2Vertex( const GLvoid* data );
void EDA_3D_CANVAS::Redraw( bool finish ) void EDA_3D_CANVAS::Redraw( bool finish )
{ {
/* SwapBuffer requires the window to be shown before calling */ /* SwapBuffer requires the window to be shown before calling */
...@@ -118,8 +144,6 @@ void EDA_3D_CANVAS::Redraw( bool finish ) ...@@ -118,8 +144,6 @@ void EDA_3D_CANVAS::Redraw( bool finish )
} }
/* Create the draw list items
*/
GLuint EDA_3D_CANVAS::CreateDrawGL_List() GLuint EDA_3D_CANVAS::CreateDrawGL_List()
{ {
PCB_BASE_FRAME* pcbframe = m_Parent->m_Parent; PCB_BASE_FRAME* pcbframe = m_Parent->m_Parent;
...@@ -410,11 +434,6 @@ void EDA_3D_CANVAS::Draw3D_Track( TRACK* track ) ...@@ -410,11 +434,6 @@ void EDA_3D_CANVAS::Draw3D_Track( TRACK* track )
} }
/**
* Function Draw3D_SolidPolygonsInZones
* draw all solid polygons used as filles areas in a zone
* @param aZone = the zone to draw
*/
void EDA_3D_CANVAS::Draw3D_SolidPolygonsInZones( ZONE_CONTAINER* aZone ) void EDA_3D_CANVAS::Draw3D_SolidPolygonsInZones( ZONE_CONTAINER* aZone )
{ {
double zpos; double zpos;
...@@ -474,8 +493,6 @@ void EDA_3D_CANVAS::Draw3D_SolidPolygonsInZones( ZONE_CONTAINER* aZone ) ...@@ -474,8 +493,6 @@ void EDA_3D_CANVAS::Draw3D_SolidPolygonsInZones( ZONE_CONTAINER* aZone )
} }
/* 3D drawing for a VIA (cylinder + filled circles)
*/
void EDA_3D_CANVAS::Draw3D_Via( SEGVIA* via ) void EDA_3D_CANVAS::Draw3D_Via( SEGVIA* via )
{ {
double x, y, r, hole; double x, y, r, hole;
...@@ -603,15 +620,6 @@ void EDA_3D_CANVAS::Draw3D_DrawSegment( DRAWSEGMENT* segment ) ...@@ -603,15 +620,6 @@ void EDA_3D_CANVAS::Draw3D_DrawSegment( DRAWSEGMENT* segment )
} }
/* function to draw 3D segments, called by DrawGraphicText
* When DrawGraphicText is called to draw a text to an OpenGL DC
* it calls Draw3dTextSegm to each segment to draw.
* 2 parameters used by Draw3D_FilledSegment are not handled by DrawGraphicText
* but are used in Draw3D_FilledSegment().
* they are 2 local variables. This is an ugly, but trivial code.
* Using DrawGraphicText to draw all texts ensure texts have the same shape
* in all contexts
*/
static double s_Text3DWidth, s_Text3DZPos; static double s_Text3DWidth, s_Text3DZPos;
static void Draw3dTextSegm( int x0, int y0, int xf, int yf ) static void Draw3dTextSegm( int x0, int y0, int xf, int yf )
{ {
...@@ -1152,7 +1160,9 @@ static void Draw3D_FilledCylinder( double posx, double posy, double rayon, ...@@ -1152,7 +1160,9 @@ static void Draw3D_FilledCylinder( double posx, double posy, double rayon,
double x, y; double x, y;
#define NB_SEGM 12 #define NB_SEGM 12
S3D_Vertex coords[4]; std::vector< S3D_Vertex > coords;
coords.resize( 4 );
double tmp = DataScale3D; double tmp = DataScale3D;
DataScale3D = 1.0; // Coordinate is already in range for Set_Object_Data(); DataScale3D = 1.0; // Coordinate is already in range for Set_Object_Data();
...@@ -1168,7 +1178,7 @@ static void Draw3D_FilledCylinder( double posx, double posy, double rayon, ...@@ -1168,7 +1178,7 @@ static void Draw3D_FilledCylinder( double posx, double posy, double rayon,
RotatePoint( &x, &y, ii * (3600 / NB_SEGM) ); RotatePoint( &x, &y, ii * (3600 / NB_SEGM) );
coords[2].x = coords[3].x = posx + x; coords[2].x = coords[3].x = posx + x;
coords[2].y = coords[3].y = posy + y; coords[2].y = coords[3].y = posy + y;
Set_Object_Data( coords, 4 ); Set_Object_Data( coords );
coords[0].x = coords[2].x; coords[0].x = coords[2].x;
coords[0].y = coords[2].y; coords[0].y = coords[2].y;
coords[1].x = coords[3].x; coords[1].x = coords[3].x;
...@@ -1377,12 +1387,6 @@ static void Draw3D_CircleSegment( double startx, double starty, double endx, ...@@ -1377,12 +1387,6 @@ static void Draw3D_CircleSegment( double startx, double starty, double endx,
} }
/**
* Function Draw3D_Polygon
* draw one solid polygon
* @param aCornersList = a std::vector<wxPoint> list of corners, in physical coordinates
* @param aZpos = the z position in 3D units
*/
void EDA_3D_CANVAS::Draw3D_Polygon( std::vector<wxPoint>& aCornersList, double aZpos ) void EDA_3D_CANVAS::Draw3D_Polygon( std::vector<wxPoint>& aCornersList, double aZpos )
{ {
g_Parm_3D_Visu.m_ActZpos = aZpos; g_Parm_3D_Visu.m_ActZpos = aZpos;
......
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 1992-2011 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/** /**
* @file 3d_read_mesh.cpp * @file 3d_read_mesh.cpp
*/ */
#include "fctsys.h" #include "fctsys.h"
#include "common.h" #include "common.h"
...@@ -48,8 +73,7 @@ int S3D_MASTER::ReadData() ...@@ -48,8 +73,7 @@ int S3D_MASTER::ReadData()
return -1; return -1;
} }
// Switch the locale to standard C (needed to print floating point // Switch the locale to standard C (needed to print floating point numbers like 1.3)
// numbers like 1.3)
SetLocaleTo_C_standard(); SetLocaleTo_C_standard();
while( GetLine( file, line, &LineNum, 512 ) ) while( GetLine( file, line, &LineNum, 512 ) )
...@@ -82,20 +106,7 @@ int S3D_MASTER::ReadData() ...@@ -82,20 +106,7 @@ int S3D_MASTER::ReadData()
} }
/* int S3D_MASTER::ReadMaterial( FILE* file, int* LineNum )
* Analyzes the description of the type:
* DEF yellow material Material (
* DiffuseColor 1.00000 1.00000 0.00000e 0
* EmissiveColor 0.00000e 0 0.00000e 0 0.00000e 0
* SpecularColor 1.00000 1.00000 1.00000
* AmbientIntensity 1.00000
* Transparency 0.00000e 0
* Shininess 1.00000
*)
* Or type:
* USE yellow material
*/
int S3D_MASTER:: ReadMaterial( FILE* file, int* LineNum )
{ {
char line[512], * text, * command; char line[512], * text, * command;
wxString mat_name; wxString mat_name;
...@@ -282,7 +293,9 @@ int S3D_MASTER::ReadAppearance( FILE* file, int* LineNum ) ...@@ -282,7 +293,9 @@ int S3D_MASTER::ReadAppearance( FILE* file, int* LineNum )
#define BUFSIZE 2000 #define BUFSIZE 2000
/* Read a coordinate list like: /**
* Function ReadCoordList
* reads 3D coordinate lists like:
* coord Coordinate { point [ * coord Coordinate { point [
* -5.24489 6.57640e-3 -9.42129e-2, * -5.24489 6.57640e-3 -9.42129e-2,
* -5.11821 6.57421e-3 0.542654, * -5.11821 6.57421e-3 0.542654,
...@@ -294,14 +307,12 @@ int S3D_MASTER::ReadAppearance( FILE* file, int* LineNum ) ...@@ -294,14 +307,12 @@ int S3D_MASTER::ReadAppearance( FILE* file, int* LineNum )
* 0.707107 -9.38186e-7 0.707107] * 0.707107 -9.38186e-7 0.707107]
* } * }
* *
* Return the coordinate list
* text_buffer contains the first line of this node : * text_buffer contains the first line of this node :
* "coord Coordinate { point [" * "coord Coordinate { point ["
*/ */
double* ReadCoordsList( FILE* file, char* text_buffer, int* bufsize, int* LineNum ) void ReadCoordsList( FILE* file, char* text_buffer, std::vector< double >& aList, int* LineNum )
{ {
double* data_list = NULL; unsigned int ii = 0, jj = 0;
unsigned int ii = 0, jj = 0, nn = BUFSIZE;
char* text; char* text;
bool HasData = false; bool HasData = false;
bool StartData = false; bool StartData = false;
...@@ -324,8 +335,8 @@ double* ReadCoordsList( FILE* file, char* text_buffer, int* bufsize, int* LineNu ...@@ -324,8 +335,8 @@ double* ReadCoordsList( FILE* file, char* text_buffer, int* bufsize, int* LineNu
{ {
case '[': case '[':
StartData = true; StartData = true;
jj = 0; string_num[jj] = 0; jj = 0;
data_list = (double*) MyZMalloc( nn * sizeof(double) ); string_num[jj] = 0;
break; break;
case '}': case '}':
...@@ -341,33 +352,29 @@ double* ReadCoordsList( FILE* file, char* text_buffer, int* bufsize, int* LineNu ...@@ -341,33 +352,29 @@ double* ReadCoordsList( FILE* file, char* text_buffer, int* bufsize, int* LineNu
if( !StartData || !HasData ) if( !StartData || !HasData )
break; break;
data_list[ii] = atof( string_num ); aList.push_back( atof( string_num ) );
string_num[jj] = 0; string_num[jj] = 0;
ii++; ii++;
if( ii >= nn )
{
nn *= 2;
data_list = (double*) realloc( data_list, ( nn * sizeof(double) ) );
}
HasData = false; HasData = false;
if( *text == ']' ) if( *text == ']' )
{ {
StartData = false; StartData = false;
} }
break; break;
default: default:
if( !StartData ) if( !StartData )
break; break;
if( jj >= sizeof(string_num) ) if( jj >= sizeof( string_num ) )
break; break;
string_num[jj] = *text; string_num[jj] = *text;
jj++; string_num[jj] = 0; jj++;
string_num[jj] = 0;
HasData = true; HasData = true;
break; break;
} }
...@@ -375,14 +382,6 @@ double* ReadCoordsList( FILE* file, char* text_buffer, int* bufsize, int* LineNu ...@@ -375,14 +382,6 @@ double* ReadCoordsList( FILE* file, char* text_buffer, int* bufsize, int* LineNu
text++; text++;
} }
} }
if( data_list )
data_list = (double*) realloc( data_list, ( ii * sizeof(double) ) );
if( bufsize )
*bufsize = ii;
return data_list;
} }
...@@ -390,9 +389,8 @@ int S3D_MASTER::ReadGeometry( FILE* file, int* LineNum ) ...@@ -390,9 +389,8 @@ int S3D_MASTER::ReadGeometry( FILE* file, int* LineNum )
{ {
char line[1024], buffer[1024], * text; char line[1024], buffer[1024], * text;
int err = 1; int err = 1;
int nn = BUFSIZE; std::vector< double > points;
double* points = NULL; std::vector< double > list;
int* index = NULL;
while( GetLine( file, line, LineNum, 512 ) ) while( GetLine( file, line, LineNum, 512 ) )
{ {
...@@ -401,7 +399,8 @@ int S3D_MASTER::ReadGeometry( FILE* file, int* LineNum ) ...@@ -401,7 +399,8 @@ int S3D_MASTER::ReadGeometry( FILE* file, int* LineNum )
if( *text == '}' ) if( *text == '}' )
{ {
err = 0; break; err = 0;
break;
} }
if( stricmp( text, "normalPerVertex" ) == 0 ) if( stricmp( text, "normalPerVertex" ) == 0 )
...@@ -432,13 +431,11 @@ int S3D_MASTER::ReadGeometry( FILE* file, int* LineNum ) ...@@ -432,13 +431,11 @@ int S3D_MASTER::ReadGeometry( FILE* file, int* LineNum )
if( stricmp( text, "normal" ) == 0 ) if( stricmp( text, "normal" ) == 0 )
{ {
int coord_number; ReadCoordsList( file, line, list, LineNum );
double* buf_points = ReadCoordsList( file, line, &coord_number, LineNum ); list.clear();
// Do something if needed
free( buf_points );
continue; continue;
} }
if( stricmp( text, "normalIndex" ) == 0 ) if( stricmp( text, "normalIndex" ) == 0 )
{ {
while( GetLine( file, line, LineNum, 512 ) ) while( GetLine( file, line, LineNum, 512 ) )
...@@ -462,11 +459,8 @@ int S3D_MASTER::ReadGeometry( FILE* file, int* LineNum ) ...@@ -462,11 +459,8 @@ int S3D_MASTER::ReadGeometry( FILE* file, int* LineNum )
if( stricmp( text, "color" ) == 0 ) if( stricmp( text, "color" ) == 0 )
{ {
int coord_number; ReadCoordsList( file, line, list, LineNum );
double* buf_points = ReadCoordsList( file, line, &coord_number, LineNum ); list.clear();
// Do something if needed
free( buf_points );
continue; continue;
} }
...@@ -493,17 +487,24 @@ int S3D_MASTER::ReadGeometry( FILE* file, int* LineNum ) ...@@ -493,17 +487,24 @@ int S3D_MASTER::ReadGeometry( FILE* file, int* LineNum )
if( stricmp( text, "coord" ) == 0 ) if( stricmp( text, "coord" ) == 0 )
{ {
int coord_number; ReadCoordsList( file, line, points, LineNum );
points = ReadCoordsList( file, line, &coord_number, LineNum );
} }
else if( stricmp( text, "coordIndex" ) == 0 ) else if( stricmp( text, "coordIndex" ) == 0 )
{ {
index = (int*) MyMalloc( nn * sizeof(int) ); if( points.size() < 3 || points.size() % 3 != 0 )
S3D_Vertex* coords = (S3D_Vertex*) MyMalloc( nn * sizeof(S3D_Vertex) ); {
wxLogError( wxT( "3D geometry read error <%s> at line %d." ),
GetChars( FROM_UTF8( text ) ), *LineNum );
err = 1;
break;
}
std::vector< int > coordIndex;
std::vector< S3D_Vertex > vertices;
while( GetLine( file, line, LineNum, 512 ) ) while( GetLine( file, line, LineNum, 512 ) )
{ {
int coord_count = 0, jj; int jj;
text = strtok( line, " ,\t\n\r" ); text = strtok( line, " ,\t\n\r" );
while( text ) while( text )
...@@ -515,24 +516,33 @@ int S3D_MASTER::ReadGeometry( FILE* file, int* LineNum ) ...@@ -515,24 +516,33 @@ int S3D_MASTER::ReadGeometry( FILE* file, int* LineNum )
if( jj < 0 ) if( jj < 0 )
{ {
S3D_Vertex* curr_coord = coords; for( jj = 0; jj < (int) coordIndex.size(); jj++ )
{
int kk = coordIndex[jj] * 3;
for( jj = 0; jj < coord_count; jj++ ) if( (kk < 0) || ((kk + 3) > points.size()) )
{ {
int kk = index[jj] * 3; wxLogError( wxT( "3D geometry index read error <%s> at line %d." ),
curr_coord->x = points[kk]; GetChars( FROM_UTF8( text ) ), *LineNum );
curr_coord->y = points[kk + 1]; err = 1;
curr_coord->z = points[kk + 2]; break;
curr_coord++;
} }
Set_Object_Coords( coords, coord_count ); S3D_Vertex vertex;
Set_Object_Data( coords, coord_count ); vertex.x = points[kk];
coord_count = 0; vertex.y = points[kk + 1];
vertex.z = points[kk + 2];
vertices.push_back( vertex );
}
Set_Object_Coords( vertices );
Set_Object_Data( vertices );
vertices.clear();
coordIndex.clear();
} }
else else
{ {
index[coord_count++] = jj; coordIndex.push_back( jj );
} }
text = strtok( NULL, " ,\t\n\r" ); text = strtok( NULL, " ,\t\n\r" );
...@@ -541,20 +551,16 @@ int S3D_MASTER::ReadGeometry( FILE* file, int* LineNum ) ...@@ -541,20 +551,16 @@ int S3D_MASTER::ReadGeometry( FILE* file, int* LineNum )
if( text && (*text == ']') ) if( text && (*text == ']') )
break; break;
} }
free( index );
free( coords );
} }
else else
{ {
printf( "ReadGeometry error line %d <%s> \n", *LineNum, text ); wxLogError( wxT( "3D geometry read error <%s> at line %d." ),
GetChars( FROM_UTF8( text ) ), *LineNum );
err = 1;
break; break;
} }
} }
if( points )
free( points );
return err; return err;
} }
......
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 1992-2011 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/** /**
* @file 3d_struct.h * @file 3d_struct.h
*/ */
...@@ -32,7 +57,9 @@ class S3D_Vertex /* 3D coordinate (3 float numbers: x,y,z coordinates)*/ ...@@ -32,7 +57,9 @@ class S3D_Vertex /* 3D coordinate (3 float numbers: x,y,z coordinates)*/
{ {
public: public:
double x, y, z; double x, y, z;
public: S3D_Vertex();
public:
S3D_Vertex();
}; };
class S3D_MATERIAL : public EDA_ITEM /* openGL "material" data*/ class S3D_MATERIAL : public EDA_ITEM /* openGL "material" data*/
...@@ -46,7 +73,8 @@ public: ...@@ -46,7 +73,8 @@ public:
float m_Transparency; float m_Transparency;
float m_Shininess; float m_Shininess;
public: S3D_MATERIAL( S3D_MASTER* father, const wxString& name ); public:
S3D_MATERIAL( S3D_MASTER* father, const wxString& name );
S3D_MATERIAL* Next() const { return (S3D_MATERIAL*) Pnext; } S3D_MATERIAL* Next() const { return (S3D_MATERIAL*) Pnext; }
S3D_MATERIAL* Back() const { return (S3D_MATERIAL*) Pback; } S3D_MATERIAL* Back() const { return (S3D_MATERIAL*) Pback; }
...@@ -66,7 +94,8 @@ public: ...@@ -66,7 +94,8 @@ public:
Struct3D_Shape* m_3D_Drawings; Struct3D_Shape* m_3D_Drawings;
S3D_MATERIAL* m_Materials; S3D_MATERIAL* m_Materials;
public: S3D_MASTER( EDA_ITEM* aParent ); public:
S3D_MASTER( EDA_ITEM* aParent );
~S3D_MASTER(); ~S3D_MASTER();
S3D_MASTER* Next() const { return (S3D_MASTER*) Pnext; } S3D_MASTER* Next() const { return (S3D_MASTER*) Pnext; }
...@@ -81,12 +110,27 @@ public: S3D_MASTER( EDA_ITEM* aParent ); ...@@ -81,12 +110,27 @@ public: S3D_MASTER( EDA_ITEM* aParent );
void Copy( S3D_MASTER* pattern ); void Copy( S3D_MASTER* pattern );
int ReadData(); int ReadData();
/**
* Function ReadMaterial
* read the description of a 3D material definition in the form:
* DEF yellow material Material (
* DiffuseColor 1.00000 1.00000 0.00000e 0
* EmissiveColor 0.00000e 0 0.00000e 0 0.00000e 0
* SpecularColor 1.00000 1.00000 1.00000
* AmbientIntensity 1.00000
* Transparency 0.00000e 0
* Shininess 1.00000
*)
* Or type:
* USE yellow material
*/
int ReadMaterial( FILE* file, int* LineNum ); int ReadMaterial( FILE* file, int* LineNum );
int ReadChildren( FILE* file, int* LineNum ); int ReadChildren( FILE* file, int* LineNum );
int ReadShape( FILE* file, int* LineNum ); int ReadShape( FILE* file, int* LineNum );
int ReadAppearance( FILE* file, int* LineNum ); int ReadAppearance( FILE* file, int* LineNum );
int ReadGeometry( FILE* file, int* LineNum ); int ReadGeometry( FILE* file, int* LineNum );
void Set_Object_Coords( S3D_Vertex* coord, int nbcoord ); void Set_Object_Coords( std::vector< S3D_Vertex >& aVertices );
}; };
...@@ -98,7 +142,8 @@ public: ...@@ -98,7 +142,8 @@ public:
int* m_3D_CoordIndex; int* m_3D_CoordIndex;
int m_3D_Points; int m_3D_Points;
public: Struct3D_Shape( EDA_ITEM* aParent ); public:
Struct3D_Shape( EDA_ITEM* aParent );
~Struct3D_Shape(); ~Struct3D_Shape();
Struct3D_Shape* Next() const { return (Struct3D_Shape*) Pnext; } Struct3D_Shape* Next() const { return (Struct3D_Shape*) Pnext; }
...@@ -108,11 +153,13 @@ public: Struct3D_Shape( EDA_ITEM* aParent ); ...@@ -108,11 +153,13 @@ public: Struct3D_Shape( EDA_ITEM* aParent );
}; };
/* Display and edit a Vertex (triplet of values) in INCHES or MM or without /**
* units. * Class WinEDA_VertexCtrl
* internal_unit is the internal unit number by inch: * displays a vertex for editing. A vertex is a triplet of values in INCHES, MM,
* - 1000 for EESchema * or without units.
* - 10000 for PcbNew *
* Internal_units are the internal units by inch which is 1000 for Eeschema and
* 10000 for Pcbnew
*/ */
class WinEDA_VertexCtrl class WinEDA_VertexCtrl
{ {
...@@ -128,6 +175,10 @@ public: ...@@ -128,6 +175,10 @@ public:
~WinEDA_VertexCtrl(); ~WinEDA_VertexCtrl();
/**
* Function GetValue
* @return the vertex in internal units.
*/
S3D_Vertex GetValue(); S3D_Vertex GetValue();
void SetValue( S3D_Vertex vertex ); void SetValue( S3D_Vertex vertex );
void Enable( bool enbl ); void Enable( bool enbl );
......
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 1992-2011 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/** /**
* @file 3d_viewer.h * @file 3d_viewer.h
*/ */
#ifndef __3D_VIEWER_H__ #ifndef __3D_VIEWER_H__
#define __3D_VIEWER_H__ #define __3D_VIEWER_H__
...@@ -175,6 +201,11 @@ public: ...@@ -175,6 +201,11 @@ public:
void OnEnterWindow( wxMouseEvent& event ); void OnEnterWindow( wxMouseEvent& event );
void Render(); void Render();
/**
* Function CreateDrawGL_List
* creates the OpenGL draw list items.
*/
GLuint CreateDrawGL_List(); GLuint CreateDrawGL_List();
void InitGL(); void InitGL();
void SetLights(); void SetLights();
...@@ -194,11 +225,28 @@ public: ...@@ -194,11 +225,28 @@ public:
* @param aZpos = the z position in 3D units * @param aZpos = the z position in 3D units
*/ */
void Draw3D_Polygon( std::vector<wxPoint>& aCornersList, double aZpos ); void Draw3D_Polygon( std::vector<wxPoint>& aCornersList, double aZpos );
/**
* Function Draw3D_Via
* draws 3D via as a cylinder and filled circles.
*/
void Draw3D_Via( SEGVIA* via ); void Draw3D_Via( SEGVIA* via );
void Draw3D_DrawSegment( DRAWSEGMENT* segment ); void Draw3D_DrawSegment( DRAWSEGMENT* segment );
/**
* Function Draw3D_DrawText
* draws 3D segments to create text objects.
* When DrawGraphicText is called to draw a text to an OpenGL DC
* it calls Draw3dTextSegm to each segment to draw.
* 2 parameters used by Draw3D_FilledSegment are not handled by DrawGraphicText
* but are used in Draw3D_FilledSegment().
* they are 2 local variables. This is an ugly, but trivial code.
* Using DrawGraphicText to draw all texts ensure texts have the same shape
* in all contexts
*/
void Draw3D_DrawText( TEXTE_PCB* text ); void Draw3D_DrawText( TEXTE_PCB* text );
/// Toggles ortographic projection on and off /// Toggles orthographic projection on and off
void ToggleOrtho(){ m_ortho = !m_ortho ; Refresh(true);}; void ToggleOrtho(){ m_ortho = !m_ortho ; Refresh(true);};
/// Returns the orthographic projection flag /// Returns the orthographic projection flag
...@@ -278,7 +326,7 @@ public: ...@@ -278,7 +326,7 @@ public:
}; };
void SetGLColor( int color ); void SetGLColor( int color );
void Set_Object_Data( const S3D_Vertex* coord, int nbcoord ); void Set_Object_Data( std::vector< S3D_Vertex >& aVertices );
extern Info_3D_Visu g_Parm_3D_Visu; extern Info_3D_Visu g_Parm_3D_Visu;
extern double g_Draw3d_dx, g_Draw3d_dy; extern double g_Draw3d_dx, g_Draw3d_dy;
......
/**************/ /*
/* common.cpp */ * This program source code file is part of KiCad, a free EDA CAD application.
/**************/ *
* Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 2008-2011 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 1992-2011 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @file common.cpp
*/
#include "fctsys.h" #include "fctsys.h"
#include "gr_basic.h" #include "gr_basic.h"
...@@ -36,10 +61,8 @@ Ki_PageDescr g_Sheet_B( wxSize( 17000, 11000 ), wxPoint( 0, 0 ), wxT( "B" ) ); ...@@ -36,10 +61,8 @@ Ki_PageDescr g_Sheet_B( wxSize( 17000, 11000 ), wxPoint( 0, 0 ), wxT( "B" ) );
Ki_PageDescr g_Sheet_C( wxSize( 22000, 17000 ), wxPoint( 0, 0 ), wxT( "C" ) ); Ki_PageDescr g_Sheet_C( wxSize( 22000, 17000 ), wxPoint( 0, 0 ), wxT( "C" ) );
Ki_PageDescr g_Sheet_D( wxSize( 34000, 22000 ), wxPoint( 0, 0 ), wxT( "D" ) ); Ki_PageDescr g_Sheet_D( wxSize( 34000, 22000 ), wxPoint( 0, 0 ), wxT( "D" ) );
Ki_PageDescr g_Sheet_E( wxSize( 44000, 34000 ), wxPoint( 0, 0 ), wxT( "E" ) ); Ki_PageDescr g_Sheet_E( wxSize( 44000, 34000 ), wxPoint( 0, 0 ), wxT( "E" ) );
Ki_PageDescr g_Sheet_GERBER( wxSize( 32000, 32000 ), wxPoint( 0, 0 ), Ki_PageDescr g_Sheet_GERBER( wxSize( 32000, 32000 ), wxPoint( 0, 0 ), wxT( "GERBER" ) );
wxT( "GERBER" ) ); Ki_PageDescr g_Sheet_user( wxSize( 17000, 11000 ), wxPoint( 0, 0 ), wxT( "User" ) );
Ki_PageDescr g_Sheet_user( wxSize( 17000, 11000 ), wxPoint( 0, 0 ),
wxT( "User" ) );
Ki_PageDescr* g_SheetSizeList[NB_ITEMS + 1] = Ki_PageDescr* g_SheetSizeList[NB_ITEMS + 1] =
{ {
...@@ -49,10 +72,6 @@ Ki_PageDescr* g_SheetSizeList[NB_ITEMS + 1] = ...@@ -49,10 +72,6 @@ Ki_PageDescr* g_SheetSizeList[NB_ITEMS + 1] =
}; };
/* File extension definitions. Please do not changes these. If a different
* file extension is needed, create a new definition in the application.
* Please note, just because they are defined as const doesn't guarantee
* that they cannot be changed. */
const wxString ProjectFileExtension( wxT( "pro" ) ); const wxString ProjectFileExtension( wxT( "pro" ) );
const wxString SchematicFileExtension( wxT( "sch" ) ); const wxString SchematicFileExtension( wxT( "sch" ) );
const wxString NetlistFileExtension( wxT( "net" ) ); const wxString NetlistFileExtension( wxT( "net" ) );
...@@ -61,7 +80,6 @@ const wxString PcbFileExtension( wxT( "brd" ) ); ...@@ -61,7 +80,6 @@ const wxString PcbFileExtension( wxT( "brd" ) );
const wxString PdfFileExtension( wxT( "pdf" ) ); const wxString PdfFileExtension( wxT( "pdf" ) );
const wxString MacrosFileExtension( wxT( "mcr" ) ); const wxString MacrosFileExtension( wxT( "mcr" ) );
/* Proper wxFileDialog wild card definitions. */
const wxString ProjectFileWildcard( _( "KiCad project files (*.pro)|*.pro" ) ); const wxString ProjectFileWildcard( _( "KiCad project files (*.pro)|*.pro" ) );
const wxString SchematicFileWildcard( _( "KiCad schematic files (*.sch)|*.sch" ) ); const wxString SchematicFileWildcard( _( "KiCad schematic files (*.sch)|*.sch" ) );
const wxString NetlistFileWildcard( _( "KiCad netlist files (*.net)|*.net" ) ); const wxString NetlistFileWildcard( _( "KiCad netlist files (*.net)|*.net" ) );
...@@ -79,13 +97,12 @@ wxString g_UserLibDirBuffer; ...@@ -79,13 +97,12 @@ wxString g_UserLibDirBuffer;
wxString g_Prj_Default_Config_FullFilename; wxString g_Prj_Default_Config_FullFilename;
wxString g_Prj_Config_LocalFilename; wxString g_Prj_Config_LocalFilename;
/* Current user unit of measure */
EDA_UNITS_T g_UserUnit; EDA_UNITS_T g_UserUnit;
/* Draw color for moving objects: */
int g_GhostColor; int g_GhostColor;
/* predefined colors used in kicad. /**
* The predefined colors used in KiCad.
* Please: if you change a value, remember these values are carefully chosen * Please: if you change a value, remember these values are carefully chosen
* to have good results in Pcbnew, that uses the ORed value of basic colors * to have good results in Pcbnew, that uses the ORed value of basic colors
* when displaying superimposed objects * when displaying superimposed objects
...@@ -119,6 +136,7 @@ StructColors ColorRefs[NBCOLOR] = ...@@ -119,6 +136,7 @@ StructColors ColorRefs[NBCOLOR] =
{ 128, 255, 255, LIGHTYELLOW, wxT( "LIGHTYELLOW" ), LIGHTYELLOW } { 128, 255, 255, LIGHTYELLOW, wxT( "LIGHTYELLOW" ), LIGHTYELLOW }
}; };
/** /**
* Function to use local notation or C standard notation for floating point numbers * Function to use local notation or C standard notation for floating point numbers
* some countries use 1,5 and others (and C) 1.5 * some countries use 1,5 and others (and C) 1.5
...@@ -131,34 +149,12 @@ StructColors ColorRefs[NBCOLOR] = ...@@ -131,34 +149,12 @@ StructColors ColorRefs[NBCOLOR] =
bool g_DisableFloatingPointLocalNotation = false; bool g_DisableFloatingPointLocalNotation = false;
/**
* Function SetLocaleTo_C_standard
* because KiCad is internationalized, switch internalization to "C" standard
* i.e. uses the . (dot) as separator in print/read float numbers
* (some countries (France, Germany ..) use , (comma) as separator)
* This function must be called before read or write ascii files using float
* numbers in data the SetLocaleTo_C_standard function must be called after
* reading or writing the file
*
* This is wrapper to the C setlocale( LC_NUMERIC, "C" ) function,
* but could make more easier an optional use of locale in KiCad
*/
void SetLocaleTo_C_standard( void ) void SetLocaleTo_C_standard( void )
{ {
setlocale( LC_NUMERIC, "C" ); // Switch the locale to standard C setlocale( LC_NUMERIC, "C" ); // Switch the locale to standard C
} }
/**
* Function SetLocaleTo_Default
* because KiCad is internationalized, switch internalization to default
* to use the default separator in print/read float numbers
* (. (dot) but some countries (France, Germany ..) use , (comma) as separator)
* This function must be called after a call to SetLocaleTo_C_standard
*
* This is wrapper to the C setlocale( LC_NUMERIC, "" ) function,
* but could make more easier an optional use of locale in KiCad
*/
void SetLocaleTo_Default( void ) void SetLocaleTo_Default( void )
{ {
if( ! g_DisableFloatingPointLocalNotation ) if( ! g_DisableFloatingPointLocalNotation )
...@@ -166,8 +162,7 @@ void SetLocaleTo_Default( void ) ...@@ -166,8 +162,7 @@ void SetLocaleTo_Default( void )
} }
bool EnsureTextCtrlWidth( wxTextCtrl* aCtrl, bool EnsureTextCtrlWidth( wxTextCtrl* aCtrl, const wxString* aString )
const wxString* aString )
{ {
wxWindow* window = aCtrl->GetParent(); wxWindow* window = aCtrl->GetParent();
...@@ -192,19 +187,19 @@ bool EnsureTextCtrlWidth( wxTextCtrl* aCtrl, ...@@ -192,19 +187,19 @@ bool EnsureTextCtrlWidth( wxTextCtrl* aCtrl,
} }
wxSize size = aCtrl->GetSize(); wxSize size = aCtrl->GetSize();
if( size.GetWidth() < width + 10 ) if( size.GetWidth() < width + 10 )
{ {
size.SetWidth( width + 10 ); size.SetWidth( width + 10 );
aCtrl->SetSizeHints( size ); aCtrl->SetSizeHints( size );
return true; return true;
} }
return false; return false;
} }
Ki_PageDescr::Ki_PageDescr( const wxSize& size, Ki_PageDescr::Ki_PageDescr( const wxSize& size, const wxPoint& offset, const wxString& name )
const wxPoint& offset,
const wxString& name )
{ {
// All sizes are in 1/1000 inch // All sizes are in 1/1000 inch
m_Size = size; m_Size = size;
...@@ -296,10 +291,6 @@ wxString GetAbbreviatedUnitsLabel( EDA_UNITS_T aUnit ) ...@@ -296,10 +291,6 @@ wxString GetAbbreviatedUnitsLabel( EDA_UNITS_T aUnit )
} }
/*
* Add string " (mm):" or " ("):" to the static text Stext.
* Used in dialog boxes for entering values depending on selected units
*/
void AddUnitSymbol( wxStaticText& Stext, EDA_UNITS_T aUnit ) void AddUnitSymbol( wxStaticText& Stext, EDA_UNITS_T aUnit )
{ {
wxString msg = Stext.GetLabel(); wxString msg = Stext.GetLabel();
...@@ -310,10 +301,6 @@ void AddUnitSymbol( wxStaticText& Stext, EDA_UNITS_T aUnit ) ...@@ -310,10 +301,6 @@ void AddUnitSymbol( wxStaticText& Stext, EDA_UNITS_T aUnit )
} }
/*
* Convert the number Value in a string according to the internal units
* and the selected unit (g_UserUnit) and put it in the wxTextCtrl TextCtrl
*/
void PutValueInLocalUnits( wxTextCtrl& TextCtr, int Value, int Internal_Unit ) void PutValueInLocalUnits( wxTextCtrl& TextCtr, int Value, int Internal_Unit )
{ {
wxString msg = ReturnStringFromValue( g_UserUnit, Value, Internal_Unit ); wxString msg = ReturnStringFromValue( g_UserUnit, Value, Internal_Unit );
...@@ -322,10 +309,6 @@ void PutValueInLocalUnits( wxTextCtrl& TextCtr, int Value, int Internal_Unit ) ...@@ -322,10 +309,6 @@ void PutValueInLocalUnits( wxTextCtrl& TextCtr, int Value, int Internal_Unit )
} }
/*
* Convert the Value in the wxTextCtrl TextCtrl in an integer,
* according to the internal units and the selected unit (g_UserUnit)
*/
int ReturnValueFromTextCtrl( const wxTextCtrl& TextCtr, int Internal_Unit ) int ReturnValueFromTextCtrl( const wxTextCtrl& TextCtr, int Internal_Unit )
{ {
int value; int value;
...@@ -337,17 +320,6 @@ int ReturnValueFromTextCtrl( const wxTextCtrl& TextCtr, int Internal_Unit ) ...@@ -337,17 +320,6 @@ int ReturnValueFromTextCtrl( const wxTextCtrl& TextCtr, int Internal_Unit )
} }
/**
* Function ReturnStringFromValue
* Return the string from Value, according to units (inch, mm ...) for display,
* and the initial unit for value
* @param aUnit = display units (INCHES, MILLIMETRE ..)
* @param aValue = value in Internal_Unit
* @param aInternal_Unit = units per inch for Value
* @param aAdd_unit_symbol = true to add symbol unit to the string value
* @return a wxString what contains value and optionally the symbol unit
* (like 2.000 mm)
*/
wxString ReturnStringFromValue( EDA_UNITS_T aUnit, int aValue, int aInternal_Unit, wxString ReturnStringFromValue( EDA_UNITS_T aUnit, int aValue, int aInternal_Unit,
bool aAdd_unit_symbol ) bool aAdd_unit_symbol )
{ {
...@@ -355,9 +327,9 @@ wxString ReturnStringFromValue( EDA_UNITS_T aUnit, int aValue, int aInternal_Uni ...@@ -355,9 +327,9 @@ wxString ReturnStringFromValue( EDA_UNITS_T aUnit, int aValue, int aInternal_Uni
double value_to_print; double value_to_print;
value_to_print = To_User_Unit( aUnit, aValue, aInternal_Unit ); value_to_print = To_User_Unit( aUnit, aValue, aInternal_Unit );
/* Yet another 'if Pcbnew' :( */ /* Yet another 'if Pcbnew' :( */
StringValue.Printf( ( aInternal_Unit > 1000 ) ? wxT( "%.4f" ) : StringValue.Printf( ( aInternal_Unit > 1000 ) ? wxT( "%.4f" ) : wxT( "%.3f" ),
wxT( "%.3f" ),
value_to_print ); value_to_print );
if( aAdd_unit_symbol ) if( aAdd_unit_symbol )
...@@ -379,15 +351,7 @@ wxString ReturnStringFromValue( EDA_UNITS_T aUnit, int aValue, int aInternal_Uni ...@@ -379,15 +351,7 @@ wxString ReturnStringFromValue( EDA_UNITS_T aUnit, int aValue, int aInternal_Uni
} }
/* int ReturnValueFromString( EDA_UNITS_T aUnit, const wxString& TextValue, int Internal_Unit )
* Return the string from Value, according to units (inch, mm ...) for display,
* and the initial unit for value
* Unit = display units (INCH, MM ..)
* Value = text
* Internal_Unit = units per inch for computed value
*/
int ReturnValueFromString( EDA_UNITS_T aUnit, const wxString& TextValue,
int Internal_Unit )
{ {
int Value; int Value;
double dtmp = 0; double dtmp = 0;
...@@ -399,6 +363,7 @@ int ReturnValueFromString( EDA_UNITS_T aUnit, const wxString& TextValue, ...@@ -399,6 +363,7 @@ int ReturnValueFromString( EDA_UNITS_T aUnit, const wxString& TextValue,
/* Convert the period in decimal point */ /* Convert the period in decimal point */
buf.Replace( wxT( "." ), wxString( decimal_point, 1 ) ); buf.Replace( wxT( "." ), wxString( decimal_point, 1 ) );
// An ugly fix needed by WxWidgets 2.9.1 that sometimes // An ugly fix needed by WxWidgets 2.9.1 that sometimes
// back to a point as separator, although the separator is the comma // back to a point as separator, although the separator is the comma
// TODO: remove this line if WxWidgets 2.9.2 fixes this issue // TODO: remove this line if WxWidgets 2.9.2 fixes this issue
...@@ -406,14 +371,16 @@ int ReturnValueFromString( EDA_UNITS_T aUnit, const wxString& TextValue, ...@@ -406,14 +371,16 @@ int ReturnValueFromString( EDA_UNITS_T aUnit, const wxString& TextValue,
/* Find the end of the numeric part */ /* Find the end of the numeric part */
unsigned brk_point = 0; unsigned brk_point = 0;
while( brk_point < buf.Len() ) while( brk_point < buf.Len() )
{ {
wxChar ch = buf[brk_point]; wxChar ch = buf[brk_point];
if( !( (ch >= '0' && ch <='9') || (ch == decimal_point)
|| (ch == '-') || (ch == '+') ) ) if( !( (ch >= '0' && ch <='9') || (ch == decimal_point) || (ch == '-') || (ch == '+') ) )
{ {
break; break;
} }
++brk_point; ++brk_point;
} }
...@@ -422,6 +389,7 @@ int ReturnValueFromString( EDA_UNITS_T aUnit, const wxString& TextValue, ...@@ -422,6 +389,7 @@ int ReturnValueFromString( EDA_UNITS_T aUnit, const wxString& TextValue,
/* Check the optional unit designator (2 ch significant) */ /* Check the optional unit designator (2 ch significant) */
wxString unit( buf.Mid( brk_point ).Strip( wxString::leading ).Left( 2 ).Lower() ); wxString unit( buf.Mid( brk_point ).Strip( wxString::leading ).Left( 2 ).Lower() );
if( unit == wxT( "in" ) || unit == wxT( "\"" ) ) if( unit == wxT( "in" ) || unit == wxT( "\"" ) )
{ {
aUnit = INCHES; aUnit = INCHES;
...@@ -435,6 +403,7 @@ int ReturnValueFromString( EDA_UNITS_T aUnit, const wxString& TextValue, ...@@ -435,6 +403,7 @@ int ReturnValueFromString( EDA_UNITS_T aUnit, const wxString& TextValue,
aUnit = INCHES; aUnit = INCHES;
dtmp /= 1000; dtmp /= 1000;
} }
Value = From_User_Unit( aUnit, dtmp, Internal_Unit ); Value = From_User_Unit( aUnit, dtmp, Internal_Unit );
return Value; return Value;
...@@ -453,18 +422,24 @@ const LENGTH_UNIT_DESC g_MillimetreDesc = ...@@ -453,18 +422,24 @@ const LENGTH_UNIT_DESC g_MillimetreDesc =
wxT( "mm" ), wxT( "mm" ),
6 6
}; };
const LENGTH_UNIT_DESC g_InchDesc = const LENGTH_UNIT_DESC g_InchDesc =
{ {
LENGTH_UNITS<LENGTH_DEF>::inch(), LENGTH_UNITS<LENGTH_DEF>::inch(),
wxT( "\"" ), wxT( "\"" ),
7 7
}; };
const LENGTH_UNIT_DESC g_MilDesc = const LENGTH_UNIT_DESC g_MilDesc =
{ {
LENGTH_UNITS<LENGTH_DEF>::mil(), LENGTH_UNITS<LENGTH_DEF>::mil(),
wxT( "mil" ), wxT( "mil" ),
5 5
}; };
const LENGTH_UNIT_DESC g_UnscaledDesc = /* stub */ const LENGTH_UNIT_DESC g_UnscaledDesc = /* stub */
{ {
LENGTH_DEF::quantum(), LENGTH_DEF::quantum(),
...@@ -472,6 +447,7 @@ const LENGTH_UNIT_DESC g_UnscaledDesc = /* stub */ ...@@ -472,6 +447,7 @@ const LENGTH_UNIT_DESC g_UnscaledDesc = /* stub */
4 4
}; };
const LENGTH_UNIT_DESC *UnitDescription( EDA_UNITS_T aUnit ) { const LENGTH_UNIT_DESC *UnitDescription( EDA_UNITS_T aUnit ) {
switch(aUnit) { switch(aUnit) {
case INCHES: case INCHES:
...@@ -483,6 +459,7 @@ const LENGTH_UNIT_DESC *UnitDescription( EDA_UNITS_T aUnit ) { ...@@ -483,6 +459,7 @@ const LENGTH_UNIT_DESC *UnitDescription( EDA_UNITS_T aUnit ) {
} }
} }
/* TODO: localisation */ /* TODO: localisation */
wxString LengthToString( const LENGTH_UNIT_DESC *aUnit, LENGTH_DEF aValue, wxString LengthToString( const LENGTH_UNIT_DESC *aUnit, LENGTH_DEF aValue,
bool aAdd_unit_symbol ) { bool aAdd_unit_symbol ) {
...@@ -491,18 +468,28 @@ wxString LengthToString( const LENGTH_UNIT_DESC *aUnit, LENGTH_DEF aValue, ...@@ -491,18 +468,28 @@ wxString LengthToString( const LENGTH_UNIT_DESC *aUnit, LENGTH_DEF aValue,
value_to_print = LENGTH<double>(aValue) / LENGTH<double>(aUnit->m_Value); value_to_print = LENGTH<double>(aValue) / LENGTH<double>(aUnit->m_Value);
StringValue.Printf( wxT( "%.*f" ), aUnit->m_Precision, value_to_print); StringValue.Printf( wxT( "%.*f" ), aUnit->m_Precision, value_to_print);
size_t zero_tail = StringValue.find_last_not_of( wxT( "0" ) ); size_t zero_tail = StringValue.find_last_not_of( wxT( "0" ) );
if( zero_tail != std::string::npos ) {
if( zero_tail != std::string::npos )
{
//fprintf( stderr, "pos : %d", (int) zero_tail ); //fprintf( stderr, "pos : %d", (int) zero_tail );
size_t delim_pos = StringValue.Length() - aUnit->m_Precision; size_t delim_pos = StringValue.Length() - aUnit->m_Precision;
if( zero_tail < delim_pos) zero_tail = delim_pos;
if( zero_tail < delim_pos)
zero_tail = delim_pos;
StringValue.Truncate( zero_tail + 1 ); StringValue.Truncate( zero_tail + 1 );
} }
if( aAdd_unit_symbol && aUnit->m_Symbol != wxT( "" ) ) {
if( aAdd_unit_symbol && aUnit->m_Symbol != wxT( "" ) )
{
StringValue += wxT( " " ); StringValue += wxT( " " );
StringValue += wxGetTranslation( aUnit->m_Symbol ); StringValue += wxGetTranslation( aUnit->m_Symbol );
} }
return StringValue; return StringValue;
} }
LENGTH_DEF StringToLength( const LENGTH_UNIT_DESC *aUnit, const wxString& TextValue ) LENGTH_DEF StringToLength( const LENGTH_UNIT_DESC *aUnit, const wxString& TextValue )
{ {
...@@ -516,6 +503,7 @@ LENGTH_DEF StringToLength( const LENGTH_UNIT_DESC *aUnit, const wxString& TextVa ...@@ -516,6 +503,7 @@ LENGTH_DEF StringToLength( const LENGTH_UNIT_DESC *aUnit, const wxString& TextVa
/* Convert the period in decimal point */ /* Convert the period in decimal point */
buf.Replace( wxT( "." ), wxString( decimal_point, 1 ) ); buf.Replace( wxT( "." ), wxString( decimal_point, 1 ) );
// An ugly fix needed by WxWidgets 2.9.1 that sometimes // An ugly fix needed by WxWidgets 2.9.1 that sometimes
// back to a point as separator, although the separator is the comma // back to a point as separator, although the separator is the comma
// TODO: remove this line if WxWidgets 2.9.2 fixes this issue // TODO: remove this line if WxWidgets 2.9.2 fixes this issue
...@@ -523,14 +511,17 @@ LENGTH_DEF StringToLength( const LENGTH_UNIT_DESC *aUnit, const wxString& TextVa ...@@ -523,14 +511,17 @@ LENGTH_DEF StringToLength( const LENGTH_UNIT_DESC *aUnit, const wxString& TextVa
/* Find the end of the numeric part */ /* Find the end of the numeric part */
unsigned brk_point = 0; unsigned brk_point = 0;
while( brk_point < buf.Len() ) while( brk_point < buf.Len() )
{ {
wxChar ch = buf[brk_point]; wxChar ch = buf[brk_point];
if( !( (ch >= '0' && ch <='9') || (ch == decimal_point) if( !( (ch >= '0' && ch <='9') || (ch == decimal_point)
|| (ch == '-') || (ch == '+') ) ) || (ch == '-') || (ch == '+') ) )
{ {
break; break;
} }
++brk_point; ++brk_point;
} }
...@@ -539,6 +530,7 @@ LENGTH_DEF StringToLength( const LENGTH_UNIT_DESC *aUnit, const wxString& TextVa ...@@ -539,6 +530,7 @@ LENGTH_DEF StringToLength( const LENGTH_UNIT_DESC *aUnit, const wxString& TextVa
/* Check the optional unit designator (2 ch significant) */ /* Check the optional unit designator (2 ch significant) */
wxString unit( buf.Mid( brk_point ).Strip( wxString::leading ).Left( 2 ).Lower() ); wxString unit( buf.Mid( brk_point ).Strip( wxString::leading ).Left( 2 ).Lower() );
if( unit == wxT( "in" ) || unit == wxT( "\"" ) ) if( unit == wxT( "in" ) || unit == wxT( "\"" ) )
{ {
aUnit = &g_InchDesc; aUnit = &g_InchDesc;
...@@ -551,16 +543,19 @@ LENGTH_DEF StringToLength( const LENGTH_UNIT_DESC *aUnit, const wxString& TextVa ...@@ -551,16 +543,19 @@ LENGTH_DEF StringToLength( const LENGTH_UNIT_DESC *aUnit, const wxString& TextVa
{ {
aUnit = &g_MilDesc; aUnit = &g_MilDesc;
} }
Value = LENGTH_DEF( dtmp * LENGTH< double, 1 >( aUnit->m_Value ) ); Value = LENGTH_DEF( dtmp * LENGTH< double, 1 >( aUnit->m_Value ) );
return Value; return Value;
} }
void LengthToTextCtrl( wxTextCtrl& TextCtr, LENGTH_DEF Value ) { void LengthToTextCtrl( wxTextCtrl& TextCtr, LENGTH_DEF Value )
{
wxString msg = LengthToString( UnitDescription( g_UserUnit ), Value ); wxString msg = LengthToString( UnitDescription( g_UserUnit ), Value );
TextCtr.SetValue( msg ); TextCtr.SetValue( msg );
} }
LENGTH_DEF LengthFromTextCtrl( const wxTextCtrl& TextCtr ) LENGTH_DEF LengthFromTextCtrl( const wxTextCtrl& TextCtr )
{ {
LENGTH_DEF value; LENGTH_DEF value;
...@@ -573,46 +568,33 @@ LENGTH_DEF LengthFromTextCtrl( const wxTextCtrl& TextCtr ) ...@@ -573,46 +568,33 @@ LENGTH_DEF LengthFromTextCtrl( const wxTextCtrl& TextCtr )
#endif #endif
/**
* Function wxStringSplit wxArrayString* wxStringSplit( wxString aString, wxChar aSplitter )
* Split a String to a String List when founding 'splitter'
* @return the list
* @param txt : wxString : a String text
* @param splitter : wxChar : the 'split' character
*/
wxArrayString* wxStringSplit( wxString txt, wxChar splitter )
{ {
wxArrayString* list = new wxArrayString(); wxArrayString* list = new wxArrayString();
while( 1 ) while( 1 )
{ {
int index = txt.Find( splitter ); int index = aString.Find( aSplitter );
if( index == wxNOT_FOUND ) if( index == wxNOT_FOUND )
break; break;
wxString tmp; wxString tmp;
tmp = txt.Mid( 0, index ); tmp = aString.Mid( 0, index );
txt = txt.Mid( index + 1, txt.size() - index ); aString = aString.Mid( index + 1, aString.size() - index );
list->Add( tmp ); list->Add( tmp );
} }
if( !txt.IsEmpty() ) if( !aString.IsEmpty() )
{ {
list->Add( txt ); list->Add( aString );
} }
return list; return list;
} }
/**
* Function To_User_Unit
* Convert in inch or mm the variable "val" (double)given in internal units
* @return the converted value, in double
* @param aUnit : user measure unit
* @param val : double : the given value
* @param internal_unit_value = internal units per inch
*/
double To_User_Unit( EDA_UNITS_T aUnit, double val, int internal_unit_value ) double To_User_Unit( EDA_UNITS_T aUnit, double val, int internal_unit_value )
{ {
switch( aUnit ) switch( aUnit )
...@@ -629,9 +611,6 @@ double To_User_Unit( EDA_UNITS_T aUnit, double val, int internal_unit_value ) ...@@ -629,9 +611,6 @@ double To_User_Unit( EDA_UNITS_T aUnit, double val, int internal_unit_value )
} }
/*
* Return in internal units the value "val" given in inch or mm
*/
int From_User_Unit( EDA_UNITS_T aUnit, double val, int internal_unit_value ) int From_User_Unit( EDA_UNITS_T aUnit, double val, int internal_unit_value )
{ {
double value; double value;
...@@ -655,9 +634,6 @@ int From_User_Unit( EDA_UNITS_T aUnit, double val, int internal_unit_value ) ...@@ -655,9 +634,6 @@ int From_User_Unit( EDA_UNITS_T aUnit, double val, int internal_unit_value )
} }
/*
* Return the string date "day month year" like "23 jun 2005"
*/
wxString GenDate() wxString GenDate()
{ {
static const wxString mois[12] = static const wxString mois[12] =
...@@ -679,36 +655,6 @@ wxString GenDate() ...@@ -679,36 +655,6 @@ wxString GenDate()
} }
/*
* My memory allocation
*/
void* MyMalloc( size_t nb_octets )
{
void* pt_mem;
if( nb_octets == 0 )
{
DisplayError( NULL, wxT( "Allocate 0 bytes !!" ) );
return NULL;
}
pt_mem = malloc( nb_octets );
if( pt_mem == NULL )
{
wxString msg;
msg.Printf( wxT( "Out of memory: allocation %d bytes" ), nb_octets );
DisplayError( NULL, msg );
}
return pt_mem;
}
/**
* Function ProcessExecute
* runs a child process.
* @param aCommandLine The process and any arguments to it all in a single string.
* @param aFlags The same args as allowed for wxExecute()
* @return bool - true if success, else false
*/
bool ProcessExecute( const wxString& aCommandLine, int aFlags ) bool ProcessExecute( const wxString& aCommandLine, int aFlags )
{ {
#ifdef __WINDOWS__ #ifdef __WINDOWS__
...@@ -721,26 +667,6 @@ bool ProcessExecute( const wxString& aCommandLine, int aFlags ) ...@@ -721,26 +667,6 @@ bool ProcessExecute( const wxString& aCommandLine, int aFlags )
} }
/*
* My memory allocation, memory space is cleared
*/
void* MyZMalloc( size_t nb_octets )
{
void* pt_mem = MyMalloc( nb_octets );
if( pt_mem )
memset( pt_mem, 0, nb_octets );
return pt_mem;
}
void MyFree( void* pt_mem )
{
if( pt_mem )
free( pt_mem );
}
int GetTimeStamp() int GetTimeStamp()
{ {
static int OldTimeStamp, NewTimeStamp; static int OldTimeStamp, NewTimeStamp;
...@@ -756,11 +682,6 @@ int GetTimeStamp() ...@@ -756,11 +682,6 @@ int GetTimeStamp()
} }
/* Returns to display the value of a parameter, by type of units selected
* Input: value in mils, buffer text
* Returns to buffer: text: value expressed in inches or millimeters
* Followed by " or mm
*/
const wxString& valeur_param( int valeur, wxString& buf_texte ) const wxString& valeur_param( int valeur, wxString& buf_texte )
{ {
switch( g_UserUnit ) switch( g_UserUnit )
...@@ -782,8 +703,6 @@ const wxString& valeur_param( int valeur, wxString& buf_texte ) ...@@ -782,8 +703,6 @@ const wxString& valeur_param( int valeur, wxString& buf_texte )
} }
wxString CoordinateToString( int aValue, int aInternalUnits, bool aConvertToMils ) wxString CoordinateToString( int aValue, int aInternalUnits, bool aConvertToMils )
{ {
wxCHECK_MSG( (aInternalUnits == EESCHEMA_INTERNAL_UNIT) wxCHECK_MSG( (aInternalUnits == EESCHEMA_INTERNAL_UNIT)
...@@ -823,9 +742,6 @@ wxString CoordinateToString( int aValue, int aInternalUnits, bool aConvertToMils ...@@ -823,9 +742,6 @@ wxString CoordinateToString( int aValue, int aInternalUnits, bool aConvertToMils
} }
/*
*
*/
wxString& operator <<( wxString& aString, const wxPoint& aPos ) wxString& operator <<( wxString& aString, const wxPoint& aPos )
{ {
wxString temp; wxString temp;
......
...@@ -1127,7 +1127,7 @@ void EDA_DRAW_PANEL::OnKeyEvent( wxKeyEvent& event ) ...@@ -1127,7 +1127,7 @@ void EDA_DRAW_PANEL::OnKeyEvent( wxKeyEvent& event )
m_AbortRequest = true; m_AbortRequest = true;
if( IsMouseCaptured() ) if( IsMouseCaptured() )
EndMouseCapture( ); EndMouseCapture();
else else
EndMouseCapture( ID_NO_TOOL_SELECTED, m_defaultCursor, wxEmptyString ); EndMouseCapture( ID_NO_TOOL_SELECTED, m_defaultCursor, wxEmptyString );
...@@ -1237,9 +1237,10 @@ void EDA_DRAW_PANEL::OnPan( wxCommandEvent& event ) ...@@ -1237,9 +1237,10 @@ void EDA_DRAW_PANEL::OnPan( wxCommandEvent& event )
} }
void EDA_DRAW_PANEL::EndMouseCapture( int id, int cursor, const wxString& title ) void EDA_DRAW_PANEL::EndMouseCapture( int id, int cursor, const wxString& title,
bool aCallEndFunc )
{ {
if( m_mouseCaptureCallback && m_endMouseCaptureCallback ) if( m_mouseCaptureCallback && m_endMouseCaptureCallback && aCallEndFunc )
{ {
INSTALL_UNBUFFERED_DC( dc, this ); INSTALL_UNBUFFERED_DC( dc, this );
m_endMouseCaptureCallback( this, &dc ); m_endMouseCaptureCallback( this, &dc );
......
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 2009-2011 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 2004-2011 KiCad Developers, see change_log.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/** /**
* @file eeschema/block.cpp * @file eeschema/block.cpp
*/ */
...@@ -39,9 +64,6 @@ static void DrawMovingBlockOutlines( EDA_DRAW_PANEL* aPanel, wxDC* aDC, ...@@ -39,9 +64,6 @@ static void DrawMovingBlockOutlines( EDA_DRAW_PANEL* aPanel, wxDC* aDC,
const wxPoint& aPosition, bool aErase ); const wxPoint& aPosition, bool aErase );
/* Return the block command (BLOCK_MOVE, BLOCK_COPY...) corresponding to
* the key (ALT, SHIFT ALT ..)
*/
int SCH_EDIT_FRAME::ReturnBlockCommand( int key ) int SCH_EDIT_FRAME::ReturnBlockCommand( int key )
{ {
int cmd; int cmd;
...@@ -78,8 +100,6 @@ int SCH_EDIT_FRAME::ReturnBlockCommand( int key ) ...@@ -78,8 +100,6 @@ int SCH_EDIT_FRAME::ReturnBlockCommand( int key )
} }
/* Init the parameters used by the block paste command
*/
void SCH_EDIT_FRAME::InitBlockPasteInfos() void SCH_EDIT_FRAME::InitBlockPasteInfos()
{ {
BLOCK_SELECTOR* block = &GetScreen()->m_BlockLocate; BLOCK_SELECTOR* block = &GetScreen()->m_BlockLocate;
...@@ -89,11 +109,6 @@ void SCH_EDIT_FRAME::InitBlockPasteInfos() ...@@ -89,11 +109,6 @@ void SCH_EDIT_FRAME::InitBlockPasteInfos()
} }
/* Routine to handle the BLOCK PLACE command
* Last routine for block operation for:
* - block move & drag
* - block copy & paste
*/
void SCH_EDIT_FRAME::HandleBlockPlace( wxDC* DC ) void SCH_EDIT_FRAME::HandleBlockPlace( wxDC* DC )
{ {
BLOCK_SELECTOR* block = &GetScreen()->m_BlockLocate; BLOCK_SELECTOR* block = &GetScreen()->m_BlockLocate;
...@@ -175,22 +190,11 @@ void SCH_EDIT_FRAME::HandleBlockPlace( wxDC* DC ) ...@@ -175,22 +190,11 @@ void SCH_EDIT_FRAME::HandleBlockPlace( wxDC* DC )
block->ClearItemsList(); block->ClearItemsList();
} }
DrawPanel->SetMouseCapture( NULL, NULL ); DrawPanel->EndMouseCapture( GetToolId(), DrawPanel->GetCurrentCursor(), wxEmptyString, false );
SetToolID( GetToolId(), DrawPanel->GetCurrentCursor(), wxEmptyString );
DrawPanel->Refresh(); DrawPanel->Refresh();
} }
/**
* Function HandleBlockEnd( )
* Handle the "end" of a block command,
* i.e. is called at the end of the definition of the area of a block.
* depending on the current block command, this command is executed
* or parameters are initialized to prepare a call to HandleBlockPlace
* in GetScreen()->m_BlockLocate
* @return false if no item selected, or command finished,
* true if some items found and HandleBlockPlace must be called later
*/
bool SCH_EDIT_FRAME::HandleBlockEnd( wxDC* DC ) bool SCH_EDIT_FRAME::HandleBlockEnd( wxDC* DC )
{ {
bool nextcmd = false; bool nextcmd = false;
...@@ -309,8 +313,8 @@ bool SCH_EDIT_FRAME::HandleBlockEnd( wxDC* DC ) ...@@ -309,8 +313,8 @@ bool SCH_EDIT_FRAME::HandleBlockEnd( wxDC* DC )
block->m_State = STATE_NO_BLOCK; block->m_State = STATE_NO_BLOCK;
block->m_Command = BLOCK_IDLE; block->m_Command = BLOCK_IDLE;
GetScreen()->SetCurItem( NULL ); GetScreen()->SetCurItem( NULL );
DrawPanel->SetMouseCapture( NULL, NULL ); DrawPanel->EndMouseCapture( GetToolId(), DrawPanel->GetCurrentCursor(), wxEmptyString,
SetToolID( GetToolId(), DrawPanel->GetCurrentCursor(), wxEmptyString ); false );
} }
if( zoom_command ) if( zoom_command )
...@@ -320,15 +324,6 @@ bool SCH_EDIT_FRAME::HandleBlockEnd( wxDC* DC ) ...@@ -320,15 +324,6 @@ bool SCH_EDIT_FRAME::HandleBlockEnd( wxDC* DC )
} }
/* Manage end block command from context menu.
* Can be called only :
* after HandleBlockEnd
* and if the current command is block move.
* Execute a command other than block move from the current block move selected items list.
* Due to (minor) problems in undo/redo or/and display block,
* a mirror/rotate command is immediately executed and multiple block commands
* are not allowed (multiple commands are tricky to undo/redo in one time)
*/
void SCH_EDIT_FRAME::HandleBlockEndByPopUp( int Command, wxDC* DC ) void SCH_EDIT_FRAME::HandleBlockEndByPopUp( int Command, wxDC* DC )
{ {
bool blockCmdFinished = true; /* set to false for block command which bool blockCmdFinished = true; /* set to false for block command which
...@@ -474,8 +469,8 @@ void SCH_EDIT_FRAME::HandleBlockEndByPopUp( int Command, wxDC* DC ) ...@@ -474,8 +469,8 @@ void SCH_EDIT_FRAME::HandleBlockEndByPopUp( int Command, wxDC* DC )
{ {
block->Clear(); block->Clear();
GetScreen()->SetCurItem( NULL ); GetScreen()->SetCurItem( NULL );
DrawPanel->SetMouseCapture( NULL, NULL ); DrawPanel->EndMouseCapture( GetToolId(), DrawPanel->GetCurrentCursor(), wxEmptyString,
SetToolID( GetToolId(), DrawPanel->GetDefaultCursor(), wxEmptyString ); false );
} }
} }
...@@ -536,10 +531,6 @@ void SCH_EDIT_FRAME::copyBlockItems( PICKED_ITEMS_LIST& aItemsList ) ...@@ -536,10 +531,6 @@ void SCH_EDIT_FRAME::copyBlockItems( PICKED_ITEMS_LIST& aItemsList )
} }
/*****************************************************************************
* Routine to paste a structure from the m_blockItems stack.
* This routine is the same as undelete but original list is NOT removed.
*****************************************************************************/
void SCH_EDIT_FRAME::PasteListOfItems( wxDC* DC ) void SCH_EDIT_FRAME::PasteListOfItems( wxDC* DC )
{ {
SCH_ITEM* Struct; SCH_ITEM* Struct;
......
...@@ -42,10 +42,6 @@ static void DrawMovingBlockOutlines( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wx ...@@ -42,10 +42,6 @@ static void DrawMovingBlockOutlines( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wx
bool aErase ); bool aErase );
/*
* Return the block command (BLOCK_MOVE, BLOCK_COPY...) corresponding to
* the key (ALT, SHIFT ALT ..)
*/
int LIB_EDIT_FRAME::ReturnBlockCommand( int key ) int LIB_EDIT_FRAME::ReturnBlockCommand( int key )
{ {
int cmd; int cmd;
...@@ -86,13 +82,6 @@ int LIB_EDIT_FRAME::ReturnBlockCommand( int key ) ...@@ -86,13 +82,6 @@ int LIB_EDIT_FRAME::ReturnBlockCommand( int key )
} }
/*
* Command BLOCK END (end of block sizing)
* return :
* 0 if command finished (zoom, delete ...)
* 1 if HandleBlockPlace must follow (items found, and a block place
* command must follow)
*/
bool LIB_EDIT_FRAME::HandleBlockEnd( wxDC* DC ) bool LIB_EDIT_FRAME::HandleBlockEnd( wxDC* DC )
{ {
int ItemCount = 0; int ItemCount = 0;
...@@ -216,8 +205,8 @@ bool LIB_EDIT_FRAME::HandleBlockEnd( wxDC* DC ) ...@@ -216,8 +205,8 @@ bool LIB_EDIT_FRAME::HandleBlockEnd( wxDC* DC )
GetScreen()->m_BlockLocate.m_State = STATE_NO_BLOCK; GetScreen()->m_BlockLocate.m_State = STATE_NO_BLOCK;
GetScreen()->m_BlockLocate.m_Command = BLOCK_IDLE; GetScreen()->m_BlockLocate.m_Command = BLOCK_IDLE;
GetScreen()->SetCurItem( NULL ); GetScreen()->SetCurItem( NULL );
DrawPanel->SetMouseCapture( NULL, NULL ); DrawPanel->EndMouseCapture( GetToolId(), DrawPanel->GetCurrentCursor(), wxEmptyString,
SetToolID( GetToolId(), DrawPanel->GetCurrentCursor(), wxEmptyString ); false );
DrawPanel->Refresh( true ); DrawPanel->Refresh( true );
} }
...@@ -225,12 +214,6 @@ bool LIB_EDIT_FRAME::HandleBlockEnd( wxDC* DC ) ...@@ -225,12 +214,6 @@ bool LIB_EDIT_FRAME::HandleBlockEnd( wxDC* DC )
} }
/*
* Routine to handle the BLOCK PLACE command
* Last routine for block operation for:
* - block move & drag
* - block copy & paste
*/
void LIB_EDIT_FRAME::HandleBlockPlace( wxDC* DC ) void LIB_EDIT_FRAME::HandleBlockPlace( wxDC* DC )
{ {
wxPoint pt; wxPoint pt;
...@@ -319,9 +302,8 @@ void LIB_EDIT_FRAME::HandleBlockPlace( wxDC* DC ) ...@@ -319,9 +302,8 @@ void LIB_EDIT_FRAME::HandleBlockPlace( wxDC* DC )
GetScreen()->m_BlockLocate.m_State = STATE_NO_BLOCK; GetScreen()->m_BlockLocate.m_State = STATE_NO_BLOCK;
GetScreen()->m_BlockLocate.m_Command = BLOCK_IDLE; GetScreen()->m_BlockLocate.m_Command = BLOCK_IDLE;
GetScreen()->SetCurItem( NULL ); GetScreen()->SetCurItem( NULL );
DrawPanel->SetMouseCapture( NULL, NULL ); DrawPanel->EndMouseCapture( GetToolId(), DrawPanel->GetCurrentCursor(), wxEmptyString, false );
DrawPanel->Refresh( true ); DrawPanel->Refresh( true );
SetToolID( GetToolId(), DrawPanel->GetCurrentCursor(), wxEmptyString );
} }
......
...@@ -102,13 +102,6 @@ static void DrawSegment( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosi ...@@ -102,13 +102,6 @@ static void DrawSegment( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosi
} }
/* Creates a new segment ( WIRE, BUS ),
* or terminates the current segment
* If the end of the current segment is on an other segment, place a junction
* if needed and terminates the command
* If the end of the current segment is on a pin, terminates the command
* In others cases starts a new segment
*/
void SCH_EDIT_FRAME::BeginSegment( wxDC* DC, int type ) void SCH_EDIT_FRAME::BeginSegment( wxDC* DC, int type )
{ {
SCH_LINE* oldsegment, * newsegment, * nextsegment; SCH_LINE* oldsegment, * newsegment, * nextsegment;
...@@ -240,8 +233,6 @@ void SCH_EDIT_FRAME::BeginSegment( wxDC* DC, int type ) ...@@ -240,8 +233,6 @@ void SCH_EDIT_FRAME::BeginSegment( wxDC* DC, int type )
} }
/* Called to terminate a bus, wire, or line creation
*/
void SCH_EDIT_FRAME::EndSegment( wxDC* DC ) void SCH_EDIT_FRAME::EndSegment( wxDC* DC )
{ {
SCH_LINE* firstsegment = (SCH_LINE*) GetScreen()->GetCurItem(); SCH_LINE* firstsegment = (SCH_LINE*) GetScreen()->GetCurItem();
...@@ -291,7 +282,7 @@ void SCH_EDIT_FRAME::EndSegment( wxDC* DC ) ...@@ -291,7 +282,7 @@ void SCH_EDIT_FRAME::EndSegment( wxDC* DC )
GetScreen()->SetDrawItems( lastsegment ); GetScreen()->SetDrawItems( lastsegment );
} }
DrawPanel->SetMouseCapture( NULL, NULL ); DrawPanel->EndMouseCapture( -1, -1, wxEmptyString, false );
GetScreen()->SetCurItem( NULL ); GetScreen()->SetCurItem( NULL );
wxPoint end_point, alt_end_point; wxPoint end_point, alt_end_point;
...@@ -369,55 +360,53 @@ void SCH_EDIT_FRAME::EndSegment( wxDC* DC ) ...@@ -369,55 +360,53 @@ void SCH_EDIT_FRAME::EndSegment( wxDC* DC )
} }
/* compute the middle coordinate for 2 segments, from the start point to /**
* new_pos * Function ComputeBreakPoint
* with the 2 segments kept H or V only * computes the middle coordinate for 2 segments from the start point to \a aPosition
* with the segments kept in the horizontal or vertical axis only.
*/ */
static void ComputeBreakPoint( SCH_LINE* segment, const wxPoint& new_pos ) static void ComputeBreakPoint( SCH_LINE* aSegment, const wxPoint& aPosition )
{ {
SCH_LINE* nextsegment = segment->Next(); SCH_LINE* nextsegment = aSegment->Next();
wxPoint middle_position = new_pos; wxPoint middle_position = aPosition;
if( nextsegment == NULL ) if( nextsegment == NULL )
return; return;
#if 0 #if 0
if( ABS( middle_position.x - segment->m_Start.x ) < if( ABS( middle_position.x - aSegment->m_Start.x ) <
ABS( middle_position.y - segment->m_Start.y ) ) ABS( middle_position.y - aSegment->m_Start.y ) )
middle_position.x = segment->m_Start.x; middle_position.x = aSegment->m_Start.x;
else else
middle_position.y = segment->m_Start.y; middle_position.y = aSegment->m_Start.y;
#else #else
int iDx = segment->m_End.x - segment->m_Start.x; int iDx = aSegment->m_End.x - aSegment->m_Start.x;
int iDy = segment->m_End.y - segment->m_Start.y; int iDy = aSegment->m_End.y - aSegment->m_Start.y;
if( iDy != 0 ) // keep the first segment orientation (currently horizontal) if( iDy != 0 ) // keep the first segment orientation (currently horizontal)
{ {
middle_position.x = segment->m_Start.x; middle_position.x = aSegment->m_Start.x;
} }
else if( iDx != 0 ) // keep the first segment orientation (currently vertical) else if( iDx != 0 ) // keep the first segment orientation (currently vertical)
{ {
middle_position.y = segment->m_Start.y; middle_position.y = aSegment->m_Start.y;
} }
else else
{ {
if( ABS( middle_position.x - segment->m_Start.x ) < if( ABS( middle_position.x - aSegment->m_Start.x ) <
ABS( middle_position.y - segment->m_Start.y ) ) ABS( middle_position.y - aSegment->m_Start.y ) )
middle_position.x = segment->m_Start.x; middle_position.x = aSegment->m_Start.x;
else else
middle_position.y = segment->m_Start.y; middle_position.y = aSegment->m_Start.y;
} }
#endif #endif
segment->m_End = middle_position; aSegment->m_End = middle_position;
nextsegment->m_Start = middle_position; nextsegment->m_Start = middle_position;
nextsegment->m_End = new_pos; nextsegment->m_End = aPosition;
} }
/*
* Erase the last trace or the element at the current mouse position.
*/
void SCH_EDIT_FRAME::DeleteCurrentSegment( wxDC* DC ) void SCH_EDIT_FRAME::DeleteCurrentSegment( wxDC* DC )
{ {
SCH_SCREEN* screen = GetScreen(); SCH_SCREEN* screen = GetScreen();
...@@ -461,8 +450,6 @@ void SCH_EDIT_FRAME::DeleteCurrentSegment( wxDC* DC ) ...@@ -461,8 +450,6 @@ void SCH_EDIT_FRAME::DeleteCurrentSegment( wxDC* DC )
} }
/* Routine to create new connection struct.
*/
SCH_JUNCTION* SCH_EDIT_FRAME::AddJunction( wxDC* aDC, const wxPoint& aPosition, SCH_JUNCTION* SCH_EDIT_FRAME::AddJunction( wxDC* aDC, const wxPoint& aPosition,
bool aPutInUndoList ) bool aPutInUndoList )
{ {
...@@ -528,10 +515,6 @@ static void AbortCreateNewLine( EDA_DRAW_PANEL* Panel, wxDC* DC ) ...@@ -528,10 +515,6 @@ static void AbortCreateNewLine( EDA_DRAW_PANEL* Panel, wxDC* DC )
} }
/* Repeat the last item placement.
* Bus lines, text, labels
* Labels that end with a number will be incremented.
*/
void SCH_EDIT_FRAME::RepeatDrawItem( wxDC* DC ) void SCH_EDIT_FRAME::RepeatDrawItem( wxDC* DC )
{ {
if( m_itemToRepeat == NULL ) if( m_itemToRepeat == NULL )
......
...@@ -278,10 +278,7 @@ void LIB_POLYLINE::drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint ...@@ -278,10 +278,7 @@ void LIB_POLYLINE::drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint
{ {
wxPoint pos1; wxPoint pos1;
int color = ReturnLayerColor( LAYER_DEVICE ); int color = ReturnLayerColor( LAYER_DEVICE );
wxPoint* buffer = NULL;
// Buffer used to store current corners coordinates for drawings
static wxPoint* Buf_Poly_Drawings = NULL;
static unsigned Buf_Poly_Size = 0;
if( aColor < 0 ) // Used normal color or selected color if( aColor < 0 ) // Used normal color or selected color
{ {
...@@ -293,29 +290,11 @@ void LIB_POLYLINE::drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint ...@@ -293,29 +290,11 @@ void LIB_POLYLINE::drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint
color = aColor; color = aColor;
} }
// Set the size of the buffer of coordinates buffer = new wxPoint[ m_PolyPoints.size() ];
if( Buf_Poly_Drawings == NULL )
{
Buf_Poly_Size = m_PolyPoints.size();
Buf_Poly_Drawings = (wxPoint*) MyMalloc( sizeof(wxPoint) * Buf_Poly_Size );
}
else if( Buf_Poly_Size < m_PolyPoints.size() )
{
Buf_Poly_Size = m_PolyPoints.size();
Buf_Poly_Drawings = (wxPoint*) realloc( Buf_Poly_Drawings,
sizeof(wxPoint) * Buf_Poly_Size );
}
// This should probably throw an exception instead of displaying a warning message.
if( Buf_Poly_Drawings == NULL )
{
wxLogWarning( wxT( "Cannot allocate memory to draw polylines." ) );
return;
}
for( unsigned ii = 0; ii < m_PolyPoints.size(); ii++ ) for( unsigned ii = 0; ii < m_PolyPoints.size(); ii++ )
{ {
Buf_Poly_Drawings[ii] = aTransform.TransformCoordinate( m_PolyPoints[ii] ) + aOffset; buffer[ii] = aTransform.TransformCoordinate( m_PolyPoints[ii] ) + aOffset;
} }
FILL_T fill = aData ? NO_FILL : m_Fill; FILL_T fill = aData ? NO_FILL : m_Fill;
...@@ -326,16 +305,17 @@ void LIB_POLYLINE::drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint ...@@ -326,16 +305,17 @@ void LIB_POLYLINE::drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint
GRSetDrawMode( aDC, aDrawMode ); GRSetDrawMode( aDC, aDrawMode );
if( fill == FILLED_WITH_BG_BODYCOLOR ) if( fill == FILLED_WITH_BG_BODYCOLOR )
GRPoly( &aPanel->m_ClipBox, aDC, m_PolyPoints.size(), GRPoly( &aPanel->m_ClipBox, aDC, m_PolyPoints.size(), buffer, 1, GetPenSize(),
Buf_Poly_Drawings, 1, GetPenSize(),
(m_Flags & IS_MOVED) ? color : ReturnLayerColor( LAYER_DEVICE_BACKGROUND ), (m_Flags & IS_MOVED) ? color : ReturnLayerColor( LAYER_DEVICE_BACKGROUND ),
ReturnLayerColor( LAYER_DEVICE_BACKGROUND ) ); ReturnLayerColor( LAYER_DEVICE_BACKGROUND ) );
else if( fill == FILLED_SHAPE ) else if( fill == FILLED_SHAPE )
GRPoly( &aPanel->m_ClipBox, aDC, m_PolyPoints.size(), GRPoly( &aPanel->m_ClipBox, aDC, m_PolyPoints.size(), buffer, 1, GetPenSize(),
Buf_Poly_Drawings, 1, GetPenSize(), color, color ); color, color );
else else
GRPoly( &aPanel->m_ClipBox, aDC, m_PolyPoints.size(), GRPoly( &aPanel->m_ClipBox, aDC, m_PolyPoints.size(), buffer, 0, GetPenSize(),
Buf_Poly_Drawings, 0, GetPenSize(), color, color ); color, color );
delete[] buffer;
/* Set to one (1) to draw bounding box around polyline to validate /* Set to one (1) to draw bounding box around polyline to validate
* bounding box calculation. */ * bounding box calculation. */
......
...@@ -470,8 +470,26 @@ public: ...@@ -470,8 +470,26 @@ public:
bool LoadComponentAndSelectLib( LIB_ALIAS* aLibEntry, CMP_LIBRARY* aLibrary ); bool LoadComponentAndSelectLib( LIB_ALIAS* aLibEntry, CMP_LIBRARY* aLibrary );
/* Block commands: */ /* Block commands: */
/**
* Function ReturnBlockCommand
* returns the block command (BLOCK_MOVE, BLOCK_COPY...) corresponding to
* the \a aKey (ALT, SHIFT ALT ..)
*/
virtual int ReturnBlockCommand( int aKey ); virtual int ReturnBlockCommand( int aKey );
/**
* Function HandleBlockPlace
* handles the block place command.
*/
virtual void HandleBlockPlace( wxDC* DC ); virtual void HandleBlockPlace( wxDC* DC );
/**
* Function HandleBlockEnd
* performs a block end command.
* @return If command finished (zoom, delete ...) false is returned otherwise true
* is returned indicating more processing is required.
*/
virtual bool HandleBlockEnd( wxDC* DC ); virtual bool HandleBlockEnd( wxDC* DC );
void PlacePin( wxDC* DC ); void PlacePin( wxDC* DC );
......
...@@ -537,13 +537,7 @@ void SCH_SHEET_LIST::BuildSheetList( SCH_SHEET* aSheet ) ...@@ -537,13 +537,7 @@ void SCH_SHEET_LIST::BuildSheetList( SCH_SHEET* aSheet )
int count = aSheet->CountSheets(); int count = aSheet->CountSheets();
m_count = count; m_count = count;
m_index = 0; m_index = 0;
count *= sizeof(SCH_SHEET_PATH); m_List = new SCH_SHEET_PATH[ count ];
/* @bug - MyZMalloc() can return a NULL pointer if there is not enough
* memory. This code continues on it's merry way with out
* checking to see if the memory was actually allocated.
*/
m_List = (SCH_SHEET_PATH*) MyZMalloc( count );
m_currList.Clear(); m_currList.Clear();
} }
......
...@@ -317,7 +317,7 @@ public: ...@@ -317,7 +317,7 @@ public:
~SCH_SHEET_LIST() ~SCH_SHEET_LIST()
{ {
if( m_List ) if( m_List )
free( m_List ); delete[] m_List;
m_List = NULL; m_List = NULL;
} }
...@@ -460,10 +460,11 @@ private: ...@@ -460,10 +460,11 @@ private:
/** /**
* Function BuildSheetList * Function BuildSheetList
* builds the list of sheets and their sheet path from \a aSheet. * builds the list of sheets and their sheet path from \a aSheet.
* If aSheet = g_RootSheet, the full sheet path and sheet list is built * If \a aSheet is the root sheet, the full sheet path and sheet list are built.
* *
* @param aSheet is the starting sheet from which the list is built, * @param aSheet is the starting sheet from which the list is built, or NULL
* or NULL indicating that g_RootSheet should be used. * indicating that g_RootSheet should be used.
* @throw std::bad_alloc if the memory for the sheet path list could not be allocated.
*/ */
void BuildSheetList( SCH_SHEET* aSheet ); void BuildSheetList( SCH_SHEET* aSheet );
}; };
......
/**
* @file gerbview/block.cpp
* @brief Block operations: displacement.
*/
/* /*
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
...@@ -27,6 +22,11 @@ ...@@ -27,6 +22,11 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/ */
/**
* @file gerbview/block.cpp
* @brief Block operations: displacement.
*/
#include "fctsys.h" #include "fctsys.h"
#include "common.h" #include "common.h"
...@@ -45,10 +45,7 @@ ...@@ -45,10 +45,7 @@
static void DrawMovingBlockOutlines( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition, static void DrawMovingBlockOutlines( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition,
bool erase ); bool erase );
/* Return the block command (BLOCK_MOVE, BLOCK_COPY...) corresponding to
* the key (ALT, SHIFT ALT ..)
* Currently, only block move and block zoom is supported
*/
int GERBVIEW_FRAME::ReturnBlockCommand( int key ) int GERBVIEW_FRAME::ReturnBlockCommand( int key )
{ {
int cmd = 0; int cmd = 0;
...@@ -78,7 +75,6 @@ int GERBVIEW_FRAME::ReturnBlockCommand( int key ) ...@@ -78,7 +75,6 @@ int GERBVIEW_FRAME::ReturnBlockCommand( int key )
} }
/* Routine to handle the BLOCK PLACE command */
void GERBVIEW_FRAME::HandleBlockPlace( wxDC* DC ) void GERBVIEW_FRAME::HandleBlockPlace( wxDC* DC )
{ {
wxASSERT( DrawPanel->IsMouseCaptured() ); wxASSERT( DrawPanel->IsMouseCaptured() );
...@@ -120,9 +116,7 @@ void GERBVIEW_FRAME::HandleBlockPlace( wxDC* DC ) ...@@ -120,9 +116,7 @@ void GERBVIEW_FRAME::HandleBlockPlace( wxDC* DC )
break; break;
} }
DrawPanel->SetMouseCapture( NULL, NULL ); DrawPanel->EndMouseCapture( GetToolId(), DrawPanel->GetCurrentCursor(), wxEmptyString, false );
DrawPanel->EndMouseCapture( );
SetToolID( GetToolId(), DrawPanel->GetCurrentCursor(), wxEmptyString );
GetScreen()->SetModify(); GetScreen()->SetModify();
GetScreen()->ClearBlockCommand(); GetScreen()->ClearBlockCommand();
...@@ -132,16 +126,6 @@ void GERBVIEW_FRAME::HandleBlockPlace( wxDC* DC ) ...@@ -132,16 +126,6 @@ void GERBVIEW_FRAME::HandleBlockPlace( wxDC* DC )
} }
/**
* Function HandleBlockEnd( )
* Handle the "end" of a block command,
* i.e. is called at the end of the definition of the area of a block.
* depending on the current block command, this command is executed
* or parameters are initialized to prepare a call to HandleBlockPlace
* in GetScreen()->m_BlockLocate
* @return false if no item selected, or command finished,
* true if some items found and HandleBlockPlace must be called later
*/
bool GERBVIEW_FRAME::HandleBlockEnd( wxDC* DC ) bool GERBVIEW_FRAME::HandleBlockEnd( wxDC* DC )
{ {
bool nextcmd = false; bool nextcmd = false;
...@@ -188,10 +172,8 @@ bool GERBVIEW_FRAME::HandleBlockEnd( wxDC* DC ) ...@@ -188,10 +172,8 @@ bool GERBVIEW_FRAME::HandleBlockEnd( wxDC* DC )
if( ! nextcmd ) if( ! nextcmd )
{ {
GetScreen()->ClearBlockCommand(); GetScreen()->ClearBlockCommand();
DrawPanel->SetMouseCapture( NULL, NULL ); DrawPanel->EndMouseCapture( GetToolId(), DrawPanel->GetCurrentCursor(), wxEmptyString,
DrawPanel->EndMouseCapture( ); false );
SetToolID( GetToolId(), DrawPanel->GetCurrentCursor(), wxEmptyString );
DisplayToolMsg( wxEmptyString );
} }
if( zoom_command ) if( zoom_command )
...@@ -246,9 +228,6 @@ static void DrawMovingBlockOutlines( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wx ...@@ -246,9 +228,6 @@ static void DrawMovingBlockOutlines( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wx
} }
/*
* Erase the selected block.
*/
void GERBVIEW_FRAME::Block_Delete( wxDC* DC ) void GERBVIEW_FRAME::Block_Delete( wxDC* DC )
{ {
if( !IsOK( this, _( "Ok to delete block ?" ) ) ) if( !IsOK( this, _( "Ok to delete block ?" ) ) )
...@@ -272,9 +251,6 @@ void GERBVIEW_FRAME::Block_Delete( wxDC* DC ) ...@@ -272,9 +251,6 @@ void GERBVIEW_FRAME::Block_Delete( wxDC* DC )
} }
/*
* Function to move items in the current selected block
*/
void GERBVIEW_FRAME::Block_Move( wxDC* DC ) void GERBVIEW_FRAME::Block_Move( wxDC* DC )
{ {
wxPoint delta; wxPoint delta;
...@@ -304,9 +280,6 @@ void GERBVIEW_FRAME::Block_Move( wxDC* DC ) ...@@ -304,9 +280,6 @@ void GERBVIEW_FRAME::Block_Move( wxDC* DC )
} }
/*
* Function to duplicate items in the current selected block
*/
void GERBVIEW_FRAME::Block_Duplicate( wxDC* DC ) void GERBVIEW_FRAME::Block_Duplicate( wxDC* DC )
{ {
wxPoint delta; wxPoint delta;
...@@ -338,4 +311,3 @@ void GERBVIEW_FRAME::Block_Duplicate( wxDC* DC ) ...@@ -338,4 +311,3 @@ void GERBVIEW_FRAME::Block_Duplicate( wxDC* DC )
DrawPanel->Refresh(); DrawPanel->Refresh();
} }
...@@ -383,12 +383,31 @@ public: GERBVIEW_FRAME( wxWindow* father, const wxString& title, ...@@ -383,12 +383,31 @@ public: GERBVIEW_FRAME( wxWindow* father, const wxString& title,
void OnUpdateSelectDCode( wxUpdateUIEvent& aEvent ); void OnUpdateSelectDCode( wxUpdateUIEvent& aEvent );
void OnUpdateLayerSelectBox( wxUpdateUIEvent& aEvent ); void OnUpdateLayerSelectBox( wxUpdateUIEvent& aEvent );
/* handlers for block commands */ /**
* Function ReturnBlockCommand
* returns the block command (BLOCK_MOVE, BLOCK_COPY...) corresponding to
* the \a aKey (ALT, SHIFT ALT ..)
*/
virtual int ReturnBlockCommand( int key ); virtual int ReturnBlockCommand( int key );
/**
* Function HandleBlockPlace
* handles the block place command.
*/
virtual void HandleBlockPlace( wxDC* DC ); virtual void HandleBlockPlace( wxDC* DC );
virtual bool HandleBlockEnd( wxDC* DC );
/* Block operations: */ /**
* Function HandleBlockEnd( )
* handles the end of a block command,
* It is called at the end of the definition of the area of a block.
* Depending on the current block command, this command is executed
* or parameters are initialized to prepare a call to HandleBlockPlace
* in GetScreen()->m_BlockLocate
*
* @return false if no item selected, or command finished,
* true if some items found and HandleBlockPlace must be called later.
*/
virtual bool HandleBlockEnd( wxDC* DC );
/** /**
* Function Block_Delete * Function Block_Delete
......
...@@ -295,9 +295,11 @@ public: ...@@ -295,9 +295,11 @@ public:
* current cursor. * current cursor.
* @param aTitle The tool message to display in the status bar or wxEmptyString to clear * @param aTitle The tool message to display in the status bar or wxEmptyString to clear
* the message. * the message.
* @param aCallEndFunc Call the abort mouse capture callback if true.
*/ */
void EndMouseCapture( int aId = -1, int aCursorId = -1, void EndMouseCapture( int aId = -1, int aCursorId = -1,
const wxString& aTitle = wxEmptyString ); const wxString& aTitle = wxEmptyString,
bool aCallEndFunc = true );
inline bool IsMouseCaptured() const { return m_mouseCaptureCallback != NULL; } inline bool IsMouseCaptured() const { return m_mouseCaptureCallback != NULL; }
......
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 2008-2011 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 1992-2011 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/** /**
* The common library * The common library
* @file common.h * @file common.h
...@@ -144,7 +169,12 @@ extern wxString g_UserLibDirBuffer; ...@@ -144,7 +169,12 @@ extern wxString g_UserLibDirBuffer;
extern bool g_ShowPageLimits; // true to display the page limits extern bool g_ShowPageLimits; // true to display the page limits
/* File name extension definitions. */ /**
* File extension definitions. Please do not changes these. If a different
* file extension is needed, create a new definition in the application.
* Please note, just because they are defined as const doesn't guarantee
* that they cannot be changed.
*/
extern const wxString ProjectFileExtension; extern const wxString ProjectFileExtension;
extern const wxString SchematicFileExtension; extern const wxString SchematicFileExtension;
extern const wxString NetlistFileExtension; extern const wxString NetlistFileExtension;
...@@ -153,6 +183,7 @@ extern const wxString PcbFileExtension; ...@@ -153,6 +183,7 @@ extern const wxString PcbFileExtension;
extern const wxString PdfFileExtension; extern const wxString PdfFileExtension;
extern const wxString MacrosFileExtension; extern const wxString MacrosFileExtension;
/// Proper wxFileDialog wild card definitions.
extern const wxString ProjectFileWildcard; extern const wxString ProjectFileWildcard;
extern const wxString SchematicFileWildcard; extern const wxString SchematicFileWildcard;
extern const wxString BoardFileWildcard; extern const wxString BoardFileWildcard;
...@@ -172,7 +203,7 @@ extern wxString g_Prj_Config_LocalFilename; ...@@ -172,7 +203,7 @@ extern wxString g_Prj_Config_LocalFilename;
extern EDA_UNITS_T g_UserUnit; ///< display units extern EDA_UNITS_T g_UserUnit; ///< display units
/* Draw color for moving objects: */ /// Draw color for moving objects.
extern int g_GhostColor; extern int g_GhostColor;
...@@ -219,8 +250,7 @@ void SetLocaleTo_Default( void ); ...@@ -219,8 +250,7 @@ void SetLocaleTo_Default( void );
* the text already within the control is used. * the text already within the control is used.
* @return bool - true if the \a aCtrl had its size changed, else false. * @return bool - true if the \a aCtrl had its size changed, else false.
*/ */
bool EnsureTextCtrlWidth( wxTextCtrl* aCtrl, bool EnsureTextCtrlWidth( wxTextCtrl* aCtrl, const wxString* aString = NULL );
const wxString* aString = NULL );
/** /**
...@@ -307,8 +337,15 @@ wxString ReturnUnitSymbol( EDA_UNITS_T aUnits = g_UserUnit, ...@@ -307,8 +337,15 @@ wxString ReturnUnitSymbol( EDA_UNITS_T aUnits = g_UserUnit,
wxString GetUnitsLabel( EDA_UNITS_T aUnits ); wxString GetUnitsLabel( EDA_UNITS_T aUnits );
wxString GetAbbreviatedUnitsLabel( EDA_UNITS_T aUnit = g_UserUnit ); wxString GetAbbreviatedUnitsLabel( EDA_UNITS_T aUnit = g_UserUnit );
int ReturnValueFromString( EDA_UNITS_T aUnit, const wxString& TextValue, /**
int Internal_Unit ); * Function ReturnValueFromeString
* @return The string from Value, according to units (inch, mm ...) for display,
* and the initial unit for value
* Unit = display units (INCH, MM ..)
* Value = text
* Internal_Unit = units per inch for computed value
*/
int ReturnValueFromString( EDA_UNITS_T aUnit, const wxString& TextValue, int Internal_Unit );
/** /**
* Function ReturnStringFromValue * Function ReturnStringFromValue
...@@ -327,18 +364,22 @@ wxString ReturnStringFromValue( EDA_UNITS_T aUnit, ...@@ -327,18 +364,22 @@ wxString ReturnStringFromValue( EDA_UNITS_T aUnit,
bool aAdd_unit_symbol = false ); bool aAdd_unit_symbol = false );
/**
* Function AddUnitSymbol
* adds string " (mm):" or " ("):" to the static text Stext.
* Used in dialog boxes for entering values depending on selected units
*/
void AddUnitSymbol( wxStaticText& Stext, EDA_UNITS_T aUnit = g_UserUnit ); void AddUnitSymbol( wxStaticText& Stext, EDA_UNITS_T aUnit = g_UserUnit );
/* Add string " (mm):" or " ("):" to the static text Stext. /* Add string " (mm):" or " ("):" to the static text Stext.
* Used in dialog boxes for entering values depending on selected units */ * Used in dialog boxes for entering values depending on selected units */
void PutValueInLocalUnits( wxTextCtrl& TextCtr, int Value, void PutValueInLocalUnits( wxTextCtrl& TextCtr, int Value, int Internal_Unit );
int Internal_Unit );
/* Convert the number Value in a string according to the internal units /**
* Convert the number Value in a string according to the internal units
* and the selected unit (g_UserUnit) and put it in the wxTextCtrl TextCtrl * and the selected unit (g_UserUnit) and put it in the wxTextCtrl TextCtrl
**/ */
int ReturnValueFromTextCtrl( const wxTextCtrl& TextCtr, int ReturnValueFromTextCtrl( const wxTextCtrl& TextCtr, int Internal_Unit );
int Internal_Unit );
#ifdef KICAD_NANOMETRE #ifdef KICAD_NANOMETRE
...@@ -348,6 +389,7 @@ struct LENGTH_UNIT_DESC ...@@ -348,6 +389,7 @@ struct LENGTH_UNIT_DESC
const wxString m_Symbol; const wxString m_Symbol;
int m_Precision; int m_Precision;
}; };
extern const LENGTH_UNIT_DESC g_MillimetreDesc, g_InchDesc, g_MilDesc; extern const LENGTH_UNIT_DESC g_MillimetreDesc, g_InchDesc, g_MilDesc;
const LENGTH_UNIT_DESC *UnitDescription( EDA_UNITS_T aUnit ); const LENGTH_UNIT_DESC *UnitDescription( EDA_UNITS_T aUnit );
...@@ -358,10 +400,17 @@ wxString LengthToString( const LENGTH_UNIT_DESC *aUnit, LENGTH_DEF aValu ...@@ -358,10 +400,17 @@ wxString LengthToString( const LENGTH_UNIT_DESC *aUnit, LENGTH_DEF aValu
void LengthToTextCtrl( wxTextCtrl& TextCtr, LENGTH_DEF Value ); void LengthToTextCtrl( wxTextCtrl& TextCtr, LENGTH_DEF Value );
LENGTH_DEF LengthFromTextCtrl( const wxTextCtrl& TextCtr ); LENGTH_DEF LengthFromTextCtrl( const wxTextCtrl& TextCtr );
#endif #endif
/* return a String List from a string, with a specific splitter*/ /**
wxArrayString* wxStringSplit( wxString txt, wxChar splitter ); * Function wxStringSplit
* splita \a aString to a string list when split by \a aSplitter.
* @return the list
* @param aString : wxString : a String text
* @param aSplitter : wxChar : the 'split' character
*/
wxArrayString* wxStringSplit( wxString aString, wxChar aSplitter );
/** /**
* Function To_User_Unit * Function To_User_Unit
...@@ -371,16 +420,18 @@ wxArrayString* wxStringSplit( wxString txt, wxChar splitter ); ...@@ -371,16 +420,18 @@ wxArrayString* wxStringSplit( wxString txt, wxChar splitter );
* @param val : double : the given value * @param val : double : the given value
* @param internal_unit_value = internal units per inch * @param internal_unit_value = internal units per inch
*/ */
double To_User_Unit( EDA_UNITS_T aUnit, double To_User_Unit( EDA_UNITS_T aUnit, double val, int internal_unit_value );
double val,
int internal_unit_value ); /*
* Return in internal units the value "val" given in inch or mm
*/
int From_User_Unit( EDA_UNITS_T aUnit, double val, int internal_unit_value );
int From_User_Unit( EDA_UNITS_T aUnit, /**
double val, * Function GenDate
int internal_unit_value ); * @return A wsString object containg the date in the format "day month year" like
* "23 jun 2005".
*/
wxString GenDate(); wxString GenDate();
void MyFree( void* pt_mem );
void* MyZMalloc( size_t nb_octets );
void* MyMalloc( size_t nb_octets );
#endif // __INCLUDE__COMMON_H__ #endif // __INCLUDE__COMMON_H__
...@@ -404,7 +404,7 @@ public: ...@@ -404,7 +404,7 @@ public:
* Uses data prepared by BuildAirWiresTargetsList() * Uses data prepared by BuildAirWiresTargetsList()
* @param aDC = the current device context * @param aDC = the current device context
*/ */
void TraceAirWiresToTargets( wxDC* DC ); void TraceAirWiresToTargets( wxDC* aDC );
/** /**
* Function BuildAirWiresTargetsList * Function BuildAirWiresTargetsList
......
...@@ -713,7 +713,10 @@ private: ...@@ -713,7 +713,10 @@ private:
*/ */
SCH_NO_CONNECT* AddNoConnect( wxDC* aDC, const wxPoint& aPosition ); SCH_NO_CONNECT* AddNoConnect( wxDC* aDC, const wxPoint& aPosition );
// Junction /**
* Function AddJunction
* adds a new junction at \a aPosition.
*/
SCH_JUNCTION* AddJunction( wxDC* aDC, const wxPoint& aPosition, bool aPutInUndoList = false ); SCH_JUNCTION* AddJunction( wxDC* aDC, const wxPoint& aPosition, bool aPutInUndoList = false );
/** /**
...@@ -738,9 +741,26 @@ private: ...@@ -738,9 +741,26 @@ private:
*/ */
void OnConvertTextType( wxCommandEvent& aEvent ); void OnConvertTextType( wxCommandEvent& aEvent );
// Wire, Bus /**
* Function BeginSegment
* creates a new segment ( WIRE, BUS ) or terminates the current segment in progress.
*
* If the end of the current segment is on an other segment, place a junction if needed
* and terminates the command. If the end of the current segment is on a pin, terminate
* the command. In all other cases starts a new segment.
*/
void BeginSegment( wxDC* DC, int type ); void BeginSegment( wxDC* DC, int type );
/**
* Function EndSegment
* called to terminate a bus, wire, or line creation
*/
void EndSegment( wxDC* DC ); void EndSegment( wxDC* DC );
/**
* Function DeleteCurrentSegment
* erases the last segment at the current mouse position.
*/
void DeleteCurrentSegment( wxDC* DC ); void DeleteCurrentSegment( wxDC* DC );
void DeleteConnection( bool DeleteFullConnection ); void DeleteConnection( bool DeleteFullConnection );
...@@ -870,6 +890,10 @@ private: ...@@ -870,6 +890,10 @@ private:
void EditComponentFieldText( SCH_FIELD* aField, wxDC* aDC ); void EditComponentFieldText( SCH_FIELD* aField, wxDC* aDC );
void RotateField( SCH_FIELD* aField, wxDC* aDC ); void RotateField( SCH_FIELD* aField, wxDC* aDC );
/**
* Function PastListOfItems
* pastes a list of items from the block stack.
*/
void PasteListOfItems( wxDC* DC ); void PasteListOfItems( wxDC* DC );
/* Undo - redo */ /* Undo - redo */
...@@ -967,8 +991,21 @@ private: ...@@ -967,8 +991,21 @@ private:
public: public:
void Key( wxDC* DC, int hotkey, EDA_ITEM* DrawStruct ); void Key( wxDC* DC, int hotkey, EDA_ITEM* DrawStruct );
/* Block operations. */ /**
* Function InitBlockPasteInfos
* initializes the parameters used by the block paste command.
*/
void InitBlockPasteInfos(); void InitBlockPasteInfos();
/* Function HandleBlockEndByPopUp
* performs an end block command from context menu.
*
* This can be called only after HandleBlockEnd and the current command is block
* move. Execute a command other than block move from the current block move
* selected items list. Due to (minor) problems in undo/redo or/and display block,
* a mirror/rotate command is immediately executed and multiple block commands are
* not allowed (multiple commands are tricky to undo/redo in one time)
*/
void HandleBlockEndByPopUp( int Command, wxDC* DC ); void HandleBlockEndByPopUp( int Command, wxDC* DC );
/** /**
...@@ -1002,6 +1039,13 @@ public: ...@@ -1002,6 +1039,13 @@ public:
*/ */
virtual bool HandleBlockEnd( wxDC* DC ); virtual bool HandleBlockEnd( wxDC* DC );
/**
* Function RepeatDrawItem
* repeats the last item placement if the last item was a bus, bus entry,
* label, or component.
*
* Labels that end with a number will be incremented.
*/
void RepeatDrawItem( wxDC* DC ); void RepeatDrawItem( wxDC* DC );
void SetRepeatItem( SCH_ITEM* aItem ) { m_itemToRepeat = aItem; } void SetRepeatItem( SCH_ITEM* aItem ) { m_itemToRepeat = aItem; }
......
...@@ -755,6 +755,10 @@ public: ...@@ -755,6 +755,10 @@ public:
*/ */
void RecreateBOMFileFromBoard( wxCommandEvent& aEvent ); void RecreateBOMFileFromBoard( wxCommandEvent& aEvent );
/**
* Function ExportToGenCAD
* creates a file in GenCAD 1.4 format from the current board.
*/
void ExportToGenCAD( wxCommandEvent& event ); void ExportToGenCAD( wxCommandEvent& event );
/** /**
...@@ -1311,6 +1315,13 @@ public: ...@@ -1311,6 +1315,13 @@ public:
bool include_fixe ); bool include_fixe );
void LockModule( MODULE* aModule, bool aLocked ); void LockModule( MODULE* aModule, bool aLocked );
void AutoMoveModulesOnPcb( bool PlaceModulesHorsPcb ); void AutoMoveModulesOnPcb( bool PlaceModulesHorsPcb );
/**
* Function AutoPlaceModule
* automatically places footprints within the confines of the PCB edges.
* The components with the FIXED status are not moved. If the menu is
* calling the placement of 1 module, it will be replaced.
*/
void AutoPlaceModule( MODULE* Module, int place_mode, wxDC* DC ); void AutoPlaceModule( MODULE* Module, int place_mode, wxDC* DC );
/** /**
...@@ -1324,6 +1335,15 @@ public: ...@@ -1324,6 +1335,15 @@ public:
int GetOptimalModulePlacement( MODULE* aModule, wxDC* aDC ); int GetOptimalModulePlacement( MODULE* aModule, wxDC* aDC );
void GenModuleOnBoard( MODULE* Module ); void GenModuleOnBoard( MODULE* Module );
/**
* Function Compute_Ratsnest_PlaceModule
* displays the module's ratsnest during displacement, and assess the "cost"
* of the position.
*
* The cost is the longest ratsnest distance with penalty for connections
* approaching 45 degrees.
*/
float Compute_Ratsnest_PlaceModule( wxDC* DC ); float Compute_Ratsnest_PlaceModule( wxDC* DC );
/** /**
...@@ -1378,12 +1398,70 @@ public: ...@@ -1378,12 +1398,70 @@ public:
*/ */
void SendMessageToEESCHEMA( BOARD_ITEM* objectToSync ); void SendMessageToEESCHEMA( BOARD_ITEM* objectToSync );
/* Micro waves functions */ /**
* Function Edit_Gap
* edits the GAP module if it has changed the position and/or size of the pads that
* form the gap get a new value.
*/
void Edit_Gap( wxDC* DC, MODULE* Module ); void Edit_Gap( wxDC* DC, MODULE* Module );
/**
* Function Create_MuWaveBasicShape
* create a footprint with pad_count pads for micro wave applications.
* This footprint has pad_count pads:
* PAD_SMD, rectangular, H size = V size = current track width.
*/
MODULE* Create_MuWaveBasicShape( const wxString& name, int pad_count ); MODULE* Create_MuWaveBasicShape( const wxString& name, int pad_count );
/**
* Create_MuWaveComponent
* creates a module "GAP" or "STUB" used in micro wave designs.
* This module has 2 pads:
* PAD_SMD, rectangular, H size = V size = current track width.
* the "gap" is isolation created between this 2 pads
*/
MODULE* Create_MuWaveComponent( int shape_type ); MODULE* Create_MuWaveComponent( int shape_type );
MODULE* Create_MuWavePolygonShape(); MODULE* Create_MuWavePolygonShape();
void Begin_Self( wxDC* DC ); void Begin_Self( wxDC* DC );
/**
* Function Genre_Self
* creates a self-shaped coil for microwave applications.
* - Length Mself.lng
* - Extremities Mself.m_Start and Mself.m_End
*
* We must determine:
* Mself.nbrin = number of segments perpendicular to the direction
* (The coil nbrin will demicercles + 1 + 2 1 / 4 circle)
* Mself.lbrin = length of a strand
* Mself.radius = radius of rounded parts of the coil
* Mself.delta = segments extremities connection between him and the coil even
*
* The equations are
* Mself.m_Size.x = 2 * Mself.radius + Mself.lbrin
* Mself.m_Size.y * Mself.delta = 2 + 2 * Mself.nbrin * Mself.radius
* Mself.lng = 2 * Mself.delta / / connections to the coil
+ (Mself.nbrin-2) * Mself.lbrin / / length of the strands except 1st and last
+ (Mself.nbrin 1) * (PI * Mself.radius) / / length of rounded
* Mself.lbrin + / 2 - Melf.radius * 2) / / length of 1st and last bit
*
* The constraints are:
* Nbrin >= 2
* Mself.radius < Mself.m_Size.x
* Mself.m_Size.y = Mself.radius * 4 + 2 * Mself.raccord
* Mself.lbrin> Mself.radius * 2
*
* The calculation is conducted in the following way:
* Initially:
* Nbrin = 2
* Radius = 4 * m_Size.x (arbitrarily fixed value)
* Then:
* Increasing the number of segments to the desired length
* (Radius decreases if necessary)
*
*/
MODULE* Genere_Self( wxDC* DC ); MODULE* Genere_Self( wxDC* DC );
/** /**
......
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 2008-2011 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 2004-2011 KiCad Developers, see change_log.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/** /**
* @file autoplac.cpp * @file autoplac.cpp
* @brief Routiness to automatically place MODULES on a board. * @brief Routiness to automatically place MODULES on a board.
...@@ -69,10 +94,6 @@ static void CreateKeepOutRectangle( BOARD* Pcb, ...@@ -69,10 +94,6 @@ static void CreateKeepOutRectangle( BOARD* Pcb,
static MODULE* PickModule( PCB_EDIT_FRAME* pcbframe, wxDC* DC ); static MODULE* PickModule( PCB_EDIT_FRAME* pcbframe, wxDC* DC );
/* Routine to automatically place components in the contour of the PCB
* The components with the FIXED status are not moved. If the menu is
* calling the placement of 1 module, it will be replaced.
*/
void PCB_EDIT_FRAME::AutoPlaceModule( MODULE* Module, int place_mode, wxDC* DC ) void PCB_EDIT_FRAME::AutoPlaceModule( MODULE* Module, int place_mode, wxDC* DC )
{ {
int ii, activ; int ii, activ;
...@@ -867,12 +888,6 @@ int TstModuleOnBoard( BOARD* Pcb, MODULE* Module, bool TstOtherSide ) ...@@ -867,12 +888,6 @@ int TstModuleOnBoard( BOARD* Pcb, MODULE* Module, bool TstOtherSide )
} }
/*
* Display the module's ratsnest during displacement, and
* assess the "cost" of the position.
* The cost is the longest ratsnest distance with penalty for connections
* approaching 45 degrees.
*/
float PCB_EDIT_FRAME::Compute_Ratsnest_PlaceModule( wxDC* DC ) float PCB_EDIT_FRAME::Compute_Ratsnest_PlaceModule( wxDC* DC )
{ {
double cout, icout; double cout, icout;
...@@ -930,11 +945,9 @@ float PCB_EDIT_FRAME::Compute_Ratsnest_PlaceModule( wxDC* DC ) ...@@ -930,11 +945,9 @@ float PCB_EDIT_FRAME::Compute_Ratsnest_PlaceModule( wxDC* DC )
} }
/***********************************/ /**
/* Draw keep out area of a module. */ * Function CreateKeepOutRectangle
/***********************************/ * builds 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 aKeepOut * incremented by value aKeepOut
* Cell outside this rectangle, but inside the rectangle * Cell outside this rectangle, but inside the rectangle
...@@ -1066,8 +1079,10 @@ static bool Tri_RatsModules( MODULE* ref, MODULE* compare ) ...@@ -1066,8 +1079,10 @@ static bool Tri_RatsModules( MODULE* ref, MODULE* compare )
} }
/* Find the "best" module place /**
* The criteria of choice are: * Function PickModule
* find the "best" module place
* The criteria are:
* - Maximum ratsnest with modules already placed * - Maximum ratsnest with modules already placed
* - Max size, and number of pads max * - Max size, and number of pads max
*/ */
...@@ -1165,9 +1180,9 @@ static MODULE* PickModule( PCB_EDIT_FRAME* pcbframe, wxDC* DC ) ...@@ -1165,9 +1180,9 @@ static MODULE* PickModule( PCB_EDIT_FRAME* pcbframe, wxDC* DC )
*/ */
int Propagation( PCB_EDIT_FRAME* frame ) int Propagation( PCB_EDIT_FRAME* frame )
{ {
int row, col, nn; int row, col;
long current_cell, old_cell_H; long current_cell, old_cell_H;
int long* pt_cell_V; std::vector< long > pt_cell_V;
int nbpoints = 0; int nbpoints = 0;
#define NO_CELL_ZONE (HOLE | CELL_is_EDGE | CELL_is_ZONE) #define NO_CELL_ZONE (HOLE | CELL_is_EDGE | CELL_is_ZONE)
...@@ -1176,13 +1191,10 @@ int Propagation( PCB_EDIT_FRAME* frame ) ...@@ -1176,13 +1191,10 @@ int Propagation( PCB_EDIT_FRAME* frame )
frame->MsgPanel->SetMessage( 57, wxT( "Detect" ), msg, CYAN ); frame->MsgPanel->SetMessage( 57, wxT( "Detect" ), msg, CYAN );
frame->MsgPanel->SetMessage( -1, wxEmptyString, wxT( "1" ), CYAN ); frame->MsgPanel->SetMessage( -1, wxEmptyString, wxT( "1" ), CYAN );
// Alloc memory to handle 1 line or 1 column on the routing matrix pt_cell_V.reserve( MAX( Nrows, Ncols ) );
nn = MAX( Nrows, Ncols ) * sizeof(*pt_cell_V); fill( pt_cell_V.begin(), pt_cell_V.end(), 0 );
pt_cell_V = (long*) MyMalloc( nn );
/* search 1 : from left to right and top to bottom */
memset( pt_cell_V, 0, nn );
// Search from left to right and top to bottom.
for( row = 0; row < Nrows; row++ ) for( row = 0; row < Nrows; row++ )
{ {
old_cell_H = 0; old_cell_H = 0;
...@@ -1205,13 +1217,14 @@ int Propagation( PCB_EDIT_FRAME* frame ) ...@@ -1205,13 +1217,14 @@ int Propagation( PCB_EDIT_FRAME* frame )
} }
} }
/* search 2 : from right to left and top to bottom */ // Search from right to left and top to bottom/
frame->MsgPanel->SetMessage( -1, wxEmptyString, wxT( "2" ), CYAN ); frame->MsgPanel->SetMessage( -1, wxEmptyString, wxT( "2" ), CYAN );
memset( pt_cell_V, 0, nn ); fill( pt_cell_V.begin(), pt_cell_V.end(), 0 );
for( row = 0; row < Nrows; row++ ) for( row = 0; row < Nrows; row++ )
{ {
old_cell_H = 0; old_cell_H = 0;
for( col = Ncols - 1; col >= 0; col-- ) for( col = Ncols - 1; col >= 0; col-- )
{ {
current_cell = GetCell( row, col, BOTTOM ) & NO_CELL_ZONE; current_cell = GetCell( row, col, BOTTOM ) & NO_CELL_ZONE;
...@@ -1230,9 +1243,9 @@ int Propagation( PCB_EDIT_FRAME* frame ) ...@@ -1230,9 +1243,9 @@ int Propagation( PCB_EDIT_FRAME* frame )
} }
} }
/* search 3 : from bottom to top and right to left balayage */ // Search from bottom to top and right to left.
frame->MsgPanel->SetMessage( -1, wxEmptyString, wxT( "3" ), CYAN ); frame->MsgPanel->SetMessage( -1, wxEmptyString, wxT( "3" ), CYAN );
memset( pt_cell_V, 0, nn ); fill( pt_cell_V.begin(), pt_cell_V.end(), 0 );
for( col = Ncols - 1; col >= 0; col-- ) for( col = Ncols - 1; col >= 0; col-- )
{ {
...@@ -1256,9 +1269,9 @@ int Propagation( PCB_EDIT_FRAME* frame ) ...@@ -1256,9 +1269,9 @@ int Propagation( PCB_EDIT_FRAME* frame )
} }
} }
/* search 4 : from bottom to top and left to right */ // Search from bottom to top and left to right.
frame->MsgPanel->SetMessage( -1, wxEmptyString, wxT( "4" ), CYAN ); frame->MsgPanel->SetMessage( -1, wxEmptyString, wxT( "4" ), CYAN );
memset( pt_cell_V, 0, nn ); fill( pt_cell_V.begin(), pt_cell_V.end(), 0 );
for( col = 0; col < Ncols; col++ ) for( col = 0; col < Ncols; col++ )
{ {
...@@ -1282,7 +1295,5 @@ int Propagation( PCB_EDIT_FRAME* frame ) ...@@ -1282,7 +1295,5 @@ int Propagation( PCB_EDIT_FRAME* frame )
} }
} }
MyFree( pt_cell_V );
return nbpoints; return nbpoints;
} }
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 2004-2011 KiCad Developers, see change_log.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/** /**
* @file autorout.h * @file autorout.h
*/ */
...@@ -60,6 +85,10 @@ typedef char MATRIX_CELL; ...@@ -60,6 +85,10 @@ typedef char MATRIX_CELL;
typedef int DIST_CELL; typedef int DIST_CELL;
typedef char DIR_CELL; typedef char DIR_CELL;
/**
* class MATRIX_ROUTING_HEAD
*/
class MATRIX_ROUTING_HEAD /* header of blocks of MATRIX_CELL */ class MATRIX_ROUTING_HEAD /* header of blocks of MATRIX_CELL */
{ {
public: public:
...@@ -79,8 +108,21 @@ public: ...@@ -79,8 +108,21 @@ public:
MATRIX_ROUTING_HEAD(); MATRIX_ROUTING_HEAD();
~MATRIX_ROUTING_HEAD(); ~MATRIX_ROUTING_HEAD();
/**
* Function ComputeMatrixSize
* calculates the number of rows and columns of dimensions of \a aPcb for routing and
* automatic calculation of area.
*/
bool ComputeMatrixSize( BOARD* aPcb ); bool ComputeMatrixSize( BOARD* aPcb );
/**
* Function InitBoard
* initializes the data structures.
*
* @return the amount of memory used or -1 if default.
*/
int InitBoard(); int InitBoard();
void UnInitBoard(); void UnInitBoard();
}; };
......
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 1992-2011 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/** /**
* @file pcbnew/block.cpp * @file pcbnew/block.cpp
*/ */
...@@ -58,6 +83,7 @@ static bool blockIncludePcbTexts = true; ...@@ -58,6 +83,7 @@ static bool blockIncludePcbTexts = true;
static bool blockDrawItems = true; static bool blockDrawItems = true;
static bool blockIncludeItemsOnInvisibleLayers = false; static bool blockIncludeItemsOnInvisibleLayers = false;
/************************************/ /************************************/
/* class DIALOG_BLOCK_OPTIONS */ /* class DIALOG_BLOCK_OPTIONS */
/************************************/ /************************************/
...@@ -149,14 +175,6 @@ void DIALOG_BLOCK_OPTIONS::ExecuteCommand( wxCommandEvent& event ) ...@@ -149,14 +175,6 @@ void DIALOG_BLOCK_OPTIONS::ExecuteCommand( wxCommandEvent& event )
} }
/**
* Function ReturnBlockCommand
* Returns the block command internat code (BLOCK_MOVE, BLOCK_COPY...)
* corresponding to the keys pressed (ALT, SHIFT, SHIFT ALT ..) when
* block command is started by dragging the mouse.
* @param aKey = the key modifiers (Alt, Shift ...)
* @return the block command id (BLOCK_MOVE, BLOCK_COPY...)
*/
int PCB_EDIT_FRAME::ReturnBlockCommand( int aKey ) int PCB_EDIT_FRAME::ReturnBlockCommand( int aKey )
{ {
int cmd = 0; int cmd = 0;
...@@ -196,13 +214,6 @@ int PCB_EDIT_FRAME::ReturnBlockCommand( int aKey ) ...@@ -196,13 +214,6 @@ int PCB_EDIT_FRAME::ReturnBlockCommand( int aKey )
} }
/**
* Function HandleBlockPlace( )
* Called after HandleBlockEnd, when a block command needs to be
* executed after the block is moved to its new place
* (bloc move, drag, copy .. )
* Parameters must be initialized in GetScreen()->m_BlockLocate
*/
void PCB_EDIT_FRAME::HandleBlockPlace( wxDC* DC ) void PCB_EDIT_FRAME::HandleBlockPlace( wxDC* DC )
{ {
if( !DrawPanel->IsMouseCaptured() ) if( !DrawPanel->IsMouseCaptured() )
...@@ -245,7 +256,7 @@ void PCB_EDIT_FRAME::HandleBlockPlace( wxDC* DC ) ...@@ -245,7 +256,7 @@ void PCB_EDIT_FRAME::HandleBlockPlace( wxDC* DC )
OnModify(); OnModify();
DrawPanel->SetMouseCapture( NULL, NULL ); DrawPanel->EndMouseCapture( GetToolId(), DrawPanel->GetCurrentCursor(), wxEmptyString, false );
GetScreen()->ClearBlockCommand(); GetScreen()->ClearBlockCommand();
if( GetScreen()->m_BlockLocate.GetCount() ) if( GetScreen()->m_BlockLocate.GetCount() )
...@@ -253,22 +264,9 @@ void PCB_EDIT_FRAME::HandleBlockPlace( wxDC* DC ) ...@@ -253,22 +264,9 @@ void PCB_EDIT_FRAME::HandleBlockPlace( wxDC* DC )
DisplayError( this, wxT( "Error in HandleBlockPLace some items left in list" ) ); DisplayError( this, wxT( "Error in HandleBlockPLace some items left in list" ) );
GetScreen()->m_BlockLocate.ClearItemsList(); GetScreen()->m_BlockLocate.ClearItemsList();
} }
DisplayToolMsg( wxEmptyString );
DrawPanel->SetCursor( DrawPanel->GetCurrentCursor() );
} }
/**
* Function HandleBlockEnd( )
* Handle the "end" of a block command,
* i.e. is called at the end of the definition of the area of a block.
* depending on the current block command, this command is executed
* or parameters are initialized to prepare a call to HandleBlockPlace
* in GetScreen()->m_BlockLocate
* @return false if no item selected, or command finished,
* true if some items found and HandleBlockPlace must be called later
*/
bool PCB_EDIT_FRAME::HandleBlockEnd( wxDC* DC ) bool PCB_EDIT_FRAME::HandleBlockEnd( wxDC* DC )
{ {
bool nextcmd = false; // Will be set to true if a block place is needed bool nextcmd = false; // Will be set to true if a block place is needed
...@@ -277,9 +275,9 @@ bool PCB_EDIT_FRAME::HandleBlockEnd( wxDC* DC ) ...@@ -277,9 +275,9 @@ bool PCB_EDIT_FRAME::HandleBlockEnd( wxDC* DC )
// If coming here after cancel block, clean up and exit // If coming here after cancel block, clean up and exit
if( GetScreen()->m_BlockLocate.m_State == STATE_NO_BLOCK ) if( GetScreen()->m_BlockLocate.m_State == STATE_NO_BLOCK )
{ {
DrawPanel->SetMouseCapture( NULL, NULL ); DrawPanel->EndMouseCapture( GetToolId(), DrawPanel->GetCurrentCursor(), wxEmptyString,
false );
GetScreen()->ClearBlockCommand(); GetScreen()->ClearBlockCommand();
DisplayToolMsg( wxEmptyString );
return false; return false;
} }
...@@ -368,22 +366,14 @@ bool PCB_EDIT_FRAME::HandleBlockEnd( wxDC* DC ) ...@@ -368,22 +366,14 @@ bool PCB_EDIT_FRAME::HandleBlockEnd( wxDC* DC )
if( ! nextcmd ) if( ! nextcmd )
{ {
GetScreen()->ClearBlockCommand(); GetScreen()->ClearBlockCommand();
DrawPanel->SetMouseCapture( NULL, NULL ); DrawPanel->EndMouseCapture( GetToolId(), DrawPanel->GetCurrentCursor(), wxEmptyString,
DisplayToolMsg( wxEmptyString ); false );
} }
return nextcmd; return nextcmd;
} }
/* Block operations: */
/*
* Function Block_SelectItems
* Uses GetScreen()->m_BlockLocate
* select items within the selected block.
* selected items are put in the pick list
*/
void PCB_EDIT_FRAME::Block_SelectItems() void PCB_EDIT_FRAME::Block_SelectItems()
{ {
int layerMask; int layerMask;
...@@ -598,9 +588,6 @@ static void drawMovingBlock( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& a ...@@ -598,9 +588,6 @@ static void drawMovingBlock( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& a
} }
/*
* Erase selected block.
*/
void PCB_EDIT_FRAME::Block_Delete() void PCB_EDIT_FRAME::Block_Delete()
{ {
OnModify(); OnModify();
...@@ -633,7 +620,7 @@ void PCB_EDIT_FRAME::Block_Delete() ...@@ -633,7 +620,7 @@ void PCB_EDIT_FRAME::Block_Delete()
case PCB_LINE_T: // a segment not on copper layers case PCB_LINE_T: // a segment not on copper layers
case PCB_TEXT_T: // a text on a layer case PCB_TEXT_T: // a text on a layer
case PCB_TRACE_T: // a track segment (segment on a copper layer) case PCB_TRACE_T: // a track segment (segment on a copper layer)
case PCB_VIA_T: // a via (like atrack segment on a copper layer) case PCB_VIA_T: // a via (like track segment on a copper layer)
case PCB_DIMENSION_T: // a dimension (graphic item) case PCB_DIMENSION_T: // a dimension (graphic item)
case PCB_TARGET_T: // a target (graphic item) case PCB_TARGET_T: // a target (graphic item)
item->UnLink(); item->UnLink();
...@@ -661,11 +648,6 @@ void PCB_EDIT_FRAME::Block_Delete() ...@@ -661,11 +648,6 @@ void PCB_EDIT_FRAME::Block_Delete()
} }
/*
* Function Block_Rotate
* Rotate all items within the selected block.
* The rotation center is the center of the block
*/
void PCB_EDIT_FRAME::Block_Rotate() void PCB_EDIT_FRAME::Block_Rotate()
{ {
wxPoint oldpos; wxPoint oldpos;
...@@ -696,7 +678,7 @@ void PCB_EDIT_FRAME::Block_Rotate() ...@@ -696,7 +678,7 @@ void PCB_EDIT_FRAME::Block_Rotate()
/* Move and rotate the track segments */ /* Move and rotate the track segments */
case PCB_TRACE_T: // a track segment (segment on a copper layer) case PCB_TRACE_T: // a track segment (segment on a copper layer)
case PCB_VIA_T: // a via (like atrack segment on a copper layer) case PCB_VIA_T: // a via (like track segment on a copper layer)
m_Pcb->m_Status_Pcb = 0; m_Pcb->m_Status_Pcb = 0;
break; break;
...@@ -726,11 +708,6 @@ void PCB_EDIT_FRAME::Block_Rotate() ...@@ -726,11 +708,6 @@ void PCB_EDIT_FRAME::Block_Rotate()
} }
/**
* Function Block_Flip
* flips items within the selected block.
* The flip center is the center of the block
*/
void PCB_EDIT_FRAME::Block_Flip() void PCB_EDIT_FRAME::Block_Flip()
{ {
#define INVERT( pos ) (pos) = center.y - ( (pos) - center.y ) #define INVERT( pos ) (pos) = center.y - ( (pos) - center.y )
...@@ -762,7 +739,7 @@ void PCB_EDIT_FRAME::Block_Flip() ...@@ -762,7 +739,7 @@ void PCB_EDIT_FRAME::Block_Flip()
/* Move and rotate the track segments */ /* Move and rotate the track segments */
case PCB_TRACE_T: // a track segment (segment on a copper layer) case PCB_TRACE_T: // a track segment (segment on a copper layer)
case PCB_VIA_T: // a via (like atrack segment on a copper layer) case PCB_VIA_T: // a via (like track segment on a copper layer)
m_Pcb->m_Status_Pcb = 0; m_Pcb->m_Status_Pcb = 0;
break; break;
...@@ -792,12 +769,6 @@ void PCB_EDIT_FRAME::Block_Flip() ...@@ -792,12 +769,6 @@ void PCB_EDIT_FRAME::Block_Flip()
} }
/*
* Function Block_Move
* moves all tracks and segments within the selected block.
* New location is determined by the current offset from the selected block's
* original location.
*/
void PCB_EDIT_FRAME::Block_Move() void PCB_EDIT_FRAME::Block_Move()
{ {
OnModify(); OnModify();
...@@ -852,12 +823,6 @@ void PCB_EDIT_FRAME::Block_Move() ...@@ -852,12 +823,6 @@ void PCB_EDIT_FRAME::Block_Move()
} }
/*
* Function Block_Duplicate
* duplicates all items within the selected block.
* New location is determined by the current offset from the selected block's
* original location.
*/
void PCB_EDIT_FRAME::Block_Duplicate() void PCB_EDIT_FRAME::Block_Duplicate()
{ {
wxPoint MoveVector = GetScreen()->m_BlockLocate.m_MoveVector; wxPoint MoveVector = GetScreen()->m_BlockLocate.m_MoveVector;
......
/****************************************************/ /*
/* block_module_editor.cpp */ * This program source code file is part of KiCad, a free EDA CAD application.
/* Handle block commands for the footprint editor */ *
/****************************************************/ * Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 1992-2011 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @file block_module_editor.cpp
* @brief Footprint editor block handling implementation.
*/
#include "fctsys.h" #include "fctsys.h"
#include "appl_wxstruct.h" #include "appl_wxstruct.h"
...@@ -194,8 +219,8 @@ bool FOOTPRINT_EDIT_FRAME::HandleBlockEnd( wxDC* DC ) ...@@ -194,8 +219,8 @@ bool FOOTPRINT_EDIT_FRAME::HandleBlockEnd( wxDC* DC )
GetScreen()->ClearBlockCommand(); GetScreen()->ClearBlockCommand();
SetCurItem( NULL ); SetCurItem( NULL );
DrawPanel->SetMouseCapture( NULL, NULL ); DrawPanel->EndMouseCapture( GetToolId(), DrawPanel->GetCurrentCursor(), wxEmptyString,
SetToolID( GetToolId(), DrawPanel->GetCurrentCursor(), wxEmptyString ); false );
DrawPanel->Refresh( true ); DrawPanel->Refresh( true );
} }
...@@ -264,9 +289,8 @@ void FOOTPRINT_EDIT_FRAME::HandleBlockPlace( wxDC* DC ) ...@@ -264,9 +289,8 @@ void FOOTPRINT_EDIT_FRAME::HandleBlockPlace( wxDC* DC )
GetScreen()->m_BlockLocate.m_State = STATE_NO_BLOCK; GetScreen()->m_BlockLocate.m_State = STATE_NO_BLOCK;
GetScreen()->m_BlockLocate.m_Command = BLOCK_IDLE; GetScreen()->m_BlockLocate.m_Command = BLOCK_IDLE;
SetCurItem( NULL ); SetCurItem( NULL );
DrawPanel->SetMouseCapture( NULL, NULL ); DrawPanel->EndMouseCapture( GetToolId(), DrawPanel->GetCurrentCursor(), wxEmptyString, false );
DrawPanel->Refresh( true ); DrawPanel->Refresh( true );
SetToolID( GetToolId(), DrawPanel->GetCurrentCursor(), wxEmptyString );
} }
......
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 2008-2011 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 2004-2011 KiCad Developers, see change_log.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/** /**
* @file board.cpp * @file board.cpp
* @brief Functions for autorouting * @brief Functions for autorouting
...@@ -19,10 +44,6 @@ ...@@ -19,10 +44,6 @@
#include "class_pcb_text.h" #include "class_pcb_text.h"
/*
* Calculates nrows and ncols, dimensions of the matrix representation of BOARD
* for routing and automatic calculation of area.
*/
bool MATRIX_ROUTING_HEAD::ComputeMatrixSize( BOARD* aPcb ) bool MATRIX_ROUTING_HEAD::ComputeMatrixSize( BOARD* aPcb )
{ {
aPcb->ComputeBoundingBox(); aPcb->ComputeBoundingBox();
...@@ -51,8 +72,6 @@ bool MATRIX_ROUTING_HEAD::ComputeMatrixSize( BOARD* aPcb ) ...@@ -51,8 +72,6 @@ bool MATRIX_ROUTING_HEAD::ComputeMatrixSize( BOARD* aPcb )
} }
/* class MATRIX_ROUTING_HEAD
*/
MATRIX_ROUTING_HEAD::MATRIX_ROUTING_HEAD() MATRIX_ROUTING_HEAD::MATRIX_ROUTING_HEAD()
{ {
m_BoardSide[0] = m_BoardSide[1] = NULL; m_BoardSide[0] = m_BoardSide[1] = NULL;
...@@ -70,9 +89,6 @@ MATRIX_ROUTING_HEAD::~MATRIX_ROUTING_HEAD() ...@@ -70,9 +89,6 @@ MATRIX_ROUTING_HEAD::~MATRIX_ROUTING_HEAD()
} }
/* initialize the data structures
* returns the RAM size used, or -1 if default
*/
int MATRIX_ROUTING_HEAD::InitBoard() int MATRIX_ROUTING_HEAD::InitBoard()
{ {
int ii, kk; int ii, kk;
...@@ -93,19 +109,19 @@ int MATRIX_ROUTING_HEAD::InitBoard() ...@@ -93,19 +109,19 @@ int MATRIX_ROUTING_HEAD::InitBoard()
m_DirSide[kk] = NULL; m_DirSide[kk] = NULL;
/* allocate Board & initialize everything to empty */ /* allocate Board & initialize everything to empty */
m_BoardSide[kk] = (MATRIX_CELL*) MyZMalloc( ii * sizeof(MATRIX_CELL) ); m_BoardSide[kk] = (MATRIX_CELL*) operator new( ii * sizeof(MATRIX_CELL) );
if( m_BoardSide[kk] == NULL ) if( m_BoardSide[kk] == NULL )
return -1; return -1;
/***** allocate Distances *****/ /***** allocate Distances *****/
m_DistSide[kk] = (DIST_CELL*) MyZMalloc( ii * sizeof(DIST_CELL) ); m_DistSide[kk] = (DIST_CELL*) operator new( ii * sizeof(DIST_CELL) );
if( m_DistSide[kk] == NULL ) if( m_DistSide[kk] == NULL )
return -1; return -1;
/***** allocate Dir (chars) *****/ /***** allocate Dir (chars) *****/
m_DirSide[kk] = (char*) MyZMalloc( ii ); m_DirSide[kk] = (char*) operator new( ii );
if( m_DirSide[kk] == NULL ) if( m_DirSide[kk] == NULL )
return -1; return -1;
...@@ -128,21 +144,21 @@ void MATRIX_ROUTING_HEAD::UnInitBoard() ...@@ -128,21 +144,21 @@ 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] ); delete m_DirSide[ii];
m_DirSide[ii] = NULL; m_DirSide[ii] = NULL;
} }
/***** de-allocate Distances matrix *****/ /***** de-allocate Distances matrix *****/
if( m_DistSide[ii] ) if( m_DistSide[ii] )
{ {
MyFree( m_DistSide[ii] ); delete m_DistSide[ii];
m_DistSide[ii] = NULL; m_DistSide[ii] = NULL;
} }
/**** de-allocate cells matrix *****/ /**** de-allocate cells matrix *****/
if( m_BoardSide[ii] ) if( m_BoardSide[ii] )
{ {
MyFree( m_BoardSide[ii] ); delete m_BoardSide[ii];
m_BoardSide[ii] = NULL; m_BoardSide[ii] = NULL;
} }
} }
...@@ -151,10 +167,11 @@ void MATRIX_ROUTING_HEAD::UnInitBoard() ...@@ -151,10 +167,11 @@ void MATRIX_ROUTING_HEAD::UnInitBoard()
} }
/* Initialize the cell board is set and VIA_IMPOSSIBLE HOLE according to /**
* the setbacks * Function PlaceCells
* The elements of net_code = net_code will not be occupied as places * initializes the cell board is set and VIA_IMPOSSIBLE HOLE according to the setbacks.
* but only VIA_IMPOSSIBLE * The elements of net_code = net_code will not be occupied as places but only
* VIA_IMPOSSIBLE
* For single-sided Routing 1: * For single-sided Routing 1:
* BOTTOM side is used and Route_Layer_BOTTOM = Route_Layer_TOP * BOTTOM side is used and Route_Layer_BOTTOM = Route_Layer_TOP
* *
......
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 2008-2011 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 2004-2011 KiCad Developers, see change_log.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/** /**
* @file export_gencad.cpp * @file export_gencad.cpp
* @brief Export GenCAD 1.4 format. * @brief Export GenCAD 1.4 format.
...@@ -53,6 +78,7 @@ static const wxString GenCAD_Layer_Name[32] = ...@@ -53,6 +78,7 @@ static const wxString GenCAD_Layer_Name[32] =
int offsetX, offsetY; int offsetX, offsetY;
D_PAD* PadList; D_PAD* PadList;
/* 2 helper functions to calculate coordinates of modules in gencad values ( /* 2 helper functions to calculate coordinates of modules in gencad values (
* GenCAD Y axis from bottom to top) * GenCAD Y axis from bottom to top)
*/ */
...@@ -68,9 +94,6 @@ static int mapYto( int y ) ...@@ -68,9 +94,6 @@ static int mapYto( int y )
} }
/*
* Creates an Export file (format GenCAD 1.4) from the current board.
*/
void PCB_EDIT_FRAME::ExportToGenCAD( wxCommandEvent& event ) void PCB_EDIT_FRAME::ExportToGenCAD( wxCommandEvent& event )
{ {
wxFileName fn = GetScreen()->GetFileName(); wxFileName fn = GetScreen()->GetFileName();
...@@ -612,6 +635,7 @@ void CreateRoutesSection( FILE* file, BOARD* pcb ) ...@@ -612,6 +635,7 @@ void CreateRoutesSection( FILE* file, BOARD* pcb )
// Count items // Count items
nbitems = 0; nbitems = 0;
for( track = pcb->m_Track; track != NULL; track = track->Next() ) for( track = pcb->m_Track; track != NULL; track = track->Next() )
nbitems++; nbitems++;
...@@ -621,7 +645,7 @@ void CreateRoutesSection( FILE* file, BOARD* pcb ) ...@@ -621,7 +645,7 @@ void CreateRoutesSection( FILE* file, BOARD* pcb )
nbitems++; nbitems++;
} }
tracklist = (TRACK**) MyMalloc( (nbitems + 1) * sizeof(TRACK*) ); tracklist = (TRACK**) operator new( (nbitems + 1) * sizeof( TRACK* ) );
nbitems = 0; nbitems = 0;
...@@ -690,7 +714,7 @@ void CreateRoutesSection( FILE* file, BOARD* pcb ) ...@@ -690,7 +714,7 @@ void CreateRoutesSection( FILE* file, BOARD* pcb )
fputs( "$ENDROUTES\n\n", file ); fputs( "$ENDROUTES\n\n", file );
free( tracklist ); delete tracklist;
} }
...@@ -926,6 +950,5 @@ void FootprintWriteShape( FILE* file, MODULE* module ) ...@@ -926,6 +950,5 @@ void FootprintWriteShape( FILE* file, MODULE* module )
default: default:
break; break;
} /* End switch Items type */ } /* End switch Items type */
} }
} }
...@@ -71,13 +71,11 @@ static bool HasNonSMDPins( MODULE* aModule ) ...@@ -71,13 +71,11 @@ static bool HasNonSMDPins( MODULE* aModule )
#endif #endif
/* Generate the module positions, used component placement.
*/
void PCB_EDIT_FRAME::GenModulesPosition( wxCommandEvent& event ) void PCB_EDIT_FRAME::GenModulesPosition( wxCommandEvent& event )
{ {
bool doBoardBack = false; bool doBoardBack = false;
MODULE* module; MODULE* module;
LIST_MOD* Liste = 0; LIST_MOD* list = NULL;
char line[1024]; char line[1024];
wxFileName fnFront; wxFileName fnFront;
wxFileName fnBack; wxFileName fnBack;
...@@ -192,7 +190,7 @@ void PCB_EDIT_FRAME::GenModulesPosition( wxCommandEvent& event ) ...@@ -192,7 +190,7 @@ void PCB_EDIT_FRAME::GenModulesPosition( wxCommandEvent& event )
AppendMsgPanel( _( "Module count" ), msg, RED ); AppendMsgPanel( _( "Module count" ), msg, RED );
// Sort the list of modules alphabetically // Sort the list of modules alphabetically
Liste = (LIST_MOD*) MyZMalloc( moduleCount * sizeof(LIST_MOD) ); list = new LIST_MOD[moduleCount];
module = GetBoard()->m_Modules; module = GetBoard()->m_Modules;
...@@ -204,13 +202,13 @@ void PCB_EDIT_FRAME::GenModulesPosition( wxCommandEvent& event ) ...@@ -204,13 +202,13 @@ void PCB_EDIT_FRAME::GenModulesPosition( wxCommandEvent& event )
if( (module->m_Attributs & MOD_CMS) == 0 ) if( (module->m_Attributs & MOD_CMS) == 0 )
continue; continue;
Liste[ii].m_Module = module; list[ii].m_Module = module;
Liste[ii].m_Reference = module->m_Reference->m_Text; list[ii].m_Reference = module->m_Reference->m_Text;
Liste[ii].m_Value = module->m_Value->m_Text; list[ii].m_Value = module->m_Value->m_Text;
ii++; ii++;
} }
qsort( Liste, moduleCount, sizeof(LIST_MOD), ListeModCmp ); qsort( list, moduleCount, sizeof(LIST_MOD), ListeModCmp );
// Write file header // Write file header
sprintf( line, "### Module positions - created on %s ###\n", TO_UTF8( DateAndTime() ) ); sprintf( line, "### Module positions - created on %s ###\n", TO_UTF8( DateAndTime() ) );
...@@ -251,11 +249,11 @@ void PCB_EDIT_FRAME::GenModulesPosition( wxCommandEvent& event ) ...@@ -251,11 +249,11 @@ void PCB_EDIT_FRAME::GenModulesPosition( wxCommandEvent& event )
for( int ii = 0; ii < moduleCount; ii++ ) for( int ii = 0; ii < moduleCount; ii++ )
{ {
wxPoint module_pos; wxPoint module_pos;
wxString ref = Liste[ii].m_Reference; wxString ref = list[ii].m_Reference;
wxString val = Liste[ii].m_Value; wxString val = list[ii].m_Value;
sprintf( line, "%-8.8s %-16.16s ", TO_UTF8( ref ), TO_UTF8( val ) ); sprintf( line, "%-8.8s %-16.16s ", TO_UTF8( ref ), TO_UTF8( val ) );
module_pos = Liste[ii].m_Module->m_Pos; module_pos = list[ii].m_Module->m_Pos;
module_pos.x -= File_Place_Offset.x; module_pos.x -= File_Place_Offset.x;
module_pos.y -= File_Place_Offset.y; module_pos.y -= File_Place_Offset.y;
...@@ -263,9 +261,9 @@ void PCB_EDIT_FRAME::GenModulesPosition( wxCommandEvent& event ) ...@@ -263,9 +261,9 @@ void PCB_EDIT_FRAME::GenModulesPosition( wxCommandEvent& event )
sprintf( text, " %9.4f %9.4f %8.1f ", sprintf( text, " %9.4f %9.4f %8.1f ",
module_pos.x * conv_unit, module_pos.x * conv_unit,
module_pos.y * conv_unit, module_pos.y * conv_unit,
double(Liste[ii].m_Module->m_Orient) / 10 ); double(list[ii].m_Module->m_Orient) / 10 );
int layer = Liste[ii].m_Module->GetLayer(); int layer = list[ii].m_Module->GetLayer();
wxASSERT( layer==LAYER_N_FRONT || layer==LAYER_N_BACK ); wxASSERT( layer==LAYER_N_FRONT || layer==LAYER_N_BACK );
...@@ -303,8 +301,8 @@ void PCB_EDIT_FRAME::GenModulesPosition( wxCommandEvent& event ) ...@@ -303,8 +301,8 @@ void PCB_EDIT_FRAME::GenModulesPosition( wxCommandEvent& event )
exit: // the only safe way out of here, no returns please. exit: // the only safe way out of here, no returns please.
if( Liste ) if( list )
MyFree( Liste ); delete[] list;
if( switchedLocale ) if( switchedLocale )
SetLocaleTo_Default( ); // revert to the current locale SetLocaleTo_Default( ); // revert to the current locale
......
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2009 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 1992-2011 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/** /**
* @file muonde.cpp * @file muonde.cpp
* @brief Microwave pcb layout code. * @brief Microwave pcb layout code.
...@@ -26,8 +51,8 @@ ...@@ -26,8 +51,8 @@
#define COEFF_COUNT 6 #define COEFF_COUNT 6
static double* PolyEdges;
static int PolyEdgesCount; static std::vector< double > PolyEdges;
static double ShapeScaleX, ShapeScaleY; static double ShapeScaleX, ShapeScaleY;
static wxSize ShapeSize; static wxSize ShapeSize;
static int PolyShapeType; static int PolyShapeType;
...@@ -148,40 +173,6 @@ void PCB_EDIT_FRAME::Begin_Self( wxDC* DC ) ...@@ -148,40 +173,6 @@ void PCB_EDIT_FRAME::Begin_Self( wxDC* DC )
} }
/* Create a self-shaped coil
* - Length Mself.lng
* - Extremities Mself.m_Start and Mself.m_End
*
* We must determine:
* Mself.nbrin = number of segments perpendicular to the direction
* (The coil nbrin will demicercles + 1 + 2 1 / 4 circle)
* Mself.lbrin = length of a strand
* Mself.radius = radius of rounded parts of the coil
* Mself.delta = segments extremities connection between him and the coil even
*
* The equations are
* Mself.m_Size.x = 2 * Mself.radius + Mself.lbrin
* Mself.m_Size.y * Mself.delta = 2 + 2 * Mself.nbrin * Mself.radius
* Mself.lng = 2 * Mself.delta / / connections to the coil
+ (Mself.nbrin-2) * Mself.lbrin / / length of the strands except 1st and last
+ (Mself.nbrin 1) * (PI * Mself.radius) / / length of rounded
* Mself.lbrin + / 2 - Melf.radius * 2) / / length of 1st and last bit
*
* The constraints are:
* Nbrin >= 2
* Mself.radius < Mself.m_Size.x
* Mself.m_Size.y = Mself.radius * 4 + 2 * Mself.raccord
* Mself.lbrin> Mself.radius * 2
*
* The calculation is conducted in the following way:
* Initially:
* Nbrin = 2
* Radius = 4 * m_Size.x (arbitrarily fixed value)
* Then:
* Increasing the number of segments to the desired length
* (Radius decreases if necessary)
*
*/
MODULE* PCB_EDIT_FRAME::Genere_Self( wxDC* DC ) MODULE* PCB_EDIT_FRAME::Genere_Self( wxDC* DC )
{ {
D_PAD* PtPad; D_PAD* PtPad;
...@@ -210,7 +201,7 @@ MODULE* PCB_EDIT_FRAME::Genere_Self( wxDC* DC ) ...@@ -210,7 +201,7 @@ MODULE* PCB_EDIT_FRAME::Genere_Self( wxDC* DC )
wxTextEntryDialog dlg( this, _( "Length:" ), _( "Length" ), msg ); wxTextEntryDialog dlg( this, _( "Length:" ), _( "Length" ), msg );
if( dlg.ShowModal() != wxID_OK ) if( dlg.ShowModal() != wxID_OK )
return NULL; // cancelled by user return NULL; // canceled by user
msg = dlg.GetValue(); msg = dlg.GetValue();
Mself.lng = ReturnValueFromString( g_UserUnit, msg, GetScreen()->GetInternalUnits() ); Mself.lng = ReturnValueFromString( g_UserUnit, msg, GetScreen()->GetInternalUnits() );
...@@ -306,8 +297,9 @@ MODULE* PCB_EDIT_FRAME::Genere_Self( wxDC* DC ) ...@@ -306,8 +297,9 @@ MODULE* PCB_EDIT_FRAME::Genere_Self( wxDC* DC )
} }
/** gen_arc /**
* Generate an arc using arc approximation by lines: * Function gen_arc
* generates an arc using arc approximation by lines:
* Center aCenter * Center aCenter
* Angle "angle" (in 0.1 deg) * Angle "angle" (in 0.1 deg)
* @param aBuffer = a buffer to store points. * @param aBuffer = a buffer to store points.
...@@ -395,7 +387,7 @@ int BuildCornersList_S_Shape( std::vector <wxPoint>& aBuffer, ...@@ -395,7 +387,7 @@ int BuildCornersList_S_Shape( std::vector <wxPoint>& aBuffer,
// the arc to segment approximation. // the arc to segment approximation.
// because we use SEGM_COUNT_PER_360DEG segment to approximate a circle, // because we use SEGM_COUNT_PER_360DEG segment to approximate a circle,
// the trace len must be corrected when calculated using arcs // the trace len must be corrected when calculated using arcs
// this factor adjust calculations and must be canged if SEGM_COUNT_PER_360DEG is modified // this factor adjust calculations and must be changed if SEGM_COUNT_PER_360DEG is modified
// because trace using segment is shorter the corresponding arc // because trace using segment is shorter the corresponding arc
// ADJUST_SIZE is the ratio between tline len and the arc len for an arc // ADJUST_SIZE is the ratio between tline len and the arc len for an arc
// of 360/ADJUST_SIZE angle // of 360/ADJUST_SIZE angle
...@@ -528,10 +520,6 @@ int BuildCornersList_S_Shape( std::vector <wxPoint>& aBuffer, ...@@ -528,10 +520,6 @@ int BuildCornersList_S_Shape( std::vector <wxPoint>& aBuffer,
} }
/* Create a footprint with pad_count pads for micro wave applications
* This footprint has pad_count pads:
* PAD_SMD, rectangular, H size = V size = current track width.
*/
MODULE* PCB_EDIT_FRAME::Create_MuWaveBasicShape( const wxString& name, int pad_count ) MODULE* PCB_EDIT_FRAME::Create_MuWaveBasicShape( const wxString& name, int pad_count )
{ {
MODULE* Module; MODULE* Module;
...@@ -578,12 +566,6 @@ MODULE* PCB_EDIT_FRAME::Create_MuWaveBasicShape( const wxString& name, int pad_c ...@@ -578,12 +566,6 @@ MODULE* PCB_EDIT_FRAME::Create_MuWaveBasicShape( const wxString& name, int pad_c
} }
/* Create a module "GAP" or "STUB"
* This a "gap" or "stub" used in micro wave designs
* This module has 2 pads:
* PAD_SMD, rectangular, H size = V size = current track width.
* the "gap" is isolation created between this 2 pads
*/
MODULE* PCB_EDIT_FRAME::Create_MuWaveComponent( int shape_type ) MODULE* PCB_EDIT_FRAME::Create_MuWaveComponent( int shape_type )
{ {
int oX; int oX;
...@@ -759,6 +741,23 @@ public: WinEDA_SetParamShapeFrame( PCB_EDIT_FRAME* parent, const wxPoint& pos ); ...@@ -759,6 +741,23 @@ public: WinEDA_SetParamShapeFrame( PCB_EDIT_FRAME* parent, const wxPoint& pos );
private: private:
void OnOkClick( wxCommandEvent& event ); void OnOkClick( wxCommandEvent& event );
void OnCancelClick( wxCommandEvent& event ); void OnCancelClick( wxCommandEvent& event );
/**
* Function ReadDataShapeDescr
* read a description shape file
* File format is
* Unit=MM
* XScale=271.501
* YScale=1.00133
*
* $COORD
* 0 0.6112600148417837
* 0.001851851851851852 0.6104800531118608
* ....
* $ENDCOORD
*
* Each line is the X Y coord (normalized units from 0 to 1)
*/
void ReadDataShapeDescr( wxCommandEvent& event ); void ReadDataShapeDescr( wxCommandEvent& event );
void AcceptOptions( wxCommandEvent& event ); void AcceptOptions( wxCommandEvent& event );
...@@ -779,11 +778,7 @@ WinEDA_SetParamShapeFrame::WinEDA_SetParamShapeFrame( PCB_EDIT_FRAME* parent, ...@@ -779,11 +778,7 @@ WinEDA_SetParamShapeFrame::WinEDA_SetParamShapeFrame( PCB_EDIT_FRAME* parent,
{ {
m_Parent = parent; m_Parent = parent;
if( PolyEdges ) PolyEdges.clear();
free( PolyEdges );
PolyEdges = NULL;
PolyEdgesCount = 0;
wxBoxSizer* MainBoxSizer = new wxBoxSizer( wxHORIZONTAL ); wxBoxSizer* MainBoxSizer = new wxBoxSizer( wxHORIZONTAL );
SetSizer( MainBoxSizer ); SetSizer( MainBoxSizer );
...@@ -825,11 +820,7 @@ WinEDA_SetParamShapeFrame::WinEDA_SetParamShapeFrame( PCB_EDIT_FRAME* parent, ...@@ -825,11 +820,7 @@ WinEDA_SetParamShapeFrame::WinEDA_SetParamShapeFrame( PCB_EDIT_FRAME* parent,
void WinEDA_SetParamShapeFrame::OnCancelClick( wxCommandEvent& event ) void WinEDA_SetParamShapeFrame::OnCancelClick( wxCommandEvent& event )
{ {
if( PolyEdges ) PolyEdges.clear();
free( PolyEdges );
PolyEdges = NULL;
PolyEdgesCount = 0;
EndModal( -1 ); EndModal( -1 );
} }
...@@ -842,20 +833,6 @@ void WinEDA_SetParamShapeFrame::OnOkClick( wxCommandEvent& event ) ...@@ -842,20 +833,6 @@ void WinEDA_SetParamShapeFrame::OnOkClick( wxCommandEvent& event )
} }
/* Read a description shape file
* File format is
* Unit=MM
* XScale=271.501
* YScale=1.00133
*
* $COORD
* 0 0.6112600148417837
* 0.001851851851851852 0.6104800531118608
* ....
* $ENDCOORD
*
* Each line is the X Y coord (normalized units from 0 to 1)
*/
void WinEDA_SetParamShapeFrame::ReadDataShapeDescr( wxCommandEvent& event ) void WinEDA_SetParamShapeFrame::ReadDataShapeDescr( wxCommandEvent& event )
{ {
wxString FullFileName; wxString FullFileName;
...@@ -864,8 +841,6 @@ void WinEDA_SetParamShapeFrame::ReadDataShapeDescr( wxCommandEvent& event ) ...@@ -864,8 +841,6 @@ void WinEDA_SetParamShapeFrame::ReadDataShapeDescr( wxCommandEvent& event )
char* Line; char* Line;
double unitconv = 10000; double unitconv = 10000;
char* param1, * param2; char* param1, * param2;
int bufsize;
double* ptbuf;
ext = wxT( ".txt" ); ext = wxT( ".txt" );
mask = wxT( "*" ) + ext; mask = wxT( "*" ) + ext;
...@@ -892,9 +867,6 @@ void WinEDA_SetParamShapeFrame::ReadDataShapeDescr( wxCommandEvent& event ) ...@@ -892,9 +867,6 @@ void WinEDA_SetParamShapeFrame::ReadDataShapeDescr( wxCommandEvent& event )
FILTER_READER reader( fileReader ); FILTER_READER reader( fileReader );
bufsize = 100;
ptbuf = PolyEdges = (double*) MyZMalloc( bufsize * 2 * sizeof(double) );
SetLocaleTo_C_standard(); SetLocaleTo_C_standard();
while( reader.ReadLine() ) while( reader.ReadLine() )
...@@ -926,20 +898,8 @@ void WinEDA_SetParamShapeFrame::ReadDataShapeDescr( wxCommandEvent& event ) ...@@ -926,20 +898,8 @@ void WinEDA_SetParamShapeFrame::ReadDataShapeDescr( wxCommandEvent& event )
if( strnicmp( param1, "$ENDCOORD", 8 ) == 0 ) if( strnicmp( param1, "$ENDCOORD", 8 ) == 0 )
break; break;
if( bufsize <= PolyEdgesCount ) PolyEdges.push_back( atof( param1 ) );
{ PolyEdges.push_back( atof( param2 ) );
int index = ptbuf - PolyEdges;
bufsize *= 2;
ptbuf = PolyEdges = (double*) realloc( PolyEdges, bufsize * 2 *
sizeof(double) );
ptbuf += index;
}
*ptbuf = atof( param1 );
ptbuf++;
*ptbuf = atof( param2 );
ptbuf++;
PolyEdgesCount++;
} }
} }
...@@ -954,12 +914,6 @@ void WinEDA_SetParamShapeFrame::ReadDataShapeDescr( wxCommandEvent& event ) ...@@ -954,12 +914,6 @@ void WinEDA_SetParamShapeFrame::ReadDataShapeDescr( wxCommandEvent& event )
} }
} }
if( PolyEdgesCount == 0 )
{
free( PolyEdges );
PolyEdges = NULL;
}
SetLocaleTo_Default(); // revert to the current locale SetLocaleTo_Default(); // revert to the current locale
ShapeScaleX *= unitconv; ShapeScaleX *= unitconv;
...@@ -988,12 +942,7 @@ MODULE* PCB_EDIT_FRAME::Create_MuWavePolygonShape() ...@@ -988,12 +942,7 @@ MODULE* PCB_EDIT_FRAME::Create_MuWavePolygonShape()
if( ok != 1 ) if( ok != 1 )
{ {
if( PolyEdges ) PolyEdges.clear();
free( PolyEdges );
PolyEdges = NULL;
PolyEdgesCount = 0;
return NULL;
} }
if( PolyShapeType == 2 ) // mirrored if( PolyShapeType == 2 ) // mirrored
...@@ -1008,7 +957,7 @@ MODULE* PCB_EDIT_FRAME::Create_MuWavePolygonShape() ...@@ -1008,7 +957,7 @@ MODULE* PCB_EDIT_FRAME::Create_MuWavePolygonShape()
return NULL; return NULL;
} }
if( PolyEdgesCount == 0 ) if( PolyEdges.size() == 0 )
{ {
DisplayError( this, _( "Shape has no points!" ) ); DisplayError( this, _( "Shape has no points!" ) );
return NULL; return NULL;
...@@ -1032,21 +981,20 @@ MODULE* PCB_EDIT_FRAME::Create_MuWavePolygonShape() ...@@ -1032,21 +981,20 @@ MODULE* PCB_EDIT_FRAME::Create_MuWavePolygonShape()
edge->m_Shape = S_POLYGON; edge->m_Shape = S_POLYGON;
edge->SetLayer( LAYER_N_FRONT ); edge->SetLayer( LAYER_N_FRONT );
npoints = PolyEdgesCount; npoints = PolyEdges.size();
std::vector<wxPoint> polyPoints = edge->GetPolyPoints(); std::vector<wxPoint> polyPoints = edge->GetPolyPoints();
polyPoints.reserve( 2 * PolyEdgesCount + 2 ); polyPoints.reserve( 2 * PolyEdges.size() + 2 );
// Init start point coord: // Init start point coord:
polyPoints.push_back( wxPoint( pad1->m_Pos0.x, 0 ) ); polyPoints.push_back( wxPoint( pad1->m_Pos0.x, 0 ) );
double* dptr = PolyEdges;
wxPoint first_coordinate, last_coordinate; wxPoint first_coordinate, last_coordinate;
for( ii = 0; ii < npoints; ii++ ) // Copy points for( ii = 0; ii < PolyEdges.size(); ii++ ) // Copy points
{ {
last_coordinate.x = wxRound( *dptr++ *ShapeScaleX ) + pad1->m_Pos0.x; last_coordinate.x = wxRound( PolyEdges[ii] * ShapeScaleX ) + pad1->m_Pos0.x;
last_coordinate.y = -wxRound( *dptr++ *ShapeScaleY ); last_coordinate.y = -wxRound( PolyEdges[ii] * ShapeScaleY );
polyPoints.push_back( last_coordinate ); polyPoints.push_back( last_coordinate );
} }
...@@ -1083,10 +1031,7 @@ MODULE* PCB_EDIT_FRAME::Create_MuWavePolygonShape() ...@@ -1083,10 +1031,7 @@ MODULE* PCB_EDIT_FRAME::Create_MuWavePolygonShape()
break; break;
} }
free( PolyEdges ); PolyEdges.clear();
PolyEdgesCount = 0;
PolyEdges = NULL;
Module->CalculateBoundingBox(); Module->CalculateBoundingBox();
GetBoard()->m_Status_Pcb = 0; GetBoard()->m_Status_Pcb = 0;
OnModify(); OnModify();
...@@ -1094,10 +1039,6 @@ MODULE* PCB_EDIT_FRAME::Create_MuWavePolygonShape() ...@@ -1094,10 +1039,6 @@ MODULE* PCB_EDIT_FRAME::Create_MuWavePolygonShape()
} }
/*
* Edit the GAP module, if it has changed the position and/or size
* Pads that form the gap to get a new value of the gap.
*/
void PCB_EDIT_FRAME::Edit_Gap( wxDC* DC, MODULE* Module ) void PCB_EDIT_FRAME::Edit_Gap( wxDC* DC, MODULE* Module )
{ {
int gap_size, oX; int gap_size, oX;
......
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 1992-2011 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/** /**
* @file queue.cpp * @file queue.cpp
*/ */
...@@ -41,7 +66,8 @@ void FreeQueue() ...@@ -41,7 +66,8 @@ void FreeQueue()
while( (p = Save) != NULL ) while( (p = Save) != NULL )
{ {
Save = p->Next; MyFree( p ); Save = p->Next;
delete p;
} }
} }
...@@ -103,7 +129,7 @@ int SetQueue( int r, int c, int side, int d, int a, int r2, int c2 ) ...@@ -103,7 +129,7 @@ int SetQueue( int r, int c, int side, int d, int a, int r2, int c2 )
{ {
Save = p->Next; Save = p->Next;
} }
else if( ( p = (struct PcbQueue*) MyMalloc( sizeof(PcbQueue) ) ) == NULL ) else if( ( p = (PcbQueue*) operator new( sizeof( PcbQueue ), std::nothrow ) ) == NULL )
{ {
return 0; return 0;
} }
......
...@@ -871,25 +871,21 @@ void PCB_BASE_FRAME::BuildAirWiresTargetsList( BOARD_CONNECTED_ITEM* aItemRef, ...@@ -871,25 +871,21 @@ void PCB_BASE_FRAME::BuildAirWiresTargetsList( BOARD_CONNECTED_ITEM* aItemRef,
} }
/* Function TraceAirWiresToTargets void PCB_BASE_FRAME::TraceAirWiresToTargets( wxDC* aDC )
* This functions shows airwires to nearest connecting points (pads)
* from the current new track end during track creation
*/
void PCB_BASE_FRAME::TraceAirWiresToTargets( wxDC* DC )
{ {
if( DC == NULL ) if( aDC == NULL )
return; return;
if( s_TargetsLocations.size() == 0 ) if( s_TargetsLocations.size() == 0 )
return; return;
GRSetDrawMode( DC, GR_XOR ); GRSetDrawMode( aDC, GR_XOR );
for( int ii = 0; ii < (int) s_TargetsLocations.size(); ii++ ) for( int ii = 0; ii < (int) s_TargetsLocations.size(); ii++ )
{ {
if( ii >= g_MaxLinksShowed ) if( ii >= g_MaxLinksShowed )
break; break;
GRLine( &DrawPanel->m_ClipBox, DC, s_CursorPos, s_TargetsLocations[ii], 0, YELLOW ); GRLine( &DrawPanel->m_ClipBox, aDC, s_CursorPos, s_TargetsLocations[ii], 0, YELLOW );
} }
} }
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 1992-2011 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/** /**
* @file work.cpp * @file work.cpp
* @brief Automatic routing routines * @brief Automatic routing routines
...@@ -47,7 +72,7 @@ void InitWork() ...@@ -47,7 +72,7 @@ void InitWork()
while( ( ptr = Head ) != NULL ) while( ( ptr = Head ) != NULL )
{ {
Head = ptr->Next; Head = ptr->Next;
MyFree( ptr ); delete ptr;
} }
Tail = Current = NULL; Tail = Current = NULL;
...@@ -78,7 +103,7 @@ int SetWork( int r1, ...@@ -78,7 +103,7 @@ int SetWork( int r1,
{ {
CWORK* p; CWORK* p;
if( ( p = (CWORK*) MyMalloc( sizeof(CWORK) ) ) != NULL ) if( ( p = (CWORK*) operator new( sizeof(CWORK), std::nothrow ) ) != NULL )
{ {
p->FromRow = r1; p->FromRow = r1;
p->FromCol = c1; p->FromCol = c1;
...@@ -153,7 +178,9 @@ void SortWork() ...@@ -153,7 +178,9 @@ void SortWork()
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 */
{ {
while( r->Next ) /* search for end */ while( r->Next ) /* search for end */
......
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