Ejemplo n.º 1
0
void TrajectoriesJPSV04::WriteGeometry(Building* building)
{
     // just put a link to the geometry file
     string embed_geometry;
     embed_geometry.append("\t<geometry>\n");
     char file_location[CLENGTH] = "";
     sprintf(file_location, "\t<file location= \"%s\"/>\n", building->GetGeometryFilename().c_str());
     embed_geometry.append(file_location);
     embed_geometry.append("\t</geometry>\n");
     //Write(embed_geometry);
     //return;
     //
     string geometry;
     geometry.append("\t<geometry>\n");

     bool plotHlines = true;
     bool plotCrossings = true;
     bool plotTransitions = true;
     bool plotPlayingField=false;
     vector<string> rooms_to_plot;
     unsigned int i;
     // first the rooms
     //to avoid writing navigation line twice
     vector<int> navLineWritten;
     //rooms_to_plot.push_back("U9");

     for (const auto& it:building->GetAllRooms())
     {
          auto&& r = it.second;
          string caption = r->GetCaption(); //if(r->GetID()!=1) continue;
          if (!rooms_to_plot.empty() && !IsElementInVector(rooms_to_plot, caption))
               continue;

          for(auto&& sitr: r->GetAllSubRooms())
          {
               auto&& s = sitr.second; //if(s->GetSubRoomID()!=7) continue;
               geometry.append(s->WriteSubRoom());

               // the hlines
               if (plotHlines) {
                    const vector<Hline*>& hlines = s->GetAllHlines();
                    for (i = 0; i < hlines.size(); i++) {
                         Hline* hline = hlines[i];
                         int uid1 = hline->GetUniqueID();
                         if (!IsElementInVector(navLineWritten, uid1)) {
                              navLineWritten.push_back(uid1);
                              if (rooms_to_plot.empty()
                                        || IsElementInVector(rooms_to_plot, caption)) {
                                   geometry.append(hline->GetDescription());
                              }
                         }
                    }

                    // the crossings
                    if (plotCrossings) {
                         const vector<Crossing*>& crossings = s->GetAllCrossings();
                         for (i = 0; i < crossings.size(); i++) {
                              Crossing* crossing = crossings[i];
                              int uid1 = crossing->GetUniqueID();
                              if (!IsElementInVector(navLineWritten, uid1)) {
                                   navLineWritten.push_back(uid1);
                                   if (rooms_to_plot.empty()
                                             || IsElementInVector(rooms_to_plot,
                                                       caption)) {
                                        geometry.append(crossing->GetDescription());
                                   }
                              }
                         }
                    }

                    // the transitions
                    if (plotTransitions) {
                         const vector<Transition*>& transitions =
                                   s->GetAllTransitions();
                         for (i = 0; i < transitions.size(); i++) {
                              Transition* transition = transitions[i];
                              int uid1 = transition->GetUniqueID();
                              if (!IsElementInVector(navLineWritten, uid1)) {
                                   navLineWritten.push_back(uid1);

                                   if (rooms_to_plot.empty()) {
                                        geometry.append(transition->GetDescription());

                                   } else {

                                        Room* room1 = transition->GetRoom1();
                                        Room* room2 = transition->GetRoom2();
                                        string caption1 = room1->GetCaption();
                                        if (room2) {
                                             string caption2 = room2->GetCaption();
                                             if (IsElementInVector(rooms_to_plot,
                                                       caption1)
                                                       || IsElementInVector(rooms_to_plot,
                                                                 caption2)) {
                                                  geometry.append(transition->GetDescription());
                                             }

                                        } else {
                                             if (IsElementInVector(rooms_to_plot,
                                                       caption1)) {
                                                  geometry.append(transition->GetDescription());
                                             }
                                        }

                                   }
                              }
                         }
                    }
               }
          }
     }

     //eventually write any goal
     for (map<int, Goal*>::const_iterator itr = building->GetAllGoals().begin();
               itr != building->GetAllGoals().end(); ++itr) {
          geometry.append(itr->second->Write());
     }

     if(plotPlayingField) {
          //add the playing area
          double width=3282;
          double length=5668;
          char tmp[100];
          geometry.append("\t\t<wall>\n");
          sprintf(tmp, "\t\t\t<point xPos=\"%.2f\" yPos=\"%.2f\"/>\n",-length,width);
          geometry.append(tmp);

          sprintf(tmp, "\t\t\t<point xPos=\"%.2f\" yPos=\"%.2f\"/>\n",-length,-width);
          geometry.append(tmp);
          sprintf(tmp, "\t\t\t<point xPos=\"%.2f\" yPos=\"%.2f\"/>\n",length,-width);
          geometry.append(tmp);
          sprintf(tmp, "\t\t\t<point xPos=\"%.2f\" yPos=\"%.2f\"/>\n",length,width);
          geometry.append(tmp);
          sprintf(tmp, "\t\t\t<point xPos=\"%.2f\" yPos=\"%.2f\"/>\n",-length,width);
          geometry.append(tmp);
          geometry.append("\t\t</wall>\n");

          geometry.append("\t\t<wall>\n");
          sprintf(tmp, "\t\t\t<point xPos=\"%.2f\" yPos=\"%.2f\"/>\n",0.0,width);
          geometry.append(tmp);
          sprintf(tmp, "\t\t\t<point xPos=\"%.2f\" yPos=\"%.2f\"/>\n",0.0,-width);
          geometry.append(tmp);
          geometry.append("\t\t</wall>\n");
     }
     geometry.append("\t</geometry>\n");
     Write(geometry);
}