Commit 7ce97878 authored by jean-pierre charras's avatar jean-pierre charras

pcb_calculator: enhancement in Regulators page dialog:

* support for 3 terminal regulators
* add a data file management to store parameters for regulators ( name, vref value, Iadj value, type)
Needs some refinements, but it is already very useable.

 Commit dialog page setting patch from Alexander Zakamaldin
parent d7feb9ab
...@@ -438,6 +438,9 @@ limits\n%.1f - %.1f %s!\nSelect another custom paper size?" ), ...@@ -438,6 +438,9 @@ limits\n%.1f - %.1f %s!\nSelect another custom paper size?" ),
PAGE_INFO::SetCustomWidthMils( m_layout_size.x ); PAGE_INFO::SetCustomWidthMils( m_layout_size.x );
PAGE_INFO::SetCustomHeightMils( m_layout_size.y ); PAGE_INFO::SetCustomHeightMils( m_layout_size.y );
m_pageInfo.SetWidthMils( m_layout_size.x );
m_pageInfo.SetHeightMils( m_layout_size.y );
m_pageInfo.SetPortrait( m_layout_size.x < m_layout_size.y );
} }
} }
else else
......
...@@ -18,10 +18,12 @@ set(PCB_CALCULATOR_SRCS ...@@ -18,10 +18,12 @@ set(PCB_CALCULATOR_SRCS
params_read_write.cpp params_read_write.cpp
pcb_calculator.cpp pcb_calculator.cpp
pcb_calculator_frame.cpp pcb_calculator_frame.cpp
datafile_read_write.cpp
regulators_funct.cpp regulators_funct.cpp
tracks_width_versus_current.cpp tracks_width_versus_current.cpp
transline_ident.cpp transline_ident.cpp
UnitSelector.cpp UnitSelector.cpp
pcb_calculator_datafile_keywords.cpp
transline/transline.cpp transline/transline.cpp
transline/c_microstrip.cpp transline/c_microstrip.cpp
transline/microstrip.cpp transline/microstrip.cpp
...@@ -33,6 +35,7 @@ set(PCB_CALCULATOR_SRCS ...@@ -33,6 +35,7 @@ set(PCB_CALCULATOR_SRCS
transline_dlg_funct.cpp transline_dlg_funct.cpp
attenuators/attenuator_classes.cpp attenuators/attenuator_classes.cpp
dialogs/pcb_calculator_frame_base.cpp dialogs/pcb_calculator_frame_base.cpp
dialogs/dialog_regulator_data_base.cpp
) )
if(WIN32) if(WIN32)
...@@ -54,6 +57,14 @@ if(APPLE) ...@@ -54,6 +57,14 @@ if(APPLE)
set(MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/Info.plist) set(MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/Info.plist)
endif(APPLE) endif(APPLE)
# auto-generate pcb_calculator_datafile.h and pcb_calculator_datafile_keywords.cpp
# for the storage data file format.
make_lexer(
${CMAKE_CURRENT_SOURCE_DIR}/pcb_calculator_datafile.keywords
${CMAKE_CURRENT_SOURCE_DIR}/pcb_calculator_datafile_lexer.h
${CMAKE_CURRENT_SOURCE_DIR}/pcb_calculator_datafile_keywords.cpp
PCBCALC_DATA_T
)
add_executable(pcb_calculator WIN32 MACOSX_BUNDLE add_executable(pcb_calculator WIN32 MACOSX_BUNDLE
......
This diff is collapsed.
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="256"
height="200"
id="svg2"
version="1.1"
inkscape:version="0.48.1 "
sodipodi:docname="regul_3pins.svg"
inkscape:export-filename="F:\kicad-launchpad\testing\pcb_calculator\bitmaps\sources\regul_3pins.png"
inkscape:export-xdpi="90"
inkscape:export-ydpi="90">
<defs
id="defs4" />
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="3.0195312"
inkscape:cx="75.011642"
inkscape:cy="108.75361"
inkscape:document-units="px"
inkscape:current-layer="layer1"
showgrid="true"
inkscape:window-width="1280"
inkscape:window-height="968"
inkscape:window-x="-4"
inkscape:window-y="-4"
inkscape:window-maximized="1">
<inkscape:grid
type="xygrid"
id="grid3769"
empspacing="5"
visible="true"
enabled="true"
snapvisiblegridlinesonly="true" />
</sodipodi:namedview>
<metadata
id="metadata7">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Calque 1"
inkscape:groupmode="layer"
id="layer1"
transform="translate(0,-852.36218)">
<rect
style="fill:#f2f274;fill-opacity:1;stroke:#0000ff;stroke-width:2.70856905;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
id="rect3757"
width="100"
height="90"
x="45"
y="872.36218"
rx="0.46518731"
ry="0.770051" />
<path
style="fill:none;stroke:#0000ff;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:2;stroke-opacity:1;stroke-dasharray:none"
d="m 5.7075806,887.36218 39.0660404,0 0.601016,0"
id="path3767"
inkscape:connector-curvature="0" />
<path
style="fill:#800000;stroke:#800000;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
d="m 145,887.36218 109.03021,0 1.67737,0"
id="path3767-5"
inkscape:connector-curvature="0" />
<text
xml:space="preserve"
style="font-size:25.21309471px;font-style:normal;font-weight:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:#800000;fill-opacity:1;stroke:none;font-family:Bitstream Vera Sans"
x="160.62158"
y="882.83466"
id="text3789"
sodipodi:linespacing="125%"
transform="scale(1.0005354,0.99946488)"><tspan
sodipodi:role="line"
id="tspan3791"
x="160.62158"
y="882.83466"
style="fill:#800000;fill-opacity:1;stroke:none">VOUT</tspan></text>
<flowRoot
xml:space="preserve"
id="flowRoot3793"
style="font-size:14px;font-style:normal;font-weight:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;font-family:Bitstream Vera Sans"
transform="translate(0,924.36218)"><flowRegion
id="flowRegion3795"><rect
id="rect3797"
width="69.019989"
height="28.36969"
x="320.98001"
y="-580.36969" /></flowRegion><flowPara
id="flowPara3799" /></flowRoot> <flowRoot
xml:space="preserve"
id="flowRoot3801"
style="font-size:14px;font-style:normal;font-weight:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;font-family:Bitstream Vera Sans"
transform="translate(0,924.36218)"><flowRegion
id="flowRegion3803"><rect
id="rect3805"
width="133.74167"
height="52.57431"
x="315.44586"
y="-596.97211" /></flowRegion><flowPara
id="flowPara3807" /></flowRoot> <text
xml:space="preserve"
style="font-size:25.66092873px;font-style:normal;font-weight:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:#3729c3;fill-opacity:1;stroke:none;font-family:Bitstream Vera Sans"
x="1.4928155"
y="899.01257"
id="text3789-2"
sodipodi:linespacing="125%"
transform="scale(1.0183069,0.98202221)"><tspan
sodipodi:role="line"
id="tspan3791-3"
x="1.4928155"
y="899.01257"
style="fill:#3729c3;fill-opacity:1;stroke:none">Vin</tspan></text>
<path
style="fill:#800000;stroke:#800000;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:2;stroke-opacity:1;stroke-dasharray:none"
d="m 95,977.36218 100.21655,1e-5 0.54178,0"
id="path3767-5-1"
inkscape:connector-curvature="0"
sodipodi:nodetypes="ccc" />
<rect
style="fill:#f3f36e;fill-opacity:1;stroke:#800000;stroke-width:2;stroke-linecap:square;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0"
id="rect3898"
width="20"
height="40"
x="185"
y="897.36218"
rx="0.46518731"
ry="0.68448979" />
<rect
style="fill:#f2f26c;fill-opacity:1;stroke:#800000;stroke-width:2;stroke-linecap:square;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0"
id="rect3898-6"
width="20"
height="40"
x="185"
y="982.36218"
rx="0.46518731"
ry="0.68448979" />
<text
xml:space="preserve"
style="font-size:22.56652641px;font-style:normal;font-weight:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:#800000;fill-opacity:1;stroke:none;font-family:Bitstream Vera Sans"
x="240.08633"
y="825.98572"
id="text3789-8"
sodipodi:linespacing="125%"
transform="scale(0.89551121,1.1166806)"><tspan
sodipodi:role="line"
id="tspan3791-8"
x="240.08633"
y="825.98572"
style="fill:#800000;fill-opacity:1;stroke:none">R1</tspan></text>
<text
xml:space="preserve"
style="font-size:22.56652641px;font-style:normal;font-weight:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:#800000;fill-opacity:1;stroke:none;font-family:Bitstream Vera Sans"
x="240.08633"
y="902.10413"
id="text3789-8-2"
sodipodi:linespacing="125%"
transform="scale(0.89551121,1.1166806)"><tspan
sodipodi:role="line"
id="tspan3791-8-7"
x="240.08633"
y="902.10413"
style="fill:#800000;fill-opacity:1;stroke:none">R2</tspan></text>
<path
style="fill:#800000;stroke:#800000;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
d="m 195,887.36218 0,10 0,0"
id="path3960"
inkscape:connector-curvature="0" />
<path
style="fill:#800000;stroke:#800000;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
d="m 195,937.36218 0,10.00002 0,34.99998"
id="path3960-7"
inkscape:connector-curvature="0"
sodipodi:nodetypes="ccc" />
<path
style="fill:#800000;stroke:#800000;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
d="m 195,1022.3622 0,10 0,0"
id="path3960-1"
inkscape:connector-curvature="0" />
<path
style="fill:none;stroke:#000000;stroke-width:3;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
d="m 184.83349,1032.3622 20.16651,0 0,0"
id="path3832-2"
inkscape:connector-curvature="0" />
<text
xml:space="preserve"
style="font-size:26.76031494px;font-style:normal;font-weight:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:#800000;fill-opacity:1;stroke:none;font-family:Bitstream Vera Sans"
x="65.917465"
y="1016.6555"
id="text3789-6"
sodipodi:linespacing="125%"
transform="scale(1.061934,0.9416781)"><tspan
sodipodi:role="line"
id="tspan3791-0"
x="65.917465"
y="1016.6555"
style="fill:#800000;fill-opacity:1;stroke:none">ADJ</tspan></text>
<path
style="fill:#800000;stroke:#800000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="m 245.70758,877.3622 10,10 -10,10 z"
id="path3794"
inkscape:connector-curvature="0" />
<path
style="fill:none;stroke:#800000;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
d="m 95,962.3622 0,14.99998"
id="path3032"
inkscape:connector-curvature="0"
sodipodi:nodetypes="cc" />
</g>
</svg>
#ifndef CLASS_REGULATOR_DATA_H
#define CLASS_REGULATOR_DATA_H
/**
* @file class_regulator_data.h
*/
/*
* This program source code file is part of KICAD, a free EDA CAD application.
*
* Copyright (C) 1992-2011 jean-pierre.charras
* Copyright (C) 1992-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
*/
#include <kicad_string.h>
// Helper class to store parameters for a regulator
class REGULATOR_DATA
{
public:
wxString m_Name; // Regulator name
int m_Type; // type: with separate sense pin (normal) (=0)
// or adjustable 3 pins reg (=1)
double m_Vref; // Vreference in volt
double m_Iadj; // 3 pin type only: I adjust in micro amp
public:
REGULATOR_DATA( const wxString& aName, double aVref, int aType, double aIadj = 0)
{
m_Type = aType;
m_Vref = aVref;
m_Name = aName;
m_Iadj = aIadj;
}
};
// Helper class to store the list of known regulators
class REGULATOR_LIST
{
public:
std::vector <REGULATOR_DATA*> m_List;
public:
REGULATOR_LIST() {};
~REGULATOR_LIST()
{
for( unsigned ii = 0; ii < m_List.size(); ii++ )
delete m_List[ii];
}
unsigned int GetCount()
{
return m_List.size();
}
void Add( REGULATOR_DATA* aItem )
{
// add new item an try to keep alphabetic order,
// and because name have numbers inside, use a KiCad compare function
// that handles number as numbers not ascii chars
unsigned ii = 0;
for( ; ii < m_List.size(); ii++ )
{
if( RefDesStringCompare( aItem->m_Name, m_List[ii]->m_Name ) < 0 )
break;
}
m_List.insert( m_List.begin() + ii, aItem );
}
REGULATOR_DATA* GetReg( const wxString& aName )
{
for( unsigned ii = 0; ii < m_List.size(); ii++ )
{
if( aName.CmpNoCase( m_List[ii]->m_Name ) == 0 )
{
return m_List[ii];
}
}
return NULL;
}
void Remove( const wxString & aRegName )
{
for( unsigned ii = 0; ii < m_List.size(); ii++ )
{
if( aRegName.CmpNoCase( m_List[ii]->m_Name ) == 0 )
{
// Found! remove it
m_List.erase( m_List.begin() + ii );
break;
}
}
}
/**
* Replace an old REGULATOR_DATA by a new one
* The old one is deleted
* the 2 items must have the same name
*/
void Replace( REGULATOR_DATA* aItem )
{
// Search for the old regulator
for( unsigned ii = 0; ii < m_List.size(); ii++ )
{
if( aItem->m_Name.CmpNoCase( m_List[ii]->m_Name ) == 0 )
{
// Found! remove it
delete m_List[ii];
m_List[ii] = aItem;
break;
}
}
}
wxArrayString GetRegList()
{
wxArrayString list;
for( unsigned ii = 0; ii < m_List.size(); ii++ )
list.Add( m_List[ii]->m_Name );
return list;
}
};
#endif // CLASS_REGULATOR_DATA_H
/**
* @file datafile_read_write.cpp
*/
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2012 Jean-Pierre Charras
* Copyright (C) 1992-2012 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
*/
#include <macros.h>
#include <common.h>
#include <kicad_string.h>
#include <appl_wxstruct.h>
#include <pcb_calculator.h>
#include <pcb_calculator_datafile_lexer.h>
#include <class_regulator_data.h>
#include <datafile_read_write.h>
#include <wx/wfstream.h>
#include <build_version.h>
using namespace PCBCALC_DATA_T;
static const char* getTokenName( T aTok )
{
return PCB_CALCULATOR_DATAFILE_LEXER::TokenName( aTok );
}
bool PCB_CALCULATOR_FRAME::ReadDataFile()
{
FILE* file = wxFopen( GetDataFilename(), wxT( "rt" ) );
if( file == NULL )
return false;
// Switch the locale to standard C (needed to read/write floating point numbers
LOCALE_IO toggle;
PCB_CALCULATOR_DATAFILE * datafile = new PCB_CALCULATOR_DATAFILE( &m_RegulatorList );
// dataReader dtor will close file
FILE_LINE_READER dataReader( file, GetDataFilename() );
PCB_CALCULATOR_DATAFILE_PARSER datafile_parser( &dataReader );
try
{
datafile_parser.Parse( datafile );
}
catch( IO_ERROR& ioe )
{
delete datafile;
ioe.errorText += '\n';
ioe.errorText += _("Data file error.");
wxMessageBox( ioe.errorText );
return false;
}
delete datafile;
return true;
}
bool PCB_CALCULATOR_FRAME::WriteDataFile()
{
wxFFileOutputStream os( GetDataFilename(), wxT( "wt" ) );
if( !os.IsOk() )
return false;
// Switch the locale to standard C (needed to read/write floating point numbers
LOCALE_IO toggle;
PCB_CALCULATOR_DATAFILE * datafile = new PCB_CALCULATOR_DATAFILE( &m_RegulatorList );
try
{
int nestlevel;
STREAM_OUTPUTFORMATTER outputFormatter( os );
nestlevel = datafile->WriteHeader( &outputFormatter );
datafile->Format( &outputFormatter, nestlevel );
while( nestlevel-- )
outputFormatter.Print( nestlevel, ")\n" );
}
catch( IO_ERROR ioe )
{
delete datafile;
return false;
}
delete datafile;
m_RegulatorListChanged = false;
return true;
}
PCB_CALCULATOR_DATAFILE::PCB_CALCULATOR_DATAFILE( REGULATOR_LIST * aList )
{
m_list = aList;
}
static const char* regtype_str[] =
{
"normal", "3terminal"
};
int PCB_CALCULATOR_DATAFILE::WriteHeader( OUTPUTFORMATTER* aFormatter ) const throw( IO_ERROR )
{
int nestlevel = 0;
aFormatter->Print( nestlevel++, "(datafile\n");
aFormatter->Print( nestlevel++, "(version 1)\n" );
aFormatter->Print( nestlevel++, "(date %s)\n",
aFormatter->Quotew( DateAndTime() ).c_str() );
aFormatter->Print( nestlevel++, "(tool %s)\n",
aFormatter->Quotew( wxGetApp().GetAppName() +
wxChar(' ') + GetBuildVersion() ).c_str() );
return nestlevel;
}
void PCB_CALCULATOR_DATAFILE::Format( OUTPUTFORMATTER* aFormatter,
int aNestLevel ) const throw( IO_ERROR )
{
// Write regulators list:
aFormatter->Print( aNestLevel++, "(%s\n", getTokenName( T_regulators ) );
for( unsigned ii = 0; ii < m_list->m_List.size(); ii++ )
{
REGULATOR_DATA * item = m_list->m_List[ii];
aFormatter->Print( aNestLevel, "(%s %s\n", getTokenName( T_regulator ),
aFormatter->Quotew(item->m_Name ).c_str() );
aFormatter->Print( aNestLevel+1, "(%s %g)\n", getTokenName( T_reg_vref ),
item->m_Vref );
if( item->m_Iadj != 0 && item->m_Type == 1)
{
aFormatter->Print( aNestLevel+1, "(%s %g)\n", getTokenName( T_reg_iadj ),
item->m_Iadj );
}
aFormatter->Print( aNestLevel+1, "(%s %s)\n", getTokenName( T_reg_type ),
regtype_str[item->m_Type] );
aFormatter->Print( aNestLevel, ")\n" );
}
aFormatter->Print( --aNestLevel, ")\n" );
}
void PCB_CALCULATOR_DATAFILE::Parse( PCB_CALCULATOR_DATAFILE_PARSER* aParser )
throw( IO_ERROR, PARSE_ERROR )
{
aParser->Parse( this );
}
// PCB_CALCULATOR_DATAFILE_PARSER
PCB_CALCULATOR_DATAFILE_PARSER::PCB_CALCULATOR_DATAFILE_PARSER( LINE_READER* aReader ) :
PCB_CALCULATOR_DATAFILE_LEXER( aReader )
{
}
PCB_CALCULATOR_DATAFILE_PARSER::PCB_CALCULATOR_DATAFILE_PARSER( char* aLine, wxString aSource ) :
PCB_CALCULATOR_DATAFILE_LEXER( aLine, aSource )
{
}
void PCB_CALCULATOR_DATAFILE_PARSER::Parse( PCB_CALCULATOR_DATAFILE* aDataList ) throw( IO_ERROR, PARSE_ERROR )
{
T token;
while( ( token = NextTok() ) != T_EOF)
{
if( token == T_LEFT )
{
token = NextTok();
if( token == T_regulators )
{
ParseRegulatorDescr( aDataList );
continue;
}
}
}
}
void PCB_CALCULATOR_DATAFILE_PARSER::ParseRegulatorDescr( PCB_CALCULATOR_DATAFILE* aDataList )
throw( IO_ERROR, PARSE_ERROR )
{
T token;
wxString name;
double vref, iadj;
int type;
while( ( token = NextTok() ) != T_RIGHT )
{
if( token == T_EOF)
Unexpected( T_EOF );
if( token == T_LEFT )
token = NextTok();
if( token == T_regulator )
{
type = 0;
vref = 0.0;
// Read name
token = NextTok();
name = FROM_UTF8( CurText() );
while( ( token = NextTok() ) != T_RIGHT )
{
if( token == T_EOF)
Unexpected( T_EOF );
if( token == T_LEFT )
token = NextTok();
switch( token )
{
case T_reg_vref: // the voltage reference value
token = NextTok();
if( token != T_NUMBER )
Expecting( T_NUMBER );
sscanf( CurText(), "%lf" , &vref);
NeedRIGHT();
break;
case T_reg_iadj: // the Iadj reference value
token = NextTok();
if( token != T_NUMBER )
Expecting( T_NUMBER );
sscanf( CurText(), "%lf" , &iadj);
NeedRIGHT();
break;
case T_reg_type: // type: normal or 3 terminal reg
token = NextTok();
if( stricmp( CurText(), regtype_str[0] ) == 0 )
type = 0;
else if( stricmp( CurText(), regtype_str[1] ) == 0 )
type = 1;
else
Unexpected( CurText() );
NeedRIGHT();
break;
default:
Unexpected( CurText() );
break;
}
}
if( ! name.IsEmpty() )
{
if( type != 1 )
iadj = 0.0;
REGULATOR_DATA * new_item = new REGULATOR_DATA(name, vref, type, iadj );
aDataList->m_list->Add( new_item );
}
}
}
}
#ifndef DATAFILE_READ_WRITE_H_
#define PDATAFILE_READ_WRITE_H_
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 1992-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
*/
#include <wx/wx.h>
#include <pcb_calculator_datafile_lexer.h>
#include <base_struct.h>
class PCB_CALCULATOR_DATAFILE_PARSER;
/**
* Class PCB_CALCULATOR_DATAFILE
* handles data to calculate regulators parameters
*/
class PCB_CALCULATOR_DATAFILE
{
friend class PCB_CALCULATOR_DATAFILE_PARSER;
protected:
REGULATOR_LIST * m_list;
public:
PCB_CALCULATOR_DATAFILE( REGULATOR_LIST * aList );
int WriteHeader( OUTPUTFORMATTER* aFormatter ) const throw( IO_ERROR );
void Format( OUTPUTFORMATTER* aFormatter, int aNestLevel ) const throw( IO_ERROR );
void Parse( PCB_CALCULATOR_DATAFILE_PARSER* aParser ) throw( IO_ERROR, PARSE_ERROR );
};
/**
* Class PCB_CALCULATOR_DATAFILE_PARSER
* is the parser class for PCB_CALCULATOR_DATAFILE.
*/
class PCB_CALCULATOR_DATAFILE_PARSER : public PCB_CALCULATOR_DATAFILE_LEXER
{
public:
PCB_CALCULATOR_DATAFILE_PARSER( LINE_READER* aReader );
PCB_CALCULATOR_DATAFILE_PARSER( char* aLine, wxString aSource );
LINE_READER* GetReader() { return reader; };
void Parse( PCB_CALCULATOR_DATAFILE* aDataList ) throw( IO_ERROR, PARSE_ERROR );
void ParseRegulatorDescr( PCB_CALCULATOR_DATAFILE* aDataList ) throw( IO_ERROR, PARSE_ERROR );
};
#endif // PDATAFILE_READ_WRITE_H_
This diff is collapsed.
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Mar 17 2012)
// http://www.wxformbuilder.org/
//
// PLEASE DO "NOT" EDIT THIS FILE!
///////////////////////////////////////////////////////////////////////////
#include "dialog_regulator_data_base.h"
///////////////////////////////////////////////////////////////////////////
DIALOG_EDITOR_DATA_BASE::DIALOG_EDITOR_DATA_BASE( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : DIALOG_SHIM( parent, id, title, pos, size, style )
{
this->SetSizeHints( wxDefaultSize, wxDefaultSize );
wxBoxSizer* bSizerMain;
bSizerMain = new wxBoxSizer( wxVERTICAL );
wxFlexGridSizer* fgSizerPrms;
fgSizerPrms = new wxFlexGridSizer( 4, 3, 0, 0 );
fgSizerPrms->AddGrowableCol( 1 );
fgSizerPrms->AddGrowableRow( 0 );
fgSizerPrms->SetFlexibleDirection( wxHORIZONTAL );
fgSizerPrms->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED );
m_staticTextName = new wxStaticText( this, wxID_ANY, _("Name"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticTextName->Wrap( -1 );
fgSizerPrms->Add( m_staticTextName, 0, wxALL, 5 );
m_textCtrlName = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
fgSizerPrms->Add( m_textCtrlName, 0, wxALL|wxEXPAND, 5 );
fgSizerPrms->Add( 0, 0, 1, wxEXPAND, 5 );
m_staticTextVref = new wxStaticText( this, wxID_ANY, _("Vref"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticTextVref->Wrap( -1 );
fgSizerPrms->Add( m_staticTextVref, 0, wxALL, 5 );
m_textCtrlVref = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
fgSizerPrms->Add( m_textCtrlVref, 0, wxALL|wxEXPAND, 5 );
m_staticTextVrefUnit = new wxStaticText( this, wxID_ANY, _("Volt"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticTextVrefUnit->Wrap( -1 );
fgSizerPrms->Add( m_staticTextVrefUnit, 0, wxALL, 5 );
m_staticTextType = new wxStaticText( this, wxID_ANY, _("Type"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticTextType->Wrap( -1 );
fgSizerPrms->Add( m_staticTextType, 0, wxALL, 5 );
wxString m_choiceRegTypeChoices[] = { _("Separate sense pin"), _("3 terminals regulator") };
int m_choiceRegTypeNChoices = sizeof( m_choiceRegTypeChoices ) / sizeof( wxString );
m_choiceRegType = new wxChoice( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, m_choiceRegTypeNChoices, m_choiceRegTypeChoices, 0 );
m_choiceRegType->SetSelection( 0 );
fgSizerPrms->Add( m_choiceRegType, 0, wxALL|wxEXPAND, 5 );
fgSizerPrms->Add( 0, 0, 1, wxEXPAND, 5 );
m_RegulIadjTitle = new wxStaticText( this, wxID_ANY, _("Iadj"), wxDefaultPosition, wxDefaultSize, 0 );
m_RegulIadjTitle->Wrap( -1 );
fgSizerPrms->Add( m_RegulIadjTitle, 0, wxALL, 5 );
m_RegulIadjValue = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
fgSizerPrms->Add( m_RegulIadjValue, 0, wxALL|wxEXPAND, 5 );
m_IadjUnitLabel = new wxStaticText( this, wxID_ANY, _("uA"), wxDefaultPosition, wxDefaultSize, 0 );
m_IadjUnitLabel->Wrap( -1 );
fgSizerPrms->Add( m_IadjUnitLabel, 0, wxALL, 5 );
bSizerMain->Add( fgSizerPrms, 0, wxEXPAND, 5 );
m_staticline2 = new wxStaticLine( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL );
bSizerMain->Add( m_staticline2, 0, wxEXPAND | wxALL, 5 );
m_sdbSizerButtons = new wxStdDialogButtonSizer();
m_sdbSizerButtonsOK = new wxButton( this, wxID_OK );
m_sdbSizerButtons->AddButton( m_sdbSizerButtonsOK );
m_sdbSizerButtonsCancel = new wxButton( this, wxID_CANCEL );
m_sdbSizerButtons->AddButton( m_sdbSizerButtonsCancel );
m_sdbSizerButtons->Realize();
bSizerMain->Add( m_sdbSizerButtons, 0, wxEXPAND, 5 );
this->SetSizer( bSizerMain );
this->Layout();
this->Centre( wxBOTH );
// Connect Events
m_choiceRegType->Connect( wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler( DIALOG_EDITOR_DATA_BASE::OnRegTypeSelection ), NULL, this );
m_sdbSizerButtonsCancel->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EDITOR_DATA_BASE::OnCancelClick ), NULL, this );
m_sdbSizerButtonsOK->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EDITOR_DATA_BASE::OnOKClick ), NULL, this );
}
DIALOG_EDITOR_DATA_BASE::~DIALOG_EDITOR_DATA_BASE()
{
// Disconnect Events
m_choiceRegType->Disconnect( wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler( DIALOG_EDITOR_DATA_BASE::OnRegTypeSelection ), NULL, this );
m_sdbSizerButtonsCancel->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EDITOR_DATA_BASE::OnCancelClick ), NULL, this );
m_sdbSizerButtonsOK->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EDITOR_DATA_BASE::OnOKClick ), NULL, this );
}
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Mar 17 2012)
// http://www.wxformbuilder.org/
//
// PLEASE DO "NOT" EDIT THIS FILE!
///////////////////////////////////////////////////////////////////////////
#ifndef __DIALOG_REGULATOR_DATA_BASE_H__
#define __DIALOG_REGULATOR_DATA_BASE_H__
#include <wx/artprov.h>
#include <wx/xrc/xmlres.h>
#include <wx/intl.h>
#include "dialog_shim.h"
#include <wx/string.h>
#include <wx/stattext.h>
#include <wx/gdicmn.h>
#include <wx/font.h>
#include <wx/colour.h>
#include <wx/settings.h>
#include <wx/textctrl.h>
#include <wx/choice.h>
#include <wx/sizer.h>
#include <wx/statline.h>
#include <wx/button.h>
#include <wx/dialog.h>
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
/// Class DIALOG_EDITOR_DATA_BASE
///////////////////////////////////////////////////////////////////////////////
class DIALOG_EDITOR_DATA_BASE : public DIALOG_SHIM
{
private:
protected:
wxStaticText* m_staticTextName;
wxTextCtrl* m_textCtrlName;
wxStaticText* m_staticTextVref;
wxTextCtrl* m_textCtrlVref;
wxStaticText* m_staticTextVrefUnit;
wxStaticText* m_staticTextType;
wxChoice* m_choiceRegType;
wxStaticText* m_RegulIadjTitle;
wxTextCtrl* m_RegulIadjValue;
wxStaticText* m_IadjUnitLabel;
wxStaticLine* m_staticline2;
wxStdDialogButtonSizer* m_sdbSizerButtons;
wxButton* m_sdbSizerButtonsOK;
wxButton* m_sdbSizerButtonsCancel;
// Virtual event handlers, overide them in your derived class
virtual void OnRegTypeSelection( wxCommandEvent& event ) { event.Skip(); }
virtual void OnCancelClick( wxCommandEvent& event ) { event.Skip(); }
virtual void OnOKClick( wxCommandEvent& event ) { event.Skip(); }
public:
DIALOG_EDITOR_DATA_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Regulator Parameters"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 310,210 ), long style = wxDEFAULT_DIALOG_STYLE );
~DIALOG_EDITOR_DATA_BASE();
};
#endif //__DIALOG_REGULATOR_DATA_BASE_H__
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Jun 30 2011) // C++ code generated with wxFormBuilder (version Mar 17 2012)
// http://www.wxformbuilder.org/ // http://www.wxformbuilder.org/
// //
// PLEASE DO "NOT" EDIT THIS FILE! // PLEASE DO "NOT" EDIT THIS FILE!
...@@ -11,11 +11,7 @@ ...@@ -11,11 +11,7 @@
#include <wx/artprov.h> #include <wx/artprov.h>
#include <wx/xrc/xmlres.h> #include <wx/xrc/xmlres.h>
#include <wx/intl.h> #include <wx/intl.h>
class UNIT_SELECTOR_ANGLE; #include "UnitSelector.h"
class UNIT_SELECTOR_FREQUENCY;
class UNIT_SELECTOR_LEN;
class UNIT_SELECTOR_RESISTOR;
#include <wx/string.h> #include <wx/string.h>
#include <wx/menu.h> #include <wx/menu.h>
#include <wx/gdicmn.h> #include <wx/gdicmn.h>
...@@ -27,15 +23,16 @@ class UNIT_SELECTOR_RESISTOR; ...@@ -27,15 +23,16 @@ class UNIT_SELECTOR_RESISTOR;
#include <wx/image.h> #include <wx/image.h>
#include <wx/icon.h> #include <wx/icon.h>
#include <wx/statbmp.h> #include <wx/statbmp.h>
#include <wx/stattext.h>
#include <wx/sizer.h> #include <wx/sizer.h>
#include <wx/stattext.h>
#include <wx/statbox.h>
#include <wx/radiobut.h> #include <wx/radiobut.h>
#include <wx/textctrl.h> #include <wx/textctrl.h>
#include <wx/choice.h>
#include <wx/button.h> #include <wx/button.h>
#include <wx/filepicker.h>
#include <wx/panel.h> #include <wx/panel.h>
#include <wx/choice.h>
#include <wx/html/htmlwin.h> #include <wx/html/htmlwin.h>
#include <wx/statbox.h>
#include <wx/statline.h> #include <wx/statline.h>
#include <wx/grid.h> #include <wx/grid.h>
#include <wx/radiobox.h> #include <wx/radiobox.h>
...@@ -57,7 +54,8 @@ class PCB_CALCULATOR_FRAME_BASE : public wxFrame ...@@ -57,7 +54,8 @@ class PCB_CALCULATOR_FRAME_BASE : public wxFrame
wxStatusBar* m_statusBar; wxStatusBar* m_statusBar;
wxNotebook* m_Notebook; wxNotebook* m_Notebook;
wxPanel* m_panelRegulators; wxPanel* m_panelRegulators;
wxStaticBitmap* m_bitmapRegul; wxStaticBitmap* m_bitmapRegul4pins;
wxStaticBitmap* m_bitmapRegul3pins;
wxStaticText* m_RegulFormula; wxStaticText* m_RegulFormula;
wxRadioButton* m_rbRegulR1; wxRadioButton* m_rbRegulR1;
wxStaticText* m_labelRegultR1; wxStaticText* m_labelRegultR1;
...@@ -67,14 +65,25 @@ class PCB_CALCULATOR_FRAME_BASE : public wxFrame ...@@ -67,14 +65,25 @@ class PCB_CALCULATOR_FRAME_BASE : public wxFrame
wxStaticText* m_labelRegultR2; wxStaticText* m_labelRegultR2;
wxTextCtrl* m_RegulR2Value; wxTextCtrl* m_RegulR2Value;
wxStaticText* m_UnitRegultR1; wxStaticText* m_UnitRegultR1;
wxStaticText* m_lableVRef;
wxTextCtrl* m_RegulVrefValue;
wxStaticText* m_unitsVref;
wxRadioButton* m_rbRegulVout; wxRadioButton* m_rbRegulVout;
wxStaticText* m_labelVout; wxStaticText* m_labelVout;
wxTextCtrl* m_RegulVoutValue; wxTextCtrl* m_RegulVoutValue;
wxStaticText* m_unitsVout; wxStaticText* m_unitsVout;
wxStaticText* m_labelVRef;
wxTextCtrl* m_RegulVrefValue;
wxStaticText* m_unitsVref;
wxStaticText* m_RegulIadjTitle;
wxTextCtrl* m_RegulIadjValue;
wxStaticText* m_IadjUnitLabel;
wxStaticText* m_staticTextRegType;
wxChoice* m_choiceRegType;
wxButton* m_buttonCalculate; wxButton* m_buttonCalculate;
wxChoice* m_choiceRegulatorSelector;
wxStaticText* m_staticTextRegFile;
wxFilePickerCtrl* m_regulators_filePicker;
wxButton* m_buttonEditItem;
wxButton* m_buttonAddItem;
wxButton* m_buttonRemoveItem;
wxStaticText* m_RegulMessage; wxStaticText* m_RegulMessage;
wxPanel* m_panelTrackWidth; wxPanel* m_panelTrackWidth;
wxStaticText* m_staticTextTW_WarningMessage; wxStaticText* m_staticTextTW_WarningMessage;
...@@ -250,7 +259,13 @@ class PCB_CALCULATOR_FRAME_BASE : public wxFrame ...@@ -250,7 +259,13 @@ class PCB_CALCULATOR_FRAME_BASE : public wxFrame
wxPanel* m_panelShowClassPrms; wxPanel* m_panelShowClassPrms;
// Virtual event handlers, overide them in your derived class // Virtual event handlers, overide them in your derived class
virtual void OnRegulTypeSelection( wxCommandEvent& event ) { event.Skip(); }
virtual void OnRegulatorCalcButtonClick( wxCommandEvent& event ) { event.Skip(); } virtual void OnRegulatorCalcButtonClick( wxCommandEvent& event ) { event.Skip(); }
virtual void OnRegulatorSelection( wxCommandEvent& event ) { event.Skip(); }
virtual void OnDataFileSelection( wxFileDirPickerEvent& event ) { event.Skip(); }
virtual void OnEditRegulator( wxCommandEvent& event ) { event.Skip(); }
virtual void OnAddRegulator( wxCommandEvent& event ) { event.Skip(); }
virtual void OnRemoveRegulator( wxCommandEvent& event ) { event.Skip(); }
virtual void OnTWCalculateButt( wxCommandEvent& event ) { event.Skip(); } virtual void OnTWCalculateButt( wxCommandEvent& event ) { event.Skip(); }
virtual void OnElectricalSpacingUnitsSelection( wxCommandEvent& event ) { event.Skip(); } virtual void OnElectricalSpacingUnitsSelection( wxCommandEvent& event ) { event.Skip(); }
virtual void OnElectricalSpacingRefresh( wxCommandEvent& event ) { event.Skip(); } virtual void OnElectricalSpacingRefresh( wxCommandEvent& event ) { event.Skip(); }
...@@ -271,7 +286,7 @@ class PCB_CALCULATOR_FRAME_BASE : public wxFrame ...@@ -271,7 +286,7 @@ class PCB_CALCULATOR_FRAME_BASE : public wxFrame
public: public:
PCB_CALCULATOR_FRAME_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Pcb Calculator"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 670,465 ), long style = wxDEFAULT_FRAME_STYLE|wxRESIZE_BORDER|wxFULL_REPAINT_ON_RESIZE|wxTAB_TRAVERSAL ); PCB_CALCULATOR_FRAME_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Pcb Calculator"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 670,489 ), long style = wxDEFAULT_FRAME_STYLE|wxRESIZE_BORDER|wxFULL_REPAINT_ON_RESIZE|wxTAB_TRAVERSAL );
~PCB_CALCULATOR_FRAME_BASE(); ~PCB_CALCULATOR_FRAME_BASE();
......
...@@ -37,6 +37,10 @@ ...@@ -37,6 +37,10 @@
#include <colors_selection.h> #include <colors_selection.h>
#include <build_version.h> #include <build_version.h>
// Pcb_calculator data file extension:
const wxString PcbCalcDataFileExt( wxT("pcbcalc") );
// PCB_CALCULATOR_APP // PCB_CALCULATOR_APP
void EDA_APP::MacOpenFile(const wxString &fileName) void EDA_APP::MacOpenFile(const wxString &fileName)
......
...@@ -10,13 +10,22 @@ ...@@ -10,13 +10,22 @@
#include <transline.h> // Included for SUBST_PRMS_ID definition. #include <transline.h> // Included for SUBST_PRMS_ID definition.
#include <transline_ident.h> #include <transline_ident.h>
#include <attenuator_classes.h> #include <attenuator_classes.h>
#include <class_regulator_data.h>
extern const wxString PcbCalcDataFileExt;
/* Class PCB_CALCULATOR_FRAME_BASE /* Class PCB_CALCULATOR_FRAME_BASE
This is the main frame for this application This is the main frame for this application
*/ */
class PCB_CALCULATOR_FRAME : public PCB_CALCULATOR_FRAME_BASE class PCB_CALCULATOR_FRAME : public PCB_CALCULATOR_FRAME_BASE
{ {
public:
REGULATOR_LIST m_RegulatorList; // the list of known regulator
private: private:
bool m_RegulatorListChanged; // set to true when m_RegulatorList
// was modified, and the corresponging file
// must be rewritten
wxSize m_FrameSize; wxSize m_FrameSize;
wxPoint m_FramePos; wxPoint m_FramePos;
wxConfig * m_Config; wxConfig * m_Config;
...@@ -27,6 +36,7 @@ private: ...@@ -27,6 +36,7 @@ private:
ATTENUATOR * m_currAttenuator; ATTENUATOR * m_currAttenuator;
// List ofattenuators: ordered like in dialog menu list // List ofattenuators: ordered like in dialog menu list
std::vector <ATTENUATOR *> m_attenuator_list; std::vector <ATTENUATOR *> m_attenuator_list;
wxString m_lastSelectedRegulatorName; // last regulator name selected
public: public:
...@@ -46,6 +56,14 @@ private: ...@@ -46,6 +56,14 @@ private:
void ReadConfig(); void ReadConfig();
void WriteConfig(); void WriteConfig();
// R/W data files:
bool ReadDataFile();
bool WriteDataFile();
const wxString GetDataFilename()
{
return m_regulators_filePicker->GetPath();
}
// tracks width versus current functions: // tracks width versus current functions:
/** /**
* Function OnTWCalculateButt * Function OnTWCalculateButt
...@@ -150,6 +168,30 @@ private: ...@@ -150,6 +168,30 @@ private:
// Regulators Panel // Regulators Panel
void OnRegulatorCalcButtonClick( wxCommandEvent& event ); void OnRegulatorCalcButtonClick( wxCommandEvent& event );
void OnRegulTypeSelection( wxCommandEvent& event );
void OnRegulatorSelection( wxCommandEvent& event );
void OnDataFileSelection( wxFileDirPickerEvent& event );
void OnAddRegulator( wxCommandEvent& event );
void OnEditRegulator( wxCommandEvent& event );
void OnRemoveRegulator( wxCommandEvent& event );
/**
* Function RegulatorPageUpdate:
* Update the regulator page dialog display:
* enable the current regulator drawings and the formula used for calculations
*/
void RegulatorPageUpdate();
/**
* Function SelectLastSelectedRegulator
* select in choice box the last selected regulator
* (name in m_lastSelectedRegulatorName)
* and update the displayed values.
* if m_lastSelectedRegulatorName is empty, just calls
* RegulatorPageUpdate()
*/
void SelectLastSelectedRegulator();
void RegulatorsSolve(); void RegulatorsSolve();
public: public:
......
regulators
regulator
reg_iadj
reg_vref
reg_type
...@@ -26,32 +26,36 @@ ...@@ -26,32 +26,36 @@
#include <pcb_calculator.h> #include <pcb_calculator.h>
#include <UnitSelector.h> #include <UnitSelector.h>
#include <bitmaps.h> #include <bitmaps.h>
#define KEYWORD_FRAME_POSX wxT( "Pcb_calculator_Pos_x" ) #define KEYWORD_FRAME_POSX wxT( "Pcb_calculator_Pos_x" )
#define KEYWORD_FRAME_POSY wxT( "Pcb_calculator_Pos_y" ) #define KEYWORD_FRAME_POSY wxT( "Pcb_calculator_Pos_y" )
#define KEYWORD_FRAME_SIZEX wxT( "Pcb_calculator_Size_x" ) #define KEYWORD_FRAME_SIZEX wxT( "Pcb_calculator_Size_x" )
#define KEYWORD_FRAME_SIZEY wxT( "Pcb_calculator_Size_y" ) #define KEYWORD_FRAME_SIZEY wxT( "Pcb_calculator_Size_y" )
#define KEYWORD_TRANSLINE_SELECTION wxT( "Transline_selection" ) #define KEYWORD_TRANSLINE_SELECTION wxT( "Transline_selection" )
#define KEYWORD_PAGE_SELECTION wxT( "Page_selection" ) #define KEYWORD_PAGE_SELECTION wxT( "Page_selection" )
#define KEYWORD_COLORCODE_SELECTION wxT( "CC_selection" ) #define KEYWORD_COLORCODE_SELECTION wxT( "CC_selection" )
#define KEYWORD_ATTENUATORS_SELECTION wxT( "Att_selection" ) #define KEYWORD_ATTENUATORS_SELECTION wxT( "Att_selection" )
#define KEYWORD_BRDCLASS_SELECTION wxT( "BrdClass_selection" ) #define KEYWORD_BRDCLASS_SELECTION wxT( "BrdClass_selection" )
#define KEYWORD_ELECTRICAL_SPACING_SELECTION wxT( "ElectSpacing_selection" ) #define KEYWORD_ELECTRICAL_SPACING_SELECTION wxT( "ElectSpacing_selection" )
#define KEYWORD_ELECTRICAL_SPACING_VOLTAGE wxT( "ElectSpacing_voltage" ) #define KEYWORD_ELECTRICAL_SPACING_VOLTAGE wxT( "ElectSpacing_voltage" )
#define KEYWORD_REGUL_R1 wxT( "RegulR1" ) #define KEYWORD_REGUL_R1 wxT( "RegulR1" )
#define KEYWORD_REGUL_R2 wxT( "RegulR2" ) #define KEYWORD_REGUL_R2 wxT( "RegulR2" )
#define KEYWORD_REGUL_VREF wxT( "RegulVREF" ) #define KEYWORD_REGUL_VREF wxT( "RegulVREF" )
#define KEYWORD_REGUL_VOUT wxT( "RegulVOUT" ) #define KEYWORD_REGUL_VOUT wxT( "RegulVOUT" )
#define KEYWORD_REGUL_FILENAME wxT( "RegulListFilename" )
PCB_CALCULATOR_FRAME::PCB_CALCULATOR_FRAME( wxWindow * parent ) : #define KEYWORD_REGUL_SELECTED wxT( "RegulName" )
PCB_CALCULATOR_FRAME_BASE( parent ) #define KEYWORD_REGUL_TYPE wxT( "RegulType" )
#define KEYWORD_REGUL_LAST_PARAM wxT( "RegulLastParam" )
PCB_CALCULATOR_FRAME::PCB_CALCULATOR_FRAME( wxWindow* parent ) :
PCB_CALCULATOR_FRAME_BASE( parent )
{ {
m_currTransLine = NULL; m_currTransLine = NULL;
m_currTransLineType = default_type; m_currTransLineType = default_type;
m_currAttenuator = NULL; m_currAttenuator = NULL;
m_RegulatorListChanged = false;
m_Config = new wxConfig(); m_Config = new wxConfig();
// Populate transline list ordered like in dialog menu list // Populate transline list ordered like in dialog menu list
...@@ -61,6 +65,7 @@ PCB_CALCULATOR_FRAME::PCB_CALCULATOR_FRAME( wxWindow * parent ) : ...@@ -61,6 +65,7 @@ PCB_CALCULATOR_FRAME::PCB_CALCULATOR_FRAME( wxWindow * parent ) :
rectwaveguide_type, coax_type, c_microstrip_type, rectwaveguide_type, coax_type, c_microstrip_type,
stripline_type, twistedpair_type stripline_type, twistedpair_type
}; };
for( int ii = 0; ii < 8; ii++ ) for( int ii = 0; ii < 8; ii++ )
m_transline_list.push_back( new TRANSLINE_IDENT( tltype_list[ii] ) ); m_transline_list.push_back( new TRANSLINE_IDENT( tltype_list[ii] ) );
...@@ -73,6 +78,8 @@ PCB_CALCULATOR_FRAME::PCB_CALCULATOR_FRAME( wxWindow * parent ) : ...@@ -73,6 +78,8 @@ PCB_CALCULATOR_FRAME::PCB_CALCULATOR_FRAME( wxWindow * parent ) :
ReadConfig(); ReadConfig();
ReadDataFile();
TranslineTypeSelection( m_currTransLineType ); TranslineTypeSelection( m_currTransLineType );
m_TranslineSelection->SetSelection( m_currTransLineType ); m_TranslineSelection->SetSelection( m_currTransLineType );
...@@ -86,6 +93,10 @@ PCB_CALCULATOR_FRAME::PCB_CALCULATOR_FRAME( wxWindow * parent ) : ...@@ -86,6 +93,10 @@ PCB_CALCULATOR_FRAME::PCB_CALCULATOR_FRAME( wxWindow * parent ) :
ElectricalSpacingUpdateData( m_ElectricalSpacingUnitsSelector->GetUnitScale() ); ElectricalSpacingUpdateData( m_ElectricalSpacingUnitsSelector->GetUnitScale() );
m_choiceRegulatorSelector->Append( m_RegulatorList.GetRegList() );
SelectLastSelectedRegulator();
// Give an icon // Give an icon
wxIcon icon; wxIcon icon;
icon.CopyFromBitmap( KiBitmap( icon_pcbcalculator_xpm ) ); icon.CopyFromBitmap( KiBitmap( icon_pcbcalculator_xpm ) );
...@@ -104,6 +115,11 @@ PCB_CALCULATOR_FRAME::PCB_CALCULATOR_FRAME( wxWindow * parent ) : ...@@ -104,6 +115,11 @@ PCB_CALCULATOR_FRAME::PCB_CALCULATOR_FRAME( wxWindow * parent ) :
PCB_CALCULATOR_FRAME::~PCB_CALCULATOR_FRAME() PCB_CALCULATOR_FRAME::~PCB_CALCULATOR_FRAME()
{ {
WriteConfig(); WriteConfig();
if( m_RegulatorListChanged )
WriteDataFile();
for( unsigned ii = 0; ii < m_transline_list.size(); ii++ ) for( unsigned ii = 0; ii < m_transline_list.size(); ii++ )
delete m_transline_list[ii]; delete m_transline_list[ii];
...@@ -124,8 +140,8 @@ void PCB_CALCULATOR_FRAME::ReadConfig() ...@@ -124,8 +140,8 @@ void PCB_CALCULATOR_FRAME::ReadConfig()
if( m_Config == NULL ) if( m_Config == NULL )
return; return;
long ltmp; long ltmp;
wxString msg; wxString msg;
m_Config->Read( KEYWORD_FRAME_POSX, &m_FramePos.x, -1 ); m_Config->Read( KEYWORD_FRAME_POSX, &m_FramePos.x, -1 );
m_Config->Read( KEYWORD_FRAME_POSY, &m_FramePos.y, -1 ); m_Config->Read( KEYWORD_FRAME_POSY, &m_FramePos.y, -1 );
m_Config->Read( KEYWORD_FRAME_SIZEX, &m_FrameSize.x, -1 ); m_Config->Read( KEYWORD_FRAME_SIZEX, &m_FrameSize.x, -1 );
...@@ -140,21 +156,40 @@ void PCB_CALCULATOR_FRAME::ReadConfig() ...@@ -140,21 +156,40 @@ void PCB_CALCULATOR_FRAME::ReadConfig()
m_AttenuatorsSelection->SetSelection( ltmp ); m_AttenuatorsSelection->SetSelection( ltmp );
m_Config->Read( KEYWORD_BRDCLASS_SELECTION, &ltmp, 0 ); m_Config->Read( KEYWORD_BRDCLASS_SELECTION, &ltmp, 0 );
m_BoardClassesUnitsSelector->SetSelection( ltmp ); m_BoardClassesUnitsSelector->SetSelection( ltmp );
m_Config->Read( KEYWORD_REGUL_R1, &msg, wxT("10") );
// Regul panel config:
m_Config->Read( KEYWORD_REGUL_R1, &msg, wxT( "10" ) );
m_RegulR1Value->SetValue( msg ); m_RegulR1Value->SetValue( msg );
m_Config->Read( KEYWORD_REGUL_R2, &msg, wxT("10") ); m_Config->Read( KEYWORD_REGUL_R2, &msg, wxT( "10" ) );
m_RegulR2Value->SetValue( msg ); m_RegulR2Value->SetValue( msg );
m_Config->Read( KEYWORD_REGUL_VREF, &msg, wxT("3") ); m_Config->Read( KEYWORD_REGUL_VREF, &msg, wxT( "3" ) );
m_RegulVrefValue->SetValue( msg ); m_RegulVrefValue->SetValue( msg );
m_Config->Read( KEYWORD_REGUL_VOUT, &msg, wxT("12") ); m_Config->Read( KEYWORD_REGUL_VOUT, &msg, wxT( "12" ) );
m_RegulVoutValue->SetValue( msg ); m_RegulVoutValue->SetValue( msg );
m_Config->Read( KEYWORD_REGUL_FILENAME, &msg, wxT( "" ) );
m_regulators_filePicker->SetPath( msg );
m_Config->Read( KEYWORD_REGUL_SELECTED, &msg, wxT( "" ) );
m_lastSelectedRegulatorName = msg;
m_Config->Read( KEYWORD_REGUL_TYPE, &ltmp, 0 );
m_choiceRegType->SetSelection( ltmp );
m_Config->Read( KEYWORD_REGUL_LAST_PARAM, &ltmp, 0 );
wxRadioButton * regprms[3] =
{ m_rbRegulR1, m_rbRegulR2, m_rbRegulVout
};
if( (unsigned)ltmp >= 3 )
ltmp = 0;
for( int ii = 0; ii < 3; ii++ )
regprms[ii]->SetValue( ltmp == ii );
// Electrical panel config
m_Config->Read( KEYWORD_ELECTRICAL_SPACING_SELECTION, &ltmp, 0 ); m_Config->Read( KEYWORD_ELECTRICAL_SPACING_SELECTION, &ltmp, 0 );
m_ElectricalSpacingUnitsSelector->SetSelection( ltmp ); m_ElectricalSpacingUnitsSelector->SetSelection( ltmp );
m_Config->Read( KEYWORD_ELECTRICAL_SPACING_VOLTAGE, &msg, wxT("500") ); m_Config->Read( KEYWORD_ELECTRICAL_SPACING_VOLTAGE, &msg, wxT( "500" ) );
m_ElectricalSpacingVoltage->SetValue( msg ); m_ElectricalSpacingVoltage->SetValue( msg );
for( unsigned ii = 0; ii < m_transline_list.size(); ii++ ) for( unsigned ii = 0; ii < m_transline_list.size(); ii++ )
m_transline_list[ii]->ReadConfig( m_Config ); m_transline_list[ii]->ReadConfig( m_Config );
for( unsigned ii = 0; ii < m_attenuator_list.size(); ii++ ) for( unsigned ii = 0; ii < m_attenuator_list.size(); ii++ )
m_attenuator_list[ii]->ReadConfig( m_Config ); m_attenuator_list[ii]->ReadConfig( m_Config );
} }
...@@ -175,15 +210,34 @@ void PCB_CALCULATOR_FRAME::WriteConfig() ...@@ -175,15 +210,34 @@ void PCB_CALCULATOR_FRAME::WriteConfig()
m_Config->Write( KEYWORD_FRAME_SIZEX, (long) m_FrameSize.x ); m_Config->Write( KEYWORD_FRAME_SIZEX, (long) m_FrameSize.x );
m_Config->Write( KEYWORD_FRAME_SIZEY, (long) m_FrameSize.y ); m_Config->Write( KEYWORD_FRAME_SIZEY, (long) m_FrameSize.y );
} }
m_Config->Write( KEYWORD_TRANSLINE_SELECTION, (long) m_currTransLineType ); m_Config->Write( KEYWORD_TRANSLINE_SELECTION, (long) m_currTransLineType );
m_Config->Write( KEYWORD_PAGE_SELECTION, m_Notebook->GetSelection() ); m_Config->Write( KEYWORD_PAGE_SELECTION, m_Notebook->GetSelection() );
m_Config->Write( KEYWORD_COLORCODE_SELECTION, m_rbToleranceSelection->GetSelection() ); m_Config->Write( KEYWORD_COLORCODE_SELECTION, m_rbToleranceSelection->GetSelection() );
m_Config->Write( KEYWORD_ATTENUATORS_SELECTION, m_AttenuatorsSelection->GetSelection()); m_Config->Write( KEYWORD_ATTENUATORS_SELECTION, m_AttenuatorsSelection->GetSelection() );
m_Config->Write( KEYWORD_BRDCLASS_SELECTION, m_BoardClassesUnitsSelector->GetSelection() ); m_Config->Write( KEYWORD_BRDCLASS_SELECTION, m_BoardClassesUnitsSelector->GetSelection() );
m_Config->Write( KEYWORD_REGUL_R1, m_RegulR1Value->GetValue() ); m_Config->Write( KEYWORD_REGUL_R1, m_RegulR1Value->GetValue() );
m_Config->Write( KEYWORD_REGUL_R2, m_RegulR2Value->GetValue() ); m_Config->Write( KEYWORD_REGUL_R2, m_RegulR2Value->GetValue() );
m_Config->Write( KEYWORD_REGUL_VREF, m_RegulVrefValue->GetValue() ); m_Config->Write( KEYWORD_REGUL_VREF, m_RegulVrefValue->GetValue() );
m_Config->Write( KEYWORD_REGUL_VOUT, m_RegulVoutValue->GetValue() ); m_Config->Write( KEYWORD_REGUL_VOUT, m_RegulVoutValue->GetValue() );
m_Config->Write( KEYWORD_REGUL_FILENAME, m_regulators_filePicker->GetPath() );
m_Config->Write( KEYWORD_REGUL_SELECTED, m_lastSelectedRegulatorName );
m_Config->Write( KEYWORD_REGUL_TYPE,
m_choiceRegType->GetSelection() );
wxRadioButton * regprms[3] =
{ m_rbRegulR1, m_rbRegulR2, m_rbRegulVout
};
for( int ii = 0; ii < 3; ii++ )
{
if( regprms[ii]->GetValue() )
{
m_Config->Write( KEYWORD_REGUL_LAST_PARAM, ii );
break;
}
}
m_Config->Write( KEYWORD_ELECTRICAL_SPACING_SELECTION, m_Config->Write( KEYWORD_ELECTRICAL_SPACING_SELECTION,
m_ElectricalSpacingUnitsSelector->GetSelection() ); m_ElectricalSpacingUnitsSelector->GetSelection() );
m_Config->Write( KEYWORD_ELECTRICAL_SPACING_VOLTAGE, m_Config->Write( KEYWORD_ELECTRICAL_SPACING_VOLTAGE,
...@@ -193,12 +247,12 @@ void PCB_CALCULATOR_FRAME::WriteConfig() ...@@ -193,12 +247,12 @@ void PCB_CALCULATOR_FRAME::WriteConfig()
for( unsigned ii = 0; ii < m_transline_list.size(); ii++ ) for( unsigned ii = 0; ii < m_transline_list.size(); ii++ )
m_transline_list[ii]->WriteConfig( m_Config ); m_transline_list[ii]->WriteConfig( m_Config );
for( unsigned ii = 0; ii < m_attenuator_list.size(); ii++ ) for( unsigned ii = 0; ii < m_attenuator_list.size(); ii++ )
m_attenuator_list[ii]->WriteConfig( m_Config ); m_attenuator_list[ii]->WriteConfig( m_Config );
} }
/** /**
* Function OnTranslineAnalyse * Function OnTranslineAnalyse
* Run a new analyse for the current transline with current parameters * Run a new analyse for the current transline with current parameters
...@@ -213,6 +267,7 @@ void PCB_CALCULATOR_FRAME::OnTranslineAnalyse( wxCommandEvent& event ) ...@@ -213,6 +267,7 @@ void PCB_CALCULATOR_FRAME::OnTranslineAnalyse( wxCommandEvent& event )
} }
} }
/** /**
* Function OnTranslineSynthetize * Function OnTranslineSynthetize
* Run a new synthezis for the current transline with current parameters * Run a new synthezis for the current transline with current parameters
...@@ -230,14 +285,15 @@ void PCB_CALCULATOR_FRAME::OnTranslineSynthetize( wxCommandEvent& event ) ...@@ -230,14 +285,15 @@ void PCB_CALCULATOR_FRAME::OnTranslineSynthetize( wxCommandEvent& event )
void PCB_CALCULATOR_FRAME::OnPaintTranslinePanel( wxPaintEvent& event ) void PCB_CALCULATOR_FRAME::OnPaintTranslinePanel( wxPaintEvent& event )
{ {
wxPaintDC dc( m_panelDisplayshape ); wxPaintDC dc( m_panelDisplayshape );
TRANSLINE_IDENT* tr_ident = m_transline_list[m_currTransLineType];
TRANSLINE_IDENT* tr_ident = m_transline_list[m_currTransLineType];
if( tr_ident ) if( tr_ident )
{ {
wxSize size = m_panelDisplayshape->GetSize(); wxSize size = m_panelDisplayshape->GetSize();
size.x -= tr_ident->m_Icon->GetWidth(); size.x -= tr_ident->m_Icon->GetWidth();
size.y -= tr_ident->m_Icon->GetHeight(); size.y -= tr_ident->m_Icon->GetHeight();
dc.DrawBitmap( *tr_ident->m_Icon, size.x / 2, size.y / 2 ); dc.DrawBitmap( *tr_ident->m_Icon, size.x / 2, size.y / 2 );
} }
......
...@@ -28,14 +28,223 @@ ...@@ -28,14 +28,223 @@
#include <wx/config.h> #include <wx/config.h>
#include <pcb_calculator.h> #include <pcb_calculator.h>
#include <class_regulator_data.h>
#include <dialog_regulator_data_base.h>
extern double ReturnDoubleFromString( const wxString& TextValue ); extern double ReturnDoubleFromString( const wxString& TextValue );
class DIALOG_EDITOR_DATA: public DIALOG_EDITOR_DATA_BASE
{
public:
DIALOG_EDITOR_DATA( PCB_CALCULATOR_FRAME * parent, const wxString & aRegName )
: DIALOG_EDITOR_DATA_BASE( parent )
{
m_textCtrlName->SetValue( aRegName );
m_textCtrlName->Enable( aRegName.IsEmpty() );
UpdateDialog();
}
~DIALOG_EDITOR_DATA() {};
/**
* Function CopyRegulatorDataToDialog
* Transfert data from dialog to aItem
* @param aItem = a pointer to the REGULATOR_DATA
*/
void CopyRegulatorDataToDialog( REGULATOR_DATA * aItem );
/**
* Function BuildRegulatorFromData
* Creates a new REGULATOR_DATA from dialog
* @return a pointer to the new REGULATOR_DATA
*/
REGULATOR_DATA * BuildRegulatorFromData();
/**
* Enable/disable Iadj realted widgets, according to
* the regulator type
*/
void UpdateDialog()
{
bool enbl = m_choiceRegType->GetSelection() == 1;
m_RegulIadjValue->Enable( enbl );
m_RegulIadjTitle->Enable( enbl );
m_IadjUnitLabel->Enable( enbl );
}
/**
* called when the current regulator type is changed
*/
void OnRegTypeSelection( wxCommandEvent& event )
{
UpdateDialog();
}
};
void DIALOG_EDITOR_DATA::CopyRegulatorDataToDialog( REGULATOR_DATA * aItem )
{
m_textCtrlName->SetValue( aItem->m_Name );
wxString value;
value.Printf( wxT("%g"), aItem->m_Vref );
m_textCtrlVref->SetValue( value );
value.Printf( wxT("%g"), aItem->m_Iadj );
m_RegulIadjValue->SetValue( value );
m_choiceRegType->SetSelection( aItem->m_Type );
UpdateDialog();
}
REGULATOR_DATA * DIALOG_EDITOR_DATA::BuildRegulatorFromData()
{
double vref = ReturnDoubleFromString( m_textCtrlVref->GetValue() );
double iadj = ReturnDoubleFromString( m_RegulIadjValue->GetValue() );
int type = m_choiceRegType->GetSelection();
if( type != 1 )
iadj = 0.0;
REGULATOR_DATA * item = new REGULATOR_DATA( m_textCtrlName->GetValue(),
vref, type, iadj );
return item;
}
void PCB_CALCULATOR_FRAME::OnRegulatorCalcButtonClick( wxCommandEvent& event ) void PCB_CALCULATOR_FRAME::OnRegulatorCalcButtonClick( wxCommandEvent& event )
{ {
RegulatorsSolve(); RegulatorsSolve();
} }
void PCB_CALCULATOR_FRAME::RegulatorPageUpdate()
{
switch( m_choiceRegType->GetSelection() )
{
default:
case 0:
m_bitmapRegul4pins->Show( true );
m_bitmapRegul3pins->Show( false );
m_RegulIadjValue->Enable( false );
m_RegulIadjTitle->Enable( false );
m_IadjUnitLabel->Enable( false );
m_RegulFormula->SetLabel( wxT("Vout = Vref * (R1 + R2) / R2") );
break;
case 1:
m_bitmapRegul4pins->Show( false );
m_bitmapRegul3pins->Show( true );
m_RegulIadjValue->Enable( true );
m_RegulIadjTitle->Enable( true );
m_IadjUnitLabel->Enable( true );
m_RegulFormula->SetLabel( wxT("Vout = Vref * (R1 + R2) / R1 + Iadj * R2") );
break;
}
// The new icon size must be taken in account
m_panelRegulators->GetSizer()->Layout();
m_panelRegulators->Refresh();
}
void PCB_CALCULATOR_FRAME::OnRegulTypeSelection( wxCommandEvent& event )
{
RegulatorPageUpdate();
}
void PCB_CALCULATOR_FRAME::OnRegulatorSelection( wxCommandEvent& event )
{
wxString name = m_choiceRegulatorSelector->GetStringSelection();
REGULATOR_DATA * item = m_RegulatorList.GetReg( name );
if( item )
{
m_lastSelectedRegulatorName = item->m_Name;
m_choiceRegType->SetSelection( item->m_Type );
wxString value;
value.Printf( wxT("%g"), item->m_Vref );
m_RegulVrefValue->SetValue( value );
value.Printf( wxT("%g"), item->m_Iadj );
m_RegulIadjValue->SetValue( value );
RegulatorPageUpdate();
}
}
void PCB_CALCULATOR_FRAME::OnDataFileSelection( wxFileDirPickerEvent& event )
{
}
void PCB_CALCULATOR_FRAME::OnAddRegulator( wxCommandEvent& event )
{
DIALOG_EDITOR_DATA dlg( this, wxEmptyString );
if( dlg.ShowModal() != wxID_OK )
return;
REGULATOR_DATA * new_item = dlg.BuildRegulatorFromData();
// Add new item, if not existing
if( m_RegulatorList.GetReg( new_item->m_Name ) == NULL )
{
// Add item in list
m_RegulatorList.Add( new_item );
m_RegulatorListChanged = true;
m_choiceRegulatorSelector->Clear();
m_choiceRegulatorSelector->Append( m_RegulatorList.GetRegList() );
SelectLastSelectedRegulator();
}
else
{
wxMessageBox( _("This regulator is already in list. Aborted") );
delete new_item;
}
}
void PCB_CALCULATOR_FRAME::OnEditRegulator( wxCommandEvent& event )
{
wxString name = m_choiceRegulatorSelector->GetStringSelection();
REGULATOR_DATA * item = m_RegulatorList.GetReg( name );
DIALOG_EDITOR_DATA dlg( this, name );
dlg.CopyRegulatorDataToDialog( item );
if( dlg.ShowModal() != wxID_OK )
return;
REGULATOR_DATA * new_item = dlg.BuildRegulatorFromData();
m_RegulatorList.Replace( new_item );
m_RegulatorListChanged = true;
SelectLastSelectedRegulator();
}
void PCB_CALCULATOR_FRAME::OnRemoveRegulator( wxCommandEvent& event )
{
wxString name = wxGetSingleChoice( _("Remove Regulator"), wxEmptyString,
m_RegulatorList.GetRegList() );
if( name.IsEmpty() )
return;
m_RegulatorList.Remove( name );
m_RegulatorListChanged = true;
m_choiceRegulatorSelector->Clear();
m_choiceRegulatorSelector->Append( m_RegulatorList.GetRegList() );
if( m_lastSelectedRegulatorName == name )
m_lastSelectedRegulatorName.Empty();
SelectLastSelectedRegulator();
}
void PCB_CALCULATOR_FRAME::SelectLastSelectedRegulator()
{
// Find last selected in regulator list:
int idx = -1;
if( ! m_lastSelectedRegulatorName.IsEmpty() )
{
for( unsigned ii = 0; ii < m_RegulatorList.GetCount(); ii++ )
if( m_RegulatorList.m_List[ii]->m_Name == m_lastSelectedRegulatorName )
{
idx = ii;
break;
}
}
m_choiceRegulatorSelector->SetSelection( idx );
wxCommandEvent event;
OnRegulatorSelection( event );
}
// Calculate a value from the 3 other values // Calculate a value from the 3 other values
// Vref is given by the regulator properties, so // Vref is given by the regulator properties, so
// we can calculate only R1, R2 or Vout // we can calculate only R1, R2 or Vout
...@@ -60,16 +269,21 @@ void PCB_CALCULATOR_FRAME::RegulatorsSolve() ...@@ -60,16 +269,21 @@ void PCB_CALCULATOR_FRAME::RegulatorsSolve()
m_RegulMessage->SetLabel( wxEmptyString); m_RegulMessage->SetLabel( wxEmptyString);
// Convert r1 and r2 in ohms
int r1scale = 1000;
int r2scale = 1000;
// Read values from panel: // Read values from panel:
txt = m_RegulR1Value->GetValue(); txt = m_RegulR1Value->GetValue();
r1 = ReturnDoubleFromString(txt); r1 = ReturnDoubleFromString(txt) * r1scale;
txt = m_RegulR2Value->GetValue(); txt = m_RegulR2Value->GetValue();
r2 = ReturnDoubleFromString(txt); r2 = ReturnDoubleFromString(txt) * r2scale;
txt = m_RegulVrefValue->GetValue(); txt = m_RegulVrefValue->GetValue();
vref = ReturnDoubleFromString(txt); vref = ReturnDoubleFromString(txt);
txt = m_RegulVoutValue->GetValue(); txt = m_RegulVoutValue->GetValue();
vout = ReturnDoubleFromString(txt); vout = ReturnDoubleFromString(txt);
// Some tests: // Some tests:
if( vout < vref && id != 2) if( vout < vref && id != 2)
{ {
...@@ -90,24 +304,51 @@ void PCB_CALCULATOR_FRAME::RegulatorsSolve() ...@@ -90,24 +304,51 @@ void PCB_CALCULATOR_FRAME::RegulatorsSolve()
} }
// Calculate // Calculate
switch( id ) if( m_choiceRegType->GetSelection() == 1)
{ { // 3 terminal regulator
case 0: txt = m_RegulIadjValue->GetValue();
r1 = ( vout / vref - 1 ) * r2; double iadj = ReturnDoubleFromString(txt);
break; // iadj is given in micro amp, so convert it in amp.
iadj /= 1000000;
case 1: switch( id )
r2 = r1 / ( vout / vref - 1); {
break; case 0:
r1 = vref * r2 / ( vout - vref - (r2 * iadj) );
break;
case 2: case 1:
vout = vref * (r1 + r2) / r2; // to do
break; r2 = ( vout - vref ) / ( iadj + (vref/r1) );
break;
case 2:
vout = vref * (r1 + r2) / r1;
vout += r2 * iadj;
break;
}
}
else
{ // Standard 4 terminal regulator
switch( id )
{
case 0:
r1 = ( vout / vref - 1 ) * r2;
break;
case 1:
r2 = r1 / ( vout / vref - 1);
break;
case 2:
vout = vref * (r1 + r2) / r2;
break;
}
} }
// write values to panel: // write values to panel:
txt.Printf(wxT("%g"), r1); txt.Printf(wxT("%g"), r1 / r1scale );
m_RegulR1Value->SetValue(txt); m_RegulR1Value->SetValue(txt);
txt.Printf(wxT("%g"), r2); txt.Printf(wxT("%g"), r2 / r2scale);
m_RegulR2Value->SetValue(txt); m_RegulR2Value->SetValue(txt);
txt.Printf(wxT("%g"), vref); txt.Printf(wxT("%g"), vref);
m_RegulVrefValue->SetValue(txt); m_RegulVrefValue->SetValue(txt);
......
...@@ -118,7 +118,7 @@ bool NETLIST_READER::ReadKicadNetList( FILE* aFile ) ...@@ -118,7 +118,7 @@ bool NETLIST_READER::ReadKicadNetList( FILE* aFile )
{ {
BOARD * brd = m_pcbframe ? m_pcbframe->GetBoard() : NULL; BOARD * brd = m_pcbframe ? m_pcbframe->GetBoard() : NULL;
// netlineReader dtor will close aFile // netlineReader dtor will close aFile
FILE_LINE_READER netlineReader( aFile, m_netlistFullName ); FILE_LINE_READER netlineReader( aFile, m_netlistFullName );
NETLIST_READER_KICAD_PARSER netlist_parser( &netlineReader, this ); NETLIST_READER_KICAD_PARSER netlist_parser( &netlineReader, this );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment