void NETLIST_EXPORTER::findAllInstancesOfComponent( SCH_COMPONENT* aComponent, LIB_PART* aEntry, SCH_SHEET_PATH* aSheetPath ) { wxString ref = aComponent->GetRef( aSheetPath ); wxString ref2; SCH_SHEET_LIST sheetList; for( SCH_SHEET_PATH* sheet = sheetList.GetFirst(); sheet; sheet = sheetList.GetNext() ) { for( EDA_ITEM* item = sheet->LastDrawList(); item; item = item->Next() ) { if( item->Type() != SCH_COMPONENT_T ) continue; SCH_COMPONENT* comp2 = (SCH_COMPONENT*) item; ref2 = comp2->GetRef( sheet ); if( ref2.CmpNoCase( ref ) != 0 ) continue; int unit2 = comp2->GetUnitSelection( sheet ); // slow for( LIB_PIN* pin = aEntry->GetNextPin(); pin; pin = aEntry->GetNextPin( pin ) ) { wxASSERT( pin->Type() == LIB_PIN_T ); if( pin->GetUnit() && pin->GetUnit() != unit2 ) continue; if( pin->GetConvert() && pin->GetConvert() != comp2->GetConvert() ) continue; // A suitable pin is found: add it to the current list addPinToComponentPinList( comp2, sheet, pin ); } } } }
void SCH_SHEET::GetNetListItem( NETLIST_OBJECT_LIST& aNetListItems, SCH_SHEET_PATH* aSheetPath ) { SCH_SHEET_PATH sheetPath = *aSheetPath; sheetPath.push_back( this ); for( size_t i = 0; i < m_pins.size(); i++ ) { NETLIST_OBJECT* item = new NETLIST_OBJECT(); item->m_SheetPathInclude = sheetPath; item->m_SheetPath = *aSheetPath; item->m_Comp = &m_pins[i]; item->m_Link = this; item->m_Type = NET_SHEETLABEL; item->m_Label = m_pins[i].GetText(); item->m_Start = item->m_End = m_pins[i].GetPosition(); aNetListItems.push_back( item ); if( IsBusLabel( m_pins[i].GetText() ) ) item->ConvertBusToNetListItems( aNetListItems ); } }
void DIALOG_PLOT_SCHEMATIC::createSVGFile( bool aPrintAll, bool aPrintFrameRef ) { wxString msg; if( aPrintAll ) { SCH_SHEET_PATH* sheetpath; SCH_SHEET_PATH oldsheetpath = m_parent->GetCurrentSheet(); SCH_SHEET_LIST SheetList( NULL ); sheetpath = SheetList.GetFirst(); SCH_SHEET_PATH list; WX_TEXT_CTRL_REPORTER reporter(m_MessagesBox); for( ; ; ) { if( sheetpath == NULL ) { break; } SCH_SCREEN* screen; list.Clear(); if( list.BuildSheetPathInfoFromSheetPathValue( sheetpath->Path() ) ) { m_parent->SetCurrentSheet( list ); m_parent->GetCurrentSheet().UpdateAllScreenReferences(); m_parent->SetSheetNumberAndCount(); screen = m_parent->GetCurrentSheet().LastScreen(); } else // Should not happen { return; } sheetpath = SheetList.GetNext(); try { wxString fname = m_parent->GetUniqueFilenameForCurrentSheet(); wxString ext = SVG_PLOTTER::GetDefaultFileExtension(); wxFileName plotFileName = createPlotFileName( m_outputDirectoryName, fname, ext, &reporter ); bool success = plotOneSheetSVG( m_parent, plotFileName.GetFullPath(), screen, getModeColor() ? false : true, aPrintFrameRef ); if( !success ) { msg.Printf( _( "Error creating file '%s'\n" ), GetChars( plotFileName.GetFullPath() ) ); } else { msg.Printf( _( "File '%s' OK\n" ), GetChars( plotFileName.GetFullPath() ) ); } m_MessagesBox->AppendText( msg ); } catch( const IO_ERROR& e ) { // Cannot plot SVG file msg.Printf( wxT( "SVG Plotter Exception : '%s'" ), GetChars( e.errorText ) ); m_MessagesBox->AppendText( msg ); m_parent->SetCurrentSheet( oldsheetpath ); m_parent->GetCurrentSheet().UpdateAllScreenReferences(); m_parent->SetSheetNumberAndCount(); return; } } m_parent->SetCurrentSheet( oldsheetpath ); m_parent->GetCurrentSheet().UpdateAllScreenReferences(); m_parent->SetSheetNumberAndCount(); } else // Print current sheet { SCH_SCREEN* screen = (SCH_SCREEN*) m_parent->GetScreen(); try { wxString fname = screen->GetFileName(); wxString ext = SVG_PLOTTER::GetDefaultFileExtension(); wxFileName fn = createPlotFileName( m_outputDirectoryName, fname, ext ); bool success = plotOneSheetSVG( m_parent, fn.GetFullPath(), screen, getModeColor() ? false : true, aPrintFrameRef ); if( success ) { msg.Printf( _( "Plot: <%s> OK\n" ), GetChars( fn.GetFullPath() ) ); } else // Error { msg.Printf( _( "Unable to create <%s>\n" ), GetChars( fn.GetFullPath() ) ); } m_MessagesBox->AppendText( msg ); } catch( const IO_ERROR& e ) { // Cannot plot SVG file msg.Printf( wxT( "SVG Plotter Exception : <%s>"), GetChars( e.errorText ) ); m_MessagesBox->AppendText( msg ); return; } } }
bool NETLIST_OBJECT_LIST::BuildNetListInfo( SCH_SHEET_LIST& aSheets ) { SCH_SHEET_PATH* sheet; // Fill list with connected items from the flattened sheet list for( unsigned i = 0; i < aSheets.size(); i++ ) { sheet = &aSheets[i]; for( SCH_ITEM* item = sheet->LastScreen()->GetDrawItems(); item; item = item->Next() ) { item->GetNetListItem( *this, sheet ); } } if( size() == 0 ) return false; // Sort objects by Sheet SortListbySheet(); sheet = &(GetItem( 0 )->m_SheetPath); m_lastNetCode = m_lastBusNetCode = 1; for( unsigned ii = 0, istart = 0; ii < size(); ii++ ) { NETLIST_OBJECT* net_item = GetItem( ii ); if( net_item->m_SheetPath != *sheet ) // Sheet change { sheet = &(net_item->m_SheetPath); istart = ii; } switch( net_item->m_Type ) { case NET_ITEM_UNSPECIFIED: wxMessageBox( wxT( "BuildNetListInfo() error" ) ); break; case NET_PIN: case NET_PINLABEL: case NET_SHEETLABEL: case NET_NOCONNECT: if( net_item->GetNet() != 0 ) break; case NET_SEGMENT: // Test connections point to point type without bus. if( net_item->GetNet() == 0 ) { net_item->SetNet( m_lastNetCode ); m_lastNetCode++; } pointToPointConnect( net_item, IS_WIRE, istart ); break; case NET_JUNCTION: // Control of the junction outside BUS. if( net_item->GetNet() == 0 ) { net_item->SetNet( m_lastNetCode ); m_lastNetCode++; } segmentToPointConnect( net_item, IS_WIRE, istart ); // Control of the junction, on BUS. if( net_item->m_BusNetCode == 0 ) { net_item->m_BusNetCode = m_lastBusNetCode; m_lastBusNetCode++; } segmentToPointConnect( net_item, IS_BUS, istart ); break; case NET_LABEL: case NET_HIERLABEL: case NET_GLOBLABEL: // Test connections type junction without bus. if( net_item->GetNet() == 0 ) { net_item->SetNet( m_lastNetCode ); m_lastNetCode++; } segmentToPointConnect( net_item, IS_WIRE, istart ); break; case NET_SHEETBUSLABELMEMBER: if( net_item->m_BusNetCode != 0 ) break; case NET_BUS: // Control type connections point to point mode bus if( net_item->m_BusNetCode == 0 ) { net_item->m_BusNetCode = m_lastBusNetCode; m_lastBusNetCode++; } pointToPointConnect( net_item, IS_BUS, istart ); break; case NET_BUSLABELMEMBER: case NET_HIERBUSLABELMEMBER: case NET_GLOBBUSLABELMEMBER: // Control connections similar has on BUS if( net_item->GetNet() == 0 ) { net_item->m_BusNetCode = m_lastBusNetCode; m_lastBusNetCode++; } segmentToPointConnect( net_item, IS_BUS, istart ); break; } } #if defined(NETLIST_DEBUG) && defined(DEBUG) std::cout << "\n\nafter sheet local\n\n"; DumpNetTable(); #endif // Updating the Bus Labels Netcode connected by Bus connectBusLabels(); // Group objects by label. for( unsigned ii = 0; ii < size(); ii++ ) { switch( GetItem( ii )->m_Type ) { case NET_PIN: case NET_SHEETLABEL: case NET_SEGMENT: case NET_JUNCTION: case NET_BUS: case NET_NOCONNECT: break; case NET_LABEL: case NET_GLOBLABEL: case NET_PINLABEL: case NET_BUSLABELMEMBER: case NET_GLOBBUSLABELMEMBER: labelConnect( GetItem( ii ) ); break; case NET_SHEETBUSLABELMEMBER: case NET_HIERLABEL: case NET_HIERBUSLABELMEMBER: break; case NET_ITEM_UNSPECIFIED: break; } } #if defined(NETLIST_DEBUG) && defined(DEBUG) std::cout << "\n\nafter sheet global\n\n"; DumpNetTable(); #endif // Connection between hierarchy sheets for( unsigned ii = 0; ii < size(); ii++ ) { if( GetItem( ii )->m_Type == NET_SHEETLABEL || GetItem( ii )->m_Type == NET_SHEETBUSLABELMEMBER ) sheetLabelConnect( GetItem( ii ) ); } // Sort objects by NetCode SortListbyNetcode(); #if defined(NETLIST_DEBUG) && defined(DEBUG) std::cout << "\n\nafter qsort()\n"; DumpNetTable(); #endif // Compress numbers of Netcode having consecutive values. int NetCode = 0; m_lastNetCode = 0; for( unsigned ii = 0; ii < size(); ii++ ) { if( GetItem( ii )->GetNet() != m_lastNetCode ) { NetCode++; m_lastNetCode = GetItem( ii )->GetNet(); } GetItem( ii )->SetNet( NetCode ); } // Set the minimal connection info: setUnconnectedFlag(); // find the best label object to give the best net name to each net findBestNetNameForEachNet(); return true; }
bool NETLIST_EXPORTER_CADSTAR::Write( const wxString& aOutFileName, unsigned aNetlistOptions ) { (void)aNetlistOptions; //unused int ret = 0; FILE* f = NULL; if( ( f = wxFopen( aOutFileName, wxT( "wt" ) ) ) == NULL ) { wxString msg; msg.Printf( _( "Failed to create file '%s'" ), GetChars( aOutFileName ) ); DisplayError( NULL, msg ); return false; } wxString StartCmpDesc = StartLine + wxT( "ADD_COM" ); wxString msg; wxString footprint; SCH_SHEET_PATH* sheet; EDA_ITEM* DrawList; SCH_COMPONENT* component; wxString title = wxT( "Eeschema " ) + GetBuildVersion(); ret |= fprintf( f, "%sHEA\n", TO_UTF8( StartLine ) ); ret |= fprintf( f, "%sTIM %s\n", TO_UTF8( StartLine ), TO_UTF8( DateAndTime() ) ); ret |= fprintf( f, "%sAPP ", TO_UTF8( StartLine ) ); ret |= fprintf( f, "\"%s\"\n", TO_UTF8( title ) ); ret |= fprintf( f, "\n" ); // Prepare list of nets generation for( unsigned ii = 0; ii < m_masterList->size(); ii++ ) m_masterList->GetItem( ii )->m_Flag = 0; // Create netlist module section m_ReferencesAlreadyFound.Clear(); SCH_SHEET_LIST SheetList; for( sheet = SheetList.GetFirst(); sheet != NULL; sheet = SheetList.GetNext() ) { for( DrawList = sheet->LastDrawList(); DrawList != NULL; DrawList = DrawList->Next() ) { DrawList = component = findNextComponentAndCreatePinList( DrawList, sheet ); if( component == NULL ) break; /* doing nothing with footprint if( !component->GetField( FOOTPRINT )->IsVoid() ) { footprint = component->GetField( FOOTPRINT )->m_Text; footprint.Replace( wxT( " " ), wxT( "_" ) ); } else footprint = wxT( "$noname" ); */ msg = component->GetRef( sheet ); ret |= fprintf( f, "%s ", TO_UTF8( StartCmpDesc ) ); ret |= fprintf( f, "%s", TO_UTF8( msg ) ); msg = component->GetField( VALUE )->GetText(); msg.Replace( wxT( " " ), wxT( "_" ) ); ret |= fprintf( f, " \"%s\"", TO_UTF8( msg ) ); ret |= fprintf( f, "\n" ); } } ret |= fprintf( f, "\n" ); m_SortedComponentPinList.clear(); if( ! writeListOfNets( f ) ) ret = -1; // set error ret |= fprintf( f, "\n%sEND\n", TO_UTF8( StartLine ) ); fclose( f ); return ret >= 0; }
void DIALOG_PLOT_SCHEMATIC::createPDFFile( bool aPlotAll, bool aPlotFrameRef ) { SCH_SCREEN* screen = m_parent->GetScreen(); SCH_SHEET_PATH* sheetpath; SCH_SHEET_PATH oldsheetpath = m_parent->GetCurrentSheet(); // sheetpath is saved here wxPoint plot_offset; /* When printing all pages, the printed page is not the current page. In * complex hierarchies, we must update component references and others * parameters in the given printed SCH_SCREEN, accordint to the sheet path * because in complex hierarchies a SCH_SCREEN (a drawing ) is shared * between many sheets and component references depend on the actual sheet * path used */ SCH_SHEET_LIST SheetList( NULL ); sheetpath = SheetList.GetFirst(); // Allocate the plotter and set the job level parameter PDF_PLOTTER* plotter = new PDF_PLOTTER(); plotter->SetDefaultLineWidth( GetDefaultLineThickness() ); plotter->SetColorMode( getModeColor() ); plotter->SetCreator( wxT( "Eeschema-PDF" ) ); wxString msg; wxString plotFileName; // First page handling is different bool first_page = true; do { // Step over the schematic hierarchy if( aPlotAll ) { SCH_SHEET_PATH list; if( list.BuildSheetPathInfoFromSheetPathValue( sheetpath->Path() ) ) { m_parent->SetCurrentSheet( list ); m_parent->GetCurrentSheet().UpdateAllScreenReferences(); m_parent->SetSheetNumberAndCount(); screen = m_parent->GetCurrentSheet().LastScreen(); } else // Should not happen wxASSERT( 0 ); sheetpath = SheetList.GetNext(); } if( first_page ) { plotFileName = m_parent->GetUniqueFilenameForCurrentSheet() + wxT( "." ) + PDF_PLOTTER::GetDefaultFileExtension(); if( ! plotter->OpenFile( plotFileName ) ) { msg.Printf( _( "** Unable to create %s **\n" ), GetChars( plotFileName ) ); m_MessagesBox->AppendText( msg ); delete plotter; return; } // Open the plotter and do the first page SetLocaleTo_C_standard(); setupPlotPagePDF( plotter, screen ); plotter->StartPlot(); first_page = false; } else { /* For the following pages you need to close the (finished) page, * reconfigure, and then start a new one */ plotter->ClosePage(); setupPlotPagePDF( plotter, screen ); plotter->StartPage(); } plotOneSheetPDF( plotter, screen, aPlotFrameRef ); } while( aPlotAll && sheetpath ); // Everything done, close the plot and restore the environment plotter->EndPlot(); delete plotter; SetLocaleTo_Default(); // Restore the previous sheet m_parent->SetCurrentSheet( oldsheetpath ); m_parent->GetCurrentSheet().UpdateAllScreenReferences(); m_parent->SetSheetNumberAndCount(); msg.Printf( _( "Plot: %s OK\n" ), GetChars( plotFileName ) ); m_MessagesBox->AppendText( msg ); }
XNODE* NETLIST_EXPORTER_GENERIC::makeComponents() { XNODE* xcomps = node( wxT( "components" ) ); wxString timeStamp; // some strings we need many times, but don't want to construct more // than once for performance. These are used within loops so the // enclosing wxString constructor would fire on each loop iteration if // they were in a nested scope. // these are actually constructor invocations, not assignments as it appears: wxString sFields = wxT( "fields" ); wxString sField = wxT( "field" ); wxString sComponent = wxT( "comp" ); // use "part" ? wxString sName = wxT( "name" ); wxString sRef = wxT( "ref" ); wxString sPins = wxT( "pins" ); wxString sPin = wxT( "pin" ); wxString sValue = wxT( "value" ); wxString sSheetPath = wxT( "sheetpath" ); wxString sFootprint = wxT( "footprint" ); wxString sDatasheet = wxT( "datasheet" ); wxString sTStamp = wxT( "tstamp" ); wxString sTStamps = wxT( "tstamps" ); wxString sTSFmt = wxT( "%8.8lX" ); // comp->m_TimeStamp wxString sLibSource = wxT( "libsource" ); wxString sLibPart = wxT( "libpart" ); wxString sLib = wxT( "lib" ); wxString sPart = wxT( "part" ); wxString sNames = wxT( "names" ); m_ReferencesAlreadyFound.Clear(); SCH_SHEET_LIST sheetList; // Output is xml, so there is no reason to remove spaces from the field values. // And XML element names need not be translated to various languages. for( SCH_SHEET_PATH* path = sheetList.GetFirst(); path; path = sheetList.GetNext() ) { for( EDA_ITEM* schItem = path->LastDrawList(); schItem; schItem = schItem->Next() ) { SCH_COMPONENT* comp = findNextComponentAndCreatePinList( schItem, path ); if( !comp ) break; // No component left schItem = comp; XNODE* xcomp; // current component being constructed // Output the component's elements in order of expected access frequency. // This may not always look best, but it will allow faster execution // under XSL processing systems which do sequential searching within // an element. xcomps->AddChild( xcomp = node( sComponent ) ); xcomp->AddAttribute( sRef, comp->GetRef( path->Last() ) ); xcomp->AddChild( node( sValue, comp->GetField( VALUE )->GetText() ) ); if( !comp->GetField( FOOTPRINT )->IsVoid() ) xcomp->AddChild( node( sFootprint, comp->GetField( FOOTPRINT )->GetText() ) ); if( !comp->GetField( DATASHEET )->IsVoid() ) xcomp->AddChild( node( sDatasheet, comp->GetField( DATASHEET )->GetText() ) ); // Export all user defined fields within the component, // which start at field index MANDATORY_FIELDS. Only output the <fields> // container element if there are any <field>s. if( comp->GetFieldCount() > MANDATORY_FIELDS ) { XNODE* xfields; xcomp->AddChild( xfields = node( sFields ) ); for( int fldNdx = MANDATORY_FIELDS; fldNdx < comp->GetFieldCount(); ++fldNdx ) { SCH_FIELD* f = comp->GetField( fldNdx ); // only output a field if non empty and not just "~" if( !f->IsVoid() ) { XNODE* xfield; xfields->AddChild( xfield = node( sField, f->GetText() ) ); xfield->AddAttribute( sName, f->GetName() ); } } } XNODE* xlibsource; xcomp->AddChild( xlibsource = node( sLibSource ) ); // "logical" library name, which is in anticipation of a better search // algorithm for parts based on "logical_lib.part" and where logical_lib // is merely the library name minus path and extension. LIB_PART* part = m_libs->FindLibPart( comp->GetPartName() ); if( part ) xlibsource->AddAttribute( sLib, part->GetLib()->GetLogicalName() ); xlibsource->AddAttribute( sPart, comp->GetPartName() ); XNODE* xsheetpath; xcomp->AddChild( xsheetpath = node( sSheetPath ) ); xsheetpath->AddAttribute( sNames, path->PathHumanReadable() ); xsheetpath->AddAttribute( sTStamps, path->Path() ); timeStamp.Printf( sTSFmt, (unsigned long)comp->GetTimeStamp() ); xcomp->AddChild( node( sTStamp, timeStamp ) ); } } return xcomps; }
XNODE* NETLIST_EXPORTER_GENERIC::makeDesignHeader() { SCH_SCREEN* screen; XNODE* xdesign = node( wxT("design") ); XNODE* xtitleBlock; XNODE* xsheet; XNODE* xcomment; wxString sheetTxt; wxFileName sourceFileName; // the root sheet is a special sheet, call it source xdesign->AddChild( node( wxT( "source" ), g_RootSheet->GetScreen()->GetFileName() ) ); xdesign->AddChild( node( wxT( "date" ), DateAndTime() ) ); // which Eeschema tool xdesign->AddChild( node( wxT( "tool" ), wxT( "Eeschema " ) + GetBuildVersion() ) ); /* Export the sheets information */ SCH_SHEET_LIST sheetList; for( SCH_SHEET_PATH* sheet = sheetList.GetFirst(); sheet; sheet = sheetList.GetNext() ) { screen = sheet->LastScreen(); xdesign->AddChild( xsheet = node( wxT( "sheet" ) ) ); // get the string representation of the sheet index number. // Note that sheet->GetIndex() is zero index base and we need to increment the number by one to make // human readable sheetTxt.Printf( wxT( "%d" ), ( sheetList.GetIndex() + 1 ) ); xsheet->AddAttribute( wxT( "number" ), sheetTxt ); xsheet->AddAttribute( wxT( "name" ), sheet->PathHumanReadable() ); xsheet->AddAttribute( wxT( "tstamps" ), sheet->Path() ); TITLE_BLOCK tb = screen->GetTitleBlock(); xsheet->AddChild( xtitleBlock = node( wxT( "title_block" ) ) ); xtitleBlock->AddChild( node( wxT( "title" ), tb.GetTitle() ) ); xtitleBlock->AddChild( node( wxT( "company" ), tb.GetCompany() ) ); xtitleBlock->AddChild( node( wxT( "rev" ), tb.GetRevision() ) ); xtitleBlock->AddChild( node( wxT( "date" ), tb.GetDate() ) ); // We are going to remove the fileName directories. sourceFileName = wxFileName( screen->GetFileName() ); xtitleBlock->AddChild( node( wxT( "source" ), sourceFileName.GetFullName() ) ); xtitleBlock->AddChild( xcomment = node( wxT( "comment" ) ) ); xcomment->AddAttribute( wxT("number"), wxT("1") ); xcomment->AddAttribute( wxT( "value" ), tb.GetComment1() ); xtitleBlock->AddChild( xcomment = node( wxT( "comment" ) ) ); xcomment->AddAttribute( wxT("number"), wxT("2") ); xcomment->AddAttribute( wxT( "value" ), tb.GetComment2() ); xtitleBlock->AddChild( xcomment = node( wxT( "comment" ) ) ); xcomment->AddAttribute( wxT("number"), wxT("3") ); xcomment->AddAttribute( wxT( "value" ), tb.GetComment3() ); xtitleBlock->AddChild( xcomment = node( wxT( "comment" ) ) ); xcomment->AddAttribute( wxT("number"), wxT("4") ); xcomment->AddAttribute( wxT( "value" ), tb.GetComment4() ); } return xdesign; }
void DIALOG_PLOT_SCHEMATIC::CreateDXFFile( bool aPlotAll, bool aPlotFrameRef ) { SCH_EDIT_FRAME* schframe = (SCH_EDIT_FRAME*) m_parent; SCH_SCREEN* screen = schframe->GetScreen(); SCH_SHEET_PATH* sheetpath; SCH_SHEET_PATH oldsheetpath = schframe->GetCurrentSheet(); /* When printing all pages, the printed page is not the current page. * In complex hierarchies, we must setup references and others parameters * in the printed SCH_SCREEN * because in complex hierarchies a SCH_SCREEN (a schematic drawings) * is shared between many sheets */ SCH_SHEET_LIST SheetList( NULL ); sheetpath = SheetList.GetFirst(); SCH_SHEET_PATH list; REPORTER& reporter = m_MessagesBox->Reporter(); while( true ) { if( aPlotAll ) { if( sheetpath == NULL ) break; list.Clear(); if( list.BuildSheetPathInfoFromSheetPathValue( sheetpath->Path() ) ) { schframe->SetCurrentSheet( list ); schframe->GetCurrentSheet().UpdateAllScreenReferences(); schframe->SetSheetNumberAndCount(); screen = schframe->GetCurrentSheet().LastScreen(); } else // Should not happen { return; } sheetpath = SheetList.GetNext(); } wxPoint plot_offset; wxString msg; try { wxString fname = schframe->GetUniqueFilenameForCurrentSheet(); wxString ext = DXF_PLOTTER::GetDefaultFileExtension(); wxFileName plotFileName = createPlotFileName( m_outputDirectoryName, fname, ext, &reporter ); if( PlotOneSheetDXF( plotFileName.GetFullPath(), screen, plot_offset, 1.0, aPlotFrameRef ) ) { msg.Printf( _( "Plot: '%s' OK.\n" ), GetChars( plotFileName.GetFullPath() ) ); reporter.Report( msg, REPORTER::ACTION ); } else // Error { msg.Printf( _( "Unable to create file '%s'.\n" ), GetChars( plotFileName.GetFullPath() ) ); reporter.Report( msg, REPORTER::ERROR ); } } catch( IO_ERROR& e ) { msg.Printf( wxT( "DXF Plotter exception: %s"), GetChars( e.errorText ) ); reporter.Report( msg, REPORTER::ERROR ); schframe->SetCurrentSheet( oldsheetpath ); schframe->GetCurrentSheet().UpdateAllScreenReferences(); schframe->SetSheetNumberAndCount(); return; } if( !aPlotAll ) { break; } } schframe->SetCurrentSheet( oldsheetpath ); schframe->GetCurrentSheet().UpdateAllScreenReferences(); schframe->SetSheetNumberAndCount(); }
void SCH_EDIT_FRAME::OnFindSchematicItem( wxFindDialogEvent& aEvent ) { static wxPoint itemPosition; // the actual position of the matched item. SCH_SHEET_LIST schematic; wxString msg; SCH_FIND_REPLACE_DATA searchCriteria; bool warpCursor = !( aEvent.GetFlags() & FR_NO_WARP_CURSOR ); SCH_FIND_COLLECTOR_DATA data; searchCriteria.SetFlags( aEvent.GetFlags() ); searchCriteria.SetFindString( aEvent.GetFindString() ); searchCriteria.SetReplaceString( aEvent.GetReplaceString() ); if( aEvent.GetEventType() == wxEVT_COMMAND_FIND_CLOSE ) { if( m_foundItems.GetCount() == 0 ) return; } else if( m_foundItems.IsSearchRequired( searchCriteria ) ) { if( aEvent.GetFlags() & FR_CURRENT_SHEET_ONLY && g_RootSheet->CountSheets() > 1 ) { m_foundItems.Collect( searchCriteria, m_CurrentSheet ); } else { m_foundItems.Collect( searchCriteria ); } } else { EDA_ITEM* currentItem = m_foundItems.GetItem( data ); if( currentItem != NULL ) currentItem->SetForceVisible( false ); m_foundItems.UpdateIndex(); } if( m_foundItems.GetItem( data ) != NULL ) { wxLogTrace( traceFindReplace, wxT( "Found " ) + m_foundItems.GetText() ); SCH_SHEET_PATH* sheet = schematic.GetSheet( data.GetSheetPath() ); wxCHECK_RET( sheet != NULL, wxT( "Could not find sheet path " ) + data.GetSheetPath() ); // Make the item temporarily visible just in case it's hide flag is set. This // has no effect on objects that don't support hiding. If this is a close find // dialog event, clear the temporary visibility flag. if( aEvent.GetEventType() == wxEVT_COMMAND_FIND_CLOSE ) m_foundItems.GetItem( data )->SetForceVisible( false ); else m_foundItems.GetItem( data )->SetForceVisible( true ); if( sheet->PathHumanReadable() != m_CurrentSheet->PathHumanReadable() ) { sheet->LastScreen()->SetZoom( GetScreen()->GetZoom() ); *m_CurrentSheet = *sheet; m_CurrentSheet->UpdateAllScreenReferences(); SetScreen( sheet->LastScreen() ); } sheet->LastScreen()->SetCrossHairPosition( data.GetPosition() ); RedrawScreen( data.GetPosition(), warpCursor ); msg = m_foundItems.GetText(); if( aEvent.GetFlags() & FR_SEARCH_REPLACE ) aEvent.SetFlags( aEvent.GetFlags() | FR_REPLACE_ITEM_FOUND ); } else { if( aEvent.GetFlags() & FR_SEARCH_REPLACE ) aEvent.SetFlags( aEvent.GetFlags() & ~FR_REPLACE_ITEM_FOUND ); msg.Printf( _( "No item found matching %s." ), GetChars( aEvent.GetFindString() ) ); } SetStatusText( msg ); }
SCH_ITEM* SCH_EDIT_FRAME::FindComponentAndItem( const wxString& aReference, bool aSearchHierarchy, SCH_SEARCH_T aSearchType, const wxString& aSearchText, bool aWarpMouse ) { SCH_SHEET_PATH* sheet; SCH_SHEET_PATH* sheetWithComponentFound = NULL; SCH_ITEM* item = NULL; SCH_COMPONENT* Component = NULL; wxPoint pos, curpos; bool centerAndRedraw = false; bool notFound = true; wxString msg; LIB_PIN* pin; SCH_SHEET_LIST sheetList; sheet = sheetList.GetFirst(); if( !aSearchHierarchy ) sheet = m_CurrentSheet; for( ; sheet != NULL; sheet = sheetList.GetNext() ) { item = (SCH_ITEM*) sheet->LastDrawList(); for( ; ( item != NULL ) && ( notFound == true ); item = item->Next() ) { if( item->Type() != SCH_COMPONENT_T ) continue; SCH_COMPONENT* pSch = (SCH_COMPONENT*) item; if( aReference.CmpNoCase( pSch->GetRef( sheet ) ) == 0 ) { Component = pSch; sheetWithComponentFound = sheet; switch( aSearchType ) { default: case FIND_COMPONENT_ONLY: // Find component only notFound = false; pos = pSch->GetPosition(); break; case FIND_PIN: // find a pin pos = pSch->GetPosition(); // temporary: will be changed if the pin is found. pin = pSch->GetPin( aSearchText ); if( pin == NULL ) break; notFound = false; pos += pin->GetPosition(); break; case FIND_REFERENCE: // find reference notFound = false; pos = pSch->GetField( REFERENCE )->GetPosition(); break; case FIND_VALUE: // find value pos = pSch->GetPosition(); if( aSearchText.CmpNoCase( pSch->GetField( VALUE )->m_Text ) != 0 ) break; notFound = false; pos = pSch->GetField( VALUE )->GetPosition(); break; } } } if( (aSearchHierarchy == false) || (notFound == false) ) break; } if( Component ) { sheet = sheetWithComponentFound; if( *sheet != *m_CurrentSheet ) { sheet->LastScreen()->SetZoom( GetScreen()->GetZoom() ); *m_CurrentSheet = *sheet; m_CurrentSheet->UpdateAllScreenReferences(); centerAndRedraw = true; } wxPoint delta; pos -= Component->GetPosition(); delta = Component->GetTransform().TransformCoordinate( pos ); pos = delta + Component->GetPosition(); /* There may be need to reframe the drawing */ if( ! m_canvas->IsPointOnDisplay( pos ) ) { centerAndRedraw = true; } if( centerAndRedraw ) { GetScreen()->SetCrossHairPosition(pos); RedrawScreen( pos, aWarpMouse ); } else { INSTALL_UNBUFFERED_DC( dc, m_canvas ); m_canvas->CrossHairOff( &dc ); if( aWarpMouse ) m_canvas->MoveCursor( pos ); GetScreen()->SetCrossHairPosition(pos); m_canvas->CrossHairOn( &dc ); } } /* Print diag */ wxString msg_item; msg = aReference; switch( aSearchType ) { default: case FIND_COMPONENT_ONLY: // Find component only break; case FIND_PIN: // find a pin msg_item = _( "Pin " ) + aSearchText; break; case FIND_REFERENCE: // find reference msg_item = _( "Ref " ) + aSearchText; break; case FIND_VALUE: // find value msg_item = _( "Value " ) + aSearchText; break; case FIND_FIELD: // find field. todo msg_item = _( "Field " ) + aSearchText; break; } if( Component ) { if( !notFound ) { if( !msg_item.IsEmpty() ) msg += wxT( " " ) + msg_item; msg += _( " found" ); } else { msg += _( " found" ); if( !msg_item.IsEmpty() ) { msg += wxT( " but " ) + msg_item + _( " not found" ); } } } else { if( !msg_item.IsEmpty() ) msg += wxT( " " ) + msg_item; msg += _( " not found" ); } SetStatusText( msg ); return item; }
void SCH_EDIT_FRAME::updateFindReplaceView( wxFindDialogEvent& aEvent ) { wxString msg; SCH_SHEET_LIST schematic( g_RootSheet ); SCH_FIND_COLLECTOR_DATA data; SCH_FIND_REPLACE_DATA searchCriteria; bool warpCursor = !( aEvent.GetFlags() & FR_NO_WARP_CURSOR ); searchCriteria.SetFlags( aEvent.GetFlags() ); searchCriteria.SetFindString( aEvent.GetFindString() ); searchCriteria.SetReplaceString( aEvent.GetReplaceString() ); if( m_foundItems.GetItem( data ) != NULL ) { wxLogTrace( traceFindReplace, wxT( "Found " ) + m_foundItems.GetText() ); SCH_SHEET_PATH* sheet = schematic.GetSheetByPath( data.GetSheetPath() ); wxCHECK_RET( sheet != NULL, wxT( "Could not find sheet path " ) + data.GetSheetPath() ); SCH_ITEM* item = (SCH_ITEM*)m_foundItems.GetItem( data ); // Make the item temporarily visible just in case it's hide flag is set. This // has no effect on objects that don't support hiding. If this is a close find // dialog event, clear the temporary visibility flag. if( item ) { if( aEvent.GetEventType() == wxEVT_COMMAND_FIND_CLOSE ) item->SetForceVisible( false ); else if( item->Type() == SCH_FIELD_T && !( (SCH_FIELD*) item )->IsVisible() ) item->SetForceVisible( true ); } if( sheet->PathHumanReadable() != m_CurrentSheet->PathHumanReadable() ) { sheet->LastScreen()->SetZoom( GetScreen()->GetZoom() ); *m_CurrentSheet = *sheet; m_CurrentSheet->UpdateAllScreenReferences(); SetScreen( sheet->LastScreen() ); } // careful here SetCrossHairPosition( data.GetPosition() ); RedrawScreen( data.GetPosition(), warpCursor ); msg = m_foundItems.GetText(); if( aEvent.GetFlags() & FR_SEARCH_REPLACE ) aEvent.SetFlags( aEvent.GetFlags() | FR_REPLACE_ITEM_FOUND ); } else { if( aEvent.GetFlags() & FR_SEARCH_REPLACE ) aEvent.SetFlags( aEvent.GetFlags() & ~FR_REPLACE_ITEM_FOUND ); msg.Printf( _( "No item found matching %s." ), GetChars( aEvent.GetFindString() ) ); } SetStatusText( msg ); }
SCH_ITEM* SCH_EDIT_FRAME::FindComponentAndItem( const wxString& aReference, bool aSearchHierarchy, SCH_SEARCH_T aSearchType, const wxString& aSearchText, bool aWarpMouse ) { SCH_SHEET_PATH* sheet = NULL; SCH_SHEET_PATH* sheetWithComponentFound = NULL; SCH_ITEM* item = NULL; SCH_COMPONENT* Component = NULL; wxPoint pos; bool centerAndRedraw = false; bool notFound = true; LIB_PIN* pin; SCH_SHEET_LIST sheetList( g_RootSheet ); if( !aSearchHierarchy ) sheetList.push_back( *m_CurrentSheet ); else sheetList.BuildSheetList( g_RootSheet ); for( SCH_SHEET_PATHS_ITER it = sheetList.begin(); it != sheetList.end(); ++it ) { sheet = &(*it); item = (*it).LastDrawList(); for( ; ( item != NULL ) && ( notFound == true ); item = item->Next() ) { if( item->Type() != SCH_COMPONENT_T ) continue; SCH_COMPONENT* pSch = (SCH_COMPONENT*) item; if( aReference.CmpNoCase( pSch->GetRef( sheet ) ) == 0 ) { Component = pSch; sheetWithComponentFound = sheet; switch( aSearchType ) { default: case FIND_COMPONENT_ONLY: // Find component only notFound = false; pos = pSch->GetPosition(); break; case FIND_PIN: // find a pin pos = pSch->GetPosition(); // temporary: will be changed if the pin is found. pin = pSch->GetPin( aSearchText ); if( pin == NULL ) break; notFound = false; pos += pin->GetPosition(); break; case FIND_REFERENCE: // find reference notFound = false; pos = pSch->GetField( REFERENCE )->GetPosition(); break; case FIND_VALUE: // find value pos = pSch->GetPosition(); if( aSearchText.CmpNoCase( pSch->GetField( VALUE )->GetShownText() ) != 0 ) break; notFound = false; pos = pSch->GetField( VALUE )->GetPosition(); break; } } } if( notFound == false ) break; } if( Component ) { sheet = sheetWithComponentFound; if( *sheet != *m_CurrentSheet ) { sheet->LastScreen()->SetZoom( GetScreen()->GetZoom() ); *m_CurrentSheet = *sheet; m_CurrentSheet->UpdateAllScreenReferences(); centerAndRedraw = true; } wxPoint delta; pos -= Component->GetPosition(); delta = Component->GetTransform().TransformCoordinate( pos ); pos = delta + Component->GetPosition(); /* There may be need to reframe the drawing */ if( ! m_canvas->IsPointOnDisplay( pos ) ) { centerAndRedraw = true; } if( centerAndRedraw ) { SetCrossHairPosition( pos ); RedrawScreen( pos, aWarpMouse ); } else { INSTALL_UNBUFFERED_DC( dc, m_canvas ); m_canvas->CrossHairOff( &dc ); if( aWarpMouse ) m_canvas->MoveCursor( pos ); SetCrossHairPosition( pos ); m_canvas->CrossHairOn( &dc ); } } /* Print diag */ wxString msg_item; wxString msg; switch( aSearchType ) { default: case FIND_COMPONENT_ONLY: // Find component only msg_item = _( "component" ); break; case FIND_PIN: // find a pin msg_item.Printf( _( "pin %s" ), GetChars( aSearchText ) ); break; case FIND_REFERENCE: // find reference msg_item.Printf( _( "reference %s" ), GetChars( aSearchText ) ); break; case FIND_VALUE: // find value msg_item.Printf( _( "value %s" ), GetChars( aSearchText ) ); break; case FIND_FIELD: // find field. todo msg_item.Printf( _( "field %s" ), GetChars( aSearchText ) ); break; } if( Component ) { if( !notFound ) { msg.Printf( _( "%s %s found" ), GetChars( aReference ), GetChars( msg_item ) ); } else { msg.Printf( _( "%s found but %s not found" ), GetChars( aReference ), GetChars( msg_item ) ); } } else { msg.Printf( _( "Component %s not found" ), GetChars( aReference ) ); } SetStatusText( msg ); return item; }
void DIALOG_PLOT_SCHEMATIC::createHPGLFile( bool aPlotAll, bool aPlotFrameRef ) { wxString plotFileName; SCH_SCREEN* screen = m_parent->GetScreen(); SCH_SHEET_PATH* sheetpath; SCH_SHEET_PATH oldsheetpath = m_parent->GetCurrentSheet(); /* When printing all pages, the printed page is not the current page. * In complex hierarchies, we must setup references and other parameters * in the printed SCH_SCREEN * because in complex hierarchies a SCH_SCREEN (a schematic drawings) * is shared between many sheets */ SCH_SHEET_LIST SheetList( NULL ); sheetpath = SheetList.GetFirst(); SCH_SHEET_PATH list; SetHPGLPenWidth(); while( true ) { if( aPlotAll ) { if( sheetpath == NULL ) break; list.Clear(); if( list.BuildSheetPathInfoFromSheetPathValue( sheetpath->Path() ) ) { m_parent->SetCurrentSheet( list ); m_parent->GetCurrentSheet().UpdateAllScreenReferences(); m_parent->SetSheetNumberAndCount(); screen = m_parent->GetCurrentSheet().LastScreen(); if( !screen ) // LastScreen() may return NULL screen = m_parent->GetScreen(); } else // Should not happen return; sheetpath = SheetList.GetNext(); } const PAGE_INFO& curPage = screen->GetPageSettings(); PAGE_INFO plotPage = curPage; // if plotting on a page size other than curPage if( m_HPGLPaperSizeOption->GetSelection() != PAGE_DEFAULT ) plotPage.SetType( plot_sheet_list( m_HPGLPaperSizeOption->GetSelection() ) ); // Calculation of conversion scales. double plot_scale = (double) plotPage.GetWidthMils() / curPage.GetWidthMils(); // Calculate offsets wxPoint plotOffset; if( GetPlotOriginCenter() ) { plotOffset.x = plotPage.GetWidthIU() / 2; plotOffset.y = -plotPage.GetHeightIU() / 2; } plotFileName = m_parent->GetUniqueFilenameForCurrentSheet() + wxT( "." ) + HPGL_PLOTTER::GetDefaultFileExtension(); plotFileName = Prj().AbsolutePath( plotFileName ); LOCALE_IO toggle; wxString msg; if( Plot_1_Page_HPGL( plotFileName, screen, plotPage, plotOffset, plot_scale, aPlotFrameRef ) ) msg.Printf( _( "Plot: <%s> OK\n" ), GetChars( plotFileName ) ); else // Error msg.Printf( _( "Unable to create <%s>\n" ), GetChars( plotFileName ) ); m_MessagesBox->AppendText( msg ); if( !aPlotAll ) break; } m_parent->SetCurrentSheet( oldsheetpath ); m_parent->GetCurrentSheet().UpdateAllScreenReferences(); m_parent->SetSheetNumberAndCount(); }
void SCH_SHEET_LIST::GetComponents( PART_LIBS* aLibs, SCH_REFERENCE_LIST& aReferences, bool aIncludePowerSymbols ) { for( SCH_SHEET_PATH* path = GetFirst(); path; path = GetNext() ) path->GetComponents( aLibs, aReferences, aIncludePowerSymbols ); }
void DIALOG_PLOT_SCHEMATIC::CreateDXFFile( bool aPlotAll, bool aPlotFrameRef ) { SCH_EDIT_FRAME* schframe = (SCH_EDIT_FRAME*) m_parent; SCH_SCREEN* screen = schframe->GetScreen(); SCH_SHEET_PATH* sheetpath; SCH_SHEET_PATH oldsheetpath = schframe->GetCurrentSheet(); wxString plotFileName; /* When printing all pages, the printed page is not the current page. * In complex hierarchies, we must setup references and others parameters * in the printed SCH_SCREEN * because in complex hierarchies a SCH_SCREEN (a schematic drawings) * is shared between many sheets */ SCH_SHEET_LIST SheetList( NULL ); sheetpath = SheetList.GetFirst(); SCH_SHEET_PATH list; while( true ) { if( aPlotAll ) { if( sheetpath == NULL ) break; list.Clear(); if( list.BuildSheetPathInfoFromSheetPathValue( sheetpath->Path() ) ) { schframe->SetCurrentSheet( list ); schframe->GetCurrentSheet().UpdateAllScreenReferences(); schframe->SetSheetNumberAndCount(); screen = schframe->GetCurrentSheet().LastScreen(); } else // Should not happen { return; } sheetpath = SheetList.GetNext(); } wxPoint plot_offset; plotFileName = schframe->GetUniqueFilenameForCurrentSheet() + wxT(".") + DXF_PLOTTER::GetDefaultFileExtension(); wxString msg; if( PlotOneSheetDXF( plotFileName, screen, plot_offset, 1.0, aPlotFrameRef ) ) msg.Printf( _( "Plot: <%s> OK\n" ), GetChars( plotFileName ) ); else // Error msg.Printf( _( "Unable to create <%s>\n" ), GetChars( plotFileName ) ); m_MessagesBox->AppendText( msg ); if( !aPlotAll ) break; } schframe->SetCurrentSheet( oldsheetpath ); schframe->GetCurrentSheet().UpdateAllScreenReferences(); schframe->SetSheetNumberAndCount(); }