MaterialPicker.hh 6.67 KB
Newer Older
Isaak Lim's avatar
Isaak Lim committed
1 2 3
/*===========================================================================*\
*                                                                            *
*                              OpenFlipper                                   *
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
 *           Copyright (c) 2001-2015, RWTH-Aachen University                 *
 *           Department of Computer Graphics and Multimedia                  *
 *                          All rights reserved.                             *
 *                            www.openflipper.org                            *
 *                                                                           *
 *---------------------------------------------------------------------------*
 * This file is part of OpenFlipper.                                         *
 *---------------------------------------------------------------------------*
 *                                                                           *
 * Redistribution and use in source and binary forms, with or without        *
 * modification, are permitted provided that the following conditions        *
 * are met:                                                                  *
 *                                                                           *
 * 1. Redistributions of source code must retain the above copyright notice, *
 *    this list of conditions and the following disclaimer.                  *
 *                                                                           *
 * 2. Redistributions in binary form must reproduce the above copyright      *
 *    notice, this list of conditions and the following disclaimer in the    *
 *    documentation and/or other materials provided with the distribution.   *
 *                                                                           *
 * 3. Neither the name of the copyright holder nor the names of its          *
 *    contributors may be used to endorse or promote products derived from   *
 *    this software without specific prior written permission.               *
 *                                                                           *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS       *
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A           *
 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,  *
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,       *
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR        *
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF    *
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING      *
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS        *
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.              *
Isaak Lim's avatar
Isaak Lim committed
39 40 41
*                                                                            *
\*===========================================================================*/

Jan Möbius's avatar
Jan Möbius committed
42

Isaak Lim's avatar
Isaak Lim committed
43 44 45 46 47 48

#ifndef MATERIALPICKER_HH
#define MATERIALPICKER_HH

#include <QObject>
#include <QString>
49 50
#include <QPushButton>
#include <QListWidget>
Isaak Lim's avatar
Isaak Lim committed
51 52 53 54 55

#include <OpenFlipper/BasePlugin/BaseInterface.hh>
#include <OpenFlipper/BasePlugin/MouseInterface.hh>
#include <OpenFlipper/BasePlugin/PickingInterface.hh>
#include <OpenFlipper/BasePlugin/ToolboxInterface.hh>
56
#include <OpenFlipper/BasePlugin/KeyInterface.hh>
Isaak Lim's avatar
Isaak Lim committed
57 58

#include <OpenFlipper/common/Types.hh>
Matthias Möller's avatar
Matthias Möller committed
59
#include <ACG/Utils/SmartPointer.hh>
Isaak Lim's avatar
Isaak Lim committed
60 61


