void LIB_EDIT_FRAME::copySelectedItems() { LIB_PART* part = GetCurPart(); if( !part ) return; m_clipboard.ClearListAndDeleteItems(); // delete previous saved list, if exists m_clipboard.SetLastCursorPosition( GetScreen()->m_BlockLocate.GetEnd() ); // store the reference point for( LIB_ITEM& item : part->GetDrawItems() ) { // We *do not* copy fields because they are unique for the whole component // so skip them (do not duplicate) if they are flagged selected. if( item.Type() == LIB_FIELD_T ) item.ClearFlags( SELECTED ); if( !item.IsSelected() ) continue; // Do not clear the 'selected' flag. It is required to have items drawn when they are pasted. LIB_ITEM* copy = (LIB_ITEM*) item.Clone(); copy->SetFlags( copy->GetFlags() | UR_TRANSIENT ); ITEM_PICKER picker( copy, UR_NEW ); m_clipboard.PushItem( picker ); } }
LIB_ITEM* LIB_EDIT_FRAME::locateItem( const wxPoint& aPosition, const KICAD_T aFilterList[] ) { if( m_component == NULL ) return NULL; LIB_ITEM* item = NULL; m_collectedItems.Collect( m_component->GetDrawItemList(), aFilterList, aPosition, m_unit, m_convert ); if( m_collectedItems.GetCount() == 0 ) { ClearMsgPanel(); } else if( m_collectedItems.GetCount() == 1 ) { item = m_collectedItems[0]; } else { 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. m_drawItem = NULL; m_canvas->SetAbortRequest( true ); // Changed to false if an item is selected PopupMenu( &selectMenu ); m_canvas->MoveCursorToCrossHair(); item = m_drawItem; } } if( item ) { MSG_PANEL_ITEMS items; item->GetMsgPanelInfo( items ); SetMsgPanel( items ); } else { ClearMsgPanel(); } return item; }
/* * Redraw the graphic shape while moving */ static void RedrawWhileMovingCursor( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition, bool aErase ) { LIB_ITEM* item; item = ( (LIB_EDIT_FRAME*) aPanel->GetParent() )->GetDrawItem(); if( item == NULL ) return; item->SetEraseLastDrawItem( aErase ); // if item is the reference field, we must add the current unit id if( item->Type() == LIB_FIELD_T ) { int unit = ((LIB_EDIT_FRAME*)aPanel->GetParent())->GetUnit(); wxString text = ((LIB_FIELD*)item)->GetFullText( unit ); item->Draw( aPanel, aDC, aPanel->GetParent()->GetCrossHairPosition( true ), COLOR4D::UNSPECIFIED, g_XorMode, &text, DefaultTransform ); } else item->Draw( aPanel, aDC, aPanel->GetParent()->GetCrossHairPosition( true ), COLOR4D::UNSPECIFIED, g_XorMode, NULL, DefaultTransform ); }
void LIB_EDIT_FRAME::BlockCopySelectedItems( const wxPoint& aOffset, LIB_PART* aPart, BLOCK_SELECTOR* aBlock ) { PICKED_ITEMS_LIST& aItemsList = aBlock->GetItems(); LIB_ITEM* oldItem; LIB_ITEM* newItem; for( unsigned ii = 0; ii < aItemsList.GetCount(); ii++ ) { oldItem = static_cast<LIB_ITEM*>( aItemsList.GetPickedItem( ii ) ); // We *do not* copy fields because they are unique for the whole component // so skip them (do not duplicate) if they are flagged selected. if( oldItem->Type() == LIB_FIELD_T ) oldItem->ClearFlags( SELECTED ); if( !oldItem->IsSelected() ) continue; newItem = (LIB_ITEM*) oldItem->Clone(); newItem->SetFlags( SELECTED ); oldItem->ClearFlags( SELECTED ); newItem->SetOffset( aBlock->GetMoveVector() ); aItemsList.SetPickedItem( newItem, ii ); aItemsList.SetPickedItemStatus( UR_NEW, ii ); aPart->GetDrawItems().push_back( newItem ); } }
//! @brief Manage mouse events when creating new graphic object or modifying an graphic object. static void SymbolDisplayDraw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition, bool aErase ) { LIB_ITEM* item = ( (LIB_EDIT_FRAME*) aPanel->GetParent() )->GetDrawItem(); if( item == NULL ) return; item->SetEraseLastDrawItem( aErase ); item->Draw( aPanel, aDC, aPanel->GetParent()->GetCrossHairPosition( true ), COLOR4D::UNSPECIFIED, g_XorMode, NULL, DefaultTransform ); }
void LIB_EDIT_FRAME::StartModifyDrawSymbol( wxDC* DC ) { LIB_ITEM* item = GetDrawItem(); if( item == NULL ) return; TempCopyComponent(); item->BeginEdit( IS_RESIZED, GetCrossHairPosition( true ) ); m_canvas->SetMouseCapture( SymbolDisplayDraw, AbortSymbolTraceOn ); m_canvas->CallMouseCapture( DC, wxDefaultPosition, true ); }
int LIB_TEXT::compare( const LIB_ITEM& other ) const { wxASSERT( other.Type() == LIB_TEXT_T ); const LIB_TEXT* tmp = ( LIB_TEXT* ) &other; int result = m_Text.CmpNoCase( tmp->m_Text ); if( result != 0 ) return result; if( m_Pos.x != tmp->m_Pos.x ) return m_Pos.x - tmp->m_Pos.x; if( m_Pos.y != tmp->m_Pos.y ) return m_Pos.y - tmp->m_Pos.y; if( m_Size.x != tmp->m_Size.x ) return m_Size.x - tmp->m_Size.x; if( m_Size.y != tmp->m_Size.y ) return m_Size.y - tmp->m_Size.y; return 0; }
int LIB_TEXT::compare( const LIB_ITEM& other ) const { wxASSERT( other.Type() == LIB_TEXT_T ); const LIB_TEXT* tmp = ( LIB_TEXT* ) &other; int result = m_Text.CmpNoCase( tmp->m_Text ); if( result != 0 ) return result; if( GetTextPos().x != tmp->GetTextPos().x ) return GetTextPos().x - tmp->GetTextPos().x; if( GetTextPos().y != tmp->GetTextPos().y ) return GetTextPos().y - tmp->GetTextPos().y; if( GetTextWidth() != tmp->GetTextWidth() ) return GetTextWidth() - tmp->GetTextWidth(); if( GetTextHeight() != tmp->GetTextHeight() ) return GetTextHeight() - tmp->GetTextHeight(); return 0; }
bool LIB_ITEM::operator==( const LIB_ITEM& aOther ) const { return ( ( Type() == aOther.Type() ) && ( m_Unit == aOther.m_Unit ) && ( m_Convert == aOther.m_Convert ) && compare( aOther ) == 0 ); }
static void AbortSymbolTraceOn( EDA_DRAW_PANEL* Panel, wxDC* DC ) { LIB_EDIT_FRAME* parent = (LIB_EDIT_FRAME*) Panel->GetParent(); LIB_ITEM* item = parent->GetDrawItem(); if( item == NULL ) return; bool newItem = item->IsNew(); item->EndEdit( parent->GetCrossHairPosition( true ), true ); if( newItem ) { delete item; } else parent->RestoreComponent(); parent->SetDrawItem( NULL ); Panel->Refresh(); }
void LIB_EDIT_FRAME::StartMoveDrawSymbol( wxDC* DC ) { LIB_ITEM* item = GetDrawItem(); if( item == NULL ) return; SetCursor( wxCURSOR_HAND ); TempCopyComponent(); // For fields only, move the anchor point of the field // to the cursor position to allow user to see the text justification if( item->Type() == LIB_FIELD_T ) item->BeginEdit( IS_MOVED, item->GetPosition() ); else item->BeginEdit( IS_MOVED, GetCrossHairPosition( true ) ); m_canvas->SetMouseCapture( RedrawWhileMovingCursor, AbortSymbolTraceOn ); m_canvas->CallMouseCapture( DC, wxDefaultPosition, true ); }
/* * Traces the outline of the search block structures * The entire block follows the cursor */ void DrawMovingBlockOutlines( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition, bool aErase ) { SCH_DRAW_PANEL* panel =static_cast<SCH_DRAW_PANEL*>( aPanel ); LIB_EDIT_FRAME* frame = (LIB_EDIT_FRAME*) aPanel->GetParent(); KIGFX::SCH_VIEW* view = panel->GetView(); KIGFX::VIEW_GROUP* preview = view->GetPreview(); BASE_SCREEN* screen = aPanel->GetScreen(); BLOCK_SELECTOR* block = &screen->m_BlockLocate; LIB_PART* component = frame->GetCurPart(); if( component == NULL ) return; block->SetMoveVector( frame->GetCrossHairPosition( true ) - block->GetLastCursorPosition() ); preview->Clear(); view->SetVisible( preview, true ); for( unsigned ii = 0; ii < block->GetCount(); ii++ ) { LIB_ITEM* libItem = (LIB_ITEM*) block->GetItem( ii ); LIB_ITEM* copy = static_cast<LIB_ITEM*>( libItem->Clone() ); copy->Move( copy->GetPosition() + block->GetMoveVector() ); copy->SetFlags( IS_MOVED ); preview->Add( copy ); view->Hide( libItem ); } view->Update( preview ); }
void LIB_EDIT_FRAME::pasteClipboard( const wxPoint& aOffset ) { LIB_PART* part = GetCurPart(); if( !part || m_clipboard.GetCount() == 0 ) return; for( unsigned int i = 0; i < m_clipboard.GetCount(); i++ ) { // Append a copy to the current part, so the clipboard buffer might be pasted multiple times LIB_ITEM* item = (LIB_ITEM*) m_clipboard.GetItem( i )->Clone(); item->SetParent( part ); item->SetSelected(); item->SetUnit( GetUnit() ); part->AddDrawItem( item ); } BlockMoveSelectedItems( aOffset, GetCurPart(), &GetScreen()->m_BlockLocate ); RebuildView(); GetCanvas()->Refresh(); OnModify(); }
void LIB_EDIT_FRAME::InitBlockPasteInfos() { BLOCK_SELECTOR& block = GetScreen()->m_BlockLocate; // Copy the clipboard contents to the screen block selector // (only the copy, the new instances will be appended to the part once the items are placed) block.GetItems().CopyList( m_clipboard.GetItems() ); // Set block items to the current unit & DeMorgan variant for( size_t i = 0; i < m_clipboard.GetItems().GetCount(); ++i ) { LIB_ITEM* item = dynamic_cast<LIB_ITEM*>( m_clipboard.GetItem( i ) ); if( item ) { item->SetUnit( m_unit ); item->SetConvert( m_convert ); } } // Set the paste reference point block.SetLastCursorPosition( m_clipboard.GetLastCursorPosition() ); m_canvas->SetMouseCaptureCallback( DrawMovingBlockOutlines ); }
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(); } }
int LIB_CIRCLE::compare( const LIB_ITEM& aOther ) const { wxASSERT( aOther.Type() == LIB_CIRCLE_T ); const LIB_CIRCLE* tmp = ( LIB_CIRCLE* ) &aOther; if( m_Pos.x != tmp->m_Pos.x ) return m_Pos.x - tmp->m_Pos.x; if( m_Pos.y != tmp->m_Pos.y ) return m_Pos.y - tmp->m_Pos.y; if( m_Radius != tmp->m_Radius ) return m_Radius - tmp->m_Radius; return 0; }
bool LIB_ITEM::operator<( const LIB_ITEM& aOther ) const { int result = m_Convert - aOther.m_Convert; if( result != 0 ) return result < 0; result = m_Unit - aOther.m_Unit; if( result != 0 ) return result < 0; result = Type() - aOther.Type(); if( result != 0 ) return result < 0; return ( compare( aOther ) < 0 ); }
int LIB_RECTANGLE::compare( const LIB_ITEM& aOther ) const { wxASSERT( aOther.Type() == LIB_RECTANGLE_T ); const LIB_RECTANGLE* tmp = ( LIB_RECTANGLE* ) &aOther; if( m_Pos.x != tmp->m_Pos.x ) return m_Pos.x - tmp->m_Pos.x; if( m_Pos.y != tmp->m_Pos.y ) return m_Pos.y - tmp->m_Pos.y; if( m_End.x != tmp->m_End.x ) return m_End.x - tmp->m_End.x; if( m_End.y != tmp->m_End.y ) return m_End.y - tmp->m_End.y; return 0; }
int LIB_ARC::compare( const LIB_ITEM& aOther ) const { wxASSERT( aOther.Type() == LIB_ARC_T ); const LIB_ARC* tmp = ( LIB_ARC* ) &aOther; if( m_Pos.x != tmp->m_Pos.x ) return m_Pos.x - tmp->m_Pos.x; if( m_Pos.y != tmp->m_Pos.y ) return m_Pos.y - tmp->m_Pos.y; if( m_t1 != tmp->m_t1 ) return m_t1 - tmp->m_t1; if( m_t2 != tmp->m_t2 ) return m_t2 - tmp->m_t2; return 0; }
int LIB_POLYLINE::compare( const LIB_ITEM& aOther ) const { wxASSERT( aOther.Type() == LIB_POLYLINE_T ); const LIB_POLYLINE* tmp = (LIB_POLYLINE*) &aOther; if( m_PolyPoints.size() != tmp->m_PolyPoints.size() ) return m_PolyPoints.size() - tmp->m_PolyPoints.size(); for( size_t i = 0; i < m_PolyPoints.size(); i++ ) { if( m_PolyPoints[i].x != tmp->m_PolyPoints[i].x ) return m_PolyPoints[i].x - tmp->m_PolyPoints[i].x; if( m_PolyPoints[i].y != tmp->m_PolyPoints[i].y ) return m_PolyPoints[i].y - tmp->m_PolyPoints[i].y; } return 0; }
int LIB_BEZIER::compare( const LIB_ITEM& aOther ) const { wxASSERT( aOther.Type() == LIB_BEZIER_T ); const LIB_BEZIER* tmp = ( LIB_BEZIER* ) &aOther; if( m_BezierPoints.size() != tmp->m_BezierPoints.size() ) return m_BezierPoints.size() - tmp->m_BezierPoints.size(); for( size_t i = 0; i < m_BezierPoints.size(); i++ ) { if( m_BezierPoints[i].x != tmp->m_BezierPoints[i].x ) return m_BezierPoints[i].x - tmp->m_BezierPoints[i].x; if( m_BezierPoints[i].y != tmp->m_BezierPoints[i].y ) return m_BezierPoints[i].y - tmp->m_BezierPoints[i].y; } return 0; }
SEARCH_RESULT LIB_COLLECTOR::Inspect( EDA_ITEM* aItem, const void* aTestData ) { LIB_ITEM* item = (LIB_ITEM*) aItem; // wxLogDebug( wxT( "Inspecting item %s, unit %d, convert %d" ), // GetChars( item->GetSelectMenuText() ), item->GetUnit(), item->GetConvert() ); if( ( m_data.m_unit && item->GetUnit() && ( m_data.m_unit != item->GetUnit() ) ) || ( m_data.m_convert && item->GetConvert() && ( m_data.m_convert != item->GetConvert() ) ) || !item->HitTest( m_RefPos, -1, DefaultTransform ) ) return SEARCH_CONTINUE; Append( aItem ); return SEARCH_CONTINUE; }
void LIB_EDIT_FRAME::LoadOneSymbol() { LIB_PART* part = GetCurPart(); // Exit if no library entry is selected or a command is in progress. if( !part || ( m_drawItem && m_drawItem->GetFlags() ) ) return; PROJECT& prj = Prj(); SEARCH_STACK* search = prj.SchSearchS(); m_canvas->SetIgnoreMouseEvents( true ); wxString default_path = prj.GetRString( PROJECT::SCH_LIB_PATH ); if( !default_path ) default_path = search->LastVisitedPath(); wxFileDialog dlg( this, _( "Import Symbol Drawings" ), default_path, wxEmptyString, SchematicSymbolFileWildcard, wxFD_OPEN | wxFD_FILE_MUST_EXIST ); if( dlg.ShowModal() == wxID_CANCEL ) return; SetCrossHairPosition( wxPoint( 0, 0 ) ); m_canvas->MoveCursorToCrossHair(); m_canvas->SetIgnoreMouseEvents( false ); wxString filename = dlg.GetPath(); prj.SetRString( PROJECT::SCH_LIB_PATH, filename ); std::unique_ptr<PART_LIB> lib( new PART_LIB( LIBRARY_TYPE_SYMBOL, filename ) ); wxString err; if( !lib->Load( err ) ) { wxString msg = wxString::Format( _( "Error '%s' occurred loading part file '%s'." ), GetChars( err ), GetChars( filename ) ); DisplayError( this, msg ); return; } if( lib->IsEmpty() ) { wxString msg = wxString::Format( _( "No parts found in part file '%s'." ), GetChars( filename ) ); DisplayError( this, msg ); return; } if( lib->GetCount() > 1 ) { wxString msg = wxString::Format( _( "More than one part in part file '%s'." ), GetChars( filename ) ); wxMessageBox( msg, _( "Warning" ), wxOK | wxICON_EXCLAMATION, this ); } LIB_PART* first = lib->GetFirstEntry()->GetPart(); LIB_ITEMS& drawList = first->GetDrawItemList(); for( LIB_ITEM& item : drawList ) { if( item.Type() == LIB_FIELD_T ) continue; if( item.GetUnit() ) item.SetUnit( m_unit ); if( item.GetConvert() ) item.SetConvert( m_convert ); item.SetFlags( IS_NEW | SELECTED ); LIB_ITEM* newItem = (LIB_ITEM*) item.Clone(); newItem->SetParent( part ); part->AddDrawItem( newItem ); } part->RemoveDuplicateDrawItems(); part->ClearSelectedItems(); OnModify(); m_canvas->Refresh(); }
/* * 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::OnLeftClick( wxDC* DC, const wxPoint& aPosition ) { LIB_ITEM* item = m_drawItem; if( m_component == NULL ) // No component loaded ! return; if( item == NULL || item->GetFlags() == 0 ) { item = LocateItemUsingCursor( aPosition ); if( item ) { item->DisplayInfo( this ); } else { DisplayCmpDoc(); if( m_canvas->GetAbortRequest() ) m_canvas->SetAbortRequest( false ); } } switch( GetToolId() ) { case ID_NO_TOOL_SELECTED: if( item && item->GetFlags() ) // moved object { switch( item->Type() ) { case LIB_PIN_T: PlacePin( DC ); break; default: EndDrawGraphicItem( DC ); break; } } break; case ID_LIBEDIT_PIN_BUTT: if( m_drawItem == NULL || m_drawItem->GetFlags() == 0 ) { CreatePin( DC ); } else { PlacePin( DC ); } 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( m_drawItem == NULL || m_drawItem->GetFlags() == 0 ) { m_drawItem = CreateGraphicItem( m_component, DC ); } else if( m_drawItem ) { if( m_drawItem->IsNew() ) GraphicItemBeginDraw( DC ); else EndDrawGraphicItem( DC ); } break; case ID_LIBEDIT_DELETE_ITEM_BUTT: m_drawItem = LocateItemUsingCursor( aPosition ); if( m_drawItem ) deleteItem( DC ); else DisplayCmpDoc(); break; case ID_LIBEDIT_ANCHOR_ITEM_BUTT: SaveCopyInUndoList( m_component ); PlaceAnchor(); SetToolID( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor(), wxEmptyString ); break; default: wxFAIL_MSG( wxString::Format( wxT( "Unhandled command ID %d" ), GetToolId() ) ); SetToolID( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor(), wxEmptyString ); break; } }
bool LIB_EDIT_FRAME::OnRightClick( const wxPoint& aPosition, wxMenu* PopMenu ) { LIB_ITEM* item = GetDrawItem(); bool blockActive = GetScreen()->IsBlockActive(); 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( items ); SetMsgPanel( items ); } else { return true; } m_drawItem = item; bool not_edited = !item->InEditMode(); wxString msg; switch( item->Type() ) { case LIB_PIN_T: AddMenusForPin( PopMenu, (LIB_PIN*) item, this ); break; case LIB_ARC_T: if( not_edited ) { msg = AddHotkeyName( _( "Move Arc" ), g_Libedit_Hokeys_Descr, HK_LIBEDIT_MOVE_GRAPHIC_ITEM ); AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_MOVE_ITEM_REQUEST, msg, KiBitmap( move_arc_xpm ) ); msg = AddHotkeyName( _( "Drag Arc Size" ), g_Libedit_Hokeys_Descr, HK_DRAG ); AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_MODIFY_ITEM, msg, KiBitmap( move_arc_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 Arc" ), g_Libedit_Hokeys_Descr, HK_DELETE ); AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_DELETE_ITEM, msg, KiBitmap( delete_arc_xpm ) ); } break; case LIB_CIRCLE_T: if( not_edited ) { msg = AddHotkeyName( _( "Move Circle" ), g_Libedit_Hokeys_Descr, HK_LIBEDIT_MOVE_GRAPHIC_ITEM ); AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_MOVE_ITEM_REQUEST, msg, KiBitmap( move_circle_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 Circle" ), 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 Rectangle" ), 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 Text" ), g_Libedit_Hokeys_Descr, HK_LIBEDIT_MOVE_GRAPHIC_ITEM ); AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_MOVE_ITEM_REQUEST, msg, KiBitmap( move_text_xpm ) ); } msg = AddHotkeyName( _( "Edit Text" ), g_Libedit_Hokeys_Descr, HK_EDIT ); AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_BODY_EDIT_ITEM, msg, KiBitmap( edit_text_xpm ) ); msg = AddHotkeyName( _( "Rotate Text" ), g_Libedit_Hokeys_Descr, HK_ROTATE ); AddMenuItem( PopMenu, ID_LIBEDIT_ROTATE_ITEM, msg, KiBitmap( edit_text_xpm ) ); if( not_edited ) { msg = AddHotkeyName( _( "Delete Text" ), g_Libedit_Hokeys_Descr, HK_DELETE ); AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_DELETE_ITEM, msg, KiBitmap( delete_text_xpm ) ); } break; case LIB_POLYLINE_T: if( not_edited ) { msg = AddHotkeyName( _( "Move Line" ), g_Libedit_Hokeys_Descr, HK_LIBEDIT_MOVE_GRAPHIC_ITEM ); AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_MOVE_ITEM_REQUEST, msg, KiBitmap( move_line_xpm ) ); msg = AddHotkeyName( _( "Drag Edge Point" ), g_Libedit_Hokeys_Descr, HK_DRAG ); AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_MODIFY_ITEM, msg, KiBitmap( move_line_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 Line " ), g_Libedit_Hokeys_Descr, HK_DELETE ); AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_DELETE_ITEM, msg, KiBitmap( delete_segment_xpm ) ); } if( item->IsNew() ) { if( ( (LIB_POLYLINE*) item )->GetCornerCount() > 2 ) { msg = AddHotkeyName( _( "Delete Segment" ), g_Libedit_Hokeys_Descr, HK_DELETE ); AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_DELETE_CURRENT_POLY_SEGMENT, msg, KiBitmap( delete_segment_xpm ) ); } } break; case LIB_FIELD_T: if( not_edited ) { msg = AddHotkeyName( _( "Move Field" ), g_Libedit_Hokeys_Descr, HK_LIBEDIT_MOVE_GRAPHIC_ITEM ); AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_MOVE_ITEM_REQUEST, msg, KiBitmap( move_field_xpm ) ); } msg = AddHotkeyName( _( "Field Rotate" ), g_Libedit_Hokeys_Descr, HK_ROTATE ); AddMenuItem( PopMenu, ID_LIBEDIT_ROTATE_ITEM, msg, KiBitmap( rotate_field_xpm ) ); msg = AddHotkeyName( _( "Field 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() ) ); m_drawItem = NULL; break; } PopMenu->AppendSeparator(); return true; }
void LIB_EDIT_FRAME::OnLeftClick( wxDC* DC, const wxPoint& aPosition ) { LIB_ITEM* item = m_drawItem; 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_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 ) m_drawItem = CreateGraphicItem( part, DC ); else if( m_drawItem ) { if( m_drawItem->IsNew() ) GraphicItemBeginDraw( DC ); else EndDrawGraphicItem( DC ); } break; case ID_LIBEDIT_DELETE_ITEM_BUTT: m_drawItem = LocateItemUsingCursor( aPosition ); if( m_drawItem ) deleteItem( DC ); else DisplayCmpDoc(); break; case ID_LIBEDIT_ANCHOR_ITEM_BUTT: SaveCopyInUndoList( part ); PlaceAnchor(); SetToolID( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor(), wxEmptyString ); break; default: wxFAIL_MSG( wxString::Format( wxT( "Unhandled command ID %d" ), GetToolId() ) ); SetToolID( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor(), wxEmptyString ); break; } }
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; }