summaryrefslogtreecommitdiff
path: root/eeschema/libedit_onleftclick.cpp
blob: 5ee53d96226e0042c2fbff2d6b5c8f92527bd97b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
/*
 * This program source code file is part of KiCad, a free EDA CAD application.
 *
 * Copyright (C) 2013 Jean-Pierre Charras, jp.charras at wanadoo.fr
 * Copyright (C) 2013 Wayne Stambaugh <stambaughw@verizon.net>
 * Copyright (C) 1992-2013 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 libedit_onleftclick.cpp
 * @brief Eeschema library editor event handler for a mouse left button single or double click.
 */

#include <fctsys.h>
#include <class_drawpanel.h>
#include <eeschema_id.h>
#include <msgpanel.h>

#include <general.h>
#include <libeditframe.h>
#include <class_libentry.h>


void LIB_EDIT_FRAME::OnLeftClick( wxDC* DC, const wxPoint& aPosition )
{
    LIB_ITEM*   item = m_drawItem;
    bool        item_in_edit = item && item->InEditMode();
    bool        no_item_edited = !item_in_edit;

    LIB_PART*      part = GetCurPart();

    if( !part )         // No component loaded !
        return;

    if( ( GetToolId() == ID_NO_TOOL_SELECTED ) && no_item_edited )
    {
        item = LocateItemUsingCursor( aPosition );

        if( item )
        {
            MSG_PANEL_ITEMS items;
            item->GetMsgPanelInfo( items );
            SetMsgPanel( items );
        }
        else
        {
            DisplayCmpDoc();

            if( m_canvas->GetAbortRequest() )
                m_canvas->SetAbortRequest( false );
        }
    }

    switch( GetToolId() )
    {
    case ID_NO_TOOL_SELECTED:
        // If an item is currently in edit, finish edit
        if( item_in_edit )
        {
            switch( item->Type() )
            {
            case LIB_PIN_T:
                PlacePin();
                break;

            default:
                EndDrawGraphicItem( DC );
                break;
            }
        }
        break;

    case ID_LIBEDIT_PIN_BUTT:
        if( no_item_edited )
            CreatePin( DC );
        else
            PlacePin();
        break;

    case ID_LIBEDIT_BODY_LINE_BUTT:
    case ID_LIBEDIT_BODY_ARC_BUTT:
    case ID_LIBEDIT_BODY_CIRCLE_BUTT:
    case ID_LIBEDIT_BODY_RECT_BUTT:
    case ID_LIBEDIT_BODY_TEXT_BUTT:
        if( no_item_edited )
            m_drawItem = CreateGraphicItem( part, DC );
        else if( m_drawItem )
        {
            if( m_drawItem->IsNew() )
                GraphicItemBeginDraw( DC );
            else
                EndDrawGraphicItem( DC );
        }
        break;

    case ID_LIBEDIT_DELETE_ITEM_BUTT:
        m_drawItem = LocateItemUsingCursor( aPosition );

        if( m_drawItem )
            deleteItem( DC );
        else
            DisplayCmpDoc();

        break;

    case ID_LIBEDIT_ANCHOR_ITEM_BUTT:
        SaveCopyInUndoList( part );
        PlaceAnchor();
        SetToolID( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor(), wxEmptyString );
        break;

    default:
        wxFAIL_MSG( wxString::Format( wxT( "Unhandled command ID %d" ), GetToolId() ) );
        SetToolID( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor(), wxEmptyString );
        break;
    }
}


/*
 * Called on a double click:
 *  If an editable item  (field, pin, graphic):
 *      Call the suitable dialog editor.
 */
void LIB_EDIT_FRAME::OnLeftDClick( wxDC* DC, const wxPoint& aPosition )
{
    LIB_PART*      part = GetCurPart();

    if( !part )
        return;

    if( !m_drawItem || !m_drawItem->InEditMode() )
    {   // We can locate an item
        m_drawItem = LocateItemUsingCursor( aPosition );

        if( m_drawItem == NULL )
        {
            wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED );

            cmd.SetId( ID_LIBEDIT_GET_FRAME_EDIT_PART );
            GetEventHandler()->ProcessEvent( cmd );
        }
    }

    if( m_drawItem )
        SetMsgPanel( m_drawItem );
    else
        return;

    m_canvas->SetIgnoreMouseEvents( true );
    bool not_edited = !m_drawItem->InEditMode();

    switch( m_drawItem->Type() )
    {
    case LIB_PIN_T:
        if( not_edited )
        {
            wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED );

            cmd.SetId( ID_LIBEDIT_EDIT_PIN );
            GetEventHandler()->ProcessEvent( cmd );
        }
        break;

    case LIB_ARC_T:
    case LIB_CIRCLE_T:
    case LIB_RECTANGLE_T:
        if( not_edited )
            EditGraphicSymbol( DC, m_drawItem );
        break;

    case LIB_POLYLINE_T:
        if( not_edited )
            EditGraphicSymbol( DC, m_drawItem );
        else if( m_drawItem->IsNew() )
            EndDrawGraphicItem( DC );
        break;

    case LIB_TEXT_T:
        if( not_edited )
            EditSymbolText( DC, m_drawItem );
        break;

    case LIB_FIELD_T:
        if( not_edited )
            EditField( (LIB_FIELD*) m_drawItem );
        break;

    default:
        wxFAIL_MSG( wxT( "Unhandled item <" ) + m_drawItem->GetClass() + wxT( ">" ) );
        break;
    }

    m_canvas->MoveCursorToCrossHair();
    m_canvas->SetIgnoreMouseEvents( false );
}