#include "BLSURFPlugin_Hypothesis.hxx"
#include <utilities.h>
#include <cstring>
+#include <iostream>
+#include <sstream>
//=============================================================================
BLSURFPlugin_Hypothesis::BLSURFPlugin_Hypothesis (int hypId, int studyId,
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;
}
bool hasOptions = false;
bool hasSizeMap = false;
bool hasAttractor = false;
+ bool hasEnforcedVertex = false;
isOK = (load >> option_or_sm);
if (isOK)
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) {
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;
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;
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;
}
// Enforced verteces array columns
enum {
-// ENF_VER_ENTRY_COLUMN = 0,
ENF_VER_NAME_COLUMN = 0,
ENF_VER_ENTRY_COLUMN,
ENF_VER_X_COLUMN,
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();
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<QLineEdit*>(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
//
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 );
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() ) );
}
}
-/** 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<QTreeWidgetItem *> 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;
+ }
+ }
}
}
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;
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<std::vector<double> > evs;
std::set<std::vector<double> >::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;