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 <class_drawpanel.h>
32 #include <general.h>
33 #include <kicad_device_context.h>
34 #include <schframe.h>
35 #include <sch_component.h>
36 #include <sch_text.h>
37 
38 
39 void SCH_EDIT_FRAME::OnCopySchematicItemRequest( wxCommandEvent& event )
40 {
41  SCH_ITEM * curr_item = GetScreen()->GetCurItem();
42 
43  if( !curr_item || curr_item->GetFlags() )
44  return;
45 
47 
48  switch( curr_item->Type() )
49  {
50  case SCH_COMPONENT_T:
51  {
52  SCH_COMPONENT* newitem;
53  newitem = new SCH_COMPONENT( *( (SCH_COMPONENT*) curr_item ) );
54  newitem->SetTimeStamp( GetNewTimeStamp() );
55  newitem->ClearAnnotation( NULL );
56  newitem->SetFlags( IS_NEW );
57  // Draw the new part, MoveItem() expects it to be already on screen.
58  newitem->Draw( m_canvas, &dc, wxPoint( 0, 0 ), g_XorMode );
59  PrepareMoveItem( newitem, &dc );
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  newitem->Draw( m_canvas, &dc, wxPoint( 0, 0 ), g_XorMode );
72  PrepareMoveItem( newitem, &dc );
73  }
74  break;
75 
76  default:
77  break;
78  }
79 }
GR_DRAWMODE g_XorMode
Definition: gr_basic.cpp:51
KICAD_T Type() const
Function Type()
Definition: base_struct.h:198
STATUS_FLAGS GetFlags() const
Definition: base_struct.h:255
virtual void Draw(EDA_DRAW_PANEL *panel, wxDC *DC, const wxPoint &offset, GR_DRAWMODE draw_mode, COLOR4D Color=COLOR4D::UNSPECIFIED) override
Function Draw Draw a schematic item.
Definition: sch_text.cpp:344
virtual EDA_ITEM * Clone() const
Function Clone creates a duplicate of this item with linked list members set to NULL.
time_t GetNewTimeStamp()
Definition: common.cpp:166
void OnCopySchematicItemRequest(wxCommandEvent &event)
Function OnCopySchematicItemRequest is the command event handler for duplicating the item at the curr...
void PrepareMoveItem(SCH_ITEM *aItem, wxDC *aDC)
Function PrepareMoveItem start moving aItem using the mouse.
Definition: schedit.cpp:783
#define IS_NEW
New item, just created.
Definition: base_struct.h:113
SCH_SCREEN * GetScreen() const override
Function GetScreen returns a pointer to a BASE_SCREEN or one of its derivatives.
Definition: schframe.cpp:527
void SetTimeStamp(time_t aNewTimeStamp)
Change the time stamp to aNewTimeStamp and updates the reference path.
a helper to handle the real device context used in KiCad
void SetFlags(STATUS_FLAGS aMask)
Definition: base_struct.h:253
SCH_ITEM * GetCurItem() const
Function GetCurItem returns the currently selected SCH_ITEM, overriding BASE_SCREEN::GetCurItem().
void ClearAnnotation(SCH_SHEET_PATH *aSheetPath)
Clear exiting component annotation.
EDA_DRAW_PANEL * m_canvas
The area to draw on.
Definition: draw_frame.h:92
Definition the SCH_COMPONENT class for Eeschema.
#define INSTALL_UNBUFFERED_DC(name, parent)
void Draw(EDA_DRAW_PANEL *aPanel, wxDC *aDC, const wxPoint &aOffset, GR_DRAWMODE aDrawMode, COLOR4D aColor=COLOR4D::UNSPECIFIED) override
Function Draw Draw a schematic item.
Class SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:69
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.