Skip to content

Commit

Permalink
Merge pull request rapyuta-robotics#84 from rapyuta-robotics/feature/…
Browse files Browse the repository at this point in the history
…tf-connector

add show-hide for individual links and joint names in RobotModel options
  • Loading branch information
seadeep42 authored Feb 12, 2020
2 parents 7193fcc + 1bd1f3e commit ac3e0bc
Show file tree
Hide file tree
Showing 8 changed files with 124 additions and 11 deletions.
17 changes: 11 additions & 6 deletions src/components/optionRow.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import React from 'react';
import { HalfWidth, StyledOptionRow } from './styled';

const OptionRow = ({ label, children }) => (
<StyledOptionRow>
<HalfWidth>{label}:</HalfWidth>
<HalfWidth>{children}</HalfWidth>
</StyledOptionRow>
);
const OptionRow = ({ label, children, separator }) => {
return (
<StyledOptionRow>
<HalfWidth>
{label}
{separator || ':'}
</HalfWidth>
<HalfWidth>{children}</HalfWidth>
</StyledOptionRow>
);
};

export default OptionRow;
4 changes: 4 additions & 0 deletions src/panels/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class Wrapper extends React.Component {
this.updateInfoTabs = this.updateInfoTabs.bind(this);
this.toggleGraphModal = this.toggleGraphModal.bind(this);

this.vizInstances = new Set();
this.ros = new ROSLIB.Ros();
this.viewer = new Amphion.TfViewer(this.ros, {
onFramesListUpdate: this.updateFramesList,
Expand Down Expand Up @@ -366,6 +367,7 @@ class Wrapper extends React.Component {
rosInstance={this.ros}
rosTopics={rosTopics}
rosStatus={rosStatus}
vizInstances={this.vizInstances}
visualizations={visualizations}
viewer={this.viewer}
connectRos={this.connectRos}
Expand Down Expand Up @@ -399,6 +401,8 @@ class Wrapper extends React.Component {
{_.map(visualizations, vizItem => (
<Visualization
options={vizItem}
vizInstances={this.vizInstances}
id={vizItem.key}
key={vizItem.key}
viewer={this.viewer}
rosTopics={rosTopics}
Expand Down
2 changes: 1 addition & 1 deletion src/panels/sidebar/globalOptions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class GlobalOptions extends React.PureComponent {
>
{_.map(framesList, f => (
<option key={f} value={f}>
{f}
{f.replace('-tf-connector', '')}
</option>
))}
</Select>
Expand Down
8 changes: 8 additions & 0 deletions src/panels/sidebar/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,11 @@ class Sidebar extends React.Component {
updateVizOptions,
viewer,
visualizations,
vizInstances: vizInstancesSet,
} = this.props;

const vizInstances = [...vizInstancesSet];

const { rosInput } = this.state;
return (
<SidebarWrapper>
Expand Down Expand Up @@ -155,6 +158,10 @@ class Sidebar extends React.Component {
const relatedTopics = _.filter(rosTopics, t =>
_.includes(vizObject.additionalMessageTypes, t.messageType),
);
const vizInstance = _.filter(
vizInstances,
v => v.key === vizItem.key,
);
return (
<VizOptions
options={vizItem}
Expand All @@ -163,6 +170,7 @@ class Sidebar extends React.Component {
topics={topics}
relatedTopics={relatedTopics}
vizObject={vizObject}
vizInstance={vizInstance}
rosInstance={rosInstance}
updateVizOptions={updateVizOptions}
removeVisualization={removeVisualization}
Expand Down
2 changes: 2 additions & 0 deletions src/panels/sidebar/vizOptions/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const VizOptions = ({
options,
topics,
relatedTopics,
vizInstance,
vizObject: { icon },
updateVizOptions,
removeVisualization,
Expand Down Expand Up @@ -85,6 +86,7 @@ const VizOptions = ({
<VizSpecificOptions
options={options}
topics={topics}
vizInstance={vizInstance}
relatedTopics={relatedTopics}
updateVizOptions={updateVizOptions}
/>
Expand Down
87 changes: 87 additions & 0 deletions src/panels/sidebar/vizOptions/robotModel.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import React from 'react';
import { keys, map } from 'lodash';
import { VizItem, VizItemCollapse } from '../../../components/styled/viz';
import Chevron from '../../../components/chevron';
import { Input, StyledOptionRow } from '../../../components/styled';
import OptionRow from '../../../components/optionRow';

class RobotModelLinksJoints extends React.PureComponent {
constructor(props) {
super(props);
this.state = {
linksCollapsed: true,
jointsCollapsed: true,
};

this.toggleCollapsed = this.toggleCollapsed.bind(this);
}

toggleCollapsed(name) {
// eslint-disable-next-line react/destructuring-assignment
const current = this.state[name];
this.setState({ [name]: !current });
}

render() {
const { jointsCollapsed, linksCollapsed } = this.state;
const { vizInstance } = this.props;

const { urdfObject } = vizInstance[0];
const { joints, links } = urdfObject;

return (
<>
<VizItem>
<StyledOptionRow>
<VizItemCollapse
collapsed={linksCollapsed}
onClick={() => this.toggleCollapsed('linksCollapsed')}
>
<Chevron />
</VizItemCollapse>
Links
</StyledOptionRow>
{!linksCollapsed &&
links &&
map(keys(links), (name, index) => {
const link = links[name];
return (
<OptionRow key={index} label={name}>
<Input
type="checkbox"
name={name}
data-id={name}
defaultChecked
onChange={e => {
const { checked } = e.target;
if (checked) {
link.show();
} else {
link.hide();
}
}}
/>
</OptionRow>
);
})}
</VizItem>
<StyledOptionRow>
<VizItemCollapse
collapsed={jointsCollapsed}
onClick={() => this.toggleCollapsed('jointsCollapsed')}
>
<Chevron />
</VizItemCollapse>
Joints
</StyledOptionRow>
{!jointsCollapsed &&
joints &&
map(keys(joints), (name, index) => {
return <OptionRow key={index} label={name} separator=" " />;
})}
</>
);
}
}

export default RobotModelLinksJoints;
10 changes: 6 additions & 4 deletions src/panels/sidebar/vizOptions/vizSpecificOption.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,33 @@ import RangeOptions from './range';
import PointOptions from './point';
import InteractiveMarkerOptions from './interactiveMarkerOptions';
import WrenchOptions from './wrench';
import RobotModelLinksJoints from './robotModel';

const {
VIZ_TYPE_IMAGE,
VIZ_TYPE_WRENCH,
VIZ_TYPE_INTERACTIVEMARKER,
VIZ_TYPE_LASERSCAN,
VIZ_TYPE_MAP,
VIZ_TYPE_MARKER,
VIZ_TYPE_MARKERARRAY,
VIZ_TYPE_ODOMETRY,
VIZ_TYPE_PATH,
VIZ_TYPE_INTERACTIVEMARKER,
VIZ_TYPE_POINT,
VIZ_TYPE_POINTCLOUD,
VIZ_TYPE_POLYGON,
VIZ_TYPE_POSE,
VIZ_TYPE_POSEARRAY,
VIZ_TYPE_RANGE,
VIZ_TYPE_ROBOTMODEL,
VIZ_TYPE_TF,
VIZ_TYPE_POINT,
VIZ_TYPE_WRENCH,
} = CONSTANTS;

const VizSpecificOptions = ({
options: { vizType },
options,
topics,
vizInstance,
relatedTopics,
updateVizOptions,
}) => {
Expand Down Expand Up @@ -103,7 +105,7 @@ const VizSpecificOptions = ({
<RangeOptions options={options} updateVizOptions={updateVizOptions} />
);
case VIZ_TYPE_ROBOTMODEL:
return null;
return <RobotModelLinksJoints vizInstance={vizInstance} />;
case VIZ_TYPE_TF:
return null;
case VIZ_TYPE_WRENCH:
Expand Down
5 changes: 5 additions & 0 deletions src/panels/visualizations/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -251,13 +251,16 @@ class Visualization extends React.PureComponent {

resetVisualization() {
const {
id,
options,
options: { topicName, visible, vizType },
rosInstance,
viewer,
vizInstances,
} = this.props;
if (this.vizInstance) {
this.vizInstance.destroy();
vizInstances.delete(this.vizInstance);
}

this.vizInstance = Visualization.getNewViz(
Expand All @@ -270,6 +273,8 @@ class Visualization extends React.PureComponent {
if (!this.vizInstance) {
return;
}
this.vizInstance.key = id;
vizInstances.add(this.vizInstance);
if (vizType === VIZ_TYPE_ROBOTMODEL) {
viewer.addRobot(this.vizInstance);
} else if (vizType === VIZ_TYPE_IMAGE) {
Expand Down

0 comments on commit ac3e0bc

Please sign in to comment.