ColorPlugin.cc 9.47 KB
Newer Older
Jan Möbius's avatar
Jan Möbius committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
//=============================================================================
//
//                               OpenFlipper
//        Copyright (C) 2008 by Computer Graphics Group, RWTH Aachen
//                           www.openflipper.org
//
//-----------------------------------------------------------------------------
//
//                                License
//
//  OpenFlipper is free software: you can redistribute it and/or modify
//  it under the terms of the GNU Lesser General Public License as published by
//  the Free Software Foundation, either version 3 of the License, or
//  (at your option) any later version.
// 
//  OpenFlipper is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU Lesser General Public License for more details.
// 
//  You should have received a copy of the GNU Lesser General Public License
//  along with OpenFlipper.  If not, see <http://www.gnu.org/licenses/>.
//
//-----------------------------------------------------------------------------
//
//   $Revision$
//   $Author$
//   $Date$
//
//=============================================================================
Jan Möbius's avatar
Jan Möbius committed
31

Jan Möbius's avatar
 
Jan Möbius committed
32
33
34
35
36
#include <QtGui>

#include "ColorPlugin.hh"

#include <iostream>
Jan Möbius's avatar
Jan Möbius committed
37
#include <ACG/GL/GLState.hh>
Jan Möbius's avatar
 
Jan Möbius committed
38
39
40
41
42
43

#include <OpenFlipper/BasePlugin/PluginFunctions.hh>
#include <OpenFlipper/common/GlobalOptions.hh>

void ColorPlugin::pluginsInitialized()
{
Jan Möbius's avatar
Jan Möbius committed
44
45
46
  // =============================================================================
  // Add a Menu for color selection
  // =============================================================================
Jan Möbius's avatar
 
Jan Möbius committed
47
48
49
  QMenu *colorMenu = new QMenu(tr("&Colors"));
  QIcon icon;
  icon.addFile(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"format-stroke-color.png");
Jan Möbius's avatar
Jan Möbius committed
50
  colorMenu->setIcon(icon);
Jan Möbius's avatar
 
Jan Möbius committed
51
  emit addMenu( colorMenu, VIEWMENU );
Jan Möbius's avatar
Jan Möbius committed
52

Jan Möbius's avatar
Jan Möbius committed
53
54
55
  // =============================================================================
  // Add Menu entries
  // =============================================================================
Jan Möbius's avatar
Jan Möbius committed
56

Jan Möbius's avatar
Jan Möbius committed
57
  QAction* AC_set_Default_color = new QAction(tr("&Default colors"), this);
Jan Möbius's avatar
 
Jan Möbius committed
58
59
  AC_set_Default_color->setStatusTip(tr("Set Default Colors"));
  AC_set_Default_color->setWhatsThis("Set colors to default colors");
Jan Möbius's avatar
Jan Möbius committed
60
  icon.addFile(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"color-default.png");
Jan Möbius's avatar
 
Jan Möbius committed
61
62
63
  AC_set_Default_color->setIcon(icon);
  connect(AC_set_Default_color, SIGNAL(triggered()), this, SLOT(setDefaultColor()));
  colorMenu->addAction(AC_set_Default_color);
Jan Möbius's avatar
Jan Möbius committed
64

Jan Möbius's avatar
Jan Möbius committed
65
  QAction* AC_set_Powerpoint_color = new QAction(tr("&Powerpoint colors"), this);
Jan Möbius's avatar
 
Jan Möbius committed
66
67
  AC_set_Powerpoint_color->setStatusTip(tr("Set Powerpoint Colors"));
  AC_set_Powerpoint_color->setWhatsThis("Set colors to Powerpoint presentation colors");
Jan Möbius's avatar
Jan Möbius committed
68
69
  icon.addFile(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"color-powerpoint.png");
  AC_set_Powerpoint_color->setIcon(icon);
Jan Möbius's avatar
 
Jan Möbius committed
70
71
  connect(AC_set_Powerpoint_color, SIGNAL(triggered()), this, SLOT(setPowerpointColor()));
  colorMenu->addAction(AC_set_Powerpoint_color);
Jan Möbius's avatar
Jan Möbius committed
72

Jan Möbius's avatar
Jan Möbius committed
73
  QAction* AC_set_Paper_color = new QAction(tr("&Paper colors"), this);
Jan Möbius's avatar
 
Jan Möbius committed
74
75
  AC_set_Paper_color->setStatusTip(tr("Set Paper Colors"));
  AC_set_Paper_color->setWhatsThis("Set colors to colors for papers");
Jan Möbius's avatar
Jan Möbius committed
76
  icon.addFile(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"color-paper.png");
Jan Möbius's avatar
 
Jan Möbius committed
77
78
79
  AC_set_Paper_color->setIcon(icon);
  connect(AC_set_Paper_color, SIGNAL(triggered()), this, SLOT(setPaperColor()));
  colorMenu->addAction(AC_set_Paper_color);
Jan Möbius's avatar
Jan Möbius committed
80

Jan Möbius's avatar
Jan Möbius committed
81
82
  // =============================================================================
  // Create symbol bar with same contents
Jan Möbius's avatar
Jan Möbius committed
83
84
  // =============================================================================

Jan Möbius's avatar
 
Jan Möbius committed
85
86
87
88
89
  QToolBar* toolbar = new QToolBar("Color Toolbar");
  toolbar->addAction(AC_set_Default_color);
  toolbar->addAction(AC_set_Powerpoint_color);
  toolbar->addAction(AC_set_Paper_color);
  emit addToolbar( toolbar );
Jan Möbius's avatar
Jan Möbius committed
90

Jan Möbius's avatar
 
Jan Möbius committed
91
92
93
}

