busentry.cpp 5.24 KB
Newer Older
1 2 3
/*****************************************************/
/* Code to handle manipulation on bus entry objects. */
/*****************************************************/
plyatov's avatar
plyatov committed
4 5 6 7

#include "fctsys.h"
#include "gr_basic.h"
#include "common.h"
8
#include "class_drawpanel.h"
9
#include "eeschema_id.h"
10 11
#include "confirm.h"

plyatov's avatar
plyatov committed
12 13 14 15
#include "program.h"
#include "general.h"
#include "protos.h"

16
static int     s_LastShape = '\\';
plyatov's avatar
plyatov committed
17 18 19
static wxPoint ItemInitialPosition;

/**************************************************************/
20
static void ExitBusEntry( WinEDA_DrawPanel* Panel, wxDC* DC )
plyatov's avatar
plyatov committed
21
{
22 23
/**************************************************************/
/* Exit bus entry mode. */
24 25 26
    DrawBusEntryStruct* BusEntry =
        (DrawBusEntryStruct*) Panel->GetScreen()->GetCurItem();

27
    if( BusEntry )
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
    {
        RedrawOneStruct( Panel, DC, BusEntry, g_XorMode );
        if( BusEntry->m_Flags & IS_NEW )
        {
            delete BusEntry;
            Panel->GetScreen()->SetCurItem( NULL );
        }
        else
        {
            BusEntry->m_Pos = ItemInitialPosition;
            RedrawOneStruct( Panel, DC, BusEntry, GR_DEFAULT_DRAWMODE );
            BusEntry->m_Flags = 0;
        }
    }

    g_ItemToRepeat = NULL;
    Panel->ManageCurseur = NULL;
    Panel->ForceCloseManageCurseur = NULL;
plyatov's avatar
plyatov committed
46 47
}

48

plyatov's avatar
plyatov committed
49
/************************************************************************/
50
static void ShowWhileMoving( WinEDA_DrawPanel* panel, wxDC* DC, bool erase )
plyatov's avatar
plyatov committed
51
{
52 53
/************************************************************************/
/*  Drawing of the bus entry segment" while moving the cursor. */
54
    BASE_SCREEN*        screen   = panel->GetScreen();
55 56 57 58 59
    DrawBusEntryStruct* BusEntry = (DrawBusEntryStruct*) screen->GetCurItem();

    if( BusEntry == NULL )
        return;

60
    /* Erase the last segment position. */
61 62 63
    if( erase )
        RedrawOneStruct( panel, DC, BusEntry, g_XorMode );

64
    /* Redraw at the new position. */
65 66
    BusEntry->m_Pos = screen->m_Curseur;
    RedrawOneStruct( panel, DC, BusEntry, g_XorMode );
plyatov's avatar
plyatov committed
67 68
}

69

plyatov's avatar
plyatov committed
70
/**********************************************************************************/
71 72 73
DrawBusEntryStruct* WinEDA_SchematicFrame::CreateBusEntry( wxDC* DC,
                                                           int   entry_type )
{
plyatov's avatar
plyatov committed
74 75
/**********************************************************************************/
/* Create a new bus entry, and prepare moving function (for later place it)
76
 */
77 78 79 80
    DrawBusEntryStruct* BusEntry = new DrawBusEntryStruct(
        GetScreen()->m_Curseur,
        s_LastShape,
        entry_type );
plyatov's avatar
plyatov committed
81

82
    BusEntry->m_Flags = IS_NEW;
plyatov's avatar
plyatov committed
83

84 85 86
    DrawPanel->CursorOff( DC );     // Erase schematic cursor
    RedrawOneStruct( DrawPanel, DC, BusEntry, g_XorMode );
    DrawPanel->CursorOn( DC );      // Display schematic cursor
plyatov's avatar
plyatov committed
87

88 89 90 91
    GetScreen()->SetModify();

    StartMoveBusEntry( BusEntry, DC );
    return BusEntry;
plyatov's avatar
plyatov committed
92 93 94 95
}


/**************************************************************************/
96 97
void WinEDA_SchematicFrame::StartMoveBusEntry( DrawBusEntryStruct* BusEntry,
                                               wxDC*               DC )
plyatov's avatar
plyatov committed
98
{
99
/**************************************************************************/
100 101 102
    if( BusEntry == NULL )
        return;

103 104
    if( (BusEntry->m_Flags & IS_NEW) == 0 )    // => not already in edit, save
                                               // shape */
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
    {
        delete g_ItemToUndoCopy;
        g_ItemToUndoCopy = BusEntry->GenCopy();
    }

    BusEntry->m_Flags |= IS_MOVED;

    ItemInitialPosition = BusEntry->m_Pos;

    DrawPanel->CursorOff( DC );
    GetScreen()->m_Curseur = BusEntry->m_Pos;
    DrawPanel->MouseToCursorSchema();

    GetScreen()->SetCurItem( BusEntry );
    DrawPanel->ManageCurseur = ShowWhileMoving;
    DrawPanel->ForceCloseManageCurseur = ExitBusEntry;

    DrawPanel->CursorOn( DC );
plyatov's avatar
plyatov committed
123 124 125 126
}


/************************************************************/
127 128 129 130
void WinEDA_SchematicFrame::SetBusEntryShape( wxDC*               DC,
                                              DrawBusEntryStruct* BusEntry,
                                              int                 entry_shape )
{
131 132
/************************************************************/
/* set the shape of BusEntry (shape = / or \ )
133 134 135 136
 */
    if( BusEntry == NULL )
        return;

137
    if( BusEntry->Type() != DRAW_BUSENTRY_STRUCT_TYPE )
138 139 140 141 142 143 144
    {
        DisplayError( this, wxT( "SetBusEntryType: Bad StructType" ) );
        return;
    }

    /* Put old item in undo list if it is not currently in edit */
    if( BusEntry->m_Flags == 0 )
145
        SaveCopyInUndoList( BusEntry, UR_CHANGED );
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164

    RedrawOneStruct( DrawPanel, DC, BusEntry, g_XorMode );

    switch( entry_shape )
    {
    case '\\':
        s_LastShape = '\\';
        BusEntry->m_Size.y = 100;
        break;

    case '/':
        s_LastShape = '/';
        BusEntry->m_Size.y = -100;
        break;
    }

    TestDanglingEnds( GetScreen()->EEDrawList, NULL );
    RedrawOneStruct( DrawPanel, DC, BusEntry, g_XorMode );
    GetScreen()->SetModify();
plyatov's avatar
plyatov committed
165 166 167 168
}


/************************************************************************/
169
int WinEDA_SchematicFrame::GetBusEntryShape( DrawBusEntryStruct* BusEntry )
plyatov's avatar
plyatov committed
170
{
171
/************************************************************************/
172
    int entry_shape = '\\';
plyatov's avatar
plyatov committed
173

174 175 176
    if( BusEntry->m_Size.y < 0 )
        entry_shape = '/';
    return entry_shape;
plyatov's avatar
plyatov committed
177
}