FreeCAD

Форк
0
/
GLGraphicsView.cpp 
696 строк · 20.7 Кб
1
/***************************************************************************
2
 *   Copyright (c) 2013 Werner Mayer <wmayer[at]users.sourceforge.net>     *
3
 *                                                                         *
4
 *   This file is part of the FreeCAD CAx development system.              *
5
 *                                                                         *
6
 *   This library is free software; you can redistribute it and/or         *
7
 *   modify it under the terms of the GNU Library General Public           *
8
 *   License as published by the Free Software Foundation; either          *
9
 *   version 2 of the License, or (at your option) any later version.      *
10
 *                                                                         *
11
 *   This library  is distributed in the hope that it will be useful,      *
12
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
13
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
14
 *   GNU Library General Public License for more details.                  *
15
 *                                                                         *
16
 *   You should have received a copy of the GNU Library General Public     *
17
 *   License along with this library; see the file COPYING.LIB. If not,    *
18
 *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
19
 *   Suite 330, Boston, MA  02111-1307, USA                                *
20
 *                                                                         *
21
 ***************************************************************************/
22

23

24
#include "PreCompiled.h"
25

26
#ifndef _PreComp_
27
#endif
28

29
#include <Inventor/SoEventManager.h>
30
#include <Inventor/SoRenderManager.h>
31
#include <Inventor/SbViewportRegion.h>
32
#include <Inventor/actions/SoGLRenderAction.h>
33
#include <Inventor/actions/SoSearchAction.h>
34
#include <Inventor/events/SoLocation2Event.h>
35
#include <Inventor/events/SoMouseButtonEvent.h>
36
#include <Inventor/nodes/SoSeparator.h>
37
#include <Inventor/nodes/SoOrthographicCamera.h>
38
#include <Inventor/nodes/SoDirectionalLight.h>
39
#include <Inventor/scxml/ScXML.h>
40
#include <Inventor/scxml/SoScXMLStateMachine.h>
41

42
#include <QApplication>
43
#include <QCheckBox>
44
#include <QColorDialog>
45
#include <QFileDialog>
46
#include <QLabel>
47
#include <QPushButton>
48
#include <QResizeEvent>
49
#include <QTimer>
50
#include <QVBoxLayout>
51
#include <QGraphicsView>
52
#include <QPaintEngine>
53
#include <QGraphicsItem>
54
#include <QGraphicsSceneMouseEvent>
55
#include <QGraphicsProxyWidget>
56
#include <QUrl>
57

58
#include "GLGraphicsView.h"
59
#include <App/Application.h>
60
#include <Gui/Document.h>
61
#include <Gui/ViewProvider.h>
62

63
#include <Quarter/devices/Mouse.h>
64
#include <Quarter/devices/Keyboard.h>
65
#include <Quarter/devices/SpaceNavigatorDevice.h>
66

67
using namespace Gui;
68

69
#ifndef GL_MULTISAMPLE
70
#define GL_MULTISAMPLE  0x809D
71
#endif
72

73
// http://doc.qt.digia.com/qq/qq26-openglcanvas.html
74

75
GraphicsView::GraphicsView()
76
{
77
}
78

79
GraphicsView::~GraphicsView()
80
{
81
}
82

83
bool GraphicsView::viewportEvent(QEvent* event)
84
{
85
    if (event->type() == QEvent::Paint || event->type() == QEvent::Resize) {
86
        return QGraphicsView::viewportEvent(event);
87
    }
88
    else if (event->type() == QEvent::MouseMove ||
89
             event->type() == QEvent::Wheel ||
90
             event->type() == QEvent::MouseButtonDblClick ||
91
             event->type() == QEvent::MouseButtonRelease ||
92
             event->type() == QEvent::MouseButtonPress) {
93
        QMouseEvent* mouse = static_cast<QMouseEvent*>(event);
94
        QGraphicsItem *item = itemAt(mouse->pos());
95
        if (!item) {
96
            QGraphicsView::viewportEvent(event);
97
            return false;
98
        }
99

100
        return QGraphicsView::viewportEvent(event);
101
    }
102

103
    return QGraphicsView::viewportEvent(event);
104
}
105

106
void GraphicsView::resizeEvent(QResizeEvent *event)
107
{
108
    if (scene())
109
        scene()->setSceneRect(
110
            QRect(QPoint(0, 0), event->size()));
111
    QGraphicsView::resizeEvent(event);
112
}
113

