0031687: Draw Harness, ViewerTest - extend command vrenderparams with option updating...
[occt.git] / src / XSDRAWSTLVRML / XSDRAWSTLVRML.cxx
CommitLineData
b311480e 1// Created on: 2000-05-30
2// Created by: Sergey MOZOKHIN
973c2be1 3// Copyright (c) 2000-2014 OPEN CASCADE SAS
b311480e 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
b311480e 6//
d5f74e42 7// This library is free software; you can redistribute it and/or modify it under
8// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 9// by the Free Software Foundation, with special exception defined in the file
10// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11// distribution for complete text of the license and disclaimer of any warranty.
b311480e 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
7fd59977 15
42cf5bc1 16
7fd59977 17#include <AIS_InteractiveContext.hxx>
42cf5bc1 18#include <Aspect_TypeOfMarker.hxx>
19#include <Bnd_Box.hxx>
4178b353 20#include <BRep_Builder.hxx>
42cf5bc1 21#include <DBRep.hxx>
0a419c51 22#include <DDocStd.hxx>
23#include <DDocStd_DrawDocument.hxx>
7fd59977 24#include <Draw.hxx>
42cf5bc1 25#include <Draw_Interpretor.hxx>
26#include <Draw_PluginMacro.hxx>
9c6afe19 27#include <Draw_ProgressIndicator.hxx>
7fd59977 28#include <Graphic3d_MaterialAspect.hxx>
42cf5bc1 29#include <MeshVS_DataMapOfIntegerAsciiString.hxx>
30#include <MeshVS_DeformedDataSource.hxx>
7fd59977 31#include <MeshVS_Drawer.hxx>
32#include <MeshVS_DrawerAttribute.hxx>
42cf5bc1 33#include <MeshVS_ElementalColorPrsBuilder.hxx>
34#include <MeshVS_Mesh.hxx>
7fd59977 35#include <MeshVS_MeshEntityOwner.hxx>
42cf5bc1 36#include <MeshVS_MeshPrsBuilder.hxx>
709e97a0 37#include <MeshVS_NodalColorPrsBuilder.hxx>
42cf5bc1 38#include <MeshVS_PrsBuilder.hxx>
39#include <MeshVS_TextPrsBuilder.hxx>
709e97a0 40#include <MeshVS_VectorPrsBuilder.hxx>
42cf5bc1 41#include <OSD_Path.hxx>
42#include <Quantity_Color.hxx>
43#include <Quantity_HArray1OfColor.hxx>
7fd59977 44#include <Quantity_NameOfColor.hxx>
0a419c51 45#include <RWGltf_CafReader.hxx>
01b2f506 46#include <RWGltf_CafWriter.hxx>
42cf5bc1 47#include <RWStl.hxx>
4151c94d 48#include <RWObj.hxx>
49#include <RWObj_CafReader.hxx>
42cf5bc1 50#include <SelectMgr_SelectionManager.hxx>
51#include <Standard_ErrorHandler.hxx>
52#include <StdSelect_ViewerSelector3d.hxx>
53#include <StlAPI.hxx>
54#include <StlAPI_Writer.hxx>
7fd59977 55#include <TColgp_SequenceOfXYZ.hxx>
42cf5bc1 56#include <TCollection_AsciiString.hxx>
57#include <TColStd_Array1OfReal.hxx>
7fd59977 58#include <TColStd_HPackedMapOfInteger.hxx>
59#include <TColStd_MapIteratorOfPackedMapOfInteger.hxx>
0a419c51 60#include <TDataStd_Name.hxx>
61#include <TDocStd_Application.hxx>
4178b353 62#include <TopoDS_Face.hxx>
42cf5bc1 63#include <TopoDS_Shape.hxx>
0a419c51 64#include <UnitsAPI.hxx>
1d441d1a 65#include <UnitsMethods.hxx>
42cf5bc1 66#include <V3d_View.hxx>
67#include <ViewerTest.hxx>
68#include <VrmlAPI.hxx>
69#include <VrmlAPI_Writer.hxx>
70#include <VrmlData_DataMapOfShapeAppearance.hxx>
7fd59977 71#include <VrmlData_Scene.hxx>
72#include <VrmlData_ShapeConvert.hxx>
01b2f506 73#include <XCAFDoc_DocumentTool.hxx>
74#include <XCAFDoc_ShapeTool.hxx>
42cf5bc1 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>
7fd59977 82
7fd59977 83#ifndef _STDIO_H
84#include <stdio.h>
85#endif
86
709e97a0 87extern Standard_Boolean VDisplayAISObject (const TCollection_AsciiString& theName,
88 const Handle(AIS_InteractiveObject)& theAISObj,
89 Standard_Boolean theReplaceIfExists = Standard_True);
90
0a419c51 91//=============================================================================
92//function : ReadGltf
93//purpose : Reads glTF file
94//=============================================================================
95static 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 && ViewerTest::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 && ViewerTest::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 std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
148 return 1;
149 }
150 }
151 if (aFilePath.IsEmpty())
152 {
153 std::cout << "Syntax error: wrong number of arguments\n";
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 std::cout << "Error: document with name " << aDestName << " does not exist\n";
170 return 1;
171 }
172 anApp->NewDocument (TCollection_ExtendedString ("BinXCAF"), aDoc);
173 }
174 else if (!toUseExistingDoc)
175 {
176 std::cout << "Error: document with name " << aDestName << " already exists\n";
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
01b2f506 211//=============================================================================
212//function : WriteGltf
213//purpose : Writes glTF file
214//=============================================================================
215static 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 && ViewerTest::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 std::cout << "Syntax error at '" << anArgCase << "'\n";
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 std::cout << "Syntax error: '" << aNameVar << "' is not a shape nor document\n";
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 std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
297 return 1;
298 }
299 }
300 if (aGltfFilePath.IsEmpty())
301 {
302 std::cout << "Syntax error: wrong number of arguments\n";
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
7fd59977 322static Standard_Integer writestl
323(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
324{
b9c1e440 325 if (argc < 3 || argc > 4) {
709e97a0 326 di << "Use: " << argv[0]
586db386 327 << " shape file [ascii/binary (0/1) : 1 by default]\n";
416d4426 328 } else {
329 TopoDS_Shape aShape = DBRep::Get(argv[1]);
48a06a30 330 Standard_Boolean isASCIIMode = Standard_False;
b9c1e440 331 if (argc == 4) {
91322f44 332 isASCIIMode = (Draw::Atoi(argv[3]) == 0);
68bc5ed7 333 }
48a06a30 334 StlAPI_Writer aWriter;
335 aWriter.ASCIIMode() = isASCIIMode;
1fc1a207 336 Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator(di, 1);
337 Standard_Boolean isOK = aWriter.Write (aShape, argv[2], aProgress);
4178b353 338 if (!isOK)
339 di << "** Error **: Mesh writing has been failed.\n";
7fd59977 340 }
341 return 0;
342}
343
4178b353 344//=============================================================================
345//function : readstl
346//purpose : Reads stl file
347//=============================================================================
348static Standard_Integer readstl(Draw_Interpretor& theDI,
349 Standard_Integer theArgc,
350 const char** theArgv)
7fd59977 351{
4c4420df 352 TCollection_AsciiString aShapeName, aFilePath;
353 bool toCreateCompOfTris = false;
354 for (Standard_Integer anArgIter = 1; anArgIter < theArgc; ++anArgIter)
4178b353 355 {
4c4420df 356 TCollection_AsciiString anArg (theArgv[anArgIter]);
357 anArg.LowerCase();
358 if (aShapeName.IsEmpty())
4178b353 359 {
4c4420df 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 && ViewerTest::ParseOnOff (theArgv[anArgIter + 1], toCreateCompOfTris))
371 {
372 ++anArgIter;
373 }
4178b353 374 }
375 else
376 {
4c4420df 377 std::cout << "Syntax error: unknown argument '" << theArgv[anArgIter] << "'\n";
378 return 1;
4178b353 379 }
380 }
4c4420df 381 if (aFilePath.IsEmpty())
382 {
383 std::cout << "Syntax error: not enough arguments\n";
384 return 1;
385 }
4178b353 386
4c4420df 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);
7fd59977 407 return 0;
408}
409
4151c94d 410//! Parse RWMesh_CoordinateSystem enumeration.
411static 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//=============================================================================
435static 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 std::cout << "Syntax error: wrong length unit '" << aUnitStr << "'\n";
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 std::cout << "Syntax error: unknown coordinate system '" << theArgVec[anArgIter] << "'\n";
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 std::cout << "Syntax error: unknown coordinate system '" << theArgVec[anArgIter] << "'\n";
483 return 1;
484 }
485 }
486 else if (anArgCase == "-singleprecision"
487 || anArgCase == "-singleprec")
488 {
489 isSinglePrecision = Standard_True;
490 if (anArgIter + 1 < theNbArgs
491 && ViewerTest::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 && ViewerTest::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 std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
532 return 1;
533 }
534 }
535 if (aFilePath.IsEmpty())
536 {
537 std::cout << "Syntax error: wrong number of arguments\n";
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 std::cout << "Error: document with name " << aDestName << " does not exist\n";
554 return 1;
555 }
556 anApp->NewDocument (TCollection_ExtendedString ("BinXCAF"), aDoc);
557 }
558 else if (!toUseExistingDoc)
559 {
560 std::cout << "Error: document with name " << aDestName << " already exists\n";
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
7fd59977 614static Standard_Integer writevrml
615(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
616{
f5fa6b33 617 if (argc < 3 || argc > 5)
618 {
586db386 619 di << "wrong number of parameters\n";
f5fa6b33 620 return 0;
7fd59977 621 }
f5fa6b33 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
c42ef165 650 if (!writer.Write(aShape, argv[2], aVersion))
651 {
652 di << "Error: File " << argv[2] << " was not written\n";
653 }
f5fa6b33 654
7fd59977 655 return 0;
656}
657
658//=======================================================================
659//function : loadvrml
9c6afe19 660//purpose :
7fd59977 661//=======================================================================
662
663static 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 {
709e97a0 668 TopoDS_Shape aShape ;
669 VrmlData_DataMapOfShapeAppearance aShapeAppMap;
7fd59977 670
671 //-----------------------------------------------------------
04232180 672 std::filebuf aFic;
673 std::istream aStream (&aFic);
7fd59977 674
04232180 675 if (aFic.open(argv[2], std::ios::in)) {
7fd59977 676
b569f2a3 677 // Get path of the VRML file.
709e97a0 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())
b569f2a3 683 {
709e97a0 684 if (!aDisk.IsEmpty())
685 aVrmlDir = aDisk;
b569f2a3 686 else
709e97a0 687 aVrmlDir.Clear();
688 aTrek.ChangeAll('|', '/');
689 aVrmlDir += aTrek;
b569f2a3 690 }
691
7fd59977 692 VrmlData_Scene aScene;
1d441d1a 693 Standard_Real anOCCUnit = UnitsMethods::GetCasCadeLengthUnit();
694 aScene.SetLinearScale(1000. / anOCCUnit);
7fd59977 695
709e97a0 696 aScene.SetVrmlDir (aVrmlDir);
7fd59977 697 aScene << aStream;
698 const char * aStr = 0L;
699 switch (aScene.Status()) {
700
701 case VrmlData_StatusOK:
702 {
709e97a0 703 aShape = aScene.GetShape(aShapeAppMap);
7fd59977 704 break;
705 }
566f8441 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;
7fd59977 725 }
726 if (aStr) {
727 di << " ++ VRML Error: " << aStr << " in line "
728 << aScene.GetLineError() << "\n";
729 }
730 else {
709e97a0 731 DBRep::Set(argv[1],aShape);
7fd59977 732 }
733 }
734 else {
586db386 735 di << "cannot open file\n";
7fd59977 736 }
737
738
739 //-----------------------------------------------------------
740 }
741 return 0;
742}
743
7fd59977 744//-----------------------------------------------------------------------------
745static Standard_Integer createmesh
746(Draw_Interpretor& di, Standard_Integer argc, const char** argv )
747{
7fd59977 748 if (argc<3)
749 {
586db386 750 di << "Wrong number of parameters\n";
751 di << "Use: " << argv[0] << " <mesh name> <stl file>\n";
709e97a0 752 return 0;
753 }
754
755 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
756 if (aContext.IsNull())
757 {
586db386 758 di << "No active view. Please call 'vinit' first\n";
709e97a0 759 return 0;
7fd59977 760 }
761
9c6afe19 762 // Progress indicator
7fd59977 763 OSD_Path aFile( argv[2] );
9c6afe19 764 Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator (di, 1);
4178b353 765 Handle(Poly_Triangulation) aSTLMesh = RWStl::ReadFile (aFile, aProgress);
7fd59977 766
586db386 767 di << "Reading OK...\n";
7fd59977 768 Handle( XSDRAWSTLVRML_DataSource ) aDS = new XSDRAWSTLVRML_DataSource( aSTLMesh );
586db386 769 di << "Data source is created successful\n";
7fd59977 770 Handle( MeshVS_Mesh ) aMesh = new MeshVS_Mesh();
586db386 771 di << "MeshVS_Mesh is created successful\n";
7fd59977 772
773 aMesh->SetDataSource( aDS );
774 aMesh->AddBuilder( new MeshVS_MeshPrsBuilder( aMesh.operator->() ), Standard_True );
7fd59977 775
709e97a0 776 aMesh->GetDrawer()->SetColor( MeshVS_DA_EdgeColor, Quantity_NOC_YELLOW );
7fd59977 777
778 // Hide all nodes by default
779 Handle(TColStd_HPackedMapOfInteger) aNodes = new TColStd_HPackedMapOfInteger();
4178b353 780 Standard_Integer aLen = aSTLMesh->Nodes().Length();
709e97a0 781 for ( Standard_Integer anIndex = 1; anIndex <= aLen; anIndex++ )
7fd59977 782 aNodes->ChangeMap().Add( anIndex );
783 aMesh->SetHiddenNodes( aNodes );
709e97a0 784 aMesh->SetSelectableNodes ( aNodes );
7fd59977 785
709e97a0 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();
7fd59977 793
709e97a0 794 return 0;
795}
796//-----------------------------------------------------------------------------
797
798static Standard_Integer create3d
799(Draw_Interpretor& di, Standard_Integer argc, const char** argv )
800{
801 if (argc<2)
7fd59977 802 {
586db386 803 di << "Wrong number of parameters\n";
804 di << "Use: " << argv[0] << " <mesh name>\n";
709e97a0 805 return 0;
7fd59977 806 }
807
709e97a0 808 Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
809 if (aContext.IsNull())
810 {
586db386 811 di << "No active view. Please call 'vinit' first\n";
709e97a0 812 return 0;
813 }
814
815 Handle( XSDRAWSTLVRML_DataSource3D ) aDS = new XSDRAWSTLVRML_DataSource3D();
586db386 816 di << "Data source is created successful\n";
709e97a0 817 Handle( MeshVS_Mesh ) aMesh = new MeshVS_Mesh();
586db386 818 di << "MeshVS_Mesh is created successful\n";
709e97a0 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);
7fd59977 834 aContext->Deactivate( aMesh );
835
836 Draw::Set( argv[1], new XSDRAWSTLVRML_DrawableMesh( aMesh ) );
709e97a0 837 Handle( V3d_View ) aView = ViewerTest::CurrentView();
838 if ( !aView.IsNull() )
839 aView->FitAll();
7fd59977 840
841 return 0;
842}
709e97a0 843
844Handle( MeshVS_Mesh ) getMesh( const char* theName, Draw_Interpretor& di)
7fd59977 845{
846 Handle( XSDRAWSTLVRML_DrawableMesh ) aDrawMesh =
709e97a0 847 Handle( XSDRAWSTLVRML_DrawableMesh )::DownCast( Draw::Get( theName ) );
7fd59977 848
849 if( aDrawMesh.IsNull() )
850 {
586db386 851 di << "There is no such object\n";
7fd59977 852 return NULL;
853 }
854 else
855 {
856 Handle( MeshVS_Mesh ) aMesh = aDrawMesh->GetMesh();
857 if( aMesh.IsNull() )
858 {
586db386 859 di << "There is invalid mesh\n";
7fd59977 860 return NULL;
861 }
862 else
863 return aMesh;
864 }
865}
7fd59977 866
7fd59977 867//-----------------------------------------------------------------------------
868static Standard_Integer setcolor
709e97a0 869(Draw_Interpretor& di, Standard_Integer argc, const char** argv, Standard_Integer theParam )
7fd59977 870{
871 if (argc<5)
586db386 872 di << "Wrong number of parameters\n";
7fd59977 873 else
874 {
875 Handle( MeshVS_Mesh ) aMesh = getMesh( argv[1], di );
876 if( !aMesh.IsNull() )
877 {
709e97a0 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 ) );
7fd59977 883
884 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
885
886 if( aContext.IsNull() )
586db386 887 di << "The context is null\n";
7fd59977 888 else
0577ae8c 889 aContext->Redisplay (aMesh, Standard_True);
7fd59977 890 }
891 }
892 return 0;
893}
894//-----------------------------------------------------------------------------
895static Standard_Integer meshcolor
709e97a0 896(Draw_Interpretor& theInterp, Standard_Integer argc, const char** argv )
7fd59977 897{
709e97a0 898 return setcolor( theInterp, argc, argv, MeshVS_DA_InteriorColor );
7fd59977 899}
900//-----------------------------------------------------------------------------
901static Standard_Integer linecolor
709e97a0 902(Draw_Interpretor& theInterp, Standard_Integer argc, const char** argv )
7fd59977 903{
709e97a0 904 return setcolor( theInterp, argc, argv, MeshVS_DA_EdgeColor );
7fd59977 905}
906//-----------------------------------------------------------------------------
907static Standard_Integer meshmat
908(Draw_Interpretor& di, Standard_Integer argc, const char** argv )
909{
910 if (argc<3)
586db386 911 di << "Wrong number of parameters\n";
7fd59977 912 else
913 {
914 Handle( MeshVS_Mesh ) aMesh = getMesh( argv[1], di );
915 if( !aMesh.IsNull() )
916 {
709e97a0 917 Standard_Integer aMaterial = Draw::Atoi (argv[2]);
7fd59977 918
919 Graphic3d_MaterialAspect aMatAsp =
709e97a0 920 (Graphic3d_MaterialAspect)(Graphic3d_NameOfMaterial)aMaterial;
7fd59977 921
709e97a0 922 if (argc == 4)
923 {
924 Standard_Real aTransparency = Draw::Atof(argv[3]);
4e1bc39a 925 aMatAsp.SetTransparency (Standard_ShortReal (aTransparency));
709e97a0 926 }
7fd59977 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() )
586db386 933 di << "The context is null\n";
7fd59977 934 else
0577ae8c 935 aContext->Redisplay (aMesh, Standard_True);
7fd59977 936 }
937 }
938 return 0;
939}
940//-----------------------------------------------------------------------------
941static Standard_Integer shrink
942(Draw_Interpretor& di, Standard_Integer argc, const char** argv )
943{
944 if (argc<3)
586db386 945 di << "Wrong number of parameters\n";
7fd59977 946 else
947 {
948 Handle( MeshVS_Mesh ) aMesh = getMesh( argv[1], di );
949 if( !aMesh.IsNull() )
950 {
709e97a0 951 Standard_Real aShrinkCoeff = Draw::Atof (argv[2]);
952 aMesh->GetDrawer()->SetDouble( MeshVS_DA_ShrinkCoeff, aShrinkCoeff );
7fd59977 953
954 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
955
956 if( aContext.IsNull() )
586db386 957 di << "The context is null\n";
7fd59977 958 else
0577ae8c 959 aContext->Redisplay (aMesh, Standard_True);
7fd59977 960 }
961 }
962 return 0;
963}
c3715b74 964
965//-----------------------------------------------------------------------------
966static Standard_Integer closed (Draw_Interpretor& theDI, Standard_Integer theArgc, const char** theArgv)
967{
968 if (theArgc < 3)
969 {
586db386 970 theDI << "Wrong number of parameters.\n";
c3715b74 971 }
972 else
973 {
974 Handle(MeshVS_Mesh) aMesh = getMesh (theArgv[1], theDI);
975 if (!aMesh.IsNull())
976 {
dde68833 977 Standard_Boolean aFlag = Draw::Atoi (theArgv[2]) != 0;
c3715b74 978 aMesh->GetDrawer()->SetBoolean (MeshVS_DA_SupressBackFaces, aFlag);
979
980 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
981 if (aContext.IsNull())
982 {
586db386 983 theDI << "The context is null\n";
c3715b74 984 }
985 else
986 {
0577ae8c 987 aContext->Redisplay (aMesh, Standard_True);
c3715b74 988 }
989 }
990 }
991 return 0;
992}
993
7fd59977 994//-----------------------------------------------------------------------------
995
996static Standard_Integer mdisplay
997(Draw_Interpretor& di, Standard_Integer argc, const char** argv )
998{
999 if (argc<2)
586db386 1000 di << "Wrong number of parameters\n";
7fd59977 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() )
586db386 1009 di << "The context is null\n";
7fd59977 1010 else
1011 {
0577ae8c 1012 aContext->Display (aMesh, Standard_True);
7fd59977 1013 }
1014 }
1015 }
1016 return 0;
1017}
1018//-----------------------------------------------------------------------------
1019static Standard_Integer merase
1020(Draw_Interpretor& di, Standard_Integer argc, const char** argv )
1021{
1022 if (argc<2)
586db386 1023 di << "Wrong number of parameters\n";
7fd59977 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() )
586db386 1032 di << "The context is null\n";
7fd59977 1033 else
1034 {
0577ae8c 1035 aContext->Erase (aMesh, Standard_True);
7fd59977 1036 }
1037 }
1038 else
586db386 1039 di << "Mesh is null\n";
7fd59977 1040 }
1041 return 0;
1042}
1043//-----------------------------------------------------------------------------
1044static Standard_Integer hidesel
1045(Draw_Interpretor& di, Standard_Integer argc, const char** argv )
1046{
709e97a0 1047 if (argc<2)
7fd59977 1048 {
586db386 1049 di << "Wrong number of parameters\n";
1050 di << "Use: " << argv[0] << " <mesh name>\n";
7fd59977 1051 return 0;
1052 }
1053
7fd59977 1054 Handle( AIS_InteractiveContext ) aContext = ViewerTest::GetAISContext();
1055 Handle( MeshVS_Mesh ) aMesh = getMesh( argv[1], di );
1056 if( aMesh.IsNull() )
1057 {
586db386 1058 di << "The mesh is invalid\n";
7fd59977 1059 return 0;
1060 }
1061
1062 if( aContext.IsNull() )
586db386 1063 di << "The context is null\n";
7fd59977 1064 else
1065 {
1066 Handle(TColStd_HPackedMapOfInteger) aHiddenNodes = aMesh->GetHiddenNodes();
709e97a0 1067 if (aHiddenNodes.IsNull())
1068 {
1069 aHiddenNodes = new TColStd_HPackedMapOfInteger();
1070 }
7fd59977 1071 Handle(TColStd_HPackedMapOfInteger) aHiddenElements = aMesh->GetHiddenElems();
709e97a0 1072 if (aHiddenElements.IsNull())
1073 {
1074 aHiddenElements = new TColStd_HPackedMapOfInteger();
1075 }
7fd59977 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() )
eafb234b 1081 {
7fd59977 1082 if( anOwner->Type()==MeshVS_ET_Node )
eafb234b 1083 {
7fd59977 1084 aHiddenNodes->ChangeMap().Add( anOwner->ID() );
eafb234b 1085 }
7fd59977 1086 else
eafb234b 1087 {
7fd59977 1088 aHiddenElements->ChangeMap().Add( anOwner->ID() );
eafb234b 1089 }
1090 }
7fd59977 1091 }
0577ae8c 1092 aContext->ClearSelected (Standard_False);
7fd59977 1093 aMesh->SetHiddenNodes( aHiddenNodes );
1094 aMesh->SetHiddenElems( aHiddenElements );
0577ae8c 1095 aContext->Redisplay (aMesh, Standard_True);
7fd59977 1096 }
1097
1098 return 0;
1099}
1100//-----------------------------------------------------------------------------
1101static Standard_Integer showonly
1102(Draw_Interpretor& di, Standard_Integer argc, const char** argv )
1103{
709e97a0 1104 if (argc<2)
7fd59977 1105 {
586db386 1106 di << "Wrong number of parameters\n";
1107 di << "Use: " << argv[0] << " <mesh name>\n";
7fd59977 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 {
586db386 1116 di << "The mesh is invalid\n";
7fd59977 1117 return 0;
1118 }
1119
1120 if( aContext.IsNull() )
586db386 1121 di << "The context is null\n";
7fd59977 1122 else
1123 {
9c6afe19 1124 Handle(TColStd_HPackedMapOfInteger) aHiddenNodes =
7fd59977 1125 new TColStd_HPackedMapOfInteger(aMesh->GetDataSource()->GetAllNodes());
9c6afe19 1126 Handle(TColStd_HPackedMapOfInteger) aHiddenElements =
7fd59977 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() )
eafb234b 1133 {
709e97a0 1134 if( anOwner->Type() == MeshVS_ET_Node )
eafb234b 1135 {
7fd59977 1136 aHiddenNodes->ChangeMap().Remove( anOwner->ID() );
eafb234b 1137 }
7fd59977 1138 else
eafb234b 1139 {
7fd59977 1140 aHiddenElements->ChangeMap().Remove( anOwner->ID() );
eafb234b 1141 }
1142 }
7fd59977 1143 }
1144 aMesh->SetHiddenNodes( aHiddenNodes );
1145 aMesh->SetHiddenElems( aHiddenElements );
0577ae8c 1146 aContext->Redisplay (aMesh, Standard_True);
7fd59977 1147 }
1148
1149 return 0;
1150}
1151//-----------------------------------------------------------------------------
1152static Standard_Integer showall
1153(Draw_Interpretor& di, Standard_Integer argc, const char** argv )
1154{
709e97a0 1155 if (argc<2)
7fd59977 1156 {
586db386 1157 di << "Wrong number of parameters\n";
1158 di << "Use: " << argv[0] << " <mesh name>\n";
7fd59977 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 {
586db386 1166 di << "The mesh is invalid\n";
7fd59977 1167 return 0;
1168 }
1169
1170 if( aContext.IsNull() )
586db386 1171 di << "The context is null\n";
7fd59977 1172 else
1173 {
709e97a0 1174 aMesh->SetHiddenNodes( new TColStd_HPackedMapOfInteger() );
1175 aMesh->SetHiddenElems( new TColStd_HPackedMapOfInteger() );
0577ae8c 1176 aContext->Redisplay (aMesh, Standard_True);
7fd59977 1177 }
1178
1179 return 0;
1180}
7fd59977 1181
7fd59977 1182//-----------------------------------------------------------------------------
9c6afe19
RK
1183static Standard_Integer meshcolors( Draw_Interpretor& di,
1184 Standard_Integer argc,
7fd59977 1185 const char** argv )
1186{
1187 try
1188 {
1189 OCC_CATCH_SIGNALS
709e97a0 1190 if ( argc < 4 )
7fd59977 1191 {
586db386 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";
9c6afe19 1201
7fd59977 1202 return 0;
1203 }
1204
1205 Handle( MeshVS_Mesh ) aMesh = getMesh( argv[ 1 ], di );
1206
1207 if ( aMesh.IsNull() )
1208 {
586db386 1209 di << "Mesh not found\n";
7fd59977 1210 return 0;
1211 }
1212 Handle(AIS_InteractiveContext) anIC = ViewerTest::GetAISContext();
1213 if ( anIC.IsNull() )
1214 {
586db386 1215 di << "The context is null\n";
7fd59977 1216 return 0;
1217 }
1218 if( !aMesh.IsNull() )
1219 {
1220 TCollection_AsciiString aMode = TCollection_AsciiString (argv[2]);
87432b82 1221 Quantity_Color aColor1(Quantity_NOC_BLUE1);
1222 Quantity_Color aColor2(Quantity_NOC_RED1);
3ba3388b 1223 if( aMode.IsEqual("elem1") || aMode.IsEqual("elem2") || aMode.IsEqual("nodal") || aMode.IsEqual("nodaltex") || aMode.IsEqual("none") )
7fd59977 1224 {
1225 Handle(MeshVS_PrsBuilder) aTempBuilder;
709e97a0 1226 Standard_Integer aReflection = Draw::Atoi(argv[3]);
7fd59977 1227
709e97a0 1228 for (Standard_Integer aCount = 0 ; aCount < aMesh->GetBuildersCount(); aCount++ ){
a9dde4a3 1229 aTempBuilder = aMesh->FindBuilder("MeshVS_ElementalColorPrsBuilder");
7fd59977 1230 if( !aTempBuilder.IsNull())
1231 aMesh->RemoveBuilderById(aTempBuilder->GetId());
1232
a9dde4a3 1233 aTempBuilder = aMesh->FindBuilder("MeshVS_NodalColorPrsBuilder");
7fd59977 1234 if( !aTempBuilder.IsNull())
1235 aMesh->RemoveBuilderById(aTempBuilder->GetId());
1236 }
1237
1238 if( aMode.IsEqual("elem1") || aMode.IsEqual("elem2") )
1239 {
9c6afe19 1240 Handle(MeshVS_ElementalColorPrsBuilder) aBuilder = new MeshVS_ElementalColorPrsBuilder(
7fd59977 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
9c6afe19 1259
7fd59977 1260 if( aMode.IsEqual("nodal") )
1261 {
9c6afe19 1262 Handle(MeshVS_NodalColorPrsBuilder) aBuilder = new MeshVS_NodalColorPrsBuilder(
7fd59977 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 {
9c6afe19 1272 Quantity_Color aColor( (Quantity_NameOfColor)(
7fd59977 1273 anIter.Key() % Quantity_NOC_WHITE ) );
1274 aBuilder->SetColor( anIter.Key(), aColor );
1275 }
1276 aMesh->AddBuilder( aBuilder, Standard_True );
1277 }
1278
3ba3388b
A
1279 if(aMode.IsEqual("nodaltex"))
1280 {
1281 // assign nodal builder to the mesh
9c6afe19 1282 Handle(MeshVS_NodalColorPrsBuilder) aBuilder = new MeshVS_NodalColorPrsBuilder(
3ba3388b
A
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;
a738b534 1321 } catch(Standard_Failure const&) {
3ba3388b
A
1322 aScaleValue = 0;
1323 }
1324
9c6afe19 1325 aScaleMap.Bind(anIter.Key(), aScaleValue);
3ba3388b
A
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);
3ba3388b
A
1333 }
1334
dde68833 1335 aMesh->GetDrawer()->SetBoolean (MeshVS_DA_ColorReflection, aReflection != 0);
7fd59977 1336
0577ae8c 1337 anIC->Redisplay (aMesh, Standard_True);
7fd59977 1338 }
1339 else
9c6afe19 1340 {
586db386 1341 di << "Wrong mode name\n";
7fd59977 1342 return 0;
1343 }
1344 }
1345 }
a738b534 1346 catch ( Standard_Failure const& )
7fd59977 1347 {
586db386 1348 di << "Error\n";
7fd59977 1349 }
1350
1351 return 0;
1352}
1353//-----------------------------------------------------------------------------
709e97a0 1354static Standard_Integer meshvectors( Draw_Interpretor& di,
1355 Standard_Integer argc,
1356 const char** argv )
1357{
1358 if ( argc < 3 )
1359 {
586db386 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";
709e97a0 1366
1367 return 0;
1368 }
1369
1370 Handle( MeshVS_Mesh ) aMesh = getMesh( argv[ 1 ], di );
1371
1372 if ( aMesh.IsNull() )
1373 {
586db386 1374 di << "Mesh not found\n";
709e97a0 1375 return 0;
1376 }
1377 Handle(AIS_InteractiveContext) anIC = ViewerTest::GetAISContext();
1378 if ( anIC.IsNull() )
1379 {
586db386 1380 di << "The context is null\n";
709e97a0 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 aColor = ViewerTest::GetColorFromName(argv[anIdx]);
1406 }
1407 else if (aParam == "-arrowpart")
1408 {
1409 anArrowPart = Draw::Atof(argv[anIdx]);
1410 }
1411 else if (aParam == "-issimple")
1412 {
dde68833 1413 isSimplePrs = Draw::Atoi(argv[anIdx]) != 0;
709e97a0 1414 }
1415 aParam.Clear();
1416 }
1417 else if (argv[anIdx][0] == '-')
1418 {
1419 aParam = argv[anIdx];
1420 }
1421 }
1422
1423 if( !aMode.IsEqual("elem") && !aMode.IsEqual("nodal") && !aMode.IsEqual("none") )
1424 {
586db386 1425 di << "Wrong mode name\n";
709e97a0 1426 return 0;
1427 }
1428
1429 Handle(MeshVS_PrsBuilder) aTempBuilder;
1430
a9dde4a3 1431 aTempBuilder = aMesh->FindBuilder("MeshVS_VectorPrsBuilder");
709e97a0 1432 if( !aTempBuilder.IsNull())
1433 aMesh->RemoveBuilderById(aTempBuilder->GetId());
1434
1435 if( !aMode.IsEqual("none") )
1436 {
1437 Handle(MeshVS_VectorPrsBuilder) aBuilder = new MeshVS_VectorPrsBuilder( aMesh.operator->(),
1438 aMaxlen,
1439 aColor,
1440 MeshVS_DMF_VectorDataPrs,
1441 0,
1442 -1,
1443 MeshVS_BP_Vector,
1444 isSimplePrs);
1445
1446 Standard_Boolean anIsElement = aMode.IsEqual("elem");
1447 const TColStd_PackedMapOfInteger& anAllIDs = anIsElement ? aMesh->GetDataSource()->GetAllElements() :
1448 aMesh->GetDataSource()->GetAllNodes();
1449
1450 Standard_Integer aNbNodes;
1451 MeshVS_EntityType aEntType;
1452
f4dee9bb 1453 TColStd_Array1OfReal aCoords(1, 3);
1454 aCoords.Init (0.);
709e97a0 1455 TColStd_MapIteratorOfPackedMapOfInteger anIter( anAllIDs );
1456 for ( ; anIter.More(); anIter.Next() )
1457 {
f4dee9bb 1458 Standard_Boolean IsValidData = Standard_False;
90b85826 1459 if (anIsElement) {
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));
1463 } else
f4dee9bb 1464 IsValidData = aMesh->GetDataSource()->GetGeom(anIter.Key(), Standard_False, aCoords, aNbNodes, aEntType);
709e97a0 1465
f4dee9bb 1466 gp_Vec aNorm;
1467 if(IsValidData)
1468 {
1469 aNorm = gp_Vec(aCoords.Value(1), aCoords.Value(2), aCoords.Value(3));
1470 if(aNorm.Magnitude() < gp::Resolution())
1471 {
1472 aNorm = gp_Vec(0,0,1); //method GetGeom(...) returns coordinates of nodes
1473 }
1474 }
1475 else
1476 {
709e97a0 1477 aNorm = gp_Vec(0,0,1);
f4dee9bb 1478 }
709e97a0 1479 aBuilder->SetVector(anIsElement, anIter.Key(), aNorm.Normalized());
1480 }
1481
1482 aMesh->AddBuilder( aBuilder, Standard_False );
1483 aMesh->GetDrawer()->SetDouble ( MeshVS_DA_VectorArrowPart, anArrowPart );
1484 }
1485
0577ae8c 1486 anIC->Redisplay (aMesh, Standard_True);
709e97a0 1487
1488 return 0;
1489}
1490//-----------------------------------------------------------------------------
1491
1492static Standard_Integer meshtext( Draw_Interpretor& di,
1493 Standard_Integer argc,
1494 const char** argv )
1495{
1496 if ( argc < 2 )
1497 {
586db386 1498 di << "Wrong number of parameters\n";
1499 di << "Use : meshtext <mesh name>\n";
709e97a0 1500 return 0;
1501 }
1502
1503 Handle( MeshVS_Mesh ) aMesh = getMesh( argv[ 1 ], di );
1504
1505 if ( aMesh.IsNull() )
1506 {
586db386 1507 di << "Mesh not found\n";
709e97a0 1508 return 0;
1509 }
1510
1511 Handle(AIS_InteractiveContext) anIC = ViewerTest::GetAISContext();
1512 if ( anIC.IsNull() )
1513 {
586db386 1514 di << "The context is null\n";
709e97a0 1515 return 0;
1516 }
1517
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 ) );
1523 }
1524
1525 Handle(MeshVS_TextPrsBuilder) aTextBuilder = new MeshVS_TextPrsBuilder( aMesh.operator->(), 20., Quantity_NOC_YELLOW );
1526 aTextBuilder->SetTexts( Standard_True, aLabels );
1527 aMesh->AddBuilder( aTextBuilder );
1528
1529 return 0;
1530}
1531
1532static Standard_Integer meshdeform( Draw_Interpretor& di,
1533 Standard_Integer argc,
1534 const char** argv )
1535{
1536 if ( argc < 3 )
1537 {
586db386 1538 di << "Wrong number of parameters\n";
1539 di << "Use : meshdeform <mesh name> < -mode {on|off} > [-scale scalefactor]\n";
709e97a0 1540 return 0;
1541 }
1542
1543 Handle( MeshVS_Mesh ) aMesh = getMesh( argv[ 1 ], di );
1544
1545 if ( aMesh.IsNull() )
1546 {
586db386 1547 di << "Mesh not found\n";
709e97a0 1548 return 0;
1549 }
1550 Handle(AIS_InteractiveContext) anIC = ViewerTest::GetAISContext();
1551 if ( anIC.IsNull() )
1552 {
586db386 1553 di << "The context is null\n";
709e97a0 1554 return 0;
1555 }
1556
1557 TCollection_AsciiString aParam;
1558 TCollection_AsciiString aMode("off");
1559 Standard_Real aScale(1.0);
1560
1561 for (Standard_Integer anIdx = 2; anIdx < argc; anIdx++)
1562 {
1563 if (!aParam.IsEmpty())
1564 {
1565 if (aParam == "-mode")
1566 {
1567 aMode = argv[anIdx];
1568 }
1569 else if (aParam == "-scale")
1570 {
1571 aScale = Draw::Atof(argv[anIdx]);
1572 }
1573 aParam.Clear();
1574 }
1575 else if (argv[anIdx][0] == '-')
1576 {
1577 aParam = argv[anIdx];
1578 }
1579 }
1580
1581 if(!aMode.IsEqual("on") && !aMode.IsEqual("off"))
1582 {
586db386 1583 di << "Wrong mode name\n";
709e97a0 1584 return 0;
1585 }
1586
1587 Handle ( MeshVS_DeformedDataSource ) aDefDS =
1588 new MeshVS_DeformedDataSource( aMesh->GetDataSource() , aScale );
1589
1590 const TColStd_PackedMapOfInteger& anAllIDs = aMesh->GetDataSource()->GetAllNodes();
1591
1592 Standard_Integer aNbNodes;
1593 MeshVS_EntityType aEntType;
1594
1595 TColStd_MapIteratorOfPackedMapOfInteger anIter( anAllIDs );
1596 for ( ; anIter.More(); anIter.Next() )
1597 {
1598 TColStd_Array1OfReal aCoords(1, 3);
1599 aMesh->GetDataSource()->GetGeom(anIter.Key(), Standard_False, aCoords, aNbNodes, aEntType);
1600
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());
1605 }
1606
1607 aMesh->SetDataSource(aDefDS);
1608
0577ae8c 1609 anIC->Redisplay (aMesh, Standard_False);
709e97a0 1610
1611 Handle( V3d_View ) aView = ViewerTest::CurrentView();
1612 if ( !aView.IsNull() )
1613 aView->FitAll();
1614
1615 return 0;
1616}
7fd59977 1617
9c6afe19
RK
1618static Standard_Integer mesh_edge_width( Draw_Interpretor& di,
1619 Standard_Integer argc,
7fd59977 1620 const char** argv )
1621{
1622 try
1623 {
1624 OCC_CATCH_SIGNALS
1625 if ( argc < 3 )
1626 {
586db386 1627 di << "Wrong number of parameters\n";
1628 di << "Use : mesh_edge_width <mesh name> <width>\n";
7fd59977 1629 return 0;
1630 }
1631
1632 Handle(MeshVS_Mesh) aMesh = getMesh( argv[ 1 ], di );
1633 if ( aMesh.IsNull() )
1634 {
586db386 1635 di << "Mesh not found\n";
7fd59977 1636 return 0;
1637 }
1638
1639 const char* aWidthStr = argv[ 2 ];
91322f44 1640 if ( aWidthStr == 0 || Draw::Atof( aWidthStr ) <= 0 )
7fd59977 1641 {
586db386 1642 di << "Width must be real value more than zero\n";
7fd59977 1643 return 0;
1644 }
1645
91322f44 1646 double aWidth = Draw::Atof( aWidthStr );
7fd59977 1647
1648 Handle(AIS_InteractiveContext) anIC = ViewerTest::GetAISContext();
1649 if ( anIC.IsNull() )
1650 {
586db386 1651 di << "The context is null\n";
7fd59977 1652 return 0;
1653 }
1654
1655 Handle(MeshVS_Drawer) aDrawer = aMesh->GetDrawer();
1656 if ( aDrawer.IsNull() )
1657 {
586db386 1658 di << "The drawer is null\n";
7fd59977 1659 return 0;
1660 }
1661
1662 aDrawer->SetDouble( MeshVS_DA_EdgeWidth, aWidth );
0577ae8c 1663 anIC->Redisplay (aMesh, Standard_True);
7fd59977 1664 }
a738b534 1665 catch ( Standard_Failure const& )
7fd59977 1666 {
586db386 1667 di << "Error\n";
7fd59977 1668 }
1669
1670 return 0;
1671}
1672
1673//-----------------------------------------------------------------------------
1674
fcc61cc4 1675static Standard_Integer meshinfo(Draw_Interpretor& di,
1676 Standard_Integer argc,
1677 const char** argv)
1678{
1679 if ( argc != 2 )
1680 {
586db386 1681 di << "Wrong number of parameters. Use : meshinfo mesh\n";
fcc61cc4 1682 return 0;
1683 }
1684
1685 Handle(MeshVS_Mesh) aMesh = getMesh(argv[ 1 ], di);
1686 if ( aMesh.IsNull() )
1687 {
586db386 1688 di << "Mesh not found\n";
fcc61cc4 1689 return 0;
1690 }
1691
1692 Handle(XSDRAWSTLVRML_DataSource) stlMeshSource = Handle(XSDRAWSTLVRML_DataSource)::DownCast(aMesh->GetDataSource());
1693 if (!stlMeshSource.IsNull())
1694 {
1695 const TColStd_PackedMapOfInteger& nodes = stlMeshSource->GetAllNodes();
1696 const TColStd_PackedMapOfInteger& tris = stlMeshSource->GetAllElements();
1697
1698 di << "Nb nodes = " << nodes.Extent() << "\n";
1699 di << "Nb triangles = " << tris.Extent() << "\n";
1700 }
1701
1702 return 0;
1703}
1704
1705//-----------------------------------------------------------------------------
1706
7fd59977 1707void XSDRAWSTLVRML::InitCommands (Draw_Interpretor& theCommands)
1708{
1709 const char* g = "XSTEP-STL/VRML"; // Step transfer file commands
1710 //XSDRAW::LoadDraw(theCommands);
1711
0a419c51 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);
01b2f506 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);
f5fa6b33 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);
416d4426 1732 theCommands.Add ("writestl", "shape file [ascii/binary (0/1) : 1 by default] [InParallel (0/1) : 0 by default]",__FILE__,writestl,g);
4c4420df 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);
7fd59977 1739 theCommands.Add ("loadvrml" , "shape file",__FILE__,loadvrml,g);
4151c94d 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);
7fd59977 1759
709e97a0 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 );
c3715b74 1766 theCommands.Add ("meshclosed", "meshclosed meshname (0/1) \nChange MeshVS_Mesh drawing mode. 0 - not closed object, 1 - closed object", __FILE__, closed, g);
709e97a0 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 );
fcc61cc4 1777 theCommands.Add ("meshinfo", "displays the number of nodes and triangles", __FILE__, meshinfo, g );
7fd59977 1778}
1779
1780//==============================================================================
1781// XSDRAWSTLVRML::Factory
1782//==============================================================================
1783void XSDRAWSTLVRML::Factory(Draw_Interpretor& theDI)
1784{
1785 XSDRAWIGES::InitSelect();
1786 XSDRAWIGES::InitToBRep(theDI);
1787 XSDRAWIGES::InitFromBRep(theDI);
1788 XSDRAWSTEP::InitCommands(theDI);
1789 XSDRAWSTLVRML::InitCommands(theDI);
7fd59977 1790 XSDRAW::LoadDraw(theDI);
0797d9d3 1791#ifdef OCCT_DEBUG
586db386 1792 theDI << "Draw Plugin : All TKXSDRAW commands are loaded\n";
7fd59977 1793#endif
1794}
1795
1796// Declare entry point PLUGINFACTORY
1797DPLUGIN(XSDRAWSTLVRML)
1798