Exemplo n.º 1
0
    def execute(self, context):
        settings = get_settings()
        dbg = settings.debug
        odcutils.scene_verification(context.scene, debug=dbg)
        spaces = odcutils.implant_selection(context)
        layers_copy = [layer for layer in context.scene.layers]
        context.scene.layers[0] = True

        if context.mode != 'OBJECT':
            bpy.ops.object.mode_set(mode='OBJECT')

        for space in spaces:
            if not space.implant:
                self.report(
                    {'WARNING'},
                    "It seems you have not yet placed an implant for %s" %
                    space.name)

            else:
                if self.use_thickness:
                    thickness = self.thickness
                else:
                    thickness = None

                implant_utils.implant_inner_cylinder(context,
                                                     space,
                                                     thickness=thickness,
                                                     debug=dbg)

        odcutils.material_management(context, context.scene.odc_implants)
        odcutils.layer_management(context.scene.odc_implants, debug=dbg)
        for i, layer in enumerate(layers_copy):
            context.scene.layers[i] = layer
        context.scene.layers[9] = True
        return {'FINISHED'}
Exemplo n.º 2
0
 def execute(self,context):
     settings = get_settings()
     dbg  = settings.debug
     odcutils.scene_verification(context.scene, debug = dbg)
     spaces = odcutils.implant_selection(context)
     layers_copy = [layer for layer in context.scene.layers]
     context.scene.layers[0] = True
     
     if context.mode != 'OBJECT':
         bpy.ops.object.mode_set(mode='OBJECT')
         
     for space in spaces: 
         if not space.implant:
             self.report({'WARNING'}, "It seems you have not yet placed an implant for %s" % space.name)
     
         else:
             if self.use_thickness:
                 thickness = self.thickness
             else:
                 thickness = None
             
             implant_utils.implant_inner_cylinder(context, space, thickness = thickness, debug = dbg)
     
     
     odcutils.material_management(context, context.scene.odc_implants) 
     odcutils.layer_management(context.scene.odc_implants, debug = dbg)
     for i, layer in enumerate(layers_copy):
         context.scene.layers[i] = layer
     context.scene.layers[9] = True
     return {'FINISHED'}   
Exemplo n.º 3
0
 def execute(self, context):
     layers_copy = [layer for layer in context.scene.layers]
     context.scene.layers[0] = True
     
     tooth = odcutils.tooth_selection(context)[0]
     sce=bpy.context.scene
     a = tooth.name
     prep = tooth.prep_model
     margin = str(a + "_Margin")
     
     Prep = bpy.data.objects[prep]
     Prep.hide = False
     L = Prep.location
     #L = bpy.context.scene.cursor_location
     
     
     ###Keep a list of unhidden objects
     for o in sce.objects:
         if o.name != prep and not o.hide:
             o.hide = True
     
     master=sce.odc_props.master
     if master:
         Master = bpy.data.objects[master]
     else:
         self.report('WARNING', "No master model...there are risks!")
     
     bpy.ops.view3d.viewnumpad(type='TOP')
     bpy.ops.object.select_all(action='DESELECT')
     #bpy.context.scene.cursor_location = L
     bpy.ops.curve.primitive_bezier_curve_add(view_align=True, enter_editmode=True, location=L)
     bpy.context.tool_settings.use_snap = True
     bpy.context.tool_settings.snap_target= 'ACTIVE'
     bpy.context.tool_settings.snap_element = 'FACE'
     bpy.context.tool_settings.proportional_edit = 'DISABLED'
     o=bpy.context.object
     o.name=margin
     if master:
         o.parent=Master #maybe this should go in the "Accept Margin" function/step
     bpy.ops.curve.handle_type_set(type='AUTOMATIC')
     bpy.ops.curve.select_all(action='DESELECT')
     bpy.context.object.data.splines[0].bezier_points[1].select_control_point=True
     bpy.ops.curve.delete()
     bpy.ops.curve.select_all(action='SELECT')
     bpy.ops.object.modifier_add(type='SHRINKWRAP')
     mod = bpy.context.object.modifiers[0]
     
     #this could also be the active object...?
     #in a different behavior mode...
     mod.target=Prep
 
     tooth.margin = margin
     
     odcutils.layer_management(sce.odc_teeth)
     for i, layer in enumerate(layers_copy):
         context.scene.layers[i] = layer
     context.scene.layers[4] = True
     
     return {'FINISHED'}
