From 72f5ea3b69fcc8d993bb03c6ed8fa37b7ede0f8d Mon Sep 17 00:00:00 2001 From: Kevin Dill Date: Fri, 5 Dec 2014 17:13:42 -0500 Subject: [PATCH 1/6] Added findInScene and findTypeInScene --- support/proxy/vwf.example.com/sceneGetter.js | 55 +++++++++++++++++++ .../vwf.example.com/sceneGetter.vwf.yaml | 16 ++++++ 2 files changed, 71 insertions(+) create mode 100644 support/proxy/vwf.example.com/sceneGetter.js diff --git a/support/proxy/vwf.example.com/sceneGetter.js b/support/proxy/vwf.example.com/sceneGetter.js new file mode 100644 index 000000000..c1d2cc604 --- /dev/null +++ b/support/proxy/vwf.example.com/sceneGetter.js @@ -0,0 +1,55 @@ +// Copyright 2014 Lockheed Martin Corporation +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may +// not use this file except in compliance with the License. You may obtain +// a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +this.findInScene = function( objName ) { + if ( !this.scene ) { + this.logger.errorx( "findInScene", "Scene is undefined!" ); + return undefined; + } + + var results = this.scene.find( "//" + objName ); + + if ( results.length < 1 ) { + this.logger.errorx( "findInScene", "Object '" + objName + + "' not found" ); + } else if ( results.length > 1 ) { + this.logger.warnx( "findInScene", "Multiple objects named '" + + objName + "' found. Names should really " + + "be unique... but we'll return the first one." ); + } + + return results[ 0 ]; +} + +this.findTypeInScene = function( typeName ) { + if (!this.scene) { + this.logger.errorx( "findTypeInScene", "Scene is undefined!" ); + return undefined; + } + + var results = this.scene.find( ".//element(*,'" + typeName + "')" ); + + if ( results.length < 1 ) { + this.logger.errorx( "findTypeInScene", "Nothing found with type '" + + typeName + "'." ); + } else if ( results.length > 1 ) { + this.logger.warnx( "findTypeInScene", "Multiple objects of type '" + + typeName + "' found. We'll return the first " + + "one." ); + } + + return results[ 0 ]; +} + +//@ sourceURL=http://vwf.example.com/sceneGetter.js diff --git a/support/proxy/vwf.example.com/sceneGetter.vwf.yaml b/support/proxy/vwf.example.com/sceneGetter.vwf.yaml index 109f9bd2c..396b9f9c8 100644 --- a/support/proxy/vwf.example.com/sceneGetter.vwf.yaml +++ b/support/proxy/vwf.example.com/sceneGetter.vwf.yaml @@ -31,3 +31,19 @@ properties: // Nullify the current scene so that next time it is gotten, it will find it from the new path this.scene = null; //@ sourceURL=sceneGetter.scenePath.set + +methods: + + # A helper that does basically what Find does, except that it handles some of + # the busywork (and assumes that we'll be looking in the scene). + # Arguments: + # objectName - the string to search for + findInScene: + + # Same as findInScene, except that this looks by type rather than by name. + # Arguments: + # typeName - the type to search for + findTypeInScene: + +scripts: +- source: "http://vwf.example.com/sceneGetter.js" From bc13440913436d453cd6a72c382e4ccc6693267c Mon Sep 17 00:00:00 2001 From: Kevin Dill Date: Fri, 12 Dec 2014 10:30:02 -0500 Subject: [PATCH 2/6] Added asserts. --- support/proxy/vwf.example.com/assert.js | 29 +++++++++++++++++++ support/proxy/vwf.example.com/assert.vwf.yaml | 28 ++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 support/proxy/vwf.example.com/assert.js create mode 100644 support/proxy/vwf.example.com/assert.vwf.yaml diff --git a/support/proxy/vwf.example.com/assert.js b/support/proxy/vwf.example.com/assert.js new file mode 100644 index 000000000..572d77717 --- /dev/null +++ b/support/proxy/vwf.example.com/assert.js @@ -0,0 +1,29 @@ +// Copyright 2014 Lockheed Martin Corporation +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may +// not use this file except in compliance with the License. You may obtain +// a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +this.assert = function( value, message, dontHalt ) { + if ( !value ) { + if ( message ) { + this.logger.errorx( "assert", message ); + } else { + this.logger.errorx( "assert", "Assert failed!" ); + } + + if ( !dontHalt ) { + debugger; + } + } +} + +//@ sourceURL=http://vwf.example.com/assert.js diff --git a/support/proxy/vwf.example.com/assert.vwf.yaml b/support/proxy/vwf.example.com/assert.vwf.yaml new file mode 100644 index 000000000..d29cb91b1 --- /dev/null +++ b/support/proxy/vwf.example.com/assert.vwf.yaml @@ -0,0 +1,28 @@ +# Copyright 2014 Lockheed Martin Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +--- + +methods: + + # A C++ style assert + # NOTE: these only fire if you have the console open. + # Arguments: + # value - the value we're checking. If true, we log and halt. + # message - the message to log if the assert fails. Optional. + # dontHalt - if true, we just log the message. Optional. + assert: + +scripts: +- source: "http://vwf.example.com/assert.js" \ No newline at end of file From 6e8bc91a477c5bbdb993fedabeb701f93c042190 Mon Sep 17 00:00:00 2001 From: Kevin Dill Date: Wed, 17 Dec 2014 13:07:44 -0500 Subject: [PATCH 3/6] Improved documentation, made warnings and errors optional. --- support/proxy/vwf.example.com/sceneGetter.js | 29 +++++++++++++++---- .../vwf.example.com/sceneGetter.vwf.yaml | 17 +++++++++-- 2 files changed, 38 insertions(+), 8 deletions(-) diff --git a/support/proxy/vwf.example.com/sceneGetter.js b/support/proxy/vwf.example.com/sceneGetter.js index c1d2cc604..575232fad 100644 --- a/support/proxy/vwf.example.com/sceneGetter.js +++ b/support/proxy/vwf.example.com/sceneGetter.js @@ -12,7 +12,15 @@ // See the License for the specific language governing permissions and // limitations under the License. -this.findInScene = function( objName ) { +this.findInScene = function( objName, errorOnNotFound, warnOnTooMany ) { + if ( errorOnNotFound === undefined ) { + errorOnNotFound = true; + } + + if ( warnOnTooMany === undefined ) { + warnOnTooMany = true; + } + if ( !this.scene ) { this.logger.errorx( "findInScene", "Scene is undefined!" ); return undefined; @@ -20,10 +28,10 @@ this.findInScene = function( objName ) { var results = this.scene.find( "//" + objName ); - if ( results.length < 1 ) { + if ( errorOnNotFound && ( results.length < 1 ) ) { this.logger.errorx( "findInScene", "Object '" + objName + "' not found" ); - } else if ( results.length > 1 ) { + } else if ( warnOnTooMany && ( results.length > 1 ) ) { this.logger.warnx( "findInScene", "Multiple objects named '" + objName + "' found. Names should really " + "be unique... but we'll return the first one." ); @@ -32,7 +40,16 @@ this.findInScene = function( objName ) { return results[ 0 ]; } -this.findTypeInScene = function( typeName ) { +this.findTypeInScene = function( typeName, errorOnNotFound, + warnOnTooMany ) { + if ( errorOnNotFound === undefined ) { + errorOnNotFound = true; + } + + if ( warnOnTooMany === undefined ) { + warnOnTooMany = true; + } + if (!this.scene) { this.logger.errorx( "findTypeInScene", "Scene is undefined!" ); return undefined; @@ -40,10 +57,10 @@ this.findTypeInScene = function( typeName ) { var results = this.scene.find( ".//element(*,'" + typeName + "')" ); - if ( results.length < 1 ) { + if ( errorOnNotFound && ( results.length < 1 ) ) { this.logger.errorx( "findTypeInScene", "Nothing found with type '" + typeName + "'." ); - } else if ( results.length > 1 ) { + } else if ( warnOnTooMany && ( results.length > 1 ) ) { this.logger.warnx( "findTypeInScene", "Multiple objects of type '" + typeName + "' found. We'll return the first " + "one." ); diff --git a/support/proxy/vwf.example.com/sceneGetter.vwf.yaml b/support/proxy/vwf.example.com/sceneGetter.vwf.yaml index 396b9f9c8..ff625de79 100644 --- a/support/proxy/vwf.example.com/sceneGetter.vwf.yaml +++ b/support/proxy/vwf.example.com/sceneGetter.vwf.yaml @@ -36,13 +36,26 @@ methods: # A helper that does basically what Find does, except that it handles some of # the busywork (and assumes that we'll be looking in the scene). + # NOTE: THIS ONLY GETS THE FIRST OBJECT FOUND. If you want the whole array, + # you'll need to extend this function (or write another). # Arguments: - # objectName - the string to search for + # objectName - the name of the object to search for + # errorOnNotFound - if true (the default) we log an error if the object is + # not found. + # warnOnTooMany - if true (the default) we log a warning if more than one + # object is found. findInScene: # Same as findInScene, except that this looks by type rather than by name. + # NOTE: THIS ONLY GETS THE FIRST OBJECT FOUND. If you want the whole array, + # you'll need to extend this function (or write another). # Arguments: - # typeName - the type to search for + # typeName - the type to search for (where the "type" is the filename + # that the object extends). + # errorOnNotFound - if true (the default) we log an error if the object is + # not found. + # warnOnTooMany - if true (the default) we log a warning if more than one + # object is found. findTypeInScene: scripts: From b4f2484a075a49a6d89bb55f4ea1fd5bb217ad11 Mon Sep 17 00:00:00 2001 From: Spencer Frazier Date: Thu, 29 Jan 2015 10:35:35 -0500 Subject: [PATCH 4/6] More verbose/correct sceneGetter warning --- support/proxy/vwf.example.com/sceneGetter.vwf.yaml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/support/proxy/vwf.example.com/sceneGetter.vwf.yaml b/support/proxy/vwf.example.com/sceneGetter.vwf.yaml index ff625de79..af7a594e1 100644 --- a/support/proxy/vwf.example.com/sceneGetter.vwf.yaml +++ b/support/proxy/vwf.example.com/sceneGetter.vwf.yaml @@ -18,7 +18,11 @@ properties: scene: get: | if ( !this.scene ) { - this.scene = this.find( this.scenePath || "/" )[ 0 ]; + var sp = this.scenePath || "/"; + this.scene = this.find( sp )[ 0 ]; + if ( !this.scene ) { + this.logger.errorx( "scene.get", "Could not find scene node: '", sp, "'" ); + } } return this.scene; //@ sourceURL=sceneGetter.scene.get From 8f2196daabf07c7ea3f8f5a97a73ff74bb25f151 Mon Sep 17 00:00:00 2001 From: Kevin Dill Date: Thu, 12 Feb 2015 12:24:46 -0500 Subject: [PATCH 5/6] Fixed the sceneGetter so that it doesn't set this.scene incorrectly when called on the prototype. --- support/proxy/vwf.example.com/sceneGetter.vwf.yaml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/support/proxy/vwf.example.com/sceneGetter.vwf.yaml b/support/proxy/vwf.example.com/sceneGetter.vwf.yaml index af7a594e1..54cec5179 100644 --- a/support/proxy/vwf.example.com/sceneGetter.vwf.yaml +++ b/support/proxy/vwf.example.com/sceneGetter.vwf.yaml @@ -20,8 +20,16 @@ properties: if ( !this.scene ) { var sp = this.scenePath || "/"; this.scene = this.find( sp )[ 0 ]; + // If this is the prototype object then it will think that it is the + // scene (because it is directly attached to the root) - in that case, + // we want to make sure that we don't incorrectly set this.scene, so + // just short-circuit and return undefined. + if ( this.scene === this ) { + return undefined; + } if ( !this.scene ) { - this.logger.errorx( "scene.get", "Could not find scene node: '", sp, "'" ); + this.logger.errorx( "scene.get", "Could not find scene node: '" + sp + + "'" ); } } return this.scene; From 6b2148e77a9d22f2811251c7775ce3db8f9f454d Mon Sep 17 00:00:00 2001 From: Kevin Dill Date: Thu, 12 Feb 2015 12:59:09 -0500 Subject: [PATCH 6/6] Really fix the sceneGetter this time. --- support/proxy/vwf.example.com/sceneGetter.vwf.yaml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/support/proxy/vwf.example.com/sceneGetter.vwf.yaml b/support/proxy/vwf.example.com/sceneGetter.vwf.yaml index 54cec5179..3f48065e0 100644 --- a/support/proxy/vwf.example.com/sceneGetter.vwf.yaml +++ b/support/proxy/vwf.example.com/sceneGetter.vwf.yaml @@ -25,11 +25,10 @@ properties: // we want to make sure that we don't incorrectly set this.scene, so // just short-circuit and return undefined. if ( this.scene === this ) { - return undefined; - } - if ( !this.scene ) { - this.logger.errorx( "scene.get", "Could not find scene node: '" + sp + - "'" ); + this.scene = undefined; + } else if ( !this.scene ) { + this.logger.errorx( "scene.get", + "Could not find scene node: '" + sp + "'" ); } } return this.scene;