AstRawDark
Manage your astrophoto dark frames
 All Classes Functions Variables Enumerations Enumerator Pages
matchDarksCommand.cpp
1 /*
2  * AstRawDark
3  *
4  * Copyright (C) 2015 - Frédéric CORNU
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #include "matchDarksCommand.h"
21 #include "data/dataStore.h"
22 #include "data/dto/imageInfo.h"
23 #include "processing/darkMatcher.h"
24 #include "processing/exceptions/noDarkForShootSettingsExcpetion.h"
25 #include "processing/exceptions/noDarkForTempException.h"
26 #include "commands/signalDispatcher.h"
27 
28 #ifndef QT_NO_DEBUG
29 #include <QDebug>
30 #endif
31 
32 MatchDarksCommand::MatchDarksCommand() {
33 
34  _description = QString(tr("Match darks"));
35 
36  connect(this,
40 
41 }
42 
43 MatchDarksCommand::~MatchDarksCommand() {
44 
45 
46 }
47 
49 
50  // Get needed darks count
51  int neededDarksCount = DataStore::getInstance()->getNeededDarks4Matching();
52 
53  // Get lights
54  QList<ImageInfo> lights = DataStore::getInstance()->getScannedLights();
55 
56  // Get all darks from library
57  QList<ImageInfo> allDarks = DataStore::getInstance()->getScannedDarks();
58 
59  #ifndef QT_NO_DEBUG
60  qDebug() << "Matching " << neededDarksCount << " darks";
61  #endif
62 
63  DarkMatcher matcher;
64 
65  _message = tr("Matching darks...");
66  emit statusChanged(this);
67 
68  try {
69 
70  matcher.match(lights, allDarks, neededDarksCount);
71 
72  _message = tr("%1 darks matched").arg(matcher.getMatchedDarks().size());
73  _reportMessages << tr("OK.");
74  _commandReport.addSection(tr("Completed successfully"),QStringList());
75 
76  emit statusChanged(this);
77  emit matchFound(matcher.getMatchedDarks());
78 
79  } catch ( NoDarkForShootSettingsExcpetion const& e ) {
80 
81  on_error(tr("ERROR - No darks available for your lights shooting settings"));
82 
83 
84  } catch ( NoDarkForTempException const& e) {
85 
86  on_error(tr("ERROR - Not enough darks for T = %1°C. Needed = %2, Available = %3")
87  .arg(e.getTemp())
88  .arg(e.getNeeded())
89  .arg(e.getAvailable()));
90  }
91 }
92 
93 void MatchDarksCommand::on_error(const QString msg) {
94 
95  _error = true;
96  _reportMessages << msg;
97  _commandReport.addSection(msg, QStringList());
98 }