Skip to content

Commit

Permalink
Node_getTransformNode and Node_getTransformable replaced with node_cast
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Mott committed Nov 30, 2021
1 parent 54dc20e commit 2843164
Show file tree
Hide file tree
Showing 17 changed files with 70 additions and 75 deletions.
24 changes: 12 additions & 12 deletions include/itransformable.h
Expand Up @@ -16,6 +16,17 @@ typedef BasicVector4<double> Vector4;
class Quaternion;
class Matrix4;

/**
* @brief Interface for a node which can be transformed via GUI operations.
*
* This interface is designed for nodes which can be translated, rotated and
* scaled via manipulators or other mouse operations. A number of incremental
* transforms can be accumulated, which are then "committed" via
* freezeTransform() or abandoned via revertTransform(). Typically the
* uncommitted live transform will affect rendering (so the user can see the
* effect of the manipulation), but will not be saved into entity spawnargs
* until the transform is frozen.
*/
class ITransformable
{
public:
Expand All @@ -37,15 +48,4 @@ class ITransformable
// before the operation started.
virtual const Vector3& getUntransformedOrigin() = 0;
};
typedef std::shared_ptr<ITransformable> ITransformablePtr;

namespace scene
{
class INode;
typedef std::shared_ptr<INode> INodePtr;
}

inline ITransformablePtr Node_getTransformable(const scene::INodePtr& node)
{
return std::dynamic_pointer_cast<ITransformable>(node);
}
typedef std::shared_ptr<ITransformable> ITransformablePtr;
5 changes: 0 additions & 5 deletions include/itransformnode.h
Expand Up @@ -15,11 +15,6 @@ class ITransformNode
};
typedef std::shared_ptr<ITransformNode> ITransformNodePtr;

inline ITransformNodePtr Node_getTransformNode(const scene::INodePtr& node)
{
return std::dynamic_pointer_cast<ITransformNode>(node);
}

