Logo Search packages:      
Sourcecode: fet version File versions

bool Rules::modifyRoom ( const QString &  initialRoomName,
const QString &  finalRoomName,
const QString &  type,
int  capacity 
)

Modifies this room and takes care of all related constraints. Returns true on success, false on failure (if not found) It does not alter the list of equipments.

Definition at line 2091 of file rules.cpp.

References Room::capacity, internalStructureComputed, Room::name, removeSpaceConstraint(), ConstraintActivityPreferredRoom::roomName, ConstraintTeacherRequiresRoom::roomName, ConstraintRoomNotAvailable::roomName, roomsList, ConstraintActivityPreferredRooms::roomsNames, ConstraintRoomTypeNotAllowedSubjects::roomType, searchRoom(), spaceConstraintsList, and Room::type.

{
      int i=this->searchRoom(initialRoomName);
      if(i<0)
            return false;

      Room* searchedRoom=this->roomsList.at(i);
      assert(searchedRoom->name==initialRoomName);

      //Removing useless ConstraintRoomTypeNotAllowedSubjects
      //Firstly, check whether the type of this room exists at another room
      bool typeExisting=false;
      for(Room *rm=this->roomsList.first(); rm; rm=this->roomsList.next())
            if(rm->name!=searchedRoom->name && rm->type==searchedRoom->type){
                  typeExisting=true;
                  break;
            }
      if(searchedRoom->type==type) //type unchanged, keep the constraints
            typeExisting=true;
      for(SpaceConstraint* ctr=this->spaceConstraintsList.first(); ctr; )
            if(!typeExisting && ctr->type==CONSTRAINT_ROOM_TYPE_NOT_ALLOWED_SUBJECTS){
                  ConstraintRoomTypeNotAllowedSubjects* crtas=(ConstraintRoomTypeNotAllowedSubjects*)ctr;
                  if(crtas->roomType==searchedRoom->type){
                        this->removeSpaceConstraint(ctr);
                        ctr=this->spaceConstraintsList.current();
                  }
                  else
                        ctr=this->spaceConstraintsList.next();
            }
            else if(ctr->type==CONSTRAINT_ROOM_NOT_AVAILABLE){
                  ConstraintRoomNotAvailable* crna=(ConstraintRoomNotAvailable*)ctr;
                  if(crna->roomName==initialRoomName)
                        crna->roomName=finalRoomName;
                  ctr=this->spaceConstraintsList.next();
            }
            else if(ctr->type==CONSTRAINT_TEACHER_REQUIRES_ROOM){
                  ConstraintTeacherRequiresRoom* c=(ConstraintTeacherRequiresRoom*)ctr;
                  if(c->roomName==initialRoomName)
                        c->roomName=finalRoomName;
                  ctr=this->spaceConstraintsList.next();
            }
            else if(ctr->type==CONSTRAINT_ACTIVITY_PREFERRED_ROOM){
                  ConstraintActivityPreferredRoom* c=(ConstraintActivityPreferredRoom*)ctr;
                  if(c->roomName==initialRoomName)
                        c->roomName=finalRoomName;
                  ctr=this->spaceConstraintsList.next();
            }
            else if(ctr->type==CONSTRAINT_ACTIVITY_PREFERRED_ROOMS){
                  ConstraintActivityPreferredRooms* c=(ConstraintActivityPreferredRooms*)ctr;
                  int t=0;
                  for(QStringList::Iterator it=c->roomsNames.begin(); it!=c->roomsNames.end(); it++){
                        if((*it)==initialRoomName){
                              *it=finalRoomName;
                              t++;
                        }
                  }
                  assert(t<=1);
                  ctr=this->spaceConstraintsList.next();
            }
            else
                  ctr=this->spaceConstraintsList.next();

      searchedRoom->name=finalRoomName;
      searchedRoom->type=type;
      searchedRoom->capacity=capacity;

      this->internalStructureComputed=false;
      return true;
}


Generated by  Doxygen 1.6.0   Back to index