## WeBWorK Problems

### GeoGebra Object Listerner

by Eric Gilson -
Number of replies: 1
In looking through the GeoGebra applet examples I came across an automated checking example for constructions. I was playing around with trying to embed this problem in a WeBWork question, but I can't figure out how to make it work right. My goal is to create a selection of construction problems for the Euclidean Geometry section of a course I teach.

In tinkering with the code, it seems like the applet listener for the addition of objects in GeoGebra is not triggering properly. I am not sure what I need to do get this to trigger. I looked though the OPL questions using GeoGebra and didn't find any with an object listener, so I was just operating off the template on the wiki.

Here is my code:

## DESCRIPTION
## Using a GeoGebra applet to check a basic Geometric Construction
## ENDDESCRIPTION

## DBsubject()
## DBchapter()
## DBsection()
## Date(07/01/2015)
## Institution(Park School of Baltimore)
## Author(Eric Gilson)
## MO()
## KEYWORDS('GeoGebra applet')

DOCUMENT();
"PGstandard.pl",
"MathObjects.pl",
"AppletObjects.pl",
"unionTables.pl",
"PGcourse.pl",
);

TEXT(beginproblem());

$showPartialCorrectAnswers = 1; ########################################## # Setup # This problem is entirely contained in GeoGebra. # No additional setup is needed Context("Point"); ###################################### # Create link to applet: ################################### # You can name your applet (anything reasonable :-) ) # Adjust the height and width as desired # Paste the geogebra parameters in at the bottom of the page just above the # command end command # so that they don't get in the way ###################################$appletName = "ggbfoo";

