Newer
Older
# Define Panel classes for updating
panels = (
PanelSnapUtilities,
)
def update_panel(self, context):
message = "Snap Utilities Line: Updating Panel locations has failed"
Germano Cavalcante
committed
addon_prefs = context.user_preferences.addons[__name__].preferences
try:
for panel in panels:
Germano Cavalcante
committed
if addon_prefs.category != panel.bl_category:
if "bl_rna" in panel.__dict__:
bpy.utils.unregister_class(panel)
Germano Cavalcante
committed
panel.bl_category = addon_prefs.category
bpy.utils.register_class(panel)
except Exception as e:
print("\n[{}]\n{}\n\nError:\n{}".format(__name__, message, e))
pass
class SnapAddonPreferences(AddonPreferences):
# this must match the addon name, use '__package__'
# when defining this in a submodule of a python package.
bl_idname = __name__
intersect = BoolProperty(
name="Intersect",
description="Intersects created line with the existing edges, "
"even if the lines do not intersect",
default=True
)
create_new_obj = BoolProperty(
name="Create a new object",
description="If have not a active object, or the active object "
"is not in edit mode, it creates a new object",
default=False
)
create_face = BoolProperty(
name="Create faces",
description="Create faces defined by enclosed edges",
default=False
)
outer_verts = BoolProperty(
name="Snap to outer vertices",
description="The vertices of the objects are not activated also snapped",
default=True
)
expand_snap_settings = BoolProperty(
name="Expand",
description="Expand, to display the settings",
default=False
)
expand_color_settings = BoolProperty(
Germano Cavalcante
committed
name="Color Settings",
description="Expand, to display the color settings",
default=False
)
increments_grid = BoolProperty(
name="Increments of Grid",
description="Snap to increments of grid",
default=False
)
category = StringProperty(
name="Category",
description="Choose a name for the category of the panel",
update=update_panel
)
incremental = FloatProperty(
name="Incremental",
description="Snap in defined increments",
default=0,
min=0,
step=1,
precision=3
)
relative_scale = FloatProperty(
name="Relative Scale",
description="Value that divides the global scale",
default=1,
min=0,
step=1,
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
precision=3
)
out_color = FloatVectorProperty(
name="OUT",
default=(0.0, 0.0, 0.0, 0.5),
size=4,
subtype="COLOR",
min=0, max=1
)
face_color = FloatVectorProperty(
name="FACE",
default=(1.0, 0.8, 0.0, 1.0),
size=4,
subtype="COLOR",
min=0, max=1
)
edge_color = FloatVectorProperty(
name="EDGE",
default=(0.0, 0.8, 1.0, 1.0),
size=4,
subtype="COLOR",
min=0, max=1
)
vert_color = FloatVectorProperty(
name="VERT",
default=(1.0, 0.5, 0.0, 1.0),
size=4,
subtype="COLOR",
min=0, max=1
)
center_color = FloatVectorProperty(
name="CENTER",
default=(1.0, 0.0, 1.0, 1.0),
size=4,
subtype="COLOR",
min=0, max=1
)
perpendicular_color = FloatVectorProperty(
name="PERPENDICULAR",
default=(0.1, 0.5, 0.5, 1.0),
size=4,
subtype="COLOR",
min=0, max=1
)
constrain_shift_color = FloatVectorProperty(
name="SHIFT CONSTRAIN",
default=(0.8, 0.5, 0.4, 1.0),
size=4,
subtype="COLOR",
min=0, max=1
)
def draw(self, context):
layout = self.layout
Germano Cavalcante
committed
icon = "TRIA_DOWN" if self.expand_color_settings else "TRIA_RIGHT"
box = layout.box()
Germano Cavalcante
committed
box.prop(self, "expand_color_settings", icon=icon, toggle=True, emboss=False)
if self.expand_color_settings:
split = box.split()
col = split.column()
col.prop(self, "out_color")
col.prop(self, "constrain_shift_color")
col = split.column()
col.prop(self, "face_color")
col.prop(self, "center_color")
col = split.column()
col.prop(self, "edge_color")
col.prop(self, "perpendicular_color")
col = split.column()
col.prop(self, "vert_color")
row = layout.row()
col = row.column(align=True)
box = col.box()
box.label(text="Snap Items:")
box.prop(self, "incremental")
Germano Cavalcante
committed
box.prop(self, "outer_verts")
box.prop(self, "increments_grid")
if self.increments_grid:
box.prop(self, "relative_scale")
else:
box.separator()
box.separator()
col = row.column(align=True)
box = col.box()
box.label(text="Line Tool:")
Germano Cavalcante
committed
box.prop(self, "intersect")
box.prop(self, "create_face")
box.prop(self, "create_new_obj")
box.separator()
box.separator()
row = layout.row()
col = row.column()
col.label(text="Tab Category:")
col.prop(self, "category", text="")
def register():
bpy.utils.register_class(SnapAddonPreferences)
bpy.utils.register_class(SnapUtilitiesLine)
bpy.utils.register_class(PanelSnapUtilities)
def unregister():
bpy.utils.unregister_class(PanelSnapUtilities)
bpy.utils.unregister_class(SnapUtilitiesLine)
bpy.utils.unregister_class(SnapAddonPreferences)
if __name__ == "__main__":
__name__ = "mesh_snap_utilities_line"
register()