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);
65 this->setToolTip(
"Sample the tool tip position");
74 toplayout->addWidget(
new QLabel(
"<b>Select coordinate system to sample in: </b>"));
75 toplayout->addWidget(mCoordinateSystemComboBox);
76 toplayout->addWidget(mToolComboBox);
77 toplayout->addWidget(mDataComboBox);
79 toplayout->addWidget(mSampleButton);
81 toplayout->addWidget(mSaveFileButton);
82 toplayout->addWidget(mSaveToFileNameLabel);
83 toplayout->addStretch();
85 connect(mSaveFileButton, SIGNAL(clicked()),
this, SLOT(saveFileSlot()));
86 connect(mSampleButton, SIGNAL(clicked()),
this, SLOT(sampleSlot()));
87 connect(mCoordinateSystems.get(), SIGNAL(changed()),
this, SLOT(coordinateSystemChanged()));
90 this->coordinateSystemChanged();
96 void ToolTipSampleWidget::saveFileSlot()
98 QString configPath =
profile()->getPath();
99 if(mServices->patient()->isPatientValid())
100 configPath = mServices->patient()->getActivePatientFolder();
102 QString fileName = QFileDialog::getSaveFileName(
this, tr(
"Save File"),
103 configPath+
"/SampledPoints.txt",
105 if(fileName.isEmpty())
107 else if(QFile::exists(fileName))
108 mTruncateFile =
true;
110 mSaveToFileNameLabel->setText(fileName);
113 void ToolTipSampleWidget::sampleSlot()
115 QFile samplingFile(mSaveToFileNameLabel->text());
117 CoordinateSystem to = this->getSelectedCoordinateSystem();
118 Vector3D toolPoint = mServices->spaceProvider()->getActiveToolTipPoint(to,
false);
120 if(!samplingFile.open(QIODevice::WriteOnly | (mTruncateFile ? QIODevice::Truncate : QIODevice::Append)))
129 mTruncateFile =
false;
134 QTextStream streamer(&samplingFile);
135 streamer << sampledPoint;
139 report(
"Sampled point in "+
qstring_cast(to.mId)+
" ("+to.mRefObject+
") space, result: "+sampledPoint);
142 void ToolTipSampleWidget::coordinateSystemChanged()
144 switch (string2enum<COORDINATE_SYSTEM>(mCoordinateSystems->getValue()))
147 mDataComboBox->show();
148 mToolComboBox->hide();
151 mToolComboBox->show();
152 mDataComboBox->hide();
155 mToolComboBox->show();
156 mDataComboBox->hide();
159 mDataComboBox->hide();
160 mToolComboBox->hide();
165 CoordinateSystem ToolTipSampleWidget::getSelectedCoordinateSystem()
167 CoordinateSystem retval(csCOUNT);
169 retval.mId = string2enum<COORDINATE_SYSTEM>(mCoordinateSystems->getValue());
174 retval = mServices->spaceProvider()->getD(mData->getData());
177 retval = mServices->spaceProvider()->getT(mTools->getTool());
180 retval = mServices->spaceProvider()->getT(mTools->getTool());
183 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 StringPropertySelectDataPtr New(PatientModelServicePtr patientModelService, QString typeRegexp=".*")
static StringPropertySelectCoordinateSystemPtr New(TrackingServicePtr trackingService)
void reportWarning(QString msg)
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.