Exemplo n.º 4
0
    def execute(self, context):
        
        sce=bpy.context.scene
        n = sce.odc_splint_index
        splint = sce.odc_splints[n]
        
        layers_copy = [layer for layer in context.scene.layers]
        context.scene.layers[0] = True
        
        model = splint.model
        Model = bpy.data.objects[model]

        L = odcutils.get_bbox_center(Model, world=True)
        #L = bpy.context.scene.cursor_location

        #bpy.ops.view3d.viewnumpad(type='TOP')
        bpy.ops.object.select_all(action='DESELECT')
        
        if context.mode != 'OBJECT':
            bpy.ops.object.mode_set(mode='OBJECT')
        
        #bpy.context.scene.cursor_location = L
        bpy.ops.curve.primitive_bezier_curve_add(view_align=True, enter_editmode=True, location=L)
        
        context.tool_settings.use_snap = True
        context.tool_settings.snap_target= 'ACTIVE'
        context.tool_settings.snap_element = 'FACE'
        context.tool_settings.proportional_edit = 'DISABLED'
        
        Margin =context.object
        Margin.name=splint.name + "_margin"
        Margin.parent = Model
        
        bpy.ops.object.mode_set(mode='EDIT')
        bpy.ops.curve.handle_type_set(type='AUTOMATIC')
        bpy.ops.curve.select_all(action='DESELECT')
        context.object.data.splines[0].bezier_points[1].select_control_point=True
        bpy.ops.curve.delete()
        bpy.ops.curve.select_all(action='SELECT')
        
        mod = Margin.modifiers.new('Wrap','SHRINKWRAP')
        mod.target = Model
        mod.offset = .75
        mod.use_keep_above_surface = True
        
        mod = Margin.modifiers.new('Smooth','SMOOTH')
        mod.iterations = 10
        
        splint.margin = Margin.name
        odcutils.layer_management(sce.odc_splints)
        
        for i, layer in enumerate(layers_copy):
            context.scene.layers[i] = layer
        context.scene.layers[4] = True
        return {'FINISHED'}
Exemplo n.º 5
0
 def execute(self,context):
     settings = get_settings()
     dbg = settings.debug
     #TODO: Scene Preservation recording
     teeth = odcutils.tooth_selection(context)
     sce = bpy.context.scene
     
     layers_copy = [layer for layer in context.scene.layers]
     context.scene.layers[0] 
     
     for tooth in teeth:
         
         #see if there is a corresponding implant
         if tooth.name in sce.odc_implants:
             contour = bpy.data.objects.get(tooth.contour)
             Z  = Vector((0,0,-1))
             if contour:
                 
                 if tooth.axis:
                     Axis = bpy.data.objects.get(tooth.axis)
                     if Axis:
                         neg_z = Axis.matrix_world.to_quaternion() * Z
                         rot_diff = odcutils.rot_between_vecs(Vector((0,0,1)), neg_z)
                     else:
                         neg_z = contour.matrix_world.to_quaternion() * Z
                         rot_diff = odcutils.rot_between_vecs(Vector((0,0,1)), neg_z)
                 else:
                     neg_z = contour.matrix_world.to_quaternion() * Z
                     rot_diff = odcutils.rot_between_vecs(Vector((0,0,1)), neg_z)
                 mx = contour.matrix_world
                 x = mx[0][3]
                 y = mx[1][3]
                 z = mx[2][3]
                 
                 #CEJ Location
                 new_loc = odcutils.box_feature_locations(contour, Vector((0,0,-1)))
                 
                 Imp = implant_utils.place_implant(context, sce.odc_implants[tooth.name], new_loc, rot_diff, self.imp, hardware = self.hardware)
                 
                 #reposition platform below CEJ
                 world_mx = Imp.matrix_world
                 delta =  Imp.dimensions[2] * world_mx.to_3x3() * Vector((0,0,1)) + self.depth * world_mx.to_3x3() * Vector((0,0,1))
                 
                 world_mx[0][3] += delta[0]
                 world_mx[1][3] += delta[1]
                 world_mx[2][3] += delta[2]
                 #odcutils.reorient_object(Imp, rot_diff)
     
     odcutils.layer_management(sce.odc_implants, debug = False)
     for i, layer in enumerate(layers_copy):
         context.scene.layers[i] = layer
     context.scene.layers[11] = True
     
     return {'FINISHED'}
