From: nge Date: Wed, 7 Oct 2009 16:37:54 +0000 (+0000) Subject: Enforced verteces (continue): X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=ed3d5f17ac71e2993c5fbfb32e456cbfbec55c12;p=plugins%2Fblsurfplugin.git Enforced verteces (continue): - hdf save process done - add custom delegate for enforced verteces tree view --- diff --git a/src/BLSURFPlugin/BLSURFPlugin_Hypothesis.cxx b/src/BLSURFPlugin/BLSURFPlugin_Hypothesis.cxx index 61fba53..75b6fda 100644 --- a/src/BLSURFPlugin/BLSURFPlugin_Hypothesis.cxx +++ b/src/BLSURFPlugin/BLSURFPlugin_Hypothesis.cxx @@ -26,6 +26,8 @@ #include "BLSURFPlugin_Hypothesis.hxx" #include #include +#include +#include //============================================================================= BLSURFPlugin_Hypothesis::BLSURFPlugin_Hypothesis (int hypId, int studyId, @@ -649,6 +651,25 @@ std::ostream & BLSURFPlugin_Hypothesis::SaveTo(std::ostream & save) save << " " << "__ATTRACTORS_END__"; } + TEnforcedVertexMap::const_iterator it_enf = _enforcedVerteces.begin(); + if (it_enf != _enforcedVerteces.end()) { + save << " " << "__ENFORCED_VERTECES_BEGIN__"; + for ( ; it_enf != _enforcedVerteces.end(); ++it_enf ) { + save << " " << it_enf->first; + TEnforcedVertexList evl = it_enf->second; + TEnforcedVertexList::const_iterator it_evl = evl.begin(); + if (it_evl != evl.end()) { + for ( ; it_evl != evl.end() ; ++it_evl) { + save << " " << (*it_evl)[0]; + save << " " << (*it_evl)[1]; + save << " " << (*it_evl)[2]; + save << "$"; // "$" is a mark of enforced vertex end + } + } + save << "#"; // "#" is a mark of enforced shape end + } + save << " " << "__ENFORCED_VERTECES_END__"; + } return save; } @@ -748,6 +769,7 @@ std::istream & BLSURFPlugin_Hypothesis::LoadFrom(std::istream & load) bool hasOptions = false; bool hasSizeMap = false; bool hasAttractor = false; + bool hasEnforcedVertex = false; isOK = (load >> option_or_sm); if (isOK) @@ -757,6 +779,8 @@ std::istream & BLSURFPlugin_Hypothesis::LoadFrom(std::istream & load) hasSizeMap = true; else if (option_or_sm == "__ATTRACTORS_BEGIN__") hasAttractor = true; + else if (option_or_sm == "__ENFORCED_VERTECES_BEGIN__") + hasEnforcedVertex = true; std::string optName, optValue; while (isOK && hasOptions) { @@ -794,6 +818,8 @@ std::istream & BLSURFPlugin_Hypothesis::LoadFrom(std::istream & load) hasSizeMap = true; else if (option_or_sm == "__ATTRACTORS_BEGIN__") hasAttractor = true; + else if (option_or_sm == "__ENFORCED_VERTECES_BEGIN__") + hasEnforcedVertex = true; } std::string smEntry, smValue; @@ -827,8 +853,11 @@ std::istream & BLSURFPlugin_Hypothesis::LoadFrom(std::istream & load) if (hasSizeMap) { isOK = (load >> option_or_sm); - if (isOK && option_or_sm == "__ATTRACTORS_BEGIN__") - hasAttractor = true; + if (isOK) + if (option_or_sm == "__ATTRACTORS_BEGIN__") + hasAttractor = true; + else if (option_or_sm == "__ENFORCED_VERTECES_BEGIN__") + hasEnforcedVertex = true; } std::string atEntry, atValue; @@ -859,6 +888,67 @@ std::istream & BLSURFPlugin_Hypothesis::LoadFrom(std::istream & load) value3[ len3-2 ] = '\0'; //cut off "%#" } } + + if (hasAttractor) { + isOK = (load >> option_or_sm); + if (isOK) + if (option_or_sm == "__ENFORCED_VERTECES_BEGIN__") + hasEnforcedVertex = true; + } + + std::string enfEntry, enfValue, trace; + std::ostringstream oss; + while (isOK && hasEnforcedVertex) { + isOK = (load >> enfEntry); + if (isOK) { + if (enfEntry == "__ENFORCED_VERTECES_END__") + break; + + enfValue = "begin"; + int len4 = enfValue.size(); + + TEnforcedVertexList & evl = _enforcedVerteces[enfEntry]; + evl.clear(); + TEnforcedVertex enfVertex; + + // continue reading until "#" encountered + while ( enfValue[len4-1] != '#') { + // New vector begin + enfVertex.clear(); + while ( enfValue[len4-1] != '$') { + isOK = (load >> enfValue); + if (isOK) { + len4 = enfValue.size(); + // End of vertex list + if (enfValue[len4-1] == '#') + break; + if (enfValue[len4-1] != '$') { + // Add to vertex + enfVertex.push_back(atof(enfValue.c_str())); + } + } + else + break; + } + if (enfValue[len4-1] == '$') { + // Remove '$' and add to vertex + enfValue[len4-1] = '\0'; //cut off "$#" + enfVertex.push_back(atof(enfValue.c_str())); + // Add vertex to list of vertex + evl.insert(enfVertex); + } + } + if (enfValue[len4-1] == '#') { + // Remove '$#' and add to vertex + enfValue[len4-2] = '\0'; //cut off "$#" + enfVertex.push_back(atof(enfValue.c_str())); + // Add vertex to list of vertex + evl.insert(enfVertex); + } + } + else + break; + } return load; } diff --git a/src/GUI/BLSURFPluginGUI_HypothesisCreator.cxx b/src/GUI/BLSURFPluginGUI_HypothesisCreator.cxx index 7fc5eeb..b2d7275 100644 --- a/src/GUI/BLSURFPluginGUI_HypothesisCreator.cxx +++ b/src/GUI/BLSURFPluginGUI_HypothesisCreator.cxx @@ -131,7 +131,6 @@ enum { // Enforced verteces array columns enum { -// ENF_VER_ENTRY_COLUMN = 0, ENF_VER_NAME_COLUMN = 0, ENF_VER_ENTRY_COLUMN, ENF_VER_X_COLUMN, @@ -251,25 +250,28 @@ End initialization Python structures and objects class QDoubleValidator; // -// BEGIN DoubleLineEditDelegate +// BEGIN EnforcedTreeWidgetDelegate // -DoubleLineEditDelegate::DoubleLineEditDelegate(QObject *parent) +EnforcedTreeWidgetDelegate::EnforcedTreeWidgetDelegate(QObject *parent) : QItemDelegate(parent) { } -QWidget *DoubleLineEditDelegate::createEditor(QWidget *parent, - const QStyleOptionViewItem &/* option */, - const QModelIndex &/* index */) const +QWidget *EnforcedTreeWidgetDelegate::createEditor(QWidget *parent, + const QStyleOptionViewItem & option , + const QModelIndex & index ) const { QLineEdit *editor = new QLineEdit(parent); - editor->setValidator(new QDoubleValidator(parent)); + if (index.column() == ENF_VER_X_COLUMN || \ + index.column() == ENF_VER_Y_COLUMN || \ + index.column() == ENF_VER_Z_COLUMN) + editor->setValidator(new QDoubleValidator(parent)); return editor; } -void DoubleLineEditDelegate::setEditorData(QWidget *editor, +void EnforcedTreeWidgetDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const { QString value = index.model()->data(index, Qt::EditRole).toString(); @@ -278,27 +280,97 @@ void DoubleLineEditDelegate::setEditorData(QWidget *editor, lineEdit->setText(value); } -void DoubleLineEditDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, +void EnforcedTreeWidgetDelegate::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); - MESSAGE("Value " << value << " was set at index(" << index.row() << "," << index.column() << ")"); + if (index.column() == ENF_VER_X_COLUMN || \ + index.column() == ENF_VER_Y_COLUMN || \ + index.column() == ENF_VER_Z_COLUMN) + { + if (not vertexExists(model, index, lineEdit->text())) { + bool ok; + double value = lineEdit->text().toDouble(&ok); + if (ok) + model->setData(index, value, Qt::EditRole); + } + } + else if (index.column() == ENF_VER_NAME_COLUMN) { + QString value = lineEdit->text(); + if (not vertexExists(model, index, value)) + model->setData(index, value, Qt::EditRole); +// MESSAGE("Value " << value.toString().toStdString() << " was set at index(" << index.row() << "," << index.column() << ")"); } } -void DoubleLineEditDelegate::updateEditorGeometry(QWidget *editor, +void EnforcedTreeWidgetDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &/* index */) const { editor->setGeometry(option.rect); } +bool EnforcedTreeWidgetDelegate::vertexExists(QAbstractItemModel *model, + const QModelIndex &index, QString value) const +{ + bool exists = false; + QModelIndex parent = index.parent(); + int row = index.row(); + int col = index.column(); + + if (parent.isValid()) { + if (col == ENF_VER_X_COLUMN || col == ENF_VER_Y_COLUMN || col == ENF_VER_Z_COLUMN) { + double x, y, z; + if (col == ENF_VER_X_COLUMN) { + x = value.toDouble(); + y = parent.child(row, ENF_VER_Y_COLUMN).data(Qt::EditRole).toDouble(); + z = parent.child(row, ENF_VER_Z_COLUMN).data(Qt::EditRole).toDouble(); + } + if (col == ENF_VER_Y_COLUMN) { + y = value.toDouble(); + x = parent.child(row, ENF_VER_X_COLUMN).data(Qt::EditRole).toDouble(); + z = parent.child(row, ENF_VER_Z_COLUMN).data(Qt::EditRole).toDouble(); + } + if (col == ENF_VER_Z_COLUMN) { + z = value.toDouble(); + x = parent.child(row, ENF_VER_X_COLUMN).data(Qt::EditRole).toDouble(); + y = parent.child(row, ENF_VER_Y_COLUMN).data(Qt::EditRole).toDouble(); + } + // MESSAGE("Checking for existing vertex " << x << ", " << y << "," << z); + int nbChildren = model->rowCount(parent); + for (int i = 0 ; i < nbChildren ; i++) { + if (i != row) { + double childX = parent.child(i, ENF_VER_X_COLUMN).data(Qt::EditRole).toDouble(); + double childY = parent.child(i, ENF_VER_Y_COLUMN).data(Qt::EditRole).toDouble(); + double childZ = parent.child(i, ENF_VER_Z_COLUMN).data(Qt::EditRole).toDouble(); + MESSAGE("Vertex: " << childX << ", " << childY << "," << childZ); + if ((childX == x) && (childY == y) && (childZ == z)) { + MESSAGE("Found !"); + exists = true; + break; + } + } + } + } + else if (index.column() == ENF_VER_NAME_COLUMN) { + int nbChildren = model->rowCount(parent); + for (int i = 0 ; i < nbChildren ; i++) { + if (i != row) { + QString childName = parent.child(i, ENF_VER_NAME_COLUMN).data(Qt::EditRole).toString(); + if (childName == value) { + exists = true; + break; + } + } + } + } + } + + return exists; +} + // -// END DoubleLineEditDelegate +// END EnforcedTreeWidgetDelegate // @@ -667,6 +739,7 @@ QFrame* BLSURFPluginGUI_HypothesisCreator::buildFrame() myEnforcedTreeWidget->resizeColumnToContents(column); } myEnforcedTreeWidget->hideColumn(ENF_VER_ENTRY_COLUMN); + myEnforcedTreeWidget->setItemDelegate(new EnforcedTreeWidgetDelegate()); anEnfLayout->addWidget(myEnforcedTreeWidget, 0, 0, 8, 1); QLabel* myXCoordLabel = new QLabel( tr( "BLSURF_ENF_VER_X_LABEL" ), myEnfGroup ); @@ -719,8 +792,9 @@ QFrame* BLSURFPluginGUI_HypothesisCreator::buildFrame() connect( removeButton, SIGNAL( clicked()), this, SLOT( onRemoveMap() ) ); connect( mySizeMapTable, SIGNAL( cellChanged ( int, int )), this, SLOT( onSetSizeMap(int,int ) ) ); - connect( myEnforcedTreeWidget,SIGNAL( itemClicked(QTreeWidgetItem *, int)), this, SLOT( synchronize(QTreeWidgetItem *, int) ) ); + connect( myEnforcedTreeWidget,SIGNAL( itemClicked(QTreeWidgetItem *, int)), this, SLOT( synchronizeCoords() ) ); connect( myEnforcedTreeWidget,SIGNAL( itemChanged(QTreeWidgetItem *, int)), this, SLOT( update(QTreeWidgetItem *, int) ) ); + connect( myEnforcedTreeWidget,SIGNAL( itemSelectionChanged() ), this, SLOT( synchronizeCoords() ) ); connect( myEnforcedTreeWidget,SIGNAL( activated(QModelIndex&)), this, SLOT( onEnforcedVertexActivated() ) ); connect( addVertexButton, SIGNAL( clicked()), this, SLOT( onAddEnforcedVerteces() ) ); connect( removeVertexButton, SIGNAL( clicked()), this, SLOT( onRemoveEnforcedVertex() ) ); @@ -757,19 +831,27 @@ void BLSURFPluginGUI_HypothesisCreator::update(QTreeWidgetItem* item, int column } } -/** BLSURFPluginGUI_HypothesisCreator::synchronize(item, column) +/** BLSURFPluginGUI_HypothesisCreator::synchronizeCoords() This method synchronizes the QLineEdit widgets content with the coordinates of the enforced vertex clicked in the tree widget. */ -void BLSURFPluginGUI_HypothesisCreator::synchronize(QTreeWidgetItem* item, int column) { +void BLSURFPluginGUI_HypothesisCreator::synchronizeCoords() { // MESSAGE("BLSURFPluginGUI_HypothesisCreator::synchronizeCoords"); - QVariant x = item->data(ENF_VER_X_COLUMN, Qt::EditRole); - if (not x.isNull()) { - QVariant y = item->data(ENF_VER_Y_COLUMN, Qt::EditRole); - QVariant z = item->data(ENF_VER_Z_COLUMN, Qt::EditRole); - myXCoord->setText(x.toString()); - myYCoord->setText(y.toString()); - myZCoord->setText(z.toString()); + QList items = myEnforcedTreeWidget->selectedItems(); + if (not items.isEmpty()) { + QTreeWidgetItem *item; + for (int i=0 ; i < items.size() ; i++) { + item = items[i]; + QVariant x = item->data(ENF_VER_X_COLUMN, Qt::EditRole); + if (not x.isNull()) { + QVariant y = item->data(ENF_VER_Y_COLUMN, Qt::EditRole); + QVariant z = item->data(ENF_VER_Z_COLUMN, Qt::EditRole); + myXCoord->setText(x.toString()); + myYCoord->setText(y.toString()); + myZCoord->setText(z.toString()); + break; + } + } } } @@ -791,11 +873,11 @@ void BLSURFPluginGUI_HypothesisCreator::addEnforcedVertex(std::string entry, std theItem = theItemList[0]; } - MESSAGE("theItemName is " << theItem->text(ENF_VER_NAME_COLUMN).toStdString()); +// MESSAGE("theItemName is " << theItem->text(ENF_VER_NAME_COLUMN).toStdString()); bool okToCreate = true; const int nbVert = theItem->childCount(); - MESSAGE("Number of child rows: " << nbVert); +// MESSAGE("Number of child rows: " << nbVert); if (nbVert >0) { double childValueX,childValueY,childValueZ; QTreeWidgetItem* child; @@ -1014,21 +1096,17 @@ void BLSURFPluginGUI_HypothesisCreator::retrieveParams() const for ( ; evmIt != data.enfVertMap.end() ; ++evmIt) { std::string entry = (*evmIt).first; std::string shapeName = myGeomToolSelected->getNameFromEntry(entry); - MESSAGE("retrieveParams(): entry " << entry << ", shape: " << shapeName); std::set > evs; std::set >::const_iterator evsIt; try { - MESSAGE("evs = (*evmIt)[entry];"); evs = (*evmIt).second; } catch(...) { - MESSAGE("Fail"); + MESSAGE("evs = (*evmIt)[entry]: FAIL"); break; } - MESSAGE("retrieveParams(): evs.size() = " << evs.size()); - evsIt = evs.begin(); for ( ; evsIt != evs.end() ; ++evsIt) { double x, y, z; diff --git a/src/GUI/BLSURFPluginGUI_HypothesisCreator.h b/src/GUI/BLSURFPluginGUI_HypothesisCreator.h index 5a9877b..56e41f4 100644 --- a/src/GUI/BLSURFPluginGUI_HypothesisCreator.h +++ b/src/GUI/BLSURFPluginGUI_HypothesisCreator.h @@ -118,7 +118,7 @@ protected slots: void addEnforcedVertex(std::string, std::string, double, double, double); void onAddEnforcedVerteces(); void onRemoveEnforcedVertex(); - void synchronize(QTreeWidgetItem* , int ); + void synchronizeCoords(); void update(QTreeWidgetItem* , int ); private: @@ -180,12 +180,12 @@ private: }; -class DoubleLineEditDelegate : public QItemDelegate +class EnforcedTreeWidgetDelegate : public QItemDelegate { Q_OBJECT public: - DoubleLineEditDelegate(QObject *parent = 0); + EnforcedTreeWidgetDelegate(QObject *parent = 0); QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const; @@ -194,8 +194,10 @@ public: void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const; - void updateEditorGeometry(QWidget *editor, - const QStyleOptionViewItem &option, const QModelIndex &index) const; + void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, + const QModelIndex &index) const; + + bool vertexExists(QAbstractItemModel *model, const QModelIndex &index, QString value) const; }; #endif // BLSURFPLUGINGUI_HypothesisCreator_H