From d24bd85bf503f83429acbeb31e34323f901f0873 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Fri, 22 Jan 2016 13:30:44 +0100 Subject: [PATCH] Minor code cleanup. --- include/wxPcbStruct.h | 43 +++----------------- pcbnew/muonde.cpp | 94 ++++++++++++++++++++++++++++++++----------- 2 files changed, 75 insertions(+), 62 deletions(-) diff --git a/include/wxPcbStruct.h b/include/wxPcbStruct.h index 103172c2fa..1cb2d7a1ca 100644 --- a/include/wxPcbStruct.h +++ b/include/wxPcbStruct.h @@ -281,6 +281,11 @@ public: void OnLayerColorChange( wxCommandEvent& aEvent ); void OnConfigurePaths( wxCommandEvent& aEvent ); + /** + * called when the alt key is pressed during a mouse wheel action + */ + void OnAltWheel( wxCommandEvent& event ); + /** * Function RecordMacros. * records sequence of hotkeys and cursor positions to a macro. @@ -1683,44 +1688,6 @@ public: void Begin_Self( wxDC* DC ); - /** - * Function Genre_Self - * creates a self-shaped coil for microwave applications. - * - Length Mself.lng - * - Extremities Mself.m_Start and Mself.m_End - * - * We must determine: - * Mself.nbrin = number of segments perpendicular to the direction - * (The coil nbrin will demicercles + 1 + 2 1 / 4 circle) - * Mself.lbrin = length of a strand - * Mself.radius = radius of rounded parts of the coil - * Mself.delta = segments extremities connection between him and the coil even - * - * The equations are - * Mself.m_Size.x = 2 * Mself.radius + Mself.lbrin - * Mself.m_Size.y * Mself.delta = 2 + 2 * Mself.nbrin * Mself.radius - * Mself.lng = 2 * Mself.delta / / connections to the coil - + (Mself.nbrin-2) * Mself.lbrin / / length of the strands except 1st and last - + (Mself.nbrin 1) * (PI * Mself.radius) / / length of rounded - * Mself.lbrin + / 2 - Melf.radius * 2) / / length of 1st and last bit - * - * The constraints are: - * Nbrin >= 2 - * Mself.radius < Mself.m_Size.x - * Mself.m_Size.y = Mself.radius * 4 + 2 * Mself.raccord - * Mself.lbrin> Mself.radius * 2 - * - * The calculation is conducted in the following way: - * Initially: - * Nbrin = 2 - * Radius = 4 * m_Size.x (arbitrarily fixed value) - * Then: - * Increasing the number of segments to the desired length - * (Radius decreases if necessary) - * - */ - MODULE* Genere_Self( wxDC* DC ); - void ShowChangedLanguage(); // override EDA_BASE_FRAME virtual /** diff --git a/pcbnew/muonde.cpp b/pcbnew/muonde.cpp index 4e551b35a6..aec5d69740 100644 --- a/pcbnew/muonde.cpp +++ b/pcbnew/muonde.cpp @@ -68,10 +68,16 @@ static void ShowBoundingBoxMicroWaveInductor( EDA_DRAW_PANEL* aPanel, bool aErase ); -int BuildCornersList_S_Shape( std::vector & aBuffer, +static int BuildCornersList_S_Shape( std::vector & aBuffer, wxPoint aStartPoint, wxPoint aEndPoint, int aLength, int aWidth ); +/** + * Creates a self-shaped coil for microwave applications. + */ +static MODULE* CreateMicrowaveInductor( PCB_EDIT_FRAME* aPcbFrame, wxString& aErrorMessage ); + + class MUWAVE_INDUCTOR { public: @@ -155,7 +161,28 @@ void PCB_EDIT_FRAME::Begin_Self( wxDC* DC ) { if( s_inductor_pattern.m_Flag ) { - Genere_Self( DC ); + m_canvas->CallMouseCapture( DC, wxDefaultPosition, false ); + m_canvas->SetMouseCapture( NULL, NULL ); + + wxString errorMessage; + + // Prepare parameters for inductor + // s_inductor_pattern.m_Start is already initialized, + // when s_inductor_pattern.m_Flag == false + s_inductor_pattern.m_Width = GetDesignSettings().GetCurrentTrackWidth(); + s_inductor_pattern.m_End = GetCrossHairPosition(); + + MODULE* footprint = CreateMicrowaveInductor( this, errorMessage ); + + if( footprint ) + { + SetMsgPanel( footprint ); + footprint->Draw( m_canvas, DC, GR_OR ); + } + + else if( !errorMessage.IsEmpty() ) + DisplayError( this, errorMessage ); + return; } @@ -173,32 +200,57 @@ void PCB_EDIT_FRAME::Begin_Self( wxDC* DC ) } -MODULE* PCB_EDIT_FRAME::Genere_Self( wxDC* DC ) + +MODULE* CreateMicrowaveInductor( PCB_EDIT_FRAME* aPcbFrame, wxString& aErrorMessage ) { + /* Build a microwave inductor footprint. + * - Length Mself.lng + * - Extremities Mself.m_Start and Mself.m_End + * We must determine: + * Mself.nbrin = number of segments perpendicular to the direction + * (The coil nbrin will demicercles + 1 + 2 1 / 4 circle) + * Mself.lbrin = length of a strand + * Mself.radius = radius of rounded parts of the coil + * Mself.delta = segments extremities connection between him and the coil even + * + * The equations are + * Mself.m_Size.x = 2 * Mself.radius + Mself.lbrin + * Mself.m_Size.y * Mself.delta = 2 + 2 * Mself.nbrin * Mself.radius + * Mself.lng = 2 * Mself.delta / / connections to the coil + + (Mself.nbrin-2) * Mself.lbrin / / length of the strands except 1st and last + + (Mself.nbrin 1) * (PI * Mself.radius) / / length of rounded + * Mself.lbrin + / 2 - Melf.radius * 2) / / length of 1st and last bit + * + * The constraints are: + * Nbrin >= 2 + * Mself.radius < Mself.m_Size.x + * Mself.m_Size.y = Mself.radius * 4 + 2 * Mself.raccord + * Mself.lbrin> Mself.radius * 2 + * + * The calculation is conducted in the following way: + * Initially: + * Nbrin = 2 + * Radius = 4 * m_Size.x (arbitrarily fixed value) + * Then: + * Increasing the number of segments to the desired length + * (Radius decreases if necessary) + */ + D_PAD* pad; int ll; wxString msg; - m_canvas->CallMouseCapture( DC, wxDefaultPosition, false ); - m_canvas->SetMouseCapture( NULL, NULL ); - - if( s_inductor_pattern.m_Flag == false ) - { - DisplayError( this, wxT( "Starting point not init.." ) ); - return NULL; - } + wxASSERT( s_inductor_pattern.m_Flag ); s_inductor_pattern.m_Flag = false; - s_inductor_pattern.m_End = GetCrossHairPosition(); - wxPoint pt = s_inductor_pattern.m_End - s_inductor_pattern.m_Start; int min_len = KiROUND( EuclideanNorm( pt ) ); s_inductor_pattern.m_lenght = min_len; // Enter the desired length. msg = StringFromValue( g_UserUnit, s_inductor_pattern.m_lenght ); - wxTextEntryDialog dlg( this, wxEmptyString, _( "Length of Trace:" ), msg ); + wxTextEntryDialog dlg( NULL, wxEmptyString, _( "Length of Trace:" ), msg ); if( dlg.ShowModal() != wxID_OK ) return NULL; // canceled by user @@ -209,13 +261,11 @@ MODULE* PCB_EDIT_FRAME::Genere_Self( wxDC* DC ) // Control values (ii = minimum length) if( s_inductor_pattern.m_lenght < min_len ) { - DisplayError( this, _( "Requested length < minimum length" ) ); + aErrorMessage = _( "Requested length < minimum length" ); return NULL; } // Calculate the elements. - s_inductor_pattern.m_Width = GetDesignSettings().GetCurrentTrackWidth(); - std::vector buffer; ll = BuildCornersList_S_Shape( buffer, s_inductor_pattern.m_Start, s_inductor_pattern.m_End, s_inductor_pattern.m_lenght, @@ -223,19 +273,19 @@ MODULE* PCB_EDIT_FRAME::Genere_Self( wxDC* DC ) if( !ll ) { - DisplayError( this, _( "Requested length too large" ) ); + aErrorMessage = _( "Requested length too large" ); return NULL; } // Generate footprint. the value is also used as footprint name. msg.Empty(); - wxTextEntryDialog cmpdlg( this, wxEmptyString, _( "Component Value:" ), msg ); + wxTextEntryDialog cmpdlg( NULL, wxEmptyString, _( "Component Value:" ), msg ); cmpdlg.SetTextValidator( FILE_NAME_CHAR_VALIDATOR( &msg ) ); if( ( cmpdlg.ShowModal() != wxID_OK ) || msg.IsEmpty() ) return NULL; // Aborted by user - MODULE* module = CreateNewModule( msg ); + MODULE* module = aPcbFrame->CreateNewModule( msg ); // here the module is already in the BOARD, CreateNewModule() does that. module->SetFPID( FPID( std::string( "mw_inductor" ) ) ); @@ -283,8 +333,6 @@ MODULE* PCB_EDIT_FRAME::Genere_Self( wxDC* DC ) pad->SetPos0( pad->GetPosition() - module->GetPosition() ); // Modify text positions. - SetMsgPanel( module ); - wxPoint refPos( ( s_inductor_pattern.m_Start.x + s_inductor_pattern.m_End.x ) / 2, ( s_inductor_pattern.m_Start.y + s_inductor_pattern.m_End.y ) / 2 ); @@ -296,8 +344,6 @@ MODULE* PCB_EDIT_FRAME::Genere_Self( wxDC* DC ) module->Value().SetPosition( valPos ); module->CalculateBoundingBox(); - module->Draw( m_canvas, DC, GR_OR ); - return module; }