2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
#include "fctsys.h"
|
2009-01-29 14:26:20 +00:00
|
|
|
#include "gr_basic.h"
|
2007-06-05 12:10:51 +00:00
|
|
|
#include "common.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 "class_sch_screen.h"
|
|
|
|
#include "wxEeschemaStruct.h"
|
2009-09-25 18:49:04 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
#include "general.h"
|
|
|
|
#include "protos.h"
|
2010-10-26 20:25:48 +00:00
|
|
|
#include "class_library.h"
|
2010-11-11 21:10:27 +00:00
|
|
|
#include "sch_items.h"
|
2010-12-21 15:13:09 +00:00
|
|
|
#include "sch_line.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"
|
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
|
|
|
|
2010-12-08 20:12:46 +00:00
|
|
|
void SetaParent( SCH_ITEM* Struct, SCH_SCREEN* Screen )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-09-01 12:00:30 +00:00
|
|
|
switch( Struct->Type() )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2010-12-10 19:47:44 +00:00
|
|
|
case SCH_POLYLINE_T:
|
|
|
|
case SCH_JUNCTION_T:
|
|
|
|
case SCH_TEXT_T:
|
|
|
|
case SCH_LABEL_T:
|
|
|
|
case SCH_GLOBAL_LABEL_T:
|
|
|
|
case SCH_HIERARCHICAL_LABEL_T:
|
|
|
|
case SCH_COMPONENT_T:
|
|
|
|
case SCH_LINE_T:
|
|
|
|
case SCH_BUS_ENTRY_T:
|
|
|
|
case SCH_SHEET_T:
|
|
|
|
case SCH_MARKER_T:
|
|
|
|
case SCH_NO_CONNECT_T:
|
2008-11-24 06:53:43 +00:00
|
|
|
Struct->SetParent( Screen );
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
|
2010-12-10 19:47:44 +00:00
|
|
|
case SCH_SHEET_LABEL_T:
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
/* Default EESchema zoom values. Limited to 17 values to keep a decent size
|
|
|
|
* to menus
|
|
|
|
*/
|
2009-02-06 11:45:35 +00:00
|
|
|
static int SchematicZoomList[] =
|
|
|
|
{
|
2009-02-14 18:01:07 +00:00
|
|
|
5, 7, 10, 15, 20, 30, 40, 60, 80, 120, 160, 230, 320, 480, 640, 800, 1280
|
2009-02-06 11:45:35 +00:00
|
|
|
};
|
2009-01-29 14:26:20 +00:00
|
|
|
|
2010-10-26 20:25:48 +00:00
|
|
|
#define SCHEMATIC_ZOOM_LIST_CNT ( sizeof( SchematicZoomList ) / sizeof( int ) )
|
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. */
|
2008-12-05 16:03:05 +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
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
void SCH_SCREEN::FreeDrawList()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2008-04-14 19:22:48 +00:00
|
|
|
SCH_ITEM* DrawStruct;
|
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
|
|
|
{
|
2010-12-08 20:12:46 +00:00
|
|
|
DrawStruct = GetDrawItems();
|
|
|
|
SetDrawItems( GetDrawItems()->Next() );
|
2008-02-26 19:19:54 +00:00
|
|
|
SAFE_DELETE( DrawStruct );
|
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
|
|
|
|
2010-12-08 20:12:46 +00:00
|
|
|
/* If found in GetDrawItems(), remove DrawStruct from GetDrawItems().
|
2007-08-20 01:20:48 +00:00
|
|
|
* DrawStruct is not deleted or modified
|
|
|
|
*/
|
2009-12-02 21:44:03 +00:00
|
|
|
void SCH_SCREEN::RemoveFromDrawList( SCH_ITEM * DrawStruct )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2010-12-08 20:12:46 +00:00
|
|
|
if( DrawStruct == GetDrawItems() )
|
|
|
|
{
|
|
|
|
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
|
|
|
{
|
2008-11-24 06:53:43 +00:00
|
|
|
if( DrawList->Next() == DrawStruct )
|
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;
|
|
|
|
}
|
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
|
|
|
|
|
|
|
|
2008-04-14 19:22:48 +00:00
|
|
|
bool SCH_SCREEN::CheckIfOnDrawList( SCH_ITEM* st )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2010-12-08 20:12:46 +00:00
|
|
|
SCH_ITEM * DrawList = GetDrawItems();
|
2008-02-26 19:19:54 +00:00
|
|
|
|
|
|
|
while( DrawList )
|
|
|
|
{
|
|
|
|
if( DrawList == st )
|
|
|
|
return true;
|
2008-04-14 19:22:48 +00:00
|
|
|
DrawList = DrawList->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
|
|
|
|
|
|
|
|
2008-04-14 19:22:48 +00:00
|
|
|
void SCH_SCREEN::AddToDrawList( SCH_ITEM* st )
|
2009-12-02 21:44:03 +00:00
|
|
|
{
|
2010-12-08 20:12:46 +00:00
|
|
|
st->SetNext( GetDrawItems() );
|
|
|
|
SetDrawItems( st );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2008-02-26 19:19:54 +00:00
|
|
|
|
2010-10-26 20:25:48 +00:00
|
|
|
/* Extract the old wires, junctions and buses, an if CreateCopy replace them
|
|
|
|
* by a copy. Old ones must be put in undo list, and the new ones can be
|
|
|
|
* modified by clean up safely.
|
2010-12-08 20:12:46 +00:00
|
|
|
* If an abort command is made, old wires must be put in GetDrawItems(), and
|
2010-10-26 20:25:48 +00:00
|
|
|
* copies must be deleted. This is because previously stored undo commands
|
|
|
|
* can handle pointers on wires or bus, and we do not delete wires or bus,
|
|
|
|
* we must put they in undo list.
|
|
|
|
*
|
|
|
|
* Because cleanup delete and/or modify bus and wires, the more easy is to put
|
|
|
|
* all wires in undo list and use a new copy of wires for cleanup.
|
|
|
|
*/
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Routine cleaning:
|
|
|
|
* - Includes segments or buses aligned in only 1 segment
|
|
|
|
* - Detects identical objects superimposed
|
|
|
|
*/
|
|
|
|
bool SCH_SCREEN::SchematicCleanUp( wxDC* DC )
|
|
|
|
{
|
|
|
|
SCH_ITEM* DrawList, * TstDrawList;
|
|
|
|
bool Modify = FALSE;
|
|
|
|
|
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 ) )
|
|
|
|
{
|
|
|
|
/* keep the bits set in .m_Flags, because the deleted
|
|
|
|
* segment can be flagged */
|
|
|
|
DrawList->m_Flags |= TstDrawList->m_Flags;
|
|
|
|
EraseStruct( TstDrawList, this );
|
|
|
|
SetRefreshReq();
|
2010-12-08 20:12:46 +00:00
|
|
|
TstDrawList = GetDrawItems();
|
2010-10-26 20:25:48 +00:00
|
|
|
Modify = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
TstDrawList = TstDrawList->Next();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
TstDrawList = TstDrawList->Next();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-08 20:12:46 +00:00
|
|
|
SCH_EDIT_FRAME* frame;
|
|
|
|
frame = (SCH_EDIT_FRAME*) wxGetApp().GetTopWindow();
|
|
|
|
frame->TestDanglingEnds( GetDrawItems(), DC );
|
2010-10-26 20:25:48 +00:00
|
|
|
|
|
|
|
return Modify;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function Save
|
|
|
|
* writes the data structures for this object out to a FILE in "*.sch" format.
|
|
|
|
* @param aFile The FILE to write to.
|
|
|
|
* @return bool - true if success writing else false.
|
|
|
|
*/
|
|
|
|
bool SCH_SCREEN::Save( FILE* aFile ) const
|
|
|
|
{
|
|
|
|
// Creates header
|
|
|
|
if( fprintf( aFile, "%s %s %d", EESCHEMA_FILE_STAMP,
|
|
|
|
SCHEMATIC_HEAD_STRING, EESCHEMA_VERSION ) < 0
|
|
|
|
|| fprintf( aFile, " date %s\n", CONV_TO_UTF8( DateAndTime() ) ) < 0 )
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
BOOST_FOREACH( const CMP_LIBRARY& lib, CMP_LIBRARY::GetLibraryList() )
|
|
|
|
{
|
|
|
|
if( fprintf( aFile, "LIBS:%s\n", CONV_TO_UTF8( lib.GetName() ) ) < 0 )
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( fprintf( aFile, "EELAYER %2d %2d\n", g_LayerDescr.NumberOfLayers,
|
|
|
|
g_LayerDescr.CurrentLayer ) < 0
|
|
|
|
|| fprintf( aFile, "EELAYER END\n" ) < 0 )
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
if( fprintf( aFile, "$Descr %s %d %d\n", CONV_TO_UTF8( m_CurrentSheetDesc->m_Name ),
|
|
|
|
m_CurrentSheetDesc->m_Size.x, m_CurrentSheetDesc->m_Size.y ) < 0
|
|
|
|
|| fprintf( aFile, "Sheet %d %d\n", m_ScreenNumber, m_NumberOfScreen ) < 0
|
|
|
|
|| fprintf( aFile, "Title \"%s\"\n", CONV_TO_UTF8( m_Title ) ) < 0
|
|
|
|
|| fprintf( aFile, "Date \"%s\"\n", CONV_TO_UTF8( m_Date ) ) < 0
|
|
|
|
|| fprintf( aFile, "Rev \"%s\"\n", CONV_TO_UTF8( m_Revision ) ) < 0
|
|
|
|
|| fprintf( aFile, "Comp \"%s\"\n", CONV_TO_UTF8( m_Company ) ) < 0
|
|
|
|
|| fprintf( aFile, "Comment1 \"%s\"\n", CONV_TO_UTF8( m_Commentaire1 ) ) < 0
|
|
|
|
|| fprintf( aFile, "Comment2 \"%s\"\n", CONV_TO_UTF8( m_Commentaire2 ) ) < 0
|
|
|
|
|| fprintf( aFile, "Comment3 \"%s\"\n", CONV_TO_UTF8( m_Commentaire3 ) ) < 0
|
|
|
|
|| fprintf( aFile, "Comment4 \"%s\"\n", CONV_TO_UTF8( m_Commentaire4 ) ) < 0
|
|
|
|
|| fprintf( aFile, "$EndDescr\n" ) < 0 )
|
|
|
|
return FALSE;
|
|
|
|
|
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 ) )
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( fprintf( aFile, "$EndSCHEMATC\n" ) < 0 )
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-12 16:36:43 +00:00
|
|
|
/**
|
|
|
|
* Function ClearUndoORRedoList
|
2010-10-26 20:25:48 +00:00
|
|
|
* free the undo or redo list from List element
|
|
|
|
* Wrappers are deleted.
|
|
|
|
* datas pointed by wrappers are deleted if not in use in schematic
|
|
|
|
* i.e. when they are copy of a schematic item or they are no more in use
|
|
|
|
* (DELETED)
|
|
|
|
* @param aList = the UNDO_REDO_CONTAINER to clear
|
|
|
|
* @param aItemCount = the count of items to remove. < 0 for all items
|
|
|
|
* items (commands stored in list) are removed from the beginning of the list.
|
|
|
|
* So this function can be called to remove old commands
|
|
|
|
*/
|
|
|
|
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() )
|
2010-11-03 14:13:15 +00:00
|
|
|
item->m_Flags = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-13 15:59:00 +00:00
|
|
|
LIB_PIN* SCH_SCREEN::GetPin( const wxPoint& aPosition, SCH_COMPONENT** aComponent )
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
|
|
|
pin = (LIB_PIN*) component->GetDrawItem( aPosition, LIB_PIN_T );
|
|
|
|
|
|
|
|
if( pin )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( aComponent )
|
|
|
|
*aComponent = component;
|
|
|
|
|
|
|
|
return pin;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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-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-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;
|
|
|
|
aItem = ds->m_AssociatedScreen;
|
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
|
|
|
}
|