ColorPlugin.cc 6 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
 
#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()
{
  // color menu
  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 );
  
  AC_set_Default_color = new QAction(tr("&Default colors"), this);;
  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);
  
  AC_set_Powerpoint_color = new QAction(tr("&Powerpoint colors"), this);;
  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);
  
  AC_set_Paper_color = new QAction(tr("&Paper colors"), this);;
  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);
  
  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() {
  
  emit scriptInfo( "setDefaultColor()" );
  
  emit showStatusMessage( "Set to default Colors", 4000 );
  
  OpenMesh::Vec4f  back_color, 
              base_color=OpenMesh::Vec4f(0.0,0.0,0.0,0.0), 
              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;
  ambient_color  = ACG::GLState::default_ambient_color;
  diffuse_color    = ACG::GLState::default_diffuse_color;
  specular_color = ACG::GLState::default_specular_color;
  line_width     = 1.0;
  
  PluginFunctions::setBackColor(back_color);

  // Force an update of 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();
}

void ColorPlugin::setPowerpointColor() {
  
  emit scriptInfo( "setPowerpointColor()" );
  
  emit showStatusMessage( "Set to Powerpoint Colors", 4000 );
  
   OpenMesh::Vec4f  back_color, 
              base_color=OpenMesh::Vec4f(0.0,0.0,0.0,0.0), 
              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;
  
   PluginFunctions::setBackColor(back_color);

   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::setPaperColor() {
  
  emit scriptInfo( "setPaperColor()" );
  
  emit showStatusMessage( "Set to Paper Colors", 4000 );
  
  OpenMesh::Vec4f  back_color, 
              base_color=OpenMesh::Vec4f(0.0,0.0,0.0,0.0), 
              ambient_color, 
              diffuse_color, 
              specular_color,
              mat_color;
  float     line_width(1.0);
  
   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;
  
   PluginFunctions::setBackColor(back_color);
   
   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::setBackgroundColor( Vector _color ) {
  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 );