Skip to content

Commit

Permalink
created observation view, date not yet included
Browse files Browse the repository at this point in the history
continued modelling necessary types
  • Loading branch information
RebeccaNowak committed Feb 9, 2024
1 parent 433edb8 commit d8ea62a
Show file tree
Hide file tree
Showing 10 changed files with 307 additions and 23 deletions.
130 changes: 130 additions & 0 deletions src/PRo3D.Base/CalendarApp/Calendar.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
namespace PRo3D.Base

open System
open Adaptify
open Aardvark.Base
open FSharp.Data.Adaptive
open Aardvark.UI
open Aardvark.UI.Operators
open Aardvark.UI.Generic
open PRo3D.Base

[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
module Calendar =
[<ReferenceEquality; NoComparison>]
type Thing<'a> = { value : 'a }
let inline thing a = { value = a }

type CalendarAction =
| SetDateString of string
| SetDate of DateTime
| SetDateJs of list<string>

let parseDate (dateString : string) =
let sucess, date = DateTime.TryParse dateString
if sucess then
date
else
let dateString = String.trimc '"' dateString
let sucess, date = DateTime.TryParse dateString
if sucess then
date
else
Log.error "[Calendar] Could not parse date %s" dateString
DateTime.Now

let update (m : Calendar) (msg : CalendarAction) =
match msg with
| SetDateString str ->
let result = DateTime.TryParse str
match result with
| true, date ->
Log.line "setting date %s" str
{m with date = date}
| _ ->
Log.error "[Calendar] Could not parse date %s" str
m
| SetDate date ->
{m with date = date}
| SetDateJs lst ->
match lst with
| [] ->
Log.warn "[Calendar] received empty list from js."
m
| date::tail ->
{m with date = parseDate date}

let view (m : AdaptiveCalendar) (centre : bool) (disabled : bool) =
let bootCode =
String.concat ";" [
yield
sprintf "$('#__ID__').calendar({
type:'date',
className: {table: 'ui inverted celled center aligned unstackable table'},
onChange: function(newDate){
console.log(newDate);
var oldDate = $(this).calendar('get date');
if(!oldDate || oldDate != newDate) {
aardvark.processEvent('__ID__', 'onDateChange', newDate.toLocaleDateString());
}
}
});"
]

let attributes =
seq {
yield clazz "ui inverted calendar"
yield onEvent "onDateChange" [] (fun x -> SetDateJs x)
if centre then
yield style "display: flex;align-items: center;;justify-content: center"
} |> Seq.toList

let divClass =
if disabled then
"ui inverted disabled input left icon"
else
"ui inverted input left icon"

require (Html.semui) (
onBoot bootCode (
div attributes [
div [clazz divClass;
] [
i [clazz "inverted calendar icon"] []
input [attribute "placeholder" "Select date"]
]
]
)
)

let init =
{
date = DateTime.Now
minDate = None
maxDate = None
label = None
}

let fromDate date =
{
date = date
minDate = None
maxDate = None
label = None
}

let withMinMax date minDate maxDate =
{
date = date
minDate = Some minDate
maxDate = Some maxDate
label = None
}

let withLabel date minDate maxDate label =
{
date = date
minDate = Some minDate
maxDate = Some maxDate
label = label
}
14 changes: 14 additions & 0 deletions src/PRo3D.Base/CalendarApp/CalendarModel.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace PRo3D.Base

open System
open Adaptify
open Aardvark.Base
open FSharp.Data.Adaptive

[<ModelType>]
type Calendar = {
date : DateTime
minDate : option<DateTime>
maxDate : option<DateTime>
label : option<string>
}
5 changes: 5 additions & 0 deletions src/PRo3D.Base/GisModels.fs
Original file line number Diff line number Diff line change
Expand Up @@ -282,3 +282,8 @@ module GisModels =
spiceName = SpacecraftSpiceName "HERA_SPACECRAFT" // ?? Need to check!
referenceFrame = FrameSpiceName "HERA_SPACECRAFT" // ?? Need to check!
}





