block_commande.h 6.27 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
/*
 * This program source code file is part of KiCad, a free EDA CAD application.
 *
 * Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
 * Copyright (C) 2004-2011 KiCad Developers, see change_log.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
 */

25
/**
26
 * This file is part of the common library.
27 28 29 30 31
 * @file  block_commande.h
 * @see   common.h
 */

#ifndef __INCLUDE__BLOCK_COMMANDE_H__
32
#define __INCLUDE__BLOCK_COMMANDE_H__
33 34


35 36
#include <base_struct.h>
#include <class_undoredo_container.h>
37
#include <gr_basic.h>
38

39
/* Block state codes. */
40
typedef enum {
41 42 43 44 45
    STATE_NO_BLOCK,
    STATE_BLOCK_INIT,
    STATE_BLOCK_END,
    STATE_BLOCK_MOVE,
    STATE_BLOCK_STOP
46
} BLOCK_STATE_T;
47

48 49

/* Block command codes. */
50 51 52 53 54 55 56 57
typedef enum {
    BLOCK_IDLE,
    BLOCK_MOVE,
    BLOCK_COPY,
    BLOCK_SAVE,
    BLOCK_DELETE,
    BLOCK_PASTE,
    BLOCK_DRAG,
58 59
    BLOCK_DRAG_ITEM,    // like BLOCK_DRAG, when used to drag a selected component
                        // and not using an area defined by a mouse drag
60
    BLOCK_ROTATE,
61
    BLOCK_FLIP,
62 63 64
    BLOCK_ZOOM,
    BLOCK_ABORT,
    BLOCK_PRESELECT_MOVE,
65
    BLOCK_MOVE_EXACT,
66 67 68
    BLOCK_SELECT_ITEMS_ONLY,
    BLOCK_MIRROR_X,
    BLOCK_MIRROR_Y
69
} BLOCK_COMMAND_T;
70 71


72
class BLOCK_SELECTOR : public EDA_RECT
73
{
74 75 76 77 78 79 80 81
    BLOCK_STATE_T     m_state;                    //< State (enum BLOCK_STATE_T) of the block.
    BLOCK_COMMAND_T   m_command;                  //< Command (enum BLOCK_COMMAND_T) operation.
    PICKED_ITEMS_LIST m_items;                    //< List of items selected in this block.
    EDA_COLOR_T       m_color;                    //< Block Color (for drawings).
    wxPoint           m_moveVector;               //< Move distance to move the block.
    wxPoint           m_lastCursorPosition;       //< Last Mouse position in block command
                                                  //< last cursor position in move commands
                                                  //< 0,0 in paste command.
82 83 84 85 86

public:
    BLOCK_SELECTOR();
    ~BLOCK_SELECTOR();

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
    void SetState( BLOCK_STATE_T aState ) { m_state = aState; }

    BLOCK_STATE_T GetState() const { return m_state; }

    void SetCommand( BLOCK_COMMAND_T aCommand ) { m_command = aCommand; }

    BLOCK_COMMAND_T GetCommand() const { return m_command; }

    void SetColor( EDA_COLOR_T aColor ) { m_color = aColor; }

    EDA_COLOR_T GetColor() const { return m_color; }

    /**
     * Function SetLastCursorPosition
     * sets the last cursor position to \a aPosition.
     *
     * @param aPosition The current cursor position.
     */
    void SetLastCursorPosition( const wxPoint& aPosition ) { m_lastCursorPosition = aPosition; }

    wxPoint GetLastCursorPosition() const { return m_lastCursorPosition; }

    void SetMoveVector( const wxPoint& aMoveVector ) { m_moveVector = aMoveVector; }

    wxPoint GetMoveVector() const { return m_moveVector; }

113 114
    /**
     * Function InitData
Dick Hollenbeck's avatar
Dick Hollenbeck committed
115 116
     * sets the initial values of a BLOCK_SELECTOR, before starting a block
     * command
117
     */
118
    void InitData( EDA_DRAW_PANEL* Panel, const wxPoint& startpos );
119

120 121
    /**
     * Function SetMessageBlock
122
     * Displays the type of block command in the status bar of the window
123
     */
124
    void SetMessageBlock( EDA_DRAW_FRAME* frame );
125

126
    void Draw( EDA_DRAW_PANEL* aPanel,
127 128
               wxDC*           aDC,
               const wxPoint&  aOffset,
129
               GR_DRAWMODE     aDrawMode,
130
               EDA_COLOR_T     aColor );
131

132 133
    /**
     * Function PushItem
134
     * adds \a aItem to the list of items.
135 136
     * @param aItem = an ITEM_PICKER to add to the list
     */
137
    void PushItem( ITEM_PICKER& aItem );
138

139 140
    /**
     * Function ClearListAndDeleteItems
141
     * deletes only the list of EDA_ITEM * pointers, AND the data printed
142
     * by m_Item
143
     */
144 145
    void ClearListAndDeleteItems();

146 147 148 149 150
    /**
     * Function ClearItemsList
     * clear only the list of #EDA_ITEM pointers, it does _NOT_ delete the #EDA_ITEM object
     * itself
     */
151
    void ClearItemsList();
152

153
    unsigned GetCount() const
154
    {
155
        return m_items.GetCount();
156
    }
157

158 159 160
    PICKED_ITEMS_LIST& GetItems() { return m_items; }

    EDA_ITEM* GetItem( unsigned aIndex )
161
    {
162 163 164 165
        if( aIndex < m_items.GetCount() )
            return m_items.GetPickedItem( aIndex );

        return NULL;
166
    }
167 168 169 170 171

    /**
     * Function IsDragging
     * returns true if the current block command is a drag operation.
     */
172 173 174 175
    bool IsDragging() const
    {
        return m_command == BLOCK_DRAG || m_command == BLOCK_DRAG_ITEM;
    }
176 177 178 179 180

    /**
     * Function IsIdle
     * returns true if there is currently no block operation in progress.
     */
181
    inline bool IsIdle() const { return m_command == BLOCK_IDLE; }
182 183 184 185 186 187 188

    /**
     * Function Clear
     * clears the block selector by setting the command to idle, the state to no block,
     * and clears the selected item list.
     */
    void Clear();
189 190 191
};


192 193 194
/**
 * Function AbortBlockCurrentCommand
 * cancels the current block operation.
195
 */
196
void AbortBlockCurrentCommand( EDA_DRAW_PANEL* aPanel, wxDC* aDC );
197

198

199 200 201 202 203 204
/**
 * Function DrawAndSizingBlockOutlines
 * redraws the outlines of the block which shows the search area for block commands.
 *
 * The first point of the rectangle showing the area is initialized by InitBlockLocateDatas().
 * The other point of the rectangle is the mouse cursor position.
205
 */
206 207
void DrawAndSizingBlockOutlines( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition,
                                 bool aErase );
208 209 210


#endif /* __INCLUDE__BLOCK_COMMANDE_H__ */