-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Temporarily remove EdgeEl so that the branch can be merged to…
- Loading branch information
1 parent
2ba887a
commit 049df19
Showing
12 changed files
with
414 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#include "EdgeEl.hpp" | ||
|
||
#include <OpenSimCreator/ModelGraph/ISceneElLookup.hpp> | ||
#include <OpenSimCreator/ModelGraph/SceneEl.hpp> | ||
#include <OpenSimCreator/ModelGraph/SceneElClass.hpp> | ||
|
||
#include <IconsFontAwesome5.h> | ||
#include <oscar/Maths/AABB.hpp> | ||
#include <oscar/Maths/MathHelpers.hpp> | ||
#include <oscar/Maths/Transform.hpp> | ||
#include <oscar/Maths/Vec3.hpp> | ||
|
||
#include <iostream> | ||
#include <utility> | ||
|
||
std::pair<osc::Vec3, osc::Vec3> osc::EdgeEl::getEdgeLineInGround(ISceneElLookup const& lookup) const | ||
{ | ||
SceneEl const* first = lookup.find(m_FirstAttachmentID); | ||
SceneEl const* second = lookup.find(m_SecondAttachmentID); | ||
if (first && second) | ||
{ | ||
return {first->getPos(lookup), second->getPos(lookup)}; | ||
} | ||
else | ||
{ | ||
return {Vec3{}, Vec3{}}; | ||
} | ||
} | ||
|
||
osc::SceneElClass osc::EdgeEl::CreateClass() | ||
{ | ||
return SceneElClass | ||
{ | ||
"Edge", | ||
"Edges", | ||
"Edge(s)", | ||
ICON_FA_ARROWS_ALT, | ||
"An edge between the centers of two other scene elements", | ||
}; | ||
} | ||
|
||
osc::Transform osc::EdgeEl::implGetXform(ISceneElLookup const& lookup) const | ||
{ | ||
SceneEl const* first = lookup.find(m_FirstAttachmentID); | ||
SceneEl const* second = lookup.find(m_FirstAttachmentID); | ||
if (first && second) | ||
{ | ||
Vec3 const pos = osc::Midpoint(first->getPos(lookup), second->getPos(lookup)); | ||
return Transform{.position = pos}; | ||
} | ||
else | ||
{ | ||
return Identity<Transform>(); | ||
} | ||
} | ||
|
||
std::ostream& osc::EdgeEl::implWriteToStream(std::ostream& out) const | ||
{ | ||
return out << "Edge(id = " << m_ID << ", lhs = " << m_FirstAttachmentID << ", rhs = " << m_SecondAttachmentID << ')'; | ||
} | ||
|
||
osc::AABB osc::EdgeEl::implCalcBounds(ISceneElLookup const& lookup) const | ||
{ | ||
auto const p = getEdgeLineInGround(lookup); | ||
return BoundingAABBOf(std::to_array({p.first, p.second})); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
#pragma once | ||
|
||
#include <OpenSimCreator/ModelGraph/CrossrefDescriptor.hpp> | ||
#include <OpenSimCreator/ModelGraph/SceneElClass.hpp> | ||
#include <OpenSimCreator/ModelGraph/SceneElCRTP.hpp> | ||
#include <OpenSimCreator/ModelGraph/SceneElFlags.hpp> | ||
|
||
#include <oscar/Maths/AABB.hpp> | ||
#include <oscar/Maths/Transform.hpp> | ||
#include <oscar/Maths/Vec3.hpp> | ||
#include <oscar/Utils/CStringView.hpp> | ||
#include <oscar/Utils/UID.hpp> | ||
|
||
#include <iosfwd> | ||
#include <stdexcept> | ||
#include <string> | ||
#include <string_view> | ||
#include <utility> | ||
#include <vector> | ||
|
||
namespace osc { class ISceneElLookup; } | ||
|
||
namespace osc | ||
{ | ||
class EdgeEl final : public SceneElCRTP<EdgeEl> { | ||
public: | ||
EdgeEl( | ||
UID id_, | ||
std::string_view label_, | ||
UID firstAttachmentID_, | ||
UID secondAttachmentID_) : | ||
|
||
m_ID{id_}, | ||
m_Label{label_}, | ||
m_FirstAttachmentID{firstAttachmentID_}, | ||
m_SecondAttachmentID{secondAttachmentID_} | ||
{ | ||
} | ||
|
||
std::pair<Vec3, Vec3> getEdgeLineInGround(ISceneElLookup const&) const; | ||
|
||
UID getFirstAttachmentID() const | ||
{ | ||
return m_FirstAttachmentID; | ||
} | ||
|
||
UID getSecondAttachmentID() const | ||
{ | ||
return m_SecondAttachmentID; | ||
} | ||
private: | ||
friend class SceneElCRTP<EdgeEl>; | ||
static SceneElClass CreateClass(); | ||
|
||
std::vector<CrossrefDescriptor> implGetCrossReferences() const final | ||
{ | ||
return | ||
{ | ||
{m_FirstAttachmentID, "First Point", CrossrefDirection::ToParent}, | ||
{m_SecondAttachmentID, "Second Point", CrossrefDirection::ToParent}, | ||
}; | ||
} | ||
|
||
void implSetCrossReferenceConnecteeID(int i, UID newAttachmentID) final | ||
{ | ||
switch (i) { | ||
case 0: | ||
m_FirstAttachmentID = newAttachmentID; | ||
return; | ||
case 1: | ||
m_SecondAttachmentID = newAttachmentID; | ||
return; | ||
default: | ||
throw std::runtime_error{"invalid index passed when looking up a cross refernece"}; | ||
} | ||
} | ||
|
||
SceneElFlags implGetFlags() const final | ||
{ | ||
return | ||
SceneElFlags::CanChangeLabel | | ||
SceneElFlags::CanDelete | | ||
SceneElFlags::CanSelect | | ||
SceneElFlags::HasPhysicalSize; | ||
} | ||
|
||
UID implGetID() const final | ||
{ | ||
return m_ID; | ||
} | ||
|
||
std::ostream& implWriteToStream(std::ostream&) const final; | ||
|
||
CStringView implGetLabel() const | ||
{ | ||
return m_Label; | ||
} | ||
|
||
void implSetLabel(std::string_view newLabel) final | ||
{ | ||
m_Label = newLabel; | ||
} | ||
|
||
Transform implGetXform(ISceneElLookup const&) const final; | ||
|
||
void implSetXform(ISceneElLookup const&, Transform const&) final | ||
{ | ||
// do nothing: transform is defined by both attachments | ||
} | ||
|
||
AABB implCalcBounds(ISceneElLookup const&) const final; | ||
|
||
UID m_ID; | ||
std::string m_Label; | ||
UID m_FirstAttachmentID; | ||
UID m_SecondAttachmentID; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.