binding/v8/jsi/geometry/MultiCurve.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 /*!
21  \file MultiCurve.cpp
22 
23  \brief Utility functions to register the MultiCurve class into Google JavaScript V8 engine.
24  */
25 
26 // TerraLib
27 #include "../../../../geometry/MultiCurve.h"
28 #include "../../common/Utils.h"
29 #include "Geometry.h"
30 
31 ::v8::Handle<::v8::Value> MultiCurve_IsClosed(const ::v8::Arguments& args)
32 {
33  ::v8::HandleScope hs;
34 
35  if(args.Holder().IsEmpty())
36  return ::v8::ThrowException(::v8::String::New("In order to use isClosed method you must use object notation: \"isclosed = obj.isClosed();\""));
37 
38  te::gm::MultiCurve* g = te::v8::common::Unwrap<te::gm::MultiCurve>(args.Holder());
39 
40  if(g == 0)
41  return ::v8::ThrowException(::v8::String::New("Invalid geometry in isClosed method!"));
42 
43  bool is = g->isClosed();
44 
45  ::v8::Handle<::v8::Boolean> jis = ::v8::Boolean::New(is);
46 
47  return hs.Close(jis);
48 }
49 
50 ::v8::Handle<::v8::Value> MultiCurve_GetLength(const ::v8::Arguments& args)
51 {
52  ::v8::HandleScope hs;
53 
54  if(args.Holder().IsEmpty())
55  return ::v8::ThrowException(::v8::String::New("In order to use getLength method you must use object notation: \"len = obj.getLength();\""));
56 
57  te::gm::MultiCurve* g = te::v8::common::Unwrap<te::gm::MultiCurve>(args.Holder());
58 
59  if(g == 0)
60  return ::v8::ThrowException(::v8::String::New("Invalid geometry in getLength method!"));
61 
62  double len = g->getLength();
63 
64  ::v8::Local<::v8::Number> jlen = ::v8::Number::New(len);
65 
66  return hs.Close(jlen);
67 }
68 
69 static ::v8::Persistent<::v8::FunctionTemplate> sg_mcurve_template;
70 
71 ::v8::Persistent<::v8::FunctionTemplate>& te::v8::jsi::GetMultiCurveTemplate()
72 {
73  if(sg_mcurve_template.IsEmpty())
74  {
75  ::v8::Persistent<::v8::FunctionTemplate>& geomTpl = GetGeometryCollectionTemplate();
76  ::v8::Local<::v8::FunctionTemplate> result = ::v8::FunctionTemplate::New();
77  result->Inherit(geomTpl);
78 
79  ::v8::Handle<::v8::ObjectTemplate> prototype = result->PrototypeTemplate();
80 
81  prototype->Set(::v8::String::NewSymbol("isClosed"), ::v8::FunctionTemplate::New(MultiCurve_IsClosed));
82  prototype->Set(::v8::String::NewSymbol("getLength"), ::v8::FunctionTemplate::New(MultiCurve_GetLength));
83 
84  sg_mcurve_template = ::v8::Persistent<::v8::FunctionTemplate>::New(result);
85  }
86 
87  return sg_mcurve_template;
88 }
89 
::v8::Handle<::v8::Value > MultiCurve_GetLength(const ::v8::Arguments &args)
::v8::Persistent<::v8::FunctionTemplate > & GetMultiCurveTemplate()
It returns a reference to the persistent template of a MultiCurve object.
bool isClosed() const
It returns true if this MultiCurve is closed [StartPoint ( ) = EndPoint ( ) for each Curve in this Mu...
::v8::Handle<::v8::Value > MultiCurve_IsClosed(const ::v8::Arguments &args)
MultiCurve is a class that represents a 1-dimensional GeometryCollection whose elements are curves...
Definition: MultiCurve.h:50
double getLength() const
It returns the Length of this MultiCurve which is equal to the sum of the lengths of the element Curv...
static::v8::Persistent<::v8::FunctionTemplate > sg_mcurve_template
::v8::Persistent<::v8::FunctionTemplate > & GetGeometryCollectionTemplate()
It returns a reference to the persistent template of a GeometryCollection object. ...