void EDA_DRAW_FRAME::OnToggleCrossHairStyle( wxCommandEvent& aEvent ) { INSTALL_UNBUFFERED_DC( dc, m_canvas ); m_canvas->CrossHairOff( &dc ); m_cursorShape = !m_cursorShape; m_canvas->CrossHairOn( &dc ); }
void EDA_DRAW_PANEL::OnMouseLeaving( wxMouseEvent& event ) { if( m_mouseCaptureCallback == NULL ) // No command in progress. m_requestAutoPan = false; if( !m_enableAutoPan || !m_requestAutoPan || m_ignoreMouseEvents ) return; // Auto pan when mouse has left the client window // Ensure the cross_hair position is updated, // because it will be used to center the screen. // We use a position inside the client window wxSize size = GetClientSize(); wxPoint cross_hair_pos = event.GetPosition(); cross_hair_pos.x = std::min( cross_hair_pos.x, size.x ); cross_hair_pos.y = std::min( cross_hair_pos.y, size.x ); cross_hair_pos.x = std::max( cross_hair_pos.x, 0 ); cross_hair_pos.y = std::max( cross_hair_pos.y, 0 ); INSTALL_UNBUFFERED_DC( dc, this ); cross_hair_pos.x = dc.DeviceToLogicalX( cross_hair_pos.x ); cross_hair_pos.y = dc.DeviceToLogicalY( cross_hair_pos.y ); GetParent()->SetCrossHairPosition( cross_hair_pos ); wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED, ID_POPUP_ZOOM_CENTER ); cmd.SetEventObject( this ); GetEventHandler()->ProcessEvent( cmd ); event.Skip(); }
wxPoint EDA_DRAW_PANEL::GetScreenCenterLogicalPosition() { wxSize size = GetClientSize() / 2; INSTALL_UNBUFFERED_DC( dc, this ); return wxPoint( dc.DeviceToLogicalX( size.x ), dc.DeviceToLogicalY( size.y ) ); }
void EDA_DRAW_PANEL::OnKeyEvent( wxKeyEvent& event ) { int localkey; wxPoint pos; localkey = event.GetKeyCode(); switch( localkey ) { default: break; case WXK_ESCAPE: m_abortRequest = true; if( IsMouseCaptured() ) EndMouseCapture(); else EndMouseCapture( ID_NO_TOOL_SELECTED, m_defaultCursor, wxEmptyString ); break; } /* Normalize keys code to easily handle keys from Ctrl+A to Ctrl+Z * They have an ascii code from 1 to 27 remapped * to GR_KB_CTRL + 'A' to GR_KB_CTRL + 'Z' */ if( event.ControlDown() && localkey >= WXK_CONTROL_A && localkey <= WXK_CONTROL_Z ) localkey += 'A' - 1; /* Disallow shift for keys that have two keycodes on them (e.g. number and * punctuation keys) leaving only the "letter keys" of A-Z. * Then, you can have, e.g. Ctrl-5 and Ctrl-% (GB layout) * and Ctrl-( and Ctrl-5 (FR layout). * Otherwise, you'd have to have to say Ctrl-Shift-5 on a FR layout */ bool keyIsLetter = ( localkey >= 'A' && localkey <= 'Z' ) || ( localkey >= 'a' && localkey <= 'z' ); if( event.ShiftDown() && ( keyIsLetter || localkey > 256 ) ) localkey |= GR_KB_SHIFT; if( event.ControlDown() ) localkey |= GR_KB_CTRL; if( event.AltDown() ) localkey |= GR_KB_ALT; INSTALL_UNBUFFERED_DC( DC, this ); // Some key commands use the current mouse position: refresh it. pos = wxGetMousePosition() - GetScreenPosition(); // Compute the cursor position in drawing units. Also known as logical units to wxDC. pos = wxPoint( DC.DeviceToLogicalX( pos.x ), DC.DeviceToLogicalY( pos.y ) ); GetParent()->SetMousePosition( pos ); if( !GetParent()->GeneralControl( &DC, pos, localkey ) ) event.Skip(); }
wxPoint EDA_DRAW_PANEL::ToLogicalXY( const wxPoint& pos ) { wxPoint ret; INSTALL_UNBUFFERED_DC( dc, this ); ret.x = dc.DeviceToLogicalX( pos.x ); ret.y = dc.DeviceToLogicalY( pos.y ); return ret; }
void SCH_EDIT_FRAME::OnSelectUnit( wxCommandEvent& aEvent ) { SCH_SCREEN* screen = GetScreen(); SCH_ITEM* item = screen->GetCurItem(); wxCHECK_RET( item != NULL && item->Type() == SCH_COMPONENT_T, wxT( "Cannot select unit of invalid schematic item." ) ); INSTALL_UNBUFFERED_DC( dc, m_canvas ); m_canvas->MoveCursorToCrossHair(); SCH_COMPONENT* component = (SCH_COMPONENT*) item; int unit = aEvent.GetId() + 1 - ID_POPUP_SCH_SELECT_UNIT1; LIB_PART* part = GetLibPart( component->GetLibId() ); if( !part ) return; int unitCount = part->GetUnitCount(); wxCHECK_RET( (unit >= 1) && (unit <= unitCount), wxString::Format( wxT( "Cannot select unit %d from component " ), unit ) + part->GetName() ); if( unitCount <= 1 || component->GetUnit() == unit ) return; if( unit > unitCount ) unit = unitCount; STATUS_FLAGS flags = component->GetFlags(); if( !flags ) // No command in progress: save in undo list SaveCopyInUndoList( component, UR_CHANGED ); if( flags ) component->Draw( m_canvas, &dc, wxPoint( 0, 0 ), g_XorMode, g_GhostColor ); else component->Draw( m_canvas, &dc, wxPoint( 0, 0 ), g_XorMode ); /* Update the unit number. */ component->SetUnitSelection( m_CurrentSheet, unit ); component->SetUnit( unit ); component->ClearFlags(); component->SetFlags( flags ); // Restore m_Flag modified by SetUnit() if( m_autoplaceFields ) component->AutoAutoplaceFields( GetScreen() ); if( screen->TestDanglingEnds() ) m_canvas->Refresh(); OnModify(); }
void EDA_DRAW_FRAME::OnToggleCrossHairStyle( wxCommandEvent& aEvent ) { INSTALL_UNBUFFERED_DC( dc, m_canvas ); m_canvas->CrossHairOff( &dc ); auto& galOpts = GetGalDisplayOptions(); galOpts.m_fullscreenCursor = !galOpts.m_fullscreenCursor; galOpts.NotifyChanged(); m_canvas->CrossHairOn( &dc ); }
void LIB_EDIT_FRAME::OnCreateNewPartFromExisting( wxCommandEvent& event ) { wxCHECK_RET( m_component != NULL, wxT( "Cannot create new part from non-existent current part." ) ); INSTALL_UNBUFFERED_DC( dc, m_canvas ); m_canvas->CrossHairOff( &dc ); EditField( &m_component->GetValueField() ); m_canvas->MoveCursorToCrossHair(); m_canvas->CrossHairOn( &dc ); }
bool EDA_DRAW_PANEL::IsPointOnDisplay( const wxPoint& aPosition ) { wxPoint pos; EDA_RECT display_rect; INSTALL_UNBUFFERED_DC( dc, this ); // Refresh the clip box to the entire screen size. SetClipBox( dc ); display_rect = m_ClipBox; // Slightly decreased the size of the useful screen area to avoid drawing limits. #define PIXEL_MARGIN 8 display_rect.Inflate( -PIXEL_MARGIN ); return display_rect.Contains( aPosition ); }
void EDA_DRAW_PANEL::MoveCursor( const wxPoint& aPosition ) { if( GetParent()->IsGalCanvasActive() ) return; int x, y, xPpu, yPpu; wxPoint screenPos, drawingPos; wxRect clientRect( wxPoint( 0, 0 ), GetClientSize() ); INSTALL_UNBUFFERED_DC( dc, this ); screenPos.x = dc.LogicalToDeviceX( aPosition.x ); screenPos.y = dc.LogicalToDeviceY( aPosition.y ); // Scroll if the requested mouse position cursor is outside the drawing area. if( !clientRect.Contains( screenPos ) ) { GetViewStart( &x, &y ); GetScrollPixelsPerUnit( &xPpu, &yPpu ); CalcUnscrolledPosition( screenPos.x, screenPos.y, &drawingPos.x, &drawingPos.y ); wxLogTrace( kicadTraceCoords, wxT( "MoveCursor() initial screen position(%d, %d) " ) \ wxT( "rectangle(%d, %d, %d, %d) view(%d, %d)" ), screenPos.x, screenPos.y, clientRect.x, clientRect.y, clientRect.width, clientRect.height, x, y ); if( screenPos.y < clientRect.GetTop() ) y -= m_scrollIncrementY * yPpu; else if( screenPos.y > clientRect.GetBottom() ) y += m_scrollIncrementY * yPpu; else if( clientRect.GetRight() < screenPos.x ) x += m_scrollIncrementX * xPpu; else x -= m_scrollIncrementX * xPpu; Scroll( x, y ); CalcScrolledPosition( drawingPos.x, drawingPos.y, &screenPos.x, &screenPos.y ); wxLogTrace( kicadTraceCoords, wxT( "MoveCursor() scrolled screen position(%d, %d) view(%d, %d)" ), screenPos.x, screenPos.y, x, y ); } WarpPointer( screenPos.x, screenPos.y ); }
void EDA_DRAW_PANEL::RefreshDrawingRect( const EDA_RECT& aRect, bool aEraseBackground ) { INSTALL_UNBUFFERED_DC( dc, this ); wxRect rect = aRect; rect.x = dc.LogicalToDeviceX( rect.x ); rect.y = dc.LogicalToDeviceY( rect.y ); rect.width = dc.LogicalToDeviceXRel( rect.width ); rect.height = dc.LogicalToDeviceYRel( rect.height ); wxLogTrace( kicadTraceCoords, wxT( "Refresh area: drawing (%d, %d, %d, %d), device (%d, %d, %d, %d)" ), aRect.GetX(), aRect.GetY(), aRect.GetWidth(), aRect.GetHeight(), rect.x, rect.y, rect.width, rect.height ); RefreshRect( rect, aEraseBackground ); }
void EDA_DRAW_PANEL::EndMouseCapture( int id, int cursor, const wxString& title, bool aCallEndFunc ) { if( m_mouseCaptureCallback && m_endMouseCaptureCallback && aCallEndFunc ) { INSTALL_UNBUFFERED_DC( dc, this ); m_endMouseCaptureCallback( this, &dc ); } m_mouseCaptureCallback = NULL; m_endMouseCaptureCallback = NULL; SetAutoPanRequest( false ); if( id != -1 && cursor != -1 ) { wxASSERT( cursor > wxCURSOR_NONE && cursor < wxCURSOR_MAX ); GetParent()->SetToolID( id, cursor, title ); } }
void SCH_EDIT_FRAME::OnCopySchematicItemRequest( wxCommandEvent& event ) { SCH_ITEM * curr_item = GetScreen()->GetCurItem(); if( !curr_item || curr_item->GetFlags() ) return; INSTALL_UNBUFFERED_DC( dc, m_canvas ); switch( curr_item->Type() ) { case SCH_COMPONENT_T: { SCH_COMPONENT* newitem; newitem = new SCH_COMPONENT( *( (SCH_COMPONENT*) curr_item ) ); newitem->SetTimeStamp( GetNewTimeStamp() ); newitem->ClearAnnotation( NULL ); newitem->SetFlags( IS_NEW ); // Draw the new part, MoveItem() expects it to be already on screen. newitem->Draw( m_canvas, &dc, wxPoint( 0, 0 ), g_XorMode ); PrepareMoveItem( newitem, &dc ); } break; case SCH_TEXT_T: case SCH_LABEL_T: case SCH_GLOBAL_LABEL_T: case SCH_HIERARCHICAL_LABEL_T: { SCH_TEXT* newitem = (SCH_TEXT*) curr_item->Clone(); newitem->SetFlags( IS_NEW ); // Draw the new item, MoveItem() expects it to be already on screen. newitem->Draw( m_canvas, &dc, wxPoint( 0, 0 ), g_XorMode ); PrepareMoveItem( newitem, &dc ); } break; default: break; } }
bool EDA_DRAW_PANEL::OnRightClick( wxMouseEvent& event ) { wxPoint pos; wxMenu MasterMenu; INSTALL_UNBUFFERED_DC( dc, this ); pos = event.GetLogicalPosition( dc ); if( !GetParent()->OnRightClick( pos, &MasterMenu ) ) return false; GetParent()->AddMenuZoomAndGrid( &MasterMenu ); pos = event.GetPosition(); m_ignoreMouseEvents = true; PopupMenu( &MasterMenu, pos ); MoveCursorToCrossHair(); m_ignoreMouseEvents = false; return true; }
void LIB_EDIT_FRAME::OnOrient( wxCommandEvent& aEvent ) { INSTALL_UNBUFFERED_DC( dc, m_canvas ); SCH_SCREEN* screen = GetScreen(); // Allows block rotate operation on hot key. if( screen->m_BlockLocate.GetState() != STATE_NO_BLOCK ) { if( aEvent.GetId() == ID_LIBEDIT_MIRROR_X ) { m_canvas->MoveCursorToCrossHair(); screen->m_BlockLocate.SetMessageBlock( this ); screen->m_BlockLocate.SetCommand( BLOCK_MIRROR_X ); HandleBlockEnd( &dc ); } else if( aEvent.GetId() == ID_LIBEDIT_MIRROR_Y ) { m_canvas->MoveCursorToCrossHair(); screen->m_BlockLocate.SetMessageBlock( this ); screen->m_BlockLocate.SetCommand( BLOCK_MIRROR_Y ); HandleBlockEnd( &dc ); } } }
void PCB_BASE_FRAME::CursorGoto( const wxPoint& aPos, bool aWarp ) { // factored out of pcbnew/find.cpp INSTALL_UNBUFFERED_DC( dc, m_canvas ); // There may be need to reframe the drawing. if( !m_canvas->IsPointOnDisplay( aPos ) ) { SetCrossHairPosition( aPos ); RedrawScreen( aPos, aWarp ); } else { // Put cursor on item position m_canvas->CrossHairOff( &dc ); SetCrossHairPosition( aPos ); if( aWarp ) m_canvas->MoveCursorToCrossHair(); } m_canvas->CrossHairOn( &dc ); m_canvas->CrossHairOn( &dc ); }
void SCH_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) { int id = event.GetId(); wxPoint pos; SCH_SCREEN* screen = GetScreen(); SCH_ITEM* item = screen->GetCurItem(); pos = wxGetMousePosition(); pos.y += 20; // If needed, stop the current command and deselect current tool switch( id ) { case wxID_CUT: case wxID_COPY: case ID_POPUP_CANCEL_CURRENT_COMMAND: case ID_POPUP_SCH_ENTRY_SELECT_SLASH: case ID_POPUP_SCH_ENTRY_SELECT_ANTISLASH: case ID_POPUP_SCH_BEGIN_WIRE: case ID_POPUP_SCH_BEGIN_BUS: case ID_POPUP_END_LINE: case ID_POPUP_SCH_SET_SHAPE_TEXT: case ID_POPUP_SCH_CLEANUP_SHEET: case ID_POPUP_SCH_END_SHEET: case ID_POPUP_SCH_RESIZE_SHEET: case ID_POPUP_IMPORT_GLABEL: case ID_POPUP_SCH_INIT_CMP: case ID_POPUP_SCH_DISPLAYDOC_CMP: case ID_POPUP_SCH_EDIT_CONVERT_CMP: case ID_POPUP_DELETE_BLOCK: case ID_POPUP_PLACE_BLOCK: case ID_POPUP_ZOOM_BLOCK: case ID_POPUP_DRAG_BLOCK: case ID_POPUP_COPY_BLOCK: case ID_POPUP_SCH_DELETE_NODE: case ID_POPUP_SCH_DELETE_CONNECTION: case ID_POPUP_SCH_ENTER_SHEET: case ID_POPUP_SCH_LEAVE_SHEET: case ID_POPUP_SCH_ADD_JUNCTION: case ID_POPUP_SCH_ADD_LABEL: case ID_POPUP_SCH_GETINFO_MARKER: /* At this point: Do nothing. these commands do not need to stop the * current command (mainly a block command) or reset the current state * They will be executed later, in next switch structure. */ break; case ID_POPUP_SCH_DELETE_CMP: case ID_POPUP_SCH_DELETE: // Stop the current command (if any) but keep the current tool m_canvas->EndMouseCapture(); break; default: // Stop the current command and deselect the current tool m_canvas->EndMouseCapture( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor() ); break; } INSTALL_UNBUFFERED_DC( dc, m_canvas ); item = screen->GetCurItem(); // Can be modified by previous calls. switch( id ) { case ID_HIERARCHY: InstallHierarchyFrame( &dc, pos ); SetRepeatItem( NULL ); break; case wxID_CUT: if( screen->m_BlockLocate.GetCommand() != BLOCK_MOVE ) break; screen->m_BlockLocate.SetCommand( BLOCK_DELETE ); screen->m_BlockLocate.SetMessageBlock( this ); HandleBlockEnd( &dc ); SetRepeatItem( NULL ); SetSheetNumberAndCount(); break; case wxID_PASTE: HandleBlockBegin( &dc, BLOCK_PASTE, GetCrossHairPosition() ); break; case ID_POPUP_SCH_ENTRY_SELECT_SLASH: m_canvas->MoveCursorToCrossHair(); SetBusEntryShape( &dc, dynamic_cast<SCH_BUS_ENTRY_BASE*>( item ), '/' ); break; case ID_POPUP_SCH_ENTRY_SELECT_ANTISLASH: m_canvas->MoveCursorToCrossHair(); SetBusEntryShape( &dc, dynamic_cast<SCH_BUS_ENTRY_BASE*>( item ), '\\' ); break; case ID_POPUP_CANCEL_CURRENT_COMMAND: if( m_canvas->IsMouseCaptured() ) { m_canvas->EndMouseCapture(); SetToolID( GetToolId(), m_canvas->GetCurrentCursor(), wxEmptyString ); } else { SetToolID( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor(), wxEmptyString ); } break; case ID_POPUP_END_LINE: m_canvas->MoveCursorToCrossHair(); EndSegment( &dc ); break; case ID_POPUP_SCH_BEGIN_WIRE: m_canvas->MoveCursorToCrossHair(); OnLeftClick( &dc, GetCrossHairPosition() ); break; case ID_POPUP_SCH_BEGIN_BUS: m_canvas->MoveCursorToCrossHair(); OnLeftClick( &dc, GetCrossHairPosition() ); break; case ID_POPUP_SCH_SET_SHAPE_TEXT: // Not used break; case ID_POPUP_SCH_DELETE_NODE: case ID_POPUP_SCH_DELETE_CONNECTION: m_canvas->MoveCursorToCrossHair(); DeleteConnection( id == ID_POPUP_SCH_DELETE_CONNECTION ); screen->SetCurItem( NULL ); SetRepeatItem( NULL ); screen->TestDanglingEnds( m_canvas, &dc ); m_canvas->Refresh(); break; case ID_POPUP_SCH_BREAK_WIRE: { DLIST< SCH_ITEM > oldWires; oldWires.SetOwnership( false ); // Prevent DLIST for deleting items in destructor. m_canvas->MoveCursorToCrossHair(); screen->ExtractWires( oldWires, true ); screen->BreakSegment( GetCrossHairPosition() ); if( oldWires.GetCount() != 0 ) { PICKED_ITEMS_LIST oldItems; oldItems.m_Status = UR_WIRE_IMAGE; while( oldWires.GetCount() != 0 ) { ITEM_PICKER picker = ITEM_PICKER( oldWires.PopFront(), UR_WIRE_IMAGE ); oldItems.PushItem( picker ); } SaveCopyInUndoList( oldItems, UR_WIRE_IMAGE ); } screen->TestDanglingEnds( m_canvas, &dc ); } break; case ID_POPUP_SCH_DELETE_CMP: case ID_POPUP_SCH_DELETE: if( item == NULL ) break; DeleteItem( item ); screen->SetCurItem( NULL ); SetRepeatItem( NULL ); screen->TestDanglingEnds( m_canvas, &dc ); SetSheetNumberAndCount(); OnModify(); break; case ID_POPUP_SCH_END_SHEET: m_canvas->MoveCursorToCrossHair(); addCurrentItemToList( &dc ); break; case ID_POPUP_SCH_RESIZE_SHEET: ReSizeSheet( (SCH_SHEET*) item, &dc ); screen->TestDanglingEnds( m_canvas, &dc ); break; case ID_POPUP_IMPORT_GLABEL: if( item != NULL && item->Type() == SCH_SHEET_T ) screen->SetCurItem( ImportSheetPin( (SCH_SHEET*) item, &dc ) ); break; case ID_POPUP_SCH_CLEANUP_SHEET: if( item != NULL && item->Type() == SCH_SHEET_T ) { SCH_SHEET* sheet = (SCH_SHEET*) item; if( !sheet->HasUndefinedPins() ) { DisplayInfoMessage( this, _( "There are no undefined labels in this sheet to clean up." ) ); return; } if( !IsOK( this, _( "Do you wish to cleanup this sheet?" ) ) ) return; /* Save sheet in undo list before cleaning up unreferenced hierarchical labels. */ SaveCopyInUndoList( sheet, UR_CHANGED ); sheet->CleanupSheet(); OnModify(); m_canvas->RefreshDrawingRect( sheet->GetBoundingBox() ); } break; case ID_POPUP_SCH_INIT_CMP: m_canvas->MoveCursorToCrossHair(); break; case ID_POPUP_SCH_EDIT_CONVERT_CMP: // Ensure the struct is a component (could be a struct of a component, like Field, text..) if( item && item->Type() == SCH_COMPONENT_T ) { m_canvas->MoveCursorToCrossHair(); ConvertPart( (SCH_COMPONENT*) item, &dc ); } break; case ID_POPUP_SCH_DISPLAYDOC_CMP: // Ensure the struct is a component (could be a piece of a component, like Field, text..) if( item && item->Type() == SCH_COMPONENT_T ) { LIB_ALIAS* LibEntry; LibEntry = CMP_LIBRARY::FindLibraryEntry( ( (SCH_COMPONENT*) item )->GetLibName() ); if( LibEntry && LibEntry->GetDocFileName() != wxEmptyString ) { GetAssociatedDocument( this, LibEntry->GetDocFileName(), &wxGetApp().GetLibraryPathList() ); } } break; case ID_POPUP_SCH_ENTER_SHEET: if( item && (item->Type() == SCH_SHEET_T) ) { m_CurrentSheet->Push( (SCH_SHEET*) item ); DisplayCurrentSheet(); } break; case ID_POPUP_SCH_LEAVE_SHEET: m_CurrentSheet->Pop(); DisplayCurrentSheet(); break; case wxID_COPY: // really this is a Save block for paste screen->m_BlockLocate.SetCommand( BLOCK_SAVE ); screen->m_BlockLocate.SetMessageBlock( this ); HandleBlockEnd( &dc ); break; case ID_POPUP_PLACE_BLOCK: m_canvas->SetAutoPanRequest( false ); m_canvas->MoveCursorToCrossHair(); HandleBlockPlace( &dc ); break; case ID_POPUP_ZOOM_BLOCK: screen->m_BlockLocate.SetCommand( BLOCK_ZOOM ); screen->m_BlockLocate.SetMessageBlock( this ); HandleBlockEnd( &dc ); break; case ID_POPUP_DELETE_BLOCK: m_canvas->MoveCursorToCrossHair(); screen->m_BlockLocate.SetCommand( BLOCK_DELETE ); screen->m_BlockLocate.SetMessageBlock( this ); HandleBlockEnd( &dc ); SetSheetNumberAndCount(); break; case ID_POPUP_COPY_BLOCK: m_canvas->MoveCursorToCrossHair(); screen->m_BlockLocate.SetCommand( BLOCK_COPY ); screen->m_BlockLocate.SetMessageBlock( this ); HandleBlockEnd( &dc ); break; case ID_POPUP_DRAG_BLOCK: m_canvas->MoveCursorToCrossHair(); screen->m_BlockLocate.SetCommand( BLOCK_DRAG ); screen->m_BlockLocate.SetMessageBlock( this ); HandleBlockEnd( &dc ); break; case ID_POPUP_SCH_ADD_JUNCTION: m_canvas->MoveCursorToCrossHair(); screen->SetCurItem( AddJunction( &dc, GetCrossHairPosition(), true ) ); screen->TestDanglingEnds( m_canvas, &dc ); screen->SetCurItem( NULL ); break; case ID_POPUP_SCH_ADD_LABEL: case ID_POPUP_SCH_ADD_GLABEL: screen->SetCurItem( CreateNewText( &dc, id == ID_POPUP_SCH_ADD_LABEL ? LAYER_LOCLABEL : LAYER_GLOBLABEL ) ); item = screen->GetCurItem(); if( item ) addCurrentItemToList( &dc ); break; case ID_POPUP_SCH_GETINFO_MARKER: if( item && item->Type() == SCH_MARKER_T ) ( (SCH_MARKER*) item )->DisplayMarkerInfo( this ); break; default: // Log error: wxFAIL_MSG( wxString::Format( wxT( "Cannot process command event ID %d" ), event.GetId() ) ); break; } // End switch ( id ) (Command execution) if( GetToolId() == ID_NO_TOOL_SELECTED ) SetRepeatItem( NULL ); }
void EDA_DRAW_PANEL::OnTimer( wxTimerEvent& event ) { INSTALL_UNBUFFERED_DC( DC, this ); DC.SetBackground( *wxBLACK_BRUSH ); GetParent()->OnLeftClick( &DC, m_CursorClickPos ); }
void EDA_DRAW_PANEL::OnMouseWheel( wxMouseEvent& event ) { if( m_ignoreMouseEvents ) return; wxRect rect = wxRect( wxPoint( 0, 0 ), GetClientSize() ); // Ignore scroll events if the cursor is outside the drawing area. if( event.GetWheelRotation() == 0 || !GetParent()->IsEnabled() || !rect.Contains( event.GetPosition() ) ) { wxLogTrace( kicadTraceCoords, wxT( "OnMouseWheel() position(%d, %d) rectangle(%d, %d, %d, %d)" ), event.GetPosition().x, event.GetPosition().y, rect.x, rect.y, rect.width, rect.height ); event.Skip(); return; } INSTALL_UNBUFFERED_DC( dc, this ); GetParent()->SetCrossHairPosition( event.GetLogicalPosition( dc ) ); wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED ); cmd.SetEventObject( this ); bool offCenterReq = event.ControlDown() && event.ShiftDown(); offCenterReq = offCenterReq || m_enableZoomNoCenter; int axis = event.GetWheelAxis(); int wheelRotation = event.GetWheelRotation(); if( m_enableMousewheelPan ) { // MousewheelPAN + Ctrl = zooming if( event.ControlDown() && !event.ShiftDown() ) { if( wheelRotation > 0 ) cmd.SetId( ID_POPUP_ZOOM_IN ); else if( wheelRotation < 0) cmd.SetId( ID_POPUP_ZOOM_OUT ); } // MousewheelPAN + Shift = horizontal scrolling // Without modifiers MousewheelPAN - just pan else { if( event.ShiftDown() && !event.ControlDown() ) axis = wxMOUSE_WHEEL_HORIZONTAL; wxPoint newStart = GetViewStart(); wxPoint center = GetParent()->GetScrollCenterPosition(); double scale = GetParent()->GetScreen()->GetScalingFactor(); if( axis == wxMOUSE_WHEEL_HORIZONTAL ) { newStart.x += wheelRotation; center.x += KiROUND( (double) wheelRotation / scale ); } else { newStart.y -= wheelRotation; center.y -= KiROUND( (double) wheelRotation / scale ); } Scroll( newStart ); GetParent()->SetScrollCenterPosition( center ); GetParent()->SetCrossHairPosition( center, true ); GetParent()->RedrawScreen( center, false ); } } else if( wheelRotation > 0 ) { if( event.ShiftDown() && !event.ControlDown() ) cmd.SetId( ID_PAN_UP ); else if( event.ControlDown() && !event.ShiftDown() ) cmd.SetId( ID_PAN_LEFT ); else if( offCenterReq ) cmd.SetId( ID_OFFCENTER_ZOOM_IN ); else cmd.SetId( ID_POPUP_ZOOM_IN ); } else if( wheelRotation < 0 ) { if( event.ShiftDown() && !event.ControlDown() ) cmd.SetId( ID_PAN_DOWN ); else if( event.ControlDown() && !event.ShiftDown() ) cmd.SetId( ID_PAN_RIGHT ); else if( offCenterReq ) cmd.SetId( ID_OFFCENTER_ZOOM_OUT ); else cmd.SetId( ID_POPUP_ZOOM_OUT ); } if( cmd.GetId() ) GetEventHandler()->ProcessEvent( cmd ); event.Skip(); }
SCH_ITEM* SCH_EDIT_FRAME::FindComponentAndItem( const wxString& aReference, bool aSearchHierarchy, SCH_SEARCH_T aSearchType, const wxString& aSearchText, bool aWarpMouse ) { SCH_SHEET_PATH* sheet; SCH_SHEET_PATH* sheetWithComponentFound = NULL; SCH_ITEM* item = NULL; SCH_COMPONENT* Component = NULL; wxPoint pos, curpos; bool centerAndRedraw = false; bool notFound = true; wxString msg; LIB_PIN* pin; SCH_SHEET_LIST sheetList; sheet = sheetList.GetFirst(); if( !aSearchHierarchy ) sheet = m_CurrentSheet; for( ; sheet != NULL; sheet = sheetList.GetNext() ) { item = (SCH_ITEM*) sheet->LastDrawList(); for( ; ( item != NULL ) && ( notFound == true ); item = item->Next() ) { if( item->Type() != SCH_COMPONENT_T ) continue; SCH_COMPONENT* pSch = (SCH_COMPONENT*) item; if( aReference.CmpNoCase( pSch->GetRef( sheet ) ) == 0 ) { Component = pSch; sheetWithComponentFound = sheet; switch( aSearchType ) { default: case FIND_COMPONENT_ONLY: // Find component only notFound = false; pos = pSch->GetPosition(); break; case FIND_PIN: // find a pin pos = pSch->GetPosition(); // temporary: will be changed if the pin is found. pin = pSch->GetPin( aSearchText ); if( pin == NULL ) break; notFound = false; pos += pin->GetPosition(); break; case FIND_REFERENCE: // find reference notFound = false; pos = pSch->GetField( REFERENCE )->GetPosition(); break; case FIND_VALUE: // find value pos = pSch->GetPosition(); if( aSearchText.CmpNoCase( pSch->GetField( VALUE )->m_Text ) != 0 ) break; notFound = false; pos = pSch->GetField( VALUE )->GetPosition(); break; } } } if( (aSearchHierarchy == false) || (notFound == false) ) break; } if( Component ) { sheet = sheetWithComponentFound; if( *sheet != *m_CurrentSheet ) { sheet->LastScreen()->SetZoom( GetScreen()->GetZoom() ); *m_CurrentSheet = *sheet; m_CurrentSheet->UpdateAllScreenReferences(); centerAndRedraw = true; } wxPoint delta; pos -= Component->GetPosition(); delta = Component->GetTransform().TransformCoordinate( pos ); pos = delta + Component->GetPosition(); /* There may be need to reframe the drawing */ if( ! m_canvas->IsPointOnDisplay( pos ) ) { centerAndRedraw = true; } if( centerAndRedraw ) { GetScreen()->SetCrossHairPosition(pos); RedrawScreen( pos, aWarpMouse ); } else { INSTALL_UNBUFFERED_DC( dc, m_canvas ); m_canvas->CrossHairOff( &dc ); if( aWarpMouse ) m_canvas->MoveCursor( pos ); GetScreen()->SetCrossHairPosition(pos); m_canvas->CrossHairOn( &dc ); } } /* Print diag */ wxString msg_item; msg = aReference; switch( aSearchType ) { default: case FIND_COMPONENT_ONLY: // Find component only break; case FIND_PIN: // find a pin msg_item = _( "Pin " ) + aSearchText; break; case FIND_REFERENCE: // find reference msg_item = _( "Ref " ) + aSearchText; break; case FIND_VALUE: // find value msg_item = _( "Value " ) + aSearchText; break; case FIND_FIELD: // find field. todo msg_item = _( "Field " ) + aSearchText; break; } if( Component ) { if( !notFound ) { if( !msg_item.IsEmpty() ) msg += wxT( " " ) + msg_item; msg += _( " found" ); } else { msg += _( " found" ); if( !msg_item.IsEmpty() ) { msg += wxT( " but " ) + msg_item + _( " not found" ); } } } else { if( !msg_item.IsEmpty() ) msg += wxT( " " ) + msg_item; msg += _( " not found" ); } SetStatusText( msg ); return item; }
void EDA_DRAW_PANEL::OnMouseWheel( wxMouseEvent& event ) { if( m_ignoreMouseEvents ) return; wxRect rect = wxRect( wxPoint( 0, 0 ), GetClientSize() ); // Ignore scroll events if the cursor is outside the drawing area. if( event.GetWheelRotation() == 0 || !GetParent()->IsEnabled() || !rect.Contains( event.GetPosition() ) ) { wxLogTrace( KICAD_TRACE_COORDS, wxT( "OnMouseWheel() position(%d, %d) rectangle(%d, %d, %d, %d)" ), event.GetPosition().x, event.GetPosition().y, rect.x, rect.y, rect.width, rect.height ); event.Skip(); return; } INSTALL_UNBUFFERED_DC( dc, this ); GetParent()->SetCrossHairPosition( event.GetLogicalPosition( dc ) ); wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED ); cmd.SetEventObject( this ); bool offCenterReq = event.ControlDown() && event.ShiftDown(); offCenterReq = offCenterReq || m_enableZoomNoCenter; int axis = event.GetWheelAxis(); // This is a zoom in or out command if( event.GetWheelRotation() > 0 ) { if( event.ShiftDown() && !event.ControlDown() ) { if( axis == 0 ) cmd.SetId( ID_PAN_UP ); else cmd.SetId( ID_PAN_RIGHT ); } else if( event.ControlDown() && !event.ShiftDown() ) cmd.SetId( ID_PAN_LEFT ); else if( offCenterReq ) cmd.SetId( ID_OFFCENTER_ZOOM_IN ); else cmd.SetId( ID_POPUP_ZOOM_IN ); } else if( event.GetWheelRotation() < 0 ) { if( event.ShiftDown() && !event.ControlDown() ) { if( axis == 0 ) cmd.SetId( ID_PAN_DOWN ); else cmd.SetId( ID_PAN_LEFT ); } else if( event.ControlDown() && !event.ShiftDown() ) cmd.SetId( ID_PAN_RIGHT ); else if( offCenterReq ) cmd.SetId( ID_OFFCENTER_ZOOM_OUT ); else cmd.SetId( ID_POPUP_ZOOM_OUT ); } GetEventHandler()->ProcessEvent( cmd ); event.Skip(); }
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 PCB_EDIT_FRAME::ListNetsAndSelect( wxCommandEvent& event ) { NETINFO_ITEM* net; wxString netFilter; wxArrayString list; netFilter = wxT( "*" ); wxTextEntryDialog dlg( this, _( "Filter Net Names" ), _( "Net Filter" ), netFilter ); if( dlg.ShowModal() != wxID_OK ) return; // cancelled by user netFilter = dlg.GetValue( ); if( netFilter.IsEmpty() ) return; wxString Line; for( unsigned ii = 0; ii < GetBoard()->GetNetCount(); ii++ ) { net = GetBoard()->m_NetInfo.GetNetItem( ii ); if( !WildCompareString( netFilter, net->GetNetname(), false ) ) continue; Line.Printf( wxT( "net %3.3d: %s" ), net->GetNet(), GetChars( net->GetNetname() ) ); list.Add( Line ); } wxSingleChoiceDialog choiceDlg( this, wxEmptyString, _( "Select Net" ), list ); if( (choiceDlg.ShowModal() == wxID_CANCEL) || (choiceDlg.GetSelection() == wxNOT_FOUND) ) return; bool found = false; unsigned netcode = (unsigned) choiceDlg.GetSelection(); // Search for the net selected. for( unsigned ii = 0; ii < GetBoard()->GetNetCount(); ii++ ) { net = GetBoard()->FindNet( ii ); if( !WildCompareString( netFilter, net->GetNetname(), false ) ) continue; if( ii == netcode ) { netcode = net->GetNet(); found = true; break; } } if( found ) { INSTALL_UNBUFFERED_DC( dc, m_canvas ); if( GetBoard()->IsHighLightNetON() ) HighLight( &dc ); GetBoard()->SetHighLightNet( netcode ); HighLight( &dc ); } }
void EDA_DRAW_PANEL::OnMouseEvent( wxMouseEvent& event ) { int localbutt = 0; BASE_SCREEN* screen = GetScreen(); if( !screen ) return; /* Adjust value to filter mouse displacement before consider the drag * mouse is really a drag command, not just a movement while click */ #define MIN_DRAG_COUNT_FOR_START_BLOCK_COMMAND 5 if( event.Leaving() ) m_canStartBlock = -1; if( !IsMouseCaptured() ) // No mouse capture in progress. SetAutoPanRequest( false ); if( GetParent()->IsActive() ) SetFocus(); else return; if( !event.IsButton() && !event.Moving() && !event.Dragging() ) return; if( event.RightDown() ) { OnRightClick( event ); return; } if( m_ignoreMouseEvents ) return; if( event.LeftDown() ) localbutt = GR_M_LEFT_DOWN; if( event.ButtonDClick( 1 ) ) localbutt = GR_M_LEFT_DOWN | GR_M_DCLICK; if( event.MiddleDown() ) localbutt = GR_M_MIDDLE_DOWN; INSTALL_UNBUFFERED_DC( DC, this ); DC.SetBackground( *wxBLACK_BRUSH ); // Compute the cursor position in drawing (logical) units. GetParent()->SetMousePosition( event.GetLogicalPosition( DC ) ); int kbstat = 0; if( event.ShiftDown() ) kbstat |= GR_KB_SHIFT; if( event.ControlDown() ) kbstat |= GR_KB_CTRL; if( event.AltDown() ) kbstat |= GR_KB_ALT; // Calling Double Click and Click functions : if( localbutt == (int) ( GR_M_LEFT_DOWN | GR_M_DCLICK ) ) { if( m_ClickTimer ) { m_ClickTimer->Stop(); wxDELETE( m_ClickTimer ); } GetParent()->OnLeftDClick( &DC, GetParent()->RefPos( true ) ); // inhibit a response to the mouse left button release, // because we have a double click, and we do not want a new // OnLeftClick command at end of this Double Click m_ignoreNextLeftButtonRelease = true; } else if( event.LeftUp() ) { // A block command is in progress: a left up is the end of block // or this is the end of a double click, already seen // Note also m_ignoreNextLeftButtonRelease can be set by // the call to OnLeftClick(), so do not change it after calling OnLeftClick bool ignoreEvt = m_ignoreNextLeftButtonRelease; m_ignoreNextLeftButtonRelease = false; if( screen->m_BlockLocate.GetState() == STATE_NO_BLOCK && !ignoreEvt ) { EDA_ITEM* item = screen->GetCurItem(); m_CursorClickPos = GetParent()->RefPos( true ); // If we have an item already selected, or we are using a tool, // we won't use the disambiguation menu so process the click immediately if( ( item && item->GetFlags() ) || GetParent()->GetToolId() != ID_NO_TOOL_SELECTED ) GetParent()->OnLeftClick( &DC, m_CursorClickPos ); else { wxDELETE( m_ClickTimer ); m_ClickTimer = new wxTimer(this, ID_MOUSE_DOUBLECLICK); m_ClickTimer->StartOnce( m_doubleClickInterval ); } } } else if( !event.LeftIsDown() ) { /* be sure there is a response to a left button release command * even when a LeftUp event is not seen. This happens when a * double click opens a dialog box, and the release mouse button * is made when the dialog box is opened. */ m_ignoreNextLeftButtonRelease = false; } if( event.ButtonDown( wxMOUSE_BTN_MIDDLE ) ) { m_PanStartCenter = GetParent()->GetScrollCenterPosition(); m_PanStartEventPosition = event.GetPosition(); INSTALL_UNBUFFERED_DC( dc, this ); CrossHairOff( &dc ); SetCursor( wxCURSOR_SIZING ); } if( event.ButtonUp( wxMOUSE_BTN_MIDDLE ) ) { INSTALL_UNBUFFERED_DC( dc, this ); CrossHairOn( &dc ); SetCursor( (wxStockCursor) m_currentCursor ); } if( event.MiddleIsDown() ) { wxPoint currentPosition = event.GetPosition(); double scale = GetParent()->GetScreen()->GetScalingFactor(); int x = m_PanStartCenter.x + KiROUND( (double) ( m_PanStartEventPosition.x - currentPosition.x ) / scale ); int y = m_PanStartCenter.y + KiROUND( (double) ( m_PanStartEventPosition.y - currentPosition.y ) / scale ); GetParent()->RedrawScreen( wxPoint( x, y ), false ); } // Calling the general function on mouse changes (and pseudo key commands) GetParent()->GeneralControl( &DC, event.GetLogicalPosition( DC ), 0 ); /*******************************/ /* Control of block commands : */ /*******************************/ // Command block can't start if mouse is dragging a new panel static EDA_DRAW_PANEL* lastPanel; if( lastPanel != this ) { m_minDragEventCount = 0; m_canStartBlock = -1; } /* A new command block can start after a release buttons * and if the drag is enough * This is to avoid a false start block when a dialog box is dismissed, * or when changing panels in hierarchy navigation * or when clicking while and moving mouse */ if( !event.LeftIsDown() && !event.MiddleIsDown() ) { m_minDragEventCount = 0; m_canStartBlock = 0; /* Remember the last cursor position when a drag mouse starts * this is the last position ** before ** clicking a button * this is useful to start a block command from the point where the * mouse was clicked first * (a filter creates a delay for the real block command start, and * we must remember this point) */ m_CursorStartPos = GetParent()->GetCrossHairPosition(); } if( m_enableBlockCommands && !(localbutt & GR_M_DCLICK) ) { if( !screen->IsBlockActive() ) { screen->m_BlockLocate.SetOrigin( m_CursorStartPos ); } if( event.LeftDown() ) { if( screen->m_BlockLocate.GetState() == STATE_BLOCK_MOVE ) { SetAutoPanRequest( false ); GetParent()->HandleBlockPlace( &DC ); m_ignoreNextLeftButtonRelease = true; } } else if( ( m_canStartBlock >= 0 ) && event.LeftIsDown() && !IsMouseCaptured() ) { // Mouse is dragging: if no block in progress, start a block command. if( screen->m_BlockLocate.GetState() == STATE_NO_BLOCK ) { // Start a block command int cmd_type = kbstat; // A block command is started if the drag is enough. A small // drag is ignored (it is certainly a little mouse move when // clicking) not really a drag mouse if( m_minDragEventCount < MIN_DRAG_COUNT_FOR_START_BLOCK_COMMAND ) m_minDragEventCount++; else { auto cmd = (GetParent()->GetToolId() == ID_ZOOM_SELECTION) ? BLOCK_ZOOM : 0; if( !GetParent()->HandleBlockBegin( &DC, cmd_type, m_CursorStartPos, cmd ) ) { // should not occur: error GetParent()->DisplayToolMsg( wxT( "EDA_DRAW_PANEL::OnMouseEvent() Block Error" ) ); } else { SetAutoPanRequest( true ); SetCursor( wxCURSOR_SIZING ); } } } } if( event.ButtonUp( wxMOUSE_BTN_LEFT ) ) { /* Release the mouse button: end of block. * The command can finish (DELETE) or have a next command (MOVE, * COPY). However the block command is canceled if the block * size is small because a block command filtering is already * made, this case happens, but only when the on grid cursor has * not moved. */ #define BLOCK_MINSIZE_LIMIT 1 bool BlockIsSmall = ( std::abs( screen->m_BlockLocate.GetWidth() ) < BLOCK_MINSIZE_LIMIT ) && ( std::abs( screen->m_BlockLocate.GetHeight() ) < BLOCK_MINSIZE_LIMIT ); if( (screen->m_BlockLocate.GetState() != STATE_NO_BLOCK) && BlockIsSmall ) { if( m_endMouseCaptureCallback ) { m_endMouseCaptureCallback( this, &DC ); SetAutoPanRequest( false ); } SetCursor( (wxStockCursor) m_currentCursor ); } else if( screen->m_BlockLocate.GetState() == STATE_BLOCK_END ) { SetAutoPanRequest( false ); GetParent()->HandleBlockEnd( &DC ); SetCursor( (wxStockCursor) m_currentCursor ); if( screen->m_BlockLocate.GetState() == STATE_BLOCK_MOVE ) { SetAutoPanRequest( true ); SetCursor( wxCURSOR_HAND ); } } } } // End of block command on a double click // To avoid an unwanted block move command if the mouse is moved while double clicking if( localbutt == (int) ( GR_M_LEFT_DOWN | GR_M_DCLICK ) ) { if( !screen->IsBlockActive() && IsMouseCaptured() ) { m_endMouseCaptureCallback( this, &DC ); } } lastPanel = this; #ifdef __WXGTK3__ // Screen has to be updated on every operation, otherwise the cursor leaves a trail (when xor // operation is changed to copy) or is not updated at all. Refresh(); #endif }
void SCH_EDIT_FRAME::OnMoveItem( wxCommandEvent& aEvent ) { SCH_SCREEN* screen = GetScreen(); SCH_ITEM* item = screen->GetCurItem(); if( screen->m_BlockLocate.GetState() != STATE_NO_BLOCK ) { // trying to move an item when there is a block at the same time is not acceptable return; } if( item == NULL ) { // If we didn't get here by a hot key, then something has gone wrong. if( aEvent.GetInt() == 0 ) return; EDA_HOTKEY_CLIENT_DATA* data = (EDA_HOTKEY_CLIENT_DATA*) aEvent.GetClientObject(); wxCHECK_RET( data != NULL, wxT( "Invalid hot key client object." ) ); item = LocateAndShowItem( data->GetPosition(), SCH_COLLECTOR::MovableItems, aEvent.GetInt() ); // Exit if no item found at the current location or the item is already being edited. if( (item == NULL) || (item->GetFlags() != 0) ) return; } INSTALL_UNBUFFERED_DC( dc, m_canvas ); switch( item->Type() ) { case SCH_LINE_T: break; case SCH_JUNCTION_T: case SCH_NO_CONNECT_T: case SCH_BUS_BUS_ENTRY_T: case SCH_BUS_WIRE_ENTRY_T: case SCH_LABEL_T: case SCH_GLOBAL_LABEL_T: case SCH_HIERARCHICAL_LABEL_T: case SCH_TEXT_T: case SCH_COMPONENT_T: case SCH_SHEET_PIN_T: case SCH_FIELD_T: MoveItem( item, &dc ); break; case SCH_BITMAP_T: MoveImage( (SCH_BITMAP*) item, &dc ); break; case SCH_SHEET_T: StartMoveSheet( (SCH_SHEET*) item, &dc ); break; case SCH_MARKER_T: default: wxFAIL_MSG( wxString::Format( wxT( "Cannot move item type %s" ), GetChars( item->GetClass() ) ) ); break; } if( GetToolId() == ID_NO_TOOL_SELECTED ) SetRepeatItem( NULL ); }
void SCH_EDIT_FRAME::OnSelectTool( wxCommandEvent& aEvent ) { int id = aEvent.GetId(); // Stop the current command and deselect the current tool. m_canvas->EndMouseCapture( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor() ); switch( id ) { case ID_NO_TOOL_SELECTED: SetToolID( id, m_canvas->GetDefaultCursor(), _( "No tool selected" ) ); break; case ID_HIERARCHY_PUSH_POP_BUTT: SetToolID( id, wxCURSOR_HAND, _( "Descend or ascend hierarchy" ) ); break; case ID_NOCONN_BUTT: SetToolID( id, wxCURSOR_PENCIL, _( "Add no connect" ) ); break; case ID_WIRE_BUTT: SetToolID( id, wxCURSOR_PENCIL, _( "Add wire" ) ); break; case ID_BUS_BUTT: SetToolID( id, wxCURSOR_PENCIL, _( "Add bus" ) ); break; case ID_LINE_COMMENT_BUTT: SetToolID( id, wxCURSOR_PENCIL, _( "Add lines" ) ); break; case ID_JUNCTION_BUTT: SetToolID( id, wxCURSOR_PENCIL, _( "Add junction" ) ); break; case ID_LABEL_BUTT: SetToolID( id, wxCURSOR_PENCIL, _( "Add label" ) ); break; case ID_GLABEL_BUTT: SetToolID( id, wxCURSOR_PENCIL, _( "Add global label" ) ); break; case ID_HIERLABEL_BUTT: SetToolID( id, wxCURSOR_PENCIL, _( "Add hierarchical label" ) ); break; case ID_TEXT_COMMENT_BUTT: SetToolID( id, wxCURSOR_PENCIL, _( "Add text" ) ); break; case ID_ADD_IMAGE_BUTT: SetToolID( id, wxCURSOR_PENCIL, _( "Add image" ) ); break; case ID_WIRETOBUS_ENTRY_BUTT: SetToolID( id, wxCURSOR_PENCIL, _( "Add wire to bus entry" ) ); break; case ID_BUSTOBUS_ENTRY_BUTT: SetToolID( id, wxCURSOR_PENCIL, _( "Add bus to bus entry" ) ); break; case ID_SHEET_SYMBOL_BUTT: SetToolID( id, wxCURSOR_PENCIL, _( "Add sheet" ) ); break; case ID_SHEET_PIN_BUTT: SetToolID( id, wxCURSOR_PENCIL, _( "Add sheet pins" ) ); break; case ID_IMPORT_HLABEL_BUTT: SetToolID( id, wxCURSOR_PENCIL, _( "Import sheet pins" ) ); break; case ID_SCH_PLACE_COMPONENT: SetToolID( id, wxCURSOR_PENCIL, _( "Add component" ) ); break; case ID_PLACE_POWER_BUTT: SetToolID( id, wxCURSOR_PENCIL, _( "Add power" ) ); break; case ID_SCHEMATIC_DELETE_ITEM_BUTT: SetToolID( id, wxCURSOR_BULLSEYE, _( "Delete item" ) ); break; default: SetRepeatItem( NULL ); } // Simulate left click event if we got here from a hot key. if( aEvent.GetClientObject() != NULL ) { EDA_HOTKEY_CLIENT_DATA* data = (EDA_HOTKEY_CLIENT_DATA*) aEvent.GetClientObject(); wxPoint pos = data->GetPosition(); INSTALL_UNBUFFERED_DC( dc, m_canvas ); OnLeftClick( &dc, pos ); } }
void SCH_EDIT_FRAME::OnOrient( wxCommandEvent& aEvent ) { SCH_SCREEN* screen = GetScreen(); SCH_ITEM* item = screen->GetCurItem(); INSTALL_UNBUFFERED_DC( dc, m_canvas ); // Allows block rotate operation on hot key. if( screen->m_BlockLocate.GetState() != STATE_NO_BLOCK ) { if( aEvent.GetId() == ID_SCH_MIRROR_X ) { m_canvas->MoveCursorToCrossHair(); screen->m_BlockLocate.SetMessageBlock( this ); screen->m_BlockLocate.SetCommand( BLOCK_MIRROR_X ); HandleBlockEnd( &dc ); } else if( aEvent.GetId() == ID_SCH_MIRROR_Y ) { m_canvas->MoveCursorToCrossHair(); screen->m_BlockLocate.SetMessageBlock( this ); screen->m_BlockLocate.SetCommand( BLOCK_MIRROR_Y ); HandleBlockEnd( &dc ); } else { wxFAIL_MSG( wxT( "Unknown block oriention command ID." ) ); } return; } if( item == NULL ) { // If we didn't get here by a hot key, then something has gone wrong. if( aEvent.GetInt() == 0 ) return; EDA_HOTKEY_CLIENT_DATA* data = (EDA_HOTKEY_CLIENT_DATA*) aEvent.GetClientObject(); wxCHECK_RET( data != NULL, wxT( "Invalid hot key client object." ) ); item = LocateAndShowItem( data->GetPosition(), SCH_COLLECTOR::OrientableItems, aEvent.GetInt() ); // Exit if no item found at the current location or the item is already being edited. if( (item == NULL) || (item->GetFlags() != 0) ) return; } switch( item->Type() ) { case SCH_COMPONENT_T: if( aEvent.GetId() == ID_SCH_MIRROR_X ) OrientComponent( CMP_MIRROR_X ); else if( aEvent.GetId() == ID_SCH_MIRROR_Y ) OrientComponent( CMP_MIRROR_Y ); else if( aEvent.GetId() == ID_SCH_ORIENT_NORMAL ) OrientComponent( CMP_NORMAL ); else wxFAIL_MSG( wxT( "Invalid orient schematic component command ID." ) ); break; case SCH_BITMAP_T: if( aEvent.GetId() == ID_SCH_MIRROR_X ) MirrorImage( (SCH_BITMAP*) item, true ); else if( aEvent.GetId() == ID_SCH_MIRROR_Y ) MirrorImage( (SCH_BITMAP*) item, false ); break; default: wxFAIL_MSG( wxString::Format( wxT( "Schematic object type %s cannot be oriented." ), GetChars( item->GetClass() ) ) ); } if( item->GetFlags() == 0 ) screen->SetCurItem( NULL ); }
void SCH_EDIT_FRAME::OnDragItem( wxCommandEvent& aEvent ) { SCH_SCREEN* screen = GetScreen(); SCH_ITEM* item = screen->GetCurItem(); INSTALL_UNBUFFERED_DC( dc, m_canvas ); if( item == NULL ) { // If we didn't get here by a hot key, then something has gone wrong. if( aEvent.GetInt() == 0 ) return; EDA_HOTKEY_CLIENT_DATA* data = (EDA_HOTKEY_CLIENT_DATA*) aEvent.GetClientObject(); wxCHECK_RET( data != NULL, wxT( "Invalid hot key client object." ) ); item = LocateAndShowItem( data->GetPosition(), SCH_COLLECTOR::DraggableItems, aEvent.GetInt() ); // Exit if no item found at the current location or the item is already being edited. if( (item == NULL) || (item->GetFlags() != 0) ) return; } switch( item->Type() ) { case SCH_BUS_BUS_ENTRY_T: case SCH_BUS_WIRE_ENTRY_T: case SCH_LINE_T: case SCH_JUNCTION_T: if( item->GetLayer() == LAYER_BUS ) break; // Fall thru if item is not on bus layer. case SCH_COMPONENT_T: case SCH_LABEL_T: case SCH_GLOBAL_LABEL_T: case SCH_HIERARCHICAL_LABEL_T: case SCH_SHEET_T: m_canvas->MoveCursorToCrossHair(); // The easiest way to handle a drag component or sheet command // is to simulate a block drag command if( screen->m_BlockLocate.GetState() == STATE_NO_BLOCK ) { if( !HandleBlockBegin( &dc, BLOCK_DRAG, GetCrossHairPosition() ) ) break; // Give a non null size to the search block: screen->m_BlockLocate.Inflate( 1 ); HandleBlockEnd( &dc ); } break; default: wxFAIL_MSG( wxString::Format( wxT( "Cannot drag schematic item type %s." ), GetChars( item->GetClass() ) ) ); } }
void SCH_EDIT_FRAME::OnEditItem( wxCommandEvent& aEvent ) { SCH_SCREEN* screen = GetScreen(); SCH_ITEM* item = screen->GetCurItem(); INSTALL_UNBUFFERED_DC( dc, m_canvas ); if( item == NULL ) { // If we didn't get here by a hot key, then something has gone wrong. if( aEvent.GetInt() == 0 ) return; EDA_HOTKEY_CLIENT_DATA* data = (EDA_HOTKEY_CLIENT_DATA*) aEvent.GetClientObject(); wxCHECK_RET( data != NULL, wxT( "Invalid hot key client object." ) ); // Set the locat filter, according to the edit command const KICAD_T* filterList = SCH_COLLECTOR::EditableItems; const KICAD_T* filterListAux = NULL; switch( aEvent.GetId() ) { case ID_SCH_EDIT_COMPONENT_REFERENCE: filterList = SCH_COLLECTOR::CmpFieldReferenceOnly; filterListAux = SCH_COLLECTOR::ComponentsOnly; break; case ID_SCH_EDIT_COMPONENT_VALUE: filterList = SCH_COLLECTOR::CmpFieldValueOnly; filterListAux = SCH_COLLECTOR::ComponentsOnly; break; case ID_SCH_EDIT_COMPONENT_FOOTPRINT: filterList = SCH_COLLECTOR::CmpFieldFootprintOnly; filterListAux = SCH_COLLECTOR::ComponentsOnly; break; default: break; } item = LocateAndShowItem( data->GetPosition(), filterList, aEvent.GetInt() ); // If no item found, and if an auxiliary filter exists, try to use it if( !item && filterListAux ) item = LocateAndShowItem( data->GetPosition(), filterListAux, aEvent.GetInt() ); // Exit if no item found at the current location or the item is already being edited. if( (item == NULL) || (item->GetFlags() != 0) ) return; } switch( item->Type() ) { case SCH_COMPONENT_T: { switch( aEvent.GetId() ) { case ID_SCH_EDIT_COMPONENT_REFERENCE: EditComponentFieldText( ( (SCH_COMPONENT*) item )->GetField( REFERENCE ) ); break; case ID_SCH_EDIT_COMPONENT_VALUE: EditComponentFieldText( ( (SCH_COMPONENT*) item )->GetField( VALUE ) ); break; case ID_SCH_EDIT_COMPONENT_FOOTPRINT: EditComponentFieldText( ( (SCH_COMPONENT*) item )->GetField( FOOTPRINT ) ); break; case ID_SCH_EDIT_ITEM: EditComponent( (SCH_COMPONENT*) item ); break; default: wxFAIL_MSG( wxString::Format( wxT( "Invalid schematic component edit command ID %d" ), aEvent.GetId() ) ); } break; } case SCH_SHEET_T: EditSheet( (SCH_SHEET*) item, &dc ); break; case SCH_SHEET_PIN_T: EditSheetPin( (SCH_SHEET_PIN*) item, &dc ); break; case SCH_TEXT_T: case SCH_LABEL_T: case SCH_GLOBAL_LABEL_T: case SCH_HIERARCHICAL_LABEL_T: EditSchematicText( (SCH_TEXT*) item ); break; case SCH_FIELD_T: EditComponentFieldText( (SCH_FIELD*) item ); break; case SCH_BITMAP_T: EditImage( (SCH_BITMAP*) item ); break; default: wxFAIL_MSG( wxString::Format( wxT( "Cannot edit schematic item type %s." ), GetChars( item->GetClass() ) ) ); } if( item->GetFlags() == 0 ) screen->SetCurItem( NULL ); }
void SCH_EDIT_FRAME::OnRotate( wxCommandEvent& aEvent ) { SCH_SCREEN* screen = GetScreen(); SCH_ITEM* item = screen->GetCurItem(); INSTALL_UNBUFFERED_DC( dc, m_canvas ); // Allows block rotate operation on hot key. if( screen->m_BlockLocate.GetState() != STATE_NO_BLOCK ) { screen->m_BlockLocate.SetCommand( BLOCK_ROTATE ); HandleBlockEnd( &dc ); return; } if( item == NULL ) { // If we didn't get here by a hot key, then something has gone wrong. if( aEvent.GetInt() == 0 ) return; EDA_HOTKEY_CLIENT_DATA* data = (EDA_HOTKEY_CLIENT_DATA*) aEvent.GetClientObject(); wxCHECK_RET( data != NULL, wxT( "Invalid hot key client object." ) ); item = LocateAndShowItem( data->GetPosition(), SCH_COLLECTOR::RotatableItems, aEvent.GetInt() ); // Exit if no item found at the current location or the item is already being edited. if( (item == NULL) || (item->GetFlags() != 0) ) return; } switch( item->Type() ) { case SCH_COMPONENT_T: if( aEvent.GetId() == ID_SCH_ROTATE_CLOCKWISE ) OrientComponent( CMP_ROTATE_CLOCKWISE ); else if( aEvent.GetId() == ID_SCH_ROTATE_COUNTERCLOCKWISE ) OrientComponent( CMP_ROTATE_COUNTERCLOCKWISE ); else wxFAIL_MSG( wxT( "Unknown rotate item command ID." ) ); break; case SCH_TEXT_T: case SCH_LABEL_T: case SCH_GLOBAL_LABEL_T: case SCH_HIERARCHICAL_LABEL_T: m_canvas->MoveCursorToCrossHair(); ChangeTextOrient( (SCH_TEXT*) item, &dc ); break; case SCH_FIELD_T: m_canvas->MoveCursorToCrossHair(); RotateField( (SCH_FIELD*) item, &dc ); break; case SCH_BITMAP_T: RotateImage( (SCH_BITMAP*) item ); break; case SCH_SHEET_T: /// @todo allow sheet rotate on hotkey default: wxFAIL_MSG( wxString::Format( wxT( "Cannot rotate schematic item type %s." ), GetChars( item->GetClass() ) ) ); } if( item->GetFlags() == 0 ) screen->SetCurItem( NULL ); }