void WGraphicsRichTextItem::paint(WPainter* painter)
{
	{
		WPainterProxy proxy(painter);
		painter->setWorldTransform(getRotateMatrix(), true);

		if (isSelected())
		{
			painter->setPen(HOVER_PEN);
			painter->setBrush(WBrush());
			painter->drawRect(_bound_rect);
			painter->drawLine(WWorldLineF(_rotate_pt, WWorldPointF(_rotate_pt.x(), _bound_rect.top())));

			painter->setPen(CP_PEN);
			painter->setBrush(ROTATE_BRUSH);
			painter->drawEllipse(WWorldRectF(_rotate_pt.x() - CP_RADIUS, _rotate_pt.y() - CP_RADIUS, CP_RADIUS * 2, CP_RADIUS * 2));
		}

		painter->setPen(WPen());
		painter->setBrush(WBrush());
		WWorldPointF c = _bound_rect.topLeft();
		WMatrix matrix = WMatrix().translate(-c.x(), -c.y()) * WMatrix().scale(1, -1) * WMatrix().translate(c.x(), c.y());
		painter->setWorldTransform(matrix, true);
		painter->drawStaticText(matrix.map(c), data()->text);
	}
	
	if (_dragging)
	{
		WPainterProxy proxy(painter);
		if (_select_flag & SF_CONTENT)
		{
			WWorldPointF offset = scene()->mousePos() - scene()->dragStartPos();
			WWorldPointF pos = _bound_rect.topLeft() + offset;
			WWorldRectF br = _bound_rect.translated(offset);
			WWorldPointF c = br.center();

			WMatrix matrix =  WMatrix().translate(-c.x(), -c.y()) * WMatrix().rotate(data()->angle) * WMatrix().translate(c.x(), c.y());
			painter->setWorldTransform(matrix, true);

			WMatrix m = WMatrix().translate(-pos.x(), -pos.y()) * WMatrix().scale(1, -1) * WMatrix().translate(pos.x(), pos.y());
			painter->setWorldTransform(m, true);

			painter->drawStaticText(m.map(pos), data()->text);
		}
		else if (_select_flag & SF_ROTATE)
		{
			WWorldPointF pos = scene()->mousePos();
			WWorldPointF c = _bound_rect.center();
			double ag = normalized_angle(WWorldLineF(c, pos).angle() - 90);
			WMatrix m = WMatrix().translate(-c.x(), -c.y()) * WMatrix().rotate(ag) * WMatrix().translate(c.x(), c.y());
			painter->setWorldTransform(m, true);
			painter->setBrush(WBrush());
			painter->setPen(DRAG_PEN);
			painter->drawRect(_bound_rect);
		}
	}
}
void WGraphicsRichTextItem::mouseReleaseEvent(WGraphicsSceneMouseEvent* event)
{
	if (isSelected() && (event->button() == Ws::LeftButton) && _dragging)
	{
		_dragging = false;

		if (_select_flag & SF_CONTENT)
		{
			setPos(data()->pos + event->scenePos() - scene()->dragStartPos(), false, true);
		}
		else if (_select_flag & SF_ROTATE)
		{
			setAngle(normalized_angle(WWorldLineF(_bound_rect.center(), event->scenePos()).angle() - 90.0), false, true);
		}

		scene()->update();
	}
}
Exemple #3
0
LOCAL int i_polar_1(
	Locstate	ahead,
	Locstate	behind,
	Locstate	refl_bow,
	Locstate	refl_mach,
	ANGLE_DIRECTION	i_to_a_dir,
	float		*abs_v,
	float		*refl_ang,
	float		*cont_ang,
	float		*mach_ang)
{
	float		p3;
	float		theta12;		/*turn angle across refl*/
	float		theta03;		/*turn angle across mach*/
	float		vel0_ang;		/*in steady frame*/
	float		vel1_ang;		/* "    "     "  */
	float		pmax, pmin;
	float		M0_sq, M1_sq;
	float		rel_v[MAXD];
	bool		Cplus_w0;		/*wave 0 is mach stem*/
	bool		Cplus_w1;		/*wave 1 is refl wave*/
	RIEMANN_SOLVER_WAVE_TYPE wtype0;
	RIEMANN_SOLVER_WAVE_TYPE wtype1;
	int		i, dim = Params(ahead)->dim;
	static Locstate st_0 = NULL, st_1 = NULL;
	static Locstate	st_2 = NULL, st_3 = NULL;
	static bool	first = YES;

	debug_print("ipolar1","Entered i_polar_1()\n");

	if (first)
	{
		size_t	sizest = Params(ahead)->sizest;

		first = NO;
		(*Params(ahead)->_alloc_state)(&st_0,sizest);
		(*Params(ahead)->_alloc_state)(&st_1,sizest);
		(*Params(ahead)->_alloc_state)(&st_2,sizest);
		(*Params(ahead)->_alloc_state)(&st_3,sizest);
	}

	set_state(st_0,TGAS_STATE,ahead);
	set_state(st_1,TGAS_STATE,behind);

	if (debugging("ipolar1"))
	{
		verbose_print_state("ahead",ahead);
		verbose_print_state("behind",behind);
		(void) printf("\tabs_v[0] = (%g, %g)\n",abs_v[0],abs_v[1]);
		print_angle_direction("\ti_to_a_dir =",i_to_a_dir,"\n");
	}

	M0_sq = mach_number_squared(st_0,abs_v,rel_v);
	vel0_ang = angle(rel_v[0],rel_v[1]);
	if (debugging("ipolar1"))
	{
		print_angle("\tvel0 angle =",vel0_ang,"\n");
		(void) printf("\tahead Mach number = %g\n",
			      mag_vector(rel_v,dim)/sound_speed(st_0));
	}
	if (mag_vector(rel_v,dim) < sound_speed(st_0))
	{
		if (debugging("ipolar1"))
		{
			(void) printf("WARNING in i_polar_1(), ");
			(void) printf("ahead is subsonic in the rest frame.\n");
		}
		debug_print("ipolar1","Left i_polar_1()\n");
		return NO;
	}

	M1_sq = mach_number_squared(st_1,abs_v,rel_v);
	if (debugging("ipolar1"))
	{
		vel1_ang = angle(rel_v[0],rel_v[1]);
		print_angle("\tvel1 angle =",vel1_ang,"\n");
		(void) printf("\tst1 Mach number = %g\n",sqrt(M1_sq));
	}
	if (mag_vector(rel_v,dim) < sound_speed(st_1))
	{
		if (debugging("ipolar1"))
		{
		       (void) printf("WARNING in i_polar_1(), ");
		       (void) printf("behind is subsonic in the rest frame.\n");
		}
		debug_print("ipolar1","Left i_polar_1()\n");
		return NO;
	}

	if (i_to_a_dir == CLOCKWISE)
	{
		Cplus_w0 = YES;
		Cplus_w1 = NO;
	}
	else
	{
		Cplus_w0 = NO;
		Cplus_w1 = YES;
	}
	
	if (pr_at_max_turn_angle(&pmin,M0_sq,st_0) == FUNCTION_FAILED)
	{
		if (debugging("ipolar1"))
		{
			(void) printf("WARNING in i_polar_1(), ");
			(void) printf("pr_at_max_turn_angle() failed\n");
		}
		return NO;
	}
	pmax = max_behind_shock_pr(M1_sq,st_1);
	if (!intersection_of_two_shock_polars(st_0,st_1,abs_v,&p3,
	                                         &pmin,&pmax,Cplus_w0,
						 Cplus_w1,&wtype0,&wtype1))
	{
		if (debugging("ipolar1"))
		{
			(void) printf("WARNING in i_polar_1(), ");
			(void) printf("unable to compute refl_mach pressure\n");
		}
		debug_print("ipolar1","Left i_polar_1()\n");
		return NO;
	}

	if ((wtype0 != SHOCK) || (wtype1 != SHOCK))
	{
		if (debugging("ipolar1"))
		{
			(void) printf("WARNING in i_polar_1() -- ");
			(void) printf("non-shock wave types.\n");
		}
		debug_print("ipolar1","Left i_polar_1()\n");
		return NO;
	}

	if (!s_polar_3(st_1,YES,p3,Cplus_w1,YES,abs_v,st_2,
			  refl_ang,&theta12))
	{
		if (debugging("ipolar1"))
		{
			(void) printf("WARNING in i_polar_1() -- ");
			(void) printf("unable to compute refl_bow.\n");
		}
		debug_print("ipolar1","Left i_polar_1()\n");
		return NO;
	}

	if (!s_polar_3(st_0,YES,p3,Cplus_w0,YES,abs_v,st_3,
				mach_ang,&theta03))
	{
		if (debugging("ipolar1"))
		{
			(void) printf("WARNING in i_polar_1() -- ");
			(void) printf("unable to compute refl_mach.\n");
		}
		debug_print("ipolar1","Left i_polar_1()\n");
		return NO;
	}

	*cont_ang = normalized_angle(vel0_ang + theta03);

	set_state(refl_bow,GAS_STATE,st_2);
	set_state(refl_mach,GAS_STATE,st_3);

	if (debugging("ipolar1"))
	{
		float ang;
		(void) printf("\n");
		print_angle("\trefl angle = %g d\n",*refl_ang,"\n");
		print_angle("\tcont angle = %g d\n",*cont_ang,"\n");
		print_angle("\tMach angle = %g d\n",*mach_ang,"\n");
		print_angle("\ttheta12 = %g d\n",theta12,"\n");
		print_angle("\ttheta03 = %g d\n",theta03,"\n");
		for (i = 0; i < dim; i++)
			rel_v[i] = vel(i,st_2) - abs_v[i];
		ang = angle(rel_v[0],rel_v[1]);
		print_angle("\tvel2_ang =",ang,"\n");
		for (i = 0; i < dim; i++)
			rel_v[i] = vel(i,st_3) - abs_v[i];
		ang = angle(rel_v[0],rel_v[1]);
		print_angle("\tvel3_ang =",ang,"\n");
		ang = (vel1_ang+theta12) - (vel0_ang+theta03);
		print_angle("(vel1_ang+theta12) - (vel0_ang+theta03) =",
			    ang,"\n");
		verbose_print_state("refl_bow",refl_bow);
		verbose_print_state("refl_mach",refl_mach);
	}

	debug_print("ipolar1","Left i_polar_1()\n");
	return YES;
}		/*end i_polar_1*/
Exemple #4
0
LOCAL bool   ip2(
	float u,		/* trial node angle in computational frame */
	float *diff,
	POINTER parameters) 
{
	static const float SMALL_ANG         = PI/30.0; /*TOLERANCE*/
	static const float twopi_m_small_ang = 2.0*PI - PI/30.0;/*TOLERANCE*/
	static const float twopi             = 2.0*PI;
	static const float halfpi            = 0.5*PI;

	float	node_speed;
	float	trial_Mach_ang;
	float	nod_ang_to_inc_ang;
	float	abs_v[SMAXD];		/*node velocity*/
	float	Msq;			/*steady Mach # sq - temp*/
	float	pinc_max;		/*max pr behind inc shock*/
	float	prefl_max;		/*max pr behind refl shock*/
	float	inc_shock_speed	  = ((IP2_PARAMS *)parameters)->inc_shock_speed;
	float	inc_ang		  = ((IP2_PARAMS *)parameters)->inc_ang;
	float	Mach_ang 	  = ((IP2_PARAMS *)parameters)->Mach_ang;
	float	*refl_ang	  = ((IP2_PARAMS *)parameters)->refl_ang;
	float	*contact_ang	  = ((IP2_PARAMS *)parameters)->contact_ang;
	ANGLE_DIRECTION i_to_a_dir= ((IP2_PARAMS *)parameters)->i_to_a_dir;
	Locstate ahead		  = ((IP2_PARAMS *)parameters)->ahead;
	Locstate behind		  = ((IP2_PARAMS *)parameters)->behind;
	Locstate refl_bow	  = ((IP2_PARAMS *)parameters)->refl_bow;
	Locstate refl_mach	  = ((IP2_PARAMS *)parameters)->refl_mach;
	static bool	first = YES;
	static float	sin_small_ang;

	debug_print("ip2","Entered ip2()\n");
	if (first == YES)
	{
	    first = NO;
	    sin_small_ang = sin(SMALL_ANG);
	}

	nod_ang_to_inc_ang = normalized_angle(inc_ang - u);
	if (fabs(nod_ang_to_inc_ang) < SMALL_ANG ||
	    fabs(nod_ang_to_inc_ang) > twopi_m_small_ang)
	{ /* A GUESS */
	    node_speed = inc_shock_speed / sin_small_ang;
	    abs_v[0] = node_speed * cos(u);
	    abs_v[1] = node_speed * sin(u);
	}
	else 
	{
	    node_speed = inc_shock_speed / fabs(sin(inc_ang - u));
	    abs_v[0] = node_speed * cos(u);
	    abs_v[1] = node_speed * sin(u);
	}

#if defined(DEBUG_GIPOLAR)
	if (debugging("ip2"))
	{
	    print_angle("\ttrial_node_ang =",u,"\n");
	    print_angle("\tinc_ang =",inc_ang,"\n");
	    (void) printf("\tinc_shock_speed = %g node_speed = %g\n",
	    	          inc_shock_speed,node_speed);
	    (void) printf("\tabs_v = (%g, %g)\n",abs_v[0],abs_v[1]);
	}
#endif /* defined(DEBUG_GIPOLAR) */

	if (!i_polar_1(ahead,behind,refl_bow,refl_mach,i_to_a_dir,
		abs_v,refl_ang,contact_ang,&trial_Mach_ang))
	{
	    Msq = mach_number_squared(ahead,abs_v,(float *)NULL);
	    pinc_max = max_behind_shock_pr(Msq,ahead);
	    Msq = mach_number_squared(behind,abs_v,(float *)NULL);
	    prefl_max = max_behind_shock_pr(Msq,behind);
	    if (((prefl_max > pinc_max) && (i_to_a_dir == CLOCKWISE))
	    	 ||
	        ((prefl_max < pinc_max) && (i_to_a_dir == COUNTER_CLOCK)))
	    {
	    	*diff = -halfpi;
	    }
	    else
	    {
	    	*diff = halfpi;
	    }
	}
	else 
	{
	    *diff = Mach_ang - trial_Mach_ang;
#if defined(DEBUG_GIPOLAR)
	    if (debugging("ip2"))
	    {
	    	print_angle("\ttrial_Mach_ang =",trial_Mach_ang,"\n");
	    	print_angle("\tdiff =",*diff,"\n");
	    }
#endif /* defined(DEBUG_GIPOLAR) */
	}
	*diff = (*diff < PI) ? *diff : *diff - twopi;
	*diff = (*diff > -PI) ? *diff : *diff + twopi;

	debug_print("ip2","Left ip2()\n");
	return FUNCTION_SUCCEEDED;
}		/*end ip2*/
//世界坐标系方向(弧度,x轴正向为0)转换化为时钟方向(角度,y轴正向为0)
static double world_to_clockwise(double radian)
{
	return normalized_angle(90 - radian * 180 / M_PI);
}