selutil.py :  » Business-Application » ThanCad » thancad-0.0.9 » thancom » 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 » thancom » selutil.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.

Package which processes commands entered by the user.
This module provides various high level selection routines.
"""

from thanvar import Canc
from thantrans import T
import thandr, thancomsel


def thanSel1line(proj, statonce, strict=True):
    """Selects 1 line and return immediatelly.

    The argument strict is not used and it is there for compatibility
    with thanSel1Order."""
    return thancomsel.thanSelect1(proj, statonce, filter=lambda e: isinstance(e, thandr.ThanLine))


def thanSel2lines(proj, statonce, strict=True): # mes=T["Select the 2 edges of a road:\n"]):
    "Selects 2 lines with no particular order."
    while True:
        elems = []
        proj[2].thanCom.thanAppend(statonce, "info1")
        res = thancomsel.thanSelectGen(proj, standalone=False)
        proj[2].thanGudResetSelColor()
        if res == Canc: return Canc
        for elem in proj[2].thanSelall:
            if isinstance(elem, thandr.ThanLine): elems.append(elem)
        if len(elems) == 2: return elems
        if not strict and len(elems) > 1: return elems[:2]
        proj[2].thanCom.thanAppend(T["2 lines are required (%d found). Try again.\n"]%len(elems), "can")


def thanSel2linsegs(proj, statonce, strict=True):
    "Selects 2 line segments; i.e. lines with only 2 nodes."
    while True:
        elems = []
        proj[2].thanCom.thanAppend(statonce, "info1")
        res = thancomsel.thanSelectGen(proj, standalone=False)
        proj[2].thanGudResetSelColor()
        if res == Canc: return Canc
        for elem in proj[2].thanSelall:
            if isinstance(elem, thandr.ThanLine) and len(elem.cp) == 2: elems.append(elem)
        if len(elems) == 2: break
        if not strict and len(elems) > 1: return elems[:2]
        proj[2].thanCom.thanAppend(T["Two single segment line is required (%d found). Try again.\n"]%len(elems), "can")
    return True


def thanSel2linesOrder(proj, statonce1, statonce2):
    "Selects 2 lines with predefined order."
    gps = thanSel1line(proj, statonce1, strict=True)
    if gps == Canc: return Canc
    rel = thanSel1line(proj, statonce2, strict=True)
    if rel == Canc: return Canc
    return [gps, rel]


def thanSel1lineOrder(proj, statonce1, strict=False):
    """Selects 1 line; if user selects 2 lines and strict==True, it is error.

    It differs to thanSel1line because the user must press enter to conclude
    the selection. thanSel1line returns immediatelly when the user selects
    a line.
    """
    while True:
        elems = []
        proj[2].thanCom.thanAppend(statonce1, "info1")
        res = thancomsel.thanSelectGen(proj, standalone=False)
        proj[2].thanGudResetSelColor()
  if res == Canc: return Canc
        for elem in proj[2].thanSelall:
            if isinstance(elem, thandr.ThanLine): elems.append(elem)
  if len(elems) == 1: break
  if not strict and len(elems) > 0: break
        proj[2].thanCom.thanAppend(T["1 line is required (%d found). Try again.\n"]%len(elems), "can")
    return elems[0]


def thanSelMultlinesOrder(proj, statonce1, statonce2):
    "Selects 2 lines with predefined order."
    gps = thanSelMultlines(proj, 2, statonce1, strict=False)
    if gps == Canc: return Canc
    rel = thanSelMultlines(proj, len(gps), statonce2, strict=True)
    if rel == Canc: return Canc
    return gps, rel


def thanSelMultlines(proj, nsel, statonce1, strict=False):
    "Selects nsel lines; if user selects n>0 lines and n<>nsel and strict==True, it is error."
    while True:
        elems = []
        proj[2].thanCom.thanAppend(statonce1, "info1")
        res = thancomsel.thanSelectGen(proj, standalone=False)
        proj[2].thanGudResetSelColor()
  if res == Canc: return Canc
        for elem in proj[2].thanSelall:
            if isinstance(elem, thandr.ThanLine): elems.append(elem)
  if len(elems) == nsel: break
  if not strict and len(elems) > 0: break
        proj[2].thanCom.thanAppend(T["%d lines are required (%d found). Try again.\n"]%(nsel, len(elems)), "can")
    return elems


def thanSel1breakable(proj, statonce1, strict=True):
    "Selects 1 breakable element."
    while True:
        elems = []
        proj[2].thanCom.thanAppend(statonce1, "info1")
        res = thancomsel.thanSelectGen(proj, standalone=False)
        proj[2].thanGudResetSelColor()   # New select will invalidate current selection; so act now
  if res == Canc: return Canc
        for elem in proj[2].thanSelall:
            if elem.thanBreak(): elems.append(elem)     # Break with no arguments returns True if element is breakable
  if len(elems) == 1: break
  if not strict and len(elems) > 0: break
        proj[2].thanCom.thanAppend(T["1 breakable element is required (%d found). Try again.\n"]%len(elems), "can")
    return elems[0]


def thanSelCutting(proj, statonce1, strict=True):
    "Selects elements to be used as cutting edges."
    while True:
        elems = []
        proj[2].thanCom.thanAppend(statonce1, "info1")
        res = thancomsel.thanSelectGen(proj, standalone=False)
  if res == Canc: return Canc
        for elem in proj[2].thanSelall:
            if elem.thanBreak(): elems.append(elem) # Break with no arguments returns True if element is breakable..
  if len(elems) > 0: break                    # ..and if an element is breakable, it can also be used us cuttingf edge
  if not strict and len(elems) > 0: break
        proj[2].thanCom.thanAppend(T["No cutting-able elements were found. Try again.\n"], "can")
        proj[2].thanGudResetSelColor()   # New select will invalidate current selection; so act now
    return elems


if __name__ == "__main__": print __doc__
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.