now sphinxdoc works

This commit is contained in:
Dave Cowden 2013-04-23 20:33:39 -04:00
parent 59d2af7a6c
commit 977eb08657
13 changed files with 178 additions and 64 deletions

2
.gitignore vendored
View File

@ -1,2 +1,2 @@
*.pyc *.pyc
sphinxdoc/_build/* doc/_build/*

View File

@ -1,21 +1,3 @@
"""
Copyright (C) 2011-2013 Parametric Products Intellectual Holdings, LLC
This file is part of CadQuery.
CadQuery is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
CadQuery is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; If not, see <http://www.gnu.org/licenses/>
"""
#these items point to the freecad implementation #these items point to the freecad implementation
@ -26,14 +8,13 @@ from .freecad_impl import exporters
#these items are the common implementation #these items are the common implementation
#the order of these matter #the order of these matter
from . import selectors from .selectors import NearestToPointSelector,ParallelDirSelector,DirectionSelector,PerpendicularDirSelector,TypeSelector,DirectionMinMaxSelector,StringSyntaxSelector,Selector
from .CQ import CQ,CQContext,Workplane from .CQ import CQ,CQContext,Workplane
__all__ = [ __all__ = [
'CQ','Workplane','plugins','selectors','Plane','BoundBox','Matrix','Vector','sortWiresByBuildOrder', 'CQ','Workplane','plugins','selectors','Plane','BoundBox','Matrix','Vector','sortWiresByBuildOrder',
'Shape','Vertex','Edge','Wire','Solid','Shell','Compound','exporters', 'Shape','Vertex','Edge','Wire','Solid','Shell','Compound','exporters', 'NearestToPointSelector','ParallelDirSelector','DirectionSelector','PerpendicularDirSelector','TypeSelector','DirectionMinMaxSelector','StringSyntaxSelector','Selector','plugins'
'plugins'
] ]
__version__ = 0.9 __version__ = 0.9

85
cadquery/cq_directive.py Normal file
View File

@ -0,0 +1,85 @@
"""
A special directive for including a cq object.
"""
import sys, os, shutil, imp, warnings, cStringIO, re,traceback
from cadquery import *
import StringIO
from docutils.parsers.rst import directives
template = """
.. raw:: html
<div class="cq" style="text-align:%(txtAlign)s;float:left;">
%(outSVG)s
</div>
<div style="clear:both;">
</div>
"""
template_content_indent = ' '
def cq_directive(name, arguments, options, content, lineno,
content_offset, block_text, state, state_machine):
#only consider inline snippets
plot_code = '\n'.join(content)
# Since we don't have a filename, use a hash based on the content
#the script must define a variable called 'out', which is expected to
#be a CQ object
outSVG = "Your Script Did not assign the 'result' variable!"
try:
_s = StringIO.StringIO()
exec(plot_code)
exporters.exportShape(result,"SVG",_s)
outSVG = _s.getvalue()
except:
traceback.print_exc()
outSVG = traceback.format_exc()
#now out
# Now start generating the lines of output
lines = []
#get rid of new lines
outSVG = outSVG.replace('\n','')
txtAlign = "left"
if options.has_key("align"):
txtAlign = options['align']
lines.extend((template % locals()).split('\n'))
lines.extend(['::', ''])
lines.extend([' %s' % row.rstrip()
for row in plot_code.split('\n')])
lines.append('')
if len(lines):
state_machine.insert_input(
lines, state_machine.input_lines.source(0))
return []
def setup(app):
setup.app = app
setup.config = app.config
setup.confdir = app.confdir
options = {'height': directives.length_or_unitless,
'width': directives.length_or_percentage_or_unitless,
'align': directives.unchanged
}
app.add_directive('cq_plot', cq_directive, True, (0, 2, 0), **options)

View File

@ -51,6 +51,7 @@ def exportShape(shape,exportType,fileLike,tolerance=0.1):
The object should be already open and ready to write. The caller is responsible The object should be already open and ready to write. The caller is responsible
for closing the object for closing the object
""" """
if isinstance(shape,cadquery.CQ): if isinstance(shape,cadquery.CQ):
shape = shape.val() shape = shape.val()
@ -243,7 +244,7 @@ def getSVG(shape,opts=None):
""" """
d = {'width':800,'height':240,'marginLeft':200,'marginTop':20} d = {'width':800,'height':240,'marginLeft':200,'marginTop':20}
if opts: if opts:
d.update(opts) d.update(opts)

View File

@ -4,12 +4,11 @@
CadQuery API Reference CadQuery API Reference
*********************** ***********************
.. automodule:: cadfile.cadutils.cadquery
.. seealso:: .. seealso::
This page lists api methods grouped by functional area. This page lists api methods grouped by functional area.
Use :ref:`classreference` to see methods alphabetically by class. Use :ref:`classreference` to see methods alphabetically by class.
Don't see a method you want? see :ref:`extending`
Primary Objects Primary Objects
---------------- ----------------
@ -25,6 +24,8 @@ The sections below list methods of these objects grouped by **functional area**
Initialization Initialization
---------------- ----------------
.. automodule:: cadquery
Creating new workplanes and object chains Creating new workplanes and object chains
.. autosummary:: .. autosummary::
@ -69,7 +70,6 @@ Creating 2-d constructs that can be used to create 3 d features
Methods that create 3d features Methods that create 3d features
.. autosummary:: .. autosummary::
Workplane.cboreHole Workplane.cboreHole
Workplane.cskHole Workplane.cskHole
Workplane.hole Workplane.hole
@ -129,6 +129,7 @@ Selectors
Objects that filter and select CAD objects Objects that filter and select CAD objects
.. autosummary:: .. autosummary::
NearestToPointSelector NearestToPointSelector
ParallelDirSelector ParallelDirSelector

View File

@ -1,6 +1,6 @@
.. _cadquerybasics: .. _cadquerybasics:
.. automodule:: cadfile.cadutils.cadquery .. automodule:: cadquery
************************* *************************
Introduction to CadQuery Introduction to CadQuery
@ -21,7 +21,7 @@ CadQuery strives to allow scripts to read roughly as a human would describe an o
For example, consider this object: For example, consider this object:
.. image:: quickstart.png .. image:: _static/quickstart.png
A human would describe this as: A human would describe this as:

View File

@ -10,7 +10,7 @@ This page documents all of the methods and functions of the CadQuery classes, or
For a listing organized by functional area, see the :ref:`apireference` For a listing organized by functional area, see the :ref:`apireference`
.. automodule:: cadfile.cadutils.cadquery .. automodule:: cadquery
Core Classes Core Classes
--------------------- ---------------------
@ -20,6 +20,20 @@ Core Classes
Plane Plane
Workplane Workplane
Primitives
-----------------
.. autosummary::
Plane
Vector
Solid
Shell
Wire
Edge
Vertex
Selectors Selectors
--------------------- ---------------------
@ -33,7 +47,47 @@ Selectors
DirectionMinMaxSelector DirectionMinMaxSelector
StringSyntaxSelector StringSyntaxSelector
Classes Geometry Classes
------------------
.. autoclass:: Vector
:members:
.. autoclass:: Plane
:members:
Shape Base Class
-------------------
All objects inherit from Shape, which as basic manipulation methods:
.. autoclass:: Shape
:members:
Primitive Classes
--------------------
.. autoclass:: Solid
:members:
.. autoclass:: Shell
:members:
.. autoclass:: Wire
:members:
.. autoclass:: Edge
:members:
.. autoclass:: Vertex
:members:
Core Classes
------------------------ ------------------------
.. autoclass:: CQ .. autoclass:: CQ
@ -46,6 +100,10 @@ Classes
:members: :members:
:inherited-members: :inherited-members:
Selector Classes
------------------------
.. autoclass:: Selector .. autoclass:: Selector
:members: :members:

View File

@ -12,9 +12,12 @@
# serve to show the default. # serve to show the default.
import sys, os import sys, os
import os.path
print "working path is %s" % os.getcwd()
sys.path.append("..")
import cadquery import cadquery
settings._target = None #settings._target = None
# If extensions (or modules to document with autodoc) are in another directory, # If extensions (or modules to document with autodoc) are in another directory,
@ -29,7 +32,7 @@ settings._target = None
# Add any Sphinx extension module names here, as strings. They can be extensions # Add any Sphinx extension module names here, as strings. They can be extensions
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones. # coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.viewcode', 'sphinx.ext.autosummary','cadfile.cadutils.cq_directive'] extensions = ['sphinx.ext.autodoc', 'sphinx.ext.viewcode', 'sphinx.ext.autosummary','cadquery.cq_directive']
# Add any paths that contain templates here, relative to this directory. # Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates'] templates_path = ['_templates']

View File

@ -4,8 +4,8 @@
CadQuery Examples CadQuery Examples
********************************* *********************************
.. automodule:: cadfile.cadutils.cadquery .. automodule:: cadquery
.. automodule:: cadfile.cadutils.cad
The examples on this page can help you learn how to build objects with CadQuery. The examples on this page can help you learn how to build objects with CadQuery.
@ -387,7 +387,7 @@ You can create a rotated work plane by specifying angles of rotation relative to
.. cq_plot:: .. cq_plot::
result = Workplane("front").box(4.0,4.0,0.25).faces(">Z").workplane() \ result = Workplane("front").box(4.0,4.0,0.25).faces(">Z").workplane() \
.transformed(offset=cad.Vector(0,-1.5,1.0),rotate=cad.Vector(60,0,0)) \ .transformed(offset=Vector(0,-1.5,1.0),rotate=Vector(60,0,0)) \
.rect(1.5,1.5,forConstruction=True).vertices().hole(0.25) .rect(1.5,1.5,forConstruction=True).vertices().hole(0.25)
.. topic:: Api References .. topic:: Api References

View File

@ -3,15 +3,10 @@
You can adapt this file completely to your liking, but it should at least You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive. contain the root `toctree` directive.
Parametric Parts Documentation Home CadQuery Documentation Home
=================================== ===================================
Parametric Parts is a technology platform that offers:
* **For Users**: Customize, download, and print models easily using only a web browser. Every model is parametric.
* **For Designers**: Create models with an easy to use, fluent API called CadQuery. ( See :ref:`examples` )
* **For Developers**: :ref:`buildservice` allows other technology platforms to build models while controlling the user
experience
Contents Contents
@ -22,17 +17,12 @@ Contents
intro.rst intro.rst
quickstart.rst quickstart.rst
fileformat.rst
cadquerybasics.rst cadquerybasics.rst
examples.rst examples.rst
apireference.rst apireference.rst
primitiveref.rst
selectors.rst selectors.rst
classreference.rst classreference.rst
restservice.rst
roadmap.rst
Indices and tables Indices and tables
================== ==================

View File

@ -4,15 +4,9 @@
Introduction Introduction
********************* *********************
What is a ParametricParts Model Script? What is CadQuery
======================================== ========================================
A Model Script is a python script that builds a 3d model in response to user inputs.
Model Scripts are written in python. They can use two different APIs:
1. FreeCAD Scripts, or
2. a new, fluent-api called CadQuery.
CadQuery is an intuitive, easy-to-use language for building parametric 3D CAD models. It has several goals: CadQuery is an intuitive, easy-to-use language for building parametric 3D CAD models. It has several goals:
* Build models with scripts that are as close as possible to how you'd describe the object to a human. * Build models with scripts that are as close as possible to how you'd describe the object to a human.
@ -28,7 +22,7 @@ CadQuery is a Python module that provides a high-level wrapper around the
(`FreeCAD <http://sourceforge.net/apps/mediawiki/free-cad/index.php?title=Main_Page>`_) python libraries. (`FreeCAD <http://sourceforge.net/apps/mediawiki/free-cad/index.php?title=Main_Page>`_) python libraries.
Where does the name CadQuery come from? Where does the name CadQuery come from?
=============================== ========================================
CadQuery is inspired by ( `jQuery <http://www.jquery.com>`_ ), a popular framework that CadQuery is inspired by ( `jQuery <http://www.jquery.com>`_ ), a popular framework that
revolutionized web development involving javascript. revolutionized web development involving javascript.
@ -44,7 +38,7 @@ If you are familiar with how jQuery, you will probably recognize several jQuery
Why ParametricParts instead of OpenSCAD? Why ParametricParts instead of OpenSCAD?
================================== ============================================
CadQuery is based on FreeCAD,which is in turn based on the OpenCascade modelling kernel. CadQuery/FreeCAD scripts CadQuery is based on FreeCAD,which is in turn based on the OpenCascade modelling kernel. CadQuery/FreeCAD scripts
share many features with OpenSCAD, another open source, script based, parametric model generator. share many features with OpenSCAD, another open source, script based, parametric model generator.

View File

@ -1,10 +1,10 @@
.. module:: cadfile.cadutils.cadquery .. module:: cadquery
.. _quickstart: .. _quickstart:
*********************** ***********************
ModelScript QuickStart CadQuery QuickStart
*********************** ***********************
Want a quick glimpse of Parametric Parts ModelScripts? You're at the right place! Want a quick glimpse of Parametric Parts ModelScripts? You're at the right place!
@ -51,7 +51,7 @@ CadQuery comes with an online, interactive default model as a starting point.
You should see the dynamic model creator page, which will display a sample model: You should see the dynamic model creator page, which will display a sample model:
.. image:: quickstart-1.png .. image:: _static/quickstart-1.png
Take a minute to play with this model. Here are a few things to try: Take a minute to play with this model. Here are a few things to try:
@ -111,7 +111,7 @@ Now, modify the build script to use your width value to make the block by chang
The value property always returns the ``user-adjusted`` value of the parameter. That's good enough for now. The value property always returns the ``user-adjusted`` value of the parameter. That's good enough for now.
Click "Save Changes" and you should see your 80x60x10mm base plate, like this: Click "Save Changes" and you should see your 80x60x10mm base plate, like this:
.. image:: quickstart-2.png .. image:: _static/quickstart-2.png
If you'd like to come back to this model later, the url bar links to the newly created part. If you'd like to come back to this model later, the url bar links to the newly created part.
@ -135,7 +135,7 @@ This modification will do the trick:
Rebuild your model by clicking "Save Model" at the bottom. Your block should look like this: Rebuild your model by clicking "Save Model" at the bottom. Your block should look like this:
.. image:: quickstart-3.png .. image:: _static/quickstart-3.png
The code is pretty compact, and works like this: The code is pretty compact, and works like this:
@ -179,7 +179,7 @@ Good news!-- we can get the job done with just two lines of code. Here's the cod
You should see something like this: You should see something like this:
.. image:: quickstart-4.png .. image:: _static/quickstart-4.png
Lets Break that down a bit Lets Break that down a bit
^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -267,7 +267,7 @@ We can do that using the preset dictionaries in the parameter definition:
Now save the model and have a look at the preset DDLB-- you'll see that you can easily switch between these Now save the model and have a look at the preset DDLB-- you'll see that you can easily switch between these
configurations: configurations:
.. image:: quickstart-5.png .. image:: _static/quickstart-5.png
Done! Done!
@ -300,6 +300,5 @@ Want to learn more?
==================== ====================
* The :ref:`examples` contains lots of examples demonstrating cadquery features * The :ref:`examples` contains lots of examples demonstrating cadquery features
* The :ref:`cadquery_reference` describes the file format in detail
* The :ref:`apireference` is a good overview of language features grouped by function * The :ref:`apireference` is a good overview of language features grouped by function
* The :ref:`classreference` is the hard-core listing of all functions available. * The :ref:`classreference` is the hard-core listing of all functions available.

View File

@ -4,7 +4,7 @@
CadQuery String Selectors CadQuery String Selectors
************************* *************************
.. automodule:: cadfile.cadutils.cadquery .. automodule:: cadquery
CadQuery selector strings allow filtering various types of object lists. Most commonly, Edges, Faces, and Vertices are CadQuery selector strings allow filtering various types of object lists. Most commonly, Edges, Faces, and Vertices are
used, but all objects types can be filtered. used, but all objects types can be filtered.
@ -69,6 +69,8 @@ Some filter types are not supported for edges. The selector usually refers to t
The axis used in the listing below are for illustration: any axis would work similarly in each case. The axis used in the listing below are for illustration: any axis would work similarly in each case.
========= ==================================== ===================================== ========================== ========= ==================================== ===================================== ==========================
Selector Selector Class Selects # objects returned Selector Selector Class Selects # objects returned
========= ==================================== ===================================== ========================== ========= ==================================== ===================================== ==========================