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 TEnfVertexList::const_iterator it_enf = _enfVertexList.begin();
828 if (it_enf != _enfVertexList.end()) {
829 save << " " << "__ENFORCED_VERTICES_BEGIN__";
830 for (; it_enf != _enfVertexList.end(); ++it_enf) {
831 TEnfVertex *enfVertex = (*it_enf);
832 save << " " << "__BEGIN_VERTEX__";
833 if (!enfVertex->name.empty()) {
834 save << " " << "__BEGIN_NAME__";
835 save << " " << enfVertex->name;
836 save << " " << "__END_NAME__";
838 if (!enfVertex->geomEntry.empty()) {
839 save << " " << "__BEGIN_ENTRY__";
840 save << " " << enfVertex->geomEntry;
841 save << " " << "__END_ENTRY__";
843 if (!enfVertex->grpName.empty()) {
844 save << " " << "__BEGIN_GROUP__";
845 save << " " << enfVertex->grpName;
846 save << " " << "__END_GROUP__";
848 if (enfVertex->coords.size()) {
849 save << " " << "__BEGIN_COORDS__";
850 for (int i=0;i<enfVertex->coords.size();i++)
851 save << " " << enfVertex->coords[i];
852 save << " " << "__END_COORDS__";
854 TEntryList::const_iterator faceEntriesIt = enfVertex->faceEntries.begin();
855 bool hasFaces = false;
856 if (faceEntriesIt != enfVertex->faceEntries.end()) {
858 save << " " << "__BEGIN_FACELIST__";
860 for (; faceEntriesIt != enfVertex->faceEntries.end(); ++faceEntriesIt)
861 save << " " << (*faceEntriesIt);
863 save << " " << "__END_FACELIST__";
864 save << " " << "__END_VERTEX__";
866 save << " " << "__ENFORCED_VERTICES_END__";
872 //=============================================================================
873 std::istream & BLSURFPlugin_Hypothesis::LoadFrom(std::istream & load) {
880 _topology = (Topology) i;
882 load.clear(std::ios::badbit | load.rdstate());
886 _physicalMesh = (PhysicalMesh) i;
888 load.clear(std::ios::badbit | load.rdstate());
892 _geometricMesh = (GeometricMesh) i;
894 load.clear(std::ios::badbit | load.rdstate());
896 isOK = (load >> val);
900 load.clear(std::ios::badbit | load.rdstate());
902 isOK = (load >> val);
906 load.clear(std::ios::badbit | load.rdstate());
908 isOK = (load >> val);
912 load.clear(std::ios::badbit | load.rdstate());
916 _quadAllowed = (bool) i;
918 load.clear(std::ios::badbit | load.rdstate());
922 _decimesh = (bool) i;
924 load.clear(std::ios::badbit | load.rdstate());
926 isOK = (load >> val);
930 load.clear(std::ios::badbit | load.rdstate());
932 isOK = (load >> val);
936 load.clear(std::ios::badbit | load.rdstate());
938 isOK = (load >> val);
942 load.clear(std::ios::badbit | load.rdstate());
944 isOK = (load >> val);
948 load.clear(std::ios::badbit | load.rdstate());
950 isOK = (load >> val);
954 load.clear(std::ios::badbit | load.rdstate());
960 load.clear(std::ios::badbit | load.rdstate());
962 std::string option_or_sm;
963 bool hasOptions = false;
964 bool hasSizeMap = false;
965 bool hasAttractor = false;
966 bool hasEnforcedVertex = false;
968 isOK = (load >> option_or_sm);
970 if (option_or_sm == "__OPTIONS_BEGIN__")
972 else if (option_or_sm == "__SIZEMAP_BEGIN__")
974 else if (option_or_sm == "__ATTRACTORS_BEGIN__")
976 else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
977 hasEnforcedVertex = true;
979 std::string optName, optValue;
980 while (isOK && hasOptions) {
981 isOK = (load >> optName);
983 if (optName == "__OPTIONS_END__")
985 isOK = (load >> optValue);
988 std::string & value = _option2value[optName];
990 int len = value.size();
991 // continue reading until "%#" encountered
992 while (value[len - 1] != '#' || value[len - 2] != '%') {
993 isOK = (load >> optValue);
1002 value[len - 2] = '\0'; //cut off "%#"
1007 isOK = (load >> option_or_sm);
1009 if (option_or_sm == "__SIZEMAP_BEGIN__")
1011 else if (option_or_sm == "__ATTRACTORS_BEGIN__")
1012 hasAttractor = true;
1013 else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
1014 hasEnforcedVertex = true;
1017 std::string smEntry, smValue;
1018 while (isOK && hasSizeMap) {
1019 isOK = (load >> smEntry);
1021 if (smEntry == "__SIZEMAP_END__")
1023 isOK = (load >> smValue);
1026 std::string & value2 = _sizeMap[smEntry];
1028 int len2 = value2.size();
1029 // continue reading until "%#" encountered
1030 while (value2[len2 - 1] != '#' || value2[len2 - 2] != '%') {
1031 isOK = (load >> smValue);
1035 len2 = value2.size();
1040 value2[len2 - 2] = '\0'; //cut off "%#"
1045 isOK = (load >> option_or_sm);
1047 if (option_or_sm == "__ATTRACTORS_BEGIN__")
1048 hasAttractor = true;
1049 else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
1050 hasEnforcedVertex = true;
1053 std::string atEntry, atValue;
1054 while (isOK && hasAttractor) {
1055 isOK = (load >> atEntry);
1057 if (atEntry == "__ATTRACTORS_END__")
1059 isOK = (load >> atValue);
1062 std::string & value3 = _attractors[atEntry];
1064 int len3 = value3.size();
1065 // continue reading until "%#" encountered
1066 while (value3[len3 - 1] != '#' || value3[len3 - 2] != '%') {
1067 isOK = (load >> atValue);
1071 len3 = value3.size();
1076 value3[len3 - 2] = '\0'; //cut off "%#"
1081 isOK = (load >> option_or_sm);
1083 if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
1084 hasEnforcedVertex = true;
1089 // Here is a example of the saved stream:
1090 // __ENFORCED_VERTICES_BEGIN__
1091 // __BEGIN_VERTEX__ => no name, no entry
1092 // __BEGIN_GROUP__ mon groupe __END_GROUP__
1093 // __BEGIN_COORDS__ 10 10 10 __END_COORDS__
1094 // __BEGIN_FACELIST__ 0:1:1:1:1 __END_FACELIST__
1096 // __BEGIN_VERTEX__ => no coords
1097 // __BEGIN_NAME__ mes points __END_NAME__
1098 // __BEGIN_ENTRY__ 0:1:1:4 __END_ENTRY__
1099 // __BEGIN_GROUP__ mon groupe __END_GROUP__
1100 // __BEGIN_FACELIST__ 0:1:1:1:3 __END_FACELIST__
1102 // __ENFORCED_VERTICES_END__
1105 std::string enfSeparator;
1106 std::string enfName;
1107 std::string enfGeomEntry;
1108 std::string enfGroup;
1109 TEntryList enfFaceEntryList;
1110 double enfCoords[3];
1111 bool hasCoords = false;
1113 _faceEntryEnfVertexListMap.clear();
1114 _enfVertexList.clear();
1115 _faceEntryCoordsListMap.clear();
1116 _coordsEnfVertexMap.clear();
1117 _faceEntryEnfVertexEntryListMap.clear();
1118 _enfVertexEntryEnfVertexMap.clear();
1121 while (isOK && hasEnforcedVertex) {
1122 isOK = (load >> enfSeparator); // __BEGIN_VERTEX__
1123 TEnfVertex *enfVertex = new TEnfVertex();
1124 // MESSAGE("enfSeparator: " <<enfSeparator);
1125 if (enfSeparator == "__ENFORCED_VERTICES_END__")
1126 break; // __ENFORCED_VERTICES_END__
1127 if (enfSeparator != "__BEGIN_VERTEX__")
1128 throw std::exception::exception();
1131 isOK = (load >> enfSeparator);
1132 MESSAGE("enfSeparator: " <<enfSeparator);
1133 if (enfSeparator == "__END_VERTEX__") {
1135 enfVertex->name = enfName;
1136 enfVertex->geomEntry = enfGeomEntry;
1137 enfVertex->grpName = enfGroup;
1138 enfVertex->coords.clear();
1140 enfVertex->coords.assign(enfCoords,enfCoords+3);
1141 enfVertex->faceEntries = enfFaceEntryList;
1143 _enfVertexList.insert(enfVertex);
1145 if (enfVertex->coords.size()) {
1146 _coordsEnfVertexMap[enfVertex->coords] = enfVertex;
1147 for (TEntryList::const_iterator it = enfVertex->faceEntries.begin() ; it != enfVertex->faceEntries.end(); ++it) {
1148 _faceEntryCoordsListMap[(*it)].insert(enfVertex->coords);
1149 _faceEntryEnfVertexListMap[(*it)].insert(enfVertex);
1152 if (!enfVertex->geomEntry.empty()) {
1153 _enfVertexEntryEnfVertexMap[enfVertex->geomEntry] = enfVertex;
1154 for (TEntryList::const_iterator it = enfVertex->faceEntries.begin() ; it != enfVertex->faceEntries.end(); ++it) {
1155 _faceEntryEnfVertexEntryListMap[(*it)].insert(enfVertex->geomEntry);
1156 _faceEntryEnfVertexListMap[(*it)].insert(enfVertex);
1161 enfGeomEntry.clear();
1163 enfFaceEntryList.clear();
1165 break; // __END_VERTEX__
1168 if (enfSeparator == "__BEGIN_NAME__") { // __BEGIN_NAME__
1169 while (isOK && (enfSeparator != "__END_NAME__")) {
1170 isOK = (load >> enfSeparator);
1171 if (enfSeparator != "__END_NAME__") {
1172 if (!enfName.empty())
1174 enfName += enfSeparator;
1177 MESSAGE("enfName: " <<enfName);
1180 if (enfSeparator == "__BEGIN_ENTRY__") { // __BEGIN_ENTRY__
1181 isOK = (load >> enfGeomEntry);
1182 isOK = (load >> enfSeparator); // __END_ENTRY__
1183 if (enfSeparator != "__END_ENTRY__")
1184 throw std::exception::exception();
1185 MESSAGE("enfGeomEntry: " <<enfGeomEntry);
1188 if (enfSeparator == "__BEGIN_GROUP__") { // __BEGIN_GROUP__
1189 while (isOK && (enfSeparator != "__END_GROUP__")) {
1190 isOK = (load >> enfSeparator);
1191 if (enfSeparator != "__END_GROUP__") {
1192 if (!enfGroup.empty())
1194 enfGroup += enfSeparator;
1197 MESSAGE("enfGroup: " <<enfGroup);
1200 if (enfSeparator == "__BEGIN_COORDS__") { // __BEGIN_COORDS__
1202 isOK = (load >> enfCoords[0] >> enfCoords[1] >> enfCoords[2]);
1203 isOK = (load >> enfSeparator); // __END_COORDS__
1204 if (enfSeparator != "__END_COORDS__")
1205 throw std::exception::exception();
1206 MESSAGE("enfCoords: " << enfCoords[0] <<","<< enfCoords[1] <<","<< enfCoords[2]);
1209 if (enfSeparator == "__BEGIN_FACELIST__") { // __BEGIN_FACELIST__
1210 while (isOK && (enfSeparator != "__END_FACELIST__")) {
1211 isOK = (load >> enfSeparator);
1212 if (enfSeparator != "__END_FACELIST__") {
1213 enfFaceEntryList.insert(enfSeparator);
1214 MESSAGE(enfSeparator << " was inserted into enfFaceEntryList");
1224 //=============================================================================
1225 std::ostream & operator <<(std::ostream & save, BLSURFPlugin_Hypothesis & hyp) {
1226 return hyp.SaveTo(save);
1229 //=============================================================================
1230 std::istream & operator >>(std::istream & load, BLSURFPlugin_Hypothesis & hyp) {
1231 return hyp.LoadFrom(load);
1234 //================================================================================
1236 * \brief Does nothing
1238 //================================================================================
1240 bool BLSURFPlugin_Hypothesis::SetParametersByMesh(const SMESH_Mesh* theMesh, const TopoDS_Shape& theShape) {
1244 //=============================================================================
1246 * \brief Initialize my parameter values by default parameters.
1247 * \retval bool - true if parameter values have been successfully defined
1249 //=============================================================================
1251 bool BLSURFPlugin_Hypothesis::SetParametersByDefaults(const TDefaults& dflts, const SMESH_Mesh* theMesh) {
1252 return bool(_phySize = dflts._elemLength);
1255 //=============================================================================
1256 BLSURFPlugin_Hypothesis::Topology BLSURFPlugin_Hypothesis::GetDefaultTopology() {
1260 //=============================================================================
1261 BLSURFPlugin_Hypothesis::PhysicalMesh BLSURFPlugin_Hypothesis::GetDefaultPhysicalMesh() {
1262 return PhysicalUserDefined;
1265 //=============================================================================
1266 double BLSURFPlugin_Hypothesis::GetDefaultPhySize() {
1270 //======================================================================
1271 double BLSURFPlugin_Hypothesis::GetDefaultMaxSize() {
1272 return undefinedDouble(); // 1e+4;
1275 //======================================================================
1276 double BLSURFPlugin_Hypothesis::GetDefaultMinSize() {
1277 return undefinedDouble(); //1e-4;
1280 //======================================================================
1281 BLSURFPlugin_Hypothesis::GeometricMesh BLSURFPlugin_Hypothesis::GetDefaultGeometricMesh() {
1285 //=============================================================================
1286 double BLSURFPlugin_Hypothesis::GetDefaultAngleMeshS() {
1290 //=============================================================================
1291 double BLSURFPlugin_Hypothesis::GetDefaultGradation() {
1295 //=============================================================================
1296 bool BLSURFPlugin_Hypothesis::GetDefaultQuadAllowed() {
1300 //=============================================================================
1301 bool BLSURFPlugin_Hypothesis::GetDefaultDecimesh() {