Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 2000-05-30 |
2 | // Created by: Sergey MOZOKHIN | |
973c2be1 | 3 | // Copyright (c) 2000-2014 OPEN CASCADE SAS |
b311480e | 4 | // |
973c2be1 | 5 | // This file is part of Open CASCADE Technology software library. |
b311480e | 6 | // |
d5f74e42 | 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 | |
973c2be1 | 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. | |
b311480e | 12 | // |
973c2be1 | 13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. | |
7fd59977 | 15 | |
16 | #include <XSDRAWSTLVRML.ixx> | |
17 | #include <Draw_Interpretor.hxx> | |
18 | #include <TopoDS_Shape.hxx> | |
19 | #include <VrmlAPI.hxx> | |
20 | #include <OSD_Path.hxx> | |
21 | #include <StlAPI.hxx> | |
22 | #include <XSDRAW.hxx> | |
23 | #include <DBRep.hxx> | |
24 | #include <VrmlAPI_Writer.hxx> | |
25 | #include <Quantity_Color.hxx> | |
26 | #include <Quantity_HArray1OfColor.hxx> | |
27 | #include <StlAPI_Writer.hxx> | |
28 | #include <Draw_PluginMacro.hxx> | |
7fd59977 | 29 | #include <XSDRAW.hxx> |
30 | #include <XSDRAWSTEP.hxx> | |
31 | #include <XSDRAWIGES.hxx> | |
32 | #include <AIS_InteractiveContext.hxx> | |
33 | #include <ViewerTest.hxx> | |
34 | #include <Draw.hxx> | |
9c6afe19 | 35 | #include <Draw_ProgressIndicator.hxx> |
7fd59977 | 36 | #include <RWStl.hxx> |
37 | #include <Quantity_Color.hxx> | |
38 | #include <V3d_View.hxx> | |
39 | #include <TCollection_AsciiString.hxx> | |
40 | ||
41 | #include <SelectMgr_SelectionManager.hxx> | |
42 | #include <StdSelect_ViewerSelector3d.hxx> | |
43 | ||
44 | #include <Aspect_TypeOfMarker.hxx> | |
45 | #include <Graphic3d_MaterialAspect.hxx> | |
46 | ||
47 | #include <StlMesh_Mesh.hxx> | |
48 | #include <StlMesh_SequenceOfMeshTriangle.hxx> | |
49 | ||
50 | #include <MeshVS_Mesh.hxx> | |
51 | #include <MeshVS_MeshPrsBuilder.hxx> | |
52 | #include <MeshVS_TextPrsBuilder.hxx> | |
53 | #include <MeshVS_Drawer.hxx> | |
54 | #include <MeshVS_DrawerAttribute.hxx> | |
55 | #include <MeshVS_MeshEntityOwner.hxx> | |
56 | #include <MeshVS_DataMapOfIntegerAsciiString.hxx> | |
709e97a0 | 57 | #include <MeshVS_NodalColorPrsBuilder.hxx> |
58 | #include <MeshVS_ElementalColorPrsBuilder.hxx> | |
59 | #include <MeshVS_VectorPrsBuilder.hxx> | |
60 | #include <MeshVS_DeformedDataSource.hxx> | |
7fd59977 | 61 | |
62 | #include <XSDRAWSTLVRML_DataSource.hxx> | |
709e97a0 | 63 | #include <XSDRAWSTLVRML_DataSource3D.hxx> |
7fd59977 | 64 | #include <XSDRAWSTLVRML_DrawableMesh.hxx> |
709e97a0 | 65 | |
7fd59977 | 66 | #include <Quantity_NameOfColor.hxx> |
67 | #include <TColgp_SequenceOfXYZ.hxx> | |
68 | #include <TColStd_HPackedMapOfInteger.hxx> | |
69 | #include <TColStd_MapIteratorOfPackedMapOfInteger.hxx> | |
70 | #include <Standard_ErrorHandler.hxx> | |
71 | #include <VrmlData_Scene.hxx> | |
72 | #include <VrmlData_ShapeConvert.hxx> | |
73 | #include <VrmlData_DataMapOfShapeAppearance.hxx> | |
3ba3388b A |
74 | #include <TColStd_Array1OfReal.hxx> |
75 | #include <Bnd_Box.hxx> | |
7fd59977 | 76 | |
7da5f7b1 | 77 | #include <XSDRAWSTLVRML_ToVRML.hxx> |
78 | ||
7fd59977 | 79 | // avoid warnings on 'extern "C"' functions returning C++ classes |
80 | #ifdef WNT | |
81 | #pragma warning(4:4190) | |
82 | #endif | |
83 | ||
84 | #ifndef _STDIO_H | |
85 | #include <stdio.h> | |
86 | #endif | |
87 | ||
709e97a0 | 88 | extern Standard_Boolean VDisplayAISObject (const TCollection_AsciiString& theName, |
89 | const Handle(AIS_InteractiveObject)& theAISObj, | |
90 | Standard_Boolean theReplaceIfExists = Standard_True); | |
91 | ||
7fd59977 | 92 | static Standard_Integer writestl |
93 | (Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
94 | { | |
b9c1e440 | 95 | if (argc < 3 || argc > 4) { |
709e97a0 | 96 | di << "Use: " << argv[0] |
b9c1e440 | 97 | << " shape file [ascii/binary (0/1) : 1 by default]" << "\n"; |
416d4426 | 98 | } else { |
99 | TopoDS_Shape aShape = DBRep::Get(argv[1]); | |
48a06a30 | 100 | Standard_Boolean isASCIIMode = Standard_False; |
b9c1e440 | 101 | if (argc == 4) { |
91322f44 | 102 | isASCIIMode = (Draw::Atoi(argv[3]) == 0); |
68bc5ed7 | 103 | } |
48a06a30 | 104 | StlAPI_Writer aWriter; |
105 | aWriter.ASCIIMode() = isASCIIMode; | |
b9c1e440 | 106 | StlAPI_ErrorStatus aStatus = aWriter.Write (aShape, argv[2]); |
107 | ||
108 | switch (aStatus) | |
109 | { | |
110 | case StlAPI_MeshIsEmpty: di << "** Error **: Mesh is empty. Please, compute triangulation before."; break; | |
111 | case StlAPI_CannotOpenFile: di << "** Error **: Cannot create/open a file with the passed name."; break; | |
112 | case StlAPI_StatusOK: default: break; | |
113 | } | |
7fd59977 | 114 | } |
115 | return 0; | |
116 | } | |
117 | ||
118 | static Standard_Integer readstl | |
119 | (Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
120 | { | |
121 | if (argc<3) di << "wrong number of parameters" << "\n"; | |
122 | else { | |
709e97a0 | 123 | TopoDS_Shape aShape ; |
124 | StlAPI::Read(aShape,argv[2]); | |
125 | DBRep::Set(argv[1],aShape); | |
7fd59977 | 126 | } |
127 | return 0; | |
128 | } | |
129 | ||
130 | static Standard_Integer writevrml | |
131 | (Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
132 | { | |
f5fa6b33 | 133 | if (argc < 3 || argc > 5) |
134 | { | |
135 | di << "wrong number of parameters" << "\n"; | |
136 | return 0; | |
7fd59977 | 137 | } |
f5fa6b33 | 138 | |
139 | TopoDS_Shape aShape = DBRep::Get(argv[1]); | |
140 | ||
141 | // Get the optional parameters | |
142 | Standard_Integer aVersion = 2; | |
143 | Standard_Integer aType = 1; | |
144 | if (argc >= 4) | |
145 | { | |
146 | aVersion = Draw::Atoi(argv[3]); | |
147 | if (argc == 5) | |
148 | aType = Draw::Atoi(argv[4]); | |
149 | } | |
150 | ||
151 | // Bound parameters | |
152 | aVersion = Max(1, aVersion); | |
153 | aVersion = Min(2, aVersion); | |
154 | aType = Max(0, aType); | |
155 | aType = Min(2, aType); | |
156 | ||
157 | VrmlAPI_Writer writer; | |
158 | ||
159 | switch (aType) | |
160 | { | |
161 | case 0: writer.SetRepresentation(VrmlAPI_ShadedRepresentation); break; | |
162 | case 1: writer.SetRepresentation(VrmlAPI_WireFrameRepresentation); break; | |
163 | case 2: writer.SetRepresentation(VrmlAPI_BothRepresentation); break; | |
164 | } | |
165 | ||
166 | writer.Write(aShape, argv[2], aVersion); | |
167 | ||
7fd59977 | 168 | return 0; |
169 | } | |
170 | ||
171 | //======================================================================= | |
172 | //function : loadvrml | |
9c6afe19 | 173 | //purpose : |
7fd59977 | 174 | //======================================================================= |
175 | ||
176 | static Standard_Integer loadvrml | |
177 | (Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
178 | { | |
179 | if (argc<3) di << "wrong number of parameters" << "\n"; | |
180 | else { | |
709e97a0 | 181 | TopoDS_Shape aShape ; |
182 | VrmlData_DataMapOfShapeAppearance aShapeAppMap; | |
7fd59977 | 183 | |
184 | //----------------------------------------------------------- | |
709e97a0 | 185 | filebuf aFic; |
186 | istream aStream (&aFic); | |
7fd59977 | 187 | |
709e97a0 | 188 | if (aFic.open(argv[2], ios::in)) { |
7fd59977 | 189 | |
b569f2a3 | 190 | // Get path of the VRML file. |
709e97a0 | 191 | OSD_Path aPath(argv[2]); |
192 | TCollection_AsciiString aVrmlDir("."); | |
193 | TCollection_AsciiString aDisk = aPath.Disk(); | |
194 | TCollection_AsciiString aTrek = aPath.Trek(); | |
195 | if (!aTrek.IsEmpty()) | |
b569f2a3 | 196 | { |
709e97a0 | 197 | if (!aDisk.IsEmpty()) |
198 | aVrmlDir = aDisk; | |
b569f2a3 | 199 | else |
709e97a0 | 200 | aVrmlDir.Clear(); |
201 | aTrek.ChangeAll('|', '/'); | |
202 | aVrmlDir += aTrek; | |
b569f2a3 | 203 | } |
204 | ||
7fd59977 | 205 | VrmlData_Scene aScene; |
206 | ||
709e97a0 | 207 | aScene.SetVrmlDir (aVrmlDir); |
7fd59977 | 208 | aScene << aStream; |
209 | const char * aStr = 0L; | |
210 | switch (aScene.Status()) { | |
211 | ||
212 | case VrmlData_StatusOK: | |
213 | { | |
709e97a0 | 214 | aShape = aScene.GetShape(aShapeAppMap); |
7fd59977 | 215 | break; |
216 | } | |
566f8441 | 217 | case VrmlData_EmptyData: aStr = "EmptyData"; break; |
218 | case VrmlData_UnrecoverableError: aStr = "UnrecoverableError"; break; | |
219 | case VrmlData_GeneralError: aStr = "GeneralError"; break; | |
220 | case VrmlData_EndOfFile: aStr = "EndOfFile"; break; | |
221 | case VrmlData_NotVrmlFile: aStr = "NotVrmlFile"; break; | |
222 | case VrmlData_CannotOpenFile: aStr = "CannotOpenFile"; break; | |
223 | case VrmlData_VrmlFormatError: aStr = "VrmlFormatError"; break; | |
224 | case VrmlData_NumericInputError: aStr = "NumericInputError"; break; | |
225 | case VrmlData_IrrelevantNumber: aStr = "IrrelevantNumber"; break; | |
226 | case VrmlData_BooleanInputError: aStr = "BooleanInputError"; break; | |
227 | case VrmlData_StringInputError: aStr = "StringInputError"; break; | |
228 | case VrmlData_NodeNameUnknown: aStr = "NodeNameUnknown"; break; | |
229 | case VrmlData_NonPositiveSize: aStr = "NonPositiveSize"; break; | |
230 | case VrmlData_ReadUnknownNode: aStr = "ReadUnknownNode"; break; | |
231 | case VrmlData_NonSupportedFeature: aStr = "NonSupportedFeature"; break; | |
232 | case VrmlData_OutputStreamUndefined:aStr = "OutputStreamUndefined"; break; | |
233 | case VrmlData_NotImplemented: aStr = "NotImplemented"; break; | |
234 | default: | |
235 | break; | |
7fd59977 | 236 | } |
237 | if (aStr) { | |
238 | di << " ++ VRML Error: " << aStr << " in line " | |
239 | << aScene.GetLineError() << "\n"; | |
240 | } | |
241 | else { | |
709e97a0 | 242 | DBRep::Set(argv[1],aShape); |
7fd59977 | 243 | } |
244 | } | |
245 | else { | |
246 | di << "cannot open file" << "\n"; | |
247 | } | |
248 | ||
249 | ||
250 | //----------------------------------------------------------- | |
251 | } | |
252 | return 0; | |
253 | } | |
254 | ||
7fd59977 | 255 | //----------------------------------------------------------------------------- |
256 | static Standard_Integer createmesh | |
257 | (Draw_Interpretor& di, Standard_Integer argc, const char** argv ) | |
258 | { | |
7fd59977 | 259 | if (argc<3) |
260 | { | |
709e97a0 | 261 | di << "Wrong number of parameters" << "\n"; |
7fd59977 | 262 | di << "Use: " << argv[0] << " <mesh name> <stl file>" << "\n"; |
709e97a0 | 263 | return 0; |
264 | } | |
265 | ||
266 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
267 | if (aContext.IsNull()) | |
268 | { | |
269 | di << "No active view. Please call 'vinit' first" << "\n"; | |
270 | return 0; | |
7fd59977 | 271 | } |
272 | ||
9c6afe19 | 273 | // Progress indicator |
7fd59977 | 274 | OSD_Path aFile( argv[2] ); |
9c6afe19 RK |
275 | Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator (di, 1); |
276 | Handle(StlMesh_Mesh) aSTLMesh = RWStl::ReadFile (aFile, aProgress); | |
7fd59977 | 277 | |
278 | di << "Reading OK..." << "\n"; | |
279 | Handle( XSDRAWSTLVRML_DataSource ) aDS = new XSDRAWSTLVRML_DataSource( aSTLMesh ); | |
280 | di << "Data source is created successful" << "\n"; | |
281 | Handle( MeshVS_Mesh ) aMesh = new MeshVS_Mesh(); | |
282 | di << "MeshVS_Mesh is created successful" << "\n"; | |
283 | ||
284 | aMesh->SetDataSource( aDS ); | |
285 | aMesh->AddBuilder( new MeshVS_MeshPrsBuilder( aMesh.operator->() ), Standard_True ); | |
7fd59977 | 286 | |
709e97a0 | 287 | aMesh->GetDrawer()->SetColor( MeshVS_DA_EdgeColor, Quantity_NOC_YELLOW ); |
7fd59977 | 288 | |
289 | // Hide all nodes by default | |
290 | Handle(TColStd_HPackedMapOfInteger) aNodes = new TColStd_HPackedMapOfInteger(); | |
709e97a0 | 291 | Standard_Integer aLen = aSTLMesh->Vertices().Length(); |
292 | for ( Standard_Integer anIndex = 1; anIndex <= aLen; anIndex++ ) | |
7fd59977 | 293 | aNodes->ChangeMap().Add( anIndex ); |
294 | aMesh->SetHiddenNodes( aNodes ); | |
709e97a0 | 295 | aMesh->SetSelectableNodes ( aNodes ); |
7fd59977 | 296 | |
709e97a0 | 297 | VDisplayAISObject(argv[1], aMesh); |
298 | aContext->Deactivate( aMesh ); | |
299 | ||
300 | Draw::Set( argv[1], new XSDRAWSTLVRML_DrawableMesh( aMesh ) ); | |
301 | Handle( V3d_View ) aView = ViewerTest::CurrentView(); | |
302 | if ( !aView.IsNull() ) | |
303 | aView->FitAll(); | |
7fd59977 | 304 | |
709e97a0 | 305 | return 0; |
306 | } | |
307 | //----------------------------------------------------------------------------- | |
308 | ||
309 | static Standard_Integer create3d | |
310 | (Draw_Interpretor& di, Standard_Integer argc, const char** argv ) | |
311 | { | |
312 | if (argc<2) | |
7fd59977 | 313 | { |
709e97a0 | 314 | di << "Wrong number of parameters" << "\n"; |
315 | di << "Use: " << argv[0] << " <mesh name>" << "\n"; | |
316 | return 0; | |
7fd59977 | 317 | } |
318 | ||
709e97a0 | 319 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); |
320 | if (aContext.IsNull()) | |
321 | { | |
322 | di << "No active view. Please call 'vinit' first" << "\n"; | |
323 | return 0; | |
324 | } | |
325 | ||
326 | Handle( XSDRAWSTLVRML_DataSource3D ) aDS = new XSDRAWSTLVRML_DataSource3D(); | |
327 | di << "Data source is created successful" << "\n"; | |
328 | Handle( MeshVS_Mesh ) aMesh = new MeshVS_Mesh(); | |
329 | di << "MeshVS_Mesh is created successful" << "\n"; | |
330 | ||
331 | aMesh->SetDataSource( aDS ); | |
332 | aMesh->AddBuilder( new MeshVS_MeshPrsBuilder( aMesh.operator->() ), Standard_True ); | |
333 | ||
334 | aMesh->GetDrawer()->SetColor( MeshVS_DA_EdgeColor, Quantity_NOC_YELLOW ); | |
335 | ||
336 | // Hide all nodes by default | |
337 | Handle(TColStd_HPackedMapOfInteger) aNodes = new TColStd_HPackedMapOfInteger(); | |
338 | Standard_Integer aLen = aDS->GetAllNodes().Extent(); | |
339 | for ( Standard_Integer anIndex = 1; anIndex <= aLen; anIndex++ ) | |
340 | aNodes->ChangeMap().Add( anIndex ); | |
341 | aMesh->SetHiddenNodes( aNodes ); | |
342 | aMesh->SetSelectableNodes ( aNodes ); | |
343 | ||
344 | VDisplayAISObject(argv[1], aMesh); | |
7fd59977 | 345 | aContext->Deactivate( aMesh ); |
346 | ||
347 | Draw::Set( argv[1], new XSDRAWSTLVRML_DrawableMesh( aMesh ) ); | |
709e97a0 | 348 | Handle( V3d_View ) aView = ViewerTest::CurrentView(); |
349 | if ( !aView.IsNull() ) | |
350 | aView->FitAll(); | |
7fd59977 | 351 | |
352 | return 0; | |
353 | } | |
709e97a0 | 354 | |
355 | Handle( MeshVS_Mesh ) getMesh( const char* theName, Draw_Interpretor& di) | |
7fd59977 | 356 | { |
357 | Handle( XSDRAWSTLVRML_DrawableMesh ) aDrawMesh = | |
709e97a0 | 358 | Handle( XSDRAWSTLVRML_DrawableMesh )::DownCast( Draw::Get( theName ) ); |
7fd59977 | 359 | |
360 | if( aDrawMesh.IsNull() ) | |
361 | { | |
362 | di << "There is no such object" << "\n"; | |
363 | return NULL; | |
364 | } | |
365 | else | |
366 | { | |
367 | Handle( MeshVS_Mesh ) aMesh = aDrawMesh->GetMesh(); | |
368 | if( aMesh.IsNull() ) | |
369 | { | |
370 | di << "There is invalid mesh" << "\n"; | |
371 | return NULL; | |
372 | } | |
373 | else | |
374 | return aMesh; | |
375 | } | |
376 | } | |
7fd59977 | 377 | |
7fd59977 | 378 | //----------------------------------------------------------------------------- |
379 | static Standard_Integer setcolor | |
709e97a0 | 380 | (Draw_Interpretor& di, Standard_Integer argc, const char** argv, Standard_Integer theParam ) |
7fd59977 | 381 | { |
382 | if (argc<5) | |
709e97a0 | 383 | di << "Wrong number of parameters" << "\n"; |
7fd59977 | 384 | else |
385 | { | |
386 | Handle( MeshVS_Mesh ) aMesh = getMesh( argv[1], di ); | |
387 | if( !aMesh.IsNull() ) | |
388 | { | |
709e97a0 | 389 | Standard_Real aRed = Draw::Atof (argv[2]); |
390 | Standard_Real aGreen = Draw::Atof (argv[3]); | |
391 | Standard_Real aBlue = Draw::Atof (argv[4]); | |
392 | aMesh->GetDrawer()->SetColor( (MeshVS_DrawerAttribute)theParam, | |
393 | Quantity_Color( aRed, aGreen, aBlue, Quantity_TOC_RGB ) ); | |
7fd59977 | 394 | |
395 | Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext(); | |
396 | ||
397 | if( aContext.IsNull() ) | |
398 | di << "The context is null" << "\n"; | |
399 | else | |
400 | aContext->Redisplay( aMesh ); | |
401 | } | |
402 | } | |
403 | return 0; | |
404 | } | |
405 | //----------------------------------------------------------------------------- | |
406 | static Standard_Integer meshcolor | |
709e97a0 | 407 | (Draw_Interpretor& theInterp, Standard_Integer argc, const char** argv ) |
7fd59977 | 408 | { |
709e97a0 | 409 | return setcolor( theInterp, argc, argv, MeshVS_DA_InteriorColor ); |
7fd59977 | 410 | } |
411 | //----------------------------------------------------------------------------- | |
412 | static Standard_Integer linecolor | |
709e97a0 | 413 | (Draw_Interpretor& theInterp, Standard_Integer argc, const char** argv ) |
7fd59977 | 414 | { |
709e97a0 | 415 | return setcolor( theInterp, argc, argv, MeshVS_DA_EdgeColor ); |
7fd59977 | 416 | } |
417 | //----------------------------------------------------------------------------- | |
418 | static Standard_Integer meshmat | |
419 | (Draw_Interpretor& di, Standard_Integer argc, const char** argv ) | |
420 | { | |
421 | if (argc<3) | |
709e97a0 | 422 | di << "Wrong number of parameters" << "\n"; |
7fd59977 | 423 | else |
424 | { | |
425 | Handle( MeshVS_Mesh ) aMesh = getMesh( argv[1], di ); | |
426 | if( !aMesh.IsNull() ) | |
427 | { | |
709e97a0 | 428 | Standard_Integer aMaterial = Draw::Atoi (argv[2]); |
7fd59977 | 429 | |
430 | Graphic3d_MaterialAspect aMatAsp = | |
709e97a0 | 431 | (Graphic3d_MaterialAspect)(Graphic3d_NameOfMaterial)aMaterial; |
7fd59977 | 432 | |
709e97a0 | 433 | if (argc == 4) |
434 | { | |
435 | Standard_Real aTransparency = Draw::Atof(argv[3]); | |
436 | aMatAsp.SetTransparency(aTransparency); | |
437 | } | |
7fd59977 | 438 | aMesh->GetDrawer()->SetMaterial( MeshVS_DA_FrontMaterial, aMatAsp ); |
439 | aMesh->GetDrawer()->SetMaterial( MeshVS_DA_BackMaterial, aMatAsp ); | |
440 | ||
441 | Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext(); | |
442 | ||
443 | if( aContext.IsNull() ) | |
444 | di << "The context is null" << "\n"; | |
445 | else | |
446 | aContext->Redisplay( aMesh ); | |
447 | } | |
448 | } | |
449 | return 0; | |
450 | } | |
451 | //----------------------------------------------------------------------------- | |
452 | static Standard_Integer shrink | |
453 | (Draw_Interpretor& di, Standard_Integer argc, const char** argv ) | |
454 | { | |
455 | if (argc<3) | |
709e97a0 | 456 | di << "Wrong number of parameters" << "\n"; |
7fd59977 | 457 | else |
458 | { | |
459 | Handle( MeshVS_Mesh ) aMesh = getMesh( argv[1], di ); | |
460 | if( !aMesh.IsNull() ) | |
461 | { | |
709e97a0 | 462 | Standard_Real aShrinkCoeff = Draw::Atof (argv[2]); |
463 | aMesh->GetDrawer()->SetDouble( MeshVS_DA_ShrinkCoeff, aShrinkCoeff ); | |
7fd59977 | 464 | |
465 | Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext(); | |
466 | ||
467 | if( aContext.IsNull() ) | |
468 | di << "The context is null" << "\n"; | |
469 | else | |
470 | aContext->Redisplay( aMesh ); | |
471 | } | |
472 | } | |
473 | return 0; | |
474 | } | |
475 | //----------------------------------------------------------------------------- | |
476 | ||
477 | static Standard_Integer mdisplay | |
478 | (Draw_Interpretor& di, Standard_Integer argc, const char** argv ) | |
479 | { | |
480 | if (argc<2) | |
709e97a0 | 481 | di << "Wrong number of parameters" << "\n"; |
7fd59977 | 482 | else |
483 | { | |
484 | Handle( MeshVS_Mesh ) aMesh = getMesh( argv[1], di ); | |
485 | if( !aMesh.IsNull() ) | |
486 | { | |
487 | Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext(); | |
488 | ||
489 | if( aContext.IsNull() ) | |
490 | di << "The context is null" << "\n"; | |
491 | else | |
492 | { | |
493 | if( aContext->HasOpenedContext() ) | |
494 | aContext->CloseLocalContext(); | |
495 | ||
496 | aContext->Display( aMesh ); | |
497 | } | |
498 | } | |
499 | } | |
500 | return 0; | |
501 | } | |
502 | //----------------------------------------------------------------------------- | |
503 | static Standard_Integer merase | |
504 | (Draw_Interpretor& di, Standard_Integer argc, const char** argv ) | |
505 | { | |
506 | if (argc<2) | |
709e97a0 | 507 | di << "Wrong number of parameters" << "\n"; |
7fd59977 | 508 | else |
509 | { | |
510 | Handle( MeshVS_Mesh ) aMesh = getMesh( argv[1], di ); | |
511 | if( !aMesh.IsNull() ) | |
512 | { | |
513 | Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext(); | |
514 | ||
515 | if( aContext.IsNull() ) | |
516 | di << "The context is null" << "\n"; | |
517 | else | |
518 | { | |
519 | if( aContext->HasOpenedContext() ) | |
520 | aContext->CloseLocalContext(); | |
521 | ||
522 | aContext->Erase( aMesh ); | |
523 | } | |
524 | } | |
525 | else | |
526 | di << "Mesh is null" << "\n"; | |
527 | } | |
528 | return 0; | |
529 | } | |
530 | //----------------------------------------------------------------------------- | |
531 | static Standard_Integer hidesel | |
532 | (Draw_Interpretor& di, Standard_Integer argc, const char** argv ) | |
533 | { | |
709e97a0 | 534 | if (argc<2) |
7fd59977 | 535 | { |
709e97a0 | 536 | di << "Wrong number of parameters" << "\n"; |
537 | di << "Use: " << argv[0] << " <mesh name>" << "\n"; | |
7fd59977 | 538 | return 0; |
539 | } | |
540 | ||
7fd59977 | 541 | Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext(); |
542 | Handle( MeshVS_Mesh ) aMesh = getMesh( argv[1], di ); | |
543 | if( aMesh.IsNull() ) | |
544 | { | |
545 | di << "The mesh is invalid" << "\n"; | |
546 | return 0; | |
547 | } | |
548 | ||
549 | if( aContext.IsNull() ) | |
550 | di << "The context is null" << "\n"; | |
551 | else | |
552 | { | |
553 | Handle(TColStd_HPackedMapOfInteger) aHiddenNodes = aMesh->GetHiddenNodes(); | |
709e97a0 | 554 | if (aHiddenNodes.IsNull()) |
555 | { | |
556 | aHiddenNodes = new TColStd_HPackedMapOfInteger(); | |
557 | } | |
7fd59977 | 558 | Handle(TColStd_HPackedMapOfInteger) aHiddenElements = aMesh->GetHiddenElems(); |
709e97a0 | 559 | if (aHiddenElements.IsNull()) |
560 | { | |
561 | aHiddenElements = new TColStd_HPackedMapOfInteger(); | |
562 | } | |
7fd59977 | 563 | for( aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected() ) |
564 | { | |
565 | Handle( MeshVS_MeshEntityOwner ) anOwner = | |
566 | Handle( MeshVS_MeshEntityOwner )::DownCast( aContext->SelectedOwner() ); | |
567 | if( !anOwner.IsNull() ) | |
eafb234b | 568 | { |
7fd59977 | 569 | if( anOwner->Type()==MeshVS_ET_Node ) |
eafb234b | 570 | { |
7fd59977 | 571 | aHiddenNodes->ChangeMap().Add( anOwner->ID() ); |
eafb234b | 572 | } |
7fd59977 | 573 | else |
eafb234b | 574 | { |
7fd59977 | 575 | aHiddenElements->ChangeMap().Add( anOwner->ID() ); |
eafb234b | 576 | } |
577 | } | |
7fd59977 | 578 | } |
579 | aContext->ClearSelected(); | |
580 | aMesh->SetHiddenNodes( aHiddenNodes ); | |
581 | aMesh->SetHiddenElems( aHiddenElements ); | |
582 | aContext->Redisplay( aMesh ); | |
583 | } | |
584 | ||
585 | return 0; | |
586 | } | |
587 | //----------------------------------------------------------------------------- | |
588 | static Standard_Integer showonly | |
589 | (Draw_Interpretor& di, Standard_Integer argc, const char** argv ) | |
590 | { | |
709e97a0 | 591 | if (argc<2) |
7fd59977 | 592 | { |
709e97a0 | 593 | di << "Wrong number of parameters" << "\n"; |
594 | di << "Use: " << argv[0] << " <mesh name>" << "\n"; | |
7fd59977 | 595 | return 0; |
596 | } | |
597 | ||
598 | ||
599 | Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext(); | |
600 | Handle( MeshVS_Mesh ) aMesh = getMesh( argv[1], di ); | |
601 | if( aMesh.IsNull() ) | |
602 | { | |
603 | di << "The mesh is invalid" << "\n"; | |
604 | return 0; | |
605 | } | |
606 | ||
607 | if( aContext.IsNull() ) | |
608 | di << "The context is null" << "\n"; | |
609 | else | |
610 | { | |
9c6afe19 | 611 | Handle(TColStd_HPackedMapOfInteger) aHiddenNodes = |
7fd59977 | 612 | new TColStd_HPackedMapOfInteger(aMesh->GetDataSource()->GetAllNodes()); |
9c6afe19 | 613 | Handle(TColStd_HPackedMapOfInteger) aHiddenElements = |
7fd59977 | 614 | new TColStd_HPackedMapOfInteger(aMesh->GetDataSource()->GetAllElements()); |
615 | for( aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected() ) | |
616 | { | |
617 | Handle( MeshVS_MeshEntityOwner ) anOwner = | |
618 | Handle( MeshVS_MeshEntityOwner )::DownCast( aContext->SelectedOwner() ); | |
619 | if( !anOwner.IsNull() ) | |
eafb234b | 620 | { |
709e97a0 | 621 | if( anOwner->Type() == MeshVS_ET_Node ) |
eafb234b | 622 | { |
7fd59977 | 623 | aHiddenNodes->ChangeMap().Remove( anOwner->ID() ); |
eafb234b | 624 | } |
7fd59977 | 625 | else |
eafb234b | 626 | { |
7fd59977 | 627 | aHiddenElements->ChangeMap().Remove( anOwner->ID() ); |
eafb234b | 628 | } |
629 | } | |
7fd59977 | 630 | } |
631 | aMesh->SetHiddenNodes( aHiddenNodes ); | |
632 | aMesh->SetHiddenElems( aHiddenElements ); | |
633 | aContext->Redisplay( aMesh ); | |
634 | } | |
635 | ||
636 | return 0; | |
637 | } | |
638 | //----------------------------------------------------------------------------- | |
639 | static Standard_Integer showall | |
640 | (Draw_Interpretor& di, Standard_Integer argc, const char** argv ) | |
641 | { | |
709e97a0 | 642 | if (argc<2) |
7fd59977 | 643 | { |
709e97a0 | 644 | di << "Wrong number of parameters" << "\n"; |
645 | di << "Use: " << argv[0] << " <mesh name>" << "\n"; | |
7fd59977 | 646 | return 0; |
647 | } | |
648 | ||
649 | Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext(); | |
650 | Handle( MeshVS_Mesh ) aMesh = getMesh( argv[1], di ); | |
651 | if( aMesh.IsNull() ) | |
652 | { | |
653 | di << "The mesh is invalid" << "\n"; | |
654 | return 0; | |
655 | } | |
656 | ||
657 | if( aContext.IsNull() ) | |
658 | di << "The context is null" << "\n"; | |
659 | else | |
660 | { | |
709e97a0 | 661 | aMesh->SetHiddenNodes( new TColStd_HPackedMapOfInteger() ); |
662 | aMesh->SetHiddenElems( new TColStd_HPackedMapOfInteger() ); | |
7fd59977 | 663 | aContext->Redisplay( aMesh ); |
664 | } | |
665 | ||
666 | return 0; | |
667 | } | |
7fd59977 | 668 | |
7fd59977 | 669 | //----------------------------------------------------------------------------- |
9c6afe19 RK |
670 | static Standard_Integer meshcolors( Draw_Interpretor& di, |
671 | Standard_Integer argc, | |
7fd59977 | 672 | const char** argv ) |
673 | { | |
674 | try | |
675 | { | |
676 | OCC_CATCH_SIGNALS | |
709e97a0 | 677 | if ( argc < 4 ) |
7fd59977 | 678 | { |
709e97a0 | 679 | di << "Wrong number of parameters" << "\n"; |
680 | di << "Use : meshcolors <mesh name> <mode> <isreflect>" << "\n"; | |
3ba3388b | 681 | di << "mode : {elem1|elem2|nodal|nodaltex|none}"<< "\n"; |
7fd59977 | 682 | di << " elem1 - different color for each element" << "\n"; |
683 | di << " elem2 - one color for one side"<<"\n"; | |
3ba3388b A |
684 | di << " nodal - different color for each node"<< "\n"; |
685 | di << " nodaltex - different color for each node with texture interpolation"<< "\n"; | |
9c6afe19 | 686 | di << " none - clear"<< "\n"; |
7fd59977 | 687 | di << "isreflect : {0|1} "<< "\n"; |
9c6afe19 | 688 | |
7fd59977 | 689 | return 0; |
690 | } | |
691 | ||
692 | Handle( MeshVS_Mesh ) aMesh = getMesh( argv[ 1 ], di ); | |
693 | ||
694 | if ( aMesh.IsNull() ) | |
695 | { | |
696 | di << "Mesh not found" << "\n"; | |
697 | return 0; | |
698 | } | |
699 | Handle(AIS_InteractiveContext) anIC = ViewerTest::GetAISContext(); | |
700 | if ( anIC.IsNull() ) | |
701 | { | |
702 | di << "The context is null" << "\n"; | |
703 | return 0; | |
704 | } | |
705 | if( !aMesh.IsNull() ) | |
706 | { | |
707 | TCollection_AsciiString aMode = TCollection_AsciiString (argv[2]); | |
708 | Quantity_Color aColor1( (Quantity_NameOfColor)( Quantity_NOC_BLUE1 ) ); | |
709 | Quantity_Color aColor2( (Quantity_NameOfColor)( Quantity_NOC_RED1 ) ); | |
3ba3388b | 710 | if( aMode.IsEqual("elem1") || aMode.IsEqual("elem2") || aMode.IsEqual("nodal") || aMode.IsEqual("nodaltex") || aMode.IsEqual("none") ) |
7fd59977 | 711 | { |
712 | Handle(MeshVS_PrsBuilder) aTempBuilder; | |
709e97a0 | 713 | Standard_Integer aReflection = Draw::Atoi(argv[3]); |
7fd59977 | 714 | |
709e97a0 | 715 | for (Standard_Integer aCount = 0 ; aCount < aMesh->GetBuildersCount(); aCount++ ){ |
7fd59977 | 716 | aTempBuilder = Handle(MeshVS_PrsBuilder)::DownCast(aMesh->FindBuilder("MeshVS_ElementalColorPrsBuilder")); |
717 | if( !aTempBuilder.IsNull()) | |
718 | aMesh->RemoveBuilderById(aTempBuilder->GetId()); | |
719 | ||
720 | aTempBuilder = Handle(MeshVS_PrsBuilder)::DownCast(aMesh->FindBuilder("MeshVS_NodalColorPrsBuilder")); | |
721 | if( !aTempBuilder.IsNull()) | |
722 | aMesh->RemoveBuilderById(aTempBuilder->GetId()); | |
723 | } | |
724 | ||
725 | if( aMode.IsEqual("elem1") || aMode.IsEqual("elem2") ) | |
726 | { | |
9c6afe19 | 727 | Handle(MeshVS_ElementalColorPrsBuilder) aBuilder = new MeshVS_ElementalColorPrsBuilder( |
7fd59977 | 728 | aMesh, MeshVS_DMF_ElementalColorDataPrs | MeshVS_DMF_OCCMask ); |
729 | // Color | |
730 | const TColStd_PackedMapOfInteger& anAllElements = aMesh->GetDataSource()->GetAllElements(); | |
731 | TColStd_MapIteratorOfPackedMapOfInteger anIter( anAllElements ); | |
732 | ||
733 | if( aMode.IsEqual("elem1") ) | |
734 | for ( ; anIter.More(); anIter.Next() ) | |
735 | { | |
736 | Quantity_Color aColor( (Quantity_NameOfColor)( anIter.Key() % Quantity_NOC_WHITE ) ); | |
737 | aBuilder->SetColor1( anIter.Key(), aColor ); | |
738 | } | |
739 | else | |
740 | for ( ; anIter.More(); anIter.Next() ) | |
741 | aBuilder->SetColor2( anIter.Key(), aColor1, aColor2 ); | |
742 | ||
743 | aMesh->AddBuilder( aBuilder, Standard_True ); | |
744 | } | |
745 | ||
9c6afe19 | 746 | |
7fd59977 | 747 | if( aMode.IsEqual("nodal") ) |
748 | { | |
9c6afe19 | 749 | Handle(MeshVS_NodalColorPrsBuilder) aBuilder = new MeshVS_NodalColorPrsBuilder( |
7fd59977 | 750 | aMesh, MeshVS_DMF_NodalColorDataPrs | MeshVS_DMF_OCCMask ); |
751 | aMesh->AddBuilder( aBuilder, Standard_True ); | |
752 | ||
753 | // Color | |
754 | const TColStd_PackedMapOfInteger& anAllNodes = | |
755 | aMesh->GetDataSource()->GetAllNodes(); | |
756 | TColStd_MapIteratorOfPackedMapOfInteger anIter( anAllNodes ); | |
757 | for ( ; anIter.More(); anIter.Next() ) | |
758 | { | |
9c6afe19 | 759 | Quantity_Color aColor( (Quantity_NameOfColor)( |
7fd59977 | 760 | anIter.Key() % Quantity_NOC_WHITE ) ); |
761 | aBuilder->SetColor( anIter.Key(), aColor ); | |
762 | } | |
763 | aMesh->AddBuilder( aBuilder, Standard_True ); | |
764 | } | |
765 | ||
3ba3388b A |
766 | if(aMode.IsEqual("nodaltex")) |
767 | { | |
768 | // assign nodal builder to the mesh | |
9c6afe19 | 769 | Handle(MeshVS_NodalColorPrsBuilder) aBuilder = new MeshVS_NodalColorPrsBuilder( |
3ba3388b A |
770 | aMesh, MeshVS_DMF_NodalColorDataPrs | MeshVS_DMF_OCCMask); |
771 | aMesh->AddBuilder(aBuilder, Standard_True); | |
772 | aBuilder->UseTexture(Standard_True); | |
773 | ||
774 | // prepare color map for texture | |
775 | Aspect_SequenceOfColor aColorMap; | |
776 | aColorMap.Append((Quantity_NameOfColor) Quantity_NOC_RED); | |
777 | aColorMap.Append((Quantity_NameOfColor) Quantity_NOC_YELLOW); | |
778 | aColorMap.Append((Quantity_NameOfColor) Quantity_NOC_BLUE1); | |
779 | ||
780 | // prepare scale map for mesh - it will be assigned to mesh as texture coordinates | |
781 | // make mesh color interpolated from minimum X coord to maximum X coord | |
782 | Handle(MeshVS_DataSource) aDataSource = aMesh->GetDataSource(); | |
783 | Standard_Real aMinX, aMinY, aMinZ, aMaxX, aMaxY, aMaxZ; | |
784 | ||
785 | // get bounding box for calculations | |
786 | aDataSource->GetBoundingBox().Get(aMinX, aMinY, aMinZ, aMaxX, aMaxY, aMaxZ); | |
787 | Standard_Real aDelta = aMaxX - aMinX; | |
788 | ||
789 | // assign color scale map values (0..1) to nodes | |
790 | TColStd_DataMapOfIntegerReal aScaleMap; | |
791 | TColStd_Array1OfReal aCoords(1, 3); | |
792 | Standard_Integer aNbNodes; | |
793 | MeshVS_EntityType aType; | |
794 | ||
795 | // iterate nodes | |
796 | const TColStd_PackedMapOfInteger& anAllNodes = | |
797 | aMesh->GetDataSource()->GetAllNodes(); | |
798 | TColStd_MapIteratorOfPackedMapOfInteger anIter(anAllNodes); | |
799 | for (; anIter.More(); anIter.Next()) | |
800 | { | |
801 | //get node coordinates to aCoord variable | |
802 | aDataSource->GetGeom(anIter.Key(), Standard_False, aCoords, aNbNodes, aType); | |
803 | ||
804 | Standard_Real aScaleValue; | |
805 | try { | |
806 | OCC_CATCH_SIGNALS | |
807 | aScaleValue = (aCoords.Value(1) - (Standard_Real) aMinX) / aDelta; | |
808 | } catch(Standard_Failure) { | |
809 | aScaleValue = 0; | |
810 | } | |
811 | ||
9c6afe19 | 812 | aScaleMap.Bind(anIter.Key(), aScaleValue); |
3ba3388b A |
813 | } |
814 | ||
815 | //set color map for builder and a color for invalid scale value | |
816 | aBuilder->SetColorMap(aColorMap); | |
817 | aBuilder->SetInvalidColor(Quantity_NOC_BLACK); | |
818 | aBuilder->SetTextureCoords(aScaleMap); | |
819 | aMesh->AddBuilder(aBuilder, Standard_True); | |
9c6afe19 | 820 | |
3ba3388b A |
821 | //set viewer to display texures |
822 | const Handle(V3d_Viewer)& aViewer = anIC->CurrentViewer(); | |
823 | for (aViewer->InitActiveViews(); aViewer->MoreActiveViews(); aViewer->NextActiveViews()) | |
824 | aViewer->ActiveView()->SetSurfaceDetail(V3d_TEX_ALL); | |
825 | } | |
826 | ||
709e97a0 | 827 | aMesh->GetDrawer()->SetBoolean ( MeshVS_DA_ColorReflection, Standard_Boolean(aReflection) ); |
7fd59977 | 828 | |
829 | anIC->Redisplay( aMesh ); | |
830 | } | |
831 | else | |
9c6afe19 | 832 | { |
7fd59977 | 833 | di << "Wrong mode name" << "\n"; |
834 | return 0; | |
835 | } | |
836 | } | |
837 | } | |
838 | catch ( Standard_Failure ) | |
839 | { | |
840 | di << "Error" << "\n"; | |
841 | } | |
842 | ||
843 | return 0; | |
844 | } | |
845 | //----------------------------------------------------------------------------- | |
709e97a0 | 846 | static Standard_Integer meshvectors( Draw_Interpretor& di, |
847 | Standard_Integer argc, | |
848 | const char** argv ) | |
849 | { | |
850 | if ( argc < 3 ) | |
851 | { | |
852 | di << "Wrong number of parameters" << "\n"; | |
853 | di << "Use : meshvectors <mesh name> < -mode {elem|nodal|none} > [-maxlen len] [-color name] [-arrowpart ratio] [-issimple {1|0}]" << "\n"; | |
854 | di << "Supported mode values:"<< "\n"; | |
855 | di << " elem - vector per element" << "\n"; | |
856 | di << " nodal - vector per node"<< "\n"; | |
857 | di << " none - clear"<< "\n"; | |
858 | ||
859 | return 0; | |
860 | } | |
861 | ||
862 | Handle( MeshVS_Mesh ) aMesh = getMesh( argv[ 1 ], di ); | |
863 | ||
864 | if ( aMesh.IsNull() ) | |
865 | { | |
866 | di << "Mesh not found" << "\n"; | |
867 | return 0; | |
868 | } | |
869 | Handle(AIS_InteractiveContext) anIC = ViewerTest::GetAISContext(); | |
870 | if ( anIC.IsNull() ) | |
871 | { | |
872 | di << "The context is null" << "\n"; | |
873 | return 0; | |
874 | } | |
875 | ||
876 | TCollection_AsciiString aParam; | |
877 | TCollection_AsciiString aMode("none"); | |
878 | Standard_Real aMaxlen(1.0); | |
879 | Quantity_Color aColor(Quantity_NOC_ORANGE); | |
880 | Standard_Real anArrowPart(0.1); | |
881 | Standard_Boolean isSimplePrs(Standard_False); | |
882 | ||
883 | for (Standard_Integer anIdx = 2; anIdx < argc; anIdx++) | |
884 | { | |
885 | if (!aParam.IsEmpty()) | |
886 | { | |
887 | if (aParam == "-mode") | |
888 | { | |
889 | aMode = argv[anIdx]; | |
890 | } | |
891 | else if (aParam == "-maxlen") | |
892 | { | |
893 | aMaxlen = Draw::Atof(argv[anIdx]); | |
894 | } | |
895 | else if (aParam == "-color") | |
896 | { | |
897 | aColor = ViewerTest::GetColorFromName(argv[anIdx]); | |
898 | } | |
899 | else if (aParam == "-arrowpart") | |
900 | { | |
901 | anArrowPart = Draw::Atof(argv[anIdx]); | |
902 | } | |
903 | else if (aParam == "-issimple") | |
904 | { | |
905 | isSimplePrs = Draw::Atoi(argv[anIdx]); | |
906 | } | |
907 | aParam.Clear(); | |
908 | } | |
909 | else if (argv[anIdx][0] == '-') | |
910 | { | |
911 | aParam = argv[anIdx]; | |
912 | } | |
913 | } | |
914 | ||
915 | if( !aMode.IsEqual("elem") && !aMode.IsEqual("nodal") && !aMode.IsEqual("none") ) | |
916 | { | |
917 | di << "Wrong mode name" << "\n"; | |
918 | return 0; | |
919 | } | |
920 | ||
921 | Handle(MeshVS_PrsBuilder) aTempBuilder; | |
922 | ||
923 | aTempBuilder = Handle(MeshVS_PrsBuilder)::DownCast(aMesh->FindBuilder("MeshVS_VectorPrsBuilder")); | |
924 | if( !aTempBuilder.IsNull()) | |
925 | aMesh->RemoveBuilderById(aTempBuilder->GetId()); | |
926 | ||
927 | if( !aMode.IsEqual("none") ) | |
928 | { | |
929 | Handle(MeshVS_VectorPrsBuilder) aBuilder = new MeshVS_VectorPrsBuilder( aMesh.operator->(), | |
930 | aMaxlen, | |
931 | aColor, | |
932 | MeshVS_DMF_VectorDataPrs, | |
933 | 0, | |
934 | -1, | |
935 | MeshVS_BP_Vector, | |
936 | isSimplePrs); | |
937 | ||
938 | Standard_Boolean anIsElement = aMode.IsEqual("elem"); | |
939 | const TColStd_PackedMapOfInteger& anAllIDs = anIsElement ? aMesh->GetDataSource()->GetAllElements() : | |
940 | aMesh->GetDataSource()->GetAllNodes(); | |
941 | ||
942 | Standard_Integer aNbNodes; | |
943 | MeshVS_EntityType aEntType; | |
944 | ||
945 | TColStd_MapIteratorOfPackedMapOfInteger anIter( anAllIDs ); | |
946 | for ( ; anIter.More(); anIter.Next() ) | |
947 | { | |
948 | TColStd_Array1OfReal aCoords(1, 3); | |
949 | if (anIsElement) | |
950 | aMesh->GetDataSource()->GetNormal(anIter.Key(), 3, aCoords.ChangeValue(1), aCoords.ChangeValue(2), aCoords.ChangeValue(3)); | |
951 | else | |
952 | aMesh->GetDataSource()->GetGeom(anIter.Key(), Standard_False, aCoords, aNbNodes, aEntType); | |
953 | ||
954 | gp_Vec aNorm = gp_Vec(aCoords.Value(1), aCoords.Value(2), aCoords.Value(3)); | |
955 | if( !aNorm.Magnitude() ) | |
956 | aNorm = gp_Vec(0,0,1); | |
957 | aBuilder->SetVector(anIsElement, anIter.Key(), aNorm.Normalized()); | |
958 | } | |
959 | ||
960 | aMesh->AddBuilder( aBuilder, Standard_False ); | |
961 | aMesh->GetDrawer()->SetDouble ( MeshVS_DA_VectorArrowPart, anArrowPart ); | |
962 | } | |
963 | ||
964 | anIC->Redisplay( aMesh ); | |
965 | ||
966 | return 0; | |
967 | } | |
968 | //----------------------------------------------------------------------------- | |
969 | ||
970 | static Standard_Integer meshtext( Draw_Interpretor& di, | |
971 | Standard_Integer argc, | |
972 | const char** argv ) | |
973 | { | |
974 | if ( argc < 2 ) | |
975 | { | |
976 | di << "Wrong number of parameters" << "\n"; | |
977 | di << "Use : meshtext <mesh name>" << "\n"; | |
978 | return 0; | |
979 | } | |
980 | ||
981 | Handle( MeshVS_Mesh ) aMesh = getMesh( argv[ 1 ], di ); | |
982 | ||
983 | if ( aMesh.IsNull() ) | |
984 | { | |
985 | di << "Mesh not found" << "\n"; | |
986 | return 0; | |
987 | } | |
988 | ||
989 | Handle(AIS_InteractiveContext) anIC = ViewerTest::GetAISContext(); | |
990 | if ( anIC.IsNull() ) | |
991 | { | |
992 | di << "The context is null" << "\n"; | |
993 | return 0; | |
994 | } | |
995 | ||
996 | // Prepare triangle labels | |
997 | MeshVS_DataMapOfIntegerAsciiString aLabels; | |
998 | Standard_Integer aLen = aMesh->GetDataSource()->GetAllElements().Extent(); | |
999 | for ( Standard_Integer anIndex = 1; anIndex <= aLen; anIndex++ ){ | |
1000 | aLabels.Bind( anIndex, TCollection_AsciiString( anIndex ) ); | |
1001 | } | |
1002 | ||
1003 | Handle(MeshVS_TextPrsBuilder) aTextBuilder = new MeshVS_TextPrsBuilder( aMesh.operator->(), 20., Quantity_NOC_YELLOW ); | |
1004 | aTextBuilder->SetTexts( Standard_True, aLabels ); | |
1005 | aMesh->AddBuilder( aTextBuilder ); | |
1006 | ||
1007 | return 0; | |
1008 | } | |
1009 | ||
1010 | static Standard_Integer meshdeform( Draw_Interpretor& di, | |
1011 | Standard_Integer argc, | |
1012 | const char** argv ) | |
1013 | { | |
1014 | if ( argc < 3 ) | |
1015 | { | |
1016 | di << "Wrong number of parameters" << "\n"; | |
1017 | di << "Use : meshdeform <mesh name> < -mode {on|off} > [-scale scalefactor]" << "\n"; | |
1018 | return 0; | |
1019 | } | |
1020 | ||
1021 | Handle( MeshVS_Mesh ) aMesh = getMesh( argv[ 1 ], di ); | |
1022 | ||
1023 | if ( aMesh.IsNull() ) | |
1024 | { | |
1025 | di << "Mesh not found" << "\n"; | |
1026 | return 0; | |
1027 | } | |
1028 | Handle(AIS_InteractiveContext) anIC = ViewerTest::GetAISContext(); | |
1029 | if ( anIC.IsNull() ) | |
1030 | { | |
1031 | di << "The context is null" << "\n"; | |
1032 | return 0; | |
1033 | } | |
1034 | ||
1035 | TCollection_AsciiString aParam; | |
1036 | TCollection_AsciiString aMode("off"); | |
1037 | Standard_Real aScale(1.0); | |
1038 | ||
1039 | for (Standard_Integer anIdx = 2; anIdx < argc; anIdx++) | |
1040 | { | |
1041 | if (!aParam.IsEmpty()) | |
1042 | { | |
1043 | if (aParam == "-mode") | |
1044 | { | |
1045 | aMode = argv[anIdx]; | |
1046 | } | |
1047 | else if (aParam == "-scale") | |
1048 | { | |
1049 | aScale = Draw::Atof(argv[anIdx]); | |
1050 | } | |
1051 | aParam.Clear(); | |
1052 | } | |
1053 | else if (argv[anIdx][0] == '-') | |
1054 | { | |
1055 | aParam = argv[anIdx]; | |
1056 | } | |
1057 | } | |
1058 | ||
1059 | if(!aMode.IsEqual("on") && !aMode.IsEqual("off")) | |
1060 | { | |
1061 | di << "Wrong mode name" << "\n"; | |
1062 | return 0; | |
1063 | } | |
1064 | ||
1065 | Handle ( MeshVS_DeformedDataSource ) aDefDS = | |
1066 | new MeshVS_DeformedDataSource( aMesh->GetDataSource() , aScale ); | |
1067 | ||
1068 | const TColStd_PackedMapOfInteger& anAllIDs = aMesh->GetDataSource()->GetAllNodes(); | |
1069 | ||
1070 | Standard_Integer aNbNodes; | |
1071 | MeshVS_EntityType aEntType; | |
1072 | ||
1073 | TColStd_MapIteratorOfPackedMapOfInteger anIter( anAllIDs ); | |
1074 | for ( ; anIter.More(); anIter.Next() ) | |
1075 | { | |
1076 | TColStd_Array1OfReal aCoords(1, 3); | |
1077 | aMesh->GetDataSource()->GetGeom(anIter.Key(), Standard_False, aCoords, aNbNodes, aEntType); | |
1078 | ||
1079 | gp_Vec aNorm = gp_Vec(aCoords.Value(1), aCoords.Value(2), aCoords.Value(3)); | |
1080 | if( !aNorm.Magnitude() ) | |
1081 | aNorm = gp_Vec(0,0,1); | |
1082 | aDefDS->SetVector(anIter.Key(), aNorm.Normalized()); | |
1083 | } | |
1084 | ||
1085 | aMesh->SetDataSource(aDefDS); | |
1086 | ||
1087 | anIC->Redisplay( aMesh ); | |
1088 | ||
1089 | Handle( V3d_View ) aView = ViewerTest::CurrentView(); | |
1090 | if ( !aView.IsNull() ) | |
1091 | aView->FitAll(); | |
1092 | ||
1093 | return 0; | |
1094 | } | |
7fd59977 | 1095 | |
9c6afe19 RK |
1096 | static Standard_Integer mesh_edge_width( Draw_Interpretor& di, |
1097 | Standard_Integer argc, | |
7fd59977 | 1098 | const char** argv ) |
1099 | { | |
1100 | try | |
1101 | { | |
1102 | OCC_CATCH_SIGNALS | |
1103 | if ( argc < 3 ) | |
1104 | { | |
709e97a0 | 1105 | di << "Wrong number of parameters" << "\n"; |
1106 | di << "Use : mesh_edge_width <mesh name> <width>" << "\n"; | |
7fd59977 | 1107 | return 0; |
1108 | } | |
1109 | ||
1110 | Handle(MeshVS_Mesh) aMesh = getMesh( argv[ 1 ], di ); | |
1111 | if ( aMesh.IsNull() ) | |
1112 | { | |
1113 | di << "Mesh not found" << "\n"; | |
1114 | return 0; | |
1115 | } | |
1116 | ||
1117 | const char* aWidthStr = argv[ 2 ]; | |
91322f44 | 1118 | if ( aWidthStr == 0 || Draw::Atof( aWidthStr ) <= 0 ) |
7fd59977 | 1119 | { |
1120 | di << "Width must be real value more than zero" << "\n"; | |
1121 | return 0; | |
1122 | } | |
1123 | ||
91322f44 | 1124 | double aWidth = Draw::Atof( aWidthStr ); |
7fd59977 | 1125 | |
1126 | Handle(AIS_InteractiveContext) anIC = ViewerTest::GetAISContext(); | |
1127 | if ( anIC.IsNull() ) | |
1128 | { | |
1129 | di << "The context is null" << "\n"; | |
1130 | return 0; | |
1131 | } | |
1132 | ||
1133 | Handle(MeshVS_Drawer) aDrawer = aMesh->GetDrawer(); | |
1134 | if ( aDrawer.IsNull() ) | |
1135 | { | |
1136 | di << "The drawer is null" << "\n"; | |
1137 | return 0; | |
1138 | } | |
1139 | ||
1140 | aDrawer->SetDouble( MeshVS_DA_EdgeWidth, aWidth ); | |
1141 | anIC->Redisplay( aMesh ); | |
1142 | } | |
1143 | catch ( Standard_Failure ) | |
1144 | { | |
1145 | di << "Error" << "\n"; | |
1146 | } | |
1147 | ||
1148 | return 0; | |
1149 | } | |
1150 | ||
7da5f7b1 | 1151 | //======================================================================= |
1152 | //function : tovrml | |
1153 | //purpose : | |
1154 | //======================================================================= | |
1155 | ||
709e97a0 | 1156 | static Standard_Integer tovrml(Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
7da5f7b1 | 1157 | { |
709e97a0 | 1158 | if ( argc < 3 ) |
1159 | { | |
1160 | di << "Wrong number of parameters" << "\n"; | |
1161 | di << "Use : tovrml <shape name> <file name>" << "\n"; | |
1162 | return 0; | |
1163 | } | |
1164 | XSDRAWSTLVRML_ToVRML aVrml; | |
1165 | TopoDS_Shape aShape = DBRep::Get (argv[1]); | |
1166 | const char* aFilename = argv[2]; | |
1167 | if (!aVrml.Write (aShape,aFilename)) return 1; | |
7da5f7b1 | 1168 | return 0; |
1169 | } | |
1170 | ||
7fd59977 | 1171 | //----------------------------------------------------------------------------- |
1172 | ||
fcc61cc4 | 1173 | static Standard_Integer meshinfo(Draw_Interpretor& di, |
1174 | Standard_Integer argc, | |
1175 | const char** argv) | |
1176 | { | |
1177 | if ( argc != 2 ) | |
1178 | { | |
1179 | di << "Wrong number of parameters. Use : meshinfo mesh" << "\n"; | |
1180 | return 0; | |
1181 | } | |
1182 | ||
1183 | Handle(MeshVS_Mesh) aMesh = getMesh(argv[ 1 ], di); | |
1184 | if ( aMesh.IsNull() ) | |
1185 | { | |
1186 | di << "Mesh not found" << "\n"; | |
1187 | return 0; | |
1188 | } | |
1189 | ||
1190 | Handle(XSDRAWSTLVRML_DataSource) stlMeshSource = Handle(XSDRAWSTLVRML_DataSource)::DownCast(aMesh->GetDataSource()); | |
1191 | if (!stlMeshSource.IsNull()) | |
1192 | { | |
1193 | const TColStd_PackedMapOfInteger& nodes = stlMeshSource->GetAllNodes(); | |
1194 | const TColStd_PackedMapOfInteger& tris = stlMeshSource->GetAllElements(); | |
1195 | ||
1196 | di << "Nb nodes = " << nodes.Extent() << "\n"; | |
1197 | di << "Nb triangles = " << tris.Extent() << "\n"; | |
1198 | } | |
1199 | ||
1200 | return 0; | |
1201 | } | |
1202 | ||
1203 | //----------------------------------------------------------------------------- | |
1204 | ||
7fd59977 | 1205 | void XSDRAWSTLVRML::InitCommands (Draw_Interpretor& theCommands) |
1206 | { | |
1207 | const char* g = "XSTEP-STL/VRML"; // Step transfer file commands | |
1208 | //XSDRAW::LoadDraw(theCommands); | |
1209 | ||
f5fa6b33 | 1210 | theCommands.Add ("writevrml", "shape file [version VRML#1.0/VRML#2.0 (1/2): 2 by default] [representation shaded/wireframe/both (0/1/2): 1 by default]",__FILE__,writevrml,g); |
7da5f7b1 | 1211 | theCommands.Add ("tovrml", "shape file",__FILE__, tovrml, g); |
416d4426 | 1212 | theCommands.Add ("writestl", "shape file [ascii/binary (0/1) : 1 by default] [InParallel (0/1) : 0 by default]",__FILE__,writestl,g); |
7fd59977 | 1213 | theCommands.Add ("readstl", "shape file",__FILE__,readstl,g); |
1214 | theCommands.Add ("loadvrml" , "shape file",__FILE__,loadvrml,g); | |
7fd59977 | 1215 | |
709e97a0 | 1216 | theCommands.Add ("meshfromstl", "creates MeshVS_Mesh from STL file", __FILE__, createmesh, g ); |
1217 | theCommands.Add ("mesh3delem", "creates 3d element mesh to test", __FILE__, create3d, g ); | |
1218 | theCommands.Add ("meshshadcolor", "change MeshVS_Mesh shading color", __FILE__, meshcolor, g ); | |
1219 | theCommands.Add ("meshlinkcolor", "change MeshVS_Mesh line color", __FILE__, linecolor, g ); | |
1220 | theCommands.Add ("meshmat", "change MeshVS_Mesh material and transparency", __FILE__, meshmat, g ); | |
1221 | theCommands.Add ("meshshrcoef", "change MeshVS_Mesh shrink coeff", __FILE__, shrink, g ); | |
1222 | theCommands.Add ("meshshow", "display MeshVS_Mesh object", __FILE__, mdisplay, g ); | |
1223 | theCommands.Add ("meshhide", "erase MeshVS_Mesh object", __FILE__, merase, g ); | |
1224 | theCommands.Add ("meshhidesel", "hide selected entities", __FILE__, hidesel, g ); | |
1225 | theCommands.Add ("meshshowsel", "show only selected entities", __FILE__, showonly, g ); | |
1226 | theCommands.Add ("meshshowall", "show all entities", __FILE__, showall, g ); | |
1227 | theCommands.Add ("meshcolors", "display color presentation", __FILE__, meshcolors, g ); | |
1228 | theCommands.Add ("meshvectors", "display sample vectors", __FILE__, meshvectors, g ); | |
1229 | theCommands.Add ("meshtext", "display text labels", __FILE__, meshtext, g ); | |
1230 | theCommands.Add ("meshdeform", "display deformed mesh", __FILE__, meshdeform, g ); | |
1231 | theCommands.Add ("mesh_edge_width", "set width of edges", __FILE__, mesh_edge_width, g ); | |
fcc61cc4 | 1232 | theCommands.Add ("meshinfo", "displays the number of nodes and triangles", __FILE__, meshinfo, g ); |
7fd59977 | 1233 | } |
1234 | ||
1235 | //============================================================================== | |
1236 | // XSDRAWSTLVRML::Factory | |
1237 | //============================================================================== | |
1238 | void XSDRAWSTLVRML::Factory(Draw_Interpretor& theDI) | |
1239 | { | |
1240 | XSDRAWIGES::InitSelect(); | |
1241 | XSDRAWIGES::InitToBRep(theDI); | |
1242 | XSDRAWIGES::InitFromBRep(theDI); | |
1243 | XSDRAWSTEP::InitCommands(theDI); | |
1244 | XSDRAWSTLVRML::InitCommands(theDI); | |
7fd59977 | 1245 | XSDRAW::LoadDraw(theDI); |
0797d9d3 | 1246 | #ifdef OCCT_DEBUG |
7fd59977 | 1247 | theDI << "Draw Plugin : All TKXSDRAW commands are loaded" << "\n"; |
1248 | #endif | |
1249 | } | |
1250 | ||
1251 | // Declare entry point PLUGINFACTORY | |
1252 | DPLUGIN(XSDRAWSTLVRML) | |
1253 |