function sys = display(X)
%display           Displays a SET object.

% Author Johan Löfberg
% $Id: display.m,v 1.9 2006/09/27 13:52:09 joloef Exp $

nlmi = size(X.clauses,2);

if (nlmi == 0)
    disp('empty SET')
    return
end

lmiinfo{1} = 'Matrix inequality';
lmiinfo{2} = 'Element-wise';
lmiinfo{3} = 'Equality constraint';
lmiinfo{4} = 'Second order cone constraint';
lmiinfo{5} = 'Rotated Lorentz constraint';
lmiinfo{7} = 'Integrality constraint';
lmiinfo{8} = 'Binary constraint';
lmiinfo{9} = 'KYP constraint';
lmiinfo{10}= 'Eigenvalue constraint';
lmiinfo{11}= 'Sum-of-square constraint';
lmiinfo{12}= 'Logic constraint';
lmiinfo{13}= 'Parametric declaration';
lmiinfo{14}= 'Low-rank data declaration';
lmiinfo{15}= 'Uncertain declaration';

headers = {'ID','Constraint','Type','Tag'};
rankVariables = yalmip('rankvariables');
extVariables = yalmip('extvariables');
if nlmi>0
    for i = 1:nlmi
        
        data{i,1} = ['#' num2str(i)];
        data{i,2} = X.clauses{i}.symbolic;
        data{i,3} = lmiinfo{X.clauses{i}.type};
        if length(getvariables(X.clauses{i}.data)) == 1
            if any(ismember(getvariables(X.clauses{i}.data),rankVariables))
                 data{i,3} = 'Rank constraint';
            end
        end
        
        if X.clauses{i}.type == 14
        else
            classification = '';
            if any(ismembc(getvariables(X.clauses{i}.data),yalmip('intvariables')))
                classification = [classification ',integer'];
            end

            if size(X.clauses{i},2)>1
                classification = [classification ',logic'];                
            end
           
            linearbilinearquadraticsigmonial = is(X.clauses{i}.data,'LBQS');
            if ~linearbilinearquadraticsigmonial(1)
                if linearbilinearquadraticsigmonial(4)
                    classification = [classification ',sigmonial'];
                elseif linearbilinearquadraticsigmonial(2)
                    classification = [classification ',bilinear'];
                elseif linearbilinearquadraticsigmonial(3)
                    classification = [classification ',quadratic'];
                else
                    classification = [classification ',polynomial'];
                end                
            end
            
            data{i,4} = X.clauses{i}.handle;
            if ~isreal(X.clauses{i}.data)                
                classification = [classification ',complex'];
            end
            %if ~isempty(intersect(getvariables(X.clauses{i}.data),extVariables))
            if any(ismembc(getvariables(X.clauses{i}.data),extVariables))
                classification = [classification ',derived'];
            end
            
            if length(classification)==0
            else                
                data{i,3} = [data{i,3} ' (' classification(2:end) ')'];
            end

            if ismembc(X.clauses{i}.type,[1 2 3 4 5 9])
                data{i,3} = [data{i,3} ' ' num2str(size(X.clauses{i}.data,1)) 'x' num2str(size(X.clauses{i}.data,2))];
            end
        end

    end
end

% If no tags, don't show...
if length([data{:,4}])==0
    headers = {headers{:,1:3}};
    data = reshape({data{:,1:3}},length({data{:,1:3}})/3,3);
end


table('',headers,data)

function x= truncstring(x,n)
if length(x) > n
    x = [x(1:n-3) '...'];
end

function x = fillstring(x,n)
x = [x blanks(n-length(x))];

