1 // Copyright (C) 2007-2010 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 <utilities.h>
33 //=============================================================================
34 BLSURFPlugin_Hypothesis::BLSURFPlugin_Hypothesis(int hypId, int studyId, SMESH_Gen * gen) :
35 SMESH_Hypothesis(hypId, studyId, gen), _topology(GetDefaultTopology()),
36 _physicalMesh(GetDefaultPhysicalMesh()),
37 _phySize(GetDefaultPhySize()),
38 _phyMax(GetDefaultMaxSize()),
39 _phyMin(GetDefaultMinSize()),
40 _hgeoMax(GetDefaultMaxSize()),
41 _hgeoMin(GetDefaultMinSize()),
42 _geometricMesh(GetDefaultGeometricMesh()),
43 _angleMeshS(GetDefaultAngleMeshS()),
44 _angleMeshC(GetDefaultAngleMeshC()),
45 _gradation(GetDefaultGradation()),
46 _quadAllowed(GetDefaultQuadAllowed()),
47 _decimesh(GetDefaultDecimesh()),
48 _verb(GetDefaultVerbosity()),
49 _sizeMap(GetDefaultSizeMap()),
50 _attractors(GetDefaultSizeMap()),
51 _faceEntryEnfVertexListMap(GetDefaultFaceEntryEnfVertexListMap()),
52 _enfVertexList(GetDefaultEnfVertexList()),
53 _faceEntryCoordsListMap(GetDefaultFaceEntryCoordsListMap()),
54 _coordsEnfVertexMap(GetDefaultCoordsEnfVertexMap()),
55 _faceEntryEnfVertexEntryListMap(GetDefaultFaceEntryEnfVertexEntryListMap()),
56 _enfVertexEntryEnfVertexMap(GetDefaultEnfVertexEntryEnfVertexMap()),
57 _groupNameNodeIDMap(GetDefaultGroupNameNodeIDMap())
60 _groupNameEnfVertexListMap(GetDefaultGroupNameEnfVertexListMap()),
61 _enfVertexGroupNameMap(GetDefaultEnfVertexGroupNameMap())
64 _name = "BLSURF_Parameters";
67 // to disable writing boundaries
68 //_phyMin = _phyMax = _hgeoMin = _hgeoMax = undefinedDouble();
71 const char* intOptionNames[] = { "addsurf_ivertex", "background", "CheckAdjacentEdges", "CheckCloseEdges",
72 "CheckWellDefined", "coiter", "communication", "decim", "export_flag", "file_h", "frontal", "gridnu", "gridnv",
73 "hinterpol_flag", "hmean_flag", "intermedfile", "memory", "normals", "optim", "pardom_flag", "pinch", "refs",
74 "rigid", "surforient", "tconf", "topo_collapse", "" // mark of end
76 const char* doubleOptionNames[] = { "addsurf_angle", "addsurf_R", "addsurf_H", "addsurf_FG", "addsurf_r",
77 "addsurf_PA", "angle_compcurv", "angle_ridge", "CoefRectangle", "eps_collapse", "eps_ends", "eps_pardom", "LSS",
78 "topo_eps1", "topo_eps2", "" // mark of end
80 const char* charOptionNames[] = { "export_format", "export_option", "import_option", "prefix", "" // mark of end
84 while (intOptionNames[i][0])
85 _option2value[intOptionNames[i++]].clear();
88 while (doubleOptionNames[i][0]) {
89 _doubleOptions.insert(doubleOptionNames[i]);
90 _option2value[doubleOptionNames[i++]].clear();
93 while (charOptionNames[i][0]) {
94 _charOptions.insert(charOptionNames[i]);
95 _option2value[charOptionNames[i++]].clear();
100 _faceEntryEnfVertexListMap.clear();
101 _enfVertexList.clear();
102 _faceEntryCoordsListMap.clear();
103 _coordsEnfVertexMap.clear();
104 _faceEntryEnfVertexEntryListMap.clear();
105 _enfVertexEntryEnfVertexMap.clear();
106 _groupNameNodeIDMap.clear();
109 _groupNameEnfVertexListMap.clear();
110 _enfVertexGroupNameMap.clear();
114 //=============================================================================
115 void BLSURFPlugin_Hypothesis::SetTopology(Topology theTopology) {
116 if (theTopology != _topology) {
117 _topology = theTopology;
118 NotifySubMeshesHypothesisModification();
122 //=============================================================================
123 void BLSURFPlugin_Hypothesis::SetPhysicalMesh(PhysicalMesh thePhysicalMesh) {
124 if (thePhysicalMesh != _physicalMesh) {
125 _physicalMesh = thePhysicalMesh;
126 switch (_physicalMesh) {
129 _phySize = GetDefaultPhySize();
130 _gradation = GetDefaultGradation();
133 NotifySubMeshesHypothesisModification();
137 //=============================================================================
138 void BLSURFPlugin_Hypothesis::SetPhySize(double theVal) {
139 if (theVal != _phySize) {
141 NotifySubMeshesHypothesisModification();
145 //=============================================================================
146 void BLSURFPlugin_Hypothesis::SetPhyMin(double theMinSize) {
147 if (theMinSize != _phyMin) {
148 _phyMin = theMinSize;
149 NotifySubMeshesHypothesisModification();
153 //=============================================================================
154 void BLSURFPlugin_Hypothesis::SetPhyMax(double theMaxSize) {
155 if (theMaxSize != _phyMax) {
156 _phyMax = theMaxSize;
157 NotifySubMeshesHypothesisModification();
161 //=============================================================================
162 void BLSURFPlugin_Hypothesis::SetGeoMin(double theMinSize) {
163 if (theMinSize != _hgeoMin) {
164 _hgeoMin = theMinSize;
165 NotifySubMeshesHypothesisModification();
169 //=============================================================================
170 void BLSURFPlugin_Hypothesis::SetGeoMax(double theMaxSize) {
171 if (theMaxSize != _hgeoMax) {
172 _hgeoMax = theMaxSize;
173 NotifySubMeshesHypothesisModification();
177 //=============================================================================
178 void BLSURFPlugin_Hypothesis::SetGeometricMesh(GeometricMesh theGeometricMesh) {
179 if (theGeometricMesh != _geometricMesh) {
180 _geometricMesh = theGeometricMesh;
181 switch (_geometricMesh) {
184 _angleMeshS = GetDefaultAngleMeshS();
185 _gradation = GetDefaultGradation();
188 NotifySubMeshesHypothesisModification();
192 //=============================================================================
193 void BLSURFPlugin_Hypothesis::SetAngleMeshS(double theVal) {
194 if (theVal != _angleMeshS) {
195 _angleMeshS = theVal;
196 NotifySubMeshesHypothesisModification();
200 //=============================================================================
201 void BLSURFPlugin_Hypothesis::SetAngleMeshC(double theVal) {
202 if (theVal != _angleMeshC) {
203 _angleMeshC = theVal;
204 NotifySubMeshesHypothesisModification();
208 //=============================================================================
209 void BLSURFPlugin_Hypothesis::SetGradation(double theVal) {
210 if (theVal != _gradation) {
212 NotifySubMeshesHypothesisModification();
216 //=============================================================================
217 void BLSURFPlugin_Hypothesis::SetQuadAllowed(bool theVal) {
218 if (theVal != _quadAllowed) {
219 _quadAllowed = theVal;
220 NotifySubMeshesHypothesisModification();
224 //=============================================================================
225 void BLSURFPlugin_Hypothesis::SetDecimesh(bool theVal) {
226 if (theVal != _decimesh) {
228 NotifySubMeshesHypothesisModification();
232 //=============================================================================
233 void BLSURFPlugin_Hypothesis::SetVerbosity(int theVal) {
234 if (theVal != _verb) {
236 NotifySubMeshesHypothesisModification();
239 //=============================================================================
240 void BLSURFPlugin_Hypothesis::SetOptionValue(const std::string& optionName, const std::string& optionValue)
241 throw (std::invalid_argument) {
242 TOptionValues::iterator op_val = _option2value.find(optionName);
243 if (op_val == _option2value.end()) {
244 std::string msg = "Unknown BLSURF option: '" + optionName + "'";
245 throw std::invalid_argument(msg);
247 if (op_val->second != optionValue) {
248 const char* ptr = optionValue.c_str();
249 // strip white spaces
250 while (ptr[0] == ' ')
253 while (i != 0 && ptr[i - 1] == ' ')
257 std::string typeName;
260 } else if (_charOptions.find(optionName) != _charOptions.end()) {
261 // do not check strings
262 } else if (_doubleOptions.find(optionName) != _doubleOptions.end()) {
263 // check if value is double
265 strtod(ptr, &endPtr);
266 typeOk = (ptr != endPtr);
269 // check if value is int
271 strtol(ptr, &endPtr, 10);
272 typeOk = (ptr != endPtr);
273 typeName = "integer";
276 std::string msg = "Advanced option '" + optionName + "' = '" + optionValue + "' but must be " + typeName;
277 throw std::invalid_argument(msg);
279 op_val->second = optionValue;
280 NotifySubMeshesHypothesisModification();
284 //=============================================================================
285 std::string BLSURFPlugin_Hypothesis::GetOptionValue(const std::string& optionName) throw (std::invalid_argument) {
286 TOptionValues::iterator op_val = _option2value.find(optionName);
287 if (op_val == _option2value.end()) {
288 std::string msg = "Unknown BLSURF option: <";
289 msg += optionName + ">";
290 throw std::invalid_argument(msg);
292 return op_val->second;
295 //=============================================================================
296 void BLSURFPlugin_Hypothesis::ClearOption(const std::string& optionName) {
297 TOptionValues::iterator op_val = _option2value.find(optionName);
298 if (op_val != _option2value.end())
299 op_val->second.clear();
302 //=======================================================================
303 //function : SetSizeMapEntry
304 //=======================================================================
305 void BLSURFPlugin_Hypothesis::SetSizeMapEntry(const std::string& entry, const std::string& sizeMap) {
306 if (_sizeMap[entry].compare(sizeMap) != 0) {
307 _sizeMap[entry] = sizeMap;
308 NotifySubMeshesHypothesisModification();
312 //=======================================================================
313 //function : GetSizeMapEntry
314 //=======================================================================
315 std::string BLSURFPlugin_Hypothesis::GetSizeMapEntry(const std::string& entry) {
316 TSizeMap::iterator it = _sizeMap.find(entry);
317 if (it != _sizeMap.end())
320 return "No_Such_Entry";
324 * \brief Return the size maps
326 BLSURFPlugin_Hypothesis::TSizeMap BLSURFPlugin_Hypothesis::GetSizeMapEntries(const BLSURFPlugin_Hypothesis* hyp) {
327 return hyp ? hyp->_GetSizeMapEntries() : GetDefaultSizeMap();
330 //=======================================================================
331 //function : SetAttractorEntry
332 //=======================================================================
333 void BLSURFPlugin_Hypothesis::SetAttractorEntry(const std::string& entry, const std::string& attractor) {
334 if (_attractors[entry].compare(attractor) != 0) {
335 _attractors[entry] = attractor;
336 NotifySubMeshesHypothesisModification();
340 //=======================================================================
341 //function : GetAttractorEntry
342 //=======================================================================
343 std::string BLSURFPlugin_Hypothesis::GetAttractorEntry(const std::string& entry) {
344 TSizeMap::iterator it = _attractors.find(entry);
345 if (it != _attractors.end())
348 return "No_Such_Entry";
352 * \brief Return the attractors
354 BLSURFPlugin_Hypothesis::TSizeMap BLSURFPlugin_Hypothesis::GetAttractorEntries(const BLSURFPlugin_Hypothesis* hyp) {
355 return hyp ? hyp->_GetAttractorEntries() : GetDefaultSizeMap();
358 //=======================================================================
359 //function : ClearEntry
360 //=======================================================================
361 void BLSURFPlugin_Hypothesis::ClearEntry(const std::string& entry) {
362 TSizeMap::iterator it = _sizeMap.find(entry);
363 if (it != _sizeMap.end()) {
365 NotifySubMeshesHypothesisModification();
367 TSizeMap::iterator itAt = _attractors.find(entry);
368 if (itAt != _attractors.end()) {
369 _attractors.erase(itAt);
370 NotifySubMeshesHypothesisModification();
372 std::cout << "No_Such_Entry" << std::endl;
376 //=======================================================================
377 //function : ClearSizeMaps
378 //=======================================================================
379 void BLSURFPlugin_Hypothesis::ClearSizeMaps() {
384 //=======================================================================
385 //function : SetEnforcedVertex
386 //=======================================================================
387 bool BLSURFPlugin_Hypothesis::SetEnforcedVertex(TEntry theFaceEntry, TEnfName theVertexName, TEntry theVertexEntry,
388 TEnfGroupName theGroupName, double x, double y, double z) {
390 MESSAGE("BLSURFPlugin_Hypothesis::SetEnforcedVertex("<< theFaceEntry << ", "
391 << x << ", " << y << ", " << z << ", " << theVertexName << ", " << theVertexEntry << ", " << theGroupName << ")");
393 // TEnfVertexList::iterator it;
394 bool toNotify = false;
395 bool toCreate = true;
397 TEnfVertex *oldEnVertex;
398 TEnfVertex *newEnfVertex = new TEnfVertex();
399 newEnfVertex->name = theVertexName;
400 newEnfVertex->geomEntry = theVertexEntry;
401 newEnfVertex->coords.clear();
402 if (theVertexEntry == "") {
403 newEnfVertex->coords.push_back(x);
404 newEnfVertex->coords.push_back(y);
405 newEnfVertex->coords.push_back(z);
407 newEnfVertex->grpName = theGroupName;
408 newEnfVertex->faceEntries.clear();
409 newEnfVertex->faceEntries.insert(theFaceEntry);
412 // update _enfVertexList
413 TEnfVertexList::iterator it = _enfVertexList.find(newEnfVertex);
414 if (it != _enfVertexList.end()) {
417 MESSAGE("Enforced Vertex was found => Update");
418 if (oldEnVertex->name != theVertexName) {
419 MESSAGE("Update name from \"" << oldEnVertex->name << "\" to \"" << theVertexName << "\"");
420 oldEnVertex->name = theVertexName;
423 if (oldEnVertex->grpName != theGroupName) {
424 MESSAGE("Update group name from \"" << oldEnVertex->grpName << "\" to \"" << theGroupName << "\"");
425 oldEnVertex->grpName = theGroupName;
428 TEntryList::iterator it_faceEntries = oldEnVertex->faceEntries.find(theFaceEntry);
429 if (it_faceEntries == oldEnVertex->faceEntries.end()) {
430 MESSAGE("Update face list by adding \"" << theFaceEntry << "\"");
431 oldEnVertex->faceEntries.insert(theFaceEntry);
432 _faceEntryEnfVertexListMap[theFaceEntry].insert(oldEnVertex);
436 // update map coords / enf vertex if needed
437 if (oldEnVertex->coords.size()) {
438 _coordsEnfVertexMap[oldEnVertex->coords] = oldEnVertex;
439 _faceEntryCoordsListMap[theFaceEntry].insert(oldEnVertex->coords);
442 // update map geom entry / enf vertex if needed
443 if (oldEnVertex->geomEntry != "") {
444 _enfVertexEntryEnfVertexMap[oldEnVertex->geomEntry] = oldEnVertex;
445 _faceEntryEnfVertexEntryListMap[theFaceEntry].insert(oldEnVertex->geomEntry);
450 // //////// CREATE ////////////
453 MESSAGE("Creating new enforced vertex");
454 _faceEntryEnfVertexListMap[theFaceEntry].insert(newEnfVertex);
455 _enfVertexList.insert(newEnfVertex);
456 if (theVertexEntry == "") {
457 _faceEntryCoordsListMap[theFaceEntry].insert(newEnfVertex->coords);
458 _coordsEnfVertexMap[newEnfVertex->coords] = newEnfVertex;
461 _faceEntryEnfVertexEntryListMap[theFaceEntry].insert(newEnfVertex->geomEntry);
462 _enfVertexEntryEnfVertexMap[newEnfVertex->geomEntry] = newEnfVertex;
467 NotifySubMeshesHypothesisModification();
469 MESSAGE("BLSURFPlugin_Hypothesis::SetEnforcedVertex END");
474 //=======================================================================
475 //function : GetEnforcedVertices
476 //=======================================================================
478 BLSURFPlugin_Hypothesis::TEnfVertexList BLSURFPlugin_Hypothesis::GetEnfVertexList(const TEntry& theFaceEntry)
479 throw (std::invalid_argument) {
481 if (_faceEntryEnfVertexListMap.count(theFaceEntry) > 0)
482 return _faceEntryEnfVertexListMap[theFaceEntry];
484 return GetDefaultEnfVertexList();
486 std::ostringstream msg;
487 msg << "No enforced vertex for face entry " << theFaceEntry;
488 throw std::invalid_argument(msg.str());
491 //=======================================================================
492 //function : GetEnfVertexCoordsList
493 //=======================================================================
495 BLSURFPlugin_Hypothesis::TEnfVertexCoordsList BLSURFPlugin_Hypothesis::GetEnfVertexCoordsList(
496 const TEntry& theFaceEntry) throw (std::invalid_argument) {
498 if (_faceEntryCoordsListMap.count(theFaceEntry) > 0)
499 return _faceEntryCoordsListMap[theFaceEntry];
501 std::ostringstream msg;
502 msg << "No enforced vertex coords for face entry " << theFaceEntry;
503 throw std::invalid_argument(msg.str());
506 //=======================================================================
507 //function : GetEnfVertexEntryList
508 //=======================================================================
510 BLSURFPlugin_Hypothesis::TEntryList BLSURFPlugin_Hypothesis::GetEnfVertexEntryList(const TEntry& theFaceEntry)
511 throw (std::invalid_argument) {
513 if (_faceEntryEnfVertexEntryListMap.count(theFaceEntry) > 0)
514 return _faceEntryEnfVertexEntryListMap[theFaceEntry];
516 std::ostringstream msg;
517 msg << "No enforced vertex entry for face entry " << theFaceEntry;
518 throw std::invalid_argument(msg.str());
521 //=======================================================================
522 //function : GetEnfVertex(TEnfVertexCoords coords)
523 //=======================================================================
525 BLSURFPlugin_Hypothesis::TEnfVertex* BLSURFPlugin_Hypothesis::GetEnfVertex(TEnfVertexCoords coords)
526 throw (std::invalid_argument) {
528 if (_coordsEnfVertexMap.count(coords) > 0)
529 return _coordsEnfVertexMap[coords];
531 std::ostringstream msg;
532 msg << "No enforced vertex with coords (" << coords[0] << ", " << coords[1] << ", " << coords[2] << ")";
533 throw std::invalid_argument(msg.str());
536 //=======================================================================
537 //function : GetEnfVertex(const TEntry& theEnfVertexEntry)
538 //=======================================================================
540 BLSURFPlugin_Hypothesis::TEnfVertex* BLSURFPlugin_Hypothesis::GetEnfVertex(const TEntry& theEnfVertexEntry)
541 throw (std::invalid_argument) {
543 if (_enfVertexEntryEnfVertexMap.count(theEnfVertexEntry) > 0)
544 return _enfVertexEntryEnfVertexMap[theEnfVertexEntry];
546 std::ostringstream msg;
547 msg << "No enforced vertex with entry " << theEnfVertexEntry;
548 throw std::invalid_argument(msg.str());
551 //=======================================================================
552 //function : ClearEnforcedVertex
553 //=======================================================================
555 bool BLSURFPlugin_Hypothesis::ClearEnforcedVertex(const TEntry& theFaceEntry, double x, double y, double z,
556 const TEntry& theVertexEntry) throw (std::invalid_argument) {
558 bool toNotify = false;
559 std::ostringstream msg;
560 TEnfVertex *oldEnfVertex;
561 TEnfVertexCoords coords;
567 // check that enf vertex with given enf vertex entry exists
568 TEnfVertexEntryEnfVertexMap::iterator it_enfVertexEntry = _enfVertexEntryEnfVertexMap.find(theVertexEntry);
569 if (it_enfVertexEntry != _enfVertexEntryEnfVertexMap.end()) {
571 MESSAGE("Found enforced vertex with geom entry " << theVertexEntry);
572 oldEnfVertex = it_enfVertexEntry->second;
574 _enfVertexEntryEnfVertexMap.erase(it_enfVertexEntry);
576 TEntryList& enfVertexEntryList = _faceEntryEnfVertexEntryListMap[theFaceEntry];
577 enfVertexEntryList.erase(theVertexEntry);
578 if (enfVertexEntryList.size() == 0)
579 _faceEntryEnfVertexEntryListMap.erase(theFaceEntry);
580 // TFaceEntryEnfVertexEntryListMap::iterator it_entry_entry = _faceEntryEnfVertexEntryListMap.find(theFaceEntry);
581 // TEntryList::iterator it_entryList = it_entry_entry->second.find(theVertexEntry);
582 // it_entry_entry->second.erase(it_entryList);
583 // if (it_entry_entry->second.size() == 0)
584 // _faceEntryEnfVertexEntryListMap.erase(it_entry_entry);
587 MESSAGE("Enforced vertex with geom entry " << theVertexEntry << " not found");
588 msg << "No enforced vertex with geom entry " << theVertexEntry;
589 // check that enf vertex with given coords exists
590 TCoordsEnfVertexMap::iterator it_coords_enf = _coordsEnfVertexMap.find(coords);
591 if (it_coords_enf != _coordsEnfVertexMap.end()) {
593 MESSAGE("Found enforced vertex with coords " << x << ", " << y << ", " << z);
594 oldEnfVertex = it_coords_enf->second;
596 _coordsEnfVertexMap.erase(it_coords_enf);
598 TEnfVertexCoordsList& enfVertexCoordsList = _faceEntryCoordsListMap[theFaceEntry];
599 enfVertexCoordsList.erase(coords);
600 if (enfVertexCoordsList.size() == 0)
601 _faceEntryCoordsListMap.erase(theFaceEntry);
602 // TFaceEntryCoordsListMap::iterator it_entry_coords = _faceEntryCoordsListMap.find(theFaceEntry);
603 // TEnfVertexCoordsList::iterator it_coordsList = it_entry_coords->second.find(coords);
604 // it_entry_coords->second.erase(it_coordsList);
605 // if (it_entry_coords->second.size() == 0)
606 // _faceEntryCoordsListMap.erase(it_entry_coords);
609 MESSAGE("Enforced vertex with coords " << x << ", " << y << ", " << z << " not found");
611 msg << "No enforced vertex at " << x << ", " << y << ", " << z;
612 throw std::invalid_argument(msg.str());
616 MESSAGE("Remove enf vertex from _enfVertexList");
618 // update _enfVertexList
619 TEnfVertexList::iterator it = _enfVertexList.find(oldEnfVertex);
620 if (it != _enfVertexList.end()) {
621 (*it)->faceEntries.erase(theFaceEntry);
622 if ((*it)->faceEntries.size() == 0){
623 _enfVertexList.erase(it);
629 // update _faceEntryEnfVertexListMap
630 TEnfVertexList& currentEnfVertexList = _faceEntryEnfVertexListMap[theFaceEntry];
631 currentEnfVertexList.erase(oldEnfVertex);
633 if (currentEnfVertexList.size() == 0) {
634 MESSAGE("Remove _faceEntryEnfVertexListMap[" << theFaceEntry <<"]");
635 _faceEntryEnfVertexListMap.erase(theFaceEntry);
640 NotifySubMeshesHypothesisModification();
645 //=======================================================================
646 //function : ClearEnforcedVertices
647 //=======================================================================
649 bool BLSURFPlugin_Hypothesis::ClearEnforcedVertices(const TEntry& theFaceEntry) throw (std::invalid_argument) {
651 bool toNotify = false;
652 TEnfVertex *oldEnfVertex;
654 TFaceEntryCoordsListMap::iterator it_entry_coords = _faceEntryCoordsListMap.find(theFaceEntry);
655 if (it_entry_coords != _faceEntryCoordsListMap.end()) {
657 TEnfVertexCoordsList coordsList = it_entry_coords->second;
658 TEnfVertexCoordsList::iterator it_coordsList = coordsList.begin();
659 for (; it_coordsList != coordsList.end(); ++it_coordsList) {
660 TEnfVertexCoords coords = (*it_coordsList);
661 oldEnfVertex = _coordsEnfVertexMap[coords];
662 _coordsEnfVertexMap.erase(coords);
663 // update _enfVertexList
664 TEnfVertexList::iterator it = _enfVertexList.find(oldEnfVertex);
665 if (it != _enfVertexList.end()) {
666 (*it)->faceEntries.erase(theFaceEntry);
667 if ((*it)->faceEntries.size() == 0){
668 _enfVertexList.erase(it);
674 _faceEntryCoordsListMap.erase(it_entry_coords);
675 _faceEntryEnfVertexListMap.erase(theFaceEntry);
678 TFaceEntryEnfVertexEntryListMap::iterator it_entry_entry = _faceEntryEnfVertexEntryListMap.find(theFaceEntry);
679 if (it_entry_entry != _faceEntryEnfVertexEntryListMap.end()) {
681 TEntryList enfVertexEntryList = it_entry_entry->second;
682 TEntryList::iterator it_enfVertexEntryList = enfVertexEntryList.begin();
683 for (; it_enfVertexEntryList != enfVertexEntryList.end(); ++it_enfVertexEntryList) {
684 TEntry enfVertexEntry = (*it_enfVertexEntryList);
685 oldEnfVertex = _enfVertexEntryEnfVertexMap[enfVertexEntry];
686 _enfVertexEntryEnfVertexMap.erase(enfVertexEntry);
687 // update _enfVertexList
688 TEnfVertexList::iterator it = _enfVertexList.find(oldEnfVertex);
689 if (it != _enfVertexList.end()) {
690 (*it)->faceEntries.erase(theFaceEntry);
691 if ((*it)->faceEntries.size() == 0){
692 _enfVertexList.erase(it);
698 _faceEntryEnfVertexEntryListMap.erase(it_entry_entry);
699 _faceEntryEnfVertexListMap.erase(theFaceEntry);
703 NotifySubMeshesHypothesisModification();
706 // std::ostringstream msg;
707 // msg << "No enforced vertex for " << theFaceEntry;
708 // throw std::invalid_argument(msg.str());
711 //=======================================================================
712 //function : ClearAllEnforcedVertices
713 //=======================================================================
714 void BLSURFPlugin_Hypothesis::ClearAllEnforcedVertices() {
715 _faceEntryEnfVertexListMap.clear();
716 _enfVertexList.clear();
717 _faceEntryCoordsListMap.clear();
718 _coordsEnfVertexMap.clear();
719 _faceEntryEnfVertexEntryListMap.clear();
720 _enfVertexEntryEnfVertexMap.clear();
721 NotifySubMeshesHypothesisModification();
724 //================================================================================
726 * \brief Return the enforced vertices
728 //================================================================================
731 BLSURFPlugin_Hypothesis::TFaceEntryEnfVertexListMap BLSURFPlugin_Hypothesis::GetAllEnforcedVerticesByFace(
732 const BLSURFPlugin_Hypothesis* hyp) {
733 return hyp ? hyp->_GetAllEnforcedVerticesByFace() : GetDefaultFaceEntryEnfVertexListMap();
736 BLSURFPlugin_Hypothesis::TEnfVertexList BLSURFPlugin_Hypothesis::GetAllEnforcedVertices(
737 const BLSURFPlugin_Hypothesis* hyp) {
738 return hyp ? hyp->_GetAllEnforcedVertices() : GetDefaultEnfVertexList();
741 BLSURFPlugin_Hypothesis::TFaceEntryCoordsListMap BLSURFPlugin_Hypothesis::GetAllCoordsByFace(
742 const BLSURFPlugin_Hypothesis* hyp) {
743 return hyp ? hyp->_GetAllCoordsByFace() : GetDefaultFaceEntryCoordsListMap();
746 BLSURFPlugin_Hypothesis::TCoordsEnfVertexMap BLSURFPlugin_Hypothesis::GetAllEnforcedVerticesByCoords(
747 const BLSURFPlugin_Hypothesis* hyp) {
748 return hyp ? hyp->_GetAllEnforcedVerticesByCoords() : GetDefaultCoordsEnfVertexMap();
751 BLSURFPlugin_Hypothesis::TFaceEntryEnfVertexEntryListMap BLSURFPlugin_Hypothesis::GetAllEnfVertexEntriesByFace(
752 const BLSURFPlugin_Hypothesis* hyp) {
753 return hyp ? hyp->_GetAllEnfVertexEntriesByFace() : GetDefaultFaceEntryEnfVertexEntryListMap();
756 BLSURFPlugin_Hypothesis::TEnfVertexEntryEnfVertexMap BLSURFPlugin_Hypothesis::GetAllEnforcedVerticesByEnfVertexEntry(
757 const BLSURFPlugin_Hypothesis* hyp) {
758 return hyp ? hyp->_GetAllEnforcedVerticesByEnfVertexEntry() : GetDefaultEnfVertexEntryEnfVertexMap();
761 std::set<int> BLSURFPlugin_Hypothesis::GetEnfVertexNodeIDs(TEnfGroupName theGroupName) throw (std::invalid_argument)
763 TGroupNameNodeIDMap::const_iterator it = _groupNameNodeIDMap.find(theGroupName);
764 if (it != _groupNameNodeIDMap.end()) {
767 std::ostringstream msg;
768 msg << "No group " << theGroupName;
769 throw std::invalid_argument(msg.str());
772 void BLSURFPlugin_Hypothesis::AddEnfVertexNodeID(TEnfGroupName theGroupName,int theNodeID)
774 _groupNameNodeIDMap[theGroupName].insert(theNodeID);
777 void BLSURFPlugin_Hypothesis::RemoveEnfVertexNodeID(TEnfGroupName theGroupName,int theNodeID) throw (std::invalid_argument)
779 TGroupNameNodeIDMap::iterator it = _groupNameNodeIDMap.find(theGroupName);
780 if (it != _groupNameNodeIDMap.end()) {
781 std::set<int>::iterator IDit = it->second.find(theNodeID);
782 if (IDit != it->second.end())
783 it->second.erase(IDit);
784 std::ostringstream msg;
785 msg << "No node IDs " << theNodeID << " for group " << theGroupName;
786 throw std::invalid_argument(msg.str());
788 std::ostringstream msg;
789 msg << "No group " << theGroupName;
790 throw std::invalid_argument(msg.str());
793 //=============================================================================
794 std::ostream & BLSURFPlugin_Hypothesis::SaveTo(std::ostream & save) {
795 save << " " << (int) _topology << " " << (int) _physicalMesh << " " << (int) _geometricMesh << " " << _phySize << " "
796 << _angleMeshS << " " << _gradation << " " << (int) _quadAllowed << " " << (int) _decimesh;
797 save << " " << _phyMin << " " << _phyMax << " " << _angleMeshC << " " << _hgeoMin << " " << _hgeoMax << " " << _verb;
799 TOptionValues::iterator op_val = _option2value.begin();
800 if (op_val != _option2value.end()) {
801 save << " " << "__OPTIONS_BEGIN__";
802 for (; op_val != _option2value.end(); ++op_val) {
803 if (!op_val->second.empty())
804 save << " " << op_val->first << " " << op_val->second << "%#"; // "%#" is a mark of value end
806 save << " " << "__OPTIONS_END__";
809 TSizeMap::iterator it_sm = _sizeMap.begin();
810 if (it_sm != _sizeMap.end()) {
811 save << " " << "__SIZEMAP_BEGIN__";
812 for (; it_sm != _sizeMap.end(); ++it_sm) {
813 save << " " << it_sm->first << " " << it_sm->second << "%#"; // "%#" is a mark of value end
815 save << " " << "__SIZEMAP_END__";
818 TSizeMap::iterator it_at = _attractors.begin();
819 if (it_at != _attractors.end()) {
820 save << " " << "__ATTRACTORS_BEGIN__";
821 for (; it_at != _attractors.end(); ++it_at) {
822 save << " " << it_at->first << " " << it_at->second << "%#"; // "%#" is a mark of value end
824 save << " " << "__ATTRACTORS_END__";
827 TFaceEntryEnfVertexListMap::const_iterator it_enf = _faceEntryEnfVertexListMap.begin();
828 if (it_enf != _faceEntryEnfVertexListMap.end()) {
829 save << " " << "__ENFORCED_VERTICES_BEGIN__";
830 for (; it_enf != _faceEntryEnfVertexListMap.end(); ++it_enf) {
831 save << " " << it_enf->first;
832 TEnfVertexList enfVertexList = it_enf->second;
833 TEnfVertexList::const_iterator it_enfVertexList = enfVertexList.begin();
834 for (; it_enfVertexList != enfVertexList.end(); ++it_enfVertexList) {
835 TEnfVertex *enfVertex = (*it_enfVertexList);
836 save << " " << enfVertex->name << ";";
837 save << " " << enfVertex->geomEntry << ";";
838 if (enfVertex->coords.size()) {
839 save << " " << enfVertex->coords[0] << ";";
840 save << " " << enfVertex->coords[1] << ";";
841 save << " " << enfVertex->coords[2] << ";";
846 save << " " << enfVertex->grpName;
847 save << " " << "$"; // "$" is a mark of enforced vertex end
849 save << "#"; // "#" is a mark of enforced shape end
851 save << " " << "__ENFORCED_VERTICES_END__";
857 //=============================================================================
858 std::istream & BLSURFPlugin_Hypothesis::LoadFrom(std::istream & load) {
865 _topology = (Topology) i;
867 load.clear(std::ios::badbit | load.rdstate());
871 _physicalMesh = (PhysicalMesh) i;
873 load.clear(std::ios::badbit | load.rdstate());
877 _geometricMesh = (GeometricMesh) i;
879 load.clear(std::ios::badbit | load.rdstate());
881 isOK = (load >> val);
885 load.clear(std::ios::badbit | load.rdstate());
887 isOK = (load >> val);
891 load.clear(std::ios::badbit | load.rdstate());
893 isOK = (load >> val);
897 load.clear(std::ios::badbit | load.rdstate());
901 _quadAllowed = (bool) i;
903 load.clear(std::ios::badbit | load.rdstate());
907 _decimesh = (bool) i;
909 load.clear(std::ios::badbit | load.rdstate());
911 isOK = (load >> val);
915 load.clear(std::ios::badbit | load.rdstate());
917 isOK = (load >> val);
921 load.clear(std::ios::badbit | load.rdstate());
923 isOK = (load >> val);
927 load.clear(std::ios::badbit | load.rdstate());
929 isOK = (load >> val);
933 load.clear(std::ios::badbit | load.rdstate());
935 isOK = (load >> val);
939 load.clear(std::ios::badbit | load.rdstate());
945 load.clear(std::ios::badbit | load.rdstate());
947 std::string option_or_sm;
948 bool hasOptions = false;
949 bool hasSizeMap = false;
950 bool hasAttractor = false;
951 bool hasEnforcedVertex = false;
953 isOK = (load >> option_or_sm);
955 if (option_or_sm == "__OPTIONS_BEGIN__")
957 else if (option_or_sm == "__SIZEMAP_BEGIN__")
959 else if (option_or_sm == "__ATTRACTORS_BEGIN__")
961 else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
962 hasEnforcedVertex = true;
964 std::string optName, optValue;
965 while (isOK && hasOptions) {
966 isOK = (load >> optName);
968 if (optName == "__OPTIONS_END__")
970 isOK = (load >> optValue);
973 std::string & value = _option2value[optName];
975 int len = value.size();
976 // continue reading until "%#" encountered
977 while (value[len - 1] != '#' || value[len - 2] != '%') {
978 isOK = (load >> optValue);
987 value[len - 2] = '\0'; //cut off "%#"
992 isOK = (load >> option_or_sm);
994 if (option_or_sm == "__SIZEMAP_BEGIN__")
996 else if (option_or_sm == "__ATTRACTORS_BEGIN__")
998 else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
999 hasEnforcedVertex = true;
1002 std::string smEntry, smValue;
1003 while (isOK && hasSizeMap) {
1004 isOK = (load >> smEntry);
1006 if (smEntry == "__SIZEMAP_END__")
1008 isOK = (load >> smValue);
1011 std::string & value2 = _sizeMap[smEntry];
1013 int len2 = value2.size();
1014 // continue reading until "%#" encountered
1015 while (value2[len2 - 1] != '#' || value2[len2 - 2] != '%') {
1016 isOK = (load >> smValue);
1020 len2 = value2.size();
1025 value2[len2 - 2] = '\0'; //cut off "%#"
1030 isOK = (load >> option_or_sm);
1032 if (option_or_sm == "__ATTRACTORS_BEGIN__")
1033 hasAttractor = true;
1034 else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
1035 hasEnforcedVertex = true;
1038 std::string atEntry, atValue;
1039 while (isOK && hasAttractor) {
1040 isOK = (load >> atEntry);
1042 if (atEntry == "__ATTRACTORS_END__")
1044 isOK = (load >> atValue);
1047 std::string & value3 = _attractors[atEntry];
1049 int len3 = value3.size();
1050 // continue reading until "%#" encountered
1051 while (value3[len3 - 1] != '#' || value3[len3 - 2] != '%') {
1052 isOK = (load >> atValue);
1056 len3 = value3.size();
1061 value3[len3 - 2] = '\0'; //cut off "%#"
1066 isOK = (load >> option_or_sm);
1068 if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
1069 hasEnforcedVertex = true;
1073 // TFaceEntryEnfVertexListMap _faceEntryEnfVertexListMap;
1074 // TEnfVertexList _enfVertexList;
1075 // // maps to get "manual" enf vertex (through their coordinates)
1076 // TFaceEntryCoordsListMap _faceEntryCoordsListMap;
1077 // TCoordsEnfVertexMap _coordsEnfVertexMap;
1078 // // maps to get "geom" enf vertex (through their geom entries)
1079 // TFaceEntryEnfVertexEntryListMap _faceEntryEnfVertexEntryListMap;
1080 // TEnfVertexEntryEnfVertexMap _enfVertexEntryEnfVertexMap;
1082 std::string enfVertexEntry, enfValue, enfGroup, trace;
1083 std::ostringstream oss;
1084 while (isOK && hasEnforcedVertex) {
1085 isOK = (load >> enfVertexEntry);
1087 MESSAGE("enfVertexEntry: " <<enfVertexEntry);
1088 if (enfVertexEntry == "__ENFORCED_VERTICES_END__")
1092 bool hasGroup = false;
1095 int len4 = enfValue.size();
1097 TEnfVertexCoordsList & coordsList = _faceEntryCoordsListMap[enfVertexEntry];
1099 TEnfVertexCoords coords;
1100 TEnfVertex *enfVertex;
1102 // continue reading until "#" encountered
1103 while (enfValue[len4 - 1] != '#') {
1106 enfVertex->coords.clear();
1108 while (enfValue[len4 - 1] != '$') {
1109 isOK = (load >> enfValue);
1111 MESSAGE("enfValue: " <<enfValue);
1112 len4 = enfValue.size();
1113 // End of vertex list
1114 if (enfValue[len4 - 1] == '#')
1117 if (enfValue == "__ENF_GROUP_BEGIN__") {
1119 isOK = (load >> enfGroup);
1120 MESSAGE("enfGroup: " <<enfGroup);
1121 TEnfGroupName& groupName = _enfVertexGroupNameMap[ enfVertex ];
1122 groupName = enfGroup;
1124 isOK = (load >> enfGroup);
1126 MESSAGE("enfGroup: " <<enfGroup);
1127 if (enfGroup == "__ENF_GROUP_END__")
1130 groupName += enfGroup;
1136 enfVertex.push_back(atof(enfValue.c_str()));
1139 if (enfValue[len4 - 1] != '$') {
1142 enfVertex->name = enfValue;
1143 isOK = (load >> enfValue);
1144 len4 = enfValue.size();
1146 if (enfValue[len4 - 1] != '$') {
1148 enfVertex->coords.push_back(atof(enfValue.c_str()));
1149 isOK = (load >> enfValue);
1150 len4 = enfValue.size();
1152 if (enfValue[len4 - 1] != '$') {
1154 enfVertex->coords.push_back(atof(enfValue.c_str()));
1155 isOK = (load >> enfValue);
1156 len4 = enfValue.size();
1158 if (enfValue[len4 - 1] != '$') {
1160 enfVertex->coords.push_back(atof(enfValue.c_str()));
1161 isOK = (load >> enfValue);
1162 len4 = enfValue.size();
1167 if (enfValue[len4 - 1] == '$') {
1168 MESSAGE("enfValue is $");
1169 enfValue[len4 - 1] = '\0'; //cut off "$"
1172 MESSAGE("no group: remove $");
1173 // Remove '$' and add to vertex
1174 // enfValue[len4-1] = '\0'; //cut off "$#"
1175 enfVertex.push_back(atof(enfValue.c_str()));
1178 enfValue[len4 - 1] = '\0'; //cut off "$#"
1179 enfVertex->coords.push_back(atof(enfValue.c_str()));
1180 MESSAGE("Add vertex to list");
1181 // Add vertex to list of vertex
1182 coordsList.insert(enfVertex->coords);
1183 _coordsEnfVertexMap[enfVertex->coords] = enfVertex;
1184 // _enfVertexList.insert(enfVertex);
1187 if (enfValue[len4 - 1] == '#') {
1190 // Remove '$#' and add to vertex
1191 enfValue[len4-2] = '\0'; //cut off "$#"
1192 enfVertex.push_back(atof(enfValue.c_str()));
1195 // Remove '$#' and add to vertex
1196 enfValue[len4 - 2] = '\0'; //cut off "$#"
1197 enfVertex->coords.push_back(atof(enfValue.c_str()));
1198 // Add vertex to list of vertex
1199 coordsList.insert(enfVertex->coords);
1200 _coordsEnfVertexMap[enfVertex->coords] = enfVertex;
1201 // _enfVertexList.insert(enfVertex);
1210 //=============================================================================
1211 std::ostream & operator <<(std::ostream & save, BLSURFPlugin_Hypothesis & hyp) {
1212 return hyp.SaveTo(save);
1215 //=============================================================================
1216 std::istream & operator >>(std::istream & load, BLSURFPlugin_Hypothesis & hyp) {
1217 return hyp.LoadFrom(load);
1220 //================================================================================
1222 * \brief Does nothing
1224 //================================================================================
1226 bool BLSURFPlugin_Hypothesis::SetParametersByMesh(const SMESH_Mesh* theMesh, const TopoDS_Shape& theShape) {
1230 //=============================================================================
1232 * \brief Initialize my parameter values by default parameters.
1233 * \retval bool - true if parameter values have been successfully defined
1235 //=============================================================================
1237 bool BLSURFPlugin_Hypothesis::SetParametersByDefaults(const TDefaults& dflts, const SMESH_Mesh* theMesh) {
1238 return bool(_phySize = dflts._elemLength);
1241 //=============================================================================
1242 BLSURFPlugin_Hypothesis::Topology BLSURFPlugin_Hypothesis::GetDefaultTopology() {
1246 //=============================================================================
1247 BLSURFPlugin_Hypothesis::PhysicalMesh BLSURFPlugin_Hypothesis::GetDefaultPhysicalMesh() {
1248 return PhysicalUserDefined;
1251 //=============================================================================
1252 double BLSURFPlugin_Hypothesis::GetDefaultPhySize() {
1256 //======================================================================
1257 double BLSURFPlugin_Hypothesis::GetDefaultMaxSize() {
1258 return undefinedDouble(); // 1e+4;
1261 //======================================================================
1262 double BLSURFPlugin_Hypothesis::GetDefaultMinSize() {
1263 return undefinedDouble(); //1e-4;
1266 //======================================================================
1267 BLSURFPlugin_Hypothesis::GeometricMesh BLSURFPlugin_Hypothesis::GetDefaultGeometricMesh() {
1271 //=============================================================================
1272 double BLSURFPlugin_Hypothesis::GetDefaultAngleMeshS() {
1276 //=============================================================================
1277 double BLSURFPlugin_Hypothesis::GetDefaultGradation() {
1281 //=============================================================================
1282 bool BLSURFPlugin_Hypothesis::GetDefaultQuadAllowed() {
1286 //=============================================================================
1287 bool BLSURFPlugin_Hypothesis::GetDefaultDecimesh() {