114

115
// ----------------------------------------------------------------------------
116

117
class SceneEventFilter::Private
118
{
119
public:
120
    QList<SIM::Coin3D::Quarter::InputDevice *> devices;
121
    GraphicsScene * scene;
122
    QPoint globalmousepos;
123
    SbVec2s windowsize;
124

125
    void trackWindowSize(QResizeEvent * event)
126
    {
127
        this->windowsize = SbVec2s(event->size().width(),
128
                                   event->size().height());
129

130
        Q_FOREACH(SIM::Coin3D::Quarter::InputDevice * device, this->devices) {
131
            device->setWindowSize(this->windowsize);
132
        }
133
    }
134

135
    void trackPointerPosition(QMouseEvent * event)
136
    {
137
        assert(this->windowsize[1] != -1);
138
        this->globalmousepos = event->globalPos();
139

140
        SbVec2s mousepos(event->pos().x(), this->windowsize[1] - event->pos().y() - 1);
141
        Q_FOREACH(SIM::Coin3D::Quarter::InputDevice * device, this->devices) {
142
            device->setMousePosition(mousepos);
143
        }
144
    }
145
};
146

147
#define PRIVATE(obj) obj->pimpl
148

149
SceneEventFilter::SceneEventFilter(QObject * parent)
150
  : QObject(parent)
151
{
152
    PRIVATE(this) = new Private;
153

154
    PRIVATE(this)->scene = dynamic_cast<GraphicsScene *>(parent);
155
    assert(PRIVATE(this)->scene);
156

157
    PRIVATE(this)->windowsize = SbVec2s(PRIVATE(this)->scene->width(),
158
                                        PRIVATE(this)->scene->height());
159

160
    PRIVATE(this)->devices += new SIM::Coin3D::Quarter::Mouse;
161
    PRIVATE(this)->devices += new SIM::Coin3D::Quarter::Keyboard;
162

163
#ifdef HAVE_SPACENAV_LIB
164
    PRIVATE(this)->devices += new SpaceNavigatorDevice;
165
#endif // HAVE_SPACENAV_LIB
166

167
}
168

169
SceneEventFilter::~SceneEventFilter()
170
{
171
    qDeleteAll(PRIVATE(this)->devices);
172
    delete PRIVATE(this);
173
}
174

175
/*!
176
  Adds a device for event translation
177
 */
178
void
179
SceneEventFilter::registerInputDevice(SIM::Coin3D::Quarter::InputDevice * device)
180
{
181
    PRIVATE(this)->devices += device;
182
}
183

184
/*!
185
  Removes a device from event translation
186
 */
187
void
188
SceneEventFilter::unregisterInputDevice(SIM::Coin3D::Quarter::InputDevice * device)
189
{
190
    int i = PRIVATE(this)->devices.indexOf(device);
191
    if (i != -1) {
192
        PRIVATE(this)->devices.removeAt(i);
193
    }
194
}
195

196
/*! Translates Qt Events into Coin events and passes them on to the
197
  event QuarterWidget for processing. If the event can not be
198
  translated or processed, it is forwarded to Qt and the method
199
  returns false.
200
 */
201
bool
202
SceneEventFilter::eventFilter(QObject *, QEvent * qevent)
203
{
204
    // Convert the scene event back to a standard event
205
    std::unique_ptr<QEvent> sceneev;
206
    switch (qevent->type()) {
207

208
    case QEvent::GraphicsSceneMouseMove:
209
        {
210
            QGraphicsSceneMouseEvent* ev = static_cast<QGraphicsSceneMouseEvent*>(qevent);
211
            sceneev.reset(new QMouseEvent(QEvent::MouseMove, ev->pos().toPoint(),
212
                ev->button(), ev->buttons(), ev->modifiers()));
213
            qevent = sceneev.get();
214
            break;
215
        }
216
    case QEvent::GraphicsSceneMousePress:
217
        {
218
            QGraphicsSceneMouseEvent* ev = static_cast<QGraphicsSceneMouseEvent*>(qevent);
219
            sceneev.reset(new QMouseEvent(QEvent::MouseButtonPress, ev->pos().toPoint(),
220
                ev->button(), ev->buttons(), ev->modifiers()));
221
            qevent = sceneev.get();
222
            break;
223
        }
224
    case QEvent::GraphicsSceneMouseRelease:
225
        {
226
            QGraphicsSceneMouseEvent* ev = static_cast<QGraphicsSceneMouseEvent*>(qevent);
227
            sceneev.reset(new QMouseEvent(QEvent::MouseButtonRelease, ev->pos().toPoint(),
228
                ev->button(), ev->buttons(), ev->modifiers()));
229
            qevent = sceneev.get();
230
            break;
231
        }
232
    case QEvent::GraphicsSceneMouseDoubleClick:
233
        {
234
            QGraphicsSceneMouseEvent* ev = static_cast<QGraphicsSceneMouseEvent*>(qevent);
235
            sceneev.reset(new QMouseEvent(QEvent::MouseButtonDblClick, ev->pos().toPoint(),
236
                ev->button(), ev->buttons(), ev->modifiers()));
237
            qevent = sceneev.get();
238
            break;
239
        }
240
    case QEvent::GraphicsSceneWheel:
241
        {
242
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
243
            QGraphicsSceneWheelEvent* ev = static_cast<QGraphicsSceneWheelEvent*>(qevent);
244
            sceneev.reset(new QWheelEvent(ev->pos().toPoint(), ev->delta(), ev->buttons(),
245
                ev->modifiers(), ev->orientation()));
246
            qevent = sceneev.get();
247
#endif
248
            break;
249
        }
250
    case QEvent::GraphicsSceneResize:
251
        {
252
            QGraphicsSceneResizeEvent* ev = static_cast<QGraphicsSceneResizeEvent*>(qevent);
253
            sceneev.reset(new QResizeEvent(ev->newSize().toSize(), ev->oldSize().toSize()));
254
            qevent = sceneev.get();
255
            break;
256
        }
257
    default:
258
        break;
259
    }
260

261
    // make sure every device has updated screen size and mouse position
262
    // before translating events
263
    switch (qevent->type()) {
264
    case QEvent::MouseMove:
265
    case QEvent::MouseButtonPress:
266
    case QEvent::MouseButtonRelease:
267
    case QEvent::MouseButtonDblClick:
268
        PRIVATE(this)->trackPointerPosition(dynamic_cast<QMouseEvent *>(qevent));
269
        break;
270
    case QEvent::Resize:
271
        PRIVATE(this)->trackWindowSize(dynamic_cast<QResizeEvent *>(qevent));
272
        break;
273
    default:
274
        break;
275
    }
276

277
    // translate QEvent into SoEvent and see if it is handled by scene
278
    // graph
279
    Q_FOREACH(SIM::Coin3D::Quarter::InputDevice * device, PRIVATE(this)->devices) {
280
        const SoEvent * soevent = device->translateEvent(qevent);
281
        if (soevent && PRIVATE(this)->scene->processSoEvent(soevent)) {
282
            //return true;
283
        }
284
    }
285
    return false;
286
}
287

288
/*!
289
  Returns mouse position in global coordinates
290
 */
291
const QPoint &
292
SceneEventFilter::globalMousePosition(void) const
293
{
294
    return PRIVATE(this)->globalmousepos;
295
}
296

297
#undef PRIVATE
298

299
// ----------------------------------------------------------------------------
300

301
QDialog *GraphicsScene::createDialog(const QString &windowTitle) const
302
{
303
    QDialog *dialog = new QDialog(0, Qt::Window | Qt::CustomizeWindowHint | Qt::WindowTitleHint);
304

305
    dialog->setWindowOpacity(0.8);
306
    dialog->setWindowTitle(windowTitle);
307
    dialog->setLayout(new QVBoxLayout);
308

309
    return dialog;
310
}
311

312
GraphicsScene::GraphicsScene()
313
    : m_backgroundColor(0, 170, 255)
314
    , m_lastTime(0)
315
    , m_distance(1.4f)
