b311480e |
1 | // Created on: 2006-05-25 |
2 | // Created by: Alexander GRIGORIEV |
973c2be1 |
3 | // Copyright (c) 2006-2014 OPEN CASCADE SAS |
b311480e |
4 | // |
973c2be1 |
5 | // This file is part of Open CASCADE Technology software library. |
b311480e |
6 | // |
d5f74e42 |
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 |
973c2be1 |
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. |
b311480e |
12 | // |
973c2be1 |
13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. |
7fd59977 |
15 | |
16 | #include <Precision.hxx> |
17 | #include <VrmlData_Appearance.hxx> |
18 | #include <VrmlData_ImageTexture.hxx> |
19 | #include <VrmlData_Material.hxx> |
20 | #include <VrmlData_ShapeNode.hxx> |
21 | #include <VrmlData_UnknownNode.hxx> |
22 | #include <VrmlData_Scene.hxx> |
23 | #include <VrmlData_InBuffer.hxx> |
24 | #include <gp_XY.hxx> |
25 | #include <gp_XYZ.hxx> |
ec357c5c |
26 | #include <VrmlData_Geometry.hxx> |
27 | #include <VrmlData_TextureTransform.hxx> |
28 | #include <VrmlData_Texture.hxx> |
7fd59977 |
29 | |
92efcf78 |
30 | IMPLEMENT_STANDARD_RTTIEXT(VrmlData_Node,Standard_Transient) |
31 | |
57c28b61 |
32 | #ifdef _MSC_VER |
7fd59977 |
33 | #define _CRT_SECURE_NO_DEPRECATE |
34 | #pragma warning (disable:4996) |
35 | #endif |
36 | |
7fd59977 |
37 | static VrmlData_Scene MyDefaultScene; |
38 | |
39 | //======================================================================= |
40 | //function : IsEqual |
41 | //purpose : Global method |
42 | //======================================================================= |
43 | |
44 | Standard_Boolean IsEqual (const Handle(VrmlData_Node)& theOne, |
45 | const Handle(VrmlData_Node)& theTwo) |
46 | { |
47 | Standard_Boolean aResult (Standard_False); |
48 | if (theOne->Name() != 0L && theTwo->Name() != 0L) |
49 | aResult = (strcmp (theOne->Name(), theTwo->Name()) == 0); |
50 | return aResult; |
51 | } |
52 | |
53 | //======================================================================= |
54 | //function : HashCode |
55 | //purpose : Global method |
56 | //======================================================================= |
57 | |
58 | Standard_Integer HashCode(const Handle(VrmlData_Node)& theNode, |
59 | const Standard_Integer theUpper) |
60 | { |
61 | return (theNode->Name() == 0L ? 0 |
62 | : HashCode((Standard_CString)theNode->Name(), theUpper)); |
63 | } |
64 | |
65 | //======================================================================= |
66 | //function : VrmlData_Node |
67 | //purpose : |
68 | //======================================================================= |
69 | |
70 | VrmlData_Node::VrmlData_Node () |
71 | : myScene (&MyDefaultScene), |
72 | myName (0L) {} |
73 | |
74 | //======================================================================= |
75 | //function : VrmlData_Node |
76 | //purpose : Constructor |
77 | //======================================================================= |
78 | |
79 | VrmlData_Node::VrmlData_Node (const VrmlData_Scene& theScene, |
80 | const char * theName) |
81 | : myScene (&theScene) |
82 | { |
83 | if (theName == 0L) |
84 | theName = ""; |
85 | setName (theName); |
86 | } |
87 | |
88 | //======================================================================= |
89 | //function : Clone |
90 | //purpose : Create a copy of this node. |
91 | //======================================================================= |
92 | |
93 | Handle(VrmlData_Node) VrmlData_Node::Clone |
94 | (const Handle(VrmlData_Node)& theOther) const |
95 | { |
96 | if (theOther.IsNull() == Standard_False) { |
97 | if (theOther->IsKind (DynamicType()) == Standard_False) |
98 | return NULL; |
99 | if (&theOther->Scene() == myScene) |
100 | theOther->myName = myName; |
101 | else |
102 | theOther->setName (myName); |
103 | } |
104 | return theOther; |
105 | } |
106 | |
107 | //======================================================================= |
108 | //function : setName |
109 | //purpose : |
110 | //======================================================================= |
111 | |
112 | void VrmlData_Node::setName (const char * theName, const char * theSuffix) |
113 | { |
114 | size_t len[2] = { |
115 | strlen(theName) + 1, |
116 | 0 |
117 | }; |
118 | if (theSuffix) |
119 | len[1] = strlen (theSuffix); |
120 | char * aName = (char *)Scene().Allocator()->Allocate(len[0]+len[1]); |
121 | myName = aName; |
122 | memcpy (aName, theName, len[0]); |
123 | if (len[1]) |
124 | memcpy (&aName[len[0] - 1], theSuffix, len[1]+1); |
125 | } |
126 | |
127 | //======================================================================= |
128 | //function : IsDefault |
129 | //purpose : |
130 | //======================================================================= |
131 | |
132 | Standard_Boolean VrmlData_Node::IsDefault () const |
133 | { |
134 | return Standard_False; |
135 | } |
136 | |
137 | |
138 | //======================================================================= |
139 | //function : Write |
140 | //purpose : |
141 | //======================================================================= |
142 | |
143 | VrmlData_ErrorStatus VrmlData_Node::Write (const char *) const |
144 | { |
145 | return VrmlData_NotImplemented; |
146 | } |
147 | |
148 | //======================================================================= |
149 | //function : WriteClosing |
150 | //purpose : |
151 | //======================================================================= |
152 | |
153 | VrmlData_ErrorStatus VrmlData_Node::WriteClosing () const |
154 | { |
155 | VrmlData_ErrorStatus aResult = Scene().Status(); |
156 | if (aResult == VrmlData_StatusOK || aResult == VrmlData_NotImplemented) |
157 | aResult = Scene().WriteLine ("}", 0L, -GlobalIndent()); |
158 | return aResult; |
159 | } |
160 | |
161 | //======================================================================= |
162 | //function : readBrace |
163 | //purpose : |
164 | //======================================================================= |
165 | |
166 | VrmlData_ErrorStatus VrmlData_Node::readBrace (VrmlData_InBuffer& theBuffer) |
167 | { |
168 | VrmlData_ErrorStatus aStatus; |
eafb234b |
169 | if (OK(aStatus, VrmlData_Scene::ReadLine(theBuffer))) { |
7fd59977 |
170 | if (theBuffer.LinePtr[0] == '}') |
171 | theBuffer.LinePtr++; |
172 | else |
173 | aStatus = VrmlData_VrmlFormatError; |
eafb234b |
174 | } |
7fd59977 |
175 | return aStatus; |
176 | } |
177 | |
178 | //======================================================================= |
179 | //function : ReadBoolean |
180 | //purpose : |
181 | //======================================================================= |
182 | |
183 | VrmlData_ErrorStatus VrmlData_Node::ReadBoolean (VrmlData_InBuffer& theBuffer, |
184 | Standard_Boolean& theResult) |
185 | { |
186 | VrmlData_ErrorStatus aStatus; |
187 | if (OK(aStatus, VrmlData_Scene::ReadLine(theBuffer))) { |
188 | if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "TRUE")) |
189 | theResult = Standard_True; |
190 | else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "FALSE")) |
191 | theResult = Standard_False; |
192 | else |
193 | aStatus = VrmlData_BooleanInputError; |
194 | } |
195 | return aStatus; |
196 | } |
197 | |
198 | //======================================================================= |
199 | //function : ReadInteger |
200 | //purpose : |
201 | //======================================================================= |
202 | |
203 | VrmlData_ErrorStatus VrmlData_Node::ReadInteger (VrmlData_InBuffer& theBuffer, |
204 | long& theResult) |
205 | { |
206 | VrmlData_ErrorStatus aStatus; |
207 | if (OK(aStatus, VrmlData_Scene::ReadLine(theBuffer))) { |
208 | char * endptr; |
209 | long aResult; |
210 | aResult = strtol (theBuffer.LinePtr, &endptr, 10); |
211 | if (endptr == theBuffer.LinePtr) |
212 | aStatus = VrmlData_NumericInputError; |
213 | else { |
214 | theResult = aResult; |
215 | theBuffer.LinePtr = endptr; |
216 | } |
217 | } |
218 | return aStatus; |
219 | } |
220 | |
221 | //======================================================================= |
222 | //function : ReadString |
223 | //purpose : |
224 | //======================================================================= |
225 | |
226 | VrmlData_ErrorStatus VrmlData_Node::ReadString |
227 | (VrmlData_InBuffer& theBuffer, |
228 | TCollection_AsciiString& theResult) |
229 | { |
230 | VrmlData_ErrorStatus aStatus; |
231 | if (OK(aStatus, VrmlData_Scene::ReadLine(theBuffer))) { |
232 | if (theBuffer.LinePtr[0] != '\"') |
233 | aStatus = VrmlData_StringInputError; |
234 | else { |
235 | char * ptr = &theBuffer.LinePtr[1]; |
236 | while (*ptr != '\0' && *ptr != '\"') |
237 | ptr++; |
238 | if (*ptr == '\0') |
239 | aStatus = VrmlData_StringInputError; |
240 | else { |
241 | *ptr = '\0'; |
242 | theResult = (Standard_CString) &theBuffer.LinePtr[1]; |
243 | theBuffer.LinePtr = ptr+1; |
244 | } |
245 | } |
246 | } |
247 | return aStatus; |
248 | } |
249 | |
250 | //======================================================================= |
251 | //function : ReadMultiString |
252 | //purpose : |
253 | //======================================================================= |
254 | |
255 | VrmlData_ErrorStatus VrmlData_Node::ReadMultiString |
256 | (VrmlData_InBuffer& theBuffer, |
257 | NCollection_List<TCollection_AsciiString>& theResult) |
258 | { |
259 | VrmlData_ErrorStatus aStatus; |
260 | Standard_Boolean isBracketed (Standard_False); |
261 | // Read the list of URL |
262 | if (OK(aStatus, VrmlData_Scene::ReadLine(theBuffer))) { |
263 | if (theBuffer.LinePtr[0] == '[') { |
264 | theBuffer.LinePtr++; |
265 | isBracketed = Standard_True; |
266 | } |
267 | while (OK(aStatus, VrmlData_Scene::ReadLine(theBuffer))) { |
268 | if (isBracketed && theBuffer.LinePtr[0] == ']') { // closing bracket |
269 | theBuffer.LinePtr++; |
270 | break; |
271 | } |
272 | TCollection_AsciiString aString; |
273 | if (!OK(aStatus, ReadString(theBuffer, aString))) |
274 | break; |
275 | theResult.Append(aString); |
276 | if (isBracketed == Standard_False || |
277 | !OK(aStatus, VrmlData_Scene::ReadLine(theBuffer))) |
278 | break; |
279 | if (theBuffer.LinePtr[0] == ',') { |
280 | theBuffer.LinePtr++; |
281 | continue; |
282 | } else if (theBuffer.LinePtr[0] == ']') // closing bracket |
283 | theBuffer.LinePtr++; |
284 | else |
285 | aStatus = VrmlData_VrmlFormatError; |
286 | break; |
287 | } |
288 | } |
289 | return aStatus; |
290 | } |
291 | |
292 | //======================================================================= |
293 | //function : ReadNode |
294 | //purpose : |
295 | //======================================================================= |
296 | |
297 | VrmlData_ErrorStatus VrmlData_Node::ReadNode |
298 | (VrmlData_InBuffer& theBuffer, |
299 | Handle(VrmlData_Node)& theNode, |
300 | const Handle(Standard_Type)& theType) |
301 | { |
302 | Handle(VrmlData_Node) aNode; |
303 | VrmlData_ErrorStatus aStatus; |
304 | // First line of a new node should identify this node type |
305 | if (OK(aStatus, VrmlData_Scene::ReadLine(theBuffer))) { |
306 | if (VRMLDATA_LCOMPARE(theBuffer.LinePtr, "USE")) { |
307 | TCollection_AsciiString aName; |
308 | aStatus = VrmlData_Scene::ReadWord (theBuffer, aName); |
309 | if (aStatus == VrmlData_StatusOK) { |
310 | aNode = myScene->FindNode (aName.ToCString(), theType); |
311 | if (aNode.IsNull()) |
312 | aStatus = VrmlData_NodeNameUnknown; |
313 | // else |
314 | // aNode = aNode->Clone(0L); |
315 | } |
316 | } |
317 | |
318 | // We create a relevant node using the line with the type ID |
319 | else if (OK(aStatus, |
320 | const_cast<VrmlData_Scene *>(myScene)->createNode (theBuffer, |
321 | aNode, |
322 | theType))) |
323 | if (aNode.IsNull() == Standard_False) |
324 | // The node data are read here, including the final closing brace |
325 | aStatus = aNode->Read(theBuffer); |
326 | |
327 | if (aStatus == VrmlData_StatusOK) |
328 | theNode = aNode; |
329 | } |
330 | return aStatus; |
331 | } |
332 | |
333 | //======================================================================= |
334 | //function : VrmlData_ShapeNode::Clone |
335 | //purpose : |
336 | //======================================================================= |
337 | |
338 | Handle(VrmlData_Node) VrmlData_ShapeNode::Clone |
339 | (const Handle(VrmlData_Node)& theOther) const |
340 | { |
341 | Handle(VrmlData_ShapeNode) aResult = |
342 | Handle(VrmlData_ShapeNode)::DownCast (VrmlData_Node::Clone(theOther)); |
343 | if (aResult.IsNull()) |
344 | aResult= new VrmlData_ShapeNode(theOther.IsNull()?Scene():theOther->Scene(), |
345 | Name()); |
346 | if (&aResult->Scene() == &Scene()) { |
347 | aResult->SetAppearance (myAppearance); |
348 | aResult->SetGeometry (myGeometry); |
349 | } else { |
350 | // Create a dummy node to pass the different Scene instance to methods Clone |
351 | const Handle(VrmlData_UnknownNode) aDummyNode = |
352 | new VrmlData_UnknownNode (aResult->Scene()); |
353 | if (myAppearance.IsNull() == Standard_False) |
354 | aResult->SetAppearance(Handle(VrmlData_Appearance)::DownCast |
355 | (myAppearance->Clone (aDummyNode))); |
356 | if (myGeometry.IsNull() == Standard_False) |
357 | aResult->SetGeometry (Handle(VrmlData_Geometry)::DownCast |
358 | (myGeometry->Clone (aDummyNode))); |
359 | } |
360 | return aResult; |
361 | } |
362 | |
363 | //======================================================================= |
364 | //function : VrmlData_ShapeNode::Read |
365 | //purpose : |
366 | //======================================================================= |
367 | |
368 | VrmlData_ErrorStatus VrmlData_ShapeNode::Read (VrmlData_InBuffer& theBuffer) |
369 | { |
370 | VrmlData_ErrorStatus aStatus; |
371 | while (OK(aStatus, VrmlData_Scene::ReadLine(theBuffer))) { |
372 | if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "appearance")) |
aa00364d |
373 | { |
374 | Handle(VrmlData_Node) aNode; |
375 | aStatus = ReadNode (theBuffer, aNode, |
7fd59977 |
376 | STANDARD_TYPE(VrmlData_Appearance)); |
aa00364d |
377 | myAppearance = Handle(VrmlData_Appearance)::DownCast (aNode); |
378 | } |
7fd59977 |
379 | else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "geometry")) |
aa00364d |
380 | { |
381 | Handle(VrmlData_Node) aNode; |
382 | aStatus = ReadNode (theBuffer, aNode); |
383 | myGeometry = Handle(VrmlData_Geometry)::DownCast (aNode); |
7fd59977 |
384 | // here we do not check for the Geometry type because unknown node types can |
385 | // occur (IndexedLineSet, etc.) |
386 | // STANDARD_TYPE(VrmlData_Geometry)); |
aa00364d |
387 | } |
7fd59977 |
388 | else |
389 | break; |
390 | |
391 | if (!OK(aStatus)) |
392 | break; |
393 | } |
394 | |
395 | // Read the terminating (closing) brace |
396 | if (OK(aStatus)) |
397 | aStatus = readBrace (theBuffer); |
398 | return aStatus; |
399 | } |
400 | |
401 | //======================================================================= |
402 | //function : VrmlData_ShapeNode::Write |
403 | //purpose : |
404 | //======================================================================= |
405 | |
406 | VrmlData_ErrorStatus VrmlData_ShapeNode::Write (const char * thePrefix) const |
407 | { |
408 | VrmlData_ErrorStatus aStatus (VrmlData_StatusOK); |
409 | const VrmlData_Scene& aScene = Scene(); |
410 | static char header[] = "Shape {"; |
411 | if (OK (aStatus, aScene.WriteLine (thePrefix, header, GlobalIndent()))) |
412 | { |
413 | if (myAppearance.IsNull() == Standard_False) |
414 | aStatus = aScene.WriteNode ("appearance", myAppearance); |
415 | if (myGeometry.IsNull() == Standard_False && OK(aStatus)) |
416 | aStatus = aScene.WriteNode ("geometry", myGeometry); |
417 | |
418 | aStatus = WriteClosing(); |
419 | } |
420 | return aStatus; |
421 | } |
422 | |
423 | //======================================================================= |
424 | //function : VrmlData_ShapeNode::IsDefault |
425 | //purpose : |
426 | //======================================================================= |
427 | |
428 | Standard_Boolean VrmlData_ShapeNode::IsDefault () const |
429 | { |
430 | Standard_Boolean aResult (Standard_True); |
431 | if (myGeometry.IsNull() == Standard_False) |
432 | aResult = myGeometry->IsDefault(); |
433 | return aResult; |
434 | } |
435 | |
436 | //======================================================================= |
437 | //function : VrmlData_UnknownNode::Read |
438 | //purpose : |
439 | //======================================================================= |
440 | |
441 | VrmlData_ErrorStatus VrmlData_UnknownNode::Read (VrmlData_InBuffer& theBuffer) |
442 | { |
1d47d8d0 |
443 | VrmlData_ErrorStatus aStatus = VrmlData_StatusOK; |
7fd59977 |
444 | Standard_Integer aLevelCounter (0); |
445 | // This loop searches for any opening brace. |
446 | // Such brace increments the level counter. A closing brace decrements |
447 | // the counter. The loop terminates when the counter becomes negative. |
448 | while (aLevelCounter >= 0 && |
449 | OK(aStatus, VrmlData_Scene::ReadLine(theBuffer))) |
450 | { |
451 | int aChar; |
452 | while ((aChar = theBuffer.LinePtr[0]) != '\0') { |
453 | theBuffer.LinePtr++; |
454 | if (aChar == '{') { |
455 | aLevelCounter++; |
456 | break; |
457 | } else if (aChar == '}') { |
458 | aLevelCounter--; |
459 | break; |
460 | } |
461 | } |
462 | } |
463 | return aStatus; |
464 | } |
465 | |
466 | //======================================================================= |
467 | //function : VrmlData_UnknownNode::IsDefault |
468 | //purpose : |
469 | //======================================================================= |
470 | |
471 | Standard_Boolean VrmlData_UnknownNode::IsDefault () const |
472 | { |
473 | return Standard_True; |
474 | } |
475 | |
476 | //======================================================================= |
477 | //function : VrmlData_Appearance::Clone |
478 | //purpose : |
479 | //======================================================================= |
480 | |
481 | Handle(VrmlData_Node) VrmlData_Appearance::Clone |
482 | (const Handle(VrmlData_Node)& theOther) const |
483 | { |
484 | Handle(VrmlData_Appearance) aResult = |
485 | Handle(VrmlData_Appearance)::DownCast (VrmlData_Node::Clone(theOther)); |
486 | if (aResult.IsNull()) |
487 | aResult = new VrmlData_Appearance |
488 | (theOther.IsNull() ? Scene() : theOther->Scene(), Name()); |
489 | if (&aResult->Scene() == &Scene()) { |
490 | aResult->SetMaterial (myMaterial); |
491 | aResult->SetTexture (myTexture); |
492 | aResult->SetTextureTransform (myTTransform); |
493 | } else { |
494 | // Create a dummy node to pass the different Scene instance to methods Clone |
495 | const Handle(VrmlData_UnknownNode) aDummyNode = |
496 | new VrmlData_UnknownNode (aResult->Scene()); |
497 | if (myMaterial.IsNull() == Standard_False) |
498 | aResult->SetMaterial (Handle(VrmlData_Material)::DownCast |
499 | (myMaterial->Clone (aDummyNode))); |
500 | if (myTexture.IsNull() == Standard_False) |
501 | aResult->SetTexture(Handle(VrmlData_Texture)::DownCast |
502 | (myTexture->Clone (aDummyNode))); |
503 | if (myTTransform.IsNull() == Standard_False) |
504 | aResult->SetTextureTransform(Handle(VrmlData_TextureTransform)::DownCast |
505 | (myTTransform->Clone (aDummyNode))); |
506 | } |
507 | return aResult; |
508 | } |
509 | |
510 | //======================================================================= |
511 | //function : VrmlData_Appearance::Read |
512 | //purpose : |
513 | //======================================================================= |
514 | |
515 | VrmlData_ErrorStatus VrmlData_Appearance::Read (VrmlData_InBuffer& theBuffer) |
516 | { |
517 | VrmlData_ErrorStatus aStatus; |
518 | while (OK(aStatus, VrmlData_Scene::ReadLine(theBuffer))) { |
519 | if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "material")) |
aa00364d |
520 | { |
521 | Handle(VrmlData_Node) aNode; |
522 | aStatus = ReadNode (theBuffer, aNode, |
7fd59977 |
523 | STANDARD_TYPE(VrmlData_Material)); |
aa00364d |
524 | myMaterial = Handle(VrmlData_Material)::DownCast (aNode); |
525 | } |
7fd59977 |
526 | else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "textureTransform")) |
aa00364d |
527 | { |
528 | Handle(VrmlData_Node) aNode; |
529 | aStatus = ReadNode (theBuffer, aNode |
7fd59977 |
530 | /*,STANDARD_TYPE(VrmlData_TextureTransform)*/); |
aa00364d |
531 | myTTransform = Handle(VrmlData_TextureTransform)::DownCast (aNode); |
532 | } |
7fd59977 |
533 | else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "texture")) |
aa00364d |
534 | { |
535 | Handle(VrmlData_Node) aNode; |
536 | aStatus = ReadNode (theBuffer, aNode, |
7fd59977 |
537 | STANDARD_TYPE(VrmlData_Texture)); |
aa00364d |
538 | myTexture = Handle(VrmlData_Texture)::DownCast (aNode); |
539 | } |
7fd59977 |
540 | else |
541 | break; |
542 | |
543 | if (!OK(aStatus)) |
544 | break; |
545 | } |
546 | |
547 | // Read the terminating (closing) brace |
548 | if (OK(aStatus)) |
549 | aStatus = readBrace (theBuffer); |
550 | return aStatus; |
551 | } |
552 | |
553 | //======================================================================= |
554 | //function : VrmlData_Appearance::Write |
555 | //purpose : |
556 | //======================================================================= |
557 | |
558 | VrmlData_ErrorStatus VrmlData_Appearance::Write (const char * thePrefix) const |
559 | { |
560 | static char header[] = "Appearance {"; |
561 | VrmlData_ErrorStatus aStatus; |
562 | const VrmlData_Scene& aScene = Scene(); |
563 | if (OK (aStatus, aScene.WriteLine (thePrefix, header, GlobalIndent()))) |
564 | { |
565 | if (myMaterial.IsNull() == Standard_False) |
566 | aStatus = aScene.WriteNode ("material", myMaterial); |
567 | if (myTexture.IsNull() == Standard_False && OK(aStatus)) |
568 | aStatus = aScene.WriteNode ("texture", myTexture); |
569 | if (myTTransform.IsNull() == Standard_False && OK(aStatus)) |
570 | aStatus = aScene.WriteNode ("textureTransform", myTTransform); |
571 | |
572 | aStatus = WriteClosing(); |
573 | } |
574 | return aStatus; |
575 | } |
576 | |
577 | //======================================================================= |
578 | //function : IsDefault |
579 | //purpose : |
580 | //======================================================================= |
581 | |
582 | Standard_Boolean VrmlData_Appearance::IsDefault () const |
583 | { |
584 | Standard_Boolean aResult (Standard_True); |
585 | if (myMaterial.IsNull() == Standard_False) |
586 | aResult = myMaterial->IsDefault(); |
7d73d13f |
587 | if (aResult && myTexture.IsNull() == Standard_False) |
588 | aResult = myTexture->IsDefault(); |
589 | if (aResult && myTTransform.IsNull() == Standard_False) |
590 | aResult = myTTransform->IsDefault(); |
7fd59977 |
591 | return aResult; |
592 | } |
593 | |
594 | //======================================================================= |
595 | //function : VrmlData_ImageTexture |
596 | //purpose : Constructor |
597 | //======================================================================= |
598 | |
599 | VrmlData_ImageTexture::VrmlData_ImageTexture (const VrmlData_Scene& theScene, |
600 | const char * theName, |
601 | const char * theURL, |
602 | const Standard_Boolean theRepS, |
603 | const Standard_Boolean theRepT) |
604 | : VrmlData_Texture (theScene, theName, theRepS, theRepT), |
605 | myURL (theScene.Allocator()) |
606 | { |
607 | myURL.Append (theURL ? (Standard_CString)theURL : ""); |
608 | } |
609 | |
610 | //======================================================================= |
611 | //function : VrmlData_ImageTexture::Clone |
612 | //purpose : |
613 | //======================================================================= |
614 | |
615 | Handle(VrmlData_Node) VrmlData_ImageTexture::Clone |
616 | (const Handle(VrmlData_Node)& theOther) const |
617 | { |
618 | Handle(VrmlData_ImageTexture) aResult = |
619 | Handle(VrmlData_ImageTexture)::DownCast (VrmlData_Node::Clone(theOther)); |
620 | if (aResult.IsNull()) |
621 | aResult = |
622 | new VrmlData_ImageTexture(theOther.IsNull() ? Scene() : theOther->Scene(), |
623 | Name()); |
624 | aResult->myURL = myURL; |
625 | return aResult; |
626 | } |
627 | |
628 | //======================================================================= |
629 | //function : VrmlData_ImageTexture::Read |
630 | //purpose : |
631 | //======================================================================= |
632 | |
633 | VrmlData_ErrorStatus VrmlData_ImageTexture::Read (VrmlData_InBuffer& theBuffer) |
634 | { |
635 | VrmlData_ErrorStatus aStatus; |
636 | Standard_Boolean aRepeatS (Standard_True), aRepeatT (Standard_True); |
637 | myURL.Clear(); |
638 | while (OK(aStatus, VrmlData_Scene::ReadLine(theBuffer))) { |
639 | if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "url")) |
640 | aStatus = ReadMultiString (theBuffer, myURL); |
641 | else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "repeatS")) |
642 | aStatus = ReadBoolean (theBuffer, aRepeatS); |
643 | else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "repeatT")) |
644 | aStatus = ReadBoolean (theBuffer, aRepeatT); |
645 | else |
646 | break; |
647 | |
648 | if (!OK(aStatus)) |
649 | break; |
650 | } |
651 | if (OK(aStatus) && OK(aStatus, readBrace (theBuffer))) { |
652 | SetRepeatS (aRepeatS); |
653 | SetRepeatT (aRepeatT); |
654 | } |
655 | return aStatus; |
656 | } |
657 | |
7d73d13f |
658 | //======================================================================= |
659 | //function : Write |
660 | //purpose : |
661 | //======================================================================= |
662 | |
663 | VrmlData_ErrorStatus VrmlData_ImageTexture::Write(const char *thePrefix) const |
664 | { |
665 | VrmlData_ErrorStatus aStatus = VrmlData_StatusOK; |
666 | const VrmlData_Scene& aScene = Scene(); |
667 | static char header[] = "ImageTexture {"; |
668 | if (aScene.IsDummyWrite() == Standard_False && |
669 | OK(aStatus, aScene.WriteLine(thePrefix, header, GlobalIndent()))) |
670 | { |
671 | TCollection_AsciiString url = "\""; |
672 | url += URL().First(); |
673 | url += "\""; |
674 | |
675 | try { |
676 | aStatus = aScene.WriteLine("url ", url.ToCString()); |
677 | } |
678 | catch (...) |
679 | { |
680 | |
681 | } |
682 | aStatus = WriteClosing(); |
683 | } |
684 | return aStatus; |
685 | } |