DIAG: Allow drawing the square the user path points to

This commit is contained in:
hasufell 2014-11-14 21:28:56 +01:00
parent 1387555de6
commit ecf203c825
No known key found for this signature in database
GPG Key ID: 220CD1C5BDEED020
5 changed files with 119 additions and 9 deletions

View File

@ -52,7 +52,9 @@ data MyGUI = MkMyGUI {
-- |grid check button -- |grid check button
gC :: CheckButton, gC :: CheckButton,
-- |coord check button -- |coord check button
cC :: CheckButton cC :: CheckButton,
-- |Path entry widget for the quad tree.
pE :: Entry
} }
@ -84,6 +86,7 @@ makeMyGladeGUI = do
<*> xmlGetWidget xml castToComboBox "comboalgo" <*> xmlGetWidget xml castToComboBox "comboalgo"
<*> xmlGetWidget xml castToCheckButton "gridcheckbutton" <*> xmlGetWidget xml castToCheckButton "gridcheckbutton"
<*> xmlGetWidget xml castToCheckButton "coordcheckbutton" <*> xmlGetWidget xml castToCheckButton "coordcheckbutton"
<*> xmlGetWidget xml castToEntry "path"
-- |Main entry point for the GTK GUI routines. -- |Main entry point for the GTK GUI routines.
@ -209,6 +212,7 @@ saveAndDrawDiag fp fps mygui =
(daW, daH) <- widgetGetSize (da mygui) (daW, daH) <- widgetGetSize (da mygui)
gd' <- toggleButtonGetActive (gC mygui) gd' <- toggleButtonGetActive (gC mygui)
ct' <- toggleButtonGetActive (cC mygui) ct' <- toggleButtonGetActive (cC mygui)
pE' <- entryGetText (pE mygui)
let let
xD = (,) <$> xD = (,) <$>
@ -230,7 +234,8 @@ saveAndDrawDiag fp fps mygui =
dY = yD', dY = yD',
alg = alg', alg = alg',
gd = gd', gd = gd',
ct = ct'}) ct = ct',
pQt = pE'})
mesh) mesh)
renderWithDrawable dw r renderWithDrawable dw r
if null fps if null fps

View File

@ -380,6 +380,7 @@ Public License instead of this License.
<property name="height_request">750</property> <property name="height_request">750</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="title" translatable="yes">CG2</property> <property name="title" translatable="yes">CG2</property>
<property name="window_position">mouse</property>
<property name="type_hint">dialog</property> <property name="type_hint">dialog</property>
<child> <child>
<widget class="GtkVBox" id="vbox1"> <widget class="GtkVBox" id="vbox1">
@ -460,6 +461,18 @@ Public License instead of this License.
<property name="position">2</property> <property name="position">2</property>
</packing> </packing>
</child> </child>
<child>
<widget class="GtkHSeparator" id="hseparator2">
<property name="visible">True</property>
<property name="can_focus">False</property>
</widget>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="padding">5</property>
<property name="position">3</property>
</packing>
</child>
<child> <child>
<widget class="GtkHBox" id="hbox2"> <widget class="GtkHBox" id="hbox2">
<property name="visible">True</property> <property name="visible">True</property>
@ -757,7 +770,71 @@ Public License instead of this License.
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
<property name="fill">False</property> <property name="fill">False</property>
<property name="position">3</property> <property name="position">4</property>
</packing>
</child>
<child>
<widget class="GtkHSeparator" id="hseparator1">
<property name="visible">True</property>
<property name="can_focus">False</property>
</widget>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="padding">5</property>
<property name="position">5</property>
</packing>
</child>
<child>
<widget class="GtkHBox" id="hbox5">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<widget class="GtkLabel" id="pathlabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">QuadTree Path</property>
</widget>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="padding">5</property>
<property name="position">0</property>
</packing>
</child>
<child>
<widget class="GtkEntry" id="path">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="invisible_char">●</property>
<property name="primary_icon_activatable">False</property>
<property name="secondary_icon_activatable">False</property>
<property name="primary_icon_sensitive">True</property>
<property name="secondary_icon_sensitive">True</property>
</widget>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</widget>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">6</property>
</packing>
</child>
<child>
<widget class="GtkHSeparator" id="hseparator3">
<property name="visible">True</property>
<property name="can_focus">False</property>
</widget>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="padding">5</property>
<property name="position">7</property>
</packing> </packing>
</child> </child>
<child> <child>
@ -773,7 +850,7 @@ Show quad tree squares</property>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
<property name="fill">False</property> <property name="fill">False</property>
<property name="position">4</property> <property name="position">8</property>
</packing> </packing>
</child> </child>
</widget> </widget>

