diff --git a/Makefile b/Makefile index fe48270..a3b33b9 100644 --- a/Makefile +++ b/Makefile @@ -7,12 +7,6 @@ DESCRIPTION = Timed Petri Net Editor STANDARD = --std=c++14 BUILD_TYPE = debug -################################################### -# Select backend for dear im gui: RayLib or GLFW3 -# -#BACKEND ?= RayLib -BACKEND ?= GLFW3 - ################################################### # Location of the project directory and Makefiles # @@ -20,13 +14,22 @@ P := . M := $(P)/.makefile include $(M)/Makefile.header +################################################### +# Editor using Dear ImGui backend. +# Select backend for dear im gui: RayLib or GLFW3 +# +#DEAR_IMGUI_BACKEND ?= RayLib +DEAR_IMGUI_BACKEND ?= GLFW3 +VPATH += $(P)/src/Editor/DearImGui +INCLUDES += -I$(P)/src/Editor/DearImGui + ################################################### # Check selected backend for dear im gui if compiled for html5 # Be sure to place this section after including MyMakefile ifeq ($(ARCHI),Emscripten) -ifneq ($(BACKEND),RayLib) +ifneq ($(DEAR_IMGUI_BACKEND),RayLib) $(warning Force RayLib backend for compiling with Emscripten) -BACKEND = RayLib +DEAR_IMGUI_BACKEND = RayLib endif endif @@ -35,7 +38,6 @@ endif # VPATH += $(P)/include $(P)/src $(P)/src/Utils $(P)/src/Net VPATH += $(P)/src/Net/Imports VPATH += $(P)/src/Net/Exports -VPATH += $(P)/src/Editor $(P)/src/Editor/DearImGui ################################################### # Inform Makefile where to find header files @@ -61,7 +63,7 @@ LINKER_FLAGS += -ldl -lpthread ################################################### # Set thirdpart Raylib # -ifeq ($(BACKEND),RayLib) +ifeq ($(DEAR_IMGUI_BACKEND),RayLib) INCLUDES += -I$(THIRDPART)/raylib/src THIRDPART_LIBS += $(abspath $(THIRDPART)/raylib/src/$(ARCHI)/libraylib.a) @@ -84,21 +86,21 @@ endif ################################################### # Dear ImGui backends: Raylib # -ifeq ($(BACKEND),RayLib) +ifeq ($(DEAR_IMGUI_BACKEND),RayLib) VPATH += $(THIRDPART)/rlImGui VPATH += $(P)/src/Editor/DearImGui/Backends/RayLib INCLUDES += -I$(THIRDPART)/rlImGui INCLUDES += -I$(P)/src/Editor/DearImGui/Backends/RayLib -DEARIMGUI_BACKEND_OBJS += rlImGui.o +DEARIMGUI_DEAR_IMGUI_BACKEND_OBJS += rlImGui.o endif ################################################### # Dear ImGui backends: OpenGL/GLFW3 # -ifeq ($(BACKEND),GLFW3) +ifeq ($(DEAR_IMGUI_BACKEND),GLFW3) VPATH += $(P)/src/Editor/DearImGui/Backends/GLFW3 INCLUDES += -I$(P)/src/Editor/DearImGui/Backends/GLFW3 -DEARIMGUI_BACKEND_OBJS += imgui_impl_glfw.o imgui_impl_opengl3.o +DEARIMGUI_DEAR_IMGUI_BACKEND_OBJS += imgui_impl_glfw.o imgui_impl_opengl3.o endif ################################################### @@ -163,8 +165,8 @@ endif ################################################### # Check if Dear im gui backend has been set # -ifeq ($(DEARIMGUI_BACKEND_OBJS),) -$(error "Define BACKEND either as RayLib or GLFW3") +ifeq ($(DEARIMGUI_DEAR_IMGUI_BACKEND_OBJS),) +$(error "Define DEAR_IMGUI_BACKEND either as RayLib or GLFW3") endif ################################################### @@ -196,9 +198,9 @@ LIB_OBJS += ExportJSON.o ExportSymfony.o ExportPnEditor.o LIB_OBJS += ExportPetriLaTeX.o ExportJulia.o ExportGraphviz.o ExportDrawIO.o LIB_OBJS += ExportGrafcetCpp.o ImportPNML.o ExportPNML.o Exports.o LIB_OBJS += ImportJSON.o Imports.o -OBJS += $(DEARIMGUI_BACKEND_OBJS) $(DEARIMGUI_OBJS) +OBJS += $(DEARIMGUI_DEAR_IMGUI_BACKEND_OBJS) $(DEARIMGUI_OBJS) OBJS += $(LIB_OBJS) -OBJS += DearUtils.o Drawable.o Application.o PetriEditor.o main.o +OBJS += DearUtils.o Drawable.o Application.o Editor.o main.o ################################################### # Compile the project, the static and shared libraries diff --git a/include/TimedPetriNetEditor/PetriEditor.hpp b/include/TimedPetriNetEditor/PetriEditor.hpp new file mode 100644 index 0000000..b13fc36 --- /dev/null +++ b/include/TimedPetriNetEditor/PetriEditor.hpp @@ -0,0 +1,46 @@ +//============================================================================= +// TimedPetriNetEditor: A timed Petri net editor. +// Copyright 2021 -- 2023 Quentin Quadrat +// +// This file is part of TimedPetriNetEditor. +// +// TimedPetriNetEditor is free software: you can redistribute it and/or modify it +// under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with GNU Emacs. If not, see . +//============================================================================= + +#ifndef PETRI_NET_EDITOR_HPP +# define PETRI_NET_EDITOR_HPP + +# include + +namespace tpne { + +// **************************************************************************** +//! \brief Graphical User interface for manipulating and simulating Petri net. +// **************************************************************************** +class PetriNetEditor +{ +public: + + //------------------------------------------------------------------------- + //! \brief Starts the Petri net editor up, load the Petri file if given not + //! empty. Then call the infinite loop of the GUI. + //! \param[in] petri_file the path of the Petri net fil to load. Pass dummy + //! string if you do not want to load a Petri net file. + //------------------------------------------------------------------------- + virtual void run(std::string const& petri_file) = 0; +}; + +} // namespace tpne + +#endif diff --git a/src/Editor/PetriEditor.cpp b/src/Editor/DearImGui/Editor.cpp similarity index 99% rename from src/Editor/PetriEditor.cpp rename to src/Editor/DearImGui/Editor.cpp index 4aaeca9..40f1b5c 100644 --- a/src/Editor/PetriEditor.cpp +++ b/src/Editor/DearImGui/Editor.cpp @@ -21,7 +21,7 @@ #include "TimedPetriNetEditor/PetriNet.hpp" #include "TimedPetriNetEditor/Algorithms.hpp" #include "TimedPetriNetEditor/SparseMatrix.hpp" -#include "Editor/PetriEditor.hpp" +#include "Editor/DearImGui/Editor.hpp" #include "Editor/DearImGui/Drawable.hpp" #include "Editor/DearImGui/DearUtils.hpp" #include "Editor/DearImGui/KeyBindings.hpp" diff --git a/src/Editor/PetriEditor.hpp b/src/Editor/DearImGui/Editor.hpp similarity index 97% rename from src/Editor/PetriEditor.hpp rename to src/Editor/DearImGui/Editor.hpp index 048af42..108caf9 100644 --- a/src/Editor/PetriEditor.hpp +++ b/src/Editor/DearImGui/Editor.hpp @@ -18,10 +18,11 @@ // along with GNU Emacs. If not, see . //============================================================================= -#ifndef PETRIEDITOR_HPP -# define PETRIEDITOR_HPP +#ifndef DEAR_IMGUI_PETRI_NET_EDITOR_HPP +# define DEAR_IMGUI_PETRI_NET_EDITOR_HPP # include "Application.hpp" // Selected by Makefile +# include "TimedPetriNetEditor/PetriEditor.hpp" # include "Net/Simulation.hpp" # include "Net/Exports/Exports.hpp" # include "Net/Imports/Imports.hpp" @@ -33,7 +34,7 @@ namespace tpne { // **************************************************************************** //! \brief Graphical User interface for manipulating and simulating Petri net. // **************************************************************************** -class Editor: public Application +class Editor: public PetriNetEditor, public Application { public: @@ -48,7 +49,7 @@ class Editor: public Application //! \param[in] petri_file the path of the Petri net fil to load. Pass dummy //! string if you do not want to load a Petri net file. //------------------------------------------------------------------------- - void run(std::string const& petri_file); + virtual void run(std::string const& petri_file) override; private: // Inheritance from Application class diff --git a/src/main.cpp b/src/main.cpp index 67121e9..2837772 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,4 +1,4 @@ -#include "Editor/PetriEditor.hpp" +#include "Editor.hpp" // Selected by Makefile #include // getopt //------------------------------------------------------------------------------