Developer Documentation
Loading...
Searching...
No Matches
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
45const char *SPLIT_COMPONENTS = "SplitComponents";
46const char *BIGGEST_COMPONENT = "ComponentsPluginBiggestComponent";
47
48//------------------------------------------------------------------------------
49
54 splitAction_(NULL),
55 biggestAction_(NULL){}
56
57/*******************************************************************************
58 BaseInterface implementation
59 *******************************************************************************/
60
66
67
68//------------------------------------------------------------------------------
69
74{
75
76 if ( ! OpenFlipper::Options::gui())
77 return;
78
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
112void 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
125void 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
141{
142 PluginFunctions::actionMode( Viewer::PickingMode );
143 PluginFunctions::pickMode( SPLIT_COMPONENTS );
144}
145
146
147//------------------------------------------------------------------------------
148
153void 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
161 _event->pos(),
162 node_idx,
163 target_idx,
164 sourcePoint3D))
165 {
166 BaseObjectData *obj;
168 splitComponents( obj->id() );
169 }
170 }
171}
172
173
175{
176 PluginFunctions::actionMode( Viewer::PickingMode );
177 PluginFunctions::pickMode( BIGGEST_COMPONENT );
178}
179
180void 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
188 _event->pos(),
189 node_idx,
190 target_idx,
191 sourcePoint3D))
192 {
193 BaseObjectData *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
@ LOGERR
int id() const
void biggestComponent(QMouseEvent *_event)
Split into Components Button was hit.
void initializePlugin()
Initialize the plugin.
void slotSplitComponentsButton()
Split into Components Button was hit.
void pluginsInitialized()
Second initialization phase.
QAction * biggestAction_
Split into Components Button was hit.
void slotPickModeChanged(const std::string &_mode)
the pickMode changed
QAction * splitAction_
Split into Components Button was hit.
ComponentsPlugin()
Constructor.
void setDescriptions()
set scripting slot descriptions
void slotMouseEvent(QMouseEvent *_event)
a mouse event occured
void slotBiggestComponentButton()
Split into Components Button was hit.
void splitComponents(QMouseEvent *_event)
Split Components of picked object.
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.
@ PICK_FACE
picks faces (should be implemented for all nodes)
Definition PickTarget.hh:78
const std::string pickMode()
Get the current Picking mode.
bool getPickedObject(const size_t _node_idx, BaseObjectData *&_object)
Get the picked mesh.
bool scenegraphPick(ACG::SceneGraph::PickTarget _pickTarget, const QPoint &_mousePos, size_t &_nodeIdx, size_t &_targetIdx, ACG::Vec3d *_hitPointPtr=0)
Execute picking operation on scenegraph.
Viewer::ActionMode actionMode()
Get the current Action mode.