Changeset 14689 for trunk/FACT++/src
- Timestamp:
- 11/25/12 12:01:03 (12 years ago)
- Location:
- trunk/FACT++/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/InterpreterV8.cc
r14688 r14689 10 10 11 11 #ifdef HAVE_NOVA 12 #include <libnova/solar.h> 12 13 #include <libnova/lunar.h> 13 14 #include <libnova/transform.h> … … 1517 1518 return handle_scope.Close(self); 1518 1519 } 1520 1521 Handle<Object> InterpreterV8::ConstructRiseSet(const Handle<Value> time, const ln_rst_time &rst) 1522 { 1523 Handle<Object> obj = Object::New(); 1524 obj->Set(String::New("time"), time, ReadOnly); 1525 if (rst.transit<0) 1526 return obj; 1527 1528 Handle<Value> rise = Date::New(Time(rst.rise).JavaDate()); 1529 Handle<Value> set = Date::New(Time(rst.set).JavaDate()); 1530 Handle<Value> trans = Date::New(Time(rst.transit).JavaDate()); 1531 if (rise.IsEmpty() || set.IsEmpty() || trans.IsEmpty()) 1532 return Handle<Object>(); 1533 1534 obj->Set(String::New("rise"), rise, ReadOnly); 1535 obj->Set(String::New("set"), set, ReadOnly); 1536 obj->Set(String::New("transit"), trans, ReadOnly); 1537 return obj; 1538 } 1539 1540 Handle<Value> InterpreterV8::SunHorizon(const Arguments &args) 1541 { 1542 if (args.Length()>2) 1543 return ThrowException(String::New("Sun.horizon must not be called with one or two arguments.")); 1544 1545 HandleScope handle_scope; 1546 1547 double hrz = NAN; 1548 if (args.Length()<2) 1549 hrz = LN_SOLAR_STANDART_HORIZON; 1550 if (args.Length()==2 && args[1]->IsNumber()) 1551 hrz = args[1]->NumberValue(); 1552 if (args.Length()==2 && args[1]->IsString()) 1553 { 1554 char *arg = *String::AsciiValue(args[1]); 1555 transform(arg, arg+strlen(arg), arg, ::tolower); 1556 1557 const string str = Tools::Trim(arg); 1558 if (str==string("civil").substr(0, str.length())) 1559 hrz = LN_SOLAR_CIVIL_HORIZON; 1560 if (str==string("nautic").substr(0, str.length())) 1561 hrz = LN_SOLAR_NAUTIC_HORIZON; 1562 if (str==string("astronomical").substr(0, str.length())) 1563 hrz = LN_SOLAR_ASTRONOMICAL_HORIZON; 1564 } 1565 1566 if (!finite(hrz)) 1567 return ThrowException(String::New("Second argument did not yield a valid number.")); 1568 1569 const Local<Value> date = 1570 args.Length()==0 ? Date::New(Time().JavaDate()) : args[0]; 1571 if (date.IsEmpty()) 1572 return Undefined(); 1573 1574 const uint64_t v = uint64_t(date->NumberValue()); 1575 const Time utc(v/1000, v%1000); 1576 1577 ln_lnlat_posn obs; 1578 obs.lng = -(17.+53./60+26.525/3600); 1579 obs.lat = 28.+45./60+42.462/3600; 1580 1581 // get Julian day from local time 1582 const double JD = utc.JD(); 1583 1584 ln_rst_time sun; 1585 const bool rc = ln_get_solar_rst_horizon(JD-0.5, &obs, hrz, &sun); 1586 if (rc) 1587 sun.transit = -1; 1588 1589 Handle<Object> rst = ConstructRiseSet(date, sun); 1590 rst->Set(String::New("horizon"), Number::New(hrz)); 1591 return handle_scope.Close(rst); 1592 }; 1593 1594 Handle<Value> InterpreterV8::MoonHorizon(const Arguments &args) 1595 { 1596 if (args.Length()>1) 1597 return ThrowException(String::New("Moon.horizon must not be called with one argument.")); 1598 1599 HandleScope handle_scope; 1600 1601 const Local<Value> date = 1602 args.Length()==0 ? Date::New(Time().JavaDate()) : args[0]; 1603 if (date.IsEmpty()) 1604 return Undefined(); 1605 1606 const uint64_t v = uint64_t(date->NumberValue()); 1607 const Time utc(v/1000, v%1000); 1608 1609 ln_lnlat_posn obs; 1610 obs.lng = -(17.+53./60+26.525/3600); 1611 obs.lat = 28.+45./60+42.462/3600; 1612 1613 // get Julian day from local time 1614 const double JD = utc.JD(); 1615 1616 ln_rst_time moon; 1617 const bool rc = ln_get_lunar_rst(JD-0.5, &obs, &moon); 1618 1619 if (rc) 1620 moon.transit = -1; 1621 1622 Handle<Object> rst = ConstructRiseSet(date, moon); 1623 return handle_scope.Close(rst); 1624 }; 1519 1625 #endif 1520 1626 … … 1792 1898 1793 1899 Handle<ObjectTemplate> dimctrl = ObjectTemplate::New(); 1794 dimctrl->Set(String::New(" newState"),FunctionTemplate::New(WrapNewState), ReadOnly);1795 dimctrl->Set(String::New("setState"), FunctionTemplate::New(WrapSetState), ReadOnly);1796 dimctrl->Set(String::New("getState"), FunctionTemplate::New(WrapGetState), ReadOnly);1900 dimctrl->Set(String::New("defineState"), FunctionTemplate::New(WrapNewState), ReadOnly); 1901 dimctrl->Set(String::New("setState"), FunctionTemplate::New(WrapSetState), ReadOnly); 1902 dimctrl->Set(String::New("getState"), FunctionTemplate::New(WrapGetState), ReadOnly); 1797 1903 1798 1904 Handle<ObjectTemplate> v8 = ObjectTemplate::New(); … … 1852 1958 moon->SetClassName(String::New("Moon")); 1853 1959 moon->Set(String::New("disk"), FunctionTemplate::New(MoonDisk), ReadOnly); 1960 moon->Set(String::New("horizon"), FunctionTemplate::New(MoonHorizon), ReadOnly); 1854 1961 global->Set(String::New("Moon"), moon, ReadOnly); 1962 1963 Handle<FunctionTemplate> sun = FunctionTemplate::New(); 1964 sun->SetClassName(String::New("Sun")); 1965 sun->Set(String::New("horizon"), FunctionTemplate::New(SunHorizon), ReadOnly); 1966 global->Set(String::New("Sun"), sun, ReadOnly); 1855 1967 1856 1968 fTemplateLocal = loc; -
trunk/FACT++/src/InterpreterV8.h
r14688 r14689 17 17 18 18 class Database; 19 20 #ifdef HAVE_NOVA 21 struct ln_rst_time; 22 #endif 19 23 20 24 class InterpreterV8 … … 83 87 v8::Handle<v8::Value> OnChangeSet(v8::Local<v8::String>, v8::Local<v8::Value>, const v8::AccessorInfo &); 84 88 89 static v8::Handle<v8::Value> Constructor(const v8::Arguments &args); 90 91 #ifdef HAVE_NOVA 85 92 static double GetDataMember(const v8::Arguments &args, const char *name); 86 static v8::Handle<v8::Value> Constructor(const v8::Arguments &args);87 93 88 94 static v8::Handle<v8::Value> LocalToString(const v8::Arguments &args); … … 97 103 static v8::Handle<v8::Value> ConstructorSky(const v8::Arguments &args); 98 104 static v8::Handle<v8::Value> ConstructorLocal(const v8::Arguments &args); 105 static v8::Handle<v8::Value> MoonHorizon(const v8::Arguments &args); 106 static v8::Handle<v8::Value> SunHorizon(const v8::Arguments &args); 107 static v8::Handle<v8::Object> ConstructRiseSet(const v8::Handle<v8::Value>, const ln_rst_time &); 108 #endif 99 109 100 110 static v8::Handle<v8::Value> WrapInclude(const v8::Arguments &args) { if (This) return This->FuncInclude(args); else return v8::Undefined(); }
Note:
See TracChangeset
for help on using the changeset viewer.