diff --git a/rocolib/api/Parameterized.py b/rocolib/api/Parameterized.py index 39803dfbecd42e54e7be53c8d7f0e9aee9920127..43b8f37ef4ab8cedb273acc33beae4a8e2a1f888 100644 --- a/rocolib/api/Parameterized.py +++ b/rocolib/api/Parameterized.py @@ -119,22 +119,37 @@ class Parameterized(object): """ Like a dictionary k/v store, but we require special syntax constructs to set/update keys - - XXX FIX: Name is duplicated both in the Parameter object and the dict key """ - def __init__(self): - self.parameters = {} + def __init__(self, name = None): + self._parameters = {} + self.name = name + class P: pass + self.p = P() + + @property + def name(self): + return self._name if self._name is not None else f"C-{str(self.__class__)}" + @name.setter + def name(self, name): + self._name = name def addParameter(self, name, defaultValue=None, **kwargs): """ Adds a k/v pair to the internal store if the key has not been added before - Raises KeyError if the key has been added before + Raises KeyError if the key has been added before or if the parameter name is already a class property/method """ - if name in self.parameters: + if name in self._parameters: raise KeyError("Parameter %s already exists on object %s" % (name, str(self))) + if name in dir(self.p): + raise KeyError("Parameter name %s is a reserved string for object %s" % (name, str(self))) p = Parameter(name, defaultValue, **kwargs) - self.parameters.setdefault(name, p) + self._parameters.setdefault(name, p) + setattr(self.p.__class__, name, property( + lambda s: self.getParameter(name), + lambda s, v: self.setParameter(name, v), + lambda s: self.delParameter(name) + )) return p @@ -144,7 +159,7 @@ class Parameterized(object): - Only if otherwise unset if force=False - Overwrite any previously set values if force=True """ - for n, p in self.parameters.items(): + for n, p in self._parameters.items(): p.setDefault(force) @@ -154,10 +169,10 @@ class Parameterized(object): Raises KeyError if the key has not been added before Passes along any ValueErrors from Parameter object """ - if n in self.parameters: - self.parameters[n].setValue(v) + if n in self._parameters: + self._parameters[n].setValue(v) else: - raise KeyError("Parameter %s not initialized on object %s" % (n, str(self))) + raise KeyError("Parameter %s not does not exist on object %s" % (n, str(self))) def getParameter(self, name): @@ -165,7 +180,7 @@ class Parameterized(object): Retrieves the parameter value with the given name Raises KeyError if the key is not been set """ - return self.parameters[name].getValue() + return self._parameters[name].getValue() def getParameterInfo(self, name=None, keys=None): @@ -173,15 +188,18 @@ class Parameterized(object): Retrieves the parameter metadata info """ if name: - return self.parameters[name].getInfo(keys) + return self._parameters[name].getInfo(keys) else: - return {k: v.getInfo(keys) for k, v in self.parameters.items()} + return {k: v.getInfo(keys) for k, v in self._parameters.items()} def hasParameter(self, name): - return name in self.parameters + return name in self._parameters def delParameter(self, name): - self.parameters.pop(name) - + if name in self._parameters: + self._parameters.pop(name) + delattr(self.p.__class__, name) + else: + raise KeyError("Parameter %s not does not exist on object %s" % (n, str(self))) diff --git a/rocolib/api/components/Component.py b/rocolib/api/components/Component.py index b94d56c7e8bfc6364b717c53ddbc7f00aa895b74..e700490b63fa5ecc67dff9a173290fffd37a06da 100644 --- a/rocolib/api/components/Component.py +++ b/rocolib/api/components/Component.py @@ -28,12 +28,15 @@ def getSubcomponentObject(component, name=None): obj = tryImport(component, component) # XXX hack to get around derived components not having name parameter in their __init__ c = obj() - c.setName(name) + c.name = name return c except ImportError: - c = Component(component) - c.setName(name) - return c + return newComponent(name, component) + +def newComponent(name, yamlFile=None): + class C(Component): + def define(self): pass + return C(name, yamlFile=yamlFile) class Component(Parameterized): @classmethod @@ -44,10 +47,9 @@ class Component(Parameterized): c.setParameter(key, val) c.makeOutput(outputs, filedir, **kwargs) - def __init__(self, yamlFile=None): - self._name = None + def __init__(self, name=None, yamlFile=None): + Parameterized.__init__(self, name) self.cName = type(self).__name__ - Parameterized.__init__(self) self.reset() yf = yamlFile if not yamlFile: @@ -68,12 +70,6 @@ class Component(Parameterized): self.predefine() self.define() - def getName(self): - return self._name if self._name is not None else str(self.__class__) - - def setName(self, name): - self._name = name - def fromYaml(self, filename): definition = load_yaml(filename) @@ -102,7 +98,6 @@ class Component(Parameterized): def reset(self): # Used during design - self.parameters = {} self.subcomponents = {} self.connections = {} self.interfaces = {} @@ -118,6 +113,7 @@ class Component(Parameterized): def define(self): ### Override in Component instance to define individual parameters, interfaces, etc. + raise TypeError(f'Component {self.name} should not be instantiated directly: use newComponent() or create an inherited class.') pass def getInterfaceInfo(self, detail=1): @@ -147,7 +143,7 @@ class Component(Parameterized): :type classname: str or unicode ''' # XXX will silently fail if subcomponent name is already taken? - obj = getSubcomponentObject(classname, self.getName() + '.' + name) + obj = getSubcomponentObject(classname, self.name + '.' + name) sc = {"classname": classname, "parameters": {}, "kwargs": kwargs, "object": obj} self.subcomponents.setdefault(name, sc) @@ -301,19 +297,19 @@ class Component(Parameterized): def delParameter(self, name): ''' - def toLibrary(self, name): + def toLibrary(self): # XXX TODO: Check for collisions! # if collision: # flag to allow rebuilding, and fail otherwise? # if no flag, check if source matches and rebuild if so, fail otherwise? - return self.toYaml(ROCOLIB_LIBRARY, name + ".yaml") + return self.toYaml(ROCOLIB_LIBRARY, self.name + ".yaml") def toYaml(self, basedir, filename): filepath = os.path.join(basedir, filename) source = os.path.relpath(sys.argv[0], basedir).replace(os.sep, posixpath.sep) parameters = {} - for k, v in self.parameters.items(): + for k, v in self._parameters.items(): parameters[k] = {"defaultValue": v.defaultValue, "spec": v.spec} subcomponents = {} @@ -531,7 +527,7 @@ class Component(Parameterized): def visualize(self, outputs=True, **ka): widgets = self.makeOutput(outputs, widgets=True, **ka) - elts = [ html.H1(f"RoCo component visualizer: {self.getName()}") ] + elts = [ html.H1(f"RoCo component visualizer: {self.name}") ] tabs = [] for c, w in widgets.items(): @@ -559,7 +555,7 @@ class Component(Parameterized): if ka.pop("remake", True): self.make(ka.pop("useDefaultParameters", True)) - log.debug(f"... done making {self.getName()}.") + log.debug(f"... done making {self.name}.") # XXX: Is this the right way to do it? import os diff --git a/rocolib/api/components/MechanicalComponent.py b/rocolib/api/components/MechanicalComponent.py index 2b1bda83ca9590c054044390318b12bc6b4d387f..aa07db84b001e0852a7a0a2bbb88863c140bab43 100644 --- a/rocolib/api/components/MechanicalComponent.py +++ b/rocolib/api/components/MechanicalComponent.py @@ -39,7 +39,7 @@ class MechanicalComponent(Component): ## XXX Duplicated from component to set parameters for transform if kwargs.get("remake", True): self.make(kwargs.get("useDefaultParameters", True)) - log.debug(f"... done making {self.getName()}.") + log.debug(f"... done making {self.name}.") kwargs["remake"] = False if "transform3D" not in kwargs: diff --git a/rocolib/api/components/__init__.py b/rocolib/api/components/__init__.py index b5aaf01598effac1c438892ac83b274102e6d30f..443c75949be40fbf2cceba69f25bc7ca6fcd4c9c 100644 --- a/rocolib/api/components/__init__.py +++ b/rocolib/api/components/__init__.py @@ -1,4 +1,4 @@ -from .Component import Component +from .Component import Component, newComponent from .MechanicalComponent import MechanicalComponent from .FoldedComponent import FoldedComponent from .DecorationComponent import DecorationComponent diff --git a/rocolib/api/composables/ComponentComposable.py b/rocolib/api/composables/ComponentComposable.py index 48c3fb19b113d37aaac9c1fc23f1bd429a95481b..45df43b159ba0b335ca55f88fa25972fb230b224 100644 --- a/rocolib/api/composables/ComponentComposable.py +++ b/rocolib/api/composables/ComponentComposable.py @@ -13,7 +13,7 @@ class ComponentComposable(Composable): def append(self, c2, name, **kwargs): sc = c2.c - scname = sc.getName() + scname = sc.name scclass = sc.cName scnet = c2.net @@ -21,14 +21,14 @@ class ComponentComposable(Composable): self.net.graph['depth'] = max(self.net.graph['depth'], scnet.graph['depth']+1) def attach(self, fromPort, toPort, **kwargs): - self.net.add_edge(fromPort.parent.getName(), toPort.parent.getName()) + self.net.add_edge(fromPort.parent.name, toPort.parent.name) def _makeComponentMap(self, scd=None, full=None, idnum = 0): if scd is None: g = self.net full = nx.DiGraph() - full.add_node(0, name="", component=self.c.getName()) - title = f"<b>{self.c.getName()}</b>" + full.add_node(0, name="", component=self.c.name) + title = f"<b>{self.c.name}</b>" else: try: g = scd['net'] diff --git a/rocolib/api/ports/Port.py b/rocolib/api/ports/Port.py index d8660791fa6d6906bb7c4b3279c9edb10be0ee60..5766b5711747ae18e3b4ec82f3bb7fce1bb83221 100644 --- a/rocolib/api/ports/Port.py +++ b/rocolib/api/ports/Port.py @@ -5,7 +5,7 @@ class Port(Parameterized): """ Abstract base class for a Port """ - def __init__(self, parent, params, name='', **kwargs): + def __init__(self, parent, params, name=None, **kwargs): """ :param parent: component that is holding this port :type parent: component @@ -16,9 +16,8 @@ class Port(Parameterized): :param kwargs: additional arguments to override params :type kwargs: dict """ - super(Port, self).__init__() + Parameterized.__init__(self, name) self.parent = parent - self.setName(name) for key, value in params.items(): self.addParameter(key, value) @@ -59,14 +58,8 @@ class Port(Parameterized): def getParent(self): return self.parent - def setName(self, name): - self.name = str(name) - - def getName(self): - return self.name - def toString(self): - return str(self.parent) + '.' + self.getName() + return str(self.parent) + '.' + self.name def attachTo(self, toPort, **kwargs): pass diff --git a/rocolib/builders/BoatBaseBuilder.py b/rocolib/builders/BoatBaseBuilder.py deleted file mode 100644 index 6007f07dbffb1fd073dcdbea4a2af8425e6009fd..0000000000000000000000000000000000000000 --- a/rocolib/builders/BoatBaseBuilder.py +++ /dev/null @@ -1,15 +0,0 @@ -from rocolib.api.components.Component import Component - -c = Component() - -c.addSubcomponent("boat","SimpleUChannel", inherit=True) -c.addSubcomponent("bow","BoatPoint", inherit=True) -c.addSubcomponent("stern","BoatPoint", inherit=True) - -c.join(("boat", "top"), ("bow", "edge")) -c.join(("boat", "bot"), ("stern", "edge")) - -c.inheritInterface("portedge", ("boat", "ledge")) -c.inheritInterface("staredge", ("boat", "redge")) - -c.toLibrary("BoatBase") diff --git a/rocolib/builders/CabinBuilder.py b/rocolib/builders/CabinBuilder.py deleted file mode 100644 index 0d4a19d79947b189caa5e251a67e47d922442908..0000000000000000000000000000000000000000 --- a/rocolib/builders/CabinBuilder.py +++ /dev/null @@ -1,61 +0,0 @@ -from rocolib.api.components.Component import Component - -c = Component() - -# BOX - -c.addParameter("depth", 50, paramType="length") -c.addParameter("width", 60, paramType="length") -c.addParameter("height", 30, paramType="length") - -c.addSubcomponent("top","Rectangle") -c.addSubcomponent("fore","Rectangle") -c.addSubcomponent("rear","Rectangle") -c.addSubcomponent("port","Rectangle") -c.addSubcomponent("star","Rectangle") - -c.addConstraint(("top","w"), "depth") -c.addConstraint(("top","l"), "width") - -c.addConstraint(("fore","w"), "height") -c.addConstraint(("fore","l"), "width") -c.addConstraint(("rear","w"), "height") -c.addConstraint(("rear","l"), "width") - -c.addConnection(("top", "b"), ("rear", "t"), angle=90) -c.addConnection(("top", "t"), ("fore", "b"), angle=90) - -c.addConstraint(("port","w"), "depth") -c.addConstraint(("port","l"), "height") -c.addConstraint(("star","w"), "depth") -c.addConstraint(("star","l"), "height") - -c.addConnection(("top", "l"), ("port", "r"), angle=90) -c.addConnection(("top", "r"), ("star", "l"), angle=90) - -c.addConnection(("port", "t"), ("fore", "l"), angle=90, tabWidth=10) -c.addConnection(("fore", "r"), ("star", "t"), angle=90, tabWidth=10) -c.addConnection(("star", "b"), ("rear", "r"), angle=90, tabWidth=10) -c.addConnection(("port", "b"), ("rear", "l"), angle=90, tabWidth=10) - -# Interface to floats - -c.addParameter("length", 200, paramType="length") - -c.addSubcomponent("portsplit","SplitEdge") -c.addSubcomponent("starsplit","SplitEdge") - -c.addConstraint(("portsplit","botlength"), ("length", "depth"), "[sum(x)]") -c.addConstraint(("portsplit","toplength"), ("length", "depth"), "[x[0]/2., x[1], x[0]/2.]") -c.addConnection(("portsplit", "topedge1"), ("port", "l")) - -c.addConstraint(("starsplit","botlength"), ("length", "depth"), "[sum(x)]") -c.addConstraint(("starsplit","toplength"), ("length", "depth"), "[x[0]/2., x[1], x[0]/2.]") -c.addConnection(("starsplit", "topedge1"), ("star", "r")) - -c.inheritInterface("portedge", ("portsplit", "botedge0")) -c.inheritInterface("staredge", ("starsplit", "botedge0")) -c.inheritInterface("foreedge", ("fore", "t")) -c.inheritInterface("rearedge", ("rear", "b")) - -c.toLibrary("Cabin") diff --git a/rocolib/builders/CanoeBuilder.py b/rocolib/builders/CanoeBuilder.py deleted file mode 100644 index ea203e8063399eddc3ca92ce3e6fbf174563f025..0000000000000000000000000000000000000000 --- a/rocolib/builders/CanoeBuilder.py +++ /dev/null @@ -1,30 +0,0 @@ -from rocolib.api.components.Component import Component - -c = Component() - -# BOX - -c.addSubcomponent("boat","BoatBase", inherit=True, prefix=None, root=True) - -c.addParameter("seats", 3, paramType="count", minValue=1, maxValue=10) - -c.addSubcomponent("portsplit","SplitEdge") -c.addSubcomponent("starsplit","SplitEdge") - -c.addConstraint(("portsplit","botlength"), ("boat.length", "seats"), "(x[0],)") -c.addConstraint(("portsplit","toplength"), ("boat.length", "seats"), "(x[0]/(2.*x[1]+1.),) * (2*x[1]+1)") -c.addConstraint(("starsplit","toplength"), ("boat.length", "seats"), "(x[0],)") -c.addConstraint(("starsplit","botlength"), ("boat.length", "seats"), "(x[0]/(2.*x[1]+1.),) * (2*x[1]+1)") - -c.addConnection(("portsplit", "botedge0"), ("boat", "portedge"), angle=90) -c.addConnection(("starsplit", "topedge0"), ("boat", "staredge"), angle=90, tabWidth=10) - -for i in range(10): - nm = "seat%d"%i - c.addSubcomponent(nm, "Rectangle") - c.addConstraint((nm, "l"), ("boat.width", "seats"), "(%d < x[1]) and x[0] or 0" % i) - c.addConstraint((nm, "w"), ("boat.length", "seats"), "x[0]/(2.*x[1]+1.)") - c.addConnection(("portsplit", "topedge%d" % (2*i+1)), (nm, "l")) - c.addConnection(("starsplit", "botedge%d" % (2*i+1)), (nm, "r")) - -c.toLibrary("Canoe") diff --git a/rocolib/builders/CatBuilder.py b/rocolib/builders/CatBuilder.py deleted file mode 100644 index 3d3b16c90ac1d1826e04eef16000fa10e8101e5f..0000000000000000000000000000000000000000 --- a/rocolib/builders/CatBuilder.py +++ /dev/null @@ -1,31 +0,0 @@ -from rocolib.api.components.Component import Component - -c = Component() - -# BOX - -c.addSubcomponent("cabin","Cabin", inherit=True, prefix=None) -c.addSubcomponent("port","BoatBase", root=True) -c.addSubcomponent("star","BoatBase") - -c.addConstraint(("port","boat.length"), ("length", "depth"), "sum(x)") -c.addConstraint(("port","boat.width"), "width", "x/4.") -c.addConstraint(("port","boat.depth"), ("length", "depth"), "sum(x)/20.") -c.addConstraint(("port","bow.point"), "length", "x/2.") -c.addConstraint(("port","stern.point"), "length", "x/8.") - -c.addConstraint(("star","boat.length"), ("length", "depth"), "sum(x)") -c.addConstraint(("star","boat.width"), "width", "x/4.") -c.addConstraint(("star","boat.depth"), ("length", "depth"), "sum(x)/20.") -c.addConstraint(("star","bow.point"), "length", "x/2.") -c.addConstraint(("star","stern.point"), "length", "x/8.") - -c.addConnection(("cabin", "portedge"), ("port", "portedge")) -c.addConnection(("cabin", "staredge"), ("star", "staredge")) - -c.inheritInterface("foreedge", ("cabin", "foreedge")) -c.inheritInterface("rearedge", ("cabin", "rearedge")) -c.inheritInterface("portedge", ("port", "staredge")) -c.inheritInterface("staredge", ("star", "portedge")) - -c.toLibrary("Catamaran") diff --git a/rocolib/builders/CatFoilBuilder.py b/rocolib/builders/CatFoilBuilder.py deleted file mode 100644 index 407e0cc294b5e3cbca915f6f7e1d68cb1b2a0dcc..0000000000000000000000000000000000000000 --- a/rocolib/builders/CatFoilBuilder.py +++ /dev/null @@ -1,25 +0,0 @@ -from rocolib.api.components.Component import Component - -c = Component() - -# BOX - -c.addSubcomponent("boat","Catamaran", inherit=True, prefix=None, root=True) -c.addSubcomponent("port","Foil", inherit=True, prefix=None) -c.addSubcomponent("star","Foil", inherit=True, prefix=None) - -c.delParameter("flip") - -c.addConstraint(("port","width"), "width", "x/4.") -c.addConstraint(("port","height"), ("length", "depth"), "sum(x)/3.") -c.addConstConstraint(("port","flip"), True) - -c.addConstraint(("star","width"), "width", "x/4.") -c.addConstraint(("star","height"), ("length", "depth"), "sum(x)/3.") -c.addConstConstraint(("star","flip"), False) - -c.addConnection(("boat", "portedge"), ("port", "mount"), angle=-180) -c.addConnection(("boat", "staredge"), ("star", "mount"), angle=-180) -c.addConnection(("star", "join"), ("port", "join"), tabWidth=10) - -c.toLibrary("CatFoil") diff --git a/rocolib/builders/ChairBackBuilder.py b/rocolib/builders/ChairBackBuilder.py index 03e7c254023c2a537682864ee5e1687723adbc67..9c6792dc195a2635b97fc5b59cb1ae93dac85aa9 100644 --- a/rocolib/builders/ChairBackBuilder.py +++ b/rocolib/builders/ChairBackBuilder.py @@ -1,6 +1,6 @@ -from rocolib.api.components.Component import Component +from rocolib.api.components.Component import newComponent -c = Component() +c = newComponent("ChairBack") c.addSubcomponent("panel","ChairPanel", inherit=("width", "thickness"), prefix=None) @@ -21,4 +21,4 @@ c.addConstraint(("sidel","w"), "gapheight") c.addConnection(("panel","tl"),("sidel","t"), angle=0) c.inheritInterface("left", ("sidel", "b")) -c.toLibrary("ChairBack") +c.toLibrary() diff --git a/rocolib/builders/ChairPanelBuilder.py b/rocolib/builders/ChairPanelBuilder.py index 2228f4cfb17073fc8c29b2dd2901366cb9133dd4..099b78008b1133e13b8851afd772cee723729ceb 100644 --- a/rocolib/builders/ChairPanelBuilder.py +++ b/rocolib/builders/ChairPanelBuilder.py @@ -1,6 +1,6 @@ -from rocolib.api.components.Component import Component +from rocolib.api.components.Component import newComponent -c = Component() +c = newComponent("ChairPanel") c.addSubcomponent("back","Rectangle", root=True) c.addSubcomponent("sidel","Rectangle") @@ -28,4 +28,4 @@ c.inheritInterface("bl", ("sidel", "b")) c.inheritInterface("right", ("sider", "r")) c.inheritInterface("left", ("sidel", "l")) -c.toLibrary("ChairPanel") +c.toLibrary() diff --git a/rocolib/builders/ChairSeatBuilder.py b/rocolib/builders/ChairSeatBuilder.py index 785557fcd6ccb29ebde23a61175bbf80d9f75082..6cd1524d41ba0bb17df5cb15d6e8a26dd8a77c07 100644 --- a/rocolib/builders/ChairSeatBuilder.py +++ b/rocolib/builders/ChairSeatBuilder.py @@ -1,6 +1,6 @@ -from rocolib.api.components.Component import Component +from rocolib.api.components.Component import newComponent -c = Component() +c = newComponent("ChairSeat") c.addSubcomponent("seat","ChairPanel", inherit=True, prefix=None, root=True) c.addSubcomponent("back","ChairBack", inherit=True, prefix=None) @@ -21,4 +21,4 @@ c.addConnection(("seat","br"),("kiter","t"), angle=0) c.inheritInterface("right", ("seat", "right")) c.inheritInterface("left", ("seat", "left")) -c.toLibrary("ChairSeat") +c.toLibrary() diff --git a/rocolib/builders/ESPBrainsBuilder.py b/rocolib/builders/ESPBrainsBuilder.py index 0071a1dac000374f6de23bc8e369a9b0ff846dea..f8d36edfc8bd2f097e5c6b848ef01f857f306f18 100644 --- a/rocolib/builders/ESPBrainsBuilder.py +++ b/rocolib/builders/ESPBrainsBuilder.py @@ -1,8 +1,8 @@ -from rocolib.api.components.Component import Component +from rocolib.api.components.Component import newComponent from rocolib.api.Function import Function -self = Component() +self = newComponent("ESPBrains") self.addSubcomponent("beam", "RectBeam") self.addSubcomponent("header", "Header") @@ -44,4 +44,4 @@ self.addConnection(("beam", "face1"), self.inheritAllInterfaces("beam", prefix=None) -self.toLibrary("ESPBrains") +self.toLibrary() diff --git a/rocolib/builders/ESPSegBuilder.py b/rocolib/builders/ESPSegBuilder.py index 6ba94f413edce0ccc1fa15ff866b8d29d45f7559..2f8a066a6a28d6b39b180c1d2a0c881e58377938 100644 --- a/rocolib/builders/ESPSegBuilder.py +++ b/rocolib/builders/ESPSegBuilder.py @@ -1,7 +1,7 @@ -from rocolib.api.components.Component import Component +from rocolib.api.components.Component import newComponent from rocolib.api.Function import Function -c = Component() +c = newComponent("ESPSeg") c.addParameter("length", 90, paramType="length") c.addParameter("width", 60, paramType="length") @@ -109,4 +109,4 @@ c.addConnection(("sheath", "face1"), mode="hole", offset=Function(*depthfn(["length", "battery"], "(4-(%s+x[3])/2, 0.5 * x[2] - 15)"))) -c.toLibrary("ESPSeg") +c.toLibrary() diff --git a/rocolib/builders/FoilBuilder.py b/rocolib/builders/FoilBuilder.py deleted file mode 100644 index dcfcf6560ce2556b18f6e907b4b8ccd87fa96669..0000000000000000000000000000000000000000 --- a/rocolib/builders/FoilBuilder.py +++ /dev/null @@ -1,36 +0,0 @@ -from rocolib.api.components.Component import Component - -c = Component() - -c.addParameter("height", 100, paramType="length") -c.addParameter("length", 40, paramType="length") -c.addParameter("depth", 20, paramType="length") -c.addParameter("dl", 0.1, paramType="length") -c.addParameter("width", 10, paramType="length") -c.addParameter("flip", False, valueType="bool") - -c.addSubcomponent("stick", "Rectangle") -c.addSubcomponent("foil","Wing") -c.addSubcomponent("split","SplitEdge") - -c.addConstraint(("split","botlength"), ("length", "depth"), "[sum(x)]") -c.addConstraint(("split","toplength"), ("length", "depth"), "[x[0]/2., x[1], x[0]/2.]") - -c.addConstraint(("stick","l"), "height") -c.addConstraint(("stick","w"), "depth") - -c.addConstraint(("foil","bodylength"), "depth") -c.addConstraint(("foil","wingtip"), "depth") -c.addConstraint(("foil","thickness"), ("dl", "depth"), "x[0] * x[1]") -c.addConstraint(("foil","wingspan"), "width") -c.addConstraint(("foil","flip"), "flip") - - -c.addConnection(("split", "topedge1"), ("stick", "l")) -c.addConnection(("stick", "r"), ("foil", "tip"), angle=90) - - -c.inheritInterface("mount", ("split", "botedge0")) -c.inheritInterface("join", ("foil", "base")) - -c.toLibrary("Foil") diff --git a/rocolib/builders/MountedServoBuilder.py b/rocolib/builders/MountedServoBuilder.py index 305bfa7bc6639694d6f7d4607c59696368a68d4e..2b667d30b5d46e65dfcba3a824d618f7ceea4d84 100644 --- a/rocolib/builders/MountedServoBuilder.py +++ b/rocolib/builders/MountedServoBuilder.py @@ -1,7 +1,7 @@ -from rocolib.api.components.Component import Component +from rocolib.api.components.Component import newComponent from rocolib.api.Function import Function -c = Component() +c = newComponent("MountedServo") c.addSubcomponent("mount", "ServoMount", inherit=True, prefix=None) c.addSubcomponent("servo", "ServoMotor", inherit=True, prefix=None) @@ -11,4 +11,4 @@ c.inheritAllInterfaces("servo", prefix=None) c.addConnection(("mount", "mount.decoration"), ("servo", "mount")) -c.toLibrary("MountedServo") +c.toLibrary() diff --git a/rocolib/builders/PaperbotBuilder.py b/rocolib/builders/PaperbotBuilder.py index e705eb2ae2cd2b1e9902e84b8f41dddd15786884..92e08209cbcb73ccf4c340be6e6ecbcfcd685db6 100644 --- a/rocolib/builders/PaperbotBuilder.py +++ b/rocolib/builders/PaperbotBuilder.py @@ -1,11 +1,11 @@ -from rocolib.api.components.Component import Component +from rocolib.api.components.Component import newComponent -c = Component() +c = newComponent("Paperbot") c.addParameter("width", 60, paramType="length", minValue=60) c.addParameter("length", 80, paramType="length", minValue=77) c.addParameter("height", 25, paramType="length", minValue=20) c.addSubcomponent("paperbot", "ESPSeg", inherit="length width height battery tire_thickness".split(), prefix=None) -c.toLibrary("Paperbot") +c.toLibrary() diff --git a/rocolib/builders/RockerChairBuilder.py b/rocolib/builders/RockerChairBuilder.py index e0403a0207bf728fe7051911e8ac220a1b833f88..be7dc6302d320f6455c3b830b15804dbfa5a96fe 100644 --- a/rocolib/builders/RockerChairBuilder.py +++ b/rocolib/builders/RockerChairBuilder.py @@ -1,6 +1,6 @@ -from rocolib.api.components.Component import Component +from rocolib.api.components.Component import newComponent -c = Component() +c = newComponent("RockerChair") c.addSubcomponent("seat","ChairSeat", inherit=True, prefix=None, root=True) c.addSubcomponent("legl","RockerLeg", inherit=True, prefix=None, mirror=True) @@ -16,4 +16,4 @@ c.addConnection(("seat","right"),("legr","topedge"), angle=0) c.addConnection(("crossbar","l"),("legl","crossbar"), angle=90) c.addConnection(("crossbar","r"),("legr","crossbar"), angle=90) -c.toLibrary("RockerChair") +c.toLibrary() diff --git a/rocolib/builders/RockerLegBuilder.py b/rocolib/builders/RockerLegBuilder.py index c63de96b545abeefe4ff0f0556792fef1fb53e70..2e7d63b99e424a1735e300b484b57ed3614c8f24 100644 --- a/rocolib/builders/RockerLegBuilder.py +++ b/rocolib/builders/RockerLegBuilder.py @@ -1,9 +1,9 @@ from numbers import Number -from rocolib.api.components.Component import Component +from rocolib.api.components.Component import newComponent -c = Component() +c = newComponent("RockerLeg") c.addParameter("height", 40, paramType="length") c.addParameter("depth", 50, paramType="length") @@ -51,4 +51,4 @@ c.addConnection(("beam0","b"),("kite%d" % (n - 1),"t"), angle=0) c.inheritInterface("topedge", ("beam2", "r")) c.inheritInterface("crossbar", ("beam5", "l")) -c.toLibrary("RockerLeg") +c.toLibrary() diff --git a/rocolib/builders/ServoMountBuilder.py b/rocolib/builders/ServoMountBuilder.py index 399f03b91bbb76b2139b6e9fa71afbe79a2f3245..84e2c05d210d022217f2da245966e37a5d731ef8 100644 --- a/rocolib/builders/ServoMountBuilder.py +++ b/rocolib/builders/ServoMountBuilder.py @@ -1,7 +1,7 @@ -from rocolib.api.components.Component import Component +from rocolib.api.components.Component import newComponent from rocolib.api.Function import Function -c = Component() +c = newComponent("ServoMount") c.addParameter("servo", "fs90r", paramType="dimension") c.addParameter("flip", False, valueType="bool") @@ -25,4 +25,4 @@ c.addConnection(("beam", "face0"), ("mount", "decoration"), mode="hole", offset=Function(params="offset")) -c.toLibrary("ServoMount") +c.toLibrary() diff --git a/rocolib/builders/SimpleChairBuilder.py b/rocolib/builders/SimpleChairBuilder.py index a3bf8b3d6c61a80460cea35878eb367e00a0d814..5feeff319a65a3618216bab4766a0763fd01b865 100644 --- a/rocolib/builders/SimpleChairBuilder.py +++ b/rocolib/builders/SimpleChairBuilder.py @@ -1,6 +1,6 @@ -from rocolib.api.components.Component import Component +from rocolib.api.components.Component import newComponent -c = Component() +c = newComponent("SimpleChair") c.addSubcomponent("seat","ChairSeat", inherit=True, prefix=None, root=True) c.addSubcomponent("legl","VLeg", inherit=True, prefix=None) @@ -12,4 +12,4 @@ c.addConstraint(("legr","width"), "depth") c.addConnection(("seat","left"),("legl","topedge"), angle=0) c.addConnection(("seat","right"),("legr","topedge"), angle=0) -c.toLibrary("SimpleChair") +c.toLibrary() diff --git a/rocolib/builders/SimpleTableBuilder.py b/rocolib/builders/SimpleTableBuilder.py index 609349d92029eac876cd660978fc10f94dcf3104..745c988866bffb3b00c528822b1ae1e55f8934b2 100644 --- a/rocolib/builders/SimpleTableBuilder.py +++ b/rocolib/builders/SimpleTableBuilder.py @@ -1,6 +1,6 @@ -from rocolib.api.components.Component import Component +from rocolib.api.components.Component import newComponent -c = Component() +c = newComponent("SimpleTable") c.addSubcomponent("top","Rectangle", root=True) c.addSubcomponent("legl","VLeg", inherit=True, prefix=None) @@ -27,4 +27,4 @@ c.addConnection(("legr","rightedge"),("legt","leftedge"), angle=90) #c.addConnection(("legt","rightedge"),("legl","leftedge"), angle=90) c.addConnection(("legl","leftedge"),("legt","rightedge"), angle=90) -c.toLibrary("SimpleTable") +c.toLibrary() diff --git a/rocolib/builders/TrimaranBuilder.py b/rocolib/builders/TrimaranBuilder.py deleted file mode 100644 index 16880d074cb743ce82be6b8c3c3c391e7e8340a1..0000000000000000000000000000000000000000 --- a/rocolib/builders/TrimaranBuilder.py +++ /dev/null @@ -1,36 +0,0 @@ -from rocolib.api.components.Component import Component - -c = Component() - -# BOX - -c.addParameter("seats", 6, valueType="int", minValue=2, maxValue=10) -c.addParameter("spacing", 25, paramType="length") - -for i in range(3): - c.addSubcomponent("boat%d"%i,"BoatBase", inherit=True, prefix=None, root=True) - - c.addSubcomponent("portsplit%d"%i,"SplitEdge") - c.addSubcomponent("starsplit%d"%i,"SplitEdge") - - c.addConstraint(("portsplit%d"%i,"botlength"), ("boat.length", "seats"), "[x[0]]") - c.addConstraint(("portsplit%d"%i,"toplength"), ("boat.length", "seats"), "[x[0]/(1.*x[1])] * x[1]") - c.addConstraint(("starsplit%d"%i,"toplength"), ("boat.length", "seats"), "[x[0]]") - c.addConstraint(("starsplit%d"%i,"botlength"), ("boat.length", "seats"), "[x[0]/(1.*x[1])] * x[1]") - - c.addConnection(("portsplit%d"%i, "botedge0"), ("boat%d"%i, "portedge"), angle=-90) - c.addConnection(("starsplit%d"%i, "topedge0"), ("boat%d"%i, "staredge"), angle=-90) - -for i in range(10): - nm = "seat%d"%i - c.addSubcomponent(nm, "Rectangle") - c.addConstraint((nm, "l"), ("spacing", "seats"), "(%d < x[1]) and x[0] or 0" % i) - c.addConstraint((nm, "w"), ("boat.length", "seats"), "x[0]/(1.*x[1])") - if (i % 2): - c.addConnection(("starsplit0", "botedge%d" % i), (nm, "l")) - c.addConnection(("portsplit1", "topedge%d" % i), (nm, "r")) - else: - c.addConnection(("starsplit1", "botedge%d" % i), (nm, "l")) - c.addConnection(("portsplit2", "topedge%d" % i), (nm, "r")) - -c.toLibrary("Trimaran") diff --git a/rocolib/builders/TugBuilder.py b/rocolib/builders/TugBuilder.py deleted file mode 100644 index 1fde8a2f8d36f5c4fa6b8d8d0fdc7b2cd7170923..0000000000000000000000000000000000000000 --- a/rocolib/builders/TugBuilder.py +++ /dev/null @@ -1,19 +0,0 @@ -from rocolib.api.components.Component import Component - -c = Component() - -# BOX - -c.addSubcomponent("cabin","Cabin", inherit=True, prefix=None) -c.addSubcomponent("boat","BoatBase", root=True) - -c.addConstraint(("boat","boat.length"), ("length", "depth"), "sum(x)") -c.addConstraint(("boat","boat.width"), "width") -c.addConstraint(("boat","boat.depth"), "width", "x/3.") -c.addConstraint(("boat","bow.point"), "length", "x/2.") -c.addConstraint(("boat","stern.point"), "length", "x/8.") - -c.addConnection(("cabin", "portedge"), ("boat", "portedge"), angle=0) -c.addConnection(("cabin", "staredge"), ("boat", "staredge"), angle=0, tabWidth=10) - -c.toLibrary("Tug") diff --git a/rocolib/builders/WheelBuilder.py b/rocolib/builders/WheelBuilder.py index 9ee698fcdf63e5993b80114928af382abf303a67..12b076d513cb1aac1b2c3da6fcf279acd1ad70af 100644 --- a/rocolib/builders/WheelBuilder.py +++ b/rocolib/builders/WheelBuilder.py @@ -1,7 +1,7 @@ -from rocolib.api.components.Component import Component +from rocolib.api.components.Component import newComponent from rocolib.api.Function import Function -c = Component() +c = newComponent("Wheel") c.addSubcomponent("drive", "MountedServo", inherit=True, prefix=None) c.addSubcomponent("tire", "Tire", inherit="radius tire_thickness".split(), prefix=None) @@ -11,4 +11,4 @@ c.inheritAllInterfaces("drive", prefix=None) c.addConnection(("drive", "horn"), ("tire", "face")) -c.toLibrary("Wheel") +c.toLibrary() diff --git a/rocolib/library/BoatBase.yaml b/rocolib/library/BoatBase.yaml deleted file mode 100644 index 3c13407c663fd0b04cfaf87d227ba0ce78c124b5..0000000000000000000000000000000000000000 --- a/rocolib/library/BoatBase.yaml +++ /dev/null @@ -1,255 +0,0 @@ -connections: - connection0: - - - boat - - top - - - bow - - edge - - {} - connection1: - - - boat - - bot - - - stern - - edge - - {} -interfaces: - portedge: - interface: ledge - subcomponent: boat - staredge: - interface: redge - subcomponent: boat -parameters: - boat._dx: - defaultValue: 0 - spec: - minValue: null - units: mm - valueType: (float, int) - boat._dy: - defaultValue: 0 - spec: - minValue: null - units: mm - valueType: (float, int) - boat._dz: - defaultValue: 0 - spec: - minValue: null - units: mm - valueType: (float, int) - boat._q_a: - defaultValue: 1 - spec: - maxValue: 1 - minValue: -1 - valueType: (int, float) - boat._q_i: - defaultValue: 0 - spec: - maxValue: 1 - minValue: -1 - valueType: (int, float) - boat._q_j: - defaultValue: 0 - spec: - maxValue: 1 - minValue: -1 - valueType: (int, float) - boat._q_k: - defaultValue: 0 - spec: - maxValue: 1 - minValue: -1 - valueType: (int, float) - boat.depth: - defaultValue: 20 - spec: - minValue: 0 - units: mm - valueType: (float, int) - boat.length: - defaultValue: 100 - spec: - minValue: 0 - units: mm - valueType: (float, int) - boat.width: - defaultValue: 50 - spec: - minValue: 0 - units: mm - valueType: (float, int) - bow._dx: - defaultValue: 0 - spec: - minValue: null - units: mm - valueType: (float, int) - bow._dy: - defaultValue: 0 - spec: - minValue: null - units: mm - valueType: (float, int) - bow._dz: - defaultValue: 0 - spec: - minValue: null - units: mm - valueType: (float, int) - bow._q_a: - defaultValue: 1 - spec: - maxValue: 1 - minValue: -1 - valueType: (int, float) - bow._q_i: - defaultValue: 0 - spec: - maxValue: 1 - minValue: -1 - valueType: (int, float) - bow._q_j: - defaultValue: 0 - spec: - maxValue: 1 - minValue: -1 - valueType: (int, float) - bow._q_k: - defaultValue: 0 - spec: - maxValue: 1 - minValue: -1 - valueType: (int, float) - bow.point: - defaultValue: 50 - spec: - minValue: 0 - units: mm - valueType: (float, int) - stern._dx: - defaultValue: 0 - spec: - minValue: null - units: mm - valueType: (float, int) - stern._dy: - defaultValue: 0 - spec: - minValue: null - units: mm - valueType: (float, int) - stern._dz: - defaultValue: 0 - spec: - minValue: null - units: mm - valueType: (float, int) - stern._q_a: - defaultValue: 1 - spec: - maxValue: 1 - minValue: -1 - valueType: (int, float) - stern._q_i: - defaultValue: 0 - spec: - maxValue: 1 - minValue: -1 - valueType: (int, float) - stern._q_j: - defaultValue: 0 - spec: - maxValue: 1 - minValue: -1 - valueType: (int, float) - stern._q_k: - defaultValue: 0 - spec: - maxValue: 1 - minValue: -1 - valueType: (int, float) - stern.point: - defaultValue: 50 - spec: - minValue: 0 - units: mm - valueType: (float, int) -source: ../builders/BoatBaseBuilder.py -subcomponents: - boat: - classname: SimpleUChannel - kwargs: {} - parameters: - _dx: - parameter: boat._dx - _dy: - parameter: boat._dy - _dz: - parameter: boat._dz - _q_a: - parameter: boat._q_a - _q_i: - parameter: boat._q_i - _q_j: - parameter: boat._q_j - _q_k: - parameter: boat._q_k - depth: - parameter: boat.depth - length: - parameter: boat.length - width: - parameter: boat.width - bow: - classname: BoatPoint - kwargs: {} - parameters: - _dx: - parameter: bow._dx - _dy: - parameter: bow._dy - _dz: - parameter: bow._dz - _q_a: - parameter: bow._q_a - _q_i: - parameter: bow._q_i - _q_j: - parameter: bow._q_j - _q_k: - parameter: bow._q_k - depth: - parameter: depth - subcomponent: boat - point: - parameter: bow.point - width: - parameter: width - subcomponent: boat - stern: - classname: BoatPoint - kwargs: {} - parameters: - _dx: - parameter: stern._dx - _dy: - parameter: stern._dy - _dz: - parameter: stern._dz - _q_a: - parameter: stern._q_a - _q_i: - parameter: stern._q_i - _q_j: - parameter: stern._q_j - _q_k: - parameter: stern._q_k - depth: - parameter: depth - subcomponent: boat - point: - parameter: stern.point - width: - parameter: width - subcomponent: boat diff --git a/rocolib/library/BoatPoint.py b/rocolib/library/BoatPoint.py index 70872b2812ad72cb0c3ea2403f020697250ae696..788d0eb4344b48f9c1fa7a4de638ae13ce96011b 100644 --- a/rocolib/library/BoatPoint.py +++ b/rocolib/library/BoatPoint.py @@ -31,9 +31,9 @@ class BoatPoint(FoldedComponent): self.addEdgeInterface("edge", ["sl.e1", "sc.e2", "sr.e1"], ["depth", "width", "depth"]) def assemble(self): - w = self.getParameter("width") - d = self.getParameter("depth") - p = self.getParameter("point") + w = self.p.width + d = self.p.depth + p = self.p.point hl, la, bla, hw, wa, bwa, diag, da = pyramid(d*2,w,p) diff --git a/rocolib/library/Cabin.yaml b/rocolib/library/Cabin.yaml deleted file mode 100644 index 48fb07675b68338bbde94ccf4ffa2544da985275..0000000000000000000000000000000000000000 --- a/rocolib/library/Cabin.yaml +++ /dev/null @@ -1,167 +0,0 @@ -connections: - connection0: - - - top - - b - - - rear - - t - - angle: 90 - connection1: - - - top - - t - - - fore - - b - - angle: 90 - connection2: - - - top - - l - - - port - - r - - angle: 90 - connection3: - - - top - - r - - - star - - l - - angle: 90 - connection4: - - - port - - t - - - fore - - l - - angle: 90 - tabWidth: 10 - connection5: - - - fore - - r - - - star - - t - - angle: 90 - tabWidth: 10 - connection6: - - - star - - b - - - rear - - r - - angle: 90 - tabWidth: 10 - connection7: - - - port - - b - - - rear - - l - - angle: 90 - tabWidth: 10 - connection8: - - - portsplit - - topedge1 - - - port - - l - - {} - connection9: - - - starsplit - - topedge1 - - - star - - r - - {} -interfaces: - foreedge: - interface: t - subcomponent: fore - portedge: - interface: botedge0 - subcomponent: portsplit - rearedge: - interface: b - subcomponent: rear - staredge: - interface: botedge0 - subcomponent: starsplit -parameters: - depth: - defaultValue: 50 - spec: - minValue: 0 - units: mm - valueType: (float, int) - height: - defaultValue: 30 - spec: - minValue: 0 - units: mm - valueType: (float, int) - length: - defaultValue: 200 - spec: - minValue: 0 - units: mm - valueType: (float, int) - width: - defaultValue: 60 - spec: - minValue: 0 - units: mm - valueType: (float, int) -source: ../builders/CabinBuilder.py -subcomponents: - fore: - classname: Rectangle - kwargs: {} - parameters: - l: - parameter: width - w: - parameter: height - port: - classname: Rectangle - kwargs: {} - parameters: - l: - parameter: height - w: - parameter: depth - portsplit: - classname: SplitEdge - kwargs: {} - parameters: - botlength: - function: '[sum(x)]' - parameter: &id001 - - length - - depth - toplength: - function: '[x[0]/2., x[1], x[0]/2.]' - parameter: *id001 - rear: - classname: Rectangle - kwargs: {} - parameters: - l: - parameter: width - w: - parameter: height - star: - classname: Rectangle - kwargs: {} - parameters: - l: - parameter: height - w: - parameter: depth - starsplit: - classname: SplitEdge - kwargs: {} - parameters: - botlength: - function: '[sum(x)]' - parameter: *id001 - toplength: - function: '[x[0]/2., x[1], x[0]/2.]' - parameter: *id001 - top: - classname: Rectangle - kwargs: {} - parameters: - l: - parameter: width - w: - parameter: depth diff --git a/rocolib/library/Canoe.yaml b/rocolib/library/Canoe.yaml deleted file mode 100644 index ee32d94a740f973ca132f67250b4cb01bc5f605e..0000000000000000000000000000000000000000 --- a/rocolib/library/Canoe.yaml +++ /dev/null @@ -1,481 +0,0 @@ -connections: - connection0: - - - portsplit - - botedge0 - - - boat - - portedge - - angle: 90 - connection1: - - - starsplit - - topedge0 - - - boat - - staredge - - angle: 90 - tabWidth: 10 - connection10: - - - portsplit - - topedge9 - - - seat4 - - l - - {} - connection11: - - - starsplit - - botedge9 - - - seat4 - - r - - {} - connection12: - - - portsplit - - topedge11 - - - seat5 - - l - - {} - connection13: - - - starsplit - - botedge11 - - - seat5 - - r - - {} - connection14: - - - portsplit - - topedge13 - - - seat6 - - l - - {} - connection15: - - - starsplit - - botedge13 - - - seat6 - - r - - {} - connection16: - - - portsplit - - topedge15 - - - seat7 - - l - - {} - connection17: - - - starsplit - - botedge15 - - - seat7 - - r - - {} - connection18: - - - portsplit - - topedge17 - - - seat8 - - l - - {} - connection19: - - - starsplit - - botedge17 - - - seat8 - - r - - {} - connection2: - - - portsplit - - topedge1 - - - seat0 - - l - - {} - connection20: - - - portsplit - - topedge19 - - - seat9 - - l - - {} - connection21: - - - starsplit - - botedge19 - - - seat9 - - r - - {} - connection3: - - - starsplit - - botedge1 - - - seat0 - - r - - {} - connection4: - - - portsplit - - topedge3 - - - seat1 - - l - - {} - connection5: - - - starsplit - - botedge3 - - - seat1 - - r - - {} - connection6: - - - portsplit - - topedge5 - - - seat2 - - l - - {} - connection7: - - - starsplit - - botedge5 - - - seat2 - - r - - {} - connection8: - - - portsplit - - topedge7 - - - seat3 - - l - - {} - connection9: - - - starsplit - - botedge7 - - - seat3 - - r - - {} -interfaces: {} -parameters: - boat._dx: - defaultValue: 0 - spec: - minValue: null - units: mm - valueType: (float, int) - boat._dy: - defaultValue: 0 - spec: - minValue: null - units: mm - valueType: (float, int) - boat._dz: - defaultValue: 0 - spec: - minValue: null - units: mm - valueType: (float, int) - boat._q_a: - defaultValue: 1 - spec: - maxValue: 1 - minValue: -1 - valueType: (int, float) - boat._q_i: - defaultValue: 0 - spec: - maxValue: 1 - minValue: -1 - valueType: (int, float) - boat._q_j: - defaultValue: 0 - spec: - maxValue: 1 - minValue: -1 - valueType: (int, float) - boat._q_k: - defaultValue: 0 - spec: - maxValue: 1 - minValue: -1 - valueType: (int, float) - boat.depth: - defaultValue: 20 - spec: - minValue: 0 - units: mm - valueType: (float, int) - boat.length: - defaultValue: 100 - spec: - minValue: 0 - units: mm - valueType: (float, int) - boat.width: - defaultValue: 50 - spec: - minValue: 0 - units: mm - valueType: (float, int) - bow._dx: - defaultValue: 0 - spec: - minValue: null - units: mm - valueType: (float, int) - bow._dy: - defaultValue: 0 - spec: - minValue: null - units: mm - valueType: (float, int) - bow._dz: - defaultValue: 0 - spec: - minValue: null - units: mm - valueType: (float, int) - bow._q_a: - defaultValue: 1 - spec: - maxValue: 1 - minValue: -1 - valueType: (int, float) - bow._q_i: - defaultValue: 0 - spec: - maxValue: 1 - minValue: -1 - valueType: (int, float) - bow._q_j: - defaultValue: 0 - spec: - maxValue: 1 - minValue: -1 - valueType: (int, float) - bow._q_k: - defaultValue: 0 - spec: - maxValue: 1 - minValue: -1 - valueType: (int, float) - bow.point: - defaultValue: 50 - spec: - minValue: 0 - units: mm - valueType: (float, int) - seats: - defaultValue: 3 - spec: - maxValue: 10 - minValue: 1 - valueType: int - stern._dx: - defaultValue: 0 - spec: - minValue: null - units: mm - valueType: (float, int) - stern._dy: - defaultValue: 0 - spec: - minValue: null - units: mm - valueType: (float, int) - stern._dz: - defaultValue: 0 - spec: - minValue: null - units: mm - valueType: (float, int) - stern._q_a: - defaultValue: 1 - spec: - maxValue: 1 - minValue: -1 - valueType: (int, float) - stern._q_i: - defaultValue: 0 - spec: - maxValue: 1 - minValue: -1 - valueType: (int, float) - stern._q_j: - defaultValue: 0 - spec: - maxValue: 1 - minValue: -1 - valueType: (int, float) - stern._q_k: - defaultValue: 0 - spec: - maxValue: 1 - minValue: -1 - valueType: (int, float) - stern.point: - defaultValue: 50 - spec: - minValue: 0 - units: mm - valueType: (float, int) -source: ../builders/CanoeBuilder.py -subcomponents: - boat: - classname: BoatBase - kwargs: - root: true - parameters: - boat._dx: - parameter: boat._dx - boat._dy: - parameter: boat._dy - boat._dz: - parameter: boat._dz - boat._q_a: - parameter: boat._q_a - boat._q_i: - parameter: boat._q_i - boat._q_j: - parameter: boat._q_j - boat._q_k: - parameter: boat._q_k - boat.depth: - parameter: boat.depth - boat.length: - parameter: boat.length - boat.width: - parameter: boat.width - bow._dx: - parameter: bow._dx - bow._dy: - parameter: bow._dy - bow._dz: - parameter: bow._dz - bow._q_a: - parameter: bow._q_a - bow._q_i: - parameter: bow._q_i - bow._q_j: - parameter: bow._q_j - bow._q_k: - parameter: bow._q_k - bow.point: - parameter: bow.point - stern._dx: - parameter: stern._dx - stern._dy: - parameter: stern._dy - stern._dz: - parameter: stern._dz - stern._q_a: - parameter: stern._q_a - stern._q_i: - parameter: stern._q_i - stern._q_j: - parameter: stern._q_j - stern._q_k: - parameter: stern._q_k - stern.point: - parameter: stern.point - portsplit: - classname: SplitEdge - kwargs: {} - parameters: - botlength: - function: (x[0],) - parameter: &id001 - - boat.length - - seats - toplength: - function: (x[0]/(2.*x[1]+1.),) * (2*x[1]+1) - parameter: *id001 - seat0: - classname: Rectangle - kwargs: {} - parameters: - l: - function: (0 < x[1]) and x[0] or 0 - parameter: &id002 - - boat.width - - seats - w: - function: x[0]/(2.*x[1]+1.) - parameter: *id001 - seat1: - classname: Rectangle - kwargs: {} - parameters: - l: - function: (1 < x[1]) and x[0] or 0 - parameter: *id002 - w: - function: x[0]/(2.*x[1]+1.) - parameter: *id001 - seat2: - classname: Rectangle - kwargs: {} - parameters: - l: - function: (2 < x[1]) and x[0] or 0 - parameter: *id002 - w: - function: x[0]/(2.*x[1]+1.) - parameter: *id001 - seat3: - classname: Rectangle - kwargs: {} - parameters: - l: - function: (3 < x[1]) and x[0] or 0 - parameter: *id002 - w: - function: x[0]/(2.*x[1]+1.) - parameter: *id001 - seat4: - classname: Rectangle - kwargs: {} - parameters: - l: - function: (4 < x[1]) and x[0] or 0 - parameter: *id002 - w: - function: x[0]/(2.*x[1]+1.) - parameter: *id001 - seat5: - classname: Rectangle - kwargs: {} - parameters: - l: - function: (5 < x[1]) and x[0] or 0 - parameter: *id002 - w: - function: x[0]/(2.*x[1]+1.) - parameter: *id001 - seat6: - classname: Rectangle - kwargs: {} - parameters: - l: - function: (6 < x[1]) and x[0] or 0 - parameter: *id002 - w: - function: x[0]/(2.*x[1]+1.) - parameter: *id001 - seat7: - classname: Rectangle - kwargs: {} - parameters: - l: - function: (7 < x[1]) and x[0] or 0 - parameter: *id002 - w: - function: x[0]/(2.*x[1]+1.) - parameter: *id001 - seat8: - classname: Rectangle - kwargs: {} - parameters: - l: - function: (8 < x[1]) and x[0] or 0 - parameter: *id002 - w: - function: x[0]/(2.*x[1]+1.) - parameter: *id001 - seat9: - classname: Rectangle - kwargs: {} - parameters: - l: - function: (9 < x[1]) and x[0] or 0 - parameter: *id002 - w: - function: x[0]/(2.*x[1]+1.) - parameter: *id001 - starsplit: - classname: SplitEdge - kwargs: {} - parameters: - botlength: - function: (x[0]/(2.*x[1]+1.),) * (2*x[1]+1) - parameter: *id001 - toplength: - function: (x[0],) - parameter: *id001 diff --git a/rocolib/library/CatFoil.yaml b/rocolib/library/CatFoil.yaml deleted file mode 100644 index b52bb88276bcbdc667b7c942d1edf08aea75f296..0000000000000000000000000000000000000000 --- a/rocolib/library/CatFoil.yaml +++ /dev/null @@ -1,102 +0,0 @@ -connections: - connection0: - - - boat - - portedge - - - port - - mount - - angle: -180 - connection1: - - - boat - - staredge - - - star - - mount - - angle: -180 - connection2: - - - star - - join - - - port - - join - - tabWidth: 10 -interfaces: {} -parameters: - depth: - defaultValue: 50 - spec: - minValue: 0 - units: mm - valueType: (float, int) - dl: - defaultValue: 0.1 - spec: - minValue: 0 - units: mm - valueType: (float, int) - height: - defaultValue: 30 - spec: - minValue: 0 - units: mm - valueType: (float, int) - length: - defaultValue: 200 - spec: - minValue: 0 - units: mm - valueType: (float, int) - width: - defaultValue: 60 - spec: - minValue: 0 - units: mm - valueType: (float, int) -source: ../builders/CatFoilBuilder.py -subcomponents: - boat: - classname: Catamaran - kwargs: - root: true - parameters: - depth: - parameter: depth - height: - parameter: height - length: - parameter: length - width: - parameter: width - port: - classname: Foil - kwargs: {} - parameters: - depth: - parameter: depth - dl: - parameter: dl - flip: true - height: - function: sum(x)/3. - parameter: &id001 - - length - - depth - length: - parameter: length - width: - function: x/4. - parameter: width - star: - classname: Foil - kwargs: {} - parameters: - depth: - parameter: depth - dl: - parameter: dl - flip: false - height: - function: sum(x)/3. - parameter: *id001 - length: - parameter: length - width: - function: x/4. - parameter: width diff --git a/rocolib/library/Catamaran.yaml b/rocolib/library/Catamaran.yaml deleted file mode 100644 index 1de83b1b6952d00acb67af27651ce6cae89ec3b5..0000000000000000000000000000000000000000 --- a/rocolib/library/Catamaran.yaml +++ /dev/null @@ -1,106 +0,0 @@ -connections: - connection0: - - - cabin - - portedge - - - port - - portedge - - {} - connection1: - - - cabin - - staredge - - - star - - staredge - - {} -interfaces: - foreedge: - interface: foreedge - subcomponent: cabin - portedge: - interface: staredge - subcomponent: port - rearedge: - interface: rearedge - subcomponent: cabin - staredge: - interface: portedge - subcomponent: star -parameters: - depth: - defaultValue: 50 - spec: - minValue: 0 - units: mm - valueType: (float, int) - height: - defaultValue: 30 - spec: - minValue: 0 - units: mm - valueType: (float, int) - length: - defaultValue: 200 - spec: - minValue: 0 - units: mm - valueType: (float, int) - width: - defaultValue: 60 - spec: - minValue: 0 - units: mm - valueType: (float, int) -source: ../builders/CatBuilder.py -subcomponents: - cabin: - classname: Cabin - kwargs: {} - parameters: - depth: - parameter: depth - height: - parameter: height - length: - parameter: length - width: - parameter: width - port: - classname: BoatBase - kwargs: - root: true - parameters: - boat.depth: - function: sum(x)/20. - parameter: &id001 - - length - - depth - boat.length: - function: sum(x) - parameter: *id001 - boat.width: - function: x/4. - parameter: width - bow.point: - function: x/2. - parameter: length - stern.point: - function: x/8. - parameter: length - star: - classname: BoatBase - kwargs: {} - parameters: - boat.depth: - function: sum(x)/20. - parameter: *id001 - boat.length: - function: sum(x) - parameter: *id001 - boat.width: - function: x/4. - parameter: width - bow.point: - function: x/2. - parameter: length - stern.point: - function: x/8. - parameter: length diff --git a/rocolib/library/Cutout.py b/rocolib/library/Cutout.py index 77cb2bb855a3b682dadb19ff619373c8e67a60b9..cf2f49e9a4bbab332bb3681578933361c9a95242 100644 --- a/rocolib/library/Cutout.py +++ b/rocolib/library/Cutout.py @@ -8,14 +8,12 @@ class Cutout(DecorationComponent): self.addParameter("d", optional=True, overrides=("dx", "dy")) def modifyParameters(self): - if self.getParameter("d") is not None: - self.setParameter("dx", self.getParameter("d")) - self.setParameter("dy", self.getParameter("d")) + if self.p.d is not None: + self.p.dx = self.p.d + self.p.dy = self.p.d def assemble(self): - dx = self.getParameter("dx") - dy = self.getParameter("dy") - self.addFace(Rectangle("r0", dx, dy), prefix="r0") + self.addFace(Rectangle("r0", self.p.dx, self.p.dy), prefix="r0") if __name__ == "__main__": Cutout.test() diff --git a/rocolib/library/ESPSeg.py b/rocolib/library/ESPSeg.py index 520b824992cac3dc851a0dff28b8236649e71cd8..9037ab02bfced1acd4aba55924f7bba2d3b97cc1 100644 --- a/rocolib/library/ESPSeg.py +++ b/rocolib/library/ESPSeg.py @@ -2,6 +2,8 @@ from rocolib.api.components import Component from rocolib.utils.utils import copyDecorations class ESPSeg(Component): + def define(self): pass + def assemble(self): copyDecorations(self, ("rightservoface", ("right", "face0", -1, 0)), ("rightservosheath", ("sheath", "face2", -1, 0))) diff --git a/rocolib/library/Foil.yaml b/rocolib/library/Foil.yaml deleted file mode 100644 index 51f060224985c0d40572d27378913f0caf28ad58..0000000000000000000000000000000000000000 --- a/rocolib/library/Foil.yaml +++ /dev/null @@ -1,94 +0,0 @@ -connections: - connection0: - - - split - - topedge1 - - - stick - - l - - {} - connection1: - - - stick - - r - - - foil - - tip - - angle: 90 -interfaces: - join: - interface: base - subcomponent: foil - mount: - interface: botedge0 - subcomponent: split -parameters: - depth: - defaultValue: 20 - spec: - minValue: 0 - units: mm - valueType: (float, int) - dl: - defaultValue: 0.1 - spec: - minValue: 0 - units: mm - valueType: (float, int) - flip: - defaultValue: false - spec: - valueType: bool - height: - defaultValue: 100 - spec: - minValue: 0 - units: mm - valueType: (float, int) - length: - defaultValue: 40 - spec: - minValue: 0 - units: mm - valueType: (float, int) - width: - defaultValue: 10 - spec: - minValue: 0 - units: mm - valueType: (float, int) -source: ../builders/FoilBuilder.py -subcomponents: - foil: - classname: Wing - kwargs: {} - parameters: - bodylength: - parameter: depth - flip: - parameter: flip - thickness: - function: x[0] * x[1] - parameter: - - dl - - depth - wingspan: - parameter: width - wingtip: - parameter: depth - split: - classname: SplitEdge - kwargs: {} - parameters: - botlength: - function: '[sum(x)]' - parameter: &id001 - - length - - depth - toplength: - function: '[x[0]/2., x[1], x[0]/2.]' - parameter: *id001 - stick: - classname: Rectangle - kwargs: {} - parameters: - l: - parameter: height - w: - parameter: depth diff --git a/rocolib/library/Header.py b/rocolib/library/Header.py index 22827533dcc68707f52de3d36bb541fd5c2bb9f9..8b68315f0a6a1c11c0eb2ec4b6fb80acf58006a4 100644 --- a/rocolib/library/Header.py +++ b/rocolib/library/Header.py @@ -11,13 +11,13 @@ class Header(DecorationComponent): self.addParameter("diameter", 1, paramType="length") def assemble(self): - diam = self.getParameter("diameter")/2. - nr = self.getParameter("nrows") - nc = self.getParameter("ncols") + diam = self.p.diameter/2. + nr = self.p.nrows + nc = self.p.ncols def hole(i, j, d): - dx = (j - (nc-1)/2.)*self.getParameter("colsep") - dy = (i - (nr-1)/2.)*self.getParameter("rowsep") + dx = (j - (nc-1)/2.)*self.p.colsep + dy = (i - (nr-1)/2.)*self.p.rowsep return Face("r-%d-%d" % (i,j), ((dx-d, dy-d), (dx+d, dy-d), (dx+d, dy+d), (dx-d, dy+d)), recenter=False) diff --git a/rocolib/library/Kite.py b/rocolib/library/Kite.py index 5796cc34d48baaff929a1e9dbd5ad25d8070069b..735d52766ed5975cc8a8bea2a046f1c788e86ba9 100644 --- a/rocolib/library/Kite.py +++ b/rocolib/library/Kite.py @@ -12,8 +12,9 @@ class Kite(FoldedComponent): self.addEdgeInterface("t", "kite.e3", "thickness") def assemble(self): - t = self.getParameter("thickness") - a = self.getParameter("angle") + t = self.p.thickness + a = self.p.angle + a2 = deg2rad(a/2.) ar = deg2rad(a) diff --git a/rocolib/library/PinchedRectBeam.py b/rocolib/library/PinchedRectBeam.py new file mode 100644 index 0000000000000000000000000000000000000000..a58245357fa5a60abd771c42a3070136a619d7cf --- /dev/null +++ b/rocolib/library/PinchedRectBeam.py @@ -0,0 +1,76 @@ +from rocolib.api.components import FoldedComponent +from rocolib.api.composables.graph.Face import Face, Rectangle +from rocolib.utils.numsym import sqrt, arccos, rad2deg + +class PinchedRectBeam(FoldedComponent): + def define(self): + self.addParameter("topwidth", 10, paramType="length") + self.addParameter("topdepth", 30, paramType="length") + self.addParameter("botwidth", 20, paramType="length") + self.addParameter("botdepth", 20, paramType="length") + self.addParameter("length", 30, paramType="length") + + for i in range(4): + self.addEdgeInterface(f"topedge{i}", f"s{i}t.e2", ["topwidth", "topdepth"][i % 2]) + self.addEdgeInterface(f"botedge{i}", f"s{i}b.e2", ["botwidth", "botdepth"][i % 2]) + + def modifyParameters(self): + tw = self.p.topwidth + td = self.p.topdepth + bw = self.p.botwidth + bd = self.p.botdepth + if (tw + td != bw + bd): + raise ValueError(f"Unequal perimeters: top = {2*(tw+td)}, bot = {2*(bw+bd)}") + + def assemble(self): + tw = self.p.topwidth + td = self.p.topdepth + bw = self.p.botwidth + bd = self.p.botdepth + l = self.p.length + + if bw < tw: + mirror = True + bw, bd = bd, bw + tw, td = td, tw + else: + mirror = False + + x = (bw-tw)/2 + a = 90-rad2deg(arccos(x/l)) + q = 180-rad2deg(arccos(x*x/(l*l))) + + rs = [] + rs.append(Face("", ((0, -l), (x, 0), (0,0)))) + rs.append(Face("", ((0, -l), (bw, -l), (bw - x, 0), (x, 0)))) + rs.append(Face("", ((bw, -l), (bw+bd, -l), (bw+bd+x, 0), (bw-x, 0)))) + rs.append(Face("", ((0, -l), (bw, -l), (bw - x, 0), (x, 0)))) + rs.append(Face("", ((bw, -l), (bw+bd, -l), (bw+bd, 0), (bw-x, 0)))) + + self.attachEdge(None, rs[0], "e2", prefix="r0", angle=90) + self.attachEdge("r0.e1", rs[1], "e0", prefix="r1", angle=q) + self.attachEdge("r1.e2", rs[2], "e0", prefix="r2", angle=q) + self.attachEdge("r2.e2", rs[3], "e0", prefix="r3", angle=q) + self.attachEdge("r3.e2", rs[4], "e0", prefix="r4", angle=q) + + self.attachEdge("r1.e1", Rectangle("", bw, 0), "e0", prefix="s0b", angle=-a) + self.attachEdge("r2.e1", Rectangle("", bd, 0), "e0", prefix="s1b", angle=a) + self.attachEdge("r3.e1", Rectangle("", bw, 0), "e0", prefix="s2b", angle=-a) + self.attachEdge("r4.e1", Rectangle("", bd, 0), "e0", prefix="s3b", angle=a) + + self.attachEdge("r1.e3", Rectangle("", tw, 0), "e0", prefix="s0t", angle=a) + self.attachEdge("r2.e3", Rectangle("", td, 0), "e0", prefix="s1t", angle=-a) + self.attachEdge("r3.e3", Rectangle("", tw, 0), "e0", prefix="s2t", angle=a) + self.attachEdge("r4.e3", Face("", ((td-x, 0), (td, 0), (0, 0))), "e0", prefix="s3t", angle=-a) + + self.addTab("r0.e0", "r4.e2", angle= 0, width=min(10, bd)) + + if mirror: + self.getGraph().mirror() + for j in range(4): + i = 3-j + self.setEdgeInterface(f"topedge{j}", f"s{i}t.e2", ["topwidth", "topdepth"][i % 2]) + self.setEdgeInterface(f"botedge{j}", f"s{i}b.e2", ["botwidth", "botdepth"][i % 2]) + +if __name__ == "__main__": + PinchedRectBeam.test() diff --git a/rocolib/library/RectBeam.py b/rocolib/library/RectBeam.py index d45e0cd4075f1ed3e7085b1384831b9d8f3a6705..474e247b39209ba69f17a9318e956041462ea762 100644 --- a/rocolib/library/RectBeam.py +++ b/rocolib/library/RectBeam.py @@ -30,27 +30,27 @@ class RectBeam(FoldedComponent): self.addEdgeInterface("slotedge", "r0.e3", "length") def modifyParameters(self): - self.setParameter("width", max(self.getParameter("width"), self.getParameter("minwidth"))) - self.setParameter("depth", max(self.getParameter("depth"), self.getParameter("mindepth"))) - self.setParameter("length", max(self.getParameter("length"), self.getParameter("minlength"))) + self.p.width = max(self.p.width, self.p.minwidth) + self.p.depth = max(self.p.depth, self.p.mindepth) + self.p.length = max(self.p.length, self.p.minlength) def assemble(self): - if self.getParameter("angle") is not None: - bangle = 90 - self.getParameter("angle") - tangle = 90 - self.getParameter("angle") + if self.p.angle is not None: + bangle = 90 - self.p.angle + tangle = 90 - self.p.angle else: - bangle = 90 - self.getParameter("bangle") - tangle = 90 - self.getParameter("tangle") + bangle = 90 - self.p.bangle + tangle = 90 - self.p.tangle try: - root = self.getParameter("root") + root = self.p.root except KeyError: root = None - length = self.getParameter("length") - width = self.getParameter("width") - depth = self.getParameter("depth") - phase = self.getParameter("phase") + length = self.p.length + width = self.p.width + depth = self.p.depth + phase = self.p.phase def dl(a): return np.tan(np.deg2rad(a)) * depth @@ -83,7 +83,7 @@ class RectBeam(FoldedComponent): slotEdge = "r0.e3" tabEdge = "r3.e1" - if self.getParameter("addTabs"): + if self.p.addTabs: self.addTab(slotEdge, tabEdge, angle= 90, width=min(10, [depth, width][phase % 2])) if __name__ == "__main__": diff --git a/rocolib/library/Rectangle.py b/rocolib/library/Rectangle.py index ab31221ac624f4f763c8063f4cc6df2ecd8e5cc3..cbdd425194c95558d33470afba3654a612771e3f 100644 --- a/rocolib/library/Rectangle.py +++ b/rocolib/library/Rectangle.py @@ -15,10 +15,7 @@ class Rectangle(FoldedComponent): self.addFaceInterface("face", "r") def assemble(self): - dx = self.getParameter("l") - dy = self.getParameter("w") - - self.addFace(Rect("r", dx, dy)) + self.addFace(Rect("r", self.p.l, self.p.w)) if __name__ == "__main__": import sympy diff --git a/rocolib/library/RegularNGon.py b/rocolib/library/RegularNGon.py index e1897fe05050e5a6692e07df6c2f73e0fb3fd740..6f128eaa93c1ace3fba3b3d6f450d3b9cf0de9dd 100644 --- a/rocolib/library/RegularNGon.py +++ b/rocolib/library/RegularNGon.py @@ -11,12 +11,9 @@ class RegularNGon(FoldedComponent): self.addFaceInterface("face", "r") def assemble(self): - n = self.getParameter("n") - l = self.getParameter("radius") + self.addFace(Shape("r", self.p.n, self.p.radius)) - self.addFace(Shape("r", n, l)) - - for i in range(n): + for i in range(self.p.n): try: self.setEdgeInterface("e%d" % i, "e%d" % i, "radius") except KeyError: diff --git a/rocolib/library/RightTriangle.py b/rocolib/library/RightTriangle.py index 200714c467d87a397a425d59b99e6421cae62dcf..e5a0629ef4eaa70c0a8dfcd928246577141801b2 100644 --- a/rocolib/library/RightTriangle.py +++ b/rocolib/library/RightTriangle.py @@ -14,10 +14,7 @@ class RightTriangle(FoldedComponent): self.addFaceInterface("face", "f") def assemble(self): - dx = self.getParameter("l") - dy = self.getParameter("w") - - self.addFace(Face("f", dx, dy)) + self.addFace(Face("f", self.p.l, self.p.w)) if __name__ == "__main__": import sympy diff --git a/rocolib/library/ServoMotor.py b/rocolib/library/ServoMotor.py index 954d2a97de209b5d2389449824e6c18022b3f4ab..a3b88ca7fa79c819668fcf516946781da79dc49c 100644 --- a/rocolib/library/ServoMotor.py +++ b/rocolib/library/ServoMotor.py @@ -15,15 +15,14 @@ class ServoMotor(FoldedComponent): self.addFaceInterface("horn", "horn") def assemble(self): - s = self.getParameter("servo") - a = self.getParameter("angle") + s = self.p.servo dz = getDim(s, "hornheight") dy = getDim(s, "motorlength") / 2 - getDim(s, "hornoffset") f = Shape("horn", 0, 0) decorateGraph(f, Shape("hole", 1, 1)) self.addFace(f) - self.setInterface("mount", AnchorPort(self, self.getGraph(), "horn", dot(RotateZ(a), Translate([0,-dy,dz])))) + self.setInterface("mount", AnchorPort(self, self.getGraph(), "horn", dot(RotateZ(self.p.angle), Translate([0,-dy,dz])))) if __name__ == "__main__": ServoMotor.test() diff --git a/rocolib/library/ServoMount.py b/rocolib/library/ServoMount.py index 88bc3127a65d5ac36794ee92577399a05a7ff299..797a1e9823560b0849711f0bc35e1a7021e3c7e1 100644 --- a/rocolib/library/ServoMount.py +++ b/rocolib/library/ServoMount.py @@ -5,28 +5,24 @@ from rocolib.api.Function import Function class ServoMount(Component): + def define(self): pass + def modifyParameters(self): - if self.getParameter("offset"): + if self.p.offset: return - servo = self.getParameter("servo") - - l = self.getParameter("length") - - ml = getDim(servo, "motorlength") - sl = getDim(servo, "shoulderlength") - ho = getDim(servo, "hornoffset") - - s = self.getParameter("shift") + ml = getDim(self.p.servo, "motorlength") + sl = getDim(self.p.servo, "shoulderlength") + ho = getDim(self.p.servo, "hornoffset") - dy = l/2. - ml/2. - sl - if self.getParameter("center"): + dy = self.p.length/2. - ml/2. - sl + if self.p.center: dy = min(dy, ml/2. - ho) - dy -= s - if self.getParameter("flip"): + dy -= self.p.shift + if self.p.flip: dy = -dy - self.setParameter("offset", (0, dy)) + self.p.offset = (0, dy) if __name__ == "__main__": ServoMount.test() diff --git a/rocolib/library/SimpleRectBeam.py b/rocolib/library/SimpleRectBeam.py index 46b14c2fc6c8f48740a65edda7e4ceb5f6adcb63..dfcca369e64b87fff0ab6b6906c58449af8ece7b 100644 --- a/rocolib/library/SimpleRectBeam.py +++ b/rocolib/library/SimpleRectBeam.py @@ -17,15 +17,11 @@ class SimpleRectBeam(FoldedComponent): self.addEdgeInterface("tabedge", "r0.e3", "length") def assemble(self): - length = self.getParameter("length") - width = self.getParameter("width") - depth = self.getParameter("depth") - rs = [] - rs.append(Rectangle("", width, length)) - rs.append(Rectangle("", depth, length)) - rs.append(Rectangle("", width, length)) - rs.append(Rectangle("", depth, length)) + rs.append(Rectangle("", self.p.width, self.p.length)) + rs.append(Rectangle("", self.p.depth, self.p.length)) + rs.append(Rectangle("", self.p.width, self.p.length)) + rs.append(Rectangle("", self.p.depth, self.p.length)) fromEdge = None for i in range(4): @@ -35,8 +31,8 @@ class SimpleRectBeam(FoldedComponent): tabEdge, slotEdge = "r0.e3", "r3.e1" - if self.getParameter("addTabs"): - self.addTab(tabEdge, slotEdge, angle= 90, width=min(10, depth)) + if self.p.addTabs: + self.addTab(tabEdge, slotEdge, angle= 90, width=min(10, self.p.depth)) if __name__ == "__main__": SimpleRectBeam.test() diff --git a/rocolib/library/SimpleUChannel.py b/rocolib/library/SimpleUChannel.py index 647a60437a3df50280d60064ef6c3bdda317cf65..9f4a52b17abe81b851fedde03c509d178fd843a7 100644 --- a/rocolib/library/SimpleUChannel.py +++ b/rocolib/library/SimpleUChannel.py @@ -21,14 +21,10 @@ class SimpleUChannel(FoldedComponent): self.addEdgeInterface("bot", ["r%d.e2" % (2-i) for i in range(3)], ["depth", "width", "depth"]) def assemble(self): - length = self.getParameter("length") - width = self.getParameter("width") - depth = self.getParameter("depth") - rs = [] - rs.append(Rectangle("", depth, length)) - rs.append(Rectangle("", width, length)) - rs.append(Rectangle("", depth, length)) + rs.append(Rectangle("", self.p.depth, self.p.length)) + rs.append(Rectangle("", self.p.width, self.p.length)) + rs.append(Rectangle("", self.p.depth, self.p.length)) fromEdge = None for i in range(3): diff --git a/rocolib/library/SplitEdge.py b/rocolib/library/SplitEdge.py index 8b1f527a64e594c54a1868d01e95f641c8a2dc81..0c1cabda6f2f2328e8ba5fc92e47955b45f47f15 100644 --- a/rocolib/library/SplitEdge.py +++ b/rocolib/library/SplitEdge.py @@ -17,12 +17,12 @@ class SplitEdge(FoldedComponent): self.addEdgeInterface("botedge%d" % i, None, "botlength") def assemble(self): - t = cumsum(self.getParameter("toplength")[::-1]) - b = cumsum(self.getParameter("botlength")[::-1]) + t = cumsum(self.p.toplength[::-1]) + b = cumsum(self.p.botlength[::-1]) if not isclose(t[-1], b[-1]): raise ValueError("SplitEdge lengths not equal: %s <> %s" % (repr(t), repr(b))) - w = self.getParameter("width") + w = self.p.width pts = [(x, 0) for x in b] pts += [(x, w) for x in t[::-1]] pts += [(0, w), (0,0)] diff --git a/rocolib/library/Stool.py b/rocolib/library/Stool.py index 3bf5b6ed795df83b51f9658e7dff1d27e4a7d147..c5ce4be0f99dc40017c6b366c503ac933169ce20 100644 --- a/rocolib/library/Stool.py +++ b/rocolib/library/Stool.py @@ -13,14 +13,14 @@ class Stool(FoldedComponent): self.addParameter("angle", 80, paramType="angle") def modifyParameters(self): - if self.getParameter("radius") is not None: - self.setParameter("legwidth", r2l.r2l(self.getParameter("radius"), self.getParameter("legs")*2)) + if self.p.radius is not None: + self.p.legwidth = r2l.r2l(self.p.radius, self.p.legs*2) def assemble(self): - h = self.getParameter("height") - lp = self.getParameter("legs") - e = self.getParameter("legwidth") - ap = self.getParameter("angle") + h = self.p.height + lp = self.p.legs + e = self.p.legwidth + ap = self.p.angle n = lp * 2 self.addFace(RegularNGon("", n, e), "seat") diff --git a/rocolib/library/Tail.py b/rocolib/library/Tail.py index 20671275919b194bbe6188114805adfa6b160108..e9d477e5f0a970a9d4609580a335c10b0d4c231c 100644 --- a/rocolib/library/Tail.py +++ b/rocolib/library/Tail.py @@ -15,12 +15,12 @@ class Tail(FoldedComponent): def assemble(self): - h = self.getParameter("height") - w = self.getParameter("width") - d = self.getParameter("depth") + h = self.p.height + w = self.p.width + d = self.p.depth - flapwidth = self.getParameter("flapwidth") - tailwidth = self.getParameter("tailwidth") + flapwidth = self.p.flapwidth + tailwidth = self.p.tailwidth lr0 = (1-flapwidth)/2. lr1 = 1-lr0 lt0 = (1-tailwidth)/2. diff --git a/rocolib/library/Tire.py b/rocolib/library/Tire.py index 29fa812dcf4bf08de981a3bd191bc5c189e27f1b..6e563dafd970a6352abd6e09d7ad7f7aa88cc6af 100644 --- a/rocolib/library/Tire.py +++ b/rocolib/library/Tire.py @@ -17,7 +17,7 @@ class Tire(FoldedComponent): self.addFaceInterface("face", "w1") def assemble(self): - thickness = self.getParameter("tire_thickness") + thickness = self.p.tire_thickness if thickness == 0: #tickness is 0 or not specified self.regularNgonTireAssembly() @@ -28,15 +28,13 @@ class Tire(FoldedComponent): def regularNgonTireAssembly(self): # number of polygon sides n = 40 - l = self.getParameter("radius") - - self.addFace(RegularNGon2("w1", n, l)) + self.addFace(RegularNGon2("w1", n, self.p.radius)) def foldedTireAssembly(self): # number of polygon sides n = 9 - r = self.getParameter("radius") - tw = self.getParameter("tire_thickness") + r = self.p.radius + tw = self.p.tire_thickness # length of sl = float(2 * r * np.cos(np.deg2rad(90-180/n))) diff --git a/rocolib/library/Trapezoid.py b/rocolib/library/Trapezoid.py index 0bcf695602f11614f76f535b90fd4d2f69f511a7..97307d15bd6c9b528135c5231d97dfc6cfa43b3b 100644 --- a/rocolib/library/Trapezoid.py +++ b/rocolib/library/Trapezoid.py @@ -17,11 +17,11 @@ class Trapezoid(FoldedComponent): self.addFaceInterface("face", "f") def assemble(self): - x1 = self.getParameter("l")/2 - x2 = self.getParameter("lt")/2 - dy = self.getParameter("w")/2 + x1 = self.p.l/2 + x2 = self.p.lt/2 + dy = self.p.w/2 - if self.getParameter("center"): + if self.p.center: xa, xb = x2, -x2 else: xa, xb = x1, x1 - 2*x2 diff --git a/rocolib/library/Trimaran.yaml b/rocolib/library/Trimaran.yaml deleted file mode 100644 index 032a1463695d19053944a5cebb14d459c10cd91f..0000000000000000000000000000000000000000 --- a/rocolib/library/Trimaran.yaml +++ /dev/null @@ -1,664 +0,0 @@ -connections: - connection0: - - - portsplit0 - - botedge0 - - - boat0 - - portedge - - angle: -90 - connection1: - - - starsplit0 - - topedge0 - - - boat0 - - staredge - - angle: -90 - connection10: - - - starsplit1 - - botedge2 - - - seat2 - - l - - {} - connection11: - - - portsplit2 - - topedge2 - - - seat2 - - r - - {} - connection12: - - - starsplit0 - - botedge3 - - - seat3 - - l - - {} - connection13: - - - portsplit1 - - topedge3 - - - seat3 - - r - - {} - connection14: - - - starsplit1 - - botedge4 - - - seat4 - - l - - {} - connection15: - - - portsplit2 - - topedge4 - - - seat4 - - r - - {} - connection16: - - - starsplit0 - - botedge5 - - - seat5 - - l - - {} - connection17: - - - portsplit1 - - topedge5 - - - seat5 - - r - - {} - connection18: - - - starsplit1 - - botedge6 - - - seat6 - - l - - {} - connection19: - - - portsplit2 - - topedge6 - - - seat6 - - r - - {} - connection2: - - - portsplit1 - - botedge0 - - - boat1 - - portedge - - angle: -90 - connection20: - - - starsplit0 - - botedge7 - - - seat7 - - l - - {} - connection21: - - - portsplit1 - - topedge7 - - - seat7 - - r - - {} - connection22: - - - starsplit1 - - botedge8 - - - seat8 - - l - - {} - connection23: - - - portsplit2 - - topedge8 - - - seat8 - - r - - {} - connection24: - - - starsplit0 - - botedge9 - - - seat9 - - l - - {} - connection25: - - - portsplit1 - - topedge9 - - - seat9 - - r - - {} - connection3: - - - starsplit1 - - topedge0 - - - boat1 - - staredge - - angle: -90 - connection4: - - - portsplit2 - - botedge0 - - - boat2 - - portedge - - angle: -90 - connection5: - - - starsplit2 - - topedge0 - - - boat2 - - staredge - - angle: -90 - connection6: - - - starsplit1 - - botedge0 - - - seat0 - - l - - {} - connection7: - - - portsplit2 - - topedge0 - - - seat0 - - r - - {} - connection8: - - - starsplit0 - - botedge1 - - - seat1 - - l - - {} - connection9: - - - portsplit1 - - topedge1 - - - seat1 - - r - - {} -interfaces: {} -parameters: - boat._dx: - defaultValue: 0 - spec: - minValue: null - units: mm - valueType: (float, int) - boat._dy: - defaultValue: 0 - spec: - minValue: null - units: mm - valueType: (float, int) - boat._dz: - defaultValue: 0 - spec: - minValue: null - units: mm - valueType: (float, int) - boat._q_a: - defaultValue: 1 - spec: - maxValue: 1 - minValue: -1 - valueType: (int, float) - boat._q_i: - defaultValue: 0 - spec: - maxValue: 1 - minValue: -1 - valueType: (int, float) - boat._q_j: - defaultValue: 0 - spec: - maxValue: 1 - minValue: -1 - valueType: (int, float) - boat._q_k: - defaultValue: 0 - spec: - maxValue: 1 - minValue: -1 - valueType: (int, float) - boat.depth: - defaultValue: 20 - spec: - minValue: 0 - units: mm - valueType: (float, int) - boat.length: - defaultValue: 100 - spec: - minValue: 0 - units: mm - valueType: (float, int) - boat.width: - defaultValue: 50 - spec: - minValue: 0 - units: mm - valueType: (float, int) - bow._dx: - defaultValue: 0 - spec: - minValue: null - units: mm - valueType: (float, int) - bow._dy: - defaultValue: 0 - spec: - minValue: null - units: mm - valueType: (float, int) - bow._dz: - defaultValue: 0 - spec: - minValue: null - units: mm - valueType: (float, int) - bow._q_a: - defaultValue: 1 - spec: - maxValue: 1 - minValue: -1 - valueType: (int, float) - bow._q_i: - defaultValue: 0 - spec: - maxValue: 1 - minValue: -1 - valueType: (int, float) - bow._q_j: - defaultValue: 0 - spec: - maxValue: 1 - minValue: -1 - valueType: (int, float) - bow._q_k: - defaultValue: 0 - spec: - maxValue: 1 - minValue: -1 - valueType: (int, float) - bow.point: - defaultValue: 50 - spec: - minValue: 0 - units: mm - valueType: (float, int) - seats: - defaultValue: 6 - spec: - maxValue: 10 - minValue: 2 - valueType: int - spacing: - defaultValue: 25 - spec: - minValue: 0 - units: mm - valueType: (float, int) - stern._dx: - defaultValue: 0 - spec: - minValue: null - units: mm - valueType: (float, int) - stern._dy: - defaultValue: 0 - spec: - minValue: null - units: mm - valueType: (float, int) - stern._dz: - defaultValue: 0 - spec: - minValue: null - units: mm - valueType: (float, int) - stern._q_a: - defaultValue: 1 - spec: - maxValue: 1 - minValue: -1 - valueType: (int, float) - stern._q_i: - defaultValue: 0 - spec: - maxValue: 1 - minValue: -1 - valueType: (int, float) - stern._q_j: - defaultValue: 0 - spec: - maxValue: 1 - minValue: -1 - valueType: (int, float) - stern._q_k: - defaultValue: 0 - spec: - maxValue: 1 - minValue: -1 - valueType: (int, float) - stern.point: - defaultValue: 50 - spec: - minValue: 0 - units: mm - valueType: (float, int) -source: ../builders/TrimaranBuilder.py -subcomponents: - boat0: - classname: BoatBase - kwargs: - root: true - parameters: - boat._dx: - parameter: boat._dx - boat._dy: - parameter: boat._dy - boat._dz: - parameter: boat._dz - boat._q_a: - parameter: boat._q_a - boat._q_i: - parameter: boat._q_i - boat._q_j: - parameter: boat._q_j - boat._q_k: - parameter: boat._q_k - boat.depth: - parameter: boat.depth - boat.length: - parameter: boat.length - boat.width: - parameter: boat.width - bow._dx: - parameter: bow._dx - bow._dy: - parameter: bow._dy - bow._dz: - parameter: bow._dz - bow._q_a: - parameter: bow._q_a - bow._q_i: - parameter: bow._q_i - bow._q_j: - parameter: bow._q_j - bow._q_k: - parameter: bow._q_k - bow.point: - parameter: bow.point - stern._dx: - parameter: stern._dx - stern._dy: - parameter: stern._dy - stern._dz: - parameter: stern._dz - stern._q_a: - parameter: stern._q_a - stern._q_i: - parameter: stern._q_i - stern._q_j: - parameter: stern._q_j - stern._q_k: - parameter: stern._q_k - stern.point: - parameter: stern.point - boat1: - classname: BoatBase - kwargs: - root: true - parameters: - boat._dx: - parameter: boat._dx - boat._dy: - parameter: boat._dy - boat._dz: - parameter: boat._dz - boat._q_a: - parameter: boat._q_a - boat._q_i: - parameter: boat._q_i - boat._q_j: - parameter: boat._q_j - boat._q_k: - parameter: boat._q_k - boat.depth: - parameter: boat.depth - boat.length: - parameter: boat.length - boat.width: - parameter: boat.width - bow._dx: - parameter: bow._dx - bow._dy: - parameter: bow._dy - bow._dz: - parameter: bow._dz - bow._q_a: - parameter: bow._q_a - bow._q_i: - parameter: bow._q_i - bow._q_j: - parameter: bow._q_j - bow._q_k: - parameter: bow._q_k - bow.point: - parameter: bow.point - stern._dx: - parameter: stern._dx - stern._dy: - parameter: stern._dy - stern._dz: - parameter: stern._dz - stern._q_a: - parameter: stern._q_a - stern._q_i: - parameter: stern._q_i - stern._q_j: - parameter: stern._q_j - stern._q_k: - parameter: stern._q_k - stern.point: - parameter: stern.point - boat2: - classname: BoatBase - kwargs: - root: true - parameters: - boat._dx: - parameter: boat._dx - boat._dy: - parameter: boat._dy - boat._dz: - parameter: boat._dz - boat._q_a: - parameter: boat._q_a - boat._q_i: - parameter: boat._q_i - boat._q_j: - parameter: boat._q_j - boat._q_k: - parameter: boat._q_k - boat.depth: - parameter: boat.depth - boat.length: - parameter: boat.length - boat.width: - parameter: boat.width - bow._dx: - parameter: bow._dx - bow._dy: - parameter: bow._dy - bow._dz: - parameter: bow._dz - bow._q_a: - parameter: bow._q_a - bow._q_i: - parameter: bow._q_i - bow._q_j: - parameter: bow._q_j - bow._q_k: - parameter: bow._q_k - bow.point: - parameter: bow.point - stern._dx: - parameter: stern._dx - stern._dy: - parameter: stern._dy - stern._dz: - parameter: stern._dz - stern._q_a: - parameter: stern._q_a - stern._q_i: - parameter: stern._q_i - stern._q_j: - parameter: stern._q_j - stern._q_k: - parameter: stern._q_k - stern.point: - parameter: stern.point - portsplit0: - classname: SplitEdge - kwargs: {} - parameters: - botlength: - function: '[x[0]]' - parameter: &id001 - - boat.length - - seats - toplength: - function: '[x[0]/(1.*x[1])] * x[1]' - parameter: *id001 - portsplit1: - classname: SplitEdge - kwargs: {} - parameters: - botlength: - function: '[x[0]]' - parameter: *id001 - toplength: - function: '[x[0]/(1.*x[1])] * x[1]' - parameter: *id001 - portsplit2: - classname: SplitEdge - kwargs: {} - parameters: - botlength: - function: '[x[0]]' - parameter: *id001 - toplength: - function: '[x[0]/(1.*x[1])] * x[1]' - parameter: *id001 - seat0: - classname: Rectangle - kwargs: {} - parameters: - l: - function: (0 < x[1]) and x[0] or 0 - parameter: &id002 - - spacing - - seats - w: - function: x[0]/(1.*x[1]) - parameter: *id001 - seat1: - classname: Rectangle - kwargs: {} - parameters: - l: - function: (1 < x[1]) and x[0] or 0 - parameter: *id002 - w: - function: x[0]/(1.*x[1]) - parameter: *id001 - seat2: - classname: Rectangle - kwargs: {} - parameters: - l: - function: (2 < x[1]) and x[0] or 0 - parameter: *id002 - w: - function: x[0]/(1.*x[1]) - parameter: *id001 - seat3: - classname: Rectangle - kwargs: {} - parameters: - l: - function: (3 < x[1]) and x[0] or 0 - parameter: *id002 - w: - function: x[0]/(1.*x[1]) - parameter: *id001 - seat4: - classname: Rectangle - kwargs: {} - parameters: - l: - function: (4 < x[1]) and x[0] or 0 - parameter: *id002 - w: - function: x[0]/(1.*x[1]) - parameter: *id001 - seat5: - classname: Rectangle - kwargs: {} - parameters: - l: - function: (5 < x[1]) and x[0] or 0 - parameter: *id002 - w: - function: x[0]/(1.*x[1]) - parameter: *id001 - seat6: - classname: Rectangle - kwargs: {} - parameters: - l: - function: (6 < x[1]) and x[0] or 0 - parameter: *id002 - w: - function: x[0]/(1.*x[1]) - parameter: *id001 - seat7: - classname: Rectangle - kwargs: {} - parameters: - l: - function: (7 < x[1]) and x[0] or 0 - parameter: *id002 - w: - function: x[0]/(1.*x[1]) - parameter: *id001 - seat8: - classname: Rectangle - kwargs: {} - parameters: - l: - function: (8 < x[1]) and x[0] or 0 - parameter: *id002 - w: - function: x[0]/(1.*x[1]) - parameter: *id001 - seat9: - classname: Rectangle - kwargs: {} - parameters: - l: - function: (9 < x[1]) and x[0] or 0 - parameter: *id002 - w: - function: x[0]/(1.*x[1]) - parameter: *id001 - starsplit0: - classname: SplitEdge - kwargs: {} - parameters: - botlength: - function: '[x[0]/(1.*x[1])] * x[1]' - parameter: *id001 - toplength: - function: '[x[0]]' - parameter: *id001 - starsplit1: - classname: SplitEdge - kwargs: {} - parameters: - botlength: - function: '[x[0]/(1.*x[1])] * x[1]' - parameter: *id001 - toplength: - function: '[x[0]]' - parameter: *id001 - starsplit2: - classname: SplitEdge - kwargs: {} - parameters: - botlength: - function: '[x[0]/(1.*x[1])] * x[1]' - parameter: *id001 - toplength: - function: '[x[0]]' - parameter: *id001 diff --git a/rocolib/library/Tug.yaml b/rocolib/library/Tug.yaml deleted file mode 100644 index 7444ea8f2200f4079955451b694a976cad470e16..0000000000000000000000000000000000000000 --- a/rocolib/library/Tug.yaml +++ /dev/null @@ -1,75 +0,0 @@ -connections: - connection0: - - - cabin - - portedge - - - boat - - portedge - - angle: 0 - connection1: - - - cabin - - staredge - - - boat - - staredge - - angle: 0 - tabWidth: 10 -interfaces: {} -parameters: - depth: - defaultValue: 50 - spec: - minValue: 0 - units: mm - valueType: (float, int) - height: - defaultValue: 30 - spec: - minValue: 0 - units: mm - valueType: (float, int) - length: - defaultValue: 200 - spec: - minValue: 0 - units: mm - valueType: (float, int) - width: - defaultValue: 60 - spec: - minValue: 0 - units: mm - valueType: (float, int) -source: ../builders/TugBuilder.py -subcomponents: - boat: - classname: BoatBase - kwargs: - root: true - parameters: - boat.depth: - function: x/3. - parameter: width - boat.length: - function: sum(x) - parameter: - - length - - depth - boat.width: - parameter: width - bow.point: - function: x/2. - parameter: length - stern.point: - function: x/8. - parameter: length - cabin: - classname: Cabin - kwargs: {} - parameters: - depth: - parameter: depth - height: - parameter: height - length: - parameter: length - width: - parameter: width diff --git a/rocolib/library/TwoDOF.py b/rocolib/library/TwoDOF.py new file mode 100644 index 0000000000000000000000000000000000000000..82bbe7277cf7789779028c4926c31edcf1eaaf80 --- /dev/null +++ b/rocolib/library/TwoDOF.py @@ -0,0 +1,33 @@ +from rocolib.api.components import FoldedComponent +from rocolib.api.composables.graph.Face import Rectangle, Face + +class TwoDOF(FoldedComponent): + def define(self): + self.addParameter("mountlength", 40, paramType="length") + self.addParameter("handlelength", 15, paramType="length") + self.addParameter("thickness", 10, paramType="length") + self.addParameter("pitch", 135, paramType="angle") + self.addParameter("yaw", 60, paramType="angle") + + self.addEdgeInterface("mountedge", "mount.e0", "width") + self.addEdgeInterface("oaredge", "r2.e2", "h") + + def assemble(self): + t = self.p.thickness + w = self.p.mountlength + h = self.p.handlelength + p = self.p.pitch + y = self.p.yaw + + b = Face("", ((w, 0), (w, t), (w/2,t), (0,t), (0,0))) + b0 = Rectangle("", w, 0) + r1 = Rectangle("", w/2, t) + r2 = Rectangle("", h, t) + + self.addFace(b, "base") + self.attachEdge("base.e2", r1, "e0", prefix="r1", angle=-180) + self.attachEdge("r1.e3", r2, "e1", prefix="r2", angle=y) + self.attachEdge("base.e0", b0, "e2", prefix="mount", angle=p) + +if __name__ == "__main__": + TwoDOF.test() diff --git a/rocolib/library/TwoNGons.py b/rocolib/library/TwoNGons.py index cacc3ee962bb2d366ddaaa70bc581f28a86eab7e..07e1a19b7a609cfbc73b3dbb1d1376b23ee1dadd 100644 --- a/rocolib/library/TwoNGons.py +++ b/rocolib/library/TwoNGons.py @@ -11,13 +11,8 @@ class TwoNGons(FoldedComponent): self.addParameter("radius", 25, paramType="length") def assemble(self): - n1 = self.getParameter("n1") - n2 = self.getParameter("n2") - d = self.getParameter("d") - l = self.getParameter("radius") - - self.addFace(Shape("", n1, l), "r1") - self.attachFace("r1", Shape("", n2, l), "r2", Translate([0,0,d])) + self.addFace(Shape("", self.p.n1, self.p.radius), "r1") + self.attachFace("r1", Shape("", self.p.n2, self.p.radius), "r2", Translate([0,0,self.p.d])) if __name__ == "__main__": TwoNGons.test() diff --git a/rocolib/library/UChannel.py b/rocolib/library/UChannel.py index 010014daf61e217b8a4fe479642f6c95091e4f8f..b16166970d50c2968ff538ebd3922c6e2f76e999 100644 --- a/rocolib/library/UChannel.py +++ b/rocolib/library/UChannel.py @@ -24,17 +24,17 @@ class UChannel(FoldedComponent): self.addEdgeInterface("redge", "r2.e1", "length") def modifyParameters(self): - if self.getParameter("angle") is not None: - self.setParameter("bangle", self.getParameter("angle")) - self.setParameter("tangle", self.getParameter("angle")) + if self.p.angle is not None: + self.p.bangle = self.p.angle + self.p.tangle = self.p.angle def assemble(self): - bangle = 90 - self.getParameter("bangle") - tangle = 90 - self.getParameter("tangle") + bangle = 90 - self.p.bangle + tangle = 90 - self.p.tangle - length = self.getParameter("length") - width = self.getParameter("width") - depth = self.getParameter("depth") + length = self.p.length + width = self.p.width + depth = self.p.depth def dl(a): return np.tan(np.deg2rad(a)) * depth @@ -72,7 +72,7 @@ if __name__ == "__main__": #test sympy r = UChannel() - r.setParameter("angle", 90) + r.p.angle = 90 r.makeOutput(useDefaultParameters=False, default=False) g = r.getGraph() for f in g.faces: diff --git a/rocolib/library/VLeg.py b/rocolib/library/VLeg.py index 7f77bd88ae1407553f540e06d3feff9f63c4c3d0..ff37fdd2d37d7e7d5dc6fbfc4d7e9639ebfd0b06 100644 --- a/rocolib/library/VLeg.py +++ b/rocolib/library/VLeg.py @@ -14,10 +14,10 @@ class VLeg(FoldedComponent): self.addEdgeInterface("rightedge", "leg.e2", "height") def assemble(self): - h = self.getParameter("height") - w = self.getParameter("width") - t = self.getParameter("thickness") - r = self.getParameter("taper") * t + h = self.p.height + w = self.p.width + t = self.p.thickness + r = self.p.taper * t s = Face("", ((h, 0), (h, w), (0, w), (0, w-r), (h-t, w-t), (h-t, t), (0, r), (0,0))) self.addFace(s, "leg") diff --git a/rocolib/library/Wing.py b/rocolib/library/Wing.py index 9019d4b1e3dfa67e8341ac6dada645cbfe8f6aa6..93c76a0f68bad3258346c8b65aec3bf7be9d8171 100644 --- a/rocolib/library/Wing.py +++ b/rocolib/library/Wing.py @@ -17,11 +17,11 @@ class Wing(FoldedComponent): self.addFaceInterface("bottom", "bottom") def assemble(self): - bodylength = self.getParameter("bodylength") - wingspan = self.getParameter("wingspan") - wingtip = self.getParameter("wingtip") - thickness = self.getParameter("thickness") - flip = self.getParameter("flip") + bodylength = self.p.bodylength + wingspan = self.p.wingspan + wingtip = self.p.wingtip + thickness = self.p.thickness + flip = self.p.flip if flip: bodylength, wingtip = wingtip, bodylength diff --git a/rocolib/library/__init__.py b/rocolib/library/__init__.py index c52a250b91658d444773f673cffc862a09dfcd17..309c68313d001fa8619d78b8339232902b93ae36 100644 --- a/rocolib/library/__init__.py +++ b/rocolib/library/__init__.py @@ -7,7 +7,7 @@ import logging from rocolib import rocopath from rocolib.utils.io import load_yaml -from rocolib.api.components import Component +from rocolib.api.components import newComponent log = logging.getLogger(__name__) @@ -45,17 +45,17 @@ def getComponent(c, **kwargs): # Instantiate the class (pass arguments to the constructor, if needed) my_obj = obj() elif c in yamlComponents: - my_obj = Component(f"{ROCOLIB_LIBRARY}/{c}.yaml") + my_obj = newComponent(c, f"{ROCOLIB_LIBRARY}/{c}.yaml") else: raise ValueError(f"Component {c} not found in library") for k, v in kwargs.items(): if k == 'name': - my_obj.setName(v) + my_obj.name = v else: my_obj.setParameter(k, v) if 'name' not in kwargs: - my_obj.setName(c) + my_obj.name = c return my_obj