@buerli.io/core 0.2.0 → 0.3.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,11 @@
1
+ import { GraphicType as GT } from '../types/IGraphicPackage';
2
+ export declare const lineFilter: (scope: string, data: GT) => boolean;
3
+ export declare const lineSegmentsFilter: (scope: string, data: GT) => boolean;
4
+ export declare const arcFilter: (scope: string, data: GT) => boolean;
5
+ export declare const circleFilter: (scope: string, data: GT) => boolean;
6
+ export declare const arcCircleFilter: (scope: string, data: GT) => boolean;
7
+ export declare const pointFilter: (scope: string, data: GT) => boolean;
8
+ export declare const meshFilter: (scope: string, data: GT) => boolean;
9
+ export declare const planeFilter: (scope: string, data: GT) => boolean;
10
+ export declare const loopFilter: (scope: string, data: GT) => boolean;
11
+ export declare const solidFilter: (scope: string, data: GT) => boolean;
@@ -0,0 +1,12 @@
1
+ import { GraphicType as GT, LineSegments, Surfaces } from '../types/IGraphicPackage';
2
+ import { BuerliScope } from '../store/states/selection';
3
+ export const lineFilter = (scope, data) => scope === BuerliScope && (data === GT.LINE || data === GT.EDGE);
4
+ export const lineSegmentsFilter = (scope, data) => scope === BuerliScope && LineSegments.includes(data);
5
+ export const arcFilter = (scope, data) => scope === BuerliScope && data === GT.ARC;
6
+ export const circleFilter = (scope, data) => scope === BuerliScope && data === GT.CIRCLE;
7
+ export const arcCircleFilter = (scope, data) => scope === BuerliScope && (data === GT.ARC || data === GT.CIRCLE);
8
+ export const pointFilter = (scope, data) => scope === BuerliScope && data === GT.POINT;
9
+ export const meshFilter = (scope, data) => scope === BuerliScope && Surfaces.includes(data);
10
+ export const planeFilter = (scope, data) => scope === BuerliScope && data === GT.PLANE;
11
+ export const loopFilter = (scope, data) => scope === BuerliScope && data === GT.LOOP;
12
+ export const solidFilter = (scope, data) => scope === BuerliScope && data === GT.BREP;
package/build/index.d.ts CHANGED
@@ -5,6 +5,7 @@ export * from './utils/Math';
5
5
  export * from './utils/Measure';
6
6
  export * from './utils/Timing';
7
7
  export * from './store/subscribtion/subscribeToDrawing';
8
+ export * from './graphic/filters';
8
9
  /**
9
10
  * Because babel typescript tools can not handle the type definitions
10
11
  * in an other way, they have to be re-exported as you can see in this code region.
package/build/index.js CHANGED
@@ -5,4 +5,5 @@ export * from './utils/Math';
5
5
  export * from './utils/Measure';
6
6
  export * from './utils/Timing';
7
7
  export * from './store/subscribtion/subscribeToDrawing';
8
+ export * from './graphic/filters';
8
9
  //#endregion Re-export type definitions
@@ -40,10 +40,10 @@ declare const generalApi: (set: SetState<BuerliState>, get: GetState<BuerliState
40
40
  *
41
41
  * @param options - options which will be set into state.options
42
42
  */
43
- init(options?: Partial<BuerliOptions> | undefined): void;
43
+ init(options?: Partial<BuerliOptions>): void;
44
44
  };
45
45
  declare const drawingManagementApi: (set: SetState<BuerliState>, get: GetState<BuerliState>, buerliApi: BuerliStoreApi) => {
46
- createDrawing(name?: string | undefined): Promise<DrawingState>;
46
+ createDrawing(name?: string): Promise<DrawingState>;
47
47
  removeDrawing(id: DrawingID): void;
48
48
  setActiveDrawing(id: DrawingID | null): void;
49
49
  };
@@ -33,7 +33,7 @@ export declare const cadApi: (set: SetState<DrawingState>, get: GetState<Drawing
33
33
  }>) => void;
