thanpoint.py :  » Business-Application » ThanCad » thancad-0.0.9 » thandr » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Business Application » ThanCad 
ThanCad » thancad 0.0.9 » thandr » thanpoint.py
##############################################################################
# ThanCad 0.0.9 "DoesSomething": 2dimensional CAD with raster support for engineers.
# 
# Copyright (c) 2001-2009 Thanasis Stamos,  August 23, 2009
# URL:     http://thancad.sourceforge.net
# e-mail:  cyberthanasis@excite.com
# 
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# 
# This program 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 General Public License for more details (www.gnu.org/licenses/gpl.html).
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
##############################################################################

"""\
ThanCad 0.0.9 "DoesSomething": 2dimensional CAD with raster support for engineers.

This module defines the point element.
"""

from math import fabs
from itertools import izip
import p_ggen
from thanelem import ThanElement
from thanvar import Canc
try: import pyx
except ImportError: pass

############################################################################
############################################################################

class ThanPoint(ThanElement):
    "A point."
    thanTkCompound = 100        # The number of Tkinter objects that make the element. 100=compound (Many lines etc.)
    psize = 8                   # Pixel size of the point

    def thanSet (self, cp):
        "Sets the coordinates of the point."
        self.setBoundBox([cp[0], cp[1], cp[0], cp[1]])
        self.cp = list(cp)
#  self.thanTags = ()                                 # thanTags is initialised in ThanElement

    def thanIsNormal(self):
        "Returns False if the point is degenerate (never)."
        return True                                        # There is no degenerate point


    def thanClone(self):
        "Makes a geometric clone of itself."
        el = ThanPoint()
        el.thanSet(self.cp)
        return el


    def thanRotate(self):
        "Rotates the element within XY-plane with predefined angle and rotation angle."
        self.cp = self.thanRotateXy(self.cp)
        self.setBoundBox([self.cp[0], self.cp[1], self.cp[0], self.cp[1]])


    def thanMirror(self):
        "Mirrors the element within XY-plane with predefined point and unit vector."
        self.cp = self.thanMirrorXy(self.cp)
        self.setBoundBox([self.cp[0], self.cp[1], self.cp[0], self.cp[1]])


    def thanScale(self, cs, scale):
        "Scales the element in n-space with defined scale and center of scale."
  self.cp = [cs1+(cc1-cs1)*scale for (cc1,cs1) in izip(self.cp, cs)]
        self.setBoundBox([self.cp[0], self.cp[1], self.cp[0], self.cp[1]])

    def thanMove(self, dc):
        "Moves the element with defined n-dimensional distance."
  self.cp = [cc1+dd1 for (cc1,dd1) in izip(self.cp, dc)]
        self.setBoundBox([self.cp[0], self.cp[1], self.cp[0], self.cp[1]])

    def thanOsnap(self, proj, otypes, ccu, eother, cori):
        "Return a point of type otype nearest to xcu, ycu."
  if "ena" not in otypes: return None            # Object snap is disabled
        if "nod" in otypes:
      return fabs(self.cp[0]-ccu[0])+fabs(self.cp[1]-ccu[1]), "nod", self.cp
        if "nea" in otypes:
      return fabs(self.cp[0]-ccu[0])+fabs(self.cp[1]-ccu[1]), "nea", self.cp
  return None

    def thanTkGet(self, proj):
        "Gets the attributes of the point interactively from a window."
        res = proj[2].thanGudGetPoint(T["Specify a point: "])
        if res == Canc: return res               # Point cancelled
        self.thanSet(res)
        return True                              # Point OK

    def thanTkDraw(self, than):
        "Draws the point on the window."
        xa, ya = than.ct.global2Local(self.cp[0], self.cp[1])
        temp = than.thanPoints["chi"](than.dc, xa, ya, self.psize,
            color=than.outline, fill=than.fill, tags=self.thanTags)

    def thanTkHiwin(self, than):
        "Highlights with a (small) window very small elements so that they become visible."
  self.thanTkHiwinDo(than, 0.0, self.cp)

    def thanExpDxf(self, fDxf):
        "Exports the point to dxf file."
        fDxf.thanDxfPlotPoint3(self.cp[0], self.cp[1], self.cp[2])

    def thanExpPil(self, than):
        "Exports the point to a PIL raster image."
        x1, y1 = than.ct.global2Locali(self.cp[0], self.cp[1])
  if than.rwidth <= 1.5:
      than.dc.point((x1, y1), fill=than.outline)
  else:
      i1, i2 = than.widtharc
      than.dc.rectangle((x1-i1, y1-i1, x1+i2, y1+i2), outline=than.outline, fill=than.fill)

    def thanPlotPdf(self, than):
        "Plots the point to a pdf file."
  g2l = than.ct.global2Local
  ca = g2l(self.cp[0], self.cp[1])
  p = pyx.path.circle(ca[0], ca[1], 0.05)
  than.dc.stroke(p)

    def thanList(self, than):
        "Shows information about the point element."
  than.writecom("Element: POINT")
  than.write("    Layer: % s\n" % than.laypath)
  than.write("Insertion point: %s\n" % than.strcoo(self.cp))


class ThanPointNamed(ThanPoint):
    "A single point with attached (unique?) name."

    def thanSet (self, c, name, validz=True):
        "Sets the coordinates and the name of the point."
  self.name = name.rstrip()
  self.validz = validz
  ThanPoint.thanSet(self, c)

    def thanClone(self):
        "Makes a geometric clone of itself."
        el = ThanPointNamed()
        el.thanSet(self.cp, self.name, self.validz)
        return el

    def thanTkGet(self, proj):
        "Gets the attributes of the point interactively from a window."
        res = proj[2].thanGudGetPoint(T["Specify a point: "])
        if res == Canc: return res                # Point cancelled
        name = proj[2].thanGudGetText0(T["Point name: "])
        if name == Canc: return name              # Point cancelled
        validz = proj[2].thanGudGetYesno(T["Is z valid for contour lines (enter=Yes): "], default="yes")
        if validz == Canc: return validz          # Point cancelled
        self.thanSet(res, name, validz)
        return True                               # Point OK

    def thanTkDraw(self, than):
        "Draws the named point on the window."
  ThanPoint.thanTkDraw(self, than)
#        print "named: thanTkDraw: than.pointPlotname=", than.pointPlotname
  if than.pointPlotname:
      ps, _ = than.ct.local2GlobalRel(self.psize, 0.0)
      self._crtext(ps).thanTkDraw(than)

    def _crtext(self, psize=None):
        "Creates a ThanCad text with the name of the point."
  from thantext import ThanText
  t = ThanText()
  c1 = self.cp[:]
#        print "psize1=", psize
        if psize == None: psize = self.psize
#        print "psize2=", psize
  c1[0] += psize
  c1[1] += psize
  t.thanSet(self.name, c1, psize, 0.0)
  t.thanTags = self.thanTags
  return t

    def thanExpDxf(self, fDxf):
        "Exports the point to dxf file."
        ThanPoint.thanExpDxf(self, fDxf)
        self._crtext(0.13).thanExpDxf(fDxf)

    def thanExpPil(self, than):
        "Exports the point to a PIL raster image."
        ThanPoint.thanExpPil(self, than)
        self._crtext().thanExpPil(than)

    def thanPlotPdf(self, than):
        "Plots the point to a pdf file."
        ThanPoint.thanPlotPdf(self, than)
        self._crtext().thanPlotPdf(than)

    def thanList(self, than):
        "Shows information about the point element."
  than.writecom("Element: POINT")
  than.write("    Layer: % s\n" % than.laypath)
  than.write("Name: %s\n" % self.name)
  than.write("Insertion point: %s\n" % than.strcoo(self.cp))


if __name__ == "__main__":
    print __doc__
    c = ThanPoint()
    c.thanSet((10.0, 20.0, 0.0))
    print "point=", c
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.