bool LIB_EDIT_FRAME::LoadComponentAndSelectLib( LIB_ALIAS* aLibEntry, PART_LIB* aLibrary ) { if( GetScreen()->IsModify() && !IsOK( this, _( "The current component is not saved.\n\nDiscard current changes?" ) ) ) return false; SelectActiveLibrary( aLibrary ); return LoadComponentFromCurrentLib( aLibEntry ); }
bool LIB_EDIT_FRAME::LoadComponentAndSelectLib( const LIB_ID& aLibId, int aUnit, int aConvert ) { if( GetScreen()->IsModify() && GetCurPart() ) { if( !HandleUnsavedChanges( this, _( "The current symbol has been modified. Save changes?" ), [&]()->bool { return saveCurrentPart(); } ) ) { return false; } } SelectActiveLibrary( aLibId.GetLibNickname() ); return LoadComponentFromCurrentLib( aLibId.GetLibItemName(), aUnit, aConvert ); }
void LIB_EDIT_FRAME::DeleteOnePart( wxCommandEvent& event ) { wxString cmp_name; LIB_ALIAS* libEntry; wxArrayString nameList; wxString msg; m_canvas->EndMouseCapture( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor() ); m_lastDrawItem = NULL; m_drawItem = NULL; LIB_PART *part = GetCurPart(); PART_LIB* lib = GetCurLib(); if( !lib ) { SelectActiveLibrary(); lib = GetCurLib(); if( !lib ) { DisplayError( this, _( "Please select a component library." ) ); return; } } auto adapter( CMP_TREE_MODEL_ADAPTER::Create( Prj().SchLibs() ) ); wxString name = part ? part->GetName() : wxString( wxEmptyString ); adapter->SetPreselectNode( name, /* aUnit */ 0 ); adapter->ShowUnits( false ); adapter->AddLibrary( *lib ); wxString dialogTitle; dialogTitle.Printf( _( "Delete Component (%u items loaded)" ), adapter->GetComponentsCount() ); DIALOG_CHOOSE_COMPONENT dlg( this, dialogTitle, adapter, m_convert ); if( dlg.ShowModal() == wxID_CANCEL ) { return; } libEntry = dlg.GetSelectedAlias( NULL ); if( !libEntry ) { msg.Printf( _( "Entry '%s' not found in library '%s'." ), GetChars( libEntry->GetName() ), GetChars( lib->GetName() ) ); DisplayError( this, msg ); return; } msg.Printf( _( "Delete component '%s' from library '%s' ?" ), GetChars( libEntry->GetName() ), GetChars( lib->GetName() ) ); if( !IsOK( this, msg ) ) return; part = GetCurPart(); if( !part || !part->HasAlias( libEntry->GetName() ) ) { lib->RemoveAlias( libEntry ); m_canvas->Refresh(); return; } // If deleting the current entry or removing one of the aliases for // the current entry, sync the changes in the current entry as well. if( GetScreen()->IsModify() && !IsOK( this, _( "The component being deleted has been modified." " All changes will be lost. Discard changes?" ) ) ) { return; } LIB_ALIAS* nextEntry = lib->RemoveAlias( libEntry ); if( nextEntry != NULL ) { if( LoadOneLibraryPartAux( nextEntry, lib ) ) Zoom_Automatique( false ); } else { SetCurPart( NULL ); // delete CurPart m_aliasName.Empty(); } m_canvas->Refresh(); }
void LIB_EDIT_FRAME::LoadOneLibraryPart( wxCommandEvent& event ) { wxString cmp_name; LIB_ALIAS* libEntry = NULL; m_canvas->EndMouseCapture( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor() ); if( GetScreen()->IsModify() && !IsOK( this, _( "The current component is not saved.\n\nDiscard current changes?" ) ) ) return; PART_LIB* lib = GetCurLib(); // No current lib, ask user for the library to use. if( !lib ) { SelectActiveLibrary(); lib = GetCurLib(); if( !lib ) return; } // Get the name of the current part to preselect it LIB_PART* current_part = GetCurPart(); wxString part_name = current_part ? current_part->GetName() : wxString( wxEmptyString ); wxArrayString dummyHistoryList; int dummyLastUnit; SCHLIB_FILTER filter; filter.LoadFrom( lib->GetName() ); cmp_name = SelectComponentFromLibrary( &filter, dummyHistoryList, dummyLastUnit, true, NULL, NULL, part_name ); if( cmp_name.IsEmpty() ) return; GetScreen()->ClrModify(); m_lastDrawItem = m_drawItem = NULL; // Delete previous library component, if any SetCurPart( NULL ); m_aliasName.Empty(); // Load the new library component libEntry = lib->FindAlias( cmp_name ); PART_LIB* searchLib = lib; if( !libEntry ) { // Not found in the active library: search inside the full list // (can happen when using Viewlib to load a component) libEntry = Prj().SchLibs()->FindLibraryAlias( LIB_ID( wxEmptyString, cmp_name ) ); if( libEntry ) { searchLib = libEntry->GetLib(); // The entry to load is not in the active lib // Ask for a new active lib wxString msg = _( "The selected component is not in the active library." ); msg += "\n\n"; msg += _( "Do you want to change the active library?" ); if( IsOK( this, msg ) ) SelectActiveLibrary( searchLib ); } } if( !libEntry ) { wxString msg = wxString::Format( _( "Part name '%s' not found in library '%s'" ), GetChars( cmp_name ), GetChars( searchLib->GetName() ) ); DisplayError( this, msg ); return; } PART_LIB* old = SetCurLib( searchLib ); LoadComponentFromCurrentLib( libEntry ); SetCurLib( old ); DisplayLibInfos(); }
void LIB_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) { int id = event.GetId(); wxPoint pos; m_canvas->SetIgnoreMouseEvents( true ); wxGetMousePosition( &pos.x, &pos.y ); pos.y += 20; switch( id ) // Stop placement commands before handling new command. { case ID_POPUP_LIBEDIT_END_CREATE_ITEM: case ID_LIBEDIT_EDIT_PIN: case ID_POPUP_LIBEDIT_BODY_EDIT_ITEM: case ID_POPUP_LIBEDIT_FIELD_EDIT_ITEM: case ID_POPUP_LIBEDIT_PIN_GLOBAL_CHANGE_PINSIZE_ITEM: case ID_POPUP_LIBEDIT_PIN_GLOBAL_CHANGE_PINNAMESIZE_ITEM: case ID_POPUP_LIBEDIT_PIN_GLOBAL_CHANGE_PINNUMSIZE_ITEM: case ID_POPUP_ZOOM_BLOCK: case ID_POPUP_DELETE_BLOCK: case ID_POPUP_COPY_BLOCK: case ID_POPUP_SELECT_ITEMS_BLOCK: case ID_POPUP_MIRROR_X_BLOCK: case ID_POPUP_MIRROR_Y_BLOCK: case ID_POPUP_ROTATE_BLOCK: case ID_POPUP_PLACE_BLOCK: case ID_POPUP_LIBEDIT_DELETE_CURRENT_POLY_SEGMENT: break; case ID_POPUP_LIBEDIT_CANCEL_EDITING: if( m_canvas->IsMouseCaptured() ) m_canvas->EndMouseCapture(); else m_canvas->EndMouseCapture( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor() ); break; case ID_POPUP_LIBEDIT_DELETE_ITEM: m_canvas->EndMouseCapture(); break; default: m_canvas->EndMouseCapture( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor(), wxEmptyString ); break; } INSTALL_UNBUFFERED_DC( dc, m_canvas ); switch( id ) { case ID_POPUP_LIBEDIT_CANCEL_EDITING: break; case ID_LIBEDIT_SELECT_CURRENT_LIB: SelectActiveLibrary(); break; case ID_LIBEDIT_SAVE_CURRENT_PART: { LIB_PART* part = GetCurPart(); if( !part ) { DisplayError( this, _( "No part to save." ) ); break; } PART_LIB* lib = GetCurLib(); if( !lib ) SelectActiveLibrary(); lib = GetCurLib(); if( !lib ) { DisplayError( this, _( "No library specified." ) ); break; } SaveOnePart( lib ); } break; case ID_LIBEDIT_EDIT_PIN_BY_PIN: m_editPinsPerPartOrConvert = m_mainToolBar->GetToolToggled( ID_LIBEDIT_EDIT_PIN_BY_PIN ); break; case ID_POPUP_LIBEDIT_END_CREATE_ITEM: m_canvas->MoveCursorToCrossHair(); if( m_drawItem ) { EndDrawGraphicItem( &dc ); } break; case ID_POPUP_LIBEDIT_BODY_EDIT_ITEM: if( m_drawItem ) { m_canvas->CrossHairOff( &dc ); switch( m_drawItem->Type() ) { case LIB_ARC_T: case LIB_CIRCLE_T: case LIB_RECTANGLE_T: case LIB_POLYLINE_T: EditGraphicSymbol( &dc, m_drawItem ); break; case LIB_TEXT_T: EditSymbolText( &dc, m_drawItem ); break; default: ; } m_canvas->CrossHairOn( &dc ); } break; case ID_POPUP_LIBEDIT_DELETE_CURRENT_POLY_SEGMENT: { // Delete the last created segment, while creating a polyline draw item if( m_drawItem == NULL ) break; m_canvas->MoveCursorToCrossHair(); STATUS_FLAGS oldFlags = m_drawItem->GetFlags(); m_drawItem->ClearFlags(); m_drawItem->Draw( m_canvas, &dc, wxPoint( 0, 0 ), UNSPECIFIED_COLOR, g_XorMode, NULL, DefaultTransform ); ( (LIB_POLYLINE*) m_drawItem )->DeleteSegment( GetCrossHairPosition( true ) ); m_drawItem->Draw( m_canvas, &dc, wxPoint( 0, 0 ), UNSPECIFIED_COLOR, g_XorMode, NULL, DefaultTransform ); m_drawItem->SetFlags( oldFlags ); m_lastDrawItem = NULL; } break; case ID_POPUP_LIBEDIT_DELETE_ITEM: if( m_drawItem ) deleteItem( &dc ); break; case ID_POPUP_LIBEDIT_MOVE_ITEM_REQUEST: if( m_drawItem == NULL ) break; if( m_drawItem->Type() == LIB_PIN_T ) StartMovePin( &dc ); else StartMoveDrawSymbol( &dc ); break; case ID_POPUP_LIBEDIT_MODIFY_ITEM: if( m_drawItem == NULL ) break; m_canvas->MoveCursorToCrossHair(); if( m_drawItem->Type() == LIB_RECTANGLE_T || m_drawItem->Type() == LIB_CIRCLE_T || m_drawItem->Type() == LIB_POLYLINE_T || m_drawItem->Type() == LIB_ARC_T ) { StartModifyDrawSymbol( &dc ); } break; case ID_POPUP_LIBEDIT_FIELD_EDIT_ITEM: if( m_drawItem == NULL ) break; m_canvas->CrossHairOff( &dc ); if( m_drawItem->Type() == LIB_FIELD_T ) { EditField( (LIB_FIELD*) m_drawItem ); } m_canvas->MoveCursorToCrossHair(); m_canvas->CrossHairOn( &dc ); break; case ID_POPUP_LIBEDIT_PIN_GLOBAL_CHANGE_PINSIZE_ITEM: case ID_POPUP_LIBEDIT_PIN_GLOBAL_CHANGE_PINNAMESIZE_ITEM: case ID_POPUP_LIBEDIT_PIN_GLOBAL_CHANGE_PINNUMSIZE_ITEM: { if( !m_drawItem || m_drawItem->Type() != LIB_PIN_T ) break; LIB_PART* part = GetCurPart(); SaveCopyInUndoList( part ); GlobalSetPins( (LIB_PIN*) m_drawItem, id ); m_canvas->MoveCursorToCrossHair(); m_canvas->Refresh(); } break; case ID_POPUP_ZOOM_BLOCK: m_canvas->SetAutoPanRequest( false ); GetScreen()->m_BlockLocate.SetCommand( BLOCK_ZOOM ); HandleBlockEnd( &dc ); break; case ID_POPUP_DELETE_BLOCK: m_canvas->SetAutoPanRequest( false ); GetScreen()->m_BlockLocate.SetCommand( BLOCK_DELETE ); m_canvas->MoveCursorToCrossHair(); HandleBlockEnd( &dc ); break; case ID_POPUP_COPY_BLOCK: m_canvas->SetAutoPanRequest( false ); GetScreen()->m_BlockLocate.SetCommand( BLOCK_COPY ); m_canvas->MoveCursorToCrossHair(); HandleBlockEnd( &dc ); break; case ID_POPUP_SELECT_ITEMS_BLOCK: m_canvas->SetAutoPanRequest( false ); GetScreen()->m_BlockLocate.SetCommand( BLOCK_SELECT_ITEMS_ONLY ); m_canvas->MoveCursorToCrossHair(); HandleBlockEnd( &dc ); break; case ID_POPUP_MIRROR_Y_BLOCK: m_canvas->SetAutoPanRequest( false ); GetScreen()->m_BlockLocate.SetCommand( BLOCK_MIRROR_Y ); m_canvas->MoveCursorToCrossHair(); HandleBlockPlace( &dc ); break; case ID_POPUP_MIRROR_X_BLOCK: m_canvas->SetAutoPanRequest( false ); GetScreen()->m_BlockLocate.SetCommand( BLOCK_MIRROR_X ); m_canvas->MoveCursorToCrossHair(); HandleBlockPlace( &dc ); break; case ID_POPUP_ROTATE_BLOCK: m_canvas->SetAutoPanRequest( false ); GetScreen()->m_BlockLocate.SetCommand( BLOCK_ROTATE ); m_canvas->MoveCursorToCrossHair(); HandleBlockPlace( &dc ); break; case ID_POPUP_PLACE_BLOCK: m_canvas->SetAutoPanRequest( false ); m_canvas->MoveCursorToCrossHair(); HandleBlockPlace( &dc ); break; default: DisplayError( this, wxT( "LIB_EDIT_FRAME::Process_Special_Functions error" ) ); break; } m_canvas->SetIgnoreMouseEvents( false ); if( GetToolId() == ID_NO_TOOL_SELECTED ) m_lastDrawItem = NULL; }
void LIB_EDIT_FRAME::DeleteOnePart( wxCommandEvent& event ) { wxString cmp_name; LIB_ALIAS* libEntry; wxArrayString nameList; wxString msg; m_canvas->EndMouseCapture( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor() ); m_lastDrawItem = NULL; m_drawItem = NULL; PART_LIB* lib = GetCurLib(); if( !lib ) { SelectActiveLibrary(); lib = GetCurLib(); if( !lib ) { DisplayError( this, _( "Please select a component library." ) ); return; } } lib->GetAliasNames( nameList ); if( nameList.IsEmpty() ) { msg.Printf( _( "Part library '%s' is empty." ), GetChars( lib->GetName() ) ); wxMessageBox( msg, _( "Delete Entry Error" ), wxID_OK | wxICON_EXCLAMATION, this ); return; } msg.Printf( _( "Select one of %d components to delete\nfrom library '%s'." ), int( nameList.GetCount() ), GetChars( lib->GetName() ) ); wxSingleChoiceDialog dlg( this, msg, _( "Delete Part" ), nameList ); if( dlg.ShowModal() == wxID_CANCEL || dlg.GetStringSelection().IsEmpty() ) return; libEntry = lib->FindAlias( dlg.GetStringSelection() ); if( !libEntry ) { msg.Printf( _( "Entry '%s' not found in library '%s'." ), GetChars( dlg.GetStringSelection() ), GetChars( lib->GetName() ) ); DisplayError( this, msg ); return; } msg.Printf( _( "Delete component '%s' from library '%s' ?" ), GetChars( libEntry->GetName() ), GetChars( lib->GetName() ) ); if( !IsOK( this, msg ) ) return; LIB_PART* part = GetCurPart(); if( !part || !part->HasAlias( libEntry->GetName() ) ) { lib->RemoveAlias( libEntry ); return; } // If deleting the current entry or removing one of the aliases for // the current entry, sync the changes in the current entry as well. if( GetScreen()->IsModify() && !IsOK( this, _( "The component being deleted has been modified." " All changes will be lost. Discard changes?" ) ) ) { return; } LIB_ALIAS* nextEntry = lib->RemoveAlias( libEntry ); if( nextEntry != NULL ) { if( LoadOneLibraryPartAux( nextEntry, lib ) ) Zoom_Automatique( false ); } else { SetCurPart( NULL ); // delete CurPart m_aliasName.Empty(); } m_canvas->Refresh(); }