62
class MaterialPicker : public QObject, BaseInterface, MouseInterface, PickingInterface, ToolboxInterface, KeyInterface
Isaak Lim's avatar
Isaak Lim committed
63 64 65 66 67 68
{
  Q_OBJECT
  Q_INTERFACES(BaseInterface)
  Q_INTERFACES(MouseInterface)
  Q_INTERFACES(PickingInterface)
  Q_INTERFACES(ToolboxInterface)
69
  Q_INTERFACES(KeyInterface)
Isaak Lim's avatar
Isaak Lim committed
70

71 72
  Q_PLUGIN_METADATA(IID "org.OpenFlipper.Plugins.Plugin-MaterialPicker")

Isaak Lim's avatar
Isaak Lim committed
73 74 75 76 77
signals:
  void addPickMode(const std::string &_mode);

  void updateView();

78
  void addToolbox( QString  _name  , QWidget* _widget, QIcon* _icon);
Isaak Lim's avatar
Isaak Lim committed
79

80 81
  void registerKey(int _key, Qt::KeyboardModifiers _modifiers, QString _description, bool _multiUse = false);

Isaak Lim's avatar
Isaak Lim committed
82 83 84 85 86 87
public slots:

  void slotMouseEvent(QMouseEvent* _event);

  void slotPickModeChanged(const std::string& _mode);

88 89
  void slotKeyEvent (QKeyEvent* _event);

Isaak Lim's avatar
Isaak Lim committed
90 91 92 93 94 95 96 97 98 99
public:

  MaterialPicker();
  ~MaterialPicker();

  QString name(){return QString("MaterialPicker");}
  QString description(){return QString("Pick to store and set materials.");}

private:

100 101 102 103 104 105 106 107 108
  struct MaterialInfo
  {
     bool color_material;
     ACG::Vec4f base_color;
     ACG::Vec4f ambient_color;
     ACG::Vec4f diffuse_color;
     ACG::Vec4f specular_color;
     float shininess;
     double reflectance;
Matthias Möller's avatar
Matthias Möller committed
109
     int key;
110 111
  };

Isaak Lim's avatar
Isaak Lim committed
112
  const std::string pickModeName_;
113
  const QString propName_;
Matthias Möller's avatar
Matthias Möller committed
114
  static const unsigned supportedKeys_ = 3;
Isaak Lim's avatar
Isaak Lim committed
115 116 117 118

  QPushButton* pickMaterialButton_;
  QPushButton* fillMaterialButton_;

Matthias Möller's avatar
Matthias Möller committed
119 120
  //all these lists are synchronized:
  QListWidget* materialListWidget_;
Isaak Lim's avatar
Isaak Lim committed
121
  QVector<MaterialInfo> materialList_;
Matthias Möller's avatar
Matthias Möller committed
122 123 124
  QStringList materialStrings_;//hold materials as a String (saves/load the material at the beginning)

  //key = hotKey, value = index for lists
125
  std::map<int,size_t> shortKeyRow_;
Isaak Lim's avatar
Isaak Lim committed
126

Matthias Möller's avatar
Matthias Möller committed
127 128
  ptr::shared_ptr<MaterialNode> materialNode_;

Isaak Lim's avatar
Isaak Lim committed
129 130 131 132 133
  /// stores the state of the pick material button
  bool pickMaterial_;
  /// stores the state of the fill material button
  bool fillMaterial_;

Matthias Möller's avatar
Matthias Möller committed
134
private:
Matthias Möller's avatar
Matthias Möller committed
135
  /// returns the item name with hotkey hint
Matthias Möller's avatar
Matthias Möller committed
136 137
  QString itemName(const QString &_name, int _key);

Matthias Möller's avatar
Matthias Möller committed
138 139 140
  /// returns the plain name of the material without hotkey hint
  QString plainName(const QString &string, int index);

Isaak Lim's avatar
Isaak Lim committed
141 142 143 144 145 146 147 148 149 150
private slots:

  void initializePlugin();

  void pluginsInitialized();

  void slotPickMaterialMode();

  void slotFillMaterialMode();

151 152
  void slotRemoveCurrentItem();

Isaak Lim's avatar
Isaak Lim committed
153 154 155
  /// items can be renamed by double clicking them
  void editMode(QListWidgetItem* _item);

Matthias Möller's avatar
Matthias Möller committed
156 157 158 159 160 161 162 163
  void editModeCurrent();

  /// saves the new material name with hotkey hint
  void saveNewName ( QWidget * _editor, QAbstractItemDelegate::EndEditHint _hint );
  void saveNewName (QListWidgetItem* _item);

  /// returns a formatted string for saving
  QString materialString(const MaterialInfo& _mat, const QString &_name);
164

Isaak Lim's avatar
Isaak Lim committed
165 166
  void clearList();

167 168
  void removeItem(QListWidgetItem* _item);

Matthias Möller's avatar
Matthias Möller committed
169 170 171 172
  /// creates context menu on current item (current is the item at mouse position)
  void createContextMenu(const QPoint& _point);

  /// change specified HotKey to current item
173
  void changeHotKey(const int _key);
Matthias Möller's avatar
Matthias Möller committed
174 175 176 177 178

  void slotMaterialProperties();

  void slotEnableListWidget(int _save);

179
  void slotMaterialChanged();
Matthias Möller's avatar
Matthias Möller committed
180

Isaak Lim's avatar
Isaak Lim committed
181 182 183 184 185 186
public slots:
  QString version(){ return QString("1.0"); }
};


#endif //MATERIALPICKER_HH