⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 drawarea2d.h

📁 crack modeling with xfem
💻 H
📖 第 1 页 / 共 2 页
字号:
	}	*/	// Check input	if (_p==NULL) return;	// Draw points	if (_cp.Typ==CT_POINTS || _cp.Typ==CT_BOTH)	{		int r = _cp.Psz/2;		if (_cp.Pch==1) // Open circle		{			fl_color      (FL_BLACK);			fl_line_style (FL_SOLID, 1);			for (size_t i=0; i<_p->nPoints(); ++i)				fl_circle (_x(_p->P(i)(0)), _y(_p->P(i)(1)), r);		}		else if (_cp.Pch==16) // Filled circle		{			fl_color      (_cp.Clr);			fl_line_style (FL_SOLID, 1);			for (size_t i=0; i<_p->nPoints(); ++i)				fl_pie (_x(_p->P(i)(0))-r, _y(_p->P(i)(1))-r, 2*r+1, 2*r+1, 0,360);		}	}	// Draw mat points ids	/*	fl_font  (0, 8);	fl_color (FL_BLACK);	for (size_t i=0; i<_p->nPoints(); ++i)	{		int xc = _x(_p->P(i)(0));		int yc = _y(_p->P(i)(1));		snprintf (buf, 256, "%d", i);                  // format text		fl_draw  (buf, xc, yc, 0, 0, FL_ALIGN_CENTER); // draw text	}	*/		// Draw velocity field	//_draw_vector_field (_p->P(), _p->v(), FL_BLUE);	// Draw boundary mat points	if (_p->nPointsOnBry()>0)	{		int r = _cp.Psz/2+1;		fl_color      (FL_BLACK);		fl_line_style (FL_SOLID, 2);		for (size_t i=0; i<_p->nPointsOnBry(); ++i)			fl_pie (_x(_p->B(i)(0))-r, _y(_p->B(i)(1))-r, 2*r+1, 2*r+1, 0,360);	}	// Draw time	if (_t==NULL) return;	snprintf (buf, 256, "t = %g", (*_t)); // format text	fl_font (0, 22);                      // Set font for labels	fl_color (FL_RED);                    // set color	fl_draw  (buf, x()+w()-2, y(), 0, 0, FL_ALIGN_RIGHT_TOP); // draw text	// Draw coords	_draw_coords();	// Draw selected	_draw_selected();	// Draw loaded nodes and points	//_draw_loaded_nodes ();	_draw_loaded_points();}inline int DrawArea2D::handle(int E){	int ret = Fl_Group::handle(E);	switch (E)	{		case FL_MOVE:		{			damage (FL_DAMAGE_USER1);			return 1;		}		case FL_PUSH:		{			if (_g==NULL) return ret;			/*			char   buf[256];			double X = _X(Fl::event_x());			double Y = _Y(Fl::event_y());			sprintf(buf, "Selected: x=%.4g y=%.4g", X, Y);			*/			// Search mat points			_pselp = _selp; // previous selected			_selp  = -1;    // current selected			for (size_t i=0; i<_p->nPoints(); ++i)			{				long dx = _x(_p->P(i)(0))-static_cast<long>(Fl::event_x());				long dy = _y(_p->P(i)(1))-static_cast<long>(Fl::event_y());				long d  = static_cast<long>(sqrt(dx*dx+dy*dy));				if (d<4) { _selp=i; break; }			}			// Search nodes			/*			_pseln = _seln; // previous selected			_seln  = -1;    // current selected			if (_selp<0)			{				for (size_t i=0; i<_g->nNodes(); ++i)				{					long dx = _x(_g->N(i)(0))-static_cast<long>(Fl::event_x());					long dy = _y(_g->N(i)(1))-static_cast<long>(Fl::event_y());					long d  = static_cast<long>(sqrt(dx*dx+dy*dy));					if (d<4) { _seln=i; break; }				}			}			*/			// Execute selection action			if (_selp>=0) (*callback()) (this, user_data());			// Redraw			damage (FL_DAMAGE_USER2);			return 1;		}	}	return ret;}/* private */inline void DrawArea2D::_draw_vector_field (Array<Vector3D> const & P, Array<Vector3D> const & V, Fl_Color Clr){	// Check	if (P.Size()<1) return;	// Boundaries	double maxvpx = V[0](0);	double maxvpy = V[0](1);	for (size_t i=0; i<P.Size(); ++i)	{		if (V[i](0)>maxvpx) maxvpx = V[i](0);		if (V[i](1)>maxvpy) maxvpy = V[i](1);	}	// Draw	for (size_t i=0; i<P.Size(); ++i)	{		int lvx = 50*(fabs(maxvpx)>0.0 ? static_cast<int>(fabs(V[i](0)/maxvpx)) : 0);		int lvy = 50*(fabs(maxvpy)>0.0 ? static_cast<int>(fabs(V[i](1)/maxvpy)) : 0);		if (lvx>0 || lvy>0)		{			// Arrows			int xi = _x(P[i](0));			int yi = _y(P[i](1));			int xf = (V[i](0)>0 ? xi+lvx : xi-lvx);			int yf = (V[i](1)>0 ? yi-lvy : yi+lvy);			_draw_arrow (xi, yi, xf, yf, Clr);		}	}}inline void DrawArea2D::_draw_arrow (int xi, int yi, int xf, int yf, Fl_Color Clr){	fl_color      (Clr);	fl_line_style (FL_SOLID, 1);	fl_line       (xi, yi, xf, yf);	fl_line_style (FL_SOLID, 2);	fl_line       ((xi+xf)/2, (yi+yf)/2, xf, yf); }inline void DrawArea2D::_draw_loaded_nodes (){	// Check	if (_g->nLd()<1) return;	// Boundaries	double maxfnx = _g->Ld(0)(0);	double maxfny = _g->Ld(0)(1);	for (size_t i=0; i<_g->nLd(); ++i)	{		if (_g->Ld(i)(0)>maxfnx) maxfnx = _g->Ld(i)(0);		if (_g->Ld(i)(1)>maxfny) maxfny = _g->Ld(i)(1);	}	// Draw	char buf[80];	for (size_t i=0; i<_g->nLd(); ++i)	{		int lfx = 20*static_cast<int>(fabs(_g->Ld(i)(0)/maxfnx+1));		int lfy = 20*static_cast<int>(fabs(_g->Ld(i)(1)/maxfny+1));		if (lfx>0 || lfy>0)		{			int xi = _x(_g->LdN(i)(0));			int yi = _y(_g->LdN(i)(1));			int xf = (_g->Ld(i)(0)>0 ? xi+lfx : xi-lfx);			int yf = (_g->Ld(i)(1)>0 ? yi-lfy : yi+lfy);			_draw_arrow (xi, yi, xf, yf, FL_MAGENTA);			// Write text			sprintf(buf, "%g\n%g",_g->Ld(i)(0)*(*_M),_g->Ld(i)(1)*(*_M));			fl_color (FL_BLACK);			fl_font  (0, 10);			fl_draw  (buf, xf, yf, 0, 0, FL_ALIGN_CENTER);		}	}}inline void DrawArea2D::_draw_loaded_points (){	for (size_t i=0; i<_p->nPoints(); ++i)	{		if (_p->HasT(i))		{			int r = _cp.Psz/2;			fl_color      (FL_BLACK);			fl_line_style (FL_SOLID, 1);			fl_pie        (_x(_p->P(i)(0))-r, _y(_p->P(i)(1))-r, 2*r+1, 2*r+1, 0,360);		}	}	/*	// Write text	char buf[256];	for (size_t i=0; i<_p->nPoints(); ++i)	{		if (fabs(_p->t(i)(0)*(*_M))>0.0 || fabs(_p->t(i)(1)*(*_M))>0.0)		{			//double V = 4.0*_p->l(i)(0)*_p->l(i)(1);			//double m = _p->m(i);			//sprintf(buf, "%g\n%g",V,m);			//sprintf(buf, "%g",_p->l(i)(2));			int xi = _x(_p->P(i)(0));			int yi = _y(_p->P(i)(1));			sprintf(buf, "%g\n%g",_p->t(i)(0)*(*_M),_p->t(i)(1)*(*_M));			fl_color (FL_BLACK);			fl_font  (0, 8);			fl_draw  (buf, xi, yi, 0, 0, FL_ALIGN_CENTER);		}	}	*/}inline void DrawArea2D::_draw_coords(){	// Coordinates as a string	char s[80];	sprintf(s, "x=%.4g y=%.4g", _X(Fl::event_x()), _Y(Fl::event_y()));	// Background	fl_color (0xefebe700);	fl_rectf (x()+1,y()+1,150,18);	// Frame	/*	fl_color      (FL_BLACK);	fl_line_style (FL_SOLID, 1);	fl_rect       (x(), y(), 150, 18);	*/	// Write text	fl_color (FL_BLACK);	fl_font  (0, 12);	fl_draw  (s, x()+2, y()+1, 0, 0, FL_ALIGN_LEFT_TOP);}inline void DrawArea2D::_draw_selected(){	// Mat points	if (_p!=NULL)	{		if (_pselp>=0) // erase previous		{			int xx = _x(_p->P(_pselp)(0));			int yy = _y(_p->P(_pselp)(1));			int r  = _cp.Psz/2;			// Clear background			fl_color      (FL_WHITE);			fl_line_style (FL_SOLID, 3);			fl_circle     (xx, yy, r);			// Draw previous			if (_cp.Typ==CT_POINTS || _cp.Typ==CT_BOTH)			{				if (_cp.Pch==1) // Open circle				{					fl_color      (FL_BLACK);					fl_line_style (FL_SOLID, 1);					fl_circle     (xx, yy, r);				}				else if (_cp.Pch==16) // Filled circle				{					fl_color      (_cp.Clr);					fl_line_style (FL_SOLID, 1);					fl_pie        (xx-r, yy-r, 2*r+1, 2*r+1, 0,360);				}			}		}		if (_selp>=0) // draw selected		{			int r = _cp.Psz/2;			fl_color      (FL_GREEN);			fl_line_style (FL_SOLID, 3);			fl_circle     (_x(_p->P(_selp)(0)), _y(_p->P(_selp)(1)), r);		}	}	// Grid nodes	if (_g!=NULL)	{		if (_pseln>=0) // erase previous		{			int xx = _x(_g->N(_pseln)(0));			int yy = _y(_g->N(_pseln)(1));			int r  = _cg.Psz/2;			// Clear background			fl_color      (FL_WHITE);			fl_line_style (FL_SOLID, 3);			fl_circle     (xx, yy, r);			// Draw pieces of grid lines			if (_cg.Typ==CT_LINES || _cg.Typ==CT_BOTH)			{				fl_color      (_cg.Clr);				fl_line_style (_cg.Lty, _cg.Lwd);				fl_line       (xx-r-2, yy, xx+r+2, yy);				fl_line       (xx, yy-r-2, xx, yy+r+2);			}			// Draw previous			if (_cg.Typ==CT_POINTS || _cg.Typ==CT_BOTH)			{				if (_cg.Pch==1) // Open circle				{					fl_color      (FL_BLACK);					fl_line_style (FL_SOLID, 1);					fl_circle     (xx, yy, r);				}				else if (_cg.Pch==16) // Filled circle				{					fl_color      (_cg.Clr);					fl_line_style (FL_SOLID, 1);					fl_pie        (xx-r, yy-r, 2*r+1, 2*r+1, 0,360);				}			}		}		if (_seln>=0) // draw selected		{			int r = _cg.Psz/2;			fl_color      (FL_MAGENTA);			fl_line_style (FL_SOLID, 3);			fl_circle     (_x(_g->N(_seln)(0)), _y(_g->N(_seln)(1)), r);		}	}}inline void DrawArea2D::_set(){	// Input	_cp.Psz = atoi(_w_psz->value());	_cg.Psz = atoi(_w_gsz->value());	// Redraw	redraw   ();	Fl::wait (0);}#endif // MPM_DRAWAREA2D_H/* 2008 (c) Dorival M. Pedroso */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -