34 #include <QPushButton>
35 #include <QTextStream>
36 #include <QFileDialog>
37 #include <QMessageBox>
56 BaseWidget(parent,
"ToolTipSampleWidget",
"ToolTip Sample"),
58 mSampleButton(new QPushButton(
"Sample")),
59 mSaveToFileNameLabel(new QLabel(
"<font color=red> No file selected </font>")),
60 mSaveFileButton(new QPushButton(
"Save to...")),
63 QVBoxLayout* toplayout =
new QVBoxLayout(
this);
73 toplayout->addWidget(
new QLabel(
"<b>Select coordinate system to sample in: </b>"));
74 toplayout->addWidget(mCoordinateSystemComboBox);
75 toplayout->addWidget(mToolComboBox);
76 toplayout->addWidget(mDataComboBox);
78 toplayout->addWidget(mSampleButton);
80 toplayout->addWidget(mSaveFileButton);
81 toplayout->addWidget(mSaveToFileNameLabel);
82 toplayout->addStretch();
84 connect(mSaveFileButton, SIGNAL(clicked()),
this, SLOT(saveFileSlot()));
85 connect(mSampleButton, SIGNAL(clicked()),
this, SLOT(sampleSlot()));
86 connect(mCoordinateSystems.get(), SIGNAL(changed()),
this, SLOT(coordinateSystemChanged()));
89 this->coordinateSystemChanged();
98 "<h3>Tool tip sampling.</h3>"
99 "<p>You can sample the active tools tooltip in any coordinate system and get the results written to file.</p>"
103 void ToolTipSampleWidget::saveFileSlot()
105 QString configPath =
profile()->getPath();
106 if(mServices->getPatientService()->isPatientValid())
107 configPath = mServices->getPatientService()->getActivePatientFolder();
109 QString fileName = QFileDialog::getSaveFileName(
this, tr(
"Save File"),
110 configPath+
"/SampledPoints.txt",
112 if(fileName.isEmpty())
114 else if(QFile::exists(fileName))
115 mTruncateFile =
true;
117 mSaveToFileNameLabel->setText(fileName);
120 void ToolTipSampleWidget::sampleSlot()
122 QFile samplingFile(mSaveToFileNameLabel->text());
124 CoordinateSystem to = this->getSelectedCoordinateSystem();
125 Vector3D toolPoint = mServices->getSpaceProvider()->getActiveToolTipPoint(to,
false);
127 if(!samplingFile.open(QIODevice::WriteOnly | (mTruncateFile ? QIODevice::Truncate : QIODevice::Append)))
136 mTruncateFile =
false;
141 QTextStream streamer(&samplingFile);
142 streamer << sampledPoint;
146 report(
"Sampled point in "+
qstring_cast(to.mId)+
" ("+to.mRefObject+
") space, result: "+sampledPoint);
149 void ToolTipSampleWidget::coordinateSystemChanged()
151 switch (string2enum<COORDINATE_SYSTEM>(mCoordinateSystems->getValue()))
154 mDataComboBox->show();
155 mToolComboBox->hide();
158 mToolComboBox->show();
159 mDataComboBox->hide();
162 mToolComboBox->show();
163 mDataComboBox->hide();
166 mDataComboBox->hide();
167 mToolComboBox->hide();
172 CoordinateSystem ToolTipSampleWidget::getSelectedCoordinateSystem()
174 CoordinateSystem retval(csCOUNT);
176 retval.mId = string2enum<COORDINATE_SYSTEM>(mCoordinateSystems->getValue());
181 retval = mServices->getSpaceProvider()->getD(mData->getData());
184 retval = mServices->getSpaceProvider()->getT(mTools->getTool());
187 retval = mServices->getSpaceProvider()->getT(mTools->getTool());
190 retval.mRefObject =
"";
QString qstring_cast(const T &val)
cxResource_EXPORT ProfilePtr profile()
boost::shared_ptr< class VisServices > VisServicesPtr
csSENSOR
a tools sensor space (s)
static StringPropertySelectCoordinateSystemPtr New(TrackingServicePtr trackingService)
void reportWarning(QString msg)
static StringPropertySelectDataPtr New(PatientModelServicePtr patientModelService)
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.