2011-10-07 14:41:30 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2009 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
|
|
|
|
* Copyright (C) 2010 Wayne Stambaugh <stambaughw@verizon.net>
|
|
|
|
* Copyright (C) 1992-2011 KiCad Developers, see AUTHORS.txt for contributors.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file sch_screen.cpp
|
|
|
|
* @brief Implementation of SCH_SCREEN and SCH_SCREENS classes.
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
#include "fctsys.h"
|
2009-01-29 14:26:20 +00:00
|
|
|
#include "gr_basic.h"
|
2010-10-26 20:25:48 +00:00
|
|
|
#include "kicad_string.h"
|
2009-09-22 12:27:57 +00:00
|
|
|
#include "eeschema_id.h"
|
2010-10-26 20:25:48 +00:00
|
|
|
#include "appl_wxstruct.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "class_drawpanel.h"
|
2010-11-10 15:30:12 +00:00
|
|
|
#include "sch_item_struct.h"
|
|
|
|
#include "wxEeschemaStruct.h"
|
2011-06-17 13:24:22 +00:00
|
|
|
#include "plot_common.h"
|
2009-09-25 18:49:04 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
#include "general.h"
|
|
|
|
#include "protos.h"
|
2010-12-31 19:47:39 +00:00
|
|
|
#include "netlist.h"
|
2010-10-26 20:25:48 +00:00
|
|
|
#include "class_library.h"
|
2011-01-12 21:47:54 +00:00
|
|
|
#include "sch_junction.h"
|
2011-01-07 19:24:24 +00:00
|
|
|
#include "sch_bus_entry.h"
|
2010-12-21 15:13:09 +00:00
|
|
|
#include "sch_line.h"
|
2011-01-07 19:24:24 +00:00
|
|
|
#include "sch_marker.h"
|
|
|
|
#include "sch_no_connect.h"
|
2010-11-11 21:10:27 +00:00
|
|
|
#include "sch_sheet.h"
|
2010-12-13 15:59:00 +00:00
|
|
|
#include "sch_component.h"
|
2011-03-25 19:16:05 +00:00
|
|
|
#include "sch_text.h"
|
2010-11-10 15:30:12 +00:00
|
|
|
|
|
|
|
#include <boost/foreach.hpp>
|
2008-02-27 19:38:16 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-09-30 18:15:37 +00:00
|
|
|
/* Default Eeschema zoom values. Limited to 17 values to keep a decent size
|
2009-12-02 21:44:03 +00:00
|
|
|
* to menus
|
|
|
|
*/
|
2011-04-12 12:41:13 +00:00
|
|
|
/* Please, note: wxMSW before version 2.9 seems have
|
|
|
|
* problems with zoom values < 1 ( i.e. userscale > 1) and needs to be patched:
|
|
|
|
* edit file <wxWidgets>/src/msw/dc.cpp
|
|
|
|
* search for line static const int VIEWPORT_EXTENT = 1000;
|
|
|
|
* and replace by static const int VIEWPORT_EXTENT = 10000;
|
|
|
|
* see http://trac.wxwidgets.org/ticket/9554
|
|
|
|
* This is a workaround that is not a full fix, but remaining artifacts are acceptable
|
2011-03-30 19:20:23 +00:00
|
|
|
*/
|
2011-07-05 12:46:14 +00:00
|
|
|
static double SchematicZoomList[] =
|
2009-02-06 11:45:35 +00:00
|
|
|
{
|
2011-07-05 12:46:14 +00:00
|
|
|
0.5, 0.7, 1.0, 1.5, 2.0, 3.0, 4.0, 6.0, 8.0,
|
|
|
|
12.0, 16.0, 23.0, 32.0, 48.0, 64.0, 80.0, 128.0
|
2009-02-06 11:45:35 +00:00
|
|
|
};
|
2009-01-29 14:26:20 +00:00
|
|
|
|
2011-07-05 12:46:14 +00:00
|
|
|
#define SCHEMATIC_ZOOM_LIST_CNT ( sizeof( SchematicZoomList ) / sizeof( SchematicZoomList[0] ) )
|
2010-01-29 20:36:12 +00:00
|
|
|
#define MM_TO_SCH_UNITS 1000.0 / 25.4 //schematic internal unites are mils
|
|
|
|
|
|
|
|
|
|
|
|
/* Default grid sizes for the schematic editor.
|
|
|
|
* Do NOT add others values (mainly grid values in mm),
|
|
|
|
* because they can break the schematic:
|
|
|
|
* because wires and pins are considered as connected when the are to the same coordinate
|
|
|
|
* we cannot mix coordinates in mils (internal units) and mm
|
|
|
|
* (that cannot exactly converted in mils in many cases
|
2010-10-26 20:25:48 +00:00
|
|
|
* in fact schematic must only use 50 and 25 mils to place labels, wires and components
|
2010-01-29 20:36:12 +00:00
|
|
|
* others values are useful only for graphic items (mainly in library editor)
|
|
|
|
* so use integer values in mils only.
|
|
|
|
*/
|
2008-12-05 16:03:05 +00:00
|
|
|
static GRID_TYPE SchematicGridList[] = {
|
2009-02-07 08:33:25 +00:00
|
|
|
{ ID_POPUP_GRID_LEVEL_50, wxRealPoint( 50, 50 ) },
|
|
|
|
{ ID_POPUP_GRID_LEVEL_25, wxRealPoint( 25, 25 ) },
|
|
|
|
{ ID_POPUP_GRID_LEVEL_10, wxRealPoint( 10, 10 ) },
|
|
|
|
{ ID_POPUP_GRID_LEVEL_5, wxRealPoint( 5, 5 ) },
|
|
|
|
{ ID_POPUP_GRID_LEVEL_2, wxRealPoint( 2, 2 ) },
|
2009-10-14 19:43:31 +00:00
|
|
|
{ ID_POPUP_GRID_LEVEL_1, wxRealPoint( 1, 1 ) },
|
2008-12-05 16:03:05 +00:00
|
|
|
};
|
|
|
|
|
2010-10-26 20:25:48 +00:00
|
|
|
#define SCHEMATIC_GRID_LIST_CNT ( sizeof( SchematicGridList ) / sizeof( GRID_TYPE ) )
|
2008-12-05 16:03:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
SCH_SCREEN::SCH_SCREEN( KICAD_T type ) : BASE_SCREEN( type )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2008-12-05 16:03:05 +00:00
|
|
|
size_t i;
|
|
|
|
|
2010-12-08 20:12:46 +00:00
|
|
|
SetDrawItems( NULL ); /* Schematic items list */
|
2007-08-20 01:20:48 +00:00
|
|
|
m_Zoom = 32;
|
2009-01-29 14:26:20 +00:00
|
|
|
|
|
|
|
for( i = 0; i < SCHEMATIC_ZOOM_LIST_CNT; i++ )
|
|
|
|
m_ZoomList.Add( SchematicZoomList[i] );
|
2008-12-05 16:03:05 +00:00
|
|
|
|
|
|
|
for( i = 0; i < SCHEMATIC_GRID_LIST_CNT; i++ )
|
|
|
|
AddGrid( SchematicGridList[i] );
|
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
SetGrid( wxRealPoint( 50, 50 ) ); /* Default grid size. */
|
2011-01-12 21:47:54 +00:00
|
|
|
m_refCount = 0;
|
2009-12-02 21:44:03 +00:00
|
|
|
m_Center = false; /* Suitable for schematic only. For
|
|
|
|
* libedit and viewlib, must be set
|
|
|
|
* to true */
|
2008-12-05 16:03:05 +00:00
|
|
|
InitDatas();
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2007-09-01 12:00:30 +00:00
|
|
|
SCH_SCREEN::~SCH_SCREEN()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-20 01:20:48 +00:00
|
|
|
ClearUndoRedoList();
|
|
|
|
FreeDrawList();
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-01-20 16:34:57 +00:00
|
|
|
void SCH_SCREEN::IncRefCount()
|
|
|
|
{
|
|
|
|
m_refCount++;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-12 21:47:54 +00:00
|
|
|
void SCH_SCREEN::DecRefCount()
|
|
|
|
{
|
|
|
|
wxCHECK_RET( m_refCount != 0,
|
|
|
|
wxT( "Screen reference count already zero. Bad programmer!" ) );
|
|
|
|
m_refCount--;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-15 18:44:24 +00:00
|
|
|
void SCH_SCREEN::Clear()
|
|
|
|
{
|
|
|
|
FreeDrawList();
|
|
|
|
|
|
|
|
/* Clear the project settings. */
|
|
|
|
m_ScreenNumber = m_NumberOfScreen = 1;
|
|
|
|
m_Title.Empty();
|
|
|
|
m_Revision.Empty();
|
|
|
|
m_Company.Empty();
|
|
|
|
m_Commentaire1.Empty();
|
|
|
|
m_Commentaire2.Empty();
|
|
|
|
m_Commentaire3.Empty();
|
|
|
|
m_Commentaire4.Empty();
|
|
|
|
m_Date = GenDate();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
void SCH_SCREEN::FreeDrawList()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2011-04-05 14:46:51 +00:00
|
|
|
SCH_ITEM* item;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2010-12-08 20:12:46 +00:00
|
|
|
while( GetDrawItems() != NULL )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2011-04-05 14:46:51 +00:00
|
|
|
item = GetDrawItems();
|
2010-12-08 20:12:46 +00:00
|
|
|
SetDrawItems( GetDrawItems()->Next() );
|
2011-04-05 14:46:51 +00:00
|
|
|
SAFE_DELETE( item );
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
2008-02-26 19:19:54 +00:00
|
|
|
|
2010-12-08 20:12:46 +00:00
|
|
|
SetDrawItems( NULL );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-04-05 14:46:51 +00:00
|
|
|
void SCH_SCREEN::RemoveFromDrawList( SCH_ITEM* aItem )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2011-04-05 14:46:51 +00:00
|
|
|
if( aItem == GetDrawItems() )
|
2010-12-08 20:12:46 +00:00
|
|
|
{
|
|
|
|
SetDrawItems( GetDrawItems()->Next() );
|
|
|
|
}
|
2007-08-20 01:20:48 +00:00
|
|
|
else
|
|
|
|
{
|
2010-12-08 20:12:46 +00:00
|
|
|
EDA_ITEM* DrawList = GetDrawItems();
|
|
|
|
|
2008-04-14 19:22:48 +00:00
|
|
|
while( DrawList && DrawList->Next() )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2011-04-05 14:46:51 +00:00
|
|
|
if( DrawList->Next() == aItem )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2008-11-24 06:53:43 +00:00
|
|
|
DrawList->SetNext( DrawList->Next()->Next() );
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
}
|
2011-02-05 02:21:11 +00:00
|
|
|
|
2008-04-14 19:22:48 +00:00
|
|
|
DrawList = DrawList->Next();
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
2008-02-26 19:19:54 +00:00
|
|
|
|
|
|
|
|
2011-03-10 19:36:30 +00:00
|
|
|
void SCH_SCREEN::DeleteItem( SCH_ITEM* aItem )
|
|
|
|
{
|
|
|
|
wxCHECK_RET( aItem != NULL, wxT( "Cannot delete invaled item from screen." ) );
|
|
|
|
|
|
|
|
SetModify();
|
|
|
|
|
2011-03-30 19:26:05 +00:00
|
|
|
if( aItem->Type() == SCH_SHEET_PIN_T )
|
2011-03-10 19:36:30 +00:00
|
|
|
{
|
|
|
|
// This structure is attached to a sheet, get the parent sheet object.
|
2011-03-30 19:26:05 +00:00
|
|
|
SCH_SHEET_PIN* sheetPin = (SCH_SHEET_PIN*) aItem;
|
|
|
|
SCH_SHEET* sheet = sheetPin->GetParent();
|
2011-03-10 19:36:30 +00:00
|
|
|
wxCHECK_RET( sheet != NULL,
|
|
|
|
wxT( "Sheet label parent not properly set, bad programmer!" ) );
|
2011-03-30 19:26:05 +00:00
|
|
|
sheet->RemovePin( sheetPin );
|
2011-03-10 19:36:30 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( aItem == GetDrawItems() )
|
|
|
|
{
|
|
|
|
SetDrawItems( aItem->Next() );
|
|
|
|
SAFE_DELETE( aItem );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SCH_ITEM* itemList = GetDrawItems();
|
|
|
|
|
|
|
|
while( itemList && itemList->Next() )
|
|
|
|
{
|
|
|
|
if( itemList->Next() == aItem )
|
|
|
|
{
|
|
|
|
itemList->SetNext( aItem->Next() );
|
|
|
|
SAFE_DELETE( aItem );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
itemList = itemList->Next();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-05 14:46:51 +00:00
|
|
|
bool SCH_SCREEN::CheckIfOnDrawList( SCH_ITEM* aItem )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2011-04-05 14:46:51 +00:00
|
|
|
SCH_ITEM* itemList = GetDrawItems();
|
2008-02-26 19:19:54 +00:00
|
|
|
|
2011-03-10 19:36:30 +00:00
|
|
|
while( itemList )
|
2008-02-26 19:19:54 +00:00
|
|
|
{
|
2011-04-05 14:46:51 +00:00
|
|
|
if( itemList == aItem )
|
2008-02-26 19:19:54 +00:00
|
|
|
return true;
|
2011-03-10 19:36:30 +00:00
|
|
|
|
|
|
|
itemList = itemList->Next();
|
2008-02-26 19:19:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
2008-02-26 19:19:54 +00:00
|
|
|
|
|
|
|
|
2011-04-05 14:46:51 +00:00
|
|
|
void SCH_SCREEN::AddToDrawList( SCH_ITEM* aItem )
|
2009-12-02 21:44:03 +00:00
|
|
|
{
|
2011-09-01 16:31:16 +00:00
|
|
|
if( aItem == NULL )
|
|
|
|
return;
|
2011-04-05 14:46:51 +00:00
|
|
|
aItem->SetNext( GetDrawItems() );
|
|
|
|
SetDrawItems( aItem );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2008-02-26 19:19:54 +00:00
|
|
|
|
2011-03-25 19:16:05 +00:00
|
|
|
SCH_ITEM* SCH_SCREEN::GetItem( const wxPoint& aPosition, int aAccuracy, KICAD_T aType ) const
|
2011-01-11 20:34:29 +00:00
|
|
|
{
|
|
|
|
for( SCH_ITEM* item = GetDrawItems(); item != NULL; item = item->Next() )
|
|
|
|
{
|
2011-03-25 19:16:05 +00:00
|
|
|
if( item->HitTest( aPosition, aAccuracy ) && (aType == NOT_USED) )
|
|
|
|
return item;
|
2011-01-11 20:34:29 +00:00
|
|
|
|
2011-03-25 19:16:05 +00:00
|
|
|
if( (aType == SCH_FIELD_T) && (item->Type() == SCH_COMPONENT_T) )
|
2011-03-10 19:36:30 +00:00
|
|
|
{
|
2011-03-25 19:16:05 +00:00
|
|
|
SCH_COMPONENT* component = (SCH_COMPONENT*) item;
|
2011-03-10 19:36:30 +00:00
|
|
|
|
2011-03-25 19:16:05 +00:00
|
|
|
for( int i = REFERENCE; i < component->GetFieldCount(); i++ )
|
2011-03-10 19:36:30 +00:00
|
|
|
{
|
2011-03-25 19:16:05 +00:00
|
|
|
SCH_FIELD* field = component->GetField( i );
|
2011-03-10 19:36:30 +00:00
|
|
|
|
2011-03-25 19:16:05 +00:00
|
|
|
if( field->HitTest( aPosition, aAccuracy ) )
|
|
|
|
return (SCH_ITEM*) field;
|
2011-03-10 19:36:30 +00:00
|
|
|
}
|
2011-03-25 19:16:05 +00:00
|
|
|
}
|
2011-03-30 19:26:05 +00:00
|
|
|
else if( (aType == SCH_SHEET_PIN_T) && (item->Type() == SCH_SHEET_T) )
|
2011-03-25 19:16:05 +00:00
|
|
|
{
|
|
|
|
SCH_SHEET* sheet = (SCH_SHEET*)item;
|
|
|
|
|
2011-03-30 19:26:05 +00:00
|
|
|
SCH_SHEET_PIN* label = sheet->GetPin( aPosition );
|
2011-03-10 19:36:30 +00:00
|
|
|
|
2011-03-25 19:16:05 +00:00
|
|
|
if( label )
|
|
|
|
return (SCH_ITEM*) label;
|
|
|
|
}
|
|
|
|
else if( (item->Type() == aType) && item->HitTest( aPosition, aAccuracy ) )
|
|
|
|
{
|
2011-03-10 19:36:30 +00:00
|
|
|
return item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-26 20:25:48 +00:00
|
|
|
SCH_ITEM* SCH_SCREEN::ExtractWires( bool CreateCopy )
|
|
|
|
{
|
|
|
|
SCH_ITEM* item, * next_item, * new_item, * List = NULL;
|
|
|
|
|
2010-12-08 20:12:46 +00:00
|
|
|
for( item = GetDrawItems(); item != NULL; item = next_item )
|
2010-10-26 20:25:48 +00:00
|
|
|
{
|
|
|
|
next_item = item->Next();
|
|
|
|
|
|
|
|
switch( item->Type() )
|
|
|
|
{
|
2010-12-10 19:47:44 +00:00
|
|
|
case SCH_JUNCTION_T:
|
|
|
|
case SCH_LINE_T:
|
2010-10-26 20:25:48 +00:00
|
|
|
RemoveFromDrawList( item );
|
|
|
|
item->SetNext( List );
|
|
|
|
List = item;
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2010-10-26 20:25:48 +00:00
|
|
|
if( CreateCopy )
|
|
|
|
{
|
2010-12-21 15:13:09 +00:00
|
|
|
new_item = item->Clone();
|
2010-12-08 20:12:46 +00:00
|
|
|
new_item->SetNext( GetDrawItems() );
|
|
|
|
SetDrawItems( new_item );
|
2010-10-26 20:25:48 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return List;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-05 02:21:11 +00:00
|
|
|
void SCH_SCREEN::ReplaceWires( SCH_ITEM* aWireList )
|
|
|
|
{
|
|
|
|
SCH_ITEM* item;
|
|
|
|
SCH_ITEM* next_item;
|
|
|
|
|
|
|
|
for( item = GetDrawItems(); item != NULL; item = next_item )
|
|
|
|
{
|
|
|
|
next_item = item->Next();
|
|
|
|
|
|
|
|
switch( item->Type() )
|
|
|
|
{
|
|
|
|
case SCH_JUNCTION_T:
|
|
|
|
case SCH_LINE_T:
|
|
|
|
RemoveFromDrawList( item );
|
|
|
|
delete item;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
while( aWireList )
|
|
|
|
{
|
|
|
|
next_item = aWireList->Next();
|
|
|
|
|
|
|
|
aWireList->SetNext( GetDrawItems() );
|
|
|
|
SetDrawItems( aWireList );
|
|
|
|
aWireList = next_item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-10 19:36:30 +00:00
|
|
|
void SCH_SCREEN::MarkConnections( SCH_LINE* aSegment )
|
|
|
|
{
|
|
|
|
wxCHECK_RET( (aSegment != NULL) && (aSegment->Type() == SCH_LINE_T),
|
|
|
|
wxT( "Invalid object pointer." ) );
|
|
|
|
|
|
|
|
for( SCH_ITEM* item = GetDrawItems(); item != NULL; item = item->Next() )
|
|
|
|
{
|
|
|
|
if( item->GetFlags() & CANDIDATE )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( item->Type() == SCH_JUNCTION_T )
|
|
|
|
{
|
|
|
|
SCH_JUNCTION* junction = (SCH_JUNCTION*) item;
|
|
|
|
|
|
|
|
if( aSegment->IsEndPoint( junction->m_Pos ) )
|
|
|
|
item->SetFlags( CANDIDATE );
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( item->Type() != SCH_LINE_T )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
SCH_LINE* segment = (SCH_LINE*) item;
|
|
|
|
|
|
|
|
if( aSegment->IsEndPoint( segment->m_Start ) && !GetPin( segment->m_Start, NULL, true ) )
|
|
|
|
{
|
|
|
|
item->SetFlags( CANDIDATE );
|
|
|
|
MarkConnections( segment );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( aSegment->IsEndPoint( segment->m_End ) && !GetPin( segment->m_End, NULL, true ) )
|
|
|
|
{
|
|
|
|
item->SetFlags( CANDIDATE );
|
|
|
|
MarkConnections( segment );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-25 19:16:05 +00:00
|
|
|
bool SCH_SCREEN::IsJunctionNeeded( const wxPoint& aPosition )
|
2011-03-10 19:36:30 +00:00
|
|
|
{
|
2011-03-25 19:16:05 +00:00
|
|
|
if( GetItem( aPosition, 0, SCH_JUNCTION_T ) )
|
2011-03-10 19:36:30 +00:00
|
|
|
return false;
|
|
|
|
|
2011-03-25 19:16:05 +00:00
|
|
|
if( GetWire( aPosition, 0, EXCLUDE_END_POINTS_T ) )
|
2011-03-10 19:36:30 +00:00
|
|
|
{
|
2011-03-25 19:16:05 +00:00
|
|
|
if( GetWire( aPosition, 0, END_POINTS_ONLY_T ) )
|
2011-03-10 19:36:30 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
if( GetPin( aPosition, NULL, true ) )
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-25 19:16:05 +00:00
|
|
|
bool SCH_SCREEN::IsTerminalPoint( const wxPoint& aPosition, int aLayer )
|
|
|
|
{
|
|
|
|
wxCHECK_MSG( aLayer == LAYER_NOTES || aLayer == LAYER_BUS || aLayer == LAYER_WIRE, false,
|
|
|
|
wxT( "Invalid layer type passed to SCH_SCREEN::IsTerminalPoint()." ) );
|
|
|
|
|
|
|
|
SCH_SHEET_PIN* label;
|
|
|
|
SCH_TEXT* text;
|
|
|
|
|
|
|
|
switch( aLayer )
|
|
|
|
{
|
|
|
|
case LAYER_BUS:
|
|
|
|
|
|
|
|
if( GetBus( aPosition ) )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
label = GetSheetLabel( aPosition );
|
|
|
|
|
|
|
|
if( label && IsBusLabel( label->m_Text ) && label->IsConnected( aPosition ) )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
text = GetLabel( aPosition );
|
|
|
|
|
|
|
|
if( text && IsBusLabel( text->GetText() ) && text->IsConnected( aPosition )
|
|
|
|
&& (text->Type() != SCH_LABEL_T) )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LAYER_NOTES:
|
|
|
|
|
|
|
|
if( GetLine( aPosition ) )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LAYER_WIRE:
|
|
|
|
if( GetItem( aPosition, MAX( g_DrawDefaultLineThickness, 3 ), SCH_BUS_ENTRY_T ) )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if( GetItem( aPosition, MAX( g_DrawDefaultLineThickness, 3 ), SCH_JUNCTION_T ) )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if( GetPin( aPosition, NULL, true ) )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if( GetWire( aPosition ) )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
text = GetLabel( aPosition );
|
|
|
|
|
|
|
|
if( text && text->IsConnected( aPosition ) && !IsBusLabel( text->GetText() ) )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
label = GetSheetLabel( aPosition );
|
|
|
|
|
|
|
|
if( label && label->IsConnected( aPosition ) && !IsBusLabel( label->m_Text ) )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-21 19:30:59 +00:00
|
|
|
bool SCH_SCREEN::SchematicCleanUp( EDA_DRAW_PANEL* aCanvas, wxDC* aDC )
|
2010-10-26 20:25:48 +00:00
|
|
|
{
|
|
|
|
SCH_ITEM* DrawList, * TstDrawList;
|
2011-02-21 21:07:00 +00:00
|
|
|
bool Modify = false;
|
2010-10-26 20:25:48 +00:00
|
|
|
|
2010-12-08 20:12:46 +00:00
|
|
|
DrawList = GetDrawItems();
|
|
|
|
|
2010-10-26 20:25:48 +00:00
|
|
|
for( ; DrawList != NULL; DrawList = DrawList->Next() )
|
|
|
|
{
|
2010-12-10 19:47:44 +00:00
|
|
|
if( DrawList->Type() == SCH_LINE_T )
|
2010-10-26 20:25:48 +00:00
|
|
|
{
|
|
|
|
TstDrawList = DrawList->Next();
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2010-10-26 20:25:48 +00:00
|
|
|
while( TstDrawList )
|
|
|
|
{
|
2010-12-10 19:47:44 +00:00
|
|
|
if( TstDrawList->Type() == SCH_LINE_T )
|
2010-10-26 20:25:48 +00:00
|
|
|
{
|
|
|
|
SCH_LINE* line = (SCH_LINE*) DrawList;
|
|
|
|
|
|
|
|
if( line->MergeOverlap( (SCH_LINE*) TstDrawList ) )
|
|
|
|
{
|
2011-03-10 19:36:30 +00:00
|
|
|
// Keep the current flags, because the deleted segment can be flagged.
|
|
|
|
DrawList->SetFlags( TstDrawList->GetFlags() );
|
|
|
|
DeleteItem( TstDrawList );
|
2010-12-08 20:12:46 +00:00
|
|
|
TstDrawList = GetDrawItems();
|
2011-02-21 21:07:00 +00:00
|
|
|
Modify = true;
|
2010-10-26 20:25:48 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
TstDrawList = TstDrawList->Next();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
TstDrawList = TstDrawList->Next();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-21 19:30:59 +00:00
|
|
|
TestDanglingEnds( aCanvas, aDC );
|
2010-10-26 20:25:48 +00:00
|
|
|
|
2011-02-23 13:48:19 +00:00
|
|
|
if( aCanvas && Modify )
|
|
|
|
aCanvas->Refresh();
|
2011-03-10 19:36:30 +00:00
|
|
|
|
2010-10-26 20:25:48 +00:00
|
|
|
return Modify;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool SCH_SCREEN::Save( FILE* aFile ) const
|
|
|
|
{
|
|
|
|
// Creates header
|
|
|
|
if( fprintf( aFile, "%s %s %d", EESCHEMA_FILE_STAMP,
|
|
|
|
SCHEMATIC_HEAD_STRING, EESCHEMA_VERSION ) < 0
|
2011-02-28 18:36:19 +00:00
|
|
|
|| fprintf( aFile, " date %s\n", TO_UTF8( DateAndTime() ) ) < 0 )
|
2011-02-21 21:07:00 +00:00
|
|
|
return false;
|
2010-10-26 20:25:48 +00:00
|
|
|
|
|
|
|
BOOST_FOREACH( const CMP_LIBRARY& lib, CMP_LIBRARY::GetLibraryList() )
|
|
|
|
{
|
2011-02-28 18:36:19 +00:00
|
|
|
if( fprintf( aFile, "LIBS:%s\n", TO_UTF8( lib.GetName() ) ) < 0 )
|
2011-02-21 21:07:00 +00:00
|
|
|
return false;
|
2010-10-26 20:25:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( fprintf( aFile, "EELAYER %2d %2d\n", g_LayerDescr.NumberOfLayers,
|
|
|
|
g_LayerDescr.CurrentLayer ) < 0
|
|
|
|
|| fprintf( aFile, "EELAYER END\n" ) < 0 )
|
2011-02-21 21:07:00 +00:00
|
|
|
return false;
|
2010-10-26 20:25:48 +00:00
|
|
|
|
|
|
|
/* Write page info, ScreenNumber and NumberOfScreen; not very meaningful for
|
|
|
|
* SheetNumber and Sheet Count in a complex hierarchy, but useful in
|
|
|
|
* simple hierarchy and flat hierarchy. Used also to search the root
|
|
|
|
* sheet ( ScreenNumber = 1 ) within the files
|
|
|
|
*/
|
|
|
|
|
2011-02-28 18:36:19 +00:00
|
|
|
if( fprintf( aFile, "$Descr %s %d %d\n", TO_UTF8( m_CurrentSheetDesc->m_Name ),
|
2010-10-26 20:25:48 +00:00
|
|
|
m_CurrentSheetDesc->m_Size.x, m_CurrentSheetDesc->m_Size.y ) < 0
|
2011-02-28 18:36:19 +00:00
|
|
|
|| fprintf( aFile, "encoding utf-8\n") < 0
|
2010-10-26 20:25:48 +00:00
|
|
|
|| fprintf( aFile, "Sheet %d %d\n", m_ScreenNumber, m_NumberOfScreen ) < 0
|
2011-03-25 20:07:27 +00:00
|
|
|
|| fprintf( aFile, "Title %s\n", EscapedUTF8( m_Title ).c_str() ) < 0
|
|
|
|
|| fprintf( aFile, "Date %s\n", EscapedUTF8( m_Date ).c_str() ) < 0
|
|
|
|
|| fprintf( aFile, "Rev %s\n", EscapedUTF8( m_Revision ).c_str() ) < 0
|
|
|
|
|| fprintf( aFile, "Comp %s\n", EscapedUTF8( m_Company ).c_str() ) < 0
|
|
|
|
|| fprintf( aFile, "Comment1 %s\n", EscapedUTF8( m_Commentaire1 ).c_str() ) < 0
|
|
|
|
|| fprintf( aFile, "Comment2 %s\n", EscapedUTF8( m_Commentaire2 ).c_str() ) < 0
|
|
|
|
|| fprintf( aFile, "Comment3 %s\n", EscapedUTF8( m_Commentaire3 ).c_str() ) < 0
|
|
|
|
|| fprintf( aFile, "Comment4 %s\n", EscapedUTF8( m_Commentaire4 ).c_str() ) < 0
|
2010-10-26 20:25:48 +00:00
|
|
|
|| fprintf( aFile, "$EndDescr\n" ) < 0 )
|
2011-02-21 21:07:00 +00:00
|
|
|
return false;
|
2010-10-26 20:25:48 +00:00
|
|
|
|
2010-12-08 20:12:46 +00:00
|
|
|
for( SCH_ITEM* item = GetDrawItems(); item; item = item->Next() )
|
2010-10-26 20:25:48 +00:00
|
|
|
{
|
|
|
|
if( !item->Save( aFile ) )
|
2011-02-21 21:07:00 +00:00
|
|
|
return false;
|
2010-10-26 20:25:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( fprintf( aFile, "$EndSCHEMATC\n" ) < 0 )
|
2011-02-21 21:07:00 +00:00
|
|
|
return false;
|
2010-10-26 20:25:48 +00:00
|
|
|
|
2011-02-21 21:07:00 +00:00
|
|
|
return true;
|
2010-10-26 20:25:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-21 19:30:59 +00:00
|
|
|
void SCH_SCREEN::Draw( EDA_DRAW_PANEL* aCanvas, wxDC* aDC, int aDrawMode, int aColor )
|
2011-01-11 20:34:29 +00:00
|
|
|
{
|
|
|
|
for( SCH_ITEM* item = GetDrawItems(); item != NULL; item = item->Next() )
|
|
|
|
{
|
2011-07-08 19:55:41 +00:00
|
|
|
if( item->IsMoving() || item->IsResized() )
|
2011-01-11 20:34:29 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
// uncomment line below when there is a virtual
|
|
|
|
// EDA_ITEM::GetBoundingBox()
|
|
|
|
// if( panel->m_ClipBox.Intersects( Structs->GetBoundingBox()
|
|
|
|
// ) )
|
|
|
|
item->Draw( aCanvas, aDC, wxPoint( 0, 0 ), aDrawMode, aColor );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-17 13:24:22 +00:00
|
|
|
void SCH_SCREEN::Plot( PLOTTER* aPlotter )
|
|
|
|
{
|
|
|
|
for( SCH_ITEM* item = GetDrawItems(); item != NULL; item = item->Next() )
|
|
|
|
{
|
|
|
|
aPlotter->set_current_line_width( item->GetPenSize() );
|
|
|
|
item->Plot( aPlotter );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-26 20:25:48 +00:00
|
|
|
void SCH_SCREEN::ClearUndoORRedoList( UNDO_REDO_CONTAINER& aList, int aItemCount )
|
|
|
|
{
|
|
|
|
if( aItemCount == 0 )
|
|
|
|
return;
|
|
|
|
|
|
|
|
unsigned icnt = aList.m_CommandsList.size();
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2010-10-26 20:25:48 +00:00
|
|
|
if( aItemCount > 0 )
|
|
|
|
icnt = aItemCount;
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2010-10-26 20:25:48 +00:00
|
|
|
for( unsigned ii = 0; ii < icnt; ii++ )
|
|
|
|
{
|
|
|
|
if( aList.m_CommandsList.size() == 0 )
|
|
|
|
break;
|
|
|
|
|
|
|
|
PICKED_ITEMS_LIST* curr_cmd = aList.m_CommandsList[0];
|
|
|
|
aList.m_CommandsList.erase( aList.m_CommandsList.begin() );
|
|
|
|
|
|
|
|
curr_cmd->ClearListAndDeleteItems();
|
|
|
|
delete curr_cmd; // Delete command
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-03 14:13:15 +00:00
|
|
|
void SCH_SCREEN::ClearDrawingState()
|
|
|
|
{
|
2010-12-08 20:12:46 +00:00
|
|
|
for( SCH_ITEM* item = GetDrawItems(); item != NULL; item = item->Next() )
|
2011-03-10 19:36:30 +00:00
|
|
|
item->ClearFlags();
|
2010-11-03 14:13:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-10 20:35:24 +00:00
|
|
|
LIB_PIN* SCH_SCREEN::GetPin( const wxPoint& aPosition, SCH_COMPONENT** aComponent,
|
2011-03-10 19:36:30 +00:00
|
|
|
bool aEndPointOnly ) const
|
2010-12-13 15:59:00 +00:00
|
|
|
{
|
|
|
|
SCH_ITEM* item;
|
|
|
|
SCH_COMPONENT* component = NULL;
|
|
|
|
LIB_PIN* pin = NULL;
|
|
|
|
|
|
|
|
for( item = GetDrawItems(); item != NULL; item = item->Next() )
|
|
|
|
{
|
|
|
|
if( item->Type() != SCH_COMPONENT_T )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
component = (SCH_COMPONENT*) item;
|
|
|
|
|
2011-05-05 17:45:35 +00:00
|
|
|
if( aEndPointOnly )
|
|
|
|
{
|
|
|
|
pin = NULL;
|
|
|
|
LIB_COMPONENT* entry = CMP_LIBRARY::FindLibraryComponent( component->GetLibName() );
|
|
|
|
if( entry == NULL )
|
|
|
|
continue;
|
|
|
|
for( pin = entry->GetNextPin(); pin != NULL; pin = entry->GetNextPin( pin ) )
|
|
|
|
{
|
|
|
|
// Skip items not used for this part.
|
|
|
|
if( component->GetUnit() && pin->GetUnit() &&
|
|
|
|
( pin->GetUnit() != component->GetUnit() ) )
|
|
|
|
continue;
|
|
|
|
if( component->GetConvert() && pin->GetConvert() &&
|
|
|
|
( pin->GetConvert() != component->GetConvert() ) )
|
|
|
|
continue;
|
|
|
|
if(component->GetPinPhysicalPosition( pin ) == aPosition )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if( pin )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pin = (LIB_PIN*) component->GetDrawItem( aPosition, LIB_PIN_T );
|
|
|
|
if( pin )
|
|
|
|
break;
|
|
|
|
}
|
2011-03-25 19:16:05 +00:00
|
|
|
}
|
2011-01-10 20:35:24 +00:00
|
|
|
|
2011-05-05 17:45:35 +00:00
|
|
|
if( pin && aComponent )
|
2010-12-13 15:59:00 +00:00
|
|
|
*aComponent = component;
|
|
|
|
|
|
|
|
return pin;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-08-31 13:27:05 +00:00
|
|
|
SCH_SHEET* SCH_SCREEN::GetSheet( const wxString& aName )
|
|
|
|
{
|
|
|
|
for( SCH_ITEM* item = GetDrawItems(); item != NULL; item = item->Next() )
|
|
|
|
{
|
|
|
|
if( item->Type() != SCH_SHEET_T )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
SCH_SHEET* sheet = (SCH_SHEET*) item;
|
|
|
|
|
|
|
|
if( aName.CmpNoCase( sheet->m_SheetName ) == 0 )
|
|
|
|
return sheet;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-11 20:34:29 +00:00
|
|
|
SCH_SHEET_PIN* SCH_SCREEN::GetSheetLabel( const wxPoint& aPosition )
|
|
|
|
{
|
2011-03-30 19:26:05 +00:00
|
|
|
SCH_SHEET_PIN* sheetPin = NULL;
|
2011-01-11 20:34:29 +00:00
|
|
|
|
|
|
|
for( SCH_ITEM* item = GetDrawItems(); item != NULL; item = item->Next() )
|
|
|
|
{
|
|
|
|
if( item->Type() != SCH_SHEET_T )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
SCH_SHEET* sheet = (SCH_SHEET*) item;
|
2011-03-30 19:26:05 +00:00
|
|
|
sheetPin = sheet->GetPin( aPosition );
|
2011-01-11 20:34:29 +00:00
|
|
|
|
2011-03-30 19:26:05 +00:00
|
|
|
if( sheetPin )
|
2011-01-11 20:34:29 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-03-30 19:26:05 +00:00
|
|
|
return sheetPin;
|
2011-01-11 20:34:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-13 15:59:00 +00:00
|
|
|
int SCH_SCREEN::CountConnectedItems( const wxPoint& aPos, bool aTestJunctions ) const
|
|
|
|
{
|
|
|
|
SCH_ITEM* item;
|
|
|
|
int count = 0;
|
|
|
|
|
|
|
|
for( item = GetDrawItems(); item != NULL; item = item->Next() )
|
|
|
|
{
|
|
|
|
if( item->Type() == SCH_JUNCTION_T && !aTestJunctions )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( item->IsConnected( aPos ) )
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-31 19:47:39 +00:00
|
|
|
void SCH_SCREEN::ClearAnnotation( SCH_SHEET_PATH* aSheetPath )
|
|
|
|
{
|
|
|
|
for( SCH_ITEM* item = GetDrawItems(); item != NULL; item = item->Next() )
|
|
|
|
{
|
|
|
|
if( item->Type() == SCH_COMPONENT_T )
|
|
|
|
{
|
|
|
|
SCH_COMPONENT* component = (SCH_COMPONENT*) item;
|
|
|
|
|
|
|
|
component->ClearAnnotation( aSheetPath );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-25 19:16:05 +00:00
|
|
|
void SCH_SCREEN::GetHierarchicalItems( EDA_ITEMS& aItems )
|
2010-12-31 19:47:39 +00:00
|
|
|
{
|
|
|
|
SCH_ITEM* item = GetDrawItems();
|
|
|
|
|
|
|
|
while( item )
|
|
|
|
{
|
|
|
|
if( ( item->Type() == SCH_SHEET_T ) || ( item->Type() == SCH_COMPONENT_T ) )
|
|
|
|
aItems.push_back( item );
|
|
|
|
|
|
|
|
item = item->Next();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-07 19:24:24 +00:00
|
|
|
void SCH_SCREEN::SelectBlockItems()
|
|
|
|
{
|
|
|
|
SCH_ITEM* item;
|
|
|
|
|
|
|
|
PICKED_ITEMS_LIST* pickedlist = &m_BlockLocate.m_ItemsSelection;
|
|
|
|
|
|
|
|
if( pickedlist->GetCount() == 0 )
|
|
|
|
return;
|
|
|
|
|
|
|
|
ClearDrawingState();
|
|
|
|
|
|
|
|
for( unsigned ii = 0; ii < pickedlist->GetCount(); ii++ )
|
|
|
|
{
|
|
|
|
item = (SCH_ITEM*) pickedlist->GetPickedItem( ii );
|
2011-03-10 19:36:30 +00:00
|
|
|
item->SetFlags( SELECTED );
|
2011-01-07 19:24:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( !m_BlockLocate.IsDragging() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Select all the items in the screen connected to the items in the block.
|
2011-01-20 11:26:10 +00:00
|
|
|
// be sure end lines that are on the block limits are seen inside this block
|
|
|
|
m_BlockLocate.Inflate(1);
|
|
|
|
unsigned last_select_id = pickedlist->GetCount();
|
|
|
|
unsigned ii = 0;
|
2011-03-10 19:36:30 +00:00
|
|
|
|
2011-01-20 11:26:10 +00:00
|
|
|
for( ; ii < last_select_id; ii++ )
|
2011-01-07 19:24:24 +00:00
|
|
|
{
|
|
|
|
item = (SCH_ITEM*)pickedlist->GetPickedItem( ii );
|
|
|
|
|
|
|
|
if( item->Type() == SCH_LINE_T )
|
|
|
|
{
|
|
|
|
item->IsSelectStateChanged( m_BlockLocate );
|
2011-03-10 19:36:30 +00:00
|
|
|
|
|
|
|
if( ( item->GetFlags() & SELECTED ) == 0 )
|
2011-01-20 11:26:10 +00:00
|
|
|
{ // This is a special case:
|
|
|
|
// this selected wire has no ends in block.
|
|
|
|
// But it was selected (because it intersects the selecting area),
|
|
|
|
// so we must keep it selected and select items connected to it
|
|
|
|
// Note: an other option could be: remove it from drag list
|
2011-03-10 19:36:30 +00:00
|
|
|
item->SetFlags( SELECTED | SKIP_STRUCT );
|
2011-01-20 11:26:10 +00:00
|
|
|
std::vector< wxPoint > connections;
|
|
|
|
item->GetConnectionPoints( connections );
|
2011-03-10 19:36:30 +00:00
|
|
|
|
2011-01-20 11:26:10 +00:00
|
|
|
for( size_t i = 0; i < connections.size(); i++ )
|
|
|
|
addConnectedItemsToBlock( connections[i] );
|
|
|
|
}
|
2011-03-10 19:36:30 +00:00
|
|
|
|
|
|
|
pickedlist->SetPickerFlags( item->GetFlags(), ii );
|
2011-01-07 19:24:24 +00:00
|
|
|
}
|
|
|
|
else if( item->IsConnectable() )
|
|
|
|
{
|
|
|
|
std::vector< wxPoint > connections;
|
|
|
|
|
|
|
|
item->GetConnectionPoints( connections );
|
|
|
|
|
|
|
|
for( size_t i = 0; i < connections.size(); i++ )
|
|
|
|
addConnectedItemsToBlock( connections[i] );
|
|
|
|
}
|
|
|
|
}
|
2011-01-20 11:26:10 +00:00
|
|
|
|
|
|
|
m_BlockLocate.Inflate(-1);
|
2011-01-07 19:24:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_SCREEN::addConnectedItemsToBlock( const wxPoint& position )
|
|
|
|
{
|
|
|
|
SCH_ITEM* item;
|
|
|
|
ITEM_PICKER picker;
|
2011-01-20 11:26:10 +00:00
|
|
|
bool addinlist = true;
|
2011-01-07 19:24:24 +00:00
|
|
|
|
2011-01-08 18:59:18 +00:00
|
|
|
for( item = GetDrawItems(); item != NULL; item = item->Next() )
|
2011-01-07 19:24:24 +00:00
|
|
|
{
|
2011-03-10 19:36:30 +00:00
|
|
|
picker.SetItem( item );
|
|
|
|
picker.SetItemType( item->Type() );
|
2011-01-07 19:24:24 +00:00
|
|
|
|
2011-01-21 19:30:59 +00:00
|
|
|
if( !item->IsConnectable() || !item->IsConnected( position )
|
2011-03-10 19:36:30 +00:00
|
|
|
|| (item->GetFlags() & SKIP_STRUCT) )
|
2011-01-07 19:24:24 +00:00
|
|
|
continue;
|
|
|
|
|
2011-01-20 11:26:10 +00:00
|
|
|
if( item->IsSelected() && item->Type() != SCH_LINE_T )
|
|
|
|
continue;
|
2011-01-07 19:24:24 +00:00
|
|
|
|
2011-01-20 11:26:10 +00:00
|
|
|
// A line having 2 ends, it can be tested twice: one time per end
|
2011-01-07 19:24:24 +00:00
|
|
|
if( item->Type() == SCH_LINE_T )
|
|
|
|
{
|
2011-01-20 11:26:10 +00:00
|
|
|
if( ! item->IsSelected() ) // First time this line is tested
|
2011-03-10 19:36:30 +00:00
|
|
|
item->SetFlags( SELECTED | STARTPOINT | ENDPOINT );
|
2011-01-20 11:26:10 +00:00
|
|
|
else // second time (or more) this line is tested
|
|
|
|
addinlist = false;
|
|
|
|
|
2011-01-07 19:24:24 +00:00
|
|
|
SCH_LINE* line = (SCH_LINE*) item;
|
|
|
|
|
|
|
|
if( line->m_Start == position )
|
2011-03-10 19:36:30 +00:00
|
|
|
item->ClearFlags( STARTPOINT );
|
2011-01-07 19:24:24 +00:00
|
|
|
else if( line->m_End == position )
|
2011-03-10 19:36:30 +00:00
|
|
|
item->ClearFlags( ENDPOINT );
|
2011-01-07 19:24:24 +00:00
|
|
|
}
|
2011-01-20 11:26:10 +00:00
|
|
|
else
|
2011-03-10 19:36:30 +00:00
|
|
|
item->SetFlags( SELECTED );
|
2011-01-07 19:24:24 +00:00
|
|
|
|
2011-01-20 11:26:10 +00:00
|
|
|
if( addinlist )
|
|
|
|
{
|
2011-03-10 19:36:30 +00:00
|
|
|
picker.m_PickerFlags = item->GetFlags();
|
2011-01-20 11:26:10 +00:00
|
|
|
m_BlockLocate.m_ItemsSelection.PushItem( picker );
|
|
|
|
}
|
2011-01-07 19:24:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-10 16:50:40 +00:00
|
|
|
int SCH_SCREEN::UpdatePickList()
|
|
|
|
{
|
|
|
|
ITEM_PICKER picker;
|
2011-03-29 19:33:07 +00:00
|
|
|
EDA_RECT area;
|
2011-01-10 16:50:40 +00:00
|
|
|
area.SetOrigin( m_BlockLocate.GetOrigin());
|
|
|
|
area.SetSize( m_BlockLocate.GetSize() );
|
|
|
|
area.Normalize();
|
|
|
|
|
|
|
|
for( SCH_ITEM* item = GetDrawItems(); item != NULL; item = item->Next() )
|
|
|
|
{
|
|
|
|
// An item is picked if its bounding box intersects the reference area.
|
|
|
|
if( item->HitTest( area ) )
|
|
|
|
{
|
2011-03-10 19:36:30 +00:00
|
|
|
picker.SetItem( item );
|
|
|
|
picker.SetItemType( item->Type() );
|
2011-01-10 16:50:40 +00:00
|
|
|
m_BlockLocate.PushItem( picker );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return m_BlockLocate.GetCount();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-21 19:30:59 +00:00
|
|
|
bool SCH_SCREEN::TestDanglingEnds( EDA_DRAW_PANEL* aCanvas, wxDC* aDC )
|
|
|
|
{
|
|
|
|
SCH_ITEM* item;
|
|
|
|
std::vector< DANGLING_END_ITEM > endPoints;
|
|
|
|
bool hasDanglingEnds = false;
|
|
|
|
|
|
|
|
for( item = GetDrawItems(); item != NULL; item = item->Next() )
|
|
|
|
item->GetEndPoints( endPoints );
|
|
|
|
|
|
|
|
for( item = GetDrawItems(); item; item = item->Next() )
|
|
|
|
{
|
|
|
|
if( item->IsDanglingStateChanged( endPoints ) && ( aCanvas != NULL ) && ( aDC != NULL ) )
|
|
|
|
{
|
|
|
|
item->Draw( aCanvas, aDC, wxPoint( 0, 0 ), g_XorMode );
|
|
|
|
item->Draw( aCanvas, aDC, wxPoint( 0, 0 ), GR_DEFAULT_DRAWMODE );
|
|
|
|
}
|
2011-01-23 21:22:42 +00:00
|
|
|
|
|
|
|
if( item->IsDangling() )
|
|
|
|
hasDanglingEnds = true;
|
2011-01-21 19:30:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return hasDanglingEnds;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool SCH_SCREEN::BreakSegment( const wxPoint& aPoint )
|
|
|
|
{
|
|
|
|
SCH_LINE* segment;
|
|
|
|
SCH_LINE* newSegment;
|
|
|
|
bool brokenSegments = false;
|
|
|
|
|
|
|
|
for( SCH_ITEM* item = GetDrawItems(); item != NULL; item = item->Next() )
|
|
|
|
{
|
2011-03-25 19:16:05 +00:00
|
|
|
if( (item->Type() != SCH_LINE_T) || (item->GetLayer() == LAYER_NOTES) )
|
2011-01-21 19:30:59 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
segment = (SCH_LINE*) item;
|
|
|
|
|
2011-03-25 19:16:05 +00:00
|
|
|
if( !segment->HitTest( aPoint, 0 ) || segment->IsEndPoint( aPoint ) )
|
2011-01-21 19:30:59 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
// Break the segment at aPoint and create a new segment.
|
|
|
|
newSegment = new SCH_LINE( *segment );
|
|
|
|
newSegment->m_Start = aPoint;
|
|
|
|
segment->m_End = newSegment->m_Start;
|
|
|
|
newSegment->SetNext( segment->Next() );
|
|
|
|
segment->SetNext( newSegment );
|
|
|
|
item = newSegment;
|
|
|
|
brokenSegments = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return brokenSegments;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool SCH_SCREEN::BreakSegmentsOnJunctions()
|
|
|
|
{
|
|
|
|
bool brokenSegments = false;
|
|
|
|
|
|
|
|
for( SCH_ITEM* item = GetDrawItems(); item != NULL; item = item->Next() )
|
|
|
|
{
|
|
|
|
if( item->Type() == SCH_JUNCTION_T )
|
|
|
|
{
|
|
|
|
SCH_JUNCTION* junction = ( SCH_JUNCTION* ) item;
|
|
|
|
|
|
|
|
if( BreakSegment( junction->m_Pos ) )
|
|
|
|
brokenSegments = true;
|
|
|
|
}
|
|
|
|
else if( item->Type() == SCH_BUS_ENTRY_T )
|
|
|
|
{
|
|
|
|
SCH_BUS_ENTRY* busEntry = ( SCH_BUS_ENTRY* ) item;
|
|
|
|
|
|
|
|
if( BreakSegment( busEntry->m_Pos ) || BreakSegment( busEntry->m_End() ) )
|
|
|
|
brokenSegments = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return brokenSegments;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-25 19:16:05 +00:00
|
|
|
int SCH_SCREEN::GetNode( const wxPoint& aPosition, EDA_ITEMS& aList )
|
|
|
|
{
|
|
|
|
for( SCH_ITEM* item = GetDrawItems(); item != NULL; item = item->Next() )
|
|
|
|
{
|
|
|
|
if( item->Type() == SCH_LINE_T && item->HitTest( aPosition )
|
|
|
|
&& (item->GetLayer() == LAYER_BUS || item->GetLayer() == LAYER_WIRE) )
|
|
|
|
{
|
|
|
|
aList.push_back( item );
|
|
|
|
}
|
|
|
|
else if( item->Type() == SCH_JUNCTION_T && item->HitTest( aPosition ) )
|
|
|
|
{
|
|
|
|
aList.push_back( item );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (int) aList.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SCH_LINE* SCH_SCREEN::GetWireOrBus( const wxPoint& aPosition )
|
|
|
|
{
|
|
|
|
for( SCH_ITEM* item = GetDrawItems(); item != NULL; item = item->Next() )
|
|
|
|
{
|
|
|
|
if( (item->Type() == SCH_LINE_T) && item->HitTest( aPosition )
|
|
|
|
&& (item->GetLayer() == LAYER_BUS || item->GetLayer() == LAYER_WIRE) )
|
|
|
|
{
|
|
|
|
return (SCH_LINE*) item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SCH_LINE* SCH_SCREEN::GetLine( const wxPoint& aPosition, int aAccuracy, int aLayer,
|
|
|
|
SCH_LINE_TEST_T aSearchType )
|
|
|
|
{
|
|
|
|
for( SCH_ITEM* item = GetDrawItems(); item != NULL; item = item->Next() )
|
|
|
|
{
|
|
|
|
if( item->Type() != SCH_LINE_T )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( item->GetLayer() != aLayer )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( !item->HitTest( aPosition, aAccuracy ) )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
switch( aSearchType )
|
|
|
|
{
|
|
|
|
case ENTIRE_LENGTH_T:
|
|
|
|
return (SCH_LINE*) item;
|
|
|
|
|
|
|
|
case EXCLUDE_END_POINTS_T:
|
|
|
|
if( !( (SCH_LINE*) item )->IsEndPoint( aPosition ) )
|
|
|
|
return (SCH_LINE*) item;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case END_POINTS_ONLY_T:
|
|
|
|
if( ( (SCH_LINE*) item )->IsEndPoint( aPosition ) )
|
|
|
|
return (SCH_LINE*) item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SCH_TEXT* SCH_SCREEN::GetLabel( const wxPoint& aPosition, int aAccuracy )
|
|
|
|
{
|
|
|
|
for( SCH_ITEM* item = GetDrawItems(); item != NULL; item = item->Next() )
|
|
|
|
{
|
|
|
|
switch( item->Type() )
|
|
|
|
{
|
|
|
|
case SCH_LABEL_T:
|
|
|
|
case SCH_GLOBAL_LABEL_T:
|
|
|
|
case SCH_HIERARCHICAL_LABEL_T:
|
|
|
|
if( item->HitTest( aPosition, aAccuracy ) )
|
|
|
|
return (SCH_TEXT*) item;
|
|
|
|
|
|
|
|
default:
|
|
|
|
;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-28 18:23:01 +00:00
|
|
|
bool SCH_SCREEN::SetComponentFootprint( SCH_SHEET_PATH* aSheetPath, const wxString& aReference,
|
|
|
|
const wxString& aFootPrint, bool aSetVisible )
|
|
|
|
{
|
|
|
|
SCH_COMPONENT* component;
|
|
|
|
bool found = false;
|
|
|
|
|
|
|
|
for( SCH_ITEM* item = GetDrawItems(); item != NULL; item = item->Next() )
|
|
|
|
{
|
|
|
|
if( item->Type() != SCH_COMPONENT_T )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
component = (SCH_COMPONENT*) item;
|
|
|
|
|
|
|
|
if( aReference.CmpNoCase( component->GetRef( aSheetPath ) ) == 0 )
|
|
|
|
{
|
|
|
|
// Found: Init Footprint Field
|
|
|
|
|
|
|
|
/* Give a reasonable value to the field position and
|
|
|
|
* orientation, if the text is empty at position 0, because
|
|
|
|
* it is probably not yet initialized
|
|
|
|
*/
|
2011-08-19 13:08:24 +00:00
|
|
|
SCH_FIELD * fpfield = component->GetField( FOOTPRINT );
|
|
|
|
if( fpfield->m_Text.IsEmpty()
|
|
|
|
&& ( fpfield->m_Pos == component->m_Pos ) )
|
2011-03-28 18:23:01 +00:00
|
|
|
{
|
2011-08-19 13:08:24 +00:00
|
|
|
fpfield->m_Orient = component->GetField( VALUE )->m_Orient;
|
|
|
|
fpfield->m_Pos = component->GetField( VALUE )->m_Pos;
|
|
|
|
fpfield->m_Size = component->GetField( VALUE )->m_Size;
|
|
|
|
if( fpfield->m_Orient == 0 )
|
|
|
|
fpfield->m_Pos.y += 100;
|
|
|
|
else
|
|
|
|
fpfield->m_Pos.x += 100;
|
2011-03-28 18:23:01 +00:00
|
|
|
}
|
|
|
|
|
2011-08-19 13:08:24 +00:00
|
|
|
fpfield->m_Text = aFootPrint;
|
2011-03-28 18:23:01 +00:00
|
|
|
|
|
|
|
if( aSetVisible )
|
2011-08-19 13:08:24 +00:00
|
|
|
fpfield->m_Attributs &= ~TEXT_NO_VISIBLE;
|
2011-03-28 18:23:01 +00:00
|
|
|
else
|
2011-08-19 13:08:24 +00:00
|
|
|
fpfield->m_Attributs |= TEXT_NO_VISIBLE;
|
2011-03-28 18:23:01 +00:00
|
|
|
|
|
|
|
found = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return found;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-15 12:40:56 +00:00
|
|
|
int SCH_SCREEN::GetConnection( const wxPoint& aPosition, PICKED_ITEMS_LIST& aList,
|
|
|
|
bool aFullConnection )
|
|
|
|
{
|
|
|
|
SCH_ITEM* item;
|
|
|
|
EDA_ITEM* tmp;
|
|
|
|
EDA_ITEMS list;
|
|
|
|
|
|
|
|
// Clear flags member for all items.
|
|
|
|
ClearDrawingState();
|
|
|
|
BreakSegmentsOnJunctions();
|
|
|
|
|
|
|
|
if( GetNode( aPosition, list ) == 0 )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
for( size_t i = 0; i < list.size(); i++ )
|
|
|
|
{
|
|
|
|
item = (SCH_ITEM*) list[ i ];
|
|
|
|
item->SetFlags( SELECTEDNODE | STRUCT_DELETED );
|
|
|
|
|
|
|
|
/* Put this structure in the picked list: */
|
|
|
|
ITEM_PICKER picker( item, UR_DELETED );
|
|
|
|
aList.PushItem( picker );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Mark all wires, junctions, .. connected to the item(s) found.
|
|
|
|
if( aFullConnection )
|
|
|
|
{
|
|
|
|
SCH_LINE* segment;
|
|
|
|
|
|
|
|
for( item = GetDrawItems(); item != NULL; item = item->Next() )
|
|
|
|
{
|
|
|
|
if( !(item->GetFlags() & SELECTEDNODE) )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( item->Type() != SCH_LINE_T )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
MarkConnections( (SCH_LINE*) item );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Search all attached wires (i.e wire with one new dangling end )
|
|
|
|
for( item = GetDrawItems(); item != NULL; item = item->Next() )
|
|
|
|
{
|
|
|
|
bool noconnect = false;
|
|
|
|
|
|
|
|
if( item->GetFlags() & STRUCT_DELETED )
|
|
|
|
continue; // Already seen
|
|
|
|
|
|
|
|
if( !(item->GetFlags() & CANDIDATE) )
|
2011-07-04 11:31:31 +00:00
|
|
|
continue; // not a candidate
|
2011-04-15 12:40:56 +00:00
|
|
|
|
|
|
|
if( item->Type() != SCH_LINE_T )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
item->SetFlags( SKIP_STRUCT );
|
|
|
|
|
|
|
|
segment = (SCH_LINE*) item;
|
|
|
|
|
2011-07-04 11:31:31 +00:00
|
|
|
/* If the wire start point is connected to a wire that was already found
|
2011-04-15 12:40:56 +00:00
|
|
|
* and now is not connected, add the wire to the list. */
|
|
|
|
for( tmp = GetDrawItems(); tmp != NULL; tmp = tmp->Next() )
|
|
|
|
{
|
2011-07-04 11:31:31 +00:00
|
|
|
// Ensure tmp is a previously deleted segment:
|
2011-04-15 12:40:56 +00:00
|
|
|
if( ( tmp->GetFlags() & STRUCT_DELETED ) == 0 )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( tmp->Type() != SCH_LINE_T )
|
|
|
|
continue;
|
|
|
|
|
2011-07-04 11:31:31 +00:00
|
|
|
SCH_LINE* testSegment = (SCH_LINE*) tmp;
|
2011-04-15 12:40:56 +00:00
|
|
|
|
2011-07-04 11:31:31 +00:00
|
|
|
// Test for segment connected to the previously deleted segment:
|
2011-04-15 12:40:56 +00:00
|
|
|
if( testSegment->IsEndPoint( segment->m_Start ) )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-07-04 11:31:31 +00:00
|
|
|
// when tmp != NULL, segment is a new candidate:
|
|
|
|
// put it in deleted list if
|
|
|
|
// the start point is not connected to an other item (like pin)
|
|
|
|
if( tmp && !CountConnectedItems( segment->m_Start, true ) )
|
2011-04-15 12:40:56 +00:00
|
|
|
noconnect = true;
|
|
|
|
|
|
|
|
/* If the wire end point is connected to a wire that has already been found
|
|
|
|
* and now is not connected, add the wire to the list. */
|
|
|
|
for( tmp = GetDrawItems(); tmp != NULL; tmp = tmp->Next() )
|
|
|
|
{
|
2011-07-04 11:31:31 +00:00
|
|
|
// Ensure tmp is a previously deleted segment:
|
2011-04-15 12:40:56 +00:00
|
|
|
if( ( tmp->GetFlags() & STRUCT_DELETED ) == 0 )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( tmp->Type() != SCH_LINE_T )
|
|
|
|
continue;
|
|
|
|
|
2011-07-04 11:31:31 +00:00
|
|
|
SCH_LINE* testSegment = (SCH_LINE*) tmp;
|
|
|
|
|
|
|
|
// Test for segment connected to the previously deleted segment:
|
2011-04-15 12:40:56 +00:00
|
|
|
if( testSegment->IsEndPoint( segment->m_End ) )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-07-04 11:31:31 +00:00
|
|
|
// when tmp != NULL, segment is a new candidate:
|
|
|
|
// put it in deleted list if
|
|
|
|
// the end point is not connected to an other item (like pin)
|
2011-04-15 12:40:56 +00:00
|
|
|
if( tmp && !CountConnectedItems( segment->m_End, true ) )
|
|
|
|
noconnect = true;
|
|
|
|
|
|
|
|
item->ClearFlags( SKIP_STRUCT );
|
|
|
|
|
|
|
|
if( noconnect )
|
|
|
|
{
|
|
|
|
item->SetFlags( STRUCT_DELETED );
|
|
|
|
|
|
|
|
ITEM_PICKER picker( item, UR_DELETED );
|
|
|
|
aList.PushItem( picker );
|
|
|
|
|
|
|
|
item = GetDrawItems();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get redundant junctions (junctions which connect < 3 end wires
|
|
|
|
// and no pin)
|
|
|
|
for( item = GetDrawItems(); item != NULL; item = item->Next() )
|
|
|
|
{
|
|
|
|
if( item->GetFlags() & STRUCT_DELETED )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( !(item->GetFlags() & CANDIDATE) )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( item->Type() != SCH_JUNCTION_T )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
SCH_JUNCTION* junction = (SCH_JUNCTION*) item;
|
|
|
|
|
|
|
|
if( CountConnectedItems( junction->m_Pos, false ) <= 2 )
|
|
|
|
{
|
|
|
|
item->SetFlags( STRUCT_DELETED );
|
|
|
|
|
|
|
|
ITEM_PICKER picker( item, UR_DELETED );
|
|
|
|
aList.PushItem( picker );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for( item = GetDrawItems(); item != NULL; item = item->Next() )
|
|
|
|
{
|
|
|
|
if( item->GetFlags() & STRUCT_DELETED )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( item->Type() != SCH_LABEL_T )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
tmp = GetWireOrBus( ( (SCH_TEXT*) item )->m_Pos );
|
|
|
|
|
|
|
|
if( tmp && tmp->GetFlags() & STRUCT_DELETED )
|
|
|
|
{
|
|
|
|
item->SetFlags( STRUCT_DELETED );
|
|
|
|
|
|
|
|
ITEM_PICKER picker( item, UR_DELETED );
|
|
|
|
aList.PushItem( picker );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ClearDrawingState();
|
|
|
|
|
|
|
|
return aList.GetCount();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-26 20:25:48 +00:00
|
|
|
/******************************************************************/
|
|
|
|
/* Class SCH_SCREENS to handle the list of screens in a hierarchy */
|
|
|
|
/******************************************************************/
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2010-12-31 19:47:39 +00:00
|
|
|
/**
|
|
|
|
* Function SortByTimeStamp
|
|
|
|
* sorts a list of schematic items by time stamp and type.
|
|
|
|
*/
|
2011-03-25 19:16:05 +00:00
|
|
|
static bool SortByTimeStamp( const EDA_ITEM* item1, const EDA_ITEM* item2 )
|
2010-12-31 19:47:39 +00:00
|
|
|
{
|
|
|
|
int ii = item1->m_TimeStamp - item2->m_TimeStamp;
|
|
|
|
|
|
|
|
/* If the time stamps are the same, compare type in order to have component objects
|
2011-02-09 12:06:42 +00:00
|
|
|
* before sheet object. This is done because changing the sheet time stamp
|
2010-12-31 19:47:39 +00:00
|
|
|
* before the component time stamp could cause the current annotation to be lost.
|
|
|
|
*/
|
|
|
|
if( ( ii == 0 && ( item1->Type() != item2->Type() ) ) && ( item1->Type() == SCH_SHEET_T ) )
|
|
|
|
ii = -1;
|
|
|
|
|
|
|
|
return ii < 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-26 20:25:48 +00:00
|
|
|
SCH_SCREENS::SCH_SCREENS()
|
2008-04-12 18:39:20 +00:00
|
|
|
{
|
2010-10-26 20:25:48 +00:00
|
|
|
m_index = 0;
|
2008-04-12 18:39:20 +00:00
|
|
|
BuildScreenList( g_RootSheet );
|
|
|
|
}
|
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
|
2010-10-26 20:25:48 +00:00
|
|
|
SCH_SCREENS::~SCH_SCREENS()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SCH_SCREEN* SCH_SCREENS::GetFirst()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2010-10-26 20:25:48 +00:00
|
|
|
m_index = 0;
|
|
|
|
|
|
|
|
if( m_screens.size() > 0 )
|
|
|
|
return m_screens[0];
|
|
|
|
|
2008-02-26 19:19:54 +00:00
|
|
|
return NULL;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2008-02-26 19:19:54 +00:00
|
|
|
|
2010-10-26 20:25:48 +00:00
|
|
|
SCH_SCREEN* SCH_SCREENS::GetNext()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2010-10-26 20:25:48 +00:00
|
|
|
if( m_index < m_screens.size() )
|
|
|
|
m_index++;
|
|
|
|
|
|
|
|
return GetScreen( m_index );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2010-10-26 20:25:48 +00:00
|
|
|
SCH_SCREEN* SCH_SCREENS::GetScreen( unsigned int aIndex )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2010-10-26 20:25:48 +00:00
|
|
|
if( aIndex < m_screens.size() )
|
|
|
|
return m_screens[ aIndex ];
|
|
|
|
|
2008-02-26 19:19:54 +00:00
|
|
|
return NULL;
|
2008-02-12 21:12:46 +00:00
|
|
|
}
|
2008-02-26 19:19:54 +00:00
|
|
|
|
|
|
|
|
2010-10-26 20:25:48 +00:00
|
|
|
void SCH_SCREENS::AddScreenToList( SCH_SCREEN* aScreen )
|
2008-02-12 21:12:46 +00:00
|
|
|
{
|
2010-10-26 20:25:48 +00:00
|
|
|
if( aScreen == NULL )
|
2008-02-26 19:19:54 +00:00
|
|
|
return;
|
2010-10-26 20:25:48 +00:00
|
|
|
|
|
|
|
for( unsigned int i = 0; i < m_screens.size(); i++ )
|
2008-02-26 19:19:54 +00:00
|
|
|
{
|
2010-10-26 20:25:48 +00:00
|
|
|
if( m_screens[i] == aScreen )
|
2008-02-26 19:19:54 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-10-26 20:25:48 +00:00
|
|
|
m_screens.push_back( aScreen );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
2008-02-26 19:19:54 +00:00
|
|
|
|
|
|
|
|
2010-12-08 20:12:46 +00:00
|
|
|
void SCH_SCREENS::BuildScreenList( EDA_ITEM* aItem )
|
2008-02-12 21:12:46 +00:00
|
|
|
{
|
2010-12-10 19:47:44 +00:00
|
|
|
if( aItem && aItem->Type() == SCH_SHEET_T )
|
2008-02-26 19:19:54 +00:00
|
|
|
{
|
2010-10-26 20:25:48 +00:00
|
|
|
SCH_SHEET* ds = (SCH_SHEET*) aItem;
|
2011-01-20 16:34:57 +00:00
|
|
|
aItem = ds->GetScreen();
|
2008-02-26 19:19:54 +00:00
|
|
|
}
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2010-12-10 19:47:44 +00:00
|
|
|
if( aItem && aItem->Type() == SCH_SCREEN_T )
|
2008-02-26 19:19:54 +00:00
|
|
|
{
|
2010-10-26 20:25:48 +00:00
|
|
|
SCH_SCREEN* screen = (SCH_SCREEN*) aItem;
|
2008-02-26 19:19:54 +00:00
|
|
|
AddScreenToList( screen );
|
2010-12-08 20:12:46 +00:00
|
|
|
EDA_ITEM* strct = screen->GetDrawItems();
|
|
|
|
|
2008-02-26 19:19:54 +00:00
|
|
|
while( strct )
|
|
|
|
{
|
2010-12-10 19:47:44 +00:00
|
|
|
if( strct->Type() == SCH_SHEET_T )
|
2008-02-26 19:19:54 +00:00
|
|
|
{
|
|
|
|
BuildScreenList( strct );
|
|
|
|
}
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2008-11-24 06:53:43 +00:00
|
|
|
strct = strct->Next();
|
2008-02-26 19:19:54 +00:00
|
|
|
}
|
|
|
|
}
|
2008-02-12 21:12:46 +00:00
|
|
|
}
|
2010-12-31 19:47:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
void SCH_SCREENS::ClearAnnotation()
|
|
|
|
{
|
|
|
|
for( size_t i = 0; i < m_screens.size(); i++ )
|
|
|
|
m_screens[i]->ClearAnnotation( NULL );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_SCREENS::SchematicCleanUp()
|
|
|
|
{
|
|
|
|
for( size_t i = 0; i < m_screens.size(); i++ )
|
|
|
|
{
|
|
|
|
// if wire list has changed, delete the undo/redo list to avoid
|
|
|
|
// pointer problems with deleted data.
|
2011-01-21 19:30:59 +00:00
|
|
|
if( m_screens[i]->SchematicCleanUp() )
|
2010-12-31 19:47:39 +00:00
|
|
|
m_screens[i]->ClearUndoRedoList();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int SCH_SCREENS::ReplaceDuplicateTimeStamps()
|
|
|
|
{
|
2011-03-25 19:16:05 +00:00
|
|
|
EDA_ITEMS items;
|
|
|
|
SCH_ITEM* item;
|
2010-12-31 19:47:39 +00:00
|
|
|
|
|
|
|
for( size_t i = 0; i < m_screens.size(); i++ )
|
|
|
|
m_screens[i]->GetHierarchicalItems( items );
|
|
|
|
|
|
|
|
if( items.size() < 2 )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
sort( items.begin(), items.end(), SortByTimeStamp );
|
|
|
|
|
|
|
|
int count = 0;
|
|
|
|
|
|
|
|
for( size_t ii = 0; ii < items.size() - 1; ii++ )
|
|
|
|
{
|
2011-03-25 19:16:05 +00:00
|
|
|
item = (SCH_ITEM*)items[ii];
|
|
|
|
|
|
|
|
SCH_ITEM* nextItem = (SCH_ITEM*)items[ii + 1];
|
2010-12-31 19:47:39 +00:00
|
|
|
|
|
|
|
if( item->m_TimeStamp == nextItem->m_TimeStamp )
|
|
|
|
{
|
|
|
|
count++;
|
|
|
|
|
|
|
|
// for a component, update its Time stamp and its paths
|
|
|
|
// (m_PathsAndReferences field)
|
|
|
|
if( item->Type() == SCH_COMPONENT_T )
|
|
|
|
( (SCH_COMPONENT*) item )->SetTimeStamp( GetTimeStamp() );
|
|
|
|
|
|
|
|
// for a sheet, update only its time stamp (annotation of its
|
|
|
|
// components will be lost)
|
|
|
|
// @todo: see how to change sheet paths for its cmp list (can
|
|
|
|
// be possible in most cases)
|
|
|
|
else
|
|
|
|
item->m_TimeStamp = GetTimeStamp();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_SCREENS::SetDate( const wxString& aDate )
|
|
|
|
{
|
|
|
|
for( size_t i = 0; i < m_screens.size(); i++ )
|
|
|
|
m_screens[i]->m_Date = aDate;
|
|
|
|
}
|
2011-03-10 19:36:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
void SCH_SCREENS::DeleteAllMarkers( int aMarkerType )
|
|
|
|
{
|
|
|
|
SCH_ITEM* item;
|
|
|
|
SCH_ITEM* nextItem;
|
|
|
|
SCH_MARKER* marker;
|
|
|
|
SCH_SCREEN* screen;
|
|
|
|
|
|
|
|
for( screen = GetFirst(); screen != NULL; screen = GetNext() )
|
|
|
|
{
|
|
|
|
for( item = screen->GetDrawItems(); item != NULL; item = nextItem )
|
|
|
|
{
|
|
|
|
nextItem = item->Next();
|
|
|
|
|
|
|
|
if( item->Type() != SCH_MARKER_T )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
marker = (SCH_MARKER*) item;
|
|
|
|
|
|
|
|
if( marker->GetMarkerType() != aMarkerType )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
screen->DeleteItem( marker );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-10-07 14:41:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
int SCH_SCREENS::GetMarkerCount( int aMarkerType )
|
|
|
|
{
|
|
|
|
SCH_ITEM* item;
|
|
|
|
SCH_ITEM* nextItem;
|
|
|
|
SCH_MARKER* marker;
|
|
|
|
SCH_SCREEN* screen;
|
|
|
|
int count = 0;
|
|
|
|
|
|
|
|
for( screen = GetFirst(); screen != NULL; screen = GetNext() )
|
|
|
|
{
|
|
|
|
for( item = screen->GetDrawItems(); item != NULL; item = nextItem )
|
|
|
|
{
|
|
|
|
nextItem = item->Next();
|
|
|
|
|
|
|
|
if( item->Type() != SCH_MARKER_T )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
marker = (SCH_MARKER*) item;
|
|
|
|
|
|
|
|
if( (aMarkerType != -1) && (marker->GetMarkerType() != aMarkerType) )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|