2007-08-06 02:02:39 +00:00
|
|
|
/****************************************************/
|
2009-11-12 15:43:38 +00:00
|
|
|
/* class_module.cpp : MODULE class implementation. */
|
2007-08-06 02:02:39 +00:00
|
|
|
/****************************************************/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
#include "fctsys.h"
|
|
|
|
#include "gr_basic.h"
|
|
|
|
#include "wxstruct.h"
|
|
|
|
#include "plot_common.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "class_drawpanel.h"
|
2007-06-05 12:10:51 +00:00
|
|
|
#include "trigo.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "confirm.h"
|
|
|
|
#include "kicad_string.h"
|
2009-04-05 20:49:15 +00:00
|
|
|
#include "pcbcommon.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
|
|
|
|
#include "pcbnew.h"
|
2009-10-28 11:48:47 +00:00
|
|
|
#include "class_board_design_settings.h"
|
2010-01-29 20:36:12 +00:00
|
|
|
#include "colors_selection.h"
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
#include "drag.h"
|
|
|
|
|
|
|
|
#include "3d_struct.h"
|
|
|
|
#include "protos.h"
|
2011-01-14 17:43:30 +00:00
|
|
|
#include "richio.h"
|
2011-02-05 16:15:48 +00:00
|
|
|
#include "filter_reader.h"
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
/*********************************************/
|
|
|
|
/* Class MODULE : describes a pcb component. */
|
|
|
|
/*********************************************/
|
2008-02-19 00:30:10 +00:00
|
|
|
MODULE::MODULE( BOARD* parent ) :
|
2008-12-04 04:28:11 +00:00
|
|
|
BOARD_ITEM( parent, TYPE_MODULE )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-06 02:02:39 +00:00
|
|
|
m_Attributs = MOD_DEFAULT;
|
2009-12-07 03:46:13 +00:00
|
|
|
m_Layer = LAYER_N_FRONT;
|
2007-08-06 02:02:39 +00:00
|
|
|
m_Orient = 0;
|
|
|
|
m_ModuleStatus = 0;
|
|
|
|
flag = 0;
|
|
|
|
m_CntRot90 = m_CntRot180 = 0;
|
2010-07-11 16:24:44 +00:00
|
|
|
m_Surface = 0.0;
|
2009-11-04 19:08:08 +00:00
|
|
|
m_Link = 0;
|
2010-07-20 10:30:40 +00:00
|
|
|
m_LastEdit_Time = time( NULL );
|
2009-11-04 19:08:08 +00:00
|
|
|
m_LocalClearance = 0;
|
|
|
|
m_LocalSolderMaskMargin = 0;
|
|
|
|
m_LocalSolderPasteMargin = 0;
|
|
|
|
m_LocalSolderPasteMarginRatio = 0.0;
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2007-08-06 02:02:39 +00:00
|
|
|
m_Reference = new TEXTE_MODULE( this, TEXT_is_REFERENCE );
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2007-08-06 02:02:39 +00:00
|
|
|
m_Value = new TEXTE_MODULE( this, TEXT_is_VALUE );
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2009-08-04 18:21:32 +00:00
|
|
|
// Reserve one void 3D entry, to avoid problems with void list
|
|
|
|
m_3D_Drawings.PushBack( new S3D_MASTER( this ) );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-06 02:02:39 +00:00
|
|
|
|
2007-09-01 12:00:30 +00:00
|
|
|
MODULE::~MODULE()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-06 02:02:39 +00:00
|
|
|
delete m_Reference;
|
|
|
|
delete m_Value;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2010-07-20 10:30:40 +00:00
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
/* Draw the anchor cross (vertical)
|
|
|
|
* Must be done after the pads, because drawing the hole will erase overwrite
|
|
|
|
* every thing already drawn.
|
|
|
|
*/
|
2011-01-21 19:30:59 +00:00
|
|
|
void MODULE::DrawAncre( EDA_DRAW_PANEL* panel, wxDC* DC, const wxPoint& offset,
|
2009-08-01 19:26:05 +00:00
|
|
|
int dim_ancre, int draw_mode )
|
|
|
|
{
|
2010-02-08 18:15:42 +00:00
|
|
|
int anchor_size = DC->DeviceToLogicalXRel( dim_ancre );
|
2009-08-01 19:26:05 +00:00
|
|
|
|
|
|
|
GRSetDrawMode( DC, draw_mode );
|
|
|
|
|
2010-01-31 20:01:46 +00:00
|
|
|
if( GetBoard()->IsElementVisible( ANCHOR_VISIBLE ) )
|
2009-08-01 19:26:05 +00:00
|
|
|
{
|
2010-07-20 10:30:40 +00:00
|
|
|
int color = g_ColorsSettings.GetItemColor( ANCHOR_VISIBLE );
|
2009-08-01 19:26:05 +00:00
|
|
|
GRLine( &panel->m_ClipBox, DC,
|
2009-11-04 19:08:08 +00:00
|
|
|
m_Pos.x - offset.x - anchor_size, m_Pos.y - offset.y,
|
|
|
|
m_Pos.x - offset.x + anchor_size, m_Pos.y - offset.y,
|
2010-01-29 20:36:12 +00:00
|
|
|
0, color );
|
2009-08-01 19:26:05 +00:00
|
|
|
GRLine( &panel->m_ClipBox, DC,
|
2009-11-04 19:08:08 +00:00
|
|
|
m_Pos.x - offset.x, m_Pos.y - offset.y - anchor_size,
|
|
|
|
m_Pos.x - offset.x, m_Pos.y - offset.y + anchor_size,
|
2010-01-29 20:36:12 +00:00
|
|
|
0, color );
|
2009-08-01 19:26:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-04 19:08:08 +00:00
|
|
|
|
2008-12-06 08:21:54 +00:00
|
|
|
void MODULE::Copy( MODULE* aModule )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2008-12-06 08:21:54 +00:00
|
|
|
m_Pos = aModule->m_Pos;
|
|
|
|
m_Layer = aModule->m_Layer;
|
|
|
|
m_LibRef = aModule->m_LibRef;
|
|
|
|
m_Attributs = aModule->m_Attributs;
|
|
|
|
m_Orient = aModule->m_Orient;
|
|
|
|
m_BoundaryBox = aModule->m_BoundaryBox;
|
|
|
|
m_PadNum = aModule->m_PadNum;
|
|
|
|
m_CntRot90 = aModule->m_CntRot90;
|
|
|
|
m_CntRot180 = aModule->m_CntRot180;
|
|
|
|
m_LastEdit_Time = aModule->m_LastEdit_Time;
|
2010-06-14 20:16:47 +00:00
|
|
|
m_Link = aModule->m_Link;
|
2008-12-06 08:21:54 +00:00
|
|
|
m_Path = aModule->m_Path; //is this correct behavior?
|
2007-08-06 02:02:39 +00:00
|
|
|
m_TimeStamp = GetTimeStamp();
|
2011-08-09 03:37:48 +00:00
|
|
|
|
|
|
|
m_LocalClearance = aModule->m_LocalClearance;
|
|
|
|
m_LocalSolderMaskMargin = aModule->m_LocalSolderMaskMargin;
|
|
|
|
m_LocalSolderPasteMargin = aModule->m_LocalSolderPasteMargin;
|
|
|
|
m_LocalSolderPasteMarginRatio = aModule->m_LocalSolderPasteMarginRatio;
|
2007-08-06 02:02:39 +00:00
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
/* Copy reference and value. */
|
2008-12-06 08:21:54 +00:00
|
|
|
m_Reference->Copy( aModule->m_Reference );
|
|
|
|
m_Value->Copy( aModule->m_Value );
|
2007-08-06 02:02:39 +00:00
|
|
|
|
2009-08-03 18:54:48 +00:00
|
|
|
/* Copy auxiliary data: Pads */
|
|
|
|
m_Pads.DeleteAll();
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2008-12-06 08:21:54 +00:00
|
|
|
for( D_PAD* pad = aModule->m_Pads; pad; pad = pad->Next() )
|
2007-08-06 02:02:39 +00:00
|
|
|
{
|
|
|
|
D_PAD* newpad = new D_PAD( this );
|
|
|
|
newpad->Copy( pad );
|
2008-12-04 04:28:11 +00:00
|
|
|
m_Pads.PushBack( newpad );
|
2007-08-06 02:02:39 +00:00
|
|
|
}
|
|
|
|
|
2009-08-03 18:54:48 +00:00
|
|
|
/* Copy auxiliary data: Drawings */
|
|
|
|
m_Drawings.DeleteAll();
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2008-12-06 08:21:54 +00:00
|
|
|
for( BOARD_ITEM* item = aModule->m_Drawings; item; item = item->Next() )
|
2007-08-06 02:02:39 +00:00
|
|
|
{
|
2008-12-04 04:28:11 +00:00
|
|
|
switch( item->Type() )
|
2007-08-06 02:02:39 +00:00
|
|
|
{
|
2008-12-04 04:28:11 +00:00
|
|
|
case TYPE_TEXTE_MODULE:
|
2009-11-04 19:08:08 +00:00
|
|
|
TEXTE_MODULE * textm;
|
2008-12-04 04:28:11 +00:00
|
|
|
textm = new TEXTE_MODULE( this );
|
|
|
|
textm->Copy( (TEXTE_MODULE*) item );
|
|
|
|
m_Drawings.PushBack( textm );
|
2007-08-06 02:02:39 +00:00
|
|
|
break;
|
|
|
|
|
2008-12-04 04:28:11 +00:00
|
|
|
case TYPE_EDGE_MODULE:
|
2009-11-04 19:08:08 +00:00
|
|
|
EDGE_MODULE * edge;
|
2008-12-04 04:28:11 +00:00
|
|
|
edge = new EDGE_MODULE( this );
|
|
|
|
edge->Copy( (EDGE_MODULE*) item );
|
|
|
|
m_Drawings.PushBack( edge );
|
2007-08-06 02:02:39 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2009-08-03 18:54:48 +00:00
|
|
|
wxMessageBox( wxT( "MODULE::Copy() Internal Err: unknown type" ) );
|
2007-08-06 02:02:39 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-04 19:08:08 +00:00
|
|
|
/* Copy auxiliary data: 3D_Drawings info */
|
2009-08-04 18:21:32 +00:00
|
|
|
m_3D_Drawings.DeleteAll();
|
2009-11-04 19:08:08 +00:00
|
|
|
|
2009-08-04 18:21:32 +00:00
|
|
|
// Ensure there is one (or more) item in m_3D_Drawings
|
2009-11-12 15:43:38 +00:00
|
|
|
m_3D_Drawings.PushBack( new S3D_MASTER( this ) ); // push a void item
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2008-12-06 08:21:54 +00:00
|
|
|
for( S3D_MASTER* item = aModule->m_3D_Drawings; item; item = item->Next() )
|
2007-08-06 02:02:39 +00:00
|
|
|
{
|
2009-11-12 15:43:38 +00:00
|
|
|
if( item->m_Shape3DName.IsEmpty() ) // do not copy empty shapes.
|
2009-04-15 07:20:30 +00:00
|
|
|
continue;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2009-04-15 06:32:15 +00:00
|
|
|
S3D_MASTER* t3d = m_3D_Drawings;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2010-07-20 10:30:40 +00:00
|
|
|
if( t3d && t3d->m_Shape3DName.IsEmpty() ) // The first entry can
|
2011-09-07 19:41:04 +00:00
|
|
|
{ // exist, but is empty : use it.
|
2009-04-15 06:32:15 +00:00
|
|
|
t3d->Copy( item );
|
2011-09-07 19:41:04 +00:00
|
|
|
}
|
2009-04-15 06:32:15 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
t3d = new S3D_MASTER( this );
|
|
|
|
t3d->Copy( item );
|
|
|
|
m_3D_Drawings.PushBack( t3d );
|
|
|
|
}
|
2007-08-06 02:02:39 +00:00
|
|
|
}
|
|
|
|
|
2008-12-06 08:21:54 +00:00
|
|
|
m_Doc = aModule->m_Doc;
|
|
|
|
m_KeyWord = aModule->m_KeyWord;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-06 02:02:39 +00:00
|
|
|
|
2010-11-12 16:36:43 +00:00
|
|
|
/**
|
|
|
|
* Function Draw
|
2008-03-13 21:18:05 +00:00
|
|
|
* Draws the footprint to the current Device Context
|
2010-12-29 17:47:32 +00:00
|
|
|
* @param aPanel = draw panel, Used to know the clip box
|
|
|
|
* @param aDC = Current Device Context
|
|
|
|
* @param aDrawMode = GR_OR, GR_XOR..
|
|
|
|
* @param aOffset = draw offset (usually wxPoint(0,0)
|
2007-08-06 02:02:39 +00:00
|
|
|
*/
|
2011-01-21 19:30:59 +00:00
|
|
|
void MODULE::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, int aDrawMode, const wxPoint& aOffset )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2010-10-09 08:08:29 +00:00
|
|
|
if( (m_Flags & DO_NOT_DRAW) || (m_Flags & IS_MOVED) )
|
2008-03-15 10:24:32 +00:00
|
|
|
return;
|
2007-08-06 02:02:39 +00:00
|
|
|
|
2008-11-24 06:53:43 +00:00
|
|
|
for( D_PAD* pad = m_Pads; pad; pad = pad->Next() )
|
2007-08-06 02:02:39 +00:00
|
|
|
{
|
2008-11-24 06:53:43 +00:00
|
|
|
if( pad->m_Flags & IS_MOVED )
|
2007-08-06 02:02:39 +00:00
|
|
|
continue;
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2010-12-29 17:47:32 +00:00
|
|
|
pad->Draw( aPanel, aDC, aDrawMode, aOffset );
|
2007-08-06 02:02:39 +00:00
|
|
|
}
|
|
|
|
|
2010-07-20 10:30:40 +00:00
|
|
|
BOARD* brd = GetBoard();
|
2010-01-31 20:01:46 +00:00
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
// Draws footprint anchor
|
2010-12-29 17:47:32 +00:00
|
|
|
DrawAncre( aPanel, aDC, aOffset, DIM_ANCRE_MODULE, aDrawMode );
|
2007-08-06 02:02:39 +00:00
|
|
|
|
2008-03-13 21:18:05 +00:00
|
|
|
/* Draw graphic items */
|
2010-01-31 20:01:46 +00:00
|
|
|
if( brd->IsElementVisible( MOD_REFERENCES_VISIBLE ) )
|
2010-01-28 13:10:46 +00:00
|
|
|
{
|
|
|
|
if( !(m_Reference->m_Flags & IS_MOVED) )
|
2010-12-29 17:47:32 +00:00
|
|
|
m_Reference->Draw( aPanel, aDC, aDrawMode, aOffset );
|
2010-01-28 13:10:46 +00:00
|
|
|
}
|
2008-04-01 05:21:50 +00:00
|
|
|
|
2010-01-31 20:01:46 +00:00
|
|
|
if( brd->IsElementVisible( MOD_VALUES_VISIBLE ) )
|
2010-01-28 13:10:46 +00:00
|
|
|
{
|
|
|
|
if( !(m_Value->m_Flags & IS_MOVED) )
|
2010-12-29 17:47:32 +00:00
|
|
|
m_Value->Draw( aPanel, aDC, aDrawMode, aOffset );
|
2010-01-28 13:10:46 +00:00
|
|
|
}
|
2007-08-06 02:02:39 +00:00
|
|
|
|
2008-04-01 05:21:50 +00:00
|
|
|
for( BOARD_ITEM* item = m_Drawings; item; item = item->Next() )
|
2007-08-06 02:02:39 +00:00
|
|
|
{
|
2008-04-01 05:21:50 +00:00
|
|
|
if( item->m_Flags & IS_MOVED )
|
2007-08-06 02:02:39 +00:00
|
|
|
continue;
|
|
|
|
|
2008-04-01 05:21:50 +00:00
|
|
|
switch( item->Type() )
|
2007-08-06 02:02:39 +00:00
|
|
|
{
|
2008-12-04 04:28:11 +00:00
|
|
|
case TYPE_TEXTE_MODULE:
|
|
|
|
case TYPE_EDGE_MODULE:
|
2010-12-29 17:47:32 +00:00
|
|
|
item->Draw( aPanel, aDC, aDrawMode, aOffset );
|
2007-08-06 02:02:39 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-12 16:36:43 +00:00
|
|
|
/**
|
|
|
|
* Function DrawEdgesOnly
|
2008-03-13 21:18:05 +00:00
|
|
|
* Draws the footprint edges only to the current Device Context
|
|
|
|
* @param panel = The active Draw Panel (used to know the clip box)
|
|
|
|
* @param DC = current Device Context
|
|
|
|
* @param offset = draw offset (usually wxPoint(0,0)
|
|
|
|
* @param draw_mode = GR_OR, GR_XOR, GR_AND
|
|
|
|
*/
|
2011-01-21 19:30:59 +00:00
|
|
|
void MODULE::DrawEdgesOnly( EDA_DRAW_PANEL* panel, wxDC* DC, const wxPoint& offset, int draw_mode )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2008-04-01 05:21:50 +00:00
|
|
|
for( BOARD_ITEM* item = m_Drawings; item; item = item->Next() )
|
2007-08-06 02:02:39 +00:00
|
|
|
{
|
2008-04-01 05:21:50 +00:00
|
|
|
switch( item->Type() )
|
2007-08-06 02:02:39 +00:00
|
|
|
{
|
2008-12-04 04:28:11 +00:00
|
|
|
case TYPE_EDGE_MODULE:
|
2008-04-01 05:21:50 +00:00
|
|
|
item->Draw( panel, DC, draw_mode, offset );
|
2007-08-06 02:02:39 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-30 21:30:58 +00:00
|
|
|
bool MODULE::Save( FILE* aFile ) const
|
|
|
|
{
|
2008-03-15 10:24:32 +00:00
|
|
|
char statusTxt[8];
|
|
|
|
BOARD_ITEM* item;
|
2008-02-19 00:30:10 +00:00
|
|
|
|
2007-10-30 21:30:58 +00:00
|
|
|
bool rc = false;
|
|
|
|
|
2011-02-28 18:36:19 +00:00
|
|
|
fprintf( aFile, "$MODULE %s\n", TO_UTF8( m_LibRef ) );
|
2007-10-30 21:30:58 +00:00
|
|
|
|
|
|
|
memset( statusTxt, 0, sizeof(statusTxt) );
|
|
|
|
if( IsLocked() )
|
|
|
|
statusTxt[0] = 'F';
|
|
|
|
else
|
|
|
|
statusTxt[0] = '~';
|
2008-02-19 00:30:10 +00:00
|
|
|
|
2007-10-30 21:30:58 +00:00
|
|
|
if( m_ModuleStatus & MODULE_is_PLACED )
|
|
|
|
statusTxt[1] = 'P';
|
|
|
|
else
|
|
|
|
statusTxt[1] = '~';
|
|
|
|
|
|
|
|
fprintf( aFile, "Po %d %d %d %d %8.8lX %8.8lX %s\n",
|
2009-11-04 19:08:08 +00:00
|
|
|
m_Pos.x, m_Pos.y,
|
|
|
|
m_Orient, m_Layer, m_LastEdit_Time,
|
|
|
|
m_TimeStamp, statusTxt );
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2011-02-28 18:36:19 +00:00
|
|
|
fprintf( aFile, "Li %s\n", TO_UTF8( m_LibRef ) );
|
2007-10-30 21:30:58 +00:00
|
|
|
|
|
|
|
if( !m_Doc.IsEmpty() )
|
|
|
|
{
|
2011-02-28 18:36:19 +00:00
|
|
|
fprintf( aFile, "Cd %s\n", TO_UTF8( m_Doc ) );
|
2007-10-30 21:30:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( !m_KeyWord.IsEmpty() )
|
|
|
|
{
|
2011-02-28 18:36:19 +00:00
|
|
|
fprintf( aFile, "Kw %s\n", TO_UTF8( m_KeyWord ) );
|
2007-10-30 21:30:58 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-10-30 21:30:58 +00:00
|
|
|
fprintf( aFile, "Sc %8.8lX\n", m_TimeStamp );
|
2011-02-28 18:36:19 +00:00
|
|
|
fprintf( aFile, "AR %s\n", TO_UTF8( m_Path ) );
|
2007-10-30 21:30:58 +00:00
|
|
|
fprintf( aFile, "Op %X %X 0\n", m_CntRot90, m_CntRot180 );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2009-11-04 19:08:08 +00:00
|
|
|
if( m_LocalSolderMaskMargin != 0 )
|
2010-07-20 10:30:40 +00:00
|
|
|
fprintf( aFile, ".SolderMask %d\n", m_LocalSolderMaskMargin );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2009-11-04 19:08:08 +00:00
|
|
|
if( m_LocalSolderPasteMargin != 0 )
|
2010-07-20 10:30:40 +00:00
|
|
|
fprintf( aFile, ".SolderPaste %d\n", m_LocalSolderPasteMargin );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2010-07-20 10:30:40 +00:00
|
|
|
if( m_LocalSolderPasteMarginRatio != 0 )
|
|
|
|
fprintf( aFile, ".SolderPasteRatio %g\n", m_LocalSolderPasteMarginRatio );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2009-11-06 12:55:20 +00:00
|
|
|
if( m_LocalClearance != 0 )
|
2010-07-20 10:30:40 +00:00
|
|
|
fprintf( aFile, ".LocalClearance %d\n", m_LocalClearance );
|
2007-10-30 21:30:58 +00:00
|
|
|
|
|
|
|
// attributes
|
|
|
|
if( m_Attributs != MOD_DEFAULT )
|
|
|
|
{
|
|
|
|
fprintf( aFile, "At " );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2007-10-30 21:30:58 +00:00
|
|
|
if( m_Attributs & MOD_CMS )
|
|
|
|
fprintf( aFile, "SMD " );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2007-10-30 21:30:58 +00:00
|
|
|
if( m_Attributs & MOD_VIRTUAL )
|
|
|
|
fprintf( aFile, "VIRTUAL " );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2007-10-30 21:30:58 +00:00
|
|
|
fprintf( aFile, "\n" );
|
|
|
|
}
|
|
|
|
|
|
|
|
// save reference
|
|
|
|
if( !m_Reference->Save( aFile ) )
|
|
|
|
goto out;
|
2008-02-19 00:30:10 +00:00
|
|
|
|
2007-10-30 21:30:58 +00:00
|
|
|
// save value
|
|
|
|
if( !m_Value->Save( aFile ) )
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
// save drawing elements
|
2008-03-15 10:24:32 +00:00
|
|
|
for( item = m_Drawings; item; item = item->Next() )
|
2007-10-30 21:30:58 +00:00
|
|
|
{
|
|
|
|
switch( item->Type() )
|
|
|
|
{
|
2008-12-04 04:28:11 +00:00
|
|
|
case TYPE_TEXTE_MODULE:
|
|
|
|
case TYPE_EDGE_MODULE:
|
2007-10-30 21:30:58 +00:00
|
|
|
if( !item->Save( aFile ) )
|
|
|
|
goto out;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2007-10-30 21:30:58 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2009-11-04 19:08:08 +00:00
|
|
|
#if defined(DEBUG)
|
2007-10-30 21:30:58 +00:00
|
|
|
printf( "MODULE::Save() ignoring type %d\n", item->Type() );
|
2008-02-19 00:30:10 +00:00
|
|
|
#endif
|
2007-10-30 21:30:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// save the pads
|
2008-03-15 10:24:32 +00:00
|
|
|
for( item = m_Pads; item; item = item->Next() )
|
2007-10-30 21:30:58 +00:00
|
|
|
if( !item->Save( aFile ) )
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
Write_3D_Descr( aFile );
|
|
|
|
|
2011-02-28 18:36:19 +00:00
|
|
|
fprintf( aFile, "$EndMODULE %s\n", TO_UTF8( m_LibRef ) );
|
2008-02-19 00:30:10 +00:00
|
|
|
|
2007-10-30 21:30:58 +00:00
|
|
|
rc = true;
|
2008-02-19 00:30:10 +00:00
|
|
|
out:
|
2007-10-30 21:30:58 +00:00
|
|
|
return rc;
|
|
|
|
}
|
2008-02-19 00:30:10 +00:00
|
|
|
|
2007-08-06 02:02:39 +00:00
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
/* Save the description of 3D MODULE
|
2007-08-06 02:02:39 +00:00
|
|
|
*/
|
2009-11-12 15:43:38 +00:00
|
|
|
int MODULE::Write_3D_Descr( FILE* File ) const
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-11-04 19:08:08 +00:00
|
|
|
char buf[512];
|
2007-08-06 02:02:39 +00:00
|
|
|
|
2008-12-06 21:20:50 +00:00
|
|
|
for( S3D_MASTER* t3D = m_3D_Drawings; t3D; t3D = t3D->Next() )
|
2007-08-06 02:02:39 +00:00
|
|
|
{
|
2008-12-06 21:20:50 +00:00
|
|
|
if( !t3D->m_Shape3DName.IsEmpty() )
|
2007-08-06 02:02:39 +00:00
|
|
|
{
|
|
|
|
fprintf( File, "$SHAPE3D\n" );
|
|
|
|
|
2011-03-25 20:07:27 +00:00
|
|
|
fprintf( File, "Na %s\n", EscapedUTF8( t3D->m_Shape3DName ).c_str() );
|
2007-08-06 02:02:39 +00:00
|
|
|
|
|
|
|
sprintf( buf, "Sc %lf %lf %lf\n",
|
2009-11-04 19:08:08 +00:00
|
|
|
t3D->m_MatScale.x,
|
|
|
|
t3D->m_MatScale.y,
|
|
|
|
t3D->m_MatScale.z );
|
2009-10-05 04:22:27 +00:00
|
|
|
fprintf( File, "%s", to_point( buf ) );
|
2007-08-06 02:02:39 +00:00
|
|
|
|
|
|
|
sprintf( buf, "Of %lf %lf %lf\n",
|
2009-11-04 19:08:08 +00:00
|
|
|
t3D->m_MatPosition.x,
|
|
|
|
t3D->m_MatPosition.y,
|
|
|
|
t3D->m_MatPosition.z );
|
2009-10-05 04:22:27 +00:00
|
|
|
fprintf( File, "%s", to_point( buf ) );
|
2007-08-06 02:02:39 +00:00
|
|
|
|
|
|
|
sprintf( buf, "Ro %lf %lf %lf\n",
|
2009-11-04 19:08:08 +00:00
|
|
|
t3D->m_MatRotation.x,
|
|
|
|
t3D->m_MatRotation.y,
|
|
|
|
t3D->m_MatRotation.z );
|
2009-10-05 04:22:27 +00:00
|
|
|
fprintf( File, "%s", to_point( buf ) );
|
2007-08-06 02:02:39 +00:00
|
|
|
|
|
|
|
fprintf( File, "$EndSHAPE3D\n" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-06 02:02:39 +00:00
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
/* Read 3D module from file. (Ascii)
|
|
|
|
* The 1st line of descr ($MODULE) is assumed to be already read
|
|
|
|
* Returns 0 if OK
|
2007-08-06 02:02:39 +00:00
|
|
|
*/
|
2011-01-14 17:43:30 +00:00
|
|
|
int MODULE::Read_3D_Descr( LINE_READER* aReader )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2011-01-14 17:43:30 +00:00
|
|
|
char* Line = aReader->Line();
|
2009-11-04 19:08:08 +00:00
|
|
|
char* text = Line + 3;
|
2008-12-06 08:21:54 +00:00
|
|
|
|
2008-12-06 21:20:50 +00:00
|
|
|
S3D_MASTER* t3D = m_3D_Drawings;
|
2007-08-06 02:02:39 +00:00
|
|
|
|
2008-12-06 21:20:50 +00:00
|
|
|
if( !t3D->m_Shape3DName.IsEmpty() )
|
2007-08-06 02:02:39 +00:00
|
|
|
{
|
2008-12-06 08:21:54 +00:00
|
|
|
S3D_MASTER* n3D = new S3D_MASTER( this );
|
|
|
|
|
|
|
|
m_3D_Drawings.PushBack( n3D );
|
|
|
|
|
2008-12-06 21:20:50 +00:00
|
|
|
t3D = n3D;
|
2007-08-06 02:02:39 +00:00
|
|
|
}
|
|
|
|
|
2011-01-14 17:43:30 +00:00
|
|
|
while( aReader->ReadLine() )
|
2007-08-06 02:02:39 +00:00
|
|
|
{
|
2011-01-14 17:43:30 +00:00
|
|
|
Line = aReader->Line();
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2007-08-06 02:02:39 +00:00
|
|
|
switch( Line[0] )
|
|
|
|
{
|
2009-11-12 15:43:38 +00:00
|
|
|
case '$':
|
2007-08-06 02:02:39 +00:00
|
|
|
if( Line[1] == 'E' )
|
|
|
|
return 0;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2007-08-06 02:02:39 +00:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
case 'N': // Shape File Name
|
|
|
|
{
|
|
|
|
char buf[512];
|
|
|
|
ReadDelimitedText( buf, text, 512 );
|
2011-02-28 18:36:19 +00:00
|
|
|
t3D->m_Shape3DName = FROM_UTF8( buf );
|
2007-08-06 02:02:39 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 'S': // Scale
|
|
|
|
sscanf( text, "%lf %lf %lf\n",
|
2009-11-04 19:08:08 +00:00
|
|
|
&t3D->m_MatScale.x,
|
|
|
|
&t3D->m_MatScale.y,
|
|
|
|
&t3D->m_MatScale.z );
|
2007-08-06 02:02:39 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'O': // Offset
|
|
|
|
sscanf( text, "%lf %lf %lf\n",
|
2009-11-04 19:08:08 +00:00
|
|
|
&t3D->m_MatPosition.x,
|
|
|
|
&t3D->m_MatPosition.y,
|
|
|
|
&t3D->m_MatPosition.z );
|
2007-08-06 02:02:39 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'R': // Rotation
|
|
|
|
sscanf( text, "%lf %lf %lf\n",
|
2009-11-04 19:08:08 +00:00
|
|
|
&t3D->m_MatRotation.x,
|
|
|
|
&t3D->m_MatRotation.y,
|
|
|
|
&t3D->m_MatRotation.z );
|
2007-08-06 02:02:39 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-06 02:02:39 +00:00
|
|
|
|
2009-11-04 19:08:08 +00:00
|
|
|
/* Read a MODULE description
|
|
|
|
* The first description line ($MODULE) is already read
|
|
|
|
* @return 0 if no error
|
2007-08-06 02:02:39 +00:00
|
|
|
*/
|
2011-01-14 17:43:30 +00:00
|
|
|
int MODULE::ReadDescr( LINE_READER* aReader )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2011-01-14 17:43:30 +00:00
|
|
|
char* Line;
|
|
|
|
char BufLine[256], BufCar1[128], * PtLine;
|
|
|
|
int itmp1, itmp2;
|
2007-08-06 02:02:39 +00:00
|
|
|
|
2011-01-14 17:43:30 +00:00
|
|
|
while( aReader->ReadLine() )
|
2007-08-06 02:02:39 +00:00
|
|
|
{
|
2011-01-14 17:43:30 +00:00
|
|
|
Line = aReader->Line();
|
2007-08-06 02:02:39 +00:00
|
|
|
if( Line[0] == '$' )
|
|
|
|
{
|
|
|
|
if( Line[1] == 'E' )
|
|
|
|
break;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2007-08-06 02:02:39 +00:00
|
|
|
if( Line[1] == 'P' )
|
|
|
|
{
|
2008-12-04 04:28:11 +00:00
|
|
|
D_PAD* pad = new D_PAD( this );
|
2011-01-14 17:43:30 +00:00
|
|
|
pad->ReadDescr( aReader );
|
2010-07-20 10:30:40 +00:00
|
|
|
RotatePoint( &pad->m_Pos, m_Orient );
|
2008-12-04 04:28:11 +00:00
|
|
|
pad->m_Pos.x += m_Pos.x;
|
|
|
|
pad->m_Pos.y += m_Pos.y;
|
2007-08-06 02:02:39 +00:00
|
|
|
|
2008-12-04 04:28:11 +00:00
|
|
|
m_Pads.PushBack( pad );
|
2007-08-06 02:02:39 +00:00
|
|
|
continue;
|
|
|
|
}
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2007-08-06 02:02:39 +00:00
|
|
|
if( Line[1] == 'S' )
|
2011-01-14 17:43:30 +00:00
|
|
|
Read_3D_Descr( aReader );
|
2007-08-06 02:02:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( strlen( Line ) < 4 )
|
|
|
|
continue;
|
2007-08-06 20:26:59 +00:00
|
|
|
|
2007-08-06 02:02:39 +00:00
|
|
|
PtLine = Line + 3;
|
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
/* Decode the first code of the current line and read the
|
|
|
|
* corresponding data
|
2010-07-20 10:30:40 +00:00
|
|
|
*/
|
2007-08-06 02:02:39 +00:00
|
|
|
switch( Line[0] )
|
|
|
|
{
|
|
|
|
case 'P':
|
|
|
|
memset( BufCar1, 0, sizeof(BufCar1) );
|
|
|
|
sscanf( PtLine, "%d %d %d %d %lX %lX %s",
|
2009-11-04 19:08:08 +00:00
|
|
|
&m_Pos.x, &m_Pos.y,
|
|
|
|
&m_Orient, &m_Layer,
|
|
|
|
&m_LastEdit_Time, &m_TimeStamp, BufCar1 );
|
2007-08-06 02:02:39 +00:00
|
|
|
|
|
|
|
m_ModuleStatus = 0;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2007-08-06 02:02:39 +00:00
|
|
|
if( BufCar1[0] == 'F' )
|
2008-03-15 10:24:32 +00:00
|
|
|
SetLocked( true );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2007-08-06 02:02:39 +00:00
|
|
|
if( BufCar1[1] == 'P' )
|
|
|
|
m_ModuleStatus |= MODULE_is_PLACED;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2007-08-06 02:02:39 +00:00
|
|
|
break;
|
|
|
|
|
2009-11-04 19:08:08 +00:00
|
|
|
case 'L': /* Li = read the library name of the footprint */
|
2007-08-06 02:02:39 +00:00
|
|
|
*BufLine = 0;
|
|
|
|
sscanf( PtLine, " %s", BufLine );
|
2011-02-28 18:36:19 +00:00
|
|
|
m_LibRef = FROM_UTF8( BufLine );
|
2007-08-06 02:02:39 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'S':
|
|
|
|
sscanf( PtLine, " %lX", &m_TimeStamp );
|
|
|
|
break;
|
2008-02-19 00:30:10 +00:00
|
|
|
|
2007-08-06 02:02:39 +00:00
|
|
|
|
2009-11-04 19:08:08 +00:00
|
|
|
case 'O': /* (Op)tions for auto placement */
|
2007-08-06 02:02:39 +00:00
|
|
|
itmp1 = itmp2 = 0;
|
|
|
|
sscanf( PtLine, " %X %X", &itmp1, &itmp2 );
|
|
|
|
|
|
|
|
m_CntRot180 = itmp2 & 0x0F;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2007-08-06 02:02:39 +00:00
|
|
|
if( m_CntRot180 > 10 )
|
|
|
|
m_CntRot180 = 10;
|
|
|
|
|
|
|
|
m_CntRot90 = itmp1 & 0x0F;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2007-08-06 02:02:39 +00:00
|
|
|
if( m_CntRot90 > 10 )
|
|
|
|
m_CntRot90 = 0;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2007-08-06 02:02:39 +00:00
|
|
|
itmp1 = (itmp1 >> 4) & 0x0F;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2007-08-06 02:02:39 +00:00
|
|
|
if( itmp1 > 10 )
|
|
|
|
itmp1 = 0;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2007-08-06 02:02:39 +00:00
|
|
|
m_CntRot90 |= itmp1 << 4;
|
|
|
|
break;
|
|
|
|
|
2008-02-19 00:30:10 +00:00
|
|
|
case 'A':
|
2008-03-15 10:24:32 +00:00
|
|
|
if( Line[1] == 't' )
|
|
|
|
{
|
2009-11-04 19:08:08 +00:00
|
|
|
/* At = (At)tributes of module */
|
2008-02-19 00:30:10 +00:00
|
|
|
if( strstr( PtLine, "SMD" ) )
|
|
|
|
m_Attributs |= MOD_CMS;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2008-02-19 00:30:10 +00:00
|
|
|
if( strstr( PtLine, "VIRTUAL" ) )
|
|
|
|
m_Attributs |= MOD_VIRTUAL;
|
|
|
|
}
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2008-03-15 10:24:32 +00:00
|
|
|
if( Line[1] == 'R' )
|
|
|
|
{
|
2009-11-12 15:43:38 +00:00
|
|
|
// alternate reference, e.g. /478C2408/478AD1B6
|
2008-02-19 00:30:10 +00:00
|
|
|
sscanf( PtLine, " %s", BufLine );
|
2011-02-28 18:36:19 +00:00
|
|
|
m_Path = FROM_UTF8( BufLine );
|
2008-02-19 00:30:10 +00:00
|
|
|
}
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2007-08-06 02:02:39 +00:00
|
|
|
break;
|
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
case 'T': /* Read a footprint text description (ref, value, or
|
|
|
|
* drawing */
|
2009-11-04 19:08:08 +00:00
|
|
|
TEXTE_MODULE * textm;
|
2007-08-06 02:02:39 +00:00
|
|
|
sscanf( Line + 1, "%d", &itmp1 );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2007-08-06 02:02:39 +00:00
|
|
|
if( itmp1 == TEXT_is_REFERENCE )
|
2008-12-04 04:28:11 +00:00
|
|
|
textm = m_Reference;
|
2007-08-06 02:02:39 +00:00
|
|
|
else if( itmp1 == TEXT_is_VALUE )
|
2008-12-04 04:28:11 +00:00
|
|
|
textm = m_Value;
|
2007-08-06 02:02:39 +00:00
|
|
|
else /* text is a drawing */
|
|
|
|
{
|
2008-12-04 04:28:11 +00:00
|
|
|
textm = new TEXTE_MODULE( this );
|
|
|
|
m_Drawings.PushBack( textm );
|
2007-08-06 02:02:39 +00:00
|
|
|
}
|
2011-01-14 17:43:30 +00:00
|
|
|
textm->ReadDescr( aReader );
|
2007-08-06 02:02:39 +00:00
|
|
|
break;
|
|
|
|
|
2009-11-04 19:08:08 +00:00
|
|
|
case 'D': /* read a drawing item */
|
|
|
|
EDGE_MODULE * edge;
|
2008-12-04 04:28:11 +00:00
|
|
|
edge = new EDGE_MODULE( this );
|
|
|
|
m_Drawings.PushBack( edge );
|
2011-01-14 17:43:30 +00:00
|
|
|
edge->ReadDescr( aReader );
|
2008-12-04 04:28:11 +00:00
|
|
|
edge->SetDrawCoord();
|
2007-08-06 02:02:39 +00:00
|
|
|
break;
|
|
|
|
|
2009-11-04 19:08:08 +00:00
|
|
|
case 'C': /* read documentation data */
|
2011-02-28 18:36:19 +00:00
|
|
|
m_Doc = FROM_UTF8( StrPurge( PtLine ) );
|
2007-08-06 02:02:39 +00:00
|
|
|
break;
|
|
|
|
|
2009-11-04 19:08:08 +00:00
|
|
|
case 'K': /* Read key words */
|
2011-02-28 18:36:19 +00:00
|
|
|
m_KeyWord = FROM_UTF8( StrPurge( PtLine ) );
|
2007-08-06 02:02:39 +00:00
|
|
|
break;
|
|
|
|
|
2009-11-04 19:08:08 +00:00
|
|
|
case '.': /* Read specific data */
|
2010-07-20 10:30:40 +00:00
|
|
|
if( strnicmp( Line, ".SolderMask ", 12 ) == 0 )
|
|
|
|
m_LocalSolderMaskMargin = atoi( Line + 12 );
|
|
|
|
else if( strnicmp( Line, ".SolderPaste ", 13 ) == 0 )
|
|
|
|
m_LocalSolderPasteMargin = atoi( Line + 13 );
|
|
|
|
else if( strnicmp( Line, ".SolderPasteRatio ", 18 ) == 0 )
|
|
|
|
m_LocalSolderPasteMarginRatio = atof( Line + 18 );
|
|
|
|
else if( strnicmp( Line, ".LocalClearance ", 16 ) == 0 )
|
|
|
|
m_LocalClearance = atoi( Line + 16 );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2010-07-20 10:30:40 +00:00
|
|
|
break;
|
2009-11-04 19:08:08 +00:00
|
|
|
|
2007-08-06 02:02:39 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-07-20 10:30:40 +00:00
|
|
|
|
2008-03-10 08:14:20 +00:00
|
|
|
/* Recalculate the bounding box */
|
2011-09-07 19:41:04 +00:00
|
|
|
CalculateBoundingBox();
|
2007-08-06 02:02:39 +00:00
|
|
|
return 0;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-06 02:02:39 +00:00
|
|
|
|
2011-09-07 19:41:04 +00:00
|
|
|
void MODULE::CalculateBoundingBox()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2011-09-01 21:39:38 +00:00
|
|
|
m_BoundaryBox = GetFootPrintRect();
|
|
|
|
m_Surface = ABS( (double) m_BoundaryBox.GetWidth() * m_BoundaryBox.GetHeight() );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-29 19:33:07 +00:00
|
|
|
EDA_RECT MODULE::GetFootPrintRect() const
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2011-03-29 19:33:07 +00:00
|
|
|
EDA_RECT area;
|
2007-08-06 02:02:39 +00:00
|
|
|
|
2010-12-10 19:47:44 +00:00
|
|
|
area.m_Pos = m_Pos;
|
|
|
|
area.SetEnd( m_Pos );
|
|
|
|
area.Inflate( 500 ); // Give a min size
|
|
|
|
|
|
|
|
for( EDGE_MODULE* edge = (EDGE_MODULE*) m_Drawings.GetFirst(); edge; edge = edge->Next() )
|
2011-09-01 22:11:54 +00:00
|
|
|
if( edge->Type() == TYPE_EDGE_MODULE )
|
2011-09-01 21:39:38 +00:00
|
|
|
area.Merge( edge->GetBoundingBox() );
|
2007-08-06 02:02:39 +00:00
|
|
|
|
2008-11-24 06:53:43 +00:00
|
|
|
for( D_PAD* pad = m_Pads; pad; pad = pad->Next() )
|
2010-12-10 19:47:44 +00:00
|
|
|
area.Merge( pad->GetBoundingBox() );
|
2007-08-06 02:02:39 +00:00
|
|
|
|
2010-12-10 19:47:44 +00:00
|
|
|
return area;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-29 19:33:07 +00:00
|
|
|
EDA_RECT MODULE::GetBoundingBox() const
|
2008-03-13 10:08:42 +00:00
|
|
|
{
|
2011-03-29 19:33:07 +00:00
|
|
|
EDA_RECT area = GetFootPrintRect();
|
2008-03-15 10:24:32 +00:00
|
|
|
|
2011-09-01 22:11:54 +00:00
|
|
|
// Calculate extended area including text fields
|
2011-09-01 21:39:38 +00:00
|
|
|
area.Merge( m_Reference->GetBoundingBox() );
|
|
|
|
area.Merge( m_Value->GetBoundingBox() );
|
2008-03-13 21:18:05 +00:00
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
// Add the Clearance shape size: (shape around the pads when the
|
|
|
|
// clearance is shown. Not optimized, but the draw cost is small
|
|
|
|
// (perhaps smaller than optimization).
|
2009-10-21 19:16:25 +00:00
|
|
|
int biggest_clearance = GetBoard()->GetBiggestClearanceValue();
|
2009-11-04 19:08:08 +00:00
|
|
|
area.Inflate( biggest_clearance );
|
2008-03-18 11:53:52 +00:00
|
|
|
|
2008-03-15 10:24:32 +00:00
|
|
|
return area;
|
2008-03-13 10:08:42 +00:00
|
|
|
}
|
|
|
|
|
2008-03-15 10:24:32 +00:00
|
|
|
|
2010-12-08 20:12:46 +00:00
|
|
|
/* Virtual function, from EDA_ITEM.
|
2009-01-31 21:42:05 +00:00
|
|
|
* display module info on MsgPanel
|
2009-11-04 19:08:08 +00:00
|
|
|
*/
|
2011-01-21 19:30:59 +00:00
|
|
|
void MODULE::DisplayInfo( EDA_DRAW_FRAME* frame )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-06 02:02:39 +00:00
|
|
|
int nbpad;
|
|
|
|
char bufcar[512], Line[512];
|
2011-09-07 19:41:04 +00:00
|
|
|
bool flag = false;
|
2007-08-06 02:02:39 +00:00
|
|
|
wxString msg;
|
2010-01-31 20:01:46 +00:00
|
|
|
BOARD* board = GetBoard();
|
2007-08-06 02:02:39 +00:00
|
|
|
|
2009-10-16 17:18:23 +00:00
|
|
|
frame->EraseMsgBox();
|
2010-12-10 19:47:44 +00:00
|
|
|
|
2007-08-06 02:02:39 +00:00
|
|
|
if( frame->m_Ident != PCB_FRAME )
|
2011-09-07 19:41:04 +00:00
|
|
|
flag = true;
|
2009-10-11 13:04:47 +00:00
|
|
|
|
2010-12-10 19:47:44 +00:00
|
|
|
frame->AppendMsgPanel( m_Reference->m_Text, m_Value->m_Text, DARKCYAN );
|
2007-08-06 02:02:39 +00:00
|
|
|
|
2009-10-11 13:04:47 +00:00
|
|
|
if( flag ) // Display last date the component was edited( useful in Module Editor)
|
2007-08-06 02:02:39 +00:00
|
|
|
{
|
2008-10-29 15:26:53 +00:00
|
|
|
time_t edit_time = m_LastEdit_Time;
|
|
|
|
strcpy( Line, ctime( &edit_time ) );
|
2007-08-06 02:02:39 +00:00
|
|
|
strtok( Line, " \n\r" );
|
|
|
|
strcpy( bufcar, strtok( NULL, " \n\r" ) ); strcat( bufcar, " " );
|
|
|
|
strcat( bufcar, strtok( NULL, " \n\r" ) ); strcat( bufcar, ", " );
|
|
|
|
strtok( NULL, " \n\r" );
|
|
|
|
strcat( bufcar, strtok( NULL, " \n\r" ) );
|
2011-02-28 18:36:19 +00:00
|
|
|
msg = FROM_UTF8( bufcar );
|
2009-10-16 17:18:23 +00:00
|
|
|
frame->AppendMsgPanel( _( "Last Change" ), msg, BROWN );
|
2007-08-06 02:02:39 +00:00
|
|
|
}
|
2009-11-12 15:43:38 +00:00
|
|
|
else // display time stamp in schematic
|
2007-08-06 02:02:39 +00:00
|
|
|
{
|
|
|
|
msg.Printf( wxT( "%8.8lX" ), m_TimeStamp );
|
2009-10-16 17:18:23 +00:00
|
|
|
frame->AppendMsgPanel( _( "Netlist path" ), m_Path, BROWN );
|
2007-08-06 02:02:39 +00:00
|
|
|
}
|
|
|
|
|
2009-10-16 17:18:23 +00:00
|
|
|
frame->AppendMsgPanel( _( "Layer" ), board->GetLayerName( m_Layer ), RED );
|
2007-08-06 02:02:39 +00:00
|
|
|
|
2010-12-08 20:12:46 +00:00
|
|
|
EDA_ITEM* PtStruct = m_Pads;
|
2007-08-06 02:02:39 +00:00
|
|
|
nbpad = 0;
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2007-08-06 02:02:39 +00:00
|
|
|
while( PtStruct )
|
|
|
|
{
|
2008-02-19 00:30:10 +00:00
|
|
|
nbpad++;
|
2008-11-24 06:53:43 +00:00
|
|
|
PtStruct = PtStruct->Next();
|
2007-08-06 02:02:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
msg.Printf( wxT( "%d" ), nbpad );
|
2009-10-16 17:18:23 +00:00
|
|
|
frame->AppendMsgPanel( _( "Pads" ), msg, BLUE );
|
2007-08-06 02:02:39 +00:00
|
|
|
|
2009-11-04 19:08:08 +00:00
|
|
|
msg = wxT( ".." );
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2007-09-09 02:27:56 +00:00
|
|
|
if( IsLocked() )
|
2007-09-21 10:38:50 +00:00
|
|
|
msg[0] = 'L';
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2007-08-06 02:02:39 +00:00
|
|
|
if( m_ModuleStatus & MODULE_is_PLACED )
|
|
|
|
msg[1] = 'P';
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2009-10-16 17:18:23 +00:00
|
|
|
frame->AppendMsgPanel( _( "Stat" ), msg, MAGENTA );
|
2007-08-06 02:02:39 +00:00
|
|
|
|
|
|
|
msg.Printf( wxT( "%.1f" ), (float) m_Orient / 10 );
|
2009-10-16 17:18:23 +00:00
|
|
|
frame->AppendMsgPanel( _( "Orient" ), msg, BROWN );
|
2007-08-06 02:02:39 +00:00
|
|
|
|
2009-10-16 17:18:23 +00:00
|
|
|
frame->AppendMsgPanel( _( "Module" ), m_LibRef, BLUE );
|
2007-08-06 02:02:39 +00:00
|
|
|
|
2009-08-04 18:21:32 +00:00
|
|
|
if( m_3D_Drawings != NULL )
|
|
|
|
msg = m_3D_Drawings->m_Shape3DName;
|
|
|
|
else
|
2009-11-04 19:08:08 +00:00
|
|
|
msg = _( "No 3D shape" );
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2009-10-16 17:18:23 +00:00
|
|
|
frame->AppendMsgPanel( _( "3D-Shape" ), msg, RED );
|
2007-08-06 02:02:39 +00:00
|
|
|
|
|
|
|
wxString doc = _( "Doc: " ) + m_Doc;
|
|
|
|
wxString keyword = _( "KeyW: " ) + m_KeyWord;
|
2009-10-16 17:18:23 +00:00
|
|
|
frame->AppendMsgPanel( doc, keyword, BLACK );
|
2007-08-06 02:02:39 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-08-06 02:02:39 +00:00
|
|
|
|
2011-09-01 21:39:38 +00:00
|
|
|
bool MODULE::HitTest( const wxPoint& aRefPos )
|
2007-08-08 03:50:44 +00:00
|
|
|
{
|
2011-09-01 21:39:38 +00:00
|
|
|
if( m_BoundaryBox.Contains( aRefPos ) )
|
2007-08-08 03:50:44 +00:00
|
|
|
return true;
|
2007-09-09 02:27:56 +00:00
|
|
|
|
2007-08-08 03:50:44 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-01 21:39:38 +00:00
|
|
|
bool MODULE::HitTest( EDA_RECT& aRefArea )
|
2008-01-06 12:43:57 +00:00
|
|
|
{
|
2011-09-01 21:39:38 +00:00
|
|
|
if( m_BoundaryBox.m_Pos.x < aRefArea.GetX() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if( m_BoundaryBox.m_Pos.y < aRefArea.GetY() )
|
|
|
|
return false;
|
2008-01-06 12:43:57 +00:00
|
|
|
|
2011-09-01 21:39:38 +00:00
|
|
|
if( m_BoundaryBox.GetRight() > aRefArea.GetRight() )
|
|
|
|
return false;
|
2008-01-06 12:43:57 +00:00
|
|
|
|
2011-09-01 21:39:38 +00:00
|
|
|
if( m_BoundaryBox.GetBottom() > aRefArea.GetBottom() )
|
|
|
|
return false;
|
2008-01-06 12:43:57 +00:00
|
|
|
|
2011-09-01 21:39:38 +00:00
|
|
|
return true;
|
2008-01-06 12:43:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-04 04:22:27 +00:00
|
|
|
D_PAD* MODULE::FindPadByName( const wxString& aPadName ) const
|
|
|
|
{
|
|
|
|
wxString buf;
|
|
|
|
|
2008-03-15 10:24:32 +00:00
|
|
|
for( D_PAD* pad = m_Pads; pad; pad = pad->Next() )
|
2008-03-04 04:22:27 +00:00
|
|
|
{
|
|
|
|
pad->ReturnStringPadName( buf );
|
|
|
|
#if 1
|
|
|
|
if( buf.CmpNoCase( aPadName ) == 0 ) // why case insensitive?
|
|
|
|
#else
|
|
|
|
if( buf == aPadName )
|
|
|
|
#endif
|
|
|
|
return pad;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-19 00:30:10 +00:00
|
|
|
// see class_module.h
|
|
|
|
SEARCH_RESULT MODULE::Visit( INSPECTOR* inspector, const void* testData,
|
2008-03-15 10:24:32 +00:00
|
|
|
const KICAD_T scanTypes[] )
|
2007-08-09 21:15:08 +00:00
|
|
|
{
|
2008-03-15 10:24:32 +00:00
|
|
|
KICAD_T stype;
|
|
|
|
SEARCH_RESULT result = SEARCH_CONTINUE;
|
|
|
|
const KICAD_T* p = scanTypes;
|
|
|
|
bool done = false;
|
2008-02-19 00:30:10 +00:00
|
|
|
|
2009-11-04 19:08:08 +00:00
|
|
|
#if 0 && defined(DEBUG)
|
2008-03-15 10:24:32 +00:00
|
|
|
std::cout << GetClass().mb_str() << ' ';
|
2008-02-19 00:30:10 +00:00
|
|
|
#endif
|
2007-08-09 21:15:08 +00:00
|
|
|
|
2007-08-24 03:40:04 +00:00
|
|
|
while( !done )
|
2007-08-09 21:15:08 +00:00
|
|
|
{
|
2007-08-24 03:40:04 +00:00
|
|
|
stype = *p;
|
2008-03-15 10:24:32 +00:00
|
|
|
|
2007-08-09 21:15:08 +00:00
|
|
|
switch( stype )
|
|
|
|
{
|
2008-12-04 04:28:11 +00:00
|
|
|
case TYPE_MODULE:
|
2007-08-09 21:15:08 +00:00
|
|
|
result = inspector->Inspect( this, testData ); // inspect me
|
2007-08-24 03:40:04 +00:00
|
|
|
++p;
|
2007-08-09 21:15:08 +00:00
|
|
|
break;
|
2008-02-19 00:30:10 +00:00
|
|
|
|
2008-12-04 04:28:11 +00:00
|
|
|
case TYPE_PAD:
|
2007-08-24 03:40:04 +00:00
|
|
|
result = IterateForward( m_Pads, inspector, testData, p );
|
|
|
|
++p;
|
2007-08-09 21:15:08 +00:00
|
|
|
break;
|
2008-02-19 00:30:10 +00:00
|
|
|
|
2008-12-04 04:28:11 +00:00
|
|
|
case TYPE_TEXTE_MODULE:
|
2007-08-09 21:15:08 +00:00
|
|
|
result = inspector->Inspect( m_Reference, testData );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2007-08-09 21:15:08 +00:00
|
|
|
if( result == SEARCH_QUIT )
|
|
|
|
break;
|
2008-02-19 00:30:10 +00:00
|
|
|
|
2007-08-09 21:15:08 +00:00
|
|
|
result = inspector->Inspect( m_Value, testData );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2007-08-09 21:15:08 +00:00
|
|
|
if( result == SEARCH_QUIT )
|
|
|
|
break;
|
|
|
|
|
2009-11-04 19:08:08 +00:00
|
|
|
// m_Drawings can hold TYPETEXTMODULE also, so fall thru
|
2008-02-19 00:30:10 +00:00
|
|
|
|
2008-12-04 04:28:11 +00:00
|
|
|
case TYPE_EDGE_MODULE:
|
2007-08-24 03:40:04 +00:00
|
|
|
result = IterateForward( m_Drawings, inspector, testData, p );
|
2008-03-15 10:24:32 +00:00
|
|
|
|
2007-08-24 03:40:04 +00:00
|
|
|
// skip over any types handled in the above call.
|
2008-03-15 10:24:32 +00:00
|
|
|
for( ; ; )
|
2007-08-24 03:40:04 +00:00
|
|
|
{
|
|
|
|
switch( stype = *++p )
|
|
|
|
{
|
2008-12-04 04:28:11 +00:00
|
|
|
case TYPE_TEXTE_MODULE:
|
|
|
|
case TYPE_EDGE_MODULE:
|
2007-08-24 03:40:04 +00:00
|
|
|
continue;
|
2008-03-15 10:24:32 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
;
|
2007-08-24 03:40:04 +00:00
|
|
|
}
|
2008-03-15 10:24:32 +00:00
|
|
|
|
2007-08-24 03:40:04 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-03-15 10:24:32 +00:00
|
|
|
|
2007-08-09 21:15:08 +00:00
|
|
|
break;
|
2008-02-19 00:30:10 +00:00
|
|
|
|
2007-08-09 21:15:08 +00:00
|
|
|
default:
|
2007-08-24 03:40:04 +00:00
|
|
|
done = true;
|
2007-08-09 21:15:08 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-02-19 00:30:10 +00:00
|
|
|
|
2007-08-09 21:15:08 +00:00
|
|
|
if( result == SEARCH_QUIT )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-02-19 00:30:10 +00:00
|
|
|
return result;
|
2007-08-09 21:15:08 +00:00
|
|
|
}
|
|
|
|
|
2007-08-08 03:50:44 +00:00
|
|
|
|
2011-07-14 15:42:44 +00:00
|
|
|
wxString MODULE::GetSelectMenuText() const
|
|
|
|
{
|
|
|
|
wxString text;
|
|
|
|
|
|
|
|
text << _( "Footprint" ) << wxT( " " ) << GetReference();
|
|
|
|
text << wxT( " (" ) << GetLayerName() << wxT( ")" );
|
|
|
|
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-04 19:08:08 +00:00
|
|
|
#if defined(DEBUG)
|
2008-03-15 10:24:32 +00:00
|
|
|
|
2007-08-06 02:02:39 +00:00
|
|
|
/**
|
|
|
|
* Function Show
|
|
|
|
* is used to output the object tree, currently for debugging only.
|
2008-02-19 00:30:10 +00:00
|
|
|
* @param nestLevel An aid to prettier tree indenting, and is the level
|
2007-08-06 02:02:39 +00:00
|
|
|
* of nesting of this object within the overall tree.
|
|
|
|
* @param os The ostream& to output to.
|
|
|
|
*/
|
|
|
|
void MODULE::Show( int nestLevel, std::ostream& os )
|
|
|
|
{
|
2010-01-31 20:01:46 +00:00
|
|
|
BOARD* board = GetBoard();
|
2008-02-19 00:30:10 +00:00
|
|
|
|
2007-08-06 02:02:39 +00:00
|
|
|
// for now, make it look like XML, expand on this later.
|
2007-08-07 06:21:19 +00:00
|
|
|
NestedSpace( nestLevel, os ) << '<' << GetClass().Lower().mb_str() <<
|
2008-03-15 10:24:32 +00:00
|
|
|
" ref=\"" << m_Reference->m_Text.mb_str() << '"' <<
|
|
|
|
" value=\"" << m_Value->m_Text.mb_str() << '"' <<
|
|
|
|
" layer=\"" << board->GetLayerName( m_Layer ).mb_str() << '"' <<
|
|
|
|
">\n";
|
2007-08-30 22:20:52 +00:00
|
|
|
|
2008-03-15 10:24:32 +00:00
|
|
|
NestedSpace( nestLevel + 1, os ) <<
|
|
|
|
"<boundingBox" << m_BoundaryBox.m_Pos << m_BoundaryBox.m_Size << "/>\n";
|
2007-08-06 02:02:39 +00:00
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
NestedSpace( nestLevel + 1, os ) << "<orientation tenths=\"" << m_Orient
|
|
|
|
<< "\"/>\n";
|
2008-02-19 00:30:10 +00:00
|
|
|
|
2010-12-08 20:12:46 +00:00
|
|
|
EDA_ITEM* p;
|
2007-08-07 06:21:19 +00:00
|
|
|
|
2008-03-15 10:24:32 +00:00
|
|
|
NestedSpace( nestLevel + 1, os ) << "<mpads>\n";
|
2007-08-07 06:21:19 +00:00
|
|
|
p = m_Pads;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2008-11-24 06:53:43 +00:00
|
|
|
for( ; p; p = p->Next() )
|
2008-03-15 10:24:32 +00:00
|
|
|
p->Show( nestLevel + 2, os );
|
|
|
|
|
|
|
|
NestedSpace( nestLevel + 1, os ) << "</mpads>\n";
|
2008-02-19 00:30:10 +00:00
|
|
|
|
2008-03-15 10:24:32 +00:00
|
|
|
NestedSpace( nestLevel + 1, os ) << "<mdrawings>\n";
|
2007-08-06 20:26:59 +00:00
|
|
|
p = m_Drawings;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2008-11-24 06:53:43 +00:00
|
|
|
for( ; p; p = p->Next() )
|
2008-03-15 10:24:32 +00:00
|
|
|
p->Show( nestLevel + 2, os );
|
|
|
|
|
|
|
|
NestedSpace( nestLevel + 1, os ) << "</mdrawings>\n";
|
2008-02-19 00:30:10 +00:00
|
|
|
|
2007-08-06 20:26:59 +00:00
|
|
|
p = m_Son;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2008-11-24 06:53:43 +00:00
|
|
|
for( ; p; p = p->Next() )
|
2007-08-06 02:02:39 +00:00
|
|
|
{
|
2008-03-15 10:24:32 +00:00
|
|
|
p->Show( nestLevel + 1, os );
|
2007-08-06 02:02:39 +00:00
|
|
|
}
|
2008-02-19 00:30:10 +00:00
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
NestedSpace( nestLevel, os ) << "</" << GetClass().Lower().mb_str()
|
|
|
|
<< ">\n";
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2008-03-15 10:24:32 +00:00
|
|
|
|
2007-08-06 02:02:39 +00:00
|
|
|
#endif
|