34
34
  addPending: (name: string, options?: {
35
35
  args?: any;
36
- } | undefined) => string;
36
+ }) => string;
37
37
  removePending: (id: string) => void;
38
38
  setConnected: (connected: boolean) => void;
39
39
  };
@@ -13,6 +13,7 @@ import { CadApi, CadData } from './cad';
13
13
  import { CanvasApi, CanvasData } from './canvas';
14
14
  import { GeometryApi, GeometryData } from './geometry';
15
15
  import { GraphicApi, GraphicData } from './graphic';
16
+ import { InteractionApi, InteractionData } from './interaction';
16
17
  import { PluginApi, PluginData } from './plugin';
17
18
  import { SelectionApi, SelectionData } from './selection';
18
19
  import { StructureApi, StructureData } from './structure';
@@ -20,6 +21,7 @@ export declare type DrawingID = string | number;
20
21
  export declare type DrawingAPI = {
21
22
  structure: StructureApi;
22
23
  selection: SelectionApi;
24
+ interaction: InteractionApi;
23
25
  plugin: PluginApi;
24
26
  geometry: GeometryApi;
25
27
  graphic: GraphicApi;
@@ -34,6 +36,7 @@ declare type StateData = {
34
36
  graphic: GraphicData;
35
37
  canvas: CanvasData;
36
38
  selection: SelectionData;
39
+ interaction: InteractionData;
37
40
  plugin: PluginData;
38
41
  cad: CadData;
39
42
  };
@@ -12,6 +12,7 @@ import { cadApi, cadData } from './cad';
12
12
  import { canvasApi, canvasData } from './canvas';
13
13
  import { geometryApi, geometryData } from './geometry';
14
14
  import { graphicApi, graphicData } from './graphic';
15
+ import { interactionApi, interactionData } from './interaction';
15
16
  import { pluginApi, pluginData } from './plugin';
16
17
  import { selectionApi, selectionData } from './selection';
17
18
  import { structureApi, structureData } from './structure';
@@ -23,6 +24,7 @@ export const createDrawingState = (set, get, buerliApi, drawingNumber, name) =>
23
24
  return {
24
25
  structure: structureData(),
25
26
  selection: selectionData(),
27
+ interaction: interactionData(),
26
28
  plugin: pluginData(),
27
29
  geometry: geometryData(),
28
30
  graphic: graphicData(),
@@ -36,6 +38,7 @@ export const createDrawingState = (set, get, buerliApi, drawingNumber, name) =>
36
38
  graphic: graphicApi(set, get, buerliApi),
37
39
  canvas: canvasApi(set, get, buerliApi),
38
40
  cad: cadApi(set, get, buerliApi),
41
+ interaction: interactionApi(set, get, buerliApi),
39
42
  },
40
43
  id: drawingId,
41
44
  name: name || `Drawing #${drawingNumber}`,
@@ -41,14 +41,14 @@ export declare const geometryApi: (set: SetState<DrawingState>, get: GetState<Dr
41
41
  * The update will only happen, if at least one solid of one product is available.
42
42
  */
43
43
  updateBounds: () => void;
44
- createGeometryIfNotCached: (containerId: number, color?: number[] | undefined) => ContainerGeometryT | undefined;
44
+ createGeometryIfNotCached: (containerId: number, color?: number[]) => ContainerGeometryT | undefined;
45
45
  setColor: (containerId: GraphicID, r: number, g: number, b: number) => void;
46
46
  setOpacity: (containerId: GraphicID, opacity: number) => void;
47
47
  setConfig: (objId: ObjectID | GraphicID, config: Partial<GeometryConfig> | null) => void;
48
48
  findDecorated: () => GeometryElement[];
49
49
  filter: (cb: (elem: GeometryElement) => boolean, options?: {
50
- onlyOne?: boolean | undefined;
51
- containerId?: number | undefined;
52
- } | undefined) => GeometryElement[];
50
+ onlyOne?: boolean;
51
+ containerId?: ObjectID;
52
+ }) => GeometryElement[];
53
53
  };
54
54
  export {};
