www.gusucode.com > mbcdata 工具箱 matlab 源码程序 > mbcdata/@cgoptimconstraint/getTypeChooserOptions.m

    function [name, opts] = getTypeChooserOptions(obj, pProj, Optim)
%GETTYPECHOOSEROPTIONS Get alternative objects to display as options
%
%  [NAME, OPTS] = GETTYPECHOOSEROPTIONS(OBJ, PPROJ, OPTIM) returns a group
%  name and a group of options that should be displayed for OBJ when the
%  method GUITYPECHOOSER is called.  OPTS must be a (1-by-N) struct array
%  with fields Type, Function and Destructor.  Function is a function
%  handle that creates an instance of a cgoptimitem when called.  Type
%  contains a string that describes the new object type.  The type string
%  should match the return of getType on the new object.

%  Copyright 2005-2006 The MathWorks, Inc. and Ford Global Technologies, Inc.


name = 'Constraint';

ObjectName = getName(obj);

% Pick up all cgconstraint types and present them as separate options
fact = cgexprfactory;
connames = getConstraintNames(fact);
confunc = getConstraintFuncs(fact, pProj, get(Optim, 'values'));
factoryfuncs = cell(size(confunc));
for n =1:length(factoryfuncs)
    % Absorb argument passed to object creation func and wrap cgconstraint
    % in an optimization object
    factoryfuncs{n} = @(dlg) cgpointconstraint(ObjectName, xregpointer(confunc{n}()));
end

% Append the sum and table gradient constraints
extraconnames = {'Range', 'Sum Constraint', 'Table Gradient'};
extrafactoryfuncs = {@(dlg) cgrangeconstraint(ObjectName), ...
    @(dlg) cgsumconstraint(ObjectName), ...
    @(dlg) cgtabgradconstraint(ObjectName)};
connames = [connames, extraconnames];
factoryfuncs = [factoryfuncs, extrafactoryfuncs];

% Pass out all the possible constraints
opts = struct('Type', connames, ...
    'Function', factoryfuncs);