Skip to content

Commit

Permalink
Merge pull request #911 from vorth/zome-part-colors
Browse files Browse the repository at this point in the history
reset object colors now handles ball color correctly
  • Loading branch information
vorth authored Sep 2, 2024
2 parents c81d9d6 + 2c68e7e commit 2ecd857
Show file tree
Hide file tree
Showing 31 changed files with 143 additions and 79 deletions.
17 changes: 13 additions & 4 deletions core/src/main/java/com/vzome/core/editor/SymmetrySystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,10 @@ public Direction createAnonymousOrbit( AlgebraicVector vector )
return orbit;
}

public Color getVectorColor( AlgebraicVector vector ) {
if( vector.isOrigin() ) {
return Color.WHITE;
public Color getVectorColor( AlgebraicVector vector )
{
if( vector == null || vector.isOrigin() ) {
return colors .getColor( Colors.CONNECTOR );
}
// try to get from cache
Axis line = this .vectorToAxis .get( vector.toString() );
Expand All @@ -266,7 +267,7 @@ public Color getVectorColor( AlgebraicVector vector ) {
public Color getColor( Direction orbit )
{
if ( orbit == null )
return Color.WHITE;
return colors .getColor( Colors.CONNECTOR );
Color shapeColor = this .shapes .getColor( orbit ); // usually null, but see ExportedVEFShapes
if ( shapeColor == null ) // the usual case
shapeColor = orbitColors .get( orbit .getName() );
Expand Down Expand Up @@ -429,4 +430,12 @@ public AlgebraicNumber getOrbitUnitLength( Direction orbit )
{
return this .symmetryPerspective .getOrbitUnitLength( orbit );
}

public void resetColors()
{
for ( Direction orbit : symmetry .getOrbitSet() .getDirections() ) {
Color color = colors .getColor( Colors.DIRECTION + orbit .getName() );
orbitColors .put( orbit.getName(), color );
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ public Color apply( Manifestation man ) {

protected Color applyTo( Manifestation manifestation )
{
// SV 2024-09-02 - I think this can never be called, since all current subclasses override it

Color color = manifestation.getColor();
if( color == null ) { // TODO fix this! Should use techniques like SystemColorMap.
color = Color.WHITE; // provide default ball color so it can be manipulated
Expand Down Expand Up @@ -697,7 +699,7 @@ protected SystemColorMap(OrbitSource symmetry) {

@Override
protected Color applyToBall(Connector ball, int alpha) {
return Color.WHITE;
return symmetrySystem.getVectorColor( null );
}

@Override
Expand Down Expand Up @@ -797,7 +799,7 @@ protected Color applyToPanel(Panel panel, int alpha) {
@Override
protected Color applyToVector(AlgebraicVector vector) {
if(vector.isOrigin()) {
return Color.WHITE;
return symmetrySystem.getVectorColor( null ); // default ball color
}
Axis nearestSpecialOrbit = symmetrySystem.getSymmetry().getAxis(vector.toRealVector(), specialOrbits);
AlgebraicVector normal = nearestSpecialOrbit.normal();
Expand Down
1 change: 0 additions & 1 deletion core/src/main/java/com/vzome/core/model/ConnectorImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public class ConnectorImpl extends ManifestationImpl implements Connector
public ConnectorImpl( AlgebraicVector loc )
{
super();
this.setColor(Color.WHITE);
m_center = loc;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ public boolean[] enableContextualCommands( String[] menu, MouseEvent e )
case "setAllDirections":
case "usedOrbits":
case "configureDirections":
case "resetOrbitColors":
result[i] = true;
break;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,11 @@ public void doAction( String action ) throws Exception
action += "/" + this .symmetrySystem .getName() + ":" + this .symmetrySystem .getStyle() .getName();
super .doAction( action );
break;

case "resetOrbitColors":
this .symmetrySystem .resetColors();
availableController .firePropertyChange( "orbits", true, false );
break;

default:
if ( action .startsWith( "setStyle." ) )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,11 @@ public void actionPerformed( ActionEvent e )
symmetryDialog .setVisible( true );
break;

case "resetOrbitColors":
delegate = mController .getSubController( "symmetry." + system );
delegate .actionPerformed( e .getSource(), e .getActionCommand() );
break;

case "addBookmark":
String numStr = toolsController .getProperty( "next.tool.number" );
int bookmarkNum = Integer .parseInt( numStr );
Expand Down Expand Up @@ -977,6 +982,7 @@ private ActionListener getActionListener( String command, Controller controller
case "configureDirections":
case "addBookmark":
case "export4dPolytope":
case "resetOrbitColors":
actionListener = this .localActions;
break;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ public void actionPerformed( ActionEvent evt )
directionPopupMenu.add( enabler .setMenuAction( "usedOrbits", drawnOrbits, new JMenuItem( "used in model" ) ) );
directionPopupMenu.add( enabler .setMenuAction( "setAllDirections", drawnOrbits, new JMenuItem( "all" ) ) );
directionPopupMenu.add( enabler .setMenuAction( "configureDirections", drawnOrbits, new JMenuItem( "configure..." ) ) );
directionPopupMenu.add( enabler .setMenuAction( "resetOrbitColors", drawnOrbits, new JMenuItem( "reset colors" ) ) );
}
else
directionPopupMenu = null;
Expand Down
5 changes: 5 additions & 0 deletions online/src/app/classic/components/strutbuilder.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ export const StrutBuildPanel = () =>
setAnchorEl( null );
showOrbitsDialog();
}
const resetOrbitColors = () => {
setAnchorEl( null );
controllerAction( symmetryController(), 'resetOrbitColors' );
}

return(
<div id="build" style={{ display: 'grid', 'grid-template-rows': '1fr min-content', height: '100%' }}>
Expand All @@ -57,6 +61,7 @@ export const StrutBuildPanel = () =>
<MenuItem onClick={ setAvailableOrbits( 'predefinedOrbits' ) }>predefined</MenuItem>
<MenuItem onClick={ setAvailableOrbits( 'setAllDirections' ) }>all</MenuItem>
<MenuItem onClick={ showConfiguration }>configure...</MenuItem>
<MenuItem onClick={ resetOrbitColors }>reset orbit colors</MenuItem>
</Menu>
</OrbitPanel>
<StrutLengthPanel controller={buildOrbits()} />
Expand Down
62 changes: 41 additions & 21 deletions online/src/wc/zometool/bom.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,36 +25,56 @@ const svgMapping = {
}

const partcodeMapping = {
ball: 'PZB-BAL-W',
b0: 'PST-B0-BLU',
b1: 'PST-B1-BLU',
b2: 'PST-B2-BLU',
y0: 'PST-Y0-YEL',
y1: 'PST-Y1-YEL',
y2: 'PST-Y2-YEL',
r00: 'PST-R00-RED',
r0: 'PST-R0-RED',
r1: 'PST-R1-RED',
r2: 'PST-R2-RED',
g0: 'PST-G0-GRN',
g1: 'PST-G1-GRN',
g2: 'PST-G2-GRN',
hg0: 'PST-HG0-GRN',
hg1: 'PST-HG1-GRN',
hg2: 'PST-HG2-GRN',
ball: 'PZB-BAL-',
b0: 'PST-B0-',
b1: 'PST-B1-',
b2: 'PST-B2-',
y0: 'PST-Y0-',
y1: 'PST-Y1-',
y2: 'PST-Y2-',
r00: 'PST-R00-',
r0: 'PST-R0-',
r1: 'PST-R1-',
r2: 'PST-R2-',
g0: 'PST-G0-',
g1: 'PST-G1-',
g2: 'PST-G2-',
hg0: 'PST-HG0-',
hg1: 'PST-HG1-',
hg2: 'PST-HG2-',
}

const colorMapping = {
"blue": "BLU",
"yellow": "YEL",
"red": "RED",
"green": "GRN",
"turquoise": "TEA",
"orange": "ORG",
"purple": "PUR",
"white": "W",
"black": "BLK",
"gray": "GRY",
}


export const normalizeBOM = rawBoM =>
export const normalizeBOM = ( rawBoM, { colors, parts } ) =>
{
const bom = [];
const zometoolCodes = Object.keys( parts ); // not using the values at the moment
// the order in partcodeMapping will be the order in bom
for (const key in partcodeMapping) {
const rawKey = svgMapping[ key ];
if ( Object.hasOwnProperty.call( rawBoM, rawKey ) ) {
const partNum = partcodeMapping[ key ];
const count = rawBoM[ rawKey ];
bom .push( { key, partNum, count } )
// There is a rawBoM entry for this rawKey (e.g. svgMapping["b0"]), itself a histogram by color
const partNumPrefix = partcodeMapping[ key ];
for (const [ colorName, count ] of Object.entries( rawBoM[ rawKey ]) ) {
const partNum = partNumPrefix + colorMapping[ colorName ];
if ( zometoolCodes .includes( partNum ) ) {
const color = colors[ colorName ];
bom .push( { key, partNum, count, color } )
}
}
}
}
return bom;
Expand Down
8 changes: 7 additions & 1 deletion online/src/wc/zometool/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ import { normalizeBOM } from './bom.js';

const debug = false;

const parts_catalog_url = 'https://zometool.github.io/vzome-sharing/metadata/zometool-parts.json';
const partsPromise = fetch( parts_catalog_url ) .then( response => response.text() ) .then( text => JSON.parse( text ) );

const StepControls = props =>
{
const { scenes, requestScene } = useViewer();
Expand Down Expand Up @@ -51,7 +54,10 @@ const StepControls = props =>

const { subscribeFor } = useWorkerClient();
subscribeFor( 'BOM_CHANGED', bom => {
props.dispatch( new CustomEvent( 'zometool-instructions-loaded', { detail: normalizeBOM( bom ) } ) );
partsPromise .then( parts => {
const detail = normalizeBOM( bom, parts );
props.dispatch( new CustomEvent( 'zometool-instructions-loaded', { detail } ) );
});
} );

return (
Expand Down
12 changes: 7 additions & 5 deletions online/src/wc/zometool/parts-list.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,12 @@ const svgStrings = {
hg2 : hg2Svg,
}

const getSvgNode = key =>
const getSvgNode = ( key, color ) =>
{
let doc = new DOMParser().parseFromString( svgStrings[ key ], 'application/xml' );
return document .importNode( doc.documentElement, true );
let doc = new DOMParser() .parseFromString( svgStrings[ key ], 'application/xml' );
const svg = document .importNode( doc.documentElement, true );
svg .setAttribute( 'fill', color );
return svg;
}

const debug = false;
Expand All @@ -72,10 +74,10 @@ const ZometoolParts = props =>
</TableRow>
</TableHead>
<TableBody>
<For each={props.bom}>{ ({ key, count }) =>
<For each={props.bom}>{ ({ key, count, color }) =>
<TableRow sx={{ "&:last-child td, &:last-child th": { border: 0 } }} >
<TableCell align="left" component="th" scope="row" sx={partSx}>
{getSvgNode( key )}
{getSvgNode( key, color )}
</TableCell>
<TableCell component="th" scope="row">{ ((key==='ball')? '' : key) .toUpperCase() }</TableCell>
<TableCell align="right">{count}</TableCell>
Expand Down
4 changes: 2 additions & 2 deletions online/src/wc/zometool/parts/b0.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions online/src/wc/zometool/parts/b1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions online/src/wc/zometool/parts/b2.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions online/src/wc/zometool/parts/ball.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions online/src/wc/zometool/parts/g0.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions online/src/wc/zometool/parts/g1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions online/src/wc/zometool/parts/g2.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions online/src/wc/zometool/parts/hg0.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions online/src/wc/zometool/parts/hg1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions online/src/wc/zometool/parts/hg2.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions online/src/wc/zometool/parts/r0.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions online/src/wc/zometool/parts/r00.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions online/src/wc/zometool/parts/r1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions online/src/wc/zometool/parts/r2.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions online/src/wc/zometool/parts/y0.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions online/src/wc/zometool/parts/y1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions online/src/wc/zometool/parts/y2.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 4 additions & 6 deletions online/src/wc/zometool/products-list.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@ import { instructionsCSS } from "./zometool.css.js";
const debug = false;

const product_catalog_url = 'https://zometool.github.io/vzome-sharing/metadata/zometool-products.json';
const parts_catalog_url = 'https://zometool.github.io/vzome-sharing/metadata/zometool-parts.json';

const fetchJSON = url => fetch( url ) .then( response => response.text() ) .then( text => JSON.parse( text ) );
const productsPromise = fetchJSON( product_catalog_url );
const partsPromise = fetchJSON( parts_catalog_url );

const findProducts = ( bom, parts, products ) =>
const findProducts = ( bom, products ) =>
{
const productCoversBom = ( product, bom ) =>
bom .reduce( (covers, part) => covers && product.bom[ part.partNum ] >= part.count, true );
Expand All @@ -33,9 +31,9 @@ const ZometoolProducts = props =>
{
const [ matchingProducts, setMatchingProducts ] = createSignal( [] );

Promise.all( [ productsPromise, partsPromise ] )
.then( ([ products, parts ]) => {
setMatchingProducts( findProducts( props.bom, parts, products ) );
productsPromise
.then( ( products ) => {
setMatchingProducts( findProducts( props.bom, products ) );
} );

return (
Expand Down
Loading

0 comments on commit 2ecd857

Please sign in to comment.