Hi, I do not have a great knowledge of this module,  I'm trying to draw a 
cad file with pyqtgraph, once I try to take the position of the mouse, 
to extract the value of plot. 
but I found a substantial diffrence between the coordinates drawn and those 
taken with the mouse.

I attach the code I have generated.

I hope for help

marcello


# -*- coding: utf-8 -*-
"""
Created on Thu Feb  7 ...

@author: ......
"""

#from caddolo import *
from PyQt4 import QtCore, QtGui
import pyqtgraph as pg
import sys, os
import numpy as np
import ezdxf

class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(800, 600)
        self.centralwidget = QtGui.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.widget = pg.PlotWidget(self.centralwidget)
        self.widget.setGeometry(QtCore.QRect(10, 10, 761, 541))
        self.widget.setObjectName("widget")
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtGui.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 18))
        self.menubar.setObjectName("menubar")
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QtGui.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        
MainWindow.setWindowTitle(QtGui.QApplication.translate("MainWindow", 
"MainWindow", None, QtGui.QApplication.UnicodeUTF8))



percorsoAcad = 'C:/Users/marcello/Desktop/pippo.dxf'

def openCad(percorsoAcad):
    """Visualizza il file dxf"""
    cavo_int =[]
    cavo_aer =[]
    estremi = []
    percorsoAcad = os.path.abspath(percorsoAcad)
    dxf = ezdxf.readfile(percorsoAcad)
    view12 = uig.widget
    pg.setConfigOptions(antialias=True)
    graph = pg.PlotItem()
    graph.hideAxis('left')
    graph.hideAxis('bottom')
  #  graph.invertX()
    graph.invertY()

    view12.addItem(graph)

    linee =[]
    for e in dxf.entities:
        if e.dxf.layer == 'O_I':
            pen=pg.mkPen('y', width=2)
            if e.dxftype() == 'POLYLINE':               
                print e.dxf.layer,e.dxftype()
                punti1 = list(e.points())
                linee= np.array(punti1)
                C = np.delete(linee, 2, 1)

                cavo = (C,'Int')
                cavo_int.append(cavo)
                graph.plot(C,pen=pen)                
        elif e.dxf.layer == 'REO' or 'O_A':
            pen=pg.mkPen('b', width=2)
            if e.dxftype() == 'POLYLINE':                
                print e.dxf.layer,e.dxftype()
                punti1 = list(e.points())
                linee= np.array(punti1)
                C = np.delete(linee, 2, 1)
               # print C
                graph.plot(C,pen=pen)               
                cavo = (C,'Aer')
                cavo_aer.append(cavo)
        else:
            pass
          
        if e.dxf.layer == 'O_I':
            pass
        if e.dxf.layer == 'EO' or 'O_A':
            if e.dxf.layer == 'T':
                id_tipo = '4-'
            if e.dxf.layer == 'NT':
                id_tipo = '3-'
            if e.dxf.layer == 'T':
                id_tipo = '2-'      
            if e.dxftype() == 'TEXT':
                Text = str(e.dxf.text)[0:5]
                if not Text.isdigit():
                    pass
                else:
                    nodo = id_tipo
                    textx = e.dxf.insert[0]
                    texty = e.dxf.insert[1]
                    ptext = np.array((textx,texty))
                    linee= np.array(ptext)
                    textdraw = str(nodo+Text)

                    estremo = (ptext,textdraw)                         
                    text = pg.TextItem(textdraw, anchor=(-0.2,0.5), 
angle=0)#, border='w', fill=(0, 0, 255, 100))
                    graph.addItem(text)
                    text.setPos(textx, texty) 
                    estremi.append(estremo)

    view12.show()
    view12.scene().sigMouseClicked.connect(posizionecadold)
    return (cavo_aer, cavo_int , estremi)

def matricecavi(cavo_aer,cavo_int,estremi):
    iop =[]
    for a in cavo_aer:
        for c in a[0]:
            iop.append(c)
    for a in cavo_int:
        for c in a[0]:
            iop.append(c)
    for a in estremi:
        iop.append(a[0])
    return iop
    
    
def posizionecadold(event):

    pos = event.scenePos()

    if  uig.widget.sceneBoundingRect().contains(pos):

        mousePoint =  uig.widget.mapFromView(pos)

        index = int(pos.x())
        
        index1 = int(pos.y())
        print mousePoint
        if index > 0 and index < len(iop):
            if index1 > 0 and index1 < len(iop):
                position = (iop[index])
                position2 = (iop[index1])
                provapos = (position,position2)
                print position
                print position2
                print provapos
        else:
            pass  

app = QtGui.QApplication(sys.argv) # Crea un'applicazione Qt, ...
app.setStyle("plastique")
    
MainWindow = QtGui.QMainWindow()

uig = Ui_MainWindow() # ... e una user interface.
uig.setupUi(MainWindow)

MainWindow.show()
c_r,c_t,esi = openCad(percorsoAcad)

iop = matricecavi(c_r,c_t,esi) 
#sys.exit(app.exec_())

-- 
You received this message because you are subscribed to the Google Groups 
"pyqtgraph" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/pyqtgraph/c20abea9-cc38-49de-b06e-0a30a3261df7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to