Forráskód Böngészése

udpate user guide, changed sketch yaml grammar

Gilbert Brault 5 éve
szülő
commit
6cb424f619

+ 102 - 95
jupysketch-doc/docs/learningbyexample.md

@@ -69,116 +69,123 @@ The general layout of a sketcher file is as follow:
 
 #### Libraries
 ```python
-libraries = {'name': "head",
-'shapes':"""\
-libraries: ["from math import tan, radians, sin, cos","from pysketcher import *"]"""}
+libraries = """\
+name: head
+shapes:
+    libraries: ["from math import tan, radians, sin, cos","from pysketcher import *"]
+"""
 ```
 #### Constants: Construction parameters
 ```python
-constants = {'name': "constants",
-'shapes':"""\
-fontsize: 18         # size of the characters
-g: 9.81              # constant gravity
-theta: 30.0          # inclined plane angle
-L: 10.0              # sketch sizing parameter
-a: 1.0               #
-xmin: 0.0            # sketech min Abscissa
-ymin: -3.0           # sketech min Ordinate     
-rl: 2.0              # rectangle width
-rL: 1.0              # rectangle length
-"""}
+constants = """\
+name: constants
+shapes:
+    fontsize: 18         # size of the characters
+    g: 9.81              # constant gravity
+    theta: 30.0          # inclined plane angle
+    L: 10.0              # sketch sizing parameter
+    a: 1.0               #
+    xmin: 0.0            # sketech min Abscissa
+    ymin: -3.0           # sketech min Ordinate     
+    rl: 2.0              # rectangle width
+    rL: 1.0              # rectangle length
+"""
 ```
 #### Frame: core geometric parameters
 ```python
-frame = {'name': "frame",
-'shapes':"""\
-setframe:            # sketch setup
-    action: "drawing_tool.set_coordinate_system(xmin=xmin-L/5, xmax=xmin+1.5*L,ymin=ymin, ymax=ymin+1.5*L,instruction_file='tmp_mpl_friction.py')"
-setblackline:        # default frame values and actions
-    action: "drawing_tool.set_linecolor('black')"
-B: point(a+L,0)                      # wall right end
-A: point(a,tan(radians(theta))*L)    # wall left end
-normal_vec: point(sin(radians(theta)),cos(radians(theta)))     # Vector normal to wall
-tangent_vec: point(cos(radians(theta)),-sin(radians(theta)))   # Vector tangent to wall
-help_line: Line(A,B)                 # wall line
-x: a + 3*L/10.                       # contact point Abscissa
-y: help_line(x=x)                    # contact point Ordinate
-contact: point(x, y)                 # contact point: middle of the rectangle bottom edge
-c: contact + rL/2*normal_vec
-"""}
+frame = """\
+name: frame
+shapes:
+    setframe:            # sketch setup
+        action: "drawing_tool.set_coordinate_system(xmin=xmin-L/5, xmax=xmin+1.5*L,ymin=ymin, ymax=ymin+1.5*L,instruction_file='tmp_mpl_friction.py')"
+    setblackline:        # default frame values and actions
+        action: "drawing_tool.set_linecolor('black')"
+    B: point(a+L,0)                      # wall right end
+    A: point(a,tan(radians(theta))*L)    # wall left end
+    normal_vec: point(sin(radians(theta)),cos(radians(theta)))     # Vector normal to wall
+    tangent_vec: point(cos(radians(theta)),-sin(radians(theta)))   # Vector tangent to wall
+    help_line: Line(A,B)                 # wall line
+    x: a + 3*L/10.                       # contact point Abscissa
+    y: help_line(x=x)                    # contact point Ordinate
+    contact: point(x, y)                 # contact point: middle of the rectangle bottom edge
+    c: contact + rL/2*normal_vec
+"""
 ```
 #### The body object
 ```python
-body={'name': "body",
-'shapes':"""\
-rectangle: 
-    formula: Rectangle(contact, rl, rL)
-    style:
-        linecolor: blue
-        filled_curves: blue
-    transform: ["rotate(-theta, contact)",
-                "translate(-rl/2*tangent_vec)"]
-N: 
-    formula: Force(contact - rl*normal_vec, contact, r'$N$', text_pos='start')
-    style:
-        linecolor: black
-wheel: 
-    formula: "Composition({'outer': rectangle})"   
-    style:
-        shadow: 1
-mc:
-    formula: Text(r'$c$', c)
-body: 
-    formula: "Composition({'wheel': wheel, 'N': N, 'mc': mc})"
-    style:
-        linecolor: black
-"""}
+body = """\
+name: body
+shapes:
+    rectangle: 
+        formula: Rectangle(contact, rl, rL)
+        style:
+            linecolor: blue
+            filled_curves: blue
+        transform: ["rotate(-theta, contact)",
+                    "translate(-rl/2*tangent_vec)"]
+    N: 
+        formula: Force(contact - rl*normal_vec, contact, r'$N$', text_pos='start')
+        style:
+            linecolor: black
+    wheel: 
+        formula: "Composition({'outer': rectangle})"   
+        style:
+            shadow: 1
+    mc:
+        formula: Text(r'$c$', c)
+    body: 
+        formula: "Composition({'wheel': wheel, 'N': N, 'mc': mc})"
+        style:
+            linecolor: black
+"""
 ```
 #### The plan object
 ```python
-plan={'name': "plan",
-'shapes':"""\
-mB:
-    formula: Text(r'$B$',B)
-mA:
-    formula: Text(r'$A$', A)
-wall: 
-    formula: Wall(x=[A[0], B[0]], y=[A[1], B[1]], thickness=-0.25,transparent=False)
-    style:
-        linecolor: black    
-x_const: 
-    formula: Line(contact, contact + point(0,4))
-    style:
-        linestyle: dotted
-    transform: rotate(-theta, contact)
-x_axis: 
-    formula: "Axis(start=contact+ 2*rl*normal_vec, length=2*rl,label='$x$', rotation_angle=-theta)"
-plan: 
-    formula: "Composition({'body': body, 'inclined wall': wall, 'x start': x_const, 'x axis': x_axis, 'mA': mA, 'mB': mB})"
-"""}
+plan = """\
+name: plan
+shapes:
+    mB:
+        formula: Text(r'$B$',B)
+    mA:
+        formula: Text(r'$A$', A)
+    wall: 
+        formula: Wall(x=[A[0], B[0]], y=[A[1], B[1]], thickness=-0.25,transparent=False)
+        style:
+            linecolor: black    
+    x_const: 
+        formula: Line(contact, contact + point(0,4))
+        style:
+            linestyle: dotted
+        transform: rotate(-theta, contact)
+    x_axis: 
+        formula: "Axis(start=contact+ 2*rl*normal_vec, length=2*rl,label='$x$', rotation_angle=-theta)"
+    plan: 
+        formula: "Composition({'body': body, 'inclined wall': wall, 'x start': x_const, 'x axis': x_axis, 'mA': mA, 'mB': mB})"
+"""
 ```
 #### The friction sketch
 ```python
-friction={'name': "friction",
-'shapes':"""\
-mg: 
-    formula: Gravity(c, rl, text='$Mg$')
-    style:
-        linecolor: black
-angle: 
-    formula: "Arc_wText(r'$<bslash>theta$', center=B, radius=3, start_angle=180-theta, arc_angle=theta, fontsize=fontsize)"
-    style:
-        linecolor: black
-        linewidth: 1
-ground: 
-     formula: Line((B[0]-L/10., 0), (B[0]-L/2.,0))
-     stlye:
-         linecolor: black
-         linestyle: dashed
-         linewidth: 1
-friction: 
-    formula: "Composition({'plan': plan, 'ground': ground, 'mg': mg, 'angle': angle})"
-"""}
+friction = """\
+name: friction
+shapes:
+    mg: 
+        formula: Gravity(c, rl, text='$Mg$')
+        style:
+            linecolor: black
+    angle: 
+        formula: "Arc_wText(r'$<bslash>theta$', center=B, radius=3, start_angle=180-theta, arc_angle=theta, fontsize=fontsize)"
+        style:
+            linecolor: black
+            linewidth: 1
+    ground: 
+         formula: Line((B[0]-L/10., 0), (B[0]-L/2.,0))
+         stlye:
+             linecolor: black
+             linestyle: dashed
+             linewidth: 1
+    friction: 
+            formula: "Composition({'plan': plan, 'ground': ground, 'mg': mg, 'angle': angle})"
+"""
 ```
 
 ### Using the parser

