Logo Search packages:      
Sourcecode: fet version File versions

bool Rules::modifySubject ( const QString &  initialSubjectName,
const QString &  finalSubjectName 
)

Modifies (renames) this subject and takes care of all related activities and constraints. Returns true on success, false on failure (if not found)

Definition at line 687 of file rules.cpp.

References activitiesList, internalStructureComputed, searchSubject(), spaceConstraintsList, ConstraintSubjectSubjectTagRequireEquipments::subjectName, ConstraintSubjectRequiresEquipments::subjectName, ConstraintActivitiesPreferredTimes::subjectName, ConstraintRoomTypeNotAllowedSubjects::subjects, subjectsList, and timeConstraintsList.

{
      assert(this->searchSubject(finalSubjectName)==-1);
      assert(this->searchSubject(initialSubjectName)>=0);

      //check the activities first
      for(Activity* act=this->activitiesList.first(); act; act=this->activitiesList.next())
            if( act->subjectName == initialSubjectName)
                  act->subjectName=finalSubjectName;
      
      //modify the time constraints related to this subject
      for(TimeConstraint* ctr=this->timeConstraintsList.first(); ctr; ctr=this->timeConstraintsList.next()){
            if(ctr->type==CONSTRAINT_ACTIVITIES_PREFERRED_TIMES){
                  ConstraintActivitiesPreferredTimes* crt_constraint=(ConstraintActivitiesPreferredTimes*)ctr;
                  if(initialSubjectName == crt_constraint->subjectName)
                        crt_constraint->subjectName=finalSubjectName;
            }
      }

      //modify the space constraints related to this subject
      for(SpaceConstraint* ctr=this->spaceConstraintsList.first(); ctr; ctr=this->spaceConstraintsList.next()){
            if(ctr->type==CONSTRAINT_ROOM_TYPE_NOT_ALLOWED_SUBJECTS){
                  ConstraintRoomTypeNotAllowedSubjects* crtas=(ConstraintRoomTypeNotAllowedSubjects*)ctr;
                  QStringList::Iterator it;
                  for(it=crtas->subjects.begin(); it!=crtas->subjects.end(); it++)
                        if(*it==initialSubjectName){
                              *it=finalSubjectName;
                              break;
                        }
            }
            else if(ctr->type==CONSTRAINT_SUBJECT_REQUIRES_EQUIPMENTS){
                  ConstraintSubjectRequiresEquipments* csre=(ConstraintSubjectRequiresEquipments*)ctr;
                  if(csre->subjectName == initialSubjectName)
                        csre->subjectName=finalSubjectName;
            }
            else if(ctr->type==CONSTRAINT_SUBJECT_SUBJECT_TAG_REQUIRE_EQUIPMENTS){
                  ConstraintSubjectSubjectTagRequireEquipments* c=(ConstraintSubjectSubjectTagRequireEquipments*)ctr;
                  if(c->subjectName == initialSubjectName)
                        c->subjectName=finalSubjectName;
            }
      }

      //rename the subject in the list
      int t=0;
      for(Subject* sbj=this->subjectsList.first(); sbj; sbj=this->subjectsList.next())
            if(sbj->name==initialSubjectName){
                  t++;
                  sbj->name=finalSubjectName;
            }
      assert(t<=1);

      this->internalStructureComputed=false;

      return true;
}


Generated by  Doxygen 1.6.0   Back to index