#
# $Id$
# $HeadURL$
# $Author$
#
FIND_PACKAGE(ArcGIS REQUIRED)
ADD_SUBDIRECTORY(ArcGISQt5Hack)

# During development: (instead top CMakeLists.txt"
IF(NOT MSVC)
  SET(CMAKE_C_FLAGS   "${CMAKE_C_FLAGS} -Wextra")
  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wextra")
ENDIF()
OPTION(BUILD_SITMAP_UNIT_TESTS "Build situation map unit tests" ON)


SET(GraphicalObjects_SRCS
  GraphicalObjects/abstract_graphical_object.cpp
  GraphicalObjects/ellipse_parameters.cpp
  GraphicalObjects/graphical_object_attributes.h
  GraphicalObjects/graphical_object_attributes.cpp
  GraphicalObjects/graphical_object_ellipse.cpp
  GraphicalObjects/graphical_object_multi_path.cpp
  GraphicalObjects/graphical_object_path.cpp
  GraphicalObjects/graphical_object_picture_marker.cpp
  GraphicalObjects/graphical_object_range.cpp
  GraphicalObjects/graphical_object_text.cpp
  GraphicalObjects/tactical_appearance.cpp
  GraphicalObjects/graphical_object_cube.cpp

  GraphicalObjects/graphical_object_scene_marker.cpp
  GraphicalObjects/graphical_object_model_scene_marker.cpp
  GraphicalObjects/graphical_object_renderer_attributes.cpp
)
SET(GraphicalObjects_HDRS
  GraphicalObjects/abstract_graphical_object.h
  GraphicalObjects/ellipse_parameters.h
  GraphicalObjects/graphical_object_ellipse.h
  GraphicalObjects/graphical_object_multi_path.h
  GraphicalObjects/graphical_object_picture_marker.h
  GraphicalObjects/graphical_object_path.h
  GraphicalObjects/graphical_object_range.h
  GraphicalObjects/graphical_object_text.h
  GraphicalObjects/stub_graphical_object.h
  GraphicalObjects/tactical_appearance.h
  GraphicalObjects/graphical_object_cube.h

  GraphicalObjects/graphical_object_scene_marker.h
  GraphicalObjects/graphical_object_model_scene_marker.h
  GraphicalObjects/graphical_object_renderer_attributes.cpp
)

QT5_ADD_RESOURCES(GraphicalObjects_SRCS Resources/situation_map.qrc)

SET(Map_SRCS
  Map/bounding_box.cpp
  Map/fill_style.cpp
  Map/line_style.cpp
  Map/map.cpp
  Map/map_notifier.cpp
  Map/map_settings.cpp
  Map/map_initializer.cpp
  Map/object_container.cpp
  Map/object_factory.cpp
  Map/operator_map_settings.cpp
#  Map/point3D.cpp
  Map/party_id_to_color_functor.cpp
#  Map/scene_marker_data.cpp
  Map/situation_map_utils.cpp
  Map/terrain_profile_parameter.cpp
  Map/text_style.cpp
  Map/geometry_model_renderer.cpp
  Map/viewshed_parameter.cpp
)

SET(Map_HDRS
  Map/situation_map_ahtc.ini
  Map/situation_map_defaults.ini
  Map/situation_map_guez.ini
  Map/situation_map_qatar.ini
  Map/situation_map_guez_tablet.ini
  Map/situation_map_ahtc_tablet.ini
  Map/abstract_effect_simulation.h
  Map/abstract_map_object.h
  Map/bounding_box.h
  Map/camera.h
  Map/camera.cpp
  Map/coord_translation_functor.h
#  Map/drop_event_manager.h
  Map/fill_style.h
  Map/generic_object_factory.h
  Map/grid.h
  Map/map.h
  Map/map_notifier.h
  Map/map_settings.h
  Map/map_initializer.h
  Map/measurement.h
  Map/layer_factory.h
  Map/layer_parameter.h
  Map/layer_parameter.cpp
  Map/location_display.h
  Map/line_style.h
  Map/object_container.h
  Map/object_factory.h
  Map/object_indicator.h
  Map/operator_map_settings.h
  Map/overview_map_handler.h
  Map/party_id_to_color_functor.h
  Map/pixel_based_textbox_handler.h
  Map/point3D.h
#  Map/scene_marker_data.cpp
  Map/sidc_symbol.h
  Map/sight_fan.h
  Map/situation_map_utils.h
  Map/situation_map_types.h
  Map/terrain_profile_parameter.h
  Map/terrain_profile.h
  Map/text_style.h
  Map/viewpoint2D.h
  Map/viewpoint2D.cpp
  Map/viewshed_parameter.h
  Map/viewshed.h
  Map/camera.h
  Map/camera.cpp

  Map/overlay_handler.h
  Map/geometry_model_renderer.h
)

