KiCad PCB EDA Suite
modules.cpp File Reference
#include <fctsys.h>
#include <gr_basic.h>
#include <class_drawpanel.h>
#include <confirm.h>
#include <wxPcbStruct.h>
#include <trigo.h>
#include <macros.h>
#include <class_board.h>
#include <class_module.h>
#include <pcbnew.h>
#include <drag.h>
#include <dialog_get_footprint_by_name.h>

Go to the source code of this file.

Functions

static void MoveFootprint (EDA_DRAW_PANEL *aPanel, wxDC *aDC, const wxPoint &aPosition, bool aErase)
 
static void Abort_MoveOrCopyModule (EDA_DRAW_PANEL *Panel, wxDC *DC)
 

Variables

static MODULEs_ModuleInitialCopy = NULL
 
static PICKED_ITEMS_LIST s_PickedList
 

Function Documentation

void Abort_MoveOrCopyModule ( EDA_DRAW_PANEL Panel,
wxDC *  DC 
)
static

Definition at line 161 of file modules.cpp.

References BOARD::BuildListOfNets(), PCB_EDIT_FRAME::Change_Side_Module(), EDA_ITEM::ClearFlags(), PICKED_ITEMS_LIST::ClearListAndDeleteItems(), BOARD_ITEM::DeleteStructure(), DO_NOT_SHOW_GENERAL_RASTNEST, TRACK::Draw(), MODULE::Draw(), PCB_BASE_FRAME::DrawGeneralRatsnest(), MODULE::DrawOutlinesWhenMoving(), EraseDragList(), g_DragSegmentList, g_Offset_Module, PCB_BASE_FRAME::GetBoard(), PCB_SCREEN::GetCurItem(), BOARD_ITEM::GetLayer(), MODULE::GetOrientation(), EDA_DRAW_PANEL::GetParent(), PCB_BASE_FRAME::GetScreen(), GR_OR, GR_XOR, IN_EDIT, IS_MOVED, BOARD::IsElementVisible(), EDA_ITEM::IsMoving(), EDA_ITEM::IsNew(), LAYER_RATSNEST, BOARD::m_Status_Pcb, RATSNEST_ITEM_LOCAL_OK, EDA_DRAW_PANEL::Refresh(), PCB_BASE_FRAME::Rotate_Module(), s_ModuleInitialCopy, PCB_BASE_FRAME::SetCurItem(), EDA_DRAW_PANEL::SetMouseCapture(), and EDA_ITEM::SetState().

Referenced by PCB_EDIT_FRAME::StartMoveModule().