Exemplo n.º 6
0
    def execute(self, context):
        
        sce=bpy.context.scene
        ob = context.object
        layers_copy = [layer for layer in context.scene.layers]
        context.scene.layers[0] = True
        
        if ob:

            L = odcutils.get_bbox_center(ob, world=True)
        
        elif sce.odc_props.master:
            ob = bpy.data.objects[sce.odc_props.master]
            L = odcutils.get_bbox_center(ob, world=True)
            
        else:
            L = bpy.context.scene.cursor_location

        bpy.ops.view3d.viewnumpad(type='TOP')
        bpy.ops.object.select_all(action='DESELECT')
        
        if context.mode != 'OBJECT':
            bpy.ops.object.mode_set(mode='OBJECT')
        
        #bpy.context.scene.cursor_location = L
        bpy.ops.curve.primitive_bezier_curve_add(view_align=True, enter_editmode=True, location=L)
        PlanCurve = context.object
        PlanCurve.layers[4] = True
        PlanCurve.layers[0] = True
        PlanCurve.layers[1] = True
        PlanCurve.layers[3] = True
        
        context.tool_settings.use_snap = True
        context.tool_settings.snap_target= 'ACTIVE'
        context.tool_settings.snap_element = 'FACE'
        context.tool_settings.proportional_edit = 'DISABLED'
        context.tool_settings.use_snap_project = False
        
        bpy.ops.object.mode_set(mode='EDIT')
        bpy.ops.curve.handle_type_set(type='AUTOMATIC')
        bpy.ops.curve.select_all(action='DESELECT')
        context.object.data.splines[0].bezier_points[1].select_control_point=True
        bpy.ops.curve.delete()
        bpy.ops.curve.select_all(action='SELECT')
            
        odcutils.layer_management(sce.odc_splints)
        for i, layer in enumerate(layers_copy):
            context.scene.layers[i] = layer
        context.scene.layers[3] = True
        return {'FINISHED'}
Exemplo n.º 7
0
 def execute(self,context):
     settings = get_settings()
     dbg = settings.debug
     
     layers_copy = [layer for layer in context.scene.layers]
     context.scene.layers[0] = True
      
     odc_bridge = bridge_methods.active_spanning_restoration(context)[0]
     bridge_methods.make_pre_bridge(context, odc_bridge, debug=dbg) #TODO: debug settings
     
     for i, layer in enumerate(layers_copy):
         context.scene.layers[i] = layer
         
     context.scene.layers[5] = True
     odcutils.layer_management(context.scene.odc_bridges, debug = dbg)
     
     return {'FINISHED'}
