From 7930a1ba1664002df8af03386b0518fa85271d94 Mon Sep 17 00:00:00 2001 From: nge Date: Thu, 11 Jun 2009 14:40:44 +0000 Subject: [PATCH] First draft * Some bug when editing hypothesis * Storage not done --- idl/GHS3DPlugin_Algorithm.idl | 15 + src/GHS3DPlugin_GHS3D.cxx | 127 ++++++-- src/GHS3DPlugin_Hypothesis.cxx | 94 +++++- src/GHS3DPlugin_Hypothesis.hxx | 26 +- src/GHS3DPlugin_Hypothesis_i.cxx | 77 +++++ src/GHS3DPlugin_Hypothesis_i.hxx | 7 + src/GUI/GHS3DPluginGUI_HypothesisCreator.cxx | 302 ++++++++++++++++++- src/GUI/GHS3DPluginGUI_HypothesisCreator.h | 52 ++++ src/GUI/GHS3DPlugin_msg_en.ts | 40 +++ src/GUI/Makefile.am | 4 +- 10 files changed, 716 insertions(+), 28 deletions(-) diff --git a/idl/GHS3DPlugin_Algorithm.idl b/idl/GHS3DPlugin_Algorithm.idl index a402d78..47f5453 100644 --- a/idl/GHS3DPlugin_Algorithm.idl +++ b/idl/GHS3DPlugin_Algorithm.idl @@ -31,6 +31,14 @@ */ module GHS3DPlugin { + struct GHS3DSizeMapVertex { + double x; + double y; + double z; + double size; + }; + + typedef sequence GHS3DSizeMapVertexList; /*! * GHS3DPlugin_GHS3D: interface of "Tetrahedron (GHS3D)" algorithm */ @@ -104,6 +112,13 @@ module GHS3DPlugin */ void SetTextOption(in string option); string GetTextOption(); + /*! + * To set an enforced vertex + */ + 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); + GHS3DSizeMapVertexList GetSizeMapVerteces(); + void ClearSizeMapVerteces(); }; }; diff --git a/src/GHS3DPlugin_GHS3D.cxx b/src/GHS3DPlugin_GHS3D.cxx index 195de5c..9506322 100644 --- a/src/GHS3DPlugin_GHS3D.cxx +++ b/src/GHS3DPlugin_GHS3D.cxx @@ -393,52 +393,105 @@ static bool writeFaces (ofstream & theFile, //purpose : //======================================================================= -static bool writePoints (ofstream & theFile, - SMESHDS_Mesh * theMesh, - map & theSmdsToGhs3dIdMap, - map & theGhs3dIdToNodeMap) +static bool writePoints (ofstream & theFile, + SMESHDS_Mesh * theMesh, + map & theSmdsToGhs3dIdMap, + map & theGhs3dIdToNodeMap, + GHS3DPlugin_Hypothesis::TSizeMapVertexValues & theEnforcedVerteces) { // record structure: // // NB_NODES // Loop from 1 to NB_NODES // X Y Z DUMMY_INT + + // Iterate over the enforced verteces + map theEnforcedNodesIdSizeMap; + double x,y,z,size; + const SMDS_MeshNode* node; + int nodeId; + + GHS3DPlugin_Hypothesis::TSizeMapVertexValues::const_iterator vertexIt; + for(vertexIt = theEnforcedVerteces.begin() ; vertexIt != theEnforcedVerteces.end() ; ++vertexIt) { + x = vertexIt->first->x; + y = vertexIt->first->y; + z = vertexIt->first->z; + size = vertexIt->second; + node = theMesh->AddNode( x,y,z ); + theEnforcedNodesIdSizeMap.insert( make_pair( node->GetID(), size)); + std::cout << "Creating node at " << node->X() << "," << node->Y() <<"," << node-> Z() << std::endl; + } int nbNodes = theMesh->NbNodes(); if ( nbNodes == 0 ) return false; + int nbEnforcedVerteces = theEnforcedVerteces.size(); + const char* space = " "; const int dummyint = 0; int aGhs3dID = 1; SMDS_NodeIteratorPtr it = theMesh->nodesIterator(); - const SMDS_MeshNode* node; +// const SMDS_MeshNode* node; // NB_NODES - theFile << space << nbNodes << endl; - cout << endl; - cout << "The initial 2D mesh contains :" << endl; - cout << " " << nbNodes << " vertices" << endl; + std::cout << std::endl; + std::cout << "The initial 2D mesh contains :" << std::endl; + std::cout << " " << nbNodes << " nodes" << std::endl; + std::cout << " " << nbEnforcedVerteces << " enforced vertices" << std::endl; + std::cout << std::endl; + std::cout << "Start writing in 'points' file ..." << std::endl; + theFile << space << nbNodes - nbEnforcedVerteces << std::endl; // Loop from 1 to NB_NODES while ( it->more() ) { node = it->next(); - theSmdsToGhs3dIdMap.insert( make_pair( node->GetID(), aGhs3dID )); - theGhs3dIdToNodeMap.insert( make_pair( aGhs3dID, node )); + if (theEnforcedNodesIdSizeMap.find(node->GetID()) == theEnforcedNodesIdSizeMap.end()) { + theSmdsToGhs3dIdMap.insert( make_pair( node->GetID(), aGhs3dID )); + theGhs3dIdToNodeMap.insert( make_pair( aGhs3dID, node )); + aGhs3dID++; + + // X Y Z DUMMY_INT + theFile + << space << node->X() + << space << node->Y() + << space << node->Z() + << space << dummyint; + + theFile << endl; + } + else { + std::cout << "While iterating in nodes, do not add node (" << node->X() << "," << node->Y() <<"," << node-> Z() << ")" << std::endl; + } + } + + // Iterate over the enforced verteces + map ::const_iterator theEnforcedNodesIdSizeMapIt; + + for(theEnforcedNodesIdSizeMapIt = theEnforcedNodesIdSizeMap.begin() ; + theEnforcedNodesIdSizeMapIt != theEnforcedNodesIdSizeMap.end() ; ++theEnforcedNodesIdSizeMapIt) { + nodeId = theEnforcedNodesIdSizeMapIt->first; + node = theMesh->FindNode(nodeId); + size = theEnforcedNodesIdSizeMapIt->second; + theSmdsToGhs3dIdMap.insert(theSmdsToGhs3dIdMap.end(), make_pair( nodeId, aGhs3dID )); + theGhs3dIdToNodeMap.insert(theGhs3dIdToNodeMap.end(), make_pair( aGhs3dID, node )); aGhs3dID++; - // X Y Z DUMMY_INT + // X Y Z PHY_SIZE DUMMY_INT theFile - << space << node->X() - << space << node->Y() - << space << node->Z() - << space << dummyint; + << space << node->X() + << space << node->Y() + << space << node->Z() + << space << size + << space << dummyint; theFile << endl; } + cout << endl; + cout << "End writing in 'points' file." << endl; return true; } @@ -448,9 +501,10 @@ static bool writePoints (ofstream & theFile, //purpose : //======================================================================= -static bool writePoints (ofstream & theFile, - SMESHDS_Mesh * theMesh, - const vector & theNodeByGhs3dId) +static bool writePoints (ofstream & theFile, + SMESHDS_Mesh * theMesh, + const vector & theNodeByGhs3dId, + GHS3DPlugin_Hypothesis::TSizeMapVertexValues & theEnforcedVerteces) { // record structure: // @@ -463,6 +517,8 @@ static bool writePoints (ofstream & theFile, if ( nbNodes == 0 ) return false; + int nbEnforcedVerteces = theEnforcedVerteces.size(); + const char* space = " "; const int dummyint = 0; @@ -470,7 +526,10 @@ static bool writePoints (ofstream & theFile, // NB_NODES theFile << space << nbNodes << endl; - cout << nbNodes << " nodes" << endl; + cout << endl; + cout << "The initial 2D mesh contains :" << endl; + cout << " " << nbNodes << " nodes" << endl; + cout << " " << nbEnforcedVerteces << " enforced vertices" << endl; // Loop from 1 to NB_NODES @@ -489,6 +548,25 @@ static bool writePoints (ofstream & theFile, theFile << endl; } + + GHS3DPlugin_Hypothesis::TSizeMapVertexValues::const_iterator it; + for(it = theEnforcedVerteces.begin() ; it != theEnforcedVerteces.end() ; ++it) { + double x = it->first->x; + double y = it->first->y; + double z = it->first->z; + double size = it->second; + SMDS_MeshNode* myNode = theMesh->AddNode( x,y,z ); + + // X Y Z PHY_SIZE DUMMY_INT + theFile + << space << myNode->X() + << space << myNode->Y() + << space << myNode->Z() + << space << size + << space << dummyint; + + theFile << endl; + } return true; } @@ -989,8 +1067,10 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, } map aSmdsToGhs3dIdMap; map aGhs3dIdToNodeMap; - - Ok = writePoints( aPointsFile, meshDS, aSmdsToGhs3dIdMap, aGhs3dIdToNodeMap ) && + + GHS3DPlugin_Hypothesis::TSizeMapVertexValues enforcedVerteces = GHS3DPlugin_Hypothesis::GetEnforcedVerteces(_hyp); + + Ok = writePoints( aPointsFile, meshDS, aSmdsToGhs3dIdMap, aGhs3dIdToNodeMap, enforcedVerteces) && writeFaces ( aFacesFile, meshDS, aSmdsToGhs3dIdMap ); aFacesFile.close(); @@ -1129,10 +1209,11 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, if (!Ok) return error( SMESH_Comment("Can't write into ") << aPointsFileName); + GHS3DPlugin_Hypothesis::TSizeMapVertexValues enforcedVerteces = GHS3DPlugin_Hypothesis::GetEnforcedVerteces(_hyp); vector aNodeByGhs3dId; Ok = (writeFaces ( aFacesFile, meshDS, aNodeByGhs3dId ) && - writePoints( aPointsFile, meshDS, aNodeByGhs3dId)); + writePoints( aPointsFile, meshDS, aNodeByGhs3dId,enforcedVerteces)); aFacesFile.close(); aPointsFile.close(); diff --git a/src/GHS3DPlugin_Hypothesis.cxx b/src/GHS3DPlugin_Hypothesis.cxx index 3a29541..97af83e 100644 --- a/src/GHS3DPlugin_Hypothesis.cxx +++ b/src/GHS3DPlugin_Hypothesis.cxx @@ -45,6 +45,7 @@ GHS3DPlugin_Hypothesis::GHS3DPlugin_Hypothesis(int hypId, int studyId, SMESH_Gen myVerboseLevel = DefaultVerboseLevel(); myToCreateNewNodes = DefaultToCreateNewNodes(); myToUseBoundaryRecoveryVersion = DefaultToUseBoundaryRecoveryVersion(); + mySizeMapVerteces = DefaultSizeMapVerteces(); } //======================================================================= @@ -264,6 +265,51 @@ string GHS3DPlugin_Hypothesis::GetTextOption() const return myTextOption; } +//======================================================================= +//function : SetSizeMapVertex +//======================================================================= + +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; + NotifySubMeshesHypothesisModification(); +} + +//======================================================================= +//function : GetSizeMapVertex +//======================================================================= + +double GHS3DPlugin_Hypothesis::GetSizeMapVertex(double x, double y, double z) + throw (std::invalid_argument) +{ +// double coord[] = {x,y,z}; + TSizeMapVertexValues::const_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)) + return it->second; + } +// if (mySizeMapVerteces.count(coord)>0) +// return mySizeMapVerteces[coord]; + ostringstream msg ; + msg << "No enforced vertex at " << x << ", " << y << ", " << z; + throw std::invalid_argument(msg.str()); +} + +//======================================================================= +//function : ClearSizeMapVerteces +//======================================================================= +void GHS3DPlugin_Hypothesis::ClearSizeMapVerteces() +{ + mySizeMapVerteces.clear(); +// mySizeMapVerteces = DefaultSizeMapVerteces(); +} //======================================================================= //function : DefaultMeshHoles @@ -280,6 +326,8 @@ bool GHS3DPlugin_Hypothesis::DefaultMeshHoles() #ifndef WIN32 #include +#else +#include #endif short GHS3DPlugin_Hypothesis::DefaultMaximumMemory() @@ -289,7 +337,19 @@ short GHS3DPlugin_Hypothesis::DefaultMaximumMemory() int err = sysinfo( &si ); if ( err == 0 ) { int ramMB = si.totalram * si.mem_unit / 1024 / 1024; - return (short) ( 0.7 * ramMB ); + return (int) ( 0.7 * ramMB ); + } +#else + // See http://msdn.microsoft.com/en-us/library/aa366589.aspx + MEMORYSTATUSEX statex; + statex.dwLength = sizeof (statex); + int err = GlobalMemoryStatusEx (&statex); + if (err != 0) { + int totMB = + statex.ullTotalPhys / 1024 / 1024 + + statex.ullTotalPageFile / 1024 / 1024 + + statex.ullTotalVirtual / 1024 / 1024; + return (int) ( 0.7 * totMB ); } #endif return -1; @@ -371,6 +431,18 @@ bool GHS3DPlugin_Hypothesis::DefaultToUseBoundaryRecoveryVersion() return false; } +//======================================================================= +//function : DefaultSizeMapVerteces +//======================================================================= + +GHS3DPlugin_Hypothesis::TSizeMapVertexValues GHS3DPlugin_Hypothesis::DefaultSizeMapVerteces() +{ + std::cout << "GHS3DPlugin_Hypothesis::DefaultSizeMapVerteces()" << std::endl; + GHS3DPlugin_Hypothesis::TSizeMapVertexValues myVerteces; + return myVerteces; +} + + //======================================================================= //function : SaveTo //======================================================================= @@ -387,6 +459,13 @@ ostream & GHS3DPlugin_Hypothesis::SaveTo(ostream & save) save << (int)myToCreateNewNodes << " "; save << (int)myToUseBoundaryRecoveryVersion << " "; save << myTextOption << " "; + +// if (mySizeMapVerteces.size() >= 4) { +// save << "__SIZEMAP_BEGIN__" << " "; +// for (int i=0 ; iGetSizeMapVerteces(); +} + diff --git a/src/GHS3DPlugin_Hypothesis.hxx b/src/GHS3DPlugin_Hypothesis.hxx index 1c59739..f9cdca6 100644 --- a/src/GHS3DPlugin_Hypothesis.hxx +++ b/src/GHS3DPlugin_Hypothesis.hxx @@ -27,7 +27,9 @@ #include "GHS3DPlugin_Defs.hxx" #include - +#include +#include +#include using namespace std; class GHS3DPLUGIN_EXPORT GHS3DPlugin_Hypothesis: public SMESH_Hypothesis @@ -96,6 +98,22 @@ public: */ void SetTextOption(const string& option); string GetTextOption() const; + /*! + * To set an enforced vertex + */ + typedef struct + { + double x; + double y; + double z; + } GHS3DSizeMapVertex; + + typedef std::map TSizeMapVertexValues; +// 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); + const TSizeMapVertexValues GetSizeMapVerteces() const { return mySizeMapVerteces; } + void ClearSizeMapVerteces(); static bool DefaultMeshHoles(); static short DefaultMaximumMemory(); @@ -106,6 +124,7 @@ public: static short DefaultVerboseLevel(); static bool DefaultToCreateNewNodes(); static bool DefaultToUseBoundaryRecoveryVersion(); + static TSizeMapVertexValues DefaultSizeMapVerteces(); /*! * \brief Return command to run ghs3d mesher excluding file prefix (-f) @@ -116,6 +135,10 @@ public: * \brief Return a unique file name */ static std::string GetFileName(const GHS3DPlugin_Hypothesis* hyp); + /*! + * \brief Return the enforced verteces + */ + static TSizeMapVertexValues GetEnforcedVerteces(const GHS3DPlugin_Hypothesis* hyp); // Persistence virtual ostream & SaveTo(ostream & save); @@ -145,6 +168,7 @@ private: bool myToCreateNewNodes; bool myToUseBoundaryRecoveryVersion; string myTextOption; + TSizeMapVertexValues mySizeMapVerteces; }; diff --git a/src/GHS3DPlugin_Hypothesis_i.cxx b/src/GHS3DPlugin_Hypothesis_i.cxx index 3cec323..742fe08 100644 --- a/src/GHS3DPlugin_Hypothesis_i.cxx +++ b/src/GHS3DPlugin_Hypothesis_i.cxx @@ -294,6 +294,83 @@ char* GHS3DPlugin_Hypothesis_i::GetTextOption() return CORBA::string_dup( this->GetImpl()->GetTextOption().c_str() ); } +//======================================================================= +//function : SetSizeMapVertex +//======================================================================= + +void GHS3DPlugin_Hypothesis_i::SetSizeMapVertex(CORBA::Double x, CORBA::Double y, CORBA::Double z, CORBA::Double size) +{ + ASSERT(myBaseImpl); + this->GetImpl()->SetSizeMapVertex(x,y,z,size); + SMESH::TPythonDump() << _this() << ".SetSizeMapVertex( " << x << ", " << y << ", " << z << ", " << size << " )"; +} + +//======================================================================= +//function : SetSizeMapVertex +//======================================================================= + +CORBA::Double GHS3DPlugin_Hypothesis_i::GetSizeMapVertex(CORBA::Double x, CORBA::Double y, CORBA::Double z) + throw (SALOME::SALOME_Exception) +{ + ASSERT(myBaseImpl); + try { + return this->GetImpl()->GetSizeMapVertex(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::GetSizeMapVertex(x,y,z)"; + ExDescription.lineNumber = 0; + throw SALOME::SALOME_Exception(ExDescription); + } + catch (SALOME_Exception& ex) { + THROW_SALOME_CORBA_EXCEPTION( ex.what() ,SALOME::BAD_PARAM ); + } + return 0; +} + +//======================================================================= +//function : GetSizeMapVerteces +//======================================================================= + +GHS3DPlugin::GHS3DSizeMapVertexList* GHS3DPlugin_Hypothesis_i::GetSizeMapVerteces() +{ + std::cout << "GHS3DPlugin_Hypothesis_i::GetSizeMapVerteces()" << std::endl; + ASSERT(myBaseImpl); + GHS3DPlugin::GHS3DSizeMapVertexList_var result = new GHS3DPlugin::GHS3DSizeMapVertexList(); + + const ::GHS3DPlugin_Hypothesis::TSizeMapVertexValues sizeMaps = this->GetImpl()->GetSizeMapVerteces(); + int size = sizeMaps.size(); + std::cout << "size: " << size << std::endl; + result->length( size ); + + ::GHS3DPlugin_Hypothesis::TSizeMapVertexValues::const_iterator it; + int i = 0; + for (it = sizeMaps.begin() ; it != sizeMaps.end(); it++ ) { + GHS3DPlugin::GHS3DSizeMapVertex_var myVertex = new GHS3DPlugin::GHS3DSizeMapVertex(); + myVertex->x = it->first->x; + myVertex->y = it->first->y; + myVertex->z = it->first->z; + myVertex->size = it->second; + result[i]=myVertex; + i++; + } + + return result._retn(); +} + +//======================================================================= +//function : ClearSizeMapVerteces +//======================================================================= + +void GHS3DPlugin_Hypothesis_i::ClearSizeMapVerteces() +{ + std::cout << "GHS3DPlugin_Hypothesis_i::ClearSizeMapVerteces()" << std::endl; + ASSERT(myBaseImpl); + this->GetImpl()->ClearSizeMapVerteces(); +} + //============================================================================= /*! * Get implementation diff --git a/src/GHS3DPlugin_Hypothesis_i.hxx b/src/GHS3DPlugin_Hypothesis_i.hxx index 60704e4..4917da4 100644 --- a/src/GHS3DPlugin_Hypothesis_i.hxx +++ b/src/GHS3DPlugin_Hypothesis_i.hxx @@ -107,6 +107,13 @@ class GHS3DPLUGIN_EXPORT GHS3DPlugin_Hypothesis_i: */ void SetTextOption(const char* option); char* GetTextOption(); + /*! + * To set an enforced vertex + */ + 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); + GHS3DPlugin::GHS3DSizeMapVertexList* GetSizeMapVerteces(); + void ClearSizeMapVerteces(); // Get implementation ::GHS3DPlugin_Hypothesis* GetImpl(); diff --git a/src/GUI/GHS3DPluginGUI_HypothesisCreator.cxx b/src/GUI/GHS3DPluginGUI_HypothesisCreator.cxx index 411036e..05ed3dd 100644 --- a/src/GUI/GHS3DPluginGUI_HypothesisCreator.cxx +++ b/src/GUI/GHS3DPluginGUI_HypothesisCreator.cxx @@ -47,15 +47,42 @@ #include #include +#include +#include +#include +#include +#include + +#include + enum { STD_TAB = 0, - ADV_TAB + ADV_TAB, + SMP_TAB, + SMP_X_COLUMN = 0, + SMP_Y_COLUMN, + SMP_Z_COLUMN, + SMP_SIZE_COLUMN, + SMP_NB_COLUMNS +}; + +enum { + SMP_COORDS = 0, + SMP_BTNS = 0, + SMP_X_COORD, + SMP_Y_COORD, + SMP_Z_COORD, + SMP_VERTEX_BTN, + SMP_SEPARATOR, + SMP_REMOVE_BTN, }; namespace { #ifndef WIN32 #include +#else +#include #endif int maxAvailableMemory() @@ -69,11 +96,68 @@ namespace { si.totalswap * si.mem_unit / 1024 / 1024 ; return (int) ( 0.7 * totMB ); } +#else +// See http://msdn.microsoft.com/en-us/library/aa366589.aspx + MEMORYSTATUSEX statex; + statex.dwLength = sizeof (statex); + int err = GlobalMemoryStatusEx (&statex); + if (err != 0) { + int totMB = + statex.ullTotalPhys / 1024 / 1024 + + statex.ullTotalPageFile / 1024 / 1024 + + statex.ullTotalVirtual / 1024 / 1024; + return (int) ( 0.7 * totMB ); + } #endif return 100000; } } +DoubleLineEditDelegate::DoubleLineEditDelegate(QObject *parent) + : QItemDelegate(parent) +{ +} + +QWidget *DoubleLineEditDelegate::createEditor(QWidget *parent, + const QStyleOptionViewItem &/* option */, + const QModelIndex &/* index */) const +{ + QLineEdit *editor = new QLineEdit(parent); + editor->setValidator(new QDoubleValidator(parent)); + + return editor; +} + +void DoubleLineEditDelegate::setEditorData(QWidget *editor, + const QModelIndex &index) const +{ + QString value = index.model()->data(index, Qt::EditRole).toString(); + + QLineEdit *lineEdit = static_cast(editor); + lineEdit->setText(value); +} + +void DoubleLineEditDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, + const QModelIndex &index) const +{ + QLineEdit *lineEdit = static_cast(editor); + bool ok; + double value = lineEdit->text().toDouble(&ok); + + if (ok) { + model->setData(index, value, Qt::EditRole); + std::cout << "Value " << value << " was set at index(" << index.row() << "," << index.column() << ")" << std::endl; + std::cout << "model->data(index).toDouble(): " << model->data(index).toDouble() << std::endl; + } +} + +void DoubleLineEditDelegate::updateEditorGeometry(QWidget *editor, + const QStyleOptionViewItem &option, const QModelIndex &/* index */) const +{ + editor->setGeometry(option.rect); +} + + GHS3DPluginGUI_HypothesisCreator::GHS3DPluginGUI_HypothesisCreator( const QString& theHypType ) : SMESHGUI_GenericHypothesisCreator( theHypType ) { @@ -182,9 +266,53 @@ QFrame* GHS3DPluginGUI_HypothesisCreator::buildFrame() anAdvLayout->addWidget( aTextOptionLabel, 7, 0, 1, 1 ); anAdvLayout->addWidget( myTextOption, 7, 1, 1, 2 ); + // Size Maps parameters + mySmpGroup = new QWidget(); + QGridLayout* anSmpLayout = new QGridLayout(mySmpGroup); + + mySmpModel = new QStandardItemModel(0, SMP_NB_COLUMNS); + mySizeMapTableView = new QTableView(mySmpGroup); + mySizeMapTableView->setModel(mySmpModel); + mySizeMapTableView->setItemDelegateForColumn(SMP_SIZE_COLUMN,new DoubleLineEditDelegate(this)); + anSmpLayout->addWidget(mySizeMapTableView, 1, 0, 9, 1); + QStringList sizeMapHeaders; + sizeMapHeaders << tr( "GHS3D_SMP_X_COLUMN" )<< tr( "GHS3D_SMP_Y_COLUMN" ) << tr( "GHS3D_SMP_Z_COLUMN" ) << tr( "GHS3D_SMP_SIZEMAP_COLUMN" ); + mySmpModel->setHorizontalHeaderLabels(sizeMapHeaders); + mySizeMapTableView->setAlternatingRowColors(true); + mySizeMapTableView->verticalHeader()->hide(); + mySizeMapTableView->horizontalHeader()->setResizeMode(QHeaderView::Stretch); + + QLabel* myXCoordLabel = new QLabel( tr( "GHS3D_SMP_X_LABEL" ), mySmpGroup ); + anSmpLayout->addWidget(myXCoordLabel, SMP_X_COORD, 1, 1, 1); + myXCoord = new QLineEdit(mySmpGroup); + myXCoord->setValidator(new QDoubleValidator(mySmpGroup)); + anSmpLayout->addWidget(myXCoord, SMP_X_COORD, 2, 1, 1); + QLabel* myYCoordLabel = new QLabel( tr( "GHS3D_SMP_Y_LABEL" ), mySmpGroup ); + anSmpLayout->addWidget(myYCoordLabel, SMP_Y_COORD, 1, 1, 1); + myYCoord = new QLineEdit(mySmpGroup); + myYCoord->setValidator(new QDoubleValidator(mySmpGroup)); + anSmpLayout->addWidget(myYCoord, SMP_Y_COORD, 2, 1, 1); + QLabel* myZCoordLabel = new QLabel( tr( "GHS3D_SMP_Z_LABEL" ), mySmpGroup ); + anSmpLayout->addWidget(myZCoordLabel, SMP_Z_COORD, 1, 1, 1); + myZCoord = new QLineEdit(mySmpGroup); + myZCoord->setValidator(new QDoubleValidator(mySmpGroup)); + anSmpLayout->addWidget(myZCoord, SMP_Z_COORD, 2, 1, 1); + + addVertexButton = new QPushButton(tr("GHS3D_SMP_VERTEX"),mySmpGroup); + anSmpLayout->addWidget(addVertexButton, SMP_VERTEX_BTN, 1, 1, 2); + + QFrame *line = new QFrame(mySmpGroup); + line->setFrameShape(QFrame::HLine); + line->setFrameShadow(QFrame::Sunken); + anSmpLayout->addWidget(line, SMP_SEPARATOR, 1, 1, 2); + + removeVertexButton = new QPushButton(tr("GHS3D_SMP_REMOVE"),mySmpGroup); + anSmpLayout->addWidget(removeVertexButton, SMP_REMOVE_BTN, 1, 1, 2); + // add tabs tab->insertTab( STD_TAB, myStdGroup, tr( "SMESH_ARGUMENTS" ) ); tab->insertTab( ADV_TAB, myAdvGroup, tr( "GHS3D_ADV_ARGS" ) ); + tab->insertTab( SMP_TAB, mySmpGroup, tr( "GHS3D_SIZE_MAP" ) ); tab->setCurrentIndex( STD_TAB ); // connections @@ -192,10 +320,95 @@ QFrame* GHS3DPluginGUI_HypothesisCreator::buildFrame() connect( myInitialMemoryCheck, SIGNAL( toggled( bool ) ), this, SLOT( updateWidgets() ) ); connect( myBoundaryRecoveryCheck, SIGNAL( toggled( bool ) ), this, SLOT( updateWidgets() ) ); connect( dirBtn, SIGNAL( clicked() ), this, SLOT( onDirBtnClicked() ) ); + connect( addVertexButton, SIGNAL( clicked() ), this, SLOT( onVertexBtnClicked() ) ); + connect( removeVertexButton, SIGNAL( clicked() ), this, SLOT( onRemoveVertexBtnClicked() ) ); return fr; } +bool GHS3DPluginGUI_HypothesisCreator::smpVertexExists(double x, double y, double z) const +{ + const int rowCount = mySmpModel->rowCount(); + for (int i=0 ; i < rowCount ; i++) { + double myX = mySmpModel->data(mySmpModel->index(i, SMP_X_COLUMN)).toDouble(); + if (myX == x) { + std::cout << "Found x value " << x << " at row " << i << std::endl; + double myY = mySmpModel->data(mySmpModel->index(i, SMP_Y_COLUMN)).toDouble(); + double myZ = mySmpModel->data(mySmpModel->index(i, SMP_Z_COLUMN)).toDouble(); + std::cout << "y: " << myY << std::endl; + std::cout << "z: " << myY << std::endl; + if ((myY == y) and (myZ == z) ) { + std::cout << "Found y value " << y << " at row " << i << std::endl; + std::cout << "Found z value " << z << " at row " << i << std::endl; + return true; + } + } + } + std::cout << "Not found x,y,z values: " << x << " " << y << " " << z << std::endl; + return false; +} + +void GHS3DPluginGUI_HypothesisCreator::onVertexBtnClicked() +{ + std::cout << "GHS3DPluginGUI_HypothesisCreator::onVertexBtnClicked()" << std::endl; + const int row = mySmpModel->rowCount() ; + double x = myXCoord->text().toDouble(); + double y = myYCoord->text().toDouble(); + double z = myZCoord->text().toDouble(); + + if (smpVertexExists(x,y,z)) return; + + double size = 10.0; + // SMP_X_COLUMN + mySmpModel->setData(mySmpModel->index(row, SMP_X_COLUMN),x); + mySmpModel->setItem( row, SMP_X_COLUMN, new QStandardItem(QString::number(x)) ); + mySmpModel->item( row, SMP_X_COLUMN )->setFlags( Qt::ItemIsSelectable ); + // SMP_Y_COLUMN + mySmpModel->setData(mySmpModel->index(row, SMP_Y_COLUMN),y); + mySmpModel->setItem( row, SMP_Y_COLUMN, new QStandardItem(QString::number(y)) ); + mySmpModel->item( row, SMP_Y_COLUMN )->setFlags( Qt::ItemIsSelectable ); + // SMP_Z_COLUMN + mySmpModel->setData(mySmpModel->index(row, SMP_Z_COLUMN),z); + mySmpModel->setItem( row, SMP_Z_COLUMN, new QStandardItem(QString::number(z)) ); + mySmpModel->item( row, SMP_Z_COLUMN )->setFlags( Qt::ItemIsSelectable ); + // SMP_SIZE_COLUMN + 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; + + mySizeMapTableView->clearSelection(); + mySizeMapTableView->scrollTo( mySmpModel->item( row, SMP_SIZE_COLUMN )->index() ); +} + +void GHS3DPluginGUI_HypothesisCreator::onRemoveVertexBtnClicked() +{ + QList selectedRows; + QList selectedIndex = mySizeMapTableView->selectionModel()->selectedIndexes(); + int row; + QModelIndex index; + foreach( index, selectedIndex ) { + row = index.row(); + if ( !selectedRows.contains( row ) ) + selectedRows.append( row ); + } + qSort( selectedRows ); + QListIterator it( selectedRows ); + it.toBack(); + while ( it.hasPrevious() ) { + row = it.previous(); + cout << "delete row #"<< row <removeRow(row ); + } + mySizeMapTableView->clearSelection(); +} void GHS3DPluginGUI_HypothesisCreator::onDirBtnClicked() { QString dir = SUIT_FileDlg::getExistingDirectory( dlg(), myWorkingDir->text(), QString() ); @@ -224,6 +437,7 @@ bool GHS3DPluginGUI_HypothesisCreator::checkParams() const void GHS3DPluginGUI_HypothesisCreator::retrieveParams() const { + std::cout << "GHS3DPluginGUI_HypothesisCreator::retrieveParams" << std::endl; GHS3DHypothesisData data; readParamsFromHypo( data ); @@ -244,6 +458,34 @@ void GHS3DPluginGUI_HypothesisCreator::retrieveParams() const myToCreateNewNodesCheck ->setChecked ( data.myToCreateNewNodes ); myBoundaryRecoveryCheck ->setChecked ( data.myBoundaryRecovery ); myTextOption ->setText ( data.myTextOption ); + + TSizeMapVertexValues::iterator it; + 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; + // SMP_X_COLUMN + mySmpModel->setData(mySmpModel->index(row, SMP_X_COLUMN),x); + mySmpModel->setItem( row, SMP_X_COLUMN, new QStandardItem(QString::number(x)) ); + mySmpModel->item( row, SMP_X_COLUMN )->setFlags( Qt::ItemIsSelectable ); + // SMP_Y_COLUMN + mySmpModel->setData(mySmpModel->index(row, SMP_Y_COLUMN),y); + mySmpModel->setItem( row, SMP_Y_COLUMN, new QStandardItem(QString::number(y)) ); + mySmpModel->item( row, SMP_Y_COLUMN )->setFlags( Qt::ItemIsSelectable ); + // SMP_Z_COLUMN + mySmpModel->setData(mySmpModel->index(row, SMP_Z_COLUMN),z); + mySmpModel->setItem( row, SMP_Z_COLUMN, new QStandardItem(QString::number(z)) ); + mySmpModel->item( row, SMP_Z_COLUMN )->setFlags( Qt::ItemIsSelectable ); + // SMP_SIZE_COLUMN + mySmpModel->setData(mySmpModel->index(row, SMP_SIZE_COLUMN),size); + mySmpModel->setItem( row, SMP_SIZE_COLUMN, new QStandardItem(QString::number(size)) ); + + std::cout << "Row " << row << ": (" << x << ","<< y << ","<< z << ") ="<< size << std::endl; + row++; + } GHS3DPluginGUI_HypothesisCreator* that = (GHS3DPluginGUI_HypothesisCreator*)this; that->updateWidgets(); @@ -251,6 +493,7 @@ void GHS3DPluginGUI_HypothesisCreator::retrieveParams() const QString GHS3DPluginGUI_HypothesisCreator::storeParams() const { + std::cout << "GHS3DPluginGUI_HypothesisCreator::storeParams" << std::endl; GHS3DHypothesisData data; readParamsFromWidgets( data ); storeParamsToHypo( data ); @@ -284,12 +527,16 @@ QString GHS3DPluginGUI_HypothesisCreator::storeParams() const valStr += " "; valStr += data.myTextOption; + + // TODO + // Add size map parameters storage return valStr; } bool GHS3DPluginGUI_HypothesisCreator::readParamsFromHypo( GHS3DHypothesisData& h_data ) const { + std::cout << "GHS3DPluginGUI_HypothesisCreator::readParamsFromHypo" << std::endl; GHS3DPlugin::GHS3DPlugin_Hypothesis_var h = GHS3DPlugin::GHS3DPlugin_Hypothesis::_narrow( initParamsHypothesis() ); @@ -308,11 +555,24 @@ bool GHS3DPluginGUI_HypothesisCreator::readParamsFromHypo( GHS3DHypothesisData& h_data.myBoundaryRecovery = h->GetToUseBoundaryRecoveryVersion(); h_data.myTextOption = h->GetTextOption(); + GHS3DPlugin::GHS3DSizeMapVertexList_var verteces = h->GetSizeMapVerteces(); + std::cout << "verteces->length(): " << verteces->length() << std::endl; + h_data.mySizeMapVerteces.clear(); + for (int i=0 ; ilength() ; i++) { + GHS3DSizeMapVertex* myVertex = new GHS3DSizeMapVertex; + myVertex->x = verteces[i].x; + myVertex->y = verteces[i].y; + myVertex->z = verteces[i].z; + double size = verteces[i].size; + std::cout << "Add enforced vertex ("<< myVertex->x << ","<< myVertex->y << ","<< myVertex->z << ") ="<< size << std::endl; + h_data.mySizeMapVerteces[myVertex] = size; + } return true; } bool GHS3DPluginGUI_HypothesisCreator::storeParamsToHypo( const GHS3DHypothesisData& h_data ) const { + std::cout << "GHS3DPluginGUI_HypothesisCreator::storeParamsToHypo" << std::endl; GHS3DPlugin::GHS3DPlugin_Hypothesis_var h = GHS3DPlugin::GHS3DPlugin_Hypothesis::_narrow( hypothesis() ); @@ -344,6 +604,32 @@ 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; + TSizeMapVertexValues::const_iterator it; + h->ClearSizeMapVerteces(); + for(it = h_data.mySizeMapVerteces.begin() ; it != h_data.mySizeMapVerteces.end(); it++ ) { + double x = it->first->x; + double y = it->first->y; + double z = it->first->z; + double size = it->second; + std::cout << "(" << x << ", " + << y << ", " + << z << ") = " + << size << std::endl; + double mySize; + try { + mySize = h->GetSizeMapVertex(x,y,z); + std::cout << "Old size: " << mySize << std::endl; + if (mySize != size) { + std::cout << "Setting new size: " << size << std::endl; + h->SetSizeMapVertex(x,y,z,size); + } + } + catch (...) { + std::cout << "Setting new size: " << size << std::endl; + h->SetSizeMapVertex(x,y,z,size); + } + } } catch ( const SALOME::SALOME_Exception& ex ) { @@ -355,6 +641,7 @@ bool GHS3DPluginGUI_HypothesisCreator::storeParamsToHypo( const GHS3DHypothesisD bool GHS3DPluginGUI_HypothesisCreator::readParamsFromWidgets( GHS3DHypothesisData& h_data ) const { + std::cout << "GHS3DPluginGUI_HypothesisCreator::readParamsFromWidgets" << std::endl; h_data.myName = myName ? myName->text() : ""; h_data.myToMeshHoles = myToMeshHolesCheck->isChecked(); h_data.myMaximumMemory = myMaximumMemoryCheck->isChecked() ? myMaximumMemorySpin->value() : -1; @@ -366,6 +653,19 @@ bool GHS3DPluginGUI_HypothesisCreator::readParamsFromWidgets( GHS3DHypothesisDat h_data.myToCreateNewNodes = myToCreateNewNodesCheck->isChecked(); h_data.myBoundaryRecovery = myBoundaryRecoveryCheck->isChecked(); h_data.myTextOption = myTextOption->text(); + h_data.mySizeMapVerteces.clear(); + for (int i=0 ; irowCount() ; i++) { + GHS3DSizeMapVertex* myVertex = new GHS3DSizeMapVertex; + myVertex->x = mySmpModel->data(mySmpModel->index(i,SMP_X_COLUMN)).toDouble(); + myVertex->y = mySmpModel->data(mySmpModel->index(i,SMP_Y_COLUMN)).toDouble(); + myVertex->z = mySmpModel->data(mySmpModel->index(i,SMP_Z_COLUMN)).toDouble(); + double size = mySmpModel->data(mySmpModel->index(i,SMP_SIZE_COLUMN)).toDouble(); + std::cout << "Add new enforced vertex (" << myVertex->x << ", " + << myVertex->y << ", " + << myVertex->z << ") = " + << size << std::endl; + h_data.mySizeMapVerteces[myVertex] = size; + } return true; } diff --git a/src/GUI/GHS3DPluginGUI_HypothesisCreator.h b/src/GUI/GHS3DPluginGUI_HypothesisCreator.h index 55c7433..6f6975b 100644 --- a/src/GUI/GHS3DPluginGUI_HypothesisCreator.h +++ b/src/GUI/GHS3DPluginGUI_HypothesisCreator.h @@ -26,12 +26,32 @@ #include "GHS3DPlugin_Defs.hxx" #include +#include +#include +#include class QWidget; class QComboBox; class QCheckBox; class QLineEdit; class QSpinBox; +class QStandardItemModel; +class QTableView; +class QHeaderView; +class QTableWidget; +class QDoubleSpinBox; +class QItemDelegate; +class QStandardItem; +class QDoubleValidator; + +typedef struct +{ + double x; + double y; + double z; +} GHS3DSizeMapVertex; + +typedef std::map TSizeMapVertexValues; typedef struct { @@ -46,6 +66,8 @@ typedef struct bool myToCreateNewNodes; bool myBoundaryRecovery; QString myTextOption; + TSizeMapVertexValues mySizeMapVerteces; +// QList mySizeMapVerteces; } GHS3DHypothesisData; @@ -75,11 +97,14 @@ protected: protected slots: void onDirBtnClicked(); void updateWidgets(); + void onVertexBtnClicked(); + void onRemoveVertexBtnClicked(); private: bool readParamsFromHypo( GHS3DHypothesisData& ) const; bool readParamsFromWidgets( GHS3DHypothesisData& ) const; bool storeParamsToHypo( const GHS3DHypothesisData& ) const; + bool smpVertexExists(double, double, double) const; private: QWidget* myStdGroup; @@ -98,6 +123,33 @@ private: QCheckBox* myToCreateNewNodesCheck; QCheckBox* myBoundaryRecoveryCheck; QLineEdit* myTextOption; + + QWidget* mySmpGroup; + QStandardItemModel* mySmpModel; + QTableView* mySizeMapTableView; + QLineEdit* myXCoord; + QLineEdit* myYCoord; + QLineEdit* myZCoord; + QPushButton* addVertexButton; + QPushButton* removeVertexButton; +}; + +class DoubleLineEditDelegate : public QItemDelegate +{ + Q_OBJECT + +public: + DoubleLineEditDelegate(QObject *parent = 0); + + QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, + const QModelIndex &index) const; + + void setEditorData(QWidget *editor, const QModelIndex &index) const; + void setModelData(QWidget *editor, QAbstractItemModel *model, + const QModelIndex &index) const; + + void updateEditorGeometry(QWidget *editor, + const QStyleOptionViewItem &option, const QModelIndex &index) const; }; #endif diff --git a/src/GUI/GHS3DPlugin_msg_en.ts b/src/GUI/GHS3DPlugin_msg_en.ts index cf795b8..1ba1fcb 100644 --- a/src/GUI/GHS3DPlugin_msg_en.ts +++ b/src/GUI/GHS3DPlugin_msg_en.ts @@ -106,5 +106,45 @@ WORKING_DIR Working directory + + GHS3D_SIZE_MAP + Size Map + + + GHS3D_SMP_X_COLUMN + X + + + GHS3D_SMP_Y_COLUMN + Y + + + GHS3D_SMP_Z_COLUMN + Z + + + GHS3D_SMP_SIZEMAP_COLUMN + Size + + + GHS3D_SMP_X_LABEL + X: + + + GHS3D_SMP_Y_LABEL + Y: + + + GHS3D_SMP_Z_LABEL + Z: + + + GHS3D_SMP_VERTEX + Add enforced vertex + + + GHS3D_SMP_REMOVE + Remove vertex + diff --git a/src/GUI/Makefile.am b/src/GUI/Makefile.am index 83b7dd9..b96a342 100644 --- a/src/GUI/Makefile.am +++ b/src/GUI/Makefile.am @@ -25,12 +25,12 @@ include $(top_srcdir)/adm_local/unix/make_common_starter.am # header files -salomeinclude_HEADERS = +salomeinclude_HEADERS = # Libraries targets lib_LTLIBRARIES = libGHS3DPluginGUI.la -dist_libGHS3DPluginGUI_la_SOURCES = GHS3DPluginGUI_HypothesisCreator.cxx +dist_libGHS3DPluginGUI_la_SOURCES = GHS3DPluginGUI_HypothesisCreator.cxx MOC_FILES = GHS3DPluginGUI_HypothesisCreator_moc.cxx nodist_libGHS3DPluginGUI_la_SOURCES= $(MOC_FILES) -- 2.39.2