示例#1
0
def activate_tool(tool):
    appdata.set('input', None)
    global active_tool
    active_tool = tool
    active_tool.reset()
    std_events.new_tool_activated.emit()
    std_events.new_step_activated.emit()
示例#2
0
def _save_as():
    filename = QtGui.QFileDialog.getSaveFileName(win, 'Save File',
                                                 appdata.get('filename'),
                                                 'STEP files (*.stp *.step)')
    if filename:
        appdata.set('filename', filename)
        doc_ctrl.save(appdata.get('filename'))
        appdata.set('dirty', False)
示例#3
0
def refresh_():
    """Save the script, run it and display its result."""
    save_script_()
    if not appdata.get('filename'):
        # save was cancelled by the user
        return
    exec_script()
    appdata.set('dirty', False)
示例#4
0
def save_script_():
    """Save the script. If it was not saved before, ask for a filename."""
    if not appdata.get('filename'):
        save_script_as_()
        return
    with open(appdata.get('filename'), 'w') as file:
        file.write(editor.toPlainText())
        appdata.set('dirty', False)
示例#5
0
def load(filename):
    """Load a script given its filename. This assumes that no script
    was loaded before.
    This occurs either on startup if a command line argument specifying the
    file to open was provided or when manually opening a file for the first
    time."""
    with open(filename) as file:
        st = file.read()
    editor.setPlainText(st)
    # If the file was opened after startup, 'filename' has not been set before.
    appdata.set('filename', filename)
    exec_script()
示例#6
0
 def _update_input_point(self):
     # Update the application-wide input point from the input in the command
     #   box
     try:
         input = gp_.gp_Pnt_([float(a) for a in self.text().split(',')])
     except ValueError:
         return
     except NotImplementedError:  # command line has only one or two entries
         return
     except TypeError:  # command line is empty
         return
     self._previous_command_input = input
     appdata.set('input', input)
示例#7
0
 def _set_active_plane(self, value):
     if value == self._active_plane:
         return
     if value == 2:
         axis = gp_Ax3(gp_Pnt_([0, 0, 0]), gp_Dir(0, 0, 1), gp_Dir(1, 0, 0))
     elif value == 1:
         axis = gp_Ax3(gp_Pnt_([0, 0, 0]), gp_Dir(0, 1, 0), gp_Dir(0, 0, 1))
     elif value == 0:
         axis = gp_Ax3(gp_Pnt_([0, 0, 0]), gp_Dir(1, 0, 0), gp_Dir(0, 1, 0))
     self._active_plane = value
     appdata.set('active_plane', value)
     self.viewer.SetPrivilegedPlane(axis)
     # TODO: 0.3: these should probably be called through signals
     self._update_input()
     self.update_preview()
示例#8
0
def open_():
    """Open a STEP file."""

    filename = QtGui.QFileDialog.getOpenFileName(win, 'Open File',
                                                 appdata.get('filename'),
                                                 'STEP files (*.stp *.step)')
    if not filename:
        # cancelled by the user
        return

    if doc_ctrl.isnew:
        # the current document is still empty -
        # open file in active window
        doc_ctrl.open(filename)
        std_events.document_modified.emit()
        appdata.set('filename', filename)
        appdata.set('dirty', False)
    else:
        # open file in new window
        # FIXME: this does not work on Debian 7, see comment above
        fname = os.path.join(appdata.get('APPDIR'), '__main__.pyw')
        subprocess.Popen([sys.executable, fname, filename])
示例#9
0
    def _update_input(self):
        """Update the input based on the current position of the mouse"""
        # TODO: 0.3: Detected shape should be highlighted
        pos = self.mapFromGlobal(QtGui.QCursor.pos())
        pos = [pos.x(), pos.y()]
        if active_tool.active_tool.input_type == 'object':
            # TODO: Currently the preview is always removed and redisplayed
            # on every input change in order to avoid it being selected.
            # Make it unselectable.
            self.replace_shapes('preview', [])
            # HACK
            # iterate over all possible object types and try to select one
            #   of them:
            for selection_mode in [
                    TopAbs.TopAbs_SOLID, TopAbs.TopAbs_SHELL,
                    TopAbs.TopAbs_FACE, TopAbs.TopAbs_WIRE, TopAbs.TopAbs_EDGE,
                    TopAbs.TopAbs_VERTEX
            ]:
                self.context.CloseLocalContext()
                self.context.OpenLocalContext()
                self.context.ActivateStandardMode(selection_mode)
                self.context.MoveTo(pos[0], pos[1], self.view.GetHandle())
                if sys.platform.startswith('win'):
                    self.context.MoveTo(pos[0], pos[1], self.view.GetHandle())
                if self.context.HasDetected():
                    appdata.set('input', self.context.DetectedShape())
                    break
            else:
                appdata.set('input', None)
        else:
            self.context.CloseLocalContext()
            self.context.OpenLocalContext()
            self.context.ActivateStandardMode(TopAbs.TopAbs_VERTEX)
            self.context.MoveTo(pos[0], pos[1], self.view.GetHandle())
            if sys.platform.startswith('win'):
                # WORKAROUND: call this twice on Windows
                self.context.MoveTo(pos[0], pos[1], self.view.GetHandle())

            if self.context.HasDetected():
                a = gp_Pnt_(self.context.DetectedShape())
            elif not self.grid:
                view_point = self.view.ConvertToGrid(*pos)
                view_direction = [
                    self.view.At()[i] - self.view.Eye()[i] for i in range(3)
                ]
                active_direction = self.active_plane
                point = [
                    view_point[i] - view_point[active_direction] *
                    view_direction[i] / view_direction[active_direction]
                    for i in range(3)
                ]
                a = gp_Pnt_(point)
            else:
                a = gp_Pnt_(self.view.ConvertToGrid(*pos))
            appdata.set('input', a)
