ColorPlugin.cc 8.24 KB
Newer Older
Jan Möbius's avatar
Jan Möbius committed
1

Jan Möbius's avatar
 
Jan Möbius committed
2
3
4
5
6
#include <QtGui>

#include "ColorPlugin.hh"

#include <iostream>
Jan Möbius's avatar
Jan Möbius committed
7
#include <ACG/GL/GLState.hh>
Jan Möbius's avatar
 
Jan Möbius committed
8
9
10
11
12
13

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

void ColorPlugin::pluginsInitialized()
{
Jan Möbius's avatar
Jan Möbius committed
14
15
16
  // =============================================================================
  // Add a Menu for color selection
  // =============================================================================
Jan Möbius's avatar
 
Jan Möbius committed
17
18
19
  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
20
  colorMenu->setIcon(icon);
Jan Möbius's avatar
 
Jan Möbius committed
21
  emit addMenu( colorMenu, VIEWMENU );
Jan Möbius's avatar
Jan Möbius committed
22

Jan Möbius's avatar
Jan Möbius committed
23
24
25
  // =============================================================================
  // Add Menu entries
  // =============================================================================
Jan Möbius's avatar
Jan Möbius committed
26

Jan Möbius's avatar
Jan Möbius committed
27
  QAction* AC_set_Default_color = new QAction(tr("&Default colors"), this);
Jan Möbius's avatar
 
Jan Möbius committed
28
29
  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
30
  icon.addFile(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"color-default.png");
Jan Möbius's avatar
 
Jan Möbius committed
31
32
33
  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
34

Jan Möbius's avatar
Jan Möbius committed
35
  QAction* AC_set_Powerpoint_color = new QAction(tr("&Powerpoint colors"), this);
Jan Möbius's avatar
 
Jan Möbius committed
36
37
  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
38
39
  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
40
41
  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
42

Jan Möbius's avatar
Jan Möbius committed
43
  QAction* AC_set_Paper_color = new QAction(tr("&Paper colors"), this);
Jan Möbius's avatar
 
Jan Möbius committed
44
45
  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
46
  icon.addFile(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"color-paper.png");
Jan Möbius's avatar
 
Jan Möbius committed
47
48
49
  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
50

Jan Möbius's avatar
Jan Möbius committed
51
52
  // =============================================================================
  // Create symbol bar with same contents
Jan Möbius's avatar
Jan Möbius committed
53
54
  // =============================================================================

Jan Möbius's avatar
 
Jan Möbius committed
55
56
57
58
59
  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
60

Jan Möbius's avatar
 
Jan Möbius committed
61
62
63
}

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

Jan Möbius's avatar
Jan Möbius committed
65
66
67
  // =============================================================================
  // Give user feedback
  // =============================================================================
Jan Möbius's avatar
 
Jan Möbius committed
68
69
  emit scriptInfo( "setDefaultColor()" );
  emit showStatusMessage( "Set to default Colors", 4000 );
Jan Möbius's avatar
Jan Möbius committed
70

Jan Möbius's avatar
Jan Möbius committed
71
72
  // =============================================================================
  // Define the new colors
Jan Möbius's avatar
Jan Möbius committed
73
74
  // =============================================================================
  OpenMesh::Vec4f back_color,
Jan Möbius's avatar
Jan Möbius committed
75
                  base_color,
Jan Möbius's avatar
Jan Möbius committed
76
77
                  ambient_color,
                  diffuse_color,
Jan Möbius's avatar
Jan Möbius committed
78
79
80
                  specular_color,
                  mat_color;
  float           line_width(1.0);
Jan Möbius's avatar
Jan Möbius committed
81

Jan Möbius's avatar
Jan Möbius committed
82
83
  back_color     = ACG::GLState::default_clear_color;
  base_color     = ACG::GLState::default_base_color;
Jan Möbius's avatar
 
Jan Möbius committed
84
  ambient_color  = ACG::GLState::default_ambient_color;
Jan Möbius's avatar
Jan Möbius committed
85
  diffuse_color  = ACG::GLState::default_diffuse_color;
Jan Möbius's avatar
 
Jan Möbius committed
86
87
  specular_color = ACG::GLState::default_specular_color;
  line_width     = 1.0;
Jan Möbius's avatar
Jan Möbius committed
88

Jan Möbius's avatar
Jan Möbius committed
89
  // Set background color
Jan Möbius's avatar
 