$applet = GeogebraWebApplet( code => "geogebra.GeoGebraApplet", archive => "geogebra.jar", codebase => findAppletCodebase("geogebra.jar"), appletName =>$appletName,
appletId => $appletName, submitActionAlias => 'getAppletValues', # default actionAlias initializeActionAlias => 'configure', # default actionAlias setStateAlias => 'setXML', getStateAlias => 'getXML', setConfigAlias => '', getConfigAlias => '', returnFieldName => '', width => 700, # may want to modify width height => 500, # may want to modify height mayscript => "true", debugMode => 0, # set debugMode to 0 for no debug # to 1 to make xml representation visible # to 2 to add alerts detailing progression # through the applet onInit => 'ggbOnInit', type => 'geogebraweb', #submitActionScript => qq{ getQE('answerBox').value = getAppletValues() }, submitActionScript => '', selfLoading => 1, params => GEOGEBRA_PARAMS(),# paste parameters in ); ############################################### # # PNG picture of GeoGebra applet for hardcopy #$im = image( "AF7-c".$c."-d".$d.".png", width=>486, height=>335, tex_size=>900 );

##################################
# Setup GeogebraWebApplet --
###################################

###############################################
#
# For persistence of GeoGebra applet state
# when answers are submitted or page is refreshed.
# Uses JavaScript interface to GeoGebra.

qq!
<script language="javascript">
function ggbOnInit(param) {
if (param == "$appletName") { applet_loaded(param,1); // report that applet is ready. ww_applet_list[param].safe_applet_initialize(2); } var applet=getApplet("$appletName");

}
</script>
<noscript>For this question to work properly,
you must enable JavaScript, or use another browser
(or computer) on which JavaScript works.</noscript>
!);

#######################################################
#
# For setting initial values in GeoGebra from WeBWorK
# Uses JavaScript interface to GeoGebra.

TEXT( MODES(TeX=>'', HTML=><<END_SCRIPT ) );
<script language="javascript">
var applet=getApplet("$appletName"); function setAppletCoefficients() { // alert("Updating coefficients"); if (typeof(applet)!="undefined") { if (typeof(applet.setValue)!="undefined") { //////////////////////////////////////////////////////////////// // List the values of the parameters to be set in the applet here } } else { setTimeout("setAppletCoefficients()", 1000); } } else { setTimeout("setAppletCoefficients()",1000); } } ww_applet_list["$appletName"].setConfig = function() {setAppletCoefficients()};

function newObjectListener (obj) {
if (obj != "finished") {
var cmd = "finished = ("+obj+"== target)";
applet.debug(cmd);
applet.evalCommand(cmd);
finished = applet.getValueString("finished");
if (finished.indexOf("true") > -1) {
applet.setVisible("wellDone",true);
}
}
}
</script>
END_SCRIPT

###################################
#insert applet into body -- this does not need to be changed
# except to adjust the insertion of the reinitialize_button or
###################################
# TEXT($PAR, MODES(TeX=>'geogebraweb code', # HTML=>$applet->insertAll(
# debug =>0,
# reinitialize_button => 1,
# )));

#######################################
# TEXT
#######################################
Context()->texStrings;
BEGIN_TEXT

$BCENTER Construct the midpoint of the points $$A$$ and $$B$$.$PAR
\{
MODES(HTML=>$applet->insertAll(debug=>0, reinitialize_button=>1, includeAnswerBox=>0,), TeX=>$im)
\}
$ECENTER END_TEXT Context()->normalStrings; ######################################### # ANSWER section ######################################### TEXT( MODES(TeX=>'', HTML=><<END_SCRIPT ) ); <script language="javascript"> var applet=getApplet("$appletName");

function newObjectListener (obj) {
if (obj != "finished") {
var cmd = "finished = ("+obj+"== target)";
applet.debug(cmd);
applet.evalCommand(cmd);
finished = applet.getValueString("finished");
if (finished.indexOf("true") > -1) {
applet.setVisible("wellDone",true);
}
}
</script>
END_SCRIPT

#########################################
# The applet as a base64 string
#########################################

sub GEOGEBRA_PARAMS {
my $result = { showToolBar=>"true", CustomToolbar=>" 1 | 5 | 2 | 10 | 15 | 6 | 40 41 42", ggbbase64=>"UEsDBBQACAAIACOcdDsAAAAAAAAAAAAAAAAWAAAAZ2VvZ2VicmFfamF2YXNjcmlwdC5qc2WQQWvDMAyF7/kVmk4O3Qo7hwxKdxkMchjsHseyp+IoxXHawch/n92SNdtusr/3nh6yk3SRBwHndCMvwlGV8FWk1+549BS3hvTkFP5gLKsVDeR4jBR2xrzmQSgoFDo3+kBdXL6yZy4Ku+z6JwA16EPey/Yywl0NaFl4/CCDGQCc2gBdb2BF0qxwk/QbrGuIbXAUS6yS+G//ZCwr+AXo1Pr90PetmCtOdBV8E6bQ99ZP9BYDSzrFrVe25MbLz5bF0GdjFcYwUer9BA+P1/brzWMK5JG1J4Vn8v55EML7bLkkzvlWc/ENUEsHCOySBgHmAAAAmgEAAFBLAwQUAAgACAAjnHQ7AAAAAAAAAAAAAAAADAAAAGdlb2dlYnJhLnhtbN1XS2/jNhA+e3/FQIeedm09/ERlLxL3UqApFnAfQG+UNLbZUKJKUX4s8uM7JCVLzia7bTaLAj045JDDeXzzDanE70+5gAOqisti6QVD3wMsUpnxYrf0ar19N/fer97EO5Q7TBSDrVQ500svGkaeWa/56s0gPvIik0c48kzvl95iHniwR77bk+JsHHkwWg3ikpyUmGp+wIpO9kTg2dLTeekZUyUrzP7AzUDIlGkbmwcZP/AM1dLzh6EfzWfRZDGPpgs/CEIPpOJY6EY3MC7J2Ki1Fh84Hp1ZM7MeSenAK54IJO+qRg94sVUsJ3HLREVy55x0K/6R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ZQSwcIksbgcCcEAAD/DQAAUEsBAhQAFAAIAAgAI5x0O+ySBgHmAAAAmgEAABYAAAAAAAAAAAAAAAAAAAAAAGdlb2dlYnJhX2phdmFzY3JpcHQuanNQSwECFAAUAAgACAAjnHQ7ksbgcCcEAAD/DQAADAAAAAAAAAAAAAAAAAAqAQAAZ2VvZ2VicmEueG1sUEsFBgAAAAACAAIAfgAAAIsFAAAAAA==" };$result;
}

COMMENT('Uses GeoGebraWeb (JavaScript), so it should work on computers and tablets.');

ENDDOCUMENT();

### Re: GeoGebra Object Listerner

by Alex Jordan -
GeoGebra has evolved a lot since most existing GeoGebra-WeBWorK documentation was built. You can avoid Java altogether and use HTML5, if that will be OK for your students' browsers. So I believe there are now far simpler ways to bring GeoGebra into a WeBWorK problem. Here is an outline.
1. Make the .ggb file in GeoGebra, or find something you like at GeoGebraTube.
2. If you made one yourself, either upload it to GeoGebra, or export it as an interactive html5 webpage. When exporting, you can go into advanced options to specify that you want to export for HTML5 only.
3. Have your PG problem either
1. use the embed code from GeoGebraTube;
2. or upload your interactive html5 webpage to the appropriate folder in your WeBWorK server/course. Copy the structure of GeoGebraTube embed code, but replace the src with the path to your html file.

You output this way in HTML mode. For hardcopy, you would create static image files as I think existing examples demonstrate, and apply that for TeX output mode.

Sorry for not offering details, but I haven't actually tried this yet in WeBWorK. I have however embedded HTML5 GeoGebra into other web pages these ways, and it is much more clean than the older Java applet.