Allow showing the coordinate points as text

This commit is contained in:
hasufell 2014-10-10 15:03:12 +02:00
parent 4137af7a7f
commit 01e2dd7802
No known key found for this signature in database
GPG Key ID: 220CD1C5BDEED020
3 changed files with 87 additions and 20 deletions

View File

@ -5,6 +5,7 @@ module Diagram (t,
dY, dY,
alg, alg,
gd, gd,
ct,
defaultProp, defaultProp,
diag, diag,
diagS, diagS,
@ -47,6 +48,8 @@ data DiagProp = MkProp {
alg :: Int, alg :: Int,
-- |If we want to show the grid. -- |If we want to show the grid.
gd :: Bool, gd :: Bool,
-- |If we want to show the coordinates as text.
ct :: Bool,
-- |Square size used to show the grid and x/y-axis. -- |Square size used to show the grid and x/y-axis.
sqS :: Double sqS :: Double
} }
@ -66,7 +69,7 @@ instance Monoid Diag where
-- |The default properties of the Diagram. -- |The default properties of the Diagram.
defaultProp :: DiagProp defaultProp :: DiagProp
defaultProp = MkProp 2 (0,500) (0,500) 0 False 50 defaultProp = MkProp 2 (0,500) (0,500) 0 False False 50
-- |Extract the lower bound of the x-axis dimension. -- |Extract the lower bound of the x-axis dimension.
@ -102,6 +105,19 @@ coordPoints = Diag cp
dot = (circle $ t p :: Diagram Cairo R2) # fc black dot = (circle $ t p :: Diagram Cairo R2) # fc black
coordPointsText :: Diag
coordPointsText = Diag cpt
where
cpt _ vt =
position $
zip vt
((\(x, y) -> (flip (<>) (square 1 # lw none) .
text $ ("(" ++ show x ++ ", " ++ show y ++ ")")) #
scale 10 # translate (r2 (0, 10))) <$>
unp2 <$>
vt)
-- |Create a diagram which shows the points of the convex hull. -- |Create a diagram which shows the points of the convex hull.
convexHullPoints :: Diag convexHullPoints :: Diag
convexHullPoints = Diag chp convexHullPoints = Diag chp
@ -114,6 +130,22 @@ convexHullPoints = Diag chp
vtch = grahamGetCH vt vtch = grahamGetCH vt
-- |Create a diagram which shows the points of the convex hull.
convexHullPointsText :: Diag
convexHullPointsText = Diag chpt
where
chpt _ vt =
position $
zip vtch
((\(x, y) -> (flip (<>) (square 1 # lw none) .
text $ ("(" ++ show x ++ ", " ++ show y ++ ")")) #
scale 10 # translate (r2 (0, 10))) <$>
unp2 <$>
vtch)
where
vtch = grahamGetCH vt
-- |Create a diagram which shows the lines along the convex hull -- |Create a diagram which shows the lines along the convex hull
-- points. -- points.
convexHullLines :: Diag convexHullLines :: Diag
@ -220,14 +252,17 @@ diag :: DiagProp -> [PT] -> Diagram Cairo R2
diag p = case alg p of diag p = case alg p of
0 -> 0 ->
mkDiag mkDiag
(mconcat [coordPoints, xAxis, yAxis, (mconcat [if ct p then coordPointsText else mempty,
(if gd p then grid else mempty), whiteRectB]) coordPoints, xAxis, yAxis,
(if gd p then grid else mempty),whiteRectB])
p p
1 -> 1 ->
mkDiag mkDiag
(mconcat (mconcat
[convexHullPoints, convexHullLines, coordPoints, [if ct p then convexHullPointsText else mempty,
xAxis, yAxis, (if gd p then grid else mempty), whiteRectB]) convexHullPoints, convexHullLines,
coordPoints, xAxis, yAxis,
(if gd p then grid else mempty), whiteRectB])
p p
_ -> mempty _ -> mempty

18
Gtk.hs
View File

@ -15,6 +15,7 @@ import System.Directory
import Text.Read import Text.Read
import OS.FileExt import OS.FileExt
-- |Monolithic object passed to various GUI functions in order -- |Monolithic object passed to various GUI functions in order
-- to keep the API stable and not alter the parameters too much. -- to keep the API stable and not alter the parameters too much.
-- This only holds GUI widgets that are needed to be read during -- This only holds GUI widgets that are needed to be read during
@ -47,7 +48,9 @@ data MyGUI = MkMyGUI {
-- |combo box for choosing the algorithm -- |combo box for choosing the algorithm
cB :: ComboBox, cB :: ComboBox,
-- |grid check button -- |grid check button
gC :: CheckButton gC :: CheckButton,
-- |coord check button
cC :: CheckButton
} }
@ -76,13 +79,14 @@ makeMyGladeGUI = do
aD' <- xmlGetWidget xml castToAboutDialog "aboutdialog" aD' <- xmlGetWidget xml castToAboutDialog "aboutdialog"
cB' <- xmlGetWidget xml castToComboBox "comboalgo" cB' <- xmlGetWidget xml castToComboBox "comboalgo"
gC' <- xmlGetWidget xml castToCheckButton "gridcheckbutton" gC' <- xmlGetWidget xml castToCheckButton "gridcheckbutton"
cC' <- xmlGetWidget xml castToCheckButton "coordcheckbutton"
return $ MkMyGUI win' dB' sB' qB' fB' da' hs' return $ MkMyGUI win' dB' sB' qB' fB' da' hs'
xl' xu' yl' yu' aD' cB' gC' xl' xu' yl' yu' aD' cB' gC' cC'
gifCLI :: FilePath -> IO () gifCLI :: FilePath -> IO ()
gifCLI startFile = do gifCLI _ = do
mesh <- readFile "UB1_sonderfaelle.obj" mesh <- readFile "UB1_sonderfaelle.obj"
gifMain (gifDiagS def mesh) gifMain (gifDiagS def mesh)
@ -206,6 +210,7 @@ drawDiag' fp mygui =
alg' <- comboBoxGetActive (cB mygui) alg' <- comboBoxGetActive (cB mygui)
(daW, daH) <- widgetGetSize (da mygui) (daW, daH) <- widgetGetSize (da mygui)
gd' <- toggleButtonGetActive (gC mygui) gd' <- toggleButtonGetActive (gC mygui)
ct' <- toggleButtonGetActive (cC mygui)
let let
xD = (,) <$> xD = (,) <$>
@ -226,7 +231,8 @@ drawDiag' fp mygui =
dX = xD', dX = xD',
dY = yD', dY = yD',
alg = alg', alg = alg',
gd = gd'}) gd = gd',
ct = ct'})
mesh) mesh)
renderWithDrawable dw r renderWithDrawable dw r
return 0 return 0
@ -252,6 +258,7 @@ saveDiag' fp mygui =
alg' <- comboBoxGetActive (cB mygui) alg' <- comboBoxGetActive (cB mygui)
(daW, daH) <- widgetGetSize (da mygui) (daW, daH) <- widgetGetSize (da mygui)
gd' <- toggleButtonGetActive (gC mygui) gd' <- toggleButtonGetActive (gC mygui)
ct' <- toggleButtonGetActive (cC mygui)
let let
xD = (,) <$> xD = (,) <$>
@ -269,7 +276,8 @@ saveDiag' fp mygui =
dX = xD', dX = xD',
dY = yD', dY = yD',
alg = alg', alg = alg',
gd = gd'}) gd = gd',
ct = ct'})
mesh) mesh)
return 0 return 0
_ -> return 1 _ -> return 1

View File

@ -692,8 +692,7 @@ Malte Flender &lt;malte.flender@fh-bielefeld.de&gt;</property>
</packing> </packing>
</child> </child>
<child> <child>
<widget class="GtkVBox" id="vbox7"> <widget class="GtkVBox" id="vbox8">
<property name="width_request">100</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<child> <child>
@ -709,23 +708,48 @@ Malte Flender &lt;malte.flender@fh-bielefeld.de&gt;</property>
</packing> </packing>
</child> </child>
<child> <child>
<widget class="GtkCheckButton" id="gridcheckbutton"> <widget class="GtkHBox" id="hbox6">
<property name="label" translatable="yes">grid</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">False</property>
<property name="receives_default">False</property> <child>
<property name="draw_indicator">True</property> <widget class="GtkCheckButton" id="gridcheckbutton">
<property name="label" translatable="yes">grid</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="draw_indicator">True</property>
</widget>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<widget class="GtkCheckButton" id="coordcheckbutton">
<property name="label" translatable="yes">coord</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="draw_indicator">True</property>
</widget>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</widget> </widget>
<packing> <packing>
<property name="expand">False</property> <property name="expand">True</property>
<property name="fill">False</property> <property name="fill">True</property>
<property name="position">1</property> <property name="position">1</property>
</packing> </packing>
</child> </child>
</widget> </widget>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
<property name="fill">True</property> <property name="fill">False</property>
<property name="position">3</property> <property name="position">3</property>
</packing> </packing>
</child> </child>