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