CMS 3D CMS Logo

IgMatEdMainWidget Class Reference

#include <Iguana/Controls/interface/IgMatEdMainWidget.h>

List of all members.

Public Slots

void createSoMaterial (void)
void fileMenuActivated (int item)
void newG4Material (QListViewItem *item)
void newMaterial (const QString &text)
void setCurrentG4Material (const QString &name)

Public Member Functions

 IgMatEdMainWidget (QWidget *parent, IgMatEdMainMenu *menu)
void saveMaterialMap (void)
void saveSoMaterials (void)
 ~IgMatEdMainWidget (void)

Public Attributes

QComboBox * m_comboBox
QListView * m_g4ListView
IgSoMaterialMapm_soMaterialMap

Private Attributes

IgMatEdColorBoxm_ambientColorBox
QHBox * m_colorBox
QPushButton * m_createMaterialButton
IgMatEdColorBoxm_diffuseColorBox
IgMatEdColorBoxm_emissiveColorBox
IgG4ToSoMaterialMapm_g4ToSoMap
QVBoxLayout * m_layout
QHBox * m_mainHBox
IgMatEdMainMenum_menu
QWidget * m_parent
SoSeparator * m_rootNode
IgMatEdSliderm_shininessSlider
QVBox * m_sliderBox
QHBox * m_soMaterialBox
IgMatEdColorBoxm_specularColorBox
IgMatEdSliderm_transparencySlider
IgMatEdViewerm_viewer


Detailed Description

Definition at line 33 of file IgMatEdMainWidget.h.


Constructor & Destructor Documentation

IgMatEdMainWidget::IgMatEdMainWidget ( QWidget *  parent,
IgMatEdMainMenu menu 
)

Definition at line 47 of file IgMatEdMainWidget.cc.

References ASSERT, IgSoMaterialMap::begin(), IgG4ToSoMaterialMap::begin(), HLT_VtxMuL3::connect, createSoMaterial(), IgG4ToSoMaterialMap::end(), IgSoMaterialMap::end(), fileMenuActivated(), i, IgG4ToSoMaterialMapSingleton::instance(), IgSoMaterialMapSingleton::instance(), IgMatEdModificationAction::m_ambientColor, m_ambientColorBox, m_colorBox, m_comboBox, m_createMaterialButton, IgMatEdModificationAction::m_diffuseColor, m_diffuseColorBox, IgMatEdModificationAction::m_emissiveColor, m_emissiveColorBox, IgMatEdMainMenu::m_fileMenu, m_g4ListView, m_g4ToSoMap, m_layout, m_mainHBox, m_menu, m_parent, m_rootNode, IgMatEdModificationAction::m_shininess, m_shininessSlider, m_sliderBox, m_soMaterialBox, m_soMaterialMap, IgMatEdModificationAction::m_specularColor, m_specularColorBox, IgMatEdModificationAction::m_transparency, m_transparencySlider, m_viewer, newG4Material(), newMaterial(), and TRUE.

