<commit_before>import org.opensim.modeling
import sys

class modelBuilder():
	"""Class to contain model building utilities."""
	@staticmethod
	# jointType is one of: 
	# 'PinJoint', 'FreeJoint', 'WeldJoint', 'PlanarJoint', 'SliderJoint', 'UniversalJoint'
	def connectBodyWithJoint(model, bodyName, jointName, jointType):
		c = model.getComponent(bodyName)
		c = modeling.PhysicalFrame.safeDownCast(c)
		p = model.getGround()
		module = sys.modules['org.opensim.modeling']
		JointClass = getattr(module, jointType)
		# Instantiate the class (pass arguments to the constructor, if needed)
		joint = JointClass(jointName, p, c)
		model.addJoint(joint)
		return model

	@staticmethod
	def addBody(model, name):
		body = modeling.Body(name, 1.0, modeling.Vec3(1.0), modeling.Inertia(1, 1, 1, 0, 0, 0))
		model.addBody(body)
		return body

	@staticmethod
	def attachGeometryWithOffset(frame, geometry):
		offset = modeling.PhysicalOffsetFrame()
		offset.setName(frame.getName()+ '_offset')
		offset.set_translation(modeling.Vec3(0.))
		offset.set_orientation(modeling.Vec3(0.))
		frame.addComponent(offset);
		bf = modeling.PhysicalFrame.safeDownCast(frame)
		offset.connectSocket_parent(bf)
		offset.attachGeometry(geometry)
		return frame
#
# example usage
# modelCopy = m.clone()
# newBody = modelBuilder.addBody(modelCopy, 'bucket')
# block = modeling.Brick(modeling.Vec3(0.1, 0.2, 0.3))
# modelBuilder.attachGeometryWithOffset(newBody, block)
# modelCopy = modelBuilder.connectBodyWithJoint(modelCopy, 'bucket', 'handle', 'PinJoint')
# loadModel(modelCopy)
<commit_msg>Add comments<commit_after>import org.opensim.modeling
import sys

class modelBuilder():
	"""Class to contain model building utilities."""
	@staticmethod
	# Connect a Body in passed in model to Ground with a Joint 
	# Arguments:
	# model: model to be modified
	# bodyName: name of the Body to be connected, any PhysicalFrame already in model should work
	# jointName: name to be given to newly created Joint
	# jointType is one of: 
	# 'PinJoint', 'FreeJoint', 'WeldJoint', 'PlanarJoint', 'SliderJoint', 'UniversalJoint'
	def connectBodyWithJoint(model, bodyName, jointName, jointType):
		c = model.getComponent(bodyName)
		c = modeling.PhysicalFrame.safeDownCast(c)
		p = model.getGround()
		module = sys.modules['org.opensim.modeling']
		JointClass = getattr(module, jointType)
		# Instantiate the class (pass arguments to the constructor, if needed)
		joint = JointClass(jointName, p, c)
		model.addJoint(joint)
		return model

	@staticmethod
	# create a Body with passed in name and add it to passed in model
	# created Body has mass of 1 and inertia (1,1,1,0,0,0)
	#
	def addBody(model, bodyName):
		body = modeling.Body(bodyName, 1.0, modeling.Vec3(1.0), modeling.Inertia(1, 1, 1, 0, 0, 0))
		model.addBody(body)
		return body

	@staticmethod
	# Attach geometry to passed in frame using an offset frame to allow moving geometry around
	def attachGeometryWithOffset(frame, geometry):
		offset = modeling.PhysicalOffsetFrame()
		offset.setName(frame.getName()+ '_offset')
		offset.set_translation(modeling.Vec3(0.))
		offset.set_orientation(modeling.Vec3(0.))
		frame.addComponent(offset);
		bf = modeling.PhysicalFrame.safeDownCast(frame)
		offset.connectSocket_parent(bf)
		offset.attachGeometry(geometry)
		return frame

	@staticmethod
	# Add muscle to current model, muscle name and type are passed in
	# muscleType is one of 'Thelen2003Muscle', 
	def addMuscle(model, muscleName, muscleType):
		module = sys.modules['org.opensim.modeling']
		MuscleClass = getattr(module, muscleType)
		# Instantiate the class (pass arguments to the constructor, if needed)
		muscle = MuscleClass()
		muscle.setName(muscleName);
		muscle.addNewPathPoint("muscle-pt1", model.getGround(), Vec3(0,0,0));
		muscle.addNewPathPoint("muscle-pt2", model.getGround(), Vec3(0,1,0));
		model.addForce(muscle)
#
# example usage
# modelCopy = m.clone()
# newBody = modelBuilder.addBody(modelCopy, 'bucket')
# block = modeling.Brick(modeling.Vec3(0.1, 0.2, 0.3))
# modelBuilder.attachGeometryWithOffset(newBody, block)
# modelCopy = modelBuilder.connectBodyWithJoint(modelCopy, 'bucket', 'handle', 'PinJoint')
# loadModel(modelCopy)

{'fraction_non_alphanumeric': 0.11943513642891336, 'fraction_numerical': 0.015557683101962662, 'mean_word_length': 5.499222395023328, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2472865', 'n_tokens_mistral': 1464, 'n_tokens_neox': 1343, 'n_words': 346}