1 // File: VrmlData_IndexedLineSet.cxx
2 // Created: 01.08.07 09:20
3 // Author: Alexander GRIGORIEV
4 // Copyright: Open Cascade 2007
7 #include <VrmlData_IndexedLineSet.hxx>
8 #include <VrmlData_Scene.hxx>
9 #include <VrmlData_InBuffer.hxx>
10 #include <VrmlData_UnknownNode.hxx>
11 #include <BRep_Builder.hxx>
12 #include <Poly_Polygon3D.hxx>
13 #include <TColStd_Array1OfReal.hxx>
14 #include <TColgp_Array1OfPnt.hxx>
15 #include <TopoDS_Edge.hxx>
16 #include <TopoDS_Wire.hxx>
19 #define _CRT_SECURE_NO_DEPRECATE
20 #pragma warning (disable:4996)
23 IMPLEMENT_STANDARD_HANDLE (VrmlData_IndexedLineSet, VrmlData_Geometry)
24 IMPLEMENT_STANDARD_RTTIEXT (VrmlData_IndexedLineSet, VrmlData_Geometry)
26 //=======================================================================
29 //=======================================================================
31 Quantity_Color VrmlData_IndexedLineSet::GetColor
32 (const Standard_Integer /*iFace*/,
33 const Standard_Integer /*iVertex*/)
36 return Quantity_NOC_BLACK;
39 //=======================================================================
41 //purpose : Query the shape. This method checks the flag myIsModified;
42 // if True it should rebuild the shape presentation.
43 //=======================================================================
45 const Handle(TopoDS_TShape)& VrmlData_IndexedLineSet::TShape ()
47 if (myNbPolygons == 0)
49 else if (myIsModified) {
51 BRep_Builder aBuilder;
52 const gp_XYZ * arrNodes = myCoords->Values();
56 aBuilder.MakeWire(aWire);
57 for (i = 0; i < (int)myNbPolygons; i++) {
58 const Standard_Integer * arrIndice;
59 const Standard_Integer nNodes = Polygon(i, arrIndice);
60 TColgp_Array1OfPnt arrPoint (1, nNodes);
61 TColStd_Array1OfReal arrParam (1, nNodes);
62 for (Standard_Integer j = 0; j < nNodes; j++) {
63 arrPoint(j+1).SetXYZ (arrNodes[arrIndice[j]]);
66 const Handle(Poly_Polygon3D) aPolyPolygon =
67 new Poly_Polygon3D (arrPoint, arrParam);
69 aBuilder.MakeEdge (anEdge, aPolyPolygon);
70 aBuilder.Add (aWire, anEdge);
72 myTShape = aWire.TShape();
77 //=======================================================================
79 //purpose : Create a copy of this node
80 //=======================================================================
82 Handle(VrmlData_Node) VrmlData_IndexedLineSet::Clone
83 (const Handle(VrmlData_Node)& theOther) const
85 Handle(VrmlData_IndexedLineSet) aResult =
86 Handle(VrmlData_IndexedLineSet)::DownCast (VrmlData_Node::Clone(theOther));
89 new VrmlData_IndexedLineSet(theOther.IsNull()? Scene(): theOther->Scene(),
92 if (&aResult->Scene() == &Scene()) {
93 aResult->SetCoordinates (myCoords);
94 aResult->SetColors (myColors);
95 aResult->SetPolygons (myNbPolygons, myArrPolygons);
96 aResult->SetColorInd (myNbColors, myArrColorInd);
98 // Create a dummy node to pass the different Scene instance to methods Clone
99 const Handle(VrmlData_UnknownNode) aDummyNode =
100 new VrmlData_UnknownNode (aResult->Scene());
101 if (myCoords.IsNull() == Standard_False)
102 aResult->SetCoordinates (Handle(VrmlData_Coordinate)::DownCast
103 (myCoords->Clone (aDummyNode)));
104 if (myColors.IsNull() == Standard_False)
105 aResult->SetColors (Handle(VrmlData_Color)::DownCast
106 (myColors->Clone (aDummyNode)));
107 //TODO: Replace the following lines with the relevant copying
108 aResult->SetPolygons (myNbPolygons, myArrPolygons);
109 aResult->SetColorInd (myNbColors, myArrColorInd);
111 aResult->SetColorPerVertex (myColorPerVertex);
115 //=======================================================================
117 //purpose : Read the Node from input stream.
118 //=======================================================================
120 VrmlData_ErrorStatus VrmlData_IndexedLineSet::Read
121 (VrmlData_InBuffer& theBuffer)
123 VrmlData_ErrorStatus aStatus;
124 const VrmlData_Scene& aScene = Scene();
125 while (OK(aStatus, VrmlData_Scene::ReadLine(theBuffer)))
127 if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "colorPerVertex"))
128 aStatus = ReadBoolean (theBuffer, myColorPerVertex);
129 else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "coordIndex"))
130 aStatus = aScene.ReadArrIndex (theBuffer, myArrPolygons, myNbPolygons);
131 else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "colorIndex"))
132 aStatus = aScene.ReadArrIndex (theBuffer, myArrColorInd, myNbColors);
133 // These two checks should be the last one to avoid their interference
134 // with the other tokens (e.g., coordIndex)
135 else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "color"))
136 aStatus = ReadNode (theBuffer, myColors,
137 STANDARD_TYPE(VrmlData_Color));
138 else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "coord"))
139 aStatus = ReadNode (theBuffer, myCoords,
140 STANDARD_TYPE(VrmlData_Coordinate));
146 // Read the terminating (closing) brace
147 if (OK(aStatus) || aStatus == VrmlData_EmptyData)
148 if (OK(aStatus, readBrace (theBuffer))) {
155 //=======================================================================
157 //purpose : Write the Node to output stream
158 //=======================================================================
160 VrmlData_ErrorStatus VrmlData_IndexedLineSet::Write
161 (const char * thePrefix) const
163 static char header[] = "IndexedLineSet {";
164 const VrmlData_Scene& aScene = Scene();
165 VrmlData_ErrorStatus aStatus;
166 if (OK (aStatus, aScene.WriteLine (thePrefix, header, GlobalIndent()))) {
168 if (OK(aStatus) && myCoords.IsNull() == Standard_False)
169 aStatus = aScene.WriteNode ("coord", myCoords);
171 aStatus = aScene.WriteArrIndex ("coordIndex", myArrPolygons,myNbPolygons);
173 if (OK(aStatus) && myColorPerVertex == Standard_False)
174 aStatus = aScene.WriteLine ("colorPerVertex FALSE");
175 if (OK(aStatus) && myColors.IsNull() == Standard_False)
176 aStatus = aScene.WriteNode ("color", myColors);
178 aStatus = aScene.WriteArrIndex ("colorIndex", myArrColorInd, myNbColors);
180 aStatus = WriteClosing();
185 //=======================================================================
186 //function : IsDefault
187 //purpose : Returns True if the node is default,
188 // so that it should not be written.
189 //=======================================================================
191 Standard_Boolean VrmlData_IndexedLineSet::IsDefault () const
193 Standard_Boolean aResult (Standard_True);
195 aResult = Standard_False;
196 else if (myCoords.IsNull() == Standard_False)
197 aResult = myCoords->IsDefault();