00048     :QWidget (parent),
00049      m_parent (parent),
00050      m_g4ListView (0),
00051      m_menu (menu),
00052      m_layout (0),
00053      m_mainHBox (0),
00054      m_viewer (0),
00055      m_rootNode (0),
00056      m_sliderBox (0)
00057 {    
00058     ASSERT (m_parent);
00059 
00060     m_layout = new QVBoxLayout (this);    
00061     m_layout->setAutoAdd (TRUE);    
00062 
00063     m_mainHBox = new QHBox (this);
00064     m_mainHBox->setMargin(5);
00065     m_mainHBox->setSpacing(20);
00066     m_mainHBox->setEnabled (true);
00067     
00068     // Create a listview with all the materials
00069     m_g4ListView = new QListView (m_mainHBox);
00070     m_g4ListView->addColumn ("G4 material");    
00071     m_g4ListView->addColumn ("OIV material");    
00072 
00073     m_g4ToSoMap = IgG4ToSoMaterialMapSingleton::instance ();
00074 
00075     for (IgG4ToSoMaterialMap::MaterialMap::iterator i = m_g4ToSoMap->begin ();i != m_g4ToSoMap->end () ; i++)
00076     {
00077         QListViewItem *item = new QListViewItem (m_g4ListView);
00078         item->setText (0, i->first);
00079         item->setText (1, i->second);   
00080     }        
00081 
00082     m_soMaterialBox = new QHBox (this);
00083     m_soMaterialBox->setMargin (10);
00084     m_soMaterialBox->setSpacing (5);
00085 
00086     m_sliderBox = new QVBox (this);
00087 
00088     m_sliderBox->setMargin (10);
00089     m_sliderBox->setSpacing (5);    
00090     
00091     //Makes the sphere scenegraph.
00092     m_rootNode = new SoSeparator;
00093     m_rootNode->ref ();
00094 
00095     m_soMaterialMap = IgSoMaterialMapSingleton::instance ();
00096     
00097     ASSERT (m_soMaterialMap);
00098     ASSERT ((*m_soMaterialMap)["default"]);
00099     
00100     m_rootNode->insertChild ((*m_soMaterialMap)["default"], 0);
00101     m_rootNode->insertChild (new SoSphere, 1);
00102     
00103     m_colorBox = new QHBox (this);    
00104     
00105     m_createMaterialButton = new QPushButton ("Create material", m_soMaterialBox);    
00106     connect (m_createMaterialButton, SIGNAL (clicked()), this, SLOT (createSoMaterial()));
00107     
00108     m_comboBox = new QComboBox (m_soMaterialBox);
00109 
00110     for (IgSoMaterialMap::MaterialMap::iterator i = m_soMaterialMap->begin (); 
00111          i != m_soMaterialMap->end (); 
00112          i++)
00113     {
00114         m_comboBox->insertItem (i->first);      
00115     }
00116 
00117     connect (m_comboBox, SIGNAL (activated (const QString &)), this, SLOT (newMaterial (const QString &)));
00118     connect (m_comboBox, SIGNAL (highlighted (const QString &)), this, SLOT (newMaterial (const QString &)));
00119     connect (m_g4ListView, SIGNAL (selectionChanged (QListViewItem *)), this, SLOT (newG4Material (QListViewItem *)));
00120     
00121     if (m_menu != 0)
00122     {
00123         QPopupMenu *tmpMenu = m_menu->m_fileMenu;
00124         ASSERT (tmpMenu);    
00125         connect (tmpMenu, SIGNAL (activated (int)), this, SLOT (fileMenuActivated (int)));
00126     }
00127     
00128     m_shininessSlider = new IgMatEdSlider (m_sliderBox, "Shininess", &IgMatEdModificationAction::m_shininess, this);
00129     m_transparencySlider = new IgMatEdSlider (m_sliderBox, "Transparency", &IgMatEdModificationAction::m_transparency, this);
00130 
00131     m_diffuseColorBox = new IgMatEdColorBox (m_colorBox, "Diffuse", IgMatEdModificationAction::m_diffuseColor, this);
00132     m_ambientColorBox = new IgMatEdColorBox (m_colorBox, "Ambient", IgMatEdModificationAction::m_ambientColor, this);
00133     m_specularColorBox = new IgMatEdColorBox (m_colorBox, "Specular", IgMatEdModificationAction::m_specularColor, this);
00134     m_emissiveColorBox = new IgMatEdColorBox (m_colorBox, "Emissive", IgMatEdModificationAction::m_emissiveColor, this);
00135     
00136     // Use one of the convenient SoQt viewer classes.
00137     QHBox *dummyBox = new QHBox (m_mainHBox);
00138     QFrame *dummyFrame = new QFrame (dummyBox);
00139     dummyFrame->setMinimumSize (200,200);
00140     
00141     m_viewer = new IgMatEdViewer (dummyFrame, m_rootNode);
00142     m_g4ListView->show ();
00143     m_mainHBox->show ();
00144     m_g4ListView->setSelected (m_g4ListView->firstChild (), true);    
00145 }

IgMatEdMainWidget::~IgMatEdMainWidget ( void   ) 

Definition at line 147 of file IgMatEdMainWidget.cc.

References ASSERT, m_g4ListView, m_rootNode, and m_viewer.

00148 {
00149     ASSERT (m_viewer);
00150     ASSERT (m_rootNode);
00151     ASSERT (m_g4ListView);
00152     
00153     m_rootNode->unref (); 
00154     
00155     delete m_viewer;    
00156     delete m_g4ListView;    
00157 }


