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_Integer i) const
74 size_t anIndex = (size_t)i;
75 if (anIndex < 0 || anIndex >= myLength) {
76 static gp_XYZ anOrigin (0., 0., 0.);
82 //=======================================================================
83 //function : AllocateValues
85 //=======================================================================
87 Standard_Boolean VrmlData_ArrayVec3d::AllocateValues
88 (const Standard_Size theLength)
90 myArray = reinterpret_cast <const gp_XYZ *>
91 (Scene().Allocator()->Allocate (theLength*sizeof(gp_XYZ)));
93 return (myArray != 0L);
96 //=======================================================================
97 //function : VrmlData_Box::TShape
99 //=======================================================================
101 const Handle(TopoDS_TShape)& VrmlData_Box::TShape ()
105 const TopoDS_Shell aShell =
106 BRepPrimAPI_MakeBox (gp_Pnt (-0.5 * mySize),
107 mySize.X(), mySize.Y(), mySize.Z());
108 SetTShape (aShell.TShape());
109 myIsModified = Standard_False;
110 } catch (Standard_Failure) {
117 //=======================================================================
118 //function : VrmlData_Box::Clone
120 //=======================================================================
122 Handle(VrmlData_Node) VrmlData_Box::Clone
123 (const Handle(VrmlData_Node)& theOther) const
125 Handle(VrmlData_Box) aResult =
126 Handle(VrmlData_Box)::DownCast (VrmlData_Node::Clone(theOther));
127 if (aResult.IsNull())
128 aResult = new VrmlData_Box (theOther.IsNull() ? Scene() : theOther->Scene(),
130 aResult->SetSize(mySize);
134 //=======================================================================
135 //function : VrmlData_Box::Read
137 //=======================================================================
139 VrmlData_ErrorStatus VrmlData_Box::Read (VrmlData_InBuffer& theBuffer)
141 VrmlData_ErrorStatus aStatus;
142 if (OK(aStatus, VrmlData_Scene::ReadLine(theBuffer))) {
143 if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "size"))
144 aStatus = Scene().ReadXYZ (theBuffer, mySize,
145 Standard_True, Standard_True);
147 aStatus = readBrace (theBuffer);
152 //=======================================================================
153 //function : VrmlData_Box::Write
155 //=======================================================================
157 VrmlData_ErrorStatus VrmlData_Box::Write (const char * thePrefix) const
159 static char header[] = "Box {";
160 VrmlData_ErrorStatus aStatus;
161 if (OK (aStatus, Scene().WriteLine (thePrefix, header, GlobalIndent())))
164 sprintf (buf, "size %.12g %.12g %.12g", mySize.X(), mySize.Y(), mySize.Z());
165 Scene().WriteLine (buf);
166 aStatus = WriteClosing();
171 //=======================================================================
172 //function : VrmlData_Cone::TShape
174 //=======================================================================
176 const Handle(TopoDS_TShape)& VrmlData_Cone::TShape ()
178 if (myIsModified && (myHasBottom || myHasSide)) {
180 gp_Ax2 aLocalAxis (gp_Pnt (0., -0.5 * myHeight, 0.),
181 gp_Dir (0., 1., 0.));
182 BRepPrim_Cone aBuilder (aLocalAxis, myBottomRadius, 0., myHeight);
184 myTShape = aBuilder.LateralFace().TShape();
186 myTShape = aBuilder.BottomFace().TShape();
188 myTShape = aBuilder.Shell().TShape();
189 myIsModified = Standard_False;
190 } catch (Standard_Failure) {
197 //=======================================================================
198 //function : VrmlData_Cone::Clone
200 //=======================================================================
202 Handle(VrmlData_Node) VrmlData_Cone::Clone
203 (const Handle(VrmlData_Node)& theOther) const
205 Handle(VrmlData_Cone) aResult =
206 Handle(VrmlData_Cone)::DownCast (VrmlData_Node::Clone(theOther));
207 if (aResult.IsNull())
208 aResult = new VrmlData_Cone (theOther.IsNull() ? Scene(): theOther->Scene(),
211 aResult->SetBottomRadius (myBottomRadius);
212 aResult->SetHeight (myHeight);
213 aResult->SetFaces (myHasBottom, myHasSide);
217 //=======================================================================
218 //function : VrmlData_Cone::Read
220 //=======================================================================
222 VrmlData_ErrorStatus VrmlData_Cone::Read (VrmlData_InBuffer& theBuffer)
224 VrmlData_ErrorStatus aStatus;
225 Standard_Boolean hasSide(Standard_True), hasBottom(Standard_True);
227 while (OK(aStatus, VrmlData_Scene::ReadLine(theBuffer)))
229 if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "bottomRadius"))
230 aStatus = Scene().ReadReal (theBuffer, myBottomRadius,
231 Standard_True, Standard_True);
232 else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "height"))
233 aStatus = Scene().ReadReal (theBuffer, myHeight,
234 Standard_True, Standard_True);
235 else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "side")) {
236 if (OK(aStatus, ReadBoolean (theBuffer, hasSide)))
238 } else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "bottom")) {
239 if (OK(aStatus, ReadBoolean (theBuffer, hasBottom)))
240 myHasBottom = hasBottom;
247 // Read the terminating (closing) brace
249 aStatus = readBrace (theBuffer);
253 //=======================================================================
254 //function : VrmlData_Cone::Write
256 //=======================================================================
258 VrmlData_ErrorStatus VrmlData_Cone::Write (const char * thePrefix) const
260 static char header[] = "Cone {";
261 VrmlData_ErrorStatus aStatus;
262 if (OK (aStatus, Scene().WriteLine (thePrefix, header, GlobalIndent())))
265 if ((myBottomRadius - 1.)*(myBottomRadius - 1.) > Precision::Confusion()) {
266 sprintf (buf, "bottomRadius %.12g", myBottomRadius);
267 aStatus = Scene().WriteLine (buf);
270 (myHeight - 2.)*(myHeight - 2.) > Precision::Confusion()) {
271 sprintf (buf, "height %.12g", myHeight);
272 aStatus = Scene().WriteLine (buf);
274 if (OK(aStatus) && myHasBottom == Standard_False)
275 aStatus = Scene().WriteLine ("bottom FALSE");
276 if (OK(aStatus) && myHasSide == Standard_False)
277 aStatus = Scene().WriteLine ("side FALSE");
279 aStatus = WriteClosing();
284 //=======================================================================
285 //function : VrmlData_Cone::IsDefault
287 //=======================================================================
289 // Standard_Boolean VrmlData_Cone::IsDefault () const
292 // (myHasBottom && myHasSide &&
293 // ((myBottomRadius - 1.)*(myBottomRadius-1.) < Precision::Confusion()) &&
294 // ((myHeight - 2.)*(myHeight - 2.) < Precision::Confusion()));
297 //=======================================================================
298 //function : VrmlData_Cylinder::TShape
300 //=======================================================================
302 const Handle(TopoDS_TShape)& VrmlData_Cylinder::TShape ()
304 if (myIsModified && (myHasBottom || myHasSide || myHasTop)) {
306 gp_Ax2 aLocalAxis (gp_Pnt (0., -0.5 * myHeight, 0.),
307 gp_Dir (0., 1., 0.));
308 BRepPrim_Cylinder aBuilder (aLocalAxis, myRadius, myHeight);
309 BRepPrim_Builder aShapeBuilder;
311 aShapeBuilder.MakeShell(aShell);
313 aShapeBuilder.AddShellFace (aShell, aBuilder.LateralFace());
315 aShapeBuilder.AddShellFace (aShell, aBuilder.TopFace());
317 aShapeBuilder.AddShellFace (aShell, aBuilder.BottomFace());
318 myTShape = aShell.TShape();
319 myIsModified = Standard_False;
320 } catch (Standard_Failure) {
327 //=======================================================================
328 //function : VrmlData_Cylinder::Clone
330 //=======================================================================
332 Handle(VrmlData_Node) VrmlData_Cylinder::Clone
333 (const Handle(VrmlData_Node)& theOther) const
335 Handle(VrmlData_Cylinder) aResult =
336 Handle(VrmlData_Cylinder)::DownCast (VrmlData_Node::Clone(theOther));
337 if (aResult.IsNull())
338 aResult = new VrmlData_Cylinder(theOther.IsNull()?Scene():theOther->Scene(),
340 aResult->SetRadius (myRadius);
341 aResult->SetHeight (myHeight);
342 aResult->SetFaces (myHasBottom, myHasSide, myHasTop);
346 //=======================================================================
347 //function : VrmlData_Cylinder::Read
349 //=======================================================================
351 VrmlData_ErrorStatus VrmlData_Cylinder::Read (VrmlData_InBuffer& theBuffer)
353 VrmlData_ErrorStatus aStatus;
354 Standard_Boolean hasSide(Standard_True), hasBottom(Standard_True);
355 Standard_Boolean hasTop (Standard_True);
357 while (OK(aStatus, VrmlData_Scene::ReadLine(theBuffer)))
359 if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "radius"))
360 aStatus = Scene().ReadReal (theBuffer, myRadius,
361 Standard_True, Standard_True);
362 else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "height"))
363 aStatus = Scene().ReadReal (theBuffer, myHeight,
364 Standard_True, Standard_True);
365 else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "top")) {
366 if (OK(aStatus, ReadBoolean (theBuffer, hasTop)))
368 } else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "side")) {
369 if (OK(aStatus, ReadBoolean (theBuffer, hasSide)))
371 } else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "bottom")) {
372 if (OK(aStatus, ReadBoolean (theBuffer, hasBottom)))
373 myHasBottom = hasBottom;
381 // Read the terminating (closing) brace
383 aStatus = readBrace (theBuffer);
387 //=======================================================================
388 //function : VrmlData_Cylinder::Write
390 //=======================================================================
392 VrmlData_ErrorStatus VrmlData_Cylinder::Write (const char * thePrefix) const
394 static char header[] = "Cylinder {";
395 VrmlData_ErrorStatus aStatus;
396 if (OK (aStatus, Scene().WriteLine (thePrefix, header, GlobalIndent())))
399 if ((myRadius - 1.)*(myRadius - 1.) > Precision::Confusion()) {
400 sprintf (buf, "radius %.12g", myRadius);
401 aStatus = Scene().WriteLine (buf);
404 (myHeight - 2.)*(myHeight - 2.) > Precision::Confusion()) {
405 sprintf (buf, "height %.12g", myHeight);
406 aStatus = Scene().WriteLine (buf);
408 if (OK(aStatus) && myHasBottom == Standard_False)
409 aStatus = Scene().WriteLine ("bottom FALSE");
410 if (OK(aStatus) && myHasSide == Standard_False)
411 aStatus = Scene().WriteLine ("side FALSE");
412 if (OK(aStatus) && myHasTop == Standard_False)
413 aStatus = Scene().WriteLine ("top FALSE");
415 aStatus = WriteClosing();
420 //=======================================================================
421 //function : VrmlData_Cylinder::IsDefault
423 //=======================================================================
425 // Standard_Boolean VrmlData_Cylinder::IsDefault () const
428 // (myHasBottom && myHasSide && myHasTop &&
429 // ((myRadius - 1.)*(myRadius - 1.) < Precision::Confusion()) &&
430 // ((myHeight - 2.)*(myHeight - 2.) < Precision::Confusion()));
433 //=======================================================================
434 //function : VrmlData_Sphere::TShape
436 //=======================================================================
438 const Handle(TopoDS_TShape)& VrmlData_Sphere::TShape ()
442 myTShape = BRepPrim_Sphere(myRadius).Shell().TShape();
443 myIsModified = Standard_False;
444 } catch (Standard_Failure) {
451 //=======================================================================
452 //function : VrmlData_Sphere::Clone
454 //=======================================================================
456 Handle(VrmlData_Node) VrmlData_Sphere::Clone
457 (const Handle(VrmlData_Node)& theOther) const
459 Handle(VrmlData_Sphere) aResult =
460 Handle(VrmlData_Sphere)::DownCast (VrmlData_Node::Clone(theOther));
461 if (aResult.IsNull())
462 aResult = new VrmlData_Sphere(theOther.IsNull()? Scene() :theOther->Scene(),
464 aResult->SetRadius (myRadius);
468 //=======================================================================
469 //function : VrmlData_Sphere::Read
471 //=======================================================================
473 VrmlData_ErrorStatus VrmlData_Sphere::Read (VrmlData_InBuffer& theBuffer)
475 VrmlData_ErrorStatus aStatus;
476 while (OK(aStatus, VrmlData_Scene::ReadLine(theBuffer)))
477 if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "radius"))
478 aStatus = Scene().ReadReal (theBuffer, myRadius,
479 Standard_True, Standard_True);
483 // Read the terminating (closing) brace
485 aStatus = readBrace (theBuffer);
489 //=======================================================================
490 //function : VrmlData_Sphere::Write
492 //=======================================================================
494 VrmlData_ErrorStatus VrmlData_Sphere::Write (const char * thePrefix) const
496 static char header[] = "Sphere {";
497 VrmlData_ErrorStatus aStatus;
498 if (OK (aStatus, Scene().WriteLine (thePrefix, header, GlobalIndent())))
501 sprintf (buf, "radius %.12g", myRadius);
502 Scene().WriteLine (buf);
503 aStatus = WriteClosing();
508 //=======================================================================
509 //function : VrmlData_Sphere::IsDefault
511 //=======================================================================
513 // Standard_Boolean VrmlData_Sphere::IsDefault () const
515 // return ((myRadius - 1.)*(myRadius - 1.) < Precision::Confusion())
518 //=======================================================================
519 //function : VrmlData_TextureCoordinate::AllocateValues
521 //=======================================================================
523 Standard_Boolean VrmlData_TextureCoordinate::AllocateValues
524 (const Standard_Size theLength)
526 myPoints = reinterpret_cast <const gp_XY *>
527 (Scene().Allocator()->Allocate (theLength*sizeof(gp_XY)));
528 myLength = theLength;
529 return (myPoints != 0L);
532 //=======================================================================
533 //function : VrmlData_TextureCoordinate::Clone
535 //=======================================================================
537 Handle(VrmlData_Node) VrmlData_TextureCoordinate::Clone
538 (const Handle(VrmlData_Node)& theOther) const
540 Handle(VrmlData_TextureCoordinate) aResult =
541 Handle(VrmlData_TextureCoordinate)::DownCast
542 (VrmlData_Node::Clone(theOther));
543 if (aResult.IsNull())
544 aResult = new VrmlData_TextureCoordinate
545 (theOther.IsNull() ? Scene() : theOther->Scene(), Name());
546 if (&aResult->Scene() == &Scene())
547 aResult->SetPoints (myLength, myPoints);
549 aResult->AllocateValues (myLength);
550 for (Standard_Size i = 0; i < myLength; i++)
551 const_cast <gp_XY&> (aResult->myPoints[i]) = myPoints[i];
556 //=======================================================================
557 //function : VrmlData_TextureCoordinate::Read
559 //=======================================================================
561 VrmlData_ErrorStatus VrmlData_TextureCoordinate::Read
562 (VrmlData_InBuffer& theBuffer)
564 VrmlData_ErrorStatus aStatus;
565 NCollection_Vector<gp_XY> vecValues;
566 if (OK(aStatus, VrmlData_Scene::ReadLine(theBuffer))) {
567 // Match the name with the current word in the stream
568 if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "point"))
569 // Read the body of the data node (comma-separated list of duplets)
570 if (OK(aStatus, VrmlData_Scene::ReadLine(theBuffer)))
571 if (theBuffer.LinePtr[0] != '[') // opening bracket
572 aStatus = VrmlData_VrmlFormatError;
577 if (!OK(aStatus, VrmlData_Scene::ReadLine(theBuffer)))
579 // closing bracket, in case that it follows a comma
580 if (theBuffer.LinePtr[0] == ']') {
584 if (!OK(aStatus, Scene().ReadXY(theBuffer, anXY,
585 Standard_False, Standard_False)))
587 vecValues.Append(anXY);
588 if (!OK(aStatus, VrmlData_Scene::ReadLine(theBuffer)))
590 if (theBuffer.LinePtr[0] == ',') {
592 } else if (theBuffer.LinePtr[0] == ']') { // closing bracket
598 if (OK(aStatus) && OK(aStatus, readBrace (theBuffer))) {
599 myLength = vecValues.Length();
601 gp_XY * aPoints = reinterpret_cast <gp_XY *>
602 (Scene().Allocator()->Allocate (myLength * sizeof(gp_XY)));
604 for (Standard_Integer i = 0; i < Standard_Integer(myLength); i++)
605 aPoints[i] = vecValues(i);
612 //=======================================================================
613 //function : VrmlData_ArrayVec3d::Clone
615 //=======================================================================
617 // Handle(VrmlData_Node) VrmlData_ArrayVec3d::Clone
618 // (const Handle(VrmlData_Node)& theOther) const
620 // VrmlData_Node::Clone (theOther);
621 // const Handle(VrmlData_ArrayVec3d) anArrayNode =
622 // Handle(VrmlData_ArrayVec3d)::DownCast (theOther);
623 // if (anArrayNode.IsNull() == Standard_False)
624 // anArrayNode->SetValues (myLength, myArray);
628 //=======================================================================
629 //function : VrmlData_ArrayVec3d::ReadArray
631 //=======================================================================
633 VrmlData_ErrorStatus VrmlData_ArrayVec3d::ReadArray
634 (VrmlData_InBuffer& theBuffer,
635 const char * theName,
636 const Standard_Boolean isScale)
638 VrmlData_ErrorStatus aStatus;
639 NCollection_Vector<gp_XYZ> vecValues;
640 if (OK(aStatus, VrmlData_Scene::ReadLine(theBuffer))) {
641 // Match the name with the current word in the stream
643 const Standard_Integer aNameLen = strlen(theName);
644 if (strncmp (theBuffer.LinePtr, theName, aNameLen))
645 aStatus = VrmlData_VrmlFormatError;
647 theBuffer.LinePtr += aNameLen;
649 // Skip the word in the input
650 while (theBuffer.LinePtr[0] != ' ' &&
651 theBuffer.LinePtr[0] != ',' &&
652 theBuffer.LinePtr[0] != '\t' &&
653 theBuffer.LinePtr[0] != '\n' &&
654 theBuffer.LinePtr[0] != '\r' &&
655 theBuffer.LinePtr[0] != '\0')
658 // Read the body of the data node (list of triplets)
659 if (OK(aStatus) && OK(aStatus, VrmlData_Scene::ReadLine(theBuffer)))
660 if (theBuffer.LinePtr[0] != '[') // opening bracket
661 aStatus = VrmlData_VrmlFormatError;
666 if (!OK(aStatus, VrmlData_Scene::ReadLine(theBuffer)))
668 // closing bracket, in case that it follows a comma
669 if (theBuffer.LinePtr[0] == ']') {
673 // Read three numbers (XYZ value)
674 if (!OK(aStatus, Scene().ReadXYZ(theBuffer, anXYZ,
675 isScale, Standard_False)))
677 vecValues.Append(anXYZ);
678 if (!OK(aStatus, VrmlData_Scene::ReadLine(theBuffer)))
680 if (theBuffer.LinePtr[0] == ']') {// closing bracket
686 if (OK(aStatus) && OK(aStatus, readBrace (theBuffer))) {
687 myLength = vecValues.Length();
689 gp_XYZ * anArray = reinterpret_cast <gp_XYZ *>
690 (Scene().Allocator()->Allocate (myLength * sizeof(gp_XYZ)));
692 for (Standard_Integer i = 0; i < Standard_Integer(myLength); i++)
693 anArray[i] = vecValues(i);
700 //=======================================================================
701 //function : VrmlData_ArrayVec3d::WriteArray
703 //=======================================================================
705 VrmlData_ErrorStatus VrmlData_ArrayVec3d::WriteArray
706 (const char * theName,
707 const Standard_Boolean isScale) const
709 VrmlData_ErrorStatus aStatus (VrmlData_StatusOK);
711 aStatus = Scene().WriteLine (theName, "[", 2*GlobalIndent());
713 for (Standard_Size i = 0; i < myLength-1; i++)
714 if (!OK (aStatus, Scene().WriteXYZ (myArray[i], isScale, ",")))
717 aStatus = Scene().WriteXYZ (myArray[myLength-1], isScale);
719 if (aStatus == VrmlData_StatusOK)
720 aStatus = Scene().WriteLine ("]", 0L, -2*GlobalIndent());
725 //=======================================================================
726 //function : VrmlData_ArrayVec3d::IsDefault
728 //=======================================================================
730 Standard_Boolean VrmlData_ArrayVec3d::IsDefault () const
732 return myLength == 0;
735 //=======================================================================
736 //function : VrmlData_Coodinate::Clone
738 //=======================================================================
740 Handle(VrmlData_Node) VrmlData_Coordinate::Clone
741 (const Handle(VrmlData_Node)& theOther) const
743 Handle(VrmlData_Coordinate) aResult =
744 Handle(VrmlData_Coordinate)::DownCast (VrmlData_Node::Clone(theOther));
745 if (aResult.IsNull())
746 aResult = new VrmlData_Coordinate
747 (theOther.IsNull() ? Scene() : theOther->Scene(), Name());
748 if (&aResult->Scene() == &Scene())
749 aResult->SetValues (Length(), Values());
751 aResult->AllocateValues (Length());
752 for (Standard_Size i = 0; i < Length(); i++)
753 const_cast <gp_XYZ&> (aResult->Values()[i]) = Values()[i];
758 //=======================================================================
759 //function : VrmlData_Coordinate::Read
761 //=======================================================================
763 VrmlData_ErrorStatus VrmlData_Coordinate::Read (VrmlData_InBuffer& theBuffer)
765 return VrmlData_ArrayVec3d::ReadArray (theBuffer, "point", Standard_True);
768 //=======================================================================
769 //function : VrmlData_Coordinate::Write
771 //=======================================================================
773 VrmlData_ErrorStatus VrmlData_Coordinate::Write (const char * thePrefix) const
775 static char header[] = "Coordinate {";
776 VrmlData_ErrorStatus aStatus;
777 if (OK (aStatus, Scene().WriteLine (thePrefix, header, GlobalIndent())))
779 WriteArray ("point", Standard_True);
780 aStatus = WriteClosing();
785 //=======================================================================
786 //function : VrmlData_Color::Clone
788 //=======================================================================
790 Handle(VrmlData_Node) VrmlData_Color::Clone
791 (const Handle(VrmlData_Node)& theOther) const
793 Handle(VrmlData_Color) aResult =
794 Handle(VrmlData_Color)::DownCast (VrmlData_Node::Clone(theOther));
795 if (aResult.IsNull())
796 aResult = new VrmlData_Color(theOther.IsNull()? Scene() : theOther->Scene(),
798 if (&aResult->Scene() == &Scene())
799 aResult->SetValues (Length(), Values());
801 aResult->AllocateValues (Length());
802 for (Standard_Size i = 0; i < Length(); i++)
803 const_cast <gp_XYZ&> (aResult->Values()[i]) = Values()[i];
808 //=======================================================================
809 //function : VrmlData_Color::Read
811 //=======================================================================
813 VrmlData_ErrorStatus VrmlData_Color::Read (VrmlData_InBuffer& theBuffer)
815 return ReadArray (theBuffer, "color", Standard_False);
818 //=======================================================================
819 //function : VrmlData_Color::Write
821 //=======================================================================
823 VrmlData_ErrorStatus VrmlData_Color::Write (const char * thePrefix) const
825 static char header[] = "Color {";
826 VrmlData_ErrorStatus aStatus;
827 if (OK (aStatus, Scene().WriteLine (thePrefix, header, GlobalIndent())))
829 WriteArray ("color", Standard_False);
830 aStatus = WriteClosing();
835 //=======================================================================
836 //function : VrmlData_Normal::Clone
838 //=======================================================================
840 Handle(VrmlData_Node) VrmlData_Normal::Clone
841 (const Handle(VrmlData_Node)& theOther) const
843 Handle(VrmlData_Normal) aResult =
844 Handle(VrmlData_Normal)::DownCast (VrmlData_Node::Clone(theOther));
845 if (aResult.IsNull())
846 aResult= new VrmlData_Normal(theOther.IsNull()? Scene() : theOther->Scene(),
848 if (&aResult->Scene() == &Scene())
849 aResult->SetValues (Length(), Values());
851 aResult->AllocateValues (Length());
852 for (Standard_Size i = 0; i < Length(); i++)
853 const_cast <gp_XYZ&> (aResult->Values()[i]) = Values()[i];
858 //=======================================================================
859 //function : VrmlData_Normal::Read
861 //=======================================================================
863 VrmlData_ErrorStatus VrmlData_Normal::Read (VrmlData_InBuffer& theBuffer)
865 return VrmlData_ArrayVec3d::ReadArray (theBuffer, "vector", Standard_False);
868 //=======================================================================
869 //function : VrmlData_Normal::Write
871 //=======================================================================
873 VrmlData_ErrorStatus VrmlData_Normal::Write (const char * thePrefix) const
875 static char header[] = "Normal {";
876 VrmlData_ErrorStatus aStatus;
877 if (OK (aStatus, Scene().WriteLine (thePrefix, header, GlobalIndent())))
879 WriteArray ("vector", Standard_False);
880 aStatus = WriteClosing();