void DrawAndSizingBlockOutlines( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition, bool aErase ) { BLOCK_SELECTOR* block; block = &aPanel->GetScreen()->m_BlockLocate; block->SetMoveVector( wxPoint( 0, 0 ) ); if( aErase ) block->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode, block->GetColor() ); block->SetLastCursorPosition( aPanel->GetParent()->GetCrossHairPosition() ); block->SetEnd( aPanel->GetParent()->GetCrossHairPosition() ); block->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode, block->GetColor() ); if( block->GetState() == STATE_BLOCK_INIT ) { if( block->GetWidth() || block->GetHeight() ) // 2nd point exists: the rectangle is not surface anywhere block->SetState( STATE_BLOCK_END ); } }
bool EDA_DRAW_FRAME::HandleBlockBegin( wxDC* aDC, int aKey, const wxPoint& aPosition ) { BLOCK_SELECTOR* Block = &GetScreen()->m_BlockLocate; if( ( Block->GetCommand() != BLOCK_IDLE ) || ( Block->GetState() != STATE_NO_BLOCK ) ) return false; Block->SetCommand( (BLOCK_COMMAND_T) BlockCommand( aKey ) ); if( Block->GetCommand() == 0 ) return false; switch( Block->GetCommand() ) { case BLOCK_IDLE: break; case BLOCK_MOVE: // Move case BLOCK_DRAG: // Drag (block defined) case BLOCK_DRAG_ITEM: // Drag from a drag item command case BLOCK_COPY: // Copy case BLOCK_DELETE: // Delete case BLOCK_SAVE: // Save case BLOCK_ROTATE: // Rotate 90 deg case BLOCK_FLIP: // Flip case BLOCK_ZOOM: // Window Zoom case BLOCK_MIRROR_X: case BLOCK_MIRROR_Y: // mirror case BLOCK_PRESELECT_MOVE: // Move with preselection list Block->InitData( m_canvas, aPosition ); break; case BLOCK_PASTE: Block->InitData( m_canvas, aPosition ); Block->SetLastCursorPosition( wxPoint( 0, 0 ) ); InitBlockPasteInfos(); if( Block->GetCount() == 0 ) // No data to paste { DisplayError( this, wxT( "No Block to paste" ), 20 ); GetScreen()->m_BlockLocate.SetCommand( BLOCK_IDLE ); m_canvas->SetMouseCaptureCallback( NULL ); return true; } if( !m_canvas->IsMouseCaptured() ) { Block->ClearItemsList(); DisplayError( this, wxT( "EDA_DRAW_FRAME::HandleBlockBegin() Err: m_mouseCaptureCallback NULL" ) ); return true; } Block->SetState( STATE_BLOCK_MOVE ); m_canvas->CallMouseCapture( aDC, aPosition, false ); break; default: { wxString msg; msg << wxT( "EDA_DRAW_FRAME::HandleBlockBegin() error: Unknown command " ) << Block->GetCommand(); DisplayError( this, msg ); } break; } Block->SetMessageBlock( this ); return true; }
bool LIB_EDIT_FRAME::HandleBlockEnd( wxDC* aDC ) { int ItemCount = 0; bool nextCmd = false; BLOCK_SELECTOR* block = &GetScreen()->m_BlockLocate; wxPoint pt; auto panel =static_cast<SCH_DRAW_PANEL*>(m_canvas); auto view = panel->GetView(); auto area = view->GetSelectionArea(); auto start = area->GetOrigin(); auto end = area->GetEnd(); block->SetOrigin( wxPoint( start.x, start.y ) ); block->SetEnd( wxPoint( end.x, end.y ) ); view->ShowSelectionArea( false ); view->ClearHiddenFlags(); if( block->GetCount() ) { BLOCK_STATE_T state = block->GetState(); BLOCK_COMMAND_T command = block->GetCommand(); m_canvas->CallEndMouseCapture( aDC ); block->SetState( state ); block->SetCommand( command ); m_canvas->SetMouseCapture( DrawAndSizingBlockOutlines, AbortBlockCurrentCommand ); if( block->GetCommand() != BLOCK_ABORT && block->GetCommand() != BLOCK_DUPLICATE && block->GetCommand() != BLOCK_COPY && block->GetCommand() != BLOCK_CUT && block->GetCommand() != BLOCK_DELETE ) { SetCrossHairPosition( block->GetEnd() ); m_canvas->MoveCursorToCrossHair(); } } if( m_canvas->IsMouseCaptured() ) { switch( block->GetCommand() ) { case BLOCK_IDLE: DisplayError( this, wxT( "Error in HandleBlockPLace" ) ); break; case BLOCK_DRAG: // Drag case BLOCK_DRAG_ITEM: case BLOCK_MOVE: // Move case BLOCK_DUPLICATE: // Duplicate if( GetCurPart() ) ItemCount = BlockSelectItems( GetCurPart(), block, m_unit, m_convert, m_syncPinEdit ); if( ItemCount ) { nextCmd = true; block->SetState( STATE_BLOCK_MOVE ); if( block->GetCommand() == BLOCK_DUPLICATE ) { if( block->AppendUndo() ) ; // UR_LIBEDIT saves entire state, so no need to append anything more else { SaveCopyInUndoList( GetCurPart(), UR_LIBEDIT ); block->SetAppendUndo(); } BlockCopySelectedItems( pt, GetCurPart(), block ); block->SetLastCursorPosition( GetCrossHairPosition( true ) ); } m_canvas->SetMouseCaptureCallback( DrawMovingBlockOutlines ); m_canvas->CallMouseCapture( aDC, wxDefaultPosition, false ); } else { m_canvas->CallMouseCapture( aDC, wxDefaultPosition, false ); m_canvas->SetMouseCapture( NULL, NULL ); } break; case BLOCK_COPY: // Save a copy of items in the clipboard buffer case BLOCK_CUT: if( GetCurPart() ) ItemCount = BlockSelectItems( GetCurPart(), block, m_unit, m_convert, m_syncPinEdit ); if( ItemCount ) { copySelectedItems(); auto cmd = block->GetCommand(); if( cmd == BLOCK_COPY ) { BlockClearSelectedItems( GetCurPart(), block ); block->ClearItemsList(); } else if( cmd == BLOCK_CUT ) { if( block->AppendUndo() ) ; // UR_LIBEDIT saves entire state, so no need to append anything more else { SaveCopyInUndoList( GetCurPart(), UR_LIBEDIT ); block->SetAppendUndo(); } BlockDeleteSelectedItems( GetCurPart(), block ); RebuildView(); GetCanvas()->Refresh(); OnModify(); } } break; case BLOCK_DELETE: // Delete if( GetCurPart() ) ItemCount = BlockSelectItems( GetCurPart(), block, m_unit, m_convert, m_syncPinEdit ); if( block->AppendUndo() ) ; // UR_LIBEDIT saves entire state, so no need to append anything more else if( ItemCount ) { SaveCopyInUndoList( GetCurPart(), UR_LIBEDIT ); block->SetAppendUndo(); } if( GetCurPart() ) { BlockDeleteSelectedItems( GetCurPart(), block ); RebuildView(); GetCanvas()->Refresh(); OnModify(); } break; case BLOCK_PASTE: case BLOCK_ROTATE: case BLOCK_MIRROR_X: case BLOCK_MIRROR_Y: case BLOCK_FLIP: wxFAIL; // should not happen break; case BLOCK_ZOOM: // Window Zoom Window_Zoom( *block ); break; case BLOCK_ABORT: break; case BLOCK_SELECT_ITEMS_ONLY: break; case BLOCK_PRESELECT_MOVE: // not used in LibEdit case BLOCK_DUPLICATE_AND_INCREMENT: // not used in Eeschema case BLOCK_MOVE_EXACT: // not used in Eeschema break; } } if( block->GetCommand() == BLOCK_ABORT ) { GetScreen()->ClearDrawingState(); } if( !nextCmd ) { if( block->GetCommand() != BLOCK_SELECT_ITEMS_ONLY && GetCurPart() ) BlockClearSelectedItems( GetCurPart(), block ); GetScreen()->ClearBlockCommand(); GetScreen()->SetCurItem( NULL ); m_canvas->EndMouseCapture( GetToolId(), GetGalCanvas()->GetCurrentCursor(), wxEmptyString, false ); } view->ShowSelectionArea( false ); view->ShowPreview( nextCmd ); return nextCmd; }