Wireframe design
Arc
var c = new GO2SXYZ
var p1 = new GO2SXYZ(10,0,0)
var p2 = new GO2SXYZ(0,10,0)
var arc = new GO2SArc
arc.SetFromCenterStartEnd(c, p1, p2)
var c = new GO2SXYZ
var p1 = new GO2SXYZ(10,0,0)
var p2 = new GO2SXYZ(0,10,0)
var arc = GO2SArcCreate.FromCenterStartEnd(c, p1, p2)
var c = new GO2SXYZ
var p1 = new GO2SXYZ(10,0,0)
var p2 = new GO2SXYZ(0,10,0)
var arc = new GO2SArc(c, p1, p2)
Chamfer
// create 3 points
var A = new GO2SXYZ(-10,-10,0)
var B = new GO2SXYZ(10,-10,0)
var D = new GO2SXYZ(-10,10,0)
// create 2 segments between points
var AB = new GO2SSegment(A,B)
var DA = new GO2SSegment(D,A)
// create a 5mm chamfer between segments
new GO2SChamfer(DA,AB,5)
Fillet
// create 3 points
var A = new GO2SPoint(-10,-10,0)
var B = new GO2SPoint(10,-10,0)
var D = new GO2SPoint(-10,10,0)
// create 2 segments between points
var AB = new GO2SSegment(A.toXYZ(),B.toXYZ())
var DA = new GO2SSegment(D.toXYZ(),A.toXYZ())
// create a 5mm fillet between segments
var fillet = new GO2SFillet(DA,AB,5)
Nurbs
var pts = []
pts.push(new GO2SXYZ(0, 0, 0))
pts.push(new GO2SXYZ(12, 5, 0))
pts.push(new GO2SXYZ(15, 10, 0))
pts.push(new GO2SXYZ(20, 20, 0))
var nurbs = new GO2SNurbs(pts, false, -1)
var s1 = new GO2SSegment(new GO2SXYZ(-100,15,0),new GO2SXYZ(-50,30,0))
var s2 = new GO2SSegment(new GO2SXYZ(45,15,0),new GO2SXYZ(120,-10,0))
var start = s1.GetLastPoint()
var end = s2.GetFirstPoint()
var p1 = new GO2SXYZ(-10, -10, 0)
var p2 = new GO2SXYZ(0, 0, 0)
var p3 = new GO2SXYZ(10, -10, 0)
var nurbs = GO2SNurbsCreate.FromPointsWTangency([start,p1,p2,p3,end], true, true)
var elts = nurbs.ToArcAndSegment(0.01, 9999)
nurbs.Delete()
console.log("nurbs converted in " + elts.length +" elements")
Oblong
var p1 = new GO2SXYZ(10,10,0)
var p2 = new GO2SXYZ(10,100,0)
var obl1 = new GO2SOblong(p1,p2,20)
var p0 = new GO2SXYZ(50,50,0)
var obl2 = GO2SOblongCreate.FromCenter(p0, 30, 90, 20)
Ellipse
var center = new GO2SXYZ(50,50,0)
var pMajor = new GO2SXYZ(120,60,0)
var pMinor = new GO2SXYZ(40, 40, 0)
var ellipse = new GO2SEllipse(center, pMajor, pMinor)
center = new GO2SXYZ(-50,-50,0)
var aMajor = new GO2SXYZ(0.707,0.707,0)
pMajor = center.Added(aMajor)
var z = new GO2SXYZ(0,0,1)
var aMinor = aMajor.CrossProduct(z)
pMinor = center.Added(aMinor)
ellipse = new GO2SEllipse(center, pMajor, pMinor)
ellipse.SetParam(GO2SParam.length, 100)
ellipse.SetParam(GO2SParam.width, 50)
Helix
var center = new GO2SXYZ(50,50,0)
var p = new GO2SXYZ(120,60,0)
var helix = new GO2SHelix(center, p, 10, 5.5, false)
var helix2 =helix.Copy()
helix2.SetParam(GO2SParam.radius, 20)
helix2.SetStepNumber(3)
helix2.SetStepSize(20)
Polygon
var center = new GO2SXYZ(50,50,0)
var p = new GO2SXYZ(120,60,0)
var pl = new GO2SPolygon(center, p, 10, false)
var pl2 = pl.Copy()
pl2.SetParam(GO2SParam.radius, 20)
Profile
var seg1 = new GO2SSegment(new GO2SXYZ, new GO2SXYZ(15,15,0))
var seg2 = new GO2SSegment(seg1.GetLastPoint(), new GO2SXYZ(40,15,0))
var seg3 = new GO2SSegment(seg2.GetLastPoint(), new GO2SXYZ(40,40,0))
var prf =new GO2SProfile(seg1,seg3)
var len1 = seg1.GetLength() + seg2.GetLength() + seg3.GetLength()
var len2 = prf.GetLength()
console.log('geometry length: '+ len1)
console.log('profile length: '+ len2)
Offset
var pt1 = new GO2SXYZ(-10, -30, 0)
var pt2 = new GO2SXYZ(0, 5, 0)
var pt3 = new GO2SXYZ(5, -30, 0)
var seg1 = new GO2SSegment(pt1, pt2)
var seg2 = new GO2SSegment(pt2, pt3)
var prf2 = GO2SProfileCreate.From2Geom(seg1,seg2)
var offsetChamfer = new GO2SOffsetCurve(prf2, GO2SOffsetSide.Outside, 2, GO2SOffsetLink.Chamfer, 1, false);
Hole
var p1 = new GO2SXYZ(10,10,0)
var p2 = new GO2SXYZ(10,100,0)
var seg = new GO2SSegment(p1,p2)
// blind hole diam 10, h 20
var hole = new GO2SHole(new GO2SXYZ(),new GO2SXYZ(0,0,1), 10, 20, true);
hole.SetPosition(seg.GetLastPoint());
Solid design
Revolution
var p1 = new GO2SXYZ(10,10,0)
var p2 = new GO2SXYZ(20,100,0)
var seg = new GO2SSegment(p1,p2)
var p0 = new GO2SXYZ(80,50,0)
var obl1 = GO2SOblongCreate.FromCenter(p0, 30, 90, 20)
var obl2 = GO2SOblongCreate.FromCenter(p0, 30, 90, 15)
var prf1 = GO2SProfileCreate.FromMultiGeom(obl1)
var prf2 = GO2SProfileCreate.FromMultiGeom(obl2)
var prf = [prf1, prf2]
var axis1 = new GO2SXYZ(GO2SAxis.x)
var revol1 = new GO2SSolid
revol1.CreateMultiRevolution(prf, axis1, 90, false)
var axis2 = seg.GetDirectionOnCurve(0)
var revol2 = new GO2SSolid
revol2.CreateMultiRevolution(prf, axis2, 180, false)
Holes
var pt1 = new GO2SXYZ(30, 0, 0)
var ptc = new GO2SXYZ(40, 0, 0)
var pt2 = new GO2SXYZ(50, 0, 0)
var arc1 = GO2SArcCreate.FromCenterStartEnd(ptc, pt1, pt2)
var arc2 = GO2SArcCreate.FromCenterStartEnd(ptc, pt2, pt1)
var prf = GO2SProfileCreate.From2Geom(arc1,arc2)
var axis = new GO2SXYZ(GO2SAxis.y)
var revol = new GO2SSolid
revol.CreateRevolution(prf, axis, 360, false)
revol.SetColor(0xFF0000)
arc1.SetVisible(false)
arc2.SetVisible(false)
var nbHole=20
var angIncr=3.14/nbHole
for( i=1;i<nbHole;i++)
{
var ang=angIncr*i
var normal=new GO2SXYZ(Math.cos(ang), 0, Math.sin(ang))
var pnt=new GO2SXYZ(50*Math.cos(ang), 0, 50*Math.sin(ang))
var hole=GO2SHoleCreate.SimpleSmoothHole(pnt , normal,5,1,true)
revol.SubtractHole(hole)
}
Boolean operation
var len = 100
var wid = 50
var hc = 40
var ht = 60
var rad = 10
var org = new GO2SXYZ(0,0,0)
var ptX = new GO2SXYZ(len,0,0)
var ptY = new GO2SXYZ(len,wid,0)
var castle = new GO2SSolid
castle.CreateCuboid(org, ptX, ptY, hc)
var tower1 = new GO2SSolid
tower1.CreateCylinder(org, rad, ht)
var mat = new GO2SMatrix
mat.DefineTranslation(new GO2SXYZ(len,0,0))
var tower2 = tower1.Transformed(mat)
mat.DefineTranslation(new GO2SXYZ(0,wid,0))
var tower3 = tower1.Transformed(mat)
mat.DefineTranslation(new GO2SXYZ(len,wid,0))
var tower4 = tower1.Transformed(mat)
castle.MultiUnion([tower1,tower2,tower3,tower4])
castle.SetColor(0xDDDDDD)
castle.SetName('Castle')
var bbox = castle.GetBoundingBox()
var p = bbox[1]
p.SetPosition(bbox[1].X(),bbox[1].Y(),bbox[0].Z())
new GO2SRectangle(bbox[0], p)
Fillets
let solid = GO2SSolidCreate.Cuboid(new GO2SXYZ(), new GO2SXYZ(100,0,0), new GO2SXYZ(100,50,0), 30)
// get all solid faces and find the top face (normal is Z)
let faces = solid.GetFaces()
let top = null
faces.forEach( f => {
if(f.GetNormal().Z() == 1)
top = f
})
// apply a fillet on all edges of the top face
if(top)
{
let edges = top.GetEdges()
solid.ApplyFillet(edges, 5)
}
XYZ computing
Intersections
var center = new GO2SXYZ(10, 20, 0)
var circle = new GO2SCircle(center, 100)
var line = new GO2SLine(new GO2SXYZ(-10, 10, 0), new GO2SXYZ(10, 15, 0))
var intersections = new GO2SIntersect(circle, line)
var inter_array = intersections.GetIntersections()
inter_array.forEach(p => new GO2SPoint(p))
Positions
var p1 = new GO2SXYZ(10,10,0)
var p2 = new GO2SXYZ(50,20,0)
var segment = new GO2SSegment(p1,p2)
// compute the center
var center = p1.Added(p2)
center.Scale(0.5)
var circle = GO2SCircleCreate.From2Points(center,p2)
var p1 = new GO2SXYZ(10,10,0)
var p2 = new GO2SXYZ(50,20,0)
var segment = new GO2SSegment(p1,p2)
var center = segment.GetMidPoint()
var end = segment.GetLastPoint()
var circle = GO2SCircleCreate.From2Points(center,end)
Tangent and normal directions
// Draw a red arc
geom = GO2SArcCreate.FromCenterStartEnd(
new GO2SXYZ(),
new GO2SXYZ(50,0,0),
new GO2SXYZ(0,50,0)
)
geom.SetColor(0x0000FF)
for(let t=0; t<1.0001; t+=0.2)
{
// draw a yellow point at t position on curve
let pt = geom.GetPositionOnCurve(t)
let point = new GO2SPoint(pt)
point.SetColor(0x000FFFF)
raw_pt = new GO2SXYZ(pt.X(), pt.Y(), pt.Z())
// draw a green segment to show the tangent direction at t position on curve
let dir = geom.GetTangentOnCurve(t)
let seg = GO2SSegmentCreate.FromDirAndLength (raw_pt, dir, 5)
seg.SetColor(0x00FF00)
// draw a blue segment to show the normal direction at t position on curve
dir = geom.GetNormalOnCurve(t)
seg = GO2SSegmentCreate.FromDirAndLength (raw_pt, dir, 5)
seg.SetColor(0xFF0000)
}
Projection
var center = new GO2SXYZ(10, 20, 0)
var circle = GO2SCircleCreate.FromRadius(center, 100)
var pt = GO2SPointCreate.FromCoordinates(-30, 60, 0)
var xyz = circle.GetProjPoint(pt.toXYZ())
var proj = GO2SPointCreate.FromReference(xyz)
Bounding box
var center = new GO2SXYZ(10, 20, 0)
var circle = new GO2SCircle(center, 100)
var bbox = circle.GetBoundingBox()
var line = new GO2SSegment(bbox[0], bbox[1])
var len = line.GetLength()
var len2 = bbox[0].Distance(bbox[1])
console.log('len:' + len)
console.log('len2:' + len2)
Discretization
var center = new GO2SXYZ(50,50,0)
var pMajor = new GO2SXYZ(120,60,0)
var pMinor = new GO2SXYZ(40, 40, 0)
var ellipse = new GO2SEllipse(center, pMajor, pMinor)
var pts = ellipse.Discretize()
pts.forEach(pt => new GO2SPoint(pt));
Translation
var p1 = new GO2SXYZ
var p2 = new GO2SXYZ(10,10,0)
var circle = new GO2SCircle(p1,5)
var seg = new GO2SSegment(p1, p2)
var dir = seg.GetDirectionOnCurve(0)
var circle2 = circle.Translated(seg.GetFirstPoint(), seg.GetLastPoint())
Rotation
var p1 = new GO2SXYZ(10,10,0)
var p2 = new GO2SXYZ(10,100,0)
var obl1 = new GO2SOblong(p1,p2,20)
obl1.SetColor(0X00FF00);
var p0 = new GO2SXYZ
var obl2 = obl1.Rotated(p0, 45, false)
obl2.SetColor(0XFF0000);
Interactions
Colors
// GO2Cam current color is red
var pt1 = new GO2SXYZ()
var pt2 = new GO2SXYZ(10,10,10)
var pt3 = new GO2SXYZ(30,30,30)
var pt4 = new GO2SXYZ(-10,20,-10)
// The Segment will be red
new GO2SSegment(pt1,pt2)
// The Segment will be blue
GO2SGeometryUtil.SetUsedColor(0xff0000)
new GO2SSegment(pt2,pt3)
// The Segment will be red
GO2SGeometryUtil.SetUsedColor(-1) // Back to red
new GO2SSegment(pt3,pt4)
// The Segment will be green
var seg = new GO2SSegment(pt4,pt1)
seg.SetColor(0x00ff00)
Getting entities
// Get all red circle
var redCircles = GO2SGeometryUtil.GetCircle(0x0000FF)
// Change the radius of all red circles
redCircles.forEach(c => c.SetParam(GO2SParam.radius, 20))
3D scene
GO2SInteract.StartSelection()
var geom = GO2SGeometryUtil.GetSelected()
var pts = []
geom.forEach( (g) =>{
if(g.IsPoint())
pts.push(g.toXYZ())
})
var nurbs = new GO2SNurbs(pts, true, -1)
var polyline = new GO2SPolyline(pts, true, -1)
var geom1 = GO2SInteract.PickEntity('Select a linear entity')
if(geom1.IsLinear())
{
var p1 = GO2SInteract.PickXYZ()
var ln = new GO2SLine()
ln.SetParallelByPoint(p1, geom1)
}
else
GO2SDialogUtil.CreateMessageBox('Please select a line or a segment')
var circle = new GO2SCircle(new GO2SXYZ, 50)
var preview = [circle]
for (let i = 0; i < 4; i++)
{
var center = GO2SInteract.PickXYZWithPreview(preview)
new GO2SCircle(center, 50)
GO2SInteract.Redraw() // Update viewport
}
Dialog
LineParam.ui
LineParam.pce
var line_a = GO2SGeometryUtil.GetByName('line_angle')[0]
var line_p = GO2SGeometryUtil.GetByName('line_parallel')[0]
var InitDialog = function()
{
GO2SDialogUtil.SetDouble('angle', line_a.GetParam(GO2SParam.angle))
GO2SDialogUtil.SetDouble('distance', line_p.GetParam(GO2SParam.length))
}
var PushButton_Clicked = function(name)
{
if(name == 'okButton')
{
line_a.SetParam(GO2SParam.angle, GO2SDialogUtil.GetDouble('angle'))
line_p.SetParam(GO2SParam.length, GO2SDialogUtil.GetDouble('distance'))
}
}
var dialog = GO2SDialogUtil.ExecDialog(scriptFilePath+'/LineParam.ui')
Parameters
var start = new GO2SXYZ(0, 20, 0)
var end = new GO2SXYZ(5, -10, 0)
var arc = GO2SArcCreate.FromCenterStartEnd(new GO2SXYZ, start, end)
//1st possibility
console.log('Solution 1')
console.log('angle editable ' + arc.IsParamEditable(GO2SParam.angle))
console.log('rayon editable ' + arc.IsParamEditable(GO2SParam.radius))
console.log('length editable ' + arc.IsParamEditable(GO2SParam.length))
console.log('Width editable ' + arc.IsParamEditable(GO2SParam.width))
console.log('Heigth editable ' + arc.IsParamEditable(GO2SParam.height))
//2nd possibility
var params = arc.GetEditableParams()
console.log('solution 2, editable')
console.log(params)
// Lets assume we designed a cuboid shape and add a fillet on it
// cuboid is labeled 'cube'
// Fillet is labeled in the solid construction tree 'fillet'
var cube = GO2SGeometryUtil.GetByName('cube')[0]
var fillet = GO2SGeometryUtil.GetByName('fillet')[0]
cube.SetParam(GO2SParam.length, 200)
cube.SetParam(GO2SParam.width, 150)
cube.SetParam(GO2SParam.height, 100)
fillet.SetParam(GO2SParam.radius,10)
Files
var filename = 'U:/test.xml';
var file = new GO2SXmlFile(filename, GO2SFileOpen.read_write);
// create nodes
file.CreateRootNode('TestFile');
file.AppendNode('Node1');
file.AppendNode('Node2');
file.GoToChild(); // to Node1
file.GoToSibling() // to Node2
file.AppendNode('SubNode1');
file.AppendNode('SubNode2');
file.GoToParent() // to root
file.AppendNode('Node3');
// write node content
file.GoToRoot() // to root
// write Node1
file.GoToChild() //to Node1
file.SetNodeValue('ValueNode1');
// write Node2
file.GoToSibling() //to Node2
file.GoToChild(); // to SubNode1
file.SetNodeValue('ValueSubNode1');
file.GoToSibling() // to SubNode2
file.SetNodeValue('ValueSubNode2');
file.GoToParent() //to Node2
// write Node3
file.GoToSibling(); // to Node3
file.SetNodeAttribute('att1', 'val1');
file.SetNodeAttribute('att2', 'val2');
file.SetNodeAttribute('att3', 'val2');
file.Save();
file.Close();
Standard Macros
Archimedean Spiral
function create_spirale()
{
const rad1 = GO2SDialogUtil.GetDouble('firstRadiusValue')
const rad2 = GO2SDialogUtil.GetDouble('secondRadiusValue')
const step = GO2SCalcUtil.ToRadian(GO2SDialogUtil.GetDouble('stepValue'))
const startAngle = GO2SCalcUtil.ToRadian(GO2SDialogUtil.GetDouble('startAngleValue'))
const endAngle = GO2SCalcUtil.ToRadian(GO2SDialogUtil.GetDouble('endAngleValue'))
const posX = GO2SDialogUtil.GetDouble('posXValue')
const posY = GO2SDialogUtil.GetDouble('posYValue')
if (step === 0)
return;
const a = (rad1 - rad2) / (startAngle - endAngle)
const b = rad1 - (a * startAngle)
var pts = []
for (let angle = startAngle; angle <= endAngle; angle += step)
{
let pX = ((a * angle + b) * Math.cos(angle)) + posX
let pY = ((a * angle + b) * Math.sin(angle)) + posY
pts.push(new GO2SXYZ(pX, pY, 0));
}
new GO2SNurbs(pts, false, 0);
}
var InitDialog = function()
{
GO2SDialogUtil.SetDouble('firstRadiusValue', 0)
GO2SDialogUtil.SetDouble('secondRadiusValue', 100)
GO2SDialogUtil.SetDouble('stepValue', 1)
GO2SDialogUtil.SetDouble('startAngleValue', 0)
GO2SDialogUtil.SetDouble('endAngleValue', 360)
GO2SDialogUtil.SetDouble('posXValue', 0)
GO2SDialogUtil.SetDouble('posYValue', 0)
}
var PushButton_Clicked = function(name)
{
if(name == 'okButton')
create_spirale();
}
GO2SDialogUtil.ExecDialog(scriptFilePath+'/ArchimedeanSpiral/ArchimedeanSpiral.ui')
Circle Center
var PushButton_Clicked = function(name)
{
let dmin = Number.MIN_VALUE
let dmax = Number.MAX_VALUE
if(GO2SDialogUtil.IsChecked('miniCheck'))
dmin = GO2SDialogUtil.GetDouble('miniDiam')
if(GO2SDialogUtil.IsChecked('maxiCheck'))
dmax = GO2SDialogUtil.GetDouble('maxiDiam')
let cb = GO2SDialogUtil.GetComboIndex('entityCombo')
GO2SInteract.StartSelection()
let geom = GO2SGeometryUtil.GetSelected()
for(let i=0; i<geom.length; i++)
{
if(geom[i].IsCircular())
{
var ok = true
if(cb==0)
ok = geom[i].IsClose()
else if (cb==1)
ok = !geom[i].IsClose()
var diam = geom[i].GetRadius() * 2;
if(ok && diam <= dmax && diam >= dmin)
new GO2SPoint(geom[i].GetPosition())
}
}
}
GO2SDialogUtil.ExecDialog(scriptFilePath+'/CircleCenter/CircleCenter.ui')
Engraving
var police = "OLF SimpleSansOC"
function CreateIniFile()
{
GO2SFileUtil.Remove(scriptFilePath+"/Engraving/Engraving.ini");
let file = new GO2SAsciiFile(scriptFilePath+'/Engraving/Engraving.ini', GO2SFileOpen.read_write);
file.AppendLast(GO2SDialogUtil.GetText("m_text"));
file.AppendLast(GO2SDialogUtil.GetDouble("m_textHeigth"));
file.AppendLast(GO2SDialogUtil.GetComboIndex("m_anchor"));
file.AppendLast(GO2SDialogUtil.GetText("opelistPath"));
file.Save();
}
var InitDialog = function()
{
GO2SDialogUtil.SetDouble("m_textHeigth", 25);
GO2SDialogUtil.SetText("m_text", "GO2cam");
if (GO2SFileUtil.Exists(scriptFilePath+"/Engraving/Engraving.ini") === true)
{
let file = new GO2SAsciiFile(scriptFilePath+"/Engraving/Engraving.ini", GO2SFileOpen.read_only);
if(file.IsOpen())
{
let count = file.GetLineCount()
GO2SDialogUtil.SetDouble("m_textHeigth", file.ReadLine(count-3));
GO2SDialogUtil.SetComboIndex("m_anchor", file.ReadLine(count-2));
GO2SDialogUtil.SetText("opelistPath", file.ReadLine(count-1))
let text = ''
for(let i=0; i< count-3; i++)
text += file.ReadLine(i) + '\n';
text = text.slice(0, -1) // remove last \n
GO2SDialogUtil.SetText("m_text", text)
file.Close();
}
}
}
var PushButton_Clicked = function(name) {
if(name === "m_okButton")
{
let text = GO2SDialogUtil.GetText("m_text");
let textHeigth = GO2SDialogUtil.GetDouble("m_textHeigth");
let anchor = GO2SDialogUtil.GetComboIndex("m_anchor")
let temp_text = new GO2SText(text, new GO2SXYZ, textHeigth, anchor, police)
temp_text.SetVerSpacing(0)
let newPos = GO2SInteract.PickXYZWithPreview([temp_text]);
temp_text.Delete();
if(!newPos)
return null;
let engraving = new GO2SText(text, newPos, textHeigth, anchor, police)
engraving.SetVerSpacing(0)
let str = GO2SUtil.GenerateName('engravig_text')
engraving.SetName(str)
let path = GO2SDialogUtil.GetText("opelistPath");
let opelist = new GO2SOpelist(path);
if(opelist.IsLoaded())
{
opelist.SetUserParam('engraving', str)
opelist.Run();
}
CreateIniFile();
}
if (name === "m_fileBrowser")
{
let opelist_path = GO2SDialogUtil.AskOpenFileName("opelist", "", "");
GO2SDialogUtil.SetText("opelistPath", opelist_path);
}
}
GO2SDialogUtil.ExecDialog(scriptFilePath+'/Engraving/Engraving.ui');
Formula
function Replace(str, value)
{
return str.replace(/p0/g, value)
}
function CreateIniFile()
{
GO2SFileUtil.Remove(scriptFilePath+"/formula/formula.ini")
let file = new GO2SAsciiFile(scriptFilePath+'/formula/formula.ini', GO2SFileOpen.read_write)
file.Append(0, GO2SDialogUtil.GetDouble("min_value"), 0)
file.Append(1, GO2SDialogUtil.GetDouble("max_value"))
file.Append(2, GO2SDialogUtil.GetDouble("step_value"))
file.Append(3, GO2SDialogUtil.GetText("formulaX"))
file.Append(4, GO2SDialogUtil.GetText("formulaY"))
file.Append(5, GO2SDialogUtil.GetText("formulaZ"))
file.Save()
}
var InitDialog = function()
{
GO2SDialogUtil.SetEnabled("fileBrowser", false)
GO2SDialogUtil.SetEnabled("file_path", false)
GO2SDialogUtil.SetEnabled("file_path_label", false)
if (GO2SFileUtil.Exists(scriptFilePath+"/formula/formula.ini") === true)
{
let file = new GO2SAsciiFile(scriptFilePath+"/formula/formula.ini", GO2SFileOpen.read_only)
GO2SDialogUtil.SetDouble("min_value", file.ReadLine(0))
GO2SDialogUtil.SetDouble("max_value", file.ReadLine(1))
GO2SDialogUtil.SetDouble("step_value", file.ReadLine(2))
GO2SDialogUtil.SetText("formulaX", file.ReadLine(3))
GO2SDialogUtil.SetText("formulaY", file.ReadLine(4))
GO2SDialogUtil.SetText("formulaZ", file.ReadLine(5))
file.Close()
}
}
var ComboBox_CurrentIndexChanged = function(name, text)
{
if (name === "geometry")
{
let enable = text === 4
GO2SDialogUtil.SetEnabled("fileBrowser", enable)
GO2SDialogUtil.SetEnabled("file_path", enable)
}
}
var PushButton_Clicked = function(name) {
if(name === "okButton")
{
let mini = GO2SDialogUtil.GetDouble("min_value")
let maxi = GO2SDialogUtil.GetDouble("max_value")
let step = GO2SDialogUtil.GetDouble("step_value")
let fx = GO2SDialogUtil.GetText("formulaX")
let fy = GO2SDialogUtil.GetText("formulaY")
let fz = GO2SDialogUtil.GetText("formulaZ")
let path = GO2SDialogUtil.GetText("file_path")
let pts = []
for (let i = mini; i <= maxi; i += step)
{
let px = GO2SCalcUtil.Evaluate(Replace(fx, i))
let py = GO2SCalcUtil.Evaluate(Replace(fy, i))
let pz = GO2SCalcUtil.Evaluate(Replace(fz, i))
pts.push(new GO2SXYZ(px, py, pz))
}
let ind = GO2SDialogUtil.GetComboIndex("geometry")
if(ind == 0)
{// segments
for (let n = 1; n < pts.length; n++)
new GO2SSegment(pts[n-1], pts[n])
}
else if(ind == 1)
{// points
pts.forEach(p => new GO2SPoint(p))
}
else if(ind == 2)
{// polyline
new GO2SPolyline(pts, false, false);
}
else if(ind == 3)
{// nurbs
new GO2SNurbs(pts, false, false);
}
else if(ind == 4)
{// file
var file = new GO2SCsvFile(path, GO2SFileOpen.read_write)
if(file.IsOpen())
{
pts.forEach(p => file.AppendRecord( [ p.X().toString(), p.Y().toString(), p.Z().toString() ] ))
file.Save()
file.Close()
}
else
GO2SDialogUtil.CreateMessageBox('Please select a valid file path', 'Error opening file', GO2SMessageType.error)
}
CreateIniFile();
}
if (name === "fileBrowser")
{
let path = GO2SDialogUtil.AskSaveFileName('', ['CSV Files (*.csv)']);
GO2SDialogUtil.SetText("file_path", path);
}
}
var dialog = GO2SDialogUtil.ExecDialog(scriptFilePath+'/formula/formula.ui');
isostat
var labels = [
'rrh', 'qrh', 'lrh', 'mrh', 'nrh', 'orh','prh', 'rri', 'qri',
'lri', 'mri', 'nri','ori', 'pri', 'b', 'g', 'f', 'e', 'nrhv',
'qrhw'
];
var angle = [0, 180, 90, 270];
var InitDialog = function()
{
let path = scriptFilePath + "/isostat/isostat";
for (let i = 0; i < labels.length; i++)
{
iconNumber = (i + 1) + ".png";
GO2SDialogUtil.AddItemCombo("comboBox", '', path + iconNumber);
}
}
var CreateSymbol = function()
{
let direction = angle[GO2SDialogUtil.GetComboIndex("direction")];
let iso = labels[GO2SDialogUtil.GetComboIndex("comboBox")];
let preview = new GO2SText(iso, null, 10, GO2SAnchor.Center, "GO2Isostatic");
preview.SetAngle(GO2SCalcUtil.ToRadian(direction));
preview.SetFilled(false);
let newpt = GO2SInteract.PickXYZWithPreview([preview])
preview.Delete()
if(!newpt)
return GO2SInterruption.unknown
let code = new GO2SText(iso, newpt, 10, GO2SAnchor.Center, "GO2Isostatic");
code.SetAngle(GO2SCalcUtil.ToRadian(direction));
code.SetFilled(false);
code.SetHorSpacing(0);
GO2SInteract.Redraw()
return GO2SInterruption.apply
}
var PushButton_Clicked = function(name)
{
let ret = GO2SInterruption.quit
if(name === "okButton")
ret = CreateSymbol()
else if(name === "cancelButton")
ret = GO2SInterruption.accept
GO2SDialogUtil.SetInterruption(ret)
return true
}
var DestroyCtrlDialog = function()
{
GO2SDialogUtil.SetInterruption(GO2SInterruption.accept)
return true
}
var Loop = function()
{
let inter = GO2SInterruption.unknown;
while (inter != GO2SInterruption.accept)
inter = GO2SInteract.WaitForInterruption()
return inter
}
var dialog = GO2SDialogUtil.LoadDialog(scriptFilePath+'/Isostat/Isostat.ui')
Part Family
var g_workingFolder = "";
const g_paramMap = new Map();
var g_initialValue = [""];
var g_columnName = [""];
var g_rowNames = ["Initial"];
var g_rowCount = 1;
var g_colCount = 1;
// to add a delete button for each configuration in the table
function AddDeleteButton(row)
{
let name = GO2SDialogUtil.GetText('m_comboSet') + '_delete_config_' + row
GO2SDialogUtil.CreatePushButton(name, "", "icon\\delete.png");
GO2SDialogUtil.AddWidgetToTable("m_tableConfig", name, row, 0);
}
// fill the configuration table with the given .tpf file
function FillTable(filePath)
{
let currentFile = new GO2SAsciiFile(filePath, GO2SFileOpen.read_only);
if (!currentFile.IsOpen())
return ;
g_rowNames = [ "Initial" ]; // Reset row name
g_rowCount = currentFile.GetLineCount() + 1;
//GO2SDialogUtil.SetRowCount("m_tableConfig", 0);
GO2SDialogUtil.SetRowCount("m_tableConfig", g_rowCount);
GO2SDialogUtil.FillRowFromArray("m_tableConfig", g_initialValue, 0)
for (let i = 0; i < currentFile.GetLineCount(); i++)
{
AddDeleteButton(i + 1);
let str = currentFile.ReadLine(i);
str = str.split(":");
g_rowNames.push(str[0]);
let value = str[1].split(",");
for (let j = 0; j < value.length && j < g_colCount; j++)
GO2SDialogUtil.SetTableValue("m_tableConfig", i + 1, j + 1, value[j])
}
GO2SDialogUtil.SetTableRowNames("m_tableConfig", g_rowNames);
currentFile.Close();
}
function SaveFile()
{
let filename = GO2SDialogUtil.GetText('m_comboSet')
if(filename.length==0)
{
console.log('no configuration selected')
return
}
filename += '.tpf'
let filePath = g_workingFolder + '/'
filePath += filename
if (GO2SFileUtil.Exists(filePath))
GO2SFileUtil.Remove(filePath)
let file = new GO2SAsciiFile(filePath, GO2SFileOpen.read_write);
if(file.IsOpen())
{
for (let i = 1; i < g_rowCount; i++)
{
let data = GO2SDialogUtil.GetTableRow("m_tableConfig", i);
let str = g_rowNames[i] + ":";
data.forEach((value, index, array) => {
str += value
if (index !== array.length - 1)
str += ",";
})
file.Append(i - 1, str);
}
file.Save();
file.Close();
GO2SDialogUtil.CreateMessageBox('data saved', 'Save', GO2SMessageType.info)
}
}
function exec()
{
let config = GO2SDialogUtil.GetSelectedRow("m_tableConfig");
if (config === undefined || config.length === 0)
return;
if (config.length === g_colCount)
config.splice(0, 1);
let i = 0;
for (const [key, item] of g_paramMap)
{
let type = key.substring(key.lastIndexOf(".") + 1, key.length);
if (type === "length")
item.forEach((obj) => { obj.SetParam(GO2SParam.length, Number(config[i])); })
if (type === "width")
item.forEach((obj) => { obj.SetParam(GO2SParam.width, Number(config[i])); })
if (type === "height")
item.forEach((obj) => { obj.SetParam(GO2SParam.height, Number(config[i])); })
if (type === "angle")
item.forEach((obj) => { obj.SetParam(GO2SParam.angle, Number(config[i])); })
if (type === "radius")
item.forEach((obj) => { obj.SetParam(GO2SParam.radius, Number(config[i])); })
i++;
}
}
function Load(dirPath)
{
if (dirPath.length === 0)
return;
g_workingFolder = dirPath;
GO2SDialogUtil.SetText('m_labelFolder', g_workingFolder)
let file = new GO2SAsciiFile(scriptFilePath+'/PartFamily/PartFamily.ini', GO2SFileOpen.read_write);
if(file.IsOpen())
{
if(file.GetLineCount()>0)
file.EditLine(0, g_workingFolder)
else
file.Append(0, g_workingFolder)
}
file.Save();
GO2SDialogUtil.SetRowCount("m_tableConfig", 0);
GO2SDialogUtil.ClearCombo("m_comboSet");
let fileList = GO2SFileUtil.GetFileList(g_workingFolder, "tpf");
fileList.forEach((filePath) => {
GO2SDialogUtil.AddItemCombo("m_comboSet", GO2SFileUtil.ExtractFilename(filePath, false));
})
}
function AddColumn(name, item, param)
{
let label = item.GetName().concat("." + name)
if (!g_paramMap.has(label))
{
g_paramMap.set(label, [item]);
g_columnName.push(label);
g_colCount++;
g_initialValue.push(item.GetParam(param).toFixed(3));
}
else
g_paramMap.get(label).push(item);
}
var InitDialog = function()
{
let geoms = GO2SGeometryUtil.GetByNameLike("@")
geoms.forEach((item) => {
if (item.IsParamEditable(GO2SParam.length))
AddColumn("length", item, GO2SParam.length);
if (item.IsParamEditable(GO2SParam.width))
AddColumn("width", item, GO2SParam.width);
if (item.IsParamEditable(GO2SParam.height))
AddColumn("height", item, GO2SParam.height);
if (item.IsParamEditable(GO2SParam.angle))
AddColumn("angle", item, GO2SParam.angle);
if (item.IsParamEditable(GO2SParam.radius))
AddColumn("radius", item, GO2SParam.radius);
})
GO2SDialogUtil.FillRowFromArray("m_tableConfig", g_initialValue)
GO2SDialogUtil.SetTableColumnNames("m_tableConfig", g_columnName)
GO2SDialogUtil.SetTableRowNames("m_tableConfig", g_rowNames)
GO2SDialogUtil.SetColumnWidth("m_tableConfig", 0, 20)
GO2SDialogUtil.SetCellReadOnly("m_tableConfig", 0, 0)
let file = new GO2SAsciiFile(scriptFilePath+"/PartFamily/PartFamily.ini", GO2SFileOpen.read_only);
let folder = scriptFilePath + '/PartFamily/'
if (file.IsOpen())
{
let f = file.ReadLine(0)
if(GO2SFileUtil.Exists(f))
folder = f
file.Close();
}
Load(folder);
}
var ComboBox_CurrentIndexChanged = function(name, index)
{
if (name === "m_comboSet" && index >= 0)
{
let filename = GO2SDialogUtil.GetText('m_comboSet')
if(filename.length!=0)
{
let filePath = g_workingFolder + '/' + filename + '.png'
if (GO2SFileUtil.Exists(filePath))
GO2SDialogUtil.SetLabelPixmap('m_labelImage', filePath)
else
GO2SDialogUtil.SetText('m_labelImage', 'Missing image')
filePath = g_workingFolder + '/' + filename + '.tpf'
FillTable(filePath);
}
}
}
var PushButton_Clicked = function(name)
{
// Top menu
if (name === "m_folderButton")
Load(GO2SDialogUtil.AskDirectory());
else if (name === "m_buttonSave")
SaveFile();
// Family
else if (name === "m_buttonAddSet")
{
let count = GO2SDialogUtil.GetComboData('m_comboSet').length + 1
let part_name = GO2SDialogUtil.AskText("Configuration set", "", "part_"+ count);
if (part_name.length > 0)
{
GO2SDialogUtil.AddItemCombo("m_comboSet", part_name);
GO2SDialogUtil.SetComboText("m_comboSet", part_name);
}
}
else if (name === "m_buttonRenameSet")
{
let name = GO2SDialogUtil.AskText("Rename family", "", GO2SDialogUtil.GetComboText("m_comboSet"));
if (name.length === 0) {
console.log("Name can't be empty");
return ;
}
let index = GO2SDialogUtil.GetComboIndex("m_comboSet");
let newName = GO2SFileUtil.MakePath(path, name+".tpf");
GO2SFileUtil.Rename(fileList[index], newName);
fileList[index] = newName;
RefreshComboBox(index);
}
else if (name === "m_buttonDelSet")
{
if (GO2SDialogUtil.AskQuestion("Do you really want to delete this set?", "Delete configuration set?"))
{
let partName = GO2SDialogUtil.GetComboText("m_comboSet");
let partFilename = g_workingFolder + '/' + partName + '.tpf'
GO2SFileUtil.Remove(partFilename);
let partImage = g_workingFolder + '/' + partName + '.png'
GO2SFileUtil.Remove(partImage);
let ind = GO2SDialogUtil.GetComboIndex("m_comboSet");
GO2SDialogUtil.RemoveItemCombo("m_comboSet", ind);
}
}
// Configuation
else if (name === "m_buttonAddConfig")
{
let name = GO2SDialogUtil.AskText("Config name", "config_name"+g_rowCount, "config"+g_rowCount);
g_rowCount++;
GO2SDialogUtil.SetRowCount("m_tableConfig", g_rowCount);
g_rowNames.push(name);
GO2SDialogUtil.SetTableRowNames("m_tableConfig", g_rowNames);
AddDeleteButton(g_rowCount - 1);
let rowValue = GO2SDialogUtil.GetTableRowByName("m_tableConfig", "Actual");
for (let j = 0; j < rowValue.length; j++)
GO2SDialogUtil.SetTableValue("m_tableConfig", g_rowCount - 1, j, rowValue[j])
}
else if (name === "m_buttonRenameConfig")
{
let index = GO2SDialogUtil.GetCurrentRowIndex("m_tableConfig");
if (index < 1) {
console.log("Can't rename first row");
return ;
}
let name = GO2SDialogUtil.AskText("Rename config", "", g_rowNames[index]);
if (name.length === 0)
{
console.log("Name can't be empty");
return ;
}
g_rowNames[index] = name;
GO2SDialogUtil.SetTableRowNames("m_tableConfig", g_rowNames);
}
else if (name.search("delete_config") > -1)
{
let index = GO2SDialogUtil.GetCurrentRowIndex("m_tableConfig");
GO2SDialogUtil.RemoveRow("m_tableConfig", index);
g_rowNames.splice(index, 1);
g_rowCount--;
GO2SDialogUtil.SetRowCount("m_tableConfig", g_rowCount);
GO2SDialogUtil.RemoveWidget(name);
}
else if (name === "m_buttonApply" || name === "m_buttonOK")
{
exec();
GO2SInteract.UpdateAll();
GO2SInteract.Redraw();
}
}
/*
var stock = new GO2SStock
stock.GetExistingStock()
stock.SetName('@stock')
*/
var dialog = GO2SDialogUtil.ExecDialog(scriptFilePath+'//PartFamily/PartFamily.ui');