<commit_before>'''
Derived SceneviewerWidget capable of editing node coordinate positions and derivatives.
'''

import math
from PySide import QtCore
from opencmiss.zincwidgets.sceneviewerwidget import SceneviewerWidget, SelectionMode
from opencmiss.zinc.field import Field
from opencmiss.zinc.graphics import Graphics
from opencmiss.zinc.scenecoordinatesystem import SCENECOORDINATESYSTEM_WINDOW_PIXEL_TOP_LEFT
from opencmiss.zinc.result import RESULT_OK as ZINC_RESULT_OK

class NodeEditorSceneviewerWidget(SceneviewerWidget):
    '''
    classdocs
    '''

    def __init__(self, parent=None):
        '''
        Constructor
        '''
        super(NodeEditorSceneviewerWidget, self).__init__(parent)
        self._model = None
        self._editNode = None
        self._editGraphics = None
        self._lastMousePos = None

    def setGeneratorModel(self, model):
        self._model = model

    def getNearestNodeAndGraphics(self, x, y):
        '''
        :return: Node, Graphics OR None, None if none found.
        '''
        oldNodeSelectMode = self._nodeSelectMode
        oldDataSelectMode = self._dataSelectMode
        oldElemSelectMode = self._elemSelectMode
        self.setSelectModeNode()
        #print('pick',x,y,self._selectTol, 'DpiX', self.physicalDpiX(), self.logicalDpiX(), 'DpiY', self.physicalDpiY(), self.logicalDpiY())
        #print('  width', self.width(), 'widthMM',self.widthMM(),'dpi',25.4*self.width()/self.widthMM(),
        #      'height', self.height(), 'heightMM',self.heightMM(),'dpi',25.4*self.height()/self.heightMM())
        #app = QtCore.QCoreApplication.instance()
        #desktop = app.desktop()
        #dpmm = self.width()/self.widthMM()
        #print('dpmm',dpmm,'physicalDpiX',desktop.physicalDpiX(),'screenGeometry',desktop.screenGeometry(self))
        tol = self._selectTol  # *0.1*dpmm
        #print('tol',tol)
        self._scenepicker.setSceneviewerRectangle(self._sceneviewer, SCENECOORDINATESYSTEM_WINDOW_PIXEL_TOP_LEFT,
            x - tol, y - tol, x + tol, y + tol)
        node = self._scenepicker.getNearestNode()
        if node.isValid():
            graphics = self._scenepicker.getNearestNodeGraphics()
        else:
            node = None
            graphics = None
        self._nodeSelectMode = oldNodeSelectMode
        self._dataSelectMode = oldDataSelectMode
        self._elemSelectMode = oldElemSelectMode
        return node, graphics
<commit_msg>Filter for nodes when picking<commit_after>'''
Derived SceneviewerWidget capable of editing node coordinate positions and derivatives.
'''

import math
from PySide import QtCore
from opencmiss.zincwidgets.sceneviewerwidget import SceneviewerWidget, SelectionMode
from opencmiss.zinc.field import Field
from opencmiss.zinc.graphics import Graphics
from opencmiss.zinc.scenecoordinatesystem import SCENECOORDINATESYSTEM_WINDOW_PIXEL_TOP_LEFT
from opencmiss.zinc.result import RESULT_OK as ZINC_RESULT_OK

class NodeEditorSceneviewerWidget(SceneviewerWidget):
    '''
    classdocs
    '''

    def __init__(self, parent=None):
        '''
        Constructor
        '''
        super(NodeEditorSceneviewerWidget, self).__init__(parent)
        self._model = None
        self._editNode = None
        self._editGraphics = None
        self._lastMousePos = None

    def setGeneratorModel(self, model):
        self._model = model

    def getNearestNodeAndGraphics(self, x, y):
        '''
        :return: Node, Graphics OR None, None if none found.
        '''
        scenefiltermodule = self._context.getScenefiltermodule()
        scenefiltermodule.beginChange()
        oldSelectionfilter = self.getSelectionfilter()
        self.setSelectionfilter(scenefiltermodule.createScenefilterFieldDomainType(Field.DOMAIN_TYPE_NODES))
        #print('pick',x,y,self._selectTol, 'DpiX', self.physicalDpiX(), self.logicalDpiX(), 'DpiY', self.physicalDpiY(), self.logicalDpiY())
        #print('  width', self.width(), 'widthMM',self.widthMM(),'dpi',25.4*self.width()/self.widthMM(),
        #      'height', self.height(), 'heightMM',self.heightMM(),'dpi',25.4*self.height()/self.heightMM())
        #app = QtCore.QCoreApplication.instance()
        #desktop = app.desktop()
        #dpmm = self.width()/self.widthMM()
        #print('dpmm',dpmm,'physicalDpiX',desktop.physicalDpiX(),'screenGeometry',desktop.screenGeometry(self))
        tol = self._selectTol  # *0.1*dpmm
        #print('tol',tol)
        self._scenepicker.setSceneviewerRectangle(self._sceneviewer, SCENECOORDINATESYSTEM_WINDOW_PIXEL_TOP_LEFT,
            x - tol, y - tol, x + tol, y + tol)
        node = self._scenepicker.getNearestNode()
        if node.isValid():
            graphics = self._scenepicker.getNearestNodeGraphics()
        else:
            node = None
            graphics = None
        self.setSelectionfilter(oldSelectionfilter)
        scenefiltermodule.endChange()
        return node, graphics

{'fraction_non_alphanumeric': 0.10930516050386022, 'fraction_numerical': 0.003250711093051605, 'mean_word_length': 3.288327526132404, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2371419', 'n_tokens_mistral': 1573, 'n_tokens_neox': 1532, 'n_words': 273}