A különbségek nem kerülnek megjelenítésre, a fájl túl nagy
+ 1172 - 0
jupysketch-doc/docs/resources/DryFriction copy.ipynb


+ 102 - 95
jupysketch-doc/site/learningbyexample/index.html

@@ -554,116 +554,123 @@ A skertcher object is composed as follow:</p>
 </li>
 </ul>
 <h4 id="libraries">Libraries</h4>
-<pre><code class="python">libraries = {'name': &quot;head&quot;,
-'shapes':&quot;&quot;&quot;\
-libraries: [&quot;from math import tan, radians, sin, cos&quot;,&quot;from pysketcher import *&quot;]&quot;&quot;&quot;}
+<pre><code class="python">libraries = &quot;&quot;&quot;\
+name: head
+shapes:
+    libraries: [&quot;from math import tan, radians, sin, cos&quot;,&quot;from pysketcher import *&quot;]
+&quot;&quot;&quot;
 </code></pre>
 
 <h4 id="constants-construction-parameters">Constants: Construction parameters</h4>
-<pre><code class="python">constants = {'name': &quot;constants&quot;,
-'shapes':&quot;&quot;&quot;\
-fontsize: 18         # size of the characters
-g: 9.81              # constant gravity
-theta: 30.0          # inclined plane angle
-L: 10.0              # sketch sizing parameter
-a: 1.0               #
-xmin: 0.0            # sketech min Abscissa
-ymin: -3.0           # sketech min Ordinate     
-rl: 2.0              # rectangle width
-rL: 1.0              # rectangle length
-&quot;&quot;&quot;}
+<pre><code class="python">constants = &quot;&quot;&quot;\
+name: constants
+shapes:
+    fontsize: 18         # size of the characters
+    g: 9.81              # constant gravity
+    theta: 30.0          # inclined plane angle
+    L: 10.0              # sketch sizing parameter
+    a: 1.0               #
+    xmin: 0.0            # sketech min Abscissa
+    ymin: -3.0           # sketech min Ordinate     
+    rl: 2.0              # rectangle width
+    rL: 1.0              # rectangle length
+&quot;&quot;&quot;
 </code></pre>
 
 <h4 id="frame-core-geometric-parameters">Frame: core geometric parameters</h4>