162 {
163  TRACK* pt_segm;
164  MODULE* module;
165  PCB_EDIT_FRAME* pcbframe = (PCB_EDIT_FRAME*) Panel->GetParent();
166 
167  module = (MODULE*) pcbframe->GetScreen()->GetCurItem();
169  Panel->SetMouseCapture( NULL, NULL );
170 
171  if( module )
172  {
173  // Erase the current footprint on screen
174  module->DrawOutlinesWhenMoving( Panel, DC, g_Offset_Module );
175 
176  /* If a move command: return to old position
177  * If a copy command, delete the new footprint
178  */
179  if( module->IsMoving() )
180  {
181  /* Restore old position for dragged tracks */
182  for( unsigned ii = 0; ii < g_DragSegmentList.size(); ii++ )
183  {
184  pt_segm = g_DragSegmentList[ii].m_Track;
185  pt_segm->Draw( Panel, DC, GR_XOR );
186  pt_segm->SetState( IN_EDIT, false );
187  pt_segm->ClearFlags();
188  g_DragSegmentList[ii].RestoreInitialValues();
189  pt_segm->Draw( Panel, DC, GR_OR );
190  }
191 
192  EraseDragList();
193  module->ClearFlags( IS_MOVED );
194  }
195 
196  if( module->IsNew() ) // Copy command: delete new footprint
197  {
198  module->DeleteStructure();
199  module = NULL;
200  pcbframe->GetBoard()->m_Status_Pcb = 0;
201  pcbframe->GetBoard()->BuildListOfNets();
202  }
203  }
204 
205  /* Redraw the module. */
206  if( module && s_ModuleInitialCopy )
207  {
209  pcbframe->Rotate_Module( NULL, module, s_ModuleInitialCopy->GetOrientation(), false );
210 
211  if( s_ModuleInitialCopy->GetLayer() != module->GetLayer() )
212  pcbframe->Change_Side_Module( module, NULL );
213 
214  module->Draw( Panel, DC, GR_OR );
215  }
216 
217  pcbframe->SetCurItem( NULL );
218 
219  delete s_ModuleInitialCopy;
220  s_ModuleInitialCopy = NULL;
222 
223  // Display ratsnest is allowed
225 
226  if( pcbframe->GetBoard()->IsElementVisible( LAYER_RATSNEST ) )
227  pcbframe->DrawGeneralRatsnest( DC );
228 
229 #ifdef __WXMAC__
230  Panel->Refresh();
231 #endif
232 }
void BuildListOfNets()
Definition: class_board.h:764
static PICKED_ITEMS_LIST s_PickedList
Definition: modules.cpp:54
wxPoint g_Offset_Module
Definition: pcbnew.cpp:83
bool IsElementVisible(GAL_LAYER_ID LAYER_aPCB) const
Function IsElementVisible tests whether a given element category is visible.
bool IsMoving() const
Definition: base_struct.h:218
#define IN_EDIT
Item currently edited.
Definition: base_struct.h:111
virtual void Refresh(bool eraseBackground=true, const wxRect *rect=NULL) override
Definition: draw_panel.cpp:326
bool IsNew() const
Definition: base_struct.h:216
void Draw(EDA_DRAW_PANEL *aPanel, wxDC *aDC, GR_DRAWMODE aDrawMode, const wxPoint &aOffset=ZeroOffset) override
Function Draw draws the footprint to the aDC.
void SetCurItem(BOARD_ITEM *aItem, bool aDisplayInfo=true)
Function SetCurItem sets the currently selected item and displays it in the MsgPanel.
void EraseDragList()
Function EraseDragList clear the .m_Flags of all track segments stored in g_DragSegmentList and clear...
Definition: dragsegm.cpp:309
void DeleteStructure()
Function DeleteStructure deletes this object after UnLink()ing it from its owner if it has one...
BOARD * GetBoard() const
void Rotate_Module(wxDC *DC, MODULE *module, double angle, bool incremental)
Definition: modules.cpp:430
std::vector< DRAG_SEGM_PICKER > g_DragSegmentList
Definition: dragsegm.cpp:48
BOARD_ITEM * GetCurItem() const
Function GetCurItem returns the currently selected BOARD_ITEM, overriding BASE_SCREEN::GetCurItem().
static MODULE * s_ModuleInitialCopy
Definition: modules.cpp:51
double GetOrientation() const
Definition: class_module.h:147
void DrawGeneralRatsnest(wxDC *aDC, int aNetcode=0)
function Displays the general ratsnest Only ratsnest with the status bit CH_VISIBLE is set are displa...
Definition: ratsnest.cpp:300
EDA_DRAW_FRAME * GetParent() const
Definition: draw_panel.cpp:175
Definition: gr_basic.h:42
void Draw(EDA_DRAW_PANEL *panel, wxDC *DC, GR_DRAWMODE aDrawMode, const wxPoint &aOffset=ZeroOffset) override
Function Draw BOARD_ITEMs have their own color information.
PCB_LAYER_ID GetLayer() const
Function GetLayer returns the primary layer this item is on.
void SetState(int type, int state)
Definition: base_struct.h:242
PCB_SCREEN * GetScreen() const override
Function GetScreen returns a pointer to a BASE_SCREEN or one of its derivatives.
void ClearFlags(STATUS_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: base_struct.h:254
void DrawOutlinesWhenMoving(EDA_DRAW_PANEL *aPanel, wxDC *aDC, const wxPoint &aMoveVector)
Function DrawOutlinesWhenMoving draws in XOR mode the footprint when moving it to the aDC...
Definition: modules.cpp:492
void Change_Side_Module(MODULE *Module, wxDC *DC)
Function Change_Side_Module Flip a footprint (switch layer from component or component to copper) The...
Definition: modules.cpp:285
void SetMouseCapture(MOUSE_CAPTURE_CALLBACK aMouseCaptureCallback, END_MOUSE_CAPTURE_CALLBACK aEndMouseCaptureCallback)
Function SetMouseCapture sets the mouse capture and end mouse capture callbacks to aMouseCaptureCallb...
void ClearListAndDeleteItems()
Function ClearListAndDeleteItems deletes the list of pickers, AND the data pointed by m_PickedItem or...
int m_Status_Pcb
Flags used in ratsnest calculation and update.
Definition: class_board.h:240
#define IS_MOVED
Item being moved.
Definition: base_struct.h:112
void MoveFootprint ( EDA_DRAW_PANEL aPanel,
wxDC *  aDC,
const wxPoint aPosition,
bool  aErase 
)
static

Definition at line 237 of file modules.cpp.

References MODULE::DrawOutlinesWhenMoving(), DrawSegmentWhileMovingFootprint(), g_Offset_Module, EDA_DRAW_FRAME::GetCrossHairPosition(), BASE_SCREEN::GetCurItem(), EDA_DRAW_PANEL::GetParent(), MODULE::GetPosition(), and EDA_DRAW_PANEL::GetScreen().

Referenced by PCB_EDIT_FRAME::StartMoveModule().

238 {
239  MODULE* module = (MODULE*) aPanel->GetScreen()->GetCurItem();
240 
241  if( module == NULL )
242  return;
243 
244  /* Erase current footprint. */
245  if( aErase )
246  {
247  module->DrawOutlinesWhenMoving( aPanel, aDC, g_Offset_Module );
248  }
249 
250  /* Redraw the module at the new position. */
251  g_Offset_Module = module->GetPosition() - aPanel->GetParent()->GetCrossHairPosition();
252  module->DrawOutlinesWhenMoving( aPanel, aDC, g_Offset_Module );
253 
254  DrawSegmentWhileMovingFootprint( aPanel, aDC );
255 }
wxPoint g_Offset_Module
Definition: pcbnew.cpp:83
void DrawSegmentWhileMovingFootprint(EDA_DRAW_PANEL *panel, wxDC *DC)
Definition: dragsegm.cpp:294
EDA_ITEM * GetCurItem() const
const wxPoint & GetPosition() const override
Definition: class_module.h:143
EDA_DRAW_FRAME * GetParent() const
Definition: draw_panel.cpp:175
BASE_SCREEN * GetScreen()
Definition: draw_panel.cpp:188
void DrawOutlinesWhenMoving(EDA_DRAW_PANEL *aPanel, wxDC *aDC, const wxPoint &aMoveVector)
Function DrawOutlinesWhenMoving draws in XOR mode the footprint when moving it to the aDC...
Definition: modules.cpp:492
wxPoint GetCrossHairPosition(bool aInvertY=false) const
Function GetCrossHairPosition return the current cross hair position in logical (drawing) coordinates...

Variable Documentation

MODULE* s_ModuleInitialCopy = NULL
static
PICKED_ITEMS_LIST s_PickedList
static

Definition at line 54 of file modules.cpp.