Added crystals to database and new units of measure

This commit is contained in:
Edward Hennessy 2010-09-23 22:02:31 -07:00
parent 3a048a6a69
commit b56ae2d4bc
8 changed files with 388 additions and 21 deletions

17
data/epson-crystals.sql Normal file
View File

@ -0,0 +1,17 @@
CALL AddCompany(
"Epson Toyocom Corporation"
);
CALL AddCrystal(
"Epson Toyocom Corporation",
"MA-505 14.3180M-C0",
"MA-505",
"CRYSTAL",
14.31818e6,
30e-6,
50e-6,
18e-12,
20,
70
);

View File

@ -110,6 +110,11 @@ CALL AddPackage(
'SMT'
);
CALL AddPackage(
"MA-505",
'SMT'
);
CALL AddPackage(
"SC-59",
'SMT'

View File

@ -16,6 +16,8 @@ create database GParts;
use GParts;
source sql/mysql/create-basic.sql;
--source sql/mysql/create-crystals.sql;
source sql/mysql/create-discretes.sql;
source sql/mysql/create-passives.sql;
source sql/mysql/create-categories.sql;

View File

@ -21,6 +21,18 @@
--
-- ---------------------------------------------------------------------------
CALL AddCategory(
"Batteries",
"BatteryV",
"UNKNOWN"
);
CALL AddCategory(
"Crystals",
"CrystalV",
"UNKNOWN"
);
CALL AddCategory(
"Discretes",
NULL,

View File

@ -0,0 +1,106 @@
-- ---------------------------------------------------------------------------
--
-- gEDA - GPL Electronic Design Automation
-- gparts - gEDA Parts Manager
-- Copyright (C) 2009 Edward C. Hennessy
-- Copyright (C) 2009 gEDA Contributors (see ChangeLog for details)
--
-- 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, write to the Free Software
-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA
--
-- ---------------------------------------------------------------------------
--
-- Create additional tables for storing crystals.
--
-- These tables store additional information to allow quick selection of
-- passive electronic components.
--
-- Create a table for crystals.
--
CREATE TABLE Crystal (
PartID INTEGER UNSIGNED NOT NULL,
PackageID INTEGER UNSIGNED NOT NULL,
Frequency FLOAT NOT NULL,
Stability FLOAT NOT NULL,
Tolerance FLOAT NOT NULL,
Capacitance FLOAT NOT NULL,
MinTemp FLOAT NOT NULL,
MaxTemp FLOAT NOT NULL,
PRIMARY KEY ( PartID )
);
-- Create a view for crystals.
--
CREATE VIEW CrystalV AS
SELECT
Company.CompanyName,
Part.PartNumber,
Package.PackageName,
Crystal.Frequency,
Crystal.Stability,
Crystal.Tolerance,
Crystal.Capacitance,
Crystal.MinTemp,
Crystal.MaxTemp,
Part.DeviceID
FROM Crystal
JOIN Part USING ( PartID )
JOIN Package USING ( PackageID )
JOIN Company USING ( CompanyID );
-- Add a crystal to the GParts database
--
DELIMITER $$
CREATE PROCEDURE AddCrystal(
IN CompanyName VARCHAR(500),
IN PartNumber VARCHAR(500),
IN PackageName VARCHAR(500),
IN DeviceName VARCHAR(500),
IN Frequency FLOAT,
IN Stability FLOAT,
IN Tolerance FLOAT,
IN Capacitance FLOAT,
IN MinTemp FLOAT,
IN MaxTemp FLOAT
)
BEGIN
CALL AddPart(
CompanyName,
PartNumber,
DeviceName
);
INSERT INTO Crystal ( PartID, PackageID, Frequency, Stability, Tolerance, Capacitance, MinTemp, MaxTemp ) VALUES (
( SELECT PartID
FROM Part JOIN Company USING ( CompanyID )
WHERE Company.CompanyName = CompanyName AND Part.PartNumber = PartNumber
),
( SELECT PackageID FROM Package WHERE PackageName = Package.PackageName ),
Frequency,
Stability,
Tolerance,
Capacitance,
MinTemp,
MaxTemp
);
END$$
DELIMITER ;

View File

@ -206,16 +206,20 @@ gparts_mysql_result_get_column_in_units(const gchar *name, gdouble value)
{ "PD", gparts_units_new_watts },
{ "IC", gparts_units_new_amps },
{ "FT", gparts_units_new_hertz },
{ "Frequency", gparts_units_new_hertz },
{ "Inductance", gparts_units_new_henrys },
{ "IF", gparts_units_new_amps },
{ "Resistance", gparts_units_new_ohms },
{ "Tolerance", gparts_units_new_percent },
{ "Tolerance", gparts_units_new_pp },
{ "Stability", gparts_units_new_pp },
{ "VBR", gparts_units_new_volts },
{ "VZ", gparts_units_new_volts },
{ "VF", gparts_units_new_volts },
{ "VR", gparts_units_new_volts },
{ "VRWM", gparts_units_new_volts },
{ "VZ", gparts_units_new_volts },
{ "MinTemp", gparts_units_new_celcius },
{ "MaxTemp", gparts_units_new_celcius },
{ NULL, gparts_units_new_none }
};

View File

@ -32,8 +32,9 @@
*/
//#ifdef __STDC__VERSION__
//#if __STDC_VERSION__ >= 199901L
#define GPARTS_SYMBOL_MICRO "\u00B5"
#define GPARTS_SYMBOL_OHM "\u2126"
#define GPARTS_SYMBOL_CELCIUS "\u00B0C"
#define GPARTS_SYMBOL_MICRO "\u00B5"
#define GPARTS_SYMBOL_OHM "\u2126"
//#endif
//#else
//#define GPARTS_SYMBOL_MICRO "u"
@ -98,6 +99,7 @@ static const GPartsUnitsMetricPrefix gparts_units_metric_prefixes[] =
{ "", "", 0 },
};
static const gchar*
gparts_units_find_format(gdouble value);
@ -110,6 +112,9 @@ gparts_units_transform(const GValue *src_value, GValue *dest_value);
static void
gparts_units_transform_percent(const GValue *src_value, GValue *dest_value);
static void
gparts_units_transform_pp(const GValue *src_value, GValue *dest_value);
static void
gparts_units_transform_std(const GValue *src_value, GValue *dest_value);
@ -187,6 +192,18 @@ gparts_units_free(GPartsUnits *units)
g_free(units);
}
GPartsUnits*
gparts_units_new_amphours(gdouble amphours)
{
GPartsUnits *units = GPARTS_UNITS(g_malloc(sizeof(GPartsUnits)));
units->value = amphours;
units->func = gparts_units_transform_std;
units->symbol = "Ah";
return units;
}
GPartsUnits*
gparts_units_new_amps(gdouble amps)
{
@ -199,6 +216,18 @@ gparts_units_new_amps(gdouble amps)
return units;
}
GPartsUnits*
gparts_units_new_celcius(gdouble celcius)
{
GPartsUnits *units = GPARTS_UNITS(g_malloc(sizeof(GPartsUnits)));
units->value = celcius;
units->func = gparts_units_transform_std;
units->symbol = GPARTS_SYMBOL_CELCIUS;
return units;
}
GPartsUnits*
gparts_units_new_farads(gdouble farads)
{
@ -211,6 +240,18 @@ gparts_units_new_farads(gdouble farads)
return units;
}
GPartsUnits*
gparts_units_new_grams(gdouble grams)
{
GPartsUnits *units = GPARTS_UNITS(g_malloc(sizeof(GPartsUnits)));
units->value = grams;
units->func = gparts_units_transform_std;
units->symbol = "g";
return units;
}
GPartsUnits*
gparts_units_new_henrys(gdouble henrys)
{
@ -235,6 +276,18 @@ gparts_units_new_hertz(gdouble hertz)
return units;
}
GPartsUnits*
gparts_units_new_meters(gdouble meters)
{
GPartsUnits *units = GPARTS_UNITS(g_malloc(sizeof(GPartsUnits)));
units->value = meters;
units->func = gparts_units_transform_std;
units->symbol = "m";
return units;
}
GPartsUnits*
gparts_units_new_none(gdouble value)
{
@ -247,18 +300,6 @@ gparts_units_new_none(gdouble value)
return units;
}
GPartsUnits*
gparts_units_new_percent(gdouble ohms)
{
GPartsUnits *units = GPARTS_UNITS(g_malloc(sizeof(GPartsUnits)));
units->value = ohms;
units->func = gparts_units_transform_percent;
units->symbol = "%";
return units;
}
GPartsUnits*
gparts_units_new_ohms(gdouble ohms)
{
@ -271,6 +312,29 @@ gparts_units_new_ohms(gdouble ohms)
return units;
}
GPartsUnits*
gparts_units_new_percent(gdouble percent)
{
GPartsUnits *units = GPARTS_UNITS(g_malloc(sizeof(GPartsUnits)));
units->value = percent;
units->func = gparts_units_transform_percent;
units->symbol = "%";
return units;
}
GPartsUnits*
gparts_units_new_pp(gdouble pp)
{
GPartsUnits *units = GPARTS_UNITS(g_malloc(sizeof(GPartsUnits)));
units->value = pp;
units->func = gparts_units_transform_pp;
units->symbol = NULL;
return units;
}
GPartsUnits*
gparts_units_new_volts(gdouble volts)
@ -345,6 +409,63 @@ gparts_units_transform_percent(const GValue *src_value, GValue *dest_value)
}
}
static void
gparts_units_transform_pp(const GValue *src_value, GValue *dest_value)
{
if (G_IS_VALUE(src_value))
{
GPartsUnits *units = g_value_get_boxed(src_value);
GString *string = g_string_new("");
gdouble pp = units->value;
gint digits = 0;
const gchar *symbol;
if (fabs(pp) >= 1e-3)
{
pp *= 100;
symbol = "%";
}
else if (fabs(pp) >= 1e-6)
{
pp *= 1e6;
symbol = "ppm";
}
else if (fabs(pp) >= 1e-9)
{
pp *= 1e9;
symbol = "ppb";
}
else if (fabs(pp) >= 1e-12)
{
pp *= 1e12;
symbol = "ppt";
}
else
{
pp *= 1e15;
symbol = "ppq";
}
if (pp != 0)
{
digits = ceil(-log10(fabs(pp)));
if (digits < 0)
{
digits = 0;
}
}
g_string_printf(string, "%.*f %s", digits, pp, symbol);
g_value_take_string(dest_value, string->str);
g_string_free(string, FALSE);
}
else
{
g_value_set_string(dest_value, "Error");
}
}
static void
gparts_units_transform_std(const GValue *src_value, GValue *dest_value)

