1 // Created on: 2006-05-25
2 // Created by: Alexander GRIGORIEV
3 // Copyright (c) 2006-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_Scene.hxx>
17 #include <VrmlData_Coordinate.hxx>
18 #include <VrmlData_Color.hxx>
19 #include <VrmlData_Normal.hxx>
20 #include <VrmlData_TextureCoordinate.hxx>
21 #include <VrmlData_InBuffer.hxx>
22 #include <VrmlData_Box.hxx>
23 #include <VrmlData_Cone.hxx>
24 #include <VrmlData_Cylinder.hxx>
25 #include <VrmlData_Sphere.hxx>
26 #include <VrmlData_UnknownNode.hxx>
27 #include <BRepPrimAPI_MakeBox.hxx>
28 #include <BRepPrim_Cone.hxx>
29 #include <BRepPrim_Cylinder.hxx>
30 #include <BRepPrim_Sphere.hxx>
31 #include <BRepPrim_Builder.hxx>
32 #include <NCollection_Vector.hxx>
33 #include <Standard_ErrorHandler.hxx>
34 #include <VrmlData_ArrayVec3d.hxx>
37 #define _CRT_SECURE_NO_DEPRECATE
38 #pragma warning (disable:4996)
60 //=======================================================================
63 //=======================================================================
65 const gp_XYZ& VrmlData_ArrayVec3d::Value (const Standard_Size i) const
67 static gp_XYZ anOrigin (0., 0., 0.);
68 return i < myLength ? myArray[i] : anOrigin;
71 //=======================================================================
72 //function : AllocateValues
74 //=======================================================================
76 Standard_Boolean VrmlData_ArrayVec3d::AllocateValues
77 (const Standard_Size theLength)
79 myArray = reinterpret_cast <const gp_XYZ *>
80 (Scene().Allocator()->Allocate (theLength*sizeof(gp_XYZ)));
82 return (myArray != 0L);
85 //=======================================================================
86 //function : VrmlData_Box::TShape
88 //=======================================================================
90 const Handle(TopoDS_TShape)& VrmlData_Box::TShape ()
94 const TopoDS_Shell aShell =
95 BRepPrimAPI_MakeBox (gp_Pnt (-0.5 * mySize),
96 mySize.X(), mySize.Y(), mySize.Z());
97 SetTShape (aShell.TShape());
98 myIsModified = Standard_False;
99 } catch (Standard_Failure) {
106 //=======================================================================
107 //function : VrmlData_Box::Clone
109 //=======================================================================
111 Handle(VrmlData_Node) VrmlData_Box::Clone
112 (const Handle(VrmlData_Node)& theOther) const
114 Handle(VrmlData_Box) aResult =
115 Handle(VrmlData_Box)::DownCast (VrmlData_Node::Clone(theOther));
116 if (aResult.IsNull())
117 aResult = new VrmlData_Box (theOther.IsNull() ? Scene() : theOther->Scene(),
119 aResult->SetSize(mySize);
123 //=======================================================================
124 //function : VrmlData_Box::Read
126 //=======================================================================
128 VrmlData_ErrorStatus VrmlData_Box::Read (VrmlData_InBuffer& theBuffer)
130 VrmlData_ErrorStatus aStatus;
131 if (OK(aStatus, VrmlData_Scene::ReadLine(theBuffer))) {
132 if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "size"))
133 aStatus = Scene().ReadXYZ (theBuffer, mySize,
134 Standard_True, Standard_True);
136 aStatus = readBrace (theBuffer);
141 //=======================================================================
142 //function : VrmlData_Box::Write
144 //=======================================================================
146 VrmlData_ErrorStatus VrmlData_Box::Write (const char * thePrefix) const
148 static char header[] = "Box {";
149 VrmlData_ErrorStatus aStatus;
150 if (OK (aStatus, Scene().WriteLine (thePrefix, header, GlobalIndent())))
153 Sprintf (buf, "size %.12g %.12g %.12g", mySize.X(), mySize.Y(), mySize.Z());
154 Scene().WriteLine (buf);
155 aStatus = WriteClosing();
160 //=======================================================================
161 //function : VrmlData_Cone::TShape
163 //=======================================================================
165 const Handle(TopoDS_TShape)& VrmlData_Cone::TShape ()
167 if (myIsModified && (myHasBottom || myHasSide)) {
169 gp_Ax2 aLocalAxis (gp_Pnt (0., -0.5 * myHeight, 0.),
170 gp_Dir (0., 1., 0.));
171 BRepPrim_Cone aBuilder (aLocalAxis, myBottomRadius, 0., myHeight);
173 myTShape = aBuilder.LateralFace().TShape();
175 myTShape = aBuilder.BottomFace().TShape();
177 myTShape = aBuilder.Shell().TShape();
178 myIsModified = Standard_False;
179 } catch (Standard_Failure) {
186 //=======================================================================
187 //function : VrmlData_Cone::Clone
189 //=======================================================================
191 Handle(VrmlData_Node) VrmlData_Cone::Clone
192 (const Handle(VrmlData_Node)& theOther) const
194 Handle(VrmlData_Cone) aResult =
195 Handle(VrmlData_Cone)::DownCast (VrmlData_Node::Clone(theOther));
196 if (aResult.IsNull())
197 aResult = new VrmlData_Cone (theOther.IsNull() ? Scene(): theOther->Scene(),
200 aResult->SetBottomRadius (myBottomRadius);
201 aResult->SetHeight (myHeight);
202 aResult->SetFaces (myHasBottom, myHasSide);
206 //=======================================================================
207 //function : VrmlData_Cone::Read
209 //=======================================================================
211 VrmlData_ErrorStatus VrmlData_Cone::Read (VrmlData_InBuffer& theBuffer)
213 VrmlData_ErrorStatus aStatus;
214 Standard_Boolean hasSide(Standard_True), hasBottom(Standard_True);
216 while (OK(aStatus, VrmlData_Scene::ReadLine(theBuffer)))
218 if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "bottomRadius"))
219 aStatus = Scene().ReadReal (theBuffer, myBottomRadius,
220 Standard_True, Standard_True);
221 else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "height"))
222 aStatus = Scene().ReadReal (theBuffer, myHeight,
223 Standard_True, Standard_True);
224 else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "side")) {
225 if (OK(aStatus, ReadBoolean (theBuffer, hasSide)))
227 } else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "bottom")) {
228 if (OK(aStatus, ReadBoolean (theBuffer, hasBottom)))
229 myHasBottom = hasBottom;
236 // Read the terminating (closing) brace
238 aStatus = readBrace (theBuffer);
242 //=======================================================================
243 //function : VrmlData_Cone::Write
245 //=======================================================================
247 VrmlData_ErrorStatus VrmlData_Cone::Write (const char * thePrefix) const
249 static char header[] = "Cone {";
250 VrmlData_ErrorStatus aStatus;
251 if (OK (aStatus, Scene().WriteLine (thePrefix, header, GlobalIndent())))
254 if ((myBottomRadius - 1.)*(myBottomRadius - 1.) > Precision::Confusion()) {
255 Sprintf (buf, "bottomRadius %.12g", myBottomRadius);
256 aStatus = Scene().WriteLine (buf);
259 (myHeight - 2.)*(myHeight - 2.) > Precision::Confusion()) {
260 Sprintf (buf, "height %.12g", myHeight);
261 aStatus = Scene().WriteLine (buf);
263 if (OK(aStatus) && myHasBottom == Standard_False)
264 aStatus = Scene().WriteLine ("bottom FALSE");
265 if (OK(aStatus) && myHasSide == Standard_False)
266 aStatus = Scene().WriteLine ("side FALSE");
268 aStatus = WriteClosing();
273 //=======================================================================
274 //function : VrmlData_Cone::IsDefault
276 //=======================================================================
278 // Standard_Boolean VrmlData_Cone::IsDefault () const
281 // (myHasBottom && myHasSide &&
282 // ((myBottomRadius - 1.)*(myBottomRadius-1.) < Precision::Confusion()) &&
283 // ((myHeight - 2.)*(myHeight - 2.) < Precision::Confusion()));
286 //=======================================================================
287 //function : VrmlData_Cylinder::TShape
289 //=======================================================================
291 const Handle(TopoDS_TShape)& VrmlData_Cylinder::TShape ()
293 if (myIsModified && (myHasBottom || myHasSide || myHasTop)) {
295 gp_Ax2 aLocalAxis (gp_Pnt (0., -0.5 * myHeight, 0.),
296 gp_Dir (0., 1., 0.));
297 BRepPrim_Cylinder aBuilder (aLocalAxis, myRadius, myHeight);
298 BRepPrim_Builder aShapeBuilder;
300 aShapeBuilder.MakeShell(aShell);
302 aShapeBuilder.AddShellFace (aShell, aBuilder.LateralFace());
304 aShapeBuilder.AddShellFace (aShell, aBuilder.TopFace());
306 aShapeBuilder.AddShellFace (aShell, aBuilder.BottomFace());
307 myTShape = aShell.TShape();
308 myIsModified = Standard_False;
309 } catch (Standard_Failure) {
316 //=======================================================================
317 //function : VrmlData_Cylinder::Clone
319 //=======================================================================
321 Handle(VrmlData_Node) VrmlData_Cylinder::Clone
322 (const Handle(VrmlData_Node)& theOther) const
324 Handle(VrmlData_Cylinder) aResult =
325 Handle(VrmlData_Cylinder)::DownCast (VrmlData_Node::Clone(theOther));
326 if (aResult.IsNull())
327 aResult = new VrmlData_Cylinder(theOther.IsNull()?Scene():theOther->Scene(),
329 aResult->SetRadius (myRadius);
330 aResult->SetHeight (myHeight);
331 aResult->SetFaces (myHasBottom, myHasSide, myHasTop);
335 //=======================================================================
336 //function : VrmlData_Cylinder::Read
338 //=======================================================================
340 VrmlData_ErrorStatus VrmlData_Cylinder::Read (VrmlData_InBuffer& theBuffer)
342 VrmlData_ErrorStatus aStatus;
343 Standard_Boolean hasSide(Standard_True), hasBottom(Standard_True);
344 Standard_Boolean hasTop (Standard_True);
346 while (OK(aStatus, VrmlData_Scene::ReadLine(theBuffer)))
348 if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "radius"))
349 aStatus = Scene().ReadReal (theBuffer, myRadius,
350 Standard_True, Standard_True);
351 else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "height"))
352 aStatus = Scene().ReadReal (theBuffer, myHeight,
353 Standard_True, Standard_True);
354 else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "top")) {
355 if (OK(aStatus, ReadBoolean (theBuffer, hasTop)))
357 } else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "side")) {
358 if (OK(aStatus, ReadBoolean (theBuffer, hasSide)))
360 } else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "bottom")) {
361 if (OK(aStatus, ReadBoolean (theBuffer, hasBottom)))
362 myHasBottom = hasBottom;
370 // Read the terminating (closing) brace
372 aStatus = readBrace (theBuffer);
376 //=======================================================================
377 //function : VrmlData_Cylinder::Write
379 //=======================================================================
381 VrmlData_ErrorStatus VrmlData_Cylinder::Write (const char * thePrefix) const
383 static char header[] = "Cylinder {";
384 VrmlData_ErrorStatus aStatus;
385 if (OK (aStatus, Scene().WriteLine (thePrefix, header, GlobalIndent())))
388 if ((myRadius - 1.)*(myRadius - 1.) > Precision::Confusion()) {
389 Sprintf (buf, "radius %.12g", myRadius);
390 aStatus = Scene().WriteLine (buf);
393 (myHeight - 2.)*(myHeight - 2.) > Precision::Confusion()) {
394 Sprintf (buf, "height %.12g", myHeight);
395 aStatus = Scene().WriteLine (buf);
397 if (OK(aStatus) && myHasBottom == Standard_False)
398 aStatus = Scene().WriteLine ("bottom FALSE");
399 if (OK(aStatus) && myHasSide == Standard_False)
400 aStatus = Scene().WriteLine ("side FALSE");
401 if (OK(aStatus) && myHasTop == Standard_False)
402 aStatus = Scene().WriteLine ("top FALSE");
404 aStatus = WriteClosing();
409 //=======================================================================
410 //function : VrmlData_Cylinder::IsDefault
412 //=======================================================================
414 // Standard_Boolean VrmlData_Cylinder::IsDefault () const
417 // (myHasBottom && myHasSide && myHasTop &&
418 // ((myRadius - 1.)*(myRadius - 1.) < Precision::Confusion()) &&
419 // ((myHeight - 2.)*(myHeight - 2.) < Precision::Confusion()));
422 //=======================================================================
423 //function : VrmlData_Sphere::TShape
425 //=======================================================================
427 const Handle(TopoDS_TShape)& VrmlData_Sphere::TShape ()
431 myTShape = BRepPrim_Sphere(myRadius).Shell().TShape();
432 myIsModified = Standard_False;
433 } catch (Standard_Failure) {
440 //=======================================================================
441 //function : VrmlData_Sphere::Clone
443 //=======================================================================
445 Handle(VrmlData_Node) VrmlData_Sphere::Clone
446 (const Handle(VrmlData_Node)& theOther) const
448 Handle(VrmlData_Sphere) aResult =
449 Handle(VrmlData_Sphere)::DownCast (VrmlData_Node::Clone(theOther));
450 if (aResult.IsNull())
451 aResult = new VrmlData_Sphere(theOther.IsNull()? Scene() :theOther->Scene(),
453 aResult->SetRadius (myRadius);
457 //=======================================================================
458 //function : VrmlData_Sphere::Read
460 //=======================================================================
462 VrmlData_ErrorStatus VrmlData_Sphere::Read (VrmlData_InBuffer& theBuffer)
464 VrmlData_ErrorStatus aStatus;
465 while (OK(aStatus, VrmlData_Scene::ReadLine(theBuffer)))
466 if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "radius"))
467 aStatus = Scene().ReadReal (theBuffer, myRadius,
468 Standard_True, Standard_True);
472 // Read the terminating (closing) brace
474 aStatus = readBrace (theBuffer);
478 //=======================================================================
479 //function : VrmlData_Sphere::Write
481 //=======================================================================
483 VrmlData_ErrorStatus VrmlData_Sphere::Write (const char * thePrefix) const
485 static char header[] = "Sphere {";
486 VrmlData_ErrorStatus aStatus;
487 if (OK (aStatus, Scene().WriteLine (thePrefix, header, GlobalIndent())))
490 Sprintf (buf, "radius %.12g", myRadius);
491 Scene().WriteLine (buf);
492 aStatus = WriteClosing();
497 //=======================================================================
498 //function : VrmlData_Sphere::IsDefault
500 //=======================================================================
502 // Standard_Boolean VrmlData_Sphere::IsDefault () const
504 // return ((myRadius - 1.)*(myRadius - 1.) < Precision::Confusion())
507 //=======================================================================
508 //function : VrmlData_TextureCoordinate::AllocateValues
510 //=======================================================================
512 Standard_Boolean VrmlData_TextureCoordinate::AllocateValues
513 (const Standard_Size theLength)
515 myPoints = reinterpret_cast <const gp_XY *>
516 (Scene().Allocator()->Allocate (theLength*sizeof(gp_XY)));
517 myLength = theLength;
518 return (myPoints != 0L);
521 //=======================================================================
522 //function : VrmlData_TextureCoordinate::Clone
524 //=======================================================================
526 Handle(VrmlData_Node) VrmlData_TextureCoordinate::Clone
527 (const Handle(VrmlData_Node)& theOther) const
529 Handle(VrmlData_TextureCoordinate) aResult =
530 Handle(VrmlData_TextureCoordinate)::DownCast
531 (VrmlData_Node::Clone(theOther));
532 if (aResult.IsNull())
533 aResult = new VrmlData_TextureCoordinate
534 (theOther.IsNull() ? Scene() : theOther->Scene(), Name());
535 if (&aResult->Scene() == &Scene())
536 aResult->SetPoints (myLength, myPoints);
538 aResult->AllocateValues (myLength);
539 for (Standard_Size i = 0; i < myLength; i++)
540 const_cast <gp_XY&> (aResult->myPoints[i]) = myPoints[i];
545 //=======================================================================
546 //function : VrmlData_TextureCoordinate::Read
548 //=======================================================================
550 VrmlData_ErrorStatus VrmlData_TextureCoordinate::Read
551 (VrmlData_InBuffer& theBuffer)
553 VrmlData_ErrorStatus aStatus;
554 NCollection_Vector<gp_XY> vecValues;
555 if (OK(aStatus, VrmlData_Scene::ReadLine(theBuffer))) {
556 // Match the name with the current word in the stream
557 if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "point"))
558 // Read the body of the data node (comma-separated list of duplets)
559 if (OK(aStatus, VrmlData_Scene::ReadLine(theBuffer))) {
560 if (theBuffer.LinePtr[0] != '[') // opening bracket
561 aStatus = VrmlData_VrmlFormatError;
566 if (!OK(aStatus, VrmlData_Scene::ReadLine(theBuffer)))
568 // closing bracket, in case that it follows a comma
569 if (theBuffer.LinePtr[0] == ']') {
573 if (!OK(aStatus, Scene().ReadXY(theBuffer, anXY,
574 Standard_False, Standard_False)))
576 vecValues.Append(anXY);
577 if (!OK(aStatus, VrmlData_Scene::ReadLine(theBuffer)))
579 if (theBuffer.LinePtr[0] == ',') {
581 } else if (theBuffer.LinePtr[0] == ']') { // closing bracket
588 if (OK(aStatus) && OK(aStatus, readBrace (theBuffer))) {
589 myLength = vecValues.Length();
591 gp_XY * aPoints = reinterpret_cast <gp_XY *>
592 (Scene().Allocator()->Allocate (myLength * sizeof(gp_XY)));
594 for (Standard_Integer i = 0; i < Standard_Integer(myLength); i++)
595 aPoints[i] = vecValues(i);
602 //=======================================================================
603 //function : VrmlData_ArrayVec3d::Clone
605 //=======================================================================
607 // Handle(VrmlData_Node) VrmlData_ArrayVec3d::Clone
608 // (const Handle(VrmlData_Node)& theOther) const
610 // VrmlData_Node::Clone (theOther);
611 // const Handle(VrmlData_ArrayVec3d) anArrayNode =
612 // Handle(VrmlData_ArrayVec3d)::DownCast (theOther);
613 // if (anArrayNode.IsNull() == Standard_False)
614 // anArrayNode->SetValues (myLength, myArray);
618 //=======================================================================
619 //function : VrmlData_ArrayVec3d::ReadArray
621 //=======================================================================
623 VrmlData_ErrorStatus VrmlData_ArrayVec3d::ReadArray
624 (VrmlData_InBuffer& theBuffer,
625 const char * theName,
626 const Standard_Boolean isScale)
628 VrmlData_ErrorStatus aStatus;
629 NCollection_Vector<gp_XYZ> vecValues;
630 if (OK(aStatus, VrmlData_Scene::ReadLine(theBuffer))) {
631 // Match the name with the current word in the stream
633 const Standard_Size aNameLen = strlen(theName);
634 if (strncmp (theBuffer.LinePtr, theName, aNameLen))
635 aStatus = VrmlData_VrmlFormatError;
637 theBuffer.LinePtr += aNameLen;
639 // Skip the word in the input
640 while (theBuffer.LinePtr[0] != ' ' &&
641 theBuffer.LinePtr[0] != ',' &&
642 theBuffer.LinePtr[0] != '\t' &&
643 theBuffer.LinePtr[0] != '\n' &&
644 theBuffer.LinePtr[0] != '\r' &&
645 theBuffer.LinePtr[0] != '\0')
648 // Read the body of the data node (list of triplets)
649 if (OK(aStatus) && OK(aStatus, VrmlData_Scene::ReadLine(theBuffer))) {
650 if (theBuffer.LinePtr[0] != '[') // opening bracket
651 aStatus = VrmlData_VrmlFormatError;
656 if (!OK(aStatus, VrmlData_Scene::ReadLine(theBuffer)))
658 // closing bracket, in case that it follows a comma
659 if (theBuffer.LinePtr[0] == ']') {
663 // Read three numbers (XYZ value)
664 if (!OK(aStatus, Scene().ReadXYZ(theBuffer, anXYZ,
665 isScale, Standard_False)))
667 vecValues.Append(anXYZ);
668 if (!OK(aStatus, VrmlData_Scene::ReadLine(theBuffer)))
670 if (theBuffer.LinePtr[0] == ']') {// closing bracket
677 if (OK(aStatus) && OK(aStatus, readBrace (theBuffer))) {
678 myLength = vecValues.Length();
680 gp_XYZ * anArray = reinterpret_cast <gp_XYZ *>
681 (Scene().Allocator()->Allocate (myLength * sizeof(gp_XYZ)));
683 for (Standard_Integer i = 0; i < Standard_Integer(myLength); i++)
684 anArray[i] = vecValues(i);
691 //=======================================================================
692 //function : VrmlData_ArrayVec3d::WriteArray
694 //=======================================================================
696 VrmlData_ErrorStatus VrmlData_ArrayVec3d::WriteArray
697 (const char * theName,
698 const Standard_Boolean isScale) const
700 VrmlData_ErrorStatus aStatus (VrmlData_StatusOK);
702 aStatus = Scene().WriteLine (theName, "[", 2*GlobalIndent());
704 for (Standard_Size i = 0; i < myLength-1; i++)
705 if (!OK (aStatus, Scene().WriteXYZ (myArray[i], isScale, ",")))
708 aStatus = Scene().WriteXYZ (myArray[myLength-1], isScale);
710 if (aStatus == VrmlData_StatusOK)
711 aStatus = Scene().WriteLine ("]", 0L, -2*GlobalIndent());
716 //=======================================================================
717 //function : VrmlData_ArrayVec3d::IsDefault
719 //=======================================================================
721 Standard_Boolean VrmlData_ArrayVec3d::IsDefault () const
723 return myLength == 0;
726 //=======================================================================
727 //function : VrmlData_Coodinate::Clone
729 //=======================================================================
731 Handle(VrmlData_Node) VrmlData_Coordinate::Clone
732 (const Handle(VrmlData_Node)& theOther) const
734 Handle(VrmlData_Coordinate) aResult =
735 Handle(VrmlData_Coordinate)::DownCast (VrmlData_Node::Clone(theOther));
736 if (aResult.IsNull())
737 aResult = new VrmlData_Coordinate
738 (theOther.IsNull() ? Scene() : theOther->Scene(), Name());
739 if (&aResult->Scene() == &Scene())
740 aResult->SetValues (Length(), Values());
742 aResult->AllocateValues (Length());
743 for (Standard_Size i = 0; i < Length(); i++)
744 const_cast <gp_XYZ&> (aResult->Values()[i]) = Values()[i];
749 //=======================================================================
750 //function : VrmlData_Coordinate::Read
752 //=======================================================================
754 VrmlData_ErrorStatus VrmlData_Coordinate::Read (VrmlData_InBuffer& theBuffer)
756 return VrmlData_ArrayVec3d::ReadArray (theBuffer, "point", Standard_True);
759 //=======================================================================
760 //function : VrmlData_Coordinate::Write
762 //=======================================================================
764 VrmlData_ErrorStatus VrmlData_Coordinate::Write (const char * thePrefix) const
766 static char header[] = "Coordinate {";
767 VrmlData_ErrorStatus aStatus;
768 if (OK (aStatus, Scene().WriteLine (thePrefix, header, GlobalIndent())))
770 WriteArray ("point", Standard_True);
771 aStatus = WriteClosing();
776 //=======================================================================
777 //function : VrmlData_Color::Clone
779 //=======================================================================
781 Handle(VrmlData_Node) VrmlData_Color::Clone
782 (const Handle(VrmlData_Node)& theOther) const
784 Handle(VrmlData_Color) aResult =
785 Handle(VrmlData_Color)::DownCast (VrmlData_Node::Clone(theOther));
786 if (aResult.IsNull())
787 aResult = new VrmlData_Color(theOther.IsNull()? Scene() : theOther->Scene(),
789 if (&aResult->Scene() == &Scene())
790 aResult->SetValues (Length(), Values());
792 aResult->AllocateValues (Length());
793 for (Standard_Size i = 0; i < Length(); i++)
794 const_cast <gp_XYZ&> (aResult->Values()[i]) = Values()[i];
799 //=======================================================================
800 //function : VrmlData_Color::Read
802 //=======================================================================
804 VrmlData_ErrorStatus VrmlData_Color::Read (VrmlData_InBuffer& theBuffer)
806 return ReadArray (theBuffer, "color", Standard_False);
809 //=======================================================================
810 //function : VrmlData_Color::Write
812 //=======================================================================
814 VrmlData_ErrorStatus VrmlData_Color::Write (const char * thePrefix) const
816 static char header[] = "Color {";
817 VrmlData_ErrorStatus aStatus;
818 if (OK (aStatus, Scene().WriteLine (thePrefix, header, GlobalIndent())))
820 WriteArray ("color", Standard_False);
821 aStatus = WriteClosing();
826 //=======================================================================
827 //function : VrmlData_Normal::Clone
829 //=======================================================================
831 Handle(VrmlData_Node) VrmlData_Normal::Clone
832 (const Handle(VrmlData_Node)& theOther) const
834 Handle(VrmlData_Normal) aResult =
835 Handle(VrmlData_Normal)::DownCast (VrmlData_Node::Clone(theOther));
836 if (aResult.IsNull())
837 aResult= new VrmlData_Normal(theOther.IsNull()? Scene() : theOther->Scene(),
839 if (&aResult->Scene() == &Scene())
840 aResult->SetValues (Length(), Values());
842 aResult->AllocateValues (Length());
843 for (Standard_Size i = 0; i < Length(); i++)
844 const_cast <gp_XYZ&> (aResult->Values()[i]) = Values()[i];
849 //=======================================================================
850 //function : VrmlData_Normal::Read
852 //=======================================================================
854 VrmlData_ErrorStatus VrmlData_Normal::Read (VrmlData_InBuffer& theBuffer)
856 return VrmlData_ArrayVec3d::ReadArray (theBuffer, "vector", Standard_False);
859 //=======================================================================
860 //function : VrmlData_Normal::Write
862 //=======================================================================
864 VrmlData_ErrorStatus VrmlData_Normal::Write (const char * thePrefix) const
866 static char header[] = "Normal {";
867 VrmlData_ErrorStatus aStatus;
868 if (OK (aStatus, Scene().WriteLine (thePrefix, header, GlobalIndent())))
870 WriteArray ("vector", Standard_False);
871 aStatus = WriteClosing();