-<pre><code class="python">frame = {'name': &quot;frame&quot;,
-'shapes':&quot;&quot;&quot;\
-setframe:            # sketch setup
-    action: &quot;drawing_tool.set_coordinate_system(xmin=xmin-L/5, xmax=xmin+1.5*L,ymin=ymin, ymax=ymin+1.5*L,instruction_file='tmp_mpl_friction.py')&quot;
-setblackline:        # default frame values and actions
-    action: &quot;drawing_tool.set_linecolor('black')&quot;
-B: point(a+L,0)                      # wall right end
-A: point(a,tan(radians(theta))*L)    # wall left end
-normal_vec: point(sin(radians(theta)),cos(radians(theta)))     # Vector normal to wall
-tangent_vec: point(cos(radians(theta)),-sin(radians(theta)))   # Vector tangent to wall
-help_line: Line(A,B)                 # wall line
-x: a + 3*L/10.                       # contact point Abscissa
-y: help_line(x=x)                    # contact point Ordinate
-contact: point(x, y)                 # contact point: middle of the rectangle bottom edge
-c: contact + rL/2*normal_vec
-&quot;&quot;&quot;}
+<pre><code class="python">frame = &quot;&quot;&quot;\
+name: frame
+shapes:
+    setframe:            # sketch setup
+        action: &quot;drawing_tool.set_coordinate_system(xmin=xmin-L/5, xmax=xmin+1.5*L,ymin=ymin, ymax=ymin+1.5*L,instruction_file='tmp_mpl_friction.py')&quot;
+    setblackline:        # default frame values and actions
+        action: &quot;drawing_tool.set_linecolor('black')&quot;
+    B: point(a+L,0)                      # wall right end
+    A: point(a,tan(radians(theta))*L)    # wall left end
+    normal_vec: point(sin(radians(theta)),cos(radians(theta)))     # Vector normal to wall
+    tangent_vec: point(cos(radians(theta)),-sin(radians(theta)))   # Vector tangent to wall
+    help_line: Line(A,B)                 # wall line
+    x: a + 3*L/10.                       # contact point Abscissa
+    y: help_line(x=x)                    # contact point Ordinate
+    contact: point(x, y)                 # contact point: middle of the rectangle bottom edge
+    c: contact + rL/2*normal_vec
+&quot;&quot;&quot;
 </code></pre>
 
 <h4 id="the-body-object">The body object</h4>
