Developer Documentation
CoordsysObject.cc
1 /*===========================================================================*\
2 * *
3 * OpenFlipper *
4  * Copyright (c) 2001-2015, RWTH-Aachen University *
5  * Department of Computer Graphics and Multimedia *
6  * All rights reserved. *
7  * www.openflipper.org *
8  * *
9  *---------------------------------------------------------------------------*
10  * This file is part of OpenFlipper. *
11  *---------------------------------------------------------------------------*
12  * *
13  * Redistribution and use in source and binary forms, with or without *
14  * modification, are permitted provided that the following conditions *
15  * are met: *
16  * *
17  * 1. Redistributions of source code must retain the above copyright notice, *
18  * this list of conditions and the following disclaimer. *
19  * *
20  * 2. Redistributions in binary form must reproduce the above copyright *
21  * notice, this list of conditions and the following disclaimer in the *
22  * documentation and/or other materials provided with the distribution. *
23  * *
24  * 3. Neither the name of the copyright holder nor the names of its *
25  * contributors may be used to endorse or promote products derived from *
26  * this software without specific prior written permission. *
27  * *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39 * *
40 \*===========================================================================*/
41 
42 
43 
44 //=============================================================================
45 //
46 // Plane Object
47 //
48 //=============================================================================
49 
50 #define PLANEOBJECT_C
51 
52 //== INCLUDES =================================================================
53 
55 #include "Coordsys.hh"
56 #include <ACG/Scenegraph/MaterialNode.hh>
57 
58 //== DEFINES ==================================================================
59 
60 //== TYPEDEFS =================================================================
61 
62 //== CLASS DEFINITION =========================================================
63 
71  BaseObjectData( ),
72  coordsysNode_(NULL)
73 {
75  init();
76 }
77 
78 //=============================================================================
79 
80 
85  BaseObjectData(_object)
86 {
87 
88  init(_object.coordsysNode_);
89 
90  setName( name() );
91 }
92 
97 {
98  // Delete the data attached to this object ( this will remove all perObject data)
99  // Not the best way to do it but it will work.
100  // This is only necessary if people use references to the coordsys below and
101  // they do something with the coordsys in the destructor of their
102  // perObjectData.
103  deleteData();
104 
105  // No need to delete the scenegraph Nodes as this will be managed by baseplugin
106  coordsysNode_ = NULL;
107 }
108 
113 
115 
116  coordsysNode_ = NULL;
117 
119  setTypeIcon(DATA_COORDSYS,"CoordsysType.png");
120 
121  init();
122 
123 }
124 
129  CoordsysObject* object = new CoordsysObject(*this);
130  return dynamic_cast< BaseObject* >(object);
131 }
132 
136 
137  if ( materialNode() == NULL)
138  std::cerr << "Error when creating Coordsys Object! materialNode is NULL!" << std::endl;
139 
140  coordsysNode_ = new CoordsysNode( materialNode() , "NEW CoordsysNode");
141 
142  if (_coordsys){
143  coordsysNode_->position( _coordsys->position() );
144  coordsysNode_->size( _coordsys->size() );
145  } else {
146  coordsysNode_->position( ACG::Vec3d(0.0, 0.0, 0.0) );
147  coordsysNode_->size( 1.0 );
148  }
149 }
150 
151 // ===============================================================================
152 // Name/Path Handling
153 // ===============================================================================
154 
158 void CoordsysObject::setName( QString _name ) {
160 
161  std::string nodename = std::string("CoordsysNode for Coordinate system " + _name.toUtf8() );
162  coordsysNode_->name( nodename );
163 }
164 
165 // ===============================================================================
166 // Visualization
167 // ===============================================================================
168 
170  return coordsysNode_;
171 }
172 
173 // ===============================================================================
174 // Object information
175 // ===============================================================================
176 
183  QString output;
184 
185  output += "========================================================================\n";
186  output += BaseObjectData::getObjectinfo();
187 
188  if ( dataType( DATA_COORDSYS ) )
189  output += "Object Contains a coordinate system : ";
190 
192  double size = coordsysNode_->size();
193 
194  output += " Position ( " + QString::number(pos[0]) + ", " + QString::number(pos[1]) + ", " + QString::number(pos[2]) + ")";
195  output += " Size ( "+ QString::number(size) + ")";
196 
197  output += "========================================================================\n";
198  return output;
199 }
200 
201 // ===============================================================================
202 // Picking
203 // ===============================================================================
204 
211 bool CoordsysObject::picked( uint _node_idx ) {
212  return ( _node_idx == coordsysNode_->id() );
213 }
214 
215 void CoordsysObject::enablePicking( bool _enable ) {
216  coordsysNode_->enablePicking( _enable );
217 }
218 
220  return coordsysNode_->pickingEnabled();
221 }
222 
223 // ===============================================================================
224 // Update
225 // ===============================================================================
226 
227 
229  BaseObject::update(_type);
230 }
231 
232 
233 //=============================================================================
234 
Update type class.
Definition: UpdateType.hh:60
ACG::SceneGraph::CoordinateSystemNode CoordsysNode
Simple Name for CoordsysNode.
virtual QString getObjectinfo()
Get all Info for the Object as a string.
Definition: BaseObject.cc:244
QString getObjectinfo()
Get all Info for the Object as a string.
virtual void update(UpdateType _type=UPDATE_ALL)
Update the whole Object (Selection,Topology,...)
MaterialNode * materialNode()
get a pointer to the materialnode
virtual void cleanup()
Reset current object, including all related nodes.
void setDataType(DataType _type)
Definition: BaseObject.cc:233
std::string name() const
Returns: name of node (needs not be unique)
void deleteData()
Delete all data attached to this object ( calls delete on each object )
Definition: BaseObject.cc:812
virtual void update(UpdateType _type=UPDATE_ALL)
This function is called to update the object.
Definition: BaseObject.cc:745
CoordsysNode * coordsysNode()
Get the scenegraph Node.
virtual void cleanup()
#define DATA_COORDSYS
Definition: Coordsys.hh:58
void position(const Vec3d &_pos)
set position of the coordsys
CoordsysNode * coordsysNode_
Get the scenegraph Node.
virtual void setName(QString _name)
path to the file from which the object is loaded ( defaults to "." )
QString name() const
return the name of the object. The name defaults to NONAME if unset.
Definition: BaseObject.cc:730
DLLEXPORT void setTypeIcon(DataType _id, QString _icon)
Set an Icon for a given DataType.
Definition: Types.cc:223
bool picked(uint _node_idx)
detect if the node has been picked
void enablePicking(bool _enable)
Enable or disable picking for this Object.
Node for displaying coordinate systems.
void setName(QString _name)
Set the name of the Object.
bool pickingEnabled()
Check if picking is enabled for this Object.
virtual void init(CoordsysNode *_coordsys=0)
Initialize current object, including all related nodes.
CoordsysObject()
constructor
void size(const double _size)
set size of the coordsys ( Size is length of one of the axis )
DataType dataType() const
Definition: BaseObject.cc:229
virtual ~CoordsysObject()
destructor
BaseObject * copy()