Skip to content

Commit

Permalink
add datasheet and description attributes to part
Browse files Browse the repository at this point in the history
  • Loading branch information
carrotIndustries committed Dec 31, 2017
1 parent e7b578b commit a016c9e
Show file tree
Hide file tree
Showing 9 changed files with 123 additions and 16 deletions.
4 changes: 4 additions & 0 deletions pool-mgr/part_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,14 @@ namespace horizon {
w_mpn = add_entry("part_mpn_box");
w_value =add_entry("part_value_box");
w_manufacturer =add_entry("part_manufacturer_box");
w_datasheet =add_entry("part_datasheet_box");
w_description =add_entry("part_description_box");

attr_editors.emplace(horizon::Part::Attribute::MPN, w_mpn);
attr_editors.emplace(horizon::Part::Attribute::VALUE, w_value);
attr_editors.emplace(horizon::Part::Attribute::MANUFACTURER, w_manufacturer);
attr_editors.emplace(horizon::Part::Attribute::DESCRIPTION, w_description);
attr_editors.emplace(horizon::Part::Attribute::DATASHEET, w_datasheet);


for(auto &it: attr_editors) {
Expand Down
2 changes: 2 additions & 0 deletions pool-mgr/part_editor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ namespace horizon {
class EntryWithInheritance *w_mpn = nullptr;
class EntryWithInheritance *w_value = nullptr;
class EntryWithInheritance *w_manufacturer = nullptr;
class EntryWithInheritance *w_description = nullptr;
class EntryWithInheritance *w_datasheet = nullptr;
std::map<Part::Attribute, class EntryWithInheritance*> attr_editors;


Expand Down
78 changes: 68 additions & 10 deletions pool-mgr/part_editor.ui
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.20.1 -->
<!-- Generated with glade 3.20.2 -->
<interface>
<requires lib="gtk+" version="3.18"/>
<object class="GtkBox" id="part_editor">
Expand Down Expand Up @@ -80,7 +80,7 @@
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">6</property>
<property name="top_attach">8</property>
</packing>
</child>
<child>
Expand All @@ -95,7 +95,7 @@
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">7</property>
<property name="top_attach">9</property>
</packing>
</child>
<child>
Expand All @@ -110,7 +110,7 @@
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">3</property>
<property name="top_attach">5</property>
</packing>
</child>
<child>
Expand All @@ -120,7 +120,7 @@
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">3</property>
<property name="top_attach">5</property>
</packing>
</child>
<child>
Expand Down Expand Up @@ -228,7 +228,7 @@
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">4</property>
<property name="top_attach">6</property>
</packing>
</child>
<child>
Expand All @@ -240,7 +240,7 @@
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">6</property>
<property name="top_attach">8</property>
</packing>
</child>
<child>
Expand Down Expand Up @@ -277,7 +277,7 @@
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">7</property>
<property name="top_attach">9</property>
</packing>
</child>
<child>
Expand All @@ -292,7 +292,7 @@
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">5</property>
<property name="top_attach">7</property>
</packing>
</child>
<child>
Expand All @@ -304,7 +304,65 @@
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">5</property>
<property name="top_attach">7</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">end</property>
<property name="label" translatable="yes">Datasheet</property>
<style>
<class name="dim-label"/>
</style>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">3</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">end</property>
<property name="label" translatable="yes">Description</property>
<style>
<class name="dim-label"/>
</style>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">4</property>
</packing>
</child>
<child>
<object class="GtkBox" id="part_datasheet_box">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">3</property>
</packing>
</child>
<child>
<object class="GtkBox" id="part_description_box">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">4</property>
</packing>
</child>
<child>
Expand Down
5 changes: 3 additions & 2 deletions pool-update/pool-update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,12 +272,13 @@ namespace horizon {
if(!skipthis) {
status_cb(PoolUpdateStatus::FILE, filename);
auto part = Part::new_from_file(filename, pool);
SQLite::Query q(db, "INSERT INTO parts (uuid, MPN, manufacturer, entity, package, filename) VALUES ($uuid, $MPN, $manufacturer, $entity, $package, $filename)");
SQLite::Query q(db, "INSERT INTO parts (uuid, MPN, manufacturer, entity, package, description, filename) VALUES ($uuid, $MPN, $manufacturer, $entity, $package, $description, $filename)");
q.bind("$uuid", part.uuid);
q.bind("$MPN", part.get_MPN());
q.bind("$manufacturer", part.get_manufacturer());
q.bind("$package", part.package->uuid);
q.bind("$entity", part.entity->uuid);
q.bind("$description", part.get_description());
q.bind("$filename", Glib::build_filename(prefix, it));
q.step();

Expand Down Expand Up @@ -305,7 +306,7 @@ namespace horizon {

void status_cb_nop(PoolUpdateStatus st, const std::string msg) {}

static const int min_user_version = 2; //keep in sync with schema
static const int min_user_version = 3; //keep in sync with schema

void pool_update(const std::string &pool_base_path, pool_update_cb_t status_cb) {
auto pool_db_path = Glib::build_filename(pool_base_path, "pool.db");
Expand Down
3 changes: 2 additions & 1 deletion pool-update/schema.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
PRAGMA user_version=2;
PRAGMA user_version=3;

DROP TABLE IF EXISTS "units";
CREATE TABLE "units" (
Expand Down Expand Up @@ -47,6 +47,7 @@ CREATE TABLE "parts" (
`manufacturer` TEXT,
`entity` TEXT NOT NULL,
`package` TEXT NOT NULL,
`description` TEXT NOT NULL,
`filename` TEXT,
PRIMARY KEY(`uuid`)
);
Expand Down
28 changes: 28 additions & 0 deletions pool/part.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ namespace horizon {
attributes[Attribute::MPN] = {j.at("MPN").at(0).get<bool>(), j.at("MPN").at(1).get<std::string>()};
attributes[Attribute::VALUE] = {j.at("value").at(0).get<bool>(), j.at("value").at(1).get<std::string>()};
attributes[Attribute::MANUFACTURER] = {j.at("manufacturer").at(0).get<bool>(), j.at("manufacturer").at(1).get<std::string>()};
if(j.count("datasheet"))
attributes[Attribute::DATASHEET] = {j.at("datasheet").at(0).get<bool>(), j.at("datasheet").at(1).get<std::string>()};
else
attributes[Attribute::DATASHEET] = {false, ""};

if(j.count("description"))
attributes[Attribute::DESCRIPTION] = {j.at("description").at(0).get<bool>(), j.at("description").at(1).get<std::string>()};
else
attributes[Attribute::DESCRIPTION] = {false, ""};

if(j.count("base")) {
base = pool.get_part(j.at("base").get<std::string>());
entity = base->entity;
Expand Down Expand Up @@ -90,6 +100,14 @@ namespace horizon {
return get_attribute(Attribute::MANUFACTURER);
}

const std::string &Part::get_description() const {
return get_attribute(Attribute::DESCRIPTION);
}

const std::string &Part::get_datasheet() const {
return get_attribute(Attribute::DATASHEET);
}

std::set<std::string> Part::get_tags() const {
auto r = tags;
if(inherit_tags && base) {
Expand All @@ -103,6 +121,8 @@ namespace horizon {
attributes[Attribute::MPN] = {false, ""};
attributes[Attribute::MANUFACTURER] = {false, ""};
attributes[Attribute::VALUE] = {false, ""};
attributes[Attribute::DATASHEET] = {false, ""};
attributes[Attribute::DESCRIPTION] = {false, ""};
}

Part Part::new_from_file(const std::string &filename, Pool &pool) {
Expand Down Expand Up @@ -133,6 +153,14 @@ namespace horizon {
const auto &a = attributes.at(Attribute::MANUFACTURER);
j["manufacturer"] = {a.first, a.second};
}
{
const auto &a = attributes.at(Attribute::DATASHEET);
j["datasheet"] = {a.first, a.second};
}
{
const auto &a = attributes.at(Attribute::DESCRIPTION);
j["description"] = {a.first, a.second};
}
j["tags"] = tags;
j["inherit_tags"] = inherit_tags;
j["parametric"] = parametric;
Expand Down
4 changes: 3 additions & 1 deletion pool/part.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,16 @@ namespace horizon {
UUID uuid;


enum class Attribute {MPN, VALUE, MANUFACTURER};
enum class Attribute {MPN, VALUE, MANUFACTURER, DATASHEET, DESCRIPTION};
std::map<Attribute, std::pair<bool, std::string>> attributes;
const std::string &get_attribute(Attribute a) const;
const std::pair<bool, std::string> &get_attribute_pair(Attribute a) const;

const std::string &get_MPN() const;
const std::string &get_value() const;
const std::string &get_manufacturer() const;
const std::string &get_datasheet() const;
const std::string &get_description() const;
std::set<std::string> get_tags() const;

std::set<std::string> tags;
Expand Down
13 changes: 11 additions & 2 deletions widgets/pool_browser_part.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ namespace horizon {
void PoolBrowserPart::create_columns() {
treeview->append_column("MPN", list_columns.MPN);
treeview->append_column("Manufacturer", list_columns.manufacturer);
{
auto cr = Gtk::manage(new Gtk::CellRendererText());
auto tvc = Gtk::manage(new Gtk::TreeViewColumn("Description", *cr));
tvc->set_resizable(true);
tvc->add_attribute(cr->property_text(), list_columns.description);
cr->property_ellipsize() = Pango::ELLIPSIZE_END;
treeview->append_column(*tvc);
}
treeview->append_column("Package", list_columns.package);
treeview->append_column("Tags", list_columns.tags);
{
Expand Down Expand Up @@ -57,10 +65,10 @@ namespace horizon {
std::set<std::string> tags{std::istream_iterator<std::string>{iss}, std::istream_iterator<std::string>{}};
std::stringstream query;
if(tags.size() == 0) {
query << "SELECT parts.uuid, parts.MPN, parts.manufacturer, packages.name, GROUP_CONCAT(tags.tag, ' '), parts.filename FROM parts LEFT JOIN tags ON tags.uuid = parts.uuid LEFT JOIN packages ON packages.uuid = parts.package WHERE parts.MPN LIKE ? AND parts.manufacturer LIKE ? AND (parts.entity=? or ?) GROUP BY parts.uuid ";
query << "SELECT parts.uuid, parts.MPN, parts.manufacturer, packages.name, GROUP_CONCAT(tags.tag, ' '), parts.filename, parts.description FROM parts LEFT JOIN tags ON tags.uuid = parts.uuid LEFT JOIN packages ON packages.uuid = parts.package WHERE parts.MPN LIKE ? AND parts.manufacturer LIKE ? AND (parts.entity=? or ?) GROUP BY parts.uuid ";
}
else {
query << "SELECT parts.uuid, parts.MPN, parts.manufacturer, packages.name, (SELECT GROUP_CONCAT(tags.tag, ' ') FROM tags WHERE tags.uuid = parts.uuid), parts.filename FROM parts LEFT JOIN tags ON tags.uuid = parts.uuid LEFT JOIN packages ON packages.uuid = parts.package WHERE parts.MPN LIKE ? AND parts.manufacturer LIKE ? AND (parts.entity=? or ?) ";
query << "SELECT parts.uuid, parts.MPN, parts.manufacturer, packages.name, (SELECT GROUP_CONCAT(tags.tag, ' ') FROM tags WHERE tags.uuid = parts.uuid), parts.filename, parts.description FROM parts LEFT JOIN tags ON tags.uuid = parts.uuid LEFT JOIN packages ON packages.uuid = parts.package WHERE parts.MPN LIKE ? AND parts.manufacturer LIKE ? AND (parts.entity=? or ?) ";
query << "AND (";
for(const auto &it: tags) {
query << "tags.tag LIKE ? OR ";
Expand Down Expand Up @@ -98,6 +106,7 @@ namespace horizon {
row[list_columns.package] = q.get<std::string>(3);
row[list_columns.tags] = q.get<std::string>(4);
row[list_columns.path] = q.get<std::string>(5);
row[list_columns.description] = q.get<std::string>(6);
}
treeview->set_model(store);
select_uuid(selected_uuid);
Expand Down
2 changes: 2 additions & 0 deletions widgets/pool_browser_part.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ namespace horizon {
ListColumns() {
Gtk::TreeModelColumnRecord::add( MPN ) ;
Gtk::TreeModelColumnRecord::add( manufacturer ) ;
Gtk::TreeModelColumnRecord::add( description ) ;
Gtk::TreeModelColumnRecord::add( package ) ;
Gtk::TreeModelColumnRecord::add( uuid ) ;
Gtk::TreeModelColumnRecord::add( tags) ;
Gtk::TreeModelColumnRecord::add( path ) ;
}
Gtk::TreeModelColumn<Glib::ustring> MPN;
Gtk::TreeModelColumn<Glib::ustring> manufacturer;
Gtk::TreeModelColumn<Glib::ustring> description;
Gtk::TreeModelColumn<Glib::ustring> package;
Gtk::TreeModelColumn<Glib::ustring> tags;
Gtk::TreeModelColumn<Glib::ustring> path;
Expand Down

0 comments on commit a016c9e

Please sign in to comment.