Skip to content

Commit

Permalink
Add support of unfilled frames for MilStd2525Placemarks.
Browse files Browse the repository at this point in the history
  • Loading branch information
ComBatVision committed Aug 24, 2024
1 parent 1a2a0e7 commit 2aea958
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 11 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ buildscript {

allprojects {
group = "earth.worldwind"
version = "1.5.20"
version = "1.5.21"

extra.apply {
set("minSdk", 21)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,4 +245,17 @@ actual object MilStd2525 {
@JvmStatic
actual fun getFillColor(sidc: String) = SymbolUtilities.getFillColorOfAffiliation(sidc)?.toARGB()
?: rendererSettings.friendlyGraphicFillColor.toARGB()

@JvmStatic
actual fun getUnfilledAttributes(sidc: String) = if (SymbolUtilities.isTacticalGraphic(sidc)) {
SymbolUtilities.getLineColorOfAffiliation(sidc)
} else {
SymbolUtilities.getFillColorOfAffiliation(sidc)
}?.toHexString()?.let {
mapOf(
MilStdAttributes.FillColor.toString() to "00000000",
MilStdAttributes.LineColor.toString() to it,
MilStdAttributes.IconColor.toString() to it
)
} ?: emptyMap()
}
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,11 @@ open class Placemark @JvmOverloads constructor(
* @return if placemark should display or skip its rendering
*/
fun selectLevelOfDetail(rc: RenderContext, placemark: Placemark, cameraDistance: Double): Boolean

/**
* Forces level of details regeneration
*/
fun invalidate() {}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ abstract class AbstractMilStd2525Placemark(
invalidate()
}
}
var isFrameFilled = true
set(value) {
// Do not invalidate state if nothing changed
if (field != value) {
field = value
invalidate()
}
}

init {
levelOfDetailSelector = lodSelector
Expand All @@ -61,6 +69,6 @@ abstract class AbstractMilStd2525Placemark(
}

protected open fun invalidate() {
(levelOfDetailSelector as? MilStd2525LevelOfDetailSelector)?.invalidate()
levelOfDetailSelector?.invalidate()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ expect object MilStd2525 {
fun setCountryCode(sidc: String, countryCode: String?): String
fun getLineColor(sidc: String): Int
fun getFillColor(sidc: String): Int
fun getUnfilledAttributes(sidc: String): Map<String, String>
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import earth.worldwind.render.RenderContext
import earth.worldwind.shape.Placemark
import earth.worldwind.shape.PlacemarkAttributes
import earth.worldwind.shape.milstd2525.MilStd2525.getSimplifiedSymbolID
import earth.worldwind.shape.milstd2525.MilStd2525.getUnfilledAttributes
import earth.worldwind.shape.milstd2525.MilStd2525.isTacticalGraphic
import earth.worldwind.shape.milstd2525.MilStd2525.modifiersThreshold
import earth.worldwind.shape.milstd2525.MilStd2525Placemark.Companion.getPlacemarkAttributes
Expand All @@ -18,7 +19,7 @@ open class MilStd2525LevelOfDetailSelector : Placemark.LevelOfDetailSelector {
protected var isHighlighted = false
protected var isInvalidateRequested = false

fun invalidate() { isInvalidateRequested = true }
override fun invalidate() { isInvalidateRequested = true }

/**
* Gets the active attributes for the current distance to the camera and highlighted state.
Expand All @@ -41,34 +42,30 @@ open class MilStd2525LevelOfDetailSelector : Placemark.LevelOfDetailSelector {
val simpleCode = if (isTacticalGraphic(placemark.symbolCode))
getSimplifiedSymbolID(placemark.symbolCode)
else placemark.symbolCode.substring(0, 3) + "*------*****"
placemark.attributes = getPlacemarkAttributes(
simpleCode, symbolAttributes = placemark.symbolAttributes
)
placemark.attributes = getPlacemarkAttributes(simpleCode, symbolAttributes = getAttributes(placemark))
lastLevelOfDetail = LOW_LEVEL_OF_DETAIL
}
} else if (cameraDistance > modifiersThreshold && !placemark.isHighlighted || !placemark.isModifiersVisible) {
// Medium-fidelity: use a simplified SIDC code without status, mobility, size and text modifiers
if (lastLevelOfDetail != MEDIUM_LEVEL_OF_DETAIL || isInvalidateRequested) {
val simpleCode = getSimplifiedSymbolID(placemark.symbolCode)
placemark.attributes = getPlacemarkAttributes(
simpleCode, symbolAttributes = placemark.symbolAttributes
)
placemark.attributes = getPlacemarkAttributes(simpleCode, symbolAttributes = getAttributes(placemark))
lastLevelOfDetail = MEDIUM_LEVEL_OF_DETAIL
}
} else if (!placemark.isHighlighted) {
// High-fidelity: use the regular SIDC code without text modifiers, except unique designation (T)
if (lastLevelOfDetail != HIGH_LEVEL_OF_DETAIL || isInvalidateRequested) {
val basicModifiers = placemark.symbolModifiers?.filter { (k,_) -> k == "T" }
placemark.attributes = getPlacemarkAttributes(
placemark.symbolCode, basicModifiers, placemark.symbolAttributes
placemark.symbolCode, basicModifiers, getAttributes(placemark)
)
lastLevelOfDetail = HIGH_LEVEL_OF_DETAIL
}
} else {
// Highest-fidelity: use the regular SIDC code with all available text modifiers
if (lastLevelOfDetail != HIGHEST_LEVEL_OF_DETAIL || isInvalidateRequested || isHighlightChanged) {
placemark.attributes = getPlacemarkAttributes(
placemark.symbolCode, placemark.symbolModifiers, placemark.symbolAttributes
placemark.symbolCode, placemark.symbolModifiers, getAttributes(placemark)
)
lastLevelOfDetail = HIGHEST_LEVEL_OF_DETAIL
}
Expand All @@ -83,6 +80,10 @@ open class MilStd2525LevelOfDetailSelector : Placemark.LevelOfDetailSelector {
return true
}

private fun getAttributes(placemark: MilStd2525Placemark) = if (placemark.isFrameFilled) placemark.symbolAttributes
else placemark.symbolAttributes?.let { getUnfilledAttributes(placemark.symbolCode) + it }
?: getUnfilledAttributes(placemark.symbolCode)

companion object {
protected const val NORMAL_SCALE = 1.0
protected const val HIGHLIGHTED_SCALE = 1.3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,16 @@ actual object MilStd2525 {

actual fun getFillColor(sidc: String) = SymbolUtilities.getFillColorOfAffiliation(sidc)?.toARGB()?.toInt()
?: RendererSettings.getFriendlyGraphicFillColor().toARGB().toInt()

actual fun getUnfilledAttributes(sidc: String) = if (isTacticalGraphic(sidc)) {
SymbolUtilities.getLineColorOfAffiliation(sidc)
} else {
SymbolUtilities.getFillColorOfAffiliation(sidc)
}?.toHexString(true)?.let {
mapOf(
MilStdAttributes.FillColor to "00000000",
MilStdAttributes.LineColor to it,
MilStdAttributes.IconColor to it
)
} ?: emptyMap()
}
Original file line number Diff line number Diff line change
Expand Up @@ -1038,5 +1038,8 @@ external object ModifiersUnits {
external object MilStdAttributes {
val PixelSize: String
val AltitudeMode: String
val FillColor: String
val LineColor: String
val IconColor: String
}

Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,17 @@ actual object MilStd2525 {
@JvmStatic
actual fun getFillColor(sidc: String) = SymbolUtilities.getFillColorOfAffiliation(sidc)?.rgb
?: rendererSettings.friendlyGraphicFillColor.rgb

@JvmStatic
actual fun getUnfilledAttributes(sidc: String) = if (SymbolUtilities.isTacticalGraphic(sidc)) {
SymbolUtilities.getLineColorOfAffiliation(sidc)
} else {
SymbolUtilities.getFillColorOfAffiliation(sidc)
}?.rgb?.let {
mapOf(
MilStdAttributes.FillColor to "00000000",
MilStdAttributes.LineColor to Integer.toHexString(it),
MilStdAttributes.IconColor to Integer.toHexString(it)
)
} ?: emptyMap()
}

0 comments on commit 2aea958

Please sign in to comment.