bes  Updated for version 3.20.6
WWWGrid.cc
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 
56 BaseType *WWWGrid::ptr_duplicate()
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, libdap::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 
84 WWWGrid::~WWWGrid()
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  if (!a) throw InternalErr(__FILE__, __LINE__, "Expected an Array");
111 
112  Array::Dim_iter p = a->dim_begin();
113  for (int i = 0; p != a->dim_end(); ++i, ++p) {
114  const int size = a->dimension_size(p, true);
115  const string n = a->dimension_name(p);
116  if (n != "")
117  ss << n << ":";
118  ss << "<input type=\"text\" name=\"" << name_for_js_code(fqn)
119  << "_" << i
120  << "\" size=8 onfocus=\"describe_index()\""
121  << "onChange=\"DODS_URL.update_url()\">\n";
122  ss << "<script type=\"text/javascript\">\n"
123  << "<!--\n"
124  << name_for_js_code(fqn) << ".add_dim(" << size << ");\n"
125  << "// -->\n" << "</script>\n";
126  }
127 
128  ss << "<br>\n";
129 }
130 
131 void
132 WWWGrid::print_val(FILE * os, string /*space*/, bool /*print_decl_p*/)
133 {
134  ostringstream ss ;
135  do_print_val( ss ) ;
136  fprintf(os, "%s", ss.str().c_str());
137 }
138 
139 void
140 WWWGrid::print_val(ostream &strm, string /*space*/, bool /*print_decl_p*/)
141 {
142  do_print_val(strm);
143 }
144 
WWWGrid
Definition: WWWGrid.h:43