2011-11-10 15:55:05 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2012-06-08 09:56:42 +00:00
|
|
|
* Copyright (C) 2012 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.fr
|
|
|
|
* Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
|
|
|
|
* Copyright (C) 2012 Wayne Stambaugh <stambaughw@verizon.net>
|
|
|
|
* Copyright (C) 1992-2012 KiCad Developers, see AUTHORS.txt for contributors.
|
2011-11-10 15:55:05 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2011-09-23 13:57:12 +00:00
|
|
|
/**
|
|
|
|
* @file muonde.cpp
|
|
|
|
* @brief Microwave pcb layout code.
|
|
|
|
*/
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <class_drawpanel.h>
|
|
|
|
#include <confirm.h>
|
|
|
|
#include <trigo.h>
|
|
|
|
#include <kicad_string.h>
|
|
|
|
#include <gestfich.h>
|
|
|
|
#include <wxPcbStruct.h>
|
|
|
|
#include <dialog_helpers.h>
|
|
|
|
#include <richio.h>
|
|
|
|
#include <filter_reader.h>
|
|
|
|
#include <gr_basic.h>
|
|
|
|
#include <pcbcommon.h>
|
|
|
|
#include <macros.h>
|
2012-04-13 18:51:24 +00:00
|
|
|
#include <base_units.h>
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <class_board.h>
|
|
|
|
#include <class_module.h>
|
|
|
|
#include <class_edge_mod.h>
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <protos.h>
|
|
|
|
#include <pcbnew.h>
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2007-08-08 03:50:44 +00:00
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
#define COEFF_COUNT 6
|
2011-11-10 15:55:05 +00:00
|
|
|
|
|
|
|
static std::vector< double > PolyEdges;
|
2008-12-06 12:49:33 +00:00
|
|
|
static double ShapeScaleX, ShapeScaleY;
|
|
|
|
static wxSize ShapeSize;
|
|
|
|
static int PolyShapeType;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2009-02-26 00:37:04 +00:00
|
|
|
|
2011-01-21 19:30:59 +00:00
|
|
|
static void Exit_Self( EDA_DRAW_PANEL* Panel, wxDC* DC );
|
2010-07-17 11:14:57 +00:00
|
|
|
static void gen_arc( std::vector <wxPoint>& aBuffer,
|
|
|
|
wxPoint aStartPoint,
|
|
|
|
wxPoint aCenter,
|
|
|
|
int a_ArcAngle );
|
2011-02-03 19:27:28 +00:00
|
|
|
static void ShowBoundingBoxMicroWaveInductor( EDA_DRAW_PANEL* apanel,
|
|
|
|
wxDC* aDC,
|
|
|
|
const wxPoint& aPosition,
|
|
|
|
bool aErase );
|
2009-02-26 00:37:04 +00:00
|
|
|
|
|
|
|
|
2010-07-17 11:14:57 +00:00
|
|
|
int BuildCornersList_S_Shape( std::vector <wxPoint>& aBuffer,
|
|
|
|
wxPoint aStartPoint, wxPoint aEndPoint,
|
|
|
|
int aLength, int aWidth );
|
|
|
|
|
2009-11-18 12:52:19 +00:00
|
|
|
class SELFPCB
|
2009-02-26 00:37:04 +00:00
|
|
|
{
|
|
|
|
public:
|
2010-07-17 11:14:57 +00:00
|
|
|
int forme; // Shape: coil, spiral, etc ..
|
2009-02-26 00:37:04 +00:00
|
|
|
wxPoint m_Start;
|
2009-11-18 12:52:19 +00:00
|
|
|
wxPoint m_End;
|
2009-02-26 00:37:04 +00:00
|
|
|
wxSize m_Size;
|
2009-11-18 12:52:19 +00:00
|
|
|
int lng; // Trace length.
|
2010-07-17 11:14:57 +00:00
|
|
|
int m_Width; // Trace width.
|
2009-02-26 00:37:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static SELFPCB Mself;
|
|
|
|
static int Self_On;
|
|
|
|
|
|
|
|
|
2009-11-23 21:03:26 +00:00
|
|
|
/* This function shows on screen the bounding box of the inductor that will be
|
|
|
|
* created at the end of the build inductor process
|
|
|
|
*/
|
2011-02-03 19:27:28 +00:00
|
|
|
static void ShowBoundingBoxMicroWaveInductor( EDA_DRAW_PANEL* aPanel, wxDC* aDC,
|
|
|
|
const wxPoint& aPosition, bool aErase )
|
2009-02-26 00:37:04 +00:00
|
|
|
{
|
2010-07-17 11:14:57 +00:00
|
|
|
/* Calculate the orientation and size of the box containing the inductor:
|
|
|
|
* the box is a rectangle with height = lenght/2
|
|
|
|
* the shape is defined by a rectangle, nor necessary horizontal or vertical
|
2009-02-26 00:37:04 +00:00
|
|
|
*/
|
2011-02-03 19:27:28 +00:00
|
|
|
GRSetDrawMode( aDC, GR_XOR );
|
2009-11-18 12:52:19 +00:00
|
|
|
|
2010-07-17 11:14:57 +00:00
|
|
|
wxPoint poly[5];
|
|
|
|
wxPoint pt = Mself.m_End - Mself.m_Start;
|
// Dick Hollenbeck's KiROUND R&D
// This provides better project control over rounding to int from double
// than wxRound() did. This scheme provides better logging in Debug builds
// and it provides for compile time calculation of constants.
#include <stdio.h>
#include <assert.h>
#include <limits.h>
//-----<KiROUND KIT>------------------------------------------------------------
/**
* KiROUND
* rounds a floating point number to an int using
* "round halfway cases away from zero".
* In Debug build an assert fires if will not fit into an int.
*/
#if defined( DEBUG )
// DEBUG: a macro to capture line and file, then calls this inline
static inline int KiRound( double v, int line, const char* filename )
{
v = v < 0 ? v - 0.5 : v + 0.5;
if( v > INT_MAX + 0.5 )
{
printf( "%s: in file %s on line %d, val: %.16g too ' > 0 ' for int\n", __FUNCTION__, filename, line, v );
}
else if( v < INT_MIN - 0.5 )
{
printf( "%s: in file %s on line %d, val: %.16g too ' < 0 ' for int\n", __FUNCTION__, filename, line, v );
}
return int( v );
}
#define KiROUND( v ) KiRound( v, __LINE__, __FILE__ )
#else
// RELEASE: a macro so compile can pre-compute constants.
#define KiROUND( v ) int( (v) < 0 ? (v) - 0.5 : (v) + 0.5 )
#endif
//-----</KiROUND KIT>-----------------------------------------------------------
// Only a macro is compile time calculated, an inline function causes a static constructor
// in a situation like this.
// Therefore the Release build is best done with a MACRO not an inline function.
int Computed = KiROUND( 14.3 * 8 );
int main( int argc, char** argv )
{
for( double d = double(INT_MAX)-1; d < double(INT_MAX)+8; d += 2.0 )
{
int i = KiROUND( d );
printf( "t: %d %.16g\n", i, d );
}
return 0;
}
2012-04-19 06:55:45 +00:00
|
|
|
int angle = -KiROUND( atan2( (double) pt.y, (double) pt.x ) * 1800.0 / M_PI );
|
|
|
|
int len = KiROUND( sqrt( (double) pt.x * pt.x + (double) pt.y * pt.y ) );
|
2010-07-17 11:14:57 +00:00
|
|
|
|
|
|
|
// calculate corners
|
|
|
|
pt.x = 0; pt.y = len / 4;
|
|
|
|
RotatePoint( &pt, angle );
|
|
|
|
poly[0] = Mself.m_Start + pt;
|
|
|
|
poly[1] = Mself.m_End + pt;
|
|
|
|
pt.x = 0; pt.y = -len / 4;
|
|
|
|
RotatePoint( &pt, angle );
|
|
|
|
poly[2] = Mself.m_End + pt;
|
|
|
|
poly[3] = Mself.m_Start + pt;
|
|
|
|
poly[4] = poly[0];
|
|
|
|
|
2011-02-03 19:27:28 +00:00
|
|
|
if( aErase )
|
2009-02-26 00:37:04 +00:00
|
|
|
{
|
2011-12-29 20:11:42 +00:00
|
|
|
GRPoly( aPanel->GetClipBox(), aDC, 5, poly, false, 0, YELLOW, YELLOW );
|
2009-02-26 00:37:04 +00:00
|
|
|
}
|
|
|
|
|
2011-02-11 20:48:13 +00:00
|
|
|
Mself.m_End = aPanel->GetScreen()->GetCrossHairPosition();
|
2010-07-17 11:14:57 +00:00
|
|
|
pt = Mself.m_End - Mself.m_Start;
|
// Dick Hollenbeck's KiROUND R&D
// This provides better project control over rounding to int from double
// than wxRound() did. This scheme provides better logging in Debug builds
// and it provides for compile time calculation of constants.
#include <stdio.h>
#include <assert.h>
#include <limits.h>
//-----<KiROUND KIT>------------------------------------------------------------
/**
* KiROUND
* rounds a floating point number to an int using
* "round halfway cases away from zero".
* In Debug build an assert fires if will not fit into an int.
*/
#if defined( DEBUG )
// DEBUG: a macro to capture line and file, then calls this inline
static inline int KiRound( double v, int line, const char* filename )
{
v = v < 0 ? v - 0.5 : v + 0.5;
if( v > INT_MAX + 0.5 )
{
printf( "%s: in file %s on line %d, val: %.16g too ' > 0 ' for int\n", __FUNCTION__, filename, line, v );
}
else if( v < INT_MIN - 0.5 )
{
printf( "%s: in file %s on line %d, val: %.16g too ' < 0 ' for int\n", __FUNCTION__, filename, line, v );
}
return int( v );
}
#define KiROUND( v ) KiRound( v, __LINE__, __FILE__ )
#else
// RELEASE: a macro so compile can pre-compute constants.
#define KiROUND( v ) int( (v) < 0 ? (v) - 0.5 : (v) + 0.5 )
#endif
//-----</KiROUND KIT>-----------------------------------------------------------
// Only a macro is compile time calculated, an inline function causes a static constructor
// in a situation like this.
// Therefore the Release build is best done with a MACRO not an inline function.
int Computed = KiROUND( 14.3 * 8 );
int main( int argc, char** argv )
{
for( double d = double(INT_MAX)-1; d < double(INT_MAX)+8; d += 2.0 )
{
int i = KiROUND( d );
printf( "t: %d %.16g\n", i, d );
}
return 0;
}
2012-04-19 06:55:45 +00:00
|
|
|
angle = -KiROUND( atan2( (double) pt.y, (double) pt.x ) * 1800.0 / M_PI );
|
|
|
|
len = KiROUND( sqrt( (double) pt.x * pt.x + (double) pt.y * pt.y ) );
|
2009-02-26 00:37:04 +00:00
|
|
|
|
2010-07-17 11:14:57 +00:00
|
|
|
// calculate new corners
|
|
|
|
pt.x = 0; pt.y = len / 4;
|
|
|
|
RotatePoint( &pt, angle );
|
|
|
|
poly[0] = Mself.m_Start + pt;
|
|
|
|
poly[1] = Mself.m_End + pt;
|
|
|
|
pt.x = 0; pt.y = -len / 4;
|
|
|
|
RotatePoint( &pt, angle );
|
|
|
|
poly[2] = Mself.m_End + pt;
|
|
|
|
poly[3] = Mself.m_Start + pt;
|
|
|
|
poly[4] = poly[0];
|
2009-02-26 00:37:04 +00:00
|
|
|
|
2011-12-29 20:11:42 +00:00
|
|
|
GRPoly( aPanel->GetClipBox(), aDC, 5, poly, false, 0, YELLOW, YELLOW );
|
2009-02-26 00:37:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-21 19:30:59 +00:00
|
|
|
void Exit_Self( EDA_DRAW_PANEL* Panel, wxDC* DC )
|
2009-02-26 00:37:04 +00:00
|
|
|
{
|
|
|
|
if( Self_On )
|
|
|
|
{
|
|
|
|
Self_On = 0;
|
2011-12-29 20:11:42 +00:00
|
|
|
Panel->CallMouseCapture( DC, wxDefaultPosition, 0 );
|
2009-02-26 00:37:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-01 19:26:17 +00:00
|
|
|
void PCB_EDIT_FRAME::Begin_Self( wxDC* DC )
|
2009-02-26 00:37:04 +00:00
|
|
|
{
|
|
|
|
if( Self_On )
|
|
|
|
{
|
|
|
|
Genere_Self( DC );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-02-11 20:48:13 +00:00
|
|
|
Mself.m_Start = GetScreen()->GetCrossHairPosition();
|
2010-07-17 11:14:57 +00:00
|
|
|
Mself.m_End = Mself.m_Start;
|
2009-02-26 00:37:04 +00:00
|
|
|
|
|
|
|
Self_On = 1;
|
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
// Update the initial coordinates.
|
2011-02-11 20:48:13 +00:00
|
|
|
GetScreen()->m_O_Curseur = GetScreen()->GetCrossHairPosition();
|
2009-04-05 20:49:15 +00:00
|
|
|
UpdateStatusBar();
|
2009-02-26 00:37:04 +00:00
|
|
|
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->SetMouseCapture( ShowBoundingBoxMicroWaveInductor, Exit_Self );
|
2011-12-29 20:11:42 +00:00
|
|
|
m_canvas->CallMouseCapture( DC, wxDefaultPosition, false );
|
2009-02-26 00:37:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-01 19:26:17 +00:00
|
|
|
MODULE* PCB_EDIT_FRAME::Genere_Self( wxDC* DC )
|
2009-02-26 00:37:04 +00:00
|
|
|
{
|
2012-02-19 04:02:19 +00:00
|
|
|
D_PAD* pad;
|
2010-07-17 11:14:57 +00:00
|
|
|
int ll;
|
|
|
|
wxString msg;
|
2009-02-26 00:37:04 +00:00
|
|
|
|
2011-12-29 20:11:42 +00:00
|
|
|
m_canvas->CallMouseCapture( DC, wxDefaultPosition, false );
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->SetMouseCapture( NULL, NULL );
|
2009-02-26 00:37:04 +00:00
|
|
|
|
|
|
|
if( Self_On == 0 )
|
|
|
|
{
|
|
|
|
DisplayError( this, wxT( "Starting point not init.." ) );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
Self_On = 0;
|
|
|
|
|
2011-02-11 20:48:13 +00:00
|
|
|
Mself.m_End = GetScreen()->GetCrossHairPosition();
|
2009-02-26 00:37:04 +00:00
|
|
|
|
2010-07-17 11:14:57 +00:00
|
|
|
wxPoint pt = Mself.m_End - Mself.m_Start;
|
// Dick Hollenbeck's KiROUND R&D
// This provides better project control over rounding to int from double
// than wxRound() did. This scheme provides better logging in Debug builds
// and it provides for compile time calculation of constants.
#include <stdio.h>
#include <assert.h>
#include <limits.h>
//-----<KiROUND KIT>------------------------------------------------------------
/**
* KiROUND
* rounds a floating point number to an int using
* "round halfway cases away from zero".
* In Debug build an assert fires if will not fit into an int.
*/
#if defined( DEBUG )
// DEBUG: a macro to capture line and file, then calls this inline
static inline int KiRound( double v, int line, const char* filename )
{
v = v < 0 ? v - 0.5 : v + 0.5;
if( v > INT_MAX + 0.5 )
{
printf( "%s: in file %s on line %d, val: %.16g too ' > 0 ' for int\n", __FUNCTION__, filename, line, v );
}
else if( v < INT_MIN - 0.5 )
{
printf( "%s: in file %s on line %d, val: %.16g too ' < 0 ' for int\n", __FUNCTION__, filename, line, v );
}
return int( v );
}
#define KiROUND( v ) KiRound( v, __LINE__, __FILE__ )
#else
// RELEASE: a macro so compile can pre-compute constants.
#define KiROUND( v ) int( (v) < 0 ? (v) - 0.5 : (v) + 0.5 )
#endif
//-----</KiROUND KIT>-----------------------------------------------------------
// Only a macro is compile time calculated, an inline function causes a static constructor
// in a situation like this.
// Therefore the Release build is best done with a MACRO not an inline function.
int Computed = KiROUND( 14.3 * 8 );
int main( int argc, char** argv )
{
for( double d = double(INT_MAX)-1; d < double(INT_MAX)+8; d += 2.0 )
{
int i = KiROUND( d );
printf( "t: %d %.16g\n", i, d );
}
return 0;
}
2012-04-19 06:55:45 +00:00
|
|
|
int min_len = KiROUND( sqrt( (double) pt.x * pt.x + (double) pt.y * pt.y ) );
|
2010-07-17 11:14:57 +00:00
|
|
|
Mself.lng = min_len;
|
2009-02-26 00:37:04 +00:00
|
|
|
|
2011-12-14 04:29:25 +00:00
|
|
|
// Enter the desired length.
|
2012-04-13 18:51:24 +00:00
|
|
|
msg = ReturnStringFromValue( g_UserUnit, Mself.lng );
|
2010-07-20 18:11:34 +00:00
|
|
|
wxTextEntryDialog dlg( this, _( "Length:" ), _( "Length" ), msg );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2010-07-20 18:11:34 +00:00
|
|
|
if( dlg.ShowModal() != wxID_OK )
|
2011-11-10 15:55:05 +00:00
|
|
|
return NULL; // canceled by user
|
2009-02-26 00:37:04 +00:00
|
|
|
|
2010-07-21 08:15:54 +00:00
|
|
|
msg = dlg.GetValue();
|
2012-04-16 17:39:32 +00:00
|
|
|
Mself.lng = ReturnValueFromString( g_UserUnit, msg );
|
2009-02-26 00:37:04 +00:00
|
|
|
|
2011-12-14 04:29:25 +00:00
|
|
|
// Control values (ii = minimum length)
|
2010-07-17 11:14:57 +00:00
|
|
|
if( Mself.lng < min_len )
|
2009-02-26 00:37:04 +00:00
|
|
|
{
|
|
|
|
DisplayError( this, _( "Requested length < minimum length" ) );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-12-14 04:29:25 +00:00
|
|
|
// Calculate the elements.
|
2010-07-17 11:14:57 +00:00
|
|
|
Mself.m_Width = GetBoard()->GetCurrentTrackWidth();
|
2009-02-26 00:37:04 +00:00
|
|
|
|
2010-07-17 11:14:57 +00:00
|
|
|
std::vector <wxPoint> buffer;
|
2011-09-07 19:41:04 +00:00
|
|
|
ll = BuildCornersList_S_Shape( buffer, Mself.m_Start, Mself.m_End, Mself.lng, Mself.m_Width );
|
|
|
|
|
2010-07-17 11:14:57 +00:00
|
|
|
if( !ll )
|
2009-02-26 00:37:04 +00:00
|
|
|
{
|
2010-07-17 11:14:57 +00:00
|
|
|
DisplayError( this, _( "Requested length too large" ) );
|
|
|
|
return NULL;
|
2009-02-26 00:37:04 +00:00
|
|
|
}
|
|
|
|
|
2011-12-14 04:29:25 +00:00
|
|
|
// Generate module.
|
|
|
|
MODULE* module;
|
|
|
|
module = Create_1_Module( wxEmptyString );
|
2010-07-17 11:14:57 +00:00
|
|
|
|
2011-12-14 04:29:25 +00:00
|
|
|
if( module == NULL )
|
2009-02-26 00:37:04 +00:00
|
|
|
return NULL;
|
|
|
|
|
2011-12-14 04:29:25 +00:00
|
|
|
// here the module is already in the BOARD, Create_1_Module() does that.
|
2013-03-13 18:53:58 +00:00
|
|
|
module->SetLibRef( wxT( "MuSelf" ) );
|
|
|
|
module->SetAttributes( MOD_VIRTUAL | MOD_CMS );
|
2011-12-21 13:42:02 +00:00
|
|
|
module->ClearFlags();
|
2013-03-13 18:53:58 +00:00
|
|
|
module->SetPosition( Mself.m_End );
|
2010-07-17 11:14:57 +00:00
|
|
|
|
2011-12-14 04:29:25 +00:00
|
|
|
// Generate segments
|
2010-07-17 11:14:57 +00:00
|
|
|
for( unsigned jj = 1; jj < buffer.size(); jj++ )
|
|
|
|
{
|
|
|
|
EDGE_MODULE* PtSegm;
|
2011-12-14 04:29:25 +00:00
|
|
|
PtSegm = new EDGE_MODULE( module );
|
|
|
|
PtSegm->SetStart( buffer[jj - 1] );
|
|
|
|
PtSegm->SetEnd( buffer[jj] );
|
|
|
|
PtSegm->SetWidth( Mself.m_Width );
|
|
|
|
PtSegm->SetLayer( module->GetLayer() );
|
|
|
|
PtSegm->SetShape( S_SEGMENT );
|
|
|
|
PtSegm->SetStart0( PtSegm->GetStart() - module->GetPosition() );
|
|
|
|
PtSegm->SetEnd0( PtSegm->GetEnd() - module->GetPosition() );
|
2013-03-18 19:36:07 +00:00
|
|
|
module->GraphicalItems().PushBack( PtSegm );
|
2009-02-26 00:37:04 +00:00
|
|
|
}
|
|
|
|
|
2011-12-14 04:29:25 +00:00
|
|
|
// Place a pad on each end of coil.
|
2012-02-19 04:02:19 +00:00
|
|
|
pad = new D_PAD( module );
|
|
|
|
|
2013-03-18 19:36:07 +00:00
|
|
|
module->Pads().PushFront( pad );
|
2012-02-19 04:02:19 +00:00
|
|
|
|
|
|
|
pad->SetPadName( wxT( "1" ) );
|
|
|
|
pad->SetPosition( Mself.m_End );
|
|
|
|
pad->SetPos0( pad->GetPosition() - module->GetPosition() );
|
2009-02-26 00:37:04 +00:00
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
pad->SetSize( wxSize( Mself.m_Width, Mself.m_Width ) );
|
2009-02-26 00:37:04 +00:00
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
pad->SetLayerMask( GetLayerMask( module->GetLayer() ) );
|
|
|
|
pad->SetAttribute( PAD_SMD );
|
|
|
|
pad->SetShape( PAD_CIRCLE );
|
2009-02-26 00:37:04 +00:00
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
D_PAD* newpad = new D_PAD( *pad );
|
2009-02-26 00:37:04 +00:00
|
|
|
|
2013-03-18 19:36:07 +00:00
|
|
|
module->Pads().Insert( newpad, pad->Next() );
|
2009-02-26 00:37:04 +00:00
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
pad = newpad;
|
|
|
|
pad->SetPadName( wxT( "2" ) );
|
|
|
|
pad->SetPosition( Mself.m_Start );
|
|
|
|
pad->SetPos0( pad->GetPosition() - module->GetPosition() );
|
2009-02-26 00:37:04 +00:00
|
|
|
|
2011-12-14 04:29:25 +00:00
|
|
|
// Modify text positions.
|
2013-01-12 17:32:24 +00:00
|
|
|
SetMsgPanel( module );
|
2009-02-26 00:37:04 +00:00
|
|
|
|
2013-03-18 19:36:07 +00:00
|
|
|
wxPoint refPos( ( Mself.m_Start.x + Mself.m_End.x ) / 2,
|
|
|
|
( Mself.m_Start.y + Mself.m_End.y ) / 2 );
|
|
|
|
|
|
|
|
wxPoint valPos = refPos;
|
|
|
|
|
|
|
|
refPos.y -= module->Reference().GetSize().y;
|
|
|
|
module->Reference().SetTextPosition( refPos );
|
|
|
|
valPos.y += module->Value().GetSize().y;
|
|
|
|
module->Value().SetTextPosition( valPos );
|
|
|
|
module->Reference().SetPos0( module->Reference().GetTextPosition() - module->GetPosition() );
|
|
|
|
module->Value().SetPos0( module->Value().GetTextPosition() - module->GetPosition() );
|
2009-02-26 00:37:04 +00:00
|
|
|
|
2011-12-14 04:29:25 +00:00
|
|
|
module->CalculateBoundingBox();
|
2011-12-22 13:28:11 +00:00
|
|
|
module->Draw( m_canvas, DC, GR_OR );
|
2009-02-26 00:37:04 +00:00
|
|
|
|
2011-12-14 04:29:25 +00:00
|
|
|
return module;
|
2009-02-26 00:37:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-11-10 15:55:05 +00:00
|
|
|
/**
|
|
|
|
* Function gen_arc
|
|
|
|
* generates an arc using arc approximation by lines:
|
2010-07-17 11:14:57 +00:00
|
|
|
* Center aCenter
|
|
|
|
* Angle "angle" (in 0.1 deg)
|
|
|
|
* @param aBuffer = a buffer to store points.
|
|
|
|
* @param aStartPoint = starting point of arc.
|
|
|
|
* @param aCenter = arc centre.
|
|
|
|
* @param a_ArcAngle = arc length in 0.1 degrees.
|
2009-02-26 00:37:04 +00:00
|
|
|
*/
|
2010-07-17 11:14:57 +00:00
|
|
|
static void gen_arc( std::vector <wxPoint>& aBuffer,
|
|
|
|
wxPoint aStartPoint,
|
|
|
|
wxPoint aCenter,
|
|
|
|
int a_ArcAngle )
|
2009-02-26 00:37:04 +00:00
|
|
|
{
|
2010-07-17 11:14:57 +00:00
|
|
|
#define SEGM_COUNT_PER_360DEG 16
|
|
|
|
wxPoint first_point = aStartPoint - aCenter;
|
2010-07-21 08:15:54 +00:00
|
|
|
int seg_count = ( ( abs( a_ArcAngle ) ) * SEGM_COUNT_PER_360DEG ) / 3600;
|
2010-07-17 11:14:57 +00:00
|
|
|
|
|
|
|
if( seg_count == 0 )
|
|
|
|
seg_count = 1;
|
|
|
|
|
2012-10-17 20:59:05 +00:00
|
|
|
double increment_angle = (double) a_ArcAngle * M_PI / 1800 / seg_count;
|
2010-07-17 11:14:57 +00:00
|
|
|
|
|
|
|
// Creates nb_seg point to approximate arc by segments:
|
|
|
|
for( int ii = 1; ii <= seg_count; ii++ )
|
|
|
|
{
|
|
|
|
double rot_angle = increment_angle * ii;
|
|
|
|
double fcos = cos( rot_angle );
|
|
|
|
double fsin = sin( rot_angle );
|
|
|
|
wxPoint currpt;
|
|
|
|
|
|
|
|
// Rotate current point:
|
// Dick Hollenbeck's KiROUND R&D
// This provides better project control over rounding to int from double
// than wxRound() did. This scheme provides better logging in Debug builds
// and it provides for compile time calculation of constants.
#include <stdio.h>
#include <assert.h>
#include <limits.h>
//-----<KiROUND KIT>------------------------------------------------------------
/**
* KiROUND
* rounds a floating point number to an int using
* "round halfway cases away from zero".
* In Debug build an assert fires if will not fit into an int.
*/
#if defined( DEBUG )
// DEBUG: a macro to capture line and file, then calls this inline
static inline int KiRound( double v, int line, const char* filename )
{
v = v < 0 ? v - 0.5 : v + 0.5;
if( v > INT_MAX + 0.5 )
{
printf( "%s: in file %s on line %d, val: %.16g too ' > 0 ' for int\n", __FUNCTION__, filename, line, v );
}
else if( v < INT_MIN - 0.5 )
{
printf( "%s: in file %s on line %d, val: %.16g too ' < 0 ' for int\n", __FUNCTION__, filename, line, v );
}
return int( v );
}
#define KiROUND( v ) KiRound( v, __LINE__, __FILE__ )
#else
// RELEASE: a macro so compile can pre-compute constants.
#define KiROUND( v ) int( (v) < 0 ? (v) - 0.5 : (v) + 0.5 )
#endif
//-----</KiROUND KIT>-----------------------------------------------------------
// Only a macro is compile time calculated, an inline function causes a static constructor
// in a situation like this.
// Therefore the Release build is best done with a MACRO not an inline function.
int Computed = KiROUND( 14.3 * 8 );
int main( int argc, char** argv )
{
for( double d = double(INT_MAX)-1; d < double(INT_MAX)+8; d += 2.0 )
{
int i = KiROUND( d );
printf( "t: %d %.16g\n", i, d );
}
return 0;
}
2012-04-19 06:55:45 +00:00
|
|
|
currpt.x = KiROUND( ( first_point.x * fcos + first_point.y * fsin ) );
|
|
|
|
currpt.y = KiROUND( ( first_point.y * fcos - first_point.x * fsin ) );
|
2010-07-17 11:14:57 +00:00
|
|
|
|
|
|
|
wxPoint corner = aCenter + currpt;
|
|
|
|
aBuffer.push_back( corner );
|
|
|
|
}
|
|
|
|
}
|
2009-02-26 00:37:04 +00:00
|
|
|
|
|
|
|
|
2010-11-12 16:36:43 +00:00
|
|
|
/**
|
|
|
|
* Function BuildCornersList_S_Shape
|
2010-07-17 11:14:57 +00:00
|
|
|
* Create a path like a S-shaped coil
|
2010-12-28 11:24:42 +00:00
|
|
|
* @param aBuffer = a buffer where to store points (ends of segments)
|
|
|
|
* @param aStartPoint = starting point of the path
|
2010-07-17 11:14:57 +00:00
|
|
|
* @param aEndPoint = ending point of the path
|
|
|
|
* @param aLength = full lenght of the path
|
2010-12-28 11:24:42 +00:00
|
|
|
* @param aWidth = segment width
|
2010-07-17 11:14:57 +00:00
|
|
|
*/
|
|
|
|
int BuildCornersList_S_Shape( std::vector <wxPoint>& aBuffer,
|
|
|
|
wxPoint aStartPoint, wxPoint aEndPoint,
|
|
|
|
int aLength, int aWidth )
|
|
|
|
{
|
|
|
|
/* We must determine:
|
|
|
|
* segm_count = number of segments perpendicular to the direction
|
|
|
|
* segm_len = length of a strand
|
|
|
|
* radius = radius of rounded parts of the coil
|
|
|
|
* stubs_len = length of the 2 stubs( segments parallel to the direction)
|
|
|
|
* connecting the start point to the start point of the S shape
|
|
|
|
* and the ending point to the end point of the S shape
|
|
|
|
* The equations are (assuming the area size of the entire shape is Size:
|
|
|
|
* Size.x = 2 * radius + segm_len
|
|
|
|
* Size.y = (segm_count + 2 ) * 2 * radius + 2 * stubs_len
|
|
|
|
* Mself.lng = 2 * delta // connections to the coil
|
|
|
|
* + (segm_count-2) * segm_len // length of the strands except 1st and last
|
|
|
|
* + (segm_count) * (PI * radius) // length of rounded
|
|
|
|
* segm_len + / 2 - radius * 2) // length of 1st and last bit
|
|
|
|
*
|
|
|
|
* The constraints are:
|
|
|
|
* segm_count >= 2
|
|
|
|
* radius < m_Size.x
|
|
|
|
* Size.y = (radius * 4) + (2 * stubs_len)
|
|
|
|
* segm_len > radius * 2
|
|
|
|
*
|
|
|
|
* The calculation is conducted in the following way:
|
|
|
|
* first:
|
|
|
|
* segm_count = 2
|
|
|
|
* radius = 4 * Size.x (arbitrarily fixed value)
|
|
|
|
* Then:
|
|
|
|
* Increasing the number of segments to the desired length
|
|
|
|
* (radius decreases if necessary)
|
|
|
|
*/
|
2010-07-21 08:15:54 +00:00
|
|
|
wxSize size;
|
2010-07-17 11:14:57 +00:00
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
// This scale factor adjusts the arc length to handle
|
2010-07-17 11:14:57 +00:00
|
|
|
// the arc to segment approximation.
|
|
|
|
// because we use SEGM_COUNT_PER_360DEG segment to approximate a circle,
|
|
|
|
// the trace len must be corrected when calculated using arcs
|
2011-11-10 15:55:05 +00:00
|
|
|
// this factor adjust calculations and must be changed if SEGM_COUNT_PER_360DEG is modified
|
2010-07-17 11:14:57 +00:00
|
|
|
// because trace using segment is shorter the corresponding arc
|
|
|
|
// ADJUST_SIZE is the ratio between tline len and the arc len for an arc
|
|
|
|
// of 360/ADJUST_SIZE angle
|
|
|
|
#define ADJUST_SIZE 0.988
|
|
|
|
|
|
|
|
wxPoint pt = aEndPoint - aStartPoint;
|
// Dick Hollenbeck's KiROUND R&D
// This provides better project control over rounding to int from double
// than wxRound() did. This scheme provides better logging in Debug builds
// and it provides for compile time calculation of constants.
#include <stdio.h>
#include <assert.h>
#include <limits.h>
//-----<KiROUND KIT>------------------------------------------------------------
/**
* KiROUND
* rounds a floating point number to an int using
* "round halfway cases away from zero".
* In Debug build an assert fires if will not fit into an int.
*/
#if defined( DEBUG )
// DEBUG: a macro to capture line and file, then calls this inline
static inline int KiRound( double v, int line, const char* filename )
{
v = v < 0 ? v - 0.5 : v + 0.5;
if( v > INT_MAX + 0.5 )
{
printf( "%s: in file %s on line %d, val: %.16g too ' > 0 ' for int\n", __FUNCTION__, filename, line, v );
}
else if( v < INT_MIN - 0.5 )
{
printf( "%s: in file %s on line %d, val: %.16g too ' < 0 ' for int\n", __FUNCTION__, filename, line, v );
}
return int( v );
}
#define KiROUND( v ) KiRound( v, __LINE__, __FILE__ )
#else
// RELEASE: a macro so compile can pre-compute constants.
#define KiROUND( v ) int( (v) < 0 ? (v) - 0.5 : (v) + 0.5 )
#endif
//-----</KiROUND KIT>-----------------------------------------------------------
// Only a macro is compile time calculated, an inline function causes a static constructor
// in a situation like this.
// Therefore the Release build is best done with a MACRO not an inline function.
int Computed = KiROUND( 14.3 * 8 );
int main( int argc, char** argv )
{
for( double d = double(INT_MAX)-1; d < double(INT_MAX)+8; d += 2.0 )
{
int i = KiROUND( d );
printf( "t: %d %.16g\n", i, d );
}
return 0;
}
2012-04-19 06:55:45 +00:00
|
|
|
int angle = -KiROUND( atan2( (double) pt.y, (double) pt.x ) * 1800.0 / M_PI );
|
|
|
|
int min_len = KiROUND( sqrt( (double) pt.x * pt.x + (double) pt.y * pt.y ) );
|
2011-09-07 19:41:04 +00:00
|
|
|
int segm_len = 0; // length of segments
|
2010-07-17 11:14:57 +00:00
|
|
|
int full_len; // full len of shape (sum of lenght of all segments + arcs)
|
|
|
|
|
|
|
|
|
|
|
|
/* Note: calculations are made for a vertical coil (more easy calculations)
|
|
|
|
* and after points are rotated to their actual position
|
|
|
|
* So the main direction is the Y axis.
|
|
|
|
* the 2 stubs are on the Y axis
|
|
|
|
* the others segments are parallel to the X axis.
|
|
|
|
*/
|
2009-11-18 12:52:19 +00:00
|
|
|
|
2010-07-17 11:14:57 +00:00
|
|
|
// Calculate the size of area (for a vertical shape)
|
|
|
|
size.x = min_len / 2;
|
|
|
|
size.y = min_len;
|
2009-02-26 00:37:04 +00:00
|
|
|
|
2010-07-17 11:14:57 +00:00
|
|
|
// Choose a reasonable starting value for the radius of the arcs.
|
2012-09-22 11:19:37 +00:00
|
|
|
int radius = std::min( aWidth * 5, size.x / 4 );
|
2009-02-26 00:37:04 +00:00
|
|
|
|
2010-07-17 11:14:57 +00:00
|
|
|
int segm_count; // number of full len segments
|
|
|
|
// the half size segments (first and last segment) are not counted here
|
|
|
|
int stubs_len = 0; // lenght of first or last segment (half size of others segments)
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2010-07-17 11:14:57 +00:00
|
|
|
for( segm_count = 0; ; segm_count++ )
|
2009-02-26 00:37:04 +00:00
|
|
|
{
|
2010-07-17 11:14:57 +00:00
|
|
|
stubs_len = ( size.y - ( radius * 2 * (segm_count + 2 ) ) ) / 2;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2010-07-17 11:14:57 +00:00
|
|
|
if( stubs_len < size.y / 10 ) // Reduce radius.
|
2009-02-26 00:37:04 +00:00
|
|
|
{
|
2010-07-17 11:14:57 +00:00
|
|
|
stubs_len = size.y / 10;
|
|
|
|
radius = ( size.y - (2 * stubs_len) ) / ( 2 * (segm_count + 2) );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2010-07-17 11:14:57 +00:00
|
|
|
if( radius < aWidth ) // Radius too small.
|
|
|
|
{
|
|
|
|
// Unable to create line: Requested length value is too large for room
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2010-07-17 11:14:57 +00:00
|
|
|
segm_len = size.x - ( radius * 2 );
|
2011-09-07 19:41:04 +00:00
|
|
|
full_len = 2 * stubs_len; // Length of coil connections.
|
|
|
|
full_len += segm_len * segm_count; // Length of full length segments.
|
// Dick Hollenbeck's KiROUND R&D
// This provides better project control over rounding to int from double
// than wxRound() did. This scheme provides better logging in Debug builds
// and it provides for compile time calculation of constants.
#include <stdio.h>
#include <assert.h>
#include <limits.h>
//-----<KiROUND KIT>------------------------------------------------------------
/**
* KiROUND
* rounds a floating point number to an int using
* "round halfway cases away from zero".
* In Debug build an assert fires if will not fit into an int.
*/
#if defined( DEBUG )
// DEBUG: a macro to capture line and file, then calls this inline
static inline int KiRound( double v, int line, const char* filename )
{
v = v < 0 ? v - 0.5 : v + 0.5;
if( v > INT_MAX + 0.5 )
{
printf( "%s: in file %s on line %d, val: %.16g too ' > 0 ' for int\n", __FUNCTION__, filename, line, v );
}
else if( v < INT_MIN - 0.5 )
{
printf( "%s: in file %s on line %d, val: %.16g too ' < 0 ' for int\n", __FUNCTION__, filename, line, v );
}
return int( v );
}
#define KiROUND( v ) KiRound( v, __LINE__, __FILE__ )
#else
// RELEASE: a macro so compile can pre-compute constants.
#define KiROUND( v ) int( (v) < 0 ? (v) - 0.5 : (v) + 0.5 )
#endif
//-----</KiROUND KIT>-----------------------------------------------------------
// Only a macro is compile time calculated, an inline function causes a static constructor
// in a situation like this.
// Therefore the Release build is best done with a MACRO not an inline function.
int Computed = KiROUND( 14.3 * 8 );
int main( int argc, char** argv )
{
for( double d = double(INT_MAX)-1; d < double(INT_MAX)+8; d += 2.0 )
{
int i = KiROUND( d );
printf( "t: %d %.16g\n", i, d );
}
return 0;
}
2012-04-19 06:55:45 +00:00
|
|
|
full_len += KiROUND( ( segm_count + 2 ) * M_PI * ADJUST_SIZE * radius ); // Ard arcs len
|
2011-09-07 19:41:04 +00:00
|
|
|
full_len += segm_len - (2 * radius); // Length of first and last segments
|
|
|
|
// (half size segments len = segm_len/2 - radius).
|
2010-07-17 11:14:57 +00:00
|
|
|
|
|
|
|
if( full_len >= aLength )
|
|
|
|
break;
|
|
|
|
}
|
2009-02-26 00:37:04 +00:00
|
|
|
|
2010-07-17 11:14:57 +00:00
|
|
|
// Adjust len by adjusting segm_len:
|
|
|
|
int delta_size = full_len - aLength;
|
2010-07-21 08:15:54 +00:00
|
|
|
|
2010-07-17 11:14:57 +00:00
|
|
|
// reduce len of the segm_count segments + 2 half size segments (= 1 full size segment)
|
2010-07-21 08:15:54 +00:00
|
|
|
segm_len -= delta_size / (segm_count + 1);
|
2009-02-26 00:37:04 +00:00
|
|
|
|
2010-07-17 11:14:57 +00:00
|
|
|
// Generate first line (the first stub) and first arc (90 deg arc)
|
|
|
|
pt = aStartPoint;
|
|
|
|
aBuffer.push_back( pt );
|
|
|
|
pt.y += stubs_len;
|
|
|
|
aBuffer.push_back( pt );
|
2009-02-26 00:37:04 +00:00
|
|
|
|
2010-07-17 11:14:57 +00:00
|
|
|
wxPoint centre = pt;
|
|
|
|
centre.x -= radius;
|
|
|
|
gen_arc( aBuffer, pt, centre, -900 );
|
|
|
|
pt = aBuffer.back();
|
2009-02-26 00:37:04 +00:00
|
|
|
|
2010-07-17 11:14:57 +00:00
|
|
|
int half_size_seg_len = segm_len / 2 - radius;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2010-07-17 11:14:57 +00:00
|
|
|
if( half_size_seg_len )
|
|
|
|
{
|
|
|
|
pt.x -= half_size_seg_len;
|
|
|
|
aBuffer.push_back( pt );
|
|
|
|
}
|
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
// Create shape.
|
2010-07-17 11:14:57 +00:00
|
|
|
int ii;
|
|
|
|
int sign = 1;
|
|
|
|
segm_count += 1; // increase segm_count to create the last half_size segment
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2010-07-17 11:14:57 +00:00
|
|
|
for( ii = 0; ii < segm_count; ii++ )
|
|
|
|
{
|
|
|
|
int arc_angle;
|
2009-02-26 00:37:04 +00:00
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
if( ii & 1 ) // odd order arcs are greater than 0
|
2010-07-17 11:14:57 +00:00
|
|
|
sign = -1;
|
|
|
|
else
|
|
|
|
sign = 1;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2010-07-17 11:14:57 +00:00
|
|
|
arc_angle = 1800 * sign;
|
|
|
|
centre = pt;
|
|
|
|
centre.y += radius;
|
|
|
|
gen_arc( aBuffer, pt, centre, arc_angle );
|
|
|
|
pt = aBuffer.back();
|
|
|
|
pt.x += segm_len * sign;
|
|
|
|
aBuffer.push_back( pt );
|
|
|
|
}
|
|
|
|
|
|
|
|
// The last point is false:
|
|
|
|
// it is the end of a full size segment, but must be
|
|
|
|
// the end of the second half_size segment. Change it.
|
|
|
|
sign *= -1;
|
|
|
|
aBuffer.back().x = aStartPoint.x + radius * sign;
|
2009-02-26 00:37:04 +00:00
|
|
|
|
2010-07-17 11:14:57 +00:00
|
|
|
// create last arc
|
|
|
|
pt = aBuffer.back();
|
|
|
|
centre = pt;
|
|
|
|
centre.y += radius;
|
|
|
|
gen_arc( aBuffer, pt, centre, 900 * sign ); pt = aBuffer.back();
|
2009-02-26 00:37:04 +00:00
|
|
|
|
2010-07-17 11:14:57 +00:00
|
|
|
// Rotate point
|
|
|
|
angle += 900;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2010-07-17 11:14:57 +00:00
|
|
|
for( unsigned jj = 0; jj < aBuffer.size(); jj++ )
|
|
|
|
{
|
2011-09-07 19:41:04 +00:00
|
|
|
RotatePoint( &aBuffer[jj].x, &aBuffer[jj].y, aStartPoint.x, aStartPoint.y, angle );
|
2009-02-26 00:37:04 +00:00
|
|
|
}
|
|
|
|
|
2010-07-17 11:14:57 +00:00
|
|
|
// push last point (end point)
|
|
|
|
aBuffer.push_back( aEndPoint );
|
|
|
|
|
|
|
|
return 1;
|
2009-02-26 00:37:04 +00:00
|
|
|
}
|
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2011-03-01 19:26:17 +00:00
|
|
|
MODULE* PCB_EDIT_FRAME::Create_MuWaveBasicShape( const wxString& name, int pad_count )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2011-12-14 04:29:25 +00:00
|
|
|
MODULE* module;
|
2007-08-08 03:50:44 +00:00
|
|
|
int pad_num = 1;
|
|
|
|
wxString Line;
|
|
|
|
|
2011-12-14 04:29:25 +00:00
|
|
|
module = Create_1_Module( name );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2011-12-14 04:29:25 +00:00
|
|
|
if( module == NULL )
|
2007-08-08 03:50:44 +00:00
|
|
|
return NULL;
|
|
|
|
|
2010-07-21 08:15:54 +00:00
|
|
|
#define DEFAULT_SIZE 30
|
2011-12-14 04:29:25 +00:00
|
|
|
module->SetTimeStamp( GetNewTimeStamp() );
|
2011-12-12 08:37:05 +00:00
|
|
|
|
2013-03-18 19:36:07 +00:00
|
|
|
module->Value().SetSize( wxSize( DEFAULT_SIZE, DEFAULT_SIZE ) );
|
2011-12-12 08:37:05 +00:00
|
|
|
|
2013-03-13 18:53:58 +00:00
|
|
|
module->Value().SetPos0( wxPoint( 0, -DEFAULT_SIZE ) );
|
2011-12-12 08:37:05 +00:00
|
|
|
|
2013-03-18 19:36:07 +00:00
|
|
|
module->Value().Offset( wxPoint( 0, module->Value().GetPos0().y ) );
|
2011-12-12 08:37:05 +00:00
|
|
|
|
2013-03-18 19:36:07 +00:00
|
|
|
module->Value().SetThickness( DEFAULT_SIZE / 4 );
|
2011-12-12 08:37:05 +00:00
|
|
|
|
2013-03-18 19:36:07 +00:00
|
|
|
module->Reference().SetSize( wxSize( DEFAULT_SIZE, DEFAULT_SIZE ) );
|
2011-12-12 08:37:05 +00:00
|
|
|
|
2013-03-13 18:53:58 +00:00
|
|
|
module->Reference().SetPos0( wxPoint( 0, DEFAULT_SIZE ) );
|
2011-12-12 08:37:05 +00:00
|
|
|
|
2013-03-18 19:36:07 +00:00
|
|
|
module->Reference().Offset( wxPoint( 0, module->Reference().GetPos0().y ) );
|
2011-12-12 08:37:05 +00:00
|
|
|
|
2013-03-18 19:36:07 +00:00
|
|
|
module->Reference().SetThickness( DEFAULT_SIZE / 4 );
|
2007-08-08 03:50:44 +00:00
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
// Create 2 pads used in gaps and stubs. The gap is between these 2 pads
|
|
|
|
// the stub is the pad 2
|
2007-08-08 03:50:44 +00:00
|
|
|
while( pad_count-- )
|
|
|
|
{
|
2011-12-14 04:29:25 +00:00
|
|
|
D_PAD* pad = new D_PAD( module );
|
2008-12-04 04:28:11 +00:00
|
|
|
|
2013-03-18 19:36:07 +00:00
|
|
|
module->Pads().PushFront( pad );
|
2008-12-04 04:28:11 +00:00
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
int tw = GetBoard()->GetCurrentTrackWidth();
|
|
|
|
pad->SetSize( wxSize( tw, tw ) );
|
|
|
|
|
|
|
|
pad->SetPosition( module->GetPosition() );
|
|
|
|
pad->SetShape( PAD_RECT );
|
|
|
|
pad->SetAttribute( PAD_SMD );
|
|
|
|
pad->SetLayerMask( LAYER_FRONT );
|
|
|
|
|
2007-08-08 03:50:44 +00:00
|
|
|
Line.Printf( wxT( "%d" ), pad_num );
|
|
|
|
pad->SetPadName( Line );
|
|
|
|
pad_num++;
|
|
|
|
}
|
2009-11-18 12:52:19 +00:00
|
|
|
|
2011-12-14 04:29:25 +00:00
|
|
|
return module;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-07 19:41:04 +00:00
|
|
|
MODULE* PCB_EDIT_FRAME::Create_MuWaveComponent( int shape_type )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2008-12-29 18:02:54 +00:00
|
|
|
int oX;
|
2008-12-06 12:49:33 +00:00
|
|
|
D_PAD* pad;
|
2011-12-14 04:29:25 +00:00
|
|
|
MODULE* module;
|
2007-08-08 03:50:44 +00:00
|
|
|
wxString msg, cmp_name;
|
|
|
|
int pad_count = 2;
|
2009-11-18 12:52:19 +00:00
|
|
|
int angle = 0;
|
2007-08-08 03:50:44 +00:00
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
// Enter the size of the gap or stub
|
2009-11-18 12:52:19 +00:00
|
|
|
int gap_size = GetBoard()->GetCurrentTrackWidth();
|
2007-08-08 03:50:44 +00:00
|
|
|
|
|
|
|
switch( shape_type )
|
|
|
|
{
|
|
|
|
case 0:
|
2009-11-18 12:52:19 +00:00
|
|
|
msg = _( "Gap" );
|
2007-08-08 03:50:44 +00:00
|
|
|
cmp_name = wxT( "GAP" );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
2009-11-18 12:52:19 +00:00
|
|
|
msg = _( "Stub" );
|
2007-08-08 03:50:44 +00:00
|
|
|
cmp_name = wxT( "STUB" );
|
|
|
|
pad_count = 2;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
2009-11-18 12:52:19 +00:00
|
|
|
msg = _( "Arc Stub" );
|
2007-08-08 03:50:44 +00:00
|
|
|
cmp_name = wxT( "ASTUB" );
|
|
|
|
pad_count = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
msg = wxT( "???" );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-04-13 18:51:24 +00:00
|
|
|
wxString value = ReturnStringFromValue( g_UserUnit, gap_size );
|
2010-07-21 08:15:54 +00:00
|
|
|
wxTextEntryDialog dlg( this, msg, _( "Create microwave module" ), value );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2010-07-20 18:11:34 +00:00
|
|
|
if( dlg.ShowModal() != wxID_OK )
|
2007-08-08 03:50:44 +00:00
|
|
|
{
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->MoveCursorToCrossHair();
|
2010-07-20 18:11:34 +00:00
|
|
|
return NULL; // cancelled by user
|
2007-08-08 03:50:44 +00:00
|
|
|
}
|
|
|
|
|
2010-07-21 08:15:54 +00:00
|
|
|
value = dlg.GetValue();
|
2012-04-16 17:39:32 +00:00
|
|
|
gap_size = ReturnValueFromString( g_UserUnit, value );
|
2007-08-08 03:50:44 +00:00
|
|
|
|
2010-07-20 18:11:34 +00:00
|
|
|
bool abort = false;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2010-07-20 18:11:34 +00:00
|
|
|
if( shape_type == 2 )
|
2007-08-08 03:50:44 +00:00
|
|
|
{
|
2010-07-21 08:15:54 +00:00
|
|
|
double fcoeff = 10.0, fval;
|
2010-07-20 18:11:34 +00:00
|
|
|
msg.Printf( wxT( "%3.1f" ), angle / fcoeff );
|
2011-09-07 19:41:04 +00:00
|
|
|
wxTextEntryDialog angledlg( this, _( "Angle (0.1deg):" ),
|
|
|
|
_( "Create microwave module" ), msg );
|
|
|
|
|
2010-07-21 08:15:54 +00:00
|
|
|
if( angledlg.ShowModal() != wxID_OK )
|
|
|
|
{
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->MoveCursorToCrossHair();
|
2010-07-21 08:15:54 +00:00
|
|
|
return NULL; // cancelled by user
|
|
|
|
}
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2010-07-21 08:15:54 +00:00
|
|
|
msg = angledlg.GetValue();
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2010-07-20 18:11:34 +00:00
|
|
|
if( !msg.ToDouble( &fval ) )
|
2007-08-08 03:50:44 +00:00
|
|
|
{
|
|
|
|
DisplayError( this, _( "Incorrect number, abort" ) );
|
2011-09-07 19:41:04 +00:00
|
|
|
abort = true;
|
2007-08-08 03:50:44 +00:00
|
|
|
}
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2012-09-22 11:19:37 +00:00
|
|
|
angle = std::abs( KiROUND( fval * fcoeff ) );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2007-08-08 03:50:44 +00:00
|
|
|
if( angle > 1800 )
|
|
|
|
angle = 1800;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( abort )
|
|
|
|
{
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->MoveCursorToCrossHair();
|
2007-08-08 03:50:44 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-12-14 04:29:25 +00:00
|
|
|
module = Create_MuWaveBasicShape( cmp_name, pad_count );
|
2013-03-18 19:36:07 +00:00
|
|
|
pad = module->Pads();
|
2007-08-08 03:50:44 +00:00
|
|
|
|
|
|
|
switch( shape_type )
|
|
|
|
{
|
|
|
|
case 0: //Gap :
|
2012-02-19 04:02:19 +00:00
|
|
|
oX = -( gap_size + pad->GetSize().x ) / 2;
|
|
|
|
pad->SetX0( oX );
|
|
|
|
|
|
|
|
pad->SetX( pad->GetPos0().x + pad->GetPosition().x );
|
|
|
|
|
2008-12-06 12:49:33 +00:00
|
|
|
pad = pad->Next();
|
2012-02-19 04:02:19 +00:00
|
|
|
|
|
|
|
pad->SetX0( oX + gap_size + pad->GetSize().x );
|
|
|
|
pad->SetX( pad->GetPos0().x + pad->GetPosition().x );
|
2007-08-08 03:50:44 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 1: //Stub :
|
2008-12-06 12:49:33 +00:00
|
|
|
pad->SetPadName( wxT( "1" ) );
|
|
|
|
pad = pad->Next();
|
2012-02-19 04:02:19 +00:00
|
|
|
pad->SetY0( -( gap_size + pad->GetSize().y ) / 2 );
|
|
|
|
pad->SetSize( wxSize( pad->GetSize().x, gap_size ) );
|
|
|
|
pad->SetY( pad->GetPos0().y + pad->GetPosition().y );
|
2007-08-08 03:50:44 +00:00
|
|
|
break;
|
|
|
|
|
2008-12-29 18:02:54 +00:00
|
|
|
case 2: // Arc Stub created by a polygonal approach:
|
2012-02-19 04:02:19 +00:00
|
|
|
{
|
|
|
|
EDGE_MODULE* edge = new EDGE_MODULE( module );
|
2013-03-18 19:36:07 +00:00
|
|
|
module->GraphicalItems().PushFront( edge );
|
2008-12-29 18:02:54 +00:00
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
edge->SetShape( S_POLYGON );
|
|
|
|
edge->SetLayer( LAYER_N_FRONT );
|
2008-12-29 18:02:54 +00:00
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
int numPoints = angle / 50 + 3; // Note: angles are in 0.1 degrees
|
|
|
|
std::vector<wxPoint> polyPoints = edge->GetPolyPoints();
|
|
|
|
polyPoints.reserve( numPoints );
|
2008-12-29 18:02:54 +00:00
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
edge->m_Start0.y = -pad->GetSize().y / 2;
|
2008-12-29 18:02:54 +00:00
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
polyPoints.push_back( wxPoint( 0, 0 ) );
|
2007-08-08 03:50:44 +00:00
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
int theta = -angle / 2;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
for( int ii = 1; ii<numPoints - 1; ii++ )
|
|
|
|
{
|
|
|
|
wxPoint pt( 0, -gap_size );
|
2008-12-29 18:02:54 +00:00
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
RotatePoint( &pt.x, &pt.y, theta );
|
2008-12-29 18:02:54 +00:00
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
polyPoints.push_back( pt );
|
2008-12-29 18:02:54 +00:00
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
theta += 50;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
if( theta > angle / 2 )
|
|
|
|
theta = angle / 2;
|
|
|
|
}
|
2009-11-18 12:52:19 +00:00
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
// Close the polygon:
|
|
|
|
polyPoints.push_back( polyPoints[0] );
|
|
|
|
}
|
|
|
|
break;
|
2007-08-08 03:50:44 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-12-14 04:29:25 +00:00
|
|
|
module->CalculateBoundingBox();
|
2009-01-05 05:21:35 +00:00
|
|
|
GetBoard()->m_Status_Pcb = 0;
|
2010-02-19 13:23:58 +00:00
|
|
|
OnModify();
|
2011-12-14 04:29:25 +00:00
|
|
|
return module;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**************** Polygon Shapes ***********************/
|
|
|
|
|
2007-08-08 03:50:44 +00:00
|
|
|
enum id_mw_cmd {
|
2007-10-07 03:08:24 +00:00
|
|
|
ID_READ_SHAPE_FILE = 1000
|
2007-05-06 16:03:28 +00:00
|
|
|
};
|
|
|
|
|
2007-08-08 03:50:44 +00:00
|
|
|
|
2009-11-18 12:52:19 +00:00
|
|
|
/* Setting polynomial form parameters
|
2007-08-08 03:50:44 +00:00
|
|
|
*/
|
2009-11-18 12:52:19 +00:00
|
|
|
class WinEDA_SetParamShapeFrame : public wxDialog
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
|
|
|
private:
|
2011-03-01 19:26:17 +00:00
|
|
|
PCB_EDIT_FRAME* m_Parent;
|
2007-08-08 03:50:44 +00:00
|
|
|
wxRadioBox* m_ShapeOptionCtrl;
|
2011-09-06 19:42:46 +00:00
|
|
|
EDA_SIZE_CTRL* m_SizeCtrl;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2011-03-01 19:26:17 +00:00
|
|
|
public: WinEDA_SetParamShapeFrame( PCB_EDIT_FRAME* parent, const wxPoint& pos );
|
2007-09-01 12:00:30 +00:00
|
|
|
~WinEDA_SetParamShapeFrame() { };
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2007-08-08 03:50:44 +00:00
|
|
|
private:
|
2009-11-18 12:52:19 +00:00
|
|
|
void OnOkClick( wxCommandEvent& event );
|
|
|
|
void OnCancelClick( wxCommandEvent& event );
|
2011-11-10 15:55:05 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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)
|
|
|
|
*/
|
2009-11-18 12:52:19 +00:00
|
|
|
void ReadDataShapeDescr( wxCommandEvent& event );
|
|
|
|
void AcceptOptions( wxCommandEvent& event );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2007-08-08 03:50:44 +00:00
|
|
|
DECLARE_EVENT_TABLE()
|
2007-05-06 16:03:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-11-18 12:52:19 +00:00
|
|
|
BEGIN_EVENT_TABLE( WinEDA_SetParamShapeFrame, wxDialog )
|
2011-09-06 19:42:46 +00:00
|
|
|
EVT_BUTTON( wxID_OK, WinEDA_SetParamShapeFrame::OnOkClick )
|
|
|
|
EVT_BUTTON( wxID_CANCEL, WinEDA_SetParamShapeFrame::OnCancelClick )
|
|
|
|
EVT_BUTTON( ID_READ_SHAPE_FILE, WinEDA_SetParamShapeFrame::ReadDataShapeDescr )
|
2009-11-18 12:52:19 +00:00
|
|
|
END_EVENT_TABLE()
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2011-09-06 19:42:46 +00:00
|
|
|
|
2011-03-01 19:26:17 +00:00
|
|
|
WinEDA_SetParamShapeFrame::WinEDA_SetParamShapeFrame( PCB_EDIT_FRAME* parent,
|
|
|
|
const wxPoint& framepos ) :
|
2011-09-07 19:41:04 +00:00
|
|
|
wxDialog( parent, -1, _( "Complex shape" ), framepos, wxSize( 350, 280 ), DIALOG_STYLE )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2007-08-08 03:50:44 +00:00
|
|
|
m_Parent = parent;
|
|
|
|
|
2011-11-10 15:55:05 +00:00
|
|
|
PolyEdges.clear();
|
2007-08-08 03:50:44 +00:00
|
|
|
|
|
|
|
wxBoxSizer* MainBoxSizer = new wxBoxSizer( wxHORIZONTAL );
|
|
|
|
SetSizer( MainBoxSizer );
|
|
|
|
wxBoxSizer* LeftBoxSizer = new wxBoxSizer( wxVERTICAL );
|
|
|
|
wxBoxSizer* RightBoxSizer = new wxBoxSizer( wxVERTICAL );
|
|
|
|
MainBoxSizer->Add( LeftBoxSizer, 0, wxGROW | wxALL, 5 );
|
|
|
|
MainBoxSizer->Add( RightBoxSizer, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
|
|
|
|
|
2007-10-07 03:08:24 +00:00
|
|
|
wxButton* Button = new wxButton( this, wxID_OK, _( "OK" ) );
|
2007-08-08 03:50:44 +00:00
|
|
|
RightBoxSizer->Add( Button, 0, wxGROW | wxALL, 5 );
|
|
|
|
|
2007-10-07 03:08:24 +00:00
|
|
|
Button = new wxButton( this, wxID_CANCEL, _( "Cancel" ) );
|
2007-08-08 03:50:44 +00:00
|
|
|
RightBoxSizer->Add( Button, 0, wxGROW | wxALL, 5 );
|
|
|
|
|
2011-09-07 19:41:04 +00:00
|
|
|
Button = new wxButton( this, ID_READ_SHAPE_FILE,
|
|
|
|
_( "Read Shape Description File..." ) );
|
2007-08-08 03:50:44 +00:00
|
|
|
RightBoxSizer->Add( Button, 0, wxGROW | wxALL, 5 );
|
|
|
|
|
2010-07-17 11:14:57 +00:00
|
|
|
wxString shapelist[3] =
|
|
|
|
{
|
|
|
|
_( "Normal" ), _( "Symmetrical" ),
|
|
|
|
_( "Mirrored" )
|
|
|
|
};
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2009-11-18 12:52:19 +00:00
|
|
|
m_ShapeOptionCtrl = new wxRadioBox( this, -1, _( "Shape Option" ),
|
|
|
|
wxDefaultPosition, wxDefaultSize, 3,
|
|
|
|
shapelist, 1,
|
2007-08-08 03:50:44 +00:00
|
|
|
wxRA_SPECIFY_COLS );
|
|
|
|
LeftBoxSizer->Add( m_ShapeOptionCtrl, 0, wxGROW | wxALL, 5 );
|
|
|
|
|
2012-04-16 17:39:32 +00:00
|
|
|
m_SizeCtrl = new EDA_SIZE_CTRL( this, _( "Size" ), ShapeSize, g_UserUnit, LeftBoxSizer );
|
2007-08-08 03:50:44 +00:00
|
|
|
|
|
|
|
GetSizer()->Fit( this );
|
|
|
|
GetSizer()->SetSizeHints( this );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-08-08 03:50:44 +00:00
|
|
|
|
2010-12-21 15:13:09 +00:00
|
|
|
void WinEDA_SetParamShapeFrame::OnCancelClick( wxCommandEvent& event )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2011-11-10 15:55:05 +00:00
|
|
|
PolyEdges.clear();
|
2007-10-07 03:08:24 +00:00
|
|
|
EndModal( -1 );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-07 03:08:24 +00:00
|
|
|
void WinEDA_SetParamShapeFrame::OnOkClick( wxCommandEvent& event )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2007-08-08 03:50:44 +00:00
|
|
|
ShapeSize = m_SizeCtrl->GetValue();
|
|
|
|
PolyShapeType = m_ShapeOptionCtrl->GetSelection();
|
|
|
|
EndModal( 1 );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-08-08 03:50:44 +00:00
|
|
|
|
2009-11-18 12:52:19 +00:00
|
|
|
void WinEDA_SetParamShapeFrame::ReadDataShapeDescr( wxCommandEvent& event )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2007-08-08 03:50:44 +00:00
|
|
|
wxString FullFileName;
|
|
|
|
wxString ext, mask;
|
|
|
|
FILE* File;
|
2011-01-14 17:43:30 +00:00
|
|
|
char* Line;
|
2007-08-08 03:50:44 +00:00
|
|
|
double unitconv = 10000;
|
|
|
|
char* param1, * param2;
|
|
|
|
|
|
|
|
ext = wxT( ".txt" );
|
|
|
|
mask = wxT( "*" ) + ext;
|
|
|
|
FullFileName = EDA_FileSelector( _( "Read descr shape file" ),
|
2009-11-18 12:52:19 +00:00
|
|
|
wxEmptyString,
|
|
|
|
FullFileName,
|
|
|
|
ext,
|
|
|
|
mask,
|
2007-08-08 03:50:44 +00:00
|
|
|
this,
|
|
|
|
wxFD_OPEN,
|
2011-09-07 19:41:04 +00:00
|
|
|
true );
|
2007-08-08 03:50:44 +00:00
|
|
|
if( FullFileName.IsEmpty() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
File = wxFopen( FullFileName, wxT( "rt" ) );
|
|
|
|
|
|
|
|
if( File == NULL )
|
|
|
|
{
|
|
|
|
DisplayError( this, _( "File not found" ) );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-01-14 17:43:30 +00:00
|
|
|
FILE_LINE_READER fileReader( File, FullFileName );
|
|
|
|
|
|
|
|
FILTER_READER reader( fileReader );
|
2007-08-08 03:50:44 +00:00
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
LOCALE_IO toggle;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2011-01-14 17:43:30 +00:00
|
|
|
while( reader.ReadLine() )
|
2007-08-08 03:50:44 +00:00
|
|
|
{
|
2011-01-14 17:43:30 +00:00
|
|
|
Line = reader.Line();
|
2007-08-08 03:50:44 +00:00
|
|
|
param1 = strtok( Line, " =\n\r" );
|
|
|
|
param2 = strtok( NULL, " \t\n\r" );
|
|
|
|
|
|
|
|
if( strnicmp( param1, "Unit", 4 ) == 0 )
|
|
|
|
{
|
|
|
|
if( strnicmp( param2, "inch", 4 ) == 0 )
|
|
|
|
unitconv = 10000;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2007-08-08 03:50:44 +00:00
|
|
|
if( strnicmp( param2, "mm", 2 ) == 0 )
|
|
|
|
unitconv = 10000 / 25.4;
|
|
|
|
}
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2007-08-08 03:50:44 +00:00
|
|
|
if( strnicmp( param1, "$ENDCOORD", 8 ) == 0 )
|
|
|
|
break;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2007-08-08 03:50:44 +00:00
|
|
|
if( strnicmp( param1, "$COORD", 6 ) == 0 )
|
|
|
|
{
|
2011-01-14 17:43:30 +00:00
|
|
|
while( reader.ReadLine() )
|
2007-08-08 03:50:44 +00:00
|
|
|
{
|
2011-01-14 17:43:30 +00:00
|
|
|
Line = reader.Line();
|
2007-08-08 03:50:44 +00:00
|
|
|
param1 = strtok( Line, " \t\n\r" );
|
|
|
|
param2 = strtok( NULL, " \t\n\r" );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2007-08-08 03:50:44 +00:00
|
|
|
if( strnicmp( param1, "$ENDCOORD", 8 ) == 0 )
|
|
|
|
break;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2011-11-10 15:55:05 +00:00
|
|
|
PolyEdges.push_back( atof( param1 ) );
|
|
|
|
PolyEdges.push_back( atof( param2 ) );
|
2007-08-08 03:50:44 +00:00
|
|
|
}
|
|
|
|
}
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2007-08-08 03:50:44 +00:00
|
|
|
if( strnicmp( Line, "XScale", 6 ) == 0 )
|
|
|
|
{
|
|
|
|
ShapeScaleX = atof( param2 );
|
|
|
|
}
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2007-08-08 03:50:44 +00:00
|
|
|
if( strnicmp( Line, "YScale", 6 ) == 0 )
|
|
|
|
{
|
|
|
|
ShapeScaleY = atof( param2 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ShapeScaleX *= unitconv;
|
|
|
|
ShapeScaleY *= unitconv;
|
|
|
|
|
|
|
|
m_SizeCtrl->SetValue( (int) ShapeScaleX, (int) ShapeScaleY );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-01 19:26:17 +00:00
|
|
|
MODULE* PCB_EDIT_FRAME::Create_MuWavePolygonShape()
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2007-08-08 03:50:44 +00:00
|
|
|
D_PAD* pad1, * pad2;
|
2011-12-14 04:29:25 +00:00
|
|
|
MODULE* module;
|
2007-08-08 03:50:44 +00:00
|
|
|
wxString cmp_name;
|
|
|
|
int pad_count = 2;
|
2008-12-29 18:02:54 +00:00
|
|
|
EDGE_MODULE* edge;
|
2007-08-08 03:50:44 +00:00
|
|
|
|
2011-09-07 19:41:04 +00:00
|
|
|
WinEDA_SetParamShapeFrame* frame = new WinEDA_SetParamShapeFrame( this, wxPoint( -1, -1 ) );
|
2008-12-29 18:02:54 +00:00
|
|
|
|
|
|
|
int ok = frame->ShowModal();
|
2009-11-18 12:52:19 +00:00
|
|
|
|
2008-12-29 18:02:54 +00:00
|
|
|
frame->Destroy();
|
2007-08-08 03:50:44 +00:00
|
|
|
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->MoveCursorToCrossHair();
|
2007-08-08 03:50:44 +00:00
|
|
|
|
|
|
|
if( ok != 1 )
|
|
|
|
{
|
2011-11-10 15:55:05 +00:00
|
|
|
PolyEdges.clear();
|
2007-08-08 03:50:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( PolyShapeType == 2 ) // mirrored
|
|
|
|
ShapeScaleY = -ShapeScaleY;
|
2008-12-29 18:02:54 +00:00
|
|
|
|
// Dick Hollenbeck's KiROUND R&D
// This provides better project control over rounding to int from double
// than wxRound() did. This scheme provides better logging in Debug builds
// and it provides for compile time calculation of constants.
#include <stdio.h>
#include <assert.h>
#include <limits.h>
//-----<KiROUND KIT>------------------------------------------------------------
/**
* KiROUND
* rounds a floating point number to an int using
* "round halfway cases away from zero".
* In Debug build an assert fires if will not fit into an int.
*/
#if defined( DEBUG )
// DEBUG: a macro to capture line and file, then calls this inline
static inline int KiRound( double v, int line, const char* filename )
{
v = v < 0 ? v - 0.5 : v + 0.5;
if( v > INT_MAX + 0.5 )
{
printf( "%s: in file %s on line %d, val: %.16g too ' > 0 ' for int\n", __FUNCTION__, filename, line, v );
}
else if( v < INT_MIN - 0.5 )
{
printf( "%s: in file %s on line %d, val: %.16g too ' < 0 ' for int\n", __FUNCTION__, filename, line, v );
}
return int( v );
}
#define KiROUND( v ) KiRound( v, __LINE__, __FILE__ )
#else
// RELEASE: a macro so compile can pre-compute constants.
#define KiROUND( v ) int( (v) < 0 ? (v) - 0.5 : (v) + 0.5 )
#endif
//-----</KiROUND KIT>-----------------------------------------------------------
// Only a macro is compile time calculated, an inline function causes a static constructor
// in a situation like this.
// Therefore the Release build is best done with a MACRO not an inline function.
int Computed = KiROUND( 14.3 * 8 );
int main( int argc, char** argv )
{
for( double d = double(INT_MAX)-1; d < double(INT_MAX)+8; d += 2.0 )
{
int i = KiROUND( d );
printf( "t: %d %.16g\n", i, d );
}
return 0;
}
2012-04-19 06:55:45 +00:00
|
|
|
ShapeSize.x = KiROUND( ShapeScaleX );
|
|
|
|
ShapeSize.y = KiROUND( ShapeScaleY );
|
2007-08-08 03:50:44 +00:00
|
|
|
|
2009-11-18 12:52:19 +00:00
|
|
|
if( ( ShapeSize.x ) == 0 || ( ShapeSize.y == 0 ) )
|
2007-08-08 03:50:44 +00:00
|
|
|
{
|
|
|
|
DisplayError( this, _( "Shape has a null size!" ) );
|
|
|
|
return NULL;
|
|
|
|
}
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2011-11-10 15:55:05 +00:00
|
|
|
if( PolyEdges.size() == 0 )
|
2007-08-08 03:50:44 +00:00
|
|
|
{
|
|
|
|
DisplayError( this, _( "Shape has no points!" ) );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
cmp_name = wxT( "POLY" );
|
|
|
|
|
2011-12-14 04:29:25 +00:00
|
|
|
module = Create_MuWaveBasicShape( cmp_name, pad_count );
|
2013-03-18 19:36:07 +00:00
|
|
|
pad1 = module->Pads();
|
2007-08-08 03:50:44 +00:00
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
pad1->SetX0( -ShapeSize.x / 2 );
|
|
|
|
pad1->SetX( pad1->GetPos0().x + pad1->GetPosition().x );
|
2007-08-08 03:50:44 +00:00
|
|
|
|
2008-11-24 06:53:43 +00:00
|
|
|
pad2 = (D_PAD*) pad1->Next();
|
2012-02-19 04:02:19 +00:00
|
|
|
pad2->SetX0( pad1->GetPos0().x + ShapeSize.x );
|
|
|
|
pad2->SetX( pad2->GetPos0().x + pad2->GetPosition().x );
|
2007-08-08 03:50:44 +00:00
|
|
|
|
2011-12-14 04:29:25 +00:00
|
|
|
edge = new EDGE_MODULE( module );
|
2008-12-04 04:28:11 +00:00
|
|
|
|
2013-03-18 19:36:07 +00:00
|
|
|
module->GraphicalItems().PushFront( edge );
|
2008-12-04 04:28:11 +00:00
|
|
|
|
2011-12-14 04:29:25 +00:00
|
|
|
edge->SetShape( S_POLYGON );
|
2009-12-07 03:46:13 +00:00
|
|
|
edge->SetLayer( LAYER_N_FRONT );
|
2007-08-08 03:50:44 +00:00
|
|
|
|
2011-08-08 23:50:55 +00:00
|
|
|
std::vector<wxPoint> polyPoints = edge->GetPolyPoints();
|
2011-11-10 15:55:05 +00:00
|
|
|
polyPoints.reserve( 2 * PolyEdges.size() + 2 );
|
2007-08-08 03:50:44 +00:00
|
|
|
|
|
|
|
// Init start point coord:
|
2012-02-19 04:02:19 +00:00
|
|
|
polyPoints.push_back( wxPoint( pad1->GetPos0().x, 0 ) );
|
2007-08-08 03:50:44 +00:00
|
|
|
|
2008-12-29 18:02:54 +00:00
|
|
|
wxPoint first_coordinate, last_coordinate;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2011-11-16 20:52:51 +00:00
|
|
|
for( unsigned ii = 0; ii < PolyEdges.size(); ii++ ) // Copy points
|
2007-08-08 03:50:44 +00:00
|
|
|
{
|
// Dick Hollenbeck's KiROUND R&D
// This provides better project control over rounding to int from double
// than wxRound() did. This scheme provides better logging in Debug builds
// and it provides for compile time calculation of constants.
#include <stdio.h>
#include <assert.h>
#include <limits.h>
//-----<KiROUND KIT>------------------------------------------------------------
/**
* KiROUND
* rounds a floating point number to an int using
* "round halfway cases away from zero".
* In Debug build an assert fires if will not fit into an int.
*/
#if defined( DEBUG )
// DEBUG: a macro to capture line and file, then calls this inline
static inline int KiRound( double v, int line, const char* filename )
{
v = v < 0 ? v - 0.5 : v + 0.5;
if( v > INT_MAX + 0.5 )
{
printf( "%s: in file %s on line %d, val: %.16g too ' > 0 ' for int\n", __FUNCTION__, filename, line, v );
}
else if( v < INT_MIN - 0.5 )
{
printf( "%s: in file %s on line %d, val: %.16g too ' < 0 ' for int\n", __FUNCTION__, filename, line, v );
}
return int( v );
}
#define KiROUND( v ) KiRound( v, __LINE__, __FILE__ )
#else
// RELEASE: a macro so compile can pre-compute constants.
#define KiROUND( v ) int( (v) < 0 ? (v) - 0.5 : (v) + 0.5 )
#endif
//-----</KiROUND KIT>-----------------------------------------------------------
// Only a macro is compile time calculated, an inline function causes a static constructor
// in a situation like this.
// Therefore the Release build is best done with a MACRO not an inline function.
int Computed = KiROUND( 14.3 * 8 );
int main( int argc, char** argv )
{
for( double d = double(INT_MAX)-1; d < double(INT_MAX)+8; d += 2.0 )
{
int i = KiROUND( d );
printf( "t: %d %.16g\n", i, d );
}
return 0;
}
2012-04-19 06:55:45 +00:00
|
|
|
last_coordinate.x = KiROUND( PolyEdges[ii] * ShapeScaleX ) + pad1->GetPos0().x;
|
|
|
|
last_coordinate.y = -KiROUND( PolyEdges[ii] * ShapeScaleY );
|
2011-08-08 23:50:55 +00:00
|
|
|
polyPoints.push_back( last_coordinate );
|
2007-08-08 03:50:44 +00:00
|
|
|
}
|
|
|
|
|
2011-08-08 23:50:55 +00:00
|
|
|
first_coordinate.y = polyPoints[1].y;
|
2007-08-08 03:50:44 +00:00
|
|
|
|
|
|
|
switch( PolyShapeType )
|
|
|
|
{
|
|
|
|
case 0: // Single
|
|
|
|
case 2: // Single mirrored
|
2012-02-19 04:02:19 +00:00
|
|
|
|
2007-08-08 03:50:44 +00:00
|
|
|
// Init end point coord:
|
2012-02-19 04:02:19 +00:00
|
|
|
pad2->SetX0( last_coordinate.x );
|
2011-08-08 23:50:55 +00:00
|
|
|
polyPoints.push_back( wxPoint( last_coordinate.x, 0 ) );
|
2008-12-29 18:02:54 +00:00
|
|
|
|
2012-09-22 11:19:37 +00:00
|
|
|
pad1->SetSize( wxSize( std::abs( first_coordinate.y ),
|
|
|
|
std::abs( first_coordinate.y ) ) );
|
|
|
|
pad2->SetSize( wxSize( std::abs( last_coordinate.y ),
|
|
|
|
std::abs( last_coordinate.y ) ) );
|
2012-02-19 04:02:19 +00:00
|
|
|
|
|
|
|
pad1->SetY0( first_coordinate.y / 2 );
|
|
|
|
pad2->SetY0( last_coordinate.y / 2 );
|
|
|
|
|
|
|
|
pad1->SetY( pad1->GetPos0().y + module->GetPosition().y );
|
|
|
|
pad2->SetY( pad2->GetPos0().y + module->GetPosition().y );
|
2007-08-08 03:50:44 +00:00
|
|
|
break;
|
|
|
|
|
2009-11-18 12:52:19 +00:00
|
|
|
case 1: // Symmetric
|
2011-08-08 23:50:55 +00:00
|
|
|
for( int ndx = polyPoints.size() - 1; ndx>=0; --ndx )
|
2007-08-08 03:50:44 +00:00
|
|
|
{
|
2011-08-08 23:50:55 +00:00
|
|
|
wxPoint pt = polyPoints[ndx];
|
2007-08-08 03:50:44 +00:00
|
|
|
|
2008-12-29 18:02:54 +00:00
|
|
|
pt.y = -pt.y; // mirror about X axis
|
2007-08-08 03:50:44 +00:00
|
|
|
|
2011-08-08 23:50:55 +00:00
|
|
|
polyPoints.push_back( pt );
|
2008-12-29 18:02:54 +00:00
|
|
|
}
|
2007-08-08 03:50:44 +00:00
|
|
|
|
2012-09-22 11:19:37 +00:00
|
|
|
pad1->SetSize( wxSize( 2 * std::abs( first_coordinate.y ),
|
|
|
|
2 * std::abs( first_coordinate.y ) ) );
|
|
|
|
pad2->SetSize( wxSize( 2 * std::abs( last_coordinate.y ),
|
|
|
|
2 * std::abs( last_coordinate.y ) ) );
|
2007-08-08 03:50:44 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-11-10 15:55:05 +00:00
|
|
|
PolyEdges.clear();
|
2011-12-14 04:29:25 +00:00
|
|
|
module->CalculateBoundingBox();
|
2009-01-05 05:21:35 +00:00
|
|
|
GetBoard()->m_Status_Pcb = 0;
|
2010-02-19 13:23:58 +00:00
|
|
|
OnModify();
|
2011-12-14 04:29:25 +00:00
|
|
|
return module;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
void PCB_EDIT_FRAME::Edit_Gap( wxDC* DC, MODULE* aModule )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2007-08-08 03:50:44 +00:00
|
|
|
int gap_size, oX;
|
|
|
|
D_PAD* pad, * next_pad;
|
|
|
|
wxString msg;
|
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
if( aModule == NULL )
|
2009-11-18 12:52:19 +00:00
|
|
|
return;
|
2007-08-08 03:50:44 +00:00
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
// Test if module is a gap type (name begins with GAP, and has 2 pads).
|
2013-03-13 18:53:58 +00:00
|
|
|
msg = aModule->GetReference().Left( 3 );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2007-08-08 03:50:44 +00:00
|
|
|
if( msg != wxT( "GAP" ) )
|
|
|
|
return;
|
|
|
|
|
2013-03-18 19:36:07 +00:00
|
|
|
pad = aModule->Pads();
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2007-08-08 03:50:44 +00:00
|
|
|
if( pad == NULL )
|
|
|
|
{
|
2009-11-18 12:52:19 +00:00
|
|
|
DisplayError( this, _( "No pad for this module" ) );
|
|
|
|
return;
|
2007-08-08 03:50:44 +00:00
|
|
|
}
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2008-11-24 06:53:43 +00:00
|
|
|
next_pad = (D_PAD*) pad->Next();
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2007-08-08 03:50:44 +00:00
|
|
|
if( next_pad == NULL )
|
|
|
|
{
|
2009-11-18 12:52:19 +00:00
|
|
|
DisplayError( this, _( "Only one pad for this module" ) );
|
|
|
|
return;
|
2007-08-08 03:50:44 +00:00
|
|
|
}
|
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
aModule->Draw( m_canvas, DC, GR_XOR );
|
2007-08-08 03:50:44 +00:00
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
// Calculate the current dimension.
|
|
|
|
gap_size = next_pad->GetPos0().x - pad->GetPos0().x - pad->GetSize().x;
|
2007-08-08 03:50:44 +00:00
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
// Entrer the desired length of the gap.
|
2012-04-13 18:51:24 +00:00
|
|
|
msg = ReturnStringFromValue( g_UserUnit, gap_size );
|
2010-07-20 18:11:34 +00:00
|
|
|
wxTextEntryDialog dlg( this, _( "Gap:" ), _( "Create Microwave Gap" ), msg );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2010-07-20 18:11:34 +00:00
|
|
|
if( dlg.ShowModal() != wxID_OK )
|
|
|
|
return; // cancelled by user
|
2007-08-08 03:50:44 +00:00
|
|
|
|
2010-07-21 08:15:54 +00:00
|
|
|
msg = dlg.GetValue();
|
2012-04-16 17:39:32 +00:00
|
|
|
gap_size = ReturnValueFromString( g_UserUnit, msg );
|
2007-08-08 03:50:44 +00:00
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
// Updating sizes of pads forming the gap.
|
|
|
|
int tw = GetBoard()->GetCurrentTrackWidth();
|
|
|
|
pad->SetSize( wxSize( tw, tw ) );
|
|
|
|
|
|
|
|
pad->SetY0( 0 );
|
|
|
|
oX = -( gap_size + pad->GetSize().x ) / 2;
|
|
|
|
pad->SetX0( oX );
|
|
|
|
|
|
|
|
wxPoint padpos = pad->GetPos0() + aModule->GetPosition();
|
|
|
|
|
|
|
|
RotatePoint( &padpos.x, &padpos.y,
|
2013-03-13 18:53:58 +00:00
|
|
|
aModule->GetPosition().x, aModule->GetPosition().y, aModule->GetOrientation() );
|
2012-02-19 04:02:19 +00:00
|
|
|
|
|
|
|
pad->SetPosition( padpos );
|
|
|
|
|
|
|
|
tw = GetBoard()->GetCurrentTrackWidth();
|
|
|
|
next_pad->SetSize( wxSize( tw, tw ) );
|
|
|
|
|
|
|
|
next_pad->SetY0( 0 );
|
|
|
|
next_pad->SetX0( oX + gap_size + next_pad->GetSize().x );
|
|
|
|
|
|
|
|
padpos = next_pad->GetPos0() + aModule->GetPosition();
|
|
|
|
|
|
|
|
RotatePoint( &padpos.x, &padpos.y,
|
2013-03-13 18:53:58 +00:00
|
|
|
aModule->GetPosition().x, aModule->GetPosition().y, aModule->GetOrientation() );
|
2012-02-19 04:02:19 +00:00
|
|
|
|
|
|
|
next_pad->SetPosition( padpos );
|
|
|
|
|
|
|
|
aModule->Draw( m_canvas, DC, GR_OR );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|