pythonCascade Sample Problems

Viewer: Model clipping

 

        if self.myPlane.IsNull():

            # creates a plane defined : center of the box ( 50,50,50) and 1 direction

            tmpPln = gp_Pln(gp_Pnt(0,0,0),gp_Dir(1,0,0))

            # getting the coefficients of the gp_Pln ( ax+by+cz+d = 0 )

            A,B,C,D = tmpPln.Coefficients()

            #with these coefficients, creating a V3d_Plane

            self.myPlane = V3d_Plane(self.viewer,A,B,C,D)

            #creates the Face

            #NOTE : the face must be behind the clipping plane !!    

            tmpPln = gp_Pln(gp_Pnt(0.1,0,0),gp_Dir(1,0,0))

            MakeFace = BRepBuilderAPI_MakeFace (tmpPln, 200, -200, 410, -410)

            S = MakeFace.Face()

            #display the face

            self.myShape = AIS_Shape(S)

 

        A,B,C,D = self.myPlane.Plane()

        self.m_ModelClipping_Z = D

           

 

        winmclipping = wxDialog(self.parent,-1,"Model Clipping",wxPoint(30,50),wxSize(350,150))

        wxButton(winmclipping,wxID_OK," OK ",wxPoint(80,100),wxDefaultSize)

        wxButton(winmclipping,wxID_CANCEL," CANCEL ",wxPoint(160,100),wxDefaultSize)

        wxStaticText(winmclipping,-1,"   Z:",wxPoint(5,20))

        self.sc5 = wxSlider(winmclipping,2109,0,-750,750,wxPoint(50,20),wxSize(300,-1),wxSL_HORIZONTAL | wxSL_AUTOTICKS | wxSL_LABELS)

        self.sc5.SetTickFreq(150,1)

 

        self.sc5.SetValue(self.m_ModelClipping_Z)

 

        EVT_SLIDER(winmclipping,2109,self.OnHScrollmclipping)

       

        self.checkbox = wxCheckBox(winmclipping,2110,"Model clipping ON/OFF",wxPoint(50,70),wxSize(200,-1),wxNO_BORDER)

        self.checkbox.SetValue(self.m_ModelClippingONOFF)

        EVT_CHECKBOX(winmclipping,2110,self.OnCheckModelclippingonoff)

 

        self.view.InitActivePlanes()

        while self.view.MoreActivePlanes():

            thePlane = self.view.ActivePlane()

            if thePlane == self.myPlane:

                self.m_ModelClippingONOFF = 1

            self.view.NextActivePlanes()

        if self.m_ModelClippingONOFF == 1:

            self.interactive_context.Display(self.myShape,1)

        val = winmclipping.ShowModal()

        if val == wxID_OK:

            if self.myShape.IsNull()== 1:

                self.interactive_context.Erase(self.myShape,0,1)

        else:

            if self.m_ModelClippingONOFF:

            #deactivate the plane

                self.view.SetPlaneOff(self.myPlane)

 

            self.m_ModelClippingONOFF = 0

 

            if self.myShape.IsNull() == 1:

                self.interactive_context.Erase(self.myShape,0,1)

            self.view.Update()

           

      

 

    def OnHScrollmclipping(self,event):

        self.m_ModelClipping_Z = self.sc5.GetValue()

 

        # Setting the ZClipping depth at m_ZClippingDepth value

        clipPln = gp_Pln(gp_Pnt(-self.m_ModelClipping_Z,0,0),gp_Dir(1,0,0))

        A,B,C,D = clipPln.Coefficients()

        self.myPlane.SetPlane(A,B,C,D)

        if self.m_ModelClippingONOFF:

            self.view.SetPlaneOn(self.myPlane)

        myTrsf = gp_Trsf()

        myTrsf.SetTranslation(gp_Pnt(self.m_ModelClipping_Z,0,0), gp_Pnt(self.myModelClipping_Z,0,0))

        self.interactive_context.SetLocation(self.myShape,TopLoc_Location(myTrsf))

        self.interactive_context.Redisplay(self.myShape)

 

        self.view.Update()

 

    def OnCheckModelclippingonoff(self,event):

        #activate the plane

        self.m_ModelClippingONOFF = self.checkbox.GetValue()

        if self.m_ModelClippingONOFF:

            #activate the plane

            self.view.SetPlaneOn(self.myPlane)

            self.interactive_context.Display(self.myShape,1)

        else:

            #deactivate the plane

            self.view.SetPlaneOff(self.myPlane)

            self.interactive_context.Erase(self.myShape,0,1)

        self.view.Update()