316
{
317
    headlight = new SoDirectionalLight();
318
    headlight->ref();
319
    sceneNode = new SoSeparator();
320
    sceneNode->ref();
321

322
    this->addEllipse(20,20, 120, 60);
323
    QWidget *controls = createDialog(tr("Controls"));
324

325
    QCheckBox *wireframe = new QCheckBox(tr("Render as wireframe"));
326

327
    controls->layout()->addWidget(wireframe);
328

329
    QCheckBox *normals = new QCheckBox(tr("Display normals vectors"));
330
    controls->layout()->addWidget(normals);
331

332
    QPushButton *colorButton = new QPushButton(tr("Choose model color"));
333
    controls->layout()->addWidget(colorButton);
334

335
    QWidget *instructions = createDialog(tr("Instructions"));
336
    instructions->layout()->addWidget(new QLabel(tr("Use mouse wheel to zoom model, and click and drag to rotate model")));
337
    instructions->layout()->addWidget(new QLabel(tr("Move the sun around to change the light position")));
338

339
    QGraphicsProxyWidget* g1 = addWidget(instructions);
340
    g1->setWindowFlags(Qt::Window | Qt::CustomizeWindowHint | Qt::WindowTitleHint);
341
    QGraphicsProxyWidget* g2 = addWidget(controls);
342
    g2->setWindowFlags(Qt::Window | Qt::CustomizeWindowHint | Qt::WindowTitleHint);
343
    controls->setAttribute(Qt::WA_TranslucentBackground);
344

345
    QPointF pos(10, 10);
346
    Q_FOREACH (QGraphicsItem *item, items()) {
347
        item->setFlag(QGraphicsItem::ItemIsMovable);
348
        item->setCacheMode(QGraphicsItem::DeviceCoordinateCache);
349

350
        const QRectF rect = item->boundingRect();
351
        item->setPos(pos.x() - rect.x(), pos.y() - rect.y());
352
        pos += QPointF(0, 10 + rect.height());
353
    }
354

355
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
356
    m_time.start();
357
#endif
358
    sorendermanager = new SoRenderManager;
359

360
    sorendermanager->setAutoClipping(SoRenderManager::VARIABLE_NEAR_PLANE);
361

362
    sorendermanager->setBackgroundColor(SbColor4f(0.0f, 0.0f, 0.0f, 0.0f));
363
    sorendermanager->activate();
364

365
    soeventmanager = new SoEventManager;
366
    soeventmanager->setNavigationState(SoEventManager::MIXED_NAVIGATION);
367

368
    eventfilter = new SceneEventFilter(this);
369

370
    connect(this, SIGNAL(sceneRectChanged(const QRectF&)),
371
            this, SLOT(onSceneRectChanged(const QRectF&)));
372
}
373

374
GraphicsScene::~GraphicsScene()
375
{
376
    headlight->unref();
377
    sceneNode->unref();
378
    delete sorendermanager;
379
    delete soeventmanager;
380
    delete eventfilter;
381
}
382

383
void GraphicsScene::viewAll()
384
{
385
    SoCamera* cam = sorendermanager->getCamera();
386
    if (cam)
387
        cam->viewAll(sceneNode, sorendermanager->getViewportRegion());
388
}
389

390
SceneEventFilter *
391
GraphicsScene::getEventFilter(void) const
392
{
393
    return eventfilter;
394
}
395

396
bool
397
GraphicsScene::processSoEvent(const SoEvent * event)
398
{
399
    if (event) {
400
        return soeventmanager && soeventmanager->processEvent(event);
401
    }
402

403
    return false;
404
}
405

406
void
407
GraphicsScene::addStateMachine(SoScXMLStateMachine * statemachine)
408
{
409
    SoEventManager * em = this->getSoEventManager();
410
    em->addSoScXMLStateMachine(statemachine);
411
    statemachine->setSceneGraphRoot(this->getSoRenderManager()->getSceneGraph());
412
    statemachine->setActiveCamera(this->getSoRenderManager()->getCamera());
413
}
414

415
void
416
GraphicsScene::removeStateMachine(SoScXMLStateMachine * statemachine)
417
{
418
    SoEventManager * em = this->getSoEventManager();
419
    statemachine->setSceneGraphRoot(NULL);
420
    statemachine->setActiveCamera(NULL);
421
    em->removeSoScXMLStateMachine(statemachine);
422
}
423

