~ubuntu-branches/ubuntu/oneiric/soqt/oneiric

« back to all changes in this revision

Viewing changes to build/msvc7/src/Inventor/Qt/nodes/Image.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Steve M. Robbins
  • Date: 2006-02-06 22:34:00 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20060206223400-g69m5soqa4zh0gkc
Tags: 1.3.0-3
debian/control: update libsoqt-dev depends.  Closes: #351700.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**************************************************************************\
 
2
 *
 
3
 *  This file is part of the Coin 3D visualization library.
 
4
 *  Copyright (C) 1998-2005 by Systems in Motion.  All rights reserved.
 
5
 *
 
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.
 
11
 *
 
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.
 
16
 *
 
17
 *  See <URL:http://www.coin3d.org/> for more information.
 
18
 *
 
19
 *  Systems in Motion, Postboks 1283, Pirsenteret, 7462 Trondheim, NORWAY.
 
20
 *  <URL:http://www.sim.no/>.
 
21
 *
 
22
\**************************************************************************/
 
23
 
 
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>
 
29
 
 
30
#include <Inventor/Qt/SoAny.h>
 
31
#include <Inventor/Qt/nodes/SoGuiImage.h>
 
32
#include <assert.h>
 
33
 
 
34
// *************************************************************************
 
35
 
 
36
class Image {
 
37
public:
 
38
  Image(void);
 
39
 
 
40
  SoGuiImage * api;
 
41
 
 
42
  SoFieldSensor * size_sensor;
 
43
  static void size_updated_cb(void * closure, SoSensor * sensor);
 
44
 
 
45
  SoCoordinate3 * coords;
 
46
 
 
47
  static const char * geometryscene[];
 
48
};
 
49
 
 
50
// *************************************************************************
 
51
 
 
52
#define PRIVATE(obj) ((Image *)obj->internals)
 
53
 
 
54
void
 
55
SoGuiImage::initClass(void)
 
56
{
 
57
  SO_KIT_INIT_CLASS(SoGuiImage, SoBaseKit, "BaseKit");
 
58
}
 
59
 
 
60
SO_KIT_SOURCE(SoGuiImage);
 
61
 
 
62
SoGuiImage::SoGuiImage(void)
 
63
{
 
64
  this->internals = new Image;
 
65
  PRIVATE(this)->api = this;
 
66
 
 
67
  SO_KIT_CONSTRUCTOR(SoGuiImage);
 
68
  SO_KIT_ADD_FIELD(size, (SbVec3f(1.0f, 1.0f, 0.0f)));
 
69
 
 
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);
 
73
 
 
74
  SO_KIT_INIT_INSTANCE();
 
75
 
 
76
  SoNode * geometryroot = SoAny::loadSceneGraph(Image::geometryscene);
 
77
  assert(geometryroot);
 
78
  geometryroot->ref();
 
79
  geometryroot->isOfType(SoSeparator::getClassTypeId());
 
80
  SoNode * realgeometry = ((SoSeparator *) geometryroot)->getChild(0);
 
81
  assert(realgeometry);
 
82
  realgeometry->ref();
 
83
 
 
84
  PRIVATE(this)->coords = (SoCoordinate3 *) SoAny::scanSceneForName(realgeometry, "coords");
 
85
  assert(PRIVATE(this)->coords);
 
86
  assert(PRIVATE(this)->coords->isOfType(SoCoordinate3::getClassTypeId()));
 
87
 
 
88
  realgeometry->unrefNoDelete();
 
89
  SbBool ok = this->setAnyPart("geometry", realgeometry);
 
90
  assert(ok);
 
91
  geometryroot->unref();
 
92
 
 
93
  PRIVATE(this)->size_sensor = new SoFieldSensor(Image::size_updated_cb, PRIVATE(this));
 
94
  PRIVATE(this)->size_sensor->attach(&(this->size));
 
95
}
 
96
 
 
97
SoGuiImage::~SoGuiImage(void)
 
98
{
 
99
  delete PRIVATE(this)->size_sensor;
 
100
  Image * obj = PRIVATE(this);
 
101
  delete obj;
 
102
}
 
103
 
 
104
#undef PRIVATE
 
105
 
 
106
// *************************************************************************
 
107
 
 
108
#define PUBLIC(obj) (obj->api)
 
109
 
 
110
const char *
 
111
Image::geometryscene[] =
 
112
{
 
113
  "#Inventor V2.1 ascii",
 
114
  "",
 
115
  "Group {",
 
116
  "  DEF coords Coordinate3 {",
 
117
  "    point [ 0 0 0, 1 0 0, 1 1 0, 0 1 0 ]",
 
118
  "  }",
 
119
  "  TextureCoordinate2 {",
 
120
  "    point [ 0 0, 1 0, 1 1, 0 1 ]",
 
121
  "  }",
 
122
  "  IndexedFaceSet {",
 
123
  "    coordIndex [ 0 1 2 -1 0 2 3 -1 ]",
 
124
  "    textureCoordIndex [ 0 1 2 -1 0 2 3 -1 ]",
 
125
  "  }",
 
126
  "}",
 
127
  NULL
 
128
};
 
129
 
 
130
Image::Image(void)
 
131
{
 
132
  this->api = NULL;
 
133
  this->size_sensor = NULL;
 
134
  this->coords = NULL;
 
135
}
 
136
 
 
137
void
 
138
Image::size_updated_cb(void * closure, SoSensor * sensor)
 
139
{
 
140
  assert(closure);
 
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();
 
149
}
 
150
 
 
151
#undef PUBLIC
 
152
 
 
153
// *************************************************************************