Skip to content

Commit 91078ed

Browse files
committed
settings and config added
1 parent da4259e commit 91078ed

File tree

8 files changed

+220
-14
lines changed

8 files changed

+220
-14
lines changed

BasicDrawPane.cpp

Lines changed: 121 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -156,19 +156,19 @@ void BasicDrawPane::render(wxPaintDC& dc) {
156156

157157
}
158158

159-
void BasicDrawPane::drawEdges(const Graph &g, wxGraphicsContext* gc) {
160-
for_each_e_const(g, [&](Edge e) {
161-
const Ver src = boost::source(e,g);
162-
const Ver tgt = boost::target(e,g);
163-
const cgtea_geometry::Point src_pos = boost::get(boost::vertex_distance, g, src);
164-
const cgtea_geometry::Point tgt_pos = boost::get(boost::vertex_distance, g, tgt);
165-
gc->SetPen(wxPen(wxColor(0, 0, 0), 2)); // black line, 3 pixels thick
166-
wxGraphicsPath path = gc->CreatePath();
167-
path.MoveToPoint(src_pos.x, src_pos.y);
168-
path.AddLineToPoint(tgt_pos.x, tgt_pos.y);
169-
gc->StrokePath(path);
170-
});
171-
}
159+
// void BasicDrawPane::drawEdges(const Graph &g, wxGraphicsContext* gc) {
160+
// for_each_e_const(g, [&](Edge e) {
161+
// const Ver src = boost::source(e,g);
162+
// const Ver tgt = boost::target(e,g);
163+
// const cgtea_geometry::Point src_pos = boost::get(boost::vertex_distance, g, src);
164+
// const cgtea_geometry::Point tgt_pos = boost::get(boost::vertex_distance, g, tgt);
165+
// gc->SetPen(wxPen(wxColor(0, 0, 0), 2)); // black line, 3 pixels thick
166+
// wxGraphicsPath path = gc->CreatePath();
167+
// path.MoveToPoint(src_pos.x, src_pos.y);
168+
// path.AddLineToPoint(tgt_pos.x, tgt_pos.y);
169+
// gc->StrokePath(path);
170+
// });
171+
// }
172172

173173
// void BasicDrawPane::drawVertices(const Graph &g, wxGraphicsContext* gc) {
174174
// for_each_v_const(g, [&](Ver v) {
@@ -271,3 +271,111 @@ void BasicDrawPane::drawVertices(const Graph &g, wxGraphicsContext* gc) {
271271
gc->DrawText(mystring, pos.x-w/2, pos.y-h/2);
272272
});
273273
}
274+
275+
void BasicDrawPane::drawEdgeShape(wxGraphicsContext* gc, EdgeShape shape,
276+
const cgtea_geometry::Point& src,
277+
const cgtea_geometry::Point& tgt) {
278+
switch(shape) {
279+
case EdgeShape::Curve:
280+
drawCurve(gc, src, tgt);
281+
break;
282+
case EdgeShape::DoubleArrow:
283+
drawDoubleArrow(gc, src, tgt);
284+
break;
285+
case EdgeShape::Dashed:
286+
drawDashed(gc, src, tgt);
287+
break;
288+
case EdgeShape::Line:
289+
default:
290+
drawLine(gc, src, tgt);
291+
break;
292+
}
293+
}
294+
295+
void BasicDrawPane::drawLine(wxGraphicsContext* gc,
296+
const cgtea_geometry::Point& src,
297+
const cgtea_geometry::Point& tgt) {
298+
wxGraphicsPath path = gc->CreatePath();
299+
path.MoveToPoint(src.x, src.y);
300+
path.AddLineToPoint(tgt.x, tgt.y);
301+
gc->StrokePath(path);
302+
}
303+
304+
void BasicDrawPane::drawCurve(wxGraphicsContext* gc,
305+
const cgtea_geometry::Point& src,
306+
const cgtea_geometry::Point& tgt) {
307+
wxGraphicsPath path = gc->CreatePath();
308+
path.MoveToPoint(src.x, src.y);
309+
// Calculate control point for quadratic curve
310+
double midX = (src.x + tgt.x) / 2;
311+
double midY = (src.y + tgt.y) / 2;
312+
double offsetY = 30; // Curve height
313+
path.AddQuadCurveToPoint(midX, midY - offsetY, tgt.x, tgt.y);
314+
gc->StrokePath(path);
315+
}
316+
317+
void BasicDrawPane::drawDoubleArrow(wxGraphicsContext* gc,
318+
const cgtea_geometry::Point& src,
319+
const cgtea_geometry::Point& tgt) {
320+
// Draw main line
321+
drawLine(gc, src, tgt);
322+
323+
// Calculate arrow parameters
324+
double angle = atan2(tgt.y - src.y, tgt.x - src.x);
325+
double arrowLength = 15;
326+
double arrowAngle = M_PI / 6; // 30 degrees
327+
328+
// Draw arrows at both ends
329+
for(const auto& point : {src, tgt}) {
330+
double baseAngle = (point.x == src.x && point.y == src.y) ?
331+
angle + M_PI : angle;
332+
333+
wxGraphicsPath arrowPath = gc->CreatePath();
334+
arrowPath.MoveToPoint(point.x, point.y);
335+
arrowPath.AddLineToPoint(
336+
point.x + arrowLength * cos(baseAngle + arrowAngle),
337+
point.y + arrowLength * sin(baseAngle + arrowAngle)
338+
);
339+
arrowPath.MoveToPoint(point.x, point.y);
340+
arrowPath.AddLineToPoint(
341+
point.x + arrowLength * cos(baseAngle - arrowAngle),
342+
point.y + arrowLength * sin(baseAngle - arrowAngle)
343+
);
344+
gc->StrokePath(arrowPath);
345+
}
346+
}
347+
348+
void BasicDrawPane::drawDashed(wxGraphicsContext* gc,
349+
const cgtea_geometry::Point& src,
350+
const cgtea_geometry::Point& tgt) {
351+
// Create a new dashed pen
352+
wxPen dashedPen(wxColor(0, 0, 0), 2); // Match the regular pen style
353+
wxDash dashes[] = {5, 5}; // 5 pixel dash, 5 pixel gap
354+
dashedPen.SetDashes(2, dashes);
355+
dashedPen.SetStyle(wxPENSTYLE_USER_DASH);
356+
gc->SetPen(dashedPen);
357+
358+
// Draw the dashed line
359+
wxGraphicsPath path = gc->CreatePath();
360+
path.MoveToPoint(src.x, src.y);
361+
path.AddLineToPoint(tgt.x, tgt.y);
362+
gc->StrokePath(path);
363+
364+
// Reset to solid pen
365+
gc->SetPen(wxPen(wxColor(0, 0, 0), 2));
366+
}
367+
368+
void BasicDrawPane::drawEdges(const Graph &g, wxGraphicsContext* gc) {
369+
for_each_e_const(g, [&](Edge e) {
370+
const Ver src = boost::source(e,g);
371+
const Ver tgt = boost::target(e,g);
372+
const cgtea_geometry::Point src_pos = boost::get(boost::vertex_distance, g, src);
373+
const cgtea_geometry::Point tgt_pos = boost::get(boost::vertex_distance, g, tgt);
374+
gc->SetPen(wxPen(wxColor(0, 0, 0), 2));
375+
376+
const auto frame = static_cast<CGTeaFrame*>(this->m_parent);
377+
const auto edgeShape = frame ? frame->getCurrentEdgeShape() : EdgeShape::Line;
378+
379+
drawEdgeShape(gc, edgeShape, src_pos, tgt_pos);
380+
});
381+
}

