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