2
Copyright 2002-2013 Michalis Kamburelis.
4
This file is part of "Castle Game Engine".
6
"Castle Game Engine" is free software; see the file COPYING.txt,
7
included in this distribution, for details about the copyright.
9
"Castle Game Engine" is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
----------------------------------------------------------------------------
16
{$ifdef read_interface}
18
{ Container tracking VRML/X3D node and prototype names during parsing.
19
Used by both classic and XML VRML/X3D readers. }
20
TX3DReaderNames = class(TX3DReader)
22
FNodes: TX3DNodeNames;
23
FPrototypes: TX3DPrototypeNames;
24
FImported: TX3DNodeNames;
25
FExported: TX3DNodeNames;
26
FImportable: TX3DImportableNames;
27
procedure CommonCreate(const AAutoRemoveNodes: boolean);
29
constructor Create(const AAutoRemoveNodes: boolean;
30
const ABaseUrl: string;
31
const AVersion: TX3DVersion);
32
constructor CreateCopy(const AAutoRemoveNodes: boolean;
34
destructor Destroy; override;
36
{ Extract names, before destructing this object.
37
This method can be used only right before calling the destructor.
38
It copies the prototype and exported names list (names visible
39
from the outside), and sets them to @nil (to avoid releasing them
41
procedure ExtractNames(out APrototypes: TX3DPrototypeNames;
42
out AExported: TX3DNodeNames);
44
{ Current namespace for DEF/USE.
46
This is a list without duplicates with all
47
currently known node names. Objects[] of this list point to
48
actual TX3DNode instances. If many instances had the same NodeName,
49
only the last instance will be referenced here, following VRML spec
50
(last DEF takes precedence).
52
Internal notes: ParseNode doesn't modify this, only TX3DNode.Parse
54
property Nodes: TX3DNodeNames read FNodes;
56
{ Current namespace of PROTO names. }
57
property Prototypes: TX3DPrototypeNames read FPrototypes;
59
{ Currently IMPORTed nodes.
61
The nodes on this list are "bound" to their aliases,
62
as this is the name under which they are visible in the current namespace.
63
Alias is the identifier after the "AS" keyword in the "IMPORT" declaration
64
(or, if no "AS xxx" clause was present, then alias is just the name
65
under which node was exported). }
66
property Imported: TX3DNodeNames read FImported;
68
{ Currently EXPORTed nodes from this scene.
70
The nodes on this list are "bound" to their
71
aliases, as this is the name under which they are visible for
72
the outside VRML scenes (that can import these nodes).
73
Alias is the identifier after the "AS" keyword in "EXPORT" declaration
74
(or, if no "AS xxx" clause, then alias is just normal node name). }
75
property Exported: TX3DNodeNames read FExported;
77
{ Currently loaded Inlines with importable nodes.
79
The mechanism is that when you load an Inline node, the resulting
80
"Exported" nodes (from the namespace within the Inline) get added
81
to this "Importable" list. Then the "IMPORT" clause in this
82
namespace can make "Importable" nodes into actually "Imported".
84
This is a list with strings representing Inline node names
85
(there's no way to IMPORT from unnamed Inline nodes).
86
Objects[] of this list are instances of TX3DNodeNames
87
corresponding to exported names within the inline. }
88
property Importable: TX3DImportableNames read FImportable;
90
procedure DoExport(E: TX3DExport);
91
procedure DoImport(I: TX3DImport);
96
{$ifdef read_implementation}
98
{ TX3DReaderNames ----------------------------------------------------------------- }
100
constructor TX3DReaderNames.Create(const AAutoRemoveNodes: boolean;
101
const ABaseUrl: string; const AVersion: TX3DVersion);
103
inherited Create(ABaseUrl, AVersion);
104
CommonCreate(AAutoRemoveNodes);
107
constructor TX3DReaderNames.CreateCopy(const AAutoRemoveNodes: boolean;
110
inherited CreateCopy(Source);
111
CommonCreate(AAutoRemoveNodes);
114
procedure TX3DReaderNames.CommonCreate(const AAutoRemoveNodes: boolean);
116
FNodes := TX3DNodeNames.Create(AAutoRemoveNodes);
117
FPrototypes := TX3DPrototypeNames.Create;
118
FImported := TX3DNodeNames.Create(AAutoRemoveNodes);
119
FExported := TX3DNodeNames.Create(AAutoRemoveNodes);
120
FImportable := TX3DImportableNames.Create;
123
destructor TX3DReaderNames.Destroy;
126
FreeAndNil(FPrototypes);
127
FreeAndNil(FImported);
128
FreeAndNil(FExported);
129
FreeAndNil(FImportable);
133
procedure TX3DReaderNames.ExtractNames(out APrototypes: TX3DPrototypeNames;
134
out AExported: TX3DNodeNames);
136
APrototypes := FPrototypes;
137
AExported := FExported;
143
procedure TX3DReaderNames.DoExport(E: TX3DExport);
145
ExportedNode: TX3DNode;
146
IgnoreNodeFinished: boolean;
148
ExportedNode := Nodes.Bound(E.ExportedNodeName, IgnoreNodeFinished);
149
if ExportedNode = nil then
151
OnWarning(wtMajor, 'VRML/X3D', Format('Exported node name "%s" not found', [E.ExportedNodeName]));
155
Exported.Bind(ExportedNode, true, E.ExportedNodeAlias);
158
procedure TX3DReaderNames.DoImport(I: TX3DImport);
160
ImportedNames: TX3DNodeNames;
161
ImportedNamesIndex: Integer;
162
ImportedNode: TX3DNode;
163
IgnoreNodeFinished: boolean;
165
ImportedNamesIndex := Importable.IndexOf(I.InlineNodeName);
166
if ImportedNamesIndex = -1 then
168
OnWarning(wtMajor, 'VRML/X3D', Format('Inline node name "%s" not found (or nothing was EXPORTed from it), cannot IMPORT', [I.InlineNodeName]));
172
ImportedNames := Importable.Objects[ImportedNamesIndex] as TX3DNodeNames;
174
ImportedNode := ImportedNames.Bound(I.ImportedNodeName, IgnoreNodeFinished);
175
if ImportedNode = nil then
177
OnWarning(wtMajor, 'VRML/X3D', Format('Imported node name "%s" not found in inline "%s"', [I.ImportedNodeName, I.InlineNodeName]));
181
Imported.Bind(ImportedNode, true, I.ImportedNodeAlias);