View File

@ -22,6 +22,13 @@
*
* \brief Data type for storing a value with a unit of measure.
*
* This data type can be transformed into strings using g_value_transform().
*
* \todo Implement inches.
* \todo Implement a monetary units (for budgetary cost, etc...).
* \todo Implement seconds.
* \todo Should an \a each units be implemented?
*
* The creation functions have the same signature to allow them to be used
* in tables of function pointers.
*/
@ -31,6 +38,7 @@
typedef struct _GPartsUnits GPartsUnits;
/*! \private */
GType
gparts_units_get_type(void);
@ -39,7 +47,7 @@ gparts_units_get_type(void);
* When no longer needed, the caller must call gparts_units_free()
* on the returned pointer.
*
* \param [in] style The GPartsUnits to be copied
* \param [in] units The GPartsUnits to be copied
* \return A pointer to the copied GPartsUnits
*/
GPartsUnits*
@ -49,12 +57,26 @@ gparts_units_copy(const GPartsUnits *units);
*
* When passing in a NULL pointer, this function does nothing.
*
* \param [in] style The GPartsUnits to be freed
* \param [in] units The GPartsUnits to be freed
*/
void
gparts_units_free(GPartsUnits *units);
/*! \brief Create a new value with a measurement in amphours.
*
* When no longer needed, the caller must call gparts_units_free()
* on the returned pointer.
*
* \param [in] amphours The value in amphours.
* \return A pointer to a new GPartsUnits boxed type
*/
GPartsUnits*
gparts_units_new_amphours(gdouble amphours);
/*! \brief Create a new value with a measurement in amps.
*
* When no longer needed, the caller must call gparts_units_free()
* on the returned pointer.
*
* \param [in] amps The current in amps.
* \return A pointer to a new GPartsUnits boxed type
@ -62,7 +84,21 @@ gparts_units_free(GPartsUnits *units);
GPartsUnits*
gparts_units_new_amps(gdouble amps);
/*! \brief Create a new value with a measurement in Celsius.
*
* When no longer needed, the caller must call gparts_units_free()
* on the returned pointer.
*
* \param [in] celcius The temperature in Celcius.
* \return A pointer to a new GPartsUnits boxed type
*/
GPartsUnits*
gparts_units_new_celcius(gdouble celcius);
/*! \brief Create a new value with a measurement in farads.
*
* When no longer needed, the caller must call gparts_units_free()
* on the returned pointer.
*
* \param [in] amps The capacitance in farads.
* \return A pointer to a new GPartsUnits boxed type
@ -70,24 +106,54 @@ gparts_units_new_amps(gdouble amps);
GPartsUnits*
gparts_units_new_farads(gdouble farads);
/*! \brief Create a new value with a measurement in henrys.
/*! \brief Create a new value with a measurement in grams.
*
* \param [in] amps The inductance in henrys.
* When no longer needed, the caller must call gparts_units_free()
* on the returned pointer.
*
* \param [in] grams The value in grams.
* \return A pointer to a new GPartsUnits boxed type
*/
GPartsUnits*
gparts_units_new_grams(gdouble grams);
/*! \brief Create a new value with a measurement in Henrys.
*
* When no longer needed, the caller must call gparts_units_free()
* on the returned pointer.
*
* \param [in] henrys The inductance in Henrys.
* \return A pointer to a new GPartsUnits boxed type
*/
GPartsUnits*
gparts_units_new_henrys(gdouble henrys);
/*! \brief Create a new value with a measurement in hertz.
/*! \brief Create a new value with a measurement in Hertz.
*
* \param [in] hertz The inductance in hertz
* When no longer needed, the caller must call gparts_units_free()
* on the returned pointer.
*
* \param [in] hertz The frequency in Hertz
* \return A pointer to a new GPartsUnits boxed type
*/
GPartsUnits*
gparts_units_new_hertz(gdouble hertz);
/*! \brief Create a new value with a measurement in meters.
*
* When no longer needed, the caller must call gparts_units_free()
* on the returned pointer.
*
* \param [in] meters The distance in meters
* \return A pointer to a new GPartsUnits boxed type
*/
GPartsUnits*
gparts_units_new_meters(gdouble meters);
/*! \brief Create a new value, unitless, but with SI unit prefixes.
*
* When no longer needed, the caller must call gparts_units_free()
* on the returned pointer.
*
* \param [in] value The value
* \return A pointer to a new GPartsUnits boxed type
@ -96,6 +162,9 @@ GPartsUnits*
gparts_units_new_none(gdouble value);
/*! \brief Create a new value with a measurment in ohms.
*
* When no longer needed, the caller must call gparts_units_free()
* on the returned pointer.
*
* \param [in] ohms The resistance in ohms
* \return A pointer to a new GPartsUnits boxed type
@ -104,6 +173,9 @@ GPartsUnits*
gparts_units_new_ohms(gdouble ohms);
/*! \brief Create a percentage
*
* When no longer needed, the caller must call gparts_units_free()
* on the returned pointer.
*
* \param [in] percent The percentge
* \return A pointer to a new GPartsUnits boxed type
@ -111,7 +183,32 @@ gparts_units_new_ohms(gdouble ohms);
GPartsUnits*
gparts_units_new_percent(gdouble percent);
/*! \brief Create a new value in parts per notation
*
* Similar to percent, however, the units are:
*
* <table>
* <tr><td>%</td><td>Parts per hundred</td></tr>
* <tr><td>ppm</td><td>Parts per million</td></tr>
* <tr><td>ppb</td><td>Parts per billion</td></tr>
* <tr><td>ppt</td><td>Parts per trillion</td></tr>
* <tr><td>ppq</td><td>Parts per quadrillion</td></tr>
* </table>
*
* When no longer needed, the caller must call gparts_units_free()
* on the returned pointer.
*
* \param [in] pp The amount in parts per unit
* \return A pointer to a new GPartsUnits boxed type
*/
GPartsUnits*
gparts_units_new_pp(gdouble pp);
/*! \brief Create a new value with a measurement in volts.
*
* When no longer needed, the caller must call gparts_units_free()
* on the returned pointer.
*
* \param [in] volts The voltage in volts
* \return A pointer to a new GPartsUnits boxed type
@ -120,6 +217,9 @@ GPartsUnits*
gparts_units_new_volts(gdouble volts);
/*! \brief Create a new value with a measurement in watts.
*
* When no longer needed, the caller must call gparts_units_free()
* on the returned pointer.
*
* \param [in] watts The wattage in watts
* \return A pointer to a new GPartsUnits boxed type