0022922: Clean up warnings on uninitialized / unused variables
[occt.git] / src / VrmlData / VrmlData_IndexedLineSet.cxx
1 // File:      VrmlData_IndexedLineSet.cxx
2 // Created:   01.08.07 09:20
3 // Author:    Alexander GRIGORIEV
4 // Copyright: Open Cascade 2007
5
6
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>
17
18 #ifdef WNT
19 #define _CRT_SECURE_NO_DEPRECATE
20 #pragma warning (disable:4996)
21 #endif
22
23 IMPLEMENT_STANDARD_HANDLE  (VrmlData_IndexedLineSet, VrmlData_Geometry)
24 IMPLEMENT_STANDARD_RTTIEXT (VrmlData_IndexedLineSet, VrmlData_Geometry)
25
26 //=======================================================================
27 //function : GetColor
28 //purpose  : 
29 //=======================================================================
30
31 Quantity_Color VrmlData_IndexedLineSet::GetColor
32                                         (const Standard_Integer /*iFace*/,
33                                          const Standard_Integer /*iVertex*/)
34 {
35   //TODO
36   return Quantity_NOC_BLACK;
37 }
38
39 //=======================================================================
40 //function : TShape
41 //purpose  : Query the shape. This method checks the flag myIsModified;
42 //           if True it should rebuild the shape presentation.
43 //=======================================================================
44
45 const Handle(TopoDS_TShape)& VrmlData_IndexedLineSet::TShape ()
46 {
47   if (myNbPolygons == 0)
48     myTShape.Nullify();
49   else if (myIsModified) {
50     Standard_Integer i;
51     BRep_Builder aBuilder;
52     const gp_XYZ * arrNodes = myCoords->Values();
53
54     // Create the Wire
55     TopoDS_Wire aWire;
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]]);
64         arrParam(j+1) = j;
65       }
66       const Handle(Poly_Polygon3D) aPolyPolygon =
67         new Poly_Polygon3D (arrPoint, arrParam);
68       TopoDS_Edge anEdge;
69       aBuilder.MakeEdge (anEdge, aPolyPolygon);
70       aBuilder.Add (aWire, anEdge);
71     }
72     myTShape = aWire.TShape();
73   }
74   return myTShape;
75 }
76
77 //=======================================================================
78 //function : Clone
79 //purpose  : Create a copy of this node
80 //=======================================================================
81
82 Handle(VrmlData_Node) VrmlData_IndexedLineSet::Clone
83                                 (const Handle(VrmlData_Node)& theOther) const
84 {
85   Handle(VrmlData_IndexedLineSet) aResult =
86     Handle(VrmlData_IndexedLineSet)::DownCast (VrmlData_Node::Clone(theOther));
87   if (aResult.IsNull())
88     aResult =
89       new VrmlData_IndexedLineSet(theOther.IsNull()? Scene(): theOther->Scene(),
90                                   Name());
91
92   if (&aResult->Scene() == &Scene()) {
93     aResult->SetCoordinates (myCoords);
94     aResult->SetColors      (myColors);
95     aResult->SetPolygons    (myNbPolygons, myArrPolygons);
96     aResult->SetColorInd    (myNbColors, myArrColorInd);
97   } else {
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);
110   }
111   aResult->SetColorPerVertex  (myColorPerVertex);
112   return aResult;
113 }
114
115 //=======================================================================
116 //function : Read
117 //purpose  : Read the Node from input stream.
118 //=======================================================================
119
120 VrmlData_ErrorStatus VrmlData_IndexedLineSet::Read
121                                         (VrmlData_InBuffer& theBuffer)
122 {
123   VrmlData_ErrorStatus aStatus;
124   const VrmlData_Scene& aScene = Scene();
125   while (OK(aStatus, VrmlData_Scene::ReadLine(theBuffer)))
126   {
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));
141     else
142       break;
143     if (!OK(aStatus))
144       break;
145   }
146   // Read the terminating (closing) brace
147   if (OK(aStatus) || aStatus == VrmlData_EmptyData)
148     if (OK(aStatus, readBrace (theBuffer))) {
149       // Post-processing
150       ;
151     }
152   return aStatus;
153 }
154
155 //=======================================================================
156 //function : Write
157 //purpose  : Write the Node to output stream
158 //=======================================================================
159
160 VrmlData_ErrorStatus VrmlData_IndexedLineSet::Write
161                                         (const char * thePrefix) const
162 {
163   static char header[] = "IndexedLineSet {";
164   const VrmlData_Scene& aScene = Scene();
165   VrmlData_ErrorStatus aStatus;
166   if (OK (aStatus, aScene.WriteLine (thePrefix, header, GlobalIndent()))) {
167
168     if (OK(aStatus) && myCoords.IsNull() == Standard_False)
169       aStatus = aScene.WriteNode ("coord", myCoords);
170     if (OK(aStatus))
171       aStatus = aScene.WriteArrIndex ("coordIndex", myArrPolygons,myNbPolygons);
172
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);
177     if (OK(aStatus))
178       aStatus = aScene.WriteArrIndex ("colorIndex", myArrColorInd, myNbColors);
179
180     aStatus = WriteClosing();
181   }
182   return aStatus;
183 }
184
185 //=======================================================================
186 //function : IsDefault
187 //purpose  : Returns True if the node is default,
188 //           so that it should not be written.
189 //=======================================================================
190
191 Standard_Boolean VrmlData_IndexedLineSet::IsDefault () const
192 {
193   Standard_Boolean aResult (Standard_True);
194   if (myNbPolygons)
195     aResult = Standard_False;
196   else if (myCoords.IsNull() == Standard_False)
197     aResult = myCoords->IsDefault();
198   return aResult;
199 }
200