Exemplo n.º 1
0
class Sketch_Command(object):
    def __init__(self, name):
        self.data = []
        self.rootNode: Node = None
        self.objectName = name
        self.objectCounter = 0
        self.curCoordinateSystem = gp_Ax3(gp.XOY())

        self.myType = Sketch_ObjectType.MainSketchType
        self.myColor = Quantity_Color(Quantity_NOC_YELLOW)
        self.myStyle = Aspect_TOL_SOLID
        self.myWidth = 1.0
        self.myPrs3dAspect = Prs3d_LineAspect(self.myColor, self.myStyle,
                                              self.myWidth)

        self.myPolylineMode = False
        self.curPnt2d = gp.Origin2d()
        self.myFirstgp_Pnt2d = gp.Origin2d()
        self.mySecondgp_Pn2d = gp.Origin2d()

        self.myFirstPoint: Geom_CartesianPoint = Geom_CartesianPoint(
            gp.Origin())
        self.mySecondPoint: Geom_CartesianPoint = Geom_CartesianPoint(
            gp.Origin())
        self.myRubberLine = AIS_Line(self.myFirstPoint, self.mySecondPoint)
        self.myRubberLine.SetColor(Quantity_Color(Quantity_NOC_LIGHTPINK1))

    def SetContext(self, theContext: AIS_InteractiveContext):
        self.myContext = theContext

    def SetData(self, theData: list):
        self.data = theData

    def SetRootNode(self, theNode: Node):
        self.rootNode: Node = theNode

    def SetAx3(self, theAx3: gp_Ax3):
        self.curCoordinateSystem = theAx3

    def SetAnalyserSnap(self, theAnalyserSnap):
        self.myAnalyserSnap: Sketch_AnalyserSnap = theAnalyserSnap

    def SetColor(self, theColor):
        self.myColor = theColor

    def SetType(self, theType):
        self.objectType = theType

    def SetWidth(self, theWidth):
        self.myWidth = theWidth

    def SetStyle(self, theLineStyle):
        self.myStyle = theLineStyle

    def AddObject(self, theGeom2d_Geometry: Geom2d_Geometry,
                  theAIS_InteractiveObject: AIS_InteractiveObject,
                  theGeometryType: Sketch_GeometryType):
        self.objectCounter += 1
        numString = str(self.objectCounter)
        currentName = self.objectName
        currentName += numString
        if self.GetTypeOfMethod() == Sketch_ObjectTypeOfMethod.Point_Method:
            theAIS_InteractiveObject.SetColor(self.myColor)
        else:
            self.myPrs3dAspect.SetColor(self.myColor)
            self.myPrs3dAspect.SetTypeOfLine(self.myStyle)
            self.myPrs3dAspect.SetWidth(self.myWidth)

        so = Sketch_Object(theGeom2d_Geometry, theAIS_InteractiveObject,
                           currentName, theGeometryType,
                           self.GetTypeOfMethod())
        so.SetColor(self.myColor)
        so.SetType(self.myType)
        so.SetStyle(self.myStyle)
        so.SetWidth(self.myWidth)
        self.data.append(so)

    def GetTypeOfMethod(self):
        raise NotImplementedError()

    def Action(self):
        raise NotImplementedError()

    def MouseInputEvent(self, thePnt2d: gp_Pnt2d, buttons, modifier):
        raise NotImplementedError()

    def MouseMoveEvent(self, thePnt2d: gp_Pnt2d, buttons, modifiers):
        raise NotImplementedError()

    def MouseReleaseEvent(self, buttons, modifiers):
        pass

    def CancelEvent(self):
        raise NotImplementedError()

    def SetPolylineFirstPnt(self, p1):
        pass

    def GetPolylineFirstPnt(self, p1):
        pass

    def SetPolylineMode(self, mode):
        pass
Exemplo n.º 2
0
    def show_line(self, origin=(0, 0, 0), direction=(0, 0, 1)):

        line_placement = Geom_Line(gp_Ax1(gp_Pnt(*origin), gp_Dir(*direction)))
        line = AIS_Line(line_placement)
        self._display_ais(line)
Exemplo n.º 3
0
 def redraw(self):
     context = self.canva._display.Context
     if not self.registeredCallback:
         self.canva._display.SetSelectionModeNeutral()
         context.SetAutoActivateSelection(True)
     context.RemoveAll(True)
     for uid in self.drawList:
         if uid in self._partDict.keys():
             if uid in self._transparencyDict.keys():
                 transp = self._transparencyDict[uid]
             else:
                 transp = 0.0
             color = self._colorDict[uid]
             aisShape = AIS_Shape(self._partDict[uid])
             context.Display(aisShape, True)
             context.SetColor(aisShape, color, True)
             # Set shape transparency, a float from 0.0 to 1.0
             context.SetTransparency(aisShape, transp, True)
             drawer = aisShape.DynamicHilightAttributes()
             context.HilightWithColor(aisShape, drawer, True)
         elif uid in self._wpDict.keys():
             wp = self._wpDict[uid]
             border = wp.border
             if uid == self.activeWpUID:
                 borderColor = Quantity_Color(Quantity_NOC_DARKGREEN)
             else:
                 borderColor = Quantity_Color(Quantity_NOC_GRAY)
             aisBorder = AIS_Shape(border)
             context.Display(aisBorder, True)
             context.SetColor(aisBorder, borderColor, True)
             transp = 0.8  # 0.0 <= transparency <= 1.0
             context.SetTransparency(aisBorder, transp, True)
             drawer = aisBorder.DynamicHilightAttributes()
             context.HilightWithColor(aisBorder, drawer, True)
             clClr = Quantity_Color(Quantity_NOC_MAGENTA1)
             for cline in wp.clines:
                 geomline = wp.geomLineBldr(cline)
                 aisline = AIS_Line(geomline)
                 aisline.SetOwner(geomline)
                 drawer = aisline.Attributes()
                 # asp parameters: (color, type, width)
                 asp = Prs3d_LineAspect(clClr, 2, 1.0)
                 drawer.SetLineAspect(asp)
                 aisline.SetAttributes(drawer)
                 context.Display(aisline, False)  # (see comment below)
                 # 'False' above enables 'context' mode display & selection
             pntlist = wp.intersectPts()  # type <gp_Pnt>
             for point in pntlist:
                 self.canva._display.DisplayShape(point)
             for ccirc in wp.ccircs:
                 aiscirc = AIS_Circle(wp.convert_circ_to_geomCirc(ccirc))
                 drawer = aisline.Attributes()
                 # asp parameters: (color, type, width)
                 asp = Prs3d_LineAspect(clClr, 2, 1.0)
                 drawer.SetLineAspect(asp)
                 aiscirc.SetAttributes(drawer)
                 context.Display(aiscirc, False)  # (see comment below)
                 # 'False' above enables 'context' mode display & selection
             for edge in wp.edgeList:
                 self.canva._display.DisplayShape(edge, color="WHITE")
             self.canva._display.Repaint()
Exemplo n.º 4
0
 def make_ais(self):
     p1 = Geom_CartesianPoint(to_Pnt(self.p1))
     p2 = Geom_CartesianPoint(to_Pnt(self.p2))
     return AIS_Line(p1, p2)