1
/* -*- Mode: JavaScript; coding: utf-8; tab-width: 3; indent-tabs-mode: tab; c-basic-offset: 3 -*-
2
*******************************************************************************
4
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6
* Copyright create3000, Scheffelstraße 31a, Leipzig, Germany 2011.
8
* All rights reserved. Holger Seelig <holger.seelig@yahoo.de>.
10
* The copyright notice above does not evidence any actual of intended
11
* publication of such source code, and is an unpublished work by create3000.
12
* This material contains CONFIDENTIAL INFORMATION that is the property of
15
* No permission is granted to copy, distribute, or create derivative works from
16
* the contents of this software, in whole or in part, without the prior written
17
* permission of create3000.
19
* NON-MILITARY USE ONLY
21
* All create3000 software are effectively free software with a non-military use
22
* restriction. It is free. Well commented source is provided. You may reuse the
23
* source in any way you please with the exception anything that uses it must be
24
* marked to indicate is contains 'non-military use only' components.
26
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
28
* Copyright 2015, 2016 Holger Seelig <holger.seelig@yahoo.de>.
30
* This file is part of the Cobweb Project.
32
* Cobweb is free software: you can redistribute it and/or modify it under the
33
* terms of the GNU General Public License version 3 only, as published by the
34
* Free Software Foundation.
36
* Cobweb is distributed in the hope that it will be useful, but WITHOUT ANY
37
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
38
* A PARTICULAR PURPOSE. See the GNU General Public License version 3 for more
39
* details (a copy is included in the LICENSE file that accompanied this code).
41
* You should have received a copy of the GNU General Public License version 3
42
* along with Cobweb. If not, see <http://www.gnu.org/licenses/gpl.html> for a
43
* copy of the GPLv3 License.
45
* For Silvio, Joy and Adi.
47
******************************************************************************/
52
"cobweb/Basic/X3DField",
53
"cobweb/Bits/X3DConstants",
55
function ($, X3DField, X3DConstants)
61
get: function (target, key)
69
field = target .getValue () .getField (key),
70
accessType = field .getAccessType ();
72
// Specification conform would be: accessType & X3DConstants .outputOnly.
73
// But we allow read access to plain fields, too.
74
if (accessType === X3DConstants .inputOnly)
77
return field .valueOf ();
84
set: function (target, key, value)
95
field = target .getValue () .getField (key),
96
accessType = field .getAccessType ();
98
if (accessType & X3DConstants .inputOnly)
99
field .setValue (value);
105
console .error (target, key, error);
111
function SFNode (value)
113
if (this instanceof SFNode)
117
value .addParent (this);
119
X3DField .call (this, value);
122
X3DField .call (this, null);
124
return new Proxy (this, handler);
127
return SFNode .call (Object .create (SFNode .prototype), value);
130
SFNode .prototype = $.extend (Object .create (X3DField .prototype),
136
return new SFNode (this .getValue ());
138
copy: function (executionContext)
140
var value = this .getValue ();
143
return new SFNode (value .copy (executionContext));
145
return new SFNode ();
147
getTypeName: function ()
153
return X3DConstants .SFNode;
155
equals: function (node)
158
return this .getValue () === node .getValue ();
160
return this .getValue () === null;
162
isDefaultValue: function ()
164
return this .getValue () === null;
166
set: function (value)
168
var current = this .getValue ();
172
current .removeClones (this ._cloneCount);
173
current .removeParent (this);
178
value .addParent (this);
179
value .addClones (this ._cloneCount);
181
X3DField .prototype .set .call (this, value);
184
X3DField .prototype .set .call (this, null);
186
getNodeTypeName: function ()
188
var value = this .getValue ();
191
return value .getTypeName ();
193
throw new Error ("SFNode.getNodeTypeName: node is null.");
195
getNodeName: function ()
197
var value = this .getValue ();
200
return value .getName ();
202
throw new Error ("SFNode.getNodeName: node is null.");
204
getNodeType: function ()
206
var value = this .getValue ();
209
return value .getType () .slice ();
211
throw new Error ("SFNode.getNodeType: node is null.");
213
getFieldDefinitions: function ()
215
var value = this .getValue ();
218
return value .getFieldDefinitions ();
220
throw new Error ("SFNode.getFieldDefinitions: node is null.");
222
addClones: function (count)
224
var value = this .getValue ();
226
this ._cloneCount += count;
229
value .addClones (count);
231
removeClones: function (count)
233
var value = this .getValue ();
235
this ._cloneCount -= count;
238
value .removeClones (count);
242
if (this .getValue ())
247
toString: function ()
249
var node = this .getValue ();
251
return node ? node .toString () : "NULL";
253
toVRMLString: function ()
255
var node = this .getValue ();
257
return node ? node .toVRMLString () : "NULL";
259
toXMLStream: function (stream)
261
var node = this .getValue ();
263
stream .string += node ? node .toXMLString () : "NULL";
269
X3DField .prototype .dispose .call (this);