Exemplo n.º 8
0
    def execute(self, context):
        settings = get_settings()
        dbg = settings.debug
        #if bpy.context.mode != 'OBJECT':
        #    bpy.ops.object.mode_set(mode = 'OBJECT')

        sce = context.scene
        implants = odcutils.implant_selection(context)

        layers_copy = [layer for layer in context.scene.layers]
        context.scene.layers[0] = True

        if implants != []:

            for implant_space in implants:
                #check if space already has an implant object.
                #if so, delete, replace, print warning
                Implant = bpy.data.objects[implant_space.implant]

                if Implant.rotation_mode != 'QUATERNION':
                    Implant.rotation_mode = 'QUATERNION'
                    Implant.update_tag()
                    sce.update()

                if bpy.data.objects.get(implant_space.drill):
                    self.report(
                        {'WARNING'},
                        "replacing the existing drill with the one you chose")
                    Sleeve = bpy.data.objects[implant_space.drill]
                    #unlink it from the scene, clear it's users, remove it.
                    sce.objects.unlink(Sleeve)
                    Implant.user_clear()
                    #remove the object
                    bpy.data.objects.remove(Sleeve)

                current_obs = [ob.name for ob in bpy.data.objects]

                #link the new implant from the library
                settings = get_settings()
                odcutils.obj_from_lib(settings.drill_lib, self.drill)

                #this is slightly more robust than trusting we don't have duplicate names.
                for ob in bpy.data.objects:
                    if ob.name not in current_obs:
                        Sleeve = ob

                sce.objects.link(Sleeve)
                Sleeve.layers[19] = True
                mx_w = Implant.matrix_world.copy()
                #point the right direction
                Sleeve.rotation_mode = 'QUATERNION'
                Sleeve.rotation_quaternion = mx_w.to_quaternion()
                Sleeve.update_tag()
                context.scene.update()
                Trans = Sleeve.rotation_quaternion * Vector(
                    (0, 0, -self.depth))
                Sleeve.matrix_world[0][3] = mx_w[0][3] + Trans[0]
                Sleeve.matrix_world[1][3] = mx_w[1][3] + Trans[1]
                Sleeve.matrix_world[2][3] = mx_w[2][3] + Trans[2]

                Sleeve.name = implant_space.name + '_' + Sleeve.name
                implant_space.drill = Sleeve.name
                Sleeve.update_tag()
                context.scene.update()
                odcutils.parent_in_place(Sleeve, Implant)
                odcutils.layer_management(sce.odc_implants, debug=dbg)
        for i, layer in enumerate(layers_copy):
            context.scene.layers[i] = layer
        context.scene.layers[19] = True
        return {'FINISHED'}
Exemplo n.º 9
0
    def execute(self, context):
        settings = get_settings()
        dbg = settings.debug
        #if bpy.context.mode != 'OBJECT':
        #    bpy.ops.object.mode_set(mode = 'OBJECT')

        sce = context.scene
        n = sce.odc_implant_index
        implant_space = sce.odc_implants[n]

        implants = odcutils.implant_selection(context)
        layers_copy = [layer for layer in context.scene.layers]
        context.scene.layers[0]

        if implants != []:

            for implant_space in implants:
                #check if space already has an implant object.
                #if so, delete, replace, print warning
                if implant_space.implant and implant_space.implant in bpy.data.objects:
                    self.report({
                        'WARNING'
                    }, "replacing the existing implant with the one you chose")
                    Implant = bpy.data.objects[implant_space.implant]

                    #the origin/location of the implant is it's apex
                    L = Implant.location.copy()

                    world_mx = Implant.matrix_world.copy()

                    #the platorm is the length of the implant above the apex, in the local Z direction
                    #local Z positive is out the apex, soit's negative.
                    #Put the cursor there
                    sce.cursor_location = L - Implant.dimensions[
                        2] * world_mx.to_3x3() * Vector((0, 0, 1))

                    #first get rid of children...so we can use the
                    #parent to find out who the children are
                    if Implant.children:
                        for child in Implant.children:
                            sce.objects.unlink(child)
                            child.user_clear()
                            bpy.data.objects.remove(child)

                    #unlink it from the scene, clear it's users, remove it.
                    sce.objects.unlink(Implant)
                    Implant.user_clear()
                    #remove the object
                    bpy.data.objects.remove(Implant)

                #TDOD what about the children/hardwares?
                else:
                    world_mx = Matrix.Identity(4)

                world_mx[0][3] = sce.cursor_location[0]
                world_mx[1][3] = sce.cursor_location[1]
                world_mx[2][3] = sce.cursor_location[2]

                #is this more memory friendly than listing all objects?
                current_obs = [ob.name for ob in bpy.data.objects]

                #link the new implant from the library
                odcutils.obj_from_lib(settings.imp_lib, self.imp)

                #this is slightly more robust than trusting we don't have duplicate names.
                for ob in bpy.data.objects:
                    if ob.name not in current_obs:
                        Implant = ob

                sce.objects.link(Implant)

                #this relies on the associated hardware objects having the parent implant
                #name inside them
                if self.hardware:
                    current_obs = [ob.name for ob in bpy.data.objects]

                    inc = self.imp + '_'
                    hardware_list = odcutils.obj_list_from_lib(
                        settings.imp_lib, include=inc)
                    print(hardware_list)
                    for ob in hardware_list:
                        odcutils.obj_from_lib(settings.imp_lib, ob)

                    for ob in bpy.data.objects:
                        if ob.name not in current_obs:
                            sce.objects.link(ob)
                            ob.parent = Implant
                            ob.layers[11] = True

                delta = Implant.dimensions[2] * world_mx.to_3x3() * Vector(
                    (0, 0, 1))
                print(delta.length)
                world_mx[0][3] += delta[0]
                world_mx[1][3] += delta[1]
                world_mx[2][3] += delta[2]

                Implant.matrix_world = world_mx

                if sce.odc_props.master:
                    Master = bpy.data.objects[sce.odc_props.master]
                    odcutils.parent_in_place(Implant, Master)
                else:
                    self.report({
                        'WARNING'
                    }, 'No Master Model, placing implant anyway, moving objects may not preserve spatial relationships'
                                )

                #looks a little redundant, but it ensure if any
                #duplicates exist our referencing stays accurate
                Implant.name = implant_space.name + '_' + Implant.name
                implant_space.implant = Implant.name

                odcutils.layer_management(sce.odc_implants, debug=dbg)

        for i, layer in enumerate(layers_copy):
            context.scene.layers[i] = layer
        context.scene.layers[11] = True
        return {'FINISHED'}
