Diff for /loncom/interface/lonnavmaps.pm between versions 1.96 and 1.97

version 1.96, 2002/11/01 19:50:00 version 1.97, 2002/11/03 21:05:03
Line 1290  sub new_handle { Line 1290  sub new_handle {
                 }                  }
   
                 $r->print("  $curMarkerBegin<a href=\"$link\">$title$partLabel</a> $curMarkerEnd $nonLinkedText");                  $r->print("  $curMarkerBegin<a href=\"$link\">$title$partLabel</a> $curMarkerEnd $nonLinkedText");
                   $r->print(" TDV:" . $curRes->{DATA}->{TOP_DOWN_VAL}); # temp
                   $r->print(" BUV:" . $curRes->{DATA}->{BOT_UP_VAL}); # temp
                   $r->print(" DD:" . $curRes->{DATA}->{DISPLAY_DEPTH}); # temp
   
                 if ($curRes->{RESOURCE_ERROR}) {                  if ($curRes->{RESOURCE_ERROR}) {
                     $r->print(&Apache::loncommon::help_open_topic ("Navmap_Host_Down",                      $r->print(&Apache::loncommon::help_open_topic ("Navmap_Host_Down",
Line 2066  sub new { Line 2069  sub new {
     # Now, we need to pre-process the map, by walking forward and backward      # Now, we need to pre-process the map, by walking forward and backward
     # over the parts of the map we're going to look at.      # over the parts of the map we're going to look at.
   
     my $forwardIterator = Apache::lonnavmaps::DFSiterator->new($self->{NAV_MAP},       # The processing steps are exactly the same, except for a few small 
                                                                $self->{FIRST_RESOURCE},      # changes, so I bundle those up in the following list of two elements:
                                                                $self->{FINISH_RESOURCE},      # (direction_to_iterate, VAL_name, next_resource_method_to_call,
                                                                $self->{FILTER},      # first_resource).
                                                                undef, $self->{CONDITION},      # This prevents writing nearly-identical code twice.
                                                                FORWARD());      my @iterations = ( [FORWARD(), 'TOP_DOWN_VAL', 'getNext', 
                           'FIRST_RESOURCE'],
                          [BACKWARD(), 'BOT_UP_VAL', 'getPrevious', 
                           'FINISH_RESOURCE'] );
   
       foreach my $pass (@iterations) {
           my $direction = $pass->[0];
           my $valName = $pass->[1];
           my $nextResourceMethod = $pass->[2];
           my $firstResourceName = $pass->[3];
   
           my $iterator = Apache::lonnavmaps::DFSiterator->new($self->{NAV_MAP}, 
                                                               $self->{FIRST_RESOURCE},
                                                               $self->{FINISH_RESOURCE},
                                                               {}, undef, 0, $direction);
           
     # prime the recursion          # prime the recursion
     $self->{FIRST_RESOURCE}->{DATA}->{TOP_DOWN_VAL} = 0;          $self->{$firstResourceName}->{DATA}->{$valName} = 0;
     my $depth = 1;          my $depth = 1;
     $forwardIterator->next();          $iterator->next();
     my $curRes = $forwardIterator->next();          my $curRes = $iterator->next();
     while ($depth > 0) {          while ($depth > 0) {
         if ($curRes == $forwardIterator->BEGIN_MAP()) { $depth++; }              if ($curRes == $iterator->BEGIN_MAP()) { $depth++; }
         if ($curRes == $forwardIterator->END_MAP()) { $depth--; }              if ($curRes == $iterator->END_MAP()) { $depth--; }
                   
         if (ref($curRes)) {              if (ref($curRes)) {
             my $topDownVal = $curRes->{DATA}->{TOP_DOWN_VAL};                  my $resultingVal = $curRes->{DATA}->{$valName};
             my $nextResources = $curRes->getNext();                  my $nextResources = $curRes->$nextResourceMethod();
             my $resourceCount = scalar(@{$nextResources});                  my $resourceCount = scalar(@{$nextResources});
                           
             if ($resourceCount == 1) {                  if ($resourceCount == 1) {
                 my $current = $nextResources->[0]->{DATA}->{TOP_DOWN_VAL} || 999999999;                      my $current = $nextResources->[0]->{DATA}->{$valName} || 999999999;
                 $nextResources->[0]->{DATA}->{TOP_DOWN_VAL} = min($topDownVal, $current);                      $nextResources->[0]->{DATA}->{$valName} = min($resultingVal, $current);
                   }
                   
                   if ($resourceCount > 1) {
                       foreach my $res (@{$nextResources}) {
                           my $current = $res->{DATA}->{$valName} || 999999999;
                           $res->{DATA}->{$valName} = min($current, $resultingVal + 1);
                       }
                   }
               }
               if (ref($curRes) && $curRes->is_map() && $direction == FORWARD()) {
                   my $firstResource = $curRes->map_start();
                   my $finishResource = $curRes->map_finish();
                   my $newIterator = Apache::lonnavmaps::iterator->new($self->{NAV_MAP},
                                                                       $firstResource,
                                                                       $finishResource,
                                                                       $self->{FILTER},
                                                                       $self->{ALREADY_SEEN},
                                                                       $self->{CONDITION});
             }              }
                           
             if ($resourceCount > 1) {              # Assign the final val
                 foreach my $res (@{$nextResources}) {              if (ref($curRes) && $direction == BACKWARD()) {
                     my $current = $res->{DATA}->{TOP_DOWN_VAL} || 999999999;                  $curRes->{DATA}->{DISPLAY_DEPTH} = min($curRes->{DATA}->{TOP_DOWN_VAL},
                     $res->{DATA}->{TOP_DOWN_VAL} = min($current, $topDownVal + 1);                                                         $curRes->{DATA}->{BOT_UP_VAL});
                 }  
             }              }
               $curRes = $iterator->next();
         }          }
         $curRes = $forwardIterator->next();  
     }      }
   
     # Now we're ready to start iterating.      # Now we're ready to start iterating.
Line 2115  package Apache::lonnavmaps::DFSiterator; Line 2149  package Apache::lonnavmaps::DFSiterator;
 # used by the main iterator for pre-processing. It also is able to isolate  # used by the main iterator for pre-processing. It also is able to isolate
 # much of the complexity of the main iterator, so the main iterator is much  # much of the complexity of the main iterator, so the main iterator is much
 # simpler.  # simpler.
   # There is no real benefit in merging the main iterator and this one into one class...
   # all the logic in DFSiterator would need to be replicated, you gain no performance,
   # at best, you just make one massively complicated iterator in place of two 
   # somewhat complicated ones. ;-) - Jeremy
   
 # Here are the tokens for the iterator, replicated from iterator for convenience:  # Here are the tokens for the iterator, replicated from iterator for convenience:
   

Removed from v.1.96  
changed lines
  Added in v.1.97


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>