JGraphx : How to avoid adding edges over each other? - edges

I'm working on an application using jGraphx and I want to know how to avoid creating edges over each other.
When I add 2 edges between 2 vetexes, the 2 edges are above eatch other..
Thanks in advance.
EDIT : That's what I get, those are 2 edges with the labels : "dist = 1" and "dist = 4" above each other.

It can be done easily:
new mxCircleLayout(graph).execute(graph.getDefaultParent());
new mxParallelEdgeLayout(graph).execute(graph.getDefaultParent());

Without seeing any of your source code it's hard to offer specific details, but in general, what you need to do is get the graph's stylesheet, and then modify the edge related parameters. An example is:
mxGraph mxgraph = new mxGraph();
Object parent = mxgraph.getDefaultParent();
mxgraph.getModel().beginUpdate();
mxStylesheet stylesheet = mxgraph.getStylesheet();
Hashtable<String, Object> style = new Hashtable<>();
stylesheet.putCellStyle("ROUNDED", style);
Map<String, Object> vertexStyle = stylesheet.getDefaultVertexStyle();
vertexStyle.put(mxConstants.STYLE_FILLCOLOR, "#FFFFFF");
vertexStyle.put(mxConstants.STYLE_STROKECOLOR, "#000000");
vertexStyle.put(mxConstants.STYLE_AUTOSIZE, 1);
vertexStyle.put(mxConstants.STYLE_SPACING, "10");
vertexStyle.put(mxConstants.STYLE_ORTHOGONAL, "true");
vertexStyle.put(mxConstants.STYLE_SHAPE, mxConstants.SHAPE_ELLIPSE);
Map<String, Object> edgeStyle = stylesheet.getDefaultEdgeStyle();
edgeStyle.put(mxConstants.STYLE_EDGE, mxConstants.EDGESTYLE_ORTHOGONAL);
edgeStyle.put(mxConstants.STYLE_SHAPE, mxConstants.SHAPE_CURVE);
edgeStyle.put(mxConstants.STYLE_ENDARROW, mxConstants.ARROW_CLASSIC);
...set up your edges and vertices here, where the last parameter is "ROUNDED" (the name of the stylesheet)
mxgraph.getModel().endUpdate();

Related

How to create helical curve using inventor api and c# or vb.net

I have code in c# windows app creating a line in a 2D sketch. And then I created a 3D sketch. Eventually I want to add a helical curve around this line from the 3D sketch. Can anyone help me please to solve this issue? Thanks in advance.
public void MyMethod(Inventor.Application ThisApplication)
{
PartDocument oSheetMetalDoc = (PartDocument)m_oInventorApp.Documents.Add(DocumentTypeEnum.kPartDocumentObject, m_oInventorApp.FileManager.GetTemplateFile(DocumentTypeEnum.kPartDocumentObject, SystemOfMeasureEnum.kMetricSystemOfMeasure, DraftingStandardEnum.kDefault_DraftingStandard, "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}"), true);
// Set a reference to the component definition.
SheetMetalComponentDefinition oCompDef = (SheetMetalComponentDefinition)oSheetMetalDoc.ComponentDefinition;
// Set a reference to the sheet
// metal features collection.
SheetMetalFeatures oSheetMetalFeatures = (SheetMetalFeatures)oCompDef.Features;
// Create a new sketch on the X-Y work plane.
PlanarSketch oSketch = default(PlanarSketch);
oSketch = oCompDef.Sketches.Add(oCompDef.WorkPlanes[3]);
TransientGeometry oTransGeom = (TransientGeometry)ThisApplication.TransientGeometry;
// Draw a 4cm x 3cm rectangle with the
// corner at (0,0)
SketchLine line = (SketchLine)oSketch.SketchLines.AddByTwoPoints(oTransGeom.CreatePoint2d(0, 0), oTransGeom.CreatePoint2d(0, 500)); // 2. ihtimal
// skecth line turn to centerline
line.Centerline = true;
ThisApplication.ActiveView.GoHome();
// Create a 3D sketch.
Sketch3D sketch3 = (Sketch3D)oCompDef.Sketches3D.Add();
SketchEntity3D selectObj = m_oInventorApp.CommandManager.Pick(SelectionFilterEnum.kSketch3DCurveFilter, "Select 3d sketch entity");
if (selectObj == null)
{
}
// HelicalConstraint3D . want to add helical curve around the line above
}
This is iLogic/VB.net code for creating helix curve based on selected SketchLine.
Part document must be active, and at least one SketchLine must be visible for selection.
Sub Main()
Dim oSketchLine As SketchLine = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kSketchCurveLinearFilter,
"Select line")
CreateHelicalCurve(oSketchLine)
End Sub
Private Sub CreateHelicalCurve(oSketchLine As SketchLine)
Dim partDef As PartComponentDefinition = oSketchLine.Parent.Parent
Dim sketch3D As Sketch3D = partDef.Sketches3D.Add()
Dim axisStartPoint As Point = oSketchLine.StartSketchPoint.Geometry3d
Dim axisEndPoint As Point = oSketchLine.EndSketchPoint.Geometry3d
Dim curveStartPoint As Point = axisStartPoint.Copy()
curveStartPoint.TranslateBy(ThisApplication.TransientGeometry.CreateVector(0, 0, 1))
Dim diameter As Double = 5 ' [cm]
Dim pitch As Double = 1 ' [cm]
Dim revolution As Object = Nothing ' Optional argument
Dim height As Double = 5 ' [cm]
Dim helicalCurveDefinition As HelicalCurveConstantShapeDefinition = sketch3D.HelicalCurves.
CreateConstantShapeDefinition(
HelicalShapeDefinitionTypeEnum.kPitchAndHeightShapeType,
axisStartPoint,
axisEndPoint,
curveStartPoint,
diameter,
pitch,
revolution,
height
)
sketch3D.HelicalCurves.Add(helicalCurveDefinition)
End Sub

Count of the biggest bin in histogram, C#, sharp

I want to make histogram of my data so, I use histogram class at c# using MathNet.Numerics.Statistics.
double[] array = { 2, 2, 5,56,78,97,3,3,5,23,34,67,12,45,65 };
Vector<double> data = Vector<double>.Build.DenseOfArray(array);
int binAmount = 3;
Histogram _currentHistogram = new Histogram(data, binAmount);
How can I get the count of the biggest bin? Or just the index of the bigest bin? I try to get it by using GetBucketOf but to do this I need the element in this bucket :(
Is there any other way to do this? I read the documentation and Google and I can't find anything.
(Hi, I would use a comment for this but i just joined so today and don't yet have 50 reputation to comment!) I just had a look at - http://numerics.mathdotnet.com/api/MathNet.Numerics.Statistics/Histogram.htm. That documentation page (footer says it was built using http://docu.jagregory.com/) shows a public property named Item which returns a Bucket. I'm wondering if that is the property you need to use because the automatically generated documentation states that the Item property "Gets' the n'th bucket" but isn't clear how the Item property acts as an indexer. Looking at your code i would try _currentHistogram.Item[n] first (if that doesn't work try _currentHistogram[n]) where you are iterating the Buckets in the histogram using something like -
var countOfBiggest = -1;
var indexOfBiggest = -1;
for (var n = 0; n < _currentHistogram.BucketCount; n++)
{
if (_currentHistogram.Item[n].Count > countOfBiggest)
{
countOfBiggest = _currentHistogram.Item[n].Count;
indexOfBiggest = n;
}
}
The code above assumes that Histogram uses 0-based and not 1-based indexing.

Parsing Projection WKT in OpenLayers 3

I am looking for a method (javascript) (external or internal part of ol3) that can parse a projection WKT to its proj4 text and create the projection.
<SRS>PROJCS["GDA94 / MGA zone 53",GEOGCS["GDA94",DATUM["Geocentric_Datum_of_Australia_1994",SPHEROID["GRS 1980",6378137,298.2572221010002,AUTHORITY["EPSG","7019"]],AUTHORITY["EPSG","6283"]],PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433],AUTHORITY["EPSG","4283"]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",0],PARAMETER["central_meridian",135],PARAMETER["scale_factor",0.9996],PARAMETER["false_easting",500000],PARAMETER["false_northing",10000000],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AUTHORITY["EPSG","28353"]]</SRS>
Above shows an example of the XML element containing the SRS.
I have found out that if I can convert this to proj4 text. Then i can add it as a projection this way:
proj4.defs("EPSG:28353", "+proj=utm +zone=53 +south +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs");
var def = proj4.defs(grid.srs);
var units = def.units;
var proj = new ol.proj.Projection({
code: grid.srs,
units: units,
axisOrientation: def.axis
});
proj.setExtent(/*...*/);
ol.proj.addProjection(proj);
var proj4Transform1 = proj4('EPSG:3857', grid.srs);
ol.proj.addCoordinateTransforms(ol.proj.get('EPSG:3857'), proj,
proj4Transform1.forward, proj4Transform1.inverse);
var proj4Transform2 = proj4('EPSG:4326', grid.srs);
ol.proj.addCoordinateTransforms(ol.proj.get('EPSG:4326'), proj,
proj4Transform2.forward, proj4Transform2.inverse);
Is it possible to find the extend of the projection in the WKT also or should I look this up also external?
proj4js supports WKT strings too. You can throw what you have (excluding the <SRS> tag) directly at proj4js, using the same syntax:
proj4.defs("EPSG:28353", "PROJCS["GDA94 / MGA zone 53",GEOGCS["GDA94",DATUM["Geocentric_Datum_of_Australia_1994",SPHEROID["GRS 1980",6378137,298.2572221010002,AUTHORITY["EPSG","7019"]],AUTHORITY["EPSG","6283"]],PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433],AUTHORITY["EPSG","4283"]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",0],PARAMETER["central_meridian",135],PARAMETER["scale_factor",0.9996],PARAMETER["false_easting",500000],PARAMETER["false_northing",10000000],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AUTHORITY["EPSG","28353"]]");
Once you have defined a projection using proj4.defs(), it will be immediately be available in OpenLayers 3, and all transforms will be registered. So the proj4.defs() line is all you need unless you want to set additional options, like the projection extent in your case. There are two options to do this: 1) globally:
ol.proj.get('EPSG:28353').setExtent(*/ ... */);
or 2) just for one ol.proj.Projection instance that you use to e.g. configure your ol.View:
var projection = new ol.proj.Projection({
code: 'EPSG:28353',
extent: /* ... */
});

