Commit bb6795dd authored by jean-pierre charras's avatar jean-pierre charras

Pcbnew: drag functions: serious cleanup and better code. Use now the...

Pcbnew: drag functions: serious cleanup and better code. Use now the connectivity functions to find tracks connected to pads,
and therefore  tracks are now dragged when a end point is inside a pad, not necessary on the pad position.
However, drag functions still need more cleanup.
parent 3668f4cc
...@@ -324,7 +324,7 @@ void Draw3D_ZaxisOblongCylinder( wxPoint aAxis1Pos, wxPoint aAxis2Pos, ...@@ -324,7 +324,7 @@ void Draw3D_ZaxisOblongCylinder( wxPoint aAxis1Pos, wxPoint aAxis2Pos,
// Draw the oblong inner cylinder // Draw the oblong inner cylinder
if( aHeight ) if( aHeight )
Draw3D_VerticalPolygonalCylinder( inner_cornerBuffer, aHeight, Draw3D_VerticalPolygonalCylinder( inner_cornerBuffer, aHeight,
true, aZpos, aBiuTo3DUnits ); aZpos, true, aBiuTo3DUnits );
// Build the horizontal full polygon shape // Build the horizontal full polygon shape
// (outer polygon shape - inner polygon shape) // (outer polygon shape - inner polygon shape)
......
...@@ -155,7 +155,7 @@ void EDA_LIST_DIALOG::SortList() ...@@ -155,7 +155,7 @@ void EDA_LIST_DIALOG::SortList()
{ {
wxArrayString list = m_listBox->GetStrings(); wxArrayString list = m_listBox->GetStrings();
if( list.IsEmpty() <= 0 ) if( list.IsEmpty() )
return; return;
list.Sort( SortItems ); list.Sort( SortItems );
......
...@@ -339,7 +339,16 @@ public: ...@@ -339,7 +339,16 @@ public:
*/ */
void DeletePad( D_PAD* aPad, bool aQuery = true ); void DeletePad( D_PAD* aPad, bool aQuery = true );
void StartMovePad( D_PAD* Pad, wxDC* DC ); /**
* Function StartMovePad
* Initialize a drag or move pad command
* @param aPad = the pad to move or drag
* @param aDC = the current device context
* @param aDragConnectedTracks = true to drag connected tracks,
* false to just move the pad
*/
void StartMovePad( D_PAD* aPad, wxDC* aDC, bool aDragConnectedTracks );
void RotatePad( D_PAD* Pad, wxDC* DC ); void RotatePad( D_PAD* Pad, wxDC* DC );
void PlacePad( D_PAD* Pad, wxDC* DC ); void PlacePad( D_PAD* Pad, wxDC* DC );
void Export_Pad_Settings( D_PAD* aPad ); void Export_Pad_Settings( D_PAD* aPad );
......
...@@ -937,7 +937,16 @@ public: ...@@ -937,7 +937,16 @@ public:
// Footprint edition (see also PCB_BASE_FRAME) // Footprint edition (see also PCB_BASE_FRAME)
void InstallModuleOptionsFrame( MODULE* Module, wxDC* DC ); void InstallModuleOptionsFrame( MODULE* Module, wxDC* DC );
void StartMove_Module( MODULE* module, wxDC* DC );
/**
* Function StartMoveModule
* Initialize a drag or move pad command
* @param aModule = the module to move or drag
* @param aDC = the current device context
* @param aDragConnectedTracks = true to drag connected tracks,
* false to just move the module
*/
void StartMoveModule( MODULE* aModule, wxDC* aDC, bool aDragConnectedTracks );
/** /**
* Function DlgGlobalChange_PadSettings * Function DlgGlobalChange_PadSettings
......
...@@ -184,6 +184,7 @@ set(PCBNEW_CLASS_SRCS ...@@ -184,6 +184,7 @@ set(PCBNEW_CLASS_SRCS
netlist_reader_kicad.cpp netlist_reader_kicad.cpp
onleftclick.cpp onleftclick.cpp
onrightclick.cpp onrightclick.cpp
pad_edition_functions.cpp
pcbnew.cpp pcbnew.cpp
pcbnew_config.cpp pcbnew_config.cpp
pcbplot.cpp pcbplot.cpp
......
...@@ -1807,8 +1807,9 @@ D_PAD* BOARD::GetPad( std::vector<D_PAD*>& aPadList, const wxPoint& aPosition, i ...@@ -1807,8 +1807,9 @@ D_PAD* BOARD::GetPad( std::vector<D_PAD*>& aPadList, const wxPoint& aPosition, i
/** /**
* Function SortPadsByXCoord * Function SortPadsByXCoord
* is used by GetSortedPadListByXCoord to Sort a pad list by x coordinate value. * is used by GetSortedPadListByXCoord to Sort a pad list by x coordinate value.
* This function is used to build ordered pads lists
*/ */
static bool sortPadsByXthenYCoord( D_PAD* const & ref, D_PAD* const & comp ) bool sortPadsByXthenYCoord( D_PAD* const & ref, D_PAD* const & comp )
{ {
if( ref->GetPosition().x == comp->GetPosition().x ) if( ref->GetPosition().x == comp->GetPosition().x )
return ref->GetPosition().y < comp->GetPosition().y; return ref->GetPosition().y < comp->GetPosition().y;
......
...@@ -196,6 +196,12 @@ public: ...@@ -196,6 +196,12 @@ public:
void Flip( const wxPoint& aCentre ); void Flip( const wxPoint& aCentre );
/**
* function IsFlipped
* @return true if the module is flipped, i.e. on the back side of the board
*/
bool IsFlipped() const {return GetLayer() == LAYER_N_BACK; }
bool IsLocked() const bool IsLocked() const
{ {
return (m_ModuleStatus & MODULE_is_LOCKED) != 0; return (m_ModuleStatus & MODULE_is_LOCKED) != 0;
......
...@@ -102,7 +102,7 @@ private: ...@@ -102,7 +102,7 @@ private:
* merge aTrackRef and aCandidate, when possible, * merge aTrackRef and aCandidate, when possible,
* i.e. when they are colinear, same width, and obviously same layer * i.e. when they are colinear, same width, and obviously same layer
*/ */
TRACK* mergeColinearSegmentIfPossible( TRACK* aTrackRef, TRACK* mergeCollinearSegmentIfPossible( TRACK* aTrackRef,
TRACK* aCandidate, int aEndType ); TRACK* aCandidate, int aEndType );
}; };
...@@ -489,7 +489,7 @@ bool TRACKS_CLEANER::clean_segments() ...@@ -489,7 +489,7 @@ bool TRACKS_CLEANER::clean_segments()
} }
} }
// delete intermediate points (merging colinear segments) // merge collinear segments:
for( segment = m_Brd->m_Track; segment; segment = nextsegment ) for( segment = m_Brd->m_Track; segment; segment = nextsegment )
{ {
TRACK* segStart; TRACK* segStart;
...@@ -533,7 +533,7 @@ bool TRACKS_CLEANER::clean_segments() ...@@ -533,7 +533,7 @@ bool TRACKS_CLEANER::clean_segments()
if( flag ) // We have the starting point of the segment is connected to an other segment if( flag ) // We have the starting point of the segment is connected to an other segment
{ {
segDelete = mergeColinearSegmentIfPossible( segment, segStart, FLG_START ); segDelete = mergeCollinearSegmentIfPossible( segment, segStart, FLG_START );
if( segDelete ) if( segDelete )
{ {
...@@ -574,7 +574,7 @@ bool TRACKS_CLEANER::clean_segments() ...@@ -574,7 +574,7 @@ bool TRACKS_CLEANER::clean_segments()
if( flag & 2 ) // We have the ending point of the segment is connected to an other segment if( flag & 2 ) // We have the ending point of the segment is connected to an other segment
{ {
segDelete = mergeColinearSegmentIfPossible( segment, segEnd, FLG_END ); segDelete = mergeCollinearSegmentIfPossible( segment, segEnd, FLG_END );
if( segDelete ) if( segDelete )
{ {
...@@ -593,9 +593,9 @@ bool TRACKS_CLEANER::clean_segments() ...@@ -593,9 +593,9 @@ bool TRACKS_CLEANER::clean_segments()
/** Function used by clean_segments. /** Function used by clean_segments.
* Test alignment of aTrackRef and aCandidate (which must have a common end). * Test if aTrackRef and aCandidate (which must have a common end) are collinear.
* and see if the common point is not on a pad (i.e. if this common point can be removed). * and see if the common point is not on a pad (i.e. if this common point can be removed).
* the ending point of pt_ref is the start point (aEndType == START) * the ending point of aTrackRef is the start point (aEndType == START)
* or the end point (aEndType != START) * or the end point (aEndType != START)
* flags START_ON_PAD and END_ON_PAD must be set before calling this function * flags START_ON_PAD and END_ON_PAD must be set before calling this function
* if the common point can be deleted, this function * if the common point can be deleted, this function
...@@ -604,7 +604,7 @@ bool TRACKS_CLEANER::clean_segments() ...@@ -604,7 +604,7 @@ bool TRACKS_CLEANER::clean_segments()
* and return aCandidate (which can be deleted). * and return aCandidate (which can be deleted).
* else return NULL * else return NULL
*/ */
TRACK* TRACKS_CLEANER::mergeColinearSegmentIfPossible( TRACK* aTrackRef, TRACK* aCandidate, TRACK* TRACKS_CLEANER::mergeCollinearSegmentIfPossible( TRACK* aTrackRef, TRACK* aCandidate,
int aEndType ) int aEndType )
{ {
if( aTrackRef->m_Width != aCandidate->m_Width ) if( aTrackRef->m_Width != aCandidate->m_Width )
......
...@@ -105,7 +105,7 @@ void CONNECTIONS::SearchConnectionsPadsToIntersectingPads() ...@@ -105,7 +105,7 @@ void CONNECTIONS::SearchConnectionsPadsToIntersectingPads()
* D_PAD::m_TracksConnected is cleared before adding items * D_PAD::m_TracksConnected is cleared before adding items
* TRACK::m_PadsConnected is not cleared * TRACK::m_PadsConnected is not cleared
*/ */
void CONNECTIONS::SearchTracksConnectedToPads() void CONNECTIONS::SearchTracksConnectedToPads( bool add_to_padlist, bool add_to_tracklist)
{ {
std::vector<CONNECTED_POINT*> candidates; std::vector<CONNECTED_POINT*> candidates;
...@@ -127,7 +127,10 @@ void CONNECTIONS::SearchTracksConnectedToPads() ...@@ -127,7 +127,10 @@ void CONNECTIONS::SearchTracksConnectedToPads()
if( pad->HitTest( cp_item->GetPoint() ) ) if( pad->HitTest( cp_item->GetPoint() ) )
{ {
if( add_to_padlist )
cp_item->GetTrack()->m_PadsConnected.push_back( pad ); cp_item->GetTrack()->m_PadsConnected.push_back( pad );
if( add_to_tracklist )
pad->m_TracksConnected.push_back( cp_item->GetTrack() ); pad->m_TracksConnected.push_back( cp_item->GetTrack() );
} }
} }
......
...@@ -183,12 +183,16 @@ public: ...@@ -183,12 +183,16 @@ public:
/** /**
* function SearchTracksConnectedToPads * function SearchTracksConnectedToPads
* Explores the list of pads. * Explores the list of pads.
* Adds to m_PadsConnected member of each track the pad(s) connected to * if( add_to_padlist )
* Adds to m_TracksConnected member of each pad the track(s) connected to * adds to m_PadsConnected member of each track the pad(s) connected to
* if add_to_tracklist
* adds to m_TracksConnected member of each pad the track(s) connected to
* D_PAD::m_TracksConnected is cleared before adding items * D_PAD::m_TracksConnected is cleared before adding items
* TRACK::m_PadsConnected is not cleared * TRACK::m_PadsConnected is not cleared
* @param add_to_padlist = true to fill m_PadsConnected member of each track
* @param add_to_tracklist = true to fill m_TracksConnected member of each pad
*/ */
void SearchTracksConnectedToPads(); void SearchTracksConnectedToPads( bool add_to_padlist = true, bool add_to_tracklist = true);
/** /**
* function CollectItemsNearTo * function CollectItemsNearTo
......
...@@ -78,7 +78,7 @@ DIALOG_GENDRILL::DIALOG_GENDRILL( PCB_EDIT_FRAME* parent ) : ...@@ -78,7 +78,7 @@ DIALOG_GENDRILL::DIALOG_GENDRILL( PCB_EDIT_FRAME* parent ) :
int DIALOG_GENDRILL:: m_UnitDrillIsInch = true; int DIALOG_GENDRILL:: m_UnitDrillIsInch = true;
int DIALOG_GENDRILL:: m_ZerosFormat = EXCELLON_WRITER::DECIMAL_FORMAT; int DIALOG_GENDRILL:: m_ZerosFormat = EXCELLON_WRITER::DECIMAL_FORMAT;
bool DIALOG_GENDRILL::m_MinimalHeader = false; bool DIALOG_GENDRILL::m_MinimalHeader = false;
bool DIALOG_GENDRILL::m_Mirror = true; bool DIALOG_GENDRILL::m_Mirror = false;
bool DIALOG_GENDRILL::m_DrillOriginIsAuxAxis = false; bool DIALOG_GENDRILL::m_DrillOriginIsAuxAxis = false;
int DIALOG_GENDRILL:: m_PrecisionFormat = 1; int DIALOG_GENDRILL:: m_PrecisionFormat = 1;
bool DIALOG_GENDRILL::m_createRpt = false; bool DIALOG_GENDRILL::m_createRpt = false;
......
/** /**
* @file drag.h * @file drag.h
* @brief Useful class and functions used to drag tracks * @brief Useful classes and functions used to collect tracks to drag
*/ */
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2004-2012 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 1992-2012 KiCad Developers, see change_log.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <vector> #include <vector>
#include <wx/gdicmn.h> #include <wx/gdicmn.h>
...@@ -13,62 +36,151 @@ class wxDC; ...@@ -13,62 +36,151 @@ class wxDC;
class EDA_DRAW_PANEL; class EDA_DRAW_PANEL;
class MODULE; class MODULE;
class D_PAD; class D_PAD;
class CONNECTIONS;
/** Helper class to handle a list of track segments to drag /** Helper classes to handle a list of track segments to drag
* and has info to undo/abort the move command * and has info to undo/abort the move command
* a DRAG_SEGM manage one track segment or a via
*/ */
class DRAG_SEGM
/*
* a DRAG_LIST manages the list of track segments to modify
* when the pad or the module is moving
*/
/*
* a DRAG_SEGM_PICKER manage one track segment or a via
*/
class DRAG_SEGM_PICKER
{ {
public: public:
TRACK* m_Segm; /* pointer to the segment a "dragger */ TRACK* m_Track; // pointer to the parent track segment
D_PAD* m_Pad_Start; /* pointer to the pad origin if origin segment of pad */ D_PAD* m_Pad_Start; // pointer to the moving pad
D_PAD* m_Pad_End; /* pointer to the pad end if end segment of pad */ // if the start point should follow this pad
int m_Flag; /* indicator flags */ // or NULL
D_PAD* m_Pad_End; // pointer to the moving pad
// if the end point should follow this pad
// or NULL
bool m_Flag; // flag used in drag vias and drag track segment functions
private: private:
wxPoint m_StartInitialValue; double m_RotationOffset; // initial orientation of the parent module
wxPoint m_EndInitialValue; // For abort: initial m_Start and m_End values for m_Segm // Used to recalculate m_PadStartOffset and m_PadEndOffset
// after a module rotation when dragging
bool m_Flipped; // initial side of the parent module
// Used to recalculate m_PadStartOffset and m_PadEndOffset
// if the module is flipped when dragging
wxPoint m_PadStartOffset; // offset between the pad and the starting point of the track
// usually 0,0, but not always
wxPoint m_PadEndOffset; // offset between the pad and the ending point of the track
// usually 0,0, but not always
wxPoint m_startInitialValue;
wxPoint m_endInitialValue; // For abort command:
// initial m_Start and m_End values for m_Track
public:
DRAG_SEGM_PICKER( TRACK* aTrack );
~DRAG_SEGM_PICKER() {};
/**
* Set auxiliary parameters relative to calucaltions needed
* to find track ends positions while dragging pads
* and when modules are rotated, flipped ..
*/
void SetAuxParameters();
/**
* Calculate track ends position while dragging pads
* and when modules are rotated, flipped ..
* @param aOffset = offset of module or pad position (when moving)
*/
void SetTrackEndsCoordinates(wxPoint aOffset);
void RestoreInitialValues()
{
m_Track->SetStart( m_startInitialValue );
m_Track->SetEnd( m_endInitialValue );
}
};
class DRAG_LIST
{
public: public:
BOARD * m_Brd; // the main board
MODULE * m_Module; // The link to the module to move, or NULL
D_PAD * m_Pad; // The link to the pad to move, or NULL
DRAG_SEGM( TRACK* segm ); std::vector<DRAG_SEGM_PICKER> m_DragList; // The list of DRAG_SEGM_PICKER items
~DRAG_SEGM() {};
void SetInitialValues() public:
DRAG_LIST( BOARD * aPcb )
{ {
m_Segm->m_Start = m_StartInitialValue; m_Brd = aPcb;
m_Segm->m_End = m_EndInitialValue;
} }
/**
* Function ClearList
* clear the .m_Flags of all track segments in m_DragList
* and clear the list.
*/
void ClearList();
/** Build the list of track segments connected to pads of aModule
* in m_DragList
* For each selected track segment the EDIT flag is set
*/
void BuildDragListe( MODULE* aModule );
/** Build the list of track segments connected to aPad
* in m_DragList
* For each selected track segment the EDIT flag is set
*/
void BuildDragListe( D_PAD* aPad );
private:
/** Fills m_DragList with of track segments connected to pads in aConnections
* For each selected track segment the EDIT flag is set
*/
void fillList(CONNECTIONS& aConnections);
}; };
/* Variables */
// a list of DRAG_SEGM items used to move or drag tracks. // Global variables:
// Each DRAG_SEGM item points a segment to move.
extern std::vector<DRAG_SEGM> g_DragSegmentList;
/* Functions */ // a list of DRAG_SEGM_PICKER items used to move or drag tracks.
void DrawSegmentWhileMovingFootprint( EDA_DRAW_PANEL* panel, wxDC* DC ); // Each DRAG_SEGM_PICKER item points a segment to move.
void Build_Drag_Liste( EDA_DRAW_PANEL* panel, wxDC* DC, MODULE* Module ); extern std::vector<DRAG_SEGM_PICKER> g_DragSegmentList;
void Build_1_Pad_SegmentsToDrag( EDA_DRAW_PANEL* panel, wxDC* DC, D_PAD* PtPad );
void Collect_TrackSegmentsToDrag( EDA_DRAW_PANEL* panel, wxDC* DC,
wxPoint& point, int LayerMask, int net_code );
// Functions:
void DrawSegmentWhileMovingFootprint( EDA_DRAW_PANEL* panel, wxDC* DC );
/** /**
* Function EraseDragList * Function EraseDragList
* clear the .m_Flags of all track segments managed by in g_DragSegmentList * clear the .m_Flags of all track segments stored in g_DragSegmentList
* and clear the list. * and clear the list.
* In order to avoid useless memory allocation, the memory is not freed * In order to avoid useless memory reallocation, the memory is not freed
* and will be reused when creating a new list * and will be reused when creating a new list
*/ */
void EraseDragList(); void EraseDragList();
/* Add the segment"Track" to the drag list, and erase it from screen /*
* function used to collect track segments in drag track segment
*/
void Collect_TrackSegmentsToDrag( BOARD* aPcb, wxPoint& point, int LayerMask, int net_code );
/* Add aTrack to the drag list
* flag = STARTPOINT (if the point to drag is the start point of Track) * flag = STARTPOINT (if the point to drag is the start point of Track)
* or ENDPOINT * or ENDPOINT (if the point to drag is the end point of Track)
*/ */
void AddSegmentToDragList( EDA_DRAW_PANEL* panel, wxDC* DC, int flag, TRACK* Track ); void AddSegmentToDragList( int flag, TRACK* aTrack );
/*
* Undraw the track segments in list, and set the EDIT flag
* Usually called after the track list is built, to prepare
* the redraw of the list when the mouse is moved
*/
void UndrawAndMarkSegmentsToDrag( EDA_DRAW_PANEL* aCanvas, wxDC* aDC );
/*********************************/ /**
/* functions used to drag tracks */ * @file dragsegm.cpp
/*********************************/ * @brief Classes to find track segments connected to a pad or a module
* for drag commands
*/
/* Fichier dragsegm.cpp */ /*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2004-2012 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 1992-2012 KiCad Developers, see change_log.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <fctsys.h> #include <fctsys.h>
#include <common.h> #include <common.h>
#include <trigo.h>
#include <gr_basic.h> #include <gr_basic.h>
#include <class_drawpanel.h> #include <class_drawpanel.h>
#include <wxBasePcbFrame.h> #include <wxBasePcbFrame.h>
...@@ -15,123 +40,291 @@ ...@@ -15,123 +40,291 @@
#include <class_module.h> #include <class_module.h>
#include <class_board.h> #include <class_board.h>
#include <connect.h>
/* a list of DRAG_SEGM items used to move or drag tracks */ /* a list of DRAG_SEGM_PICKER items used to move or drag tracks */
std::vector<DRAG_SEGM> g_DragSegmentList; std::vector<DRAG_SEGM_PICKER> g_DragSegmentList;
/* helper class to handle a list of track segments to drag or move /* helper class to handle a list of track segments to drag or move
*/ */
DRAG_SEGM::DRAG_SEGM( TRACK* segm ) DRAG_SEGM_PICKER::DRAG_SEGM_PICKER( TRACK* aTrack )
{ {
m_Segm = segm; m_Track = aTrack;
m_StartInitialValue = m_Segm->m_Start; m_startInitialValue = m_Track->m_Start;
m_EndInitialValue = m_Segm->m_End; m_endInitialValue = m_Track->m_End;
m_Pad_Start = m_Pad_End = NULL; m_Pad_Start = m_Track->GetState( START_ON_PAD ) ? (D_PAD*)m_Track->start : NULL;
m_Pad_End = m_Track->GetState( END_ON_PAD ) ? (D_PAD*)m_Track->end : NULL;
m_Flag = 0; m_Flag = 0;
m_RotationOffset = 0.0;
m_Flipped = false;
} }
/* Redraw the list of segments starting in g_DragSegmentList, while moving a footprint */ /* Set auxiliary parameters relative to calucaltions needed
void DrawSegmentWhileMovingFootprint( EDA_DRAW_PANEL* panel, wxDC* DC ) * to find track ends positions while dragging pads
* and when modules are rotated, flipped ..
*/
void DRAG_SEGM_PICKER::SetAuxParameters()
{ {
if( g_DragSegmentList.size() == 0 ) MODULE * module = NULL;
return; if( m_Pad_Start )
for( unsigned ii = 0; ii < g_DragSegmentList.size(); ii++ )
{ {
wxPoint pos; module = (MODULE *) m_Pad_Start->GetParent();
m_PadStartOffset = m_Track->GetStart() - m_Pad_Start->GetPosition();
TRACK* track = g_DragSegmentList[ii].m_Segm; }
#ifndef USE_WX_OVERLAY
track->Draw( panel, DC, GR_XOR ); // erase from screen at old position
#endif
D_PAD* pad = g_DragSegmentList[ii].m_Pad_Start; if( m_Pad_End )
{
if( module == NULL )
module = (MODULE *) m_Pad_End->GetParent();
m_PadEndOffset = m_Track->GetEnd() - m_Pad_End->GetPosition();
}
if( pad ) if( module )
{ {
pos = pad->GetPosition() - g_Offset_Module; m_Flipped = module->IsFlipped();
track->m_Start = pos; m_RotationOffset = module->GetOrientation();
} }
}
pad = g_DragSegmentList[ii].m_Pad_End; /*
* Calculate track ends positions while dragging pads
* and when modules are rotated, flipped ..
* aOffset = module or pad position offset when moving the module or pad
* (the actual position is the module/pad position - offset)
*/
void DRAG_SEGM_PICKER::SetTrackEndsCoordinates(wxPoint aOffset)
{
// the track start position is the pad position + m_PadStartOffset
// however m_PadStartOffset is known for the initial rotation/flip
// this is also true for track end position and m_PadEndOffset
// Therefore, because rotation/flipping is allowed during a drag
// and move module, we should recalculate the pad offset,
// depending on the current orientation/flip state of the module
// relative to its initial orientation.
// (although most of time, offset is 0,0)
double curr_rot_offset = m_RotationOffset;
MODULE * module = NULL;
bool flip = false;
if( m_Pad_Start )
module = (MODULE *) m_Pad_Start->GetParent();
if( module == NULL && m_Pad_End )
module = (MODULE *) m_Pad_End->GetParent();
if( module )
{
flip = m_Flipped != module->IsFlipped();
curr_rot_offset = module->GetOrientation() - m_RotationOffset;
if( flip ) // when flipping, module orientation is negated
curr_rot_offset = - module->GetOrientation() - m_RotationOffset;
}
if( pad ) if( m_Pad_Start )
{ {
pos = pad->GetPosition() - g_Offset_Module; wxPoint padoffset = m_PadStartOffset;
track->m_End = pos;
if( curr_rot_offset != 0.0 )
RotatePoint(&padoffset, curr_rot_offset);
if( flip )
NEGATE( padoffset.y );
m_Track->m_Start = m_Pad_Start->GetPosition() - aOffset + padoffset;
} }
track->Draw( panel, DC, GR_XOR ); if( m_Pad_End )
{
wxPoint padoffset = m_PadEndOffset;
if( curr_rot_offset != 0.0 )
RotatePoint(&padoffset, curr_rot_offset);
if( flip )
NEGATE( padoffset.y );
m_Track->m_End = m_Pad_End->GetPosition() - aOffset + padoffset;
} }
} }
/** Build the list of track segments connected to pads of a given module // A sort function needed to build ordered pads lists
* by populate the std::vector<DRAG_SEGM> g_DragSegmentList extern bool sortPadsByXthenYCoord( D_PAD* const & ref, D_PAD* const & comp );
* For each selected track segment set the EDIT flag
* and redraw them in EDIT mode (sketch mode) void DRAG_LIST::BuildDragListe( MODULE* aModule )
*/
void Build_Drag_Liste( EDA_DRAW_PANEL* panel, wxDC* DC, MODULE* aModule )
{ {
m_Pad = NULL;
m_Module = aModule;
// Build connections info
CONNECTIONS connections( m_Brd );
std::vector<D_PAD*>&padList = connections.GetPadsList();
for( D_PAD* pad = aModule->m_Pads; pad; pad = pad->Next() ) for( D_PAD* pad = aModule->m_Pads; pad; pad = pad->Next() )
{ padList.push_back( pad );
Build_1_Pad_SegmentsToDrag( panel, DC, pad );
}
return; sort( padList.begin(), padList.end(), sortPadsByXthenYCoord );
fillList( connections );
} }
void DRAG_LIST::BuildDragListe( D_PAD* aPad )
{
m_Pad = aPad;
m_Module = NULL;
// Build connections info
CONNECTIONS connections( m_Brd );
std::vector<D_PAD*>&padList = connections.GetPadsList();
padList.push_back( aPad );
/** Build the list of track segments connected to a given pad fillList( connections );
* by populate the std::vector<DRAG_SEGM> g_DragSegmentList }
* For each selected track segment set the EDIT flag
* and redraw them in EDIT mode (sketch mode) // A helper function to sort track list per tracks
* Net codes must be OK. bool sort_tracklist( const DRAG_SEGM_PICKER& ref, const DRAG_SEGM_PICKER& tst )
{
return ref.m_Track < tst.m_Track;
}
/** Fills m_DragList with track segments connected to pads in aConnections
* For each selected track segment the EDIT flag is set
*/ */
void Build_1_Pad_SegmentsToDrag( EDA_DRAW_PANEL* panel, wxDC* DC, D_PAD* aPad ) void DRAG_LIST::fillList(CONNECTIONS& aConnections)
{ {
BOARD* pcb = ( (PCB_BASE_FRAME*)( panel->GetParent() ) )->GetBoard(); aConnections.BuildTracksCandidatesList( m_Brd->m_Track, NULL);
int net_code = aPad->GetNet(); // Build connections info tracks to pads
// Rebuild pads to track info only)
aConnections.SearchTracksConnectedToPads( false, true );
TRACK* track = pcb->m_Track->GetStartNetCode( net_code ); std::vector<D_PAD*>padList = aConnections.GetPadsList();
wxPoint pos = aPad->GetPosition(); // clear flags and variables of selected tracks
for( unsigned ii = 0; ii < padList.size(); ii++ )
{
D_PAD * pad = padList[ii];
int layerMask = aPad->GetLayerMask(); // store track connected to the pad
for( unsigned jj = 0; jj < pad->m_TracksConnected.size(); jj++ )
{
TRACK * track = pad->m_TracksConnected[jj];
track->start = NULL;
track->end = NULL;
track->SetState( START_ON_PAD|END_ON_PAD|BUSY, OFF );
}
}
for( ; track; track = track->Next() ) // store tracks connected to pads
for( unsigned ii = 0; ii < padList.size(); ii++ )
{ {
if( track->GetNet() != net_code ) D_PAD * pad = padList[ii];
break;
if( ( layerMask & track->ReturnMaskLayer() ) == 0 ) // store track connected to the pad
continue; for( unsigned jj = 0; jj < pad->m_TracksConnected.size(); jj++ )
{
TRACK * track = pad->m_TracksConnected[jj];
if( pad->HitTest( track->GetStart() ) )
{
track->start = pad;
track->SetState( START_ON_PAD, ON );
}
if( pos == track->m_Start ) if( pad->HitTest( track->GetEnd() ) )
{ {
AddSegmentToDragList( panel, DC, STARTPOINT, track ); track->end = pad;
g_DragSegmentList.back().m_Pad_Start = aPad; track->SetState( END_ON_PAD, ON );
}
DRAG_SEGM_PICKER wrapper( track );
m_DragList.push_back( wrapper );
} }
}
// remove duplicate in m_DragList:
// a track can be stored more than once if connected to 2 overlapping pads, or
// each track end connected to 2 moving pads
// to avoid artifact in draw function, items should be not duplicated
// However, there is not a lot of items to be removed, so there ir no optimization.
if( pos == track->m_End ) // sort the drag list by track pointers
sort( m_DragList.begin(), m_DragList.end(), sort_tracklist );
// Explore the list, merge duplicates
for( int ii = 0; ii < (int)m_DragList.size()-1; ii++ )
{ {
AddSegmentToDragList( panel, DC, ENDPOINT, track ); int jj = ii+1;
g_DragSegmentList.back().m_Pad_End = aPad; if( m_DragList[ii].m_Track != m_DragList[jj].m_Track )
continue;
// duplicate found: merge info and remove duplicate
if( m_DragList[ii].m_Pad_Start == NULL )
m_DragList[ii].m_Pad_Start = m_DragList[jj].m_Pad_Start;
if( m_DragList[ii].m_Pad_End == NULL )
m_DragList[ii].m_Pad_End = m_DragList[jj].m_Pad_End;
m_DragList.erase(m_DragList.begin() + jj );
ii--;
} }
// Initialize pad offsets and other params
for( unsigned ii = 0; ii < m_DragList.size(); ii++ )
m_DragList[ii].SetAuxParameters();
// Copy the list in global list
g_DragSegmentList = m_DragList;
}
void DRAG_LIST::ClearList()
{
for( unsigned ii = 0; ii < m_DragList.size(); ii++ )
m_DragList[ii].m_Track->ClearFlags();
m_DragList.clear();
m_Module = NULL;
m_Pad = NULL;
}
// Redraw the list of segments stored in g_DragSegmentList, while moving a footprint
void DrawSegmentWhileMovingFootprint( EDA_DRAW_PANEL* panel, wxDC* DC )
{
for( unsigned ii = 0; ii < g_DragSegmentList.size(); ii++ )
{
TRACK* track = g_DragSegmentList[ii].m_Track;
#ifndef USE_WX_OVERLAY
track->Draw( panel, DC, GR_XOR ); // erase from screen at old position
#endif
g_DragSegmentList[ii].SetTrackEndsCoordinates( g_Offset_Module );
track->Draw( panel, DC, GR_XOR );
} }
} }
/* Add the segment"Track" to the drag list, and erase it from screen /**
* Function EraseDragList
* clear the .m_Flags of all track segments found in g_DragSegmentList
* and clear the list.
*/
void EraseDragList()
{
for( unsigned ii = 0; ii < g_DragSegmentList.size(); ii++ )
g_DragSegmentList[ii].m_Track->ClearFlags();
g_DragSegmentList.clear();
}
/* Add Track to the drag list, and erase it from screen
* flag = STARTPOINT (if the point to drag is the start point of Track) or ENDPOINT * flag = STARTPOINT (if the point to drag is the start point of Track) or ENDPOINT
*/ */
void AddSegmentToDragList( EDA_DRAW_PANEL* panel, wxDC* DC, int flag, TRACK* Track ) void AddSegmentToDragList( int flag, TRACK* aTrack )
{ {
DRAG_SEGM wrapper( Track ); DRAG_SEGM_PICKER wrapper( aTrack );
if( (flag & STARTPOINT) ) if( (flag & STARTPOINT) )
wrapper.m_Flag |= 1; wrapper.m_Flag |= 1;
...@@ -139,30 +332,23 @@ void AddSegmentToDragList( EDA_DRAW_PANEL* panel, wxDC* DC, int flag, TRACK* Tra ...@@ -139,30 +332,23 @@ void AddSegmentToDragList( EDA_DRAW_PANEL* panel, wxDC* DC, int flag, TRACK* Tra
if( (flag & ENDPOINT) ) if( (flag & ENDPOINT) )
wrapper.m_Flag |= 2; wrapper.m_Flag |= 2;
Track->Draw( panel, DC, GR_XOR );
Track->SetState( IN_EDIT, ON );
if( (flag & STARTPOINT) ) if( (flag & STARTPOINT) )
Track->SetFlags( STARTPOINT ); aTrack->SetFlags( STARTPOINT );
if( (flag & ENDPOINT) ) if( (flag & ENDPOINT) )
Track->SetFlags( ENDPOINT ); aTrack->SetFlags( ENDPOINT );
Track->Draw( panel, DC, GR_XOR );
g_DragSegmentList.push_back( wrapper ); g_DragSegmentList.push_back( wrapper );
} }
/* Build the list of tracks connected to the ref point /* Build the list of tracks connected to the ref point
* Net codes must be up to date, because only tracks having the right net code are tested. * Net codes must be up to date, because only tracks having the right net code are tested.
* @param aRefPos = reference point of connection * aRefPos = reference point of connection
*/ */
void Collect_TrackSegmentsToDrag( EDA_DRAW_PANEL* panel, wxDC* DC, void Collect_TrackSegmentsToDrag( BOARD* aPcb, wxPoint& aRefPos, int LayerMask, int net_code )
wxPoint& aRefPos, int LayerMask, int net_code )
{ {
BOARD* pcb = ( (PCB_BASE_FRAME*)( panel->GetParent() ) )->GetBoard(); TRACK* track = aPcb->m_Track->GetStartNetCode( net_code );
TRACK* track = pcb->m_Track->GetStartNetCode( net_code );
for( ; track; track = track->Next() ) for( ; track; track = track->Next() )
{ {
...@@ -187,28 +373,38 @@ void Collect_TrackSegmentsToDrag( EDA_DRAW_PANEL* panel, wxDC* DC, ...@@ -187,28 +373,38 @@ void Collect_TrackSegmentsToDrag( EDA_DRAW_PANEL* panel, wxDC* DC,
// and must not be entered twice. // and must not be entered twice.
if( flag ) if( flag )
{ {
AddSegmentToDragList( panel, DC, flag, track ); AddSegmentToDragList( flag, track );
// If a connected via is found at location aRefPos, // If a connected via is found at location aRefPos,
// collect also tracks connected by this via. // collect also tracks connected by this via.
if( track->Type() == PCB_VIA_T ) if( track->Type() == PCB_VIA_T )
Collect_TrackSegmentsToDrag( panel, DC, aRefPos, track->ReturnMaskLayer(), Collect_TrackSegmentsToDrag( aPcb, aRefPos, track->ReturnMaskLayer(),
net_code ); net_code );
} }
} }
} }
/*
/** * Undraw the track segments in list, and set the IN_EDIT flag
* Function EraseDragList * Usually called after the track list is built, to prepare
* clear the .m_Flags of all track segments found in g_DragSegmentList * the redraw of the list when the mouse is moved
* and clear the list.
* the memory is not freed and will be reused when creating a new list
*/ */
void EraseDragList() void UndrawAndMarkSegmentsToDrag( EDA_DRAW_PANEL* aCanvas, wxDC* aDC )
{ {
for( unsigned ii = 0; ii < g_DragSegmentList.size(); ii++ ) for( unsigned ii = 0; ii < g_DragSegmentList.size(); ii++ )
g_DragSegmentList[ii].m_Segm->ClearFlags(); {
TRACK* track = g_DragSegmentList[ii].m_Track;
g_DragSegmentList.clear(); track->Draw( aCanvas, aDC, GR_XOR );
track->SetState( IN_EDIT, ON );
if( (g_DragSegmentList[ii].m_Flag & STARTPOINT) )
track->SetFlags( STARTPOINT );
if( (g_DragSegmentList[ii].m_Flag & ENDPOINT) )
track->SetFlags( ENDPOINT );
track->Draw( aCanvas, aDC, GR_XOR );
}
} }
...@@ -614,8 +614,6 @@ void PCB_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) ...@@ -614,8 +614,6 @@ void PCB_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
break; break;
case ID_POPUP_PCB_DRAG_MODULE_REQUEST: case ID_POPUP_PCB_DRAG_MODULE_REQUEST:
g_Drag_Pistes_On = true;
case ID_POPUP_PCB_MOVE_MODULE_REQUEST: case ID_POPUP_PCB_MOVE_MODULE_REQUEST:
if( GetCurItem() == NULL ) if( GetCurItem() == NULL )
break; break;
...@@ -625,10 +623,7 @@ void PCB_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) ...@@ -625,10 +623,7 @@ void PCB_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
SetCurItem( GetCurItem()->GetParent() ); SetCurItem( GetCurItem()->GetParent() );
if( !GetCurItem() || GetCurItem()->Type() != PCB_MODULE_T ) if( !GetCurItem() || GetCurItem()->Type() != PCB_MODULE_T )
{
g_Drag_Pistes_On = false;
break; break;
}
module = (MODULE*) GetCurItem(); module = (MODULE*) GetCurItem();
...@@ -644,7 +639,7 @@ void PCB_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) ...@@ -644,7 +639,7 @@ void PCB_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
SendMessageToEESCHEMA( module ); SendMessageToEESCHEMA( module );
GetScreen()->SetCrossHairPosition( module->m_Pos ); GetScreen()->SetCrossHairPosition( module->m_Pos );
m_canvas->MoveCursorToCrossHair(); m_canvas->MoveCursorToCrossHair();
StartMove_Module( module, &dc ); StartMoveModule( module, &dc, id == ID_POPUP_PCB_DRAG_MODULE_REQUEST );
break; break;
case ID_POPUP_PCB_GET_AND_MOVE_MODULE_REQUEST: /* get module by name and move it */ case ID_POPUP_PCB_GET_AND_MOVE_MODULE_REQUEST: /* get module by name and move it */
...@@ -665,7 +660,7 @@ void PCB_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) ...@@ -665,7 +660,7 @@ void PCB_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
SendMessageToEESCHEMA( module ); SendMessageToEESCHEMA( module );
m_canvas->MoveCursorToCrossHair(); m_canvas->MoveCursorToCrossHair();
StartMove_Module( module, &dc ); StartMoveModule( module, &dc, false );
break; break;
case ID_POPUP_PCB_DELETE_MODULE: case ID_POPUP_PCB_DELETE_MODULE:
...@@ -809,9 +804,8 @@ void PCB_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) ...@@ -809,9 +804,8 @@ void PCB_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
break; break;
} }
g_Drag_Pistes_On = true;
m_canvas->MoveCursorToCrossHair(); m_canvas->MoveCursorToCrossHair();
StartMovePad( (D_PAD*) GetCurItem(), &dc ); StartMovePad( (D_PAD*) GetCurItem(), &dc, true );
break; break;
case ID_POPUP_PCB_MOVE_PAD_REQUEST: case ID_POPUP_PCB_MOVE_PAD_REQUEST:
...@@ -829,9 +823,8 @@ void PCB_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) ...@@ -829,9 +823,8 @@ void PCB_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
break; break;
} }
g_Drag_Pistes_On = false;
m_canvas->MoveCursorToCrossHair(); m_canvas->MoveCursorToCrossHair();
StartMovePad( (D_PAD*) GetCurItem(), &dc ); StartMovePad( (D_PAD*) GetCurItem(), &dc, false );
break; break;
case ID_POPUP_PCB_EDIT_PAD: case ID_POPUP_PCB_EDIT_PAD:
......
...@@ -566,7 +566,7 @@ void FOOTPRINT_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) ...@@ -566,7 +566,7 @@ void FOOTPRINT_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
case ID_POPUP_PCB_MOVE_PAD_REQUEST: case ID_POPUP_PCB_MOVE_PAD_REQUEST:
{ {
m_canvas->MoveCursorToCrossHair(); m_canvas->MoveCursorToCrossHair();
StartMovePad( (D_PAD*) GetScreen()->GetCurItem(), &dc ); StartMovePad( (D_PAD*) GetScreen()->GetCurItem(), &dc, false );
} }
break; break;
......
...@@ -91,9 +91,10 @@ MODULE* PCB_BASE_FRAME::GetModuleByName() ...@@ -91,9 +91,10 @@ MODULE* PCB_BASE_FRAME::GetModuleByName()
} }
void PCB_EDIT_FRAME::StartMove_Module( MODULE* module, wxDC* DC ) void PCB_EDIT_FRAME::StartMoveModule( MODULE* aModule, wxDC* aDC,
bool aDragConnectedTracks )
{ {
if( module == NULL ) if( aModule == NULL )
return; return;
if( s_ModuleInitialCopy ) if( s_ModuleInitialCopy )
...@@ -102,33 +103,37 @@ void PCB_EDIT_FRAME::StartMove_Module( MODULE* module, wxDC* DC ) ...@@ -102,33 +103,37 @@ void PCB_EDIT_FRAME::StartMove_Module( MODULE* module, wxDC* DC )
s_PickedList.ClearItemsList(); // Should be empty, but... s_PickedList.ClearItemsList(); // Should be empty, but...
// Creates a copy of the current module, for abort and undo commands // Creates a copy of the current module, for abort and undo commands
s_ModuleInitialCopy = (MODULE*)module->Clone(); s_ModuleInitialCopy = (MODULE*)aModule->Clone();
s_ModuleInitialCopy->SetParent( GetBoard() ); s_ModuleInitialCopy->SetParent( GetBoard() );
s_ModuleInitialCopy->ClearFlags(); s_ModuleInitialCopy->ClearFlags();
SetCurItem( module ); SetCurItem( aModule );
GetBoard()->m_Status_Pcb &= ~RATSNEST_ITEM_LOCAL_OK; GetBoard()->m_Status_Pcb &= ~RATSNEST_ITEM_LOCAL_OK;
module->SetFlags( IS_MOVED ); aModule->SetFlags( IS_MOVED );
/* Show ratsnest. */ /* Show ratsnest. */
if( GetBoard()->IsElementVisible( RATSNEST_VISIBLE ) ) if( GetBoard()->IsElementVisible( RATSNEST_VISIBLE ) )
DrawGeneralRatsnest( DC ); DrawGeneralRatsnest( aDC );
EraseDragList(); EraseDragList();
if( g_Drag_Pistes_On ) if( aDragConnectedTracks )
{ {
Build_Drag_Liste( m_canvas, DC, module ); DRAG_LIST drglist( GetBoard() );
drglist.BuildDragListe( aModule );
ITEM_PICKER itemWrapper( NULL, UR_CHANGED ); ITEM_PICKER itemWrapper( NULL, UR_CHANGED );
for( unsigned ii = 0; ii < g_DragSegmentList.size(); ii++ ) for( unsigned ii = 0; ii < g_DragSegmentList.size(); ii++ )
{ {
TRACK* segm = g_DragSegmentList[ii].m_Segm; TRACK* segm = g_DragSegmentList[ii].m_Track;
itemWrapper.SetItem( segm ); itemWrapper.SetItem( segm );
itemWrapper.SetLink( segm->Clone() ); itemWrapper.SetLink( segm->Clone() );
itemWrapper.GetLink()->SetState( IN_EDIT, OFF ); itemWrapper.GetLink()->SetState( IN_EDIT, OFF );
s_PickedList.PushItem( itemWrapper ); s_PickedList.PushItem( itemWrapper );
} }
UndrawAndMarkSegmentsToDrag( m_canvas, aDC );
} }
GetBoard()->m_Status_Pcb |= DO_NOT_SHOW_GENERAL_RASTNEST; GetBoard()->m_Status_Pcb |= DO_NOT_SHOW_GENERAL_RASTNEST;
...@@ -136,14 +141,14 @@ void PCB_EDIT_FRAME::StartMove_Module( MODULE* module, wxDC* DC ) ...@@ -136,14 +141,14 @@ void PCB_EDIT_FRAME::StartMove_Module( MODULE* module, wxDC* DC )
m_canvas->SetAutoPanRequest( true ); m_canvas->SetAutoPanRequest( true );
// Erase the module. // Erase the module.
if( DC ) if( aDC )
{ {
module->SetFlags( DO_NOT_DRAW ); aModule->SetFlags( DO_NOT_DRAW );
m_canvas->RefreshDrawingRect( module->GetBoundingBox() ); m_canvas->RefreshDrawingRect( aModule->GetBoundingBox() );
module->ClearFlags( DO_NOT_DRAW ); aModule->ClearFlags( DO_NOT_DRAW );
} }
m_canvas->CallMouseCapture( DC, wxDefaultPosition, false ); m_canvas->CallMouseCapture( aDC, wxDefaultPosition, false );
} }
...@@ -169,22 +174,13 @@ void Abort_MoveOrCopyModule( EDA_DRAW_PANEL* Panel, wxDC* DC ) ...@@ -169,22 +174,13 @@ void Abort_MoveOrCopyModule( EDA_DRAW_PANEL* Panel, wxDC* DC )
*/ */
if( module->IsMoving() ) if( module->IsMoving() )
{ {
if( g_Drag_Pistes_On ) /* Restore old position for dragged tracks */
{
/* Erase on screen dragged tracks */
for( unsigned ii = 0; ii < g_DragSegmentList.size(); ii++ ) for( unsigned ii = 0; ii < g_DragSegmentList.size(); ii++ )
{ {
pt_segm = g_DragSegmentList[ii].m_Segm; pt_segm = g_DragSegmentList[ii].m_Track;
pt_segm->Draw( Panel, DC, GR_XOR ); pt_segm->Draw( Panel, DC, GR_XOR );
}
}
/* Go to old position for dragged tracks */
for( unsigned ii = 0; ii < g_DragSegmentList.size(); ii++ )
{
pt_segm = g_DragSegmentList[ii].m_Segm;
pt_segm->SetState( IN_EDIT, OFF ); pt_segm->SetState( IN_EDIT, OFF );
g_DragSegmentList[ii].SetInitialValues(); g_DragSegmentList[ii].RestoreInitialValues();
pt_segm->Draw( Panel, DC, GR_OR ); pt_segm->Draw( Panel, DC, GR_OR );
} }
...@@ -213,7 +209,6 @@ void Abort_MoveOrCopyModule( EDA_DRAW_PANEL* Panel, wxDC* DC ) ...@@ -213,7 +209,6 @@ void Abort_MoveOrCopyModule( EDA_DRAW_PANEL* Panel, wxDC* DC )
module->Draw( Panel, DC, GR_OR ); module->Draw( Panel, DC, GR_OR );
} }
g_Drag_Pistes_On = false;
pcbframe->SetCurItem( NULL ); pcbframe->SetCurItem( NULL );
delete s_ModuleInitialCopy; delete s_ModuleInitialCopy;
...@@ -363,7 +358,6 @@ void PCB_EDIT_FRAME::Change_Side_Module( MODULE* Module, wxDC* DC ) ...@@ -363,7 +358,6 @@ void PCB_EDIT_FRAME::Change_Side_Module( MODULE* Module, wxDC* DC )
void PCB_BASE_FRAME::PlaceModule( MODULE* aModule, wxDC* aDC, bool aDoNotRecreateRatsnest ) void PCB_BASE_FRAME::PlaceModule( MODULE* aModule, wxDC* aDC, bool aDoNotRecreateRatsnest )
{ {
TRACK* pt_segm;
wxPoint newpos; wxPoint newpos;
if( aModule == 0 ) if( aModule == 0 )
...@@ -406,23 +400,19 @@ void PCB_BASE_FRAME::PlaceModule( MODULE* aModule, wxDC* aDC, bool aDoNotRecreat ...@@ -406,23 +400,19 @@ void PCB_BASE_FRAME::PlaceModule( MODULE* aModule, wxDC* aDC, bool aDoNotRecreat
if( aDC ) if( aDC )
aModule->Draw( m_canvas, aDC, GR_OR ); aModule->Draw( m_canvas, aDC, GR_OR );
if( g_DragSegmentList.size() ) // Redraw dragged track segments, if any
{
/* Redraw dragged track segments */
for( unsigned ii = 0; ii < g_DragSegmentList.size(); ii++ ) for( unsigned ii = 0; ii < g_DragSegmentList.size(); ii++ )
{ {
pt_segm = g_DragSegmentList[ii].m_Segm; TRACK * track = g_DragSegmentList[ii].m_Track;
pt_segm->SetState( IN_EDIT, OFF ); track->SetState( IN_EDIT, OFF );
if( aDC ) if( aDC )
pt_segm->Draw( m_canvas, aDC, GR_OR ); track->Draw( m_canvas, aDC, GR_OR );
} }
// Delete drag list // Delete drag list
EraseDragList(); EraseDragList();
}
g_Drag_Pistes_On = false;
m_canvas->SetMouseCapture( NULL, NULL ); m_canvas->SetMouseCapture( NULL, NULL );
if( GetBoard()->IsElementVisible( RATSNEST_VISIBLE ) && !aDoNotRecreateRatsnest ) if( GetBoard()->IsElementVisible( RATSNEST_VISIBLE ) && !aDoNotRecreateRatsnest )
......
...@@ -9,11 +9,9 @@ ...@@ -9,11 +9,9 @@
#include <gr_basic.h> #include <gr_basic.h>
#include <common.h> #include <common.h>
#include <class_drawpanel.h> #include <class_drawpanel.h>
#include <confirm.h>
#include <trigo.h> #include <trigo.h>
#include <block_commande.h> #include <block_commande.h>
#include <wxBasePcbFrame.h> #include <wxBasePcbFrame.h>
#include <macros.h>
#include <pcbcommon.h> #include <pcbcommon.h>
#include <class_board.h> #include <class_board.h>
...@@ -21,7 +19,6 @@ ...@@ -21,7 +19,6 @@
#include <pcbnew.h> #include <pcbnew.h>
#include <drag.h> #include <drag.h>
#include <protos.h>
static D_PAD* s_CurrentSelectedPad; static D_PAD* s_CurrentSelectedPad;
...@@ -44,22 +41,18 @@ static void Abort_Move_Pad( EDA_DRAW_PANEL* Panel, wxDC* DC ) ...@@ -44,22 +41,18 @@ static void Abort_Move_Pad( EDA_DRAW_PANEL* Panel, wxDC* DC )
pad->SetPosition( Pad_OldPos ); pad->SetPosition( Pad_OldPos );
pad->Draw( Panel, DC, GR_XOR ); pad->Draw( Panel, DC, GR_XOR );
// Pad move in progress: the restore origin. // Pad move in progress: restore origin of dragged tracks, if any.
if( g_Drag_Pistes_On )
{
for( unsigned ii = 0; ii < g_DragSegmentList.size(); ii++ ) for( unsigned ii = 0; ii < g_DragSegmentList.size(); ii++ )
{ {
TRACK* Track = g_DragSegmentList[ii].m_Segm; TRACK* Track = g_DragSegmentList[ii].m_Track;
Track->Draw( Panel, DC, GR_XOR ); Track->Draw( Panel, DC, GR_XOR );
Track->SetState( IN_EDIT, OFF ); Track->SetState( IN_EDIT, OFF );
g_DragSegmentList[ii].SetInitialValues(); g_DragSegmentList[ii].RestoreInitialValues();
Track->Draw( Panel, DC, GR_OR ); Track->Draw( Panel, DC, GR_OR );
} }
}
EraseDragList(); EraseDragList();
s_CurrentSelectedPad = NULL; s_CurrentSelectedPad = NULL;
g_Drag_Pistes_On = false;
} }
...@@ -81,209 +74,22 @@ static void Show_Pad_Move( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPo ...@@ -81,209 +74,22 @@ static void Show_Pad_Move( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPo
pad->SetPosition( screen->GetCrossHairPosition() ); pad->SetPosition( screen->GetCrossHairPosition() );
pad->Draw( aPanel, aDC, GR_XOR ); pad->Draw( aPanel, aDC, GR_XOR );
if( !g_Drag_Pistes_On )
return;
for( unsigned ii = 0; ii < g_DragSegmentList.size(); ii++ ) for( unsigned ii = 0; ii < g_DragSegmentList.size(); ii++ )
{ {
Track = g_DragSegmentList[ii].m_Segm; Track = g_DragSegmentList[ii].m_Track;
if( aErase ) if( aErase )
Track->Draw( aPanel, aDC, GR_XOR ); Track->Draw( aPanel, aDC, GR_XOR );
if( g_DragSegmentList[ii].m_Pad_Start ) g_DragSegmentList[ii].SetTrackEndsCoordinates( wxPoint(0, 0) );
{
Track->m_Start = pad->GetPosition();
}
if( g_DragSegmentList[ii].m_Pad_End )
{
Track->m_End = pad->GetPosition();
}
Track->Draw( aPanel, aDC, GR_XOR ); Track->Draw( aPanel, aDC, GR_XOR );
} }
} }
/* Load list of features for default pad selection.
*/
void PCB_BASE_FRAME::Export_Pad_Settings( D_PAD* aPad )
{
if( aPad == NULL )
return;
aPad->DisplayInfo( this );
D_PAD& mp = GetDesignSettings().m_Pad_Master;
mp.SetShape( aPad->GetShape() );
mp.SetAttribute( aPad->GetAttribute() );
mp.SetLayerMask( aPad->GetLayerMask() );
mp.SetOrientation( aPad->GetOrientation() - aPad->GetParent()->GetOrientation() );
mp.SetSize( aPad->GetSize() );
mp.SetDelta( aPad->GetDelta() );
mp.SetOffset( aPad->GetOffset() );
mp.SetDrillSize( aPad->GetDrillSize() );
mp.SetDrillShape( aPad->GetDrillShape() );
}
/* Imports the new values of dimensions of the pad edge by aPad
* - Source: selected values of general characteristics
* - Measurements are modified
* - The position, names, and keys are not.
*/
void PCB_BASE_FRAME::Import_Pad_Settings( D_PAD* aPad, bool aDraw )
{
if( aDraw )
{
aPad->SetFlags( DO_NOT_DRAW );
m_canvas->RefreshDrawingRect( aPad->GetBoundingBox() );
aPad->ClearFlags( DO_NOT_DRAW );
}
D_PAD& mp = GetDesignSettings().m_Pad_Master;
aPad->SetShape( mp.GetShape() );
aPad->SetLayerMask( mp.GetLayerMask() );
aPad->SetAttribute( mp.GetAttribute() );
aPad->SetOrientation( mp.GetOrientation() + aPad->GetParent()->GetOrientation() );
aPad->SetSize( mp.GetSize() );
aPad->SetDelta( wxSize( 0, 0 ) );
aPad->SetOffset( mp.GetOffset() );
aPad->SetDrillSize( mp.GetDrillSize() );
aPad->SetDrillShape( mp.GetDrillShape() );
switch( mp.GetShape() )
{
case PAD_TRAPEZOID:
aPad->SetDelta( mp.GetDelta() );
break;
case PAD_CIRCLE:
// set size.y to size.x
aPad->SetSize( wxSize( aPad->GetSize().x, aPad->GetSize().x ) );
break;
default:
;
}
switch( mp.GetAttribute() )
{
case PAD_SMD:
case PAD_CONN:
aPad->SetDrillSize( wxSize( 0, 0 ) );
aPad->SetOffset( wxPoint( 0, 0 ) );
break;
default:
;
}
if( aDraw )
m_canvas->RefreshDrawingRect( aPad->GetBoundingBox() );
aPad->GetParent()->SetLastEditTime();
}
/* Add a pad on the selected module.
*/
void PCB_BASE_FRAME::AddPad( MODULE* aModule, bool draw )
{
// Last used pad name (pad num)
wxString lastPadName = GetDesignSettings().m_Pad_Master.GetPadName();
m_Pcb->m_Status_Pcb = 0;
aModule->SetLastEditTime();
D_PAD* pad = new D_PAD( aModule );
// Add the new pad to end of the module pad list.
aModule->m_Pads.PushBack( pad );
// Update the pad properties.
Import_Pad_Settings( pad, false );
pad->SetNetname( wxEmptyString );
pad->SetPosition( GetScreen()->GetCrossHairPosition() );
// Set the relative pad position
// ( pad position for module orient, 0, and relative to the module position)
wxPoint pos0 = pad->GetPosition() - aModule->GetPosition();
RotatePoint( &pos0, -aModule->GetOrientation() );
pad->SetPos0( pos0 );
// Automatically increment the current pad number.
long num = 0;
int ponder = 1;
while( lastPadName.Len() && lastPadName.Last() >= '0' && lastPadName.Last() <= '9' )
{
num += ( lastPadName.Last() - '0' ) * ponder;
lastPadName.RemoveLast();
ponder *= 10;
}
num++; // Use next number for the new pad
lastPadName << num;
pad->SetPadName( lastPadName );
GetDesignSettings().m_Pad_Master.SetPadName(lastPadName);
aModule->CalculateBoundingBox();
pad->DisplayInfo( this );
if( draw )
m_canvas->RefreshDrawingRect( aModule->GetBoundingBox() );
}
/**
* Function DeletePad
* Delete the pad aPad.
* Refresh the modified screen area
* Refresh modified parameters of the parent module (bounding box, last date)
* @param aPad = the pad to delete
* @param aQuery = true to promt for confirmation, false to delete silently
*/
void PCB_BASE_FRAME::DeletePad( D_PAD* aPad, bool aQuery )
{
MODULE* module;
if( aPad == NULL )
return;
module = (MODULE*) aPad->GetParent();
module->SetLastEditTime();
if( aQuery )
{
wxString msg;
msg.Printf( _( "Delete Pad (module %s %s) " ),
GetChars( module->m_Reference->m_Text ),
GetChars( module->m_Value->m_Text ) );
if( !IsOK( this, msg ) )
return;
}
m_Pcb->m_Status_Pcb = 0;
aPad->DeleteStructure();
m_canvas->RefreshDrawingRect( module->GetBoundingBox() );
module->CalculateBoundingBox();
OnModify();
}
// Function to initialize the "move pad" command // Function to initialize the "move pad" command
void PCB_BASE_FRAME::StartMovePad( D_PAD* aPad, wxDC* DC ) void PCB_BASE_FRAME::StartMovePad( D_PAD* aPad, wxDC* aDC, bool aDragConnectedTracks )
{ {
if( aPad == NULL ) if( aPad == NULL )
return; return;
...@@ -295,16 +101,20 @@ void PCB_BASE_FRAME::StartMovePad( D_PAD* aPad, wxDC* DC ) ...@@ -295,16 +101,20 @@ void PCB_BASE_FRAME::StartMovePad( D_PAD* aPad, wxDC* DC )
aPad->DisplayInfo( this ); aPad->DisplayInfo( this );
m_canvas->SetMouseCapture( Show_Pad_Move, Abort_Move_Pad ); m_canvas->SetMouseCapture( Show_Pad_Move, Abort_Move_Pad );
// Draw the pad (SKETCH mode) // Draw the pad, in SKETCH mode
aPad->Draw( m_canvas, DC, GR_XOR ); aPad->Draw( m_canvas, aDC, GR_XOR );
aPad->SetFlags( IS_MOVED ); aPad->SetFlags( IS_MOVED );
aPad->Draw( m_canvas, DC, GR_XOR ); aPad->Draw( m_canvas, aDC, GR_XOR );
// Build the list of track segments to drag if the command is a drag pad
if( g_Drag_Pistes_On )
Build_1_Pad_SegmentsToDrag( m_canvas, DC, aPad );
else
EraseDragList(); EraseDragList();
// Build the list of track segments to drag if the command is a drag pad
if( aDragConnectedTracks )
{
DRAG_LIST drglist( GetBoard() );
drglist.BuildDragListe( aPad );
UndrawAndMarkSegmentsToDrag( m_canvas, aDC );
}
} }
...@@ -325,7 +135,7 @@ void PCB_BASE_FRAME::PlacePad( D_PAD* aPad, wxDC* DC ) ...@@ -325,7 +135,7 @@ void PCB_BASE_FRAME::PlacePad( D_PAD* aPad, wxDC* DC )
// Save dragged track segments in undo list // Save dragged track segments in undo list
for( unsigned ii = 0; ii < g_DragSegmentList.size(); ii++ ) for( unsigned ii = 0; ii < g_DragSegmentList.size(); ii++ )
{ {
Track = g_DragSegmentList[ii].m_Segm; Track = g_DragSegmentList[ii].m_Track;
// Set the old state // Set the old state
if( g_DragSegmentList[ii].m_Pad_Start ) if( g_DragSegmentList[ii].m_Pad_Start )
...@@ -358,7 +168,7 @@ void PCB_BASE_FRAME::PlacePad( D_PAD* aPad, wxDC* DC ) ...@@ -358,7 +168,7 @@ void PCB_BASE_FRAME::PlacePad( D_PAD* aPad, wxDC* DC )
// Redraw dragged track segments // Redraw dragged track segments
for( unsigned ii = 0; ii < g_DragSegmentList.size(); ii++ ) for( unsigned ii = 0; ii < g_DragSegmentList.size(); ii++ )
{ {
Track = g_DragSegmentList[ii].m_Segm; Track = g_DragSegmentList[ii].m_Track;
// Set the new state // Set the new state
if( g_DragSegmentList[ii].m_Pad_Start ) if( g_DragSegmentList[ii].m_Pad_Start )
...@@ -380,8 +190,7 @@ void PCB_BASE_FRAME::PlacePad( D_PAD* aPad, wxDC* DC ) ...@@ -380,8 +190,7 @@ void PCB_BASE_FRAME::PlacePad( D_PAD* aPad, wxDC* DC )
RotatePoint( &dX, &dY, -module->GetOrientation() ); RotatePoint( &dX, &dY, -module->GetOrientation() );
aPad->SetX0( dX + aPad->GetPos0().x ); aPad->SetX0( dX + aPad->GetPos0().x );
aPad->SetY0( dY + aPad->GetPos0().y );
s_CurrentSelectedPad->SetY0( dY + s_CurrentSelectedPad->GetPos0().y );
aPad->ClearFlags(); aPad->ClearFlags();
...@@ -397,45 +206,3 @@ void PCB_BASE_FRAME::PlacePad( D_PAD* aPad, wxDC* DC ) ...@@ -397,45 +206,3 @@ void PCB_BASE_FRAME::PlacePad( D_PAD* aPad, wxDC* DC )
m_canvas->SetMouseCapture( NULL, NULL ); m_canvas->SetMouseCapture( NULL, NULL );
m_Pcb->m_Status_Pcb &= ~( LISTE_RATSNEST_ITEM_OK | CONNEXION_OK ); m_Pcb->m_Status_Pcb &= ~( LISTE_RATSNEST_ITEM_OK | CONNEXION_OK );
} }
// Rotate selected pad 90 degrees.
void PCB_BASE_FRAME::RotatePad( D_PAD* aPad, wxDC* DC )
{
if( aPad == NULL )
return;
MODULE* module = aPad->GetParent();
module->SetLastEditTime();
OnModify();
if( DC )
module->Draw( m_canvas, DC, GR_XOR );
wxSize sz = aPad->GetSize();
EXCHG( sz.x, sz.y );
aPad->SetSize( sz );
sz = aPad->GetDrillSize();
EXCHG( sz.x, sz.y );
aPad->SetDrillSize( sz );
wxPoint pt = aPad->GetOffset();
EXCHG( pt.x, pt.y );
aPad->SetOffset( pt );
aPad->SetOffset( wxPoint( aPad->GetOffset().x, -aPad->GetOffset().y ) );
sz = aPad->GetDelta();
EXCHG( sz.x, sz.y );
sz.x = -sz.x;
aPad->SetDelta( sz );
module->CalculateBoundingBox();
aPad->DisplayInfo( this );
if( DC )
module->Draw( m_canvas, DC, GR_OR );
}
...@@ -58,8 +58,6 @@ static bool InitialiseDragParameters(); ...@@ -58,8 +58,6 @@ static bool InitialiseDragParameters();
static wxPoint PosInit, s_LastPos; static wxPoint PosInit, s_LastPos;
static TRACK* NewTrack; /* New track or track being moved. */
static int NbPtNewTrack;
static double s_StartSegmentSlope, s_EndSegmentSlope, static double s_StartSegmentSlope, s_EndSegmentSlope,
s_MovingSegmentSlope, s_MovingSegmentSlope,
s_StartSegment_Yorg, s_EndSegment_Yorg, s_StartSegment_Yorg, s_EndSegment_Yorg,
...@@ -74,89 +72,32 @@ bool s_StartSegmentPresent, s_EndSegmentPresent; ...@@ -74,89 +72,32 @@ bool s_StartSegmentPresent, s_EndSegmentPresent;
static PICKED_ITEMS_LIST s_ItemsListPicker; static PICKED_ITEMS_LIST s_ItemsListPicker;
/** Abort function for commands drag, copy or move track /** Abort function for drag or move track
*/ */
static void Abort_MoveTrack( EDA_DRAW_PANEL* Panel, wxDC* DC ) static void Abort_MoveTrack( EDA_DRAW_PANEL* aPanel, wxDC* aDC )
{ {
TRACK* NextS; PCB_EDIT_FRAME* frame = (PCB_EDIT_FRAME*) aPanel->GetParent();
int ii; BOARD * pcb = frame->GetBoard();
BOARD * pcb = ( (PCB_EDIT_FRAME*) Panel->GetParent() )->GetBoard();
/* Erase the current drawings */
wxPoint oldpos = Panel->GetScreen()->GetCrossHairPosition();
Panel->GetScreen()->SetCrossHairPosition( PosInit );
if( Panel->IsMouseCaptured() )
Panel->CallMouseCapture( DC, wxDefaultPosition, true );
Panel->GetScreen()->SetCrossHairPosition( oldpos );
pcb->HighLightOFF(); pcb->HighLightOFF();
pcb->DrawHighLight( Panel, DC, pcb->GetHighLightNetCode() ); pcb->PopHighLight();
if( NewTrack )
{
if( NewTrack->IsNew() )
{
for( ii = 0; ii < NbPtNewTrack; ii++, NewTrack = NextS )
{
if( NewTrack == NULL )
break;
NextS = NewTrack->Next();
delete NewTrack;
}
}
else /* Move existing trace. */
{
TRACK* Track = NewTrack;
int dx = s_LastPos.x - PosInit.x;
int dy = s_LastPos.y - PosInit.y;
for( ii = 0; ii < NbPtNewTrack; ii++, Track = Track->Next() )
{
if( Track == NULL )
break;
Track->m_Start.x -= dx;
Track->m_Start.y -= dy;
Track->m_End.x -= dx;
Track->m_End.y -= dy;
Track->ClearFlags();
}
DrawTraces( Panel, DC, NewTrack, NbPtNewTrack, GR_OR );
}
NewTrack = NULL;
}
( (PCB_EDIT_FRAME*) Panel->GetParent() )->SetCurItem( NULL ); frame->SetCurItem( NULL );
aPanel->SetMouseCapture( NULL, NULL );
/* Undo move and redraw trace segments. */ /* Undo move and redraw trace segments. */
for( unsigned jj=0 ; jj < g_DragSegmentList.size(); jj++ ) for( unsigned jj=0 ; jj < g_DragSegmentList.size(); jj++ )
{ {
TRACK* Track = g_DragSegmentList[jj].m_Segm; TRACK* track = g_DragSegmentList[jj].m_Track;
g_DragSegmentList[jj].SetInitialValues(); g_DragSegmentList[jj].RestoreInitialValues();
Track->SetState( IN_EDIT, OFF ); track->SetState( IN_EDIT, OFF );
Track->ClearFlags(); track->ClearFlags();
Track->Draw( Panel, DC, GR_OR );
} }
// Clear the undo picker list: // Clear the undo picker list:
s_ItemsListPicker.ClearListAndDeleteItems(); s_ItemsListPicker.ClearListAndDeleteItems();
pcb->PopHighLight();
if( pcb->IsHighLightNetON() )
pcb->DrawHighLight( Panel, DC, pcb->GetHighLightNetCode() );
EraseDragList(); EraseDragList();
Panel->SetMouseCapture( NULL, NULL ); aPanel->Refresh();
Panel->Refresh();
} }
...@@ -164,9 +105,7 @@ static void Abort_MoveTrack( EDA_DRAW_PANEL* Panel, wxDC* DC ) ...@@ -164,9 +105,7 @@ static void Abort_MoveTrack( EDA_DRAW_PANEL* Panel, wxDC* DC )
static void Show_MoveNode( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition, static void Show_MoveNode( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition,
bool aErase ) bool aErase )
{ {
int ii;
wxPoint moveVector; wxPoint moveVector;
TRACK* Track;
BASE_SCREEN* screen = aPanel->GetScreen(); BASE_SCREEN* screen = aPanel->GetScreen();
int track_fill_copy = DisplayOpt.DisplayPcbTrackFill; int track_fill_copy = DisplayOpt.DisplayPcbTrackFill;
GR_DRAWMODE draw_mode = GR_XOR | GR_HIGHLIGHT; GR_DRAWMODE draw_mode = GR_XOR | GR_HIGHLIGHT;
...@@ -179,61 +118,42 @@ static void Show_MoveNode( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPo ...@@ -179,61 +118,42 @@ static void Show_MoveNode( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPo
aErase = false; aErase = false;
#endif #endif
/* erase the current moved track segments from screen */
if( aErase )
{
if( NewTrack )
DrawTraces( aPanel, aDC, NewTrack, NbPtNewTrack, draw_mode );
}
/* set the new track coordinates */ /* set the new track coordinates */
wxPoint Pos = screen->GetCrossHairPosition(); wxPoint Pos = screen->GetCrossHairPosition();
moveVector = Pos - s_LastPos; moveVector = Pos - s_LastPos;
s_LastPos = Pos; s_LastPos = Pos;
ii = NbPtNewTrack; TRACK *track = NULL;
Track = NewTrack;
for( ; (ii > 0) && (Track != NULL); ii--, Track = Track->Next() )
{
if( Track->GetFlags() & STARTPOINT )
Track->m_Start += moveVector;
if( Track->GetFlags() & ENDPOINT )
Track->m_End += moveVector;
}
#ifndef USE_WX_OVERLAY
/* Redraw the current moved track segments */
DrawTraces( aPanel, aDC, NewTrack, NbPtNewTrack, draw_mode );
#endif
for( unsigned ii = 0; ii < g_DragSegmentList.size(); ii++ ) for( unsigned ii = 0; ii < g_DragSegmentList.size(); ii++ )
{ {
Track = g_DragSegmentList[ii].m_Segm; if( aErase )
track = g_DragSegmentList[ii].m_Track;
if( aErase ) if( aErase )
Track->Draw( aPanel, aDC, draw_mode ); track->Draw( aPanel, aDC, draw_mode );
if( Track->GetFlags() & STARTPOINT ) if( track->GetFlags() & STARTPOINT )
Track->m_Start += moveVector; track->m_Start += moveVector;
if( Track->GetFlags() & ENDPOINT ) if( track->GetFlags() & ENDPOINT )
Track->m_End += moveVector; track->m_End += moveVector;
Track->Draw( aPanel, aDC, draw_mode ); if( track->Type() == PCB_VIA_T )
track->m_End = track->m_Start;
track->Draw( aPanel, aDC, draw_mode );
} }
DisplayOpt.DisplayPcbTrackFill = track_fill_copy; DisplayOpt.DisplayPcbTrackFill = track_fill_copy;
// Display track length // Display track length
if( track )
{
PCB_BASE_FRAME* frame = (PCB_BASE_FRAME*) aPanel->GetParent(); PCB_BASE_FRAME* frame = (PCB_BASE_FRAME*) aPanel->GetParent();
if( Track == NULL ) // can happen if g_DragSegmentList is empty track->DisplayInfo( frame );
Track = NewTrack; // try to use main item }
if( Track )
Track->DisplayInfo( frame );
} }
...@@ -298,7 +218,7 @@ static void Show_Drag_Track_Segment_With_Cte_Slope( EDA_DRAW_PANEL* aPanel, wxDC ...@@ -298,7 +218,7 @@ static void Show_Drag_Track_Segment_With_Cte_Slope( EDA_DRAW_PANEL* aPanel, wxDC
* the segment connected to its start point (if exists) * the segment connected to its start point (if exists)
*/ */
int ii = g_DragSegmentList.size() - 1; int ii = g_DragSegmentList.size() - 1;
Track = g_DragSegmentList[ii].m_Segm; Track = g_DragSegmentList[ii].m_Track;
if( Track == NULL ) if( Track == NULL )
return; return;
...@@ -310,7 +230,7 @@ static void Show_Drag_Track_Segment_With_Cte_Slope( EDA_DRAW_PANEL* aPanel, wxDC ...@@ -310,7 +230,7 @@ static void Show_Drag_Track_Segment_With_Cte_Slope( EDA_DRAW_PANEL* aPanel, wxDC
if( s_EndSegmentPresent ) if( s_EndSegmentPresent )
{ {
// Get the segment connected to the end point // Get the segment connected to the end point
tSegmentToEnd = g_DragSegmentList[ii].m_Segm; tSegmentToEnd = g_DragSegmentList[ii].m_Track;
ii--; ii--;
} }
...@@ -318,7 +238,7 @@ static void Show_Drag_Track_Segment_With_Cte_Slope( EDA_DRAW_PANEL* aPanel, wxDC ...@@ -318,7 +238,7 @@ static void Show_Drag_Track_Segment_With_Cte_Slope( EDA_DRAW_PANEL* aPanel, wxDC
{ {
// Get the segment connected to the start point // Get the segment connected to the start point
if( ii >= 0 ) if( ii >= 0 )
tSegmentToStart = g_DragSegmentList[ii].m_Segm; tSegmentToStart = g_DragSegmentList[ii].m_Track;
} }
} }
...@@ -531,7 +451,7 @@ bool InitialiseDragParameters() ...@@ -531,7 +451,7 @@ bool InitialiseDragParameters()
* the segment connected to its start point (if exists) * the segment connected to its start point (if exists)
*/ */
int ii = g_DragSegmentList.size() - 1; int ii = g_DragSegmentList.size() - 1;
Track = g_DragSegmentList[ii].m_Segm; Track = g_DragSegmentList[ii].m_Track;
if( Track == NULL ) if( Track == NULL )
return false; return false;
...@@ -541,7 +461,7 @@ bool InitialiseDragParameters() ...@@ -541,7 +461,7 @@ bool InitialiseDragParameters()
{ {
if( s_EndSegmentPresent ) if( s_EndSegmentPresent )
{ {
tSegmentToEnd = g_DragSegmentList[ii].m_Segm; // Get the segment connected to tSegmentToEnd = g_DragSegmentList[ii].m_Track; // Get the segment connected to
// the end point // the end point
ii--; ii--;
} }
...@@ -549,7 +469,7 @@ bool InitialiseDragParameters() ...@@ -549,7 +469,7 @@ bool InitialiseDragParameters()
if( s_StartSegmentPresent ) if( s_StartSegmentPresent )
{ {
if( ii >= 0 ) if( ii >= 0 )
tSegmentToStart = g_DragSegmentList[ii].m_Segm; // Get the segment connected to tSegmentToStart = g_DragSegmentList[ii].m_Track; // Get the segment connected to
// the start point // the start point
} }
} }
...@@ -694,8 +614,6 @@ void PCB_EDIT_FRAME::StartMoveOneNodeOrSegment( TRACK* aTrack, wxDC* aDC, int aC ...@@ -694,8 +614,6 @@ void PCB_EDIT_FRAME::StartMoveOneNodeOrSegment( TRACK* aTrack, wxDC* aDC, int aC
if( !aTrack ) if( !aTrack )
return; return;
NewTrack = NULL;
NbPtNewTrack = 0;
EraseDragList(); EraseDragList();
/* Change highlighted net: the new one will be highlighted */ /* Change highlighted net: the new one will be highlighted */
...@@ -706,19 +624,18 @@ void PCB_EDIT_FRAME::StartMoveOneNodeOrSegment( TRACK* aTrack, wxDC* aDC, int aC ...@@ -706,19 +624,18 @@ void PCB_EDIT_FRAME::StartMoveOneNodeOrSegment( TRACK* aTrack, wxDC* aDC, int aC
PosInit = GetScreen()->GetCrossHairPosition(); PosInit = GetScreen()->GetCrossHairPosition();
if( aTrack->Type() == PCB_VIA_T ) // For a via: always drag it if( aTrack->Type() == PCB_VIA_T )
{ {
aTrack->SetFlags( IS_DRAGGED | STARTPOINT | ENDPOINT ); aTrack->SetFlags( IS_DRAGGED | STARTPOINT | ENDPOINT );
AddSegmentToDragList( aTrack->GetFlags(), aTrack );
if( aCommand != ID_POPUP_PCB_MOVE_TRACK_SEGMENT ) if( aCommand != ID_POPUP_PCB_MOVE_TRACK_SEGMENT )
{ {
Collect_TrackSegmentsToDrag( m_canvas, aDC, aTrack->m_Start, Collect_TrackSegmentsToDrag( GetBoard(), aTrack->m_Start,
aTrack->ReturnMaskLayer(), aTrack->ReturnMaskLayer(),
aTrack->GetNet() ); aTrack->GetNet() );
} }
NewTrack = aTrack;
NbPtNewTrack = 1;
PosInit = aTrack->m_Start; PosInit = aTrack->m_Start;
} }
else else
...@@ -730,25 +647,22 @@ void PCB_EDIT_FRAME::StartMoveOneNodeOrSegment( TRACK* aTrack, wxDC* aDC, int aC ...@@ -730,25 +647,22 @@ void PCB_EDIT_FRAME::StartMoveOneNodeOrSegment( TRACK* aTrack, wxDC* aDC, int aC
{ {
case ID_POPUP_PCB_MOVE_TRACK_SEGMENT: // Move segment case ID_POPUP_PCB_MOVE_TRACK_SEGMENT: // Move segment
aTrack->SetFlags( IS_DRAGGED | ENDPOINT | STARTPOINT ); aTrack->SetFlags( IS_DRAGGED | ENDPOINT | STARTPOINT );
AddSegmentToDragList( m_canvas, aDC, aTrack->GetFlags(), aTrack ); AddSegmentToDragList( aTrack->GetFlags(), aTrack );
break; break;
case ID_POPUP_PCB_DRAG_TRACK_SEGMENT: // drag a segment case ID_POPUP_PCB_DRAG_TRACK_SEGMENT: // drag a segment
pos = aTrack->m_Start; pos = aTrack->m_Start;
Collect_TrackSegmentsToDrag( m_canvas, aDC, pos, Collect_TrackSegmentsToDrag( GetBoard(), pos, aTrack->ReturnMaskLayer(),
aTrack->ReturnMaskLayer(),
aTrack->GetNet() ); aTrack->GetNet() );
pos = aTrack->m_End; pos = aTrack->m_End;
aTrack->SetFlags( IS_DRAGGED | ENDPOINT | STARTPOINT ); aTrack->SetFlags( IS_DRAGGED | ENDPOINT | STARTPOINT );
Collect_TrackSegmentsToDrag( m_canvas, aDC, pos, Collect_TrackSegmentsToDrag( GetBoard(), pos, aTrack->ReturnMaskLayer(),
aTrack->ReturnMaskLayer(),
aTrack->GetNet() ); aTrack->GetNet() );
break; break;
case ID_POPUP_PCB_MOVE_TRACK_NODE: // Drag via or move node case ID_POPUP_PCB_MOVE_TRACK_NODE: // Drag via or move node
pos = (diag & STARTPOINT) ? aTrack->m_Start : aTrack->m_End; pos = (diag & STARTPOINT) ? aTrack->m_Start : aTrack->m_End;
Collect_TrackSegmentsToDrag( m_canvas, aDC, pos, Collect_TrackSegmentsToDrag( GetBoard(), pos, aTrack->ReturnMaskLayer(),
aTrack->ReturnMaskLayer(),
aTrack->GetNet() ); aTrack->GetNet() );
PosInit = pos; PosInit = pos;
break; break;
...@@ -764,7 +678,7 @@ void PCB_EDIT_FRAME::StartMoveOneNodeOrSegment( TRACK* aTrack, wxDC* aDC, int aC ...@@ -764,7 +678,7 @@ void PCB_EDIT_FRAME::StartMoveOneNodeOrSegment( TRACK* aTrack, wxDC* aDC, int aC
for( unsigned ii = 0; ii < g_DragSegmentList.size(); ii++ ) for( unsigned ii = 0; ii < g_DragSegmentList.size(); ii++ )
{ {
TRACK* draggedtrack = g_DragSegmentList[ii].m_Segm; TRACK* draggedtrack = g_DragSegmentList[ii].m_Track;
picker.SetItem( draggedtrack ); picker.SetItem( draggedtrack );
picker.SetLink( draggedtrack->Clone() ); picker.SetLink( draggedtrack->Clone() );
s_ItemsListPicker.PushItem( picker ); s_ItemsListPicker.PushItem( picker );
...@@ -781,87 +695,11 @@ void PCB_EDIT_FRAME::StartMoveOneNodeOrSegment( TRACK* aTrack, wxDC* aDC, int aC ...@@ -781,87 +695,11 @@ void PCB_EDIT_FRAME::StartMoveOneNodeOrSegment( TRACK* aTrack, wxDC* aDC, int aC
GetBoard()->DrawHighLight( m_canvas, aDC, GetBoard()->GetHighLightNetCode() ); GetBoard()->DrawHighLight( m_canvas, aDC, GetBoard()->GetHighLightNetCode() );
m_canvas->CallMouseCapture( aDC, wxDefaultPosition, true ); m_canvas->CallMouseCapture( aDC, wxDefaultPosition, true );
}
#if 0 UndrawAndMarkSegmentsToDrag( m_canvas, aDC );
// @todo: This function is broken: does not handle pointers to pads for start
// and end and flags relative to these pointers
void SortTrackEndPoints( TRACK* track )
{
// sort the track endpoints -- should not matter in terms of drawing
// or producing the pcb -- but makes doing comparisons easier.
int dx = track->m_End.x - track->m_Start.x;
if( dx )
{
if( track->m_Start.x > track->m_End.x )
{
EXCHG( track->m_Start, track->m_End );
}
}
else
{
if( track->m_Start.y > track->m_End.y )
{
EXCHG( track->m_Start, track->m_End );
}
}
}
bool PCB_EDIT_FRAME::MergeCollinearTracks( TRACK* track, wxDC* DC, int end )
{
testtrack = track->GetTrace( GetBoard()->m_Track, NULL, end );
if( testtrack )
{
SortTrackEndPoints( track );
SortTrackEndPoints( testtrack );
int dx = track->m_End.x - track->m_Start.x;
int dy = track->m_End.y - track->m_Start.y;
int tdx = testtrack->m_End.x - testtrack->m_Start.x;
int tdy = testtrack->m_End.y - testtrack->m_Start.y;
if( ( dy * tdx == dx * tdy && dy != 0 && dx != 0 && tdy != 0 && tdx != 0 ) /* angle, same slope */
|| ( dy == 0 && tdy == 0 && dx * tdx ) /*horizontal */
|| ( dx == 0 && tdx == 0 && dy * tdy ) /*vertical */
)
{
if( track->m_Start == testtrack->m_Start || track->m_End == testtrack->m_Start )
{
if( ( dx * tdx && testtrack->m_End.x > track->m_End.x )
||( dy * tdy && testtrack->m_End.y > track->m_End.y ) )
{
track->m_End = testtrack->m_End;
Delete_Segment( DC, testtrack );
return true;
}
}
if( track->m_Start == testtrack->m_End || track->m_End == testtrack->m_End )
{
if( ( dx * tdx && testtrack->m_Start.x < track->m_Start.x )
|| ( dy * tdy && testtrack->m_Start.y < track->m_Start.y ) )
{
track->m_Start = testtrack->m_Start;
Delete_Segment( DC, testtrack );
return true;
}
}
}
}
return false;
} }
#endif
void PCB_EDIT_FRAME::Start_DragTrackSegmentAndKeepSlope( TRACK* track, wxDC* DC ) void PCB_EDIT_FRAME::Start_DragTrackSegmentAndKeepSlope( TRACK* track, wxDC* DC )
{ {
TRACK* TrackToStartPoint = NULL; TRACK* TrackToStartPoint = NULL;
...@@ -871,18 +709,8 @@ void PCB_EDIT_FRAME::Start_DragTrackSegmentAndKeepSlope( TRACK* track, wxDC* DC ...@@ -871,18 +709,8 @@ void PCB_EDIT_FRAME::Start_DragTrackSegmentAndKeepSlope( TRACK* track, wxDC* DC
if( !track ) if( !track )
return; return;
// TODO: Use clenup functions to merge collinear segments if track
#if 0 // is connected to a collinear segment.
// Broken functions: see comments
while( MergeCollinearTracks( track, DC, START ) )
{
};
while( MergeCollinearTracks( track, DC, END ) )
{
};
#endif
s_StartSegmentPresent = s_EndSegmentPresent = true; s_StartSegmentPresent = s_EndSegmentPresent = true;
...@@ -937,8 +765,6 @@ void PCB_EDIT_FRAME::Start_DragTrackSegmentAndKeepSlope( TRACK* track, wxDC* DC ...@@ -937,8 +765,6 @@ void PCB_EDIT_FRAME::Start_DragTrackSegmentAndKeepSlope( TRACK* track, wxDC* DC
EraseDragList(); EraseDragList();
NewTrack = NULL;
NbPtNewTrack = 0;
track->SetFlags( IS_DRAGGED ); track->SetFlags( IS_DRAGGED );
if( TrackToStartPoint ) if( TrackToStartPoint )
...@@ -948,7 +774,7 @@ void PCB_EDIT_FRAME::Start_DragTrackSegmentAndKeepSlope( TRACK* track, wxDC* DC ...@@ -948,7 +774,7 @@ void PCB_EDIT_FRAME::Start_DragTrackSegmentAndKeepSlope( TRACK* track, wxDC* DC
if( track->m_Start != TrackToStartPoint->m_Start ) if( track->m_Start != TrackToStartPoint->m_Start )
flag = ENDPOINT; flag = ENDPOINT;
AddSegmentToDragList( m_canvas, DC, flag, TrackToStartPoint ); AddSegmentToDragList( flag, TrackToStartPoint );
track->SetFlags( STARTPOINT ); track->SetFlags( STARTPOINT );
} }
...@@ -959,11 +785,13 @@ void PCB_EDIT_FRAME::Start_DragTrackSegmentAndKeepSlope( TRACK* track, wxDC* DC ...@@ -959,11 +785,13 @@ void PCB_EDIT_FRAME::Start_DragTrackSegmentAndKeepSlope( TRACK* track, wxDC* DC
if( track->m_End != TrackToEndPoint->m_Start ) if( track->m_End != TrackToEndPoint->m_Start )
flag = ENDPOINT; flag = ENDPOINT;
AddSegmentToDragList( m_canvas, DC, flag, TrackToEndPoint ); AddSegmentToDragList( flag, TrackToEndPoint );
track->SetFlags( ENDPOINT ); track->SetFlags( ENDPOINT );
} }
AddSegmentToDragList( m_canvas, DC, track->GetFlags(), track ); AddSegmentToDragList( track->GetFlags(), track );
UndrawAndMarkSegmentsToDrag( m_canvas, DC );
PosInit = GetScreen()->GetCrossHairPosition(); PosInit = GetScreen()->GetCrossHairPosition();
...@@ -979,7 +807,7 @@ void PCB_EDIT_FRAME::Start_DragTrackSegmentAndKeepSlope( TRACK* track, wxDC* DC ...@@ -979,7 +807,7 @@ void PCB_EDIT_FRAME::Start_DragTrackSegmentAndKeepSlope( TRACK* track, wxDC* DC
for( unsigned ii = 0; ii < g_DragSegmentList.size(); ii++ ) for( unsigned ii = 0; ii < g_DragSegmentList.size(); ii++ )
{ {
TRACK* draggedtrack = g_DragSegmentList[ii].m_Segm; TRACK* draggedtrack = g_DragSegmentList[ii].m_Track;
picker.SetItem( draggedtrack); picker.SetItem( draggedtrack);
picker.SetLink ( draggedtrack->Clone() ); picker.SetLink ( draggedtrack->Clone() );
s_ItemsListPicker.PushItem( picker ); s_ItemsListPicker.PushItem( picker );
...@@ -1019,27 +847,23 @@ bool PCB_EDIT_FRAME::PlaceDraggedOrMovedTrackSegment( TRACK* Track, wxDC* DC ) ...@@ -1019,27 +847,23 @@ bool PCB_EDIT_FRAME::PlaceDraggedOrMovedTrackSegment( TRACK* Track, wxDC* DC )
/* Redraw the dragged segments */ /* Redraw the dragged segments */
for( unsigned ii = 0; ii < g_DragSegmentList.size(); ii++ ) for( unsigned ii = 0; ii < g_DragSegmentList.size(); ii++ )
{ {
errdrc = m_drc->Drc( g_DragSegmentList[ii].m_Segm, GetBoard()->m_Track ); errdrc = m_drc->Drc( g_DragSegmentList[ii].m_Track, GetBoard()->m_Track );
if( errdrc == BAD_DRC ) if( errdrc == BAD_DRC )
return false; return false;
} }
} }
GR_DRAWMODE draw_mode = GR_OR | GR_HIGHLIGHT;
// DRC Ok: place track segments // DRC Ok: place track segments
Track->ClearFlags(); Track->ClearFlags();
Track->SetState( IN_EDIT, OFF ); Track->SetState( IN_EDIT, OFF );
Track->Draw( m_canvas, DC, draw_mode );
/* Draw dragged tracks */ /* Draw dragged tracks */
for( unsigned ii = 0; ii < g_DragSegmentList.size(); ii++ ) for( unsigned ii = 0; ii < g_DragSegmentList.size(); ii++ )
{ {
Track = g_DragSegmentList[ii].m_Segm; Track = g_DragSegmentList[ii].m_Track;
Track->SetState( IN_EDIT, OFF ); Track->SetState( IN_EDIT, OFF );
Track->ClearFlags(); Track->ClearFlags();
Track->Draw( m_canvas, DC, draw_mode );
/* Test the connections modified by the move /* Test the connections modified by the move
* (only pad connection must be tested, track connection will be * (only pad connection must be tested, track connection will be
...@@ -1065,21 +889,15 @@ bool PCB_EDIT_FRAME::PlaceDraggedOrMovedTrackSegment( TRACK* Track, wxDC* DC ) ...@@ -1065,21 +889,15 @@ bool PCB_EDIT_FRAME::PlaceDraggedOrMovedTrackSegment( TRACK* Track, wxDC* DC )
SaveCopyInUndoList( s_ItemsListPicker, UR_UNSPECIFIED ); SaveCopyInUndoList( s_ItemsListPicker, UR_UNSPECIFIED );
s_ItemsListPicker.ClearItemsList(); // s_ItemsListPicker is no more owner of picked items s_ItemsListPicker.ClearItemsList(); // s_ItemsListPicker is no more owner of picked items
if( GetBoard()->IsHighLightNetON() )
HighLight( DC );
GetBoard()->PopHighLight(); GetBoard()->PopHighLight();
if( GetBoard()->IsHighLightNetON() )
GetBoard()->DrawHighLight( m_canvas, DC, GetBoard()->GetHighLightNetCode() );
OnModify(); OnModify();
m_canvas->SetMouseCapture( NULL, NULL ); m_canvas->SetMouseCapture( NULL, NULL );
m_canvas->Refresh();
if( current_net_code > 0 ) if( current_net_code > 0 )
TestNetConnection( DC, current_net_code ); TestNetConnection( DC, current_net_code );
m_canvas->Refresh();
return true; return true;
} }
...@@ -101,7 +101,7 @@ void PCB_EDIT_FRAME::MuWaveCommand( wxDC* DC, const wxPoint& MousePos ) ...@@ -101,7 +101,7 @@ void PCB_EDIT_FRAME::MuWaveCommand( wxDC* DC, const wxPoint& MousePos )
if( module ) if( module )
{ {
StartMove_Module( module, DC ); StartMoveModule( module, DC, false );
} }
m_canvas->MoveCursorToCrossHair(); m_canvas->MoveCursorToCrossHair();
......
...@@ -221,7 +221,7 @@ void PCB_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition ) ...@@ -221,7 +221,7 @@ void PCB_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition )
} }
else else
{ {
DisplayError( this, wxT( "Internal err: Struct not PCB_TARGET_T" ) ); DisplayError( this, wxT( "OnLeftClick err: not a PCB_TARGET_T" ) );
} }
break; break;
...@@ -333,7 +333,7 @@ void PCB_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition ) ...@@ -333,7 +333,7 @@ void PCB_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition )
} }
else else
{ {
DisplayError( this, wxT( "Internal err: Struct not PCB_TEXT_T" ) ); DisplayError( this, wxT( "OnLeftClick err: not a PCB_TEXT_T" ) );
} }
break; break;
...@@ -346,7 +346,7 @@ void PCB_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition ) ...@@ -346,7 +346,7 @@ void PCB_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition )
SetCurItem( DrawStruct ); SetCurItem( DrawStruct );
if( DrawStruct ) if( DrawStruct )
StartMove_Module( (MODULE*) DrawStruct, aDC ); StartMoveModule( (MODULE*) DrawStruct, aDC, false );
} }
else if( DrawStruct->Type() == PCB_MODULE_T ) else if( DrawStruct->Type() == PCB_MODULE_T )
{ {
......
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2012 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.fr
* Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
* Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 1992-2011 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @file pad_change_functions.cpp
*/
#include <fctsys.h>
#include <class_drawpanel.h>
#include <confirm.h>
#include <trigo.h>
#include <wxBasePcbFrame.h>
#include <pcbnew.h>
#include <class_board.h>
#include <class_module.h>
#include <class_pad.h>
#include <class_board_design_settings.h>
/* Exports the current pad settings to board design settings.
*/
void PCB_BASE_FRAME::Export_Pad_Settings( D_PAD* aPad )
{
if( aPad == NULL )
return;
aPad->DisplayInfo( this );
D_PAD& mp = GetDesignSettings().m_Pad_Master;
mp.SetShape( aPad->GetShape() );
mp.SetAttribute( aPad->GetAttribute() );
mp.SetLayerMask( aPad->GetLayerMask() );
mp.SetOrientation( aPad->GetOrientation() - aPad->GetParent()->GetOrientation() );
mp.SetSize( aPad->GetSize() );
mp.SetDelta( aPad->GetDelta() );
mp.SetOffset( aPad->GetOffset() );
mp.SetDrillSize( aPad->GetDrillSize() );
mp.SetDrillShape( aPad->GetDrillShape() );
}
/* Imports the board design settings to aPad
* - The position, names, and keys are not modifed.
*/
void PCB_BASE_FRAME::Import_Pad_Settings( D_PAD* aPad, bool aDraw )
{
if( aDraw )
{
aPad->SetFlags( DO_NOT_DRAW );
m_canvas->RefreshDrawingRect( aPad->GetBoundingBox() );
aPad->ClearFlags( DO_NOT_DRAW );
}
D_PAD& mp = GetDesignSettings().m_Pad_Master;
aPad->SetShape( mp.GetShape() );
aPad->SetLayerMask( mp.GetLayerMask() );
aPad->SetAttribute( mp.GetAttribute() );
aPad->SetOrientation( mp.GetOrientation() + aPad->GetParent()->GetOrientation() );
aPad->SetSize( mp.GetSize() );
aPad->SetDelta( wxSize( 0, 0 ) );
aPad->SetOffset( mp.GetOffset() );
aPad->SetDrillSize( mp.GetDrillSize() );
aPad->SetDrillShape( mp.GetDrillShape() );
switch( mp.GetShape() )
{
case PAD_TRAPEZOID:
aPad->SetDelta( mp.GetDelta() );
break;
case PAD_CIRCLE:
// ensure size.y == size.x
aPad->SetSize( wxSize( aPad->GetSize().x, aPad->GetSize().x ) );
break;
default:
;
}
switch( mp.GetAttribute() )
{
case PAD_SMD:
case PAD_CONN:
aPad->SetDrillSize( wxSize( 0, 0 ) );
aPad->SetOffset( wxPoint( 0, 0 ) );
break;
default:
;
}
if( aDraw )
m_canvas->RefreshDrawingRect( aPad->GetBoundingBox() );
aPad->GetParent()->SetLastEditTime();
}
/* Add a new pad to aModule.
*/
void PCB_BASE_FRAME::AddPad( MODULE* aModule, bool draw )
{
// Last used pad name (pad num)
wxString lastPadName = GetDesignSettings().m_Pad_Master.GetPadName();
m_Pcb->m_Status_Pcb = 0;
aModule->SetLastEditTime();
D_PAD* pad = new D_PAD( aModule );
// Add the new pad to end of the module pad list.
aModule->m_Pads.PushBack( pad );
// Update the pad properties.
Import_Pad_Settings( pad, false );
pad->SetNetname( wxEmptyString );
pad->SetPosition( GetScreen()->GetCrossHairPosition() );
// Set the relative pad position
// ( pad position for module orient, 0, and relative to the module position)
wxPoint pos0 = pad->GetPosition() - aModule->GetPosition();
RotatePoint( &pos0, -aModule->GetOrientation() );
pad->SetPos0( pos0 );
// Automatically increment the current pad number.
long num = 0;
int ponder = 1;
while( lastPadName.Len() && lastPadName.Last() >= '0' && lastPadName.Last() <= '9' )
{
num += ( lastPadName.Last() - '0' ) * ponder;
lastPadName.RemoveLast();
ponder *= 10;
}
num++; // Use next number for the new pad
lastPadName << num;
pad->SetPadName( lastPadName );
GetDesignSettings().m_Pad_Master.SetPadName(lastPadName);
aModule->CalculateBoundingBox();
pad->DisplayInfo( this );
if( draw )
m_canvas->RefreshDrawingRect( aModule->GetBoundingBox() );
}
/**
* Function DeletePad
* Delete the pad aPad.
* Refresh the modified screen area
* Refresh modified parameters of the parent module (bounding box, last date)
* @param aPad = the pad to delete
* @param aQuery = true to promt for confirmation, false to delete silently
*/
void PCB_BASE_FRAME::DeletePad( D_PAD* aPad, bool aQuery )
{
MODULE* module;
if( aPad == NULL )
return;
module = (MODULE*) aPad->GetParent();
module->SetLastEditTime();
if( aQuery )
{
wxString msg;
msg.Printf( _( "Delete Pad (module %s %s) " ),
GetChars( module->m_Reference->m_Text ),
GetChars( module->m_Value->m_Text ) );
if( !IsOK( this, msg ) )
return;
}
m_Pcb->m_Status_Pcb = 0;
aPad->DeleteStructure();
m_canvas->RefreshDrawingRect( module->GetBoundingBox() );
module->CalculateBoundingBox();
OnModify();
}
// Rotate selected pad 90 degrees.
void PCB_BASE_FRAME::RotatePad( D_PAD* aPad, wxDC* DC )
{
if( aPad == NULL )
return;
MODULE* module = aPad->GetParent();
module->SetLastEditTime();
OnModify();
if( DC )
module->Draw( m_canvas, DC, GR_XOR );
wxSize sz = aPad->GetSize();
EXCHG( sz.x, sz.y );
aPad->SetSize( sz );
sz = aPad->GetDrillSize();
EXCHG( sz.x, sz.y );
aPad->SetDrillSize( sz );
wxPoint pt = aPad->GetOffset();
EXCHG( pt.x, pt.y );
aPad->SetOffset( pt );
aPad->SetOffset( wxPoint( aPad->GetOffset().x, -aPad->GetOffset().y ) );
sz = aPad->GetDelta();
EXCHG( sz.x, sz.y );
sz.x = -sz.x;
aPad->SetDelta( sz );
module->CalculateBoundingBox();
aPad->DisplayInfo( this );
if( DC )
module->Draw( m_canvas, DC, GR_OR );
}
...@@ -58,7 +58,6 @@ COLORS_DESIGN_SETTINGS g_ColorsSettings; ...@@ -58,7 +58,6 @@ COLORS_DESIGN_SETTINGS g_ColorsSettings;
bool Drc_On = true; bool Drc_On = true;
bool g_AutoDeleteOldTrack = true; bool g_AutoDeleteOldTrack = true;
bool g_Drag_Pistes_On;
bool g_Show_Module_Ratsnest; bool g_Show_Module_Ratsnest;
bool g_Raccord_45_Auto = true; bool g_Raccord_45_Auto = true;
bool g_Alternate_Track_Posture = false; bool g_Alternate_Track_Posture = false;
......
...@@ -51,7 +51,6 @@ extern wxString g_DocModulesFileName; ...@@ -51,7 +51,6 @@ extern wxString g_DocModulesFileName;
/* variables */ /* variables */
extern bool Drc_On; extern bool Drc_On;
extern bool g_AutoDeleteOldTrack; extern bool g_AutoDeleteOldTrack;
extern bool g_Drag_Pistes_On;
extern bool g_Show_Module_Ratsnest; extern bool g_Show_Module_Ratsnest;
extern bool g_Raccord_45_Auto; extern bool g_Raccord_45_Auto;
extern bool g_Track_45_Only_Allowed; extern bool g_Track_45_Only_Allowed;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment