dialog_annotate.cpp 7.82 KB
Newer Older
1
/**
2
 * @file dialog_annotate.cpp
3
 * @brief Annotation dialog functions.
4 5 6
 */

/*
7
 * This program source code file is part of KiCad, a free EDA CAD application.
8
 *
9 10
 * Copyright (C) 1992-2012 jean-pierre Charras <jean-pierre.charras@ujf-grenoble.fr>
  * Copyright (C) 1992-2012 Kicad Developers, see change_log.txt for contributors.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
 *
 * 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
 */
29

30

31 32 33
#include <fctsys.h>
#include <wxEeschemaStruct.h>
#include <class_drawpanel.h>
34

35
#include <invoke_sch_dialog.h>
36
#include <dialog_annotate_base.h>
37
#include <kiface_i.h>
38

39 40 41 42
#define KEY_ANNOTATE_SORT_OPTION        wxT( "AnnotateSortOption" )
#define KEY_ANNOTATE_ALGO_OPTION        wxT( "AnnotateAlgoOption" )
#define KEY_ANNOTATE_AUTOCLOSE_OPTION   wxT( "AnnotateAutoCloseOption" )
#define KEY_ANNOTATE_USE_SILENTMODE     wxT( "AnnotateSilentMode" )
43 44


45
class wxConfigBase;
46 47 48 49 50 51 52 53 54 55 56 57 58


/**
 * Class DIALOG_ANNOTATE
 */
class DIALOG_ANNOTATE: public DIALOG_ANNOTATE_BASE
{
public:
    DIALOG_ANNOTATE( SCH_EDIT_FRAME* parent );


private:
    SCH_EDIT_FRAME* m_Parent;
59
    wxConfigBase*   m_Config;
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

    /// Initialises member variables
    void InitValues();
    void OnCancelClick( wxCommandEvent& event );
    void OnClearAnnotationCmpClick( wxCommandEvent& event );
    void OnApplyClick( wxCommandEvent& event );

    // User functions:
    bool GetLevel();
    bool GetResetItems();

    /**
     * Function GetSortOrder
     * @return 0 if annotation by X position,
     *         1 if annotation by Y position,
     *         2 if annotation by value
     */
    int GetSortOrder();

    /**
     * Function GetAnnotateAlgo
     * @return 0 if annotation using first not used Id value
     *         1 if annotation using first not used Id value inside sheet num * 100 to  sheet num * 100 + 99
     *         2 if annotation using first nhot used Id value inside sheet num * 1000 to  sheet num * 1000 + 999
     */
    int GetAnnotateAlgo();

    bool GetAnnotateAutoCloseOpt()
    {
        return m_cbAutoCloseDlg->GetValue();
    }

    bool GetAnnotateSilentMode()
    {
        return m_cbUseSilentMode->GetValue();
    }
};
97

98

99

100
DIALOG_ANNOTATE::DIALOG_ANNOTATE( SCH_EDIT_FRAME* parent )
101
    : DIALOG_ANNOTATE_BASE( parent )
102
{
103
    m_Parent = parent;
104

105 106
    InitValues();
    Layout();
107
    GetSizer()->SetSizeHints( this );
108 109 110
    Centre();
}

111

112
void DIALOG_ANNOTATE::InitValues()
113
{
114
    m_Config = Kiface().KifaceSettings();
115

116 117 118
    if( m_Config )
    {
        long option;
119 120

        m_Config->Read( KEY_ANNOTATE_SORT_OPTION, &option, 0l );
121 122
        switch( option )
        {
123 124 125 126 127 128 129 130 131 132 133 134 135
        default:
        case 0:
            m_rbSortBy_X_Position->SetValue( 1 );
            break;

        case 1:
            m_rbSortBy_Y_Position->SetValue( 1 );
            break;

        case 2:
            m_rbUseIncremental->SetValue( 1 );
            break;
        }
136

137
        m_Config->Read( KEY_ANNOTATE_ALGO_OPTION, &option, 0l );
138 139
        switch( option )
        {
140 141 142 143 144 145 146 147 148 149 150 151
        default:
        case 0:
            m_rbUseIncremental->SetValue( 1 );
            break;

        case 1:
            m_rbUseSheetNum->SetValue( 1 );
            break;

        case 2:
            m_rbStartSheetNumLarge->SetValue( 1 );
            break;
152
        }
153

154
        m_Config->Read( KEY_ANNOTATE_AUTOCLOSE_OPTION, &option, 0l );
155
        if( option )
156
            m_cbAutoCloseDlg->SetValue( 1 );
157

158
        m_Config->Read( KEY_ANNOTATE_USE_SILENTMODE, &option, 0l );
159
        if( option )
160
            m_cbUseSilentMode->SetValue( 1 );
161
    }
162

163 164
    annotate_down_right_bitmap->SetBitmap( KiBitmap( annotate_down_right_xpm ) );
    annotate_right_down_bitmap->SetBitmap( KiBitmap( annotate_right_down_xpm ) );
165 166

    m_btnApply->SetDefault();
167 168
}

