static void AbortMoveAndEditTarget( EDA_DRAW_PANEL* Panel, wxDC* DC ) { BASE_SCREEN* screen = Panel->GetScreen(); PCB_TARGET* target = (PCB_TARGET*) screen->GetCurItem(); ( (PCB_EDIT_FRAME*) Panel->GetParent() )->SetCurItem( NULL ); Panel->SetMouseCapture( NULL, NULL ); if( target == NULL ) return; target->Draw( Panel, DC, GR_XOR ); if( target->IsNew() ) // If it is new, delete it { target->Draw( Panel, DC, GR_XOR ); target->DeleteStructure(); target = NULL; } else // it is an existing item: retrieve initial values of parameters { if( ( target->GetFlags() & (IN_EDIT | IS_MOVED) ) ) { target->SetPosition( s_TargetCopy.GetPosition() ); target->SetWidth( s_TargetCopy.GetWidth() ); target->SetSize( s_TargetCopy.GetSize() ); target->SetShape( s_TargetCopy.GetShape() ); } target->ClearFlags(); target->Draw( Panel, DC, GR_OR ); } }
// Redraw the contour of the track while moving the mouse static void ShowTargetShapeWhileMovingMouse( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition, bool aErase ) { BASE_SCREEN* screen = aPanel->GetScreen(); PCB_TARGET* target = (PCB_TARGET*) screen->GetCurItem(); if( target == NULL ) return; if( aErase ) target->Draw( aPanel, aDC, GR_XOR ); target->SetPosition( aPanel->GetParent()->GetCrossHairPosition() ); target->Draw( aPanel, aDC, GR_XOR ); }
PCB_TARGET* PCB_EDIT_FRAME::CreateTarget( wxDC* DC ) { PCB_TARGET* target = new PCB_TARGET( GetBoard() ); target->SetFlags( IS_NEW ); GetBoard()->Add( target ); target->SetLayer( Edge_Cuts ); target->SetWidth( GetDesignSettings().m_EdgeSegmentWidth ); target->SetSize( MireDefaultSize ); target->SetPosition( GetCrossHairPosition() ); PlaceTarget( target, DC ); return target; }
int PCB_EDITOR_CONTROL::PlaceTarget( const TOOL_EVENT& aEvent ) { KIGFX::VIEW* view = getView(); KIGFX::VIEW_CONTROLS* controls = getViewControls(); BOARD* board = getModel<BOARD>(); PCB_TARGET* target = new PCB_TARGET( board ); // Init the new item attributes target->SetLayer( Edge_Cuts ); target->SetWidth( board->GetDesignSettings().m_EdgeSegmentWidth ); target->SetSize( Millimeter2iu( 5 ) ); VECTOR2I cursorPos = controls->GetCursorPosition(); target->SetPosition( wxPoint( cursorPos.x, cursorPos.y ) ); // Add a VIEW_GROUP that serves as a preview for the new item KIGFX::VIEW_GROUP preview( view ); preview.Add( target ); view->Add( &preview ); preview.ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear, true ); controls->SetSnapping( true ); Activate(); m_frame->SetToolID( ID_PCB_MIRE_BUTT, wxCURSOR_PENCIL, _( "Add layer alignment target" ) ); // Main loop: keep receiving events while( OPT_TOOL_EVENT evt = Wait() ) { cursorPos = controls->GetCursorPosition(); if( evt->IsCancel() || evt->IsActivate() ) break; else if( evt->IsAction( &COMMON_ACTIONS::incWidth ) ) { target->SetWidth( target->GetWidth() + WIDTH_STEP ); preview.ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); } else if( evt->IsAction( &COMMON_ACTIONS::decWidth ) ) { int width = target->GetWidth(); if( width > WIDTH_STEP ) { target->SetWidth( width - WIDTH_STEP ); preview.ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); } } else if( evt->IsClick( BUT_LEFT ) ) { assert( target->GetSize() > 0 ); assert( target->GetWidth() > 0 ); view->Add( target ); board->Add( target ); target->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); m_frame->OnModify(); m_frame->SaveCopyInUndoList( target, UR_NEW ); preview.Remove( target ); // Create next PCB_TARGET target = new PCB_TARGET( *target ); preview.Add( target ); } else if( evt->IsMotion() ) { target->SetPosition( wxPoint( cursorPos.x, cursorPos.y ) ); preview.ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); } } delete target; controls->SetSnapping( false ); view->Remove( &preview ); m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString ); return 0; }