SET(MapImpl_SRCS
  MapImpl/abstract_effect_simulation_impl.cpp
  MapImpl/abstract_effect_simulation_impl.h
  MapImpl/abstract_map_object_impl.cpp
  MapImpl/abstract_map_object_impl.h
  MapImpl/coordinate_translation.cpp
  MapImpl/coordinate_translation_thread.cpp
  MapImpl/grid_impl.cpp
  MapImpl/jump_point_model.cpp
  MapImpl/jump_point_custom_view.cpp
  MapImpl/jump_point_widget.cpp
  MapImpl/logical_layer.cpp
  MapImpl/layer_factory_impl.cpp
  MapImpl/layer_control_widget.cpp
  MapImpl/screen_location_elevation_helper_base.cpp
  MapImpl/location_display_impl.cpp
  MapImpl/location_to_elevation_helper.cpp
  MapImpl/location_to_elevation_bulk.cpp
  MapImpl/map_impl.cpp
  MapImpl/map_layer.cpp
  MapImpl/measurement_impl.cpp
  MapImpl/object_container_impl.cpp
  MapImpl/object_indicator_impl.cpp
  MapImpl/overview_map_handler_impl.cpp
  MapImpl/pixel_based_textbox_handler_impl.cpp
  MapImpl/screen_to_location_helper.cpp
  MapImpl/sidc_symbol_impl.cpp
  MapImpl/sight_fan_impl.cpp
  MapImpl/terrain_profile_impl.cpp
  MapImpl/terrain_profile_processor.cpp
#  MapImpl/tms_layer.cpp
  MapImpl/viewshed_base.cpp
  MapImpl/viewshed_analysis.cpp
  MapImpl/viewshed_geo_processing.cpp
  MapImpl/viewshed_base.cpp
  MapImpl/viewshed_impl.cpp
  MapImpl/jump_point_namer.cpp


  MapImpl/geometry_model_renderer_esri.cpp
  MapImpl/overlay_handler_impl.cpp
)

SET(MapImpl_HDRS
  MapImpl/abstract_effect_simulation_impl.h
  MapImpl/abstract_map_object_impl.h
  MapImpl/coordinate_translation.h
  MapImpl/coordinate_translation_thread.h
  MapImpl/coord_translation_functor_impl.h
  MapImpl/geometry_model_renderer_esri.h
  MapImpl/grid_impl.cpp
  MapImpl/grid_impl.h
  MapImpl/jump_point_model.h
  MapImpl/jump_point_custom_view.h
  MapImpl/jump_point_widget.h
  MapImpl/logical_layer.h
  MapImpl/layer_control_widget.h
  MapImpl/layer_factory_impl.h
  MapImpl/screen_location_elevation_helper_base.h
  MapImpl/location_display_impl.h
  MapImpl/location_to_elevation_helper.h
  MapImpl/location_to_elevation_bulk.h
  MapImpl/map_impl.h
  MapImpl/map_layer.h
  MapImpl/measurement_impl.h
  MapImpl/object_container_impl.h
  MapImpl/object_indicator_impl.h
  MapImpl/overview_map_handler_impl.h
  MapImpl/overlay_handler_impl.h
  MapImpl/pixel_based_textbox_handler_impl.h
  MapImpl/screen_to_location_helper.h
  MapImpl/sidc_symbol_impl.h
  MapImpl/sight_fan_impl.h
  MapImpl/terrain_profile_impl.h
  MapImpl/terrain_profile_processor.h
#  MapImpl/tms_layer.h
  MapImpl/viewshed_base.h
  MapImpl/viewshed_analysis.h
  MapImpl/viewshed_geo_processing.h
  MapImpl/viewshed_impl.h
  MapImpl/jump_point_namer.h
)



