Skip to content

Commit eca6708

Browse files
committed
Closes #807
1 parent 297e3c9 commit eca6708

File tree

2 files changed

+49
-25
lines changed

2 files changed

+49
-25
lines changed

src/Core/Utils/Tests/TypeIDTableTests.cc

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,14 @@
2828

2929
#include <gtest/gtest.h>
3030
#include <boost/thread.hpp>
31+
#include <boost/lexical_cast.hpp>
32+
#include <boost/format.hpp>
3133

3234
#include <Core/Utils/TypeIDTable.h>
3335

3436
using namespace SCIRun::Core::Utility;
3537

36-
struct Dummy
38+
struct Dummy
3739
{
3840
int x;
3941
};
@@ -51,7 +53,7 @@ bool operator!=(const Dummy& x1, const Dummy& x2)
5153
TEST(TypeIDTableTests, CanConstructEmpty)
5254
{
5355
TypeIDTable<Dummy> table;
54-
56+
5557
auto ctor = table.findConstructorInfo("LatVolMesh");
5658

5759
EXPECT_FALSE(ctor);
@@ -133,3 +135,15 @@ TEST(TypeIDTableTests, MultithreadedAccessIsSafe)
133135

134136
EXPECT_EQ(1, trueCount);
135137
}
138+
139+
TEST(StringFormatting, NewWayMatchesOldWay)
140+
{
141+
double x = 3.14159265;
142+
char s[32];
143+
sprintf(s, "%8.4f", x);
144+
auto expected = boost::lexical_cast<std::string>(s);
145+
146+
auto actual = str(boost::format("%8.4f") % x);
147+
148+
EXPECT_EQ(expected, actual);
149+
}

src/Modules/Fields/EditMeshBoundingBox.cc

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include <Core/Datatypes/DenseMatrix.h>
3333
#include <Graphics/Glyphs/GlyphGeom.h>
3434
#include <Core/Datatypes/Color.h>
35+
#include <boost/format.hpp>
3536

3637
using namespace SCIRun;
3738
using namespace Modules::Fields;
@@ -167,17 +168,16 @@ EditMeshBoundingBox::EditMeshBoundingBox()
167168
void EditMeshBoundingBox::processWidgetFeedback(const ModuleFeedback& var)
168169
{
169170
auto vsf = static_cast<const ViewSceneFeedback&>(var);
170-
if (vsf.selectionName.find(get_id()) != std::string::npos)// && impl_->previousTransform_ != vsf.transform)
171+
if (vsf.selectionName.find(get_id()) != std::string::npos)
171172
{
172173
impl_->userWidgetTransform_ = vsf.transform;
173174
enqueueExecuteAgain();
174175
}
175-
176176
}
177177

178178
void EditMeshBoundingBox::createBoxWidget()
179179
{
180-
box_ = WidgetFactory::createBox(); //new BoxWidget(this, &widget_lock_, 1.0, false, false);
180+
box_ = WidgetFactory::createBox();
181181
box_->connect(getOutputPort(Transformation_Widget));
182182
}
183183

@@ -204,8 +204,8 @@ void EditMeshBoundingBox::setStateDefaults()
204204
state->setValue(XYZTranslation, false);
205205
state->setValue(RDITranslation, false);
206206
state->setValue(Resetting, false);
207-
208-
//TODO
207+
state->setValue(BoxRealScale, 0.0);
208+
state->setValue(BoxMode, 0);
209209

210210
createBoxWidget();
211211
setBoxRestrictions();
@@ -242,6 +242,14 @@ void EditMeshBoundingBox::clear_vals()
242242
state->setValue(InputSizeZ, cleared);
243243
}
244244

245+
namespace
246+
{
247+
std::string convertForLabel(double coord)
248+
{
249+
return str(boost::format("%8.4f") % coord);
250+
}
251+
}
252+
245253
void EditMeshBoundingBox::update_input_attributes(FieldHandle f)
246254
{
247255
bbox_ = f->vmesh()->get_bounding_box();
@@ -254,11 +262,14 @@ void EditMeshBoundingBox::update_input_attributes(FieldHandle f)
254262
}
255263
auto size = bbox_.diagonal();
256264
auto center = bbox_.center();
257-
box_->setPosition(center,
258-
center + Vector(size.x() / 2., 0, 0),
259-
center + Vector(0, size.y() / 2., 0),
260-
center + Vector(0, 0, size.z() / 2.));
261-
updateOutputAttributes(bbox_);
265+
266+
auto state = get_state();
267+
state->setValue(InputCenterX, convertForLabel(center.x()));
268+
state->setValue(InputCenterY, convertForLabel(center.y()));
269+
state->setValue(InputCenterZ, convertForLabel(center.z()));
270+
state->setValue(InputSizeX, convertForLabel(size.x()));
271+
state->setValue(InputSizeY, convertForLabel(size.y()));
272+
state->setValue(InputSizeZ, convertForLabel(size.z()));
262273
}
263274

264275
void EditMeshBoundingBox::updateOutputAttributes(const BBox& box)
@@ -268,24 +279,23 @@ void EditMeshBoundingBox::updateOutputAttributes(const BBox& box)
268279
auto state = get_state();
269280
const bool useOutputSize = state->getValue(UseOutputSize).toBool();
270281
const bool useOutputCenter = state->getValue(UseOutputCenter).toBool();
271-
char s[32];
272-
sprintf(s, "%8.4f", center.x());
273-
state->setValue(InputCenterX, boost::lexical_cast<std::string>(s));
282+
283+
state->setValue(OutputCenterX, convertForLabel(center.x()));
274284
if (!useOutputCenter) state->setValue(OutputCenterX, center.x());
275-
sprintf(s, "%8.4f", center.y());
276-
state->setValue(InputCenterY, boost::lexical_cast<std::string>(s));
285+
286+
state->setValue(OutputCenterY, convertForLabel(center.y()));
277287
if (!useOutputCenter) state->setValue(OutputCenterY, center.y());
278-
sprintf(s, "%8.4f", center.z());
279-
state->setValue(InputCenterZ, boost::lexical_cast<std::string>(s));
288+
289+
state->setValue(OutputCenterZ, convertForLabel(center.z()));
280290
if (!useOutputCenter) state->setValue(OutputCenterZ, center.z());
281-
sprintf(s, "%8.4f", size.x());
282-
state->setValue(InputSizeX, boost::lexical_cast<std::string>(s));
291+
292+
state->setValue(OutputSizeX, convertForLabel(size.x()));
283293
if (!useOutputSize) state->setValue(OutputSizeX, size.x());
284-
sprintf(s, "%8.4f", size.y());
285-
state->setValue(InputSizeY, boost::lexical_cast<std::string>(s));
294+
295+
state->setValue(OutputSizeY, convertForLabel(size.y()));
286296
if (!useOutputSize) state->setValue(OutputSizeY, size.y());
287-
sprintf(s, "%8.4f", size.z());
288-
state->setValue(InputSizeZ, boost::lexical_cast<std::string>(s));
297+
298+
state->setValue(OutputSizeZ, convertForLabel(size.z()));
289299
if (!useOutputSize) state->setValue(OutputSizeZ, size.z());
290300
}
291301

0 commit comments

Comments
 (0)