Exemplo n.º 10
0
    def execute(self, context):
        settings = get_settings()
        dbg = settings.debug
        #TODO: Scene Preservation recording
        teeth = odcutils.tooth_selection(context)
        sce = bpy.context.scene

        layers_copy = [layer for layer in context.scene.layers]
        context.scene.layers[0]

        for tooth in teeth:

            #see if there is a corresponding implant
            if tooth.name in sce.odc_implants:
                contour = bpy.data.objects.get(tooth.contour)
                Z = Vector((0, 0, -1))
                if contour:

                    if tooth.axis:
                        Axis = bpy.data.objects.get(tooth.axis)
                        if Axis:
                            neg_z = Axis.matrix_world.to_quaternion() * Z
                            rot_diff = odcutils.rot_between_vecs(
                                Vector((0, 0, 1)), neg_z)
                        else:
                            neg_z = contour.matrix_world.to_quaternion() * Z
                            rot_diff = odcutils.rot_between_vecs(
                                Vector((0, 0, 1)), neg_z)
                    else:
                        neg_z = contour.matrix_world.to_quaternion() * Z
                        rot_diff = odcutils.rot_between_vecs(
                            Vector((0, 0, 1)), neg_z)
                    mx = contour.matrix_world
                    x = mx[0][3]
                    y = mx[1][3]
                    z = mx[2][3]

                    #CEJ Location
                    new_loc = odcutils.box_feature_locations(
                        contour, Vector((0, 0, -1)))

                    Imp = implant_utils.place_implant(
                        context,
                        sce.odc_implants[tooth.name],
                        new_loc,
                        rot_diff,
                        self.imp,
                        hardware=self.hardware)

                    #reposition platform below CEJ
                    world_mx = Imp.matrix_world
                    delta = Imp.dimensions[2] * world_mx.to_3x3() * Vector(
                        (0, 0, 1)) + self.depth * world_mx.to_3x3() * Vector(
                            (0, 0, 1))

                    world_mx[0][3] += delta[0]
                    world_mx[1][3] += delta[1]
                    world_mx[2][3] += delta[2]
                    #odcutils.reorient_object(Imp, rot_diff)

        odcutils.layer_management(sce.odc_implants, debug=False)
        for i, layer in enumerate(layers_copy):
            context.scene.layers[i] = layer
        context.scene.layers[11] = True

        return {'FINISHED'}
