-
Notifications
You must be signed in to change notification settings - Fork 222
Expand file tree
/
Copy patheditForwardDialog.cpp
More file actions
193 lines (162 loc) · 6.09 KB
/
Copy patheditForwardDialog.cpp
File metadata and controls
193 lines (162 loc) · 6.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
//
// Copyright 2026 Autodesk
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#include "editForwardDialog.h"
#include <mayaUsd/nodes/proxyShapeBase.h>
#include <mayaUsd/ufe/ProxyShapeHandler.h>
#include <mayaUsd/ufe/Utils.h>
// This is added to prevent multiple definitions of the MApiVersion string.
#define MNoVersionString
#include <maya/MDagPath.h>
#include <maya/MFnDagNode.h>
#include <maya/MMessage.h>
#include <maya/MQtUtil.h>
#include <maya/MSceneMessage.h>
#include <ufe/globalSelection.h>
#include <ufe/observableSelection.h>
#include <ufe/selection.h>
#include <ufe/selectionNotification.h>
#include <AdskUsdEditForwardUi/ForwardWidget.h>
#include <AdskUsdEditForwardUi/StageEntry.h>
#include <QtCore/QPointer>
#include <QtCore/QTimer>
#include <QtCore/QVariant>
#include <QtWidgets/QVBoxLayout>
#include <vector>
namespace UsdEditForwardConfig {
namespace {
std::vector<AdskUsdEditForwardUi::StageEntry> findAllStages()
{
std::vector<AdskUsdEditForwardUi::StageEntry> result;
for (const auto& dagPath : MayaUsd::ufe::ProxyShapeHandler::getAllNames()) {
PXR_NS::UsdStageWeakPtr stage = MayaUsd::ufe::ProxyShapeHandler::dagPathToStage(dagPath);
if (!stage)
continue;
AdskUsdEditForwardUi::StageEntry out;
out.name = dagPath.substr(dagPath.rfind('|') + 1); // npos+1==0, so safe when no '|'
out.stage = stage;
result.push_back(std::move(out));
}
// Sort alphabetically by name, matching the layer editor's allStages() ordering.
std::sort(
result.begin(), result.end(), [](const auto& a, const auto& b) { return a.name < b.name; });
return result;
}
struct SelectionObserver : Ufe::Observer
{
QPointer<EditForwardDialog> dialog;
explicit SelectionObserver(EditForwardDialog* d)
: dialog(d)
{
}
void operator()(const Ufe::Notification& n) override
{
if (dialog && dynamic_cast<const Ufe::SelectionChanged*>(&n))
dialog->handleSelectionChanged();
}
};
} // namespace
EditForwardDialog::EditForwardDialog(const QString& title, QWidget* parent)
: QDialog(parent)
{
setAttribute(Qt::WA_DeleteOnClose);
setWindowTitle(title);
// Maya keys saved window preferences off the object name.
setObjectName("EditForwardConfigDialog");
// Tell Maya to treat this as a Maya-managed window. This is the same
// mechanism Maya uses internally to keep its own dialogs from going behind
// the main window. This should not be combined with other flags.
setWindowFlags(Qt::Window);
setProperty("saveWindowPref", QVariant::fromValue(true));
_forwardWidget = new AdskUsdEditForwardUi::ForwardWidget(this);
_forwardWidget->setSourceLayerDefault(
AdskUsdEditForwardUi::ForwardWidget::SourceLayerDefault::SessionLayer);
auto* layout = new QVBoxLayout(this);
layout->setContentsMargins(0, 0, 0, 0);
layout->addWidget(_forwardWidget);
refreshStages();
// Observe proxy shape node additions and removals directly.
PXR_NS::MayaUsdProxyShapeBase::getProxyShapesObserver().addTypeListener(*this);
// Refresh after scene open or new scene.
_sceneCallbackIds.push_back(
MSceneMessage::addCallback(MSceneMessage::kAfterOpen, onSceneChangedCB, this));
_sceneCallbackIds.push_back(
MSceneMessage::addCallback(MSceneMessage::kAfterNew, onSceneChangedCB, this));
// Register as UFE observer to listen for selection changes.
_selectionObserver = std::make_shared<SelectionObserver>(this);
const Ufe::GlobalSelection::Ptr& ufeSelection = Ufe::GlobalSelection::get();
if (ufeSelection) {
ufeSelection->addObserver(_selectionObserver);
}
}
EditForwardDialog::~EditForwardDialog()
{
PXR_NS::MayaUsdProxyShapeBase::getProxyShapesObserver().removeTypeListener(*this);
for (auto id : _sceneCallbackIds) {
MMessage::removeCallback(id);
}
const Ufe::GlobalSelection::Ptr& ufeSelection = Ufe::GlobalSelection::get();
if (ufeSelection && _selectionObserver) {
ufeSelection->removeObserver(_selectionObserver);
}
}
QSize EditForwardDialog::sizeHint() const
{
return QSize(
static_cast<int>(MQtUtil::dpiScale(1250.0f)), static_cast<int>(MQtUtil::dpiScale(1000.0f)));
}
void EditForwardDialog::processNodeAdded(MObject& /*node*/)
{
QTimer::singleShot(0, this, &EditForwardDialog::refreshStages);
}
void EditForwardDialog::processNodeRemoved(MObject& /*node*/)
{
QTimer::singleShot(0, this, &EditForwardDialog::refreshStages);
}
void EditForwardDialog::onSceneChangedCB(void* clientData)
{
auto* self = static_cast<EditForwardDialog*>(clientData);
QTimer::singleShot(0, self, &EditForwardDialog::refreshStages);
}
void EditForwardDialog::handleSelectionChanged()
{
const Ufe::GlobalSelection::Ptr& ufeGlobalSelection = Ufe::GlobalSelection::get();
if (!ufeGlobalSelection)
return;
for (const auto& item : *ufeGlobalSelection) {
auto* proxy = MayaUsd::ufe::getProxyShapeFromItemOrChildren(item);
if (!proxy)
continue;
MFnDagNode dagNode(proxy->thisMObject());
MDagPath dagPath;
dagNode.getPath(dagPath);
PXR_NS::UsdStageWeakPtr stage
= MayaUsd::ufe::ProxyShapeHandler::dagPathToStage(dagPath.fullPathName().asChar());
if (stage) {
setActiveStage(stage);
return;
}
}
}
void EditForwardDialog::refreshStages()
{
_forwardWidget->setStages(findAllStages());
handleSelectionChanged();
}
void EditForwardDialog::setActiveStage(PXR_NS::UsdStageRefPtr const& stage)
{
_forwardWidget->setActiveStage(stage);
}
} // namespace UsdEditForwardConfig