| 1 |
/**************************************************************************\ |
| 2 |
* Copyright (c) Kongsberg Oil & Gas Technologies AS |
| 3 |
* All rights reserved. |
| 4 |
* |
| 5 |
* Redistribution and use in source and binary forms, with or without |
| 6 |
* modification, are permitted provided that the following conditions are |
| 7 |
* met: |
| 8 |
* |
| 9 |
* Redistributions of source code must retain the above copyright notice, |
| 10 |
* this list of conditions and the following disclaimer. |
| 11 |
* |
| 12 |
* Redistributions in binary form must reproduce the above copyright |
| 13 |
* notice, this list of conditions and the following disclaimer in the |
| 14 |
* documentation and/or other materials provided with the distribution. |
| 15 |
* |
| 16 |
* Neither the name of the copyright holder nor the names of its |
| 17 |
* contributors may be used to endorse or promote products derived from |
| 18 |
* this software without specific prior written permission. |
| 19 |
* |
| 20 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 21 |
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 22 |
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 23 |
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 24 |
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 25 |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 26 |
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 27 |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 28 |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 29 |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 30 |
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 31 |
\**************************************************************************/ |
| 32 |
|
| 33 |
/* |
| 34 |
|
| 35 |
Quarter is a light-weight glue library that provides seamless |
| 36 |
integration between Systems in Motions's \COIN high-level 3D |
| 37 |
visualization library and Trolltech's \QT 2D user interface |
| 38 |
library. |
| 39 |
|
| 40 |
\QT and \COIN is a perfect match since they are both open source, |
| 41 |
widely portable and easy to use. Quarter has evolved from Systems in |
| 42 |
Motion's own experiences using \COIN and \QT together in our |
| 43 |
applications. |
| 44 |
|
| 45 |
The functionality in Quarter revolves around QuarterWidget, a |
| 46 |
subclass of QGLWidget. This widget provides functionality for |
| 47 |
rendering of Coin scenegraphs and translation of QEvents into |
| 48 |
SoEvents. Using this widget is as easy as using any other QWidget. |
| 49 |
|
| 50 |
\subpage QuarterWidgetPlugin |
| 51 |
|
| 52 |
Quarter also comes with a plugin for Qt Designer, Trolltech's tool |
| 53 |
for designing and building GUIs. Once you install Quarter, the |
| 54 |
QuarterWidget becomes accessible in Qt Designer, and you can include |
| 55 |
it in the user interfaces you create. The plugin facility also |
| 56 |
provides you with the capability of dynamically loading ui files |
| 57 |
containing a QuarterWidget in your application. |
| 58 |
|
| 59 |
By using \COIN, \QT and Quarter to build your 3D graphics |
| 60 |
applications, you have the power to write software that is portable |
| 61 |
across the whole range of UNIX, Linux, Microsoft Windows and Mac OS |
| 62 |
X operating systems, from a 100% common codebase. |
| 63 |
|
| 64 |
For a small, completely stand-alone usage example on how to |
| 65 |
initialize the library and set up a viewer instance window, see the |
| 66 |
following code: |
| 67 |
|
| 68 |
\code |
| 69 |
#include <QtGui/QApplication> |
| 70 |
|
| 71 |
#include <Inventor/nodes/SoBaseColor.h> |
| 72 |
#include <Inventor/nodes/SoCone.h> |
| 73 |
#include <Inventor/nodes/SoSeparator.h> |
| 74 |
|
| 75 |
#include <Quarter/Quarter.h> |
| 76 |
#include <Quarter/QuarterWidget.h> |
| 77 |
|
| 78 |
using namespace SIM::Coin3D::Quarter; |
| 79 |
|
| 80 |
int |
| 81 |
main(int argc, char ** argv) |
| 82 |
{ |
| 83 |
QApplication app(argc, argv); |
| 84 |
// Initializes Quarter library (and implicitly also the Coin and Qt |
| 85 |
// libraries). |
| 86 |
Quarter::init(); |
| 87 |
|
| 88 |
// Make a dead simple scene graph by using the Coin library, only |
| 89 |
// containing a single yellow cone under the scenegraph root. |
| 90 |
SoSeparator * root = new SoSeparator; |
| 91 |
root->ref(); |
| 92 |
|
| 93 |
SoBaseColor * col = new SoBaseColor; |
| 94 |
col->rgb = SbColor(1, 1, 0); |
| 95 |
root->addChild(col); |
| 96 |
|
| 97 |
root->addChild(new SoCone); |
| 98 |
|
| 99 |
// Create a QuarterWidget for displaying a Coin scene graph |
| 100 |
QuarterWidget * viewer = new QuarterWidget; |
| 101 |
viewer->setSceneGraph(root); |
| 102 |
|
| 103 |
// make the viewer react to input events similar to the good old |
| 104 |
// ExaminerViewer |
| 105 |
viewer->setNavigationModeFile(QUrl("coin:///scxml/navigation/examiner.xml")); |
| 106 |
|
| 107 |
// Pop up the QuarterWidget |
| 108 |
viewer->show(); |
| 109 |
// Loop until exit. |
| 110 |
app.exec(); |
| 111 |
// Clean up resources. |
| 112 |
root->unref(); |
| 113 |
delete viewer; |
| 114 |
|
| 115 |
Quarter::clean(); |
| 116 |
|
| 117 |
return 0; |
| 118 |
} |
| 119 |
\endcode |
| 120 |
|
| 121 |
\subpage examples |
| 122 |
*/ |
| 123 |
|
| 124 |
// The subsequent doxygen referenced page/subpages do not exist in the copy of Quarter used within FreeCad. |
| 125 |
// To preserve the history and their origin the doxygen commands have been disabled but left in the file. |
| 126 |
// /*! |
| 127 |
// \page examples More Examples |
| 128 |
// |
| 129 |
// The examples code is included in Quarter and can be found in the |
| 130 |
// src/examples subdirectory. |
| 131 |
// |
| 132 |
// \subpage directui |
| 133 |
// |
| 134 |
// \subpage dynamicui |
| 135 |
// |
| 136 |
// \subpage inheritui |
| 137 |
// |
| 138 |
// \subpage mdi |
| 139 |
// |
| 140 |
// \subpage examiner |
| 141 |
//*/ |
| 142 |
|
| 143 |
#include <Inventor/SoDB.h> |
| 144 |
#include <Inventor/SoInteraction.h> |
| 145 |
#include <Inventor/nodekits/SoNodeKit.h> |
| 146 |
|
| 147 |
#include "SensorManager.h" |
| 148 |
|
| 149 |
#include "Quarter.h" |
| 150 |
#include "QuarterP.h" |
| 151 |
|
| 152 |
|
| 153 |
using namespace SIM::Coin3D::Quarter; |
| 154 |
|
| 155 |
static QuarterP * self = nullptr; |
| 156 |
|
| 157 |
/*! |
| 158 |
initialize Quarter, and implicitly Coin |
| 159 |
*/ |
| 160 |
void |
| 161 |
Quarter::init(bool initCoin) |
| 162 |
{ |
| 163 |
COMPILE_ONLY_BEFORE(2,0,0,"Should not be encapsulated in double Quarter namespace"); |
| 164 |
if (self) { |
| 165 |
// FIXME: Use SoDebugError |
| 166 |
fprintf(stderr, "Quarter is already initialized\n"); |
| 167 |
return; |
| 168 |
} |
| 169 |
|
| 170 |
if (initCoin) { |
| 171 |
SoDB::init(); |
| 172 |
SoNodeKit::init(); |
| 173 |
SoInteraction::init(); |
| 174 |
} |
| 175 |
|
| 176 |
self = new QuarterP; |
| 177 |
self->initCoin = initCoin; |
| 178 |
|
| 179 |
} |
| 180 |
|
| 181 |
/*! |
| 182 |
clean up resources |
| 183 |
*/ |
| 184 |
void |
| 185 |
Quarter::clean() |
| 186 |
{ |
| 187 |
COMPILE_ONLY_BEFORE(2,0,0,"Should not be encapsulated in double Quarter namespace"); |
| 188 |
assert(self); |
| 189 |
bool initCoin = self->initCoin; |
| 190 |
|
| 191 |
delete self; |
| 192 |
self = nullptr; |
| 193 |
|
| 194 |
if (initCoin) { |
| 195 |
// SoDB::finish() will clean up everything that has been |
| 196 |
// initialized. There's no need to add SoNodeKit::finish() and |
| 197 |
// SoInteraction::finish() like in TGS Inventor |
| 198 |
SoDB::finish(); |
| 199 |
} |
| 200 |
} |
| 201 |
|
| 202 |
/*! |
| 203 |
override lower refresh rate limit |
| 204 |
*/ |
| 205 |
void |
| 206 |
Quarter::setTimerEpsilon(double sec) |
| 207 |
{ |
| 208 |
COMPILE_ONLY_BEFORE(2,0,0,"Should not be encapsulated in double Quarter namespace"); |
| 209 |
if (!self) { |
| 210 |
fprintf(stderr, "Quarter is not initialized!\n"); |
| 211 |
return; |
| 212 |
} |
| 213 |
|
| 214 |
self->sensormanager->setTimerEpsilon(sec); |
| 215 |
} |