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