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