mirror of
https://github.com/xibyte/jsketcher
synced 2025-12-16 05:23:19 +01:00
custom selection filters
This commit is contained in:
parent
835c5f7157
commit
66b9f6c56a
5 changed files with 32 additions and 20 deletions
|
|
@ -1,3 +1,5 @@
|
|||
import {entityKindCapture} from "cad/craft/schema/types/entityType";
|
||||
|
||||
export default {
|
||||
orientation: {
|
||||
type: 'string',
|
||||
|
|
@ -6,7 +8,7 @@ export default {
|
|||
},
|
||||
datum: {
|
||||
type: 'entity',
|
||||
allowedKinds: ['face', 'datum'],
|
||||
allowedKinds: entityKindCapture('face', 'datum'),
|
||||
optional: true,
|
||||
defaultValue: {
|
||||
usePreselection: true,
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ export default function initializeBySchema(schema: OperationSchema, context: Cor
|
|||
if (defaultValue.usePreselection === true) {
|
||||
const entitySchema = md.items;
|
||||
const currentSelection =
|
||||
context.entityContextService.selectedEntities.value.filter(e => entitySchema.allowedKinds.includes(e.TYPE));
|
||||
context.entityContextService.selectedEntities.value.filter(entitySchema.entityCapture);
|
||||
val = currentSelection.map(e => e.id);
|
||||
}
|
||||
} else {
|
||||
|
|
@ -23,11 +23,9 @@ export default function initializeBySchema(schema: OperationSchema, context: Cor
|
|||
}
|
||||
} else if (md.type === Types.entity && md.defaultValue !== undefined) {
|
||||
const defaultValue = md.defaultValue;
|
||||
console.log(defaultValue)
|
||||
if (defaultValue.usePreselection === true && defaultValue.preselectionIndex !== undefined) {
|
||||
const allowedKinds = md.allowedKinds;
|
||||
const currentSelection =
|
||||
context.entityContextService.selectedEntities.value.filter(e => allowedKinds.includes(e.TYPE));
|
||||
context.entityContextService.selectedEntities.value.filter(md.entityCapture);
|
||||
|
||||
let mObject = currentSelection[defaultValue.preselectionIndex as number];
|
||||
if (mObject) {
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ export interface EntityTypeSchema extends BaseSchemaField {
|
|||
|
||||
type: Types.entity,
|
||||
|
||||
allowedKinds: EntityKind[];
|
||||
entityCapture: EntityCapture,
|
||||
|
||||
defaultValue?: {
|
||||
usePreselection: boolean;
|
||||
|
|
@ -16,6 +16,8 @@ export interface EntityTypeSchema extends BaseSchemaField {
|
|||
}
|
||||
}
|
||||
|
||||
export type EntityCapture = (entity: MObject) => boolean;
|
||||
|
||||
export const EntityType: Type<string, MObject, EntityTypeSchema> = {
|
||||
|
||||
resolve(ctx: CoreContext,
|
||||
|
|
@ -38,3 +40,10 @@ export const EntityType: Type<string, MObject, EntityTypeSchema> = {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
export function entityKindCapture(...allowedKinds: EntityKind[]) {
|
||||
|
||||
return e => allowedKinds.includes(e.TYPE);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import {MarkerPluginContext} from "cad/scene/selectionMarker/markerPlugin";
|
|||
import {WizardPluginContext} from "cad/craft/wizard/wizardPlugin";
|
||||
import {PickControlPluginContext} from "cad/scene/controls/pickControlPlugin";
|
||||
import _ from "lodash";
|
||||
import {MObject} from "cad/model/mobject";
|
||||
|
||||
export type WizardSelectionPluginInputContext = MarkerPluginContext & WizardPluginContext & PickControlPluginContext;
|
||||
|
||||
|
|
@ -94,13 +95,13 @@ function createPickHandlerFromSchema(wizardService: WizardService) {
|
|||
}
|
||||
|
||||
|
||||
function activeCanTakeIt(kind) {
|
||||
function activeCanTakeIt(model: MObject) {
|
||||
let activeRef: EntityReference = activeEntityRef();
|
||||
if (!activeRef) {
|
||||
return false;
|
||||
}
|
||||
const activeMd = activeRef?.metadata;
|
||||
return activeMd && activeMd.allowedKinds.includes(kind);
|
||||
return activeMd && activeMd.entityCapture(model);
|
||||
}
|
||||
|
||||
function select(entityRef: EntityReference, id: string) {
|
||||
|
|
@ -129,10 +130,10 @@ function createPickHandlerFromSchema(wizardService: WizardService) {
|
|||
select(activeEntityRef(), id);
|
||||
}
|
||||
|
||||
function selectToFirst(entity, id) {
|
||||
function selectToFirst(entity) {
|
||||
for (let eRef of schemaIndex.entities) {
|
||||
if (eRef.metadata.allowedKinds.includes(entity)) {
|
||||
select(eRef, id);
|
||||
if (eRef.metadata.entityCapture(entity)) {
|
||||
select(eRef, entity.id);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -175,20 +176,20 @@ function createPickHandlerFromSchema(wizardService: WizardService) {
|
|||
}
|
||||
|
||||
if (modelType === FACE) {
|
||||
if (activeCanTakeIt(SHELL)) {
|
||||
if (activeCanTakeIt(model.shell)) {
|
||||
selectActive(model.shell.id);
|
||||
} else if (activeCanTakeIt(FACE)) {
|
||||
} else if (activeCanTakeIt(model)) {
|
||||
selectActive(model.id);
|
||||
} else {
|
||||
if (!selectToFirst(FACE, model.id)) {
|
||||
selectToFirst(SHELL, model.shell.id)
|
||||
}
|
||||
// if (!selectToFirst(model)) {
|
||||
// selectToFirst(model.shell)
|
||||
// }
|
||||
}
|
||||
} else{
|
||||
if (activeCanTakeIt(modelType)) {
|
||||
if (activeCanTakeIt(model)) {
|
||||
selectActive(model.id);
|
||||
} else {
|
||||
selectToFirst(modelType, model.id);
|
||||
// selectToFirst(model);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@ import {FieldBasicProps, fieldToSchemaGeneric} from "cad/mdf/ui/field";
|
|||
import {EntityKind} from "cad/model/entities";
|
||||
import {ArrayTypeSchema} from "cad/craft/schema/types/arrayType";
|
||||
import {Types} from "cad/craft/schema/types";
|
||||
import {MObject} from "cad/model/mobject";
|
||||
import {EntityCapture, entityKindCapture} from "cad/craft/schema/types/entityType";
|
||||
|
||||
|
||||
export interface SelectionWidgetProps extends FieldBasicProps {
|
||||
|
|
@ -14,7 +16,7 @@ export interface SelectionWidgetProps extends FieldBasicProps {
|
|||
|
||||
multi?: boolean;
|
||||
|
||||
capture: EntityKind[];
|
||||
capture: EntityKind[] | EntityCapture;
|
||||
|
||||
min?: number;
|
||||
|
||||
|
|
@ -29,7 +31,7 @@ SelectionWidget.propsToSchema = (props: SelectionWidgetProps) => {
|
|||
|
||||
let value = {
|
||||
type: Types.entity,
|
||||
allowedKinds: props.capture,
|
||||
entityCapture: Array.isArray(props.capture) ? entityKindCapture(...props.capture) : props.capture,
|
||||
} as SchemaField;
|
||||
|
||||
if (props.multi) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue