Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

219

220

221

222

223

224

225

226

227

228

229

230

231

232

233

234

235

236

237

238

239

240

241

242

243

244

245

246

247

248

249

250

251

252

253

254

255

256

257

258

259

260

261

262

263

264

265

266

267

268

269

270

271

272

273

274

275

276

277

278

279

280

281

282

283

284

285

286

287

288

289

290

291

292

293

294

295

296

297

298

299

300

301

302

303

304

305

306

307

308

309

310

311

312

313

314

315

316

317

318

319

320

321

322

323

324

325

326

327

328

329

330

331

332

333

334

335

336

337

338

339

340

341

342

343

344

345

346

347

348

349

350

351

352

353

354

355

356

357

358

359

360

361

362

363

364

365

366

367

368

369

370

371

372

373

374

375

376

377

378

379

380

381

382

383

384

385

386

387

388

389

390

391

392

393

394

395

396

397

398

399

400

401

402

403

404

405

406

407

408

409

410

411

412

413

414

415

416

417

418

419

420

421

422

423

424

425

426

427

428

429

430

431

432

433

434

435

436

437

438

439

440

441

442

443

444

445

446

447

448

449

450

451

452

453

454

455

456

457

458

459

460

461

462

463

464

465

466

467

468

469

470

471

472

473

474

475

476

477

478

479

480

481

482

483

484

485

486

487

488

489

490

491

492

493

494

495

496

497

498

499

500

501

502

503

504

505

506

507

508

509

510

511

512

513

514

515

516

517

518

519

520

521

522

523

524

525

526

527

528

529

530

531

532

533

534

535

536

537

538

539

540

541

542

543

544

545

546

547

548

549

550

551

552

553

554

555

556

557

558

559

560

561

562

563

564

565

566

567

568

569

570

571

572

573

574

575

576

577

578

579

580

581

582

583

584

585

586

587

588

589

590

591

592

593

594

595

596

597

598

599

600

601

602

603

604

605

606

607

608

609

610

611

612

import PythonQt 

from PythonQt import QtCore, QtGui 

import director.objectmodel as om 

import director.visualization as vis 

from director import affordanceitems 

from director import lcmUtils 

from director import callbacks 

from director import cameracontrol 

from director import splinewidget 

from director import transformUtils 

from director import teleoppanel 

from director import footstepsdriverpanel 

from director import applogic as app 

from director import vtkAll as vtk 

from director import filterUtils 

from director.shallowCopy import shallowCopy 

from director import segmentationpanel 

from director import segmentation 

from director import segmentationroutines 

from director.robotlinkselector import RobotLinkSelector 

from director.vieweventfilter import ViewEventFilter 

from director import viewbehaviors 

import numpy as np 

import ioUtils 

import os 

import re 

import random 

import colorsys 

 

# todo: refactor these global variables 

# several functions in this module depend on these global variables 

# which are set by calling ViewBehaviors.addRobotBehaviors(). 

# These could be refactored to be members of a new behaviors class. 

robotSystem = None 

robotModel = None 

handFactory = None 

neckDriver = None 

footstepsDriver = None 

robotLinkSelector = None 

lastRandomColor = 0.0 

 

 

def resetCameraToRobot(view): 

    t = robotModel.getLinkFrame('pelvis') 

    if t is None: 

        t = vtk.vtkTransform() 

 

    focalPoint = [0.0, 0.0, 0.25] 

    position = [-4.0, -2.0, 2.25] 

    t.TransformPoint(focalPoint, focalPoint) 

    t.TransformPoint(position, position) 

    flyer = cameracontrol.Flyer(view) 

    flyer.zoomTo(focalPoint, position) 

 

 

def resetCameraToHeadView(view): 

 

    head = robotModel.getLinkFrame('head') 

    pelvis = robotModel.getLinkFrame('pelvis') 

 

    viewDirection = np.array([1.0, 0.0, 0.0]) 

    pelvis.TransformVector(viewDirection, viewDirection) 

 

    cameraPosition = np.array(head.GetPosition()) + 0.10 * viewDirection 

 

    camera = view.camera() 

 

    focalOffset = np.array(camera.GetFocalPoint()) - np.array(camera.GetPosition()) 

    focalOffset /= np.linalg.norm(focalOffset) 

 

    camera.SetPosition(cameraPosition) 

    camera.SetFocalPoint(cameraPosition + focalOffset*0.03) 

    camera.SetViewUp([0, 0, 1]) 

    camera.SetViewAngle(90) 

    view.render() 

 

 

