OPeNDAP Hyrax Back End Server (BES)  Updated for version 3.8.3
WWWGrid.cc
Go to the documentation of this file.
1 
2 // -*- mode: c++; c-basic-offset:4 -*-
3 
4 // This file is part of www_int, software which returns an HTML form which
5 // can be used to build a URL to access data from a DAP data server.
6 
7 // Copyright (c) 2002,2003 OPeNDAP, Inc.
8 // Author: James Gallagher <jgallagher@opendap.org>
9 //
10 // This library is free software; you can redistribute it and/or
11 // modify it under the terms of the GNU Lesser General Public
12 // License as published by the Free Software Foundation; either
13 // version 2.1 of the License, or (at your option) any later version.
14 //
15 // This library is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public
21 // License along with this library; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 //
24 // You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
25 
26 // (c) COPYRIGHT URI/MIT 1999
27 // Please read the full copyright statement in the file COPYRIGHT_URI.
28 //
29 // Authors:
30 // jhrg,jimg James Gallagher <jgallagher@gso.uri.edu>
31 
32 // implementation for WWWGrid. See WWWByte.
33 //
34 // 4/7/99 jhrg
35 
36 #include "config.h"
37 
38 static char rcsid[] not_used =
39  { "$Id$" };
40 
41 #include <assert.h>
42 #include <iostream>
43 #include <sstream>
44 #include <string>
45 
46 #include "Array.h"
47 #include "escaping.h"
48 #include "InternalErr.h"
49 
50 #include "WWWGrid.h"
51 #include "WWWOutput.h"
52 #include "get_html_form.h"
53 
54 using namespace dap_html_form;
55 
57 {
58  return new WWWGrid(*this);
59 }
60 
61 WWWGrid::WWWGrid(const string & n) : Grid(n)
62 {
63 }
64 
65 WWWGrid::WWWGrid(Grid * grid): Grid(grid->name())
66 {
67  BaseType *bt = basetype_to_wwwtype(grid->array_var());
68  bt->set_attr_table(grid->array_var()->get_attr_table());
69  add_var(bt, array);
70  delete bt;
71 
72  Grid::Map_iter i = grid->map_begin();
73  Grid::Map_iter e = grid->map_end();
74  while ( i != e ) {
75  Array *at = dynamic_cast<Array *>(basetype_to_wwwtype(*i));
76  at->set_attr_table((*i)->get_attr_table());
77  add_var(at, maps);
78  delete at;
79  ++i;
80  }
81 }
82 
83 
85 {
86 }
87 
88 void
89 WWWGrid::do_print_val(ostream &ss)
90 {
91  const string fqn = get_fqn(this);
92  ss << "<script type=\"text/javascript\">\n"
93  << "<!--\n"
94  << name_for_js_code(fqn) << " = new dods_var(\""
95  << id2www_ce(fqn)
96  << "\", \"" << name_for_js_code(fqn) << "\", 1);\n"
97  << "DODS_URL.add_dods_var(" << name_for_js_code(fqn) << ");\n"
98  << "// -->\n" << "</script>\n";
99 
100  ss << "<b>"
101  << "<input type=\"checkbox\" name=\"get_" <<
102  name_for_js_code(fqn)
103  << "\"\n" << "onclick=\"" << name_for_js_code(fqn)
104  << ".handle_projection_change(get_"
105  << name_for_js_code(fqn) << ") \" onfocus=\"describe_projection()\">\n"
106  << "<font size=\"+1\">" << name() << "</font></b>"
107  << ": " << fancy_typename(this) << "<br>\n\n";
108 
109  Array *a = dynamic_cast < Array * >(array_var());
110 
111  Array::Dim_iter p = a->dim_begin();
112  for (int i = 0; p != a->dim_end(); ++i, ++p) {
113  const int size = a->dimension_size(p, true);
114  const string n = a->dimension_name(p);
115  if (n != "")
116  ss << n << ":";
117  ss << "<input type=\"text\" name=\"" << name_for_js_code(fqn)
118  << "_" << i
119  << "\" size=8 onfocus=\"describe_index()\""
120  << "onChange=\"DODS_URL.update_url()\">\n";
121  ss << "<script type=\"text/javascript\">\n"
122  << "<!--\n"
123  << name_for_js_code(fqn) << ".add_dim(" << size << ");\n"
124  << "// -->\n" << "</script>\n";
125  }
126 
127  ss << "<br>\n";
128 }
129 
130 void
131 WWWGrid::print_val(FILE * os, string /*space*/, bool /*print_decl_p*/)
132 {
133  ostringstream ss ;
134  do_print_val( ss ) ;
135  fprintf(os, "%s", ss.str().c_str());
136 }
137 
138 void
139 WWWGrid::print_val(ostream &strm, string /*space*/, bool /*print_decl_p*/)
140 {
141  do_print_val(strm);
142 }
143 
#define not_used
Definition: config.h:315
BaseType * basetype_to_wwwtype(BaseType *bt)
Given a BaseType variable, return a pointer to a new variable that has the same parent types (Byte...
virtual ~WWWGrid()
Definition: WWWGrid.cc:84
virtual void print_val(FILE *os, string space="", bool print_decl_p=true)
Definition: WWWGrid.cc:131
string get_fqn(BaseType *var)
Get the Fully Qualified Name for a variable.
string fancy_typename(BaseType *v)
Return a string which describes the datatype of a DODS variable.
WWWGrid(const string &n)
Definition: WWWGrid.cc:61
virtual BaseType * ptr_duplicate()
Definition: WWWGrid.cc:56
string name_for_js_code(const string &dods_name)
Generate variable names to be used by the JavaScript code.