4 changes: 3 additions & 1 deletion src/PRo3D.Base/PRo3D.Base.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@
<Compile Include="CooTransformation.fs" />
<Compile Include="Serialization.fs" />
<Compile Include="PlatformIndependent.fs" />
<Compile Include="Utilities.fs" />
<Compile Include="Utilities.fs" />
<Compile Include="CalendarApp\CalendarModel.fs" />
<Compile Include="CalendarApp\Calendar.fs" />
<Compile Include="OutlineEffect.fs" />
<Compile Include="Navigation-Model.fs" />
<Compile Include="GisModels.fs" />
Expand Down
31 changes: 26 additions & 5 deletions src/PRo3D.Core/GIS/GisApp.fs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ open Aether

[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
module GisApp =
type GisAppLenses<'viewer> =
{
surfacesModel : Lens<'viewer, SurfaceModel>
bookmarks : Lens<'viewer, SequencedBookmarks.SequencedBookmarks>
scenePath : Lens<'viewer, option<string>>
navigation : Lens<'viewer, NavigationModel>
referenceSystem : Lens<'viewer, ReferenceSystem>
}

let assignBody (entities : HashMap<SurfaceId, Entity>)
(surfaceId : SurfaceId)
Expand Down Expand Up @@ -67,6 +75,10 @@ module GisApp =
let viewer =
Optic.set lenses.surfacesModel surfaces viewer
viewer, m
| GisAppAction.ObservationInfoMessage msg ->
let info = ObservationInfo.update m.defaultObservationInfo msg
let m = {m with defaultObservationInfo = info}
viewer, m
| GisAppAction.Observe ->
viewer, m
| GisAppAction.AssignBody (surfaceId, body) ->
Expand Down Expand Up @@ -227,11 +239,19 @@ module GisApp =
(viewTree [] surfaces.rootGroup surfaces m)
)



let view (m : AdaptiveGisApp) (surfaces : AdaptiveSurfaceModel) =
div [] [
yield GuiEx.accordion "Surfaces" "Cubes" false
[ viewSurfacesGroupsGis surfaces.surfaces m]
yield GuiEx.accordion "Bookmarks" "Cubes" false []
yield GuiEx.accordion "Observation" "Cubes" false [
ObservationInfo.view m.defaultObservationInfo m.entities m.referenceFrames
|> UI.map ObservationInfoMessage
]
yield GuiEx.accordion "GIS Bookmarks" "Cubes" false [

]
yield GuiEx.accordion "Spacecraft" "Cubes" false []

]
Expand All @@ -258,8 +278,9 @@ module GisApp =
] |> HashMap.ofList

{
bodies = bodies
referenceFrames = referenceFrames
spacecraft = spacecraft
entities = HashMap.empty
bodies = bodies
referenceFrames = referenceFrames
spacecraft = spacecraft
entities = HashMap.empty
defaultObservationInfo = ObservationInfo.inital
}
86 changes: 86 additions & 0 deletions src/PRo3D.Core/GIS/ObservationInfo.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
namespace PRo3D.Core.Gis


open Aardvark.Base
open Aardvark.UI
open PRo3D.Base
open PRo3D.Core
open FSharp.Data.Adaptive
open PRo3D.Core.Surface
open PRo3D.Base.GisModels
open Aether

