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

RelativePath asset #1166

Open
wants to merge 1 commit into
base: master
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
1 change: 1 addition & 0 deletions ui/zenoedit/dialog/zeditparamlayoutdlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ static CONTROL_ITEM_INFO controlList[] = {
{"Boolean", CONTROL_BOOL, "bool", ":/icons/parameter_control_boolean.svg"},
{"Multiline String", CONTROL_MULTILINE_STRING, "string", ":/icons/parameter_control_string.svg"},
{"read path", CONTROL_READPATH, "string", ":/icons/parameter_control_fold.svg"},
{"relative path", CONTROL_RELATIVE_PATH, "string", ":/icons/parameter_control_fold.svg"},
{"write path", CONTROL_WRITEPATH, "string", ":/icons/parameter_control_fold.svg"},
{"Enum", CONTROL_ENUM, "string", ":/icons/parameter_control_enum.svg"},
{"Float Vector 4", CONTROL_VEC4_FLOAT, "vec4f", ":/icons/parameter_control_floatVector4.svg"},
Expand Down
1 change: 1 addition & 0 deletions ui/zenoedit/nodesys/zenonode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,7 @@ ZGraphicsLayout* ZenoNode::addParam(const QModelIndex& viewparamIdx, ZenoSubGrap
case CONTROL_VEC4_INT:
case CONTROL_ENUM:
case CONTROL_READPATH:
case CONTROL_RELATIVE_PATH:
case CONTROL_WRITEPATH:
case CONTROL_MULTILINE_STRING:
case CONTROL_PURE_COLOR:
Expand Down
1 change: 1 addition & 0 deletions ui/zenomodel/include/modeldata.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ enum PARAM_CONTROL {
CONTROL_ENUM,
CONTROL_WRITEPATH,
CONTROL_READPATH,
CONTROL_RELATIVE_PATH,
CONTROL_MULTILINE_STRING,
CONTROL_COLOR,
CONTROL_PURE_COLOR,
Expand Down
3 changes: 3 additions & 0 deletions ui/zenomodel/src/graphsmanagment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <zenomodel/include/uihelper.h>
#include <zeno/utils/log.h>
#include <zeno/utils/scope_exit.h>
#include <zeno/extra/assetDir.h>
#include "common_def.h"
#include <zenoio/writer/zsgwriter.h>

Expand Down Expand Up @@ -91,6 +92,8 @@ IGraphsModel* GraphsManagment::openZsgFile(const QString& fn)
pModel->clearDirty();
setCurrentModel(pModel);
emit fileOpened(fn);

zeno::setConfigVariable("$ZSGPATH", fn.toStdString());
return pModel;
}

Expand Down
14 changes: 14 additions & 0 deletions ui/zenomodel/src/uihelper.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "uihelper.h"
#include <zeno/utils/logger.h>
#include "modeldata.h"
#include "modelrole.h"
#include "zassert.h"
#include "curvemodel.h"
Expand Down Expand Up @@ -139,6 +140,7 @@ bool UiHelper::validateVariant(const QVariant& var, const QString& type)
case CONTROL_STRING:
case CONTROL_WRITEPATH:
case CONTROL_READPATH:
case CONTROL_RELATIVE_PATH:
case CONTROL_ENUM:
return (QVariant::String == varType);
case CONTROL_MULTILINE_STRING:
Expand Down Expand Up @@ -248,6 +250,7 @@ QVariant UiHelper::parseStringByType(const QString &defaultValue, const QString
case CONTROL_STRING:
case CONTROL_WRITEPATH:
case CONTROL_READPATH:
case CONTROL_RELATIVE_PATH:
case CONTROL_MULTILINE_STRING:
case CONTROL_COLOR:
case CONTROL_ENUM:
Expand Down Expand Up @@ -298,6 +301,7 @@ QVariant UiHelper::parseTextValue(PARAM_CONTROL editCtrl, const QString& textVal
case CONTROL_BOOL: varValue = textValue.isEmpty() ? false : textValue == "true" ? true :
(textValue == "false" ? false : (bool)std::stoi(textValue.toStdString())); break;
case CONTROL_READPATH:
case CONTROL_RELATIVE_PATH:
case CONTROL_WRITEPATH:
case CONTROL_MULTILINE_STRING:
case CONTROL_COLOR:
Expand Down Expand Up @@ -378,6 +382,7 @@ QString UiHelper::getControlDesc(PARAM_CONTROL ctrl)
case CONTROL_BOOL: return "Boolean";
case CONTROL_MULTILINE_STRING: return "Multiline String";
case CONTROL_READPATH: return "read path";
case CONTROL_RELATIVE_PATH: return "relative path";
case CONTROL_WRITEPATH: return "write path";
case CONTROL_ENUM: return "Enum";
case CONTROL_VEC4_FLOAT: return "Float Vector 4";
Expand Down Expand Up @@ -426,6 +431,10 @@ PARAM_CONTROL UiHelper::getControlByDesc(const QString& descName)
{
return CONTROL_READPATH;
}
else if (descName == "relative path")
{
return CONTROL_RELATIVE_PATH;
}
else if (descName == "write path")
{
return CONTROL_WRITEPATH;
Expand Down Expand Up @@ -552,6 +561,7 @@ QStringList UiHelper::getControlLists(const QString& type, bool isNodeUI)
else if (type == "vec4i") { ctrls = { CONTROL_VEC4_INT }; }
else if (type == "writepath") { ctrls = { CONTROL_WRITEPATH }; }
else if (type == "readpath") { ctrls = { CONTROL_READPATH }; }
else if (type == "relativepath") { ctrls = { CONTROL_RELATIVE_PATH }; }
else if (type == "multiline_string") { ctrls = { CONTROL_STRING, CONTROL_MULTILINE_STRING }; }
else if (type == "color") { //color is more general than heatmap.
ctrls = {CONTROL_COLOR, CONTROL_PURE_COLOR};
Expand Down Expand Up @@ -605,6 +615,8 @@ PARAM_CONTROL UiHelper::getControlByType(const QString &type)
return CONTROL_WRITEPATH;
} else if (type == "readpath") {
return CONTROL_READPATH;
} else if (type == "relativepath") {
return CONTROL_RELATIVE_PATH;
} else if (type == "multiline_string") {
return CONTROL_MULTILINE_STRING;
} else if (type == "color") { //color is more general than heatmap.
Expand Down Expand Up @@ -654,6 +666,7 @@ QString UiHelper::getTypeByControl(PARAM_CONTROL ctrl)
case CONTROL_VEC4_INT: return "vec4i";
case CONTROL_WRITEPATH: return "string";
case CONTROL_READPATH: return "string";
case CONTROL_RELATIVE_PATH: return "string";
case CONTROL_COLOR: return "color"; //todo: is vec3?
case CONTROL_CURVE: return "curve";
case CONTROL_ENUM: return "string";
Expand Down Expand Up @@ -827,6 +840,7 @@ QVariant UiHelper::initVariantByControl(PARAM_CONTROL ctrl)
case CONTROL_ENUM:
case CONTROL_WRITEPATH:
case CONTROL_READPATH:
case CONTROL_RELATIVE_PATH:
case CONTROL_MULTILINE_STRING:
case CONTROL_STRING:
return "";
Expand Down
17 changes: 16 additions & 1 deletion ui/zenoui/comctrl/gv/zenoparamwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include "../zpathedit.h"
#include <QSvgRenderer>

#include <filesystem>
#include <zeno/extra/assetDir.h>

ZenoParamWidget::ZenoParamWidget(QGraphicsItem* parent, Qt::WindowFlags wFlags)
: QGraphicsProxyWidget(parent, wFlags)
Expand Down Expand Up @@ -274,7 +276,20 @@ void ZenoParamPathEdit::mousePressEvent(QGraphicsSceneMouseEvent *event)
path = QFileDialog::getOpenFileName(nullptr, "File to Open", "", "All Files(*);;");
} else if (m_control == CONTROL_WRITEPATH) {
path = QFileDialog::getSaveFileName(nullptr, "Path to Save", "", "All Files(*);;");
} else {
}
else if (m_control == CONTROL_RELATIVE_PATH) {

path = QFileDialog::getOpenFileName(nullptr, "File to Open", "", "All Files(*);;");
std::filesystem::path selectedPath(path.toStdString());

auto zpath = zeno::getConfigVariable("$ZSGPATH");
std::filesystem::path basePath(zpath);
basePath = basePath.remove_filename();

auto relative_path = std::filesystem::relative(selectedPath, basePath);
path = QString(relative_path.c_str());
}
else {
path = QFileDialog::getExistingDirectory(nullptr, "Path to Save", "");
}
if (path.isEmpty()) {
Expand Down
1 change: 1 addition & 0 deletions ui/zenoui/comctrl/gv/zitemfactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ namespace zenoui
break;
}
case CONTROL_READPATH:
case CONTROL_RELATIVE_PATH:
case CONTROL_WRITEPATH:
{
const QString& path = UiHelper::variantToString(value);
Expand Down
19 changes: 16 additions & 3 deletions ui/zenoui/comctrl/zpathedit.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#include "zpathedit.h"
#include "zlineedit.h"
#include <filesystem>
#include <zenomodel/include/modeldata.h>
#include <zenoedit/zenoapplication.h>
#include <zenoedit/zenomainwindow.h>


#include <zeno/extra/assetDir.h>

ZPathEdit::ZPathEdit(QWidget *parent)
: ZLineEdit(parent)
Expand Down Expand Up @@ -35,7 +35,20 @@ void ZPathEdit::initUI()
path = QFileDialog::getOpenFileName(nullptr, "File to Open", "", "All Files(*);;");
} else if (ctrl == CONTROL_WRITEPATH) {
path = QFileDialog::getSaveFileName(nullptr, "Path to Save", "", "All Files(*);;");
} else {
}
else if (ctrl == CONTROL_RELATIVE_PATH) {

path = QFileDialog::getOpenFileName(nullptr, "File to Open", "", "All Files(*);;");
std::filesystem::path selectedPath(path.toStdString());

auto zpath = zeno::getConfigVariable("$ZSGPATH");
std::filesystem::path basePath(zpath);
basePath = basePath.remove_filename();

auto relative_path = std::filesystem::relative(selectedPath, basePath);
path = QString(relative_path.c_str());
}
else {
path = QFileDialog::getExistingDirectory(nullptr, "Path to Save", "");
}
if (path.isEmpty()) {
Expand Down
2 changes: 2 additions & 0 deletions ui/zenoui/comctrl/zwidgetfactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ namespace zenoui
return pCheckbox;
}
case CONTROL_READPATH:
case CONTROL_RELATIVE_PATH:
case CONTROL_WRITEPATH:
{
ZPathEdit *pathLineEdit = new ZPathEdit(value.toString());
Expand Down Expand Up @@ -373,6 +374,7 @@ namespace zenoui
case CONTROL_INT:
case CONTROL_FLOAT: return qobject_cast<ZLineEdit*>(pControl) != nullptr; //be careful type changed.
case CONTROL_READPATH:
case CONTROL_RELATIVE_PATH:
case CONTROL_WRITEPATH: return qobject_cast<ZLineEdit*>(pControl) != nullptr;
case CONTROL_BOOL: return qobject_cast<QCheckBox*>(pControl) != nullptr;
case CONTROL_VEC2_FLOAT:
Expand Down
79 changes: 79 additions & 0 deletions zeno/src/nodes/StringNodes.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
#include <memory>
#include <filesystem>
#include <zeno/zeno.h>
#include <zeno/types/StringObject.h>
#include <zeno/types/NumericObject.h>
#include <zeno/utils/format.h>
#include <zeno/utils/fileio.h>
#include <zeno/extra/assetDir.h>
#include <zeno/extra/GlobalState.h>

#include "magic_enum.hpp"

namespace zeno {
namespace {

Expand Down Expand Up @@ -38,6 +43,80 @@ ZENDEFNODE(MakeReadPath, {
{"string"},
});



struct RelativePath : zeno::INode {

enum struct BasePath {
ZSGPATH, RUNPATH, NASLOC
};

std::string nasPath(std::string& relative) {

auto zpath = zeno::getConfigVariable("nasloc");

std::filesystem::path basePath(zpath);
//basePath = basePath.remove_filename();
basePath /= relative;

auto p = std::filesystem::canonical(basePath);
return p.string();
}

std::string zsgPath(std::string& relative) {

auto zpath = zeno::getConfigVariable("$ZSGPATH");

std::filesystem::path basePath(zpath);
basePath = basePath.remove_filename();
basePath /= relative;

auto p = std::filesystem::canonical(basePath);
return p.string();
}

std::string runPath(std::string& relative) {
auto path = std::filesystem::current_path();
path /= relative;

auto p = std::filesystem::canonical(path);
return path.string();
}

virtual void apply() override {

auto baseRaw = get_input2<std::string>("base:");
auto baseEnum = magic_enum::enum_cast<BasePath>(baseRaw).value_or(BasePath::ZSGPATH);

zeno::StringObject fullpath;
auto relative = get_input2<std::string>("relative");

switch (baseEnum) {
case BasePath::ZSGPATH: {
fullpath.set(zsgPath(relative));
}
case BasePath::RUNPATH: {
fullpath.set(runPath(relative));
}
case BasePath::NASLOC: {
fullpath.set(nasPath(relative));
}
default: {}
}

set_output("fullpath", std::make_shared<zeno::StringObject>(fullpath));
}
};

ZENDEFNODE(RelativePath, {
{
{"relativepath", "relative", ""}
},
{ {"string", "fullpath"} },
{ {"enum ZSG_PATH RUN_PATH{unsupported} NASLOC{unsupported} ", "base", "ZSG_PATH"} },
{"string"},
});

struct MakeString : zeno::INode {
virtual void apply() override {
auto obj = std::make_unique<zeno::StringObject>();
Expand Down