# Antiderivative Maplet
# Copyright 2002 Waterloo Maple Inc.
# 
# The Antiderivative maplet graphically illustrates the concept of an antiderivative of a function.  
# 
# The user enters a function f(x) and a range on the x-axis [a,b]. If the user provides an initial value for the antiderivative of f(x), the maplet plots the antiderivative that satisfies the initial value condition.
# 
# To run this maplet, click the Execute (!!!) button in the context bar.
# 
restart;
AntiderivativeMaplet := module()

############################################################

export getAntiderivativePlot, runAntiderivativeMaplet:
local helpStr, valueStr, defStr:

############################################################


############################################################

helpStr := 
"O maplet antiderivativo graficamente ilustra o conceito da antiderivativa de uma função.  
Entre com uma função f(x) e o alcance do eixo x [a,b].  Clique em 'Plotar'.  Forneça um valor para a antiderivativa de f(x). O maplet plota a antiderivativa que satisfaz a condição do valor inicial.":

defStr:= 
"<math><mrow>
<mtext fontsize=18 fontweight=bold>Antiderivative</mtext>
<mtext>&NewLine;</mtext>
<mtext fontsize=16>Uma antiderivativa da função f é uma função F de forma que Diff(F(x), x) = f(x) sempre que a f(x) é definida.</mtext>
<munderover><mo>&Integral;</mo><mi>a</mi><mi>b</mi></munderover><msqrt><mfenced><mrow><mn>1</mn><mo>+</mo><msup><mfenced><mrow><mfrac><mo>&DifferentialD;</mo><mrow><mo>&DifferentialD;</mo><mi>x</mi></mrow></mfrac><mrow><mi>f</mi><mo>&ApplyFunction;</mo><mfenced><mi>x</mi></mfenced></mrow></mrow></mfenced><mn>2</mn></msup></mrow></mfenced></msqrt><mo>&InvisibleTimes;</mo><mrow><mo>&DifferentialD;</mo><mi>x</mi></mrow>
</mrow></math>":
:

valueStr := 
"Este valor algébrico, vetor, ou lista determina a antiderivativa primária.  Qualquer valor algébrico, vetor, ou lista pode ser digitado.  Se nenhum valor inicial for digitado, a antiderivativa primária plotada é aquela para a qual o valor no último ponto da esquerda (a) é 0.  

Um valor algébrico, como 0 ou Pi, para esta opção especifica o valor da antiderivativa no último ponto da esquerda do alcance.  Um vetor ou lista de 2 dimensões, como [0,0], especifica o valor da antiderivativa neste ponto.":

############################################################


############################################################

getAntiderivativePlot := proc(boo1, boo2, boo3)

  local temp, temp2, str, view:
 
  use Maplets:-Tools in

    str:=StringTools:-Trim(Get('TF_fun')):
    if str="" then 
      error "Nenhuma função digitada no campo de texto: TF_fun":
    end if:

    temp:=StringTools:-Trim(Get('TF_a')):
    temp2:=StringTools:-Trim(Get('TF_b')):
    if temp<>"" and temp2<>"" then
      str:=cat(str, ", ", temp, "..", temp2):
    end if:

if not(boo1 or boo2 or boo3) then 
      return plots[textplot]([1,2,"Escolha uma função, antiderivativa, ou classe de antiderivativas"]):
    end if: 
    if not boo1 then str := cat(str, ", showfunction=false") end if:
    if not boo2 then str := cat(str, ", showantiderivative=false") end if:
    if boo3 then str := cat(str, ", showclass=true") end if:

    temp:=StringTools:-Trim(Get('TF_value')):
    if temp<>"" then
      str := cat(str, ", value=", temp):
    end if:

    view := ["DEFAULT","DEFAULT"]:

    temp:=StringTools:-Trim(Get('x1')):
    temp2:=StringTools:-Trim(Get('x2')):
    if temp<>"" and temp2<>"" then
      view[1]:=cat(temp, "..", temp2):
    end if: 

    temp:=StringTools:-Trim(Get('y1')):
    temp2:=StringTools:-Trim(Get('y2')):
    if temp<>"" and temp2<>"" then
      view[2]:=cat(temp, "..", temp2):
    end if: 

    temp:=cat(", view=[", view[1], ", ", view[2], "]"):
    str := cat(str, temp):

    Student:-Calculus1:-AntiderivativePlot(eval(parse(str))):

  end use: 

