Skip to content

Webpackify #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Sep 9, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": ["es2015"]
}
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@
*.iml
*.ipr
*.iws
/web/app/test/viz/**
/web/app/test/viz/**
/npm-debug.log
/node_modules
/dist
3 changes: 3 additions & 0 deletions build/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/web/app/math/lm.js
/web/app/math/qr.js

24 changes: 24 additions & 0 deletions build/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"extends": "eslint:recommended",
"env": {
"browser": true,
"commonjs": true,
"es6": true
},
"parser": "babel-eslint",
"plugins": [
"babel"
],
"globals" : {
"THREE" : true,
"CSG" : true,
"PNLTRI" : true
},
"rules": {
"comma-dangle": "off",
"no-unused-vars": "off",
"max-len": "off",
"no-console": "off",
"no-extra-boolean-cast": "off"
}
}
51 changes: 0 additions & 51 deletions build/build.sh

This file was deleted.

2 changes: 1 addition & 1 deletion build/publish.sh
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

cd `dirname "$0"`

aws s3 sync ../web/ s3://sketcher/
aws s3 sync ./web/ s3://sketcher/
Binary file removed build/yuic.jar
Binary file not shown.
43 changes: 43 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"name": "jsketcher",
"version": "0.1.0",
"description": "JS.Sketcher is a parametric 2D and 3D CAD modeler written in pure javascript",
"scripts": {
"start": "webpack-dev-server --content-base web/ --port 3000",
"build": "webpack --config webpack.config.js --progress --profile --colors",
"lint": "eslint web/app -c ./build/.eslintrc.json --ignore-path ./build/.eslintignore"
},
"repository": {
"type": "git",
"url": "https://github.com/xibyte/jsketcher.git"
},
"keywords": [
"parametric",
"cad"
],
"author": "Val Erastov <xibyte@gmail.com> (http://github.com/xibyte)",
"license": "AGPL-3.0",
"bugs": {
"url": "https://github.com/xibyte/jsketcher/issues"
},
"homepage": "https://github.com/xibyte/jsketcher",
"devDependencies": {
"babel-cli": "6.14.0",
"babel-core": "6.14.0",
"babel-eslint": "6.1.2",
"babel-loader": "6.2.5",
"babel-preset-es2015": "6.14.0",
"css-loader": "0.24.0",
"eslint": "3.2.0",
"eslint-config-airbnb-base": "5.0.1",
"eslint-plugin-babel": "3.2.0",
"eslint-plugin-import": "1.12.0",
"style-loader": "0.13.1",
"webpack": "1.13.2",
"webpack-dev-server": "1.15.0"
},
"dependencies": {
"diff-match-patch": "1.0.0",
"numeric": "1.2.6"
}
}
60 changes: 32 additions & 28 deletions web/app/3d/ctrl.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import * as tk from '../ui/toolkit'
import * as cad_utils from '../utils/cad-utils'
import * as math from '../math/math'
import * as workbench from './workbench'
import {ExtrudeWizard, PlaneWizard} from './wizards/wizards'
import {IO} from '../sketcher/io'

TCAD.UI = function(app) {
function UI(app) {
this.app = app;
this.viewer = app.viewer;

var tk = TCAD.toolkit;
var mainBox = new tk.Box();
mainBox.root.css({height : '100%'});
var propFolder = new tk.Folder("Solid's Properties");
Expand Down Expand Up @@ -53,7 +58,7 @@ TCAD.UI = function(app) {
rows.removeClass('history-selected');
rows.eq(craft.historyPointer).addClass('history-selected');
var op = craft.history[craft.historyPointer];
historyWizard = TCAD.UI.createWizard(op, app, mainBox);
historyWizard = UI.createWizard(op, app, mainBox);
finishHistory.root.show();
} else {
finishHistory.root.hide();
Expand All @@ -80,7 +85,7 @@ TCAD.UI = function(app) {
var op = JSON.parse(JSON.stringify(craft.history[craft.historyPointer]));
op.protoParams = historyWizard.currentParams();
historyWizard.close();
historyWizard = TCAD.UI.createWizard(op, app, mainBox);
historyWizard = UI.createWizard(op, app, mainBox);
}
});

Expand All @@ -94,7 +99,7 @@ TCAD.UI = function(app) {
if (app.viewer.selectionMgr.selection.length == 0) {
return;
}
TCAD.UI.createCutExtrudeWizard(isCut, ui.app, app.viewer.selectionMgr.selection[0], mainBox);
UI.createCutExtrudeWizard(isCut, ui.app, app.viewer.selectionMgr.selection[0], mainBox);
}
}

Expand All @@ -103,7 +108,7 @@ TCAD.UI = function(app) {
edit.root.click(tk.methodRef(app, "sketchFace"));
refreshSketches.root.click(tk.methodRef(app, "refreshSketches"));
addPlane.root.click(function() {
TCAD.UI.createPlaneWizard(app, mainBox);
UI.createPlaneWizard(app, mainBox);
});
printSolids.root.click(function () {
app.findAllSolids().map(function(o) {
Expand Down Expand Up @@ -139,17 +144,17 @@ TCAD.UI = function(app) {
app.viewer.selectionMgr.deselectAll();
});
stlExport.root.click(function() {
var allPolygons = TCAD.utils.arrFlatten1L(app.findAllSolids().map(function (s) {
var allPolygons = cad_utils.arrFlatten1L(app.findAllSolids().map(function (s) {
return s.csg.toPolygons()
}));
var stl = CSG.fromPolygons(allPolygons).toStlString();
TCAD.io.exportTextData(stl.data[0], app.id + ".stl");
IO.exportTextData(stl.data[0], app.id + ".stl");
})
};
}

TCAD.UI.prototype.getInfoForOp = function(op) {
UI.prototype.getInfoForOp = function(op) {
var p = op.params;
var norm2 = TCAD.math.norm2;
var norm2 = math.norm2;
if ('CUT' === op.type) {
return op.type + " (" + norm2(p.target) + ")";
} else if ('PAD' === op.type) {
Expand All @@ -162,31 +167,30 @@ TCAD.UI.prototype.getInfoForOp = function(op) {
return op.type;
};

TCAD.UI.createWizard = function(op, app, alignComponent) {
UI.createWizard = function(op, app, alignComponent) {
var initParams = op.protoParams;
var face = op.face !== undefined ? app.findFace(op.face) : null;
if (face != null) {
app.viewer.selectionMgr.select(face);
}
if ('CUT' === op.type) {
return TCAD.UI.createCutExtrudeWizard(true, app, face, alignComponent, initParams, true);
return UI.createCutExtrudeWizard(true, app, face, alignComponent, initParams, true);
} else if ('PAD' === op.type) {
return TCAD.UI.createCutExtrudeWizard(false, app, face, alignComponent, initParams, true);
return UI.createCutExtrudeWizard(false, app, face, alignComponent, initParams, true);
} else if ('PLANE' === op.type) {
return TCAD.UI.createPlaneWizard(app, alignComponent, initParams, true);
return UI.createPlaneWizard(app, alignComponent, initParams, true);
}
return null;
};


TCAD.UI.createCutExtrudeWizard = function (isCut, app, face, alignComponent, initParams, overriding) {
var tk = TCAD.toolkit;
UI.createCutExtrudeWizard = function (isCut, app, face, alignComponent, initParams, overriding) {
function def(index, fallback) {
return !!initParams ? initParams[index] : fallback;
}

var normal = TCAD.utils.vec(face.csgGroup.plane.normal);
var polygons = TCAD.craft.getSketchedPolygons3D(app, face);
var normal = cad_utils.vec(face.csgGroup.plane.normal);
var polygons = workbench.getSketchedPolygons3D(app, face);

var box = new tk.Box();
box.root.css({left : (alignComponent.root.width() + 10) + 'px', top : 0});
Expand All @@ -196,7 +200,7 @@ TCAD.UI.createCutExtrudeWizard = function (isCut, app, face, alignComponent, ini
var scale = new tk.Number("Expansion", def(1, 1), 0.1, 1);
var deflection = new tk.Number("Deflection", def(2, 0), 1);
var angle = new tk.Number("Angle", def(3, 0), 5);
var wizard = new TCAD.wizards.ExtrudeWizard(app.viewer, polygons);
var wizard = new ExtrudeWizard(app.viewer, polygons);
function onChange() {
var depthValue = theValue.input.val();
var scaleValue = scale.input.val();
Expand Down Expand Up @@ -248,12 +252,10 @@ TCAD.UI.createCutExtrudeWizard = function (isCut, app, face, alignComponent, ini
}

tk.add(folder, new tk.ButtonRow(["Cancel", "OK"], [close, isCut ? applyCut : applyExtrude]));
return new TCAD.UI.WizardRef(wizard, box, close, protoParams);
return new UI.WizardRef(wizard, box, close, protoParams);
};

TCAD.UI.createPlaneWizard = function (app, alignComponent, initParams, overiding) {
var tk = TCAD.toolkit;

UI.createPlaneWizard = function (app, alignComponent, initParams, overiding) {
var box = new tk.Box();
box.root.css({left : (alignComponent.root.width() + 10) + 'px', top : 0});
var folder = new tk.Folder("Add a Plane");
Expand All @@ -264,7 +266,7 @@ TCAD.UI.createPlaneWizard = function (app, alignComponent, initParams, overiding

tk.add(folder, orientation);
tk.add(folder, depth);
var wizard = new TCAD.wizards.PlaneWizard(app.viewer);
var wizard = new PlaneWizard(app.viewer);
var orientationValue, w;
function onChange() {
wizard.update(orientationValue = orientation.getValue(), w = depth.input.val());
Expand All @@ -289,12 +291,14 @@ TCAD.UI.createPlaneWizard = function (app, alignComponent, initParams, overiding
depth.input.on('t-change', onChange);
onChange();
tk.add(folder, new tk.ButtonRow(["Cancel", "OK"], [close, ok]));
return new TCAD.UI.WizardRef(wizard, box, close, protoParams);
return new UI.WizardRef(wizard, box, close, protoParams);
};

TCAD.UI.WizardRef = function(wizard, box, close, currentParams) {
UI.WizardRef = function(wizard, box, close, currentParams) {
this.wizard = wizard;
this.box = box;
this.close = close;
this.currentParams = currentParams;
};
};

export {UI}
Loading