Skip to content

Commit

Permalink
MINT loading is working
Browse files Browse the repository at this point in the history
  • Loading branch information
rkrishnasanka committed Jan 25, 2019
1 parent 008c9fd commit 6264ae3
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 140 deletions.
14 changes: 10 additions & 4 deletions src/app/core/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ class Component {
* @param name
*/
setName(name){
console.log("test", name);
this.__name = name;
}

Expand Down Expand Up @@ -304,6 +303,15 @@ class Component {
return ret;
}

/**
* Returns the center position of the component as a 2D vector
* @return {*[]}
*/
getCenterPosition(){
let bounds = this.getBoundingRectangle();
return [bounds.center.x, bounds.center.y];
}

/**
* This method is used to import the component from Interchange V1 JSON
* @param json
Expand All @@ -320,7 +328,7 @@ class Component {
let entity = json.entity;
let params = {};
let definition = Registry.featureSet.getDefinition(entity);
console.log(definition);
// console.log(definition);
let type;
let value;
for(let key in json.params){
Expand All @@ -333,8 +341,6 @@ class Component {
// let paramobject = Parameter.generateComponentParameter(key, json.params[key]);
//Check if the value type is float and convert the value from string
value = json.params[key];
console.log(value);
console.log(typeof value);
if(type === "Float" && typeof value == "string"){
value = parseFloat(value);
}
Expand Down
2 changes: 0 additions & 2 deletions src/app/core/device.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,6 @@ export default class Device {
connectiontoload = Connection.fromInterchangeV1(connections[i]);
this.__connections.push(connectiontoload);
}
console.log("Connections:", this.__connections);
}


Expand Down Expand Up @@ -428,7 +427,6 @@ export default class Device {

//Updating cross-references
let features = newDevice.getAllFeaturesFromDevice();
console.log("Features: ",features);
let feature;
for(let i in features){
//console.log("Feature:", features[i]);
Expand Down
23 changes: 23 additions & 0 deletions src/app/view/paperView.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import PanAndZoom from "./panAndZoom";
const Colors = require("./colors");
import TextFeature from "../core/textFeature";
import ManufacturingLayer from "../manufacturing/manufacturingLayer";
import RatsNestRenderer2D from "./render2D/ratsNestRenderer2D";
const DXFObjectRenderer2D = require('./render2D/dxfObjectRenderer2D');
const DXFSolidObjectRenderer = require('./render2D/dxfSolidObjectRenderer2D');

Expand Down Expand Up @@ -47,6 +48,8 @@ export default class PaperView {
this.alignmentMarksLayer.insertAbove(this.textFeatureLayer);
this.uiLayer = new paper.Group(); //This is the layer which we use to render targets
this.uiLayer.insertAbove(this.featureLayer);
this.ratsNestLayer = new paper.Group();
this.ratsNestLayer.insertAbove(this.featureLayer);
this.currentTarget = null;
this.lastTargetType = null;
this.lastTargetPosition = null;
Expand Down Expand Up @@ -463,6 +466,26 @@ export default class PaperView {
this.alignmentMarks = null;
}

updateRatsNest(){
this.removeRatsNest();
let unrouted = this.__viewManagerDelegate.currentDevice.getUnroutedConnections();

let rendergroup = RatsNestRenderer2D.renderRatsNest(unrouted, this.__viewManagerDelegate.currentDevice);

this.__ratsNestRender = rendergroup;
this.ratsNestLayer.addChild(this.__ratsNestRender);

}

removeRatsNest() {
//First clear out the render objects
if(this.__ratsNestRender){
this.__ratsNestRender.remove();
}
//Next set it to null
this.__ratsNestRender = null;
}

moveCenter(delta) {
this.panAndZoom.moveCenter(delta);
}
Expand Down
120 changes: 12 additions & 108 deletions src/app/view/render2D/ratsNestRenderer2D.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ export default class RatsNestRenderer2D{
sinkid = sink.componentID;

let startcomponent = device.getComponentByID(sourceid);
let endcomponent = device.getComponentByID(sinkid)
start = startcomponent.getPosition();
end = endcomponent.getPosition();
console.log(startcomponent, endcomponent);
let endcomponent = device.getComponentByID(sinkid);
start = startcomponent.getCenterPosition();
end = endcomponent.getCenterPosition();
// console.log(start, end);
render = RatsNestRenderer2D.renderRatsNestConnection(start, end);
ratsnestgroup.addChild(render);
}
Expand All @@ -35,112 +35,16 @@ export default class RatsNestRenderer2D{
}

static renderRatsNestConnection(start, end){
// let vstart = new paper.Point(start.x, start.y - radius);
// let vend = new paper.Point(end.x, end.y + radius);
//
// let vpath = new paper.Path(vstart, vend);
//
// vpath.strokeColor = '#696965';
// vpath.strokeWidth = 500;
// vpath.strokeCap = 'round';
//
// vpath.dashArray = [1000, 1200];
// return vpath;
}
}

function getLayerColor(feature) {
let height = feature.getValue("height");
let layerHeight = 1; // feature.layer.estimateLayerHeight();
let decimal = height / layerHeight;
if (decimal >1) decimal = 1;
if (!feature.layer.flip) decimal = 1 - decimal;
let targetColorSet = Colors.getLayerColors(feature.layer);
return Colors.decimalToLayerColor(decimal, targetColorSet, Colors.darkColorKeys);
}

function getBaseColor(feature) {
let decimal = 0;
if (!feature.layer.flip) decimal = 1 - decimal;
let targetColorSet = Colors.getLayerColors(feature.layer);
return Colors.decimalToLayerColor(decimal, targetColorSet, Colors.darkColorKeys);
}

function getDefaultValueForType(typeString, setString, key) {
return Feature.getDefaultsForType(typeString, setString)[key];
}

function getFeatureRenderer(typeString, setString) {
let rendererInfo = FeatureSets.getRender2D(typeString, setString);
return rendererInfo;
}

function getPrimitive2D(typeString, setString) {
return PrimitiveSets2D[setString][typeString];
}

function calculateDistance(pointer_position, feature_position) {
return Math.sqrt(Math.pow(pointer_position[0] - feature_position.x, 2) + Math.pow(pointer_position[1] - feature_position.y, 2));
}

function renderAlignmentMarks(position, radius, features) {
// let renderer = getFeatureRenderer(typeString, setString);
// let params = renderer.targetParams;
// let prim = getPrimitive2D(renderer.targetPrimitiveType, renderer.targetPrimitiveSet);
// let primParams = {};
// for (let key in params) {
// primParams[key] = getDefaultValueForType(typeString, setString, params[key]);
// }
// primParams["position"] = position;
// primParams["color"] = Colors.getDefaultFeatureColor(typeString, setString, Registry.currentLayer);
// let rendered = prim(primParams);
let alignmentmarkergroup = new paper.Group();
let vstart = new paper.Point(start[0], start[1]);
let vend = new paper.Point(end[0], end[1]);

for(let i in features){
let vpath = new paper.Path(vstart, vend);

let feature = features[i];
if(feature == null){
continue;
}
if(calculateDistance(position, feature.getBounds().center) <radius){
//TODO: figure out how check for different kinds of components and then generate

//Generate the alignment H | V lines for each of the features

//Get the bounds of the feature

let bounds = feature.getBounds();

//Only the centroid alignment marks
let center = bounds.center;
let hstart = new paper.Point(center.x - radius, center.y);
let hend = new paper.Point(center.x + radius, center.y);

let vstart = new paper.Point(center.x, center.y - radius);
let vend = new paper.Point(center.x, center.y + radius);

let hpath = new paper.Path(hstart, hend);
let vpath = new paper.Path(vstart, vend);

hpath.strokeColor = '#696965';
hpath.strokeWidth = 500;
hpath.strokeCap = 'round';
vpath.strokeColor = '#696965';
vpath.strokeWidth = 500;
vpath.strokeCap = 'round';

hpath.dashArray = [1000, 1200];

vpath.strokeColor = '#696965';
vpath.strokeWidth = 500;
vpath.strokeCap = 'round';

vpath.dashArray = [1000, 1200];


alignmentmarkergroup.addChild(vpath);
alignmentmarkergroup.addChild(hpath);
}
vpath.dashArray = [1000, 1300];
return vpath;
}

return alignmentmarkergroup;
}

module.exports.renderAlignmentMarks = renderAlignmentMarks;
36 changes: 10 additions & 26 deletions src/app/view/viewManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ export default class ViewManager {
this.view.setResizeFunction(function() {
reference.updateGrid();
reference.updateAlignmentMarks();

reference.view.updateRatsNest();

reference.updateDevice(Registry.currentDevice);
});
Expand Down Expand Up @@ -350,6 +352,7 @@ export default class ViewManager {
this.view.setZoom(zoom);
this.updateGrid(false);
this.updateAlignmentMarks();
this.view.updateRatsNest();

this.updateDevice(Registry.currentDevice, false);
this.__updateViewTarget(false);
Expand Down Expand Up @@ -442,12 +445,14 @@ export default class ViewManager {
updateTarget(featureType, featureSet, position, refresh = true) {
this.view.addTarget(featureType, featureSet, position);
this.view.updateAlignmentMarks();
this.view.updateRatsNest();
this.refresh(refresh);
}

__updateViewTarget(refresh = true) {
this.view.updateTarget();
this.updateAlignmentMarks();
this.view.updateRatsNest();
this.refresh(refresh);
}

Expand All @@ -458,7 +463,7 @@ export default class ViewManager {
this.view.adjustZoom(delta, point);
this.updateGrid(false);
//this.updateAlignmentMarks();

this.view.updateRatsNest();
this.updateDevice(Registry.currentDevice, false);
this.__updateViewTarget(false);
} else {
Expand All @@ -480,7 +485,7 @@ export default class ViewManager {
this.view.moveCenter(delta);
this.updateGrid(false);
// this.updateAlignmentMarks();

this.view.updateRatsNest();
this.updateDevice(Registry.currentDevice, false);
this.refresh(refresh);
}
Expand Down Expand Up @@ -906,46 +911,25 @@ export default class ViewManager {

//TODO: Step 2 generate rats nest renders for all the components

let connections = this.currentDevice.getConnections();
let unrouted = [];
for(let i in connections){
let connection = connections[i];
if(!connection.routed){
unrouted.push(connection);
}
}

let drawinggroup = RatsNestRenderer2D.renderRatsNest(unrouted, this.currentDevice);

//Pass this to the view somehow
this.view.updateRatsNest();
}

__generateDefaultPlacementForComponent(component, xpos, ypos) {

let params_to_copy = component.getParams().toJSON();

// console.log(params_to_copy);
params_to_copy["position"] = [xpos, ypos];

//Get default params and overwrite them with json params, this can account for inconsistencies
let nonminttype = Registry.featureSet.getTypeForMINT(component.getType());
// console.log(nonminttype);
let newFeature = Feature.makeFeature(nonminttype, "Basic", {
"position": [xpos, ypos]
});

// console.log(newFeature);

// let currentFeatureID = newFeature.getID();
let newFeature = Feature.makeFeature(nonminttype, "Basic", params_to_copy);

component.addFeatureID(newFeature.getID());

Registry.currentLayer.addFeature(newFeature);

//Set the component position
console.log("updating component position");
component.updateComponetPosition([xpos, ypos]);



}
}

0 comments on commit 6264ae3

Please sign in to comment.