ColorPlugin.cc 8.32 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
 
#include <QtGui>

#include "ColorPlugin.hh"

#include <iostream>
#include <ACG/GL/GLState.hh> 

#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
20
21
22
  QMenu *colorMenu = new QMenu(tr("&Colors"));
  QIcon icon;
  icon.addFile(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"format-stroke-color.png");
  colorMenu->setIcon(icon);  
  emit addMenu( colorMenu, VIEWMENU );
  
Jan Möbius's avatar
Jan Möbius committed
23
24
25
26
27
  // =============================================================================
  // Add Menu entries
  // =============================================================================
  
  QAction* AC_set_Default_color = new QAction(tr("&Default colors"), this);
Jan Möbius's avatar
 
Jan Möbius committed
28
29
30
31
32
33
34
  AC_set_Default_color->setStatusTip(tr("Set Default Colors"));
  AC_set_Default_color->setWhatsThis("Set colors to default colors");
  icon.addFile(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"flag.png");
  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
35
  QAction* AC_set_Powerpoint_color = new QAction(tr("&Powerpoint colors"), this);
Jan Möbius's avatar
 
Jan Möbius committed
36
37
38
39
40
41
42
  AC_set_Powerpoint_color->setStatusTip(tr("Set Powerpoint Colors"));
  AC_set_Powerpoint_color->setWhatsThis("Set colors to Powerpoint presentation colors");
  icon.addFile(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"video-projector.png");
  AC_set_Powerpoint_color->setIcon(icon);  
  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
43
  QAction* AC_set_Paper_color = new QAction(tr("&Paper colors"), this);
Jan Möbius's avatar
 
Jan Möbius committed
44
45
46
47
48
49
50
  AC_set_Paper_color->setStatusTip(tr("Set Paper Colors"));
  AC_set_Paper_color->setWhatsThis("Set colors to colors for papers");
  icon.addFile(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"view-pim-news.png");
  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
51
52
53
54
  // =============================================================================
  // Create symbol bar with same contents
  // =============================================================================  
  
Jan Möbius's avatar
 
Jan Möbius committed
55
56
57
58
59
60
61
62
63
64
  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 );
   
}

void ColorPlugin::setDefaultColor() {
  
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
70
  emit scriptInfo( "setDefaultColor()" );
  emit showStatusMessage( "Set to default Colors", 4000 );
  
Jan Möbius's avatar
Jan Möbius committed
71
72
73
74
75
76
77
78
79
80
81
82
83
  // =============================================================================
  // Define the new colors
  // =============================================================================    
  OpenMesh::Vec4f back_color, 
                  base_color,
                  ambient_color, 
                  diffuse_color, 
                  specular_color,
                  mat_color;
  float           line_width(1.0);
  
  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
88
  specular_color = ACG::GLState::default_specular_color;
  line_width     = 1.0;
  
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
94
  // =============================================================================
  // Apply to all objects
  // =============================================================================    
Jan Möbius's avatar
 
Jan Möbius committed
95
96
97
98
99
100
101
102
103
104
105
106
107
108
  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);       
  }
  
  emit update_view();
}

void ColorPlugin::setPowerpointColor() {
  
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
114
  emit scriptInfo( "setPowerpointColor()" );
  emit showStatusMessage( "Set to Powerpoint Colors", 4000 );
  
Jan Möbius's avatar
Jan Möbius committed
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
  // =============================================================================
  // Define the new colors
  // ============================================================================= 
  OpenMesh::Vec4f back_color, 
                  base_color, 
                  ambient_color, 
                  diffuse_color, 
                  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
146
147
148
149
  // =============================================================================
  // 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);      
  }
  
  emit update_view();
Jan Möbius's avatar
 
Jan Möbius committed
150
151
152
153
}

void ColorPlugin::setPaperColor() {
  
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
159
  emit scriptInfo( "setPaperColor()" );
  emit showStatusMessage( "Set to Paper Colors", 4000 );
  
Jan Möbius's avatar
Jan Möbius committed
160
161
162
163
164
165
166
167
168
  // =============================================================================
  // Define the new colors
  // ============================================================================= 
  OpenMesh::Vec4f back_color, 
                  base_color, 
                  ambient_color, 
                  diffuse_color, 
                  specular_color,
                  mat_color;
Jan Möbius's avatar
 
Jan Möbius committed
169
170
  float     line_width(1.0);
  
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
  // Set background color
  PluginFunctions::setBackColor(back_color);
    
  // =============================================================================
  // 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);
  }
  
  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
202
  emit scriptInfo( "setBackgroundColor()" );
  emit showStatusMessage( "Set background color", 4000 );
  
Jan Möbius's avatar
 
Jan Möbius committed
203
204
205
206
207
208
209
210
211
212
213
214
  ACG::Vec4f color;
  color[0] = _color[0];
  color[1] = _color[1];
  color[2] = _color[2];
  color[3] = 1.0;
  
  PluginFunctions::setBackColor(color);
}


Q_EXPORT_PLUGIN2( colorplugin , ColorPlugin );