Exemple #1
0
    def process_module(desc):
        # 0.9.3 upgrades
        if not desc.name in klasses:
            return
        remap = UpgradeModuleRemap(None, '0.9.3', '0.9.3',
                                   module_name=desc.name)
        process_ports(desc, remap, 'input')
        process_ports(desc, remap, 'output')
        _remap.add_module_remap(remap)
        for old, new in module_name_remap.iteritems():
            if desc.name == new:
                # Remap using old name
                remap.new_module = old
                _remap.add_module_remap(remap, old)
        # 0.9.5 upgrades
        remap = UpgradeModuleRemap('0.9.3', '0.9.5', '0.9.5',
                                   module_name=desc.name)
        remap.add_remap('src_port_remap', 'self', 'Instance')
        _remap.add_module_remap(remap)
        for old, new in module_name_remap.iteritems():
            if desc.name == new:
                # Remap using old name
                remap.new_module = old
                _remap.add_module_remap(remap, old)
        # 1.0.0 upgrades
        input_mappings = {}
        function_mappings = {}
        input_specs = [desc.module._get_input_spec(s)
                     for s in get_port_specs(desc, 'input')]
        input_names = [s.name for s in input_specs]
        for spec in input_specs:
            if spec is None:
                continue
            elif spec.name == 'TextScaleMode':
                function_mappings['ScaledTextOn'] = \
                                           change_func('TextScaleMode', 'Prop')
            elif spec.method_type == 'OnOff':
                # Convert On/Off to single port
                input_mappings[spec.name + 'On'] = spec.name
                input_mappings[spec.name + 'Off'] = spec.name
                function_mappings[spec.name + 'On'] = \
                                              change_func(spec.name, True)
                function_mappings[spec.name + 'Off'] = \
                                             change_func(spec.name, False)
            elif spec.method_type == 'nullary':
                # Add True to execute empty functions
                function_mappings[spec.name] = change_func(spec.name, True)
            elif spec.method_type == 'SetXToY':
                # Add one mapping for each default
                for enum in spec.values[0]:
                    input_mappings[spec.method_name + enum] = spec.name
                    # Add enum value to function
                    function_mappings[spec.method_name + enum] = \
                                                  change_func(spec.name, enum)
                # Convert SetX(int) methods
                old_name = spec.method_name[:-2]
                function_mappings[spec.method_name[:-2]] = change_SetXint(spec)
            elif spec.port_type == 'basic:Color':
                # Remove 'Widget' suffix on Color
                input_mappings[spec.method_name + 'Widget'] = spec.name
                # Remove 'Set prefix'
                input_mappings[spec.method_name] = spec.name
                # Change old type (float, float, float) -> (,)*3
                function_mappings[spec.method_name] = color_func(spec.name)
            elif spec.port_type == 'basic:File':
                input_mappings[spec.method_name] = to_file_func(spec.name)  # Set*FileName -> (->File->*File)
                input_mappings['Set' + spec.name] = spec.name # Set*File -> *File
                function_mappings[spec.method_name] = file_func(spec.name)
            elif base_name(spec.name) == 'AddDataSetInput':
                # SetInput* does not exist in VTK 6
                if spec.name[15:] == '_1':
                    # Upgrade from version without overload
                    input_mappings['AddInput'] = spec.name
                input_mappings['AddInput' + spec.name[15:]] = spec.name
            elif base_name(spec.name) == 'InputData':
                # SetInput* does not exist in VTK 6
                if spec.name[9:] == '_1':
                    # Upgrade from version without overload
                    input_mappings['SetInput'] = spec.name
                input_mappings['SetInput' + spec.name[9:]] = spec.name
            elif base_name(spec.name) == 'AddInputData':
                # AddInput* does not exist in VTK 6
                if spec.name[12:] == '_1':
                    # Upgrade from version without overload
                    input_mappings['AddInput'] = spec.name
                input_mappings['AddInput' + spec.name[12:]] = spec.name
            elif base_name(spec.name) ==  'SourceData':
                # SetSource* does not exist in VTK 6
                if spec.name[10:] == '_1':
                    # Upgrade from version without overload
                    input_mappings['SetSource'] = spec.name
                input_mappings['SetSource' + spec.name[10:]] = spec.name
            elif spec.method_name == 'Set' + base_name(spec.name):
                if spec.name[-2:] == '_1':
                    # Upgrade from versions without overload
                    input_mappings[spec.name[:-2]] = spec.name
                    input_mappings['Set' + spec.name[:-2]] = spec.name
                # Remove 'Set' prefixes
                input_mappings['Set' + spec.name] = spec.name
            elif spec.name == 'AddInput_1':
                # FIXME what causes this?
                # New version does not have AddInput
                input_mappings['AddInput'] = 'AddInput_1'
            elif spec.name == 'vtkRenderer':
                # Classes having SetRendererWindow also used to have VTKCell
                input_mappings['SetVTKCell'] = fix_vtkcell_func()
        output_mappings = {}
        for spec_name in get_port_specs(desc, 'output'):
            spec = desc.module._get_output_spec(spec_name)
            if spec is None:
                continue
            if spec.method_name == 'Get' + spec.name:
                # Remove 'Get' prefixes
                output_mappings[spec.method_name] = spec.name
        if desc.name == 'vtkMultiBlockPLOT3DReader':
            # Move GetOutput to custom FirstBlock
            output_mappings['GetOutput'] = wrap_block_func()  # what!?
            # Move GetOutputPort0 to custom FirstBlock
            # and change destination port to AddInputData_1 or similar
            output_mappings['GetOutputPort0'] = wrap_block_func()

        remap = UpgradeModuleRemap('0.9.5', '1.0.0', '1.0.0',
                                   module_name=desc.name)
        for k, v in input_mappings.iteritems():
            remap.add_remap('dst_port_remap', k, v)
        for k, v in output_mappings.iteritems():
            remap.add_remap('src_port_remap', k, v)
        for k, v in function_mappings.iteritems():
            remap.add_remap('function_remap', k, v)
        _remap.add_module_remap(remap)
        for old, new in module_name_remap.iteritems():
            if desc.name == new:
                # Remap to new name
                remap.new_module = new
                _remap.add_module_remap(remap, old)
