1 // Created on: 2006-05-25
2 // Created by: Alexander GRIGORIEV
3 // Copyright (c) 2006-2012 OPEN CASCADE SAS
5 // The content of this file is subject to the Open CASCADE Technology Public
6 // License Version 6.5 (the "License"). You may not use the content of this file
7 // except in compliance with the License. Please obtain a copy of the License
8 // at http://www.opencascade.org and read it completely before using this file.
10 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 // The Original Code and all software distributed under the License is
14 // distributed on an "AS IS" basis, without warranty of any kind, and the
15 // Initial Developer hereby disclaims all such warranties, including without
16 // limitation, any warranties of merchantability, fitness for a particular
17 // purpose or non-infringement. Please see the License for the specific terms
18 // and conditions governing the rights and limitations under the License.
22 #include <VrmlData_Scene.hxx>
23 #include <VrmlData_Coordinate.hxx>
24 #include <VrmlData_Color.hxx>
25 #include <VrmlData_Normal.hxx>
26 #include <VrmlData_TextureCoordinate.hxx>
27 #include <VrmlData_InBuffer.hxx>
28 #include <VrmlData_Box.hxx>
29 #include <VrmlData_Cone.hxx>
30 #include <VrmlData_Cylinder.hxx>
31 #include <VrmlData_Sphere.hxx>
32 #include <VrmlData_UnknownNode.hxx>
33 #include <BRepPrimAPI_MakeBox.hxx>
34 #include <BRepPrim_Cone.hxx>
35 #include <BRepPrim_Cylinder.hxx>
36 #include <BRepPrim_Sphere.hxx>
37 #include <BRepPrim_Builder.hxx>
38 #include <NCollection_Vector.hxx>
39 #include <Standard_ErrorHandler.hxx>
42 #define _CRT_SECURE_NO_DEPRECATE
43 #pragma warning (disable:4996)
46 IMPLEMENT_STANDARD_HANDLE (VrmlData_Geometry, VrmlData_Node)
47 IMPLEMENT_STANDARD_RTTIEXT (VrmlData_Geometry, VrmlData_Node)
48 IMPLEMENT_STANDARD_HANDLE (VrmlData_Box, VrmlData_Geometry)
49 IMPLEMENT_STANDARD_RTTIEXT (VrmlData_Box, VrmlData_Geometry)
50 IMPLEMENT_STANDARD_HANDLE (VrmlData_Cone, VrmlData_Geometry)
51 IMPLEMENT_STANDARD_RTTIEXT (VrmlData_Cone, VrmlData_Geometry)
52 IMPLEMENT_STANDARD_HANDLE (VrmlData_Cylinder, VrmlData_Geometry)
53 IMPLEMENT_STANDARD_RTTIEXT (VrmlData_Cylinder, VrmlData_Geometry)
54 IMPLEMENT_STANDARD_HANDLE (VrmlData_Sphere, VrmlData_Geometry)
55 IMPLEMENT_STANDARD_RTTIEXT (VrmlData_Sphere, VrmlData_Geometry)
56 IMPLEMENT_STANDARD_HANDLE (VrmlData_ArrayVec3d, VrmlData_Node)
57 IMPLEMENT_STANDARD_RTTIEXT (VrmlData_ArrayVec3d, VrmlData_Node)
58 IMPLEMENT_STANDARD_HANDLE (VrmlData_Color, VrmlData_ArrayVec3d)
59 IMPLEMENT_STANDARD_RTTIEXT (VrmlData_Color, VrmlData_ArrayVec3d)
60 IMPLEMENT_STANDARD_HANDLE (VrmlData_Coordinate, VrmlData_ArrayVec3d)
61 IMPLEMENT_STANDARD_RTTIEXT (VrmlData_Coordinate, VrmlData_ArrayVec3d)
62 IMPLEMENT_STANDARD_HANDLE (VrmlData_Normal, VrmlData_ArrayVec3d)
63 IMPLEMENT_STANDARD_RTTIEXT (VrmlData_Normal, VrmlData_ArrayVec3d)
64 IMPLEMENT_STANDARD_HANDLE (VrmlData_TextureCoordinate, VrmlData_Node)
65 IMPLEMENT_STANDARD_RTTIEXT (VrmlData_TextureCoordinate, VrmlData_Node)
67 //=======================================================================
70 //=======================================================================
72 const gp_XYZ& VrmlData_ArrayVec3d::Value (const Standard_Size i) const
74 static gp_XYZ anOrigin (0., 0., 0.);
75 return i < myLength ? myArray[i] : anOrigin;
78 //=======================================================================
79 //function : AllocateValues
81 //=======================================================================
83 Standard_Boolean VrmlData_ArrayVec3d::AllocateValues
84 (const Standard_Size theLength)
86 myArray = reinterpret_cast <const gp_XYZ *>
87 (Scene().Allocator()->Allocate (theLength*sizeof(gp_XYZ)));
89 return (myArray != 0L);
92 //=======================================================================
93 //function : VrmlData_Box::TShape
95 //=======================================================================
97 const Handle(TopoDS_TShape)& VrmlData_Box::TShape ()
101 const TopoDS_Shell aShell =
102 BRepPrimAPI_MakeBox (gp_Pnt (-0.5 * mySize),
103 mySize.X(), mySize.Y(), mySize.Z());
104 SetTShape (aShell.TShape());
105 myIsModified = Standard_False;
106 } catch (Standard_Failure) {
113 //=======================================================================
114 //function : VrmlData_Box::Clone
116 //=======================================================================
118 Handle(VrmlData_Node) VrmlData_Box::Clone
119 (const Handle(VrmlData_Node)& theOther) const
121 Handle(VrmlData_Box) aResult =
122 Handle(VrmlData_Box)::DownCast (VrmlData_Node::Clone(theOther));
123 if (aResult.IsNull())
124 aResult = new VrmlData_Box (theOther.IsNull() ? Scene() : theOther->Scene(),
126 aResult->SetSize(mySize);
130 //=======================================================================
131 //function : VrmlData_Box::Read
133 //=======================================================================
135 VrmlData_ErrorStatus VrmlData_Box::Read (VrmlData_InBuffer& theBuffer)
137 VrmlData_ErrorStatus aStatus;
138 if (OK(aStatus, VrmlData_Scene::ReadLine(theBuffer))) {
139 if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "size"))
140 aStatus = Scene().ReadXYZ (theBuffer, mySize,
141 Standard_True, Standard_True);
143 aStatus = readBrace (theBuffer);
148 //=======================================================================
149 //function : VrmlData_Box::Write
151 //=======================================================================
153 VrmlData_ErrorStatus VrmlData_Box::Write (const char * thePrefix) const
155 static char header[] = "Box {";
156 VrmlData_ErrorStatus aStatus;
157 if (OK (aStatus, Scene().WriteLine (thePrefix, header, GlobalIndent())))
160 sprintf (buf, "size %.12g %.12g %.12g", mySize.X(), mySize.Y(), mySize.Z());
161 Scene().WriteLine (buf);
162 aStatus = WriteClosing();
167 //=======================================================================
168 //function : VrmlData_Cone::TShape
170 //=======================================================================
172 const Handle(TopoDS_TShape)& VrmlData_Cone::TShape ()
174 if (myIsModified && (myHasBottom || myHasSide)) {
176 gp_Ax2 aLocalAxis (gp_Pnt (0., -0.5 * myHeight, 0.),
177 gp_Dir (0., 1., 0.));
178 BRepPrim_Cone aBuilder (aLocalAxis, myBottomRadius, 0., myHeight);
180 myTShape = aBuilder.LateralFace().TShape();
182 myTShape = aBuilder.BottomFace().TShape();
184 myTShape = aBuilder.Shell().TShape();
185 myIsModified = Standard_False;
186 } catch (Standard_Failure) {
193 //=======================================================================
194 //function : VrmlData_Cone::Clone
196 //=======================================================================
198 Handle(VrmlData_Node) VrmlData_Cone::Clone
199 (const Handle(VrmlData_Node)& theOther) const
201 Handle(VrmlData_Cone) aResult =
202 Handle(VrmlData_Cone)::DownCast (VrmlData_Node::Clone(theOther));
203 if (aResult.IsNull())
204 aResult = new VrmlData_Cone (theOther.IsNull() ? Scene(): theOther->Scene(),
207 aResult->SetBottomRadius (myBottomRadius);
208 aResult->SetHeight (myHeight);
209 aResult->SetFaces (myHasBottom, myHasSide);
213 //=======================================================================
214 //function : VrmlData_Cone::Read
216 //=======================================================================
218 VrmlData_ErrorStatus VrmlData_Cone::Read (VrmlData_InBuffer& theBuffer)
220 VrmlData_ErrorStatus aStatus;
221 Standard_Boolean hasSide(Standard_True), hasBottom(Standard_True);
223 while (OK(aStatus, VrmlData_Scene::ReadLine(theBuffer)))
225 if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "bottomRadius"))
226 aStatus = Scene().ReadReal (theBuffer, myBottomRadius,
227 Standard_True, Standard_True);
228 else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "height"))
229 aStatus = Scene().ReadReal (theBuffer, myHeight,
230 Standard_True, Standard_True);
231 else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "side")) {
232 if (OK(aStatus, ReadBoolean (theBuffer, hasSide)))
234 } else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "bottom")) {
235 if (OK(aStatus, ReadBoolean (theBuffer, hasBottom)))
236 myHasBottom = hasBottom;
243 // Read the terminating (closing) brace
245 aStatus = readBrace (theBuffer);
249 //=======================================================================
250 //function : VrmlData_Cone::Write
252 //=======================================================================
254 VrmlData_ErrorStatus VrmlData_Cone::Write (const char * thePrefix) const
256 static char header[] = "Cone {";
257 VrmlData_ErrorStatus aStatus;
258 if (OK (aStatus, Scene().WriteLine (thePrefix, header, GlobalIndent())))
261 if ((myBottomRadius - 1.)*(myBottomRadius - 1.) > Precision::Confusion()) {
262 sprintf (buf, "bottomRadius %.12g", myBottomRadius);
263 aStatus = Scene().WriteLine (buf);
266 (myHeight - 2.)*(myHeight - 2.) > Precision::Confusion()) {
267 sprintf (buf, "height %.12g", myHeight);
268 aStatus = Scene().WriteLine (buf);
270 if (OK(aStatus) && myHasBottom == Standard_False)
271 aStatus = Scene().WriteLine ("bottom FALSE");
272 if (OK(aStatus) && myHasSide == Standard_False)
273 aStatus = Scene().WriteLine ("side FALSE");
275 aStatus = WriteClosing();
280 //=======================================================================
281 //function : VrmlData_Cone::IsDefault
283 //=======================================================================
285 // Standard_Boolean VrmlData_Cone::IsDefault () const
288 // (myHasBottom && myHasSide &&
289 // ((myBottomRadius - 1.)*(myBottomRadius-1.) < Precision::Confusion()) &&
290 // ((myHeight - 2.)*(myHeight - 2.) < Precision::Confusion()));
293 //=======================================================================
294 //function : VrmlData_Cylinder::TShape
296 //=======================================================================
298 const Handle(TopoDS_TShape)& VrmlData_Cylinder::TShape ()
300 if (myIsModified && (myHasBottom || myHasSide || myHasTop)) {
302 gp_Ax2 aLocalAxis (gp_Pnt (0., -0.5 * myHeight, 0.),
303 gp_Dir (0., 1., 0.));
304 BRepPrim_Cylinder aBuilder (aLocalAxis, myRadius, myHeight);
305 BRepPrim_Builder aShapeBuilder;
307 aShapeBuilder.MakeShell(aShell);
309 aShapeBuilder.AddShellFace (aShell, aBuilder.LateralFace());
311 aShapeBuilder.AddShellFace (aShell, aBuilder.TopFace());
313 aShapeBuilder.AddShellFace (aShell, aBuilder.BottomFace());
314 myTShape = aShell.TShape();
315 myIsModified = Standard_False;
316 } catch (Standard_Failure) {
323 //=======================================================================
324 //function : VrmlData_Cylinder::Clone
326 //=======================================================================
328 Handle(VrmlData_Node) VrmlData_Cylinder::Clone
329 (const Handle(VrmlData_Node)& theOther) const
331 Handle(VrmlData_Cylinder) aResult =
332 Handle(VrmlData_Cylinder)::DownCast (VrmlData_Node::Clone(theOther));
333 if (aResult.IsNull())
334 aResult = new VrmlData_Cylinder(theOther.IsNull()?Scene():theOther->Scene(),
336 aResult->SetRadius (myRadius);
337 aResult->SetHeight (myHeight);
338 aResult->SetFaces (myHasBottom, myHasSide, myHasTop);
342 //=======================================================================
343 //function : VrmlData_Cylinder::Read
345 //=======================================================================
347 VrmlData_ErrorStatus VrmlData_Cylinder::Read (VrmlData_InBuffer& theBuffer)
349 VrmlData_ErrorStatus aStatus;
350 Standard_Boolean hasSide(Standard_True), hasBottom(Standard_True);
351 Standard_Boolean hasTop (Standard_True);
353 while (OK(aStatus, VrmlData_Scene::ReadLine(theBuffer)))
355 if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "radius"))
356 aStatus = Scene().ReadReal (theBuffer, myRadius,
357 Standard_True, Standard_True);
358 else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "height"))
359 aStatus = Scene().ReadReal (theBuffer, myHeight,
360 Standard_True, Standard_True);
361 else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "top")) {
362 if (OK(aStatus, ReadBoolean (theBuffer, hasTop)))
364 } else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "side")) {
365 if (OK(aStatus, ReadBoolean (theBuffer, hasSide)))
367 } else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "bottom")) {
368 if (OK(aStatus, ReadBoolean (theBuffer, hasBottom)))
369 myHasBottom = hasBottom;
377 // Read the terminating (closing) brace
379 aStatus = readBrace (theBuffer);
383 //=======================================================================
384 //function : VrmlData_Cylinder::Write
386 //=======================================================================
388 VrmlData_ErrorStatus VrmlData_Cylinder::Write (const char * thePrefix) const
390 static char header[] = "Cylinder {";
391 VrmlData_ErrorStatus aStatus;
392 if (OK (aStatus, Scene().WriteLine (thePrefix, header, GlobalIndent())))
395 if ((myRadius - 1.)*(myRadius - 1.) > Precision::Confusion()) {
396 sprintf (buf, "radius %.12g", myRadius);
397 aStatus = Scene().WriteLine (buf);
400 (myHeight - 2.)*(myHeight - 2.) > Precision::Confusion()) {
401 sprintf (buf, "height %.12g", myHeight);
402 aStatus = Scene().WriteLine (buf);
404 if (OK(aStatus) && myHasBottom == Standard_False)
405 aStatus = Scene().WriteLine ("bottom FALSE");
406 if (OK(aStatus) && myHasSide == Standard_False)
407 aStatus = Scene().WriteLine ("side FALSE");
408 if (OK(aStatus) && myHasTop == Standard_False)
409 aStatus = Scene().WriteLine ("top FALSE");
411 aStatus = WriteClosing();
416 //=======================================================================
417 //function : VrmlData_Cylinder::IsDefault
419 //=======================================================================
421 // Standard_Boolean VrmlData_Cylinder::IsDefault () const
424 // (myHasBottom && myHasSide && myHasTop &&
425 // ((myRadius - 1.)*(myRadius - 1.) < Precision::Confusion()) &&
426 // ((myHeight - 2.)*(myHeight - 2.) < Precision::Confusion()));
429 //=======================================================================
430 //function : VrmlData_Sphere::TShape
432 //=======================================================================
434 const Handle(TopoDS_TShape)& VrmlData_Sphere::TShape ()
438 myTShape = BRepPrim_Sphere(myRadius).Shell().TShape();
439 myIsModified = Standard_False;
440 } catch (Standard_Failure) {
447 //=======================================================================
448 //function : VrmlData_Sphere::Clone
450 //=======================================================================
452 Handle(VrmlData_Node) VrmlData_Sphere::Clone
453 (const Handle(VrmlData_Node)& theOther) const
455 Handle(VrmlData_Sphere) aResult =
456 Handle(VrmlData_Sphere)::DownCast (VrmlData_Node::Clone(theOther));
457 if (aResult.IsNull())
458 aResult = new VrmlData_Sphere(theOther.IsNull()? Scene() :theOther->Scene(),
460 aResult->SetRadius (myRadius);
464 //=======================================================================
465 //function : VrmlData_Sphere::Read
467 //=======================================================================
469 VrmlData_ErrorStatus VrmlData_Sphere::Read (VrmlData_InBuffer& theBuffer)
471 VrmlData_ErrorStatus aStatus;
472 while (OK(aStatus, VrmlData_Scene::ReadLine(theBuffer)))
473 if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "radius"))
474 aStatus = Scene().ReadReal (theBuffer, myRadius,
475 Standard_True, Standard_True);
479 // Read the terminating (closing) brace
481 aStatus = readBrace (theBuffer);
485 //=======================================================================
486 //function : VrmlData_Sphere::Write
488 //=======================================================================
490 VrmlData_ErrorStatus VrmlData_Sphere::Write (const char * thePrefix) const
492 static char header[] = "Sphere {";
493 VrmlData_ErrorStatus aStatus;
494 if (OK (aStatus, Scene().WriteLine (thePrefix, header, GlobalIndent())))
497 sprintf (buf, "radius %.12g", myRadius);
498 Scene().WriteLine (buf);
499 aStatus = WriteClosing();
504 //=======================================================================
505 //function : VrmlData_Sphere::IsDefault
507 //=======================================================================
509 // Standard_Boolean VrmlData_Sphere::IsDefault () const
511 // return ((myRadius - 1.)*(myRadius - 1.) < Precision::Confusion())
514 //=======================================================================
515 //function : VrmlData_TextureCoordinate::AllocateValues
517 //=======================================================================
519 Standard_Boolean VrmlData_TextureCoordinate::AllocateValues
520 (const Standard_Size theLength)
522 myPoints = reinterpret_cast <const gp_XY *>
523 (Scene().Allocator()->Allocate (theLength*sizeof(gp_XY)));
524 myLength = theLength;
525 return (myPoints != 0L);
528 //=======================================================================
529 //function : VrmlData_TextureCoordinate::Clone
531 //=======================================================================
533 Handle(VrmlData_Node) VrmlData_TextureCoordinate::Clone
534 (const Handle(VrmlData_Node)& theOther) const
536 Handle(VrmlData_TextureCoordinate) aResult =
537 Handle(VrmlData_TextureCoordinate)::DownCast
538 (VrmlData_Node::Clone(theOther));
539 if (aResult.IsNull())
540 aResult = new VrmlData_TextureCoordinate
541 (theOther.IsNull() ? Scene() : theOther->Scene(), Name());
542 if (&aResult->Scene() == &Scene())
543 aResult->SetPoints (myLength, myPoints);
545 aResult->AllocateValues (myLength);
546 for (Standard_Size i = 0; i < myLength; i++)
547 const_cast <gp_XY&> (aResult->myPoints[i]) = myPoints[i];
552 //=======================================================================
553 //function : VrmlData_TextureCoordinate::Read
555 //=======================================================================
557 VrmlData_ErrorStatus VrmlData_TextureCoordinate::Read
558 (VrmlData_InBuffer& theBuffer)
560 VrmlData_ErrorStatus aStatus;
561 NCollection_Vector<gp_XY> vecValues;
562 if (OK(aStatus, VrmlData_Scene::ReadLine(theBuffer))) {
563 // Match the name with the current word in the stream
564 if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "point"))
565 // Read the body of the data node (comma-separated list of duplets)
566 if (OK(aStatus, VrmlData_Scene::ReadLine(theBuffer)))
567 if (theBuffer.LinePtr[0] != '[') // opening bracket
568 aStatus = VrmlData_VrmlFormatError;
573 if (!OK(aStatus, VrmlData_Scene::ReadLine(theBuffer)))
575 // closing bracket, in case that it follows a comma
576 if (theBuffer.LinePtr[0] == ']') {
580 if (!OK(aStatus, Scene().ReadXY(theBuffer, anXY,
581 Standard_False, Standard_False)))
583 vecValues.Append(anXY);
584 if (!OK(aStatus, VrmlData_Scene::ReadLine(theBuffer)))
586 if (theBuffer.LinePtr[0] == ',') {
588 } else if (theBuffer.LinePtr[0] == ']') { // closing bracket
594 if (OK(aStatus) && OK(aStatus, readBrace (theBuffer))) {
595 myLength = vecValues.Length();
597 gp_XY * aPoints = reinterpret_cast <gp_XY *>
598 (Scene().Allocator()->Allocate (myLength * sizeof(gp_XY)));
600 for (Standard_Integer i = 0; i < Standard_Integer(myLength); i++)
601 aPoints[i] = vecValues(i);
608 //=======================================================================
609 //function : VrmlData_ArrayVec3d::Clone
611 //=======================================================================
613 // Handle(VrmlData_Node) VrmlData_ArrayVec3d::Clone
614 // (const Handle(VrmlData_Node)& theOther) const
616 // VrmlData_Node::Clone (theOther);
617 // const Handle(VrmlData_ArrayVec3d) anArrayNode =
618 // Handle(VrmlData_ArrayVec3d)::DownCast (theOther);
619 // if (anArrayNode.IsNull() == Standard_False)
620 // anArrayNode->SetValues (myLength, myArray);
624 //=======================================================================
625 //function : VrmlData_ArrayVec3d::ReadArray
627 //=======================================================================
629 VrmlData_ErrorStatus VrmlData_ArrayVec3d::ReadArray
630 (VrmlData_InBuffer& theBuffer,
631 const char * theName,
632 const Standard_Boolean isScale)
634 VrmlData_ErrorStatus aStatus;
635 NCollection_Vector<gp_XYZ> vecValues;
636 if (OK(aStatus, VrmlData_Scene::ReadLine(theBuffer))) {
637 // Match the name with the current word in the stream
639 const Standard_Size aNameLen = strlen(theName);
640 if (strncmp (theBuffer.LinePtr, theName, aNameLen))
641 aStatus = VrmlData_VrmlFormatError;
643 theBuffer.LinePtr += aNameLen;
645 // Skip the word in the input
646 while (theBuffer.LinePtr[0] != ' ' &&
647 theBuffer.LinePtr[0] != ',' &&
648 theBuffer.LinePtr[0] != '\t' &&
649 theBuffer.LinePtr[0] != '\n' &&
650 theBuffer.LinePtr[0] != '\r' &&
651 theBuffer.LinePtr[0] != '\0')
654 // Read the body of the data node (list of triplets)
655 if (OK(aStatus) && OK(aStatus, VrmlData_Scene::ReadLine(theBuffer)))
656 if (theBuffer.LinePtr[0] != '[') // opening bracket
657 aStatus = VrmlData_VrmlFormatError;
662 if (!OK(aStatus, VrmlData_Scene::ReadLine(theBuffer)))
664 // closing bracket, in case that it follows a comma
665 if (theBuffer.LinePtr[0] == ']') {
669 // Read three numbers (XYZ value)
670 if (!OK(aStatus, Scene().ReadXYZ(theBuffer, anXYZ,
671 isScale, Standard_False)))
673 vecValues.Append(anXYZ);
674 if (!OK(aStatus, VrmlData_Scene::ReadLine(theBuffer)))
676 if (theBuffer.LinePtr[0] == ']') {// closing bracket
682 if (OK(aStatus) && OK(aStatus, readBrace (theBuffer))) {
683 myLength = vecValues.Length();
685 gp_XYZ * anArray = reinterpret_cast <gp_XYZ *>
686 (Scene().Allocator()->Allocate (myLength * sizeof(gp_XYZ)));
688 for (Standard_Integer i = 0; i < Standard_Integer(myLength); i++)
689 anArray[i] = vecValues(i);
696 //=======================================================================
697 //function : VrmlData_ArrayVec3d::WriteArray
699 //=======================================================================
701 VrmlData_ErrorStatus VrmlData_ArrayVec3d::WriteArray
702 (const char * theName,
703 const Standard_Boolean isScale) const
705 VrmlData_ErrorStatus aStatus (VrmlData_StatusOK);
707 aStatus = Scene().WriteLine (theName, "[", 2*GlobalIndent());
709 for (Standard_Size i = 0; i < myLength-1; i++)
710 if (!OK (aStatus, Scene().WriteXYZ (myArray[i], isScale, ",")))
713 aStatus = Scene().WriteXYZ (myArray[myLength-1], isScale);
715 if (aStatus == VrmlData_StatusOK)
716 aStatus = Scene().WriteLine ("]", 0L, -2*GlobalIndent());
721 //=======================================================================
722 //function : VrmlData_ArrayVec3d::IsDefault
724 //=======================================================================
726 Standard_Boolean VrmlData_ArrayVec3d::IsDefault () const
728 return myLength == 0;
731 //=======================================================================
732 //function : VrmlData_Coodinate::Clone
734 //=======================================================================
736 Handle(VrmlData_Node) VrmlData_Coordinate::Clone
737 (const Handle(VrmlData_Node)& theOther) const
739 Handle(VrmlData_Coordinate) aResult =
740 Handle(VrmlData_Coordinate)::DownCast (VrmlData_Node::Clone(theOther));
741 if (aResult.IsNull())
742 aResult = new VrmlData_Coordinate
743 (theOther.IsNull() ? Scene() : theOther->Scene(), Name());
744 if (&aResult->Scene() == &Scene())
745 aResult->SetValues (Length(), Values());
747 aResult->AllocateValues (Length());
748 for (Standard_Size i = 0; i < Length(); i++)
749 const_cast <gp_XYZ&> (aResult->Values()[i]) = Values()[i];
754 //=======================================================================
755 //function : VrmlData_Coordinate::Read
757 //=======================================================================
759 VrmlData_ErrorStatus VrmlData_Coordinate::Read (VrmlData_InBuffer& theBuffer)
761 return VrmlData_ArrayVec3d::ReadArray (theBuffer, "point", Standard_True);
764 //=======================================================================
765 //function : VrmlData_Coordinate::Write
767 //=======================================================================
769 VrmlData_ErrorStatus VrmlData_Coordinate::Write (const char * thePrefix) const
771 static char header[] = "Coordinate {";
772 VrmlData_ErrorStatus aStatus;
773 if (OK (aStatus, Scene().WriteLine (thePrefix, header, GlobalIndent())))
775 WriteArray ("point", Standard_True);
776 aStatus = WriteClosing();
781 //=======================================================================
782 //function : VrmlData_Color::Clone
784 //=======================================================================
786 Handle(VrmlData_Node) VrmlData_Color::Clone
787 (const Handle(VrmlData_Node)& theOther) const
789 Handle(VrmlData_Color) aResult =
790 Handle(VrmlData_Color)::DownCast (VrmlData_Node::Clone(theOther));
791 if (aResult.IsNull())
792 aResult = new VrmlData_Color(theOther.IsNull()? Scene() : theOther->Scene(),
794 if (&aResult->Scene() == &Scene())
795 aResult->SetValues (Length(), Values());
797 aResult->AllocateValues (Length());
798 for (Standard_Size i = 0; i < Length(); i++)
799 const_cast <gp_XYZ&> (aResult->Values()[i]) = Values()[i];
804 //=======================================================================
805 //function : VrmlData_Color::Read
807 //=======================================================================
809 VrmlData_ErrorStatus VrmlData_Color::Read (VrmlData_InBuffer& theBuffer)
811 return ReadArray (theBuffer, "color", Standard_False);
814 //=======================================================================
815 //function : VrmlData_Color::Write
817 //=======================================================================
819 VrmlData_ErrorStatus VrmlData_Color::Write (const char * thePrefix) const
821 static char header[] = "Color {";
822 VrmlData_ErrorStatus aStatus;
823 if (OK (aStatus, Scene().WriteLine (thePrefix, header, GlobalIndent())))
825 WriteArray ("color", Standard_False);
826 aStatus = WriteClosing();
831 //=======================================================================
832 //function : VrmlData_Normal::Clone
834 //=======================================================================
836 Handle(VrmlData_Node) VrmlData_Normal::Clone
837 (const Handle(VrmlData_Node)& theOther) const
839 Handle(VrmlData_Normal) aResult =
840 Handle(VrmlData_Normal)::DownCast (VrmlData_Node::Clone(theOther));
841 if (aResult.IsNull())
842 aResult= new VrmlData_Normal(theOther.IsNull()? Scene() : theOther->Scene(),
844 if (&aResult->Scene() == &Scene())
845 aResult->SetValues (Length(), Values());
847 aResult->AllocateValues (Length());
848 for (Standard_Size i = 0; i < Length(); i++)
849 const_cast <gp_XYZ&> (aResult->Values()[i]) = Values()[i];
854 //=======================================================================
855 //function : VrmlData_Normal::Read
857 //=======================================================================
859 VrmlData_ErrorStatus VrmlData_Normal::Read (VrmlData_InBuffer& theBuffer)
861 return VrmlData_ArrayVec3d::ReadArray (theBuffer, "vector", Standard_False);
864 //=======================================================================
865 //function : VrmlData_Normal::Write
867 //=======================================================================
869 VrmlData_ErrorStatus VrmlData_Normal::Write (const char * thePrefix) const
871 static char header[] = "Normal {";
872 VrmlData_ErrorStatus aStatus;
873 if (OK (aStatus, Scene().WriteLine (thePrefix, header, GlobalIndent())))
875 WriteArray ("vector", Standard_False);
876 aStatus = WriteClosing();