Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Editor #9

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ before_deploy:
- sed -i "s/__VERSION__/$TRAVIS_BUILD_NUMBER/g" bintray-spec.json

deploy:
- provider: pages
- provider: pages
skip_cleanup: true
github_token: $GITHUB_TOKEN
keep-history: true
Expand Down
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ option(ENABLE_DOXYGEN "Build documentation" OFF)

# ================ Project ========================
# Project name and a few useful settings
project(struct
project(editor
VERSION 0.0.$ENV{TRAVIS_BUILD_NUMBER}
DESCRIPTION "OTUS c++ homeworks: struct"
DESCRIPTION "OTUS c++ homeworks: editor"
LANGUAGES CXX
)

Expand Down
1 change: 1 addition & 0 deletions apps/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_subdirectory(Editor)
4 changes: 4 additions & 0 deletions apps/Editor/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
add_and_install_project_app(editor
DEPEND
lib_Editor
)
25 changes: 25 additions & 0 deletions apps/Editor/src/main_GraphicEditor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* \brief Main application
*/

#include <Editor/GraphicEditor.h>
#include <Editor/Document/Tools/Tools.h>
#include <Editor/Document/Primitives/Circle.h>

#include <memory>

using namespace document;

int main() {
GraphicEditor editor;
editor.CreateNewDocument("/tmp/file0.jpg", DocumentType::JPG);
editor.ImportDocument("/tmp/file1.jpg");
editor.ExportDocument("/tmp/file1_export.jpg", DocumentType::PNG);
auto config = PrimitiveConfig{Color::Red, LineStyle::Solid, {0,0}, std::make_shared<Pensil>()};
auto circle = std::make_shared<Circle>(1, config);
editor.CreatePrimitive(circle);
editor.RemovePrimitive(circle);
editor.SetActiveDocument();

return 0;
}
1 change: 1 addition & 0 deletions library/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_subdirectory(Editor)
3 changes: 3 additions & 0 deletions library/Editor/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
add_project_library()

add_subdirectory(test)
23 changes: 23 additions & 0 deletions library/Editor/README.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# OTUS course: "C++ Developer. Professional"

## Домашнее Задание 4

Спроектировать простейший графический векторный редактор. Подготовить макеты классов, отражающих структуру будущего проекта.

Функционал для макетирования следующий: - создание нового документа

- импорт документа из файла
- экспорт документа в файл
- создание графического примитива - удаление графического примитива

Основной упор сделать на шаблон контроллера (MVC) и полиморфизм. Функции, являющиеся обработчиками GUI, собрать в одном файле с функцией `main`.

Внимание должно быть сосредоточено на декларациях, реализация только в крайнем случае для минимальной демонстрации необходимых вызовов. Проект должен компилироваться, все заголовки должны пройти стадию компиляции.

Задание считается выполненным успешно, если все файлы прошли стадию компиляции, все классы охвачены диаграммами, код успешно прошел анализ.
Дополнительные рекомендации

1. Заложить в интерфейсы использование умных указателей, тем самым решив вопрос владения объектами.
2. Помнить про принцип единственности ответственности, разделить код на логические модули (классы, функции).
3. Избегать дублирования кода.

11 changes: 11 additions & 0 deletions library/Editor/include/Editor/Document/Color/Color.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once

namespace document {

enum class Color {
Red,
Green,
Blue
};

} // namespace document {
25 changes: 25 additions & 0 deletions library/Editor/include/Editor/Document/Document.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#pragma once

#include <Editor/Document/IDocument.h>

#include <filesystem>

namespace document {

class PNG : public IDocument {
public:
PNG(const std::filesystem::path& path): IDocument(path) {}
bool SaveAs(const std::filesystem::path& new_path, DocumentType) override {
return true;
}
};

class JPG : public IDocument {
public:
JPG(const std::filesystem::path& path): IDocument(path) {}
bool SaveAs(const std::filesystem::path& new_path, DocumentType) override {
return true;
}
};

} // namespace document
15 changes: 15 additions & 0 deletions library/Editor/include/Editor/Document/DocumentType.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#pragma once

namespace document {

/**
* @brief Supported type of documents for Graphic Editor
*
*/

enum class DocumentType {
PNG = 0,
JPG = 1
};

} // namespace document
33 changes: 33 additions & 0 deletions library/Editor/include/Editor/Document/IDocument.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#pragma once

#include <Editor/Document/Primitives/IPrimitive.h>
#include <Editor/Document/DocumentType.h>

#include <filesystem>
#include <vector>

namespace document {

class IDocument {
public:
IDocument(const std::filesystem::path& path) :
m_path(path) {}

virtual bool SaveAs(const std::filesystem::path& new_path, DocumentType) = 0;

bool AddPrimitive(const std::shared_ptr<IPrimitive> primitive) {
m_primitives.push_back(primitive);
return true;
}

virtual void Update() {};

std::vector<std::shared_ptr<IPrimitive>>& GetAllPrimitives() { return m_primitives; }

virtual ~IDocument() = default;
protected:
std::filesystem::path m_path;
std::vector<std::shared_ptr<IPrimitive>> m_primitives;
};

} // namespace document
16 changes: 16 additions & 0 deletions library/Editor/include/Editor/Document/Primitives/Circle.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#pragma once

#include <Editor/Document/Primitives/IPrimitive.h>
#include <Editor/Document/Primitives/PrimitiveConfig.h>

namespace document {

class Circle: public IPrimitive {
public:
Circle(const float radius, PrimitiveConfig config):
IPrimitive(config), m_radius(radius) {}
private:
float m_radius;
};

} // namespace document {
15 changes: 15 additions & 0 deletions library/Editor/include/Editor/Document/Primitives/IPrimitive.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#pragma once

#include <Editor/Document/Primitives/PrimitiveConfig.h>

namespace document {

class IPrimitive {
public:
IPrimitive(const PrimitiveConfig& config):
m_config(config) {}
protected:
PrimitiveConfig m_config;
};

} // namespace document {
16 changes: 16 additions & 0 deletions library/Editor/include/Editor/Document/Primitives/Line.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#pragma once

#include <Editor/Document/Primitives/IPrimitive.h>
#include <Editor/Document/Primitives/PrimitiveConfig.h>

namespace document {

class Line: public IPrimitive {
public:
Line(const float width, PrimitiveConfig config):
IPrimitive(config), m_width(width) {}
private:
float m_width;
};

} // namespace document {
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#pragma once

#include <Editor/Document/Tools/ITool.h>
#include <Editor/Document/Color/Color.h>

#include <memory>

namespace document {

struct Position {
float x;
float y;
};

enum class LineStyle {
Dash,
Solid
};

struct PrimitiveConfig {
Color color;
LineStyle line_style;
Position position;
std::shared_ptr<ITool> tool;
};

enum class PrimitiveType {
Circle,
Line
};

} // namespace document
8 changes: 8 additions & 0 deletions library/Editor/include/Editor/Document/Tools/ITool.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#pragma once


namespace document {

class ITool {};

} // namespace document {
11 changes: 11 additions & 0 deletions library/Editor/include/Editor/Document/Tools/Tools.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once

#include <Editor/Document/Tools/ITool.h>

namespace document {

class Brush: public ITool {};

class Pensil: public ITool {};

} // namespace document
25 changes: 25 additions & 0 deletions library/Editor/include/Editor/GraphicEditor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* \file Editor.h
* \brief Declaration of Simple Vector Graphics Editor
* \version 0.1
*
* \copyright Copyright (c) 2021
*
*/

#pragma once

#include <Editor/IEditor.h>
#include <Editor/Document/IDocument.h>
#include <Editor/Document/DocumentType.h>
#include <filesystem>

class GraphicEditor: public IEditor<document::IPrimitive, document::PrimitiveConfig> {
public:
std::shared_ptr<document::IDocument> CreateNewDocument(const std::filesystem::path& path, document::DocumentType) override;
void ImportDocument(const std::filesystem::path& path) override;
void ExportDocument(const std::filesystem::path& path, document::DocumentType) override;

private:
document::DocumentType GetDocumentType(const std::filesystem::path& path);
};
Loading