1 /*
2 * NodeContourPolyline2D.cpp
3 *
4 * Copyright (C) 1999 Stephen F. White
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program 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 General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program (see the file "COPYING" for details); if
18 * not, write to the Free Software Foundation, Inc., 675 Mass Ave,
19 * Cambridge, MA 02139, USA.
20 */
21
22 #include <stdio.h>
23 #include "stdafx.h"
24
25 #include "NodeContourPolyline2D.h"
26 #include "Proto.h"
27 #include "MFVec3f.h"
28 #include "ExposedField.h"
29 #include "Field.h"
30 #include "DuneApp.h"
31 #include "Scene.h"
32 #include "RenderState.h"
33 #include "Util.h"
34 #include "resource.h"
35
ProtoContourPolyline2D(Scene * scene)36 ProtoContourPolyline2D::ProtoContourPolyline2D(Scene *scene)
37 : Proto(scene, "ContourPolyline2D")
38 {
39 static bool init = true;
40 ExposedField* l;
41 if (init || (scene->getParsedX3dVersion() != 0))
42 l = new ExposedField(MFVEC2D, "lineSegments", new MFVec2d(), NULL,
43 NULL, ANY_NODE, 0, NULL, "controlPoint");
44 else
45 l = new ExposedField(MFVEC2F, "lineSegments", new MFVec2f(), NULL,
46 NULL, ANY_NODE, 0, NULL, "point");
47 init = false;
48 lineSegments.set(addExposedField(l));
49 }
50
51 Node *
create(Scene * scene)52 ProtoContourPolyline2D::create(Scene *scene)
53 {
54 return new NodeContourPolyline2D(scene, this);
55 }
56
NodeContourPolyline2D(Scene * scene,Proto * def)57 NodeContourPolyline2D::NodeContourPolyline2D(Scene *scene, Proto *def)
58 : Node(scene, def)
59 {
60 }
61
62 void
setField(int index,FieldValue * value,int cf)63 NodeContourPolyline2D::setField(int index, FieldValue *value, int cf)
64 {
65 Node::setField(index, value, cf);
66 if (hasParent())
67 getParents().update();
68 }
69
70 void
drawHandles()71 NodeContourPolyline2D::drawHandles()
72 {
73 int iSize = lineSegments()->getSize() / 2;
74 RenderState state;
75
76 glPushName(iSize + 1);
77 glDisable(GL_LIGHTING);
78 Util::myGlColor3f(1.0f, 1.0f, 1.0f);
79 glLoadName(NO_HANDLE);
80 glBegin(GL_LINE_STRIP);
81 for (int i = 0; i < iSize; i++) {
82 const double *v = lineSegments()->getValue(i);
83 glVertex3d(v[0], v[1], 0);
84 }
85 glEnd();
86
87 int ci;
88
89 state.startDrawHandles();
90 for (ci = 0; ci < iSize; ci++) {
91 state.setHandleColor(m_scene, ci);
92 glLoadName(ci);
93 const double *v = lineSegments()->getValue(ci);
94
95 state.drawHandle(Vec3f((float)v[0], (float)v[1], 0));
96 }
97 state.endDrawHandles();
98 glPopName();
99 glEnable(GL_LIGHTING);
100 }
101
102
103 Vec3f
getHandle(int handle,int * constraint,int * field)104 NodeContourPolyline2D::getHandle(int handle, int *constraint, int *field)
105 {
106 *field = lineSegments_Field() ;
107
108 if (handle >= 0 && handle < lineSegments()->getSize() / 2) {
109 const double *p = lineSegments()->getValue(handle);
110
111 Vec3f ret(p[0], p[1], 0);
112 TheApp->PrintMessageWindowsVertex(IDS_VERTEX_SELECTED,
113 "lineSegments", handle, ret);
114 return ret;
115 }
116 *field = -1;
117 return Vec3f(0.0f, 0.0f, 0.0f);
118 }
119
120 void
setHandle(int handle,const Vec3f & v)121 NodeContourPolyline2D::setHandle(int handle, const Vec3f &v)
122 {
123 MFVec2d *newValue = new MFVec2d(*lineSegments());
124
125 int numPoints = lineSegments()->getSize() / 2;
126 if (handle >= 0 && handle < numPoints) {
127 newValue->setValue(handle * 2 , v.x);
128 newValue->setValue(handle * 2 + 1, v.y);
129 }
130 m_scene->setField(this, lineSegments_Field(), newValue);
131 if (hasParent())
132 getParents().update();
133 }
134
135
136