GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: src/windows-manager.cpp Lines: 1 632 0.2 %
Date: 2020-05-14 11:23:33 Branches: 2 1574 0.1 %

Line Branch Exec Source
1
// Copyright (c) 2015, Joseph Mirabel
2
// Authors: Joseph Mirabel (joseph.mirabel@laas.fr)
3
//
4
// This file is part of gepetto-viewer.
5
// gepetto-viewer is free software: you can redistribute it
6
// and/or modify it under the terms of the GNU Lesser General Public
7
// License as published by the Free Software Foundation, either version
8
// 3 of the License, or (at your option) any later version.
9
//
10
// gepetto-viewer is distributed in the hope that it will be
11
// useful, but WITHOUT ANY WARRANTY; without even the implied warranty
12
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
// General Lesser Public License for more details.  You should have
14
// received a copy of the GNU Lesser General Public License along with
15
// gepetto-viewer. If not, see <http://www.gnu.org/licenses/>.
16
17
#include "gepetto/viewer/windows-manager.h"
18
19
#include <sys/types.h>
20
#include <sys/stat.h>
21
#include <unistd.h>
22
23
#include <algorithm>
24
25
#include <OpenThreads/ScopedLock>
26
27
#include <osgDB/WriteFile>
28
#include <osgDB/Registry>
29
#include <osgDB/ReaderWriter>
30
31
#include <gepetto/viewer/window-manager.h>
32
#include <gepetto/viewer/node.h>
33
#include <gepetto/viewer/group-node.h>
34
#include <gepetto/viewer/leaf-node-box.h>
35
#include <gepetto/viewer/leaf-node-capsule.h>
36
#include <gepetto/viewer/leaf-node-cone.h>
37
#include <gepetto/viewer/leaf-node-cylinder.h>
38
#include <gepetto/viewer/leaf-node-line.h>
39
#include <gepetto/viewer/leaf-node-face.h>
40
#include <gepetto/viewer/leaf-node-sphere.h>
41
#include <gepetto/viewer/leaf-node-arrow.h>
42
#include <gepetto/viewer/leaf-node-light.h>
43
#include <gepetto/viewer/leaf-node-xyzaxis.h>
44
#include <gepetto/viewer/node-rod.h>
45
#include <gepetto/viewer/roadmap-viewer.h>
46
#include <gepetto/viewer/macros.h>
47
#include <gepetto/viewer/config-osg.h>
48
#include <gepetto/viewer/leaf-node-ground.h>
49
#include <gepetto/viewer/leaf-node-collada.h>
50
#include <gepetto/viewer/urdf-parser.h>
51
#include <gepetto/viewer/blender-geom-writer.h>
52
53
#define RETURN_FALSE_IF_NODE_EXISTS(name)                                      \
54
  if (nodeExists(name)) {                                                      \
55
    std::cerr << "Node \"" << name << "\" already exists." << std::endl;       \
56
    return false;                                                              \
57
  }
58
59
#define RETURN_FALSE_IF_NODE_DOES_NOT_EXIST(name)                              \
60
  if (!nodeExists(name)) {                                                     \
61
    std::cerr << "Node \"" << name << "\" does not exist." << std::endl;       \
62
    return false;                                                              \
63
  }
64
65
#define THROW_IF_NODE_EXISTS(name)                                             \
66
  if (nodeExists(name)) {                                                      \
67
    std::ostringstream oss;                                                    \
68
    oss << "Node \"" << name << "\" already exists.";                          \
69
    throw std::invalid_argument (oss.str ().c_str ());				       \
70
  }
71
72
#define THROW_IF_NODE_DOES_NOT_EXIST(name)                                     \
73
  if (!nodeExists(name)) {                                                     \
74
    std::ostringstream oss;                                                    \
75
    oss << "Node \"" << name << "\" does not exist.";                          \
76
    throw std::invalid_argument (oss.str ().c_str ());				       \
77
  }
78
79
#define FIND_NODE_OF_TYPE_OR_THROW(NodeType, varname, nodename)                \
80
  NodeType##Ptr_t varname (dynamic_pointer_cast <NodeType>                     \
81
      (getNode(nodename, true)));                                              \
82
  if (!varname) {                                                              \
83
    std::ostringstream oss;                                                    \
84
    oss << "Node \"" << nodename << "\" is not of type " #NodeType;             \
85
    throw std::invalid_argument (oss.str ().c_str ());				       \
86
  }
87
88
#define RETURN_FALSE_IF_WINDOW_DOES_NOT_EXIST(var,name)                        \
89
  WindowManagerPtr_t var = getWindowManager(name, false);                      \
90
  if (!var) {                                                                  \
91
    std::cerr << "Window \"" << name << "\" does not exist." << std::endl;     \
92
    return false;                                                              \
93
  }
