001 /*
002 * @(#)MohrPrincipalStrsCanvas.java
003 */
004
005 import java.awt.*;
006 import java.awt.geom.*;
007 import java.awt.event.*;
008 import java.text.*;
009
010 import wc.*;
011
012 /**
013 * MohrPrincipalStrsCanvas.java - Desenha o estado de tensões.
014 *
015 * <p>
016 * Descrição:
017 * <p>
018 * ===============================================================
019 * <p>
020 * Este arquivo contém a classe que desenha e manipula o
021 * estado de tensões principais.
022 *
023 * <p>
024 * ===============================================================
025 *
026 * @version 1.0 04/09/2004
027 * @author Luiz Fernando Martha
028 * @author Alonso Juvinao Carbono
029 * @author Anderson Resende Pereira
030 * @author Fernando Busato Ramires
031 * @author Paôla Reginal Dalcanal
032 * @author Ricardo Rodrigues de Araujo
033 *
034 */
035 class MohrPrincipalStrsCanvas extends CanvasWC
036 {
037 /** Driver do programa Mohr-Circle */
038 protected MohrDriver driver;
039
040 /** Quadrado */
041 protected Rectangle2D.Double quad;
042
043 /** Fator de proporção em relação ao tamanho horizontal da janela
044 * em coordenadas do mundo para stroke básico do quadrado */
045 protected static final double QUAD_STROKE_FAC = 0.005;
046
047 /** Objeto seta para desenhar tensões */
048 protected Arrow2D arrow;
049
050 /** Fator de proporção em relação ao tamanho horizontal da janela
051 * em coordenadas do mundo para stroke básico das setas */
052 protected static final double ARROW_STROKE_FAC = 0.010;
053
054 /** Stroke básico dos eixos */
055 protected BasicStroke arrow_stroke;
056
057 /** Stroke básico do quadrado */
058 protected BasicStroke quad_stroke;
059
060 /** Objeto arco para desenhar ângulos */
061 protected MohrArc arc;
062
063 /** Objeto linha para desenho de linhas auxiliares */
064
065 protected Line2D.Double auxline;
066
067 /** Fator de proporção em relação ao tamanho horizontal da janela
068 * em coordenadas do mundo para stroke básico das linhas auxiliares */
069 protected static final double AUXLINE_STROKE_FAC = 0.010;
070
071 /** Stroke básico das linhas auxiliares */
072 protected BasicStroke auxline_stroke;
073
074 /** Transformação window-viewport corrent */
075 protected AffineTransform def_transf;
076
077 /** Fonte adotado para desenho */
078 protected Font fnt;
079
080
081 /*========================== Constructor =========================*/
082 /**
083 * Constructor: Especifica eixo Y no sentido para cima.
084 */
085 MohrPrincipalStrsCanvas( MohrDriver driver )
086 {
087 super( UPWARD_Y );
088 this.driver = driver;
089
090 double xmin = 0.0;
091 double xmax = 600.0;
092 double ymin = 0.0;
093 double ymax = 600.0;
094
095 double aresta = xmax/3.0;
096 double centro = xmax/2.0;
097
098 setWorld( xmin, xmax, ymin, ymax );
099
100 quad = new Rectangle2D.Double( centro - (aresta/2), centro - (aresta/2),
101 aresta, aresta);
102 quad_stroke = new BasicStroke(
103 (float)(world_area.height*QUAD_STROKE_FAC) );
104 arrow = new Arrow2D();
105 arrow_stroke = new BasicStroke(
106 (float)(world_area.height*ARROW_STROKE_FAC) );
107
108 arc = new MohrArc( );
109
110 auxline = new Line2D.Double( );
111 auxline_stroke = new BasicStroke(
112 (float)(world_area.height*AUXLINE_STROKE_FAC) );
113
114 def_transf = new AffineTransform( );
115
116 fnt = new Font( "Times New Roman", Font.ITALIC, 14 );
117 }
118
119 /*
120 ** ---------------------------------------------------------------
121 ** Private and Protected methods:
122 */
123
124
125 /*
126 ** ---------------------------------------------------------------
127 ** Public methods:
128 */
129
130 /*=============================== update ==============================*/
131 /**
132 * Reset method.
133 */
134 void update()
135 {
136
137 double xmin = 0.0;
138 double xmax = 600.0;
139 double ymin = 0.0;
140 double ymax = 600.0;
141
142 double aresta = xmax/3.0;
143 double centro = xmax/2.0;
144
145 setWorld( xmin, xmax, ymin, ymax );
146
147 quad.setFrame( centro - (aresta/2), centro - (aresta/2), aresta, aresta );
148
149
150 quad_stroke = new BasicStroke(
151 (float)(world_area.height*QUAD_STROKE_FAC) );
152
153 arrow_stroke = new BasicStroke(
154 (float)(world_area.height*ARROW_STROKE_FAC) );
155
156 auxline_stroke = new BasicStroke(
157 (float)(world_area.height*AUXLINE_STROKE_FAC) );
158
159 repaint();
160 }
161
162 /*=============================== redraw =============================*/
163 /**
164 * Redisplay method.
165 * This method is called every time the canvas is updated.
166 * Client's concrete class must implement it.
167 * @param g is the 2D graphics context that the client uses to display
168 */
169 public void redraw( Graphics2D g )
170 {
171 double pi = Math.PI;
172
173 double xmin = world_area.x;
174 double xmax = world_area.x + world_area.width;
175 double ymin = world_area.y;
176 double ymax = world_area.y + world_area.height;
177
178 double aresta = (ymax-ymin)/3.0;
179 double centro = (xmax+xmin)/2.0;
180
181 double fact = aresta/8.0;
182
183 double x = centro;
184 double y = centro;
185
186 double sin_a;
187 double cos_a;
188
189 g.setRenderingHint( RenderingHints.KEY_ANTIALIASING,
190 RenderingHints.VALUE_ANTIALIAS_ON );
191
192 g.setFont( fnt );
193
194 /* Desenha arco com ângulo */
195 if( driver.getSolver().ThetaP() > 0.2 )
196 {
197 g.setColor( Color.gray.brighter() );
198 g.setStroke( auxline_stroke );
199 auxline.setLine( centro + 0.5*aresta, centro, centro + 0.9*aresta, centro );
200 g.draw( auxline );
201 cos_a = Math.cos( driver.getSolver().ThetaP() );
202 sin_a = Math.sin( driver.getSolver().ThetaP() );
203 arc.DrawArc( this, g, Color.gray.brighter(),
204 centro, centro, centro + aresta, centro,
205 centro + aresta*cos_a, centro + aresta*sin_a,
206 0.8*aresta, "\u03B8p", 1.5*fact, auxline_stroke );
207 }
208
209 /* Ajusta transformação de rotação */
210 def_transf = g.getTransform();
211 AffineTransform curr_transf = g.getTransform();
212
213 curr_transf.translate( centro, centro );
214 curr_transf.rotate( driver.getSolver().ThetaP() );
215 curr_transf.translate( -centro, -centro );
216 g.setTransform( curr_transf );
217
218 g.setColor( Color.white );
219 g.fill( quad );
220 g.setColor( Color.black );
221 g.draw( quad );
222
223 /* Desenha Sigma 1 */
224 if( Math.abs( driver.getSolver().Sigma1() ) > 0.01 )
225 {
226 g.setColor( Color.red );
227 g.setStroke( arrow_stroke );
228 if( driver.getSolver().Sigma1() > 0 )
229 {
230 x = centro + (aresta/2.0) + fact;
231 y = centro;
232 arrow.DrawArrow( g, x, y, 0, aresta/2.0, Arrow2D.SIDE_LEAD,
233 pi/4.0, aresta/10.0 );
234
235 x = centro - (aresta/2.0) - fact;
236 y = centro;
237 arrow.DrawArrow( g, x, y, pi, aresta/2.0, Arrow2D.SIDE_LEAD,
238 pi/4.0, aresta/10.0 );
239 }
240 else if( driver.getSolver().Sigma1() < 0 )
241 {
242 x = centro + (aresta/2.0) + fact;
243 y = centro;
244 arrow.DrawArrow( g, x, y, 0, aresta/2.0, Arrow2D.SIDE_TRAIL,
245 pi/4.0, aresta/10.0 );
246
247 x = centro - (aresta/2.0) - fact;
248 y = centro;
249 arrow.DrawArrow( g, x, y, pi, aresta/2.0, Arrow2D.SIDE_TRAIL,
250 pi/4.0, aresta/10.0 );
251 }
252 }
253
254 /* Desenha Sigma 2 */
255 if( Math.abs( driver.getSolver().Sigma2() ) > 0.01 )
256 {
257 g.setColor( Color.red.darker() );
258 g.setStroke( arrow_stroke );
259 if( driver.getSolver().Sigma2() > 0 )
260 {
261 x = centro;
262 y = centro + (aresta/2.0) + fact;
263 arrow.DrawArrow( g, x, y, pi/2, aresta/2.0, Arrow2D.SIDE_LEAD,
264 pi/4.0, aresta/10.0 );
265
266 x = centro;
267 y = centro - (aresta/2.0) - fact;
268 arrow.DrawArrow( g, x, y, 3*pi/2, aresta/2.0, Arrow2D.SIDE_LEAD,
269 pi/4.0, aresta/10.0 );
270 }
271 else if( driver.getSolver().Sigma2() < 0 )
272 {
273 x = centro;
274 y = centro + (aresta/2.0) + fact;
275 arrow.DrawArrow( g, x, y, pi/2, aresta/2.0, Arrow2D.SIDE_TRAIL,
276 pi/4.0, aresta/10.0 );
277
278 x = centro;
279 y = centro - (aresta/2.0) - fact;
280 arrow.DrawArrow( g, x, y, 3*pi/2, aresta/2.0, Arrow2D.SIDE_TRAIL,
281 pi/4.0, aresta/10.0 );
282 }
283 }
284
285 g.setColor( Color.black );
286 setTextAlignment( CENTER );
287 if( Math.abs( driver.getSolver().Sigma1() ) > 0.01 )
288 {
289 drawString( "\u03C31", centro + aresta + (2.5*fact), centro );
290 drawString( "\u03C31", centro - (aresta + (2.5*fact)), centro );
291 }
292 if( Math.abs( driver.getSolver().Sigma2() ) > 0.01 )
293 {
294 drawString( "\u03C32", centro, centro + aresta + (2.5*fact) );
295 drawString( "\u03C32", centro, centro - (aresta + (2.5*fact)) );
296 }
297
298 g.setTransform( def_transf );
299 }
300
301 /**
302 * Handles the event of the user pressing down the mouse button.
303 */
304 public void mousePressedWC( MouseEvent e, Point2D.Double mouse_pos )
305 {
306 }
307
308 /**
309 * Handles the event of a user dragging the mouse while holding
310 * down the mouse button.
311 */
312 public void mouseDraggedWC( MouseEvent e, Point2D.Double mouse_pos )
313 {
314 }
315
316 /**
317 * Handles the event of a user releasing the mouse button.
318 */
319 public void mouseReleasedWC( MouseEvent e, Point2D.Double mouse_pos )
320 {
321 }
322 }
323