diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 5c9da193c67d7d15eee08cb6409196131e353dcd..5546dfe4a10aea6cef2d3da1cfeec11f5a989f5f 100755 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -1867,4 +1867,14 @@ void MainWindow::slotOnGeometryItemChanged( QStandardItem *item) bool state=item->checkState(); _visualisationThread->getGeometry().UpdateVisibility(room,subr,state); } + else + { + for(int i=0;i<item->rowCount();i++) + { + QStandardItem *child= item->child(i); + child->setCheckState(item->checkState()); + slotOnGeometryItemChanged(child); + } + + } } diff --git a/src/SaxParser.cpp b/src/SaxParser.cpp index 01ef8bc3431a0176f492fd3d6ace6a1575fe24be..6b8f9a747201768010f5a03c63a2c9575bc35f57 100644 --- a/src/SaxParser.cpp +++ b/src/SaxParser.cpp @@ -592,6 +592,169 @@ void SaxParser::clearPoints() } /// provided for convenience and will be removed in the next version +bool SaxParser::parseGeometryJPS(QString fileName, GeometryFactory& geoFac) +{ + + double captionsColor=0;//red + if(!fileName.endsWith(".xml",Qt::CaseInsensitive)) return false; + QString wd; + SystemSettings::getWorkingDirectory(wd); + fileName=wd+"/"+fileName; + + Building* building = new Building(); + string geometrypath = fileName.toStdString(); + + // read the geometry + if(!building->LoadGeometry(geometrypath)) + return false; + if(!building->InitGeometry()) + return false; // create the polygons + + + + for(auto&& itr_room: building->GetAllRooms()) + { + for(auto&& itr_subroom: itr_room.second->GetAllSubRooms()) + { + auto geometry= shared_ptr<FacilityGeometry>(new FacilityGeometry(itr_subroom.second->GetType())); + + int currentFloorPolyID=0; + int currentObstPolyID=0; + + // Setup the points + VTK_CREATE(vtkPoints,floor_points); + VTK_CREATE(vtkPoints,obstacles_points); + // Add the polygon to a list of polygons + VTK_CREATE(vtkCellArray,floor_polygons); + VTK_CREATE(vtkCellArray,obstacles_polygons); + + //string caption = r->GetCaption(); + SubRoom* sub = itr_subroom.second.get(); + + vector<Point> poly = sub->GetPolygon(); + if(sub->IsClockwise()==true) { + std::reverse(poly.begin(),poly.end()); + } + + // Create the polygon + VTK_CREATE(vtkPolygon,polygon); + polygon->GetPointIds()->SetNumberOfIds(poly.size()); + + for (unsigned int s=0; s<poly.size(); s++) { + floor_points->InsertNextPoint(poly[s]._x*FAKTOR,poly[s]._y*FAKTOR,sub->GetElevation(poly[s])*FAKTOR); + polygon->GetPointIds()->SetId(s, currentFloorPolyID++); + } + floor_polygons->InsertNextCell(polygon); + + //plot the walls only for not stairs + const vector<Wall>& walls= sub->GetAllWalls(); + for(unsigned int w=0; w<walls.size(); w++) { + Point p1 = walls[w].GetPoint1(); + Point p2 = walls[w].GetPoint2(); + double z1= sub->GetElevation(p1); + double z2= sub->GetElevation(p2); + + if(sub->GetType()=="stair") { + geometry->addStair(p1._x*FAKTOR, p1._y*FAKTOR, z1*FAKTOR, p2._x*FAKTOR, p2._y*FAKTOR,z2*FAKTOR); + } else { + geometry->addWall(p1._x*FAKTOR, p1._y*FAKTOR, z1*FAKTOR, p2._x*FAKTOR, p2._y*FAKTOR,z2*FAKTOR); + } + } + + //insert the subroom caption + string caption=itr_room.second->GetCaption()+" ( " + QString::number(sub->GetSubRoomID()).toStdString() + " ) "; + const Point& p=sub->GetCentroid(); + double z= sub->GetElevation(p); + double pos[3]= {p._x*FAKTOR,p._y*FAKTOR,z*FAKTOR}; + geometry->addObjectLabel(pos,pos,caption,captionsColor); + + //plot the obstacles + for(auto obst:sub->GetAllObstacles()) + { + for(auto wall: obst->GetAllWalls()) + { + Point p1 = wall.GetPoint1(); + Point p2 = wall.GetPoint2(); + double z1= sub->GetElevation(p1); + double z2= sub->GetElevation(p2); + geometry->addWall(p1._x*FAKTOR, p1._y*FAKTOR, z1*FAKTOR, p2._x*FAKTOR, p2._y*FAKTOR,z2*FAKTOR); + } + //add the obstacle caption + const Point& p=obst->GetCentroid(); + double z= sub->GetElevation(p); + double pos[3]= {p._x*FAKTOR,p._y*FAKTOR,z*FAKTOR}; + geometry->addObjectLabel(pos,pos,obst->GetCaption(),captionsColor); + + //add a special texture to the obstacles + auto poly = obst->GetPolygon(); + //if(obst->IsClockwise()==true) { + // std::reverse(poly.begin(),poly.end()); + //} + + // Create the polygon + VTK_CREATE(vtkPolygon,polygon); + polygon->GetPointIds()->SetNumberOfIds(poly.size()); + + for (unsigned int s=0; s<poly.size(); s++) { + obstacles_points->InsertNextPoint(poly[s]._x*FAKTOR,poly[s]._y*FAKTOR,sub->GetElevation(poly[s])*FAKTOR); + polygon->GetPointIds()->SetId(s, currentObstPolyID++); + } + obstacles_polygons->InsertNextCell(polygon); + } + + // Create a PolyData to represent the floor + VTK_CREATE(vtkPolyData, floorPolygonPolyData); + floorPolygonPolyData->SetPoints(floor_points); + floorPolygonPolyData->SetPolys(floor_polygons); + geometry->addFloor(floorPolygonPolyData); + + // Create a PolyData to represen the obstacles + VTK_CREATE(vtkPolyData, obstPolygonPolyData); + obstPolygonPolyData->SetPoints(obstacles_points); + obstPolygonPolyData->SetPolys(obstacles_polygons); + 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); + } + + // 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 + } + } + + + // free memory + delete building; + return true; +} + +/* + bool SaxParser::parseGeometryJPS(QString fileName, GeometryFactory& geoFac) { auto geometry= shared_ptr<FacilityGeometry>(new FacilityGeometry("test")); @@ -753,6 +916,7 @@ bool SaxParser::parseGeometryJPS(QString fileName, GeometryFactory& geoFac) return true; } + */ /// provided for convenience and will be removed in the next version diff --git a/src/geometry/GeometryFactory.cpp b/src/geometry/GeometryFactory.cpp index fd89158e2f009474a690cf92786482dba6f81f5b..c7041b189fe11441f91a51500388f4ad2bfca711 100644 --- a/src/geometry/GeometryFactory.cpp +++ b/src/geometry/GeometryFactory.cpp @@ -31,6 +31,7 @@ void GeometryFactory::Set2D(bool status) subroom.second->set2D(status); } } + //Set3D(!status); } void GeometryFactory::Set3D(bool status) @@ -42,6 +43,7 @@ void GeometryFactory::Set3D(bool status) subroom.second->set3D(status); } } + //Set2D(!status); } void GeometryFactory::Clear() @@ -176,7 +178,7 @@ void GeometryFactory::ShowGeometryLabels(int status) void GeometryFactory::RefreshView() { _model.setHorizontalHeaderItem( 0, new QStandardItem( "Entity" ) ); - _model.setHorizontalHeaderItem( 1, new QStandardItem( "Description" ) ); + //_model.setHorizontalHeaderItem( 1, new QStandardItem( "Description" ) ); for (auto&& room: _geometryFactory) { @@ -186,13 +188,18 @@ void GeometryFactory::RefreshView() //_model.setItem(room.first, 1, roomcaption); QStandardItem *item = new QStandardItem( QString("Room:%0").arg(room.first)); - item->setCheckable(false); + item->setCheckable(true); item->setCheckState(Qt::Checked); for(auto&& subroom:room.second) { - QStandardItem *child = new QStandardItem( QString("Subroom: %0").arg(subroom.first)); - child->setEditable( false ); + 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 );