Skip to content
Snippets Groups Projects
np_point_copy.py 52.4 KiB
Newer Older
  • Learn to ignore specific revisions
  •             co[0] = round((co[0] * badge_size),0) -(badge_size*10) + self.co2d[0]
                co[1] = round((co[1] * badge_size),0) -(badge_size*25) + self.co2d[1]
            ipx = round((ipx * badge_size),0) -(badge_size*10) + self.co2d[0]
            ipy = round((ipy * badge_size),0) -(badge_size*25) + self.co2d[1]
            ipsize = int(6* badge_size)
            bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
            bgl.glBegin(bgl.GL_TRIANGLE_FAN)
            for x,y in square:
                bgl.glVertex2f(x,y)
            bgl.glEnd()
            bgl.glColor4f(0.5, 0.75, 0.0, 1.0)
            bgl.glBegin(bgl.GL_TRIANGLE_FAN)
            for x,y in rectangle:
                bgl.glVertex2f(x,y)
    
            bgl.glColor4f(0.2, 0.15, 0.55, 1.0)
            bgl.glBegin(bgl.GL_TRIANGLE_FAN)
            for x,y in rectangle:
                bgl.glVertex2f(x,(y-(badge_size*35)))
    
            bgl.glColor4f(1.0, 1.0, 1.0, 1.0)
            font_id = 0
            blf.position(font_id,ipx,ipy,0)
            blf.size(font_id,ipsize,72)
            blf.draw(font_id,'NAVIGATE')
            blf.position(font_id,ipx,(ipy-(badge_size*35)),0)
            blf.size(font_id,ipsize,72)
            blf.draw(font_id,'CTRL+SCRL')
            bgl.glColor4f(1,1,1,1)
            blf.position(font_id,ipx,(int(ipy-badge_size*25)),0)
            blf.size(font_id,(int(badge_size*24)),72)
            if NP020PC.fit_type == 'FIT_LENGTH':
                blf.draw(font_id,'/' + str(NP020PC.count))
            else:
                blf.draw(font_id,str(NP020PC.count))
            bgl.glColor4f(1.0, 1.0, 1.0, 1.0)
            bgl.glBegin(bgl.GL_LINE_STRIP)
            for x,y in icon:
                bgl.glVertex2f(x,y)
            bgl.glEnd()
    
        # ON-SCREEN INSTRUCTIONS:
        font_id = 0
        bgl.glColor4f(1,1,1,0.35)
        blf.size(font_id,88,72)
        blf.position(font_id,5,74,0)
        blf.draw(font_id,'N')
        blf.size(font_id,28,72)
        blf.position(font_id,22,74,0)
        blf.draw(font_id,'P')
        blf.enable(font_id, ROTATION)
        bgl.glColor4f(1,1,1,0.40)
        ang = radians(90)
        blf.size(font_id,19,72)
        blf.rotation(font_id,ang)
        blf.position(font_id,78,73,0)
        blf.draw(font_id,'PC 002')
        blf.disable(font_id, ROTATION)
    
        main='SPECIFY NUMBER OF ITEMS IN ARRAY'
        bgl.glColor4f(0,0.5,0,1)
        blf.size(font_id,11,72)
        blf.position(font_id,93,105,0)
        blf.draw(font_id,'MMB, SCROLL - navigate')
        blf.position(font_id,93,90,0)
        blf.draw(font_id,'CTRL+SCROLL, UPARROW / DOWNARROW - number of items')
        blf.position(font_id,93,75,0)
        blf.draw(font_id,'LMB, RMB - confirm and keep array, ENTER - apply as one, TAB - apply as separate, CTRL+TAB - apply as instanced')
        bgl.glColor4f(1,0,0,1)
        blf.position(font_id,93,60,0)
        blf.draw(font_id,'ESC - cancel array')
        bgl.glColor4f(0.0, 0.0, 0.0, 0.5)
        blf.position(font_id,93,124,0)
        blf.size(font_id,16,72)
        blf.draw(font_id,main)
        bgl.glColor4f(1,1,1,1)
        blf.position(font_id,94,125,0)
        blf.size(font_id,16,72)
        blf.draw(font_id,main)
    
    
        region = context.region
        rv3d = context.region_data
        ar12d = view3d_utils.location_3d_to_region_2d(region, rv3d, NP020PC.ar13d)
        ar22d = view3d_utils.location_3d_to_region_2d(region, rv3d, NP020PC.ar23d)
        ardist = NP020PC.ardist
        ardist_loc = (ar12d + ar22d) /2
    
        # ARMARKERS:
        markersize = badge_size*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:
        np_print('ardist = ', ardist, 'ardist_loc = ', ardist_loc)
    
        bgl.glColor4f(0.4, 0.15, 0.75, 1.0)
    
        font_id = 0
        blf.size(font_id, 20, 72)
        blf.position(font_id, ardist_loc[0], ardist_loc[1], 0)
        blf.draw(font_id, ardist)
    
        #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 = ', NP020PC.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 NPPCRestoreContext(bpy.types.Operator):
        bl_idname = "object.np_pc_restore_context"
        bl_label = "NP PC Restore Context"
        bl_options = {'INTERNAL'}
    
        def execute(self, context):
            np_print('07_CleanExit_START',';','flag = ', NP020PC.flag)
            flag = NP020PC.flag
            selob = NP020PC.selob
            take = NP020PC.take
            place = NP020PC.place
            bpy.ops.object.select_all(action='DESELECT')
    
            take.select_set(True)
            place.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
    
            NP020PC.take = None
            NP020PC.place = None
            NP020PC.takeloc3d = (0.0,0.0,0.0)
            NP020PC.placeloc3d = (0.0,0.0,0.0)
            NP020PC.dist = None
            NP020PC.mode = 'MOVE'
            NP020PC.flag = 'NONE'
            NP020PC.ardict = {}
            NP020PC.deltavec = Vector ((0, 0, 0))
            NP020PC.deltavec_safe = Vector ((0, 0, 0))
            bpy.context.tool_settings.use_snap = NP020PC.use_snap
            bpy.context.tool_settings.snap_element = NP020PC.snap_element
            bpy.context.tool_settings.snap_target = NP020PC.snap_target
            bpy.context.space_data.pivot_point = NP020PC.pivot_point
            bpy.context.space_data.transform_orientation = NP020PC.trans_orient
            #if NP020PC.acob is not None:
                #bpy.context.scene.objects.active = NP020PC.acob
                #bpy.ops.object.mode_set(mode = NP020PC.edit_mode)
    
            np_print('07_CleanExit_FINISHED',';','flag = ', NP020PC.flag)
            return {'FINISHED'}
    
    
    '''
    # Defining the settings of the addon in the User preferences / addons tab:
    
    class NPPCPreferences(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(NPPCPreferences)
        #bpy.utils.register_module(__name__)
        bpy.app.handlers.scene_update_post.append(NPPC_scene_update)
    
        NP020PointCopy.define('OBJECT_OT_np_pc_get_context')
        NP020PointCopy.define('OBJECT_OT_np_pc_get_selection')
        NP020PointCopy.define('OBJECT_OT_np_pc_get_mouseloc')
        NP020PointCopy.define('OBJECT_OT_np_pc_add_helpers')
        NP020PointCopy.define('OBJECT_OT_np_pc_prepare_context')
        for i in range(1, 50):
            for i in range(1, 10):
                NP020PointCopy.define('OBJECT_OT_np_pc_run_translate')
                NP020PointCopy.define('OBJECT_OT_np_pc_nav_translate')
            NP020PointCopy.define('OBJECT_OT_np_pc_prepare_next')
        #NP020PointCopy.define('OBJECT_OT_np_pc_array_translate')
        NP020PointCopy.define('OBJECT_OT_np_pc_restore_context')
    
    def unregister():
        #pass
        #bpy.utils.unregister_class(NPPCPreferences)
        #bpy.utils.unregister_module(__name__)
        bpy.app.handlers.scene_update_post.remove(NPPC_scene_update)