Exemple #2
0
    def process_module(desc):
        # 0.9.3 upgrades
        if not desc.name in klasses:
            return
        remap = UpgradeModuleRemap(None,
                                   '0.9.3',
                                   '0.9.3',
                                   module_name=desc.name)
        process_ports(desc, remap, 'input')
        process_ports(desc, remap, 'output')
        _remap.add_module_remap(remap)
        for old, new in module_name_remap.iteritems():
            if desc.name == new:
                # Remap using old name
                remap.new_module = old
                _remap.add_module_remap(remap, old)
        # 0.9.5 upgrades
        remap = UpgradeModuleRemap('0.9.3',
                                   '0.9.5',
                                   '0.9.5',
                                   module_name=desc.name)
        remap.add_remap('src_port_remap', 'self', 'Instance')
        _remap.add_module_remap(remap)
        for old, new in module_name_remap.iteritems():
            if desc.name == new:
                # Remap using old name
                remap.new_module = old
                _remap.add_module_remap(remap, old)
        # 1.0.0 upgrades
        input_mappings = {}
        function_mappings = {}
        input_specs = [
            desc.module._get_input_spec(s)
            for s in get_port_specs(desc, 'input')
        ]
        input_names = [s.name for s in input_specs]
        for spec in input_specs:
            if spec is None:
                continue
            elif spec.name == 'TextScaleMode':
                function_mappings['ScaledTextOn'] = \
                                           change_func('TextScaleMode', 'Prop')
            elif spec.method_type == 'OnOff':
                # Convert On/Off to single port
                input_mappings[spec.name + 'On'] = spec.name
                input_mappings[spec.name + 'Off'] = spec.name
                function_mappings[spec.name + 'On'] = \
                                              change_func(spec.name, True)
                function_mappings[spec.name + 'Off'] = \
                                             change_func(spec.name, False)
            elif spec.method_type == 'nullary':
                # Add True to execute empty functions
                function_mappings[spec.name] = change_func(spec.name, True)
            elif spec.method_type == 'SetXToY':
                # Add one mapping for each default
                for enum in spec.values[0]:
                    input_mappings[spec.method_name + enum] = spec.name
                    # Add enum value to function
                    function_mappings[spec.method_name + enum] = \
                                                  change_func(spec.name, enum)
                # Convert SetX(int) methods
                old_name = spec.method_name[:-2]
                function_mappings[spec.method_name[:-2]] = change_SetXint(spec)
            elif spec.port_type == 'basic:Color':
                # Remove 'Widget' suffix on Color
                input_mappings[spec.method_name + 'Widget'] = spec.name
                # Remove 'Set prefix'
                input_mappings[spec.method_name] = spec.name
                # Change old type (float, float, float) -> (,)*3
                function_mappings[spec.method_name] = color_func(spec.name)
            elif spec.port_type == 'basic:File':
                input_mappings[spec.method_name] = to_file_func(
                    spec.name)  # Set*FileName -> (->File->*File)
                input_mappings['Set' +
                               spec.name] = spec.name  # Set*File -> *File
                function_mappings[spec.method_name] = file_func(spec.name)
            elif base_name(spec.name) == 'AddDataSetInput':
                # SetInput* does not exist in VTK 6
                if spec.name[15:] == '_1':
                    # Upgrade from version without overload
                    input_mappings['AddInput'] = spec.name
                input_mappings['AddInput' + spec.name[15:]] = spec.name
            elif base_name(spec.name) == 'InputData':
                # SetInput* does not exist in VTK 6
                if spec.name[9:] == '_1':
                    # Upgrade from version without overload
                    input_mappings['SetInput'] = spec.name
                input_mappings['SetInput' + spec.name[9:]] = spec.name
            elif base_name(spec.name) == 'AddInputData':
                # AddInput* does not exist in VTK 6
                if spec.name[12:] == '_1':
                    # Upgrade from version without overload
                    input_mappings['AddInput'] = spec.name
                input_mappings['AddInput' + spec.name[12:]] = spec.name
            elif base_name(spec.name) == 'SourceData':
                # SetSource* does not exist in VTK 6
                if spec.name[10:] == '_1':
                    # Upgrade from version without overload
                    input_mappings['SetSource'] = spec.name
                input_mappings['SetSource' + spec.name[10:]] = spec.name
            elif spec.method_name == 'Set' + base_name(spec.name):
                if spec.name[-2:] == '_1':
                    # Upgrade from versions without overload
                    input_mappings[spec.name[:-2]] = spec.name
                    input_mappings['Set' + spec.name[:-2]] = spec.name
                # Remove 'Set' prefixes
                input_mappings['Set' + spec.name] = spec.name
            elif spec.name == 'AddInput_1':
                # FIXME what causes this?
                # New version does not have AddInput
                input_mappings['AddInput'] = 'AddInput_1'
            elif spec.name == 'vtkRenderer':
                # Classes having SetRendererWindow also used to have VTKCell
                input_mappings['SetVTKCell'] = fix_vtkcell_func()
        output_mappings = {}
        for spec_name in get_port_specs(desc, 'output'):
            spec = desc.module._get_output_spec(spec_name)
            if spec is None:
                continue
            if spec.method_name == 'Get' + spec.name:
                # Remove 'Get' prefixes
                output_mappings[spec.method_name] = spec.name
        if desc.name == 'vtkMultiBlockPLOT3DReader':
            # Move GetOutput to custom FirstBlock
            output_mappings['GetOutput'] = wrap_block_func()  # what!?
            # Move GetOutputPort0 to custom FirstBlock
            # and change destination port to AddInputData_1 or similar
            output_mappings['GetOutputPort0'] = wrap_block_func()

        remap = UpgradeModuleRemap('0.9.5',
                                   '1.0.0',
                                   '1.0.0',
                                   module_name=desc.name)
        for k, v in input_mappings.iteritems():
            remap.add_remap('dst_port_remap', k, v)
        for k, v in output_mappings.iteritems():
            remap.add_remap('src_port_remap', k, v)
        for k, v in function_mappings.iteritems():
            remap.add_remap('function_remap', k, v)
        _remap.add_module_remap(remap)
        for old, new in module_name_remap.iteritems():
            if desc.name == new:
                # Remap to new name
                remap.new_module = new
                _remap.add_module_remap(remap, old)