diff --git a/common/pcbcommon.cpp b/common/pcbcommon.cpp index da36d48c09..ddfd0e5f68 100644 --- a/common/pcbcommon.cpp +++ b/common/pcbcommon.cpp @@ -55,9 +55,6 @@ LAYER_MSK g_TabAllCopperLayerMask[NB_COPPER_LAYERS] = { DISPLAY_OPTIONS DisplayOpt; // Display options for board items -// This will be always be 450 or 900 (by UI design) at the moment -int g_RotationAngle; - int g_AnchorColor = BLUE; int g_ModuleTextCMPColor = LIGHTGRAY; int g_ModuleTextCUColor = MAGENTA; diff --git a/common/string.cpp b/common/string.cpp index 7d3a74f0c4..86b60d938f 100644 --- a/common/string.cpp +++ b/common/string.cpp @@ -477,3 +477,18 @@ bool ReplaceIllegalFileNameChars( std::string* aName ) return changed; } + + +wxString RemoveTrailingZeros( const wxString& aString ) +{ + wxString retv = aString; + int i = retv.Length(); + + while( --i > 0 && retv[i] == wxChar( '0' ) ) + retv.RemoveLast(); + + if( retv[i] == wxChar( '.' ) ) + retv.RemoveLast(); + + return retv; +} diff --git a/include/kicad_string.h b/include/kicad_string.h index 314e803a8f..ee13446132 100644 --- a/include/kicad_string.h +++ b/include/kicad_string.h @@ -164,6 +164,18 @@ wxString GetIllegalFileNameWxChars(); */ bool ReplaceIllegalFileNameChars( std::string* aName ); +/** + * Function RemoveTrailingZeros + * removes the trailing zeros from \a aString. + * + * All trailing zeros and the '.' character from floating point numbers are removed from + * \a aString. + * + * @param aString is a wxString object to remove the trailing zeros from. + * @return a wxString with the trailing zeros removed. + */ +wxString RemoveTrailingZeros( const wxString& aString ); + #ifndef HAVE_STRTOKR // common/strtok_r.c optionally: extern "C" char* strtok_r( char* str, const char* delim, char** nextp ); diff --git a/include/pcbcommon.h b/include/pcbcommon.h index 6aec7cf240..cdec3783b5 100644 --- a/include/pcbcommon.h +++ b/include/pcbcommon.h @@ -25,8 +25,6 @@ extern DISPLAY_OPTIONS DisplayOpt; extern int g_CurrentVersionPCB; -extern int g_RotationAngle; - /// List of segments of the trace currently being drawn. extern DLIST g_CurrentTrackList; diff --git a/include/wxPcbStruct.h b/include/wxPcbStruct.h index fc7d379a07..036dda9eee 100644 --- a/include/wxPcbStruct.h +++ b/include/wxPcbStruct.h @@ -87,6 +87,9 @@ class PCB_EDIT_FRAME : public PCB_BASE_FRAME /// The global footprint library table. FP_LIB_TABLE* m_globalFootprintTable; + /// User defined rotation angle (in tenths of a degree). + int m_rotationAngle; + /** * Function loadFootprints * loads the footprints for each #COMPONENT in \a aNetlist from the list of libraries. @@ -330,6 +333,9 @@ public: */ virtual void SetGridColor(EDA_COLOR_T aColor); + int GetRotationAngle() const { return m_rotationAngle; } + void SetRotationAngle( int aRotationAngle ); + // Configurations: void InstallConfigFrame(); void Process_Config( wxCommandEvent& event ); diff --git a/pcbnew/board_undo_redo.cpp b/pcbnew/board_undo_redo.cpp index e58e734320..cd058e172b 100644 --- a/pcbnew/board_undo_redo.cpp +++ b/pcbnew/board_undo_redo.cpp @@ -504,11 +504,13 @@ void PCB_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList, bool aRed break; case UR_ROTATED: - item->Rotate( aList->m_TransformPoint, aRedoCommand ? 900 : -900 ); + item->Rotate( aList->m_TransformPoint, + aRedoCommand ? m_rotationAngle : -m_rotationAngle ); break; case UR_ROTATED_CLOCKWISE: - item->Rotate( aList->m_TransformPoint, aRedoCommand ? -900 : 900 ); + item->Rotate( aList->m_TransformPoint, + aRedoCommand ? -m_rotationAngle : m_rotationAngle ); break; case UR_FLIPPED: diff --git a/pcbnew/dialogs/dialog_general_options.cpp b/pcbnew/dialogs/dialog_general_options.cpp index 0c4e43290b..3470426f2c 100644 --- a/pcbnew/dialogs/dialog_general_options.cpp +++ b/pcbnew/dialogs/dialog_general_options.cpp @@ -37,7 +37,7 @@ #include #include #include - +#include #include #include @@ -69,15 +69,9 @@ void DIALOG_GENERALOPTIONS::init() m_CursorShape->SetSelection( GetParent()->GetCursorShape() ? 1 : 0 ); - switch( g_RotationAngle ) - { - case 450: - m_RotationAngle->SetSelection( 0 ); - break; - - default: - m_RotationAngle->SetSelection( 1 ); - } + wxString rotationAngle; + rotationAngle.Printf( wxT( "%.1f" ), ((double)GetParent()->GetRotationAngle()) / 10.0 ); + m_RotationAngle->SetValue( RemoveTrailingZeros( rotationAngle ) ); wxString timevalue; timevalue << GetParent()->GetAutoSaveInterval() / 60; @@ -121,8 +115,7 @@ void DIALOG_GENERALOPTIONS::OnOkClick( wxCommandEvent& event ) GetParent()->SetCursorShape( m_CursorShape->GetSelection() ); GetParent()->SetAutoSaveInterval( m_SaveTime->GetValue() * 60 ); - - g_RotationAngle = 10 * wxAtoi( m_RotationAngle->GetStringSelection() ); + GetParent()->SetRotationAngle( wxRound( 10.0 * wxAtof( m_RotationAngle->GetValue() ) ) ); /* Updating the combobox to display the active layer. */ g_MaxLinksShowed = m_MaxShowLinks->GetValue(); diff --git a/pcbnew/dialogs/dialog_general_options_BoardEditor_base.cpp b/pcbnew/dialogs/dialog_general_options_BoardEditor_base.cpp index a368448e28..6a2daad28a 100644 --- a/pcbnew/dialogs/dialog_general_options_BoardEditor_base.cpp +++ b/pcbnew/dialogs/dialog_general_options_BoardEditor_base.cpp @@ -79,13 +79,10 @@ DIALOG_GENERALOPTIONS_BOARDEDITOR_BASE::DIALOG_GENERALOPTIONS_BOARDEDITOR_BASE( m_staticTextRotationAngle->Wrap( -1 ); fgSizer1->Add( m_staticTextRotationAngle, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); - wxString m_RotationAngleChoices[] = { _("45"), _("90") }; - int m_RotationAngleNChoices = sizeof( m_RotationAngleChoices ) / sizeof( wxString ); - m_RotationAngle = new wxChoice( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, m_RotationAngleNChoices, m_RotationAngleChoices, 0 ); - m_RotationAngle->SetSelection( 0 ); - m_RotationAngle->SetToolTip( _("Footprints rotation increment, for rotate menu or hot key.") ); + m_RotationAngle = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); + m_RotationAngle->SetToolTip( _("Context menu and hot key footprint rotation increment.") ); - fgSizer1->Add( m_RotationAngle, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); + fgSizer1->Add( m_RotationAngle, 0, wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxLEFT|wxRIGHT, 5 ); bMiddleLeftSizer->Add( fgSizer1, 0, wxEXPAND, 5 ); diff --git a/pcbnew/dialogs/dialog_general_options_BoardEditor_base.fbp b/pcbnew/dialogs/dialog_general_options_BoardEditor_base.fbp index 715589dd05..e4b73b36fa 100644 --- a/pcbnew/dialogs/dialog_general_options_BoardEditor_base.fbp +++ b/pcbnew/dialogs/dialog_general_options_BoardEditor_base.fbp @@ -831,9 +831,9 @@ 5 - wxALIGN_CENTER_VERTICAL|wxALL + wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxLEFT|wxRIGHT 0 - + 1 1 1 @@ -847,7 +847,6 @@ 1 0 - "45" "90" 1 1 @@ -865,6 +864,7 @@ 0 + 0 @@ -877,22 +877,21 @@ 1 Resizable - 0 1 0 - Footprints rotation increment, for rotate menu or hot key. + Context menu and hot key footprint rotation increment. wxFILTER_NONE wxDefaultValidator + - @@ -914,6 +913,10 @@ + + + + diff --git a/pcbnew/dialogs/dialog_general_options_BoardEditor_base.h b/pcbnew/dialogs/dialog_general_options_BoardEditor_base.h index e5eeb92afd..b66bb0c3f7 100644 --- a/pcbnew/dialogs/dialog_general_options_BoardEditor_base.h +++ b/pcbnew/dialogs/dialog_general_options_BoardEditor_base.h @@ -23,7 +23,7 @@ class DIALOG_SHIM; #include #include #include -#include +#include #include #include #include @@ -64,7 +64,7 @@ class DIALOG_GENERALOPTIONS_BOARDEDITOR_BASE : public DIALOG_SHIM wxStaticText* m_staticTextautosave; wxSpinCtrl* m_SaveTime; wxStaticText* m_staticTextRotationAngle; - wxChoice* m_RotationAngle; + wxTextCtrl* m_RotationAngle; wxCheckBox* m_DrcOn; wxCheckBox* m_ShowGlobalRatsnest; wxCheckBox* m_ShowModuleRatsnest; diff --git a/pcbnew/edit.cpp b/pcbnew/edit.cpp index cf90c3fad9..a742523dbe 100644 --- a/pcbnew/edit.cpp +++ b/pcbnew/edit.cpp @@ -745,9 +745,9 @@ void PCB_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) // This is a simple rotation, no other editing in progress if( !GetCurItem()->IsMoving() ) - SaveCopyInUndoList( GetCurItem(), UR_ROTATED, ((MODULE*)GetCurItem())->GetPosition() ); + SaveCopyInUndoList( GetCurItem(), UR_CHANGED, ((MODULE*)GetCurItem())->GetPosition() ); - Rotate_Module( &dc, (MODULE*) GetCurItem(), g_RotationAngle, true ); + Rotate_Module( &dc, (MODULE*) GetCurItem(), m_rotationAngle, true ); break; case ID_POPUP_PCB_ROTATE_MODULE_CLOCKWISE: @@ -773,10 +773,9 @@ void PCB_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) // This is a simple rotation, no other editing in progress if( !GetCurItem()->IsMoving() ) - SaveCopyInUndoList( GetCurItem(), UR_ROTATED_CLOCKWISE, - ((MODULE*)GetCurItem())->GetPosition() ); + SaveCopyInUndoList( GetCurItem(), UR_CHANGED, ((MODULE*)GetCurItem())->GetPosition() ); - Rotate_Module( &dc, (MODULE*) GetCurItem(), -g_RotationAngle, true ); + Rotate_Module( &dc, (MODULE*) GetCurItem(), -m_rotationAngle, true ); break; case ID_POPUP_PCB_CHANGE_SIDE_MODULE: diff --git a/pcbnew/pcbframe.cpp b/pcbnew/pcbframe.cpp index 22e65331bb..44f48f5e1f 100644 --- a/pcbnew/pcbframe.cpp +++ b/pcbnew/pcbframe.cpp @@ -317,6 +317,7 @@ PCB_EDIT_FRAME::PCB_EDIT_FRAME( wxWindow* parent, const wxString& title, m_footprintLibTable = NULL; m_globalFootprintTable = NULL; + m_rotationAngle = 900; #ifdef KICAD_SCRIPTING_WXPYTHON m_pythonPanel = NULL; @@ -1072,3 +1073,12 @@ void PCB_EDIT_FRAME::ToPlotter( wxCommandEvent& event ) DIALOG_PLOT dlg( this ); dlg.ShowModal(); } + + +void PCB_EDIT_FRAME::SetRotationAngle( int aRotationAngle ) +{ + wxCHECK2_MSG( aRotationAngle > 0 && aRotationAngle <= 900, aRotationAngle = 900, + wxT( "Invalid rotation angle, defaulting to 90." ) ); + + m_rotationAngle = aRotationAngle; +} diff --git a/pcbnew/pcbnew_config.cpp b/pcbnew/pcbnew_config.cpp index bcfc5d1b29..9d5b1c9724 100644 --- a/pcbnew/pcbnew_config.cpp +++ b/pcbnew/pcbnew_config.cpp @@ -158,27 +158,27 @@ void PCB_EDIT_FRAME::Process_Config( wxCommandEvent& event ) break; case ID_CONFIG_READ: + { + fn = GetBoard()->GetFileName(); + fn.SetExt( ProjectFileExtension ); + + wxFileDialog dlg( this, _( "Read Project File" ), fn.GetPath(), + fn.GetFullName(), ProjectFileWildcard, + wxFD_OPEN | wxFD_FILE_MUST_EXIST | wxFD_CHANGE_DIR ); + + if( dlg.ShowModal() == wxID_CANCEL ) + break; + + if( !wxFileExists( dlg.GetPath() ) ) { - fn = GetBoard()->GetFileName(); - fn.SetExt( ProjectFileExtension ); - - wxFileDialog dlg( this, _( "Read Project File" ), fn.GetPath(), - fn.GetFullName(), ProjectFileWildcard, - wxFD_OPEN | wxFD_FILE_MUST_EXIST | wxFD_CHANGE_DIR ); - - if( dlg.ShowModal() == wxID_CANCEL ) - break; - - if( !wxFileExists( dlg.GetPath() ) ) - { - wxString msg; - msg.Printf( _( "File %s not found" ), GetChars( dlg.GetPath() ) ); - DisplayError( this, msg ); - break; - } - - LoadProjectSettings( dlg.GetPath() ); + wxString msg; + msg.Printf( _( "File %s not found" ), GetChars( dlg.GetPath() ) ); + DisplayError( this, msg ); + break; } + + LoadProjectSettings( dlg.GetPath() ); + } break; // Hotkey IDs @@ -478,16 +478,16 @@ PARAM_CFG_ARRAY& PCB_EDIT_FRAME::GetConfigurationSettings() WHITE ) ); // Miscellaneous: - m_configSettings.push_back( new PARAM_CFG_INT( true, wxT( "RotationAngle" ), &g_RotationAngle, - 900, 450, 900 ) ); + m_configSettings.push_back( new PARAM_CFG_INT( true, wxT( "RotationAngle" ), &m_rotationAngle, + 900, 1, 900 ) ); m_configSettings.push_back( new PARAM_CFG_INT( true, wxT( "MaxLnkS" ), &g_MaxLinksShowed, 3, 0, 15 ) ); m_configSettings.push_back( new PARAM_CFG_BOOL( true, wxT( "ShowMRa" ), &g_Show_Module_Ratsnest, true ) ); m_configSettings.push_back( new PARAM_CFG_BOOL( true, wxT( "TwoSegT" ), &g_TwoSegmentTrackBuild, true ) ); - m_configSettings.push_back( new PARAM_CFG_BOOL( true, wxT( "SegmPcb45Only" ), &g_Segments_45_Only, - true ) ); + m_configSettings.push_back( new PARAM_CFG_BOOL( true, wxT( "SegmPcb45Only" ) + , &g_Segments_45_Only, true ) ); return m_configSettings; }