SET(MapObj_SRCS
  MapObjects/geometry.cpp
)

SET(MapObj_HDRS
  MapObjects/abstract_multi_point_map_object.h
  MapObjects/abstract_single_point_map_object.h
  MapObjects/air_support.h
  MapObjects/area_fire.h
  MapObjects/biological_agent.h
  MapObjects/building_outline.h
  MapObjects/chemical_agent.h
  MapObjects/cube.h
  MapObjects/danger_area.h
  MapObjects/functional_area.h
  MapObjects/geo_image.h
  MapObjects/geometry.h
  MapObjects/hit_line.h
  MapObjects/line_of_sight.h
  MapObjects/map_object_attributes.h
  MapObjects/map_object_indicator.h
  MapObjects/mine.h
  MapObjects/mine_field.h
  MapObjects/nuclear_agent.h
  MapObjects/participant.h
  MapObjects/polygon.h
  MapObjects/polyline.h
  MapObjects/single_fire.h
#  MapObjects/single_fire_central.h
  MapObjects/sound_area.h
  MapObjects/text.h
  MapObjects/virtual_mine.h
  #situation_map_objects_export.h
)


SET (LayerAggregation_SRCS
  LayerAggregation/layer_aggregation_widget.cpp
  LayerAggregation/participant_aggregation_dialog.cpp
)

SET (LayerAggregation_HDRS
  LayerAggregation/layer_aggregation_widget.h
  LayerAggregation/participant_aggregation_dialog.h
)


SET(Rubberbands_SRCS
  Rubberbands/abstract_event_dispatcher.cpp
  Rubberbands/drawable_ellipse.cpp
  Rubberbands/drawable_line.cpp
  Rubberbands/drawable_painter_path.cpp
  Rubberbands/drawable_smooth_path.cpp
  Rubberbands/event_delegater.cpp
  Rubberbands/event_dispatcher.cpp
  Rubberbands/event_mouse_navigator.cpp
  Rubberbands/gestures.cpp
  Rubberbands/rubberband_base.cpp
  Rubberbands/rubberband.cpp
  Rubberbands/rubberband_3d.cpp
  Rubberbands/rubberband_arrow.cpp
  Rubberbands/rubberband_corridor.cpp
  Rubberbands/rubberband_drawable.cpp
  Rubberbands/rubberband_factory.cpp
  Rubberbands/rubberband_frame_handle.cpp
  Rubberbands/rubberband_free_hand.cpp
  Rubberbands/rubberband_ellipse.cpp
  Rubberbands/rubberband_ellipse_handle.cpp
  Rubberbands/rubberband_handle.cpp
  Rubberbands/rubberband_handle_proxy.cpp
  Rubberbands/rubberband_internal.cpp
  Rubberbands/rubberband_line_handle.cpp
  Rubberbands/rubberband_multi_point_feature.cpp
  Rubberbands/rubberband_multi_ellipse_feature.cpp
  Rubberbands/rubberband_multi_point_feature_3d.cpp
  Rubberbands/rubberband_point_handle.cpp
  Rubberbands/rubberband_point_cluster.cpp
  Rubberbands/rubberband_point_feature.cpp
  Rubberbands/rubberband_point_feature_3d.cpp
  Rubberbands/rubberband_polyline_width.cpp
  Rubberbands/rubberband_rectangle.cpp
  Rubberbands/rubberband_smooth_line.cpp
  Rubberbands/rubberband_state_select.cpp
  Rubberbands/rubberband_transform.cpp
  Rubberbands/rubberband_transform_move.cpp
  Rubberbands/rubberband_transform_rotate.cpp
  Rubberbands/rubberband_transform_scale.cpp
  Rubberbands/transient_tactical_symbol.cpp
)