Jan Möbius committed
90
91
  PluginFunctions::setBackColor(back_color);

Jan Möbius's avatar
Jan Möbius committed
92
93
  // =============================================================================
  // Apply to all objects
Jan Möbius's avatar
Jan Möbius committed
94
  // =============================================================================
Jan Möbius's avatar
 
Jan Möbius committed
95
96
97
98
99
100
  for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS) ; o_it != PluginFunctions::objects_end(); ++o_it) {
    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
101
    mat->set_line_width(line_width);
Jan Möbius's avatar
 
Jan Möbius committed
102
  }
Jan Möbius's avatar
Jan Möbius committed
103

Jan Möbius's avatar
 
Jan Möbius committed
104
105
106
107
  emit update_view();
}

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

Jan Möbius's avatar
Jan Möbius committed
109
110
111
  // =============================================================================
  // Give user feedback
  // =============================================================================
Jan Möbius's avatar
 
Jan Möbius committed
112
113
  emit scriptInfo( "setPowerpointColor()" );
  emit showStatusMessage( "Set to Powerpoint Colors", 4000 );
Jan Möbius's avatar
Jan Möbius committed
114

Jan Möbius's avatar
Jan Möbius committed
115
116
  // =============================================================================
  // Define the new colors
Jan Möbius's avatar
Jan Möbius committed
117
118
119
120
121
  // =============================================================================
  OpenMesh::Vec4f back_color,
                  base_color,
                  ambient_color,
                  diffuse_color,
Jan Möbius's avatar
Jan Möbius committed
122
123
124
125
126
127
128
129
130
131
132
                  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
133

Jan Möbius's avatar
Jan Möbius committed
134
135
  // Set background color
  PluginFunctions::setBackColor(back_color);
Jan Möbius's avatar
 
Jan Möbius committed
136

Jan Möbius's avatar
Jan Möbius committed
137
138
139
140
141
142
143
144
145
  // =============================================================================
  // Apply to all objects
  // =============================================================================
  for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS) ; o_it != PluginFunctions::objects_end(); ++o_it) {
    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
146
    mat->set_line_width(line_width);
Jan Möbius's avatar
Jan Möbius committed
147
  }
Jan Möbius's avatar
Jan Möbius committed
148

Jan Möbius's avatar
Jan Möbius committed
149
  emit update_view();
Jan Möbius's avatar
 
Jan Möbius committed
150
151
152
}

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

Jan Möbius's avatar
Jan Möbius committed
154
155
156
  // =============================================================================
  // Give user feedback
  // =============================================================================
Jan Möbius's avatar
 
Jan Möbius committed
157
158
  emit scriptInfo( "setPaperColor()" );
  emit showStatusMessage( "Set to Paper Colors", 4000 );
Jan Möbius's avatar
Jan Möbius committed
159

Jan Möbius's avatar
Jan Möbius committed
160
161
  // =============================================================================
  // Define the new colors
Jan Möbius's avatar
Jan Möbius committed
162
163
164
165
166
  // =============================================================================
  OpenMesh::Vec4f back_color,
                  base_color,
                  ambient_color,
                  diffuse_color,
Jan Möbius's avatar
Jan Möbius committed
167
168
                  specular_color,
                  mat_color;
Jan Möbius's avatar
 
Jan Möbius committed
169
  float     line_width(1.0);
Jan Möbius's avatar
Jan Möbius committed
170

Jan Möbius's avatar
Jan Möbius committed
171
172
173
174
175
176
177
  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
178

Jan Möbius's avatar
Jan Möbius committed
179
180
  // Set background color
  PluginFunctions::setBackColor(back_color);
Jan Möbius's avatar
Jan Möbius committed
181

Jan Möbius's avatar
Jan Möbius committed
182
183
184
185
186
187
188
189
190
191
192
  // =============================================================================
  // Apply to all objects
  // =============================================================================
  for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS) ; o_it != PluginFunctions::objects_end(); ++o_it) {
    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
193

Jan Möbius's avatar
Jan Möbius committed
194
  emit update_view();
Jan Möbius's avatar
 
Jan Möbius committed
195
196
197
198
199
}

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

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

Jan Möbius's avatar
 
Jan Möbius committed
203
204
205
206
207
  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
208

Jan Möbius's avatar
 
Jan Möbius committed
209
210
211
212
213
214
  PluginFunctions::setBackColor(color);
}


Q_EXPORT_PLUGIN2( colorplugin , ColorPlugin );