View File

@ -19,8 +19,8 @@ diag p obj@(Object _)
mkDiag (mconcat [convexHPText, convexHP, convexHLs, coordPoints, plotterBG]) mkDiag (mconcat [convexHPText, convexHP, convexHLs, coordPoints, plotterBG])
p obj p obj
| alg p == 4 = | alg p == 4 =
mkDiag (mconcat [squares, coordPointsText, coordPoints, polyLines, mkDiag (mconcat [quadPathSquare, squares, coordPointsText,
plotterBG]) coordPoints, polyLines, plotterBG])
p obj p obj
| otherwise = mempty | otherwise = mempty
diag p objs@(Objects _) diag p objs@(Objects _)

View File

@ -6,11 +6,13 @@ import Algebra.VectorTypes
import Algorithms.ConvexHull.GrahamScan import Algorithms.ConvexHull.GrahamScan
import Algorithms.RangeSearch.Core import Algorithms.RangeSearch.Core
import Algorithms.PolygonIntersection.Core import Algorithms.PolygonIntersection.Core
import Data.Maybe
import Data.Monoid import Data.Monoid
import Diagrams.Backend.Cairo import Diagrams.Backend.Cairo
import Diagrams.Prelude hiding ((<>)) import Diagrams.Prelude hiding ((<>))
import Graphics.Diagram.Types import Graphics.Diagram.Types
import Graphics.Gloss.Data.Extent import Graphics.Gloss.Data.Extent
import Parser.PathParser
-- |Creates a Diagram that shows the coordinates from the points -- |Creates a Diagram that shows the coordinates from the points
@ -188,6 +190,30 @@ squares = Diag f
f _ _ = mempty f _ _ = mempty
-- |Create a diagram that shows a single square of the RangeSearch algorithm
-- from the quad tree in red, according to the given path in pQt.
quadPathSquare :: Diag
quadPathSquare = Diag f
where
f p (Object []) = mempty
f p (Object vt) =
(\((xmin, xmax), (ymin, ymax)) -> rect (xmax - xmin) (ymax - ymin)
# moveTo (p2 ((xmax + xmin) / 2,(ymax + ymin) / 2)) # lw thin # lc red)
(getSquare (stringToQuads (pQt p)) (qt, []))
where
quads :: [QuadOrOrient]
quads = stringToQuads (pQt p)
getSquare :: [QuadOrOrient] -> Zipper PT -> Square
getSquare [] z = getSquareByZipper (dX p, dY p) z
getSquare (q:qs) z = case q of
Orient x -> getSquare qs (fromMaybe z (findNeighbor x z))
Quad x -> getSquare qs (fromMaybe z (goQuad x z))
qt :: QuadTree PT
qt = quadTree vtf (dX p, dY p)
vtf :: [PT]
vtf = filterValidPT p vt
-- |Creates a Diagram that shows an XAxis which is bound -- |Creates a Diagram that shows an XAxis which is bound
-- by the dimensions given in xD from DiagProp. -- by the dimensions given in xD from DiagProp.
xAxis :: Diag xAxis :: Diag

View File

@ -53,7 +53,9 @@ data DiagProp = MkProp {
-- |If we want to show the coordinates as text. -- |If we want to show the coordinates as text.
ct :: Bool, 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,
-- |The path to a quad in the quad tree.
pQt :: String
} }
@ -83,7 +85,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 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.