169

170
void DIALOG_ANNOTATE::OnApplyClick( wxCommandEvent& event )
171
{
172 173
    int         response;
    wxString    message;
174

175
    if( m_Config )
176
    {
177 178 179 180
        m_Config->Write( KEY_ANNOTATE_SORT_OPTION, GetSortOrder() );
        m_Config->Write( KEY_ANNOTATE_ALGO_OPTION, GetAnnotateAlgo() );
        m_Config->Write( KEY_ANNOTATE_AUTOCLOSE_OPTION, GetAnnotateAutoCloseOpt() );
        m_Config->Write( KEY_ANNOTATE_USE_SILENTMODE, GetAnnotateSilentMode() );
181
    }
182

183 184 185 186
    // Display a message info in verbose mode,
    // or if a reset of the previous annotation is asked.
    bool promptUser = ! GetAnnotateSilentMode();

187
    if( GetResetItems() )
188
    {
189 190 191 192
        if( GetLevel() )
            message += _( "Clear and annotate all of the components on the entire schematic?" );
        else
            message += _( "Clear and annotate all of the components on the current sheet?" );
193 194
        promptUser = true;
    }
195
    else
196 197 198 199 200 201
    {
        if( GetLevel() )
            message += _( "Annotate only the unannotated components on the entire schematic?" );
        else
            message += _( "Annotate only the unannotated components on the current sheet?" );
    }
202

203
    message += _( "\n\nThis operation will change the current annotation and cannot be undone." );
204

205 206 207 208
    if( promptUser )
    {
        response = wxMessageBox( message, wxT( "" ), wxICON_EXCLAMATION | wxOK | wxCANCEL );

209
        if( response == wxCANCEL )
210 211
            return;
    }
212

213 214
    m_Parent->AnnotateComponents( GetLevel(), (ANNOTATE_ORDER_T) GetSortOrder(),
                                  (ANNOTATE_OPTION_T) GetAnnotateAlgo(),
215
                                  GetResetItems() , true );
216
    m_Parent->GetCanvas()->Refresh();
217

218
    m_btnClear->Enable();
219 220 221 222 223 224 225 226 227 228 229

    if( GetAnnotateAutoCloseOpt() )
    {
        if( IsModal() )
            EndModal( wxID_OK );
        else
        {
            SetReturnCode( wxID_OK );
            this->Show( false );
        }
    }
230
}
231

232

233
void DIALOG_ANNOTATE::OnClearAnnotationCmpClick( wxCommandEvent& event )
234
{
235 236
    int         response;
    wxString    message;
237 238

    if( GetLevel() )
239
        message = _( "Clear the existing annotation for the entire schematic?" );
240
    else
241
        message = _( "Clear the existing annotation for the current sheet?" );
242

243
    message += _( "\n\nThis operation will clear the existing annotation and cannot be undone." );
244 245
    response = wxMessageBox( message, wxT( "" ), wxICON_EXCLAMATION | wxOK | wxCANCEL );

246
    if( response == wxCANCEL )
247
        return;
248

249
    m_Parent->DeleteAnnotation( GetLevel() ? false : true );
250
    m_Parent->GetCanvas()->Refresh();
251

252
    m_btnClear->Enable( false );
253 254 255
}


256
void DIALOG_ANNOTATE::OnCancelClick( wxCommandEvent& event )
257 258 259 260 261 262 263 264 265 266
{
    if( IsModal() )
        EndModal( wxID_CANCEL );
    else
    {
        SetReturnCode( wxID_CANCEL );
        this->Show( false );
    }
}

267

268
bool DIALOG_ANNOTATE::GetLevel()
269
{
270
    return m_rbEntireSchematic->GetValue();
271 272
}

273 274

bool DIALOG_ANNOTATE::GetResetItems()
275
{
charras's avatar
charras committed
276
    return m_rbResetAnnotation->GetValue();
277 278
}

279 280

int DIALOG_ANNOTATE::GetSortOrder()
281
{
282
    if( m_rbSortBy_X_Position->GetValue() )
charras's avatar
charras committed
283
        return 0;
284 285

    if( m_rbSortBy_Y_Position->GetValue() )
286
        return 1;
287

288
    return 2;
289
}
290

291 292

int DIALOG_ANNOTATE::GetAnnotateAlgo()
293
{
294
    if( m_rbUseIncremental->GetValue() )
295
        return 0;
296 297

    if( m_rbUseSheetNum->GetValue() )
298
        return 1;
299

300 301
    return 2;
}
302 303 304 305 306 307 308 309 310


int InvokeDialogAnnotate( SCH_EDIT_FRAME* aCaller )
{
    DIALOG_ANNOTATE dlg( aCaller );

    return dlg.ShowModal();
}