示例#10
0
def save_script_as_():
    """Show a file dialog to save the opened script under a certian name."""
    filename = QtGui.QFileDialog.getSaveFileName(win, 'Save Script',
                                                 appdata.get('filename'),
                                                 'Python scripts (*.py)')
    if filename:
        appdata.set('filename', filename)
        with open(filename, 'w') as script:
            script.write(editor.toPlainText())
        appdata.set('filename', filename)
        appdata.set('dirty', False)
示例#11
0
def preview_from_current_input():
    """Return the preview shapes corresponding to the current input.

    If no valid shapes can be constructed for the current input, return an
    empty list and set 'input_valid' to False."""
    if appdata.get('input') is None:
        appdata.set('input_valid', False)
        return []
    try:
        a = active_tool.preview(appdata.get('input'),
                                appdata.get('active_plane'))
    except InvalidInputException:
        appdata.set('input_valid', False)
        return []
    else:
        appdata.set('input_valid', True)
        return a
示例#12
0
    def __init__(self, *args, **kwargs):

        try:
            appdir = kwargs.pop('appdir')
        except KeyError:
            pass

        CadAppQt.__init__(self)

        # set application directory
        appdata.set('APPDIR', appdir)

        # Search for icons in './icons/kubos'.
        if appdata.get('APPDIR') is not None:
            ip = _QIcon.themeSearchPaths() + [
                _path.join(appdata.get('APPDIR'), 'icons')
            ]
            _QIcon.setThemeSearchPaths(ip)
            _QIcon.setThemeName('kubos')
        if appdata.get('mode'):
            if _QIcon.hasThemeIcon('kubos-' + appdata.get('mode')):
                appdata.set('icon',
                            _QIcon.fromTheme('kubos-' + appdata.get('mode')))
            else:
                appdata.set('icon', _QIcon.fromTheme('kubos'))
        else:
            appdata.set('icon', _QIcon.fromTheme('kubos'))

        appdata.set('AUTHORS', 'Marko Knöbl')
        appdata.set('VERSION', '0.2b2')
        self.doc = doc_ctrl
        # 'win' cannot be imported before creating a QApplication
        from gui import win
        self.win = win
        self.update_title()
        self.viewer = win.viewer_3d
        self._menu_bar = self.win.menuBar()
        self._menus = {}
        self._actiongroups = {}

        self._toolbars = {}
示例#13
0
# -*- coding: UTF-8 -*-
#convert to Python 3
# TODO: check occurences of document_modified.emit(), reduce them
from data import appdata
from app import app
from lib import argparse

parser = argparse.ArgumentParser()
parser.add_argument(
    '--mode',
    choices=['standard', 'minimal', 'viewer', 'test', 'script'],
    help='Determines the tools and modules available on startup.')
parser.add_argument('URL', nargs='?', default='', help='Document to open')
args = parser.parse_args()
appdata.set('mode', args.mode or 'standard')
appdata.set('filename', args.URL)
if appdata.get('mode') == 'standard':
    appdata.set('APPLICATION_NAME', 'Kubos')
else:
    appdata.set('APPLICATION_NAME', 'Kubos ' + appdata.get('mode').title())

app.exec_()
示例#14
0
 def next_step(self):
     # reset the input (this is neccessary if the input type
     # will change)
     appdata.set('input', None)
     self.step += 1
     self.input_type = self.input_types[self.step]
示例#15
0
def _save():
    if appdata.get('filename'):
        doc_ctrl.save(appdata.get('filename'))
        appdata.set('dirty', False)
    else:
        _save_as()
示例#16
0

from os import path

from data import appdata

# application directory
appdata.set('APPDIR', path.dirname(__file__))

appdata.set('mode', 'standard')
appdata.set('APPLICATION_NAME', 'Kubos')

from app import app

app.load_actions('actions.view')

app.exec_()