Member Function Documentation

void IgMatEdMainWidget::createSoMaterial ( void   )  [slot]

Definition at line 303 of file IgMatEdMainWidget.cc.

References IgSoMaterialMap::addEntry(), m_comboBox, m_soMaterialMap, and edm::Normal.

Referenced by IgMatEdMainWidget().

00304 {
00305     bool ok;    
00306     QString text = QInputDialog::getText (
00307         "Create new material", "Enter material name:", QLineEdit::Normal,
00308         QString::null, &ok, this );
00309     if (text != QString::null)
00310     {
00311         SoMaterial *entry= new SoMaterial;
00312         entry->ref ();
00313         entry->setName (text.ascii ());
00314 
00315         m_soMaterialMap->addEntry (text.ascii (), entry);       
00316         m_comboBox->insertItem (text);
00317     }    
00318 }

void IgMatEdMainWidget::fileMenuActivated ( int  item  )  [slot]

Definition at line 287 of file IgMatEdMainWidget.cc.

References IgMatEdMainMenu::LOAD_G4_MATERIAL_MAP, IgMatEdMainMenu::SAVE_G4_MATERIAL_MAP, IgMatEdMainMenu::SAVE_MATERIALS, saveMaterialMap(), and saveSoMaterials().

Referenced by IgMatEdMainWidget().

00288 {
00289     switch (item)
00290     {
00291     case IgMatEdMainMenu::SAVE_G4_MATERIAL_MAP:
00292         saveMaterialMap ();
00293         break;
00294     case IgMatEdMainMenu::LOAD_G4_MATERIAL_MAP:
00295         break;
00296     case IgMatEdMainMenu::SAVE_MATERIALS:
00297         saveSoMaterials ();     
00298         break;  
00299     }    
00300 }

void IgMatEdMainWidget::newG4Material ( QListViewItem *  item  )  [slot]

Definition at line 176 of file IgMatEdMainWidget.cc.

References TestMuL1L2Filter_cff::cerr, lat::endl(), m_comboBox, and newMaterial().

Referenced by IgMatEdMainWidget().

00177 {    
00178     std::cerr << "newG4Material called" << std::endl;    
00179     newMaterial (item->text (1));    
00180     m_comboBox->setCurrentText (item->text (1));    
00181 }

void IgMatEdMainWidget::newMaterial ( const QString &  text  )  [slot]

Definition at line 184 of file IgMatEdMainWidget.cc.

References IgSoMaterialMap::addEntry(), ASSERT, TestMuL1L2Filter_cff::cerr, lat::endl(), m_ambientColorBox, m_comboBox, m_diffuseColorBox, m_emissiveColorBox, m_g4ListView, m_rootNode, m_shininessSlider, m_soMaterialMap, m_specularColorBox, m_transparencySlider, IgMatEdColorBox::updatePosition(), IgMatEdSlider::updatePosition(), and warning.

Referenced by IgMatEdMainWidget(), and newG4Material().

00185 {
00186     std::cerr << "newMaterial called with argument " << text << std::endl;    
00187     ASSERT (m_soMaterialMap);
00188 
00189     if (text != QString::null)
00190     {
00191         /*Set the new name for the SoMaterial*/
00192         ASSERT (m_g4ListView);  
00193         ASSERT (m_comboBox);
00194         QListViewItem *item = m_g4ListView->selectedItem ();
00195         item->setText (1, text);        
00196 
00197         /*Updates the G4->So mapping map*/
00198         (*m_g4ToSoMap) [item->text (0).ascii ()] = text.ascii ();               
00199 
00200         /*Updates the display material using the selected one*/
00201         SoMaterial *m_selectedMaterial = (*m_soMaterialMap) [text.ascii ()];
00202 
00203         if (m_selectedMaterial == 0)
00204         {
00205             QMessageBox::warning (0, "Warning!", "Open Inventor material "+text+" not found. Using a default one for it.", "OK");
00206             m_selectedMaterial = new SoMaterial;
00207             m_soMaterialMap->addEntry (text.ascii (), m_selectedMaterial);
00208         }       
00209 
00210         ASSERT (m_selectedMaterial);
00211         m_rootNode->removeChild (0);
00212         m_rootNode->insertChild (m_selectedMaterial, 0);
00213         std::cerr << m_selectedMaterial->ambientColor[0][0] << " " << m_selectedMaterial->ambientColor[0][1] << " " << m_selectedMaterial->ambientColor[0][2] << std::endl;
00214         
00215         /*Updates the position of the sliders*/
00216         ASSERT (m_diffuseColorBox);
00217         ASSERT (m_ambientColorBox);
00218         ASSERT (m_specularColorBox);
00219         ASSERT (m_emissiveColorBox);
00220         ASSERT (m_transparencySlider);
00221         ASSERT (m_shininessSlider);
00222         
00223         m_diffuseColorBox->updatePosition (m_selectedMaterial->diffuseColor);    
00224         m_ambientColorBox->updatePosition (m_selectedMaterial->ambientColor);
00225         m_specularColorBox->updatePosition (m_selectedMaterial->specularColor);
00226         m_emissiveColorBox->updatePosition (m_selectedMaterial->emissiveColor);
00227         m_transparencySlider->updatePosition ((int) (m_selectedMaterial->transparency[0]*100));
00228         m_shininessSlider->updatePosition ((int) (m_selectedMaterial->shininess[0]*100));
00229     }
00230 }