void ColorPlugin::setDefaultColor() {
Jan Möbius's avatar
Jan Möbius committed
94

Jan Möbius's avatar
Jan Möbius committed
95
96
97
  // =============================================================================
  // Give user feedback
  // =============================================================================
Jan Möbius's avatar
 
Jan Möbius committed
98
99
  emit scriptInfo( "setDefaultColor()" );
  emit showStatusMessage( "Set to default Colors", 4000 );
Jan Möbius's avatar
Jan Möbius committed
100

Jan Möbius's avatar
Jan Möbius committed
101
102
  // =============================================================================
  // Define the new colors
Jan Möbius's avatar
Jan Möbius committed
103
104
  // =============================================================================
  OpenMesh::Vec4f back_color,
Jan Möbius's avatar
Jan Möbius committed
105
                  base_color,
Jan Möbius's avatar
Jan Möbius committed
106
107
                  ambient_color,
                  diffuse_color,
Jan Möbius's avatar
Jan Möbius committed
108
109
110
                  specular_color,
                  mat_color;
  float           line_width(1.0);
Jan Möbius's avatar
Jan Möbius committed
111

Jan Möbius's avatar
Jan Möbius committed
112
113
  back_color     = ACG::GLState::default_clear_color;
  base_color     = ACG::GLState::default_base_color;
Jan Möbius's avatar
 
Jan Möbius committed
114
  ambient_color  = ACG::GLState::default_ambient_color;
Jan Möbius's avatar
Jan Möbius committed
115
  diffuse_color  = ACG::GLState::default_diffuse_color;
Jan Möbius's avatar
 
Jan Möbius committed
116
117
  specular_color = ACG::GLState::default_specular_color;
  line_width     = 1.0;
Jan Möbius's avatar
Jan Möbius committed
118

Jan Möbius's avatar
Jan Möbius committed
119
  // Set background color
Jan Möbius's avatar
 
Jan Möbius committed
120
121
  PluginFunctions::setBackColor(back_color);

Jan Möbius's avatar
Jan Möbius committed
122
123
  // =============================================================================
  // Apply to all objects
Jan Möbius's avatar
Jan Möbius committed
124
  // =============================================================================
Jan Möbius's avatar
   
Jan Möbius committed
125
  for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS) ; o_it != PluginFunctions::objectsEnd(); ++o_it) {
Jan Möbius's avatar
 
Jan Möbius committed
126
127
128
129
130
    MaterialNode* mat = o_it->materialNode();
    mat->set_base_color(base_color);
    mat->set_ambient_color(ambient_color);
    mat->set_diffuse_color(diffuse_color);
    mat->set_specular_color(specular_color);
Jan Möbius's avatar
Jan Möbius committed
131
    mat->set_line_width(line_width);
Jan Möbius's avatar
 
Jan Möbius committed
132
  }
Jan Möbius's avatar
Jan Möbius committed
133

Jan Möbius's avatar
   
Jan Möbius committed
134
  emit updateView();
Jan Möbius's avatar
 
Jan Möbius committed
135
136
137
}

void ColorPlugin::setPowerpointColor() {
Jan Möbius's avatar
Jan Möbius committed
138

Jan Möbius's avatar
Jan Möbius committed
139
140
141
  // =============================================================================
  // Give user feedback
  // =============================================================================
Jan Möbius's avatar
 
Jan Möbius committed
142
143
  emit scriptInfo( "setPowerpointColor()" );
  emit showStatusMessage( "Set to Powerpoint Colors", 4000 );
Jan Möbius's avatar
Jan Möbius committed
144

Jan Möbius's avatar
Jan Möbius committed
145
146
  // =============================================================================
  // Define the new colors
Jan Möbius's avatar
Jan Möbius committed
147
148
149
150
151
  // =============================================================================
  OpenMesh::Vec4f back_color,
                  base_color,
                  ambient_color,
                  diffuse_color,
Jan Möbius's avatar
Jan Möbius committed
152
153
154
155
156
157
158
159
160
161
162
                  specular_color,
                  mat_color;
  float           line_width(1.0);

  back_color     = OpenMesh::Vec4f(0.0, 0.188, 0.062, 1.0);
  base_color     = OpenMesh::Vec4f(0.88, 0.88,  0.188, 1.0);
  mat_color      = OpenMesh::Vec4f(0.941, 0.439, 0.31, 1.0);
  ambient_color  = 0.2f * mat_color;
  diffuse_color  = 0.6f * mat_color;
  specular_color = 0.8f * mat_color;
  line_width     = 1.0;
Jan Möbius's avatar
Jan Möbius committed
163

Jan Möbius's avatar
Jan Möbius committed
164
165
  // Set background color
  PluginFunctions::setBackColor(back_color);
Jan Möbius's avatar
 
Jan Möbius committed
166

Jan Möbius's avatar
Jan Möbius committed
167
168
169
  // =============================================================================
  // Apply to all objects
  // =============================================================================
Jan Möbius's avatar
   
Jan Möbius committed
170
  for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS) ; o_it != PluginFunctions::objectsEnd(); ++o_it) {
Jan Möbius's avatar
Jan Möbius committed
171
172
173
174
175
    MaterialNode* mat = o_it->materialNode();
    mat->set_base_color(base_color);
    mat->set_ambient_color(ambient_color);
    mat->set_diffuse_color(diffuse_color);
    mat->set_specular_color(specular_color);
Jan Möbius's avatar
Jan Möbius committed
176
    mat->set_line_width(line_width);
Jan Möbius's avatar
Jan Möbius committed
177
  }