SET(Rubberbands_HDRS
  Rubberbands/abstract_event_dispatcher.h
  Rubberbands/drawable_ellipse.h
  Rubberbands/drawable_line.h
  Rubberbands/drawable_painter_path.h
  Rubberbands/drawable_smooth_path.h
  Rubberbands/event_delegater.h
  Rubberbands/event_dispatcher.h
  Rubberbands/event_mouse_navigator.h
  Rubberbands/gestures.h
  Rubberbands/rubberband_free_hand.h
  Rubberbands/rubberband_base.h
  Rubberbands/rubberband_base_internal.h
  Rubberbands/rubberband.h
  Rubberbands/rubberband_3d.h
  Rubberbands/rubberband_arrow.h
  Rubberbands/rubberband_corridor.h
  Rubberbands/rubberband_drawable.h
  Rubberbands/rubberband_ellipse.h
  Rubberbands/rubberband_ellipse_handle.h
  Rubberbands/rubberband_factory.h
  Rubberbands/rubberband_frame_handle.h
  Rubberbands/rubberband_handle.h
  Rubberbands/rubberband_handle_proxy.h
  Rubberbands/rubberband_internal.h
  Rubberbands/rubberband_line_handle.h
  Rubberbands/rubberband_multi_point_feature.h
  Rubberbands/rubberband_multi_ellipse_feature.h
  Rubberbands/rubberband_multi_point_feature_3d.h
  Rubberbands/rubberband_point_cluster.h
  Rubberbands/rubberband_point_feature.h
  Rubberbands/rubberband_point_feature_3d.h
  Rubberbands/rubberband_point_handle.h
  Rubberbands/rubberband_polyline_width.h
  Rubberbands/rubberband_rectangle.h
  Rubberbands/rubberband_smooth_line.h
  Rubberbands/rubberband_state_select.h
  Rubberbands/rubberband_transform.h
  Rubberbands/rubberband_transform_move.h
  Rubberbands/rubberband_transform_rotate.h
  Rubberbands/rubberband_transform_scale.h
  Rubberbands/transient_tactical_symbol.h
)

SET(Utils_SRCS
  situation_map_export.h
  Utils/movement_track.cpp
  Utils/movement_track_manager.cpp
  Utils/terrain_profile_dialog.cpp
)

SET(Utils_HDRS
  Utils/movement_track.h
  Utils/movement_track_manager.h
  Utils/terrain_profile_dialog.h
)



SET(MathUtils_SRCS
  MathUtils/clipper.cpp
  MathUtils/curve.cpp
  MathUtils/geometry_engine.cpp
  MathUtils/matrix2d.cpp
  MathUtils/path_rasterer.cpp
  MathUtils/simple_helper.cpp
)

SET(MathUtils_HDRS
  MathUtils/clipper.hpp
  MathUtils/curve.h
  MathUtils/geometry_engine.h
  MathUtils/matrix2d.h
  MathUtils/math_const.h
  MathUtils/path_rasterer.h
  MathUtils/simple_helper.h
)

NGL_WRAP_UI(Utils_HDRS
  MapImpl/jump_point_custom_view.ui
  Utils/terrain_profile_dialog.ui
)

NGL_WRAP_UI(MapImpl_SRCS
  MapImpl/jump_point_namer.ui
)


SOURCE_GROUP(GraphicalObjects   FILES ${GraphicalObjects_SRCS} ${GraphicalObjects_HDRS})
SOURCE_GROUP(Map                FILES ${Map_SRCS} ${Map_HDRS} ${MapImpl_SRCS} ${MapImpl_HDRS})
SOURCE_GROUP(MapObjects         FILES ${MapObj_HDRS})
SOURCE_GROUP(LayerAggregation   FILES ${LayerAggregation_SRCS} ${LayerAggregation_HDRS})
SOURCE_GROUP(Rubberband         FILES ${Rubberbands_SRCS} ${Rubberbands_HDRS})
SOURCE_GROUP(Utils              FILES ${Utils_SRCS} ${Utils_HDRS})
SOURCE_GROUP(MathUtils          FILES ${MathUtils_SRCS} ${MathUtils_HDRS})
SOURCE_GROUP(SideBar            FILES ${SideBar_SRCS} ${SideBar_HDRS})


