KiCad PCB EDA Suite
common/legacy_gal/block.cpp
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
5  * Copyright (C) 2004-2011 KiCad Developers, see change_log.txt for contributors.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
30 #include <fctsys.h>
31 #include <gr_basic.h>
32 #include <draw_frame.h>
33 #include <common.h>
34 #include <macros.h>
35 #include <base_struct.h>
36 #include <base_screen.h>
37 #include <class_drawpanel.h>
38 #include <confirm.h>
39 #include <block_commande.h>
40 
41 
43  EDA_RECT()
44 {
45  m_state = STATE_NO_BLOCK; // State (enum BLOCK_STATE_T) of block.
46  m_command = BLOCK_IDLE; // Type (enum BLOCK_COMMAND_T) of operation.
47  m_color = BROWN;
48  m_appendUndo = false; // Indicates at least one undo record has been saved and
49  // any additional undo records should be appended.
50 }
51 
52 
54 {
56 }
57 
58 
60 {
61  wxString msg;
62 
63  switch( m_command )
64  {
65  case BLOCK_IDLE:
66  break;
67 
68  case BLOCK_MOVE: // Move
69  case BLOCK_PRESELECT_MOVE: // Move with preselection list
70  case BLOCK_MOVE_EXACT:
71  msg = _( "Block Move" );
72  break;
73 
74  case BLOCK_DRAG: // Drag
75  msg = _( "Block Drag" );
76  break;
77 
78  case BLOCK_DRAG_ITEM: // Drag
79  msg = _( "Drag item" );
80  break;
81 
82  case BLOCK_DUPLICATE: // Duplicate
83  msg = _( "Block Duplicate" );
84  break;
85 
86  case BLOCK_DELETE: // Delete
87  msg = _( "Block Delete" );
88  break;
89 
90  case BLOCK_COPY: // Copy
91  msg = _( "Block Copy" );
92  break;
93 
94  case BLOCK_PASTE:
95  msg = _( "Block Paste" );
96  break;
97 
98  case BLOCK_ZOOM: // Window Zoom
99  msg = _( "Zoom to selection" );
100  break;
101 
102  case BLOCK_FLIP: // Flip
103  msg = _( "Block Flip" );
104  break;
105 
106  case BLOCK_ABORT:
107  break;
108 
109  default:
110  msg = wxT( "???" );
111  break;
112  }
113 
114  frame->DisplayToolMsg( msg );
115 }
116 
117 
118 void BLOCK_SELECTOR::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset,
119  GR_DRAWMODE aDrawMode, COLOR4D aColor )
120 {
121  if( !aDC )
122  return;
123 
124  int w = GetWidth();
125  int h = GetHeight();
126 
127  GRSetDrawMode( aDC, aDrawMode );
128 
129  if( w == 0 || h == 0 )
130  GRLine( aPanel->GetClipBox(), aDC, GetX() + aOffset.x, GetY() + aOffset.y,
131  GetRight() + aOffset.x, GetBottom() + aOffset.y, 0, aColor );
132  else
133  GRRect( aPanel->GetClipBox(), aDC, GetX() + aOffset.x, GetY() + aOffset.y,
134  GetRight() + aOffset.x, GetBottom() + aOffset.y, 0, aColor );
135 }
136 
137 
138 void BLOCK_SELECTOR::InitData( EDA_DRAW_PANEL* aPanel, const wxPoint& startpos )
139 {
141  SetOrigin( startpos );
142  SetSize( wxSize( 0, 0 ) );
145 }
146 
147 
149 {
151  m_appendUndo = false;
152 }
153 
154 
156 {
158  m_appendUndo = false;
159 }
160 
161 
163 {
164  m_items.PushItem( aItem );
165  m_appendUndo = false;
166 }
167 
168 
170 {
171  if( m_command != BLOCK_IDLE )
172  {
175  ClearItemsList();
176  }
177 }
178 
179 void AbortBlockCurrentCommand( EDA_DRAW_PANEL* aPanel, wxDC* aDC )
180 {
181  BASE_SCREEN* screen = aPanel->GetScreen();
182 
183  if( aPanel->IsMouseCaptured() ) // Erase current drawing on screen
184  {
185  aPanel->SetMouseCapture( NULL, NULL );
186  screen->SetCurItem( NULL );
187 
188  // Delete the picked wrapper if this is a picked list.
189  screen->m_BlockLocate.ClearItemsList();
190  }
191 
194  aPanel->GetParent()->HandleBlockEnd( aDC );
195 
197  aPanel->GetParent()->DisplayToolMsg( wxEmptyString );
198 
199  // ugly, but temporary
200  auto gal_panel = dynamic_cast<EDA_DRAW_PANEL_GAL*>( aPanel );
201 
202  if( gal_panel )
203  gal_panel->SetDefaultCursor();
204 }
virtual BASE_SCREEN * GetScreen()=0
void SetCurItem(EDA_ITEM *aItem)
Function SetCurItem sets the currently selected object, m_CurrentItem.
Definition: base_screen.h:231
BLOCK_SELECTOR m_BlockLocate
Block description for block commands.
Definition: base_screen.h:214
void GRSetDrawMode(wxDC *DC, GR_DRAWMODE draw_mode)
Definition: gr_basic.cpp:223
BLOCK_COMMAND_T m_command
void Draw(EDA_DRAW_PANEL *aPanel, wxDC *aDC, const wxPoint &aOffset, GR_DRAWMODE aDrawMode, COLOR4D aColor)
This file is part of the common library.
void AbortBlockCurrentCommand(EDA_DRAW_PANEL *aPanel, wxDC *aDC)
Function AbortBlockCurrentCommand cancels the current block operation.
void SetMessageBlock(EDA_DRAW_FRAME *frame)
Function SetMessageBlock Displays the type of block command in the status bar of the window...
int GetHeight() const
Definition: eda_rect.h:118
void SetOrigin(const wxPoint &pos)
Definition: eda_rect.h:124
void PushItem(const ITEM_PICKER &aItem)
Function PushItem pushes aItem to the top of the list.
virtual EDA_RECT * GetClipBox()
The base class for create windows for drawing purpose.
Definition: draw_frame.h:78
This file contains miscellaneous commonly used macros and functions.
void ClearItemsList()
Function ClearItemsList clear only the list of EDA_ITEM pointers, it does NOT delete the EDA_ITEM obj...
virtual EDA_DRAW_FRAME * GetParent() const =0
void SetState(BLOCK_STATE_T aState)
void GRRect(EDA_RECT *aClipBox, wxDC *aDC, int x1, int y1, int x2, int y2, COLOR4D aColor)
Definition: gr_basic.cpp:1003
void ClearListAndDeleteItems()
Function ClearListAndDeleteItems deletes only the list of EDA_ITEM * pointers, AND the data printed b...
GR_DRAWMODE
Drawmode. Compositing mode plus a flag or two.
Definition: gr_basic.h:37
Class BASE_SCREEN handles how to draw a screen (a board, a schematic ...)
Definition: base_screen.h:76
virtual 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 DrawAndSizingBlockOutlines(EDA_DRAW_PANEL *aPanel, wxDC *aDC, const wxPoint &aPosition, bool aErase)
Function DrawAndSizingBlockOutlines redraws the outlines of the block which shows the search area for...
int GetBottom() const
Definition: eda_rect.h:122
int GetRight() const
Definition: eda_rect.h:119
void GRLine(EDA_RECT *ClipBox, wxDC *DC, int x1, int y1, int x2, int y2, int width, COLOR4D Color, wxPenStyle aStyle)
Definition: gr_basic.cpp:285
virtual bool HandleBlockEnd(wxDC *DC)
Handle the "end" of a block command, i.e.
PICKED_ITEMS_LIST m_items
This file is part of the common library.
void SetSize(const wxSize &size)
Definition: eda_rect.h:126
BLOCK_STATE_T m_state
void DisplayToolMsg(const wxString &msg)
Class EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
int GetX() const
Definition: eda_rect.h:109
The common library.
int GetWidth() const
Definition: eda_rect.h:117
void ClearItemsList()
Function ClearItemsList deletes only the list of pickers, NOT the picked data itself.
int GetY() const
Definition: eda_rect.h:110
void InitData(EDA_DRAW_PANEL *Panel, const wxPoint &startpos)
Function InitData sets the initial values of a BLOCK_SELECTOR, before starting a block command...
Basic classes for most KiCad items.
BASE_SCREEN class implementation.
virtual void SetDefaultCursor()
void ClearListAndDeleteItems()
Function ClearListAndDeleteItems deletes the list of pickers, AND the data pointed by m_PickedItem or...
void SetCommand(BLOCK_COMMAND_T aCommand)
void Clear()
Function Clear clears the block selector by setting the command to idle, the state to no block...
void PushItem(ITEM_PICKER &aItem)
Function PushItem adds aItem to the list of items.
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39
Definition: colors.h:62