forked from Open-Cascade-SAS/OCCT
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathXSDRAWSTL.cxx
More file actions
1296 lines (1131 loc) · 41.1 KB
/
Copy pathXSDRAWSTL.cxx
File metadata and controls
1296 lines (1131 loc) · 41.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright (c) 2023 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <XSDRAWSTL.hxx>
#include <AIS_InteractiveContext.hxx>
#include <BRep_Builder.hxx>
#include <DBRep.hxx>
#include <DDocStd.hxx>
#include <DDocStd_DrawDocument.hxx>
#include <Draw.hxx>
#include <Draw_Interpretor.hxx>
#include <Draw_PluginMacro.hxx>
#include <Draw_ProgressIndicator.hxx>
#include <MeshVS_DeformedDataSource.hxx>
#include <MeshVS_Drawer.hxx>
#include <MeshVS_DrawerAttribute.hxx>
#include <MeshVS_ElementalColorPrsBuilder.hxx>
#include <MeshVS_Mesh.hxx>
#include <MeshVS_MeshEntityOwner.hxx>
#include <MeshVS_MeshPrsBuilder.hxx>
#include <MeshVS_NodalColorPrsBuilder.hxx>
#include <MeshVS_TextPrsBuilder.hxx>
#include <MeshVS_VectorPrsBuilder.hxx>
#include <RWStl.hxx>
#include <StlAPI.hxx>
#include <StlAPI_Writer.hxx>
#include <TColStd_HPackedMapOfInteger.hxx>
#include <TDataStd_Name.hxx>
#include <TDocStd_Application.hxx>
#include <TopoDS_Shape.hxx>
#include <V3d_View.hxx>
#include <ViewerTest.hxx>
#include <XSControl_WorkSession.hxx>
#include <XSDRAW.hxx>
#include <XSDRAWSTL_DataSource.hxx>
#include <XSDRAWSTL_DataSource3D.hxx>
#include <XSDRAWSTL_DrawableMesh.hxx>
extern Standard_Boolean VDisplayAISObject(const TCollection_AsciiString& theName,
const Handle(AIS_InteractiveObject)& theAISObj,
Standard_Boolean theReplaceIfExists = Standard_True);
//=================================================================================================
static Standard_Integer writestl(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
{
if (argc < 3 || argc > 4)
{
di << "Use: " << argv[0] << " shape file [ascii/binary (0/1) : 1 by default]\n";
}
else
{
TopoDS_Shape aShape = DBRep::Get(argv[1]);
Standard_Boolean isASCIIMode = Standard_False;
if (argc == 4)
{
isASCIIMode = (Draw::Atoi(argv[3]) == 0);
}
StlAPI_Writer aWriter;
aWriter.ASCIIMode() = isASCIIMode;
Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator(di);
Standard_Boolean isOK = aWriter.Write(aShape, argv[2], aProgress->Start());
if (!isOK)
di << "** Error **: Mesh writing has been failed.\n";
}
return 0;
}
//=================================================================================================
static Standard_Integer readstl(Draw_Interpretor& theDI,
Standard_Integer theArgc,
const char** theArgv)
{
TCollection_AsciiString aShapeName, aFilePath;
bool toCreateCompOfTris = false;
bool anIsMulti = false;
double aMergeAngle = M_PI / 2.0;
for (Standard_Integer anArgIter = 1; anArgIter < theArgc; ++anArgIter)
{
TCollection_AsciiString anArg(theArgv[anArgIter]);
anArg.LowerCase();
if (aShapeName.IsEmpty())
{
aShapeName = theArgv[anArgIter];
}
else if (aFilePath.IsEmpty())
{
aFilePath = theArgv[anArgIter];
}
else if (anArg == "-brep")
{
toCreateCompOfTris = true;
if (anArgIter + 1 < theArgc && Draw::ParseOnOff(theArgv[anArgIter + 1], toCreateCompOfTris))
{
++anArgIter;
}
}
else if (anArg == "-multi")
{
anIsMulti = true;
if (anArgIter + 1 < theArgc && Draw::ParseOnOff(theArgv[anArgIter + 1], anIsMulti))
{
++anArgIter;
}
}
else if (anArg == "-mergeangle" || anArg == "-smoothangle" || anArg == "-nomergeangle"
|| anArg == "-nosmoothangle")
{
if (anArg.StartsWith("-no"))
{
aMergeAngle = M_PI / 2.0;
}
else
{
aMergeAngle = M_PI / 4.0;
if (anArgIter + 1 < theArgc && Draw::ParseReal(theArgv[anArgIter + 1], aMergeAngle))
{
if (aMergeAngle < 0.0 || aMergeAngle > 90.0)
{
theDI << "Syntax error: angle should be within [0,90] range";
return 1;
}
++anArgIter;
aMergeAngle = aMergeAngle * M_PI / 180.0;
}
}
}
else
{
Message::SendFail() << "Syntax error: unknown argument '" << theArgv[anArgIter] << "'";
return 1;
}
}
if (aFilePath.IsEmpty())
{
Message::SendFail() << "Syntax error: not enough arguments";
return 1;
}
TopoDS_Shape aShape;
if (!toCreateCompOfTris)
{
Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator(theDI, 1);
if (anIsMulti)
{
NCollection_Sequence<Handle(Poly_Triangulation)> aTriangList;
// Read STL file to the triangulation list.
RWStl::ReadFile(aFilePath.ToCString(), aMergeAngle, aTriangList, aProgress->Start());
BRep_Builder aB;
TopoDS_Face aFace;
if (aTriangList.Size() == 1)
{
aB.MakeFace(aFace);
aB.UpdateFace(aFace, aTriangList.First());
aShape = aFace;
}
else
{
TopoDS_Compound aCmp;
aB.MakeCompound(aCmp);
NCollection_Sequence<Handle(Poly_Triangulation)>::Iterator anIt(aTriangList);
for (; anIt.More(); anIt.Next())
{
aB.MakeFace(aFace);
aB.UpdateFace(aFace, anIt.Value());
aB.Add(aCmp, aFace);
}
aShape = aCmp;
}
}
else
{
// Read STL file to the triangulation.
Handle(Poly_Triangulation) aTriangulation =
RWStl::ReadFile(aFilePath.ToCString(), aMergeAngle, aProgress->Start());
TopoDS_Face aFace;
BRep_Builder aB;
aB.MakeFace(aFace);
aB.UpdateFace(aFace, aTriangulation);
aShape = aFace;
}
}
else
{
Standard_DISABLE_DEPRECATION_WARNINGS StlAPI::Read(aShape, aFilePath.ToCString());
Standard_ENABLE_DEPRECATION_WARNINGS
}
DBRep::Set(aShapeName.ToCString(), aShape);
return 0;
}
//=================================================================================================
static Standard_Integer createmesh(Draw_Interpretor& theDI,
Standard_Integer theNbArgs,
const char** theArgVec)
{
if (theNbArgs < 3)
{
theDI << "Wrong number of parameters\n";
theDI << "Use: " << theArgVec[0] << " <mesh name> <stl file>\n";
return 0;
}
Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
if (aContext.IsNull())
{
theDI << "No active view. Please call 'vinit' first\n";
return 0;
}
// Progress indicator
OSD_Path aFile(theArgVec[2]);
Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator(theDI, 1);
Handle(Poly_Triangulation) aSTLMesh = RWStl::ReadFile(aFile, aProgress->Start());
theDI << "Reading OK...\n";
Handle(XSDRAWSTL_DataSource) aDS = new XSDRAWSTL_DataSource(aSTLMesh);
theDI << "Data source is created successful\n";
Handle(MeshVS_Mesh) aMesh = new MeshVS_Mesh();
theDI << "MeshVS_Mesh is created successful\n";
aMesh->SetDataSource(aDS);
aMesh->AddBuilder(new MeshVS_MeshPrsBuilder(aMesh.operator->()), Standard_True);
aMesh->GetDrawer()->SetColor(MeshVS_DA_EdgeColor, Quantity_NOC_YELLOW);
// Hide all nodes by default
Handle(TColStd_HPackedMapOfInteger) aNodes = new TColStd_HPackedMapOfInteger();
const Standard_Integer aLen = aSTLMesh->NbNodes();
for (Standard_Integer anIndex = 1; anIndex <= aLen; anIndex++)
aNodes->ChangeMap().Add(anIndex);
aMesh->SetHiddenNodes(aNodes);
aMesh->SetSelectableNodes(aNodes);
VDisplayAISObject(theArgVec[1], aMesh);
aContext->Deactivate(aMesh);
Draw::Set(theArgVec[1], new XSDRAWSTL_DrawableMesh(aMesh));
Handle(V3d_View) aView = ViewerTest::CurrentView();
if (!aView.IsNull())
aView->FitAll();
return 0;
}
//=================================================================================================
static Standard_Integer create3d(Draw_Interpretor& theDI,
Standard_Integer theNbArgs,
const char** theArgVec)
{
if (theNbArgs < 2)
{
theDI << "Wrong number of parameters\n";
theDI << "Use: " << theArgVec[0] << " <mesh name>\n";
return 0;
}
Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
if (aContext.IsNull())
{
theDI << "No active view. Please call 'vinit' first\n";
return 0;
}
Handle(XSDRAWSTL_DataSource3D) aDS = new XSDRAWSTL_DataSource3D();
theDI << "Data source is created successful\n";
Handle(MeshVS_Mesh) aMesh = new MeshVS_Mesh();
theDI << "MeshVS_Mesh is created successful\n";
aMesh->SetDataSource(aDS);
aMesh->AddBuilder(new MeshVS_MeshPrsBuilder(aMesh.operator->()), Standard_True);
aMesh->GetDrawer()->SetColor(MeshVS_DA_EdgeColor, Quantity_NOC_YELLOW);
// Hide all nodes by default
Handle(TColStd_HPackedMapOfInteger) aNodes = new TColStd_HPackedMapOfInteger();
Standard_Integer aLen = aDS->GetAllNodes().Extent();
for (Standard_Integer anIndex = 1; anIndex <= aLen; anIndex++)
aNodes->ChangeMap().Add(anIndex);
aMesh->SetHiddenNodes(aNodes);
aMesh->SetSelectableNodes(aNodes);
VDisplayAISObject(theArgVec[1], aMesh);
aContext->Deactivate(aMesh);
Draw::Set(theArgVec[1], new XSDRAWSTL_DrawableMesh(aMesh));
Handle(V3d_View) aView = ViewerTest::CurrentView();
if (!aView.IsNull())
aView->FitAll();
return 0;
}
//=================================================================================================
Handle(MeshVS_Mesh) getMesh(const char* theName, Draw_Interpretor& theDI)
{
Handle(XSDRAWSTL_DrawableMesh) aDrawMesh =
Handle(XSDRAWSTL_DrawableMesh)::DownCast(Draw::Get(theName));
if (aDrawMesh.IsNull())
{
theDI << "There is no such object\n";
return NULL;
}
else
{
Handle(MeshVS_Mesh) aMesh = aDrawMesh->GetMesh();
if (aMesh.IsNull())
{
theDI << "There is invalid mesh\n";
return NULL;
}
else
return aMesh;
}
}
//=================================================================================================
static Standard_Integer setcolor(Draw_Interpretor& theDI,
Standard_Integer theNbArgs,
const char** theArgVec,
Standard_Integer theParam)
{
if (theNbArgs < 5)
theDI << "Wrong number of parameters\n";
else
{
Handle(MeshVS_Mesh) aMesh = getMesh(theArgVec[1], theDI);
if (!aMesh.IsNull())
{
Standard_Real aRed = Draw::Atof(theArgVec[2]);
Standard_Real aGreen = Draw::Atof(theArgVec[3]);
Standard_Real aBlue = Draw::Atof(theArgVec[4]);
aMesh->GetDrawer()->SetColor((MeshVS_DrawerAttribute)theParam,
Quantity_Color(aRed, aGreen, aBlue, Quantity_TOC_RGB));
Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
if (aContext.IsNull())
theDI << "The context is null\n";
else
aContext->Redisplay(aMesh, Standard_True);
}
}
return 0;
}
//=================================================================================================
static Standard_Integer meshcolor(Draw_Interpretor& theInterp,
Standard_Integer theNbArgs,
const char** theArgVec)
{
return setcolor(theInterp, theNbArgs, theArgVec, MeshVS_DA_InteriorColor);
}
//=================================================================================================
static Standard_Integer linecolor(Draw_Interpretor& theInterp,
Standard_Integer theNbArgs,
const char** theArgVec)
{
return setcolor(theInterp, theNbArgs, theArgVec, MeshVS_DA_EdgeColor);
}
//=================================================================================================
static Standard_Integer meshmat(Draw_Interpretor& theDI,
Standard_Integer theNbArgs,
const char** theArgVec)
{
if (theNbArgs < 3)
theDI << "Wrong number of parameters\n";
else
{
Handle(MeshVS_Mesh) aMesh = getMesh(theArgVec[1], theDI);
if (!aMesh.IsNull())
{
Standard_Integer aMaterial = Draw::Atoi(theArgVec[2]);
Graphic3d_MaterialAspect aMatAsp =
(Graphic3d_MaterialAspect)(Graphic3d_NameOfMaterial)aMaterial;
if (theNbArgs == 4)
{
Standard_Real aTransparency = Draw::Atof(theArgVec[3]);
aMatAsp.SetTransparency(Standard_ShortReal(aTransparency));
}
aMesh->GetDrawer()->SetMaterial(MeshVS_DA_FrontMaterial, aMatAsp);
aMesh->GetDrawer()->SetMaterial(MeshVS_DA_BackMaterial, aMatAsp);
Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
if (aContext.IsNull())
theDI << "The context is null\n";
else
aContext->Redisplay(aMesh, Standard_True);
}
}
return 0;
}
//=================================================================================================
static Standard_Integer shrink(Draw_Interpretor& theDI,
Standard_Integer theNbArgs,
const char** theArgVec)
{
if (theNbArgs < 3)
theDI << "Wrong number of parameters\n";
else
{
Handle(MeshVS_Mesh) aMesh = getMesh(theArgVec[1], theDI);
if (!aMesh.IsNull())
{
Standard_Real aShrinkCoeff = Draw::Atof(theArgVec[2]);
aMesh->GetDrawer()->SetDouble(MeshVS_DA_ShrinkCoeff, aShrinkCoeff);
Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
if (aContext.IsNull())
theDI << "The context is null\n";
else
aContext->Redisplay(aMesh, Standard_True);
}
}
return 0;
}
//=================================================================================================
static Standard_Integer closed(Draw_Interpretor& theDI,
Standard_Integer theArgc,
const char** theArgv)
{
if (theArgc < 3)
{
theDI << "Wrong number of parameters.\n";
}
else
{
Handle(MeshVS_Mesh) aMesh = getMesh(theArgv[1], theDI);
if (!aMesh.IsNull())
{
Standard_Boolean aFlag = Draw::Atoi(theArgv[2]) != 0;
aMesh->GetDrawer()->SetBoolean(MeshVS_DA_SupressBackFaces, aFlag);
Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
if (aContext.IsNull())
{
theDI << "The context is null\n";
}
else
{
aContext->Redisplay(aMesh, Standard_True);
}
}
}
return 0;
}
//=================================================================================================
static Standard_Integer mdisplay(Draw_Interpretor& theDI,
Standard_Integer theNbArgs,
const char** theArgVec)
{
if (theNbArgs < 2)
theDI << "Wrong number of parameters\n";
else
{
Handle(MeshVS_Mesh) aMesh = getMesh(theArgVec[1], theDI);
if (!aMesh.IsNull())
{
Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
if (aContext.IsNull())
theDI << "The context is null\n";
else
{
aContext->Display(aMesh, Standard_True);
}
}
}
return 0;
}
//=================================================================================================
static Standard_Integer merase(Draw_Interpretor& theDI,
Standard_Integer theNbArgs,
const char** theArgVec)
{
if (theNbArgs < 2)
theDI << "Wrong number of parameters\n";
else
{
Handle(MeshVS_Mesh) aMesh = getMesh(theArgVec[1], theDI);
if (!aMesh.IsNull())
{
Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
if (aContext.IsNull())
theDI << "The context is null\n";
else
{
aContext->Erase(aMesh, Standard_True);
}
}
else
theDI << "Mesh is null\n";
}
return 0;
}
//=================================================================================================
static Standard_Integer hidesel(Draw_Interpretor& theDI,
Standard_Integer theNbArgs,
const char** theArgVec)
{
if (theNbArgs < 2)
{
theDI << "Wrong number of parameters\n";
theDI << "Use: " << theArgVec[0] << " <mesh name>\n";
return 0;
}
Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
Handle(MeshVS_Mesh) aMesh = getMesh(theArgVec[1], theDI);
if (aMesh.IsNull())
{
theDI << "The mesh is invalid\n";
return 0;
}
if (aContext.IsNull())
theDI << "The context is null\n";
else
{
Handle(TColStd_HPackedMapOfInteger) aHiddenNodes = aMesh->GetHiddenNodes();
if (aHiddenNodes.IsNull())
{
aHiddenNodes = new TColStd_HPackedMapOfInteger();
}
Handle(TColStd_HPackedMapOfInteger) aHiddenElements = aMesh->GetHiddenElems();
if (aHiddenElements.IsNull())
{
aHiddenElements = new TColStd_HPackedMapOfInteger();
}
for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
{
Handle(MeshVS_MeshEntityOwner) anOwner =
Handle(MeshVS_MeshEntityOwner)::DownCast(aContext->SelectedOwner());
if (!anOwner.IsNull())
{
if (anOwner->Type() == MeshVS_ET_Node)
{
aHiddenNodes->ChangeMap().Add(anOwner->ID());
}
else
{
aHiddenElements->ChangeMap().Add(anOwner->ID());
}
}
}
aContext->ClearSelected(Standard_False);
aMesh->SetHiddenNodes(aHiddenNodes);
aMesh->SetHiddenElems(aHiddenElements);
aContext->Redisplay(aMesh, Standard_True);
}
return 0;
}
//=================================================================================================
static Standard_Integer showonly(Draw_Interpretor& theDI,
Standard_Integer theNbArgs,
const char** theArgVec)
{
if (theNbArgs < 2)
{
theDI << "Wrong number of parameters\n";
theDI << "Use: " << theArgVec[0] << " <mesh name>\n";
return 0;
}
Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
Handle(MeshVS_Mesh) aMesh = getMesh(theArgVec[1], theDI);
if (aMesh.IsNull())
{
theDI << "The mesh is invalid\n";
return 0;
}
if (aContext.IsNull())
theDI << "The context is null\n";
else
{
Handle(TColStd_HPackedMapOfInteger) aHiddenNodes =
new TColStd_HPackedMapOfInteger(aMesh->GetDataSource()->GetAllNodes());
Handle(TColStd_HPackedMapOfInteger) aHiddenElements =
new TColStd_HPackedMapOfInteger(aMesh->GetDataSource()->GetAllElements());
for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
{
Handle(MeshVS_MeshEntityOwner) anOwner =
Handle(MeshVS_MeshEntityOwner)::DownCast(aContext->SelectedOwner());
if (!anOwner.IsNull())
{
if (anOwner->Type() == MeshVS_ET_Node)
{
aHiddenNodes->ChangeMap().Remove(anOwner->ID());
}
else
{
aHiddenElements->ChangeMap().Remove(anOwner->ID());
}
}
}
aMesh->SetHiddenNodes(aHiddenNodes);
aMesh->SetHiddenElems(aHiddenElements);
aContext->Redisplay(aMesh, Standard_True);
}
return 0;
}
//=================================================================================================
static Standard_Integer showall(Draw_Interpretor& theDI,
Standard_Integer theNbArgs,
const char** theArgVec)
{
if (theNbArgs < 2)
{
theDI << "Wrong number of parameters\n";
theDI << "Use: " << theArgVec[0] << " <mesh name>\n";
return 0;
}
Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
Handle(MeshVS_Mesh) aMesh = getMesh(theArgVec[1], theDI);
if (aMesh.IsNull())
{
theDI << "The mesh is invalid\n";
return 0;
}
if (aContext.IsNull())
theDI << "The context is null\n";
else
{
aMesh->SetHiddenNodes(new TColStd_HPackedMapOfInteger());
aMesh->SetHiddenElems(new TColStd_HPackedMapOfInteger());
aContext->Redisplay(aMesh, Standard_True);
}
return 0;
}
//=================================================================================================
static Standard_Integer meshcolors(Draw_Interpretor& theDI,
Standard_Integer theNbArgs,
const char** theArgVec)
{
try
{
OCC_CATCH_SIGNALS
if (theNbArgs < 4)
{
theDI << "Wrong number of parameters\n";
theDI << "Use : meshcolors <mesh name> <mode> <isreflect>\n";
theDI << "mode : {elem1|elem2|nodal|nodaltex|none}\n";
theDI << " elem1 - different color for each element\n";
theDI << " elem2 - one color for one side\n";
theDI << " nodal - different color for each node\n";
theDI << " nodaltex - different color for each node with texture interpolation\n";
theDI << " none - clear\n";
theDI << "isreflect : {0|1} \n";
return 0;
}
Handle(MeshVS_Mesh) aMesh = getMesh(theArgVec[1], theDI);
if (aMesh.IsNull())
{
theDI << "Mesh not found\n";
return 0;
}
Handle(AIS_InteractiveContext) anIC = ViewerTest::GetAISContext();
if (anIC.IsNull())
{
theDI << "The context is null\n";
return 0;
}
if (!aMesh.IsNull())
{
TCollection_AsciiString aMode = TCollection_AsciiString(theArgVec[2]);
Quantity_Color aColor1(Quantity_NOC_BLUE1);
Quantity_Color aColor2(Quantity_NOC_RED1);
if (aMode.IsEqual("elem1") || aMode.IsEqual("elem2") || aMode.IsEqual("nodal")
|| aMode.IsEqual("nodaltex") || aMode.IsEqual("none"))
{
Handle(MeshVS_PrsBuilder) aTempBuilder;
Standard_Integer aReflection = Draw::Atoi(theArgVec[3]);
for (Standard_Integer aCount = 0; aCount < aMesh->GetBuildersCount(); aCount++)
{
aTempBuilder = aMesh->FindBuilder(STANDARD_TYPE(MeshVS_ElementalColorPrsBuilder));
if (!aTempBuilder.IsNull())
aMesh->RemoveBuilderById(aTempBuilder->GetId());
aTempBuilder = aMesh->FindBuilder(STANDARD_TYPE(MeshVS_NodalColorPrsBuilder));
if (!aTempBuilder.IsNull())
aMesh->RemoveBuilderById(aTempBuilder->GetId());
}
if (aMode.IsEqual("elem1") || aMode.IsEqual("elem2"))
{
Handle(MeshVS_ElementalColorPrsBuilder) aBuilder = new MeshVS_ElementalColorPrsBuilder(
aMesh,
MeshVS_DMF_ElementalColorDataPrs | MeshVS_DMF_OCCMask);
// Color
const TColStd_PackedMapOfInteger& anAllElements =
aMesh->GetDataSource()->GetAllElements();
if (aMode.IsEqual("elem1"))
for (TColStd_PackedMapOfInteger::Iterator anIter(anAllElements); anIter.More();
anIter.Next())
{
Quantity_Color aColor((Quantity_NameOfColor)(anIter.Key() % Quantity_NOC_WHITE));
aBuilder->SetColor1(anIter.Key(), aColor);
}
else
for (TColStd_PackedMapOfInteger::Iterator anIter(anAllElements); anIter.More();
anIter.Next())
{
aBuilder->SetColor2(anIter.Key(), aColor1, aColor2);
}
aMesh->AddBuilder(aBuilder, Standard_True);
}
if (aMode.IsEqual("nodal"))
{
Handle(MeshVS_NodalColorPrsBuilder) aBuilder =
new MeshVS_NodalColorPrsBuilder(aMesh,
MeshVS_DMF_NodalColorDataPrs | MeshVS_DMF_OCCMask);
aMesh->AddBuilder(aBuilder, Standard_True);
// Color
const TColStd_PackedMapOfInteger& anAllNodes = aMesh->GetDataSource()->GetAllNodes();
for (TColStd_PackedMapOfInteger::Iterator anIter(anAllNodes); anIter.More();
anIter.Next())
{
Quantity_Color aColor((Quantity_NameOfColor)(anIter.Key() % Quantity_NOC_WHITE));
aBuilder->SetColor(anIter.Key(), aColor);
}
aMesh->AddBuilder(aBuilder, Standard_True);
}
if (aMode.IsEqual("nodaltex"))
{
// assign nodal builder to the mesh
Handle(MeshVS_NodalColorPrsBuilder) aBuilder =
new MeshVS_NodalColorPrsBuilder(aMesh,
MeshVS_DMF_NodalColorDataPrs | MeshVS_DMF_OCCMask);
aMesh->AddBuilder(aBuilder, Standard_True);
aBuilder->UseTexture(Standard_True);
// prepare color map for texture
Aspect_SequenceOfColor aColorMap;
aColorMap.Append((Quantity_NameOfColor)Quantity_NOC_RED);
aColorMap.Append((Quantity_NameOfColor)Quantity_NOC_YELLOW);
aColorMap.Append((Quantity_NameOfColor)Quantity_NOC_BLUE1);
// prepare scale map for mesh - it will be assigned to mesh as texture coordinates
// make mesh color interpolated from minimum X coord to maximum X coord
Handle(MeshVS_DataSource) aDataSource = aMesh->GetDataSource();
Standard_Real aMinX, aMinY, aMinZ, aMaxX, aMaxY, aMaxZ;
// get bounding box for calculations
aDataSource->GetBoundingBox().Get(aMinX, aMinY, aMinZ, aMaxX, aMaxY, aMaxZ);
Standard_Real aDelta = aMaxX - aMinX;
// assign color scale map values (0..1) to nodes
TColStd_DataMapOfIntegerReal aScaleMap;
TColStd_Array1OfReal aCoords(1, 3);
Standard_Integer aNbNodes;
MeshVS_EntityType aType;
// iterate nodes
const TColStd_PackedMapOfInteger& anAllNodes = aMesh->GetDataSource()->GetAllNodes();
for (TColStd_PackedMapOfInteger::Iterator anIter(anAllNodes); anIter.More();
anIter.Next())
{
// get node coordinates to aCoord variable
aDataSource->GetGeom(anIter.Key(), Standard_False, aCoords, aNbNodes, aType);
Standard_Real aScaleValue;
if (aDelta > Precision::Confusion())
{
aScaleValue = (aCoords.Value(1) - aMinX) / aDelta;
}
else
{
aScaleValue = 0.0;
}
aScaleMap.Bind(anIter.Key(), aScaleValue);
}
// set color map for builder and a color for invalid scale value
aBuilder->SetColorMap(aColorMap);
aBuilder->SetInvalidColor(Quantity_NOC_BLACK);
aBuilder->SetTextureCoords(aScaleMap);
aMesh->AddBuilder(aBuilder, Standard_True);
}
aMesh->GetDrawer()->SetBoolean(MeshVS_DA_ColorReflection, aReflection != 0);
anIC->Redisplay(aMesh, Standard_True);
}
else
{
theDI << "Wrong mode name\n";
return 0;
}
}
}
catch (Standard_Failure const&)
{
theDI << "Error\n";
}
return 0;
}
//=================================================================================================
static Standard_Integer meshvectors(Draw_Interpretor& theDI,
Standard_Integer theNbArgs,
const char** theArgVec)
{
if (theNbArgs < 3)
{
theDI << "Wrong number of parameters\n";
theDI << "Use : meshvectors <mesh name> < -mode {elem|nodal|none} > [-maxlen len] [-color "
"name] [-arrowpart ratio] [-issimple {1|0}]\n";
theDI << "Supported mode values:\n";
theDI << " elem - vector per element\n";
theDI << " nodal - vector per node\n";
theDI << " none - clear\n";
return 0;
}
Handle(MeshVS_Mesh) aMesh = getMesh(theArgVec[1], theDI);
if (aMesh.IsNull())
{
theDI << "Mesh not found\n";
return 0;
}
Handle(AIS_InteractiveContext) anIC = ViewerTest::GetAISContext();
if (anIC.IsNull())
{
theDI << "The context is null\n";
return 0;
}
TCollection_AsciiString aParam;
TCollection_AsciiString aMode("none");
Standard_Real aMaxlen(1.0);
Quantity_Color aColor(Quantity_NOC_ORANGE);
Standard_Real anArrowPart(0.1);
Standard_Boolean isSimplePrs(Standard_False);
for (Standard_Integer anIdx = 2; anIdx < theNbArgs; anIdx++)
{
if (!aParam.IsEmpty())
{
if (aParam == "-mode")
{
aMode = theArgVec[anIdx];
}
else if (aParam == "-maxlen")
{
aMaxlen = Draw::Atof(theArgVec[anIdx]);
}
else if (aParam == "-color")
{
if (!Quantity_Color::ColorFromName(theArgVec[anIdx], aColor))
{
theDI << "Syntax error at " << aParam << "\n";
return 1;
}
}
else if (aParam == "-arrowpart")
{
anArrowPart = Draw::Atof(theArgVec[anIdx]);
}
else if (aParam == "-issimple")
{
isSimplePrs = Draw::Atoi(theArgVec[anIdx]) != 0;
}
aParam.Clear();
}
else if (theArgVec[anIdx][0] == '-')
{
aParam = theArgVec[anIdx];
}
}
if (!aMode.IsEqual("elem") && !aMode.IsEqual("nodal") && !aMode.IsEqual("none"))
{
theDI << "Wrong mode name\n";
return 0;
}
Handle(MeshVS_PrsBuilder) aTempBuilder;
aTempBuilder = aMesh->FindBuilder(STANDARD_TYPE(MeshVS_VectorPrsBuilder));
if (!aTempBuilder.IsNull())
aMesh->RemoveBuilderById(aTempBuilder->GetId());
if (!aMode.IsEqual("none"))
{
Handle(MeshVS_VectorPrsBuilder) aBuilder = new MeshVS_VectorPrsBuilder(aMesh.operator->(),
aMaxlen,
aColor,
MeshVS_DMF_VectorDataPrs,
0,
-1,
MeshVS_BP_Vector,
isSimplePrs);
Standard_Boolean anIsElement = aMode.IsEqual("elem");
const TColStd_PackedMapOfInteger& anAllIDs = anIsElement
? aMesh->GetDataSource()->GetAllElements()
: aMesh->GetDataSource()->GetAllNodes();
Standard_Integer aNbNodes;
MeshVS_EntityType aEntType;
TColStd_Array1OfReal aCoords(1, 3);
aCoords.Init(0.);
for (TColStd_PackedMapOfInteger::Iterator anIter(anAllIDs); anIter.More(); anIter.Next())
{
Standard_Boolean IsValidData = Standard_False;
if (anIsElement)
{
aMesh->GetDataSource()->GetGeomType(anIter.Key(), anIsElement, aEntType);
if (aEntType == MeshVS_ET_Face)
IsValidData = aMesh->GetDataSource()->GetNormal(anIter.Key(),
3,
aCoords.ChangeValue(1),
aCoords.ChangeValue(2),
aCoords.ChangeValue(3));
}
else
IsValidData = aMesh->GetDataSource()->GetGeom(anIter.Key(),
Standard_False,
aCoords,
aNbNodes,
aEntType);
gp_Vec aNorm;
if (IsValidData)
{
aNorm = gp_Vec(aCoords.Value(1), aCoords.Value(2), aCoords.Value(3));
if (aNorm.Magnitude() < gp::Resolution())
{
aNorm = gp_Vec(0, 0, 1); // method GetGeom(...) returns coordinates of nodes
}
}
else
{