BasicDrawPane.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,23 @@ class BasicDrawPane : public wxPanel
3434
void drawTriangle(wxGraphicsContext* gc, const cgtea_geometry::Point& pos, double size);
3535
void drawDiamond(wxGraphicsContext* gc, const cgtea_geometry::Point& pos, double size);
3636

37+
void drawEdgeShape(wxGraphicsContext* gc, EdgeShape shape,
38+
const cgtea_geometry::Point& src,
39+
const cgtea_geometry::Point& tgt);
40+
void drawLine(wxGraphicsContext* gc,
41+
const cgtea_geometry::Point& src,
42+
const cgtea_geometry::Point& tgt);
43+
void drawCurve(wxGraphicsContext* gc,
44+
const cgtea_geometry::Point& src,
45+
const cgtea_geometry::Point& tgt);
46+
void drawDoubleArrow(wxGraphicsContext* gc,
47+
const cgtea_geometry::Point& src,
48+
const cgtea_geometry::Point& tgt);
49+
void drawDashed(wxGraphicsContext* gc,
50+
const cgtea_geometry::Point& src,
51+
const cgtea_geometry::Point& tgt);
52+
53+
3754
void mouseMoved(wxMouseEvent& event);
3855
void mouseDown(wxMouseEvent& event);
3956
void mouseWheelMoved(wxMouseEvent& event);

CGTeaFrame.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040

4141
#include <memory>
4242

43+
#include "Config.h"
4344
#include "SettingsDialog.h"
4445

4546
wxBEGIN_EVENT_TABLE(CGTeaFrame, wxFrame)
@@ -294,6 +295,9 @@ void CGTeaFrame::OnSettings(wxCommandEvent& event) {
294295
SettingsDialog dialog(this);
295296
if (dialog.ShowModal() == wxID_OK) {
296297
currentVertexShape = dialog.GetSelectedShape();
298+
currentEdgeShape = dialog.GetSelectedEdgeShape();
299+
Config::SaveVertexShape(currentVertexShape);
300+
Config::SaveEdgeShape(currentEdgeShape);
297301
Refresh(); // Redraw the graph with the new vertex shape
298302
}
299303
}

