[LON-CAPA-cvs] cvs: loncom /homework functionplotresponse.pm

www www at source.lon-capa.org
Tue Feb 28 20:46:52 EST 2012


www		Wed Feb 29 01:46:52 2012 EDT

  Modified files:              
    /loncom/homework	functionplotresponse.pm 
  Log:
  Add some robustness: give warning if labels are used multiple times or before being defined.
  
  
Index: loncom/homework/functionplotresponse.pm
diff -u loncom/homework/functionplotresponse.pm:1.94 loncom/homework/functionplotresponse.pm:1.95
--- loncom/homework/functionplotresponse.pm:1.94	Wed Feb 29 01:24:47 2012
+++ loncom/homework/functionplotresponse.pm	Wed Feb 29 01:46:52 2012
@@ -1,7 +1,7 @@
 # LearningOnline Network with CAPA
 # Functionplot responses
 #
-# $Id: functionplotresponse.pm,v 1.94 2012/02/29 01:24:47 www Exp $
+# $Id: functionplotresponse.pm,v 1.95 2012/02/29 01:46:52 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -551,6 +551,10 @@
    $label=~s/\W//gs;
    $label=ucfirst($label);
    unless ($label) { $label="NewVector"; }
+   if ($Apache::functionplotresponse::vectorlabels{$label}) {
+       &Apache::lonxml::warning(&mt('Vector labels must be unique: [_1]',$label));
+   }
+   $Apache::functionplotresponse::vectorlabels{$label}=1;
    if ($target eq 'web') {
       my ($xmin,$xmax,$ymin,$ymax)=&boundaries($parstack,$safeeval,-3);
       unless (defined($tailx)) { $tailx=$xmin; }
@@ -621,6 +625,10 @@
                 $thisvector=~s/\W//gs;
                 $thisvector=ucfirst($thisvector);
                 unless ($thisvector) { next; }
+                unless ($Apache::functionplotresponse::vectorlabels{$thisvector}) {
+                    &Apache::lonxml::warning(&mt('Vectors must be defined before using them for drawing vector sums: [_1]',$thisvector));
+                    next;
+                }
                 my $vectorx=$thisvector.'X';
                 my $vectory=$thisvector.'Y';
                 $result.=(<<ENDADDVEC);
@@ -1304,6 +1312,8 @@
   undef %Apache::functionplotresponse::previous;
   $Apache::functionplotresponse::inputfields='';
   $Apache::functionplotresponse::counter=0;
+# Remember vectors
+  undef %Apache::functionplotresponse::vectorlabels;
 # Remember rules
   undef @Apache::functionplotresponse::functionplotrules;
   undef @Apache::functionplotresponse::functionplotvectorrules;




More information about the LON-CAPA-cvs mailing list