VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "Step2"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
' step2.cls - 
'
' 1.                        - Intersect2Line
' 2.                        - Intersect2Curve
' 3.                  - IntersectLineSegArc
' 4.                    - TanLinePointCircle
' 5.                   - TanLineAngCircle
' 6.                          - RotatePoint
' 7.                        - SymmetryPoint
' 8.      - Couplin2Lines
' 9.                        - Perpendicular

'  
Dim iKompasObject As Kompas6API5.Application   '  KompasObject
Dim iDocument2D As Kompas6API5.Document2D      '  ksDocument2D
Dim iMathematic2D As Kompas6API5.Mathematic2D  '  ksMathematic2D
Dim iForm As Form1

'      iDocument2D        

Sub DrawPointByArray(iDynamicArray As Object)
  If Not iDynamicArray Is Nothing Then
    Dim iMathPointParam As Kompas6API5.MathPointParam   '  ksMathPointParam
    '     
    Set iMathPointParam = iKompasObject.GetParamStruct(ko_MathPointParam)
  
    If Not iMathPointParam Is Nothing Then              '  
      For i = 0 To iDynamicArray.ksGetArrayCount - 1    '      
        iDynamicArray.ksGetArrayItem i, iMathPointParam '   
        '    
        iDocument2D.ksPoint iMathPointParam.x, iMathPointParam.y, 5
        '      
        iKompasObject.ksMessage "x = " & iMathPointParam.x & " y = " & iMathPointParam.y
      Next                                              '  
    End If
  End If
End Sub

'  

Sub Intersect2Line()
  Dim iDynamicArray As Kompas6API5.DynamicArray         '  ksDynamicArray
  '      
  Set iDynamicArray = iKompasObject.GetDynamicArray(POINT_ARR)
  
  If Not iDynamicArray Is Nothing Then                  '  
    iDocument2D.ksLine 10, 10, 0                        '  
    iDocument2D.ksLine 15, 5, 90                        '
    '     (10, 10),    = 0,
    '     (15, 5),    = 90
    '      
    iMathematic2D.ksIntersectLinLin 10, 10, 0, 15, 5, 90, iDynamicArray
    
    DrawPointByArray iDynamicArray                      '   
    
    iDynamicArray.ksDeleteArray                         '  
  End If
End Sub

'  

Sub Intersect2Curve()
  Dim iDynamicArray As Kompas6API5.DynamicArray         '  ksDynamicArray
  '      
  Set iDynamicArray = iKompasObject.GetDynamicArray(POINT_ARR)
  
  If Not iDynamicArray Is Nothing Then                  '  
    Dim pp1 As Long                                     '    
    Dim pp2 As Long                                     '    
    
    iDocument2D.ksBezier 0, 0                           '   
      iDocument2D.ksPoint 20, 0, 0                      '     
      iDocument2D.ksPoint 10, 20, 0
      iDocument2D.ksPoint 20, 40, 0
      iDocument2D.ksPoint 30, 20, 0
      iDocument2D.ksPoint 20, 0, 0
    '  EndObj       
    pp1 = iDocument2D.ksEndObj

    iDocument2D.ksBezier 0, 0                           '   
      iDocument2D.ksPoint 0, 20, 0                      '     
      iDocument2D.ksPoint 20, 10, 0
      iDocument2D.ksPoint 40, 20, 0
      iDocument2D.ksPoint 20, 30, 0
      iDocument2D.ksPoint 0, 20, 0
    pp2 = iDocument2D.ksEndObj

    '  2- ,    : ,
    ' , , , , , , 
    iMathematic2D.ksIntersectCurvCurv pp1, pp2, iDynamicArray
    
    DrawPointByArray iDynamicArray                      '   
    
    iDynamicArray.ksDeleteArray                         '  
  End If
End Sub

'    

Sub IntersectLineSegArc()
  Dim iDynamicArray As Kompas6API5.DynamicArray         '  ksDynamicArray
  '      
  Set iDynamicArray = iKompasObject.GetDynamicArray(POINT_ARR)
  
  If Not iDynamicArray Is Nothing Then                  '  
    iDocument2D.ksLineSeg 0, 40, 100, 40, 1             '  
    iDocument2D.ksArcByPoint 50, 40, 20, 30, 40, 70, 40, 1, 1 '       
    Dim a1 As Double
    Dim a2 As Double
    a1 = iMathematic2D.ksAngle(50, 40, 30, 40)          '   
    a2 = iMathematic2D.ksAngle(50, 40, 70, 40)          '   

    '       
    '    (0, 40),    (100, 40),
    '   (50, 40),   20
    iMathematic2D.ksIntersectLinSArc 0, 40, 100, 40, 50, 40, 20, a1, a2, 1, iDynamicArray
    DrawPointByArray iDynamicArray                      '   
    
    iDynamicArray.ksDeleteArray                         '  
  End If
End Sub
      
'   

Sub TanLinePointCircle()
  Dim iDynamicArray As Kompas6API5.DynamicArray         '  ksDynamicArray
  '      
  Set iDynamicArray = iKompasObject.GetDynamicArray(POINT_ARR)
  
  Dim iMathPointParam As Kompas6API5.MathPointParam     '  ksMathPointParam
  '     
  Set iMathPointParam = iKompasObject.GetParamStruct(ko_MathPointParam)
  
  '  
  If (Not iDynamicArray Is Nothing) And (Not iMathPointParam Is Nothing) Then
    iDocument2D.ksPoint 10, 50, 3                       '  
    iDocument2D.ksCircle 50, 10, 40, 1                  '  
    
    '      ,    
    '    (10, 50),   (50, 10),
    '   40
    iMathematic2D.ksTanLinePointCircle 10, 50, 50, 10, 40, iDynamicArray
    
    DrawPointByArray iDynamicArray                      '   
         
    Dim a As Double
    
    '  
    For i = 0 To iDynamicArray.ksGetArrayCount - 1
      iDynamicArray.ksGetArrayItem i, iMathPointParam   '   
      iDocument2D.ksLine 10, 50, iMathematic2D.ksAngle(10, 50, iMathPointParam.x, iMathPointParam.y)
    Next
       
    iDynamicArray.ksDeleteArray                         '  
  End If
End Sub
  
'   

Sub TanLineAngCircle()
  Dim iDynamicArray As Kompas6API5.DynamicArray         '  ksDynamicArray
  '      
  Set iDynamicArray = iKompasObject.GetDynamicArray(POINT_ARR)
  
  Dim iMathPointParam As Kompas6API5.MathPointParam     '  ksMathPointParam
  '     
  Set iMathPointParam = iKompasObject.GetParamStruct(ko_MathPointParam)
  
  '  
  If (Not iDynamicArray Is Nothing) And (Not iMathPointParam Is Nothing) Then

    iDocument2D.ksLineSeg 0, 40, 100, 40, 1             '  
    iDocument2D.ksCircle 50, 10, 40, 1                  '  
    
    '      ,    
    '   (50, 10),   40,    45
    iMathematic2D.ksTanLineAngCircle 50, 10, 40, 45, iDynamicArray
    
    DrawPointByArray iDynamicArray                      '   
         
    '  
    For i = 0 To iDynamicArray.ksGetArrayCount - 1
      iDynamicArray.ksGetArrayItem i, iMathPointParam   '   
      iDocument2D.ksLine iMathPointParam.x, iMathPointParam.y, 45
    Next
       
    iDynamicArray.ksDeleteArray                         '  
  End If
End Sub

'  

Sub RotatePoint()
  Dim x As Double                                       '   
  Dim y As Double
  
  iDocument2D.ksPoint 60, 50, 3                         '  
  iDocument2D.ksPoint 50, 50, 2                         '  
  
  iMathematic2D.ksRotate 60, 50, 50, 50, 180, x, y      '    
  
  iDocument2D.ksPoint x, y, 5                           '   
  iKompasObject.ksMessage "x = " & x & " y = " & y      '  
End Sub

'  

Sub SymmetryPoint()
  Dim x As Double                                       '   
  Dim y As Double

  iDocument2D.ksPoint 30, 60, 3                         '  
  iDocument2D.ksLineSeg 0, 50, 60, 50, 3                '  
  
  '   ,    
  iMathematic2D.ksSymmetry 30, 60, 0, 50, 60, 50, x, y
  
  iDocument2D.ksPoint x, y, 5                           '   
  iKompasObject.ksMessage "x = " & x & " y = " & y      '  
End Sub

'     

Sub Couplin2Lines()
  Dim iCON As Kompas6API5.CON                           '  ksCON
  '      
  Set iCON = iKompasObject.GetParamStruct(ko_CON)
  
  If Not iCON Is Nothing Then                           '  
    iDocument2D.ksLine 100, 100, 45                     '   -  
    iDocument2D.ksLine 100, 100, -45                    '  
    
    '   ,    
    '   20
    iMathematic2D.ksCouplingLineLine 100, 100, 45, 100, 100, -45, 20, iCON

    '      
    For i = 0 To iCON.GetCount
      iDocument2D.ksCircle iCON.GetXc(i), iCON.GetYc(i), 20, 2
      iDocument2D.ksPoint iCON.GetX1(i), iCON.GetY1(i), i
      iDocument2D.ksPoint iCON.GetX2(i), iCON.GetY2(i), i
    Next
  
  '  
  iKompasObject.ksMessage "count = " & iCON.GetCount & "con[0].x1 = " & iCON.GetX1(0) & " con[0].y1 = " & iCON.GetY1(0) & "con[0].x2 = " & iCON.GetX2(0) & " con[0].y2 = " & iCON.GetY2(0) & " ..."
  End If
End Sub

' 

Sub Perpendicular()
  iDocument2D.ksPoint 50, 50, 2                         '  
  iDocument2D.ksLineSeg 60, 10, 100, 10, 1              '  
  
  Dim x As Double                                       '     
  Dim y As Double

  '      
  '     (50, 50)
  '     (60, 10),     (100, 10)
  iMathematic2D.ksPerpendicular 50, 50, 60, 10, 100, 10, x, y '
  
  iDocument2D.ksLine 50, 50, iMathematic2D.ksAngle(50, 50, x, y)  '  
  iDocument2D.ksPoint x, y, 5                           '    
  
  iKompasObject.ksMessage "x = " & x & " y = " & y      '   
End Sub

'   

Public Function GetLibraryName() As String
  GetLibraryName = "e  " '  
End Function

'   

Public Function ExternalMenuItem(ByVal number As Integer, itemType As Integer, command As Integer) As String
  itemType = 1 'MENUITEM'
  
  Select Case number
    Case 1                                            '  1 -  
      ExternalMenuItem = " "
      command = 1
    Case 2                                            '  2 -  
      ExternalMenuItem = " "
      command = 2
    Case 3                                            '  3 -    
      ExternalMenuItem = "   "
      command = 3
    Case 4                                            '  4 -   
      ExternalMenuItem = "  "
      command = 4
    Case 5                                            '  5 -   
      ExternalMenuItem = "  "
      command = 5
    Case 6                                            '  6 -  
      ExternalMenuItem = " "
      command = 6
    Case 7                                            '  7 -  
      ExternalMenuItem = " "
      command = 7
    Case 8                                            '  8 -     
      ExternalMenuItem = "    "
      command = 8
    Case 9                                            '  9 - 
      ExternalMenuItem = ""
      command = 9
    Case 10                                           '   
      itemType = 3 'ENDMENU'
      ExternalMenuItem = ""
      command = -1
  End Select
End Function

'    -      

Public Sub ExternalRunCommand(ByVal command As Integer, ByVal mode As Integer, ByVal Kompas As Kompas6API5.Application)
  Set iKompasObject = Kompas                          '   
  
  If iKompasObject Is Nothing Then                    '     - 
    Exit Sub                                          '    
  End If
  
  Set iDocument2D = iKompasObject.ActiveDocument2D    '    2D 
  
  If iDocument2D Is Nothing Then                      '       2D 
    Exit Sub                                          '      
  End If
  
  Set iMathematic2D = iKompasObject.GetMathematic2D   '    
  
  If iMathematic2D Is Nothing Then                    '     
    Exit Sub                                          '      
  End If
  
  Select Case command                                 '   
    Case 1
      Intersect2Line                                  '  
    Case 2
      Intersect2Curve                                 '  
    Case 3
      IntersectLineSegArc                             '    
    Case 4
      TanLinePointCircle                              '   
    Case 5
      TanLineAngCircle                                '   
    Case 6
      RotatePoint                                     '  
    Case 7
      SymmetryPoint                                   '  
    Case 8
      Couplin2Lines                                   '     
    Case 9
      Perpendicular                                   ' 
  End Select
  
  iKompasObject.ksMessageBoxResult                    '   
  
End Sub


Public Function ExternalGetImage(ByVal command As Integer, enableDelete As Integer) As OLE_HANDLE
  Select Case command
    Case 1
      ExternalGetImage = iForm.Image1.Picture.Handle

    Case 2
      ExternalGetImage = iForm.Image2.Picture.Handle
    
    Case 3
      ExternalGetImage = iForm.Image2.Picture.Handle
    
    Case 4
      ExternalGetImage = iForm.Image2.Picture.Handle
    
    Case Else
      ExternalGetImage = iForm.Image2.Picture.Handle

  End Select
  
  enableDelete = False
End Function

Public Function GetImageHeight() As Long
  GetImageHeight = 100
End Function

Public Function GetImageWidth() As Long
  GetImageWidth = 100
End Function

Private Sub Class_Initialize()
  Set iForm = New Form1
End Sub

Private Sub Class_Terminate()
  Set iForm = Nothing
End Sub