def getChildFrame(obj): 

    if hasattr(obj, 'getChildFrame'): 

        return obj.getChildFrame() 

 

 

def placeHandModel(displayPoint, view, side='left'): 

 

    obj, _ = vis.findPickedObject(displayPoint, view) 

    if isinstance(obj, vis.FrameItem): 

        _, handFrame = handFactory.placeHandModelWithTransform(obj.transform, view, side=side, parent=obj.parent()) 

        handFrame.frameSync = vis.FrameSync() 

        handFrame.frameSync.addFrame(obj) 

        handFrame.frameSync.addFrame(handFrame, ignoreIncoming=True) 

        return 

 

    pickedPoint, prop, _, normal = vis.pickPoint(displayPoint, view, pickType='cells', tolerance=0.0, returnNormal=True) 

 

    obj = vis.getObjectByProp(prop) 

    if not obj: 

        return 

 

    yaxis = -normal 

    zaxis = [0,0,1] 

    xaxis = np.cross(yaxis, zaxis) 

    xaxis /= np.linalg.norm(xaxis) 

    zaxis = np.cross(xaxis, yaxis) 

    zaxis /= np.linalg.norm(zaxis) 

 

    t = transformUtils.getTransformFromAxes(-zaxis, yaxis, xaxis) 

    t.PostMultiply() 

    t.Translate(pickedPoint) 

 

    if side == 'right': 

        t.PreMultiply() 

        t.RotateY(180) 

 

    handObj, handFrame = handFactory.placeHandModelWithTransform(t, view, side=side, parent=obj) 

 

    syncFrame = getChildFrame(obj) 

    if syncFrame: 

        handFrame.frameSync = vis.FrameSync() 

        handFrame.frameSync.addFrame(handFrame, ignoreIncoming=True) 

        handFrame.frameSync.addFrame(syncFrame) 

 

 

def newWalkingGoal(displayPoint, view): 

 

    footFrame = footstepsDriver.getFeetMidPoint(robotModel) 

 

    worldPt1, worldPt2 = vis.getRayFromDisplayPoint(view, displayPoint) 

    groundOrigin = footFrame.GetPosition() 

    groundNormal = [0.0, 0.0, 1.0] 

    selectedGroundPoint = [0.0, 0.0, 0.0] 

 

    t = vtk.mutable(0.0) 

    vtk.vtkPlane.IntersectWithLine(worldPt1, worldPt2, groundNormal, groundOrigin, t, selectedGroundPoint) 

 

    walkingTarget = transformUtils.frameFromPositionAndRPY(selectedGroundPoint, np.array(footFrame.GetOrientation())) 

 

    footstepsdriverpanel.panel.onNewWalkingGoal(walkingTarget) 

 

 

def toggleFootstepWidget(displayPoint, view, useHorizontalWidget=False): 

 

    obj, _ = vis.findPickedObject(displayPoint, view) 

 

    if not obj: 

        return False 

 

    name = obj.getProperty('Name') 

 

    if name in ('footstep widget', 'footstep widget frame'): 

        om.removeFromObjectModel(om.findObjectByName('footstep widget')) 

        return True 

 

    match = re.match('^step (\d+)$', name) 

    if not match: 

        return False 

 

    stepIndex = int(match.group(1)) 

 

    existingWidget = om.findObjectByName('footstep widget') 

    if existingWidget: 

        previousStep = existingWidget.stepIndex 

        om.removeFromObjectModel(existingWidget) 

        if previousStep == stepIndex: 

            return True 

 

 

    footMesh = shallowCopy(obj.polyData) 

    footFrame = transformUtils.copyFrame(obj.getChildFrame().transform) 

 

    if useHorizontalWidget: 

        rpy = [0.0, 0.0, transformUtils.rollPitchYawFromTransform(footFrame)[2]] 

        footFrame = transformUtils.frameFromPositionAndRPY(footFrame.GetPosition(), np.degrees(rpy)) 

 

    footObj = vis.showPolyData(footMesh, 'footstep widget', parent='planning', alpha=0.2) 

    footObj.stepIndex = stepIndex 

    frameObj = vis.showFrame(footFrame, 'footstep widget frame', parent=footObj, scale=0.2) 

    footObj.actor.SetUserTransform(frameObj.transform) 

    footObj.setProperty('Color', obj.getProperty('Color')) 

    frameObj.setProperty('Edit', True) 

 

    rep = frameObj.widget.GetRepresentation() 

    rep.SetTranslateAxisEnabled(2, False) 

    rep.SetRotateAxisEnabled(0, False) 

    rep.SetRotateAxisEnabled(1, False) 

    frameObj.widget.HandleRotationEnabledOff() 

 

    walkGoal = om.findObjectByName('walking goal') 

    if walkGoal: 

        walkGoal.setProperty('Edit', False) 

 

 

    def onFootWidgetChanged(frame): 

        footstepsDriver.onStepModified(stepIndex - 1, frame) 

 

    frameObj.connectFrameModified(onFootWidgetChanged) 

    return True 

 

 

