Location (hwx.inspire.Attributes)#

class Location(default=(0, 0, 0), **kwds)#

Bases: HasReferenceFrame, Triple

Store a location relative to another entity.

Locations are get or set in global coordinates.

Locations relative to Features have special code to stay at the same point on the feature after feature modifications like push/pull.

Attribute Table#

Name

Type

units

str

Method Table#

Name

Description

castForSet (self, obj, value)

getCoord (self, feature, point)

Converts the location on the feature into UV coordinates.

getCoordLocation (self, feature, coord, normalized=False)

Convert coordinates to location from the specified feature.

Example

from hwx.inspire import *

class PointOnFace(GeneralObject):
   feature  = Reference(Feature)
   location = Location(wrt=feature)

model = newModel()
cyl  = model.createSolidCylinder()
face = cyl.getFeatures(FeaturePlanar)[0]
obj = PointOnFace(feature=face, location=face.location)

# Locations wrt a feature move with the feature.part
start = obj.location
obj.feature.part.position *= math.Matrix44(origin=(1,1,1))
print('location moved from', start, 'to', obj.location)

# Locations wrt a feature stay attached during geometry changes
start = obj.location
face.pushPull(2)
assert obj.location.close(start + face.normal*2)
Value#

alias of Value

class Point(x=0, y=0, z=0)#

Bases: Point

Point in a reference frame

Method Table#

Name

Description

getCoord (self, normalized=True)

Get UV coordinate on wrt feature.

isTouchingFeature (self)

Is point touching its wrt feature?

swap (self, other)

Swap location and wrt entity with another location without the rounding

getCoord(normalized=True)#

Get UV coordinate on wrt feature. - None is returned if point is not touching feature

isTouchingFeature()#

Is point touching its wrt feature?

swap(other)#

Swap location and wrt entity with another location without the rounding error that is caused by converting the location to and from global coordinates.

Roughly equivalent to doing (without rounding error): self.entity1, self.entity2 = self.entity2, self.entity1 self.location1, self.location2 = self.location2, self.location1

castForSet(obj, value)#

Converts and validates the value of the attribute before setting.

Converts the value it to its internal type (and base units if applicable).

Parameters:
  • obj (GeneralObject) – Object this attribute belongs to.

  • value (Any) – Value of the attribute to set.

Returns:

Validated and converted value.

Return type:

value (Any)

class Listener(*typesOrObjects)#

Bases: ModelListener

Attribute Table#

Name

Type

coord

NoneType

Method Table#

Name

Description

activateModelListener (self, attr, obj)

onObjectModified (self, part, attr)

onValueChanged (self)

syncValueWithCoord (self, value)

activateModelListener(attr, obj)#
Activates or start listening to the data model and call the handlers,

when the specified types are created, destroyed or modified.

Parameters:

*typesOrObjects (Part, BC, Motor, ...) – Types or objects to listen to. Sub classes of Named (Features are not supported).

onObjectModified(part, attr)#

Implement if interested when an object’s attribute value changes.

Parameters:
  • obj (Named) – Object whose attribute got modified. Check if attr == ‘features’ to react to geometry changes.

  • attr (str) – Name of attribute like ‘mass’, ‘name’, …

class UV(iterable=(), /)#

Bases: tuple

Method Table#

Name

Description

resolve (self, normalize=False)

getCoord(feature, point)#

Converts the location on the feature into UV coordinates.

None is returned if point is not touching feature

Parameters:
  • feature (Feature) – Feature from which coordinates are extracted from.

  • point (Point) – Point on the feature for which UV coordinates are derived.

Returns:

Coordinates from the converted location.

Return type:

UV Coordinates

getCoordLocation(feature, coord, normalized=False)#

Convert coordinates to location from the specified feature.

Parameters:
  • feature (Feature) – Feature on which location is extracted.

  • coord (list[Point]) – Coordinates from which the location is derived.

  • normalized (bool) – If True normalize the locations, defaults to False.

Returns:

Converted UV coordinates to location value.

Return type:

Location