Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Position implementation change #1510

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/toolkit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ endif()
SET(CYCLUS_CORE_SRC ${CYCLUS_CORE_SRC} ${cc_files} PARENT_SCOPE)

FILE(GLOB h_files "${CMAKE_CURRENT_SOURCE_DIR}/*.h")
FILE(GLOB cycpp_files "${CMAKE_CURRENT_SOURCE_DIR}/*.cycpp.h")

INSTALL(
FILES ${h_files}
FILES ${h_files} ${cycpp_files}
DESTINATION include/cyclus/toolkit
COMPONENT core
)
19 changes: 15 additions & 4 deletions src/toolkit/position.cc
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#include "position.h"

#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <sstream>

#include "position.h"

namespace cyclus {
namespace toolkit {

Expand Down Expand Up @@ -43,8 +44,18 @@ void Position::set_position(double lat, double lon) {
longitude_ = SetPrecision(lon * CYCLUS_DECIMAL_SECOND_MULTIPLIER, 1);
}

void Position::RecordPosition(Agent* agent) {
agent->context()
->NewDatum("AgentPosition")
->AddVal("Spec", agent->spec())
->AddVal("Prototype", agent->prototype())
->AddVal("AgentId", agent->id())
->AddVal("Latitude", latitude_ / CYCLUS_DECIMAL_SECOND_MULTIPLIER)
->AddVal("Longitude", longitude_ / CYCLUS_DECIMAL_SECOND_MULTIPLIER)
->Record();
}
void Position::LatCheck(double lat) {
if (lat > 90 || lat < -90){
if (lat > 90 || lat < -90) {
std::stringstream msg;
msg << "The provided latitude (" << lat
<< ") is outside the acceptable range. "
Expand All @@ -54,7 +65,7 @@ void Position::LatCheck(double lat) {
}

void Position::LonCheck(double lon) {
if (lon > 180 || lon < -180){
if (lon > 180 || lon < -180) {
std::stringstream msg;
msg << "The provided longitude (" << lon
<< ") is outside the acceptable range."
Expand Down
32 changes: 32 additions & 0 deletions src/toolkit/position.cycpp.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@

// This includes the required header to add geographic coordinates to a
// archetypes.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thinks we need a longer message here that explains how it all works, since it is a brand new concept,

Also, can we use one of the archetypes that’s in cyclus/cyclus to demonstrate?

// One only need to:
// - '#include "toolkit/position.cycpp.h"' in the core of the archetype class (as
// private)
// - and in the EnterNotify() method:
// - set the coordinates 'coordinates = cyclus::toolkit::Position(latitude,
// longitude);'
// - call the record method: 'coordinates.RecordPosititon(this);'

cyclus::toolkit::Position coordinates(0,0);

#pragma cyclus var { \
"default": 0.0, \
"uilabel": "Geographical latitude in degrees as a double", \
"doc": "Latitude of the agent's geographical position. The value should " \
"be expressed in degrees as a double." \
}
double latitude;
// required for compilation but not added by the cycpp preprocessor...
std::vector<int> cycpp_shape_latitude = 0;

#pragma cyclus var { \
"default": 0.0, \
"uilabel": "Geographical longitude in degrees as a double", \
"doc": "Longitude of the agent's geographical position. The value should " \
"be expressed in degrees as a double." \
}
double longitude;
// required for compilation but not added by the cycpp preprocessor...
std::vector<int> cycpp_shape_longitude = 0;
4 changes: 3 additions & 1 deletion src/toolkit/position.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
#define CYCLUS_DECIMAL_SECOND_MULTIPLIER 3600

#include <string>

#include "cyclus.h"

namespace cyclus {
namespace toolkit {

/// @class Position
/// The Position class is a basic class that stores the geographic location of
/// each
Expand Down Expand Up @@ -128,6 +128,8 @@ class Position {
std::string ToString(
Position::StringFormat format = StringFormat::DEGREES) const;

void RecordPosition(Agent* agent);

private:
/// Latitude is stored as seconds of degree. Explanation and example is
/// available above in class documentation
Expand Down
2 changes: 1 addition & 1 deletion tests/toolkit/position_tests.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <gtest/gtest.h>

#include <iostream>
#include <string>

katyhuff marked this conversation as resolved.
Show resolved Hide resolved
#include "toolkit/position.h"
using cyclus::toolkit::Position;

Expand Down