X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FBLSURFPlugin%2FBLSURFPlugin_Hypothesis.cxx;h=992fbd3df68fcdd42ed57cc0e3cc55762c7453c2;hb=8422810dcc5e588762f906db7a15f31eb337f3eb;hp=a9f54e563cac03ea994f0863ad07ebdc7d803a52;hpb=7f93c91d84ef90f1885e44131f34b3794a793dd6;p=plugins%2Fblsurfplugin.git diff --git a/src/BLSURFPlugin/BLSURFPlugin_Hypothesis.cxx b/src/BLSURFPlugin/BLSURFPlugin_Hypothesis.cxx index a9f54e5..992fbd3 100644 --- a/src/BLSURFPlugin/BLSURFPlugin_Hypothesis.cxx +++ b/src/BLSURFPlugin/BLSURFPlugin_Hypothesis.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2014 CEA/DEN, EDF R&D +// Copyright (C) 2007-2015 CEA/DEN, EDF R&D // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -82,7 +82,7 @@ BLSURFPlugin_Hypothesis::BLSURFPlugin_Hypothesis(int hypId, int studyId, SMESH_G _preCadFacesPeriodicityVector(GetDefaultPreCadFacesPeriodicityVector()), _preCadEdgesPeriodicityVector(GetDefaultPreCadEdgesPeriodicityVector()) { - _name = "BLSURF_Parameters"; + _name = GetHypType(); _param_algo_dim = 2; // _GMFFileMode = false; // GMF ascii mode @@ -96,6 +96,10 @@ BLSURFPlugin_Hypothesis::BLSURFPlugin_Hypothesis(int hypId, int studyId, SMESH_G "proximity", // default = 0 "rectify_jacobian", // default = 1 "respect_geometry", // default = 1 + "optimise_tiny_edges", // default = 0 + "remove_duplicate_cad_faces", // default = 1 + "tiny_edge_avoid_surface_intersections", // default = 1 + "tiny_edge_respect_geometry", // default = 0 "" // mark of end }; @@ -108,6 +112,8 @@ BLSURFPlugin_Hypothesis::BLSURFPlugin_Hypothesis(int hypId, int studyId, SMESH_G const char* doubleOptionNames[] = { "surface_intersections_processing_max_cost",// default = 15 "periodic_tolerance", // default = diag/100 "prox_ratio", + "volume_gradation", + "tiny_edge_optimisation_length", // default = diag * 1e-6 "" // mark of end }; const char* charOptionNames[] = { "required_entities", // default = "respect" @@ -417,7 +423,7 @@ void BLSURFPlugin_Hypothesis::SetOptionValue(const std::string& optionName, cons throw (std::invalid_argument) { TOptionValues::iterator op_val = _option2value.find(optionName); if (op_val == _option2value.end()) { - std::string msg = "Unknown BLSURF option: '" + optionName + "'"; + std::string msg = "Unknown MG-CADSurf option: '" + optionName + "'"; throw std::invalid_argument(msg); } if (op_val->second != optionValue) { @@ -462,7 +468,7 @@ void BLSURFPlugin_Hypothesis::SetPreCADOptionValue(const std::string& optionName throw (std::invalid_argument) { TOptionValues::iterator op_val = _preCADoption2value.find(optionName); if (op_val == _preCADoption2value.end()) { - std::string msg = "Unknown BLSURF option: '" + optionName + "'"; + std::string msg = "Unknown MG-CADSurf option: '" + optionName + "'"; throw std::invalid_argument(msg); } if (op_val->second != optionValue) { @@ -506,7 +512,7 @@ void BLSURFPlugin_Hypothesis::SetPreCADOptionValue(const std::string& optionName std::string BLSURFPlugin_Hypothesis::GetOptionValue(const std::string& optionName) throw (std::invalid_argument) { TOptionValues::iterator op_val = _option2value.find(optionName); if (op_val == _option2value.end()) { - std::string msg = "Unknown BLSURF option: <"; + std::string msg = "Unknown MG-CADSurf option: <"; msg += optionName + ">"; throw std::invalid_argument(msg); } @@ -526,16 +532,82 @@ std::string BLSURFPlugin_Hypothesis::GetPreCADOptionValue(const std::string& opt //============================================================================= void BLSURFPlugin_Hypothesis::ClearOption(const std::string& optionName) { - TOptionValues::iterator op_val = _option2value.find(optionName); - if (op_val != _option2value.end()) - op_val->second.clear(); + TOptionValues::iterator op_val = _customOption2value.find(optionName); + if (op_val != _customOption2value.end()) + _customOption2value.erase(op_val); + else { + op_val = _option2value.find(optionName); + if (op_val != _option2value.end()) + op_val->second.clear(); + } } //============================================================================= void BLSURFPlugin_Hypothesis::ClearPreCADOption(const std::string& optionName) { + TOptionValues::iterator op_val = _customPreCADOption2value.find(optionName); + if (op_val != _customPreCADOption2value.end()) + _customPreCADOption2value.erase(op_val); + else { + op_val = _preCADoption2value.find(optionName); + if (op_val != _preCADoption2value.end()) + op_val->second.clear(); + } +} + +//============================================================================= +void BLSURFPlugin_Hypothesis::AddOption(const std::string& optionName, const std::string& optionValue) +{ + TOptionValues::iterator op_val = _option2value.find(optionName); + if (op_val != _option2value.end()) { + if (op_val->second != optionValue) + op_val->second = optionValue; + } + else { + op_val = _customOption2value.find(optionName); + if (op_val == _customOption2value.end()) + _customOption2value[optionName] = optionValue; + else if (op_val->second != optionValue) + op_val->second = optionValue; + } + NotifySubMeshesHypothesisModification(); +} + +//============================================================================= +void BLSURFPlugin_Hypothesis::AddPreCADOption(const std::string& optionName, const std::string& optionValue) +{ TOptionValues::iterator op_val = _preCADoption2value.find(optionName); - if (op_val != _preCADoption2value.end()) - op_val->second.clear(); + if (op_val != _preCADoption2value.end()) { + if (op_val->second != optionValue) + op_val->second = optionValue; + } + else { + op_val = _customPreCADOption2value.find(optionName); + if (op_val == _customPreCADOption2value.end()) + _customPreCADOption2value[optionName] = optionValue; + else if (op_val->second != optionValue) + op_val->second = optionValue; + } + NotifySubMeshesHypothesisModification(); +} + +//============================================================================= +std::string BLSURFPlugin_Hypothesis::GetOption(const std::string& optionName) +{ + TOptionValues::iterator op_val = _customOption2value.find(optionName); + if (op_val != _customOption2value.end()) + return op_val->second; + else + return ""; +} + +//============================================================================= +std::string BLSURFPlugin_Hypothesis::GetPreCADOption(const std::string& optionName) +{ + TOptionValues::iterator op_val = _customPreCADOption2value.find(optionName); + if (op_val != _customPreCADOption2value.end()) + return op_val->second; + else + return ""; } //======================================================================= @@ -619,26 +691,26 @@ void BLSURFPlugin_Hypothesis::SetClassAttractorEntry(const std::string& entry, c const TopoDS_Shape AttractorShape = BLSURFPlugin_Hypothesis::entryToShape(attEntry); const TopoDS_Face FaceShape = TopoDS::Face(BLSURFPlugin_Hypothesis::entryToShape(entry)); - bool attExists = (_classAttractors.find(entry) != _classAttractors.end()); - double u1,u2,v1,v2, diag; - - if ( !attExists || (attExists && _classAttractors[entry]->GetAttractorEntry().compare(attEntry) != 0)){ - ShapeAnalysis::GetFaceUVBounds(FaceShape,u1,u2,v1,v2); -// diag = sqrt((u2 - u1) * (u2 - u1) + (v2 - v1) * (v2 - v1)); - BLSURFPlugin_Attractor* myAttractor = new BLSURFPlugin_Attractor(FaceShape, AttractorShape, attEntry);//, 0.1 ); // test 0.002 * diag); - myAttractor->BuildMap(); - myAttractor->SetParameters(StartSize, EndSize, ActionRadius, ConstantRadius); - _classAttractors[entry] = myAttractor; - NotifySubMeshesHypothesisModification(); + TAttractorMap::iterator attIt = _classAttractors.find(entry); + for ( ; attIt != _classAttractors.end(); ++attIt ) + if ( attIt->first == entry && + attIt->second->GetAttractorEntry() == attEntry ) + break; + bool attExists = (attIt != _classAttractors.end()); + + BLSURFPlugin_Attractor* myAttractor; + if ( !attExists ) { + myAttractor = new BLSURFPlugin_Attractor(FaceShape, AttractorShape, attEntry);//, 0.1 ); + _classAttractors.insert( make_pair( entry, myAttractor )); } else { - _classAttractors[entry]->SetParameters(StartSize, EndSize, ActionRadius, ConstantRadius); - if (!_classAttractors[entry]->IsMapBuilt()){ - _classAttractors[entry]->BuildMap(); - } - NotifySubMeshesHypothesisModification(); + myAttractor = attIt->second; } - + // if (!myAttractor->IsMapBuilt()) + // myAttractor->BuildMap(); + myAttractor->SetParameters(StartSize, EndSize, ActionRadius, ConstantRadius); + + NotifySubMeshesHypothesisModification(); } //======================================================================= @@ -681,7 +753,8 @@ BLSURFPlugin_Hypothesis::TAttractorMap BLSURFPlugin_Hypothesis::GetClassAttracto //======================================================================= //function : ClearEntry //======================================================================= -void BLSURFPlugin_Hypothesis::ClearEntry(const std::string& entry) +void BLSURFPlugin_Hypothesis::ClearEntry(const std::string& entry, + const char * attEntry/*=0*/) { TSizeMap::iterator it = _sizeMap.find( entry ); @@ -698,7 +771,13 @@ void BLSURFPlugin_Hypothesis::ClearEntry(const std::string& entry) else { TAttractorMap::iterator it_clAt = _classAttractors.find( entry ); if ( it_clAt != _classAttractors.end() ) { - _classAttractors.erase(it_clAt); + do { + if ( !attEntry || it_clAt->second->GetAttractorEntry() == attEntry ) + _classAttractors.erase( it_clAt++ ); + else + ++it_clAt; + } + while ( it_clAt != _classAttractors.end() ); MESSAGE("_classAttractors.size() = "<<_classAttractors.size()) NotifySubMeshesHypothesisModification(); } @@ -1335,7 +1414,7 @@ void BLSURFPlugin_Hypothesis::AddVertexPeriodicity(TEntry theEdge1Entry, TEntry //============================================================================= std::ostream & BLSURFPlugin_Hypothesis::SaveTo(std::ostream & save) { // We must keep at least the same number of arguments when increasing the SALOME version - // When BLSURF becomes CADMESH, some parameters were fused into a single one. Thus the same + // When MG-CADSurf becomes CADMESH, some parameters were fused into a single one. Thus the same // parameter can be written several times to keep the old global number of parameters. // Treat old options which are now in the advanced options @@ -1382,6 +1461,16 @@ std::ostream & BLSURFPlugin_Hypothesis::SaveTo(std::ostream & save) { save << " " << "__OPTIONS_END__"; } + op_val = _customOption2value.begin(); + if (op_val != _customOption2value.end()) { + save << " " << "__CUSTOM_OPTIONS_BEGIN__"; + for (; op_val != _customOption2value.end(); ++op_val) { + if (!op_val->second.empty()) + save << " " << op_val->first << " " << op_val->second << "%#"; // "%#" is a mark of value end + } + save << " " << "__CUSTOM_OPTIONS_END__"; + } + op_val = _preCADoption2value.begin(); if (op_val != _preCADoption2value.end()) { save << " " << "__PRECAD_OPTIONS_BEGIN__"; @@ -1392,6 +1481,16 @@ std::ostream & BLSURFPlugin_Hypothesis::SaveTo(std::ostream & save) { save << " " << "__PRECAD_OPTIONS_END__"; } + op_val = _customPreCADOption2value.begin(); + if (op_val != _customPreCADOption2value.end()) { + save << " " << "__CUSTOM_PRECAD_OPTIONS_BEGIN__"; + for (; op_val != _customPreCADOption2value.end(); ++op_val) { + if (!op_val->second.empty()) + save << " " << op_val->first << " " << op_val->second << "%#"; // "%#" is a mark of value end + } + save << " " << "__CUSTOM_PRECAD_OPTIONS_END__"; + } + TSizeMap::iterator it_sm = _sizeMap.begin(); if (it_sm != _sizeMap.end()) { save << " " << "__SIZEMAP_BEGIN__"; @@ -1768,7 +1867,9 @@ std::istream & BLSURFPlugin_Hypothesis::LoadFrom(std::istream & load) { bool hasCADSurfOptions = false; bool hasOptions = false; + bool hasCustomOptions = false; bool hasPreCADOptions = false; + bool hasCustomPreCADOptions = false; bool hasSizeMap = false; bool hasAttractor = false; bool hasNewAttractor = false; @@ -1788,8 +1889,12 @@ std::istream & BLSURFPlugin_Hypothesis::LoadFrom(std::istream & load) { } if (option_or_sm == "__OPTIONS_BEGIN__") hasOptions = true; + else if (option_or_sm == "__CUSTOM_OPTIONS_BEGIN__") + hasCustomOptions = true; else if (option_or_sm == "__PRECAD_OPTIONS_BEGIN__") hasPreCADOptions = true; + else if (option_or_sm == "__CUSTOM_PRECAD_OPTIONS_BEGIN__") + hasCustomPreCADOptions = true; else if (option_or_sm == "__SIZEMAP_BEGIN__") hasSizeMap = true; else if (option_or_sm == "__ATTRACTORS_BEGIN__") @@ -1890,8 +1995,12 @@ std::istream & BLSURFPlugin_Hypothesis::LoadFrom(std::istream & load) { if (isOK) if (option_or_sm == "__OPTIONS_BEGIN__") hasOptions = true; + else if (option_or_sm == "__CUSTOM_OPTIONS_BEGIN__") + hasCustomOptions = true; else if (option_or_sm == "__PRECAD_OPTIONS_BEGIN__") hasPreCADOptions = true; + else if (option_or_sm == "__CUSTOM_PRECAD_OPTIONS_BEGIN__") + hasCustomPreCADOptions = true; else if (option_or_sm == "__SIZEMAP_BEGIN__") hasSizeMap = true; else if (option_or_sm == "__ATTRACTORS_BEGIN__") @@ -1940,10 +2049,67 @@ std::istream & BLSURFPlugin_Hypothesis::LoadFrom(std::istream & load) { } if (hasOptions) { + isOK = (load >> option_or_sm); + if (isOK) + if (option_or_sm == "__CUSTOM_OPTIONS_BEGIN__") + hasCustomOptions = true; + else if (option_or_sm == "__PRECAD_OPTIONS_BEGIN__") + hasPreCADOptions = true; + else if (option_or_sm == "__CUSTOM_PRECAD_OPTIONS_BEGIN__") + hasCustomPreCADOptions = true; + else if (option_or_sm == "__SIZEMAP_BEGIN__") + hasSizeMap = true; + else if (option_or_sm == "__ATTRACTORS_BEGIN__") + hasAttractor = true; + else if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__") + hasNewAttractor = true; + else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__") + hasEnforcedVertex = true; + else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__") + hasPreCADFacesPeriodicity = true; + else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__") + hasPreCADEdgesPeriodicity = true; + else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__") + hasFacesPeriodicity = true; + else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__") + hasEdgesPeriodicity = true; + else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__") + hasVerticesPeriodicity = true; + } + + while (isOK && hasCustomOptions) { + isOK = (load >> optName); + if (isOK) { + if (optName == "__CUSTOM_OPTIONS_END__") + break; + isOK = (load >> optValue); + } + if (isOK) { + std::string& value = optValue; + int len = value.size(); + // continue reading until "%#" encountered + while (value[len - 1] != '#' || value[len - 2] != '%') { + isOK = (load >> optValue); + if (isOK) { + value += " "; + value += optValue; + len = value.size(); + } else { + break; + } + } + _customOption2value[optName] = value.substr(0,len-2); + value[len - 2] = '\0'; //cut off "%#" + } + } + + if (hasCustomOptions) { isOK = (load >> option_or_sm); if (isOK) if (option_or_sm == "__PRECAD_OPTIONS_BEGIN__") hasPreCADOptions = true; + else if (option_or_sm == "__CUSTOM_PRECAD_OPTIONS_BEGIN__") + hasCustomPreCADOptions = true; else if (option_or_sm == "__SIZEMAP_BEGIN__") hasSizeMap = true; else if (option_or_sm == "__ATTRACTORS_BEGIN__") @@ -1991,6 +2157,57 @@ std::istream & BLSURFPlugin_Hypothesis::LoadFrom(std::istream & load) { } if (hasPreCADOptions) { + isOK = (load >> option_or_sm); + if (isOK) + if (option_or_sm == "__CUSTOM_PRECAD_OPTIONS_BEGIN__") + hasCustomPreCADOptions = true; + else if (option_or_sm == "__SIZEMAP_BEGIN__") + hasSizeMap = true; + else if (option_or_sm == "__ATTRACTORS_BEGIN__") + hasAttractor = true; + else if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__") + hasNewAttractor = true; + else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__") + hasEnforcedVertex = true; + else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__") + hasPreCADFacesPeriodicity = true; + else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__") + hasPreCADEdgesPeriodicity = true; + else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__") + hasFacesPeriodicity = true; + else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__") + hasEdgesPeriodicity = true; + else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__") + hasVerticesPeriodicity = true; + } + + while (isOK && hasCustomPreCADOptions) { + isOK = (load >> optName); + if (isOK) { + if (optName == "__CUSTOM_PRECAD_OPTIONS_END__") + break; + isOK = (load >> optValue); + } + if (isOK) { + std::string& value = optValue; + int len = value.size(); + // continue reading until "%#" encountered + while (value[len - 1] != '#' || value[len - 2] != '%') { + isOK = (load >> optValue); + if (isOK) { + value += " "; + value += optValue; + len = value.size(); + } else { + break; + } + } + _customPreCADOption2value[optName] = value.substr(0,len-2); + value[len - 2] = '\0'; //cut off "%#" + } + } + + if (hasCustomPreCADOptions) { isOK = (load >> option_or_sm); if (isOK) if (option_or_sm == "__SIZEMAP_BEGIN__") @@ -2112,7 +2329,7 @@ std::istream & BLSURFPlugin_Hypothesis::LoadFrom(std::istream & load) { double attParams[4]; double step; while (isOK && hasNewAttractor) { - std::cout<<"Load new attractor"<> newAtFaceEntry); if (isOK) { if (newAtFaceEntry == "__NEW_ATTRACTORS_END__") @@ -2128,8 +2345,8 @@ std::istream & BLSURFPlugin_Hypothesis::LoadFrom(std::istream & load) { const TopoDS_Face faceShape = TopoDS::Face(BLSURFPlugin_Hypothesis::entryToShape(newAtFaceEntry)); BLSURFPlugin_Attractor* attractor = new BLSURFPlugin_Attractor(faceShape, attractorShape, newAtShapeEntry);//, step); attractor->SetParameters(attParams[0], attParams[1], attParams[2], attParams[3]); - attractor->BuildMap(); - _classAttractors[newAtFaceEntry]=attractor; + //attractor->BuildMap(); + _classAttractors.insert( make_pair( newAtFaceEntry, attractor )); } }