Skip to content

Commit

Permalink
w3
Browse files Browse the repository at this point in the history
  • Loading branch information
cquiroz committed Sep 24, 2024
1 parent 26a853b commit 5e7b9df
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 42 deletions.
17 changes: 10 additions & 7 deletions explore/src/main/scala/explore/targeteditor/AgsOverlay.scala
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,25 @@ object AgsOverlay:
}

val maxIndex = props.agsResults.filter(_.isUsable).size
println(s"maxIndex: $maxIndex $selectedIndex")

// println(s"selectedIndex: $selectedIndex, maxIndex: $maxIndex")
val canGoPrev = props.agsState === AgsState.Idle && selectedIndex.exists(_ > 0)
val canGoNext = props.agsState === AgsState.Idle && selectedIndex.exists(_ < maxIndex - 1)

def goPrev(e: ReactEvent): Option[Callback] =
def goPrev: Option[Callback] =
selectedIndex
.map { i =>
props.selectedGS.set(props.agsResults.pick(i - 1))
Callback.log("goPrev") *>
props.selectedGS.set(props.agsResults.pick(i - 1))
}
.filter(_ => canGoNext)
.filter(_ => canGoPrev)

def goNext(e: ReactEvent): Option[Callback] =
def goNext: Option[Callback] =
selectedIndex
.map { i =>
props.selectedGS.set(props.agsResults.pick(i + 1))
Callback.log("goNext") *>
props.selectedGS.set(props.agsResults.pick(i + 1))
}
.filter(_ => canGoNext)

Expand All @@ -85,13 +88,13 @@ object AgsOverlay:
ExploreStyles.AgsNavigation,
<.span(
ExploreStyles.Disabled.unless(canGoPrev),
^.onClick ==>? goPrev,
^.onClick -->? goPrev,
ExploreStyles.AgsNavigationButton,
Icons.ChevronLeft
),
<.span(
ExploreStyles.Disabled.unless(canGoNext),
^.onClick ==>? goNext,
^.onClick -->? goNext,
ExploreStyles.AgsNavigationButton,
Icons.ChevronRight
)
Expand Down
85 changes: 51 additions & 34 deletions explore/src/main/scala/explore/targeteditor/AladinCell.scala
Original file line number Diff line number Diff line change
Expand Up @@ -263,13 +263,14 @@ object AladinCell extends ModelOptics with AladinCommon:
(props, ctx, _, _, root, options) => _ =>
import ctx.given

AsterismPreferences
.queryWithDefault[IO](props.uid, props.asterism.ids, Constants.InitialFov)
.flatMap { tp =>
(options.set(tp.ready) *>
setVariable(root, "saturation", tp.saturation) *>
setVariable(root, "brightness", tp.brightness)).toAsync
}
IO.println("Read prefs") *>
AsterismPreferences
.queryWithDefault[IO](props.uid, props.asterism.ids, Constants.InitialFov)
.flatMap { tp =>
(options.set(tp.ready) *>
setVariable(root, "saturation", tp.saturation) *>
setVariable(root, "brightness", tp.brightness)).toAsync
}
}
// Ags selection
.useStateViewBy((props, _, candidates, _, _, _) =>
Expand All @@ -281,19 +282,26 @@ object AladinCell extends ModelOptics with AladinCommon:

selection.withOnMod {
(_, _) match {
case (AgsSelection(_), AgsOverride(n, _, _)) =>
case (AgsOverride(m, _, _), AgsOverride(n, _, _)) if m =!= n =>
Callback.log(s"new selected name to $n") *>
ObsQueries
.setGuideTargetName[IO](props.obsId.get, n.some)
.runAsyncAndForget
case (AgsOverride(_, _, _) | AgsSelection(_), AgsOverride(n, _, _)) =>
// From automatic to manual
ObsQueries
.setGuideTargetName[IO](props.obsId.get, n.some)
.runAsyncAndForget
case (AgsOverride(_, _, _), AgsSelection(_)) =>
Callback.log(s"new overriden name to $n") *>
ObsQueries
.setGuideTargetName[IO](props.obsId.get, n.some)
.runAsyncAndForget
case (AgsOverride(_, _, _), AgsSelection(_)) =>
// From manual to automatic
ObsQueries
.setGuideTargetName[IO](props.obsId.get, none)
.runAsyncAndForget
case _ =>
Callback.log(s"Overridde to automatic") // *>
// ObsQueries
// .setGuideTargetName[IO](props.obsId.get, none)
// .runAsyncAndForget
case m =>
// All other combinations
Callback.empty
Callback.log(m) // Callback.empty
}
}
)
Expand All @@ -307,7 +315,7 @@ object AladinCell extends ModelOptics with AladinCommon:

