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

New Import UI feature - WIP #206

Merged
merged 9 commits into from
Feb 10, 2020
10 changes: 10 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,16 @@ if(CMAKE_WANT_UFE_BUILD)
endif()
endif()

if(DEFINED QT_LOCATION)
set(CMAKE_PREFIX_PATH "${QT_LOCATION}")
find_package(Qt5 COMPONENTS Core Gui Widgets REQUIRED)
if(Qt5_FOUND)
message(STATUS "Building with Qt features enabled.")
endif()
else()
message(STATUS "QT_LOCATION not set. Building Qt features will be disabled.")
endif()

#==============================================================================
# Compiler
#==============================================================================
Expand Down
11 changes: 11 additions & 0 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,10 @@ def BuildAndInstall(context, buildArgs, stages):
else:
extraArgs.append('-DMAYAUSD_DEFINE_BOOST_DEBUG_PYTHON_FLAG=OFF')

if context.qtLocation:
extraArgs.append('-DQT_LOCATION="{qtLocation}"'
.format(qtLocation=context.qtLocation))

extraArgs += buildArgs
stagesArgs += stages

Expand Down Expand Up @@ -422,6 +426,9 @@ def Package(context):
parser.add_argument("--debug-python", dest="debug_python", action="store_true",
help="Define Boost Python Debug if your Python library comes with Debugging symbols (default: %(default)s).")

parser.add_argument("--qt-location", type=str,
help="Directory where Qt is installed.")

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To build the new UI (which uses) Qt you need to specify where to find Qt (should be the same one that Maya is using).

parser.add_argument("--build-args", type=str, nargs="*", default=[],
help=("Comma-separated list of arguments passed into CMake when building libraries"))

Expand Down Expand Up @@ -493,6 +500,10 @@ def __init__(self, args):
self.devkitLocation = (os.path.abspath(args.devkit_location)
if args.devkit_location else None)

# Qt Location
self.qtLocation = (os.path.abspath(args.qt_location)
if args.qt_location else None)

# Log File Name
logFileName="build_log.txt"
self.logFileLocation=os.path.join(self.buildDir, logFileName)
Expand Down
44 changes: 35 additions & 9 deletions cmake/utils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ function(mayaUsd_find_python_module module)
"Location of Python module ${module}")
endif(NOT _${module}_status)
endif(NOT ${module_found})
endfunction(mayaUsd_find_python_module)
endfunction()

# Initialize a variable to accumulate an rpath. The origin is the
# RUNTIME DESTINATION of the target. If not absolute it's appended
Expand Down Expand Up @@ -158,10 +158,36 @@ function(mayaUsd_promoteMayaUsdHeader)
configure_file(${srcFile} ${dstFile})
endfunction()

#
# mayaUsd_promoteHeaderList(
# [SUBDIR <optional sub-directory>])
# [FILES <list of files>]
#
# SUBDIR - optional sub-directory in which to promote files.
# FILES - list of files to promote.
#
function(mayaUsd_promoteHeaderList)
foreach(header ${ARGV})
cmake_parse_arguments(PREFIX
"" # options
"SUBDIR" # one_value keywords
"HEADERS" # multi_value keywords
${ARGN}
)

set(DEST_DIR ${CMAKE_BINARY_DIR}/include/mayaUsd)
if(PREFIX_SUBDIR)
set(DEST_DIR ${DEST_DIR}/${PREFIX_SUBDIR})
endif()

if(PREFIX_HEADERS)
set(headerFiles ${PREFIX_HEADERS})
else()
message(FATAL_ERROR "HEADERS keyword is not specified.")
endif()

foreach(header ${headerFiles})
set(srcFile ${CMAKE_CURRENT_SOURCE_DIR}/${header})
set(dstFile ${CMAKE_BINARY_DIR}/include/mayaUsd/${header})
set(dstFile ${DEST_DIR}/${header})
Comment on lines +161 to +190
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes to these CMake functions and their existing usages would also be nice to see as a dedicated pull request. The new feature only adds one new usage of mayaUsd_promoteHeaderList() that takes advantage of the change, but many existing call sites (unrelated to the feature) have to change to absorb this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mattyjams great point. I am going to have a separate PR addressing all that after this PR is merged into dev.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Matt, you are right. But in this case this is one of our backlog branch issues which was waiting for PR154 to go in.


set(content "#pragma once\n#include \"${srcFile}\"\n")

Expand Down Expand Up @@ -193,9 +219,9 @@ endfunction()
#
function(mayaUsd_copyFiles target)
cmake_parse_arguments(PREFIX
"TARGET"
"DESTINATION"
"FILES"
"" # options
"DESTINATION" # one_value keywords
"FILES" # multi_value keywords
${ARGN}
)

