Logo Search packages:      
Sourcecode: fet version File versions

bool Rules::modifyEquipment ( const QString &  initialEquipmentName,
const QString &  finalEquipmentName 
)

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

Definition at line 1948 of file rules.cpp.

References equipmentsList, ConstraintSubjectRequiresEquipments::equipmentsNames, internalStructureComputed, Equipment::name, roomsList, searchEquipment(), and spaceConstraintsList.

{
      int i=this->searchEquipment(initialEquipmentName);
      assert(i>=0);
      assert(this->searchEquipment(finalEquipmentName)==-1 || initialEquipmentName==finalEquipmentName);

      Equipment* searchedEquipment=this->equipmentsList.at(i);
      assert(searchedEquipment->name==initialEquipmentName);
      
      //check the constraints
      for(SpaceConstraint* ctr=this->spaceConstraintsList.first(); ctr; ctr=this->spaceConstraintsList.next())
            if(ctr->type==CONSTRAINT_SUBJECT_REQUIRES_EQUIPMENTS){
                  ConstraintSubjectRequiresEquipments* csre=(ConstraintSubjectRequiresEquipments*)ctr;
                  for(QStringList::Iterator it=csre->equipmentsNames.begin(); it!=csre->equipmentsNames.end(); it++)
                        if(*it==initialEquipmentName)
                              *it=finalEquipmentName;
            }
      
      //Modify this equipment in all the rooms that posess it.
      for(Room* rm=this->roomsList.first(); rm; rm=this->roomsList.next())
            for(QStringList::Iterator it=rm->equipments.begin(); it!=rm->equipments.end(); it++)
                  if(*it==initialEquipmentName)
                        *it=finalEquipmentName;
                        
      searchedEquipment->name=finalEquipmentName;

      this->internalStructureComputed=false;
      return true;
}


Generated by  Doxygen 1.6.0   Back to index