[system] / branches / rel-2-4-patches / webwork-modperl / lib / WeBWorK / PG.pm Repository:
ViewVC logotype

Diff of /branches/rel-2-4-patches/webwork-modperl/lib/WeBWorK/PG.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1144 Revision 1154
12=cut 12=cut
13 13
14use strict; 14use strict;
15use warnings; 15use warnings;
16use File::Path qw(rmtree); 16use File::Path qw(rmtree);
17use WeBWorK::PG::ImageGenerator;
17use WeBWorK::PG::Translator; 18use WeBWorK::PG::Translator;
18use WeBWorK::Utils qw(readFile formatDateTime writeTimingLogEntry makeTempDirectory); 19use WeBWorK::Utils qw(readFile formatDateTime writeTimingLogEntry makeTempDirectory);
19 20
20sub new($$$$$$$$) { 21sub new($$$$$$$$) {
21 my $invocant = shift; 22 my $invocant = shift;
136 137
137 # translate the PG source into text 138 # translate the PG source into text
138 #warn "PG: translating the PG source into text\n"; 139 #warn "PG: translating the PG source into text\n";
139 $translator->translate(); 140 $translator->translate();
140 141
141 # after we're done translating, we may have to clean up after the translator. 142 # after we're done translating, we may have to clean up after the
143 # translator:
144
142 # for example, 'images' mode uses a tempdir for dvipng's temp files. We have 145 # for example, HTML_img mode uses a tempdir for dvipng's temp files.\
143 # to remove it. 146 # We have to remove it.
144 if ($translationOptions->{displayMode} eq 'images' && $envir->{dvipngTempDir}) { 147 if ($envir->{dvipngTempDir}) {
145 rmtree($envir->{dvipngTempDir}, 0, 0); 148 rmtree($envir->{dvipngTempDir}, 0, 0);
149 }
150
151 # HTML_dpng, on the other hand, uses an ImageGenerator. We have to
152 # render the queued equations.
153 if ($envir->{imagegen}) {
154 my $sourceFile = $courseEnv->{courseDirs}->{templates} . "/" . $problem->source_file;
155 my %mtimeOption = -e $sourceFile
156 ? (mtime => (stat $sourceFile)[9])
157 : ();
158
159 $envir->{imagegen}->render(
160 refresh => $translationOptions->{refreshMath2img},
161 %mtimeOption,
162 );
146 } 163 }
147 164
148 my ($result, $state); # we'll need these on the other side of the if block! 165 my ($result, $state); # we'll need these on the other side of the if block!
149 if ($translationOptions->{processAnswers}) { 166 if ($translationOptions->{processAnswers}) {
150 167
225 $options, 242 $options,
226 ) = @_; 243 ) = @_;
227 244
228 my %envir; 245 my %envir;
229 246
247 # ----------------------------------------------------------------------
248
230 # PG environment variables 249 # PG environment variables
231 # from docs/pglanguage/pgreference/environmentvariables as of 06/25/2002 250 # from docs/pglanguage/pgreference/environmentvariables as of 06/25/2002
232 # any changes are noted by "ADDED:" or "REMOVED:" 251 # any changes are noted by "ADDED:" or "REMOVED:"
233 252
234 # Vital state information 253 # Vital state information
245 $envir{displayMode} = translateDisplayModeNames($options->{displayMode}); 264 $envir{displayMode} = translateDisplayModeNames($options->{displayMode});
246 $envir{languageMode} = $envir{displayMode}; 265 $envir{languageMode} = $envir{displayMode};
247 $envir{outputMode} = $envir{displayMode}; 266 $envir{outputMode} = $envir{displayMode};
248 $envir{displayHintsQ} = $options->{showHints}; 267 $envir{displayHintsQ} = $options->{showHints};
249 $envir{displaySolutionsQ} = $options->{showSolutions}; 268 $envir{displaySolutionsQ} = $options->{showSolutions};
269 # FIXME: this is HTML_img specific
250 $envir{refreshMath2img} = $options->{refreshMath2img}; 270 #$envir{refreshMath2img} = $options->{refreshMath2img};
251 $envir{texDisposition} = "pdf"; # in webwork-modperl, we use pdflatex 271 $envir{texDisposition} = "pdf"; # in webwork-modperl, we use pdflatex
252 272
253 # Problem Information 273 # Problem Information
254 # ADDED: courseName, formatedDueDate 274 # ADDED: courseName, formatedDueDate
255 275
307 $envir{templateDirectory} = $courseEnv->{courseDirs}->{templates}."/"; 327 $envir{templateDirectory} = $courseEnv->{courseDirs}->{templates}."/";
308 $envir{tempDirectory} = $courseEnv->{courseDirs}->{html_temp}."/"; 328 $envir{tempDirectory} = $courseEnv->{courseDirs}->{html_temp}."/";
309 $envir{tempURL} = $courseEnv->{courseURLs}->{html_temp}."/"; 329 $envir{tempURL} = $courseEnv->{courseURLs}->{html_temp}."/";
310 $envir{scriptDirectory} = undef; 330 $envir{scriptDirectory} = undef;
311 $envir{webworkDocsURL} = $courseEnv->{webworkURLs}->{docs}."/"; 331 $envir{webworkDocsURL} = $courseEnv->{webworkURLs}->{docs}."/";
332 # FIXME: this is HTML_img mode-specific
312 $envir{dvipngTempDir} = $options->{displayMode} eq 'images' 333 #$envir{dvipngTempDir} = $options->{displayMode} eq 'images'
313 ? makeTempDirectory($envir{tempDirectory}, "webwork-dvipng") 334 # ? makeTempDirectory($envir{tempDirectory}, "webwork-dvipng")
314 : undef; 335 # : undef;
315 336
316 # Information for sending mail 337 # Information for sending mail
317 338
318 $envir{mailSmtpServer} = $courseEnv->{mail}->{smtpServer}; 339 $envir{mailSmtpServer} = $courseEnv->{mail}->{smtpServer};
319 $envir{mailSmtpSender} = $courseEnv->{mail}->{smtpSender}; 340 $envir{mailSmtpSender} = $courseEnv->{mail}->{smtpSender};
322 # Default values for evaluating answers 343 # Default values for evaluating answers
323 344
324 my $ansEvalDefaults = $courseEnv->{pg}->{ansEvalDefaults}; 345 my $ansEvalDefaults = $courseEnv->{pg}->{ansEvalDefaults};
325 $envir{$_} = $ansEvalDefaults->{$_} foreach (keys %$ansEvalDefaults); 346 $envir{$_} = $ansEvalDefaults->{$_} foreach (keys %$ansEvalDefaults);
326 347
348 # ----------------------------------------------------------------------
349
350 # Object for generating equation images
351 $envir{imagegen} = WeBWorK::PG::ImageGenerator->new(
352 tempDir => $courseEnv->{webworkDirs}->{tmp}, # global temp dir
353 dir => $envir{tempDirectory},
354 url => $envir{tempURL},
355 #basename => "$envir{studentLogin}.$envir{setNumber}.$envir{probNum}",
356 basename => "equation-$envir{psvn}.$envir{probNum}.$envir{problemSeed}",
357 latex => $envir{externalLaTeXPath},
358 dvipng => $envir{externalDvipngPath},
359 );
360
327 # Other things... 361 # Other things...
328 $envir{QUIZ_PREFIX} = $options->{QUIZ_PREFIX}; #used by quizzes 362 $envir{QUIZ_PREFIX} = $options->{QUIZ_PREFIX}; # used by quizzes
329 $envir{PROBLEM_GRADER_TO_USE} = $courseEnv->{pg}->{options}->{grader}; 363 $envir{PROBLEM_GRADER_TO_USE} = $courseEnv->{pg}->{options}->{grader};
330
331 $envir{PRINT_FILE_NAMES_FOR} = $courseEnv->{pg}->{specialPGEnvironmentVars}->{PRINT_FILE_NAMES_FOR}; 364 $envir{PRINT_FILE_NAMES_FOR} = $courseEnv->{pg}->{specialPGEnvironmentVars}->{PRINT_FILE_NAMES_FOR};
332 365
333 # variables for interpreting capa problems. 366 # variables for interpreting capa problems.
334 $envir{CAPA_Tools} = $courseEnv->{pg}->{specialPGEnvironmentVars}->{CAPA_Tools}; 367 $envir{CAPA_Tools} = $courseEnv->{pg}->{specialPGEnvironmentVars}->{CAPA_Tools};
335 $envir{CAPA_MCTools} = $courseEnv->{pg}->{specialPGEnvironmentVars}->{CAPA_MCTools}; 368 $envir{CAPA_MCTools} = $courseEnv->{pg}->{specialPGEnvironmentVars}->{CAPA_MCTools};
343 my $name = shift; 376 my $name = shift;
344 return { 377 return {
345 tex => "TeX", 378 tex => "TeX",
346 plainText => "HTML", 379 plainText => "HTML",
347 formattedText => "HTML_tth", 380 formattedText => "HTML_tth",
348 images => "HTML_img" 381 images => "HTML_dpng", # "HTML_img",
349 }->{$name}; 382 }->{$name};
350} 383}
351 384
352sub safetyFilter { 385sub safetyFilter {
353 my $answer = shift; # accepts one answer and checks it 386 my $answer = shift; # accepts one answer and checks it
480boolean, render solutions 513boolean, render solutions
481 514
482=item refreshMath2img 515=item refreshMath2img
483 516
484boolean, force images created by math2img (in "images" mode) to be recreated, 517boolean, force images created by math2img (in "images" mode) to be recreated,
485even if the PG source has not been updated. 518even if the PG source has not been updated. FIXME: change the name of this
519option to "refreshEquations" and update the docs accordingly.
486 520
487=item processAnswers 521=item processAnswers
488 522
489boolean, call answer evaluators and graders 523boolean, call answer evaluators and graders
490 524

Legend:
Removed from v.1144  
changed lines
  Added in v.1154

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9