-<pre><code class="python">body={'name': &quot;body&quot;,
-'shapes':&quot;&quot;&quot;\
-rectangle: 
-    formula: Rectangle(contact, rl, rL)
-    style:
-        linecolor: blue
-        filled_curves: blue
-    transform: [&quot;rotate(-theta, contact)&quot;,
-                &quot;translate(-rl/2*tangent_vec)&quot;]
-N: 
-    formula: Force(contact - rl*normal_vec, contact, r'$N$', text_pos='start')
-    style:
-        linecolor: black
-wheel: 
-    formula: &quot;Composition({'outer': rectangle})&quot;   
-    style:
-        shadow: 1
-mc:
-    formula: Text(r'$c$', c)
-body: 
-    formula: &quot;Composition({'wheel': wheel, 'N': N, 'mc': mc})&quot;
-    style:
-        linecolor: black
-&quot;&quot;&quot;}
+<pre><code class="python">body = &quot;&quot;&quot;\
+name: body
+shapes:
+    rectangle: 
+        formula: Rectangle(contact, rl, rL)
+        style:
+            linecolor: blue
+            filled_curves: blue
+        transform: [&quot;rotate(-theta, contact)&quot;,
+                    &quot;translate(-rl/2*tangent_vec)&quot;]
+    N: 
+        formula: Force(contact - rl*normal_vec, contact, r'$N$', text_pos='start')
+        style:
+            linecolor: black
+    wheel: 
+        formula: &quot;Composition({'outer': rectangle})&quot;   
+        style:
+            shadow: 1
+    mc:
+        formula: Text(r'$c$', c)
+    body: 
+        formula: &quot;Composition({'wheel': wheel, 'N': N, 'mc': mc})&quot;
+        style:
+            linecolor: black
+&quot;&quot;&quot;
 </code></pre>
 
 <h4 id="the-plan-object">The plan object</h4>