def reachToFrame(frameObj, side, collisionObj): 

    goalFrame = teleoppanel.panel.endEffectorTeleop.newReachTeleop(frameObj.transform, side, collisionObj) 

    goalFrame.frameSync = vis.FrameSync() 

    goalFrame.frameSync.addFrame(goalFrame, ignoreIncoming=True) 

    goalFrame.frameSync.addFrame(frameObj) 

 

 

def getAsFrame(obj): 

    if isinstance(obj, vis.FrameItem): 

        return obj 

    elif hasattr(obj, 'getChildFrame'): 

        return obj.getChildFrame() 

 

 

def isGraspSeed(obj): 

    return hasattr(obj, 'side') 

 

 

def getCollisionParent(obj): 

    ''' 

    If obj is an affordance, return obj 

    If obj is a frame or a grasp seed, return first parent. 

    ''' 

    if isinstance(obj, vis.FrameItem): 

        return obj.parent() 

    if isGraspSeed(obj): 

        return obj.parent() 

    else: 

        return obj 

 

 

# The most recently cached PickedPoint - available as input to any other algorithm 

lastCachedPickedPoint = np.array([0,0,0]) 

 

 

def getObjectAsPointCloud(obj): 

    try: 

        obj = obj.model.polyDataObj 

    except AttributeError: 

        pass 

 

    try: 

        obj.polyData 

    except AttributeError: 

        return None 

 

    if obj and obj.polyData.GetNumberOfPoints():# and (obj.polyData.GetNumberOfCells() == obj.polyData.GetNumberOfVerts()): 

        return obj 

 

 

