vrecko
virtual reality framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
WallRemove.h
Go to the documentation of this file.
1 #ifndef _WALL_REMOVE_H
2 #define _WALL_REMOVE_H
3 
4 #include "Tool.h"
5 
6 namespace APRoomEdit {
7 
8  class WallRemove : public Tool {
9  public:
11  virtual ~WallRemove() {}
12 
13  virtual bool loadXMLParameters(XERCES_CPP_NAMESPACE_QUALIFIER DOMNode *pParametersNode) {
14  if (findXMLNode(pParametersNode, "Name")) {
15  ReaderWriter::getStringValue(name, pParametersNode, "Name");
16  } else {
17  name = "WallRemove";
18  }
19  return true;
20  }
21 
22 
23  virtual void init(osgUtil::LineSegmentIntersector::Intersection* intersection,
24  WG_Wall* curWall,
25  WG_Point* curPoint,
27  vrecko::EnvironmentObject* pEOOwner,
28  std::vector<osg::ref_ptr<WG_Wall> >* walls,
29  std::vector<osg::ref_ptr<WG_Point> >* points,
30  osg::Geode* pOSGGeode,
31  osg::Vec3Array* pOSGVertexArray) {
32 
33  if (curWall == NULL)
34  return;
35 
36  if (walls->size() == 1) {
37  logger.warningLog("Impossible to destroy last and the only one wall.");
38  return;
39  }
40 
41  WG_Point* Q = curWall->getPoint(WG_Q_POINT);
42  WG_Point* R = curWall->getPoint(WG_R_POINT);
43 
44  if (Q->getWalls()->size() == 1) {
45  points->erase(points->begin()+Q->getId());
46  if (Q->getId() < R->getId())
47  R->setId(R->getId()-1);
48  }
49  else {
50  Q->removeWall(curWall);
51  }
52 
53  if (R->getWalls()->size() == 1) {
54  points->erase(points->begin()+R->getId());
55  }
56  else {
57  R->removeWall(curWall);
58  }
59 
60  walls->erase(walls->begin()+curWall->getId());
61 
62  unsigned int i;
63  for (i=0; i<points->size(); i++) {
64  points->at(i)->setId(i);
65  }
66  for (i=0; i<walls->size(); i++) {
67  walls->at(i)->setId(i);
68  }
69 
70  setDirty(true);
71  }
72  };
73 
74 }
75 
76 #endif
77