Skip to content

Commit be7723c

Browse files
authored
Merge pull request #1447 from opensim-org/connectConnector_macro
Macro-generated connectConnector methods.
2 parents 5423946 + 2d7db84 commit be7723c

19 files changed

+69
-50
lines changed

Bindings/Java/Matlab/tests/testConnectorsInputsOutputs.m

+2-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@
5353
body = Body.safeDownCast(joint.getConnectee('child_frame'));
5454
assert(body.getMass() == 2);
5555

56-
% Connect a connector.
56+
% Connect a connector. Try the different methods to ensure they all work.
57+
offset.connectConnector_parent(ground);
5758
offset.updConnector('parent').connect(ground);
5859
assert(strcmp(offset.getConnector('parent').getConnecteeName(), '../ground'));
5960

Bindings/Python/tests/test_connectors_inputs_outputs.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,11 @@ def test_connecting(self):
8484
j1 = osim.PinJoint()
8585
j1.setName("j1")
8686
j1.updConnector("parent_frame").connect(model.getGround())
87-
j1.updConnector("child_frame").connect(b1)
87+
j1.connectConnector_child_frame(b1)
8888

8989
j2 = osim.PinJoint()
9090
j2.setName("j2")
91-
j2.updConnector("parent_frame").connect(b1)
91+
j2.connectConnector_parent_frame(b1)
9292
j2.updConnector("child_frame").connect(b2)
9393

9494
model.addBody(b1)

OpenSim/Actuators/BodyActuator.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ const std::string& BodyActuator::getBodyName() const
9393
*/
9494
void BodyActuator::setBody(const Body& body)
9595
{
96-
updConnector<Body>("body").connect(body);
96+
connectConnector_body(body);
9797
}
9898

9999
/**

OpenSim/Common/ComponentConnector.h

+23-5
Original file line numberDiff line numberDiff line change
@@ -848,16 +848,25 @@ class Input : public AbstractInput {
848848
/** In an XML file, you can set this Connector's connectee name */ \
849849
/** via the <b>\<connector_##cname##_connectee_name\></b> element. */ \
850850
/** This connector was generated with the */ \
851-
/** #OpenSim_DECLARE_CONNECTOR macro. */ \
851+
/** #OpenSim_DECLARE_CONNECTOR macro; */ \
852+
/** see AbstractConnector for more information. */ \
853+
/** @connectormethods connectConnector_##cname##() */ \
852854
OpenSim_DOXYGEN_Q_PROPERTY(T, cname) \
853855
/** @} */ \
854856
/** @cond */ \
855857
PropertyIndex PropertyIndex_connector_##cname##_connectee_name { \
856858
this->template constructConnector<T>(#cname, \
857-
"Path to a Component to satisfy the Connector '" \
859+
"Path to a Component that satisfies the Connector '" \
858860
#cname "' of type " #T " (description: " comment ").") \
859861
}; \
860-
/** @endcond */
862+
/** @endcond */ \
863+
/** @name Connector-related functions */ \
864+
/** @{ */ \
865+
/** Connect the '##cname##' Connector to an object of type T##. */ \
866+
void connectConnector_##cname(const Object& object) { \
867+
this->updConnector(#cname).connect(object); \
868+
} \
869+
/** @} */
861870

