*/
module GHS3DPlugin
{
+ struct GHS3DSizeMapVertex {
+ double x;
+ double y;
+ double z;
+ double size;
+ };
+
+ typedef sequence<GHS3DSizeMapVertex> GHS3DSizeMapVertexList;
/*!
* GHS3DPlugin_GHS3D: interface of "Tetrahedron (GHS3D)" algorithm
*/
*/
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();
};
};
//purpose :
//=======================================================================
-static bool writePoints (ofstream & theFile,
- SMESHDS_Mesh * theMesh,
- map <int,int> & theSmdsToGhs3dIdMap,
- map <int,const SMDS_MeshNode*> & theGhs3dIdToNodeMap)
+static bool writePoints (ofstream & theFile,
+ SMESHDS_Mesh * theMesh,
+ map <int,int> & theSmdsToGhs3dIdMap,
+ map <int,const SMDS_MeshNode*> & 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<int,double> 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 <int,double>::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;
}
//purpose :
//=======================================================================
-static bool writePoints (ofstream & theFile,
- SMESHDS_Mesh * theMesh,
- const vector <const SMDS_MeshNode*> & theNodeByGhs3dId)
+static bool writePoints (ofstream & theFile,
+ SMESHDS_Mesh * theMesh,
+ const vector <const SMDS_MeshNode*> & theNodeByGhs3dId,
+ GHS3DPlugin_Hypothesis::TSizeMapVertexValues & theEnforcedVerteces)
{
// record structure:
//
if ( nbNodes == 0 )
return false;
+ int nbEnforcedVerteces = theEnforcedVerteces.size();
+
const char* space = " ";
const int dummyint = 0;
// 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
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;
}
}
map <int,int> aSmdsToGhs3dIdMap;
map <int,const SMDS_MeshNode*> 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();
if (!Ok)
return error( SMESH_Comment("Can't write into ") << aPointsFileName);
+ GHS3DPlugin_Hypothesis::TSizeMapVertexValues enforcedVerteces = GHS3DPlugin_Hypothesis::GetEnforcedVerteces(_hyp);
vector <const SMDS_MeshNode*> aNodeByGhs3dId;
Ok = (writeFaces ( aFacesFile, meshDS, aNodeByGhs3dId ) &&
- writePoints( aPointsFile, meshDS, aNodeByGhs3dId));
+ writePoints( aPointsFile, meshDS, aNodeByGhs3dId,enforcedVerteces));
aFacesFile.close();
aPointsFile.close();
myVerboseLevel = DefaultVerboseLevel();
myToCreateNewNodes = DefaultToCreateNewNodes();
myToUseBoundaryRecoveryVersion = DefaultToUseBoundaryRecoveryVersion();
+ mySizeMapVerteces = DefaultSizeMapVerteces();
}
//=======================================================================
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<double> 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
#ifndef WIN32
#include <sys/sysinfo.h>
+#else
+#include <windows.h>
#endif
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;
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
//=======================================================================
save << (int)myToCreateNewNodes << " ";
save << (int)myToUseBoundaryRecoveryVersion << " ";
save << myTextOption << " ";
+
+// if (mySizeMapVerteces.size() >= 4) {
+// save << "__SIZEMAP_BEGIN__" << " ";
+// for (int i=0 ; i<mySizeMapVerteces.size(); i++)
+// save << mySizeMapVerteces.at(i) << " ";
+// save << "__SIZEMAP_END__" << " ";
+// }
return save;
}
return aGenericName.ToCString();
}
+
+
+//================================================================================
+/*!
+* \brief Return the enforced verteces
+*/
+//================================================================================
+
+GHS3DPlugin_Hypothesis::TSizeMapVertexValues GHS3DPlugin_Hypothesis::GetEnforcedVerteces(const GHS3DPlugin_Hypothesis* hyp)
+{
+ return hyp->GetSizeMapVerteces();
+}
+
#include "GHS3DPlugin_Defs.hxx"
#include <SMESH_Hypothesis.hxx>
-
+#include <stdexcept>
+#include <map>
+#include <cstdio>
using namespace std;
class GHS3DPLUGIN_EXPORT GHS3DPlugin_Hypothesis: public SMESH_Hypothesis
*/
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<GHS3DSizeMapVertex*,double> TSizeMapVertexValues;
+// typedef std::map<double[3],double> 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();
static short DefaultVerboseLevel();
static bool DefaultToCreateNewNodes();
static bool DefaultToUseBoundaryRecoveryVersion();
+ static TSizeMapVertexValues DefaultSizeMapVerteces();
/*!
* \brief Return command to run ghs3d mesher excluding file prefix (-f)
* \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);
bool myToCreateNewNodes;
bool myToUseBoundaryRecoveryVersion;
string myTextOption;
+ TSizeMapVertexValues mySizeMapVerteces;
};
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
*/
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();
#include <QPushButton>
#include <QFileInfo>
+#include <QTableWidget>
+#include <QStandardItemModel>
+#include <QStandardItem>
+#include <QHeaderView>
+#include <QModelIndexList>
+
+#include <stdexcept>
+
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 <sys/sysinfo.h>
+#else
+#include <windows.h>
#endif
int maxAvailableMemory()
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<QLineEdit*>(editor);
+ lineEdit->setText(value);
+}
+
+void DoubleLineEditDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
+ const QModelIndex &index) const
+{
+ QLineEdit *lineEdit = static_cast<QLineEdit*>(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 )
{
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
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("<<row<<","<<SMP_X_COLUMN<<")).toDouble(): "
+ << mySmpModel->data(mySmpModel->index(row,SMP_X_COLUMN)).toDouble() << std::endl;
+ std::cout << "mySmpModel->data(mySmpModel->index("<<row<<","<<SMP_Y_COLUMN<<")).toDouble(): "
+ << mySmpModel->data(mySmpModel->index(row,SMP_Y_COLUMN)).toDouble() << std::endl;
+ std::cout << "mySmpModel->data(mySmpModel->index("<<row<<","<<SMP_Z_COLUMN<<")).toDouble(): "
+ << mySmpModel->data(mySmpModel->index(row,SMP_Z_COLUMN)).toDouble() << std::endl;
+ std::cout << "mySmpModel->data(mySmpModel->index("<<row<<","<<SMP_SIZE_COLUMN<<")).toDouble(): "
+ << mySmpModel->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<int> selectedRows;
+ QList<QModelIndex> selectedIndex = mySizeMapTableView->selectionModel()->selectedIndexes();
+ int row;
+ QModelIndex index;
+ foreach( index, selectedIndex ) {
+ row = index.row();
+ if ( !selectedRows.contains( row ) )
+ selectedRows.append( row );
+ }
+ qSort( selectedRows );
+ QListIterator<int> it( selectedRows );
+ it.toBack();
+ while ( it.hasPrevious() ) {
+ row = it.previous();
+ cout << "delete row #"<< row <<endl;
+ mySmpModel->removeRow(row );
+ }
+ mySizeMapTableView->clearSelection();
+}
void GHS3DPluginGUI_HypothesisCreator::onDirBtnClicked()
{
QString dir = SUIT_FileDlg::getExistingDirectory( dlg(), myWorkingDir->text(), QString() );
void GHS3DPluginGUI_HypothesisCreator::retrieveParams() const
{
+ std::cout << "GHS3DPluginGUI_HypothesisCreator::retrieveParams" << std::endl;
GHS3DHypothesisData data;
readParamsFromHypo( data );
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();
QString GHS3DPluginGUI_HypothesisCreator::storeParams() const
{
+ std::cout << "GHS3DPluginGUI_HypothesisCreator::storeParams" << std::endl;
GHS3DHypothesisData data;
readParamsFromWidgets( data );
storeParamsToHypo( data );
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() );
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 ; i<verteces->length() ; 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() );
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 )
{
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;
h_data.myToCreateNewNodes = myToCreateNewNodesCheck->isChecked();
h_data.myBoundaryRecovery = myBoundaryRecoveryCheck->isChecked();
h_data.myTextOption = myTextOption->text();
+ h_data.mySizeMapVerteces.clear();
+ for (int i=0 ; i<mySmpModel->rowCount() ; 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;
}
#include "GHS3DPlugin_Defs.hxx"
#include <SMESHGUI_Hypotheses.h>
+#include <QItemDelegate>
+#include <map>
+#include <vector>
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<GHS3DSizeMapVertex*,double> TSizeMapVertexValues;
typedef struct
{
bool myToCreateNewNodes;
bool myBoundaryRecovery;
QString myTextOption;
+ TSizeMapVertexValues mySizeMapVerteces;
+// QList<GHS3DSizeMapVertex> mySizeMapVerteces;
} GHS3DHypothesisData;
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;
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
<source>WORKING_DIR</source>
<translation>Working directory</translation>
</message>
+ <message>
+ <source>GHS3D_SIZE_MAP</source>
+ <translation>Size Map</translation>
+ </message>
+ <message>
+ <source>GHS3D_SMP_X_COLUMN</source>
+ <translation>X</translation>
+ </message>
+ <message>
+ <source>GHS3D_SMP_Y_COLUMN</source>
+ <translation>Y</translation>
+ </message>
+ <message>
+ <source>GHS3D_SMP_Z_COLUMN</source>
+ <translation>Z</translation>
+ </message>
+ <message>
+ <source>GHS3D_SMP_SIZEMAP_COLUMN</source>
+ <translation>Size</translation>
+ </message>
+ <message>
+ <source>GHS3D_SMP_X_LABEL</source>
+ <translation>X:</translation>
+ </message>
+ <message>
+ <source>GHS3D_SMP_Y_LABEL</source>
+ <translation>Y:</translation>
+ </message>
+ <message>
+ <source>GHS3D_SMP_Z_LABEL</source>
+ <translation>Z:</translation>
+ </message>
+ <message>
+ <source>GHS3D_SMP_VERTEX</source>
+ <translation>Add enforced vertex</translation>
+ </message>
+ <message>
+ <source>GHS3D_SMP_REMOVE</source>
+ <translation>Remove vertex</translation>
+ </message>
</context>
</TS>
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)