1 /***************************************************************************
2                           addconstraintteachersmingapsbetweenbuildingchangesform.cpp  -  description
3                              -------------------
4     begin                : Feb 10, 2005
5     copyright            : (C) 2005 by Lalescu Liviu
6     email                : Please see https://lalescu.ro/liviu/ for details about contacting Liviu Lalescu (in particular, you can find here the e-mail address)
7  ***************************************************************************/
8 
9 /***************************************************************************
10  *                                                                         *
11  *   This program is free software: you can redistribute it and/or modify  *
12  *   it under the terms of the GNU Affero General Public License as        *
13  *   published by the Free Software Foundation, either version 3 of the    *
14  *   License, or (at your option) any later version.                       *
15  *                                                                         *
16  ***************************************************************************/
17 
18 #include <QMessageBox>
19 
20 #include "longtextmessagebox.h"
21 
22 #include "addconstraintteachersmingapsbetweenbuildingchangesform.h"
23 #include "spaceconstraint.h"
24 
AddConstraintTeachersMinGapsBetweenBuildingChangesForm(QWidget * parent)25 AddConstraintTeachersMinGapsBetweenBuildingChangesForm::AddConstraintTeachersMinGapsBetweenBuildingChangesForm(QWidget* parent): QDialog(parent)
26 {
27 	setupUi(this);
28 
29 	addConstraintPushButton->setDefault(true);
30 
31 	connect(addConstraintPushButton, SIGNAL(clicked()), this, SLOT(addCurrentConstraint()));
32 	connect(closePushButton, SIGNAL(clicked()), this, SLOT(close()));
33 
34 	centerWidgetOnScreen(this);
35 	restoreFETDialogGeometry(this);
36 
37 	minGapsSpinBox->setMinimum(1);
38 	minGapsSpinBox->setMaximum(gt.rules.nHoursPerDay);
39 	minGapsSpinBox->setValue(1);
40 }
41 
~AddConstraintTeachersMinGapsBetweenBuildingChangesForm()42 AddConstraintTeachersMinGapsBetweenBuildingChangesForm::~AddConstraintTeachersMinGapsBetweenBuildingChangesForm()
43 {
44 	saveFETDialogGeometry(this);
45 }
46 
addCurrentConstraint()47 void AddConstraintTeachersMinGapsBetweenBuildingChangesForm::addCurrentConstraint()
48 {
49 	SpaceConstraint *ctr=nullptr;
50 
51 	double weight;
52 	QString tmp=weightLineEdit->text();
53 	weight_sscanf(tmp, "%lf", &weight);
54 	if(weight<100.0 || weight>100.0){
55 		QMessageBox::warning(this, tr("FET information"),
56 			tr("Invalid weight (percentage). It has to be 100"));
57 		return;
58 	}
59 
60 	ctr=new ConstraintTeachersMinGapsBetweenBuildingChanges(weight, minGapsSpinBox->value());
61 
62 	bool tmp2=gt.rules.addSpaceConstraint(ctr);
63 	if(tmp2)
64 		LongTextMessageBox::information(this, tr("FET information"),
65 			tr("Constraint added:")+"\n\n"+ctr->getDetailedDescription(gt.rules));
66 	else{
67 		QMessageBox::warning(this, tr("FET information"),
68 			tr("Constraint NOT added - please report error"));
69 		delete ctr;
70 	}
71 }
72