feat: select object after creation of floor, rail and component
This commit is contained in:
parent
da71d5560c
commit
997839a187
@ -14,18 +14,18 @@ class BBP_PG_bme_adder_cfgs(bpy.types.PropertyGroup):
|
|||||||
soft_min = 0, soft_max = 32,
|
soft_min = 0, soft_max = 32,
|
||||||
step = 1,
|
step = 1,
|
||||||
default = 1,
|
default = 1,
|
||||||
)
|
) # type: ignore
|
||||||
prop_float: bpy.props.FloatProperty(
|
prop_float: bpy.props.FloatProperty(
|
||||||
name = 'Single Float', description = 'Single Float',
|
name = 'Single Float', description = 'Single Float',
|
||||||
min = 0.0, max = 1024.0,
|
min = 0.0, max = 1024.0,
|
||||||
soft_min = 0.0, soft_max = 512.0,
|
soft_min = 0.0, soft_max = 512.0,
|
||||||
step = 50, # Step is in UI, in [1, 100] (WARNING: actual value is /100). So we choose 50, mean 0.5
|
step = 50, # Step is in UI, in [1, 100] (WARNING: actual value is /100). So we choose 50, mean 0.5
|
||||||
default = 5.0,
|
default = 5.0,
|
||||||
)
|
) # type: ignore
|
||||||
prop_bool: bpy.props.BoolProperty(
|
prop_bool: bpy.props.BoolProperty(
|
||||||
name = 'Single Bool', description = 'Single Bool',
|
name = 'Single Bool', description = 'Single Bool',
|
||||||
default = True
|
default = True
|
||||||
)
|
) # type: ignore
|
||||||
|
|
||||||
class BBP_OT_add_bme_struct(bpy.types.Operator):
|
class BBP_OT_add_bme_struct(bpy.types.Operator):
|
||||||
"""Add BME Struct"""
|
"""Add BME Struct"""
|
||||||
@ -55,7 +55,7 @@ class BBP_OT_add_bme_struct(bpy.types.Operator):
|
|||||||
description = "Internal flag.",
|
description = "Internal flag.",
|
||||||
options = {'HIDDEN', 'SKIP_SAVE'},
|
options = {'HIDDEN', 'SKIP_SAVE'},
|
||||||
default = False
|
default = False
|
||||||
)
|
) # type: ignore
|
||||||
|
|
||||||
## A BME struct cfgs descriptor cache list
|
## A BME struct cfgs descriptor cache list
|
||||||
# Not only the descriptor self, also the cfg associated index in bme_struct_cfgs
|
# Not only the descriptor self, also the cfg associated index in bme_struct_cfgs
|
||||||
@ -133,13 +133,13 @@ class BBP_OT_add_bme_struct(bpy.types.Operator):
|
|||||||
description = "BME struct type",
|
description = "BME struct type",
|
||||||
items = _g_EnumHelper_BmeStructType.generate_items(),
|
items = _g_EnumHelper_BmeStructType.generate_items(),
|
||||||
update = bme_struct_type_updated
|
update = bme_struct_type_updated
|
||||||
)
|
) # type: ignore
|
||||||
|
|
||||||
bme_struct_cfgs : bpy.props.CollectionProperty(
|
bme_struct_cfgs : bpy.props.CollectionProperty(
|
||||||
name = "Cfgs",
|
name = "Cfgs",
|
||||||
description = "Cfg collection.",
|
description = "Cfg collection.",
|
||||||
type = BBP_PG_bme_adder_cfgs,
|
type = BBP_PG_bme_adder_cfgs,
|
||||||
)
|
) # type: ignore
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def poll(self, context):
|
def poll(self, context):
|
||||||
@ -180,6 +180,8 @@ class BBP_OT_add_bme_struct(bpy.types.Operator):
|
|||||||
|
|
||||||
# move to cursor
|
# move to cursor
|
||||||
UTIL_functions.add_into_scene_and_move_to_cursor(obj)
|
UTIL_functions.add_into_scene_and_move_to_cursor(obj)
|
||||||
|
# select created object
|
||||||
|
UTIL_functions.select_certain_objects((obj, ))
|
||||||
return {'FINISHED'}
|
return {'FINISHED'}
|
||||||
|
|
||||||
def draw(self, context):
|
def draw(self, context):
|
||||||
|
@ -12,7 +12,7 @@ class ComponentSectorParam():
|
|||||||
min = 1, max = 999,
|
min = 1, max = 999,
|
||||||
soft_min = 1, soft_max = 8,
|
soft_min = 1, soft_max = 8,
|
||||||
default = 1,
|
default = 1,
|
||||||
)
|
) # type: ignore
|
||||||
|
|
||||||
def general_get_component_sector(self) -> int:
|
def general_get_component_sector(self) -> int:
|
||||||
return self.component_sector
|
return self.component_sector
|
||||||
@ -27,7 +27,7 @@ class ComponentCountParam():
|
|||||||
min = 1, max = 64,
|
min = 1, max = 64,
|
||||||
soft_min = 1, soft_max = 32,
|
soft_min = 1, soft_max = 32,
|
||||||
default = 1,
|
default = 1,
|
||||||
)
|
) # type: ignore
|
||||||
|
|
||||||
def general_get_component_count(self) -> int:
|
def general_get_component_count(self) -> int:
|
||||||
return self.component_count
|
return self.component_count
|
||||||
@ -94,38 +94,61 @@ def _check_component_existance(comp_type: PROP_ballance_element.BallanceElementT
|
|||||||
if expect_name in bpy.data.objects: return expect_name
|
if expect_name in bpy.data.objects: return expect_name
|
||||||
else: return None
|
else: return None
|
||||||
|
|
||||||
def _general_create_component(
|
class _GeneralComponentCreator():
|
||||||
comp_type: PROP_ballance_element.BallanceElementType,
|
"""
|
||||||
comp_sector: int,
|
The assist class for general component creation function.
|
||||||
comp_count: int,
|
Because we need select all created component, thus we need collect all created object into a list.
|
||||||
comp_offset: typing.Callable[[int], mathutils.Matrix]
|
This is the reason why we create this class.
|
||||||
) -> None:
|
|
||||||
"""
|
"""
|
||||||
General component creation function.
|
|
||||||
|
|
||||||
@param comp_type[in] The component type created.
|
## The list storing all created component within this creation.
|
||||||
@param comp_sector[in] The sector param which passed to other functions. For non-sector component, pass any number.
|
__mObjList: list[bpy.types.Object]
|
||||||
@param comp_count[in] The count of created component. For single component creation, please pass 1.
|
|
||||||
@param comp_offset[in] The function pointer which receive 1 argument indicating the index of object which we want to get its offset.
|
def __init__(self):
|
||||||
You can pass `lambda _: mathutils.Matrix.Identity(4)` to get zero offset for every items.
|
self.__mObjList = []
|
||||||
You can pass `lambda _: mathutils.Matrix( xxx )` to get same offset for every items.
|
|
||||||
You can pass `lambda i: mathutils.Matrix( func(i) )` to get index based offset for each items.
|
def create_component(self,
|
||||||
The offset is the offset to the origin point, not the previous object.
|
comp_type: PROP_ballance_element.BallanceElementType,
|
||||||
"""
|
comp_sector: int,
|
||||||
# get element info first
|
comp_count: int,
|
||||||
ele_info: UTIL_naming_convension.BallanceObjectInfo = _get_component_info(comp_type, comp_sector)
|
comp_offset: typing.Callable[[int], mathutils.Matrix]
|
||||||
# create blc element context
|
) -> None:
|
||||||
with PROP_ballance_element.BallanceElementsHelper(bpy.context.scene) as creator:
|
"""
|
||||||
# object creation counter
|
General component creation function.
|
||||||
for i in range(comp_count):
|
|
||||||
# get mesh from element context, and create with empty name first. we assign name later.
|
@param comp_type[in] The component type created.
|
||||||
obj: bpy.types.Object = bpy.data.objects.new('', creator.get_element(comp_type))
|
@param comp_sector[in] The sector param which passed to other functions. For non-sector component, pass any number.
|
||||||
# assign virtools group, object name by we gotten element info.
|
@param comp_count[in] The count of created component. For single component creation, please pass 1.
|
||||||
_set_component_by_info(obj, ele_info)
|
@param comp_offset[in] The function pointer which receive 1 argument indicating the index of object which we want to get its offset.
|
||||||
# add into scene and move to cursor
|
You can pass `lambda _: mathutils.Matrix.Identity(4)` to get zero offset for every items.
|
||||||
UTIL_functions.add_into_scene_and_move_to_cursor(obj)
|
You can pass `lambda _: mathutils.Matrix( xxx )` to get same offset for every items.
|
||||||
# move with extra offset by calling offset getter
|
You can pass `lambda i: mathutils.Matrix( func(i) )` to get index based offset for each items.
|
||||||
obj.matrix_world = obj.matrix_world @ comp_offset(i)
|
The offset is the offset to the origin point, not the previous object.
|
||||||
|
@return The created component instance.
|
||||||
|
"""
|
||||||
|
# get element info first
|
||||||
|
ele_info: UTIL_naming_convension.BallanceObjectInfo = _get_component_info(comp_type, comp_sector)
|
||||||
|
# create blc element context
|
||||||
|
with PROP_ballance_element.BallanceElementsHelper(bpy.context.scene) as creator:
|
||||||
|
# object creation counter
|
||||||
|
for i in range(comp_count):
|
||||||
|
# get mesh from element context, and create with empty name first. we assign name later.
|
||||||
|
obj: bpy.types.Object = bpy.data.objects.new('', creator.get_element(comp_type))
|
||||||
|
# assign virtools group, object name by we gotten element info.
|
||||||
|
_set_component_by_info(obj, ele_info)
|
||||||
|
# add into scene and move to cursor
|
||||||
|
UTIL_functions.add_into_scene_and_move_to_cursor(obj)
|
||||||
|
# move with extra offset by calling offset getter
|
||||||
|
obj.matrix_world = obj.matrix_world @ comp_offset(i)
|
||||||
|
# put into created object list
|
||||||
|
self.__mObjList.append(obj)
|
||||||
|
|
||||||
|
def finish_component(self) -> None:
|
||||||
|
"""
|
||||||
|
Finish up component creation.
|
||||||
|
Just deselect all objects and select all created components.
|
||||||
|
"""
|
||||||
|
UTIL_functions.select_certain_objects(tuple(self.__mObjList))
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -156,7 +179,7 @@ class BBP_OT_add_component(bpy.types.Operator, ComponentSectorParam):
|
|||||||
name = "Type",
|
name = "Type",
|
||||||
description = "This component type",
|
description = "This component type",
|
||||||
items = _g_EnumHelper_Component.generate_items(),
|
items = _g_EnumHelper_Component.generate_items(),
|
||||||
)
|
) # type: ignore
|
||||||
|
|
||||||
def invoke(self, context, event):
|
def invoke(self, context, event):
|
||||||
wm = context.window_manager
|
wm = context.window_manager
|
||||||
@ -179,12 +202,14 @@ class BBP_OT_add_component(bpy.types.Operator, ComponentSectorParam):
|
|||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
# call general creator
|
# call general creator
|
||||||
_general_create_component(
|
creator: _GeneralComponentCreator = _GeneralComponentCreator()
|
||||||
|
creator.create_component(
|
||||||
_g_EnumHelper_Component.get_selection(self.component_type),
|
_g_EnumHelper_Component.get_selection(self.component_type),
|
||||||
self.general_get_component_sector(),
|
self.general_get_component_sector(),
|
||||||
1, # only create one
|
1, # only create one
|
||||||
lambda _: mathutils.Matrix.Identity(4)
|
lambda _: mathutils.Matrix.Identity(4)
|
||||||
)
|
)
|
||||||
|
creator.finish_component()
|
||||||
return {'FINISHED'}
|
return {'FINISHED'}
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@ -218,12 +243,14 @@ class BBP_OT_add_nong_extra_point(bpy.types.Operator, ComponentSectorParam, Comp
|
|||||||
# calc percent first
|
# calc percent first
|
||||||
percent: float = 1.0 / self.general_get_component_count()
|
percent: float = 1.0 / self.general_get_component_count()
|
||||||
# create elements
|
# create elements
|
||||||
_general_create_component(
|
creator: _GeneralComponentCreator = _GeneralComponentCreator()
|
||||||
|
creator.create_component(
|
||||||
PROP_ballance_element.BallanceElementType.P_Extra_Point,
|
PROP_ballance_element.BallanceElementType.P_Extra_Point,
|
||||||
self.general_get_component_sector(),
|
self.general_get_component_sector(),
|
||||||
self.general_get_component_count(),
|
self.general_get_component_count(),
|
||||||
lambda i: mathutils.Matrix.Rotation(percent * i * math.pi * 2, 4, 'Z')
|
lambda i: mathutils.Matrix.Rotation(percent * i * math.pi * 2, 4, 'Z')
|
||||||
)
|
)
|
||||||
|
creator.finish_component()
|
||||||
return {'FINISHED'}
|
return {'FINISHED'}
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@ -243,22 +270,22 @@ class BBP_OT_add_nong_ventilator(bpy.types.Operator, ComponentSectorParam, Compo
|
|||||||
|
|
||||||
ventilator_count_source: bpy.props.EnumProperty(
|
ventilator_count_source: bpy.props.EnumProperty(
|
||||||
name = "Ventilator Count Source",
|
name = "Ventilator Count Source",
|
||||||
items = (
|
items = [
|
||||||
('DEFINED', "Predefined", "Pre-defined ventilator count."),
|
('DEFINED', "Predefined", "Pre-defined ventilator count."),
|
||||||
('CUSTOM', "Custom", "User specified ventilator count."),
|
('CUSTOM', "Custom", "User specified ventilator count."),
|
||||||
),
|
],
|
||||||
)
|
) # type: ignore
|
||||||
|
|
||||||
preset_vetilator_count: bpy.props.EnumProperty(
|
preset_vetilator_count: bpy.props.EnumProperty(
|
||||||
name = "Preset Count",
|
name = "Preset Count",
|
||||||
description = "Pick preset ventilator count.",
|
description = "Pick preset ventilator count.",
|
||||||
items = (
|
items = [
|
||||||
# (token, display name, descriptions, icon, index)
|
# (token, display name, descriptions, icon, index)
|
||||||
('PAPER', 'Paper', 'The ventilator count (1) can push paper ball up.'),
|
('PAPER', 'Paper', 'The ventilator count (1) can push paper ball up.'),
|
||||||
('WOOD', 'Wood', 'The ventilator count (6) can push wood ball up.'),
|
('WOOD', 'Wood', 'The ventilator count (6) can push wood ball up.'),
|
||||||
('STONE', 'Stone', 'The ventilator count (32) can push stone ball up.'),
|
('STONE', 'Stone', 'The ventilator count (32) can push stone ball up.'),
|
||||||
),
|
],
|
||||||
)
|
) # type: ignore
|
||||||
|
|
||||||
def draw(self, context):
|
def draw(self, context):
|
||||||
layout = self.layout
|
layout = self.layout
|
||||||
@ -286,12 +313,14 @@ class BBP_OT_add_nong_ventilator(bpy.types.Operator, ComponentSectorParam, Compo
|
|||||||
case _: raise UTIL_functions.BBPException('invalid enumprop data')
|
case _: raise UTIL_functions.BBPException('invalid enumprop data')
|
||||||
|
|
||||||
# create elements without any move
|
# create elements without any move
|
||||||
_general_create_component(
|
creator: _GeneralComponentCreator = _GeneralComponentCreator()
|
||||||
|
creator.create_component(
|
||||||
PROP_ballance_element.BallanceElementType.P_Modul_18,
|
PROP_ballance_element.BallanceElementType.P_Modul_18,
|
||||||
self.general_get_component_sector(),
|
self.general_get_component_sector(),
|
||||||
count,
|
count,
|
||||||
lambda _: mathutils.Matrix.Identity(4)
|
lambda _: mathutils.Matrix.Identity(4)
|
||||||
)
|
)
|
||||||
|
creator.finish_component()
|
||||||
return {'FINISHED'}
|
return {'FINISHED'}
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@ -319,7 +348,7 @@ class BBP_OT_add_tilting_block_series(bpy.types.Operator, ComponentSectorParam,
|
|||||||
min = 0.0, max = 100.0,
|
min = 0.0, max = 100.0,
|
||||||
soft_min = 0.0, soft_max = 12.0,
|
soft_min = 0.0, soft_max = 12.0,
|
||||||
default = 6.0022,
|
default = 6.0022,
|
||||||
)
|
) # type: ignore
|
||||||
|
|
||||||
def draw(self, context):
|
def draw(self, context):
|
||||||
layout = self.layout
|
layout = self.layout
|
||||||
@ -332,13 +361,14 @@ class BBP_OT_add_tilting_block_series(bpy.types.Operator, ComponentSectorParam,
|
|||||||
# get span first
|
# get span first
|
||||||
span: float = self.component_span
|
span: float = self.component_span
|
||||||
# create elements
|
# create elements
|
||||||
_general_create_component(
|
creator: _GeneralComponentCreator = _GeneralComponentCreator()
|
||||||
|
creator.create_component(
|
||||||
PROP_ballance_element.BallanceElementType.P_Modul_41,
|
PROP_ballance_element.BallanceElementType.P_Modul_41,
|
||||||
self.general_get_component_sector(),
|
self.general_get_component_sector(),
|
||||||
self.general_get_component_count(),
|
self.general_get_component_count(),
|
||||||
lambda i: mathutils.Matrix.Translation(mathutils.Vector((span * i, 0.0, 0.0))) # move with extra delta in x axis
|
lambda i: mathutils.Matrix.Translation(mathutils.Vector((span * i, 0.0, 0.0))) # move with extra delta in x axis
|
||||||
)
|
)
|
||||||
|
creator.finish_component()
|
||||||
return {'FINISHED'}
|
return {'FINISHED'}
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@ -363,7 +393,7 @@ class BBP_OT_add_ventilator_series(bpy.types.Operator, ComponentSectorParam, Com
|
|||||||
min = 0.0, max = 100.0,
|
min = 0.0, max = 100.0,
|
||||||
soft_min = 0.0, soft_max = 50.0,
|
soft_min = 0.0, soft_max = 50.0,
|
||||||
default = (0.0, 0.0, 15.0),
|
default = (0.0, 0.0, 15.0),
|
||||||
)
|
) # type: ignore
|
||||||
|
|
||||||
def draw(self, context):
|
def draw(self, context):
|
||||||
layout = self.layout
|
layout = self.layout
|
||||||
@ -376,13 +406,14 @@ class BBP_OT_add_ventilator_series(bpy.types.Operator, ComponentSectorParam, Com
|
|||||||
# get translation first
|
# get translation first
|
||||||
translation: mathutils.Vector = mathutils.Vector(self.component_translation)
|
translation: mathutils.Vector = mathutils.Vector(self.component_translation)
|
||||||
# create elements
|
# create elements
|
||||||
_general_create_component(
|
creator: _GeneralComponentCreator = _GeneralComponentCreator()
|
||||||
|
creator.create_component(
|
||||||
PROP_ballance_element.BallanceElementType.P_Modul_18,
|
PROP_ballance_element.BallanceElementType.P_Modul_18,
|
||||||
self.general_get_component_sector(),
|
self.general_get_component_sector(),
|
||||||
self.general_get_component_count(),
|
self.general_get_component_count(),
|
||||||
lambda i: mathutils.Matrix.Translation(i * translation) # move with extra translation
|
lambda i: mathutils.Matrix.Translation(i * translation) # move with extra translation
|
||||||
)
|
)
|
||||||
|
creator.finish_component()
|
||||||
return {'FINISHED'}
|
return {'FINISHED'}
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@ -450,20 +481,21 @@ class BBP_OT_add_sector_component_pair(bpy.types.Operator, ComponentSectorParam)
|
|||||||
|
|
||||||
# add elements
|
# add elements
|
||||||
# create checkpoint
|
# create checkpoint
|
||||||
_general_create_component(
|
creator: _GeneralComponentCreator = _GeneralComponentCreator()
|
||||||
|
creator.create_component(
|
||||||
checkp_ty,
|
checkp_ty,
|
||||||
checkp_sector,
|
checkp_sector,
|
||||||
1, # only create one
|
1, # only create one
|
||||||
lambda _: mathutils.Matrix.Identity(4)
|
lambda _: mathutils.Matrix.Identity(4)
|
||||||
)
|
)
|
||||||
# create resetpoint
|
# create resetpoint
|
||||||
_general_create_component(
|
creator.create_component(
|
||||||
resetp_ty,
|
resetp_ty,
|
||||||
resetp_sector,
|
resetp_sector,
|
||||||
1, # only create one
|
1, # only create one
|
||||||
lambda _: mathutils.Matrix.Translation(mathutils.Vector((0.0, 0.0, resetp_offset))) # apply resetpoint offset
|
lambda _: mathutils.Matrix.Translation(mathutils.Vector((0.0, 0.0, resetp_offset))) # apply resetpoint offset
|
||||||
)
|
)
|
||||||
|
creator.finish_component()
|
||||||
return {'FINISHED'}
|
return {'FINISHED'}
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -492,6 +492,8 @@ def _rail_creator_wrapper(fct_poly_cret: typing.Callable[[bmesh.types.BMesh], No
|
|||||||
|
|
||||||
# move to cursor
|
# move to cursor
|
||||||
UTIL_functions.add_into_scene_and_move_to_cursor(obj)
|
UTIL_functions.add_into_scene_and_move_to_cursor(obj)
|
||||||
|
# select created object
|
||||||
|
UTIL_functions.select_certain_objects((obj, ))
|
||||||
|
|
||||||
# return rail
|
# return rail
|
||||||
return obj
|
return obj
|
||||||
|
@ -68,6 +68,18 @@ def add_into_scene_and_move_to_cursor(obj: bpy.types.Object):
|
|||||||
|
|
||||||
move_to_cursor(obj)
|
move_to_cursor(obj)
|
||||||
|
|
||||||
|
def select_certain_objects(objs: tuple[bpy.types.Object, ...]) -> None:
|
||||||
|
# deselect all objects first
|
||||||
|
bpy.ops.object.select_all(action = 'DESELECT')
|
||||||
|
# if no objects, return
|
||||||
|
if len(objs) == 0: return
|
||||||
|
|
||||||
|
# set selection for each object
|
||||||
|
for obj in objs:
|
||||||
|
obj.select_set(True)
|
||||||
|
# select first object as active object
|
||||||
|
bpy.context.view_layer.objects.active = objs[0]
|
||||||
|
|
||||||
class EnumPropHelper():
|
class EnumPropHelper():
|
||||||
"""
|
"""
|
||||||
These class contain all functions related to EnumProperty, including generating `items`,
|
These class contain all functions related to EnumProperty, including generating `items`,
|
||||||
|
Loading…
Reference in New Issue
Block a user