######################################################################## #### #### Title: transfer.magik #### Author: Mark Cederholm #### Last Revised: 06-Jun-2002 #### #### Copy and paste object visible attributes. The "Force geometry #### update" option forces table update for mapped geometries. #### ######################################################################## #********************************************************************** # Exemplar #********************************************************************** remex(:att_transfer_utility) $ def_slotted_exemplar(:att_transfer_utility, { {:grs, _unset}, {:items, _unset}, {:clipboard, _unset}, {:flist, _unset}, {:clist, _unset} }, :model) $ #********************************************************************** # Method to launch #********************************************************************** _method graphics_system.launch_att_transfer_utility() menu_key << :att_transfer_utility _if (menu << .sub_menus[menu_key]) _is _unset _then menu << .sub_menus[menu_key] << att_transfer_utility.new(_self) _endif menu.activate() >> menu _endmethod $ #********************************************************************** # Public methods #********************************************************************** _method att_transfer_utility.new(a_grs) >> _clone.init(a_grs) _endmethod _method att_transfer_utility.activate_in(a_frame) # set up dialog _self.title << "Copy/Paste Attributes" .items << hash_table.new() p << panel.new(a_frame) .items[:status] << label_item.new(p, "OK") p.start_row() .items[:update_geom] << toggle_item.new(p,"Force geometry update", :value, _false) p.start_row() button_item.new(p,"Copy",_self,:|do_copy()|) button_item.new(p,"Fields...",_self,:|field_options()|) button_item.new(p,"Paste",_self,:|do_paste()|) button_item.new(p,"Quit",_self,:|quit()|) _endmethod _method att_transfer_utility.do_copy() g << .grs _if g.selected_rwos.size ~= 1 _then _self.show_alert("One object must be selected") .items[:status].label << "ERROR" _return _endif e << g.selected_rwos.an_element() _if .clipboard _is _unset _orif ~ e.is_class_of?(.clipboard) _then # Set field and copy lists fldlist << rope.new() _for f _over e.visible_fields.fast_elements() _loop _if f.is_physical? _then fldlist.add(f) _endif _endloop _if fldlist.size = 0 _then _self.show_alert("No copyable fields") .items[:status].label << "ERROR" _return _endif .flist << .clist << fldlist _endif .clipboard << e .items[:status].label << "Object copied." _endmethod _method att_transfer_utility.field_options() _if .clipboard _is _unset _then _self.show_alert("No object copied") .items[:status].label << "ERROR" _return _endif # Create choice_lister for field copy choices fc << choice_lister.new(:indestructable,_false,"OK") fc.activate_on(.flist,_self,:|set_fields()|,:external_name,:many) fc.title << "Copy field(s)" # Set selection based on .clist index_set << sorted_collection.new() _for f1 _over .clist.fast_elements() _loop index << _for i,f2 _over .flist.fast_keys_and_elements() _loop _if f1 _is f2 _then _leave _with i _endif _finally _continue _endloop index_set.add(index) _endloop fc.set_current_index(index_set,_unset) fc.changed(:list) _endmethod _method att_transfer_utility.set_fields(a_selection, an_index) # Set field copy choices .clist << a_selection _endmethod _method att_transfer_utility.do_paste() g << .grs c << .clipboard v << c.source_view t << c.source_collection _dynamic !current_grs! << g _dynamic !current_dsview! << v _dynamic !current_world! << v.world update_geom? << .items[:update_geom].value updated << 0 _for e _over g.selected_rwos.elements() _loop _if ~ e.is_class_of?(c) _then _continue _endif has_geometry? << e.has_geometry? _if update_geom? _and has_geometry? _then r << e.detached() _else r << e _endif ok? << v.start_lwt() _protect # Loop through visible fields and transfer physical values _for f _over .clist.fast_elements() _loop val << c.perform(f.name) r.perform(f.name.with_chevron, val) # this also works: r.ole_set(f.name, val) _endloop ok? << _true _protection v.end_lwt(ok?) _endprotect _if update_geom? _and has_geometry? _then ok? << v.start_lwt() _protect t.update(r) ok? << _true _protection v.end_lwt(ok?) _endprotect _endif updated +<< 1 _endloop .items[:status].label << updated.write_string + " object(s) updated." _endmethod #********************************************************************** # Private methods #********************************************************************** _private _method att_transfer_utility.init(a_grs) # initialize .grs and .view .grs << a_grs >> _super.init() _endmethod