NGL_ADD_LIBRARY(WS situationMap SHARED
#                                       ${FunctionDialog_SRCS}
                                       ${Map_SRCS} ${Map_HDRS} ${MapImpl_SRCS}
                                       ${MapObj_SRCS} ${MapObj_HDRS}
                                       ${GraphicalObjects_SRCS} ${GraphicalObjects_HDRS}
                                       ${LayerAggregation_SRCS} ${LayerAggregation_HDRS}
                                       ${Rubberbands_SRCS}
                                       ${Utils_SRCS} ${Utils_HDRS}
                                       ${MathUtils_SRCS} ${MathUtils_HDRS}
)

NGL_TARGET_INCLUDE_DIRECTORIES(situationMap
  PUBLIC
    ${CMAKE_CURRENT_SOURCE_DIR}/..
)


NGL_TARGET_LINK_LIBRARIES(situationMap
  PRIVATE
    NGLLogger
    ArcGIS::ArcGIS
    Qt5::Concurrent
    Qt5::Network
    Qt5::PrintSupport
    LtsCoordTrans
    ArcGISQt5Hack
  PUBLIC
    Qt5::Core
    Qt5::Widgets
    LtsUtilsCoreHeaderOnly  # QPoint3D
    LtsWidgets
    LtsDataView
    situationMapCommon
    situationMapElevationMap
    situationMapSideBar
    advancedSymbology
    situationMapGeometryModel
    ngltools
)

# Copy on LIBchanges:
IF(TARGET situationMap)
  SET(SYMBOLE_CSV symbole2.csv)
  ADD_CUSTOM_COMMAND(TARGET situationMap POST_BUILD
                     COMMAND ${CMAKE_COMMAND}
                        ARGS -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/FunctionDialog/${SYMBOLE_CSV} $<TARGET_FILE_DIR:situationMap>/${SYMBOLE_CSV}
  )




  # copy ini to build-dir/share/Lts/situation_map/:
  SET(INI_DEST_DIR ${CMAKE_BINARY_DIR}/share/Lts/situation_map)

  SET(SITUATIONMAPSETTINGS_INI situation_map_defaults.ini)
  SET(SITUATIONMAPSETTINGS_INI_PATH Map/${SITUATIONMAPSETTINGS_INI})
  ADD_CUSTOM_COMMAND(TARGET situationMap POST_BUILD
                     COMMAND ${CMAKE_COMMAND}
                        ARGS -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/${SITUATIONMAPSETTINGS_INI_PATH} ${INI_DEST_DIR}/${SITUATIONMAPSETTINGS_INI}
  )

  SET(SITUATIONMAPSETTINGS_INI situation_map_defaults.ini)
  SET(SITUATIONMAPSETTINGS_INI_PATH Map/${SITUATIONMAPSETTINGS_INI})

  #check if we need to change it
  IF(BUILD_RPM AND DEFINED _pname)

    IF(UNIX AND "${_pname}" STREQUAL "guez")
     MESSAGE("Install situationmap ini for GUEZ")
     SET(SITUATIONMAPSETTINGS_INI_PATH Map/situation_map_guez.ini)

     SET(TABLET_SITUATIONMAPSETTINGS_INI_PATH Map/situation_map_guez_tablet.ini)

    ElseIF(UNIX AND "${_pname}" STREQUAL "ahtc")
     MESSAGE("Install situationmap ini for AHTC")
     SET(SITUATIONMAPSETTINGS_INI_PATH Map/situation_map_ahtc.ini)

     SET(TABLET_SITUATIONMAPSETTINGS_INI_PATH Map/situation_map_ahtc_tablet.ini)

    ElseIF(UNIX AND "${_pname}" STREQUAL "l400p2")
     MESSAGE("Install situationmap ini for L400P2")
     SET(SITUATIONMAPSETTINGS_INI_PATH Map/situation_map_land400.ini)

     SET(TABLET_SITUATIONMAPSETTINGS_INI_PATH Map/situation_map_l400p2_tablet.ini)

    ElseIF(UNIX AND "${_pname}" STREQUAL "qatar")
     MESSAGE("Install situationmap ini for Qatar")
     SET(SITUATIONMAPSETTINGS_INI_PATH Map/situation_map_qatar.ini)

     SET(TABLET_SITUATIONMAPSETTINGS_INI_PATH Map/situation_map_qatar_tablet.ini)

    ElseIF(UNIX AND "${_pname}" STREQUAL "qatarmout")
     MESSAGE("Install situationmap ini for Qatar Mout")
     SET(SITUATIONMAPSETTINGS_INI_PATH Map/situation_map_qatarmout.ini)

     SET(TABLET_SITUATIONMAPSETTINGS_INI_PATH Map/situation_map_qatar_tablet.ini)

    ElseIF(UNIX AND "${_pname}" STREQUAL "commaster")
      MESSAGE("Install situationmap ini for ComMaster/Luxemburg")
      SET(SITUATIONMAPSETTINGS_INI_PATH Map/situation_map_luxemburg.ini)

      SET(TABLET_SITUATIONMAPSETTINGS_INI_PATH Map/situation_map_luxemburg_tablet.ini)


    ENDIF()


  ENDIF()