def getRobotActions(view, pickedObj, pickedPoint): 

 

    reachFrame = getAsFrame(pickedObj) 

    collisionParent = getCollisionParent(pickedObj) 

    pointCloudObj = getObjectAsPointCloud(pickedObj) 

    affordanceObj = pickedObj if isinstance(pickedObj, affordanceitems.AffordanceItem) else None 

 

    def onReachLeft(): 

        reachToFrame(reachFrame, 'left', collisionParent) 

 

    def onReachRight(): 

        reachToFrame(reachFrame, 'right', collisionParent) 

 

    def flipHandSide(): 

        for obj in [pickedObj] + pickedObj.children(): 

            if not isGraspSeed(obj): 

                continue 

            side = 'right' if obj.side == 'left' else 'left' 

            obj.side = side 

            color = [1.0, 1.0, 0.0] 

            if side == 'right': 

                color = [0.33, 1.0, 0.0] 

            obj.setProperty('Color', color) 

 

            polyData = handFactory.getNewHandPolyData(side) 

            obj.setPolyData(polyData) 

 

            handFrame = obj.children()[0] 

            t = transformUtils.copyFrame(handFrame.transform) 

            t.PreMultiply() 

            t.RotateY(180) 

            handFrame.copyFrame(t) 

 

            objName = obj.getProperty('Name') 

            frameName = handFrame.getProperty('Name') 

            if side == 'left': 

                obj.setProperty('Name', objName.replace("right", "left")) 

                handFrame.setProperty('Name', frameName.replace("right", "left")) 

            else: 

                obj.setProperty('Name', objName.replace("left", "right")) 

                handFrame.setProperty('Name', frameName.replace("left", "right")) 

            obj._renderAllViews() 

 

    def flipHandThumb(): 

        handFrame = pickedObj.children()[0] 

        t = transformUtils.copyFrame(handFrame.transform) 

        t.PreMultiply() 

        t.RotateY(180) 

        handFrame.copyFrame(t) 

        pickedObj._renderAllViews() 

 

    def onSplineLeft(): 

        splinewidget.planner.newSpline(pickedObj, 'left') 

 

    def onSplineRight(): 

        splinewidget.planner.newSpline(pickedObj, 'right') 

 

 

    def onSegmentGround(): 

        groundPoints, scenePoints =  segmentation.removeGround(pointCloudObj.polyData) 

        vis.showPolyData(groundPoints, 'ground points', color=[0,1,0], parent='segmentation') 

        vis.showPolyData(scenePoints, 'scene points', color=[1,0,1], parent='segmentation') 

        pickedObj.setProperty('Visible', False) 

 

 

    def onCopyPointCloud(): 

        global lastRandomColor 

        polyData = vtk.vtkPolyData() 

        polyData.DeepCopy(pointCloudObj.polyData) 

 

        if pointCloudObj.getChildFrame(): 

            polyData = segmentation.transformPolyData(polyData, pointCloudObj.getChildFrame().transform) 

        polyData = segmentation.addCoordArraysToPolyData(polyData) 

 

        # generate random color, and average with a common color to make them generally similar 

        lastRandomColor = lastRandomColor + 0.1 + 0.1*random.random() 

        rgb = colorsys.hls_to_rgb(lastRandomColor, 0.7, 1.0) 

        obj = vis.showPolyData(polyData, pointCloudObj.getProperty('Name') + ' copy', color=rgb, parent='point clouds') 

 

        #t = vtk.vtkTransform() 

        #t.PostMultiply() 

        #t.Translate(filterUtils.computeCentroid(polyData)) 

        #segmentation.makeMovable(obj, t) 

        om.setActiveObject(obj) 

        pickedObj.setProperty('Visible', False) 

 

    def onMergeIntoPointCloud(): 

        allPointClouds = om.findObjectByName('point clouds') 

        if allPointClouds: 

            allPointClouds = [i.getProperty('Name') for i in allPointClouds.children()] 

        sel =  QtGui.QInputDialog.getItem(None, "Point Cloud Merging", "Pick point cloud to merge into:", allPointClouds, current=0, editable=False) 

        sel = om.findObjectByName(sel) 

 

        # Make a copy of each in same frame 

        polyDataInto = vtk.vtkPolyData() 

        polyDataInto.ShallowCopy(sel.polyData) 

        if sel.getChildFrame(): 

            polyDataInto = segmentation.transformPolyData(polyDataInto, sel.getChildFrame().transform) 

 

        polyDataFrom = vtk.vtkPolyData() 

        polyDataFrom.DeepCopy(pointCloudObj.polyData) 

        if pointCloudObj.getChildFrame(): 

            polyDataFrom = segmentation.transformPolyData(polyDataFrom, pointCloudObj.getChildFrame().transform) 

 

        # Actual merge 

        append = filterUtils.appendPolyData([polyDataFrom, polyDataInto]) 

        if sel.getChildFrame(): 

            polyDataInto = segmentation.transformPolyData(polyDataInto, sel.getChildFrame().transform.GetInverse()) 

 

        # resample 

        append = segmentationroutines.applyVoxelGrid(append, 0.01) 

        append = segmentation.addCoordArraysToPolyData(append) 

 

        # Recenter the frame 

        sel.setPolyData(append) 

        t = vtk.vtkTransform() 

        t.PostMultiply() 

        t.Translate(filterUtils.computeCentroid(append)) 

        segmentation.makeMovable(sel, t) 

 

        # Hide the old one 

        if pointCloudObj.getProperty('Name') in allPointClouds: 

            pointCloudObj.setProperty('Visible', False) 

 

 

    def onSegmentTableScene(): 

        data = segmentation.segmentTableScene(pointCloudObj.polyData, pickedPoint) 

        vis.showClusterObjects(data.clusters, parent='segmentation') 

        segmentation.showTable(data.table, parent='segmentation') 

 

 

    def onSegmentDrillAlignedWithTable(): 

        segmentation.segmentDrillAlignedWithTable(pickedPoint, pointCloudObj.polyData) 

 

    def onCachePickedPoint(): 

        ''' Cache the Picked Point for general purpose use''' 

        global lastCachedPickedPoint 

        lastCachedPickedPoint = pickedPoint 

        #data = segmentation.segmentTableScene(pointCloudObj.polyData, pickedPoint) 

        #vis.showClusterObjects(data.clusters + [data.table], parent='segmentation') 

 

 

    def onLocalPlaneFit(): 

        planePoints, normal = segmentation.applyLocalPlaneFit(pointCloudObj.polyData, pickedPoint, searchRadius=0.1, searchRadiusEnd=0.2) 

        obj = vis.showPolyData(planePoints, 'local plane fit', color=[0,1,0]) 

        obj.setProperty('Point Size', 7) 

 

        fields = segmentation.makePolyDataFields(obj.polyData) 

 

        pose = transformUtils.poseFromTransform(fields.frame) 

        desc = dict(classname='BoxAffordanceItem', Name='local plane', Dimensions=list(fields.dims), pose=pose) 

        box = segmentation.affordanceManager.newAffordanceFromDescription(desc) 

 

    def onOrientToMajorPlane(): 

        polyData, planeFrame = segmentation.orientToMajorPlane(pointCloudObj.polyData, pickedPoint=pickedPoint) 

        pointCloudObj.setPolyData(polyData) 

 

 

    def onDiskGlyph(): 

        result = segmentation.applyDiskGlyphs(pointCloudObj.polyData) 

        obj = vis.showPolyData(result, 'disks', color=[0.8,0.8,0.8]) 

        om.setActiveObject(obj) 

        pickedObj.setProperty('Visible', False) 

 

    def onArrowGlyph(): 

        result = segmentation.applyArrowGlyphs(pointCloudObj.polyData) 

        obj = vis.showPolyData(result, 'arrows') 

 

    def onSegmentationEditor(): 

        segmentationpanel.activateSegmentationMode(pointCloudObj.polyData) 

 

    def addNewFrame(): 

        t = transformUtils.copyFrame(affordanceObj.getChildFrame().transform) 

        t.PostMultiply() 

        t.Translate(np.array(pickedPoint) - np.array(t.GetPosition())) 

        newFrame = vis.showFrame(t, '%s frame %d' % (affordanceObj.getProperty('Name'), len(affordanceObj.children())), scale=0.2, parent=affordanceObj) 

        affordanceObj.getChildFrame().getFrameSync().addFrame(newFrame, ignoreIncoming=True) 

 

    def copyAffordance(): 

        desc = dict(affordanceObj.getDescription()) 

        del desc['uuid'] 

        desc['Name'] = desc['Name'] + ' copy' 

        aff = robotSystem.affordanceManager.newAffordanceFromDescription(desc) 

        aff.getChildFrame().setProperty('Edit', True) 

 

    def onPromoteToAffordance(): 

        affObj = affordanceitems.MeshAffordanceItem.promotePolyDataItem(pickedObj) 

        robotSystem.affordanceManager.registerAffordance(affObj) 

 

 

    actions = [] 

 

 

    if affordanceObj: 

        actions.extend([ 

            ('Copy affordance', copyAffordance), 

            ('Add new frame', addNewFrame), 

        ]) 

 

    elif type(pickedObj) == vis.PolyDataItem: 

        actions.extend([ 

            ('Promote to Affordance', onPromoteToAffordance), 

        ]) 

 

    if isGraspSeed(pickedObj): 

        actions.extend([ 

            (None, None), 

            ('Flip Side', flipHandSide), 

            ('Flip Thumb', flipHandThumb), 

        ]) 

 

    if reachFrame is not None: 

        actions.extend([ 

            (None, None), 

            ('Reach Left', onReachLeft), 

            ('Reach Right', onReachRight), 

            #('Spline Left', onSplineLeft), 

            #('Spline Right', onSplineRight), 

            ]) 

 

    if pointCloudObj: 

        actions.extend([ 

            (None, None), 

            ('Copy Pointcloud', onCopyPointCloud), 

            ('Merge Pointcloud Into', onMergeIntoPointCloud), 

            ('Segment Ground', onSegmentGround), 

            ('Segment Table', onSegmentTableScene), 

            ('Segment Drill Aligned', onSegmentDrillAlignedWithTable), 

            ('Local Plane Fit', onLocalPlaneFit), 

            ('Orient with Horizontal', onOrientToMajorPlane), 

            ('Arrow Glyph', onArrowGlyph), 

            ('Disk Glyph', onDiskGlyph), 

            ('Cache Pick Point', onCachePickedPoint), 

            (None, None), 

            ('Open Segmentation Editor', onSegmentationEditor) 

            ]) 

 

    return actions 

 

 