Exemplo n.º 11
0
    def execute(self, context):
        layers_copy = [layer for layer in context.scene.layers]
        context.scene.layers[0] = True

        tooth = odcutils.tooth_selection(context)[0]
        sce = bpy.context.scene
        a = tooth.name
        prep = tooth.prep_model
        margin = str(a + "_Margin")

        Prep = bpy.data.objects[prep]
        Prep.hide = False
        L = Prep.location
        #L = bpy.context.scene.cursor_location

        ###Keep a list of unhidden objects
        for o in sce.objects:
            if o.name != prep and not o.hide:
                o.hide = True

        master = sce.odc_props.master
        if master:
            Master = bpy.data.objects[master]
        else:
            self.report('WARNING', "No master model...there are risks!")

        bpy.ops.view3d.viewnumpad(type='TOP')
        bpy.ops.object.select_all(action='DESELECT')
        #bpy.context.scene.cursor_location = L
        bpy.ops.curve.primitive_bezier_curve_add(view_align=True,
                                                 enter_editmode=True,
                                                 location=L)
        bpy.context.tool_settings.use_snap = True
        bpy.context.tool_settings.snap_target = 'ACTIVE'
        bpy.context.tool_settings.snap_element = 'FACE'
        bpy.context.tool_settings.proportional_edit = 'DISABLED'
        o = bpy.context.object
        o.name = margin
        if master:
            o.parent = Master  #maybe this should go in the "Accept Margin" function/step
        bpy.ops.curve.handle_type_set(type='AUTOMATIC')
        bpy.ops.curve.select_all(action='DESELECT')
        bpy.context.object.data.splines[0].bezier_points[
            1].select_control_point = True
        bpy.ops.curve.delete()
        bpy.ops.curve.select_all(action='SELECT')
        bpy.ops.object.modifier_add(type='SHRINKWRAP')
        mod = bpy.context.object.modifiers[0]

        #this could also be the active object...?
        #in a different behavior mode...
        mod.target = Prep

        tooth.margin = margin

        odcutils.layer_management(sce.odc_teeth)
        for i, layer in enumerate(layers_copy):
            context.scene.layers[i] = layer
        context.scene.layers[4] = True

        return {'FINISHED'}
Exemplo n.º 12
0
 def execute(self, context):
     settings = get_settings()
     dbg = settings.debug
     #if bpy.context.mode != 'OBJECT':
     #    bpy.ops.object.mode_set(mode = 'OBJECT')
     
     sce = context.scene
     implants = odcutils.implant_selection(context)
     
     layers_copy = [layer for layer in context.scene.layers]
     context.scene.layers[0] = True
     
     if implants != []:
     
         for implant_space in implants:
             #check if space already has an implant object.
             #if so, delete, replace, print warning
             Implant = bpy.data.objects[implant_space.implant]
             
             if Implant.rotation_mode != 'QUATERNION':
                 Implant.rotation_mode = 'QUATERNION'
                 Implant.update_tag()
                 sce.update()
                 
             if bpy.data.objects.get(implant_space.drill):
                 self.report({'WARNING'}, "replacing the existing drill with the one you chose")
                 Sleeve = bpy.data.objects[implant_space.drill]
                 #unlink it from the scene, clear it's users, remove it.
                 sce.objects.unlink(Sleeve)
                 Implant.user_clear()
                 #remove the object
                 bpy.data.objects.remove(Sleeve)
                 
             current_obs = [ob.name for ob in bpy.data.objects]
             
             #link the new implant from the library
             settings = get_settings()
             odcutils.obj_from_lib(settings.drill_lib,self.drill)
             
             #this is slightly more robust than trusting we don't have duplicate names.
             for ob in bpy.data.objects:
                 if ob.name not in current_obs:
                     Sleeve = ob
                     
             sce.objects.link(Sleeve)
             Sleeve.layers[19] = True
             mx_w = Implant.matrix_world.copy()
             #point the right direction
             Sleeve.rotation_mode = 'QUATERNION'
             Sleeve.rotation_quaternion = mx_w.to_quaternion()          
             Sleeve.update_tag()
             context.scene.update()   
             Trans = Sleeve.rotation_quaternion * Vector((0,0,-self.depth))
             Sleeve.matrix_world[0][3] = mx_w[0][3] + Trans[0]
             Sleeve.matrix_world[1][3] = mx_w[1][3] + Trans[1]
             Sleeve.matrix_world[2][3] = mx_w[2][3] + Trans[2]
             
             Sleeve.name = implant_space.name + '_' + Sleeve.name
             implant_space.drill = Sleeve.name
             Sleeve.update_tag()
             context.scene.update()    
             odcutils.parent_in_place(Sleeve, Implant)
             odcutils.layer_management(sce.odc_implants, debug = dbg)
     for i, layer in enumerate(layers_copy):
         context.scene.layers[i] = layer
     context.scene.layers[19] = True                
     return {'FINISHED'}
