Back to index

fet  5.18.0
daysform.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 "timetable_defs.h"
00019 #include "timetable.h"
00020 #include "fet.h"
00021 
00022 #include "lockunlock.h"
00023 
00024 #include "daysform.h"
00025 
00026 #include <QLineEdit>
00027 #include <QMessageBox>
00028 
00029 extern Timetable gt;
00030 
00031 static QLineEdit* daysNames[35];
00032 static int nDays;
00033 
00034 extern bool students_schedule_ready;
00035 extern bool teachers_schedule_ready;
00036 extern bool rooms_schedule_ready;
00037 
00038 DaysForm::DaysForm(QWidget* parent): QDialog(parent)
00039 {
00040        setupUi(this);
00041 
00042        okPushButton->setDefault(true);
00043 
00044        connect(daysSpinBox, SIGNAL(valueChanged(int)), this, SLOT(daysChanged()));
00045        connect(cancelPushButton, SIGNAL(clicked()), this, SLOT(cancel()));
00046        connect(okPushButton, SIGNAL(clicked()), this, SLOT(ok()));
00047 
00048        centerWidgetOnScreen(this);
00049        restoreFETDialogGeometry(this);
00050        
00051        nDays=gt.rules.nDaysPerWeek;
00052        
00053        daysNames[0]=day1LineEdit;
00054        daysNames[1]=day2LineEdit;
00055        daysNames[2]=day3LineEdit;
00056        daysNames[3]=day4LineEdit;
00057        daysNames[4]=day5LineEdit;
00058        daysNames[5]=day6LineEdit;
00059        daysNames[6]=day7LineEdit;
00060 
00061        daysNames[7]=day8LineEdit;
00062        daysNames[8]=day9LineEdit;
00063        daysNames[9]=day10LineEdit;
00064        daysNames[10]=day11LineEdit;
00065        daysNames[11]=day12LineEdit;
00066        daysNames[12]=day13LineEdit;
00067        daysNames[13]=day14LineEdit;
00068 
00069        daysNames[14]=day15LineEdit;
00070        daysNames[15]=day16LineEdit;
00071        daysNames[16]=day17LineEdit;
00072        daysNames[17]=day18LineEdit;
00073        daysNames[18]=day19LineEdit;
00074        daysNames[19]=day20LineEdit;
00075        daysNames[20]=day21LineEdit;
00076 
00077        daysNames[21]=day22LineEdit;
00078        daysNames[22]=day23LineEdit;
00079        daysNames[23]=day24LineEdit;
00080        daysNames[24]=day25LineEdit;
00081        daysNames[25]=day26LineEdit;
00082        daysNames[26]=day27LineEdit;
00083        daysNames[27]=day28LineEdit;
00084 
00085        daysNames[28]=day29LineEdit;
00086        daysNames[29]=day30LineEdit;
00087        daysNames[30]=day31LineEdit;
00088        daysNames[31]=day32LineEdit;
00089        daysNames[32]=day33LineEdit;
00090        daysNames[33]=day34LineEdit;
00091        daysNames[34]=day35LineEdit;
00092 
00093        daysSpinBox->setMinimum(1);
00094        daysSpinBox->setMaximum(35);
00095        daysSpinBox->setValue(gt.rules.nDaysPerWeek);
00096 
00097        for(int i=0; i<35; i++)
00098               if(i<nDays){
00099                      daysNames[i]->setEnabled(true);
00100                      daysNames[i]->setText(gt.rules.daysOfTheWeek[i]);
00101               }
00102               else
00103                      daysNames[i]->setDisabled(true);
00104 }
00105 
00106 DaysForm::~DaysForm()
00107 {
00108        saveFETDialogGeometry(this);
00109 }
00110 
00111 void DaysForm::daysChanged()
00112 {
00113        nDays=daysSpinBox->value();
00114        assert(nDays <= MAX_DAYS_PER_WEEK);
00115        for(int i=0; i<35; i++)
00116               if(i<nDays)
00117                      daysNames[i]->setEnabled(true);
00118               else
00119                      daysNames[i]->setDisabled(true);
00120 }
00121 
00122 void DaysForm::ok()
00123 {
00124        for(int i=0; i<nDays; i++)
00125               if(daysNames[i]->text()==""){
00126                      QMessageBox::warning(this, tr("FET information"),
00127                             tr("Empty names not allowed"));
00128                      return;
00129               }
00130        for(int i=0; i<nDays-1; i++)
00131               for(int j=i+1; j<nDays; j++)
00132                      if(daysNames[i]->text()==daysNames[j]->text()){
00133                             QMessageBox::warning(this, tr("FET information"),
00134                                    tr("Duplicates not allowed"));
00135                             return;
00136                      }
00137        
00138        //2011-10-18
00139        int cnt_mod=0;
00140        int cnt_rem=0;
00141        int oldDays=gt.rules.nDaysPerWeek;
00142        gt.rules.nDaysPerWeek=nDays;
00143        
00144        foreach(TimeConstraint* tc, gt.rules.timeConstraintsList)
00145               if(tc->hasWrongDayOrHour(gt.rules)){
00146                      if(tc->canRepairWrongDayOrHour(gt.rules))
00147                             cnt_mod++;
00148                      else
00149                             cnt_rem++;
00150               }
00151 
00152        foreach(SpaceConstraint* sc, gt.rules.spaceConstraintsList)
00153               if(sc->hasWrongDayOrHour(gt.rules)){
00154                      if(sc->canRepairWrongDayOrHour(gt.rules))
00155                             cnt_mod++;
00156                      else
00157                             cnt_rem++;
00158               }
00159        
00160        gt.rules.nDaysPerWeek=oldDays;
00161                      
00162        if(cnt_mod>0 || cnt_rem>0){
00163               QString s=QString("");
00164               if(cnt_rem>0){
00165                      s+=tr("%1 constraints will be removed.", "%1 is the number of constraints").arg(cnt_rem);
00166                      s+=" ";
00167               }
00168               if(cnt_mod>0){
00169                      s+=tr("%1 constraints will be modified.", "%1 is the number of constraints").arg(cnt_mod);
00170                      s+=" ";
00171               }
00172               s+=tr("Do you want to continue?");
00173 
00174               int res=QMessageBox::warning(this, tr("FET warning"), s, QMessageBox::Yes|QMessageBox::Cancel);
00175               
00176               if(res==QMessageBox::Cancel)
00177                      return;
00178                      
00179               int _oldDays=gt.rules.nDaysPerWeek;
00180               gt.rules.nDaysPerWeek=nDays;
00181 
00182               //time
00183               QList<TimeConstraint*> toBeRemovedTime;
00184               foreach(TimeConstraint* tc, gt.rules.timeConstraintsList){
00185                      if(tc->hasWrongDayOrHour(gt.rules)){
00186                             bool tmp=tc->canRepairWrongDayOrHour(gt.rules);
00187                             if(tmp){
00188                                    int tmp2=tc->repairWrongDayOrHour(gt.rules);
00189                                    assert(tmp2);
00190                             }
00191                             else{
00192                                    toBeRemovedTime.append(tc);
00193                             }
00194                      }
00195               }
00196               bool recomputeTime=false;
00197 
00198               if(toBeRemovedTime.count()>0){
00199                      foreach(TimeConstraint* tc, toBeRemovedTime){
00200                             if(tc->type==CONSTRAINT_ACTIVITY_PREFERRED_STARTING_TIME)
00201                                    recomputeTime=true;
00202                             bool tmp=gt.rules.removeTimeConstraint(tc);
00203                             assert(tmp);
00204                      }
00205               }
00207 
00208               //space
00209               QList<SpaceConstraint*> toBeRemovedSpace;
00210               foreach(SpaceConstraint* sc, gt.rules.spaceConstraintsList){
00211                      if(sc->hasWrongDayOrHour(gt.rules)){
00212                             bool tmp=sc->canRepairWrongDayOrHour(gt.rules);
00213                             if(tmp){
00214                                    int tmp2=sc->repairWrongDayOrHour(gt.rules);
00215                                    assert(tmp2);
00216                             }
00217                             else{
00218                                    toBeRemovedSpace.append(sc);
00219                             }
00220                      }
00221               }
00222               
00223               bool recomputeSpace=false;
00224 
00225               if(toBeRemovedSpace.count()>0){
00226                      foreach(SpaceConstraint* sc, toBeRemovedSpace){
00227                             if(sc->type==CONSTRAINT_ACTIVITY_PREFERRED_ROOM)
00228                                    recomputeSpace=true;
00229                             bool tmp=gt.rules.removeSpaceConstraint(sc);
00230                             assert(tmp);
00231                      }
00232               }
00234 
00235               gt.rules.nDaysPerWeek=_oldDays;
00236 
00237               if(recomputeTime){
00238                      LockUnlock::computeLockedUnlockedActivitiesOnlyTime();
00239               }
00240               if(recomputeSpace){
00241                      assert(0);
00242                      LockUnlock::computeLockedUnlockedActivitiesOnlySpace();
00243               }
00244               if(recomputeTime || recomputeSpace){
00245                      LockUnlock::increaseCommunicationSpinBox();
00246               }
00247        }
00249 
00250        if(gt.rules.nDaysPerWeek!=nDays){
00251               students_schedule_ready=false;
00252               teachers_schedule_ready=false;
00253               rooms_schedule_ready=false;
00254        }
00255               
00256        //remove old names
00257        for(int i=nDays; i<gt.rules.nDaysPerWeek; i++)
00258               gt.rules.daysOfTheWeek[i]="";
00259 
00260        gt.rules.nDaysPerWeek=nDays;
00261        for(int i=0; i<nDays; i++)
00262               gt.rules.daysOfTheWeek[i]=daysNames[i]->text();
00263               
00264        gt.rules.nHoursPerWeek=gt.rules.nDaysPerWeek*gt.rules.nHoursPerDay; //not needed
00265        gt.rules.internalStructureComputed=false;
00266        setRulesModifiedAndOtherThings(&gt.rules);
00267 
00268        this->close();
00269 }
00270 
00271 void DaysForm::cancel()
00272 {
00273        this->close();
00274 }