Developer Documentation

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 #include "ComponentsPlugin.hh"
43
44
45 const char *SPLIT_COMPONENTS = "SplitComponents";
46 const char *BIGGEST_COMPONENT = "ComponentsPluginBiggestComponent";
47
48 //------------------------------------------------------------------------------
49
53 ComponentsPlugin::ComponentsPlugin():
54 splitAction_(NULL),
55 biggestAction_(NULL){}
56
57 /*******************************************************************************
58 BaseInterface implementation
59 *******************************************************************************/
60
64 void ComponentsPlugin::initializePlugin() {
65 }
66
67
68 //------------------------------------------------------------------------------
69
73 void ComponentsPlugin::pluginsInitialized()
74 {
75
76 if ( ! OpenFlipper::Options::gui())
77 return;
78
79 setDescriptions();
80
81 emit addPickMode( SPLIT_COMPONENTS );
82 emit addPickMode( BIGGEST_COMPONENT );
83
84 // Add a scissor Toolbar
85 QToolBar* toolbar = new QToolBar("Components Toolbar");
86 //Split components
87 splitAction_ = new QAction(tr("&Split into components"), this);
88 splitAction_->setCheckable( true );
89 splitAction_->setStatusTip(tr("Clicked objects are splitted into components"));
90 splitAction_->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"components_split_components.png") );
91 connect(splitAction_, SIGNAL(triggered()), this, SLOT(slotSplitComponentsButton()) );
92 toolbar->addAction(splitAction_);
93
94 biggestAction_ = new QAction(tr("&Get biggest component"), this);
95 biggestAction_->setCheckable( true );
96 biggestAction_->setStatusTip(tr("Get the biggest component of the clicked object and delete the other components."));
97 biggestAction_->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"components_biggest_component.png") );
98 connect(biggestAction_, SIGNAL(triggered()), this, SLOT(slotBiggestComponentButton()) );
99 toolbar->addAction(biggestAction_);
100
101 emit addToolbar( toolbar );
102 }
103
104 /*******************************************************************************
105 PickingInterface implementation
106 *******************************************************************************/
107
112 void ComponentsPlugin::slotPickModeChanged( const std::string& _mode){
113 splitAction_->setChecked( _mode == SPLIT_COMPONENTS );
114 biggestAction_->setChecked( _mode == BIGGEST_COMPONENT );
115 }
116
117 /*******************************************************************************
118 MouseInterface implementation
119 *******************************************************************************/
120
125 void ComponentsPlugin::slotMouseEvent( QMouseEvent* _event )
126 {
127 if( PluginFunctions::pickMode() == SPLIT_COMPONENTS )
128 splitComponents( _event );
129 if (PluginFunctions::pickMode() == BIGGEST_COMPONENT)
130 biggestComponent( _event );
131 }
132
133 /*******************************************************************************
134 ComponentsPlugin Implementation
135 *******************************************************************************/
136
140 void ComponentsPlugin::slotSplitComponentsButton( )
141 {
142 PluginFunctions::actionMode( Viewer::PickingMode );
143 PluginFunctions::pickMode( SPLIT_COMPONENTS );
144 }
145
146
147 //------------------------------------------------------------------------------
148
153 void ComponentsPlugin::splitComponents(QMouseEvent * _event)
154 {
155 if (_event->type() == QEvent::MouseButtonPress )
156 {
157 size_t node_idx, target_idx;
158 ACG::Vec3d* sourcePoint3D = 0;
159
160 if (PluginFunctions::scenegraphPick(ACG::SceneGraph::PICK_FACE,
161 _event->pos(),
162 node_idx,
163 target_idx,
164 sourcePoint3D))
165 {
166 BaseObjectData *obj;
167 PluginFunctions::getPickedObject(node_idx, obj);
168 splitComponents( obj->id() );
169 }
170 }
171 }
172
173
174 void ComponentsPlugin::slotBiggestComponentButton()
175 {
176 PluginFunctions::actionMode( Viewer::PickingMode );
177 PluginFunctions::pickMode( BIGGEST_COMPONENT );
178 }
179
180 void ComponentsPlugin::biggestComponent(QMouseEvent* _event)
181 {
182 if (_event->type() == QEvent::MouseButtonPress )
183 {
184 size_t node_idx, target_idx;
185 ACG::Vec3d* sourcePoint3D = 0;
186
187 if (PluginFunctions::scenegraphPick(ACG::SceneGraph::PICK_FACE,
188 _event->pos(),
189 node_idx,
190 target_idx,
191 sourcePoint3D))
192 {
193 BaseObjectData *obj;
194 PluginFunctions::getPickedObject(node_idx, obj);
195
196 if (!obj)
197 {
198 emit log(LOGERR,tr("Unable to pick Object."));
199 return;
200 }
201
202 biggestComponent(obj->id());
203
204 emit createBackup(obj->id(),"GetBiggestComponents",UPDATE_ALL);
205 emit updatedObject( obj->id() , UPDATE_ALL );
206 }
207 }
208 }
209
PluginFunctions::scenegraphPick
bool scenegraphPick(ACG::SceneGraph::PickTarget _pickTarget, const QPoint &_mousePos, size_t &_nodeIdx, size_t &_targetIdx, ACG::Vec3d *_hitPointPtr=0)
Execute picking operation on scenegraph.
Definition: PluginFunctions.cc:480
LOGERR
Definition: LoggingInterface.hh:96
ComponentsPlugin::ComponentsPlugin
ComponentsPlugin()
Constructor.
Definition: ComponentsPlugin.cc:53
ComponentsPlugin::initializePlugin
void initializePlugin()
Initialize the plugin.
Definition: ComponentsPlugin.cc:64
UPDATE_ALL
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.
ACG::SceneGraph::PICK_FACE
picks faces (should be implemented for all nodes)
Definition: PickTarget.hh:78
ComponentsPlugin::biggestComponent
void biggestComponent(QMouseEvent *_event)
Split into Components Button was hit.
Definition: ComponentsPlugin.cc:180
ComponentsPlugin::splitComponents
void splitComponents(QMouseEvent *_event)
Split Components of picked object.
Definition: ComponentsPlugin.cc:153
OpenMesh::VectorT
Definition: Vector11T.hh:83
ComponentsPlugin::setDescriptions
void setDescriptions()
set scripting slot descriptions
Definition: ComponentsScripting.cc:51
BaseObject::id
int id() const
Definition: BaseObject.cc:190
ComponentsPlugin::biggestAction_
QAction * biggestAction_
Split into Components Button was hit.
Definition: ComponentsPlugin.hh:148
PluginFunctions::actionMode
Viewer::ActionMode actionMode()
Get the current Action mode.
Definition: PluginFunctions.cc:588
ComponentsPlugin::splitAction_
QAction * splitAction_
Split into Components Button was hit.
Definition: ComponentsPlugin.hh:147
ComponentsPlugin::slotMouseEvent
void slotMouseEvent(QMouseEvent *_event)
a mouse event occured
Definition: ComponentsPlugin.cc:125
ComponentsPlugin::slotPickModeChanged
void slotPickModeChanged(const std::string &_mode)
the pickMode changed
Definition: ComponentsPlugin.cc:112
ComponentsPlugin::slotSplitComponentsButton
void slotSplitComponentsButton()
Split into Components Button was hit.
Definition: ComponentsPlugin.cc:140
BaseObjectData
Definition: BaseObjectData.hh:102
PluginFunctions::pickMode
const std::string pickMode()
Get the current Picking mode.
Definition: PluginFunctions.cc:577
ComponentsPlugin::pluginsInitialized
void pluginsInitialized()
Second initialization phase.
Definition: ComponentsPlugin.cc:73
ComponentsPlugin::slotBiggestComponentButton
void slotBiggestComponentButton()
Split into Components Button was hit.
Definition: ComponentsPlugin.cc:174
PluginFunctions::getPickedObject
bool getPickedObject(const size_t _node_idx, BaseObjectData *&_object)
Get the picked mesh.
Definition: PluginFunctions.cc:261