void LIB_EDIT_FRAME::OnImportPart( wxCommandEvent& event ) { wxString msg; m_lastDrawItem = NULL; wxString libName = getTargetLib(); if( !m_libMgr->LibraryExists( libName ) ) { libName = SelectLibraryFromList(); if( !m_libMgr->LibraryExists( libName ) ) return; } wxFileDialog dlg( this, _( "Import Symbol" ), m_mruPath, wxEmptyString, SchematicLibraryFileWildcard(), wxFD_OPEN | wxFD_FILE_MUST_EXIST ); if( dlg.ShowModal() == wxID_CANCEL ) return; wxFileName fn = dlg.GetPath(); m_mruPath = fn.GetPath(); wxArrayString symbols; SCH_PLUGIN::SCH_PLUGIN_RELEASER pi( SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_LEGACY ) ); // TODO dialog to select the part to be imported if there is more than one try { pi->EnumerateSymbolLib( symbols, fn.GetFullPath() ); } catch( const IO_ERROR& ioe ) { msg.Printf( _( "Cannot import symbol library \"%s\"." ), fn.GetFullPath() ); DisplayErrorMessage( this, msg, ioe.What() ); return; } if( symbols.empty() ) { msg.Printf( _( "Symbol library file \"%s\" is empty." ), fn.GetFullPath() ); DisplayError( this, msg ); return; } wxString symbolName = symbols[0]; LIB_ALIAS* entry = pi->LoadSymbol( fn.GetFullPath(), symbolName ); if( m_libMgr->PartExists( symbols[0], libName ) ) { msg.Printf( _( "Symbol \"%s\" already exists in library \"%s\"." ), symbolName, libName ); DisplayError( this, msg ); return; } m_libMgr->UpdatePart( entry->GetPart(), libName ); SyncLibraries( false ); loadPart( symbolName, libName, 1 ); }
void LIB_EDIT_FRAME::OnEditSymbolLibTable( wxCommandEvent& aEvent ) { m_libMgr->GetAdapter()->Freeze(); SCH_BASE_FRAME::OnEditSymbolLibTable( aEvent ); SyncLibraries( true ); m_libMgr->GetAdapter()->Thaw(); }
void LIB_EDIT_FRAME::OnPasteDuplicatePart( wxCommandEvent& aEvent ) { int dummyUnit; LIB_ID libId = m_treePane->GetLibTree()->GetSelectedLibId( &dummyUnit ); wxString lib = libId.GetLibNickname(); if( !m_libMgr->LibraryExists( lib ) ) return; LIB_PART* srcPart = nullptr; LIB_PART* newPart = nullptr; if( aEvent.GetId() == ID_LIBEDIT_DUPLICATE_PART ) { srcPart = m_libMgr->GetBufferedPart( libId.GetLibItemName(), lib ); newPart = new LIB_PART( *srcPart ); } else if( aEvent.GetId() == ID_LIBEDIT_PASTE_PART ) { auto clipboard = wxTheClipboard; wxClipboardLocker clipboardLock( clipboard ); if( !clipboardLock || ! clipboard->IsSupported( wxDF_TEXT ) ) return; wxTextDataObject data; clipboard->GetData( data ); wxString partSource = data.GetText(); STRING_LINE_READER reader( TO_UTF8( partSource ), "Clipboard" ); try { reader.ReadLine(); newPart = SCH_LEGACY_PLUGIN::ParsePart( reader ); } catch( IO_ERROR& e ) { wxLogError( wxString::Format( "Malformed clipboard: %s" ), GetChars( e.What() ) ); return; } } else wxFAIL; if( !newPart ) return; fixDuplicateAliases( newPart, lib ); m_libMgr->UpdatePart( newPart, lib ); SyncLibraries( false ); m_treePane->GetLibTree()->SelectLibId( LIB_ID( lib, newPart->GetName() ) ); delete newPart; }
void LIB_EDIT_FRAME::HardRedraw() { SyncLibraries( true ); RebuildView(); }
LIB_EDIT_FRAME::LIB_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) : SCH_BASE_FRAME( aKiway, aParent, FRAME_SCH_LIB_EDITOR, _( "Library Editor" ), wxDefaultPosition, wxDefaultSize, KICAD_DEFAULT_DRAWFRAME_STYLE, LIB_EDIT_FRAME_NAME ) { m_showAxis = true; // true to draw axis SetShowDeMorgan( false ); m_DrawSpecificConvert = true; m_DrawSpecificUnit = false; m_hotkeysDescrList = g_Libedit_Hotkeys_Descr; m_SyncPinEdit = false; m_repeatPinStep = DEFAULT_REPEAT_OFFSET_PIN; SetShowElectricalType( true ); m_FrameSize = ConvertDialogToPixels( wxSize( 500, 350 ) ); // default in case of no prefs m_my_part = NULL; m_treePane = nullptr; m_libMgr = nullptr; m_unit = 1; m_convert = 1; m_AboutTitle = "LibEdit"; // Delayed initialization if( g_LastTextSize == -1 ) g_LastTextSize = GetDefaultTextSize(); // Initialize grid id to the default value 50 mils: m_LastGridSizeId = ID_POPUP_GRID_LEVEL_50 - ID_POPUP_GRID_LEVEL_1000; wxIcon icon; icon.CopyFromBitmap( KiBitmap( icon_libedit_xpm ) ); SetIcon( icon ); LoadSettings( config() ); // Ensure axis are always drawn KIGFX::GAL_DISPLAY_OPTIONS& gal_opts = GetGalDisplayOptions(); gal_opts.m_axesEnabled = true; m_dummyScreen = new SCH_SCREEN( aKiway ); SetScreen( m_dummyScreen ); GetScreen()->m_Center = true; GetScreen()->SetMaxUndoItems( m_UndoRedoCountMax ); SetCrossHairPosition( wxPoint( 0, 0 ) ); SetSize( m_FramePos.x, m_FramePos.y, m_FrameSize.x, m_FrameSize.y ); m_libMgr = new LIB_MANAGER( *this ); SyncLibraries( true ); m_treePane = new SYMBOL_TREE_PANE( this, m_libMgr ); setupTools(); ReCreateMenuBar(); ReCreateHToolbar(); ReCreateVToolbar(); ReCreateOptToolbar(); updateTitle(); DisplayCmpDoc(); RebuildSymbolUnitsList(); m_auimgr.SetManagedWindow( this ); m_auimgr.SetArtProvider( new EDA_DOCKART( this ) ); m_auimgr.AddPane( m_mainToolBar, EDA_PANE().HToolbar().Name( "MainToolbar" ).Top().Layer(6) ); m_auimgr.AddPane( m_messagePanel, EDA_PANE().Messages().Name( "MsgPanel" ).Bottom().Layer(6) ); m_auimgr.AddPane( m_optionsToolBar, EDA_PANE().VToolbar().Name( "OptToolbar" ).Left().Layer(3) ); m_auimgr.AddPane( m_treePane, EDA_PANE().Palette().Name( "ComponentTree" ).Left().Layer(1) .Caption( _( "Libraries" ) ).MinSize( 250, -1 ) .BestSize( m_defaultLibWidth, -1 ).Resizable() ); m_auimgr.AddPane( m_drawToolBar, EDA_PANE().VToolbar().Name( "ToolsToolbar" ).Right().Layer(1) ); m_auimgr.AddPane( m_canvas->GetWindow(), wxAuiPaneInfo().Name( "DrawFrame" ).CentrePane() ); m_auimgr.Update(); GetToolManager()->RunAction( "common.Control.gridPreset", true, m_LastGridSizeId ); Raise(); Show( true ); Bind( wxEVT_COMMAND_MENU_SELECTED, &LIB_EDIT_FRAME::OnConfigurePaths, this, ID_PREFERENCES_CONFIGURE_PATHS ); Bind( wxEVT_COMMAND_MENU_SELECTED, &LIB_EDIT_FRAME::OnEditSymbolLibTable, this, ID_EDIT_SYM_LIB_TABLE ); m_toolManager->RunAction( ACTIONS::zoomFitScreen, true ); SyncView(); GetGalCanvas()->GetViewControls()->SetSnapping( true ); GetGalCanvas()->GetView()->UseDrawPriority( true ); GetGalCanvas()->GetGAL()->SetGridVisibility( IsGridVisible() ); GetGalCanvas()->GetGAL()->SetAxesEnabled( true ); // Set the working/draw area size to display a symbol to a reasonable value: // A 600mm x 600mm with a origin at the area center looks like a large working area double max_size_x = Millimeter2iu( 600 ); double max_size_y = Millimeter2iu( 600 ); BOX2D bbox; bbox.SetOrigin( -max_size_x /2, -max_size_y/2 ); bbox.SetSize( max_size_x, max_size_y ); GetCanvas()->GetView()->SetBoundary( bbox ); }
void LIB_EDIT_FRAME::savePartAs() { LIB_ID old_lib_id = getTargetLibId(); wxString old_name = old_lib_id.GetLibItemName(); wxString old_lib = old_lib_id.GetLibNickname(); LIB_PART* part = m_libMgr->GetBufferedPart( old_name, old_lib ); if( part ) { SYMBOL_LIB_TABLE* tbl = Prj().SchSymbolLibTable(); wxArrayString headers; std::vector< wxArrayString > itemsToDisplay; std::vector< wxString > libNicknames = tbl->GetLogicalLibs(); headers.Add( _( "Nickname" ) ); headers.Add( _( "Description" ) ); for( const auto& name : libNicknames ) { wxArrayString item; item.Add( name ); item.Add( tbl->GetDescription( name ) ); itemsToDisplay.push_back( item ); } EDA_LIST_DIALOG dlg( this, _( "Save Copy of Symbol" ), headers, itemsToDisplay, old_lib, nullptr, nullptr, /* sort */ false, /* show headers */ false ); dlg.SetListLabel( _( "Save in library:" ) ); dlg.SetOKLabel( _( "Save" ) ); wxBoxSizer* bNameSizer = new wxBoxSizer( wxHORIZONTAL ); wxStaticText* label = new wxStaticText( &dlg, wxID_ANY, _( "Name:" ), wxDefaultPosition, wxDefaultSize, 0 ); bNameSizer->Add( label, 0, wxALIGN_CENTER_VERTICAL|wxTOP|wxBOTTOM|wxLEFT, 5 ); wxTextCtrl* nameTextCtrl = new wxTextCtrl( &dlg, wxID_ANY, old_name, wxDefaultPosition, wxDefaultSize, 0 ); bNameSizer->Add( nameTextCtrl, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); wxSizer* mainSizer = dlg.GetSizer(); mainSizer->Prepend( bNameSizer, 0, wxEXPAND|wxTOP|wxLEFT|wxRIGHT, 5 ); // Move nameTextCtrl to the head of the tab-order if( dlg.GetChildren().DeleteObject( nameTextCtrl ) ) dlg.GetChildren().Insert( nameTextCtrl ); dlg.SetInitialFocus( nameTextCtrl ); dlg.Layout(); mainSizer->Fit( &dlg ); if( dlg.ShowModal() != wxID_OK ) return; // canceled by user wxString new_lib = dlg.GetTextSelection(); if( new_lib.IsEmpty() ) { DisplayError( NULL, _( "No library specified. Symbol could not be saved." ) ); return; } wxString new_name = nameTextCtrl->GetValue(); new_name.Trim( true ); new_name.Trim( false ); new_name.Replace( " ", "_" ); if( new_name.IsEmpty() ) { DisplayError( NULL, _( "No symbol name specified. Symbol could not be saved." ) ); return; } // Test if there is a component with this name already. if( m_libMgr->PartExists( new_name, new_lib ) ) { wxString msg = wxString::Format( _( "Symbol \"%s\" already exists in library \"%s\"" ), new_name, new_lib ); DisplayError( this, msg ); return; } LIB_PART new_part( *part ); new_part.SetName( new_name ); fixDuplicateAliases( &new_part, new_lib ); m_libMgr->UpdatePart( &new_part, new_lib ); SyncLibraries( false ); m_treePane->GetLibTree()->SelectLibId( LIB_ID( new_lib, new_part.GetName() ) ); if( isCurrentPart( old_lib_id ) ) loadPart( new_name, new_lib, m_unit ); } }
void LIB_EDIT_FRAME::OnCreateNewPart( wxCommandEvent& event ) { m_canvas->EndMouseCapture( ID_NO_TOOL_SELECTED, GetGalCanvas()->GetDefaultCursor() ); SetDrawItem( NULL ); wxString lib = getTargetLib(); if( !m_libMgr->LibraryExists( lib ) ) { lib = SelectLibraryFromList(); if( !m_libMgr->LibraryExists( lib ) ) return; } DIALOG_LIB_NEW_COMPONENT dlg( this ); dlg.SetMinSize( dlg.GetSize() ); if( dlg.ShowModal() == wxID_CANCEL ) return; if( dlg.GetName().IsEmpty() ) { wxMessageBox( _( "This new symbol has no name and cannot be created." ) ); return; } wxString name = dlg.GetName(); // Currently, symbol names cannot include a space, that breaks libraries: name.Replace( " ", "_" ); // Test if there is a component with this name already. if( !lib.empty() && m_libMgr->PartExists( name, lib ) ) { wxString msg = wxString::Format( _( "Symbol \"%s\" already exists in library \"%s\"" ), name, lib ); DisplayError( this, msg ); return; } LIB_PART new_part( name ); // do not create part on the heap, it will be buffered soon new_part.GetReferenceField().SetText( dlg.GetReference() ); new_part.SetUnitCount( dlg.GetUnitCount() ); // Initialize new_part.m_TextInside member: // if 0, pin text is outside the body (on the pin) // if > 0, pin text is inside the body if( dlg.GetPinNameInside() ) { new_part.SetPinNameOffset( dlg.GetPinTextPosition() ); if( new_part.GetPinNameOffset() == 0 ) new_part.SetPinNameOffset( 1 ); } else { new_part.SetPinNameOffset( 0 ); } ( dlg.GetPowerSymbol() ) ? new_part.SetPower() : new_part.SetNormal(); new_part.SetShowPinNumbers( dlg.GetShowPinNumber() ); new_part.SetShowPinNames( dlg.GetShowPinName() ); new_part.LockUnits( dlg.GetLockItems() ); if( dlg.GetUnitCount() < 2 ) new_part.LockUnits( false ); m_libMgr->UpdatePart( &new_part, lib ); SyncLibraries( false ); loadPart( name, lib, 1 ); new_part.SetConversion( dlg.GetAlternateBodyStyle() ); // must be called after loadPart, that calls SetShowDeMorgan, but // because the symbol is empty,it looks like it has no alternate body SetShowDeMorgan( dlg.GetAlternateBodyStyle() ); }