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>
36 IMPLEMENT_STANDARD_RTTIEXT(VrmlData_Geometry,VrmlData_Node)
39 #define _CRT_SECURE_NO_DEPRECATE
40 #pragma warning (disable:4996)
43 //=======================================================================
46 //=======================================================================
48 const gp_XYZ& VrmlData_ArrayVec3d::Value (const Standard_Size i) const
50 static gp_XYZ anOrigin (0., 0., 0.);
51 return i < myLength ? myArray[i] : anOrigin;
54 //=======================================================================
55 //function : AllocateValues
57 //=======================================================================
59 Standard_Boolean VrmlData_ArrayVec3d::AllocateValues
60 (const Standard_Size theLength)
62 myArray = reinterpret_cast <const gp_XYZ *>
63 (Scene().Allocator()->Allocate (theLength*sizeof(gp_XYZ)));
65 return (myArray != 0L);
68 //=======================================================================
69 //function : VrmlData_Box::TShape
71 //=======================================================================
73 const Handle(TopoDS_TShape)& VrmlData_Box::TShape ()
77 const TopoDS_Shell aShell =
78 BRepPrimAPI_MakeBox (gp_Pnt (-0.5 * mySize),
79 mySize.X(), mySize.Y(), mySize.Z());
80 SetTShape (aShell.TShape());
81 myIsModified = Standard_False;
82 } catch (Standard_Failure) {
89 //=======================================================================
90 //function : VrmlData_Box::Clone
92 //=======================================================================
94 Handle(VrmlData_Node) VrmlData_Box::Clone
95 (const Handle(VrmlData_Node)& theOther) const
97 Handle(VrmlData_Box) aResult =
98 Handle(VrmlData_Box)::DownCast (VrmlData_Node::Clone(theOther));
100 aResult = new VrmlData_Box (theOther.IsNull() ? Scene() : theOther->Scene(),
102 aResult->SetSize(mySize);
106 //=======================================================================
107 //function : VrmlData_Box::Read
109 //=======================================================================
111 VrmlData_ErrorStatus VrmlData_Box::Read (VrmlData_InBuffer& theBuffer)
113 VrmlData_ErrorStatus aStatus;
114 if (OK(aStatus, VrmlData_Scene::ReadLine(theBuffer))) {
115 if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "size"))
116 aStatus = Scene().ReadXYZ (theBuffer, mySize,
117 Standard_True, Standard_True);
119 aStatus = readBrace (theBuffer);
124 //=======================================================================
125 //function : VrmlData_Box::Write
127 //=======================================================================
129 VrmlData_ErrorStatus VrmlData_Box::Write (const char * thePrefix) const
131 static char header[] = "Box {";
132 VrmlData_ErrorStatus aStatus;
133 if (OK (aStatus, Scene().WriteLine (thePrefix, header, GlobalIndent())))
136 Sprintf (buf, "size %.12g %.12g %.12g", mySize.X(), mySize.Y(), mySize.Z());
137 Scene().WriteLine (buf);
138 aStatus = WriteClosing();
143 //=======================================================================
144 //function : VrmlData_Cone::TShape
146 //=======================================================================
148 const Handle(TopoDS_TShape)& VrmlData_Cone::TShape ()
150 if (myIsModified && (myHasBottom || myHasSide)) {
152 gp_Ax2 aLocalAxis (gp_Pnt (0., -0.5 * myHeight, 0.),
153 gp_Dir (0., 1., 0.));
154 BRepPrim_Cone aBuilder (aLocalAxis, myBottomRadius, 0., myHeight);
156 myTShape = aBuilder.LateralFace().TShape();
158 myTShape = aBuilder.BottomFace().TShape();
160 myTShape = aBuilder.Shell().TShape();
161 myIsModified = Standard_False;
162 } catch (Standard_Failure) {
169 //=======================================================================
170 //function : VrmlData_Cone::Clone
172 //=======================================================================
174 Handle(VrmlData_Node) VrmlData_Cone::Clone
175 (const Handle(VrmlData_Node)& theOther) const
177 Handle(VrmlData_Cone) aResult =
178 Handle(VrmlData_Cone)::DownCast (VrmlData_Node::Clone(theOther));
179 if (aResult.IsNull())
180 aResult = new VrmlData_Cone (theOther.IsNull() ? Scene(): theOther->Scene(),
183 aResult->SetBottomRadius (myBottomRadius);
184 aResult->SetHeight (myHeight);
185 aResult->SetFaces (myHasBottom, myHasSide);
189 //=======================================================================
190 //function : VrmlData_Cone::Read
192 //=======================================================================
194 VrmlData_ErrorStatus VrmlData_Cone::Read (VrmlData_InBuffer& theBuffer)
196 VrmlData_ErrorStatus aStatus;
197 Standard_Boolean hasSide(Standard_True), hasBottom(Standard_True);
199 while (OK(aStatus, VrmlData_Scene::ReadLine(theBuffer)))
201 if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "bottomRadius"))
202 aStatus = Scene().ReadReal (theBuffer, myBottomRadius,
203 Standard_True, Standard_True);
204 else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "height"))
205 aStatus = Scene().ReadReal (theBuffer, myHeight,
206 Standard_True, Standard_True);
207 else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "side")) {
208 if (OK(aStatus, ReadBoolean (theBuffer, hasSide)))
210 } else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "bottom")) {
211 if (OK(aStatus, ReadBoolean (theBuffer, hasBottom)))
212 myHasBottom = hasBottom;
219 // Read the terminating (closing) brace
221 aStatus = readBrace (theBuffer);
225 //=======================================================================
226 //function : VrmlData_Cone::Write
228 //=======================================================================
230 VrmlData_ErrorStatus VrmlData_Cone::Write (const char * thePrefix) const
232 static char header[] = "Cone {";
233 VrmlData_ErrorStatus aStatus;
234 if (OK (aStatus, Scene().WriteLine (thePrefix, header, GlobalIndent())))
237 if ((myBottomRadius - 1.)*(myBottomRadius - 1.) > Precision::Confusion()) {
238 Sprintf (buf, "bottomRadius %.12g", myBottomRadius);
239 aStatus = Scene().WriteLine (buf);
242 (myHeight - 2.)*(myHeight - 2.) > Precision::Confusion()) {
243 Sprintf (buf, "height %.12g", myHeight);
244 aStatus = Scene().WriteLine (buf);
246 if (OK(aStatus) && myHasBottom == Standard_False)
247 aStatus = Scene().WriteLine ("bottom FALSE");
248 if (OK(aStatus) && myHasSide == Standard_False)
249 aStatus = Scene().WriteLine ("side FALSE");
251 aStatus = WriteClosing();
256 //=======================================================================
257 //function : VrmlData_Cone::IsDefault
259 //=======================================================================
261 // Standard_Boolean VrmlData_Cone::IsDefault () const
264 // (myHasBottom && myHasSide &&
265 // ((myBottomRadius - 1.)*(myBottomRadius-1.) < Precision::Confusion()) &&
266 // ((myHeight - 2.)*(myHeight - 2.) < Precision::Confusion()));
269 //=======================================================================
270 //function : VrmlData_Cylinder::TShape
272 //=======================================================================
274 const Handle(TopoDS_TShape)& VrmlData_Cylinder::TShape ()
276 if (myIsModified && (myHasBottom || myHasSide || myHasTop)) {
278 gp_Ax2 aLocalAxis (gp_Pnt (0., -0.5 * myHeight, 0.),
279 gp_Dir (0., 1., 0.));
280 BRepPrim_Cylinder aBuilder (aLocalAxis, myRadius, myHeight);
281 BRepPrim_Builder aShapeBuilder;
283 aShapeBuilder.MakeShell(aShell);
285 aShapeBuilder.AddShellFace (aShell, aBuilder.LateralFace());
287 aShapeBuilder.AddShellFace (aShell, aBuilder.TopFace());
289 aShapeBuilder.AddShellFace (aShell, aBuilder.BottomFace());
290 myTShape = aShell.TShape();
291 myIsModified = Standard_False;
292 } catch (Standard_Failure) {
299 //=======================================================================
300 //function : VrmlData_Cylinder::Clone
302 //=======================================================================
304 Handle(VrmlData_Node) VrmlData_Cylinder::Clone
305 (const Handle(VrmlData_Node)& theOther) const
307 Handle(VrmlData_Cylinder) aResult =
308 Handle(VrmlData_Cylinder)::DownCast (VrmlData_Node::Clone(theOther));
309 if (aResult.IsNull())
310 aResult = new VrmlData_Cylinder(theOther.IsNull()?Scene():theOther->Scene(),
312 aResult->SetRadius (myRadius);
313 aResult->SetHeight (myHeight);
314 aResult->SetFaces (myHasBottom, myHasSide, myHasTop);
318 //=======================================================================
319 //function : VrmlData_Cylinder::Read
321 //=======================================================================
323 VrmlData_ErrorStatus VrmlData_Cylinder::Read (VrmlData_InBuffer& theBuffer)
325 VrmlData_ErrorStatus aStatus;
326 Standard_Boolean hasSide(Standard_True), hasBottom(Standard_True);
327 Standard_Boolean hasTop (Standard_True);
329 while (OK(aStatus, VrmlData_Scene::ReadLine(theBuffer)))
331 if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "radius"))
332 aStatus = Scene().ReadReal (theBuffer, myRadius,
333 Standard_True, Standard_True);
334 else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "height"))
335 aStatus = Scene().ReadReal (theBuffer, myHeight,
336 Standard_True, Standard_True);
337 else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "top")) {
338 if (OK(aStatus, ReadBoolean (theBuffer, hasTop)))
340 } else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "side")) {
341 if (OK(aStatus, ReadBoolean (theBuffer, hasSide)))
343 } else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "bottom")) {
344 if (OK(aStatus, ReadBoolean (theBuffer, hasBottom)))
345 myHasBottom = hasBottom;
353 // Read the terminating (closing) brace
355 aStatus = readBrace (theBuffer);
359 //=======================================================================
360 //function : VrmlData_Cylinder::Write
362 //=======================================================================
364 VrmlData_ErrorStatus VrmlData_Cylinder::Write (const char * thePrefix) const
366 static char header[] = "Cylinder {";
367 VrmlData_ErrorStatus aStatus;
368 if (OK (aStatus, Scene().WriteLine (thePrefix, header, GlobalIndent())))
371 if ((myRadius - 1.)*(myRadius - 1.) > Precision::Confusion()) {
372 Sprintf (buf, "radius %.12g", myRadius);
373 aStatus = Scene().WriteLine (buf);
376 (myHeight - 2.)*(myHeight - 2.) > Precision::Confusion()) {
377 Sprintf (buf, "height %.12g", myHeight);
378 aStatus = Scene().WriteLine (buf);
380 if (OK(aStatus) && myHasBottom == Standard_False)
381 aStatus = Scene().WriteLine ("bottom FALSE");
382 if (OK(aStatus) && myHasSide == Standard_False)
383 aStatus = Scene().WriteLine ("side FALSE");
384 if (OK(aStatus) && myHasTop == Standard_False)
385 aStatus = Scene().WriteLine ("top FALSE");
387 aStatus = WriteClosing();
392 //=======================================================================
393 //function : VrmlData_Cylinder::IsDefault
395 //=======================================================================
397 // Standard_Boolean VrmlData_Cylinder::IsDefault () const
400 // (myHasBottom && myHasSide && myHasTop &&
401 // ((myRadius - 1.)*(myRadius - 1.) < Precision::Confusion()) &&
402 // ((myHeight - 2.)*(myHeight - 2.) < Precision::Confusion()));
405 //=======================================================================
406 //function : VrmlData_Sphere::TShape
408 //=======================================================================
410 const Handle(TopoDS_TShape)& VrmlData_Sphere::TShape ()
414 myTShape = BRepPrim_Sphere(myRadius).Shell().TShape();
415 myIsModified = Standard_False;
416 } catch (Standard_Failure) {
423 //=======================================================================
424 //function : VrmlData_Sphere::Clone
426 //=======================================================================
428 Handle(VrmlData_Node) VrmlData_Sphere::Clone
429 (const Handle(VrmlData_Node)& theOther) const
431 Handle(VrmlData_Sphere) aResult =
432 Handle(VrmlData_Sphere)::DownCast (VrmlData_Node::Clone(theOther));
433 if (aResult.IsNull())
434 aResult = new VrmlData_Sphere(theOther.IsNull()? Scene() :theOther->Scene(),
436 aResult->SetRadius (myRadius);
440 //=======================================================================
441 //function : VrmlData_Sphere::Read
443 //=======================================================================
445 VrmlData_ErrorStatus VrmlData_Sphere::Read (VrmlData_InBuffer& theBuffer)
447 VrmlData_ErrorStatus aStatus;
448 while (OK(aStatus, VrmlData_Scene::ReadLine(theBuffer)))
449 if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "radius"))
450 aStatus = Scene().ReadReal (theBuffer, myRadius,
451 Standard_True, Standard_True);
455 // Read the terminating (closing) brace
457 aStatus = readBrace (theBuffer);
461 //=======================================================================
462 //function : VrmlData_Sphere::Write
464 //=======================================================================
466 VrmlData_ErrorStatus VrmlData_Sphere::Write (const char * thePrefix) const
468 static char header[] = "Sphere {";
469 VrmlData_ErrorStatus aStatus;
470 if (OK (aStatus, Scene().WriteLine (thePrefix, header, GlobalIndent())))
473 Sprintf (buf, "radius %.12g", myRadius);
474 Scene().WriteLine (buf);
475 aStatus = WriteClosing();
480 //=======================================================================
481 //function : VrmlData_Sphere::IsDefault
483 //=======================================================================
485 // Standard_Boolean VrmlData_Sphere::IsDefault () const
487 // return ((myRadius - 1.)*(myRadius - 1.) < Precision::Confusion())
490 //=======================================================================
491 //function : VrmlData_TextureCoordinate::AllocateValues
493 //=======================================================================
495 Standard_Boolean VrmlData_TextureCoordinate::AllocateValues
496 (const Standard_Size theLength)
498 myPoints = reinterpret_cast <const gp_XY *>
499 (Scene().Allocator()->Allocate (theLength*sizeof(gp_XY)));
500 myLength = theLength;
501 return (myPoints != 0L);
504 //=======================================================================
505 //function : VrmlData_TextureCoordinate::Clone
507 //=======================================================================
509 Handle(VrmlData_Node) VrmlData_TextureCoordinate::Clone
510 (const Handle(VrmlData_Node)& theOther) const
512 Handle(VrmlData_TextureCoordinate) aResult =
513 Handle(VrmlData_TextureCoordinate)::DownCast
514 (VrmlData_Node::Clone(theOther));
515 if (aResult.IsNull())
516 aResult = new VrmlData_TextureCoordinate
517 (theOther.IsNull() ? Scene() : theOther->Scene(), Name());
518 if (&aResult->Scene() == &Scene())
519 aResult->SetPoints (myLength, myPoints);
521 aResult->AllocateValues (myLength);
522 for (Standard_Size i = 0; i < myLength; i++)
523 const_cast <gp_XY&> (aResult->myPoints[i]) = myPoints[i];
528 //=======================================================================
529 //function : VrmlData_TextureCoordinate::Read
531 //=======================================================================
533 VrmlData_ErrorStatus VrmlData_TextureCoordinate::Read
534 (VrmlData_InBuffer& theBuffer)
536 VrmlData_ErrorStatus aStatus;
537 NCollection_Vector<gp_XY> vecValues;
538 if (OK(aStatus, VrmlData_Scene::ReadLine(theBuffer))) {
539 // Match the name with the current word in the stream
540 if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "point"))
541 // Read the body of the data node (comma-separated list of duplets)
542 if (OK(aStatus, VrmlData_Scene::ReadLine(theBuffer))) {
543 if (theBuffer.LinePtr[0] != '[') // opening bracket
544 aStatus = VrmlData_VrmlFormatError;
549 if (!OK(aStatus, VrmlData_Scene::ReadLine(theBuffer)))
551 // closing bracket, in case that it follows a comma
552 if (theBuffer.LinePtr[0] == ']') {
556 if (!OK(aStatus, Scene().ReadXY(theBuffer, anXY,
557 Standard_False, Standard_False)))
559 vecValues.Append(anXY);
560 if (!OK(aStatus, VrmlData_Scene::ReadLine(theBuffer)))
562 if (theBuffer.LinePtr[0] == ',') {
564 } else if (theBuffer.LinePtr[0] == ']') { // closing bracket
571 if (OK(aStatus) && OK(aStatus, readBrace (theBuffer))) {
572 myLength = vecValues.Length();
574 gp_XY * aPoints = reinterpret_cast <gp_XY *>
575 (Scene().Allocator()->Allocate (myLength * sizeof(gp_XY)));
577 for (Standard_Integer i = 0; i < Standard_Integer(myLength); i++)
578 aPoints[i] = vecValues(i);
585 //=======================================================================
586 //function : VrmlData_ArrayVec3d::Clone
588 //=======================================================================
590 // Handle(VrmlData_Node) VrmlData_ArrayVec3d::Clone
591 // (const Handle(VrmlData_Node)& theOther) const
593 // VrmlData_Node::Clone (theOther);
594 // const Handle(VrmlData_ArrayVec3d) anArrayNode =
595 // Handle(VrmlData_ArrayVec3d)::DownCast (theOther);
596 // if (anArrayNode.IsNull() == Standard_False)
597 // anArrayNode->SetValues (myLength, myArray);
601 //=======================================================================
602 //function : VrmlData_ArrayVec3d::ReadArray
604 //=======================================================================
606 VrmlData_ErrorStatus VrmlData_ArrayVec3d::ReadArray
607 (VrmlData_InBuffer& theBuffer,
608 const char * theName,
609 const Standard_Boolean isScale)
611 VrmlData_ErrorStatus aStatus;
612 NCollection_Vector<gp_XYZ> vecValues;
613 if (OK(aStatus, VrmlData_Scene::ReadLine(theBuffer))) {
614 // Match the name with the current word in the stream
616 const Standard_Size aNameLen = strlen(theName);
617 if (strncmp (theBuffer.LinePtr, theName, aNameLen))
618 aStatus = VrmlData_VrmlFormatError;
620 theBuffer.LinePtr += aNameLen;
622 // Skip the word in the input
623 while (theBuffer.LinePtr[0] != ' ' &&
624 theBuffer.LinePtr[0] != ',' &&
625 theBuffer.LinePtr[0] != '\t' &&
626 theBuffer.LinePtr[0] != '\n' &&
627 theBuffer.LinePtr[0] != '\r' &&
628 theBuffer.LinePtr[0] != '\0')
631 // Read the body of the data node (list of triplets)
632 if (OK(aStatus) && OK(aStatus, VrmlData_Scene::ReadLine(theBuffer))) {
633 if (theBuffer.LinePtr[0] != '[') // opening bracket
635 // Handle case when brackets are ommited for single element of array
637 // Read three numbers (XYZ value)
638 if (!OK(aStatus, Scene().ReadXYZ(theBuffer, anXYZ,
639 isScale, Standard_False)))
640 aStatus = VrmlData_VrmlFormatError;
642 vecValues.Append(anXYZ);
648 if (!OK(aStatus, VrmlData_Scene::ReadLine(theBuffer)))
650 // closing bracket, in case that it follows a comma
651 if (theBuffer.LinePtr[0] == ']') {
655 // Read three numbers (XYZ value)
656 if (!OK(aStatus, Scene().ReadXYZ(theBuffer, anXYZ,
657 isScale, Standard_False)))
659 vecValues.Append(anXYZ);
660 if (!OK(aStatus, VrmlData_Scene::ReadLine(theBuffer)))
662 if (theBuffer.LinePtr[0] == ']') {// closing bracket
669 if (OK(aStatus) && OK(aStatus, readBrace (theBuffer))) {
670 myLength = vecValues.Length();
672 gp_XYZ * anArray = reinterpret_cast <gp_XYZ *>
673 (Scene().Allocator()->Allocate (myLength * sizeof(gp_XYZ)));
675 for (Standard_Integer i = 0; i < Standard_Integer(myLength); i++)
676 anArray[i] = vecValues(i);
683 //=======================================================================
684 //function : VrmlData_ArrayVec3d::WriteArray
686 //=======================================================================
688 VrmlData_ErrorStatus VrmlData_ArrayVec3d::WriteArray
689 (const char * theName,
690 const Standard_Boolean isScale) const
692 VrmlData_ErrorStatus aStatus (VrmlData_StatusOK);
694 aStatus = Scene().WriteLine (theName, "[", 2*GlobalIndent());
696 for (Standard_Size i = 0; i < myLength-1; i++)
697 if (!OK (aStatus, Scene().WriteXYZ (myArray[i], isScale, ",")))
700 aStatus = Scene().WriteXYZ (myArray[myLength-1], isScale);
702 if (aStatus == VrmlData_StatusOK)
703 aStatus = Scene().WriteLine ("]", 0L, -2*GlobalIndent());
708 //=======================================================================
709 //function : VrmlData_ArrayVec3d::IsDefault
711 //=======================================================================
713 Standard_Boolean VrmlData_ArrayVec3d::IsDefault () const
715 return myLength == 0;
718 //=======================================================================
719 //function : VrmlData_Coodinate::Clone
721 //=======================================================================
723 Handle(VrmlData_Node) VrmlData_Coordinate::Clone
724 (const Handle(VrmlData_Node)& theOther) const
726 Handle(VrmlData_Coordinate) aResult =
727 Handle(VrmlData_Coordinate)::DownCast (VrmlData_Node::Clone(theOther));
728 if (aResult.IsNull())
729 aResult = new VrmlData_Coordinate
730 (theOther.IsNull() ? Scene() : theOther->Scene(), Name());
731 if (&aResult->Scene() == &Scene())
732 aResult->SetValues (Length(), Values());
734 aResult->AllocateValues (Length());
735 for (Standard_Size i = 0; i < Length(); i++)
736 const_cast <gp_XYZ&> (aResult->Values()[i]) = Values()[i];
741 //=======================================================================
742 //function : VrmlData_Coordinate::Read
744 //=======================================================================
746 VrmlData_ErrorStatus VrmlData_Coordinate::Read (VrmlData_InBuffer& theBuffer)
748 return VrmlData_ArrayVec3d::ReadArray (theBuffer, "point", Standard_True);
751 //=======================================================================
752 //function : VrmlData_Coordinate::Write
754 //=======================================================================
756 VrmlData_ErrorStatus VrmlData_Coordinate::Write (const char * thePrefix) const
758 static char header[] = "Coordinate {";
759 VrmlData_ErrorStatus aStatus;
760 if (OK (aStatus, Scene().WriteLine (thePrefix, header, GlobalIndent())))
762 WriteArray ("point", Standard_True);
763 aStatus = WriteClosing();
768 //=======================================================================
769 //function : VrmlData_Color::Clone
771 //=======================================================================
773 Handle(VrmlData_Node) VrmlData_Color::Clone
774 (const Handle(VrmlData_Node)& theOther) const
776 Handle(VrmlData_Color) aResult =
777 Handle(VrmlData_Color)::DownCast (VrmlData_Node::Clone(theOther));
778 if (aResult.IsNull())
779 aResult = new VrmlData_Color(theOther.IsNull()? Scene() : theOther->Scene(),
781 if (&aResult->Scene() == &Scene())
782 aResult->SetValues (Length(), Values());
784 aResult->AllocateValues (Length());
785 for (Standard_Size i = 0; i < Length(); i++)
786 const_cast <gp_XYZ&> (aResult->Values()[i]) = Values()[i];
791 //=======================================================================
792 //function : VrmlData_Color::Read
794 //=======================================================================
796 VrmlData_ErrorStatus VrmlData_Color::Read (VrmlData_InBuffer& theBuffer)
798 return ReadArray (theBuffer, "color", Standard_False);
801 //=======================================================================
802 //function : VrmlData_Color::Write
804 //=======================================================================
806 VrmlData_ErrorStatus VrmlData_Color::Write (const char * thePrefix) const
808 static char header[] = "Color {";
809 VrmlData_ErrorStatus aStatus;
810 if (OK (aStatus, Scene().WriteLine (thePrefix, header, GlobalIndent())))
812 WriteArray ("color", Standard_False);
813 aStatus = WriteClosing();
818 //=======================================================================
819 //function : VrmlData_Normal::Clone
821 //=======================================================================
823 Handle(VrmlData_Node) VrmlData_Normal::Clone
824 (const Handle(VrmlData_Node)& theOther) const
826 Handle(VrmlData_Normal) aResult =
827 Handle(VrmlData_Normal)::DownCast (VrmlData_Node::Clone(theOther));
828 if (aResult.IsNull())
829 aResult= new VrmlData_Normal(theOther.IsNull()? Scene() : theOther->Scene(),
831 if (&aResult->Scene() == &Scene())
832 aResult->SetValues (Length(), Values());
834 aResult->AllocateValues (Length());
835 for (Standard_Size i = 0; i < Length(); i++)
836 const_cast <gp_XYZ&> (aResult->Values()[i]) = Values()[i];
841 //=======================================================================
842 //function : VrmlData_Normal::Read
844 //=======================================================================
846 VrmlData_ErrorStatus VrmlData_Normal::Read (VrmlData_InBuffer& theBuffer)
848 return VrmlData_ArrayVec3d::ReadArray (theBuffer, "vector", Standard_False);
851 //=======================================================================
852 //function : VrmlData_Normal::Write
854 //=======================================================================
856 VrmlData_ErrorStatus VrmlData_Normal::Write (const char * thePrefix) const
858 static char header[] = "Normal {";
859 VrmlData_ErrorStatus aStatus;
860 if (OK (aStatus, Scene().WriteLine (thePrefix, header, GlobalIndent())))
862 WriteArray ("vector", Standard_False);
863 aStatus = WriteClosing();