// if the coordinates change, reset ags, offset and mouse coordinates
for {
_ <- gs.set(AgsSelection(none)).when_(gs.get.isOverride) // TODO Reset remote
// _ <- gs.set(AgsSelection(none)).when_(gs.get.isOverride) // TODO Reset remote
_ <- offsetOnCenter.set(Offset.Zero)
_ <- mouseCoords.setState(props.asterism.baseTracking.baseCoordinates)
} yield ()
Expand Down Expand Up @@ -396,18 +404,21 @@ object AladinCell extends ModelOptics with AladinCommon:
val index = 0.some.filter(_ => r.exists(_.nonEmpty))
val selectedGS = index.flatMap(i => r.flatMap(_.lift(i)))
val name = selectedGS.map(_.target.name)
selectedIndex
.mod {
case AgsSelection(_) => AgsSelection(index) // replace automatic selection
case rem @ RemoteGSSelection(name) =>
r.map(_.pick(name)).getOrElse(rem)
// val loc: Option[Int] =
// r.map(_.indexWhere(_.target.name === name)).filter(_ >= 0)
// loc.fold[GuideStarSelection](AgsSelection(index))(i =>
// AgsOverride(name, i, r.get(i))
// )
case a: AgsOverride => a
}
Callback.log(
s"Ags seleects $index ${selectedIndex.get} ${selectedIndex.get.isOverride}"
) *>
selectedIndex
.mod {
case AgsSelection(_) => AgsSelection(index) // replace automatic selection
case rem @ RemoteGSSelection(name) =>
// Recover the analysis for the remotely selected star
r.map(_.pick(name)).getOrElse(rem)
case a: AgsOverride =>
// If overriden ignore
a
}
.unlessA(selectedIndex.get.isOverride)

// .unlessA(agsOverride.get.value) // *>
// props.obsConf
// .flatMap(_.selectedGS)
Expand Down Expand Up @@ -439,9 +450,10 @@ object AladinCell extends ModelOptics with AladinCommon:

selectedIndex
.set(AgsSelection(none))
.toAsync // *>
.toAsync // *>
// props.obsConf.flatMap(_.selectedGS).map(_.set(none)).orEmpty).toAsync
.whenA(positions.isEmpty) *> runAgs
.whenA(positions.isEmpty) // *>
runAgs.unlessA(selectedIndex.get.isOverride)
case _ => IO.unit
}
}
Expand Down Expand Up @@ -484,7 +496,11 @@ object AladinCell extends ModelOptics with AladinCommon:
// )
// .getOrEmpty
// }
pprint.pprintln(selectedGSIndexView.get)
pprint.pprintln(selectedGSIndexView.get match {
case a @ AgsSelection(_) => a
case a @ RemoteGSSelection(_) => a
case a @ AgsOverride(n, _, _) => s"AgsOverride($n)"
})
// )

val fovView =
Expand All @@ -498,7 +514,8 @@ object AladinCell extends ModelOptics with AladinCommon:
)

val coordinatesSetter =
((c: Coordinates) => mouseCoords.setState(c)).reuseAlways
((c: Coordinates) => Callback.empty).reuseAlways
// ((c: Coordinates) => mouseCoords.setState(c)).reuseAlways

val fovSetter = (newFov: Fov) => {
val ignore = options.get.fold(
Expand Down
2 changes: 1 addition & 1 deletion explore/src/main/scala/explore/targeteditor/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ object GuideStarSelection:
case RemoteGSSelection(name) => name.some
case AgsOverride(name, _, _) => name.some

def isOverride: Boolean = fold(_ => true, _ => false, _ => true)
def isOverride: Boolean = fold(_ => false, _ => false, _ => true)

def idx: Option[Int] = fold(_.index, _ => none, _.selectedGSIndex.some)

Expand Down

0 comments on commit 5e7b9df

Please sign in to comment.