KiCad PCB EDA Suite
events_called_functions_for_edit.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) 2010 Jean-Pierre Charras, jp.charras at wanadoo.fr
5  * Copyright (C) 2014 KiCad Developers, see CHANGELOG.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 
25 /*
26  * @file events_called_functions.cpp
27  */
28 
29 #include <fctsys.h>
30 #include <gr_basic.h>
31 #include <sch_draw_panel.h>
32 #include <general.h>
33 #include <kicad_device_context.h>
34 #include <sch_edit_frame.h>
35 #include <sch_component.h>
36 #include <sch_text.h>
37 #include <view/view_controls.h>
38 
39 
40 void SCH_EDIT_FRAME::OnCopySchematicItemRequest( wxCommandEvent& event )
41 {
42  SCH_ITEM * curr_item = GetScreen()->GetCurItem();
43 
44  if( !curr_item || curr_item->GetFlags() )
45  return;
46 
48 
49  switch( curr_item->Type() )
50  {
51  case SCH_COMPONENT_T:
52  {
53  SCH_COMPONENT* newitem;
54  newitem = new SCH_COMPONENT( *( (SCH_COMPONENT*) curr_item ) );
55  newitem->SetTimeStamp( GetNewTimeStamp() );
56  newitem->ClearAnnotation( NULL );
57  newitem->SetFlags( IS_NEW );
58  // Draw the new part, MoveItem() expects it to be already on screen.
59  PrepareMoveItem( newitem );
60  }
61  break;
62 
63  case SCH_TEXT_T:
64  case SCH_LABEL_T:
65  case SCH_GLOBAL_LABEL_T:
67  {
68  SCH_TEXT* newitem = (SCH_TEXT*) curr_item->Clone();
69  newitem->SetFlags( IS_NEW );
70  // Draw the new item, MoveItem() expects it to be already on screen.
71  PrepareMoveItem( newitem );
72  }
73  break;
74 
75  default:
76  break;
77  }
78 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:201
void SetTimeStamp(timestamp_t aNewTimeStamp)
Change the time stamp to aNewTimeStamp and updates the reference path.
STATUS_FLAGS GetFlags() const
Definition: base_struct.h:258
virtual EDA_ITEM * Clone() const
Function Clone creates a duplicate of this item with linked list members set to NULL.
VIEW_CONTROLS class definition.
void OnCopySchematicItemRequest(wxCommandEvent &event)
Command event handler for duplicating the item at the current location.
virtual void SetCursorPosition(const VECTOR2D &aPosition, bool aWarpView=true)=0
Moves cursor to the requested position expressed in world coordinates.
#define IS_NEW
New item, just created.
Definition: base_struct.h:114
SCH_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
timestamp_t GetNewTimeStamp()
Definition: common.cpp:212
a helper to handle the real device context used in KiCad
void PrepareMoveItem(SCH_ITEM *aItem)
Start moving aItem using the mouse.
Definition: schedit.cpp:762
void SetFlags(STATUS_FLAGS aMask)
Definition: base_struct.h:256
SCH_ITEM * GetCurItem() const
Return the currently selected SCH_ITEM, overriding BASE_SCREEN::GetCurItem().
Definition: sch_screen.h:196
SCH_DRAW_PANEL * GetCanvas() const override
void ClearAnnotation(SCH_SHEET_PATH *aSheetPath)
Clear exiting component annotation.
Definition the SCH_COMPONENT class for Eeschema.
Class SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:69
KIGFX::VIEW_CONTROLS * GetViewControls() const
Function GetViewControls() Returns a pointer to the VIEW_CONTROLS instance used in the panel...
wxPoint GetCrossHairPosition(bool aInvertY=false) const
Return the current cross hair position in logical (drawing) coordinates.
Class SCH_ITEM is a base class for any item which can be embedded within the SCHEMATIC container clas...
Implementation of the label properties dialog.