Merged PR 311: #7975 Cotations sur les ancrages

Related work items: #7975
This commit is contained in:
parent
532151b939
commit
acb5ba2d82
7 changed files with 251 additions and 182 deletions
|
@ -1,4 +1,4 @@
|
|||
using System.Runtime.Serialization;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace SVGLDLibs.Models
|
||||
|
@ -26,5 +26,8 @@ namespace SVGLDLibs.Models
|
|||
|
||||
[DataMember(EmitDefaultValue = false)]
|
||||
public List<string> linkedContainers { get; set; }
|
||||
|
||||
[DataMember(EmitDefaultValue = false)]
|
||||
public List<bool> showDimension { get; set; }
|
||||
}
|
||||
}
|
|
@ -5,10 +5,18 @@ import { ISymbolModel } from '../../Interfaces/ISymbolModel';
|
|||
import {
|
||||
SHOW_BORROWER_DIMENSIONS,
|
||||
SHOW_CHILDREN_DIMENSIONS,
|
||||
SHOW_SELF_DIMENSIONS,
|
||||
SHOW_SELF_MARGINS_DIMENSIONS
|
||||
SHOW_SELF_DIMENSIONS, SHOW_SELF_MARGINS_DIMENSIONS
|
||||
} from '../../utils/default';
|
||||
import { ApplyWidthMargin, ApplyXMargin, RemoveWidthMargin, RemoveXMargin, RestoreX, RestoreY, TransformX, TransformY } from '../../utils/svg';
|
||||
import {
|
||||
ApplyWidthMargin,
|
||||
ApplyXMargin,
|
||||
RemoveWidthMargin,
|
||||
RemoveXMargin,
|
||||
RestoreX,
|
||||
RestoreY,
|
||||
TransformX,
|
||||
TransformY
|
||||
} from '../../utils/svg';
|
||||
import { Text } from '../Text/Text';
|
||||
import { InputGroup } from '../InputGroup/InputGroup';
|
||||
import { TextInputGroup } from '../InputGroup/TextInputGroup';
|
||||
|
|
|
@ -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
|
||||
|
@ -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],
|
||||
|
|
|
@ -97,7 +97,7 @@ export function SVG(props: ISVGProps): JSX.Element {
|
|||
{SHOW_DIMENSIONS_PER_DEPTH
|
||||
? <DepthDimensionLayer containers={props.containers} scale={scale} roots={props.children} />
|
||||
: null}
|
||||
<DimensionLayer containers={props.containers} scale={scale} root={props.children} />
|
||||
<DimensionLayer containers={props.containers} symbols={props.symbols} scale={scale} root={props.children} />
|
||||
<SymbolLayer scale={scale} symbols={props.symbols} />
|
||||
<Selector containers={props.containers} scale={scale} selected={props.selected} /> {/* leave this at the end so it can be removed during the svg export */}
|
||||
</svg>
|
||||
|
|
|
@ -4,6 +4,8 @@ import { RestoreX, TransformX } from '../../utils/svg';
|
|||
import { InputGroup } from '../InputGroup/InputGroup';
|
||||
import { TextInputGroup } from '../InputGroup/TextInputGroup';
|
||||
import { Text } from '../Text/Text';
|
||||
import { PropertyType } from '../../Enums/PropertyType';
|
||||
import { ToggleButton } from '../ToggleButton/ToggleButton';
|
||||
|
||||
interface ISymbolFormProps {
|
||||
symbol: ISymbolModel
|
||||
|
@ -60,6 +62,13 @@ export function SymbolForm(props: ISymbolFormProps): JSX.Element {
|
|||
min={0}
|
||||
value={props.symbol.width.toString()}
|
||||
onChange={(value) => props.onChange('width', Number(value))} />
|
||||
<ToggleButton
|
||||
labelText={Text({ textId: '@ShowDimension' })}
|
||||
inputKey='showDimension'
|
||||
labelClassName=''
|
||||
inputClassName=''
|
||||
checked={props.symbol.showDimension}
|
||||
onChange={(e) => props.onChange('showDimension', e.target.checked)}/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
|
@ -26,4 +26,7 @@ export interface ISymbolModel {
|
|||
|
||||
/** List of linked container id */
|
||||
linkedContainers: Set<string>
|
||||
|
||||
/** Dimensions options */
|
||||
showDimension: boolean
|
||||
}
|
||||
|
|
|
@ -313,6 +313,7 @@ export function GetDefaultSymbolModel(name: string,
|
|||
x: 0,
|
||||
width: symbolConfig.Width ?? DEFAULT_SYMBOL_WIDTH,
|
||||
height: symbolConfig.Height ?? DEFAULT_SYMBOL_HEIGHT,
|
||||
linkedContainers: new Set()
|
||||
linkedContainers: new Set(),
|
||||
showDimension: false
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue