function data=mphgetselection(node)
% data=mphgetselection(node)
%
% data=mphgetselection(model.selection('ball1'))

try
    if ~isa(node, 'com.comsol.model.impl.SelectionFeatureImpl') && ...
            ~isa(node, 'com.comsol.model.impl.LocalSelectionImpl')
        node = node.selection;
    end
catch
    data = [];
    return
end

% data.type = model.selection('sel1').getType
%
% model.selection('sel1').entities(3)

%data.type = char(node.getType);
data.dimension = node.dimension;
data.geom = char(node.geom);
if length(data.dimension)==1
    data.entities = node.entities(data.dimension)';
else
    for i=1:length(data.dimension)
        data.entities{i} = node.entities(data.dimension(i))';
    end
end

data.isGlobal = double(node.isGlobal);
% data.hasSelection = double(node.hasSelection);
% if data.hasSelection
%     data.selection = node.selection;
% end
% Copyright 2010-2011 COMSOL