void IgMatEdMainWidget::saveMaterialMap ( void   ) 

Definition at line 233 of file IgMatEdMainWidget.cc.

References lat::endl(), EgammaValidation_cff::filename, mergeAndRegister_online::fname, m_g4ListView, and output().

Referenced by VisG4TwigOps::actionAppearance(), and fileMenuActivated().

00234 {
00235     //Get material map name, use default one "material.map" if not set.
00236     std::string filename;
00237     char *fname = getenv ("MATERIAL_CONFIG");    
00238         
00239     if (fname == 0)
00240     {
00241         filename = "./materials.map";   
00242     }
00243     else
00244     {
00245         filename = fname;    
00246     }
00247     
00248     std::ofstream output;
00249     output.open (filename.c_str ());
00250 
00251     if (output)
00252     {
00253         QListViewItem *item = m_g4ListView->firstChild ();
00254     
00255         while (item!=0)
00256         {
00257             output << item->text (0) << "= " << item->text (1) << std::endl;
00258             item = item->nextSibling ();        
00259         }
00260         output.close();    
00261     }
00262 }

void IgMatEdMainWidget::saveSoMaterials ( void   ) 

Definition at line 265 of file IgMatEdMainWidget.cc.

References IgSoMaterialMap::begin(), IgSoMaterialMap::end(), EgammaValidation_cff::filename, fn, i, m_soMaterialMap, and out.

Referenced by VisG4TwigOps::actionAppearance(), and fileMenuActivated().

00266 {
00267     SoOutput out;
00268     std::string filename;
00269     
00270     char *fn = getenv ("SO_MATERIALS_IV");        
00271     if (!fn)
00272         filename = "./materials.iv";
00273     else
00274         filename = fn;
00275     
00276     out.openFile (filename.c_str ());
00277     SoWriteAction writer (&out);
00278     for (IgSoMaterialMap::MaterialMap::iterator i = m_soMaterialMap->begin (); 
00279          i != m_soMaterialMap->end (); 
00280          i++)
00281     {
00282         writer.apply (i->second);
00283     }
00284 }

void IgMatEdMainWidget::setCurrentG4Material ( const QString &  name  )  [slot]

Definition at line 160 of file IgMatEdMainWidget.cc.

References m_g4ListView.

Referenced by VisG4TwigOps::actionAppearance().

00161 {
00162     QListViewItem *item = m_g4ListView->findItem (name,0);
00163     //If the material name matches one of the list, then select it
00164     //in the list, otherwise create and select a new entry for it.
00165     if (!item)
00166     {
00167         item = new QListViewItem (m_g4ListView, name, "default");       
00168         m_g4ListView->insertItem (item);
00169         (*m_g4ToSoMap)[name.ascii ()] = "default";
00170     }    
00171     m_g4ListView->setCurrentItem (item);    
00172     m_g4ListView->ensureItemVisible (item);    
00173 }


Member Data Documentation

IgMatEdColorBox* IgMatEdMainWidget::m_ambientColorBox [private]

Definition at line 72 of file IgMatEdMainWidget.h.

