libedit_onleftclick.cpp 9.54 KB
Newer Older
1 2 3
/*****************************************/
/*	EESchema - libedit_onleftclick.cpp	*/
/*****************************************/
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 11 12 13 14 15 16 17 18 19 20 21 22

#include "fctsys.h"
#include "gr_basic.h"

#include "common.h"
#include "program.h"
#include "libcmp.h"
#include "general.h"

#include "bitmaps.h"
#include "protos.h"

#include "id.h"


/************************************************************************/
23
void WinEDA_LibeditFrame::OnLeftClick( wxDC* DC, const wxPoint& MousePos )
plyatov's avatar
plyatov committed
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
    LibEDA_BaseStruct* DrawEntry = CurrentDrawItem;

    if( CurrentLibEntry == NULL )
        return;

    if( m_ID_current_state == 0 )
    {
        if( DrawEntry && DrawEntry->m_Flags )
        {
            SaveCopyInUndoList( CurrentLibEntry );

            switch( DrawEntry->Type() )
            {
            case COMPONENT_PIN_DRAW_TYPE:
                PlacePin( DC );
                break;

            case COMPONENT_FIELD_DRAW_TYPE:
                PlaceField( DC, (LibDrawField*) DrawEntry );
                DrawEntry = NULL;
                break;

            default:
                EndDrawGraphicItem( DC );
                break;
            }
        }
        else
        {
            DrawEntry = LocatePin( m_CurrentScreen->m_MousePosition, CurrentLibEntry,
                                   CurrentUnit, CurrentConvert );
            if( DrawEntry == NULL )
            {
                DrawEntry = LocateDrawItem( GetScreen(), GetScreen()->m_MousePosition,
                                            CurrentLibEntry, CurrentUnit,
                                            CurrentConvert, LOCATE_ALL_DRAW_ITEM );
            }

            if( DrawEntry == NULL )
                DrawEntry = LocatePin( m_CurrentScreen->m_Curseur, CurrentLibEntry,
                                       CurrentUnit, CurrentConvert );
            if( DrawEntry == NULL )
            {
                DrawEntry = LocateDrawItem( GetScreen(), GetScreen()->m_Curseur,
                                            CurrentLibEntry, CurrentUnit,
                                            CurrentConvert, LOCATE_ALL_DRAW_ITEM );
            }

            if( DrawEntry )
                DrawEntry->Display_Infos_DrawEntry( this );

            else
            {
                EraseMsgBox();
                AfficheDoc( this, CurrentLibEntry->m_Doc.GetData(),
                           CurrentLibEntry->m_KeyWord.GetData() );
            }
        }
    }

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

        case ID_LIBEDIT_PIN_BUTT:
            if( CurrentDrawItem == NULL )
            {
                CreatePin( DC );
            }
            else
            {
                SaveCopyInUndoList( CurrentLibEntry );
                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:
            if( CurrentDrawItem == NULL )
            {
                CurrentDrawItem = CreateGraphicItem( DC );
            }
            else
            {
                if( CurrentDrawItem->m_Flags & IS_NEW )
                    GraphicItemBeginDraw( DC );
                else
                {
                    SaveCopyInUndoList( CurrentLibEntry );
                    EndDrawGraphicItem( DC );
                }
            }
            break;

        case ID_LIBEDIT_DELETE_ITEM_BUTT:
            DrawEntry = LocatePin( m_CurrentScreen->m_MousePosition, CurrentLibEntry,
                                   CurrentUnit, CurrentConvert );
            if( DrawEntry == NULL )
            {
                DrawEntry = LocateDrawItem( GetScreen(), m_CurrentScreen->m_MousePosition,
                                            CurrentLibEntry, CurrentUnit,
                                            CurrentConvert, LOCATE_ALL_DRAW_ITEM );
            }

            if( DrawEntry == NULL )
                DrawEntry = LocatePin( m_CurrentScreen->m_Curseur, CurrentLibEntry,
                                       CurrentUnit, CurrentConvert );
            if( DrawEntry == NULL )
            {
                DrawEntry = LocateDrawItem( GetScreen(), m_CurrentScreen->m_Curseur,
                                            CurrentLibEntry, CurrentUnit,
                                            CurrentConvert, LOCATE_ALL_DRAW_ITEM );
            }
            if( DrawEntry == NULL )
            {
                AfficheDoc( this, CurrentLibEntry->m_Doc.GetData(),
                           CurrentLibEntry->m_KeyWord.GetData() );
                break;
            }
            SaveCopyInUndoList( CurrentLibEntry );
            if( DrawEntry->Type() == COMPONENT_PIN_DRAW_TYPE )
                DeletePin( DC, CurrentLibEntry, (LibDrawPin*) DrawEntry );
            else
                DeleteOneLibraryDrawStruct( DrawPanel, DC, CurrentLibEntry, DrawEntry, TRUE );
            DrawEntry = NULL;
            m_CurrentScreen->SetModify();
            break;

        case ID_LIBEDIT_ANCHOR_ITEM_BUTT:
            SaveCopyInUndoList( CurrentLibEntry );
            PlaceAncre();
            SetToolID( 0, wxCURSOR_ARROW, wxEmptyString );
            break;


        default:
            DisplayError( this, wxT( "WinEDA_LibeditFrame::OnLeftClick error" ) );
            SetToolID( 0, wxCURSOR_ARROW, wxEmptyString );
            break;
        }
    }