Expand Down Expand Up @@ -236,9 +262,9 @@ endfunction()
#
function(mayaUsd_copyDirectory target)
cmake_parse_arguments(PREFIX
"TARGET"
"DESTINATION"
"DIRECTORY"
"" # options
"DESTINATION" # one_value keywords
"DIRECTORY" # multi_value keywords
${ARGN}
)

Expand Down
30 changes: 16 additions & 14 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ list(APPEND mayaUsd_src
fileio/fallbackPrimReader.cpp
fileio/functorPrimReader.cpp
fileio/functorPrimWriter.cpp
fileio/importData.cpp
fileio/instancedNodeWriter.cpp
fileio/primReader.cpp
fileio/primReaderArgs.cpp
Expand Down Expand Up @@ -244,6 +245,7 @@ list(APPEND mayaUsdFileio_headers
fileio/fallbackPrimReader.h
fileio/functorPrimReader.h
fileio/functorPrimWriter.h
fileio/importData.h
fileio/instancedNodeWriter.h
fileio/primReader.h
fileio/primReaderArgs.h
Expand Down Expand Up @@ -511,22 +513,22 @@ set_property(GLOBAL PROPERTY GLOBAL_LIBRARY_LOCATION ${CMAKE_INSTALL_PREFIX}/lib

# promote headers
mayaUsd_promoteMayaUsdHeader()
mayaUsd_promoteHeaderList(${mayaUsdBase_headers})
mayaUsd_promoteHeaderList(${mayaUsdFileio_headers})
mayaUsd_promoteHeaderList(${mayaUsdChaser_headers})
mayaUsd_promoteHeaderList(${mayaUsdJobs_headers})
mayaUsd_promoteHeaderList(${mayaUsdUtilsIO_headers})
mayaUsd_promoteHeaderList(${mayaUsdShading_headers})
mayaUsd_promoteHeaderList(${mayaUsdTranslators_headers})
mayaUsd_promoteHeaderList(${mayaUsdUtils_headers})
mayaUsd_promoteHeaderList(${mayaUsdNodes_headers})
mayaUsd_promoteHeaderList(${mayaUsdListeners_headers})
mayaUsd_promoteHeaderList(${mayaUsdVP2RenderDelegate_headers})
mayaUsd_promoteHeaderList(HEADERS ${mayaUsdBase_headers})
mayaUsd_promoteHeaderList(HEADERS ${mayaUsdFileio_headers})
mayaUsd_promoteHeaderList(HEADERS ${mayaUsdChaser_headers})
mayaUsd_promoteHeaderList(HEADERS ${mayaUsdJobs_headers})
mayaUsd_promoteHeaderList(HEADERS ${mayaUsdUtilsIO_headers})
mayaUsd_promoteHeaderList(HEADERS ${mayaUsdShading_headers})
mayaUsd_promoteHeaderList(HEADERS ${mayaUsdTranslators_headers})
mayaUsd_promoteHeaderList(HEADERS ${mayaUsdUtils_headers})
mayaUsd_promoteHeaderList(HEADERS ${mayaUsdNodes_headers})
mayaUsd_promoteHeaderList(HEADERS ${mayaUsdListeners_headers})
mayaUsd_promoteHeaderList(HEADERS ${mayaUsdVP2RenderDelegate_headers})
if(UFE_FOUND)
mayaUsd_promoteHeaderList(${mayaUsdUfe_headers})
mayaUsd_promoteHeaderList(HEADERS ${mayaUsdUfe_headers})
endif()
mayaUsd_promoteHeaderList(${mayaUsdPxrUsdMayaGL_headers})
mayaUsd_promoteHeaderList(${mayaUsdPxVP20_headers})
mayaUsd_promoteHeaderList(HEADERS ${mayaUsdPxrUsdMayaGL_headers})
mayaUsd_promoteHeaderList(HEADERS ${mayaUsdPxVP20_headers})

# install public headers
install(FILES ${CMAKE_BINARY_DIR}/include/mayaUsd/mayaUsd.h
Expand Down
160 changes: 160 additions & 0 deletions lib/fileio/importData.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
//
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New file containing all the import data, such as root prim path, stage pop mask, variants, etc.

// Copyright 2019 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 "importData.h"

#include <type_traits>

MAYAUSD_NS_DEF {

//------------------------------------------------------------------------------
// ImportData:
//------------------------------------------------------------------------------

constexpr const char* kRootPrimPath = "/";

ImportData::ImportData()
: fLoadSet(UsdStage::InitialLoadSet::LoadAll)
, fRootPrimPath(kRootPrimPath)
{
}

ImportData::ImportData(const std::string& f)
: fLoadSet(UsdStage::InitialLoadSet::LoadAll)
, fRootPrimPath(kRootPrimPath)
, fFilename(f)
{
}

/*static*/
ImportData& ImportData::instance()
{
static ImportData sImportData;
return sImportData;
}
Comment on lines +41 to +46
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a little unclear why this is made available as a static global singleton. Can't it just be constructed from the import arguments on demand and be owned by the import UI?

It feels like careless use of this in future code could open up the possibility of confusing behavior if you go back and forth between importing via the UI and importing via commands (or using some other tool that does that) since they may share state. This would also block any chance of imports working in parallel, if that is or even could be possible.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I explained in another comment why this is a singleton.

But you do bring up a good point about going back and forth between import via the UI and importing via commands. Note: I've partially fixed this by moving the filename into the import data and first checking if the filenames match. So this problem will only happen if you import via UI and import from command the same file and you don't import a different file inbetween. And this problem only exists when using the import from the MayaUSD plugin since it's the only one with the import UI.

I need to think about a good way to solve this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, another reason that its a global is because we want to be able to support a user opening the import dialog, making some changes, closing the dialog and then before importing reopen the dialog to continue making changes. It is not done yet, but I will be repopulating the dialog with the data stored in import data. So a user can continue editing.


/*static*/
const ImportData& ImportData::cinstance()
{
return instance();
}

void ImportData::clearData()
{
fLoadSet = UsdStage::InitialLoadSet::LoadAll;
UsdStagePopulationMask tmpPopMask;
fPopMask.swap(tmpPopMask);
fRootVariants.clear();
fPrimVariants.clear();
fFilename.clear();
fRootPrimPath = kRootPrimPath;
}

bool ImportData::empty() const
{
// If we don't have a filename set then we are empty.
return fFilename.empty();
}
Comment on lines +65 to +69
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a little dubious of the concept of an ImportData being "empty", and particularly so if it's the presence of a filename that determines that.

I could see this class being useful if you already have a handle to an open stage and just want to use an ImportData to "index" into it with just a root prim path specified, for example.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that I've moved the filename into the import data, does it being empty without a filename solve your concern?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could still imagine cases where you might want to import from an open stage as opposed to a file, but I don't think we have any existing usage like that currently. Seems like we have what we need for now.


const std::string& ImportData::filename() const
{
return fFilename;
}

void ImportData::setFilename(const std::string& f)
{
// If the input filename doesn't match what we have stored (empty or not) we
// clear the data because it doesn't belong to the new file.
if (fFilename != f)
clearData();
fFilename = f;
}

const std::string& ImportData::rootPrimPath() const
{
return fRootPrimPath;
}

void ImportData::setRootPrimPath(const std::string& primPath)
{
fRootPrimPath = primPath;
}

bool ImportData::hasPopulationMask() const
{
return !fPopMask.IsEmpty();
}

const UsdStagePopulationMask& ImportData::stagePopulationMask() const
{
return fPopMask;
}

void ImportData::setStagePopulationMask(const UsdStagePopulationMask& mask)
{
fPopMask = mask;
}

void ImportData::setStagePopulationMask(UsdStagePopulationMask&& mask)
{
fPopMask = std::move(mask);
}

UsdStage::InitialLoadSet ImportData::stageInitialLoadSet() const
{
return fLoadSet;
}

void ImportData::setStageInitialLoadSet(UsdStage::InitialLoadSet loadSet)
{
fLoadSet = loadSet;
}

bool ImportData::hasVariantSelections() const
{
return !(fRootVariants.empty() || fPrimVariants.empty());
}

const SdfVariantSelectionMap& ImportData::rootVariantSelections() const
{
return fRootVariants;
}

const ImportData::PrimVariantSelections& ImportData::primVariantSelections() const
{
return fPrimVariants;
}

void ImportData::setRootVariantSelections(const SdfVariantSelectionMap& vars)
{
fRootVariants = vars;
}

void ImportData::setRootVariantSelections(SdfVariantSelectionMap&& vars)
{
fRootVariants = std::move(vars);
}

void ImportData::setPrimVariantSelections(const PrimVariantSelections& vars)
{
fPrimVariants = vars;
}

void ImportData::setPrimVariantSelections(PrimVariantSelections&& vars)
{
fPrimVariants = std::move(vars);
}

} // namespace MayaUsd
Loading