/
SMESH_Mesh.cpp
2461 lines (2158 loc) · 81.9 KB
/
SMESH_Mesh.cpp
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) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE
//
// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
// Suppress warning due to use of #import an macOS inside Aspect_RenderingContext.hxx
#if defined(__clang__)
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wimport-preprocessor-directive-pedantic"
#endif
// File : SMESH_Mesh.cxx
// Author : Paul RASCLE, EDF
// Module : SMESH
//
#include "SMESH_Mesh.hxx"
#include "SMESH_MesherHelper.hxx"
#include "SMDS_MeshVolume.hxx"
#include "SMDS_SetIterator.hxx"
#include "SMESHDS_Document.hxx"
#include "SMESHDS_Group.hxx"
#include "SMESHDS_GroupOnGeom.hxx"
#include "SMESHDS_Script.hxx"
#include "SMESHDS_TSubMeshHolder.hxx"
#include "SMESH_Gen.hxx"
#include "SMESH_Group.hxx"
#include "SMESH_HypoFilter.hxx"
#include "SMESH_Hypothesis.hxx"
#include "SMESH_subMesh.hxx"
#include "utilities.h"
#include "SMESH_Exception.hxx"
#include "DriverDAT_W_SMDS_Mesh.h"
#include "DriverDAT_R_SMDS_Mesh.h"
#include "DriverGMF_Read.hxx"
#include "DriverGMF_Write.hxx"
#include "DriverMED_R_SMESHDS_Mesh.h"
#include "DriverMED_W_SMESHDS_Mesh.h"
#include "DriverSTL_R_SMDS_Mesh.h"
#include "DriverSTL_W_SMDS_Mesh.h"
#include "DriverUNV_R_SMDS_Mesh.h"
#include "DriverUNV_W_SMDS_Mesh.h"
#ifdef WITH_CGNS
#include "DriverCGNS_Read.hxx"
#include "DriverCGNS_Write.hxx"
#endif
#include <GEOMUtils.hxx>
#undef _Precision_HeaderFile
#include <BRepBndLib.hxx>
#include <BRepPrimAPI_MakeBox.hxx>
#include <Bnd_Box.hxx>
#include <TColStd_MapOfInteger.hxx>
#include <TopExp.hxx>
#include <TopExp_Explorer.hxx>
#include <TopTools_ListIteratorOfListOfShape.hxx>
#include <TopTools_ListOfShape.hxx>
#include <TopTools_MapOfShape.hxx>
#include <TopoDS_Iterator.hxx>
#include "SMESH_TryCatch.hxx" // include after OCCT headers!
#include "Utils_ExceptHandlers.hxx"
#ifndef WIN32
#include <boost/thread/thread.hpp>
#include <boost/bind/bind.hpp>
#else
#include <boost/thread/thread.hpp>
#include <boost/bind/bind.hpp>
//#include <pthread.h>
#endif
using namespace std;
// maximum stored group name length in MED file
#define MAX_MED_GROUP_NAME_LENGTH 80
#ifdef _DEBUG_
static int MYDEBUG = 0;
#else
static int MYDEBUG = 0;
#endif
#define cSMESH_Hyp(h) static_cast<const SMESH_Hypothesis*>(h)
typedef SMESH_HypoFilter THypType;
class SMESH_Mesh::SubMeshHolder : public SMESHDS_TSubMeshHolder< SMESH_subMesh >
{
};
//=============================================================================
/*!
*
*/
//=============================================================================
SMESH_Mesh::SMESH_Mesh(int theLocalId,
int theStudyId,
SMESH_Gen* theGen,
bool theIsEmbeddedMode,
SMESHDS_Document* theDocument):
_groupId( 0 ), _nbSubShapes( 0 )
{
MESSAGE("SMESH_Mesh::SMESH_Mesh(int localId)");
_id = theLocalId;
_studyId = theStudyId;
_gen = theGen;
_myDocument = theDocument;
_myMeshDS = theDocument->NewMesh(theIsEmbeddedMode,theLocalId);
_isShapeToMesh = false;
_isAutoColor = false;
_isModified = false;
_shapeDiagonal = 0.0;
_callUp = NULL;
_myMeshDS->ShapeToMesh( PseudoShape() );
_subMeshHolder = new SubMeshHolder;
}
//================================================================================
/*!
* \brief Constructor of SMESH_Mesh being a base of some descendant class
*/
//================================================================================
SMESH_Mesh::SMESH_Mesh():
_id(-1),
_studyId(-1),
_groupId( 0 ),
_nbSubShapes( 0 ),
_isShapeToMesh( false ),
_myDocument( 0 ),
_myMeshDS( 0 ),
_gen( 0 ),
_isAutoColor( false ),
_isModified( false ),
_shapeDiagonal( 0.0 ),
_callUp( 0 )
{
_subMeshHolder = new SubMeshHolder;
}
namespace
{
#ifndef WIN32
void deleteMeshDS(SMESHDS_Mesh* meshDS)
{
//cout << "deleteMeshDS( " << meshDS << endl;
delete meshDS;
}
#else
static void* deleteMeshDS(void* meshDS)
{
//cout << "deleteMeshDS( " << meshDS << endl;
SMESHDS_Mesh* m = (SMESHDS_Mesh*)meshDS;
if(m) {
delete m;
}
return 0;
}
#endif
}
//=============================================================================
/*!
*
*/
//=============================================================================
SMESH_Mesh::~SMESH_Mesh()
{
MESSAGE("SMESH_Mesh::~SMESH_Mesh");
// avoid usual removal of elements while processing RemoveHypothesis( algo ) event
SMESHDS_SubMeshIteratorPtr smIt = _myMeshDS->SubMeshes();
while ( smIt->more() )
const_cast<SMESHDS_SubMesh*>( smIt->next() )->Clear();
// issue 0020340: EDF 1022 SMESH : Crash with FindNodeClosestTo in a second new study
// Notify event listeners at least that something happens
if ( SMESH_subMesh * sm = GetSubMeshContaining(1))
sm->ComputeStateEngine( SMESH_subMesh::MESH_ENTITY_REMOVED );
// delete groups
map < int, SMESH_Group * >::iterator itg;
for (itg = _mapGroup.begin(); itg != _mapGroup.end(); itg++) {
SMESH_Group *aGroup = (*itg).second;
delete aGroup;
}
_mapGroup.clear();
// delete sub-meshes
delete _subMeshHolder;
if ( _callUp) delete _callUp;
_callUp = 0;
// remove self from studyContext
if ( _gen )
{
StudyContextStruct * studyContext = _gen->GetStudyContext( _studyId );
studyContext->mapMesh.erase( _id );
}
if ( _myDocument )
_myDocument->RemoveMesh( _id );
_myDocument = 0;
if ( _myMeshDS ) {
// delete _myMeshDS, in a thread in order not to block closing a study with large meshes
#ifndef WIN32
boost::thread aThread(boost::bind( & deleteMeshDS, _myMeshDS ));
#else
boost::thread aThread(boost::bind( & deleteMeshDS, _myMeshDS ));
// pthread_t thread;
// int result=pthread_create(&thread, NULL, deleteMeshDS, (void*)_myMeshDS);
#endif
}
}
//================================================================================
/*!
* \brief Return true if a mesh with given id exists
*/
//================================================================================
bool SMESH_Mesh::MeshExists( int meshId ) const
{
return _myDocument ? bool( _myDocument->GetMesh( meshId )) : false;
}
//================================================================================
/*!
* \brief Return a mesh by id
*/
//================================================================================
SMESH_Mesh* SMESH_Mesh::FindMesh( int meshId ) const
{
if ( _id == meshId )
return (SMESH_Mesh*) this;
if ( StudyContextStruct *aStudyContext = _gen->GetStudyContext( _studyId ))
{
std::map < int, SMESH_Mesh * >::iterator i_m = aStudyContext->mapMesh.find( meshId );
if ( i_m != aStudyContext->mapMesh.end() )
return i_m->second;
}
return NULL;
}
//=============================================================================
/*!
* \brief Set geometry to be meshed
*/
//=============================================================================
void SMESH_Mesh::ShapeToMesh(const TopoDS_Shape & aShape)
{
if(MYDEBUG) MESSAGE("SMESH_Mesh::ShapeToMesh");
if ( !aShape.IsNull() && _isShapeToMesh ) {
if ( aShape.ShapeType() != TopAbs_COMPOUND && // group contents is allowed to change
_myMeshDS->ShapeToMesh().ShapeType() != TopAbs_COMPOUND )
throw SALOME_Exception(LOCALIZED ("a shape to mesh has already been defined"));
}
// clear current data
if ( !_myMeshDS->ShapeToMesh().IsNull() )
{
// removal of a shape to mesh, delete objects referring to sub-shapes:
// - sub-meshes
_subMeshHolder->DeleteAll();
// - groups on geometry
map <int, SMESH_Group *>::iterator i_gr = _mapGroup.begin();
while ( i_gr != _mapGroup.end() ) {
if ( dynamic_cast<SMESHDS_GroupOnGeom*>( i_gr->second->GetGroupDS() )) {
_myMeshDS->RemoveGroup( i_gr->second->GetGroupDS() );
delete i_gr->second;
_mapGroup.erase( i_gr++ );
}
else
i_gr++;
}
_mapAncestors.Clear();
// clear SMESHDS
TopoDS_Shape aNullShape;
_myMeshDS->ShapeToMesh( aNullShape );
_shapeDiagonal = 0.0;
}
// set a new geometry
if ( !aShape.IsNull() )
{
_myMeshDS->ShapeToMesh(aShape);
_isShapeToMesh = true;
_nbSubShapes = _myMeshDS->MaxShapeIndex();
// fill map of ancestors
fillAncestorsMap(aShape);
}
else
{
_isShapeToMesh = false;
_shapeDiagonal = 0.0;
_myMeshDS->ShapeToMesh( PseudoShape() );
}
_isModified = false;
}
//=======================================================================
/*!
* \brief Return geometry to be meshed. (It may be a PseudoShape()!)
*/
//=======================================================================
TopoDS_Shape SMESH_Mesh::GetShapeToMesh() const
{
return _myMeshDS->ShapeToMesh();
}
//=======================================================================
/*!
* \brief Return a solid which is returned by GetShapeToMesh() if
* a real geometry to be meshed was not set
*/
//=======================================================================
const TopoDS_Solid& SMESH_Mesh::PseudoShape()
{
static TopoDS_Solid aSolid;
if ( aSolid.IsNull() )
{
aSolid = BRepPrimAPI_MakeBox(1,1,1);
}
return aSolid;
}
//=======================================================================
/*!
* \brief Return diagonal size of bounding box of a shape
*/
//=======================================================================
double SMESH_Mesh::GetShapeDiagonalSize(const TopoDS_Shape & aShape)
{
if ( !aShape.IsNull() ) {
Bnd_Box Box;
// avoid too long waiting on large shapes. PreciseBoundingBox() was added
// to assure same result which else depends on presence of triangulation (IPAL52557).
const int maxNbFaces = 4000;
int nbFaces = 0;
for ( TopExp_Explorer f( aShape, TopAbs_FACE ); f.More() && nbFaces < maxNbFaces; f.Next() )
++nbFaces;
if ( nbFaces < maxNbFaces )
GEOMUtils::PreciseBoundingBox(aShape, Box);
else
BRepBndLib::Add( aShape, Box);
if ( !Box.IsVoid() )
return sqrt( Box.SquareExtent() );
}
return 0;
}
//=======================================================================
/*!
* \brief Return diagonal size of bounding box of shape to mesh
*/
//=======================================================================
double SMESH_Mesh::GetShapeDiagonalSize() const
{
if ( _shapeDiagonal == 0. && _isShapeToMesh )
const_cast<SMESH_Mesh*>(this)->_shapeDiagonal = GetShapeDiagonalSize( GetShapeToMesh() );
return _shapeDiagonal;
}
//================================================================================
/*!
* \brief Load mesh from study file
*/
//================================================================================
void SMESH_Mesh::Load()
{
if (_callUp)
_callUp->Load();
}
//=======================================================================
/*!
* \brief Remove all nodes and elements
*/
//=======================================================================
void SMESH_Mesh::Clear()
{
if ( HasShapeToMesh() ) // remove all nodes and elements
{
// clear mesh data
_myMeshDS->ClearMesh();
// update compute state of submeshes
if ( SMESH_subMesh *sm = GetSubMeshContaining( GetShapeToMesh() ) )
{
sm->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
sm->ComputeSubMeshStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
sm->ComputeStateEngine( SMESH_subMesh::CLEAN ); // for event listeners (issue 0020918)
sm->ComputeSubMeshStateEngine( SMESH_subMesh::CLEAN );
}
}
else // remove only nodes/elements computed by algorithms
{
if ( SMESH_subMesh *sm = GetSubMeshContaining( GetShapeToMesh() ) )
{
sm->ComputeStateEngine( SMESH_subMesh::CLEAN );
sm->ComputeSubMeshStateEngine( SMESH_subMesh::CLEAN );
sm->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
sm->ComputeSubMeshStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
}
}
_isModified = false;
}
//=======================================================================
/*!
* \brief Remove all nodes and elements of indicated shape
*/
//=======================================================================
void SMESH_Mesh::ClearSubMesh(const int theShapeId)
{
// clear sub-meshes; get ready to re-compute as a side-effect
if ( SMESH_subMesh *sm = GetSubMeshContaining( theShapeId ) )
{
SMESH_subMeshIteratorPtr smIt = sm->getDependsOnIterator(/*includeSelf=*/true,
/*complexShapeFirst=*/false);
while ( smIt->more() )
{
sm = smIt->next();
TopAbs_ShapeEnum shapeType = sm->GetSubShape().ShapeType();
if ( shapeType == TopAbs_VERTEX || shapeType < TopAbs_SOLID )
// all other shapes depends on vertices so they are already cleaned
sm->ComputeStateEngine( SMESH_subMesh::CLEAN );
// to recompute even if failed
sm->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
}
}
}
//=======================================================================
//function : UNVToMesh
//purpose :
//=======================================================================
int SMESH_Mesh::UNVToMesh(const char* theFileName)
{
if(MYDEBUG) MESSAGE("UNVToMesh - theFileName = "<<theFileName);
if(_isShapeToMesh)
throw SALOME_Exception(LOCALIZED("a shape to mesh has already been defined"));
_isShapeToMesh = false;
DriverUNV_R_SMDS_Mesh myReader;
myReader.SetMesh(_myMeshDS);
myReader.SetFile(theFileName);
myReader.SetMeshId(-1);
myReader.Perform();
if(MYDEBUG){
MESSAGE("UNVToMesh - _myMeshDS->NbNodes() = "<<_myMeshDS->NbNodes());
MESSAGE("UNVToMesh - _myMeshDS->NbEdges() = "<<_myMeshDS->NbEdges());
MESSAGE("UNVToMesh - _myMeshDS->NbFaces() = "<<_myMeshDS->NbFaces());
MESSAGE("UNVToMesh - _myMeshDS->NbVolumes() = "<<_myMeshDS->NbVolumes());
}
SMDS_MeshGroup* aGroup = (SMDS_MeshGroup*) myReader.GetGroup();
if (aGroup != 0) {
TGroupNamesMap aGroupNames = myReader.GetGroupNamesMap();
//const TGroupIdMap& aGroupId = myReader.GetGroupIdMap();
aGroup->InitSubGroupsIterator();
while (aGroup->MoreSubGroups()) {
SMDS_MeshGroup* aSubGroup = (SMDS_MeshGroup*) aGroup->NextSubGroup();
string aName = aGroupNames[aSubGroup];
int aId;
SMESH_Group* aSMESHGroup = AddGroup( aSubGroup->GetType(), aName.c_str(), aId );
if ( aSMESHGroup ) {
if(MYDEBUG) MESSAGE("UNVToMesh - group added: "<<aName);
SMESHDS_Group* aGroupDS = dynamic_cast<SMESHDS_Group*>( aSMESHGroup->GetGroupDS() );
if ( aGroupDS ) {
aGroupDS->SetStoreName(aName.c_str());
aSubGroup->InitIterator();
const SMDS_MeshElement* aElement = 0;
while (aSubGroup->More()) {
aElement = aSubGroup->Next();
if (aElement) {
aGroupDS->SMDSGroup().Add(aElement);
}
}
if (aElement)
aGroupDS->SetType(aElement->GetType());
}
}
}
}
return 1;
}
//=======================================================================
//function : MEDToMesh
//purpose :
//=======================================================================
int SMESH_Mesh::MEDToMesh(const char* theFileName, const char* theMeshName)
{
if(MYDEBUG) MESSAGE("MEDToMesh - theFileName = "<<theFileName<<", mesh name = "<<theMeshName);
if(_isShapeToMesh)
throw SALOME_Exception(LOCALIZED("a shape to mesh has already been defined"));
_isShapeToMesh = false;
DriverMED_R_SMESHDS_Mesh myReader;
myReader.SetMesh(_myMeshDS);
myReader.SetMeshId(-1);
myReader.SetFile(theFileName);
myReader.SetMeshName(theMeshName);
Driver_Mesh::Status status = myReader.Perform();
if(MYDEBUG){
MESSAGE("MEDToMesh - _myMeshDS->NbNodes() = "<<_myMeshDS->NbNodes());
MESSAGE("MEDToMesh - _myMeshDS->NbEdges() = "<<_myMeshDS->NbEdges());
MESSAGE("MEDToMesh - _myMeshDS->NbFaces() = "<<_myMeshDS->NbFaces());
MESSAGE("MEDToMesh - _myMeshDS->NbVolumes() = "<<_myMeshDS->NbVolumes());
}
// Reading groups (sub-meshes are out of scope of MED import functionality)
list<TNameAndType> aGroupNames = myReader.GetGroupNamesAndTypes();
if(MYDEBUG) MESSAGE("MEDToMesh - Nb groups = "<<aGroupNames.size());
int anId;
list<TNameAndType>::iterator name_type = aGroupNames.begin();
for ( ; name_type != aGroupNames.end(); name_type++ ) {
SMESH_Group* aGroup = AddGroup( name_type->second, name_type->first.c_str(), anId );
if ( aGroup ) {
if(MYDEBUG) MESSAGE("MEDToMesh - group added: "<<name_type->first.c_str());
SMESHDS_Group* aGroupDS = dynamic_cast<SMESHDS_Group*>( aGroup->GetGroupDS() );
if ( aGroupDS ) {
aGroupDS->SetStoreName( name_type->first.c_str() );
myReader.GetGroup( aGroupDS );
}
}
}
return (int) status;
}
//=======================================================================
//function : STLToMesh
//purpose :
//=======================================================================
int SMESH_Mesh::STLToMesh(const char* theFileName)
{
if(MYDEBUG) MESSAGE("STLToMesh - theFileName = "<<theFileName);
if(_isShapeToMesh)
throw SALOME_Exception(LOCALIZED("a shape to mesh has already been defined"));
_isShapeToMesh = false;
DriverSTL_R_SMDS_Mesh myReader;
myReader.SetMesh(_myMeshDS);
myReader.SetFile(theFileName);
myReader.SetMeshId(-1);
myReader.Perform();
if(MYDEBUG){
MESSAGE("STLToMesh - _myMeshDS->NbNodes() = "<<_myMeshDS->NbNodes());
MESSAGE("STLToMesh - _myMeshDS->NbEdges() = "<<_myMeshDS->NbEdges());
MESSAGE("STLToMesh - _myMeshDS->NbFaces() = "<<_myMeshDS->NbFaces());
MESSAGE("STLToMesh - _myMeshDS->NbVolumes() = "<<_myMeshDS->NbVolumes());
}
return 1;
}
//=======================================================================
//function : DATToMesh
//purpose :
//=======================================================================
int SMESH_Mesh::DATToMesh(const char* theFileName)
{
if(MYDEBUG) MESSAGE("DATToMesh - theFileName = "<<theFileName);
if(_isShapeToMesh)
throw SMESH_Exception(LOCALIZED("a shape to mesh has already been defined"));
_isShapeToMesh = true;
DriverDAT_R_SMDS_Mesh myReader;
myReader.SetMesh(_myMeshDS);
myReader.SetFile(theFileName);
myReader.SetMeshId(-1);
myReader.Perform();
if(MYDEBUG){
MESSAGE("DATToMesh - _myMeshDS->NbNodes() = "<<_myMeshDS->NbNodes());
MESSAGE("DATToMesh - _myMeshDS->NbEdges() = "<<_myMeshDS->NbEdges());
MESSAGE("DATToMesh - _myMeshDS->NbFaces() = "<<_myMeshDS->NbFaces());
MESSAGE("DATToMesh - _myMeshDS->NbVolumes() = "<<_myMeshDS->NbVolumes());
}
return 1;
}
//================================================================================
/*!
* \brief Reads the given mesh from the CGNS file
* \param theFileName - name of the file
* \retval int - Driver_Mesh::Status
*/
//================================================================================
int SMESH_Mesh::CGNSToMesh(const char* theFileName,
const int theMeshIndex,
std::string& theMeshName)
{
int res = Driver_Mesh::DRS_FAIL;
#ifdef WITH_CGNS
DriverCGNS_Read myReader;
myReader.SetMesh(_myMeshDS);
myReader.SetFile(theFileName);
myReader.SetMeshId(theMeshIndex);
res = myReader.Perform();
theMeshName = myReader.GetMeshName();
// create groups
SynchronizeGroups();
#endif
return res;
}
//================================================================================
/*!
* \brief Fill its data by reading a GMF file
*/
//================================================================================
SMESH_ComputeErrorPtr SMESH_Mesh::GMFToMesh(const char* theFileName,
bool theMakeRequiredGroups)
{
DriverGMF_Read myReader;
myReader.SetMesh(_myMeshDS);
myReader.SetFile(theFileName);
myReader.SetMakeRequiredGroups( theMakeRequiredGroups );
myReader.Perform();
//theMeshName = myReader.GetMeshName();
// create groups
SynchronizeGroups();
return myReader.GetError();
}
//=============================================================================
/*!
*
*/
//=============================================================================
SMESH_Hypothesis::Hypothesis_Status
SMESH_Mesh::AddHypothesis(const TopoDS_Shape & aSubShape,
int anHypId,
std::string* anError )
{
Unexpect aCatch(SalomeException);
if(MYDEBUG) MESSAGE("SMESH_Mesh::AddHypothesis");
if ( anError )
anError->clear();
SMESH_subMesh *subMesh = GetSubMesh(aSubShape);
if ( !subMesh || !subMesh->GetId())
return SMESH_Hypothesis::HYP_BAD_SUBSHAPE;
SMESH_Hypothesis *anHyp = GetHypothesis( anHypId );
if ( !anHyp )
throw SALOME_Exception(LOCALIZED("hypothesis does not exist"));
bool isGlobalHyp = IsMainShape( aSubShape );
// NotConformAllowed can be only global
if ( !isGlobalHyp )
{
// NOTE: this is not a correct way to check a name of hypothesis,
// there should be an attribute of hypothesis saying that it can/can't
// be global/local
string hypName = anHyp->GetName();
if ( hypName == "NotConformAllowed" )
{
if(MYDEBUG) MESSAGE( "Hypotesis <NotConformAllowed> can be only global" );
return SMESH_Hypothesis::HYP_INCOMPATIBLE;
}
}
// shape
bool isAlgo = ( anHyp->GetType() != SMESHDS_Hypothesis::PARAM_ALGO );
int event = isAlgo ? SMESH_subMesh::ADD_ALGO : SMESH_subMesh::ADD_HYP;
SMESH_Hypothesis::Hypothesis_Status ret = subMesh->AlgoStateEngine(event, anHyp);
if ( anError && SMESH_Hypothesis::IsStatusFatal(ret) && subMesh->GetComputeError() )
*anError = subMesh->GetComputeError()->myComment;
// sub-shapes
if ( !SMESH_Hypothesis::IsStatusFatal(ret) &&
anHyp->GetDim() <= SMESH_Gen::GetShapeDim(aSubShape)) // is added on father
{
event = isAlgo ? SMESH_subMesh::ADD_FATHER_ALGO : SMESH_subMesh::ADD_FATHER_HYP;
SMESH_Hypothesis::Hypothesis_Status ret2 =
subMesh->SubMeshesAlgoStateEngine(event, anHyp, /*exitOnFatal=*/true);
if (ret2 > ret)
{
ret = ret2;
if ( SMESH_Hypothesis::IsStatusFatal( ret ))
{
if ( anError && subMesh->GetComputeError() )
*anError = subMesh->GetComputeError()->myComment;
// remove anHyp
event = isAlgo ? SMESH_subMesh::REMOVE_ALGO : SMESH_subMesh::REMOVE_HYP;
subMesh->AlgoStateEngine(event, anHyp);
}
}
// check concurent hypotheses on ancestors
if (ret < SMESH_Hypothesis::HYP_CONCURENT && !isGlobalHyp )
{
SMESH_subMeshIteratorPtr smIt = subMesh->getDependsOnIterator(false,false);
while ( smIt->more() ) {
SMESH_subMesh* sm = smIt->next();
if ( sm->IsApplicableHypotesis( anHyp )) {
ret2 = sm->CheckConcurentHypothesis( anHyp->GetType() );
if (ret2 > ret) {
ret = ret2;
break;
}
}
}
}
}
HasModificationsToDiscard(); // to reset _isModified flag if a mesh becomes empty
if(MYDEBUG) subMesh->DumpAlgoState(true);
if(MYDEBUG) SCRUTE(ret);
return ret;
}
//=============================================================================
/*!
*
*/
//=============================================================================
SMESH_Hypothesis::Hypothesis_Status
SMESH_Mesh::RemoveHypothesis(const TopoDS_Shape & aSubShape,
int anHypId)
{
Unexpect aCatch(SalomeException);
if(MYDEBUG) MESSAGE("SMESH_Mesh::RemoveHypothesis");
StudyContextStruct *sc = _gen->GetStudyContext(_studyId);
if (sc->mapHypothesis.find(anHypId) == sc->mapHypothesis.end())
throw SALOME_Exception(LOCALIZED("hypothesis does not exist"));
SMESH_Hypothesis *anHyp = sc->mapHypothesis[anHypId];
if(MYDEBUG) {
SCRUTE(anHyp->GetType());
}
// shape
bool isAlgo = !( anHyp->GetType() == SMESHDS_Hypothesis::PARAM_ALGO );
int event = isAlgo ? SMESH_subMesh::REMOVE_ALGO : SMESH_subMesh::REMOVE_HYP;
SMESH_subMesh *subMesh = GetSubMesh(aSubShape);
SMESH_Hypothesis::Hypothesis_Status ret = subMesh->AlgoStateEngine(event, anHyp);
// there may appear concurrent hyps that were covered by the removed hyp
if (ret < SMESH_Hypothesis::HYP_CONCURENT &&
subMesh->IsApplicableHypotesis( anHyp ) &&
subMesh->CheckConcurentHypothesis( anHyp->GetType() ) != SMESH_Hypothesis::HYP_OK)
ret = SMESH_Hypothesis::HYP_CONCURENT;
// sub-shapes
if (!SMESH_Hypothesis::IsStatusFatal(ret) &&
anHyp->GetDim() <= SMESH_Gen::GetShapeDim(aSubShape)) // is removed from father
{
event = isAlgo ? SMESH_subMesh::REMOVE_FATHER_ALGO : SMESH_subMesh::REMOVE_FATHER_HYP;
SMESH_Hypothesis::Hypothesis_Status ret2 =
subMesh->SubMeshesAlgoStateEngine(event, anHyp);
if (ret2 > ret) // more severe
ret = ret2;
// check concurent hypotheses on ancestors
if (ret < SMESH_Hypothesis::HYP_CONCURENT && !IsMainShape( aSubShape ) )
{
SMESH_subMeshIteratorPtr smIt = subMesh->getDependsOnIterator(false,false);
while ( smIt->more() ) {
SMESH_subMesh* sm = smIt->next();
if ( sm->IsApplicableHypotesis( anHyp )) {
ret2 = sm->CheckConcurentHypothesis( anHyp->GetType() );
if (ret2 > ret) {
ret = ret2;
break;
}
}
}
}
}
HasModificationsToDiscard(); // to reset _isModified flag if mesh become empty
if(MYDEBUG) subMesh->DumpAlgoState(true);
if(MYDEBUG) SCRUTE(ret);
return ret;
}
//=============================================================================
/*!
*
*/
//=============================================================================
const list<const SMESHDS_Hypothesis*>&
SMESH_Mesh::GetHypothesisList(const TopoDS_Shape & aSubShape) const
{
return _myMeshDS->GetHypothesis(aSubShape);
}
//=======================================================================
/*!
* \brief Return the hypothesis assigned to the shape
* \param aSubShape - the shape to check
* \param aFilter - the hypothesis filter
* \param andAncestors - flag to check hypos assigned to ancestors of the shape
* \param assignedTo - to return the shape the found hypo is assigned to
* \retval SMESH_Hypothesis* - the first hypo passed through aFilter
*/
//=======================================================================
const SMESH_Hypothesis * SMESH_Mesh::GetHypothesis(const TopoDS_Shape & aSubShape,
const SMESH_HypoFilter& aFilter,
const bool andAncestors,
TopoDS_Shape* assignedTo) const
{
return GetHypothesis( const_cast< SMESH_Mesh* >(this)->GetSubMesh( aSubShape ),
aFilter, andAncestors, assignedTo );
}
//=======================================================================
/*!
* \brief Return the hypothesis assigned to the shape of a sub-mesh
* \param aSubMesh - the sub-mesh to check
* \param aFilter - the hypothesis filter
* \param andAncestors - flag to check hypos assigned to ancestors of the shape
* \param assignedTo - to return the shape the found hypo is assigned to
* \retval SMESH_Hypothesis* - the first hypo passed through aFilter
*/
//=======================================================================
const SMESH_Hypothesis * SMESH_Mesh::GetHypothesis(const SMESH_subMesh * aSubMesh,
const SMESH_HypoFilter& aFilter,
const bool andAncestors,
TopoDS_Shape* assignedTo) const
{
if ( !aSubMesh ) return 0;
{
const TopoDS_Shape & aSubShape = aSubMesh->GetSubShape();
const list<const SMESHDS_Hypothesis*>& hypList = _myMeshDS->GetHypothesis(aSubShape);
list<const SMESHDS_Hypothesis*>::const_iterator hyp = hypList.begin();
for ( ; hyp != hypList.end(); hyp++ ) {
const SMESH_Hypothesis * h = cSMESH_Hyp( *hyp );
if ( aFilter.IsOk( h, aSubShape)) {
if ( assignedTo ) *assignedTo = aSubShape;
return h;
}
}
}
if ( andAncestors )
{
// user sorted submeshes of ancestors, according to stored submesh priority
std::vector< SMESH_subMesh * > & ancestors =
const_cast< std::vector< SMESH_subMesh * > & > ( aSubMesh->GetAncestors() );
SortByMeshOrder( ancestors );
vector<SMESH_subMesh*>::const_iterator smIt = ancestors.begin();
for ( ; smIt != ancestors.end(); smIt++ )
{
const TopoDS_Shape& curSh = (*smIt)->GetSubShape();
const list<const SMESHDS_Hypothesis*>& hypList = _myMeshDS->GetHypothesis(curSh);
list<const SMESHDS_Hypothesis*>::const_iterator hyp = hypList.begin();
for ( ; hyp != hypList.end(); hyp++ ) {
const SMESH_Hypothesis * h = cSMESH_Hyp( *hyp );
if (aFilter.IsOk( h, curSh )) {
if ( assignedTo ) *assignedTo = curSh;
return h;
}
}
}
}
return 0;
}
//================================================================================
/*!
* \brief Return hypotheses assigned to the shape
* \param aSubShape - the shape to check
* \param aFilter - the hypothesis filter
* \param aHypList - the list of the found hypotheses
* \param andAncestors - flag to check hypos assigned to ancestors of the shape
* \retval int - number of unique hypos in aHypList
*/
//================================================================================
int SMESH_Mesh::GetHypotheses(const TopoDS_Shape & aSubShape,
const SMESH_HypoFilter& aFilter,
list <const SMESHDS_Hypothesis * >& aHypList,
const bool andAncestors,
list< TopoDS_Shape > * assignedTo/*=0*/) const
{
return GetHypotheses( const_cast< SMESH_Mesh* >(this)->GetSubMesh( aSubShape ),
aFilter, aHypList, andAncestors, assignedTo );
}
//================================================================================
/*!
* \brief Return hypotheses assigned to the shape of a sub-mesh
* \param aSubShape - the sub-mesh to check
* \param aFilter - the hypothesis filter
* \param aHypList - the list of the found hypotheses
* \param andAncestors - flag to check hypos assigned to ancestors of the shape
* \retval int - number of unique hypos in aHypList
*/
//================================================================================
int SMESH_Mesh::GetHypotheses(const SMESH_subMesh * aSubMesh,
const SMESH_HypoFilter& aFilter,
list <const SMESHDS_Hypothesis * >& aHypList,
const bool andAncestors,
list< TopoDS_Shape > * assignedTo/*=0*/) const
{
if ( !aSubMesh ) return 0;
set<string> hypTypes; // to exclude same type hypos from the result list
int nbHyps = 0;
// only one main hypothesis is allowed
bool mainHypFound = false;
// fill in hypTypes
list<const SMESHDS_Hypothesis*>::const_iterator hyp;
for ( hyp = aHypList.begin(); hyp != aHypList.end(); hyp++ ) {
if ( hypTypes.insert( (*hyp)->GetName() ).second )
nbHyps++;
if ( !cSMESH_Hyp(*hyp)->IsAuxiliary() )
mainHypFound = true;
}
// get hypos from aSubShape
{
const TopoDS_Shape & aSubShape = aSubMesh->GetSubShape();
const list<const SMESHDS_Hypothesis*>& hypList = _myMeshDS->GetHypothesis(aSubShape);
for ( hyp = hypList.begin(); hyp != hypList.end(); hyp++ )
{
const SMESH_Hypothesis* h = cSMESH_Hyp( *hyp );
if (( aFilter.IsOk( h, aSubShape )) &&
( h->IsAuxiliary() || !mainHypFound ) &&
( h->IsAuxiliary() || hypTypes.insert( h->GetName() ).second ))
{
aHypList.push_back( *hyp );
nbHyps++;
if ( !h->IsAuxiliary() )
mainHypFound = true;
if ( assignedTo ) assignedTo->push_back( aSubShape );
}
}
}
// get hypos from ancestors of aSubShape
if ( andAncestors )