Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
TypeSkeleton.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 * $Revision$ *
45 * $LastChangedBy$ *
46 * $Date$ *
47 * *
48 \*===========================================================================*/
49 
50 
51 #include "TypeSkeleton.hh"
52 
54 #include <OpenFlipper/common/BackupData.hh>
56 #include "SkeletonBackup.hh"
57 
58 TypeSkeletonPlugin::TypeSkeletonPlugin()
59  : showIndicesAction_(0),
60  showCoordFramesAction_(0),
61  showMotionAction_(0)
62 {
63 }
64 
69 {
70 
71  if ( OpenFlipper::Options::gui() ){
72 
73  QMenu* contextMenu = new QMenu("Options");
74 
75  QString iconPath = OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator();
76 
77  //Show indices
78  showIndicesAction_ = new QAction(tr("Show &Indices"), this);
79  showIndicesAction_->setStatusTip(tr("Show Joint Indices"));
80  showIndicesAction_->setIcon( QIcon(iconPath + "showIndices.png") );
81  showIndicesAction_->setCheckable(true);
82  showIndicesAction_->setChecked(false);
83  //Show coord-frames
84  showCoordFramesAction_ = new QAction(tr("Show &Coordinate Frames"), this);
85  showCoordFramesAction_->setStatusTip(tr("Show Coordinate Frames for joints"));
86  showCoordFramesAction_->setIcon( QIcon(iconPath + "coordsys.png") );
87  showCoordFramesAction_->setCheckable(true);
88  showCoordFramesAction_->setChecked(false);
89  //Show motion space
90  showMotionAction_ = new QAction(tr("Show &Motion Path"), this);
91  showMotionAction_->setStatusTip(tr("Show path of motions for joints"));
92  showMotionAction_->setIcon( QIcon(iconPath + "motionPath.png") );
93  showMotionAction_->setCheckable(true);
94  showMotionAction_->setChecked(false);
95 
96  connect(showIndicesAction_, SIGNAL(triggered()), this, SLOT(slotShowIndices()) );
97  connect(showCoordFramesAction_, SIGNAL(triggered()), this, SLOT(slotShowCoordFrames()) );
98  connect(showMotionAction_, SIGNAL(triggered()), this, SLOT(slotShowMotionPath()) );
99 
100  contextMenu->addAction(showIndicesAction_);
101  contextMenu->addAction(showCoordFramesAction_);
102  contextMenu->addAction(showMotionAction_);
103 
104  emit addContextMenuItem(contextMenu->menuAction(), DATA_SKELETON, CONTEXTOBJECTMENU);
105  }
106 }
107 
109 {
110  if ( _objectId == -1)
111  return;
112 
113  BaseObjectData* object;
114  if ( !PluginFunctions::getObject(_objectId,object) )
115  return;
116 
117  SkeletonObject* skeletonObject = dynamic_cast<SkeletonObject*>(object);
118 
119  if(skeletonObject != 0){
120  showIndicesAction_->setChecked( skeletonObject->indicesVisible() );
121  showCoordFramesAction_->setChecked( skeletonObject->skeletonNode()->coordFramesVisible() );
122  showMotionAction_->setChecked( skeletonObject->motionPathVisible() );
123  }
124 }
125 
126 void TypeSkeletonPlugin::slotShowIndices(){
127 
128  QVariant contextObject = showIndicesAction_->data();
129  int objectId = contextObject.toInt();
130 
131  if ( objectId == -1)
132  return;
133 
134  BaseObjectData* object;
135  if ( !PluginFunctions::getObject(objectId,object) )
136  return;
137 
138  SkeletonObject* skeletonObject = dynamic_cast<SkeletonObject*>(object);
139 
140  if(skeletonObject != 0){
141  skeletonObject->showIndices( showIndicesAction_->isChecked() );
142  emit updatedObject( objectId, UPDATE_ALL );
143  }
144 }
145 
146 void TypeSkeletonPlugin::slotShowCoordFrames(){
147 
148  QVariant contextObject = showCoordFramesAction_->data();
149  int objectId = contextObject.toInt();
150 
151  if ( objectId == -1)
152  return;
153 
154  BaseObjectData* object;
155  if ( !PluginFunctions::getObject(objectId,object) )
156  return;
157 
158  SkeletonObject* skeletonObject = dynamic_cast<SkeletonObject*>(object);
159 
160  if(skeletonObject != 0){
161  skeletonObject->skeletonNode()->showCoordFrames( showCoordFramesAction_->isChecked() );
162  emit updatedObject( objectId, UPDATE_ALL );
163  }
164 }
165 
166 void TypeSkeletonPlugin::slotShowMotionPath(){
167 
168  QVariant contextObject = showMotionAction_->data();
169  int objectId = contextObject.toInt();
170 
171  if ( objectId == -1)
172  return;
173 
174  BaseObjectData* object;
175  if ( !PluginFunctions::getObject(objectId,object) )
176  return;
177 
178  SkeletonObject* skeletonObject = dynamic_cast<SkeletonObject*>(object);
179 
180  if(skeletonObject != 0){
181  skeletonObject->showMotionPath( showMotionAction_->isChecked() );
182  emit updatedObject( objectId, UPDATE_ALL );
183  }
184 }
185 
186 bool TypeSkeletonPlugin::registerType() {
187  addDataType("Skeleton",tr("Skeleton"));
188  setTypeIcon("Skeleton", "SkeletonType.png");
189  return true;
190 }
191 
193 
194  // new object data struct
195  SkeletonObject * object = new SkeletonObject();
196 
197  if ( OpenFlipperSettings().value("Core/File/AllTarget",false).toBool() )
198  object->target(true);
199  else {
200 
201  // Only the first object in the scene will be target
202  if ( PluginFunctions::objectCount() == 1 )
203  object->target(true);
204 
205  // If no target is available, we set the new object as target
206  if (PluginFunctions::targetCount() == 0 )
207  object->target(true);
208  }
209 
210  QString name = QString(tr("New Skeleton %1.skl").arg( object->id() ));
211 
212  // call the local function to update names
213  QFileInfo f(name);
214  object->setName( f.fileName() );
215 
216  // set the default color
217  object->materialNode()->set_color(ACG::Vec4f(0.654f, 0.8f, 1.0f, 1.0f));
218 
219  object->update();
220 
221  object->show();
222 
223  emit emptyObjectAdded (object->id() );
224 
225  return object->id();
226 }
227 
228 void TypeSkeletonPlugin::generateBackup( int _id, QString _name, UpdateType _type ){
229 
230  BaseObjectData* object = 0;
231  PluginFunctions::getObject(_id, object);
232 
234 
235  if ( skelObj != 0 ){
236 
237  //get backup object data
238  BackupData* backupData = 0;
239 
240  if ( object->hasObjectData( OBJECT_BACKUPS ) )
241  backupData = dynamic_cast< BackupData* >(object->objectData(OBJECT_BACKUPS));
242  else{
243  //add backup data
244  backupData = new BackupData(object);
245  object->setObjectData(OBJECT_BACKUPS, backupData);
246  }
247 
248  //store a new backup
249  SkeletonBackup* backup = new SkeletonBackup(skelObj, _name, _type);
250  backupData->storeBackup( backup );
251  }
252 }
253 
254 #if QT_VERSION < 0x050000
255  Q_EXPORT_PLUGIN2( typeskeletonplugin , TypeSkeletonPlugin );
256 #endif
257 
DLLEXPORT OpenFlipperQSettings & OpenFlipperSettings()
QSettings object containing all program settings of OpenFlipper.
QString name()
Return a name for the plugin.
DLLEXPORT void setTypeIcon(DataType _id, QString _icon)
Set an Icon for a given DataType.
Definition: Types.cc:234
SkeletonObject * skeletonObject(BaseObjectData *_object)
Cast an BaseObject to a SkeletonObject if possible.
PerObjectData * objectData(QString _dataName)
Returns the object data pointer.
Definition: BaseObject.cc:814
int targetCount()
Get the number of target objects.
void storeBackup(BaseBackup *_backup)
store a backup
Definition: BackupData.cc:80
void slotUpdateContextMenu(int _objectId)
Update type class.
Definition: UpdateType.hh:70
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.
bool getObject(int _identifier, BSplineCurveObject *&_object)
virtual void updatedObject(int _objectId)
An object has been changed or added by this plugin.
void showMotionPath(bool _visible=true)
Shows or hides the local motion space for a joint.
DLLEXPORT DataType addDataType(QString _name, QString _readableName)
Adds a datatype and returns the id for the new type.
Definition: Types.cc:128
void generateBackup(int _id, QString _name, UpdateType _type)
This slot should be implemented in a TypePlugin to generate type specific backups.
Class that encapsulates a backup.
bool hasObjectData(QString _dataName)
Checks if object data with given name is available.
Definition: BaseObject.cc:806
int addEmpty()
Create an empty object.
void showIndices(bool _bVisible=true)
Shows or hides the indices.
The Menu will be shown when an object was picked.
int objectCount()
Get the number of available objects.
#define DATA_SKELETON
Definition: Skeleton.hh:70
ACG::SceneGraph::SkeletonNodeT< Skeleton > * skeletonNode()
Returns the skeleton scenegraph node.
int id() const
Definition: BaseObject.cc:201
Abstract class that is used to store backups.
Definition: BackupData.hh:66
void pluginsInitialized()
Second initialization phase.
Definition: TypeSkeleton.cc:68