std::pair<std::string, std::vector<std::string> > Animation::GetCurrentInfo() const { std::vector<std::string> each; for (size_t i = 0; i < numpts; ++i) { std::ostringstream each_string; auto info = GetAnimateInfo(i); each_string<<"pt "<<i<<": ("<<info.mPosition.x<<", "<<info.mPosition.y<<"), dir="<<info.mDirection<<", realdir="<<info.mRealDirection<<(info.mCollision ? ", collision!" : ""); each.push_back(each_string.str()); } std::ostringstream output; output<<GetCurrentSheetName()<<" ("<<GetCurrentSheet()<<" of "<<GetNumberSheets()<<")\n"; output<<"beat "<<GetCurrentBeat() <<" of "<<GetNumberBeats()<<"\n"; return std::pair<std::string, std::vector<std::string> >(output.str(), each); }
SCH_ITEM* SCH_EDIT_FRAME::LocateItem( const wxPoint& aPosition, const KICAD_T aFilterList[], int aHotKeyCommandId ) { SCH_ITEM* item = NULL; m_collectedItems.Collect( GetScreen()->GetDrawItems(), aFilterList, aPosition ); if( m_collectedItems.GetCount() == 0 ) { ClearMsgPanel(); } else if( m_collectedItems.GetCount() == 1 ) { item = m_collectedItems[0]; } else { // There are certain parent/child and enclosure combinations that can be handled // automatically. Since schematics are meant to be human-readable we don't have // all the various overlap and coverage issues that we do in Pcbnew. if( m_collectedItems.GetCount() == 2 ) { SCH_ITEM* a = m_collectedItems[ 0 ]; SCH_ITEM* b = m_collectedItems[ 1 ]; if( a->GetParent() == b ) item = a; else if( a == b->GetParent() ) item = b; else if( a->Type() == SCH_SHEET_T && b->Type() != SCH_SHEET_T ) item = b; else if( b->Type() == SCH_SHEET_T && a->Type() != SCH_SHEET_T ) item = a; } // There are certain combinations of items that do not need clarification such as // a corner were two lines meet or all the items form a junction. if( aHotKeyCommandId ) { switch( aHotKeyCommandId ) { case HK_DRAG: if( m_collectedItems.IsCorner() || m_collectedItems.IsNode( false ) || m_collectedItems.IsDraggableJunction() ) { item = m_collectedItems[0]; } break; case HK_MOVE_COMPONENT_OR_ITEM: if( m_collectedItems.GetCount() == 2 && dynamic_cast< SCH_SHEET_PIN * >( m_collectedItems[0] ) && dynamic_cast< SCH_SHEET * >( m_collectedItems[1] ) ) { item = m_collectedItems[0]; } break; default: ; } } if( item == NULL ) { wxASSERT_MSG( m_collectedItems.GetCount() <= MAX_SELECT_ITEM_IDS, wxT( "Select item clarification context menu size limit exceeded." ) ); wxMenu selectMenu; AddMenuItem( &selectMenu, wxID_NONE, _( "Clarify Selection" ), KiBitmap( info_xpm ) ); selectMenu.AppendSeparator(); for( int i = 0; i < m_collectedItems.GetCount() && i < MAX_SELECT_ITEM_IDS; i++ ) { wxString text = m_collectedItems[i]->GetSelectMenuText( m_UserUnits ); BITMAP_DEF xpm = m_collectedItems[i]->GetMenuImage(); AddMenuItem( &selectMenu, ID_SELECT_ITEM_START + i, text, KiBitmap( xpm ) ); } // Set to NULL in case the user aborts the clarification context menu. GetScreen()->SetCurItem( NULL ); m_canvas->SetAbortRequest( true ); // Changed to false if an item is selected PopupMenu( &selectMenu ); if( !m_canvas->GetAbortRequest() ) { m_canvas->MoveCursorToCrossHair(); item = GetScreen()->GetCurItem(); } } } GetScreen()->SetCurItem( item ); if( item ) { if( item->Type() == SCH_COMPONENT_T ) ( (SCH_COMPONENT*) item )->SetCurrentSheetPath( &GetCurrentSheet() ); MSG_PANEL_ITEMS items; item->GetMsgPanelInfo( m_UserUnits, items ); SetMsgPanel( items ); } else { ClearMsgPanel(); } return item; }
SCH_COMPONENT* SCH_EDIT_FRAME::Load_Component( wxDC* aDC, const SCHLIB_FILTER* aFilter, SCH_BASE_FRAME::HISTORY_LIST& aHistoryList, bool aUseLibBrowser ) { wxString msg; SetRepeatItem( NULL ); m_canvas->SetIgnoreMouseEvents( true ); auto sel = SelectComponentFromLibrary( aFilter, aHistoryList, aUseLibBrowser, 1, 1, m_footprintPreview ); if( !sel.LibId.IsValid() ) { m_canvas->SetIgnoreMouseEvents( false ); m_canvas->MoveCursorToCrossHair(); return NULL; } m_canvas->SetIgnoreMouseEvents( false ); m_canvas->MoveCursorToCrossHair(); wxString libsource; // the library name to use. If empty, load from any lib if( aFilter ) libsource = aFilter->GetLibSource(); LIB_ID libId = sel.LibId; LIB_PART* part = GetLibPart( libId, true ); if( !part ) return NULL; SCH_COMPONENT* component = new SCH_COMPONENT( *part, m_CurrentSheet, sel.Unit, sel.Convert, GetCrossHairPosition(), true ); // Set the m_ChipName value, from component name in lib, for aliases // Note if part is found, and if name is an alias of a component, // alias exists because its root component was found component->SetLibId( libId ); // Be sure the link to the corresponding LIB_PART is OK: component->Resolve( *Prj().SchSymbolLibTable() ); // Set any fields that have been modified for( auto const& i : sel.Fields ) { auto field = component->GetField( i.first ); if( field ) field->SetText( i.second ); } // Set the component value that can differ from component name in lib, for aliases component->GetField( VALUE )->SetText( sel.LibId.GetLibItemName() ); // If there is no field defined in the component, copy one over from the library // ( from the .dcm file ) // This way the Datasheet field will not be empty and can be changed from the schematic if( component->GetField( DATASHEET )->GetText().IsEmpty() ) { LIB_ALIAS* entry = GetLibAlias( component->GetLibId(), true, true ); if( entry && !!entry->GetDocFileName() ) component->GetField( DATASHEET )->SetText( entry->GetDocFileName() ); } MSG_PANEL_ITEMS items; component->SetCurrentSheetPath( &GetCurrentSheet() ); component->GetMsgPanelInfo( items ); SetMsgPanel( items ); component->Draw( m_canvas, aDC, wxPoint( 0, 0 ), g_XorMode ); component->SetFlags( IS_NEW ); if( m_autoplaceFields ) component->AutoplaceFields( /* aScreen */ NULL, /* aManual */ false ); PrepareMoveItem( (SCH_ITEM*) component, aDC ); return component; }
SCH_ITEM* SCH_EDIT_FRAME::LocateItem( const wxPoint& aPosition, const KICAD_T aFilterList[], int aHotKeyCommandId ) { SCH_ITEM* item = NULL; m_collectedItems.Collect( GetScreen()->GetDrawItems(), aFilterList, aPosition ); if( m_collectedItems.GetCount() == 0 ) { ClearMsgPanel(); } else if( m_collectedItems.GetCount() == 1 ) { item = m_collectedItems[0]; } else { // There are certain combinations of items that do not need clarification such as // a corner were two lines meet or all the items form a junction. if( aHotKeyCommandId ) { switch( aHotKeyCommandId ) { case HK_DRAG: if( m_collectedItems.IsCorner() || m_collectedItems.IsNode( false ) || m_collectedItems.IsDraggableJunction() ) { item = m_collectedItems[0]; } default: ; } } if( item == NULL ) { wxASSERT_MSG( m_collectedItems.GetCount() <= MAX_SELECT_ITEM_IDS, wxT( "Select item clarification context menu size limit exceeded." ) ); wxMenu selectMenu; wxMenuItem* title = new wxMenuItem( &selectMenu, wxID_NONE, _( "Clarify Selection" ) ); selectMenu.Append( title ); selectMenu.AppendSeparator(); for( int i = 0; i < m_collectedItems.GetCount() && i < MAX_SELECT_ITEM_IDS; i++ ) { wxString text = m_collectedItems[i]->GetSelectMenuText(); BITMAP_DEF xpm = m_collectedItems[i]->GetMenuImage(); AddMenuItem( &selectMenu, ID_SELECT_ITEM_START + i, text, KiBitmap( xpm ) ); } // Set to NULL in case user aborts the clarification context menu. GetScreen()->SetCurItem( NULL ); m_canvas->SetAbortRequest( true ); // Changed to false if an item is selected PopupMenu( &selectMenu ); m_canvas->MoveCursorToCrossHair(); item = GetScreen()->GetCurItem(); } } GetScreen()->SetCurItem( item ); if( item ) { if( item->Type() == SCH_COMPONENT_T ) ( (SCH_COMPONENT*) item )->SetCurrentSheetPath( &GetCurrentSheet() ); MSG_PANEL_ITEMS items; item->GetMsgPanelInfo( items ); SetMsgPanel( items ); } else { ClearMsgPanel(); } return item; }
void SCH_EDIT_FRAME::EditComponentFieldText( SCH_FIELD* aField ) { wxCHECK_RET( aField != NULL && aField->Type() == SCH_FIELD_T, wxT( "Cannot edit invalid schematic field." ) ); int fieldNdx; SCH_COMPONENT* component = (SCH_COMPONENT*) aField->GetParent(); wxCHECK_RET( component != NULL && component->Type() == SCH_COMPONENT_T, wxT( "Invalid schematic field parent item." ) ); LIB_PART* part = Prj().SchLibs()->FindLibPart( component->GetPartName() ); wxCHECK_RET( part, wxT( "Library part for component <" ) + component->GetPartName() + wxT( "> could not be found." ) ); fieldNdx = aField->GetId(); // Save old component in undo list if not already in edit, or moving. if( aField->GetFlags() == 0 ) SaveCopyInUndoList( component, UR_CHANGED ); // Don't use GetText() here. If the field is the reference designator and it's parent // component has multiple parts, we don't want the part suffix added to the field. m_canvas->SetIgnoreMouseEvents( true ); wxString title; title.Printf( _( "Edit %s Field" ), GetChars( aField->GetName() ) ); DIALOG_SCH_EDIT_ONE_FIELD dlg( this, title, aField ); // Value fields of power components cannot be modified. This will grey out // the text box and display an explanation. if( fieldNdx == VALUE && part->IsPower() ) { dlg.SetPowerWarning( true ); } //The diag may invoke a kiway player for footprint fields //so we must use a quasimodal int response = dlg.ShowQuasiModal(); m_canvas->MoveCursorToCrossHair(); m_canvas->SetIgnoreMouseEvents( false ); wxString newtext = dlg.GetTextField( ); if ( response != wxID_OK ) return; // canceled by user // make some tests bool can_update = true; if( !newtext.IsEmpty() ) { if( fieldNdx == REFERENCE ) { // Test if the reference string is valid: if( SCH_COMPONENT::IsReferenceStringValid( newtext ) ) { component->SetRef( m_CurrentSheet, newtext ); } else { DisplayError( this, _( "Illegal reference string! No change" ) ); can_update = false; } } } else { if( fieldNdx == REFERENCE ) { DisplayError( this, _( "The reference field cannot be empty! No change" ) ); can_update = false; } else if( fieldNdx == VALUE && ! part->IsPower() ) { // Note that power components also should not have empty value fields - but // since the user is forbidden from changing the value field here, if it // were to happen somehow, it'd be awfully confusing if an error were to // be displayed! DisplayError( this, _( "The value field cannot be empty! No change" ) ); can_update = false; } else if ( !( fieldNdx == VALUE && part->IsPower() ) ) { dlg.SetTextField( wxT( "~" ) ); } } if( can_update ) { dlg.TransfertDataToField( /* aIncludeText = */ !( fieldNdx == VALUE && part->IsPower() ) ); OnModify(); if( m_autoplaceFields ) component->AutoAutoplaceFields( GetScreen() ); m_canvas->Refresh(); } MSG_PANEL_ITEMS items; component->SetCurrentSheetPath( &GetCurrentSheet() ); component->GetMsgPanelInfo( items ); SetMsgPanel( items ); }
void SCH_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition ) { SCH_ITEM* item = GetScreen()->GetCurItem(); wxPoint gridPosition = GetGridPosition( aPosition ); if( ( GetToolId() == ID_NO_TOOL_SELECTED ) || ( item && item->GetFlags() ) ) { m_canvas->SetAutoPanRequest( false ); SetRepeatItem( NULL ); if( item && item->GetFlags() ) { switch( item->Type() ) { case SCH_LABEL_T: case SCH_GLOBAL_LABEL_T: case SCH_HIERARCHICAL_LABEL_T: case SCH_TEXT_T: case SCH_SHEET_PIN_T: case SCH_SHEET_T: case SCH_BUS_WIRE_ENTRY_T: case SCH_BUS_BUS_ENTRY_T: case SCH_JUNCTION_T: case SCH_COMPONENT_T: case SCH_FIELD_T: case SCH_BITMAP_T: case SCH_NO_CONNECT_T: addCurrentItemToList(); return; case SCH_LINE_T: // May already be drawing segment. break; default: wxFAIL_MSG( wxT( "SCH_EDIT_FRAME::OnLeftClick error. Item type <" ) + item->GetClass() + wxT( "> is already being edited." ) ); item->ClearFlags(); break; } } else { item = LocateAndShowItem( aPosition ); // Show the sheet information when the user clicks anywhere there are no items // in the schematic. if( item == NULL ) SetMsgPanel( GetCurrentSheet().Last() ); } } switch( GetToolId() ) { case ID_NO_TOOL_SELECTED: break; case ID_HIERARCHY_PUSH_POP_BUTT: if( ( item && item->GetFlags() ) || ( g_RootSheet->CountSheets() == 0 ) ) break; item = LocateAndShowItem( aPosition, SCH_COLLECTOR::SheetsOnly ); if( item ) // The user has clicked on a sheet: this is an enter sheet command { m_CurrentSheet->Push( (SCH_SHEET*) item ); DisplayCurrentSheet(); } else if( m_CurrentSheet->Last() != g_RootSheet ) { // The user has clicked ouside a sheet:this is an leave sheet command m_CurrentSheet->Pop(); DisplayCurrentSheet(); } break; case ID_NOCONN_BUTT: if( ( item == NULL ) || ( item->GetFlags() == 0 ) ) { if( GetScreen()->GetItem( gridPosition, 0, SCH_NO_CONNECT_T ) == NULL ) { SCH_NO_CONNECT* no_connect = AddNoConnect( aDC, gridPosition ); SetRepeatItem( no_connect ); GetScreen()->SetCurItem( no_connect ); m_canvas->SetAutoPanRequest( true ); } } else { addCurrentItemToList(); } break; case ID_JUNCTION_BUTT: if( ( item == NULL ) || ( item->GetFlags() == 0 ) ) { if( GetScreen()->GetItem( gridPosition, 0, SCH_JUNCTION_T ) == NULL ) { SCH_JUNCTION* junction = AddJunction( aDC, gridPosition, true ); SetRepeatItem( junction ); GetScreen()->SetCurItem( junction ); m_canvas->SetAutoPanRequest( true ); } } else { addCurrentItemToList(); } break; case ID_WIRETOBUS_ENTRY_BUTT: if( ( item == NULL ) || ( item->GetFlags() == 0 ) ) { CreateBusWireEntry(); m_canvas->SetAutoPanRequest( true ); } else { addCurrentItemToList(); } break; case ID_BUSTOBUS_ENTRY_BUTT: if( ( item == NULL ) || ( item->GetFlags() == 0 ) ) { CreateBusBusEntry(); m_canvas->SetAutoPanRequest( true ); } else { addCurrentItemToList(); } break; case ID_SCHEMATIC_DELETE_ITEM_BUTT: DeleteItemAtCrossHair( aDC ); break; case ID_WIRE_BUTT: BeginSegment( aDC, LAYER_WIRE ); m_canvas->SetAutoPanRequest( true ); break; case ID_BUS_BUTT: BeginSegment( aDC, LAYER_BUS ); m_canvas->SetAutoPanRequest( true ); break; case ID_LINE_COMMENT_BUTT: BeginSegment( aDC, LAYER_NOTES ); m_canvas->SetAutoPanRequest( true ); break; case ID_TEXT_COMMENT_BUTT: if( ( item == NULL ) || ( item->GetFlags() == 0 ) ) { GetScreen()->SetCurItem( CreateNewText( aDC, LAYER_NOTES ) ); m_canvas->SetAutoPanRequest( true ); } else { addCurrentItemToList(); } break; case ID_ADD_IMAGE_BUTT: if( ( item == NULL ) || ( item->GetFlags() == 0 ) ) { GetScreen()->SetCurItem( CreateNewImage( aDC ) ); m_canvas->SetAutoPanRequest( true ); } else { addCurrentItemToList(); } break; case ID_LABEL_BUTT: if( ( item == NULL ) || ( item->GetFlags() == 0 ) ) { GetScreen()->SetCurItem( CreateNewText( aDC, LAYER_LOCLABEL ) ); m_canvas->SetAutoPanRequest( true ); } else { addCurrentItemToList(); } break; case ID_GLABEL_BUTT: case ID_HIERLABEL_BUTT: if( (item == NULL) || (item->GetFlags() == 0) ) { if( GetToolId() == ID_GLABEL_BUTT ) GetScreen()->SetCurItem( CreateNewText( aDC, LAYER_GLOBLABEL ) ); if( GetToolId() == ID_HIERLABEL_BUTT ) GetScreen()->SetCurItem( CreateNewText( aDC, LAYER_HIERLABEL ) ); m_canvas->SetAutoPanRequest( true ); } else { addCurrentItemToList(); } break; case ID_SHEET_SYMBOL_BUTT: if( ( item == NULL ) || ( item->GetFlags() == 0 ) ) { item = CreateSheet( aDC ); if( item != NULL ) { GetScreen()->SetCurItem( item ); m_canvas->SetAutoPanRequest( true ); } } else { addCurrentItemToList(); } break; case ID_IMPORT_HLABEL_BUTT: case ID_SHEET_PIN_BUTT: if( ( item == NULL ) || ( item->GetFlags() == 0 ) ) item = LocateAndShowItem( aPosition, SCH_COLLECTOR::SheetsAndSheetLabels ); if( item == NULL ) break; if( (item->Type() == SCH_SHEET_T) && (item->GetFlags() == 0) ) { if( GetToolId() == ID_IMPORT_HLABEL_BUTT ) GetScreen()->SetCurItem( ImportSheetPin( (SCH_SHEET*) item, aDC ) ); else GetScreen()->SetCurItem( CreateSheetPin( (SCH_SHEET*) item, aDC ) ); } else if( (item->Type() == SCH_SHEET_PIN_T) && (item->GetFlags() != 0) ) { addCurrentItemToList(); } break; case ID_SCH_PLACE_COMPONENT: if( (item == NULL) || (item->GetFlags() == 0) ) { GetScreen()->SetCurItem( Load_Component( aDC, NULL, s_CmpNameList, s_CmpLastUnit, true ) ); m_canvas->SetAutoPanRequest( true ); } else { addCurrentItemToList(); } break; case ID_PLACE_POWER_BUTT: if( ( item == NULL ) || ( item->GetFlags() == 0 ) ) { SCHLIB_FILTER filter; filter.FilterPowerParts( true ); GetScreen()->SetCurItem( Load_Component( aDC, &filter, s_PowerNameList, s_LastPowerUnit, false ) ); m_canvas->SetAutoPanRequest( true ); } else { addCurrentItemToList(); } break; default: SetToolID( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor(), wxEmptyString ); wxFAIL_MSG( wxT( "SCH_EDIT_FRAME::OnLeftClick invalid tool ID <" ) + wxString::Format( wxT( "%d> selected." ), GetToolId() ) ); } }