How to vary the width of TextBox views using Rikulo Anchor Layout

I am new to Dart and Rikulo.
class NameView extends Section
{
View parentVu;
// the inputs
DropDownList titleDdl, suffixDdl;
TextBox firstNameTBox, middleNameTBox, lastNameTBox;
// the labels
TextView titleLbl, firstNameLbl, middleNameLbl, lastNameLbl, suffixLbl;
List<String> titles = [ 'Dr', 'Hon', 'Miss', 'Mr', 'Mrs', 'Prof', 'Sir' ];
List<String> suffixes = ['I', 'II', 'III', 'IV', 'Junior', 'Senior'];
NameView()
{
parentVu = new View()
..style.background = 'cyan'
..addToDocument();
titleLbl = new TextView( 'Title' );
parentVu.addChild( titleLbl );
titleDdl = new DropDownList( model : new DefaultListModel( titles ) )
..profile.anchorView = titleLbl
..profile.location = 'east center';
parentVu.addChild( titleDdl );
firstNameLbl = new TextView( 'First' )
..profile.anchorView = titleDdl
..profile.location = 'east center';
parentVu.addChild(firstNameLbl );
firstNameTBox = new TextBox( null, 'text' )
..profile.anchorView = firstNameLbl
..profile.location = 'east center';
//..profile.width = 'flex';
parentVu.addChild( firstNameTBox );
}
The program renders. However, it does not uses the entire width of the browser (FireFox).
I have tried for the TextBoxes
profile.width = 'flex'
but it does not work.
Any help is appreciated.
Firefox? Did you test it with Dartium? Notice that you have to compile it to JS before you can test it with browsers other than Dartium.
BTW, from your implementation, NameView seems not related to parentVu at all. If it is just a controller, it needs not to extend from Section (i.e., it doesn't have to be a view).
If a view is anchored to another, both location and size will depend on the view it anchors. In your case, if specifying flex to TextBox, its width will be the same as FirstNameLb1. It is why it is so small.
You can listen to the layout event such as:
firstNameTBox.on.layout.listen((_) {
firstNameTBox.width = parentVu.width;
});
Note: You need to do some calculation to get the right width.
See also Layout Overview

How to clone an object3d in Three.js?

I want to clone a model loaded with loader, I found this issue on github,but the solution doesn't work. It seems there has been an structural change in Object3D.
How can I clone an Object3D in current stable version of Three.js?
In this new version of three.js you have a method clone.
For example, I use a queen from chess and I had to duplicate multiple times:
// queen is a mesh
var newQueen = queen.clone();
// make sure to re position to be able to see the new queen!
newQueen.position.set(100,100,100); // or any other coordinates
It will work with any mesh.
I used three.js r61.
Actually mrdoob's answer is your answer...
The loader output a geometry you use to create a mesh.
You need to create a new mesh with the loader-created mesh's geometry and material.
for ( var i = 0; i < 10; i ++ ) {
var mesh = new THREE.Mesh( loadedMesh.geometry, loadedMesh.material );
mesh.position.set( i * 100, 0, 0 );
scene.add( mesh );
}
You want to clone a Mesh and not an Object3D because the output of the loader is a Mesh.
I found one fast solution (not the most efficient)
The GLTFLoader uses the THREE.FileLoader() method internally, which allows you to cache files.
To do so, you need to add this line before you create an instance of the GLTFLoader
THREE.Cache.enabled = true;
Then you can load multiple times the same model, but only the first time will take longer, for example:
THREE.Cache.enabled = true;
var loader = new GLTFLoader();
var deeplyClonedModels = [];
for( var i = 0; i < 10; i++ ){
loader.load('foo.gltf', function ( gltf ) {
deeplyClonedModels.push(gltf.scene);
});
}

Resources