2011-10-07 14:41:30 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2012-09-28 17:47:41 +00:00
|
|
|
* Copyright (C) 2009 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
2015-12-08 00:37:11 +00:00
|
|
|
* Copyright (C) 1992-2015 KiCad Developers, see AUTHORS.txt for contributors.
|
2011-10-07 14:41:30 +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
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file sch_sheet.cpp
|
|
|
|
* @brief Implementation of SCH_SHEET class.
|
|
|
|
*/
|
2008-02-12 21:12:46 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <class_drawpanel.h>
|
|
|
|
#include <drawtxt.h>
|
|
|
|
#include <trigo.h>
|
|
|
|
#include <richio.h>
|
2015-02-21 09:46:44 +00:00
|
|
|
#include <schframe.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <plot_common.h>
|
|
|
|
#include <kicad_string.h>
|
2013-01-12 17:32:24 +00:00
|
|
|
#include <msgpanel.h>
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2016-01-03 13:58:27 +00:00
|
|
|
#include <class_library.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <sch_sheet.h>
|
|
|
|
#include <sch_sheet_path.h>
|
|
|
|
#include <sch_component.h>
|
|
|
|
#include <class_netlist_object.h>
|
2011-10-12 14:03:43 +00:00
|
|
|
|
|
|
|
|
2011-01-20 16:34:57 +00:00
|
|
|
SCH_SHEET::SCH_SHEET( const wxPoint& pos ) :
|
|
|
|
SCH_ITEM( NULL, SCH_SHEET_T )
|
2008-02-12 21:12:46 +00:00
|
|
|
{
|
2009-11-03 13:26:31 +00:00
|
|
|
m_Layer = LAYER_SHEET;
|
2011-12-08 15:45:01 +00:00
|
|
|
m_pos = pos;
|
|
|
|
m_size = wxSize( MIN_SHEET_WIDTH, MIN_SHEET_HEIGHT );
|
2011-12-12 08:37:05 +00:00
|
|
|
SetTimeStamp( GetNewTimeStamp() );
|
2014-05-16 13:57:53 +00:00
|
|
|
m_sheetNameSize = GetDefaultTextSize();
|
|
|
|
m_fileNameSize = GetDefaultTextSize();
|
2011-12-08 15:45:01 +00:00
|
|
|
m_screen = NULL;
|
2015-02-22 21:25:29 +00:00
|
|
|
m_name.Printf( wxT( "Sheet%8.8lX" ), (long) m_TimeStamp );
|
|
|
|
m_fileName.Printf( wxT( "file%8.8lX.sch" ), (long) m_TimeStamp );
|
2008-02-12 21:12:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-21 15:13:09 +00:00
|
|
|
SCH_SHEET::SCH_SHEET( const SCH_SHEET& aSheet ) :
|
|
|
|
SCH_ITEM( aSheet )
|
|
|
|
{
|
2011-12-08 15:45:01 +00:00
|
|
|
m_pos = aSheet.m_pos;
|
|
|
|
m_size = aSheet.m_size;
|
2010-12-23 13:16:06 +00:00
|
|
|
m_Layer = aSheet.m_Layer;
|
2011-12-12 08:37:05 +00:00
|
|
|
SetTimeStamp( aSheet.m_TimeStamp );
|
2011-12-08 15:45:01 +00:00
|
|
|
m_sheetNameSize = aSheet.m_sheetNameSize;
|
|
|
|
m_fileNameSize = aSheet.m_fileNameSize;
|
|
|
|
m_screen = aSheet.m_screen;
|
|
|
|
m_name = aSheet.m_name;
|
|
|
|
m_fileName = aSheet.m_fileName;
|
2011-03-30 19:26:05 +00:00
|
|
|
m_pins = aSheet.m_pins;
|
2010-12-21 15:13:09 +00:00
|
|
|
|
2011-03-30 19:26:05 +00:00
|
|
|
for( size_t i = 0; i < m_pins.size(); i++ )
|
|
|
|
m_pins[i].SetParent( this );
|
2010-12-21 15:13:09 +00:00
|
|
|
|
2011-12-08 15:45:01 +00:00
|
|
|
if( m_screen )
|
|
|
|
m_screen->IncRefCount();
|
2010-12-21 15:13:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-04 20:46:53 +00:00
|
|
|
SCH_SHEET::~SCH_SHEET()
|
2008-02-12 21:12:46 +00:00
|
|
|
{
|
2012-10-31 20:27:31 +00:00
|
|
|
// wxLogDebug( wxT( "Destroying sheet " ) + m_name );
|
2011-01-23 21:22:42 +00:00
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
// also, look at the associated sheet & its reference count
|
|
|
|
// perhaps it should be deleted also.
|
2011-12-08 15:45:01 +00:00
|
|
|
if( m_screen )
|
2008-02-26 19:19:54 +00:00
|
|
|
{
|
2011-12-08 15:45:01 +00:00
|
|
|
m_screen->DecRefCount();
|
2010-06-24 18:31:43 +00:00
|
|
|
|
2011-12-08 15:45:01 +00:00
|
|
|
if( m_screen->GetRefCount() == 0 )
|
|
|
|
delete m_screen;
|
2008-02-26 19:19:54 +00:00
|
|
|
}
|
2008-02-12 21:12:46 +00:00
|
|
|
}
|
|
|
|
|
2008-02-26 19:19:54 +00:00
|
|
|
|
2012-03-17 14:39:27 +00:00
|
|
|
EDA_ITEM* SCH_SHEET::Clone() const
|
2010-12-21 15:13:09 +00:00
|
|
|
{
|
|
|
|
return new SCH_SHEET( *this );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-20 16:34:57 +00:00
|
|
|
void SCH_SHEET::SetScreen( SCH_SCREEN* aScreen )
|
|
|
|
{
|
2011-12-08 15:45:01 +00:00
|
|
|
if( aScreen == m_screen )
|
2011-01-20 16:34:57 +00:00
|
|
|
return;
|
|
|
|
|
2011-12-08 15:45:01 +00:00
|
|
|
if( m_screen != NULL )
|
2011-01-20 16:34:57 +00:00
|
|
|
{
|
2011-12-08 15:45:01 +00:00
|
|
|
m_screen->DecRefCount();
|
2011-01-20 16:34:57 +00:00
|
|
|
|
2011-12-08 15:45:01 +00:00
|
|
|
if( m_screen->GetRefCount() == 0 )
|
2011-01-20 16:34:57 +00:00
|
|
|
{
|
2011-12-08 15:45:01 +00:00
|
|
|
delete m_screen;
|
|
|
|
m_screen = NULL;
|
2011-01-20 16:34:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-08 15:45:01 +00:00
|
|
|
m_screen = aScreen;
|
2011-01-20 16:34:57 +00:00
|
|
|
|
2011-12-08 15:45:01 +00:00
|
|
|
if( m_screen )
|
|
|
|
m_screen->IncRefCount();
|
2011-01-20 16:34:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int SCH_SHEET::GetScreenCount() const
|
|
|
|
{
|
2011-12-08 15:45:01 +00:00
|
|
|
if( m_screen == NULL )
|
2011-01-20 16:34:57 +00:00
|
|
|
return 0;
|
|
|
|
|
2011-12-08 15:45:01 +00:00
|
|
|
return m_screen->GetRefCount();
|
2011-01-20 16:34:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
bool SCH_SHEET::Save( FILE* aFile ) const
|
2008-04-12 18:39:20 +00:00
|
|
|
{
|
2009-12-02 21:44:03 +00:00
|
|
|
if( fprintf( aFile, "$Sheet\n" ) == EOF
|
|
|
|
|| fprintf( aFile, "S %-4d %-4d %-4d %-4d\n",
|
2011-12-08 15:45:01 +00:00
|
|
|
m_pos.x, m_pos.y, m_size.x, m_size.y ) == EOF )
|
2009-12-02 21:44:03 +00:00
|
|
|
return false;
|
2008-04-12 18:39:20 +00:00
|
|
|
|
2009-11-03 13:26:31 +00:00
|
|
|
//save the unique timestamp, like other schematic parts.
|
2009-12-02 21:44:03 +00:00
|
|
|
if( fprintf( aFile, "U %8.8lX\n", m_TimeStamp ) == EOF )
|
|
|
|
return false;
|
2008-04-12 18:39:20 +00:00
|
|
|
|
2009-11-03 13:26:31 +00:00
|
|
|
/* Save schematic sheetname and filename. */
|
2011-12-08 15:45:01 +00:00
|
|
|
if( !m_name.IsEmpty() )
|
2008-04-12 18:39:20 +00:00
|
|
|
{
|
2011-12-08 15:45:01 +00:00
|
|
|
if( fprintf( aFile, "F0 %s %d\n", EscapedUTF8( m_name ).c_str(),
|
|
|
|
m_sheetNameSize ) == EOF )
|
2009-12-02 21:44:03 +00:00
|
|
|
return false;
|
2008-04-12 18:39:20 +00:00
|
|
|
}
|
|
|
|
|
2011-12-08 15:45:01 +00:00
|
|
|
if( !m_fileName.IsEmpty() )
|
2008-04-12 18:39:20 +00:00
|
|
|
{
|
2011-12-08 15:45:01 +00:00
|
|
|
if( fprintf( aFile, "F1 %s %d\n", EscapedUTF8( m_fileName ).c_str(),
|
|
|
|
m_fileNameSize ) == EOF )
|
2009-12-02 21:44:03 +00:00
|
|
|
return false;
|
2008-04-12 18:39:20 +00:00
|
|
|
}
|
|
|
|
|
2010-06-24 18:31:43 +00:00
|
|
|
/* Save the list of labels in the sheet. */
|
|
|
|
|
2011-03-30 19:26:05 +00:00
|
|
|
BOOST_FOREACH( const SCH_SHEET_PIN& label, m_pins )
|
2008-04-12 18:39:20 +00:00
|
|
|
{
|
2010-06-24 18:31:43 +00:00
|
|
|
if( !label.Save( aFile ) )
|
|
|
|
return false;
|
2008-04-12 18:39:20 +00:00
|
|
|
}
|
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
if( fprintf( aFile, "$EndSheet\n" ) == EOF )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
2008-04-12 18:39:20 +00:00
|
|
|
}
|
|
|
|
|
2008-04-15 19:38:19 +00:00
|
|
|
|
2010-11-10 15:30:12 +00:00
|
|
|
bool SCH_SHEET::Load( LINE_READER& aLine, wxString& aErrorMsg )
|
|
|
|
{
|
2011-03-25 20:07:27 +00:00
|
|
|
int fieldNdx, size;
|
2011-03-30 19:26:05 +00:00
|
|
|
SCH_SHEET_PIN* sheetPin;
|
2010-11-10 15:30:12 +00:00
|
|
|
char* ptcar;
|
|
|
|
|
2016-01-13 02:31:34 +00:00
|
|
|
if( IsRootSheet() )
|
|
|
|
m_number = 1;
|
|
|
|
else
|
|
|
|
m_number = GetRootSheet()->CountSheets();
|
|
|
|
|
2011-12-12 08:37:05 +00:00
|
|
|
SetTimeStamp( GetNewTimeStamp() );
|
2010-11-10 15:30:12 +00:00
|
|
|
|
2010-12-08 20:12:46 +00:00
|
|
|
// sheets are added to the GetDrawItems() like other schematic components.
|
2010-11-10 15:30:12 +00:00
|
|
|
// however, in order to preserve the hierarchy (through m_Parent pointers),
|
|
|
|
// a duplicate of the sheet is added to m_SubSheet array.
|
|
|
|
// must be a duplicate, references just work for a two-layer structure.
|
|
|
|
// this is accomplished through the Sync() function.
|
|
|
|
|
|
|
|
if( ((char*)aLine)[0] == '$' ) // line should be "$Sheet"
|
|
|
|
{
|
|
|
|
if( !aLine.ReadLine() )
|
|
|
|
{
|
2011-06-07 15:29:01 +00:00
|
|
|
aErrorMsg.Printf( wxT( "Read File Error" ) );
|
2010-11-10 15:30:12 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Next line: must be "S xx yy nn mm" with xx, yy = sheet position
|
|
|
|
* ( upper left corner ) et nn,mm = sheet size */
|
|
|
|
if( ( sscanf( &((char*)aLine)[1], "%d %d %d %d",
|
2011-12-08 15:45:01 +00:00
|
|
|
&m_pos.x, &m_pos.y, &m_size.x, &m_size.y ) != 4 )
|
2010-11-10 15:30:12 +00:00
|
|
|
|| ( ((char*)aLine)[0] != 'S' ) )
|
|
|
|
{
|
2015-12-08 00:37:11 +00:00
|
|
|
aErrorMsg.Printf( wxT( " ** Eeschema file sheet error at line %d, aborted\n" ),
|
2010-11-10 15:30:12 +00:00
|
|
|
aLine.LineNumber() );
|
|
|
|
|
2011-02-28 18:36:19 +00:00
|
|
|
aErrorMsg << FROM_UTF8( ((char*)aLine) );
|
2010-11-10 15:30:12 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read fields */
|
|
|
|
for( ; ; ) /* Analysis of lines "Fn" text. */
|
|
|
|
{
|
|
|
|
if( !aLine.ReadLine() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if( ((char*)aLine)[0] == 'U' )
|
|
|
|
{
|
|
|
|
sscanf( ((char*)aLine) + 1, "%lX", &m_TimeStamp );
|
2016-01-13 02:31:34 +00:00
|
|
|
|
2010-11-10 15:30:12 +00:00
|
|
|
if( m_TimeStamp == 0 ) // zero is not unique!
|
2011-12-12 08:37:05 +00:00
|
|
|
SetTimeStamp( GetNewTimeStamp() );
|
2016-01-13 02:31:34 +00:00
|
|
|
|
2010-11-10 15:30:12 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( ((char*)aLine)[0] != 'F' )
|
|
|
|
break;
|
|
|
|
|
|
|
|
sscanf( ((char*)aLine) + 1, "%d", &fieldNdx );
|
|
|
|
|
|
|
|
/* Read the field:
|
|
|
|
* If fieldNdx> = 2: Fn "text" t s posx posy
|
|
|
|
* If F0 "text" for SheetName
|
|
|
|
* F1 and "text" for filename
|
|
|
|
*/
|
|
|
|
ptcar = ((char*)aLine);
|
2011-12-08 15:45:01 +00:00
|
|
|
|
2010-11-10 15:30:12 +00:00
|
|
|
while( *ptcar && ( *ptcar != '"' ) )
|
|
|
|
ptcar++;
|
|
|
|
|
|
|
|
if( *ptcar != '"' )
|
|
|
|
{
|
2011-09-30 18:15:37 +00:00
|
|
|
aErrorMsg.Printf( wxT( "Eeschema file sheet label F%d at line %d, aborted\n" ),
|
2010-11-10 15:30:12 +00:00
|
|
|
fieldNdx, aLine.LineNumber() );
|
2011-02-28 18:36:19 +00:00
|
|
|
aErrorMsg << FROM_UTF8( (char*) aLine );
|
2010-11-10 15:30:12 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-03-25 20:07:27 +00:00
|
|
|
wxString sheetName;
|
|
|
|
ptcar += ReadDelimitedText( &sheetName, ptcar );
|
2010-11-10 15:30:12 +00:00
|
|
|
|
2011-03-25 20:07:27 +00:00
|
|
|
if( *ptcar == 0 )
|
|
|
|
{
|
2011-09-30 18:15:37 +00:00
|
|
|
aErrorMsg.Printf( wxT( "Eeschema file sheet field F at line %d, aborted\n" ),
|
2011-03-25 20:07:27 +00:00
|
|
|
aLine.LineNumber() );
|
|
|
|
aErrorMsg << FROM_UTF8( (char*) aLine );
|
|
|
|
return false;
|
2010-11-10 15:30:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( ( fieldNdx == 0 ) || ( fieldNdx == 1 ) )
|
|
|
|
{
|
|
|
|
if( sscanf( ptcar, "%d", &size ) != 1 )
|
|
|
|
{
|
2011-09-30 18:15:37 +00:00
|
|
|
aErrorMsg.Printf( wxT( "Eeschema file sheet Label error line %d, aborted\n" ),
|
2010-11-10 15:30:12 +00:00
|
|
|
aLine.LineNumber() );
|
|
|
|
|
2011-02-28 18:36:19 +00:00
|
|
|
aErrorMsg << FROM_UTF8( (char*) aLine );
|
2010-11-10 15:30:12 +00:00
|
|
|
}
|
2011-12-08 15:45:01 +00:00
|
|
|
|
2010-11-10 15:30:12 +00:00
|
|
|
if( size == 0 )
|
2014-05-16 13:57:53 +00:00
|
|
|
size = GetDefaultTextSize();
|
2010-11-10 15:30:12 +00:00
|
|
|
|
|
|
|
if( fieldNdx == 0 )
|
|
|
|
{
|
2011-12-08 15:45:01 +00:00
|
|
|
m_name = sheetName;
|
|
|
|
m_sheetNameSize = size;
|
2010-11-10 15:30:12 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-03-25 20:07:27 +00:00
|
|
|
SetFileName( sheetName );
|
2011-12-08 15:45:01 +00:00
|
|
|
m_fileNameSize = size;
|
2010-11-10 15:30:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( fieldNdx > 1 )
|
|
|
|
{
|
2011-03-30 19:26:05 +00:00
|
|
|
sheetPin = new SCH_SHEET_PIN( this );
|
2010-11-10 15:30:12 +00:00
|
|
|
|
2011-03-30 19:26:05 +00:00
|
|
|
if( !sheetPin->Load( aLine, aErrorMsg ) )
|
2010-11-10 15:30:12 +00:00
|
|
|
{
|
2011-03-30 19:26:05 +00:00
|
|
|
delete sheetPin;
|
|
|
|
sheetPin = NULL;
|
2010-11-10 15:30:12 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-03-30 19:26:05 +00:00
|
|
|
AddPin( sheetPin );
|
2010-11-10 15:30:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( strnicmp( "$End", ((char*)aLine), 4 ) != 0 )
|
|
|
|
{
|
2015-12-08 00:37:11 +00:00
|
|
|
aErrorMsg.Printf( wxT( "**Eeschema file end_sheet error at line %d, aborted\n" ),
|
2010-11-10 15:30:12 +00:00
|
|
|
aLine.LineNumber() );
|
2011-02-28 18:36:19 +00:00
|
|
|
aErrorMsg << FROM_UTF8( ((char*)aLine) );
|
2010-11-10 15:30:12 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-07 15:29:01 +00:00
|
|
|
void SCH_SHEET::SwapData( SCH_ITEM* aItem )
|
2009-12-02 21:44:03 +00:00
|
|
|
{
|
2011-06-07 15:29:01 +00:00
|
|
|
wxCHECK_RET( aItem->Type() == SCH_SHEET_T,
|
|
|
|
wxString::Format( wxT( "SCH_SHEET object cannot swap data with %s object." ),
|
|
|
|
GetChars( aItem->GetClass() ) ) );
|
|
|
|
|
|
|
|
SCH_SHEET* sheet = ( SCH_SHEET* ) aItem;
|
|
|
|
|
2015-06-26 13:41:56 +00:00
|
|
|
std::swap( m_pos, sheet->m_pos );
|
|
|
|
std::swap( m_size, sheet->m_size );
|
|
|
|
std::swap( m_name, sheet->m_name );
|
|
|
|
std::swap( m_sheetNameSize, sheet->m_sheetNameSize );
|
|
|
|
std::swap( m_fileNameSize, sheet->m_fileNameSize );
|
2011-06-07 15:29:01 +00:00
|
|
|
m_pins.swap( sheet->m_pins );
|
2008-03-30 16:15:53 +00:00
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
// Ensure sheet labels have their .m_Parent member pointing really on their
|
2009-11-03 13:26:31 +00:00
|
|
|
// parent, after swapping.
|
2011-03-30 19:26:05 +00:00
|
|
|
BOOST_FOREACH( SCH_SHEET_PIN& sheetPin, m_pins )
|
2010-06-24 18:31:43 +00:00
|
|
|
{
|
|
|
|
sheetPin.SetParent( this );
|
|
|
|
}
|
|
|
|
|
2011-06-07 15:29:01 +00:00
|
|
|
BOOST_FOREACH( SCH_SHEET_PIN& sheetPin, sheet->m_pins )
|
2010-06-24 18:31:43 +00:00
|
|
|
{
|
2011-06-07 15:29:01 +00:00
|
|
|
sheetPin.SetParent( sheet );
|
2010-06-24 18:31:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-30 19:26:05 +00:00
|
|
|
void SCH_SHEET::AddPin( SCH_SHEET_PIN* aSheetPin )
|
2010-06-24 18:31:43 +00:00
|
|
|
{
|
2011-03-30 19:26:05 +00:00
|
|
|
wxASSERT( aSheetPin != NULL );
|
|
|
|
wxASSERT( aSheetPin->Type() == SCH_SHEET_PIN_T );
|
2010-06-24 18:31:43 +00:00
|
|
|
|
2011-03-30 19:26:05 +00:00
|
|
|
m_pins.push_back( aSheetPin );
|
|
|
|
renumberPins();
|
2010-06-24 18:31:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-30 19:26:05 +00:00
|
|
|
void SCH_SHEET::RemovePin( SCH_SHEET_PIN* aSheetPin )
|
2010-06-24 18:31:43 +00:00
|
|
|
{
|
2011-03-30 19:26:05 +00:00
|
|
|
wxASSERT( aSheetPin != NULL );
|
|
|
|
wxASSERT( aSheetPin->Type() == SCH_SHEET_PIN_T );
|
2010-06-24 18:31:43 +00:00
|
|
|
|
2011-03-30 19:26:05 +00:00
|
|
|
SCH_SHEET_PINS::iterator i;
|
2010-06-24 18:31:43 +00:00
|
|
|
|
2011-03-30 19:26:05 +00:00
|
|
|
for( i = m_pins.begin(); i < m_pins.end(); ++i )
|
2008-03-30 16:15:53 +00:00
|
|
|
{
|
2011-03-30 19:26:05 +00:00
|
|
|
if( *i == aSheetPin )
|
2010-06-24 18:31:43 +00:00
|
|
|
{
|
2011-03-30 19:26:05 +00:00
|
|
|
m_pins.erase( i );
|
|
|
|
renumberPins();
|
2010-06-24 18:31:43 +00:00
|
|
|
return;
|
|
|
|
}
|
2008-03-30 16:15:53 +00:00
|
|
|
}
|
2008-04-15 19:38:19 +00:00
|
|
|
|
2010-06-24 18:31:43 +00:00
|
|
|
wxLogDebug( wxT( "Fix me: attempt to remove label %s which is not in sheet %s." ),
|
2014-09-13 18:15:45 +00:00
|
|
|
GetChars( aSheetPin->GetShownText() ), GetChars( m_name ) );
|
2010-06-24 18:31:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-30 19:26:05 +00:00
|
|
|
bool SCH_SHEET::HasPin( const wxString& aName )
|
2010-06-24 18:31:43 +00:00
|
|
|
{
|
2011-03-30 19:26:05 +00:00
|
|
|
BOOST_FOREACH( SCH_SHEET_PIN pin, m_pins )
|
2008-03-30 16:15:53 +00:00
|
|
|
{
|
2013-03-18 19:36:07 +00:00
|
|
|
if( pin.GetText().CmpNoCase( aName ) == 0 )
|
2010-06-24 18:31:43 +00:00
|
|
|
return true;
|
2008-03-30 16:15:53 +00:00
|
|
|
}
|
2010-06-24 18:31:43 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-12-10 19:47:44 +00:00
|
|
|
|
2011-06-17 13:24:22 +00:00
|
|
|
bool SCH_SHEET::IsVerticalOrientation() const
|
2010-09-09 17:37:25 +00:00
|
|
|
{
|
2011-03-30 19:26:05 +00:00
|
|
|
BOOST_FOREACH( SCH_SHEET_PIN pin, m_pins )
|
2010-09-05 17:01:48 +00:00
|
|
|
{
|
2011-03-30 19:26:05 +00:00
|
|
|
if( pin.GetEdge() > 1 )
|
2010-09-09 17:37:25 +00:00
|
|
|
return true;
|
2010-09-05 17:01:48 +00:00
|
|
|
}
|
2010-09-09 17:37:25 +00:00
|
|
|
return false;
|
2010-09-05 17:01:48 +00:00
|
|
|
}
|
|
|
|
|
2010-06-24 18:31:43 +00:00
|
|
|
|
2011-03-30 19:26:05 +00:00
|
|
|
bool SCH_SHEET::HasUndefinedPins()
|
2010-06-24 18:31:43 +00:00
|
|
|
{
|
2011-03-30 19:26:05 +00:00
|
|
|
BOOST_FOREACH( SCH_SHEET_PIN pin, m_pins )
|
2010-06-24 18:31:43 +00:00
|
|
|
{
|
|
|
|
/* Search the schematic for a hierarchical label corresponding to this sheet label. */
|
2011-12-08 15:45:01 +00:00
|
|
|
EDA_ITEM* DrawStruct = m_screen->GetDrawItems();
|
2014-09-13 18:15:45 +00:00
|
|
|
const SCH_HIERLABEL* HLabel = NULL;
|
2010-06-24 18:31:43 +00:00
|
|
|
|
|
|
|
for( ; DrawStruct != NULL; DrawStruct = DrawStruct->Next() )
|
|
|
|
{
|
2010-12-10 19:47:44 +00:00
|
|
|
if( DrawStruct->Type() != SCH_HIERARCHICAL_LABEL_T )
|
2010-06-24 18:31:43 +00:00
|
|
|
continue;
|
|
|
|
|
2014-09-13 18:15:45 +00:00
|
|
|
HLabel = static_cast<SCH_HIERLABEL*>( DrawStruct );
|
2010-06-24 18:31:43 +00:00
|
|
|
|
2013-03-18 19:36:07 +00:00
|
|
|
if( pin.GetText().CmpNoCase( HLabel->GetText() ) == 0 )
|
2010-06-24 18:31:43 +00:00
|
|
|
break; // Found!
|
|
|
|
|
|
|
|
HLabel = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( HLabel == NULL ) // Corresponding hierarchical label not found.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2008-02-12 21:12:46 +00:00
|
|
|
}
|
2008-02-26 19:19:54 +00:00
|
|
|
|
|
|
|
|
2011-06-07 15:29:01 +00:00
|
|
|
int SCH_SHEET::GetMinWidth() const
|
|
|
|
{
|
|
|
|
int width = MIN_SHEET_WIDTH;
|
|
|
|
|
|
|
|
for( size_t i = 0; i < m_pins.size(); i++ )
|
|
|
|
{
|
|
|
|
int edge = m_pins[i].GetEdge();
|
|
|
|
|
|
|
|
// Make sure pin is on right or left side of sheet.
|
|
|
|
if( edge >= 2 )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
EDA_RECT rect = m_pins[i].GetBoundingBox();
|
|
|
|
|
|
|
|
if( width < rect.GetWidth() )
|
|
|
|
width = rect.GetWidth();
|
|
|
|
|
|
|
|
for( size_t j = 0; j < m_pins.size(); j++ )
|
|
|
|
{
|
2013-03-18 19:36:07 +00:00
|
|
|
if( (i == j) || (m_pins[i].GetPosition().y != m_pins[j].GetPosition().y) )
|
2011-06-07 15:29:01 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if( width < rect.GetWidth() + m_pins[j].GetBoundingBox().GetWidth() )
|
|
|
|
{
|
|
|
|
width = rect.GetWidth() + m_pins[j].GetBoundingBox().GetWidth();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return width;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int SCH_SHEET::GetMinHeight() const
|
|
|
|
{
|
|
|
|
int height = MIN_SHEET_HEIGHT;
|
|
|
|
|
|
|
|
for( size_t i = 0; i < m_pins.size(); i++ )
|
|
|
|
{
|
2013-03-18 19:36:07 +00:00
|
|
|
int pinY = m_pins[i].GetPosition().y - m_pos.y;
|
2011-06-07 15:29:01 +00:00
|
|
|
|
|
|
|
if( pinY > height )
|
|
|
|
height = pinY;
|
|
|
|
}
|
|
|
|
|
|
|
|
return height;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-24 18:31:43 +00:00
|
|
|
void SCH_SHEET::CleanupSheet()
|
2009-12-02 21:44:03 +00:00
|
|
|
{
|
2011-03-30 19:26:05 +00:00
|
|
|
SCH_SHEET_PINS::iterator i = m_pins.begin();
|
2008-02-26 19:19:54 +00:00
|
|
|
|
2011-03-30 19:26:05 +00:00
|
|
|
while( i != m_pins.end() )
|
2008-02-26 19:19:54 +00:00
|
|
|
{
|
2010-06-24 18:31:43 +00:00
|
|
|
/* Search the schematic for a hierarchical label corresponding to this sheet label. */
|
2011-12-08 15:45:01 +00:00
|
|
|
EDA_ITEM* DrawStruct = m_screen->GetDrawItems();
|
2014-09-13 18:15:45 +00:00
|
|
|
const SCH_HIERLABEL* HLabel = NULL;
|
2010-06-24 18:31:43 +00:00
|
|
|
|
2008-11-24 06:53:43 +00:00
|
|
|
for( ; DrawStruct != NULL; DrawStruct = DrawStruct->Next() )
|
2008-02-26 19:19:54 +00:00
|
|
|
{
|
2010-12-10 19:47:44 +00:00
|
|
|
if( DrawStruct->Type() != SCH_HIERARCHICAL_LABEL_T )
|
2008-02-26 19:19:54 +00:00
|
|
|
continue;
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2014-09-13 18:15:45 +00:00
|
|
|
HLabel = static_cast<SCH_HIERLABEL*>( DrawStruct );
|
2010-06-24 18:31:43 +00:00
|
|
|
|
2013-03-18 19:36:07 +00:00
|
|
|
if( i->GetText().CmpNoCase( HLabel->GetText() ) == 0 )
|
2009-11-03 13:26:31 +00:00
|
|
|
break; // Found!
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2008-02-26 19:19:54 +00:00
|
|
|
HLabel = NULL;
|
|
|
|
}
|
|
|
|
|
2010-06-24 18:31:43 +00:00
|
|
|
if( HLabel == NULL ) // Hlabel not found: delete sheet label.
|
2015-12-27 12:16:46 +00:00
|
|
|
i = m_pins.erase( i );
|
2010-06-24 18:31:43 +00:00
|
|
|
else
|
|
|
|
++i;
|
2008-02-26 19:19:54 +00:00
|
|
|
}
|
2010-06-24 18:31:43 +00:00
|
|
|
}
|
|
|
|
|
2008-04-30 17:04:22 +00:00
|
|
|
|
2011-03-30 19:26:05 +00:00
|
|
|
SCH_SHEET_PIN* SCH_SHEET::GetPin( const wxPoint& aPosition )
|
2010-06-24 18:31:43 +00:00
|
|
|
{
|
2011-03-30 19:26:05 +00:00
|
|
|
BOOST_FOREACH( SCH_SHEET_PIN& pin, m_pins )
|
2010-06-24 18:31:43 +00:00
|
|
|
{
|
2012-03-15 14:31:16 +00:00
|
|
|
if( pin.HitTest( aPosition, 0 ) )
|
2011-03-30 19:26:05 +00:00
|
|
|
return &pin;
|
2010-06-24 18:31:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
2008-02-12 21:12:46 +00:00
|
|
|
}
|
|
|
|
|
2008-02-26 19:19:54 +00:00
|
|
|
|
2010-12-10 19:47:44 +00:00
|
|
|
int SCH_SHEET::GetPenSize() const
|
2009-06-30 19:21:41 +00:00
|
|
|
{
|
2012-09-28 17:47:41 +00:00
|
|
|
return GetDefaultLineThickness();
|
2009-06-30 19:21:41 +00:00
|
|
|
}
|
|
|
|
|
2009-11-03 13:26:31 +00:00
|
|
|
|
2010-10-20 19:43:58 +00:00
|
|
|
wxPoint SCH_SHEET::GetSheetNamePosition()
|
|
|
|
{
|
2011-12-08 15:45:01 +00:00
|
|
|
wxPoint pos = m_pos;
|
|
|
|
|
2010-10-20 19:43:58 +00:00
|
|
|
if( IsVerticalOrientation() )
|
|
|
|
{
|
|
|
|
pos.x -= 8;
|
2011-12-08 15:45:01 +00:00
|
|
|
pos.y += m_size.y;
|
2010-10-20 19:43:58 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pos.y -= 8;
|
|
|
|
}
|
|
|
|
|
|
|
|
return pos;
|
|
|
|
}
|
|
|
|
|
2010-12-21 15:13:09 +00:00
|
|
|
|
2010-10-20 19:43:58 +00:00
|
|
|
wxPoint SCH_SHEET::GetFileNamePosition()
|
|
|
|
{
|
2011-12-08 15:45:01 +00:00
|
|
|
wxPoint pos = m_pos;
|
2011-05-25 10:42:56 +00:00
|
|
|
int margin = GetPenSize() + 4;
|
|
|
|
|
2010-10-20 19:43:58 +00:00
|
|
|
if( IsVerticalOrientation() )
|
|
|
|
{
|
2011-12-08 15:45:01 +00:00
|
|
|
pos.x += m_size.x + margin;
|
|
|
|
pos.y += m_size.y;
|
2010-10-20 19:43:58 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-12-08 15:45:01 +00:00
|
|
|
pos.y += m_size.y + margin;
|
2010-10-20 19:43:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-21 19:30:59 +00:00
|
|
|
void SCH_SHEET::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC,
|
2012-09-02 12:06:47 +00:00
|
|
|
const wxPoint& aOffset, GR_DRAWMODE aDrawMode, EDA_COLOR_T aColor )
|
2009-12-02 21:44:03 +00:00
|
|
|
{
|
2012-09-02 12:06:47 +00:00
|
|
|
EDA_COLOR_T txtcolor;
|
2008-02-12 21:12:46 +00:00
|
|
|
wxString Text;
|
2012-09-02 12:06:47 +00:00
|
|
|
EDA_COLOR_T color;
|
2010-09-05 17:01:48 +00:00
|
|
|
int name_orientation;
|
|
|
|
wxPoint pos_sheetname,pos_filename;
|
2011-12-08 15:45:01 +00:00
|
|
|
wxPoint pos = m_pos + aOffset;
|
2011-04-29 12:42:04 +00:00
|
|
|
int lineWidth = GetPenSize();
|
2013-06-29 09:52:22 +00:00
|
|
|
EDA_RECT* clipbox = aPanel? aPanel->GetClipBox() : NULL;
|
2008-02-12 21:12:46 +00:00
|
|
|
|
2009-01-04 18:52:57 +00:00
|
|
|
if( aColor >= 0 )
|
|
|
|
color = aColor;
|
2008-02-12 21:12:46 +00:00
|
|
|
else
|
2013-04-04 21:35:01 +00:00
|
|
|
color = GetLayerColor( m_Layer );
|
2010-12-10 19:47:44 +00:00
|
|
|
|
2009-01-04 18:52:57 +00:00
|
|
|
GRSetDrawMode( aDC, aDrawMode );
|
2008-02-12 21:12:46 +00:00
|
|
|
|
2013-06-29 09:52:22 +00:00
|
|
|
GRRect( clipbox, aDC, pos.x, pos.y,
|
2011-12-08 15:45:01 +00:00
|
|
|
pos.x + m_size.x, pos.y + m_size.y, lineWidth, color );
|
2010-10-20 19:43:58 +00:00
|
|
|
|
|
|
|
pos_sheetname = GetSheetNamePosition() + aOffset;
|
|
|
|
pos_filename = GetFileNamePosition() + aOffset;
|
|
|
|
|
2010-09-09 17:37:25 +00:00
|
|
|
if( IsVerticalOrientation() )
|
|
|
|
name_orientation = TEXT_ORIENT_VERT;
|
2010-09-05 17:01:48 +00:00
|
|
|
else
|
2010-09-09 17:37:25 +00:00
|
|
|
name_orientation = TEXT_ORIENT_HORIZ;
|
2010-10-20 19:43:58 +00:00
|
|
|
|
2008-02-12 21:12:46 +00:00
|
|
|
/* Draw text : SheetName */
|
2009-01-04 18:52:57 +00:00
|
|
|
if( aColor > 0 )
|
|
|
|
txtcolor = aColor;
|
2008-02-12 21:12:46 +00:00
|
|
|
else
|
2013-04-04 21:35:01 +00:00
|
|
|
txtcolor = GetLayerColor( LAYER_SHEETNAME );
|
2008-02-12 21:12:46 +00:00
|
|
|
|
2011-12-08 15:45:01 +00:00
|
|
|
Text = wxT( "Sheet: " ) + m_name;
|
2013-06-29 09:52:22 +00:00
|
|
|
DrawGraphicText( clipbox, aDC, pos_sheetname,
|
2015-11-03 19:44:05 +00:00
|
|
|
txtcolor, Text, name_orientation,
|
2011-12-08 15:45:01 +00:00
|
|
|
wxSize( m_sheetNameSize, m_sheetNameSize ),
|
2011-04-29 12:42:04 +00:00
|
|
|
GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_VJUSTIFY_BOTTOM, lineWidth,
|
2010-11-20 19:53:00 +00:00
|
|
|
false, false );
|
2008-02-12 21:12:46 +00:00
|
|
|
|
|
|
|
/* Draw text : FileName */
|
2009-01-04 18:52:57 +00:00
|
|
|
if( aColor >= 0 )
|
|
|
|
txtcolor = aColor;
|
2008-02-12 21:12:46 +00:00
|
|
|
else
|
2013-04-04 21:35:01 +00:00
|
|
|
txtcolor = GetLayerColor( LAYER_SHEETFILENAME );
|
2010-12-10 19:47:44 +00:00
|
|
|
|
2011-12-08 15:45:01 +00:00
|
|
|
Text = wxT( "File: " ) + m_fileName;
|
2013-06-29 09:52:22 +00:00
|
|
|
DrawGraphicText( clipbox, aDC, pos_filename,
|
2015-11-03 19:44:05 +00:00
|
|
|
txtcolor, Text, name_orientation,
|
2011-12-08 15:45:01 +00:00
|
|
|
wxSize( m_fileNameSize, m_fileNameSize ),
|
2011-04-29 12:42:04 +00:00
|
|
|
GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_VJUSTIFY_TOP, lineWidth,
|
2010-11-20 19:53:00 +00:00
|
|
|
false, false );
|
2008-02-12 21:12:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* Draw text : SheetLabel */
|
2011-03-30 19:26:05 +00:00
|
|
|
BOOST_FOREACH( SCH_SHEET_PIN& sheetPin, m_pins )
|
2008-02-12 21:12:46 +00:00
|
|
|
{
|
2011-12-21 13:42:02 +00:00
|
|
|
if( !sheetPin.IsMoving() )
|
2010-06-24 18:31:43 +00:00
|
|
|
sheetPin.Draw( aPanel, aDC, aOffset, aDrawMode, aColor );
|
2008-02-12 21:12:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-15 19:38:19 +00:00
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
const EDA_RECT SCH_SHEET::GetBoundingBox() const
|
2009-12-02 21:44:03 +00:00
|
|
|
{
|
2011-04-29 12:42:04 +00:00
|
|
|
wxPoint end;
|
2011-12-08 15:45:01 +00:00
|
|
|
EDA_RECT box( m_pos, m_size );
|
2011-04-29 12:42:04 +00:00
|
|
|
int lineWidth = GetPenSize();
|
2008-04-15 19:38:19 +00:00
|
|
|
|
2008-03-30 10:14:37 +00:00
|
|
|
// Determine length of texts
|
2011-12-08 15:45:01 +00:00
|
|
|
wxString text = wxT( "Sheet: " ) + m_name;
|
* KIWAY Milestone A): Make major modules into DLL/DSOs.
! The initial testing of this commit should be done using a Debug build so that
all the wxASSERT()s are enabled. Also, be sure and keep enabled the
USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it
off is senseless anyways. If you want stable code, go back to a prior version,
the one tagged with "stable".
* Relocate all functionality out of the wxApp derivative into more finely
targeted purposes:
a) DLL/DSO specific
b) PROJECT specific
c) EXE or process specific
d) configuration file specific data
e) configuration file manipulations functions.
All of this functionality was blended into an extremely large wxApp derivative
and that was incompatible with the desire to support multiple concurrently
loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects.
An amazing amount of organization come from simply sorting each bit of
functionality into the proper box.
* Switch to wxConfigBase from wxConfig everywhere except instantiation.
* Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD,
PGM_SINGLE_TOP,
* Remove "Return" prefix on many function names.
* Remove obvious comments from CMakeLists.txt files, and from else() and endif()s.
* Fix building boost for use in a DSO on linux.
* Remove some of the assumptions in the CMakeLists.txt files that windows had
to be the host platform when building windows binaries.
* Reduce the number of wxStrings being constructed at program load time via
static construction.
* Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that
these functions are useful even when the wxConfigBase comes from another
source, as is the case in the KICAD_MANAGER_FRAME.
* Move the setting of the KIPRJMOD environment variable into class PROJECT,
so that it can be moved into a project variable soon, and out of FP_LIB_TABLE.
* Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all
its child wxFrames and wxDialogs now have a Kiway() member function which
returns a KIWAY& that that window tree branch is in support of. This is like
wxWindows DNA in that child windows get this member with proper value at time
of construction.
* Anticipate some of the needs for milestones B) and C) and make code
adjustments now in an effort to reduce work in those milestones.
* No testing has been done for python scripting, since milestone C) has that
being largely reworked and re-thought-out.
2014-03-20 00:42:08 +00:00
|
|
|
int textlen = GraphicTextWidth( text, m_sheetNameSize, false, lineWidth );
|
2011-12-08 15:45:01 +00:00
|
|
|
text = wxT( "File: " ) + m_fileName;
|
* KIWAY Milestone A): Make major modules into DLL/DSOs.
! The initial testing of this commit should be done using a Debug build so that
all the wxASSERT()s are enabled. Also, be sure and keep enabled the
USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it
off is senseless anyways. If you want stable code, go back to a prior version,
the one tagged with "stable".
* Relocate all functionality out of the wxApp derivative into more finely
targeted purposes:
a) DLL/DSO specific
b) PROJECT specific
c) EXE or process specific
d) configuration file specific data
e) configuration file manipulations functions.
All of this functionality was blended into an extremely large wxApp derivative
and that was incompatible with the desire to support multiple concurrently
loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects.
An amazing amount of organization come from simply sorting each bit of
functionality into the proper box.
* Switch to wxConfigBase from wxConfig everywhere except instantiation.
* Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD,
PGM_SINGLE_TOP,
* Remove "Return" prefix on many function names.
* Remove obvious comments from CMakeLists.txt files, and from else() and endif()s.
* Fix building boost for use in a DSO on linux.
* Remove some of the assumptions in the CMakeLists.txt files that windows had
to be the host platform when building windows binaries.
* Reduce the number of wxStrings being constructed at program load time via
static construction.
* Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that
these functions are useful even when the wxConfigBase comes from another
source, as is the case in the KICAD_MANAGER_FRAME.
* Move the setting of the KIPRJMOD environment variable into class PROJECT,
so that it can be moved into a project variable soon, and out of FP_LIB_TABLE.
* Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all
its child wxFrames and wxDialogs now have a Kiway() member function which
returns a KIWAY& that that window tree branch is in support of. This is like
wxWindows DNA in that child windows get this member with proper value at time
of construction.
* Anticipate some of the needs for milestones B) and C) and make code
adjustments now in an effort to reduce work in those milestones.
* No testing has been done for python scripting, since milestone C) has that
being largely reworked and re-thought-out.
2014-03-20 00:42:08 +00:00
|
|
|
int textlen2 = GraphicTextWidth( text, m_fileNameSize, false, lineWidth );
|
2008-04-15 19:38:19 +00:00
|
|
|
|
2011-04-29 12:42:04 +00:00
|
|
|
// Calculate bounding box X size:
|
2012-09-22 11:19:37 +00:00
|
|
|
textlen = std::max( textlen, textlen2 );
|
|
|
|
end.x = std::max( m_size.x, textlen );
|
2008-04-15 19:38:19 +00:00
|
|
|
|
2011-04-29 12:42:04 +00:00
|
|
|
// Calculate bounding box pos:
|
2011-12-08 15:45:01 +00:00
|
|
|
end.y = m_size.y;
|
|
|
|
end += m_pos;
|
2011-04-29 12:42:04 +00:00
|
|
|
|
|
|
|
// Move upper and lower limits to include texts:
|
// 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
|
|
|
box.SetY( box.GetY() - ( KiROUND( m_sheetNameSize * 1.3 ) + 8 ) );
|
|
|
|
end.y += KiROUND( m_fileNameSize * 1.3 ) + 8;
|
2011-04-29 12:42:04 +00:00
|
|
|
|
|
|
|
box.SetEnd( end );
|
|
|
|
box.Inflate( lineWidth / 2 );
|
2010-06-24 18:31:43 +00:00
|
|
|
|
2008-03-30 10:14:37 +00:00
|
|
|
return box;
|
|
|
|
}
|
2008-02-26 19:19:54 +00:00
|
|
|
|
2009-11-03 13:26:31 +00:00
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
int SCH_SHEET::ComponentCount()
|
|
|
|
{
|
2008-02-26 19:19:54 +00:00
|
|
|
int n = 0;
|
|
|
|
|
2011-12-08 15:45:01 +00:00
|
|
|
if( m_screen )
|
2008-02-26 19:19:54 +00:00
|
|
|
{
|
2010-12-08 20:12:46 +00:00
|
|
|
EDA_ITEM* bs;
|
|
|
|
|
2011-12-08 15:45:01 +00:00
|
|
|
for( bs = m_screen->GetDrawItems(); bs != NULL; bs = bs->Next() )
|
2008-02-26 19:19:54 +00:00
|
|
|
{
|
2010-12-10 19:47:44 +00:00
|
|
|
if( bs->Type() == SCH_COMPONENT_T )
|
2008-02-26 19:19:54 +00:00
|
|
|
{
|
2008-03-20 01:50:21 +00:00
|
|
|
SCH_COMPONENT* Cmp = (SCH_COMPONENT*) bs;
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2013-03-18 19:36:07 +00:00
|
|
|
if( Cmp->GetField( VALUE )->GetText().GetChar( 0 ) != '#' )
|
2008-02-26 19:19:54 +00:00
|
|
|
n++;
|
|
|
|
}
|
2010-12-10 19:47:44 +00:00
|
|
|
|
|
|
|
if( bs->Type() == SCH_SHEET_T )
|
2008-02-26 19:19:54 +00:00
|
|
|
{
|
2009-11-04 20:46:53 +00:00
|
|
|
SCH_SHEET* sheet = (SCH_SHEET*) bs;
|
2008-02-26 19:19:54 +00:00
|
|
|
n += sheet->ComponentCount();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-12-02 21:44:03 +00:00
|
|
|
|
2008-02-26 19:19:54 +00:00
|
|
|
return n;
|
2008-02-12 21:12:46 +00:00
|
|
|
}
|
2008-02-26 19:19:54 +00:00
|
|
|
|
|
|
|
|
2011-01-20 16:34:57 +00:00
|
|
|
bool SCH_SHEET::SearchHierarchy( const wxString& aFilename, SCH_SCREEN** aScreen )
|
2009-12-02 21:44:03 +00:00
|
|
|
{
|
2011-12-08 15:45:01 +00:00
|
|
|
if( m_screen )
|
2008-02-26 19:19:54 +00:00
|
|
|
{
|
2011-12-08 15:45:01 +00:00
|
|
|
EDA_ITEM* item = m_screen->GetDrawItems();
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2011-01-20 16:34:57 +00:00
|
|
|
while( item )
|
2008-02-26 19:19:54 +00:00
|
|
|
{
|
2011-01-20 16:34:57 +00:00
|
|
|
if( item->Type() == SCH_SHEET_T )
|
2008-02-26 19:19:54 +00:00
|
|
|
{
|
2011-01-20 16:34:57 +00:00
|
|
|
SCH_SHEET* sheet = (SCH_SHEET*) item;
|
|
|
|
|
2011-12-08 15:45:01 +00:00
|
|
|
if( sheet->m_screen
|
|
|
|
&& sheet->m_screen->GetFileName().CmpNoCase( aFilename ) == 0 )
|
2008-02-26 19:19:54 +00:00
|
|
|
{
|
2011-12-08 15:45:01 +00:00
|
|
|
*aScreen = sheet->m_screen;
|
2008-02-26 19:19:54 +00:00
|
|
|
return true;
|
|
|
|
}
|
2009-12-02 21:44:03 +00:00
|
|
|
|
2011-01-20 16:34:57 +00:00
|
|
|
if( sheet->SearchHierarchy( aFilename, aScreen ) )
|
2008-02-26 19:19:54 +00:00
|
|
|
return true;
|
|
|
|
}
|
2011-01-20 16:34:57 +00:00
|
|
|
|
|
|
|
item = item->Next();
|
2008-02-26 19:19:54 +00:00
|
|
|
}
|
|
|
|
}
|
2009-12-02 21:44:03 +00:00
|
|
|
|
2008-02-26 19:19:54 +00:00
|
|
|
return false;
|
2008-02-12 21:12:46 +00:00
|
|
|
}
|
2008-02-26 19:19:54 +00:00
|
|
|
|
|
|
|
|
2010-12-08 20:12:46 +00:00
|
|
|
bool SCH_SHEET::Load( SCH_EDIT_FRAME* aFrame )
|
2009-12-02 21:44:03 +00:00
|
|
|
{
|
2008-02-29 12:33:07 +00:00
|
|
|
bool success = true;
|
2008-02-28 19:27:25 +00:00
|
|
|
|
2015-08-06 00:10:52 +00:00
|
|
|
SCH_SCREEN* screen = NULL;
|
2015-12-08 00:37:11 +00:00
|
|
|
|
2011-12-08 15:45:01 +00:00
|
|
|
if( !m_screen )
|
2008-02-26 19:19:54 +00:00
|
|
|
{
|
2015-12-08 00:37:11 +00:00
|
|
|
GetRootSheet()->SearchHierarchy( m_fileName, &screen );
|
2010-12-10 19:47:44 +00:00
|
|
|
|
2008-02-26 19:19:54 +00:00
|
|
|
if( screen )
|
|
|
|
{
|
2011-01-20 16:34:57 +00:00
|
|
|
SetScreen( screen );
|
2008-02-26 19:19:54 +00:00
|
|
|
|
|
|
|
//do not need to load the sub-sheets - this has already been done.
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
SetScreen( new SCH_SCREEN( &aFrame->Kiway() ) );
|
|
|
|
|
2011-12-08 15:45:01 +00:00
|
|
|
success = aFrame->LoadOneEEFile( m_screen, m_fileName );
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2008-02-29 12:33:07 +00:00
|
|
|
if( success )
|
|
|
|
{
|
2011-12-08 15:45:01 +00:00
|
|
|
EDA_ITEM* bs = m_screen->GetDrawItems();
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2008-02-29 12:33:07 +00:00
|
|
|
while( bs )
|
|
|
|
{
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
if( bs->Type() == SCH_SHEET_T )
|
2008-02-29 12:33:07 +00:00
|
|
|
{
|
2009-11-04 20:46:53 +00:00
|
|
|
SCH_SHEET* sheetstruct = (SCH_SHEET*) bs;
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2015-12-08 00:37:11 +00:00
|
|
|
// Set the parent to this sheet. This effectively creates the
|
|
|
|
// schematic sheet hierarchy eliminating the need to keep a
|
|
|
|
// copy of the root sheet in order to generate the hierarchy.
|
|
|
|
sheetstruct->SetParent( this );
|
|
|
|
|
2009-01-04 18:52:57 +00:00
|
|
|
if( !sheetstruct->Load( aFrame ) )
|
2008-02-29 12:33:07 +00:00
|
|
|
success = false;
|
|
|
|
}
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2008-11-24 06:53:43 +00:00
|
|
|
bs = bs->Next();
|
2008-02-29 12:33:07 +00:00
|
|
|
}
|
|
|
|
}
|
2008-02-26 19:19:54 +00:00
|
|
|
}
|
|
|
|
}
|
2009-12-02 21:44:03 +00:00
|
|
|
|
2008-02-28 19:27:25 +00:00
|
|
|
return success;
|
2008-02-12 21:12:46 +00:00
|
|
|
}
|
2008-02-26 19:19:54 +00:00
|
|
|
|
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
int SCH_SHEET::CountSheets()
|
|
|
|
{
|
2008-02-26 19:19:54 +00:00
|
|
|
int count = 1; //1 = this!!
|
|
|
|
|
2011-12-08 15:45:01 +00:00
|
|
|
if( m_screen )
|
2008-02-26 19:19:54 +00:00
|
|
|
{
|
2011-12-08 15:45:01 +00:00
|
|
|
EDA_ITEM* strct = m_screen->GetDrawItems();
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2008-11-24 06:53:43 +00:00
|
|
|
for( ; strct; strct = strct->Next() )
|
2008-02-26 19:19:54 +00:00
|
|
|
{
|
2010-12-10 19:47:44 +00:00
|
|
|
if( strct->Type() == SCH_SHEET_T )
|
2008-02-26 19:19:54 +00:00
|
|
|
{
|
2009-11-04 20:46:53 +00:00
|
|
|
SCH_SHEET* subsheet = (SCH_SHEET*) strct;
|
2009-01-06 20:09:32 +00:00
|
|
|
count += subsheet->CountSheets();
|
2008-02-26 19:19:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-12-08 00:37:11 +00:00
|
|
|
|
2008-02-26 19:19:54 +00:00
|
|
|
return count;
|
2008-02-12 21:12:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-17 13:24:22 +00:00
|
|
|
wxString SCH_SHEET::GetFileName( void ) const
|
2008-02-28 19:27:25 +00:00
|
|
|
{
|
2011-12-08 15:45:01 +00:00
|
|
|
return m_fileName;
|
2008-02-28 19:27:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-01-12 17:32:24 +00:00
|
|
|
void SCH_SHEET::GetMsgPanelInfo( MSG_PANEL_ITEMS& aList )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2014-11-15 19:06:05 +00:00
|
|
|
aList.push_back( MSG_PANEL_ITEM( _( "Sheet Name" ), m_name, CYAN ) );
|
|
|
|
aList.push_back( MSG_PANEL_ITEM( _( "File Name" ), m_fileName, BROWN ) );
|
2015-12-08 00:37:11 +00:00
|
|
|
aList.push_back( MSG_PANEL_ITEM( _( "Path" ), GetHumanReadablePath(), DARKMAGENTA ) );
|
2011-12-08 15:45:01 +00:00
|
|
|
|
2016-01-24 20:46:14 +00:00
|
|
|
if( IsRootSheet() )
|
|
|
|
aList.push_back( MSG_PANEL_ITEM( _( "Hierarchy Type" ),
|
|
|
|
IsComplexHierarchy() ? _( "Complex" ) : _( "Simple" ),
|
|
|
|
GREEN ) );
|
|
|
|
|
2015-12-08 00:37:11 +00:00
|
|
|
#if 1 // Set to 1 to display the sheet time stamp (mainly for test)
|
|
|
|
aList.push_back( MSG_PANEL_ITEM( _( "Time Stamp" ), GetPath(), BLUE ) );
|
2011-01-01 17:28:21 +00:00
|
|
|
#endif
|
2009-04-05 20:49:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-15 14:31:16 +00:00
|
|
|
void SCH_SHEET::Rotate(wxPoint aPosition)
|
2010-09-05 17:01:48 +00:00
|
|
|
{
|
2012-03-15 14:31:16 +00:00
|
|
|
RotatePoint( &m_pos, aPosition, 900 );
|
2011-12-08 15:45:01 +00:00
|
|
|
RotatePoint( &m_size.x, &m_size.y, 900 );
|
2010-09-09 17:37:25 +00:00
|
|
|
|
2011-12-08 15:45:01 +00:00
|
|
|
if( m_size.x < 0 )
|
2010-09-09 17:37:25 +00:00
|
|
|
{
|
2011-12-08 15:45:01 +00:00
|
|
|
m_pos.x += m_size.x;
|
2015-06-26 13:41:56 +00:00
|
|
|
m_size.x = -m_size.x;
|
2010-09-05 17:01:48 +00:00
|
|
|
}
|
2010-09-09 17:37:25 +00:00
|
|
|
|
2011-12-08 15:45:01 +00:00
|
|
|
if( m_size.y < 0 )
|
2010-09-09 17:37:25 +00:00
|
|
|
{
|
2011-12-08 15:45:01 +00:00
|
|
|
m_pos.y += m_size.y;
|
2015-06-26 13:41:56 +00:00
|
|
|
m_size.y = -m_size.y;
|
2010-09-05 17:01:48 +00:00
|
|
|
}
|
2010-09-09 17:37:25 +00:00
|
|
|
|
2011-03-30 19:26:05 +00:00
|
|
|
BOOST_FOREACH( SCH_SHEET_PIN& sheetPin, m_pins )
|
2010-09-05 17:01:48 +00:00
|
|
|
{
|
2012-03-15 14:31:16 +00:00
|
|
|
sheetPin.Rotate( aPosition );
|
2010-09-05 17:01:48 +00:00
|
|
|
}
|
|
|
|
}
|
2010-09-09 17:37:25 +00:00
|
|
|
|
|
|
|
|
2012-03-15 14:31:16 +00:00
|
|
|
void SCH_SHEET::MirrorX( int aXaxis_position )
|
2010-09-05 17:01:48 +00:00
|
|
|
{
|
2015-06-26 13:41:56 +00:00
|
|
|
MIRROR( m_pos.y, aXaxis_position );
|
2011-12-08 15:45:01 +00:00
|
|
|
m_pos.y -= m_size.y;
|
2010-12-10 19:47:44 +00:00
|
|
|
|
2011-03-30 19:26:05 +00:00
|
|
|
BOOST_FOREACH( SCH_SHEET_PIN& sheetPin, m_pins )
|
2010-09-05 17:01:48 +00:00
|
|
|
{
|
2012-03-15 14:31:16 +00:00
|
|
|
sheetPin.MirrorX( aXaxis_position );
|
2010-09-05 17:01:48 +00:00
|
|
|
}
|
|
|
|
}
|
2010-09-09 17:37:25 +00:00
|
|
|
|
|
|
|
|
2012-03-15 14:31:16 +00:00
|
|
|
void SCH_SHEET::MirrorY( int aYaxis_position )
|
2009-07-27 14:32:40 +00:00
|
|
|
{
|
2015-06-26 13:41:56 +00:00
|
|
|
MIRROR( m_pos.x, aYaxis_position );
|
2011-12-08 15:45:01 +00:00
|
|
|
m_pos.x -= m_size.x;
|
2009-07-27 14:32:40 +00:00
|
|
|
|
2011-03-30 19:26:05 +00:00
|
|
|
BOOST_FOREACH( SCH_SHEET_PIN& label, m_pins )
|
2010-06-24 18:31:43 +00:00
|
|
|
{
|
2012-03-15 14:31:16 +00:00
|
|
|
label.MirrorY( aYaxis_position );
|
2010-06-24 18:31:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-28 16:56:09 +00:00
|
|
|
void SCH_SHEET::SetPosition( const wxPoint& aPosition )
|
|
|
|
{
|
|
|
|
// Remember the sheet and all pin sheet positions must be
|
|
|
|
// modified. So use Move function to do that.
|
|
|
|
Move( aPosition - m_pos );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-24 18:31:43 +00:00
|
|
|
|
|
|
|
void SCH_SHEET::Resize( const wxSize& aSize )
|
|
|
|
{
|
2011-12-08 15:45:01 +00:00
|
|
|
if( aSize == m_size )
|
2010-06-24 18:31:43 +00:00
|
|
|
return;
|
|
|
|
|
2011-12-08 15:45:01 +00:00
|
|
|
m_size = aSize;
|
2010-06-24 18:31:43 +00:00
|
|
|
|
|
|
|
/* Move the sheet labels according to the new sheet size. */
|
2011-03-30 19:26:05 +00:00
|
|
|
BOOST_FOREACH( SCH_SHEET_PIN& label, m_pins )
|
2009-07-27 14:32:40 +00:00
|
|
|
{
|
2013-03-18 19:36:07 +00:00
|
|
|
label.ConstrainOnEdge( label.GetPosition() );
|
2009-07-27 14:32:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-21 15:13:09 +00:00
|
|
|
bool SCH_SHEET::Matches( wxFindReplaceData& aSearchData, void* aAuxData, wxPoint* aFindLocation )
|
2010-03-16 18:22:59 +00:00
|
|
|
{
|
2011-12-13 15:37:33 +00:00
|
|
|
wxLogTrace( traceFindItem, wxT( " item " ) + GetSelectMenuText() );
|
2011-12-01 16:49:28 +00:00
|
|
|
|
2011-12-13 15:37:33 +00:00
|
|
|
// Ignore the sheet file name if searching to replace.
|
|
|
|
if( !(aSearchData.GetFlags() & FR_SEARCH_REPLACE)
|
|
|
|
&& SCH_ITEM::Matches( m_fileName, aSearchData ) )
|
2010-10-20 19:43:58 +00:00
|
|
|
{
|
|
|
|
if( aFindLocation )
|
|
|
|
*aFindLocation = GetFileNamePosition();
|
2010-12-10 19:47:44 +00:00
|
|
|
|
2010-10-20 19:43:58 +00:00
|
|
|
return true;
|
|
|
|
}
|
2010-03-16 18:22:59 +00:00
|
|
|
|
2011-12-08 15:45:01 +00:00
|
|
|
if( SCH_ITEM::Matches( m_name, aSearchData ) )
|
2010-10-20 19:43:58 +00:00
|
|
|
{
|
|
|
|
if( aFindLocation )
|
|
|
|
*aFindLocation = GetSheetNamePosition();
|
2010-12-10 19:47:44 +00:00
|
|
|
|
2010-10-20 19:43:58 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2010-03-16 18:22:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-12-21 20:21:15 +00:00
|
|
|
bool SCH_SHEET::Replace( wxFindReplaceData& aSearchData, void* aAuxData )
|
2011-12-13 15:37:33 +00:00
|
|
|
{
|
|
|
|
return EDA_ITEM::Replace( aSearchData, m_name );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-30 19:26:05 +00:00
|
|
|
void SCH_SHEET::renumberPins()
|
2010-06-24 18:31:43 +00:00
|
|
|
{
|
2011-03-30 19:26:05 +00:00
|
|
|
int id = 2;
|
2010-06-24 18:31:43 +00:00
|
|
|
|
2011-03-30 19:26:05 +00:00
|
|
|
BOOST_FOREACH( SCH_SHEET_PIN& pin, m_pins )
|
2010-06-24 18:31:43 +00:00
|
|
|
{
|
2011-03-30 19:26:05 +00:00
|
|
|
pin.SetNumber( id );
|
|
|
|
id++;
|
2010-06-24 18:31:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-03 14:13:15 +00:00
|
|
|
void SCH_SHEET::GetEndPoints( std::vector <DANGLING_END_ITEM>& aItemList )
|
|
|
|
{
|
2011-03-30 19:26:05 +00:00
|
|
|
for( unsigned ii = 0; ii < GetPins().size(); ii++ )
|
2010-11-03 14:13:15 +00:00
|
|
|
{
|
2011-03-30 19:26:05 +00:00
|
|
|
SCH_SHEET_PIN &pinsheet = GetPins()[ii];
|
2010-11-03 14:13:15 +00:00
|
|
|
|
2011-03-30 19:26:05 +00:00
|
|
|
wxCHECK2_MSG( pinsheet.Type() == SCH_SHEET_PIN_T, continue,
|
2010-11-03 14:13:15 +00:00
|
|
|
wxT( "Invalid item in schematic sheet pin list. Bad programmer!" ) );
|
|
|
|
|
|
|
|
pinsheet.GetEndPoints( aItemList );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool SCH_SHEET::IsDanglingStateChanged( std::vector< DANGLING_END_ITEM >& aItemList )
|
|
|
|
{
|
|
|
|
bool currentState = IsDangling();
|
|
|
|
|
2011-03-30 19:26:05 +00:00
|
|
|
BOOST_FOREACH( SCH_SHEET_PIN& pinsheet, GetPins() )
|
2010-11-03 14:13:15 +00:00
|
|
|
{
|
|
|
|
pinsheet.IsDanglingStateChanged( aItemList );
|
|
|
|
}
|
|
|
|
|
|
|
|
return currentState != IsDangling();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool SCH_SHEET::IsDangling() const
|
|
|
|
{
|
|
|
|
// If any hierarchical label in the sheet is dangling, then the sheet is dangling.
|
2011-03-30 19:26:05 +00:00
|
|
|
for( size_t i = 0; i < GetPins().size(); i++ )
|
2010-11-03 14:13:15 +00:00
|
|
|
{
|
2011-03-30 19:26:05 +00:00
|
|
|
if( GetPins()[i].IsDangling() )
|
2010-11-03 14:13:15 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool SCH_SHEET::IsSelectStateChanged( const wxRect& aRect )
|
|
|
|
{
|
|
|
|
bool previousState = IsSelected();
|
|
|
|
|
2011-03-29 19:33:07 +00:00
|
|
|
EDA_RECT boundingBox = GetBoundingBox();
|
2010-11-03 14:13:15 +00:00
|
|
|
|
|
|
|
if( aRect.Intersects( boundingBox ) )
|
2013-03-30 19:55:26 +00:00
|
|
|
SetFlags( SELECTED );
|
2010-11-03 14:13:15 +00:00
|
|
|
else
|
2013-03-30 19:55:26 +00:00
|
|
|
ClearFlags( SELECTED );
|
2010-11-03 14:13:15 +00:00
|
|
|
|
|
|
|
return previousState != IsSelected();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-12-13 16:27:30 +00:00
|
|
|
void SCH_SHEET::GetConnectionPoints( std::vector< wxPoint >& aPoints ) const
|
2010-11-03 14:13:15 +00:00
|
|
|
{
|
2011-03-30 19:26:05 +00:00
|
|
|
for( size_t i = 0; i < GetPins().size(); i++ )
|
2013-03-18 19:36:07 +00:00
|
|
|
aPoints.push_back( GetPins()[i].GetPosition() );
|
2010-11-03 14:13:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-25 19:16:05 +00:00
|
|
|
SEARCH_RESULT SCH_SHEET::Visit( INSPECTOR* aInspector, const void* aTestData,
|
|
|
|
const KICAD_T aFilterTypes[] )
|
2010-12-10 19:47:44 +00:00
|
|
|
{
|
2011-03-25 19:16:05 +00:00
|
|
|
KICAD_T stype;
|
|
|
|
|
|
|
|
for( const KICAD_T* p = aFilterTypes; (stype = *p) != EOT; ++p )
|
|
|
|
{
|
|
|
|
// If caller wants to inspect my type
|
|
|
|
if( stype == Type() )
|
|
|
|
{
|
2011-12-01 16:49:28 +00:00
|
|
|
if( SEARCH_QUIT == aInspector->Inspect( this, NULL ) )
|
2011-03-25 19:16:05 +00:00
|
|
|
return SEARCH_QUIT;
|
|
|
|
}
|
2011-03-30 19:26:05 +00:00
|
|
|
else if( stype == SCH_SHEET_PIN_T )
|
2011-03-25 19:16:05 +00:00
|
|
|
{
|
2011-12-01 16:49:28 +00:00
|
|
|
// Test the sheet labels.
|
2011-03-30 19:26:05 +00:00
|
|
|
for( size_t i = 0; i < m_pins.size(); i++ )
|
2011-03-25 19:16:05 +00:00
|
|
|
{
|
2011-12-01 16:49:28 +00:00
|
|
|
if( SEARCH_QUIT == aInspector->Inspect( &m_pins[ i ], (void*) this ) )
|
2011-03-25 19:16:05 +00:00
|
|
|
return SEARCH_QUIT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return SEARCH_CONTINUE;
|
|
|
|
}
|
2010-12-13 15:59:00 +00:00
|
|
|
|
2011-03-25 19:16:05 +00:00
|
|
|
|
|
|
|
wxString SCH_SHEET::GetSelectMenuText() const
|
|
|
|
{
|
2011-03-26 10:08:50 +00:00
|
|
|
wxString tmp;
|
2011-12-08 15:45:01 +00:00
|
|
|
tmp.Printf( _( "Hierarchical Sheet %s" ), GetChars( m_name ) );
|
2011-03-26 10:08:50 +00:00
|
|
|
return tmp;
|
2011-03-25 19:16:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-15 14:31:16 +00:00
|
|
|
bool SCH_SHEET::HitTest( const wxPoint& aPosition, int aAccuracy ) const
|
2011-03-25 19:16:05 +00:00
|
|
|
{
|
2011-03-29 19:33:07 +00:00
|
|
|
EDA_RECT rect = GetBoundingBox();
|
2010-12-10 19:47:44 +00:00
|
|
|
|
|
|
|
rect.Inflate( aAccuracy );
|
|
|
|
|
2012-03-15 14:31:16 +00:00
|
|
|
return rect.Contains( aPosition );
|
2010-12-10 19:47:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-15 14:31:16 +00:00
|
|
|
bool SCH_SHEET::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
|
2010-12-10 19:47:44 +00:00
|
|
|
{
|
2011-03-29 19:33:07 +00:00
|
|
|
EDA_RECT rect = aRect;
|
2010-12-10 19:47:44 +00:00
|
|
|
|
|
|
|
rect.Inflate( aAccuracy );
|
|
|
|
|
|
|
|
if( aContained )
|
2010-12-20 17:44:25 +00:00
|
|
|
return rect.Contains( GetBoundingBox() );
|
2010-12-10 19:47:44 +00:00
|
|
|
|
|
|
|
return rect.Intersects( GetBoundingBox() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-07 15:29:01 +00:00
|
|
|
wxPoint SCH_SHEET::GetResizePosition() const
|
|
|
|
{
|
2011-12-08 15:45:01 +00:00
|
|
|
return wxPoint( m_pos.x + m_size.GetWidth(), m_pos.y + m_size.GetHeight() );
|
2011-06-07 15:29:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-25 19:09:57 +00:00
|
|
|
void SCH_SHEET::GetNetListItem( NETLIST_OBJECT_LIST& aNetListItems,
|
|
|
|
SCH_SHEET_PATH* aSheetPath )
|
2011-10-12 14:03:43 +00:00
|
|
|
{
|
|
|
|
SCH_SHEET_PATH sheetPath = *aSheetPath;
|
|
|
|
sheetPath.Push( this );
|
|
|
|
|
|
|
|
for( size_t i = 0; i < m_pins.size(); i++ )
|
|
|
|
{
|
|
|
|
NETLIST_OBJECT* item = new NETLIST_OBJECT();
|
2013-09-29 18:24:38 +00:00
|
|
|
item->m_SheetPathInclude = sheetPath;
|
|
|
|
item->m_SheetPath = *aSheetPath;
|
2011-10-12 14:03:43 +00:00
|
|
|
item->m_Comp = &m_pins[i];
|
|
|
|
item->m_Link = this;
|
|
|
|
item->m_Type = NET_SHEETLABEL;
|
2011-12-08 15:45:01 +00:00
|
|
|
item->m_ElectricalType = m_pins[i].GetShape();
|
2013-03-18 19:36:07 +00:00
|
|
|
item->m_Label = m_pins[i].GetText();
|
|
|
|
item->m_Start = item->m_End = m_pins[i].GetPosition();
|
2011-10-12 14:03:43 +00:00
|
|
|
aNetListItems.push_back( item );
|
|
|
|
|
2013-03-18 19:36:07 +00:00
|
|
|
if( IsBusLabel( m_pins[i].GetText() ) )
|
2011-10-12 15:34:52 +00:00
|
|
|
item->ConvertBusToNetListItems( aNetListItems );
|
2011-10-12 14:03:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-15 14:31:16 +00:00
|
|
|
void SCH_SHEET::Plot( PLOTTER* aPlotter )
|
2011-06-17 13:24:22 +00:00
|
|
|
{
|
2012-09-02 12:06:47 +00:00
|
|
|
EDA_COLOR_T txtcolor = UNSPECIFIED_COLOR;
|
2012-03-26 23:47:08 +00:00
|
|
|
wxSize size;
|
|
|
|
wxString Text;
|
|
|
|
int name_orientation;
|
|
|
|
wxPoint pos_sheetname, pos_filename;
|
|
|
|
wxPoint pos;
|
2011-06-17 13:24:22 +00:00
|
|
|
|
2013-04-04 21:35:01 +00:00
|
|
|
aPlotter->SetColor( GetLayerColor( GetLayer() ) );
|
2011-06-17 13:24:22 +00:00
|
|
|
|
|
|
|
int thickness = GetPenSize();
|
2012-05-03 18:37:56 +00:00
|
|
|
aPlotter->SetCurrentLineWidth( thickness );
|
2011-06-17 13:24:22 +00:00
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
aPlotter->MoveTo( m_pos );
|
2011-12-08 15:45:01 +00:00
|
|
|
pos = m_pos;
|
|
|
|
pos.x += m_size.x;
|
2011-06-17 13:24:22 +00:00
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
aPlotter->LineTo( pos );
|
2011-12-08 15:45:01 +00:00
|
|
|
pos.y += m_size.y;
|
2011-06-17 13:24:22 +00:00
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
aPlotter->LineTo( pos );
|
2011-12-08 15:45:01 +00:00
|
|
|
pos = m_pos;
|
|
|
|
pos.y += m_size.y;
|
2011-06-17 13:24:22 +00:00
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
aPlotter->LineTo( pos );
|
|
|
|
aPlotter->FinishTo( m_pos );
|
2011-06-17 13:24:22 +00:00
|
|
|
|
|
|
|
if( IsVerticalOrientation() )
|
|
|
|
{
|
2011-12-08 15:45:01 +00:00
|
|
|
pos_sheetname = wxPoint( m_pos.x - 8, m_pos.y + m_size.y );
|
|
|
|
pos_filename = wxPoint( m_pos.x + m_size.x + 4, m_pos.y + m_size.y );
|
2011-06-17 13:24:22 +00:00
|
|
|
name_orientation = TEXT_ORIENT_VERT;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-12-08 15:45:01 +00:00
|
|
|
pos_sheetname = wxPoint( m_pos.x, m_pos.y - 4 );
|
|
|
|
pos_filename = wxPoint( m_pos.x, m_pos.y + m_size.y + 4 );
|
2011-06-17 13:24:22 +00:00
|
|
|
name_orientation = TEXT_ORIENT_HORIZ;
|
|
|
|
}
|
2011-12-08 15:45:01 +00:00
|
|
|
|
2011-06-17 13:24:22 +00:00
|
|
|
/* Draw texts: SheetName */
|
2011-12-08 15:45:01 +00:00
|
|
|
Text = m_name;
|
|
|
|
size = wxSize( m_sheetNameSize, m_sheetNameSize );
|
2011-06-17 13:24:22 +00:00
|
|
|
|
2012-09-28 17:47:41 +00:00
|
|
|
thickness = GetDefaultLineThickness();
|
2011-06-17 13:24:22 +00:00
|
|
|
thickness = Clamp_Text_PenSize( thickness, size, false );
|
|
|
|
|
2013-04-04 21:35:01 +00:00
|
|
|
aPlotter->SetColor( GetLayerColor( LAYER_SHEETNAME ) );
|
2011-06-17 13:24:22 +00:00
|
|
|
|
|
|
|
bool italic = false;
|
2012-05-03 18:37:56 +00:00
|
|
|
aPlotter->Text( pos_sheetname, txtcolor, Text, name_orientation, size,
|
2011-06-17 13:24:22 +00:00
|
|
|
GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_VJUSTIFY_BOTTOM,
|
|
|
|
thickness, italic, false );
|
|
|
|
|
|
|
|
/*Draw texts : FileName */
|
|
|
|
Text = GetFileName();
|
2011-12-08 15:45:01 +00:00
|
|
|
size = wxSize( m_fileNameSize, m_fileNameSize );
|
2012-09-28 17:47:41 +00:00
|
|
|
thickness = GetDefaultLineThickness();
|
2011-06-17 13:24:22 +00:00
|
|
|
thickness = Clamp_Text_PenSize( thickness, size, false );
|
|
|
|
|
2013-04-04 21:35:01 +00:00
|
|
|
aPlotter->SetColor( GetLayerColor( LAYER_SHEETFILENAME ) );
|
2011-06-17 13:24:22 +00:00
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
aPlotter->Text( pos_filename, txtcolor, Text, name_orientation, size,
|
2011-06-17 13:24:22 +00:00
|
|
|
GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_VJUSTIFY_TOP,
|
|
|
|
thickness, italic, false );
|
|
|
|
|
2013-04-04 21:35:01 +00:00
|
|
|
aPlotter->SetColor( GetLayerColor( GetLayer() ) );
|
2011-06-17 13:24:22 +00:00
|
|
|
|
|
|
|
/* Draw texts : SheetLabel */
|
|
|
|
for( size_t i = 0; i < m_pins.size(); i++ )
|
|
|
|
{
|
|
|
|
m_pins[i].Plot( aPlotter );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-01-24 20:46:14 +00:00
|
|
|
unsigned SCH_SHEET::GetSheets( std::vector<const SCH_SHEET*>& aSheetList ) const
|
|
|
|
{
|
|
|
|
// Sheet pointers must be unique.
|
|
|
|
wxASSERT( find( aSheetList.begin(), aSheetList.end(), this ) == aSheetList.end() );
|
|
|
|
|
|
|
|
aSheetList.push_back( this );
|
|
|
|
|
|
|
|
const SCH_ITEM* item = m_screen->GetDrawItems();
|
|
|
|
|
|
|
|
while( item )
|
|
|
|
{
|
|
|
|
if( item->Type() == SCH_SHEET_T )
|
|
|
|
( (SCH_SHEET*) item )->GetSheets( aSheetList );
|
|
|
|
|
|
|
|
item = item->Next();
|
|
|
|
}
|
|
|
|
|
|
|
|
return aSheetList.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-12-08 00:37:11 +00:00
|
|
|
SCH_SHEET* SCH_SHEET::GetRootSheet()
|
|
|
|
{
|
|
|
|
EDA_ITEM* parent = GetParent();
|
|
|
|
SCH_SHEET* rootSheet = this;
|
|
|
|
|
|
|
|
while( parent )
|
|
|
|
{
|
|
|
|
// The parent of a SCH_SHEET object can only be another SCH_SHEET object or NULL.
|
|
|
|
wxASSERT_MSG( parent->Type() == SCH_SHEET_T, "SCH_SHEET parent is not a SCH_SHEET" );
|
|
|
|
rootSheet = static_cast<SCH_SHEET*>( parent );
|
|
|
|
parent = parent->GetParent();
|
|
|
|
}
|
|
|
|
|
|
|
|
return rootSheet;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_SHEET::GetPath( SCH_CONST_SHEETS& aSheetPath ) const
|
|
|
|
{
|
|
|
|
aSheetPath.insert( aSheetPath.begin(), const_cast<SCH_SHEET*>( this ) );
|
|
|
|
|
|
|
|
if( GetParent() )
|
|
|
|
static_cast<SCH_SHEET*>( GetParent() )->GetPath( aSheetPath );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxString SCH_SHEET::GetPath() const
|
|
|
|
{
|
|
|
|
wxString tmp;
|
|
|
|
wxString path = "/";
|
|
|
|
const SCH_SHEET* sheet = this;
|
|
|
|
|
|
|
|
while( sheet->GetParent() )
|
|
|
|
{
|
|
|
|
tmp.Printf( "/%8.8lX", (long unsigned) sheet->GetTimeStamp() );
|
|
|
|
|
|
|
|
// We are walking up the parent stack so prepend each time stamp.
|
|
|
|
path = tmp + path;
|
|
|
|
sheet = static_cast<SCH_SHEET*>( sheet->GetParent() );
|
|
|
|
}
|
|
|
|
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxString SCH_SHEET::GetHumanReadablePath() const
|
|
|
|
{
|
|
|
|
wxString path = "/";
|
|
|
|
const SCH_SHEET* sheet = this;
|
|
|
|
|
|
|
|
while( sheet->GetParent() )
|
|
|
|
{
|
|
|
|
// We are walking up the parent stack so prepend each sheet name.
|
|
|
|
path = "/" + sheet->GetName() + path;
|
|
|
|
sheet = static_cast<SCH_SHEET*>( sheet->GetParent() );
|
|
|
|
}
|
|
|
|
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-12-12 17:06:24 +00:00
|
|
|
void SCH_SHEET::ClearAnnotation( bool aIncludeSubSheets )
|
|
|
|
{
|
|
|
|
m_screen->ClearAnnotation( this );
|
|
|
|
|
|
|
|
if( aIncludeSubSheets )
|
|
|
|
{
|
|
|
|
SCH_ITEM* item = m_screen->GetDrawItems();
|
|
|
|
|
|
|
|
while( item )
|
|
|
|
{
|
|
|
|
if( item->Type() == SCH_SHEET_T )
|
|
|
|
static_cast<SCH_SHEET*>( item )->ClearAnnotation( aIncludeSubSheets );
|
|
|
|
|
|
|
|
item = item->Next();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-12-17 00:27:53 +00:00
|
|
|
bool SCH_SHEET::IsModified() const
|
|
|
|
{
|
|
|
|
if( m_screen->IsModify() )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
bool retv = false;
|
|
|
|
SCH_ITEM* item = m_screen->GetDrawItems();
|
|
|
|
|
|
|
|
while( item && !retv )
|
|
|
|
{
|
|
|
|
if( item->Type() == SCH_SHEET_T )
|
|
|
|
retv = static_cast<SCH_SHEET*>( item )->IsModified();
|
|
|
|
|
|
|
|
item = item->Next();
|
|
|
|
}
|
|
|
|
|
|
|
|
return retv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-12-20 20:58:18 +00:00
|
|
|
bool SCH_SHEET::IsAutoSaveRequired()
|
|
|
|
{
|
|
|
|
if( m_screen->IsModify() )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
bool retv = false;
|
|
|
|
SCH_ITEM* item = m_screen->GetDrawItems();
|
|
|
|
|
|
|
|
while( item && !retv )
|
|
|
|
{
|
|
|
|
if( item->Type() == SCH_SHEET_T )
|
|
|
|
{
|
|
|
|
SCH_SHEET* sheet = static_cast<SCH_SHEET*>( item );
|
|
|
|
|
|
|
|
if( sheet->m_screen )
|
|
|
|
retv = sheet->m_screen->IsSave();
|
|
|
|
}
|
|
|
|
|
|
|
|
item = item->Next();
|
|
|
|
}
|
|
|
|
|
|
|
|
return retv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-12-17 00:27:53 +00:00
|
|
|
void SCH_SHEET::ClearModifyStatus()
|
|
|
|
{
|
|
|
|
m_screen->ClrModify();
|
|
|
|
|
|
|
|
SCH_ITEM* item = m_screen->GetDrawItems();
|
|
|
|
|
|
|
|
while( item )
|
|
|
|
{
|
|
|
|
if( item->Type() == SCH_SHEET_T )
|
|
|
|
static_cast<SCH_SHEET*>( item )->m_screen->ClrModify();
|
|
|
|
|
|
|
|
item = item->Next();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-01-03 13:58:27 +00:00
|
|
|
void SCH_SHEET::AnnotatePowerSymbols( PART_LIBS* aLibs, int* aReference )
|
|
|
|
{
|
|
|
|
int ref = 1;
|
|
|
|
|
|
|
|
if( aReference )
|
|
|
|
ref = *aReference;
|
|
|
|
|
|
|
|
for( EDA_ITEM* item = m_screen->GetDrawItems(); item; item = item->Next() )
|
|
|
|
{
|
|
|
|
if( item->Type() != SCH_COMPONENT_T )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
SCH_COMPONENT* component = (SCH_COMPONENT*) item;
|
|
|
|
LIB_PART* part = aLibs->FindLibPart( component->GetPartName() );
|
|
|
|
|
|
|
|
if( !part || !part->IsPower() )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
wxString refstr = component->GetPrefix();
|
|
|
|
|
|
|
|
//str will be "C?" or so after the ClearAnnotation call.
|
|
|
|
while( refstr.Last() == '?' )
|
|
|
|
refstr.RemoveLast();
|
|
|
|
|
|
|
|
if( !refstr.StartsWith( wxT( "#" ) ) )
|
|
|
|
refstr = wxT( "#" ) + refstr;
|
|
|
|
|
|
|
|
refstr << wxT( "0" ) << ref;
|
|
|
|
component->SetRef( this, refstr );
|
|
|
|
ref++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( aReference )
|
|
|
|
*aReference = ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-01-07 00:07:30 +00:00
|
|
|
void SCH_SHEET::UpdateAllScreenReferences()
|
|
|
|
{
|
|
|
|
EDA_ITEM* t = m_screen->GetDrawItems();
|
|
|
|
|
|
|
|
while( t )
|
|
|
|
{
|
|
|
|
if( t->Type() == SCH_COMPONENT_T )
|
|
|
|
{
|
|
|
|
SCH_COMPONENT* component = (SCH_COMPONENT*) t;
|
|
|
|
component->GetField( REFERENCE )->SetText( component->GetRef( this ) );
|
|
|
|
component->UpdateUnit( component->GetUnitSelection( this ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
t = t->Next();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-01-13 02:31:34 +00:00
|
|
|
void SCH_SHEET::GetComponents( PART_LIBS* aLibs, SCH_REFERENCE_LIST& aReferences,
|
|
|
|
bool aIncludePowerSymbols, bool aIncludeSubSheets )
|
|
|
|
{
|
|
|
|
for( SCH_ITEM* item = m_screen->GetDrawItems(); item; item = item->Next() )
|
|
|
|
{
|
|
|
|
if( item->Type() == SCH_SHEET_T && aIncludeSubSheets )
|
|
|
|
{
|
|
|
|
((SCH_SHEET*)item)->GetComponents( aLibs, aReferences, aIncludePowerSymbols,
|
|
|
|
aIncludeSubSheets );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( item->Type() == SCH_COMPONENT_T )
|
|
|
|
{
|
|
|
|
SCH_COMPONENT* component = (SCH_COMPONENT*) item;
|
|
|
|
|
|
|
|
// Skip pseudo components, which have a reference starting with #. This mainly
|
|
|
|
// affects power symbols.
|
|
|
|
if( !aIncludePowerSymbols && component->GetRef( this )[0] == wxT( '#' ) )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
LIB_PART* part = aLibs->FindLibPart( component->GetPartName() );
|
|
|
|
|
|
|
|
if( part )
|
|
|
|
{
|
|
|
|
SCH_REFERENCE reference = SCH_REFERENCE( component, part, this );
|
|
|
|
reference.SetSheetNumber( m_number );
|
|
|
|
aReferences.AddItem( reference );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-01-09 20:26:55 +00:00
|
|
|
SCH_ITEM& SCH_SHEET::operator=( const SCH_ITEM& aItem )
|
|
|
|
{
|
|
|
|
wxLogDebug( wxT( "Sheet assignment operator." ) );
|
|
|
|
|
|
|
|
wxCHECK_MSG( Type() == aItem.Type(), *this,
|
|
|
|
wxT( "Cannot assign object type " ) + aItem.GetClass() + wxT( " to type " ) +
|
|
|
|
GetClass() );
|
|
|
|
|
|
|
|
if( &aItem != this )
|
|
|
|
{
|
|
|
|
SCH_ITEM::operator=( aItem );
|
|
|
|
|
|
|
|
SCH_SHEET* sheet = (SCH_SHEET*) &aItem;
|
|
|
|
|
|
|
|
m_pos = sheet->m_pos;
|
|
|
|
m_size = sheet->m_size;
|
|
|
|
m_name = sheet->m_name;
|
|
|
|
m_sheetNameSize = sheet->m_sheetNameSize;
|
|
|
|
m_fileNameSize = sheet->m_fileNameSize;
|
|
|
|
m_pins = sheet->m_pins;
|
|
|
|
|
|
|
|
// Ensure sheet labels have their #m_Parent member pointing really on their
|
|
|
|
// parent, after assigning.
|
|
|
|
BOOST_FOREACH( SCH_SHEET_PIN& sheetPin, m_pins )
|
|
|
|
{
|
|
|
|
sheetPin.SetParent( this );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-01-22 00:01:34 +00:00
|
|
|
void SCH_SHEET::GetMultiUnitComponents( PART_LIBS* aLibs,
|
|
|
|
SCH_MULTI_UNIT_REFERENCE_MAP& aRefList,
|
|
|
|
bool aIncludePowerSymbols )
|
|
|
|
{
|
|
|
|
for( SCH_ITEM* item = m_screen->GetDrawItems(); item; item = item->Next() )
|
|
|
|
{
|
|
|
|
if( item->Type() == SCH_SHEET_T )
|
|
|
|
{
|
|
|
|
( (SCH_SHEET*) item )->GetMultiUnitComponents( aLibs, aRefList, aIncludePowerSymbols );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( item->Type() != SCH_COMPONENT_T )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
SCH_COMPONENT* component = (SCH_COMPONENT*) item;
|
|
|
|
|
|
|
|
// Skip pseudo components, which have a reference starting with #. This mainly
|
|
|
|
// affects power symbols.
|
|
|
|
if( !aIncludePowerSymbols && component->GetRef( this )[0] == wxT( '#' ) )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
LIB_PART* part = aLibs->FindLibPart( component->GetPartName() );
|
|
|
|
|
|
|
|
if( part && part->GetUnitCount() > 1 )
|
|
|
|
{
|
|
|
|
SCH_REFERENCE reference = SCH_REFERENCE( component, part, this );
|
|
|
|
reference.SetSheetNumber( m_number );
|
|
|
|
wxString reference_str = reference.GetRef();
|
|
|
|
|
|
|
|
// Never lock unassigned references
|
|
|
|
if( reference_str[reference_str.Len() - 1] == '?' )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
aRefList[reference_str].AddItem( reference );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-01-24 20:46:14 +00:00
|
|
|
bool SCH_SHEET::IsComplexHierarchy() const
|
|
|
|
{
|
|
|
|
std::set<wxString> fileNames;
|
|
|
|
std::vector< const SCH_SHEET* > sheets;
|
|
|
|
|
|
|
|
unsigned count = GetSheets( sheets );
|
|
|
|
|
|
|
|
for( unsigned i = 0; i < count; i++ )
|
|
|
|
{
|
|
|
|
if( fileNames.find( sheets[i]->m_fileName ) != fileNames.end() )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
fileNames.insert( sheets[i]->m_fileName );
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SCH_ITEM* SCH_SHEET::FindNextItem( KICAD_T aType, SCH_ITEM* aLastItem, bool aWrap ) const
|
|
|
|
{
|
|
|
|
wxCHECK( m_screen != NULL, NULL );
|
|
|
|
|
|
|
|
bool hasWrapped = false;
|
|
|
|
bool firstItemFound = false;
|
|
|
|
SCH_ITEM* drawItem = m_screen->GetDrawItems();
|
|
|
|
|
|
|
|
while( drawItem )
|
|
|
|
{
|
|
|
|
if( drawItem->Type() == aType )
|
|
|
|
{
|
|
|
|
if( !aLastItem || firstItemFound )
|
|
|
|
{
|
|
|
|
return drawItem;
|
|
|
|
}
|
|
|
|
else if( !firstItemFound && drawItem == aLastItem )
|
|
|
|
{
|
|
|
|
firstItemFound = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
drawItem = drawItem->Next();
|
|
|
|
|
|
|
|
if( !drawItem && aLastItem && aWrap && !hasWrapped )
|
|
|
|
{
|
|
|
|
hasWrapped = true;
|
|
|
|
drawItem = m_screen->GetDrawItems();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-12-08 00:37:11 +00:00
|
|
|
bool SCH_SHEET::operator<( const SCH_SHEET& aRhs ) const
|
2016-01-13 02:31:34 +00:00
|
|
|
{
|
|
|
|
if( (*this - aRhs) < 0 )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int SCH_SHEET::operator-( const SCH_SHEET& aRhs ) const
|
2015-12-08 00:37:11 +00:00
|
|
|
{
|
|
|
|
// Don't waste time against comparing the same objects..
|
|
|
|
if( this == &aRhs )
|
2016-01-13 02:31:34 +00:00
|
|
|
return 0;
|
2015-12-08 00:37:11 +00:00
|
|
|
|
|
|
|
SCH_CONST_SHEETS lhsPath, rhsPath;
|
|
|
|
|
|
|
|
GetPath( lhsPath );
|
|
|
|
aRhs.GetPath( rhsPath );
|
|
|
|
|
|
|
|
// Shorter paths are less than longer paths.
|
2016-01-13 02:31:34 +00:00
|
|
|
int retv = lhsPath.size() - rhsPath.size();
|
2015-12-08 00:37:11 +00:00
|
|
|
|
2016-01-13 02:31:34 +00:00
|
|
|
if( retv == 0 )
|
2015-12-08 00:37:11 +00:00
|
|
|
{
|
2016-01-13 02:31:34 +00:00
|
|
|
// Compare time stamps when path lengths are the same.
|
|
|
|
for( unsigned i = 0; i < lhsPath.size(); i++ )
|
|
|
|
{
|
|
|
|
retv = lhsPath[i]->GetTimeStamp() - rhsPath[i]->GetTimeStamp();
|
|
|
|
|
|
|
|
if( retv != 0 )
|
|
|
|
break;
|
|
|
|
}
|
2015-12-08 00:37:11 +00:00
|
|
|
}
|
|
|
|
|
2016-01-13 02:31:34 +00:00
|
|
|
return retv;
|
2015-12-08 00:37:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-22 16:38:23 +00:00
|
|
|
#if defined(DEBUG)
|
2010-06-24 18:31:43 +00:00
|
|
|
|
2011-12-14 17:25:42 +00:00
|
|
|
void SCH_SHEET::Show( int nestLevel, std::ostream& os ) const
|
2008-04-22 16:38:23 +00:00
|
|
|
{
|
|
|
|
// XML output:
|
|
|
|
wxString s = GetClass();
|
|
|
|
|
2010-06-24 18:31:43 +00:00
|
|
|
NestedSpace( nestLevel, os ) << '<' << s.Lower().mb_str() << ">" << " sheet_name=\""
|
2011-12-08 15:45:01 +00:00
|
|
|
<< TO_UTF8( m_name ) << '"' << ">\n";
|
2008-04-22 16:38:23 +00:00
|
|
|
|
|
|
|
// show all the pins, and check the linked list integrity
|
2011-12-14 17:25:42 +00:00
|
|
|
BOOST_FOREACH( const SCH_SHEET_PIN& label, m_pins )
|
2008-04-22 16:38:23 +00:00
|
|
|
{
|
2010-06-24 18:31:43 +00:00
|
|
|
label.Show( nestLevel + 1, os );
|
2008-04-22 16:38:23 +00:00
|
|
|
}
|
|
|
|
|
2010-06-24 18:31:43 +00:00
|
|
|
NestedSpace( nestLevel, os ) << "</" << s.Lower().mb_str() << ">\n" << std::flush;
|
2008-02-12 21:12:46 +00:00
|
|
|
}
|
2008-02-26 19:19:54 +00:00
|
|
|
|
2009-01-04 18:52:57 +00:00
|
|
|
#endif
|