void GeoTreeModel::appendSurfaces(const std::string &name, GeoLib::SurfaceVec const& surfaceVec) { for (size_t i = 0; i < _lists.size(); i++) { if ( name.compare( _lists[i]->data(0).toString().toStdString() ) == 0 ) { int nChildren = _lists[i]->childCount(); for (int j = 0; j < nChildren; j++) { GeoObjectListItem* parent = static_cast<GeoObjectListItem*>(_lists[i]->child(j)); if (GeoLib::GEOTYPE::SURFACE == parent->getType()) { this->addChildren(parent, surfaceVec, parent->childCount(), surfaceVec.getVector()->size()); parent->vtkSource()->Modified(); reset(); return; } } } } OGSError::box("Error adding surface to geometry."); }
void GeoTreeView::removeGeometry() { QModelIndex index (this->selectionModel()->currentIndex()); if (!index.isValid()) OGSError::box("No geometry selected."); else { TreeItem* item = static_cast<GeoTreeModel*>(model())->getItem(index); GeoObjectListItem* list = dynamic_cast<GeoObjectListItem*>(item); if (list) { emit listRemoved((item->parentItem()->data( 0).toString()).toStdString(), list->getType()); } else { emit listRemoved((item->data(0).toString()).toStdString(), GeoLib::GEOTYPE::SURFACE); emit listRemoved((item->data(0).toString()).toStdString(), GeoLib::GEOTYPE::POLYLINE); emit listRemoved((item->data(0).toString()).toStdString(), GeoLib::GEOTYPE::POINT); } if(this->selectionModel()->selectedIndexes().count() == 0) { emit enableSaveButton(false); emit enableRemoveButton(false); } } }
vtkPolyDataAlgorithm* GeoTreeModel::vtkSource(const std::string &name, GeoLib::GEOTYPE type) const { size_t nLists = _lists.size(); for (size_t i = 0; i < nLists; i++) { if ( name.compare( _lists[i]->data(0).toString().toStdString() ) == 0 ) for (int j = 0; j < _lists[i]->childCount(); j++) { GeoObjectListItem* item = dynamic_cast<GeoObjectListItem*>(_lists[i]->child(j)); if (item->getType() == type) return item->vtkSource(); } } return NULL; }
void GeoTreeModel::addPointList(QString geoName, GeoLib::PointVec const& pointVec) { const std::vector<GeoLib::Point*>* points = pointVec.getVector(); QList<QVariant> geoData; geoData << QVariant(geoName) << "" << "" << "" << ""; GeoTreeItem* geo (new GeoTreeItem(geoData, _rootItem)); _lists.push_back(geo); _rootItem->appendChild(geo); QList<QVariant> pointData; pointData << "Points" << "" << "" << "" << ""; GeoObjectListItem* pointList = new GeoObjectListItem(pointData, geo, points, GeoLib::GEOTYPE::POINT); geo->appendChild(pointList); size_t nPoints = points->size(); for (size_t j = 0; j < nPoints; j++) { const GeoLib::Point &pnt(*(*points)[j]); QList<QVariant> pnt_data; pnt_data.reserve(5); pnt_data << static_cast<unsigned>(j) << QString::number(pnt[0], 'f') << QString::number(pnt[1], 'f') << QString::number(pnt[2], 'f') << ""; pointList->appendChild(new GeoTreeItem(pnt_data, pointList, static_cast<const GeoLib::Point*>(&pnt))); } for (auto pnt = pointVec.getNameIDMapBegin(); pnt != pointVec.getNameIDMapEnd(); ++pnt) QVariant pnt_data (pointList->child(pnt->second)->setData(4, QString::fromStdString(pnt->first))); INFO("Geometry \"%s\" built. %d points added.", geoName.toStdString().c_str(), nPoints); reset(); }
void GeoTreeModel::addPointList(QString geoName, const GeoLib::PointVec* pointVec) { const std::vector<GeoLib::Point*>* points = pointVec->getVector(); QList<QVariant> geoData; geoData << QVariant(geoName) << "" << "" << "" << ""; GeoTreeItem* geo (new GeoTreeItem(geoData, _rootItem)); _lists.push_back(geo); _rootItem->appendChild(geo); QList<QVariant> pointData; pointData << "Points" << "" << "" << "" << ""; GeoObjectListItem* pointList = new GeoObjectListItem(pointData, geo, points, GeoLib::POINT); geo->appendChild(pointList); size_t nPoints = points->size(); for (size_t j = 0; j < nPoints; j++) { const GeoLib::Point &pnt(*(*points)[j]); std::string pnt_name(""); pointVec->getNameOfElementByID(j, pnt_name); QList<QVariant> pnt_data; pnt_data << static_cast<unsigned>(j) << QString::number(pnt[0], 'f') << QString::number(pnt[1], 'f') << QString::number(pnt[2], 'f') << QString::fromStdString(pnt_name); GeoTreeItem* point(new GeoTreeItem(pnt_data, pointList, static_cast<const GeoLib::Point*>(&pnt))); pointList->appendChild(point); } std::cout << "Geometry \"" << geoName.toStdString() << "\" built." << std::endl; std::cout << nPoints << " points added." << std::endl; reset(); }
void GeoTreeModel::appendPolylines(const std::string &name, const GeoLib::PolylineVec* polylineVec) { for (size_t i = 0; i < _lists.size(); i++) { if ( name.compare( _lists[i]->data(0).toString().toStdString() ) == 0 ) for (int j = 0; j < _lists[i]->childCount(); j++) { GeoObjectListItem* parent = static_cast<GeoObjectListItem*>(_lists[i]->child(j)); if (GeoLib::POLYLINE == parent->getType()) { this->addChildren(parent, polylineVec, parent->childCount(), polylineVec->getVector()->size()); reset(); parent->vtkSource()->Modified(); return; } } } OGSError::box("Error adding polyline to geometry."); }
void GeoTreeView::contextMenuEvent( QContextMenuEvent* event ) { QModelIndex index = this->selectionModel()->currentIndex(); TreeItem* item = static_cast<TreeItem*>(index.internalPointer()); GeoObjectListItem* list = dynamic_cast<GeoObjectListItem*>(item); QMenu menu; // The current index is a list of points/polylines/surfaces if (list != NULL) { QAction* connectPlyAction(NULL); if (list->getType() == GeoLib::GEOTYPE::POLYLINE) { connectPlyAction = menu.addAction("Connect Polylines..."); connect(connectPlyAction, SIGNAL(triggered()), this, SLOT(connectPolylines())); } menu.addSeparator(); //QAction* removeAction = menu.addAction("Remove " + item->data(0).toString()); //connect(removeAction, SIGNAL(triggered()), this, SLOT(removeList())); } else { if (!item) // Otherwise sometimes it crashes when (unmotivated ;-) ) clicking in a treeview return; GeoObjectListItem* parent = dynamic_cast<GeoObjectListItem*>(item->parentItem()); // The current index refers to a geo-object if (parent != NULL) { QMenu* cond_menu = new QMenu("Set FEM Condition"); //menu.addMenu(cond_menu); QAction* addCondAction = cond_menu->addAction("On object..."); QAction* addCondPointAction = cond_menu->addAction("On all points..."); QAction* addNameAction = menu.addAction("Set name..."); connect(addCondAction, SIGNAL(triggered()), this, SLOT(setObjectAsCondition())); connect(addNameAction, SIGNAL(triggered()), this, SLOT(setNameForElement())); if (parent->getType() == GeoLib::GEOTYPE::POINT) addCondPointAction->setEnabled(false); else connect(addCondPointAction, SIGNAL(triggered()), this, SLOT(setObjectPointsAsCondition())); } // The current index refers to the name of a geometry-object else if (item->childCount() > 0) { if (item->child(0)->data(0).toString().compare("Points") == 0) // clumsy way to find out { //QAction* saveAction = menu.addAction("Save geometry..."); QAction* mapAction = menu.addAction("Map geometry..."); //QAction* addCNDAction = menu.addAction("Load FEM Conditions..."); //QAction* saveCondAction = menu.addAction("Save FEM conditions..."); menu.addSeparator(); //QAction* removeAction = menu.addAction("Remove geometry"); //connect(saveAction, SIGNAL(triggered()), this, SLOT(writeToFile())); connect(mapAction, SIGNAL(triggered()), this, SLOT(mapGeometry())); //connect(addCNDAction, SIGNAL(triggered()), this, SLOT(loadFEMConditions())); //connect(saveCondAction, SIGNAL(triggered()), this, SLOT(saveFEMConditions())); //connect(removeAction, SIGNAL(triggered()), this, SLOT(removeList())); } } } menu.exec(event->globalPos()); }