1 // Created on: 2000-05-30
2 // Created by: Sergey MOZOKHIN
3 // Copyright (c) 2000-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
17 #include <AIS_InteractiveContext.hxx>
18 #include <Aspect_TypeOfMarker.hxx>
19 #include <Bnd_Box.hxx>
20 #include <BRep_Builder.hxx>
22 #include <DDocStd.hxx>
23 #include <DDocStd_DrawDocument.hxx>
25 #include <Draw_Interpretor.hxx>
26 #include <Draw_PluginMacro.hxx>
27 #include <Draw_ProgressIndicator.hxx>
28 #include <Graphic3d_MaterialAspect.hxx>
29 #include <MeshVS_DataMapOfIntegerAsciiString.hxx>
30 #include <MeshVS_DeformedDataSource.hxx>
31 #include <MeshVS_Drawer.hxx>
32 #include <MeshVS_DrawerAttribute.hxx>
33 #include <MeshVS_ElementalColorPrsBuilder.hxx>
34 #include <MeshVS_Mesh.hxx>
35 #include <MeshVS_MeshEntityOwner.hxx>
36 #include <MeshVS_MeshPrsBuilder.hxx>
37 #include <MeshVS_NodalColorPrsBuilder.hxx>
38 #include <MeshVS_PrsBuilder.hxx>
39 #include <MeshVS_TextPrsBuilder.hxx>
40 #include <MeshVS_VectorPrsBuilder.hxx>
41 #include <OSD_Path.hxx>
42 #include <Quantity_Color.hxx>
43 #include <Quantity_HArray1OfColor.hxx>
44 #include <Quantity_NameOfColor.hxx>
45 #include <RWGltf_CafReader.hxx>
48 #include <RWObj_CafReader.hxx>
49 #include <SelectMgr_SelectionManager.hxx>
50 #include <Standard_ErrorHandler.hxx>
51 #include <StdSelect_ViewerSelector3d.hxx>
53 #include <StlAPI_Writer.hxx>
54 #include <TColgp_SequenceOfXYZ.hxx>
55 #include <TCollection_AsciiString.hxx>
56 #include <TColStd_Array1OfReal.hxx>
57 #include <TColStd_HPackedMapOfInteger.hxx>
58 #include <TColStd_MapIteratorOfPackedMapOfInteger.hxx>
59 #include <TDataStd_Name.hxx>
60 #include <TDocStd_Application.hxx>
61 #include <TopoDS_Face.hxx>
62 #include <TopoDS_Shape.hxx>
63 #include <UnitsAPI.hxx>
64 #include <UnitsMethods.hxx>
65 #include <V3d_View.hxx>
66 #include <ViewerTest.hxx>
67 #include <VrmlAPI.hxx>
68 #include <VrmlAPI_Writer.hxx>
69 #include <VrmlData_DataMapOfShapeAppearance.hxx>
70 #include <VrmlData_Scene.hxx>
71 #include <VrmlData_ShapeConvert.hxx>
73 #include <XSDRAWIGES.hxx>
74 #include <XSDRAWSTEP.hxx>
75 #include <XSDRAWSTLVRML.hxx>
76 #include <XSDRAWSTLVRML_DataSource.hxx>
77 #include <XSDRAWSTLVRML_DataSource3D.hxx>
78 #include <XSDRAWSTLVRML_DrawableMesh.hxx>
84 extern Standard_Boolean VDisplayAISObject (const TCollection_AsciiString& theName,
85 const Handle(AIS_InteractiveObject)& theAISObj,
86 Standard_Boolean theReplaceIfExists = Standard_True);
88 //=============================================================================
90 //purpose : Reads glTF file
91 //=============================================================================
92 static Standard_Integer ReadGltf (Draw_Interpretor& theDI,
93 Standard_Integer theNbArgs,
94 const char** theArgVec)
96 TCollection_AsciiString aDestName, aFilePath;
97 Standard_Boolean toUseExistingDoc = Standard_False;
98 Standard_Real aSystemUnitFactor = UnitsMethods::GetCasCadeLengthUnit() * 0.001;
99 Standard_Boolean toListExternalFiles = Standard_False;
100 Standard_Boolean isParallel = Standard_False;
101 Standard_Boolean isNoDoc = (TCollection_AsciiString(theArgVec[0]) == "readgltf");
102 for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
104 TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
105 anArgCase.LowerCase();
107 && (anArgCase == "-nocreate"
108 || anArgCase == "-nocreatedoc"))
110 toUseExistingDoc = Standard_True;
111 if (anArgIter + 1 < theNbArgs
112 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toUseExistingDoc))
117 else if (anArgCase == "-parallel")
119 isParallel = Standard_True;
120 if (anArgIter + 1 < theNbArgs
121 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], isParallel))
126 else if (anArgCase == "-listexternalfiles"
127 || anArgCase == "-listexternals"
128 || anArgCase == "-listexternal"
129 || anArgCase == "-external"
130 || anArgCase == "-externalfiles")
132 toListExternalFiles = Standard_True;
134 else if (aDestName.IsEmpty())
136 aDestName = theArgVec[anArgIter];
138 else if (aFilePath.IsEmpty())
140 aFilePath = theArgVec[anArgIter];
144 std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
148 if (aFilePath.IsEmpty())
150 std::cout << "Syntax error: wrong number of arguments\n";
154 Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator (theDI, 1);
155 Handle(TDocStd_Document) aDoc;
156 if (!toListExternalFiles
159 Handle(TDocStd_Application) anApp = DDocStd::GetApplication();
160 Standard_CString aNameVar = aDestName.ToCString();
161 DDocStd::GetDocument (aNameVar, aDoc, Standard_False);
164 if (toUseExistingDoc)
166 std::cout << "Error: document with name " << aDestName << " does not exist\n";
169 anApp->NewDocument (TCollection_ExtendedString ("BinXCAF"), aDoc);
171 else if (!toUseExistingDoc)
173 std::cout << "Error: document with name " << aDestName << " already exists\n";
178 RWGltf_CafReader aReader;
179 aReader.SetSystemLengthUnit (aSystemUnitFactor);
180 aReader.SetSystemCoordinateSystem (RWMesh_CoordinateSystem_Zup);
181 aReader.SetDocument (aDoc);
182 aReader.SetParallel (isParallel);
183 if (toListExternalFiles)
185 aReader.ProbeHeader (aFilePath);
186 for (NCollection_IndexedMap<TCollection_AsciiString>::Iterator aFileIter (aReader.ExternalFiles()); aFileIter.More(); aFileIter.Next())
188 theDI << "\"" << aFileIter.Value() << "\" ";
193 aReader.Perform (aFilePath, aProgress);
196 DBRep::Set (aDestName.ToCString(), aReader.SingleShape());
200 Handle(DDocStd_DrawDocument) aDrawDoc = new DDocStd_DrawDocument (aDoc);
201 TDataStd_Name::Set (aDoc->GetData()->Root(), aDestName.ToCString());
202 Draw::Set (aDestName.ToCString(), aDrawDoc);
208 static Standard_Integer writestl
209 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
211 if (argc < 3 || argc > 4) {
212 di << "Use: " << argv[0]
213 << " shape file [ascii/binary (0/1) : 1 by default]\n";
215 TopoDS_Shape aShape = DBRep::Get(argv[1]);
216 Standard_Boolean isASCIIMode = Standard_False;
218 isASCIIMode = (Draw::Atoi(argv[3]) == 0);
220 StlAPI_Writer aWriter;
221 aWriter.ASCIIMode() = isASCIIMode;
222 Standard_Boolean isOK = aWriter.Write (aShape, argv[2]);
224 di << "** Error **: Mesh writing has been failed.\n";
229 //=============================================================================
231 //purpose : Reads stl file
232 //=============================================================================
233 static Standard_Integer readstl(Draw_Interpretor& theDI,
234 Standard_Integer theArgc,
235 const char** theArgv)
237 TCollection_AsciiString aShapeName, aFilePath;
238 bool toCreateCompOfTris = false;
239 for (Standard_Integer anArgIter = 1; anArgIter < theArgc; ++anArgIter)
241 TCollection_AsciiString anArg (theArgv[anArgIter]);
243 if (aShapeName.IsEmpty())
245 aShapeName = theArgv[anArgIter];
247 else if (aFilePath.IsEmpty())
249 aFilePath = theArgv[anArgIter];
251 else if (anArg == "-brep")
253 toCreateCompOfTris = true;
254 if (anArgIter + 1 < theArgc
255 && ViewerTest::ParseOnOff (theArgv[anArgIter + 1], toCreateCompOfTris))
262 std::cout << "Syntax error: unknown argument '" << theArgv[anArgIter] << "'\n";
266 if (aFilePath.IsEmpty())
268 std::cout << "Syntax error: not enough arguments\n";
273 if (!toCreateCompOfTris)
275 // Read STL file to the triangulation.
276 Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator (theDI, 1);
277 Handle(Poly_Triangulation) aTriangulation = RWStl::ReadFile (aFilePath.ToCString(), aProgress);
282 aB.UpdateFace (aFace, aTriangulation);
287 Standard_DISABLE_DEPRECATION_WARNINGS
288 StlAPI::Read(aShape, aFilePath.ToCString());
289 Standard_ENABLE_DEPRECATION_WARNINGS
291 DBRep::Set (aShapeName.ToCString(), aShape);
295 //! Parse RWMesh_CoordinateSystem enumeration.
296 static Standard_Boolean parseCoordinateSystem (const char* theArg,
297 RWMesh_CoordinateSystem& theSystem)
299 TCollection_AsciiString aCSStr (theArg);
303 theSystem = RWMesh_CoordinateSystem_Zup;
305 else if (aCSStr == "yup")
307 theSystem = RWMesh_CoordinateSystem_Yup;
311 return Standard_False;
313 return Standard_True;
316 //=============================================================================
318 //purpose : Reads OBJ file
319 //=============================================================================
320 static Standard_Integer ReadObj (Draw_Interpretor& theDI,
321 Standard_Integer theNbArgs,
322 const char** theArgVec)
324 TCollection_AsciiString aDestName, aFilePath;
325 Standard_Boolean toUseExistingDoc = Standard_False;
326 Standard_Real aFileUnitFactor = -1.0;
327 RWMesh_CoordinateSystem aResultCoordSys = RWMesh_CoordinateSystem_Zup, aFileCoordSys = RWMesh_CoordinateSystem_Yup;
328 Standard_Boolean toListExternalFiles = Standard_False, isSingleFace = Standard_False, isSinglePrecision = Standard_False;
329 Standard_Boolean isNoDoc = (TCollection_AsciiString(theArgVec[0]) == "readobj");
330 for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
332 TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
333 anArgCase.LowerCase();
334 if (anArgIter + 1 < theNbArgs
335 && (anArgCase == "-unit"
336 || anArgCase == "-units"
337 || anArgCase == "-fileunit"
338 || anArgCase == "-fileunits"))
340 const TCollection_AsciiString aUnitStr (theArgVec[++anArgIter]);
341 aFileUnitFactor = UnitsAPI::AnyToSI (1.0, aUnitStr.ToCString());
342 if (aFileUnitFactor <= 0.0)
344 std::cout << "Syntax error: wrong length unit '" << aUnitStr << "'\n";
348 else if (anArgIter + 1 < theNbArgs
349 && (anArgCase == "-filecoordinatesystem"
350 || anArgCase == "-filecoordsystem"
351 || anArgCase == "-filecoordsys"))
353 if (!parseCoordinateSystem (theArgVec[++anArgIter], aFileCoordSys))
355 std::cout << "Syntax error: unknown coordinate system '" << theArgVec[anArgIter] << "'\n";
359 else if (anArgIter + 1 < theNbArgs
360 && (anArgCase == "-resultcoordinatesystem"
361 || anArgCase == "-resultcoordsystem"
362 || anArgCase == "-resultcoordsys"
363 || anArgCase == "-rescoordsys"))
365 if (!parseCoordinateSystem (theArgVec[++anArgIter], aResultCoordSys))
367 std::cout << "Syntax error: unknown coordinate system '" << theArgVec[anArgIter] << "'\n";
371 else if (anArgCase == "-singleprecision"
372 || anArgCase == "-singleprec")
374 isSinglePrecision = Standard_True;
375 if (anArgIter + 1 < theNbArgs
376 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], isSinglePrecision))
382 && (anArgCase == "-singleface"
383 || anArgCase == "-singletriangulation"))
385 isSingleFace = Standard_True;
388 && (anArgCase == "-nocreate"
389 || anArgCase == "-nocreatedoc"))
391 toUseExistingDoc = Standard_True;
392 if (anArgIter + 1 < theNbArgs
393 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toUseExistingDoc))
398 else if (anArgCase == "-listexternalfiles"
399 || anArgCase == "-listexternals"
400 || anArgCase == "-listexternal"
401 || anArgCase == "-external"
402 || anArgCase == "-externalfiles")
404 toListExternalFiles = Standard_True;
406 else if (aDestName.IsEmpty())
408 aDestName = theArgVec[anArgIter];
410 else if (aFilePath.IsEmpty())
412 aFilePath = theArgVec[anArgIter];
416 std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
420 if (aFilePath.IsEmpty())
422 std::cout << "Syntax error: wrong number of arguments\n";
426 Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator (theDI, 1);
427 Handle(TDocStd_Document) aDoc;
429 && !toListExternalFiles)
431 Handle(TDocStd_Application) anApp = DDocStd::GetApplication();
432 Standard_CString aNameVar = aDestName.ToCString();
433 DDocStd::GetDocument (aNameVar, aDoc, Standard_False);
436 if (toUseExistingDoc)
438 std::cout << "Error: document with name " << aDestName << " does not exist\n";
441 anApp->NewDocument (TCollection_ExtendedString ("BinXCAF"), aDoc);
443 else if (!toUseExistingDoc)
445 std::cout << "Error: document with name " << aDestName << " already exists\n";
450 RWObj_CafReader aReader;
451 aReader.SetSinglePrecision (isSinglePrecision);
452 aReader.SetSystemLengthUnit (UnitsMethods::GetCasCadeLengthUnit() * 0.001);
453 aReader.SetSystemCoordinateSystem (aResultCoordSys);
454 aReader.SetFileLengthUnit (aFileUnitFactor);
455 aReader.SetFileCoordinateSystem (aFileCoordSys);
456 aReader.SetDocument (aDoc);
459 RWObj_TriangulationReader aSimpleReader;
460 aSimpleReader.SetSinglePrecision (isSinglePrecision);
461 aSimpleReader.SetCreateShapes (Standard_False);
462 aSimpleReader.SetTransformation (aReader.CoordinateSystemConverter());
463 aSimpleReader.Read (aFilePath.ToCString(), aProgress);
465 Handle(Poly_Triangulation) aTriangulation = aSimpleReader.GetTriangulation();
467 BRep_Builder aBuiler;
468 aBuiler.MakeFace (aFace);
469 aBuiler.UpdateFace (aFace, aTriangulation);
470 DBRep::Set (aDestName.ToCString(), aFace);
474 if (toListExternalFiles)
476 aReader.ProbeHeader (aFilePath);
477 for (NCollection_IndexedMap<TCollection_AsciiString>::Iterator aFileIter (aReader.ExternalFiles()); aFileIter.More(); aFileIter.Next())
479 theDI << "\"" << aFileIter.Value() << "\" ";
484 aReader.Perform (aFilePath, aProgress);
487 DBRep::Set (aDestName.ToCString(), aReader.SingleShape());
491 Handle(DDocStd_DrawDocument) aDrawDoc = new DDocStd_DrawDocument (aDoc);
492 TDataStd_Name::Set (aDoc->GetData()->Root(), aDestName.ToCString());
493 Draw::Set (aDestName.ToCString(), aDrawDoc);
499 static Standard_Integer writevrml
500 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
502 if (argc < 3 || argc > 5)
504 di << "wrong number of parameters\n";
508 TopoDS_Shape aShape = DBRep::Get(argv[1]);
510 // Get the optional parameters
511 Standard_Integer aVersion = 2;
512 Standard_Integer aType = 1;
515 aVersion = Draw::Atoi(argv[3]);
517 aType = Draw::Atoi(argv[4]);
521 aVersion = Max(1, aVersion);
522 aVersion = Min(2, aVersion);
523 aType = Max(0, aType);
524 aType = Min(2, aType);
526 VrmlAPI_Writer writer;
530 case 0: writer.SetRepresentation(VrmlAPI_ShadedRepresentation); break;
531 case 1: writer.SetRepresentation(VrmlAPI_WireFrameRepresentation); break;
532 case 2: writer.SetRepresentation(VrmlAPI_BothRepresentation); break;
535 writer.Write(aShape, argv[2], aVersion);
540 //=======================================================================
541 //function : loadvrml
543 //=======================================================================
545 static Standard_Integer loadvrml
546 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
548 if (argc<3) di << "wrong number of parameters" << "\n";
550 TopoDS_Shape aShape ;
551 VrmlData_DataMapOfShapeAppearance aShapeAppMap;
553 //-----------------------------------------------------------
555 std::istream aStream (&aFic);
557 if (aFic.open(argv[2], std::ios::in)) {
559 // Get path of the VRML file.
560 OSD_Path aPath(argv[2]);
561 TCollection_AsciiString aVrmlDir(".");
562 TCollection_AsciiString aDisk = aPath.Disk();
563 TCollection_AsciiString aTrek = aPath.Trek();
564 if (!aTrek.IsEmpty())
566 if (!aDisk.IsEmpty())
570 aTrek.ChangeAll('|', '/');
574 VrmlData_Scene aScene;
575 Standard_Real anOCCUnit = UnitsMethods::GetCasCadeLengthUnit();
576 aScene.SetLinearScale(1000. / anOCCUnit);
578 aScene.SetVrmlDir (aVrmlDir);
580 const char * aStr = 0L;
581 switch (aScene.Status()) {
583 case VrmlData_StatusOK:
585 aShape = aScene.GetShape(aShapeAppMap);
588 case VrmlData_EmptyData: aStr = "EmptyData"; break;
589 case VrmlData_UnrecoverableError: aStr = "UnrecoverableError"; break;
590 case VrmlData_GeneralError: aStr = "GeneralError"; break;
591 case VrmlData_EndOfFile: aStr = "EndOfFile"; break;
592 case VrmlData_NotVrmlFile: aStr = "NotVrmlFile"; break;
593 case VrmlData_CannotOpenFile: aStr = "CannotOpenFile"; break;
594 case VrmlData_VrmlFormatError: aStr = "VrmlFormatError"; break;
595 case VrmlData_NumericInputError: aStr = "NumericInputError"; break;
596 case VrmlData_IrrelevantNumber: aStr = "IrrelevantNumber"; break;
597 case VrmlData_BooleanInputError: aStr = "BooleanInputError"; break;
598 case VrmlData_StringInputError: aStr = "StringInputError"; break;
599 case VrmlData_NodeNameUnknown: aStr = "NodeNameUnknown"; break;
600 case VrmlData_NonPositiveSize: aStr = "NonPositiveSize"; break;
601 case VrmlData_ReadUnknownNode: aStr = "ReadUnknownNode"; break;
602 case VrmlData_NonSupportedFeature: aStr = "NonSupportedFeature"; break;
603 case VrmlData_OutputStreamUndefined:aStr = "OutputStreamUndefined"; break;
604 case VrmlData_NotImplemented: aStr = "NotImplemented"; break;
609 di << " ++ VRML Error: " << aStr << " in line "
610 << aScene.GetLineError() << "\n";
613 DBRep::Set(argv[1],aShape);
617 di << "cannot open file\n";
621 //-----------------------------------------------------------
626 //-----------------------------------------------------------------------------
627 static Standard_Integer createmesh
628 (Draw_Interpretor& di, Standard_Integer argc, const char** argv )
632 di << "Wrong number of parameters\n";
633 di << "Use: " << argv[0] << " <mesh name> <stl file>\n";
637 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
638 if (aContext.IsNull())
640 di << "No active view. Please call 'vinit' first\n";
644 // Progress indicator
645 OSD_Path aFile( argv[2] );
646 Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator (di, 1);
647 Handle(Poly_Triangulation) aSTLMesh = RWStl::ReadFile (aFile, aProgress);
649 di << "Reading OK...\n";
650 Handle( XSDRAWSTLVRML_DataSource ) aDS = new XSDRAWSTLVRML_DataSource( aSTLMesh );
651 di << "Data source is created successful\n";
652 Handle( MeshVS_Mesh ) aMesh = new MeshVS_Mesh();
653 di << "MeshVS_Mesh is created successful\n";
655 aMesh->SetDataSource( aDS );
656 aMesh->AddBuilder( new MeshVS_MeshPrsBuilder( aMesh.operator->() ), Standard_True );
658 aMesh->GetDrawer()->SetColor( MeshVS_DA_EdgeColor, Quantity_NOC_YELLOW );
660 // Hide all nodes by default
661 Handle(TColStd_HPackedMapOfInteger) aNodes = new TColStd_HPackedMapOfInteger();
662 Standard_Integer aLen = aSTLMesh->Nodes().Length();
663 for ( Standard_Integer anIndex = 1; anIndex <= aLen; anIndex++ )
664 aNodes->ChangeMap().Add( anIndex );
665 aMesh->SetHiddenNodes( aNodes );
666 aMesh->SetSelectableNodes ( aNodes );
668 VDisplayAISObject(argv[1], aMesh);
669 aContext->Deactivate( aMesh );
671 Draw::Set( argv[1], new XSDRAWSTLVRML_DrawableMesh( aMesh ) );
672 Handle( V3d_View ) aView = ViewerTest::CurrentView();
673 if ( !aView.IsNull() )
678 //-----------------------------------------------------------------------------
680 static Standard_Integer create3d
681 (Draw_Interpretor& di, Standard_Integer argc, const char** argv )
685 di << "Wrong number of parameters\n";
686 di << "Use: " << argv[0] << " <mesh name>\n";
690 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
691 if (aContext.IsNull())
693 di << "No active view. Please call 'vinit' first\n";
697 Handle( XSDRAWSTLVRML_DataSource3D ) aDS = new XSDRAWSTLVRML_DataSource3D();
698 di << "Data source is created successful\n";
699 Handle( MeshVS_Mesh ) aMesh = new MeshVS_Mesh();
700 di << "MeshVS_Mesh is created successful\n";
702 aMesh->SetDataSource( aDS );
703 aMesh->AddBuilder( new MeshVS_MeshPrsBuilder( aMesh.operator->() ), Standard_True );
705 aMesh->GetDrawer()->SetColor( MeshVS_DA_EdgeColor, Quantity_NOC_YELLOW );
707 // Hide all nodes by default
708 Handle(TColStd_HPackedMapOfInteger) aNodes = new TColStd_HPackedMapOfInteger();
709 Standard_Integer aLen = aDS->GetAllNodes().Extent();
710 for ( Standard_Integer anIndex = 1; anIndex <= aLen; anIndex++ )
711 aNodes->ChangeMap().Add( anIndex );
712 aMesh->SetHiddenNodes( aNodes );
713 aMesh->SetSelectableNodes ( aNodes );
715 VDisplayAISObject(argv[1], aMesh);
716 aContext->Deactivate( aMesh );
718 Draw::Set( argv[1], new XSDRAWSTLVRML_DrawableMesh( aMesh ) );
719 Handle( V3d_View ) aView = ViewerTest::CurrentView();
720 if ( !aView.IsNull() )
726 Handle( MeshVS_Mesh ) getMesh( const char* theName, Draw_Interpretor& di)
728 Handle( XSDRAWSTLVRML_DrawableMesh ) aDrawMesh =
729 Handle( XSDRAWSTLVRML_DrawableMesh )::DownCast( Draw::Get( theName ) );
731 if( aDrawMesh.IsNull() )
733 di << "There is no such object\n";
738 Handle( MeshVS_Mesh ) aMesh = aDrawMesh->GetMesh();
741 di << "There is invalid mesh\n";
749 //-----------------------------------------------------------------------------
750 static Standard_Integer setcolor
751 (Draw_Interpretor& di, Standard_Integer argc, const char** argv, Standard_Integer theParam )
754 di << "Wrong number of parameters\n";
757 Handle( MeshVS_Mesh ) aMesh = getMesh( argv[1], di );
758 if( !aMesh.IsNull() )
760 Standard_Real aRed = Draw::Atof (argv[2]);
761 Standard_Real aGreen = Draw::Atof (argv[3]);
762 Standard_Real aBlue = Draw::Atof (argv[4]);
763 aMesh->GetDrawer()->SetColor( (MeshVS_DrawerAttribute)theParam,
764 Quantity_Color( aRed, aGreen, aBlue, Quantity_TOC_RGB ) );
766 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
768 if( aContext.IsNull() )
769 di << "The context is null\n";
771 aContext->Redisplay (aMesh, Standard_True);
776 //-----------------------------------------------------------------------------
777 static Standard_Integer meshcolor
778 (Draw_Interpretor& theInterp, Standard_Integer argc, const char** argv )
780 return setcolor( theInterp, argc, argv, MeshVS_DA_InteriorColor );
782 //-----------------------------------------------------------------------------
783 static Standard_Integer linecolor
784 (Draw_Interpretor& theInterp, Standard_Integer argc, const char** argv )
786 return setcolor( theInterp, argc, argv, MeshVS_DA_EdgeColor );
788 //-----------------------------------------------------------------------------
789 static Standard_Integer meshmat
790 (Draw_Interpretor& di, Standard_Integer argc, const char** argv )
793 di << "Wrong number of parameters\n";
796 Handle( MeshVS_Mesh ) aMesh = getMesh( argv[1], di );
797 if( !aMesh.IsNull() )
799 Standard_Integer aMaterial = Draw::Atoi (argv[2]);
801 Graphic3d_MaterialAspect aMatAsp =
802 (Graphic3d_MaterialAspect)(Graphic3d_NameOfMaterial)aMaterial;
806 Standard_Real aTransparency = Draw::Atof(argv[3]);
807 aMatAsp.SetTransparency (Standard_ShortReal (aTransparency));
809 aMesh->GetDrawer()->SetMaterial( MeshVS_DA_FrontMaterial, aMatAsp );
810 aMesh->GetDrawer()->SetMaterial( MeshVS_DA_BackMaterial, aMatAsp );
812 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
814 if( aContext.IsNull() )
815 di << "The context is null\n";
817 aContext->Redisplay (aMesh, Standard_True);
822 //-----------------------------------------------------------------------------
823 static Standard_Integer shrink
824 (Draw_Interpretor& di, Standard_Integer argc, const char** argv )
827 di << "Wrong number of parameters\n";
830 Handle( MeshVS_Mesh ) aMesh = getMesh( argv[1], di );
831 if( !aMesh.IsNull() )
833 Standard_Real aShrinkCoeff = Draw::Atof (argv[2]);
834 aMesh->GetDrawer()->SetDouble( MeshVS_DA_ShrinkCoeff, aShrinkCoeff );
836 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
838 if( aContext.IsNull() )
839 di << "The context is null\n";
841 aContext->Redisplay (aMesh, Standard_True);
847 //-----------------------------------------------------------------------------
848 static Standard_Integer closed (Draw_Interpretor& theDI, Standard_Integer theArgc, const char** theArgv)
852 theDI << "Wrong number of parameters.\n";
856 Handle(MeshVS_Mesh) aMesh = getMesh (theArgv[1], theDI);
859 Standard_Boolean aFlag = Draw::Atoi (theArgv[2]) != 0;
860 aMesh->GetDrawer()->SetBoolean (MeshVS_DA_SupressBackFaces, aFlag);
862 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
863 if (aContext.IsNull())
865 theDI << "The context is null\n";
869 aContext->Redisplay (aMesh, Standard_True);
876 //-----------------------------------------------------------------------------
878 static Standard_Integer mdisplay
879 (Draw_Interpretor& di, Standard_Integer argc, const char** argv )
882 di << "Wrong number of parameters\n";
885 Handle( MeshVS_Mesh ) aMesh = getMesh( argv[1], di );
886 if( !aMesh.IsNull() )
888 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
890 if( aContext.IsNull() )
891 di << "The context is null\n";
894 aContext->Display (aMesh, Standard_True);
900 //-----------------------------------------------------------------------------
901 static Standard_Integer merase
902 (Draw_Interpretor& di, Standard_Integer argc, const char** argv )
905 di << "Wrong number of parameters\n";
908 Handle( MeshVS_Mesh ) aMesh = getMesh( argv[1], di );
909 if( !aMesh.IsNull() )
911 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
913 if( aContext.IsNull() )
914 di << "The context is null\n";
917 aContext->Erase (aMesh, Standard_True);
921 di << "Mesh is null\n";
925 //-----------------------------------------------------------------------------
926 static Standard_Integer hidesel
927 (Draw_Interpretor& di, Standard_Integer argc, const char** argv )
931 di << "Wrong number of parameters\n";
932 di << "Use: " << argv[0] << " <mesh name>\n";
936 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
937 Handle( MeshVS_Mesh ) aMesh = getMesh( argv[1], di );
940 di << "The mesh is invalid\n";
944 if( aContext.IsNull() )
945 di << "The context is null\n";
948 Handle(TColStd_HPackedMapOfInteger) aHiddenNodes = aMesh->GetHiddenNodes();
949 if (aHiddenNodes.IsNull())
951 aHiddenNodes = new TColStd_HPackedMapOfInteger();
953 Handle(TColStd_HPackedMapOfInteger) aHiddenElements = aMesh->GetHiddenElems();
954 if (aHiddenElements.IsNull())
956 aHiddenElements = new TColStd_HPackedMapOfInteger();
958 for( aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected() )
960 Handle( MeshVS_MeshEntityOwner ) anOwner =
961 Handle( MeshVS_MeshEntityOwner )::DownCast( aContext->SelectedOwner() );
962 if( !anOwner.IsNull() )
964 if( anOwner->Type()==MeshVS_ET_Node )
966 aHiddenNodes->ChangeMap().Add( anOwner->ID() );
970 aHiddenElements->ChangeMap().Add( anOwner->ID() );
974 aContext->ClearSelected (Standard_False);
975 aMesh->SetHiddenNodes( aHiddenNodes );
976 aMesh->SetHiddenElems( aHiddenElements );
977 aContext->Redisplay (aMesh, Standard_True);
982 //-----------------------------------------------------------------------------
983 static Standard_Integer showonly
984 (Draw_Interpretor& di, Standard_Integer argc, const char** argv )
988 di << "Wrong number of parameters\n";
989 di << "Use: " << argv[0] << " <mesh name>\n";
994 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
995 Handle( MeshVS_Mesh ) aMesh = getMesh( argv[1], di );
998 di << "The mesh is invalid\n";
1002 if( aContext.IsNull() )
1003 di << "The context is null\n";
1006 Handle(TColStd_HPackedMapOfInteger) aHiddenNodes =
1007 new TColStd_HPackedMapOfInteger(aMesh->GetDataSource()->GetAllNodes());
1008 Handle(TColStd_HPackedMapOfInteger) aHiddenElements =
1009 new TColStd_HPackedMapOfInteger(aMesh->GetDataSource()->GetAllElements());
1010 for( aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected() )
1012 Handle( MeshVS_MeshEntityOwner ) anOwner =
1013 Handle( MeshVS_MeshEntityOwner )::DownCast( aContext->SelectedOwner() );
1014 if( !anOwner.IsNull() )
1016 if( anOwner->Type() == MeshVS_ET_Node )
1018 aHiddenNodes->ChangeMap().Remove( anOwner->ID() );
1022 aHiddenElements->ChangeMap().Remove( anOwner->ID() );
1026 aMesh->SetHiddenNodes( aHiddenNodes );
1027 aMesh->SetHiddenElems( aHiddenElements );
1028 aContext->Redisplay (aMesh, Standard_True);
1033 //-----------------------------------------------------------------------------
1034 static Standard_Integer showall
1035 (Draw_Interpretor& di, Standard_Integer argc, const char** argv )
1039 di << "Wrong number of parameters\n";
1040 di << "Use: " << argv[0] << " <mesh name>\n";
1044 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
1045 Handle( MeshVS_Mesh ) aMesh = getMesh( argv[1], di );
1046 if( aMesh.IsNull() )
1048 di << "The mesh is invalid\n";
1052 if( aContext.IsNull() )
1053 di << "The context is null\n";
1056 aMesh->SetHiddenNodes( new TColStd_HPackedMapOfInteger() );
1057 aMesh->SetHiddenElems( new TColStd_HPackedMapOfInteger() );
1058 aContext->Redisplay (aMesh, Standard_True);
1064 //-----------------------------------------------------------------------------
1065 static Standard_Integer meshcolors( Draw_Interpretor& di,
1066 Standard_Integer argc,
1074 di << "Wrong number of parameters\n";
1075 di << "Use : meshcolors <mesh name> <mode> <isreflect>\n";
1076 di << "mode : {elem1|elem2|nodal|nodaltex|none}\n";
1077 di << " elem1 - different color for each element\n";
1078 di << " elem2 - one color for one side\n";
1079 di << " nodal - different color for each node\n";
1080 di << " nodaltex - different color for each node with texture interpolation\n";
1081 di << " none - clear\n";
1082 di << "isreflect : {0|1} \n";
1087 Handle( MeshVS_Mesh ) aMesh = getMesh( argv[ 1 ], di );
1089 if ( aMesh.IsNull() )
1091 di << "Mesh not found\n";
1094 Handle(AIS_InteractiveContext) anIC = ViewerTest::GetAISContext();
1095 if ( anIC.IsNull() )
1097 di << "The context is null\n";
1100 if( !aMesh.IsNull() )
1102 TCollection_AsciiString aMode = TCollection_AsciiString (argv[2]);
1103 Quantity_Color aColor1(Quantity_NOC_BLUE1);
1104 Quantity_Color aColor2(Quantity_NOC_RED1);
1105 if( aMode.IsEqual("elem1") || aMode.IsEqual("elem2") || aMode.IsEqual("nodal") || aMode.IsEqual("nodaltex") || aMode.IsEqual("none") )
1107 Handle(MeshVS_PrsBuilder) aTempBuilder;
1108 Standard_Integer aReflection = Draw::Atoi(argv[3]);
1110 for (Standard_Integer aCount = 0 ; aCount < aMesh->GetBuildersCount(); aCount++ ){
1111 aTempBuilder = aMesh->FindBuilder("MeshVS_ElementalColorPrsBuilder");
1112 if( !aTempBuilder.IsNull())
1113 aMesh->RemoveBuilderById(aTempBuilder->GetId());
1115 aTempBuilder = aMesh->FindBuilder("MeshVS_NodalColorPrsBuilder");
1116 if( !aTempBuilder.IsNull())
1117 aMesh->RemoveBuilderById(aTempBuilder->GetId());
1120 if( aMode.IsEqual("elem1") || aMode.IsEqual("elem2") )
1122 Handle(MeshVS_ElementalColorPrsBuilder) aBuilder = new MeshVS_ElementalColorPrsBuilder(
1123 aMesh, MeshVS_DMF_ElementalColorDataPrs | MeshVS_DMF_OCCMask );
1125 const TColStd_PackedMapOfInteger& anAllElements = aMesh->GetDataSource()->GetAllElements();
1126 TColStd_MapIteratorOfPackedMapOfInteger anIter( anAllElements );
1128 if( aMode.IsEqual("elem1") )
1129 for ( ; anIter.More(); anIter.Next() )
1131 Quantity_Color aColor( (Quantity_NameOfColor)( anIter.Key() % Quantity_NOC_WHITE ) );
1132 aBuilder->SetColor1( anIter.Key(), aColor );
1135 for ( ; anIter.More(); anIter.Next() )
1136 aBuilder->SetColor2( anIter.Key(), aColor1, aColor2 );
1138 aMesh->AddBuilder( aBuilder, Standard_True );
1142 if( aMode.IsEqual("nodal") )
1144 Handle(MeshVS_NodalColorPrsBuilder) aBuilder = new MeshVS_NodalColorPrsBuilder(
1145 aMesh, MeshVS_DMF_NodalColorDataPrs | MeshVS_DMF_OCCMask );
1146 aMesh->AddBuilder( aBuilder, Standard_True );
1149 const TColStd_PackedMapOfInteger& anAllNodes =
1150 aMesh->GetDataSource()->GetAllNodes();
1151 TColStd_MapIteratorOfPackedMapOfInteger anIter( anAllNodes );
1152 for ( ; anIter.More(); anIter.Next() )
1154 Quantity_Color aColor( (Quantity_NameOfColor)(
1155 anIter.Key() % Quantity_NOC_WHITE ) );
1156 aBuilder->SetColor( anIter.Key(), aColor );
1158 aMesh->AddBuilder( aBuilder, Standard_True );
1161 if(aMode.IsEqual("nodaltex"))
1163 // assign nodal builder to the mesh
1164 Handle(MeshVS_NodalColorPrsBuilder) aBuilder = new MeshVS_NodalColorPrsBuilder(
1165 aMesh, MeshVS_DMF_NodalColorDataPrs | MeshVS_DMF_OCCMask);
1166 aMesh->AddBuilder(aBuilder, Standard_True);
1167 aBuilder->UseTexture(Standard_True);
1169 // prepare color map for texture
1170 Aspect_SequenceOfColor aColorMap;
1171 aColorMap.Append((Quantity_NameOfColor) Quantity_NOC_RED);
1172 aColorMap.Append((Quantity_NameOfColor) Quantity_NOC_YELLOW);
1173 aColorMap.Append((Quantity_NameOfColor) Quantity_NOC_BLUE1);
1175 // prepare scale map for mesh - it will be assigned to mesh as texture coordinates
1176 // make mesh color interpolated from minimum X coord to maximum X coord
1177 Handle(MeshVS_DataSource) aDataSource = aMesh->GetDataSource();
1178 Standard_Real aMinX, aMinY, aMinZ, aMaxX, aMaxY, aMaxZ;
1180 // get bounding box for calculations
1181 aDataSource->GetBoundingBox().Get(aMinX, aMinY, aMinZ, aMaxX, aMaxY, aMaxZ);
1182 Standard_Real aDelta = aMaxX - aMinX;
1184 // assign color scale map values (0..1) to nodes
1185 TColStd_DataMapOfIntegerReal aScaleMap;
1186 TColStd_Array1OfReal aCoords(1, 3);
1187 Standard_Integer aNbNodes;
1188 MeshVS_EntityType aType;
1191 const TColStd_PackedMapOfInteger& anAllNodes =
1192 aMesh->GetDataSource()->GetAllNodes();
1193 TColStd_MapIteratorOfPackedMapOfInteger anIter(anAllNodes);
1194 for (; anIter.More(); anIter.Next())
1196 //get node coordinates to aCoord variable
1197 aDataSource->GetGeom(anIter.Key(), Standard_False, aCoords, aNbNodes, aType);
1199 Standard_Real aScaleValue;
1202 aScaleValue = (aCoords.Value(1) - (Standard_Real) aMinX) / aDelta;
1203 } catch(Standard_Failure const&) {
1207 aScaleMap.Bind(anIter.Key(), aScaleValue);
1210 //set color map for builder and a color for invalid scale value
1211 aBuilder->SetColorMap(aColorMap);
1212 aBuilder->SetInvalidColor(Quantity_NOC_BLACK);
1213 aBuilder->SetTextureCoords(aScaleMap);
1214 aMesh->AddBuilder(aBuilder, Standard_True);
1217 aMesh->GetDrawer()->SetBoolean (MeshVS_DA_ColorReflection, aReflection != 0);
1219 anIC->Redisplay (aMesh, Standard_True);
1223 di << "Wrong mode name\n";
1228 catch ( Standard_Failure const& )
1235 //-----------------------------------------------------------------------------
1236 static Standard_Integer meshvectors( Draw_Interpretor& di,
1237 Standard_Integer argc,
1242 di << "Wrong number of parameters\n";
1243 di << "Use : meshvectors <mesh name> < -mode {elem|nodal|none} > [-maxlen len] [-color name] [-arrowpart ratio] [-issimple {1|0}]\n";
1244 di << "Supported mode values:\n";
1245 di << " elem - vector per element\n";
1246 di << " nodal - vector per node\n";
1247 di << " none - clear\n";
1252 Handle( MeshVS_Mesh ) aMesh = getMesh( argv[ 1 ], di );
1254 if ( aMesh.IsNull() )
1256 di << "Mesh not found\n";
1259 Handle(AIS_InteractiveContext) anIC = ViewerTest::GetAISContext();
1260 if ( anIC.IsNull() )
1262 di << "The context is null\n";
1266 TCollection_AsciiString aParam;
1267 TCollection_AsciiString aMode("none");
1268 Standard_Real aMaxlen(1.0);
1269 Quantity_Color aColor(Quantity_NOC_ORANGE);
1270 Standard_Real anArrowPart(0.1);
1271 Standard_Boolean isSimplePrs(Standard_False);
1273 for (Standard_Integer anIdx = 2; anIdx < argc; anIdx++)
1275 if (!aParam.IsEmpty())
1277 if (aParam == "-mode")
1279 aMode = argv[anIdx];
1281 else if (aParam == "-maxlen")
1283 aMaxlen = Draw::Atof(argv[anIdx]);
1285 else if (aParam == "-color")
1287 aColor = ViewerTest::GetColorFromName(argv[anIdx]);
1289 else if (aParam == "-arrowpart")
1291 anArrowPart = Draw::Atof(argv[anIdx]);
1293 else if (aParam == "-issimple")
1295 isSimplePrs = Draw::Atoi(argv[anIdx]) != 0;
1299 else if (argv[anIdx][0] == '-')
1301 aParam = argv[anIdx];
1305 if( !aMode.IsEqual("elem") && !aMode.IsEqual("nodal") && !aMode.IsEqual("none") )
1307 di << "Wrong mode name\n";
1311 Handle(MeshVS_PrsBuilder) aTempBuilder;
1313 aTempBuilder = aMesh->FindBuilder("MeshVS_VectorPrsBuilder");
1314 if( !aTempBuilder.IsNull())
1315 aMesh->RemoveBuilderById(aTempBuilder->GetId());
1317 if( !aMode.IsEqual("none") )
1319 Handle(MeshVS_VectorPrsBuilder) aBuilder = new MeshVS_VectorPrsBuilder( aMesh.operator->(),
1322 MeshVS_DMF_VectorDataPrs,
1328 Standard_Boolean anIsElement = aMode.IsEqual("elem");
1329 const TColStd_PackedMapOfInteger& anAllIDs = anIsElement ? aMesh->GetDataSource()->GetAllElements() :
1330 aMesh->GetDataSource()->GetAllNodes();
1332 Standard_Integer aNbNodes;
1333 MeshVS_EntityType aEntType;
1335 TColStd_Array1OfReal aCoords(1, 3);
1337 TColStd_MapIteratorOfPackedMapOfInteger anIter( anAllIDs );
1338 for ( ; anIter.More(); anIter.Next() )
1340 Standard_Boolean IsValidData = Standard_False;
1342 aMesh->GetDataSource()->GetGeomType(anIter.Key(), anIsElement, aEntType);
1343 if (aEntType == MeshVS_ET_Face)
1344 IsValidData = aMesh->GetDataSource()->GetNormal(anIter.Key(), 3, aCoords.ChangeValue(1), aCoords.ChangeValue(2), aCoords.ChangeValue(3));
1346 IsValidData = aMesh->GetDataSource()->GetGeom(anIter.Key(), Standard_False, aCoords, aNbNodes, aEntType);
1351 aNorm = gp_Vec(aCoords.Value(1), aCoords.Value(2), aCoords.Value(3));
1352 if(aNorm.Magnitude() < gp::Resolution())
1354 aNorm = gp_Vec(0,0,1); //method GetGeom(...) returns coordinates of nodes
1359 aNorm = gp_Vec(0,0,1);
1361 aBuilder->SetVector(anIsElement, anIter.Key(), aNorm.Normalized());
1364 aMesh->AddBuilder( aBuilder, Standard_False );
1365 aMesh->GetDrawer()->SetDouble ( MeshVS_DA_VectorArrowPart, anArrowPart );
1368 anIC->Redisplay (aMesh, Standard_True);
1372 //-----------------------------------------------------------------------------
1374 static Standard_Integer meshtext( Draw_Interpretor& di,
1375 Standard_Integer argc,
1380 di << "Wrong number of parameters\n";
1381 di << "Use : meshtext <mesh name>\n";
1385 Handle( MeshVS_Mesh ) aMesh = getMesh( argv[ 1 ], di );
1387 if ( aMesh.IsNull() )
1389 di << "Mesh not found\n";
1393 Handle(AIS_InteractiveContext) anIC = ViewerTest::GetAISContext();
1394 if ( anIC.IsNull() )
1396 di << "The context is null\n";
1400 // Prepare triangle labels
1401 MeshVS_DataMapOfIntegerAsciiString aLabels;
1402 Standard_Integer aLen = aMesh->GetDataSource()->GetAllElements().Extent();
1403 for ( Standard_Integer anIndex = 1; anIndex <= aLen; anIndex++ ){
1404 aLabels.Bind( anIndex, TCollection_AsciiString( anIndex ) );
1407 Handle(MeshVS_TextPrsBuilder) aTextBuilder = new MeshVS_TextPrsBuilder( aMesh.operator->(), 20., Quantity_NOC_YELLOW );
1408 aTextBuilder->SetTexts( Standard_True, aLabels );
1409 aMesh->AddBuilder( aTextBuilder );
1414 static Standard_Integer meshdeform( Draw_Interpretor& di,
1415 Standard_Integer argc,
1420 di << "Wrong number of parameters\n";
1421 di << "Use : meshdeform <mesh name> < -mode {on|off} > [-scale scalefactor]\n";
1425 Handle( MeshVS_Mesh ) aMesh = getMesh( argv[ 1 ], di );
1427 if ( aMesh.IsNull() )
1429 di << "Mesh not found\n";
1432 Handle(AIS_InteractiveContext) anIC = ViewerTest::GetAISContext();
1433 if ( anIC.IsNull() )
1435 di << "The context is null\n";
1439 TCollection_AsciiString aParam;
1440 TCollection_AsciiString aMode("off");
1441 Standard_Real aScale(1.0);
1443 for (Standard_Integer anIdx = 2; anIdx < argc; anIdx++)
1445 if (!aParam.IsEmpty())
1447 if (aParam == "-mode")
1449 aMode = argv[anIdx];
1451 else if (aParam == "-scale")
1453 aScale = Draw::Atof(argv[anIdx]);
1457 else if (argv[anIdx][0] == '-')
1459 aParam = argv[anIdx];
1463 if(!aMode.IsEqual("on") && !aMode.IsEqual("off"))
1465 di << "Wrong mode name\n";
1469 Handle ( MeshVS_DeformedDataSource ) aDefDS =
1470 new MeshVS_DeformedDataSource( aMesh->GetDataSource() , aScale );
1472 const TColStd_PackedMapOfInteger& anAllIDs = aMesh->GetDataSource()->GetAllNodes();
1474 Standard_Integer aNbNodes;
1475 MeshVS_EntityType aEntType;
1477 TColStd_MapIteratorOfPackedMapOfInteger anIter( anAllIDs );
1478 for ( ; anIter.More(); anIter.Next() )
1480 TColStd_Array1OfReal aCoords(1, 3);
1481 aMesh->GetDataSource()->GetGeom(anIter.Key(), Standard_False, aCoords, aNbNodes, aEntType);
1483 gp_Vec aNorm = gp_Vec(aCoords.Value(1), aCoords.Value(2), aCoords.Value(3));
1484 if( !aNorm.Magnitude() )
1485 aNorm = gp_Vec(0,0,1);
1486 aDefDS->SetVector(anIter.Key(), aNorm.Normalized());
1489 aMesh->SetDataSource(aDefDS);
1491 anIC->Redisplay (aMesh, Standard_False);
1493 Handle( V3d_View ) aView = ViewerTest::CurrentView();
1494 if ( !aView.IsNull() )
1500 static Standard_Integer mesh_edge_width( Draw_Interpretor& di,
1501 Standard_Integer argc,
1509 di << "Wrong number of parameters\n";
1510 di << "Use : mesh_edge_width <mesh name> <width>\n";
1514 Handle(MeshVS_Mesh) aMesh = getMesh( argv[ 1 ], di );
1515 if ( aMesh.IsNull() )
1517 di << "Mesh not found\n";
1521 const char* aWidthStr = argv[ 2 ];
1522 if ( aWidthStr == 0 || Draw::Atof( aWidthStr ) <= 0 )
1524 di << "Width must be real value more than zero\n";
1528 double aWidth = Draw::Atof( aWidthStr );
1530 Handle(AIS_InteractiveContext) anIC = ViewerTest::GetAISContext();
1531 if ( anIC.IsNull() )
1533 di << "The context is null\n";
1537 Handle(MeshVS_Drawer) aDrawer = aMesh->GetDrawer();
1538 if ( aDrawer.IsNull() )
1540 di << "The drawer is null\n";
1544 aDrawer->SetDouble( MeshVS_DA_EdgeWidth, aWidth );
1545 anIC->Redisplay (aMesh, Standard_True);
1547 catch ( Standard_Failure const& )
1555 //-----------------------------------------------------------------------------
1557 static Standard_Integer meshinfo(Draw_Interpretor& di,
1558 Standard_Integer argc,
1563 di << "Wrong number of parameters. Use : meshinfo mesh\n";
1567 Handle(MeshVS_Mesh) aMesh = getMesh(argv[ 1 ], di);
1568 if ( aMesh.IsNull() )
1570 di << "Mesh not found\n";
1574 Handle(XSDRAWSTLVRML_DataSource) stlMeshSource = Handle(XSDRAWSTLVRML_DataSource)::DownCast(aMesh->GetDataSource());
1575 if (!stlMeshSource.IsNull())
1577 const TColStd_PackedMapOfInteger& nodes = stlMeshSource->GetAllNodes();
1578 const TColStd_PackedMapOfInteger& tris = stlMeshSource->GetAllElements();
1580 di << "Nb nodes = " << nodes.Extent() << "\n";
1581 di << "Nb triangles = " << tris.Extent() << "\n";
1587 //-----------------------------------------------------------------------------
1589 void XSDRAWSTLVRML::InitCommands (Draw_Interpretor& theCommands)
1591 const char* g = "XSTEP-STL/VRML"; // Step transfer file commands
1592 //XSDRAW::LoadDraw(theCommands);
1594 theCommands.Add ("ReadGltf",
1595 "ReadGltf Doc file [-parallel {on|off}] [-listExternalFiles] [-noCreateDoc]"
1596 "\n\t\t: Read glTF file into XDE document."
1597 "\n\t\t: -listExternalFiles do not read mesh and only list external files"
1598 "\n\t\t: -noCreateDoc read into existing XDE document",
1599 __FILE__, ReadGltf, g);
1600 theCommands.Add ("readgltf",
1601 "readgltf shape file"
1602 "\n\t\t: Same as ReadGltf but reads glTF file into a shape instead of a document.",
1603 __FILE__, ReadGltf, g);
1604 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);
1605 theCommands.Add ("writestl", "shape file [ascii/binary (0/1) : 1 by default] [InParallel (0/1) : 0 by default]",__FILE__,writestl,g);
1606 theCommands.Add ("readstl",
1607 "readstl shape file [-brep]"
1608 "\n\t\t: Reads STL file and creates a new shape with specified name."
1609 "\n\t\t: When -brep is specified, creates a Compound of per-triangle Faces."
1610 "\n\t\t: Single triangulation-only Face is created otherwise (default).",
1611 __FILE__, readstl, g);
1612 theCommands.Add ("loadvrml" , "shape file",__FILE__,loadvrml,g);
1613 theCommands.Add ("ReadObj",
1614 "ReadObj Doc file [-fileCoordSys {Zup|Yup}] [-fileUnit Unit]"
1615 "\n\t\t: [-resultCoordSys {Zup|Yup}] [-singlePrecision]"
1616 "\n\t\t: [-listExternalFiles] [-noCreateDoc]"
1617 "\n\t\t: Read OBJ file into XDE document."
1618 "\n\t\t: -fileUnit length unit of OBJ file content;"
1619 "\n\t\t: -fileCoordSys coordinate system defined by OBJ file; Yup when not specified."
1620 "\n\t\t: -resultCoordSys result coordinate system; Zup when not specified."
1621 "\n\t\t: -singlePrecision truncate vertex data to single precision during read; FALSE by default."
1622 "\n\t\t: -listExternalFiles do not read mesh and only list external files."
1623 "\n\t\t: -noCreateDoc read into existing XDE document.",
1624 __FILE__, ReadObj, g);
1625 theCommands.Add ("readobj",
1626 "readobj shape file [-fileCoordSys {Zup|Yup}] [-fileUnit Unit]"
1627 "\n\t\t: [-resultCoordSys {Zup|Yup}] [-singlePrecision]"
1628 "\n\t\t: [-singleFace]"
1629 "\n\t\t: Same as ReadObj but reads OBJ file into a shape instead of a document."
1630 "\n\t\t: -singleFace merge OBJ content into a single triangulation Face.",
1631 __FILE__, ReadObj, g);
1633 theCommands.Add ("meshfromstl", "creates MeshVS_Mesh from STL file", __FILE__, createmesh, g );
1634 theCommands.Add ("mesh3delem", "creates 3d element mesh to test", __FILE__, create3d, g );
1635 theCommands.Add ("meshshadcolor", "change MeshVS_Mesh shading color", __FILE__, meshcolor, g );
1636 theCommands.Add ("meshlinkcolor", "change MeshVS_Mesh line color", __FILE__, linecolor, g );
1637 theCommands.Add ("meshmat", "change MeshVS_Mesh material and transparency", __FILE__, meshmat, g );
1638 theCommands.Add ("meshshrcoef", "change MeshVS_Mesh shrink coeff", __FILE__, shrink, g );
1639 theCommands.Add ("meshclosed", "meshclosed meshname (0/1) \nChange MeshVS_Mesh drawing mode. 0 - not closed object, 1 - closed object", __FILE__, closed, g);
1640 theCommands.Add ("meshshow", "display MeshVS_Mesh object", __FILE__, mdisplay, g );
1641 theCommands.Add ("meshhide", "erase MeshVS_Mesh object", __FILE__, merase, g );
1642 theCommands.Add ("meshhidesel", "hide selected entities", __FILE__, hidesel, g );
1643 theCommands.Add ("meshshowsel", "show only selected entities", __FILE__, showonly, g );
1644 theCommands.Add ("meshshowall", "show all entities", __FILE__, showall, g );
1645 theCommands.Add ("meshcolors", "display color presentation", __FILE__, meshcolors, g );
1646 theCommands.Add ("meshvectors", "display sample vectors", __FILE__, meshvectors, g );
1647 theCommands.Add ("meshtext", "display text labels", __FILE__, meshtext, g );
1648 theCommands.Add ("meshdeform", "display deformed mesh", __FILE__, meshdeform, g );
1649 theCommands.Add ("mesh_edge_width", "set width of edges", __FILE__, mesh_edge_width, g );
1650 theCommands.Add ("meshinfo", "displays the number of nodes and triangles", __FILE__, meshinfo, g );
1653 //==============================================================================
1654 // XSDRAWSTLVRML::Factory
1655 //==============================================================================
1656 void XSDRAWSTLVRML::Factory(Draw_Interpretor& theDI)
1658 XSDRAWIGES::InitSelect();
1659 XSDRAWIGES::InitToBRep(theDI);
1660 XSDRAWIGES::InitFromBRep(theDI);
1661 XSDRAWSTEP::InitCommands(theDI);
1662 XSDRAWSTLVRML::InitCommands(theDI);
1663 XSDRAW::LoadDraw(theDI);
1665 theDI << "Draw Plugin : All TKXSDRAW commands are loaded\n";
1669 // Declare entry point PLUGINFACTORY
1670 DPLUGIN(XSDRAWSTLVRML)