Exemplo n.º 13
0
    def execute(self, context):
        settings = get_settings()
        dbg = settings.debug
        #if bpy.context.mode != 'OBJECT':
        #    bpy.ops.object.mode_set(mode = 'OBJECT')
        
        sce = context.scene
        n = sce.odc_implant_index
        implant_space = sce.odc_implants[n]
        
        implants = odcutils.implant_selection(context)
        layers_copy = [layer for layer in context.scene.layers]
        context.scene.layers[0] 
        
        if implants != []:
        
            for implant_space in implants:
                #check if space already has an implant object.
                #if so, delete, replace, print warning
                if implant_space.implant and implant_space.implant in bpy.data.objects:
                    self.report({'WARNING'}, "replacing the existing implant with the one you chose")
                    Implant = bpy.data.objects[implant_space.implant]
                    
                    
                    #the origin/location of the implant is it's apex
                    L = Implant.location.copy()  

                    world_mx = Implant.matrix_world.copy()
                    
                    #the platorm is the length of the implant above the apex, in the local Z direction
                    #local Z positive is out the apex, soit's negative.
                    #Put the cursor there
                    sce.cursor_location = L - Implant.dimensions[2] * world_mx.to_3x3() *  Vector((0,0,1))
                                        
                    #first get rid of children...so we can use the
                    #parent to find out who the children are
                    if Implant.children:
                        for child in Implant.children:
                            sce.objects.unlink(child)
                            child.user_clear()
                            bpy.data.objects.remove(child)
                            
                    #unlink it from the scene, clear it's users, remove it.
                    sce.objects.unlink(Implant)
                    Implant.user_clear()
                    #remove the object
                    bpy.data.objects.remove(Implant)
                    
                    
                    
                #TDOD what about the children/hardwares?
                else:
                    world_mx = Matrix.Identity(4)
                    
                world_mx[0][3]=sce.cursor_location[0]
                world_mx[1][3]=sce.cursor_location[1]
                world_mx[2][3]=sce.cursor_location[2]
                                        
                #is this more memory friendly than listing all objects?
                current_obs = [ob.name for ob in bpy.data.objects]
                
                #link the new implant from the library
                odcutils.obj_from_lib(settings.imp_lib,self.imp)
                
                #this is slightly more robust than trusting we don't have duplicate names.
                for ob in bpy.data.objects:
                    if ob.name not in current_obs:
                        Implant = ob
                        
                sce.objects.link(Implant)
                
                #this relies on the associated hardware objects having the parent implant
                #name inside them
                if self.hardware:
                    current_obs = [ob.name for ob in bpy.data.objects]
                    
                    inc = self.imp + '_'
                    hardware_list = odcutils.obj_list_from_lib(settings.imp_lib, include = inc)
                    print(hardware_list)
                    for ob in hardware_list:
                        odcutils.obj_from_lib(settings.imp_lib,ob)
                
                    for ob in bpy.data.objects:
                        if ob.name not in current_obs:
                            sce.objects.link(ob)
                            ob.parent = Implant
                            ob.layers[11] = True
                

                delta =  Implant.dimensions[2] * world_mx.to_3x3() * Vector((0,0,1))
                print(delta.length)
                world_mx[0][3] += delta[0]
                world_mx[1][3] += delta[1]
                world_mx[2][3] += delta[2]
                    

                Implant.matrix_world = world_mx

                
                if sce.odc_props.master:
                    Master = bpy.data.objects[sce.odc_props.master]
                    odcutils.parent_in_place(Implant, Master)
                else:
                    self.report({'WARNING'}, 'No Master Model, placing implant anyway, moving objects may not preserve spatial relationships')
                
                #looks a little redundant, but it ensure if any
                #duplicates exist our referencing stays accurate
                Implant.name = implant_space.name + '_' + Implant.name
                implant_space.implant = Implant.name
                    
                odcutils.layer_management(sce.odc_implants, debug = dbg)
        
        for i, layer in enumerate(layers_copy):
            context.scene.layers[i] = layer
        context.scene.layers[11] = True           
        return {'FINISHED'}