#now that we set the situation map ini if neccecsary we install it depending of the tablet build or not
IF(TABLET_MODE)
    NGL_INSTALL(WS FILES ${TABLET_SITUATIONMAPSETTINGS_INI_PATH} DESTINATION "./share/Lts/situation_map" RENAME ${SITUATIONMAPSETTINGS_INI})
ELSE()
    NGL_INSTALL(WS FILES ${SITUATIONMAPSETTINGS_INI_PATH} DESTINATION "./share/Lts/situation_map" RENAME ${SITUATIONMAPSETTINGS_INI})
ENDIF()

ENDIF()

IF(BUILD_TESTING AND BUILD_SITMAP_UNIT_TESTS)

  NGL_ADD_LIBRARY(WS NO_TRANSLATION situationMap_static STATIC
                                         ${FunctionDialog_SRCS}
                                         ${Map_SRCS} ${Map_HDRS} ${MapImpl_SRCS}
                                         ${MapObj_SRCS} ${MapObj_HDRS}
                                         ${GraphicalObjects_SRCS}
                                         ${Rubberbands_SRCS}
                                         ${Utils_SRCS} ${Utils_HDRS}
                                         ${MathUtils_SRCS} ${MathUtils_HDRS}
  )
  NGL_TARGET_COMPILE_DEFINITIONS(situationMap_static PUBLIC "SITUATIONMAP_EXPORT=")

  NGL_TARGET_INCLUDE_DIRECTORIES(situationMap_static
  INTERFACE
    ${CMAKE_CURRENT_SOURCE_DIR}
  )

  NGL_TARGET_LINK_LIBRARIES(situationMap_static
    PRIVATE
      NGLLogger
      Qt5::Concurrent
      Qt5::Network
      Qt5::PrintSupport
      LtsCoordTrans
      ArcGISQt5Hack
    PUBLIC
      Qt5::Core
      Qt5::Widgets
      LtsUtilsCoreHeaderOnly  # QPoint3D
      LtsWidgets
      LtsDataView
      situationMapCommon
      situationMapElevationMap
      situationMapSideBar
      advancedSymbology_static
      situationMapGeometryModel
      ngltools
      )
ENDIF()

NGL_INSTALL_TARGET(situationMap)


# Choose logical order instead of alphabetical.
# UnitTest should be performed BEFORE ModuleTest
ADD_SUBDIRECTORY(Common)
ADD_SUBDIRECTORY(ElevationMap)
ADD_SUBDIRECTORY(Symbology)
ADD_SUBDIRECTORY(SymbologyGui)
ADD_SUBDIRECTORY(SymbologyXML)
ADD_SUBDIRECTORY(MapObjectsImpl)
#ADD_SUBDIRECTORY(LocalSrv)

ADD_SUBDIRECTORY(SideBar)
ADD_SUBDIRECTORY(FunctionDialog)
ADD_SUBDIRECTORY(GeometryModel)
ADD_SUBDIRECTORY(Portal)

ADD_SUBDIRECTORY(Tests)

IF(BUILD_SITMAP_UNIT_TESTS)
  ADD_SUBDIRECTORY(EvalApps)
  ADD_SUBDIRECTORY(UnitTests)
  ADD_SUBDIRECTORY(UnitTestsGeoModel)
  ADD_SUBDIRECTORY(ModuleTests)
ENDIF()
