Commit 2694c524 authored by Wayne Stambaugh's avatar Wayne Stambaugh

EESchema back annotate code refactoring and other minor changes.

* Push schematic back annotation code down into the appropriate class.
* Minor improvements to back annotate file selection code and user prompt
  strings.
* Minor tool bar tool tip capitalization fixes.
* Change tool bar ID error from message dialog to a debug assert message.
parent 115d1adb
......@@ -17,78 +17,14 @@
#include "sch_component.h"
/**
* Function FillFootprintFieldForAllInstancesofComponent
* Search for component "aReference", and place a Footprint in Footprint field
* @param aReference = reference of the component to initialize
* @param aFootPrint = new value for the filed Footprint component
* @param aSetVisible = true to have the field visible, false to set the
* invisible flag
* @return true if the given component is found
* Note:
* the component is searched in the whole schematic, and because some
* components
* have more than one instance (multiple parts per package components)
* the search is not stopped when a reference is found (all instances must be
* found).
*/
bool SCH_EDIT_FRAME::FillFootprintFieldForAllInstancesofComponent( const wxString& aReference,
const wxString& aFootPrint,
bool aSetVisible )
{
SCH_SHEET_PATH* sheet;
SCH_ITEM* DrawList = NULL;
SCH_SHEET_LIST SheetList;
SCH_COMPONENT* Cmp;
bool found = false;
for( sheet = SheetList.GetFirst();
sheet != NULL;
sheet = SheetList.GetNext() )
{
DrawList = (SCH_ITEM*) sheet->LastDrawList();
for( ; (DrawList != NULL); DrawList = DrawList->Next() )
{
if( DrawList->Type() != SCH_COMPONENT_T )
continue;
Cmp = (SCH_COMPONENT*) DrawList;
if( aReference.CmpNoCase( Cmp->GetRef( sheet ) ) == 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
*/
if( Cmp->GetField( FOOTPRINT )->m_Text.IsEmpty()
&& ( Cmp->GetField( FOOTPRINT )->m_Pos == wxPoint( 0, 0 ) ) )
{
Cmp->GetField( FOOTPRINT )->m_Orient = Cmp->GetField(
VALUE )->m_Orient;
Cmp->GetField( FOOTPRINT )->m_Pos = Cmp->GetField(
VALUE )->m_Pos;
Cmp->GetField( FOOTPRINT )->m_Pos.y -= 100;
}
Cmp->GetField( FOOTPRINT )->m_Text = aFootPrint;
if( aSetVisible )
Cmp->GetField( FOOTPRINT )->m_Attributs &=
~TEXT_NO_VISIBLE;
else
Cmp->GetField( FOOTPRINT )->m_Attributs |= TEXT_NO_VISIBLE;
found = true;
}
}
}
return found;
}
const wxString BackAnnotateFileWildcard( wxT( "EESchema Back Annotation File (*.stf)|*.stf" ) );
bool SCH_EDIT_FRAME::ProcessStuffFile( FILE* aFilename, bool aSetFieldAttributeToVisible )
{
int LineNum = 0;
char* cp, Ref[256], FootPrint[256], Line[1024];
SCH_SHEET_LIST SheetList;
while( GetLine( aFilename, Line, &LineNum, sizeof(Line) ) )
{
......@@ -104,9 +40,7 @@ bool SCH_EDIT_FRAME::ProcessStuffFile( FILE* aFilename, bool aSetFieldAttributeT
wxString reference = FROM_UTF8( Ref );
wxString Footprint = FROM_UTF8( FootPrint );
FillFootprintFieldForAllInstancesofComponent( reference,
Footprint,
aSetFieldAttributeToVisible );
SheetList.SetComponentFootprint( reference, Footprint, aSetFieldAttributeToVisible );
}
}
......@@ -114,56 +48,44 @@ bool SCH_EDIT_FRAME::ProcessStuffFile( FILE* aFilename, bool aSetFieldAttributeT
}
/* Backann footprint info to schematic.
*/
bool SCH_EDIT_FRAME::ReadInputStuffFile()
{
wxString Line, filename;
FILE* StuffFile;
wxString title, filename;
FILE* file;
wxString msg;
bool SetFieldToVisible = true;
filename = EDA_FileSelector( _( "Load Stuff File" ),
wxEmptyString,
wxEmptyString,
wxT( ".stf" ),
wxT( "*.stf" ),
this,
wxFD_OPEN,
FALSE
);
if( filename.IsEmpty() )
return FALSE;
Line = wxGetApp().GetAppName() + wxT( " " ) + GetBuildVersion();
Line += wxT( " " ) + filename;
SetTitle( Line );
if( filename.IsEmpty() )
return FALSE;
int diag = wxMessageBox(
_( "Set the foot print field to visible?" ),
_( "Field Display Option" ),
wxYES_NO | wxICON_QUESTION | wxCANCEL, this );
if( diag == wxCANCEL )
bool visible = false;
wxFileDialog dlg( this, _( "Load Back Annotate File" ), wxEmptyString, wxEmptyString,
BackAnnotateFileWildcard, wxFD_OPEN | wxFD_FILE_MUST_EXIST );
if( dlg.ShowModal() == wxID_CANCEL )
return false;
if( diag == wxYES )
SetFieldToVisible = true;
else
SetFieldToVisible = false;
StuffFile = wxFopen( filename, wxT( "rt" ) );
if( StuffFile == NULL )
filename = dlg.GetPath();
title = wxGetApp().GetAppName() + wxT( " " ) + GetBuildVersion();
title += wxT( " " ) + filename;
SetTitle( title );
int response = wxMessageBox( _( "Do you want to make all the foot print fields visible?" ),
_( "Field Display Option" ),
wxYES_NO | wxICON_QUESTION | wxCANCEL, this );
if( response == wxCANCEL )
return false;
if( response == wxYES )
visible = true;
file = wxFopen( filename, wxT( "rt" ) );
if( file == NULL )
{
msg.Printf( _( "Failed to open stuff file <%s>" ), filename.GetData() );
DisplayError( this, msg, 20 );
return FALSE;
msg.Printf( _( "Failed to open back annotate file <%s>" ), filename.GetData() );
DisplayError( this, msg );
return false;
}
ProcessStuffFile( StuffFile, SetFieldToVisible );
ProcessStuffFile( file, visible );
return TRUE;
return true;
}
......@@ -992,6 +992,50 @@ SCH_TEXT* SCH_SCREEN::GetLabel( const wxPoint& aPosition, int aAccuracy )
}
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
*/
if( component->GetField( FOOTPRINT )->m_Text.IsEmpty()
&& ( component->GetField( FOOTPRINT )->m_Pos == wxPoint( 0, 0 ) ) )
{
component->GetField( FOOTPRINT )->m_Orient = component->GetField( VALUE )->m_Orient;
component->GetField( FOOTPRINT )->m_Pos = component->GetField( VALUE )->m_Pos;
component->GetField( FOOTPRINT )->m_Pos.y -= 100;
}
component->GetField( FOOTPRINT )->m_Text = aFootPrint;
if( aSetVisible )
component->GetField( FOOTPRINT )->m_Attributs &= ~TEXT_NO_VISIBLE;
else
component->GetField( FOOTPRINT )->m_Attributs |= TEXT_NO_VISIBLE;
found = true;
}
}
return found;
}
/******************************************************************/
/* Class SCH_SCREENS to handle the list of screens in a hierarchy */
/******************************************************************/
......
......@@ -448,6 +448,18 @@ SCH_ITEM* SCH_SHEET_PATH::MatchNextItem( wxFindReplaceData& aSearchData,
}
bool SCH_SHEET_PATH::SetComponentFootprint( const wxString& aReference, const wxString& aFootPrint,
bool aSetVisible )
{
SCH_SCREEN* screen = LastScreen();
if( screen == NULL )
return false;
return screen->SetComponentFootprint( this, aReference, aFootPrint, aSetVisible );
}
SCH_SHEET_PATH& SCH_SHEET_PATH::operator=( const SCH_SHEET_PATH& d1 )
{
if( this == &d1 ) // Self assignment is bad!
......@@ -786,3 +798,15 @@ SCH_ITEM* SCH_SHEET_LIST::MatchNextItem( wxFindReplaceData& aSearchData,
return NULL;
}
bool SCH_SHEET_LIST::SetComponentFootprint( const wxString& aReference,
const wxString& aFootPrint, bool aSetVisible )
{
bool found = false;
for( SCH_SHEET_PATH* path = GetFirst(); path != NULL; path = GetNext() )
found = path->SetComponentFootprint( aReference, aFootPrint, aSetVisible );
return found;
}
......@@ -100,27 +100,27 @@ public:
* @param aSheetPathToTest = sheet path to compare
* @return -1 if different, 0 if same
*/
int Cmp( const SCH_SHEET_PATH& aSheetPathToTest ) const;
int Cmp( const SCH_SHEET_PATH& aSheetPathToTest ) const;
/**
* Function Last
* returns a pointer to the last sheet of the list
* One can see the others sheet as the "path" to reach this last sheet
*/
SCH_SHEET* Last();
SCH_SHEET* Last();
/**
* Function LastScreen
* @return the SCH_SCREEN relative to the last sheet in list
*/
SCH_SCREEN* LastScreen();
SCH_SCREEN* LastScreen();
/**
* Function LastScreen
* @return a pointer to the first schematic item handled by the
* SCH_SCREEN relative to the last sheet in list
*/
SCH_ITEM* LastDrawList();
SCH_ITEM* LastDrawList();
/**
* Get the last schematic item relative to the first sheet in the list.
......@@ -128,7 +128,7 @@ public:
* @return Last schematic item relative to the first sheet in the list if list
* is not empty. Otherwise NULL.
*/
SCH_ITEM* FirstDrawList();
SCH_ITEM* FirstDrawList();
/**
* Function Push
......@@ -137,7 +137,7 @@ public:
* Push is used when entered a sheet to select or analyze it
* This is like cd &ltdirectory&gt in directories navigation
*/
void Push( SCH_SHEET* aSheet );
void Push( SCH_SHEET* aSheet );
/**
* Function Pop
......@@ -146,7 +146,7 @@ public:
* Pop is used when leaving a sheet after a selection or analyze
* This is like cd .. in directories navigation
*/
SCH_SHEET* Pop();
SCH_SHEET* Pop();
/**
* Function Path
......@@ -154,7 +154,7 @@ public:
* sheet parameters
* a path is something like / (root) or /34005677 or /34005677/00AE4523
*/
wxString Path();
wxString Path();
/**
* Function PathHumanReadable
......@@ -163,7 +163,7 @@ public:
* stamps in the path. (Time stamps do not change even when editing
* sheet parameters).
*/
wxString PathHumanReadable() const;
wxString PathHumanReadable() const;
/**
* Function BuildSheetPathInfoFromSheetPathValue
......@@ -172,8 +172,7 @@ public:
* @param aFound - Please document me.
* @return true if success else false
*/
bool BuildSheetPathInfoFromSheetPathValue( const wxString& aPath,
bool aFound = false );
bool BuildSheetPathInfoFromSheetPathValue( const wxString& aPath, bool aFound = false );
/**
* Function UpdateAllScreenReferences
......@@ -184,7 +183,7 @@ public:
* but with different references and part selections according to the
* displayed sheet
*/
void UpdateAllScreenReferences();
void UpdateAllScreenReferences();
/**
* Function AnnotatePowerSymbols
......@@ -202,8 +201,20 @@ public:
* @param aReferences List of references to populate.
* @param aIncludePowerSymbols Set to false to only get normal components.
*/
void GetComponents( SCH_REFERENCE_LIST& aReferences,
bool aIncludePowerSymbols = true );
void GetComponents( SCH_REFERENCE_LIST& aReferences, bool aIncludePowerSymbols = true );
/**
* Function SetFootprintField
* searches last sheet in the path for a component with \a aReference and set the footprint
* field to \a aFootPrint if found.
*
* @param aReference The reference designator of the component.
* @param aFootPrint The value to set the footprint fiield.
* @param aSetVisible The value to set the field visibility flag.
* @retrun True if \a aReference was found otherwise false.
*/
bool SetComponentFootprint( const wxString& aReference, const wxString& aFootPrint,
bool aSetVisible );
/**
* Find the next schematic item in this sheet ojbect.
......@@ -405,6 +416,19 @@ public:
SCH_ITEM* aLastItem,
wxPoint * aFindLocation );
/**
* Function SetFootprintField
* searches all the sheets for a component with \a aReference and set the footprint
* field to \a aFootPrint if found.
*
* @param aReference The reference designator of the component.
* @param aFootPrint The value to set the footprint fiield.
* @param aSetVisible The value to set the field visibility flag.
* @retrun True if \a aReference was found otherwise false.
*/
bool SetComponentFootprint( const wxString& aReference, const wxString& aFootPrint,
bool aSetVisible );
private:
/**
......
......@@ -100,19 +100,19 @@ void SCH_EDIT_FRAME::ReCreateHToolbar()
m_HToolBar->AddSeparator();
m_HToolBar->AddTool( ID_GET_NETLIST, wxEmptyString, wxBitmap( netlist_xpm ),
_( "Netlist generation" ) );
_( "Generate netlist" ) );
m_HToolBar->AddTool( ID_GET_ANNOTATE, wxEmptyString, wxBitmap( annotate_xpm ),
_( "Annotate schematic" ) );
m_HToolBar->AddTool( ID_GET_ERC, wxEmptyString, wxBitmap( erc_xpm ),
_( "Schematic Electric Rules Check" ) );
_( "Perform electric rules check" ) );
m_HToolBar->AddTool( ID_GET_TOOLS, wxEmptyString, wxBitmap( tools_xpm ),
_( "Bill of material and/or Cross references" ) );
_( "Generate bill of materials and/or cross references" ) );
m_HToolBar->AddTool( ID_BACKANNO_ITEMS, wxEmptyString, wxBitmap( backanno_xpm ),
_( "Backannotate footprint" ) );
_( "Back bnnotate component foot prints" ) );
// after adding the tools to the toolbar, must call Realize() to reflect the changes
m_HToolBar->Realize();
......@@ -254,7 +254,7 @@ void SCH_EDIT_FRAME::OnSelectOptionToolbar( wxCommandEvent& event )
break;
default:
DisplayError( this, wxT( "OnSelectOptionToolbar() error" ) );
wxFAIL_MSG( wxT( "Unexpected select option tool bar ID." ) );
break;
}
}
......@@ -357,6 +357,20 @@ public:
*/
SCH_TEXT* GetLabel( const wxPoint& aPosition, int aAccuracy = 0 );
/**
* Function SetFootprintField
* searches screen for a component with \a aReference and set the footprint field to
* \a aFootPrint if found.
*
* @param aSheetPath The sheet path used to look up the reference designator.
* @param aReference The reference designator of the component.
* @param aFootPrint The value to set the footprint fiield.
* @param aSetVisible The value to set the field visibility flag.
* @retrun True if \a aReference was found otherwise false.
*/
bool SetComponentFootprint( SCH_SHEET_PATH* aSheetPath, const wxString& aReference,
const wxString& aFootPrint, bool aSetVisible );
/**
* Function SelectBlockItems
* creates a list of items found when a block command is initiated. The items selected
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment