'//
'//   File Name: ElecSuppDraw.EBS
'//
'//   (c) Copyright  1997-2003, Bentley
'//
'//   Description:
'//      This script file is used to create a Electrical support attachment for a pipe.
'//
'//   Global Functions:
'//      at_Instbox_draw             - Draw a 36x18x48 Instrument box in the defined drawing mode
'//      at_Inst3vlv_draw            - Draw a Elect. instrument c/w 3 valve connection in the defined drawing mode
'//      at_Inst5vlv_draw            - Draw a Elect. instrument c/w 5 valve connection in the defined drawing mode
'//      at_Inst3vlvI_draw           - Draw a Elect. instrument c/w 3 valve connection & insulated enclusure in the 
'//                                    defined drawing mode
'//      at_Inst5vlvI_draw           - Draw a Elect. instrument c/w 3 valve connection & insulated enclusure in the
'//                                    defined drawing mode
'//      at_SnglStand_draw           - Draw a Single Instrument stand in the defined drawing mode
'//      at_TeeStand_draw            - Draw a Tee Instrument stand in the defined drawing mode
'//
'//   $Workfile:   ElecSuppDraw.ebs  $
'//   $Author: muhammad.asif $
'//   $Revision: 1.4 $
'//   $Modtime:   Mar 29 2004 07:45:02  $ 
'//
'//   Notes:
'//
'//   $end$
'//

'//////////////////////////////////////////////////////////
'//
'//  General Instrument Draw Routine
'//
'///////////////////////////////////////////////////////////

                                           
Sub at_SnglStand_draw()
   Call at_ElecInstr_draw ("Single Instr Stand")
End Sub

Sub at_DoubleStand_draw()
   Call at_ElecInstr_draw ("Double Instr Stand")
End Sub

Sub at_TripleStand_draw()
   Call at_ElecInstr_draw ("Triple Instr Stand")
End Sub
                                           
Sub at_WalMntSupp_draw()
   Call at_ElecInstr_draw ("Wall Mounted Instr Support")
End Sub
                                           
Sub at_PltMntSupp_draw()
   Call at_ElecInstr_draw ("Pltf Mounted Instr Support")
End Sub

Sub at_TeeStand_draw()
   Call at_ElecInstr_draw ("Tee Instr Stand")
End Sub


'////////////////////////////////////////////////////////////////////////////////
'//
'//  Common Electrical Instrument Draw Routine
'//
'////////////////////////////////////////////////////////////////////////////////

Sub at_ElecInstr_draw (sType As String)

   Dim drawMode         As String            '// Drawing mode variable
   Dim viewVec          As at_Vector         '// View vector
   Dim viewDir          As String            '// View direction
   Dim status           As Integer           '// Check return value
   Dim compID           As At_ComponentID    '// Item reference
   Dim InsPt            As At_Point          '// Location of insertion point

'// Get parameters from specs and preferences

   status = at_Component_getCurrID (compID)
   Call at_Vector_set(viewVec, 0.0, 0.0, 1.0)   'TOP view default
   status = at_Preference_getString (drawMode, "Draw_Mode")
   status = at_Component_getPoint (InsPt, compID, "InsPt.Loc")
   status = at_Component_getViewDir (viewDir, compID, viewVec)

'// Drawing Begins

   status = at_CADCurrObjectSet_begin()

   Select Case UCase(drawMode)

      Case "3D", "DOUBLE"

         Call ElecInstr_draw3D (compID, drawMode, viewVec, InsPt, sType)

      Case "SINGLE"
         Call ElecInstr_draw3D (compID, "3D", viewVec, InsPt, sType)

   End Select

'// Drawing Ends

   status = at_CADCurrObjectSet_addToDrawing()
   Call at_CADCurrObjectSet_end()

End Sub

'////////////////////////////////////////////////////////////////////////////////
'//
'// 3D Electrical Istruments
'//
'////////////////////////////////////////////////////////////////////////////////

Sub ElecInstr_draw3D (compID As at_ComponentID, drawMode As String, viewVec As At_Vector, InsPt As at_Point, sType As String)

   Dim status        As Integer
   Dim obj           As Long
   Dim basePt        As At_Point
   Dim diameter      As Double
   Dim height        As Double
   Dim depth         As Double
   Dim length        As Double
   Dim width1        As Double
   Dim width2        As Double
   Dim PlateThk      As Double
   Dim xdir          As At_Vector
   Dim ydir          As At_Vector
   Dim zDir          As at_vector
   Dim rotation      As Double
   Dim endPt1        As At_Point
   Dim endPt2        As At_Point
   Dim endPt3        As At_Point
   Dim endPt4        As At_Point
   Dim endPt5        As At_Point
   Dim endPt6        As At_Point
   Dim vec1          As At_Vector
   Dim vec2          As At_Vector
   Dim supOD         As Double
   Dim rimFlag       As Integer
   Dim offset        As Double
   Dim class         As String
   Dim basethick     As Double
   Dim supthick      As Double
   Dim supwidth      As Double
   Dim supdepth      As Double
   Dim CentreBox     As at_point
   Dim topoffset     As At_Vector
   Dim endPtAdj      As At_Point
   Dim PipeLoc       As Double
   Dim TopRef        As at_point
   Dim BottomRef     As at_point
   Dim DirSup        As Double
   Dim MatType       As Double
   Dim axisVec As    At_Vector
   Dim apexOffset    As At_Vector         '//Pyramid offset vector (0,0,0) here
   Dim dummy         As at_Vector         '// Null vector for cone
   Dim conCOH        As Integer           '// Flag to draw a centerline on hide
   Dim units         As String            '// Added by TMAC to check CAD units for possible conversion
   Dim conval        As Double            '// Added by TMAC to convert to metric units
   Dim TypeSel       As Double

   cylCOH  = AT_CYLINDER_CENTERLINEONHIDE
   conCOH  = AT_CONE_START_RIM + AT_CONE_END_RIM
   Rims    = AT_CYLINDER_START_RIM + AT_CYLINDER_END_RIM


   '//  Get the diameter and height information from the support data.
   status = At_Component_getReal (diameter, compID, "DIAMETER")
   status = at_Component_getReal (height, compID, "CTR_END_B")
   status = at_Component_getReal (supdepth, compID, "SUPDEPTH")
   status = at_Component_getReal (supwidth, compID, "SUPWIDTH")
   status = at_Component_getReal (depth, compID, "FLATS")
   status = at_Component_getReal (length, compID, "LENGTH")
   status = at_Component_getReal (width1, compID, "WIDTH1")
   status = at_Component_getReal (width2, compID, "WIDTH2")

   status = at_Preference_getString (units, "UNITS")
   If (units = "MMETRIC") Or (units = "METRIC") Then
      conval = 25.4
    Else
      conval = 1.0
   End If
      anglesize = (2.17 * conval)
      PlateThk = (0.39 * conval)

   Call at_Point_set (basePt, 0.0, 0.0, 0.0)
   Call at_Vector_set (xDir, 0.0, 0.0, 1.0)
   Call at_Vector_set (axisVec, 0.0, 0.0, 1.0)

   Call at_Vector_set (yDir, 0.0, 1.0, 0.0)
   Call at_Vector_computeNormal (xDir, topRef, bottomRef)
   Call at_Vector_crossProduct (zDir, xDir, yDir)

   offset = 0

   Select Case UCase(sType)

   Case "SINGLE INSTR STAND"

      status = at_Component_getReal (TypeSel, compID, "typeOption")

   '//Draw single instrument stand

      endPtAdj = basept
      Call at_point_setx (endptadj, -PlateThk)
      Call at_Point_translateByVector (endPt1, endptadj, zDir, supdepth )
      Obj = at_CADCylinder_create(anglesize*.46, endptadj, endPt1, Rims)

      endPtAdj = basept
      Call at_point_setx (endptadj, 0)
      Call at_point_sety (endptadj, 0)
      Call at_point_setz (endptadj, 0)
      Call at_Point_translateByVector (endPt1, endptadj, zDir, 0)
      Call at_Point_translateByVector (endPt2, endptadj, zDir, 0 + PlateThk)

      Obj = at_CADBox_create(endPt1, 0, endPt2, topoffset, Depth, Depth)

      endPtAdj = basept
      Call at_Point_translateByVector (endPt1, endptadj, zDir, supdepth )
      Call at_Vector_set (Vec1, 0.0, 1.0, 0.0)
      Call at_Vector_set (Vec2, 0.0, -1.0, 0.0)
      Call at_Point_translateByVector (endPt3, endPt1, Vec1, length*0.5 )
      Call at_Point_translateByVector (endPt4, endPt1, Vec2, length*0.5 )
      Obj = at_CADCylinder_create(anglesize*.46, endPt3, endPt4, Rims)

   Case "DOUBLE INSTR STAND"

      status = at_Component_getReal (TypeSel, compID, "typeOption")

   '//Draw double instrument stand

      endPtAdj = basept
      Call at_point_setx (endptadj, -PlateThk)
      Call at_Point_translateByVector (endPt1, endptadj, zDir, supdepth )
      Obj = at_CADCylinder_create(anglesize*.46, endptadj, endPt1, Rims)

      endPtAdj = basept
      Call at_point_setx (endptadj, 0)
      Call at_point_sety (endptadj, 0)
      Call at_point_setz (endptadj, 0)
      Call at_Point_translateByVector (endPt1, endptadj, zDir, 0)
      Call at_Point_translateByVector (endPt2, endptadj, zDir, 0 + PlateThk)

      Obj = at_CADBox_create(endPt1, 0, endPt2, topoffset, Depth, Depth)

      endPtAdj = basept
      Call at_Point_translateByVector (endPt1, endptadj, zDir, supdepth )
      Call at_Vector_set (Vec1, 0.0, 1.0, 0.0)
      Call at_Vector_set (Vec2, 0.0, -1.0, 0.0)
      Call at_Point_translateByVector (endPt3, endPt1, Vec1, length*0.5 )
      Call at_Point_translateByVector (endPt4, endPt1, Vec2, length*0.5 )
      Obj = at_CADCylinder_create(anglesize*.46, endPt3, endPt4, Rims)

      Call at_Point_midpoint (endPt1, endPt3, endPt4)
      Call at_Point_midpoint (endPt2, endPt1, endPt4)
      Call at_Point_midpoint (endPt1, endPt1, endPt3)
      Call at_Vector_computeNormal (Vec1, endPt3, endPt4)
      Call at_Vector_computeNormal (Vec2, endPt4, endPt3)

      Call at_Point_translateByVector (endPt5, endPt1, Vec1, length*0.01 )
      Call at_Point_translateByVector (endPt6, endPt1, Vec2, length*0.01 )
      Obj = at_CADCylinder_create(anglesize*.5, endPt5, endPt6, Rims)

      Call at_Point_translateByVector (endPt5, endPt2, Vec1, length*0.01 )
      Call at_Point_translateByVector (endPt6, endPt2, Vec2, length*0.01 )
      Obj = at_CADCylinder_create(anglesize*.5, endPt5, endPt6, Rims)

   Case "TRIPLE INSTR STAND"

      status = at_Component_getReal (TypeSel, compID, "typeOption")

   '//Draw triple instrument stand

      endPtAdj = basept
      Call at_point_setx (endptadj, -PlateThk)
      Call at_Point_translateByVector (endPt1, endptadj, zDir, supdepth )
      Obj = at_CADCylinder_create(anglesize*.46, endptadj, endPt1, Rims)

      endPtAdj = basept
      Call at_point_setx (endptadj, 0)
      Call at_point_sety (endptadj, 0)
      Call at_point_setz (endptadj, 0)
      Call at_Point_translateByVector (endPt1, endptadj, zDir, 0)
      Call at_Point_translateByVector (endPt2, endptadj, zDir, 0 + PlateThk)

      Obj = at_CADBox_create(endPt1, 0, endPt2, topoffset, Depth, Depth)

      endPtAdj = basept
      Call at_Point_translateByVector (endPt1, endptadj, zDir, supdepth )
      Call at_Vector_set (Vec1, 0.0, 1.0, 0.0)
      Call at_Vector_set (Vec2, 0.0, -1.0, 0.0)
      Call at_Point_translateByVector (endPt3, endPt1, Vec1, length*0.5 )
      Call at_Point_translateByVector (endPt4, endPt1, Vec2, length*0.5 )
      Obj = at_CADCylinder_create(anglesize*.46, endPt3, endPt4, Rims)

      Call at_Vector_computeNormal (Vec1, endPt3, endPt4)
      Call at_Vector_computeNormal (Vec2, endPt4, endPt3)

      Call at_Point_translateByVector (endPt6, endPt1, Vec1, ((length*0.5)/3))
      Call at_Point_translateByVector (endPt5, endPt6, Vec1, length*0.01 )
      Call at_Point_translateByVector (endPt6, endPt6, Vec2, length*0.01 )
      Obj = at_CADCylinder_create(anglesize*.5, endPt5, endPt6, Rims)
      Call at_Point_translateByVector (endPt6, endPt1, Vec2, ((length*0.5)/3))
      Call at_Point_translateByVector (endPt5, endPt6, Vec1, length*0.01 )
      Call at_Point_translateByVector (endPt6, endPt6, Vec2, length*0.01 )
      Obj = at_CADCylinder_create(anglesize*.5, endPt5, endPt6, Rims)

      Call at_Point_translateByVector (endPt6, endPt1, Vec1, (2*(length*0.5)/3))
      Call at_Point_translateByVector (endPt5, endPt6, Vec1, length*0.01 )
      Call at_Point_translateByVector (endPt6, endPt6, Vec2, length*0.01 )
      Obj = at_CADCylinder_create(anglesize*.5, endPt5, endPt6, Rims)
      Call at_Point_translateByVector (endPt6, endPt1, Vec2, (2*(length*0.5)/3))
      Call at_Point_translateByVector (endPt5, endPt6, Vec1, length*0.01 )
      Call at_Point_translateByVector (endPt6, endPt6, Vec2, length*0.01 )
      Obj = at_CADCylinder_create(anglesize*.5, endPt5, endPt6, Rims)


  Case "WALL MOUNTED INSTR SUPPORT"

   '//Draw wall mounted instrument stand

      endPtAdj = basept
      Call at_point_setz (endptadj, Supwidth)
      Call at_Point_translateByVector (endPt1, endptadj, zDir, Supdepth )
'      Obj = at_CADCylinder_create(anglesize*.46, endptadj, endPt1, Rims)
      Obj = at_CADCylinder_create(diameter/2, endptadj, endPt1, Rims)

      endPtAdj = basept
      Call at_point_setz (endptadj, PlateThk)
      Call at_Point_translateByVector (endPt1, endptadj, XDir, (Supwidth-PlateThk))
'      Obj = at_CADCylinder_create(anglesize*.46, endptadj, endPt1, Rims)
      Obj = at_CADCylinder_create(diameter/2, endptadj, endPt1, Rims)

      Call at_Point_translateByVector (endPt1, endptadj, xDir, (Supwidth-PlateThk))
'      CADObj = at_CADSphere_create(endPt1,anglesize*.47, axisVec)
      CADObj = at_CADSphere_create(endPt1,diameter/2, axisVec)

      endPtAdj = basept
      Call at_point_setx (endptadj, 0)
      Call at_point_sety (endptadj, 0)
      Call at_point_setz (endptadj, 0)
      Call at_Point_translateByVector (endPt1, endptadj, XDir, 0)
      Call at_Point_translateByVector (endPt2, endptadj, XDir, 0 + PlateThk)
'      Obj = at_CADBox_create(endPt1, 0, endPt2, topoffset, Depth*0.488, Depth*0.65)
      Obj = at_CADBox_create(endPt1, 0, endPt2, topoffset, Width2, Width1)


  Case "PLTF MOUNTED INSTR SUPPORT"

   '//Draw platform mounted instrument stand
   
      endPtAdj = basept
      Call at_point_setz (endptadj, Supwidth)
      Call at_Point_translateByVector (endPt1, endptadj, zDir, Supdepth )
      Obj = at_CADCylinder_create(anglesize*.46, endptadj, endPt1, Rims)

      Call at_point_setx (endptadj, Depth*0.2+PlateThk)
      Call at_point_sety (endptadj, Depth*0.174)
      Call at_point_setz (endptadj, (Supwidth+Depth*0.3)/2)
      Call at_Vector_set (apexOffset, 0.0, 0.06, 0.0)
      Call at_Point_translateByVector (endPt1, endptadj, zDir, Depth*0.2) 
      Obj = at_CADPyramid_create(endPt1,(PlateThk*1.3),(Supwidth+Depth*0.3),0.0,endptadj,(PlateThk),(Supwidth+Depth*0.3),apexOffset)

      Call at_point_setx (endptadj, Depth*0.2+PlateThk)
      Call at_point_sety (endptadj, -Depth*0.174)
      Call at_point_setz (endptadj, (Supwidth+Depth*0.3)/2)
      Call at_Vector_set (apexOffset, 0.0, -0.06, 0.0)
      Call at_Point_translateByVector (endPt1, endptadj, zDir, Depth*0.2) 
      Obj = at_CADPyramid_create(endPt1,(PlateThk*1.3),(Supwidth+Depth*0.3),0.0,endptadj,(PlateThk),(Supwidth+Depth*0.3),apexOffset)

      endPtAdj = basept
      Call at_point_setx (endptadj, PlateThk)
      Call at_point_sety (endptadj, 0)
      Call at_point_setz (endptadj, (Supwidth+Depth*0.3)/2)
      Call at_Point_translateByVector (endPt1, endptadj, zDir, 0)
      Call at_Point_translateByVector (endPt2, endptadj, zDir, 0 + PlateThk)
      Obj = at_CADBox_create(endPt1, 0, endPt2, topoffset, Depth*0.40, Supwidth+Depth*0.3)


   Case "TEE INSTR STAND"

      '//Draw tee instrument stand
	  endPtAdj = basept
       Call at_point_setx (endptadj, -supdepth-diameter*0.4)
       Call at_point_setz (endptadj,  Supwidth/2)
       Call at_Point_translateByVector (endPt1, endptadj, zDir, diameter*2)
       Obj = at_CADCylinder_create(diameter/2, endptadj, endPt1, Rims)

       endPtAdj = basept
       Call at_point_setx (endptadj, -supdepth-diameter*0.4)
       Call at_point_setz (endptadj, -Supwidth/2)
       Call at_Point_translateByVector (endPt1, endptadj, zDir, diameter*2)
       Obj = at_CADCylinder_create(diameter/2, endptadj, endPt1, Rims)

       endPtAdj = basept
       Call at_point_setx (endptadj, -supdepth-diameter*0.20)
       Call at_point_sety (endptadj, 0)
       Call at_point_setz (endptadj, -Supwidth/2)
       Call at_Point_translateByVector (endPt1, endptadj, xDir, -diameter)
       Call at_Point_translateByVector (endPt2, endptadj, xDir,Supwidth+diameter)
	   Obj = at_CADBox_create(endPt1, 0, endPt2, topoffset, diameter*0.4, diameter*2)

       endPtAdj = basept
       Call at_point_setx (endptadj, -supdepth)
       Call at_Point_translateByVector (endPt1, endptadj, zDir, -diameter*1.3)
       Obj = at_CADCylinder_create(diameter*0.6, endptadj, endPt1, Rims)

       endPtAdj = basept
       Call at_point_setx (endptadj, -diameter*0.20)
       Call at_Point_translateByVector (endPt1, endptadj, zDir, supdepth-diameter*0.20)
       Obj = at_CADCylinder_create(diameter/2, endptadj, endPt1, Rims)
'base plate
       endPtAdj = basept
       Call at_point_setx (endptadj, 0)
       Call at_point_sety (endptadj, 0)
       Call at_point_setz (endptadj, 0)
       Call at_Point_translateByVector (endPt1, endptadj, zDir, 0)
       Call at_Point_translateByVector (endPt2, endptadj, zDir, 0 + diameter*0.20)
       Obj = at_CADBox_create(endPt1, 0, endPt2, topoffset, diameter*3, diameter*3)

     Case Else                                                                                                

   End Select  

End Sub
