Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
TypeBSplineSurface.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 Surface Plugin - IMPLEMENTATION
53 //
54 // Author: Ellen Dekkers <dekkers@cs.rwth-aachen.de>
55 //
56 // Date: 2010-02-02 11:01:53 +0100 (Di, 02. Feb 2010)
57 //
58 //=============================================================================
59 
60 
61 #include "TypeBSplineSurface.hh"
62 
65 
66 //-----------------------------------------------------------------------------
67 
68 TypeBSplineSurfacePlugin::
69 TypeBSplineSurfacePlugin() :
70 renderControlNetAction_(0),
71 renderSurfaceAction_(0),
72 renderCPSelectionAction_(0),
73 renderKnotSelectionAction_(0),
74 renderNoSelectionAction_(0)
75 {
76 }
77 
78 //-----------------------------------------------------------------------------
79 
84 {
85 
86  if ( OpenFlipper::Options::gui() ){
87 
88  QMenu* contextMenu = new QMenu("Rendering");
89 
90  QString iconPath = OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator();
91 
92  // Render Control Net
93  renderControlNetAction_ = new QAction(tr("Render Control Net"), this);
94  renderControlNetAction_->setStatusTip(tr("Render Control Net"));
95 // renderControlNetAction_->setIcon( QIcon(iconPath + "showIndices.png") );
96  renderControlNetAction_->setCheckable(true);
97  renderControlNetAction_->setChecked(false);
98 
99  // Render Surface
100  renderSurfaceAction_ = new QAction(tr("Render Surface"), this);
101  renderSurfaceAction_->setStatusTip(tr("Render Surface"));
102 // renderSurfaceAction_->setIcon( QIcon(iconPath + "coordsys.png") );
103  renderSurfaceAction_->setCheckable(true);
104  renderSurfaceAction_->setChecked(true);
105 
106  QActionGroup* group = new QActionGroup(this);
107  group->setExclusive(true);
108 
109  // Render Control Point Selection
110  renderCPSelectionAction_ = new QAction(tr("Render Control Point Selection"), group);
111  renderCPSelectionAction_->setStatusTip(tr("Render Control Point Selection"));
112 // renderCPSelectionAction_->setIcon( QIcon(iconPath + "coordsys.png") );
113  renderCPSelectionAction_->setCheckable(true);
114  renderCPSelectionAction_->setChecked(true);
115 
116  // Render Knot Selection
117  renderKnotSelectionAction_ = new QAction(tr("Render Knot Selection"), group);
118  renderKnotSelectionAction_->setStatusTip(tr("Render Knot Selection"));
119 // renderKnotSelectionAction_->setIcon( QIcon(iconPath + "coordsys.png") );
120  renderKnotSelectionAction_->setCheckable(true);
121  renderKnotSelectionAction_->setChecked(true);
122 
123  // Render No Selection
124  renderNoSelectionAction_ = new QAction(tr("Don't Render Selection"), group);
125  renderNoSelectionAction_->setStatusTip(tr("Don't Render Selection"));
126 // renderNoSelectionAction_->setIcon( QIcon(iconPath + "coordsys.png") );
127  renderNoSelectionAction_->setCheckable(true);
128  renderNoSelectionAction_->setChecked(true);
129 
130 
131  connect(renderControlNetAction_, SIGNAL(triggered()), this, SLOT(slotRenderControlNet()) );
132  connect(renderSurfaceAction_, SIGNAL(triggered()), this, SLOT(slotRenderSurface()) );
133 
134  connect(group, SIGNAL(triggered(QAction*)), this, SLOT(slotRenderSelection(QAction*)));
135 
136  contextMenu->addAction(renderControlNetAction_);
137  contextMenu->addAction(renderSurfaceAction_);
138  contextMenu->addSeparator();
139  contextMenu->addAction(renderCPSelectionAction_);
140  contextMenu->addAction(renderKnotSelectionAction_);
141  contextMenu->addAction(renderNoSelectionAction_);
142 
143  emit addContextMenuItem(contextMenu->menuAction(), DATA_BSPLINE_SURFACE, CONTEXTOBJECTMENU);
144  }
145 }
146 
147 //-----------------------------------------------------------------------------
148 
149 void
151 slotUpdateContextMenu( int _objectId ) {
152  if ( _objectId == -1)
153  return;
154 
155  BaseObjectData* object;
156  if ( !PluginFunctions::getObject(_objectId,object) )
157  return;
158 
159  BSplineSurfaceObject* bsplineSurfaceObject = dynamic_cast<BSplineSurfaceObject*>(object);
160 
161  if(bsplineSurfaceObject != 0){
162  renderControlNetAction_->setChecked( bsplineSurfaceObject->splineSurfaceNode()->render_control_net() );
163  renderSurfaceAction_->setChecked( bsplineSurfaceObject->splineSurfaceNode()->render_bspline_surface() );
164  renderCPSelectionAction_->setChecked( bsplineSurfaceObject->splineSurfaceNode()->get_selection_draw_mode() == ACG::SceneGraph::BSplineSurfaceNodeT<BSplineSurface>::CONTROLPOINT );
165  renderKnotSelectionAction_->setChecked( bsplineSurfaceObject->splineSurfaceNode()->get_selection_draw_mode() == ACG::SceneGraph::BSplineSurfaceNodeT<BSplineSurface>::KNOTVECTOR );
166  renderNoSelectionAction_->setChecked( bsplineSurfaceObject->splineSurfaceNode()->get_selection_draw_mode() == ACG::SceneGraph::BSplineSurfaceNodeT<BSplineSurface>::NONE );
167  }
168 }
169 
170 //-----------------------------------------------------------------------------
171 
173 
174  QVariant contextObject = renderControlNetAction_->data();
175  int objectId = contextObject.toInt();
176 
177  if ( objectId == -1)
178  return;
179 
180  BaseObjectData* object;
181  if ( !PluginFunctions::getObject(objectId,object) )
182  return;
183 
184  BSplineSurfaceObject* bsplineSurfaceObject = dynamic_cast<BSplineSurfaceObject*>(object);
185 
186  if(bsplineSurfaceObject != 0){
187  bsplineSurfaceObject->splineSurfaceNode()->render_control_net(renderControlNetAction_->isChecked());
188  emit updatedObject( objectId, UPDATE_ALL );
189  }
190 }
191 
192 //-----------------------------------------------------------------------------
193 
195 
196  QVariant contextObject = renderSurfaceAction_->data();
197  int objectId = contextObject.toInt();
198 
199  if ( objectId == -1)
200  return;
201 
202  BaseObjectData* object;
203  if ( !PluginFunctions::getObject(objectId,object) )
204  return;
205 
206  BSplineSurfaceObject* bsplineSurfaceObject = dynamic_cast<BSplineSurfaceObject*>(object);
207 
208  if(bsplineSurfaceObject != 0){
209  bsplineSurfaceObject->splineSurfaceNode()->render_bspline_surface(renderSurfaceAction_->isChecked());
210  emit updatedObject( objectId, UPDATE_ALL );
211  }
212 }
213 
214 //-----------------------------------------------------------------------------
215 
217 
218  QVariant contextObject = _action->data();
219  int objectId = contextObject.toInt();
220 
221  if ( objectId == -1)
222  return;
223 
224  BaseObjectData* object;
225  if ( !PluginFunctions::getObject(objectId,object) )
226  return;
227 
228  BSplineSurfaceObject* bsplineSurfaceObject = dynamic_cast<BSplineSurfaceObject*>(object);
229 
230  if(bsplineSurfaceObject != 0){
231  if(_action == renderCPSelectionAction_) {
232  bsplineSurfaceObject->splineSurfaceNode()->set_selection_draw_mode(ACG::SceneGraph::BSplineSurfaceNodeT<BSplineSurface>::CONTROLPOINT);
233  emit updatedObject( objectId, UPDATE_ALL );
234  } else if(_action == renderKnotSelectionAction_) {
235  bsplineSurfaceObject->splineSurfaceNode()->set_selection_draw_mode(ACG::SceneGraph::BSplineSurfaceNodeT<BSplineSurface>::KNOTVECTOR);
236  emit updatedObject( objectId, UPDATE_ALL );
237  } else if(_action == renderNoSelectionAction_) {
238  bsplineSurfaceObject->splineSurfaceNode()->set_selection_draw_mode(ACG::SceneGraph::BSplineSurfaceNodeT<BSplineSurface>::NONE);
239  emit updatedObject( objectId, UPDATE_ALL );
240 
241  }
242  }
243 }
244 
245 //-----------------------------------------------------------------------------
246 
247 bool
248 TypeBSplineSurfacePlugin::
249 registerType()
250 {
251  addDataType("BSplineSurface",tr("B-Spline Surface"));
252  setTypeIcon("BSplineSurface", "BSplineSurfaceType.png");
253  return true;
254 }
255 
256 //-----------------------------------------------------------------------------
257 
258 DataType
261 {
263  return type;
264 }
265 
266 //-----------------------------------------------------------------------------
267 
268 int
271 {
272  // new object data struct
274 
275  if ( OpenFlipperSettings().value("Core/File/AllTarget",false).toBool() )
276  object->target(true);
277  else {
278 
279  // Only the first object in the scene will be target
280  if ( PluginFunctions::objectCount() == 1 )
281  object->target(true);
282 
283  // If no target is available, we set the new object as target
284  if (PluginFunctions::targetCount() == 0 )
285  object->target(true);
286  }
287 
288  QString name = "BSplineSurface_" + QString::number( object->id() ) + ".bss";
289 
290  // call the local function to update names
291  QFileInfo f(name);
292  object->setName( f.fileName() );
293 
294  // set the default colors
295  const QColor color = OpenFlipper::Options::defaultColor();
296  const ACG::Vec4f default_color(color.redF(), color.greenF(), color.blueF(), color.alphaF());
297  object->materialNode()->set_color(default_color);
298 
299  object->update();
300 
301  object->show();
302 
303  emit log(LOGINFO,object->getObjectinfo());
304 
305  emit emptyObjectAdded (object->id() );
306 
307  return object->id();
308 }
309 
310 //-----------------------------------------------------------------------------
311 
312 #if QT_VERSION < 0x050000
313  Q_EXPORT_PLUGIN2( typebsplinesurfaceplugin , TypeBSplineSurfacePlugin );
314 #endif
315 
316 
DLLEXPORT OpenFlipperQSettings & OpenFlipperSettings()
QSettings object containing all program settings of OpenFlipper.
void slotRenderControlNet()
Slot triggered from context menu, if the control net should be rendered.
QAction * renderControlNetAction_
Context menu action.
DLLEXPORT void setTypeIcon(DataType _id, QString _icon)
Set an Icon for a given DataType.
Definition: Types.cc:234
int targetCount()
Get the number of target objects.
void slotUpdateContextMenu(int _objectId)
QString name()
Return a name for the plugin.
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.
DLLEXPORT DataType addDataType(QString _name, QString _readableName)
Adds a datatype and returns the id for the new type.
Definition: Types.cc:128
DataType supportedType()
Return your supported object type( e.g. DATA_TRIANGLE_MESH )
void slotRenderSelection(QAction *_action)
Slot triggered from context menu, if the selection rendering should be altered.
void slotRenderSurface()
Slot triggered from context menu, if the surface should be rendered.
int addEmpty()
Create an empty object.
ACG::SceneGraph::BSplineSurfaceNodeT< BSplineSurface > * splineSurfaceNode()
Return pointer to the bspline surface node.
QAction * renderSurfaceAction_
Context menu action.
#define DATA_BSPLINE_SURFACE
void pluginsInitialized()
Second initialization phase.
The Menu will be shown when an object was picked.
int objectCount()
Get the number of available objects.
Predefined datatypes.
Definition: DataTypes.hh:96
QString getObjectinfo()
Get all Info for the Object as a string.
QAction * renderCPSelectionAction_
Context menu action (render selection texture)
int id() const
Definition: BaseObject.cc:201