424
void
425
GraphicsScene::setNavigationModeFile(const QUrl & url)
426
{
427
    QString filename;
428

429
    if (url.scheme()== QLatin1String("coin")) {
430
        filename = url.path();
431
        //FIXME: This conditional needs to be implemented when the
432
        //CoinResources systems if working
433
        //Workaround for differences between url scheme, and Coin internal
434
        //scheme in Coin 3.0.
435
        if (filename[0] == QLatin1Char('/')) {
436
            filename.remove(0,1);
437
        }
438
        filename = url.scheme() + QLatin1Char(':') + filename;
439
    }
440
    else if (url.scheme() == QLatin1String("file"))
441
        filename = url.toLocalFile();
442
    else if (url.isEmpty()) {
443

444
        return;
445
    }
446
    else {
447
        return;
448
    }
449

450
    QByteArray filenametmp = filename.toLocal8Bit();
451
    ScXMLStateMachine * stateMachine = NULL;
452

453
    if (filenametmp.startsWith("coin:")){
454
        stateMachine = ScXML::readFile(filenametmp.data());
455
    }
456
    else {
457
        //Use Qt to read the file in case it is a Qt resource
458
        QFile file(QString::fromLatin1(filenametmp));
459
        if (file.open(QIODevice::ReadOnly)) {
460
            QByteArray fileContents = file.readAll();
461
#if COIN_MAJOR_VERSION >= 4
462
            stateMachine = ScXML::readBuffer(SbByteBuffer(fileContents.size(), fileContents.constData()));
463
#else
464
            stateMachine = ScXML::readBuffer(fileContents.constData());
465
#endif
466
            file.close();
467
        }
468
    }
469

470
    if (stateMachine && stateMachine->isOfType(SoScXMLStateMachine::getClassTypeId())) {
471
        SoScXMLStateMachine * newsm = static_cast<SoScXMLStateMachine *>(stateMachine);
472

473
        this->addStateMachine(newsm);
474
        newsm->initialize();
475
    }
476
    else {
477
        if (stateMachine)
478
            delete stateMachine;
479

480
        return;
481
    }
482
}
483

484
SoNode* GraphicsScene::getSceneGraph() const
485
{
486
    return sceneNode;
487
}
488

489
SoCamera *
490
GraphicsScene::searchForCamera(SoNode * root)
491
{
492
    SoSearchAction sa;
493
    sa.setInterest(SoSearchAction::FIRST);
494
    sa.setType(SoCamera::getClassTypeId());
495
    sa.apply(root);
496

497
    if (sa.getPath()) {
498
        SoNode * node = sa.getPath()->getTail();
499
        if (node && node->isOfType(SoCamera::getClassTypeId())) {
500
            return (SoCamera *) node;
501
        }
502
    }
503
    return NULL;
504
}
505

506
void GraphicsScene::setSceneGraph(SoNode * node)
507
{
508
    if (node == sceneNode) {
509
        return;
510
    }
511

512
    if (sceneNode) {
513
        sceneNode->unref();
514
        sceneNode = NULL;
515
    }
516

517
    SoCamera * camera = NULL;
518
    SoSeparator * superscene = NULL;
519
    bool viewall = false;
520

521
    if (node) {
522
        sceneNode = node;
523
        sceneNode->ref();
524

525
        superscene = new SoSeparator;
526
        superscene->addChild(headlight);
527

528
        // if the scene does not contain a camera, add one
529
        if (!(camera = searchForCamera(node))) {
530
            camera = new SoOrthographicCamera;
531
            superscene->addChild(camera);
532
            viewall = true;
533
        }
534

535
        superscene->addChild(node);
536
    }
537

538
    soeventmanager->setCamera(camera);
539
    sorendermanager->setCamera(camera);
540
    soeventmanager->setSceneGraph(superscene);
541
    sorendermanager->setSceneGraph(superscene);
542

543
    if (viewall) {
544
        this->viewAll();
545
    }
546
    if (superscene) {
547
        superscene->touch();
548
    }
549
}
550

551
SoRenderManager *
552
GraphicsScene::getSoRenderManager(void) const
553
{
554
    return sorendermanager;
555
}
556

557
SoEventManager *
558
GraphicsScene::getSoEventManager(void) const
559
{
560
    return soeventmanager;
561
}
562

563
void GraphicsScene::onSceneRectChanged(const QRectF & rect)
564
{
565
    SbViewportRegion vp(rect.width(), rect.height());
566
    sorendermanager->setViewportRegion(vp);
567
    soeventmanager->setViewportRegion(vp);
568
}
569

570
void GraphicsScene::drawBackground(QPainter *painter, const QRectF &)
571
{
572
    if (painter->paintEngine()->type() != QPaintEngine::OpenGL && painter->paintEngine()->type() != QPaintEngine::OpenGL2) {
573
        qWarning("GraphicsScene: drawBackground needs a QGLWidget to be set as viewport on the graphics view");
574
        return;
575
    }
576

577
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
578
    const int delta = m_time.elapsed() - m_lastTime;
579
    m_lastTime += delta;
580
#endif
581

582
    sorendermanager->render(true/*PRIVATE(this)->clearwindow*/,
583
                            false/*PRIVATE(this)->clearzbuffer*/);
584

585
    painter->save();
586
    painter->fillRect(40,40,40,60,Qt::lightGray);
587
    painter->drawText(50,50, QString::fromLatin1("Done with QPainter"));
588
    painter->restore();
589

590
    QTimer::singleShot(20, this, SLOT(update()));
591
}
592

