Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Add Motor Operator #348

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 19 additions & 24 deletions phobos/blender/operators/editing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1763,11 +1763,16 @@ class AddMotorOperator(Operator):
bl_idname = "phobos.add_motor"
bl_label = "Add Motor"
bl_options = {'UNDO'}
bl_description = "Add a motor to the selected joint.\n" \
"It is possible to add motors to multiple joints at the same time"
lastMotorDefault = None

template : EnumProperty(items=[(n,n,n) for n in resources.get_motor_defaults()], name='Template', description="The template to use for this motor")
motorType : EnumProperty(items=[(n,n,n) for n in representation.Motor.BUILD_TYPES], name="Motor type", description='The motor type')
controllerType: EnumProperty(items=[(n,n,n) for n in representation.Motor.TYPES], name="Controller type", description='The controller type')
template : EnumProperty(items=[(n,n,n) for n in resources.get_motor_defaults()], name='Template',
description="The template to use for this motor")
motorType : EnumProperty(items=[(n,n,n) for n in representation.Motor.BUILD_TYPES], name="Motor type",
description='The motor type')
controllerType: EnumProperty(items=[(n,n,n) for n in representation.Motor.TYPES], name="Controller type",
description='The controller type')
maxeffort : FloatProperty(
name="Max Effort (N or Nm)", default=0.0, description="Maximum effort of the joint"
)
Expand Down Expand Up @@ -1859,26 +1864,9 @@ def poll(cls, context):
Returns:

"""
active_obj = (
context.active_object
and context.active_object.phobostype == 'link'
and context.active_object.mode == 'OBJECT'
)

if not active_obj:
return False
# for obj in context.selected_objects:
# if obj.mode == 'OBJECT' and obj.phobostype == 'link':
# active_obj = obj
# context.view_layer.objects.active = obj
# break
# if not active_obj:
else:
active_obj = context.active_object

joint_obj = 'joint/type' in active_obj and active_obj['joint/type'] != 'fixed'

return joint_obj
objects = [o for o in context.selected_objects if o.phobostype == "link"
and "joint/type" in o and o["joint/type"] != "fixed"]
return len(objects) > 0

def execute(self, context):
"""
Expand All @@ -1889,7 +1877,8 @@ def execute(self, context):
Returns:

"""
objects = [o for o in context.selected_objects if o.phobostype == "link"]
objects = [o for o in context.selected_objects if o.phobostype == "link"
and "joint/type" in o and o["joint/type"] != "fixed"]
for obj in objects:
phobos2blender.createMotor(representation.Motor(
name=obj.name+"_motor",
Expand All @@ -1900,6 +1889,9 @@ def execute(self, context):
i=self.controli,
d=self.controld
), linkobj=obj)
n = len(objects)
s = "" if n == 1 else "s"
log(message=f"Added a motor to {n} joint{s}", level="INFO")
return {'FINISHED'}


Expand Down Expand Up @@ -2098,6 +2090,9 @@ class AddSensorOperator(Operator):
bl_idname = "phobos.add_sensor"
bl_label = "Add Sensor"
bl_options = {'REGISTER', 'UNDO'}
bl_description = "Add a sensor at the position of the selected object. \n" \
"It is possible to create a new link for the sensor on the fly. Otherwise, \n" \
"the next link in the hierarchy will be used to parent the sensor to"


def sensorlist(self, context):
Expand Down