94
95
namespace gepetto {
96
namespace viewer {
97
    namespace {
98
      typedef std::map<std::string, NodePtr_t>::iterator          NodeMapIt;
99
      typedef std::map<std::string, NodePtr_t>::const_iterator    NodeMapConstIt;
100
101
      typedef std::map<std::string, GroupNodePtr_t>::iterator          GroupNodeMapIt;
102
      typedef std::map<std::string, GroupNodePtr_t>::const_iterator    GroupNodeMapConstIt;
103
104
      typedef ScopedLock ScopedLock;
105
    }
106
107
    BlenderFrameCapture::BlenderFrameCapture () :
108
      writer_visitor_ (new TransformWriterVisitor
109
          (new YamlTransformWriter ("gepetto_viewer.yaml"))),
110
      nodes_ ()
111
    {}
112
113
    void BlenderFrameCapture::captureFrame ()
114
    {
115
      using std::invalid_argument;
116
      if (!writer_visitor_)
117
        throw invalid_argument ("Capture writer not defined");
118
      if (nodes_.empty()) throw invalid_argument ("No node to capture");
119
      writer_visitor_->captureFrame (nodes_.begin(), nodes_.end());
120
    }
121
122
    WindowsManager::WindowsManager () :
123
        windowManagers_ (), nodes_ (), groupNodes_ (),roadmapNodes_(),
124
        osgFrameMtx_ (), configListMtx_ (), newNodeConfigurations_ (),
125
        autoCaptureTransform_ (false)
126
    {}
127
128
    WindowsManager::WindowID WindowsManager::addWindow (std::string winName,
129
            WindowManagerPtr_t newWindow)
130
    {
131
      WindowManagerMap_t::const_iterator it = windowManagers_.find (winName);
132
      if (it != windowManagers_.end ())
133
        throw std::invalid_argument ("A window with this name already exists.");
134
135
      windowManagers_.insert(std::make_pair(winName, newWindow));
136
      addGroup (winName, newWindow->getScene(), false);
137
      return winName;
138
    }
139
140
    WindowsManagerPtr_t WindowsManager::create ()
141
    {
142
      WindowsManagerPtr_t shPtr (new WindowsManager());
143
      return shPtr;
144
    }
145
146
    osgVector4 WindowsManager::getColor (const std::string& colorName)
147
    {
148
        if (colorName == "blue")
149
            return osgVector4 (0.f, 0.f, 1.f, 1.f);
150
        else if (colorName == "green")
151
            return osgVector4 (0.f, 1.f, 0.f, 1.f);
152
        else if (colorName == "red")
153
            return osgVector4 (1.f, 0.f, 0.f, 1.f);
154
        else if (colorName == "white")
155
            return osgVector4 (1.f, 1.f, 1.f, 1.f);
156
        else
157
            return osgVector4 (0.f, 0.f, 0.f, 1.f);
158
    }
159
160
    VisibilityMode WindowsManager::getVisibility (const std::string& vName)
161
    {
162
        if (vName == "OFF")
163
            return VISIBILITY_OFF;
164
        else if (vName == "ALWAYS_ON_TOP")
165
            return ALWAYS_ON_TOP;
166
        else if (vName == "ON")
167
            return VISIBILITY_ON;
168
        else {
169
            std::cout << "Visibility mode not known, visibility mode can be"
170
                " \"ON\",\"OFF\" or \"ALWAYS_ON_TOP\"." << std::endl;
171
            std::cout << "Visibility mode set to default = \"ON\"." << std::endl;
172
            return VISIBILITY_ON;
173
        }
174
    }
175
176
    WireFrameMode WindowsManager::getWire (const std::string& wireName)
177
    {
178
        if (wireName == "WIREFRAME")
179
            return WIREFRAME;
180
        else if (wireName == "FILL_AND_WIREFRAME")
181
            return FILL_AND_WIREFRAME;
182
        else if (wireName == "FILL")
183
            return FILL;
184
        else {
185
            std::cout << "Wire mode not known, wire mode can be \"FILL\","
186
                "\"WIREFRAME\" or \"FILL_AND_WIREFRAME\"." << std::endl;
187
            std::cout << "Wire mode set to default = \"FILL\"." << std::endl;
188
            return FILL;
189
        }
190
    }
191
192
    LightingMode WindowsManager::getLight (const std::string& lightName)
193
    {
194
        if (lightName == "OFF")
195
            return LIGHT_INFLUENCE_OFF;
196
        else if (lightName == "ON")
197
            return LIGHT_INFLUENCE_ON;
198
        else {
199
            std::cout << "Lighting mode not known, lighting mode can be "
200
                "\"ON\" or \"OFF\"." << std::endl;
201
            std::cout << "Lighting mode set to default = \"ON\"." << std::endl;
202
            return LIGHT_INFLUENCE_ON;
203
        }
204
    }
205
206
    std::string WindowsManager::parentName (const std::string& name)
207
    {
208
        std::string::size_type slash = name.find_last_of ('/');
209
        if (slash == std::string::npos) return "";
210
        else return name.substr(0, slash);
211
    }
212
213
    NodePtr_t WindowsManager::find (const std::string name, GroupNodePtr_t)
214
    {
215
      NodeMapIt it = nodes_.find (name);
216
      if (it == nodes_.end ()) {
217
        std::string::size_type slash = name.find_first_of ('/');
218
        if (slash == std::string::npos)
219
          return NodePtr_t ();
220
        GroupNodeMapIt itg = groupNodes_.find (name.substr (0, slash));
221
        if (itg == groupNodes_.end ())
222
          return NodePtr_t ();
223
        return find (name.substr (slash + 1), itg->second);
224
      }
225
      return it->second;
226
    }
227
228
    bool WindowsManager::nodeExists (const std::string& name)
229
    {
230
      NodeMapConstIt it = nodes_.find (name);
231
      return (it != nodes_.end ());
232
    }
233
234
    NodePtr_t WindowsManager::getNode (const std::string& name,
235
        bool throwIfDoesntExist) const
236
    {
237
      NodeMapConstIt it = nodes_.find (name);
238
      if (it == nodes_.end ()) {
239
        if (throwIfDoesntExist) {
240
          std::ostringstream oss;
241
          oss << "No node with name \"" << name << "\".";
242
          throw std::invalid_argument (oss.str ().c_str ());
243
        } else
244
          return NodePtr_t();
245
      }
246
      return it->second;
247
    }
248
249
    template <typename Iterator, typename NodeContainer_t>
250
      std::size_t WindowsManager::getNodes
251
      (const Iterator& begin, const Iterator& end, NodeContainer_t& nodes)
252
    {
253
      const std::size_t l = nodes.size();
254
      for (Iterator it = begin; it != end; ++it) {
255
        std::string name (*it);
256
        NodePtr_t n = getNode (name);
257
        if (n) nodes.push_back (n);
258
        else std::cout << "Node \"" << name << "\" doesn't exist." << std::endl;
259
      }
260
      return nodes.size() - l;
261
    }
262
263
    void WindowsManager::initParent (NodePtr_t node, GroupNodePtr_t parent)
264
    {
265
      if (parent && !parent->hasChild(node)) parent->addChild (node);
266
    }
267
268
    void WindowsManager::addNode (const std::string& nodeName, NodePtr_t node,
269
        bool guessParent)
270
    {
271
      GroupNodePtr_t parent;
272
      if (guessParent) parent = getGroup(parentName(nodeName));
273
      addNode(nodeName, node, parent);
274
    }
275
276
    void WindowsManager::addNode (const std::string& nodeName, NodePtr_t node,
277
        GroupNodePtr_t parent)
278
    {
279
      initParent (node, parent);
280
      nodes_[nodeName] = node;
281
    }
282
283
    void WindowsManager::addGroup (const std::string& groupName,
284
            GroupNodePtr_t group,
285
            bool guessParent)
286
    {
287
      GroupNodePtr_t parent;
288
      if (guessParent) parent = getGroup(parentName(groupName));
289
      addGroup (groupName, group, parent);
290
    }
291
292
    void WindowsManager::addGroup(const std::string& groupName,
293
        GroupNodePtr_t group, GroupNodePtr_t parent)
294
    {
295
      initParent (group, parent);
296
      nodes_[groupName] = group;
297
      groupNodes_[groupName] = group;
298
    }
299
300
    //Public functions
301
302
    WindowsManager::WindowID WindowsManager::getWindowID (const std::string& wn)
303
    {
304
        WindowManagerMap_t::const_iterator it = windowManagers_.find (wn);
305
        if (it == windowManagers_.end ())
306
            throw std::invalid_argument ("There is no windows with that name");
307
        return wn;
308
    }
309
310
    void WindowsManager::createScene (const std::string& sceneName)
311
    {
312
      createGroup(sceneName);
313
    }
314
315
    void WindowsManager::createSceneWithFloor (const std::string& sceneName)
316
    {
317
        createScene(sceneName);
318
        addFloor((sceneName + "/floor").c_str());
319
    }
320
321
    bool WindowsManager::addSceneToWindow (const std::string& sceneName,
322
            WindowID windowId)
323
    {
324
        GroupNodePtr_t group = getGroup(sceneName, true);
325
        RETURN_FALSE_IF_WINDOW_DOES_NOT_EXIST(window, windowId);
326
        ScopedLock lock(osgFrameMutex());
327
        window->addNode (group);
328
        return true;
329
    }
330
331
     bool WindowsManager::attachCameraToNode(const std::string& nodeName, const WindowID windowId)
332
     {
333
        NodePtr_t node = getNode(nodeName, true);
334
        RETURN_FALSE_IF_WINDOW_DOES_NOT_EXIST(window, windowId);
335
  	ScopedLock lock(osgFrameMutex());
336
	window->attachCameraToNode(node);
337
	return true;
338
     }
339
340
     bool WindowsManager::detachCamera(const WindowID windowId)
341
     {
342
        RETURN_FALSE_IF_WINDOW_DOES_NOT_EXIST(window, windowId);
343
  	ScopedLock lock(osgFrameMutex());
344
	window->detachCamera();
345
	return true;
346
     }
347
348
    bool WindowsManager::addFloor(const std::string& floorName)
349
    {
350
        RETURN_FALSE_IF_NODE_EXISTS(floorName);
351
        LeafNodeGroundPtr_t floor = LeafNodeGround::create (floorName);
352
        ScopedLock lock(osgFrameMutex());
353
        addNode (floorName, floor, true);
354
        return true;
355
    }
356
357
    bool WindowsManager::addBox (const std::string& boxName,
358
            const float& boxSize1,
359
            const float& boxSize2,
360
            const float& boxSize3,
361
            const Color_t& color)
362
    {
363
        RETURN_FALSE_IF_NODE_EXISTS(boxName);
364
365
        LeafNodeBoxPtr_t box = LeafNodeBox::create
366
          (boxName, osgVector3 (.5f*boxSize1, .5f*boxSize2, .5f*boxSize3), color);
367
        ScopedLock lock(osgFrameMutex());
368
        addNode (boxName, box, true);
369
        return true;
370
    }
371
372
    bool WindowsManager::addCapsule (const std::string& capsuleName,
373
            const float radius,
374
            const float height,
375
            const Color_t& color)
376
    {
377
        RETURN_FALSE_IF_NODE_EXISTS(capsuleName);
378
379
        LeafNodeCapsulePtr_t capsule = LeafNodeCapsule::create (capsuleName, radius, height, color);
380
        ScopedLock lock(osgFrameMutex());
381
        addNode (capsuleName, capsule, true);
382
        return true;
383
    }
384
385
    bool WindowsManager::addArrow (const std::string& arrowName,
386
            const float radius,
387
            const float length,
388
            const Color_t& color)
389
    {
390
        RETURN_FALSE_IF_NODE_EXISTS(arrowName);
391
392
        LeafNodeArrowPtr_t arrow = LeafNodeArrow::create (arrowName, color, radius, length);
393
        ScopedLock lock(osgFrameMutex());
394
        addNode (arrowName, arrow, true);
395
        return true;
396
    }
397
398
    bool WindowsManager::addRod (const std::string& rodName,
399
            const Color_t& color,
400
            const float radius,
401
            const float length,
402
            short maxCapsule)
403
    {
404
      RETURN_FALSE_IF_NODE_EXISTS(rodName);
405
406
      NodeRodPtr_t rod = NodeRod::create(rodName,color,radius,length,maxCapsule);
407
      ScopedLock lock(osgFrameMutex());
408
      addNode (rodName, rod, true);
409
      for(size_t i = 0 ; i < (size_t) maxCapsule ; i++)
410
        addNode(rod->getCapsuleName(i),rod->getCapsule(i), false);
411
      return true;
412
    }
413
414
    bool WindowsManager::resizeCapsule(const std::string& capsuleName, float newHeight)
415
    {
416
        FIND_NODE_OF_TYPE_OR_THROW (LeafNodeCapsule, cap, capsuleName);
417
        ScopedLock lock(osgFrameMutex());
418
        cap->setHeight(newHeight);
419
        return true;
420
    }
421
422
    bool WindowsManager::resizeArrow(const std::string& arrowName ,float newRadius, float newLength)
423
    {
424
        FIND_NODE_OF_TYPE_OR_THROW (LeafNodeArrow, arrow, arrowName);
425
        ScopedLock lock(osgFrameMutex());
426
        arrow->resize(newRadius,newLength);
427
        return true;
428
    }
429
430
    bool WindowsManager::addMesh (const std::string& meshName,
431
            const std::string& meshPath)
432
    {
433
        RETURN_FALSE_IF_NODE_EXISTS(meshName);
434
        LeafNodeColladaPtr_t mesh;
435
        try {
436
          mesh = LeafNodeCollada::create (meshName,
437
              urdfParser::getFilename(meshPath));
438
        } catch (const std::exception& exc) {
439
          std::cout << exc.what() << std::endl;
440
          return false;
441
        }
442
        ScopedLock lock(osgFrameMutex());
443
        addNode (meshName, mesh, true);
444
        return true;
445
    }
446
447
    void WindowsManager::removeLightSources (const std::string& meshName)
448
    {
449
        FIND_NODE_OF_TYPE_OR_THROW (LeafNodeCollada, mesh, meshName);
450
        ScopedLock lock(osgFrameMutex());
451
        mesh->removeLightSources();
452
    }
453
454
    bool WindowsManager::addCone (const std::string& coneName,
455
            const float radius, const float height,
456
            const Color_t& color)
457
    {
458
        RETURN_FALSE_IF_NODE_EXISTS(coneName);
459
460
        LeafNodeConePtr_t cone = LeafNodeCone::create
461
          (coneName, radius, height, color);
462
        ScopedLock lock(osgFrameMutex());
463
        addNode (coneName, cone, true);
464
        return true;
465
    }
466
467
    bool WindowsManager::addCylinder (const std::string& cylinderName,
468
            const float radius,
469
            const float height,
470
            const Color_t& color)
471
    {
472
        RETURN_FALSE_IF_NODE_EXISTS(cylinderName);
473
474
        LeafNodeCylinderPtr_t cylinder = LeafNodeCylinder::create
475
          (cylinderName, radius, height, color);
476
        ScopedLock lock(osgFrameMutex());
477
        addNode (cylinderName, cylinder, true);
478
        return true;
479
    }
480
481
    bool WindowsManager::addSphere (const std::string& sphereName,
482
            const float radius,
483
            const Color_t& color)
484
    {
485
        RETURN_FALSE_IF_NODE_EXISTS(sphereName);
486
487
        LeafNodeSpherePtr_t sphere = LeafNodeSphere::create
488
          (sphereName, radius, color);
489
        ScopedLock lock(osgFrameMutex());
490
        addNode (sphereName, sphere, true);
491
        return true;
492
    }
493
494
    bool WindowsManager::addLight (const std::string& lightName,
495
            const WindowID wid,
496
            const float radius,
497
            const Color_t& color)
498
    {
499
        RETURN_FALSE_IF_NODE_EXISTS(lightName);
500
501
        WindowManagerPtr_t wm = getWindowManager(wid, true);
502
        LeafNodeLightPtr_t light = LeafNodeLight::create
503
          (lightName, radius, color);
504
        ScopedLock lock(osgFrameMutex());
505
        addNode (lightName, light, true);
506
        light->setRoot (wm->getScene ());
507
        return true;
508
    }
509
510
    bool WindowsManager::addLine (const std::string& lineName,
511
            const osgVector3& pos1,
512
            const osgVector3& pos2,
513
            const Color_t& color)
514
    {
515
        RETURN_FALSE_IF_NODE_EXISTS(lineName);
516
517
        LeafNodeLinePtr_t line = LeafNodeLine::create (lineName, pos1, pos2, color);
518
        ScopedLock lock(osgFrameMutex());
519
        addNode (lineName, line, true);
520
        return true;
521
    }
522
523
  bool WindowsManager::setLineStartPoint(const std::string& lineName,
524
                                            const osgVector3& pos1)
525
  {
526
    FIND_NODE_OF_TYPE_OR_THROW (LeafNodeLine, line, lineName);
527
    ScopedLock lock(osgFrameMutex());
528
    line->setStartPoint(pos1);
529
    return true;
530
  }
531
532
  bool WindowsManager::setLineEndPoint(const std::string& lineName,
533
                                            const osgVector3& pos2)
534
  {
535
    FIND_NODE_OF_TYPE_OR_THROW (LeafNodeLine, line, lineName);
536
    ScopedLock lock(osgFrameMutex());
537
    line->setEndPoint(pos2);
538
    return true;
539
  }
540
541
  bool WindowsManager::setLineExtremalPoints(const std::string& lineName,
542
                                             const osgVector3& pos1,
543
                                             const osgVector3& pos2)
544
  {
545
    FIND_NODE_OF_TYPE_OR_THROW (LeafNodeLine, line, lineName);
546
    ScopedLock lock(osgFrameMutex());
547
    line->setStartPoint(pos1);
548
    line->setEndPoint(pos2);
549
    return true;
550
  }
551
552
    bool WindowsManager::addCurve (const std::string& curveName,
553
            const Vec3ArrayPtr_t& pos,
554
            const Color_t& color)
555
    {
556
      RETURN_FALSE_IF_NODE_EXISTS(curveName);
557
      if (pos->size () < 2) {
558
        throw std::invalid_argument ("Need at least two points");
559
      }
560
      LeafNodeLinePtr_t curve = LeafNodeLine::create (curveName, pos, color);
561
      curve->setMode (GL_LINE_STRIP);
562
      ScopedLock lock(osgFrameMutex());
563
      addNode (curveName, curve, true);
564
      return true;
565
    }
566
567
  bool WindowsManager::setCurvePoints (const std::string& curveName,
568
                                       const Vec3ArrayPtr_t& pos)
569
  {
570
    FIND_NODE_OF_TYPE_OR_THROW (LeafNodeLine, curve, curveName);
571
    if (pos->size () < 2) {
572
        throw std::invalid_argument ("Need at least two points");
573
    }
574
    ScopedLock lock(osgFrameMutex());
575
    curve->setPoints(pos);
576
    return true;
577
  }
578
579
  bool WindowsManager::setCurveColors (const std::string& curveName,
580
                                       const Vec4ArrayPtr_t& colors)
581
  {
582
    FIND_NODE_OF_TYPE_OR_THROW (LeafNodeLine, curve, curveName);
583
    ScopedLock lock(osgFrameMutex());
584
    curve->setColors(colors);
585
    return true;
586
  }
587
588
    bool WindowsManager::setCurveMode (const std::string& curveName, const GLenum mode)
589
    {
590
        FIND_NODE_OF_TYPE_OR_THROW (LeafNodeLine, curve, curveName);
591
        ScopedLock lock(osgFrameMutex());
592
        curve->setMode (mode);
593
        return true;
594
    }
595
596
    bool WindowsManager::setCurvePointsSubset (const std::string& curveName,
597
        const int first, const std::size_t count)
598
    {
599
        FIND_NODE_OF_TYPE_OR_THROW (LeafNodeLine, curve, curveName);
600
        ScopedLock lock(osgFrameMutex());
601
        curve->setPointsSubset (first, count);
602
        return true;
603
    }
604
605
    bool WindowsManager::setCurveLineWidth (const std::string& curveName, const float& width)
606
    {
607
        FIND_NODE_OF_TYPE_OR_THROW (LeafNodeLine, curve, curveName);
608
        setFloatProperty(curveName, "LineWidth", width);
609
        return true;
610
    }
611
612
    bool WindowsManager::addTriangleFace (const std::string& faceName,
613
            const osgVector3& pos1,
614
            const osgVector3& pos2,
615
            const osgVector3& pos3,
616
            const Color_t& color)
617
    {
618
      RETURN_FALSE_IF_NODE_EXISTS (faceName);
619
620
      LeafNodeFacePtr_t face = LeafNodeFace::create (faceName, pos1, pos2, pos3, color);
621
      ScopedLock lock(osgFrameMutex());
622
      addNode (faceName, face, true);
623
      return true;
624
    }
625
626
    bool WindowsManager::addSquareFace (const std::string& faceName,
627
            const osgVector3& pos1,
628
            const osgVector3& pos2,
629
            const osgVector3& pos3,
630
            const osgVector3& pos4,
631
            const Color_t& color)
632
    {
633
      RETURN_FALSE_IF_NODE_EXISTS(faceName);
634
635
      LeafNodeFacePtr_t face = LeafNodeFace::create
636
        (faceName, pos1, pos2, pos3, pos4, color);
637
      ScopedLock lock(osgFrameMutex());
638
      addNode (faceName, face, true);
639
      return true;
640
    }
641
642
  bool WindowsManager::setTexture (const std::string& nodeName,
643
				   const std::string& filename)
644
  {
645
    FIND_NODE_OF_TYPE_OR_THROW (LeafNodeFace, faceNode, nodeName);
646
647
    if (faceNode->nbVertices () != 4) {
648
      std::ostringstream oss;
649
      oss << "Face should have 4 vertices to apply texture. "
650
	  << nodeName << " has " << faceNode->nbVertices () << ".";
651
      throw std::runtime_error (oss.str ());
652
    }
653
    faceNode->setTexture (filename);
654
    return true;
655
  }
656
657
    bool WindowsManager::addXYZaxis (const std::string& nodeName,const Color_t& color, float radius, float sizeAxis)
658
    {
659
      RETURN_FALSE_IF_NODE_EXISTS (nodeName);
660
661
      LeafNodeXYZAxisPtr_t axis = LeafNodeXYZAxis::create
662
        (nodeName,color,radius,sizeAxis);
663
      ScopedLock lock(osgFrameMutex());
664
      addNode (nodeName, axis, true);
665
      return true;
666
    }
667
668
    bool WindowsManager::createRoadmap(const std::string& roadmapName,const Color_t& colorNode, float radius, float sizeAxis, const Color_t& colorEdge)
669
    {
670
      RETURN_FALSE_IF_NODE_EXISTS(roadmapName);
671
672
      RoadmapViewerPtr_t rm = RoadmapViewer::create(roadmapName,colorNode,radius,sizeAxis,colorEdge);
673
      ScopedLock lock(osgFrameMutex());
674
      addNode (roadmapName, rm, true);
675
      roadmapNodes_[roadmapName]=rm;
676
      return true;
677
    }
678
679
    bool WindowsManager::addEdgeToRoadmap(const std::string& nameRoadmap, const osgVector3& posFrom, const osgVector3& posTo)
680
    {
681
        if (roadmapNodes_.find (nameRoadmap) == roadmapNodes_.end ()) {
682
            //no node named nodeName
683
            std::cout << "No roadmap named \"" << nameRoadmap << "\"" << std::endl;
684
            return false;
685
        }
686
        else {
687
            RoadmapViewerPtr_t rm_ptr = roadmapNodes_[nameRoadmap];
688
          //  ScopedLock lock(osgFrameMutex()); mtx is now locked only when required in addEdge
689
            rm_ptr->addEdge(posFrom,posTo,osgFrameMutex());
690
            return true;
691
        }
692
    }
693
694
    bool WindowsManager::addNodeToRoadmap(const std::string& nameRoadmap, const Configuration& conf)
695
    {
696
        if (roadmapNodes_.find (nameRoadmap) == roadmapNodes_.end ()) {
697
            //no node named nodeName
698
            std::cout << "No roadmap named \"" << nameRoadmap << "\"" << std::endl;
699
            return false;
700
        }
701
        else {
702
            RoadmapViewerPtr_t rm_ptr = roadmapNodes_[nameRoadmap];
703
           // ScopedLock lock(osgFrameMutex());
704
            rm_ptr->addNode(conf.position,conf.quat,osgFrameMutex());
705
            return true;
706
        }
707
    }
708
709
    std::vector<std::string> WindowsManager::getNodeList ()
710
    {
711
        std::vector<std::string> l;
712
        for (NodeMapIt it=nodes_.begin (); it!=nodes_.end (); ++it) {
713
            l.push_back (it->first);
714
        }
715
        return l;
716
    }
717
718
    std::vector<std::string> WindowsManager::getGroupNodeList (const std::string& group)
719
    {
720
        std::vector<std::string> l;
721
        GroupNodePtr_t g (getGroup(group));
722
        if(!g) return l;
723
        l.reserve(g->getNumOfChildren());
724
        for(std::size_t i = 0; i < g->getNumOfChildren(); ++i)
725
          l.push_back(g->getChild(i)->getID());
726
        return l;
727
    }
728
729
    std::vector<std::string> WindowsManager::getSceneList ()
730
    {
731
        std::vector<std::string> l;
732
        l.reserve(groupNodes_.size());
733
        for (GroupNodeMapConstIt it = groupNodes_.begin ();
734
            it!=groupNodes_.end (); ++it)
735
            l.push_back (it->first);
736
        return l;
737
    }
738
739
    std::vector<std::string> WindowsManager::getWindowList ()
740
    {
741
        std::vector<std::string> l;
742
        l.reserve(windowManagers_.size());
743
        for (WindowManagerMap_t::const_iterator it = windowManagers_.begin ();
744
                it!=windowManagers_.end (); ++it) {
745
            l.push_back (it->first);
746
        }
747
        return l;
748
    }
749
750
    bool WindowsManager::createGroup (const std::string& groupName)
751
    {
752
      RETURN_FALSE_IF_NODE_EXISTS(groupName);
753
754
      GroupNodePtr_t groupNode = GroupNode::create (groupName);
755
      ScopedLock lock(osgFrameMutex());
756
      addGroup (groupName, groupNode, true);
757
      return true;
758
    }
759
760
    bool WindowsManager::addURDF (const std::string& urdfName,
761
            const std::string& urdfPath)
762
    {
763
      return loadUDRF(urdfName, urdfPath, true, true);
764
    }
765
766
    bool WindowsManager::addURDF (const std::string& urdfName,
767
            const std::string& urdfPath,
768
            const std::string& /*urdfPackagePath*/)
769
    {
770
      return addURDF(urdfName, urdfPath);
771
    }
772
773
    bool WindowsManager::addUrdfCollision (const std::string& urdfName,
774
            const std::string& urdfPath)
775
    {
776
      return loadUDRF(urdfName, urdfPath, false, true);
777
    }
778
779
    bool WindowsManager::addUrdfCollision (const std::string& urdfName,
780
            const std::string& urdfPath, const std::string& /*urdfPackagePath*/)
781
    {
782
      return addUrdfCollision (urdfName, urdfPath);
783
    }
784
785
    void WindowsManager::addUrdfObjects (const std::string& urdfName,
786
            const std::string& urdfPath,
787
            bool visual)
788
    {
789
      loadUDRF(urdfName, urdfPath, visual, false);
790
    }
791
792
    void WindowsManager::addUrdfObjects (const std::string& urdfName,
793
            const std::string& urdfPath,
794
            const std::string& /*urdfPackagePath*/,
795
            bool visual)
796
    {
797
      return addUrdfObjects (urdfName, urdfPath, visual);
798
    }
799
800
    bool WindowsManager::loadUDRF(const std::string& urdfName,
801
        const std::string& urdfPath, bool visual, bool linkFrame)
802
    {
803
      RETURN_FALSE_IF_NODE_EXISTS(urdfName);
804
805
      GroupNodePtr_t urdf =
806
        urdfParser::parse (urdfName, urdfPath, visual, linkFrame);
807
      ScopedLock lock(osgFrameMutex());
808
      addGroup (urdfName, urdf, true);
809
      NodePtr_t link;
810
      for (std::size_t i=0; i< urdf->getNumOfChildren (); i++) {
811
        link = urdf->getChild (i);
812
        GroupNodePtr_t groupNode (dynamic_pointer_cast
813
            <GroupNode> (link));
814
        if (groupNode) {
815
          addGroup(link->getID(), groupNode, urdf);
816
          for (std::size_t j=0; j < groupNode->getNumOfChildren (); ++j) {
817
            NodePtr_t object (groupNode->getChild (j));
818
            addNode(object->getID (), object, groupNode);
819
          }
820
        } else {
821
          addNode(link->getID(), link, urdf);
822
        }
823
      }
824
      return true;
825
    }
826
827
    bool WindowsManager::addToGroup (const std::string& nodeName,
828
            const std::string& groupName)
829
    {
830
        NodePtr_t node = getNode(nodeName, true);
831
        GroupNodePtr_t group = getGroup(groupName, true);
832
833
        if (group->hasChild(node)) return false;
834
835
        ScopedLock lock(osgFrameMutex());// if addChild is called in the same time as osg::frame(), gepetto-viewer crash
836
        groupNodes_[groupName]->addChild (nodes_[nodeName]);
837
        return true;
838
    }
839
840
    bool WindowsManager::removeFromGroup (const std::string& nodeName,
841
            const std::string& groupName)
842
    {
843
        if (nodes_.find (nodeName) == nodes_.end () ||
844
                groupNodes_.find (groupName) == groupNodes_.end ()) {
845
            std::cout << "Node name \"" << nodeName << "\" and/or groupNode \""
846
                << groupName << "\" doesn't exist." << std::endl;
847
            return false;
848
        }
849
        else {
850
            ScopedLock lock(osgFrameMutex());
851
            groupNodes_[groupName]->removeChild(nodes_[nodeName]);
852
            return true;
853
        }
854
    }
855
856
    bool WindowsManager::deleteNode (const std::string& nodeName, bool all)
857
    {
858
        NodePtr_t n = getNode (nodeName);
859
        if (!n) return false;
860
        else {
861
            /// Check if it is a group
862
            GroupNodeMapIt it = groupNodes_.find(nodeName);
863
            if (it != groupNodes_.end ()) {
864
              if (all) {
865
                std::vector <std::string> names(it->second->getNumOfChildren ());
866
                for (std::size_t i = 0; i < names.size(); ++i)
867
                  names[i] = it->second->getChild (i)->getID();
868
                {
869
                  ScopedLock lock(osgFrameMutex());
870
                  it->second->removeAllChildren ();
871
                }
872
                for (std::size_t i = 0; i < names.size(); ++i)
873
                  deleteNode (names[i], all);
874
              }
875
              {
876
                ScopedLock lock(osgFrameMutex());
877
                groupNodes_.erase (nodeName);
878
              }
879
            }
880
            GroupNodeMapConstIt itg;
881
            ScopedLock lock(osgFrameMutex());
882
            for (itg = groupNodes_.begin (); itg != groupNodes_.end(); ++itg) {
883
              if (itg->second && itg->second->hasChild (n))
884
                itg->second->removeChild(n);
885
            }
886
            nodes_.erase (nodeName);
887
            return true;
888
        }
889
    }
890
891
    bool WindowsManager::applyConfiguration (const std::string& nodeName,
892
            const Configuration& configuration)
893
    {
894
        // TODO should we throw ?
895
        if (!configuration.valid()) return false;
896
        NodePtr_t updatedNode = getNode (nodeName, false);
897
        if (!updatedNode) return false;
898
899
        NodeConfiguration newNodeConfiguration;
900
        newNodeConfiguration.node = updatedNode;
901
        ((Configuration&)newNodeConfiguration) = configuration;
902
903
        ScopedLock lock(configListMtx_);
904
        newNodeConfigurations_.push_back (newNodeConfiguration);
905
        return true;
906
    }
907
908
    bool WindowsManager::applyConfigurations (const std::vector<std::string>& nodeNames,
909
            const std::vector<Configuration>& configurations)
910
    {
911
        if (nodeNames.size() != configurations.size())
912
          throw std::invalid_argument ("Number of node names and configurations must be equal.");
913
914
        newNodeConfigurations_.reserve (
915
            newNodeConfigurations_.capacity() + nodeNames.size());
916
917
        bool success = true;
918
        ScopedLock lock(configListMtx_);
919
        for (std::size_t i = 0; i < nodeNames.size(); ++i) {
920
          NodePtr_t updatedNode = getNode (nodeNames[i], false);
921
          if (!updatedNode) {
922
            success = false;
923
            continue;
924
          }
925
926
          NodeConfiguration newNodeConfiguration;
927
          newNodeConfiguration.node = updatedNode;
928
          newNodeConfiguration.position = configurations[i].position;
929
          newNodeConfiguration.quat = configurations[i].quat;
930
931
          newNodeConfigurations_.push_back (newNodeConfiguration);
932
        }
933
934
        return success;
935
    }
936
937
    bool WindowsManager::addLandmark (const std::string& nodeName,
938
            float size)
939
    {
940
        THROW_IF_NODE_DOES_NOT_EXIST(nodeName);
941
	ScopedLock lock(osgFrameMutex());
942
        nodes_[nodeName]->addLandmark (size);
943
        return true;
944
    }
945
946
    bool WindowsManager::deleteLandmark (const std::string& nodeName)
947
    {
948
        THROW_IF_NODE_DOES_NOT_EXIST(nodeName);
949
	ScopedLock lock(osgFrameMutex());
950
        nodes_[nodeName]->deleteLandmark ();
951
        return true;
952
    }
953
954
    Configuration WindowsManager::getStaticTransform (const std::string& nodeName) const
955
    {
956
        NodePtr_t node = getNode(nodeName, true);
957
        return Configuration(node->getStaticPosition (),
958
                             node->getStaticRotation ());
959
    }
960
961
  bool WindowsManager::setStaticTransform (const std::string& nodeName,
962
      const Configuration& transform)
963
  {
964
    RETURN_FALSE_IF_NODE_DOES_NOT_EXIST(nodeName);
965
    ScopedLock lock(osgFrameMutex());
966
    nodes_[nodeName]->setStaticTransform(transform.position,transform.quat);
967
    return true;
968
  }
969
970
    bool WindowsManager::setVisibility (const std::string& nodeName,
971
            const std::string& visibilityMode)
972
    {
973
        RETURN_FALSE_IF_NODE_DOES_NOT_EXIST(nodeName);
974
        VisibilityMode visibility =  getVisibility (visibilityMode);
975
	ScopedLock lock(osgFrameMutex());
976
        nodes_[nodeName]->setVisibilityMode (visibility);
977
        return true;
978
    }
979
980
    bool WindowsManager::setScale(const std::string& nodeName, const osgVector3& scale)
981
    {
982
        THROW_IF_NODE_DOES_NOT_EXIST(nodeName);
983
        ScopedLock lock(osgFrameMutex());
984
        nodes_[nodeName]->setScale(scale);
985
        return true;
986
    }
987
988
    bool WindowsManager::setScale(const std::string& nodeName, const float& scale)
989
    {
990
      return setScale(nodeName, osgVector3(scale, scale, scale));
991
    }
992
993
    bool WindowsManager::setScale(const std::string& nodeName, const int& scalePercentage)
994
    {
995
      return setScale (nodeName, (value_type)scalePercentage / 100);
996
    }
997
998
    bool WindowsManager::setAlpha(const std::string& nodeName, const float& alpha)
999
    {
1000
        RETURN_FALSE_IF_NODE_DOES_NOT_EXIST(nodeName);
1001
  	ScopedLock lock(osgFrameMutex());
1002
        nodes_[nodeName]->setAlpha (alpha);
1003
        return true;
1004
    }
1005
1006
    bool WindowsManager::setAlpha(const std::string& nodeName, const int& alphaPercentage)
1007
    {
1008
      return setAlpha (nodeName, (float)alphaPercentage / 100);
1009
    }
1010
1011
    bool WindowsManager::setColor(const std::string& nodeName, const Color_t& color)
1012
    {
1013
        RETURN_FALSE_IF_NODE_DOES_NOT_EXIST(nodeName);
1014
        osgVector4 vecColor(color[0],color[1],color[2],color[3]);
1015
        ScopedLock lock(osgFrameMutex());
1016
        nodes_[nodeName]->setColor (vecColor);
1017
        return true;
1018
    }
1019
1020
    bool WindowsManager::setWireFrameMode (const std::string& nodeName,
1021
            const std::string& wireFrameMode)
1022
    {
1023
        RETURN_FALSE_IF_NODE_DOES_NOT_EXIST(nodeName);
1024
        WireFrameMode wire = getWire (wireFrameMode);
1025
	ScopedLock lock(osgFrameMutex());
1026
        nodes_[nodeName]->setWireFrameMode (wire);
1027
	return true;
1028
    }
1029
1030
    bool WindowsManager::setLightingMode (const std::string& nodeName,
1031
            const std::string& lightingMode)
1032
    {
1033
        RETURN_FALSE_IF_NODE_DOES_NOT_EXIST(nodeName);
1034
        LightingMode light = getLight (lightingMode);
1035
	ScopedLock lock(osgFrameMutex());
1036
        nodes_[nodeName]->setLightingMode (light);
1037
        return true;
1038
    }
1039
1040
    bool WindowsManager::setHighlight (const std::string& nodeName,
1041
            int state)
1042
    {
1043
        RETURN_FALSE_IF_NODE_DOES_NOT_EXIST(nodeName);
1044
	ScopedLock lock(osgFrameMutex());
1045
        nodes_[nodeName]->setHighlightState (state);
1046
        return true;
1047
    }
1048
1049
    bool WindowsManager::setCaptureTransform (const std::string& filename,
1050
        const std::vector<std::string>& nodeNames)
1051
    {
1052
        blenderCapture_.nodes_.clear ();
1053
        std::size_t nb = getNodes (nodeNames.begin(), nodeNames.end(),
1054
            blenderCapture_.nodes_);
1055
        blenderCapture_.writer_visitor_->writer_ =
1056
          new YamlTransformWriter (filename);
1057
        return nb == nodeNames.size();
1058
    }
1059
1060
    void WindowsManager::captureTransformOnRefresh (bool autoCapture)
1061
    {
1062
      autoCaptureTransform_ = autoCapture;
1063
    }
1064
1065
    void WindowsManager::captureTransform ()
1066
    {
1067
        // This requires only a read access to the scene.
1068
        // The only requirement is that no node get delete while accessing them.
1069
	//ScopedLock lock(osgFrameMutex());
1070
        blenderCapture_.captureFrame ();
1071
    }
1072
1073
    bool WindowsManager::writeBlenderScript (const std::string& filename,
1074
        const std::vector<std::string>& nodeNames)
1075
    {
1076
      std::vector<NodePtr_t> nodes;
1077
      std::size_t nb = getNodes (nodeNames.begin(), nodeNames.end(), nodes);
1078
      if (nb != nodeNames.size())
1079
        throw std::invalid_argument ("Could not find one of the nodes");
1080
      BlenderGeomWriterVisitor visitor (filename);
1081
      for (std::size_t i = 0; i < nodes.size(); ++i)
1082
        nodes[i]->accept(visitor);
1083
      return true;
1084
    }
1085
1086
    bool WindowsManager::writeNodeFile (const std::string& nodeName,
1087
        const std::string& filename)
1088
    {
1089
        RETURN_FALSE_IF_NODE_DOES_NOT_EXIST(nodeName);
1090
        ScopedLock lock(osgFrameMutex());
1091
        osg::ref_ptr <osgDB::Options> os = new osgDB::Options;
1092
        os->setOptionString ("NoExtras");
1093
        osgDB::ReaderWriter::WriteResult wr =
1094
          osgDB::Registry::instance()->writeNode
1095
          (*nodes_[nodeName]->asGroup (), std::string (filename), os.get());
1096
        if (!wr.success()) {
1097
          std::ostringstream oss;
1098
          oss << "Error writing file " << filename << ": " << wr.message();
1099
          throw std::runtime_error (oss.str ().c_str ());
1100
        }
1101
        return wr.success();
1102
    }
1103
1104
    bool WindowsManager::writeWindowFile (const WindowID windowId,
1105
        const std::string& filename)
1106
    {
1107
        RETURN_FALSE_IF_WINDOW_DOES_NOT_EXIST(window, windowId);
1108
        ScopedLock lock(osgFrameMutex());
1109
        bool ret = window->writeNodeFile (std::string (filename));
1110
        return ret;
1111
    }
1112
1113
    WindowManagerPtr_t WindowsManager::getWindowManager (const WindowID wid,
1114
        bool throwIfDoesntExist) const
1115
    {
1116
      WindowManagerMap_t::const_iterator it = windowManagers_.find (wid);
1117
      if (it != windowManagers_.end ())
1118
        return it->second;
1119
      else if (throwIfDoesntExist)
1120
        throw std::invalid_argument ("Window ID " + wid + " doesn't exist.");
1121
      return WindowManagerPtr_t ();
1122
    }
1123
1124
    GroupNodePtr_t WindowsManager::getGroup (const std::string groupName,
1125
        bool throwIfDoesntExist) const
1126
    {
1127
      GroupNodeMapConstIt it = groupNodes_.find (groupName);
1128
        if (it == groupNodes_.end ()) {
1129
          if (throwIfDoesntExist) {
1130
            std::ostringstream oss;
1131
            oss << "No group with name \"" << groupName << "\".";
1132
            throw std::invalid_argument (oss.str ().c_str ());
1133
          } else
1134
            return GroupNodePtr_t ();
1135
        }
1136
        return it->second;
1137
    }
1138
1139
    Configuration WindowsManager::getNodeGlobalTransform(const std::string nodeName) const
1140
    {
1141
        NodePtr_t node = getNode(nodeName, true);
1142
        return node->getGlobalTransform();
1143
    }
1144
1145
    bool WindowsManager::setBackgroundColor1(const WindowID windowId,const Color_t& color)
1146
    {
1147
      WindowManagerPtr_t wm = getWindowManager(windowId, true);
1148
      ScopedLock lock(osgFrameMutex());
1149
      wm->setBackgroundColor1(color);
1150
      return true;
1151
    }
1152
1153
  bool WindowsManager::setBackgroundColor2(const WindowID windowId,const Color_t& color)
1154
  {
1155
    WindowManagerPtr_t wm = getWindowManager(windowId, true);
1156
    ScopedLock lock(osgFrameMutex());
1157
    wm->setBackgroundColor2(color);
1158
    return true;
1159
  }
1160
1161
  Configuration WindowsManager::getCameraTransform(const WindowID windowId){
1162
    osg::Quat rot;
1163
    osg::Vec3d pos;
1164
    WindowManagerPtr_t wm = getWindowManager(windowId, true);
1165
    ScopedLock lock(osgFrameMutex());
1166
    wm->getCameraTransform(pos,rot);
1167
    return Configuration(pos,rot);
1168
  }
1169
1170
  bool WindowsManager::setCameraTransform(const WindowID windowId,const Configuration& configuration){
1171
    WindowManagerPtr_t wm = getWindowManager(windowId, true);
1172
    ScopedLock lock(osgFrameMutex());
1173
    wm->setCameraTransform(configuration.position,configuration.quat);
1174
    return true;
1175
  }
1176
1177
  std::vector<std::string> WindowsManager::getPropertyNames(const std::string& nodeName) const
1178
  {
1179
    NodePtr_t node = getNode(nodeName, true);
1180
    const Properties::PropertyMap_t& map = node->properties();
1181
    std::vector<std::string> names;
1182
    names.reserve(map.size());
1183
    for (Properties::PropertyMap_t::const_iterator _prop = map.begin(); _prop != map.end(); ++_prop)
1184
      names.push_back(_prop->first);
1185
    return names;
1186
  }
1187
1188
  std::vector<std::string> WindowsManager::getPropertyTypes(const std::string& nodeName) const
1189
  {
1190
    NodePtr_t node = getNode(nodeName, true);
1191
    const Properties::PropertyMap_t& map = node->properties();
1192
    std::vector<std::string> types;
1193
    types.reserve(map.size());
1194
    for (Properties::PropertyMap_t::const_iterator _prop = map.begin(); _prop != map.end(); ++_prop)
1195
      types.push_back(_prop->second->type());
1196
    return types;
1197
  }
1198
1199
  template <typename Property_t>
1200
  Property_t WindowsManager::getProperty(const std::string& nodeName, const std::string& propName) const
1201
  {
1202
    NodePtr_t node = getNode(nodeName, true);
1203
    Property_t value;
1204
    if (!node->getProperty<Property_t>(propName, value)) {
1205
      throw std::invalid_argument ("Could not get the property");
1206
    }
1207
    return value;
1208
  }
1209
1210
  template <typename Property_t>
1211
  void WindowsManager::setProperty(const std::string& nodeName, const std::string& propName, const Property_t& value)
1212
  {
1213
    ScopedLock lock(osgFrameMutex());
1214
    NodePtr_t node = getNode(nodeName, true);
1215
    if (!node->setProperty<Property_t>(propName, value)) {
1216
      throw std::invalid_argument ("Could not set the property");
1217
    }
1218
  }
1219
1220
#define DEFINE_WINDOWS_MANAGER_GET_SET_PROPERTY_FOR_TYPE(Type,Name) \
1221
  Type WindowsManager::get ## Name ## Property(const std::string& nodeName, const std::string& propName) const \
1222
  { return getProperty<Type>(nodeName, propName); } \
1223
  void WindowsManager::set ## Name ## Property(const std::string& nodeName, const std::string& propName, const Type& value) \
1224
  { setProperty<Type>(nodeName, propName, value); }
1225
1226
#define INSTANCIATE_WINDOWS_MANAGER_GET_SET_PROPERTY_FOR_TYPE(Type) \
1227
  template Type WindowsManager::getProperty<Type>(const std::string&, const std::string&) const; \
1228
  template void WindowsManager::setProperty<Type>(const std::string&, const std::string&, const Type&)
1229
1230
  INSTANCIATE_WINDOWS_MANAGER_GET_SET_PROPERTY_FOR_TYPE(std::string);
1231
  INSTANCIATE_WINDOWS_MANAGER_GET_SET_PROPERTY_FOR_TYPE(osgVector2);
1232
  INSTANCIATE_WINDOWS_MANAGER_GET_SET_PROPERTY_FOR_TYPE(osgVector3);
1233
  INSTANCIATE_WINDOWS_MANAGER_GET_SET_PROPERTY_FOR_TYPE(osgVector4);
1234
  INSTANCIATE_WINDOWS_MANAGER_GET_SET_PROPERTY_FOR_TYPE(float);
1235
  INSTANCIATE_WINDOWS_MANAGER_GET_SET_PROPERTY_FOR_TYPE(bool);
1236
  INSTANCIATE_WINDOWS_MANAGER_GET_SET_PROPERTY_FOR_TYPE(int);
1237
1238
  DEFINE_WINDOWS_MANAGER_GET_SET_PROPERTY_FOR_TYPE(std::string, String)
1239
  DEFINE_WINDOWS_MANAGER_GET_SET_PROPERTY_FOR_TYPE(osgVector2, Vector2)
1240
  DEFINE_WINDOWS_MANAGER_GET_SET_PROPERTY_FOR_TYPE(osgVector3, Vector3)
1241
  DEFINE_WINDOWS_MANAGER_GET_SET_PROPERTY_FOR_TYPE(osgVector4, Color)
1242
  DEFINE_WINDOWS_MANAGER_GET_SET_PROPERTY_FOR_TYPE(float, Float)
1243
  DEFINE_WINDOWS_MANAGER_GET_SET_PROPERTY_FOR_TYPE(bool, Bool)
1244
  DEFINE_WINDOWS_MANAGER_GET_SET_PROPERTY_FOR_TYPE(int, Int)
1245
1246
  void WindowsManager::callVoidProperty(const std::string& nodeName, const std::string& propName)
1247
  {
1248
    NodePtr_t node = getNode(nodeName, true);
1249
    ScopedLock lock(osgFrameMutex());
1250
    if (!node->hasProperty(propName))
1251
      throw std::invalid_argument ("Could not find the property");
1252
    node->callVoidProperty(propName);
1253
  }
1254
} /* namespace viewer */
1255
1256

3
} // namespace gepetto