viewbehaviors.registerContextMenuActions(getRobotActions) 

 

 

class RobotViewEventFilter(ViewEventFilter): 

 

    def onMouseWheel(self, event): 

        if neckDriver: 

            neckDriver.onWheelDelta(event.delta()) 

 

    def onMouseMove(self, event): 

 

        for picker in segmentation.viewPickers: 

            if not picker.enabled: 

                continue 

 

            picker.onMouseMove(self.getMousePositionInView(event), event.modifiers()) 

            self.consumeEvent() 

 

    def onLeftMousePress(self, event): 

        if event.modifiers() == QtCore.Qt.ControlModifier: 

            displayPoint = self.getMousePositionInView(event) 

            if footstepsDriver: 

                newWalkingGoal(displayPoint, self.view) 

                self.consumeEvent() 

 

        for picker in segmentation.viewPickers: 

            if not picker.enabled: 

                continue 

 

            picker.onMousePress(self.getMousePositionInView(event), event.modifiers()) 

            self.consumeEvent() 

 

    def onLeftDoubleClick(self, event): 

 

        displayPoint = self.getMousePositionInView(event) 

 

        useHorizontalWidget =  (event.modifiers() == QtCore.Qt.ShiftModifier) 

        if toggleFootstepWidget(displayPoint, self.view, useHorizontalWidget): 

            self.consumeEvent() 

            return 

 

        if robotLinkSelector and robotLinkSelector.selectLink(displayPoint, self.view): 

            self.consumeEvent() 

            return 

 

    def onKeyPress(self, event): 

 

        consumed = False 

 

        key = str(event.text()).lower() 

 

        if key == 'r': 

            consumed = True 

            if robotModel is not None: 

                resetCameraToRobot(self.view) 

 

        elif key == 's': 

            if handFactory is not None: 

                side = 'left' if event.modifiers() != QtCore.Qt.ShiftModifier else 'right' 

                placeHandModel(self.getCursorDisplayPosition(), self.view, side) 

        elif key == 'n': 

            if neckDriver: 

                neckDriver.activateNeckControl() 

 

        elif key in ['0', '1', '2', '3']: 

            if neckDriver: 

                neckDriver.applyNeckPitchPreset(int(key)) 

 

        if consumed: 

            self.consumeEvent() 

 

    def onKeyRelease(self, event): 

        if str(event.text()).lower() == 'n': 

            if neckDriver: 

                neckDriver.deactivateNeckControl() 

 

 

