Skip to content
Snippets Groups Projects
np_point_array.py 49.2 KiB
Newer Older
  • Learn to ignore specific revisions
  •     markersize = 2 * 2.5
        triangle = [[0, 0], [-1, 1], [1, 1]]
        triangle = [[0, 0], [-1, 1], [1, 1]]
        for co in triangle:
            co[0] = int(co[0] * markersize * 3) + ar12d[0]
            co[1] = int(co[1] * markersize * 3) + ar12d[1]
        bgl.glColor4f(0.4, 0.15, 0.75, 1.0)
        bgl.glBegin(bgl.GL_TRIANGLE_FAN)
        for x,y in triangle:
            bgl.glVertex2f(x,y)
        bgl.glEnd()
        triangle = [[0, 0], [-1, 1], [1, 1]]
        for co in triangle:
            co[0] = int(co[0] * markersize * 3) + ar22d[0]
            co[1] = int(co[1] * markersize * 3) + ar22d[1]
        bgl.glColor4f(0.4, 0.15, 0.75, 1.0)
        bgl.glBegin(bgl.GL_TRIANGLE_FAN)
        for x,y in triangle:
            bgl.glVertex2f(x,y)
        bgl.glEnd()
    
        # AR NUMERICAL DISTANCE:
        display_distance_between_two_points(region, rv3d, NP020PA.ar13d, NP020PA.ar23d)
    
        #DRAWING END:
        bgl.glLineWidth(1)
        bgl.glDisable(bgl.GL_BLEND)
        bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
        np_print('06a_DRAW_ArrayTrans_FINISHED',';','flag = ', NP020PA.flag)
    
    
    # Restoring the object selection and system settings from before the operator activation. Deleting the helpers after successful translation, reseting all viewport options and reselecting previously selected objects:
    
    class NPPARestoreContext(bpy.types.Operator):
        bl_idname = "object.np_pa_restore_context"
        bl_label = "NP PA Restore Context"
        bl_options = {'INTERNAL'}
    
        def execute(self, context):
            np_print('07_CleanExit_START',';','flag = ', NP020PA.flag)
            flag = NP020PA.flag
            selob = NP020PA.selob
            take = NP020PA.take
            place = NP020PA.place
            bpy.ops.object.select_all(action='DESELECT')
    
            take.select_set(True)
            place.select_set(True)
    
            if NP020PA.prevob != None:
                prevob = NP020PA.prevob
                nextob = NP020PA.nextob
                if prevob is not selob:
                    for i, ob in enumerate(prevob):
    
                        ob.select_set(True)
    
                for i, ob in enumerate(nextob):
    
                    ob.select_set(True)
    
            bpy.ops.object.delete('EXEC_DEFAULT')
            lenselob = len(selob)
            for i, ob in enumerate(selob):
    
                ob.select_set(True)
    
                if i == lenselob-1:
    
                    bpy.context.view_layer.objects.active = ob
    
            NP020PA.take = None
            NP020PA.place = None
            NP020PA.takeloc3d = (0.0,0.0,0.0)
            NP020PA.placeloc3d = (0.0,0.0,0.0)
            NP020PA.prevob = None
            NP020PA.nextob = None
            NP020PA.dist = None
            NP020PA.mode = 'MOVE'
            NP020PA.flag = 'NONE'
            NP020PA.ardict = {}
            NP020PA.deltavec = Vector ((0, 0, 0))
            NP020PA.deltavec_safe = Vector ((0, 0, 0))
            bpy.context.tool_settings.use_snap = NP020PA.use_snap
            bpy.context.tool_settings.snap_element = NP020PA.snap_element
            bpy.context.tool_settings.snap_target = NP020PA.snap_target
            bpy.context.space_data.pivot_point = NP020PA.pivot_point
            bpy.context.space_data.transform_orientation = NP020PA.trans_orient
            if NP020PA.acob is not None:
    
                bpy.context.view_layer.objects.active = NP020PA.acob
    
                bpy.ops.object.mode_set(mode = NP020PA.edit_mode)
    
            np_print('07_CleanExit_FINISHED',';','flag = ', NP020PA.flag)
            return {'FINISHED'}
    
    
    '''
    # Defining the settings of the addon in the User preferences / addons tab:
    
    class NPPAPreferences(bpy.types.AddonPreferences):
        # this must match the addon name, use '__package__'
        # when defining this in a submodule of a python package.
        bl_idname = __name__
    
        dist_scale = bpy.props.FloatProperty(
                name='Unit scale',
                description='Distance multiplier (for example, for cm use 100)',
                default=100,
                min=0,
                step=1,
                precision=3)
    
        suffix = bpy.props.EnumProperty(
            name='Unit suffix',
    
            items=(("'","'",''), ('"','"',''), ('thou','thou',''), ('km','km',''), ('m','m',''), ('cm','cm',''), ('mm','mm',''), ('nm','nm',''), ('None','None','')),
    
            default='cm',
            description='Add a unit extension after the numerical distance ')
    
        badge = bpy.props.BoolProperty(
                name='Mouse badge',
                description='Use the graphical badge near the mouse cursor',
                default=True)
    
        badge_size = bpy.props.FloatProperty(
                name='size',
                description='Size of the mouse badge, the default is 2.0',
                default=2,
                min=0.5,
                step=10,
                precision=1)
    
        col_line_main_DEF = bpy.props.BoolProperty(
                name='Default',
                description='Use the default color',
                default=True)
    
        col_line_shadow_DEF = bpy.props.BoolProperty(
                name='Default',
                description='Use the default color',
                default=True)
    
        col_num_main_DEF = bpy.props.BoolProperty(
                name='Default',
                description='Use the default color',
                default=True)
    
        col_num_shadow_DEF = bpy.props.BoolProperty(
                name='Default',
                description='Use the default color',
                default=True)
    
        col_line_main = bpy.props.FloatVectorProperty(name='', default=(1.0, 1.0, 1.0, 1.0), size=4, subtype="COLOR", min=0, max=1, description = 'Color of the measurement line, to disable it set alpha to 0.0')
    
        col_line_shadow = bpy.props.FloatVectorProperty(name='', default=(0.1, 0.1, 0.1, 0.25), size=4, subtype="COLOR", min=0, max=1, description = 'Color of the line shadow, to disable it set alpha to 0.0')
    
        col_num_main = bpy.props.FloatVectorProperty(name='', default=(0.1, 0.1, 0.1, 0.75), size=4, subtype="COLOR", min=0, max=1, description = 'Color of the number, to disable it set alpha to 0.0')
    
        col_num_shadow = bpy.props.FloatVectorProperty(name='', default=(1.0, 1.0, 1.0, 1.0), size=4, subtype="COLOR", min=0, max=1, description = 'Color of the number shadow, to disable it set alpha to 0.0')
    
        def draw(self, context):
            layout = self.layout
            split = layout.split()
            col = split.column()
            col.prop(self, "dist_scale")
            col = split.column()
            col.prop(self, "suffix")
            split = layout.split()
            col = split.column()
            col.label(text='Line Main COLOR')
            col.prop(self, "col_line_main_DEF")
            if self.col_line_main_DEF == False:
                col.prop(self, "col_line_main")
            col = split.column()
            col.label(text='Line Shadow COLOR')
            col.prop(self, "col_line_shadow_DEF")
            if self.col_line_shadow_DEF == False:
                col.prop(self, "col_line_shadow")
            col = split.column()
            col.label(text='Numerical Main COLOR')
            col.prop(self, "col_num_main_DEF")
            if self.col_num_main_DEF == False:
                col.prop(self, "col_num_main")
            col = split.column()
            col.label(text='Numerical Shadow COLOR')
            col.prop(self, "col_num_shadow_DEF")
            if self.col_num_shadow_DEF == False:
                col.prop(self, "col_num_shadow")
            split = layout.split()
            col = split.column()
            col.prop(self, "badge")
            col = split.column()
            if self.badge == True:
                col.prop(self, "badge_size")
            col = split.column()
            col = split.column()
    '''
    
    # This is the actual addon process, the algorithm that defines the order of operator activation inside the main macro:
    
    def register():
    
        #bpy.utils.register_class(NPPAPreferences)
        #bpy.utils.register_module(__name__)
        bpy.app.handlers.scene_update_post.append(NPPA_scene_update)
    
        NP020PointArray.define('OBJECT_OT_np_pa_get_context')
        NP020PointArray.define('OBJECT_OT_np_pa_get_selection')
        NP020PointArray.define('OBJECT_OT_np_pa_get_mouseloc')
        NP020PointArray.define('OBJECT_OT_np_pa_add_helpers')
        NP020PointArray.define('OBJECT_OT_np_pa_prepare_context')
        for i in range(1, 3):
            for i in range(1, 10):
                NP020PointArray.define('OBJECT_OT_np_pa_run_translate')
                NP020PointArray.define('OBJECT_OT_np_pa_nav_translate')
            NP020PointArray.define('OBJECT_OT_np_pa_prepare_next')
        NP020PointArray.define('OBJECT_OT_np_pa_array_translate')
        NP020PointArray.define('OBJECT_OT_np_pa_restore_context')
    
    def unregister():
        #pass
        #bpy.utils.unregister_class(NPPAPreferences)
        #bpy.utils.unregister_module(__name__)
    
        bpy.app.handlers.scene_update_post.remove(NPPA_scene_update)