35 #include <QDialogButtonBox> 
   36 #include <QGraphicsScene> 
   37 #include <QGraphicsPolygonItem> 
   50 class RegularGeneratorDialog::ITileFactory
 
   53         virtual ~ITileFactory() {}
 
   54         virtual Tile *Create() 
const = 0;
 
   60 template <
class TileType>
 
   61 class RegularGeneratorDialog::TileFactory : 
public RegularGeneratorDialog::ITileFactory
 
   64         virtual ~TileFactory() {}
 
   65         virtual Tile *Create()
 const { 
return new TileType(); }
 
   68 const double RegularGeneratorDialog::g_scene_margin = 2.0;
 
   69 const std::vector<std::pair<std::shared_ptr<const RegularGeneratorDialog::ITileFactory>, std::string>> RegularGeneratorDialog::g_tile_factories{
 
   70                 std::make_pair(std::make_shared<TileFactory<RectangularTile>>(), 
"Rectangles"),
 
   71                 std::make_pair(std::make_shared<TileFactory<TriangularTile>>(), 
"Triangles"),
 
   72                 std::make_pair(std::make_shared<TileFactory<DiamondTile>>(), 
"Diamonds"),
 
   73                 std::make_pair(std::make_shared<TileFactory<HexagonalTile>>(), 
"Hexagons")};
 
   78         SetupSceneItems(boundaryPolygon);
 
   79         SetupGui(initialScale);
 
   88         std::list<QPolygonF> polygons;
 
   89         for (
const QPolygonF& polygon : m_tiling->
GetPolygons()) {
 
   98 void RegularGeneratorDialog::UpdateTiling(
int index)
 
  101         m_tiling = 
new RegularTiling(g_tile_factories[index].first->Create(), m_boundary->boundingRect(), m_boundary);
 
  102         UpdateTransformation();
 
  105 void RegularGeneratorDialog::UpdateTransformation()
 
  107         QTransform transformation;
 
  109         QPointF polygonCenter = m_boundary->boundingRect().center();
 
  112         transformation.translate(polygonCenter.x(), polygonCenter.y());
 
  113         transformation.rotate(m_transformation->
GetRotation());
 
  115         transformation.translate(-polygonCenter.x(), -polygonCenter.y());
 
  117         m_tiling->setTransform(transformation);
 
  120 void RegularGeneratorDialog::SetupSceneItems(
const QPolygonF &boundaryPolygon)
 
  122         m_scene = 
new QGraphicsScene();
 
  125         m_boundary->setPen(QPen(QBrush(QColor(51, 102, 0, 255)), 0));
 
  126         m_scene->addItem(m_boundary);
 
  128         m_boundary->setFlag(QGraphicsItem::ItemClipsChildrenToShape, 
true);
 
  129         m_tiling = 
new RegularTiling(g_tile_factories[0].first->Create(), m_boundary->boundingRect(), m_boundary);
 
  131         m_scene->setSceneRect(m_boundary->boundingRect().adjusted(-g_scene_margin, -g_scene_margin, g_scene_margin, g_scene_margin));
 
  134 void RegularGeneratorDialog::SetupGui(
double scale)
 
  136         setWindowTitle(
"Regular cell pattern generator");
 
  137         setMinimumSize(800, 500);
 
  140         QHBoxLayout *layout = 
new QHBoxLayout();
 
  144         view->setParent(
this);
 
  146         view->setScene(m_scene);
 
  147         view->setRenderHints(QPainter::Antialiasing);
 
  149         layout->addWidget(view, 3);
 
  153         QVBoxLayout *controlsLayout = 
new QVBoxLayout();
 
  156         QComboBox *tilingSelection = 
new QComboBox();
 
  157         for (
auto pair : g_tile_factories) {
 
  158                 tilingSelection->addItem(QString::fromStdString(pair.second));
 
  160         tilingSelection->setCurrentIndex(0);
 
  161         connect(tilingSelection, SIGNAL(currentIndexChanged(
int)), 
this, SLOT(UpdateTiling(
int)));
 
  162         controlsLayout->addWidget(tilingSelection);
 
  165         QFrame *line = 
new QFrame();
 
  166         line->setFrameShape(QFrame::HLine);
 
  167         line->setFrameShadow(QFrame::Sunken);
 
  168         controlsLayout->addWidget(line);
 
  171         m_transformation = 
new TransformationWidget(10, m_boundary->boundingRect().width() / 2, m_boundary->boundingRect().height() / 2);
 
  172         connect(m_transformation, SIGNAL(TransformationChanged()), 
this, SLOT(UpdateTransformation()));
 
  173         controlsLayout->addWidget(m_transformation);
 
  176         controlsLayout->addStretch();
 
  179         QDialogButtonBox *buttonBox = 
new QDialogButtonBox(QDialogButtonBox::Cancel | QDialogButtonBox::Ok);
 
  180         connect(buttonBox, SIGNAL(accepted()), 
this, SLOT(accept()));
 
  181         connect(buttonBox, SIGNAL(rejected()), 
this, SLOT(reject()));
 
  182         controlsLayout->addWidget(buttonBox);
 
  185         layout->addLayout(controlsLayout, 1);
 
QGraphicsView with the ability to pan and zoom. 
 
static QPolygonF OpenPolygon(const QPolygonF &polygon)
Opens the polygon, ie. 
 
Namespace for SimPT tissue editor package. 
 
Combo header for circular iterator. 
 
Interface for RegularGeneratorDialog. 
 
static std::list< QPolygonF > ClipPolygon(const QPolygonF &polygon1, const QPolygonF &polygon2)
Clip a polygon with another polygon and return the intersecting subpolygons. 
 
Interface for TriangularTile. 
 
see the online Qt documentation 
 
Interface for DiamondTile. 
 
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...
 
Namespace for graphical interface classes. 
 
double GetTranslationY()
Gets the y translation of the transformation. 
 
Interface for TransformationWidget. 
 
int GetRotation()
Gets the rotation of the transformation. 
 
Interface for RegularTiling. 
 
virtual ~RegularGeneratorDialog()
Destructor. 
 
Interface for PanAndZoomView. 
 
std::list< QPolygonF > GetPolygons() const 
Get the polygons associated with this tiling. 
 
Interface for HexagonalTile. 
 
double GetScalingX()
Gets the x scaling of the transformation. 
 
double GetTranslationX()
Gets the x translation of the transformation. 
 
Class of a cell tiling with regular polygons. 
 
double GetScalingY()
Gets the y scaling of the transformation. 
 
see the online Qt documentation 
 
std::list< QPolygonF > GetGeneratedPolygons() const 
Retrieves the generated polygons after the dialog has successfully executed. 
 
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. 
 
see the online Qt documentation 
 
RegularGeneratorDialog(const QPolygonF &boundaryPolygon, double initialScale=1.0, QWidget *parent=nullptr)
Constructor. 
 
Interface for RectangularTile.