SCH_SHEET_PIN* SCH_EDIT_FRAME::CreateSheetPin( SCH_SHEET* aSheet, wxDC* aDC ) { wxString line; SCH_SHEET_PIN* sheetPin; sheetPin = new SCH_SHEET_PIN( aSheet, wxPoint( 0, 0 ), line ); sheetPin->SetFlags( IS_NEW ); sheetPin->SetSize( m_lastSheetPinTextSize ); sheetPin->SetShape( m_lastSheetPinType ); int response = EditSheetPin( sheetPin, NULL ); if( sheetPin->GetText().IsEmpty() || (response == wxID_CANCEL) ) { delete sheetPin; return NULL; } m_lastSheetPinType = sheetPin->GetShape(); m_lastSheetPinTextSize = sheetPin->GetSize(); sheetPin->SetPosition( GetCrossHairPosition() ); sheetPin->Draw( m_canvas, aDC, wxPoint( 0, 0 ), g_XorMode ); MoveItem( (SCH_ITEM*) sheetPin, aDC ); OnModify(); return sheetPin; }
void SCH_SHEET_PIN::SwapData( SCH_ITEM* aItem ) { wxCHECK_RET( aItem->Type() == SCH_SHEET_PIN_T, wxString::Format( wxT( "SCH_SHEET_PIN object cannot swap data with %s object." ), GetChars( aItem->GetClass() ) ) ); SCH_SHEET_PIN* pin = ( SCH_SHEET_PIN* ) aItem; SCH_TEXT::SwapData( (SCH_TEXT*) pin ); int tmp = pin->GetNumber(); pin->SetNumber( GetNumber() ); SetNumber( tmp ); SHEET_SIDE stmp = pin->GetEdge(); pin->SetEdge( GetEdge() ); SetEdge( stmp ); }
void SCH_SCREEN::DeleteItem( SCH_ITEM* aItem ) { wxCHECK_RET( aItem, wxT( "Cannot delete invalid item from screen." ) ); SetModify(); if( aItem->Type() == SCH_SHEET_PIN_T ) { // This structure is attached to a sheet, get the parent sheet object. SCH_SHEET_PIN* sheetPin = (SCH_SHEET_PIN*) aItem; SCH_SHEET* sheet = sheetPin->GetParent(); wxCHECK_RET( sheet, wxT( "Sheet label parent not properly set, bad programmer!" ) ); sheet->RemovePin( sheetPin ); return; } else { delete m_drawList.Remove( aItem ); } }
SCH_SHEET_PIN* SCH_EDIT_FRAME::ImportSheetPin( SCH_SHEET* aSheet, wxDC* aDC ) { EDA_ITEM* item; SCH_SHEET_PIN* sheetPin; SCH_HIERLABEL* label = NULL; if( !aSheet->GetScreen() ) return NULL; item = aSheet->GetScreen()->GetDrawItems(); for( ; item != NULL; item = item->Next() ) { if( item->Type() != SCH_HIERARCHICAL_LABEL_T ) continue; label = (SCH_HIERLABEL*) item; /* A global label has been found: check if there a corresponding sheet label. */ if( !aSheet->HasPin( label->GetText() ) ) break; label = NULL; } if( label == NULL ) { DisplayInfoMessage( this, _( "No new hierarchical labels found." ) ); return NULL; } sheetPin = new SCH_SHEET_PIN( aSheet, wxPoint( 0, 0 ), label->GetText() ); sheetPin->SetFlags( IS_NEW ); sheetPin->SetSize( m_lastSheetPinTextSize ); m_lastSheetPinType = label->GetShape(); sheetPin->SetShape( label->GetShape() ); sheetPin->SetPosition( GetCrossHairPosition() ); sheetPin->Draw( m_canvas, aDC, wxPoint( 0, 0 ), g_XorMode ); MoveItem( (SCH_ITEM*) sheetPin, aDC ); return sheetPin; }
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->GetText() ) && 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, std::max( GetDefaultLineThickness(), 3 ), SCH_BUS_WIRE_ENTRY_T) ) return true; if( GetItem( aPosition, std::max( GetDefaultLineThickness(), 3 ), SCH_BUS_BUS_ENTRY_T) ) return true; if( GetItem( aPosition, std::max( GetDefaultLineThickness(), 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->GetText() ) ) return true; break; default: break; } return false; }
bool SCH_SHEET::Load( LINE_READER& aLine, wxString& aErrorMsg ) { int fieldNdx, size; SCH_SHEET_PIN* sheetPin; char* ptcar; SetTimeStamp( GetNewTimeStamp() ); // sheets are added to the GetDrawItems() like other schematic components. // however, in order to preserve the hierarchy (through m_Parent pointers), // a duplicate of the sheet is added to m_SubSheet array. // must be a duplicate, references just work for a two-layer structure. // this is accomplished through the Sync() function. if( ((char*)aLine)[0] == '$' ) // line should be "$Sheet" { if( !aLine.ReadLine() ) { aErrorMsg.Printf( wxT( "Read File Error" ) ); return false; } } /* Next line: must be "S xx yy nn mm" with xx, yy = sheet position * ( upper left corner ) et nn,mm = sheet size */ if( ( sscanf( &((char*)aLine)[1], "%d %d %d %d", &m_pos.x, &m_pos.y, &m_size.x, &m_size.y ) != 4 ) || ( ((char*)aLine)[0] != 'S' ) ) { aErrorMsg.Printf( wxT( " ** Eeschema file sheet struct error at line %d, aborted\n" ), aLine.LineNumber() ); aErrorMsg << FROM_UTF8( ((char*)aLine) ); return false; } /* Read fields */ for( ; ; ) /* Analysis of lines "Fn" text. */ { if( !aLine.ReadLine() ) return false; if( ((char*)aLine)[0] == 'U' ) { sscanf( ((char*)aLine) + 1, "%lX", &m_TimeStamp ); if( m_TimeStamp == 0 ) // zero is not unique! SetTimeStamp( GetNewTimeStamp() ); continue; } if( ((char*)aLine)[0] != 'F' ) break; sscanf( ((char*)aLine) + 1, "%d", &fieldNdx ); /* Read the field: * If fieldNdx> = 2: Fn "text" t s posx posy * If F0 "text" for SheetName * F1 and "text" for filename */ ptcar = ((char*)aLine); while( *ptcar && ( *ptcar != '"' ) ) ptcar++; if( *ptcar != '"' ) { aErrorMsg.Printf( wxT( "Eeschema file sheet label F%d at line %d, aborted\n" ), fieldNdx, aLine.LineNumber() ); aErrorMsg << FROM_UTF8( (char*) aLine ); return false; } wxString sheetName; ptcar += ReadDelimitedText( &sheetName, ptcar ); if( *ptcar == 0 ) { aErrorMsg.Printf( wxT( "Eeschema file sheet field F at line %d, aborted\n" ), aLine.LineNumber() ); aErrorMsg << FROM_UTF8( (char*) aLine ); return false; } if( ( fieldNdx == 0 ) || ( fieldNdx == 1 ) ) { if( sscanf( ptcar, "%d", &size ) != 1 ) { aErrorMsg.Printf( wxT( "Eeschema file sheet Label error line %d, aborted\n" ), aLine.LineNumber() ); aErrorMsg << FROM_UTF8( (char*) aLine ); } if( size == 0 ) size = DEFAULT_SIZE_TEXT; if( fieldNdx == 0 ) { m_name = sheetName; m_sheetNameSize = size; } else { SetFileName( sheetName ); m_fileNameSize = size; } } if( fieldNdx > 1 ) { sheetPin = new SCH_SHEET_PIN( this ); if( !sheetPin->Load( aLine, aErrorMsg ) ) { delete sheetPin; sheetPin = NULL; return false; } AddPin( sheetPin ); } } if( strnicmp( "$End", ((char*)aLine), 4 ) != 0 ) { aErrorMsg.Printf( wxT( "**Eeschema file end_sheet struct error at line %d, aborted\n" ), aLine.LineNumber() ); aErrorMsg << FROM_UTF8( ((char*)aLine) ); return false; } return true; }