593
void GraphicsScene::setBackgroundColor(const QColor& color)
594
{
595
    if (color.isValid()) {
596
        m_backgroundColor = color;
597
        update();
598

599
        SbColor4f bgcolor(SbClamp(color.red()   / 255.0, 0.0, 1.0),
600
                          SbClamp(color.green() / 255.0, 0.0, 1.0),
601
                          SbClamp(color.blue()  / 255.0, 0.0, 1.0),
602
                          SbClamp(color.alpha() / 255.0, 0.0, 1.0));
603
        sorendermanager->setBackgroundColor(bgcolor);
604
        sorendermanager->scheduleRedraw();
605
    }
606
}
607

608
void GraphicsScene::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
609
{
610
    QGraphicsScene::mouseMoveEvent(event);
611
    if (event->isAccepted())
612
        return;
613
    if (event->buttons() & Qt::LeftButton) {
614
        event->accept();
615
        update();
616
    }
617
}
618

619
void GraphicsScene::mousePressEvent(QGraphicsSceneMouseEvent *event)
620
{
621
    QGraphicsScene::mousePressEvent(event);
622
    if (event->isAccepted())
623
        return;
624

625
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
626
    m_mouseEventTime = m_time.elapsed();
627
#endif
628
    event->accept();
629
}
630

631
void GraphicsScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
632
{
633
    QGraphicsScene::mouseReleaseEvent(event);
634
    if (event->isAccepted())
635
        return;
636

637
    event->accept();
638
    update();
639
}
640

641
void GraphicsScene::wheelEvent(QGraphicsSceneWheelEvent *event)
642
{
643
    QGraphicsScene::wheelEvent(event);
644
    if (event->isAccepted())
645
        return;
646
    event->accept();
647
    update();
648
}
649

650
// ----------------------------------------------------------------------------
651

652
GraphicsView3D::GraphicsView3D(Gui::Document* doc, QWidget* parent)
653
  : Gui::MDIView(doc, parent), m_scene(new GraphicsScene()), m_view(new GraphicsView)
654
{
655
    m_view->installEventFilter(m_scene->getEventFilter());
656
    m_view->setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
657
    m_view->setScene(m_scene);
658
    m_scene->setNavigationModeFile(QUrl(QString::fromLatin1("coin:///scxml/navigation/examiner.xml")));
659

660
    std::vector<ViewProvider*> v = doc->getViewProvidersOfType(ViewProvider::getClassTypeId());
661
    SoSeparator* root = new SoSeparator();
662
    for (std::vector<ViewProvider*>::iterator it = v.begin(); it != v.end(); ++it)
663
        root->addChild((*it)->getRoot());
664
    m_scene->setSceneGraph(root);
665
    setCentralWidget(m_view);
666
    m_scene->viewAll();
667

668
    // attach parameter Observer
669
    hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/View");
670
    hGrp->Attach(this);
671

672
    OnChange(*hGrp,"BackgroundColor");
673
}
674

675
GraphicsView3D::~GraphicsView3D()
676
{
677
    hGrp->Detach(this);
678
    delete m_view;
679
    delete m_scene;
680
}
681

682
void GraphicsView3D::OnChange(ParameterGrp::SubjectType &rCaller,ParameterGrp::MessageType Reason)
683
{
684
    const ParameterGrp& rGrp = static_cast<ParameterGrp&>(rCaller);
685

686
    if (strcmp(Reason, "BackgroundColor") == 0)
687
    {
688
        unsigned long col1 = rGrp.GetUnsigned("BackgroundColor",3940932863UL);
689

690
        float r1,g1,b1;
691

692
        r1 = ((col1 >> 24) & 0xff) / 255.0; g1 = ((col1 >> 16) & 0xff) / 255.0; b1 = ((col1 >> 8) & 0xff) / 255.0;
693
        m_scene->setBackgroundColor(QColor::fromRgbF(r1, g1, b1));
694
    }
695
}
696
#include "moc_GLGraphicsView.cpp"
697

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.