/// An ITransformNode which can provide non-const access to its transform matrix
class IMatrixTransform: public ITransformNode
{
Expand Down
2 changes: 1 addition & 1 deletion libs/transformlib.h
Expand Up @@ -38,7 +38,7 @@ void forEachTransformable(const INode& node, Func functor)
node.foreachNode(
[&](const scene::INodePtr& child) -> bool
{
ITransformablePtr transformable = Node_getTransformable(child);
ITransformablePtr transformable = scene::node_cast<ITransformable>(child);
if (transformable)
functor(*transformable);

Expand Down
2 changes: 1 addition & 1 deletion radiantcore/entity/EntityModule.cpp
Expand Up @@ -162,7 +162,7 @@ IEntityNodePtr Doom3EntityModule::createEntityFromSelection(const std::string& n
{
selection::algorithm::deleteSelection();

ITransformablePtr transform = Node_getTransformable(node);
ITransformablePtr transform = scene::node_cast<ITransformable>(node);

if (transform != 0) {
transform->setType(TRANSFORM_PRIMITIVE);
Expand Down
2 changes: 1 addition & 1 deletion radiantcore/entity/EntityNode.cpp
Expand Up @@ -91,7 +91,7 @@ void EntityNode::constructClone(const EntityNode& original)
if (originalModel && originalModel->hasModifiedScale())
{
assert(getModelKey().getNode()); // clone should have a child model like the original
auto transformable = Node_getTransformable(getModelKey().getNode());
auto transformable = scene::node_cast<ITransformable>(getModelKey().getNode());

if (transformable)
{
Expand Down
4 changes: 2 additions & 2 deletions radiantcore/model/export/ModelScalePreserver.cpp
Expand Up @@ -34,7 +34,7 @@ ModelScalePreserver::ModelScalePreserver() :
);
}

void ModelScalePreserver::forEachScaledModel(const scene::IMapRootNodePtr& root,
void ModelScalePreserver::forEachScaledModel(const scene::IMapRootNodePtr& root,
const std::function<void(Entity&, model::ModelNode&)>& func)
{
root->foreachNode([&](const scene::INodePtr& node)
Expand Down Expand Up @@ -104,7 +104,7 @@ void ModelScalePreserver::restoreModelScale(const scene::IMapRootNodePtr& root)
node->foreachNode([&](const scene::INodePtr& child)
{
model::ModelNodePtr model = Node_getModel(child);
ITransformablePtr transformable = Node_getTransformable(child);
ITransformablePtr transformable = scene::node_cast<ITransformable>(child);

if (model && transformable)
{
Expand Down
4 changes: 2 additions & 2 deletions radiantcore/selection/RadiantSelectionSystem.cpp
Expand Up @@ -814,7 +814,7 @@ void RadiantSelectionSystem::onManipulationCancelled()
// Tell all the scene objects to revert their transformations
foreachSelected([](const scene::INodePtr& node)
{
ITransformablePtr transform = Node_getTransformable(node);
ITransformablePtr transform = scene::node_cast<ITransformable>(node);

if (transform)
{
Expand All @@ -826,7 +826,7 @@ void RadiantSelectionSystem::onManipulationCancelled()
{
node->foreachNode([&](const scene::INodePtr& child)
{
ITransformablePtr transform = Node_getTransformable(child);
ITransformablePtr transform = scene::node_cast<ITransformable>(child);

if (transform)
{
Expand Down
2 changes: 1 addition & 1 deletion radiantcore/selection/SceneWalkers.h
Expand Up @@ -81,7 +81,7 @@ namespace scene

inline bool freezeTransformableNode(const scene::INodePtr& node)
{
ITransformablePtr transform = Node_getTransformable(node);
ITransformablePtr transform = scene::node_cast<ITransformable>(node);

if (transform)
{
Expand Down
32 changes: 16 additions & 16 deletions radiantcore/selection/TransformationVisitors.cpp
Expand Up @@ -49,7 +49,7 @@ void translation_for_pivoted_scale(Vector3& parent_translation, const Vector3& l
// ===================================================================================

void TranslateSelected::visit(const scene::INodePtr& node) const {
ITransformablePtr transform = Node_getTransformable(node);
ITransformablePtr transform = scene::node_cast<ITransformable>(node);
if(transform != 0) {
transform->setType(TRANSFORM_PRIMITIVE);
transform->setTranslation(m_translate);
Expand All @@ -58,20 +58,20 @@ void TranslateSelected::visit(const scene::INodePtr& node) const {

// ===================================================================================

RotateSelected::RotateSelected(const Quaternion& rotation, const Vector3& world_pivot) :
_rotation(rotation),
RotateSelected::RotateSelected(const Quaternion& rotation, const Vector3& world_pivot) :
_rotation(rotation),
_worldPivot(world_pivot),
_freeObjectRotation(registry::getValue<bool>(selection::algorithm::RKEY_FREE_OBJECT_ROTATION))
{}

void RotateSelected::visit(const scene::INodePtr& node) const
{
ITransformNodePtr transformNode = Node_getTransformNode(node);
ITransformNodePtr transformNode = scene::node_cast<ITransformNode>(node);

if (transformNode)
if (transformNode)
{
// Upcast the instance onto a Transformable
ITransformablePtr transformable = Node_getTransformable(node);
ITransformablePtr transformable = scene::node_cast<ITransformable>(node);

if (transformable)
{
Expand All @@ -81,10 +81,10 @@ void RotateSelected::visit(const scene::INodePtr& node) const
transformable->setScale(c_scale_identity);
transformable->setTranslation(c_translation_identity);

// Pass the rotation quaternion and the world pivot,
// Pass the rotation quaternion and the world pivot,
// unless we're rotating each object around their own center
transformable->setRotation(_rotation,
_freeObjectRotation ? transformable->getUntransformedOrigin() : _worldPivot,
transformable->setRotation(_rotation,
_freeObjectRotation ? transformable->getUntransformedOrigin() : _worldPivot,
node->localToWorld());
}
}
Expand All @@ -93,10 +93,10 @@ void RotateSelected::visit(const scene::INodePtr& node) const
// ===================================================================================

void ScaleSelected::visit(const scene::INodePtr& node) const {
ITransformNodePtr transformNode = Node_getTransformNode(node);
ITransformNodePtr transformNode = scene::node_cast<ITransformNode>(node);
if(transformNode != 0)
{
ITransformablePtr transform = Node_getTransformable(node);
ITransformablePtr transform = scene::node_cast<ITransformable>(node);
if(transform != 0)
{
transform->setType(TRANSFORM_PRIMITIVE);
Expand Down Expand Up @@ -124,7 +124,7 @@ void ScaleSelected::visit(const scene::INodePtr& node) const {
// ====== Component Visitors ==========================================================

void TranslateComponentSelected::visit(const scene::INodePtr& node) const {
ITransformablePtr transform = Node_getTransformable(node);
ITransformablePtr transform = scene::node_cast<ITransformable>(node);
if(transform != 0)
{
transform->setType(TRANSFORM_COMPONENT);
Expand All @@ -133,12 +133,12 @@ void TranslateComponentSelected::visit(const scene::INodePtr& node) const {
}

void RotateComponentSelected::visit(const scene::INodePtr& node) const {
ITransformablePtr transform = Node_getTransformable(node);
ITransformablePtr transform = scene::node_cast<ITransformable>(node);
if(transform != 0) {
Vector3 parent_translation;
translation_for_pivoted_rotation(parent_translation, m_rotate, m_world_pivot,
node->localToWorld(),
Node_getTransformNode(node)->localToParent());
scene::node_cast<ITransformNode>(node)->localToParent());

transform->setType(TRANSFORM_COMPONENT);
transform->setRotation(m_rotate);
Expand All @@ -147,10 +147,10 @@ void RotateComponentSelected::visit(const scene::INodePtr& node) const {
}

void ScaleComponentSelected::visit(const scene::INodePtr& node) const {
ITransformablePtr transform = Node_getTransformable(node);
ITransformablePtr transform = scene::node_cast<ITransformable>(node);
if(transform != 0) {
Vector3 parent_translation;
translation_for_pivoted_scale(parent_translation, m_scale, m_world_pivot, node->localToWorld(), Node_getTransformNode(node)->localToParent());
translation_for_pivoted_scale(parent_translation, m_scale, m_world_pivot, node->localToWorld(), scene::node_cast<ITransformNode>(node)->localToParent());

transform->setType(TRANSFORM_COMPONENT);
transform->setScale(m_scale);
Expand Down
6 changes: 3 additions & 3 deletions radiantcore/selection/algorithm/Curves.cpp
Expand Up @@ -26,7 +26,7 @@ namespace
const char* const GKEY_CURVE_CATMULLROM_KEY = "/defaults/curveCatmullRomKey";
}

/**
/**
* greebo: Creates a new entity with an attached curve
*
* @key: The curve type: pass either "curve_CatmullRomSpline" or "curve_Nurbs".
Expand Down Expand Up @@ -71,7 +71,7 @@ void createCurve(const std::string& key)
"3 ( 0 0 0 50 50 0 50 100 0 )"
);

ITransformablePtr transformable = Node_getTransformable(curve);
ITransformablePtr transformable = scene::node_cast<ITransformable>(curve);
if (transformable != NULL) {
// Translate the entity to the center of the current workzone
transformable->setTranslation(GlobalXYWndManager().getActiveViewOrigin());
Expand Down Expand Up @@ -238,7 +238,7 @@ void insertCurveControlPoints(const cmd::ArgumentList& args)
_("Can't insert curve points - no entities with curves selected.")
);
}

UndoableCommand command("curveInsertControlPoints");

// The functor object
Expand Down
4 changes: 2 additions & 2 deletions radiantcore/selection/algorithm/General.cpp
Expand Up @@ -952,7 +952,7 @@ void floorNode(const scene::INodePtr& node)
{
Vector3 translation = finder.getIntersection() - objectOrigin;

ITransformablePtr transformable = Node_getTransformable(node);
ITransformablePtr transformable = scene::node_cast<ITransformable>(node);

if (transformable)
{
Expand Down Expand Up @@ -987,7 +987,7 @@ void registerCommands()
GlobalCommandSystem().addCommand("InvertSelection", invertSelection);
GlobalCommandSystem().addCommand("SelectInside", selectInside,
{ cmd::ARGTYPE_VECTOR3 | cmd::ARGTYPE_OPTIONAL, cmd::ARGTYPE_VECTOR3 | cmd::ARGTYPE_OPTIONAL });
GlobalCommandSystem().addCommand("SelectFullyInside", selectFullyInside,
GlobalCommandSystem().addCommand("SelectFullyInside", selectFullyInside,
{ cmd::ARGTYPE_VECTOR3 | cmd::ARGTYPE_OPTIONAL, cmd::ARGTYPE_VECTOR3 | cmd::ARGTYPE_OPTIONAL });
GlobalCommandSystem().addCommand("SelectTouching", selectTouching,
{ cmd::ARGTYPE_VECTOR3 | cmd::ARGTYPE_OPTIONAL, cmd::ARGTYPE_VECTOR3 | cmd::ARGTYPE_OPTIONAL });
Expand Down
4 changes: 2 additions & 2 deletions radiantcore/selection/manipulators/ManipulatorComponents.cpp
Expand Up @@ -330,7 +330,7 @@ void ModelScaleComponent::transform(const Matrix4& pivot2world, const VolumeTest
assert(!_entityNode.expired());

scene::INodePtr entityNode = _entityNode.lock();
ITransformablePtr transformable = Node_getTransformable(entityNode);
ITransformablePtr transformable = scene::node_cast<ITransformable>(entityNode);

if (transformable)
{
Expand All @@ -341,7 +341,7 @@ void ModelScaleComponent::transform(const Matrix4& pivot2world, const VolumeTest
// Apply the scale to the model beneath the entity
entityNode->foreachNode([&](const scene::INodePtr& node)
{
ITransformablePtr transformable = Node_getTransformable(node);
ITransformablePtr transformable = scene::node_cast<ITransformable>(node);

if (transformable)
{
Expand Down
10 changes: 5 additions & 5 deletions test/Brush.cpp
Expand Up @@ -133,10 +133,10 @@ TEST_F(BrushTest, FacePlaneRotateWithMatrix)
const double ANGLE = 2.0;
Matrix4 rot = Matrix4::getRotation(Vector3(0, 1, 0), ANGLE);

Node_getTransformable(_brushNode)->setRotation(
scene::node_cast<ITransformable>(_brushNode)->setRotation(
Quaternion::createForY(-ANGLE)
);
Node_getTransformable(_brushNode)->freezeTransform();
scene::node_cast<ITransformable>(_brushNode)->freezeTransform();

double EPSILON = 0.001;
EXPECT_NE(face.getPlane3(), orig);
Expand Down Expand Up @@ -167,8 +167,8 @@ TEST_F(BrushTest, FacePlaneTranslate)
// Translate in the Y direction
const Vector3 translation(0, 3, 0);

Node_getTransformable(_brushNode)->setTranslation(translation);
Node_getTransformable(_brushNode)->freezeTransform();
scene::node_cast<ITransformable>(_brushNode)->setTranslation(translation);
scene::node_cast<ITransformable>(_brushNode)->freezeTransform();

EXPECT_NE(face.getPlane3(), orig);
EXPECT_EQ(face.getPlane3().normal(), orig.normal());
Expand Down Expand Up @@ -375,7 +375,7 @@ TEST_F(BrushTest, RotateBrushZ90Degrees)
GlobalCommandSystem().executeCommand("RotateSelectionZ");

auto brush = Node_getIBrush(brushNode);

// Check the faces explicitly, normals should have been rotated, order of faces unchanged
checkFaceNormalAndShader(brush, 0, { 0,-1, 0 }, "textures/numbers/1");
checkFaceNormalAndShader(brush, 1, { 0, 1, 0 }, "textures/numbers/1");
Expand Down
18 changes: 9 additions & 9 deletions test/EntityInspector.cpp
Expand Up @@ -131,7 +131,7 @@ inline void expectUnique(const KeyValueStore& keyValueStore, const std::string&
return;
}

EXPECT_EQ(keyValueStore.store.at(key), value) <<
EXPECT_EQ(keyValueStore.store.at(key), value) <<
"Key Value Store should contain " << key << " = " << value << ", but value was " << keyValueStore.store.at(key);
}

Expand All @@ -144,13 +144,13 @@ inline void expectNonUnique(const KeyValueStore& keyValueStore, const std::strin
}

EXPECT_EQ(keyValueStore.store.at(key), KeyValueStore::DifferingValues) <<
"Key Value Store should contain " << key << " = " << KeyValueStore::DifferingValues <<
"Key Value Store should contain " << key << " = " << KeyValueStore::DifferingValues <<
", but value was " << keyValueStore.store.at(key);
}

inline void expectNotListed(const KeyValueStore& keyValueStore, const std::string& key)
{
EXPECT_EQ(keyValueStore.store.count(key), 0) <<
EXPECT_EQ(keyValueStore.store.count(key), 0) <<
"Key Value Store should not contain " << key;
}

Expand Down Expand Up @@ -256,7 +256,7 @@ TEST_F(EntityInspectorTest, TwoEntitiesSelected)
expectUnique(keyValueStore, "classname", "light_torchflame");
expectUnique(keyValueStore, "light_center", "0 0 0");
expectUnique(keyValueStore, "light_radius", "126 102 79");

// Shared keys, but differing values
expectNonUnique(keyValueStore, "name");
expectNonUnique(keyValueStore, "origin");
Expand Down Expand Up @@ -515,7 +515,7 @@ TEST_F(EntityInspectorTest, SelectEntitiesPlusWorldspawnPrimitive)
auto light1 = selectEntity("light_torchflame_1");
auto speaker1 = selectEntity("speaker_1");
keyValueStore.rescanSelection();

// Prerequisites of worldspawn
EXPECT_EQ(Node_getEntity(worldspawn)->getKeyValue("name"), "") << "Worldspawn shouldn't have a name";
EXPECT_EQ(Node_getEntity(worldspawn)->getKeyValue("origin"), "") << "Worldspawn shouldn't have an origin";
Expand Down Expand Up @@ -598,7 +598,7 @@ TEST_F(EntityInspectorTest, UndoRedoKeyValueChange)

for (const auto& pair : keyValuesBeforeChange)
{
EXPECT_EQ(keyValueStore.store[pair.first], pair.first == "unique_to_1" ? ChangedValue : pair.second)
EXPECT_EQ(keyValueStore.store[pair.first], pair.first == "unique_to_1" ? ChangedValue : pair.second)
<< "Keyvalues not matching up after change";
}

Expand Down Expand Up @@ -793,7 +793,7 @@ TEST_F(EntityInspectorTest, SelectWorldspawnBrushes)

// Check behaviour when selecting and deselecting various child primitives of two entities
// every time the entity selection changes, the key value store is supposed to receive callbacks.
// Even if a primitive selection changes, as long as the corresponding entity selection set
// Even if a primitive selection changes, as long as the corresponding entity selection set
// doesn't change, the key value store should not receive any change events.
TEST_F(EntityInspectorTest, SelectChildPrimitivesOfTwoEntities)
{
Expand Down Expand Up @@ -893,7 +893,7 @@ TEST_F(EntityInspectorTest, SelectChildPrimitivesOfTwoEntities)
}

// In a problematic case, a worldspawn patch and a func_static have been moved,
// the modified "origin" key on the func_static was appearing in the Entity Inspector
// the modified "origin" key on the func_static was appearing in the Entity Inspector
// after the modification. It should remain hidden, since worldspawn doesn't have an "origin" key.
TEST_F(EntityInspectorTest, MoveFuncStaticAndWorldPrimitives)
{
Expand All @@ -915,7 +915,7 @@ TEST_F(EntityInspectorTest, MoveFuncStaticAndWorldPrimitives)

auto previousOrigin = Node_getEntity(func_static)->getKeyValue("origin");

auto transformable = Node_getTransformable(func_static);
auto transformable = scene::node_cast<ITransformable>(func_static);
if (transformable)
{
transformable->setType(TRANSFORM_PRIMITIVE);
Expand Down

0 comments on commit 2843164

Please sign in to comment.