2011-09-30 18:15:37 +00:00
|
|
|
/**
|
2013-06-13 16:09:35 +00:00
|
|
|
* @file dialog_annotate.cpp
|
2011-09-30 18:15:37 +00:00
|
|
|
* @brief Annotation dialog functions.
|
2011-01-04 20:27:52 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2011-09-30 18:15:37 +00:00
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
2011-01-04 20:27:52 +00:00
|
|
|
*
|
2012-08-21 10:45:54 +00:00
|
|
|
* 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.
|
2011-01-04 20:27:52 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2008-04-16 17:21:01 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <appl_wxstruct.h>
|
|
|
|
#include <wxEeschemaStruct.h>
|
|
|
|
#include <class_drawpanel.h>
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2013-06-10 12:24:01 +00:00
|
|
|
#include <invoke_sch_dialog.h>
|
2013-06-07 20:56:55 +00:00
|
|
|
#include <dialog_annotate_base.h>
|
|
|
|
|
|
|
|
|
|
|
|
#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" )
|
|
|
|
|
|
|
|
|
|
|
|
class wxConfig;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class DIALOG_ANNOTATE
|
|
|
|
*/
|
|
|
|
class DIALOG_ANNOTATE: public DIALOG_ANNOTATE_BASE
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
DIALOG_ANNOTATE( SCH_EDIT_FRAME* parent );
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
SCH_EDIT_FRAME* m_Parent;
|
|
|
|
wxConfig* m_Config;
|
|
|
|
|
|
|
|
/// 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();
|
|
|
|
}
|
|
|
|
};
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-10-27 19:30:32 +00:00
|
|
|
|
2008-04-16 17:21:01 +00:00
|
|
|
|
2010-12-08 20:12:46 +00:00
|
|
|
DIALOG_ANNOTATE::DIALOG_ANNOTATE( SCH_EDIT_FRAME* parent )
|
2009-10-27 19:30:32 +00:00
|
|
|
: DIALOG_ANNOTATE_BASE( parent )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2008-02-26 01:07:38 +00:00
|
|
|
m_Parent = parent;
|
2013-06-07 20:56:55 +00:00
|
|
|
|
2009-10-27 19:30:32 +00:00
|
|
|
InitValues();
|
|
|
|
Layout();
|
2013-06-07 20:56:55 +00:00
|
|
|
GetSizer()->SetSizeHints( this );
|
2007-06-05 12:10:51 +00:00
|
|
|
Centre();
|
|
|
|
}
|
|
|
|
|
2008-02-26 01:07:38 +00:00
|
|
|
|
2009-10-27 19:30:32 +00:00
|
|
|
void DIALOG_ANNOTATE::InitValues()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2011-12-16 20:12:49 +00:00
|
|
|
m_Config = wxGetApp().GetSettings();
|
2013-06-07 20:56:55 +00:00
|
|
|
|
2009-10-27 19:30:32 +00:00
|
|
|
if( m_Config )
|
|
|
|
{
|
|
|
|
long option;
|
2013-06-07 20:56:55 +00:00
|
|
|
|
|
|
|
m_Config->Read( KEY_ANNOTATE_SORT_OPTION, &option, 0l );
|
2009-10-27 19:30:32 +00:00
|
|
|
switch( option )
|
|
|
|
{
|
2013-06-07 20:56:55 +00:00
|
|
|
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;
|
|
|
|
}
|
2011-01-04 20:27:52 +00:00
|
|
|
|
2013-06-07 20:56:55 +00:00
|
|
|
m_Config->Read( KEY_ANNOTATE_ALGO_OPTION, &option, 0l );
|
2011-01-04 20:27:52 +00:00
|
|
|
switch( option )
|
|
|
|
{
|
2013-06-07 20:56:55 +00:00
|
|
|
default:
|
|
|
|
case 0:
|
|
|
|
m_rbUseIncremental->SetValue( 1 );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
m_rbUseSheetNum->SetValue( 1 );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
m_rbStartSheetNumLarge->SetValue( 1 );
|
|
|
|
break;
|
2009-10-27 19:30:32 +00:00
|
|
|
}
|
2012-08-21 10:45:54 +00:00
|
|
|
|
2013-06-07 20:56:55 +00:00
|
|
|
m_Config->Read( KEY_ANNOTATE_AUTOCLOSE_OPTION, &option, 0l );
|
2012-08-21 10:45:54 +00:00
|
|
|
if( option )
|
2013-06-07 20:56:55 +00:00
|
|
|
m_cbAutoCloseDlg->SetValue( 1 );
|
2012-08-21 10:45:54 +00:00
|
|
|
|
2013-06-07 20:56:55 +00:00
|
|
|
m_Config->Read( KEY_ANNOTATE_USE_SILENTMODE, &option, 0l );
|
2012-08-21 10:45:54 +00:00
|
|
|
if( option )
|
2013-06-07 20:56:55 +00:00
|
|
|
m_cbUseSilentMode->SetValue( 1 );
|
2009-10-27 19:30:32 +00:00
|
|
|
}
|
2008-04-30 11:52:34 +00:00
|
|
|
|
2011-09-08 05:58:45 +00:00
|
|
|
annotate_down_right_bitmap->SetBitmap( KiBitmap( annotate_down_right_xpm ) );
|
|
|
|
annotate_right_down_bitmap->SetBitmap( KiBitmap( annotate_right_down_xpm ) );
|
2010-11-11 21:10:27 +00:00
|
|
|
|
|
|
|
m_btnApply->SetDefault();
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2008-04-16 17:21:01 +00:00
|
|
|
|
2009-10-27 19:30:32 +00:00
|
|
|
void DIALOG_ANNOTATE::OnApplyClick( wxCommandEvent& event )
|
2008-02-26 01:07:38 +00:00
|
|
|
{
|
2013-06-07 20:56:55 +00:00
|
|
|
int response;
|
|
|
|
wxString message;
|
2008-02-26 01:07:38 +00:00
|
|
|
|
2009-10-27 19:30:32 +00:00
|
|
|
if( m_Config )
|
2011-01-04 20:27:52 +00:00
|
|
|
{
|
2013-06-07 20:56:55 +00:00
|
|
|
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() );
|
2011-01-04 20:27:52 +00:00
|
|
|
}
|
2009-10-27 19:30:32 +00:00
|
|
|
|
2012-08-21 10:45:54 +00:00
|
|
|
// Display a message info in verbose mode,
|
|
|
|
// or if a reset of the previous annotation is asked.
|
|
|
|
bool promptUser = ! GetAnnotateSilentMode();
|
|
|
|
|
2008-02-26 01:07:38 +00:00
|
|
|
if( GetResetItems() )
|
2012-08-21 10:45:54 +00:00
|
|
|
{
|
2013-04-09 17:49:01 +00:00
|
|
|
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?" );
|
2012-08-21 10:45:54 +00:00
|
|
|
promptUser = true;
|
|
|
|
}
|
2008-02-26 01:07:38 +00:00
|
|
|
else
|
2013-04-09 17:49:01 +00:00
|
|
|
{
|
|
|
|
if( GetLevel() )
|
|
|
|
message += _( "Annotate only the unannotated components on the entire schematic?" );
|
|
|
|
else
|
|
|
|
message += _( "Annotate only the unannotated components on the current sheet?" );
|
|
|
|
}
|
2008-02-26 01:07:38 +00:00
|
|
|
|
2009-05-21 17:42:42 +00:00
|
|
|
message += _( "\n\nThis operation will change the current annotation and cannot be undone." );
|
2011-12-22 13:28:11 +00:00
|
|
|
|
2012-08-21 10:45:54 +00:00
|
|
|
if( promptUser )
|
|
|
|
{
|
|
|
|
response = wxMessageBox( message, wxT( "" ), wxICON_EXCLAMATION | wxOK | wxCANCEL );
|
|
|
|
|
2013-06-07 20:56:55 +00:00
|
|
|
if( response == wxCANCEL )
|
2012-08-21 10:45:54 +00:00
|
|
|
return;
|
|
|
|
}
|
2011-01-04 20:27:52 +00:00
|
|
|
|
2011-05-20 19:21:09 +00:00
|
|
|
m_Parent->AnnotateComponents( GetLevel(), (ANNOTATE_ORDER_T) GetSortOrder(),
|
|
|
|
(ANNOTATE_OPTION_T) GetAnnotateAlgo(),
|
2011-01-04 20:27:52 +00:00
|
|
|
GetResetItems() , true );
|
2011-12-22 13:28:11 +00:00
|
|
|
m_Parent->GetCanvas()->Refresh();
|
2011-01-01 17:28:21 +00:00
|
|
|
|
2008-02-26 01:07:38 +00:00
|
|
|
m_btnClear->Enable();
|
2012-08-21 10:45:54 +00:00
|
|
|
|
|
|
|
if( GetAnnotateAutoCloseOpt() )
|
|
|
|
{
|
|
|
|
if( IsModal() )
|
|
|
|
EndModal( wxID_OK );
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SetReturnCode( wxID_OK );
|
|
|
|
this->Show( false );
|
|
|
|
}
|
|
|
|
}
|
2008-02-26 01:07:38 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2008-04-16 17:21:01 +00:00
|
|
|
|
2009-10-27 19:30:32 +00:00
|
|
|
void DIALOG_ANNOTATE::OnClearAnnotationCmpClick( wxCommandEvent& event )
|
2008-04-16 17:21:01 +00:00
|
|
|
{
|
2013-06-07 20:56:55 +00:00
|
|
|
int response;
|
|
|
|
wxString message;
|
2008-04-16 17:21:01 +00:00
|
|
|
|
|
|
|
if( GetLevel() )
|
2013-04-09 17:49:01 +00:00
|
|
|
message = _( "Clear the existing annotation for the entire schematic?" );
|
2008-04-16 17:21:01 +00:00
|
|
|
else
|
2013-04-09 17:49:01 +00:00
|
|
|
message = _( "Clear the existing annotation for the current sheet?" );
|
2008-04-16 17:21:01 +00:00
|
|
|
|
2009-05-21 17:42:42 +00:00
|
|
|
message += _( "\n\nThis operation will clear the existing annotation and cannot be undone." );
|
2011-12-22 13:28:11 +00:00
|
|
|
response = wxMessageBox( message, wxT( "" ), wxICON_EXCLAMATION | wxOK | wxCANCEL );
|
|
|
|
|
2013-06-07 20:56:55 +00:00
|
|
|
if( response == wxCANCEL )
|
2008-04-16 17:21:01 +00:00
|
|
|
return;
|
2011-12-22 13:28:11 +00:00
|
|
|
|
2011-01-01 17:28:21 +00:00
|
|
|
m_Parent->DeleteAnnotation( GetLevel() ? false : true );
|
2011-12-22 13:28:11 +00:00
|
|
|
m_Parent->GetCanvas()->Refresh();
|
2011-01-01 17:28:21 +00:00
|
|
|
|
2013-06-07 20:56:55 +00:00
|
|
|
m_btnClear->Enable( false );
|
2008-04-16 17:21:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-10-27 19:30:32 +00:00
|
|
|
void DIALOG_ANNOTATE::OnCancelClick( wxCommandEvent& event )
|
2008-02-27 19:38:16 +00:00
|
|
|
{
|
|
|
|
if( IsModal() )
|
|
|
|
EndModal( wxID_CANCEL );
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SetReturnCode( wxID_CANCEL );
|
|
|
|
this->Show( false );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-16 17:21:01 +00:00
|
|
|
|
2013-06-07 20:56:55 +00:00
|
|
|
bool DIALOG_ANNOTATE::GetLevel()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2008-02-26 01:07:38 +00:00
|
|
|
return m_rbEntireSchematic->GetValue();
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2013-06-07 20:56:55 +00:00
|
|
|
|
|
|
|
bool DIALOG_ANNOTATE::GetResetItems()
|
2008-02-26 01:07:38 +00:00
|
|
|
{
|
2008-04-21 14:03:20 +00:00
|
|
|
return m_rbResetAnnotation->GetValue();
|
2008-02-26 01:07:38 +00:00
|
|
|
}
|
|
|
|
|
2013-06-07 20:56:55 +00:00
|
|
|
|
|
|
|
int DIALOG_ANNOTATE::GetSortOrder()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2013-06-07 20:56:55 +00:00
|
|
|
if( m_rbSortBy_X_Position->GetValue() )
|
2008-04-21 14:03:20 +00:00
|
|
|
return 0;
|
2013-06-07 20:56:55 +00:00
|
|
|
|
|
|
|
if( m_rbSortBy_Y_Position->GetValue() )
|
2011-01-04 20:27:52 +00:00
|
|
|
return 1;
|
2013-06-07 20:56:55 +00:00
|
|
|
|
2011-01-04 20:27:52 +00:00
|
|
|
return 2;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
2008-04-16 17:21:01 +00:00
|
|
|
|
2013-06-07 20:56:55 +00:00
|
|
|
|
|
|
|
int DIALOG_ANNOTATE::GetAnnotateAlgo()
|
2011-01-04 20:27:52 +00:00
|
|
|
{
|
2013-06-07 20:56:55 +00:00
|
|
|
if( m_rbUseIncremental->GetValue() )
|
2011-01-04 20:27:52 +00:00
|
|
|
return 0;
|
2013-06-07 20:56:55 +00:00
|
|
|
|
|
|
|
if( m_rbUseSheetNum->GetValue() )
|
2011-01-04 20:27:52 +00:00
|
|
|
return 1;
|
2013-06-07 20:56:55 +00:00
|
|
|
|
2011-01-04 20:27:52 +00:00
|
|
|
return 2;
|
|
|
|
}
|
2013-06-07 20:56:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
int InvokeDialogAnnotate( SCH_EDIT_FRAME* aCaller )
|
|
|
|
{
|
|
|
|
DIALOG_ANNOTATE dlg( aCaller );
|
|
|
|
|
|
|
|
return dlg.ShowModal();
|
|
|
|
}
|
|
|
|
|