end proc:

############################################################


############################################################
runAntiderivativeMaplet := proc()

local maplet:
use Maplets:-Elements in

############################################################

maplet := Maplet( 
  'onstartup'=RunWindow('mainWin'),

############################################################

  Font['F1']('family'="Default", 'bold'='true', 'italic'='true'),
  Font['F2']('family'="Default", 'bold'='true', 'size'=14),

############################################################

  MenuBar['MB'](
    Menu("Arquivo", 
      MenuItem("Plotar", 
        'onclick'=Evaluate( 'P' = 'getAntiderivativePlot(CB1,CB2,CB3)' ) ),
      MenuSeparator(),
      MenuItem("Fechar", 'onclick'=Shutdown())
    ), # end Menu/File
    Menu("Ajuda", 
      MenuItem("Usando este Maplet", 'onclick'=RunWindow('helpWin'))
    ) # end menu/Help
  ), # end MenuBar 

############################################################

  Window['mainWin']('resizable'='true', 
    'title'="Cálculo 1 - Antiderivativa",
    'menubar'='MB', 'defaultbutton'='B_plot', 
    
    BoxRow('inset'=0, 'spacing'=0, 'background'="#DDFFFF",  

      BoxColumn('inset'=0, 'spacing'=0, 'background'="#DDFFFF", 
        'border'='true', 'caption'="Janela de Plotagem", 
        Plotter['P']('background'="#EEFFFF")
      ), # end BoxRow
 
     BoxColumn('inset'=0, 'spacing'=0, 'background'="#DDFFFF", 'border'='false',

         BoxRow('inset'=0, 'spacing'=0, 'background'="#DDFFFF", 
          'border'='true', 'caption'="Digite uma função e o intervalo de plotagem (opcional)",  
          Label("Função ", 'font'='F2', 'background'="#DDFFFF"), 
          TextField['TF_fun']('width'=15, 'background'="#EEFFFF", 
            'tooltip'="Contínuo em [a,b], diferenciável em (a,b)",
            'value'=3*x^2),
          Label(" a ", 'font'='F2', 'background'="#DDFFFF"), 
          Label(" = ", 'font'='F1', 'background'="#DDFFFF"), 
          TextField['TF_a']('value'=-2, 'width'=3, 'background'="#EEFFFF", 
            'tooltip'="Ponto final inferior"),
          Label(" b ", 'font'='F2', 'background'="#DDFFFF"), 
          Label(" = ", 'font'='F1', 'background'="#DDFFFF"), 
          TextField['TF_b']('value'=2, 'width'=3, 'background'="#EEFFFF", 
            'tooltip'="Ponto final superior")
      ), # end BoxRow 
 
      BoxRow('inset'=0, 'spacing'=2, 'background'="#DDFFFF", 
        'border'='true', 
        'caption'="Valor inicial da antiderivativa primária", 
          Label(" Valor", 'font'='F2', 'background'="#DDFFFF"), 
          TextField['TF_value']('width'=15, 
             'background'="#EEFFFF", 'value'=0),
          Button("O que é isto?", 'background'="#DDFFFF",  
            'onclick'=RunWindow(valueWin))
      ), # end BoxRow

      BoxRow('inset'=0, 'spacing'=0, 'background'="#DDFFFF", 
 
        BoxColumn('inset'=0, 'spacing'=0, 'background'="#DDFFFF", 
          'border'='true', 'caption'="Opções",  
          
BoxRow('inset'=0, 'spacing'=0, 'background'="#DDFFFF",
            CheckBox[CB1]('value'=true, 'background'="#DDFFFF", 
              'caption'="Mostrar função"    
            ), # end CheckBox
            CheckBox[CB2]('value'=true, 'background'="#DDFFFF", 
              'caption'="Mostrar uma antiderivativa"    
            ) # end CheckBox
), # end BoxRow

        BoxRow('inset'=0, 'spacing'=0, 'background'="#DDFFFF",            CheckBox[CB3]('value'=false, 'background'="#DDFFFF", 
              'caption'="Mostrar classe de antiderivativas"    
            ) # end CheckBox 
 ), # end BoxRow

        BoxRow('inset'=0, 'spacing'=0, 'background'="#DDFFFF",
            Label("x", 'font'='F2', 'background'="#DDFFFF"), 
            Label(" = ", 'font'='F1', 'background'="#DDFFFF"),
            TextField['x1'](2, 'background'="#EEFFFF"), 
            Label("..", 'font'='F2', 'background'="#DDFFFF"),
            TextField['x2'](2, 'background'="#EEFFFF"),
            Label(" y", 'font'='F2', 'background'="#DDFFFF"), 
            Label(" = ", 'font'='F1', 'background'="#DDFFFF"),
            TextField['y1'](2, 'background'="#EEFFFF"),
            Label("..", 'font'='F2', 'background'="#DDFFFF"),
            TextField['y2'](2, 'background'="#EEFFFF") 
          ) # end BoxRow
                       
        )),  # end BoxColumn

        BoxRow('inset'=0, 'spacing'=4, 'background'="#DDFFFF",
            'halign'=center, 
            Button['B_plot']("  Plotar  ", 'background'="#EEFFFF", 
              'onclick'=Evaluate( 'P' = 'getAntiderivativePlot(CB1,CB2,CB3)' ) 
            ), # end Button
            Button("Fechar", 'background'="#EEFFFF", Shutdown())    
        )  # end BoxColumn

      ) # end BoxRow
  
    ) # end BoxColumn

  ), # end Window

############################################################

  Window['helpWin']( 'resizable'='false',
    'title'="Usando o Maplet de antiderivativa",
    BoxColumn('border'='true', 'inset'=0, 'spacing'=5,
      'background'="#CCFFFF",
      BoxCell(
        TextBox('height'=9, 'width'=26,
          'background'="#DDFFFF", 'foreground'="#333399", 
          'editable'='false', 'font'='F2', 
          'value'=helpStr
        ) # end TextBox
      ), # end BoxCell
      BoxRow('inset'=0, 'spacing'=0, 'background'="#CCFFFF",
        Button("Fechar",          CloseWindow('helpWin'), 
          'background'="#DDFFFF")
      ) # end BoxRow
    ) # end BoxColumn
  ),  # end helpWin

############################################################

  Window['valueWin']( 'resizable'='false',
    'title'="O valor inicial da antiderivativa primária",
    BoxColumn('border'='true', 'inset'=0, 'spacing'=5,
      'background'="#CCFFFF",
      BoxCell(
         TextBox['ML_def']('height'=15, 'width'=26, 'value'=valueStr, 'height'=15, 'width'=26, 'background'="#CCFFFF", 'foreground'="#333399", 'font'='F2', 'editable'='false')
              ), # end BoxRow
      BoxRow('background'="#CCFFFF", 'inset'=0, 'spacing'=0, 'background'="#CCFFFF",
        Button("Fechar", 'font'='F2', CloseWindow('valueWin'), 
          'background'="#DDFFFF", 'foreground'="#333399")
      ) # end BoxRow
    ) # end BoxColumn
  ),  # end valueWin

############################################################

  Action['A']()

############################################################

): # end Maplet

############################################################

Maplets:-Display(maplet):

end use: # end use
end proc: # end proc
############################################################


end module: # end AntiderivativeMaplet
AntiderivativeMaplet:-runAntiderivativeMaplet();


















