libedit_onleftclick.cpp 6.76 KB
Newer Older
1
/*****************************************/
2
/*  EESchema - libedit_onleftclick.cpp  */
3
/*****************************************/
plyatov's avatar
plyatov committed
4 5

/* Library editor commands created by a mouse left button simple or double click
6
 */
plyatov's avatar
plyatov committed
7 8 9 10

#include "fctsys.h"
#include "gr_basic.h"
#include "common.h"
11 12
#include "class_drawpanel.h"
#include "confirm.h"
13
#include "eeschema_id.h"
14

plyatov's avatar
plyatov committed
15 16 17
#include "program.h"
#include "general.h"
#include "protos.h"
18
#include "libeditfrm.h"
19
#include "class_libentry.h"
plyatov's avatar
plyatov committed
20 21


22
void WinEDA_LibeditFrame::OnLeftClick( wxDC* DC, const wxPoint& MousePos )
plyatov's avatar
plyatov committed
23
{
24
    LIB_DRAW_ITEM* DrawEntry = m_drawItem;
25

26
    if( m_component == NULL )   // No component loaded !
27 28 29 30 31 32
        return;

    if( m_ID_current_state == 0 )
    {
        if( DrawEntry && DrawEntry->m_Flags )
        {
33
            SaveCopyInUndoList( m_component );
34 35 36 37

            switch( DrawEntry->Type() )
            {
            case COMPONENT_FIELD_DRAW_TYPE:
38
                PlaceField( DC, (LIB_FIELD*) DrawEntry );
39 40 41 42 43 44 45 46 47 48
                DrawEntry = NULL;
                break;

            default:
                EndDrawGraphicItem( DC );
                break;
            }
        }
        else
        {
49 50 51
            DrawEntry =
                m_component->LocateDrawItem( m_unit, m_convert, TYPE_NOT_INIT,
                                             GetScreen()->m_MousePosition );
52 53 54

            if( DrawEntry == NULL )
            {
55 56 57 58
                DrawEntry =
                    m_component->LocateDrawItem( m_unit, m_convert,
                                                 TYPE_NOT_INIT,
                                                 GetScreen()->m_Curseur );
59 60 61
            }

            if( DrawEntry )
62
                DrawEntry->DisplayInfo( this );
63 64

            else
65
                DisplayCmpDoc();
66 67 68 69 70 71 72 73 74 75 76
        }
    }

    if( m_ID_current_state )
    {
        switch( m_ID_current_state )
        {
        case ID_NO_SELECT_BUTT:
            break;

        case ID_LIBEDIT_PIN_BUTT:
77
            if( m_drawItem == NULL || m_drawItem->m_Flags == 0 )
78 79 80 81 82
            {
                CreatePin( DC );
            }
            else
            {
83
                SaveCopyInUndoList( m_component );
84 85 86 87 88 89 90 91 92
                PlacePin( DC );
            }
            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:
93
            if( m_drawItem == NULL || m_drawItem->m_Flags == 0 )
94
            {
95
                m_drawItem = CreateGraphicItem( m_component, DC );
96
            }
97
            else if( m_drawItem )
98
            {
99
                if( m_drawItem->m_Flags & IS_NEW )
100 101 102
                    GraphicItemBeginDraw( DC );
                else
                {
103
                    SaveCopyInUndoList( m_component );
104 105 106 107 108 109
                    EndDrawGraphicItem( DC );
                }
            }
            break;

        case ID_LIBEDIT_DELETE_ITEM_BUTT:
110 111 112
            DrawEntry =
                m_component->LocateDrawItem( m_unit, m_convert, TYPE_NOT_INIT,
                                             GetScreen()->m_MousePosition );
113 114 115

            if( DrawEntry == NULL )
            {
116 117 118 119
                DrawEntry =
                    m_component->LocateDrawItem( m_unit, m_convert,
                                                 TYPE_NOT_INIT,
                                                 GetScreen()->m_Curseur );
120 121
            }
            if( DrawEntry == NULL )
122
            {
123
                DisplayCmpDoc();
124 125
                break;
            }
126
            SaveCopyInUndoList( m_component );
127
            if( DrawEntry->Type() == COMPONENT_PIN_DRAW_TYPE )
128
                DeletePin( DC, m_component, (LIB_PIN*) DrawEntry );
129
            else
130
                m_component->RemoveDrawItem( DrawEntry, DrawPanel, DC );
131
            DrawEntry = NULL;
132
            GetScreen()->SetModify();
133 134 135
            break;

        case ID_LIBEDIT_ANCHOR_ITEM_BUTT:
136
            SaveCopyInUndoList( m_component );
137 138 139 140 141 142
            PlaceAncre();
            SetToolID( 0, wxCURSOR_ARROW, wxEmptyString );
            break;


        default:
143 144
            DisplayError( this,
                          wxT( "WinEDA_LibeditFrame::OnLeftClick error" ) );
145 146 147 148
            SetToolID( 0, wxCURSOR_ARROW, wxEmptyString );
            break;
        }
    }
plyatov's avatar
plyatov committed
149 150 151
}


