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)
25 IMPLEMENT_STANDARD_HANDLE (VrmlData_WorldInfo, VrmlData_Node)
26 IMPLEMENT_STANDARD_RTTIEXT (VrmlData_WorldInfo, VrmlData_Node)
28 //=======================================================================
29 //function : VrmlData_WorldInfo::VrmlData_WorldInfo
30 //purpose : Constructor
31 //=======================================================================
33 VrmlData_WorldInfo::VrmlData_WorldInfo (const VrmlData_Scene& theScene,
35 const char * theTitle)
36 : VrmlData_Node (theScene, theName),
37 myInfo (theScene.Allocator())
42 //=======================================================================
44 //purpose : Set or modify the title.
45 //=======================================================================
47 void VrmlData_WorldInfo::SetTitle (const char * theString)
52 const size_t len = strlen (theString) + 1;
56 myTitle = static_cast <const char *>(Scene().Allocator()->Allocate(len));
57 memcpy (const_cast<char *> (myTitle), theString, len);
62 //=======================================================================
64 //purpose : Add a string to the list of info strings.
65 //=======================================================================
67 void VrmlData_WorldInfo::AddInfo (const char * theString)
70 if (* theString != '\0') {
71 const size_t len = strlen (theString) + 1;
72 char * aStr = static_cast <char *>(Scene().Allocator()->Allocate(len));
73 memcpy (aStr, theString, len);
78 //=======================================================================
80 //purpose : Create a copy of this node
81 //=======================================================================
83 Handle(VrmlData_Node) VrmlData_WorldInfo::Clone
84 (const Handle(VrmlData_Node)& theOther) const
86 Handle(VrmlData_WorldInfo) aResult =
87 Handle(VrmlData_WorldInfo)::DownCast (VrmlData_Node::Clone(theOther));
90 new VrmlData_WorldInfo (theOther.IsNull() ? Scene() : theOther->Scene(),
93 if (&aResult->Scene() == &Scene()) {
94 aResult->myTitle = myTitle;
95 aResult->myInfo = myInfo;
97 aResult->SetTitle (myTitle);
98 NCollection_List <const char *>::Iterator anIter (myInfo);
99 for (; anIter.More(); anIter.Next())
100 aResult->AddInfo (anIter.Value());
105 //=======================================================================
107 //purpose : Read the Node from input stream.
108 //=======================================================================
110 VrmlData_ErrorStatus VrmlData_WorldInfo::Read (VrmlData_InBuffer& theBuffer)
112 VrmlData_ErrorStatus aStatus;
113 while (OK(aStatus, VrmlData_Scene::ReadLine(theBuffer))) {
115 if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "title")) {
116 TCollection_AsciiString aTitleString;
117 if (OK (aStatus, ReadString (theBuffer, aTitleString)))
118 SetTitle (aTitleString.ToCString());
120 } else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "info")) {
121 NCollection_List<TCollection_AsciiString> lstInfo;
122 if (OK (aStatus, ReadMultiString (theBuffer, lstInfo))) {
123 NCollection_List<TCollection_AsciiString>::Iterator anIter (lstInfo);
124 for (; anIter.More(); anIter.Next())
125 AddInfo (anIter.Value().ToCString());
131 // Read the terminating (closing) brace
133 aStatus = readBrace (theBuffer);
137 //=======================================================================
139 //purpose : Write the Node to the Scene output.
140 //=======================================================================
142 VrmlData_ErrorStatus VrmlData_WorldInfo::Write (const char * thePrefix) const
144 VrmlData_ErrorStatus aStatus (VrmlData_StatusOK);
145 const VrmlData_Scene& aScene = Scene();
146 static char header[] = "WorldInfo {";
147 if (aScene.IsDummyWrite() == Standard_False &&
148 OK (aStatus, aScene.WriteLine (thePrefix, header, GlobalIndent())))
152 Sprintf (buf, "title \"%s\"", myTitle);
153 aStatus = aScene.WriteLine (buf);
156 if (myInfo.IsEmpty() == Standard_False && OK(aStatus)) {
157 if (OK (aStatus, aScene.WriteLine ("info [", 0L, GlobalIndent()))) {
158 NCollection_List<const char *>::Iterator anIter (myInfo);
159 while (anIter.More()) {
160 Sprintf (buf, "\"%s\"", anIter.Value());
163 aStatus = aScene.WriteLine (buf, ",");
165 aStatus = aScene.WriteLine (buf);
168 aStatus = aScene.WriteLine ("]", 0L, -GlobalIndent());
171 aStatus = WriteClosing();
176 //=======================================================================
177 //function : IsDefault
179 //=======================================================================
181 Standard_Boolean VrmlData_WorldInfo::IsDefault() const
183 return (myTitle == 0L && myInfo.IsEmpty());