Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
TypeBSplineCurve.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 //
52 // CLASS Type BSpline Curve Plugin - IMPLEMENTATION
53 //
54 // Author: Ellen Dekkers <dekkers@cs.rwth-aachen.de>
55 //
56 // Date: 2010-02-02 11:02:14 +0100 (Di, 02. Feb 2010)
57 //
58 //=============================================================================
59 
60 
61 #include "TypeBSplineCurve.hh"
62 
64 #include <OpenFlipper/common/BackupData.hh>
66 #include "BSplineCurveBackup.hh"
67 
68 //-----------------------------------------------------------------------------
69 
70 TypeBSplineCurvePlugin::
71 TypeBSplineCurvePlugin():
72 renderControlPolygonAction_(0),
73 renderCurveAction_(0),
74 renderCPSelectionAction_(0),
75 renderKnotSelectionAction_(0),
76 renderNoSelectionAction_(0)
77 {
78 }
79 
80 
81 //-----------------------------------------------------------------------------
82 
87 {
88 
89  if ( OpenFlipper::Options::gui() ){
90 
91  QMenu* contextMenu = new QMenu("Rendering");
92 
93  QString iconPath = OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator();
94 
95  // Render Control Net
96  renderControlPolygonAction_ = new QAction(tr("Render Control Polygon"), this);
97  renderControlPolygonAction_->setStatusTip(tr("Render Control Polygon"));
98 // renderControlPolygonAction_->setIcon( QIcon(iconPath + "showIndices.png") );
99  renderControlPolygonAction_->setCheckable(true);
100  renderControlPolygonAction_->setChecked(false);
101 
102  // Render Surface
103  renderCurveAction_ = new QAction(tr("Render Curve"), this);
104  renderCurveAction_->setStatusTip(tr("Render Curve"));
105 // renderCurveAction_->setIcon( QIcon(iconPath + "coordsys.png") );
106  renderCurveAction_->setCheckable(true);
107  renderCurveAction_->setChecked(true);
108 
109  QActionGroup* group = new QActionGroup(this);
110  group->setExclusive(true);
111 
112  // Render Control Point Selection
113  renderCPSelectionAction_ = new QAction(tr("Render Control Point Selection"), group);
114  renderCPSelectionAction_->setStatusTip(tr("Render Control Point Selection"));
115 // renderCPSelectionAction_->setIcon( QIcon(iconPath + "coordsys.png") );
116  renderCPSelectionAction_->setCheckable(true);
117  renderCPSelectionAction_->setChecked(true);
118 
119  // Render Knot Selection
120  renderKnotSelectionAction_ = new QAction(tr("Render Knot Selection"), group);
121  renderKnotSelectionAction_->setStatusTip(tr("Render Knot Selection"));
122 // renderKnotSelectionAction_->setIcon( QIcon(iconPath + "coordsys.png") );
123  renderKnotSelectionAction_->setCheckable(true);
124  renderKnotSelectionAction_->setChecked(true);
125 
126  // Render No Selection
127  renderNoSelectionAction_ = new QAction(tr("Don't Render Selection"), group);
128  renderNoSelectionAction_->setStatusTip(tr("Don't Render Selection"));
129 // renderNoSelectionAction_->setIcon( QIcon(iconPath + "coordsys.png") );
130  renderNoSelectionAction_->setCheckable(true);
131  renderNoSelectionAction_->setChecked(true);
132 
133 
134  connect(renderControlPolygonAction_, SIGNAL(triggered()), this, SLOT(slotRenderControlPolygon()) );
135  connect(renderCurveAction_, SIGNAL(triggered()), this, SLOT(slotRenderCurve()) );
136 
137  connect(group, SIGNAL(triggered(QAction*)), this, SLOT(slotRenderSelection(QAction*)));
138 
139  contextMenu->addAction(renderControlPolygonAction_);
140  contextMenu->addAction(renderCurveAction_);
141  contextMenu->addSeparator();
142  contextMenu->addAction(renderCPSelectionAction_);
143  contextMenu->addAction(renderKnotSelectionAction_);
144  contextMenu->addAction(renderNoSelectionAction_);
145 
146  emit addContextMenuItem(contextMenu->menuAction(), DATA_BSPLINE_CURVE, CONTEXTOBJECTMENU);
147  }
148 }
149 
150 //-----------------------------------------------------------------------------
151 
152 void
154 slotUpdateContextMenu( int _objectId ) {
155  if ( _objectId == -1)
156  return;
157 
158  BaseObjectData* object;
159  if ( !PluginFunctions::getObject(_objectId,object) )
160  return;
161 
162  BSplineCurveObject* bsplineCurveObject = dynamic_cast<BSplineCurveObject*>(object);
163 
164  if(bsplineCurveObject != 0){
165  renderControlPolygonAction_->setChecked( bsplineCurveObject->splineCurveNode()->render_control_polygon() );
166  renderCurveAction_->setChecked( bsplineCurveObject->splineCurveNode()->render_bspline_curve() );
167  renderCPSelectionAction_->setChecked( bsplineCurveObject->splineCurveNode()->get_selection_draw_mode() == ACG::SceneGraph::BSplineCurveNodeT<BSplineCurve>::CONTROLPOINT );
168  renderKnotSelectionAction_->setChecked( bsplineCurveObject->splineCurveNode()->get_selection_draw_mode() == ACG::SceneGraph::BSplineCurveNodeT<BSplineCurve>::KNOTVECTOR );
169  renderNoSelectionAction_->setChecked( bsplineCurveObject->splineCurveNode()->get_selection_draw_mode() == ACG::SceneGraph::BSplineCurveNodeT<BSplineCurve>::NONE );
170  }
171 }
172 
173 //-----------------------------------------------------------------------------
174 
176 
177  QVariant contextObject = renderControlPolygonAction_->data();
178  int objectId = contextObject.toInt();
179 
180  if ( objectId == -1)
181  return;
182 
183  BaseObjectData* object;
184  if ( !PluginFunctions::getObject(objectId,object) )
185  return;
186 
187  BSplineCurveObject* bsplineCurveObject = dynamic_cast<BSplineCurveObject*>(object);
188 
189  if(bsplineCurveObject != 0){
190  bsplineCurveObject->splineCurveNode()->render_control_polygon(renderControlPolygonAction_->isChecked());
191  emit updatedObject( objectId, UPDATE_ALL );
192  }
193 }
194 
195 //-----------------------------------------------------------------------------
196 
198 
199  QVariant contextObject = renderCurveAction_->data();
200  int objectId = contextObject.toInt();
201 
202  if ( objectId == -1)
203  return;
204 
205  BaseObjectData* object;
206  if ( !PluginFunctions::getObject(objectId,object) )
207  return;
208 
209  BSplineCurveObject* bsplineCurveObject = dynamic_cast<BSplineCurveObject*>(object);
210 
211  if(bsplineCurveObject != 0){
212  bsplineCurveObject->splineCurveNode()->render_bspline_curve(renderCurveAction_->isChecked());
213  emit updatedObject( objectId, UPDATE_ALL );
214  }
215 }
216 
217 //-----------------------------------------------------------------------------
218 
220 
221  QVariant contextObject = _action->data();
222  int objectId = contextObject.toInt();
223 
224  if ( objectId == -1)
225  return;
226 
227  BaseObjectData* object;
228  if ( !PluginFunctions::getObject(objectId,object) )
229  return;
230 
231  BSplineCurveObject* bsplineCurveObject = dynamic_cast<BSplineCurveObject*>(object);
232 
233  if(bsplineCurveObject != 0){
234  if(_action == renderCPSelectionAction_) {
235  bsplineCurveObject->splineCurveNode()->set_selection_draw_mode(ACG::SceneGraph::BSplineCurveNodeT<BSplineCurve>::CONTROLPOINT);
236  emit updatedObject( objectId, UPDATE_ALL );
237  } else if(_action == renderKnotSelectionAction_) {
238  bsplineCurveObject->splineCurveNode()->set_selection_draw_mode(ACG::SceneGraph::BSplineCurveNodeT<BSplineCurve>::KNOTVECTOR);
239  emit updatedObject( objectId, UPDATE_ALL );
240  } else if(_action == renderNoSelectionAction_) {
241  bsplineCurveObject->splineCurveNode()->set_selection_draw_mode(ACG::SceneGraph::BSplineCurveNodeT<BSplineCurve>::NONE);
242  emit updatedObject( objectId, UPDATE_ALL );
243  }
244  }
245 }
246 
247 //-----------------------------------------------------------------------------
248 
249 bool
250 TypeBSplineCurvePlugin::
251 registerType()
252 {
253  addDataType("BSplineCurve",tr("B-Spline Curve"));
254  setTypeIcon("BSplineCurve", "BSplineCurveType.png");
255  return true;
256 }
257 
258 //-----------------------------------------------------------------------------
259 
260 DataType
263 {
265  return type;
266 }
267 
268 //-----------------------------------------------------------------------------
269 
270 int
273 {
274  // new object data struct
275  BSplineCurveObject * object = new BSplineCurveObject();
276 
277 
278  if ( OpenFlipperSettings().value("Core/File/AllTarget",false).toBool() )
279  object->target(true);
280  else {
281 
282  // Only the first object in the scene will be target
283  if ( PluginFunctions::objectCount() == 1 )
284  object->target(true);
285 
286  // If no target is available, we set the new object as target
287  if (PluginFunctions::targetCount() == 0 )
288  object->target(true);
289  }
290 
291  QString name = "BSplineCurve_" + QString::number( object->id() ) + ".bsc";
292 
293  // call the local function to update names
294  QFileInfo f(name);
295  object->setName( f.fileName() );
296 
297  // set the default colors
298  const QColor color = OpenFlipper::Options::defaultColor();
299  const ACG::Vec4f default_color(color.redF(), color.greenF(), color.blueF(), color.alphaF());
300  object->materialNode()->set_color(default_color);
301 
302  object->update();
303 
304  object->show();
305 
306  emit log(LOGINFO,object->getObjectinfo());
307 
308  emit emptyObjectAdded (object->id() );
309 
310  return object->id();
311 }
312 
313 //-----------------------------------------------------------------------------
314 
315 void TypeBSplineCurvePlugin::generateBackup( int _id, QString _name, UpdateType _type ){
316 
317  BaseObjectData* object = 0;
318  PluginFunctions::getObject(_id, object);
319 
321 
322  if ( splineObj != 0 ){
323 
324  //get backup object data
325  BackupData* backupData = 0;
326 
327  if ( object->hasObjectData( OBJECT_BACKUPS ) )
328  backupData = dynamic_cast< BackupData* >(object->objectData(OBJECT_BACKUPS));
329  else{
330  //add backup data
331  backupData = new BackupData(object);
332  object->setObjectData(OBJECT_BACKUPS, backupData);
333  }
334 
335  //store a new backup
336  BSplineCurveBackup* backup = new BSplineCurveBackup(splineObj, _name, _type);
337  backupData->storeBackup( backup );
338  }
339 }
340 
341 //-----------------------------------------------------------------------------
342 
343 #if QT_VERSION < 0x050000
344  Q_EXPORT_PLUGIN2( typebsplinecurveplugin , TypeBSplineCurvePlugin );
345 #endif
346 
347 
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
QAction * renderCurveAction_
Context menu action.
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
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.
#define DATA_BSPLINE_CURVE
Definition: BSplineCurve.hh:73
DLLEXPORT DataType addDataType(QString _name, QString _readableName)
Adds a datatype and returns the id for the new type.
Definition: Types.cc:128
QAction * renderControlPolygonAction_
Context menu action.
void pluginsInitialized()
Second initialization phase.
QString getObjectinfo()
Get all Info for the Object as a string.
bool hasObjectData(QString _dataName)
Checks if object data with given name is available.
Definition: BaseObject.cc:806
void slotRenderControlPolygon()
Slot triggered from context menu, if the control polygon should be rendered.
int addEmpty()
Create an empty object.
void slotRenderSelection(QAction *_action)
Slot triggered from context menu, if the selection rendering should be altered.
The Menu will be shown when an object was picked.
ACG::SceneGraph::BSplineCurveNodeT< BSplineCurve > * splineCurveNode()
Get the scenegraph Node.
DataType supportedType()
Return your supported object type( e.g. DATA_TRIANGLE_MESH )
int objectCount()
Get the number of available objects.
QAction * renderCPSelectionAction_
Context menu action (render selection texture)
BSplineCurveObject * bsplineCurveObject(BaseObjectData *_object)
Cast an BaseObject to a BSplineCurveObject if possible.
Predefined datatypes.
Definition: DataTypes.hh:96
void slotRenderCurve()
Slot triggered from context menu, if the curve should be rendered.
void slotUpdateContextMenu(int _objectId)
int id() const
Definition: BaseObject.cc:201
Class that encapsulates a backup.
Abstract class that is used to store backups.
Definition: BackupData.hh:66