[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
module ObservationInfo =
let update (m : ObservationInfo) (msg : ObservationInfoAction) =
match msg with
| ObservationInfoAction.CalendarMessage msg ->
{m with time = Calendar.update m.time msg}
| ObservationInfoAction.SetTarget target ->
{m with target = target}
| ObservationInfoAction.SetObserver observer ->
{m with observer = observer}
| ObservationInfoAction.SetTime time ->
{m with time = {m.time with date = time}}
| ObservationInfoAction.SetReferenceFrame frame ->
{m with referenceFrame = frame}

let view (m : AdaptiveObservationInfo)
(entities : amap<System.Guid, Entity>)
(referenceFrames : amap<FrameSpiceName, ReferenceFrame>) =

let entityDropdownText entity =
match Entity.spiceName entity with
| Some name -> name
| None -> "---"

let observerDropdown =
UI.dropDownWithEmptyText
(entities
|> AMap.toASet
|> ASet.toAList
|> AList.map snd)
m.observer
(fun x -> SetObserver x)
(fun x -> entityDropdownText x)
"Select Observer"
let targetDropdown =
UI.dropDownWithEmptyText
(entities
|> AMap.toASet
|> ASet.toAList
|> AList.map snd)
m.target
(fun x -> SetTarget x)
(fun x -> entityDropdownText x)
"Select Target"

let frameDropdown =
UI.dropDownWithEmptyText
(referenceFrames
|> AMap.toASet
|> ASet.toAList
|> AList.map snd)
m.referenceFrame
(fun x -> SetReferenceFrame x)
(fun x -> x.spiceName.Value)
"Select Frame"

require GuiEx.semui (
Html.table [
Html.row "Observer:" [observerDropdown]
Html.row "Target:" [targetDropdown]
//Html.row "Time:" [Calendar.view m.time false false]
// |> UI.map CalendarMessage
Html.row "Reference Frame:" [frameDropdown]
]
)

let inital =
{
target = None
observer = None
time = Calendar.init
referenceFrame = None
}

Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,39 @@ type GisSurface = {
referenceFrame : option<FrameSpiceName>
}

type Entity =
| EntitySurface of GisSurface
| EntitySpaccecraft of Spacecraft

[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
module Entity =
let spiceName (entity : Entity) =
match entity with
| EntitySurface surface ->
match surface.body with
| Some body ->
Some body.Value
| None ->
Log.line "[GisApp-Model] Surface has no associated body!"
None
| EntitySpaccecraft spacecraft ->
Some spacecraft.spiceName.Value

[<ModelType>]
type ObservationInfo = {
target : option<Entity>
observer : option<Entity>
time : Calendar
referenceFrame : option<ReferenceFrame>
}

type ObservationInfoAction =
| CalendarMessage of Calendar.CalendarAction
| SetTarget of option<Entity>
| SetObserver of option<Entity>
| SetTime of DateTime
| SetReferenceFrame of option<ReferenceFrame>

[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
module GisSurface =
let fromBody surfaceId body =
Expand All @@ -44,23 +77,11 @@ module GisSurface =
referenceFrame = frame
}

type Entity =
| EntitySurface of GisSurface
| EntitySpaccecraft of Spacecraft
| EntityBookmark of GisBookmark

type GisAppLenses<'viewer> =
{
surfacesModel : Lens<'viewer, SurfaceModel>
bookmarks : Lens<'viewer, SequencedBookmarks.SequencedBookmarks>
scenePath : Lens<'viewer, option<string>>
navigation : Lens<'viewer, NavigationModel>
referenceSystem : Lens<'viewer, ReferenceSystem>
}

[<ModelType>]
type GisApp =
{
defaultObservationInfo : ObservationInfo

bodies : HashMap<BodySpiceName, Body>
referenceFrames : HashMap<FrameSpiceName, ReferenceFrame>
spacecraft : HashMap<SpacecraftSpiceName, Spacecraft>
Expand All @@ -72,6 +93,7 @@ type GisAppAction =
| AssignBody of (SurfaceId * option<BodySpiceName>)
| AssignReferenceFrame of (SurfaceId * option<FrameSpiceName>)
| SurfacesMessage of SurfaceAppAction
| ObservationInfoMessage of ObservationInfoAction



Loading

0 comments on commit d8ea62a

Please sign in to comment.