void LIB_EDIT_FRAME::EndDrawGraphicItem( wxDC* DC ) { LIB_ITEM* item = GetDrawItem(); if( item == NULL ) return; if( LIB_PART* part = GetCurPart() ) { if( GetToolId() != ID_NO_TOOL_SELECTED ) SetCursor( wxCURSOR_PENCIL ); else SetCursor( (wxStockCursor) m_canvas->GetDefaultCursor() ); if( GetTempCopyComponent() ) // used when editing an existing item SaveCopyInUndoList( GetTempCopyComponent() ); else { // When creating a new item, there is still no change for the // current symbol. So save it. SaveCopyInUndoList( part ); } if( item->IsNew() ) part->AddDrawItem( item ); item->EndEdit( GetCrossHairPosition( true ) ); SetDrawItem( NULL ); OnModify(); m_canvas->SetMouseCapture( NULL, NULL ); m_canvas->Refresh(); } }
LIB_ITEM* LIB_EDIT_FRAME::CreateGraphicItem( LIB_PART* LibEntry, wxDC* DC ) { LIB_ITEM* item = GetDrawItem(); m_canvas->SetMouseCapture( SymbolDisplayDraw, AbortSymbolTraceOn ); wxPoint drawPos = GetCrossHairPosition( true ); // no temp copy -> the current version of symbol will be used for Undo // This is normal when adding new items to the current symbol ClearTempCopyComponent(); switch( GetToolId() ) { case ID_LIBEDIT_BODY_ARC_BUTT: item = new LIB_ARC( LibEntry ); break; case ID_LIBEDIT_BODY_CIRCLE_BUTT: item = new LIB_CIRCLE( LibEntry ); break; case ID_LIBEDIT_BODY_RECT_BUTT: item = new LIB_RECTANGLE( LibEntry ); break; case ID_LIBEDIT_BODY_LINE_BUTT: item = new LIB_POLYLINE( LibEntry ); break; case ID_LIBEDIT_BODY_TEXT_BUTT: { LIB_TEXT* text = new LIB_TEXT( LibEntry ); text->SetTextSize( wxSize( m_textSize, m_textSize ) ); text->SetTextAngle( m_current_text_angle ); // Enter the graphic text info m_canvas->SetIgnoreMouseEvents( true ); EditSymbolText( NULL, text ); m_canvas->SetIgnoreMouseEvents( false ); m_canvas->MoveCursorToCrossHair(); if( text->GetText().IsEmpty() ) { delete text; item = NULL; } else { item = text; } } break; default: DisplayError( this, wxT( "LIB_EDIT_FRAME::CreateGraphicItem() error" ) ); return NULL; } if( item ) { item->BeginEdit( IS_NEW, drawPos ); // Don't set line parameters for text objects. if( item->Type() != LIB_TEXT_T ) { item->SetWidth( m_drawLineWidth ); item->SetFillMode( m_drawFillStyle ); } if( m_drawSpecificUnit ) item->SetUnit( m_unit ); if( m_drawSpecificConvert ) item->SetConvert( m_convert ); // Draw initial symbol: m_canvas->CallMouseCapture( DC, wxDefaultPosition, false ); } else { m_canvas->EndMouseCapture(); return NULL; } m_canvas->MoveCursorToCrossHair(); m_canvas->SetIgnoreMouseEvents( false ); SetDrawItem( item ); return item; }
void LIB_EDIT_FRAME::OnExportPart( wxCommandEvent& event ) { wxString msg, title; LIB_PART* part = getTargetPart(); if( !part ) { DisplayError( this, _( "There is no symbol selected to save." ) ); return; } wxFileName fn; fn.SetName( part->GetName().Lower() ); fn.SetExt( SchematicLibraryFileExtension ); wxFileDialog dlg( this, _( "Export Symbol" ), m_mruPath, fn.GetFullName(), SchematicLibraryFileWildcard(), wxFD_SAVE ); if( dlg.ShowModal() == wxID_CANCEL ) return; fn = dlg.GetPath(); fn.MakeAbsolute(); LIB_PART* old_part = NULL; SCH_PLUGIN::SCH_PLUGIN_RELEASER pi( SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_LEGACY ) ); if( fn.FileExists() ) { try { LIB_ALIAS* alias = pi->LoadSymbol( fn.GetFullPath(), part->GetName() ); if( alias ) old_part = alias->GetPart(); } catch( const IO_ERROR& ioe ) { msg.Printf( _( "Error occurred attempting to load symbol library file \"%s\"" ), fn.GetFullPath() ); DisplayErrorMessage( this, msg, ioe.What() ); return; } if( old_part ) { msg.Printf( _( "Symbol \"%s\" already exists in \"%s\"." ), part->GetName(), fn.GetFullName() ); KIDIALOG errorDlg( this, msg, _( "Confirmation" ), wxOK | wxCANCEL | wxICON_WARNING ); errorDlg.SetOKLabel( _( "Overwrite" ) ); errorDlg.DoNotShowCheckbox( __FILE__, __LINE__ ); if( errorDlg.ShowModal() == wxID_CANCEL ) return; } } if( fn.Exists() && !fn.IsDirWritable() ) { msg.Printf( _( "Write permissions are required to save library \"%s\"." ), fn.GetFullPath() ); DisplayError( this, msg ); return; } try { if( !fn.FileExists() ) pi->CreateSymbolLib( fn.GetFullPath() ); pi->SaveSymbol( fn.GetFullPath(), new LIB_PART( *part ) ); } catch( const IO_ERROR& ioe ) { msg = _( "Failed to create symbol library file " ) + fn.GetFullPath(); DisplayErrorMessage( this, msg, ioe.What() ); msg.Printf( _( "Error creating symbol library \"%s\"" ), fn.GetFullName() ); SetStatusText( msg ); return; } m_mruPath = fn.GetPath(); m_lastDrawItem = NULL; SetDrawItem( NULL ); msg.Printf( _( "Symbol \"%s\" saved in library \"%s\"" ), part->GetName(), fn.GetFullPath() ); SetStatusText( msg ); // See if the user wants it added to a library table (global or project) SYMBOL_LIB_TABLE* libTable = selectSymLibTable( true ); if( libTable ) { if( !m_libMgr->AddLibrary( fn.GetFullPath(), libTable ) ) { DisplayError( this, _( "Could not open the library file." ) ); return; } bool globalTable = ( libTable == &SYMBOL_LIB_TABLE::GetGlobalLibTable() ); saveSymbolLibTables( globalTable, !globalTable ); } }
void LIB_EDIT_FRAME::OnLeftClick( wxDC* DC, const wxPoint& aPosition ) { LIB_ITEM* item = GetDrawItem(); bool item_in_edit = item && item->InEditMode(); bool no_item_edited = !item_in_edit; LIB_PART* part = GetCurPart(); if( !part ) // No component loaded ! return; if( ( GetToolId() == ID_NO_TOOL_SELECTED ) && no_item_edited ) { item = LocateItemUsingCursor( aPosition ); if( item ) { MSG_PANEL_ITEMS items; item->GetMsgPanelInfo( items ); SetMsgPanel( items ); } else { DisplayCmpDoc(); if( m_canvas->GetAbortRequest() ) m_canvas->SetAbortRequest( false ); } } switch( GetToolId() ) { case ID_ZOOM_SELECTION: break; case ID_NO_TOOL_SELECTED: // If an item is currently in edit, finish edit if( item_in_edit ) { switch( item->Type() ) { case LIB_PIN_T: PlacePin(); break; default: EndDrawGraphicItem( DC ); break; } } break; case ID_LIBEDIT_PIN_BUTT: if( no_item_edited ) CreatePin( DC ); else PlacePin(); break; case ID_LIBEDIT_BODY_LINE_BUTT: case ID_LIBEDIT_BODY_ARC_BUTT: case ID_LIBEDIT_BODY_CIRCLE_BUTT: case ID_LIBEDIT_BODY_RECT_BUTT: case ID_LIBEDIT_BODY_TEXT_BUTT: if( no_item_edited ) SetDrawItem( CreateGraphicItem( part, DC ) ); else if( item ) { if( item->IsNew() ) GraphicItemBeginDraw( DC ); else EndDrawGraphicItem( DC ); } break; case ID_LIBEDIT_DELETE_ITEM_BUTT: item = LocateItemUsingCursor( aPosition ); if( item ) { deleteItem( DC, item ); } else { DisplayCmpDoc(); if( m_canvas->GetAbortRequest() ) m_canvas->SetAbortRequest( false ); } break; case ID_LIBEDIT_ANCHOR_ITEM_BUTT: SaveCopyInUndoList( part ); PlaceAnchor(); SetNoToolSelected(); break; default: wxFAIL_MSG( wxString::Format( wxT( "Unhandled command ID %d" ), GetToolId() ) ); SetNoToolSelected(); break; } }
/* * Called on a double click: * If an editable item (field, pin, graphic): * Call the suitable dialog editor. */ void LIB_EDIT_FRAME::OnLeftDClick( wxDC* DC, const wxPoint& aPosition ) { LIB_PART* part = GetCurPart(); LIB_ITEM* item = GetDrawItem(); if( !part ) return; if( !item || !item->InEditMode() ) { // We can locate an item item = LocateItemUsingCursor( aPosition, LIB_COLLECTOR::DoubleClickItems ); if( item == NULL ) { // The user canceled the disambiguation menu if( m_canvas->GetAbortRequest() ) m_canvas->SetAbortRequest( false ); else { // If there is only a random double-click, we allow the use to edit the part wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED ); cmd.SetId( ID_LIBEDIT_GET_FRAME_EDIT_PART ); GetEventHandler()->ProcessEvent( cmd ); } } } if( item ) SetMsgPanel( item ); else return; m_canvas->SetIgnoreMouseEvents( true ); bool not_edited = !item->InEditMode(); switch( item->Type() ) { case LIB_PIN_T: if( not_edited ) { SetDrawItem( item ); wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED ); cmd.SetId( ID_LIBEDIT_EDIT_PIN ); GetEventHandler()->ProcessEvent( cmd ); } break; case LIB_ARC_T: case LIB_CIRCLE_T: case LIB_RECTANGLE_T: if( not_edited ) EditGraphicSymbol( DC, item ); break; case LIB_POLYLINE_T: if( not_edited ) EditGraphicSymbol( DC, item ); else if( item->IsNew() ) EndDrawGraphicItem( DC ); break; case LIB_TEXT_T: if( not_edited ) EditSymbolText( DC, item ); break; case LIB_FIELD_T: if( not_edited ) EditField( (LIB_FIELD*) item ); break; default: wxFAIL_MSG( wxT( "Unhandled item <" ) + item->GetClass() + wxT( ">" ) ); break; } m_canvas->MoveCursorToCrossHair(); m_canvas->SetIgnoreMouseEvents( false ); }
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() ); }
bool LIB_EDIT_FRAME::OnRightClick( const wxPoint& aPosition, wxMenu* PopMenu ) { LIB_ITEM* item = GetDrawItem(); bool blockActive = GetScreen()->IsBlockActive(); wxString msg; if( blockActive ) { AddMenusForBlock( PopMenu, this ); PopMenu->AppendSeparator(); return true; } LIB_PART* part = GetCurPart(); if( !part ) return true; // If Command in progress, put menu "cancel" if( item && item->InEditMode() ) { AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_CANCEL_EDITING, _( "Cancel" ), KiBitmap( cancel_xpm ) ); PopMenu->AppendSeparator(); } else { item = LocateItemUsingCursor( aPosition ); // If the clarify item selection context menu is aborted, don't show the context menu. if( item == NULL && m_canvas->GetAbortRequest() ) { m_canvas->SetAbortRequest( false ); return false; } if( GetToolId() != ID_NO_TOOL_SELECTED ) { // If a tool is active, put menu "end tool" AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_CANCEL_EDITING, _( "End Tool" ), KiBitmap( cursor_xpm ) ); PopMenu->AppendSeparator(); } } if( item ) { MSG_PANEL_ITEMS items; item->GetMsgPanelInfo( m_UserUnits, items ); SetMsgPanel( items ); } else { if( GetToolId() == ID_NO_TOOL_SELECTED ) { msg = AddHotkeyName( _( "&Paste" ), g_Libedit_Hokeys_Descr, HK_EDIT_PASTE ); AddMenuItem( PopMenu, ID_POPUP_PASTE_BLOCK, msg, _( "Pastes copied item(s)" ), KiBitmap( paste_xpm ) ); PopMenu->AppendSeparator(); } return true; } SetDrawItem( item ); bool not_edited = !item->InEditMode(); switch( item->Type() ) { case LIB_PIN_T: AddMenusForPin( PopMenu, (LIB_PIN*) item, this ); break; case LIB_ARC_T: if( not_edited ) { msg = AddHotkeyName( _( "Move" ), g_Libedit_Hokeys_Descr, HK_LIBEDIT_MOVE_GRAPHIC_ITEM ); AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_MOVE_ITEM_REQUEST, msg, KiBitmap( move_xpm ) ); msg = AddHotkeyName( _( "Drag Arc Edge" ), g_Libedit_Hokeys_Descr, HK_DRAG ); AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_MODIFY_ITEM, msg, KiBitmap( move_xpm ) ); } msg = AddHotkeyName( _( "Edit Arc Options" ), g_Libedit_Hokeys_Descr, HK_EDIT ); AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_BODY_EDIT_ITEM, msg, KiBitmap( options_arc_xpm ) ); if( not_edited ) { msg = AddHotkeyName( _( "Delete" ), g_Libedit_Hokeys_Descr, HK_DELETE ); AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_DELETE_ITEM, msg, KiBitmap( delete_xpm ) ); } break; case LIB_CIRCLE_T: if( not_edited ) { msg = AddHotkeyName( _( "Move" ), g_Libedit_Hokeys_Descr, HK_LIBEDIT_MOVE_GRAPHIC_ITEM ); AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_MOVE_ITEM_REQUEST, msg, KiBitmap( move_xpm ) ); msg = AddHotkeyName( _( "Drag Circle Outline" ), g_Libedit_Hokeys_Descr, HK_DRAG ); AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_MODIFY_ITEM, msg, KiBitmap( move_rectangle_xpm ) ); } msg = AddHotkeyName( _( "Edit Circle Options..." ), g_Libedit_Hokeys_Descr, HK_EDIT ); AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_BODY_EDIT_ITEM, msg, KiBitmap( options_circle_xpm ) ); if( not_edited ) { msg = AddHotkeyName( _( "Delete" ), g_Libedit_Hokeys_Descr, HK_DELETE ); AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_DELETE_ITEM, msg, KiBitmap( delete_circle_xpm ) ); } break; case LIB_RECTANGLE_T: if( not_edited ) { msg = AddHotkeyName( _( "Move Rectangle" ), g_Libedit_Hokeys_Descr, HK_LIBEDIT_MOVE_GRAPHIC_ITEM ); AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_MOVE_ITEM_REQUEST, msg, KiBitmap( move_rectangle_xpm ) ); } msg = AddHotkeyName( _( "Edit Rectangle Options..." ), g_Libedit_Hokeys_Descr, HK_EDIT ); AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_BODY_EDIT_ITEM, msg, KiBitmap( options_rectangle_xpm ) ); if( not_edited ) { msg = AddHotkeyName( _( "Drag Rectangle Edge" ), g_Libedit_Hokeys_Descr, HK_DRAG ); AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_MODIFY_ITEM, msg, KiBitmap( move_rectangle_xpm ) ); msg = AddHotkeyName( _( "Delete" ), g_Libedit_Hokeys_Descr, HK_DELETE ); AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_DELETE_ITEM, msg, KiBitmap( delete_rectangle_xpm ) ); } break; case LIB_TEXT_T: if( not_edited ) { msg = AddHotkeyName( _( "Move" ), g_Libedit_Hokeys_Descr, HK_LIBEDIT_MOVE_GRAPHIC_ITEM ); AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_MOVE_ITEM_REQUEST, msg, KiBitmap( move_xpm ) ); } msg = AddHotkeyName( _( "Edit..." ), g_Libedit_Hokeys_Descr, HK_EDIT ); AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_BODY_EDIT_ITEM, msg, KiBitmap( edit_text_xpm ) ); msg = AddHotkeyName( _( "Rotate Clockwise" ), g_Libedit_Hokeys_Descr, HK_ROTATE ); AddMenuItem( PopMenu, ID_LIBEDIT_ROTATE_ITEM, msg, KiBitmap( rotate_cw_xpm ) ); if( not_edited ) { msg = AddHotkeyName( _( "Delete" ), g_Libedit_Hokeys_Descr, HK_DELETE ); AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_DELETE_ITEM, msg, KiBitmap( delete_xpm ) ); } break; case LIB_POLYLINE_T: if( not_edited ) { msg = AddHotkeyName( _( "Move" ), g_Libedit_Hokeys_Descr, HK_LIBEDIT_MOVE_GRAPHIC_ITEM ); AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_MOVE_ITEM_REQUEST, msg, KiBitmap( move_xpm ) ); msg = AddHotkeyName( _( "Drag Edge Point" ), g_Libedit_Hokeys_Descr, HK_DRAG ); AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_MODIFY_ITEM, msg, KiBitmap( move_exactly_xpm ) ); } if( item->IsNew() ) { AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_END_CREATE_ITEM, _( "Line End" ), KiBitmap( checked_ok_xpm ) ); } msg = AddHotkeyName( _( "Edit Line Options..." ), g_Libedit_Hokeys_Descr, HK_EDIT ); AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_BODY_EDIT_ITEM, msg, KiBitmap( options_segment_xpm ) ); if( not_edited ) { msg = AddHotkeyName( _( "Delete" ), g_Libedit_Hokeys_Descr, HK_DELETE ); AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_DELETE_ITEM, msg, KiBitmap( delete_xpm ) ); } if( item->IsNew() ) { if( ( (LIB_POLYLINE*) item )->GetCornerCount() > 2 ) { msg = AddHotkeyName( _( "Delete" ), g_Libedit_Hokeys_Descr, HK_DELETE ); AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_DELETE_CURRENT_POLY_SEGMENT, msg, KiBitmap( delete_xpm ) ); } } break; case LIB_FIELD_T: if( not_edited ) { msg = AddHotkeyName( _( "Move" ), g_Libedit_Hokeys_Descr, HK_LIBEDIT_MOVE_GRAPHIC_ITEM ); AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_MOVE_ITEM_REQUEST, msg, KiBitmap( move_xpm ) ); } msg = AddHotkeyName( _( "Rotate Clockwise" ), g_Libedit_Hokeys_Descr, HK_ROTATE ); AddMenuItem( PopMenu, ID_LIBEDIT_ROTATE_ITEM, msg, KiBitmap( rotate_cw_xpm ) ); msg = AddHotkeyName( _( "Edit..." ), g_Libedit_Hokeys_Descr, HK_EDIT ); AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_FIELD_EDIT_ITEM, msg, KiBitmap( edit_text_xpm ) ); break; default: wxFAIL_MSG( wxString::Format( wxT( "Unknown library item type %d" ), item->Type() ) ); SetDrawItem( NULL ); break; } PopMenu->AppendSeparator(); return true; }