class KeyPressLogCommander(ViewEventFilter): 

 

    def __init__(self, view): 

        ViewEventFilter.__init__(self, view) 

        self.commander = lcmUtils.LogPlayerCommander() 

 

    def onKeyPressRepeat(self, event): 

 

        key = str(event.text()).lower() 

        consumed = True 

 

        if key == 'p': 

            self.commander.togglePlay() 

        elif key == 'n': 

            self.commander.step() 

        elif key in ('+', '='): 

            self.commander.faster() 

        elif key in ('-', '_'): 

            self.commander.slower() 

        elif key == '[': 

            self.commander.back() 

        elif key == ']': 

            self.commander.forward() 

        else: 

            consumed = False 

 

        if consumed: 

            self.consumeEvent() 

 

 

class RobotViewBehaviors(object): 

 

    def __init__(self, view, _robotSystem): 

        self.view = view 

        self.viewBehaviors = viewbehaviors.ViewBehaviors(view) 

        self.logCommander = KeyPressLogCommander(view) 

        self.robotViewBehaviors = RobotViewEventFilter(view) 

 

        global robotSystem, robotModel, handFactory, footstepsDriver, neckDriver, robotLinkSelector 

 

        robotSystem = _robotSystem 

        robotModel = robotSystem.robotStateModel 

        handFactory = robotSystem.handFactory 

        footstepsDriver = robotSystem.footstepsDriver 

        neckDriver = robotSystem.neckDriver 

        if app.getMainWindow() is not None: 

            robotLinkSelector = RobotLinkSelector()