001 /*
002 * @(#)MohrThetaStrsCanvas.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 * MohrThetaStrsCanvas.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 para o plano theta.
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 MohrThetaStrsCanvas 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 MohrThetaStrsCanvas( 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 quad_stroke = new BasicStroke(
150 (float)(world_area.height*QUAD_STROKE_FAC) );
151
152 arrow_stroke = new BasicStroke(
153 (float)(world_area.height*ARROW_STROKE_FAC) );
154
155 auxline_stroke = new BasicStroke(
156 (float)(world_area.height*AUXLINE_STROKE_FAC) );
157
158 repaint();
159 }
160
161 /*=============================== redraw =============================*/
162 /**
163 * Redisplay method.
164 * This method is called every time the canvas is updated.
165 * Client's concrete class must implement it.
166 * @param g is the 2D graphics context that the client uses to display
167 */
168 public void redraw( Graphics2D g )
169 {
170 double pi = Math.PI;
171 double xmin = world_area.x;
172 double xmax = world_area.x + world_area.width;
173 double ymin = world_area.y;
174 double ymax = world_area.y + world_area.height;
175
176 double aresta = (ymax-ymin)/3.0;
177 double centro = (xmax+xmin)/2.0;
178
179 double fact = aresta/8.0;
180
181 double x = centro;
182 double y = centro;
183
184 double sin_a;
185 double cos_a;
186
187 g.setRenderingHint( RenderingHints.KEY_ANTIALIASING,
188 RenderingHints.VALUE_ANTIALIAS_ON );
189
190 g.setFont( fnt );
191
192 /* Desenha arco com ângulo */
193 if( driver.getSolver().getTheta() > 0.2 )
194 {
195 g.setColor( Color.gray.brighter() );
196 g.setStroke( auxline_stroke );
197 auxline.setLine( centro + 0.5*aresta, centro, centro + 1.1*aresta, centro );
198 g.draw( auxline );
199 cos_a = Math.cos( driver.getSolver().getTheta() );
200 sin_a = Math.sin( driver.getSolver().getTheta() );
201 arc.DrawArc( this, g, Color.gray.brighter(),
202 centro, centro, centro + aresta, centro,
203 centro + aresta*cos_a, centro + aresta*sin_a,
204 aresta, "\u03B8", 1.5*fact, auxline_stroke );
205 }
206
207 /* Ajusta transformação de rotação */
208 def_transf = g.getTransform();
209 AffineTransform curr_transf = g.getTransform();
210
211 curr_transf.translate( centro, centro );
212 curr_transf.rotate( driver.getSolver().getTheta() );
213 curr_transf.translate( -centro, -centro );
214 g.setTransform( curr_transf );
215
216 g.setColor( Color.white );
217 g.fill( quad );
218 g.setColor( Color.black );
219 g.draw( quad );
220
221 g.setStroke( arrow_stroke );
222
223 /* Desenha Sigma Theta */
224 if( Math.abs( driver.getSolver().SigmaTheta() ) > 0.01 )
225 {
226 g.setColor( Color.green.darker() );
227 if( driver.getSolver().SigmaTheta() > 0 )
228 {
229 x = centro + (aresta/2.0) + fact;
230 y = centro;
231 arrow.DrawArrow( g, x, y, 0.0, aresta/2.0,
232 Arrow2D.SIDE_LEAD, pi/4.0, aresta/10.0 );
233
234 x = centro - (aresta/2.0) - fact;
235 y = centro;
236 arrow.DrawArrow( g, x, y, pi, aresta/2.0,
237 Arrow2D.SIDE_LEAD, pi/4.0, aresta/10.0 );
238 }
239 else if( driver.getSolver().SigmaTheta() < 0 )
240 {
241 x = centro + (aresta/2.0) + fact;
242 y = centro;
243 arrow.DrawArrow( g, x, y, 0.0, aresta/2.0,
244 Arrow2D.SIDE_TRAIL, pi/4.0, aresta/10.0 );
245
246 x = centro - (aresta/2.0) - fact;
247 y = centro;
248 arrow.DrawArrow( g, x, y, pi, aresta/2.0,
249 Arrow2D.SIDE_TRAIL, pi/4.0, aresta/10.0 );
250 }
251 }
252
253 /* Desenha Sigma Theta+90 */
254 if( Math.abs( driver.getSolver().SigmaTheta90() ) > 0.01 )
255 {
256 g.setColor( Color.gray );
257 if( driver.getSolver().SigmaTheta90() > 0 )
258 {
259 x = centro;
260 y = centro + (aresta/2.0) + fact;
261 arrow.DrawArrow( g, x, y, pi/2, aresta/2.0,
262 Arrow2D.SIDE_LEAD, pi/4.0, aresta/10.0 );
263
264 x = centro;
265 y = centro - (aresta/2.0) - fact;
266 arrow.DrawArrow( g, x, y, 3*pi/2, aresta/2.0,
267 Arrow2D.SIDE_LEAD, pi/4.0, aresta/10.0 );
268 }
269 else if( driver.getSolver().SigmaTheta90() < 0 )
270 {
271 x = centro;
272 y = centro + (aresta/2.0) + fact;
273 arrow.DrawArrow( g, x, y, pi/2, aresta/2.0,
274 Arrow2D.SIDE_TRAIL, pi/4.0, aresta/10.0 );
275
276 x = centro;
277 y = centro - (aresta/2.0) - fact;
278 arrow.DrawArrow( g, x, y, 3*pi/2, aresta/2.0,
279 Arrow2D.SIDE_TRAIL, pi/4.0, aresta/10.0 );
280 }
281 }
282
283 /* Desenha Tau Theta */
284 if( Math.abs( driver.getSolver().TauTheta() ) > 0.01 )
285 {
286 if( driver.getSolver().TauTheta() < 0 )
287 {
288 g.setColor( Color.green.darker() );
289 x = centro + (aresta/2.0) + (fact/1.5);
290 y = centro - (aresta/2.0);
291 arrow.DrawArrow( g, x, y, pi/2, aresta,
292 Arrow2D.SIDE_LEAD_RIGHT, pi/4.0, aresta/10.0 );
293
294 x = centro - (aresta/2.0) - (fact/1.5);
295 y = centro + (aresta/2.0);
296 arrow.DrawArrow( g, x, y, 3*pi/2, aresta,
297 Arrow2D.SIDE_LEAD_RIGHT, pi/4.0, aresta/10.0 );
298
299 g.setColor( Color.gray );
300 x = centro - (aresta/2.0);
301 y = centro + (aresta/2.0) + (fact/1.5);
302 arrow.DrawArrow( g, x, y, 0.0, aresta,
303 Arrow2D.SIDE_LEAD_LEFT, pi/4.0, aresta/10.0 );
304
305 x = centro + (aresta/2.0);
306 y = centro - (aresta/2.0) - (fact/1.5);
307 arrow.DrawArrow( g, x, y, pi, aresta,
308 Arrow2D.SIDE_LEAD_LEFT, pi/4.0, aresta/10.0 );
309 }
310 else if( driver.getSolver().TauTheta() > 0 )
311 {
312 g.setColor( Color.green.darker() );
313 x = centro + (aresta/2.0) + (fact/1.5);
314 y = centro - (aresta/2.0);
315 arrow.DrawArrow( g, x, y, pi/2, aresta,
316 Arrow2D.SIDE_TRAIL_RIGHT, pi/4.0, aresta/10.0 );
317
318 x = centro - (aresta/2.0) - (fact/1.5);
319 y = centro + (aresta/2.0);
320 arrow.DrawArrow( g, x, y, 3*pi/2, aresta,
321 Arrow2D.SIDE_TRAIL_RIGHT, pi/4.0, aresta/10.0 );
322
323 g.setColor( Color.gray );
324 x = centro - (aresta/2.0);
325 y = centro + (aresta/2.0) + (fact/1.5);
326 arrow.DrawArrow( g, x, y, 0.0, aresta,
327 Arrow2D.SIDE_TRAIL_LEFT, pi/4.0, aresta/10.0 );
328
329 x = centro + (aresta/2.0);
330 y = centro - (aresta/2.0) - (fact/1.5);
331 arrow.DrawArrow( g, x, y, pi, aresta,
332 Arrow2D.SIDE_TRAIL_LEFT, pi/4.0, aresta/10.0 );
333 }
334 }
335
336 g.setColor( Color.black );
337 setTextAlignment( CENTER );
338
339 if( Math.abs( driver.getSolver().SigmaTheta() ) > 0.01 )
340 {
341 drawString( "\u03C3\u03B8", centro + aresta + (2.5*fact), centro );
342 drawString( "\u03C3\u03B8", centro - (aresta + (2.5*fact)), centro );
343 }
344
345 if( Math.abs( driver.getSolver().TauTheta() ) > 0.01 )
346 {
347 if( driver.getSolver().TauTheta() < 0 )
348 {
349 drawString( "\u03C4\u03B8", centro + ((aresta/2.0) + (2.3*fact)),
350 centro + (2.0*fact) );
351 drawString( "\u03C4\u03B8", centro - ((aresta/2.0) + (2.3*fact)),
352 centro - (2.0*fact) );
353 }
354 else if( driver.getSolver().TauTheta() > 0 )
355 {
356 drawString( "\u03C4\u03B8", centro + ((aresta/2.0) + (2.3*fact)),
357 centro - (2.0*fact) );
358 drawString( "\u03C4\u03B8", centro - ((aresta/2.0) + (2.3*fact)),
359 centro + (2.0*fact) );
360 }
361 }
362
363 g.setTransform( def_transf );
364 }
365
366 /**
367 * Handles the event of the user pressing down the mouse button.
368 */
369 public void mousePressedWC( MouseEvent e, Point2D.Double mouse_pos )
370 {
371 }
372
373 /**
374 * Handles the event of a user dragging the mouse while holding
375 * down the mouse button.
376 */
377 public void mouseDraggedWC( MouseEvent e, Point2D.Double mouse_pos )
378 {
379 }
380
381 /**
382 * Handles the event of a user releasing the mouse button.
383 */
384 public void mouseReleasedWC( MouseEvent e, Point2D.Double mouse_pos )
385 {
386 }
387 }
388