thantkguiroad.py :  » Business-Application » ThanCad » thancad-0.0.9 » thantkgui » thantkguilowget » 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 » thantkgui » thantkguilowget » thantkguiroad.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 line states, i.e. as the user moves the mouse, a road
(which is a line with circular arcs) is drawn from a given point to mouse
cursor, continuously.
"""
from math import hypot
import Tkinter
from thantkconst import *
from thanvar import thanLogTk,calcRoadNode,calcRoadNodeR,tkRoadNode,tkRoadNodeR

from thantkguigeneric import ThanStateGeneric


class ThanStateRoadp(ThanStateGeneric):
    "An object which interprets mouse movements to addition of a node to a road."

    def __init__(self, proj, x1, y1, x2, y2, x3, y3, r1):
        "Initialize object."
        self.thanProj = proj
        self.__x1 = x1
        self.__y1 = y1
        self.__x2 = x2
        self.__y2 = y2
        self.__x3 = x3
        self.__y3 = y3
        self.__r1 = r1
        dc = self.thanProj[2].thanCanvas
        dc.thanOrtho.enable(x2, y2)               # Ortho is disabled in thanCleanup in stateless mixin
        self.__dragged = (dc.create_line(10000, 10000, 10001, 10001),)  # Dummy element to avoid complexity in onMotion()
        for i1 in self.__dragged:
            dc.thanTempItems.add(i1)
        if self.__x3 != None:
#           hopefully everything is set, and the following event will trigger __onMotion to do the drawing work
            dc.event_generate("<Motion>", when="head", x=self.__x3, y=self.__y3, warp=1)  # Set mouse position to the previous c3 point


    def thanOnMotion(self, event, x, y):
        "Well, here is what should be drawn each time mouse moves."
        dc = self.thanProj[2].thanCanvas
        x, y = dc.thanOrtho.orthoxy(x, y)
        draggedp = self.__dragged
        self.__dragged, ct = tkRoadNode(self.__x1, self.__y1, self.__x2, self.__y2,
                             x, y, self.__r1, dc, fill="blue", tags=())
        for i1 in draggedp:
            dc.delete(i1)
            dc.thanTempItems.remove(i1)
        for i1 in self.__dragged:
            dc.thanTempItems.add(i1)


    def thanOnClick(self, event, x, y, cc):
        "Well, here is what should be done when mouse clicks."
        dc = self.thanProj[2].thanCanvas
        for i1 in self.__dragged:
            dc.delete(i1)
            dc.thanTempItems.remove(i1)
        dc.thanLastResult = cc, None
        dc.thanState = THAN_STATE_NONE
        dc.thanOState = ThanStateGeneric(self.thanProj)


    def thanOnClickr(self, event, x, y, cc):
        "Well, here is what should be done when right mouse button clicks."
        dc = self.thanProj[2].thanCanvas
        for i1 in self.__dragged:
            dc.delete(i1)
            dc.thanTempItems.remove(i1)
        dc.thanLastResult = cc, "r"
        dc.thanState = THAN_STATE_NONE
        dc.thanOState = ThanStateGeneric(self.thanProj)


class ThanStateRoadr(ThanStateGeneric):
    "An object which interprets mouse movements to modification of the radius of an arc."

    def __init__(self, proj, x1, y1, x2, y2, x3, y3, r1):
        "Initialize object."
        self.thanProj = proj
        self.__x1 = x1
        self.__y1 = y1
        self.__x2 = x2
        self.__y2 = y2
        self.__x3 = x3
        self.__y3 = y3
        self.__r1 = r1
        dc = self.thanProj[2].thanCanvas
#        dc.thanOrtho.enable(x3, y3)               # Ortho is akward here
        self.__dragged = (dc.create_line(10000, 10000, 10001, 10001),)  # Dummy element to avoid complexity in onMotion()
        for i1 in self.__dragged:
            dc.thanTempItems.add(i1)
#       hopefully everything is set, and the following event will trigger __onMotion to do the drawing work
        ro = calcRoadNode(self.__x1, self.__y1, self.__x2, self.__y2, self.__x3, self.__y3, self.__r1)
        dc.event_generate("<Motion>", when="head", x=ro.pm.x, y=ro.pm.y, warp=1)  # Set mouse position to the middle of the circular curve


    def thanOnMotion(self, event, x, y):
        "Well, here is what should be drawn each time mouse moves."
        dc = self.thanProj[2].thanCanvas
#        x, y = dc.thanOrtho.orthoxy(x, y)         # Ortho is akward here
        ct = self.thanProj[2].thanCt
        draggedp = self.__dragged
        self.__dragged, ct = tkRoadNodeR(self.__x1, self.__y1, self.__x2, self.__y2,
                                         self.__x3, self.__y3, x, y, dc, ct, fill="blue", tags=())
        for i1 in draggedp:
            dc.delete(i1)
            dc.thanTempItems.remove(i1)
        for i1 in self.__dragged:
            dc.thanTempItems.add(i1)


    def thanOnClick(self, event, x, y, cc):
        "Well, here is what should be done when mouse clicks."
        dc = self.thanProj[2].thanCanvas
        for i1 in self.__dragged:
            dc.delete(i1)
            dc.thanTempItems.remove(i1)
        dc.thanLastResult = cc, None
        dc.thanState = THAN_STATE_NONE
        dc.thanOState = ThanStateGeneric(self.thanProj)


    def thanOnClickr(self, event, x, y, cc):
        "Well, here is what should be done when right mouse button clicks."
        self.thanOnClick(event, x, y, cc) # It is like if the user pressed left click
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.