Hi everyone !

I follow your advices and change my program but I have the same problem with
rectangles' colors in function of my point of view.
I want to know if you have it if you interpret my code with your machine and
open an empty IGES file.

Thank you in advance.
Naide

My code is :

import wx
from OCC.Display.wxDisplay import wxViewer3d
import time
from OCC.Display.SimpleGui import *
from OCC.gp import *

from OCC.BRepPrimAPI import *
from OCC.Utils.Construct import *
from OCC.Graphic3d import *
from OCC.Utils.Common import *

class ViewerFrame(wx.MDIChildFrame):
     def __init__(self, parent):
        wx.MDIChildFrame.__init__(self, parent, -1, "",
style=wx.DEFAULT_FRAME_STYLE,size = (640,480))
        self.canva = wxViewer3d(self)
        self.canvas = wx.ClientDC(self)

     def LoadFile(self,filename):
        extension = os.path.basename(filename).split(".").pop().lower()
        start_time = time.time()
        if extension =="step" or extension == "stp":
            from OCC.Utils.DataExchange.STEP import STEPImporter
            stepReader = STEPImporter(str(filename))
            stepReader.read_file()
            shape = stepReader.get_shapes()
        elif extension =="iges" or extension =="igs":
            from OCC import IGESControl
            i  = IGESControl.IGESControl_Controller()
            i.Init()
            iges_reader = IGESControl.IGESControl_Reader()
            iges_reader.ReadFile(str(filename))
            iges_reader.TransferRoots()
            shape = iges_reader.OneShape()
        else:
            return True
        self.canva._display.DisplayShape(shape)
        end_time = time.time()
        self.SetTitle("Test")
        duration = end_time-start_time
        print "%s STEP file loaded and displayed in %f 
seconds."%(filename,duration)

        self.canva._display.DisplayShape(shape)

        L= 100
        l=100

        X1 = 0.0
        Y1 = 0.0
        Z1 = 0.0

        X2 = L
        Y2 = 0.0
        Z2 = 0.0

        X3 = 0.0
        Y3 = -l
        Z3 = 0.0

        X4 = L
        Y4 = -l
        Z4 = 0.0

        p1 = gp_Pnt(X1,Y1,Z1+0.1)
        p2 = gp_Pnt(X2,Y2,Z2+0.1)
        p3 = gp_Pnt(X3,Y3,Z3+0.1)
        p4 = gp_Pnt(X4,Y4,Z4+0.1)

        f1 = make_face(make_closed_polygon(p1,p2,p4,p3))
        self.canva._display.DisplayColoredShape(f1,'RED', update=True)


        p5 = gp_Pnt(X1+10,Y1-10,Z1+0.2)
        p6 = gp_Pnt(X2-10,Y2-10,Z2+0.2)
        p7 = gp_Pnt(X3+10,Y3+10,Z3+0.2)
        p8 = gp_Pnt(X4-10,Y4+10,Z4+0.2)

        f2 = make_face(make_closed_polygon(p5,p6,p8,p7))
        self.canva._display.DisplayColoredShape(f2,'WHITE', update=True)

        p9 =  gp_Pnt(X1+20,Y1-20,Z1+0.3)
        p10 = gp_Pnt(X2-20,Y2-20,Z2+0.3)
        p11 = gp_Pnt(X3+20,Y3+20,Z3+0.3)
        p12 = gp_Pnt(X4-20,Y4+20,Z4+0.3)

        f3 = make_face(make_closed_polygon(p9,p10,p12,p11))
        self.canva._display.DisplayColoredShape(f3,'BLUE', update=True)

        p13 = gp_Pnt(X1+30,Y1-30,Z1+0.4)
        p14 = gp_Pnt(X2-30,Y2-30,Z2+0.4)
        p15 = gp_Pnt(X3+30,Y3+30,Z3+0.4)
        p16 = gp_Pnt(X4-30,Y4+30,Z4+0.4)

        f4 = make_face(make_closed_polygon(p13,p14,p16,p15))
        self.canva._display.DisplayColoredShape(f4,'GREEN', update=True)

class AppFrame(wx.MDIParentFrame):
    def __init__(self, parent):
        wx.MDIParentFrame.__init__(self, parent, -1,"Test",
style=wx.DEFAULT_FRAME_STYLE,size = (800,600))

        menuBar = wx.MenuBar()
        menu = wx.Menu()
        menu.Append(101, "&Open", "Open a STEP file")
        self.Bind(wx.EVT_MENU, self.OnOpen, id=101)

        menuBar.Append(menu, "File")
        self.SetMenuBar(menuBar)

    def OnOpen(self,event):
        dlg = wx.FileDialog(
            self, message="Choose a STEP",
            defaultDir=os.getcwd(),
            defaultFile="",
            wildcard="",
            style=wx.OPEN | wx.MULTIPLE | wx.CHANGE_DIR
            )
        if dlg.ShowModal() == wx.ID_OK:
            paths = dlg.GetPaths()
        new_frame = ViewerFrame(self)
        new_frame.Show(True)
        new_frame.canva.InitDriver()
        wx.SafeYield()
        new_frame.LoadFile(paths[0])


if __name__=="__main__":


    app = wx.PySimpleApp()
    wx.InitAllImageHandlers()
    frame = AppFrame(None)
    frame.Show(True)
    app.SetTopWindow(frame)
    app.MainLoop()








_______________________________________________
Pythonocc-users mailing list
Pythonocc-users@gna.org
https://mail.gna.org/listinfo/pythonocc-users

Reply via email to