DlgMaterialPropertiesImp.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "PreCompiled.h"
00025
00026 #include <App/PropertyStandard.h>
00027 #include <App/Material.h>
00028
00029 #include "DlgMaterialPropertiesImp.h"
00030 #include "Widgets.h"
00031 #include "SpinBox.h"
00032 #include "ViewProvider.h"
00033
00034 using namespace Gui::Dialog;
00035
00036
00037
00038
00046 DlgMaterialPropertiesImp::DlgMaterialPropertiesImp(const std::string& mat, QWidget* parent, Qt::WFlags fl)
00047 : QDialog(parent, fl), material(mat)
00048 {
00049 this->setupUi(this);
00050 if (material != "ShapeMaterial") {
00051 this->textLabel1->hide();
00052 this->diffuseColor->hide();
00053 }
00054
00055 ambientColor->setModal(false);
00056 diffuseColor->setModal(false);
00057 emissiveColor->setModal(false);
00058 specularColor->setModal(false);
00059 }
00060
00064 DlgMaterialPropertiesImp::~DlgMaterialPropertiesImp()
00065 {
00066 }
00067
00071 void DlgMaterialPropertiesImp::on_ambientColor_changed()
00072 {
00073 QColor col = ambientColor->color();
00074 float r = (float)col.red()/255.0f;
00075 float g = (float)col.green()/255.0f;
00076 float b = (float)col.blue()/255.0f;
00077 App::Color ambient(r,g,b);
00078
00079 for (std::vector<ViewProvider*>::iterator it= Objects.begin();it!=Objects.end();it++) {
00080 App::Property* prop = (*it)->getPropertyByName(material.c_str());
00081 if (prop && prop->getTypeId().isDerivedFrom(App::PropertyMaterial::getClassTypeId())) {
00082 App::PropertyMaterial* ShapeMaterial = (App::PropertyMaterial*)prop;
00083 App::Material mat = ShapeMaterial->getValue();
00084 mat.ambientColor = ambient;
00085 ShapeMaterial->setValue(mat);
00086 }
00087 }
00088 }
00089
00093 void DlgMaterialPropertiesImp::on_diffuseColor_changed()
00094 {
00095 QColor col = diffuseColor->color();
00096 float r = (float)col.red()/255.0f;
00097 float g = (float)col.green()/255.0f;
00098 float b = (float)col.blue()/255.0f;
00099 App::Color diffuse(r,g,b);
00100
00101 for (std::vector<ViewProvider*>::iterator it= Objects.begin();it!=Objects.end();it++) {
00102 App::Property* prop = (*it)->getPropertyByName(material.c_str());
00103 if (prop && prop->getTypeId().isDerivedFrom(App::PropertyMaterial::getClassTypeId())) {
00104 App::PropertyMaterial* ShapeMaterial = (App::PropertyMaterial*)prop;
00105 App::Material mat = ShapeMaterial->getValue();
00106 mat.diffuseColor = diffuse;
00107 ShapeMaterial->setValue(mat);
00108 }
00109 }
00110 }
00111
00115 void DlgMaterialPropertiesImp::on_emissiveColor_changed()
00116 {
00117 QColor col = emissiveColor->color();
00118 float r = (float)col.red()/255.0f;
00119 float g = (float)col.green()/255.0f;
00120 float b = (float)col.blue()/255.0f;
00121 App::Color emissive(r,g,b);
00122
00123 for (std::vector<ViewProvider*>::iterator it= Objects.begin();it!=Objects.end();it++) {
00124 App::Property* prop = (*it)->getPropertyByName(material.c_str());
00125 if (prop && prop->getTypeId().isDerivedFrom(App::PropertyMaterial::getClassTypeId())) {
00126 App::PropertyMaterial* ShapeMaterial = (App::PropertyMaterial*)prop;
00127 App::Material mat = ShapeMaterial->getValue();
00128 mat.emissiveColor = emissive;
00129 ShapeMaterial->setValue(mat);
00130 }
00131 }
00132 }
00133
00137 void DlgMaterialPropertiesImp::on_specularColor_changed()
00138 {
00139 QColor col = specularColor->color();
00140 float r = (float)col.red()/255.0f;
00141 float g = (float)col.green()/255.0f;
00142 float b = (float)col.blue()/255.0f;
00143 App::Color specular(r,g,b);
00144
00145 for (std::vector<ViewProvider*>::iterator it= Objects.begin();it!=Objects.end();it++) {
00146 App::Property* prop = (*it)->getPropertyByName(material.c_str());
00147 if (prop && prop->getTypeId().isDerivedFrom(App::PropertyMaterial::getClassTypeId())) {
00148 App::PropertyMaterial* ShapeMaterial = (App::PropertyMaterial*)prop;
00149 App::Material mat = ShapeMaterial->getValue();
00150 mat.specularColor = specular;
00151 ShapeMaterial->setValue(mat);
00152 }
00153 }
00154 }
00155
00159 void DlgMaterialPropertiesImp::on_shininess_valueChanged(int sh)
00160 {
00161 float shininess = (float)sh/100.0f;
00162 for (std::vector<ViewProvider*>::iterator it= Objects.begin();it!=Objects.end();it++) {
00163 App::Property* prop = (*it)->getPropertyByName(material.c_str());
00164 if (prop && prop->getTypeId().isDerivedFrom(App::PropertyMaterial::getClassTypeId())) {
00165 App::PropertyMaterial* ShapeMaterial = (App::PropertyMaterial*)prop;
00166 App::Material mat = ShapeMaterial->getValue();
00167 mat.shininess = shininess;
00168 ShapeMaterial->setValue(mat);
00169 }
00170 }
00171 }
00172
00176 void DlgMaterialPropertiesImp::setViewProviders(const std::vector<Gui::ViewProvider*>& Obj)
00177 {
00178 Objects = Obj;
00179
00180 for (std::vector<ViewProvider*>::iterator it= Objects.begin();it!=Objects.end();it++) {
00181 App::Property* prop = (*it)->getPropertyByName(material.c_str());
00182 if (prop && prop->getTypeId().isDerivedFrom(App::PropertyMaterial::getClassTypeId())) {
00183 App::PropertyMaterial* ShapeMaterial = (App::PropertyMaterial*)prop;
00184 App::Material mat = ShapeMaterial->getValue();
00185 int r = int(mat.ambientColor.r * 255.0f);
00186 int g = int(mat.ambientColor.g * 255.0f);
00187 int b = int(mat.ambientColor.b * 255.0f);
00188 ambientColor->setColor( QColor(r,g,b) );
00189 r = int(mat.diffuseColor.r * 255.0f);
00190 g = int(mat.diffuseColor.g * 255.0f);
00191 b = int(mat.diffuseColor.b * 255.0f);
00192 diffuseColor->setColor( QColor(r,g,b) );
00193 r = int(mat.emissiveColor.r * 255.0f);
00194 g = int(mat.emissiveColor.g * 255.0f);
00195 b = int(mat.emissiveColor.b * 255.0f);
00196 emissiveColor->setColor( QColor(r,g,b) );
00197 r = int(mat.specularColor.r * 255.0f);
00198 g = int(mat.specularColor.g * 255.0f);
00199 b = int(mat.specularColor.b * 255.0f);
00200 specularColor->setColor( QColor(r,g,b) );
00201 shininess->blockSignals(true);
00202 shininess->setValue((int)(100.0f * (mat.shininess+0.001f)));
00203 shininess->blockSignals(false);
00204 break;
00205 }
00206 }
00207 }
00208
00209 #include "moc_DlgMaterialPropertiesImp.cpp"