-<pre><code class="python">plan={'name': &quot;plan&quot;,
-'shapes':&quot;&quot;&quot;\
-mB:
-    formula: Text(r'$B$',B)
-mA:
-    formula: Text(r'$A$', A)
-wall: 
-    formula: Wall(x=[A[0], B[0]], y=[A[1], B[1]], thickness=-0.25,transparent=False)
-    style:
-        linecolor: black    
-x_const: 
-    formula: Line(contact, contact + point(0,4))
-    style:
-        linestyle: dotted
-    transform: rotate(-theta, contact)
-x_axis: 
-    formula: &quot;Axis(start=contact+ 2*rl*normal_vec, length=2*rl,label='$x$', rotation_angle=-theta)&quot;
-plan: 
-    formula: &quot;Composition({'body': body, 'inclined wall': wall, 'x start': x_const, 'x axis': x_axis, 'mA': mA, 'mB': mB})&quot;
-&quot;&quot;&quot;}
+<pre><code class="python">plan = &quot;&quot;&quot;\
+name: plan
+shapes:
+    mB:
+        formula: Text(r'$B$',B)
+    mA:
+        formula: Text(r'$A$', A)
+    wall: 
+        formula: Wall(x=[A[0], B[0]], y=[A[1], B[1]], thickness=-0.25,transparent=False)
+        style:
+            linecolor: black    
+    x_const: 
+        formula: Line(contact, contact + point(0,4))
+        style:
+            linestyle: dotted
+        transform: rotate(-theta, contact)
+    x_axis: 
+        formula: &quot;Axis(start=contact+ 2*rl*normal_vec, length=2*rl,label='$x$', rotation_angle=-theta)&quot;
+    plan: 
+        formula: &quot;Composition({'body': body, 'inclined wall': wall, 'x start': x_const, 'x axis': x_axis, 'mA': mA, 'mB': mB})&quot;
+&quot;&quot;&quot;
 </code></pre>
 
 <h4 id="the-friction-sketch">The friction sketch</h4>
-<pre><code class="python">friction={'name': &quot;friction&quot;,
-'shapes':&quot;&quot;&quot;\
-mg: 
-    formula: Gravity(c, rl, text='$Mg$')
-    style:
-        linecolor: black
-angle: 
-    formula: &quot;Arc_wText(r'$&lt;bslash&gt;theta$', center=B, radius=3, start_angle=180-theta, arc_angle=theta, fontsize=fontsize)&quot;
-    style:
-        linecolor: black
-        linewidth: 1
-ground: 
-     formula: Line((B[0]-L/10., 0), (B[0]-L/2.,0))
-     stlye:
-         linecolor: black
-         linestyle: dashed
-         linewidth: 1
-friction: 
-    formula: &quot;Composition({'plan': plan, 'ground': ground, 'mg': mg, 'angle': angle})&quot;
-&quot;&quot;&quot;}
+<pre><code class="python">friction = &quot;&quot;&quot;\
+name: friction
+shapes:
+    mg: 
+        formula: Gravity(c, rl, text='$Mg$')
+        style:
+            linecolor: black
+    angle: 
+        formula: &quot;Arc_wText(r'$&lt;bslash&gt;theta$', center=B, radius=3, start_angle=180-theta, arc_angle=theta, fontsize=fontsize)&quot;
+        style:
+            linecolor: black
+            linewidth: 1
+    ground: 
+         formula: Line((B[0]-L/10., 0), (B[0]-L/2.,0))
+         stlye:
+             linecolor: black
+             linestyle: dashed
+             linewidth: 1
+    friction: 
+            formula: &quot;Composition({'plan': plan, 'ground': ground, 'mg': mg, 'angle': angle})&quot;
+&quot;&quot;&quot;
 </code></pre>
 
 <h3 id="using-the-parser">Using the parser</h3>

A különbségek nem kerülnek megjelenítésre, a fájl túl nagy
+ 1172 - 0
jupysketch-doc/site/resources/DryFriction copy.ipynb


A különbségek nem kerülnek megjelenítésre, a fájl túl nagy
+ 1 - 1
jupysketch-doc/site/search/search_index.json


+ 5 - 5
jupysketch-doc/site/sitemap.xml

@@ -1,23 +1,23 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"><url>
      <loc>None</loc>
-     <lastmod>2020-08-05</lastmod>
+     <lastmod>2020-08-06</lastmod>
      <changefreq>daily</changefreq>
     </url><url>
      <loc>None</loc>
-     <lastmod>2020-08-05</lastmod>
+     <lastmod>2020-08-06</lastmod>
      <changefreq>daily</changefreq>
     </url><url>
      <loc>None</loc>
-     <lastmod>2020-08-05</lastmod>
+     <lastmod>2020-08-06</lastmod>
      <changefreq>daily</changefreq>
     </url><url>
      <loc>None</loc>
-     <lastmod>2020-08-05</lastmod>
+     <lastmod>2020-08-06</lastmod>
      <changefreq>daily</changefreq>
     </url><url>
      <loc>None</loc>
