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

Add ClippingPlaneCollection add/remove events #6875

Merged
merged 3 commits into from
Aug 3, 2018
Merged
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
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Change Log
==========

### 1.49 - 2018-09-03

##### Additions :tada:
* Added `ClippingPlaneCollection.collectionChanged` event. This event is raised when a `ClippingPlane` is added or removed from the collection [#6875](https://github.com/AnalyticalGraphicsInc/cesium/pull/6875)

### 1.48 - 2018-08-01

##### Additions :tada:
Expand Down
40 changes: 31 additions & 9 deletions Source/Scene/ClippingPlaneCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ define([
'../Core/deprecationWarning',
'../Core/destroyObject',
'../Core/DeveloperError',
'../Core/Event',
'../Core/Intersect',
'../Core/Matrix4',
'../Core/PixelFormat',
Expand All @@ -36,6 +37,7 @@ define([
deprecationWarning,
destroyObject,
DeveloperError,
Event,
Intersect,
Matrix4,
PixelFormat,
Expand Down Expand Up @@ -75,15 +77,6 @@ define([
this._dirtyIndex = -1;
this._multipleDirtyPlanes = false;

// Add each ClippingPlane object.
var planes = options.planes;
if (defined(planes)) {
var planesLength = planes.length;
for (var i = 0; i < planesLength; ++i) {
this.add(planes[i]);
}
}

this._enabled = defaultValue(options.enabled, true);

/**
Expand Down Expand Up @@ -111,6 +104,22 @@ define([
*/
this.edgeWidth = defaultValue(options.edgeWidth, 0.0);

/**
* An event triggered when a new clipping plane is added to the collection. Event handlers
* are passed the new plane and the index at which it was added.
* @type {Event}
* @default Event()
*/
this.planeAdded = new Event();

/**
* An event triggered when a new clipping plane is removed from the collection. Event handlers
* are passed the new plane and the index from which it was removed.
* @type {Event}
* @default Event()
*/
this.planeRemoved = new Event();

// If this ClippingPlaneCollection has an owner, only its owner should update or destroy it.
// This is because in a Cesium3DTileset multiple models may reference the tileset's ClippingPlaneCollection.
this._owner = undefined;
Expand All @@ -123,6 +132,15 @@ define([
this._float32View = undefined;

this._clippingPlanesTexture = undefined;

// Add each ClippingPlane object.
var planes = options.planes;
if (defined(planes)) {
var planesLength = planes.length;
for (var i = 0; i < planesLength; ++i) {
this.add(planes[i]);
}
}
}

function unionIntersectFunction(value) {
Expand Down Expand Up @@ -263,6 +281,7 @@ define([

setIndexDirty(this, newPlaneIndex);
this._planes.push(plane);
this.planeAdded.raiseEvent(plane, newPlaneIndex);
};

/**
Expand Down Expand Up @@ -346,6 +365,8 @@ define([
this._multipleDirtyPlanes = true;
planes.length = length;

this.planeRemoved.raiseEvent(clippingPlane, index);

return true;
};

Expand All @@ -365,6 +386,7 @@ define([
plane.onChangeCallback = undefined;
plane.index = -1;
}
this.planeRemoved.raiseEvent(plane, i);
}
this._multipleDirtyPlanes = true;
this._planes = [];
Expand Down
45 changes: 45 additions & 0 deletions Specs/Scene/ClippingPlaneCollectionSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ defineSuite([
expect(clippingPlanes._planes[0]).toBe(planes[0]);
});

it('fires the planeAdded event when a plane is added', function() {
clippingPlanes = new ClippingPlaneCollection();
var spy = jasmine.createSpy();
clippingPlanes.planeAdded.addEventListener(spy);
clippingPlanes.add(planes[0]);
expect(spy).toHaveBeenCalled();
});

it('gets the plane at an index', function() {
clippingPlanes = new ClippingPlaneCollection({
planes : planes
Expand Down Expand Up @@ -138,6 +146,43 @@ defineSuite([
expect(result).toBe(false);
});

it('remove fires planeRemoved event', function() {
clippingPlanes = new ClippingPlaneCollection({
planes : planes
});

var spy = jasmine.createSpy();
clippingPlanes.planeRemoved.addEventListener(spy);

clippingPlanes.remove(planes[0]);
expect(spy).toHaveBeenCalled();
});

it('removeAll removes all of the planes in the collection', function() {
clippingPlanes = new ClippingPlaneCollection({
planes : planes
});

expect(clippingPlanes.length).toEqual(planes.length);

clippingPlanes.removeAll();

expect(clippingPlanes.length).toBe(0);
});

it('removeAll fires planeRemoved event', function() {
clippingPlanes = new ClippingPlaneCollection({
planes : planes
});

var spy = jasmine.createSpy();
clippingPlanes.planeRemoved.addEventListener(spy);

clippingPlanes.removeAll();

expect(spy).toHaveBeenCalled();
});

describe('uint8 texture mode', function() {
beforeEach(function() {
spyOn(ClippingPlaneCollection, 'useFloatTexture').and.returnValue(false);
Expand Down