-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #139 from NREL/GE-125
new import/export functions
- Loading branch information
Showing
7 changed files
with
97 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import idFactory from './generateId'; | ||
|
||
export default function importFloorplan(context, payload) { | ||
// intializr a versionNumber if the app is running in embedded mode | ||
if (window.api) { window.versionNumber = 0; } | ||
|
||
// GEOMETRY | ||
const geometry = payload.data.stories.map((story) => { | ||
const faces = story.geometry.faces.map((face) => { | ||
const edgeRefs = face.edge_ids.map((id, index) => ({ | ||
edge_id: id, | ||
reverse: !face.edge_order[index], | ||
})); | ||
return { | ||
id: face.id, | ||
edgeRefs, | ||
}; | ||
}); | ||
|
||
const edges = story.geometry.edges.map(e => ({ | ||
id: e.id, | ||
v1: e.vertex_ids[0], | ||
v2: e.vertex_ids[1], | ||
})); | ||
return { | ||
id: story.geometry.id, | ||
faces, | ||
edges, | ||
vertices: story.geometry.vertices, | ||
}; | ||
}); | ||
|
||
// MODELS | ||
const stories = payload.data.stories.map((s) => { | ||
const story = { | ||
geometry_id: s.geometry.id, | ||
...s, | ||
}; | ||
delete story.geometry; | ||
return story; | ||
}); | ||
|
||
function forEachNestedProp(obj, func, propName = null) { | ||
if (_.isObject(obj)) { | ||
Object.keys(obj).forEach(k => forEachNestedProp(obj[k], func, k)); | ||
} else if (_.isArray(obj)) { | ||
obj.forEach(elem => forEachNestedProp(elem, func)); | ||
} else { | ||
func(propName, obj); | ||
} | ||
} | ||
|
||
// find the highest id in the imported floorplan | ||
let largestId = 0; | ||
forEachNestedProp(payload, (k, v) => { | ||
if (k && k === 'id' && (+v > largestId)) { | ||
largestId = v; | ||
} | ||
}); | ||
|
||
// set the idFactory to the next id | ||
largestId += 1; | ||
idFactory.setId(largestId); | ||
|
||
context.commit('importState', { | ||
project: payload.data.project, | ||
application: context.state.application, | ||
models: { | ||
stories, | ||
library: { | ||
building_units: payload.data.building_units, | ||
thermal_zones: payload.data.thermal_zones, | ||
space_types: payload.data.space_types, | ||
construction_sets: payload.data.construction_sets, | ||
windows: payload.data.windows, | ||
daylighting_controls: payload.data.daylighting_controls, | ||
}, | ||
}, | ||
geometry, | ||
}); | ||
|
||
document.getElementById('svg-grid').dispatchEvent(new Event('reloadGrid')); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.