void WayPointShape::draw( wxDC& dc)
{
	// The minimum size of the RectangleShape is the size of the title
	titleSize = dc.GetTextExtent( WXSTRING( title));
	if (size.x < (titleSize.x + 2 * spacing + 2 * borderWidth))
	{
		size.x = titleSize.x + 2 * spacing + 2 * borderWidth;
	}
	if (size.y < (titleSize.y + 2 * spacing + 2 * borderWidth))
	{
		size.y = titleSize.y + 2 * spacing + 2 * borderWidth;
	}

	if (getWayPoint()->getSize() != size)
	{
		getWayPoint()->setSize( size, false);
	}

	// Draws a rectangle with the given top left corner, and with the given size.
	dc.SetBrush( *wxWHITE_BRUSH);
	if (isSelected())
	{
		dc.SetPen( wxPen( WXSTRING( getSelectionColour()), borderWidth, wxSOLID));
	} else
	{
		dc.SetPen( wxPen( WXSTRING( getNormalColour()), borderWidth, wxSOLID));
	}

	int x = centre.x - (size.x / 2);
	int y = centre.y - (size.y / 2);
	dc.DrawRectangle( x, y, size.x, size.y);

	dc.SetPen( wxPen( WXSTRING( "BLACK"), borderWidth, wxSOLID));
	dc.DrawText( WXSTRING( title), centre.x - titleSize.x / 2, y + spacing + borderWidth);
}
void LineShape::draw(wxDC& dc)
{
	if (isSelected()) {
		dc.SetPen(wxPen(WXSTRING("RED"), lineWidth, wxSOLID));
	} else {
		dc.SetPen(wxPen(WXSTRING("BLACK"), lineWidth, wxSOLID));
	}

	dc.DrawLine(node1->getCentre().x, node1->getCentre().y, node2->getCentre().x,
	            node2->getCentre().y);

	if (arrowHeadSize > 0) {
		drawHead(dc);
	}

	if (title == "" && node1->getTitle() != "" && node2->getTitle() != "") {
		title = node1->getTitle() + " to " + node2->getTitle();
	}
	Size textSize = dc.GetTextExtent(WXSTRING(title));

	Point textPoint = getBegin();
	// double angle = getAngle();
	double angle = Shape2DUtils::getAngle(node1->getCentre(), node2->getCentre());
	double dX = (getLength() / 2 - textSize.x / 2) * sin(angle);
	double dY = (getLength() / 2 - textSize.x / 2) * cos(angle);

	textPoint.x += dX;
	textPoint.y -= dY;

	double degreeAngle = angle * (180.0 / PI);
	double rotationAngle = 90 - degreeAngle;

	dc.DrawRotatedText(WXSTRING(title), textPoint, rotationAngle);
}
Beispiel #3
0
std::string GetTextFromUser(	const std::string& aTitleBarMessage,
								const std::string& aMessage,
								const std::string& aDefaultValue /* = "" */,
								Window* aParent /* = NULL */,
								bool UNUSEDPARAM(centre) /* = false */,
								const Point& aPoint /* = DefaultPosition */)
{
	std::string text( STDSTRING( wxGetTextFromUser( WXSTRING( aTitleBarMessage), WXSTRING( aMessage), WXSTRING( aDefaultValue), aParent, aPoint.x, aPoint.y)));
	return text;
}
void LineShape::drawHead(wxDC& dc)
{
	int arrowHeadSize = 10;

	// First we draw a triangle at (0.0)
	// Second we rotate the triangle with the angle the line makes with the
	// Y-axis around it's centre
	// Than we move the centre of the triangle to the end of the line, but
	// outside the node

	top = Point(0, -arrowHeadSize);
	right = Point(arrowHeadSize * std::sin(PI / 3), arrowHeadSize * std::cos(PI / 3));
	left = Point(-arrowHeadSize * std::sin(PI / 3), arrowHeadSize * std::cos(PI / 3));

	// double angle = getAngle();
	double angle = Shape2DUtils::getAngle(node1->getCentre(), node2->getCentre()) + 0.5 * PI;

	top = Shape2DUtils::rotate(top, angle);
	right = Shape2DUtils::rotate(right, angle);
	left = Shape2DUtils::rotate(left, angle);

	double shortenLine = 0.0;

	double dxRect = node2->getSize().x / 2;
	double dyRect = node2->getSize().y / 2;
	double boundaryAngle = std::atan(dxRect / dyRect);

	if (0.0 < angle && angle <= PI / 2) {
		if (angle < boundaryAngle) {
			shortenLine = dyRect / std::cos(angle);
		} else {
			shortenLine = dxRect / std::cos(PI / 2 - angle);
		}
	} else if (PI / 2 < angle && angle <= 2 * PI / 2) {
		if (angle < PI - boundaryAngle) {
			shortenLine = dxRect / std::cos(angle - PI / 2);
		} else {
			shortenLine = dyRect / std::cos(PI - angle);
		}
	} else if (2 * PI / 2 < angle && angle <= 3 * PI / 2) {
		if (angle < boundaryAngle + PI) {
			shortenLine = dyRect / std::cos(angle - PI);
		} else {
			shortenLine = dxRect / std::cos(3 * PI / 2 - angle);
		}
	} else if (3 * PI / 2 < angle && angle <= 4 * PI / 2) {
		if (angle < 2 * PI - boundaryAngle) {
			shortenLine = dxRect / std::cos(angle - PI / 2);
		} else {
			shortenLine = dyRect / std::cos(PI / 2 - angle);
		}
	} else {
		if (angle < 2 * PI - boundaryAngle) {
			shortenLine = dxRect / std::cos(angle - 3 * PI / 2);
		} else {
			shortenLine = dyRect / std::cos(2 * PI - angle);
		}
	}

	shortenLine += arrowHeadSize;

	double dX = (getLength() - shortenLine) * sin(angle);
	double dY = (getLength() - shortenLine) * cos(angle);

	Point triangleCentre(getBegin().x + dX, getBegin().y - dY);

	top += triangleCentre;
	right += triangleCentre;
	left += triangleCentre;

	Point triangle[] = {top, right, left};

	if (isSelected()) {
		dc.SetPen(wxPen(WXSTRING("RED"), lineWidth, wxSOLID));
		dc.SetBrush(wxBrush(wxColour(WXSTRING("RED"))));
	} else {
		dc.SetPen(wxPen(WXSTRING("BLACK"), lineWidth, wxSOLID));
		dc.SetBrush(wxBrush(wxColour(WXSTRING("BLACK"))));
	}
	dc.DrawPolygon(3, triangle);

	// For debugging purposes
	dc.SetPen(wxPen(WXSTRING("ORANGE"), 2, wxSOLID));
	dc.SetBrush(wxBrush(wxColour(WXSTRING("ORANGE"))));
	dc.DrawCircle(top, 2);
	dc.SetPen(wxPen(WXSTRING("GREEN"), 2, wxSOLID)); // stuuRRRRRRboord RRRRRRechts gRRRRRRoen
	dc.SetBrush(wxBrush(wxColour(WXSTRING("GREEN"))));
	dc.DrawCircle(right, 2);
	dc.SetPen(wxPen(WXSTRING("RED"), 2, wxSOLID));
	dc.SetBrush(wxBrush(wxColour(WXSTRING("RED"))));
	dc.DrawCircle(left, 2);
}