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>
46 #include <RWGltf_CafWriter.hxx>
49 #include <RWObj_CafReader.hxx>
50 #include <SelectMgr_SelectionManager.hxx>
51 #include <Standard_ErrorHandler.hxx>
52 #include <StdSelect_ViewerSelector3d.hxx>
54 #include <StlAPI_Writer.hxx>
55 #include <TColgp_SequenceOfXYZ.hxx>
56 #include <TCollection_AsciiString.hxx>
57 #include <TColStd_Array1OfReal.hxx>
58 #include <TColStd_HPackedMapOfInteger.hxx>
59 #include <TColStd_MapIteratorOfPackedMapOfInteger.hxx>
60 #include <TDataStd_Name.hxx>
61 #include <TDocStd_Application.hxx>
62 #include <TopoDS_Face.hxx>
63 #include <TopoDS_Shape.hxx>
64 #include <UnitsAPI.hxx>
65 #include <UnitsMethods.hxx>
66 #include <V3d_View.hxx>
67 #include <ViewerTest.hxx>
68 #include <VrmlAPI.hxx>
69 #include <VrmlAPI_Writer.hxx>
70 #include <VrmlData_DataMapOfShapeAppearance.hxx>
71 #include <VrmlData_Scene.hxx>
72 #include <VrmlData_ShapeConvert.hxx>
73 #include <XCAFDoc_DocumentTool.hxx>
74 #include <XCAFDoc_ShapeTool.hxx>
76 #include <XSDRAWIGES.hxx>
77 #include <XSDRAWSTEP.hxx>
78 #include <XSDRAWSTLVRML.hxx>
79 #include <XSDRAWSTLVRML_DataSource.hxx>
80 #include <XSDRAWSTLVRML_DataSource3D.hxx>
81 #include <XSDRAWSTLVRML_DrawableMesh.hxx>
87 extern Standard_Boolean VDisplayAISObject (const TCollection_AsciiString& theName,
88 const Handle(AIS_InteractiveObject)& theAISObj,
89 Standard_Boolean theReplaceIfExists = Standard_True);
91 //=============================================================================
93 //purpose : Reads glTF file
94 //=============================================================================
95 static Standard_Integer ReadGltf (Draw_Interpretor& theDI,
96 Standard_Integer theNbArgs,
97 const char** theArgVec)
99 TCollection_AsciiString aDestName, aFilePath;
100 Standard_Boolean toUseExistingDoc = Standard_False;
101 Standard_Real aSystemUnitFactor = UnitsMethods::GetCasCadeLengthUnit() * 0.001;
102 Standard_Boolean toListExternalFiles = Standard_False;
103 Standard_Boolean isParallel = Standard_False;
104 Standard_Boolean isNoDoc = (TCollection_AsciiString(theArgVec[0]) == "readgltf");
105 for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
107 TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
108 anArgCase.LowerCase();
110 && (anArgCase == "-nocreate"
111 || anArgCase == "-nocreatedoc"))
113 toUseExistingDoc = Standard_True;
114 if (anArgIter + 1 < theNbArgs
115 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toUseExistingDoc))
120 else if (anArgCase == "-parallel")
122 isParallel = Standard_True;
123 if (anArgIter + 1 < theNbArgs
124 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], isParallel))
129 else if (anArgCase == "-listexternalfiles"
130 || anArgCase == "-listexternals"
131 || anArgCase == "-listexternal"
132 || anArgCase == "-external"
133 || anArgCase == "-externalfiles")
135 toListExternalFiles = Standard_True;
137 else if (aDestName.IsEmpty())
139 aDestName = theArgVec[anArgIter];
141 else if (aFilePath.IsEmpty())
143 aFilePath = theArgVec[anArgIter];
147 std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
151 if (aFilePath.IsEmpty())
153 std::cout << "Syntax error: wrong number of arguments\n";
157 Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator (theDI, 1);
158 Handle(TDocStd_Document) aDoc;
159 if (!toListExternalFiles
162 Handle(TDocStd_Application) anApp = DDocStd::GetApplication();
163 Standard_CString aNameVar = aDestName.ToCString();
164 DDocStd::GetDocument (aNameVar, aDoc, Standard_False);
167 if (toUseExistingDoc)
169 std::cout << "Error: document with name " << aDestName << " does not exist\n";
172 anApp->NewDocument (TCollection_ExtendedString ("BinXCAF"), aDoc);
174 else if (!toUseExistingDoc)
176 std::cout << "Error: document with name " << aDestName << " already exists\n";
181 RWGltf_CafReader aReader;
182 aReader.SetSystemLengthUnit (aSystemUnitFactor);
183 aReader.SetSystemCoordinateSystem (RWMesh_CoordinateSystem_Zup);
184 aReader.SetDocument (aDoc);
185 aReader.SetParallel (isParallel);
186 if (toListExternalFiles)
188 aReader.ProbeHeader (aFilePath);
189 for (NCollection_IndexedMap<TCollection_AsciiString>::Iterator aFileIter (aReader.ExternalFiles()); aFileIter.More(); aFileIter.Next())
191 theDI << "\"" << aFileIter.Value() << "\" ";
196 aReader.Perform (aFilePath, aProgress);
199 DBRep::Set (aDestName.ToCString(), aReader.SingleShape());
203 Handle(DDocStd_DrawDocument) aDrawDoc = new DDocStd_DrawDocument (aDoc);
204 TDataStd_Name::Set (aDoc->GetData()->Root(), aDestName.ToCString());
205 Draw::Set (aDestName.ToCString(), aDrawDoc);
211 //=============================================================================
212 //function : WriteGltf
213 //purpose : Writes glTF file
214 //=============================================================================
215 static Standard_Integer WriteGltf (Draw_Interpretor& theDI,
216 Standard_Integer theNbArgs,
217 const char** theArgVec)
219 TCollection_AsciiString aGltfFilePath;
220 Handle(TDocStd_Document) aDoc;
221 Handle(TDocStd_Application) anApp = DDocStd::GetApplication();
222 TColStd_IndexedDataMapOfStringString aFileInfo;
223 RWGltf_WriterTrsfFormat aTrsfFormat = RWGltf_WriterTrsfFormat_Compact;
224 bool toForceUVExport = false;
225 for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
227 TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
228 anArgCase.LowerCase();
229 if (anArgCase == "-comments"
230 && anArgIter + 1 < theNbArgs)
232 aFileInfo.Add ("Comments", theArgVec[++anArgIter]);
234 else if (anArgCase == "-author"
235 && anArgIter + 1 < theNbArgs)
237 aFileInfo.Add ("Author", theArgVec[++anArgIter]);
239 else if (anArgCase == "-forceuvexport"
240 || anArgCase == "-forceuv")
242 toForceUVExport = true;
243 if (anArgIter + 1 < theNbArgs
244 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toForceUVExport))
249 else if (anArgCase == "-trsfformat"
250 && anArgIter + 1 < theNbArgs)
252 TCollection_AsciiString aTrsfStr (theArgVec[++anArgIter]);
253 aTrsfStr.LowerCase();
254 if (aTrsfStr == "compact")
256 aTrsfFormat = RWGltf_WriterTrsfFormat_Compact;
258 else if (aTrsfStr == "mat4")
260 aTrsfFormat = RWGltf_WriterTrsfFormat_Mat4;
262 else if (aTrsfStr == "trs")
264 aTrsfFormat = RWGltf_WriterTrsfFormat_TRS;
268 std::cout << "Syntax error at '" << anArgCase << "'\n";
272 else if (aDoc.IsNull())
274 Standard_CString aNameVar = theArgVec[anArgIter];
275 DDocStd::GetDocument (aNameVar, aDoc, false);
278 TopoDS_Shape aShape = DBRep::Get (aNameVar);
281 std::cout << "Syntax error: '" << aNameVar << "' is not a shape nor document\n";
285 anApp->NewDocument (TCollection_ExtendedString ("BinXCAF"), aDoc);
286 Handle(XCAFDoc_ShapeTool) aShapeTool = XCAFDoc_DocumentTool::ShapeTool (aDoc->Main());
287 aShapeTool->AddShape (aShape);
290 else if (aGltfFilePath.IsEmpty())
292 aGltfFilePath = theArgVec[anArgIter];
296 std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
300 if (aGltfFilePath.IsEmpty())
302 std::cout << "Syntax error: wrong number of arguments\n";
306 Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator (theDI, 1);
308 TCollection_AsciiString anExt = aGltfFilePath;
311 const Standard_Real aSystemUnitFactor = UnitsMethods::GetCasCadeLengthUnit() * 0.001;
313 RWGltf_CafWriter aWriter (aGltfFilePath, anExt.EndsWith (".glb"));
314 aWriter.SetTransformationFormat (aTrsfFormat);
315 aWriter.SetForcedUVExport (toForceUVExport);
316 aWriter.ChangeCoordinateSystemConverter().SetInputLengthUnit (aSystemUnitFactor);
317 aWriter.ChangeCoordinateSystemConverter().SetInputCoordinateSystem (RWMesh_CoordinateSystem_Zup);
318 aWriter.Perform (aDoc, aFileInfo, aProgress);
322 static Standard_Integer writestl
323 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
325 if (argc < 3 || argc > 4) {
326 di << "Use: " << argv[0]
327 << " shape file [ascii/binary (0/1) : 1 by default]\n";
329 TopoDS_Shape aShape = DBRep::Get(argv[1]);
330 Standard_Boolean isASCIIMode = Standard_False;
332 isASCIIMode = (Draw::Atoi(argv[3]) == 0);
334 StlAPI_Writer aWriter;
335 aWriter.ASCIIMode() = isASCIIMode;
336 Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator(di, 1);
337 Standard_Boolean isOK = aWriter.Write (aShape, argv[2], aProgress);
339 di << "** Error **: Mesh writing has been failed.\n";
344 //=============================================================================
346 //purpose : Reads stl file
347 //=============================================================================
348 static Standard_Integer readstl(Draw_Interpretor& theDI,
349 Standard_Integer theArgc,
350 const char** theArgv)
352 TCollection_AsciiString aShapeName, aFilePath;
353 bool toCreateCompOfTris = false;
354 for (Standard_Integer anArgIter = 1; anArgIter < theArgc; ++anArgIter)
356 TCollection_AsciiString anArg (theArgv[anArgIter]);
358 if (aShapeName.IsEmpty())
360 aShapeName = theArgv[anArgIter];
362 else if (aFilePath.IsEmpty())
364 aFilePath = theArgv[anArgIter];
366 else if (anArg == "-brep")
368 toCreateCompOfTris = true;
369 if (anArgIter + 1 < theArgc
370 && ViewerTest::ParseOnOff (theArgv[anArgIter + 1], toCreateCompOfTris))
377 std::cout << "Syntax error: unknown argument '" << theArgv[anArgIter] << "'\n";
381 if (aFilePath.IsEmpty())
383 std::cout << "Syntax error: not enough arguments\n";
388 if (!toCreateCompOfTris)
390 // Read STL file to the triangulation.
391 Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator (theDI, 1);
392 Handle(Poly_Triangulation) aTriangulation = RWStl::ReadFile (aFilePath.ToCString(), aProgress);
397 aB.UpdateFace (aFace, aTriangulation);
402 Standard_DISABLE_DEPRECATION_WARNINGS
403 StlAPI::Read(aShape, aFilePath.ToCString());
404 Standard_ENABLE_DEPRECATION_WARNINGS
406 DBRep::Set (aShapeName.ToCString(), aShape);
410 //! Parse RWMesh_CoordinateSystem enumeration.
411 static Standard_Boolean parseCoordinateSystem (const char* theArg,
412 RWMesh_CoordinateSystem& theSystem)
414 TCollection_AsciiString aCSStr (theArg);
418 theSystem = RWMesh_CoordinateSystem_Zup;
420 else if (aCSStr == "yup")
422 theSystem = RWMesh_CoordinateSystem_Yup;
426 return Standard_False;
428 return Standard_True;
431 //=============================================================================
433 //purpose : Reads OBJ file
434 //=============================================================================
435 static Standard_Integer ReadObj (Draw_Interpretor& theDI,
436 Standard_Integer theNbArgs,
437 const char** theArgVec)
439 TCollection_AsciiString aDestName, aFilePath;
440 Standard_Boolean toUseExistingDoc = Standard_False;
441 Standard_Real aFileUnitFactor = -1.0;
442 RWMesh_CoordinateSystem aResultCoordSys = RWMesh_CoordinateSystem_Zup, aFileCoordSys = RWMesh_CoordinateSystem_Yup;
443 Standard_Boolean toListExternalFiles = Standard_False, isSingleFace = Standard_False, isSinglePrecision = Standard_False;
444 Standard_Boolean isNoDoc = (TCollection_AsciiString(theArgVec[0]) == "readobj");
445 for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
447 TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
448 anArgCase.LowerCase();
449 if (anArgIter + 1 < theNbArgs
450 && (anArgCase == "-unit"
451 || anArgCase == "-units"
452 || anArgCase == "-fileunit"
453 || anArgCase == "-fileunits"))
455 const TCollection_AsciiString aUnitStr (theArgVec[++anArgIter]);
456 aFileUnitFactor = UnitsAPI::AnyToSI (1.0, aUnitStr.ToCString());
457 if (aFileUnitFactor <= 0.0)
459 std::cout << "Syntax error: wrong length unit '" << aUnitStr << "'\n";
463 else if (anArgIter + 1 < theNbArgs
464 && (anArgCase == "-filecoordinatesystem"
465 || anArgCase == "-filecoordsystem"
466 || anArgCase == "-filecoordsys"))
468 if (!parseCoordinateSystem (theArgVec[++anArgIter], aFileCoordSys))
470 std::cout << "Syntax error: unknown coordinate system '" << theArgVec[anArgIter] << "'\n";
474 else if (anArgIter + 1 < theNbArgs
475 && (anArgCase == "-resultcoordinatesystem"
476 || anArgCase == "-resultcoordsystem"
477 || anArgCase == "-resultcoordsys"
478 || anArgCase == "-rescoordsys"))
480 if (!parseCoordinateSystem (theArgVec[++anArgIter], aResultCoordSys))
482 std::cout << "Syntax error: unknown coordinate system '" << theArgVec[anArgIter] << "'\n";
486 else if (anArgCase == "-singleprecision"
487 || anArgCase == "-singleprec")
489 isSinglePrecision = Standard_True;
490 if (anArgIter + 1 < theNbArgs
491 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], isSinglePrecision))
497 && (anArgCase == "-singleface"
498 || anArgCase == "-singletriangulation"))
500 isSingleFace = Standard_True;
503 && (anArgCase == "-nocreate"
504 || anArgCase == "-nocreatedoc"))
506 toUseExistingDoc = Standard_True;
507 if (anArgIter + 1 < theNbArgs
508 && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toUseExistingDoc))
513 else if (anArgCase == "-listexternalfiles"
514 || anArgCase == "-listexternals"
515 || anArgCase == "-listexternal"
516 || anArgCase == "-external"
517 || anArgCase == "-externalfiles")
519 toListExternalFiles = Standard_True;
521 else if (aDestName.IsEmpty())
523 aDestName = theArgVec[anArgIter];
525 else if (aFilePath.IsEmpty())
527 aFilePath = theArgVec[anArgIter];
531 std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
535 if (aFilePath.IsEmpty())
537 std::cout << "Syntax error: wrong number of arguments\n";
541 Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator (theDI, 1);
542 Handle(TDocStd_Document) aDoc;
544 && !toListExternalFiles)
546 Handle(TDocStd_Application) anApp = DDocStd::GetApplication();
547 Standard_CString aNameVar = aDestName.ToCString();
548 DDocStd::GetDocument (aNameVar, aDoc, Standard_False);
551 if (toUseExistingDoc)
553 std::cout << "Error: document with name " << aDestName << " does not exist\n";
556 anApp->NewDocument (TCollection_ExtendedString ("BinXCAF"), aDoc);
558 else if (!toUseExistingDoc)
560 std::cout << "Error: document with name " << aDestName << " already exists\n";
565 RWObj_CafReader aReader;
566 aReader.SetSinglePrecision (isSinglePrecision);
567 aReader.SetSystemLengthUnit (UnitsMethods::GetCasCadeLengthUnit() * 0.001);
568 aReader.SetSystemCoordinateSystem (aResultCoordSys);
569 aReader.SetFileLengthUnit (aFileUnitFactor);
570 aReader.SetFileCoordinateSystem (aFileCoordSys);
571 aReader.SetDocument (aDoc);
574 RWObj_TriangulationReader aSimpleReader;
575 aSimpleReader.SetSinglePrecision (isSinglePrecision);
576 aSimpleReader.SetCreateShapes (Standard_False);
577 aSimpleReader.SetTransformation (aReader.CoordinateSystemConverter());
578 aSimpleReader.Read (aFilePath.ToCString(), aProgress);
580 Handle(Poly_Triangulation) aTriangulation = aSimpleReader.GetTriangulation();
582 BRep_Builder aBuiler;
583 aBuiler.MakeFace (aFace);
584 aBuiler.UpdateFace (aFace, aTriangulation);
585 DBRep::Set (aDestName.ToCString(), aFace);
589 if (toListExternalFiles)
591 aReader.ProbeHeader (aFilePath);
592 for (NCollection_IndexedMap<TCollection_AsciiString>::Iterator aFileIter (aReader.ExternalFiles()); aFileIter.More(); aFileIter.Next())
594 theDI << "\"" << aFileIter.Value() << "\" ";
599 aReader.Perform (aFilePath, aProgress);
602 DBRep::Set (aDestName.ToCString(), aReader.SingleShape());
606 Handle(DDocStd_DrawDocument) aDrawDoc = new DDocStd_DrawDocument (aDoc);
607 TDataStd_Name::Set (aDoc->GetData()->Root(), aDestName.ToCString());
608 Draw::Set (aDestName.ToCString(), aDrawDoc);
614 static Standard_Integer writevrml
615 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
617 if (argc < 3 || argc > 5)
619 di << "wrong number of parameters\n";
623 TopoDS_Shape aShape = DBRep::Get(argv[1]);
625 // Get the optional parameters
626 Standard_Integer aVersion = 2;
627 Standard_Integer aType = 1;
630 aVersion = Draw::Atoi(argv[3]);
632 aType = Draw::Atoi(argv[4]);
636 aVersion = Max(1, aVersion);
637 aVersion = Min(2, aVersion);
638 aType = Max(0, aType);
639 aType = Min(2, aType);
641 VrmlAPI_Writer writer;
645 case 0: writer.SetRepresentation(VrmlAPI_ShadedRepresentation); break;
646 case 1: writer.SetRepresentation(VrmlAPI_WireFrameRepresentation); break;
647 case 2: writer.SetRepresentation(VrmlAPI_BothRepresentation); break;
650 if (!writer.Write(aShape, argv[2], aVersion))
652 di << "Error: File " << argv[2] << " was not written\n";
658 //=======================================================================
659 //function : loadvrml
661 //=======================================================================
663 static Standard_Integer loadvrml
664 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
666 if (argc<3) di << "wrong number of parameters" << "\n";
668 TopoDS_Shape aShape ;
669 VrmlData_DataMapOfShapeAppearance aShapeAppMap;
671 //-----------------------------------------------------------
673 std::istream aStream (&aFic);
675 if (aFic.open(argv[2], std::ios::in)) {
677 // Get path of the VRML file.
678 OSD_Path aPath(argv[2]);
679 TCollection_AsciiString aVrmlDir(".");
680 TCollection_AsciiString aDisk = aPath.Disk();
681 TCollection_AsciiString aTrek = aPath.Trek();
682 if (!aTrek.IsEmpty())
684 if (!aDisk.IsEmpty())
688 aTrek.ChangeAll('|', '/');
692 VrmlData_Scene aScene;
693 Standard_Real anOCCUnit = UnitsMethods::GetCasCadeLengthUnit();
694 aScene.SetLinearScale(1000. / anOCCUnit);
696 aScene.SetVrmlDir (aVrmlDir);
698 const char * aStr = 0L;
699 switch (aScene.Status()) {
701 case VrmlData_StatusOK:
703 aShape = aScene.GetShape(aShapeAppMap);
706 case VrmlData_EmptyData: aStr = "EmptyData"; break;
707 case VrmlData_UnrecoverableError: aStr = "UnrecoverableError"; break;
708 case VrmlData_GeneralError: aStr = "GeneralError"; break;
709 case VrmlData_EndOfFile: aStr = "EndOfFile"; break;
710 case VrmlData_NotVrmlFile: aStr = "NotVrmlFile"; break;
711 case VrmlData_CannotOpenFile: aStr = "CannotOpenFile"; break;
712 case VrmlData_VrmlFormatError: aStr = "VrmlFormatError"; break;
713 case VrmlData_NumericInputError: aStr = "NumericInputError"; break;
714 case VrmlData_IrrelevantNumber: aStr = "IrrelevantNumber"; break;
715 case VrmlData_BooleanInputError: aStr = "BooleanInputError"; break;
716 case VrmlData_StringInputError: aStr = "StringInputError"; break;
717 case VrmlData_NodeNameUnknown: aStr = "NodeNameUnknown"; break;
718 case VrmlData_NonPositiveSize: aStr = "NonPositiveSize"; break;
719 case VrmlData_ReadUnknownNode: aStr = "ReadUnknownNode"; break;
720 case VrmlData_NonSupportedFeature: aStr = "NonSupportedFeature"; break;
721 case VrmlData_OutputStreamUndefined:aStr = "OutputStreamUndefined"; break;
722 case VrmlData_NotImplemented: aStr = "NotImplemented"; break;
727 di << " ++ VRML Error: " << aStr << " in line "
728 << aScene.GetLineError() << "\n";
731 DBRep::Set(argv[1],aShape);
735 di << "cannot open file\n";
739 //-----------------------------------------------------------
744 //-----------------------------------------------------------------------------
745 static Standard_Integer createmesh
746 (Draw_Interpretor& di, Standard_Integer argc, const char** argv )
750 di << "Wrong number of parameters\n";
751 di << "Use: " << argv[0] << " <mesh name> <stl file>\n";
755 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
756 if (aContext.IsNull())
758 di << "No active view. Please call 'vinit' first\n";
762 // Progress indicator
763 OSD_Path aFile( argv[2] );
764 Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator (di, 1);
765 Handle(Poly_Triangulation) aSTLMesh = RWStl::ReadFile (aFile, aProgress);
767 di << "Reading OK...\n";
768 Handle( XSDRAWSTLVRML_DataSource ) aDS = new XSDRAWSTLVRML_DataSource( aSTLMesh );
769 di << "Data source is created successful\n";
770 Handle( MeshVS_Mesh ) aMesh = new MeshVS_Mesh();
771 di << "MeshVS_Mesh is created successful\n";
773 aMesh->SetDataSource( aDS );
774 aMesh->AddBuilder( new MeshVS_MeshPrsBuilder( aMesh.operator->() ), Standard_True );
776 aMesh->GetDrawer()->SetColor( MeshVS_DA_EdgeColor, Quantity_NOC_YELLOW );
778 // Hide all nodes by default
779 Handle(TColStd_HPackedMapOfInteger) aNodes = new TColStd_HPackedMapOfInteger();
780 Standard_Integer aLen = aSTLMesh->Nodes().Length();
781 for ( Standard_Integer anIndex = 1; anIndex <= aLen; anIndex++ )
782 aNodes->ChangeMap().Add( anIndex );
783 aMesh->SetHiddenNodes( aNodes );
784 aMesh->SetSelectableNodes ( aNodes );
786 VDisplayAISObject(argv[1], aMesh);
787 aContext->Deactivate( aMesh );
789 Draw::Set( argv[1], new XSDRAWSTLVRML_DrawableMesh( aMesh ) );
790 Handle( V3d_View ) aView = ViewerTest::CurrentView();
791 if ( !aView.IsNull() )
796 //-----------------------------------------------------------------------------
798 static Standard_Integer create3d
799 (Draw_Interpretor& di, Standard_Integer argc, const char** argv )
803 di << "Wrong number of parameters\n";
804 di << "Use: " << argv[0] << " <mesh name>\n";
808 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
809 if (aContext.IsNull())
811 di << "No active view. Please call 'vinit' first\n";
815 Handle( XSDRAWSTLVRML_DataSource3D ) aDS = new XSDRAWSTLVRML_DataSource3D();
816 di << "Data source is created successful\n";
817 Handle( MeshVS_Mesh ) aMesh = new MeshVS_Mesh();
818 di << "MeshVS_Mesh is created successful\n";
820 aMesh->SetDataSource( aDS );
821 aMesh->AddBuilder( new MeshVS_MeshPrsBuilder( aMesh.operator->() ), Standard_True );
823 aMesh->GetDrawer()->SetColor( MeshVS_DA_EdgeColor, Quantity_NOC_YELLOW );
825 // Hide all nodes by default
826 Handle(TColStd_HPackedMapOfInteger) aNodes = new TColStd_HPackedMapOfInteger();
827 Standard_Integer aLen = aDS->GetAllNodes().Extent();
828 for ( Standard_Integer anIndex = 1; anIndex <= aLen; anIndex++ )
829 aNodes->ChangeMap().Add( anIndex );
830 aMesh->SetHiddenNodes( aNodes );
831 aMesh->SetSelectableNodes ( aNodes );
833 VDisplayAISObject(argv[1], aMesh);
834 aContext->Deactivate( aMesh );
836 Draw::Set( argv[1], new XSDRAWSTLVRML_DrawableMesh( aMesh ) );
837 Handle( V3d_View ) aView = ViewerTest::CurrentView();
838 if ( !aView.IsNull() )
844 Handle( MeshVS_Mesh ) getMesh( const char* theName, Draw_Interpretor& di)
846 Handle( XSDRAWSTLVRML_DrawableMesh ) aDrawMesh =
847 Handle( XSDRAWSTLVRML_DrawableMesh )::DownCast( Draw::Get( theName ) );
849 if( aDrawMesh.IsNull() )
851 di << "There is no such object\n";
856 Handle( MeshVS_Mesh ) aMesh = aDrawMesh->GetMesh();
859 di << "There is invalid mesh\n";
867 //-----------------------------------------------------------------------------
868 static Standard_Integer setcolor
869 (Draw_Interpretor& di, Standard_Integer argc, const char** argv, Standard_Integer theParam )
872 di << "Wrong number of parameters\n";
875 Handle( MeshVS_Mesh ) aMesh = getMesh( argv[1], di );
876 if( !aMesh.IsNull() )
878 Standard_Real aRed = Draw::Atof (argv[2]);
879 Standard_Real aGreen = Draw::Atof (argv[3]);
880 Standard_Real aBlue = Draw::Atof (argv[4]);
881 aMesh->GetDrawer()->SetColor( (MeshVS_DrawerAttribute)theParam,
882 Quantity_Color( aRed, aGreen, aBlue, Quantity_TOC_RGB ) );
884 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
886 if( aContext.IsNull() )
887 di << "The context is null\n";
889 aContext->Redisplay (aMesh, Standard_True);
894 //-----------------------------------------------------------------------------
895 static Standard_Integer meshcolor
896 (Draw_Interpretor& theInterp, Standard_Integer argc, const char** argv )
898 return setcolor( theInterp, argc, argv, MeshVS_DA_InteriorColor );
900 //-----------------------------------------------------------------------------
901 static Standard_Integer linecolor
902 (Draw_Interpretor& theInterp, Standard_Integer argc, const char** argv )
904 return setcolor( theInterp, argc, argv, MeshVS_DA_EdgeColor );
906 //-----------------------------------------------------------------------------
907 static Standard_Integer meshmat
908 (Draw_Interpretor& di, Standard_Integer argc, const char** argv )
911 di << "Wrong number of parameters\n";
914 Handle( MeshVS_Mesh ) aMesh = getMesh( argv[1], di );
915 if( !aMesh.IsNull() )
917 Standard_Integer aMaterial = Draw::Atoi (argv[2]);
919 Graphic3d_MaterialAspect aMatAsp =
920 (Graphic3d_MaterialAspect)(Graphic3d_NameOfMaterial)aMaterial;
924 Standard_Real aTransparency = Draw::Atof(argv[3]);
925 aMatAsp.SetTransparency (Standard_ShortReal (aTransparency));
927 aMesh->GetDrawer()->SetMaterial( MeshVS_DA_FrontMaterial, aMatAsp );
928 aMesh->GetDrawer()->SetMaterial( MeshVS_DA_BackMaterial, aMatAsp );
930 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
932 if( aContext.IsNull() )
933 di << "The context is null\n";
935 aContext->Redisplay (aMesh, Standard_True);
940 //-----------------------------------------------------------------------------
941 static Standard_Integer shrink
942 (Draw_Interpretor& di, Standard_Integer argc, const char** argv )
945 di << "Wrong number of parameters\n";
948 Handle( MeshVS_Mesh ) aMesh = getMesh( argv[1], di );
949 if( !aMesh.IsNull() )
951 Standard_Real aShrinkCoeff = Draw::Atof (argv[2]);
952 aMesh->GetDrawer()->SetDouble( MeshVS_DA_ShrinkCoeff, aShrinkCoeff );
954 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
956 if( aContext.IsNull() )
957 di << "The context is null\n";
959 aContext->Redisplay (aMesh, Standard_True);
965 //-----------------------------------------------------------------------------
966 static Standard_Integer closed (Draw_Interpretor& theDI, Standard_Integer theArgc, const char** theArgv)
970 theDI << "Wrong number of parameters.\n";
974 Handle(MeshVS_Mesh) aMesh = getMesh (theArgv[1], theDI);
977 Standard_Boolean aFlag = Draw::Atoi (theArgv[2]) != 0;
978 aMesh->GetDrawer()->SetBoolean (MeshVS_DA_SupressBackFaces, aFlag);
980 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
981 if (aContext.IsNull())
983 theDI << "The context is null\n";
987 aContext->Redisplay (aMesh, Standard_True);
994 //-----------------------------------------------------------------------------
996 static Standard_Integer mdisplay
997 (Draw_Interpretor& di, Standard_Integer argc, const char** argv )
1000 di << "Wrong number of parameters\n";
1003 Handle( MeshVS_Mesh ) aMesh = getMesh( argv[1], di );
1004 if( !aMesh.IsNull() )
1006 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
1008 if( aContext.IsNull() )
1009 di << "The context is null\n";
1012 aContext->Display (aMesh, Standard_True);
1018 //-----------------------------------------------------------------------------
1019 static Standard_Integer merase
1020 (Draw_Interpretor& di, Standard_Integer argc, const char** argv )
1023 di << "Wrong number of parameters\n";
1026 Handle( MeshVS_Mesh ) aMesh = getMesh( argv[1], di );
1027 if( !aMesh.IsNull() )
1029 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
1031 if( aContext.IsNull() )
1032 di << "The context is null\n";
1035 aContext->Erase (aMesh, Standard_True);
1039 di << "Mesh is null\n";
1043 //-----------------------------------------------------------------------------
1044 static Standard_Integer hidesel
1045 (Draw_Interpretor& di, Standard_Integer argc, const char** argv )
1049 di << "Wrong number of parameters\n";
1050 di << "Use: " << argv[0] << " <mesh name>\n";
1054 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
1055 Handle( MeshVS_Mesh ) aMesh = getMesh( argv[1], di );
1056 if( aMesh.IsNull() )
1058 di << "The mesh is invalid\n";
1062 if( aContext.IsNull() )
1063 di << "The context is null\n";
1066 Handle(TColStd_HPackedMapOfInteger) aHiddenNodes = aMesh->GetHiddenNodes();
1067 if (aHiddenNodes.IsNull())
1069 aHiddenNodes = new TColStd_HPackedMapOfInteger();
1071 Handle(TColStd_HPackedMapOfInteger) aHiddenElements = aMesh->GetHiddenElems();
1072 if (aHiddenElements.IsNull())
1074 aHiddenElements = new TColStd_HPackedMapOfInteger();
1076 for( aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected() )
1078 Handle( MeshVS_MeshEntityOwner ) anOwner =
1079 Handle( MeshVS_MeshEntityOwner )::DownCast( aContext->SelectedOwner() );
1080 if( !anOwner.IsNull() )
1082 if( anOwner->Type()==MeshVS_ET_Node )
1084 aHiddenNodes->ChangeMap().Add( anOwner->ID() );
1088 aHiddenElements->ChangeMap().Add( anOwner->ID() );
1092 aContext->ClearSelected (Standard_False);
1093 aMesh->SetHiddenNodes( aHiddenNodes );
1094 aMesh->SetHiddenElems( aHiddenElements );
1095 aContext->Redisplay (aMesh, Standard_True);
1100 //-----------------------------------------------------------------------------
1101 static Standard_Integer showonly
1102 (Draw_Interpretor& di, Standard_Integer argc, const char** argv )
1106 di << "Wrong number of parameters\n";
1107 di << "Use: " << argv[0] << " <mesh name>\n";
1112 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
1113 Handle( MeshVS_Mesh ) aMesh = getMesh( argv[1], di );
1114 if( aMesh.IsNull() )
1116 di << "The mesh is invalid\n";
1120 if( aContext.IsNull() )
1121 di << "The context is null\n";
1124 Handle(TColStd_HPackedMapOfInteger) aHiddenNodes =
1125 new TColStd_HPackedMapOfInteger(aMesh->GetDataSource()->GetAllNodes());
1126 Handle(TColStd_HPackedMapOfInteger) aHiddenElements =
1127 new TColStd_HPackedMapOfInteger(aMesh->GetDataSource()->GetAllElements());
1128 for( aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected() )
1130 Handle( MeshVS_MeshEntityOwner ) anOwner =
1131 Handle( MeshVS_MeshEntityOwner )::DownCast( aContext->SelectedOwner() );
1132 if( !anOwner.IsNull() )
1134 if( anOwner->Type() == MeshVS_ET_Node )
1136 aHiddenNodes->ChangeMap().Remove( anOwner->ID() );
1140 aHiddenElements->ChangeMap().Remove( anOwner->ID() );
1144 aMesh->SetHiddenNodes( aHiddenNodes );
1145 aMesh->SetHiddenElems( aHiddenElements );
1146 aContext->Redisplay (aMesh, Standard_True);
1151 //-----------------------------------------------------------------------------
1152 static Standard_Integer showall
1153 (Draw_Interpretor& di, Standard_Integer argc, const char** argv )
1157 di << "Wrong number of parameters\n";
1158 di << "Use: " << argv[0] << " <mesh name>\n";
1162 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
1163 Handle( MeshVS_Mesh ) aMesh = getMesh( argv[1], di );
1164 if( aMesh.IsNull() )
1166 di << "The mesh is invalid\n";
1170 if( aContext.IsNull() )
1171 di << "The context is null\n";
1174 aMesh->SetHiddenNodes( new TColStd_HPackedMapOfInteger() );
1175 aMesh->SetHiddenElems( new TColStd_HPackedMapOfInteger() );
1176 aContext->Redisplay (aMesh, Standard_True);
1182 //-----------------------------------------------------------------------------
1183 static Standard_Integer meshcolors( Draw_Interpretor& di,
1184 Standard_Integer argc,
1192 di << "Wrong number of parameters\n";
1193 di << "Use : meshcolors <mesh name> <mode> <isreflect>\n";
1194 di << "mode : {elem1|elem2|nodal|nodaltex|none}\n";
1195 di << " elem1 - different color for each element\n";
1196 di << " elem2 - one color for one side\n";
1197 di << " nodal - different color for each node\n";
1198 di << " nodaltex - different color for each node with texture interpolation\n";
1199 di << " none - clear\n";
1200 di << "isreflect : {0|1} \n";
1205 Handle( MeshVS_Mesh ) aMesh = getMesh( argv[ 1 ], di );
1207 if ( aMesh.IsNull() )
1209 di << "Mesh not found\n";
1212 Handle(AIS_InteractiveContext) anIC = ViewerTest::GetAISContext();
1213 if ( anIC.IsNull() )
1215 di << "The context is null\n";
1218 if( !aMesh.IsNull() )
1220 TCollection_AsciiString aMode = TCollection_AsciiString (argv[2]);
1221 Quantity_Color aColor1(Quantity_NOC_BLUE1);
1222 Quantity_Color aColor2(Quantity_NOC_RED1);
1223 if( aMode.IsEqual("elem1") || aMode.IsEqual("elem2") || aMode.IsEqual("nodal") || aMode.IsEqual("nodaltex") || aMode.IsEqual("none") )
1225 Handle(MeshVS_PrsBuilder) aTempBuilder;
1226 Standard_Integer aReflection = Draw::Atoi(argv[3]);
1228 for (Standard_Integer aCount = 0 ; aCount < aMesh->GetBuildersCount(); aCount++ ){
1229 aTempBuilder = aMesh->FindBuilder("MeshVS_ElementalColorPrsBuilder");
1230 if( !aTempBuilder.IsNull())
1231 aMesh->RemoveBuilderById(aTempBuilder->GetId());
1233 aTempBuilder = aMesh->FindBuilder("MeshVS_NodalColorPrsBuilder");
1234 if( !aTempBuilder.IsNull())
1235 aMesh->RemoveBuilderById(aTempBuilder->GetId());
1238 if( aMode.IsEqual("elem1") || aMode.IsEqual("elem2") )
1240 Handle(MeshVS_ElementalColorPrsBuilder) aBuilder = new MeshVS_ElementalColorPrsBuilder(
1241 aMesh, MeshVS_DMF_ElementalColorDataPrs | MeshVS_DMF_OCCMask );
1243 const TColStd_PackedMapOfInteger& anAllElements = aMesh->GetDataSource()->GetAllElements();
1244 TColStd_MapIteratorOfPackedMapOfInteger anIter( anAllElements );
1246 if( aMode.IsEqual("elem1") )
1247 for ( ; anIter.More(); anIter.Next() )
1249 Quantity_Color aColor( (Quantity_NameOfColor)( anIter.Key() % Quantity_NOC_WHITE ) );
1250 aBuilder->SetColor1( anIter.Key(), aColor );
1253 for ( ; anIter.More(); anIter.Next() )
1254 aBuilder->SetColor2( anIter.Key(), aColor1, aColor2 );
1256 aMesh->AddBuilder( aBuilder, Standard_True );
1260 if( aMode.IsEqual("nodal") )
1262 Handle(MeshVS_NodalColorPrsBuilder) aBuilder = new MeshVS_NodalColorPrsBuilder(
1263 aMesh, MeshVS_DMF_NodalColorDataPrs | MeshVS_DMF_OCCMask );
1264 aMesh->AddBuilder( aBuilder, Standard_True );
1267 const TColStd_PackedMapOfInteger& anAllNodes =
1268 aMesh->GetDataSource()->GetAllNodes();
1269 TColStd_MapIteratorOfPackedMapOfInteger anIter( anAllNodes );
1270 for ( ; anIter.More(); anIter.Next() )
1272 Quantity_Color aColor( (Quantity_NameOfColor)(
1273 anIter.Key() % Quantity_NOC_WHITE ) );
1274 aBuilder->SetColor( anIter.Key(), aColor );
1276 aMesh->AddBuilder( aBuilder, Standard_True );
1279 if(aMode.IsEqual("nodaltex"))
1281 // assign nodal builder to the mesh
1282 Handle(MeshVS_NodalColorPrsBuilder) aBuilder = new MeshVS_NodalColorPrsBuilder(
1283 aMesh, MeshVS_DMF_NodalColorDataPrs | MeshVS_DMF_OCCMask);
1284 aMesh->AddBuilder(aBuilder, Standard_True);
1285 aBuilder->UseTexture(Standard_True);
1287 // prepare color map for texture
1288 Aspect_SequenceOfColor aColorMap;
1289 aColorMap.Append((Quantity_NameOfColor) Quantity_NOC_RED);
1290 aColorMap.Append((Quantity_NameOfColor) Quantity_NOC_YELLOW);
1291 aColorMap.Append((Quantity_NameOfColor) Quantity_NOC_BLUE1);
1293 // prepare scale map for mesh - it will be assigned to mesh as texture coordinates
1294 // make mesh color interpolated from minimum X coord to maximum X coord
1295 Handle(MeshVS_DataSource) aDataSource = aMesh->GetDataSource();
1296 Standard_Real aMinX, aMinY, aMinZ, aMaxX, aMaxY, aMaxZ;
1298 // get bounding box for calculations
1299 aDataSource->GetBoundingBox().Get(aMinX, aMinY, aMinZ, aMaxX, aMaxY, aMaxZ);
1300 Standard_Real aDelta = aMaxX - aMinX;
1302 // assign color scale map values (0..1) to nodes
1303 TColStd_DataMapOfIntegerReal aScaleMap;
1304 TColStd_Array1OfReal aCoords(1, 3);
1305 Standard_Integer aNbNodes;
1306 MeshVS_EntityType aType;
1309 const TColStd_PackedMapOfInteger& anAllNodes =
1310 aMesh->GetDataSource()->GetAllNodes();
1311 TColStd_MapIteratorOfPackedMapOfInteger anIter(anAllNodes);
1312 for (; anIter.More(); anIter.Next())
1314 //get node coordinates to aCoord variable
1315 aDataSource->GetGeom(anIter.Key(), Standard_False, aCoords, aNbNodes, aType);
1317 Standard_Real aScaleValue;
1320 aScaleValue = (aCoords.Value(1) - (Standard_Real) aMinX) / aDelta;
1321 } catch(Standard_Failure const&) {
1325 aScaleMap.Bind(anIter.Key(), aScaleValue);
1328 //set color map for builder and a color for invalid scale value
1329 aBuilder->SetColorMap(aColorMap);
1330 aBuilder->SetInvalidColor(Quantity_NOC_BLACK);
1331 aBuilder->SetTextureCoords(aScaleMap);
1332 aMesh->AddBuilder(aBuilder, Standard_True);
1335 aMesh->GetDrawer()->SetBoolean (MeshVS_DA_ColorReflection, aReflection != 0);
1337 anIC->Redisplay (aMesh, Standard_True);
1341 di << "Wrong mode name\n";
1346 catch ( Standard_Failure const& )
1353 //-----------------------------------------------------------------------------
1354 static Standard_Integer meshvectors( Draw_Interpretor& di,
1355 Standard_Integer argc,
1360 di << "Wrong number of parameters\n";
1361 di << "Use : meshvectors <mesh name> < -mode {elem|nodal|none} > [-maxlen len] [-color name] [-arrowpart ratio] [-issimple {1|0}]\n";
1362 di << "Supported mode values:\n";
1363 di << " elem - vector per element\n";
1364 di << " nodal - vector per node\n";
1365 di << " none - clear\n";
1370 Handle( MeshVS_Mesh ) aMesh = getMesh( argv[ 1 ], di );
1372 if ( aMesh.IsNull() )
1374 di << "Mesh not found\n";
1377 Handle(AIS_InteractiveContext) anIC = ViewerTest::GetAISContext();
1378 if ( anIC.IsNull() )
1380 di << "The context is null\n";
1384 TCollection_AsciiString aParam;
1385 TCollection_AsciiString aMode("none");
1386 Standard_Real aMaxlen(1.0);
1387 Quantity_Color aColor(Quantity_NOC_ORANGE);
1388 Standard_Real anArrowPart(0.1);
1389 Standard_Boolean isSimplePrs(Standard_False);
1391 for (Standard_Integer anIdx = 2; anIdx < argc; anIdx++)
1393 if (!aParam.IsEmpty())
1395 if (aParam == "-mode")
1397 aMode = argv[anIdx];
1399 else if (aParam == "-maxlen")
1401 aMaxlen = Draw::Atof(argv[anIdx]);
1403 else if (aParam == "-color")
1405 aColor = ViewerTest::GetColorFromName(argv[anIdx]);
1407 else if (aParam == "-arrowpart")
1409 anArrowPart = Draw::Atof(argv[anIdx]);
1411 else if (aParam == "-issimple")
1413 isSimplePrs = Draw::Atoi(argv[anIdx]) != 0;
1417 else if (argv[anIdx][0] == '-')
1419 aParam = argv[anIdx];
1423 if( !aMode.IsEqual("elem") && !aMode.IsEqual("nodal") && !aMode.IsEqual("none") )
1425 di << "Wrong mode name\n";
1429 Handle(MeshVS_PrsBuilder) aTempBuilder;
1431 aTempBuilder = aMesh->FindBuilder("MeshVS_VectorPrsBuilder");
1432 if( !aTempBuilder.IsNull())
1433 aMesh->RemoveBuilderById(aTempBuilder->GetId());
1435 if( !aMode.IsEqual("none") )
1437 Handle(MeshVS_VectorPrsBuilder) aBuilder = new MeshVS_VectorPrsBuilder( aMesh.operator->(),
1440 MeshVS_DMF_VectorDataPrs,
1446 Standard_Boolean anIsElement = aMode.IsEqual("elem");
1447 const TColStd_PackedMapOfInteger& anAllIDs = anIsElement ? aMesh->GetDataSource()->GetAllElements() :
1448 aMesh->GetDataSource()->GetAllNodes();
1450 Standard_Integer aNbNodes;
1451 MeshVS_EntityType aEntType;
1453 TColStd_Array1OfReal aCoords(1, 3);
1455 TColStd_MapIteratorOfPackedMapOfInteger anIter( anAllIDs );
1456 for ( ; anIter.More(); anIter.Next() )
1458 Standard_Boolean IsValidData = Standard_False;
1460 aMesh->GetDataSource()->GetGeomType(anIter.Key(), anIsElement, aEntType);
1461 if (aEntType == MeshVS_ET_Face)
1462 IsValidData = aMesh->GetDataSource()->GetNormal(anIter.Key(), 3, aCoords.ChangeValue(1), aCoords.ChangeValue(2), aCoords.ChangeValue(3));
1464 IsValidData = aMesh->GetDataSource()->GetGeom(anIter.Key(), Standard_False, aCoords, aNbNodes, aEntType);
1469 aNorm = gp_Vec(aCoords.Value(1), aCoords.Value(2), aCoords.Value(3));
1470 if(aNorm.Magnitude() < gp::Resolution())
1472 aNorm = gp_Vec(0,0,1); //method GetGeom(...) returns coordinates of nodes
1477 aNorm = gp_Vec(0,0,1);
1479 aBuilder->SetVector(anIsElement, anIter.Key(), aNorm.Normalized());
1482 aMesh->AddBuilder( aBuilder, Standard_False );
1483 aMesh->GetDrawer()->SetDouble ( MeshVS_DA_VectorArrowPart, anArrowPart );
1486 anIC->Redisplay (aMesh, Standard_True);
1490 //-----------------------------------------------------------------------------
1492 static Standard_Integer meshtext( Draw_Interpretor& di,
1493 Standard_Integer argc,
1498 di << "Wrong number of parameters\n";
1499 di << "Use : meshtext <mesh name>\n";
1503 Handle( MeshVS_Mesh ) aMesh = getMesh( argv[ 1 ], di );
1505 if ( aMesh.IsNull() )
1507 di << "Mesh not found\n";
1511 Handle(AIS_InteractiveContext) anIC = ViewerTest::GetAISContext();
1512 if ( anIC.IsNull() )
1514 di << "The context is null\n";
1518 // Prepare triangle labels
1519 MeshVS_DataMapOfIntegerAsciiString aLabels;
1520 Standard_Integer aLen = aMesh->GetDataSource()->GetAllElements().Extent();
1521 for ( Standard_Integer anIndex = 1; anIndex <= aLen; anIndex++ ){
1522 aLabels.Bind( anIndex, TCollection_AsciiString( anIndex ) );
1525 Handle(MeshVS_TextPrsBuilder) aTextBuilder = new MeshVS_TextPrsBuilder( aMesh.operator->(), 20., Quantity_NOC_YELLOW );
1526 aTextBuilder->SetTexts( Standard_True, aLabels );
1527 aMesh->AddBuilder( aTextBuilder );
1532 static Standard_Integer meshdeform( Draw_Interpretor& di,
1533 Standard_Integer argc,
1538 di << "Wrong number of parameters\n";
1539 di << "Use : meshdeform <mesh name> < -mode {on|off} > [-scale scalefactor]\n";
1543 Handle( MeshVS_Mesh ) aMesh = getMesh( argv[ 1 ], di );
1545 if ( aMesh.IsNull() )
1547 di << "Mesh not found\n";
1550 Handle(AIS_InteractiveContext) anIC = ViewerTest::GetAISContext();
1551 if ( anIC.IsNull() )
1553 di << "The context is null\n";
1557 TCollection_AsciiString aParam;
1558 TCollection_AsciiString aMode("off");
1559 Standard_Real aScale(1.0);
1561 for (Standard_Integer anIdx = 2; anIdx < argc; anIdx++)
1563 if (!aParam.IsEmpty())
1565 if (aParam == "-mode")
1567 aMode = argv[anIdx];
1569 else if (aParam == "-scale")
1571 aScale = Draw::Atof(argv[anIdx]);
1575 else if (argv[anIdx][0] == '-')
1577 aParam = argv[anIdx];
1581 if(!aMode.IsEqual("on") && !aMode.IsEqual("off"))
1583 di << "Wrong mode name\n";
1587 Handle ( MeshVS_DeformedDataSource ) aDefDS =
1588 new MeshVS_DeformedDataSource( aMesh->GetDataSource() , aScale );
1590 const TColStd_PackedMapOfInteger& anAllIDs = aMesh->GetDataSource()->GetAllNodes();
1592 Standard_Integer aNbNodes;
1593 MeshVS_EntityType aEntType;
1595 TColStd_MapIteratorOfPackedMapOfInteger anIter( anAllIDs );
1596 for ( ; anIter.More(); anIter.Next() )
1598 TColStd_Array1OfReal aCoords(1, 3);
1599 aMesh->GetDataSource()->GetGeom(anIter.Key(), Standard_False, aCoords, aNbNodes, aEntType);
1601 gp_Vec aNorm = gp_Vec(aCoords.Value(1), aCoords.Value(2), aCoords.Value(3));
1602 if( !aNorm.Magnitude() )
1603 aNorm = gp_Vec(0,0,1);
1604 aDefDS->SetVector(anIter.Key(), aNorm.Normalized());
1607 aMesh->SetDataSource(aDefDS);
1609 anIC->Redisplay (aMesh, Standard_False);
1611 Handle( V3d_View ) aView = ViewerTest::CurrentView();
1612 if ( !aView.IsNull() )
1618 static Standard_Integer mesh_edge_width( Draw_Interpretor& di,
1619 Standard_Integer argc,
1627 di << "Wrong number of parameters\n";
1628 di << "Use : mesh_edge_width <mesh name> <width>\n";
1632 Handle(MeshVS_Mesh) aMesh = getMesh( argv[ 1 ], di );
1633 if ( aMesh.IsNull() )
1635 di << "Mesh not found\n";
1639 const char* aWidthStr = argv[ 2 ];
1640 if ( aWidthStr == 0 || Draw::Atof( aWidthStr ) <= 0 )
1642 di << "Width must be real value more than zero\n";
1646 double aWidth = Draw::Atof( aWidthStr );
1648 Handle(AIS_InteractiveContext) anIC = ViewerTest::GetAISContext();
1649 if ( anIC.IsNull() )
1651 di << "The context is null\n";
1655 Handle(MeshVS_Drawer) aDrawer = aMesh->GetDrawer();
1656 if ( aDrawer.IsNull() )
1658 di << "The drawer is null\n";
1662 aDrawer->SetDouble( MeshVS_DA_EdgeWidth, aWidth );
1663 anIC->Redisplay (aMesh, Standard_True);
1665 catch ( Standard_Failure const& )
1673 //-----------------------------------------------------------------------------
1675 static Standard_Integer meshinfo(Draw_Interpretor& di,
1676 Standard_Integer argc,
1681 di << "Wrong number of parameters. Use : meshinfo mesh\n";
1685 Handle(MeshVS_Mesh) aMesh = getMesh(argv[ 1 ], di);
1686 if ( aMesh.IsNull() )
1688 di << "Mesh not found\n";
1692 Handle(XSDRAWSTLVRML_DataSource) stlMeshSource = Handle(XSDRAWSTLVRML_DataSource)::DownCast(aMesh->GetDataSource());
1693 if (!stlMeshSource.IsNull())
1695 const TColStd_PackedMapOfInteger& nodes = stlMeshSource->GetAllNodes();
1696 const TColStd_PackedMapOfInteger& tris = stlMeshSource->GetAllElements();
1698 di << "Nb nodes = " << nodes.Extent() << "\n";
1699 di << "Nb triangles = " << tris.Extent() << "\n";
1705 //-----------------------------------------------------------------------------
1707 void XSDRAWSTLVRML::InitCommands (Draw_Interpretor& theCommands)
1709 const char* g = "XSTEP-STL/VRML"; // Step transfer file commands
1710 //XSDRAW::LoadDraw(theCommands);
1712 theCommands.Add ("ReadGltf",
1713 "ReadGltf Doc file [-parallel {on|off}] [-listExternalFiles] [-noCreateDoc]"
1714 "\n\t\t: Read glTF file into XDE document."
1715 "\n\t\t: -listExternalFiles do not read mesh and only list external files"
1716 "\n\t\t: -noCreateDoc read into existing XDE document",
1717 __FILE__, ReadGltf, g);
1718 theCommands.Add ("readgltf",
1719 "readgltf shape file"
1720 "\n\t\t: Same as ReadGltf but reads glTF file into a shape instead of a document.",
1721 __FILE__, ReadGltf, g);
1722 theCommands.Add ("WriteGltf",
1723 "WriteGltf Doc file [-trsfFormat {compact|TRS|mat4}=compact] [-comments Text] [-author Name] [-forceUVExport]"
1724 "\n\t\t: Write XDE document into glTF file."
1725 "\n\t\t: -trsfFormat preferred transformation format"
1726 "\n\t\t: -forceUVExport always export UV coordinates",
1727 __FILE__, WriteGltf, g);
1728 theCommands.Add ("writegltf",
1729 "writegltf shape file",
1730 __FILE__, WriteGltf, g);
1731 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);
1732 theCommands.Add ("writestl", "shape file [ascii/binary (0/1) : 1 by default] [InParallel (0/1) : 0 by default]",__FILE__,writestl,g);
1733 theCommands.Add ("readstl",
1734 "readstl shape file [-brep]"
1735 "\n\t\t: Reads STL file and creates a new shape with specified name."
1736 "\n\t\t: When -brep is specified, creates a Compound of per-triangle Faces."
1737 "\n\t\t: Single triangulation-only Face is created otherwise (default).",
1738 __FILE__, readstl, g);
1739 theCommands.Add ("loadvrml" , "shape file",__FILE__,loadvrml,g);
1740 theCommands.Add ("ReadObj",
1741 "ReadObj Doc file [-fileCoordSys {Zup|Yup}] [-fileUnit Unit]"
1742 "\n\t\t: [-resultCoordSys {Zup|Yup}] [-singlePrecision]"
1743 "\n\t\t: [-listExternalFiles] [-noCreateDoc]"
1744 "\n\t\t: Read OBJ file into XDE document."
1745 "\n\t\t: -fileUnit length unit of OBJ file content;"
1746 "\n\t\t: -fileCoordSys coordinate system defined by OBJ file; Yup when not specified."
1747 "\n\t\t: -resultCoordSys result coordinate system; Zup when not specified."
1748 "\n\t\t: -singlePrecision truncate vertex data to single precision during read; FALSE by default."
1749 "\n\t\t: -listExternalFiles do not read mesh and only list external files."
1750 "\n\t\t: -noCreateDoc read into existing XDE document.",
1751 __FILE__, ReadObj, g);
1752 theCommands.Add ("readobj",
1753 "readobj shape file [-fileCoordSys {Zup|Yup}] [-fileUnit Unit]"
1754 "\n\t\t: [-resultCoordSys {Zup|Yup}] [-singlePrecision]"
1755 "\n\t\t: [-singleFace]"
1756 "\n\t\t: Same as ReadObj but reads OBJ file into a shape instead of a document."
1757 "\n\t\t: -singleFace merge OBJ content into a single triangulation Face.",
1758 __FILE__, ReadObj, g);
1760 theCommands.Add ("meshfromstl", "creates MeshVS_Mesh from STL file", __FILE__, createmesh, g );
1761 theCommands.Add ("mesh3delem", "creates 3d element mesh to test", __FILE__, create3d, g );
1762 theCommands.Add ("meshshadcolor", "change MeshVS_Mesh shading color", __FILE__, meshcolor, g );
1763 theCommands.Add ("meshlinkcolor", "change MeshVS_Mesh line color", __FILE__, linecolor, g );
1764 theCommands.Add ("meshmat", "change MeshVS_Mesh material and transparency", __FILE__, meshmat, g );
1765 theCommands.Add ("meshshrcoef", "change MeshVS_Mesh shrink coeff", __FILE__, shrink, g );
1766 theCommands.Add ("meshclosed", "meshclosed meshname (0/1) \nChange MeshVS_Mesh drawing mode. 0 - not closed object, 1 - closed object", __FILE__, closed, g);
1767 theCommands.Add ("meshshow", "display MeshVS_Mesh object", __FILE__, mdisplay, g );
1768 theCommands.Add ("meshhide", "erase MeshVS_Mesh object", __FILE__, merase, g );
1769 theCommands.Add ("meshhidesel", "hide selected entities", __FILE__, hidesel, g );
1770 theCommands.Add ("meshshowsel", "show only selected entities", __FILE__, showonly, g );
1771 theCommands.Add ("meshshowall", "show all entities", __FILE__, showall, g );
1772 theCommands.Add ("meshcolors", "display color presentation", __FILE__, meshcolors, g );
1773 theCommands.Add ("meshvectors", "display sample vectors", __FILE__, meshvectors, g );
1774 theCommands.Add ("meshtext", "display text labels", __FILE__, meshtext, g );
1775 theCommands.Add ("meshdeform", "display deformed mesh", __FILE__, meshdeform, g );
1776 theCommands.Add ("mesh_edge_width", "set width of edges", __FILE__, mesh_edge_width, g );
1777 theCommands.Add ("meshinfo", "displays the number of nodes and triangles", __FILE__, meshinfo, g );
1780 //==============================================================================
1781 // XSDRAWSTLVRML::Factory
1782 //==============================================================================
1783 void XSDRAWSTLVRML::Factory(Draw_Interpretor& theDI)
1785 XSDRAWIGES::InitSelect();
1786 XSDRAWIGES::InitToBRep(theDI);
1787 XSDRAWIGES::InitFromBRep(theDI);
1788 XSDRAWSTEP::InitCommands(theDI);
1789 XSDRAWSTLVRML::InitCommands(theDI);
1790 XSDRAW::LoadDraw(theDI);
1792 theDI << "Draw Plugin : All TKXSDRAW commands are loaded\n";
1796 // Declare entry point PLUGINFACTORY
1797 DPLUGIN(XSDRAWSTLVRML)