1 // Copyright (C) 2007-2012 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 // File : BLSURFPlugin_Hypothesis.cxx
22 // Authors : Francis KLOSS (OCC) & Patrick LAUG (INRIA) & Lioka RAZAFINDRAZAKA (CEA)
23 // & Aurelien ALLEAUME (DISTENE)
24 // Size maps development: Nicolas GEIMER (OCC) & Gilles DAVID (EURIWARE)
27 #include "BLSURFPlugin_Hypothesis.hxx"
28 #include "BLSURFPlugin_Attractor.hxx"
29 #include "SMESH_Gen_i.hxx"
30 #include <utilities.h>
36 #include "ShapeAnalysis.hxx"
39 #include CORBA_CLIENT_HEADER(SALOMEDS)
40 #include CORBA_CLIENT_HEADER(GEOM_Gen)
42 //=============================================================================
43 BLSURFPlugin_Hypothesis::BLSURFPlugin_Hypothesis(int hypId, int studyId, SMESH_Gen * gen) :
44 SMESH_Hypothesis(hypId, studyId, gen), _topology(GetDefaultTopology()),
45 _physicalMesh(GetDefaultPhysicalMesh()),
46 _phySize(GetDefaultPhySize()),
47 _phyMax(GetDefaultMaxSize()),
48 _phyMin(GetDefaultMinSize()),
49 _hgeoMax(GetDefaultMaxSize()),
50 _hgeoMin(GetDefaultMinSize()),
51 _geometricMesh(GetDefaultGeometricMesh()),
52 _angleMeshS(GetDefaultAngleMeshS()),
53 _angleMeshC(GetDefaultAngleMeshC()),
54 _gradation(GetDefaultGradation()),
55 _quadAllowed(GetDefaultQuadAllowed()),
56 _decimesh(GetDefaultDecimesh()),
57 _verb(GetDefaultVerbosity()),
58 _preCADMergeEdges(GetDefaultPreCADMergeEdges()),
59 _preCADRemoveNanoEdges(GetDefaultPreCADRemoveNanoEdges()),
60 _preCADDiscardInput(GetDefaultPreCADDiscardInput()),
61 _preCADEpsNano(GetDefaultPreCADEpsNano()),
62 _sizeMap(GetDefaultSizeMap()),
63 _attractors(GetDefaultSizeMap()),
64 _classAttractors(GetDefaultAttractorMap()),
65 _faceEntryEnfVertexListMap(GetDefaultFaceEntryEnfVertexListMap()),
66 _enfVertexList(GetDefaultEnfVertexList()),
67 _faceEntryCoordsListMap(GetDefaultFaceEntryCoordsListMap()),
68 _coordsEnfVertexMap(GetDefaultCoordsEnfVertexMap()),
69 _faceEntryEnfVertexEntryListMap(GetDefaultFaceEntryEnfVertexEntryListMap()),
70 _enfVertexEntryEnfVertexMap(GetDefaultEnfVertexEntryEnfVertexMap()),
71 _groupNameNodeIDMap(GetDefaultGroupNameNodeIDMap()),
72 _GMFFileName(GetDefaultGMFFile()),
73 _enforcedInternalVerticesAllFaces(GetDefaultInternalEnforcedVertex())
75 _name = "BLSURF_Parameters";
78 // _GMFFileMode = false; // GMF ascii mode
80 // to disable writing boundaries
81 //_phyMin = _phyMax = _hgeoMin = _hgeoMax = undefinedDouble();
84 const char* intOptionNames[] = { "addsurf_ivertex", "anisotropic", "background", "CheckAdjacentEdges", "CheckCloseEdges",
85 "CheckWellDefined", "coiter", "communication", "debug", "decim", "export_flag", "file_h", "frontal", "gridnu", "gridnv",
86 "hinterpol_flag", "hmean_flag", "intermedfile", "memory", "normals", "optim", "pardom_flag", "pinch", "refs",
87 "rigid", "surforient", "tconf", "topo_collapse",
88 "proximity", "prox_nb_layer", "prox_ratio", // detects the volumic proximity of surfaces
91 const char* doubleOptionNames[] = { "addsurf_angle", "addsurf_R", "addsurf_H", "addsurf_FG", "addsurf_r",
92 "addsurf_PA", "angle_compcurv", "angle_ridge", "anisotropic_ratio", "CoefRectangle", "eps_collapse", "eps_ends", "eps_pardom", "LSS",
93 "topo_eps1", "topo_eps2", "" // mark of end
95 const char* charOptionNames[] = { "export_format", "export_option", "import_option", "prefix", "" // mark of end
98 // PreCAD advanced options
99 const char* preCADintOptionNames[] = { "closed_geometry", "debug", "manifold_geometry", "create_tag_on_collision","" // mark of end
101 const char* preCADdoubleOptionNames[] = { "eps_nano_relative", "eps_sewing", "eps_sewing_relative", "periodic_tolerance",
102 "periodic_tolerance_relative", "periodic_split_tolerance", "periodic_split_tolerance_relative", "" // mark of end
106 while (intOptionNames[i][0])
107 _option2value[intOptionNames[i++]].clear();
110 while (preCADintOptionNames[i][0])
111 _preCADoption2value[preCADintOptionNames[i++]].clear();
114 while (doubleOptionNames[i][0]) {
115 _doubleOptions.insert(doubleOptionNames[i]);
116 _option2value[doubleOptionNames[i++]].clear();
119 while (preCADdoubleOptionNames[i][0]) {
120 _preCADdoubleOptions.insert(preCADdoubleOptionNames[i]);
121 _preCADoption2value[preCADdoubleOptionNames[i++]].clear();
124 while (charOptionNames[i][0]) {
125 _charOptions.insert(charOptionNames[i]);
126 _option2value[charOptionNames[i++]].clear();
133 _faceEntryEnfVertexListMap.clear();
134 _enfVertexList.clear();
135 _faceEntryCoordsListMap.clear();
136 _coordsEnfVertexMap.clear();
137 _faceEntryEnfVertexEntryListMap.clear();
138 _enfVertexEntryEnfVertexMap.clear();
139 _groupNameNodeIDMap.clear();
142 _groupNameEnfVertexListMap.clear();
143 _enfVertexGroupNameMap.clear();
147 TopoDS_Shape BLSURFPlugin_Hypothesis::entryToShape(std::string entry)
149 MESSAGE("BLSURFPlugin_Hypothesis::entryToShape "<<entry );
150 GEOM::GEOM_Object_var aGeomObj;
151 SMESH_Gen_i* smeshGen_i = SMESH_Gen_i::GetSMESHGen();
152 SALOMEDS::Study_ptr myStudy = smeshGen_i->GetCurrentStudy();
154 TopoDS_Shape S = TopoDS_Shape();
155 SALOMEDS::SObject_var aSObj = myStudy->FindObjectID( entry.c_str() );
156 SALOMEDS::GenericAttribute_var anAttr;
158 if (!aSObj->_is_nil() && aSObj->FindAttribute(anAttr, "AttributeIOR")) {
159 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
160 CORBA::String_var aVal = anIOR->Value();
161 CORBA::Object_var obj = myStudy->ConvertIORToObject(aVal);
162 aGeomObj = GEOM::GEOM_Object::_narrow(obj);
164 if ( !aGeomObj->_is_nil() )
165 S = smeshGen_i->GeomObjectToShape( aGeomObj.in() );
169 //=============================================================================
170 void BLSURFPlugin_Hypothesis::SetTopology(Topology theTopology) {
171 if (theTopology != _topology) {
172 _topology = theTopology;
173 NotifySubMeshesHypothesisModification();
177 //=============================================================================
178 void BLSURFPlugin_Hypothesis::SetPhysicalMesh(PhysicalMesh thePhysicalMesh) {
179 if (thePhysicalMesh != _physicalMesh) {
180 _physicalMesh = thePhysicalMesh;
181 NotifySubMeshesHypothesisModification();
185 //=============================================================================
186 void BLSURFPlugin_Hypothesis::SetPhySize(double theVal) {
187 if (theVal != _phySize) {
189 _phySize = GetPhyMax();
190 MESSAGE("Warning: nul physical size is not allowed");
194 NotifySubMeshesHypothesisModification();
198 //=============================================================================
199 void BLSURFPlugin_Hypothesis::SetPhyMin(double theMinSize) {
200 if (theMinSize != _phyMin) {
201 _phyMin = theMinSize;
202 NotifySubMeshesHypothesisModification();
206 //=============================================================================
207 void BLSURFPlugin_Hypothesis::SetPhyMax(double theMaxSize) {
208 if (theMaxSize != _phyMax) {
209 _phyMax = theMaxSize;
210 NotifySubMeshesHypothesisModification();
214 //=============================================================================
215 void BLSURFPlugin_Hypothesis::SetGeoMin(double theMinSize) {
216 if (theMinSize != _hgeoMin) {
217 _hgeoMin = theMinSize;
218 NotifySubMeshesHypothesisModification();
222 //=============================================================================
223 void BLSURFPlugin_Hypothesis::SetGeoMax(double theMaxSize) {
224 if (theMaxSize != _hgeoMax) {
225 _hgeoMax = theMaxSize;
226 NotifySubMeshesHypothesisModification();
230 //=============================================================================
231 void BLSURFPlugin_Hypothesis::SetGeometricMesh(GeometricMesh theGeometricMesh) {
232 if (theGeometricMesh != _geometricMesh) {
233 _geometricMesh = theGeometricMesh;
234 switch (_geometricMesh) {
237 _angleMeshS = GetDefaultAngleMeshS();
238 _gradation = GetDefaultGradation();
241 NotifySubMeshesHypothesisModification();
245 //=============================================================================
246 void BLSURFPlugin_Hypothesis::SetAngleMeshS(double theVal) {
247 if (theVal != _angleMeshS) {
248 _angleMeshS = theVal;
249 NotifySubMeshesHypothesisModification();
253 //=============================================================================
254 void BLSURFPlugin_Hypothesis::SetAngleMeshC(double theVal) {
255 if (theVal != _angleMeshC) {
256 _angleMeshC = theVal;
257 NotifySubMeshesHypothesisModification();
261 //=============================================================================
262 void BLSURFPlugin_Hypothesis::SetGradation(double theVal) {
263 if (theVal != _gradation) {
265 NotifySubMeshesHypothesisModification();
269 //=============================================================================
270 void BLSURFPlugin_Hypothesis::SetQuadAllowed(bool theVal) {
271 if (theVal != _quadAllowed) {
272 _quadAllowed = theVal;
273 NotifySubMeshesHypothesisModification();
277 //=============================================================================
278 void BLSURFPlugin_Hypothesis::SetDecimesh(bool theVal) {
279 if (theVal != _decimesh) {
281 NotifySubMeshesHypothesisModification();
285 //=============================================================================
286 void BLSURFPlugin_Hypothesis::SetVerbosity(int theVal) {
287 if (theVal != _verb) {
289 NotifySubMeshesHypothesisModification();
293 //=============================================================================
294 void BLSURFPlugin_Hypothesis::SetPreCADMergeEdges(bool theVal) {
295 if (theVal != _preCADMergeEdges) {
297 _preCADMergeEdges = theVal;
298 NotifySubMeshesHypothesisModification();
302 //=============================================================================
303 void BLSURFPlugin_Hypothesis::SetPreCADRemoveNanoEdges(bool theVal) {
304 if (theVal != _preCADRemoveNanoEdges) {
306 _preCADRemoveNanoEdges = theVal;
307 NotifySubMeshesHypothesisModification();
311 //=============================================================================
312 void BLSURFPlugin_Hypothesis::SetPreCADDiscardInput(bool theVal) {
313 if (theVal != _preCADDiscardInput) {
315 _preCADDiscardInput = theVal;
316 NotifySubMeshesHypothesisModification();
320 //=============================================================================
321 void BLSURFPlugin_Hypothesis::SetPreCADEpsNano(double theVal) {
322 if (theVal != _preCADEpsNano) {
324 _preCADEpsNano = theVal;
325 NotifySubMeshesHypothesisModification();
329 //=============================================================================
330 // void BLSURFPlugin_Hypothesis::SetGMFFile(const std::string& theFileName, bool isBinary)
331 void BLSURFPlugin_Hypothesis::SetGMFFile(const std::string& theFileName)
333 _GMFFileName = theFileName;
334 // _GMFFileMode = isBinary;
335 NotifySubMeshesHypothesisModification();
338 //=============================================================================
339 void BLSURFPlugin_Hypothesis::SetOptionValue(const std::string& optionName, const std::string& optionValue)
340 throw (std::invalid_argument) {
341 TOptionValues::iterator op_val = _option2value.find(optionName);
342 if (op_val == _option2value.end()) {
343 std::string msg = "Unknown BLSURF option: '" + optionName + "'";
344 throw std::invalid_argument(msg);
346 if (op_val->second != optionValue) {
347 const char* ptr = optionValue.c_str();
348 // strip white spaces
349 while (ptr[0] == ' ')
352 while (i != 0 && ptr[i - 1] == ' ')
356 std::string typeName;
359 } else if (_charOptions.find(optionName) != _charOptions.end()) {
360 // do not check strings
361 } else if (_doubleOptions.find(optionName) != _doubleOptions.end()) {
362 // check if value is double
364 strtod(ptr, &endPtr);
365 typeOk = (ptr != endPtr);
368 // check if value is int
370 strtol(ptr, &endPtr, 10);
371 typeOk = (ptr != endPtr);
372 typeName = "integer";
375 std::string msg = "Advanced option '" + optionName + "' = '" + optionValue + "' but must be " + typeName;
376 throw std::invalid_argument(msg);
378 op_val->second = optionValue;
379 NotifySubMeshesHypothesisModification();
383 //=============================================================================
384 void BLSURFPlugin_Hypothesis::SetPreCADOptionValue(const std::string& optionName, const std::string& optionValue)
385 throw (std::invalid_argument) {
386 TOptionValues::iterator op_val = _preCADoption2value.find(optionName);
387 if (op_val == _preCADoption2value.end()) {
388 std::string msg = "Unknown BLSURF option: '" + optionName + "'";
389 throw std::invalid_argument(msg);
391 if (op_val->second != optionValue) {
392 const char* ptr = optionValue.c_str();
393 // strip white spaces
394 while (ptr[0] == ' ')
397 while (i != 0 && ptr[i - 1] == ' ')
401 std::string typeName;
404 } else if (_preCADdoubleOptions.find(optionName) != _preCADdoubleOptions.end()) {
405 // check if value is double
407 strtod(ptr, &endPtr);
408 typeOk = (ptr != endPtr);
411 // check if value is int
413 strtol(ptr, &endPtr, 10);
414 typeOk = (ptr != endPtr);
415 typeName = "integer";
418 std::string msg = "PreCAD advanced option '" + optionName + "' = '" + optionValue + "' but must be " + typeName;
419 throw std::invalid_argument(msg);
421 op_val->second = optionValue;
422 NotifySubMeshesHypothesisModification();
426 //=============================================================================
427 std::string BLSURFPlugin_Hypothesis::GetOptionValue(const std::string& optionName) throw (std::invalid_argument) {
428 TOptionValues::iterator op_val = _option2value.find(optionName);
429 if (op_val == _option2value.end()) {
430 std::string msg = "Unknown BLSURF option: <";
431 msg += optionName + ">";
432 throw std::invalid_argument(msg);
434 return op_val->second;
437 //=============================================================================
438 std::string BLSURFPlugin_Hypothesis::GetPreCADOptionValue(const std::string& optionName) throw (std::invalid_argument) {
439 TOptionValues::iterator op_val = _preCADoption2value.find(optionName);
440 if (op_val == _preCADoption2value.end()) {
441 std::string msg = "Unknown PRECAD option: <";
442 msg += optionName + ">";
443 throw std::invalid_argument(msg);
445 return op_val->second;
448 //=============================================================================
449 void BLSURFPlugin_Hypothesis::ClearOption(const std::string& optionName) {
450 TOptionValues::iterator op_val = _option2value.find(optionName);
451 if (op_val != _option2value.end())
452 op_val->second.clear();
455 //=============================================================================
456 void BLSURFPlugin_Hypothesis::ClearPreCADOption(const std::string& optionName) {
457 TOptionValues::iterator op_val = _preCADoption2value.find(optionName);
458 if (op_val != _preCADoption2value.end())
459 op_val->second.clear();
462 //=======================================================================
463 //function : SetSizeMapEntry
464 //=======================================================================
465 void BLSURFPlugin_Hypothesis::SetSizeMapEntry(const std::string& entry, const std::string& sizeMap) {
466 if (_sizeMap[entry].compare(sizeMap) != 0) {
467 SetPhysicalMesh(SizeMap);
468 _sizeMap[entry] = sizeMap;
469 NotifySubMeshesHypothesisModification();
473 //=======================================================================
474 //function : GetSizeMapEntry
475 //=======================================================================
476 std::string BLSURFPlugin_Hypothesis::GetSizeMapEntry(const std::string& entry) {
477 TSizeMap::iterator it = _sizeMap.find(entry);
478 if (it != _sizeMap.end())
481 return "No_Such_Entry";
485 * \brief Return the size maps
487 BLSURFPlugin_Hypothesis::TSizeMap BLSURFPlugin_Hypothesis::GetSizeMapEntries(const BLSURFPlugin_Hypothesis* hyp) {
488 return hyp ? hyp->_GetSizeMapEntries() : GetDefaultSizeMap();
491 //=======================================================================
492 //function : SetAttractorEntry
493 //=======================================================================
494 void BLSURFPlugin_Hypothesis::SetAttractorEntry(const std::string& entry, const std::string& attractor) {
495 if (_attractors[entry].compare(attractor) != 0) {
496 SetPhysicalMesh(SizeMap);
497 _attractors[entry] = attractor;
498 NotifySubMeshesHypothesisModification();
502 //=======================================================================
503 //function : GetAttractorEntry
504 //=======================================================================
505 std::string BLSURFPlugin_Hypothesis::GetAttractorEntry(const std::string& entry) {
506 TSizeMap::iterator it = _attractors.find(entry);
507 if (it != _attractors.end())
510 return "No_Such_Entry";
514 * \brief Return the attractors
516 BLSURFPlugin_Hypothesis::TSizeMap BLSURFPlugin_Hypothesis::GetAttractorEntries(const BLSURFPlugin_Hypothesis* hyp) {
517 return hyp ? hyp->_GetAttractorEntries() : GetDefaultSizeMap();
520 //=======================================================================
521 //function : SetClassAttractorEntry
522 //=======================================================================
523 void BLSURFPlugin_Hypothesis::SetClassAttractorEntry(const std::string& entry, const std::string& attEntry, double StartSize, double EndSize, double ActionRadius, double ConstantRadius)
525 SetPhysicalMesh(SizeMap);
527 // The new attractor can't be defined on the same face as another sizemap
528 TSizeMap::iterator it = _sizeMap.find( entry );
529 if ( it != _sizeMap.end() ) {
531 NotifySubMeshesHypothesisModification();
534 TSizeMap::iterator itAt = _attractors.find( entry );
535 if ( itAt != _attractors.end() ) {
536 _attractors.erase(itAt);
537 NotifySubMeshesHypothesisModification();
541 const TopoDS_Shape AttractorShape = BLSURFPlugin_Hypothesis::entryToShape(attEntry);
542 const TopoDS_Face FaceShape = TopoDS::Face(BLSURFPlugin_Hypothesis::entryToShape(entry));
543 bool attExists = (_classAttractors.find(entry) != _classAttractors.end());
544 double u1,u2,v1,v2, diag;
546 if ( !attExists || (attExists && _classAttractors[entry]->GetAttractorEntry().compare(attEntry) != 0)){
547 ShapeAnalysis::GetFaceUVBounds(FaceShape,u1,u2,v1,v2);
548 // diag = sqrt((u2 - u1) * (u2 - u1) + (v2 - v1) * (v2 - v1));
549 BLSURFPlugin_Attractor* myAttractor = new BLSURFPlugin_Attractor(FaceShape, AttractorShape, attEntry);//, 0.1 ); // test 0.002 * diag);
550 myAttractor->BuildMap();
551 myAttractor->SetParameters(StartSize, EndSize, ActionRadius, ConstantRadius);
552 _classAttractors[entry] = myAttractor;
553 NotifySubMeshesHypothesisModification();
556 _classAttractors[entry]->SetParameters(StartSize, EndSize, ActionRadius, ConstantRadius);
557 if (!_classAttractors[entry]->IsMapBuilt()){
558 _classAttractors[entry]->BuildMap();
560 NotifySubMeshesHypothesisModification();
565 //=======================================================================
566 //function : SetConstantSizeOnAdjacentFaces
567 //=======================================================================
568 // TODO uncomment and test (include the needed .hxx)
569 // SetConstantSizeOnAdjacentFaces(myShape, att_entry, startSize, endSize = user_size, const_dist ) {
570 // TopTools_IndexedMapOfShapListOdShape anEdge2FaceMap;
571 // TopExp::MapShapesAnAncestors(myShape,TopAbs_EDGE, TopAbs_FACE, anEdge2FaceMap);
572 // TopTools_IndexedMapOfShapListOdShape::iterator it;
573 // for (it = anEdge2FaceMap.begin();it != anEdge2FaceMap.end();it++){
574 // SetClassAttractorEntry((*it).first, att_entry, startSize, endSize, 0, const_dist)
582 //=======================================================================
583 //function : GetClassAttractorEntry
584 //=======================================================================
585 // BLSURFPlugin_Attractor& BLSURFPlugin_Hypothesis::GetClassAttractorEntry(const std::string& entry)
587 // TAttractorMap::iterator it = _classAttractors.find( entry );
588 // if ( it != _classAttractors.end() )
589 // return it->second;
591 // return "No_Such_Entry";
595 * \brief Return the map of attractor instances
597 BLSURFPlugin_Hypothesis::TAttractorMap BLSURFPlugin_Hypothesis::GetClassAttractorEntries(const BLSURFPlugin_Hypothesis* hyp)
599 return hyp ? hyp->_GetClassAttractorEntries():GetDefaultAttractorMap();
602 //=======================================================================
603 //function : ClearEntry
604 //=======================================================================
605 void BLSURFPlugin_Hypothesis::ClearEntry(const std::string& entry)
607 TSizeMap::iterator it = _sizeMap.find( entry );
609 if ( it != _sizeMap.end() ) {
611 NotifySubMeshesHypothesisModification();
614 TSizeMap::iterator itAt = _attractors.find( entry );
615 if ( itAt != _attractors.end() ) {
616 _attractors.erase(itAt);
617 NotifySubMeshesHypothesisModification();
620 TAttractorMap::iterator it_clAt = _classAttractors.find( entry );
621 if ( it_clAt != _classAttractors.end() ) {
622 _classAttractors.erase(it_clAt);
623 MESSAGE("_classAttractors.size() = "<<_classAttractors.size())
624 NotifySubMeshesHypothesisModification();
627 std::cout<<"No_Such_Entry"<<std::endl;
632 //=======================================================================
633 //function : ClearSizeMaps
634 //=======================================================================
635 void BLSURFPlugin_Hypothesis::ClearSizeMaps() {
638 _classAttractors.clear();
641 // Enable internal enforced vertices on specific face if requested by user
643 ////=======================================================================
644 ////function : SetInternalEnforcedVertex
645 ////=======================================================================
646 //void BLSURFPlugin_Hypothesis::SetInternalEnforcedVertex(TEntry theFaceEntry,
647 // bool toEnforceInternalVertices,
648 // TEnfGroupName theGroupName) {
650 // MESSAGE("BLSURFPlugin_Hypothesis::SetInternalEnforcedVertex("<< theFaceEntry << ", "
651 // << toEnforceInternalVertices << ", " << theGroupName << ")");
653 // TFaceEntryInternalVerticesList::iterator it = _faceEntryInternalVerticesList.find(theFaceEntry);
654 // if (it != _faceEntryInternalVerticesList.end()) {
655 // if (!toEnforceInternalVertices) {
656 // _faceEntryInternalVerticesList.erase(it);
660 // if (toEnforceInternalVertices) {
661 // _faceEntryInternalVerticesList.insert(theFaceEntry);
666 // // Take care of groups
670 //=======================================================================
671 //function : SetEnforcedVertex
672 //=======================================================================
673 bool BLSURFPlugin_Hypothesis::SetEnforcedVertex(TEntry theFaceEntry, TEnfName theVertexName, TEntry theVertexEntry,
674 TEnfGroupName theGroupName, double x, double y, double z) {
676 MESSAGE("BLSURFPlugin_Hypothesis::SetEnforcedVertex("<< theFaceEntry << ", "
677 << x << ", " << y << ", " << z << ", " << theVertexName << ", " << theVertexEntry << ", " << theGroupName << ")");
679 SetPhysicalMesh(SizeMap);
681 // TEnfVertexList::iterator it;
682 bool toNotify = false;
683 bool toCreate = true;
685 TEnfVertex *oldEnVertex;
686 TEnfVertex *newEnfVertex = new TEnfVertex();
687 newEnfVertex->name = theVertexName;
688 newEnfVertex->geomEntry = theVertexEntry;
689 newEnfVertex->coords.clear();
690 if (theVertexEntry == "") {
691 newEnfVertex->coords.push_back(x);
692 newEnfVertex->coords.push_back(y);
693 newEnfVertex->coords.push_back(z);
695 newEnfVertex->grpName = theGroupName;
696 newEnfVertex->faceEntries.clear();
697 newEnfVertex->faceEntries.insert(theFaceEntry);
700 // update _enfVertexList
701 TEnfVertexList::iterator it = _enfVertexList.find(newEnfVertex);
702 if (it != _enfVertexList.end()) {
705 MESSAGE("Enforced Vertex was found => Update");
706 if (oldEnVertex->name != theVertexName) {
707 MESSAGE("Update name from \"" << oldEnVertex->name << "\" to \"" << theVertexName << "\"");
708 oldEnVertex->name = theVertexName;
711 if (oldEnVertex->grpName != theGroupName) {
712 MESSAGE("Update group name from \"" << oldEnVertex->grpName << "\" to \"" << theGroupName << "\"");
713 oldEnVertex->grpName = theGroupName;
716 TEntryList::iterator it_faceEntries = oldEnVertex->faceEntries.find(theFaceEntry);
717 if (it_faceEntries == oldEnVertex->faceEntries.end()) {
718 MESSAGE("Update face list by adding \"" << theFaceEntry << "\"");
719 oldEnVertex->faceEntries.insert(theFaceEntry);
720 _faceEntryEnfVertexListMap[theFaceEntry].insert(oldEnVertex);
724 // update map coords / enf vertex if needed
725 if (oldEnVertex->coords.size()) {
726 _coordsEnfVertexMap[oldEnVertex->coords] = oldEnVertex;
727 _faceEntryCoordsListMap[theFaceEntry].insert(oldEnVertex->coords);
730 // update map geom entry / enf vertex if needed
731 if (oldEnVertex->geomEntry != "") {
732 _enfVertexEntryEnfVertexMap[oldEnVertex->geomEntry] = oldEnVertex;
733 _faceEntryEnfVertexEntryListMap[theFaceEntry].insert(oldEnVertex->geomEntry);
738 // //////// CREATE ////////////
741 MESSAGE("Creating new enforced vertex");
742 _faceEntryEnfVertexListMap[theFaceEntry].insert(newEnfVertex);
743 _enfVertexList.insert(newEnfVertex);
744 if (theVertexEntry == "") {
745 _faceEntryCoordsListMap[theFaceEntry].insert(newEnfVertex->coords);
746 _coordsEnfVertexMap[newEnfVertex->coords] = newEnfVertex;
749 _faceEntryEnfVertexEntryListMap[theFaceEntry].insert(newEnfVertex->geomEntry);
750 _enfVertexEntryEnfVertexMap[newEnfVertex->geomEntry] = newEnfVertex;
755 NotifySubMeshesHypothesisModification();
757 MESSAGE("BLSURFPlugin_Hypothesis::SetEnforcedVertex END");
762 //=======================================================================
763 //function : GetEnforcedVertices
764 //=======================================================================
766 BLSURFPlugin_Hypothesis::TEnfVertexList BLSURFPlugin_Hypothesis::GetEnfVertexList(const TEntry& theFaceEntry)
767 throw (std::invalid_argument) {
769 if (_faceEntryEnfVertexListMap.count(theFaceEntry) > 0)
770 return _faceEntryEnfVertexListMap[theFaceEntry];
772 return GetDefaultEnfVertexList();
774 std::ostringstream msg;
775 msg << "No enforced vertex for face entry " << theFaceEntry;
776 throw std::invalid_argument(msg.str());
779 //=======================================================================
780 //function : GetEnfVertexCoordsList
781 //=======================================================================
783 BLSURFPlugin_Hypothesis::TEnfVertexCoordsList BLSURFPlugin_Hypothesis::GetEnfVertexCoordsList(
784 const TEntry& theFaceEntry) throw (std::invalid_argument) {
786 if (_faceEntryCoordsListMap.count(theFaceEntry) > 0)
787 return _faceEntryCoordsListMap[theFaceEntry];
789 std::ostringstream msg;
790 msg << "No enforced vertex coords for face entry " << theFaceEntry;
791 throw std::invalid_argument(msg.str());
794 //=======================================================================
795 //function : GetEnfVertexEntryList
796 //=======================================================================
798 BLSURFPlugin_Hypothesis::TEntryList BLSURFPlugin_Hypothesis::GetEnfVertexEntryList(const TEntry& theFaceEntry)
799 throw (std::invalid_argument) {
801 if (_faceEntryEnfVertexEntryListMap.count(theFaceEntry) > 0)
802 return _faceEntryEnfVertexEntryListMap[theFaceEntry];
804 std::ostringstream msg;
805 msg << "No enforced vertex entry for face entry " << theFaceEntry;
806 throw std::invalid_argument(msg.str());
809 //=======================================================================
810 //function : GetEnfVertex(TEnfVertexCoords coords)
811 //=======================================================================
813 BLSURFPlugin_Hypothesis::TEnfVertex* BLSURFPlugin_Hypothesis::GetEnfVertex(TEnfVertexCoords coords)
814 throw (std::invalid_argument) {
816 if (_coordsEnfVertexMap.count(coords) > 0)
817 return _coordsEnfVertexMap[coords];
819 std::ostringstream msg;
820 msg << "No enforced vertex with coords (" << coords[0] << ", " << coords[1] << ", " << coords[2] << ")";
821 throw std::invalid_argument(msg.str());
824 //=======================================================================
825 //function : GetEnfVertex(const TEntry& theEnfVertexEntry)
826 //=======================================================================
828 BLSURFPlugin_Hypothesis::TEnfVertex* BLSURFPlugin_Hypothesis::GetEnfVertex(const TEntry& theEnfVertexEntry)
829 throw (std::invalid_argument) {
831 if (_enfVertexEntryEnfVertexMap.count(theEnfVertexEntry) > 0)
832 return _enfVertexEntryEnfVertexMap[theEnfVertexEntry];
834 std::ostringstream msg;
835 msg << "No enforced vertex with entry " << theEnfVertexEntry;
836 throw std::invalid_argument(msg.str());
839 //Enable internal enforced vertices on specific face if requested by user
840 ////=======================================================================
841 ////function : GetInternalEnforcedVertex
842 ////=======================================================================
844 //bool BLSURFPlugin_Hypothesis::GetInternalEnforcedVertex(const TEntry& theFaceEntry)
846 // if (_faceEntryInternalVerticesList.count(theFaceEntry) > 0)
851 //=======================================================================
852 //function : ClearEnforcedVertex
853 //=======================================================================
855 bool BLSURFPlugin_Hypothesis::ClearEnforcedVertex(const TEntry& theFaceEntry, double x, double y, double z,
856 const TEntry& theVertexEntry) throw (std::invalid_argument) {
858 bool toNotify = false;
859 std::ostringstream msg;
860 TEnfVertex *oldEnfVertex;
861 TEnfVertexCoords coords;
867 // check that enf vertex with given enf vertex entry exists
868 TEnfVertexEntryEnfVertexMap::iterator it_enfVertexEntry = _enfVertexEntryEnfVertexMap.find(theVertexEntry);
869 if (it_enfVertexEntry != _enfVertexEntryEnfVertexMap.end()) {
871 MESSAGE("Found enforced vertex with geom entry " << theVertexEntry);
872 oldEnfVertex = it_enfVertexEntry->second;
874 _enfVertexEntryEnfVertexMap.erase(it_enfVertexEntry);
876 TEntryList& enfVertexEntryList = _faceEntryEnfVertexEntryListMap[theFaceEntry];
877 enfVertexEntryList.erase(theVertexEntry);
878 if (enfVertexEntryList.size() == 0)
879 _faceEntryEnfVertexEntryListMap.erase(theFaceEntry);
880 // TFaceEntryEnfVertexEntryListMap::iterator it_entry_entry = _faceEntryEnfVertexEntryListMap.find(theFaceEntry);
881 // TEntryList::iterator it_entryList = it_entry_entry->second.find(theVertexEntry);
882 // it_entry_entry->second.erase(it_entryList);
883 // if (it_entry_entry->second.size() == 0)
884 // _faceEntryEnfVertexEntryListMap.erase(it_entry_entry);
887 MESSAGE("Enforced vertex with geom entry " << theVertexEntry << " not found");
888 msg << "No enforced vertex with geom entry " << theVertexEntry;
889 // check that enf vertex with given coords exists
890 TCoordsEnfVertexMap::iterator it_coords_enf = _coordsEnfVertexMap.find(coords);
891 if (it_coords_enf != _coordsEnfVertexMap.end()) {
893 MESSAGE("Found enforced vertex with coords " << x << ", " << y << ", " << z);
894 oldEnfVertex = it_coords_enf->second;
896 _coordsEnfVertexMap.erase(it_coords_enf);
898 TEnfVertexCoordsList& enfVertexCoordsList = _faceEntryCoordsListMap[theFaceEntry];
899 enfVertexCoordsList.erase(coords);
900 if (enfVertexCoordsList.size() == 0)
901 _faceEntryCoordsListMap.erase(theFaceEntry);
902 // TFaceEntryCoordsListMap::iterator it_entry_coords = _faceEntryCoordsListMap.find(theFaceEntry);
903 // TEnfVertexCoordsList::iterator it_coordsList = it_entry_coords->second.find(coords);
904 // it_entry_coords->second.erase(it_coordsList);
905 // if (it_entry_coords->second.size() == 0)
906 // _faceEntryCoordsListMap.erase(it_entry_coords);
909 MESSAGE("Enforced vertex with coords " << x << ", " << y << ", " << z << " not found");
911 msg << "No enforced vertex at " << x << ", " << y << ", " << z;
912 throw std::invalid_argument(msg.str());
916 MESSAGE("Remove enf vertex from _enfVertexList");
918 // update _enfVertexList
919 TEnfVertexList::iterator it = _enfVertexList.find(oldEnfVertex);
920 if (it != _enfVertexList.end()) {
921 (*it)->faceEntries.erase(theFaceEntry);
922 if ((*it)->faceEntries.size() == 0){
923 _enfVertexList.erase(it);
929 // update _faceEntryEnfVertexListMap
930 TEnfVertexList& currentEnfVertexList = _faceEntryEnfVertexListMap[theFaceEntry];
931 currentEnfVertexList.erase(oldEnfVertex);
933 if (currentEnfVertexList.size() == 0) {
934 MESSAGE("Remove _faceEntryEnfVertexListMap[" << theFaceEntry <<"]");
935 _faceEntryEnfVertexListMap.erase(theFaceEntry);
940 NotifySubMeshesHypothesisModification();
945 //=======================================================================
946 //function : ClearEnforcedVertices
947 //=======================================================================
949 bool BLSURFPlugin_Hypothesis::ClearEnforcedVertices(const TEntry& theFaceEntry) throw (std::invalid_argument) {
951 bool toNotify = false;
952 TEnfVertex *oldEnfVertex;
954 TFaceEntryCoordsListMap::iterator it_entry_coords = _faceEntryCoordsListMap.find(theFaceEntry);
955 if (it_entry_coords != _faceEntryCoordsListMap.end()) {
957 TEnfVertexCoordsList coordsList = it_entry_coords->second;
958 TEnfVertexCoordsList::iterator it_coordsList = coordsList.begin();
959 for (; it_coordsList != coordsList.end(); ++it_coordsList) {
960 TEnfVertexCoords coords = (*it_coordsList);
961 oldEnfVertex = _coordsEnfVertexMap[coords];
962 _coordsEnfVertexMap.erase(coords);
963 // update _enfVertexList
964 TEnfVertexList::iterator it = _enfVertexList.find(oldEnfVertex);
965 if (it != _enfVertexList.end()) {
966 (*it)->faceEntries.erase(theFaceEntry);
967 if ((*it)->faceEntries.size() == 0){
968 _enfVertexList.erase(it);
974 _faceEntryCoordsListMap.erase(it_entry_coords);
975 _faceEntryEnfVertexListMap.erase(theFaceEntry);
978 TFaceEntryEnfVertexEntryListMap::iterator it_entry_entry = _faceEntryEnfVertexEntryListMap.find(theFaceEntry);
979 if (it_entry_entry != _faceEntryEnfVertexEntryListMap.end()) {
981 TEntryList enfVertexEntryList = it_entry_entry->second;
982 TEntryList::iterator it_enfVertexEntryList = enfVertexEntryList.begin();
983 for (; it_enfVertexEntryList != enfVertexEntryList.end(); ++it_enfVertexEntryList) {
984 TEntry enfVertexEntry = (*it_enfVertexEntryList);
985 oldEnfVertex = _enfVertexEntryEnfVertexMap[enfVertexEntry];
986 _enfVertexEntryEnfVertexMap.erase(enfVertexEntry);
987 // update _enfVertexList
988 TEnfVertexList::iterator it = _enfVertexList.find(oldEnfVertex);
989 if (it != _enfVertexList.end()) {
990 (*it)->faceEntries.erase(theFaceEntry);
991 if ((*it)->faceEntries.size() == 0){
992 _enfVertexList.erase(it);
998 _faceEntryEnfVertexEntryListMap.erase(it_entry_entry);
999 _faceEntryEnfVertexListMap.erase(theFaceEntry);
1003 NotifySubMeshesHypothesisModification();
1006 // std::ostringstream msg;
1007 // msg << "No enforced vertex for " << theFaceEntry;
1008 // throw std::invalid_argument(msg.str());
1011 //=======================================================================
1012 //function : ClearAllEnforcedVertices
1013 //=======================================================================
1014 void BLSURFPlugin_Hypothesis::ClearAllEnforcedVertices() {
1015 _faceEntryEnfVertexListMap.clear();
1016 _enfVertexList.clear();
1017 _faceEntryCoordsListMap.clear();
1018 _coordsEnfVertexMap.clear();
1019 _faceEntryEnfVertexEntryListMap.clear();
1020 _enfVertexEntryEnfVertexMap.clear();
1021 // Enable internal enforced vertices on specific face if requested by user
1022 // _faceEntryInternalVerticesList.clear();
1023 NotifySubMeshesHypothesisModification();
1026 //================================================================================
1028 * \brief Return the enforced vertices
1030 //================================================================================
1033 BLSURFPlugin_Hypothesis::TFaceEntryEnfVertexListMap BLSURFPlugin_Hypothesis::GetAllEnforcedVerticesByFace(
1034 const BLSURFPlugin_Hypothesis* hyp) {
1035 return hyp ? hyp->_GetAllEnforcedVerticesByFace() : GetDefaultFaceEntryEnfVertexListMap();
1038 //Enable internal enforced vertices on specific face if requested by user
1039 //BLSURFPlugin_Hypothesis::TFaceEntryInternalVerticesList BLSURFPlugin_Hypothesis::GetAllInternalEnforcedVerticesByFace(
1040 // const BLSURFPlugin_Hypothesis* hyp) {
1041 // return hyp ? hyp->_GetAllInternalEnforcedVerticesByFace() : GetDefaultFaceEntryInternalVerticesMap();
1044 bool BLSURFPlugin_Hypothesis::GetInternalEnforcedVertexAllFaces(const BLSURFPlugin_Hypothesis* hyp)
1046 return hyp ? hyp->_GetInternalEnforcedVertexAllFaces() : GetDefaultInternalEnforcedVertex();
1049 BLSURFPlugin_Hypothesis::TEnfGroupName BLSURFPlugin_Hypothesis::GetInternalEnforcedVertexAllFacesGroup(const BLSURFPlugin_Hypothesis* hyp)
1051 return hyp ? hyp->_GetInternalEnforcedVertexAllFacesGroup() : BLSURFPlugin_Hypothesis::TEnfGroupName();
1054 BLSURFPlugin_Hypothesis::TEnfVertexList BLSURFPlugin_Hypothesis::GetAllEnforcedVertices(
1055 const BLSURFPlugin_Hypothesis* hyp) {
1056 return hyp ? hyp->_GetAllEnforcedVertices() : GetDefaultEnfVertexList();
1059 BLSURFPlugin_Hypothesis::TFaceEntryCoordsListMap BLSURFPlugin_Hypothesis::GetAllCoordsByFace(
1060 const BLSURFPlugin_Hypothesis* hyp) {
1061 return hyp ? hyp->_GetAllCoordsByFace() : GetDefaultFaceEntryCoordsListMap();
1064 BLSURFPlugin_Hypothesis::TCoordsEnfVertexMap BLSURFPlugin_Hypothesis::GetAllEnforcedVerticesByCoords(
1065 const BLSURFPlugin_Hypothesis* hyp) {
1066 return hyp ? hyp->_GetAllEnforcedVerticesByCoords() : GetDefaultCoordsEnfVertexMap();
1069 BLSURFPlugin_Hypothesis::TFaceEntryEnfVertexEntryListMap BLSURFPlugin_Hypothesis::GetAllEnfVertexEntriesByFace(
1070 const BLSURFPlugin_Hypothesis* hyp) {
1071 return hyp ? hyp->_GetAllEnfVertexEntriesByFace() : GetDefaultFaceEntryEnfVertexEntryListMap();
1074 BLSURFPlugin_Hypothesis::TEnfVertexEntryEnfVertexMap BLSURFPlugin_Hypothesis::GetAllEnforcedVerticesByEnfVertexEntry(
1075 const BLSURFPlugin_Hypothesis* hyp) {
1076 return hyp ? hyp->_GetAllEnforcedVerticesByEnfVertexEntry() : GetDefaultEnfVertexEntryEnfVertexMap();
1079 std::set<int> BLSURFPlugin_Hypothesis::GetEnfVertexNodeIDs(TEnfGroupName theGroupName) throw (std::invalid_argument)
1081 TGroupNameNodeIDMap::const_iterator it = _groupNameNodeIDMap.find(theGroupName);
1082 if (it != _groupNameNodeIDMap.end()) {
1085 std::ostringstream msg;
1086 msg << "No group " << theGroupName;
1087 throw std::invalid_argument(msg.str());
1090 void BLSURFPlugin_Hypothesis::AddEnfVertexNodeID(TEnfGroupName theGroupName,int theNodeID)
1092 _groupNameNodeIDMap[theGroupName].insert(theNodeID);
1095 void BLSURFPlugin_Hypothesis::RemoveEnfVertexNodeID(TEnfGroupName theGroupName,int theNodeID) throw (std::invalid_argument)
1097 TGroupNameNodeIDMap::iterator it = _groupNameNodeIDMap.find(theGroupName);
1098 if (it != _groupNameNodeIDMap.end()) {
1099 std::set<int>::iterator IDit = it->second.find(theNodeID);
1100 if (IDit != it->second.end())
1101 it->second.erase(IDit);
1102 std::ostringstream msg;
1103 msg << "No node IDs " << theNodeID << " for group " << theGroupName;
1104 throw std::invalid_argument(msg.str());
1106 std::ostringstream msg;
1107 msg << "No group " << theGroupName;
1108 throw std::invalid_argument(msg.str());
1112 //=============================================================================
1113 void BLSURFPlugin_Hypothesis::SetInternalEnforcedVertexAllFaces(bool toEnforceInternalVertices) {
1114 if (toEnforceInternalVertices != _enforcedInternalVerticesAllFaces) {
1115 _enforcedInternalVerticesAllFaces = toEnforceInternalVertices;
1116 if (toEnforceInternalVertices)
1117 SetPhysicalMesh(SizeMap);
1118 NotifySubMeshesHypothesisModification();
1123 //=============================================================================
1124 void BLSURFPlugin_Hypothesis::SetInternalEnforcedVertexAllFacesGroup(BLSURFPlugin_Hypothesis::TEnfGroupName theGroupName) {
1125 if (string(theGroupName) != string(_enforcedInternalVerticesAllFacesGroup)) {
1126 _enforcedInternalVerticesAllFacesGroup = theGroupName;
1127 NotifySubMeshesHypothesisModification();
1131 //=============================================================================
1132 std::ostream & BLSURFPlugin_Hypothesis::SaveTo(std::ostream & save) {
1133 save << " " << (int) _topology << " " << (int) _physicalMesh << " " << (int) _geometricMesh << " " << _phySize << " "
1134 << _angleMeshS << " " << _gradation << " " << (int) _quadAllowed << " " << (int) _decimesh;
1135 save << " " << _phyMin << " " << _phyMax << " " << _angleMeshC << " " << _hgeoMin << " " << _hgeoMax << " " << _verb;
1136 save << " " << (int) _preCADMergeEdges << " " << (int) _preCADRemoveNanoEdges << " " << (int) _preCADDiscardInput << " " << _preCADEpsNano ;
1137 save << " " << (int) _enforcedInternalVerticesAllFaces;
1139 TOptionValues::iterator op_val = _option2value.begin();
1140 if (op_val != _option2value.end()) {
1141 save << " " << "__OPTIONS_BEGIN__";
1142 for (; op_val != _option2value.end(); ++op_val) {
1143 if (!op_val->second.empty())
1144 save << " " << op_val->first << " " << op_val->second << "%#"; // "%#" is a mark of value end
1146 save << " " << "__OPTIONS_END__";
1149 op_val = _preCADoption2value.begin();
1150 if (op_val != _preCADoption2value.end()) {
1151 save << " " << "__PRECAD_OPTIONS_BEGIN__";
1152 for (; op_val != _preCADoption2value.end(); ++op_val) {
1153 if (!op_val->second.empty())
1154 save << " " << op_val->first << " " << op_val->second << "%#"; // "%#" is a mark of value end
1156 save << " " << "__PRECAD_OPTIONS_END__";
1159 TSizeMap::iterator it_sm = _sizeMap.begin();
1160 if (it_sm != _sizeMap.end()) {
1161 save << " " << "__SIZEMAP_BEGIN__";
1162 for (; it_sm != _sizeMap.end(); ++it_sm) {
1163 save << " " << it_sm->first << " " << it_sm->second << "%#"; // "%#" is a mark of value end
1165 save << " " << "__SIZEMAP_END__";
1168 TSizeMap::iterator it_at = _attractors.begin();
1169 if (it_at != _attractors.end()) {
1170 save << " " << "__ATTRACTORS_BEGIN__";
1171 for (; it_at != _attractors.end(); ++it_at) {
1172 save << " " << it_at->first << " " << it_at->second << "%#"; // "%#" is a mark of value end
1174 save << " " << "__ATTRACTORS_END__";
1177 TAttractorMap::iterator it_At = _classAttractors.begin();
1178 if (it_At != _classAttractors.end()) {
1179 std::ostringstream test;
1180 save << " " << "__NEW_ATTRACTORS_BEGIN__";
1181 test << " " << "__NEW_ATTRACTORS_BEGIN__";
1182 for (; it_At != _classAttractors.end(); ++it_At) {
1183 std::vector<double> attParams;
1184 attParams = it_At->second->GetParameters();
1185 // double step = it_At->second->GetStep();
1186 save << " " << it_At->first;
1187 save << " " << it_At->second->GetAttractorEntry();
1188 save << " " << attParams[0] << " " << attParams[1] << " " << attParams[2] << " " << attParams[3];
1189 // save << " " << step;
1190 test << " " << it_At->first;
1191 test << " " << it_At->second->GetAttractorEntry();
1192 test << " " << attParams[0] << " " << attParams[1] << " " << attParams[2] << " " << attParams[3];
1193 // test << " " << step;
1195 save << " " << "__NEW_ATTRACTORS_END__";
1196 test << " " << "__NEW_ATTRACTORS_END__";
1197 MESSAGE(" Attractor hypothesis saved as "<<test.str())
1200 TEnfVertexList::const_iterator it_enf = _enfVertexList.begin();
1201 if (it_enf != _enfVertexList.end()) {
1202 save << " " << "__ENFORCED_VERTICES_BEGIN__";
1203 for (; it_enf != _enfVertexList.end(); ++it_enf) {
1204 TEnfVertex *enfVertex = (*it_enf);
1205 save << " " << "__BEGIN_VERTEX__";
1206 if (!enfVertex->name.empty()) {
1207 save << " " << "__BEGIN_NAME__";
1208 save << " " << enfVertex->name;
1209 save << " " << "__END_NAME__";
1211 if (!enfVertex->geomEntry.empty()) {
1212 save << " " << "__BEGIN_ENTRY__";
1213 save << " " << enfVertex->geomEntry;
1214 save << " " << "__END_ENTRY__";
1216 if (!enfVertex->grpName.empty()) {
1217 save << " " << "__BEGIN_GROUP__";
1218 save << " " << enfVertex->grpName;
1219 save << " " << "__END_GROUP__";
1221 if (enfVertex->coords.size()) {
1222 save << " " << "__BEGIN_COORDS__";
1223 for (int i=0;i<enfVertex->coords.size();i++)
1224 save << " " << enfVertex->coords[i];
1225 save << " " << "__END_COORDS__";
1227 TEntryList::const_iterator faceEntriesIt = enfVertex->faceEntries.begin();
1228 bool hasFaces = false;
1229 if (faceEntriesIt != enfVertex->faceEntries.end()) {
1231 save << " " << "__BEGIN_FACELIST__";
1233 for (; faceEntriesIt != enfVertex->faceEntries.end(); ++faceEntriesIt)
1234 save << " " << (*faceEntriesIt);
1236 save << " " << "__END_FACELIST__";
1237 save << " " << "__END_VERTEX__";
1239 save << " " << "__ENFORCED_VERTICES_END__";
1245 //=============================================================================
1246 std::istream & BLSURFPlugin_Hypothesis::LoadFrom(std::istream & load) {
1253 _topology = (Topology) i;
1255 load.clear(std::ios::badbit | load.rdstate());
1259 _physicalMesh = (PhysicalMesh) i;
1261 load.clear(std::ios::badbit | load.rdstate());
1265 _geometricMesh = (GeometricMesh) i;
1267 load.clear(std::ios::badbit | load.rdstate());
1269 isOK = (load >> val);
1273 load.clear(std::ios::badbit | load.rdstate());
1275 isOK = (load >> val);
1279 load.clear(std::ios::badbit | load.rdstate());
1281 isOK = (load >> val);
1285 load.clear(std::ios::badbit | load.rdstate());
1289 _quadAllowed = (bool) i;
1291 load.clear(std::ios::badbit | load.rdstate());
1295 _decimesh = (bool) i;
1297 load.clear(std::ios::badbit | load.rdstate());
1299 isOK = (load >> val);
1303 load.clear(std::ios::badbit | load.rdstate());
1305 isOK = (load >> val);
1309 load.clear(std::ios::badbit | load.rdstate());
1311 isOK = (load >> val);
1315 load.clear(std::ios::badbit | load.rdstate());
1317 isOK = (load >> val);
1321 load.clear(std::ios::badbit | load.rdstate());
1323 isOK = (load >> val);
1327 load.clear(std::ios::badbit | load.rdstate());
1333 load.clear(std::ios::badbit | load.rdstate());
1337 _preCADMergeEdges = (bool) i;
1339 load.clear(std::ios::badbit | load.rdstate());
1343 _preCADRemoveNanoEdges = (bool) i;
1345 load.clear(std::ios::badbit | load.rdstate());
1349 _preCADDiscardInput = (bool) i;
1351 load.clear(std::ios::badbit | load.rdstate());
1353 isOK = (load >> val);
1355 _preCADEpsNano = val;
1357 load.clear(std::ios::badbit | load.rdstate());
1361 _enforcedInternalVerticesAllFaces = (bool) i;
1363 load.clear(std::ios::badbit | load.rdstate());
1365 std::string option_or_sm;
1366 bool hasOptions = false;
1367 bool hasPreCADOptions = false;
1368 bool hasSizeMap = false;
1369 bool hasAttractor = false;
1370 bool hasNewAttractor = false;
1371 bool hasEnforcedVertex = false;
1373 isOK = (load >> option_or_sm);
1375 if (option_or_sm == "__OPTIONS_BEGIN__")
1377 else if (option_or_sm == "__PRECAD_OPTIONS_BEGIN__")
1378 hasPreCADOptions = true;
1379 else if (option_or_sm == "__SIZEMAP_BEGIN__")
1381 else if (option_or_sm == "__ATTRACTORS_BEGIN__")
1382 hasAttractor = true;
1383 else if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
1384 hasNewAttractor = true;
1385 else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
1386 hasEnforcedVertex = true;
1388 std::string optName, optValue;
1389 while (isOK && hasOptions) {
1390 isOK = (load >> optName);
1392 if (optName == "__OPTIONS_END__")
1394 isOK = (load >> optValue);
1397 std::string & value = _option2value[optName];
1399 int len = value.size();
1400 // continue reading until "%#" encountered
1401 while (value[len - 1] != '#' || value[len - 2] != '%') {
1402 isOK = (load >> optValue);
1411 value[len - 2] = '\0'; //cut off "%#"
1416 isOK = (load >> option_or_sm);
1418 if (option_or_sm == "__PRECAD_OPTIONS_BEGIN__")
1419 hasPreCADOptions = true;
1420 else if (option_or_sm == "__SIZEMAP_BEGIN__")
1422 else if (option_or_sm == "__ATTRACTORS_BEGIN__")
1423 hasAttractor = true;
1424 else if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
1425 hasNewAttractor = true;
1426 else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
1427 hasEnforcedVertex = true;
1430 while (isOK && hasPreCADOptions) {
1431 isOK = (load >> optName);
1433 if (optName == "__PRECAD_OPTIONS_END__")
1435 isOK = (load >> optValue);
1438 std::string & value = _preCADoption2value[optName];
1440 int len = value.size();
1441 // continue reading until "%#" encountered
1442 while (value[len - 1] != '#' || value[len - 2] != '%') {
1443 isOK = (load >> optValue);
1452 value[len - 2] = '\0'; //cut off "%#"
1456 if (hasPreCADOptions) {
1457 isOK = (load >> option_or_sm);
1459 if (option_or_sm == "__SIZEMAP_BEGIN__")
1461 else if (option_or_sm == "__ATTRACTORS_BEGIN__")
1462 hasAttractor = true;
1463 else if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
1464 hasNewAttractor = true;
1465 else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
1466 hasEnforcedVertex = true;
1469 std::string smEntry, smValue;
1470 while (isOK && hasSizeMap) {
1471 isOK = (load >> smEntry);
1473 if (smEntry == "__SIZEMAP_END__")
1475 isOK = (load >> smValue);
1478 std::string & value2 = _sizeMap[smEntry];
1480 int len2 = value2.size();
1481 // continue reading until "%#" encountered
1482 while (value2[len2 - 1] != '#' || value2[len2 - 2] != '%') {
1483 isOK = (load >> smValue);
1487 len2 = value2.size();
1492 value2[len2 - 2] = '\0'; //cut off "%#"
1497 isOK = (load >> option_or_sm);
1499 if (option_or_sm == "__ATTRACTORS_BEGIN__")
1500 hasAttractor = true;
1501 if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
1502 hasNewAttractor = true;
1503 else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
1504 hasEnforcedVertex = true;
1507 std::string atEntry, atValue;
1508 while (isOK && hasAttractor) {
1509 isOK = (load >> atEntry);
1511 if (atEntry == "__ATTRACTORS_END__")
1513 isOK = (load >> atValue);
1516 std::string & value3 = _attractors[atEntry];
1518 int len3 = value3.size();
1519 // continue reading until "%#" encountered
1520 while (value3[len3 - 1] != '#' || value3[len3 - 2] != '%') {
1521 isOK = (load >> atValue);
1525 len3 = value3.size();
1530 value3[len3 - 2] = '\0'; //cut off "%#"
1535 isOK = (load >> option_or_sm);
1537 if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
1538 hasNewAttractor = true;
1539 else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
1540 hasEnforcedVertex = true;
1543 std::string newAtFaceEntry, atTestString;
1544 std::string newAtShapeEntry;
1545 double attParams[4];
1547 while (isOK && hasNewAttractor) {
1548 std::cout<<"Load new attractor"<<std::endl;
1549 isOK = (load >> newAtFaceEntry);
1551 if (newAtFaceEntry == "__NEW_ATTRACTORS_END__")
1553 isOK = (load >> newAtShapeEntry);
1556 isOK = (load >> attParams[0]>>attParams[1]>>attParams[2]>>attParams[3]); //>>step);
1559 MESSAGE(" LOADING ATTRACTOR HYPOTHESIS ")
1560 const TopoDS_Shape attractorShape = BLSURFPlugin_Hypothesis::entryToShape(newAtShapeEntry);
1561 const TopoDS_Face faceShape = TopoDS::Face(BLSURFPlugin_Hypothesis::entryToShape(newAtFaceEntry));
1562 BLSURFPlugin_Attractor* attractor = new BLSURFPlugin_Attractor(faceShape, attractorShape, newAtShapeEntry);//, step);
1563 attractor->SetParameters(attParams[0], attParams[1], attParams[2], attParams[3]);
1564 attractor->BuildMap();
1565 _classAttractors[newAtFaceEntry]=attractor;
1570 if (hasNewAttractor) {
1571 isOK = (load >> option_or_sm);
1573 if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
1574 hasEnforcedVertex = true;
1579 // Here is a example of the saved stream:
1580 // __ENFORCED_VERTICES_BEGIN__
1581 // __BEGIN_VERTEX__ => no name, no entry
1582 // __BEGIN_GROUP__ mon groupe __END_GROUP__
1583 // __BEGIN_COORDS__ 10 10 10 __END_COORDS__
1584 // __BEGIN_FACELIST__ 0:1:1:1:1 __END_FACELIST__
1586 // __BEGIN_VERTEX__ => no coords
1587 // __BEGIN_NAME__ mes points __END_NAME__
1588 // __BEGIN_ENTRY__ 0:1:1:4 __END_ENTRY__
1589 // __BEGIN_GROUP__ mon groupe __END_GROUP__
1590 // __BEGIN_FACELIST__ 0:1:1:1:3 __END_FACELIST__
1592 // __ENFORCED_VERTICES_END__
1595 std::string enfSeparator;
1596 std::string enfName;
1597 std::string enfGeomEntry;
1598 std::string enfGroup;
1599 TEntryList enfFaceEntryList;
1600 double enfCoords[3];
1601 bool hasCoords = false;
1603 _faceEntryEnfVertexListMap.clear();
1604 _enfVertexList.clear();
1605 _faceEntryCoordsListMap.clear();
1606 _coordsEnfVertexMap.clear();
1607 _faceEntryEnfVertexEntryListMap.clear();
1608 _enfVertexEntryEnfVertexMap.clear();
1611 while (isOK && hasEnforcedVertex) {
1612 isOK = (load >> enfSeparator); // __BEGIN_VERTEX__
1613 TEnfVertex *enfVertex = new TEnfVertex();
1614 // MESSAGE("enfSeparator: " <<enfSeparator);
1615 if (enfSeparator == "__ENFORCED_VERTICES_END__")
1616 break; // __ENFORCED_VERTICES_END__
1617 if (enfSeparator != "__BEGIN_VERTEX__")
1618 throw std::exception();
1621 isOK = (load >> enfSeparator);
1622 MESSAGE("enfSeparator: " <<enfSeparator);
1623 if (enfSeparator == "__END_VERTEX__") {
1625 enfVertex->name = enfName;
1626 enfVertex->geomEntry = enfGeomEntry;
1627 enfVertex->grpName = enfGroup;
1628 enfVertex->coords.clear();
1630 enfVertex->coords.assign(enfCoords,enfCoords+3);
1631 enfVertex->faceEntries = enfFaceEntryList;
1633 _enfVertexList.insert(enfVertex);
1635 if (enfVertex->coords.size()) {
1636 _coordsEnfVertexMap[enfVertex->coords] = enfVertex;
1637 for (TEntryList::const_iterator it = enfVertex->faceEntries.begin() ; it != enfVertex->faceEntries.end(); ++it) {
1638 _faceEntryCoordsListMap[(*it)].insert(enfVertex->coords);
1639 _faceEntryEnfVertexListMap[(*it)].insert(enfVertex);
1642 if (!enfVertex->geomEntry.empty()) {
1643 _enfVertexEntryEnfVertexMap[enfVertex->geomEntry] = enfVertex;
1644 for (TEntryList::const_iterator it = enfVertex->faceEntries.begin() ; it != enfVertex->faceEntries.end(); ++it) {
1645 _faceEntryEnfVertexEntryListMap[(*it)].insert(enfVertex->geomEntry);
1646 _faceEntryEnfVertexListMap[(*it)].insert(enfVertex);
1651 enfGeomEntry.clear();
1653 enfFaceEntryList.clear();
1655 break; // __END_VERTEX__
1658 if (enfSeparator == "__BEGIN_NAME__") { // __BEGIN_NAME__
1659 while (isOK && (enfSeparator != "__END_NAME__")) {
1660 isOK = (load >> enfSeparator);
1661 if (enfSeparator != "__END_NAME__") {
1662 if (!enfName.empty())
1664 enfName += enfSeparator;
1667 MESSAGE("enfName: " <<enfName);
1670 if (enfSeparator == "__BEGIN_ENTRY__") { // __BEGIN_ENTRY__
1671 isOK = (load >> enfGeomEntry);
1672 isOK = (load >> enfSeparator); // __END_ENTRY__
1673 if (enfSeparator != "__END_ENTRY__")
1674 throw std::exception();
1675 MESSAGE("enfGeomEntry: " <<enfGeomEntry);
1678 if (enfSeparator == "__BEGIN_GROUP__") { // __BEGIN_GROUP__
1679 while (isOK && (enfSeparator != "__END_GROUP__")) {
1680 isOK = (load >> enfSeparator);
1681 if (enfSeparator != "__END_GROUP__") {
1682 if (!enfGroup.empty())
1684 enfGroup += enfSeparator;
1687 MESSAGE("enfGroup: " <<enfGroup);
1690 if (enfSeparator == "__BEGIN_COORDS__") { // __BEGIN_COORDS__
1692 isOK = (load >> enfCoords[0] >> enfCoords[1] >> enfCoords[2]);
1693 isOK = (load >> enfSeparator); // __END_COORDS__
1694 if (enfSeparator != "__END_COORDS__")
1695 throw std::exception();
1696 MESSAGE("enfCoords: " << enfCoords[0] <<","<< enfCoords[1] <<","<< enfCoords[2]);
1699 if (enfSeparator == "__BEGIN_FACELIST__") { // __BEGIN_FACELIST__
1700 while (isOK && (enfSeparator != "__END_FACELIST__")) {
1701 isOK = (load >> enfSeparator);
1702 if (enfSeparator != "__END_FACELIST__") {
1703 enfFaceEntryList.insert(enfSeparator);
1704 MESSAGE(enfSeparator << " was inserted into enfFaceEntryList");
1714 //=============================================================================
1715 std::ostream & operator <<(std::ostream & save, BLSURFPlugin_Hypothesis & hyp) {
1716 return hyp.SaveTo(save);
1719 //=============================================================================
1720 std::istream & operator >>(std::istream & load, BLSURFPlugin_Hypothesis & hyp) {
1721 return hyp.LoadFrom(load);
1724 //================================================================================
1726 * \brief Does nothing
1728 //================================================================================
1730 bool BLSURFPlugin_Hypothesis::SetParametersByMesh(const SMESH_Mesh* theMesh, const TopoDS_Shape& theShape) {
1734 //=============================================================================
1736 * \brief Initialize my parameter values by default parameters.
1737 * \retval bool - true if parameter values have been successfully defined
1739 //=============================================================================
1741 bool BLSURFPlugin_Hypothesis::SetParametersByDefaults(const TDefaults& dflts, const SMESH_Mesh* theMesh) {
1742 return bool(_phySize = dflts._elemLength);
1745 //=============================================================================
1746 BLSURFPlugin_Hypothesis::Topology BLSURFPlugin_Hypothesis::GetDefaultTopology() {
1750 //=============================================================================
1751 BLSURFPlugin_Hypothesis::PhysicalMesh BLSURFPlugin_Hypothesis::GetDefaultPhysicalMesh() {
1752 return PhysicalUserDefined;
1755 //=============================================================================
1756 double BLSURFPlugin_Hypothesis::GetDefaultPhySize() {
1760 //======================================================================
1761 double BLSURFPlugin_Hypothesis::GetDefaultMaxSize() {
1762 return undefinedDouble(); // 1e+4;
1765 //======================================================================
1766 double BLSURFPlugin_Hypothesis::GetDefaultMinSize() {
1767 return undefinedDouble(); //1e-4;
1770 //======================================================================
1771 BLSURFPlugin_Hypothesis::GeometricMesh BLSURFPlugin_Hypothesis::GetDefaultGeometricMesh() {
1775 //=============================================================================
1776 double BLSURFPlugin_Hypothesis::GetDefaultAngleMeshS() {
1780 //=============================================================================
1781 double BLSURFPlugin_Hypothesis::GetDefaultGradation() {
1785 //=============================================================================
1786 bool BLSURFPlugin_Hypothesis::GetDefaultQuadAllowed() {
1790 //=============================================================================
1791 bool BLSURFPlugin_Hypothesis::GetDefaultDecimesh() {
1795 //======================================================================
1796 double BLSURFPlugin_Hypothesis::GetDefaultPreCADEpsNano() {
1797 return undefinedDouble(); //1e-4;
1800 //======================================================================
1801 std::string BLSURFPlugin_Hypothesis::GetDefaultGMFFile() {
1805 //=============================================================================
1806 bool BLSURFPlugin_Hypothesis::GetDefaultInternalEnforcedVertex() {