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