VPTissue Reference Manual
VoronoiGeneratorDialog.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2011-2016 Universiteit Antwerpen
3  *
4  * Licensed under the EUPL, Version 1.1 or as soon they will be approved by
5  * the European Commission - subsequent versions of the EUPL (the "Licence");
6  * You may not use this work except in compliance with the Licence.
7  * You may obtain a copy of the Licence at: http://ec.europa.eu/idabc/eupl5
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the Licence is distributed on an "AS IS" basis,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the Licence for the specific language governing
13  * permissions and limitations under the Licence.
14  */
20 #include "VoronoiGeneratorDialog.h"
21 
22 #include "editor/PolygonUtils.h"
23 
24 #include "VoronoiTesselation.h"
25 #include <cassert>
26 #include <QBoxLayout>
27 #include <QBrush>
28 #include <QComboBox>
29 #include <QDialogButtonBox>
30 #include <QGraphicsPolygonItem>
31 #include <QGraphicsScene>
32 #include <QPen>
33 #include "gui/PanAndZoomView.h"
34 
35 class QColor;
36 class QWidget;
37 
38 namespace SimPT_Editor {
39 
40 using namespace SimShell;
41 using namespace SimShell::Gui;
42 
43 const double VoronoiGeneratorDialog::g_scene_margin = 2.0;
44 
45 VoronoiGeneratorDialog::VoronoiGeneratorDialog(const QPolygonF &boundaryPolygon, double initialScale, QWidget *parent)
46  : QDialog(parent)
47 {
48  SetupSceneItems(boundaryPolygon);
49  SetupGui(initialScale);
50 }
51 
53 {
54 }
55 
57 {
58  // Make the polygons counterclockwise (in the standard coordinate system).
59  std::list<QPolygonF> polygons;
60  for (QPolygonF& polygon : m_tesselation->GetCellPolygons()) {
61  polygons.push_back(PolygonUtils::Counterclockwise(polygon));
62  }
63 
64  return !polygons.empty() ? polygons : std::list<QPolygonF>({m_tesselation->polygon()});
65 }
66 
67 void VoronoiGeneratorDialog::SetupSceneItems(const QPolygonF &boundaryPolygon)
68 {
69  m_scene = new QGraphicsScene();
70  m_tesselation = new VoronoiTesselation(boundaryPolygon);
71  m_tesselation->setPen(QPen(QBrush(QColor(51, 102, 0, 255)), 0));
72  m_scene->addItem(m_tesselation);
73  m_scene->setSceneRect(m_tesselation->boundingRect().adjusted(
74  -g_scene_margin, -g_scene_margin, g_scene_margin, g_scene_margin));
75 }
76 
77 void VoronoiGeneratorDialog::SetupGui(double scale)
78 {
79  setWindowTitle("Voronoi cell pattern generator");
80  setMinimumSize(800, 500);
81 
82  // > GUI layout
83  QVBoxLayout *layout = new QVBoxLayout();
84 
85  // > Generator graphics view
86  PanAndZoomView *view = new PanAndZoomView();
87  view->setParent(this);
88  view->ScaleView(scale);
89  view->setScene(m_scene);
90  view->setRenderHints(QPainter::Antialiasing);
91 
92  layout->addWidget(view);
93  // < Generator graphics view
94 
95  // > Dialog button box layout
96  QHBoxLayout *controlsLayout = new QHBoxLayout();
97  controlsLayout->addStretch();
98 
99  // > Dialog button box
100  QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Cancel | QDialogButtonBox::Ok);
101  connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
102  connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
103  controlsLayout->addWidget(buttonBox);
104  // < Dialog button box
105 
106  layout->addLayout(controlsLayout);
107  // < Dialog button box layout
108 
109  setLayout(layout);
110  // < GUI layout
111 }
112 
113 } // namespace
QGraphicsView with the ability to pan and zoom.
Namespace for SimPT tissue editor package.
Definition: Cell.h:32
static QPolygonF Counterclockwise(const QPolygonF &polygon)
Checks if the order of the polygon's points is clockwise and if so, reverts it, else the original pol...
Interface for VoronoiGeneratorDialog.
Namespace for graphical interface classes.
Interface for PanAndZoomView.
VoronoiGeneratorDialog(const QPolygonF &boundaryPolygon, double initialScale=1.0, QWidget *parent=nullptr)
Constructor.
Interface for VoronoiTesselation.
see the online Qt documentation
std::list< QPolygonF > GetGeneratedPolygons() const
Retrieves the generated polygons after the dialog has successfully executed.
std::list< QPolygonF > GetCellPolygons()
Returns the polygons of cell of the Voronoi tesselation.
void ScaleView(double factor)
Scales the view, bounded by the minimum and maximum zooming factor.
Interface for PolygonUtils.
Namespace for generic graphical shell for simulators.
Definition: SimSession.h:32
see the online Qt documentation
Graphics item for Voronoi tesselation of a polygon.