Back to index

fet  5.18.0
hoursform.cpp
Go to the documentation of this file.
00001 //
00002 //
00003 // Description: This file is part of FET
00004 //
00005 //
00006 // Author: Lalescu Liviu <Please see http://lalescu.ro/liviu/ for details about contacting Liviu Lalescu (in particular, you can find here the e-mail address)>
00007 // Copyright (C) 2003 Liviu Lalescu <http://lalescu.ro/liviu/>
00008 //
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 #include <QMessageBox>
00019 
00020 #include "timetable_defs.h"
00021 #include "timetable.h"
00022 #include "fet.h"
00023 
00024 #include "lockunlock.h"
00025 
00026 #include "hoursform.h"
00027 
00028 #include <QLineEdit>
00029 
00030 extern Timetable gt;
00031 
00032 static QLineEdit* hoursNames[60];
00033 static int nHours;
00034 
00035 extern bool students_schedule_ready;
00036 extern bool teachers_schedule_ready;
00037 extern bool rooms_schedule_ready;
00038 
00039 HoursForm::HoursForm(QWidget* parent): QDialog(parent)
00040 {
00041        setupUi(this);
00042        
00043        okPushButton->setDefault(true);
00044 
00045        connect(hoursSpinBox, SIGNAL(valueChanged(int)), this, SLOT(hoursChanged()));
00046        connect(okPushButton, SIGNAL(clicked()), this, SLOT(ok()));
00047        connect(cancelPushButton, SIGNAL(clicked()), this, SLOT(cancel()));
00048 
00049        centerWidgetOnScreen(this);
00050        restoreFETDialogGeometry(this);
00051        
00052        nHours=gt.rules.nHoursPerDay;
00053 
00054        hoursNames[0]=hour1LineEdit;
00055        hoursNames[1]=hour2LineEdit;
00056        hoursNames[2]=hour3LineEdit;
00057        hoursNames[3]=hour4LineEdit;
00058        hoursNames[4]=hour5LineEdit;
00059        hoursNames[5]=hour6LineEdit;
00060        hoursNames[6]=hour7LineEdit;
00061        hoursNames[7]=hour8LineEdit;
00062        hoursNames[8]=hour9LineEdit;
00063        hoursNames[9]=hour10LineEdit;
00064 
00065        hoursNames[10]=hour11LineEdit;
00066        hoursNames[11]=hour12LineEdit;
00067        hoursNames[12]=hour13LineEdit;
00068        hoursNames[13]=hour14LineEdit;
00069        hoursNames[14]=hour15LineEdit;
00070        hoursNames[15]=hour16LineEdit;
00071        hoursNames[16]=hour17LineEdit;
00072        hoursNames[17]=hour18LineEdit;
00073        hoursNames[18]=hour19LineEdit;
00074        hoursNames[19]=hour20LineEdit;
00075 
00076        hoursNames[20]=hour21LineEdit;
00077        hoursNames[21]=hour22LineEdit;
00078        hoursNames[22]=hour23LineEdit;
00079        hoursNames[23]=hour24LineEdit;
00080        hoursNames[24]=hour25LineEdit;
00081        hoursNames[25]=hour26LineEdit;
00082        hoursNames[26]=hour27LineEdit;
00083        hoursNames[27]=hour28LineEdit;
00084        hoursNames[28]=hour29LineEdit;
00085        hoursNames[29]=hour30LineEdit;
00086 
00087        hoursNames[30]=hour31LineEdit;
00088        hoursNames[31]=hour32LineEdit;
00089        hoursNames[32]=hour33LineEdit;
00090        hoursNames[33]=hour34LineEdit;
00091        hoursNames[34]=hour35LineEdit;
00092        hoursNames[35]=hour36LineEdit;
00093        hoursNames[36]=hour37LineEdit;
00094        hoursNames[37]=hour38LineEdit;
00095        hoursNames[38]=hour39LineEdit;
00096        hoursNames[39]=hour40LineEdit;
00097 
00098        hoursNames[40]=hour41LineEdit;
00099        hoursNames[41]=hour42LineEdit;
00100        hoursNames[42]=hour43LineEdit;
00101        hoursNames[43]=hour44LineEdit;
00102        hoursNames[44]=hour45LineEdit;
00103        hoursNames[45]=hour46LineEdit;
00104        hoursNames[46]=hour47LineEdit;
00105        hoursNames[47]=hour48LineEdit;
00106        hoursNames[48]=hour49LineEdit;
00107        hoursNames[49]=hour50LineEdit;
00108 
00109        hoursNames[50]=hour51LineEdit;
00110        hoursNames[51]=hour52LineEdit;
00111        hoursNames[52]=hour53LineEdit;
00112        hoursNames[53]=hour54LineEdit;
00113        hoursNames[54]=hour55LineEdit;
00114        hoursNames[55]=hour56LineEdit;
00115        hoursNames[56]=hour57LineEdit;
00116        hoursNames[57]=hour58LineEdit;
00117        hoursNames[58]=hour59LineEdit;
00118        hoursNames[59]=hour60LineEdit;
00119 
00120        hoursSpinBox->setMinimum(1);
00121        hoursSpinBox->setMaximum(60);
00122        hoursSpinBox->setValue(gt.rules.nHoursPerDay);
00123 
00124        for(int i=0; i<60; i++)
00125               if(i<nHours){
00126                      hoursNames[i]->setEnabled(true);
00127                      hoursNames[i]->setText(gt.rules.hoursOfTheDay[i]);
00128               }
00129               else
00130                      hoursNames[i]->setDisabled(true);
00131 }
00132 
00133 HoursForm::~HoursForm()
00134 {
00135        saveFETDialogGeometry(this);
00136 }
00137 
00138 void HoursForm::hoursChanged()
00139 {
00140        nHours=hoursSpinBox->value();
00141        assert(nHours <= MAX_HOURS_PER_DAY);
00142        for(int i=0; i<60; i++)
00143               if(i<nHours)
00144                      hoursNames[i]->setEnabled(true);
00145               else
00146                      hoursNames[i]->setDisabled(true);
00147 }
00148 
00149 void HoursForm::ok()
00150 {
00151        for(int i=0; i<nHours; i++)
00152               if(hoursNames[i]->text()==""){
00153                      QMessageBox::warning(this, tr("FET information"),
00154                             tr("Empty names not allowed"));
00155                      return;
00156               }
00157        for(int i=0; i<nHours-1; i++)
00158               for(int j=i+1; j<nHours; j++)
00159                      if(hoursNames[i]->text()==hoursNames[j]->text()){
00160                             QMessageBox::warning(this, tr("FET information"),
00161                                    tr("Duplicates not allowed"));
00162                             return;
00163                      }
00164                      
00165        //2011-10-18
00166        int cnt_mod=0;
00167        int cnt_rem=0;
00168        int oldHours=gt.rules.nHoursPerDay;
00169        gt.rules.nHoursPerDay=nHours;
00170 
00171        foreach(TimeConstraint* tc, gt.rules.timeConstraintsList)
00172               if(tc->hasWrongDayOrHour(gt.rules)){
00173                      if(tc->canRepairWrongDayOrHour(gt.rules))
00174                             cnt_mod++;
00175                      else
00176                             cnt_rem++;
00177               }
00178 
00179        foreach(SpaceConstraint* sc, gt.rules.spaceConstraintsList)
00180               if(sc->hasWrongDayOrHour(gt.rules)){
00181                      if(sc->canRepairWrongDayOrHour(gt.rules))
00182                             cnt_mod++;
00183                      else
00184                             cnt_rem++;
00185               }
00186        
00187        gt.rules.nHoursPerDay=oldHours;
00188                      
00189        if(cnt_mod>0 || cnt_rem>0){
00190               QString s=QString("");
00191               if(cnt_rem>0){
00192                      s+=tr("%1 constraints will be removed.", "%1 is the number of constraints").arg(cnt_rem);
00193                      s+=" ";
00194               }
00195               if(cnt_mod>0){
00196                      s+=tr("%1 constraints will be modified.", "%1 is the number of constraints").arg(cnt_mod);
00197                      s+=" ";
00198               }
00199               s+=tr("Do you want to continue?");
00200 
00201               int res=QMessageBox::warning(this, tr("FET warning"), s, QMessageBox::Yes|QMessageBox::Cancel);
00202               
00203               if(res==QMessageBox::Cancel)
00204                      return;
00205                      
00206               int _oldHours=gt.rules.nHoursPerDay;
00207               gt.rules.nHoursPerDay=nHours;
00208               
00209               //time
00210               QList<TimeConstraint*> toBeRemovedTime;
00211               foreach(TimeConstraint* tc, gt.rules.timeConstraintsList){
00212                      if(tc->hasWrongDayOrHour(gt.rules)){
00213                             bool tmp=tc->canRepairWrongDayOrHour(gt.rules);
00214                             if(tmp){
00215                                    int tmp2=tc->repairWrongDayOrHour(gt.rules);
00216                                    assert(tmp2);
00217                             }
00218                             else{
00219                                    toBeRemovedTime.append(tc);
00220                             }
00221                      }
00222               }
00223               bool recomputeTime=false;
00224 
00225               if(toBeRemovedTime.count()>0){
00226                      foreach(TimeConstraint* tc, toBeRemovedTime){
00227                             if(tc->type==CONSTRAINT_ACTIVITY_PREFERRED_STARTING_TIME)
00228                                    recomputeTime=true;
00229                             bool tmp=gt.rules.removeTimeConstraint(tc);
00230                             assert(tmp);
00231                      }
00232               }
00234 
00235               //space
00236               QList<SpaceConstraint*> toBeRemovedSpace;
00237               foreach(SpaceConstraint* sc, gt.rules.spaceConstraintsList){
00238                      if(sc->hasWrongDayOrHour(gt.rules)){
00239                             bool tmp=sc->canRepairWrongDayOrHour(gt.rules);
00240                             if(tmp){
00241                                    int tmp2=sc->repairWrongDayOrHour(gt.rules);
00242                                    assert(tmp2);
00243                             }
00244                             else{
00245                                    toBeRemovedSpace.append(sc);
00246                             }
00247                      }
00248               }
00249 
00250               bool recomputeSpace=false;
00251               
00252               if(toBeRemovedSpace.count()>0){
00253                      foreach(SpaceConstraint* sc, toBeRemovedSpace){
00254                             if(sc->type==CONSTRAINT_ACTIVITY_PREFERRED_ROOM)
00255                                    recomputeSpace=true;
00256                             bool tmp=gt.rules.removeSpaceConstraint(sc);
00257                             assert(tmp);
00258                      }
00259               }
00261 
00262               gt.rules.nHoursPerDay=_oldHours;
00263 
00264               if(recomputeTime){
00265                      LockUnlock::computeLockedUnlockedActivitiesOnlyTime();
00266               }
00267               if(recomputeSpace){
00268                      assert(0);
00269                      LockUnlock::computeLockedUnlockedActivitiesOnlySpace();
00270               }
00271               if(recomputeTime || recomputeSpace){
00272                      LockUnlock::increaseCommunicationSpinBox();
00273               }
00274        }
00276 
00277        if(gt.rules.nHoursPerDay!=nHours){
00278               students_schedule_ready=false;
00279               teachers_schedule_ready=false;
00280               rooms_schedule_ready=false;
00281        }
00282 
00283        //remove old names
00284        for(int i=nHours; i<gt.rules.nHoursPerDay; i++)
00285               gt.rules.hoursOfTheDay[i]="";
00286               
00287        gt.rules.nHoursPerDay=nHours;
00288        for(int i=0; i<nHours; i++)
00289               gt.rules.hoursOfTheDay[i]=hoursNames[i]->text();
00290               
00291        gt.rules.nHoursPerWeek=gt.rules.nHoursPerDay*gt.rules.nDaysPerWeek; //not needed
00292        gt.rules.internalStructureComputed=false;
00293        setRulesModifiedAndOtherThings(&gt.rules);
00294 
00295        assert(gt.rules.nHoursPerDay<=MAX_HOURS_PER_DAY);
00296               
00297        this->close();
00298 }
00299 
00300 void HoursForm::cancel()
00301 {
00302        this->close();
00303 }