From c50a4593c5492aad3a27f0e64e20687290bf39bf Mon Sep 17 00:00:00 2001
From: Ulrich Kemloh <u.kemloh@fz-juelich.de>
Date: Fri, 17 Aug 2012 12:53:35 +0000
Subject: [PATCH] captions are now displayed when viewing the new geometry
 format

---
 src/SaxParser.cpp                 | 77 ++++++++++++++++++++++---------
 src/geometry/FacilityGeometry.cpp |  4 +-
 2 files changed, 58 insertions(+), 23 deletions(-)

diff --git a/src/SaxParser.cpp b/src/SaxParser.cpp
index c421ec2..fbaf4c2 100644
--- a/src/SaxParser.cpp
+++ b/src/SaxParser.cpp
@@ -890,6 +890,11 @@ void SaxParser::parseGeometryXMLV04(QString filename, FacilityGeometry *geo){
 
 	double version =root.attribute("version","-1").toDouble();
 
+	string unit=root.attribute("unit","cm").toStdString();
+	double xToCmfactor=100;
+	if (unit=="cm") xToCmfactor=1;
+	if (unit=="m") xToCmfactor=100;
+
 	if(version<0.4){
 		QMessageBox::warning(0, QObject::tr("Parsing Error"),
 				QObject::tr("Only geometry version >= 0.4 supported"));
@@ -900,26 +905,48 @@ void SaxParser::parseGeometryXMLV04(QString filename, FacilityGeometry *geo){
 	//parsing the walls
 	for (unsigned int i = 0; i < xSubRoomsNodeList.length(); i++) {
 		QDomElement xPoly = xSubRoomsNodeList.item(i).firstChildElement("polygon");
+		double position[3]={0,0,0};
+		double pos_count=1;
+		double color=0;
+
 		while(!xPoly.isNull()) {
 			//wall thickness, default to 30 cm
 			double thickness = xPoly.attribute("thickness","15").toDouble();
 			//wall height default to 250 cm
 			double height = xPoly.attribute("height","250").toDouble();
 			//wall color default to blue
-			double color = xPoly.attribute("color","0").toDouble();
+			 color = xPoly.attribute("color","0").toDouble();
 
 			QDomNodeList xVertices=xPoly.elementsByTagName("vertex");
+			pos_count+=xVertices.count()-1;
+
 			for( int i=0;i<xVertices.count()-1;i++){
-				double x1=xVertices.item(i).toElement().attribute("px", "0").toDouble();
-				double y1=xVertices.item(i).toElement().attribute("py", "0").toDouble();
-				double z1=xVertices.item(i).toElement().attribute("pz", "0").toDouble();
+				//all unit are converted in cm
+				double x1=xVertices.item(i).toElement().attribute("px", "0").toDouble()*xToCmfactor;
+				double y1=xVertices.item(i).toElement().attribute("py", "0").toDouble()*xToCmfactor;
+				double z1=xVertices.item(i).toElement().attribute("pz", "0").toDouble()*xToCmfactor;
+				double x2=xVertices.item(i+1).toElement().attribute("px", "0").toDouble()*xToCmfactor;
+				double y2=xVertices.item(i+1).toElement().attribute("py", "0").toDouble()*xToCmfactor;
+
+				position[0]+= x1;
+				position[1]+= y1;
+				position[2]+= z1;
 
-				double x2=xVertices.item(i+1).toElement().attribute("px", "0").toDouble();
-				double y2=xVertices.item(i+1).toElement().attribute("py", "0").toDouble();
 				geo->addWall(x1, y1, x2, y2,z1,thickness,height,color);
 			}
 			xPoly = xPoly.nextSiblingElement("polygon");
 		}
+
+		//add the caption
+		string roomCaption = xSubRoomsNodeList.item(i).parentNode().toElement().attribute("caption").toStdString();
+		string subroomCaption=xSubRoomsNodeList.item(i).toElement().attribute("id").toStdString();
+		string caption=roomCaption+" ( " + subroomCaption + " ) ";
+		position[0]/=pos_count;
+		position[1]/=pos_count;
+		position[2]/=pos_count;
+		geo->addObjectLabel(position,position,caption,color);
+		//cout<<"position: [" <<position[0]<<", "<<position[1]<<", "<<position[2]<<" ]"<<endl;;
+
 	}
 
 	QDomNodeList xObstaclesList=doc.elementsByTagName("obstacle");
@@ -935,12 +962,12 @@ void SaxParser::parseGeometryXMLV04(QString filename, FacilityGeometry *geo){
 
 			QDomNodeList xVertices=xPoly.elementsByTagName("vertex");
 			for( int i=0;i<xVertices.count()-1;i++){
-				double x1=xVertices.item(i).toElement().attribute("px", "0").toDouble();
-				double y1=xVertices.item(i).toElement().attribute("py", "0").toDouble();
-				double z1=xVertices.item(i).toElement().attribute("pz", "0").toDouble();
+				double x1=xVertices.item(i).toElement().attribute("px", "0").toDouble()*xToCmfactor;
+				double y1=xVertices.item(i).toElement().attribute("py", "0").toDouble()*xToCmfactor;
+				double z1=xVertices.item(i).toElement().attribute("pz", "0").toDouble()*xToCmfactor;
 
-				double x2=xVertices.item(i+1).toElement().attribute("px", "0").toDouble();
-				double y2=xVertices.item(i+1).toElement().attribute("py", "0").toDouble();
+				double x2=xVertices.item(i+1).toElement().attribute("px", "0").toDouble()*xToCmfactor;
+				double y2=xVertices.item(i+1).toElement().attribute("py", "0").toDouble()*xToCmfactor;
 				geo->addWall(x1, y1, x2, y2,z1,thickness,height,color);
 			}
 			xPoly = xPoly.nextSiblingElement("polygon");
@@ -958,14 +985,18 @@ void SaxParser::parseGeometryXMLV04(QString filename, FacilityGeometry *geo){
 		double height = xCrossing.attribute("height","250").toDouble();
 		//door color default to blue
 		double color = xCrossing.attribute("color","255").toDouble();
+		QString id= xCrossing.attribute("id","-1");
 
-		double x1=xVertices.item(0).toElement().attribute("px", "0").toDouble();
-		double y1=xVertices.item(0).toElement().attribute("py", "0").toDouble();
-		double z1=xVertices.item(0).toElement().attribute("pz", "0").toDouble();
+		double x1=xVertices.item(0).toElement().attribute("px", "0").toDouble()*xToCmfactor;
+		double y1=xVertices.item(0).toElement().attribute("py", "0").toDouble()*xToCmfactor;
+		double z1=xVertices.item(0).toElement().attribute("pz", "0").toDouble()*xToCmfactor;
 
-		double x2=xVertices.item(1).toElement().attribute("px", "0").toDouble();
-		double y2=xVertices.item(1).toElement().attribute("py", "0").toDouble();
+		double x2=xVertices.item(1).toElement().attribute("px", "0").toDouble()*xToCmfactor;
+		double y2=xVertices.item(1).toElement().attribute("py", "0").toDouble()*xToCmfactor;
 		geo->addDoor(x1, y1, x2, y2,z1,thickness,height,color);
+
+		double center[3]={(x1+x2)/2.0, (y1+y2)/2.0, z1};
+		geo->addObjectLabel(center,center,id.toStdString(),21);
 	}
 
 	QDomNodeList xTransitionsList=doc.elementsByTagName("transition");
@@ -980,12 +1011,16 @@ void SaxParser::parseGeometryXMLV04(QString filename, FacilityGeometry *geo){
 		//door color default to blue
 		double color = xTransition.attribute("color","255").toDouble();
 
-		double x1=xVertices.item(0).toElement().attribute("px", "0").toDouble();
-		double y1=xVertices.item(0).toElement().attribute("py", "0").toDouble();
-		double z1=xVertices.item(0).toElement().attribute("pz", "0").toDouble();
+		double x1=xVertices.item(0).toElement().attribute("px", "0").toDouble()*xToCmfactor;
+		double y1=xVertices.item(0).toElement().attribute("py", "0").toDouble()*xToCmfactor;
+		double z1=xVertices.item(0).toElement().attribute("pz", "0").toDouble()*xToCmfactor;
 
-		double x2=xVertices.item(1).toElement().attribute("px", "0").toDouble();
-		double y2=xVertices.item(1).toElement().attribute("py", "0").toDouble();
+		double x2=xVertices.item(1).toElement().attribute("px", "0").toDouble()*xToCmfactor;
+		double y2=xVertices.item(1).toElement().attribute("py", "0").toDouble()*xToCmfactor;
 		geo->addDoor(x1, y1, x2, y2,z1,thickness,height,color);
+
+		string id= xTransition.attribute("id","-1").toStdString();
+		double center[3]={(x1+x2)/2.0, (y1+y2)/2.0, z1};
+		geo->addObjectLabel(center,center,id,21);
 	}
 }
diff --git a/src/geometry/FacilityGeometry.cpp b/src/geometry/FacilityGeometry.cpp
index cf6d2f6..046ef94 100644
--- a/src/geometry/FacilityGeometry.cpp
+++ b/src/geometry/FacilityGeometry.cpp
@@ -276,8 +276,8 @@ void FacilityGeometry::addDoor(double x1, double y1, double x2, double y2, doubl
 
 	//double m[]={x1,y1,z+1};
 	//double n[]={x2,y2,z+1};
+	//printf("[%f %f %f]---[%f %f %f]\n",x1,y1,z,x2,y2,z);
 
-	printf("[%f %f %f]---[%f %f %f]\n",x1,y1,z,x2,y2,z);
 	linesPlotter2D->PlotDoor(m,n,doorColor/255.0);
 }
 
@@ -570,7 +570,7 @@ vtkActor2DCollection* FacilityGeometry::getCaptions(){
 void FacilityGeometry::addNewElementText(double center[3], double orientation[3],
 		string text, double color) {
 
-	return ;
+	//return ;
 
 		{//caption
 			VTK_CREATE(vtkTextActor3D,caption);
-- 
GitLab