H3D API  2.4.1
Contour2D.h
Go to the documentation of this file.
1 // Copyright 2004-2019, SenseGraphics AB
3 //
4 // This file is part of H3D API.
5 //
6 // H3D API 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 // H3D API 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 H3D API; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 //
20 // A commercial license is also available. Please contact us at
21 // www.sensegraphics.com for more information.
22 //
23 //
27 //
29 #ifndef __CONTOUR2D_H__
30 #define __CONTOUR2D_H__
31 
32 #include <H3D/X3DNode.h>
33 #include <H3D/MFNode.h>
34 #include <H3D/NurbsCurve2D.h>
35 #include <H3D/ContourPolyline2D.h>
36 #include "GL/glew.h"
37 
38 namespace H3D {
39 
60 
61  class H3DAPI_API Contour2D :
62  public X3DNode {
63  public:
64 
65 
69  class H3DAPI_API AddTheChildren: public MFNode {
70  public:
71 
72  virtual void onAdd( Node *n ) {
73  MFNode::onAdd( n );
74  NurbsCurve2D *nurbs_curve_2D =
75  dynamic_cast< NurbsCurve2D * >( n );
76 
77  ContourPolyline2D *contour_poly_line_2D =
78  dynamic_cast< ContourPolyline2D * >( n );
79 
80  if( !nurbs_curve_2D && !contour_poly_line_2D ) {
81  stringstream s;
82  s << "Expecting NurbsCurve2D or ContourPolyline2D";
83  throw InvalidNodeType( n->getTypeName(),
84  s.str(),
86  }
87  else{
88  Contour2D * contourNode2D =
89  static_cast< Contour2D * >( getOwner() );
90  contourNode2D->children->push_back( n );
91  }
92  }
93  };
94 #ifdef __BORLANDC__
95  friend class AddTheChildren;
96 #endif
97 
101  class H3DAPI_API RemoveTheChildren: public MFNode {
102  public:
103 
104 
105  virtual void onRemove( Node *n ) {
106  NurbsCurve2D *nurbs_curve_2D =
107  dynamic_cast< NurbsCurve2D * >( n );
108 
109  ContourPolyline2D *contour_poly_line_2D =
110  dynamic_cast< ContourPolyline2D * >( n );
111 
112  if( !nurbs_curve_2D && !contour_poly_line_2D ) {
113  stringstream s;
114  s << "Expecting NurbsCurve2D or ContourPolyline2D";
115  throw InvalidNodeType( n->getTypeName(),
116  s.str(),
118  }
119  else {
120  Contour2D * contourNode2D =
121  static_cast< Contour2D * >( getOwner() );
122  contourNode2D->children->erase( n );
123  }
124 
125  MFNode::onRemove( n );
126  }
127  };
128 #ifdef __BORLANDC__
129  friend class RemoveTheChildren;
130 #endif
131 
135  class H3DAPI_API CheckTheChildren: public MFNode {
136  public:
137 
138  virtual void onAdd( Node *n ) {
139  MFNode::onAdd( n );
140  NurbsCurve2D *nurbs_curve_2D =
141  dynamic_cast< NurbsCurve2D * >( n );
142 
143  ContourPolyline2D *contour_poly_line_2D =
144  dynamic_cast< ContourPolyline2D * >( n );
145 
146  if( !nurbs_curve_2D && !contour_poly_line_2D ) {
147  stringstream s;
148  s << "Expecting NurbsCurve2D or ContourPolyline2D";
149  throw InvalidNodeType( n->getTypeName(),
150  s.str(),
152  }
153  }
154 
155  virtual void onRemove( Node *n ) {
156  NurbsCurve2D *nurbs_curve_2D =
157  dynamic_cast< NurbsCurve2D * >( n );
158 
159  ContourPolyline2D *contour_poly_line_2D =
160  dynamic_cast< ContourPolyline2D * >( n );
161 
162  if( !nurbs_curve_2D && !contour_poly_line_2D ) {
163  stringstream s;
164  s << "Expecting NurbsCurve2D or ContourPolyline2D";
165  throw InvalidNodeType( n->getTypeName(),
166  s.str(),
168  }
169 
170  MFNode::onRemove( n );
171  }
172  };
173 #ifdef __BORLANDC__
174  friend class CheckTheChildren;
175 #endif
176 
178  void renderTrimmedCurve( GLUnurbsObj *nurbs_object );
179 
181  Contour2D( Inst< SFNode > _metadata = 0,
182  Inst< AddTheChildren > _addChildren = 0,
183  Inst< RemoveTheChildren > _removeChildren = 0,
184  Inst< CheckTheChildren > _children = 0 );
185 
191  H3DUniquePtr< AddTheChildren > addChildren;
192 
199  H3DUniquePtr< RemoveTheChildren > removeChildren;
200 
206  H3DUniquePtr< CheckTheChildren > children;
207 
210  };
211 }
212 
213 #endif
Header file for ContourPolyline2D, X3D scene-graph node.
#define H3D_FULL_LOCATION
Contains the MFNode class.
Header file for NurbsCurve2D, X3D scene-graph node.
Header file for X3DNode, X3D scene-graph node.
std::string getTypeName() const
This field class checks whether the given node is of the right type (ContourPolyline2D or NurbsCurve2...
Definition: Contour2D.h:69
virtual void onAdd(Node *n)
This function will be called when values of RefCountMField changes.
Definition: Contour2D.h:72
This field class checks whether the given Node is of the right type (ContourPolyline2D or NurbsCurve2...
Definition: Contour2D.h:135
virtual void onRemove(Node *n)
This function will be called when values of RefCountMField changes.
Definition: Contour2D.h:155
virtual void onAdd(Node *n)
This function will be called when values of RefCountMField changes.
Definition: Contour2D.h:138
This field class checks whether the given node is of the right type (ContourPolyline2D or NurbsCurve2...
Definition: Contour2D.h:101
virtual void onRemove(Node *n)
This function will be called when values of RefCountMField changes.
Definition: Contour2D.h:105
The Contour2D node groups a set of curve segments to a composite contour.
Definition: Contour2D.h:62
static H3DNodeDatabase database
The H3DNodeDatabase for this node.
Definition: Contour2D.h:209
H3DUniquePtr< AddTheChildren > addChildren
Adds a node to the children field if it is the correct type of Node.
Definition: Contour2D.h:191
H3DUniquePtr< RemoveTheChildren > removeChildren
Removes a node from the children field if it is the correct type of Node.
Definition: Contour2D.h:199
H3DUniquePtr< CheckTheChildren > children
Contains the curves making up the contour.
Definition: Contour2D.h:206
The ContourPolyline2D node defines a piecewise linear curve segment as a part of a trimming contour i...
Definition: ContourPolyline2D.h:52
MFNode is almost like any MField but it encapsulates a vector of Node pointers.
Definition: MFNode.h:44
Node is the base class for all classes that can be part of the H3D scene-graph.
Definition: Node.h:46
The NurbsCurve2D node defines a trimming segment that is part of a trimming contour in the u,...
Definition: NurbsCurve2D.h:53
virtual void onRemove(Node *n)
This function will be called when values of RefCountMField changes.
Definition: RefCountMField.h:233
virtual void onAdd(Node *n)
This function will be called when values of RefCountMField changes.
Definition: RefCountMField.h:222
This abstract node type is the base type for all nodes in the X3D system.
Definition: X3DNode.h:65
H3D API namespace.
Definition: Anchor.h:38
The H3DNodeDatabase contains a mapping between a name of a Node and the constructor for the Node with...
Definition: H3DNodeDatabase.h:194