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

Some small changes #371

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
47 changes: 28 additions & 19 deletions phobos/blender/operators/editing.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@
from idprop.types import IDPropertyGroup
from phobos.io import hyrodyn

from .. import defs as defs
from .. import defs as defs, phobosgui
from .. import display as display
from ..io import phobos2blender, blender2phobos
from ..model import controllers as controllermodel
from ..model import inertia as inertialib
from ..model import joints as jUtils
from ..model import links as modellinks
from ..phobosgui import prev_collections
from ..phoboslog import log, ErrorMessageWithBox, WarnMessageWithBox
from ..phoboslog import log, ErrorMessageWithBox, WarnMessageWithBox, InfoMessageWithBox
from ..operators.generic import addObjectFromYaml, DynamicProperty, AddAnnotationsOperator, \
EditAnnotationsOperator, AnnotationsOperator
from ..utils import blender as bUtils
Expand Down Expand Up @@ -514,6 +514,7 @@ def execute(self, context):

for obj in context.selected_objects:
obj.phobostype = self.phobostype
phobosgui.updateSidebar()
return {'FINISHED'}

@classmethod
Expand Down Expand Up @@ -810,6 +811,7 @@ def execute(self, context):
'INFO',
)
log(" Objects: " + str([obj.name for obj in objs]), 'DEBUG')
phobosgui.updateSidebar()
return {'FINISHED'}

@classmethod
Expand Down Expand Up @@ -1982,12 +1984,10 @@ def execute(self, context):
del obj[mProp]
if not motorRemoved:
motorRemoved = True
removedMotors+=1
removedMotors += 1
if len(context.selected_objects) > 1 and removedMotors > 0:
pluralS = "s" if removedMotors > 1 else ""
WarnMessageWithBox(message=f"{removedMotors} motor{pluralS} removed from selected objects",
title="Phobos Message", icon="INFO")
print("Motor removed")
InfoMessageWithBox(message=f"{removedMotors} motor{pluralS} removed from selected objects", silentFor=0)
return {'FINISHED'}

@classmethod
Expand Down Expand Up @@ -3101,9 +3101,9 @@ def execute(self, context):
parameters = {
'type': '{0}R'.format(len(self.joints)),
#'jointnames': [j["joint/name"] for j in self.joints], #Is autogenerated
'jointnames_spanningtree': [j.get("joint/name",j.name) for j in self.joints],
'jointnames_active': [j.get("joint/name",j.name) for j in self.joints],
'jointnames_independent': [j.get("joint/name",j.name) for j in self.joints],
'jointnames_spanningtree': [j.get("joint/name", j.name) for j in self.joints],
'jointnames_active': [j.get("joint/name", j.name) for j in self.joints],
'jointnames_independent': [j.get("joint/name", j.name) for j in self.joints],
'name': self.mechanism_name,
'contextual_name': self.contextual_name
}
Expand All @@ -3121,7 +3121,7 @@ def execute(self, context):
size = len(mechanismdata['joints']['spanningtree'])
if len(self.joints) == size:
jointmap = {
getattr(self, 'jointtype' + str(i)): self.joints[i].get("joint/name",self.joints[i].name)
getattr(self, 'jointtype' + str(i)): self.joints[i].get("joint/name", self.joints[i].name)
for i in range(len(self.joints))
}
for j in mechanismdata['joints']['spanningtree']:
Expand Down Expand Up @@ -3182,9 +3182,12 @@ def get_submechanism_roots_static(cls, context):
Returns:

"""
return bUtils.compileEnumPropertyList(
[r['name'] for r in context.scene.objects if r.phobostype == "submechanism"]
)
list = []
for r in context.scene.objects:
if r.phobostype == "submechanism":
el = (r['contextual_name'], r['contextual_name']+" - "+r['name'], "Type " + r['type'])
list.append(el)
return list

def get_submechanism_roots(self, context):
"""
Expand All @@ -3197,7 +3200,7 @@ def get_submechanism_roots(self, context):
"""
return SelectSubmechanism.get_submechanism_roots_static(context)

submechanism : EnumProperty(
submechanism: EnumProperty(
name="Submechanism",
description="submechanism which to select",
items=get_submechanism_roots,
Expand Down Expand Up @@ -3253,11 +3256,8 @@ def execute(self, context):

"""
root = sUtils.getObjectByProperty('contextual_name', self.submechanism)
jointIDs = root['jointnames_spanningtree']
jointlist = [
sUtils.getObjectByProperty('joint/name', id) for id in jointIDs
]
sUtils.selectObjects([root] + jointlist, clear=True, active=0)
joints = root['jointnames_spanningtree']
sUtils.selectObjects([root] + joints, clear=True, active=0)
return {'FINISHED'}


Expand Down Expand Up @@ -3539,8 +3539,17 @@ def execute(self, context):
children = context.selected_objects
for child in children:
if child != parent:
if sUtils.getEffectiveParent(parent) == child:
root = sUtils.getEffectiveParent(child)
sUtils.selectObjects([parent], active=0, clear=True)
bpy.ops.object.parent_clear(type='CLEAR_KEEP_TRANSFORM')
if root is not None:
eUtils.parentObjectsTo(parent, root)

eUtils.parentObjectsTo(child, parent)

sUtils.selectObjects(children, active=children.index(parent) or 0, clear=True)

return {'FINISHED'}

@classmethod
Expand Down
2 changes: 1 addition & 1 deletion phobos/blender/operators/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,6 @@ def draw(self, layout, properties=[]):
else:
row = layout

self.deleteOption = True
if self.deleteOption:
line = layout.split(factor=0.9)
row = line.row()
Expand Down Expand Up @@ -771,6 +770,7 @@ def addProperty(self, c1):
if newName and self.getPropertyByName(newName, self.add_property_root) is None:
new_prop = self.custom_properties.add()
new_prop.valueType = ID
new_prop.deleteOption = True
if not self.rootType() == list:
new_prop.name = newName
# Assign dict
Expand Down
Loading