Ejemplo n.º 1
0
TEST_F(CoordinateTransformableDataObject_test, TransformAppliedToVisibleBounds)
{
    const auto coordsSpec = ReferencedCoordinateSystemSpecification(
        CoordinateSystemType::geographic,
        "testSystem",
        {}, {}, {}, {});
    const auto targetCoordsSpec = ReferencedCoordinateSystemSpecification(
        CoordinateSystemType::geographic,
        "otherTestSystem",
        {}, {}, {}, {});

    auto data = genPolyData<TransformedPolyData>();
    data->specifyCoordinateSystem(coordsSpec);
    auto transform = vtkSmartPointer<vtkTransform>::New();
    transform->Translate(3, 4, 5);
    data->setTransform(transform);

    const auto dataSetBounds = DataBounds(data->dataSet()->GetBounds());
    const auto dataBounds = data->bounds();
    const auto shiftedBounds = data->bounds().shifted(vtkVector3d(3, 4, 5));
    auto rendered = data->createRendered();
    rendered->setDefaultCoordinateSystem(targetCoordsSpec);
    const auto visibleBounds = rendered->visibleBounds();

    ASSERT_EQ(dataSetBounds, dataBounds);
    ASSERT_EQ(shiftedBounds, visibleBounds);
}
Ejemplo n.º 2
0
TEST_F(CoordinateTransformableDataObject_test, NullTransformKeepsBounds)
{
    auto data = genPolyData<TransformedPolyData>();
    const auto dataSetBounds = DataBounds(data->dataSet()->GetBounds());
    const auto dataBounds = data->bounds();
    const auto visibleBounds = data->createRendered()->visibleBounds();

    ASSERT_EQ(dataSetBounds, dataBounds);
    ASSERT_EQ(dataBounds, visibleBounds);
}
Ejemplo n.º 3
0
void
DataView::GetPreferredSize(float *_width, float *_height)
{
	BRect bounds = DataBounds();

	if (_width)
		*_width = bounds.Width();

	if (_height)
		*_height = bounds.Height();
}
Ejemplo n.º 4
0
int32
DataView::PositionAt(view_focus focus, BPoint point, view_focus *_newFocus)
{
	// clip the point into our data bounds

	BRect bounds = DataBounds(true);
	if (point.x < bounds.left)
		point.x = bounds.left;
	else if (point.x > bounds.right)
		point.x = bounds.right;

	if (point.y < bounds.top)
		point.y = bounds.top;
	else if (point.y >= bounds.bottom - kVerticalSpace)
		point.y = bounds.bottom - kVerticalSpace - 1;

	float left = fCharWidth * (fPositionLength + kBlockSpace) + kHorizontalSpace;
	float hexWidth = fCharWidth * kBlockSize * kHexByteWidth;
	float width = fCharWidth;

	if (focus == kNoFocus) {
		// find in which part the point is in
		if (point.x < left - width / 2)
			return -1;

		if (point.x > left + hexWidth)
			focus = kAsciiFocus;
		else
			focus = kHexFocus;

		if (_newFocus)
			*_newFocus = focus;
	}
	if (focus == kHexFocus) {
		left -= width / 2;
		width *= kHexByteWidth;
	} else
		left += hexWidth + (kBlockSpace * width);

	int32 row = int32((point.y - kVerticalSpace) / fFontHeight);
	int32 column = int32((point.x - left) / width);
	if (column >= (int32)kBlockSize)
		column = (int32)kBlockSize - 1;
	else if (column < 0)
		column = 0;

	return row * kBlockSize + column;
}
Ejemplo n.º 5
0
void
DataView::KeyDown(const char *bytes, int32 numBytes)
{
	int32 modifiers;
	if (Looper()->CurrentMessage() == NULL
		|| Looper()->CurrentMessage()->FindInt32("modifiers", &modifiers) != B_OK)
		modifiers = ::modifiers();

	// check if the selection is going to be changed
	switch (bytes[0]) {
		case B_LEFT_ARROW:
		case B_RIGHT_ARROW:
		case B_UP_ARROW:
		case B_DOWN_ARROW:
			if (modifiers & B_SHIFT_KEY) {
				if (fKeySelectionStart == -1)
					fKeySelectionStart = fStart;
			} else
				fKeySelectionStart = -1;
			break;
	}

	switch (bytes[0]) {
		case B_LEFT_ARROW:
		{
			int32 position = fStart - 1;

			if (modifiers & B_SHIFT_KEY) {
				if (fKeySelectionStart == fEnd)
					SetSelection(fStart - 1, fEnd);
				else {
					SetSelection(fStart, fEnd - 1);
					position = fEnd;
				}
			} else
				SetSelection(fStart - 1, fStart - 1);

			MakeVisible(position);
			break;
		}
		case B_RIGHT_ARROW:
		{
			int32 position = fEnd + 1;

			if (modifiers & B_SHIFT_KEY) {
				if (fKeySelectionStart == fStart)
					SetSelection(fStart, fEnd + 1);
				else
					SetSelection(fStart + 1, fEnd);
			} else
				SetSelection(fEnd + 1, fEnd + 1);

			MakeVisible(position);
			break;
		}
		case B_UP_ARROW:
		{
			int32 start, end;
			if (modifiers & B_SHIFT_KEY) {
				if (fKeySelectionStart == fStart) {
					start = fEnd - int32(kBlockSize);
					end = fStart;
				} else {
					start = fStart - int32(kBlockSize);
					end = fEnd;
				}
				if (start < 0)
					start = 0;
			} else {
				start = fStart - int32(kBlockSize);
				if (start < 0)
					start = fStart;

				end = start;
			}

			SetSelection(start, end);
			MakeVisible(start);
			break;
		}
		case B_DOWN_ARROW:
		{
			int32 start, end;
			if (modifiers & B_SHIFT_KEY) {
				if (fKeySelectionStart == fEnd) {
					start = fEnd;
					end = fStart + int32(kBlockSize);
				} else {
					start = fStart;
					end = fEnd + int32(kBlockSize);
				}
				if (end >= int32(fSizeInView))
					end = int32(fSizeInView) - 1;
			} else {
				end = fEnd + int32(kBlockSize);
				if (end >= int32(fSizeInView))
					start = fEnd;

				start = end;
			}

			SetSelection(start, end);
			MakeVisible(end);
			break;
		}

		case B_PAGE_UP:
		{
			// scroll one page up, but keep the same cursor column

			BRect frame = SelectionFrame(fFocus, fStart, fStart);
			frame.OffsetBy(0, -Bounds().Height());
			if (frame.top <= kVerticalSpace)
				frame.top = kVerticalSpace + 1;
			ScrollBy(0, -Bounds().Height());

			int32 position = PositionAt(fFocus, frame.LeftTop());
			SetSelection(position, position);
			break;
		}
		case B_PAGE_DOWN:
		{
			// scroll one page down, but keep the same cursor column

			BRect frame = SelectionFrame(fFocus, fStart, fStart);
			frame.OffsetBy(0, Bounds().Height());

			float lastLine = DataBounds().Height() - 1 - kVerticalSpace;
			if (frame.top > lastLine)
				frame.top = lastLine;
			ScrollBy(0, Bounds().Height());

			int32 position = PositionAt(fFocus, frame.LeftTop());
			SetSelection(position, position);
			break;
		}
		case B_HOME:
			SetSelection(0, 0);
			MakeVisible(fStart);
			break;
		case B_END:
			SetSelection(fDataSize - 1, fDataSize - 1);
			MakeVisible(fStart);
			break;
		case B_TAB:
			SetFocus(fFocus == kHexFocus ? kAsciiFocus : kHexFocus);
			MakeVisible(fStart);
			break;

		case B_FUNCTION_KEY:
			// this is ignored
			break;

		case B_BACKSPACE:
			if (fBitPosition == 0)
				SetSelection(fStart - 1, fStart - 1);

			if (fFocus == kHexFocus)
				fBitPosition = (fBitPosition + 4) % 8;

			// supposed to fall through
		case B_DELETE:
			SetSelection(fStart, fStart);
				// to make sure only the cursor is selected

			if (fFocus == kHexFocus) {
				const uint8 *data = DataAt(fStart);
				if (data == NULL)
					break;

				uint8 c = data[0] & (fBitPosition == 0 ? 0x0f : 0xf0);
					// mask out region to be cleared

				fEditor.Replace(fOffset + fStart, &c, 1);
			} else
				fEditor.Replace(fOffset + fStart, (const uint8 *)"", 1);
			break;

		default:
			if (fFocus == kHexFocus) {
				// only hexadecimal characters are allowed to be entered
				const uint8 *data = DataAt(fStart);
				uint8 c = bytes[0];
				if (c >= 'A' && c <= 'F')
					c += 'A' - 'a';
				const char *hexNumbers = "0123456789abcdef";
				addr_t number;
				if (data == NULL || (number = (addr_t)strchr(hexNumbers, c)) == 0)
					break;

				SetSelection(fStart, fStart);
					// to make sure only the cursor is selected

				number -= (addr_t)hexNumbers;
				fBitPosition = (fBitPosition + 4) % 8;

				c = (data[0] & (fBitPosition ? 0x0f : 0xf0)) | (number << fBitPosition);
					// mask out overwritten region and bit-wise or the number to be inserted

				if (fEditor.Replace(fOffset + fStart, &c, 1) == B_OK && fBitPosition == 0)
					SetSelection(fStart + 1, fStart + 1);
			} else {
				if (fEditor.Replace(fOffset + fStart, (const uint8 *)bytes, numBytes) == B_OK)
					SetSelection(fStart + 1, fStart + 1);
			}
			break;
	}
}