152 153
/*
 * Called on a double click:
154 155
 *  If an editable item  (field, pin, graphic):
 *      Call the suitable dialog editor.
156
 */
157
void WinEDA_LibeditFrame::OnLeftDClick( wxDC* DC, const wxPoint& MousePos )
plyatov's avatar
plyatov committed
158
{
159 160
    wxPoint        pos = GetPosition();
    LIB_DRAW_ITEM* DrawEntry = m_drawItem;
161

162
    if( m_component == NULL )
163 164
        return;

165
    if( ( DrawEntry == NULL ) || ( DrawEntry->m_Flags == 0 ) )
166
    {   // We can locate an item
167 168 169
        DrawEntry = m_drawItem =
            m_component->LocateDrawItem( m_unit, m_convert, TYPE_NOT_INIT,
                                         GetScreen()->m_MousePosition );
170 171
        if( DrawEntry == NULL )
        {
172
            DrawEntry = m_drawItem =
173 174
                m_component->LocateDrawItem( m_unit, m_convert, TYPE_NOT_INIT,
                                             GetScreen()->m_Curseur );
175 176 177
        }
        if( DrawEntry == NULL )
        {
178
            EditComponentProperties();
179 180 181 182
        }
    }

    if( DrawEntry )
183
        DrawEntry->DisplayInfo( this );
184 185 186
    else
        return;

187
    m_drawItem = DrawEntry;
188 189 190 191 192

    DrawPanel->m_IgnoreMouseEvents = TRUE;

    switch( DrawEntry->Type() )
    {
193
    case COMPONENT_PIN_DRAW_TYPE:
194
        if( DrawEntry->m_Flags == 0 )
195
        {
196 197 198
            wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED );
            cmd.SetId( ID_LIBEDIT_EDIT_PIN );
            GetEventHandler()->ProcessEvent( cmd );
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232
        }
        break;

    case COMPONENT_ARC_DRAW_TYPE:
    case COMPONENT_CIRCLE_DRAW_TYPE:
    case COMPONENT_RECT_DRAW_TYPE:
        if( DrawEntry->m_Flags == 0 )
        {
            EditGraphicSymbol( DC, DrawEntry );
        }
        break;

    case COMPONENT_LINE_DRAW_TYPE:
    case COMPONENT_POLYLINE_DRAW_TYPE:
        if( DrawEntry->m_Flags == 0 )
        {
            EditGraphicSymbol( DC, DrawEntry );
        }
        else if( DrawEntry->m_Flags & IS_NEW )
        {
            EndDrawGraphicItem( DC );
        }
        break;

    case COMPONENT_GRAPHIC_TEXT_DRAW_TYPE:
        if( DrawEntry->m_Flags == 0 )
        {
            EditSymbolText( DC, DrawEntry );
        }
        break;

    case COMPONENT_FIELD_DRAW_TYPE:
        if( DrawEntry->m_Flags == 0 )
        {
233
            EditField( DC, (LIB_FIELD*) DrawEntry );
234 235 236 237 238 239
        }
        break;


    default:
        wxString msg;
240 241 242
        msg.Printf( wxT( "WinEDA_LibeditFrame::OnLeftDClick Error: unknown \
StructType %d" ),
                    DrawEntry->Type() );
243 244 245 246 247 248
        DisplayError( this, msg );
        break;
    }

    DrawPanel->MouseToCursorSchema();
    DrawPanel->m_IgnoreMouseEvents = FALSE;
plyatov's avatar
plyatov committed
249
}