diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index a06b6697a46600a9437bd45199ea7be37fad6cc3..56ebdc44301575030327c893e45a79a077c2b084 100755 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -1849,12 +1849,15 @@ void MainWindow::slotShowHideGeometryCaptions() void MainWindow::slotShowGeometryStructure() { //QListView list; - _geoStructure.setWindowTitle("Geometry structure"); - _geoStructure.setVisible(! _geoStructure.isVisible()); + //_geoStructure.setVisible(! _geoStructure.isVisible()); //_geoStructure.showColumn(0); - _geoStructure.show(); - _visualisationThread->getGeometry().RefreshView(); - _geoStructure.setModel(&_visualisationThread->getGeometry().GetModel()); + //_geoStructure.show(); + _geoStructure.setHidden(not ui.actionShowGeometry_Structure->isChecked()); + if(_visualisationThread->getGeometry().RefreshView()) + { + _geoStructure.setWindowTitle("Geometry structure"); + _geoStructure.setModel(&_visualisationThread->getGeometry().GetModel()); + } } void MainWindow::slotOnGeometryItemChanged( QStandardItem *item) diff --git a/src/SaxParser.cpp b/src/SaxParser.cpp index 6b8f9a747201768010f5a03c63a2c9575bc35f57..e7043edb25077adc1cd7a9907e30cc9f6a3e8f14 100644 --- a/src/SaxParser.cpp +++ b/src/SaxParser.cpp @@ -327,6 +327,7 @@ bool SaxParser::startElement(const QString & /* namespaceURI */, _height=250; _color=255; _caption=""; + QString room_id, subroom_id; for(int i=0; i<at.length(); i++) { if(at.localName(i)=="thickness") { @@ -337,8 +338,13 @@ bool SaxParser::startElement(const QString & /* namespaceURI */, _color=at.value(i).toDouble(); } else if(at.localName(i)=="caption") { _caption=at.value(i); + }else if(at.localName(i)=="room_id") { + room_id=at.value(i); + }else if(at.localName(i)=="subroom_id") { + subroom_id=at.value(i); } } + _caption=room_id+":"+subroom_id+":"+_caption; } else if (qName == "timeFirstFrame") { @@ -526,10 +532,30 @@ bool SaxParser::endElement(const QString & /* namespaceURI */, } clearPoints(); } else if (qName == "hline") { - if(_currentPointsList.size()>1) //hack - for(unsigned int i=0; i<_currentPointsList.size()-1; i++) { - _geometry->addNavLine(_currentPointsList[i],_currentPointsList[i+1],_caption.toStdString()); + if(_currentPointsList.size()>1) + { + for(unsigned int i=0; i<_currentPointsList.size()-1; i++) + { + int room_id=-1; + int subroom_id=-1; + QStringList lst = _caption.split(":"); + if(lst.length()>2) + { + room_id=lst[0].toInt(); + subroom_id=lst[1].toInt(); + _caption=lst[2]; + } + auto&& geo=_geoFactory.GetElement(room_id,subroom_id); + if(geo!=nullptr) + { + geo->addNavLine(_currentPointsList[i],_currentPointsList[i+1],_caption.toStdString()); + } + else + { + _geometry->addNavLine(_currentPointsList[i],_currentPointsList[i+1],_caption.toStdString()); + } } + } clearPoints(); } else if (qName == "step") {//FIXME for(unsigned int i=0; i<_currentPointsList.size()-1; i++) { @@ -715,35 +741,35 @@ bool SaxParser::parseGeometryJPS(QString fileName, GeometryFactory& geoFac) geometry->addObstacles(obstPolygonPolyData); // add the crossings - for(auto&& cr: itr_subroom.second->GetAllCrossings()) - { - Point p1 = cr->GetPoint1(); - Point p2 = cr->GetPoint2(); - double z1= cr->GetSubRoom1()->GetElevation(p1); - double z2= cr->GetSubRoom1()->GetElevation(p2); - geometry->addNavLine(p1._x*FAKTOR, p1._y*FAKTOR, z1*FAKTOR, p2._x*FAKTOR, p2._y*FAKTOR,z2*FAKTOR); - - const Point& p =cr->GetCentre(); - double pos[3]= {p._x*FAKTOR,p._y*FAKTOR,z1*FAKTOR}; - geometry->addObjectLabel(pos,pos,"nav_"+QString::number(cr->GetID()).toStdString(),captionsColor); - } + for(auto&& cr: itr_subroom.second->GetAllCrossings()) + { + Point p1 = cr->GetPoint1(); + Point p2 = cr->GetPoint2(); + double z1= cr->GetSubRoom1()->GetElevation(p1); + double z2= cr->GetSubRoom1()->GetElevation(p2); + geometry->addNavLine(p1._x*FAKTOR, p1._y*FAKTOR, z1*FAKTOR, p2._x*FAKTOR, p2._y*FAKTOR,z2*FAKTOR); + + const Point& p =cr->GetCentre(); + double pos[3]= {p._x*FAKTOR,p._y*FAKTOR,z1*FAKTOR}; + geometry->addObjectLabel(pos,pos,"nav_"+QString::number(cr->GetID()).toStdString(),captionsColor); + } - // add the exits - for(auto&& tr: itr_subroom.second->GetAllTransitions()) - { - Point p1 = tr->GetPoint1(); - Point p2 = tr->GetPoint2(); - double z1= tr->GetSubRoom1()->GetElevation(p1); - double z2= tr->GetSubRoom1()->GetElevation(p2); - geometry->addDoor(p1._x*FAKTOR, p1._y*FAKTOR, z1*FAKTOR, p2._x*FAKTOR, p2._y*FAKTOR,z2*FAKTOR); - - const Point& p =tr->GetCentre(); - double pos[3]= {p._x*FAKTOR,p._y*FAKTOR,z1*FAKTOR}; - geometry->addObjectLabel(pos,pos,"door_"+QString::number(tr->GetID()).toStdString(),captionsColor); - } + // add the exits + for(auto&& tr: itr_subroom.second->GetAllTransitions()) + { + Point p1 = tr->GetPoint1(); + Point p2 = tr->GetPoint2(); + double z1= tr->GetSubRoom1()->GetElevation(p1); + double z2= tr->GetSubRoom1()->GetElevation(p2); + geometry->addDoor(p1._x*FAKTOR, p1._y*FAKTOR, z1*FAKTOR, p2._x*FAKTOR, p2._y*FAKTOR,z2*FAKTOR); + + const Point& p =tr->GetCentre(); + double pos[3]= {p._x*FAKTOR,p._y*FAKTOR,z1*FAKTOR}; + geometry->addObjectLabel(pos,pos,"door_"+QString::number(tr->GetID()).toStdString(),captionsColor); + } - geoFac.AddElement(itr_subroom.second->GetRoomID(),itr_subroom.second->GetSubRoomID(),geometry); - //TODO: parsing the Hlines + geoFac.AddElement(itr_subroom.second->GetRoomID(),itr_subroom.second->GetSubRoomID(),geometry); + //TODO: parsing the Hlines } } diff --git a/src/SaxParser.h b/src/SaxParser.h index 7c3e7a63b557211dea27682400bf83112b75860e..cc74cf7acea6e3f1389a449afc7236f2a891bb25 100644 --- a/src/SaxParser.h +++ b/src/SaxParser.h @@ -100,12 +100,12 @@ private: bool _parsingWalls; bool _parsingCrossings; - //wall and door parameters + //wall and door and hlines parameters double _thickness; double _height; double _color; - //actual caption of door/wall + //actual caption of door/wall/hlines QString _caption; //header dependant variables diff --git a/src/geometry/FacilityGeometry.cpp b/src/geometry/FacilityGeometry.cpp index ab9168a4930b9cf6b1ea4b6b6920ac29d7ed5f4d..415f3188d0c6277fb15b3bfcdd0b482854693ab2 100644 --- a/src/geometry/FacilityGeometry.cpp +++ b/src/geometry/FacilityGeometry.cpp @@ -153,63 +153,16 @@ void FacilityGeometry::CreateActors() void FacilityGeometry::setVisibility(bool status) { - assembly2D->SetVisibility(status); - assembly3D->SetVisibility(status); + if(SystemSettings::get2D()) + { + assembly2D->SetVisibility(status); + } + else + { + assembly3D->SetVisibility(status); + } } -//void FacilityGeometry::drawWall(Point *p1, Point *p2){ -// double scale =1; -// -// double *center = p1->centreCoordinatesWith(*p2); -// double angle =p1->angleMadeWith(*p2); -// -// vtkCylinderSource* src = vtkCylinderSource::New(); -// src->SetResolution(10); -// src->SetCenter(center[0],center[1],center[2]); -// src->SetRadius(scale*3); -// src->SetHeight(p1->distanceTo(*p2)); -// vtkPolyDataMapper* mapper = vtkPolyDataMapper::New(); -// mapper->SetInputConnection(src->GetOutputPort()); -// vtkActor* actor = vtkActor::New(); -// actor->SetMapper(mapper); -// actor->GetProperty()->SetLighting(true); -// actor->SetOrigin(center[0],center[1],center[2]); -// //actor->SetOrientation(0,0,90); -// //actor->RotateZ(90); -// actor->RotateZ(angle); -// actor->GetProperty()->SetColor(0.0,0.0,1.0); -// actor->GetProperty()->SetAmbient(0.2); -// actor->GetProperty()->SetDiffuse(0.8); -// -// assembly->AddPart(actor); -// -//} - -//void FacilityGeometry::drawDoor(Point *p1, Point *p2){ -// double *center = p1->centreCoordinatesWith(*p2); -// double angle =p1->angleMadeWith(*p2); -// -// vtkCylinderSource* src = vtkCylinderSource::New(); -// src->SetResolution(40); -// src->SetCenter(center[0],center[1],center[2]); -// src->SetRadius(4); -// src->SetHeight(p1->distanceTo(*p2)); -// vtkPolyDataMapper* mapper = vtkPolyDataMapper::New(); -// mapper->SetInputConnection(src->GetOutputPort()); -// vtkActor* actor = vtkActor::New(); -// actor->SetMapper(mapper); -// actor->GetProperty()->SetLighting(true); -// actor->SetOrigin(center[0],center[1],center[2]); -// //actor->SetOrientation(0,0,90); -// //actor->RotateZ(90); -// actor->RotateZ(angle); -// //actor->GetProperty()->SetColor(0.0,0.1,0.0); -// actor->GetProperty()->SetColor(1.0,0.41,0.72); -// //actor->GetProperty()->SetColor(0.0,0.0,0.0); -// assembly->AddPart(actor); -// -//} - /*** * This is the main build method and should be called by all functions * drawing a wall or a door. Important @@ -907,8 +860,8 @@ void FacilityGeometry::showGeometryLabels(int status) vtkProp3DCollection* col=assemblyCaptions->GetParts(); assemblyCaptions->GetActors(col); - int count = col->GetNumberOfItems(); - for (int i=0; i<count; i++) { + for (int i=0; i<col->GetNumberOfItems(); i++) + { ((vtkActor*)col->GetItemAsObject(i))->SetVisibility(status); } assemblyCaptions->Modified(); diff --git a/src/geometry/GeometryFactory.cpp b/src/geometry/GeometryFactory.cpp index c7041b189fe11441f91a51500388f4ad2bfca711..500c9ddc7587f81be7af4ac2d8b2128a32970430 100644 --- a/src/geometry/GeometryFactory.cpp +++ b/src/geometry/GeometryFactory.cpp @@ -175,44 +175,50 @@ void GeometryFactory::ShowGeometryLabels(int status) } } -void GeometryFactory::RefreshView() +bool GeometryFactory::RefreshView() { - _model.setHorizontalHeaderItem( 0, new QStandardItem( "Entity" ) ); - //_model.setHorizontalHeaderItem( 1, new QStandardItem( "Description" ) ); - - for (auto&& room: _geometryFactory) + if(_model.objectName()!="initialized") { - //room caption - //QStandardItem *roomcaption = new QStandardItem( QString("R %0").arg(room.first)); - //roomcaption->setEditable( false ); - //_model.setItem(room.first, 1, roomcaption); + _model.setObjectName("initialized"); + _model.setHorizontalHeaderItem( 0, new QStandardItem( "Entity" ) ); + //_model.setHorizontalHeaderItem( 1, new QStandardItem( "Description" ) ); - QStandardItem *item = new QStandardItem( QString("Room:%0").arg(room.first)); - item->setCheckable(true); - item->setCheckState(Qt::Checked); - - for(auto&& subroom:room.second) + for (auto&& room: _geometryFactory) { - QStandardItem *child = new QStandardItem( - QString("%0: (%1)") - .arg(QString::fromStdString(subroom.second->GetDescription())) - .arg(subroom.first) - ); + //room caption + //QStandardItem *roomcaption = new QStandardItem( QString("R %0").arg(room.first)); + //roomcaption->setEditable( false ); + //_model.setItem(room.first, 1, roomcaption); - child->setEditable(false); - child->setCheckable(true); - child->setCheckState(Qt::Checked); - item->appendRow( child ); - _model.setItem(room.first, 0, item); - QString data = QString("%0:%1").arg(room.first).arg(subroom.first); - child->setData(data); + QStandardItem *item = new QStandardItem( QString("Room:%0").arg(room.first)); + item->setCheckable(true); + item->setCheckState(Qt::Checked); - //Subroom caption - //QStandardItem *childcaption = new QStandardItem( QString("S %0").arg(subroom.first)); - //childcaption->setEditable( false ); - //_model.setItem(room.first, 1, childcaption); + for(auto&& subroom:room.second) + { + QStandardItem *child = new QStandardItem( + QString("%0: (%1)") + .arg(QString::fromStdString(subroom.second->GetDescription())) + .arg(subroom.first) + ); + + child->setEditable(false); + child->setCheckable(true); + child->setCheckState(Qt::Checked); + item->appendRow( child ); + _model.setItem(room.first, 0, item); + QString data = QString("%0:%1").arg(room.first).arg(subroom.first); + child->setData(data); + + //Subroom caption + //QStandardItem *childcaption = new QStandardItem( QString("S %0").arg(subroom.first)); + //childcaption->setEditable( false ); + //_model.setItem(room.first, 1, childcaption); + } } + return true; } + return false; } const std::map<int , std::map<int, std::shared_ptr<FacilityGeometry> > > & GeometryFactory::GetGeometry() const @@ -226,6 +232,18 @@ void GeometryFactory::AddElement(int room, int subroom, std::shared_ptr<Facility _geometryFactory[room][subroom]=geo; } +std::shared_ptr<FacilityGeometry> GeometryFactory::GetElement(int room, int subroom) +{ + if(_geometryFactory.count(room)) + { + if(_geometryFactory[room].count(subroom)) + { + return _geometryFactory[room][subroom]; + } + } + return nullptr; +} + void GeometryFactory::UpdateVisibility(int room,int subroom,bool status) { if(_geometryFactory.count(room)) diff --git a/src/geometry/GeometryFactory.h b/src/geometry/GeometryFactory.h index e6b3fe4f4afba3a18884c7808db7421e50b99a03..f6fc74a3632c5e9308674f701e2b5a9b0a5b91bc 100644 --- a/src/geometry/GeometryFactory.h +++ b/src/geometry/GeometryFactory.h @@ -31,11 +31,12 @@ public: void ShowNavLines(bool status); void ShowFloor(bool status); void ShowGeometryLabels(int status); - void RefreshView(); + bool RefreshView(); void Clear(); const std::map<int , std::map<int, std::shared_ptr<FacilityGeometry> > > & GetGeometry() const; void AddElement(int room, int subroom, std::shared_ptr<FacilityGeometry> geo); + std::shared_ptr<FacilityGeometry> GetElement(int room, int subroom); void UpdateVisibility(int room,int subroom,bool status); QStandardItemModel& GetModel();