0031687: Draw Harness, ViewerTest - extend command vrenderparams with option updating...
[occt.git] / src / XSDRAWSTLVRML / XSDRAWSTLVRML_DataSource3D.cxx
CommitLineData
709e97a0 1// Created on: 2014-08-04
2// Created by: Artem NOVIKOV
3// Copyright (c) 2014 OPEN CASCADE SAS
4//
5// This file is part of Open CASCADE Technology software library.
6//
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.
12//
13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
15
709e97a0 16
42cf5bc1 17#include <Standard_Type.hxx>
709e97a0 18#include <TColgp_SequenceOfXYZ.hxx>
709e97a0 19#include <TColStd_DataMapOfIntegerInteger.hxx>
42cf5bc1 20#include <TColStd_DataMapOfIntegerReal.hxx>
21#include <XSDRAWSTLVRML_DataSource3D.hxx>
709e97a0 22
92efcf78 23IMPLEMENT_STANDARD_RTTIEXT(XSDRAWSTLVRML_DataSource3D,MeshVS_DataSource)
24
709e97a0 25//================================================================
26// Function : Constructor
27// Purpose :
28//================================================================
29XSDRAWSTLVRML_DataSource3D::XSDRAWSTLVRML_DataSource3D()
30{
31 for (Standard_Integer aNodeID = 1; aNodeID <= 16; aNodeID++)
32 {
33 myNodes.Add( aNodeID );
34 }
35
36 for (Standard_Integer anElemID = 1; anElemID <= 5; anElemID++)
37 {
38 myElements.Add( anElemID );
39 }
40
41 myNodeCoords = new TColStd_HArray2OfReal(1, 16, 1, 3);
42
43 myNodeCoords->SetValue( 1, 1, 5 );
44 myNodeCoords->SetValue( 1, 2, 5 );
45 myNodeCoords->SetValue( 1, 3, 20 );
46
47 myNodeCoords->SetValue( 2, 1, 0 );
48 myNodeCoords->SetValue( 2, 2, 10 );
49 myNodeCoords->SetValue( 2, 3, 10 );
50
51 myNodeCoords->SetValue( 3, 1, 10 );
52 myNodeCoords->SetValue( 3, 2, 0 );
53 myNodeCoords->SetValue( 3, 3, 10 );
54
55 myNodeCoords->SetValue( 4, 1, 0 );
56 myNodeCoords->SetValue( 4, 2, 0 );
57 myNodeCoords->SetValue( 4, 3, 10 );
58
59 myNodeCoords->SetValue( 5, 1, -10 );
60 myNodeCoords->SetValue( 5, 2, 0 );
61 myNodeCoords->SetValue( 5, 3, 10 );
62
63 myNodeCoords->SetValue( 6, 1, -10 );
64 myNodeCoords->SetValue( 6, 2, 10 );
65 myNodeCoords->SetValue( 6, 3, 10 );
66
67 myNodeCoords->SetValue( 7, 1, -10 );
68 myNodeCoords->SetValue( 7, 2, 10 );
69 myNodeCoords->SetValue( 7, 3, 0 );
70
71 myNodeCoords->SetValue( 8, 1, -10 );
72 myNodeCoords->SetValue( 8, 2, 0 );
73 myNodeCoords->SetValue( 8, 3, 0 );
74
75 myNodeCoords->SetValue( 9, 1, 0 );
76 myNodeCoords->SetValue( 9, 2, 0 );
77 myNodeCoords->SetValue( 9, 3, 0 );
78
79 myNodeCoords->SetValue( 10, 1, 0 );
80 myNodeCoords->SetValue( 10, 2, 10 );
81 myNodeCoords->SetValue( 10, 3, 0 );
82
83 myNodeCoords->SetValue( 11, 1, 0 );
84 myNodeCoords->SetValue( 11, 2, -10 );
85 myNodeCoords->SetValue( 11, 3, 10 );
86
87 myNodeCoords->SetValue( 12, 1, 10 );
88 myNodeCoords->SetValue( 12, 2, -10 );
89 myNodeCoords->SetValue( 12, 3, 10 );
90
91 myNodeCoords->SetValue( 13, 1, 10 );
92 myNodeCoords->SetValue( 13, 2, -10 );
93 myNodeCoords->SetValue( 13, 3, 0 );
94
95 myNodeCoords->SetValue( 14, 1, 0 );
96 myNodeCoords->SetValue( 14, 2, -10 );
97 myNodeCoords->SetValue( 14, 3, 0 );
98
99 myNodeCoords->SetValue( 15, 1, 10 );
100 myNodeCoords->SetValue( 15, 2, 0 );
101 myNodeCoords->SetValue( 15, 3, 0 );
102
103 myNodeCoords->SetValue( 16, 1, 5 );
104 myNodeCoords->SetValue( 16, 2, 5 );
105 myNodeCoords->SetValue( 16, 3, -10 );
106
107 myElemNbNodes = new TColStd_HArray1OfInteger(1, 5);
108
109 myElemNbNodes->SetValue( 1, 4 );
110 myElemNbNodes->SetValue( 2, 8 );
111 myElemNbNodes->SetValue( 3, 6 );
112 myElemNbNodes->SetValue( 4, 8 );
113 myElemNbNodes->SetValue( 5, 4 );
114
115 myElemNodes = new TColStd_HArray2OfInteger(1, 5, 1, 8);
116
117 myElemNodes->SetValue(1, 1, 1);
118 myElemNodes->SetValue(1, 2, 2);
119 myElemNodes->SetValue(1, 3, 3);
120 myElemNodes->SetValue(1, 4, 4);
121
122 myElemNodes->SetValue(2, 1, 2);
123 myElemNodes->SetValue(2, 2, 4);
124 myElemNodes->SetValue(2, 3, 5);
125 myElemNodes->SetValue(2, 4, 6);
126 myElemNodes->SetValue(2, 5, 7);
127 myElemNodes->SetValue(2, 6, 8);
128 myElemNodes->SetValue(2, 7, 9);
129 myElemNodes->SetValue(2, 8, 10);
130
131 myElemNodes->SetValue(3, 1, 2);
132 myElemNodes->SetValue(3, 2, 3);
133 myElemNodes->SetValue(3, 3, 4);
134 myElemNodes->SetValue(3, 4, 10);
135 myElemNodes->SetValue(3, 5, 15);
136 myElemNodes->SetValue(3, 6, 9);
137
138 myElemNodes->SetValue(4, 1, 4);
139 myElemNodes->SetValue(4, 2, 3);
140 myElemNodes->SetValue(4, 3, 12);
141 myElemNodes->SetValue(4, 4, 11);
142 myElemNodes->SetValue(4, 5, 14);
143 myElemNodes->SetValue(4, 6, 13);
144 myElemNodes->SetValue(4, 7, 15);
145 myElemNodes->SetValue(4, 8, 9);
146
147 myElemNodes->SetValue(5, 1, 16);
148 myElemNodes->SetValue(5, 2, 15);
149 myElemNodes->SetValue(5, 3, 10);
150 myElemNodes->SetValue(5, 4, 9);
151}
152
153//================================================================
154// Function : GetGeom
155// Purpose :
156//================================================================
157Standard_Boolean XSDRAWSTLVRML_DataSource3D::GetGeom
158( const Standard_Integer theID, const Standard_Boolean theIsElement,
159 TColStd_Array1OfReal& theCoords, Standard_Integer& theNbNodes,
160 MeshVS_EntityType& theType ) const
161{
162 if (theIsElement)
163 {
164 if (theID >= 1 && theID <= myElements.Extent())
165 {
166 theType = MeshVS_ET_Volume;
167 theNbNodes = myElemNbNodes->Value(theID);
168
169 for (Standard_Integer aNodeI = 1, aGlobCoordI = 1; aNodeI <= theNbNodes; aNodeI++)
170 {
171 Standard_Integer anIdxNode = myElemNodes->Value(theID, aNodeI);
172 for(Standard_Integer aCoordI = 1; aCoordI <= 3; aCoordI++, aGlobCoordI++ )
173 theCoords(aGlobCoordI) = myNodeCoords->Value(anIdxNode, aCoordI);
174 }
175
176 return Standard_True;
177 }
178 else
179 return Standard_False;
180 }
181 else
182 if (theID >= 1 && theID <= myNodes.Extent())
183 {
184 theType = MeshVS_ET_Node;
185 theNbNodes = 1;
186
187 theCoords( 1 ) = myNodeCoords->Value(theID, 1);
188 theCoords( 2 ) = myNodeCoords->Value(theID, 2);
189 theCoords( 3 ) = myNodeCoords->Value(theID, 3);
190 return Standard_True;
191 }
192 else
193 return Standard_False;
194}
195
196//================================================================
197// Function : Get3DGeom
198// Purpose :
199//================================================================
200Standard_Boolean XSDRAWSTLVRML_DataSource3D::Get3DGeom
201( const Standard_Integer theID, Standard_Integer& theNbNodes,
202 Handle(MeshVS_HArray1OfSequenceOfInteger)& theData ) const
203{
204 Handle(MeshVS_HArray1OfSequenceOfInteger) aMeshData;
205 if (theID == 1 || theID == 5)
206 {
207 aMeshData = new MeshVS_HArray1OfSequenceOfInteger(1,4);
208 theNbNodes = 4;
209 for (Standard_Integer anElemI = 1; anElemI <= 4; anElemI++)
210 {
211 aMeshData->ChangeValue(anElemI).Append( (anElemI - 1) % 4 );
212 aMeshData->ChangeValue(anElemI).Append( anElemI % 4 );
213 aMeshData->ChangeValue(anElemI).Append( (anElemI + 1) % 4 );
214 }
215 theData = aMeshData;
216 return Standard_True;
217 }
218
219 if (theID == 2 || theID == 4)
220 {
221 aMeshData = new MeshVS_HArray1OfSequenceOfInteger(1,6);
222 theNbNodes = 8;
223 for (Standard_Integer anElemI = 1, k = 1; anElemI <= 4; anElemI++)
224 {
225 aMeshData->ChangeValue(anElemI).Append( (k - 1) % 8 );
226 aMeshData->ChangeValue(anElemI).Append( k % 8 );
227 aMeshData->ChangeValue(anElemI).Append( (k + 1) % 8 );
228 aMeshData->ChangeValue(anElemI).Append( (k + 2) % 8 );
229 k+=2;
230 }
231
232 aMeshData->ChangeValue(5).Append( 0 );
233 aMeshData->ChangeValue(5).Append( 3 );
234 aMeshData->ChangeValue(5).Append( 4 );
235 aMeshData->ChangeValue(5).Append( 7 );
236
237 aMeshData->ChangeValue(6).Append( 1 );
238 aMeshData->ChangeValue(6).Append( 2 );
239 aMeshData->ChangeValue(6).Append( 5 );
240 aMeshData->ChangeValue(6).Append( 6 );
241
242 theData = aMeshData;
243 return Standard_True;
244 }
245
246 if (theID == 3)
247 {
248 aMeshData = new MeshVS_HArray1OfSequenceOfInteger(1,5);
249 theNbNodes = 6;
250 for (Standard_Integer anElemI = 1; anElemI <= 2; anElemI++)
251 {
252 aMeshData->ChangeValue(anElemI).Append( (anElemI - 1) * 3 );
253 aMeshData->ChangeValue(anElemI).Append( (anElemI - 1) * 3 + 1 );
254 aMeshData->ChangeValue(anElemI).Append( (anElemI - 1) * 3 + 2 );
255 }
256 for (Standard_Integer anElemI = 1; anElemI <= 3; anElemI++)
257 {
258 aMeshData->ChangeValue(2 + anElemI).Append( (anElemI - 1) % 3 );
259 aMeshData->ChangeValue(2 + anElemI).Append( anElemI % 3 );
260 aMeshData->ChangeValue(2 + anElemI).Append( anElemI % 3 + 3 );
261 aMeshData->ChangeValue(2 + anElemI).Append( (anElemI - 1) % 3 + 3 );
262 }
263 theData = aMeshData;
264 return Standard_True;
265 }
266
267 return Standard_False;
268}
269
270//================================================================
271// Function : GetGeomType
272// Purpose :
273//================================================================
274Standard_Boolean XSDRAWSTLVRML_DataSource3D::GetGeomType
275( const Standard_Integer theID,
276 const Standard_Boolean theIsElement,
277 MeshVS_EntityType& theType ) const
278{
279 if (theIsElement)
280 {
281 if (theID >= 1 && theID <= myElements.Extent())
282 {
283 theType = MeshVS_ET_Volume;
284 return Standard_True;
285 }
286 }
287 else
288 if (theID >= 1 && theID <= myNodes.Extent())
289 {
290 theType = MeshVS_ET_Node;
291 return Standard_True;
292 }
293
294 return Standard_False;
295}
296
297//================================================================
298// Function : GetAddr
299// Purpose :
300//================================================================
301Standard_Address XSDRAWSTLVRML_DataSource3D::GetAddr
302( const Standard_Integer, const Standard_Boolean ) const
303{
304 return NULL;
305}
306
307//================================================================
308// Function : GetNodesByElement
309// Purpose :
310//================================================================
311Standard_Boolean XSDRAWSTLVRML_DataSource3D::GetNodesByElement
312( const Standard_Integer theID,
313 TColStd_Array1OfInteger& theNodeIDs,
314 Standard_Integer& theNbNodes ) const
315{
316 Standard_Integer aLow;
317 if (theID == 1 || theID == 5)
318 {
319 theNbNodes = 4;
320 aLow = theNodeIDs.Lower();
321 theNodeIDs (aLow) = myElemNodes->Value(theID, 1 );
322 theNodeIDs (aLow + 1) = myElemNodes->Value(theID, 2 );
323 theNodeIDs (aLow + 2) = myElemNodes->Value(theID, 3 );
324 theNodeIDs (aLow + 3) = myElemNodes->Value(theID, 4 );
325 return Standard_True;
326 }
327
328 if (theID == 2 || theID == 4)
329 {
330 theNbNodes = 8;
331 aLow = theNodeIDs.Lower();
332 theNodeIDs (aLow) = myElemNodes->Value(theID, 1 );
333 theNodeIDs (aLow + 1) = myElemNodes->Value(theID, 2 );
334 theNodeIDs (aLow + 2) = myElemNodes->Value(theID, 3 );
335 theNodeIDs (aLow + 3) = myElemNodes->Value(theID, 4 );
336 theNodeIDs (aLow + 4) = myElemNodes->Value(theID, 5 );
337 theNodeIDs (aLow + 5) = myElemNodes->Value(theID, 6 );
338 theNodeIDs (aLow + 6) = myElemNodes->Value(theID, 7 );
339 theNodeIDs (aLow + 7) = myElemNodes->Value(theID, 8 );
340 return Standard_True;
341 }
342
343 if (theID == 3)
344 {
345 theNbNodes = 6;
346 aLow = theNodeIDs.Lower();
347 theNodeIDs (aLow) = myElemNodes->Value(theID, 1 );
348 theNodeIDs (aLow + 1) = myElemNodes->Value(theID, 2 );
349 theNodeIDs (aLow + 2) = myElemNodes->Value(theID, 3 );
350 theNodeIDs (aLow + 3) = myElemNodes->Value(theID, 4 );
351 theNodeIDs (aLow + 4) = myElemNodes->Value(theID, 5 );
352 theNodeIDs (aLow + 5) = myElemNodes->Value(theID, 6 );
353 return Standard_True;
354 }
355
356 return Standard_False;
357}
358
359//================================================================
360// Function : GetAllNodes
361// Purpose :
362//================================================================
363const TColStd_PackedMapOfInteger& XSDRAWSTLVRML_DataSource3D::GetAllNodes() const
364{
365 return myNodes;
366}
367
368//================================================================
369// Function : GetAllElements
370// Purpose :
371//================================================================
372const TColStd_PackedMapOfInteger& XSDRAWSTLVRML_DataSource3D::GetAllElements() const
373{
374 return myElements;
375}
376
377//================================================================
378// Function : GetNormal
379// Purpose :
380//================================================================
381Standard_Boolean XSDRAWSTLVRML_DataSource3D::GetNormal
382( const Standard_Integer /*theID*/, const Standard_Integer /*theMax*/,
383 Standard_Real& /*theNx*/, Standard_Real& /*theNy*/,Standard_Real& /*theNz*/ ) const
384{
385 return Standard_False;
386}