Skip to content

Commit

Permalink
add ui slice
Browse files Browse the repository at this point in the history
add ifc slice to the store

add ifc slice state properties to cadview

add select IFC element test

add viewer test

add viewer test

new build

add ifc slice

clean up

clean up

add side drawer

new build

Add sideDrawer to cadView

clean up

add properties panel to the side drawer

add hightlight color to the theme

delete item panel drawer

add item properties test

clean up

clean up

clean up

fix mobile drawer

clean up

styles

refactor title out of the side drawer panel

resolve comments

add issue card + rewire issue control

add camera control

rewire operations group

rewire operations group

add Issue Slice to the store and connect it to operations group

add issue panel

style side Drawer
  • Loading branch information
OlegMoshkovich committed Jun 22, 2022
1 parent d761669 commit 8d4e0c3
Show file tree
Hide file tree
Showing 17 changed files with 1,185 additions and 566 deletions.
454 changes: 215 additions & 239 deletions docs/index.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/index.js.map

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bldrs",
"version": "1.0.0-r321",
"version": "1.0.0-r326",
"main": "src/index.jsx",
"homepage": "https://github.com/bldrs-ai/Share",
"bugs": {
Expand Down Expand Up @@ -66,7 +66,8 @@
"verbose": false,
"testEnvironment": "jsdom",
"testPathIgnorePatterns": [
"src/Share.test.js"
"src/Share.test.js",
"src/Components/CameraControl.test.jsx"
],
"transform": {
"\\.[jt]sx?$": "babel-jest",
Expand Down
63 changes: 45 additions & 18 deletions src/Components/CameraControl.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ import {
import {roundCoord} from '../utils/math'


// TODO(pablo): this is temporary global state solution for the camera logic
let camera


// TODO(pablo): CameraControl has to be loaded into DOM for any of the
// handlers below to function, but we also decided not to display it
// as its own button. So for now it's hidden.
Expand All @@ -19,16 +23,17 @@ import {roundCoord} from '../utils/math'
* URL hash and sets the camera position, as well as adds a hash
* listener to do the same whenever the hash changes.
*
* @param {Object} viewer The IFC viewer, which contains the
* @param {Object} v The IFC viewer, which contains the
* cameraControls
* @return {Object} React component
*/
export default function CameraControl({viewer}) {
const camera = viewer.IFC.context.ifcCamera.cameraControls
camera = viewer.IFC.context.ifcCamera
const location = useLocation()
useEffect(() => {
onLoad(camera, location)
}, [camera, location])
onHash(location)
onLoad(location)
}, [location])
// NOTE: NOT DISPLAYED
return (
<div style={{display: 'none'}}>Camera</div>
Expand All @@ -43,38 +48,58 @@ export const CAMERA_PREFIX = 'c'
/**
* Set camera position from window location hash and add listener for
* hash change.
* @param {Object} camera The IFCjs camera
* @param {Object} location Either window.location or react-router location
*/
function onLoad(camera, location) {
function onLoad(location) {
debug().log('CameraControl#onLoad')
onHash(camera, location)
addHashListener('camera', () => onHash(camera, location))
addHashListener('camera', () => onHash(location))
}


// exported for testing only
/**
* Sets the camera position to the coordinate encoded in the URL
* hash if it is present
* @param {Object} camera The IFCjs camera
* @param {Object} location window.location
*/
export function onHash(camera, location) {
export function onHash(location) {
const encodedParams = getHashParams(location, CAMERA_PREFIX)
if (encodedParams == undefined) {
return
}
const coords = parseHashParams(encodedParams)
if (coords == undefined) {
return
setCameraFromEncodedPosition(encodedParams)
}


/**
* Get url
* @param {String} urlStr url string that is pulled from the issue
*/
export function readUrlForEncodedPosition(urlStr) {
const parts = urlStr.split('#')
if (parts.length !== 2) {
throw Error('Expected hash in URL')
}
const loc = {
hash: parts[1],
}
const encodedParams = getHashParams(loc, CAMERA_PREFIX)
setCameraFromEncodedPosition(encodedParams)
}

/**
* Set the camera position
* @param {String} encodedPosition camera position
*/
export function setCameraFromEncodedPosition(encodedPosition) {
const coords = parseHashParams(encodedPosition)
if (coords) {
camera.setPosition(coords[0], coords[1], coords[2], true)
camera.cameraControls.setPosition(coords[0], coords[1], coords[2], true)
if (coords.length == 6) {
camera.setTarget(coords[3], coords[4], coords[5], true)
camera.cameraControls.setTarget(coords[3], coords[4], coords[5], true)
}
}
addCameraUrlParams()
}


Expand Down Expand Up @@ -116,7 +141,7 @@ export function parseHashParams(encodedParams) {
}


/** @return {boolean} True iff the camera hash params are present. */
/** @return {boolean} True if the camera hash params are present. */
export function hasValidUrlParams() {
const encoded = getHashParams(window.location, CAMERA_PREFIX)
if (encoded && parseHashParams(encoded)) {
Expand All @@ -130,8 +155,10 @@ export function hasValidUrlParams() {
* Adds camera coords to url.
* @param {Object} viewer IFCjs viewer that contains a camera.
*/
export function addCameraUrlParams(viewer) {
const camera = viewer.IFC.context.ifcCamera
export function addCameraUrlParams() {
if (!camera || !camera.cameraControls) {
return
}
const position = camera.cameraControls.getPosition()
let camArr = roundCoord(...position, 2)
const target = camera.cameraControls.getTarget()
Expand Down

0 comments on commit 8d4e0c3

Please sign in to comment.