23
#include "PreCompiled.h"
27
# include <Inventor/nodes/SoDirectionalLight.h>
28
# include <Inventor/nodes/SoOrthographicCamera.h>
29
# include <Inventor/nodes/SoPerspectiveCamera.h>
32
#include <Base/Builder3D.h>
33
#include <Base/Interpreter.h>
35
#include "SplitView3DInventor.h"
36
#include "Application.h"
39
#include "NavigationStyle.h"
40
#include "SoFCSelectionAction.h"
41
#include "View3DInventorViewer.h"
43
#include "View3DSettings.h"
48
TYPESYSTEM_SOURCE_ABSTRACT(Gui::AbstractSplitView,Gui::MDIView)
50
AbstractSplitView::AbstractSplitView(Gui::Document* pcDocument, QWidget* parent, Qt::WindowFlags wflags)
51
: MDIView(pcDocument,parent, wflags)
55
setMouseTracking(true);
58
AbstractSplitView::~AbstractSplitView()
60
for (std::vector<View3DInventorViewer*>::iterator it = _viewer.begin(); it != _viewer.end(); ++it) {
64
Base::PyGILStateLocker lock;
69
void AbstractSplitView::deleteSelf()
71
for (std::vector<View3DInventorViewer*>::iterator it = _viewer.begin(); it != _viewer.end(); ++it) {
72
(*it)->setSceneGraph(nullptr);
74
MDIView::deleteSelf();
77
void AbstractSplitView::setDocumentOfViewers(Gui::Document* document)
79
for (auto view : _viewer) {
80
view->setDocument(document);
84
void AbstractSplitView::viewAll()
86
for (std::vector<View3DInventorViewer*>::iterator it = _viewer.begin(); it != _viewer.end(); ++it)
90
bool AbstractSplitView::containsViewProvider(const ViewProvider* vp) const
92
for (auto it = _viewer.begin(); it != _viewer.end(); ++it) {
93
if ((*it)->containsViewProvider(vp))
100
void AbstractSplitView::setupSettings()
102
viewSettings = std::make_unique<View3DSettings>(App::GetApplication().GetParameterGroupByPath
103
("User parameter:BaseApp/Preferences/View"), _viewer);
106
viewSettings->ignoreNavigationStyle = true;
108
viewSettings->ignoreVBO = true;
109
viewSettings->ignoreTransparent = true;
110
viewSettings->ignoreRenderCache = true;
111
viewSettings->ignoreDimensions = true;
112
viewSettings->applySettings();
114
for (auto view : _viewer) {
115
NaviCubeSettings naviSettings(App::GetApplication().GetParameterGroupByPath
116
("User parameter:BaseApp/Preferences/NaviCube"), view);
117
naviSettings.applySettings();
121
View3DInventorViewer* AbstractSplitView::getViewer(unsigned int n) const
123
return (_viewer.size() > n ? _viewer[n] : nullptr);
126
void AbstractSplitView::onUpdate()
131
const char *AbstractSplitView::getName() const
133
return "SplitView3DInventor";
136
bool AbstractSplitView::onMsg(const char* pMsg, const char**)
138
if (strcmp("ViewFit",pMsg) == 0 ) {
142
else if (strcmp("ViewBottom",pMsg) == 0) {
143
SbRotation rot(Camera::rotation(Camera::Bottom));
144
for (std::vector<View3DInventorViewer*>::iterator it = _viewer.begin(); it != _viewer.end(); ++it) {
145
SoCamera* cam = (*it)->getSoRenderManager()->getCamera();
146
cam->orientation.setValue(rot);
151
else if (strcmp("ViewFront",pMsg) == 0) {
152
SbRotation rot(Camera::rotation(Camera::Front));
153
for (std::vector<View3DInventorViewer*>::iterator it = _viewer.begin(); it != _viewer.end(); ++it) {
154
SoCamera* cam = (*it)->getSoRenderManager()->getCamera();
155
cam->orientation.setValue(rot);
160
else if (strcmp("ViewLeft",pMsg) == 0) {
161
SbRotation rot(Camera::rotation(Camera::Left));
162
for (std::vector<View3DInventorViewer*>::iterator it = _viewer.begin(); it != _viewer.end(); ++it) {
163
SoCamera* cam = (*it)->getSoRenderManager()->getCamera();
164
cam->orientation.setValue(rot);
169
else if (strcmp("ViewRear",pMsg) == 0) {
170
SbRotation rot(Camera::rotation(Camera::Rear));
171
for (std::vector<View3DInventorViewer*>::iterator it = _viewer.begin(); it != _viewer.end(); ++it) {
172
SoCamera* cam = (*it)->getSoRenderManager()->getCamera();
173
cam->orientation.setValue(rot);
178
else if (strcmp("ViewRight",pMsg) == 0) {
179
SbRotation rot(Camera::rotation(Camera::Right));
180
for (std::vector<View3DInventorViewer*>::iterator it = _viewer.begin(); it != _viewer.end(); ++it) {
181
SoCamera* cam = (*it)->getSoRenderManager()->getCamera();
182
cam->orientation.setValue(rot);
187
else if (strcmp("ViewTop",pMsg) == 0) {
188
SbRotation rot(Camera::rotation(Camera::Top));
189
for (std::vector<View3DInventorViewer*>::iterator it = _viewer.begin(); it != _viewer.end(); ++it) {
190
SoCamera* cam = (*it)->getSoRenderManager()->getCamera();
191
cam->orientation.setValue(rot);
196
else if (strcmp("ViewAxo",pMsg) == 0) {
197
SbRotation rot(Camera::rotation(Camera::Isometric));
198
for (std::vector<View3DInventorViewer*>::iterator it = _viewer.begin(); it != _viewer.end(); ++it) {
199
SoCamera* cam = (*it)->getSoRenderManager()->getCamera();
200
cam->orientation.setValue(rot);
209
bool AbstractSplitView::onHasMsg(const char* pMsg) const
211
if (strcmp("CanPan",pMsg) == 0) {
214
else if (strcmp("ViewFit",pMsg) == 0) {
217
else if (strcmp("ViewBottom",pMsg) == 0) {
220
else if (strcmp("ViewFront",pMsg) == 0) {
223
else if (strcmp("ViewLeft",pMsg) == 0) {
226
else if (strcmp("ViewRear",pMsg) == 0) {
229
else if (strcmp("ViewRight",pMsg) == 0) {
232
else if (strcmp("ViewTop",pMsg) == 0) {
235
else if (strcmp("ViewAxo",pMsg) == 0) {
241
void AbstractSplitView::setOverrideCursor(const QCursor& aCursor)
247
PyObject *AbstractSplitView::getPyObject()
250
_viewerPy = new AbstractSplitViewPy(this);
251
Py_INCREF(_viewerPy);
255
void AbstractSplitView::setPyObject(PyObject *)
257
throw Base::AttributeError("Attribute is read-only");
260
int AbstractSplitView::getSize()
262
return static_cast<int>(_viewer.size());
267
void AbstractSplitViewPy::init_type()
269
behaviors().name("AbstractSplitViewPy");
270
behaviors().doc("Python binding class for the Inventor viewer class");
272
behaviors().supportRepr();
273
behaviors().supportGetattr();
274
behaviors().supportSetattr();
275
behaviors().supportSequenceType();
277
add_varargs_method("fitAll",&AbstractSplitViewPy::fitAll,"fitAll()");
278
add_varargs_method("viewBottom",&AbstractSplitViewPy::viewBottom,"viewBottom()");
279
add_varargs_method("viewFront",&AbstractSplitViewPy::viewFront,"viewFront()");
280
add_varargs_method("viewLeft",&AbstractSplitViewPy::viewLeft,"viewLeft()");
281
add_varargs_method("viewRear",&AbstractSplitViewPy::viewRear,"viewRear()");
282
add_varargs_method("viewRight",&AbstractSplitViewPy::viewRight,"viewRight()");
283
add_varargs_method("viewTop",&AbstractSplitViewPy::viewTop,"viewTop()");
284
add_varargs_method("viewAxometric",&AbstractSplitViewPy::viewIsometric,"viewAxometric()");
285
add_varargs_method("viewIsometric",&AbstractSplitViewPy::viewIsometric,"viewIsometric()");
286
add_varargs_method("getViewer",&AbstractSplitViewPy::getViewer,"getViewer(index)");
287
add_varargs_method("close",&AbstractSplitViewPy::close,"close()");
288
add_varargs_method("cast_to_base", &AbstractSplitViewPy::cast_to_base, "cast_to_base() cast to MDIView class");
289
behaviors().readyType();
292
AbstractSplitViewPy::AbstractSplitViewPy(AbstractSplitView *vi)
297
AbstractSplitViewPy::~AbstractSplitViewPy() = default;
299
Py::Object AbstractSplitViewPy::cast_to_base(const Py::Tuple&)
301
return Gui::MDIViewPy::create(base.getMDIViewPtr());
304
Py::Object AbstractSplitViewPy::repr()
306
std::ostringstream s_out;
307
if (!getSplitViewPtr())
308
throw Py::RuntimeError("Cannot print representation of deleted object");
309
s_out << "AbstractSplitView";
310
return Py::String(s_out.str());
317
Py::Object AbstractSplitViewPy::getattr(const char * attr)
320
std::string name( attr );
321
if (name == "__dict__" || name == "__class__") {
322
Py::Dict dict_self(BaseType::getattr("__dict__"));
323
Py::Dict dict_base(base.getattr("__dict__"));
324
for (const auto& it : dict_base) {
325
dict_self.setItem(it.first, it.second);
331
return BaseType::getattr(attr);
333
catch (Py::AttributeError& e) {
335
return base.getattr(attr);
339
AbstractSplitView* AbstractSplitViewPy::getSplitViewPtr()
341
auto view = qobject_cast<AbstractSplitView*>(base.getMDIViewPtr());
342
if (!(view && view->getViewer(0)))
343
throw Py::RuntimeError("Object already deleted");
347
Py::Object AbstractSplitViewPy::fitAll(const Py::Tuple& args)
349
if (!PyArg_ParseTuple(args.ptr(), ""))
350
throw Py::Exception();
353
getSplitViewPtr()->onMsg("ViewFit", nullptr);
355
catch (const Base::Exception& e) {
356
throw Py::RuntimeError(e.what());
358
catch (const std::exception& e) {
359
throw Py::RuntimeError(e.what());
362
throw Py::RuntimeError("Unknown C++ exception");
367
Py::Object AbstractSplitViewPy::viewBottom(const Py::Tuple& args)
369
if (!PyArg_ParseTuple(args.ptr(), ""))
370
throw Py::Exception();
373
getSplitViewPtr()->onMsg("ViewBottom", nullptr);
375
catch (const Base::Exception& e) {
376
throw Py::RuntimeError(e.what());
378
catch (const std::exception& e) {
379
throw Py::RuntimeError(e.what());
382
throw Py::RuntimeError("Unknown C++ exception");
388
Py::Object AbstractSplitViewPy::viewFront(const Py::Tuple& args)
390
if (!PyArg_ParseTuple(args.ptr(), ""))
391
throw Py::Exception();
394
getSplitViewPtr()->onMsg("ViewFront", nullptr);
396
catch (const Base::Exception& e) {
397
throw Py::RuntimeError(e.what());
399
catch (const std::exception& e) {
400
throw Py::RuntimeError(e.what());
403
throw Py::RuntimeError("Unknown C++ exception");
409
Py::Object AbstractSplitViewPy::viewLeft(const Py::Tuple& args)
411
if (!PyArg_ParseTuple(args.ptr(), ""))
412
throw Py::Exception();
415
getSplitViewPtr()->onMsg("ViewLeft", nullptr);
417
catch (const Base::Exception& e) {
418
throw Py::RuntimeError(e.what());
420
catch (const std::exception& e) {
421
throw Py::RuntimeError(e.what());
424
throw Py::RuntimeError("Unknown C++ exception");
430
Py::Object AbstractSplitViewPy::viewRear(const Py::Tuple& args)
432
if (!PyArg_ParseTuple(args.ptr(), ""))
433
throw Py::Exception();
436
getSplitViewPtr()->onMsg("ViewRear", nullptr);
438
catch (const Base::Exception& e) {
439
throw Py::RuntimeError(e.what());
441
catch (const std::exception& e) {
442
throw Py::RuntimeError(e.what());
445
throw Py::RuntimeError("Unknown C++ exception");
451
Py::Object AbstractSplitViewPy::viewRight(const Py::Tuple& args)
453
if (!PyArg_ParseTuple(args.ptr(), ""))
454
throw Py::Exception();
457
getSplitViewPtr()->onMsg("ViewRight", nullptr);
459
catch (const Base::Exception& e) {
460
throw Py::RuntimeError(e.what());
462
catch (const std::exception& e) {
463
throw Py::RuntimeError(e.what());
466
throw Py::RuntimeError("Unknown C++ exception");
472
Py::Object AbstractSplitViewPy::viewTop(const Py::Tuple& args)
474
if (!PyArg_ParseTuple(args.ptr(), ""))
475
throw Py::Exception();
478
getSplitViewPtr()->onMsg("ViewTop", nullptr);
480
catch (const Base::Exception& e) {
481
throw Py::RuntimeError(e.what());
483
catch (const std::exception& e) {
484
throw Py::RuntimeError(e.what());
487
throw Py::RuntimeError("Unknown C++ exception");
493
Py::Object AbstractSplitViewPy::viewIsometric(const Py::Tuple& args)
495
if (!PyArg_ParseTuple(args.ptr(), ""))
496
throw Py::Exception();
499
getSplitViewPtr()->onMsg("ViewAxo", nullptr);
501
catch (const Base::Exception& e) {
502
throw Py::RuntimeError(e.what());
504
catch (const std::exception& e) {
505
throw Py::RuntimeError(e.what());
508
throw Py::RuntimeError("Unknown C++ exception");
514
Py::Object AbstractSplitViewPy::getViewer(const Py::Tuple& args)
517
if (!PyArg_ParseTuple(args.ptr(), "i", &viewIndex))
518
throw Py::Exception();
521
Gui::View3DInventorViewer* view = getSplitViewPtr()->getViewer(viewIndex);
523
throw Py::IndexError("Index out of range");
524
return Py::asObject(view->getPyObject());
526
catch (const Base::Exception& e) {
527
throw Py::RuntimeError(e.what());
529
catch (const std::exception& e) {
530
throw Py::RuntimeError(e.what());
532
catch (const Py::Exception&) {
537
throw Py::RuntimeError("Unknown C++ exception");
541
Py::Object AbstractSplitViewPy::sequence_item(Py_ssize_t viewIndex)
543
AbstractSplitView* view = getSplitViewPtr();
544
if (viewIndex >= view->getSize() || viewIndex < 0)
545
throw Py::IndexError("Index out of range");
546
PyObject* viewer = view->getViewer(viewIndex)->getPyObject();
547
return Py::asObject(viewer);
550
PyCxx_ssize_t AbstractSplitViewPy::sequence_length()
552
AbstractSplitView* view = getSplitViewPtr();
553
return view->getSize();
556
Py::Object AbstractSplitViewPy::close(const Py::Tuple& args)
558
if (!PyArg_ParseTuple(args.ptr(), ""))
559
throw Py::Exception();
561
AbstractSplitView* view = getSplitViewPtr();
563
if (view->parentWidget())
564
view->parentWidget()->deleteLater();
571
TYPESYSTEM_SOURCE_ABSTRACT(Gui::SplitView3DInventor, Gui::AbstractSplitView)
573
SplitView3DInventor::SplitView3DInventor(int views, Gui::Document* pcDocument, QWidget* parent, Qt::WindowFlags wflags)
574
: AbstractSplitView(pcDocument,parent, wflags)
577
bool smoothing = false;
578
bool glformat = false;
579
int samples = View3DInventorViewer::getNumSamples();
584
f.setSamples(samples);
586
else if (samples > 0) {
594
QSplitter* mainSplitter = nullptr;
598
mainSplitter = new QSplitter(Qt::Horizontal, this);
599
for (int i=0; i < views; i++) {
601
_viewer.push_back(new View3DInventorViewer(f, mainSplitter));
603
_viewer.push_back(new View3DInventorViewer(mainSplitter));
607
mainSplitter = new QSplitter(Qt::Vertical, this);
608
auto topSplitter = new QSplitter(Qt::Horizontal, mainSplitter);
609
auto botSplitter = new QSplitter(Qt::Horizontal, mainSplitter);
612
_viewer.push_back(new View3DInventorViewer(f, topSplitter));
613
_viewer.push_back(new View3DInventorViewer(f, topSplitter));
616
_viewer.push_back(new View3DInventorViewer(topSplitter));
617
_viewer.push_back(new View3DInventorViewer(topSplitter));
620
for (int i=2;i<views;i++) {
622
_viewer.push_back(new View3DInventorViewer(f, botSplitter));
624
_viewer.push_back(new View3DInventorViewer(botSplitter));
627
topSplitter->setOpaqueResize(true);
628
botSplitter->setOpaqueResize(true);
632
for (std::vector<int>::size_type i = 0; i != _viewer.size(); i++)
633
_viewer[i]->getSoRenderManager()->getGLRenderAction()->setSmoothing(true);
636
mainSplitter->show();
637
setCentralWidget(mainSplitter);
639
setDocumentOfViewers(pcDocument);
645
SplitView3DInventor::~SplitView3DInventor() = default;
647
#include "moc_SplitView3DInventor.cpp"