Jan Möbius's avatar
Jan Möbius committed
178

Jan Möbius's avatar
   
Jan Möbius committed
179
  emit updateView();
Jan Möbius's avatar
 
Jan Möbius committed
180
181
182
}

void ColorPlugin::setPaperColor() {
Jan Möbius's avatar
Jan Möbius committed
183

Jan Möbius's avatar
Jan Möbius committed
184
185
186
  // =============================================================================
  // Give user feedback
  // =============================================================================
Jan Möbius's avatar
 
Jan Möbius committed
187
188
  emit scriptInfo( "setPaperColor()" );
  emit showStatusMessage( "Set to Paper Colors", 4000 );
Jan Möbius's avatar
Jan Möbius committed
189

Jan Möbius's avatar
Jan Möbius committed
190
191
  // =============================================================================
  // Define the new colors
Jan Möbius's avatar
Jan Möbius committed
192
193
194
195
196
  // =============================================================================
  OpenMesh::Vec4f back_color,
                  base_color,
                  ambient_color,
                  diffuse_color,
Jan Möbius's avatar
Jan Möbius committed
197
198
                  specular_color,
                  mat_color;
Jan Möbius's avatar
 
Jan Möbius committed
199
  float     line_width(1.0);
Jan Möbius's avatar
Jan Möbius committed
200

Jan Möbius's avatar
Jan Möbius committed
201
202
203
204
205
206
207
  back_color     = OpenMesh::Vec4f(1.00, 1.00, 1.00, 1.0);
  base_color     = OpenMesh::Vec4f(0.00, 0.00, 0.00, 1.0);
  mat_color      = OpenMesh::Vec4f(0.12, 0.76, 0.62, 1.0);
  ambient_color  = 0.2f * mat_color;
  diffuse_color  = 0.5f * mat_color;
  specular_color = 0.8f * mat_color;
  line_width     = 2.0;
Jan Möbius's avatar
Jan Möbius committed
208

Jan Möbius's avatar
Jan Möbius committed
209
210
  // Set background color
  PluginFunctions::setBackColor(back_color);
Jan Möbius's avatar
Jan Möbius committed
211

Jan Möbius's avatar
Jan Möbius committed
212
213
214
  // =============================================================================
  // Apply to all objects
  // =============================================================================
Jan Möbius's avatar
   
Jan Möbius committed
215
  for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS) ; o_it != PluginFunctions::objectsEnd(); ++o_it) {
Jan Möbius's avatar
Jan Möbius committed
216
217
218
219
220
221
222
    MaterialNode* mat = o_it->materialNode();
    mat->set_base_color(base_color);
    mat->set_ambient_color(ambient_color);
    mat->set_diffuse_color(diffuse_color);
    mat->set_specular_color(specular_color);
    mat->set_line_width(line_width);
  }
Jan Möbius's avatar
Jan Möbius committed
223

Jan Möbius's avatar
   
Jan Möbius committed
224
  emit updateView();
Jan Möbius's avatar
 
Jan Möbius committed
225
226
227
228
229
}

//-----------------------------------------------------------------------------

void ColorPlugin::setBackgroundColor( Vector _color ) {
Jan Möbius's avatar
Jan Möbius committed
230
231
  emit scriptInfo( "setBackgroundColor()" );
  emit showStatusMessage( "Set background color", 4000 );
Jan Möbius's avatar
Jan Möbius committed
232

Jan Möbius's avatar
 
Jan Möbius committed
233
234
235
236
237
  ACG::Vec4f color;
  color[0] = _color[0];
  color[1] = _color[1];
  color[2] = _color[2];
  color[3] = 1.0;
Jan Möbius's avatar
Jan Möbius committed
238

Jan Möbius's avatar
 
Jan Möbius committed
239
240
241
242
243
244
  PluginFunctions::setBackColor(color);
}


Q_EXPORT_PLUGIN2( colorplugin , ColorPlugin );