// Redraw the moved node according to the mouse cursor position static void Show_MoveNode( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition, bool aErase ) { auto displ_opts = (PCB_DISPLAY_OPTIONS*) aPanel->GetDisplayOptions(); wxPoint moveVector; int tmp = displ_opts->m_DisplayPcbTrackFill; GR_DRAWMODE draw_mode = GR_XOR | GR_HIGHLIGHT; displ_opts->m_DisplayPcbTrackFill = false; #ifndef USE_WX_OVERLAY aErase = true; #else aErase = false; #endif // set the new track coordinates wxPoint Pos = aPanel->GetParent()->GetCrossHairPosition(); moveVector = Pos - s_LastPos; s_LastPos = Pos; TRACK *track = NULL; for( unsigned ii = 0; ii < g_DragSegmentList.size(); ii++ ) { track = g_DragSegmentList[ii].m_Track; if( aErase ) track->Draw( aPanel, aDC, draw_mode ); if( track->GetFlags() & STARTPOINT ) track->SetStart( track->GetStart() + moveVector ); if( track->GetFlags() & ENDPOINT ) track->SetEnd( track->GetEnd() + moveVector ); if( track->Type() == PCB_VIA_T ) track->SetEnd( track->GetStart() ); track->Draw( aPanel, aDC, draw_mode ); } displ_opts->m_DisplayPcbTrackFill = tmp; // Display track length if( track ) { PCB_BASE_FRAME* frame = (PCB_BASE_FRAME*) aPanel->GetParent(); frame->SetMsgPanel( track ); } }
/* drawing the track segment movement * > s_MovingSegmentSlope slope = moving track segment slope * > s_StartSegmentSlope slope = slope of the segment connected to the start * point of the moving segment * > s_EndSegmentSlope slope = slope of the segment connected to the end point * of the moving segment * * moved segment function : * yt=s_MovingSegmentSlope * x + s_MovingSegment_Yorg * * segment connected to moved segment's start: * y1 = s_StartSegmentSlope * x + s_StartSegment_Yorg * * segment connected to moved segment's end: * y2=s_EndSegmentSlope * x + s_EndSegment_Yorg * * first intersection point will be located at * y1=yt -> * * xi1=(s_MovingSegment_Yorg-s_StartSegment_Yorg)/(s_StartSegmentSlope-s_MovingSegmentSlope) * yi1=s_MovingSegmentSlope*xi1+s_MovingSegment_Yorg * or yi1=s_StartSegmentSlope*xi1+s_MovingSegment_Yorg * * second intersection point * y2=yt -> * * xi2=(s_MovingSegment_Yorg-s_StartSegment_Yorg)/(s_MovingSegmentSlope-s_MovingSegmentSlope) * yi2=s_MovingSegmentSlope*xi2+s_MovingSegment_Yorg * or yi1=s_EndSegmentSlope*xi2+s_MovingSegment_Yorg * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! * !!!!! special attention to vertical segments because * !!!!! their slope=infinite * !!!!! intersection point will be calculated using the * !!!!! segment intersecting it * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! * * Slope parameters are computed once, because they can become undetermined * when moving segments * (i.e. when a segment length is 0) and we want keep them constant */ static void Show_Drag_Track_Segment_With_Cte_Slope( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition, bool aErase ) { double xi1 = 0, yi1 = 0, xi2 = 0, yi2 = 0; // calculated intersection points double tx1, tx2, ty1, ty2; // temporary storage of points int dx, dy; bool update = true; TRACK* Track; TRACK* tSegmentToStart = NULL, * tSegmentToEnd = NULL; if( g_DragSegmentList.size() == 0 ) return; /* get the segments : * from last to first in list are: * the segment to move * the segment connected to its end point (if exists) * the segment connected to its start point (if exists) */ int ii = g_DragSegmentList.size() - 1; Track = g_DragSegmentList[ii].m_Track; if( Track == NULL ) return; ii--; if( ii >= 0) { if( s_EndSegmentPresent ) { // Get the segment connected to the end point tSegmentToEnd = g_DragSegmentList[ii].m_Track; ii--; } if( s_StartSegmentPresent ) { // Get the segment connected to the start point if( ii >= 0 ) tSegmentToStart = g_DragSegmentList[ii].m_Track; } } GR_DRAWMODE draw_mode = GR_XOR | GR_HIGHLIGHT; // Undraw the current moved track segments before modification #ifndef USE_WX_OVERLAY // if( erase ) { Track->Draw( aPanel, aDC, draw_mode ); if( tSegmentToStart ) tSegmentToStart->Draw( aPanel, aDC, draw_mode ); if( tSegmentToEnd ) tSegmentToEnd->Draw( aPanel, aDC, draw_mode ); } #endif // Compute the new track segment position wxPoint Pos = aPanel->GetParent()->GetCrossHairPosition(); dx = Pos.x - s_LastPos.x; dy = Pos.y - s_LastPos.y; // move the line by dx and dy tx1 = (double) ( Track->GetStart().x + dx ); ty1 = (double) ( Track->GetStart().y + dy ); tx2 = (double) ( Track->GetEnd().x + dx ); ty2 = (double) ( Track->GetEnd().y + dy ); // recalculate the segments new parameters and intersection points // only the intercept will change, segment slopes does not change // because we are moving parallel with is initial state if( !s_MovingSegmentVertical ) { s_MovingSegment_Yorg = ty1 - ( s_MovingSegmentSlope * tx1 ); } if( ( !s_EndPointVertical ) && ( !s_MovingSegmentVertical ) ) { xi2 = ( s_MovingSegment_Yorg - s_EndSegment_Yorg ) / ( s_EndSegmentSlope - s_MovingSegmentSlope ); } else { if( !s_EndPointVertical ) { xi2 = tx2; } else { //P1=P2 if( !s_EndPointHorizontal ) { xi2 = tx2 - dx; } else { update = false; } } } if( !s_MovingSegmentVertical ) { yi2 = s_MovingSegmentSlope * ( xi2 ) + s_MovingSegment_Yorg; } else { if( !s_EndPointVertical ) { yi2 = s_EndSegmentSlope * ( xi2 ) + s_EndSegment_Yorg; } else { if( !s_EndPointHorizontal ) { update = false; } else { yi2 = s_MovingSegmentSlope * ( xi2 ) + s_MovingSegment_Yorg; } } } if( ( !s_StartPointVertical ) && ( !s_MovingSegmentVertical ) ) { xi1 = ( s_MovingSegment_Yorg - s_StartSegment_Yorg ) / ( s_StartSegmentSlope - s_MovingSegmentSlope ); } else { if( !s_StartPointVertical ) { xi1 = tx1; } else { //P1=P2 if( !s_StartPointHorizontal ) { xi1 = tx1 - dx; } else { if( !s_StartPointHorizontal ) { update = false; } } } } if( !s_MovingSegmentVertical ) { yi1 = s_MovingSegmentSlope * ( xi1 ) + s_MovingSegment_Yorg; } else { if( !s_StartPointVertical ) { yi1 = s_StartSegmentSlope * ( xi1 ) + s_StartSegment_Yorg; } else { if( !s_StartPointHorizontal ) { update = false; } else { yi2 = s_MovingSegmentSlope * ( xi1 ) + s_MovingSegment_Yorg; } } } // update the segment coordinates (if possible) if( tSegmentToStart == NULL ) { xi1 = tx1; yi1 = ty1; } if( tSegmentToEnd == NULL ) { xi2 = tx2; yi2 = ty2; } if( update ) { s_LastPos = Pos; Track->SetStart( wxPoint( KiROUND( xi1 ), KiROUND( yi1 ) ) ); Track->SetEnd( wxPoint( KiROUND( xi2 ), KiROUND( yi2 ) ) ); if( tSegmentToEnd ) { if( tSegmentToEnd->GetFlags() & STARTPOINT ) tSegmentToEnd->SetStart( Track->GetEnd() ); else tSegmentToEnd->SetEnd( Track->GetEnd() ); } if( tSegmentToStart ) { if( tSegmentToStart->GetFlags() & STARTPOINT ) tSegmentToStart->SetStart( Track->GetStart() ); else tSegmentToStart->SetEnd( Track->GetStart() ); } } Track->Draw( aPanel, aDC, draw_mode ); if( tSegmentToStart ) tSegmentToStart->Draw( aPanel, aDC, draw_mode ); if( tSegmentToEnd ) tSegmentToEnd->Draw( aPanel, aDC, draw_mode ); // Display track length PCB_BASE_FRAME* frame = (PCB_BASE_FRAME*) aPanel->GetParent(); frame->SetMsgPanel( Track ); }
void DIALOG_PAD_PROPERTIES::PadPropertiesAccept( wxCommandEvent& event ) { if( !padValuesOK() ) return; bool rastnestIsChanged = false; int isign = m_isFlipped ? -1 : 1; transferDataToPad( m_padMaster ); // m_padMaster is a pattern: ensure there is no net for this pad: m_padMaster->SetNetCode( NETINFO_LIST::UNCONNECTED ); if( m_currentPad ) // Set current Pad parameters { wxSize size; MODULE* module = m_currentPad->GetParent(); m_parent->SaveCopyInUndoList( module, UR_CHANGED ); module->SetLastEditTime(); // redraw the area where the pad was, without pad (delete pad on screen) m_currentPad->SetFlags( DO_NOT_DRAW ); m_parent->GetCanvas()->RefreshDrawingRect( m_currentPad->GetBoundingBox() ); m_currentPad->ClearFlags( DO_NOT_DRAW ); // Update values m_currentPad->SetShape( m_padMaster->GetShape() ); m_currentPad->SetAttribute( m_padMaster->GetAttribute() ); if( m_currentPad->GetPosition() != m_padMaster->GetPosition() ) { m_currentPad->SetPosition( m_padMaster->GetPosition() ); rastnestIsChanged = true; } // compute the pos 0 value, i.e. pad position for module with orientation = 0 // i.e. relative to module origin (module position) wxPoint pt = m_currentPad->GetPosition() - module->GetPosition(); RotatePoint( &pt, -module->GetOrientation() ); m_currentPad->SetPos0( pt ); m_currentPad->SetOrientation( m_padMaster->GetOrientation() * isign + module->GetOrientation() ); m_currentPad->SetSize( m_padMaster->GetSize() ); size = m_padMaster->GetDelta(); size.y *= isign; m_currentPad->SetDelta( size ); m_currentPad->SetDrillSize( m_padMaster->GetDrillSize() ); m_currentPad->SetDrillShape( m_padMaster->GetDrillShape() ); wxPoint offset = m_padMaster->GetOffset(); offset.y *= isign; m_currentPad->SetOffset( offset ); m_currentPad->SetPadToDieLength( m_padMaster->GetPadToDieLength() ); if( m_currentPad->GetLayerSet() != m_padMaster->GetLayerSet() ) { rastnestIsChanged = true; m_currentPad->SetLayerSet( m_padMaster->GetLayerSet() ); } if( m_isFlipped ) m_currentPad->SetLayerSet( FlipLayerMask( m_currentPad->GetLayerSet() ) ); m_currentPad->SetPadName( m_padMaster->GetPadName() ); wxString padNetname; // For PAD_HOLE_NOT_PLATED, ensure there is no net name selected if( m_padMaster->GetAttribute() != PAD_HOLE_NOT_PLATED ) padNetname = m_PadNetNameCtrl->GetValue(); if( m_currentPad->GetNetname() != padNetname ) { const NETINFO_ITEM* netinfo = m_board->FindNet( padNetname ); if( !padNetname.IsEmpty() && netinfo == NULL ) { DisplayError( NULL, _( "Unknown netname, netname not changed" ) ); } else { rastnestIsChanged = true; m_currentPad->SetNetCode( netinfo->GetNet() ); } } m_currentPad->SetLocalClearance( m_padMaster->GetLocalClearance() ); m_currentPad->SetLocalSolderMaskMargin( m_padMaster->GetLocalSolderMaskMargin() ); m_currentPad->SetLocalSolderPasteMargin( m_padMaster->GetLocalSolderPasteMargin() ); m_currentPad->SetLocalSolderPasteMarginRatio( m_padMaster->GetLocalSolderPasteMarginRatio() ); m_currentPad->SetZoneConnection( m_padMaster->GetZoneConnection() ); m_currentPad->SetThermalWidth( m_padMaster->GetThermalWidth() ); m_currentPad->SetThermalGap( m_padMaster->GetThermalGap() ); module->CalculateBoundingBox(); m_parent->SetMsgPanel( m_currentPad ); // redraw the area where the pad was m_parent->GetCanvas()->RefreshDrawingRect( m_currentPad->GetBoundingBox() ); m_parent->OnModify(); } EndModal( wxID_OK ); if( rastnestIsChanged ) // The net ratsnest must be recalculated m_board->m_Status_Pcb = 0; }