-     <lastmod>2020-08-05</lastmod>
+     <lastmod>2020-08-06</lastmod>
      <changefreq>daily</changefreq>
     </url>
 </urlset>

BIN
jupysketch-doc/site/sitemap.xml.gz


A különbségek nem kerülnek megjelenítésre, a fájl túl nagy
+ 131 - 124
notebooks/.ipynb_checkpoints/DryFriction-checkpoint.ipynb


A különbségek nem kerülnek megjelenítésre, a fájl túl nagy
+ 131 - 124
notebooks/DryFriction.ipynb


BIN
notebooks/friction.png


+ 12 - 9
pysketcher/shapes.py

@@ -58,7 +58,10 @@ def sketchParse(sketch, container):
         - all the shapes needed to create the shapes it defines
     """
     yaml = YAML()
-    gwd = yaml.load(sketch["shapes"])
+    psketch = yaml.load(sketch)
+
+    sketch_name = psketch["name"]
+    gwd = psketch['shapes']
     
     for _k in list(gwd.keys()):
         if _k == "stop":
@@ -67,7 +70,7 @@ def sketchParse(sketch, container):
         _t = str(type(_c))
         if _k == "libraries":
             for l in _c:
-                _r = sVe(_k, l, container, sketch["name"])
+                _r = sVe(_k, l, container, sketch_name)
                 if type(_r) == str:
                     print(_r)
                     return False
@@ -78,7 +81,7 @@ def sketchParse(sketch, container):
             _expression = f"{_c}".replace("<bslash>","\\") 
             _formula = f"{_k} = {_expression}"
             #print(_formula)
-            _r = sVe(_k, _expression, container, sketch["name"])
+            _r = sVe(_k, _expression, container, sketch_name)
             if type(_r) == str:
                 print(_r)
                 return False
@@ -91,15 +94,15 @@ def sketchParse(sketch, container):
                 _expression = f"{_c['formula']}".replace("<bslash>","\\") 
                 _formula = f"{_k} = {_expression}"
                 #print(_formula)
-                _r = sVe(_k, _expression, container, sketch["name"])
+                _r = sVe(_k, _expression, container, sketch_name)
                 if type(_r) == str:
                     print(_r)
                     return False
                 exec(_formula,container)
                 # if the new object is a shape and has the sketch name, set this shape name as the sketch name
                 if issubclass(type(container[_k]), Shape):
-                    if _k == sketch['name']:
-                        container[_k].set_name(sketch['name'])
+                    if _k == sketch_name:
+                        container[_k].set_name(sketch_name)
             if 'style' in _keys:
                 for _style in _c["style"]:
                     #  x_const.set_linestyle('dotted')
@@ -117,7 +120,7 @@ def sketchParse(sketch, container):
                 if str(type(_c['transform'])) == "<class 'str'>":
                     _t = f"{_k}.{_c['transform']}"
                     #print(_t)
-                    _r = sVe(_k, _formula, container, sketch["name"])
+                    _r = sVe(_k, _formula, container, sketch_name)
                     if type(_r) == str:
                         print(_r)
                         return False
@@ -127,7 +130,7 @@ def sketchParse(sketch, container):
                     #  x_const.rotate(-theta, contact)
                         _t = f"{_k}.{_transform}"
                         #print(_t)
-                        _r = sVe(_k, _t, container, sketch["name"])
+                        _r = sVe(_k, _t, container, sketch_name)
                         if type(_r) == str:
                             print(_r)
                             return False
@@ -135,7 +138,7 @@ def sketchParse(sketch, container):
             if "action" in _keys:
                 _action = _c["action"]
                 #print(_action)
-                _r = sVe(_k, _action, container, sketch["name"])
+                _r = sVe(_k, _action, container, sketch_name)
                 if type(_r) == str:
                     print(_r)
                     return False

+ 1 - 0
requirements.txt

@@ -4,3 +4,4 @@ numpy
 Pillow
 matplotlib
 ipympl
+scipy