ATLAS Offline Software
VP1ExtraInputSystem.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 #include "ui_extrainputcontrollerform.h"
7 
9 #include "VP1Base/VP1Serialise.h"
10 #include "VP1Base/VP1Deserialise.h"
11 #include "VP1Base/VP1Settings.h"
12 
13 #include <Inventor/nodes/SoSeparator.h>
14 #include <Inventor/nodes/SoPickStyle.h>
15 #include <Inventor/nodes/SoLightModel.h>
16 #include <Inventor/nodes/SoMaterial.h>
17 #include <Inventor/nodes/SoSwitch.h>
18 
19 #include <QFileDialog>
20 #include <QDir>
21 #include <map>
22 
24 
25 public:
26 
27  SoSeparator *root = nullptr;
28  SoSwitch *visibilitySwitch = nullptr;
29  SoLightModel *lightModel = nullptr;
30  SoMaterial *material = nullptr;
31  SoPickStyle *pickStyle = nullptr;
32 
33  std::map<std::string, SoSeparator *> fileMap;
34  Ui::ExtraInputControllerForm ui{};
35  QString lastInputDir;
36  void inputFile(const VP1ExtraInputSystem *This, const QString &);
37 
38 };
39 
40 
42  IVP13DSystemSimple("ExtraInput","Co-display extra input from an external Open Inventor, or VRML, file","boudreau@pitt.edu"),
43  m_c(new Clockwork())
44 {
45  m_c->root=NULL;
46  m_c->visibilitySwitch = 0;
47  m_c->lightModel = 0;
48  m_c->material = 0;
49  m_c->pickStyle = 0;
50  m_c->ui.materialButton=0;
52 }
53 
55  delete m_c;
56 }
57 
59 
60  QWidget* controller = new QWidget(0);
61  m_c->ui.setupUi(controller);
62  m_c->ui.materialButton->setMaterial(m_c->material);
63  connect (m_c->ui.visibleCheckBox,SIGNAL(toggled(bool)), this, SLOT(toggleVisibility(bool)));
64  connect (m_c->ui.baseLMButton,SIGNAL(toggled(bool)), this, SLOT(toggleBaseLightModel(bool)));
65  connect (m_c->ui.newFilePushButton, SIGNAL(clicked()), this, SLOT(newFile()));
66  connect (m_c->ui.deleteFilePushButton, SIGNAL(clicked()), this, SLOT(deleteFile()));
67  return controller;
68 
69 
70 }
71 
72 
74  m_c->root=root;
75 
76  m_c->visibilitySwitch = new SoSwitch();
77  m_c->visibilitySwitch->ref();
78  toggleVisibility(m_c->ui.visibleCheckBox->isChecked());
79 
80  m_c->lightModel = new SoLightModel();
81  m_c->lightModel->ref();
82  toggleBaseLightModel(m_c->ui.baseLMButton->isChecked());
83  m_c->root->addChild(m_c->lightModel);
84 
85  m_c->material = new SoMaterial();
86  m_c->material->ref();
87  m_c->ui.materialButton->setMaterial(m_c->material);
88  m_c->root->addChild(m_c->material);
89 
90  m_c->pickStyle = new SoPickStyle();
91  m_c->pickStyle->ref();
92  m_c->pickStyle->style = SoPickStyleElement::UNPICKABLE;
93  m_c->root->addChild(m_c->pickStyle);
94 
95  m_c->root->addChild(m_c->visibilitySwitch);
96 
97 }
98 
100 {
101  if (m_c->visibilitySwitch)
102  m_c->visibilitySwitch->unref();
103  if (m_c->lightModel)
104  m_c->lightModel->unref();
105  if (m_c->material)
106  m_c->material->unref();
107  if (m_c->pickStyle)
108  m_c->pickStyle->unref();
109 }
110 
112 }
113 
114 
116  m_c->visibilitySwitch->whichChild = flag ? SO_SWITCH_ALL : SO_SWITCH_NONE;
117 }
118 
120  m_c->lightModel->model= flag ? SoLightModel::BASE_COLOR : SoLightModel::PHONG;
121 }
122 
124  QList<QListWidgetItem *> itemList = ui.fileListWidget->findItems(fileName,Qt::MatchExactly);
125  if (itemList.isEmpty()) {
126  SoSeparator *inputRoot = VP1QtInventorUtils::readGraphFromFile(fileName);
127  if (inputRoot) {
128  visibilitySwitch->addChild(inputRoot);
129  ui.fileListWidget->addItem(fileName);
130  fileMap[fileName.toStdString()]=inputRoot;
131  } else {
132  This->message("Warning: Could not get scenegraph from file "+fileName);
133  }
134  lastInputDir = QFileInfo(fileName).absolutePath();
135  } else {
136  This->message("Warning, file is already in the display list");
137  }
138 }
139 
141 
142  QString fileName = QFileDialog::getOpenFileName(NULL, tr("Open File"),m_c->lastInputDir,tr("3D Formats (*.iv *.wrl)"));
143  if (!fileName.isEmpty()) m_c->inputFile(this,fileName);
144 
145 }
146 
148  if (m_c->ui.fileListWidget->count()) {
149  int currentRow = m_c->ui.fileListWidget->currentRow();
150  QListWidgetItem *item=m_c->ui.fileListWidget->takeItem(currentRow);
151  m_c->visibilitySwitch->removeChild(m_c->fileMap[item->text().toStdString()]);
152  m_c->fileMap.erase(item->text().toStdString());
153  }
154 }
155 
157 
159 
160  VP1Serialise serialise(1/*version*/,this);
162 
163  serialise.save(m_c->ui.toolBox);
164 
165  QStringList fileListEntries;
166  for (int i=0;i<m_c->ui.fileListWidget->count();++i)
167  fileListEntries << m_c->ui.fileListWidget->item(i)->text();
168  serialise.save(fileListEntries);
169  serialise.widgetHandled(m_c->ui.fileListWidget);
170 
171  serialise.save(m_c->ui.baseLMButton,m_c->ui.phongLMButton);
172  serialise.save(m_c->ui.visibleCheckBox);
173  serialise.save(m_c->ui.materialButton);
174 
175  serialise.warnUnsaved(controllerWidget());
176  return serialise.result();
177 }
178 
180  VP1Deserialise state(ba,this);
181  if (state.version()==0) {
182  message("Warning: State data in .vp1 file has obsolete format - ignoring!");
183  return;
184  }
185  if (state.version()!=1) {
186  message("Warning: State data in .vp1 file is in wrong format - ignoring!");
187  return;
188  }
190  IVP13DSystemSimple::restoreFromState(state.restoreByteArray());
191 
192  state.restore(m_c->ui.toolBox);
193  for (const QString& fileName : state.restore<QStringList>())
194  m_c->inputFile(this,fileName);
195  state.restore(m_c->ui.baseLMButton,m_c->ui.phongLMButton);
196  state.restore(m_c->ui.visibleCheckBox);
197  state.restore(m_c->ui.materialButton);
198 
199  state.warnUnrestored(controllerWidget());
200 }
VP1Serialise.h
VP1Deserialise.h
VP1ExtraInputSystem::Clockwork::lastInputDir
QString lastInputDir
Definition: VP1ExtraInputSystem.cxx:35
VP1Serialise
Definition: VP1Serialise.h:45
IVP13DSystemSimple
Definition: IVP13DSystemSimple.h:24
RoiUtil::serialise
void serialise(const std::vector< const IRoiDescriptor * > &rois, roiserial_type &s)
serialise an entire vector of IRoiDescriptors
Definition: RoiSerialise.cxx:45
fillPileUpNoiseLumi.connect
string connect
Definition: fillPileUpNoiseLumi.py:70
CSV_InDetExporter.new
new
Definition: CSV_InDetExporter.py:145
VP1ExtraInputSystem::~VP1ExtraInputSystem
~VP1ExtraInputSystem()
Definition: VP1ExtraInputSystem.cxx:54
sendEI_SPB.root
root
Definition: sendEI_SPB.py:34
VP1ExtraInputSystem::VP1ExtraInputSystem
VP1ExtraInputSystem()
Definition: VP1ExtraInputSystem.cxx:41
VP1ExtraInputSystem::restoreFromState
void restoreFromState(QByteArray ba)
Definition: VP1ExtraInputSystem.cxx:179
IVP1System::state
State state() const
Definition: IVP1System.cxx:129
IVP1System::saveState
virtual QByteArray saveState()
Definition: IVP1System.cxx:294
VP1QtInventorUtils.h
VP1ExtraInputSystem::newFile
void newFile()
Definition: VP1ExtraInputSystem.cxx:140
VP1Settings.h
VP1ExtraInputSystem::Clockwork::ui
Ui::ExtraInputControllerForm ui
Definition: VP1ExtraInputSystem.cxx:34
StoreGateSvc
The Athena Transient Store API.
Definition: StoreGateSvc.h:125
FortranAlgorithmOptions.fileName
fileName
Definition: FortranAlgorithmOptions.py:13
VP1Settings::defaultFileSelectDirectory
static QString defaultFileSelectDirectory()
Definition: VP1Settings.cxx:22
lumiFormat.i
int i
Definition: lumiFormat.py:85
VP1ExtraInputSystem::buildController
QWidget * buildController()
Definition: VP1ExtraInputSystem.cxx:58
VP1ExtraInputSystem::m_c
Clockwork * m_c
Definition: VP1ExtraInputSystem.h:38
master.flag
bool flag
Definition: master.py:29
VP1ExtraInputSystem::systemuncreate
void systemuncreate()
Definition: VP1ExtraInputSystem.cxx:99
VP1ExtraInputSystem::Clockwork::fileMap
std::map< std::string, SoSeparator * > fileMap
Definition: VP1ExtraInputSystem.cxx:33
VP1ExtraInputSystem::toggleVisibility
void toggleVisibility(bool)
Definition: VP1ExtraInputSystem.cxx:115
VP1ExtraInputSystem::saveState
QByteArray saveState()
Definition: VP1ExtraInputSystem.cxx:156
IVP13DSystemSimple::ensureBuildController
void ensureBuildController()
Definition: IVP13DSystemSimple.cxx:90
VP1Deserialise
Definition: VP1Deserialise.h:44
VP1ExtraInputSystem::Clockwork::lightModel
SoLightModel * lightModel
Definition: VP1ExtraInputSystem.cxx:29
VP1ExtraInputSystem::Clockwork::material
SoMaterial * material
Definition: VP1ExtraInputSystem.cxx:30
VP1ExtraInputSystem::deleteFile
void deleteFile()
Definition: VP1ExtraInputSystem.cxx:147
item
Definition: ItemListSvc.h:43
VP1ExtraInputSystem::Clockwork::visibilitySwitch
SoSwitch * visibilitySwitch
Definition: VP1ExtraInputSystem.cxx:28
VP1QtInventorUtils::readGraphFromFile
static SoSeparator * readGraphFromFile(const QString &filename)
Definition: VP1QtInventorUtils.cxx:1447
VP1ExtraInputSystem::buildPermanentSceneGraph
void buildPermanentSceneGraph(StoreGateSvc *detstore, SoSeparator *root)
Definition: VP1ExtraInputSystem.cxx:73
VP1ExtraInputSystem::Clockwork::inputFile
void inputFile(const VP1ExtraInputSystem *This, const QString &)
Definition: VP1ExtraInputSystem.cxx:123
VP1ExtraInputSystem.h
VP1ExtraInputSystem
Definition: VP1ExtraInputSystem.h:11
VP1ExtraInputSystem::Clockwork
Definition: VP1ExtraInputSystem.cxx:23
VP1ExtraInputSystem::toggleBaseLightModel
void toggleBaseLightModel(bool)
Definition: VP1ExtraInputSystem.cxx:119
IVP1System::message
void message(const QString &) const
Definition: IVP1System.cxx:336
VP1ExtraInputSystem::buildEventSceneGraph
void buildEventSceneGraph(StoreGateSvc *sg, SoSeparator *root)
Definition: VP1ExtraInputSystem.cxx:111
VP1ExtraInputSystem::Clockwork::pickStyle
SoPickStyle * pickStyle
Definition: VP1ExtraInputSystem.cxx:31
IVP1System::controllerWidget
QWidget * controllerWidget()
Definition: IVP1System.cxx:202
IVP1System::restoreFromState
virtual void restoreFromState(QByteArray)
Definition: IVP1System.cxx:302
VP1ExtraInputSystem::Clockwork::root
SoSeparator * root
Definition: VP1ExtraInputSystem.cxx:27