Skip to content

Commit da4259e

Browse files
committed
adding selection of vertex shapes in settings
1 parent 7628e2d commit da4259e

File tree

7 files changed

+100
-11
lines changed

7 files changed

+100
-11
lines changed

BasicDrawPane.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ void BasicDrawPane::paintEvent(wxPaintEvent & evt)
115115
* at any time. Using this generally does not free you from
116116
* catching paint events, since it is possible that e.g. the window
117117
* manager throws away your drawing when the window comes to the
118-
* background, and expects you will redraw it when the window comes
118+
* background and expects you will redraw it when the window comes
119119
* back (by sending a paint event).
120120
*
121121
* In most cases, this will not be needed at all; simply handling
@@ -131,7 +131,7 @@ void BasicDrawPane::paintNow()
131131
/*
132132
* Here we do the actual rendering. I put it in a separate
133133
* method so that it can work no matter what type of DC
134-
* (e.g. wxPaintDC or wxClientDC) is used.
134+
* (e.g., wxPaintDC or wxClientDC) is used.
135135
*/
136136
void BasicDrawPane::render(wxPaintDC& dc) {
137137

@@ -145,7 +145,7 @@ void BasicDrawPane::render(wxPaintDC& dc) {
145145
gc->SetPen(wxPen(wxColor(0, 0, 0), 1)); // black line, 3 pixels thick
146146
gc->DrawRectangle(0,0,dc.GetSize().GetWidth(),dc.GetSize().GetHeight());
147147
try {
148-
const Graph& g = ((CGTeaFrame*)this->m_parent)->currentGraph;
148+
const Graph& g = static_cast<CGTeaFrame*>(this->m_parent)->currentGraph;
149149
drawEdges(g, gc);
150150
drawVertices(g, gc);
151151
} catch (std::exception &e) {
@@ -194,7 +194,7 @@ void BasicDrawPane::drawEdges(const Graph &g, wxGraphicsContext* gc) {
194194
// });
195195
// }
196196

197-
void BasicDrawPane::drawShape(wxGraphicsContext* gc, VertexShape shape,
197+
void BasicDrawPane::drawShape(wxGraphicsContext* gc, const VertexShape shape,
198198
const cgtea_geometry::Point& pos, double size) {
199199
switch(shape) {
200200
case VertexShape::Square:
@@ -248,7 +248,10 @@ void BasicDrawPane::drawVertices(const Graph &g, wxGraphicsContext* gc) {
248248
for_each_v_const(g, [&](Ver v) {
249249
const int color = boost::get(vertex_color, g, v);
250250
const cgtea_geometry::Point pos = boost::get(boost::vertex_distance, g, v);
251-
auto shape = VertexShape::Diamond;
251+
//auto shape = VertexShape::Diamond;
252+
const auto frame = static_cast<CGTeaFrame*>(this->m_parent);
253+
const auto shape = frame ? frame->getCurrentVertexShape() : VertexShape::Circle;
254+
252255

253256
// Draw a white background
254257
gc->SetPen(wxPen(wxColor(255, 0, 0), 1));

BasicDrawPane.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@
88
#include <wx/wxprec.h>
99
#ifndef WX_PRECOMP
1010
#include <wx/wx.h>
11-
#include <wx/sizer.h>
1211
#include "datatypes.h"
1312
#include <string>
1413
#endif
15-
#include <exception>
1614
#include <wx/graphics.h>
1715
#include <map>
1816

CGTeaFrame.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,10 @@
4040

4141
#include <memory>
4242

43+
#include "SettingsDialog.h"
44+
4345
wxBEGIN_EVENT_TABLE(CGTeaFrame, wxFrame)
44-
EVT_MENU(wxID_ABOUT, CGTeaFrame::OnAbout)
46+
EVT_MENU(wxID_ABOUT, CGTeaFrame::OnAbout)
4547
wxEND_EVENT_TABLE()
4648

4749
CGTeaFrame::CGTeaFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
@@ -80,11 +82,14 @@ CGTeaFrame::CGTeaFrame(const wxString& title, const wxPoint& pos, const wxSize&
8082
auto menuFile = std::make_unique<wxMenu>();
8183
menuFile->Append(1000, "&Open");
8284
menuFile->Append(1001, "&Save");
85+
menuFile->Append(1002, "&Settings");
8386
menuFile->AppendSeparator();
8487
menuFile->Append(wxID_EXIT);
8588

8689
Connect(1000, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(CGTeaFrame::Open));
8790
Connect(1001, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(CGTeaFrame::Save));
91+
Connect(1002, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(CGTeaFrame::OnSettings));
92+
8893
Connect(wxID_EXIT, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(CGTeaFrame::OnExit));
8994

9095
auto menuGenerate = std::make_unique<wxMenu>();
@@ -283,4 +288,12 @@ void CGTeaFrame::Save(wxCommandEvent& event) {
283288
out.flush();
284289
out.close();
285290
cerr << g6 << endl;
286-
}
291+
}
292+
293+
void CGTeaFrame::OnSettings(wxCommandEvent& event) {
294+
SettingsDialog dialog(this);
295+
if (dialog.ShowModal() == wxID_OK) {
296+
currentVertexShape = dialog.GetSelectedShape();
297+
Refresh(); // Redraw the graph with the new vertex shape
298+
}
299+
}

CGTeaFrame.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class CGTeaFrame: public wxFrame {
2525
Graph currentGraph;
2626

2727
CGTeaFrame(const wxString &title, const wxPoint &pos, const wxSize &size);
28+
VertexShape getCurrentVertexShape() const { return currentVertexShape; }
2829

2930
std::vector<std::unique_ptr<GeneratorInterface>> availableGenerators;
3031
std::vector<std::unique_ptr<ReportInterface>> availableReports;
@@ -44,6 +45,11 @@ class CGTeaFrame: public wxFrame {
4445
void Open(wxCommandEvent &event);
4546
void Save(wxCommandEvent &event);
4647

48+
void OnSettings(wxCommandEvent& event);
49+
50+
VertexShape currentVertexShape = VertexShape::Circle;
51+
52+
4753
wxDECLARE_EVENT_TABLE();
4854
};
4955

CMakeLists.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ file(GLOB ConjectureCheck "ConjectureCheck/*.cpp")
1313
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage")
1414
#set( CMAKE_CXX_FLAGS "`wx-config --cxxflags --libs`")
1515
add_executable(CGTea CGTeaApp.cpp BasicDrawPane.cpp CGTeaFrame.cpp CGTeaSidebar.cpp ${Reports} ${Generators} ${Actions}
16-
const_values.h)
17-
add_executable(BoostTest ${Reports} ${Generators} ${BoostTestSrc} ${ConjectureCheck} ${Actions})
16+
const_values.h
17+
SettingsDialog.cpp
18+
SettingsDialog.h)
19+
add_executable(BoostTest ${Reports} ${Generators} ${BoostTestSrc} ${ConjectureCheck} ${Actions}
20+
SettingsDialog.cpp
21+
SettingsDialog.h)
1822
target_link_libraries(CGTea ${wxWidgets_LIBRARIES} ${Boost_LIBRARIES})
1923
target_link_libraries(BoostTest ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})

SettingsDialog.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//
2+
// Created by rostam on 15.05.25.
3+
//
4+
5+
#include "SettingsDialog.h"
6+
7+
8+
SettingsDialog::SettingsDialog(wxWindow* parent)
9+
: wxDialog(parent, wxID_ANY, "Settings", wxDefaultPosition, wxDefaultSize)
10+
{
11+
wxBoxSizer* mainSizer = new wxBoxSizer(wxVERTICAL);
12+
13+
wxArrayString shapeChoices;
14+
shapeChoices.Add("Circle");
15+
shapeChoices.Add("Square");
16+
shapeChoices.Add("Triangle");
17+
shapeChoices.Add("Diamond");
18+
19+
shapeRadioBox = new wxRadioBox(this, wxID_ANY, "Vertex Shape",
20+
wxDefaultPosition, wxDefaultSize,
21+
shapeChoices, 1, wxRA_SPECIFY_COLS);
22+
23+
mainSizer->Add(shapeRadioBox, 0, wxALL | wxEXPAND, 5);
24+
25+
wxStdDialogButtonSizer* buttonSizer = new wxStdDialogButtonSizer();
26+
buttonSizer->AddButton(new wxButton(this, wxID_OK));
27+
buttonSizer->AddButton(new wxButton(this, wxID_CANCEL));
28+
buttonSizer->Realize();
29+
mainSizer->Add(buttonSizer, 0, wxALL | wxEXPAND, 5);
30+
31+
SetSizer(mainSizer);
32+
mainSizer->Fit(this);
33+
}
34+
35+
VertexShape SettingsDialog::GetSelectedShape() const {
36+
switch (shapeRadioBox->GetSelection()) {
37+
case 0: return VertexShape::Circle;
38+
case 1: return VertexShape::Square;
39+
case 2: return VertexShape::Triangle;
40+
case 3: return VertexShape::Diamond;
41+
default: return VertexShape::Circle;
42+
}
43+
}

SettingsDialog.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//
2+
// Created by rostam on 15.05.25.
3+
//
4+
5+
#ifndef CGTEA_SETTINGSDIALOG_H
6+
#define CGTEA_SETTINGSDIALOG_H
7+
8+
#include <wx/wx.h>
9+
#include <wx/radiobox.h>
10+
#include "const_values.h"
11+
12+
class SettingsDialog : public wxDialog {
13+
public:
14+
explicit SettingsDialog(wxWindow* parent);
15+
VertexShape GetSelectedShape() const;
16+
17+
private:
18+
wxRadioBox* shapeRadioBox;
19+
};
20+
21+
#endif //CGTEA_SETTINGSDIALOG_H
22+

0 commit comments

Comments
 (0)