Logo Search packages:      
Sourcecode: fet version File versions

bool Rules::removeRoom ( const QString &  roomName  ) 

Removes the room with this name. Returns true on success, false on failure (not found).

Definition at line 2004 of file rules.cpp.

References ConstraintActivityPreferredRooms::activityId, addSpaceConstraint(), SpaceConstraint::compulsory, ConstraintActivityPreferredRoom::getDetailedDescription(), ConstraintActivityPreferredRooms::getDetailedDescription(), internalStructureComputed, Room::name, removeSpaceConstraint(), ConstraintActivityPreferredRoom::roomName, ConstraintTeacherRequiresRoom::roomName, ConstraintRoomNotAvailable::roomName, roomsList, ConstraintActivityPreferredRooms::roomsNames, ConstraintRoomTypeNotAllowedSubjects::roomType, searchRoom(), spaceConstraintsList, Room::type, and SpaceConstraint::weight.

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

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

      //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;
            }
      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==roomName){
                        this->removeSpaceConstraint(ctr);
                        ctr=this->spaceConstraintsList.current();
                  }
                  else
                        ctr=this->spaceConstraintsList.next();
            }
            else if(ctr->type==CONSTRAINT_TEACHER_REQUIRES_ROOM){
                  ConstraintTeacherRequiresRoom* c=(ConstraintTeacherRequiresRoom*)ctr;
                  if(c->roomName==roomName){
                        this->removeSpaceConstraint(ctr);
                        ctr=this->spaceConstraintsList.current();
                  }
                  else
                        ctr=this->spaceConstraintsList.next();
            }
            else if(ctr->type==CONSTRAINT_ACTIVITY_PREFERRED_ROOM){
                  ConstraintActivityPreferredRoom* c=(ConstraintActivityPreferredRoom*)ctr;
                  if(c->roomName==roomName){
                        this->removeSpaceConstraint(ctr);
                        ctr=this->spaceConstraintsList.current();
                  }
                  else
                        ctr=this->spaceConstraintsList.next();
            }
            else if(ctr->type==CONSTRAINT_ACTIVITY_PREFERRED_ROOMS){
                  ConstraintActivityPreferredRooms* c=(ConstraintActivityPreferredRooms*)ctr;
                  int t=c->roomsNames.remove(roomName);
                  assert(t<=1);
                  if(t==1 && c->roomsNames.count()==0){
                        this->removeSpaceConstraint(ctr);
                        ctr=this->spaceConstraintsList.current();
                  }
                  else if(t==1 && c->roomsNames.count()==1){
                        ConstraintActivityPreferredRoom* c2=new ConstraintActivityPreferredRoom
                         (c->weight, c->compulsory, c->activityId, *(c->roomsNames.at(0)));

                        QMessageBox::information(NULL, QObject::tr("FET information"), 
                         QObject::tr("The constraint\n%1 will be modified into constraint\n%2 because"
                         " there is only one room left in the constraint")
                         .arg(c->getDetailedDescription(*this))
                         .arg(c2->getDetailedDescription(*this)));

                        this->removeSpaceConstraint(ctr);
                        ctr=this->spaceConstraintsList.current();
                        this->addSpaceConstraint(c2);
                  }
                  else
                        ctr=this->spaceConstraintsList.next();
            }
            else
                  ctr=this->spaceConstraintsList.next();

      this->roomsList.remove(i);
      this->internalStructureComputed=false;
      return true;
}


Generated by  Doxygen 1.6.0   Back to index