3ba85b230f4fa63ce800b29ef4a15041886557bf
[occt.git] / src / XSDRAWSTLVRML / XSDRAWSTLVRML.cxx
1 // Created on: 2000-05-30
2 // Created by: Sergey MOZOKHIN
3 // Copyright (c) 2000-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16
17 #include <AIS_InteractiveContext.hxx>
18 #include <Aspect_TypeOfMarker.hxx>
19 #include <Bnd_Box.hxx>
20 #include <BRep_Builder.hxx>
21 #include <DBRep.hxx>
22 #include <DDocStd.hxx>
23 #include <DDocStd_DrawDocument.hxx>
24 #include <Draw.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>
47 #include <RWStl.hxx>
48 #include <RWObj.hxx>
49 #include <RWObj_CafReader.hxx>
50 #include <SelectMgr_SelectionManager.hxx>
51 #include <Standard_ErrorHandler.hxx>
52 #include <StdSelect_ViewerSelector3d.hxx>
53 #include <StlAPI.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>
75 #include <XSDRAW.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>
82
83 #ifndef _STDIO_H
84 #include <stdio.h>
85 #endif
86
87 extern Standard_Boolean VDisplayAISObject (const TCollection_AsciiString& theName,
88                                            const Handle(AIS_InteractiveObject)& theAISObj,
89                                            Standard_Boolean theReplaceIfExists = Standard_True);
90
91 //=============================================================================
92 //function : ReadGltf
93 //purpose  : Reads glTF file
94 //=============================================================================
95 static Standard_Integer ReadGltf (Draw_Interpretor& theDI,
96                                   Standard_Integer theNbArgs,
97                                   const char** theArgVec)
98 {
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)
106   {
107     TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
108     anArgCase.LowerCase();
109     if (!isNoDoc
110      && (anArgCase == "-nocreate"
111       || anArgCase == "-nocreatedoc"))
112     {
113       toUseExistingDoc = Standard_True;
114       if (anArgIter + 1 < theNbArgs
115        && Draw::ParseOnOff (theArgVec[anArgIter + 1], toUseExistingDoc))
116       {
117         ++anArgIter;
118       }
119     }
120     else if (anArgCase == "-parallel")
121     {
122       isParallel = Standard_True;
123       if (anArgIter + 1 < theNbArgs
124        && Draw::ParseOnOff (theArgVec[anArgIter + 1], isParallel))
125       {
126         ++anArgIter;
127       }
128     }
129     else if (anArgCase == "-listexternalfiles"
130           || anArgCase == "-listexternals"
131           || anArgCase == "-listexternal"
132           || anArgCase == "-external"
133           || anArgCase == "-externalfiles")
134     {
135       toListExternalFiles = Standard_True;
136     }
137     else if (aDestName.IsEmpty())
138     {
139       aDestName = theArgVec[anArgIter];
140     }
141     else if (aFilePath.IsEmpty())
142     {
143       aFilePath = theArgVec[anArgIter];
144     }
145     else
146     {
147       Message::SendFail() << "Syntax error at '" << theArgVec[anArgIter] << "'";
148       return 1;
149     }
150   }
151   if (aFilePath.IsEmpty())
152   {
153     Message::SendFail() << "Syntax error: wrong number of arguments";
154     return 1;
155   }
156
157   Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator (theDI, 1);
158   Handle(TDocStd_Document) aDoc;
159   if (!toListExternalFiles
160    && !isNoDoc)
161   {
162     Handle(TDocStd_Application) anApp = DDocStd::GetApplication();
163     Standard_CString aNameVar = aDestName.ToCString();
164     DDocStd::GetDocument (aNameVar, aDoc, Standard_False);
165     if (aDoc.IsNull())
166     {
167       if (toUseExistingDoc)
168       {
169         Message::SendFail() << "Error: document with name " << aDestName << " does not exist";
170         return 1;
171       }
172       anApp->NewDocument (TCollection_ExtendedString ("BinXCAF"), aDoc);
173     }
174     else if (!toUseExistingDoc)
175     {
176       Message::SendFail() << "Error: document with name " << aDestName << " already exists";
177       return 1;
178     }
179   }
180
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)
187   {
188     aReader.ProbeHeader (aFilePath);
189     for (NCollection_IndexedMap<TCollection_AsciiString>::Iterator aFileIter (aReader.ExternalFiles()); aFileIter.More(); aFileIter.Next())
190     {
191       theDI << "\"" << aFileIter.Value() << "\" ";
192     }
193   }
194   else
195   {
196     aReader.Perform (aFilePath, aProgress);
197     if (isNoDoc)
198     {
199       DBRep::Set (aDestName.ToCString(), aReader.SingleShape());
200     }
201     else
202     {
203       Handle(DDocStd_DrawDocument) aDrawDoc = new DDocStd_DrawDocument (aDoc);
204       TDataStd_Name::Set (aDoc->GetData()->Root(), aDestName.ToCString());
205       Draw::Set (aDestName.ToCString(), aDrawDoc);
206     }
207   }
208   return 0;
209 }
210
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)
218 {
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)
226   {
227     TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
228     anArgCase.LowerCase();
229     if (anArgCase == "-comments"
230      && anArgIter + 1 < theNbArgs)
231     {
232       aFileInfo.Add ("Comments", theArgVec[++anArgIter]);
233     }
234     else if (anArgCase == "-author"
235           && anArgIter + 1 < theNbArgs)
236     {
237       aFileInfo.Add ("Author", theArgVec[++anArgIter]);
238     }
239     else if (anArgCase == "-forceuvexport"
240           || anArgCase == "-forceuv")
241     {
242       toForceUVExport = true;
243       if (anArgIter + 1 < theNbArgs
244        && Draw::ParseOnOff (theArgVec[anArgIter + 1], toForceUVExport))
245       {
246         ++anArgIter;
247       }
248     }
249     else if (anArgCase == "-trsfformat"
250           && anArgIter + 1 < theNbArgs)
251     {
252       TCollection_AsciiString aTrsfStr (theArgVec[++anArgIter]);
253       aTrsfStr.LowerCase();
254       if (aTrsfStr == "compact")
255       {
256         aTrsfFormat = RWGltf_WriterTrsfFormat_Compact;
257       }
258       else if (aTrsfStr == "mat4")
259       {
260         aTrsfFormat = RWGltf_WriterTrsfFormat_Mat4;
261       }
262       else if (aTrsfStr == "trs")
263       {
264         aTrsfFormat = RWGltf_WriterTrsfFormat_TRS;
265       }
266       else
267       {
268         Message::SendFail() << "Syntax error at '" << anArgCase << "'";
269         return 1;
270       }
271     }
272     else if (aDoc.IsNull())
273     {
274       Standard_CString aNameVar = theArgVec[anArgIter];
275       DDocStd::GetDocument (aNameVar, aDoc, false);
276       if (aDoc.IsNull())
277       {
278         TopoDS_Shape aShape = DBRep::Get (aNameVar);
279         if (aShape.IsNull())
280         {
281           Message::SendFail() << "Syntax error: '" << aNameVar << "' is not a shape nor document";
282           return 1;
283         }
284
285         anApp->NewDocument (TCollection_ExtendedString ("BinXCAF"), aDoc);
286         Handle(XCAFDoc_ShapeTool) aShapeTool = XCAFDoc_DocumentTool::ShapeTool (aDoc->Main());
287         aShapeTool->AddShape (aShape);
288       }
289     }
290     else if (aGltfFilePath.IsEmpty())
291     {
292       aGltfFilePath = theArgVec[anArgIter];
293     }
294     else
295     {
296       Message::SendFail() << "Syntax error at '" << theArgVec[anArgIter] << "'";
297       return 1;
298     }
299   }
300   if (aGltfFilePath.IsEmpty())
301   {
302     Message::SendFail() << "Syntax error: wrong number of arguments";
303     return 1;
304   }
305
306   Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator (theDI, 1);
307
308   TCollection_AsciiString anExt = aGltfFilePath;
309   anExt.LowerCase();
310
311   const Standard_Real aSystemUnitFactor = UnitsMethods::GetCasCadeLengthUnit() * 0.001;
312
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);
319   return 0;
320 }
321
322 static Standard_Integer writestl
323 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
324 {
325   if (argc < 3 || argc > 4) {
326     di << "Use: " << argv[0]
327     << " shape file [ascii/binary (0/1) : 1 by default]\n";
328   } else {
329     TopoDS_Shape aShape = DBRep::Get(argv[1]);
330     Standard_Boolean isASCIIMode = Standard_False;
331     if (argc == 4) {
332       isASCIIMode = (Draw::Atoi(argv[3]) == 0);
333     }
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);
338     if (!isOK)
339        di << "** Error **: Mesh writing has been failed.\n";
340   }
341   return 0;
342 }
343
344 //=============================================================================
345 //function : readstl
346 //purpose  : Reads stl file
347 //=============================================================================
348 static Standard_Integer readstl(Draw_Interpretor& theDI,
349                                 Standard_Integer theArgc,
350                                 const char** theArgv)
351 {
352   TCollection_AsciiString aShapeName, aFilePath;
353   bool toCreateCompOfTris = false;
354   for (Standard_Integer anArgIter = 1; anArgIter < theArgc; ++anArgIter)
355   {
356     TCollection_AsciiString anArg (theArgv[anArgIter]);
357     anArg.LowerCase();
358     if (aShapeName.IsEmpty())
359     {
360       aShapeName = theArgv[anArgIter];
361     }
362     else if (aFilePath.IsEmpty())
363     {
364       aFilePath = theArgv[anArgIter];
365     }
366     else if (anArg == "-brep")
367     {
368       toCreateCompOfTris = true;
369       if (anArgIter + 1 < theArgc
370        && Draw::ParseOnOff (theArgv[anArgIter + 1], toCreateCompOfTris))
371       {
372         ++anArgIter;
373       }
374     }
375     else
376     {
377       Message::SendFail() << "Syntax error: unknown argument '" << theArgv[anArgIter] << "'";
378       return 1;
379     }
380   }
381   if (aFilePath.IsEmpty())
382   {
383     Message::SendFail() << "Syntax error: not enough arguments";
384     return 1;
385   }
386
387   TopoDS_Shape aShape;
388   if (!toCreateCompOfTris)
389   {
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);
393
394     TopoDS_Face aFace;
395     BRep_Builder aB;
396     aB.MakeFace (aFace);
397     aB.UpdateFace (aFace, aTriangulation);
398     aShape = aFace;
399   }
400   else
401   {
402     Standard_DISABLE_DEPRECATION_WARNINGS
403     StlAPI::Read(aShape, aFilePath.ToCString());
404     Standard_ENABLE_DEPRECATION_WARNINGS
405   }
406   DBRep::Set (aShapeName.ToCString(), aShape);
407   return 0;
408 }
409
410 //! Parse RWMesh_CoordinateSystem enumeration.
411 static Standard_Boolean parseCoordinateSystem (const char* theArg,
412                                                RWMesh_CoordinateSystem& theSystem)
413 {
414   TCollection_AsciiString aCSStr (theArg);
415   aCSStr.LowerCase();
416   if (aCSStr == "zup")
417   {
418     theSystem = RWMesh_CoordinateSystem_Zup;
419   }
420   else if (aCSStr == "yup")
421   {
422     theSystem = RWMesh_CoordinateSystem_Yup;
423   }
424   else
425   {
426     return Standard_False;
427   }
428   return Standard_True;
429 }
430
431 //=============================================================================
432 //function : ReadObj
433 //purpose  : Reads OBJ file
434 //=============================================================================
435 static Standard_Integer ReadObj (Draw_Interpretor& theDI,
436                                  Standard_Integer theNbArgs,
437                                  const char** theArgVec)
438 {
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)
446   {
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"))
454     {
455       const TCollection_AsciiString aUnitStr (theArgVec[++anArgIter]);
456       aFileUnitFactor = UnitsAPI::AnyToSI (1.0, aUnitStr.ToCString());
457       if (aFileUnitFactor <= 0.0)
458       {
459         Message::SendFail() << "Syntax error: wrong length unit '" << aUnitStr << "'";
460         return 1;
461       }
462     }
463     else if (anArgIter + 1 < theNbArgs
464           && (anArgCase == "-filecoordinatesystem"
465            || anArgCase == "-filecoordsystem"
466            || anArgCase == "-filecoordsys"))
467     {
468       if (!parseCoordinateSystem (theArgVec[++anArgIter], aFileCoordSys))
469       {
470         Message::SendFail() << "Syntax error: unknown coordinate system '" << theArgVec[anArgIter] << "'";
471         return 1;
472       }
473     }
474     else if (anArgIter + 1 < theNbArgs
475           && (anArgCase == "-resultcoordinatesystem"
476            || anArgCase == "-resultcoordsystem"
477            || anArgCase == "-resultcoordsys"
478            || anArgCase == "-rescoordsys"))
479     {
480       if (!parseCoordinateSystem (theArgVec[++anArgIter], aResultCoordSys))
481       {
482         Message::SendFail() << "Syntax error: unknown coordinate system '" << theArgVec[anArgIter] << "'";
483         return 1;
484       }
485     }
486     else if (anArgCase == "-singleprecision"
487           || anArgCase == "-singleprec")
488     {
489       isSinglePrecision = Standard_True;
490       if (anArgIter + 1 < theNbArgs
491        && Draw::ParseOnOff (theArgVec[anArgIter + 1], isSinglePrecision))
492       {
493         ++anArgIter;
494       }
495     }
496     else if (isNoDoc
497           && (anArgCase == "-singleface"
498            || anArgCase == "-singletriangulation"))
499     {
500       isSingleFace = Standard_True;
501     }
502     else if (!isNoDoc
503           && (anArgCase == "-nocreate"
504            || anArgCase == "-nocreatedoc"))
505     {
506       toUseExistingDoc = Standard_True;
507       if (anArgIter + 1 < theNbArgs
508        && Draw::ParseOnOff (theArgVec[anArgIter + 1], toUseExistingDoc))
509       {
510         ++anArgIter;
511       }
512     }
513     else if (anArgCase == "-listexternalfiles"
514           || anArgCase == "-listexternals"
515           || anArgCase == "-listexternal"
516           || anArgCase == "-external"
517           || anArgCase == "-externalfiles")
518     {
519       toListExternalFiles = Standard_True;
520     }
521     else if (aDestName.IsEmpty())
522     {
523       aDestName = theArgVec[anArgIter];
524     }
525     else if (aFilePath.IsEmpty())
526     {
527       aFilePath = theArgVec[anArgIter];
528     }
529     else
530     {
531       Message::SendFail() << "Syntax error at '" << theArgVec[anArgIter] << "'";
532       return 1;
533     }
534   }
535   if (aFilePath.IsEmpty())
536   {
537     Message::SendFail() << "Syntax error: wrong number of arguments";
538     return 1;
539   }
540
541   Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator (theDI, 1);
542   Handle(TDocStd_Document) aDoc;
543   if (!isNoDoc
544    && !toListExternalFiles)
545   {
546     Handle(TDocStd_Application) anApp = DDocStd::GetApplication();
547     Standard_CString aNameVar = aDestName.ToCString();
548     DDocStd::GetDocument (aNameVar, aDoc, Standard_False);
549     if (aDoc.IsNull())
550     {
551       if (toUseExistingDoc)
552       {
553         Message::SendFail() << "Error: document with name " << aDestName << " does not exist";
554         return 1;
555       }
556       anApp->NewDocument (TCollection_ExtendedString ("BinXCAF"), aDoc);
557     }
558     else if (!toUseExistingDoc)
559     {
560       Message::SendFail() << "Error: document with name " << aDestName << " already exists";
561       return 1;
562     }
563   }
564
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);
572   if (isSingleFace)
573   {
574     RWObj_TriangulationReader aSimpleReader;
575     aSimpleReader.SetSinglePrecision (isSinglePrecision);
576     aSimpleReader.SetCreateShapes (Standard_False);
577     aSimpleReader.SetTransformation (aReader.CoordinateSystemConverter());
578     aSimpleReader.Read (aFilePath.ToCString(), aProgress);
579
580     Handle(Poly_Triangulation) aTriangulation = aSimpleReader.GetTriangulation();
581     TopoDS_Face aFace;
582     BRep_Builder aBuiler;
583     aBuiler.MakeFace (aFace);
584     aBuiler.UpdateFace (aFace, aTriangulation);
585     DBRep::Set (aDestName.ToCString(), aFace);
586     return 0;
587   }
588
589   if (toListExternalFiles)
590   {
591     aReader.ProbeHeader (aFilePath);
592     for (NCollection_IndexedMap<TCollection_AsciiString>::Iterator aFileIter (aReader.ExternalFiles()); aFileIter.More(); aFileIter.Next())
593     {
594       theDI << "\"" << aFileIter.Value() << "\" ";
595     }
596   }
597   else
598   {
599     aReader.Perform (aFilePath, aProgress);
600     if (isNoDoc)
601     {
602       DBRep::Set (aDestName.ToCString(), aReader.SingleShape());
603     }
604     else
605     {
606       Handle(DDocStd_DrawDocument) aDrawDoc = new DDocStd_DrawDocument (aDoc);
607       TDataStd_Name::Set (aDoc->GetData()->Root(), aDestName.ToCString());
608       Draw::Set (aDestName.ToCString(), aDrawDoc);
609     }
610   }
611   return 0;
612 }
613
614 static Standard_Integer writevrml
615 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
616 {
617   if (argc < 3 || argc > 5) 
618   {
619     di << "wrong number of parameters\n";
620     return 0;
621   }
622
623   TopoDS_Shape aShape = DBRep::Get(argv[1]);
624
625   // Get the optional parameters
626   Standard_Integer aVersion = 2;
627   Standard_Integer aType = 1;
628   if (argc >= 4)
629   {
630     aVersion = Draw::Atoi(argv[3]);
631     if (argc == 5)
632       aType = Draw::Atoi(argv[4]);
633   }
634
635   // Bound parameters
636   aVersion = Max(1, aVersion);
637   aVersion = Min(2, aVersion);
638   aType = Max(0, aType);
639   aType = Min(2, aType);
640
641   VrmlAPI_Writer writer;
642
643   switch (aType)
644   {
645   case 0: writer.SetRepresentation(VrmlAPI_ShadedRepresentation); break;
646   case 1: writer.SetRepresentation(VrmlAPI_WireFrameRepresentation); break;
647   case 2: writer.SetRepresentation(VrmlAPI_BothRepresentation); break;
648   }
649
650   if (!writer.Write(aShape, argv[2], aVersion))
651   {
652     di << "Error: File " << argv[2] << " was not written\n";
653   }
654
655   return 0;
656 }
657
658 //=======================================================================
659 //function : loadvrml
660 //purpose  :
661 //=======================================================================
662
663 static Standard_Integer loadvrml
664 (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
665 {
666   if (argc<3) di << "wrong number of parameters"    << "\n";
667   else {
668     TopoDS_Shape aShape ;
669     VrmlData_DataMapOfShapeAppearance aShapeAppMap;
670
671     //-----------------------------------------------------------
672     std::filebuf aFic;
673     std::istream aStream (&aFic);
674
675     if (aFic.open(argv[2], std::ios::in)) {
676
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())
683       {
684         if (!aDisk.IsEmpty())
685           aVrmlDir = aDisk;
686         else
687           aVrmlDir.Clear();
688         aTrek.ChangeAll('|', '/');
689         aVrmlDir += aTrek;
690       }
691
692       VrmlData_Scene aScene;
693       Standard_Real anOCCUnit = UnitsMethods::GetCasCadeLengthUnit();
694       aScene.SetLinearScale(1000. / anOCCUnit);
695
696       aScene.SetVrmlDir (aVrmlDir);
697       aScene << aStream;
698       const char * aStr = 0L;
699       switch (aScene.Status()) {
700
701       case VrmlData_StatusOK:
702         {
703           aShape = aScene.GetShape(aShapeAppMap);
704           break;
705         }
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;
723       default:
724         break;
725       }
726       if (aStr) {
727         di << " ++ VRML Error: " << aStr << " in line "
728           << aScene.GetLineError() << "\n";
729       }
730       else {
731         DBRep::Set(argv[1],aShape);
732       }
733     }
734     else {
735       di << "cannot open file\n";
736     }
737
738
739     //-----------------------------------------------------------
740   }
741   return 0;
742 }
743
744 //-----------------------------------------------------------------------------
745 static Standard_Integer createmesh
746 (Draw_Interpretor& di, Standard_Integer argc, const char** argv )
747 {
748   if (argc<3)
749   {
750     di << "Wrong number of parameters\n";
751     di << "Use: " << argv[0] << " <mesh name> <stl file>\n";
752     return 0;
753   }
754
755   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
756   if (aContext.IsNull())
757   {
758     di << "No active view. Please call 'vinit' first\n";
759     return 0;
760   }
761
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);
766
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";
772
773   aMesh->SetDataSource( aDS );
774   aMesh->AddBuilder( new MeshVS_MeshPrsBuilder( aMesh.operator->() ), Standard_True );
775
776   aMesh->GetDrawer()->SetColor( MeshVS_DA_EdgeColor, Quantity_NOC_YELLOW );
777
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 );
785
786   VDisplayAISObject(argv[1], aMesh);
787   aContext->Deactivate( aMesh );
788
789   Draw::Set( argv[1], new XSDRAWSTLVRML_DrawableMesh( aMesh ) );
790   Handle( V3d_View ) aView = ViewerTest::CurrentView();
791   if ( !aView.IsNull() )
792     aView->FitAll();
793
794   return 0;
795 }
796 //-----------------------------------------------------------------------------
797
798 static Standard_Integer create3d
799 (Draw_Interpretor& di, Standard_Integer argc, const char** argv )
800 {
801   if (argc<2)
802   {
803     di << "Wrong number of parameters\n";
804     di << "Use: " << argv[0] << " <mesh name>\n";
805     return 0;
806   }
807
808   Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
809   if (aContext.IsNull())
810   {
811     di << "No active view. Please call 'vinit' first\n";
812     return 0;
813   }
814
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";
819
820   aMesh->SetDataSource( aDS );
821   aMesh->AddBuilder( new MeshVS_MeshPrsBuilder( aMesh.operator->() ), Standard_True );
822
823   aMesh->GetDrawer()->SetColor( MeshVS_DA_EdgeColor, Quantity_NOC_YELLOW );
824
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 );
832
833   VDisplayAISObject(argv[1], aMesh);
834   aContext->Deactivate( aMesh );
835
836   Draw::Set( argv[1], new XSDRAWSTLVRML_DrawableMesh( aMesh ) );
837   Handle( V3d_View ) aView = ViewerTest::CurrentView();
838   if ( !aView.IsNull() )
839     aView->FitAll();
840
841   return 0;
842 }
843
844 Handle( MeshVS_Mesh ) getMesh( const char* theName, Draw_Interpretor& di)
845 {
846   Handle( XSDRAWSTLVRML_DrawableMesh ) aDrawMesh =
847     Handle( XSDRAWSTLVRML_DrawableMesh )::DownCast( Draw::Get( theName ) );
848
849   if( aDrawMesh.IsNull() )
850   {
851     di << "There is no such object\n";
852     return NULL;
853   }
854   else
855   {
856     Handle( MeshVS_Mesh ) aMesh = aDrawMesh->GetMesh();
857     if( aMesh.IsNull() )
858     {
859       di << "There is invalid mesh\n";
860       return NULL;
861     }
862     else
863       return aMesh;
864   }
865 }
866
867 //-----------------------------------------------------------------------------
868 static Standard_Integer setcolor
869 (Draw_Interpretor& di, Standard_Integer argc, const char** argv, Standard_Integer theParam )
870 {
871   if (argc<5)
872     di << "Wrong number of parameters\n";
873   else
874   {
875     Handle( MeshVS_Mesh ) aMesh = getMesh( argv[1], di );
876     if( !aMesh.IsNull() )
877     {
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 ) );
883
884       Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
885
886       if( aContext.IsNull() )
887         di << "The context is null\n";
888       else
889         aContext->Redisplay (aMesh, Standard_True);
890     }
891   }
892   return 0;
893 }
894 //-----------------------------------------------------------------------------
895 static Standard_Integer meshcolor
896 (Draw_Interpretor& theInterp, Standard_Integer argc, const char** argv )
897 {
898   return setcolor( theInterp, argc, argv, MeshVS_DA_InteriorColor );
899 }
900 //-----------------------------------------------------------------------------
901 static Standard_Integer linecolor
902 (Draw_Interpretor& theInterp, Standard_Integer argc, const char** argv )
903 {
904   return setcolor( theInterp, argc, argv, MeshVS_DA_EdgeColor );
905 }
906 //-----------------------------------------------------------------------------
907 static Standard_Integer meshmat
908 (Draw_Interpretor& di, Standard_Integer argc, const char** argv )
909 {
910   if (argc<3)
911     di << "Wrong number of parameters\n";
912   else
913   {
914     Handle( MeshVS_Mesh ) aMesh = getMesh( argv[1], di );
915     if( !aMesh.IsNull() )
916     {
917       Standard_Integer aMaterial = Draw::Atoi (argv[2]);
918
919       Graphic3d_MaterialAspect aMatAsp =
920         (Graphic3d_MaterialAspect)(Graphic3d_NameOfMaterial)aMaterial;
921
922       if (argc == 4)
923       {
924         Standard_Real aTransparency = Draw::Atof(argv[3]);
925         aMatAsp.SetTransparency (Standard_ShortReal (aTransparency));
926       }
927       aMesh->GetDrawer()->SetMaterial( MeshVS_DA_FrontMaterial, aMatAsp );
928       aMesh->GetDrawer()->SetMaterial( MeshVS_DA_BackMaterial, aMatAsp );
929
930       Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
931
932       if( aContext.IsNull() )
933         di << "The context is null\n";
934       else
935         aContext->Redisplay (aMesh, Standard_True);
936     }
937   }
938   return 0;
939 }
940 //-----------------------------------------------------------------------------
941 static Standard_Integer shrink
942 (Draw_Interpretor& di, Standard_Integer argc, const char** argv )
943 {
944   if (argc<3)
945     di << "Wrong number of parameters\n";
946   else
947   {
948     Handle( MeshVS_Mesh ) aMesh = getMesh( argv[1], di );
949     if( !aMesh.IsNull() )
950     {
951       Standard_Real aShrinkCoeff = Draw::Atof (argv[2]);
952       aMesh->GetDrawer()->SetDouble( MeshVS_DA_ShrinkCoeff, aShrinkCoeff );
953
954       Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
955
956       if( aContext.IsNull() )
957         di << "The context is null\n";
958       else
959         aContext->Redisplay (aMesh, Standard_True);
960     }
961   }
962   return 0;
963 }
964
965 //-----------------------------------------------------------------------------
966 static Standard_Integer closed (Draw_Interpretor& theDI, Standard_Integer theArgc, const char** theArgv)
967 {
968   if (theArgc < 3)
969   {
970     theDI << "Wrong number of parameters.\n";
971   }
972   else
973   {
974     Handle(MeshVS_Mesh) aMesh = getMesh (theArgv[1], theDI);
975     if (!aMesh.IsNull())
976     {
977       Standard_Boolean aFlag = Draw::Atoi (theArgv[2]) != 0;
978       aMesh->GetDrawer()->SetBoolean (MeshVS_DA_SupressBackFaces, aFlag);
979
980       Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
981       if (aContext.IsNull())
982       {
983         theDI << "The context is null\n";
984       }
985       else
986       {
987         aContext->Redisplay (aMesh, Standard_True);
988       }
989     }
990   }
991   return 0;
992 }
993
994 //-----------------------------------------------------------------------------
995
996 static Standard_Integer mdisplay
997 (Draw_Interpretor& di, Standard_Integer argc, const char** argv )
998 {
999   if (argc<2)
1000     di << "Wrong number of parameters\n";
1001   else
1002   {
1003     Handle( MeshVS_Mesh ) aMesh = getMesh( argv[1], di );
1004     if( !aMesh.IsNull() )
1005     {
1006       Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
1007
1008       if( aContext.IsNull() )
1009         di << "The context is null\n";
1010       else
1011       {
1012         aContext->Display (aMesh, Standard_True);
1013       }
1014     }
1015   }
1016   return 0;
1017 }
1018 //-----------------------------------------------------------------------------
1019 static Standard_Integer merase
1020 (Draw_Interpretor& di, Standard_Integer argc, const char** argv )
1021 {
1022   if (argc<2)
1023     di << "Wrong number of parameters\n";
1024   else
1025   {
1026     Handle( MeshVS_Mesh ) aMesh = getMesh( argv[1], di );
1027     if( !aMesh.IsNull() )
1028     {
1029       Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
1030
1031       if( aContext.IsNull() )
1032         di << "The context is null\n";
1033       else
1034       {
1035         aContext->Erase (aMesh, Standard_True);
1036       }
1037     }
1038     else
1039       di << "Mesh is null\n";
1040   }
1041   return 0;
1042 }
1043 //-----------------------------------------------------------------------------
1044 static Standard_Integer hidesel
1045 (Draw_Interpretor& di, Standard_Integer argc, const char** argv )
1046 {
1047   if (argc<2)
1048   {
1049     di << "Wrong number of parameters\n";
1050     di << "Use: " << argv[0] << " <mesh name>\n";
1051     return 0;
1052   }
1053
1054   Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
1055   Handle( MeshVS_Mesh ) aMesh = getMesh( argv[1], di );
1056   if( aMesh.IsNull() )
1057   {
1058     di << "The mesh is invalid\n";
1059     return 0;
1060   }
1061
1062   if( aContext.IsNull() )
1063     di << "The context is null\n";
1064   else
1065   {
1066     Handle(TColStd_HPackedMapOfInteger) aHiddenNodes = aMesh->GetHiddenNodes();
1067     if (aHiddenNodes.IsNull())
1068     {
1069       aHiddenNodes = new TColStd_HPackedMapOfInteger();
1070     }
1071     Handle(TColStd_HPackedMapOfInteger) aHiddenElements = aMesh->GetHiddenElems();
1072     if (aHiddenElements.IsNull())
1073     {
1074       aHiddenElements = new TColStd_HPackedMapOfInteger();
1075     }
1076     for( aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected() )
1077     {
1078       Handle( MeshVS_MeshEntityOwner ) anOwner =
1079         Handle( MeshVS_MeshEntityOwner )::DownCast( aContext->SelectedOwner() );
1080       if( !anOwner.IsNull() )
1081       {
1082         if( anOwner->Type()==MeshVS_ET_Node )
1083         {
1084           aHiddenNodes->ChangeMap().Add( anOwner->ID() );
1085         }
1086         else
1087         {
1088           aHiddenElements->ChangeMap().Add( anOwner->ID() );
1089         }
1090       }
1091     }
1092     aContext->ClearSelected (Standard_False);
1093     aMesh->SetHiddenNodes( aHiddenNodes );
1094     aMesh->SetHiddenElems( aHiddenElements );
1095     aContext->Redisplay (aMesh, Standard_True);
1096   }
1097
1098   return 0;
1099 }
1100 //-----------------------------------------------------------------------------
1101 static Standard_Integer showonly
1102 (Draw_Interpretor& di, Standard_Integer argc, const char** argv )
1103 {
1104   if (argc<2)
1105   {
1106     di << "Wrong number of parameters\n";
1107     di << "Use: " << argv[0] << " <mesh name>\n";
1108     return 0;
1109   }
1110
1111
1112   Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
1113   Handle( MeshVS_Mesh ) aMesh = getMesh( argv[1], di );
1114   if( aMesh.IsNull() )
1115   {
1116     di << "The mesh is invalid\n";
1117     return 0;
1118   }
1119
1120   if( aContext.IsNull() )
1121     di << "The context is null\n";
1122   else
1123   {
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() )
1129     {
1130       Handle( MeshVS_MeshEntityOwner ) anOwner =
1131         Handle( MeshVS_MeshEntityOwner )::DownCast( aContext->SelectedOwner() );
1132       if( !anOwner.IsNull() )
1133       {
1134         if( anOwner->Type() == MeshVS_ET_Node )
1135         {
1136           aHiddenNodes->ChangeMap().Remove( anOwner->ID() );
1137         }
1138         else
1139         {
1140           aHiddenElements->ChangeMap().Remove( anOwner->ID() );
1141         }
1142       }
1143     }
1144     aMesh->SetHiddenNodes( aHiddenNodes );
1145     aMesh->SetHiddenElems( aHiddenElements );
1146     aContext->Redisplay (aMesh, Standard_True);
1147   }
1148
1149   return 0;
1150 }
1151 //-----------------------------------------------------------------------------
1152 static Standard_Integer showall
1153 (Draw_Interpretor& di, Standard_Integer argc, const char** argv )
1154 {
1155   if (argc<2)
1156   {
1157     di << "Wrong number of parameters\n";
1158     di << "Use: " << argv[0] << " <mesh name>\n";
1159     return 0;
1160   }
1161
1162   Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
1163   Handle( MeshVS_Mesh ) aMesh = getMesh( argv[1], di );
1164   if( aMesh.IsNull() )
1165   {
1166     di << "The mesh is invalid\n";
1167     return 0;
1168   }
1169
1170   if( aContext.IsNull() )
1171     di << "The context is null\n";
1172   else
1173   {
1174     aMesh->SetHiddenNodes( new TColStd_HPackedMapOfInteger() );
1175     aMesh->SetHiddenElems( new TColStd_HPackedMapOfInteger() );
1176     aContext->Redisplay (aMesh, Standard_True);
1177   }
1178
1179   return 0;
1180 }
1181
1182 //-----------------------------------------------------------------------------
1183 static Standard_Integer meshcolors( Draw_Interpretor& di,
1184                                     Standard_Integer argc,
1185                                     const char** argv )
1186 {
1187   try
1188   {
1189     OCC_CATCH_SIGNALS
1190       if ( argc < 4 )
1191       {
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";
1201
1202         return 0;
1203       }
1204
1205       Handle( MeshVS_Mesh ) aMesh = getMesh( argv[ 1 ], di );
1206
1207       if ( aMesh.IsNull() )
1208       {
1209         di << "Mesh not found\n";
1210         return 0;
1211       }
1212       Handle(AIS_InteractiveContext) anIC = ViewerTest::GetAISContext();
1213       if ( anIC.IsNull() )
1214       {
1215         di << "The context is null\n";
1216         return 0;
1217       }
1218       if( !aMesh.IsNull() )
1219       {
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") )
1224         {
1225           Handle(MeshVS_PrsBuilder) aTempBuilder;
1226           Standard_Integer aReflection = Draw::Atoi(argv[3]);
1227
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());
1232
1233             aTempBuilder = aMesh->FindBuilder("MeshVS_NodalColorPrsBuilder");
1234             if( !aTempBuilder.IsNull())
1235               aMesh->RemoveBuilderById(aTempBuilder->GetId());
1236           }
1237
1238           if( aMode.IsEqual("elem1") || aMode.IsEqual("elem2") )
1239           {
1240             Handle(MeshVS_ElementalColorPrsBuilder) aBuilder = new MeshVS_ElementalColorPrsBuilder(
1241                 aMesh, MeshVS_DMF_ElementalColorDataPrs | MeshVS_DMF_OCCMask );
1242               // Color
1243             const TColStd_PackedMapOfInteger& anAllElements = aMesh->GetDataSource()->GetAllElements();
1244             TColStd_MapIteratorOfPackedMapOfInteger anIter( anAllElements );
1245
1246             if( aMode.IsEqual("elem1") )
1247               for ( ; anIter.More(); anIter.Next() )
1248               {
1249                 Quantity_Color aColor( (Quantity_NameOfColor)( anIter.Key() % Quantity_NOC_WHITE ) );
1250                 aBuilder->SetColor1( anIter.Key(), aColor );
1251               }
1252             else
1253               for ( ; anIter.More(); anIter.Next() )
1254                 aBuilder->SetColor2( anIter.Key(), aColor1, aColor2 );
1255
1256             aMesh->AddBuilder( aBuilder, Standard_True );
1257           }
1258
1259
1260           if( aMode.IsEqual("nodal") )
1261           {
1262             Handle(MeshVS_NodalColorPrsBuilder) aBuilder = new MeshVS_NodalColorPrsBuilder(
1263                 aMesh, MeshVS_DMF_NodalColorDataPrs | MeshVS_DMF_OCCMask );
1264             aMesh->AddBuilder( aBuilder, Standard_True );
1265
1266             // Color
1267             const TColStd_PackedMapOfInteger& anAllNodes =
1268               aMesh->GetDataSource()->GetAllNodes();
1269             TColStd_MapIteratorOfPackedMapOfInteger anIter( anAllNodes );
1270             for ( ; anIter.More(); anIter.Next() )
1271             {
1272               Quantity_Color aColor( (Quantity_NameOfColor)(
1273                 anIter.Key() % Quantity_NOC_WHITE ) );
1274               aBuilder->SetColor( anIter.Key(), aColor );
1275             }
1276             aMesh->AddBuilder( aBuilder, Standard_True );
1277           }
1278
1279           if(aMode.IsEqual("nodaltex"))
1280           {
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);
1286
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);
1292
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;
1297
1298             // get bounding box for calculations
1299             aDataSource->GetBoundingBox().Get(aMinX, aMinY, aMinZ, aMaxX, aMaxY, aMaxZ);
1300             Standard_Real aDelta = aMaxX - aMinX;
1301
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;
1307
1308             // iterate nodes
1309             const TColStd_PackedMapOfInteger& anAllNodes =
1310                   aMesh->GetDataSource()->GetAllNodes();
1311             TColStd_MapIteratorOfPackedMapOfInteger anIter(anAllNodes);
1312             for (; anIter.More(); anIter.Next())
1313             {
1314               //get node coordinates to aCoord variable
1315               aDataSource->GetGeom(anIter.Key(), Standard_False, aCoords, aNbNodes, aType);
1316
1317               Standard_Real aScaleValue;
1318               try {
1319                 OCC_CATCH_SIGNALS
1320                 aScaleValue = (aCoords.Value(1) - (Standard_Real) aMinX) / aDelta;
1321               } catch(Standard_Failure const&) {
1322                 aScaleValue = 0;
1323               }
1324
1325               aScaleMap.Bind(anIter.Key(), aScaleValue);
1326             }
1327
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);
1333           }
1334
1335           aMesh->GetDrawer()->SetBoolean (MeshVS_DA_ColorReflection, aReflection != 0);
1336
1337           anIC->Redisplay (aMesh, Standard_True);
1338         }
1339         else
1340         {
1341           di << "Wrong mode name\n";
1342           return 0;
1343         }
1344       }
1345   }
1346   catch ( Standard_Failure const& )
1347   {
1348     di << "Error\n";
1349   }
1350
1351   return 0;
1352 }
1353 //-----------------------------------------------------------------------------
1354 static Standard_Integer meshvectors( Draw_Interpretor& di,
1355                                      Standard_Integer argc,
1356                                      const char** argv )
1357 {
1358   if ( argc < 3 )
1359   {
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";
1366
1367     return 0;
1368   }
1369
1370   Handle( MeshVS_Mesh ) aMesh = getMesh( argv[ 1 ], di );
1371
1372   if ( aMesh.IsNull() )
1373   {
1374     di << "Mesh not found\n";
1375     return 0;
1376   }
1377   Handle(AIS_InteractiveContext) anIC = ViewerTest::GetAISContext();
1378   if ( anIC.IsNull() )
1379   {
1380     di << "The context is null\n";
1381     return 0;
1382   }
1383
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);
1390
1391   for (Standard_Integer anIdx = 2; anIdx < argc; anIdx++)
1392   {
1393     if (!aParam.IsEmpty())
1394     {
1395       if (aParam == "-mode")
1396       {
1397         aMode       = argv[anIdx];
1398       }
1399       else if (aParam == "-maxlen")
1400       {
1401         aMaxlen     = Draw::Atof(argv[anIdx]);
1402       }
1403       else if (aParam == "-color")
1404       {
1405         if (!Quantity_Color::ColorFromName (argv[anIdx], aColor))
1406         {
1407           Message::SendFail() << "Syntax error at " << aParam;
1408           return 1;
1409         }
1410       }
1411       else if (aParam == "-arrowpart")
1412       {
1413         anArrowPart = Draw::Atof(argv[anIdx]);
1414       }
1415       else if (aParam == "-issimple")
1416       {
1417         isSimplePrs = Draw::Atoi(argv[anIdx]) != 0;
1418       }
1419       aParam.Clear();
1420     }
1421     else if (argv[anIdx][0] == '-')
1422     {
1423       aParam = argv[anIdx];
1424     }
1425   }
1426
1427   if( !aMode.IsEqual("elem") && !aMode.IsEqual("nodal") && !aMode.IsEqual("none") )
1428   {
1429     di << "Wrong mode name\n";
1430     return 0;
1431   }
1432
1433   Handle(MeshVS_PrsBuilder) aTempBuilder;
1434
1435   aTempBuilder = aMesh->FindBuilder("MeshVS_VectorPrsBuilder");
1436   if( !aTempBuilder.IsNull())
1437     aMesh->RemoveBuilderById(aTempBuilder->GetId());
1438
1439   if( !aMode.IsEqual("none") )
1440   {
1441     Handle(MeshVS_VectorPrsBuilder) aBuilder = new MeshVS_VectorPrsBuilder( aMesh.operator->(), 
1442                                                                             aMaxlen,
1443                                                                             aColor,
1444                                                                             MeshVS_DMF_VectorDataPrs,
1445                                                                             0,
1446                                                                             -1,
1447                                                                             MeshVS_BP_Vector,
1448                                                                             isSimplePrs);
1449
1450     Standard_Boolean anIsElement = aMode.IsEqual("elem");
1451     const TColStd_PackedMapOfInteger& anAllIDs = anIsElement ? aMesh->GetDataSource()->GetAllElements() :
1452                                                                aMesh->GetDataSource()->GetAllNodes();
1453
1454     Standard_Integer aNbNodes;
1455     MeshVS_EntityType aEntType;
1456
1457     TColStd_Array1OfReal aCoords(1, 3);
1458     aCoords.Init (0.);
1459     TColStd_MapIteratorOfPackedMapOfInteger anIter( anAllIDs );
1460     for ( ; anIter.More(); anIter.Next() )
1461     {
1462       Standard_Boolean IsValidData = Standard_False; 
1463       if (anIsElement) {
1464         aMesh->GetDataSource()->GetGeomType(anIter.Key(), anIsElement, aEntType);
1465         if (aEntType == MeshVS_ET_Face)
1466           IsValidData = aMesh->GetDataSource()->GetNormal(anIter.Key(), 3, aCoords.ChangeValue(1), aCoords.ChangeValue(2), aCoords.ChangeValue(3));
1467       } else
1468         IsValidData = aMesh->GetDataSource()->GetGeom(anIter.Key(), Standard_False, aCoords, aNbNodes, aEntType);
1469
1470       gp_Vec aNorm;
1471       if(IsValidData)
1472       { 
1473         aNorm = gp_Vec(aCoords.Value(1), aCoords.Value(2), aCoords.Value(3));
1474         if(aNorm.Magnitude() < gp::Resolution())
1475         {
1476           aNorm = gp_Vec(0,0,1); //method GetGeom(...) returns coordinates of nodes
1477         }
1478       }
1479       else
1480       {
1481         aNorm = gp_Vec(0,0,1);
1482       }
1483       aBuilder->SetVector(anIsElement, anIter.Key(), aNorm.Normalized());
1484     }
1485
1486     aMesh->AddBuilder( aBuilder, Standard_False );
1487     aMesh->GetDrawer()->SetDouble ( MeshVS_DA_VectorArrowPart, anArrowPart );
1488   }
1489
1490   anIC->Redisplay (aMesh, Standard_True);
1491
1492   return 0;
1493 }
1494 //-----------------------------------------------------------------------------
1495
1496 static Standard_Integer meshtext( Draw_Interpretor& di,
1497                                   Standard_Integer argc,
1498                                   const char** argv )
1499 {
1500   if ( argc < 2 )
1501   {
1502     di << "Wrong number of parameters\n";
1503     di << "Use : meshtext <mesh name>\n";
1504     return 0;
1505   }
1506
1507   Handle( MeshVS_Mesh ) aMesh = getMesh( argv[ 1 ], di );
1508
1509   if ( aMesh.IsNull() )
1510   {
1511     di << "Mesh not found\n";
1512     return 0;
1513   }
1514
1515   Handle(AIS_InteractiveContext) anIC = ViewerTest::GetAISContext();
1516   if ( anIC.IsNull() )
1517   {
1518     di << "The context is null\n";
1519     return 0;
1520   }
1521
1522   // Prepare triangle labels
1523   MeshVS_DataMapOfIntegerAsciiString aLabels;
1524   Standard_Integer aLen = aMesh->GetDataSource()->GetAllElements().Extent();
1525   for ( Standard_Integer anIndex = 1; anIndex <= aLen; anIndex++ ){
1526     aLabels.Bind( anIndex, TCollection_AsciiString( anIndex ) );
1527   }
1528
1529   Handle(MeshVS_TextPrsBuilder) aTextBuilder = new MeshVS_TextPrsBuilder( aMesh.operator->(), 20., Quantity_NOC_YELLOW );
1530   aTextBuilder->SetTexts( Standard_True, aLabels );
1531   aMesh->AddBuilder( aTextBuilder );
1532
1533   return 0;
1534 }
1535
1536 static Standard_Integer meshdeform( Draw_Interpretor& di,
1537                                     Standard_Integer argc,
1538                                     const char** argv )
1539 {
1540   if ( argc < 3 )
1541   {
1542     di << "Wrong number of parameters\n";
1543     di << "Use : meshdeform <mesh name> < -mode {on|off} > [-scale scalefactor]\n";
1544     return 0;
1545   }
1546
1547   Handle( MeshVS_Mesh ) aMesh = getMesh( argv[ 1 ], di );
1548
1549   if ( aMesh.IsNull() )
1550   {
1551     di << "Mesh not found\n";
1552     return 0;
1553   }
1554   Handle(AIS_InteractiveContext) anIC = ViewerTest::GetAISContext();
1555   if ( anIC.IsNull() )
1556   {
1557     di << "The context is null\n";
1558     return 0;
1559   }
1560
1561   TCollection_AsciiString aParam;
1562   TCollection_AsciiString aMode("off");
1563   Standard_Real           aScale(1.0);
1564
1565   for (Standard_Integer anIdx = 2; anIdx < argc; anIdx++)
1566   {
1567     if (!aParam.IsEmpty())
1568     {
1569       if (aParam == "-mode")
1570       {
1571         aMode = argv[anIdx];
1572       }
1573       else if (aParam == "-scale")
1574       {
1575         aScale = Draw::Atof(argv[anIdx]);
1576       }
1577       aParam.Clear();
1578     }
1579     else if (argv[anIdx][0] == '-')
1580     {
1581       aParam = argv[anIdx];
1582     }
1583   }
1584
1585   if(!aMode.IsEqual("on") && !aMode.IsEqual("off"))
1586   {
1587     di << "Wrong mode name\n";
1588     return 0;
1589   }
1590
1591   Handle ( MeshVS_DeformedDataSource ) aDefDS =
1592     new MeshVS_DeformedDataSource( aMesh->GetDataSource() , aScale );
1593
1594   const TColStd_PackedMapOfInteger& anAllIDs = aMesh->GetDataSource()->GetAllNodes();
1595
1596   Standard_Integer aNbNodes;
1597   MeshVS_EntityType aEntType;
1598
1599   TColStd_MapIteratorOfPackedMapOfInteger anIter( anAllIDs );
1600   for ( ; anIter.More(); anIter.Next() )
1601   {
1602     TColStd_Array1OfReal aCoords(1, 3);
1603     aMesh->GetDataSource()->GetGeom(anIter.Key(), Standard_False, aCoords, aNbNodes, aEntType);
1604
1605     gp_Vec aNorm = gp_Vec(aCoords.Value(1), aCoords.Value(2), aCoords.Value(3));
1606     if( !aNorm.Magnitude() )
1607       aNorm = gp_Vec(0,0,1);
1608     aDefDS->SetVector(anIter.Key(), aNorm.Normalized());
1609   }
1610
1611   aMesh->SetDataSource(aDefDS);
1612
1613   anIC->Redisplay (aMesh, Standard_False);
1614
1615   Handle( V3d_View ) aView = ViewerTest::CurrentView();
1616   if ( !aView.IsNull() )
1617     aView->FitAll();
1618
1619   return 0;
1620 }
1621
1622 static Standard_Integer mesh_edge_width( Draw_Interpretor& di,
1623                                         Standard_Integer argc,
1624                                         const char** argv )
1625 {
1626   try
1627   {
1628     OCC_CATCH_SIGNALS
1629       if ( argc < 3 )
1630       {
1631         di << "Wrong number of parameters\n";
1632         di << "Use : mesh_edge_width <mesh name> <width>\n";
1633         return 0;
1634       }
1635
1636       Handle(MeshVS_Mesh) aMesh = getMesh( argv[ 1 ], di );
1637       if ( aMesh.IsNull() )
1638       {
1639         di << "Mesh not found\n";
1640         return 0;
1641       }
1642
1643       const char* aWidthStr = argv[ 2 ];
1644       if ( aWidthStr == 0 || Draw::Atof( aWidthStr ) <= 0 )
1645       {
1646         di << "Width must be real value more than zero\n";
1647         return 0;
1648       }
1649
1650       double aWidth = Draw::Atof( aWidthStr );
1651
1652       Handle(AIS_InteractiveContext) anIC = ViewerTest::GetAISContext();
1653       if ( anIC.IsNull() )
1654       {
1655         di << "The context is null\n";
1656         return 0;
1657       }
1658
1659       Handle(MeshVS_Drawer) aDrawer = aMesh->GetDrawer();
1660       if ( aDrawer.IsNull() )
1661       {
1662         di << "The drawer is null\n";
1663         return 0;
1664       }
1665
1666       aDrawer->SetDouble( MeshVS_DA_EdgeWidth, aWidth );
1667       anIC->Redisplay (aMesh, Standard_True);
1668   }
1669   catch ( Standard_Failure const& )
1670   {
1671     di << "Error\n";
1672   }
1673
1674   return 0;
1675 }
1676
1677 //-----------------------------------------------------------------------------
1678
1679 static Standard_Integer meshinfo(Draw_Interpretor& di,
1680                                  Standard_Integer argc,
1681                                  const char** argv)
1682 {
1683   if ( argc != 2 )
1684   {
1685     di << "Wrong number of parameters. Use : meshinfo mesh\n";
1686     return 0;
1687   }
1688
1689   Handle(MeshVS_Mesh) aMesh = getMesh(argv[ 1 ], di);
1690   if ( aMesh.IsNull() )
1691   {
1692     di << "Mesh not found\n";
1693     return 0;
1694   }
1695
1696   Handle(XSDRAWSTLVRML_DataSource) stlMeshSource = Handle(XSDRAWSTLVRML_DataSource)::DownCast(aMesh->GetDataSource());
1697   if (!stlMeshSource.IsNull())
1698   {
1699     const TColStd_PackedMapOfInteger& nodes = stlMeshSource->GetAllNodes();
1700     const TColStd_PackedMapOfInteger& tris  = stlMeshSource->GetAllElements();
1701
1702     di << "Nb nodes = " << nodes.Extent() << "\n";
1703     di << "Nb triangles = " << tris.Extent() << "\n";
1704   }
1705
1706   return 0;
1707 }
1708
1709 //-----------------------------------------------------------------------------
1710
1711 void  XSDRAWSTLVRML::InitCommands (Draw_Interpretor& theCommands)
1712 {
1713   const char* g = "XSTEP-STL/VRML";  // Step transfer file commands
1714   //XSDRAW::LoadDraw(theCommands);
1715
1716   theCommands.Add ("ReadGltf",
1717                    "ReadGltf Doc file [-parallel {on|off}] [-listExternalFiles] [-noCreateDoc]"
1718                    "\n\t\t: Read glTF file into XDE document."
1719                    "\n\t\t:   -listExternalFiles do not read mesh and only list external files"
1720                    "\n\t\t:   -noCreateDoc read into existing XDE document",
1721                    __FILE__, ReadGltf, g);
1722   theCommands.Add ("readgltf",
1723                    "readgltf shape file"
1724                    "\n\t\t: Same as ReadGltf but reads glTF file into a shape instead of a document.",
1725                    __FILE__, ReadGltf, g);
1726   theCommands.Add ("WriteGltf",
1727                    "WriteGltf Doc file [-trsfFormat {compact|TRS|mat4}=compact] [-comments Text] [-author Name] [-forceUVExport]"
1728                    "\n\t\t: Write XDE document into glTF file."
1729                    "\n\t\t:   -trsfFormat preferred transformation format"
1730                    "\n\t\t:   -forceUVExport always export UV coordinates",
1731                    __FILE__, WriteGltf, g);
1732   theCommands.Add ("writegltf",
1733                    "writegltf shape file",
1734                    __FILE__, WriteGltf, g);
1735   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);
1736   theCommands.Add ("writestl",  "shape file [ascii/binary (0/1) : 1 by default] [InParallel (0/1) : 0 by default]",__FILE__,writestl,g);
1737   theCommands.Add ("readstl",
1738                    "readstl shape file [-brep]"
1739                    "\n\t\t: Reads STL file and creates a new shape with specified name."
1740                    "\n\t\t: When -brep is specified, creates a Compound of per-triangle Faces."
1741                    "\n\t\t: Single triangulation-only Face is created otherwise (default).",
1742                    __FILE__, readstl, g);
1743   theCommands.Add ("loadvrml" , "shape file",__FILE__,loadvrml,g);
1744   theCommands.Add ("ReadObj",
1745                    "ReadObj Doc file [-fileCoordSys {Zup|Yup}] [-fileUnit Unit]"
1746            "\n\t\t:                  [-resultCoordSys {Zup|Yup}] [-singlePrecision]"
1747            "\n\t\t:                  [-listExternalFiles] [-noCreateDoc]"
1748            "\n\t\t: Read OBJ file into XDE document."
1749            "\n\t\t:   -fileUnit       length unit of OBJ file content;"
1750            "\n\t\t:   -fileCoordSys   coordinate system defined by OBJ file; Yup when not specified."
1751            "\n\t\t:   -resultCoordSys result coordinate system; Zup when not specified."
1752            "\n\t\t:   -singlePrecision truncate vertex data to single precision during read; FALSE by default."
1753            "\n\t\t:   -listExternalFiles do not read mesh and only list external files."
1754            "\n\t\t:   -noCreateDoc    read into existing XDE document.",
1755                    __FILE__, ReadObj, g);
1756   theCommands.Add ("readobj",
1757                    "readobj shape file [-fileCoordSys {Zup|Yup}] [-fileUnit Unit]"
1758            "\n\t\t:                    [-resultCoordSys {Zup|Yup}] [-singlePrecision]"
1759            "\n\t\t:                    [-singleFace]"
1760            "\n\t\t: Same as ReadObj but reads OBJ file into a shape instead of a document."
1761            "\n\t\t:   -singleFace merge OBJ content into a single triangulation Face.",
1762            __FILE__, ReadObj, g);
1763
1764   theCommands.Add ("meshfromstl",     "creates MeshVS_Mesh from STL file",            __FILE__, createmesh,      g );
1765   theCommands.Add ("mesh3delem",      "creates 3d element mesh to test",              __FILE__, create3d,        g );
1766   theCommands.Add ("meshshadcolor",   "change MeshVS_Mesh shading color",             __FILE__, meshcolor,       g );
1767   theCommands.Add ("meshlinkcolor",   "change MeshVS_Mesh line color",                __FILE__, linecolor,       g );
1768   theCommands.Add ("meshmat",         "change MeshVS_Mesh material and transparency", __FILE__, meshmat,         g );
1769   theCommands.Add ("meshshrcoef",     "change MeshVS_Mesh shrink coeff",              __FILE__, shrink,          g );
1770   theCommands.Add ("meshclosed",      "meshclosed meshname (0/1) \nChange MeshVS_Mesh drawing mode. 0 - not closed object, 1 - closed object", __FILE__, closed, g);
1771   theCommands.Add ("meshshow",        "display MeshVS_Mesh object",                   __FILE__, mdisplay,        g );
1772   theCommands.Add ("meshhide",        "erase MeshVS_Mesh object",                     __FILE__, merase,          g );
1773   theCommands.Add ("meshhidesel",     "hide selected entities",                       __FILE__, hidesel,         g );
1774   theCommands.Add ("meshshowsel",     "show only selected entities",                  __FILE__, showonly,        g );
1775   theCommands.Add ("meshshowall",     "show all entities",                            __FILE__, showall,         g );
1776   theCommands.Add ("meshcolors",      "display color presentation",                   __FILE__, meshcolors,      g );
1777   theCommands.Add ("meshvectors",     "display sample vectors",                       __FILE__, meshvectors,     g );
1778   theCommands.Add ("meshtext",        "display text labels",                          __FILE__, meshtext,        g );
1779   theCommands.Add ("meshdeform",      "display deformed mesh",                        __FILE__, meshdeform,      g );
1780   theCommands.Add ("mesh_edge_width", "set width of edges",                           __FILE__, mesh_edge_width, g );
1781   theCommands.Add ("meshinfo",        "displays the number of nodes and triangles",   __FILE__, meshinfo,        g );
1782 }
1783
1784 //==============================================================================
1785 // XSDRAWSTLVRML::Factory
1786 //==============================================================================
1787 void XSDRAWSTLVRML::Factory(Draw_Interpretor& theDI)
1788 {
1789   XSDRAWIGES::InitSelect();
1790   XSDRAWIGES::InitToBRep(theDI);
1791   XSDRAWIGES::InitFromBRep(theDI);
1792   XSDRAWSTEP::InitCommands(theDI);
1793   XSDRAWSTLVRML::InitCommands(theDI);
1794   XSDRAW::LoadDraw(theDI);
1795 #ifdef OCCT_DEBUG
1796   theDI << "Draw Plugin : All TKXSDRAW commands are loaded\n";
1797 #endif
1798 }
1799
1800 // Declare entry point PLUGINFACTORY
1801 DPLUGIN(XSDRAWSTLVRML)
1802