source: src/UIElements/Views/Qt4/QtHomologyList.cpp@ 0ac3e3

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Added_ParseSaveFragmentResults AddingActions_SaveParseParticleParameters Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_ParticleName_to_Atom Adding_StructOpt_integration_tests AtomFragments Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator CombiningParticlePotentialParsing Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_BoundInBox_CenterInBox_MoleculeActions Fix_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_PopActions Fix_QtFragmentList_sorted_selection Fix_Restrictedkeyset_FragmentMolecule Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns Fix_fitting_potentials Fixes ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion FragmentAction_writes_AtomFragments FragmentMolecule_checks_bonddegrees GeometryObjects Gui_Fixes Gui_displays_atomic_force_velocity ImplicitCharges IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix MoreRobust_FragmentAutomation ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PdbParser_setsAtomName PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks Rewrite_FitPartialCharges RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching SaturateAtoms_singleDegree StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg Switchable_LogView ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps TremoloParser_setsAtomName Ubuntu_1604_changes stable
Last change on this file since 0ac3e3 was 0ac3e3, checked in by Frederik Heber <heber@…>, 10 years ago

FIX: QSeisPlotPage takes up all remaining space in QtHomologyList.

  • Property mode set to 100644
File size: 9.5 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2013 Frederik Heber. All rights reserved.
5 *
6 *
7 * This file is part of MoleCuilder.
8 *
9 * MoleCuilder is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * MoleCuilder is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23/*
24 * QtHomologyList.cpp
25 *
26 * Created on: Jun 24, 2013
27 * Author: heber
28 */
29
30// include config.h
31#ifdef HAVE_CONFIG_H
32#include <config.h>
33#endif
34
35#include "Views/Qt4/QtHomologyList.hpp"
36
37#include <iterator>
38#include <iostream>
39
40#include <QAbstractItemView>
41#include <QtGui/QTreeWidget>
42#include <QtGui/QTabWidget>
43#include <Qt/qsplitter.h>
44#include <Qt/qboxlayout.h>
45
46#include "CodePatterns/MemDebug.hpp"
47
48#include "CodePatterns/Log.hpp"
49
50#include "Fragmentation/Homology/HomologyContainer.hpp"
51#include "FunctionApproximation/FunctionModel.hpp"
52#include "FunctionApproximation/TrainingData.hpp"
53#include "Potentials/CompoundPotential.hpp"
54#include "Potentials/EmpiricalPotential.hpp"
55#include "Potentials/InternalCoordinates/Coordinator.hpp"
56#include "Potentials/PotentialRegistry.hpp"
57#ifdef HAVE_QWT
58#include "UIElements/Views/Qt4/Plotting/QSeisData.hpp"
59#include "UIElements/Views/Qt4/Plotting/QSeisPageRegistry.hpp"
60#include "UIElements/Views/Qt4/Plotting/QSeisPlotCurve.hpp"
61#include "UIElements/Views/Qt4/Plotting/QSeisPlotPage.hpp"
62#include "UIElements/Views/Qt4/Plotting/QSeisCurveRegistry.hpp"
63#endif
64#include "World.hpp"
65
66using namespace std;
67
68const int QtHomologyList::COLUMNCOUNT = COLUMNTYPES_MAX;
69const char *QtHomologyList::COLUMNNAMES[QtHomologyList::COLUMNCOUNT]={"Number","Nodes","Edges","Occurrence"};
70
71QtHomologyList::QtHomologyList(QWidget * _parent) :
72 QWidget(_parent),
73 Observer("QtHomologyList"),
74 potentialregistry_enabled(false)
75{
76 QVBoxLayout* layout = new QVBoxLayout(this);
77 QSplitter *splitter = new QSplitter (Qt::Horizontal, this );
78 layout->addWidget(splitter);
79
80 // tree widget
81 treewidget = new QTreeWidget (splitter);
82 treewidget->setSelectionMode( QTreeWidget::SingleSelection );
83 treewidget->setColumnCount(COLUMNCOUNT);
84 QStringList header;
85 for(int i=0; i<COLUMNCOUNT;++i)
86 header << COLUMNNAMES[i];
87 treewidget->setHeaderLabels(header);
88 splitter->addWidget(treewidget);
89
90 // plot widget
91#ifdef HAVE_QWT
92 widget = new QSeisPlotPage ("energy", splitter);
93 QSeisPageRegistry::getInstance().registerInstance(widget);
94#else
95 widget = new QWidget(splitter);
96#endif
97 splitter->addWidget(widget);
98
99 dirty = true;
100 clearing = false;
101
102 refill();
103
104 HomologyContainer &homologies = World::getInstance().getHomologies();
105 homologies.signOn(this);
106 PotentialRegistry::getInstance().signOn(this);
107 potentialregistry_enabled = true;
108
109#ifdef HAVE_QWT
110 //connect the PlotCurveRegistry directly to the PlotPage registry
111 connect(QSeisCurveRegistry::getPointer(), SIGNAL(curveAdded(std::string, QString)), QSeisPageRegistry::getPointer(), SLOT(addCurve(std::string, QString)));
112 connect(QSeisCurveRegistry::getPointer(), SIGNAL(curveRemoved(std::string, QString)), QSeisPageRegistry::getPointer(), SLOT(removeCurve(std::string, QString)));
113 connect(QSeisCurveRegistry::getPointer(), SIGNAL(curveChanged(std::string, QString)), QSeisPageRegistry::getPointer(), SLOT(updateCurve(std::string, QString)));
114#endif
115
116 connect(treewidget,SIGNAL(itemSelectionChanged()),this,SLOT(rowSelected()));
117 connect(this,SIGNAL(changed()),this,SLOT(update()));
118}
119
120QtHomologyList::~QtHomologyList()
121{
122 HomologyContainer &homologies = World::getInstance().getHomologies();
123 homologies.signOff(this);
124 if (potentialregistry_enabled)
125 PotentialRegistry::getInstance().signOff(this);
126}
127
128void QtHomologyList::update(Observable *publisher) {
129
130 dirty = true;
131
132 // force an update from Qt...
133// clearing = true;
134// treewidget->clear();
135// clearing = false;
136 emit changed(); //doesn't work!?!
137}
138
139void QtHomologyList::refill()
140{
141 clearing = true;
142 const HomologyContainer &homologies = World::getInstance().getHomologies();
143
144 // clear everything
145 HomologySelection.clear();
146 treewidget->clear();
147#ifdef HAVE_QWT
148 QSeisCurveRegistry::getInstance().resetRegistry();
149#endif
150
151 size_t count = 0;
152 for (HomologyContainer::const_key_iterator homologyiter = homologies.key_begin();
153 homologyiter != homologies.key_end();
154 homologyiter = homologies.getNextKey(homologyiter), ++count) {
155 HomologyContainer::range_t occurences = homologies.getHomologousGraphs(*homologyiter);
156 const HomologyGraph &graph = occurences.first->first;
157 const size_t times = std::distance(occurences.first, occurences.second);
158
159 // create item
160 QTreeWidgetItem *treeItem = new QTreeWidgetItem(treewidget);
161 treeItem->setText(NUMBER, QString::number(count));
162 {
163 std::stringstream output;
164 graph.printNodes(output);
165 treeItem->setText(NODES, QString(output.str().c_str()));
166 }
167 {
168 std::stringstream output;
169 graph.printEdges(output);
170 treeItem->setText(EDGES, QString(output.str().c_str()));
171 }
172 if (times > 0) {
173 treeItem->setText(OCCURRENCE, QString::number(times));
174 } else {
175 treeItem->setText(OCCURRENCE, "none");
176 treeItem->setDisabled(true);
177 }
178 HomologySelection.push_back(treeItem->isSelected());
179
180#ifdef HAVE_QWT
181 // create associated curve in plot
182 CompoundPotential *compound = new CompoundPotential(graph);
183 ASSERT( compound != NULL,
184 "QtHomologyList::refill() - compound is NULL.");
185 TrainingData data(compound->getSpecificFilter());
186 data(homologies.getHomologousGraphs(graph));
187 if (!data.getTrainingInputs().empty()) {
188 // generate QSeisData
189 const TrainingData::InputVector_t &inputs = data.getAllArguments();
190 const TrainingData::OutputVector_t &outputs = data.getTrainingOutputs();
191 std::vector<double> xvalues;
192 std::vector<double> yvalues;
193 for (TrainingData::OutputVector_t::const_iterator outputiter = outputs.begin();
194 outputiter != outputs.end(); ++outputiter)
195 yvalues.push_back((*outputiter)[0]);
196
197 // go through each potential
198 for (CompoundPotential::models_t::const_iterator potiter = compound->begin();
199 potiter != compound->end();
200 ++potiter) {
201 const EmpiricalPotential &potential = dynamic_cast<const EmpiricalPotential &>(**potiter);
202 const std::string potentialname = potential.getName();
203 Coordinator::ptr coordinator = potential.getCoordinator();
204 // then we need to sample the potential
205 xvalues.clear();
206 for (TrainingData::InputVector_t::const_iterator inputiter = inputs.begin();
207 inputiter != inputs.end(); ++inputiter)
208 xvalues.push_back((*coordinator)(*inputiter));
209
210 // We need to sort the xvalues (and yvalues also)
211 std::vector<double>::const_iterator xiter = xvalues.begin();
212 std::vector<double>::const_iterator yiter = yvalues.begin();
213 std::map<double, std::set<double> > sorted_xy;
214 for (;xiter != xvalues.end(); ++xiter, ++yiter) {
215 std::set<double> yset;
216 yset.insert(*yiter);
217 std::pair<std::map<double, std::set<double> >::iterator, bool> inserter =
218 sorted_xy.insert(std::make_pair(*xiter, yset));
219 if (!inserter.second)
220 inserter.first->second.insert(*yiter);
221 }
222 xvalues.clear();
223 yvalues.clear();
224 for (std::map<double, std::set<double> >::const_iterator iter = sorted_xy.begin();
225 iter != sorted_xy.end(); ++iter) {
226 for (std::set<double>::const_iterator valueiter = iter->second.begin();
227 valueiter != iter->second.end();
228 ++valueiter) {
229 xvalues.push_back(iter->first);
230 yvalues.push_back(*valueiter);
231 }
232 }
233
234 QSeisData data(xvalues, yvalues, QString(potentialname.c_str()));
235 // couple to QSeisPlotCurve and register the curve
236 QSeisPlotCurve *curve = new QSeisPlotCurve(QString(potentialname.c_str()), "energy");
237 curve->updateCurve(&data);
238 if (!QSeisCurveRegistry::getInstance().isPresentByName(curve->getName()))
239 QSeisCurveRegistry::getInstance().registerInstance(curve);
240 else
241 delete curve;
242 // couple to QSeisPlotPage
243 widget->addCurve(potentialname);
244
245 }
246 }
247#endif
248 }
249 dirty = false;
250 clearing = false;
251}
252
253void QtHomologyList::paintEvent(QPaintEvent * event)
254{
255 if (dirty)
256 refill();
257// treewidget->paintEvent(event);
258}
259
260void QtHomologyList::subjectKilled(Observable *publisher)
261{
262 // as a new instance should always already be present ... just sign on
263 if (static_cast<PotentialRegistry *>(publisher) == PotentialRegistry::getPointer()) {
264 potentialregistry_enabled = false;
265 } else {
266 // its HomologyContainer
267 }
268}
269
270
271void QtHomologyList::rowSelected()
272{
273 //std::cout << "rowSelected\n";
274 for (int i=0;i<treewidget->topLevelItemCount();i++){
275 QTreeWidgetItem *item = treewidget->topLevelItem(i);
276 bool newSelection = item->isSelected();
277 if (newSelection != HomologySelection[i]){
278 // TODO: Add selected curve to QTabWidget
279 }
280 }
281}
282
Note: See TracBrowser for help on using the repository browser.