Merged PR 311: #7975 Cotations sur les ancrages

![image.png](e30b9bba-4b18-4276-b4ef-74d97b7daef3/pullRequests/311/attachments/image.png)

Related work items: #7975
This commit is contained in:
Carl Fuchs 2023-02-07 10:16:19 +00:00 committed by Eric Nguyen
parent 532151b939
commit acb5ba2d82
7 changed files with 251 additions and 182 deletions

View file

@ -12,9 +12,11 @@ import {
import { FindContainerById, MakeRecursionDFSIterator, Pairwise } from '../../../utils/itertools';
import { TransformX, TransformY } from '../../../utils/svg';
import { Dimension } from './Dimension';
import { ISymbolModel } from '../../../Interfaces/ISymbolModel';
interface IDimensionLayerProps {
containers: Map<string, IContainerModel>
symbols: Map<string, ISymbolModel>
root: IContainerModel
scale: number
}
@ -35,7 +37,8 @@ function ActionByPosition(
horizontalAction: (dim: number, ...params: any[]) => void,
verticalAction: (dim: number, isRight: boolean, ...params: any[]) => void,
params: any[]
): void {
): boolean {
let incrementDepthSymbols = false;
positions.forEach((position: Position) => {
const dim = dimMapped[position];
switch (position) {
@ -47,10 +50,12 @@ function ActionByPosition(
}
case Position.Down:
case Position.Up:
incrementDepthSymbols = true;
horizontalAction(dim, ...params);
break;
}
});
return incrementDepthSymbols;
}
/**
@ -58,7 +63,7 @@ function ActionByPosition(
* @param param0 Object with the root container and the scale of the svg
* @returns A list of dimensions
*/
function Dimensions({ containers, root, scale }: IDimensionLayerProps): React.ReactNode[] {
function Dimensions({ containers, symbols, root, scale }: IDimensionLayerProps): React.ReactNode[] {
const it = MakeRecursionDFSIterator(root, containers, 0, [0, 0]);
const dimensions: React.ReactNode[] = [];
const topDim = root.properties.y;
@ -69,6 +74,7 @@ function Dimensions({ containers, root, scale }: IDimensionLayerProps): React.Re
if (!SHOW_SELF_DIMENSIONS) {
return [];
}
let startDepthSymbols: number = 0;
for (const { container, depth, currentTransform } of it) {
const offset = (DIMENSION_MARGIN * (depth + 1)) / scale;
@ -78,7 +84,7 @@ function Dimensions({ containers, root, scale }: IDimensionLayerProps): React.Re
const containerRightDim = rightDim + offset;
const dimMapped = [containerLeftDim, containerBottomDim, containerTopDim, containerRightDim];
if (SHOW_SELF_DIMENSIONS && container.properties.dimensionOptions.selfDimensions.positions.length > 0) {
ActionByPosition(
const incrementDepthSymbol = ActionByPosition(
dimMapped,
container.properties.dimensionOptions.selfDimensions.positions,
AddHorizontalSelfDimension,
@ -90,10 +96,11 @@ function Dimensions({ containers, root, scale }: IDimensionLayerProps): React.Re
scale,
container.properties.dimensionOptions.selfDimensions.color]
);
if (incrementDepthSymbol) { startDepthSymbols++; }
}
if (SHOW_SELF_MARGINS_DIMENSIONS && container.properties.dimensionOptions.selfMarginsDimensions.positions.length > 0) {
ActionByPosition(
const incrementDepthSymbol = ActionByPosition(
dimMapped,
container.properties.dimensionOptions.selfMarginsDimensions.positions,
AddHorizontalSelfMarginsDimension,
@ -105,12 +112,14 @@ function Dimensions({ containers, root, scale }: IDimensionLayerProps): React.Re
scale,
container.properties.dimensionOptions.selfMarginsDimensions.color]
);
if (incrementDepthSymbol) { startDepthSymbols++; }
}
if (SHOW_BORROWER_DIMENSIONS && container.properties.dimensionOptions.dimensionWithMarks.positions.length > 0) {
ActionByPosition(
const incrementDepthSymbol = ActionByPosition(
dimMapped,
container.properties.dimensionOptions.dimensionWithMarks.positions,
AddHorizontalBorrowerDimension,
AddVerticalBorrowerDimension,
[
@ -122,10 +131,11 @@ function Dimensions({ containers, root, scale }: IDimensionLayerProps): React.Re
scale,
container.properties.dimensionOptions.dimensionWithMarks.color]
);
if (incrementDepthSymbol) { startDepthSymbols++; }
}
if (SHOW_CHILDREN_DIMENSIONS && container.properties.dimensionOptions.childrenDimensions.positions.length > 0 && container.children.length >= 2) {
ActionByPosition(
const incrementDepthSymbol = ActionByPosition(
dimMapped,
container.properties.dimensionOptions.childrenDimensions.positions,
AddHorizontalChildrenDimension,
@ -138,12 +148,50 @@ function Dimensions({ containers, root, scale }: IDimensionLayerProps): React.Re
scale,
container.properties.dimensionOptions.childrenDimensions.color]
);
if (incrementDepthSymbol) { startDepthSymbols++; }
}
}
for (const symbol of symbols) {
if (symbol[1].showDimension) {
startDepthSymbols++;
AddHorizontalSymbolDimension(symbol[1], dimensions, scale, 'black', startDepthSymbols);
}
}
return dimensions;
}
function AddHorizontalSymbolDimension(symbol: ISymbolModel,
dimensions: React.ReactNode[],
scale: number,
color: string,
depth: number
): void {
const width = symbol.x + (symbol.width / 2);
if (width != null && width > 0) {
const id = `dim-y-margin-left${symbol.width.toFixed(0)}-${symbol.id}`;
const offset = (DIMENSION_MARGIN * (depth + 1)) / scale;
const text = width
.toFixed(0)
.toString();
dimensions.push(
<Dimension
key={id}
id={id}
xStart={0}
yStart={-offset}
xEnd={width}
yEnd={-offset}
text={text}
scale={scale}
color={color}/>
);
}
}
/**
* A layer containing all dimension
* @param props
@ -152,7 +200,7 @@ function Dimensions({ containers, root, scale }: IDimensionLayerProps): React.Re
export function DimensionLayer(props: IDimensionLayerProps): JSX.Element {
return (
<g>
{ Dimensions(props) }
{Dimensions(props)}
</g>
);
}
@ -230,7 +278,6 @@ function AddVerticalChildrenDimension(
dimensions: React.ReactNode[],
scale: number,
color: string
): void {
const childrenId = `dim-x${xDim.toFixed(0)}-children-${container.properties.id}`;
@ -451,7 +498,6 @@ function AddVerticalSelfDimension(
}
function AddHorizontalSelfDimension(
yDim: number,
container: IContainerModel,
currentTransform: [number, number],
@ -481,7 +527,6 @@ function AddHorizontalSelfDimension(
}
function AddHorizontalSelfMarginsDimension(
yDim: number,
container: IContainerModel,
currentTransform: [number, number],