1
/**************************************************************************\
3
* This file is part of the Coin 3D visualization library.
4
* Copyright (C) 1998-2005 by Systems in Motion. All rights reserved.
6
* This library is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* ("GPL") version 2 as published by the Free Software Foundation.
9
* See the file LICENSE.GPL at the root directory of this source
10
* distribution for additional information about the GNU GPL.
12
* For using Coin with software that can not be combined with the GNU
13
* GPL, and for taking advantage of the additional benefits of our
14
* support services, please contact Systems in Motion about acquiring
15
* a Coin Professional Edition License.
17
* See <URL:http://www.coin3d.org/> for more information.
19
* Systems in Motion, Postboks 1283, Pirsenteret, 7462 Trondheim, NORWAY.
20
* <URL:http://www.sim.no/>.
22
\**************************************************************************/
24
#include <Inventor/errors/SoDebugError.h>
25
#include <Inventor/nodes/SoSeparator.h>
26
#include <Inventor/nodes/SoTexture2.h>
27
#include <Inventor/nodes/SoCoordinate3.h>
28
#include <Inventor/sensors/SoFieldSensor.h>
30
#include <Inventor/Qt/SoAny.h>
31
#include <Inventor/Qt/nodes/SoGuiImage.h>
34
// *************************************************************************
42
SoFieldSensor * size_sensor;
43
static void size_updated_cb(void * closure, SoSensor * sensor);
45
SoCoordinate3 * coords;
47
static const char * geometryscene[];
50
// *************************************************************************
52
#define PRIVATE(obj) ((Image *)obj->internals)
55
SoGuiImage::initClass(void)
57
SO_KIT_INIT_CLASS(SoGuiImage, SoBaseKit, "BaseKit");
60
SO_KIT_SOURCE(SoGuiImage);
62
SoGuiImage::SoGuiImage(void)
64
this->internals = new Image;
65
PRIVATE(this)->api = this;
67
SO_KIT_CONSTRUCTOR(SoGuiImage);
68
SO_KIT_ADD_FIELD(size, (SbVec3f(1.0f, 1.0f, 0.0f)));
70
SO_KIT_ADD_CATALOG_ENTRY(geometry, SoGroup, FALSE, topSeparator, "", FALSE);
71
SO_KIT_ADD_CATALOG_ENTRY(texture, SoTexture2, FALSE, topSeparator, geometry, TRUE);
72
SO_KIT_ADD_CATALOG_ENTRY(topSeparator, SoSeparator, FALSE, this, "", FALSE);
74
SO_KIT_INIT_INSTANCE();
76
SoNode * geometryroot = SoAny::loadSceneGraph(Image::geometryscene);
79
geometryroot->isOfType(SoSeparator::getClassTypeId());
80
SoNode * realgeometry = ((SoSeparator *) geometryroot)->getChild(0);
84
PRIVATE(this)->coords = (SoCoordinate3 *) SoAny::scanSceneForName(realgeometry, "coords");
85
assert(PRIVATE(this)->coords);
86
assert(PRIVATE(this)->coords->isOfType(SoCoordinate3::getClassTypeId()));
88
realgeometry->unrefNoDelete();
89
SbBool ok = this->setAnyPart("geometry", realgeometry);
91
geometryroot->unref();
93
PRIVATE(this)->size_sensor = new SoFieldSensor(Image::size_updated_cb, PRIVATE(this));
94
PRIVATE(this)->size_sensor->attach(&(this->size));
97
SoGuiImage::~SoGuiImage(void)
99
delete PRIVATE(this)->size_sensor;
100
Image * obj = PRIVATE(this);
106
// *************************************************************************
108
#define PUBLIC(obj) (obj->api)
111
Image::geometryscene[] =
113
"#Inventor V2.1 ascii",
116
" DEF coords Coordinate3 {",
117
" point [ 0 0 0, 1 0 0, 1 1 0, 0 1 0 ]",
119
" TextureCoordinate2 {",
120
" point [ 0 0, 1 0, 1 1, 0 1 ]",
123
" coordIndex [ 0 1 2 -1 0 2 3 -1 ]",
124
" textureCoordIndex [ 0 1 2 -1 0 2 3 -1 ]",
133
this->size_sensor = NULL;
138
Image::size_updated_cb(void * closure, SoSensor * sensor)
141
Image * me = (Image *) closure;
142
SbVec3f size = PUBLIC(me)->size.getValue();
143
SbBool save = me->coords->point.enableNotify(FALSE);
144
me->coords->point.set1Value(1, SbVec3f(size[0], 0.0f, 0.0f));
145
me->coords->point.set1Value(2, SbVec3f(size[0], size[1], 0.0f));
146
me->coords->point.set1Value(3, SbVec3f(0.0f, size[1], 0.0f));
147
me->coords->point.enableNotify(save);
148
if ( save ) me->coords->point.touch();
153
// *************************************************************************