Exemplo n.º 14
0
    def execute(self, context):
        
            
        settings = get_settings()
        dbg = settings.debug
        
        #first, ensure all models are present and not deleted etc
        odcutils.scene_verification(context.scene, debug = dbg)      
        b = settings.behavior
        behave_mode = settings.behavior_modes[int(b)]
        
        settings = get_settings()
        dbg = settings.debug    
        [ob_sets, tool_sets, space_sets] = odcutils.scene_preserv(context, debug=dbg)
        
        #this is sneaky way of letting me test different things
        if behave_mode in {'ACTIVE','ACTIVE_SELECTED'} and dbg > 2:
            obs = context.selected_objects
            if obs[0].type == 'CURVE':
                model = obs[1]
                margin = obs[0]
            else:
                model = obs[0]
                margin = obs[1]
        
                exclude = ['name','teeth','implants','tooth_string','implant_string']
                splint = odcutils.active_odc_item_candidate(context.scene.odc_splints, obs[0], exclude)
        
        else:
            j = context.scene.odc_splint_index
            splint =context.scene.odc_splints[j]
            if splint.model in bpy.data.objects and splint.margin in bpy.data.objects:
                model = bpy.data.objects[splint.model]
                margin = bpy.data.objects[splint.margin]
            else:
                print('whoopsie...margin and model not defined or something is wrong')
                return {'CANCELLED'}
        
        
        layers_copy = [layer for layer in context.scene.layers]
        context.scene.layers[0] = True
        
        z = Vector((0,0,1))
        vrot= context.space_data.region_3d.view_rotation
        Z = vrot*z
        
        [Splint, Falloff, Refractory] = full_arch_methods.splint_bezier_step_1(context, model, margin, Z, self.thickness, debug=dbg)

        splint.splint = Splint.name #that's a pretty funny statement.
        
        if splint.bone and splint.bone in bpy.data.objects:
            mod = Splint.modifiers['Bone']
            mod.target = bpy.data.objects[splint.bone]
        
        if self.cleanup:
            context.scene.objects.active = Splint
            Splint.select = True
            
            for mod in Splint.modifiers:
                
                if mod.name != 'Bone':
                    if mod.type in {'BOOLEAN', 'SHRINKWRAP'}:
                        if mod.type == 'BOOLEAN' and mod.object:
                            bpy.ops.object.modifier_apply(modifier=mod.name)
                        elif mod.type == 'SHRINKWRAP' and mod.target:
                            bpy.ops.object.modifier_apply(modifier=mod.name)
                    else:
                        bpy.ops.object.modifier_apply(modifier=mod.name)

            context.scene.objects.unlink(Falloff)    
            Falloff.user_clear()
            bpy.data.objects.remove(Falloff)
            
            context.scene.objects.unlink(Refractory)
            Refractory.user_clear()
            bpy.data.objects.remove(Refractory)
            odcutils.scene_reconstruct(context, ob_sets, tool_sets, space_sets, debug=dbg)  
            
        else:
            odcutils.scene_reconstruct(context, ob_sets, tool_sets, space_sets, debug=dbg)  
            Falloff.hide = True
            Refractory.hide = True
                
        for i, layer in enumerate(layers_copy):
            context.scene.layers[i] = layer
        context.scene.layers[10] = True
          
        odcutils.material_management(context, context.scene.odc_splints, debug = dbg)
        odcutils.layer_management(context.scene.odc_splints, debug = dbg)   
        return {'FINISHED'}