Referenced by IgMatEdMainWidget(), and newMaterial().

QHBox* IgMatEdMainWidget::m_colorBox [private]

Definition at line 64 of file IgMatEdMainWidget.h.

Referenced by IgMatEdMainWidget().

QComboBox* IgMatEdMainWidget::m_comboBox

Definition at line 49 of file IgMatEdMainWidget.h.

Referenced by createSoMaterial(), IgMatEdMainWidget(), newG4Material(), newMaterial(), and IgMatEdSlider::updateValue().

QPushButton* IgMatEdMainWidget::m_createMaterialButton [private]

Definition at line 66 of file IgMatEdMainWidget.h.

Referenced by IgMatEdMainWidget().

IgMatEdColorBox* IgMatEdMainWidget::m_diffuseColorBox [private]

Definition at line 71 of file IgMatEdMainWidget.h.

Referenced by IgMatEdMainWidget(), and newMaterial().

IgMatEdColorBox* IgMatEdMainWidget::m_emissiveColorBox [private]

Definition at line 74 of file IgMatEdMainWidget.h.

Referenced by IgMatEdMainWidget(), and newMaterial().

QListView* IgMatEdMainWidget::m_g4ListView

Definition at line 50 of file IgMatEdMainWidget.h.

Referenced by IgMatEdMainWidget(), newMaterial(), saveMaterialMap(), setCurrentG4Material(), and ~IgMatEdMainWidget().

IgG4ToSoMaterialMap* IgMatEdMainWidget::m_g4ToSoMap [private]

Definition at line 67 of file IgMatEdMainWidget.h.

Referenced by IgMatEdMainWidget().

QVBoxLayout* IgMatEdMainWidget::m_layout [private]

Definition at line 59 of file IgMatEdMainWidget.h.

Referenced by IgMatEdMainWidget().

QHBox* IgMatEdMainWidget::m_mainHBox [private]

Definition at line 60 of file IgMatEdMainWidget.h.

Referenced by IgMatEdMainWidget().

IgMatEdMainMenu* IgMatEdMainWidget::m_menu [private]

Definition at line 58 of file IgMatEdMainWidget.h.

Referenced by IgMatEdMainWidget().

QWidget* IgMatEdMainWidget::m_parent [private]

Definition at line 37 of file IgMatEdMainWidget.h.

Referenced by IgMatEdMainWidget().

SoSeparator* IgMatEdMainWidget::m_rootNode [private]

Definition at line 62 of file IgMatEdMainWidget.h.

Referenced by IgMatEdMainWidget(), newMaterial(), and ~IgMatEdMainWidget().

IgMatEdSlider* IgMatEdMainWidget::m_shininessSlider [private]

Definition at line 68 of file IgMatEdMainWidget.h.

Referenced by IgMatEdMainWidget(), and newMaterial().

QVBox* IgMatEdMainWidget::m_sliderBox [private]

Definition at line 63 of file IgMatEdMainWidget.h.

Referenced by IgMatEdMainWidget().

QHBox* IgMatEdMainWidget::m_soMaterialBox [private]

Definition at line 65 of file IgMatEdMainWidget.h.

Referenced by IgMatEdMainWidget().

IgSoMaterialMap* IgMatEdMainWidget::m_soMaterialMap

Definition at line 48 of file IgMatEdMainWidget.h.

Referenced by createSoMaterial(), IgMatEdMainWidget(), newMaterial(), saveSoMaterials(), and IgMatEdSlider::updateValue().

IgMatEdColorBox* IgMatEdMainWidget::m_specularColorBox [private]

Definition at line 73 of file IgMatEdMainWidget.h.

Referenced by IgMatEdMainWidget(), and newMaterial().

IgMatEdSlider* IgMatEdMainWidget::m_transparencySlider [private]

Definition at line 69 of file IgMatEdMainWidget.h.

Referenced by IgMatEdMainWidget(), and newMaterial().

IgMatEdViewer* IgMatEdMainWidget::m_viewer [private]

Definition at line 61 of file IgMatEdMainWidget.h.

Referenced by IgMatEdMainWidget(), and ~IgMatEdMainWidget().


The documentation for this class was generated from the following files:
Generated on Tue Jun 9 18:25:12 2009 for CMSSW by  doxygen 1.5.4