plyatov's avatar
plyatov committed
173 174 175 176
}


/*************************************************************************/
177
void WinEDA_LibeditFrame::OnLeftDClick( wxDC* DC, const wxPoint& MousePos )
plyatov's avatar
plyatov committed
178
/*************************************************************************/
179

plyatov's avatar
plyatov committed
180
/* Appel sur un double click:
181 182 183 184 185
 *  pour un lment editable (textes, composant):
 *      appel de l'editeur correspondant.
 *  pour une connexion en cours:
 *      termine la connexion
 */
plyatov's avatar
plyatov committed
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 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302
    wxPoint            pos = GetPosition();
    LibEDA_BaseStruct* DrawEntry = CurrentDrawItem;

    if( CurrentLibEntry == NULL )
        return;

    if( !m_ID_current_state    // Simple localisation des elements
       || (DrawEntry == NULL) || (DrawEntry->m_Flags == 0) )
    {
        DrawEntry = LocatePin( m_CurrentScreen->m_MousePosition, CurrentLibEntry,
                               CurrentUnit, CurrentConvert );
        if( DrawEntry == NULL )
            DrawEntry = LocatePin( m_CurrentScreen->m_Curseur, CurrentLibEntry,
                                   CurrentUnit, CurrentConvert );
        if( DrawEntry == NULL )
        {
            DrawEntry = CurrentDrawItem = LocateDrawItem( (SCH_SCREEN*) m_CurrentScreen,
                                                         m_CurrentScreen->m_MousePosition,
                                                         CurrentLibEntry, CurrentUnit,
                                                         CurrentConvert,
                                                         LOCATE_ALL_DRAW_ITEM );
        }
        if( DrawEntry == NULL )
        {
            DrawEntry = CurrentDrawItem = LocateDrawItem( (SCH_SCREEN*) m_CurrentScreen,
                                                         m_CurrentScreen->m_Curseur,
                                                         CurrentLibEntry, CurrentUnit,
                                                         CurrentConvert,
                                                         LOCATE_ALL_DRAW_ITEM );
        }
        if( DrawEntry == NULL )
        {
            DrawEntry = CurrentDrawItem = (LibEDA_BaseStruct*)
                                          LocateField( CurrentLibEntry );
        }
        if( DrawEntry == NULL )
        {
            wxPoint mpos;
            wxGetMousePosition( &mpos.x, &mpos.y );
            InstallLibeditFrame( mpos );
        }
    }

    // Si Commande en cours: affichage commande d'annulation
    if( m_ID_current_state )
    {
    }
    else
    {
    }

    if( DrawEntry )
        DrawEntry->Display_Infos_DrawEntry( this );
    else
        return;

    CurrentDrawItem = DrawEntry;

    DrawPanel->m_IgnoreMouseEvents = TRUE;

    switch( DrawEntry->Type() )
    {
    case  COMPONENT_PIN_DRAW_TYPE:
        if( DrawEntry->m_Flags == 0 )       // Item localis et non en edition: placement commande move
        {
            InstallPineditFrame( this, DC, pos );
        }
        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 )
        {
            EditField( DC, (LibDrawField*) DrawEntry );
        }
        break;


    default:
        wxString msg;
        msg.Printf(
            wxT( "WinEDA_LibeditFrame::OnLeftDClick Error: unknown StructType %d" ),
            DrawEntry->Type() );
        DisplayError( this, msg );
        break;
    }

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