Why not set the parameter values as follows:

This looks to me like a rather non-orthogonal design.

Why not have:
  a1 = something
  a3 = 0 or 1   or    true or false    (depending on semantics)

then calculate what you now call a2:
  a2 = 2*a1 + a3

Edward


At 10:36 AM 2/15/2006, Kevin Ruland wrote:
Hi all,

We have a number of actors which require certain conditions to be satisfied by attributes as a collection. For sake of example, suppose we have two attributes a1, a2 which are integers. And the following conditions must hold:

a1 = 1 <=> a2 = 1, 2
a1 = 2 <=> a2 = 3, 4

You get the idea.

Now suppose the user selects configure actor and sees:

a1:  1
a2:  2

And wants to configure the actor to be:

a1: 2
a2: 4

If I do all the validation in the attributeChanged method such as this:

public void attributeChanged(Attribute attribute) throws IllegalActionException {
       int a1val;
       int a2val;
       if ( attribute.equals(_a1) || attribute.equals(_a2) ) {
           try {
               a1val = Integer.parseInt( _a1.getExpression() );
               a2val = Integer.parseInt( _a2.getExpression() );
           } catch (NumberFormatException e ) {
               throw new IllegalActionException("Invalid Number");
           }

           switch (a1val) {
           case 1:
               if ( a2val != 1 && a2val != 2 ) {
                   throw new IllegalActionException("invalid values");
               }
               break;
           case 2:
               if ( a2val != 3 && a2val != 4 ) {
                   throw new IllegalActionException("invalid values");
               }
               break;
           default:
               throw new IllegalActionException("invalid values");
           }

       }
       super.attributeChanged(attribute);
   }


With this code in place I was actually able to convince the actor to move to the proper state but only by judiciously "ok"-ing the error dialog. In fact, by abusing the error dialog I was even able to move the actor into a completely invalid configuration.

Is there a better place to do this validation -- I'm hoping for notification from the "commit" button instead of in preinitialize/initialize. For this simple example, I could perhaps change the

Thanks for the help.

Kevin

----------------------------------------------------------------------------
Posted to the ptolemy-hackers mailing list.  Please send administrative
mail for this list to: [EMAIL PROTECTED]

------------
Edward A. Lee
Professor, Chair of the EE Division, Associate Chair of EECS
231 Cory Hall, UC Berkeley, Berkeley, CA 94720
phone: 510-642-0253 or 510-642-0455, fax: 510-642-2845
[EMAIL PROTECTED], http://ptolemy.eecs.berkeley.edu/~eal

----------------------------------------------------------------------------
Posted to the ptolemy-hackers mailing list.  Please send administrative
mail for this list to: [EMAIL PROTECTED]

Reply via email to