Skip to content

Commit

Permalink
Merge pull request #36 from davesrocketshop/parts
Browse files Browse the repository at this point in the history
Parts
  • Loading branch information
davesrocketshop authored Aug 16, 2022
2 parents 27a93fa + 64097d9 commit 908d569
Show file tree
Hide file tree
Showing 20 changed files with 130 additions and 21,229 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "Resources/parts/openrocket-database"]
path = Resources/parts/openrocket-database
url = https://github.com/dbcook/openrocket-database.git
24 changes: 13 additions & 11 deletions App/Parts/Material.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,26 +97,28 @@ def persist(self, connection):
def getMaterial(connection, manufacturer, name, type):
cursor = connection.cursor()

cursor.execute("SELECT material_index FROM material WHERE manufacturer=:manufacturer AND material_name=:name COLLATE NOCASE AND type=:type", {
cursor.execute("SELECT material_index FROM material WHERE manufacturer=:manufacturer COLLATE NOCASE AND material_name=:name COLLATE NOCASE AND type=:type", {
"manufacturer" : manufacturer,
"name" : name,
"type" : type
})

rows = cursor.fetchall()
if len(rows) < 1:
raise MaterialNotFoundError()
cursor.execute("SELECT material_index FROM material WHERE material_name=:name COLLATE NOCASE AND type=:type", {
"name" : name,
"type" : type
})

if len(rows) > 1:
print("%d rows found!" % len(rows))
cursor.execute("SELECT * FROM material WHERE material_name=:name AND type=:type",
{"name" : name,
"type" : type})
rows = cursor.fetchall()
i = 0
for row in rows:
print("%d: %s" % (i, str(row)))
i += 1
if len(rows) < 1:
cursor.execute("SELECT material_index FROM material WHERE material_name=:name COLLATE NOCASE", {
"name" : name
})
rows = cursor.fetchall()
if len(rows) < 1:
print("Not found getMaterial('%s', '%s', '%s')" % (manufacturer, name, type))
raise MaterialNotFoundError()

return rows[0]['material_index']

Expand Down
2 changes: 1 addition & 1 deletion App/Parts/NoseCone.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from App.Parts.Component import Component
from App.Constants import TYPE_CONE, TYPE_ELLIPTICAL, TYPE_HAACK, TYPE_OGIVE, TYPE_VON_KARMAN, TYPE_PARABOLA, TYPE_PARABOLIC, TYPE_POWER
from App.Constants import STYLE_SOLID, STYLE_CAPPED
from App.Utilities import _err
from App.Parts.Utilities import _err
from App.Parts.Exceptions import MultipleEntryError, NotFoundError

class NoseCone(Component):
Expand Down
11 changes: 8 additions & 3 deletions App/Parts/PartDatabase.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from App.Parts.PartDatabaseOrcImporter import PartDatabaseOrcImporter
from App.Parts.Component import Component
from App.Parts.Exceptions import NotFoundError
from App.Utilities import _msg
from App.Parts.Utilities import _msg

class PartDatabase:

Expand Down Expand Up @@ -79,17 +79,21 @@ def _createTables(self, connection):

cursor.execute("DROP TABLE IF EXISTS material")
cursor.execute("CREATE TABLE material (material_index INTEGER PRIMARY KEY ASC, manufacturer, material_name, type, density, units)")
cursor.execute("CREATE INDEX idx_material ON material(manufacturer, material_name, type)")

cursor.execute("DROP TABLE IF EXISTS component")
cursor.execute("CREATE TABLE component (component_index INTEGER PRIMARY KEY ASC, manufacturer, part_number, description, material_index, mass, mass_units)")
cursor.execute("CREATE INDEX idx_component_manufacturer ON component(manufacturer)")

cursor.execute("DROP TABLE IF EXISTS tube_type")
cursor.execute("CREATE TABLE tube_type (tube_type_index INTEGER PRIMARY KEY ASC, type)")
cursor.execute("CREATE INDEX idx_tube_type_type ON tube_type(type)")
cursor.execute("INSERT INTO tube_type(type) VALUES ('Body Tube'), ('Centering Ring'), ('Tube Coupler'), ('Engine Block'), ('Launch Lug'), ('Bulkhead')")

cursor.execute("DROP TABLE IF EXISTS body_tube")
cursor.execute("CREATE TABLE body_tube (body_tube_index INTEGER PRIMARY KEY ASC, component_index, tube_type_index, inner_diameter, inner_diameter_units, outer_diameter, outer_diameter_units, length, length_units)")

cursor.execute("CREATE INDEX idx_body_tube ON body_tube(component_index, tube_type_index)")

cursor.execute("DROP TABLE IF EXISTS nose")
cursor.execute("""CREATE TABLE nose (nose_index INTEGER PRIMARY KEY ASC, component_index, shape, style, diameter, diameter_units,
length, length_units, thickness, thickness_units, shoulder_diameter, shoulder_diameter_units, shoulder_length, shoulder_length_units)""")
Expand All @@ -114,7 +118,8 @@ def _importFiles(self, connection):
for file in filenames:
self._importOrcPartFile(connection, dirpath + file)

for (dirpath, dirnames, filenames) in walk(self._rootFolder + "/Resources/parts/openrocket_components/"):
for (dirpath, dirnames, filenames) in walk(self._rootFolder + "/Resources/parts/openrocket-database/orc/"):
self._importOrcPartFile(connection, dirpath + 'generic_materials.orc')
for file in filenames:
self._importOrcPartFile(connection, dirpath + file)

Expand Down
41 changes: 28 additions & 13 deletions App/Parts/PartDatabaseOrcImporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

import xml.sax

from App.Utilities import _msg, _err, _toFloat, _toBoolean, _toInt
from App.Parts.Utilities import _msg, _err, _toFloat, _toBoolean, _toInt
from App.Parts.BodyTube import BodyTube
from App.Parts.Bulkhead import Bulkhead
from App.Parts.CenteringRing import CenteringRing
Expand Down Expand Up @@ -148,15 +148,21 @@ def _defaultManufacturer(self):
# The default manufacturer is based on the filename
manufacturers = {
"preseed.orc" : "unspecified",
"apogee.orc" : "Apogee",
"competition_chutes.orc" : "Generic competition",
"bluetube.orc" : "Always Ready Rocketry",
"bms.orc" : "BalsaMachining.com",
"estes.orc" : "Estes",
"fliskits.orc" : "FlisKits",
"estes_classic.orc" : "Estes",
"estes_ps2.orc" : "Estes",
"generic_materials.orc" : "unspecified",
"giantleaprocketry.orc" : "Giant Leap",
"locprecision.orc" : "LOC/Precision",
"loc_precision.orc" : "LOC Precision",
"madcow.orc" : "Madcow",
"mpc.orc" : "MPC",
"publicmissiles.orc" : "Public Missiles",
"quest.orc" : "Quest Aerospace",
"semroc.orc" : "SEMROC Astronautics"
"quest.orc" : "Quest",
"semroc.orc" : "SEMROC",
"top_flight.orc" : "Top Flight Recovery"
}

name = PurePath(self._filename).name.lower()
Expand Down Expand Up @@ -243,15 +249,21 @@ def _defaultManufacturer(self):
# The default manufacturer is based on the filename
manufacturers = {
"preseed.orc" : "unspecified",
"apogee.orc" : "Apogee",
"competition_chutes.orc" : "Generic competition",
"bluetube.orc" : "Always Ready Rocketry",
"bms.orc" : "BalsaMachining.com",
"estes.orc" : "Estes",
"fliskits.orc" : "FlisKits",
"estes_classic.orc" : "Estes",
"estes_ps2.orc" : "Estes",
"generic_materials.orc" : "unspecified",
"giantleaprocketry.orc" : "Giant Leap",
"locprecision.orc" : "LOC/Precision",
"loc_precision.orc" : "LOC Precision",
"madcow.orc" : "Madcow",
"mpc.orc" : "MPC",
"publicmissiles.orc" : "Public Missiles",
"quest.orc" : "Quest Aerospace",
"semroc.orc" : "SEMROC Astronautics"
"quest.orc" : "Quest",
"semroc.orc" : "SEMROC",
"top_flight.orc" : "Top Flight Recovery"
}

name = PurePath(self._filename).name.lower()
Expand Down Expand Up @@ -535,7 +547,7 @@ def __init__(self, parent, tag, attributes, connection, filename, line):
self._sides = 0
self._lineCount = 0
self._lineLength = (0.0, "")
self._lineMaterial = ("", MATERIAL_TYPE_LINE)
self._lineMaterial = ("unspecified", MATERIAL_TYPE_LINE)

def handleTag(self, tag, attributes):
_tag = tag.lower().strip()
Expand Down Expand Up @@ -667,7 +679,10 @@ def handleTag(self, tag, attributes):
elif _tag == "length":
self._length = (self._length[0], attributes['Unit'])
elif _tag == "thickness":
self._thickness = (self._thickness[0], attributes['Unit'])
try:
self._thickness = (self._thickness[0], attributes['Unit'])
except KeyError:
self._thickness = (self._thickness[0], "in")
else:
super().handleTag(tag, attributes)

Expand Down
61 changes: 61 additions & 0 deletions App/Parts/Utilities.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# ***************************************************************************
# * Copyright (c) 2021 David Carter <[email protected]> *
# * *
# * This program is free software; you can redistribute it and/or modify *
# * it under the terms of the GNU Lesser General Public License (LGPL) *
# * as published by the Free Software Foundation; either version 2 of *
# * the License, or (at your option) any later version. *
# * for detail see the LICENCE text file. *
# * *
# * 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 Library General Public License for more details. *
# * *
# * You should have received a copy of the GNU Library General Public *
# * License along with this program; if not, write to the Free Software *
# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
# * USA *
# * *
# ***************************************************************************
"""General utilities for the Rocket Workbench"""

__title__ = "General utilities for the Rocket Workbench"
__author__ = "David Carter"
__url__ = "https://www.davesrocketshop.com"

def _msg(message):
"""Write messages to the console including the line ending."""
print(message + "\n")

def _wrn(message):
"""Write warnings to the console including the line ending."""
print(message + "\n")

def _err(message):
"""Write errors to the console including the line ending."""
print(message + "\n")

def _trace(className, functionName, message = None):
"""Write errors to the console including the line ending."""
trace = True
if trace:
if message is None:
print("%s:%s()\n" % (className, functionName))
else:
print("%s:%s(%s)\n" % (className, functionName, message))

def _toFloat(input, defaultValue = 0.0):
if input == '':
return defaultValue
return float(input)

def _toInt(input, defaultValue = 0):
if input == '':
return defaultValue
return int(input)

def _toBoolean(value):
if str(value).strip().lower() == "true":
return True
return False
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ For any feedback, bugs, features, and discussion please refer to the Rocketry wo

David Carter AKA [@davesrocketshop](https://github.com/davesrocketshop)

Component database taken from the Open Rocket project (https://github.com/openrocket/openrocket)
Component database originally taken from the Open Rocket project (https://github.com/openrocket/openrocket)

Now using the improved and curated parts database by Dave Cook instead (https://github.com/dbcook/openrocket-database)

[![Total alerts](https://img.shields.io/lgtm/alerts/g/davesrocketshop/Rocket.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/davesrocketshop/Rocket/alerts/) [![Language grade: Python](https://img.shields.io/lgtm/grade/python/g/davesrocketshop/Rocket.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/davesrocketshop/Rocket/context:python)

Expand Down
Binary file modified Resources/parts/Parts.db
Binary file not shown.
1 change: 1 addition & 0 deletions Resources/parts/openrocket-database
Submodule openrocket-database added at 89d545
Loading

0 comments on commit 908d569

Please sign in to comment.