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