Skip to content

Commit

Permalink
1. Moved bindings from gui.Directory to gui.View
Browse files Browse the repository at this point in the history
2. Implemented move-bindings
  • Loading branch information
Skaleee committed Jun 12, 2024
1 parent 82e31f6 commit 962781a
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 21 deletions.
14 changes: 7 additions & 7 deletions plugins/gui/include/gui/gui_api/gui_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include <QSet>
#include <tuple>
#include <vector>
#include <optional>

namespace hal
{
Expand Down Expand Up @@ -63,14 +64,13 @@ namespace hal
static ModuleGateIdPair getValidObjects(int viewId, const std::vector<Module*>, const std::vector<Gate*>);
static GridPlacement* getGridPlacement(int viewId);
static bool setGridPlacement(int viewId, GridPlacement* gp);
};

class Directory{
public:
static int getCurrentDirectory();
static void setCurrentDirectory(int id);
static int createNewDirectory(const std::string& name);
static void deleteDirectory(int id);
static u32 getCurrentDirectory();
static void setCurrentDirectory(u32 id);
static u32 createNewDirectory(const std::string& name);
static void deleteDirectory(u32 id);
static void moveView(u32 viewId, std::optional<u32> destinationDirectoryId, std::optional<int> row);
static void moveDirectory(u32 directoryId, std::optional<u32> destinationDirectoryId, std::optional<int> row);
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ namespace hal
{
case 0:
return mDirectory->name();
case 1:
return mDirectory->id();
default:
return "";
}
Expand Down
52 changes: 48 additions & 4 deletions plugins/gui/src/gui_api/gui_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "gui/user_action/action_fold_module.h"
#include "gui/user_action/action_unfold_module.h"
#include "gui/user_action/action_move_node.h"
#include "gui/user_action/action_move_item.h"
#include "gui/graph_widget/graph_context_manager.h"
#include "gui/context_manager_widget/models/context_tree_model.h"
#include "hal_core/utilities/log.h"
Expand Down Expand Up @@ -935,7 +936,7 @@ namespace hal
return true;
}

int GuiApiClasses::Directory::getCurrentDirectory()
u32 GuiApiClasses::View::getCurrentDirectory()
{
auto currentDirectory = gGraphContextManager->getContextTreeModel()->getCurrentDirectory();
if(currentDirectory == nullptr)
Expand All @@ -948,26 +949,69 @@ namespace hal
}
}

void GuiApiClasses::Directory::setCurrentDirectory(int id)
void GuiApiClasses::View::setCurrentDirectory(u32 id)
{
ContextTreeItem* directory = static_cast<ContextTreeItem*>(gGraphContextManager->getContextTreeModel()->getDirectory(id));
gGraphContextManager->getContextTreeModel()->setCurrentDirectory(directory);
}

int GuiApiClasses::Directory::createNewDirectory(const std::string& name)
u32 GuiApiClasses::View::createNewDirectory(const std::string& name)
{
ActionCreateObject* act = new ActionCreateObject(UserActionObjectType::ContextDir, QString::fromStdString(name));
UserActionManager::instance()->executeActionBlockThread(act);
auto id = act->object().id();
return id;
}

void GuiApiClasses::Directory::deleteDirectory(int id){
void GuiApiClasses::View::deleteDirectory(u32 id)
{
/*ContextDirectory* directory = gGraphContextManager->getDirectoryById(id);
if(directory)
gGraphContextManager->deleteContextDirectory(directory);*/
ActionDeleteObject* act = new ActionDeleteObject();
act->setObject(UserActionObject(id, UserActionObjectType::ContextDir));
UserActionManager::instance()->executeActionBlockThread(act);
}

void GuiApiClasses::View::moveView(u32 viewId, std::optional<u32> destinationDirectoryId, std::optional<int> row)
{
BaseTreeItem* viewItem = gGraphContextManager->getContextTreeModel()->getContext(viewId);
if(!viewItem)
return;

u32 parentId = 0;
BaseTreeItem* parentItem = viewItem->getParent();
if(parentItem && gGraphContextManager->getContextTreeModel()->getRootItem() != parentItem)
parentId = dynamic_cast<ContextTreeItem*>(parentItem)->getId();

UserActionObject uao = UserActionObject(viewId, UserActionObjectType::ContextView);
ActionMoveItem* act;
if(row.has_value())
act = new ActionMoveItem(destinationDirectoryId.value_or(getCurrentDirectory()), parentId, row.value());
else
act = new ActionMoveItem(destinationDirectoryId.value_or(getCurrentDirectory()), parentId);
act->setObject(uao);
act->exec();
}

void GuiApiClasses::View::moveDirectory(u32 directoryId, std::optional<u32> destinationDirectoryId, std::optional<int> row)
{
BaseTreeItem* directoryItem = gGraphContextManager->getContextTreeModel()->getDirectory(directoryId);
if(!directoryItem)
return;

u32 parentId = 0;
BaseTreeItem* parentItem = directoryItem->getParent();
if(parentItem && gGraphContextManager->getContextTreeModel()->getRootItem() != parentItem)
parentId = dynamic_cast<ContextTreeItem*>(parentItem)->getId();

UserActionObject uao = UserActionObject(directoryId, UserActionObjectType::ContextDir);
ActionMoveItem* act;
if(row.has_value())
act = new ActionMoveItem(destinationDirectoryId.value_or(getCurrentDirectory()), parentId, row.value());
else
act = new ActionMoveItem(destinationDirectoryId.value_or(getCurrentDirectory()), parentId);
act->setObject(uao);
act->exec();
}
}
31 changes: 21 additions & 10 deletions plugins/gui/src/python/python_gui_api_bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,40 +219,51 @@ PYBIND11_PLUGIN(hal_gui)
:returns: GridPlacement of the specified view.
:rtype: GridPlacement
)")


.def_static("setGridPlacement", &GuiApiClasses::View::setGridPlacement, py::arg("view_id"), py::arg("grid placement"), R"(
Set grid placement to the view specified by id
:param int viewId ID of the view.
:param GridPlacement* gp: grid placement.
:rtype: bool
)");


py::class_<GuiApiClasses::Directory>(py_gui_api, "Directory")
.def_static("getCurrentDirectory", &GuiApiClasses::Directory::getCurrentDirectory,R"(
)")
.def_static("getCurrentDirectory", &GuiApiClasses::View::getCurrentDirectory,R"(
Gets the CurrentDirectory.
:returns: ID of the current directory. 0, if it's the top level directory.
:rtype: int
)")
.def_static("setCurrentDirectory", &GuiApiClasses::Directory::setCurrentDirectory, py::arg("id"), R"(
.def_static("setCurrentDirectory", &GuiApiClasses::View::setCurrentDirectory, py::arg("id"), R"(
Sets the CurrentDirectory.
:param int id ID of the new current directory.
)")
.def_static("createNewDirectory", &GuiApiClasses::Directory::createNewDirectory, py::arg("name"), R"(
.def_static("createNewDirectory", &GuiApiClasses::View::createNewDirectory, py::arg("name"), R"(
Creates a new directory under the current directory.
:param string name: Name of the new directory.
:returns: ID of the new directory.
:rtype: int
)")
.def_static("deleteDirectory", &GuiApiClasses::Directory::deleteDirectory, py::arg("id"), R"(
.def_static("deleteDirectory", &GuiApiClasses::View::deleteDirectory, py::arg("id"), R"(
Deletes the directory specified by a given id.
:param int id: ID of the directory to delete.
)")
.def_static("moveView", &GuiApiClasses::View::moveView, py::arg("viewId"), py::arg("destinationDirectoryId") = py::none(), py::arg("row") = py::none(), R"(
Moves a view to a directory.
:param int viewId: ID of the view to move.
:param int destinationDirectoryId: ID of the destination directory to which the view will be moved.
If None, the view is instead moved to the current directory.
:param int row: The row index in the parent directory, where the view will be inserted.
)")
.def_static("moveDirectory", &GuiApiClasses::View::moveDirectory, py::arg("directoryId"), py::arg("destinationDirectoryId") = py::none(), py::arg("row") = py::none(), R"(
Moves a directory under another directory.
:param int directoryId: ID of the directory to move.
:param int destinationDirectoryId: ID of the destination directory to which the directory will be moved.
If None, the directory is instead moved to the current directory.
:param int row: The row index in the parent directory, where the directory will be inserted.
)");


Expand Down

0 comments on commit 962781a

Please sign in to comment.