@@ -12,9 +12,9 @@ export declare const graphicApi: (set: SetState<DrawingState>, get: GetState<Dra
12
12
  addPackages: (packages: IGraphicPackage[]) => void;
13
13
  cleanupGraphicRecords: () => void;
14
14
  filter: (cb: (elem: IGraphicElement) => boolean, options?: {
15
- onlyOne?: boolean | undefined;
16
- containerId?: number | undefined;
17
- } | undefined) => {
15
+ onlyOne?: boolean;
16
+ containerId?: ObjectID;
17
+ }) => {
18
18
  elem: IGraphicElement;
19
19
  containerId: ObjectID;
20
20
  solidId: ObjectID;
@@ -0,0 +1,34 @@
1
+ import { GetState, SetState } from 'zustand';
2
+ import { BuerliStoreApi } from '../../store/store';
3
+ import { InteractionInfo } from '../../types';
4
+ import { DrawingState } from './drawing';
5
+ export declare type InteractionData = {
6
+ hovered?: InteractionInfo | null;
7
+ selected?: InteractionInfo[];
8
+ };
9
+ export declare type InteractionApi = ReturnType<typeof interactionApi>;
10
+ export declare const interactionData: () => InteractionData;
11
+ export declare const interactionApi: (set: SetState<DrawingState>, get: GetState<DrawingState>, buerliApi: BuerliStoreApi) => {
12
+ /**
13
+ * Sets the hovered item in the store to the given item.
14
+ *
15
+ * @param item The item.
16
+ */
17
+ setHovered: (item: InteractionInfo | null) => void;
18
+ /**
19
+ * Reset the 'selected' array to the given items.
20
+ *
21
+ * @param items The items.
22
+ */
23
+ setSelected: (items: InteractionInfo[]) => void;
24
+ /**
25
+ * Adds the given item to the 'selected' array if it is not yet selected.
26
+ * If the item is already selected, it will be removed from the 'selected' array.
27
+ *
28
+ * With 'multi' enabled, the already selected items will remain selected.
29
+ *
30
+ * @param item The item to select.
31
+ * @param multi Do multi select.
32
+ */
33
+ select: (item: InteractionInfo, multi?: boolean) => void;
34
+ };
@@ -0,0 +1,50 @@
1
+ ////////////////////////////////////////////////////
2
+ // DATA
3
+ ////////////////////////////////////////////////////
4
+ export const interactionData = () => ({
5
+ hovered: null,
6
+ selected: [],
7
+ });
8
+ ////////////////////////////////////////////////////
9
+ // API
10
+ ////////////////////////////////////////////////////
11
+ export const interactionApi = (set, get, buerliApi) => ({
12
+ /**
13
+ * Sets the hovered item in the store to the given item.
14
+ *
15
+ * @param item The item.
16
+ */
17
+ setHovered: (item) => {
18
+ set(state => (Object.assign(Object.assign({}, state), { interaction: Object.assign(Object.assign({}, state.interaction), { hovered: item }) })));
19
+ },
20
+ /**
21
+ * Reset the 'selected' array to the given items.
22
+ *
23
+ * @param items The items.
24
+ */
25
+ setSelected: (items) => {
26
+ set(state => (Object.assign(Object.assign({}, state), { interaction: Object.assign(Object.assign({}, state.interaction), { selected: items }) })));
27
+ },
28
+ /**
29
+ * Adds the given item to the 'selected' array if it is not yet selected.
30
+ * If the item is already selected, it will be removed from the 'selected' array.
31
+ *
32
+ * With 'multi' enabled, the already selected items will remain selected.
33
+ *
34
+ * @param item The item to select.
35
+ * @param multi Do multi select.
36
+ */
37
+ select: (item, multi) => {
38
+ const setSelected = get().api.interaction.setSelected;
39
+ const selected = get().interaction.selected || [];
40
+ const newKey = item.uniqueIdent;
41
+ let newSel = selected.length === 1 && selected[0].uniqueIdent === newKey ? [] : [item];
42
+ if (multi) {
43
+ newSel = selected.filter(s => s.uniqueIdent != newKey);
44
+ if (newSel.length === selected.length) {
45
+ newSel.push(item);
46
+ }
47
+ }
48
+ setSelected(newSel);
49
+ },
50
+ });
@@ -47,7 +47,7 @@ export declare const pluginApi: (set: SetState<DrawingState>, get: GetState<Draw
47
47
  setActiveFeature: (id: ObjectID | null) => void;
48
48
  setVisiblePlugin: (id: PluginID, visible: boolean) => void;
49
49
  setActiveGlobal: (id: PluginID, active: boolean) => void;
50
- createPlugin: (def: PluginDef, defaultId?: string | number | undefined, drawingId?: DrawingID | undefined, objectId?: number | undefined) => (deactivate?: boolean) => void;
50
+ createPlugin: (def: PluginDef, defaultId?: ObjectID | string, drawingId?: DrawingID, objectId?: ObjectID) => (deactivate?: boolean) => void;
51
51
  };
52
52
  export declare function isPromisePlugin(def: PluginDef): def is Promise<Plugin>;
53
53
  export {};
@@ -15,7 +15,7 @@ export declare type SelectedItem<T extends SeletedItemData<any> = any> = {
15
15
  readonly label?: any;
16
16
  readonly removeCondition?: (d: DrawingState) => boolean;
17
17
  };
18
- export declare type SelectionFilter = (scope: SelectionScope, data: any) => boolean;
18
+ export declare type SelectionFilter<T = any> = (scope: SelectionScope, data: T) => boolean;
19
19
  export declare type CustomSelect = (selectorId: SelectorID, newItems: SelectedItem[], diff: SelectedItem[]) => void;
20
20
  /**
21
21
  * Type for selector.
@@ -41,22 +41,22 @@ export declare type SelectionData = {
41
41
  export declare type SelectionApi = ReturnType<typeof selectionApi>;
42
42
  export declare const selectionData: () => SelectionData;
43
43
  export declare const selectionApi: (set: SetState<DrawingState>, get: GetState<DrawingState>, buerliApi: BuerliStoreApi) => {
44
- unselectAll(selectorId?: SelectorID | undefined): void;
45
- unselect(items: SelectedItem | SelectedItem[], selectorId?: SelectorID | undefined): void;
46
- select(items: SelectedItem | SelectedItem[], selectorId?: SelectorID | undefined): void;
47
- setHovered(item: SelectedItem | null, selectorId?: SelectorID | undefined): void;
44
+ unselectAll(selectorId?: SelectorID): void;
45
+ unselect(items: SelectedItem | SelectedItem[], selectorId?: SelectorID): void;
46
+ select(items: SelectedItem | SelectedItem[], selectorId?: SelectorID): void;
47
+ setHovered(item: SelectedItem | null, selectorId?: SelectorID): void;
48
48
  activateSelector(selectorId: SelectorID | null): void;
49
- createSelector(selectorId: SelectorID, filter: SelectionFilter, activate?: boolean, initialItems?: SelectedItem[], maxLen?: number, customSelect?: CustomSelect | undefined, customUnSelect?: CustomSelect | undefined): () => void;
50
- areItemsSelected: (items: SelectedItem[], selectorId?: SelectorID | undefined) => boolean;
51
- isItemSelected: (item: SelectedItem, selectorId?: SelectorID | undefined) => boolean;
49
+ createSelector(selectorId: SelectorID, filter: SelectionFilter, activate?: boolean, initialItems?: SelectedItem[], maxLen?: number, customSelect?: CustomSelect, customUnSelect?: CustomSelect): () => void;
50
+ areItemsSelected: (items: SelectedItem[], selectorId?: SelectorID) => boolean;
51
+ isItemSelected: (item: SelectedItem, selectorId?: SelectorID) => boolean;
52
52
  setItems(id: SelectorID, items: SelectedItem[]): void;
53
53
  selectGraphic: (selectorId: SelectorID, items: {
54
54
  productId: ObjectID;
55
55
  containerId: GraphicID;
56
56
  graphicId?: GraphicID;
57
57
  }[], options?: {
58
- unselectExisting?: boolean | undefined;
59
- } | undefined) => void;
60
- getGraphicItem: (productId: ObjectID, containerId: GraphicID, graphicId?: number | undefined) => SelectedItem<ProductElement> | null;
58
+ unselectExisting?: boolean;
59
+ }) => void;
60
+ getGraphicItem: (productId: ObjectID, containerId: GraphicID, graphicId?: GraphicID) => SelectedItem<ProductElement> | null;
61
61
  };
62
62
  export declare const createGraphicItem: (productId: ObjectID, el: GeometryElement) => SelectedItem<ProductElement>;
@@ -29,7 +29,7 @@ export declare const structureApi: (set: SetState<DrawingState>, get: GetState<D
29
29
  calculateProductBounds: (productId: ObjectID, base?: {
30
30
  min: THREE.Vector3;
31
31
  max: THREE.Vector3;
32
- } | undefined) => {
32
+ }) => {
33
33
  center: THREE.Vector3;
34
34
  radius: number;
35
35
  max: THREE.Vector3;
@@ -0,0 +1,43 @@
1
+ import { GraphicID } from './IGraphicPackage';
2
+ import { ObjectID } from './IStructureTree';
3
+ /**
4
+ * It contains general information that can be used to identify CCObjects as well as Brep Elements.
5
+ */
6
+ export declare type InteractionInfo<T = any> = {
7
+ /**
8
+ * Unique identifier of the interaction info.
9
+ */
10
+ uniqueIdent: string;
11
+ /**
12
+ * Identifies the object of the Part (for BaseModeling).
13
+ * Needed to identify the location ot the object in the tree.
14
+ */
15
+ objectId: ObjectID;
16
+ /**
17
+ * Identifies the node of the Assembly (for BaseModeling).
18
+ * Needed to identify the location ot the object in the tree.
19
+ */
20
+ prodRefId?: ObjectID | null;
21
+ /**
22
+ * Indentifies an object in the tree by it's full path, starting at AllObjects.
23
+ * It is optional, but should be filled if possible. It can be used to get the full,
24
+ * proper transformation of the identified object.
25
+ */
26
+ objectPath?: ObjectID[];
27
+ /**
28
+ * Identifies the cad entity of the graphic/geometry cache.
29
+ * Optional but needed for graphic/geometry element identification.
30
+ */
31
+ containerId?: ObjectID;
32
+ /**
33
+ * Identifies a single graphic/geometry element of a cad entity.
34
+ * Optional but needed for graphic/geometry element identification.
35
+ */
36
+ graphicId?: GraphicID;
37
+ /**
38
+ * Arbitrary object that contains user specific information.
39
+ */
40
+ userData?: T;
41
+ };
42
+ export declare const createInfo: (data: Omit<InteractionInfo, 'uniqueIdent'>) => InteractionInfo;
43
+ export declare const createUniqueIdent: (data: Omit<InteractionInfo, 'uniqueIdent'>) => string;
@@ -0,0 +1,6 @@
1
+ export const createInfo = (data) => {
2
+ return Object.assign({ uniqueIdent: createUniqueIdent(data) }, data);
3
+ };
4
+ export const createUniqueIdent = (data) => {
5
+ return `${[data.prodRefId, data.objectId, data.containerId, data.graphicId]}`;
6
+ };
@@ -1,4 +1,5 @@
1
1
  export * from './ErrorTypes';
2
2
  export * from './IGraphicPackage';
3
+ export * from './InteractionInfo';
3
4
  export * from './IStructurePatch';
4
5
  export * from './IStructureTree';
@@ -1,4 +1,5 @@
1
1
  export * from './ErrorTypes';
2
2
  export * from './IGraphicPackage';
3
+ export * from './InteractionInfo';
3
4
  export * from './IStructurePatch';
4
5
  export * from './IStructureTree';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@buerli.io/core",
3
- "version": "0.2.0",
3
+ "version": "0.3.0-beta.0",
4
4
  "description": "buerli state management",
5
5
  "author": "AWV Informatik AG <info@awv-informatik.ch>",
6
6
  "license": "ISC",