Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
ComponentsPlugin.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 #include "ComponentsPlugin.hh"
51 
52 #if QT_VERSION >= 0x050000
53 #else
54 #include <QtGui>
55 #endif
56 
57 const char *SPLIT_COMPONENTS = "SplitComponents";
58 const char *BIGGEST_COMPONENT = "ComponentsPluginBiggestComponent";
59 
60 //------------------------------------------------------------------------------
61 
66  splitAction_(NULL),
67  biggestAction_(NULL){}
68 
69 /*******************************************************************************
70  BaseInterface implementation
71  *******************************************************************************/
72 
77 }
78 
79 
80 //------------------------------------------------------------------------------
81 
86 {
87 
88  if ( ! OpenFlipper::Options::gui())
89  return;
90 
92 
93  emit addPickMode( SPLIT_COMPONENTS );
94  emit addPickMode( BIGGEST_COMPONENT );
95 
96  // Add a scissor Toolbar
97  QToolBar* toolbar = new QToolBar("Components Toolbar");
98  //Split components
99  splitAction_ = new QAction(tr("&Split into components"), this);
100  splitAction_->setCheckable( true );
101  splitAction_->setStatusTip(tr("Clicked objects are splitted into components"));
102  splitAction_->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"components_split_components.png") );
103  connect(splitAction_, SIGNAL(triggered()), this, SLOT(slotSplitComponentsButton()) );
104  toolbar->addAction(splitAction_);
105 
106  biggestAction_ = new QAction(tr("&Get biggest component"), this);
107  biggestAction_->setCheckable( true );
108  biggestAction_->setStatusTip(tr("Get the biggest component of the clicked object and delete the other components."));
109  biggestAction_->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"components_biggest_component.png") );
110  connect(biggestAction_, SIGNAL(triggered()), this, SLOT(slotBiggestComponentButton()) );
111  toolbar->addAction(biggestAction_);
112 
113  emit addToolbar( toolbar );
114 }
115 
116 /*******************************************************************************
117  PickingInterface implementation
118  *******************************************************************************/
119 
124 void ComponentsPlugin::slotPickModeChanged( const std::string& _mode){
125  splitAction_->setChecked( _mode == SPLIT_COMPONENTS );
126  biggestAction_->setChecked( _mode == BIGGEST_COMPONENT );
127 }
128 
129 /*******************************************************************************
130  MouseInterface implementation
131  *******************************************************************************/
132 
137 void ComponentsPlugin::slotMouseEvent( QMouseEvent* _event )
138 {
139  if( PluginFunctions::pickMode() == SPLIT_COMPONENTS )
140  splitComponents( _event );
141  if (PluginFunctions::pickMode() == BIGGEST_COMPONENT)
142  biggestComponent( _event );
143 }
144 
145 /*******************************************************************************
146  ComponentsPlugin Implementation
147  *******************************************************************************/
148 
153 {
154  PluginFunctions::actionMode( Viewer::PickingMode );
155  PluginFunctions::pickMode( SPLIT_COMPONENTS );
156 }
157 
158 
159 //------------------------------------------------------------------------------
160 
165 void ComponentsPlugin::splitComponents(QMouseEvent * _event)
166 {
167  if (_event->type() == QEvent::MouseButtonPress )
168  {
169  unsigned int node_idx, target_idx;
170  ACG::Vec3d* sourcePoint3D = 0;
171 
173  _event->pos(),
174  node_idx,
175  target_idx,
176  sourcePoint3D))
177  {
178  BaseObjectData *obj;
179  PluginFunctions::getPickedObject(node_idx, obj);
180  splitComponents( obj->id() );
181  }
182  }
183 }
184 
185 
187 {
188  PluginFunctions::actionMode( Viewer::PickingMode );
189  PluginFunctions::pickMode( BIGGEST_COMPONENT );
190 }
191 
192 void ComponentsPlugin::biggestComponent(QMouseEvent* _event)
193 {
194  if (_event->type() == QEvent::MouseButtonPress )
195  {
196  unsigned int node_idx, target_idx;
197  ACG::Vec3d* sourcePoint3D = 0;
198 
200  _event->pos(),
201  node_idx,
202  target_idx,
203  sourcePoint3D))
204  {
205  BaseObjectData *obj;
206  PluginFunctions::getPickedObject(node_idx, obj);
207 
208  if (!obj)
209  {
210  emit log(LOGERR,tr("Unable to pick Object."));
211  return;
212  }
213 
214  biggestComponent(obj->id());
215 
216  emit createBackup(obj->id(),"GetBiggestComponents",UPDATE_ALL);
217  emit updatedObject( obj->id() , UPDATE_ALL );
218  }
219  }
220 }
221 
222 #if QT_VERSION < 0x050000
223 Q_EXPORT_PLUGIN2( componentsplugin, ComponentsPlugin );
224 #endif
void splitComponents(QMouseEvent *_event)
Split Components of picked object.
void slotSplitComponentsButton()
Split into Components Button was hit.
picks faces (should be implemented for all nodes)
Definition: BaseNode.hh:104
ComponentsPlugin()
Constructor.
void pluginsInitialized()
Second initialization phase.
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.
QAction * biggestAction_
Split into Components Button was hit.
void slotPickModeChanged(const std::string &_mode)
the pickMode changed
const std::string pickMode()
Get the current Picking mode.
QAction * splitAction_
Split into Components Button was hit.
void setDescriptions()
set scripting slot descriptions
void initializePlugin()
Initialize the plugin.
void slotBiggestComponentButton()
Split into Components Button was hit.
void slotMouseEvent(QMouseEvent *_event)
a mouse event occured
bool scenegraphPick(ACG::SceneGraph::PickTarget _pickTarget, const QPoint &_mousePos, unsigned int &_nodeIdx, unsigned int &_targetIdx, ACG::Vec3d *_hitPointPtr=0)
Execute picking operation on scenegraph.
Viewer::ActionMode actionMode()
Get the current Action mode.
bool getPickedObject(const unsigned int _node_idx, BaseObjectData *&_object)
Get the picked mesh.
int id() const
Definition: BaseObject.cc:201
void biggestComponent(QMouseEvent *_event)
Split into Components Button was hit.