1 // Created on: 2007-08-01
2 // Created by: Alexander GRIGORIEV
3 // Copyright (c) 2007-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #include <VrmlData_WorldInfo.hxx>
17 #include <VrmlData_Scene.hxx>
18 #include <VrmlData_InBuffer.hxx>
21 #define _CRT_SECURE_NO_DEPRECATE
22 #pragma warning (disable:4996)
26 //=======================================================================
27 //function : VrmlData_WorldInfo::VrmlData_WorldInfo
28 //purpose : Constructor
29 //=======================================================================
31 VrmlData_WorldInfo::VrmlData_WorldInfo (const VrmlData_Scene& theScene,
33 const char * theTitle)
34 : VrmlData_Node (theScene, theName),
35 myInfo (theScene.Allocator())
40 //=======================================================================
42 //purpose : Set or modify the title.
43 //=======================================================================
45 void VrmlData_WorldInfo::SetTitle (const char * theString)
50 const size_t len = strlen (theString) + 1;
54 myTitle = static_cast <const char *>(Scene().Allocator()->Allocate(len));
55 memcpy (const_cast<char *> (myTitle), theString, len);
60 //=======================================================================
62 //purpose : Add a string to the list of info strings.
63 //=======================================================================
65 void VrmlData_WorldInfo::AddInfo (const char * theString)
68 if (* theString != '\0') {
69 const size_t len = strlen (theString) + 1;
70 char * aStr = static_cast <char *>(Scene().Allocator()->Allocate(len));
71 memcpy (aStr, theString, len);
76 //=======================================================================
78 //purpose : Create a copy of this node
79 //=======================================================================
81 Handle(VrmlData_Node) VrmlData_WorldInfo::Clone
82 (const Handle(VrmlData_Node)& theOther) const
84 Handle(VrmlData_WorldInfo) aResult =
85 Handle(VrmlData_WorldInfo)::DownCast (VrmlData_Node::Clone(theOther));
88 new VrmlData_WorldInfo (theOther.IsNull() ? Scene() : theOther->Scene(),
91 if (&aResult->Scene() == &Scene()) {
92 aResult->myTitle = myTitle;
93 aResult->myInfo = myInfo;
95 aResult->SetTitle (myTitle);
96 NCollection_List <const char *>::Iterator anIter (myInfo);
97 for (; anIter.More(); anIter.Next())
98 aResult->AddInfo (anIter.Value());
103 //=======================================================================
105 //purpose : Read the Node from input stream.
106 //=======================================================================
108 VrmlData_ErrorStatus VrmlData_WorldInfo::Read (VrmlData_InBuffer& theBuffer)
110 VrmlData_ErrorStatus aStatus;
111 while (OK(aStatus, VrmlData_Scene::ReadLine(theBuffer))) {
113 if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "title")) {
114 TCollection_AsciiString aTitleString;
115 if (OK (aStatus, ReadString (theBuffer, aTitleString)))
116 SetTitle (aTitleString.ToCString());
118 } else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "info")) {
119 NCollection_List<TCollection_AsciiString> lstInfo;
120 if (OK (aStatus, ReadMultiString (theBuffer, lstInfo))) {
121 NCollection_List<TCollection_AsciiString>::Iterator anIter (lstInfo);
122 for (; anIter.More(); anIter.Next())
123 AddInfo (anIter.Value().ToCString());
129 // Read the terminating (closing) brace
131 aStatus = readBrace (theBuffer);
135 //=======================================================================
137 //purpose : Write the Node to the Scene output.
138 //=======================================================================
140 VrmlData_ErrorStatus VrmlData_WorldInfo::Write (const char * thePrefix) const
142 VrmlData_ErrorStatus aStatus (VrmlData_StatusOK);
143 const VrmlData_Scene& aScene = Scene();
144 static char header[] = "WorldInfo {";
145 if (aScene.IsDummyWrite() == Standard_False &&
146 OK (aStatus, aScene.WriteLine (thePrefix, header, GlobalIndent())))
150 Sprintf (buf, "title \"%s\"", myTitle);
151 aStatus = aScene.WriteLine (buf);
154 if (myInfo.IsEmpty() == Standard_False && OK(aStatus)) {
155 if (OK (aStatus, aScene.WriteLine ("info [", 0L, GlobalIndent()))) {
156 NCollection_List<const char *>::Iterator anIter (myInfo);
157 while (anIter.More()) {
158 Sprintf (buf, "\"%s\"", anIter.Value());
161 aStatus = aScene.WriteLine (buf, ",");
163 aStatus = aScene.WriteLine (buf);
166 aStatus = aScene.WriteLine ("]", 0L, -GlobalIndent());
169 aStatus = WriteClosing();
174 //=======================================================================
175 //function : IsDefault
177 //=======================================================================
179 Standard_Boolean VrmlData_WorldInfo::IsDefault() const
181 return (myTitle == 0L && myInfo.IsEmpty());