From: nge Date: Thu, 16 Jul 2009 11:55:57 +0000 (+0000) Subject: * Added RemoveSizeMapVertex(x,y,z) IDL method X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=ff38e444d4b617ccc9c713f3c8ebc027418acfb8;p=plugins%2Fghs3dplugin.git * Added RemoveSizeMapVertex(x,y,z) IDL method * A mesh with Ghs3d and no hypothesis now computes * Table of enforced vertex can now be ordered --- diff --git a/idl/GHS3DPlugin_Algorithm.idl b/idl/GHS3DPlugin_Algorithm.idl index 47f5453..d14d738 100644 --- a/idl/GHS3DPlugin_Algorithm.idl +++ b/idl/GHS3DPlugin_Algorithm.idl @@ -117,6 +117,7 @@ module GHS3DPlugin */ void SetSizeMapVertex(in double x, in double y, in double z, in double size); double GetSizeMapVertex(in double x, in double y, in double z) raises (SALOME::SALOME_Exception); + void RemoveSizeMapVertex(in double x, in double y, in double z) raises (SALOME::SALOME_Exception); GHS3DSizeMapVertexList GetSizeMapVerteces(); void ClearSizeMapVerteces(); }; diff --git a/src/GHS3DPlugin_GHS3D.cxx b/src/GHS3DPlugin_GHS3D.cxx index ddc1e9c..67faa66 100644 --- a/src/GHS3DPlugin_GHS3D.cxx +++ b/src/GHS3DPlugin_GHS3D.cxx @@ -28,9 +28,7 @@ using namespace std; #include "GHS3DPlugin_GHS3D.hxx" #include "GHS3DPlugin_Hypothesis.hxx" -#include -#include -#include + #include "SMESH_Gen.hxx" #include "SMESH_Mesh.hxx" @@ -1062,9 +1060,15 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, } map aSmdsToGhs3dIdMap; map aGhs3dIdToNodeMap; - - GHS3DPlugin_Hypothesis::TSizeMapVertexValues enforcedVerteces = GHS3DPlugin_Hypothesis::GetEnforcedVerteces(_hyp); - int nbEnforcedVerteces = enforcedVerteces.size(); + GHS3DPlugin_Hypothesis::TSizeMapVertexValues enforcedVerteces; + int nbEnforcedVerteces; + try { + enforcedVerteces = GHS3DPlugin_Hypothesis::GetEnforcedVerteces(_hyp); + nbEnforcedVerteces = enforcedVerteces.size(); + } + catch(...) { + nbEnforcedVerteces = 0; + } Ok = writePoints( aPointsFile, meshDS, aSmdsToGhs3dIdMap, aGhs3dIdToNodeMap, enforcedVerteces) && writeFaces ( aFacesFile, meshDS, aSmdsToGhs3dIdMap ); @@ -1204,9 +1208,17 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, if (!Ok) return error( SMESH_Comment("Can't write into ") << aPointsFileName); + + GHS3DPlugin_Hypothesis::TSizeMapVertexValues enforcedVerteces; + int nbEnforcedVerteces; + try { + enforcedVerteces = GHS3DPlugin_Hypothesis::GetEnforcedVerteces(_hyp); + nbEnforcedVerteces = enforcedVerteces.size(); + } + catch(...) { + nbEnforcedVerteces = 0; + } - GHS3DPlugin_Hypothesis::TSizeMapVertexValues enforcedVerteces = GHS3DPlugin_Hypothesis::GetEnforcedVerteces(_hyp); - int nbEnforcedVerteces = enforcedVerteces.size(); vector aNodeByGhs3dId; Ok = (writeFaces ( aFacesFile, meshDS, aNodeByGhs3dId ) && diff --git a/src/GHS3DPlugin_Hypothesis.cxx b/src/GHS3DPlugin_Hypothesis.cxx index aadb51c..0095c58 100644 --- a/src/GHS3DPlugin_Hypothesis.cxx +++ b/src/GHS3DPlugin_Hypothesis.cxx @@ -31,21 +31,20 @@ //======================================================================= GHS3DPlugin_Hypothesis::GHS3DPlugin_Hypothesis(int hypId, int studyId, SMESH_Gen * gen) - : SMESH_Hypothesis(hypId, studyId, gen) + : SMESH_Hypothesis(hypId, studyId, gen), + myToMeshHoles(DefaultMeshHoles()), + myMaximumMemory(-1), + myInitialMemory(-1), + myOptimizationLevel(DefaultOptimizationLevel()), + myWorkingDirectory(DefaultWorkingDirectory()), + myKeepFiles(DefaultKeepFiles()), + myVerboseLevel(DefaultVerboseLevel()), + myToCreateNewNodes(DefaultToCreateNewNodes()), + myToUseBoundaryRecoveryVersion(DefaultToUseBoundaryRecoveryVersion()), + mySizeMapVerteces(DefaultSizeMapVerteces()) { _name = "GHS3D_Parameters"; _param_algo_dim = 3; - - myToMeshHoles = DefaultMeshHoles(); - myMaximumMemory = -1;//DefaultMaximumMemory(); - myInitialMemory = -1;//DefaultInitialMemory(); - myOptimizationLevel = DefaultOptimizationLevel(); - myWorkingDirectory = DefaultWorkingDirectory(); - myKeepFiles = DefaultKeepFiles(); - myVerboseLevel = DefaultVerboseLevel(); - myToCreateNewNodes = DefaultToCreateNewNodes(); - myToUseBoundaryRecoveryVersion = DefaultToUseBoundaryRecoveryVersion(); - mySizeMapVerteces = DefaultSizeMapVerteces(); } //======================================================================= @@ -272,13 +271,21 @@ string GHS3DPlugin_Hypothesis::GetTextOption() const void GHS3DPlugin_Hypothesis::SetSizeMapVertex(double x, double y, double z, double size) { std::cout << "GHS3DPlugin_Hypothesis::SetSizeMapVertex(x,y,z,size)" << std::endl; -// std::vector coord (x,y,z); - GHS3DSizeMapVertex* coord = new GHS3DSizeMapVertex; - coord->x = x; - coord->y = y; - coord->z = z; -// double coord[] = {x,y,z}; - mySizeMapVerteces[coord] = size; + bool found = false; + TSizeMapVertexValues::iterator it; + for (it = mySizeMapVerteces.begin() ; it != mySizeMapVerteces.end() ; ++it) + if ((it->first->x == x) and (it->first->y == y) and (it->first->z == z)) { + it->second = size; + found = true; + break; + } + if (not found) { + GHS3DSizeMapVertex* coord = new GHS3DSizeMapVertex; + coord->x = x; + coord->y = y; + coord->z = z; + mySizeMapVerteces[coord] = size; + } NotifySubMeshesHypothesisModification(); } @@ -302,6 +309,31 @@ double GHS3DPlugin_Hypothesis::GetSizeMapVertex(double x, double y, double z) throw std::invalid_argument(msg.str()); } +//======================================================================= +//function : RemoveSizeMapVertex +//======================================================================= + +void GHS3DPlugin_Hypothesis::RemoveSizeMapVertex(double x, double y, double z) + throw (std::invalid_argument) +{ + TSizeMapVertexValues::const_iterator it; + bool found = false; + for (it = mySizeMapVerteces.begin() ; it != mySizeMapVerteces.end() ; ++it) + if ((it->first->x == x) and (it->first->y == y) and (it->first->z == z)) { + found = true; + break; + } + if (found) { + mySizeMapVerteces.erase(it->first); + NotifySubMeshesHypothesisModification(); + } + else { + ostringstream msg ; + msg << "No enforced vertex at " << x << ", " << y << ", " << z; + throw std::invalid_argument(msg.str()); + } +} + //======================================================================= //function : ClearSizeMapVerteces //======================================================================= @@ -438,8 +470,7 @@ bool GHS3DPlugin_Hypothesis::DefaultToUseBoundaryRecoveryVersion() GHS3DPlugin_Hypothesis::TSizeMapVertexValues GHS3DPlugin_Hypothesis::DefaultSizeMapVerteces() { std::cout << "GHS3DPlugin_Hypothesis::DefaultSizeMapVerteces()" << std::endl; - GHS3DPlugin_Hypothesis::TSizeMapVertexValues myVerteces; - return myVerteces; + return GHS3DPlugin_Hypothesis::TSizeMapVertexValues(); } @@ -715,6 +746,6 @@ string GHS3DPlugin_Hypothesis::GetFileName(const GHS3DPlugin_Hypothesis* hyp) GHS3DPlugin_Hypothesis::TSizeMapVertexValues GHS3DPlugin_Hypothesis::GetEnforcedVerteces(const GHS3DPlugin_Hypothesis* hyp) { - return hyp->GetSizeMapVerteces(); + return hyp ? hyp->GetSizeMapVerteces():DefaultSizeMapVerteces(); } diff --git a/src/GHS3DPlugin_Hypothesis.hxx b/src/GHS3DPlugin_Hypothesis.hxx index 683402f..f4317ff 100644 --- a/src/GHS3DPlugin_Hypothesis.hxx +++ b/src/GHS3DPlugin_Hypothesis.hxx @@ -111,6 +111,7 @@ public: typedef std::map TSizeMapVertexValues; void SetSizeMapVertex(double x, double y, double z, double size); double GetSizeMapVertex(double x, double y, double z) throw (std::invalid_argument); + void RemoveSizeMapVertex(double x, double y, double z) throw (std::invalid_argument); const TSizeMapVertexValues GetSizeMapVerteces() const { return mySizeMapVerteces; } void ClearSizeMapVerteces(); diff --git a/src/GHS3DPlugin_Hypothesis_i.cxx b/src/GHS3DPlugin_Hypothesis_i.cxx index 742fe08..4b3f278 100644 --- a/src/GHS3DPlugin_Hypothesis_i.cxx +++ b/src/GHS3DPlugin_Hypothesis_i.cxx @@ -342,7 +342,7 @@ GHS3DPlugin::GHS3DSizeMapVertexList* GHS3DPlugin_Hypothesis_i::GetSizeMapVertece const ::GHS3DPlugin_Hypothesis::TSizeMapVertexValues sizeMaps = this->GetImpl()->GetSizeMapVerteces(); int size = sizeMaps.size(); - std::cout << "size: " << size << std::endl; +// std::cout << "size: " << size << std::endl; result->length( size ); ::GHS3DPlugin_Hypothesis::TSizeMapVertexValues::const_iterator it; @@ -360,6 +360,31 @@ GHS3DPlugin::GHS3DSizeMapVertexList* GHS3DPlugin_Hypothesis_i::GetSizeMapVertece return result._retn(); } +//======================================================================= +//function : RemoveSizeMapVertex +//======================================================================= + +void GHS3DPlugin_Hypothesis_i::RemoveSizeMapVertex(CORBA::Double x, CORBA::Double y, CORBA::Double z) + throw (SALOME::SALOME_Exception) +{ + ASSERT(myBaseImpl); + try { + this->GetImpl()->RemoveSizeMapVertex(x,y,z); + SMESH::TPythonDump() << _this() << ".RemoveSizeMapVertex( " << x << ", " << y << ", " << z << " )"; + } + catch (const std::invalid_argument& ex) { + SALOME::ExceptionStruct ExDescription; + ExDescription.text = ex.what(); + ExDescription.type = SALOME::BAD_PARAM; + ExDescription.sourceFile = "GHS3DPlugin_Hypothesis::RemoveSizeMapVertex(x,y,z)"; + ExDescription.lineNumber = 0; + throw SALOME::SALOME_Exception(ExDescription); + } + catch (SALOME_Exception& ex) { + THROW_SALOME_CORBA_EXCEPTION( ex.what() ,SALOME::BAD_PARAM ); + } +} + //======================================================================= //function : ClearSizeMapVerteces //======================================================================= diff --git a/src/GHS3DPlugin_Hypothesis_i.hxx b/src/GHS3DPlugin_Hypothesis_i.hxx index 4917da4..ab5a079 100644 --- a/src/GHS3DPlugin_Hypothesis_i.hxx +++ b/src/GHS3DPlugin_Hypothesis_i.hxx @@ -112,6 +112,7 @@ class GHS3DPLUGIN_EXPORT GHS3DPlugin_Hypothesis_i: */ void SetSizeMapVertex(CORBA::Double x, CORBA::Double y, CORBA::Double z, CORBA::Double size); CORBA::Double GetSizeMapVertex(CORBA::Double x, CORBA::Double y, CORBA::Double z) throw (SALOME::SALOME_Exception); + void RemoveSizeMapVertex(CORBA::Double x, CORBA::Double y, CORBA::Double z) throw (SALOME::SALOME_Exception); GHS3DPlugin::GHS3DSizeMapVertexList* GetSizeMapVerteces(); void ClearSizeMapVerteces(); diff --git a/src/GUI/GHS3DPluginGUI_HypothesisCreator.cxx b/src/GUI/GHS3DPluginGUI_HypothesisCreator.cxx index b88a820..43672c4 100644 --- a/src/GUI/GHS3DPluginGUI_HypothesisCreator.cxx +++ b/src/GUI/GHS3DPluginGUI_HypothesisCreator.cxx @@ -280,6 +280,7 @@ QFrame* GHS3DPluginGUI_HypothesisCreator::buildFrame() mySmpModel = new QStandardItemModel(0, SMP_NB_COLUMNS); mySizeMapTableView = new QTableView(mySmpGroup); mySizeMapTableView->setModel(mySmpModel); + mySizeMapTableView->setSortingEnabled(true); mySizeMapTableView->setItemDelegateForColumn(SMP_SIZE_COLUMN,new DoubleLineEditDelegate(this)); anSmpLayout->addWidget(mySizeMapTableView, 1, 0, 9, 1); QStringList sizeMapHeaders; @@ -382,14 +383,14 @@ void GHS3DPluginGUI_HypothesisCreator::onVertexBtnClicked() mySmpModel->setData(mySmpModel->index(row, SMP_SIZE_COLUMN),size); mySmpModel->setItem( row, SMP_SIZE_COLUMN, new QStandardItem(QString::number(size,'f')) ); - std::cout << "mySmpModel->data(mySmpModel->index("<data(mySmpModel->index(row,SMP_X_COLUMN)).toDouble() << std::endl; - std::cout << "mySmpModel->data(mySmpModel->index("<data(mySmpModel->index(row,SMP_Y_COLUMN)).toDouble() << std::endl; - std::cout << "mySmpModel->data(mySmpModel->index("<data(mySmpModel->index(row,SMP_Z_COLUMN)).toDouble() << std::endl; - std::cout << "mySmpModel->data(mySmpModel->index("<data(mySmpModel->index(row,SMP_SIZE_COLUMN)).toDouble() << std::endl; +// std::cout << "mySmpModel->data(mySmpModel->index("<data(mySmpModel->index(row,SMP_X_COLUMN)).toDouble() << std::endl; +// std::cout << "mySmpModel->data(mySmpModel->index("<data(mySmpModel->index(row,SMP_Y_COLUMN)).toDouble() << std::endl; +// std::cout << "mySmpModel->data(mySmpModel->index("<data(mySmpModel->index(row,SMP_Z_COLUMN)).toDouble() << std::endl; +// std::cout << "mySmpModel->data(mySmpModel->index("<data(mySmpModel->index(row,SMP_SIZE_COLUMN)).toDouble() << std::endl; mySizeMapTableView->clearSelection(); mySizeMapTableView->scrollTo( mySmpModel->item( row, SMP_SIZE_COLUMN )->index() ); @@ -470,10 +471,10 @@ void GHS3DPluginGUI_HypothesisCreator::retrieveParams() const int row = 0; for(it = data.mySizeMapVerteces.begin() ; it != data.mySizeMapVerteces.end(); it++ ) { - double x = (*it).first->x; - double y = (*it).first->y; - double z = (*it).first->z; - double size = (*it).second; + double x = it->first->x; + double y = it->first->y; + double z = it->first->z; + double size = it->second; // SMP_X_COLUMN mySmpModel->setData(mySmpModel->index(row, SMP_X_COLUMN),x); mySmpModel->setItem( row, SMP_X_COLUMN, new QStandardItem(QString::number(x)) ); @@ -611,13 +612,40 @@ bool GHS3DPluginGUI_HypothesisCreator::storeParamsToHypo( const GHS3DHypothesisD h->SetToUseBoundaryRecoveryVersion( h_data.myBoundaryRecovery ); if ( h->GetTextOption() != h_data.myTextOption ) h->SetTextOption ( h_data.myTextOption.toLatin1().constData() ); - std::cout << "Store params for size maps: " << (int) h_data.mySizeMapVerteces.size() << " enforced verteces" << std::endl; + + int nbVertex = (int) h_data.mySizeMapVerteces.size(); + GHS3DPlugin::GHS3DSizeMapVertexList_var vertexHyp = h->GetSizeMapVerteces(); + int nbVertexHyp = vertexHyp->length(); + + std::cout << "Store params for size maps: " << nbVertex << " enforced verteces" << std::endl; + std::cout << "h->GetSizeMapVerteces()->length(): " << nbVertexHyp << std::endl; + + // Some verteces were removed + if (nbVertex < nbVertexHyp) { + if (nbVertex == 0) + h->ClearSizeMapVerteces(); + else { + // iterate over verteces of hypo +// GHS3DPlugin_Hypothesis::TSizeMapVertexValues::const_iterator vertexHypIt; + for(int i = 0 ; i RemoveSizeMapVertex(x,y,z); + } + } + } + +// if ((int) h_data.mySizeMapVerteces.size() == 0) +// if (h->GetSizeMapVerteces()->length() > 0) +// h->ClearSizeMapVerteces(); +// else +// h->ClearSizeMapVerteces(); + TSizeMapVertexValues::const_iterator it; - if (h_data.mySizeMapVerteces.size() == 0) - if (h->GetSizeMapVerteces()->length() > 0) - h->ClearSizeMapVerteces(); - else - h->ClearSizeMapVerteces(); for(it = h_data.mySizeMapVerteces.begin() ; it != h_data.mySizeMapVerteces.end(); it++ ) { double x = it->first->x; double y = it->first->y;