CGTeaFrame.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ class CGTeaFrame: public wxFrame {
2626

2727
CGTeaFrame(const wxString &title, const wxPoint &pos, const wxSize &size);
2828
VertexShape getCurrentVertexShape() const { return currentVertexShape; }
29+
EdgeShape getCurrentEdgeShape() const { return currentEdgeShape; }
30+
2931

3032
std::vector<std::unique_ptr<GeneratorInterface>> availableGenerators;
3133
std::vector<std::unique_ptr<ReportInterface>> availableReports;
@@ -48,6 +50,8 @@ class CGTeaFrame: public wxFrame {
4850
void OnSettings(wxCommandEvent& event);
4951

5052
VertexShape currentVertexShape = VertexShape::Circle;
53+
EdgeShape currentEdgeShape = EdgeShape::Line;
54+
5155

5256

5357
wxDECLARE_EVENT_TABLE();

Config.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#ifndef CGTEA_CONFIG_H
2+
#define CGTEA_CONFIG_H
3+
4+
#include <wx/config.h>
5+
#include "const_values.h"
6+
7+
class Config {
8+
public:
9+
static void SaveVertexShape(VertexShape shape) {
10+
wxConfig::Get()->Write("/Settings/VertexShape", static_cast<int>(shape));
11+
}
12+
13+
static void SaveEdgeShape(EdgeShape shape) {
14+
wxConfig::Get()->Write("/Settings/EdgeShape", static_cast<int>(shape));
15+
}
16+
17+
static VertexShape LoadVertexShape() {
18+
int shape;
19+
if (wxConfig::Get()->Read("/Settings/VertexShape", &shape)) {
20+
return static_cast<VertexShape>(shape);
21+
}
22+
return VertexShape::Circle; // default
23+
}
24+
25+
static EdgeShape LoadEdgeShape() {
26+
int shape;
27+
if (wxConfig::Get()->Read("/Settings/EdgeShape", &shape)) {
28+
return static_cast<EdgeShape>(shape);
29+
}
30+
return EdgeShape::Line; // default
31+
}
32+
};
33+
34+
#endif //CGTEA_CONFIG_H

SettingsDialog.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
#include "SettingsDialog.h"
66

7+
#include "Config.h"
8+
79

810
SettingsDialog::SettingsDialog(wxWindow* parent)
911
: wxDialog(parent, wxID_ANY, "Settings", wxDefaultPosition, wxDefaultSize)
@@ -20,7 +22,21 @@ SettingsDialog::SettingsDialog(wxWindow* parent)
2022
wxDefaultPosition, wxDefaultSize,
2123
shapeChoices, 1, wxRA_SPECIFY_COLS);
2224

25+
wxArrayString edgeShapeChoices;
26+
edgeShapeChoices.Add("Line");
27+
edgeShapeChoices.Add("Curve");
28+
edgeShapeChoices.Add("Double Arrow");
29+
edgeShapeChoices.Add("Dashed");
30+
31+
edgeShapeRadioBox = new wxRadioBox(this, wxID_ANY, "Edge Shape",
32+
wxDefaultPosition, wxDefaultSize,
33+
edgeShapeChoices, 1, wxRA_SPECIFY_COLS);
34+
35+
shapeRadioBox->SetSelection(static_cast<int>(Config::LoadVertexShape()));
36+
edgeShapeRadioBox->SetSelection(static_cast<int>(Config::LoadEdgeShape()));
37+
2338
mainSizer->Add(shapeRadioBox, 0, wxALL | wxEXPAND, 5);
39+
mainSizer->Add(edgeShapeRadioBox, 0, wxALL | wxEXPAND, 5);
2440

2541
wxStdDialogButtonSizer* buttonSizer = new wxStdDialogButtonSizer();
2642
buttonSizer->AddButton(new wxButton(this, wxID_OK));
@@ -40,4 +56,16 @@ VertexShape SettingsDialog::GetSelectedShape() const {
4056
case 3: return VertexShape::Diamond;
4157
default: return VertexShape::Circle;
4258
}
59+
}
60+
61+
EdgeShape SettingsDialog::GetSelectedEdgeShape() const
62+
{
63+
switch (edgeShapeRadioBox->GetSelection())
64+
{
65+
case 0: return EdgeShape::Line;
66+
case 1: return EdgeShape::Curve;
67+
case 2: return EdgeShape::DoubleArrow;
68+
case 3: return EdgeShape::Dashed;
69+
default: return EdgeShape::Line;
70+
}
4371
}

SettingsDialog.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,13 @@ class SettingsDialog : public wxDialog {
1313
public:
1414
explicit SettingsDialog(wxWindow* parent);
1515
VertexShape GetSelectedShape() const;
16+
EdgeShape GetSelectedEdgeShape() const;
17+
1618

1719
private:
1820
wxRadioBox* shapeRadioBox;
21+
wxRadioBox* edgeShapeRadioBox;
22+
1923
};
2024

2125
#endif //CGTEA_SETTINGSDIALOG_H

const_values.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,11 @@ enum class VertexShape {
1212
Diamond
1313
};
1414

15-
#endif //CONST_VALUES_H
15+
enum class EdgeShape {
16+
Line,
17+
Curve,
18+
DoubleArrow,
19+
Dashed
20+
};
21+
22+
#endif //CONST_VALUES_H

0 commit comments

Comments
 (0)