862871
// The following doxygen-like description does NOT actually appear in doxygen.
863872
/* Preferably, use the #OpenSim_DECLARE_CONNECTOR macro. Only use this macro
@@ -914,6 +923,8 @@ class Input : public AbstractInput {
914923
/** comment */ \
915924
/** In an XML file, you can set this Connector's connectee name */ \
916925
/** via the <b>\<connector_##cname##_connectee_name\></b> element. */ \
926+
/** See AbstractConnector for more information. */ \
927+
/** @connectormethods connectConnector_##cname##() */ \
917928
OpenSim_DOXYGEN_Q_PROPERTY(T, cname) \
918929
/** @} */ \
919930
/** @cond */ \
@@ -925,7 +936,14 @@ class Input : public AbstractInput {
925936
PropertyIndex constructConnector_##cname(); \
926937
/* Remember the provided type so we can use it in the DEFINE macro. */ \
927938
typedef T _connector_##cname##_type; \
928-
/** @endcond */
939+
/** @endcond */ \
940+
/** @name Connector-related functions */ \
941+
/** @{ */ \
942+
/** Connect the '##cname##' Connector to an object of type T##. */ \
943+
void connectConnector_##cname(const Object& object) { \
944+
this->updConnector(#cname).connect(object); \
945+
} \
946+
/** @} */
929947

930948
// The following doxygen-like description does NOT actually appear in doxygen.
931949
/* When specifying a Connector to a forward-declared type (using
@@ -950,7 +968,7 @@ PropertyIndex Class::constructConnector_##cname() { \
950968
using T = _connector_##cname##_type; \
951969
std::string typeStr = T::getClassName(); \
952970
return this->template constructConnector<T>(#cname, \
953-
"Path to a Component to satisfy the Connector '" \
971+
"Path to a Component that satisfies the Connector '" \
954972
#cname "' of type " + typeStr + "."); \
955973
}
956974
/// @}

OpenSim/Common/Test/testComponentInterface.cpp

+9-10
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ void testMisc() {
480480
//Configure the connector to look for its dependency by this name
481481
//Will get resolved and connected automatically at Component connect
482482
bar.updConnector<Foo>("parentFoo").setConnecteeName(foo.getAbsolutePathName());
483-
bar.updConnector<Foo>("childFoo").connect(foo);
483+
bar.connectConnector_childFoo(foo);
484484

485485
// add a subcomponent
486486
// connect internals
@@ -527,7 +527,7 @@ void testMisc() {
527527
SimTK_TEST(!theWorld.hasComponent<Foo>("Nonexistant"));
528528

529529

530-
bar.updConnector<Foo>("childFoo").connect(foo2);
530+
bar.connectConnector_childFoo(foo2);
531531
string connectorName = bar.updConnector<Foo>("childFoo").getName();
532532

533533
// Bar should connect now
@@ -675,7 +675,7 @@ void testMisc() {
675675
bar2.updConnector<Foo>("parentFoo")
676676
.setConnecteeName(compFoo.getRelativePathName(bar2));
677677

678-
bar2.updConnector<Foo>("childFoo").connect(foo);
678+
bar2.connectConnector_childFoo(foo);
679679
compFoo.upd_Foo1().updInput("input1")
680680
.connect(bar2.getOutput("PotentialEnergy"));
681681

@@ -864,7 +864,7 @@ void testListConnectors() {
864864

865865
// Ensure that calling connect() on bar's "parentFoo" doesn't increase
866866
// its number of connectees.
867-
bar.updConnector<Foo>("parentFoo").connect(foo);
867+
bar.connectConnector_parentFoo(foo);
868868
// TODO The "Already connected to 'foo'" is caught by `connect()`.
869869
SimTK_TEST(bar.getConnector<Foo>("parentFoo").getNumConnectees() == 1);
870870

@@ -1001,9 +1001,8 @@ void testComponentPathNames()
10011001
ASSERT(&foo1inA == foo1);
10021002

10031003
// This bar2 that belongs to A and connects the two foo2s
1004-
bar2->updConnector<Foo>("parentFoo").connect(*foo2);
1005-
bar2->updConnector<Foo>("childFoo")
1006-
.connect(F->getComponent<Foo>("Foo2"));
1004+
bar2->connectConnector_parentFoo(*foo2);
1005+
bar2->connectConnector_childFoo(F->getComponent<Foo>("Foo2"));
10071006

10081007
// auto& foo2inF = bar2->getComponent<Foo>("../../F/Foo2");
10091008

@@ -1012,7 +1011,7 @@ void testComponentPathNames()
10121011
auto& fbar2 = F->updComponent<Bar>("Bar2");
10131012
ASSERT(&fbar2 != bar2);
10141013

1015-
fbar2.updConnector<Foo>("parentFoo").connect(*foo1);
1014+
fbar2.connectConnector_parentFoo(*foo1);
10161015
fbar2.updConnector<Foo>("childFoo")
10171016
.setConnecteeName("../Foo1");
10181017

@@ -1031,8 +1030,8 @@ void testInputOutputConnections()
10311030
foo1->setName("foo1");
10321031
foo2->setName("foo2");
10331032
bar->setName("bar");
1034-
bar->updConnector<Foo>("parentFoo").connect(*foo1);
1035-
bar->updConnector<Foo>("childFoo").connect(*foo2);
1033+
bar->connectConnector_parentFoo(*foo1);
1034+
bar->connectConnector_childFoo(*foo2);
10361035

10371036
world.add(foo1);
10381037
world.add(foo2);

OpenSim/Examples/ExampleHopperDevice/buildDeviceModel_answers.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ Device* buildDevice() {
8585
// frame will be connected in exampleHopperDevice.cpp.
8686
#pragma region Step2_TaskC_solution
8787

88-
anchorA->updConnector("child_frame").connect(*cuffA);
88+
anchorA->connectConnector_child_frame(*cuffA);
8989

9090
#pragma endregion
9191

@@ -103,7 +103,7 @@ Device* buildDevice() {
103103

104104
auto anchorB = new WeldJoint();
105105
anchorB->setName("anchorB");
106-
anchorB->updConnector("child_frame").connect(*cuffB);
106+
anchorB->connectConnector_child_frame(*cuffB);
107107
device->addComponent(anchorB);
108108

109109
#pragma endregion
@@ -124,7 +124,7 @@ Device* buildDevice() {
124124
//TODO: Connect the controller's "actuator" Connector to pathActuator.
125125
#pragma region Step2_TaskC_solution
126126

127-
controller->updConnector("actuator").connect(*pathActuator);
127+
controller->connectConnector_actuator(*pathActuator);
128128

129129
#pragma endregion
130130

OpenSim/Examples/ExampleHopperDevice/exampleHopperDevice_answers.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,9 @@ void connectDeviceToModel(OpenSim::Device& device, OpenSim::Model& model,
114114
#pragma region Step2_TaskD_solution
115115

116116
const auto& frameA = model.getComponent<PhysicalFrame>(modelFrameAname);
117-
anchorA.updConnector("parent_frame").connect(frameA);
117+
anchorA.connectConnector_parent_frame(frameA);
118118
const auto& frameB = model.getComponent<PhysicalFrame>(modelFrameBname);
119-
anchorB.updConnector("parent_frame").connect(frameB);
119+
anchorB.connectConnector_parent_frame(frameB);
120120

121121
#pragma endregion
122122

OpenSim/Simulation/Model/ConditionalPathPoint.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ void ConditionalPathPoint::constructProperties()
9494
*/
9595
void ConditionalPathPoint::setCoordinate(const Coordinate& coordinate)
9696
{
97-
updConnector<Coordinate>("coordinate").connect(coordinate);
97+
connectConnector_coordinate(coordinate);
9898
}
9999

100100
bool ConditionalPathPoint::hasCoordinate() const

OpenSim/Simulation/Model/ContactGeometry.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ const PhysicalFrame& ContactGeometry::getFrame() const
101101

102102
void ContactGeometry::setFrame(const PhysicalFrame& frame)
103103
{
104-
updConnector<PhysicalFrame>("frame").connect(frame);
104+
connectConnector_frame(frame);
105105
}
106106

107107
const PhysicalFrame& ContactGeometry::getBody() const

OpenSim/Simulation/Model/MovingPathPoint.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,15 @@ const Coordinate& MovingPathPoint::getZCoordinate() const
9898

9999
void MovingPathPoint::setXCoordinate(const Coordinate& coordinate)
100100
{
101-
updConnector<Coordinate>("x_coordinate").connect(coordinate);
101+
connectConnector_x_coordinate(coordinate);
102102
}
103103
void MovingPathPoint::setYCoordinate(const Coordinate& coordinate)
104104
{
105-
updConnector<Coordinate>("y_coordinate").connect(coordinate);
105+
connectConnector_y_coordinate(coordinate);
106106
}
107107
void MovingPathPoint::setZCoordinate(const Coordinate& coordinate)
108108
{
109-
updConnector<Coordinate>("z_coordinate").connect(coordinate);
109+
connectConnector_z_coordinate(coordinate);
110110
}
111111

112112
void MovingPathPoint::extendConnectToModel(Model& model)

OpenSim/Simulation/Model/OffsetFrame.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ calcAccelerationInGround(const SimTK::State& state) const
292292
template <class C>
293293
void OffsetFrame<C>::setParentFrame(const C& parent)
294294
{
295-
this->template updConnector<C>("parent").connect(parent);
295+
this->connectConnector_parent(parent);
296296
}
297297

298298
template <class C>

OpenSim/Simulation/Model/PointToPointSpring.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,12 @@ void PointToPointSpring::constructProperties()
9191

9292
void PointToPointSpring::setBody1(const PhysicalFrame& body)
9393
{
94-
updConnector<PhysicalFrame>("body1").connect(body);
94+
connectConnector_body1(body);
9595
}
9696

9797
void PointToPointSpring::setBody2(const PhysicalFrame& body)
9898
{
99-
updConnector<PhysicalFrame>("body2").connect(body);
99+
connectConnector_body2(body);
100100
}
101101

102102
const PhysicalFrame& PointToPointSpring::getBody1() const

OpenSim/Simulation/Model/PrescribedForce.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ PrescribedForce::PrescribedForce(const std::string& name, const PhysicalFrame& f
5151
PrescribedForce()
5252
{
5353
setName(name);
54-
updConnector<PhysicalFrame>("frame").connect(frame);
54+
connectConnector_frame(frame);
5555
}
5656

5757
//_____________________________________________________________________________

OpenSim/Simulation/Model/Station.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ const PhysicalFrame& Station::getParentFrame() const
9898
*/
9999
void Station::setParentFrame(const OpenSim::PhysicalFrame& aFrame)
100100
{
101-
updConnector<PhysicalFrame>("parent_frame").connect(aFrame);
101+
connectConnector_parent_frame(aFrame);
102102
}
103103

104104
SimTK::Vec3 Station::findLocationInFrame(const SimTK::State& s,

OpenSim/Simulation/Model/TwoFrameLinker.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -306,8 +306,8 @@ TwoFrameLinker<C, F>::TwoFrameLinker(const std::string &name,
306306
int ix2 = append_frames(frame2Offset);
307307
this->finalizeFromProperties();
308308

309-
this->template updConnector<F>("frame1").connect(get_frames(ix1));
310-
this->template updConnector<F>("frame2").connect(get_frames(ix2));
309+
this->connectConnector_frame1(get_frames(ix1));
310+
this->connectConnector_frame2(get_frames(ix2));
311311

312312
static_cast<PhysicalOffsetFrame&>(upd_frames(ix1)).setParentFrame(frame1);
313313
static_cast<PhysicalOffsetFrame&>(upd_frames(ix2)).setParentFrame(frame2);
@@ -333,8 +333,8 @@ TwoFrameLinker<C, F>::TwoFrameLinker(const std::string &name,
333333
int ix2 = append_frames(frame2Offset);
334334
this->finalizeFromProperties();
335335

336-
this->template updConnector<F>("frame1").connect(get_frames(ix1));
337-
this->template updConnector<F>("frame2").connect(get_frames(ix2));
336+
this->connectConnector_frame1(get_frames(ix1));
337+
this->connectConnector_frame2(get_frames(ix2));
338338
}
339339

340340
template <class C, class F>

OpenSim/Simulation/SimbodyEngine/Joint.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ Joint::Joint(const std::string &name, const PhysicalFrame& parent,
7070
setName(name);
7171
set_reverse(reverse);
7272

73-
updConnector<PhysicalFrame>("parent_frame").connect(parent);
74-
updConnector<PhysicalFrame>("child_frame").connect(child);
73+
connectConnector_parent_frame(parent);
74+
connectConnector_child_frame(child);
7575
}
7676

7777
/* Convenience Constructor*/
@@ -130,8 +130,8 @@ Joint::Joint(const std::string &name,
130130
static_cast<PhysicalOffsetFrame&>(upd_frames(pix)).setParentFrame(parent);
131131
static_cast<PhysicalOffsetFrame&>(upd_frames(cix)).setParentFrame(child);
132132

133-
updConnector<PhysicalFrame>("parent_frame").connect(upd_frames(pix));
134-
updConnector<PhysicalFrame>("child_frame").connect(upd_frames(cix));
133+
connectConnector_parent_frame(upd_frames(pix));
134+
connectConnector_child_frame(upd_frames(cix));
135135
}
136136

137137
//=============================================================================

OpenSim/Simulation/SimbodyEngine/WeldConstraint.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ void WeldConstraint::
158158
_internalOffset1.reset(new PhysicalOffsetFrame(frame1, in1));
159159
_internalOffset1->setName("internal_" + frame1.getName());
160160
updProperty_frames().adoptAndAppendValue(_internalOffset1.get());
161-
updConnector<PhysicalFrame>("frame1").connect(*_internalOffset1);
161+
connectConnector_frame1(*_internalOffset1);
162162
}
163163
else { // otherwise it is already "wired" up so just update
164164
_internalOffset1->setOffsetTransform(in1);
@@ -168,7 +168,7 @@ void WeldConstraint::
168168
_internalOffset2.reset(new PhysicalOffsetFrame(frame2, in2));
169169
_internalOffset2->setName("internal_" + frame2.getName());
170170
updProperty_frames().adoptAndAppendValue(_internalOffset2.get());
171-
updConnector<PhysicalFrame>("frame2").connect(*_internalOffset2);
171+
connectConnector_frame2(*_internalOffset2);
172172
}
173173
else {
174174
_internalOffset2->setOffsetTransform(in2);

OpenSim/Simulation/Test/testNestedModelComponents.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,11 @@ void testPendulumModelWithNestedJoints()
8181
// Create WeldJoints to anchor cuff Bodies to the pendulum.
8282
auto* anchorA = new WeldJoint();
8383
anchorA->setName("anchorA");
84-
anchorA->updConnector("child_frame").connect(*cuffA);
84+
anchorA->connectConnector_child_frame(*cuffA);
8585

8686
auto* anchorB = new WeldJoint();
8787
anchorB->setName("anchorB");
88-
anchorB->updConnector("child_frame").connect(*cuffB);
88+
anchorB->connectConnector_child_frame(*cuffB);
8989

9090
// add anchors to the Device
9191
device->addComponent(anchorA);
@@ -97,8 +97,8 @@ void testPendulumModelWithNestedJoints()
9797
// Connect the device to bodies of the pendulum
9898
const auto& rod1 = pendulum->getComponent<OpenSim::Body>("rod1");
9999
const auto& rod2 = pendulum->getComponent<OpenSim::Body>("rod2");
100-
anchorA->updConnector("parent_frame").connect(rod1);
101-
anchorB->updConnector("parent_frame").connect(rod2);
100+
anchorA->connectConnector_parent_frame(rod1);
101+
anchorB->connectConnector_parent_frame(rod2);
102102

103103
State& s = pendulum->initSystem();
104104
}

doc/doxyfile_shared.in

+3-2
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,9 @@ TAB_SIZE = 4
204204
# will result in a user-defined paragraph with heading "Side Effects:".
205205
# You can put \n's in the value part of an alias to insert newlines.
206206

207-
ALIASES = "propmethods=\par Methods related to this property\n" \
208-
"inputmethods=\par Methods related to this input\n"
207+
ALIASES = "propmethods=\par Methods related to this property\n" \
208+
"inputmethods=\par Methods related to this input\n" \
209+
"connectormethods=\par Methods related to this connector\n"
209210

210211
# This tag can be used to specify a number of word-keyword mappings (TCL only).
211212
# A mapping has the form "name=value". For example adding

0 commit comments

Comments
 (0)