summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSunil Shetye2025-07-16 13:05:22 +0530
committerGitHub2025-07-16 13:05:22 +0530
commit818a9e648bb074b915a557042c497f75b53c6d2c (patch)
tree6e9e2ef29f34705549c17f550c15a38fd174d325
parentff459f7d9185b4194ba1d061c4f5d88204820497 (diff)
parent2f0b4defead36d2e8e7449d4ec788b0457594b48 (diff)
downloadCommon-Interface-Project-818a9e648bb074b915a557042c497f75b53c6d2c.tar.gz
Common-Interface-Project-818a9e648bb074b915a557042c497f75b53c6d2c.tar.bz2
Common-Interface-Project-818a9e648bb074b915a557042c497f75b53c6d2c.zip
Merge pull request #349 from suchitalad/portpositionHEADxcosblocks
Added flip and mirror icon
-rw-r--r--blocks/eda-frontend/src/components/SchematicEditor/Helper/ToolbarTools.js29
-rw-r--r--blocks/eda-frontend/src/components/SchematicEditor/SchematicToolbar.js6
-rw-r--r--blocks/eda-frontend/src/utils/GalleryUtils.js11
3 files changed, 45 insertions, 1 deletions
diff --git a/blocks/eda-frontend/src/components/SchematicEditor/Helper/ToolbarTools.js b/blocks/eda-frontend/src/components/SchematicEditor/Helper/ToolbarTools.js
index 73e3a1ac..5db83d44 100644
--- a/blocks/eda-frontend/src/components/SchematicEditor/Helper/ToolbarTools.js
+++ b/blocks/eda-frontend/src/components/SchematicEditor/Helper/ToolbarTools.js
@@ -5,7 +5,7 @@ import { useSelector } from 'react-redux'
import mxGraphFactory from 'mxgraph'
-import { styleToObject } from '../../../utils/GalleryUtils'
+import { styleToObject, objectToStyle } from '../../../utils/GalleryUtils'
import { getPortType, InputPort, OutputPort } from './ComponentDrag'
import { portSize, getParameter } from './SvgParser'
@@ -111,6 +111,33 @@ export function Rotate () {
}
}
+// vertically
+export function Flip () {
+ const cell = graph.getSelectionCell()
+ if (cell && cell.CellType === 'Component') {
+ const model = graph.getModel()
+ const currentStyle = model.getStyle(cell) || ''
+ const styleMap = styleToObject(currentStyle)
+
+ styleMap.flip = styleMap.flip === 'true' ? 'false' : 'true'
+ model.setStyle(cell, objectToStyle(styleMap))
+ }
+}
+
+// horizontally
+export function Mirror () {
+ const cell = graph.getSelectionCell()
+ if (cell && cell.CellType === 'Component') {
+ const model = graph.getModel()
+ const currentStyle = model.getStyle(cell) || ''
+ const styleMap = styleToObject(currentStyle)
+
+ styleMap.mirror = styleMap.mirror === 'true' ? 'false' : 'true'
+
+ model.setStyle(cell, objectToStyle(styleMap))
+ }
+}
+
// PRINT PREVIEW OF SCHEMATIC
export function PrintPreview () {
const title = useSelector(state => state.saveSchematic.title)
diff --git a/blocks/eda-frontend/src/components/SchematicEditor/SchematicToolbar.js b/blocks/eda-frontend/src/components/SchematicEditor/SchematicToolbar.js
index b992db10..b91b43bd 100644
--- a/blocks/eda-frontend/src/components/SchematicEditor/SchematicToolbar.js
+++ b/blocks/eda-frontend/src/components/SchematicEditor/SchematicToolbar.js
@@ -24,6 +24,7 @@ import { makeStyles } from '@material-ui/core/styles'
import AddBoxOutlinedIcon from '@material-ui/icons/AddBoxOutlined'
import ClearAllIcon from '@material-ui/icons/ClearAll'
import CloseIcon from '@material-ui/icons/Close'
+import CompareArrowsIcon from '@material-ui/icons/CompareArrows'
import CreateNewFolderOutlinedIcon from '@material-ui/icons/CreateNewFolderOutlined'
import DeleteIcon from '@material-ui/icons/Delete'
import DescriptionIcon from '@material-ui/icons/Description'
@@ -64,6 +65,8 @@ import {
editorZoomIn,
editorZoomOut,
renderGalleryXML,
+ Flip,
+ Mirror,
saveXml
} from './Helper/ToolbarTools'
import {
@@ -512,7 +515,10 @@ export default function SchematicToolbar ({ _mobileClose, gridRef }) {
'pipe',
{ icon: <UndoIcon fontSize='small' />, label: 'Undo', action: editorUndo },
{ icon: <RedoIcon fontSize='small' />, label: 'Redo', action: editorRedo },
+ 'pipe',
{ icon: <RotateRightIcon fontSize='small' />, label: 'Rotate', action: Rotate },
+ { icon: <CompareArrowsIcon style={{ transform: 'rotate(90deg)' }} fontSize='small' />, label: 'Flip', action: Flip },
+ { icon: <CompareArrowsIcon fontSize='small' />, label: 'Mirror', action: Mirror },
'pipe',
{ icon: <ZoomInIcon fontSize='small' />, label: 'Zoom In', action: editorZoomIn },
{ icon: <ZoomOutIcon fontSize='small' />, label: 'Zoom Out', action: editorZoomOut },
diff --git a/blocks/eda-frontend/src/utils/GalleryUtils.js b/blocks/eda-frontend/src/utils/GalleryUtils.js
index 7e6a6bf7..37322592 100644
--- a/blocks/eda-frontend/src/utils/GalleryUtils.js
+++ b/blocks/eda-frontend/src/utils/GalleryUtils.js
@@ -176,6 +176,17 @@ export const styleToObject = (style) => {
return styleObject
}
+export const objectToStyle = (styleObject) => {
+ let style = styleObject.default
+ for (const [key, value] of Object.entries(styleObject)) {
+ if (key === 'default' || value == null || value === '') {
+ continue
+ }
+ style += `;${key}=${value}`
+ }
+ return style
+}
+
export const saveToFile = (filename, filetype, data) => {
const blob = new Blob([data], { type: filetype + ';charset=utf-8' })
saveAs(blob, filename)