{-# LANGUAGE CApiFFI #-}
module OpenCascade.BRepTools.WireExplorer
( WireExplorer
, fromWire
, more
, next
, current
, orientation
)where

import qualified OpenCascade.TopoDS as TopoDS
import OpenCascade.BRepTools.Types (WireExplorer)
import OpenCascade.BRepTools.Internal.Destructors (deleteWireExplorer)
import OpenCascade.Internal.Bool (cBoolToBool)
import qualified OpenCascade.TopAbs as TopAbs
import Foreign.Ptr
import Foreign.C
import Data.Acquire
foreign import capi unsafe "hs_BRepTools_WireExplorer.h hs_new_BRepTools_WireExplorer_fromWire" rawNew :: Ptr TopoDS.Wire -> IO (Ptr WireExplorer)

fromWire :: Ptr TopoDS.Wire -> Acquire (Ptr WireExplorer)
fromWire :: Ptr Wire -> Acquire (Ptr WireExplorer)
fromWire Ptr Wire
wire = IO (Ptr WireExplorer)
-> (Ptr WireExplorer -> IO ()) -> Acquire (Ptr WireExplorer)
forall a. IO a -> (a -> IO ()) -> Acquire a
mkAcquire (Ptr Wire -> IO (Ptr WireExplorer)
rawNew Ptr Wire
wire) Ptr WireExplorer -> IO ()
deleteWireExplorer

foreign import capi unsafe "hs_BRepTools_WireExplorer.h hs_BRepTools_WireExplorer_more" rawMore :: Ptr WireExplorer -> IO (CBool)

more :: Ptr WireExplorer -> IO Bool
more :: Ptr WireExplorer -> IO Bool
more = (CBool -> Bool) -> IO CBool -> IO Bool
forall a b. (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (CBool -> Bool
cBoolToBool) (IO CBool -> IO Bool)
-> (Ptr WireExplorer -> IO CBool) -> Ptr WireExplorer -> IO Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Ptr WireExplorer -> IO CBool
rawMore 

foreign import capi unsafe "hs_BRepTools_WireExplorer.h hs_BRepTools_WireExplorer_next" next :: Ptr WireExplorer -> IO ()

foreign import capi unsafe "hs_BRepTools_WireExplorer.h hs_BRepTools_WireExplorer_current" current :: Ptr WireExplorer -> IO (Ptr TopoDS.Edge)

foreign import capi unsafe "hs_BRepTools_WireExplorer.h hs_BRepTools_WireExplorer_orientation" rawOrientation :: Ptr WireExplorer -> IO (CInt)

orientation :: Ptr WireExplorer -> IO TopAbs.Orientation
orientation :: Ptr WireExplorer -> IO Orientation
orientation Ptr WireExplorer
explorer = Int -> Orientation
forall a. Enum a => Int -> a
toEnum (Int -> Orientation) -> (CInt -> Int) -> CInt -> Orientation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CInt -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (CInt -> Orientation) -> IO CInt -> IO Orientation
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>  Ptr WireExplorer -> IO CInt
rawOrientation Ptr WireExplorer
explorer